aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/Kconfig18
-rw-r--r--drivers/usb/Makefile6
-rw-r--r--drivers/usb/atm/Makefile6
-rw-r--r--drivers/usb/atm/cxacru.c20
-rw-r--r--drivers/usb/atm/speedtch.c28
-rw-r--r--drivers/usb/atm/ueagle-atm.c56
-rw-r--r--drivers/usb/atm/usbatm.c15
-rw-r--r--drivers/usb/c67x00/Makefile6
-rw-r--r--drivers/usb/c67x00/c67x00-drv.c2
-rw-r--r--drivers/usb/c67x00/c67x00-hcd.h2
-rw-r--r--drivers/usb/c67x00/c67x00-sched.c2
-rw-r--r--drivers/usb/class/cdc-acm.c493
-rw-r--r--drivers/usb/class/cdc-acm.h26
-rw-r--r--drivers/usb/class/cdc-wdm.c21
-rw-r--r--drivers/usb/class/usblp.c1
-rw-r--r--drivers/usb/class/usbtmc.c3
-rw-r--r--drivers/usb/core/Kconfig16
-rw-r--r--drivers/usb/core/Makefile21
-rw-r--r--drivers/usb/core/buffer.c26
-rw-r--r--drivers/usb/core/config.c2
-rw-r--r--drivers/usb/core/devices.c44
-rw-r--r--drivers/usb/core/devio.c10
-rw-r--r--drivers/usb/core/driver.c190
-rw-r--r--drivers/usb/core/endpoint.c4
-rw-r--r--drivers/usb/core/file.c10
-rw-r--r--drivers/usb/core/hcd-pci.c72
-rw-r--r--drivers/usb/core/hcd.c303
-rw-r--r--drivers/usb/core/hub.c422
-rw-r--r--drivers/usb/core/inode.c23
-rw-r--r--drivers/usb/core/message.c61
-rw-r--r--drivers/usb/core/quirks.c23
-rw-r--r--drivers/usb/core/sysfs.c97
-rw-r--r--drivers/usb/core/urb.c16
-rw-r--r--drivers/usb/core/usb.c11
-rw-r--r--drivers/usb/core/usb.h20
-rw-r--r--drivers/usb/early/Makefile2
-rw-r--r--drivers/usb/early/ehci-dbgp.c9
-rw-r--r--drivers/usb/gadget/Kconfig158
-rw-r--r--drivers/usb/gadget/Makefile52
-rw-r--r--drivers/usb/gadget/amd5536udc.c31
-rw-r--r--drivers/usb/gadget/amd5536udc.h2
-rw-r--r--drivers/usb/gadget/at91_udc.c21
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c16
-rw-r--r--drivers/usb/gadget/audio.c10
-rw-r--r--drivers/usb/gadget/cdc2.c10
-rw-r--r--drivers/usb/gadget/ci13xxx_msm.c134
-rw-r--r--drivers/usb/gadget/ci13xxx_pci.c176
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c1048
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.h38
-rw-r--r--drivers/usb/gadget/composite.c238
-rw-r--r--drivers/usb/gadget/dbgp.c31
-rw-r--r--drivers/usb/gadget/dummy_hcd.c295
-rw-r--r--drivers/usb/gadget/epautoconf.c7
-rw-r--r--drivers/usb/gadget/ether.c16
-rw-r--r--drivers/usb/gadget/f_acm.c2
-rw-r--r--drivers/usb/gadget/f_audio.c7
-rw-r--r--drivers/usb/gadget/f_eem.c8
-rw-r--r--drivers/usb/gadget/f_fs.c461
-rw-r--r--drivers/usb/gadget/f_hid.c6
-rw-r--r--drivers/usb/gadget/f_loopback.c7
-rw-r--r--drivers/usb/gadget/f_mass_storage.c673
-rw-r--r--drivers/usb/gadget/f_ncm.c1407
-rw-r--r--drivers/usb/gadget/f_phonet.c15
-rw-r--r--drivers/usb/gadget/f_rndis.c3
-rw-r--r--drivers/usb/gadget/f_sourcesink.c5
-rw-r--r--drivers/usb/gadget/file_storage.c212
-rw-r--r--drivers/usb/gadget/fsl_mxc_udc.c18
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c47
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.h8
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c476
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.h10
-rw-r--r--drivers/usb/gadget/fusb300_udc.c1744
-rw-r--r--drivers/usb/gadget/fusb300_udc.h687
-rw-r--r--drivers/usb/gadget/g_ffs.c132
-rw-r--r--drivers/usb/gadget/gadget_chips.h50
-rw-r--r--drivers/usb/gadget/gmidi.c7
-rw-r--r--drivers/usb/gadget/goku_udc.c36
-rw-r--r--drivers/usb/gadget/goku_udc.h3
-rw-r--r--drivers/usb/gadget/hid.c10
-rw-r--r--drivers/usb/gadget/imx_udc.c20
-rw-r--r--drivers/usb/gadget/imx_udc.h3
-rw-r--r--drivers/usb/gadget/inode.c26
-rw-r--r--drivers/usb/gadget/langwell_udc.c1085
-rw-r--r--drivers/usb/gadget/langwell_udc.h15
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c2152
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.h259
-rw-r--r--drivers/usb/gadget/m66592-udc.c11
-rw-r--r--drivers/usb/gadget/mass_storage.c84
-rw-r--r--drivers/usb/gadget/multi.c36
-rw-r--r--drivers/usb/gadget/mv_udc.h294
-rw-r--r--drivers/usb/gadget/mv_udc_core.c2149
-rw-r--r--drivers/usb/gadget/mv_udc_phy.c214
-rw-r--r--drivers/usb/gadget/ncm.c248
-rw-r--r--drivers/usb/gadget/net2280.c13
-rw-r--r--drivers/usb/gadget/nokia.c13
-rw-r--r--drivers/usb/gadget/omap_udc.c29
-rw-r--r--drivers/usb/gadget/pch_udc.c3004
-rw-r--r--drivers/usb/gadget/printer.c33
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c91
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c27
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c18
-rw-r--r--drivers/usb/gadget/r8a66597-udc.h2
-rw-r--r--drivers/usb/gadget/rndis.c494
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c284
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c1352
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c94
-rw-r--r--drivers/usb/gadget/serial.c11
-rw-r--r--drivers/usb/gadget/storage_common.c74
-rw-r--r--drivers/usb/gadget/u_audio.c10
-rw-r--r--drivers/usb/gadget/u_ether.c19
-rw-r--r--drivers/usb/gadget/u_ether.h5
-rw-r--r--drivers/usb/gadget/u_serial.c54
-rw-r--r--drivers/usb/gadget/webcam.c11
-rw-r--r--drivers/usb/gadget/zero.c5
-rw-r--r--drivers/usb/host/Kconfig160
-rw-r--r--drivers/usb/host/Makefile25
-rw-r--r--drivers/usb/host/ehci-ath79.c204
-rw-r--r--drivers/usb/host/ehci-atmel.c11
-rw-r--r--drivers/usb/host/ehci-au1xxx.c14
-rw-r--r--drivers/usb/host/ehci-cns3xxx.c171
-rw-r--r--drivers/usb/host/ehci-dbg.c14
-rw-r--r--drivers/usb/host/ehci-fsl.c315
-rw-r--r--drivers/usb/host/ehci-fsl.h13
-rw-r--r--drivers/usb/host/ehci-grlib.c242
-rw-r--r--drivers/usb/host/ehci-hcd.c135
-rw-r--r--drivers/usb/host/ehci-hub.c49
-rw-r--r--drivers/usb/host/ehci-ixp4xx.c2
-rw-r--r--drivers/usb/host/ehci-lpm.c5
-rw-r--r--drivers/usb/host/ehci-mem.c28
-rw-r--r--drivers/usb/host/ehci-msm.c265
-rw-r--r--drivers/usb/host/ehci-mxc.c100
-rw-r--r--drivers/usb/host/ehci-octeon.c207
-rw-r--r--drivers/usb/host/ehci-omap.c726
-rw-r--r--drivers/usb/host/ehci-orion.c7
-rw-r--r--drivers/usb/host/ehci-pci.c81
-rw-r--r--drivers/usb/host/ehci-pmcmsp.c383
-rw-r--r--drivers/usb/host/ehci-ppc-of.c11
-rw-r--r--drivers/usb/host/ehci-ps3.c2
-rw-r--r--drivers/usb/host/ehci-q.c50
-rw-r--r--drivers/usb/host/ehci-s5p.c202
-rw-r--r--drivers/usb/host/ehci-sched.c68
-rw-r--r--drivers/usb/host/ehci-sh.c243
-rw-r--r--drivers/usb/host/ehci-spear.c212
-rw-r--r--drivers/usb/host/ehci-tegra.c787
-rw-r--r--drivers/usb/host/ehci-vt8500.c173
-rw-r--r--drivers/usb/host/ehci-w90x900.c5
-rw-r--r--drivers/usb/host/ehci-xilinx-of.c10
-rw-r--r--drivers/usb/host/ehci.h18
-rw-r--r--drivers/usb/host/fhci-hcd.c15
-rw-r--r--drivers/usb/host/fhci-tds.c12
-rw-r--r--drivers/usb/host/fhci.h4
-rw-r--r--drivers/usb/host/fsl-mph-dr-of.c313
-rw-r--r--drivers/usb/host/imx21-dbg.c2
-rw-r--r--drivers/usb/host/imx21-hcd.c297
-rw-r--r--drivers/usb/host/imx21-hcd.h8
-rw-r--r--drivers/usb/host/isp116x-hcd.c13
-rw-r--r--drivers/usb/host/isp116x.h2
-rw-r--r--drivers/usb/host/isp1362-hcd.c44
-rw-r--r--drivers/usb/host/isp1760-hcd.c2380
-rw-r--r--drivers/usb/host/isp1760-hcd.h132
-rw-r--r--drivers/usb/host/isp1760-if.c9
-rw-r--r--drivers/usb/host/octeon2-common.c200
-rw-r--r--drivers/usb/host/ohci-ath79.c151
-rw-r--r--drivers/usb/host/ohci-au1xxx.c2
-rw-r--r--drivers/usb/host/ohci-cns3xxx.c165
-rw-r--r--drivers/usb/host/ohci-dbg.c3
-rw-r--r--drivers/usb/host/ohci-hcd.c75
-rw-r--r--drivers/usb/host/ohci-hub.c13
-rw-r--r--drivers/usb/host/ohci-jz4740.c2
-rw-r--r--drivers/usb/host/ohci-lh7a404.c252
-rw-r--r--drivers/usb/host/ohci-octeon.c214
-rw-r--r--drivers/usb/host/ohci-omap3.c584
-rw-r--r--drivers/usb/host/ohci-pci.c126
-rw-r--r--drivers/usb/host/ohci-ppc-of.c9
-rw-r--r--drivers/usb/host/ohci-pxa27x.c14
-rw-r--r--drivers/usb/host/ohci-q.c4
-rw-r--r--drivers/usb/host/ohci-s3c2410.c58
-rw-r--r--drivers/usb/host/ohci-sh.c5
-rw-r--r--drivers/usb/host/ohci-sm501.c4
-rw-r--r--drivers/usb/host/ohci-spear.c240
-rw-r--r--drivers/usb/host/ohci-tmio.c8
-rw-r--r--drivers/usb/host/ohci.h15
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c31
-rw-r--r--drivers/usb/host/pci-quirks.c523
-rw-r--r--drivers/usb/host/pci-quirks.h12
-rw-r--r--drivers/usb/host/r8a66597-hcd.c10
-rw-r--r--drivers/usb/host/r8a66597.h2
-rw-r--r--drivers/usb/host/sl811-hcd.c16
-rw-r--r--drivers/usb/host/sl811_cs.c70
-rw-r--r--drivers/usb/host/u132-hcd.c22
-rw-r--r--drivers/usb/host/uhci-debug.c89
-rw-r--r--drivers/usb/host/uhci-grlib.c208
-rw-r--r--drivers/usb/host/uhci-hcd.c467
-rw-r--r--drivers/usb/host/uhci-hcd.h248
-rw-r--r--drivers/usb/host/uhci-hub.c41
-rw-r--r--drivers/usb/host/uhci-pci.c301
-rw-r--r--drivers/usb/host/uhci-q.c174
-rw-r--r--drivers/usb/host/whci/Kbuild2
-rw-r--r--drivers/usb/host/whci/hcd.c2
-rw-r--r--drivers/usb/host/whci/qset.c2
-rw-r--r--drivers/usb/host/xhci-dbg.c68
-rw-r--r--drivers/usb/host/xhci-ext-caps.h4
-rw-r--r--drivers/usb/host/xhci-hub.c756
-rw-r--r--drivers/usb/host/xhci-mem.c517
-rw-r--r--drivers/usb/host/xhci-pci.c213
-rw-r--r--drivers/usb/host/xhci-ring.c1197
-rw-r--r--drivers/usb/host/xhci.c978
-rw-r--r--drivers/usb/host/xhci.h332
-rw-r--r--drivers/usb/image/mdc800.c1
-rw-r--r--drivers/usb/image/microtek.c23
-rw-r--r--drivers/usb/misc/Kconfig13
-rw-r--r--drivers/usb/misc/Makefile45
-rw-r--r--drivers/usb/misc/adutux.c3
-rw-r--r--drivers/usb/misc/appledisplay.c1
-rw-r--r--drivers/usb/misc/cypress_cy7c63.c6
-rw-r--r--drivers/usb/misc/ftdi-elan.c7
-rw-r--r--drivers/usb/misc/idmouse.c1
-rw-r--r--drivers/usb/misc/iowarrior.c8
-rw-r--r--drivers/usb/misc/ldusb.c55
-rw-r--r--drivers/usb/misc/rio500.c1
-rw-r--r--drivers/usb/misc/sisusbvga/Makefile3
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c1
-rw-r--r--drivers/usb/misc/trancevibrator.c2
-rw-r--r--drivers/usb/misc/usblcd.c1
-rw-r--r--drivers/usb/misc/usbled.c122
-rw-r--r--drivers/usb/misc/usbsevseg.c10
-rw-r--r--drivers/usb/misc/usbtest.c1014
-rw-r--r--drivers/usb/misc/uss720.c10
-rw-r--r--drivers/usb/misc/yurex.c564
-rw-r--r--drivers/usb/mon/Makefile2
-rw-r--r--drivers/usb/mon/mon_bin.c35
-rw-r--r--drivers/usb/mon/mon_main.c2
-rw-r--r--drivers/usb/mon/mon_stat.c1
-rw-r--r--drivers/usb/mon/mon_text.c3
-rw-r--r--drivers/usb/musb/Kconfig80
-rw-r--r--drivers/usb/musb/Makefile73
-rw-r--r--drivers/usb/musb/am35x.c657
-rw-r--r--drivers/usb/musb/blackfin.c267
-rw-r--r--drivers/usb/musb/cppi_dma.c59
-rw-r--r--drivers/usb/musb/da8xx.c608
-rw-r--r--drivers/usb/musb/davinci.c189
-rw-r--r--drivers/usb/musb/musb_core.c506
-rw-r--r--drivers/usb/musb/musb_core.h210
-rw-r--r--drivers/usb/musb/musb_debug.h17
-rw-r--r--drivers/usb/musb/musb_debugfs.c1
-rw-r--r--drivers/usb/musb/musb_dma.h3
-rw-r--r--drivers/usb/musb/musb_gadget.c688
-rw-r--r--drivers/usb/musb/musb_gadget.h17
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c46
-rw-r--r--drivers/usb/musb/musb_host.c181
-rw-r--r--drivers/usb/musb/musb_io.h4
-rw-r--r--drivers/usb/musb/musb_regs.h7
-rw-r--r--drivers/usb/musb/musb_virthub.c31
-rw-r--r--drivers/usb/musb/musbhsdma.c37
-rw-r--r--drivers/usb/musb/musbhsdma.h21
-rw-r--r--drivers/usb/musb/omap2430.c416
-rw-r--r--drivers/usb/musb/tusb6010.c249
-rw-r--r--drivers/usb/musb/tusb6010_omap.c36
-rw-r--r--drivers/usb/musb/ux500.c218
-rw-r--r--drivers/usb/musb/ux500_dma.c422
-rw-r--r--drivers/usb/otg/Kconfig63
-rw-r--r--drivers/usb/otg/Makefile14
-rw-r--r--drivers/usb/otg/ab8500-usb.c585
-rw-r--r--drivers/usb/otg/fsl_otg.c1169
-rw-r--r--drivers/usb/otg/fsl_otg.h406
-rw-r--r--drivers/usb/otg/gpio_vbus.c14
-rw-r--r--drivers/usb/otg/isp1301_omap.c32
-rw-r--r--drivers/usb/otg/langwell_otg.c2347
-rw-r--r--drivers/usb/otg/msm_otg.c1761
-rw-r--r--drivers/usb/otg/nop-usb-xceiv.c2
-rw-r--r--drivers/usb/otg/otg.c35
-rw-r--r--drivers/usb/otg/otg_fsm.c349
-rw-r--r--drivers/usb/otg/otg_fsm.h154
-rw-r--r--drivers/usb/otg/twl4030-usb.c33
-rw-r--r--drivers/usb/otg/twl6030-usb.c526
-rw-r--r--drivers/usb/otg/ulpi.c60
-rw-r--r--drivers/usb/otg/ulpi_viewport.c80
-rw-r--r--drivers/usb/renesas_usbhs/Kconfig16
-rw-r--r--drivers/usb/renesas_usbhs/Makefile9
-rw-r--r--drivers/usb/renesas_usbhs/common.c437
-rw-r--r--drivers/usb/renesas_usbhs/common.h230
-rw-r--r--drivers/usb/renesas_usbhs/mod.c328
-rw-r--r--drivers/usb/renesas_usbhs/mod.h137
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c1385
-rw-r--r--drivers/usb/renesas_usbhs/pipe.c874
-rw-r--r--drivers/usb/renesas_usbhs/pipe.h104
-rw-r--r--drivers/usb/serial/Kconfig4
-rw-r--r--drivers/usb/serial/Makefile9
-rw-r--r--drivers/usb/serial/aircable.c4
-rw-r--r--drivers/usb/serial/ark3116.c46
-rw-r--r--drivers/usb/serial/belkin_sa.c8
-rw-r--r--drivers/usb/serial/ch341.c18
-rw-r--r--drivers/usb/serial/cp210x.c45
-rw-r--r--drivers/usb/serial/cypress_m8.c16
-rw-r--r--drivers/usb/serial/digi_acceleport.c24
-rw-r--r--drivers/usb/serial/ftdi_sio.c159
-rw-r--r--drivers/usb/serial/ftdi_sio.h3
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h119
-rw-r--r--drivers/usb/serial/garmin_gps.c21
-rw-r--r--drivers/usb/serial/generic.c20
-rw-r--r--drivers/usb/serial/io_edgeport.c81
-rw-r--r--drivers/usb/serial/io_edgeport.h2
-rw-r--r--drivers/usb/serial/io_tables.h5
-rw-r--r--drivers/usb/serial/io_ti.c41
-rw-r--r--drivers/usb/serial/iuu_phoenix.c6
-rw-r--r--drivers/usb/serial/keyspan.c16
-rw-r--r--drivers/usb/serial/keyspan.h11
-rw-r--r--drivers/usb/serial/keyspan_pda.c37
-rw-r--r--drivers/usb/serial/kl5kusb105.c8
-rw-r--r--drivers/usb/serial/kobil_sct.c14
-rw-r--r--drivers/usb/serial/mct_u232.c122
-rw-r--r--drivers/usb/serial/mct_u232.h9
-rw-r--r--drivers/usb/serial/mos7720.c71
-rw-r--r--drivers/usb/serial/mos7840.c66
-rw-r--r--drivers/usb/serial/moto_modem.c2
-rw-r--r--drivers/usb/serial/omninet.c2
-rw-r--r--drivers/usb/serial/opticon.c161
-rw-r--r--drivers/usb/serial/option.c105
-rw-r--r--drivers/usb/serial/oti6858.c18
-rw-r--r--drivers/usb/serial/pl2303.c18
-rw-r--r--drivers/usb/serial/pl2303.h1
-rw-r--r--drivers/usb/serial/qcaux.c3
-rw-r--r--drivers/usb/serial/qcserial.c64
-rw-r--r--drivers/usb/serial/siemens_mpi.c1
-rw-r--r--drivers/usb/serial/sierra.c25
-rw-r--r--drivers/usb/serial/spcp8x5.c14
-rw-r--r--drivers/usb/serial/ssu100.c110
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c54
-rw-r--r--drivers/usb/serial/usb-serial.c38
-rw-r--r--drivers/usb/serial/usb-wwan.h6
-rw-r--r--drivers/usb/serial/usb_debug.c1
-rw-r--r--drivers/usb/serial/usb_wwan.c141
-rw-r--r--drivers/usb/serial/visor.c23
-rw-r--r--drivers/usb/serial/whiteheat.c18
-rw-r--r--drivers/usb/storage/Kconfig40
-rw-r--r--drivers/usb/storage/Makefile39
-rw-r--r--drivers/usb/storage/ene_ub6250.c803
-rw-r--r--drivers/usb/storage/isd200.c3
-rw-r--r--drivers/usb/storage/realtek_cr.c675
-rw-r--r--drivers/usb/storage/scsiglue.c22
-rw-r--r--drivers/usb/storage/sddr09.c2
-rw-r--r--drivers/usb/storage/shuttle_usbat.c2
-rw-r--r--drivers/usb/storage/sierra_ms.c4
-rw-r--r--drivers/usb/storage/transport.c39
-rw-r--r--drivers/usb/storage/uas.c776
-rw-r--r--drivers/usb/storage/unusual_alauda.h4
-rw-r--r--drivers/usb/storage/unusual_cypress.h9
-rw-r--r--drivers/usb/storage/unusual_datafab.h20
-rw-r--r--drivers/usb/storage/unusual_devs.h638
-rw-r--r--drivers/usb/storage/unusual_ene_ub6250.h26
-rw-r--r--drivers/usb/storage/unusual_freecom.h2
-rw-r--r--drivers/usb/storage/unusual_isd200.h12
-rw-r--r--drivers/usb/storage/unusual_jumpshot.h2
-rw-r--r--drivers/usb/storage/unusual_karma.h2
-rw-r--r--drivers/usb/storage/unusual_onetouch.h4
-rw-r--r--drivers/usb/storage/unusual_realtek.h41
-rw-r--r--drivers/usb/storage/unusual_sddr09.h12
-rw-r--r--drivers/usb/storage/unusual_sddr55.h8
-rw-r--r--drivers/usb/storage/unusual_usbat.h8
-rw-r--r--drivers/usb/storage/usb.c50
-rw-r--r--drivers/usb/storage/usb.h2
-rw-r--r--drivers/usb/storage/usual-tables.c2
-rw-r--r--drivers/usb/usb-skeleton.c1
-rw-r--r--drivers/usb/wusbcore/Makefile19
-rw-r--r--drivers/usb/wusbcore/crypto.c4
-rw-r--r--drivers/usb/wusbcore/reservation.c2
-rw-r--r--drivers/usb/wusbcore/rh.c8
-rw-r--r--drivers/usb/wusbcore/wa-rpipe.c4
-rw-r--r--drivers/usb/wusbcore/wa-xfer.c8
-rw-r--r--drivers/usb/wusbcore/wusbhc.c2
-rw-r--r--drivers/usb/wusbcore/wusbhc.h4
371 files changed, 48833 insertions, 13624 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 4aa00e6e57ad..48f1781352f1 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -31,7 +31,6 @@ config USB_ARCH_HAS_OHCI
31 # ARM: 31 # ARM:
32 default y if SA1111 32 default y if SA1111
33 default y if ARCH_OMAP 33 default y if ARCH_OMAP
34 default y if ARCH_LH7A404
35 default y if ARCH_S3C2410 34 default y if ARCH_S3C2410
36 default y if PXA27x 35 default y if PXA27x
37 default y if PXA3xx 36 default y if PXA3xx
@@ -41,17 +40,14 @@ config USB_ARCH_HAS_OHCI
41 default y if MFD_TC6393XB 40 default y if MFD_TC6393XB
42 default y if ARCH_W90X900 41 default y if ARCH_W90X900
43 default y if ARCH_DAVINCI_DA8XX 42 default y if ARCH_DAVINCI_DA8XX
43 default y if ARCH_CNS3XXX
44 default y if PLAT_SPEAR
44 # PPC: 45 # PPC:
45 default y if STB03xxx 46 default y if STB03xxx
46 default y if PPC_MPC52xx 47 default y if PPC_MPC52xx
47 # MIPS: 48 # MIPS:
48 default y if MIPS_ALCHEMY 49 default y if MIPS_ALCHEMY
49 default y if MACH_JZ4740 50 default y if MACH_JZ4740
50 # SH:
51 default y if CPU_SUBTYPE_SH7720
52 default y if CPU_SUBTYPE_SH7721
53 default y if CPU_SUBTYPE_SH7763
54 default y if CPU_SUBTYPE_SH7786
55 # more: 51 # more:
56 default PCI 52 default PCI
57 53
@@ -59,12 +55,20 @@ config USB_ARCH_HAS_OHCI
59config USB_ARCH_HAS_EHCI 55config USB_ARCH_HAS_EHCI
60 boolean 56 boolean
61 default y if PPC_83xx 57 default y if PPC_83xx
58 default y if PPC_MPC512x
62 default y if SOC_AU1200 59 default y if SOC_AU1200
63 default y if ARCH_IXP4XX 60 default y if ARCH_IXP4XX
64 default y if ARCH_W90X900 61 default y if ARCH_W90X900
65 default y if ARCH_AT91SAM9G45 62 default y if ARCH_AT91SAM9G45
66 default y if ARCH_MXC 63 default y if ARCH_MXC
67 default y if ARCH_OMAP3 64 default y if ARCH_OMAP3
65 default y if ARCH_CNS3XXX
66 default y if ARCH_VT8500
67 default y if PLAT_SPEAR
68 default y if PLAT_S5P
69 default y if ARCH_MSM
70 default y if MICROBLAZE
71 default y if SPARC_LEON
68 default PCI 72 default PCI
69 73
70# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. 74# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
@@ -114,6 +118,8 @@ source "drivers/usb/host/Kconfig"
114 118
115source "drivers/usb/musb/Kconfig" 119source "drivers/usb/musb/Kconfig"
116 120
121source "drivers/usb/renesas_usbhs/Kconfig"
122
117source "drivers/usb/class/Kconfig" 123source "drivers/usb/class/Kconfig"
118 124
119source "drivers/usb/storage/Kconfig" 125source "drivers/usb/storage/Kconfig"
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 239f050efa35..30ddf8dc4f72 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_USB_R8A66597_HCD) += host/
22obj-$(CONFIG_USB_HWA_HCD) += host/ 22obj-$(CONFIG_USB_HWA_HCD) += host/
23obj-$(CONFIG_USB_ISP1760_HCD) += host/ 23obj-$(CONFIG_USB_ISP1760_HCD) += host/
24obj-$(CONFIG_USB_IMX21_HCD) += host/ 24obj-$(CONFIG_USB_IMX21_HCD) += host/
25obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
25 26
26obj-$(CONFIG_USB_C67X00_HCD) += c67x00/ 27obj-$(CONFIG_USB_C67X00_HCD) += c67x00/
27 28
@@ -45,3 +46,8 @@ obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/
45 46
46obj-$(CONFIG_USB_ATM) += atm/ 47obj-$(CONFIG_USB_ATM) += atm/
47obj-$(CONFIG_USB_SPEEDTOUCH) += atm/ 48obj-$(CONFIG_USB_SPEEDTOUCH) += atm/
49
50obj-$(CONFIG_USB_MUSB_HDRC) += musb/
51obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs/
52obj-$(CONFIG_USB_OTG_UTILS) += otg/
53obj-$(CONFIG_USB_GADGET) += gadget/
diff --git a/drivers/usb/atm/Makefile b/drivers/usb/atm/Makefile
index 4c4a776ab1cd..a5d792ec3ad5 100644
--- a/drivers/usb/atm/Makefile
+++ b/drivers/usb/atm/Makefile
@@ -2,12 +2,10 @@
2# Makefile for USB ATM/xDSL drivers 2# Makefile for USB ATM/xDSL drivers
3# 3#
4 4
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6
5obj-$(CONFIG_USB_CXACRU) += cxacru.o 7obj-$(CONFIG_USB_CXACRU) += cxacru.o
6obj-$(CONFIG_USB_SPEEDTOUCH) += speedtch.o 8obj-$(CONFIG_USB_SPEEDTOUCH) += speedtch.o
7obj-$(CONFIG_USB_UEAGLEATM) += ueagle-atm.o 9obj-$(CONFIG_USB_UEAGLEATM) += ueagle-atm.o
8obj-$(CONFIG_USB_ATM) += usbatm.o 10obj-$(CONFIG_USB_ATM) += usbatm.o
9obj-$(CONFIG_USB_XUSBATM) += xusbatm.o 11obj-$(CONFIG_USB_XUSBATM) += xusbatm.o
10
11ifeq ($(CONFIG_USB_DEBUG),y)
12EXTRA_CFLAGS += -DDEBUG
13endif
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index 5af23cc5ea9f..a845f8b8382f 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -1247,7 +1247,7 @@ static void cxacru_unbind(struct usbatm_data *usbatm_instance,
1247 mutex_unlock(&instance->poll_state_serialize); 1247 mutex_unlock(&instance->poll_state_serialize);
1248 1248
1249 if (is_polling) 1249 if (is_polling)
1250 cancel_rearming_delayed_work(&instance->poll_work); 1250 cancel_delayed_work_sync(&instance->poll_work);
1251 1251
1252 usb_kill_urb(instance->snd_urb); 1252 usb_kill_urb(instance->snd_urb);
1253 usb_kill_urb(instance->rcv_urb); 1253 usb_kill_urb(instance->rcv_urb);
@@ -1344,8 +1344,24 @@ static struct usbatm_driver cxacru_driver = {
1344 .tx_padding = 11, 1344 .tx_padding = 11,
1345}; 1345};
1346 1346
1347static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) 1347static int cxacru_usb_probe(struct usb_interface *intf,
1348 const struct usb_device_id *id)
1348{ 1349{
1350 struct usb_device *usb_dev = interface_to_usbdev(intf);
1351 char buf[15];
1352
1353 /* Avoid ADSL routers (cx82310_eth).
1354 * Abort if bDeviceClass is 0xff and iProduct is "USB NET CARD".
1355 */
1356 if (usb_dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC
1357 && usb_string(usb_dev, usb_dev->descriptor.iProduct,
1358 buf, sizeof(buf)) > 0) {
1359 if (!strcmp(buf, "USB NET CARD")) {
1360 dev_info(&intf->dev, "ignoring cx82310_eth device\n");
1361 return -ENODEV;
1362 }
1363 }
1364
1349 return usbatm_usb_probe(intf, id, &cxacru_driver); 1365 return usbatm_usb_probe(intf, id, &cxacru_driver);
1350} 1366}
1351 1367
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 4716e707de59..0842cfbf60cf 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -139,7 +139,8 @@ struct speedtch_instance_data {
139 139
140 struct speedtch_params params; /* set in probe, constant afterwards */ 140 struct speedtch_params params; /* set in probe, constant afterwards */
141 141
142 struct delayed_work status_checker; 142 struct timer_list status_check_timer;
143 struct work_struct status_check_work;
143 144
144 unsigned char last_status; 145 unsigned char last_status;
145 146
@@ -498,7 +499,7 @@ static void speedtch_check_status(struct work_struct *work)
498{ 499{
499 struct speedtch_instance_data *instance = 500 struct speedtch_instance_data *instance =
500 container_of(work, struct speedtch_instance_data, 501 container_of(work, struct speedtch_instance_data,
501 status_checker.work); 502 status_check_work);
502 struct usbatm_data *usbatm = instance->usbatm; 503 struct usbatm_data *usbatm = instance->usbatm;
503 struct atm_dev *atm_dev = usbatm->atm_dev; 504 struct atm_dev *atm_dev = usbatm->atm_dev;
504 unsigned char *buf = instance->scratch_buffer; 505 unsigned char *buf = instance->scratch_buffer;
@@ -575,11 +576,11 @@ static void speedtch_status_poll(unsigned long data)
575{ 576{
576 struct speedtch_instance_data *instance = (void *)data; 577 struct speedtch_instance_data *instance = (void *)data;
577 578
578 schedule_delayed_work(&instance->status_checker, 0); 579 schedule_work(&instance->status_check_work);
579 580
580 /* The following check is racy, but the race is harmless */ 581 /* The following check is racy, but the race is harmless */
581 if (instance->poll_delay < MAX_POLL_DELAY) 582 if (instance->poll_delay < MAX_POLL_DELAY)
582 mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(instance->poll_delay)); 583 mod_timer(&instance->status_check_timer, jiffies + msecs_to_jiffies(instance->poll_delay));
583 else 584 else
584 atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n"); 585 atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n");
585} 586}
@@ -595,7 +596,7 @@ static void speedtch_resubmit_int(unsigned long data)
595 if (int_urb) { 596 if (int_urb) {
596 ret = usb_submit_urb(int_urb, GFP_ATOMIC); 597 ret = usb_submit_urb(int_urb, GFP_ATOMIC);
597 if (!ret) 598 if (!ret)
598 schedule_delayed_work(&instance->status_checker, 0); 599 schedule_work(&instance->status_check_work);
599 else { 600 else {
600 atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); 601 atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
601 mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); 602 mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY));
@@ -624,7 +625,7 @@ static void speedtch_handle_int(struct urb *int_urb)
624 } 625 }
625 626
626 if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) { 627 if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) {
627 del_timer(&instance->status_checker.timer); 628 del_timer(&instance->status_check_timer);
628 atm_info(usbatm, "DSL line goes up\n"); 629 atm_info(usbatm, "DSL line goes up\n");
629 } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) { 630 } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) {
630 atm_info(usbatm, "DSL line goes down\n"); 631 atm_info(usbatm, "DSL line goes down\n");
@@ -640,7 +641,7 @@ static void speedtch_handle_int(struct urb *int_urb)
640 641
641 if ((int_urb = instance->int_urb)) { 642 if ((int_urb = instance->int_urb)) {
642 ret = usb_submit_urb(int_urb, GFP_ATOMIC); 643 ret = usb_submit_urb(int_urb, GFP_ATOMIC);
643 schedule_delayed_work(&instance->status_checker, 0); 644 schedule_work(&instance->status_check_work);
644 if (ret < 0) { 645 if (ret < 0) {
645 atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); 646 atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
646 goto fail; 647 goto fail;
@@ -686,7 +687,7 @@ static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_de
686 } 687 }
687 688
688 /* Start status polling */ 689 /* Start status polling */
689 mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(1000)); 690 mod_timer(&instance->status_check_timer, jiffies + msecs_to_jiffies(1000));
690 691
691 return 0; 692 return 0;
692} 693}
@@ -698,7 +699,7 @@ static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_de
698 699
699 atm_dbg(usbatm, "%s entered\n", __func__); 700 atm_dbg(usbatm, "%s entered\n", __func__);
700 701
701 del_timer_sync(&instance->status_checker.timer); 702 del_timer_sync(&instance->status_check_timer);
702 703
703 /* 704 /*
704 * Since resubmit_timer and int_urb can schedule themselves and 705 * Since resubmit_timer and int_urb can schedule themselves and
@@ -717,7 +718,7 @@ static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_de
717 del_timer_sync(&instance->resubmit_timer); 718 del_timer_sync(&instance->resubmit_timer);
718 usb_free_urb(int_urb); 719 usb_free_urb(int_urb);
719 720
720 flush_scheduled_work(); 721 flush_work_sync(&instance->status_check_work);
721} 722}
722 723
723static int speedtch_pre_reset(struct usb_interface *intf) 724static int speedtch_pre_reset(struct usb_interface *intf)
@@ -869,10 +870,11 @@ static int speedtch_bind(struct usbatm_data *usbatm,
869 870
870 usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0); 871 usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0);
871 872
872 INIT_DELAYED_WORK(&instance->status_checker, speedtch_check_status); 873 INIT_WORK(&instance->status_check_work, speedtch_check_status);
874 init_timer(&instance->status_check_timer);
873 875
874 instance->status_checker.timer.function = speedtch_status_poll; 876 instance->status_check_timer.function = speedtch_status_poll;
875 instance->status_checker.timer.data = (unsigned long)instance; 877 instance->status_check_timer.data = (unsigned long)instance;
876 instance->last_status = 0xff; 878 instance->last_status = 0xff;
877 instance->poll_delay = MIN_POLL_DELAY; 879 instance->poll_delay = MIN_POLL_DELAY;
878 880
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index ea071a5b6eee..e71521ce3010 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -168,7 +168,6 @@ struct uea_softc {
168 union cmv_dsc cmv_dsc; 168 union cmv_dsc cmv_dsc;
169 169
170 struct work_struct task; 170 struct work_struct task;
171 struct workqueue_struct *work_q;
172 u16 pageno; 171 u16 pageno;
173 u16 ovl; 172 u16 ovl;
174 173
@@ -1284,7 +1283,7 @@ static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1284 1283
1285 /* in bulk mode the modem have problem with high rate 1284 /* in bulk mode the modem have problem with high rate
1286 * changing internal timing could improve things, but the 1285 * changing internal timing could improve things, but the
1287 * value is misterious. 1286 * value is mysterious.
1288 * ADI930 don't support it (-EPIPE error). 1287 * ADI930 don't support it (-EPIPE error).
1289 */ 1288 */
1290 1289
@@ -1744,7 +1743,7 @@ static int uea_send_cmvs_e1(struct uea_softc *sc)
1744 goto out; 1743 goto out;
1745 } 1744 }
1746 } else { 1745 } else {
1747 /* This realy should not happen */ 1746 /* This really should not happen */
1748 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver); 1747 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1749 goto out; 1748 goto out;
1750 } 1749 }
@@ -1799,7 +1798,7 @@ static int uea_send_cmvs_e4(struct uea_softc *sc)
1799 goto out; 1798 goto out;
1800 } 1799 }
1801 } else { 1800 } else {
1802 /* This realy should not happen */ 1801 /* This really should not happen */
1803 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver); 1802 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1804 goto out; 1803 goto out;
1805 } 1804 }
@@ -1830,7 +1829,7 @@ static int uea_start_reset(struct uea_softc *sc)
1830 1829
1831 /* mask interrupt */ 1830 /* mask interrupt */
1832 sc->booting = 1; 1831 sc->booting = 1;
1833 /* We need to set this here because, a ack timeout could have occured, 1832 /* We need to set this here because, a ack timeout could have occurred,
1834 * but before we start the reboot, the ack occurs and set this to 1. 1833 * but before we start the reboot, the ack occurs and set this to 1.
1835 * So we will failed to wait Ready CMV. 1834 * So we will failed to wait Ready CMV.
1836 */ 1835 */
@@ -1879,7 +1878,7 @@ static int uea_start_reset(struct uea_softc *sc)
1879 /* start loading DSP */ 1878 /* start loading DSP */
1880 sc->pageno = 0; 1879 sc->pageno = 0;
1881 sc->ovl = 0; 1880 sc->ovl = 0;
1882 queue_work(sc->work_q, &sc->task); 1881 schedule_work(&sc->task);
1883 1882
1884 /* wait for modem ready CMV */ 1883 /* wait for modem ready CMV */
1885 ret = wait_cmv_ack(sc); 1884 ret = wait_cmv_ack(sc);
@@ -2091,14 +2090,14 @@ static void uea_schedule_load_page_e1(struct uea_softc *sc,
2091{ 2090{
2092 sc->pageno = intr->e1_bSwapPageNo; 2091 sc->pageno = intr->e1_bSwapPageNo;
2093 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4; 2092 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2094 queue_work(sc->work_q, &sc->task); 2093 schedule_work(&sc->task);
2095} 2094}
2096 2095
2097static void uea_schedule_load_page_e4(struct uea_softc *sc, 2096static void uea_schedule_load_page_e4(struct uea_softc *sc,
2098 struct intr_pkt *intr) 2097 struct intr_pkt *intr)
2099{ 2098{
2100 sc->pageno = intr->e4_bSwapPageNo; 2099 sc->pageno = intr->e4_bSwapPageNo;
2101 queue_work(sc->work_q, &sc->task); 2100 schedule_work(&sc->task);
2102} 2101}
2103 2102
2104/* 2103/*
@@ -2170,13 +2169,6 @@ static int uea_boot(struct uea_softc *sc)
2170 2169
2171 init_waitqueue_head(&sc->sync_q); 2170 init_waitqueue_head(&sc->sync_q);
2172 2171
2173 sc->work_q = create_workqueue("ueagle-dsp");
2174 if (!sc->work_q) {
2175 uea_err(INS_TO_USBDEV(sc), "cannot allocate workqueue\n");
2176 uea_leaves(INS_TO_USBDEV(sc));
2177 return -ENOMEM;
2178 }
2179
2180 if (UEA_CHIP_VERSION(sc) == ADI930) 2172 if (UEA_CHIP_VERSION(sc) == ADI930)
2181 load_XILINX_firmware(sc); 2173 load_XILINX_firmware(sc);
2182 2174
@@ -2206,8 +2198,11 @@ static int uea_boot(struct uea_softc *sc)
2206 goto err1; 2198 goto err1;
2207 } 2199 }
2208 2200
2209 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm"); 2201 /* Create worker thread, but don't start it here. Start it after
2210 if (sc->kthread == ERR_PTR(-ENOMEM)) { 2202 * all usbatm generic initialization is done.
2203 */
2204 sc->kthread = kthread_create(uea_kthread, sc, "ueagle-atm");
2205 if (IS_ERR(sc->kthread)) {
2211 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n"); 2206 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2212 goto err2; 2207 goto err2;
2213 } 2208 }
@@ -2222,7 +2217,6 @@ err1:
2222 sc->urb_int = NULL; 2217 sc->urb_int = NULL;
2223 kfree(intr); 2218 kfree(intr);
2224err0: 2219err0:
2225 destroy_workqueue(sc->work_q);
2226 uea_leaves(INS_TO_USBDEV(sc)); 2220 uea_leaves(INS_TO_USBDEV(sc));
2227 return -ENOMEM; 2221 return -ENOMEM;
2228} 2222}
@@ -2243,8 +2237,8 @@ static void uea_stop(struct uea_softc *sc)
2243 kfree(sc->urb_int->transfer_buffer); 2237 kfree(sc->urb_int->transfer_buffer);
2244 usb_free_urb(sc->urb_int); 2238 usb_free_urb(sc->urb_int);
2245 2239
2246 /* stop any pending boot process, when no one can schedule work */ 2240 /* flush the work item, when no one can schedule it */
2247 destroy_workqueue(sc->work_q); 2241 flush_work_sync(&sc->task);
2248 2242
2249 if (sc->dsp_firm) 2243 if (sc->dsp_firm)
2250 release_firmware(sc->dsp_firm); 2244 release_firmware(sc->dsp_firm);
@@ -2301,7 +2295,7 @@ out:
2301 return ret; 2295 return ret;
2302} 2296}
2303 2297
2304static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot); 2298static DEVICE_ATTR(stat_status, S_IWUSR | S_IRUGO, read_status, reboot);
2305 2299
2306static ssize_t read_human_status(struct device *dev, 2300static ssize_t read_human_status(struct device *dev,
2307 struct device_attribute *attr, char *buf) 2301 struct device_attribute *attr, char *buf)
@@ -2364,8 +2358,7 @@ out:
2364 return ret; 2358 return ret;
2365} 2359}
2366 2360
2367static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, 2361static DEVICE_ATTR(stat_human_status, S_IRUGO, read_human_status, NULL);
2368 read_human_status, NULL);
2369 2362
2370static ssize_t read_delin(struct device *dev, struct device_attribute *attr, 2363static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2371 char *buf) 2364 char *buf)
@@ -2397,7 +2390,7 @@ out:
2397 return ret; 2390 return ret;
2398} 2391}
2399 2392
2400static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL); 2393static DEVICE_ATTR(stat_delin, S_IRUGO, read_delin, NULL);
2401 2394
2402#define UEA_ATTR(name, reset) \ 2395#define UEA_ATTR(name, reset) \
2403 \ 2396 \
@@ -2625,6 +2618,7 @@ static struct usbatm_driver uea_usbatm_driver = {
2625static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id) 2618static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2626{ 2619{
2627 struct usb_device *usb = interface_to_usbdev(intf); 2620 struct usb_device *usb = interface_to_usbdev(intf);
2621 int ret;
2628 2622
2629 uea_enters(usb); 2623 uea_enters(usb);
2630 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n", 2624 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
@@ -2638,7 +2632,19 @@ static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2638 if (UEA_IS_PREFIRM(id)) 2632 if (UEA_IS_PREFIRM(id))
2639 return uea_load_firmware(usb, UEA_CHIP_VERSION(id)); 2633 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2640 2634
2641 return usbatm_usb_probe(intf, id, &uea_usbatm_driver); 2635 ret = usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2636 if (ret == 0) {
2637 struct usbatm_data *usbatm = usb_get_intfdata(intf);
2638 struct uea_softc *sc = usbatm->driver_data;
2639
2640 /* Ensure carrier is initialized to off as early as possible */
2641 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
2642
2643 /* Only start the worker thread when all init is done */
2644 wake_up_process(sc->kthread);
2645 }
2646
2647 return ret;
2642} 2648}
2643 2649
2644static void uea_disconnect(struct usb_interface *intf) 2650static void uea_disconnect(struct usb_interface *intf)
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 05bf5a27b5b0..989e16e4ab5c 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -951,7 +951,9 @@ static int usbatm_atm_init(struct usbatm_data *instance)
951 * condition: callbacks we register can be executed at once, before we have 951 * condition: callbacks we register can be executed at once, before we have
952 * initialized the struct atm_dev. To protect against this, all callbacks 952 * initialized the struct atm_dev. To protect against this, all callbacks
953 * abort if atm_dev->dev_data is NULL. */ 953 * abort if atm_dev->dev_data is NULL. */
954 atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL); 954 atm_dev = atm_dev_register(instance->driver_name,
955 &instance->usb_intf->dev, &usbatm_atm_devops,
956 -1, NULL);
955 if (!atm_dev) { 957 if (!atm_dev) {
956 usb_err(instance, "%s: failed to register ATM device!\n", __func__); 958 usb_err(instance, "%s: failed to register ATM device!\n", __func__);
957 return -1; 959 return -1;
@@ -966,14 +968,6 @@ static int usbatm_atm_init(struct usbatm_data *instance)
966 /* temp init ATM device, set to 128kbit */ 968 /* temp init ATM device, set to 128kbit */
967 atm_dev->link_rate = 128 * 1000 / 424; 969 atm_dev->link_rate = 128 * 1000 / 424;
968 970
969 ret = sysfs_create_link(&atm_dev->class_dev.kobj,
970 &instance->usb_intf->dev.kobj, "device");
971 if (ret) {
972 atm_err(instance, "%s: sysfs_create_link failed: %d\n",
973 __func__, ret);
974 goto fail_sysfs;
975 }
976
977 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) { 971 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) {
978 atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret); 972 atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret);
979 goto fail; 973 goto fail;
@@ -992,8 +986,6 @@ static int usbatm_atm_init(struct usbatm_data *instance)
992 return 0; 986 return 0;
993 987
994 fail: 988 fail:
995 sysfs_remove_link(&atm_dev->class_dev.kobj, "device");
996 fail_sysfs:
997 instance->atm_dev = NULL; 989 instance->atm_dev = NULL;
998 atm_dev_deregister(atm_dev); /* usbatm_atm_dev_close will eventually be called */ 990 atm_dev_deregister(atm_dev); /* usbatm_atm_dev_close will eventually be called */
999 return ret; 991 return ret;
@@ -1329,7 +1321,6 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
1329 1321
1330 /* ATM finalize */ 1322 /* ATM finalize */
1331 if (instance->atm_dev) { 1323 if (instance->atm_dev) {
1332 sysfs_remove_link(&instance->atm_dev->class_dev.kobj, "device");
1333 atm_dev_deregister(instance->atm_dev); 1324 atm_dev_deregister(instance->atm_dev);
1334 instance->atm_dev = NULL; 1325 instance->atm_dev = NULL;
1335 } 1326 }
diff --git a/drivers/usb/c67x00/Makefile b/drivers/usb/c67x00/Makefile
index 868bc41b5980..b1218683c8ec 100644
--- a/drivers/usb/c67x00/Makefile
+++ b/drivers/usb/c67x00/Makefile
@@ -2,8 +2,8 @@
2# Makefile for Cypress C67X00 USB Controller 2# Makefile for Cypress C67X00 USB Controller
3# 3#
4 4
5ccflags-$(CONFIG_USB_DEBUG) += -DDEBUG 5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6 6
7obj-$(CONFIG_USB_C67X00_HCD) += c67x00.o 7obj-$(CONFIG_USB_C67X00_HCD) += c67x00.o
8 8
9c67x00-objs := c67x00-drv.o c67x00-ll-hpi.o c67x00-hcd.o c67x00-sched.o 9c67x00-y := c67x00-drv.o c67x00-ll-hpi.o c67x00-hcd.o c67x00-sched.o
diff --git a/drivers/usb/c67x00/c67x00-drv.c b/drivers/usb/c67x00/c67x00-drv.c
index b6d49234e521..62050f7a4f97 100644
--- a/drivers/usb/c67x00/c67x00-drv.c
+++ b/drivers/usb/c67x00/c67x00-drv.c
@@ -27,7 +27,7 @@
27 * the link between the common hardware parts and the subdrivers (e.g. 27 * the link between the common hardware parts and the subdrivers (e.g.
28 * interrupt handling). 28 * interrupt handling).
29 * 29 *
30 * The c67x00 has 2 SIE's (serial interface engine) wich can be configured 30 * The c67x00 has 2 SIE's (serial interface engine) which can be configured
31 * to be host, device or OTG (with some limitations, E.G. only SIE1 can be OTG). 31 * to be host, device or OTG (with some limitations, E.G. only SIE1 can be OTG).
32 * 32 *
33 * Depending on the platform configuration, the SIE's are created and 33 * Depending on the platform configuration, the SIE's are created and
diff --git a/drivers/usb/c67x00/c67x00-hcd.h b/drivers/usb/c67x00/c67x00-hcd.h
index 74e44621e313..e3d493d4d61a 100644
--- a/drivers/usb/c67x00/c67x00-hcd.h
+++ b/drivers/usb/c67x00/c67x00-hcd.h
@@ -34,7 +34,7 @@
34/* 34/*
35 * The following parameters depend on the CPU speed, bus speed, ... 35 * The following parameters depend on the CPU speed, bus speed, ...
36 * These can be tuned for specific use cases, e.g. if isochronous transfers 36 * These can be tuned for specific use cases, e.g. if isochronous transfers
37 * are very important, bandwith can be sacrificed to guarantee that the 37 * are very important, bandwidth can be sacrificed to guarantee that the
38 * 1ms deadline will be met. 38 * 1ms deadline will be met.
39 * If bulk transfers are important, the MAX_FRAME_BW can be increased, 39 * If bulk transfers are important, the MAX_FRAME_BW can be increased,
40 * but some (or many) isochronous deadlines might not be met. 40 * but some (or many) isochronous deadlines might not be met.
diff --git a/drivers/usb/c67x00/c67x00-sched.c b/drivers/usb/c67x00/c67x00-sched.c
index f6b3c253f3fa..a03fbc15fa9c 100644
--- a/drivers/usb/c67x00/c67x00-sched.c
+++ b/drivers/usb/c67x00/c67x00-sched.c
@@ -907,7 +907,7 @@ static inline int c67x00_end_of_data(struct c67x00_td *td)
907 907
908/* Remove all td's from the list which come 908/* Remove all td's from the list which come
909 * after last_td and are meant for the same pipe. 909 * after last_td and are meant for the same pipe.
910 * This is used when a short packet has occured */ 910 * This is used when a short packet has occurred */
911static inline void c67x00_clear_pipe(struct c67x00_hcd *c67x00, 911static inline void c67x00_clear_pipe(struct c67x00_hcd *c67x00,
912 struct c67x00_td *last_td) 912 struct c67x00_td *last_td)
913{ 913{
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index bc62fae0680f..dac7676ce21b 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -7,35 +7,12 @@
7 * Copyright (c) 2000 Vojtech Pavlik <vojtech@suse.cz> 7 * Copyright (c) 2000 Vojtech Pavlik <vojtech@suse.cz>
8 * Copyright (c) 2004 Oliver Neukum <oliver@neukum.name> 8 * Copyright (c) 2004 Oliver Neukum <oliver@neukum.name>
9 * Copyright (c) 2005 David Kubicek <dave@awk.cz> 9 * Copyright (c) 2005 David Kubicek <dave@awk.cz>
10 * Copyright (c) 2011 Johan Hovold <jhovold@gmail.com>
10 * 11 *
11 * USB Abstract Control Model driver for USB modems and ISDN adapters 12 * USB Abstract Control Model driver for USB modems and ISDN adapters
12 * 13 *
13 * Sponsored by SuSE 14 * Sponsored by SuSE
14 * 15 *
15 * ChangeLog:
16 * v0.9 - thorough cleaning, URBification, almost a rewrite
17 * v0.10 - some more cleanups
18 * v0.11 - fixed flow control, read error doesn't stop reads
19 * v0.12 - added TIOCM ioctls, added break handling, made struct acm
20 * kmalloced
21 * v0.13 - added termios, added hangup
22 * v0.14 - sized down struct acm
23 * v0.15 - fixed flow control again - characters could be lost
24 * v0.16 - added code for modems with swapped data and control interfaces
25 * v0.17 - added new style probing
26 * v0.18 - fixed new style probing for devices with more configurations
27 * v0.19 - fixed CLOCAL handling (thanks to Richard Shih-Ping Chan)
28 * v0.20 - switched to probing on interface (rather than device) class
29 * v0.21 - revert to probing on device for devices with multiple configs
30 * v0.22 - probe only the control interface. if usbcore doesn't choose the
31 * config we want, sysadmin changes bConfigurationValue in sysfs.
32 * v0.23 - use softirq for rx processing, as needed by tty layer
33 * v0.24 - change probe method to evaluate CDC union descriptor
34 * v0.25 - downstream tasks paralelized to maximize throughput
35 * v0.26 - multiple write urbs, writesize increased
36 */
37
38/*
39 * This program is free software; you can redistribute it and/or modify 16 * This program is free software; you can redistribute it and/or modify
40 * it under the terms of the GNU General Public License as published by 17 * it under the terms of the GNU General Public License as published by
41 * the Free Software Foundation; either version 2 of the License, or 18 * the Free Software Foundation; either version 2 of the License, or
@@ -74,13 +51,7 @@
74#include "cdc-acm.h" 51#include "cdc-acm.h"
75 52
76 53
77#define ACM_CLOSE_TIMEOUT 15 /* seconds to let writes drain */ 54#define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek, Johan Hovold"
78
79/*
80 * Version Information
81 */
82#define DRIVER_VERSION "v0.26"
83#define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek"
84#define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters" 55#define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters"
85 56
86static struct usb_driver acm_driver; 57static struct usb_driver acm_driver;
@@ -94,12 +65,6 @@ static DEFINE_MUTEX(open_mutex);
94static const struct tty_port_operations acm_port_ops = { 65static const struct tty_port_operations acm_port_ops = {
95}; 66};
96 67
97#ifdef VERBOSE_DEBUG
98#define verbose 1
99#else
100#define verbose 0
101#endif
102
103/* 68/*
104 * Functions for ACM control messages. 69 * Functions for ACM control messages.
105 */ 70 */
@@ -111,8 +76,9 @@ static int acm_ctrl_msg(struct acm *acm, int request, int value,
111 request, USB_RT_ACM, value, 76 request, USB_RT_ACM, value,
112 acm->control->altsetting[0].desc.bInterfaceNumber, 77 acm->control->altsetting[0].desc.bInterfaceNumber,
113 buf, len, 5000); 78 buf, len, 5000);
114 dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", 79 dev_dbg(&acm->control->dev,
115 request, value, len, retval); 80 "%s - rq 0x%02x, val %#x, len %#x, result %d\n",
81 __func__, request, value, len, retval);
116 return retval < 0 ? retval : 0; 82 return retval < 0 ? retval : 0;
117} 83}
118 84
@@ -192,7 +158,9 @@ static int acm_start_wb(struct acm *acm, struct acm_wb *wb)
192 158
193 rc = usb_submit_urb(wb->urb, GFP_ATOMIC); 159 rc = usb_submit_urb(wb->urb, GFP_ATOMIC);
194 if (rc < 0) { 160 if (rc < 0) {
195 dbg("usb_submit_urb(write bulk) failed: %d", rc); 161 dev_err(&acm->data->dev,
162 "%s - usb_submit_urb(write bulk) failed: %d\n",
163 __func__, rc);
196 acm_write_done(acm, wb); 164 acm_write_done(acm, wb);
197 } 165 }
198 return rc; 166 return rc;
@@ -211,7 +179,8 @@ static int acm_write_start(struct acm *acm, int wbn)
211 return -ENODEV; 179 return -ENODEV;
212 } 180 }
213 181
214 dbg("%s susp_count: %d", __func__, acm->susp_count); 182 dev_vdbg(&acm->data->dev, "%s - susp_count %d\n", __func__,
183 acm->susp_count);
215 usb_autopm_get_interface_async(acm->control); 184 usb_autopm_get_interface_async(acm->control);
216 if (acm->susp_count) { 185 if (acm->susp_count) {
217 if (!acm->delayed_wb) 186 if (!acm->delayed_wb)
@@ -287,21 +256,27 @@ static void acm_ctrl_irq(struct urb *urb)
287 case -ENOENT: 256 case -ENOENT:
288 case -ESHUTDOWN: 257 case -ESHUTDOWN:
289 /* this urb is terminated, clean up */ 258 /* this urb is terminated, clean up */
290 dbg("%s - urb shutting down with status: %d", __func__, status); 259 dev_dbg(&acm->control->dev,
260 "%s - urb shutting down with status: %d\n",
261 __func__, status);
291 return; 262 return;
292 default: 263 default:
293 dbg("%s - nonzero urb status received: %d", __func__, status); 264 dev_dbg(&acm->control->dev,
265 "%s - nonzero urb status received: %d\n",
266 __func__, status);
294 goto exit; 267 goto exit;
295 } 268 }
296 269
297 if (!ACM_READY(acm)) 270 if (!ACM_READY(acm))
298 goto exit; 271 goto exit;
299 272
273 usb_mark_last_busy(acm->dev);
274
300 data = (unsigned char *)(dr + 1); 275 data = (unsigned char *)(dr + 1);
301 switch (dr->bNotificationType) { 276 switch (dr->bNotificationType) {
302 case USB_CDC_NOTIFY_NETWORK_CONNECTION: 277 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
303 dbg("%s network", dr->wValue ? 278 dev_dbg(&acm->control->dev, "%s - network connection: %d\n",
304 "connected to" : "disconnected from"); 279 __func__, dr->wValue);
305 break; 280 break;
306 281
307 case USB_CDC_NOTIFY_SERIAL_STATE: 282 case USB_CDC_NOTIFY_SERIAL_STATE:
@@ -311,7 +286,8 @@ static void acm_ctrl_irq(struct urb *urb)
311 if (tty) { 286 if (tty) {
312 if (!acm->clocal && 287 if (!acm->clocal &&
313 (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { 288 (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) {
314 dbg("calling hangup"); 289 dev_dbg(&acm->control->dev,
290 "%s - calling hangup\n", __func__);
315 tty_hangup(tty); 291 tty_hangup(tty);
316 } 292 }
317 tty_kref_put(tty); 293 tty_kref_put(tty);
@@ -319,7 +295,10 @@ static void acm_ctrl_irq(struct urb *urb)
319 295
320 acm->ctrlin = newctrl; 296 acm->ctrlin = newctrl;
321 297
322 dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c", 298 dev_dbg(&acm->control->dev,
299 "%s - input control lines: dcd%c dsr%c break%c "
300 "ring%c framing%c parity%c overrun%c\n",
301 __func__,
323 acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', 302 acm->ctrlin & ACM_CTRL_DCD ? '+' : '-',
324 acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', 303 acm->ctrlin & ACM_CTRL_DSR ? '+' : '-',
325 acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', 304 acm->ctrlin & ACM_CTRL_BRK ? '+' : '-',
@@ -330,175 +309,107 @@ static void acm_ctrl_irq(struct urb *urb)
330 break; 309 break;
331 310
332 default: 311 default:
333 dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", 312 dev_dbg(&acm->control->dev,
313 "%s - unknown notification %d received: index %d "
314 "len %d data0 %d data1 %d\n",
315 __func__,
334 dr->bNotificationType, dr->wIndex, 316 dr->bNotificationType, dr->wIndex,
335 dr->wLength, data[0], data[1]); 317 dr->wLength, data[0], data[1]);
336 break; 318 break;
337 } 319 }
338exit: 320exit:
339 usb_mark_last_busy(acm->dev);
340 retval = usb_submit_urb(urb, GFP_ATOMIC); 321 retval = usb_submit_urb(urb, GFP_ATOMIC);
341 if (retval) 322 if (retval)
342 dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with " 323 dev_err(&acm->control->dev, "%s - usb_submit_urb failed: %d\n",
343 "result %d", __func__, retval); 324 __func__, retval);
344} 325}
345 326
346/* data interface returns incoming bytes, or we got unthrottled */ 327static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags)
347static void acm_read_bulk(struct urb *urb)
348{ 328{
349 struct acm_rb *buf; 329 int res;
350 struct acm_ru *rcv = urb->context;
351 struct acm *acm = rcv->instance;
352 int status = urb->status;
353 330
354 dbg("Entering acm_read_bulk with status %d", status); 331 if (!test_and_clear_bit(index, &acm->read_urbs_free))
332 return 0;
355 333
356 if (!ACM_READY(acm)) { 334 dev_vdbg(&acm->data->dev, "%s - urb %d\n", __func__, index);
357 dev_dbg(&acm->data->dev, "Aborting, acm not ready"); 335
358 return; 336 res = usb_submit_urb(acm->read_urbs[index], mem_flags);
337 if (res) {
338 if (res != -EPERM) {
339 dev_err(&acm->data->dev,
340 "%s - usb_submit_urb failed: %d\n",
341 __func__, res);
342 }
343 set_bit(index, &acm->read_urbs_free);
344 return res;
359 } 345 }
360 usb_mark_last_busy(acm->dev);
361 346
362 if (status) 347 return 0;
363 dev_dbg(&acm->data->dev, "bulk rx status %d\n", status); 348}
364 349
365 buf = rcv->buffer; 350static int acm_submit_read_urbs(struct acm *acm, gfp_t mem_flags)
366 buf->size = urb->actual_length; 351{
352 int res;
353 int i;
367 354
368 if (likely(status == 0)) { 355 for (i = 0; i < acm->rx_buflimit; ++i) {
369 spin_lock(&acm->read_lock); 356 res = acm_submit_read_urb(acm, i, mem_flags);
370 acm->processing++; 357 if (res)
371 list_add_tail(&rcv->list, &acm->spare_read_urbs); 358 return res;
372 list_add_tail(&buf->list, &acm->filled_read_bufs);
373 spin_unlock(&acm->read_lock);
374 } else {
375 /* we drop the buffer due to an error */
376 spin_lock(&acm->read_lock);
377 list_add_tail(&rcv->list, &acm->spare_read_urbs);
378 list_add(&buf->list, &acm->spare_read_bufs);
379 spin_unlock(&acm->read_lock);
380 /* nevertheless the tasklet must be kicked unconditionally
381 so the queue cannot dry up */
382 } 359 }
383 if (likely(!acm->susp_count)) 360
384 tasklet_schedule(&acm->urb_task); 361 return 0;
385} 362}
386 363
387static void acm_rx_tasklet(unsigned long _acm) 364static void acm_process_read_urb(struct acm *acm, struct urb *urb)
388{ 365{
389 struct acm *acm = (void *)_acm;
390 struct acm_rb *buf;
391 struct tty_struct *tty; 366 struct tty_struct *tty;
392 struct acm_ru *rcv;
393 unsigned long flags;
394 unsigned char throttled;
395
396 dbg("Entering acm_rx_tasklet");
397
398 if (!ACM_READY(acm)) {
399 dbg("acm_rx_tasklet: ACM not ready");
400 return;
401 }
402 367
403 spin_lock_irqsave(&acm->throttle_lock, flags); 368 if (!urb->actual_length)
404 throttled = acm->throttle;
405 spin_unlock_irqrestore(&acm->throttle_lock, flags);
406 if (throttled) {
407 dbg("acm_rx_tasklet: throttled");
408 return; 369 return;
409 }
410 370
411 tty = tty_port_tty_get(&acm->port); 371 tty = tty_port_tty_get(&acm->port);
372 if (!tty)
373 return;
412 374
413next_buffer: 375 tty_insert_flip_string(tty, urb->transfer_buffer, urb->actual_length);
414 spin_lock_irqsave(&acm->read_lock, flags); 376 tty_flip_buffer_push(tty);
415 if (list_empty(&acm->filled_read_bufs)) {
416 spin_unlock_irqrestore(&acm->read_lock, flags);
417 goto urbs;
418 }
419 buf = list_entry(acm->filled_read_bufs.next,
420 struct acm_rb, list);
421 list_del(&buf->list);
422 spin_unlock_irqrestore(&acm->read_lock, flags);
423
424 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
425
426 if (tty) {
427 spin_lock_irqsave(&acm->throttle_lock, flags);
428 throttled = acm->throttle;
429 spin_unlock_irqrestore(&acm->throttle_lock, flags);
430 if (!throttled) {
431 tty_insert_flip_string(tty, buf->base, buf->size);
432 tty_flip_buffer_push(tty);
433 } else {
434 tty_kref_put(tty);
435 dbg("Throttling noticed");
436 spin_lock_irqsave(&acm->read_lock, flags);
437 list_add(&buf->list, &acm->filled_read_bufs);
438 spin_unlock_irqrestore(&acm->read_lock, flags);
439 return;
440 }
441 }
442
443 spin_lock_irqsave(&acm->read_lock, flags);
444 list_add(&buf->list, &acm->spare_read_bufs);
445 spin_unlock_irqrestore(&acm->read_lock, flags);
446 goto next_buffer;
447 377
448urbs:
449 tty_kref_put(tty); 378 tty_kref_put(tty);
379}
450 380
451 while (!list_empty(&acm->spare_read_bufs)) { 381static void acm_read_bulk_callback(struct urb *urb)
452 spin_lock_irqsave(&acm->read_lock, flags); 382{
453 if (list_empty(&acm->spare_read_urbs)) { 383 struct acm_rb *rb = urb->context;
454 acm->processing = 0; 384 struct acm *acm = rb->instance;
455 spin_unlock_irqrestore(&acm->read_lock, flags); 385 unsigned long flags;
456 return;
457 }
458 rcv = list_entry(acm->spare_read_urbs.next,
459 struct acm_ru, list);
460 list_del(&rcv->list);
461 spin_unlock_irqrestore(&acm->read_lock, flags);
462 386
463 buf = list_entry(acm->spare_read_bufs.next, 387 dev_vdbg(&acm->data->dev, "%s - urb %d, len %d\n", __func__,
464 struct acm_rb, list); 388 rb->index, urb->actual_length);
465 list_del(&buf->list); 389 set_bit(rb->index, &acm->read_urbs_free);
466 390
467 rcv->buffer = buf; 391 if (!acm->dev) {
392 dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__);
393 return;
394 }
395 usb_mark_last_busy(acm->dev);
468 396
469 if (acm->is_int_ep) 397 if (urb->status) {
470 usb_fill_int_urb(rcv->urb, acm->dev, 398 dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n",
471 acm->rx_endpoint, 399 __func__, urb->status);
472 buf->base, 400 return;
473 acm->readsize,
474 acm_read_bulk, rcv, acm->bInterval);
475 else
476 usb_fill_bulk_urb(rcv->urb, acm->dev,
477 acm->rx_endpoint,
478 buf->base,
479 acm->readsize,
480 acm_read_bulk, rcv);
481 rcv->urb->transfer_dma = buf->dma;
482 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
483
484 /* This shouldn't kill the driver as unsuccessful URBs are
485 returned to the free-urbs-pool and resubmited ASAP */
486 spin_lock_irqsave(&acm->read_lock, flags);
487 if (acm->susp_count ||
488 usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) {
489 list_add(&buf->list, &acm->spare_read_bufs);
490 list_add(&rcv->list, &acm->spare_read_urbs);
491 acm->processing = 0;
492 spin_unlock_irqrestore(&acm->read_lock, flags);
493 return;
494 } else {
495 spin_unlock_irqrestore(&acm->read_lock, flags);
496 dbg("acm_rx_tasklet: sending urb 0x%p, rcv 0x%p, buf 0x%p", rcv->urb, rcv, buf);
497 }
498 } 401 }
402 acm_process_read_urb(acm, urb);
403
404 /* throttle device if requested by tty */
499 spin_lock_irqsave(&acm->read_lock, flags); 405 spin_lock_irqsave(&acm->read_lock, flags);
500 acm->processing = 0; 406 acm->throttled = acm->throttle_req;
501 spin_unlock_irqrestore(&acm->read_lock, flags); 407 if (!acm->throttled && !acm->susp_count) {
408 spin_unlock_irqrestore(&acm->read_lock, flags);
409 acm_submit_read_urb(acm, rb->index, GFP_ATOMIC);
410 } else {
411 spin_unlock_irqrestore(&acm->read_lock, flags);
412 }
502} 413}
503 414
504/* data interface wrote those outgoing bytes */ 415/* data interface wrote those outgoing bytes */
@@ -508,9 +419,9 @@ static void acm_write_bulk(struct urb *urb)
508 struct acm *acm = wb->instance; 419 struct acm *acm = wb->instance;
509 unsigned long flags; 420 unsigned long flags;
510 421
511 if (verbose || urb->status 422 if (urb->status || (urb->actual_length != urb->transfer_buffer_length))
512 || (urb->actual_length != urb->transfer_buffer_length)) 423 dev_vdbg(&acm->data->dev, "%s - len %d/%d, status %d\n",
513 dev_dbg(&acm->data->dev, "tx %d/%d bytes -- > %d\n", 424 __func__,
514 urb->actual_length, 425 urb->actual_length,
515 urb->transfer_buffer_length, 426 urb->transfer_buffer_length,
516 urb->status); 427 urb->status);
@@ -520,8 +431,6 @@ static void acm_write_bulk(struct urb *urb)
520 spin_unlock_irqrestore(&acm->write_lock, flags); 431 spin_unlock_irqrestore(&acm->write_lock, flags);
521 if (ACM_READY(acm)) 432 if (ACM_READY(acm))
522 schedule_work(&acm->work); 433 schedule_work(&acm->work);
523 else
524 wake_up_interruptible(&acm->drain_wait);
525} 434}
526 435
527static void acm_softint(struct work_struct *work) 436static void acm_softint(struct work_struct *work)
@@ -529,10 +438,13 @@ static void acm_softint(struct work_struct *work)
529 struct acm *acm = container_of(work, struct acm, work); 438 struct acm *acm = container_of(work, struct acm, work);
530 struct tty_struct *tty; 439 struct tty_struct *tty;
531 440
532 dev_vdbg(&acm->data->dev, "tx work\n"); 441 dev_vdbg(&acm->data->dev, "%s\n", __func__);
442
533 if (!ACM_READY(acm)) 443 if (!ACM_READY(acm))
534 return; 444 return;
535 tty = tty_port_tty_get(&acm->port); 445 tty = tty_port_tty_get(&acm->port);
446 if (!tty)
447 return;
536 tty_wakeup(tty); 448 tty_wakeup(tty);
537 tty_kref_put(tty); 449 tty_kref_put(tty);
538} 450}
@@ -545,8 +457,6 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
545{ 457{
546 struct acm *acm; 458 struct acm *acm;
547 int rv = -ENODEV; 459 int rv = -ENODEV;
548 int i;
549 dbg("Entering acm_tty_open.");
550 460
551 mutex_lock(&open_mutex); 461 mutex_lock(&open_mutex);
552 462
@@ -556,6 +466,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
556 else 466 else
557 rv = 0; 467 rv = 0;
558 468
469 dev_dbg(&acm->control->dev, "%s\n", __func__);
470
559 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); 471 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
560 472
561 tty->driver_data = acm; 473 tty->driver_data = acm;
@@ -575,38 +487,28 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
575 487
576 acm->ctrlurb->dev = acm->dev; 488 acm->ctrlurb->dev = acm->dev;
577 if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { 489 if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
578 dbg("usb_submit_urb(ctrl irq) failed"); 490 dev_err(&acm->control->dev,
491 "%s - usb_submit_urb(ctrl irq) failed\n", __func__);
579 goto bail_out; 492 goto bail_out;
580 } 493 }
581 494
582 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && 495 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
583 (acm->ctrl_caps & USB_CDC_CAP_LINE)) 496 (acm->ctrl_caps & USB_CDC_CAP_LINE))
584 goto full_bailout; 497 goto bail_out;
585 498
586 usb_autopm_put_interface(acm->control); 499 usb_autopm_put_interface(acm->control);
587 500
588 INIT_LIST_HEAD(&acm->spare_read_urbs); 501 if (acm_submit_read_urbs(acm, GFP_KERNEL))
589 INIT_LIST_HEAD(&acm->spare_read_bufs); 502 goto bail_out;
590 INIT_LIST_HEAD(&acm->filled_read_bufs);
591
592 for (i = 0; i < acm->rx_buflimit; i++)
593 list_add(&(acm->ru[i].list), &acm->spare_read_urbs);
594 for (i = 0; i < acm->rx_buflimit; i++)
595 list_add(&(acm->rb[i].list), &acm->spare_read_bufs);
596
597 acm->throttle = 0;
598 503
599 set_bit(ASYNCB_INITIALIZED, &acm->port.flags); 504 set_bit(ASYNCB_INITIALIZED, &acm->port.flags);
600 rv = tty_port_block_til_ready(&acm->port, tty, filp); 505 rv = tty_port_block_til_ready(&acm->port, tty, filp);
601 tasklet_schedule(&acm->urb_task);
602 506
603 mutex_unlock(&acm->mutex); 507 mutex_unlock(&acm->mutex);
604out: 508out:
605 mutex_unlock(&open_mutex); 509 mutex_unlock(&open_mutex);
606 return rv; 510 return rv;
607 511
608full_bailout:
609 usb_kill_urb(acm->ctrlurb);
610bail_out: 512bail_out:
611 acm->port.count--; 513 acm->port.count--;
612 mutex_unlock(&acm->mutex); 514 mutex_unlock(&acm->mutex);
@@ -619,26 +521,24 @@ early_bail:
619 521
620static void acm_tty_unregister(struct acm *acm) 522static void acm_tty_unregister(struct acm *acm)
621{ 523{
622 int i, nr; 524 int i;
623 525
624 nr = acm->rx_buflimit;
625 tty_unregister_device(acm_tty_driver, acm->minor); 526 tty_unregister_device(acm_tty_driver, acm->minor);
626 usb_put_intf(acm->control); 527 usb_put_intf(acm->control);
627 acm_table[acm->minor] = NULL; 528 acm_table[acm->minor] = NULL;
628 usb_free_urb(acm->ctrlurb); 529 usb_free_urb(acm->ctrlurb);
629 for (i = 0; i < ACM_NW; i++) 530 for (i = 0; i < ACM_NW; i++)
630 usb_free_urb(acm->wb[i].urb); 531 usb_free_urb(acm->wb[i].urb);
631 for (i = 0; i < nr; i++) 532 for (i = 0; i < acm->rx_buflimit; i++)
632 usb_free_urb(acm->ru[i].urb); 533 usb_free_urb(acm->read_urbs[i]);
633 kfree(acm->country_codes); 534 kfree(acm->country_codes);
634 kfree(acm); 535 kfree(acm);
635} 536}
636 537
637static int acm_tty_chars_in_buffer(struct tty_struct *tty);
638
639static void acm_port_down(struct acm *acm) 538static void acm_port_down(struct acm *acm)
640{ 539{
641 int i, nr = acm->rx_buflimit; 540 int i;
541
642 mutex_lock(&open_mutex); 542 mutex_lock(&open_mutex);
643 if (acm->dev) { 543 if (acm->dev) {
644 usb_autopm_get_interface(acm->control); 544 usb_autopm_get_interface(acm->control);
@@ -646,8 +546,8 @@ static void acm_port_down(struct acm *acm)
646 usb_kill_urb(acm->ctrlurb); 546 usb_kill_urb(acm->ctrlurb);
647 for (i = 0; i < ACM_NW; i++) 547 for (i = 0; i < ACM_NW; i++)
648 usb_kill_urb(acm->wb[i].urb); 548 usb_kill_urb(acm->wb[i].urb);
649 for (i = 0; i < nr; i++) 549 for (i = 0; i < acm->rx_buflimit; i++)
650 usb_kill_urb(acm->ru[i].urb); 550 usb_kill_urb(acm->read_urbs[i]);
651 acm->control->needs_remote_wakeup = 0; 551 acm->control->needs_remote_wakeup = 0;
652 usb_autopm_put_interface(acm->control); 552 usb_autopm_put_interface(acm->control);
653 } 553 }
@@ -693,13 +593,13 @@ static int acm_tty_write(struct tty_struct *tty,
693 int wbn; 593 int wbn;
694 struct acm_wb *wb; 594 struct acm_wb *wb;
695 595
696 dbg("Entering acm_tty_write to write %d bytes,", count);
697
698 if (!ACM_READY(acm)) 596 if (!ACM_READY(acm))
699 return -EINVAL; 597 return -EINVAL;
700 if (!count) 598 if (!count)
701 return 0; 599 return 0;
702 600
601 dev_vdbg(&acm->data->dev, "%s - count %d\n", __func__, count);
602
703 spin_lock_irqsave(&acm->write_lock, flags); 603 spin_lock_irqsave(&acm->write_lock, flags);
704 wbn = acm_wb_alloc(acm); 604 wbn = acm_wb_alloc(acm);
705 if (wbn < 0) { 605 if (wbn < 0) {
@@ -709,7 +609,7 @@ static int acm_tty_write(struct tty_struct *tty,
709 wb = &acm->wb[wbn]; 609 wb = &acm->wb[wbn];
710 610
711 count = (count > acm->writesize) ? acm->writesize : count; 611 count = (count > acm->writesize) ? acm->writesize : count;
712 dbg("Get %d bytes...", count); 612 dev_vdbg(&acm->data->dev, "%s - write %d\n", __func__, count);
713 memcpy(wb->buf, buf, count); 613 memcpy(wb->buf, buf, count);
714 wb->len = count; 614 wb->len = count;
715 spin_unlock_irqrestore(&acm->write_lock, flags); 615 spin_unlock_irqrestore(&acm->write_lock, flags);
@@ -746,22 +646,31 @@ static int acm_tty_chars_in_buffer(struct tty_struct *tty)
746static void acm_tty_throttle(struct tty_struct *tty) 646static void acm_tty_throttle(struct tty_struct *tty)
747{ 647{
748 struct acm *acm = tty->driver_data; 648 struct acm *acm = tty->driver_data;
649
749 if (!ACM_READY(acm)) 650 if (!ACM_READY(acm))
750 return; 651 return;
751 spin_lock_bh(&acm->throttle_lock); 652
752 acm->throttle = 1; 653 spin_lock_irq(&acm->read_lock);
753 spin_unlock_bh(&acm->throttle_lock); 654 acm->throttle_req = 1;
655 spin_unlock_irq(&acm->read_lock);
754} 656}
755 657
756static void acm_tty_unthrottle(struct tty_struct *tty) 658static void acm_tty_unthrottle(struct tty_struct *tty)
757{ 659{
758 struct acm *acm = tty->driver_data; 660 struct acm *acm = tty->driver_data;
661 unsigned int was_throttled;
662
759 if (!ACM_READY(acm)) 663 if (!ACM_READY(acm))
760 return; 664 return;
761 spin_lock_bh(&acm->throttle_lock); 665
762 acm->throttle = 0; 666 spin_lock_irq(&acm->read_lock);
763 spin_unlock_bh(&acm->throttle_lock); 667 was_throttled = acm->throttled;
764 tasklet_schedule(&acm->urb_task); 668 acm->throttled = 0;
669 acm->throttle_req = 0;
670 spin_unlock_irq(&acm->read_lock);
671
672 if (was_throttled)
673 acm_submit_read_urbs(acm, GFP_KERNEL);
765} 674}
766 675
767static int acm_tty_break_ctl(struct tty_struct *tty, int state) 676static int acm_tty_break_ctl(struct tty_struct *tty, int state)
@@ -772,11 +681,12 @@ static int acm_tty_break_ctl(struct tty_struct *tty, int state)
772 return -EINVAL; 681 return -EINVAL;
773 retval = acm_send_break(acm, state ? 0xffff : 0); 682 retval = acm_send_break(acm, state ? 0xffff : 0);
774 if (retval < 0) 683 if (retval < 0)
775 dbg("send break failed"); 684 dev_dbg(&acm->control->dev, "%s - send break failed\n",
685 __func__);
776 return retval; 686 return retval;
777} 687}
778 688
779static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file) 689static int acm_tty_tiocmget(struct tty_struct *tty)
780{ 690{
781 struct acm *acm = tty->driver_data; 691 struct acm *acm = tty->driver_data;
782 692
@@ -791,7 +701,7 @@ static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file)
791 TIOCM_CTS; 701 TIOCM_CTS;
792} 702}
793 703
794static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file, 704static int acm_tty_tiocmset(struct tty_struct *tty,
795 unsigned int set, unsigned int clear) 705 unsigned int set, unsigned int clear)
796{ 706{
797 struct acm *acm = tty->driver_data; 707 struct acm *acm = tty->driver_data;
@@ -813,7 +723,7 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file,
813 return acm_set_control(acm, acm->ctrlout = newctrl); 723 return acm_set_control(acm, acm->ctrlout = newctrl);
814} 724}
815 725
816static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, 726static int acm_tty_ioctl(struct tty_struct *tty,
817 unsigned int cmd, unsigned long arg) 727 unsigned int cmd, unsigned long arg)
818{ 728{
819 struct acm *acm = tty->driver_data; 729 struct acm *acm = tty->driver_data;
@@ -867,7 +777,9 @@ static void acm_tty_set_termios(struct tty_struct *tty,
867 777
868 if (memcmp(&acm->line, &newline, sizeof newline)) { 778 if (memcmp(&acm->line, &newline, sizeof newline)) {
869 memcpy(&acm->line, &newline, sizeof newline); 779 memcpy(&acm->line, &newline, sizeof newline);
870 dbg("set line: %d %d %d %d", le32_to_cpu(newline.dwDTERate), 780 dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n",
781 __func__,
782 le32_to_cpu(newline.dwDTERate),
871 newline.bCharFormat, newline.bParityType, 783 newline.bCharFormat, newline.bParityType,
872 newline.bDataBits); 784 newline.bDataBits);
873 acm_set_line(acm, &acm->line); 785 acm_set_line(acm, &acm->line);
@@ -892,11 +804,11 @@ static void acm_write_buffers_free(struct acm *acm)
892static void acm_read_buffers_free(struct acm *acm) 804static void acm_read_buffers_free(struct acm *acm)
893{ 805{
894 struct usb_device *usb_dev = interface_to_usbdev(acm->control); 806 struct usb_device *usb_dev = interface_to_usbdev(acm->control);
895 int i, n = acm->rx_buflimit; 807 int i;
896 808
897 for (i = 0; i < n; i++) 809 for (i = 0; i < acm->rx_buflimit; i++)
898 usb_free_coherent(usb_dev, acm->readsize, 810 usb_free_coherent(usb_dev, acm->readsize,
899 acm->rb[i].base, acm->rb[i].dma); 811 acm->read_buffers[i].base, acm->read_buffers[i].dma);
900} 812}
901 813
902/* Little helper: write buffers allocate */ 814/* Little helper: write buffers allocate */
@@ -941,7 +853,7 @@ static int acm_probe(struct usb_interface *intf,
941 u8 ac_management_function = 0; 853 u8 ac_management_function = 0;
942 u8 call_management_function = 0; 854 u8 call_management_function = 0;
943 int call_interface_num = -1; 855 int call_interface_num = -1;
944 int data_interface_num; 856 int data_interface_num = -1;
945 unsigned long quirks; 857 unsigned long quirks;
946 int num_rx_buf; 858 int num_rx_buf;
947 int i; 859 int i;
@@ -1025,7 +937,11 @@ next_desc:
1025 if (!union_header) { 937 if (!union_header) {
1026 if (call_interface_num > 0) { 938 if (call_interface_num > 0) {
1027 dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); 939 dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n");
1028 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); 940 /* quirks for Droids MuIn LCD */
941 if (quirks & NO_DATA_INTERFACE)
942 data_interface = usb_ifnum_to_if(usb_dev, 0);
943 else
944 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num));
1029 control_interface = intf; 945 control_interface = intf;
1030 } else { 946 } else {
1031 if (intf->cur_altsetting->desc.bNumEndpoints != 3) { 947 if (intf->cur_altsetting->desc.bNumEndpoints != 3) {
@@ -1128,7 +1044,7 @@ skip_normal_probe:
1128 epwrite = t; 1044 epwrite = t;
1129 } 1045 }
1130made_compressed_probe: 1046made_compressed_probe:
1131 dbg("interfaces are valid"); 1047 dev_dbg(&intf->dev, "interfaces are valid\n");
1132 for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++); 1048 for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++);
1133 1049
1134 if (minor == ACM_TTY_MINORS) { 1050 if (minor == ACM_TTY_MINORS) {
@@ -1138,7 +1054,7 @@ made_compressed_probe:
1138 1054
1139 acm = kzalloc(sizeof(struct acm), GFP_KERNEL); 1055 acm = kzalloc(sizeof(struct acm), GFP_KERNEL);
1140 if (acm == NULL) { 1056 if (acm == NULL) {
1141 dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); 1057 dev_err(&intf->dev, "out of memory (acm kzalloc)\n");
1142 goto alloc_fail; 1058 goto alloc_fail;
1143 } 1059 }
1144 1060
@@ -1157,11 +1073,7 @@ made_compressed_probe:
1157 acm->ctrlsize = ctrlsize; 1073 acm->ctrlsize = ctrlsize;
1158 acm->readsize = readsize; 1074 acm->readsize = readsize;
1159 acm->rx_buflimit = num_rx_buf; 1075 acm->rx_buflimit = num_rx_buf;
1160 acm->urb_task.func = acm_rx_tasklet;
1161 acm->urb_task.data = (unsigned long) acm;
1162 INIT_WORK(&acm->work, acm_softint); 1076 INIT_WORK(&acm->work, acm_softint);
1163 init_waitqueue_head(&acm->drain_wait);
1164 spin_lock_init(&acm->throttle_lock);
1165 spin_lock_init(&acm->write_lock); 1077 spin_lock_init(&acm->write_lock);
1166 spin_lock_init(&acm->read_lock); 1078 spin_lock_init(&acm->read_lock);
1167 mutex_init(&acm->mutex); 1079 mutex_init(&acm->mutex);
@@ -1174,53 +1086,69 @@ made_compressed_probe:
1174 1086
1175 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 1087 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
1176 if (!buf) { 1088 if (!buf) {
1177 dev_dbg(&intf->dev, "out of memory (ctrl buffer alloc)\n"); 1089 dev_err(&intf->dev, "out of memory (ctrl buffer alloc)\n");
1178 goto alloc_fail2; 1090 goto alloc_fail2;
1179 } 1091 }
1180 acm->ctrl_buffer = buf; 1092 acm->ctrl_buffer = buf;
1181 1093
1182 if (acm_write_buffers_alloc(acm) < 0) { 1094 if (acm_write_buffers_alloc(acm) < 0) {
1183 dev_dbg(&intf->dev, "out of memory (write buffer alloc)\n"); 1095 dev_err(&intf->dev, "out of memory (write buffer alloc)\n");
1184 goto alloc_fail4; 1096 goto alloc_fail4;
1185 } 1097 }
1186 1098
1187 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); 1099 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
1188 if (!acm->ctrlurb) { 1100 if (!acm->ctrlurb) {
1189 dev_dbg(&intf->dev, "out of memory (ctrlurb kmalloc)\n"); 1101 dev_err(&intf->dev, "out of memory (ctrlurb kmalloc)\n");
1190 goto alloc_fail5; 1102 goto alloc_fail5;
1191 } 1103 }
1192 for (i = 0; i < num_rx_buf; i++) { 1104 for (i = 0; i < num_rx_buf; i++) {
1193 struct acm_ru *rcv = &(acm->ru[i]); 1105 struct acm_rb *rb = &(acm->read_buffers[i]);
1106 struct urb *urb;
1194 1107
1195 rcv->urb = usb_alloc_urb(0, GFP_KERNEL); 1108 rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL,
1196 if (rcv->urb == NULL) { 1109 &rb->dma);
1197 dev_dbg(&intf->dev, 1110 if (!rb->base) {
1198 "out of memory (read urbs usb_alloc_urb)\n"); 1111 dev_err(&intf->dev, "out of memory "
1112 "(read bufs usb_alloc_coherent)\n");
1199 goto alloc_fail6; 1113 goto alloc_fail6;
1200 } 1114 }
1115 rb->index = i;
1116 rb->instance = acm;
1201 1117
1202 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1118 urb = usb_alloc_urb(0, GFP_KERNEL);
1203 rcv->instance = acm; 1119 if (!urb) {
1204 } 1120 dev_err(&intf->dev,
1205 for (i = 0; i < num_rx_buf; i++) { 1121 "out of memory (read urbs usb_alloc_urb)\n");
1206 struct acm_rb *rb = &(acm->rb[i]); 1122 goto alloc_fail6;
1207
1208 rb->base = usb_alloc_coherent(acm->dev, readsize,
1209 GFP_KERNEL, &rb->dma);
1210 if (!rb->base) {
1211 dev_dbg(&intf->dev,
1212 "out of memory (read bufs usb_alloc_coherent)\n");
1213 goto alloc_fail7;
1214 } 1123 }
1124 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1125 urb->transfer_dma = rb->dma;
1126 if (acm->is_int_ep) {
1127 usb_fill_int_urb(urb, acm->dev,
1128 acm->rx_endpoint,
1129 rb->base,
1130 acm->readsize,
1131 acm_read_bulk_callback, rb,
1132 acm->bInterval);
1133 } else {
1134 usb_fill_bulk_urb(urb, acm->dev,
1135 acm->rx_endpoint,
1136 rb->base,
1137 acm->readsize,
1138 acm_read_bulk_callback, rb);
1139 }
1140
1141 acm->read_urbs[i] = urb;
1142 __set_bit(i, &acm->read_urbs_free);
1215 } 1143 }
1216 for (i = 0; i < ACM_NW; i++) { 1144 for (i = 0; i < ACM_NW; i++) {
1217 struct acm_wb *snd = &(acm->wb[i]); 1145 struct acm_wb *snd = &(acm->wb[i]);
1218 1146
1219 snd->urb = usb_alloc_urb(0, GFP_KERNEL); 1147 snd->urb = usb_alloc_urb(0, GFP_KERNEL);
1220 if (snd->urb == NULL) { 1148 if (snd->urb == NULL) {
1221 dev_dbg(&intf->dev, 1149 dev_err(&intf->dev,
1222 "out of memory (write urbs usb_alloc_urb)"); 1150 "out of memory (write urbs usb_alloc_urb)\n");
1223 goto alloc_fail8; 1151 goto alloc_fail7;
1224 } 1152 }
1225 1153
1226 if (usb_endpoint_xfer_int(epwrite)) 1154 if (usb_endpoint_xfer_int(epwrite))
@@ -1239,7 +1167,7 @@ made_compressed_probe:
1239 1167
1240 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); 1168 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);
1241 if (i < 0) 1169 if (i < 0)
1242 goto alloc_fail8; 1170 goto alloc_fail7;
1243 1171
1244 if (cfd) { /* export the country data */ 1172 if (cfd) { /* export the country data */
1245 acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); 1173 acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);
@@ -1291,14 +1219,13 @@ skip_countries:
1291 acm_table[minor] = acm; 1219 acm_table[minor] = acm;
1292 1220
1293 return 0; 1221 return 0;
1294alloc_fail8: 1222alloc_fail7:
1295 for (i = 0; i < ACM_NW; i++) 1223 for (i = 0; i < ACM_NW; i++)
1296 usb_free_urb(acm->wb[i].urb); 1224 usb_free_urb(acm->wb[i].urb);
1297alloc_fail7:
1298 acm_read_buffers_free(acm);
1299alloc_fail6: 1225alloc_fail6:
1300 for (i = 0; i < num_rx_buf; i++) 1226 for (i = 0; i < num_rx_buf; i++)
1301 usb_free_urb(acm->ru[i].urb); 1227 usb_free_urb(acm->read_urbs[i]);
1228 acm_read_buffers_free(acm);
1302 usb_free_urb(acm->ctrlurb); 1229 usb_free_urb(acm->ctrlurb);
1303alloc_fail5: 1230alloc_fail5:
1304 acm_write_buffers_free(acm); 1231 acm_write_buffers_free(acm);
@@ -1313,17 +1240,14 @@ alloc_fail:
1313static void stop_data_traffic(struct acm *acm) 1240static void stop_data_traffic(struct acm *acm)
1314{ 1241{
1315 int i; 1242 int i;
1316 dbg("Entering stop_data_traffic");
1317 1243
1318 tasklet_disable(&acm->urb_task); 1244 dev_dbg(&acm->control->dev, "%s\n", __func__);
1319 1245
1320 usb_kill_urb(acm->ctrlurb); 1246 usb_kill_urb(acm->ctrlurb);
1321 for (i = 0; i < ACM_NW; i++) 1247 for (i = 0; i < ACM_NW; i++)
1322 usb_kill_urb(acm->wb[i].urb); 1248 usb_kill_urb(acm->wb[i].urb);
1323 for (i = 0; i < acm->rx_buflimit; i++) 1249 for (i = 0; i < acm->rx_buflimit; i++)
1324 usb_kill_urb(acm->ru[i].urb); 1250 usb_kill_urb(acm->read_urbs[i]);
1325
1326 tasklet_enable(&acm->urb_task);
1327 1251
1328 cancel_work_sync(&acm->work); 1252 cancel_work_sync(&acm->work);
1329} 1253}
@@ -1384,11 +1308,9 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message)
1384 if (message.event & PM_EVENT_AUTO) { 1308 if (message.event & PM_EVENT_AUTO) {
1385 int b; 1309 int b;
1386 1310
1387 spin_lock_irq(&acm->read_lock); 1311 spin_lock_irq(&acm->write_lock);
1388 spin_lock(&acm->write_lock); 1312 b = acm->transmitting;
1389 b = acm->processing + acm->transmitting; 1313 spin_unlock_irq(&acm->write_lock);
1390 spin_unlock(&acm->write_lock);
1391 spin_unlock_irq(&acm->read_lock);
1392 if (b) 1314 if (b)
1393 return -EBUSY; 1315 return -EBUSY;
1394 } 1316 }
@@ -1450,7 +1372,7 @@ static int acm_resume(struct usb_interface *intf)
1450 if (rv < 0) 1372 if (rv < 0)
1451 goto err_out; 1373 goto err_out;
1452 1374
1453 tasklet_schedule(&acm->urb_task); 1375 rv = acm_submit_read_urbs(acm, GFP_NOIO);
1454 } 1376 }
1455 1377
1456err_out: 1378err_out:
@@ -1607,6 +1529,9 @@ static const struct usb_device_id acm_ids[] = {
1607 { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */ 1529 { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */
1608 { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */ 1530 { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */
1609 { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */ 1531 { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */
1532 { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */
1533 { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */
1534 { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */
1610 { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */ 1535 { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */
1611 1536
1612 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */ 1537 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
@@ -1614,7 +1539,12 @@ static const struct usb_device_id acm_ids[] = {
1614 /* Support Lego NXT using pbLua firmware */ 1539 /* Support Lego NXT using pbLua firmware */
1615 { USB_DEVICE(0x0694, 0xff00), 1540 { USB_DEVICE(0x0694, 0xff00),
1616 .driver_info = NOT_A_MODEM, 1541 .driver_info = NOT_A_MODEM,
1617 }, 1542 },
1543
1544 /* Support for Droids MuIn LCD */
1545 { USB_DEVICE(0x04d8, 0x000b),
1546 .driver_info = NO_DATA_INTERFACE,
1547 },
1618 1548
1619 /* control interfaces without any protocol set */ 1549 /* control interfaces without any protocol set */
1620 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1550 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
@@ -1710,8 +1640,7 @@ static int __init acm_init(void)
1710 return retval; 1640 return retval;
1711 } 1641 }
1712 1642
1713 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" 1643 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
1714 DRIVER_DESC "\n");
1715 1644
1716 return 0; 1645 return 0;
1717} 1646}
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 5eeb570b9a61..ca7937f26e27 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -52,7 +52,7 @@
52 */ 52 */
53 53
54/* 54/*
55 * The only reason to have several buffers is to accomodate assumptions 55 * The only reason to have several buffers is to accommodate assumptions
56 * in line disciplines. They ask for empty space amount, receive our URB size, 56 * in line disciplines. They ask for empty space amount, receive our URB size,
57 * and proceed to issue several 1-character writes, assuming they will fit. 57 * and proceed to issue several 1-character writes, assuming they will fit.
58 * The very first write takes a complete URB. Fortunately, this only happens 58 * The very first write takes a complete URB. Fortunately, this only happens
@@ -72,16 +72,10 @@ struct acm_wb {
72}; 72};
73 73
74struct acm_rb { 74struct acm_rb {
75 struct list_head list;
76 int size; 75 int size;
77 unsigned char *base; 76 unsigned char *base;
78 dma_addr_t dma; 77 dma_addr_t dma;
79}; 78 int index;
80
81struct acm_ru {
82 struct list_head list;
83 struct acm_rb *buffer;
84 struct urb *urb;
85 struct acm *instance; 79 struct acm *instance;
86}; 80};
87 81
@@ -97,35 +91,30 @@ struct acm {
97 unsigned int country_code_size; /* size of this buffer */ 91 unsigned int country_code_size; /* size of this buffer */
98 unsigned int country_rel_date; /* release date of version */ 92 unsigned int country_rel_date; /* release date of version */
99 struct acm_wb wb[ACM_NW]; 93 struct acm_wb wb[ACM_NW];
100 struct acm_ru ru[ACM_NR]; 94 unsigned long read_urbs_free;
101 struct acm_rb rb[ACM_NR]; 95 struct urb *read_urbs[ACM_NR];
96 struct acm_rb read_buffers[ACM_NR];
102 int rx_buflimit; 97 int rx_buflimit;
103 int rx_endpoint; 98 int rx_endpoint;
104 spinlock_t read_lock; 99 spinlock_t read_lock;
105 struct list_head spare_read_urbs;
106 struct list_head spare_read_bufs;
107 struct list_head filled_read_bufs;
108 int write_used; /* number of non-empty write buffers */ 100 int write_used; /* number of non-empty write buffers */
109 int processing;
110 int transmitting; 101 int transmitting;
111 spinlock_t write_lock; 102 spinlock_t write_lock;
112 struct mutex mutex; 103 struct mutex mutex;
113 struct usb_cdc_line_coding line; /* bits, stop, parity */ 104 struct usb_cdc_line_coding line; /* bits, stop, parity */
114 struct work_struct work; /* work queue entry for line discipline waking up */ 105 struct work_struct work; /* work queue entry for line discipline waking up */
115 wait_queue_head_t drain_wait; /* close processing */
116 struct tasklet_struct urb_task; /* rx processing */
117 spinlock_t throttle_lock; /* synchronize throtteling and read callback */
118 unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */ 106 unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */
119 unsigned int ctrlout; /* output control lines (DTR, RTS) */ 107 unsigned int ctrlout; /* output control lines (DTR, RTS) */
120 unsigned int writesize; /* max packet size for the output bulk endpoint */ 108 unsigned int writesize; /* max packet size for the output bulk endpoint */
121 unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ 109 unsigned int readsize,ctrlsize; /* buffer sizes for freeing */
122 unsigned int minor; /* acm minor number */ 110 unsigned int minor; /* acm minor number */
123 unsigned char throttle; /* throttled by tty layer */
124 unsigned char clocal; /* termios CLOCAL */ 111 unsigned char clocal; /* termios CLOCAL */
125 unsigned int ctrl_caps; /* control capabilities from the class specific header */ 112 unsigned int ctrl_caps; /* control capabilities from the class specific header */
126 unsigned int susp_count; /* number of suspended interfaces */ 113 unsigned int susp_count; /* number of suspended interfaces */
127 unsigned int combined_interfaces:1; /* control and data collapsed */ 114 unsigned int combined_interfaces:1; /* control and data collapsed */
128 unsigned int is_int_ep:1; /* interrupt endpoints contrary to spec used */ 115 unsigned int is_int_ep:1; /* interrupt endpoints contrary to spec used */
116 unsigned int throttled:1; /* actually throttled */
117 unsigned int throttle_req:1; /* throttle requested */
129 u8 bInterval; 118 u8 bInterval;
130 struct acm_wb *delayed_wb; /* write queued for a device about to be woken */ 119 struct acm_wb *delayed_wb; /* write queued for a device about to be woken */
131}; 120};
@@ -137,3 +126,4 @@ struct acm {
137#define SINGLE_RX_URB 2 126#define SINGLE_RX_URB 2
138#define NO_CAP_LINE 4 127#define NO_CAP_LINE 4
139#define NOT_A_MODEM 8 128#define NOT_A_MODEM 8
129#define NO_DATA_INTERFACE 16
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 094c76b5de17..2b9ff518b509 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -281,7 +281,7 @@ static void cleanup(struct wdm_device *desc)
281 desc->sbuf, 281 desc->sbuf,
282 desc->validity->transfer_dma); 282 desc->validity->transfer_dma);
283 usb_free_coherent(interface_to_usbdev(desc->intf), 283 usb_free_coherent(interface_to_usbdev(desc->intf),
284 desc->wMaxCommand, 284 desc->bMaxPacketSize0,
285 desc->inbuf, 285 desc->inbuf,
286 desc->response->transfer_dma); 286 desc->response->transfer_dma);
287 kfree(desc->orq); 287 kfree(desc->orq);
@@ -342,7 +342,7 @@ static ssize_t wdm_write
342 goto outnp; 342 goto outnp;
343 } 343 }
344 344
345 if (!file->f_flags && O_NONBLOCK) 345 if (!(file->f_flags & O_NONBLOCK))
346 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE, 346 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
347 &desc->flags)); 347 &desc->flags));
348 else 348 else
@@ -542,6 +542,8 @@ static int wdm_open(struct inode *inode, struct file *file)
542 542
543 mutex_lock(&desc->lock); 543 mutex_lock(&desc->lock);
544 if (!desc->count++) { 544 if (!desc->count++) {
545 desc->werr = 0;
546 desc->rerr = 0;
545 rv = usb_submit_urb(desc->validity, GFP_KERNEL); 547 rv = usb_submit_urb(desc->validity, GFP_KERNEL);
546 if (rv < 0) { 548 if (rv < 0) {
547 desc->count--; 549 desc->count--;
@@ -584,7 +586,8 @@ static const struct file_operations wdm_fops = {
584 .open = wdm_open, 586 .open = wdm_open,
585 .flush = wdm_flush, 587 .flush = wdm_flush,
586 .release = wdm_release, 588 .release = wdm_release,
587 .poll = wdm_poll 589 .poll = wdm_poll,
590 .llseek = noop_llseek,
588}; 591};
589 592
590static struct usb_class_driver wdm_class = { 593static struct usb_class_driver wdm_class = {
@@ -852,6 +855,18 @@ static int wdm_pre_reset(struct usb_interface *intf)
852 struct wdm_device *desc = usb_get_intfdata(intf); 855 struct wdm_device *desc = usb_get_intfdata(intf);
853 856
854 mutex_lock(&desc->lock); 857 mutex_lock(&desc->lock);
858 kill_urbs(desc);
859
860 /*
861 * we notify everybody using poll of
862 * an exceptional situation
863 * must be done before recovery lest a spontaneous
864 * message from the device is lost
865 */
866 spin_lock_irq(&desc->iuspin);
867 desc->rerr = -EINTR;
868 spin_unlock_irq(&desc->iuspin);
869 wake_up_all(&desc->wait);
855 return 0; 870 return 0;
856} 871}
857 872
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index e325162859b0..9eca4053312e 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -1043,6 +1043,7 @@ static const struct file_operations usblp_fops = {
1043 .compat_ioctl = usblp_ioctl, 1043 .compat_ioctl = usblp_ioctl,
1044 .open = usblp_open, 1044 .open = usblp_open,
1045 .release = usblp_release, 1045 .release = usblp_release,
1046 .llseek = noop_llseek,
1046}; 1047};
1047 1048
1048static char *usblp_devnode(struct device *dev, mode_t *mode) 1049static char *usblp_devnode(struct device *dev, mode_t *mode)
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 3e7c1b800ebb..385acb895ab3 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -483,7 +483,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
483 } 483 }
484 484
485 done += n_characters; 485 done += n_characters;
486 /* Terminate if end-of-message bit recieved from device */ 486 /* Terminate if end-of-message bit received from device */
487 if ((buffer[8] & 0x01) && (actual >= n_characters + 12)) 487 if ((buffer[8] & 0x01) && (actual >= n_characters + 12))
488 remaining = 0; 488 remaining = 0;
489 else 489 else
@@ -987,6 +987,7 @@ static const struct file_operations fops = {
987 .open = usbtmc_open, 987 .open = usbtmc_open,
988 .release = usbtmc_release, 988 .release = usbtmc_release,
989 .unlocked_ioctl = usbtmc_ioctl, 989 .unlocked_ioctl = usbtmc_ioctl,
990 .llseek = default_llseek,
990}; 991};
991 992
992static struct usb_class_driver usbtmc_class = { 993static struct usb_class_driver usbtmc_class = {
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index 9eed5b52d9de..18d02e32a3d5 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -107,17 +107,25 @@ config USB_SUSPEND
107 If you are unsure about this, say N here. 107 If you are unsure about this, say N here.
108 108
109config USB_OTG 109config USB_OTG
110 bool 110 bool "OTG support"
111 depends on USB && EXPERIMENTAL 111 depends on USB && EXPERIMENTAL
112 depends on USB_SUSPEND 112 depends on USB_SUSPEND
113 default n 113 default n
114 help
115 The most notable feature of USB OTG is support for a
116 "Dual-Role" device, which can act as either a device
117 or a host. The initial role is decided by the type of
118 plug inserted and can be changed later when two dual
119 role devices talk to each other.
114 120
121 Select this only if your board has Mini-AB/Micro-AB
122 connector.
115 123
116config USB_OTG_WHITELIST 124config USB_OTG_WHITELIST
117 bool "Rely on OTG Targeted Peripherals List" 125 bool "Rely on OTG Targeted Peripherals List"
118 depends on USB_OTG || EMBEDDED 126 depends on USB_OTG || EXPERT
119 default y if USB_OTG 127 default y if USB_OTG
120 default n if EMBEDDED 128 default n if EXPERT
121 help 129 help
122 If you say Y here, the "otg_whitelist.h" file will be used as a 130 If you say Y here, the "otg_whitelist.h" file will be used as a
123 product whitelist, so USB peripherals not listed there will be 131 product whitelist, so USB peripherals not listed there will be
@@ -133,7 +141,7 @@ config USB_OTG_WHITELIST
133 141
134config USB_OTG_BLACKLIST_HUB 142config USB_OTG_BLACKLIST_HUB
135 bool "Disable external hubs" 143 bool "Disable external hubs"
136 depends on USB_OTG || EMBEDDED 144 depends on USB_OTG || EXPERT
137 help 145 help
138 If you say Y here, then Linux will refuse to enumerate 146 If you say Y here, then Linux will refuse to enumerate
139 external hubs. OTG hosts are allowed to reduce hardware 147 external hubs. OTG hosts are allowed to reduce hardware
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
index ec16e6029905..507a4e1b6360 100644
--- a/drivers/usb/core/Makefile
+++ b/drivers/usb/core/Makefile
@@ -2,20 +2,13 @@
2# Makefile for USB Core files and filesystem 2# Makefile for USB Core files and filesystem
3# 3#
4 4
5usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ 5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6 config.o file.o buffer.o sysfs.o endpoint.o \
7 devio.o notify.o generic.o quirks.o devices.o
8 6
9ifeq ($(CONFIG_PCI),y) 7usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
10 usbcore-objs += hcd-pci.o 8usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
11endif 9usbcore-y += devio.o notify.o generic.o quirks.o devices.o
12 10
13ifeq ($(CONFIG_USB_DEVICEFS),y) 11usbcore-$(CONFIG_PCI) += hcd-pci.o
14 usbcore-objs += inode.o 12usbcore-$(CONFIG_USB_DEVICEFS) += inode.o
15endif
16 13
17obj-$(CONFIG_USB) += usbcore.o 14obj-$(CONFIG_USB) += usbcore.o
18
19ifeq ($(CONFIG_USB_DEBUG),y)
20EXTRA_CFLAGS += -DDEBUG
21endif
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 2c6965484fe8..b0585e623ba9 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -10,7 +10,7 @@
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <asm/io.h> 13#include <linux/io.h>
14#include <linux/dma-mapping.h> 14#include <linux/dma-mapping.h>
15#include <linux/dmapool.h> 15#include <linux/dmapool.h>
16#include <linux/usb.h> 16#include <linux/usb.h>
@@ -22,7 +22,7 @@
22 */ 22 */
23 23
24/* FIXME tune these based on pool statistics ... */ 24/* FIXME tune these based on pool statistics ... */
25static const size_t pool_max [HCD_BUFFER_POOLS] = { 25static const size_t pool_max[HCD_BUFFER_POOLS] = {
26 /* platforms without dma-friendly caches might need to 26 /* platforms without dma-friendly caches might need to
27 * prevent cacheline sharing... 27 * prevent cacheline sharing...
28 */ 28 */
@@ -51,7 +51,7 @@ static const size_t pool_max [HCD_BUFFER_POOLS] = {
51int hcd_buffer_create(struct usb_hcd *hcd) 51int hcd_buffer_create(struct usb_hcd *hcd)
52{ 52{
53 char name[16]; 53 char name[16];
54 int i, size; 54 int i, size;
55 55
56 if (!hcd->self.controller->dma_mask && 56 if (!hcd->self.controller->dma_mask &&
57 !(hcd->driver->flags & HCD_LOCAL_MEM)) 57 !(hcd->driver->flags & HCD_LOCAL_MEM))
@@ -64,7 +64,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
64 snprintf(name, sizeof name, "buffer-%d", size); 64 snprintf(name, sizeof name, "buffer-%d", size);
65 hcd->pool[i] = dma_pool_create(name, hcd->self.controller, 65 hcd->pool[i] = dma_pool_create(name, hcd->self.controller,
66 size, size, 0); 66 size, size, 0);
67 if (!hcd->pool [i]) { 67 if (!hcd->pool[i]) {
68 hcd_buffer_destroy(hcd); 68 hcd_buffer_destroy(hcd);
69 return -ENOMEM; 69 return -ENOMEM;
70 } 70 }
@@ -99,14 +99,14 @@ void hcd_buffer_destroy(struct usb_hcd *hcd)
99 */ 99 */
100 100
101void *hcd_buffer_alloc( 101void *hcd_buffer_alloc(
102 struct usb_bus *bus, 102 struct usb_bus *bus,
103 size_t size, 103 size_t size,
104 gfp_t mem_flags, 104 gfp_t mem_flags,
105 dma_addr_t *dma 105 dma_addr_t *dma
106) 106)
107{ 107{
108 struct usb_hcd *hcd = bus_to_hcd(bus); 108 struct usb_hcd *hcd = bus_to_hcd(bus);
109 int i; 109 int i;
110 110
111 /* some USB hosts just use PIO */ 111 /* some USB hosts just use PIO */
112 if (!bus->controller->dma_mask && 112 if (!bus->controller->dma_mask &&
@@ -116,21 +116,21 @@ void *hcd_buffer_alloc(
116 } 116 }
117 117
118 for (i = 0; i < HCD_BUFFER_POOLS; i++) { 118 for (i = 0; i < HCD_BUFFER_POOLS; i++) {
119 if (size <= pool_max [i]) 119 if (size <= pool_max[i])
120 return dma_pool_alloc(hcd->pool [i], mem_flags, dma); 120 return dma_pool_alloc(hcd->pool[i], mem_flags, dma);
121 } 121 }
122 return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags); 122 return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags);
123} 123}
124 124
125void hcd_buffer_free( 125void hcd_buffer_free(
126 struct usb_bus *bus, 126 struct usb_bus *bus,
127 size_t size, 127 size_t size,
128 void *addr, 128 void *addr,
129 dma_addr_t dma 129 dma_addr_t dma
130) 130)
131{ 131{
132 struct usb_hcd *hcd = bus_to_hcd(bus); 132 struct usb_hcd *hcd = bus_to_hcd(bus);
133 int i; 133 int i;
134 134
135 if (!addr) 135 if (!addr)
136 return; 136 return;
@@ -142,8 +142,8 @@ void hcd_buffer_free(
142 } 142 }
143 143
144 for (i = 0; i < HCD_BUFFER_POOLS; i++) { 144 for (i = 0; i < HCD_BUFFER_POOLS; i++) {
145 if (size <= pool_max [i]) { 145 if (size <= pool_max[i]) {
146 dma_pool_free(hcd->pool [i], addr, dma); 146 dma_pool_free(hcd->pool[i], addr, dma);
147 return; 147 return;
148 } 148 }
149 } 149 }
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 83126b03e7cf..c962608b4b9a 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -129,7 +129,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
129 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1); 129 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1);
130 else 130 else
131 max_tx = 999999; 131 max_tx = 999999;
132 if (desc->wBytesPerInterval > max_tx) { 132 if (le16_to_cpu(desc->wBytesPerInterval) > max_tx) {
133 dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in " 133 dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in "
134 "config %d interface %d altsetting %d ep %d: " 134 "config %d interface %d altsetting %d ep %d: "
135 "setting to %d\n", 135 "setting to %d\n",
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index 3449742c00e1..0149c0976e9c 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -54,7 +54,6 @@
54#include <linux/gfp.h> 54#include <linux/gfp.h>
55#include <linux/poll.h> 55#include <linux/poll.h>
56#include <linux/usb.h> 56#include <linux/usb.h>
57#include <linux/smp_lock.h>
58#include <linux/usbdevice_fs.h> 57#include <linux/usbdevice_fs.h>
59#include <linux/usb/hcd.h> 58#include <linux/usb/hcd.h>
60#include <linux/mutex.h> 59#include <linux/mutex.h>
@@ -65,49 +64,49 @@
65/* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */ 64/* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */
66#define ALLOW_SERIAL_NUMBER 65#define ALLOW_SERIAL_NUMBER
67 66
68static const char *format_topo = 67static const char format_topo[] =
69/* T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=ddd MxCh=dd */ 68/* T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=dddd MxCh=dd */
70"\nT: Bus=%2.2d Lev=%2.2d Prnt=%2.2d Port=%2.2d Cnt=%2.2d Dev#=%3d Spd=%3s MxCh=%2d\n"; 69"\nT: Bus=%2.2d Lev=%2.2d Prnt=%2.2d Port=%2.2d Cnt=%2.2d Dev#=%3d Spd=%-4s MxCh=%2d\n";
71 70
72static const char *format_string_manufacturer = 71static const char format_string_manufacturer[] =
73/* S: Manufacturer=xxxx */ 72/* S: Manufacturer=xxxx */
74 "S: Manufacturer=%.100s\n"; 73 "S: Manufacturer=%.100s\n";
75 74
76static const char *format_string_product = 75static const char format_string_product[] =
77/* S: Product=xxxx */ 76/* S: Product=xxxx */
78 "S: Product=%.100s\n"; 77 "S: Product=%.100s\n";
79 78
80#ifdef ALLOW_SERIAL_NUMBER 79#ifdef ALLOW_SERIAL_NUMBER
81static const char *format_string_serialnumber = 80static const char format_string_serialnumber[] =
82/* S: SerialNumber=xxxx */ 81/* S: SerialNumber=xxxx */
83 "S: SerialNumber=%.100s\n"; 82 "S: SerialNumber=%.100s\n";
84#endif 83#endif
85 84
86static const char *format_bandwidth = 85static const char format_bandwidth[] =
87/* B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd */ 86/* B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd */
88 "B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n"; 87 "B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n";
89 88
90static const char *format_device1 = 89static const char format_device1[] =
91/* D: Ver=xx.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd */ 90/* D: Ver=xx.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd */
92 "D: Ver=%2x.%02x Cls=%02x(%-5s) Sub=%02x Prot=%02x MxPS=%2d #Cfgs=%3d\n"; 91 "D: Ver=%2x.%02x Cls=%02x(%-5s) Sub=%02x Prot=%02x MxPS=%2d #Cfgs=%3d\n";
93 92
94static const char *format_device2 = 93static const char format_device2[] =
95/* P: Vendor=xxxx ProdID=xxxx Rev=xx.xx */ 94/* P: Vendor=xxxx ProdID=xxxx Rev=xx.xx */
96 "P: Vendor=%04x ProdID=%04x Rev=%2x.%02x\n"; 95 "P: Vendor=%04x ProdID=%04x Rev=%2x.%02x\n";
97 96
98static const char *format_config = 97static const char format_config[] =
99/* C: #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA */ 98/* C: #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA */
100 "C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n"; 99 "C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n";
101 100
102static const char *format_iad = 101static const char format_iad[] =
103/* A: FirstIf#=dd IfCount=dd Cls=xx(sssss) Sub=xx Prot=xx */ 102/* A: FirstIf#=dd IfCount=dd Cls=xx(sssss) Sub=xx Prot=xx */
104 "A: FirstIf#=%2d IfCount=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x\n"; 103 "A: FirstIf#=%2d IfCount=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x\n";
105 104
106static const char *format_iface = 105static const char format_iface[] =
107/* I: If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=xxxx*/ 106/* I: If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=xxxx*/
108 "I:%c If#=%2d Alt=%2d #EPs=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x Driver=%s\n"; 107 "I:%c If#=%2d Alt=%2d #EPs=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x Driver=%s\n";
109 108
110static const char *format_endpt = 109static const char format_endpt[] =
111/* E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=D?s */ 110/* E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=D?s */
112 "E: Ad=%02x(%c) Atr=%02x(%-4s) MxPS=%4d Ivl=%d%cs\n"; 111 "E: Ad=%02x(%c) Atr=%02x(%-4s) MxPS=%4d Ivl=%d%cs\n";
113 112
@@ -222,7 +221,7 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end,
222 break; 221 break;
223 case USB_ENDPOINT_XFER_INT: 222 case USB_ENDPOINT_XFER_INT:
224 type = "Int."; 223 type = "Int.";
225 if (speed == USB_SPEED_HIGH) 224 if (speed == USB_SPEED_HIGH || speed == USB_SPEED_SUPER)
226 interval = 1 << (desc->bInterval - 1); 225 interval = 1 << (desc->bInterval - 1);
227 else 226 else
228 interval = desc->bInterval; 227 interval = desc->bInterval;
@@ -230,7 +229,8 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end,
230 default: /* "can't happen" */ 229 default: /* "can't happen" */
231 return start; 230 return start;
232 } 231 }
233 interval *= (speed == USB_SPEED_HIGH) ? 125 : 1000; 232 interval *= (speed == USB_SPEED_HIGH ||
233 speed == USB_SPEED_SUPER) ? 125 : 1000;
234 if (interval % 1000) 234 if (interval % 1000)
235 unit = 'u'; 235 unit = 'u';
236 else { 236 else {
@@ -520,11 +520,14 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
520 speed = "1.5"; break; 520 speed = "1.5"; break;
521 case USB_SPEED_UNKNOWN: /* usb 1.1 root hub code */ 521 case USB_SPEED_UNKNOWN: /* usb 1.1 root hub code */
522 case USB_SPEED_FULL: 522 case USB_SPEED_FULL:
523 speed = "12 "; break; 523 speed = "12"; break;
524 case USB_SPEED_WIRELESS: /* Wireless has no real fixed speed */
524 case USB_SPEED_HIGH: 525 case USB_SPEED_HIGH:
525 speed = "480"; break; 526 speed = "480"; break;
527 case USB_SPEED_SUPER:
528 speed = "5000"; break;
526 default: 529 default:
527 speed = "?? "; 530 speed = "??";
528 } 531 }
529 data_end = pages_start + sprintf(pages_start, format_topo, 532 data_end = pages_start + sprintf(pages_start, format_topo,
530 bus->busnum, level, parent_devnum, 533 bus->busnum, level, parent_devnum,
@@ -540,8 +543,9 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
540 if (level == 0) { 543 if (level == 0) {
541 int max; 544 int max;
542 545
543 /* high speed reserves 80%, full/low reserves 90% */ 546 /* super/high speed reserves 80%, full/low reserves 90% */
544 if (usbdev->speed == USB_SPEED_HIGH) 547 if (usbdev->speed == USB_SPEED_HIGH ||
548 usbdev->speed == USB_SPEED_SUPER)
545 max = 800; 549 max = 800;
546 else 550 else
547 max = FRAME_TIME_MAX_USECS_ALLOC; 551 max = FRAME_TIME_MAX_USECS_ALLOC;
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index f1aaff6202a5..37518dfdeb98 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -37,7 +37,6 @@
37#include <linux/fs.h> 37#include <linux/fs.h>
38#include <linux/mm.h> 38#include <linux/mm.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/smp_lock.h>
41#include <linux/signal.h> 40#include <linux/signal.h>
42#include <linux/poll.h> 41#include <linux/poll.h>
43#include <linux/module.h> 42#include <linux/module.h>
@@ -803,7 +802,7 @@ static int proc_control(struct dev_state *ps, void __user *arg)
803 tbuf, ctrl.wLength, tmo); 802 tbuf, ctrl.wLength, tmo);
804 usb_lock_device(dev); 803 usb_lock_device(dev);
805 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE, 804 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE,
806 tbuf, i); 805 tbuf, max(i, 0));
807 if ((i > 0) && ctrl.wLength) { 806 if ((i > 0) && ctrl.wLength) {
808 if (copy_to_user(ctrl.data, tbuf, i)) { 807 if (copy_to_user(ctrl.data, tbuf, i)) {
809 free_page((unsigned long)tbuf); 808 free_page((unsigned long)tbuf);
@@ -965,10 +964,11 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg)
965 964
966static int proc_connectinfo(struct dev_state *ps, void __user *arg) 965static int proc_connectinfo(struct dev_state *ps, void __user *arg)
967{ 966{
968 struct usbdevfs_connectinfo ci; 967 struct usbdevfs_connectinfo ci = {
968 .devnum = ps->dev->devnum,
969 .slow = ps->dev->speed == USB_SPEED_LOW
970 };
969 971
970 ci.devnum = ps->dev->devnum;
971 ci.slow = ps->dev->speed == USB_SPEED_LOW;
972 if (copy_to_user(arg, &ci, sizeof(ci))) 972 if (copy_to_user(arg, &ci, sizeof(ci)))
973 return -EFAULT; 973 return -EFAULT;
974 return 0; 974 return 0;
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index d7a4401ef019..34e3da5aa72a 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -27,7 +27,6 @@
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/usb/quirks.h> 28#include <linux/usb/quirks.h>
29#include <linux/usb/hcd.h> 29#include <linux/usb/hcd.h>
30#include <linux/pm_runtime.h>
31 30
32#include "usb.h" 31#include "usb.h"
33 32
@@ -376,7 +375,7 @@ static int usb_unbind_interface(struct device *dev)
376 * Just re-enable it without affecting the endpoint toggles. 375 * Just re-enable it without affecting the endpoint toggles.
377 */ 376 */
378 usb_enable_interface(udev, intf, false); 377 usb_enable_interface(udev, intf, false);
379 } else if (!error && intf->dev.power.status == DPM_ON) { 378 } else if (!error && !intf->dev.power.is_prepared) {
380 r = usb_set_interface(udev, intf->altsetting[0]. 379 r = usb_set_interface(udev, intf->altsetting[0].
381 desc.bInterfaceNumber, 0); 380 desc.bInterfaceNumber, 0);
382 if (r < 0) 381 if (r < 0)
@@ -961,7 +960,7 @@ void usb_rebind_intf(struct usb_interface *intf)
961 } 960 }
962 961
963 /* Try to rebind the interface */ 962 /* Try to rebind the interface */
964 if (intf->dev.power.status == DPM_ON) { 963 if (!intf->dev.power.is_prepared) {
965 intf->needs_binding = 0; 964 intf->needs_binding = 0;
966 rc = device_attach(&intf->dev); 965 rc = device_attach(&intf->dev);
967 if (rc < 0) 966 if (rc < 0)
@@ -1108,8 +1107,7 @@ static int usb_resume_interface(struct usb_device *udev,
1108 if (intf->condition == USB_INTERFACE_UNBOUND) { 1107 if (intf->condition == USB_INTERFACE_UNBOUND) {
1109 1108
1110 /* Carry out a deferred switch to altsetting 0 */ 1109 /* Carry out a deferred switch to altsetting 0 */
1111 if (intf->needs_altsetting0 && 1110 if (intf->needs_altsetting0 && !intf->dev.power.is_prepared) {
1112 intf->dev.power.status == DPM_ON) {
1113 usb_set_interface(udev, intf->altsetting[0]. 1111 usb_set_interface(udev, intf->altsetting[0].
1114 desc.bInterfaceNumber, 0); 1112 desc.bInterfaceNumber, 0);
1115 intf->needs_altsetting0 = 0; 1113 intf->needs_altsetting0 = 0;
@@ -1189,13 +1187,22 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1189 for (i = n - 1; i >= 0; --i) { 1187 for (i = n - 1; i >= 0; --i) {
1190 intf = udev->actconfig->interface[i]; 1188 intf = udev->actconfig->interface[i];
1191 status = usb_suspend_interface(udev, intf, msg); 1189 status = usb_suspend_interface(udev, intf, msg);
1190
1191 /* Ignore errors during system sleep transitions */
1192 if (!(msg.event & PM_EVENT_AUTO))
1193 status = 0;
1192 if (status != 0) 1194 if (status != 0)
1193 break; 1195 break;
1194 } 1196 }
1195 } 1197 }
1196 if (status == 0) 1198 if (status == 0) {
1197 status = usb_suspend_device(udev, msg); 1199 status = usb_suspend_device(udev, msg);
1198 1200
1201 /* Again, ignore errors during system sleep transitions */
1202 if (!(msg.event & PM_EVENT_AUTO))
1203 status = 0;
1204 }
1205
1199 /* If the suspend failed, resume interfaces that did get suspended */ 1206 /* If the suspend failed, resume interfaces that did get suspended */
1200 if (status != 0) { 1207 if (status != 0) {
1201 msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME); 1208 msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME);
@@ -1262,6 +1269,7 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)
1262 udev->reset_resume); 1269 udev->reset_resume);
1263 } 1270 }
1264 } 1271 }
1272 usb_mark_last_busy(udev);
1265 1273
1266 done: 1274 done:
1267 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); 1275 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status);
@@ -1329,7 +1337,6 @@ int usb_resume(struct device *dev, pm_message_t msg)
1329 pm_runtime_disable(dev); 1337 pm_runtime_disable(dev);
1330 pm_runtime_set_active(dev); 1338 pm_runtime_set_active(dev);
1331 pm_runtime_enable(dev); 1339 pm_runtime_enable(dev);
1332 udev->last_busy = jiffies;
1333 do_unbind_rebind(udev, DO_REBIND); 1340 do_unbind_rebind(udev, DO_REBIND);
1334 } 1341 }
1335 } 1342 }
@@ -1337,7 +1344,7 @@ int usb_resume(struct device *dev, pm_message_t msg)
1337 /* Avoid PM error messages for devices disconnected while suspended 1344 /* Avoid PM error messages for devices disconnected while suspended
1338 * as we'll display regular disconnect messages just a bit later. 1345 * as we'll display regular disconnect messages just a bit later.
1339 */ 1346 */
1340 if (status == -ENODEV) 1347 if (status == -ENODEV || status == -ESHUTDOWN)
1341 status = 0; 1348 status = 0;
1342 return status; 1349 return status;
1343} 1350}
@@ -1397,33 +1404,8 @@ void usb_autosuspend_device(struct usb_device *udev)
1397{ 1404{
1398 int status; 1405 int status;
1399 1406
1400 udev->last_busy = jiffies; 1407 usb_mark_last_busy(udev);
1401 status = pm_runtime_put_sync(&udev->dev); 1408 status = pm_runtime_put_sync_autosuspend(&udev->dev);
1402 dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n",
1403 __func__, atomic_read(&udev->dev.power.usage_count),
1404 status);
1405}
1406
1407/**
1408 * usb_try_autosuspend_device - attempt an autosuspend of a USB device and its interfaces
1409 * @udev: the usb_device to autosuspend
1410 *
1411 * This routine should be called when a core subsystem thinks @udev may
1412 * be ready to autosuspend.
1413 *
1414 * @udev's usage counter left unchanged. If it is 0 and all the interfaces
1415 * are inactive then an autosuspend will be attempted. The attempt may
1416 * fail or be delayed.
1417 *
1418 * The caller must hold @udev's device lock.
1419 *
1420 * This routine can run only in process context.
1421 */
1422void usb_try_autosuspend_device(struct usb_device *udev)
1423{
1424 int status;
1425
1426 status = pm_runtime_idle(&udev->dev);
1427 dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", 1409 dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n",
1428 __func__, atomic_read(&udev->dev.power.usage_count), 1410 __func__, atomic_read(&udev->dev.power.usage_count),
1429 status); 1411 status);
@@ -1482,7 +1464,7 @@ void usb_autopm_put_interface(struct usb_interface *intf)
1482 struct usb_device *udev = interface_to_usbdev(intf); 1464 struct usb_device *udev = interface_to_usbdev(intf);
1483 int status; 1465 int status;
1484 1466
1485 udev->last_busy = jiffies; 1467 usb_mark_last_busy(udev);
1486 atomic_dec(&intf->pm_usage_cnt); 1468 atomic_dec(&intf->pm_usage_cnt);
1487 status = pm_runtime_put_sync(&intf->dev); 1469 status = pm_runtime_put_sync(&intf->dev);
1488 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", 1470 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n",
@@ -1509,32 +1491,11 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface);
1509void usb_autopm_put_interface_async(struct usb_interface *intf) 1491void usb_autopm_put_interface_async(struct usb_interface *intf)
1510{ 1492{
1511 struct usb_device *udev = interface_to_usbdev(intf); 1493 struct usb_device *udev = interface_to_usbdev(intf);
1512 unsigned long last_busy; 1494 int status;
1513 int status = 0;
1514 1495
1515 last_busy = udev->last_busy; 1496 usb_mark_last_busy(udev);
1516 udev->last_busy = jiffies;
1517 atomic_dec(&intf->pm_usage_cnt); 1497 atomic_dec(&intf->pm_usage_cnt);
1518 pm_runtime_put_noidle(&intf->dev); 1498 status = pm_runtime_put(&intf->dev);
1519
1520 if (udev->dev.power.runtime_auto) {
1521 /* Optimization: Don't schedule a delayed autosuspend if
1522 * the timer is already running and the expiration time
1523 * wouldn't change.
1524 *
1525 * We have to use the interface's timer. Attempts to
1526 * schedule a suspend for the device would fail because
1527 * the interface is still active.
1528 */
1529 if (intf->dev.power.timer_expires == 0 ||
1530 round_jiffies_up(last_busy) !=
1531 round_jiffies_up(jiffies)) {
1532 status = pm_schedule_suspend(&intf->dev,
1533 jiffies_to_msecs(
1534 round_jiffies_up_relative(
1535 udev->autosuspend_delay)));
1536 }
1537 }
1538 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", 1499 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n",
1539 __func__, atomic_read(&intf->dev.power.usage_count), 1500 __func__, atomic_read(&intf->dev.power.usage_count),
1540 status); 1501 status);
@@ -1554,7 +1515,7 @@ void usb_autopm_put_interface_no_suspend(struct usb_interface *intf)
1554{ 1515{
1555 struct usb_device *udev = interface_to_usbdev(intf); 1516 struct usb_device *udev = interface_to_usbdev(intf);
1556 1517
1557 udev->last_busy = jiffies; 1518 usb_mark_last_busy(udev);
1558 atomic_dec(&intf->pm_usage_cnt); 1519 atomic_dec(&intf->pm_usage_cnt);
1559 pm_runtime_put_noidle(&intf->dev); 1520 pm_runtime_put_noidle(&intf->dev);
1560} 1521}
@@ -1612,18 +1573,9 @@ EXPORT_SYMBOL_GPL(usb_autopm_get_interface);
1612 */ 1573 */
1613int usb_autopm_get_interface_async(struct usb_interface *intf) 1574int usb_autopm_get_interface_async(struct usb_interface *intf)
1614{ 1575{
1615 int status = 0; 1576 int status;
1616 enum rpm_status s;
1617
1618 /* Don't request a resume unless the interface is already suspending
1619 * or suspended. Doing so would force a running suspend timer to be
1620 * cancelled.
1621 */
1622 pm_runtime_get_noresume(&intf->dev);
1623 s = ACCESS_ONCE(intf->dev.power.runtime_status);
1624 if (s == RPM_SUSPENDING || s == RPM_SUSPENDED)
1625 status = pm_request_resume(&intf->dev);
1626 1577
1578 status = pm_runtime_get(&intf->dev);
1627 if (status < 0 && status != -EINPROGRESS) 1579 if (status < 0 && status != -EINPROGRESS)
1628 pm_runtime_put_noidle(&intf->dev); 1580 pm_runtime_put_noidle(&intf->dev);
1629 else 1581 else
@@ -1650,7 +1602,7 @@ void usb_autopm_get_interface_no_resume(struct usb_interface *intf)
1650{ 1602{
1651 struct usb_device *udev = interface_to_usbdev(intf); 1603 struct usb_device *udev = interface_to_usbdev(intf);
1652 1604
1653 udev->last_busy = jiffies; 1605 usb_mark_last_busy(udev);
1654 atomic_inc(&intf->pm_usage_cnt); 1606 atomic_inc(&intf->pm_usage_cnt);
1655 pm_runtime_get_noresume(&intf->dev); 1607 pm_runtime_get_noresume(&intf->dev);
1656} 1608}
@@ -1661,7 +1613,6 @@ static int autosuspend_check(struct usb_device *udev)
1661{ 1613{
1662 int w, i; 1614 int w, i;
1663 struct usb_interface *intf; 1615 struct usb_interface *intf;
1664 unsigned long suspend_time, j;
1665 1616
1666 /* Fail if autosuspend is disabled, or any interfaces are in use, or 1617 /* Fail if autosuspend is disabled, or any interfaces are in use, or
1667 * any interface drivers require remote wakeup but it isn't available. 1618 * any interface drivers require remote wakeup but it isn't available.
@@ -1701,103 +1652,58 @@ static int autosuspend_check(struct usb_device *udev)
1701 return -EOPNOTSUPP; 1652 return -EOPNOTSUPP;
1702 } 1653 }
1703 udev->do_remote_wakeup = w; 1654 udev->do_remote_wakeup = w;
1704
1705 /* If everything is okay but the device hasn't been idle for long
1706 * enough, queue a delayed autosuspend request.
1707 */
1708 j = ACCESS_ONCE(jiffies);
1709 suspend_time = udev->last_busy + udev->autosuspend_delay;
1710 if (time_before(j, suspend_time)) {
1711 pm_schedule_suspend(&udev->dev, jiffies_to_msecs(
1712 round_jiffies_up_relative(suspend_time - j)));
1713 return -EAGAIN;
1714 }
1715 return 0; 1655 return 0;
1716} 1656}
1717 1657
1718static int usb_runtime_suspend(struct device *dev) 1658int usb_runtime_suspend(struct device *dev)
1719{ 1659{
1720 int status = 0; 1660 struct usb_device *udev = to_usb_device(dev);
1661 int status;
1721 1662
1722 /* A USB device can be suspended if it passes the various autosuspend 1663 /* A USB device can be suspended if it passes the various autosuspend
1723 * checks. Runtime suspend for a USB device means suspending all the 1664 * checks. Runtime suspend for a USB device means suspending all the
1724 * interfaces and then the device itself. 1665 * interfaces and then the device itself.
1725 */ 1666 */
1726 if (is_usb_device(dev)) { 1667 if (autosuspend_check(udev) != 0)
1727 struct usb_device *udev = to_usb_device(dev); 1668 return -EAGAIN;
1728
1729 if (autosuspend_check(udev) != 0)
1730 return -EAGAIN;
1731
1732 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND);
1733
1734 /* If an interface fails the suspend, adjust the last_busy
1735 * time so that we don't get another suspend attempt right
1736 * away.
1737 */
1738 if (status) {
1739 udev->last_busy = jiffies +
1740 (udev->autosuspend_delay == 0 ?
1741 HZ/2 : 0);
1742 }
1743
1744 /* Prevent the parent from suspending immediately after */
1745 else if (udev->parent)
1746 udev->parent->last_busy = jiffies;
1747 }
1748 1669
1749 /* Runtime suspend for a USB interface doesn't mean anything. */ 1670 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND);
1671 /* The PM core reacts badly unless the return code is 0,
1672 * -EAGAIN, or -EBUSY, so always return -EBUSY on an error.
1673 */
1674 if (status != 0)
1675 return -EBUSY;
1750 return status; 1676 return status;
1751} 1677}
1752 1678
1753static int usb_runtime_resume(struct device *dev) 1679int usb_runtime_resume(struct device *dev)
1754{ 1680{
1681 struct usb_device *udev = to_usb_device(dev);
1682 int status;
1683
1755 /* Runtime resume for a USB device means resuming both the device 1684 /* Runtime resume for a USB device means resuming both the device
1756 * and all its interfaces. 1685 * and all its interfaces.
1757 */ 1686 */
1758 if (is_usb_device(dev)) { 1687 status = usb_resume_both(udev, PMSG_AUTO_RESUME);
1759 struct usb_device *udev = to_usb_device(dev); 1688 return status;
1760 int status;
1761
1762 status = usb_resume_both(udev, PMSG_AUTO_RESUME);
1763 udev->last_busy = jiffies;
1764 return status;
1765 }
1766
1767 /* Runtime resume for a USB interface doesn't mean anything. */
1768 return 0;
1769} 1689}
1770 1690
1771static int usb_runtime_idle(struct device *dev) 1691int usb_runtime_idle(struct device *dev)
1772{ 1692{
1693 struct usb_device *udev = to_usb_device(dev);
1694
1773 /* An idle USB device can be suspended if it passes the various 1695 /* An idle USB device can be suspended if it passes the various
1774 * autosuspend checks. An idle interface can be suspended at 1696 * autosuspend checks.
1775 * any time.
1776 */ 1697 */
1777 if (is_usb_device(dev)) { 1698 if (autosuspend_check(udev) == 0)
1778 struct usb_device *udev = to_usb_device(dev); 1699 pm_runtime_autosuspend(dev);
1779
1780 if (autosuspend_check(udev) != 0)
1781 return 0;
1782 }
1783
1784 pm_runtime_suspend(dev);
1785 return 0; 1700 return 0;
1786} 1701}
1787 1702
1788static const struct dev_pm_ops usb_bus_pm_ops = {
1789 .runtime_suspend = usb_runtime_suspend,
1790 .runtime_resume = usb_runtime_resume,
1791 .runtime_idle = usb_runtime_idle,
1792};
1793
1794#endif /* CONFIG_USB_SUSPEND */ 1703#endif /* CONFIG_USB_SUSPEND */
1795 1704
1796struct bus_type usb_bus_type = { 1705struct bus_type usb_bus_type = {
1797 .name = "usb", 1706 .name = "usb",
1798 .match = usb_device_match, 1707 .match = usb_device_match,
1799 .uevent = usb_uevent, 1708 .uevent = usb_uevent,
1800#ifdef CONFIG_USB_SUSPEND
1801 .pm = &usb_bus_pm_ops,
1802#endif
1803}; 1709};
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 3788e738e265..df502a98d0df 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -192,17 +192,17 @@ int usb_create_ep_devs(struct device *parent,
192 ep_dev->dev.parent = parent; 192 ep_dev->dev.parent = parent;
193 ep_dev->dev.release = ep_device_release; 193 ep_dev->dev.release = ep_device_release;
194 dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress); 194 dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress);
195 device_enable_async_suspend(&ep_dev->dev);
196 195
197 retval = device_register(&ep_dev->dev); 196 retval = device_register(&ep_dev->dev);
198 if (retval) 197 if (retval)
199 goto error_register; 198 goto error_register;
200 199
200 device_enable_async_suspend(&ep_dev->dev);
201 endpoint->ep_dev = ep_dev; 201 endpoint->ep_dev = ep_dev;
202 return retval; 202 return retval;
203 203
204error_register: 204error_register:
205 kfree(ep_dev); 205 put_device(&ep_dev->dev);
206exit: 206exit:
207 return retval; 207 return retval;
208} 208}
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 1e6ccef2cf0c..99458c843d60 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -19,7 +19,6 @@
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/rwsem.h> 20#include <linux/rwsem.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/smp_lock.h>
23#include <linux/usb.h> 22#include <linux/usb.h>
24 23
25#include "usb.h" 24#include "usb.h"
@@ -59,6 +58,7 @@ static int usb_open(struct inode * inode, struct file * file)
59static const struct file_operations usb_fops = { 58static const struct file_operations usb_fops = {
60 .owner = THIS_MODULE, 59 .owner = THIS_MODULE,
61 .open = usb_open, 60 .open = usb_open,
61 .llseek = noop_llseek,
62}; 62};
63 63
64static struct usb_class { 64static struct usb_class {
@@ -236,13 +236,6 @@ EXPORT_SYMBOL_GPL(usb_register_dev);
236void usb_deregister_dev(struct usb_interface *intf, 236void usb_deregister_dev(struct usb_interface *intf,
237 struct usb_class_driver *class_driver) 237 struct usb_class_driver *class_driver)
238{ 238{
239 int minor_base = class_driver->minor_base;
240 char name[20];
241
242#ifdef CONFIG_USB_DYNAMIC_MINORS
243 minor_base = 0;
244#endif
245
246 if (intf->minor == -1) 239 if (intf->minor == -1)
247 return; 240 return;
248 241
@@ -252,7 +245,6 @@ void usb_deregister_dev(struct usb_interface *intf,
252 usb_minors[intf->minor] = NULL; 245 usb_minors[intf->minor] = NULL;
253 up_write(&minor_rwsem); 246 up_write(&minor_rwsem);
254 247
255 snprintf(name, sizeof(name), class_driver->name, intf->minor - minor_base);
256 device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); 248 device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor));
257 intf->usb_dev = NULL; 249 intf->usb_dev = NULL;
258 intf->minor = -1; 250 intf->minor = -1;
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index c3f98543caaf..ce22f4a84ed0 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -19,7 +19,6 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/pm_runtime.h>
23#include <linux/usb.h> 22#include <linux/usb.h>
24#include <linux/usb/hcd.h> 23#include <linux/usb/hcd.h>
25 24
@@ -193,13 +192,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
193 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", 192 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
194 pci_name(dev)); 193 pci_name(dev));
195 retval = -ENODEV; 194 retval = -ENODEV;
196 goto err1; 195 goto disable_pci;
197 } 196 }
198 197
199 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); 198 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
200 if (!hcd) { 199 if (!hcd) {
201 retval = -ENOMEM; 200 retval = -ENOMEM;
202 goto err1; 201 goto disable_pci;
203 } 202 }
204 203
205 if (driver->flags & HCD_MEMORY) { 204 if (driver->flags & HCD_MEMORY) {
@@ -210,13 +209,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
210 driver->description)) { 209 driver->description)) {
211 dev_dbg(&dev->dev, "controller already in use\n"); 210 dev_dbg(&dev->dev, "controller already in use\n");
212 retval = -EBUSY; 211 retval = -EBUSY;
213 goto err2; 212 goto clear_companion;
214 } 213 }
215 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); 214 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
216 if (hcd->regs == NULL) { 215 if (hcd->regs == NULL) {
217 dev_dbg(&dev->dev, "error mapping memory\n"); 216 dev_dbg(&dev->dev, "error mapping memory\n");
218 retval = -EFAULT; 217 retval = -EFAULT;
219 goto err3; 218 goto release_mem_region;
220 } 219 }
221 220
222 } else { 221 } else {
@@ -237,7 +236,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
237 if (region == PCI_ROM_RESOURCE) { 236 if (region == PCI_ROM_RESOURCE) {
238 dev_dbg(&dev->dev, "no i/o regions available\n"); 237 dev_dbg(&dev->dev, "no i/o regions available\n");
239 retval = -EBUSY; 238 retval = -EBUSY;
240 goto err2; 239 goto clear_companion;
241 } 240 }
242 } 241 }
243 242
@@ -245,24 +244,24 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
245 244
246 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); 245 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
247 if (retval != 0) 246 if (retval != 0)
248 goto err4; 247 goto unmap_registers;
249 set_hs_companion(dev, hcd); 248 set_hs_companion(dev, hcd);
250 249
251 if (pci_dev_run_wake(dev)) 250 if (pci_dev_run_wake(dev))
252 pm_runtime_put_noidle(&dev->dev); 251 pm_runtime_put_noidle(&dev->dev);
253 return retval; 252 return retval;
254 253
255 err4: 254unmap_registers:
256 if (driver->flags & HCD_MEMORY) { 255 if (driver->flags & HCD_MEMORY) {
257 iounmap(hcd->regs); 256 iounmap(hcd->regs);
258 err3: 257release_mem_region:
259 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 258 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
260 } else 259 } else
261 release_region(hcd->rsrc_start, hcd->rsrc_len); 260 release_region(hcd->rsrc_start, hcd->rsrc_len);
262 err2: 261clear_companion:
263 clear_hs_companion(dev, hcd); 262 clear_hs_companion(dev, hcd);
264 usb_put_hcd(hcd); 263 usb_put_hcd(hcd);
265 err1: 264disable_pci:
266 pci_disable_device(dev); 265 pci_disable_device(dev);
267 dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); 266 dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval);
268 return retval; 267 return retval;
@@ -329,12 +328,14 @@ void usb_hcd_pci_shutdown(struct pci_dev *dev)
329 return; 328 return;
330 329
331 if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && 330 if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) &&
332 hcd->driver->shutdown) 331 hcd->driver->shutdown) {
333 hcd->driver->shutdown(hcd); 332 hcd->driver->shutdown(hcd);
333 pci_disable_device(dev);
334 }
334} 335}
335EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); 336EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown);
336 337
337#ifdef CONFIG_PM_OPS 338#ifdef CONFIG_PM
338 339
339#ifdef CONFIG_PPC_PMAC 340#ifdef CONFIG_PPC_PMAC
340static void powermac_set_asic(struct pci_dev *pci_dev, int enable) 341static void powermac_set_asic(struct pci_dev *pci_dev, int enable)
@@ -362,11 +363,17 @@ static int check_root_hub_suspended(struct device *dev)
362 struct pci_dev *pci_dev = to_pci_dev(dev); 363 struct pci_dev *pci_dev = to_pci_dev(dev);
363 struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 364 struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
364 365
365 if (!(hcd->state == HC_STATE_SUSPENDED || 366 if (HCD_RH_RUNNING(hcd)) {
366 hcd->state == HC_STATE_HALT)) {
367 dev_warn(dev, "Root hub is not suspended\n"); 367 dev_warn(dev, "Root hub is not suspended\n");
368 return -EBUSY; 368 return -EBUSY;
369 } 369 }
370 if (hcd->shared_hcd) {
371 hcd = hcd->shared_hcd;
372 if (HCD_RH_RUNNING(hcd)) {
373 dev_warn(dev, "Secondary root hub is not suspended\n");
374 return -EBUSY;
375 }
376 }
370 return 0; 377 return 0;
371} 378}
372 379
@@ -385,17 +392,22 @@ static int suspend_common(struct device *dev, bool do_wakeup)
385 if (retval) 392 if (retval)
386 return retval; 393 return retval;
387 394
388 if (hcd->driver->pci_suspend) { 395 if (hcd->driver->pci_suspend && !HCD_DEAD(hcd)) {
389 /* Optimization: Don't suspend if a root-hub wakeup is 396 /* Optimization: Don't suspend if a root-hub wakeup is
390 * pending and it would cause the HCD to wake up anyway. 397 * pending and it would cause the HCD to wake up anyway.
391 */ 398 */
392 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) 399 if (do_wakeup && HCD_WAKEUP_PENDING(hcd))
393 return -EBUSY; 400 return -EBUSY;
401 if (do_wakeup && hcd->shared_hcd &&
402 HCD_WAKEUP_PENDING(hcd->shared_hcd))
403 return -EBUSY;
394 retval = hcd->driver->pci_suspend(hcd, do_wakeup); 404 retval = hcd->driver->pci_suspend(hcd, do_wakeup);
395 suspend_report_result(hcd->driver->pci_suspend, retval); 405 suspend_report_result(hcd->driver->pci_suspend, retval);
396 406
397 /* Check again in case wakeup raced with pci_suspend */ 407 /* Check again in case wakeup raced with pci_suspend */
398 if (retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) { 408 if ((retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) ||
409 (retval == 0 && do_wakeup && hcd->shared_hcd &&
410 HCD_WAKEUP_PENDING(hcd->shared_hcd))) {
399 if (hcd->driver->pci_resume) 411 if (hcd->driver->pci_resume)
400 hcd->driver->pci_resume(hcd, false); 412 hcd->driver->pci_resume(hcd, false);
401 retval = -EBUSY; 413 retval = -EBUSY;
@@ -404,7 +416,12 @@ static int suspend_common(struct device *dev, bool do_wakeup)
404 return retval; 416 return retval;
405 } 417 }
406 418
407 synchronize_irq(pci_dev->irq); 419 /* If MSI-X is enabled, the driver will have synchronized all vectors
420 * in pci_suspend(). If MSI or legacy PCI is enabled, that will be
421 * synchronized here.
422 */
423 if (!hcd->msix_enabled)
424 synchronize_irq(pci_dev->irq);
408 425
409 /* Downstream ports from this root hub should already be quiesced, so 426 /* Downstream ports from this root hub should already be quiesced, so
410 * there will be no DMA activity. Now we can shut down the upstream 427 * there will be no DMA activity. Now we can shut down the upstream
@@ -421,7 +438,9 @@ static int resume_common(struct device *dev, int event)
421 struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 438 struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
422 int retval; 439 int retval;
423 440
424 if (hcd->state != HC_STATE_SUSPENDED) { 441 if (HCD_RH_RUNNING(hcd) ||
442 (hcd->shared_hcd &&
443 HCD_RH_RUNNING(hcd->shared_hcd))) {
425 dev_dbg(dev, "can't resume, not suspended!\n"); 444 dev_dbg(dev, "can't resume, not suspended!\n");
426 return 0; 445 return 0;
427 } 446 }
@@ -435,8 +454,10 @@ static int resume_common(struct device *dev, int event)
435 pci_set_master(pci_dev); 454 pci_set_master(pci_dev);
436 455
437 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 456 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
457 if (hcd->shared_hcd)
458 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags);
438 459
439 if (hcd->driver->pci_resume) { 460 if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) {
440 if (event != PM_EVENT_AUTO_RESUME) 461 if (event != PM_EVENT_AUTO_RESUME)
441 wait_for_companions(pci_dev, hcd); 462 wait_for_companions(pci_dev, hcd);
442 463
@@ -444,6 +465,8 @@ static int resume_common(struct device *dev, int event)
444 event == PM_EVENT_RESTORE); 465 event == PM_EVENT_RESTORE);
445 if (retval) { 466 if (retval) {
446 dev_err(dev, "PCI post-resume error %d!\n", retval); 467 dev_err(dev, "PCI post-resume error %d!\n", retval);
468 if (hcd->shared_hcd)
469 usb_hc_died(hcd->shared_hcd);
447 usb_hc_died(hcd); 470 usb_hc_died(hcd);
448 } 471 }
449 } 472 }
@@ -469,10 +492,11 @@ static int hcd_pci_suspend_noirq(struct device *dev)
469 492
470 pci_save_state(pci_dev); 493 pci_save_state(pci_dev);
471 494
472 /* If the root hub is HALTed rather than SUSPENDed, 495 /* If the root hub is dead rather than suspended, disallow remote
473 * disallow remote wakeup. 496 * wakeup. usb_hc_died() should ensure that both hosts are marked as
497 * dying, so we only need to check the primary roothub.
474 */ 498 */
475 if (hcd->state == HC_STATE_HALT) 499 if (HCD_DEAD(hcd))
476 device_set_wakeup_enable(dev, 0); 500 device_set_wakeup_enable(dev, 0);
477 dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); 501 dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev));
478 502
@@ -574,4 +598,4 @@ const struct dev_pm_ops usb_hcd_pci_pm_ops = {
574}; 598};
575EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops); 599EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops);
576 600
577#endif /* CONFIG_PM_OPS */ 601#endif /* CONFIG_PM */
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 5cca00a6d09d..ace9f8442e5d 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -38,7 +38,6 @@
38#include <asm/unaligned.h> 38#include <asm/unaligned.h>
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40#include <linux/workqueue.h> 40#include <linux/workqueue.h>
41#include <linux/pm_runtime.h>
42 41
43#include <linux/usb.h> 42#include <linux/usb.h>
44#include <linux/usb/hcd.h> 43#include <linux/usb/hcd.h>
@@ -298,7 +297,7 @@ static const u8 ss_rh_config_descriptor[] = {
298 /* one configuration */ 297 /* one configuration */
299 0x09, /* __u8 bLength; */ 298 0x09, /* __u8 bLength; */
300 0x02, /* __u8 bDescriptorType; Configuration */ 299 0x02, /* __u8 bDescriptorType; Configuration */
301 0x19, 0x00, /* __le16 wTotalLength; FIXME */ 300 0x1f, 0x00, /* __le16 wTotalLength; */
302 0x01, /* __u8 bNumInterfaces; (1) */ 301 0x01, /* __u8 bNumInterfaces; (1) */
303 0x01, /* __u8 bConfigurationValue; */ 302 0x01, /* __u8 bConfigurationValue; */
304 0x00, /* __u8 iConfiguration; */ 303 0x00, /* __u8 iConfiguration; */
@@ -328,11 +327,14 @@ static const u8 ss_rh_config_descriptor[] = {
328 /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) 327 /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8)
329 * see hub.c:hub_configure() for details. */ 328 * see hub.c:hub_configure() for details. */
330 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, 329 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
331 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ 330 0x0c, /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
332 /* 331
333 * All 3.0 hubs should have an endpoint companion descriptor, 332 /* one SuperSpeed endpoint companion descriptor */
334 * but we're ignoring that for now. FIXME? 333 0x06, /* __u8 ss_bLength */
335 */ 334 0x30, /* __u8 ss_bDescriptorType; SuperSpeed EP Companion */
335 0x00, /* __u8 ss_bMaxBurst; allows 1 TX between ACKs */
336 0x00, /* __u8 ss_bmAttributes; 1 packet per service interval */
337 0x02, 0x00 /* __le16 ss_wBytesPerInterval; 15 bits for max 15 ports */
336}; 338};
337 339
338/*-------------------------------------------------------------------------*/ 340/*-------------------------------------------------------------------------*/
@@ -505,7 +507,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
505 case DeviceRequest | USB_REQ_GET_DESCRIPTOR: 507 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
506 switch (wValue & 0xff00) { 508 switch (wValue & 0xff00) {
507 case USB_DT_DEVICE << 8: 509 case USB_DT_DEVICE << 8:
508 switch (hcd->driver->flags & HCD_MASK) { 510 switch (hcd->speed) {
509 case HCD_USB3: 511 case HCD_USB3:
510 bufp = usb3_rh_dev_descriptor; 512 bufp = usb3_rh_dev_descriptor;
511 break; 513 break;
@@ -523,7 +525,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
523 patch_protocol = 1; 525 patch_protocol = 1;
524 break; 526 break;
525 case USB_DT_CONFIG << 8: 527 case USB_DT_CONFIG << 8:
526 switch (hcd->driver->flags & HCD_MASK) { 528 switch (hcd->speed) {
527 case HCD_USB3: 529 case HCD_USB3:
528 bufp = ss_rh_config_descriptor; 530 bufp = ss_rh_config_descriptor;
529 len = sizeof ss_rh_config_descriptor; 531 len = sizeof ss_rh_config_descriptor;
@@ -698,7 +700,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
698 /* The USB 2.0 spec says 256 ms. This is close enough and won't 700 /* The USB 2.0 spec says 256 ms. This is close enough and won't
699 * exceed that limit if HZ is 100. The math is more clunky than 701 * exceed that limit if HZ is 100. The math is more clunky than
700 * maybe expected, this is to make sure that all timers for USB devices 702 * maybe expected, this is to make sure that all timers for USB devices
701 * fire at the same time to give the CPU a break inbetween */ 703 * fire at the same time to give the CPU a break in between */
702 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : 704 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) :
703 (length == 0 && hcd->status_urb != NULL)) 705 (length == 0 && hcd->status_urb != NULL))
704 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); 706 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4));
@@ -984,7 +986,7 @@ static int register_root_hub(struct usb_hcd *hcd)
984 spin_unlock_irq (&hcd_root_hub_lock); 986 spin_unlock_irq (&hcd_root_hub_lock);
985 987
986 /* Did the HC die before the root hub was registered? */ 988 /* Did the HC die before the root hub was registered? */
987 if (hcd->state == HC_STATE_HALT) 989 if (HCD_DEAD(hcd))
988 usb_hc_died (hcd); /* This time clean up */ 990 usb_hc_died (hcd); /* This time clean up */
989 } 991 }
990 992
@@ -1090,13 +1092,10 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb)
1090 * Check the host controller's state and add the URB to the 1092 * Check the host controller's state and add the URB to the
1091 * endpoint's queue. 1093 * endpoint's queue.
1092 */ 1094 */
1093 switch (hcd->state) { 1095 if (HCD_RH_RUNNING(hcd)) {
1094 case HC_STATE_RUNNING:
1095 case HC_STATE_RESUMING:
1096 urb->unlinked = 0; 1096 urb->unlinked = 0;
1097 list_add_tail(&urb->urb_list, &urb->ep->urb_list); 1097 list_add_tail(&urb->urb_list, &urb->ep->urb_list);
1098 break; 1098 } else {
1099 default:
1100 rc = -ESHUTDOWN; 1099 rc = -ESHUTDOWN;
1101 goto done; 1100 goto done;
1102 } 1101 }
@@ -1154,6 +1153,8 @@ int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
1154 dev_warn(hcd->self.controller, "Unlink after no-IRQ? " 1153 dev_warn(hcd->self.controller, "Unlink after no-IRQ? "
1155 "Controller is probably using the wrong IRQ.\n"); 1154 "Controller is probably using the wrong IRQ.\n");
1156 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 1155 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
1156 if (hcd->shared_hcd)
1157 set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags);
1157 } 1158 }
1158 1159
1159 return 0; 1160 return 0;
@@ -1263,10 +1264,8 @@ static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle,
1263 *dma_handle = 0; 1264 *dma_handle = 0;
1264} 1265}
1265 1266
1266static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) 1267void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb)
1267{ 1268{
1268 enum dma_data_direction dir;
1269
1270 if (urb->transfer_flags & URB_SETUP_MAP_SINGLE) 1269 if (urb->transfer_flags & URB_SETUP_MAP_SINGLE)
1271 dma_unmap_single(hcd->self.controller, 1270 dma_unmap_single(hcd->self.controller,
1272 urb->setup_dma, 1271 urb->setup_dma,
@@ -1279,6 +1278,25 @@ static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1279 sizeof(struct usb_ctrlrequest), 1278 sizeof(struct usb_ctrlrequest),
1280 DMA_TO_DEVICE); 1279 DMA_TO_DEVICE);
1281 1280
1281 /* Make it safe to call this routine more than once */
1282 urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL);
1283}
1284EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_setup_for_dma);
1285
1286static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1287{
1288 if (hcd->driver->unmap_urb_for_dma)
1289 hcd->driver->unmap_urb_for_dma(hcd, urb);
1290 else
1291 usb_hcd_unmap_urb_for_dma(hcd, urb);
1292}
1293
1294void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1295{
1296 enum dma_data_direction dir;
1297
1298 usb_hcd_unmap_urb_setup_for_dma(hcd, urb);
1299
1282 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 1300 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1283 if (urb->transfer_flags & URB_DMA_MAP_SG) 1301 if (urb->transfer_flags & URB_DMA_MAP_SG)
1284 dma_unmap_sg(hcd->self.controller, 1302 dma_unmap_sg(hcd->self.controller,
@@ -1303,14 +1321,23 @@ static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1303 dir); 1321 dir);
1304 1322
1305 /* Make it safe to call this routine more than once */ 1323 /* Make it safe to call this routine more than once */
1306 urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL | 1324 urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE |
1307 URB_DMA_MAP_SG | URB_DMA_MAP_PAGE |
1308 URB_DMA_MAP_SINGLE | URB_MAP_LOCAL); 1325 URB_DMA_MAP_SINGLE | URB_MAP_LOCAL);
1309} 1326}
1327EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_for_dma);
1310 1328
1311static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, 1329static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1312 gfp_t mem_flags) 1330 gfp_t mem_flags)
1313{ 1331{
1332 if (hcd->driver->map_urb_for_dma)
1333 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags);
1334 else
1335 return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
1336}
1337
1338int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1339 gfp_t mem_flags)
1340{
1314 enum dma_data_direction dir; 1341 enum dma_data_direction dir;
1315 int ret = 0; 1342 int ret = 0;
1316 1343
@@ -1321,6 +1348,8 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1321 */ 1348 */
1322 1349
1323 if (usb_endpoint_xfer_control(&urb->ep->desc)) { 1350 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
1351 if (hcd->self.uses_pio_for_control)
1352 return ret;
1324 if (hcd->self.uses_dma) { 1353 if (hcd->self.uses_dma) {
1325 urb->setup_dma = dma_map_single( 1354 urb->setup_dma = dma_map_single(
1326 hcd->self.controller, 1355 hcd->self.controller,
@@ -1400,10 +1429,11 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1400 } 1429 }
1401 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | 1430 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE |
1402 URB_SETUP_MAP_LOCAL))) 1431 URB_SETUP_MAP_LOCAL)))
1403 unmap_urb_for_dma(hcd, urb); 1432 usb_hcd_unmap_urb_for_dma(hcd, urb);
1404 } 1433 }
1405 return ret; 1434 return ret;
1406} 1435}
1436EXPORT_SYMBOL_GPL(usb_hcd_map_urb_for_dma);
1407 1437
1408/*-------------------------------------------------------------------------*/ 1438/*-------------------------------------------------------------------------*/
1409 1439
@@ -1878,7 +1908,7 @@ void usb_free_streams(struct usb_interface *interface,
1878 1908
1879 /* Streams only apply to bulk endpoints. */ 1909 /* Streams only apply to bulk endpoints. */
1880 for (i = 0; i < num_eps; i++) 1910 for (i = 0; i < num_eps; i++)
1881 if (!usb_endpoint_xfer_bulk(&eps[i]->desc)) 1911 if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->desc))
1882 return; 1912 return;
1883 1913
1884 hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); 1914 hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags);
@@ -1903,7 +1933,7 @@ int usb_hcd_get_frame_number (struct usb_device *udev)
1903{ 1933{
1904 struct usb_hcd *hcd = bus_to_hcd(udev->bus); 1934 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1905 1935
1906 if (!HC_IS_RUNNING (hcd->state)) 1936 if (!HCD_RH_RUNNING(hcd))
1907 return -ESHUTDOWN; 1937 return -ESHUTDOWN;
1908 return hcd->driver->get_frame_number (hcd); 1938 return hcd->driver->get_frame_number (hcd);
1909} 1939}
@@ -1920,9 +1950,15 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
1920 1950
1921 dev_dbg(&rhdev->dev, "bus %s%s\n", 1951 dev_dbg(&rhdev->dev, "bus %s%s\n",
1922 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend"); 1952 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend");
1953 if (HCD_DEAD(hcd)) {
1954 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend");
1955 return 0;
1956 }
1957
1923 if (!hcd->driver->bus_suspend) { 1958 if (!hcd->driver->bus_suspend) {
1924 status = -ENOENT; 1959 status = -ENOENT;
1925 } else { 1960 } else {
1961 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
1926 hcd->state = HC_STATE_QUIESCING; 1962 hcd->state = HC_STATE_QUIESCING;
1927 status = hcd->driver->bus_suspend(hcd); 1963 status = hcd->driver->bus_suspend(hcd);
1928 } 1964 }
@@ -1930,7 +1966,12 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
1930 usb_set_device_state(rhdev, USB_STATE_SUSPENDED); 1966 usb_set_device_state(rhdev, USB_STATE_SUSPENDED);
1931 hcd->state = HC_STATE_SUSPENDED; 1967 hcd->state = HC_STATE_SUSPENDED;
1932 } else { 1968 } else {
1933 hcd->state = old_state; 1969 spin_lock_irq(&hcd_root_hub_lock);
1970 if (!HCD_DEAD(hcd)) {
1971 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
1972 hcd->state = old_state;
1973 }
1974 spin_unlock_irq(&hcd_root_hub_lock);
1934 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", 1975 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
1935 "suspend", status); 1976 "suspend", status);
1936 } 1977 }
@@ -1945,21 +1986,30 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
1945 1986
1946 dev_dbg(&rhdev->dev, "usb %s%s\n", 1987 dev_dbg(&rhdev->dev, "usb %s%s\n",
1947 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); 1988 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume");
1948 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); 1989 if (HCD_DEAD(hcd)) {
1990 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume");
1991 return 0;
1992 }
1949 if (!hcd->driver->bus_resume) 1993 if (!hcd->driver->bus_resume)
1950 return -ENOENT; 1994 return -ENOENT;
1951 if (hcd->state == HC_STATE_RUNNING) 1995 if (HCD_RH_RUNNING(hcd))
1952 return 0; 1996 return 0;
1953 1997
1954 hcd->state = HC_STATE_RESUMING; 1998 hcd->state = HC_STATE_RESUMING;
1955 status = hcd->driver->bus_resume(hcd); 1999 status = hcd->driver->bus_resume(hcd);
2000 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
1956 if (status == 0) { 2001 if (status == 0) {
1957 /* TRSMRCY = 10 msec */ 2002 /* TRSMRCY = 10 msec */
1958 msleep(10); 2003 msleep(10);
1959 usb_set_device_state(rhdev, rhdev->actconfig 2004 spin_lock_irq(&hcd_root_hub_lock);
1960 ? USB_STATE_CONFIGURED 2005 if (!HCD_DEAD(hcd)) {
1961 : USB_STATE_ADDRESS); 2006 usb_set_device_state(rhdev, rhdev->actconfig
1962 hcd->state = HC_STATE_RUNNING; 2007 ? USB_STATE_CONFIGURED
2008 : USB_STATE_ADDRESS);
2009 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2010 hcd->state = HC_STATE_RUNNING;
2011 }
2012 spin_unlock_irq(&hcd_root_hub_lock);
1963 } else { 2013 } else {
1964 hcd->state = old_state; 2014 hcd->state = old_state;
1965 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", 2015 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
@@ -2070,15 +2120,14 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd)
2070 */ 2120 */
2071 local_irq_save(flags); 2121 local_irq_save(flags);
2072 2122
2073 if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) { 2123 if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) {
2074 rc = IRQ_NONE; 2124 rc = IRQ_NONE;
2075 } else if (hcd->driver->irq(hcd) == IRQ_NONE) { 2125 } else if (hcd->driver->irq(hcd) == IRQ_NONE) {
2076 rc = IRQ_NONE; 2126 rc = IRQ_NONE;
2077 } else { 2127 } else {
2078 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 2128 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
2079 2129 if (hcd->shared_hcd)
2080 if (unlikely(hcd->state == HC_STATE_HALT)) 2130 set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags);
2081 usb_hc_died(hcd);
2082 rc = IRQ_HANDLED; 2131 rc = IRQ_HANDLED;
2083 } 2132 }
2084 2133
@@ -2095,7 +2144,9 @@ EXPORT_SYMBOL_GPL(usb_hcd_irq);
2095 * 2144 *
2096 * This is called by bus glue to report a USB host controller that died 2145 * This is called by bus glue to report a USB host controller that died
2097 * while operations may still have been pending. It's called automatically 2146 * while operations may still have been pending. It's called automatically
2098 * by the PCI glue, so only glue for non-PCI busses should need to call it. 2147 * by the PCI glue, so only glue for non-PCI busses should need to call it.
2148 *
2149 * Only call this function with the primary HCD.
2099 */ 2150 */
2100void usb_hc_died (struct usb_hcd *hcd) 2151void usb_hc_died (struct usb_hcd *hcd)
2101{ 2152{
@@ -2104,6 +2155,8 @@ void usb_hc_died (struct usb_hcd *hcd)
2104 dev_err (hcd->self.controller, "HC died; cleaning up\n"); 2155 dev_err (hcd->self.controller, "HC died; cleaning up\n");
2105 2156
2106 spin_lock_irqsave (&hcd_root_hub_lock, flags); 2157 spin_lock_irqsave (&hcd_root_hub_lock, flags);
2158 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2159 set_bit(HCD_FLAG_DEAD, &hcd->flags);
2107 if (hcd->rh_registered) { 2160 if (hcd->rh_registered) {
2108 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2161 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2109 2162
@@ -2112,17 +2165,31 @@ void usb_hc_died (struct usb_hcd *hcd)
2112 USB_STATE_NOTATTACHED); 2165 USB_STATE_NOTATTACHED);
2113 usb_kick_khubd (hcd->self.root_hub); 2166 usb_kick_khubd (hcd->self.root_hub);
2114 } 2167 }
2168 if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) {
2169 hcd = hcd->shared_hcd;
2170 if (hcd->rh_registered) {
2171 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2172
2173 /* make khubd clean up old urbs and devices */
2174 usb_set_device_state(hcd->self.root_hub,
2175 USB_STATE_NOTATTACHED);
2176 usb_kick_khubd(hcd->self.root_hub);
2177 }
2178 }
2115 spin_unlock_irqrestore (&hcd_root_hub_lock, flags); 2179 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
2180 /* Make sure that the other roothub is also deallocated. */
2116} 2181}
2117EXPORT_SYMBOL_GPL (usb_hc_died); 2182EXPORT_SYMBOL_GPL (usb_hc_died);
2118 2183
2119/*-------------------------------------------------------------------------*/ 2184/*-------------------------------------------------------------------------*/
2120 2185
2121/** 2186/**
2122 * usb_create_hcd - create and initialize an HCD structure 2187 * usb_create_shared_hcd - create and initialize an HCD structure
2123 * @driver: HC driver that will use this hcd 2188 * @driver: HC driver that will use this hcd
2124 * @dev: device for this HC, stored in hcd->self.controller 2189 * @dev: device for this HC, stored in hcd->self.controller
2125 * @bus_name: value to store in hcd->self.bus_name 2190 * @bus_name: value to store in hcd->self.bus_name
2191 * @primary_hcd: a pointer to the usb_hcd structure that is sharing the
2192 * PCI device. Only allocate certain resources for the primary HCD
2126 * Context: !in_interrupt() 2193 * Context: !in_interrupt()
2127 * 2194 *
2128 * Allocate a struct usb_hcd, with extra space at the end for the 2195 * Allocate a struct usb_hcd, with extra space at the end for the
@@ -2131,8 +2198,9 @@ EXPORT_SYMBOL_GPL (usb_hc_died);
2131 * 2198 *
2132 * If memory is unavailable, returns NULL. 2199 * If memory is unavailable, returns NULL.
2133 */ 2200 */
2134struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, 2201struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
2135 struct device *dev, const char *bus_name) 2202 struct device *dev, const char *bus_name,
2203 struct usb_hcd *primary_hcd)
2136{ 2204{
2137 struct usb_hcd *hcd; 2205 struct usb_hcd *hcd;
2138 2206
@@ -2141,7 +2209,24 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
2141 dev_dbg (dev, "hcd alloc failed\n"); 2209 dev_dbg (dev, "hcd alloc failed\n");
2142 return NULL; 2210 return NULL;
2143 } 2211 }
2144 dev_set_drvdata(dev, hcd); 2212 if (primary_hcd == NULL) {
2213 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex),
2214 GFP_KERNEL);
2215 if (!hcd->bandwidth_mutex) {
2216 kfree(hcd);
2217 dev_dbg(dev, "hcd bandwidth mutex alloc failed\n");
2218 return NULL;
2219 }
2220 mutex_init(hcd->bandwidth_mutex);
2221 dev_set_drvdata(dev, hcd);
2222 } else {
2223 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex;
2224 hcd->primary_hcd = primary_hcd;
2225 primary_hcd->primary_hcd = primary_hcd;
2226 hcd->shared_hcd = primary_hcd;
2227 primary_hcd->shared_hcd = hcd;
2228 }
2229
2145 kref_init(&hcd->kref); 2230 kref_init(&hcd->kref);
2146 2231
2147 usb_bus_init(&hcd->self); 2232 usb_bus_init(&hcd->self);
@@ -2155,19 +2240,53 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
2155#ifdef CONFIG_USB_SUSPEND 2240#ifdef CONFIG_USB_SUSPEND
2156 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); 2241 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
2157#endif 2242#endif
2158 mutex_init(&hcd->bandwidth_mutex);
2159 2243
2160 hcd->driver = driver; 2244 hcd->driver = driver;
2245 hcd->speed = driver->flags & HCD_MASK;
2161 hcd->product_desc = (driver->product_desc) ? driver->product_desc : 2246 hcd->product_desc = (driver->product_desc) ? driver->product_desc :
2162 "USB Host Controller"; 2247 "USB Host Controller";
2163 return hcd; 2248 return hcd;
2164} 2249}
2250EXPORT_SYMBOL_GPL(usb_create_shared_hcd);
2251
2252/**
2253 * usb_create_hcd - create and initialize an HCD structure
2254 * @driver: HC driver that will use this hcd
2255 * @dev: device for this HC, stored in hcd->self.controller
2256 * @bus_name: value to store in hcd->self.bus_name
2257 * Context: !in_interrupt()
2258 *
2259 * Allocate a struct usb_hcd, with extra space at the end for the
2260 * HC driver's private data. Initialize the generic members of the
2261 * hcd structure.
2262 *
2263 * If memory is unavailable, returns NULL.
2264 */
2265struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
2266 struct device *dev, const char *bus_name)
2267{
2268 return usb_create_shared_hcd(driver, dev, bus_name, NULL);
2269}
2165EXPORT_SYMBOL_GPL(usb_create_hcd); 2270EXPORT_SYMBOL_GPL(usb_create_hcd);
2166 2271
2272/*
2273 * Roothubs that share one PCI device must also share the bandwidth mutex.
2274 * Don't deallocate the bandwidth_mutex until the last shared usb_hcd is
2275 * deallocated.
2276 *
2277 * Make sure to only deallocate the bandwidth_mutex when the primary HCD is
2278 * freed. When hcd_release() is called for the non-primary HCD, set the
2279 * primary_hcd's shared_hcd pointer to null (since the non-primary HCD will be
2280 * freed shortly).
2281 */
2167static void hcd_release (struct kref *kref) 2282static void hcd_release (struct kref *kref)
2168{ 2283{
2169 struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); 2284 struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref);
2170 2285
2286 if (usb_hcd_is_primary_hcd(hcd))
2287 kfree(hcd->bandwidth_mutex);
2288 else
2289 hcd->shared_hcd->shared_hcd = NULL;
2171 kfree(hcd); 2290 kfree(hcd);
2172} 2291}
2173 2292
@@ -2186,6 +2305,54 @@ void usb_put_hcd (struct usb_hcd *hcd)
2186} 2305}
2187EXPORT_SYMBOL_GPL(usb_put_hcd); 2306EXPORT_SYMBOL_GPL(usb_put_hcd);
2188 2307
2308int usb_hcd_is_primary_hcd(struct usb_hcd *hcd)
2309{
2310 if (!hcd->primary_hcd)
2311 return 1;
2312 return hcd == hcd->primary_hcd;
2313}
2314EXPORT_SYMBOL_GPL(usb_hcd_is_primary_hcd);
2315
2316static int usb_hcd_request_irqs(struct usb_hcd *hcd,
2317 unsigned int irqnum, unsigned long irqflags)
2318{
2319 int retval;
2320
2321 if (hcd->driver->irq) {
2322
2323 /* IRQF_DISABLED doesn't work as advertised when used together
2324 * with IRQF_SHARED. As usb_hcd_irq() will always disable
2325 * interrupts we can remove it here.
2326 */
2327 if (irqflags & IRQF_SHARED)
2328 irqflags &= ~IRQF_DISABLED;
2329
2330 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
2331 hcd->driver->description, hcd->self.busnum);
2332 retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
2333 hcd->irq_descr, hcd);
2334 if (retval != 0) {
2335 dev_err(hcd->self.controller,
2336 "request interrupt %d failed\n",
2337 irqnum);
2338 return retval;
2339 }
2340 hcd->irq = irqnum;
2341 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum,
2342 (hcd->driver->flags & HCD_MEMORY) ?
2343 "io mem" : "io base",
2344 (unsigned long long)hcd->rsrc_start);
2345 } else {
2346 hcd->irq = -1;
2347 if (hcd->rsrc_start)
2348 dev_info(hcd->self.controller, "%s 0x%08llx\n",
2349 (hcd->driver->flags & HCD_MEMORY) ?
2350 "io mem" : "io base",
2351 (unsigned long long)hcd->rsrc_start);
2352 }
2353 return 0;
2354}
2355
2189/** 2356/**
2190 * usb_add_hcd - finish generic HCD structure initialization and register 2357 * usb_add_hcd - finish generic HCD structure initialization and register
2191 * @hcd: the usb_hcd structure to initialize 2358 * @hcd: the usb_hcd structure to initialize
@@ -2226,7 +2393,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2226 } 2393 }
2227 hcd->self.root_hub = rhdev; 2394 hcd->self.root_hub = rhdev;
2228 2395
2229 switch (hcd->driver->flags & HCD_MASK) { 2396 switch (hcd->speed) {
2230 case HCD_USB11: 2397 case HCD_USB11:
2231 rhdev->speed = USB_SPEED_FULL; 2398 rhdev->speed = USB_SPEED_FULL;
2232 break; 2399 break;
@@ -2237,6 +2404,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2237 rhdev->speed = USB_SPEED_SUPER; 2404 rhdev->speed = USB_SPEED_SUPER;
2238 break; 2405 break;
2239 default: 2406 default:
2407 retval = -EINVAL;
2240 goto err_set_rh_speed; 2408 goto err_set_rh_speed;
2241 } 2409 }
2242 2410
@@ -2246,6 +2414,12 @@ int usb_add_hcd(struct usb_hcd *hcd,
2246 */ 2414 */
2247 device_init_wakeup(&rhdev->dev, 1); 2415 device_init_wakeup(&rhdev->dev, 1);
2248 2416
2417 /* HCD_FLAG_RH_RUNNING doesn't matter until the root hub is
2418 * registered. But since the controller can die at any time,
2419 * let's initialize the flag before touching the hardware.
2420 */
2421 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2422
2249 /* "reset" is misnamed; its role is now one-time init. the controller 2423 /* "reset" is misnamed; its role is now one-time init. the controller
2250 * should already have been reset (and boot firmware kicked off etc). 2424 * should already have been reset (and boot firmware kicked off etc).
2251 */ 2425 */
@@ -2261,38 +2435,15 @@ int usb_add_hcd(struct usb_hcd *hcd,
2261 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); 2435 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
2262 2436
2263 /* enable irqs just before we start the controller */ 2437 /* enable irqs just before we start the controller */
2264 if (hcd->driver->irq) { 2438 if (usb_hcd_is_primary_hcd(hcd)) {
2265 2439 retval = usb_hcd_request_irqs(hcd, irqnum, irqflags);
2266 /* IRQF_DISABLED doesn't work as advertised when used together 2440 if (retval)
2267 * with IRQF_SHARED. As usb_hcd_irq() will always disable
2268 * interrupts we can remove it here.
2269 */
2270 if (irqflags & IRQF_SHARED)
2271 irqflags &= ~IRQF_DISABLED;
2272
2273 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
2274 hcd->driver->description, hcd->self.busnum);
2275 if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
2276 hcd->irq_descr, hcd)) != 0) {
2277 dev_err(hcd->self.controller,
2278 "request interrupt %d failed\n", irqnum);
2279 goto err_request_irq; 2441 goto err_request_irq;
2280 }
2281 hcd->irq = irqnum;
2282 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum,
2283 (hcd->driver->flags & HCD_MEMORY) ?
2284 "io mem" : "io base",
2285 (unsigned long long)hcd->rsrc_start);
2286 } else {
2287 hcd->irq = -1;
2288 if (hcd->rsrc_start)
2289 dev_info(hcd->self.controller, "%s 0x%08llx\n",
2290 (hcd->driver->flags & HCD_MEMORY) ?
2291 "io mem" : "io base",
2292 (unsigned long long)hcd->rsrc_start);
2293 } 2442 }
2294 2443
2295 if ((retval = hcd->driver->start(hcd)) < 0) { 2444 hcd->state = HC_STATE_RUNNING;
2445 retval = hcd->driver->start(hcd);
2446 if (retval < 0) {
2296 dev_err(hcd->self.controller, "startup error %d\n", retval); 2447 dev_err(hcd->self.controller, "startup error %d\n", retval);
2297 goto err_hcd_driver_start; 2448 goto err_hcd_driver_start;
2298 } 2449 }
@@ -2313,6 +2464,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2313 return retval; 2464 return retval;
2314 2465
2315error_create_attr_group: 2466error_create_attr_group:
2467 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2316 if (HC_IS_RUNNING(hcd->state)) 2468 if (HC_IS_RUNNING(hcd->state))
2317 hcd->state = HC_STATE_QUIESCING; 2469 hcd->state = HC_STATE_QUIESCING;
2318 spin_lock_irq(&hcd_root_hub_lock); 2470 spin_lock_irq(&hcd_root_hub_lock);
@@ -2334,7 +2486,7 @@ err_register_root_hub:
2334 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2486 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2335 del_timer_sync(&hcd->rh_timer); 2487 del_timer_sync(&hcd->rh_timer);
2336err_hcd_driver_start: 2488err_hcd_driver_start:
2337 if (hcd->irq >= 0) 2489 if (usb_hcd_is_primary_hcd(hcd) && hcd->irq >= 0)
2338 free_irq(irqnum, hcd); 2490 free_irq(irqnum, hcd);
2339err_request_irq: 2491err_request_irq:
2340err_hcd_driver_setup: 2492err_hcd_driver_setup:
@@ -2365,6 +2517,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2365 usb_get_dev(rhdev); 2517 usb_get_dev(rhdev);
2366 sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group); 2518 sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group);
2367 2519
2520 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2368 if (HC_IS_RUNNING (hcd->state)) 2521 if (HC_IS_RUNNING (hcd->state))
2369 hcd->state = HC_STATE_QUIESCING; 2522 hcd->state = HC_STATE_QUIESCING;
2370 2523
@@ -2397,8 +2550,10 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2397 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2550 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2398 del_timer_sync(&hcd->rh_timer); 2551 del_timer_sync(&hcd->rh_timer);
2399 2552
2400 if (hcd->irq >= 0) 2553 if (usb_hcd_is_primary_hcd(hcd)) {
2401 free_irq(hcd->irq, hcd); 2554 if (hcd->irq >= 0)
2555 free_irq(hcd->irq, hcd);
2556 }
2402 2557
2403 usb_put_dev(hcd->self.root_hub); 2558 usb_put_dev(hcd->self.root_hub);
2404 usb_deregister_bus(&hcd->self); 2559 usb_deregister_bus(&hcd->self);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 84c1897188d2..a428aa080a36 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -24,7 +24,6 @@
24#include <linux/kthread.h> 24#include <linux/kthread.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/freezer.h> 26#include <linux/freezer.h>
27#include <linux/pm_runtime.h>
28 27
29#include <asm/uaccess.h> 28#include <asm/uaccess.h>
30#include <asm/byteorder.h> 29#include <asm/byteorder.h>
@@ -83,6 +82,10 @@ struct usb_hub {
83 void **port_owners; 82 void **port_owners;
84}; 83};
85 84
85static inline int hub_is_superspeed(struct usb_device *hdev)
86{
87 return (hdev->descriptor.bDeviceProtocol == 3);
88}
86 89
87/* Protect struct usb_device->state and ->children members 90/* Protect struct usb_device->state and ->children members
88 * Note: Both are also protected by ->dev.sem, except that ->state can 91 * Note: Both are also protected by ->dev.sem, except that ->state can
@@ -152,14 +155,14 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem);
152 155
153static int usb_reset_and_verify_device(struct usb_device *udev); 156static int usb_reset_and_verify_device(struct usb_device *udev);
154 157
155static inline char *portspeed(int portstatus) 158static inline char *portspeed(struct usb_hub *hub, int portstatus)
156{ 159{
160 if (hub_is_superspeed(hub->hdev))
161 return "5.0 Gb/s";
157 if (portstatus & USB_PORT_STAT_HIGH_SPEED) 162 if (portstatus & USB_PORT_STAT_HIGH_SPEED)
158 return "480 Mb/s"; 163 return "480 Mb/s";
159 else if (portstatus & USB_PORT_STAT_LOW_SPEED) 164 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
160 return "1.5 Mb/s"; 165 return "1.5 Mb/s";
161 else if (portstatus & USB_PORT_STAT_SUPER_SPEED)
162 return "5.0 Gb/s";
163 else 166 else
164 return "12 Mb/s"; 167 return "12 Mb/s";
165} 168}
@@ -173,14 +176,23 @@ static struct usb_hub *hdev_to_hub(struct usb_device *hdev)
173} 176}
174 177
175/* USB 2.0 spec Section 11.24.4.5 */ 178/* USB 2.0 spec Section 11.24.4.5 */
176static int get_hub_descriptor(struct usb_device *hdev, void *data, int size) 179static int get_hub_descriptor(struct usb_device *hdev, void *data)
177{ 180{
178 int i, ret; 181 int i, ret, size;
182 unsigned dtype;
183
184 if (hub_is_superspeed(hdev)) {
185 dtype = USB_DT_SS_HUB;
186 size = USB_DT_SS_HUB_SIZE;
187 } else {
188 dtype = USB_DT_HUB;
189 size = sizeof(struct usb_hub_descriptor);
190 }
179 191
180 for (i = 0; i < 3; i++) { 192 for (i = 0; i < 3; i++) {
181 ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), 193 ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0),
182 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, 194 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB,
183 USB_DT_HUB << 8, 0, data, size, 195 dtype << 8, 0, data, size,
184 USB_CTRL_GET_TIMEOUT); 196 USB_CTRL_GET_TIMEOUT);
185 if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2)) 197 if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2))
186 return ret; 198 return ret;
@@ -327,7 +339,8 @@ static int get_hub_status(struct usb_device *hdev,
327{ 339{
328 int i, status = -ETIMEDOUT; 340 int i, status = -ETIMEDOUT;
329 341
330 for (i = 0; i < USB_STS_RETRIES && status == -ETIMEDOUT; i++) { 342 for (i = 0; i < USB_STS_RETRIES &&
343 (status == -ETIMEDOUT || status == -EPIPE); i++) {
331 status = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), 344 status = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0),
332 USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0, 345 USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0,
333 data, sizeof(*data), USB_STS_TIMEOUT); 346 data, sizeof(*data), USB_STS_TIMEOUT);
@@ -343,7 +356,8 @@ static int get_port_status(struct usb_device *hdev, int port1,
343{ 356{
344 int i, status = -ETIMEDOUT; 357 int i, status = -ETIMEDOUT;
345 358
346 for (i = 0; i < USB_STS_RETRIES && status == -ETIMEDOUT; i++) { 359 for (i = 0; i < USB_STS_RETRIES &&
360 (status == -ETIMEDOUT || status == -EPIPE); i++) {
347 status = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), 361 status = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0),
348 USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port1, 362 USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port1,
349 data, sizeof(*data), USB_STS_TIMEOUT); 363 data, sizeof(*data), USB_STS_TIMEOUT);
@@ -366,6 +380,7 @@ static int hub_port_status(struct usb_hub *hub, int port1,
366 } else { 380 } else {
367 *status = le16_to_cpu(hub->status->port.wPortStatus); 381 *status = le16_to_cpu(hub->status->port.wPortStatus);
368 *change = le16_to_cpu(hub->status->port.wPortChange); 382 *change = le16_to_cpu(hub->status->port.wPortChange);
383
369 ret = 0; 384 ret = 0;
370 } 385 }
371 mutex_unlock(&hub->status_mutex); 386 mutex_unlock(&hub->status_mutex);
@@ -608,7 +623,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
608 if (hdev->children[port1-1] && set_state) 623 if (hdev->children[port1-1] && set_state)
609 usb_set_device_state(hdev->children[port1-1], 624 usb_set_device_state(hdev->children[port1-1],
610 USB_STATE_NOTATTACHED); 625 USB_STATE_NOTATTACHED);
611 if (!hub->error) 626 if (!hub->error && !hub_is_superspeed(hub->hdev))
612 ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); 627 ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE);
613 if (ret) 628 if (ret)
614 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", 629 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
@@ -617,7 +632,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
617} 632}
618 633
619/* 634/*
620 * Disable a port and mark a logical connnect-change event, so that some 635 * Disable a port and mark a logical connect-change event, so that some
621 * time later khubd will disconnect() any existing usb_device on the port 636 * time later khubd will disconnect() any existing usb_device on the port
622 * and will re-enumerate if there actually is a device attached. 637 * and will re-enumerate if there actually is a device attached.
623 */ 638 */
@@ -677,6 +692,8 @@ static void hub_init_func3(struct work_struct *ws);
677static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) 692static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
678{ 693{
679 struct usb_device *hdev = hub->hdev; 694 struct usb_device *hdev = hub->hdev;
695 struct usb_hcd *hcd;
696 int ret;
680 int port1; 697 int port1;
681 int status; 698 int status;
682 bool need_debounce_delay = false; 699 bool need_debounce_delay = false;
@@ -715,6 +732,25 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
715 usb_autopm_get_interface_no_resume( 732 usb_autopm_get_interface_no_resume(
716 to_usb_interface(hub->intfdev)); 733 to_usb_interface(hub->intfdev));
717 return; /* Continues at init2: below */ 734 return; /* Continues at init2: below */
735 } else if (type == HUB_RESET_RESUME) {
736 /* The internal host controller state for the hub device
737 * may be gone after a host power loss on system resume.
738 * Update the device's info so the HW knows it's a hub.
739 */
740 hcd = bus_to_hcd(hdev->bus);
741 if (hcd->driver->update_hub_device) {
742 ret = hcd->driver->update_hub_device(hcd, hdev,
743 &hub->tt, GFP_NOIO);
744 if (ret < 0) {
745 dev_err(hub->intfdev, "Host not "
746 "accepting hub info "
747 "update.\n");
748 dev_err(hub->intfdev, "LS/FS devices "
749 "and hubs may not work "
750 "under this hub\n.");
751 }
752 }
753 hub_power_on(hub, true);
718 } else { 754 } else {
719 hub_power_on(hub, true); 755 hub_power_on(hub, true);
720 } 756 }
@@ -749,15 +785,14 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
749 * USB3 protocol ports will automatically transition 785 * USB3 protocol ports will automatically transition
750 * to Enabled state when detect an USB3.0 device attach. 786 * to Enabled state when detect an USB3.0 device attach.
751 * Do not disable USB3 protocol ports. 787 * Do not disable USB3 protocol ports.
752 * FIXME: USB3 root hub and external hubs are treated
753 * differently here.
754 */ 788 */
755 if (hdev->descriptor.bDeviceProtocol != 3 || 789 if (!hub_is_superspeed(hdev)) {
756 (!hdev->parent &&
757 !(portstatus & USB_PORT_STAT_SUPER_SPEED))) {
758 clear_port_feature(hdev, port1, 790 clear_port_feature(hdev, port1,
759 USB_PORT_FEAT_ENABLE); 791 USB_PORT_FEAT_ENABLE);
760 portstatus &= ~USB_PORT_STAT_ENABLE; 792 portstatus &= ~USB_PORT_STAT_ENABLE;
793 } else {
794 /* Pretend that power was lost for USB3 devs */
795 portstatus &= ~USB_PORT_STAT_ENABLE;
761 } 796 }
762 } 797 }
763 798
@@ -772,6 +807,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
772 clear_port_feature(hub->hdev, port1, 807 clear_port_feature(hub->hdev, port1,
773 USB_PORT_FEAT_C_ENABLE); 808 USB_PORT_FEAT_C_ENABLE);
774 } 809 }
810 if (portchange & USB_PORT_STAT_C_LINK_STATE) {
811 need_debounce_delay = true;
812 clear_port_feature(hub->hdev, port1,
813 USB_PORT_FEAT_C_PORT_LINK_STATE);
814 }
775 815
776 /* We can forget about a "removed" device when there's a 816 /* We can forget about a "removed" device when there's a
777 * physical disconnect or the connect status changes. 817 * physical disconnect or the connect status changes.
@@ -941,12 +981,23 @@ static int hub_configure(struct usb_hub *hub,
941 goto fail; 981 goto fail;
942 } 982 }
943 983
984 if (hub_is_superspeed(hdev) && (hdev->parent != NULL)) {
985 ret = usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
986 HUB_SET_DEPTH, USB_RT_HUB,
987 hdev->level - 1, 0, NULL, 0,
988 USB_CTRL_SET_TIMEOUT);
989
990 if (ret < 0) {
991 message = "can't set hub depth";
992 goto fail;
993 }
994 }
995
944 /* Request the entire hub descriptor. 996 /* Request the entire hub descriptor.
945 * hub->descriptor can handle USB_MAXCHILDREN ports, 997 * hub->descriptor can handle USB_MAXCHILDREN ports,
946 * but the hub can/will return fewer bytes here. 998 * but the hub can/will return fewer bytes here.
947 */ 999 */
948 ret = get_hub_descriptor(hdev, hub->descriptor, 1000 ret = get_hub_descriptor(hdev, hub->descriptor);
949 sizeof(*hub->descriptor));
950 if (ret < 0) { 1001 if (ret < 0) {
951 message = "can't read hub descriptor"; 1002 message = "can't read hub descriptor";
952 goto fail; 1003 goto fail;
@@ -968,12 +1019,14 @@ static int hub_configure(struct usb_hub *hub,
968 1019
969 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); 1020 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
970 1021
971 if (wHubCharacteristics & HUB_CHAR_COMPOUND) { 1022 /* FIXME for USB 3.0, skip for now */
1023 if ((wHubCharacteristics & HUB_CHAR_COMPOUND) &&
1024 !(hub_is_superspeed(hdev))) {
972 int i; 1025 int i;
973 char portstr [USB_MAXCHILDREN + 1]; 1026 char portstr [USB_MAXCHILDREN + 1];
974 1027
975 for (i = 0; i < hdev->maxchild; i++) 1028 for (i = 0; i < hdev->maxchild; i++)
976 portstr[i] = hub->descriptor->DeviceRemovable 1029 portstr[i] = hub->descriptor->u.hs.DeviceRemovable
977 [((i + 1) / 8)] & (1 << ((i + 1) % 8)) 1030 [((i + 1) / 8)] & (1 << ((i + 1) % 8))
978 ? 'F' : 'R'; 1031 ? 'F' : 'R';
979 portstr[hdev->maxchild] = 0; 1032 portstr[hdev->maxchild] = 0;
@@ -1230,8 +1283,14 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
1230 desc = intf->cur_altsetting; 1283 desc = intf->cur_altsetting;
1231 hdev = interface_to_usbdev(intf); 1284 hdev = interface_to_usbdev(intf);
1232 1285
1233 /* Hubs have proper suspend/resume support */ 1286 /* Hubs have proper suspend/resume support. USB 3.0 device suspend is
1234 usb_enable_autosuspend(hdev); 1287 * different from USB 2.0/1.1 device suspend, and unfortunately we
1288 * don't support it yet. So leave autosuspend disabled for USB 3.0
1289 * external hubs for now. Enable autosuspend for USB 3.0 roothubs,
1290 * since that isn't a "real" hub.
1291 */
1292 if (!hub_is_superspeed(hdev) || !hdev->parent)
1293 usb_enable_autosuspend(hdev);
1235 1294
1236 if (hdev->level == MAX_TOPO_LEVEL) { 1295 if (hdev->level == MAX_TOPO_LEVEL) {
1237 dev_err(&intf->dev, 1296 dev_err(&intf->dev,
@@ -1442,6 +1501,7 @@ void usb_set_device_state(struct usb_device *udev,
1442 enum usb_device_state new_state) 1501 enum usb_device_state new_state)
1443{ 1502{
1444 unsigned long flags; 1503 unsigned long flags;
1504 int wakeup = -1;
1445 1505
1446 spin_lock_irqsave(&device_state_lock, flags); 1506 spin_lock_irqsave(&device_state_lock, flags);
1447 if (udev->state == USB_STATE_NOTATTACHED) 1507 if (udev->state == USB_STATE_NOTATTACHED)
@@ -1456,11 +1516,10 @@ void usb_set_device_state(struct usb_device *udev,
1456 || new_state == USB_STATE_SUSPENDED) 1516 || new_state == USB_STATE_SUSPENDED)
1457 ; /* No change to wakeup settings */ 1517 ; /* No change to wakeup settings */
1458 else if (new_state == USB_STATE_CONFIGURED) 1518 else if (new_state == USB_STATE_CONFIGURED)
1459 device_set_wakeup_capable(&udev->dev, 1519 wakeup = udev->actconfig->desc.bmAttributes
1460 (udev->actconfig->desc.bmAttributes 1520 & USB_CONFIG_ATT_WAKEUP;
1461 & USB_CONFIG_ATT_WAKEUP));
1462 else 1521 else
1463 device_set_wakeup_capable(&udev->dev, 0); 1522 wakeup = 0;
1464 } 1523 }
1465 if (udev->state == USB_STATE_SUSPENDED && 1524 if (udev->state == USB_STATE_SUSPENDED &&
1466 new_state != USB_STATE_SUSPENDED) 1525 new_state != USB_STATE_SUSPENDED)
@@ -1472,10 +1531,19 @@ void usb_set_device_state(struct usb_device *udev,
1472 } else 1531 } else
1473 recursively_mark_NOTATTACHED(udev); 1532 recursively_mark_NOTATTACHED(udev);
1474 spin_unlock_irqrestore(&device_state_lock, flags); 1533 spin_unlock_irqrestore(&device_state_lock, flags);
1534 if (wakeup >= 0)
1535 device_set_wakeup_capable(&udev->dev, wakeup);
1475} 1536}
1476EXPORT_SYMBOL_GPL(usb_set_device_state); 1537EXPORT_SYMBOL_GPL(usb_set_device_state);
1477 1538
1478/* 1539/*
1540 * Choose a device number.
1541 *
1542 * Device numbers are used as filenames in usbfs. On USB-1.1 and
1543 * USB-2.0 buses they are also used as device addresses, however on
1544 * USB-3.0 buses the address is assigned by the controller hardware
1545 * and it usually is not the same as the device number.
1546 *
1479 * WUSB devices are simple: they have no hubs behind, so the mapping 1547 * WUSB devices are simple: they have no hubs behind, so the mapping
1480 * device <-> virtual port number becomes 1:1. Why? to simplify the 1548 * device <-> virtual port number becomes 1:1. Why? to simplify the
1481 * life of the device connection logic in 1549 * life of the device connection logic in
@@ -1497,7 +1565,7 @@ EXPORT_SYMBOL_GPL(usb_set_device_state);
1497 * the HCD must setup data structures before issuing a set address 1565 * the HCD must setup data structures before issuing a set address
1498 * command to the hardware. 1566 * command to the hardware.
1499 */ 1567 */
1500static void choose_address(struct usb_device *udev) 1568static void choose_devnum(struct usb_device *udev)
1501{ 1569{
1502 int devnum; 1570 int devnum;
1503 struct usb_bus *bus = udev->bus; 1571 struct usb_bus *bus = udev->bus;
@@ -1522,7 +1590,7 @@ static void choose_address(struct usb_device *udev)
1522 } 1590 }
1523} 1591}
1524 1592
1525static void release_address(struct usb_device *udev) 1593static void release_devnum(struct usb_device *udev)
1526{ 1594{
1527 if (udev->devnum > 0) { 1595 if (udev->devnum > 0) {
1528 clear_bit(udev->devnum, udev->bus->devmap.devicemap); 1596 clear_bit(udev->devnum, udev->bus->devmap.devicemap);
@@ -1530,7 +1598,7 @@ static void release_address(struct usb_device *udev)
1530 } 1598 }
1531} 1599}
1532 1600
1533static void update_address(struct usb_device *udev, int devnum) 1601static void update_devnum(struct usb_device *udev, int devnum)
1534{ 1602{
1535 /* The address for a WUSB device is managed by wusbcore. */ 1603 /* The address for a WUSB device is managed by wusbcore. */
1536 if (!udev->wusb) 1604 if (!udev->wusb)
@@ -1566,6 +1634,7 @@ void usb_disconnect(struct usb_device **pdev)
1566{ 1634{
1567 struct usb_device *udev = *pdev; 1635 struct usb_device *udev = *pdev;
1568 int i; 1636 int i;
1637 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1569 1638
1570 if (!udev) { 1639 if (!udev) {
1571 pr_debug ("%s nodev\n", __func__); 1640 pr_debug ("%s nodev\n", __func__);
@@ -1574,10 +1643,11 @@ void usb_disconnect(struct usb_device **pdev)
1574 1643
1575 /* mark the device as inactive, so any further urb submissions for 1644 /* mark the device as inactive, so any further urb submissions for
1576 * this device (and any of its children) will fail immediately. 1645 * this device (and any of its children) will fail immediately.
1577 * this quiesces everyting except pending urbs. 1646 * this quiesces everything except pending urbs.
1578 */ 1647 */
1579 usb_set_device_state(udev, USB_STATE_NOTATTACHED); 1648 usb_set_device_state(udev, USB_STATE_NOTATTACHED);
1580 dev_info (&udev->dev, "USB disconnect, address %d\n", udev->devnum); 1649 dev_info(&udev->dev, "USB disconnect, device number %d\n",
1650 udev->devnum);
1581 1651
1582 usb_lock_device(udev); 1652 usb_lock_device(udev);
1583 1653
@@ -1592,7 +1662,9 @@ void usb_disconnect(struct usb_device **pdev)
1592 * so that the hardware is now fully quiesced. 1662 * so that the hardware is now fully quiesced.
1593 */ 1663 */
1594 dev_dbg (&udev->dev, "unregistering device\n"); 1664 dev_dbg (&udev->dev, "unregistering device\n");
1665 mutex_lock(hcd->bandwidth_mutex);
1595 usb_disable_device(udev, 0); 1666 usb_disable_device(udev, 0);
1667 mutex_unlock(hcd->bandwidth_mutex);
1596 usb_hcd_synchronize_unlinks(udev); 1668 usb_hcd_synchronize_unlinks(udev);
1597 1669
1598 usb_remove_ep_devs(&udev->ep0); 1670 usb_remove_ep_devs(&udev->ep0);
@@ -1607,7 +1679,7 @@ void usb_disconnect(struct usb_device **pdev)
1607 /* Free the device number and delete the parent's children[] 1679 /* Free the device number and delete the parent's children[]
1608 * (or root_hub) pointer. 1680 * (or root_hub) pointer.
1609 */ 1681 */
1610 release_address(udev); 1682 release_devnum(udev);
1611 1683
1612 /* Avoid races with recursively_mark_NOTATTACHED() */ 1684 /* Avoid races with recursively_mark_NOTATTACHED() */
1613 spin_lock_irq(&device_state_lock); 1685 spin_lock_irq(&device_state_lock);
@@ -1801,8 +1873,15 @@ int usb_new_device(struct usb_device *udev)
1801 1873
1802 /* Tell the runtime-PM framework the device is active */ 1874 /* Tell the runtime-PM framework the device is active */
1803 pm_runtime_set_active(&udev->dev); 1875 pm_runtime_set_active(&udev->dev);
1876 pm_runtime_get_noresume(&udev->dev);
1877 pm_runtime_use_autosuspend(&udev->dev);
1804 pm_runtime_enable(&udev->dev); 1878 pm_runtime_enable(&udev->dev);
1805 1879
1880 /* By default, forbid autosuspend for all devices. It will be
1881 * allowed for hubs during binding.
1882 */
1883 usb_disable_autosuspend(udev);
1884
1806 err = usb_enumerate_device(udev); /* Read descriptors */ 1885 err = usb_enumerate_device(udev); /* Read descriptors */
1807 if (err < 0) 1886 if (err < 0)
1808 goto fail; 1887 goto fail;
@@ -1828,6 +1907,8 @@ int usb_new_device(struct usb_device *udev)
1828 } 1907 }
1829 1908
1830 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); 1909 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev);
1910 usb_mark_last_busy(udev);
1911 pm_runtime_put_sync_autosuspend(&udev->dev);
1831 return err; 1912 return err;
1832 1913
1833fail: 1914fail:
@@ -1983,7 +2064,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
1983 (portstatus & USB_PORT_STAT_ENABLE)) { 2064 (portstatus & USB_PORT_STAT_ENABLE)) {
1984 if (hub_is_wusb(hub)) 2065 if (hub_is_wusb(hub))
1985 udev->speed = USB_SPEED_WIRELESS; 2066 udev->speed = USB_SPEED_WIRELESS;
1986 else if (portstatus & USB_PORT_STAT_SUPER_SPEED) 2067 else if (hub_is_superspeed(hub->hdev))
1987 udev->speed = USB_SPEED_SUPER; 2068 udev->speed = USB_SPEED_SUPER;
1988 else if (portstatus & USB_PORT_STAT_HIGH_SPEED) 2069 else if (portstatus & USB_PORT_STAT_HIGH_SPEED)
1989 udev->speed = USB_SPEED_HIGH; 2070 udev->speed = USB_SPEED_HIGH;
@@ -2039,7 +2120,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
2039 case 0: 2120 case 0:
2040 /* TRSTRCY = 10 ms; plus some extra */ 2121 /* TRSTRCY = 10 ms; plus some extra */
2041 msleep(10 + 40); 2122 msleep(10 + 40);
2042 update_address(udev, 0); 2123 update_devnum(udev, 0);
2043 if (hcd->driver->reset_device) { 2124 if (hcd->driver->reset_device) {
2044 status = hcd->driver->reset_device(hcd, udev); 2125 status = hcd->driver->reset_device(hcd, udev);
2045 if (status < 0) { 2126 if (status < 0) {
@@ -2075,11 +2156,76 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
2075 return status; 2156 return status;
2076} 2157}
2077 2158
2159/* Warm reset a USB3 protocol port */
2160static int hub_port_warm_reset(struct usb_hub *hub, int port)
2161{
2162 int ret;
2163 u16 portstatus, portchange;
2164
2165 if (!hub_is_superspeed(hub->hdev)) {
2166 dev_err(hub->intfdev, "only USB3 hub support warm reset\n");
2167 return -EINVAL;
2168 }
2169
2170 /* Warm reset the port */
2171 ret = set_port_feature(hub->hdev,
2172 port, USB_PORT_FEAT_BH_PORT_RESET);
2173 if (ret) {
2174 dev_err(hub->intfdev, "cannot warm reset port %d\n", port);
2175 return ret;
2176 }
2177
2178 msleep(20);
2179 ret = hub_port_status(hub, port, &portstatus, &portchange);
2180
2181 if (portchange & USB_PORT_STAT_C_RESET)
2182 clear_port_feature(hub->hdev, port, USB_PORT_FEAT_C_RESET);
2183
2184 if (portchange & USB_PORT_STAT_C_BH_RESET)
2185 clear_port_feature(hub->hdev, port,
2186 USB_PORT_FEAT_C_BH_PORT_RESET);
2187
2188 if (portchange & USB_PORT_STAT_C_LINK_STATE)
2189 clear_port_feature(hub->hdev, port,
2190 USB_PORT_FEAT_C_PORT_LINK_STATE);
2191
2192 return ret;
2193}
2194
2195/* Check if a port is power on */
2196static int port_is_power_on(struct usb_hub *hub, unsigned portstatus)
2197{
2198 int ret = 0;
2199
2200 if (hub_is_superspeed(hub->hdev)) {
2201 if (portstatus & USB_SS_PORT_STAT_POWER)
2202 ret = 1;
2203 } else {
2204 if (portstatus & USB_PORT_STAT_POWER)
2205 ret = 1;
2206 }
2207
2208 return ret;
2209}
2210
2078#ifdef CONFIG_PM 2211#ifdef CONFIG_PM
2079 2212
2080#define MASK_BITS (USB_PORT_STAT_POWER | USB_PORT_STAT_CONNECTION | \ 2213/* Check if a port is suspended(USB2.0 port) or in U3 state(USB3.0 port) */
2081 USB_PORT_STAT_SUSPEND) 2214static int port_is_suspended(struct usb_hub *hub, unsigned portstatus)
2082#define WANT_BITS (USB_PORT_STAT_POWER | USB_PORT_STAT_CONNECTION) 2215{
2216 int ret = 0;
2217
2218 if (hub_is_superspeed(hub->hdev)) {
2219 if ((portstatus & USB_PORT_STAT_LINK_STATE)
2220 == USB_SS_PORT_LS_U3)
2221 ret = 1;
2222 } else {
2223 if (portstatus & USB_PORT_STAT_SUSPEND)
2224 ret = 1;
2225 }
2226
2227 return ret;
2228}
2083 2229
2084/* Determine whether the device on a port is ready for a normal resume, 2230/* Determine whether the device on a port is ready for a normal resume,
2085 * is ready for a reset-resume, or should be disconnected. 2231 * is ready for a reset-resume, or should be disconnected.
@@ -2089,7 +2235,9 @@ static int check_port_resume_type(struct usb_device *udev,
2089 int status, unsigned portchange, unsigned portstatus) 2235 int status, unsigned portchange, unsigned portstatus)
2090{ 2236{
2091 /* Is the device still present? */ 2237 /* Is the device still present? */
2092 if (status || (portstatus & MASK_BITS) != WANT_BITS) { 2238 if (status || port_is_suspended(hub, portstatus) ||
2239 !port_is_power_on(hub, portstatus) ||
2240 !(portstatus & USB_PORT_STAT_CONNECTION)) {
2093 if (status >= 0) 2241 if (status >= 0)
2094 status = -ENODEV; 2242 status = -ENODEV;
2095 } 2243 }
@@ -2200,7 +2348,13 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2200 } 2348 }
2201 2349
2202 /* see 7.1.7.6 */ 2350 /* see 7.1.7.6 */
2203 status = set_port_feature(hub->hdev, port1, USB_PORT_FEAT_SUSPEND); 2351 if (hub_is_superspeed(hub->hdev))
2352 status = set_port_feature(hub->hdev,
2353 port1 | (USB_SS_PORT_LS_U3 << 3),
2354 USB_PORT_FEAT_LINK_STATE);
2355 else
2356 status = set_port_feature(hub->hdev, port1,
2357 USB_PORT_FEAT_SUSPEND);
2204 if (status) { 2358 if (status) {
2205 dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", 2359 dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n",
2206 port1, status); 2360 port1, status);
@@ -2211,6 +2365,10 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2211 USB_DEVICE_REMOTE_WAKEUP, 0, 2365 USB_DEVICE_REMOTE_WAKEUP, 0,
2212 NULL, 0, 2366 NULL, 0,
2213 USB_CTRL_SET_TIMEOUT); 2367 USB_CTRL_SET_TIMEOUT);
2368
2369 /* System sleep transitions should never fail */
2370 if (!(msg.event & PM_EVENT_AUTO))
2371 status = 0;
2214 } else { 2372 } else {
2215 /* device has up to 10 msec to fully suspend */ 2373 /* device has up to 10 msec to fully suspend */
2216 dev_dbg(&udev->dev, "usb %ssuspend\n", 2374 dev_dbg(&udev->dev, "usb %ssuspend\n",
@@ -2218,6 +2376,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2218 usb_set_device_state(udev, USB_STATE_SUSPENDED); 2376 usb_set_device_state(udev, USB_STATE_SUSPENDED);
2219 msleep(10); 2377 msleep(10);
2220 } 2378 }
2379 usb_mark_last_busy(hub->hdev);
2221 return status; 2380 return status;
2222} 2381}
2223 2382
@@ -2343,7 +2502,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
2343 2502
2344 /* Skip the initial Clear-Suspend step for a remote wakeup */ 2503 /* Skip the initial Clear-Suspend step for a remote wakeup */
2345 status = hub_port_status(hub, port1, &portstatus, &portchange); 2504 status = hub_port_status(hub, port1, &portstatus, &portchange);
2346 if (status == 0 && !(portstatus & USB_PORT_STAT_SUSPEND)) 2505 if (status == 0 && !port_is_suspended(hub, portstatus))
2347 goto SuspendCleared; 2506 goto SuspendCleared;
2348 2507
2349 // dev_dbg(hub->intfdev, "resume port %d\n", port1); 2508 // dev_dbg(hub->intfdev, "resume port %d\n", port1);
@@ -2351,8 +2510,13 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
2351 set_bit(port1, hub->busy_bits); 2510 set_bit(port1, hub->busy_bits);
2352 2511
2353 /* see 7.1.7.7; affects power usage, but not budgeting */ 2512 /* see 7.1.7.7; affects power usage, but not budgeting */
2354 status = clear_port_feature(hub->hdev, 2513 if (hub_is_superspeed(hub->hdev))
2355 port1, USB_PORT_FEAT_SUSPEND); 2514 status = set_port_feature(hub->hdev,
2515 port1 | (USB_SS_PORT_LS_U0 << 3),
2516 USB_PORT_FEAT_LINK_STATE);
2517 else
2518 status = clear_port_feature(hub->hdev,
2519 port1, USB_PORT_FEAT_SUSPEND);
2356 if (status) { 2520 if (status) {
2357 dev_dbg(hub->intfdev, "can't resume port %d, status %d\n", 2521 dev_dbg(hub->intfdev, "can't resume port %d, status %d\n",
2358 port1, status); 2522 port1, status);
@@ -2374,9 +2538,15 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
2374 2538
2375 SuspendCleared: 2539 SuspendCleared:
2376 if (status == 0) { 2540 if (status == 0) {
2377 if (portchange & USB_PORT_STAT_C_SUSPEND) 2541 if (hub_is_superspeed(hub->hdev)) {
2378 clear_port_feature(hub->hdev, port1, 2542 if (portchange & USB_PORT_STAT_C_LINK_STATE)
2379 USB_PORT_FEAT_C_SUSPEND); 2543 clear_port_feature(hub->hdev, port1,
2544 USB_PORT_FEAT_C_PORT_LINK_STATE);
2545 } else {
2546 if (portchange & USB_PORT_STAT_C_SUSPEND)
2547 clear_port_feature(hub->hdev, port1,
2548 USB_PORT_FEAT_C_SUSPEND);
2549 }
2380 } 2550 }
2381 2551
2382 clear_bit(port1, hub->busy_bits); 2552 clear_bit(port1, hub->busy_bits);
@@ -2448,16 +2618,15 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
2448 struct usb_device *hdev = hub->hdev; 2618 struct usb_device *hdev = hub->hdev;
2449 unsigned port1; 2619 unsigned port1;
2450 2620
2451 /* fail if children aren't already suspended */ 2621 /* Warn if children aren't already suspended */
2452 for (port1 = 1; port1 <= hdev->maxchild; port1++) { 2622 for (port1 = 1; port1 <= hdev->maxchild; port1++) {
2453 struct usb_device *udev; 2623 struct usb_device *udev;
2454 2624
2455 udev = hdev->children [port1-1]; 2625 udev = hdev->children [port1-1];
2456 if (udev && udev->can_submit) { 2626 if (udev && udev->can_submit) {
2457 if (!(msg.event & PM_EVENT_AUTO)) 2627 dev_warn(&intf->dev, "port %d nyet suspended\n", port1);
2458 dev_dbg(&intf->dev, "port %d nyet suspended\n", 2628 if (msg.event & PM_EVENT_AUTO)
2459 port1); 2629 return -EBUSY;
2460 return -EBUSY;
2461 } 2630 }
2462 } 2631 }
2463 2632
@@ -2594,16 +2763,14 @@ static int hub_set_address(struct usb_device *udev, int devnum)
2594 return 0; 2763 return 0;
2595 if (udev->state != USB_STATE_DEFAULT) 2764 if (udev->state != USB_STATE_DEFAULT)
2596 return -EINVAL; 2765 return -EINVAL;
2597 if (hcd->driver->address_device) { 2766 if (hcd->driver->address_device)
2598 retval = hcd->driver->address_device(hcd, udev); 2767 retval = hcd->driver->address_device(hcd, udev);
2599 } else { 2768 else
2600 retval = usb_control_msg(udev, usb_sndaddr0pipe(), 2769 retval = usb_control_msg(udev, usb_sndaddr0pipe(),
2601 USB_REQ_SET_ADDRESS, 0, devnum, 0, 2770 USB_REQ_SET_ADDRESS, 0, devnum, 0,
2602 NULL, 0, USB_CTRL_SET_TIMEOUT); 2771 NULL, 0, USB_CTRL_SET_TIMEOUT);
2603 if (retval == 0)
2604 update_address(udev, devnum);
2605 }
2606 if (retval == 0) { 2772 if (retval == 0) {
2773 update_devnum(udev, devnum);
2607 /* Device now using proper address. */ 2774 /* Device now using proper address. */
2608 usb_set_device_state(udev, USB_STATE_ADDRESS); 2775 usb_set_device_state(udev, USB_STATE_ADDRESS);
2609 usb_ep0_reinit(udev); 2776 usb_ep0_reinit(udev);
@@ -2650,17 +2817,13 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2650 2817
2651 mutex_lock(&usb_address0_mutex); 2818 mutex_lock(&usb_address0_mutex);
2652 2819
2653 if (!udev->config && oldspeed == USB_SPEED_SUPER) { 2820 /* Reset the device; full speed may morph to high speed */
2654 /* Don't reset USB 3.0 devices during an initial setup */ 2821 /* FIXME a USB 2.0 device may morph into SuperSpeed on reset. */
2655 usb_set_device_state(udev, USB_STATE_DEFAULT); 2822 retval = hub_port_reset(hub, port1, udev, delay);
2656 } else { 2823 if (retval < 0) /* error or disconnect */
2657 /* Reset the device; full speed may morph to high speed */ 2824 goto fail;
2658 /* FIXME a USB 2.0 device may morph into SuperSpeed on reset. */ 2825 /* success, speed is known */
2659 retval = hub_port_reset(hub, port1, udev, delay); 2826
2660 if (retval < 0) /* error or disconnect */
2661 goto fail;
2662 /* success, speed is known */
2663 }
2664 retval = -ENODEV; 2827 retval = -ENODEV;
2665 2828
2666 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed) { 2829 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed) {
@@ -2712,9 +2875,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2712 } 2875 }
2713 if (udev->speed != USB_SPEED_SUPER) 2876 if (udev->speed != USB_SPEED_SUPER)
2714 dev_info(&udev->dev, 2877 dev_info(&udev->dev,
2715 "%s %s speed %sUSB device using %s and address %d\n", 2878 "%s %s speed %sUSB device number %d using %s\n",
2716 (udev->config) ? "reset" : "new", speed, type, 2879 (udev->config) ? "reset" : "new", speed, type,
2717 udev->bus->controller->driver->name, devnum); 2880 devnum, udev->bus->controller->driver->name);
2718 2881
2719 /* Set up TT records, if needed */ 2882 /* Set up TT records, if needed */
2720 if (hdev->tt) { 2883 if (hdev->tt) {
@@ -2722,6 +2885,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2722 udev->ttport = hdev->ttport; 2885 udev->ttport = hdev->ttport;
2723 } else if (udev->speed != USB_SPEED_HIGH 2886 } else if (udev->speed != USB_SPEED_HIGH
2724 && hdev->speed == USB_SPEED_HIGH) { 2887 && hdev->speed == USB_SPEED_HIGH) {
2888 if (!hub->tt.hub) {
2889 dev_err(&udev->dev, "parent hub has no TT\n");
2890 retval = -EINVAL;
2891 goto fail;
2892 }
2725 udev->tt = &hub->tt; 2893 udev->tt = &hub->tt;
2726 udev->ttport = port1; 2894 udev->ttport = port1;
2727 } 2895 }
@@ -2739,10 +2907,6 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2739 * value. 2907 * value.
2740 */ 2908 */
2741 for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { 2909 for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) {
2742 /*
2743 * An xHCI controller cannot send any packets to a device until
2744 * a set address command successfully completes.
2745 */
2746 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { 2910 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) {
2747 struct usb_device_descriptor *buf; 2911 struct usb_device_descriptor *buf;
2748 int r = 0; 2912 int r = 0;
@@ -2825,9 +2989,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2825 if (udev->speed == USB_SPEED_SUPER) { 2989 if (udev->speed == USB_SPEED_SUPER) {
2826 devnum = udev->devnum; 2990 devnum = udev->devnum;
2827 dev_info(&udev->dev, 2991 dev_info(&udev->dev,
2828 "%s SuperSpeed USB device using %s and address %d\n", 2992 "%s SuperSpeed USB device number %d using %s\n",
2829 (udev->config) ? "reset" : "new", 2993 (udev->config) ? "reset" : "new",
2830 udev->bus->controller->driver->name, devnum); 2994 devnum, udev->bus->controller->driver->name);
2831 } 2995 }
2832 2996
2833 /* cope with hardware quirkiness: 2997 /* cope with hardware quirkiness:
@@ -2860,13 +3024,16 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2860 else 3024 else
2861 i = udev->descriptor.bMaxPacketSize0; 3025 i = udev->descriptor.bMaxPacketSize0;
2862 if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { 3026 if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) {
2863 if (udev->speed != USB_SPEED_FULL || 3027 if (udev->speed == USB_SPEED_LOW ||
2864 !(i == 8 || i == 16 || i == 32 || i == 64)) { 3028 !(i == 8 || i == 16 || i == 32 || i == 64)) {
2865 dev_err(&udev->dev, "ep0 maxpacket = %d\n", i); 3029 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i);
2866 retval = -EMSGSIZE; 3030 retval = -EMSGSIZE;
2867 goto fail; 3031 goto fail;
2868 } 3032 }
2869 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); 3033 if (udev->speed == USB_SPEED_FULL)
3034 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i);
3035 else
3036 dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i);
2870 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); 3037 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i);
2871 usb_ep0_reinit(udev); 3038 usb_ep0_reinit(udev);
2872 } 3039 }
@@ -2887,7 +3054,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2887fail: 3054fail:
2888 if (retval) { 3055 if (retval) {
2889 hub_port_disable(hub, port1, 0); 3056 hub_port_disable(hub, port1, 0);
2890 update_address(udev, devnum); /* for disconnect processing */ 3057 update_devnum(udev, devnum); /* for disconnect processing */
2891 } 3058 }
2892 mutex_unlock(&usb_address0_mutex); 3059 mutex_unlock(&usb_address0_mutex);
2893 return retval; 3060 return retval;
@@ -2978,7 +3145,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2978 3145
2979 dev_dbg (hub_dev, 3146 dev_dbg (hub_dev,
2980 "port %d, status %04x, change %04x, %s\n", 3147 "port %d, status %04x, change %04x, %s\n",
2981 port1, portstatus, portchange, portspeed (portstatus)); 3148 port1, portstatus, portchange, portspeed(hub, portstatus));
2982 3149
2983 if (hub->has_indicators) { 3150 if (hub->has_indicators) {
2984 set_port_led(hub, port1, HUB_LED_AUTO); 3151 set_port_led(hub, port1, HUB_LED_AUTO);
@@ -3053,7 +3220,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
3053 3220
3054 /* maybe switch power back on (e.g. root hub was reset) */ 3221 /* maybe switch power back on (e.g. root hub was reset) */
3055 if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2 3222 if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2
3056 && !(portstatus & USB_PORT_STAT_POWER)) 3223 && !port_is_power_on(hub, portstatus))
3057 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); 3224 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
3058 3225
3059 if (portstatus & USB_PORT_STAT_ENABLE) 3226 if (portstatus & USB_PORT_STAT_ENABLE)
@@ -3079,34 +3246,16 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
3079 udev->level = hdev->level + 1; 3246 udev->level = hdev->level + 1;
3080 udev->wusb = hub_is_wusb(hub); 3247 udev->wusb = hub_is_wusb(hub);
3081 3248
3082 /* 3249 /* Only USB 3.0 devices are connected to SuperSpeed hubs. */
3083 * USB 3.0 devices are reset automatically before the connect 3250 if (hub_is_superspeed(hub->hdev))
3084 * port status change appears, and the root hub port status
3085 * shows the correct speed. We also get port change
3086 * notifications for USB 3.0 devices from the USB 3.0 portion of
3087 * an external USB 3.0 hub, but this isn't handled correctly yet
3088 * FIXME.
3089 */
3090
3091 if (!(hcd->driver->flags & HCD_USB3))
3092 udev->speed = USB_SPEED_UNKNOWN;
3093 else if ((hdev->parent == NULL) &&
3094 (portstatus & USB_PORT_STAT_SUPER_SPEED))
3095 udev->speed = USB_SPEED_SUPER; 3251 udev->speed = USB_SPEED_SUPER;
3096 else 3252 else
3097 udev->speed = USB_SPEED_UNKNOWN; 3253 udev->speed = USB_SPEED_UNKNOWN;
3098 3254
3099 /* 3255 choose_devnum(udev);
3100 * xHCI needs to issue an address device command later 3256 if (udev->devnum <= 0) {
3101 * in the hub_port_init sequence for SS/HS/FS/LS devices. 3257 status = -ENOTCONN; /* Don't retry */
3102 */ 3258 goto loop;
3103 if (!(hcd->driver->flags & HCD_USB3)) {
3104 /* set the address */
3105 choose_address(udev);
3106 if (udev->devnum <= 0) {
3107 status = -ENOTCONN; /* Don't retry */
3108 goto loop;
3109 }
3110 } 3259 }
3111 3260
3112 /* reset (non-USB 3.0 devices) and get descriptor */ 3261 /* reset (non-USB 3.0 devices) and get descriptor */
@@ -3195,7 +3344,7 @@ loop_disable:
3195 hub_port_disable(hub, port1, 1); 3344 hub_port_disable(hub, port1, 1);
3196loop: 3345loop:
3197 usb_ep0_reinit(udev); 3346 usb_ep0_reinit(udev);
3198 release_address(udev); 3347 release_devnum(udev);
3199 hub_free_dev(udev); 3348 hub_free_dev(udev);
3200 usb_put_dev(udev); 3349 usb_put_dev(udev);
3201 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) 3350 if ((status == -ENOTCONN) || (status == -ENOTSUPP))
@@ -3372,12 +3521,19 @@ static void hub_events(void)
3372 } 3521 }
3373 3522
3374 if (portchange & USB_PORT_STAT_C_OVERCURRENT) { 3523 if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
3375 dev_err (hub_dev, 3524 u16 status = 0;
3376 "over-current change on port %d\n", 3525 u16 unused;
3377 i); 3526
3527 dev_dbg(hub_dev, "over-current change on port "
3528 "%d\n", i);
3378 clear_port_feature(hdev, i, 3529 clear_port_feature(hdev, i,
3379 USB_PORT_FEAT_C_OVER_CURRENT); 3530 USB_PORT_FEAT_C_OVER_CURRENT);
3531 msleep(100); /* Cool down */
3380 hub_power_on(hub, true); 3532 hub_power_on(hub, true);
3533 hub_port_status(hub, i, &status, &unused);
3534 if (status & USB_PORT_STAT_OVERCURRENT)
3535 dev_err(hub_dev, "over-current "
3536 "condition on port %d\n", i);
3381 } 3537 }
3382 3538
3383 if (portchange & USB_PORT_STAT_C_RESET) { 3539 if (portchange & USB_PORT_STAT_C_RESET) {
@@ -3387,6 +3543,35 @@ static void hub_events(void)
3387 clear_port_feature(hdev, i, 3543 clear_port_feature(hdev, i,
3388 USB_PORT_FEAT_C_RESET); 3544 USB_PORT_FEAT_C_RESET);
3389 } 3545 }
3546 if ((portchange & USB_PORT_STAT_C_BH_RESET) &&
3547 hub_is_superspeed(hub->hdev)) {
3548 dev_dbg(hub_dev,
3549 "warm reset change on port %d\n",
3550 i);
3551 clear_port_feature(hdev, i,
3552 USB_PORT_FEAT_C_BH_PORT_RESET);
3553 }
3554 if (portchange & USB_PORT_STAT_C_LINK_STATE) {
3555 clear_port_feature(hub->hdev, i,
3556 USB_PORT_FEAT_C_PORT_LINK_STATE);
3557 }
3558 if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) {
3559 dev_warn(hub_dev,
3560 "config error on port %d\n",
3561 i);
3562 clear_port_feature(hub->hdev, i,
3563 USB_PORT_FEAT_C_PORT_CONFIG_ERROR);
3564 }
3565
3566 /* Warm reset a USB3 protocol port if it's in
3567 * SS.Inactive state.
3568 */
3569 if (hub_is_superspeed(hub->hdev) &&
3570 (portstatus & USB_PORT_STAT_LINK_STATE)
3571 == USB_SS_PORT_LS_SS_INACTIVE) {
3572 dev_dbg(hub_dev, "warm reset port %d\n", i);
3573 hub_port_warm_reset(hub, i);
3574 }
3390 3575
3391 if (connect_change) 3576 if (connect_change)
3392 hub_port_connect_change(hub, i, 3577 hub_port_connect_change(hub, i,
@@ -3409,10 +3594,17 @@ static void hub_events(void)
3409 hub->limited_power = 0; 3594 hub->limited_power = 0;
3410 } 3595 }
3411 if (hubchange & HUB_CHANGE_OVERCURRENT) { 3596 if (hubchange & HUB_CHANGE_OVERCURRENT) {
3412 dev_dbg (hub_dev, "overcurrent change\n"); 3597 u16 status = 0;
3413 msleep(500); /* Cool down */ 3598 u16 unused;
3599
3600 dev_dbg(hub_dev, "over-current change\n");
3414 clear_hub_feature(hdev, C_HUB_OVER_CURRENT); 3601 clear_hub_feature(hdev, C_HUB_OVER_CURRENT);
3602 msleep(500); /* Cool down */
3415 hub_power_on(hub, true); 3603 hub_power_on(hub, true);
3604 hub_hub_status(hub, &status, &unused);
3605 if (status & HUB_STATUS_OVERCURRENT)
3606 dev_err(hub_dev, "over-current "
3607 "condition\n");
3416 } 3608 }
3417 } 3609 }
3418 3610
@@ -3629,7 +3821,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3629 } 3821 }
3630 3822
3631 if (!parent_hdev) { 3823 if (!parent_hdev) {
3632 /* this requires hcd-specific logic; see OHCI hc_restart() */ 3824 /* this requires hcd-specific logic; see ohci_restart() */
3633 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); 3825 dev_dbg(&udev->dev, "%s for root hub!\n", __func__);
3634 return -EISDIR; 3826 return -EISDIR;
3635 } 3827 }
@@ -3661,13 +3853,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3661 if (!udev->actconfig) 3853 if (!udev->actconfig)
3662 goto done; 3854 goto done;
3663 3855
3664 mutex_lock(&hcd->bandwidth_mutex); 3856 mutex_lock(hcd->bandwidth_mutex);
3665 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); 3857 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL);
3666 if (ret < 0) { 3858 if (ret < 0) {
3667 dev_warn(&udev->dev, 3859 dev_warn(&udev->dev,
3668 "Busted HC? Not enough HCD resources for " 3860 "Busted HC? Not enough HCD resources for "
3669 "old configuration.\n"); 3861 "old configuration.\n");
3670 mutex_unlock(&hcd->bandwidth_mutex); 3862 mutex_unlock(hcd->bandwidth_mutex);
3671 goto re_enumerate; 3863 goto re_enumerate;
3672 } 3864 }
3673 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 3865 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -3678,10 +3870,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3678 dev_err(&udev->dev, 3870 dev_err(&udev->dev,
3679 "can't restore configuration #%d (error=%d)\n", 3871 "can't restore configuration #%d (error=%d)\n",
3680 udev->actconfig->desc.bConfigurationValue, ret); 3872 udev->actconfig->desc.bConfigurationValue, ret);
3681 mutex_unlock(&hcd->bandwidth_mutex); 3873 mutex_unlock(hcd->bandwidth_mutex);
3682 goto re_enumerate; 3874 goto re_enumerate;
3683 } 3875 }
3684 mutex_unlock(&hcd->bandwidth_mutex); 3876 mutex_unlock(hcd->bandwidth_mutex);
3685 usb_set_device_state(udev, USB_STATE_CONFIGURED); 3877 usb_set_device_state(udev, USB_STATE_CONFIGURED);
3686 3878
3687 /* Put interfaces back into the same altsettings as before. 3879 /* Put interfaces back into the same altsettings as before.
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 095fa5366690..2278dad886e2 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -39,7 +39,6 @@
39#include <linux/parser.h> 39#include <linux/parser.h>
40#include <linux/notifier.h> 40#include <linux/notifier.h>
41#include <linux/seq_file.h> 41#include <linux/seq_file.h>
42#include <linux/smp_lock.h>
43#include <linux/usb/hcd.h> 42#include <linux/usb/hcd.h>
44#include <asm/byteorder.h> 43#include <asm/byteorder.h>
45#include "usb.h" 44#include "usb.h"
@@ -276,6 +275,7 @@ static struct inode *usbfs_get_inode (struct super_block *sb, int mode, dev_t de
276 struct inode *inode = new_inode(sb); 275 struct inode *inode = new_inode(sb);
277 276
278 if (inode) { 277 if (inode) {
278 inode->i_ino = get_next_ino();
279 inode->i_mode = mode; 279 inode->i_mode = mode;
280 inode->i_uid = current_fsuid(); 280 inode->i_uid = current_fsuid();
281 inode->i_gid = current_fsgid(); 281 inode->i_gid = current_fsgid();
@@ -343,17 +343,19 @@ static int usbfs_empty (struct dentry *dentry)
343{ 343{
344 struct list_head *list; 344 struct list_head *list;
345 345
346 spin_lock(&dcache_lock); 346 spin_lock(&dentry->d_lock);
347
348 list_for_each(list, &dentry->d_subdirs) { 347 list_for_each(list, &dentry->d_subdirs) {
349 struct dentry *de = list_entry(list, struct dentry, d_u.d_child); 348 struct dentry *de = list_entry(list, struct dentry, d_u.d_child);
349
350 spin_lock_nested(&de->d_lock, DENTRY_D_LOCK_NESTED);
350 if (usbfs_positive(de)) { 351 if (usbfs_positive(de)) {
351 spin_unlock(&dcache_lock); 352 spin_unlock(&de->d_lock);
353 spin_unlock(&dentry->d_lock);
352 return 0; 354 return 0;
353 } 355 }
356 spin_unlock(&de->d_lock);
354 } 357 }
355 358 spin_unlock(&dentry->d_lock);
356 spin_unlock(&dcache_lock);
357 return 1; 359 return 1;
358} 360}
359 361
@@ -387,7 +389,6 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry)
387 mutex_unlock(&inode->i_mutex); 389 mutex_unlock(&inode->i_mutex);
388 if (!error) 390 if (!error)
389 d_delete(dentry); 391 d_delete(dentry);
390 dput(dentry);
391 return error; 392 return error;
392} 393}
393 394
@@ -573,16 +574,16 @@ static void fs_remove_file (struct dentry *dentry)
573 574
574/* --------------------------------------------------------------------- */ 575/* --------------------------------------------------------------------- */
575 576
576static int usb_get_sb(struct file_system_type *fs_type, 577static struct dentry *usb_mount(struct file_system_type *fs_type,
577 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 578 int flags, const char *dev_name, void *data)
578{ 579{
579 return get_sb_single(fs_type, flags, data, usbfs_fill_super, mnt); 580 return mount_single(fs_type, flags, data, usbfs_fill_super);
580} 581}
581 582
582static struct file_system_type usb_fs_type = { 583static struct file_system_type usb_fs_type = {
583 .owner = THIS_MODULE, 584 .owner = THIS_MODULE,
584 .name = "usbfs", 585 .name = "usbfs",
585 .get_sb = usb_get_sb, 586 .mount = usb_mount,
586 .kill_sb = kill_litter_super, 587 .kill_sb = kill_litter_super,
587}; 588};
588 589
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 9f0ce7de0e36..0b5ec234c787 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1135,22 +1135,26 @@ void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf,
1135 * Deallocates hcd/hardware state for the endpoints (nuking all or most 1135 * Deallocates hcd/hardware state for the endpoints (nuking all or most
1136 * pending urbs) and usbcore state for the interfaces, so that usbcore 1136 * pending urbs) and usbcore state for the interfaces, so that usbcore
1137 * must usb_set_configuration() before any interfaces could be used. 1137 * must usb_set_configuration() before any interfaces could be used.
1138 *
1139 * Must be called with hcd->bandwidth_mutex held.
1138 */ 1140 */
1139void usb_disable_device(struct usb_device *dev, int skip_ep0) 1141void usb_disable_device(struct usb_device *dev, int skip_ep0)
1140{ 1142{
1141 int i; 1143 int i;
1142 1144 struct usb_hcd *hcd = bus_to_hcd(dev->bus);
1143 dev_dbg(&dev->dev, "%s nuking %s URBs\n", __func__,
1144 skip_ep0 ? "non-ep0" : "all");
1145 for (i = skip_ep0; i < 16; ++i) {
1146 usb_disable_endpoint(dev, i, true);
1147 usb_disable_endpoint(dev, i + USB_DIR_IN, true);
1148 }
1149 1145
1150 /* getting rid of interfaces will disconnect 1146 /* getting rid of interfaces will disconnect
1151 * any drivers bound to them (a key side effect) 1147 * any drivers bound to them (a key side effect)
1152 */ 1148 */
1153 if (dev->actconfig) { 1149 if (dev->actconfig) {
1150 /*
1151 * FIXME: In order to avoid self-deadlock involving the
1152 * bandwidth_mutex, we have to mark all the interfaces
1153 * before unregistering any of them.
1154 */
1155 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
1156 dev->actconfig->interface[i]->unregistering = 1;
1157
1154 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { 1158 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
1155 struct usb_interface *interface; 1159 struct usb_interface *interface;
1156 1160
@@ -1160,7 +1164,6 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1160 continue; 1164 continue;
1161 dev_dbg(&dev->dev, "unregistering interface %s\n", 1165 dev_dbg(&dev->dev, "unregistering interface %s\n",
1162 dev_name(&interface->dev)); 1166 dev_name(&interface->dev));
1163 interface->unregistering = 1;
1164 remove_intf_ep_devs(interface); 1167 remove_intf_ep_devs(interface);
1165 device_del(&interface->dev); 1168 device_del(&interface->dev);
1166 } 1169 }
@@ -1176,6 +1179,23 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1176 if (dev->state == USB_STATE_CONFIGURED) 1179 if (dev->state == USB_STATE_CONFIGURED)
1177 usb_set_device_state(dev, USB_STATE_ADDRESS); 1180 usb_set_device_state(dev, USB_STATE_ADDRESS);
1178 } 1181 }
1182
1183 dev_dbg(&dev->dev, "%s nuking %s URBs\n", __func__,
1184 skip_ep0 ? "non-ep0" : "all");
1185 if (hcd->driver->check_bandwidth) {
1186 /* First pass: Cancel URBs, leave endpoint pointers intact. */
1187 for (i = skip_ep0; i < 16; ++i) {
1188 usb_disable_endpoint(dev, i, false);
1189 usb_disable_endpoint(dev, i + USB_DIR_IN, false);
1190 }
1191 /* Remove endpoints from the host controller internal state */
1192 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
1193 /* Second pass: remove endpoint pointers */
1194 }
1195 for (i = skip_ep0; i < 16; ++i) {
1196 usb_disable_endpoint(dev, i, true);
1197 usb_disable_endpoint(dev, i + USB_DIR_IN, true);
1198 }
1179} 1199}
1180 1200
1181/** 1201/**
@@ -1273,6 +1293,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1273 interface); 1293 interface);
1274 return -EINVAL; 1294 return -EINVAL;
1275 } 1295 }
1296 if (iface->unregistering)
1297 return -ENODEV;
1276 1298
1277 alt = usb_altnum_to_altsetting(iface, alternate); 1299 alt = usb_altnum_to_altsetting(iface, alternate);
1278 if (!alt) { 1300 if (!alt) {
@@ -1284,12 +1306,12 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1284 /* Make sure we have enough bandwidth for this alternate interface. 1306 /* Make sure we have enough bandwidth for this alternate interface.
1285 * Remove the current alt setting and add the new alt setting. 1307 * Remove the current alt setting and add the new alt setting.
1286 */ 1308 */
1287 mutex_lock(&hcd->bandwidth_mutex); 1309 mutex_lock(hcd->bandwidth_mutex);
1288 ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); 1310 ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt);
1289 if (ret < 0) { 1311 if (ret < 0) {
1290 dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", 1312 dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n",
1291 alternate); 1313 alternate);
1292 mutex_unlock(&hcd->bandwidth_mutex); 1314 mutex_unlock(hcd->bandwidth_mutex);
1293 return ret; 1315 return ret;
1294 } 1316 }
1295 1317
@@ -1311,10 +1333,10 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1311 } else if (ret < 0) { 1333 } else if (ret < 0) {
1312 /* Re-instate the old alt setting */ 1334 /* Re-instate the old alt setting */
1313 usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); 1335 usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting);
1314 mutex_unlock(&hcd->bandwidth_mutex); 1336 mutex_unlock(hcd->bandwidth_mutex);
1315 return ret; 1337 return ret;
1316 } 1338 }
1317 mutex_unlock(&hcd->bandwidth_mutex); 1339 mutex_unlock(hcd->bandwidth_mutex);
1318 1340
1319 /* FIXME drivers shouldn't need to replicate/bugfix the logic here 1341 /* FIXME drivers shouldn't need to replicate/bugfix the logic here
1320 * when they implement async or easily-killable versions of this or 1342 * when they implement async or easily-killable versions of this or
@@ -1413,7 +1435,7 @@ int usb_reset_configuration(struct usb_device *dev)
1413 1435
1414 config = dev->actconfig; 1436 config = dev->actconfig;
1415 retval = 0; 1437 retval = 0;
1416 mutex_lock(&hcd->bandwidth_mutex); 1438 mutex_lock(hcd->bandwidth_mutex);
1417 /* Make sure we have enough bandwidth for each alternate setting 0 */ 1439 /* Make sure we have enough bandwidth for each alternate setting 0 */
1418 for (i = 0; i < config->desc.bNumInterfaces; i++) { 1440 for (i = 0; i < config->desc.bNumInterfaces; i++) {
1419 struct usb_interface *intf = config->interface[i]; 1441 struct usb_interface *intf = config->interface[i];
@@ -1442,7 +1464,7 @@ reset_old_alts:
1442 usb_hcd_alloc_bandwidth(dev, NULL, 1464 usb_hcd_alloc_bandwidth(dev, NULL,
1443 alt, intf->cur_altsetting); 1465 alt, intf->cur_altsetting);
1444 } 1466 }
1445 mutex_unlock(&hcd->bandwidth_mutex); 1467 mutex_unlock(hcd->bandwidth_mutex);
1446 return retval; 1468 return retval;
1447 } 1469 }
1448 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1470 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
@@ -1451,7 +1473,7 @@ reset_old_alts:
1451 NULL, 0, USB_CTRL_SET_TIMEOUT); 1473 NULL, 0, USB_CTRL_SET_TIMEOUT);
1452 if (retval < 0) 1474 if (retval < 0)
1453 goto reset_old_alts; 1475 goto reset_old_alts;
1454 mutex_unlock(&hcd->bandwidth_mutex); 1476 mutex_unlock(hcd->bandwidth_mutex);
1455 1477
1456 /* re-init hc/hcd interface/endpoint state */ 1478 /* re-init hc/hcd interface/endpoint state */
1457 for (i = 0; i < config->desc.bNumInterfaces; i++) { 1479 for (i = 0; i < config->desc.bNumInterfaces; i++) {
@@ -1727,6 +1749,7 @@ free_interfaces:
1727 /* if it's already configured, clear out old state first. 1749 /* if it's already configured, clear out old state first.
1728 * getting rid of old interfaces means unbinding their drivers. 1750 * getting rid of old interfaces means unbinding their drivers.
1729 */ 1751 */
1752 mutex_lock(hcd->bandwidth_mutex);
1730 if (dev->state != USB_STATE_ADDRESS) 1753 if (dev->state != USB_STATE_ADDRESS)
1731 usb_disable_device(dev, 1); /* Skip ep0 */ 1754 usb_disable_device(dev, 1); /* Skip ep0 */
1732 1755
@@ -1739,10 +1762,9 @@ free_interfaces:
1739 * host controller will not allow submissions to dropped endpoints. If 1762 * host controller will not allow submissions to dropped endpoints. If
1740 * this call fails, the device state is unchanged. 1763 * this call fails, the device state is unchanged.
1741 */ 1764 */
1742 mutex_lock(&hcd->bandwidth_mutex);
1743 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); 1765 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL);
1744 if (ret < 0) { 1766 if (ret < 0) {
1745 mutex_unlock(&hcd->bandwidth_mutex); 1767 mutex_unlock(hcd->bandwidth_mutex);
1746 usb_autosuspend_device(dev); 1768 usb_autosuspend_device(dev);
1747 goto free_interfaces; 1769 goto free_interfaces;
1748 } 1770 }
@@ -1761,11 +1783,11 @@ free_interfaces:
1761 if (!cp) { 1783 if (!cp) {
1762 usb_set_device_state(dev, USB_STATE_ADDRESS); 1784 usb_set_device_state(dev, USB_STATE_ADDRESS);
1763 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); 1785 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
1764 mutex_unlock(&hcd->bandwidth_mutex); 1786 mutex_unlock(hcd->bandwidth_mutex);
1765 usb_autosuspend_device(dev); 1787 usb_autosuspend_device(dev);
1766 goto free_interfaces; 1788 goto free_interfaces;
1767 } 1789 }
1768 mutex_unlock(&hcd->bandwidth_mutex); 1790 mutex_unlock(hcd->bandwidth_mutex);
1769 usb_set_device_state(dev, USB_STATE_CONFIGURED); 1791 usb_set_device_state(dev, USB_STATE_CONFIGURED);
1770 1792
1771 /* Initialize the new interface structures and the 1793 /* Initialize the new interface structures and the
@@ -1804,6 +1826,7 @@ free_interfaces:
1804 INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); 1826 INIT_WORK(&intf->reset_ws, __usb_queue_reset_device);
1805 intf->minor = -1; 1827 intf->minor = -1;
1806 device_initialize(&intf->dev); 1828 device_initialize(&intf->dev);
1829 pm_runtime_no_callbacks(&intf->dev);
1807 dev_set_name(&intf->dev, "%d-%s:%d.%d", 1830 dev_set_name(&intf->dev, "%d-%s:%d.%d",
1808 dev->bus->busnum, dev->devpath, 1831 dev->bus->busnum, dev->devpath,
1809 configuration, alt->desc.bInterfaceNumber); 1832 configuration, alt->desc.bInterfaceNumber);
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 25719da45e33..81ce6a8e1d94 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -48,6 +48,10 @@ static const struct usb_device_id usb_quirk_list[] = {
48 { USB_DEVICE(0x04b4, 0x0526), .driver_info = 48 { USB_DEVICE(0x04b4, 0x0526), .driver_info =
49 USB_QUIRK_CONFIG_INTF_STRINGS }, 49 USB_QUIRK_CONFIG_INTF_STRINGS },
50 50
51 /* Samsung Android phone modem - ID conflict with SPH-I500 */
52 { USB_DEVICE(0x04e8, 0x6601), .driver_info =
53 USB_QUIRK_CONFIG_INTF_STRINGS },
54
51 /* Roland SC-8820 */ 55 /* Roland SC-8820 */
52 { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME }, 56 { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME },
53 57
@@ -68,6 +72,10 @@ static const struct usb_device_id usb_quirk_list[] = {
68 /* M-Systems Flash Disk Pioneers */ 72 /* M-Systems Flash Disk Pioneers */
69 { USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME }, 73 { USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME },
70 74
75 /* Keytouch QWERTY Panel keyboard */
76 { USB_DEVICE(0x0926, 0x3333), .driver_info =
77 USB_QUIRK_CONFIG_INTF_STRINGS },
78
71 /* X-Rite/Gretag-Macbeth Eye-One Pro display colorimeter */ 79 /* X-Rite/Gretag-Macbeth Eye-One Pro display colorimeter */
72 { USB_DEVICE(0x0971, 0x2000), .driver_info = USB_QUIRK_NO_SET_INTF }, 80 { USB_DEVICE(0x0971, 0x2000), .driver_info = USB_QUIRK_NO_SET_INTF },
73 81
@@ -117,21 +125,6 @@ void usb_detect_quirks(struct usb_device *udev)
117 dev_dbg(&udev->dev, "USB quirks for this device: %x\n", 125 dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
118 udev->quirks); 126 udev->quirks);
119 127
120#ifdef CONFIG_USB_SUSPEND
121
122 /* By default, disable autosuspend for all devices. The hub driver
123 * will enable it for hubs.
124 */
125 usb_disable_autosuspend(udev);
126
127 /* Autosuspend can also be disabled if the initial autosuspend_delay
128 * is negative.
129 */
130 if (udev->autosuspend_delay < 0)
131 usb_autoresume_device(udev);
132
133#endif
134
135 /* For the present, all devices default to USB-PERSIST enabled */ 128 /* For the present, all devices default to USB-PERSIST enabled */
136#if 0 /* was: #ifdef CONFIG_PM */ 129#if 0 /* was: #ifdef CONFIG_PM */
137 /* Hubs are automatically enabled for USB-PERSIST */ 130 /* Hubs are automatically enabled for USB-PERSIST */
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 448f5b47fc48..cf05b97693ea 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -233,8 +233,6 @@ static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
233 233
234#ifdef CONFIG_PM 234#ifdef CONFIG_PM
235 235
236static const char power_group[] = "power";
237
238static ssize_t 236static ssize_t
239show_persist(struct device *dev, struct device_attribute *attr, char *buf) 237show_persist(struct device *dev, struct device_attribute *attr, char *buf)
240{ 238{
@@ -278,7 +276,7 @@ static int add_persist_attributes(struct device *dev)
278 if (udev->descriptor.bDeviceClass != USB_CLASS_HUB) 276 if (udev->descriptor.bDeviceClass != USB_CLASS_HUB)
279 rc = sysfs_add_file_to_group(&dev->kobj, 277 rc = sysfs_add_file_to_group(&dev->kobj,
280 &dev_attr_persist.attr, 278 &dev_attr_persist.attr,
281 power_group); 279 power_group_name);
282 } 280 }
283 return rc; 281 return rc;
284} 282}
@@ -287,7 +285,7 @@ static void remove_persist_attributes(struct device *dev)
287{ 285{
288 sysfs_remove_file_from_group(&dev->kobj, 286 sysfs_remove_file_from_group(&dev->kobj,
289 &dev_attr_persist.attr, 287 &dev_attr_persist.attr,
290 power_group); 288 power_group_name);
291} 289}
292#else 290#else
293 291
@@ -336,44 +334,20 @@ static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL);
336static ssize_t 334static ssize_t
337show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) 335show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
338{ 336{
339 struct usb_device *udev = to_usb_device(dev); 337 return sprintf(buf, "%d\n", dev->power.autosuspend_delay / 1000);
340
341 return sprintf(buf, "%d\n", udev->autosuspend_delay / HZ);
342} 338}
343 339
344static ssize_t 340static ssize_t
345set_autosuspend(struct device *dev, struct device_attribute *attr, 341set_autosuspend(struct device *dev, struct device_attribute *attr,
346 const char *buf, size_t count) 342 const char *buf, size_t count)
347{ 343{
348 struct usb_device *udev = to_usb_device(dev); 344 int value;
349 int value, old_delay;
350 int rc;
351 345
352 if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ || 346 if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/1000 ||
353 value <= - INT_MAX/HZ) 347 value <= -INT_MAX/1000)
354 return -EINVAL; 348 return -EINVAL;
355 value *= HZ;
356
357 usb_lock_device(udev);
358 old_delay = udev->autosuspend_delay;
359 udev->autosuspend_delay = value;
360
361 if (old_delay < 0) { /* Autosuspend wasn't allowed */
362 if (value >= 0)
363 usb_autosuspend_device(udev);
364 } else { /* Autosuspend was allowed */
365 if (value < 0) {
366 rc = usb_autoresume_device(udev);
367 if (rc < 0) {
368 count = rc;
369 udev->autosuspend_delay = old_delay;
370 }
371 } else {
372 usb_try_autosuspend_device(udev);
373 }
374 }
375 349
376 usb_unlock_device(udev); 350 pm_runtime_set_autosuspend_delay(dev, value * 1000);
377 return count; 351 return count;
378} 352}
379 353
@@ -438,44 +412,30 @@ set_level(struct device *dev, struct device_attribute *attr,
438 412
439static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level); 413static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level);
440 414
415static struct attribute *power_attrs[] = {
416 &dev_attr_autosuspend.attr,
417 &dev_attr_level.attr,
418 &dev_attr_connected_duration.attr,
419 &dev_attr_active_duration.attr,
420 NULL,
421};
422static struct attribute_group power_attr_group = {
423 .name = power_group_name,
424 .attrs = power_attrs,
425};
426
441static int add_power_attributes(struct device *dev) 427static int add_power_attributes(struct device *dev)
442{ 428{
443 int rc = 0; 429 int rc = 0;
444 430
445 if (is_usb_device(dev)) { 431 if (is_usb_device(dev))
446 rc = sysfs_add_file_to_group(&dev->kobj, 432 rc = sysfs_merge_group(&dev->kobj, &power_attr_group);
447 &dev_attr_autosuspend.attr,
448 power_group);
449 if (rc == 0)
450 rc = sysfs_add_file_to_group(&dev->kobj,
451 &dev_attr_level.attr,
452 power_group);
453 if (rc == 0)
454 rc = sysfs_add_file_to_group(&dev->kobj,
455 &dev_attr_connected_duration.attr,
456 power_group);
457 if (rc == 0)
458 rc = sysfs_add_file_to_group(&dev->kobj,
459 &dev_attr_active_duration.attr,
460 power_group);
461 }
462 return rc; 433 return rc;
463} 434}
464 435
465static void remove_power_attributes(struct device *dev) 436static void remove_power_attributes(struct device *dev)
466{ 437{
467 sysfs_remove_file_from_group(&dev->kobj, 438 sysfs_unmerge_group(&dev->kobj, &power_attr_group);
468 &dev_attr_active_duration.attr,
469 power_group);
470 sysfs_remove_file_from_group(&dev->kobj,
471 &dev_attr_connected_duration.attr,
472 power_group);
473 sysfs_remove_file_from_group(&dev->kobj,
474 &dev_attr_level.attr,
475 power_group);
476 sysfs_remove_file_from_group(&dev->kobj,
477 &dev_attr_autosuspend.attr,
478 power_group);
479} 439}
480 440
481#else 441#else
@@ -882,22 +842,19 @@ const struct attribute_group *usb_interface_groups[] = {
882 NULL 842 NULL
883}; 843};
884 844
885int usb_create_sysfs_intf_files(struct usb_interface *intf) 845void usb_create_sysfs_intf_files(struct usb_interface *intf)
886{ 846{
887 struct usb_device *udev = interface_to_usbdev(intf); 847 struct usb_device *udev = interface_to_usbdev(intf);
888 struct usb_host_interface *alt = intf->cur_altsetting; 848 struct usb_host_interface *alt = intf->cur_altsetting;
889 int retval;
890 849
891 if (intf->sysfs_files_created || intf->unregistering) 850 if (intf->sysfs_files_created || intf->unregistering)
892 return 0; 851 return;
893 852
894 if (alt->string == NULL && 853 if (!alt->string && !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
895 !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
896 alt->string = usb_cache_string(udev, alt->desc.iInterface); 854 alt->string = usb_cache_string(udev, alt->desc.iInterface);
897 if (alt->string) 855 if (alt->string && device_create_file(&intf->dev, &dev_attr_interface))
898 retval = device_create_file(&intf->dev, &dev_attr_interface); 856 ; /* We don't actually care if the function fails. */
899 intf->sysfs_files_created = 1; 857 intf->sysfs_files_created = 1;
900 return 0;
901} 858}
902 859
903void usb_remove_sysfs_intf_files(struct usb_interface *intf) 860void usb_remove_sysfs_intf_files(struct usb_interface *intf)
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 419e6b34e2fe..ae334b067c13 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -366,7 +366,16 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
366 if (xfertype == USB_ENDPOINT_XFER_ISOC) { 366 if (xfertype == USB_ENDPOINT_XFER_ISOC) {
367 int n, len; 367 int n, len;
368 368
369 /* FIXME SuperSpeed isoc endpoints have up to 16 bursts */ 369 /* SuperSpeed isoc endpoints have up to 16 bursts of up to
370 * 3 packets each
371 */
372 if (dev->speed == USB_SPEED_SUPER) {
373 int burst = 1 + ep->ss_ep_comp.bMaxBurst;
374 int mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes);
375 max *= burst;
376 max *= mult;
377 }
378
370 /* "high bandwidth" mode, 1-3 packets/uframe? */ 379 /* "high bandwidth" mode, 1-3 packets/uframe? */
371 if (dev->speed == USB_SPEED_HIGH) { 380 if (dev->speed == USB_SPEED_HIGH) {
372 int mult = 1 + ((max >> 11) & 0x03); 381 int mult = 1 + ((max >> 11) & 0x03);
@@ -401,8 +410,11 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
401 }; 410 };
402 411
403 /* Check that the pipe's type matches the endpoint's type */ 412 /* Check that the pipe's type matches the endpoint's type */
404 if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) 413 if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) {
414 dev_err(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n",
415 usb_pipetype(urb->pipe), pipetypes[xfertype]);
405 return -EPIPE; /* The most suitable error code :-) */ 416 return -EPIPE; /* The most suitable error code :-) */
417 }
406 418
407 /* enforce simple/standard policy */ 419 /* enforce simple/standard policy */
408 allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT | URB_DIR_MASK | 420 allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT | URB_DIR_MASK |
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index fdd4130fbb7d..8706fc97e60f 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -315,6 +315,11 @@ static const struct dev_pm_ops usb_device_pm_ops = {
315 .thaw = usb_dev_thaw, 315 .thaw = usb_dev_thaw,
316 .poweroff = usb_dev_poweroff, 316 .poweroff = usb_dev_poweroff,
317 .restore = usb_dev_restore, 317 .restore = usb_dev_restore,
318#ifdef CONFIG_USB_SUSPEND
319 .runtime_suspend = usb_runtime_suspend,
320 .runtime_resume = usb_runtime_resume,
321 .runtime_idle = usb_runtime_idle,
322#endif
318}; 323};
319 324
320#endif /* CONFIG_PM */ 325#endif /* CONFIG_PM */
@@ -445,7 +450,8 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
445 INIT_LIST_HEAD(&dev->filelist); 450 INIT_LIST_HEAD(&dev->filelist);
446 451
447#ifdef CONFIG_PM 452#ifdef CONFIG_PM
448 dev->autosuspend_delay = usb_autosuspend_delay * HZ; 453 pm_runtime_set_autosuspend_delay(&dev->dev,
454 usb_autosuspend_delay * 1000);
449 dev->connect_time = jiffies; 455 dev->connect_time = jiffies;
450 dev->active_duration = -jiffies; 456 dev->active_duration = -jiffies;
451#endif 457#endif
@@ -947,8 +953,7 @@ static int usb_bus_notify(struct notifier_block *nb, unsigned long action,
947 if (dev->type == &usb_device_type) 953 if (dev->type == &usb_device_type)
948 (void) usb_create_sysfs_dev_files(to_usb_device(dev)); 954 (void) usb_create_sysfs_dev_files(to_usb_device(dev));
949 else if (dev->type == &usb_if_device_type) 955 else if (dev->type == &usb_if_device_type)
950 (void) usb_create_sysfs_intf_files( 956 usb_create_sysfs_intf_files(to_usb_interface(dev));
951 to_usb_interface(dev));
952 break; 957 break;
953 958
954 case BUS_NOTIFY_DEL_DEVICE: 959 case BUS_NOTIFY_DEL_DEVICE:
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index cd882203ad34..d44d4b7bbf17 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -4,7 +4,7 @@
4 4
5extern int usb_create_sysfs_dev_files(struct usb_device *dev); 5extern int usb_create_sysfs_dev_files(struct usb_device *dev);
6extern void usb_remove_sysfs_dev_files(struct usb_device *dev); 6extern void usb_remove_sysfs_dev_files(struct usb_device *dev);
7extern int usb_create_sysfs_intf_files(struct usb_interface *intf); 7extern void usb_create_sysfs_intf_files(struct usb_interface *intf);
8extern void usb_remove_sysfs_intf_files(struct usb_interface *intf); 8extern void usb_remove_sysfs_intf_files(struct usb_interface *intf);
9extern int usb_create_ep_devs(struct device *parent, 9extern int usb_create_ep_devs(struct device *parent,
10 struct usb_host_endpoint *endpoint, 10 struct usb_host_endpoint *endpoint,
@@ -75,14 +75,15 @@ static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
75#ifdef CONFIG_USB_SUSPEND 75#ifdef CONFIG_USB_SUSPEND
76 76
77extern void usb_autosuspend_device(struct usb_device *udev); 77extern void usb_autosuspend_device(struct usb_device *udev);
78extern void usb_try_autosuspend_device(struct usb_device *udev);
79extern int usb_autoresume_device(struct usb_device *udev); 78extern int usb_autoresume_device(struct usb_device *udev);
80extern int usb_remote_wakeup(struct usb_device *dev); 79extern int usb_remote_wakeup(struct usb_device *dev);
80extern int usb_runtime_suspend(struct device *dev);
81extern int usb_runtime_resume(struct device *dev);
82extern int usb_runtime_idle(struct device *dev);
81 83
82#else 84#else
83 85
84#define usb_autosuspend_device(udev) do {} while (0) 86#define usb_autosuspend_device(udev) do {} while (0)
85#define usb_try_autosuspend_device(udev) do {} while (0)
86static inline int usb_autoresume_device(struct usb_device *udev) 87static inline int usb_autoresume_device(struct usb_device *udev)
87{ 88{
88 return 0; 89 return 0;
@@ -124,6 +125,19 @@ static inline int is_usb_device_driver(struct device_driver *drv)
124 for_devices; 125 for_devices;
125} 126}
126 127
128/* translate USB error codes to codes user space understands */
129static inline int usb_translate_errors(int error_code)
130{
131 switch (error_code) {
132 case 0:
133 case -ENOMEM:
134 case -ENODEV:
135 return error_code;
136 default:
137 return -EIO;
138 }
139}
140
127 141
128/* for labeling diagnostics */ 142/* for labeling diagnostics */
129extern const char *usbcore_name; 143extern const char *usbcore_name;
diff --git a/drivers/usb/early/Makefile b/drivers/usb/early/Makefile
index dfedee8c45b6..24bbe519c737 100644
--- a/drivers/usb/early/Makefile
+++ b/drivers/usb/early/Makefile
@@ -2,4 +2,4 @@
2# Makefile for early USB devices 2# Makefile for early USB devices
3# 3#
4 4
5obj-$(CONFIG_EARLY_PRINTK_DBGP) += ehci-dbgp.o 5obj-$(CONFIG_EARLY_PRINTK_DBGP) += ehci-dbgp.o
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
index 94ecdbc758ce..1fc8f1249806 100644
--- a/drivers/usb/early/ehci-dbgp.c
+++ b/drivers/usb/early/ehci-dbgp.c
@@ -102,6 +102,9 @@ static struct kgdb_io kgdbdbgp_io_ops;
102#define dbgp_kgdb_mode (0) 102#define dbgp_kgdb_mode (0)
103#endif 103#endif
104 104
105/* Local version of HC_LENGTH macro as ehci struct is not available here */
106#define EARLY_HC_LENGTH(p) (0x00ff & (p)) /* bits 7 : 0 */
107
105/* 108/*
106 * USB Packet IDs (PIDs) 109 * USB Packet IDs (PIDs)
107 */ 110 */
@@ -601,7 +604,7 @@ try_again:
601 dbgp_printk("dbgp_bulk_write failed: %d\n", ret); 604 dbgp_printk("dbgp_bulk_write failed: %d\n", ret);
602 goto err; 605 goto err;
603 } 606 }
604 dbgp_printk("small write doned\n"); 607 dbgp_printk("small write done\n");
605 dbgp_not_safe = 0; 608 dbgp_not_safe = 0;
606 609
607 return 0; 610 return 0;
@@ -648,7 +651,7 @@ static int ehci_reset_port(int port)
648 if (!(portsc & PORT_CONNECT)) 651 if (!(portsc & PORT_CONNECT))
649 return -ENOTCONN; 652 return -ENOTCONN;
650 653
651 /* bomb out completely if something weird happend */ 654 /* bomb out completely if something weird happened */
652 if ((portsc & PORT_CSC)) 655 if ((portsc & PORT_CSC))
653 return -EINVAL; 656 return -EINVAL;
654 657
@@ -892,7 +895,7 @@ int __init early_dbgp_init(char *s)
892 dbgp_printk("ehci_bar: %p\n", ehci_bar); 895 dbgp_printk("ehci_bar: %p\n", ehci_bar);
893 896
894 ehci_caps = ehci_bar; 897 ehci_caps = ehci_bar;
895 ehci_regs = ehci_bar + HC_LENGTH(readl(&ehci_caps->hc_capbase)); 898 ehci_regs = ehci_bar + EARLY_HC_LENGTH(readl(&ehci_caps->hc_capbase));
896 ehci_debug = ehci_bar + offset; 899 ehci_debug = ehci_bar + offset;
897 ehci_dev.bus = bus; 900 ehci_dev.bus = bus;
898 ehci_dev.slot = slot; 901 ehci_dev.slot = slot;
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index cd27f9bde2c8..029e288805b6 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -158,6 +158,7 @@ config USB_GADGET_FSL_USB2
158 boolean "Freescale Highspeed USB DR Peripheral Controller" 158 boolean "Freescale Highspeed USB DR Peripheral Controller"
159 depends on FSL_SOC || ARCH_MXC 159 depends on FSL_SOC || ARCH_MXC
160 select USB_GADGET_DUALSPEED 160 select USB_GADGET_DUALSPEED
161 select USB_FSL_MPH_DR_OF if OF
161 help 162 help
162 Some of Freescale PowerPC processors have a High Speed 163 Some of Freescale PowerPC processors have a High Speed
163 Dual-Role(DR) USB controller, which supports device mode. 164 Dual-Role(DR) USB controller, which supports device mode.
@@ -175,15 +176,15 @@ config USB_FSL_USB2
175 default USB_GADGET 176 default USB_GADGET
176 select USB_GADGET_SELECTED 177 select USB_GADGET_SELECTED
177 178
178config USB_GADGET_LH7A40X 179config USB_GADGET_FUSB300
179 boolean "LH7A40X" 180 boolean "Faraday FUSB300 USB Peripheral Controller"
180 depends on ARCH_LH7A40X 181 select USB_GADGET_DUALSPEED
181 help 182 help
182 This driver provides USB Device Controller driver for LH7A40x 183 Faraday usb device controller FUSB300 driver
183 184
184config USB_LH7A40X 185config USB_FUSB300
185 tristate 186 tristate
186 depends on USB_GADGET_LH7A40X 187 depends on USB_GADGET_FUSB300
187 default USB_GADGET 188 default USB_GADGET
188 select USB_GADGET_SELECTED 189 select USB_GADGET_SELECTED
189 190
@@ -209,17 +210,6 @@ config USB_OMAP
209 default USB_GADGET 210 default USB_GADGET
210 select USB_GADGET_SELECTED 211 select USB_GADGET_SELECTED
211 212
212config USB_OTG
213 boolean "OTG Support"
214 depends on USB_GADGET_OMAP && ARCH_OMAP_OTG && USB_OHCI_HCD
215 help
216 The most notable feature of USB OTG is support for a
217 "Dual-Role" device, which can act as either a device
218 or a host. The initial role choice can be changed
219 later, when two dual-role devices talk to each other.
220
221 Select this only if your OMAP board has a Mini-AB connector.
222
223config USB_GADGET_PXA25X 213config USB_GADGET_PXA25X
224 boolean "PXA 25x or IXP 4xx" 214 boolean "PXA 25x or IXP 4xx"
225 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX 215 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
@@ -270,6 +260,24 @@ config USB_R8A66597
270 default USB_GADGET 260 default USB_GADGET
271 select USB_GADGET_SELECTED 261 select USB_GADGET_SELECTED
272 262
263config USB_GADGET_RENESAS_USBHS
264 boolean "Renesas USBHS"
265 depends on USB_RENESAS_USBHS
266 select USB_GADGET_DUALSPEED
267 help
268 Renesas USBHS is a discrete USB host and peripheral controller
269 chip that supports both full and high speed USB 2.0 data transfers.
270 platform is able to configure endpoint (pipe) style
271
272 Say "y" to enable the gadget specific portion of the USBHS driver.
273
274
275config USB_RENESAS_USBHS_UDC
276 tristate
277 depends on USB_GADGET_RENESAS_USBHS
278 default USB_GADGET
279 select USB_GADGET_SELECTED
280
273config USB_GADGET_PXA27X 281config USB_GADGET_PXA27X
274 boolean "PXA 27x" 282 boolean "PXA 27x"
275 depends on ARCH_PXA && (PXA27x || PXA3xx) 283 depends on ARCH_PXA && (PXA27x || PXA3xx)
@@ -348,6 +356,36 @@ config USB_S3C2410_DEBUG
348 boolean "S3C2410 udc debug messages" 356 boolean "S3C2410 udc debug messages"
349 depends on USB_GADGET_S3C2410 357 depends on USB_GADGET_S3C2410
350 358
359config USB_GADGET_S3C_HSUDC
360 boolean "S3C2416, S3C2443 and S3C2450 USB Device Controller"
361 depends on ARCH_S3C2410
362 select USB_GADGET_DUALSPEED
363 help
364 Samsung's S3C2416, S3C2443 and S3C2450 is an ARM9 based SoC
365 integrated with dual speed USB 2.0 device controller. It has
366 8 endpoints, as well as endpoint zero.
367
368 This driver has been tested on S3C2416 and S3C2450 processors.
369
370config USB_S3C_HSUDC
371 tristate
372 depends on USB_GADGET_S3C_HSUDC
373 default USB_GADGET
374 select USB_GADGET_SELECTED
375
376config USB_GADGET_PXA_U2O
377 boolean "PXA9xx Processor USB2.0 controller"
378 select USB_GADGET_DUALSPEED
379 help
380 PXA9xx Processor series include a high speed USB2.0 device
381 controller, which support high speed and full speed USB peripheral.
382
383config USB_PXA_U2O
384 tristate
385 depends on USB_GADGET_PXA_U2O
386 default USB_GADGET
387 select USB_GADGET_SELECTED
388
351# 389#
352# Controllers available in both integrated and discrete versions 390# Controllers available in both integrated and discrete versions
353# 391#
@@ -424,8 +462,8 @@ config USB_FSL_QE
424 default USB_GADGET 462 default USB_GADGET
425 select USB_GADGET_SELECTED 463 select USB_GADGET_SELECTED
426 464
427config USB_GADGET_CI13XXX 465config USB_GADGET_CI13XXX_PCI
428 boolean "MIPS USB CI13xxx" 466 boolean "MIPS USB CI13xxx PCI UDC"
429 depends on PCI 467 depends on PCI
430 select USB_GADGET_DUALSPEED 468 select USB_GADGET_DUALSPEED
431 help 469 help
@@ -436,9 +474,9 @@ config USB_GADGET_CI13XXX
436 dynamically linked module called "ci13xxx_udc" and force all 474 dynamically linked module called "ci13xxx_udc" and force all
437 gadget drivers to also be dynamically linked. 475 gadget drivers to also be dynamically linked.
438 476
439config USB_CI13XXX 477config USB_CI13XXX_PCI
440 tristate 478 tristate
441 depends on USB_GADGET_CI13XXX 479 depends on USB_GADGET_CI13XXX_PCI
442 default USB_GADGET 480 default USB_GADGET
443 select USB_GADGET_SELECTED 481 select USB_GADGET_SELECTED
444 482
@@ -505,6 +543,56 @@ config USB_LANGWELL
505 default USB_GADGET 543 default USB_GADGET
506 select USB_GADGET_SELECTED 544 select USB_GADGET_SELECTED
507 545
546config USB_GADGET_EG20T
547 boolean "Intel EG20T PCH/OKI SEMICONDUCTOR ML7213 IOH UDC"
548 depends on PCI
549 select USB_GADGET_DUALSPEED
550 help
551 This is a USB device driver for EG20T PCH.
552 EG20T PCH is the platform controller hub that is used in Intel's
553 general embedded platform. EG20T PCH has USB device interface.
554 Using this interface, it is able to access system devices connected
555 to USB device.
556 This driver enables USB device function.
557 USB device is a USB peripheral controller which
558 supports both full and high speed USB 2.0 data transfers.
559 This driver supports both control transfer and bulk transfer modes.
560 This driver dose not support interrupt transfer or isochronous
561 transfer modes.
562
563 This driver also can be used for OKI SEMICONDUCTOR's ML7213 which is
564 for IVI(In-Vehicle Infotainment) use.
565 ML7213 is companion chip for Intel Atom E6xx series.
566 ML7213 is completely compatible for Intel EG20T PCH.
567
568config USB_EG20T
569 tristate
570 depends on USB_GADGET_EG20T
571 default USB_GADGET
572 select USB_GADGET_SELECTED
573
574config USB_GADGET_CI13XXX_MSM
575 boolean "MIPS USB CI13xxx for MSM"
576 depends on ARCH_MSM
577 select USB_GADGET_DUALSPEED
578 select USB_MSM_OTG
579 help
580 MSM SoC has chipidea USB controller. This driver uses
581 ci13xxx_udc core.
582 This driver depends on OTG driver for PHY initialization,
583 clock management, powering up VBUS, and power management.
584 This driver is not supported on boards like trout which
585 has an external PHY.
586
587 Say "y" to link the driver statically, or "m" to build a
588 dynamically linked module called "ci13xxx_msm" and force all
589 gadget drivers to also be dynamically linked.
590
591config USB_CI13XXX_MSM
592 tristate
593 depends on USB_GADGET_CI13XXX_MSM
594 default USB_GADGET
595 select USB_GADGET_SELECTED
508 596
509# 597#
510# LAST -- dummy/emulated controller 598# LAST -- dummy/emulated controller
@@ -544,13 +632,10 @@ config USB_DUMMY_HCD
544 632
545endchoice 633endchoice
546 634
635# Selected by UDC drivers that support high-speed operation.
547config USB_GADGET_DUALSPEED 636config USB_GADGET_DUALSPEED
548 bool 637 bool
549 depends on USB_GADGET 638 depends on USB_GADGET
550 default n
551 help
552 Means that gadget drivers should include extra descriptors
553 and code to handle dual-speed controllers.
554 639
555# 640#
556# USB Gadget Drivers 641# USB Gadget Drivers
@@ -695,6 +780,19 @@ config USB_ETH_EEM
695 If you say "y" here, the Ethernet gadget driver will use the EEM 780 If you say "y" here, the Ethernet gadget driver will use the EEM
696 protocol rather than ECM. If unsure, say "n". 781 protocol rather than ECM. If unsure, say "n".
697 782
783config USB_G_NCM
784 tristate "Network Control Model (NCM) support"
785 depends on NET
786 select CRC32
787 help
788 This driver implements USB CDC NCM subclass standard. NCM is
789 an advanced protocol for Ethernet encapsulation, allows grouping
790 of several ethernet frames into one USB transfer and diffferent
791 alignment possibilities.
792
793 Say "y" to link the driver statically, or "m" to build a
794 dynamically linked module called "g_ncm".
795
698config USB_GADGETFS 796config USB_GADGETFS
699 tristate "Gadget Filesystem (EXPERIMENTAL)" 797 tristate "Gadget Filesystem (EXPERIMENTAL)"
700 depends on EXPERIMENTAL 798 depends on EXPERIMENTAL
@@ -716,8 +814,8 @@ config USB_FUNCTIONFS
716 depends on EXPERIMENTAL 814 depends on EXPERIMENTAL
717 select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) 815 select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS)
718 help 816 help
719 The Function Filesystem (FunctioFS) lets one create USB 817 The Function Filesystem (FunctionFS) lets one create USB
720 composite functions in user space in the same way as GadgetFS 818 composite functions in user space in the same way GadgetFS
721 lets one create USB gadgets in user space. This allows creation 819 lets one create USB gadgets in user space. This allows creation
722 of composite gadgets such that some of the functions are 820 of composite gadgets such that some of the functions are
723 implemented in kernel space (for instance Ethernet, serial or 821 implemented in kernel space (for instance Ethernet, serial or
@@ -733,14 +831,14 @@ config USB_FUNCTIONFS_ETH
733 bool "Include configuration with CDC ECM (Ethernet)" 831 bool "Include configuration with CDC ECM (Ethernet)"
734 depends on USB_FUNCTIONFS && NET 832 depends on USB_FUNCTIONFS && NET
735 help 833 help
736 Include a configuration with CDC ECM funcion (Ethernet) and the 834 Include a configuration with CDC ECM function (Ethernet) and the
737 Funcion Filesystem. 835 Function Filesystem.
738 836
739config USB_FUNCTIONFS_RNDIS 837config USB_FUNCTIONFS_RNDIS
740 bool "Include configuration with RNDIS (Ethernet)" 838 bool "Include configuration with RNDIS (Ethernet)"
741 depends on USB_FUNCTIONFS && NET 839 depends on USB_FUNCTIONFS && NET
742 help 840 help
743 Include a configuration with RNDIS funcion (Ethernet) and the Filesystem. 841 Include a configuration with RNDIS function (Ethernet) and the Filesystem.
744 842
745config USB_FUNCTIONFS_GENERIC 843config USB_FUNCTIONFS_GENERIC
746 bool "Include 'pure' configuration" 844 bool "Include 'pure' configuration"
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 27283df37d09..4fe92b18a055 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -1,9 +1,7 @@
1# 1#
2# USB peripheral controller drivers 2# USB peripheral controller drivers
3# 3#
4ifeq ($(CONFIG_USB_GADGET_DEBUG),y) 4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
5 EXTRA_CFLAGS += -DDEBUG
6endif
7 5
8obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 6obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
9obj-$(CONFIG_USB_NET2280) += net2280.o 7obj-$(CONFIG_USB_NET2280) += net2280.o
@@ -13,40 +11,44 @@ obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o
13obj-$(CONFIG_USB_IMX) += imx_udc.o 11obj-$(CONFIG_USB_IMX) += imx_udc.o
14obj-$(CONFIG_USB_GOKU) += goku_udc.o 12obj-$(CONFIG_USB_GOKU) += goku_udc.o
15obj-$(CONFIG_USB_OMAP) += omap_udc.o 13obj-$(CONFIG_USB_OMAP) += omap_udc.o
16obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
17obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o 14obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o
18obj-$(CONFIG_USB_AT91) += at91_udc.o 15obj-$(CONFIG_USB_AT91) += at91_udc.o
19obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o 16obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
20obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o 17obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
21fsl_usb2_udc-objs := fsl_udc_core.o 18fsl_usb2_udc-y := fsl_udc_core.o
22ifeq ($(CONFIG_ARCH_MXC),y) 19fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o
23fsl_usb2_udc-objs += fsl_mxc_udc.o
24endif
25obj-$(CONFIG_USB_M66592) += m66592-udc.o 20obj-$(CONFIG_USB_M66592) += m66592-udc.o
26obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o 21obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o
27obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o 22obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o
28obj-$(CONFIG_USB_CI13XXX) += ci13xxx_udc.o 23obj-$(CONFIG_USB_CI13XXX_PCI) += ci13xxx_pci.o
29obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o 24obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o
25obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o
30obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o 26obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o
27obj-$(CONFIG_USB_EG20T) += pch_udc.o
28obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o
29mv_udc-y := mv_udc_core.o mv_udc_phy.o
30obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o
31obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
31 32
32# 33#
33# USB gadget drivers 34# USB gadget drivers
34# 35#
35g_zero-objs := zero.o 36g_zero-y := zero.o
36g_audio-objs := audio.o 37g_audio-y := audio.o
37g_ether-objs := ether.o 38g_ether-y := ether.o
38g_serial-objs := serial.o 39g_serial-y := serial.o
39g_midi-objs := gmidi.o 40g_midi-y := gmidi.o
40gadgetfs-objs := inode.o 41gadgetfs-y := inode.o
41g_file_storage-objs := file_storage.o 42g_file_storage-y := file_storage.o
42g_mass_storage-objs := mass_storage.o 43g_mass_storage-y := mass_storage.o
43g_printer-objs := printer.o 44g_printer-y := printer.o
44g_cdc-objs := cdc2.o 45g_cdc-y := cdc2.o
45g_multi-objs := multi.o 46g_multi-y := multi.o
46g_hid-objs := hid.o 47g_hid-y := hid.o
47g_dbgp-objs := dbgp.o 48g_dbgp-y := dbgp.o
48g_nokia-objs := nokia.o 49g_nokia-y := nokia.o
49g_webcam-objs := webcam.o 50g_webcam-y := webcam.o
51g_ncm-y := ncm.o
50 52
51obj-$(CONFIG_USB_ZERO) += g_zero.o 53obj-$(CONFIG_USB_ZERO) += g_zero.o
52obj-$(CONFIG_USB_AUDIO) += g_audio.o 54obj-$(CONFIG_USB_AUDIO) += g_audio.o
@@ -64,4 +66,4 @@ obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o
64obj-$(CONFIG_USB_G_MULTI) += g_multi.o 66obj-$(CONFIG_USB_G_MULTI) += g_multi.o
65obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o 67obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o
66obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o 68obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o
67 69obj-$(CONFIG_USB_G_NCM) += g_ncm.o
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 731150d4b1d9..95e8138cd48f 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -60,6 +60,7 @@
60#include <linux/device.h> 60#include <linux/device.h>
61#include <linux/io.h> 61#include <linux/io.h>
62#include <linux/irq.h> 62#include <linux/irq.h>
63#include <linux/prefetch.h>
63 64
64#include <asm/byteorder.h> 65#include <asm/byteorder.h>
65#include <asm/system.h> 66#include <asm/system.h>
@@ -203,7 +204,7 @@ static void print_regs(struct udc *dev)
203 DBG(dev, "DMA mode = PPBNDU (packet per buffer " 204 DBG(dev, "DMA mode = PPBNDU (packet per buffer "
204 "WITHOUT desc. update)\n"); 205 "WITHOUT desc. update)\n");
205 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBNDU"); 206 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBNDU");
206 } else if (use_dma && use_dma_ppb_du && use_dma_ppb_du) { 207 } else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
207 DBG(dev, "DMA mode = PPBDU (packet per buffer " 208 DBG(dev, "DMA mode = PPBDU (packet per buffer "
208 "WITH desc. update)\n"); 209 "WITH desc. update)\n");
209 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBDU"); 210 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBDU");
@@ -278,7 +279,7 @@ static int udc_enable_dev_setup_interrupts(struct udc *dev)
278 return 0; 279 return 0;
279} 280}
280 281
281/* Calculates fifo start of endpoint based on preceeding endpoints */ 282/* Calculates fifo start of endpoint based on preceding endpoints */
282static int udc_set_txfifo_addr(struct udc_ep *ep) 283static int udc_set_txfifo_addr(struct udc_ep *ep)
283{ 284{
284 struct udc *dev; 285 struct udc *dev;
@@ -1954,13 +1955,14 @@ static int setup_ep0(struct udc *dev)
1954} 1955}
1955 1956
1956/* Called by gadget driver to register itself */ 1957/* Called by gadget driver to register itself */
1957int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1958int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1959 int (*bind)(struct usb_gadget *))
1958{ 1960{
1959 struct udc *dev = udc; 1961 struct udc *dev = udc;
1960 int retval; 1962 int retval;
1961 u32 tmp; 1963 u32 tmp;
1962 1964
1963 if (!driver || !driver->bind || !driver->setup 1965 if (!driver || !bind || !driver->setup
1964 || driver->speed != USB_SPEED_HIGH) 1966 || driver->speed != USB_SPEED_HIGH)
1965 return -EINVAL; 1967 return -EINVAL;
1966 if (!dev) 1968 if (!dev)
@@ -1972,7 +1974,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1972 dev->driver = driver; 1974 dev->driver = driver;
1973 dev->gadget.dev.driver = &driver->driver; 1975 dev->gadget.dev.driver = &driver->driver;
1974 1976
1975 retval = driver->bind(&dev->gadget); 1977 retval = bind(&dev->gadget);
1976 1978
1977 /* Some gadget drivers use both ep0 directions. 1979 /* Some gadget drivers use both ep0 directions.
1978 * NOTE: to gadget driver, ep0 is just one endpoint... 1980 * NOTE: to gadget driver, ep0 is just one endpoint...
@@ -2000,7 +2002,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2000 2002
2001 return 0; 2003 return 0;
2002} 2004}
2003EXPORT_SYMBOL(usb_gadget_register_driver); 2005EXPORT_SYMBOL(usb_gadget_probe_driver);
2004 2006
2005/* shutdown requests and disconnect from gadget */ 2007/* shutdown requests and disconnect from gadget */
2006static void 2008static void
@@ -2136,7 +2138,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int ep_ix)
2136 if (use_dma) { 2138 if (use_dma) {
2137 /* BNA event ? */ 2139 /* BNA event ? */
2138 if (tmp & AMD_BIT(UDC_EPSTS_BNA)) { 2140 if (tmp & AMD_BIT(UDC_EPSTS_BNA)) {
2139 DBG(dev, "BNA ep%dout occured - DESPTR = %x \n", 2141 DBG(dev, "BNA ep%dout occurred - DESPTR = %x \n",
2140 ep->num, readl(&ep->regs->desptr)); 2142 ep->num, readl(&ep->regs->desptr));
2141 /* clear BNA */ 2143 /* clear BNA */
2142 writel(tmp | AMD_BIT(UDC_EPSTS_BNA), &ep->regs->sts); 2144 writel(tmp | AMD_BIT(UDC_EPSTS_BNA), &ep->regs->sts);
@@ -2150,7 +2152,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int ep_ix)
2150 } 2152 }
2151 /* HE event ? */ 2153 /* HE event ? */
2152 if (tmp & AMD_BIT(UDC_EPSTS_HE)) { 2154 if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
2153 dev_err(&dev->pdev->dev, "HE ep%dout occured\n", ep->num); 2155 dev_err(&dev->pdev->dev, "HE ep%dout occurred\n", ep->num);
2154 2156
2155 /* clear HE */ 2157 /* clear HE */
2156 writel(tmp | AMD_BIT(UDC_EPSTS_HE), &ep->regs->sts); 2158 writel(tmp | AMD_BIT(UDC_EPSTS_HE), &ep->regs->sts);
@@ -2353,7 +2355,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix)
2353 /* BNA ? */ 2355 /* BNA ? */
2354 if (epsts & AMD_BIT(UDC_EPSTS_BNA)) { 2356 if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
2355 dev_err(&dev->pdev->dev, 2357 dev_err(&dev->pdev->dev,
2356 "BNA ep%din occured - DESPTR = %08lx \n", 2358 "BNA ep%din occurred - DESPTR = %08lx \n",
2357 ep->num, 2359 ep->num,
2358 (unsigned long) readl(&ep->regs->desptr)); 2360 (unsigned long) readl(&ep->regs->desptr));
2359 2361
@@ -2366,7 +2368,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix)
2366 /* HE event ? */ 2368 /* HE event ? */
2367 if (epsts & AMD_BIT(UDC_EPSTS_HE)) { 2369 if (epsts & AMD_BIT(UDC_EPSTS_HE)) {
2368 dev_err(&dev->pdev->dev, 2370 dev_err(&dev->pdev->dev,
2369 "HE ep%dn occured - DESPTR = %08lx \n", 2371 "HE ep%dn occurred - DESPTR = %08lx \n",
2370 ep->num, (unsigned long) readl(&ep->regs->desptr)); 2372 ep->num, (unsigned long) readl(&ep->regs->desptr));
2371 2373
2372 /* clear HE */ 2374 /* clear HE */
@@ -2383,7 +2385,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix)
2383 req = list_entry(ep->queue.next, 2385 req = list_entry(ep->queue.next,
2384 struct udc_request, queue); 2386 struct udc_request, queue);
2385 /* 2387 /*
2386 * length bytes transfered 2388 * length bytes transferred
2387 * check dma done of last desc. in PPBDU mode 2389 * check dma done of last desc. in PPBDU mode
2388 */ 2390 */
2389 if (use_dma_ppb_du) { 2391 if (use_dma_ppb_du) {
@@ -2783,7 +2785,7 @@ static irqreturn_t udc_control_in_isr(struct udc *dev)
2783 /* write fifo */ 2785 /* write fifo */
2784 udc_txfifo_write(ep, &req->req); 2786 udc_txfifo_write(ep, &req->req);
2785 2787
2786 /* lengh bytes transfered */ 2788 /* lengh bytes transferred */
2787 len = req->req.length - req->req.actual; 2789 len = req->req.length - req->req.actual;
2788 if (len > ep->ep.maxpacket) 2790 if (len > ep->ep.maxpacket)
2789 len = ep->ep.maxpacket; 2791 len = ep->ep.maxpacket;
@@ -3358,7 +3360,6 @@ static int udc_probe(struct udc *dev)
3358 dev_set_name(&dev->gadget.dev, "gadget"); 3360 dev_set_name(&dev->gadget.dev, "gadget");
3359 dev->gadget.dev.release = gadget_release; 3361 dev->gadget.dev.release = gadget_release;
3360 dev->gadget.name = name; 3362 dev->gadget.name = name;
3361 dev->gadget.name = name;
3362 dev->gadget.is_dualspeed = 1; 3363 dev->gadget.is_dualspeed = 1;
3363 3364
3364 /* init registers, interrupts, ... */ 3365 /* init registers, interrupts, ... */
@@ -3382,8 +3383,10 @@ static int udc_probe(struct udc *dev)
3382 udc = dev; 3383 udc = dev;
3383 3384
3384 retval = device_register(&dev->gadget.dev); 3385 retval = device_register(&dev->gadget.dev);
3385 if (retval) 3386 if (retval) {
3387 put_device(&dev->gadget.dev);
3386 goto finished; 3388 goto finished;
3389 }
3387 3390
3388 /* timer init */ 3391 /* timer init */
3389 init_timer(&udc_timer); 3392 init_timer(&udc_timer);
diff --git a/drivers/usb/gadget/amd5536udc.h b/drivers/usb/gadget/amd5536udc.h
index 4bbabbbfc93f..1d1c7543468e 100644
--- a/drivers/usb/gadget/amd5536udc.h
+++ b/drivers/usb/gadget/amd5536udc.h
@@ -584,7 +584,7 @@ union udc_setup_data {
584 * SET and GET bitfields in u32 values 584 * SET and GET bitfields in u32 values
585 * via constants for mask/offset: 585 * via constants for mask/offset:
586 * <bit_field_stub_name> is the text between 586 * <bit_field_stub_name> is the text between
587 * UDC_ and _MASK|_OFS of appropiate 587 * UDC_ and _MASK|_OFS of appropriate
588 * constant 588 * constant
589 * 589 *
590 * set bitfield value in u32 u32Val 590 * set bitfield value in u32 u32Val
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 93ead19507b6..f4690ffcb489 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -38,6 +38,7 @@
38#include <linux/clk.h> 38#include <linux/clk.h>
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/prefetch.h>
41 42
42#include <asm/byteorder.h> 43#include <asm/byteorder.h>
43#include <mach/hardware.h> 44#include <mach/hardware.h>
@@ -826,7 +827,7 @@ done:
826 return status; 827 return status;
827} 828}
828 829
829/* reinit == restore inital software state */ 830/* reinit == restore initial software state */
830static void udc_reinit(struct at91_udc *udc) 831static void udc_reinit(struct at91_udc *udc)
831{ 832{
832 u32 i; 833 u32 i;
@@ -1266,7 +1267,6 @@ write_in:
1266 csr |= AT91_UDP_TXPKTRDY; 1267 csr |= AT91_UDP_TXPKTRDY;
1267 __raw_writel(csr, creg); 1268 __raw_writel(csr, creg);
1268 udc->req_pending = 0; 1269 udc->req_pending = 0;
1269 return;
1270} 1270}
1271 1271
1272static void handle_ep0(struct at91_udc *udc) 1272static void handle_ep0(struct at91_udc *udc)
@@ -1628,7 +1628,8 @@ static void at91_vbus_timer(unsigned long data)
1628 schedule_work(&udc->vbus_timer_work); 1628 schedule_work(&udc->vbus_timer_work);
1629} 1629}
1630 1630
1631int usb_gadget_register_driver (struct usb_gadget_driver *driver) 1631int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1632 int (*bind)(struct usb_gadget *))
1632{ 1633{
1633 struct at91_udc *udc = &controller; 1634 struct at91_udc *udc = &controller;
1634 int retval; 1635 int retval;
@@ -1636,7 +1637,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1636 1637
1637 if (!driver 1638 if (!driver
1638 || driver->speed < USB_SPEED_FULL 1639 || driver->speed < USB_SPEED_FULL
1639 || !driver->bind 1640 || !bind
1640 || !driver->setup) { 1641 || !driver->setup) {
1641 DBG("bad parameter.\n"); 1642 DBG("bad parameter.\n");
1642 return -EINVAL; 1643 return -EINVAL;
@@ -1653,9 +1654,9 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1653 udc->enabled = 1; 1654 udc->enabled = 1;
1654 udc->selfpowered = 1; 1655 udc->selfpowered = 1;
1655 1656
1656 retval = driver->bind(&udc->gadget); 1657 retval = bind(&udc->gadget);
1657 if (retval) { 1658 if (retval) {
1658 DBG("driver->bind() returned %d\n", retval); 1659 DBG("bind() returned %d\n", retval);
1659 udc->driver = NULL; 1660 udc->driver = NULL;
1660 udc->gadget.dev.driver = NULL; 1661 udc->gadget.dev.driver = NULL;
1661 dev_set_drvdata(&udc->gadget.dev, NULL); 1662 dev_set_drvdata(&udc->gadget.dev, NULL);
@@ -1671,7 +1672,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1671 DBG("bound to %s\n", driver->driver.name); 1672 DBG("bound to %s\n", driver->driver.name);
1672 return 0; 1673 return 0;
1673} 1674}
1674EXPORT_SYMBOL (usb_gadget_register_driver); 1675EXPORT_SYMBOL(usb_gadget_probe_driver);
1675 1676
1676int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 1677int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
1677{ 1678{
@@ -1767,7 +1768,7 @@ static int __init at91udc_probe(struct platform_device *pdev)
1767 } 1768 }
1768 1769
1769 /* newer chips have more FIFO memory than rm9200 */ 1770 /* newer chips have more FIFO memory than rm9200 */
1770 if (cpu_is_at91sam9260()) { 1771 if (cpu_is_at91sam9260() || cpu_is_at91sam9g20()) {
1771 udc->ep[0].maxpacket = 64; 1772 udc->ep[0].maxpacket = 64;
1772 udc->ep[3].maxpacket = 64; 1773 udc->ep[3].maxpacket = 64;
1773 udc->ep[4].maxpacket = 512; 1774 udc->ep[4].maxpacket = 512;
@@ -1798,8 +1799,10 @@ static int __init at91udc_probe(struct platform_device *pdev)
1798 } 1799 }
1799 1800
1800 retval = device_register(&udc->gadget.dev); 1801 retval = device_register(&udc->gadget.dev);
1801 if (retval < 0) 1802 if (retval < 0) {
1803 put_device(&udc->gadget.dev);
1802 goto fail0b; 1804 goto fail0b;
1805 }
1803 1806
1804 /* don't do anything until we have both gadget driver and VBUS */ 1807 /* don't do anything until we have both gadget driver and VBUS */
1805 clk_enable(udc->iclk); 1808 clk_enable(udc->iclk);
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index d623c7bda1f6..db1a659702ba 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1789,7 +1789,8 @@ out:
1789 return IRQ_HANDLED; 1789 return IRQ_HANDLED;
1790} 1790}
1791 1791
1792int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1792int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1793 int (*bind)(struct usb_gadget *))
1793{ 1794{
1794 struct usba_udc *udc = &the_udc; 1795 struct usba_udc *udc = &the_udc;
1795 unsigned long flags; 1796 unsigned long flags;
@@ -1812,7 +1813,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1812 clk_enable(udc->pclk); 1813 clk_enable(udc->pclk);
1813 clk_enable(udc->hclk); 1814 clk_enable(udc->hclk);
1814 1815
1815 ret = driver->bind(&udc->gadget); 1816 ret = bind(&udc->gadget);
1816 if (ret) { 1817 if (ret) {
1817 DBG(DBG_ERR, "Could not bind to driver %s: error %d\n", 1818 DBG(DBG_ERR, "Could not bind to driver %s: error %d\n",
1818 driver->driver.name, ret); 1819 driver->driver.name, ret);
@@ -1841,7 +1842,7 @@ err_driver_bind:
1841 udc->gadget.dev.driver = NULL; 1842 udc->gadget.dev.driver = NULL;
1842 return ret; 1843 return ret;
1843} 1844}
1844EXPORT_SYMBOL(usb_gadget_register_driver); 1845EXPORT_SYMBOL(usb_gadget_probe_driver);
1845 1846
1846int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1847int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1847{ 1848{
@@ -2014,6 +2015,9 @@ static int __init usba_udc_probe(struct platform_device *pdev)
2014 } else { 2015 } else {
2015 disable_irq(gpio_to_irq(udc->vbus_pin)); 2016 disable_irq(gpio_to_irq(udc->vbus_pin));
2016 } 2017 }
2018 } else {
2019 /* gpio_request fail so use -EINVAL for gpio_is_valid */
2020 udc->vbus_pin = -EINVAL;
2017 } 2021 }
2018 } 2022 }
2019 2023
@@ -2053,8 +2057,10 @@ static int __exit usba_udc_remove(struct platform_device *pdev)
2053 usba_ep_cleanup_debugfs(&usba_ep[i]); 2057 usba_ep_cleanup_debugfs(&usba_ep[i]);
2054 usba_cleanup_debugfs(udc); 2058 usba_cleanup_debugfs(udc);
2055 2059
2056 if (gpio_is_valid(udc->vbus_pin)) 2060 if (gpio_is_valid(udc->vbus_pin)) {
2061 free_irq(gpio_to_irq(udc->vbus_pin), udc);
2057 gpio_free(udc->vbus_pin); 2062 gpio_free(udc->vbus_pin);
2063 }
2058 2064
2059 free_irq(udc->irq, udc); 2065 free_irq(udc->irq, udc);
2060 kfree(usba_ep); 2066 kfree(usba_ep);
@@ -2089,6 +2095,6 @@ static void __exit udc_exit(void)
2089module_exit(udc_exit); 2095module_exit(udc_exit);
2090 2096
2091MODULE_DESCRIPTION("Atmel USBA UDC driver"); 2097MODULE_DESCRIPTION("Atmel USBA UDC driver");
2092MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>"); 2098MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
2093MODULE_LICENSE("GPL"); 2099MODULE_LICENSE("GPL");
2094MODULE_ALIAS("platform:atmel_usba_udc"); 2100MODULE_ALIAS("platform:atmel_usba_udc");
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index b744ccd0f34d..93b999e49ef3 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -89,7 +89,7 @@ static const struct usb_descriptor_header *otg_desc[] = {
89 89
90/*-------------------------------------------------------------------------*/ 90/*-------------------------------------------------------------------------*/
91 91
92static int __ref audio_do_config(struct usb_configuration *c) 92static int __init audio_do_config(struct usb_configuration *c)
93{ 93{
94 /* FIXME alloc iConfiguration string, set it in c->strings */ 94 /* FIXME alloc iConfiguration string, set it in c->strings */
95 95
@@ -105,7 +105,6 @@ static int __ref audio_do_config(struct usb_configuration *c)
105 105
106static struct usb_configuration audio_config_driver = { 106static struct usb_configuration audio_config_driver = {
107 .label = DRIVER_DESC, 107 .label = DRIVER_DESC,
108 .bind = audio_do_config,
109 .bConfigurationValue = 1, 108 .bConfigurationValue = 1,
110 /* .iConfiguration = DYNAMIC */ 109 /* .iConfiguration = DYNAMIC */
111 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 110 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -113,7 +112,7 @@ static struct usb_configuration audio_config_driver = {
113 112
114/*-------------------------------------------------------------------------*/ 113/*-------------------------------------------------------------------------*/
115 114
116static int __ref audio_bind(struct usb_composite_dev *cdev) 115static int __init audio_bind(struct usb_composite_dev *cdev)
117{ 116{
118 int gcnum; 117 int gcnum;
119 int status; 118 int status;
@@ -145,7 +144,7 @@ static int __ref audio_bind(struct usb_composite_dev *cdev)
145 strings_dev[STRING_PRODUCT_IDX].id = status; 144 strings_dev[STRING_PRODUCT_IDX].id = status;
146 device_desc.iProduct = status; 145 device_desc.iProduct = status;
147 146
148 status = usb_add_config(cdev, &audio_config_driver); 147 status = usb_add_config(cdev, &audio_config_driver, audio_do_config);
149 if (status < 0) 148 if (status < 0)
150 goto fail; 149 goto fail;
151 150
@@ -166,13 +165,12 @@ static struct usb_composite_driver audio_driver = {
166 .name = "g_audio", 165 .name = "g_audio",
167 .dev = &device_desc, 166 .dev = &device_desc,
168 .strings = audio_strings, 167 .strings = audio_strings,
169 .bind = audio_bind,
170 .unbind = __exit_p(audio_unbind), 168 .unbind = __exit_p(audio_unbind),
171}; 169};
172 170
173static int __init init(void) 171static int __init init(void)
174{ 172{
175 return usb_composite_register(&audio_driver); 173 return usb_composite_probe(&audio_driver, audio_bind);
176} 174}
177module_init(init); 175module_init(init);
178 176
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 1f5ba2fd4c1f..2720ab07ef1a 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -129,7 +129,7 @@ static u8 hostaddr[ETH_ALEN];
129/* 129/*
130 * We _always_ have both CDC ECM and CDC ACM functions. 130 * We _always_ have both CDC ECM and CDC ACM functions.
131 */ 131 */
132static int __ref cdc_do_config(struct usb_configuration *c) 132static int __init cdc_do_config(struct usb_configuration *c)
133{ 133{
134 int status; 134 int status;
135 135
@@ -151,7 +151,6 @@ static int __ref cdc_do_config(struct usb_configuration *c)
151 151
152static struct usb_configuration cdc_config_driver = { 152static struct usb_configuration cdc_config_driver = {
153 .label = "CDC Composite (ECM + ACM)", 153 .label = "CDC Composite (ECM + ACM)",
154 .bind = cdc_do_config,
155 .bConfigurationValue = 1, 154 .bConfigurationValue = 1,
156 /* .iConfiguration = DYNAMIC */ 155 /* .iConfiguration = DYNAMIC */
157 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 156 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -159,7 +158,7 @@ static struct usb_configuration cdc_config_driver = {
159 158
160/*-------------------------------------------------------------------------*/ 159/*-------------------------------------------------------------------------*/
161 160
162static int __ref cdc_bind(struct usb_composite_dev *cdev) 161static int __init cdc_bind(struct usb_composite_dev *cdev)
163{ 162{
164 int gcnum; 163 int gcnum;
165 struct usb_gadget *gadget = cdev->gadget; 164 struct usb_gadget *gadget = cdev->gadget;
@@ -218,7 +217,7 @@ static int __ref cdc_bind(struct usb_composite_dev *cdev)
218 device_desc.iProduct = status; 217 device_desc.iProduct = status;
219 218
220 /* register our configuration */ 219 /* register our configuration */
221 status = usb_add_config(cdev, &cdc_config_driver); 220 status = usb_add_config(cdev, &cdc_config_driver, cdc_do_config);
222 if (status < 0) 221 if (status < 0)
223 goto fail1; 222 goto fail1;
224 223
@@ -245,7 +244,6 @@ static struct usb_composite_driver cdc_driver = {
245 .name = "g_cdc", 244 .name = "g_cdc",
246 .dev = &device_desc, 245 .dev = &device_desc,
247 .strings = dev_strings, 246 .strings = dev_strings,
248 .bind = cdc_bind,
249 .unbind = __exit_p(cdc_unbind), 247 .unbind = __exit_p(cdc_unbind),
250}; 248};
251 249
@@ -255,7 +253,7 @@ MODULE_LICENSE("GPL");
255 253
256static int __init init(void) 254static int __init init(void)
257{ 255{
258 return usb_composite_register(&cdc_driver); 256 return usb_composite_probe(&cdc_driver, cdc_bind);
259} 257}
260module_init(init); 258module_init(init);
261 259
diff --git a/drivers/usb/gadget/ci13xxx_msm.c b/drivers/usb/gadget/ci13xxx_msm.c
new file mode 100644
index 000000000000..139ac9419597
--- /dev/null
+++ b/drivers/usb/gadget/ci13xxx_msm.c
@@ -0,0 +1,134 @@
1/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 *
17 */
18
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/pm_runtime.h>
22#include <linux/usb/msm_hsusb_hw.h>
23#include <linux/usb/ulpi.h>
24
25#include "ci13xxx_udc.c"
26
27#define MSM_USB_BASE (udc->regs)
28
29static irqreturn_t msm_udc_irq(int irq, void *data)
30{
31 return udc_irq();
32}
33
34static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event)
35{
36 struct device *dev = udc->gadget.dev.parent;
37 int val;
38
39 switch (event) {
40 case CI13XXX_CONTROLLER_RESET_EVENT:
41 dev_dbg(dev, "CI13XXX_CONTROLLER_RESET_EVENT received\n");
42 writel(0, USB_AHBBURST);
43 writel(0, USB_AHBMODE);
44 break;
45 case CI13XXX_CONTROLLER_STOPPED_EVENT:
46 dev_dbg(dev, "CI13XXX_CONTROLLER_STOPPED_EVENT received\n");
47 /*
48 * Put the transceiver in non-driving mode. Otherwise host
49 * may not detect soft-disconnection.
50 */
51 val = otg_io_read(udc->transceiver, ULPI_FUNC_CTRL);
52 val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
53 val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
54 otg_io_write(udc->transceiver, val, ULPI_FUNC_CTRL);
55 break;
56 default:
57 dev_dbg(dev, "unknown ci13xxx_udc event\n");
58 break;
59 }
60}
61
62static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = {
63 .name = "ci13xxx_msm",
64 .flags = CI13XXX_REGS_SHARED |
65 CI13XXX_REQUIRE_TRANSCEIVER |
66 CI13XXX_PULLUP_ON_VBUS |
67 CI13XXX_DISABLE_STREAMING,
68
69 .notify_event = ci13xxx_msm_notify_event,
70};
71
72static int ci13xxx_msm_probe(struct platform_device *pdev)
73{
74 struct resource *res;
75 void __iomem *regs;
76 int irq;
77 int ret;
78
79 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
80
81 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
82 if (!res) {
83 dev_err(&pdev->dev, "failed to get platform resource mem\n");
84 return -ENXIO;
85 }
86
87 regs = ioremap(res->start, resource_size(res));
88 if (!regs) {
89 dev_err(&pdev->dev, "ioremap failed\n");
90 return -ENOMEM;
91 }
92
93 ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, regs);
94 if (ret < 0) {
95 dev_err(&pdev->dev, "udc_probe failed\n");
96 goto iounmap;
97 }
98
99 irq = platform_get_irq(pdev, 0);
100 if (irq < 0) {
101 dev_err(&pdev->dev, "IRQ not found\n");
102 ret = -ENXIO;
103 goto udc_remove;
104 }
105
106 ret = request_irq(irq, msm_udc_irq, IRQF_SHARED, pdev->name, pdev);
107 if (ret < 0) {
108 dev_err(&pdev->dev, "request_irq failed\n");
109 goto udc_remove;
110 }
111
112 pm_runtime_no_callbacks(&pdev->dev);
113 pm_runtime_enable(&pdev->dev);
114
115 return 0;
116
117udc_remove:
118 udc_remove();
119iounmap:
120 iounmap(regs);
121
122 return ret;
123}
124
125static struct platform_driver ci13xxx_msm_driver = {
126 .probe = ci13xxx_msm_probe,
127 .driver = { .name = "msm_hsusb", },
128};
129
130static int __init ci13xxx_msm_init(void)
131{
132 return platform_driver_register(&ci13xxx_msm_driver);
133}
134module_init(ci13xxx_msm_init);
diff --git a/drivers/usb/gadget/ci13xxx_pci.c b/drivers/usb/gadget/ci13xxx_pci.c
new file mode 100644
index 000000000000..883ab5e832d1
--- /dev/null
+++ b/drivers/usb/gadget/ci13xxx_pci.c
@@ -0,0 +1,176 @@
1/*
2 * ci13xxx_pci.c - MIPS USB IP core family device controller
3 *
4 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
5 *
6 * Author: David Lopo
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/pci.h>
15
16#include "ci13xxx_udc.c"
17
18/* driver name */
19#define UDC_DRIVER_NAME "ci13xxx_pci"
20
21/******************************************************************************
22 * PCI block
23 *****************************************************************************/
24/**
25 * ci13xxx_pci_irq: interrut handler
26 * @irq: irq number
27 * @pdev: USB Device Controller interrupt source
28 *
29 * This function returns IRQ_HANDLED if the IRQ has been handled
30 * This is an ISR don't trace, use attribute interface instead
31 */
32static irqreturn_t ci13xxx_pci_irq(int irq, void *pdev)
33{
34 if (irq == 0) {
35 dev_err(&((struct pci_dev *)pdev)->dev, "Invalid IRQ0 usage!");
36 return IRQ_HANDLED;
37 }
38 return udc_irq();
39}
40
41static struct ci13xxx_udc_driver ci13xxx_pci_udc_driver = {
42 .name = UDC_DRIVER_NAME,
43};
44
45/**
46 * ci13xxx_pci_probe: PCI probe
47 * @pdev: USB device controller being probed
48 * @id: PCI hotplug ID connecting controller to UDC framework
49 *
50 * This function returns an error code
51 * Allocates basic PCI resources for this USB device controller, and then
52 * invokes the udc_probe() method to start the UDC associated with it
53 */
54static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
55 const struct pci_device_id *id)
56{
57 void __iomem *regs = NULL;
58 int retval = 0;
59
60 if (id == NULL)
61 return -EINVAL;
62
63 retval = pci_enable_device(pdev);
64 if (retval)
65 goto done;
66
67 if (!pdev->irq) {
68 dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
69 retval = -ENODEV;
70 goto disable_device;
71 }
72
73 retval = pci_request_regions(pdev, UDC_DRIVER_NAME);
74 if (retval)
75 goto disable_device;
76
77 /* BAR 0 holds all the registers */
78 regs = pci_iomap(pdev, 0, 0);
79 if (!regs) {
80 dev_err(&pdev->dev, "Error mapping memory!");
81 retval = -EFAULT;
82 goto release_regions;
83 }
84 pci_set_drvdata(pdev, (__force void *)regs);
85
86 pci_set_master(pdev);
87 pci_try_set_mwi(pdev);
88
89 retval = udc_probe(&ci13xxx_pci_udc_driver, &pdev->dev, regs);
90 if (retval)
91 goto iounmap;
92
93 /* our device does not have MSI capability */
94
95 retval = request_irq(pdev->irq, ci13xxx_pci_irq, IRQF_SHARED,
96 UDC_DRIVER_NAME, pdev);
97 if (retval)
98 goto gadget_remove;
99
100 return 0;
101
102 gadget_remove:
103 udc_remove();
104 iounmap:
105 pci_iounmap(pdev, regs);
106 release_regions:
107 pci_release_regions(pdev);
108 disable_device:
109 pci_disable_device(pdev);
110 done:
111 return retval;
112}
113
114/**
115 * ci13xxx_pci_remove: PCI remove
116 * @pdev: USB Device Controller being removed
117 *
118 * Reverses the effect of ci13xxx_pci_probe(),
119 * first invoking the udc_remove() and then releases
120 * all PCI resources allocated for this USB device controller
121 */
122static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
123{
124 free_irq(pdev->irq, pdev);
125 udc_remove();
126 pci_iounmap(pdev, (__force void __iomem *)pci_get_drvdata(pdev));
127 pci_release_regions(pdev);
128 pci_disable_device(pdev);
129}
130
131/**
132 * PCI device table
133 * PCI device structure
134 *
135 * Check "pci.h" for details
136 */
137static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = {
138 { PCI_DEVICE(0x153F, 0x1004) },
139 { PCI_DEVICE(0x153F, 0x1006) },
140 { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
141};
142MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table);
143
144static struct pci_driver ci13xxx_pci_driver = {
145 .name = UDC_DRIVER_NAME,
146 .id_table = ci13xxx_pci_id_table,
147 .probe = ci13xxx_pci_probe,
148 .remove = __devexit_p(ci13xxx_pci_remove),
149};
150
151/**
152 * ci13xxx_pci_init: module init
153 *
154 * Driver load
155 */
156static int __init ci13xxx_pci_init(void)
157{
158 return pci_register_driver(&ci13xxx_pci_driver);
159}
160module_init(ci13xxx_pci_init);
161
162/**
163 * ci13xxx_pci_exit: module exit
164 *
165 * Driver unload
166 */
167static void __exit ci13xxx_pci_exit(void)
168{
169 pci_unregister_driver(&ci13xxx_pci_driver);
170}
171module_exit(ci13xxx_pci_exit);
172
173MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
174MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
175MODULE_LICENSE("GPL");
176MODULE_VERSION("June 2008");
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index 699695128e33..baaf87ed7685 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -22,7 +22,6 @@
22 * - ENDPT: endpoint operations (Gadget API) 22 * - ENDPT: endpoint operations (Gadget API)
23 * - GADGET: gadget operations (Gadget API) 23 * - GADGET: gadget operations (Gadget API)
24 * - BUS: bus glue code, bus abstraction layer 24 * - BUS: bus glue code, bus abstraction layer
25 * - PCI: PCI core interface and PCI resources (interrupts, memory...)
26 * 25 *
27 * Compile Options 26 * Compile Options
28 * - CONFIG_USB_GADGET_DEBUG_FILES: enable debug facilities 27 * - CONFIG_USB_GADGET_DEBUG_FILES: enable debug facilities
@@ -60,11 +59,11 @@
60#include <linux/io.h> 59#include <linux/io.h>
61#include <linux/irq.h> 60#include <linux/irq.h>
62#include <linux/kernel.h> 61#include <linux/kernel.h>
63#include <linux/module.h>
64#include <linux/pci.h>
65#include <linux/slab.h> 62#include <linux/slab.h>
63#include <linux/pm_runtime.h>
66#include <linux/usb/ch9.h> 64#include <linux/usb/ch9.h>
67#include <linux/usb/gadget.h> 65#include <linux/usb/gadget.h>
66#include <linux/usb/otg.h>
68 67
69#include "ci13xxx_udc.h" 68#include "ci13xxx_udc.h"
70 69
@@ -75,15 +74,23 @@
75/* ctrl register bank access */ 74/* ctrl register bank access */
76static DEFINE_SPINLOCK(udc_lock); 75static DEFINE_SPINLOCK(udc_lock);
77 76
78/* driver name */
79#define UDC_DRIVER_NAME "ci13xxx_udc"
80
81/* control endpoint description */ 77/* control endpoint description */
82static const struct usb_endpoint_descriptor 78static const struct usb_endpoint_descriptor
83ctrl_endpt_desc = { 79ctrl_endpt_out_desc = {
80 .bLength = USB_DT_ENDPOINT_SIZE,
81 .bDescriptorType = USB_DT_ENDPOINT,
82
83 .bEndpointAddress = USB_DIR_OUT,
84 .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
85 .wMaxPacketSize = cpu_to_le16(CTRL_PAYLOAD_MAX),
86};
87
88static const struct usb_endpoint_descriptor
89ctrl_endpt_in_desc = {
84 .bLength = USB_DT_ENDPOINT_SIZE, 90 .bLength = USB_DT_ENDPOINT_SIZE,
85 .bDescriptorType = USB_DT_ENDPOINT, 91 .bDescriptorType = USB_DT_ENDPOINT,
86 92
93 .bEndpointAddress = USB_DIR_IN,
87 .bmAttributes = USB_ENDPOINT_XFER_CONTROL, 94 .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
88 .wMaxPacketSize = cpu_to_le16(CTRL_PAYLOAD_MAX), 95 .wMaxPacketSize = cpu_to_le16(CTRL_PAYLOAD_MAX),
89}; 96};
@@ -132,6 +139,9 @@ static struct {
132 size_t size; /* bank size */ 139 size_t size; /* bank size */
133} hw_bank; 140} hw_bank;
134 141
142/* MSM specific */
143#define ABS_AHBBURST (0x0090UL)
144#define ABS_AHBMODE (0x0098UL)
135/* UDC register map */ 145/* UDC register map */
136#define ABS_CAPLENGTH (0x100UL) 146#define ABS_CAPLENGTH (0x100UL)
137#define ABS_HCCPARAMS (0x108UL) 147#define ABS_HCCPARAMS (0x108UL)
@@ -248,13 +258,7 @@ static u32 hw_ctest_and_write(u32 addr, u32 mask, u32 data)
248 return (reg & mask) >> ffs_nr(mask); 258 return (reg & mask) >> ffs_nr(mask);
249} 259}
250 260
251/** 261static int hw_device_init(void __iomem *base)
252 * hw_device_reset: resets chip (execute without interruption)
253 * @base: register base address
254 *
255 * This function returns an error code
256 */
257static int hw_device_reset(void __iomem *base)
258{ 262{
259 u32 reg; 263 u32 reg;
260 264
@@ -271,6 +275,28 @@ static int hw_device_reset(void __iomem *base)
271 hw_bank.size += CAP_LAST; 275 hw_bank.size += CAP_LAST;
272 hw_bank.size /= sizeof(u32); 276 hw_bank.size /= sizeof(u32);
273 277
278 reg = hw_aread(ABS_DCCPARAMS, DCCPARAMS_DEN) >> ffs_nr(DCCPARAMS_DEN);
279 hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */
280
281 if (hw_ep_max == 0 || hw_ep_max > ENDPT_MAX)
282 return -ENODEV;
283
284 /* setup lock mode ? */
285
286 /* ENDPTSETUPSTAT is '0' by default */
287
288 /* HCSPARAMS.bf.ppc SHOULD BE zero for device */
289
290 return 0;
291}
292/**
293 * hw_device_reset: resets chip (execute without interruption)
294 * @base: register base address
295 *
296 * This function returns an error code
297 */
298static int hw_device_reset(struct ci13xxx *udc)
299{
274 /* should flush & stop before reset */ 300 /* should flush & stop before reset */
275 hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0); 301 hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0);
276 hw_cwrite(CAP_USBCMD, USBCMD_RS, 0); 302 hw_cwrite(CAP_USBCMD, USBCMD_RS, 0);
@@ -279,6 +305,14 @@ static int hw_device_reset(void __iomem *base)
279 while (hw_cread(CAP_USBCMD, USBCMD_RST)) 305 while (hw_cread(CAP_USBCMD, USBCMD_RST))
280 udelay(10); /* not RTOS friendly */ 306 udelay(10); /* not RTOS friendly */
281 307
308
309 if (udc->udc_driver->notify_event)
310 udc->udc_driver->notify_event(udc,
311 CI13XXX_CONTROLLER_RESET_EVENT);
312
313 if (udc->udc_driver->flags & CI13XXX_DISABLE_STREAMING)
314 hw_cwrite(CAP_USBMODE, USBMODE_SDIS, USBMODE_SDIS);
315
282 /* USBMODE should be configured step by step */ 316 /* USBMODE should be configured step by step */
283 hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); 317 hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE);
284 hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); 318 hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE);
@@ -290,18 +324,6 @@ static int hw_device_reset(void __iomem *base)
290 return -ENODEV; 324 return -ENODEV;
291 } 325 }
292 326
293 reg = hw_aread(ABS_DCCPARAMS, DCCPARAMS_DEN) >> ffs_nr(DCCPARAMS_DEN);
294 if (reg == 0 || reg > ENDPT_MAX)
295 return -ENODEV;
296
297 hw_ep_max = reg; /* cache hw ENDPT_MAX */
298
299 /* setup lock mode ? */
300
301 /* ENDPTSETUPSTAT is '0' by default */
302
303 /* HCSPARAMS.bf.ppc SHOULD BE zero for device */
304
305 return 0; 327 return 0;
306} 328}
307 329
@@ -413,20 +435,6 @@ static int hw_ep_get_halt(int num, int dir)
413} 435}
414 436
415/** 437/**
416 * hw_ep_is_primed: test if endpoint is primed (execute without interruption)
417 * @num: endpoint number
418 * @dir: endpoint direction
419 *
420 * This function returns true if endpoint primed
421 */
422static int hw_ep_is_primed(int num, int dir)
423{
424 u32 reg = hw_cread(CAP_ENDPTPRIME, ~0) | hw_cread(CAP_ENDPTSTAT, ~0);
425
426 return test_bit(hw_ep_bit(num, dir), (void *)&reg);
427}
428
429/**
430 * hw_test_and_clear_setup_status: test & clear setup status (execute without 438 * hw_test_and_clear_setup_status: test & clear setup status (execute without
431 * interruption) 439 * interruption)
432 * @n: bit number (endpoint) 440 * @n: bit number (endpoint)
@@ -450,10 +458,6 @@ static int hw_ep_prime(int num, int dir, int is_ctrl)
450{ 458{
451 int n = hw_ep_bit(num, dir); 459 int n = hw_ep_bit(num, dir);
452 460
453 /* the caller should flush first */
454 if (hw_ep_is_primed(num, dir))
455 return -EBUSY;
456
457 if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) 461 if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num)))
458 return -EAGAIN; 462 return -EAGAIN;
459 463
@@ -1186,16 +1190,17 @@ static ssize_t show_qheads(struct device *dev, struct device_attribute *attr,
1186 } 1190 }
1187 1191
1188 spin_lock_irqsave(udc->lock, flags); 1192 spin_lock_irqsave(udc->lock, flags);
1189 for (i = 0; i < hw_ep_max; i++) { 1193 for (i = 0; i < hw_ep_max/2; i++) {
1190 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; 1194 struct ci13xxx_ep *mEpRx = &udc->ci13xxx_ep[i];
1195 struct ci13xxx_ep *mEpTx = &udc->ci13xxx_ep[i + hw_ep_max/2];
1191 n += scnprintf(buf + n, PAGE_SIZE - n, 1196 n += scnprintf(buf + n, PAGE_SIZE - n,
1192 "EP=%02i: RX=%08X TX=%08X\n", 1197 "EP=%02i: RX=%08X TX=%08X\n",
1193 i, (u32)mEp->qh[RX].dma, (u32)mEp->qh[TX].dma); 1198 i, (u32)mEpRx->qh.dma, (u32)mEpTx->qh.dma);
1194 for (j = 0; j < (sizeof(struct ci13xxx_qh)/sizeof(u32)); j++) { 1199 for (j = 0; j < (sizeof(struct ci13xxx_qh)/sizeof(u32)); j++) {
1195 n += scnprintf(buf + n, PAGE_SIZE - n, 1200 n += scnprintf(buf + n, PAGE_SIZE - n,
1196 " %04X: %08X %08X\n", j, 1201 " %04X: %08X %08X\n", j,
1197 *((u32 *)mEp->qh[RX].ptr + j), 1202 *((u32 *)mEpRx->qh.ptr + j),
1198 *((u32 *)mEp->qh[TX].ptr + j)); 1203 *((u32 *)mEpTx->qh.ptr + j));
1199 } 1204 }
1200 } 1205 }
1201 spin_unlock_irqrestore(udc->lock, flags); 1206 spin_unlock_irqrestore(udc->lock, flags);
@@ -1282,7 +1287,7 @@ static ssize_t show_requests(struct device *dev, struct device_attribute *attr,
1282 unsigned long flags; 1287 unsigned long flags;
1283 struct list_head *ptr = NULL; 1288 struct list_head *ptr = NULL;
1284 struct ci13xxx_req *req = NULL; 1289 struct ci13xxx_req *req = NULL;
1285 unsigned i, j, k, n = 0, qSize = sizeof(struct ci13xxx_td)/sizeof(u32); 1290 unsigned i, j, n = 0, qSize = sizeof(struct ci13xxx_td)/sizeof(u32);
1286 1291
1287 dbg_trace("[%s] %p\n", __func__, buf); 1292 dbg_trace("[%s] %p\n", __func__, buf);
1288 if (attr == NULL || buf == NULL) { 1293 if (attr == NULL || buf == NULL) {
@@ -1292,22 +1297,20 @@ static ssize_t show_requests(struct device *dev, struct device_attribute *attr,
1292 1297
1293 spin_lock_irqsave(udc->lock, flags); 1298 spin_lock_irqsave(udc->lock, flags);
1294 for (i = 0; i < hw_ep_max; i++) 1299 for (i = 0; i < hw_ep_max; i++)
1295 for (k = RX; k <= TX; k++) 1300 list_for_each(ptr, &udc->ci13xxx_ep[i].qh.queue)
1296 list_for_each(ptr, &udc->ci13xxx_ep[i].qh[k].queue) 1301 {
1297 { 1302 req = list_entry(ptr, struct ci13xxx_req, queue);
1298 req = list_entry(ptr,
1299 struct ci13xxx_req, queue);
1300 1303
1304 n += scnprintf(buf + n, PAGE_SIZE - n,
1305 "EP=%02i: TD=%08X %s\n",
1306 i % hw_ep_max/2, (u32)req->dma,
1307 ((i < hw_ep_max/2) ? "RX" : "TX"));
1308
1309 for (j = 0; j < qSize; j++)
1301 n += scnprintf(buf + n, PAGE_SIZE - n, 1310 n += scnprintf(buf + n, PAGE_SIZE - n,
1302 "EP=%02i: TD=%08X %s\n", 1311 " %04X: %08X\n", j,
1303 i, (u32)req->dma, 1312 *((u32 *)req->ptr + j));
1304 ((k == RX) ? "RX" : "TX")); 1313 }
1305
1306 for (j = 0; j < qSize; j++)
1307 n += scnprintf(buf + n, PAGE_SIZE - n,
1308 " %04X: %08X\n", j,
1309 *((u32 *)req->ptr + j));
1310 }
1311 spin_unlock_irqrestore(udc->lock, flags); 1314 spin_unlock_irqrestore(udc->lock, flags);
1312 1315
1313 return n; 1316 return n;
@@ -1413,6 +1416,8 @@ static inline u8 _usb_addr(struct ci13xxx_ep *ep)
1413static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) 1416static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1414{ 1417{
1415 unsigned i; 1418 unsigned i;
1419 int ret = 0;
1420 unsigned length = mReq->req.length;
1416 1421
1417 trace("%p, %p", mEp, mReq); 1422 trace("%p, %p", mEp, mReq);
1418 1423
@@ -1420,53 +1425,91 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1420 if (mReq->req.status == -EALREADY) 1425 if (mReq->req.status == -EALREADY)
1421 return -EALREADY; 1426 return -EALREADY;
1422 1427
1423 if (hw_ep_is_primed(mEp->num, mEp->dir))
1424 return -EBUSY;
1425
1426 mReq->req.status = -EALREADY; 1428 mReq->req.status = -EALREADY;
1427 1429 if (length && !mReq->req.dma) {
1428 if (mReq->req.length && !mReq->req.dma) {
1429 mReq->req.dma = \ 1430 mReq->req.dma = \
1430 dma_map_single(mEp->device, mReq->req.buf, 1431 dma_map_single(mEp->device, mReq->req.buf,
1431 mReq->req.length, mEp->dir ? 1432 length, mEp->dir ? DMA_TO_DEVICE :
1432 DMA_TO_DEVICE : DMA_FROM_DEVICE); 1433 DMA_FROM_DEVICE);
1433 if (mReq->req.dma == 0) 1434 if (mReq->req.dma == 0)
1434 return -ENOMEM; 1435 return -ENOMEM;
1435 1436
1436 mReq->map = 1; 1437 mReq->map = 1;
1437 } 1438 }
1438 1439
1440 if (mReq->req.zero && length && (length % mEp->ep.maxpacket == 0)) {
1441 mReq->zptr = dma_pool_alloc(mEp->td_pool, GFP_ATOMIC,
1442 &mReq->zdma);
1443 if (mReq->zptr == NULL) {
1444 if (mReq->map) {
1445 dma_unmap_single(mEp->device, mReq->req.dma,
1446 length, mEp->dir ? DMA_TO_DEVICE :
1447 DMA_FROM_DEVICE);
1448 mReq->req.dma = 0;
1449 mReq->map = 0;
1450 }
1451 return -ENOMEM;
1452 }
1453 memset(mReq->zptr, 0, sizeof(*mReq->zptr));
1454 mReq->zptr->next = TD_TERMINATE;
1455 mReq->zptr->token = TD_STATUS_ACTIVE;
1456 if (!mReq->req.no_interrupt)
1457 mReq->zptr->token |= TD_IOC;
1458 }
1439 /* 1459 /*
1440 * TD configuration 1460 * TD configuration
1441 * TODO - handle requests which spawns into several TDs 1461 * TODO - handle requests which spawns into several TDs
1442 */ 1462 */
1443 memset(mReq->ptr, 0, sizeof(*mReq->ptr)); 1463 memset(mReq->ptr, 0, sizeof(*mReq->ptr));
1444 mReq->ptr->next |= TD_TERMINATE; 1464 mReq->ptr->token = length << ffs_nr(TD_TOTAL_BYTES);
1445 mReq->ptr->token = mReq->req.length << ffs_nr(TD_TOTAL_BYTES);
1446 mReq->ptr->token &= TD_TOTAL_BYTES; 1465 mReq->ptr->token &= TD_TOTAL_BYTES;
1447 mReq->ptr->token |= TD_IOC;
1448 mReq->ptr->token |= TD_STATUS_ACTIVE; 1466 mReq->ptr->token |= TD_STATUS_ACTIVE;
1467 if (mReq->zptr) {
1468 mReq->ptr->next = mReq->zdma;
1469 } else {
1470 mReq->ptr->next = TD_TERMINATE;
1471 if (!mReq->req.no_interrupt)
1472 mReq->ptr->token |= TD_IOC;
1473 }
1449 mReq->ptr->page[0] = mReq->req.dma; 1474 mReq->ptr->page[0] = mReq->req.dma;
1450 for (i = 1; i < 5; i++) 1475 for (i = 1; i < 5; i++)
1451 mReq->ptr->page[i] = 1476 mReq->ptr->page[i] =
1452 (mReq->req.dma + i * PAGE_SIZE) & ~TD_RESERVED_MASK; 1477 (mReq->req.dma + i * CI13XXX_PAGE_SIZE) & ~TD_RESERVED_MASK;
1453 1478
1454 /* 1479 if (!list_empty(&mEp->qh.queue)) {
1455 * QH configuration 1480 struct ci13xxx_req *mReqPrev;
1456 * At this point it's guaranteed exclusive access to qhead 1481 int n = hw_ep_bit(mEp->num, mEp->dir);
1457 * (endpt is not primed) so it's no need to use tripwire 1482 int tmp_stat;
1458 */ 1483
1459 mEp->qh[mEp->dir].ptr->td.next = mReq->dma; /* TERMINATE = 0 */ 1484 mReqPrev = list_entry(mEp->qh.queue.prev,
1460 mEp->qh[mEp->dir].ptr->td.token &= ~TD_STATUS; /* clear status */ 1485 struct ci13xxx_req, queue);
1461 if (mReq->req.zero == 0) 1486 if (mReqPrev->zptr)
1462 mEp->qh[mEp->dir].ptr->cap |= QH_ZLT; 1487 mReqPrev->zptr->next = mReq->dma & TD_ADDR_MASK;
1463 else 1488 else
1464 mEp->qh[mEp->dir].ptr->cap &= ~QH_ZLT; 1489 mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK;
1490 wmb();
1491 if (hw_cread(CAP_ENDPTPRIME, BIT(n)))
1492 goto done;
1493 do {
1494 hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW);
1495 tmp_stat = hw_cread(CAP_ENDPTSTAT, BIT(n));
1496 } while (!hw_cread(CAP_USBCMD, USBCMD_ATDTW));
1497 hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, 0);
1498 if (tmp_stat)
1499 goto done;
1500 }
1501
1502 /* QH configuration */
1503 mEp->qh.ptr->td.next = mReq->dma; /* TERMINATE = 0 */
1504 mEp->qh.ptr->td.token &= ~TD_STATUS; /* clear status */
1505 mEp->qh.ptr->cap |= QH_ZLT;
1465 1506
1466 wmb(); /* synchronize before ep prime */ 1507 wmb(); /* synchronize before ep prime */
1467 1508
1468 return hw_ep_prime(mEp->num, mEp->dir, 1509 ret = hw_ep_prime(mEp->num, mEp->dir,
1469 mEp->type == USB_ENDPOINT_XFER_CONTROL); 1510 mEp->type == USB_ENDPOINT_XFER_CONTROL);
1511done:
1512 return ret;
1470} 1513}
1471 1514
1472/** 1515/**
@@ -1483,8 +1526,15 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1483 if (mReq->req.status != -EALREADY) 1526 if (mReq->req.status != -EALREADY)
1484 return -EINVAL; 1527 return -EINVAL;
1485 1528
1486 if (hw_ep_is_primed(mEp->num, mEp->dir)) 1529 if ((TD_STATUS_ACTIVE & mReq->ptr->token) != 0)
1487 hw_ep_flush(mEp->num, mEp->dir); 1530 return -EBUSY;
1531
1532 if (mReq->zptr) {
1533 if ((TD_STATUS_ACTIVE & mReq->zptr->token) != 0)
1534 return -EBUSY;
1535 dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma);
1536 mReq->zptr = NULL;
1537 }
1488 1538
1489 mReq->req.status = 0; 1539 mReq->req.status = 0;
1490 1540
@@ -1496,9 +1546,7 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1496 } 1546 }
1497 1547
1498 mReq->req.status = mReq->ptr->token & TD_STATUS; 1548 mReq->req.status = mReq->ptr->token & TD_STATUS;
1499 if ((TD_STATUS_ACTIVE & mReq->req.status) != 0) 1549 if ((TD_STATUS_HALTED & mReq->req.status) != 0)
1500 mReq->req.status = -ECONNRESET;
1501 else if ((TD_STATUS_HALTED & mReq->req.status) != 0)
1502 mReq->req.status = -1; 1550 mReq->req.status = -1;
1503 else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0) 1551 else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0)
1504 mReq->req.status = -1; 1552 mReq->req.status = -1;
@@ -1531,16 +1579,16 @@ __acquires(mEp->lock)
1531 1579
1532 hw_ep_flush(mEp->num, mEp->dir); 1580 hw_ep_flush(mEp->num, mEp->dir);
1533 1581
1534 while (!list_empty(&mEp->qh[mEp->dir].queue)) { 1582 while (!list_empty(&mEp->qh.queue)) {
1535 1583
1536 /* pop oldest request */ 1584 /* pop oldest request */
1537 struct ci13xxx_req *mReq = \ 1585 struct ci13xxx_req *mReq = \
1538 list_entry(mEp->qh[mEp->dir].queue.next, 1586 list_entry(mEp->qh.queue.next,
1539 struct ci13xxx_req, queue); 1587 struct ci13xxx_req, queue);
1540 list_del_init(&mReq->queue); 1588 list_del_init(&mReq->queue);
1541 mReq->req.status = -ESHUTDOWN; 1589 mReq->req.status = -ESHUTDOWN;
1542 1590
1543 if (!mReq->req.no_interrupt && mReq->req.complete != NULL) { 1591 if (mReq->req.complete != NULL) {
1544 spin_unlock(mEp->lock); 1592 spin_unlock(mEp->lock);
1545 mReq->req.complete(&mEp->ep, &mReq->req); 1593 mReq->req.complete(&mEp->ep, &mReq->req);
1546 spin_lock(mEp->lock); 1594 spin_lock(mEp->lock);
@@ -1557,26 +1605,28 @@ __acquires(mEp->lock)
1557 * Caller must hold lock 1605 * Caller must hold lock
1558 */ 1606 */
1559static int _gadget_stop_activity(struct usb_gadget *gadget) 1607static int _gadget_stop_activity(struct usb_gadget *gadget)
1560__releases(udc->lock)
1561__acquires(udc->lock)
1562{ 1608{
1563 struct usb_ep *ep; 1609 struct usb_ep *ep;
1564 struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); 1610 struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget);
1565 struct ci13xxx_ep *mEp = container_of(gadget->ep0, 1611 unsigned long flags;
1566 struct ci13xxx_ep, ep);
1567 1612
1568 trace("%p", gadget); 1613 trace("%p", gadget);
1569 1614
1570 if (gadget == NULL) 1615 if (gadget == NULL)
1571 return -EINVAL; 1616 return -EINVAL;
1572 1617
1573 spin_unlock(udc->lock); 1618 spin_lock_irqsave(udc->lock, flags);
1619 udc->gadget.speed = USB_SPEED_UNKNOWN;
1620 udc->remote_wakeup = 0;
1621 udc->suspended = 0;
1622 spin_unlock_irqrestore(udc->lock, flags);
1574 1623
1575 /* flush all endpoints */ 1624 /* flush all endpoints */
1576 gadget_for_each_ep(ep, gadget) { 1625 gadget_for_each_ep(ep, gadget) {
1577 usb_ep_fifo_flush(ep); 1626 usb_ep_fifo_flush(ep);
1578 } 1627 }
1579 usb_ep_fifo_flush(gadget->ep0); 1628 usb_ep_fifo_flush(&udc->ep0out.ep);
1629 usb_ep_fifo_flush(&udc->ep0in.ep);
1580 1630
1581 udc->driver->disconnect(gadget); 1631 udc->driver->disconnect(gadget);
1582 1632
@@ -1584,15 +1634,12 @@ __acquires(udc->lock)
1584 gadget_for_each_ep(ep, gadget) { 1634 gadget_for_each_ep(ep, gadget) {
1585 usb_ep_disable(ep); 1635 usb_ep_disable(ep);
1586 } 1636 }
1587 usb_ep_disable(gadget->ep0);
1588 1637
1589 if (mEp->status != NULL) { 1638 if (udc->status != NULL) {
1590 usb_ep_free_request(gadget->ep0, mEp->status); 1639 usb_ep_free_request(&udc->ep0in.ep, udc->status);
1591 mEp->status = NULL; 1640 udc->status = NULL;
1592 } 1641 }
1593 1642
1594 spin_lock(udc->lock);
1595
1596 return 0; 1643 return 0;
1597} 1644}
1598 1645
@@ -1609,7 +1656,6 @@ static void isr_reset_handler(struct ci13xxx *udc)
1609__releases(udc->lock) 1656__releases(udc->lock)
1610__acquires(udc->lock) 1657__acquires(udc->lock)
1611{ 1658{
1612 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[0];
1613 int retval; 1659 int retval;
1614 1660
1615 trace("%p", udc); 1661 trace("%p", udc);
@@ -1621,6 +1667,7 @@ __acquires(udc->lock)
1621 1667
1622 dbg_event(0xFF, "BUS RST", 0); 1668 dbg_event(0xFF, "BUS RST", 0);
1623 1669
1670 spin_unlock(udc->lock);
1624 retval = _gadget_stop_activity(&udc->gadget); 1671 retval = _gadget_stop_activity(&udc->gadget);
1625 if (retval) 1672 if (retval)
1626 goto done; 1673 goto done;
@@ -1629,15 +1676,10 @@ __acquires(udc->lock)
1629 if (retval) 1676 if (retval)
1630 goto done; 1677 goto done;
1631 1678
1632 spin_unlock(udc->lock); 1679 udc->status = usb_ep_alloc_request(&udc->ep0in.ep, GFP_ATOMIC);
1633 retval = usb_ep_enable(&mEp->ep, &ctrl_endpt_desc); 1680 if (udc->status == NULL)
1634 if (!retval) { 1681 retval = -ENOMEM;
1635 mEp->status = usb_ep_alloc_request(&mEp->ep, GFP_KERNEL); 1682
1636 if (mEp->status == NULL) {
1637 usb_ep_disable(&mEp->ep);
1638 retval = -ENOMEM;
1639 }
1640 }
1641 spin_lock(udc->lock); 1683 spin_lock(udc->lock);
1642 1684
1643 done: 1685 done:
@@ -1667,16 +1709,17 @@ static void isr_get_status_complete(struct usb_ep *ep, struct usb_request *req)
1667 1709
1668/** 1710/**
1669 * isr_get_status_response: get_status request response 1711 * isr_get_status_response: get_status request response
1670 * @ep: endpoint 1712 * @udc: udc struct
1671 * @setup: setup request packet 1713 * @setup: setup request packet
1672 * 1714 *
1673 * This function returns an error code 1715 * This function returns an error code
1674 */ 1716 */
1675static int isr_get_status_response(struct ci13xxx_ep *mEp, 1717static int isr_get_status_response(struct ci13xxx *udc,
1676 struct usb_ctrlrequest *setup) 1718 struct usb_ctrlrequest *setup)
1677__releases(mEp->lock) 1719__releases(mEp->lock)
1678__acquires(mEp->lock) 1720__acquires(mEp->lock)
1679{ 1721{
1722 struct ci13xxx_ep *mEp = &udc->ep0in;
1680 struct usb_request *req = NULL; 1723 struct usb_request *req = NULL;
1681 gfp_t gfp_flags = GFP_ATOMIC; 1724 gfp_t gfp_flags = GFP_ATOMIC;
1682 int dir, num, retval; 1725 int dir, num, retval;
@@ -1701,7 +1744,8 @@ __acquires(mEp->lock)
1701 } 1744 }
1702 1745
1703 if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { 1746 if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) {
1704 /* TODO: D1 - Remote Wakeup; D0 - Self Powered */ 1747 /* Assume that device is bus powered for now. */
1748 *((u16 *)req->buf) = _udc->remote_wakeup << 1;
1705 retval = 0; 1749 retval = 0;
1706 } else if ((setup->bRequestType & USB_RECIP_MASK) \ 1750 } else if ((setup->bRequestType & USB_RECIP_MASK) \
1707 == USB_RECIP_ENDPOINT) { 1751 == USB_RECIP_ENDPOINT) {
@@ -1730,28 +1774,48 @@ __acquires(mEp->lock)
1730} 1774}
1731 1775
1732/** 1776/**
1777 * isr_setup_status_complete: setup_status request complete function
1778 * @ep: endpoint
1779 * @req: request handled
1780 *
1781 * Caller must release lock. Put the port in test mode if test mode
1782 * feature is selected.
1783 */
1784static void
1785isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req)
1786{
1787 struct ci13xxx *udc = req->context;
1788 unsigned long flags;
1789
1790 trace("%p, %p", ep, req);
1791
1792 spin_lock_irqsave(udc->lock, flags);
1793 if (udc->test_mode)
1794 hw_port_test_set(udc->test_mode);
1795 spin_unlock_irqrestore(udc->lock, flags);
1796}
1797
1798/**
1733 * isr_setup_status_phase: queues the status phase of a setup transation 1799 * isr_setup_status_phase: queues the status phase of a setup transation
1734 * @mEp: endpoint 1800 * @udc: udc struct
1735 * 1801 *
1736 * This function returns an error code 1802 * This function returns an error code
1737 */ 1803 */
1738static int isr_setup_status_phase(struct ci13xxx_ep *mEp) 1804static int isr_setup_status_phase(struct ci13xxx *udc)
1739__releases(mEp->lock) 1805__releases(mEp->lock)
1740__acquires(mEp->lock) 1806__acquires(mEp->lock)
1741{ 1807{
1742 int retval; 1808 int retval;
1809 struct ci13xxx_ep *mEp;
1743 1810
1744 trace("%p", mEp); 1811 trace("%p", udc);
1745
1746 /* mEp is always valid & configured */
1747
1748 if (mEp->type == USB_ENDPOINT_XFER_CONTROL)
1749 mEp->dir = (mEp->dir == TX) ? RX : TX;
1750 1812
1751 mEp->status->no_interrupt = 1; 1813 mEp = (udc->ep0_dir == TX) ? &udc->ep0out : &udc->ep0in;
1814 udc->status->context = udc;
1815 udc->status->complete = isr_setup_status_complete;
1752 1816
1753 spin_unlock(mEp->lock); 1817 spin_unlock(mEp->lock);
1754 retval = usb_ep_queue(&mEp->ep, mEp->status, GFP_ATOMIC); 1818 retval = usb_ep_queue(&mEp->ep, udc->status, GFP_ATOMIC);
1755 spin_lock(mEp->lock); 1819 spin_lock(mEp->lock);
1756 1820
1757 return retval; 1821 return retval;
@@ -1768,40 +1832,37 @@ static int isr_tr_complete_low(struct ci13xxx_ep *mEp)
1768__releases(mEp->lock) 1832__releases(mEp->lock)
1769__acquires(mEp->lock) 1833__acquires(mEp->lock)
1770{ 1834{
1771 struct ci13xxx_req *mReq; 1835 struct ci13xxx_req *mReq, *mReqTemp;
1772 int retval; 1836 struct ci13xxx_ep *mEpTemp = mEp;
1837 int uninitialized_var(retval);
1773 1838
1774 trace("%p", mEp); 1839 trace("%p", mEp);
1775 1840
1776 if (list_empty(&mEp->qh[mEp->dir].queue)) 1841 if (list_empty(&mEp->qh.queue))
1777 return -EINVAL; 1842 return -EINVAL;
1778 1843
1779 /* pop oldest request */ 1844 list_for_each_entry_safe(mReq, mReqTemp, &mEp->qh.queue,
1780 mReq = list_entry(mEp->qh[mEp->dir].queue.next, 1845 queue) {
1781 struct ci13xxx_req, queue); 1846 retval = _hardware_dequeue(mEp, mReq);
1782 list_del_init(&mReq->queue); 1847 if (retval < 0)
1783 1848 break;
1784 retval = _hardware_dequeue(mEp, mReq); 1849 list_del_init(&mReq->queue);
1785 if (retval < 0) { 1850 dbg_done(_usb_addr(mEp), mReq->ptr->token, retval);
1786 dbg_event(_usb_addr(mEp), "DONE", retval); 1851 if (mReq->req.complete != NULL) {
1787 goto done; 1852 spin_unlock(mEp->lock);
1788 } 1853 if ((mEp->type == USB_ENDPOINT_XFER_CONTROL) &&
1789 1854 mReq->req.length)
1790 dbg_done(_usb_addr(mEp), mReq->ptr->token, retval); 1855 mEpTemp = &_udc->ep0in;
1791 1856 mReq->req.complete(&mEpTemp->ep, &mReq->req);
1792 if (!mReq->req.no_interrupt && mReq->req.complete != NULL) { 1857 spin_lock(mEp->lock);
1793 spin_unlock(mEp->lock); 1858 }
1794 mReq->req.complete(&mEp->ep, &mReq->req);
1795 spin_lock(mEp->lock);
1796 } 1859 }
1797 1860
1798 if (!list_empty(&mEp->qh[mEp->dir].queue)) { 1861 if (retval == -EBUSY)
1799 mReq = list_entry(mEp->qh[mEp->dir].queue.next, 1862 retval = 0;
1800 struct ci13xxx_req, queue); 1863 if (retval < 0)
1801 _hardware_enqueue(mEp, mReq); 1864 dbg_event(_usb_addr(mEp), "DONE", retval);
1802 }
1803 1865
1804 done:
1805 return retval; 1866 return retval;
1806} 1867}
1807 1868
@@ -1816,6 +1877,7 @@ __releases(udc->lock)
1816__acquires(udc->lock) 1877__acquires(udc->lock)
1817{ 1878{
1818 unsigned i; 1879 unsigned i;
1880 u8 tmode = 0;
1819 1881
1820 trace("%p", udc); 1882 trace("%p", udc);
1821 1883
@@ -1826,19 +1888,17 @@ __acquires(udc->lock)
1826 1888
1827 for (i = 0; i < hw_ep_max; i++) { 1889 for (i = 0; i < hw_ep_max; i++) {
1828 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; 1890 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i];
1829 int type, num, err = -EINVAL; 1891 int type, num, dir, err = -EINVAL;
1830 struct usb_ctrlrequest req; 1892 struct usb_ctrlrequest req;
1831 1893
1832
1833 if (mEp->desc == NULL) 1894 if (mEp->desc == NULL)
1834 continue; /* not configured */ 1895 continue; /* not configured */
1835 1896
1836 if ((mEp->dir == RX && hw_test_and_clear_complete(i)) || 1897 if (hw_test_and_clear_complete(i)) {
1837 (mEp->dir == TX && hw_test_and_clear_complete(i + 16))) {
1838 err = isr_tr_complete_low(mEp); 1898 err = isr_tr_complete_low(mEp);
1839 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) { 1899 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) {
1840 if (err > 0) /* needs status phase */ 1900 if (err > 0) /* needs status phase */
1841 err = isr_setup_status_phase(mEp); 1901 err = isr_setup_status_phase(udc);
1842 if (err < 0) { 1902 if (err < 0) {
1843 dbg_event(_usb_addr(mEp), 1903 dbg_event(_usb_addr(mEp),
1844 "ERROR", err); 1904 "ERROR", err);
@@ -1859,36 +1919,56 @@ __acquires(udc->lock)
1859 continue; 1919 continue;
1860 } 1920 }
1861 1921
1922 /*
1923 * Flush data and handshake transactions of previous
1924 * setup packet.
1925 */
1926 _ep_nuke(&udc->ep0out);
1927 _ep_nuke(&udc->ep0in);
1928
1862 /* read_setup_packet */ 1929 /* read_setup_packet */
1863 do { 1930 do {
1864 hw_test_and_set_setup_guard(); 1931 hw_test_and_set_setup_guard();
1865 memcpy(&req, &mEp->qh[RX].ptr->setup, sizeof(req)); 1932 memcpy(&req, &mEp->qh.ptr->setup, sizeof(req));
1866 } while (!hw_test_and_clear_setup_guard()); 1933 } while (!hw_test_and_clear_setup_guard());
1867 1934
1868 type = req.bRequestType; 1935 type = req.bRequestType;
1869 1936
1870 mEp->dir = (type & USB_DIR_IN) ? TX : RX; 1937 udc->ep0_dir = (type & USB_DIR_IN) ? TX : RX;
1871 1938
1872 dbg_setup(_usb_addr(mEp), &req); 1939 dbg_setup(_usb_addr(mEp), &req);
1873 1940
1874 switch (req.bRequest) { 1941 switch (req.bRequest) {
1875 case USB_REQ_CLEAR_FEATURE: 1942 case USB_REQ_CLEAR_FEATURE:
1876 if (type != (USB_DIR_OUT|USB_RECIP_ENDPOINT) && 1943 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) &&
1877 le16_to_cpu(req.wValue) != USB_ENDPOINT_HALT) 1944 le16_to_cpu(req.wValue) ==
1878 goto delegate; 1945 USB_ENDPOINT_HALT) {
1879 if (req.wLength != 0) 1946 if (req.wLength != 0)
1880 break; 1947 break;
1881 num = le16_to_cpu(req.wIndex); 1948 num = le16_to_cpu(req.wIndex);
1882 num &= USB_ENDPOINT_NUMBER_MASK; 1949 dir = num & USB_ENDPOINT_DIR_MASK;
1883 if (!udc->ci13xxx_ep[num].wedge) { 1950 num &= USB_ENDPOINT_NUMBER_MASK;
1884 spin_unlock(udc->lock); 1951 if (dir) /* TX */
1885 err = usb_ep_clear_halt( 1952 num += hw_ep_max/2;
1886 &udc->ci13xxx_ep[num].ep); 1953 if (!udc->ci13xxx_ep[num].wedge) {
1887 spin_lock(udc->lock); 1954 spin_unlock(udc->lock);
1888 if (err) 1955 err = usb_ep_clear_halt(
1956 &udc->ci13xxx_ep[num].ep);
1957 spin_lock(udc->lock);
1958 if (err)
1959 break;
1960 }
1961 err = isr_setup_status_phase(udc);
1962 } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE) &&
1963 le16_to_cpu(req.wValue) ==
1964 USB_DEVICE_REMOTE_WAKEUP) {
1965 if (req.wLength != 0)
1889 break; 1966 break;
1967 udc->remote_wakeup = 0;
1968 err = isr_setup_status_phase(udc);
1969 } else {
1970 goto delegate;
1890 } 1971 }
1891 err = isr_setup_status_phase(mEp);
1892 break; 1972 break;
1893 case USB_REQ_GET_STATUS: 1973 case USB_REQ_GET_STATUS:
1894 if (type != (USB_DIR_IN|USB_RECIP_DEVICE) && 1974 if (type != (USB_DIR_IN|USB_RECIP_DEVICE) &&
@@ -1898,7 +1978,7 @@ __acquires(udc->lock)
1898 if (le16_to_cpu(req.wLength) != 2 || 1978 if (le16_to_cpu(req.wLength) != 2 ||
1899 le16_to_cpu(req.wValue) != 0) 1979 le16_to_cpu(req.wValue) != 0)
1900 break; 1980 break;
1901 err = isr_get_status_response(mEp, &req); 1981 err = isr_get_status_response(udc, &req);
1902 break; 1982 break;
1903 case USB_REQ_SET_ADDRESS: 1983 case USB_REQ_SET_ADDRESS:
1904 if (type != (USB_DIR_OUT|USB_RECIP_DEVICE)) 1984 if (type != (USB_DIR_OUT|USB_RECIP_DEVICE))
@@ -1909,28 +1989,59 @@ __acquires(udc->lock)
1909 err = hw_usb_set_address((u8)le16_to_cpu(req.wValue)); 1989 err = hw_usb_set_address((u8)le16_to_cpu(req.wValue));
1910 if (err) 1990 if (err)
1911 break; 1991 break;
1912 err = isr_setup_status_phase(mEp); 1992 err = isr_setup_status_phase(udc);
1913 break; 1993 break;
1914 case USB_REQ_SET_FEATURE: 1994 case USB_REQ_SET_FEATURE:
1915 if (type != (USB_DIR_OUT|USB_RECIP_ENDPOINT) && 1995 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) &&
1916 le16_to_cpu(req.wValue) != USB_ENDPOINT_HALT) 1996 le16_to_cpu(req.wValue) ==
1917 goto delegate; 1997 USB_ENDPOINT_HALT) {
1918 if (req.wLength != 0) 1998 if (req.wLength != 0)
1919 break; 1999 break;
1920 num = le16_to_cpu(req.wIndex); 2000 num = le16_to_cpu(req.wIndex);
1921 num &= USB_ENDPOINT_NUMBER_MASK; 2001 dir = num & USB_ENDPOINT_DIR_MASK;
2002 num &= USB_ENDPOINT_NUMBER_MASK;
2003 if (dir) /* TX */
2004 num += hw_ep_max/2;
1922 2005
1923 spin_unlock(udc->lock); 2006 spin_unlock(udc->lock);
1924 err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep); 2007 err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep);
1925 spin_lock(udc->lock); 2008 spin_lock(udc->lock);
1926 if (err) 2009 if (!err)
1927 break; 2010 isr_setup_status_phase(udc);
1928 err = isr_setup_status_phase(mEp); 2011 } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE)) {
2012 if (req.wLength != 0)
2013 break;
2014 switch (le16_to_cpu(req.wValue)) {
2015 case USB_DEVICE_REMOTE_WAKEUP:
2016 udc->remote_wakeup = 1;
2017 err = isr_setup_status_phase(udc);
2018 break;
2019 case USB_DEVICE_TEST_MODE:
2020 tmode = le16_to_cpu(req.wIndex) >> 8;
2021 switch (tmode) {
2022 case TEST_J:
2023 case TEST_K:
2024 case TEST_SE0_NAK:
2025 case TEST_PACKET:
2026 case TEST_FORCE_EN:
2027 udc->test_mode = tmode;
2028 err = isr_setup_status_phase(
2029 udc);
2030 break;
2031 default:
2032 break;
2033 }
2034 default:
2035 goto delegate;
2036 }
2037 } else {
2038 goto delegate;
2039 }
1929 break; 2040 break;
1930 default: 2041 default:
1931delegate: 2042delegate:
1932 if (req.wLength == 0) /* no data phase */ 2043 if (req.wLength == 0) /* no data phase */
1933 mEp->dir = TX; 2044 udc->ep0_dir = TX;
1934 2045
1935 spin_unlock(udc->lock); 2046 spin_unlock(udc->lock);
1936 err = udc->driver->setup(&udc->gadget, &req); 2047 err = udc->driver->setup(&udc->gadget, &req);
@@ -1961,7 +2072,7 @@ static int ep_enable(struct usb_ep *ep,
1961 const struct usb_endpoint_descriptor *desc) 2072 const struct usb_endpoint_descriptor *desc)
1962{ 2073{
1963 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); 2074 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep);
1964 int direction, retval = 0; 2075 int retval = 0;
1965 unsigned long flags; 2076 unsigned long flags;
1966 2077
1967 trace("%p, %p", ep, desc); 2078 trace("%p, %p", ep, desc);
@@ -1975,7 +2086,7 @@ static int ep_enable(struct usb_ep *ep,
1975 2086
1976 mEp->desc = desc; 2087 mEp->desc = desc;
1977 2088
1978 if (!list_empty(&mEp->qh[mEp->dir].queue)) 2089 if (!list_empty(&mEp->qh.queue))
1979 warn("enabling a non-empty endpoint!"); 2090 warn("enabling a non-empty endpoint!");
1980 2091
1981 mEp->dir = usb_endpoint_dir_in(desc) ? TX : RX; 2092 mEp->dir = usb_endpoint_dir_in(desc) ? TX : RX;
@@ -1984,30 +2095,28 @@ static int ep_enable(struct usb_ep *ep,
1984 2095
1985 mEp->ep.maxpacket = __constant_le16_to_cpu(desc->wMaxPacketSize); 2096 mEp->ep.maxpacket = __constant_le16_to_cpu(desc->wMaxPacketSize);
1986 2097
1987 direction = mEp->dir; 2098 dbg_event(_usb_addr(mEp), "ENABLE", 0);
1988 do {
1989 dbg_event(_usb_addr(mEp), "ENABLE", 0);
1990 2099
1991 mEp->qh[mEp->dir].ptr->cap = 0; 2100 mEp->qh.ptr->cap = 0;
1992 2101
1993 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) 2102 if (mEp->type == USB_ENDPOINT_XFER_CONTROL)
1994 mEp->qh[mEp->dir].ptr->cap |= QH_IOS; 2103 mEp->qh.ptr->cap |= QH_IOS;
1995 else if (mEp->type == USB_ENDPOINT_XFER_ISOC) 2104 else if (mEp->type == USB_ENDPOINT_XFER_ISOC)
1996 mEp->qh[mEp->dir].ptr->cap &= ~QH_MULT; 2105 mEp->qh.ptr->cap &= ~QH_MULT;
1997 else 2106 else
1998 mEp->qh[mEp->dir].ptr->cap &= ~QH_ZLT; 2107 mEp->qh.ptr->cap &= ~QH_ZLT;
1999 2108
2000 mEp->qh[mEp->dir].ptr->cap |= 2109 mEp->qh.ptr->cap |=
2001 (mEp->ep.maxpacket << ffs_nr(QH_MAX_PKT)) & QH_MAX_PKT; 2110 (mEp->ep.maxpacket << ffs_nr(QH_MAX_PKT)) & QH_MAX_PKT;
2002 mEp->qh[mEp->dir].ptr->td.next |= TD_TERMINATE; /* needed? */ 2111 mEp->qh.ptr->td.next |= TD_TERMINATE; /* needed? */
2003 2112
2113 /*
2114 * Enable endpoints in the HW other than ep0 as ep0
2115 * is always enabled
2116 */
2117 if (mEp->num)
2004 retval |= hw_ep_enable(mEp->num, mEp->dir, mEp->type); 2118 retval |= hw_ep_enable(mEp->num, mEp->dir, mEp->type);
2005 2119
2006 if (mEp->type == USB_ENDPOINT_XFER_CONTROL)
2007 mEp->dir = (mEp->dir == TX) ? RX : TX;
2008
2009 } while (mEp->dir != direction);
2010
2011 spin_unlock_irqrestore(mEp->lock, flags); 2120 spin_unlock_irqrestore(mEp->lock, flags);
2012 return retval; 2121 return retval;
2013} 2122}
@@ -2061,7 +2170,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
2061{ 2170{
2062 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); 2171 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep);
2063 struct ci13xxx_req *mReq = NULL; 2172 struct ci13xxx_req *mReq = NULL;
2064 unsigned long flags;
2065 2173
2066 trace("%p, %i", ep, gfp_flags); 2174 trace("%p, %i", ep, gfp_flags);
2067 2175
@@ -2070,8 +2178,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
2070 return NULL; 2178 return NULL;
2071 } 2179 }
2072 2180
2073 spin_lock_irqsave(mEp->lock, flags);
2074
2075 mReq = kzalloc(sizeof(struct ci13xxx_req), gfp_flags); 2181 mReq = kzalloc(sizeof(struct ci13xxx_req), gfp_flags);
2076 if (mReq != NULL) { 2182 if (mReq != NULL) {
2077 INIT_LIST_HEAD(&mReq->queue); 2183 INIT_LIST_HEAD(&mReq->queue);
@@ -2086,8 +2192,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
2086 2192
2087 dbg_event(_usb_addr(mEp), "ALLOC", mReq == NULL); 2193 dbg_event(_usb_addr(mEp), "ALLOC", mReq == NULL);
2088 2194
2089 spin_unlock_irqrestore(mEp->lock, flags);
2090
2091 return (mReq == NULL) ? NULL : &mReq->req; 2195 return (mReq == NULL) ? NULL : &mReq->req;
2092} 2196}
2093 2197
@@ -2143,11 +2247,15 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
2143 2247
2144 spin_lock_irqsave(mEp->lock, flags); 2248 spin_lock_irqsave(mEp->lock, flags);
2145 2249
2146 if (mEp->type == USB_ENDPOINT_XFER_CONTROL && 2250 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) {
2147 !list_empty(&mEp->qh[mEp->dir].queue)) { 2251 if (req->length)
2148 _ep_nuke(mEp); 2252 mEp = (_udc->ep0_dir == RX) ?
2149 retval = -EOVERFLOW; 2253 &_udc->ep0out : &_udc->ep0in;
2150 warn("endpoint ctrl %X nuked", _usb_addr(mEp)); 2254 if (!list_empty(&mEp->qh.queue)) {
2255 _ep_nuke(mEp);
2256 retval = -EOVERFLOW;
2257 warn("endpoint ctrl %X nuked", _usb_addr(mEp));
2258 }
2151 } 2259 }
2152 2260
2153 /* first nuke then test link, e.g. previous status has not sent */ 2261 /* first nuke then test link, e.g. previous status has not sent */
@@ -2157,8 +2265,8 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
2157 goto done; 2265 goto done;
2158 } 2266 }
2159 2267
2160 if (req->length > (4 * PAGE_SIZE)) { 2268 if (req->length > (4 * CI13XXX_PAGE_SIZE)) {
2161 req->length = (4 * PAGE_SIZE); 2269 req->length = (4 * CI13XXX_PAGE_SIZE);
2162 retval = -EMSGSIZE; 2270 retval = -EMSGSIZE;
2163 warn("request length truncated"); 2271 warn("request length truncated");
2164 } 2272 }
@@ -2168,13 +2276,15 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
2168 /* push request */ 2276 /* push request */
2169 mReq->req.status = -EINPROGRESS; 2277 mReq->req.status = -EINPROGRESS;
2170 mReq->req.actual = 0; 2278 mReq->req.actual = 0;
2171 list_add_tail(&mReq->queue, &mEp->qh[mEp->dir].queue);
2172 2279
2173 retval = _hardware_enqueue(mEp, mReq); 2280 retval = _hardware_enqueue(mEp, mReq);
2174 if (retval == -EALREADY || retval == -EBUSY) { 2281
2282 if (retval == -EALREADY) {
2175 dbg_event(_usb_addr(mEp), "QUEUE", retval); 2283 dbg_event(_usb_addr(mEp), "QUEUE", retval);
2176 retval = 0; 2284 retval = 0;
2177 } 2285 }
2286 if (!retval)
2287 list_add_tail(&mReq->queue, &mEp->qh.queue);
2178 2288
2179 done: 2289 done:
2180 spin_unlock_irqrestore(mEp->lock, flags); 2290 spin_unlock_irqrestore(mEp->lock, flags);
@@ -2194,22 +2304,28 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req)
2194 2304
2195 trace("%p, %p", ep, req); 2305 trace("%p, %p", ep, req);
2196 2306
2197 if (ep == NULL || req == NULL || mEp->desc == NULL || 2307 if (ep == NULL || req == NULL || mReq->req.status != -EALREADY ||
2198 list_empty(&mReq->queue) || list_empty(&mEp->qh[mEp->dir].queue)) 2308 mEp->desc == NULL || list_empty(&mReq->queue) ||
2309 list_empty(&mEp->qh.queue))
2199 return -EINVAL; 2310 return -EINVAL;
2200 2311
2201 spin_lock_irqsave(mEp->lock, flags); 2312 spin_lock_irqsave(mEp->lock, flags);
2202 2313
2203 dbg_event(_usb_addr(mEp), "DEQUEUE", 0); 2314 dbg_event(_usb_addr(mEp), "DEQUEUE", 0);
2204 2315
2205 if (mReq->req.status == -EALREADY) 2316 hw_ep_flush(mEp->num, mEp->dir);
2206 _hardware_dequeue(mEp, mReq);
2207 2317
2208 /* pop request */ 2318 /* pop request */
2209 list_del_init(&mReq->queue); 2319 list_del_init(&mReq->queue);
2320 if (mReq->map) {
2321 dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length,
2322 mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
2323 mReq->req.dma = 0;
2324 mReq->map = 0;
2325 }
2210 req->status = -ECONNRESET; 2326 req->status = -ECONNRESET;
2211 2327
2212 if (!mReq->req.no_interrupt && mReq->req.complete != NULL) { 2328 if (mReq->req.complete != NULL) {
2213 spin_unlock(mEp->lock); 2329 spin_unlock(mEp->lock);
2214 mReq->req.complete(&mEp->ep, &mReq->req); 2330 mReq->req.complete(&mEp->ep, &mReq->req);
2215 spin_lock(mEp->lock); 2331 spin_lock(mEp->lock);
@@ -2240,7 +2356,7 @@ static int ep_set_halt(struct usb_ep *ep, int value)
2240#ifndef STALL_IN 2356#ifndef STALL_IN
2241 /* g_file_storage MS compliant but g_zero fails chapter 9 compliance */ 2357 /* g_file_storage MS compliant but g_zero fails chapter 9 compliance */
2242 if (value && mEp->type == USB_ENDPOINT_XFER_BULK && mEp->dir == TX && 2358 if (value && mEp->type == USB_ENDPOINT_XFER_BULK && mEp->dir == TX &&
2243 !list_empty(&mEp->qh[mEp->dir].queue)) { 2359 !list_empty(&mEp->qh.queue)) {
2244 spin_unlock_irqrestore(mEp->lock, flags); 2360 spin_unlock_irqrestore(mEp->lock, flags);
2245 return -EAGAIN; 2361 return -EAGAIN;
2246 } 2362 }
@@ -2332,30 +2448,104 @@ static const struct usb_ep_ops usb_ep_ops = {
2332/****************************************************************************** 2448/******************************************************************************
2333 * GADGET block 2449 * GADGET block
2334 *****************************************************************************/ 2450 *****************************************************************************/
2451static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
2452{
2453 struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget);
2454 unsigned long flags;
2455 int gadget_ready = 0;
2456
2457 if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS))
2458 return -EOPNOTSUPP;
2459
2460 spin_lock_irqsave(udc->lock, flags);
2461 udc->vbus_active = is_active;
2462 if (udc->driver)
2463 gadget_ready = 1;
2464 spin_unlock_irqrestore(udc->lock, flags);
2465
2466 if (gadget_ready) {
2467 if (is_active) {
2468 pm_runtime_get_sync(&_gadget->dev);
2469 hw_device_reset(udc);
2470 hw_device_state(udc->ep0out.qh.dma);
2471 } else {
2472 hw_device_state(0);
2473 if (udc->udc_driver->notify_event)
2474 udc->udc_driver->notify_event(udc,
2475 CI13XXX_CONTROLLER_STOPPED_EVENT);
2476 _gadget_stop_activity(&udc->gadget);
2477 pm_runtime_put_sync(&_gadget->dev);
2478 }
2479 }
2480
2481 return 0;
2482}
2483
2484static int ci13xxx_wakeup(struct usb_gadget *_gadget)
2485{
2486 struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget);
2487 unsigned long flags;
2488 int ret = 0;
2489
2490 trace();
2491
2492 spin_lock_irqsave(udc->lock, flags);
2493 if (!udc->remote_wakeup) {
2494 ret = -EOPNOTSUPP;
2495 dbg_trace("remote wakeup feature is not enabled\n");
2496 goto out;
2497 }
2498 if (!hw_cread(CAP_PORTSC, PORTSC_SUSP)) {
2499 ret = -EINVAL;
2500 dbg_trace("port is not suspended\n");
2501 goto out;
2502 }
2503 hw_cwrite(CAP_PORTSC, PORTSC_FPR, PORTSC_FPR);
2504out:
2505 spin_unlock_irqrestore(udc->lock, flags);
2506 return ret;
2507}
2508
2509static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
2510{
2511 struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget);
2512
2513 if (udc->transceiver)
2514 return otg_set_power(udc->transceiver, mA);
2515 return -ENOTSUPP;
2516}
2517
2335/** 2518/**
2336 * Device operations part of the API to the USB controller hardware, 2519 * Device operations part of the API to the USB controller hardware,
2337 * which don't involve endpoints (or i/o) 2520 * which don't involve endpoints (or i/o)
2338 * Check "usb_gadget.h" for details 2521 * Check "usb_gadget.h" for details
2339 */ 2522 */
2340static const struct usb_gadget_ops usb_gadget_ops; 2523static const struct usb_gadget_ops usb_gadget_ops = {
2524 .vbus_session = ci13xxx_vbus_session,
2525 .wakeup = ci13xxx_wakeup,
2526 .vbus_draw = ci13xxx_vbus_draw,
2527};
2341 2528
2342/** 2529/**
2343 * usb_gadget_register_driver: register a gadget driver 2530 * usb_gadget_probe_driver: register a gadget driver
2531 * @driver: the driver being registered
2532 * @bind: the driver's bind callback
2344 * 2533 *
2345 * Check usb_gadget_register_driver() at "usb_gadget.h" for details 2534 * Check usb_gadget_probe_driver() at <linux/usb/gadget.h> for details.
2346 * Interrupts are enabled here 2535 * Interrupts are enabled here.
2347 */ 2536 */
2348int usb_gadget_register_driver(struct usb_gadget_driver *driver) 2537int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2538 int (*bind)(struct usb_gadget *))
2349{ 2539{
2350 struct ci13xxx *udc = _udc; 2540 struct ci13xxx *udc = _udc;
2351 unsigned long i, k, flags; 2541 unsigned long flags;
2542 int i, j;
2352 int retval = -ENOMEM; 2543 int retval = -ENOMEM;
2353 2544
2354 trace("%p", driver); 2545 trace("%p", driver);
2355 2546
2356 if (driver == NULL || 2547 if (driver == NULL ||
2357 driver->bind == NULL || 2548 bind == NULL ||
2358 driver->unbind == NULL ||
2359 driver->setup == NULL || 2549 driver->setup == NULL ||
2360 driver->disconnect == NULL || 2550 driver->disconnect == NULL ||
2361 driver->suspend == NULL || 2551 driver->suspend == NULL ||
@@ -2369,13 +2559,13 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2369 /* alloc resources */ 2559 /* alloc resources */
2370 udc->qh_pool = dma_pool_create("ci13xxx_qh", &udc->gadget.dev, 2560 udc->qh_pool = dma_pool_create("ci13xxx_qh", &udc->gadget.dev,
2371 sizeof(struct ci13xxx_qh), 2561 sizeof(struct ci13xxx_qh),
2372 64, PAGE_SIZE); 2562 64, CI13XXX_PAGE_SIZE);
2373 if (udc->qh_pool == NULL) 2563 if (udc->qh_pool == NULL)
2374 return -ENOMEM; 2564 return -ENOMEM;
2375 2565
2376 udc->td_pool = dma_pool_create("ci13xxx_td", &udc->gadget.dev, 2566 udc->td_pool = dma_pool_create("ci13xxx_td", &udc->gadget.dev,
2377 sizeof(struct ci13xxx_td), 2567 sizeof(struct ci13xxx_td),
2378 64, PAGE_SIZE); 2568 64, CI13XXX_PAGE_SIZE);
2379 if (udc->td_pool == NULL) { 2569 if (udc->td_pool == NULL) {
2380 dma_pool_destroy(udc->qh_pool); 2570 dma_pool_destroy(udc->qh_pool);
2381 udc->qh_pool = NULL; 2571 udc->qh_pool = NULL;
@@ -2386,68 +2576,88 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2386 2576
2387 info("hw_ep_max = %d", hw_ep_max); 2577 info("hw_ep_max = %d", hw_ep_max);
2388 2578
2389 udc->driver = driver;
2390 udc->gadget.ops = NULL;
2391 udc->gadget.dev.driver = NULL; 2579 udc->gadget.dev.driver = NULL;
2392 2580
2393 retval = 0; 2581 retval = 0;
2394 for (i = 0; i < hw_ep_max; i++) { 2582 for (i = 0; i < hw_ep_max/2; i++) {
2395 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; 2583 for (j = RX; j <= TX; j++) {
2396 2584 int k = i + j * hw_ep_max/2;
2397 scnprintf(mEp->name, sizeof(mEp->name), "ep%i", (int)i); 2585 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[k];
2398 2586
2399 mEp->lock = udc->lock; 2587 scnprintf(mEp->name, sizeof(mEp->name), "ep%i%s", i,
2400 mEp->device = &udc->gadget.dev; 2588 (j == TX) ? "in" : "out");
2401 mEp->td_pool = udc->td_pool; 2589
2402 2590 mEp->lock = udc->lock;
2403 mEp->ep.name = mEp->name; 2591 mEp->device = &udc->gadget.dev;
2404 mEp->ep.ops = &usb_ep_ops; 2592 mEp->td_pool = udc->td_pool;
2405 mEp->ep.maxpacket = CTRL_PAYLOAD_MAX; 2593
2406 2594 mEp->ep.name = mEp->name;
2407 /* this allocation cannot be random */ 2595 mEp->ep.ops = &usb_ep_ops;
2408 for (k = RX; k <= TX; k++) { 2596 mEp->ep.maxpacket = CTRL_PAYLOAD_MAX;
2409 INIT_LIST_HEAD(&mEp->qh[k].queue); 2597
2410 mEp->qh[k].ptr = dma_pool_alloc(udc->qh_pool, 2598 INIT_LIST_HEAD(&mEp->qh.queue);
2411 GFP_KERNEL, 2599 spin_unlock_irqrestore(udc->lock, flags);
2412 &mEp->qh[k].dma); 2600 mEp->qh.ptr = dma_pool_alloc(udc->qh_pool, GFP_KERNEL,
2413 if (mEp->qh[k].ptr == NULL) 2601 &mEp->qh.dma);
2602 spin_lock_irqsave(udc->lock, flags);
2603 if (mEp->qh.ptr == NULL)
2414 retval = -ENOMEM; 2604 retval = -ENOMEM;
2415 else 2605 else
2416 memset(mEp->qh[k].ptr, 0, 2606 memset(mEp->qh.ptr, 0, sizeof(*mEp->qh.ptr));
2417 sizeof(*mEp->qh[k].ptr)); 2607
2418 } 2608 /* skip ep0 out and in endpoints */
2419 if (i == 0) 2609 if (i == 0)
2420 udc->gadget.ep0 = &mEp->ep; 2610 continue;
2421 else 2611
2422 list_add_tail(&mEp->ep.ep_list, &udc->gadget.ep_list); 2612 list_add_tail(&mEp->ep.ep_list, &udc->gadget.ep_list);
2613 }
2423 } 2614 }
2424 if (retval) 2615 if (retval)
2425 goto done; 2616 goto done;
2617 spin_unlock_irqrestore(udc->lock, flags);
2618 retval = usb_ep_enable(&udc->ep0out.ep, &ctrl_endpt_out_desc);
2619 if (retval)
2620 return retval;
2621 retval = usb_ep_enable(&udc->ep0in.ep, &ctrl_endpt_in_desc);
2622 if (retval)
2623 return retval;
2624 spin_lock_irqsave(udc->lock, flags);
2426 2625
2626 udc->gadget.ep0 = &udc->ep0in.ep;
2427 /* bind gadget */ 2627 /* bind gadget */
2428 driver->driver.bus = NULL; 2628 driver->driver.bus = NULL;
2429 udc->gadget.ops = &usb_gadget_ops;
2430 udc->gadget.dev.driver = &driver->driver; 2629 udc->gadget.dev.driver = &driver->driver;
2431 2630
2432 spin_unlock_irqrestore(udc->lock, flags); 2631 spin_unlock_irqrestore(udc->lock, flags);
2433 retval = driver->bind(&udc->gadget); /* MAY SLEEP */ 2632 retval = bind(&udc->gadget); /* MAY SLEEP */
2434 spin_lock_irqsave(udc->lock, flags); 2633 spin_lock_irqsave(udc->lock, flags);
2435 2634
2436 if (retval) { 2635 if (retval) {
2437 udc->gadget.ops = NULL;
2438 udc->gadget.dev.driver = NULL; 2636 udc->gadget.dev.driver = NULL;
2439 goto done; 2637 goto done;
2440 } 2638 }
2441 2639
2442 retval = hw_device_state(udc->ci13xxx_ep[0].qh[RX].dma); 2640 udc->driver = driver;
2641 pm_runtime_get_sync(&udc->gadget.dev);
2642 if (udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) {
2643 if (udc->vbus_active) {
2644 if (udc->udc_driver->flags & CI13XXX_REGS_SHARED)
2645 hw_device_reset(udc);
2646 } else {
2647 pm_runtime_put_sync(&udc->gadget.dev);
2648 goto done;
2649 }
2650 }
2651
2652 retval = hw_device_state(udc->ep0out.qh.dma);
2653 if (retval)
2654 pm_runtime_put_sync(&udc->gadget.dev);
2443 2655
2444 done: 2656 done:
2445 spin_unlock_irqrestore(udc->lock, flags); 2657 spin_unlock_irqrestore(udc->lock, flags);
2446 if (retval)
2447 usb_gadget_unregister_driver(driver);
2448 return retval; 2658 return retval;
2449} 2659}
2450EXPORT_SYMBOL(usb_gadget_register_driver); 2660EXPORT_SYMBOL(usb_gadget_probe_driver);
2451 2661
2452/** 2662/**
2453 * usb_gadget_unregister_driver: unregister a gadget driver 2663 * usb_gadget_unregister_driver: unregister a gadget driver
@@ -2457,12 +2667,11 @@ EXPORT_SYMBOL(usb_gadget_register_driver);
2457int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2667int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2458{ 2668{
2459 struct ci13xxx *udc = _udc; 2669 struct ci13xxx *udc = _udc;
2460 unsigned long i, k, flags; 2670 unsigned long i, flags;
2461 2671
2462 trace("%p", driver); 2672 trace("%p", driver);
2463 2673
2464 if (driver == NULL || 2674 if (driver == NULL ||
2465 driver->bind == NULL ||
2466 driver->unbind == NULL || 2675 driver->unbind == NULL ||
2467 driver->setup == NULL || 2676 driver->setup == NULL ||
2468 driver->disconnect == NULL || 2677 driver->disconnect == NULL ||
@@ -2473,35 +2682,35 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2473 2682
2474 spin_lock_irqsave(udc->lock, flags); 2683 spin_lock_irqsave(udc->lock, flags);
2475 2684
2476 hw_device_state(0); 2685 if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) ||
2477 2686 udc->vbus_active) {
2478 /* unbind gadget */ 2687 hw_device_state(0);
2479 if (udc->gadget.ops != NULL) { 2688 if (udc->udc_driver->notify_event)
2689 udc->udc_driver->notify_event(udc,
2690 CI13XXX_CONTROLLER_STOPPED_EVENT);
2480 _gadget_stop_activity(&udc->gadget); 2691 _gadget_stop_activity(&udc->gadget);
2692 pm_runtime_put(&udc->gadget.dev);
2693 }
2481 2694
2482 spin_unlock_irqrestore(udc->lock, flags); 2695 /* unbind gadget */
2483 driver->unbind(&udc->gadget); /* MAY SLEEP */ 2696 spin_unlock_irqrestore(udc->lock, flags);
2484 spin_lock_irqsave(udc->lock, flags); 2697 driver->unbind(&udc->gadget); /* MAY SLEEP */
2698 spin_lock_irqsave(udc->lock, flags);
2485 2699
2486 udc->gadget.ops = NULL; 2700 udc->gadget.dev.driver = NULL;
2487 udc->gadget.dev.driver = NULL;
2488 }
2489 2701
2490 /* free resources */ 2702 /* free resources */
2491 for (i = 0; i < hw_ep_max; i++) { 2703 for (i = 0; i < hw_ep_max; i++) {
2492 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; 2704 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i];
2493 2705
2494 if (i == 0) 2706 if (!list_empty(&mEp->ep.ep_list))
2495 udc->gadget.ep0 = NULL;
2496 else if (!list_empty(&mEp->ep.ep_list))
2497 list_del_init(&mEp->ep.ep_list); 2707 list_del_init(&mEp->ep.ep_list);
2498 2708
2499 for (k = RX; k <= TX; k++) 2709 if (mEp->qh.ptr != NULL)
2500 if (mEp->qh[k].ptr != NULL) 2710 dma_pool_free(udc->qh_pool, mEp->qh.ptr, mEp->qh.dma);
2501 dma_pool_free(udc->qh_pool,
2502 mEp->qh[k].ptr, mEp->qh[k].dma);
2503 } 2711 }
2504 2712
2713 udc->gadget.ep0 = NULL;
2505 udc->driver = NULL; 2714 udc->driver = NULL;
2506 2715
2507 spin_unlock_irqrestore(udc->lock, flags); 2716 spin_unlock_irqrestore(udc->lock, flags);
@@ -2542,6 +2751,14 @@ static irqreturn_t udc_irq(void)
2542 } 2751 }
2543 2752
2544 spin_lock(udc->lock); 2753 spin_lock(udc->lock);
2754
2755 if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) {
2756 if (hw_cread(CAP_USBMODE, USBMODE_CM) !=
2757 USBMODE_CM_DEVICE) {
2758 spin_unlock(udc->lock);
2759 return IRQ_NONE;
2760 }
2761 }
2545 intr = hw_test_and_clear_intr_active(); 2762 intr = hw_test_and_clear_intr_active();
2546 if (intr) { 2763 if (intr) {
2547 isr_statistics.hndl.buf[isr_statistics.hndl.idx++] = intr; 2764 isr_statistics.hndl.buf[isr_statistics.hndl.idx++] = intr;
@@ -2557,6 +2774,12 @@ static irqreturn_t udc_irq(void)
2557 isr_statistics.pci++; 2774 isr_statistics.pci++;
2558 udc->gadget.speed = hw_port_is_high_speed() ? 2775 udc->gadget.speed = hw_port_is_high_speed() ?
2559 USB_SPEED_HIGH : USB_SPEED_FULL; 2776 USB_SPEED_HIGH : USB_SPEED_FULL;
2777 if (udc->suspended) {
2778 spin_unlock(udc->lock);
2779 udc->driver->resume(&udc->gadget);
2780 spin_lock(udc->lock);
2781 udc->suspended = 0;
2782 }
2560 } 2783 }
2561 if (USBi_UEI & intr) 2784 if (USBi_UEI & intr)
2562 isr_statistics.uei++; 2785 isr_statistics.uei++;
@@ -2564,8 +2787,15 @@ static irqreturn_t udc_irq(void)
2564 isr_statistics.ui++; 2787 isr_statistics.ui++;
2565 isr_tr_complete_handler(udc); 2788 isr_tr_complete_handler(udc);
2566 } 2789 }
2567 if (USBi_SLI & intr) 2790 if (USBi_SLI & intr) {
2791 if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
2792 udc->suspended = 1;
2793 spin_unlock(udc->lock);
2794 udc->driver->suspend(&udc->gadget);
2795 spin_lock(udc->lock);
2796 }
2568 isr_statistics.sli++; 2797 isr_statistics.sli++;
2798 }
2569 retval = IRQ_HANDLED; 2799 retval = IRQ_HANDLED;
2570 } else { 2800 } else {
2571 isr_statistics.none++; 2801 isr_statistics.none++;
@@ -2600,14 +2830,16 @@ static void udc_release(struct device *dev)
2600 * No interrupts active, the IRQ has not been requested yet 2830 * No interrupts active, the IRQ has not been requested yet
2601 * Kernel assumes 32-bit DMA operations by default, no need to dma_set_mask 2831 * Kernel assumes 32-bit DMA operations by default, no need to dma_set_mask
2602 */ 2832 */
2603static int udc_probe(struct device *dev, void __iomem *regs, const char *name) 2833static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
2834 void __iomem *regs)
2604{ 2835{
2605 struct ci13xxx *udc; 2836 struct ci13xxx *udc;
2606 int retval = 0; 2837 int retval = 0;
2607 2838
2608 trace("%p, %p, %p", dev, regs, name); 2839 trace("%p, %p, %p", dev, regs, name);
2609 2840
2610 if (dev == NULL || regs == NULL || name == NULL) 2841 if (dev == NULL || regs == NULL || driver == NULL ||
2842 driver->name == NULL)
2611 return -EINVAL; 2843 return -EINVAL;
2612 2844
2613 udc = kzalloc(sizeof(struct ci13xxx), GFP_KERNEL); 2845 udc = kzalloc(sizeof(struct ci13xxx), GFP_KERNEL);
@@ -2615,42 +2847,77 @@ static int udc_probe(struct device *dev, void __iomem *regs, const char *name)
2615 return -ENOMEM; 2847 return -ENOMEM;
2616 2848
2617 udc->lock = &udc_lock; 2849 udc->lock = &udc_lock;
2850 udc->regs = regs;
2851 udc->udc_driver = driver;
2618 2852
2619 retval = hw_device_reset(regs); 2853 udc->gadget.ops = &usb_gadget_ops;
2620 if (retval)
2621 goto done;
2622
2623 udc->gadget.ops = NULL;
2624 udc->gadget.speed = USB_SPEED_UNKNOWN; 2854 udc->gadget.speed = USB_SPEED_UNKNOWN;
2625 udc->gadget.is_dualspeed = 1; 2855 udc->gadget.is_dualspeed = 1;
2626 udc->gadget.is_otg = 0; 2856 udc->gadget.is_otg = 0;
2627 udc->gadget.name = name; 2857 udc->gadget.name = driver->name;
2628 2858
2629 INIT_LIST_HEAD(&udc->gadget.ep_list); 2859 INIT_LIST_HEAD(&udc->gadget.ep_list);
2630 udc->gadget.ep0 = NULL; 2860 udc->gadget.ep0 = NULL;
2631 2861
2632 dev_set_name(&udc->gadget.dev, "gadget"); 2862 dev_set_name(&udc->gadget.dev, "gadget");
2633 udc->gadget.dev.dma_mask = dev->dma_mask; 2863 udc->gadget.dev.dma_mask = dev->dma_mask;
2864 udc->gadget.dev.coherent_dma_mask = dev->coherent_dma_mask;
2634 udc->gadget.dev.parent = dev; 2865 udc->gadget.dev.parent = dev;
2635 udc->gadget.dev.release = udc_release; 2866 udc->gadget.dev.release = udc_release;
2636 2867
2868 retval = hw_device_init(regs);
2869 if (retval < 0)
2870 goto free_udc;
2871
2872 udc->transceiver = otg_get_transceiver();
2873
2874 if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) {
2875 if (udc->transceiver == NULL) {
2876 retval = -ENODEV;
2877 goto free_udc;
2878 }
2879 }
2880
2881 if (!(udc->udc_driver->flags & CI13XXX_REGS_SHARED)) {
2882 retval = hw_device_reset(udc);
2883 if (retval)
2884 goto put_transceiver;
2885 }
2886
2637 retval = device_register(&udc->gadget.dev); 2887 retval = device_register(&udc->gadget.dev);
2638 if (retval) 2888 if (retval) {
2639 goto done; 2889 put_device(&udc->gadget.dev);
2890 goto put_transceiver;
2891 }
2640 2892
2641#ifdef CONFIG_USB_GADGET_DEBUG_FILES 2893#ifdef CONFIG_USB_GADGET_DEBUG_FILES
2642 retval = dbg_create_files(&udc->gadget.dev); 2894 retval = dbg_create_files(&udc->gadget.dev);
2643#endif 2895#endif
2644 if (retval) { 2896 if (retval)
2645 device_unregister(&udc->gadget.dev); 2897 goto unreg_device;
2646 goto done; 2898
2899 if (udc->transceiver) {
2900 retval = otg_set_peripheral(udc->transceiver, &udc->gadget);
2901 if (retval)
2902 goto remove_dbg;
2647 } 2903 }
2904 pm_runtime_no_callbacks(&udc->gadget.dev);
2905 pm_runtime_enable(&udc->gadget.dev);
2648 2906
2649 _udc = udc; 2907 _udc = udc;
2650 return retval; 2908 return retval;
2651 2909
2652 done:
2653 err("error = %i", retval); 2910 err("error = %i", retval);
2911remove_dbg:
2912#ifdef CONFIG_USB_GADGET_DEBUG_FILES
2913 dbg_remove_files(&udc->gadget.dev);
2914#endif
2915unreg_device:
2916 device_unregister(&udc->gadget.dev);
2917put_transceiver:
2918 if (udc->transceiver)
2919 otg_put_transceiver(udc->transceiver);
2920free_udc:
2654 kfree(udc); 2921 kfree(udc);
2655 _udc = NULL; 2922 _udc = NULL;
2656 return retval; 2923 return retval;
@@ -2670,6 +2937,10 @@ static void udc_remove(void)
2670 return; 2937 return;
2671 } 2938 }
2672 2939
2940 if (udc->transceiver) {
2941 otg_set_peripheral(udc->transceiver, &udc->gadget);
2942 otg_put_transceiver(udc->transceiver);
2943 }
2673#ifdef CONFIG_USB_GADGET_DEBUG_FILES 2944#ifdef CONFIG_USB_GADGET_DEBUG_FILES
2674 dbg_remove_files(&udc->gadget.dev); 2945 dbg_remove_files(&udc->gadget.dev);
2675#endif 2946#endif
@@ -2678,156 +2949,3 @@ static void udc_remove(void)
2678 kfree(udc); 2949 kfree(udc);
2679 _udc = NULL; 2950 _udc = NULL;
2680} 2951}
2681
2682/******************************************************************************
2683 * PCI block
2684 *****************************************************************************/
2685/**
2686 * ci13xxx_pci_irq: interrut handler
2687 * @irq: irq number
2688 * @pdev: USB Device Controller interrupt source
2689 *
2690 * This function returns IRQ_HANDLED if the IRQ has been handled
2691 * This is an ISR don't trace, use attribute interface instead
2692 */
2693static irqreturn_t ci13xxx_pci_irq(int irq, void *pdev)
2694{
2695 if (irq == 0) {
2696 dev_err(&((struct pci_dev *)pdev)->dev, "Invalid IRQ0 usage!");
2697 return IRQ_HANDLED;
2698 }
2699 return udc_irq();
2700}
2701
2702/**
2703 * ci13xxx_pci_probe: PCI probe
2704 * @pdev: USB device controller being probed
2705 * @id: PCI hotplug ID connecting controller to UDC framework
2706 *
2707 * This function returns an error code
2708 * Allocates basic PCI resources for this USB device controller, and then
2709 * invokes the udc_probe() method to start the UDC associated with it
2710 */
2711static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
2712 const struct pci_device_id *id)
2713{
2714 void __iomem *regs = NULL;
2715 int retval = 0;
2716
2717 if (id == NULL)
2718 return -EINVAL;
2719
2720 retval = pci_enable_device(pdev);
2721 if (retval)
2722 goto done;
2723
2724 if (!pdev->irq) {
2725 dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
2726 retval = -ENODEV;
2727 goto disable_device;
2728 }
2729
2730 retval = pci_request_regions(pdev, UDC_DRIVER_NAME);
2731 if (retval)
2732 goto disable_device;
2733
2734 /* BAR 0 holds all the registers */
2735 regs = pci_iomap(pdev, 0, 0);
2736 if (!regs) {
2737 dev_err(&pdev->dev, "Error mapping memory!");
2738 retval = -EFAULT;
2739 goto release_regions;
2740 }
2741 pci_set_drvdata(pdev, (__force void *)regs);
2742
2743 pci_set_master(pdev);
2744 pci_try_set_mwi(pdev);
2745
2746 retval = udc_probe(&pdev->dev, regs, UDC_DRIVER_NAME);
2747 if (retval)
2748 goto iounmap;
2749
2750 /* our device does not have MSI capability */
2751
2752 retval = request_irq(pdev->irq, ci13xxx_pci_irq, IRQF_SHARED,
2753 UDC_DRIVER_NAME, pdev);
2754 if (retval)
2755 goto gadget_remove;
2756
2757 return 0;
2758
2759 gadget_remove:
2760 udc_remove();
2761 iounmap:
2762 pci_iounmap(pdev, regs);
2763 release_regions:
2764 pci_release_regions(pdev);
2765 disable_device:
2766 pci_disable_device(pdev);
2767 done:
2768 return retval;
2769}
2770
2771/**
2772 * ci13xxx_pci_remove: PCI remove
2773 * @pdev: USB Device Controller being removed
2774 *
2775 * Reverses the effect of ci13xxx_pci_probe(),
2776 * first invoking the udc_remove() and then releases
2777 * all PCI resources allocated for this USB device controller
2778 */
2779static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
2780{
2781 free_irq(pdev->irq, pdev);
2782 udc_remove();
2783 pci_iounmap(pdev, (__force void __iomem *)pci_get_drvdata(pdev));
2784 pci_release_regions(pdev);
2785 pci_disable_device(pdev);
2786}
2787
2788/**
2789 * PCI device table
2790 * PCI device structure
2791 *
2792 * Check "pci.h" for details
2793 */
2794static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = {
2795 { PCI_DEVICE(0x153F, 0x1004) },
2796 { PCI_DEVICE(0x153F, 0x1006) },
2797 { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
2798};
2799MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table);
2800
2801static struct pci_driver ci13xxx_pci_driver = {
2802 .name = UDC_DRIVER_NAME,
2803 .id_table = ci13xxx_pci_id_table,
2804 .probe = ci13xxx_pci_probe,
2805 .remove = __devexit_p(ci13xxx_pci_remove),
2806};
2807
2808/**
2809 * ci13xxx_pci_init: module init
2810 *
2811 * Driver load
2812 */
2813static int __init ci13xxx_pci_init(void)
2814{
2815 return pci_register_driver(&ci13xxx_pci_driver);
2816}
2817module_init(ci13xxx_pci_init);
2818
2819/**
2820 * ci13xxx_pci_exit: module exit
2821 *
2822 * Driver unload
2823 */
2824static void __exit ci13xxx_pci_exit(void)
2825{
2826 pci_unregister_driver(&ci13xxx_pci_driver);
2827}
2828module_exit(ci13xxx_pci_exit);
2829
2830MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
2831MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
2832MODULE_LICENSE("GPL");
2833MODULE_VERSION("June 2008");
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h
index 4026e9cede34..23707775cb43 100644
--- a/drivers/usb/gadget/ci13xxx_udc.h
+++ b/drivers/usb/gadget/ci13xxx_udc.h
@@ -19,7 +19,8 @@
19/****************************************************************************** 19/******************************************************************************
20 * DEFINE 20 * DEFINE
21 *****************************************************************************/ 21 *****************************************************************************/
22#define ENDPT_MAX (16) 22#define CI13XXX_PAGE_SIZE 4096ul /* page size for TD's */
23#define ENDPT_MAX (32)
23#define CTRL_PAYLOAD_MAX (64) 24#define CTRL_PAYLOAD_MAX (64)
24#define RX (0) /* similar to USB_DIR_OUT but can be used as an index */ 25#define RX (0) /* similar to USB_DIR_OUT but can be used as an index */
25#define TX (1) /* similar to USB_DIR_IN but can be used as an index */ 26#define TX (1) /* similar to USB_DIR_IN but can be used as an index */
@@ -32,6 +33,7 @@ struct ci13xxx_td {
32 /* 0 */ 33 /* 0 */
33 u32 next; 34 u32 next;
34#define TD_TERMINATE BIT(0) 35#define TD_TERMINATE BIT(0)
36#define TD_ADDR_MASK (0xFFFFFFEUL << 5)
35 /* 1 */ 37 /* 1 */
36 u32 token; 38 u32 token;
37#define TD_STATUS (0x00FFUL << 0) 39#define TD_STATUS (0x00FFUL << 0)
@@ -73,6 +75,8 @@ struct ci13xxx_req {
73 struct list_head queue; 75 struct list_head queue;
74 struct ci13xxx_td *ptr; 76 struct ci13xxx_td *ptr;
75 dma_addr_t dma; 77 dma_addr_t dma;
78 struct ci13xxx_td *zptr;
79 dma_addr_t zdma;
76}; 80};
77 81
78/* Extension of usb_ep */ 82/* Extension of usb_ep */
@@ -87,8 +91,7 @@ struct ci13xxx_ep {
87 struct list_head queue; 91 struct list_head queue;
88 struct ci13xxx_qh *ptr; 92 struct ci13xxx_qh *ptr;
89 dma_addr_t dma; 93 dma_addr_t dma;
90 } qh[2]; 94 } qh;
91 struct usb_request *status;
92 int wedge; 95 int wedge;
93 96
94 /* global resources */ 97 /* global resources */
@@ -97,17 +100,43 @@ struct ci13xxx_ep {
97 struct dma_pool *td_pool; 100 struct dma_pool *td_pool;
98}; 101};
99 102
103struct ci13xxx;
104struct ci13xxx_udc_driver {
105 const char *name;
106 unsigned long flags;
107#define CI13XXX_REGS_SHARED BIT(0)
108#define CI13XXX_REQUIRE_TRANSCEIVER BIT(1)
109#define CI13XXX_PULLUP_ON_VBUS BIT(2)
110#define CI13XXX_DISABLE_STREAMING BIT(3)
111
112#define CI13XXX_CONTROLLER_RESET_EVENT 0
113#define CI13XXX_CONTROLLER_STOPPED_EVENT 1
114 void (*notify_event) (struct ci13xxx *udc, unsigned event);
115};
116
100/* CI13XXX UDC descriptor & global resources */ 117/* CI13XXX UDC descriptor & global resources */
101struct ci13xxx { 118struct ci13xxx {
102 spinlock_t *lock; /* ctrl register bank access */ 119 spinlock_t *lock; /* ctrl register bank access */
120 void __iomem *regs; /* registers address space */
103 121
104 struct dma_pool *qh_pool; /* DMA pool for queue heads */ 122 struct dma_pool *qh_pool; /* DMA pool for queue heads */
105 struct dma_pool *td_pool; /* DMA pool for transfer descs */ 123 struct dma_pool *td_pool; /* DMA pool for transfer descs */
124 struct usb_request *status; /* ep0 status request */
106 125
107 struct usb_gadget gadget; /* USB slave device */ 126 struct usb_gadget gadget; /* USB slave device */
108 struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */ 127 struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */
128 u32 ep0_dir; /* ep0 direction */
129#define ep0out ci13xxx_ep[0]
130#define ep0in ci13xxx_ep[16]
131 u8 remote_wakeup; /* Is remote wakeup feature
132 enabled by the host? */
133 u8 suspended; /* suspended by the host */
134 u8 test_mode; /* the selected test mode */
109 135
110 struct usb_gadget_driver *driver; /* 3rd party gadget driver */ 136 struct usb_gadget_driver *driver; /* 3rd party gadget driver */
137 struct ci13xxx_udc_driver *udc_driver; /* device controller driver */
138 int vbus_active; /* is VBUS active */
139 struct otg_transceiver *transceiver; /* Transceiver struct */
111}; 140};
112 141
113/****************************************************************************** 142/******************************************************************************
@@ -130,6 +159,7 @@ struct ci13xxx {
130#define USBCMD_RS BIT(0) 159#define USBCMD_RS BIT(0)
131#define USBCMD_RST BIT(1) 160#define USBCMD_RST BIT(1)
132#define USBCMD_SUTW BIT(13) 161#define USBCMD_SUTW BIT(13)
162#define USBCMD_ATDTW BIT(14)
133 163
134/* USBSTS & USBINTR */ 164/* USBSTS & USBINTR */
135#define USBi_UI BIT(0) 165#define USBi_UI BIT(0)
@@ -143,6 +173,7 @@ struct ci13xxx {
143#define DEVICEADDR_USBADR (0x7FUL << 25) 173#define DEVICEADDR_USBADR (0x7FUL << 25)
144 174
145/* PORTSC */ 175/* PORTSC */
176#define PORTSC_FPR BIT(6)
146#define PORTSC_SUSP BIT(7) 177#define PORTSC_SUSP BIT(7)
147#define PORTSC_HSP BIT(9) 178#define PORTSC_HSP BIT(9)
148#define PORTSC_PTC (0x0FUL << 16) 179#define PORTSC_PTC (0x0FUL << 16)
@@ -157,6 +188,7 @@ struct ci13xxx {
157#define USBMODE_CM_DEVICE (0x02UL << 0) 188#define USBMODE_CM_DEVICE (0x02UL << 0)
158#define USBMODE_CM_HOST (0x03UL << 0) 189#define USBMODE_CM_HOST (0x03UL << 0)
159#define USBMODE_SLOM BIT(3) 190#define USBMODE_SLOM BIT(3)
191#define USBMODE_SDIS BIT(4)
160 192
161/* ENDPTCTRL */ 193/* ENDPTCTRL */
162#define ENDPTCTRL_RXS BIT(0) 194#define ENDPTCTRL_RXS BIT(0)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 1160c55de7f2..5cbb1a41c223 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -24,6 +24,7 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/utsname.h>
27 28
28#include <linux/usb/composite.h> 29#include <linux/usb/composite.h>
29 30
@@ -39,8 +40,9 @@
39#define USB_BUFSIZ 1024 40#define USB_BUFSIZ 1024
40 41
41static struct usb_composite_driver *composite; 42static struct usb_composite_driver *composite;
43static int (*composite_gadget_bind)(struct usb_composite_dev *cdev);
42 44
43/* Some systems will need runtime overrides for the product identifers 45/* Some systems will need runtime overrides for the product identifiers
44 * published in the device descriptor, either numbers or strings or both. 46 * published in the device descriptor, either numbers or strings or both.
45 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters). 47 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
46 */ 48 */
@@ -69,6 +71,8 @@ static char *iSerialNumber;
69module_param(iSerialNumber, charp, 0); 71module_param(iSerialNumber, charp, 0);
70MODULE_PARM_DESC(iSerialNumber, "SerialNumber string"); 72MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
71 73
74static char composite_manufacturer[50];
75
72/*-------------------------------------------------------------------------*/ 76/*-------------------------------------------------------------------------*/
73 77
74/** 78/**
@@ -201,14 +205,14 @@ int usb_function_activate(struct usb_function *function)
201 * usb_interface_id() is called from usb_function.bind() callbacks to 205 * usb_interface_id() is called from usb_function.bind() callbacks to
202 * allocate new interface IDs. The function driver will then store that 206 * allocate new interface IDs. The function driver will then store that
203 * ID in interface, association, CDC union, and other descriptors. It 207 * ID in interface, association, CDC union, and other descriptors. It
204 * will also handle any control requests targetted at that interface, 208 * will also handle any control requests targeted at that interface,
205 * particularly changing its altsetting via set_alt(). There may 209 * particularly changing its altsetting via set_alt(). There may
206 * also be class-specific or vendor-specific requests to handle. 210 * also be class-specific or vendor-specific requests to handle.
207 * 211 *
208 * All interface identifier should be allocated using this routine, to 212 * All interface identifier should be allocated using this routine, to
209 * ensure that for example different functions don't wrongly assign 213 * ensure that for example different functions don't wrongly assign
210 * different meanings to the same identifier. Note that since interface 214 * different meanings to the same identifier. Note that since interface
211 * identifers are configuration-specific, functions used in more than 215 * identifiers are configuration-specific, functions used in more than
212 * one configuration (or more than once in a given configuration) need 216 * one configuration (or more than once in a given configuration) need
213 * multiple versions of the relevant descriptors. 217 * multiple versions of the relevant descriptors.
214 * 218 *
@@ -457,12 +461,23 @@ static int set_config(struct usb_composite_dev *cdev,
457 reset_config(cdev); 461 reset_config(cdev);
458 goto done; 462 goto done;
459 } 463 }
464
465 if (result == USB_GADGET_DELAYED_STATUS) {
466 DBG(cdev,
467 "%s: interface %d (%s) requested delayed status\n",
468 __func__, tmp, f->name);
469 cdev->delayed_status++;
470 DBG(cdev, "delayed_status count %d\n",
471 cdev->delayed_status);
472 }
460 } 473 }
461 474
462 /* when we return, be sure our power usage is valid */ 475 /* when we return, be sure our power usage is valid */
463 power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW; 476 power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW;
464done: 477done:
465 usb_gadget_vbus_draw(gadget, power); 478 usb_gadget_vbus_draw(gadget, power);
479 if (result >= 0 && cdev->delayed_status)
480 result = USB_GADGET_DELAYED_STATUS;
466 return result; 481 return result;
467} 482}
468 483
@@ -470,18 +485,20 @@ done:
470 * usb_add_config() - add a configuration to a device. 485 * usb_add_config() - add a configuration to a device.
471 * @cdev: wraps the USB gadget 486 * @cdev: wraps the USB gadget
472 * @config: the configuration, with bConfigurationValue assigned 487 * @config: the configuration, with bConfigurationValue assigned
488 * @bind: the configuration's bind function
473 * Context: single threaded during gadget setup 489 * Context: single threaded during gadget setup
474 * 490 *
475 * One of the main tasks of a composite driver's bind() routine is to 491 * One of the main tasks of a composite @bind() routine is to
476 * add each of the configurations it supports, using this routine. 492 * add each of the configurations it supports, using this routine.
477 * 493 *
478 * This function returns the value of the configuration's bind(), which 494 * This function returns the value of the configuration's @bind(), which
479 * is zero for success else a negative errno value. Binding configurations 495 * is zero for success else a negative errno value. Binding configurations
480 * assigns global resources including string IDs, and per-configuration 496 * assigns global resources including string IDs, and per-configuration
481 * resources such as interface IDs and endpoints. 497 * resources such as interface IDs and endpoints.
482 */ 498 */
483int usb_add_config(struct usb_composite_dev *cdev, 499int usb_add_config(struct usb_composite_dev *cdev,
484 struct usb_configuration *config) 500 struct usb_configuration *config,
501 int (*bind)(struct usb_configuration *))
485{ 502{
486 int status = -EINVAL; 503 int status = -EINVAL;
487 struct usb_configuration *c; 504 struct usb_configuration *c;
@@ -490,7 +507,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
490 config->bConfigurationValue, 507 config->bConfigurationValue,
491 config->label, config); 508 config->label, config);
492 509
493 if (!config->bConfigurationValue || !config->bind) 510 if (!config->bConfigurationValue || !bind)
494 goto done; 511 goto done;
495 512
496 /* Prevent duplicate configuration identifiers */ 513 /* Prevent duplicate configuration identifiers */
@@ -507,7 +524,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
507 INIT_LIST_HEAD(&config->functions); 524 INIT_LIST_HEAD(&config->functions);
508 config->next_interface_id = 0; 525 config->next_interface_id = 0;
509 526
510 status = config->bind(config); 527 status = bind(config);
511 if (status < 0) { 528 if (status < 0) {
512 list_del(&config->list); 529 list_del(&config->list);
513 config->cdev = NULL; 530 config->cdev = NULL;
@@ -533,7 +550,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
533 } 550 }
534 } 551 }
535 552
536 /* set_alt(), or next config->bind(), sets up 553 /* set_alt(), or next bind(), sets up
537 * ep->driver_data as needed. 554 * ep->driver_data as needed.
538 */ 555 */
539 usb_ep_autoconfig_reset(cdev->gadget); 556 usb_ep_autoconfig_reset(cdev->gadget);
@@ -599,6 +616,7 @@ static int get_string(struct usb_composite_dev *cdev,
599 struct usb_configuration *c; 616 struct usb_configuration *c;
600 struct usb_function *f; 617 struct usb_function *f;
601 int len; 618 int len;
619 const char *str;
602 620
603 /* Yes, not only is USB's I18N support probably more than most 621 /* Yes, not only is USB's I18N support probably more than most
604 * folk will ever care about ... also, it's all supported here. 622 * folk will ever care about ... also, it's all supported here.
@@ -638,9 +656,29 @@ static int get_string(struct usb_composite_dev *cdev,
638 return s->bLength; 656 return s->bLength;
639 } 657 }
640 658
641 /* Otherwise, look up and return a specified string. String IDs 659 /* Otherwise, look up and return a specified string. First
642 * are device-scoped, so we look up each string table we're told 660 * check if the string has not been overridden.
643 * about. These lookups are infrequent; simpler-is-better here. 661 */
662 if (cdev->manufacturer_override == id)
663 str = iManufacturer ?: composite->iManufacturer ?:
664 composite_manufacturer;
665 else if (cdev->product_override == id)
666 str = iProduct ?: composite->iProduct;
667 else if (cdev->serial_override == id)
668 str = iSerialNumber;
669 else
670 str = NULL;
671 if (str) {
672 struct usb_gadget_strings strings = {
673 .language = language,
674 .strings = &(struct usb_string) { 0xff, str }
675 };
676 return usb_gadget_get_string(&strings, 0xff, buf);
677 }
678
679 /* String IDs are device-scoped, so we look up each string
680 * table we're told about. These lookups are infrequent;
681 * simpler-is-better here.
644 */ 682 */
645 if (composite->strings) { 683 if (composite->strings) {
646 len = lookup_string(composite->strings, buf, language, id); 684 len = lookup_string(composite->strings, buf, language, id);
@@ -786,7 +824,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
786 */ 824 */
787 req->zero = 0; 825 req->zero = 0;
788 req->complete = composite_setup_complete; 826 req->complete = composite_setup_complete;
789 req->length = USB_BUFSIZ; 827 req->length = 0;
790 gadget->ep0->driver_data = cdev; 828 gadget->ep0->driver_data = cdev;
791 829
792 switch (ctrl->bRequest) { 830 switch (ctrl->bRequest) {
@@ -860,7 +898,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
860 case USB_REQ_SET_INTERFACE: 898 case USB_REQ_SET_INTERFACE:
861 if (ctrl->bRequestType != USB_RECIP_INTERFACE) 899 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
862 goto unknown; 900 goto unknown;
863 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) 901 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
864 break; 902 break;
865 f = cdev->config->interface[intf]; 903 f = cdev->config->interface[intf];
866 if (!f) 904 if (!f)
@@ -868,11 +906,19 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
868 if (w_value && !f->set_alt) 906 if (w_value && !f->set_alt)
869 break; 907 break;
870 value = f->set_alt(f, w_index, w_value); 908 value = f->set_alt(f, w_index, w_value);
909 if (value == USB_GADGET_DELAYED_STATUS) {
910 DBG(cdev,
911 "%s: interface %d (%s) requested delayed status\n",
912 __func__, intf, f->name);
913 cdev->delayed_status++;
914 DBG(cdev, "delayed_status count %d\n",
915 cdev->delayed_status);
916 }
871 break; 917 break;
872 case USB_REQ_GET_INTERFACE: 918 case USB_REQ_GET_INTERFACE:
873 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) 919 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
874 goto unknown; 920 goto unknown;
875 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) 921 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
876 break; 922 break;
877 f = cdev->config->interface[intf]; 923 f = cdev->config->interface[intf];
878 if (!f) 924 if (!f)
@@ -901,6 +947,8 @@ unknown:
901 */ 947 */
902 switch (ctrl->bRequestType & USB_RECIP_MASK) { 948 switch (ctrl->bRequestType & USB_RECIP_MASK) {
903 case USB_RECIP_INTERFACE: 949 case USB_RECIP_INTERFACE:
950 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
951 break;
904 f = cdev->config->interface[intf]; 952 f = cdev->config->interface[intf];
905 break; 953 break;
906 954
@@ -929,7 +977,7 @@ unknown:
929 } 977 }
930 978
931 /* respond with data transfer before status phase? */ 979 /* respond with data transfer before status phase? */
932 if (value >= 0) { 980 if (value >= 0 && value != USB_GADGET_DELAYED_STATUS) {
933 req->length = value; 981 req->length = value;
934 req->zero = value < w_length; 982 req->zero = value < w_length;
935 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); 983 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
@@ -938,6 +986,10 @@ unknown:
938 req->status = 0; 986 req->status = 0;
939 composite_setup_complete(gadget->ep0, req); 987 composite_setup_complete(gadget->ep0, req);
940 } 988 }
989 } else if (value == USB_GADGET_DELAYED_STATUS && w_length != 0) {
990 WARN(cdev,
991 "%s: Delayed status not supported for w_length != 0",
992 __func__);
941 } 993 }
942 994
943done: 995done:
@@ -1019,32 +1071,23 @@ composite_unbind(struct usb_gadget *gadget)
1019 kfree(cdev->req->buf); 1071 kfree(cdev->req->buf);
1020 usb_ep_free_request(gadget->ep0, cdev->req); 1072 usb_ep_free_request(gadget->ep0, cdev->req);
1021 } 1073 }
1074 device_remove_file(&gadget->dev, &dev_attr_suspended);
1022 kfree(cdev); 1075 kfree(cdev);
1023 set_gadget_data(gadget, NULL); 1076 set_gadget_data(gadget, NULL);
1024 device_remove_file(&gadget->dev, &dev_attr_suspended);
1025 composite = NULL; 1077 composite = NULL;
1026} 1078}
1027 1079
1028static void 1080static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
1029string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s)
1030{ 1081{
1031 struct usb_string *str = tab->strings; 1082 if (!*desc) {
1032 1083 int ret = usb_string_id(cdev);
1033 for (str = tab->strings; str->s; str++) { 1084 if (unlikely(ret < 0))
1034 if (str->id == id) { 1085 WARNING(cdev, "failed to override string ID\n");
1035 str->s = s; 1086 else
1036 return; 1087 *desc = ret;
1037 }
1038 } 1088 }
1039}
1040 1089
1041static void 1090 return *desc;
1042string_override(struct usb_gadget_strings **tab, u8 id, const char *s)
1043{
1044 while (*tab) {
1045 string_override_one(*tab, id, s);
1046 tab++;
1047 }
1048} 1091}
1049 1092
1050static int composite_bind(struct usb_gadget *gadget) 1093static int composite_bind(struct usb_gadget *gadget)
@@ -1074,7 +1117,13 @@ static int composite_bind(struct usb_gadget *gadget)
1074 cdev->bufsiz = USB_BUFSIZ; 1117 cdev->bufsiz = USB_BUFSIZ;
1075 cdev->driver = composite; 1118 cdev->driver = composite;
1076 1119
1077 usb_gadget_set_selfpowered(gadget); 1120 /*
1121 * As per USB compliance update, a device that is actively drawing
1122 * more than 100mA from USB must report itself as bus-powered in
1123 * the GetStatus(DEVICE) call.
1124 */
1125 if (CONFIG_USB_GADGET_VBUS_DRAW <= USB_SELF_POWER_VBUS_MAX_DRAW)
1126 usb_gadget_set_selfpowered(gadget);
1078 1127
1079 /* interface and string IDs start at zero via kzalloc. 1128 /* interface and string IDs start at zero via kzalloc.
1080 * we force endpoints to start unassigned; few controller 1129 * we force endpoints to start unassigned; few controller
@@ -1082,38 +1131,53 @@ static int composite_bind(struct usb_gadget *gadget)
1082 */ 1131 */
1083 usb_ep_autoconfig_reset(cdev->gadget); 1132 usb_ep_autoconfig_reset(cdev->gadget);
1084 1133
1085 /* standardized runtime overrides for device ID data */
1086 if (idVendor)
1087 cdev->desc.idVendor = cpu_to_le16(idVendor);
1088 if (idProduct)
1089 cdev->desc.idProduct = cpu_to_le16(idProduct);
1090 if (bcdDevice)
1091 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1092
1093 /* composite gadget needs to assign strings for whole device (like 1134 /* composite gadget needs to assign strings for whole device (like
1094 * serial number), register function drivers, potentially update 1135 * serial number), register function drivers, potentially update
1095 * power state and consumption, etc 1136 * power state and consumption, etc
1096 */ 1137 */
1097 status = composite->bind(cdev); 1138 status = composite_gadget_bind(cdev);
1098 if (status < 0) 1139 if (status < 0)
1099 goto fail; 1140 goto fail;
1100 1141
1101 cdev->desc = *composite->dev; 1142 cdev->desc = *composite->dev;
1102 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket; 1143 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1103 1144
1104 /* strings can't be assigned before bind() allocates the 1145 /* standardized runtime overrides for device ID data */
1105 * releavnt identifiers 1146 if (idVendor)
1106 */ 1147 cdev->desc.idVendor = cpu_to_le16(idVendor);
1107 if (cdev->desc.iManufacturer && iManufacturer) 1148 if (idProduct)
1108 string_override(composite->strings, 1149 cdev->desc.idProduct = cpu_to_le16(idProduct);
1109 cdev->desc.iManufacturer, iManufacturer); 1150 if (bcdDevice)
1110 if (cdev->desc.iProduct && iProduct) 1151 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1111 string_override(composite->strings, 1152
1112 cdev->desc.iProduct, iProduct); 1153 /* string overrides */
1113 if (cdev->desc.iSerialNumber && iSerialNumber) 1154 if (iManufacturer || !cdev->desc.iManufacturer) {
1114 string_override(composite->strings, 1155 if (!iManufacturer && !composite->iManufacturer &&
1115 cdev->desc.iSerialNumber, iSerialNumber); 1156 !*composite_manufacturer)
1157 snprintf(composite_manufacturer,
1158 sizeof composite_manufacturer,
1159 "%s %s with %s",
1160 init_utsname()->sysname,
1161 init_utsname()->release,
1162 gadget->name);
1163
1164 cdev->manufacturer_override =
1165 override_id(cdev, &cdev->desc.iManufacturer);
1166 }
1167
1168 if (iProduct || (!cdev->desc.iProduct && composite->iProduct))
1169 cdev->product_override =
1170 override_id(cdev, &cdev->desc.iProduct);
1171
1172 if (iSerialNumber)
1173 cdev->serial_override =
1174 override_id(cdev, &cdev->desc.iSerialNumber);
1116 1175
1176 /* has userspace failed to provide a serial number? */
1177 if (composite->needs_serial && !cdev->desc.iSerialNumber)
1178 WARNING(cdev, "userspace failed to provide iSerialNumber\n");
1179
1180 /* finish up */
1117 status = device_create_file(&gadget->dev, &dev_attr_suspended); 1181 status = device_create_file(&gadget->dev, &dev_attr_suspended);
1118 if (status) 1182 if (status)
1119 goto fail; 1183 goto fail;
@@ -1148,6 +1212,8 @@ composite_suspend(struct usb_gadget *gadget)
1148 composite->suspend(cdev); 1212 composite->suspend(cdev);
1149 1213
1150 cdev->suspended = 1; 1214 cdev->suspended = 1;
1215
1216 usb_gadget_vbus_draw(gadget, 2);
1151} 1217}
1152 1218
1153static void 1219static void
@@ -1155,6 +1221,7 @@ composite_resume(struct usb_gadget *gadget)
1155{ 1221{
1156 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1222 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1157 struct usb_function *f; 1223 struct usb_function *f;
1224 u8 maxpower;
1158 1225
1159 /* REVISIT: should we have config level 1226 /* REVISIT: should we have config level
1160 * suspend/resume callbacks? 1227 * suspend/resume callbacks?
@@ -1167,6 +1234,11 @@ composite_resume(struct usb_gadget *gadget)
1167 if (f->resume) 1234 if (f->resume)
1168 f->resume(f); 1235 f->resume(f);
1169 } 1236 }
1237
1238 maxpower = cdev->config->bMaxPower;
1239
1240 usb_gadget_vbus_draw(gadget, maxpower ?
1241 (2 * maxpower) : CONFIG_USB_GADGET_VBUS_DRAW);
1170 } 1242 }
1171 1243
1172 cdev->suspended = 0; 1244 cdev->suspended = 0;
@@ -1177,7 +1249,6 @@ composite_resume(struct usb_gadget *gadget)
1177static struct usb_gadget_driver composite_driver = { 1249static struct usb_gadget_driver composite_driver = {
1178 .speed = USB_SPEED_HIGH, 1250 .speed = USB_SPEED_HIGH,
1179 1251
1180 .bind = composite_bind,
1181 .unbind = composite_unbind, 1252 .unbind = composite_unbind,
1182 1253
1183 .setup = composite_setup, 1254 .setup = composite_setup,
@@ -1192,8 +1263,12 @@ static struct usb_gadget_driver composite_driver = {
1192}; 1263};
1193 1264
1194/** 1265/**
1195 * usb_composite_register() - register a composite driver 1266 * usb_composite_probe() - register a composite driver
1196 * @driver: the driver to register 1267 * @driver: the driver to register
1268 * @bind: the callback used to allocate resources that are shared across the
1269 * whole device, such as string IDs, and add its configurations using
1270 * @usb_add_config(). This may fail by returning a negative errno
1271 * value; it should return zero on successful initialization.
1197 * Context: single threaded during gadget setup 1272 * Context: single threaded during gadget setup
1198 * 1273 *
1199 * This function is used to register drivers using the composite driver 1274 * This function is used to register drivers using the composite driver
@@ -1206,18 +1281,22 @@ static struct usb_gadget_driver composite_driver = {
1206 * while it was binding. That would usually be done in order to wait for 1281 * while it was binding. That would usually be done in order to wait for
1207 * some userspace participation. 1282 * some userspace participation.
1208 */ 1283 */
1209int usb_composite_register(struct usb_composite_driver *driver) 1284int usb_composite_probe(struct usb_composite_driver *driver,
1285 int (*bind)(struct usb_composite_dev *cdev))
1210{ 1286{
1211 if (!driver || !driver->dev || !driver->bind || composite) 1287 if (!driver || !driver->dev || !bind || composite)
1212 return -EINVAL; 1288 return -EINVAL;
1213 1289
1214 if (!driver->name) 1290 if (!driver->name)
1215 driver->name = "composite"; 1291 driver->name = "composite";
1292 if (!driver->iProduct)
1293 driver->iProduct = driver->name;
1216 composite_driver.function = (char *) driver->name; 1294 composite_driver.function = (char *) driver->name;
1217 composite_driver.driver.name = driver->name; 1295 composite_driver.driver.name = driver->name;
1218 composite = driver; 1296 composite = driver;
1297 composite_gadget_bind = bind;
1219 1298
1220 return usb_gadget_register_driver(&composite_driver); 1299 return usb_gadget_probe_driver(&composite_driver, composite_bind);
1221} 1300}
1222 1301
1223/** 1302/**
@@ -1233,3 +1312,40 @@ void usb_composite_unregister(struct usb_composite_driver *driver)
1233 return; 1312 return;
1234 usb_gadget_unregister_driver(&composite_driver); 1313 usb_gadget_unregister_driver(&composite_driver);
1235} 1314}
1315
1316/**
1317 * usb_composite_setup_continue() - Continue with the control transfer
1318 * @cdev: the composite device who's control transfer was kept waiting
1319 *
1320 * This function must be called by the USB function driver to continue
1321 * with the control transfer's data/status stage in case it had requested to
1322 * delay the data/status stages. A USB function's setup handler (e.g. set_alt())
1323 * can request the composite framework to delay the setup request's data/status
1324 * stages by returning USB_GADGET_DELAYED_STATUS.
1325 */
1326void usb_composite_setup_continue(struct usb_composite_dev *cdev)
1327{
1328 int value;
1329 struct usb_request *req = cdev->req;
1330 unsigned long flags;
1331
1332 DBG(cdev, "%s\n", __func__);
1333 spin_lock_irqsave(&cdev->lock, flags);
1334
1335 if (cdev->delayed_status == 0) {
1336 WARN(cdev, "%s: Unexpected call\n", __func__);
1337
1338 } else if (--cdev->delayed_status == 0) {
1339 DBG(cdev, "%s: Completing delayed status\n", __func__);
1340 req->length = 0;
1341 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
1342 if (value < 0) {
1343 DBG(cdev, "ep_queue --> %d\n", value);
1344 req->status = 0;
1345 composite_setup_complete(cdev->gadget->ep0, req);
1346 }
1347 }
1348
1349 spin_unlock_irqrestore(&cdev->lock, flags);
1350}
1351
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c
index 0ed50a2c0a36..dbe92ee88477 100644
--- a/drivers/usb/gadget/dbgp.c
+++ b/drivers/usb/gadget/dbgp.c
@@ -261,8 +261,8 @@ static int __init dbgp_configure_endpoints(struct usb_gadget *gadget)
261 o_desc.wMaxPacketSize = 261 o_desc.wMaxPacketSize =
262 __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE); 262 __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
263 263
264 dbg_desc.bDebugInEndpoint = i_desc.bEndpointAddress & 0x7f; 264 dbg_desc.bDebugInEndpoint = i_desc.bEndpointAddress;
265 dbg_desc.bDebugOutEndpoint = o_desc.bEndpointAddress & 0x7f; 265 dbg_desc.bDebugOutEndpoint = o_desc.bEndpointAddress;
266 266
267#ifdef CONFIG_USB_G_DBGP_SERIAL 267#ifdef CONFIG_USB_G_DBGP_SERIAL
268 dbgp.serial->in = dbgp.i_ep; 268 dbgp.serial->in = dbgp.i_ep;
@@ -312,6 +312,7 @@ static int __init dbgp_bind(struct usb_gadget *gadget)
312 312
313 dbgp.req->length = DBGP_REQ_EP0_LEN; 313 dbgp.req->length = DBGP_REQ_EP0_LEN;
314 gadget->ep0->driver_data = gadget; 314 gadget->ep0->driver_data = gadget;
315 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
315 316
316#ifdef CONFIG_USB_G_DBGP_SERIAL 317#ifdef CONFIG_USB_G_DBGP_SERIAL
317 dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL); 318 dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL);
@@ -350,9 +351,9 @@ static int dbgp_setup(struct usb_gadget *gadget,
350 u8 request = ctrl->bRequest; 351 u8 request = ctrl->bRequest;
351 u16 value = le16_to_cpu(ctrl->wValue); 352 u16 value = le16_to_cpu(ctrl->wValue);
352 u16 length = le16_to_cpu(ctrl->wLength); 353 u16 length = le16_to_cpu(ctrl->wLength);
353 int err = 0; 354 int err = -EOPNOTSUPP;
354 void *data; 355 void *data = NULL;
355 u16 len; 356 u16 len = 0;
356 357
357 gadget->ep0->driver_data = gadget; 358 gadget->ep0->driver_data = gadget;
358 359
@@ -371,10 +372,9 @@ static int dbgp_setup(struct usb_gadget *gadget,
371 default: 372 default:
372 goto fail; 373 goto fail;
373 } 374 }
375 err = 0;
374 } else if (request == USB_REQ_SET_FEATURE && 376 } else if (request == USB_REQ_SET_FEATURE &&
375 value == USB_DEVICE_DEBUG_MODE) { 377 value == USB_DEVICE_DEBUG_MODE) {
376 len = 0;
377 data = NULL;
378 dev_dbg(&dbgp.gadget->dev, "setup: feat debug\n"); 378 dev_dbg(&dbgp.gadget->dev, "setup: feat debug\n");
379#ifdef CONFIG_USB_G_DBGP_PRINTK 379#ifdef CONFIG_USB_G_DBGP_PRINTK
380 err = dbgp_enable_ep(); 380 err = dbgp_enable_ep();
@@ -386,15 +386,13 @@ static int dbgp_setup(struct usb_gadget *gadget,
386 } else 386 } else
387 goto fail; 387 goto fail;
388 388
389 if (len >= 0) { 389 req->length = min(length, len);
390 req->length = min(length, len); 390 req->zero = len < req->length;
391 req->zero = len < req->length; 391 if (data && req->length)
392 if (data && req->length) 392 memcpy(req->buf, data, req->length);
393 memcpy(req->buf, data, req->length);
394 393
395 req->complete = dbgp_setup_complete; 394 req->complete = dbgp_setup_complete;
396 return usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); 395 return usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
397 }
398 396
399fail: 397fail:
400 dev_dbg(&dbgp.gadget->dev, 398 dev_dbg(&dbgp.gadget->dev,
@@ -405,7 +403,6 @@ fail:
405static struct usb_gadget_driver dbgp_driver = { 403static struct usb_gadget_driver dbgp_driver = {
406 .function = "dbgp", 404 .function = "dbgp",
407 .speed = USB_SPEED_HIGH, 405 .speed = USB_SPEED_HIGH,
408 .bind = dbgp_bind,
409 .unbind = dbgp_unbind, 406 .unbind = dbgp_unbind,
410 .setup = dbgp_setup, 407 .setup = dbgp_setup,
411 .disconnect = dbgp_disconnect, 408 .disconnect = dbgp_disconnect,
@@ -417,7 +414,7 @@ static struct usb_gadget_driver dbgp_driver = {
417 414
418static int __init dbgp_init(void) 415static int __init dbgp_init(void)
419{ 416{
420 return usb_gadget_register_driver(&dbgp_driver); 417 return usb_gadget_probe_driver(&dbgp_driver, dbgp_bind);
421} 418}
422 419
423static void __exit dbgp_exit(void) 420static void __exit dbgp_exit(void)
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index dc6546248ed9..d3dcabc1a5fc 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -748,7 +748,8 @@ static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
748 */ 748 */
749 749
750int 750int
751usb_gadget_register_driver (struct usb_gadget_driver *driver) 751usb_gadget_probe_driver(struct usb_gadget_driver *driver,
752 int (*bind)(struct usb_gadget *))
752{ 753{
753 struct dummy *dum = the_controller; 754 struct dummy *dum = the_controller;
754 int retval, i; 755 int retval, i;
@@ -757,8 +758,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
757 return -EINVAL; 758 return -EINVAL;
758 if (dum->driver) 759 if (dum->driver)
759 return -EBUSY; 760 return -EBUSY;
760 if (!driver->bind || !driver->setup 761 if (!bind || !driver->setup || driver->speed == USB_SPEED_UNKNOWN)
761 || driver->speed == USB_SPEED_UNKNOWN)
762 return -EINVAL; 762 return -EINVAL;
763 763
764 /* 764 /*
@@ -796,7 +796,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
796 dum->gadget.dev.driver = &driver->driver; 796 dum->gadget.dev.driver = &driver->driver;
797 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", 797 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
798 driver->driver.name); 798 driver->driver.name);
799 retval = driver->bind(&dum->gadget); 799 retval = bind(&dum->gadget);
800 if (retval) { 800 if (retval) {
801 dum->driver = NULL; 801 dum->driver = NULL;
802 dum->gadget.dev.driver = NULL; 802 dum->gadget.dev.driver = NULL;
@@ -812,7 +812,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
812 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 812 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
813 return 0; 813 return 0;
814} 814}
815EXPORT_SYMBOL (usb_gadget_register_driver); 815EXPORT_SYMBOL(usb_gadget_probe_driver);
816 816
817int 817int
818usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 818usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
@@ -874,6 +874,8 @@ static int dummy_udc_probe (struct platform_device *pdev)
874 struct dummy *dum = the_controller; 874 struct dummy *dum = the_controller;
875 int rc; 875 int rc;
876 876
877 usb_get_hcd(dummy_to_hcd(dum));
878
877 dum->gadget.name = gadget_name; 879 dum->gadget.name = gadget_name;
878 dum->gadget.ops = &dummy_ops; 880 dum->gadget.ops = &dummy_ops;
879 dum->gadget.is_dualspeed = 1; 881 dum->gadget.is_dualspeed = 1;
@@ -885,15 +887,16 @@ static int dummy_udc_probe (struct platform_device *pdev)
885 dum->gadget.dev.parent = &pdev->dev; 887 dum->gadget.dev.parent = &pdev->dev;
886 dum->gadget.dev.release = dummy_gadget_release; 888 dum->gadget.dev.release = dummy_gadget_release;
887 rc = device_register (&dum->gadget.dev); 889 rc = device_register (&dum->gadget.dev);
888 if (rc < 0) 890 if (rc < 0) {
891 put_device(&dum->gadget.dev);
889 return rc; 892 return rc;
893 }
890 894
891 usb_get_hcd (dummy_to_hcd (dum));
892
893 platform_set_drvdata (pdev, dum);
894 rc = device_create_file (&dum->gadget.dev, &dev_attr_function); 895 rc = device_create_file (&dum->gadget.dev, &dev_attr_function);
895 if (rc < 0) 896 if (rc < 0)
896 device_unregister (&dum->gadget.dev); 897 device_unregister (&dum->gadget.dev);
898 else
899 platform_set_drvdata(pdev, dum);
897 return rc; 900 return rc;
898} 901}
899 902
@@ -1195,6 +1198,139 @@ static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address)
1195#define Ep_Request (USB_TYPE_STANDARD | USB_RECIP_ENDPOINT) 1198#define Ep_Request (USB_TYPE_STANDARD | USB_RECIP_ENDPOINT)
1196#define Ep_InRequest (Ep_Request | USB_DIR_IN) 1199#define Ep_InRequest (Ep_Request | USB_DIR_IN)
1197 1200
1201
1202/**
1203 * handle_control_request() - handles all control transfers
1204 * @dum: pointer to dummy (the_controller)
1205 * @urb: the urb request to handle
1206 * @setup: pointer to the setup data for a USB device control
1207 * request
1208 * @status: pointer to request handling status
1209 *
1210 * Return 0 - if the request was handled
1211 * 1 - if the request wasn't handles
1212 * error code on error
1213 */
1214static int handle_control_request(struct dummy *dum, struct urb *urb,
1215 struct usb_ctrlrequest *setup,
1216 int *status)
1217{
1218 struct dummy_ep *ep2;
1219 int ret_val = 1;
1220 unsigned w_index;
1221 unsigned w_value;
1222
1223 w_index = le16_to_cpu(setup->wIndex);
1224 w_value = le16_to_cpu(setup->wValue);
1225 switch (setup->bRequest) {
1226 case USB_REQ_SET_ADDRESS:
1227 if (setup->bRequestType != Dev_Request)
1228 break;
1229 dum->address = w_value;
1230 *status = 0;
1231 dev_dbg(udc_dev(dum), "set_address = %d\n",
1232 w_value);
1233 ret_val = 0;
1234 break;
1235 case USB_REQ_SET_FEATURE:
1236 if (setup->bRequestType == Dev_Request) {
1237 ret_val = 0;
1238 switch (w_value) {
1239 case USB_DEVICE_REMOTE_WAKEUP:
1240 break;
1241 case USB_DEVICE_B_HNP_ENABLE:
1242 dum->gadget.b_hnp_enable = 1;
1243 break;
1244 case USB_DEVICE_A_HNP_SUPPORT:
1245 dum->gadget.a_hnp_support = 1;
1246 break;
1247 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1248 dum->gadget.a_alt_hnp_support = 1;
1249 break;
1250 default:
1251 ret_val = -EOPNOTSUPP;
1252 }
1253 if (ret_val == 0) {
1254 dum->devstatus |= (1 << w_value);
1255 *status = 0;
1256 }
1257 } else if (setup->bRequestType == Ep_Request) {
1258 /* endpoint halt */
1259 ep2 = find_endpoint(dum, w_index);
1260 if (!ep2 || ep2->ep.name == ep0name) {
1261 ret_val = -EOPNOTSUPP;
1262 break;
1263 }
1264 ep2->halted = 1;
1265 ret_val = 0;
1266 *status = 0;
1267 }
1268 break;
1269 case USB_REQ_CLEAR_FEATURE:
1270 if (setup->bRequestType == Dev_Request) {
1271 ret_val = 0;
1272 switch (w_value) {
1273 case USB_DEVICE_REMOTE_WAKEUP:
1274 w_value = USB_DEVICE_REMOTE_WAKEUP;
1275 break;
1276 default:
1277 ret_val = -EOPNOTSUPP;
1278 break;
1279 }
1280 if (ret_val == 0) {
1281 dum->devstatus &= ~(1 << w_value);
1282 *status = 0;
1283 }
1284 } else if (setup->bRequestType == Ep_Request) {
1285 /* endpoint halt */
1286 ep2 = find_endpoint(dum, w_index);
1287 if (!ep2) {
1288 ret_val = -EOPNOTSUPP;
1289 break;
1290 }
1291 if (!ep2->wedged)
1292 ep2->halted = 0;
1293 ret_val = 0;
1294 *status = 0;
1295 }
1296 break;
1297 case USB_REQ_GET_STATUS:
1298 if (setup->bRequestType == Dev_InRequest
1299 || setup->bRequestType == Intf_InRequest
1300 || setup->bRequestType == Ep_InRequest) {
1301 char *buf;
1302 /*
1303 * device: remote wakeup, selfpowered
1304 * interface: nothing
1305 * endpoint: halt
1306 */
1307 buf = (char *)urb->transfer_buffer;
1308 if (urb->transfer_buffer_length > 0) {
1309 if (setup->bRequestType == Ep_InRequest) {
1310 ep2 = find_endpoint(dum, w_index);
1311 if (!ep2) {
1312 ret_val = -EOPNOTSUPP;
1313 break;
1314 }
1315 buf[0] = ep2->halted;
1316 } else if (setup->bRequestType ==
1317 Dev_InRequest) {
1318 buf[0] = (u8)dum->devstatus;
1319 } else
1320 buf[0] = 0;
1321 }
1322 if (urb->transfer_buffer_length > 1)
1323 buf[1] = 0;
1324 urb->actual_length = min_t(u32, 2,
1325 urb->transfer_buffer_length);
1326 ret_val = 0;
1327 *status = 0;
1328 }
1329 break;
1330 }
1331 return ret_val;
1332}
1333
1198/* drive both sides of the transfers; looks like irq handlers to 1334/* drive both sides of the transfers; looks like irq handlers to
1199 * both drivers except the callbacks aren't in_irq(). 1335 * both drivers except the callbacks aren't in_irq().
1200 */ 1336 */
@@ -1297,14 +1433,8 @@ restart:
1297 if (ep == &dum->ep [0] && ep->setup_stage) { 1433 if (ep == &dum->ep [0] && ep->setup_stage) {
1298 struct usb_ctrlrequest setup; 1434 struct usb_ctrlrequest setup;
1299 int value = 1; 1435 int value = 1;
1300 struct dummy_ep *ep2;
1301 unsigned w_index;
1302 unsigned w_value;
1303 1436
1304 setup = *(struct usb_ctrlrequest*) urb->setup_packet; 1437 setup = *(struct usb_ctrlrequest*) urb->setup_packet;
1305 w_index = le16_to_cpu(setup.wIndex);
1306 w_value = le16_to_cpu(setup.wValue);
1307
1308 /* paranoia, in case of stale queued data */ 1438 /* paranoia, in case of stale queued data */
1309 list_for_each_entry (req, &ep->queue, queue) { 1439 list_for_each_entry (req, &ep->queue, queue) {
1310 list_del_init (&req->queue); 1440 list_del_init (&req->queue);
@@ -1326,117 +1456,9 @@ restart:
1326 ep->last_io = jiffies; 1456 ep->last_io = jiffies;
1327 ep->setup_stage = 0; 1457 ep->setup_stage = 0;
1328 ep->halted = 0; 1458 ep->halted = 0;
1329 switch (setup.bRequest) {
1330 case USB_REQ_SET_ADDRESS:
1331 if (setup.bRequestType != Dev_Request)
1332 break;
1333 dum->address = w_value;
1334 status = 0;
1335 dev_dbg (udc_dev(dum), "set_address = %d\n",
1336 w_value);
1337 value = 0;
1338 break;
1339 case USB_REQ_SET_FEATURE:
1340 if (setup.bRequestType == Dev_Request) {
1341 value = 0;
1342 switch (w_value) {
1343 case USB_DEVICE_REMOTE_WAKEUP:
1344 break;
1345 case USB_DEVICE_B_HNP_ENABLE:
1346 dum->gadget.b_hnp_enable = 1;
1347 break;
1348 case USB_DEVICE_A_HNP_SUPPORT:
1349 dum->gadget.a_hnp_support = 1;
1350 break;
1351 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1352 dum->gadget.a_alt_hnp_support
1353 = 1;
1354 break;
1355 default:
1356 value = -EOPNOTSUPP;
1357 }
1358 if (value == 0) {
1359 dum->devstatus |=
1360 (1 << w_value);
1361 status = 0;
1362 }
1363 1459
1364 } else if (setup.bRequestType == Ep_Request) { 1460 value = handle_control_request(dum, urb, &setup,
1365 // endpoint halt 1461 &status);
1366 ep2 = find_endpoint (dum, w_index);
1367 if (!ep2 || ep2->ep.name == ep0name) {
1368 value = -EOPNOTSUPP;
1369 break;
1370 }
1371 ep2->halted = 1;
1372 value = 0;
1373 status = 0;
1374 }
1375 break;
1376 case USB_REQ_CLEAR_FEATURE:
1377 if (setup.bRequestType == Dev_Request) {
1378 switch (w_value) {
1379 case USB_DEVICE_REMOTE_WAKEUP:
1380 dum->devstatus &= ~(1 <<
1381 USB_DEVICE_REMOTE_WAKEUP);
1382 value = 0;
1383 status = 0;
1384 break;
1385 default:
1386 value = -EOPNOTSUPP;
1387 break;
1388 }
1389 } else if (setup.bRequestType == Ep_Request) {
1390 // endpoint halt
1391 ep2 = find_endpoint (dum, w_index);
1392 if (!ep2) {
1393 value = -EOPNOTSUPP;
1394 break;
1395 }
1396 if (!ep2->wedged)
1397 ep2->halted = 0;
1398 value = 0;
1399 status = 0;
1400 }
1401 break;
1402 case USB_REQ_GET_STATUS:
1403 if (setup.bRequestType == Dev_InRequest
1404 || setup.bRequestType
1405 == Intf_InRequest
1406 || setup.bRequestType
1407 == Ep_InRequest
1408 ) {
1409 char *buf;
1410
1411 // device: remote wakeup, selfpowered
1412 // interface: nothing
1413 // endpoint: halt
1414 buf = (char *)urb->transfer_buffer;
1415 if (urb->transfer_buffer_length > 0) {
1416 if (setup.bRequestType ==
1417 Ep_InRequest) {
1418 ep2 = find_endpoint (dum, w_index);
1419 if (!ep2) {
1420 value = -EOPNOTSUPP;
1421 break;
1422 }
1423 buf [0] = ep2->halted;
1424 } else if (setup.bRequestType ==
1425 Dev_InRequest) {
1426 buf [0] = (u8)
1427 dum->devstatus;
1428 } else
1429 buf [0] = 0;
1430 }
1431 if (urb->transfer_buffer_length > 1)
1432 buf [1] = 0;
1433 urb->actual_length = min_t(u32, 2,
1434 urb->transfer_buffer_length);
1435 value = 0;
1436 status = 0;
1437 }
1438 break;
1439 }
1440 1462
1441 /* gadget driver handles all other requests. block 1463 /* gadget driver handles all other requests. block
1442 * until setup() returns; no reentrancy issues etc. 1464 * until setup() returns; no reentrancy issues etc.
@@ -1572,8 +1594,8 @@ hub_descriptor (struct usb_hub_descriptor *desc)
1572 desc->bDescLength = 9; 1594 desc->bDescLength = 9;
1573 desc->wHubCharacteristics = cpu_to_le16(0x0001); 1595 desc->wHubCharacteristics = cpu_to_le16(0x0001);
1574 desc->bNbrPorts = 1; 1596 desc->bNbrPorts = 1;
1575 desc->bitmap [0] = 0xff; 1597 desc->u.hs.DeviceRemovable[0] = 0xff;
1576 desc->bitmap [1] = 0xff; 1598 desc->u.hs.DeviceRemovable[1] = 0xff;
1577} 1599}
1578 1600
1579static int dummy_hub_control ( 1601static int dummy_hub_control (
@@ -1884,6 +1906,7 @@ static int dummy_hcd_probe(struct platform_device *pdev)
1884 if (!hcd) 1906 if (!hcd)
1885 return -ENOMEM; 1907 return -ENOMEM;
1886 the_controller = hcd_to_dummy (hcd); 1908 the_controller = hcd_to_dummy (hcd);
1909 hcd->has_tt = 1;
1887 1910
1888 retval = usb_add_hcd(hcd, 0, 0); 1911 retval = usb_add_hcd(hcd, 0, 0);
1889 if (retval != 0) { 1912 if (retval != 0) {
@@ -1974,11 +1997,29 @@ static int __init init (void)
1974 retval = platform_device_add(the_hcd_pdev); 1997 retval = platform_device_add(the_hcd_pdev);
1975 if (retval < 0) 1998 if (retval < 0)
1976 goto err_add_hcd; 1999 goto err_add_hcd;
2000 if (!the_controller) {
2001 /*
2002 * The hcd was added successfully but its probe function failed
2003 * for some reason.
2004 */
2005 retval = -EINVAL;
2006 goto err_add_udc;
2007 }
1977 retval = platform_device_add(the_udc_pdev); 2008 retval = platform_device_add(the_udc_pdev);
1978 if (retval < 0) 2009 if (retval < 0)
1979 goto err_add_udc; 2010 goto err_add_udc;
2011 if (!platform_get_drvdata(the_udc_pdev)) {
2012 /*
2013 * The udc was added successfully but its probe function failed
2014 * for some reason.
2015 */
2016 retval = -EINVAL;
2017 goto err_probe_udc;
2018 }
1980 return retval; 2019 return retval;
1981 2020
2021err_probe_udc:
2022 platform_device_del(the_udc_pdev);
1982err_add_udc: 2023err_add_udc:
1983 platform_device_del(the_hcd_pdev); 2024 platform_device_del(the_hcd_pdev);
1984err_add_hcd: 2025err_add_hcd:
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 8a832488ccdd..9b7360ff5aa7 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -128,6 +128,13 @@ ep_matches (
128 } 128 }
129 } 129 }
130 130
131 /*
132 * If the protocol driver hasn't yet decided on wMaxPacketSize
133 * and wants to know the maximum possible, provide the info.
134 */
135 if (desc->wMaxPacketSize == 0)
136 desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket);
137
131 /* endpoint maxpacket size is an input parameter, except for bulk 138 /* endpoint maxpacket size is an input parameter, except for bulk
132 * where it's an output parameter representing the full speed limit. 139 * where it's an output parameter representing the full speed limit.
133 * the usb spec fixes high speed bulk maxpacket at 512 bytes. 140 * the usb spec fixes high speed bulk maxpacket at 512 bytes.
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 114fa024c22c..1690c9d68256 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -237,7 +237,7 @@ static u8 hostaddr[ETH_ALEN];
237 * the first one present. That's to make Microsoft's drivers happy, 237 * the first one present. That's to make Microsoft's drivers happy,
238 * and to follow DOCSIS 1.0 (cable modem standard). 238 * and to follow DOCSIS 1.0 (cable modem standard).
239 */ 239 */
240static int __ref rndis_do_config(struct usb_configuration *c) 240static int __init rndis_do_config(struct usb_configuration *c)
241{ 241{
242 /* FIXME alloc iConfiguration string, set it in c->strings */ 242 /* FIXME alloc iConfiguration string, set it in c->strings */
243 243
@@ -251,7 +251,6 @@ static int __ref rndis_do_config(struct usb_configuration *c)
251 251
252static struct usb_configuration rndis_config_driver = { 252static struct usb_configuration rndis_config_driver = {
253 .label = "RNDIS", 253 .label = "RNDIS",
254 .bind = rndis_do_config,
255 .bConfigurationValue = 2, 254 .bConfigurationValue = 2,
256 /* .iConfiguration = DYNAMIC */ 255 /* .iConfiguration = DYNAMIC */
257 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 256 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -270,7 +269,7 @@ MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
270/* 269/*
271 * We _always_ have an ECM, CDC Subset, or EEM configuration. 270 * We _always_ have an ECM, CDC Subset, or EEM configuration.
272 */ 271 */
273static int __ref eth_do_config(struct usb_configuration *c) 272static int __init eth_do_config(struct usb_configuration *c)
274{ 273{
275 /* FIXME alloc iConfiguration string, set it in c->strings */ 274 /* FIXME alloc iConfiguration string, set it in c->strings */
276 275
@@ -289,7 +288,6 @@ static int __ref eth_do_config(struct usb_configuration *c)
289 288
290static struct usb_configuration eth_config_driver = { 289static struct usb_configuration eth_config_driver = {
291 /* .label = f(hardware) */ 290 /* .label = f(hardware) */
292 .bind = eth_do_config,
293 .bConfigurationValue = 1, 291 .bConfigurationValue = 1,
294 /* .iConfiguration = DYNAMIC */ 292 /* .iConfiguration = DYNAMIC */
295 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 293 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -297,7 +295,7 @@ static struct usb_configuration eth_config_driver = {
297 295
298/*-------------------------------------------------------------------------*/ 296/*-------------------------------------------------------------------------*/
299 297
300static int __ref eth_bind(struct usb_composite_dev *cdev) 298static int __init eth_bind(struct usb_composite_dev *cdev)
301{ 299{
302 int gcnum; 300 int gcnum;
303 struct usb_gadget *gadget = cdev->gadget; 301 struct usb_gadget *gadget = cdev->gadget;
@@ -373,12 +371,13 @@ static int __ref eth_bind(struct usb_composite_dev *cdev)
373 371
374 /* register our configuration(s); RNDIS first, if it's used */ 372 /* register our configuration(s); RNDIS first, if it's used */
375 if (has_rndis()) { 373 if (has_rndis()) {
376 status = usb_add_config(cdev, &rndis_config_driver); 374 status = usb_add_config(cdev, &rndis_config_driver,
375 rndis_do_config);
377 if (status < 0) 376 if (status < 0)
378 goto fail; 377 goto fail;
379 } 378 }
380 379
381 status = usb_add_config(cdev, &eth_config_driver); 380 status = usb_add_config(cdev, &eth_config_driver, eth_do_config);
382 if (status < 0) 381 if (status < 0)
383 goto fail; 382 goto fail;
384 383
@@ -402,7 +401,6 @@ static struct usb_composite_driver eth_driver = {
402 .name = "g_ether", 401 .name = "g_ether",
403 .dev = &device_desc, 402 .dev = &device_desc,
404 .strings = dev_strings, 403 .strings = dev_strings,
405 .bind = eth_bind,
406 .unbind = __exit_p(eth_unbind), 404 .unbind = __exit_p(eth_unbind),
407}; 405};
408 406
@@ -412,7 +410,7 @@ MODULE_LICENSE("GPL");
412 410
413static int __init init(void) 411static int __init init(void)
414{ 412{
415 return usb_composite_register(&eth_driver); 413 return usb_composite_probe(&eth_driver, eth_bind);
416} 414}
417module_init(init); 415module_init(init);
418 416
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index d47a123f15ab..bd6226cbae86 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -111,7 +111,7 @@ acm_iad_descriptor = {
111 .bInterfaceCount = 2, // control + data 111 .bInterfaceCount = 2, // control + data
112 .bFunctionClass = USB_CLASS_COMM, 112 .bFunctionClass = USB_CLASS_COMM,
113 .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, 113 .bFunctionSubClass = USB_CDC_SUBCLASS_ACM,
114 .bFunctionProtocol = USB_CDC_PROTO_NONE, 114 .bFunctionProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
115 /* .iFunction = DYNAMIC */ 115 /* .iFunction = DYNAMIC */
116}; 116};
117 117
diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c
index 1f48ceb55a77..8ee330a2ab58 100644
--- a/drivers/usb/gadget/f_audio.c
+++ b/drivers/usb/gadget/f_audio.c
@@ -177,7 +177,7 @@ static struct uac_format_type_i_discrete_descriptor_1 as_type_i_desc = {
177}; 177};
178 178
179/* Standard ISO OUT Endpoint Descriptor */ 179/* Standard ISO OUT Endpoint Descriptor */
180static struct usb_endpoint_descriptor as_out_ep_desc __initdata = { 180static struct usb_endpoint_descriptor as_out_ep_desc = {
181 .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, 181 .bLength = USB_DT_ENDPOINT_AUDIO_SIZE,
182 .bDescriptorType = USB_DT_ENDPOINT, 182 .bDescriptorType = USB_DT_ENDPOINT,
183 .bEndpointAddress = USB_DIR_OUT, 183 .bEndpointAddress = USB_DIR_OUT,
@@ -317,8 +317,6 @@ static void f_audio_playback_work(struct work_struct *data)
317 317
318 u_audio_playback(&audio->card, play_buf->buf, play_buf->actual); 318 u_audio_playback(&audio->card, play_buf->buf, play_buf->actual);
319 f_audio_buffer_free(play_buf); 319 f_audio_buffer_free(play_buf);
320
321 return;
322} 320}
323 321
324static int f_audio_out_ep_complete(struct usb_ep *ep, struct usb_request *req) 322static int f_audio_out_ep_complete(struct usb_ep *ep, struct usb_request *req)
@@ -708,6 +706,7 @@ f_audio_unbind(struct usb_configuration *c, struct usb_function *f)
708 struct f_audio *audio = func_to_audio(f); 706 struct f_audio *audio = func_to_audio(f);
709 707
710 usb_free_descriptors(f->descriptors); 708 usb_free_descriptors(f->descriptors);
709 usb_free_descriptors(f->hs_descriptors);
711 kfree(audio); 710 kfree(audio);
712} 711}
713 712
@@ -744,7 +743,7 @@ int __init control_selector_init(struct f_audio *audio)
744} 743}
745 744
746/** 745/**
747 * audio_bind_config - add USB audio fucntion to a configuration 746 * audio_bind_config - add USB audio function to a configuration
748 * @c: the configuration to supcard the USB audio function 747 * @c: the configuration to supcard the USB audio function
749 * Context: single threaded during gadget setup 748 * Context: single threaded during gadget setup
750 * 749 *
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index 95dd4662d6a8..b3c304290150 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -314,6 +314,9 @@ eem_unbind(struct usb_configuration *c, struct usb_function *f)
314 314
315static void eem_cmd_complete(struct usb_ep *ep, struct usb_request *req) 315static void eem_cmd_complete(struct usb_ep *ep, struct usb_request *req)
316{ 316{
317 struct sk_buff *skb = (struct sk_buff *)req->context;
318
319 dev_kfree_skb_any(skb);
317} 320}
318 321
319/* 322/*
@@ -428,10 +431,11 @@ static int eem_unwrap(struct gether *port,
428 skb_trim(skb2, len); 431 skb_trim(skb2, len);
429 put_unaligned_le16(BIT(15) | BIT(11) | len, 432 put_unaligned_le16(BIT(15) | BIT(11) | len,
430 skb_push(skb2, 2)); 433 skb_push(skb2, 2));
431 skb_copy_bits(skb, 0, req->buf, skb->len); 434 skb_copy_bits(skb2, 0, req->buf, skb2->len);
432 req->length = skb->len; 435 req->length = skb2->len;
433 req->complete = eem_cmd_complete; 436 req->complete = eem_cmd_complete;
434 req->zero = 1; 437 req->zero = 1;
438 req->context = skb2;
435 if (usb_ep_queue(port->in_ep, req, GFP_ATOMIC)) 439 if (usb_ep_queue(port->in_ep, req, GFP_ATOMIC))
436 DBG(cdev, "echo response queue fail\n"); 440 DBG(cdev, "echo response queue fail\n");
437 break; 441 break;
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index e4f595055208..19fffccc370d 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * f_fs.c -- user mode filesystem api for usb composite funtcion controllers 2 * f_fs.c -- user mode file system API for USB composite function controllers
3 * 3 *
4 * Copyright (C) 2010 Samsung Electronics 4 * Copyright (C) 2010 Samsung Electronics
5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com> 5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
6 * 6 *
7 * Based on inode.c (GadgetFS): 7 * Based on inode.c (GadgetFS) which was:
8 * Copyright (C) 2003-2004 David Brownell 8 * Copyright (C) 2003-2004 David Brownell
9 * Copyright (C) 2003 Agilent Technologies 9 * Copyright (C) 2003 Agilent Technologies
10 * 10 *
@@ -30,7 +30,6 @@
30#include <linux/blkdev.h> 30#include <linux/blkdev.h>
31#include <linux/pagemap.h> 31#include <linux/pagemap.h>
32#include <asm/unaligned.h> 32#include <asm/unaligned.h>
33#include <linux/smp_lock.h>
34 33
35#include <linux/usb/composite.h> 34#include <linux/usb/composite.h>
36#include <linux/usb/functionfs.h> 35#include <linux/usb/functionfs.h>
@@ -39,62 +38,56 @@
39#define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ 38#define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */
40 39
41 40
42/* Debuging *****************************************************************/ 41/* Debugging ****************************************************************/
43
44#define ffs_printk(level, fmt, args...) printk(level "f_fs: " fmt "\n", ## args)
45
46#define FERR(...) ffs_printk(KERN_ERR, __VA_ARGS__)
47#define FINFO(...) ffs_printk(KERN_INFO, __VA_ARGS__)
48
49#ifdef DEBUG
50# define FDBG(...) ffs_printk(KERN_DEBUG, __VA_ARGS__)
51#else
52# define FDBG(...) do { } while (0)
53#endif /* DEBUG */
54
55#ifdef VERBOSE_DEBUG
56# define FVDBG FDBG
57#else
58# define FVDBG(...) do { } while (0)
59#endif /* VERBOSE_DEBUG */
60
61#define ENTER() FVDBG("%s()", __func__)
62 42
63#ifdef VERBOSE_DEBUG 43#ifdef VERBOSE_DEBUG
44# define pr_vdebug pr_debug
64# define ffs_dump_mem(prefix, ptr, len) \ 45# define ffs_dump_mem(prefix, ptr, len) \
65 print_hex_dump_bytes("f_fs" prefix ": ", DUMP_PREFIX_NONE, ptr, len) 46 print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len)
66#else 47#else
48# define pr_vdebug(...) do { } while (0)
67# define ffs_dump_mem(prefix, ptr, len) do { } while (0) 49# define ffs_dump_mem(prefix, ptr, len) do { } while (0)
68#endif 50#endif /* VERBOSE_DEBUG */
51
52#define ENTER() pr_vdebug("%s()\n", __func__)
69 53
70 54
71/* The data structure and setup file ****************************************/ 55/* The data structure and setup file ****************************************/
72 56
73enum ffs_state { 57enum ffs_state {
74 /* Waiting for descriptors and strings. */ 58 /*
75 /* In this state no open(2), read(2) or write(2) on epfiles 59 * Waiting for descriptors and strings.
60 *
61 * In this state no open(2), read(2) or write(2) on epfiles
76 * may succeed (which should not be the problem as there 62 * may succeed (which should not be the problem as there
77 * should be no such files opened in the firts place). */ 63 * should be no such files opened in the first place).
64 */
78 FFS_READ_DESCRIPTORS, 65 FFS_READ_DESCRIPTORS,
79 FFS_READ_STRINGS, 66 FFS_READ_STRINGS,
80 67
81 /* We've got descriptors and strings. We are or have called 68 /*
69 * We've got descriptors and strings. We are or have called
82 * functionfs_ready_callback(). functionfs_bind() may have 70 * functionfs_ready_callback(). functionfs_bind() may have
83 * been called but we don't know. */ 71 * been called but we don't know.
84 /* This is the only state in which operations on epfiles may 72 *
85 * succeed. */ 73 * This is the only state in which operations on epfiles may
74 * succeed.
75 */
86 FFS_ACTIVE, 76 FFS_ACTIVE,
87 77
88 /* All endpoints have been closed. This state is also set if 78 /*
79 * All endpoints have been closed. This state is also set if
89 * we encounter an unrecoverable error. The only 80 * we encounter an unrecoverable error. The only
90 * unrecoverable error is situation when after reading strings 81 * unrecoverable error is situation when after reading strings
91 * from user space we fail to initialise EP files or 82 * from user space we fail to initialise epfiles or
92 * functionfs_ready_callback() returns with error (<0). */ 83 * functionfs_ready_callback() returns with error (<0).
93 /* In this state no open(2), read(2) or write(2) (both on ep0 84 *
85 * In this state no open(2), read(2) or write(2) (both on ep0
94 * as well as epfile) may succeed (at this point epfiles are 86 * as well as epfile) may succeed (at this point epfiles are
95 * unlinked and all closed so this is not a problem; ep0 is 87 * unlinked and all closed so this is not a problem; ep0 is
96 * also closed but ep0 file exists and so open(2) on ep0 must 88 * also closed but ep0 file exists and so open(2) on ep0 must
97 * fail). */ 89 * fail).
90 */
98 FFS_CLOSING 91 FFS_CLOSING
99}; 92};
100 93
@@ -102,14 +95,18 @@ enum ffs_state {
102enum ffs_setup_state { 95enum ffs_setup_state {
103 /* There is no setup request pending. */ 96 /* There is no setup request pending. */
104 FFS_NO_SETUP, 97 FFS_NO_SETUP,
105 /* User has read events and there was a setup request event 98 /*
99 * User has read events and there was a setup request event
106 * there. The next read/write on ep0 will handle the 100 * there. The next read/write on ep0 will handle the
107 * request. */ 101 * request.
102 */
108 FFS_SETUP_PENDING, 103 FFS_SETUP_PENDING,
109 /* There was event pending but before user space handled it 104 /*
105 * There was event pending but before user space handled it
110 * some other event was introduced which canceled existing 106 * some other event was introduced which canceled existing
111 * setup. If this state is set read/write on ep0 return 107 * setup. If this state is set read/write on ep0 return
112 * -EIDRM. This state is only set when adding event. */ 108 * -EIDRM. This state is only set when adding event.
109 */
113 FFS_SETUP_CANCELED 110 FFS_SETUP_CANCELED
114}; 111};
115 112
@@ -121,23 +118,29 @@ struct ffs_function;
121struct ffs_data { 118struct ffs_data {
122 struct usb_gadget *gadget; 119 struct usb_gadget *gadget;
123 120
124 /* Protect access read/write operations, only one read/write 121 /*
122 * Protect access read/write operations, only one read/write
125 * at a time. As a consequence protects ep0req and company. 123 * at a time. As a consequence protects ep0req and company.
126 * While setup request is being processed (queued) this is 124 * While setup request is being processed (queued) this is
127 * held. */ 125 * held.
126 */
128 struct mutex mutex; 127 struct mutex mutex;
129 128
130 /* Protect access to enpoint related structures (basically 129 /*
130 * Protect access to endpoint related structures (basically
131 * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for 131 * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for
132 * endpint zero. */ 132 * endpoint zero.
133 */
133 spinlock_t eps_lock; 134 spinlock_t eps_lock;
134 135
135 /* XXX REVISIT do we need our own request? Since we are not 136 /*
136 * handling setup requests immidiatelly user space may be so 137 * XXX REVISIT do we need our own request? Since we are not
138 * handling setup requests immediately user space may be so
137 * slow that another setup will be sent to the gadget but this 139 * slow that another setup will be sent to the gadget but this
138 * time not to us but another function and then there could be 140 * time not to us but another function and then there could be
139 * a race. Is that the case? Or maybe we can use cdev->req 141 * a race. Is that the case? Or maybe we can use cdev->req
140 * after all, maybe we just need some spinlock for that? */ 142 * after all, maybe we just need some spinlock for that?
143 */
141 struct usb_request *ep0req; /* P: mutex */ 144 struct usb_request *ep0req; /* P: mutex */
142 struct completion ep0req_completion; /* P: mutex */ 145 struct completion ep0req_completion; /* P: mutex */
143 int ep0req_status; /* P: mutex */ 146 int ep0req_status; /* P: mutex */
@@ -151,7 +154,7 @@ struct ffs_data {
151 enum ffs_state state; 154 enum ffs_state state;
152 155
153 /* 156 /*
154 * Possible transations: 157 * Possible transitions:
155 * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock 158 * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock
156 * happens only in ep0 read which is P: mutex 159 * happens only in ep0 read which is P: mutex
157 * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock 160 * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock
@@ -184,18 +187,21 @@ struct ffs_data {
184 /* Active function */ 187 /* Active function */
185 struct ffs_function *func; 188 struct ffs_function *func;
186 189
187 /* Device name, write once when file system is mounted. 190 /*
188 * Intendet for user to read if she wants. */ 191 * Device name, write once when file system is mounted.
192 * Intended for user to read if she wants.
193 */
189 const char *dev_name; 194 const char *dev_name;
190 /* Private data for our user (ie. gadget). Managed by 195 /* Private data for our user (ie. gadget). Managed by user. */
191 * user. */
192 void *private_data; 196 void *private_data;
193 197
194 /* filled by __ffs_data_got_descs() */ 198 /* filled by __ffs_data_got_descs() */
195 /* real descriptors are 16 bytes after raw_descs (so you need 199 /*
200 * Real descriptors are 16 bytes after raw_descs (so you need
196 * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the 201 * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the
197 * first full speed descriptor). raw_descs_length and 202 * first full speed descriptor). raw_descs_length and
198 * raw_fs_descs_length do not have those 16 bytes added. */ 203 * raw_fs_descs_length do not have those 16 bytes added.
204 */
199 const void *raw_descs; 205 const void *raw_descs;
200 unsigned raw_descs_length; 206 unsigned raw_descs_length;
201 unsigned raw_fs_descs_length; 207 unsigned raw_fs_descs_length;
@@ -212,18 +218,23 @@ struct ffs_data {
212 const void *raw_strings; 218 const void *raw_strings;
213 struct usb_gadget_strings **stringtabs; 219 struct usb_gadget_strings **stringtabs;
214 220
215 /* File system's super block, write once when file system is mounted. */ 221 /*
222 * File system's super block, write once when file system is
223 * mounted.
224 */
216 struct super_block *sb; 225 struct super_block *sb;
217 226
218 /* File permissions, written once when fs is mounted*/ 227 /* File permissions, written once when fs is mounted */
219 struct ffs_file_perms { 228 struct ffs_file_perms {
220 umode_t mode; 229 umode_t mode;
221 uid_t uid; 230 uid_t uid;
222 gid_t gid; 231 gid_t gid;
223 } file_perms; 232 } file_perms;
224 233
225 /* The endpoint files, filled by ffs_epfiles_create(), 234 /*
226 * destroyed by ffs_epfiles_destroy(). */ 235 * The endpoint files, filled by ffs_epfiles_create(),
236 * destroyed by ffs_epfiles_destroy().
237 */
227 struct ffs_epfile *epfiles; 238 struct ffs_epfile *epfiles;
228}; 239};
229 240
@@ -237,7 +248,7 @@ static struct ffs_data *__must_check ffs_data_new(void) __attribute__((malloc));
237static void ffs_data_opened(struct ffs_data *ffs); 248static void ffs_data_opened(struct ffs_data *ffs);
238static void ffs_data_closed(struct ffs_data *ffs); 249static void ffs_data_closed(struct ffs_data *ffs);
239 250
240/* Called with ffs->mutex held; take over ownerrship of data. */ 251/* Called with ffs->mutex held; take over ownership of data. */
241static int __must_check 252static int __must_check
242__ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len); 253__ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len);
243static int __must_check 254static int __must_check
@@ -268,11 +279,9 @@ static struct ffs_function *ffs_func_from_usb(struct usb_function *f)
268 279
269static void ffs_func_free(struct ffs_function *func); 280static void ffs_func_free(struct ffs_function *func);
270 281
271
272static void ffs_func_eps_disable(struct ffs_function *func); 282static void ffs_func_eps_disable(struct ffs_function *func);
273static int __must_check ffs_func_eps_enable(struct ffs_function *func); 283static int __must_check ffs_func_eps_enable(struct ffs_function *func);
274 284
275
276static int ffs_func_bind(struct usb_configuration *, 285static int ffs_func_bind(struct usb_configuration *,
277 struct usb_function *); 286 struct usb_function *);
278static void ffs_func_unbind(struct usb_configuration *, 287static void ffs_func_unbind(struct usb_configuration *,
@@ -289,7 +298,6 @@ static int ffs_func_revmap_ep(struct ffs_function *func, u8 num);
289static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf); 298static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf);
290 299
291 300
292
293/* The endpoints structures *************************************************/ 301/* The endpoints structures *************************************************/
294 302
295struct ffs_ep { 303struct ffs_ep {
@@ -322,7 +330,6 @@ struct ffs_epfile {
322 unsigned char _pad; 330 unsigned char _pad;
323}; 331};
324 332
325
326static int __must_check ffs_epfiles_create(struct ffs_data *ffs); 333static int __must_check ffs_epfiles_create(struct ffs_data *ffs);
327static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count); 334static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count);
328 335
@@ -349,7 +356,6 @@ static void ffs_ep0_complete(struct usb_ep *ep, struct usb_request *req)
349 complete_all(&ffs->ep0req_completion); 356 complete_all(&ffs->ep0req_completion);
350} 357}
351 358
352
353static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) 359static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
354{ 360{
355 struct usb_request *req = ffs->ep0req; 361 struct usb_request *req = ffs->ep0req;
@@ -362,6 +368,14 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
362 req->buf = data; 368 req->buf = data;
363 req->length = len; 369 req->length = len;
364 370
371 /*
372 * UDC layer requires to provide a buffer even for ZLP, but should
373 * not use it at all. Let's provide some poisoned pointer to catch
374 * possible bug in the driver.
375 */
376 if (req->buf == NULL)
377 req->buf = (void *)0xDEADBABE;
378
365 INIT_COMPLETION(ffs->ep0req_completion); 379 INIT_COMPLETION(ffs->ep0req_completion);
366 380
367 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); 381 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC);
@@ -381,17 +395,16 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
381static int __ffs_ep0_stall(struct ffs_data *ffs) 395static int __ffs_ep0_stall(struct ffs_data *ffs)
382{ 396{
383 if (ffs->ev.can_stall) { 397 if (ffs->ev.can_stall) {
384 FVDBG("ep0 stall\n"); 398 pr_vdebug("ep0 stall\n");
385 usb_ep_set_halt(ffs->gadget->ep0); 399 usb_ep_set_halt(ffs->gadget->ep0);
386 ffs->setup_state = FFS_NO_SETUP; 400 ffs->setup_state = FFS_NO_SETUP;
387 return -EL2HLT; 401 return -EL2HLT;
388 } else { 402 } else {
389 FDBG("bogus ep0 stall!\n"); 403 pr_debug("bogus ep0 stall!\n");
390 return -ESRCH; 404 return -ESRCH;
391 } 405 }
392} 406}
393 407
394
395static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, 408static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
396 size_t len, loff_t *ptr) 409 size_t len, loff_t *ptr)
397{ 410{
@@ -410,7 +423,6 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
410 if (unlikely(ret < 0)) 423 if (unlikely(ret < 0))
411 return ret; 424 return ret;
412 425
413
414 /* Check state */ 426 /* Check state */
415 switch (ffs->state) { 427 switch (ffs->state) {
416 case FFS_READ_DESCRIPTORS: 428 case FFS_READ_DESCRIPTORS:
@@ -422,14 +434,14 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
422 } 434 }
423 435
424 data = ffs_prepare_buffer(buf, len); 436 data = ffs_prepare_buffer(buf, len);
425 if (unlikely(IS_ERR(data))) { 437 if (IS_ERR(data)) {
426 ret = PTR_ERR(data); 438 ret = PTR_ERR(data);
427 break; 439 break;
428 } 440 }
429 441
430 /* Handle data */ 442 /* Handle data */
431 if (ffs->state == FFS_READ_DESCRIPTORS) { 443 if (ffs->state == FFS_READ_DESCRIPTORS) {
432 FINFO("read descriptors"); 444 pr_info("read descriptors\n");
433 ret = __ffs_data_got_descs(ffs, data, len); 445 ret = __ffs_data_got_descs(ffs, data, len);
434 if (unlikely(ret < 0)) 446 if (unlikely(ret < 0))
435 break; 447 break;
@@ -437,7 +449,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
437 ffs->state = FFS_READ_STRINGS; 449 ffs->state = FFS_READ_STRINGS;
438 ret = len; 450 ret = len;
439 } else { 451 } else {
440 FINFO("read strings"); 452 pr_info("read strings\n");
441 ret = __ffs_data_got_strings(ffs, data, len); 453 ret = __ffs_data_got_strings(ffs, data, len);
442 if (unlikely(ret < 0)) 454 if (unlikely(ret < 0))
443 break; 455 break;
@@ -462,11 +474,12 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
462 } 474 }
463 break; 475 break;
464 476
465
466 case FFS_ACTIVE: 477 case FFS_ACTIVE:
467 data = NULL; 478 data = NULL;
468 /* We're called from user space, we can use _irq 479 /*
469 * rather then _irqsave */ 480 * We're called from user space, we can use _irq
481 * rather then _irqsave
482 */
470 spin_lock_irq(&ffs->ev.waitq.lock); 483 spin_lock_irq(&ffs->ev.waitq.lock);
471 switch (FFS_SETUP_STATE(ffs)) { 484 switch (FFS_SETUP_STATE(ffs)) {
472 case FFS_SETUP_CANCELED: 485 case FFS_SETUP_CANCELED:
@@ -494,23 +507,25 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
494 spin_unlock_irq(&ffs->ev.waitq.lock); 507 spin_unlock_irq(&ffs->ev.waitq.lock);
495 508
496 data = ffs_prepare_buffer(buf, len); 509 data = ffs_prepare_buffer(buf, len);
497 if (unlikely(IS_ERR(data))) { 510 if (IS_ERR(data)) {
498 ret = PTR_ERR(data); 511 ret = PTR_ERR(data);
499 break; 512 break;
500 } 513 }
501 514
502 spin_lock_irq(&ffs->ev.waitq.lock); 515 spin_lock_irq(&ffs->ev.waitq.lock);
503 516
504 /* We are guaranteed to be still in FFS_ACTIVE state 517 /*
518 * We are guaranteed to be still in FFS_ACTIVE state
505 * but the state of setup could have changed from 519 * but the state of setup could have changed from
506 * FFS_SETUP_PENDING to FFS_SETUP_CANCELED so we need 520 * FFS_SETUP_PENDING to FFS_SETUP_CANCELED so we need
507 * to check for that. If that happened we copied data 521 * to check for that. If that happened we copied data
508 * from user space in vain but it's unlikely. */ 522 * from user space in vain but it's unlikely.
509 /* For sure we are not in FFS_NO_SETUP since this is 523 *
524 * For sure we are not in FFS_NO_SETUP since this is
510 * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP 525 * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP
511 * transition can be performed and it's protected by 526 * transition can be performed and it's protected by
512 * mutex. */ 527 * mutex.
513 528 */
514 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) { 529 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) {
515 ret = -EIDRM; 530 ret = -EIDRM;
516done_spin: 531done_spin:
@@ -522,25 +537,22 @@ done_spin:
522 kfree(data); 537 kfree(data);
523 break; 538 break;
524 539
525
526 default: 540 default:
527 ret = -EBADFD; 541 ret = -EBADFD;
528 break; 542 break;
529 } 543 }
530 544
531
532 mutex_unlock(&ffs->mutex); 545 mutex_unlock(&ffs->mutex);
533 return ret; 546 return ret;
534} 547}
535 548
536
537
538static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, 549static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
539 size_t n) 550 size_t n)
540{ 551{
541 /* We are holding ffs->ev.waitq.lock and ffs->mutex and we need 552 /*
542 * to release them. */ 553 * We are holding ffs->ev.waitq.lock and ffs->mutex and we need
543 554 * to release them.
555 */
544 struct usb_functionfs_event events[n]; 556 struct usb_functionfs_event events[n];
545 unsigned i = 0; 557 unsigned i = 0;
546 558
@@ -569,7 +581,6 @@ static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
569 ? -EFAULT : sizeof events; 581 ? -EFAULT : sizeof events;
570} 582}
571 583
572
573static ssize_t ffs_ep0_read(struct file *file, char __user *buf, 584static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
574 size_t len, loff_t *ptr) 585 size_t len, loff_t *ptr)
575{ 586{
@@ -589,16 +600,16 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
589 if (unlikely(ret < 0)) 600 if (unlikely(ret < 0))
590 return ret; 601 return ret;
591 602
592
593 /* Check state */ 603 /* Check state */
594 if (ffs->state != FFS_ACTIVE) { 604 if (ffs->state != FFS_ACTIVE) {
595 ret = -EBADFD; 605 ret = -EBADFD;
596 goto done_mutex; 606 goto done_mutex;
597 } 607 }
598 608
599 609 /*
600 /* We're called from user space, we can use _irq rather then 610 * We're called from user space, we can use _irq rather then
601 * _irqsave */ 611 * _irqsave
612 */
602 spin_lock_irq(&ffs->ev.waitq.lock); 613 spin_lock_irq(&ffs->ev.waitq.lock);
603 614
604 switch (FFS_SETUP_STATE(ffs)) { 615 switch (FFS_SETUP_STATE(ffs)) {
@@ -618,7 +629,8 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
618 break; 629 break;
619 } 630 }
620 631
621 if (unlikely(wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, ffs->ev.count))) { 632 if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq,
633 ffs->ev.count)) {
622 ret = -EINTR; 634 ret = -EINTR;
623 break; 635 break;
624 } 636 }
@@ -626,7 +638,6 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
626 return __ffs_ep0_read_events(ffs, buf, 638 return __ffs_ep0_read_events(ffs, buf,
627 min(n, (size_t)ffs->ev.count)); 639 min(n, (size_t)ffs->ev.count));
628 640
629
630 case FFS_SETUP_PENDING: 641 case FFS_SETUP_PENDING:
631 if (ffs->ev.setup.bRequestType & USB_DIR_IN) { 642 if (ffs->ev.setup.bRequestType & USB_DIR_IN) {
632 spin_unlock_irq(&ffs->ev.waitq.lock); 643 spin_unlock_irq(&ffs->ev.waitq.lock);
@@ -672,8 +683,6 @@ done_mutex:
672 return ret; 683 return ret;
673} 684}
674 685
675
676
677static int ffs_ep0_open(struct inode *inode, struct file *file) 686static int ffs_ep0_open(struct inode *inode, struct file *file)
678{ 687{
679 struct ffs_data *ffs = inode->i_private; 688 struct ffs_data *ffs = inode->i_private;
@@ -689,7 +698,6 @@ static int ffs_ep0_open(struct inode *inode, struct file *file)
689 return 0; 698 return 0;
690} 699}
691 700
692
693static int ffs_ep0_release(struct inode *inode, struct file *file) 701static int ffs_ep0_release(struct inode *inode, struct file *file)
694{ 702{
695 struct ffs_data *ffs = file->private_data; 703 struct ffs_data *ffs = file->private_data;
@@ -701,7 +709,6 @@ static int ffs_ep0_release(struct inode *inode, struct file *file)
701 return 0; 709 return 0;
702} 710}
703 711
704
705static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value) 712static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
706{ 713{
707 struct ffs_data *ffs = file->private_data; 714 struct ffs_data *ffs = file->private_data;
@@ -722,7 +729,6 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
722 return ret; 729 return ret;
723} 730}
724 731
725
726static const struct file_operations ffs_ep0_operations = { 732static const struct file_operations ffs_ep0_operations = {
727 .owner = THIS_MODULE, 733 .owner = THIS_MODULE,
728 .llseek = no_llseek, 734 .llseek = no_llseek,
@@ -737,7 +743,6 @@ static const struct file_operations ffs_ep0_operations = {
737 743
738/* "Normal" endpoints operations ********************************************/ 744/* "Normal" endpoints operations ********************************************/
739 745
740
741static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req) 746static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
742{ 747{
743 ENTER(); 748 ENTER();
@@ -748,7 +753,6 @@ static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
748 } 753 }
749} 754}
750 755
751
752static ssize_t ffs_epfile_io(struct file *file, 756static ssize_t ffs_epfile_io(struct file *file,
753 char __user *buf, size_t len, int read) 757 char __user *buf, size_t len, int read)
754{ 758{
@@ -778,8 +782,8 @@ first_try:
778 goto error; 782 goto error;
779 } 783 }
780 784
781 if (unlikely(wait_event_interruptible 785 if (wait_event_interruptible(epfile->wait,
782 (epfile->wait, (ep = epfile->ep)))) { 786 (ep = epfile->ep))) {
783 ret = -EINTR; 787 ret = -EINTR;
784 goto error; 788 goto error;
785 } 789 }
@@ -811,12 +815,16 @@ first_try:
811 if (unlikely(ret)) 815 if (unlikely(ret))
812 goto error; 816 goto error;
813 817
814 /* We're called from user space, we can use _irq rather then 818 /*
815 * _irqsave */ 819 * We're called from user space, we can use _irq rather then
820 * _irqsave
821 */
816 spin_lock_irq(&epfile->ffs->eps_lock); 822 spin_lock_irq(&epfile->ffs->eps_lock);
817 823
818 /* While we were acquiring mutex endpoint got disabled 824 /*
819 * or changed? */ 825 * While we were acquiring mutex endpoint got disabled
826 * or changed?
827 */
820 } while (unlikely(epfile->ep != ep)); 828 } while (unlikely(epfile->ep != ep));
821 829
822 /* Halt */ 830 /* Halt */
@@ -858,7 +866,6 @@ error:
858 return ret; 866 return ret;
859} 867}
860 868
861
862static ssize_t 869static ssize_t
863ffs_epfile_write(struct file *file, const char __user *buf, size_t len, 870ffs_epfile_write(struct file *file, const char __user *buf, size_t len,
864 loff_t *ptr) 871 loff_t *ptr)
@@ -904,7 +911,6 @@ ffs_epfile_release(struct inode *inode, struct file *file)
904 return 0; 911 return 0;
905} 912}
906 913
907
908static long ffs_epfile_ioctl(struct file *file, unsigned code, 914static long ffs_epfile_ioctl(struct file *file, unsigned code,
909 unsigned long value) 915 unsigned long value)
910{ 916{
@@ -943,7 +949,6 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
943 return ret; 949 return ret;
944} 950}
945 951
946
947static const struct file_operations ffs_epfile_operations = { 952static const struct file_operations ffs_epfile_operations = {
948 .owner = THIS_MODULE, 953 .owner = THIS_MODULE,
949 .llseek = no_llseek, 954 .llseek = no_llseek,
@@ -956,15 +961,13 @@ static const struct file_operations ffs_epfile_operations = {
956}; 961};
957 962
958 963
959
960/* File system and super block operations ***********************************/ 964/* File system and super block operations ***********************************/
961 965
962/* 966/*
963 * Mounting the filesystem creates a controller file, used first for 967 * Mounting the file system creates a controller file, used first for
964 * function configuration then later for event monitoring. 968 * function configuration then later for event monitoring.
965 */ 969 */
966 970
967
968static struct inode *__must_check 971static struct inode *__must_check
969ffs_sb_make_inode(struct super_block *sb, void *data, 972ffs_sb_make_inode(struct super_block *sb, void *data,
970 const struct file_operations *fops, 973 const struct file_operations *fops,
@@ -980,6 +983,7 @@ ffs_sb_make_inode(struct super_block *sb, void *data,
980 if (likely(inode)) { 983 if (likely(inode)) {
981 struct timespec current_time = CURRENT_TIME; 984 struct timespec current_time = CURRENT_TIME;
982 985
986 inode->i_ino = get_next_ino();
983 inode->i_mode = perms->mode; 987 inode->i_mode = perms->mode;
984 inode->i_uid = perms->uid; 988 inode->i_uid = perms->uid;
985 inode->i_gid = perms->gid; 989 inode->i_gid = perms->gid;
@@ -996,9 +1000,7 @@ ffs_sb_make_inode(struct super_block *sb, void *data,
996 return inode; 1000 return inode;
997} 1001}
998 1002
999
1000/* Create "regular" file */ 1003/* Create "regular" file */
1001
1002static struct inode *ffs_sb_create_file(struct super_block *sb, 1004static struct inode *ffs_sb_create_file(struct super_block *sb,
1003 const char *name, void *data, 1005 const char *name, void *data,
1004 const struct file_operations *fops, 1006 const struct file_operations *fops,
@@ -1027,9 +1029,7 @@ static struct inode *ffs_sb_create_file(struct super_block *sb,
1027 return inode; 1029 return inode;
1028} 1030}
1029 1031
1030
1031/* Super block */ 1032/* Super block */
1032
1033static const struct super_operations ffs_sb_operations = { 1033static const struct super_operations ffs_sb_operations = {
1034 .statfs = simple_statfs, 1034 .statfs = simple_statfs,
1035 .drop_inode = generic_delete_inode, 1035 .drop_inode = generic_delete_inode,
@@ -1050,7 +1050,7 @@ static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
1050 1050
1051 ENTER(); 1051 ENTER();
1052 1052
1053 /* Initialize data */ 1053 /* Initialise data */
1054 ffs = ffs_data_new(); 1054 ffs = ffs_data_new();
1055 if (unlikely(!ffs)) 1055 if (unlikely(!ffs))
1056 goto enomem0; 1056 goto enomem0;
@@ -1096,7 +1096,6 @@ enomem0:
1096 return -ENOMEM; 1096 return -ENOMEM;
1097} 1097}
1098 1098
1099
1100static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts) 1099static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
1101{ 1100{
1102 ENTER(); 1101 ENTER();
@@ -1116,7 +1115,7 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
1116 /* Value limit */ 1115 /* Value limit */
1117 eq = strchr(opts, '='); 1116 eq = strchr(opts, '=');
1118 if (unlikely(!eq)) { 1117 if (unlikely(!eq)) {
1119 FERR("'=' missing in %s", opts); 1118 pr_err("'=' missing in %s\n", opts);
1120 return -EINVAL; 1119 return -EINVAL;
1121 } 1120 }
1122 *eq = 0; 1121 *eq = 0;
@@ -1124,7 +1123,7 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
1124 /* Parse value */ 1123 /* Parse value */
1125 value = simple_strtoul(eq + 1, &end, 0); 1124 value = simple_strtoul(eq + 1, &end, 0);
1126 if (unlikely(*end != ',' && *end != 0)) { 1125 if (unlikely(*end != ',' && *end != 0)) {
1127 FERR("%s: invalid value: %s", opts, eq + 1); 1126 pr_err("%s: invalid value: %s\n", opts, eq + 1);
1128 return -EINVAL; 1127 return -EINVAL;
1129 } 1128 }
1130 1129
@@ -1159,7 +1158,7 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
1159 1158
1160 default: 1159 default:
1161invalid: 1160invalid:
1162 FERR("%s: invalid option", opts); 1161 pr_err("%s: invalid option\n", opts);
1163 return -EINVAL; 1162 return -EINVAL;
1164 } 1163 }
1165 1164
@@ -1172,12 +1171,11 @@ invalid:
1172 return 0; 1171 return 0;
1173} 1172}
1174 1173
1175
1176/* "mount -t functionfs dev_name /dev/function" ends up here */ 1174/* "mount -t functionfs dev_name /dev/function" ends up here */
1177 1175
1178static int 1176static struct dentry *
1179ffs_fs_get_sb(struct file_system_type *t, int flags, 1177ffs_fs_mount(struct file_system_type *t, int flags,
1180 const char *dev_name, void *opts, struct vfsmount *mnt) 1178 const char *dev_name, void *opts)
1181{ 1179{
1182 struct ffs_sb_fill_data data = { 1180 struct ffs_sb_fill_data data = {
1183 .perms = { 1181 .perms = {
@@ -1193,14 +1191,14 @@ ffs_fs_get_sb(struct file_system_type *t, int flags,
1193 1191
1194 ret = functionfs_check_dev_callback(dev_name); 1192 ret = functionfs_check_dev_callback(dev_name);
1195 if (unlikely(ret < 0)) 1193 if (unlikely(ret < 0))
1196 return ret; 1194 return ERR_PTR(ret);
1197 1195
1198 ret = ffs_fs_parse_opts(&data, opts); 1196 ret = ffs_fs_parse_opts(&data, opts);
1199 if (unlikely(ret < 0)) 1197 if (unlikely(ret < 0))
1200 return ret; 1198 return ERR_PTR(ret);
1201 1199
1202 data.dev_name = dev_name; 1200 data.dev_name = dev_name;
1203 return get_sb_single(t, flags, &data, ffs_sb_fill, mnt); 1201 return mount_single(t, flags, &data, ffs_sb_fill);
1204} 1202}
1205 1203
1206static void 1204static void
@@ -1219,15 +1217,13 @@ ffs_fs_kill_sb(struct super_block *sb)
1219static struct file_system_type ffs_fs_type = { 1217static struct file_system_type ffs_fs_type = {
1220 .owner = THIS_MODULE, 1218 .owner = THIS_MODULE,
1221 .name = "functionfs", 1219 .name = "functionfs",
1222 .get_sb = ffs_fs_get_sb, 1220 .mount = ffs_fs_mount,
1223 .kill_sb = ffs_fs_kill_sb, 1221 .kill_sb = ffs_fs_kill_sb,
1224}; 1222};
1225 1223
1226 1224
1227
1228/* Driver's main init/cleanup functions *************************************/ 1225/* Driver's main init/cleanup functions *************************************/
1229 1226
1230
1231static int functionfs_init(void) 1227static int functionfs_init(void)
1232{ 1228{
1233 int ret; 1229 int ret;
@@ -1236,9 +1232,9 @@ static int functionfs_init(void)
1236 1232
1237 ret = register_filesystem(&ffs_fs_type); 1233 ret = register_filesystem(&ffs_fs_type);
1238 if (likely(!ret)) 1234 if (likely(!ret))
1239 FINFO("file system registered"); 1235 pr_info("file system registered\n");
1240 else 1236 else
1241 FERR("failed registering file system (%d)", ret); 1237 pr_err("failed registering file system (%d)\n", ret);
1242 1238
1243 return ret; 1239 return ret;
1244} 1240}
@@ -1247,18 +1243,16 @@ static void functionfs_cleanup(void)
1247{ 1243{
1248 ENTER(); 1244 ENTER();
1249 1245
1250 FINFO("unloading"); 1246 pr_info("unloading\n");
1251 unregister_filesystem(&ffs_fs_type); 1247 unregister_filesystem(&ffs_fs_type);
1252} 1248}
1253 1249
1254 1250
1255
1256/* ffs_data and ffs_function construction and destruction code **************/ 1251/* ffs_data and ffs_function construction and destruction code **************/
1257 1252
1258static void ffs_data_clear(struct ffs_data *ffs); 1253static void ffs_data_clear(struct ffs_data *ffs);
1259static void ffs_data_reset(struct ffs_data *ffs); 1254static void ffs_data_reset(struct ffs_data *ffs);
1260 1255
1261
1262static void ffs_data_get(struct ffs_data *ffs) 1256static void ffs_data_get(struct ffs_data *ffs)
1263{ 1257{
1264 ENTER(); 1258 ENTER();
@@ -1279,7 +1273,7 @@ static void ffs_data_put(struct ffs_data *ffs)
1279 ENTER(); 1273 ENTER();
1280 1274
1281 if (unlikely(atomic_dec_and_test(&ffs->ref))) { 1275 if (unlikely(atomic_dec_and_test(&ffs->ref))) {
1282 FINFO("%s(): freeing", __func__); 1276 pr_info("%s(): freeing\n", __func__);
1283 ffs_data_clear(ffs); 1277 ffs_data_clear(ffs);
1284 BUG_ON(mutex_is_locked(&ffs->mutex) || 1278 BUG_ON(mutex_is_locked(&ffs->mutex) ||
1285 spin_is_locked(&ffs->ev.waitq.lock) || 1279 spin_is_locked(&ffs->ev.waitq.lock) ||
@@ -1289,8 +1283,6 @@ static void ffs_data_put(struct ffs_data *ffs)
1289 } 1283 }
1290} 1284}
1291 1285
1292
1293
1294static void ffs_data_closed(struct ffs_data *ffs) 1286static void ffs_data_closed(struct ffs_data *ffs)
1295{ 1287{
1296 ENTER(); 1288 ENTER();
@@ -1303,7 +1295,6 @@ static void ffs_data_closed(struct ffs_data *ffs)
1303 ffs_data_put(ffs); 1295 ffs_data_put(ffs);
1304} 1296}
1305 1297
1306
1307static struct ffs_data *ffs_data_new(void) 1298static struct ffs_data *ffs_data_new(void)
1308{ 1299{
1309 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); 1300 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL);
@@ -1326,7 +1317,6 @@ static struct ffs_data *ffs_data_new(void)
1326 return ffs; 1317 return ffs;
1327} 1318}
1328 1319
1329
1330static void ffs_data_clear(struct ffs_data *ffs) 1320static void ffs_data_clear(struct ffs_data *ffs)
1331{ 1321{
1332 ENTER(); 1322 ENTER();
@@ -1344,7 +1334,6 @@ static void ffs_data_clear(struct ffs_data *ffs)
1344 kfree(ffs->stringtabs); 1334 kfree(ffs->stringtabs);
1345} 1335}
1346 1336
1347
1348static void ffs_data_reset(struct ffs_data *ffs) 1337static void ffs_data_reset(struct ffs_data *ffs)
1349{ 1338{
1350 ENTER(); 1339 ENTER();
@@ -1407,7 +1396,6 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
1407 return 0; 1396 return 0;
1408} 1397}
1409 1398
1410
1411static void functionfs_unbind(struct ffs_data *ffs) 1399static void functionfs_unbind(struct ffs_data *ffs)
1412{ 1400{
1413 ENTER(); 1401 ENTER();
@@ -1420,7 +1408,6 @@ static void functionfs_unbind(struct ffs_data *ffs)
1420 } 1408 }
1421} 1409}
1422 1410
1423
1424static int ffs_epfiles_create(struct ffs_data *ffs) 1411static int ffs_epfiles_create(struct ffs_data *ffs)
1425{ 1412{
1426 struct ffs_epfile *epfile, *epfiles; 1413 struct ffs_epfile *epfile, *epfiles;
@@ -1451,7 +1438,6 @@ static int ffs_epfiles_create(struct ffs_data *ffs)
1451 return 0; 1438 return 0;
1452} 1439}
1453 1440
1454
1455static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) 1441static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count)
1456{ 1442{
1457 struct ffs_epfile *epfile = epfiles; 1443 struct ffs_epfile *epfile = epfiles;
@@ -1471,7 +1457,6 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count)
1471 kfree(epfiles); 1457 kfree(epfiles);
1472} 1458}
1473 1459
1474
1475static int functionfs_bind_config(struct usb_composite_dev *cdev, 1460static int functionfs_bind_config(struct usb_composite_dev *cdev,
1476 struct usb_configuration *c, 1461 struct usb_configuration *c,
1477 struct ffs_data *ffs) 1462 struct ffs_data *ffs)
@@ -1491,7 +1476,6 @@ static int functionfs_bind_config(struct usb_composite_dev *cdev,
1491 func->function.bind = ffs_func_bind; 1476 func->function.bind = ffs_func_bind;
1492 func->function.unbind = ffs_func_unbind; 1477 func->function.unbind = ffs_func_unbind;
1493 func->function.set_alt = ffs_func_set_alt; 1478 func->function.set_alt = ffs_func_set_alt;
1494 /*func->function.get_alt = ffs_func_get_alt;*/
1495 func->function.disable = ffs_func_disable; 1479 func->function.disable = ffs_func_disable;
1496 func->function.setup = ffs_func_setup; 1480 func->function.setup = ffs_func_setup;
1497 func->function.suspend = ffs_func_suspend; 1481 func->function.suspend = ffs_func_suspend;
@@ -1516,14 +1500,15 @@ static void ffs_func_free(struct ffs_function *func)
1516 ffs_data_put(func->ffs); 1500 ffs_data_put(func->ffs);
1517 1501
1518 kfree(func->eps); 1502 kfree(func->eps);
1519 /* eps and interfaces_nums are allocated in the same chunk so 1503 /*
1504 * eps and interfaces_nums are allocated in the same chunk so
1520 * only one free is required. Descriptors are also allocated 1505 * only one free is required. Descriptors are also allocated
1521 * in the same chunk. */ 1506 * in the same chunk.
1507 */
1522 1508
1523 kfree(func); 1509 kfree(func);
1524} 1510}
1525 1511
1526
1527static void ffs_func_eps_disable(struct ffs_function *func) 1512static void ffs_func_eps_disable(struct ffs_function *func)
1528{ 1513{
1529 struct ffs_ep *ep = func->eps; 1514 struct ffs_ep *ep = func->eps;
@@ -1581,11 +1566,12 @@ static int ffs_func_eps_enable(struct ffs_function *func)
1581 1566
1582/* Parsing and building descriptors and strings *****************************/ 1567/* Parsing and building descriptors and strings *****************************/
1583 1568
1584 1569/*
1585/* This validates if data pointed by data is a valid USB descriptor as 1570 * This validates if data pointed by data is a valid USB descriptor as
1586 * well as record how many interfaces, endpoints and strings are 1571 * well as record how many interfaces, endpoints and strings are
1587 * required by given configuration. Returns address afther the 1572 * required by given configuration. Returns address after the
1588 * descriptor or NULL if data is invalid. */ 1573 * descriptor or NULL if data is invalid.
1574 */
1589 1575
1590enum ffs_entity_type { 1576enum ffs_entity_type {
1591 FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT 1577 FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT
@@ -1607,14 +1593,14 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1607 1593
1608 /* At least two bytes are required: length and type */ 1594 /* At least two bytes are required: length and type */
1609 if (len < 2) { 1595 if (len < 2) {
1610 FVDBG("descriptor too short"); 1596 pr_vdebug("descriptor too short\n");
1611 return -EINVAL; 1597 return -EINVAL;
1612 } 1598 }
1613 1599
1614 /* If we have at least as many bytes as the descriptor takes? */ 1600 /* If we have at least as many bytes as the descriptor takes? */
1615 length = _ds->bLength; 1601 length = _ds->bLength;
1616 if (len < length) { 1602 if (len < length) {
1617 FVDBG("descriptor longer then available data"); 1603 pr_vdebug("descriptor longer then available data\n");
1618 return -EINVAL; 1604 return -EINVAL;
1619 } 1605 }
1620 1606
@@ -1622,15 +1608,15 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1622#define __entity_check_STRING(val) (val) 1608#define __entity_check_STRING(val) (val)
1623#define __entity_check_ENDPOINT(val) ((val) & USB_ENDPOINT_NUMBER_MASK) 1609#define __entity_check_ENDPOINT(val) ((val) & USB_ENDPOINT_NUMBER_MASK)
1624#define __entity(type, val) do { \ 1610#define __entity(type, val) do { \
1625 FVDBG("entity " #type "(%02x)", (val)); \ 1611 pr_vdebug("entity " #type "(%02x)\n", (val)); \
1626 if (unlikely(!__entity_check_ ##type(val))) { \ 1612 if (unlikely(!__entity_check_ ##type(val))) { \
1627 FVDBG("invalid entity's value"); \ 1613 pr_vdebug("invalid entity's value\n"); \
1628 return -EINVAL; \ 1614 return -EINVAL; \
1629 } \ 1615 } \
1630 ret = entity(FFS_ ##type, &val, _ds, priv); \ 1616 ret = entity(FFS_ ##type, &val, _ds, priv); \
1631 if (unlikely(ret < 0)) { \ 1617 if (unlikely(ret < 0)) { \
1632 FDBG("entity " #type "(%02x); ret = %d", \ 1618 pr_debug("entity " #type "(%02x); ret = %d\n", \
1633 (val), ret); \ 1619 (val), ret); \
1634 return ret; \ 1620 return ret; \
1635 } \ 1621 } \
1636 } while (0) 1622 } while (0)
@@ -1642,12 +1628,13 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1642 case USB_DT_STRING: 1628 case USB_DT_STRING:
1643 case USB_DT_DEVICE_QUALIFIER: 1629 case USB_DT_DEVICE_QUALIFIER:
1644 /* function can't have any of those */ 1630 /* function can't have any of those */
1645 FVDBG("descriptor reserved for gadget: %d", _ds->bDescriptorType); 1631 pr_vdebug("descriptor reserved for gadget: %d\n",
1632 _ds->bDescriptorType);
1646 return -EINVAL; 1633 return -EINVAL;
1647 1634
1648 case USB_DT_INTERFACE: { 1635 case USB_DT_INTERFACE: {
1649 struct usb_interface_descriptor *ds = (void *)_ds; 1636 struct usb_interface_descriptor *ds = (void *)_ds;
1650 FVDBG("interface descriptor"); 1637 pr_vdebug("interface descriptor\n");
1651 if (length != sizeof *ds) 1638 if (length != sizeof *ds)
1652 goto inv_length; 1639 goto inv_length;
1653 1640
@@ -1659,7 +1646,7 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1659 1646
1660 case USB_DT_ENDPOINT: { 1647 case USB_DT_ENDPOINT: {
1661 struct usb_endpoint_descriptor *ds = (void *)_ds; 1648 struct usb_endpoint_descriptor *ds = (void *)_ds;
1662 FVDBG("endpoint descriptor"); 1649 pr_vdebug("endpoint descriptor\n");
1663 if (length != USB_DT_ENDPOINT_SIZE && 1650 if (length != USB_DT_ENDPOINT_SIZE &&
1664 length != USB_DT_ENDPOINT_AUDIO_SIZE) 1651 length != USB_DT_ENDPOINT_AUDIO_SIZE)
1665 goto inv_length; 1652 goto inv_length;
@@ -1674,7 +1661,7 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1674 1661
1675 case USB_DT_INTERFACE_ASSOCIATION: { 1662 case USB_DT_INTERFACE_ASSOCIATION: {
1676 struct usb_interface_assoc_descriptor *ds = (void *)_ds; 1663 struct usb_interface_assoc_descriptor *ds = (void *)_ds;
1677 FVDBG("interface association descriptor"); 1664 pr_vdebug("interface association descriptor\n");
1678 if (length != sizeof *ds) 1665 if (length != sizeof *ds)
1679 goto inv_length; 1666 goto inv_length;
1680 if (ds->iFunction) 1667 if (ds->iFunction)
@@ -1688,17 +1675,17 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1688 case USB_DT_SECURITY: 1675 case USB_DT_SECURITY:
1689 case USB_DT_CS_RADIO_CONTROL: 1676 case USB_DT_CS_RADIO_CONTROL:
1690 /* TODO */ 1677 /* TODO */
1691 FVDBG("unimplemented descriptor: %d", _ds->bDescriptorType); 1678 pr_vdebug("unimplemented descriptor: %d\n", _ds->bDescriptorType);
1692 return -EINVAL; 1679 return -EINVAL;
1693 1680
1694 default: 1681 default:
1695 /* We should never be here */ 1682 /* We should never be here */
1696 FVDBG("unknown descriptor: %d", _ds->bDescriptorType); 1683 pr_vdebug("unknown descriptor: %d\n", _ds->bDescriptorType);
1697 return -EINVAL; 1684 return -EINVAL;
1698 1685
1699 inv_length: 1686inv_length:
1700 FVDBG("invalid length: %d (descriptor %d)", 1687 pr_vdebug("invalid length: %d (descriptor %d)\n",
1701 _ds->bLength, _ds->bDescriptorType); 1688 _ds->bLength, _ds->bDescriptorType);
1702 return -EINVAL; 1689 return -EINVAL;
1703 } 1690 }
1704 1691
@@ -1711,7 +1698,6 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1711 return length; 1698 return length;
1712} 1699}
1713 1700
1714
1715static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, 1701static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
1716 ffs_entity_callback entity, void *priv) 1702 ffs_entity_callback entity, void *priv)
1717{ 1703{
@@ -1726,10 +1712,11 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
1726 if (num == count) 1712 if (num == count)
1727 data = NULL; 1713 data = NULL;
1728 1714
1729 /* Record "descriptor" entitny */ 1715 /* Record "descriptor" entity */
1730 ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); 1716 ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv);
1731 if (unlikely(ret < 0)) { 1717 if (unlikely(ret < 0)) {
1732 FDBG("entity DESCRIPTOR(%02lx); ret = %d", num, ret); 1718 pr_debug("entity DESCRIPTOR(%02lx); ret = %d\n",
1719 num, ret);
1733 return ret; 1720 return ret;
1734 } 1721 }
1735 1722
@@ -1738,7 +1725,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
1738 1725
1739 ret = ffs_do_desc(data, len, entity, priv); 1726 ret = ffs_do_desc(data, len, entity, priv);
1740 if (unlikely(ret < 0)) { 1727 if (unlikely(ret < 0)) {
1741 FDBG("%s returns %d", __func__, ret); 1728 pr_debug("%s returns %d\n", __func__, ret);
1742 return ret; 1729 return ret;
1743 } 1730 }
1744 1731
@@ -1748,7 +1735,6 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
1748 } 1735 }
1749} 1736}
1750 1737
1751
1752static int __ffs_data_do_entity(enum ffs_entity_type type, 1738static int __ffs_data_do_entity(enum ffs_entity_type type,
1753 u8 *valuep, struct usb_descriptor_header *desc, 1739 u8 *valuep, struct usb_descriptor_header *desc,
1754 void *priv) 1740 void *priv)
@@ -1762,16 +1748,20 @@ static int __ffs_data_do_entity(enum ffs_entity_type type,
1762 break; 1748 break;
1763 1749
1764 case FFS_INTERFACE: 1750 case FFS_INTERFACE:
1765 /* Interfaces are indexed from zero so if we 1751 /*
1752 * Interfaces are indexed from zero so if we
1766 * encountered interface "n" then there are at least 1753 * encountered interface "n" then there are at least
1767 * "n+1" interfaces. */ 1754 * "n+1" interfaces.
1755 */
1768 if (*valuep >= ffs->interfaces_count) 1756 if (*valuep >= ffs->interfaces_count)
1769 ffs->interfaces_count = *valuep + 1; 1757 ffs->interfaces_count = *valuep + 1;
1770 break; 1758 break;
1771 1759
1772 case FFS_STRING: 1760 case FFS_STRING:
1773 /* Strings are indexed from 1 (0 is magic ;) reserved 1761 /*
1774 * for languages list or some such) */ 1762 * Strings are indexed from 1 (0 is magic ;) reserved
1763 * for languages list or some such)
1764 */
1775 if (*valuep > ffs->strings_count) 1765 if (*valuep > ffs->strings_count)
1776 ffs->strings_count = *valuep; 1766 ffs->strings_count = *valuep;
1777 break; 1767 break;
@@ -1786,7 +1776,6 @@ static int __ffs_data_do_entity(enum ffs_entity_type type,
1786 return 0; 1776 return 0;
1787} 1777}
1788 1778
1789
1790static int __ffs_data_got_descs(struct ffs_data *ffs, 1779static int __ffs_data_got_descs(struct ffs_data *ffs,
1791 char *const _data, size_t len) 1780 char *const _data, size_t len)
1792{ 1781{
@@ -1849,8 +1838,6 @@ error:
1849 return ret; 1838 return ret;
1850} 1839}
1851 1840
1852
1853
1854static int __ffs_data_got_strings(struct ffs_data *ffs, 1841static int __ffs_data_got_strings(struct ffs_data *ffs,
1855 char *const _data, size_t len) 1842 char *const _data, size_t len)
1856{ 1843{
@@ -1876,17 +1863,17 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
1876 if (unlikely(str_count < needed_count)) 1863 if (unlikely(str_count < needed_count))
1877 goto error; 1864 goto error;
1878 1865
1879 /* If we don't need any strings just return and free all 1866 /*
1880 * memory */ 1867 * If we don't need any strings just return and free all
1868 * memory.
1869 */
1881 if (!needed_count) { 1870 if (!needed_count) {
1882 kfree(_data); 1871 kfree(_data);
1883 return 0; 1872 return 0;
1884 } 1873 }
1885 1874
1886 /* Allocate */ 1875 /* Allocate everything in one chunk so there's less maintenance. */
1887 { 1876 {
1888 /* Allocate everything in one chunk so there's less
1889 * maintanance. */
1890 struct { 1877 struct {
1891 struct usb_gadget_strings *stringtabs[lang_count + 1]; 1878 struct usb_gadget_strings *stringtabs[lang_count + 1];
1892 struct usb_gadget_strings stringtab[lang_count]; 1879 struct usb_gadget_strings stringtab[lang_count];
@@ -1937,13 +1924,17 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
1937 if (unlikely(length == len)) 1924 if (unlikely(length == len))
1938 goto error_free; 1925 goto error_free;
1939 1926
1940 /* user may provide more strings then we need, 1927 /*
1941 * if that's the case we simply ingore the 1928 * User may provide more strings then we need,
1942 * rest */ 1929 * if that's the case we simply ignore the
1930 * rest
1931 */
1943 if (likely(needed)) { 1932 if (likely(needed)) {
1944 /* s->id will be set while adding 1933 /*
1934 * s->id will be set while adding
1945 * function to configuration so for 1935 * function to configuration so for
1946 * now just leave garbage here. */ 1936 * now just leave garbage here.
1937 */
1947 s->s = data; 1938 s->s = data;
1948 --needed; 1939 --needed;
1949 ++s; 1940 ++s;
@@ -1977,8 +1968,6 @@ error:
1977} 1968}
1978 1969
1979 1970
1980
1981
1982/* Events handling and management *******************************************/ 1971/* Events handling and management *******************************************/
1983 1972
1984static void __ffs_event_add(struct ffs_data *ffs, 1973static void __ffs_event_add(struct ffs_data *ffs,
@@ -1987,29 +1976,32 @@ static void __ffs_event_add(struct ffs_data *ffs,
1987 enum usb_functionfs_event_type rem_type1, rem_type2 = type; 1976 enum usb_functionfs_event_type rem_type1, rem_type2 = type;
1988 int neg = 0; 1977 int neg = 0;
1989 1978
1990 /* Abort any unhandled setup */ 1979 /*
1991 /* We do not need to worry about some cmpxchg() changing value 1980 * Abort any unhandled setup
1981 *
1982 * We do not need to worry about some cmpxchg() changing value
1992 * of ffs->setup_state without holding the lock because when 1983 * of ffs->setup_state without holding the lock because when
1993 * state is FFS_SETUP_PENDING cmpxchg() in several places in 1984 * state is FFS_SETUP_PENDING cmpxchg() in several places in
1994 * the source does nothing. */ 1985 * the source does nothing.
1986 */
1995 if (ffs->setup_state == FFS_SETUP_PENDING) 1987 if (ffs->setup_state == FFS_SETUP_PENDING)
1996 ffs->setup_state = FFS_SETUP_CANCELED; 1988 ffs->setup_state = FFS_SETUP_CANCELED;
1997 1989
1998 switch (type) { 1990 switch (type) {
1999 case FUNCTIONFS_RESUME: 1991 case FUNCTIONFS_RESUME:
2000 rem_type2 = FUNCTIONFS_SUSPEND; 1992 rem_type2 = FUNCTIONFS_SUSPEND;
2001 /* FALL THGOUTH */ 1993 /* FALL THROUGH */
2002 case FUNCTIONFS_SUSPEND: 1994 case FUNCTIONFS_SUSPEND:
2003 case FUNCTIONFS_SETUP: 1995 case FUNCTIONFS_SETUP:
2004 rem_type1 = type; 1996 rem_type1 = type;
2005 /* discard all similar events */ 1997 /* Discard all similar events */
2006 break; 1998 break;
2007 1999
2008 case FUNCTIONFS_BIND: 2000 case FUNCTIONFS_BIND:
2009 case FUNCTIONFS_UNBIND: 2001 case FUNCTIONFS_UNBIND:
2010 case FUNCTIONFS_DISABLE: 2002 case FUNCTIONFS_DISABLE:
2011 case FUNCTIONFS_ENABLE: 2003 case FUNCTIONFS_ENABLE:
2012 /* discard everything other then power management. */ 2004 /* Discard everything other then power management. */
2013 rem_type1 = FUNCTIONFS_SUSPEND; 2005 rem_type1 = FUNCTIONFS_SUSPEND;
2014 rem_type2 = FUNCTIONFS_RESUME; 2006 rem_type2 = FUNCTIONFS_RESUME;
2015 neg = 1; 2007 neg = 1;
@@ -2026,11 +2018,11 @@ static void __ffs_event_add(struct ffs_data *ffs,
2026 if ((*ev == rem_type1 || *ev == rem_type2) == neg) 2018 if ((*ev == rem_type1 || *ev == rem_type2) == neg)
2027 *out++ = *ev; 2019 *out++ = *ev;
2028 else 2020 else
2029 FVDBG("purging event %d", *ev); 2021 pr_vdebug("purging event %d\n", *ev);
2030 ffs->ev.count = out - ffs->ev.types; 2022 ffs->ev.count = out - ffs->ev.types;
2031 } 2023 }
2032 2024
2033 FVDBG("adding event %d", type); 2025 pr_vdebug("adding event %d\n", type);
2034 ffs->ev.types[ffs->ev.count++] = type; 2026 ffs->ev.types[ffs->ev.count++] = type;
2035 wake_up_locked(&ffs->ev.waitq); 2027 wake_up_locked(&ffs->ev.waitq);
2036} 2028}
@@ -2055,8 +2047,10 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
2055 struct ffs_function *func = priv; 2047 struct ffs_function *func = priv;
2056 struct ffs_ep *ffs_ep; 2048 struct ffs_ep *ffs_ep;
2057 2049
2058 /* If hs_descriptors is not NULL then we are reading hs 2050 /*
2059 * descriptors now */ 2051 * If hs_descriptors is not NULL then we are reading hs
2052 * descriptors now
2053 */
2060 const int isHS = func->function.hs_descriptors != NULL; 2054 const int isHS = func->function.hs_descriptors != NULL;
2061 unsigned idx; 2055 unsigned idx;
2062 2056
@@ -2075,9 +2069,9 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
2075 ffs_ep = func->eps + idx; 2069 ffs_ep = func->eps + idx;
2076 2070
2077 if (unlikely(ffs_ep->descs[isHS])) { 2071 if (unlikely(ffs_ep->descs[isHS])) {
2078 FVDBG("two %sspeed descriptors for EP %d", 2072 pr_vdebug("two %sspeed descriptors for EP %d\n",
2079 isHS ? "high" : "full", 2073 isHS ? "high" : "full",
2080 ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 2074 ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
2081 return -EINVAL; 2075 return -EINVAL;
2082 } 2076 }
2083 ffs_ep->descs[isHS] = ds; 2077 ffs_ep->descs[isHS] = ds;
@@ -2091,11 +2085,11 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
2091 struct usb_request *req; 2085 struct usb_request *req;
2092 struct usb_ep *ep; 2086 struct usb_ep *ep;
2093 2087
2094 FVDBG("autoconfig"); 2088 pr_vdebug("autoconfig\n");
2095 ep = usb_ep_autoconfig(func->gadget, ds); 2089 ep = usb_ep_autoconfig(func->gadget, ds);
2096 if (unlikely(!ep)) 2090 if (unlikely(!ep))
2097 return -ENOTSUPP; 2091 return -ENOTSUPP;
2098 ep->driver_data = func->eps + idx;; 2092 ep->driver_data = func->eps + idx;
2099 2093
2100 req = usb_ep_alloc_request(ep, GFP_KERNEL); 2094 req = usb_ep_alloc_request(ep, GFP_KERNEL);
2101 if (unlikely(!req)) 2095 if (unlikely(!req))
@@ -2111,7 +2105,6 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
2111 return 0; 2105 return 0;
2112} 2106}
2113 2107
2114
2115static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, 2108static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep,
2116 struct usb_descriptor_header *desc, 2109 struct usb_descriptor_header *desc,
2117 void *priv) 2110 void *priv)
@@ -2143,8 +2136,10 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep,
2143 break; 2136 break;
2144 2137
2145 case FFS_ENDPOINT: 2138 case FFS_ENDPOINT:
2146 /* USB_DT_ENDPOINT are handled in 2139 /*
2147 * __ffs_func_bind_do_descs(). */ 2140 * USB_DT_ENDPOINT are handled in
2141 * __ffs_func_bind_do_descs().
2142 */
2148 if (desc->bDescriptorType == USB_DT_ENDPOINT) 2143 if (desc->bDescriptorType == USB_DT_ENDPOINT)
2149 return 0; 2144 return 0;
2150 2145
@@ -2160,7 +2155,7 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep,
2160 break; 2155 break;
2161 } 2156 }
2162 2157
2163 FVDBG("%02x -> %02x", *valuep, newValue); 2158 pr_vdebug("%02x -> %02x\n", *valuep, newValue);
2164 *valuep = newValue; 2159 *valuep = newValue;
2165 return 0; 2160 return 0;
2166} 2161}
@@ -2211,9 +2206,11 @@ static int ffs_func_bind(struct usb_configuration *c,
2211 func->eps = data->eps; 2206 func->eps = data->eps;
2212 func->interfaces_nums = data->inums; 2207 func->interfaces_nums = data->inums;
2213 2208
2214 /* Go throught all the endpoint descriptors and allocate 2209 /*
2210 * Go through all the endpoint descriptors and allocate
2215 * endpoints first, so that later we can rewrite the endpoint 2211 * endpoints first, so that later we can rewrite the endpoint
2216 * numbers without worying that it may be described later on. */ 2212 * numbers without worrying that it may be described later on.
2213 */
2217 if (likely(full)) { 2214 if (likely(full)) {
2218 func->function.descriptors = data->fs_descs; 2215 func->function.descriptors = data->fs_descs;
2219 ret = ffs_do_descs(ffs->fs_descs_count, 2216 ret = ffs_do_descs(ffs->fs_descs_count,
@@ -2234,9 +2231,11 @@ static int ffs_func_bind(struct usb_configuration *c,
2234 __ffs_func_bind_do_descs, func); 2231 __ffs_func_bind_do_descs, func);
2235 } 2232 }
2236 2233
2237 /* Now handle interface numbers allocation and interface and 2234 /*
2238 * enpoint numbers rewritting. We can do that in one go 2235 * Now handle interface numbers allocation and interface and
2239 * now. */ 2236 * endpoint numbers rewriting. We can do that in one go
2237 * now.
2238 */
2240 ret = ffs_do_descs(ffs->fs_descs_count + 2239 ret = ffs_do_descs(ffs->fs_descs_count +
2241 (high ? ffs->hs_descs_count : 0), 2240 (high ? ffs->hs_descs_count : 0),
2242 data->raw_descs, sizeof data->raw_descs, 2241 data->raw_descs, sizeof data->raw_descs,
@@ -2274,7 +2273,6 @@ static void ffs_func_unbind(struct usb_configuration *c,
2274 ffs_func_free(func); 2273 ffs_func_free(func);
2275} 2274}
2276 2275
2277
2278static int ffs_func_set_alt(struct usb_function *f, 2276static int ffs_func_set_alt(struct usb_function *f,
2279 unsigned interface, unsigned alt) 2277 unsigned interface, unsigned alt)
2280{ 2278{
@@ -2322,20 +2320,21 @@ static int ffs_func_setup(struct usb_function *f,
2322 2320
2323 ENTER(); 2321 ENTER();
2324 2322
2325 FVDBG("creq->bRequestType = %02x", creq->bRequestType); 2323 pr_vdebug("creq->bRequestType = %02x\n", creq->bRequestType);
2326 FVDBG("creq->bRequest = %02x", creq->bRequest); 2324 pr_vdebug("creq->bRequest = %02x\n", creq->bRequest);
2327 FVDBG("creq->wValue = %04x", le16_to_cpu(creq->wValue)); 2325 pr_vdebug("creq->wValue = %04x\n", le16_to_cpu(creq->wValue));
2328 FVDBG("creq->wIndex = %04x", le16_to_cpu(creq->wIndex)); 2326 pr_vdebug("creq->wIndex = %04x\n", le16_to_cpu(creq->wIndex));
2329 FVDBG("creq->wLength = %04x", le16_to_cpu(creq->wLength)); 2327 pr_vdebug("creq->wLength = %04x\n", le16_to_cpu(creq->wLength));
2330 2328
2331 /* Most requests directed to interface go throught here 2329 /*
2330 * Most requests directed to interface go through here
2332 * (notable exceptions are set/get interface) so we need to 2331 * (notable exceptions are set/get interface) so we need to
2333 * handle them. All other either handled by composite or 2332 * handle them. All other either handled by composite or
2334 * passed to usb_configuration->setup() (if one is set). No 2333 * passed to usb_configuration->setup() (if one is set). No
2335 * matter, we will handle requests directed to endpoint here 2334 * matter, we will handle requests directed to endpoint here
2336 * as well (as it's straightforward) but what to do with any 2335 * as well (as it's straightforward) but what to do with any
2337 * other request? */ 2336 * other request?
2338 2337 */
2339 if (ffs->state != FFS_ACTIVE) 2338 if (ffs->state != FFS_ACTIVE)
2340 return -ENODEV; 2339 return -ENODEV;
2341 2340
@@ -2378,8 +2377,7 @@ static void ffs_func_resume(struct usb_function *f)
2378} 2377}
2379 2378
2380 2379
2381 2380/* Endpoint and interface numbers reverse mapping ***************************/
2382/* Enpoint and interface numbers reverse mapping ****************************/
2383 2381
2384static int ffs_func_revmap_ep(struct ffs_function *func, u8 num) 2382static int ffs_func_revmap_ep(struct ffs_function *func, u8 num)
2385{ 2383{
@@ -2410,7 +2408,6 @@ static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
2410 : mutex_lock_interruptible(mutex); 2408 : mutex_lock_interruptible(mutex);
2411} 2409}
2412 2410
2413
2414static char *ffs_prepare_buffer(const char * __user buf, size_t len) 2411static char *ffs_prepare_buffer(const char * __user buf, size_t len)
2415{ 2412{
2416 char *data; 2413 char *data;
@@ -2427,7 +2424,7 @@ static char *ffs_prepare_buffer(const char * __user buf, size_t len)
2427 return ERR_PTR(-EFAULT); 2424 return ERR_PTR(-EFAULT);
2428 } 2425 }
2429 2426
2430 FVDBG("Buffer from user space:"); 2427 pr_vdebug("Buffer from user space:\n");
2431 ffs_dump_mem("", data, len); 2428 ffs_dump_mem("", data, len);
2432 2429
2433 return data; 2430 return data;
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c
index 53e120208e99..598e7e2ab80c 100644
--- a/drivers/usb/gadget/f_hid.c
+++ b/drivers/usb/gadget/f_hid.c
@@ -25,7 +25,6 @@
25#include <linux/cdev.h> 25#include <linux/cdev.h>
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include <linux/poll.h> 27#include <linux/poll.h>
28#include <linux/smp_lock.h>
29#include <linux/uaccess.h> 28#include <linux/uaccess.h>
30#include <linux/wait.h> 29#include <linux/wait.h>
31#include <linux/usb/g_hid.h> 30#include <linux/usb/g_hid.h>
@@ -318,8 +317,6 @@ static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req)
318 spin_unlock(&hidg->spinlock); 317 spin_unlock(&hidg->spinlock);
319 318
320 wake_up(&hidg->read_queue); 319 wake_up(&hidg->read_queue);
321
322 return;
323} 320}
324 321
325static int hidg_setup(struct usb_function *f, 322static int hidg_setup(struct usb_function *f,
@@ -413,8 +410,6 @@ static void hidg_disable(struct usb_function *f)
413 410
414 usb_ep_disable(hidg->in_ep); 411 usb_ep_disable(hidg->in_ep);
415 hidg->in_ep->driver_data = NULL; 412 hidg->in_ep->driver_data = NULL;
416
417 return;
418} 413}
419 414
420static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) 415static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
@@ -451,6 +446,7 @@ const struct file_operations f_hidg_fops = {
451 .write = f_hidg_write, 446 .write = f_hidg_write,
452 .read = f_hidg_read, 447 .read = f_hidg_read,
453 .poll = f_hidg_poll, 448 .poll = f_hidg_poll,
449 .llseek = noop_llseek,
454}; 450};
455 451
456static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f) 452static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index 43225879c3cd..b37960f9e753 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -324,7 +324,7 @@ static void loopback_disable(struct usb_function *f)
324 324
325/*-------------------------------------------------------------------------*/ 325/*-------------------------------------------------------------------------*/
326 326
327static int __ref loopback_bind_config(struct usb_configuration *c) 327static int __init loopback_bind_config(struct usb_configuration *c)
328{ 328{
329 struct f_loopback *loop; 329 struct f_loopback *loop;
330 int status; 330 int status;
@@ -346,10 +346,9 @@ static int __ref loopback_bind_config(struct usb_configuration *c)
346 return status; 346 return status;
347} 347}
348 348
349static struct usb_configuration loopback_driver = { 349static struct usb_configuration loopback_driver = {
350 .label = "loopback", 350 .label = "loopback",
351 .strings = loopback_strings, 351 .strings = loopback_strings,
352 .bind = loopback_bind_config,
353 .bConfigurationValue = 2, 352 .bConfigurationValue = 2,
354 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 353 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
355 /* .iConfiguration = DYNAMIC */ 354 /* .iConfiguration = DYNAMIC */
@@ -382,5 +381,5 @@ int __init loopback_add(struct usb_composite_dev *cdev, bool autoresume)
382 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 381 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
383 } 382 }
384 383
385 return usb_add_config(cdev, &loopback_driver); 384 return usb_add_config(cdev, &loopback_driver, loopback_bind_config);
386} 385}
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 32cce029f65c..efb58f9f5aa9 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -37,7 +37,6 @@
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */ 38 */
39 39
40
41/* 40/*
42 * The Mass Storage Function acts as a USB Mass Storage device, 41 * The Mass Storage Function acts as a USB Mass Storage device,
43 * appearing to the host as a disk drive or as a CD-ROM drive. In 42 * appearing to the host as a disk drive or as a CD-ROM drive. In
@@ -73,6 +72,8 @@
73 * being removable. 72 * being removable.
74 * ->cdrom Flag specifying that LUN shall be reported as 73 * ->cdrom Flag specifying that LUN shall be reported as
75 * being a CD-ROM. 74 * being a CD-ROM.
75 * ->nofua Flag specifying that FUA flag in SCSI WRITE(10,12)
76 * commands for this LUN shall be ignored.
76 * 77 *
77 * lun_name_format A printf-like format for names of the LUN 78 * lun_name_format A printf-like format for names of the LUN
78 * devices. This determines how the 79 * devices. This determines how the
@@ -127,6 +128,8 @@
127 * Default true, boolean for removable media. 128 * Default true, boolean for removable media.
128 * cdrom=b[,b...] Default false, boolean for whether to emulate 129 * cdrom=b[,b...] Default false, boolean for whether to emulate
129 * a CD-ROM drive. 130 * a CD-ROM drive.
131 * nofua=b[,b...] Default false, booleans for ignore FUA flag
132 * in SCSI WRITE(10,12) commands
130 * luns=N Default N = number of filenames, number of 133 * luns=N Default N = number of filenames, number of
131 * LUNs to support. 134 * LUNs to support.
132 * stall Default determined according to the type of 135 * stall Default determined according to the type of
@@ -181,7 +184,6 @@
181 * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>. 184 * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
182 */ 185 */
183 186
184
185/* 187/*
186 * Driver Design 188 * Driver Design
187 * 189 *
@@ -271,7 +273,6 @@
271/* #define VERBOSE_DEBUG */ 273/* #define VERBOSE_DEBUG */
272/* #define DUMP_MSGS */ 274/* #define DUMP_MSGS */
273 275
274
275#include <linux/blkdev.h> 276#include <linux/blkdev.h>
276#include <linux/completion.h> 277#include <linux/completion.h>
277#include <linux/dcache.h> 278#include <linux/dcache.h>
@@ -292,11 +293,11 @@
292 293
293#include <linux/usb/ch9.h> 294#include <linux/usb/ch9.h>
294#include <linux/usb/gadget.h> 295#include <linux/usb/gadget.h>
296#include <linux/usb/composite.h>
295 297
296#include "gadget_chips.h" 298#include "gadget_chips.h"
297 299
298 300
299
300/*------------------------------------------------------------------------*/ 301/*------------------------------------------------------------------------*/
301 302
302#define FSG_DRIVER_DESC "Mass Storage Function" 303#define FSG_DRIVER_DESC "Mass Storage Function"
@@ -304,7 +305,6 @@
304 305
305static const char fsg_string_interface[] = "Mass Storage"; 306static const char fsg_string_interface[] = "Mass Storage";
306 307
307
308#define FSG_NO_INTR_EP 1 308#define FSG_NO_INTR_EP 1
309#define FSG_NO_DEVICE_STRINGS 1 309#define FSG_NO_DEVICE_STRINGS 1
310#define FSG_NO_OTG 1 310#define FSG_NO_OTG 1
@@ -320,28 +320,34 @@ struct fsg_common;
320 320
321/* FSF callback functions */ 321/* FSF callback functions */
322struct fsg_operations { 322struct fsg_operations {
323 /* Callback function to call when thread exits. If no 323 /*
324 * Callback function to call when thread exits. If no
324 * callback is set or it returns value lower then zero MSF 325 * callback is set or it returns value lower then zero MSF
325 * will force eject all LUNs it operates on (including those 326 * will force eject all LUNs it operates on (including those
326 * marked as non-removable or with prevent_medium_removal flag 327 * marked as non-removable or with prevent_medium_removal flag
327 * set). */ 328 * set).
329 */
328 int (*thread_exits)(struct fsg_common *common); 330 int (*thread_exits)(struct fsg_common *common);
329 331
330 /* Called prior to ejection. Negative return means error, 332 /*
333 * Called prior to ejection. Negative return means error,
331 * zero means to continue with ejection, positive means not to 334 * zero means to continue with ejection, positive means not to
332 * eject. */ 335 * eject.
336 */
333 int (*pre_eject)(struct fsg_common *common, 337 int (*pre_eject)(struct fsg_common *common,
334 struct fsg_lun *lun, int num); 338 struct fsg_lun *lun, int num);
335 /* Called after ejection. Negative return means error, zero 339 /*
336 * or positive is just a success. */ 340 * Called after ejection. Negative return means error, zero
341 * or positive is just a success.
342 */
337 int (*post_eject)(struct fsg_common *common, 343 int (*post_eject)(struct fsg_common *common,
338 struct fsg_lun *lun, int num); 344 struct fsg_lun *lun, int num);
339}; 345};
340 346
341
342/* Data shared by all the FSG instances. */ 347/* Data shared by all the FSG instances. */
343struct fsg_common { 348struct fsg_common {
344 struct usb_gadget *gadget; 349 struct usb_gadget *gadget;
350 struct usb_composite_dev *cdev;
345 struct fsg_dev *fsg, *new_fsg; 351 struct fsg_dev *fsg, *new_fsg;
346 wait_queue_head_t fsg_wait; 352 wait_queue_head_t fsg_wait;
347 353
@@ -394,14 +400,15 @@ struct fsg_common {
394 /* Gadget's private data. */ 400 /* Gadget's private data. */
395 void *private_data; 401 void *private_data;
396 402
397 /* Vendor (8 chars), product (16 chars), release (4 403 /*
398 * hexadecimal digits) and NUL byte */ 404 * Vendor (8 chars), product (16 chars), release (4
405 * hexadecimal digits) and NUL byte
406 */
399 char inquiry_string[8 + 16 + 4 + 1]; 407 char inquiry_string[8 + 16 + 4 + 1];
400 408
401 struct kref ref; 409 struct kref ref;
402}; 410};
403 411
404
405struct fsg_config { 412struct fsg_config {
406 unsigned nluns; 413 unsigned nluns;
407 struct fsg_lun_config { 414 struct fsg_lun_config {
@@ -409,6 +416,7 @@ struct fsg_config {
409 char ro; 416 char ro;
410 char removable; 417 char removable;
411 char cdrom; 418 char cdrom;
419 char nofua;
412 } luns[FSG_MAX_LUNS]; 420 } luns[FSG_MAX_LUNS];
413 421
414 const char *lun_name_format; 422 const char *lun_name_format;
@@ -426,7 +434,6 @@ struct fsg_config {
426 char can_stall; 434 char can_stall;
427}; 435};
428 436
429
430struct fsg_dev { 437struct fsg_dev {
431 struct usb_function function; 438 struct usb_function function;
432 struct usb_gadget *gadget; /* Copy of cdev->gadget */ 439 struct usb_gadget *gadget; /* Copy of cdev->gadget */
@@ -444,7 +451,6 @@ struct fsg_dev {
444 struct usb_ep *bulk_out; 451 struct usb_ep *bulk_out;
445}; 452};
446 453
447
448static inline int __fsg_is_set(struct fsg_common *common, 454static inline int __fsg_is_set(struct fsg_common *common,
449 const char *func, unsigned line) 455 const char *func, unsigned line)
450{ 456{
@@ -457,13 +463,11 @@ static inline int __fsg_is_set(struct fsg_common *common,
457 463
458#define fsg_is_set(common) likely(__fsg_is_set(common, __func__, __LINE__)) 464#define fsg_is_set(common) likely(__fsg_is_set(common, __func__, __LINE__))
459 465
460
461static inline struct fsg_dev *fsg_from_func(struct usb_function *f) 466static inline struct fsg_dev *fsg_from_func(struct usb_function *f)
462{ 467{
463 return container_of(f, struct fsg_dev, function); 468 return container_of(f, struct fsg_dev, function);
464} 469}
465 470
466
467typedef void (*fsg_routine_t)(struct fsg_dev *); 471typedef void (*fsg_routine_t)(struct fsg_dev *);
468 472
469static int exception_in_progress(struct fsg_common *common) 473static int exception_in_progress(struct fsg_common *common)
@@ -473,7 +477,7 @@ static int exception_in_progress(struct fsg_common *common)
473 477
474/* Make bulk-out requests be divisible by the maxpacket size */ 478/* Make bulk-out requests be divisible by the maxpacket size */
475static void set_bulk_out_req_length(struct fsg_common *common, 479static void set_bulk_out_req_length(struct fsg_common *common,
476 struct fsg_buffhd *bh, unsigned int length) 480 struct fsg_buffhd *bh, unsigned int length)
477{ 481{
478 unsigned int rem; 482 unsigned int rem;
479 483
@@ -484,6 +488,7 @@ static void set_bulk_out_req_length(struct fsg_common *common,
484 bh->outreq->length = length; 488 bh->outreq->length = length;
485} 489}
486 490
491
487/*-------------------------------------------------------------------------*/ 492/*-------------------------------------------------------------------------*/
488 493
489static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep) 494static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
@@ -514,14 +519,15 @@ static void wakeup_thread(struct fsg_common *common)
514 wake_up_process(common->thread_task); 519 wake_up_process(common->thread_task);
515} 520}
516 521
517
518static void raise_exception(struct fsg_common *common, enum fsg_state new_state) 522static void raise_exception(struct fsg_common *common, enum fsg_state new_state)
519{ 523{
520 unsigned long flags; 524 unsigned long flags;
521 525
522 /* Do nothing if a higher-priority exception is already in progress. 526 /*
527 * Do nothing if a higher-priority exception is already in progress.
523 * If a lower-or-equal priority exception is in progress, preempt it 528 * If a lower-or-equal priority exception is in progress, preempt it
524 * and notify the main thread by sending it a signal. */ 529 * and notify the main thread by sending it a signal.
530 */
525 spin_lock_irqsave(&common->lock, flags); 531 spin_lock_irqsave(&common->lock, flags);
526 if (common->state <= new_state) { 532 if (common->state <= new_state) {
527 common->exception_req_tag = common->ep0_req_tag; 533 common->exception_req_tag = common->ep0_req_tag;
@@ -550,10 +556,10 @@ static int ep0_queue(struct fsg_common *common)
550 return rc; 556 return rc;
551} 557}
552 558
559
553/*-------------------------------------------------------------------------*/ 560/*-------------------------------------------------------------------------*/
554 561
555/* Bulk and interrupt endpoint completion handlers. 562/* Completion handlers. These always run in_irq. */
556 * These always run in_irq. */
557 563
558static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req) 564static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
559{ 565{
@@ -562,7 +568,7 @@ static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
562 568
563 if (req->status || req->actual != req->length) 569 if (req->status || req->actual != req->length)
564 DBG(common, "%s --> %d, %u/%u\n", __func__, 570 DBG(common, "%s --> %d, %u/%u\n", __func__,
565 req->status, req->actual, req->length); 571 req->status, req->actual, req->length);
566 if (req->status == -ECONNRESET) /* Request was cancelled */ 572 if (req->status == -ECONNRESET) /* Request was cancelled */
567 usb_ep_fifo_flush(ep); 573 usb_ep_fifo_flush(ep);
568 574
@@ -583,8 +589,7 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
583 dump_msg(common, "bulk-out", req->buf, req->actual); 589 dump_msg(common, "bulk-out", req->buf, req->actual);
584 if (req->status || req->actual != bh->bulk_out_intended_length) 590 if (req->status || req->actual != bh->bulk_out_intended_length)
585 DBG(common, "%s --> %d, %u/%u\n", __func__, 591 DBG(common, "%s --> %d, %u/%u\n", __func__,
586 req->status, req->actual, 592 req->status, req->actual, bh->bulk_out_intended_length);
587 bh->bulk_out_intended_length);
588 if (req->status == -ECONNRESET) /* Request was cancelled */ 593 if (req->status == -ECONNRESET) /* Request was cancelled */
589 usb_ep_fifo_flush(ep); 594 usb_ep_fifo_flush(ep);
590 595
@@ -597,13 +602,8 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
597 spin_unlock(&common->lock); 602 spin_unlock(&common->lock);
598} 603}
599 604
600
601/*-------------------------------------------------------------------------*/
602
603/* Ep0 class-specific handlers. These always run in_irq. */
604
605static int fsg_setup(struct usb_function *f, 605static int fsg_setup(struct usb_function *f,
606 const struct usb_ctrlrequest *ctrl) 606 const struct usb_ctrlrequest *ctrl)
607{ 607{
608 struct fsg_dev *fsg = fsg_from_func(f); 608 struct fsg_dev *fsg = fsg_from_func(f);
609 struct usb_request *req = fsg->common->ep0req; 609 struct usb_request *req = fsg->common->ep0req;
@@ -614,6 +614,11 @@ static int fsg_setup(struct usb_function *f,
614 if (!fsg_is_set(fsg->common)) 614 if (!fsg_is_set(fsg->common))
615 return -EOPNOTSUPP; 615 return -EOPNOTSUPP;
616 616
617 ++fsg->common->ep0_req_tag; /* Record arrival of a new request */
618 req->context = NULL;
619 req->length = 0;
620 dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
621
617 switch (ctrl->bRequest) { 622 switch (ctrl->bRequest) {
618 623
619 case USB_BULK_RESET_REQUEST: 624 case USB_BULK_RESET_REQUEST:
@@ -623,8 +628,10 @@ static int fsg_setup(struct usb_function *f,
623 if (w_index != fsg->interface_number || w_value != 0) 628 if (w_index != fsg->interface_number || w_value != 0)
624 return -EDOM; 629 return -EDOM;
625 630
626 /* Raise an exception to stop the current operation 631 /*
627 * and reinitialize our state. */ 632 * Raise an exception to stop the current operation
633 * and reinitialize our state.
634 */
628 DBG(fsg, "bulk reset request\n"); 635 DBG(fsg, "bulk reset request\n");
629 raise_exception(fsg->common, FSG_STATE_RESET); 636 raise_exception(fsg->common, FSG_STATE_RESET);
630 return DELAYED_STATUS; 637 return DELAYED_STATUS;
@@ -636,7 +643,7 @@ static int fsg_setup(struct usb_function *f,
636 if (w_index != fsg->interface_number || w_value != 0) 643 if (w_index != fsg->interface_number || w_value != 0)
637 return -EDOM; 644 return -EDOM;
638 VDBG(fsg, "get max LUN\n"); 645 VDBG(fsg, "get max LUN\n");
639 *(u8 *) req->buf = fsg->common->nluns - 1; 646 *(u8 *)req->buf = fsg->common->nluns - 1;
640 647
641 /* Respond with data/status */ 648 /* Respond with data/status */
642 req->length = min((u16)1, w_length); 649 req->length = min((u16)1, w_length);
@@ -644,8 +651,7 @@ static int fsg_setup(struct usb_function *f,
644 } 651 }
645 652
646 VDBG(fsg, 653 VDBG(fsg,
647 "unknown class-specific control req " 654 "unknown class-specific control req %02x.%02x v%04x i%04x l%u\n",
648 "%02x.%02x v%04x i%04x l%u\n",
649 ctrl->bRequestType, ctrl->bRequest, 655 ctrl->bRequestType, ctrl->bRequest,
650 le16_to_cpu(ctrl->wValue), w_index, w_length); 656 le16_to_cpu(ctrl->wValue), w_index, w_length);
651 return -EOPNOTSUPP; 657 return -EOPNOTSUPP;
@@ -656,11 +662,10 @@ static int fsg_setup(struct usb_function *f,
656 662
657/* All the following routines run in process context */ 663/* All the following routines run in process context */
658 664
659
660/* Use this for bulk or interrupt transfers, not ep0 */ 665/* Use this for bulk or interrupt transfers, not ep0 */
661static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, 666static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
662 struct usb_request *req, int *pbusy, 667 struct usb_request *req, int *pbusy,
663 enum fsg_buffer_state *state) 668 enum fsg_buffer_state *state)
664{ 669{
665 int rc; 670 int rc;
666 671
@@ -678,25 +683,34 @@ static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
678 683
679 /* We can't do much more than wait for a reset */ 684 /* We can't do much more than wait for a reset */
680 685
681 /* Note: currently the net2280 driver fails zero-length 686 /*
682 * submissions if DMA is enabled. */ 687 * Note: currently the net2280 driver fails zero-length
683 if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP && 688 * submissions if DMA is enabled.
684 req->length == 0)) 689 */
690 if (rc != -ESHUTDOWN &&
691 !(rc == -EOPNOTSUPP && req->length == 0))
685 WARNING(fsg, "error in submission: %s --> %d\n", 692 WARNING(fsg, "error in submission: %s --> %d\n",
686 ep->name, rc); 693 ep->name, rc);
687 } 694 }
688} 695}
689 696
690#define START_TRANSFER_OR(common, ep_name, req, pbusy, state) \ 697static bool start_in_transfer(struct fsg_common *common, struct fsg_buffhd *bh)
691 if (fsg_is_set(common)) \ 698{
692 start_transfer((common)->fsg, (common)->fsg->ep_name, \ 699 if (!fsg_is_set(common))
693 req, pbusy, state); \ 700 return false;
694 else 701 start_transfer(common->fsg, common->fsg->bulk_in,
695 702 bh->inreq, &bh->inreq_busy, &bh->state);
696#define START_TRANSFER(common, ep_name, req, pbusy, state) \ 703 return true;
697 START_TRANSFER_OR(common, ep_name, req, pbusy, state) (void)0 704}
698
699 705
706static bool start_out_transfer(struct fsg_common *common, struct fsg_buffhd *bh)
707{
708 if (!fsg_is_set(common))
709 return false;
710 start_transfer(common->fsg, common->fsg->bulk_out,
711 bh->outreq, &bh->outreq_busy, &bh->state);
712 return true;
713}
700 714
701static int sleep_thread(struct fsg_common *common) 715static int sleep_thread(struct fsg_common *common)
702{ 716{
@@ -734,16 +748,20 @@ static int do_read(struct fsg_common *common)
734 unsigned int partial_page; 748 unsigned int partial_page;
735 ssize_t nread; 749 ssize_t nread;
736 750
737 /* Get the starting Logical Block Address and check that it's 751 /*
738 * not too big */ 752 * Get the starting Logical Block Address and check that it's
739 if (common->cmnd[0] == SC_READ_6) 753 * not too big.
754 */
755 if (common->cmnd[0] == READ_6)
740 lba = get_unaligned_be24(&common->cmnd[1]); 756 lba = get_unaligned_be24(&common->cmnd[1]);
741 else { 757 else {
742 lba = get_unaligned_be32(&common->cmnd[2]); 758 lba = get_unaligned_be32(&common->cmnd[2]);
743 759
744 /* We allow DPO (Disable Page Out = don't save data in the 760 /*
761 * We allow DPO (Disable Page Out = don't save data in the
745 * cache) and FUA (Force Unit Access = don't read from the 762 * cache) and FUA (Force Unit Access = don't read from the
746 * cache), but we don't implement them. */ 763 * cache), but we don't implement them.
764 */
747 if ((common->cmnd[1] & ~0x18) != 0) { 765 if ((common->cmnd[1] & ~0x18) != 0) {
748 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 766 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
749 return -EINVAL; 767 return -EINVAL;
@@ -761,22 +779,23 @@ static int do_read(struct fsg_common *common)
761 return -EIO; /* No default reply */ 779 return -EIO; /* No default reply */
762 780
763 for (;;) { 781 for (;;) {
764 782 /*
765 /* Figure out how much we need to read: 783 * Figure out how much we need to read:
766 * Try to read the remaining amount. 784 * Try to read the remaining amount.
767 * But don't read more than the buffer size. 785 * But don't read more than the buffer size.
768 * And don't try to read past the end of the file. 786 * And don't try to read past the end of the file.
769 * Finally, if we're not at a page boundary, don't read past 787 * Finally, if we're not at a page boundary, don't read past
770 * the next page. 788 * the next page.
771 * If this means reading 0 then we were asked to read past 789 * If this means reading 0 then we were asked to read past
772 * the end of file. */ 790 * the end of file.
791 */
773 amount = min(amount_left, FSG_BUFLEN); 792 amount = min(amount_left, FSG_BUFLEN);
774 amount = min((loff_t) amount, 793 amount = min((loff_t)amount,
775 curlun->file_length - file_offset); 794 curlun->file_length - file_offset);
776 partial_page = file_offset & (PAGE_CACHE_SIZE - 1); 795 partial_page = file_offset & (PAGE_CACHE_SIZE - 1);
777 if (partial_page > 0) 796 if (partial_page > 0)
778 amount = min(amount, (unsigned int) PAGE_CACHE_SIZE - 797 amount = min(amount, (unsigned int)PAGE_CACHE_SIZE -
779 partial_page); 798 partial_page);
780 799
781 /* Wait for the next buffer to become available */ 800 /* Wait for the next buffer to become available */
782 bh = common->next_buffhd_to_fill; 801 bh = common->next_buffhd_to_fill;
@@ -786,8 +805,10 @@ static int do_read(struct fsg_common *common)
786 return rc; 805 return rc;
787 } 806 }
788 807
789 /* If we were asked to read past the end of file, 808 /*
790 * end with an empty buffer. */ 809 * If we were asked to read past the end of file,
810 * end with an empty buffer.
811 */
791 if (amount == 0) { 812 if (amount == 0) {
792 curlun->sense_data = 813 curlun->sense_data =
793 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 814 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
@@ -801,21 +822,19 @@ static int do_read(struct fsg_common *common)
801 /* Perform the read */ 822 /* Perform the read */
802 file_offset_tmp = file_offset; 823 file_offset_tmp = file_offset;
803 nread = vfs_read(curlun->filp, 824 nread = vfs_read(curlun->filp,
804 (char __user *) bh->buf, 825 (char __user *)bh->buf,
805 amount, &file_offset_tmp); 826 amount, &file_offset_tmp);
806 VLDBG(curlun, "file read %u @ %llu -> %d\n", amount, 827 VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
807 (unsigned long long) file_offset, 828 (unsigned long long)file_offset, (int)nread);
808 (int) nread);
809 if (signal_pending(current)) 829 if (signal_pending(current))
810 return -EINTR; 830 return -EINTR;
811 831
812 if (nread < 0) { 832 if (nread < 0) {
813 LDBG(curlun, "error in file read: %d\n", 833 LDBG(curlun, "error in file read: %d\n", (int)nread);
814 (int) nread);
815 nread = 0; 834 nread = 0;
816 } else if (nread < amount) { 835 } else if (nread < amount) {
817 LDBG(curlun, "partial file read: %d/%u\n", 836 LDBG(curlun, "partial file read: %d/%u\n",
818 (int) nread, amount); 837 (int)nread, amount);
819 nread -= (nread & 511); /* Round down to a block */ 838 nread -= (nread & 511); /* Round down to a block */
820 } 839 }
821 file_offset += nread; 840 file_offset += nread;
@@ -837,10 +856,8 @@ static int do_read(struct fsg_common *common)
837 856
838 /* Send this buffer and go read some more */ 857 /* Send this buffer and go read some more */
839 bh->inreq->zero = 0; 858 bh->inreq->zero = 0;
840 START_TRANSFER_OR(common, bulk_in, bh->inreq, 859 if (!start_in_transfer(common, bh))
841 &bh->inreq_busy, &bh->state) 860 /* Don't know what to do if common->fsg is NULL */
842 /* Don't know what to do if
843 * common->fsg is NULL */
844 return -EIO; 861 return -EIO;
845 common->next_buffhd_to_fill = bh->next; 862 common->next_buffhd_to_fill = bh->next;
846 } 863 }
@@ -872,22 +889,26 @@ static int do_write(struct fsg_common *common)
872 curlun->filp->f_flags &= ~O_SYNC; /* Default is not to wait */ 889 curlun->filp->f_flags &= ~O_SYNC; /* Default is not to wait */
873 spin_unlock(&curlun->filp->f_lock); 890 spin_unlock(&curlun->filp->f_lock);
874 891
875 /* Get the starting Logical Block Address and check that it's 892 /*
876 * not too big */ 893 * Get the starting Logical Block Address and check that it's
877 if (common->cmnd[0] == SC_WRITE_6) 894 * not too big
895 */
896 if (common->cmnd[0] == WRITE_6)
878 lba = get_unaligned_be24(&common->cmnd[1]); 897 lba = get_unaligned_be24(&common->cmnd[1]);
879 else { 898 else {
880 lba = get_unaligned_be32(&common->cmnd[2]); 899 lba = get_unaligned_be32(&common->cmnd[2]);
881 900
882 /* We allow DPO (Disable Page Out = don't save data in the 901 /*
902 * We allow DPO (Disable Page Out = don't save data in the
883 * cache) and FUA (Force Unit Access = write directly to the 903 * cache) and FUA (Force Unit Access = write directly to the
884 * medium). We don't implement DPO; we implement FUA by 904 * medium). We don't implement DPO; we implement FUA by
885 * performing synchronous output. */ 905 * performing synchronous output.
906 */
886 if (common->cmnd[1] & ~0x18) { 907 if (common->cmnd[1] & ~0x18) {
887 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 908 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
888 return -EINVAL; 909 return -EINVAL;
889 } 910 }
890 if (common->cmnd[1] & 0x08) { /* FUA */ 911 if (!curlun->nofua && (common->cmnd[1] & 0x08)) { /* FUA */
891 spin_lock(&curlun->filp->f_lock); 912 spin_lock(&curlun->filp->f_lock);
892 curlun->filp->f_flags |= O_SYNC; 913 curlun->filp->f_flags |= O_SYNC;
893 spin_unlock(&curlun->filp->f_lock); 914 spin_unlock(&curlun->filp->f_lock);
@@ -910,7 +931,8 @@ static int do_write(struct fsg_common *common)
910 bh = common->next_buffhd_to_fill; 931 bh = common->next_buffhd_to_fill;
911 if (bh->state == BUF_STATE_EMPTY && get_some_more) { 932 if (bh->state == BUF_STATE_EMPTY && get_some_more) {
912 933
913 /* Figure out how much we want to get: 934 /*
935 * Figure out how much we want to get:
914 * Try to get the remaining amount. 936 * Try to get the remaining amount.
915 * But don't get more than the buffer size. 937 * But don't get more than the buffer size.
916 * And don't try to go past the end of the file. 938 * And don't try to go past the end of the file.
@@ -918,14 +940,15 @@ static int do_write(struct fsg_common *common)
918 * don't go past the next page. 940 * don't go past the next page.
919 * If this means getting 0, then we were asked 941 * If this means getting 0, then we were asked
920 * to write past the end of file. 942 * to write past the end of file.
921 * Finally, round down to a block boundary. */ 943 * Finally, round down to a block boundary.
944 */
922 amount = min(amount_left_to_req, FSG_BUFLEN); 945 amount = min(amount_left_to_req, FSG_BUFLEN);
923 amount = min((loff_t) amount, curlun->file_length - 946 amount = min((loff_t)amount,
924 usb_offset); 947 curlun->file_length - usb_offset);
925 partial_page = usb_offset & (PAGE_CACHE_SIZE - 1); 948 partial_page = usb_offset & (PAGE_CACHE_SIZE - 1);
926 if (partial_page > 0) 949 if (partial_page > 0)
927 amount = min(amount, 950 amount = min(amount,
928 (unsigned int) PAGE_CACHE_SIZE - partial_page); 951 (unsigned int)PAGE_CACHE_SIZE - partial_page);
929 952
930 if (amount == 0) { 953 if (amount == 0) {
931 get_some_more = 0; 954 get_some_more = 0;
@@ -935,11 +958,13 @@ static int do_write(struct fsg_common *common)
935 curlun->info_valid = 1; 958 curlun->info_valid = 1;
936 continue; 959 continue;
937 } 960 }
938 amount -= (amount & 511); 961 amount -= amount & 511;
939 if (amount == 0) { 962 if (amount == 0) {
940 963
941 /* Why were we were asked to transfer a 964 /*
942 * partial block? */ 965 * Why were we were asked to transfer a
966 * partial block?
967 */
943 get_some_more = 0; 968 get_some_more = 0;
944 continue; 969 continue;
945 } 970 }
@@ -951,15 +976,15 @@ static int do_write(struct fsg_common *common)
951 if (amount_left_to_req == 0) 976 if (amount_left_to_req == 0)
952 get_some_more = 0; 977 get_some_more = 0;
953 978
954 /* amount is always divisible by 512, hence by 979 /*
955 * the bulk-out maxpacket size */ 980 * amount is always divisible by 512, hence by
981 * the bulk-out maxpacket size
982 */
956 bh->outreq->length = amount; 983 bh->outreq->length = amount;
957 bh->bulk_out_intended_length = amount; 984 bh->bulk_out_intended_length = amount;
958 bh->outreq->short_not_ok = 1; 985 bh->outreq->short_not_ok = 1;
959 START_TRANSFER_OR(common, bulk_out, bh->outreq, 986 if (!start_out_transfer(common, bh))
960 &bh->outreq_busy, &bh->state) 987 /* Dunno what to do if common->fsg is NULL */
961 /* Don't know what to do if
962 * common->fsg is NULL */
963 return -EIO; 988 return -EIO;
964 common->next_buffhd_to_fill = bh->next; 989 common->next_buffhd_to_fill = bh->next;
965 continue; 990 continue;
@@ -985,30 +1010,29 @@ static int do_write(struct fsg_common *common)
985 amount = bh->outreq->actual; 1010 amount = bh->outreq->actual;
986 if (curlun->file_length - file_offset < amount) { 1011 if (curlun->file_length - file_offset < amount) {
987 LERROR(curlun, 1012 LERROR(curlun,
988 "write %u @ %llu beyond end %llu\n", 1013 "write %u @ %llu beyond end %llu\n",
989 amount, (unsigned long long) file_offset, 1014 amount, (unsigned long long)file_offset,
990 (unsigned long long) curlun->file_length); 1015 (unsigned long long)curlun->file_length);
991 amount = curlun->file_length - file_offset; 1016 amount = curlun->file_length - file_offset;
992 } 1017 }
993 1018
994 /* Perform the write */ 1019 /* Perform the write */
995 file_offset_tmp = file_offset; 1020 file_offset_tmp = file_offset;
996 nwritten = vfs_write(curlun->filp, 1021 nwritten = vfs_write(curlun->filp,
997 (char __user *) bh->buf, 1022 (char __user *)bh->buf,
998 amount, &file_offset_tmp); 1023 amount, &file_offset_tmp);
999 VLDBG(curlun, "file write %u @ %llu -> %d\n", amount, 1024 VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
1000 (unsigned long long) file_offset, 1025 (unsigned long long)file_offset, (int)nwritten);
1001 (int) nwritten);
1002 if (signal_pending(current)) 1026 if (signal_pending(current))
1003 return -EINTR; /* Interrupted! */ 1027 return -EINTR; /* Interrupted! */
1004 1028
1005 if (nwritten < 0) { 1029 if (nwritten < 0) {
1006 LDBG(curlun, "error in file write: %d\n", 1030 LDBG(curlun, "error in file write: %d\n",
1007 (int) nwritten); 1031 (int)nwritten);
1008 nwritten = 0; 1032 nwritten = 0;
1009 } else if (nwritten < amount) { 1033 } else if (nwritten < amount) {
1010 LDBG(curlun, "partial file write: %d/%u\n", 1034 LDBG(curlun, "partial file write: %d/%u\n",
1011 (int) nwritten, amount); 1035 (int)nwritten, amount);
1012 nwritten -= (nwritten & 511); 1036 nwritten -= (nwritten & 511);
1013 /* Round down to a block */ 1037 /* Round down to a block */
1014 } 1038 }
@@ -1081,16 +1105,20 @@ static int do_verify(struct fsg_common *common)
1081 unsigned int amount; 1105 unsigned int amount;
1082 ssize_t nread; 1106 ssize_t nread;
1083 1107
1084 /* Get the starting Logical Block Address and check that it's 1108 /*
1085 * not too big */ 1109 * Get the starting Logical Block Address and check that it's
1110 * not too big.
1111 */
1086 lba = get_unaligned_be32(&common->cmnd[2]); 1112 lba = get_unaligned_be32(&common->cmnd[2]);
1087 if (lba >= curlun->num_sectors) { 1113 if (lba >= curlun->num_sectors) {
1088 curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 1114 curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
1089 return -EINVAL; 1115 return -EINVAL;
1090 } 1116 }
1091 1117
1092 /* We allow DPO (Disable Page Out = don't save data in the 1118 /*
1093 * cache) but we don't implement it. */ 1119 * We allow DPO (Disable Page Out = don't save data in the
1120 * cache) but we don't implement it.
1121 */
1094 if (common->cmnd[1] & ~0x10) { 1122 if (common->cmnd[1] & ~0x10) {
1095 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1123 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1096 return -EINVAL; 1124 return -EINVAL;
@@ -1115,16 +1143,17 @@ static int do_verify(struct fsg_common *common)
1115 1143
1116 /* Just try to read the requested blocks */ 1144 /* Just try to read the requested blocks */
1117 while (amount_left > 0) { 1145 while (amount_left > 0) {
1118 1146 /*
1119 /* Figure out how much we need to read: 1147 * Figure out how much we need to read:
1120 * Try to read the remaining amount, but not more than 1148 * Try to read the remaining amount, but not more than
1121 * the buffer size. 1149 * the buffer size.
1122 * And don't try to read past the end of the file. 1150 * And don't try to read past the end of the file.
1123 * If this means reading 0 then we were asked to read 1151 * If this means reading 0 then we were asked to read
1124 * past the end of file. */ 1152 * past the end of file.
1153 */
1125 amount = min(amount_left, FSG_BUFLEN); 1154 amount = min(amount_left, FSG_BUFLEN);
1126 amount = min((loff_t) amount, 1155 amount = min((loff_t)amount,
1127 curlun->file_length - file_offset); 1156 curlun->file_length - file_offset);
1128 if (amount == 0) { 1157 if (amount == 0) {
1129 curlun->sense_data = 1158 curlun->sense_data =
1130 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 1159 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
@@ -1145,13 +1174,12 @@ static int do_verify(struct fsg_common *common)
1145 return -EINTR; 1174 return -EINTR;
1146 1175
1147 if (nread < 0) { 1176 if (nread < 0) {
1148 LDBG(curlun, "error in file verify: %d\n", 1177 LDBG(curlun, "error in file verify: %d\n", (int)nread);
1149 (int) nread);
1150 nread = 0; 1178 nread = 0;
1151 } else if (nread < amount) { 1179 } else if (nread < amount) {
1152 LDBG(curlun, "partial file verify: %d/%u\n", 1180 LDBG(curlun, "partial file verify: %d/%u\n",
1153 (int) nread, amount); 1181 (int)nread, amount);
1154 nread -= (nread & 511); /* Round down to a sector */ 1182 nread -= nread & 511; /* Round down to a sector */
1155 } 1183 }
1156 if (nread == 0) { 1184 if (nread == 0) {
1157 curlun->sense_data = SS_UNRECOVERED_READ_ERROR; 1185 curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
@@ -1181,7 +1209,7 @@ static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh)
1181 return 36; 1209 return 36;
1182 } 1210 }
1183 1211
1184 buf[0] = curlun->cdrom ? TYPE_CDROM : TYPE_DISK; 1212 buf[0] = curlun->cdrom ? TYPE_ROM : TYPE_DISK;
1185 buf[1] = curlun->removable ? 0x80 : 0; 1213 buf[1] = curlun->removable ? 0x80 : 0;
1186 buf[2] = 2; /* ANSI SCSI level 2 */ 1214 buf[2] = 2; /* ANSI SCSI level 2 */
1187 buf[3] = 2; /* SCSI-2 INQUIRY data format */ 1215 buf[3] = 2; /* SCSI-2 INQUIRY data format */
@@ -1193,7 +1221,6 @@ static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh)
1193 return 36; 1221 return 36;
1194} 1222}
1195 1223
1196
1197static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh) 1224static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1198{ 1225{
1199 struct fsg_lun *curlun = common->curlun; 1226 struct fsg_lun *curlun = common->curlun;
@@ -1247,13 +1274,12 @@ static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1247 return 18; 1274 return 18;
1248} 1275}
1249 1276
1250
1251static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh) 1277static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh)
1252{ 1278{
1253 struct fsg_lun *curlun = common->curlun; 1279 struct fsg_lun *curlun = common->curlun;
1254 u32 lba = get_unaligned_be32(&common->cmnd[2]); 1280 u32 lba = get_unaligned_be32(&common->cmnd[2]);
1255 int pmi = common->cmnd[8]; 1281 int pmi = common->cmnd[8];
1256 u8 *buf = (u8 *) bh->buf; 1282 u8 *buf = (u8 *)bh->buf;
1257 1283
1258 /* Check the PMI and LBA fields */ 1284 /* Check the PMI and LBA fields */
1259 if (pmi > 1 || (pmi == 0 && lba != 0)) { 1285 if (pmi > 1 || (pmi == 0 && lba != 0)) {
@@ -1267,13 +1293,12 @@ static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh)
1267 return 8; 1293 return 8;
1268} 1294}
1269 1295
1270
1271static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh) 1296static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh)
1272{ 1297{
1273 struct fsg_lun *curlun = common->curlun; 1298 struct fsg_lun *curlun = common->curlun;
1274 int msf = common->cmnd[1] & 0x02; 1299 int msf = common->cmnd[1] & 0x02;
1275 u32 lba = get_unaligned_be32(&common->cmnd[2]); 1300 u32 lba = get_unaligned_be32(&common->cmnd[2]);
1276 u8 *buf = (u8 *) bh->buf; 1301 u8 *buf = (u8 *)bh->buf;
1277 1302
1278 if (common->cmnd[1] & ~0x02) { /* Mask away MSF */ 1303 if (common->cmnd[1] & ~0x02) { /* Mask away MSF */
1279 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1304 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
@@ -1290,13 +1315,12 @@ static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh)
1290 return 8; 1315 return 8;
1291} 1316}
1292 1317
1293
1294static int do_read_toc(struct fsg_common *common, struct fsg_buffhd *bh) 1318static int do_read_toc(struct fsg_common *common, struct fsg_buffhd *bh)
1295{ 1319{
1296 struct fsg_lun *curlun = common->curlun; 1320 struct fsg_lun *curlun = common->curlun;
1297 int msf = common->cmnd[1] & 0x02; 1321 int msf = common->cmnd[1] & 0x02;
1298 int start_track = common->cmnd[6]; 1322 int start_track = common->cmnd[6];
1299 u8 *buf = (u8 *) bh->buf; 1323 u8 *buf = (u8 *)bh->buf;
1300 1324
1301 if ((common->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */ 1325 if ((common->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
1302 start_track > 1) { 1326 start_track > 1) {
@@ -1318,7 +1342,6 @@ static int do_read_toc(struct fsg_common *common, struct fsg_buffhd *bh)
1318 return 20; 1342 return 20;
1319} 1343}
1320 1344
1321
1322static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh) 1345static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1323{ 1346{
1324 struct fsg_lun *curlun = common->curlun; 1347 struct fsg_lun *curlun = common->curlun;
@@ -1343,16 +1366,18 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1343 changeable_values = (pc == 1); 1366 changeable_values = (pc == 1);
1344 all_pages = (page_code == 0x3f); 1367 all_pages = (page_code == 0x3f);
1345 1368
1346 /* Write the mode parameter header. Fixed values are: default 1369 /*
1370 * Write the mode parameter header. Fixed values are: default
1347 * medium type, no cache control (DPOFUA), and no block descriptors. 1371 * medium type, no cache control (DPOFUA), and no block descriptors.
1348 * The only variable value is the WriteProtect bit. We will fill in 1372 * The only variable value is the WriteProtect bit. We will fill in
1349 * the mode data length later. */ 1373 * the mode data length later.
1374 */
1350 memset(buf, 0, 8); 1375 memset(buf, 0, 8);
1351 if (mscmnd == SC_MODE_SENSE_6) { 1376 if (mscmnd == MODE_SENSE) {
1352 buf[2] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */ 1377 buf[2] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */
1353 buf += 4; 1378 buf += 4;
1354 limit = 255; 1379 limit = 255;
1355 } else { /* SC_MODE_SENSE_10 */ 1380 } else { /* MODE_SENSE_10 */
1356 buf[3] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */ 1381 buf[3] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */
1357 buf += 8; 1382 buf += 8;
1358 limit = 65535; /* Should really be FSG_BUFLEN */ 1383 limit = 65535; /* Should really be FSG_BUFLEN */
@@ -1360,8 +1385,10 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1360 1385
1361 /* No block descriptors */ 1386 /* No block descriptors */
1362 1387
1363 /* The mode pages, in numerical order. The only page we support 1388 /*
1364 * is the Caching page. */ 1389 * The mode pages, in numerical order. The only page we support
1390 * is the Caching page.
1391 */
1365 if (page_code == 0x08 || all_pages) { 1392 if (page_code == 0x08 || all_pages) {
1366 valid_page = 1; 1393 valid_page = 1;
1367 buf[0] = 0x08; /* Page code */ 1394 buf[0] = 0x08; /* Page code */
@@ -1383,8 +1410,10 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1383 buf += 12; 1410 buf += 12;
1384 } 1411 }
1385 1412
1386 /* Check that a valid page was requested and the mode data length 1413 /*
1387 * isn't too long. */ 1414 * Check that a valid page was requested and the mode data length
1415 * isn't too long.
1416 */
1388 len = buf - buf0; 1417 len = buf - buf0;
1389 if (!valid_page || len > limit) { 1418 if (!valid_page || len > limit) {
1390 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1419 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
@@ -1392,14 +1421,13 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1392 } 1421 }
1393 1422
1394 /* Store the mode data length */ 1423 /* Store the mode data length */
1395 if (mscmnd == SC_MODE_SENSE_6) 1424 if (mscmnd == MODE_SENSE)
1396 buf0[0] = len - 1; 1425 buf0[0] = len - 1;
1397 else 1426 else
1398 put_unaligned_be16(len - 2, buf0); 1427 put_unaligned_be16(len - 2, buf0);
1399 return len; 1428 return len;
1400} 1429}
1401 1430
1402
1403static int do_start_stop(struct fsg_common *common) 1431static int do_start_stop(struct fsg_common *common)
1404{ 1432{
1405 struct fsg_lun *curlun = common->curlun; 1433 struct fsg_lun *curlun = common->curlun;
@@ -1419,8 +1447,10 @@ static int do_start_stop(struct fsg_common *common)
1419 loej = common->cmnd[4] & 0x02; 1447 loej = common->cmnd[4] & 0x02;
1420 start = common->cmnd[4] & 0x01; 1448 start = common->cmnd[4] & 0x01;
1421 1449
1422 /* Our emulation doesn't support mounting; the medium is 1450 /*
1423 * available for use as soon as it is loaded. */ 1451 * Our emulation doesn't support mounting; the medium is
1452 * available for use as soon as it is loaded.
1453 */
1424 if (start) { 1454 if (start) {
1425 if (!fsg_lun_is_open(curlun)) { 1455 if (!fsg_lun_is_open(curlun)) {
1426 curlun->sense_data = SS_MEDIUM_NOT_PRESENT; 1456 curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
@@ -1461,7 +1491,6 @@ static int do_start_stop(struct fsg_common *common)
1461 : 0; 1491 : 0;
1462} 1492}
1463 1493
1464
1465static int do_prevent_allow(struct fsg_common *common) 1494static int do_prevent_allow(struct fsg_common *common)
1466{ 1495{
1467 struct fsg_lun *curlun = common->curlun; 1496 struct fsg_lun *curlun = common->curlun;
@@ -1486,7 +1515,6 @@ static int do_prevent_allow(struct fsg_common *common)
1486 return 0; 1515 return 0;
1487} 1516}
1488 1517
1489
1490static int do_read_format_capacities(struct fsg_common *common, 1518static int do_read_format_capacities(struct fsg_common *common,
1491 struct fsg_buffhd *bh) 1519 struct fsg_buffhd *bh)
1492{ 1520{
@@ -1504,7 +1532,6 @@ static int do_read_format_capacities(struct fsg_common *common,
1504 return 12; 1532 return 12;
1505} 1533}
1506 1534
1507
1508static int do_mode_select(struct fsg_common *common, struct fsg_buffhd *bh) 1535static int do_mode_select(struct fsg_common *common, struct fsg_buffhd *bh)
1509{ 1536{
1510 struct fsg_lun *curlun = common->curlun; 1537 struct fsg_lun *curlun = common->curlun;
@@ -1563,37 +1590,6 @@ static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
1563 return rc; 1590 return rc;
1564} 1591}
1565 1592
1566static int pad_with_zeros(struct fsg_dev *fsg)
1567{
1568 struct fsg_buffhd *bh = fsg->common->next_buffhd_to_fill;
1569 u32 nkeep = bh->inreq->length;
1570 u32 nsend;
1571 int rc;
1572
1573 bh->state = BUF_STATE_EMPTY; /* For the first iteration */
1574 fsg->common->usb_amount_left = nkeep + fsg->common->residue;
1575 while (fsg->common->usb_amount_left > 0) {
1576
1577 /* Wait for the next buffer to be free */
1578 while (bh->state != BUF_STATE_EMPTY) {
1579 rc = sleep_thread(fsg->common);
1580 if (rc)
1581 return rc;
1582 }
1583
1584 nsend = min(fsg->common->usb_amount_left, FSG_BUFLEN);
1585 memset(bh->buf + nkeep, 0, nsend - nkeep);
1586 bh->inreq->length = nsend;
1587 bh->inreq->zero = 0;
1588 start_transfer(fsg, fsg->bulk_in, bh->inreq,
1589 &bh->inreq_busy, &bh->state);
1590 bh = fsg->common->next_buffhd_to_fill = bh->next;
1591 fsg->common->usb_amount_left -= nsend;
1592 nkeep = 0;
1593 }
1594 return 0;
1595}
1596
1597static int throw_away_data(struct fsg_common *common) 1593static int throw_away_data(struct fsg_common *common)
1598{ 1594{
1599 struct fsg_buffhd *bh; 1595 struct fsg_buffhd *bh;
@@ -1612,7 +1608,7 @@ static int throw_away_data(struct fsg_common *common)
1612 1608
1613 /* A short packet or an error ends everything */ 1609 /* A short packet or an error ends everything */
1614 if (bh->outreq->actual != bh->outreq->length || 1610 if (bh->outreq->actual != bh->outreq->length ||
1615 bh->outreq->status != 0) { 1611 bh->outreq->status != 0) {
1616 raise_exception(common, 1612 raise_exception(common,
1617 FSG_STATE_ABORT_BULK_OUT); 1613 FSG_STATE_ABORT_BULK_OUT);
1618 return -EINTR; 1614 return -EINTR;
@@ -1626,15 +1622,15 @@ static int throw_away_data(struct fsg_common *common)
1626 && common->usb_amount_left > 0) { 1622 && common->usb_amount_left > 0) {
1627 amount = min(common->usb_amount_left, FSG_BUFLEN); 1623 amount = min(common->usb_amount_left, FSG_BUFLEN);
1628 1624
1629 /* amount is always divisible by 512, hence by 1625 /*
1630 * the bulk-out maxpacket size */ 1626 * amount is always divisible by 512, hence by
1627 * the bulk-out maxpacket size.
1628 */
1631 bh->outreq->length = amount; 1629 bh->outreq->length = amount;
1632 bh->bulk_out_intended_length = amount; 1630 bh->bulk_out_intended_length = amount;
1633 bh->outreq->short_not_ok = 1; 1631 bh->outreq->short_not_ok = 1;
1634 START_TRANSFER_OR(common, bulk_out, bh->outreq, 1632 if (!start_out_transfer(common, bh))
1635 &bh->outreq_busy, &bh->state) 1633 /* Dunno what to do if common->fsg is NULL */
1636 /* Don't know what to do if
1637 * common->fsg is NULL */
1638 return -EIO; 1634 return -EIO;
1639 common->next_buffhd_to_fill = bh->next; 1635 common->next_buffhd_to_fill = bh->next;
1640 common->usb_amount_left -= amount; 1636 common->usb_amount_left -= amount;
@@ -1649,7 +1645,6 @@ static int throw_away_data(struct fsg_common *common)
1649 return 0; 1645 return 0;
1650} 1646}
1651 1647
1652
1653static int finish_reply(struct fsg_common *common) 1648static int finish_reply(struct fsg_common *common)
1654{ 1649{
1655 struct fsg_buffhd *bh = common->next_buffhd_to_fill; 1650 struct fsg_buffhd *bh = common->next_buffhd_to_fill;
@@ -1659,10 +1654,12 @@ static int finish_reply(struct fsg_common *common)
1659 case DATA_DIR_NONE: 1654 case DATA_DIR_NONE:
1660 break; /* Nothing to send */ 1655 break; /* Nothing to send */
1661 1656
1662 /* If we don't know whether the host wants to read or write, 1657 /*
1658 * If we don't know whether the host wants to read or write,
1663 * this must be CB or CBI with an unknown command. We mustn't 1659 * this must be CB or CBI with an unknown command. We mustn't
1664 * try to send or receive any data. So stall both bulk pipes 1660 * try to send or receive any data. So stall both bulk pipes
1665 * if we can and wait for a reset. */ 1661 * if we can and wait for a reset.
1662 */
1666 case DATA_DIR_UNKNOWN: 1663 case DATA_DIR_UNKNOWN:
1667 if (!common->can_stall) { 1664 if (!common->can_stall) {
1668 /* Nothing */ 1665 /* Nothing */
@@ -1680,37 +1677,38 @@ static int finish_reply(struct fsg_common *common)
1680 if (common->data_size == 0) { 1677 if (common->data_size == 0) {
1681 /* Nothing to send */ 1678 /* Nothing to send */
1682 1679
1680 /* Don't know what to do if common->fsg is NULL */
1681 } else if (!fsg_is_set(common)) {
1682 rc = -EIO;
1683
1683 /* If there's no residue, simply send the last buffer */ 1684 /* If there's no residue, simply send the last buffer */
1684 } else if (common->residue == 0) { 1685 } else if (common->residue == 0) {
1685 bh->inreq->zero = 0; 1686 bh->inreq->zero = 0;
1686 START_TRANSFER_OR(common, bulk_in, bh->inreq, 1687 if (!start_in_transfer(common, bh))
1687 &bh->inreq_busy, &bh->state)
1688 return -EIO; 1688 return -EIO;
1689 common->next_buffhd_to_fill = bh->next; 1689 common->next_buffhd_to_fill = bh->next;
1690 1690
1691 /* For Bulk-only, if we're allowed to stall then send the 1691 /*
1692 * short packet and halt the bulk-in endpoint. If we can't 1692 * For Bulk-only, mark the end of the data with a short
1693 * stall, pad out the remaining data with 0's. */ 1693 * packet. If we are allowed to stall, halt the bulk-in
1694 } else if (common->can_stall) { 1694 * endpoint. (Note: This violates the Bulk-Only Transport
1695 * specification, which requires us to pad the data if we
1696 * don't halt the endpoint. Presumably nobody will mind.)
1697 */
1698 } else {
1695 bh->inreq->zero = 1; 1699 bh->inreq->zero = 1;
1696 START_TRANSFER_OR(common, bulk_in, bh->inreq, 1700 if (!start_in_transfer(common, bh))
1697 &bh->inreq_busy, &bh->state)
1698 /* Don't know what to do if
1699 * common->fsg is NULL */
1700 rc = -EIO; 1701 rc = -EIO;
1701 common->next_buffhd_to_fill = bh->next; 1702 common->next_buffhd_to_fill = bh->next;
1702 if (common->fsg) 1703 if (common->can_stall)
1703 rc = halt_bulk_in_endpoint(common->fsg); 1704 rc = halt_bulk_in_endpoint(common->fsg);
1704 } else if (fsg_is_set(common)) {
1705 rc = pad_with_zeros(common->fsg);
1706 } else {
1707 /* Don't know what to do if common->fsg is NULL */
1708 rc = -EIO;
1709 } 1705 }
1710 break; 1706 break;
1711 1707
1712 /* We have processed all we want from the data the host has sent. 1708 /*
1713 * There may still be outstanding bulk-out requests. */ 1709 * We have processed all we want from the data the host has sent.
1710 * There may still be outstanding bulk-out requests.
1711 */
1714 case DATA_DIR_FROM_HOST: 1712 case DATA_DIR_FROM_HOST:
1715 if (common->residue == 0) { 1713 if (common->residue == 0) {
1716 /* Nothing to receive */ 1714 /* Nothing to receive */
@@ -1720,12 +1718,14 @@ static int finish_reply(struct fsg_common *common)
1720 raise_exception(common, FSG_STATE_ABORT_BULK_OUT); 1718 raise_exception(common, FSG_STATE_ABORT_BULK_OUT);
1721 rc = -EINTR; 1719 rc = -EINTR;
1722 1720
1723 /* We haven't processed all the incoming data. Even though 1721 /*
1722 * We haven't processed all the incoming data. Even though
1724 * we may be allowed to stall, doing so would cause a race. 1723 * we may be allowed to stall, doing so would cause a race.
1725 * The controller may already have ACK'ed all the remaining 1724 * The controller may already have ACK'ed all the remaining
1726 * bulk-out packets, in which case the host wouldn't see a 1725 * bulk-out packets, in which case the host wouldn't see a
1727 * STALL. Not realizing the endpoint was halted, it wouldn't 1726 * STALL. Not realizing the endpoint was halted, it wouldn't
1728 * clear the halt -- leading to problems later on. */ 1727 * clear the halt -- leading to problems later on.
1728 */
1729#if 0 1729#if 0
1730 } else if (common->can_stall) { 1730 } else if (common->can_stall) {
1731 if (fsg_is_set(common)) 1731 if (fsg_is_set(common))
@@ -1735,8 +1735,10 @@ static int finish_reply(struct fsg_common *common)
1735 rc = -EINTR; 1735 rc = -EINTR;
1736#endif 1736#endif
1737 1737
1738 /* We can't stall. Read in the excess data and throw it 1738 /*
1739 * all away. */ 1739 * We can't stall. Read in the excess data and throw it
1740 * all away.
1741 */
1740 } else { 1742 } else {
1741 rc = throw_away_data(common); 1743 rc = throw_away_data(common);
1742 } 1744 }
@@ -1745,7 +1747,6 @@ static int finish_reply(struct fsg_common *common)
1745 return rc; 1747 return rc;
1746} 1748}
1747 1749
1748
1749static int send_status(struct fsg_common *common) 1750static int send_status(struct fsg_common *common)
1750{ 1751{
1751 struct fsg_lun *curlun = common->curlun; 1752 struct fsg_lun *curlun = common->curlun;
@@ -1793,8 +1794,7 @@ static int send_status(struct fsg_common *common)
1793 1794
1794 bh->inreq->length = USB_BULK_CS_WRAP_LEN; 1795 bh->inreq->length = USB_BULK_CS_WRAP_LEN;
1795 bh->inreq->zero = 0; 1796 bh->inreq->zero = 0;
1796 START_TRANSFER_OR(common, bulk_in, bh->inreq, 1797 if (!start_in_transfer(common, bh))
1797 &bh->inreq_busy, &bh->state)
1798 /* Don't know what to do if common->fsg is NULL */ 1798 /* Don't know what to do if common->fsg is NULL */
1799 return -EIO; 1799 return -EIO;
1800 1800
@@ -1805,11 +1805,13 @@ static int send_status(struct fsg_common *common)
1805 1805
1806/*-------------------------------------------------------------------------*/ 1806/*-------------------------------------------------------------------------*/
1807 1807
1808/* Check whether the command is properly formed and whether its data size 1808/*
1809 * and direction agree with the values we already have. */ 1809 * Check whether the command is properly formed and whether its data size
1810 * and direction agree with the values we already have.
1811 */
1810static int check_command(struct fsg_common *common, int cmnd_size, 1812static int check_command(struct fsg_common *common, int cmnd_size,
1811 enum data_direction data_dir, unsigned int mask, 1813 enum data_direction data_dir, unsigned int mask,
1812 int needs_medium, const char *name) 1814 int needs_medium, const char *name)
1813{ 1815{
1814 int i; 1816 int i;
1815 int lun = common->cmnd[1] >> 5; 1817 int lun = common->cmnd[1] >> 5;
@@ -1820,19 +1822,23 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1820 hdlen[0] = 0; 1822 hdlen[0] = 0;
1821 if (common->data_dir != DATA_DIR_UNKNOWN) 1823 if (common->data_dir != DATA_DIR_UNKNOWN)
1822 sprintf(hdlen, ", H%c=%u", dirletter[(int) common->data_dir], 1824 sprintf(hdlen, ", H%c=%u", dirletter[(int) common->data_dir],
1823 common->data_size); 1825 common->data_size);
1824 VDBG(common, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n", 1826 VDBG(common, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
1825 name, cmnd_size, dirletter[(int) data_dir], 1827 name, cmnd_size, dirletter[(int) data_dir],
1826 common->data_size_from_cmnd, common->cmnd_size, hdlen); 1828 common->data_size_from_cmnd, common->cmnd_size, hdlen);
1827 1829
1828 /* We can't reply at all until we know the correct data direction 1830 /*
1829 * and size. */ 1831 * We can't reply at all until we know the correct data direction
1832 * and size.
1833 */
1830 if (common->data_size_from_cmnd == 0) 1834 if (common->data_size_from_cmnd == 0)
1831 data_dir = DATA_DIR_NONE; 1835 data_dir = DATA_DIR_NONE;
1832 if (common->data_size < common->data_size_from_cmnd) { 1836 if (common->data_size < common->data_size_from_cmnd) {
1833 /* Host data size < Device data size is a phase error. 1837 /*
1838 * Host data size < Device data size is a phase error.
1834 * Carry out the command, but only transfer as much as 1839 * Carry out the command, but only transfer as much as
1835 * we are allowed. */ 1840 * we are allowed.
1841 */
1836 common->data_size_from_cmnd = common->data_size; 1842 common->data_size_from_cmnd = common->data_size;
1837 common->phase_error = 1; 1843 common->phase_error = 1;
1838 } 1844 }
@@ -1840,8 +1846,7 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1840 common->usb_amount_left = common->data_size; 1846 common->usb_amount_left = common->data_size;
1841 1847
1842 /* Conflicting data directions is a phase error */ 1848 /* Conflicting data directions is a phase error */
1843 if (common->data_dir != data_dir 1849 if (common->data_dir != data_dir && common->data_size_from_cmnd > 0) {
1844 && common->data_size_from_cmnd > 0) {
1845 common->phase_error = 1; 1850 common->phase_error = 1;
1846 return -EINVAL; 1851 return -EINVAL;
1847 } 1852 }
@@ -1849,7 +1854,8 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1849 /* Verify the length of the command itself */ 1854 /* Verify the length of the command itself */
1850 if (cmnd_size != common->cmnd_size) { 1855 if (cmnd_size != common->cmnd_size) {
1851 1856
1852 /* Special case workaround: There are plenty of buggy SCSI 1857 /*
1858 * Special case workaround: There are plenty of buggy SCSI
1853 * implementations. Many have issues with cbw->Length 1859 * implementations. Many have issues with cbw->Length
1854 * field passing a wrong command size. For those cases we 1860 * field passing a wrong command size. For those cases we
1855 * always try to work around the problem by using the length 1861 * always try to work around the problem by using the length
@@ -1878,10 +1884,10 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1878 common->lun, lun); 1884 common->lun, lun);
1879 1885
1880 /* Check the LUN */ 1886 /* Check the LUN */
1881 if (common->lun >= 0 && common->lun < common->nluns) { 1887 if (common->lun < common->nluns) {
1882 curlun = &common->luns[common->lun]; 1888 curlun = &common->luns[common->lun];
1883 common->curlun = curlun; 1889 common->curlun = curlun;
1884 if (common->cmnd[0] != SC_REQUEST_SENSE) { 1890 if (common->cmnd[0] != REQUEST_SENSE) {
1885 curlun->sense_data = SS_NO_SENSE; 1891 curlun->sense_data = SS_NO_SENSE;
1886 curlun->sense_data_info = 0; 1892 curlun->sense_data_info = 0;
1887 curlun->info_valid = 0; 1893 curlun->info_valid = 0;
@@ -1891,20 +1897,24 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1891 curlun = NULL; 1897 curlun = NULL;
1892 common->bad_lun_okay = 0; 1898 common->bad_lun_okay = 0;
1893 1899
1894 /* INQUIRY and REQUEST SENSE commands are explicitly allowed 1900 /*
1895 * to use unsupported LUNs; all others may not. */ 1901 * INQUIRY and REQUEST SENSE commands are explicitly allowed
1896 if (common->cmnd[0] != SC_INQUIRY && 1902 * to use unsupported LUNs; all others may not.
1897 common->cmnd[0] != SC_REQUEST_SENSE) { 1903 */
1904 if (common->cmnd[0] != INQUIRY &&
1905 common->cmnd[0] != REQUEST_SENSE) {
1898 DBG(common, "unsupported LUN %d\n", common->lun); 1906 DBG(common, "unsupported LUN %d\n", common->lun);
1899 return -EINVAL; 1907 return -EINVAL;
1900 } 1908 }
1901 } 1909 }
1902 1910
1903 /* If a unit attention condition exists, only INQUIRY and 1911 /*
1904 * REQUEST SENSE commands are allowed; anything else must fail. */ 1912 * If a unit attention condition exists, only INQUIRY and
1913 * REQUEST SENSE commands are allowed; anything else must fail.
1914 */
1905 if (curlun && curlun->unit_attention_data != SS_NO_SENSE && 1915 if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
1906 common->cmnd[0] != SC_INQUIRY && 1916 common->cmnd[0] != INQUIRY &&
1907 common->cmnd[0] != SC_REQUEST_SENSE) { 1917 common->cmnd[0] != REQUEST_SENSE) {
1908 curlun->sense_data = curlun->unit_attention_data; 1918 curlun->sense_data = curlun->unit_attention_data;
1909 curlun->unit_attention_data = SS_NO_SENSE; 1919 curlun->unit_attention_data = SS_NO_SENSE;
1910 return -EINVAL; 1920 return -EINVAL;
@@ -1930,7 +1940,6 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1930 return 0; 1940 return 0;
1931} 1941}
1932 1942
1933
1934static int do_scsi_command(struct fsg_common *common) 1943static int do_scsi_command(struct fsg_common *common)
1935{ 1944{
1936 struct fsg_buffhd *bh; 1945 struct fsg_buffhd *bh;
@@ -1955,7 +1964,7 @@ static int do_scsi_command(struct fsg_common *common)
1955 down_read(&common->filesem); /* We're using the backing file */ 1964 down_read(&common->filesem); /* We're using the backing file */
1956 switch (common->cmnd[0]) { 1965 switch (common->cmnd[0]) {
1957 1966
1958 case SC_INQUIRY: 1967 case INQUIRY:
1959 common->data_size_from_cmnd = common->cmnd[4]; 1968 common->data_size_from_cmnd = common->cmnd[4];
1960 reply = check_command(common, 6, DATA_DIR_TO_HOST, 1969 reply = check_command(common, 6, DATA_DIR_TO_HOST,
1961 (1<<4), 0, 1970 (1<<4), 0,
@@ -1964,7 +1973,7 @@ static int do_scsi_command(struct fsg_common *common)
1964 reply = do_inquiry(common, bh); 1973 reply = do_inquiry(common, bh);
1965 break; 1974 break;
1966 1975
1967 case SC_MODE_SELECT_6: 1976 case MODE_SELECT:
1968 common->data_size_from_cmnd = common->cmnd[4]; 1977 common->data_size_from_cmnd = common->cmnd[4];
1969 reply = check_command(common, 6, DATA_DIR_FROM_HOST, 1978 reply = check_command(common, 6, DATA_DIR_FROM_HOST,
1970 (1<<1) | (1<<4), 0, 1979 (1<<1) | (1<<4), 0,
@@ -1973,7 +1982,7 @@ static int do_scsi_command(struct fsg_common *common)
1973 reply = do_mode_select(common, bh); 1982 reply = do_mode_select(common, bh);
1974 break; 1983 break;
1975 1984
1976 case SC_MODE_SELECT_10: 1985 case MODE_SELECT_10:
1977 common->data_size_from_cmnd = 1986 common->data_size_from_cmnd =
1978 get_unaligned_be16(&common->cmnd[7]); 1987 get_unaligned_be16(&common->cmnd[7]);
1979 reply = check_command(common, 10, DATA_DIR_FROM_HOST, 1988 reply = check_command(common, 10, DATA_DIR_FROM_HOST,
@@ -1983,7 +1992,7 @@ static int do_scsi_command(struct fsg_common *common)
1983 reply = do_mode_select(common, bh); 1992 reply = do_mode_select(common, bh);
1984 break; 1993 break;
1985 1994
1986 case SC_MODE_SENSE_6: 1995 case MODE_SENSE:
1987 common->data_size_from_cmnd = common->cmnd[4]; 1996 common->data_size_from_cmnd = common->cmnd[4];
1988 reply = check_command(common, 6, DATA_DIR_TO_HOST, 1997 reply = check_command(common, 6, DATA_DIR_TO_HOST,
1989 (1<<1) | (1<<2) | (1<<4), 0, 1998 (1<<1) | (1<<2) | (1<<4), 0,
@@ -1992,7 +2001,7 @@ static int do_scsi_command(struct fsg_common *common)
1992 reply = do_mode_sense(common, bh); 2001 reply = do_mode_sense(common, bh);
1993 break; 2002 break;
1994 2003
1995 case SC_MODE_SENSE_10: 2004 case MODE_SENSE_10:
1996 common->data_size_from_cmnd = 2005 common->data_size_from_cmnd =
1997 get_unaligned_be16(&common->cmnd[7]); 2006 get_unaligned_be16(&common->cmnd[7]);
1998 reply = check_command(common, 10, DATA_DIR_TO_HOST, 2007 reply = check_command(common, 10, DATA_DIR_TO_HOST,
@@ -2002,7 +2011,7 @@ static int do_scsi_command(struct fsg_common *common)
2002 reply = do_mode_sense(common, bh); 2011 reply = do_mode_sense(common, bh);
2003 break; 2012 break;
2004 2013
2005 case SC_PREVENT_ALLOW_MEDIUM_REMOVAL: 2014 case ALLOW_MEDIUM_REMOVAL:
2006 common->data_size_from_cmnd = 0; 2015 common->data_size_from_cmnd = 0;
2007 reply = check_command(common, 6, DATA_DIR_NONE, 2016 reply = check_command(common, 6, DATA_DIR_NONE,
2008 (1<<4), 0, 2017 (1<<4), 0,
@@ -2011,7 +2020,7 @@ static int do_scsi_command(struct fsg_common *common)
2011 reply = do_prevent_allow(common); 2020 reply = do_prevent_allow(common);
2012 break; 2021 break;
2013 2022
2014 case SC_READ_6: 2023 case READ_6:
2015 i = common->cmnd[4]; 2024 i = common->cmnd[4];
2016 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; 2025 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
2017 reply = check_command(common, 6, DATA_DIR_TO_HOST, 2026 reply = check_command(common, 6, DATA_DIR_TO_HOST,
@@ -2021,7 +2030,7 @@ static int do_scsi_command(struct fsg_common *common)
2021 reply = do_read(common); 2030 reply = do_read(common);
2022 break; 2031 break;
2023 2032
2024 case SC_READ_10: 2033 case READ_10:
2025 common->data_size_from_cmnd = 2034 common->data_size_from_cmnd =
2026 get_unaligned_be16(&common->cmnd[7]) << 9; 2035 get_unaligned_be16(&common->cmnd[7]) << 9;
2027 reply = check_command(common, 10, DATA_DIR_TO_HOST, 2036 reply = check_command(common, 10, DATA_DIR_TO_HOST,
@@ -2031,7 +2040,7 @@ static int do_scsi_command(struct fsg_common *common)
2031 reply = do_read(common); 2040 reply = do_read(common);
2032 break; 2041 break;
2033 2042
2034 case SC_READ_12: 2043 case READ_12:
2035 common->data_size_from_cmnd = 2044 common->data_size_from_cmnd =
2036 get_unaligned_be32(&common->cmnd[6]) << 9; 2045 get_unaligned_be32(&common->cmnd[6]) << 9;
2037 reply = check_command(common, 12, DATA_DIR_TO_HOST, 2046 reply = check_command(common, 12, DATA_DIR_TO_HOST,
@@ -2041,7 +2050,7 @@ static int do_scsi_command(struct fsg_common *common)
2041 reply = do_read(common); 2050 reply = do_read(common);
2042 break; 2051 break;
2043 2052
2044 case SC_READ_CAPACITY: 2053 case READ_CAPACITY:
2045 common->data_size_from_cmnd = 8; 2054 common->data_size_from_cmnd = 8;
2046 reply = check_command(common, 10, DATA_DIR_TO_HOST, 2055 reply = check_command(common, 10, DATA_DIR_TO_HOST,
2047 (0xf<<2) | (1<<8), 1, 2056 (0xf<<2) | (1<<8), 1,
@@ -2050,7 +2059,7 @@ static int do_scsi_command(struct fsg_common *common)
2050 reply = do_read_capacity(common, bh); 2059 reply = do_read_capacity(common, bh);
2051 break; 2060 break;
2052 2061
2053 case SC_READ_HEADER: 2062 case READ_HEADER:
2054 if (!common->curlun || !common->curlun->cdrom) 2063 if (!common->curlun || !common->curlun->cdrom)
2055 goto unknown_cmnd; 2064 goto unknown_cmnd;
2056 common->data_size_from_cmnd = 2065 common->data_size_from_cmnd =
@@ -2062,7 +2071,7 @@ static int do_scsi_command(struct fsg_common *common)
2062 reply = do_read_header(common, bh); 2071 reply = do_read_header(common, bh);
2063 break; 2072 break;
2064 2073
2065 case SC_READ_TOC: 2074 case READ_TOC:
2066 if (!common->curlun || !common->curlun->cdrom) 2075 if (!common->curlun || !common->curlun->cdrom)
2067 goto unknown_cmnd; 2076 goto unknown_cmnd;
2068 common->data_size_from_cmnd = 2077 common->data_size_from_cmnd =
@@ -2074,7 +2083,7 @@ static int do_scsi_command(struct fsg_common *common)
2074 reply = do_read_toc(common, bh); 2083 reply = do_read_toc(common, bh);
2075 break; 2084 break;
2076 2085
2077 case SC_READ_FORMAT_CAPACITIES: 2086 case READ_FORMAT_CAPACITIES:
2078 common->data_size_from_cmnd = 2087 common->data_size_from_cmnd =
2079 get_unaligned_be16(&common->cmnd[7]); 2088 get_unaligned_be16(&common->cmnd[7]);
2080 reply = check_command(common, 10, DATA_DIR_TO_HOST, 2089 reply = check_command(common, 10, DATA_DIR_TO_HOST,
@@ -2084,7 +2093,7 @@ static int do_scsi_command(struct fsg_common *common)
2084 reply = do_read_format_capacities(common, bh); 2093 reply = do_read_format_capacities(common, bh);
2085 break; 2094 break;
2086 2095
2087 case SC_REQUEST_SENSE: 2096 case REQUEST_SENSE:
2088 common->data_size_from_cmnd = common->cmnd[4]; 2097 common->data_size_from_cmnd = common->cmnd[4];
2089 reply = check_command(common, 6, DATA_DIR_TO_HOST, 2098 reply = check_command(common, 6, DATA_DIR_TO_HOST,
2090 (1<<4), 0, 2099 (1<<4), 0,
@@ -2093,7 +2102,7 @@ static int do_scsi_command(struct fsg_common *common)
2093 reply = do_request_sense(common, bh); 2102 reply = do_request_sense(common, bh);
2094 break; 2103 break;
2095 2104
2096 case SC_START_STOP_UNIT: 2105 case START_STOP:
2097 common->data_size_from_cmnd = 0; 2106 common->data_size_from_cmnd = 0;
2098 reply = check_command(common, 6, DATA_DIR_NONE, 2107 reply = check_command(common, 6, DATA_DIR_NONE,
2099 (1<<1) | (1<<4), 0, 2108 (1<<1) | (1<<4), 0,
@@ -2102,7 +2111,7 @@ static int do_scsi_command(struct fsg_common *common)
2102 reply = do_start_stop(common); 2111 reply = do_start_stop(common);
2103 break; 2112 break;
2104 2113
2105 case SC_SYNCHRONIZE_CACHE: 2114 case SYNCHRONIZE_CACHE:
2106 common->data_size_from_cmnd = 0; 2115 common->data_size_from_cmnd = 0;
2107 reply = check_command(common, 10, DATA_DIR_NONE, 2116 reply = check_command(common, 10, DATA_DIR_NONE,
2108 (0xf<<2) | (3<<7), 1, 2117 (0xf<<2) | (3<<7), 1,
@@ -2111,16 +2120,18 @@ static int do_scsi_command(struct fsg_common *common)
2111 reply = do_synchronize_cache(common); 2120 reply = do_synchronize_cache(common);
2112 break; 2121 break;
2113 2122
2114 case SC_TEST_UNIT_READY: 2123 case TEST_UNIT_READY:
2115 common->data_size_from_cmnd = 0; 2124 common->data_size_from_cmnd = 0;
2116 reply = check_command(common, 6, DATA_DIR_NONE, 2125 reply = check_command(common, 6, DATA_DIR_NONE,
2117 0, 1, 2126 0, 1,
2118 "TEST UNIT READY"); 2127 "TEST UNIT READY");
2119 break; 2128 break;
2120 2129
2121 /* Although optional, this command is used by MS-Windows. We 2130 /*
2122 * support a minimal version: BytChk must be 0. */ 2131 * Although optional, this command is used by MS-Windows. We
2123 case SC_VERIFY: 2132 * support a minimal version: BytChk must be 0.
2133 */
2134 case VERIFY:
2124 common->data_size_from_cmnd = 0; 2135 common->data_size_from_cmnd = 0;
2125 reply = check_command(common, 10, DATA_DIR_NONE, 2136 reply = check_command(common, 10, DATA_DIR_NONE,
2126 (1<<1) | (0xf<<2) | (3<<7), 1, 2137 (1<<1) | (0xf<<2) | (3<<7), 1,
@@ -2129,7 +2140,7 @@ static int do_scsi_command(struct fsg_common *common)
2129 reply = do_verify(common); 2140 reply = do_verify(common);
2130 break; 2141 break;
2131 2142
2132 case SC_WRITE_6: 2143 case WRITE_6:
2133 i = common->cmnd[4]; 2144 i = common->cmnd[4];
2134 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; 2145 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
2135 reply = check_command(common, 6, DATA_DIR_FROM_HOST, 2146 reply = check_command(common, 6, DATA_DIR_FROM_HOST,
@@ -2139,7 +2150,7 @@ static int do_scsi_command(struct fsg_common *common)
2139 reply = do_write(common); 2150 reply = do_write(common);
2140 break; 2151 break;
2141 2152
2142 case SC_WRITE_10: 2153 case WRITE_10:
2143 common->data_size_from_cmnd = 2154 common->data_size_from_cmnd =
2144 get_unaligned_be16(&common->cmnd[7]) << 9; 2155 get_unaligned_be16(&common->cmnd[7]) << 9;
2145 reply = check_command(common, 10, DATA_DIR_FROM_HOST, 2156 reply = check_command(common, 10, DATA_DIR_FROM_HOST,
@@ -2149,7 +2160,7 @@ static int do_scsi_command(struct fsg_common *common)
2149 reply = do_write(common); 2160 reply = do_write(common);
2150 break; 2161 break;
2151 2162
2152 case SC_WRITE_12: 2163 case WRITE_12:
2153 common->data_size_from_cmnd = 2164 common->data_size_from_cmnd =
2154 get_unaligned_be32(&common->cmnd[6]) << 9; 2165 get_unaligned_be32(&common->cmnd[6]) << 9;
2155 reply = check_command(common, 12, DATA_DIR_FROM_HOST, 2166 reply = check_command(common, 12, DATA_DIR_FROM_HOST,
@@ -2159,14 +2170,16 @@ static int do_scsi_command(struct fsg_common *common)
2159 reply = do_write(common); 2170 reply = do_write(common);
2160 break; 2171 break;
2161 2172
2162 /* Some mandatory commands that we recognize but don't implement. 2173 /*
2174 * Some mandatory commands that we recognize but don't implement.
2163 * They don't mean much in this setting. It's left as an exercise 2175 * They don't mean much in this setting. It's left as an exercise
2164 * for anyone interested to implement RESERVE and RELEASE in terms 2176 * for anyone interested to implement RESERVE and RELEASE in terms
2165 * of Posix locks. */ 2177 * of Posix locks.
2166 case SC_FORMAT_UNIT: 2178 */
2167 case SC_RELEASE: 2179 case FORMAT_UNIT:
2168 case SC_RESERVE: 2180 case RELEASE:
2169 case SC_SEND_DIAGNOSTIC: 2181 case RESERVE:
2182 case SEND_DIAGNOSTIC:
2170 /* Fall through */ 2183 /* Fall through */
2171 2184
2172 default: 2185 default:
@@ -2190,7 +2203,7 @@ unknown_cmnd:
2190 if (reply == -EINVAL) 2203 if (reply == -EINVAL)
2191 reply = 0; /* Error reply length */ 2204 reply = 0; /* Error reply length */
2192 if (reply >= 0 && common->data_dir == DATA_DIR_TO_HOST) { 2205 if (reply >= 0 && common->data_dir == DATA_DIR_TO_HOST) {
2193 reply = min((u32) reply, common->data_size_from_cmnd); 2206 reply = min((u32)reply, common->data_size_from_cmnd);
2194 bh->inreq->length = reply; 2207 bh->inreq->length = reply;
2195 bh->state = BUF_STATE_FULL; 2208 bh->state = BUF_STATE_FULL;
2196 common->residue -= reply; 2209 common->residue -= reply;
@@ -2220,7 +2233,8 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2220 req->actual, 2233 req->actual,
2221 le32_to_cpu(cbw->Signature)); 2234 le32_to_cpu(cbw->Signature));
2222 2235
2223 /* The Bulk-only spec says we MUST stall the IN endpoint 2236 /*
2237 * The Bulk-only spec says we MUST stall the IN endpoint
2224 * (6.6.1), so it's unavoidable. It also says we must 2238 * (6.6.1), so it's unavoidable. It also says we must
2225 * retain this state until the next reset, but there's 2239 * retain this state until the next reset, but there's
2226 * no way to tell the controller driver it should ignore 2240 * no way to tell the controller driver it should ignore
@@ -2228,7 +2242,8 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2228 * 2242 *
2229 * We aren't required to halt the OUT endpoint; instead 2243 * We aren't required to halt the OUT endpoint; instead
2230 * we can simply accept and discard any data received 2244 * we can simply accept and discard any data received
2231 * until the next reset. */ 2245 * until the next reset.
2246 */
2232 wedge_bulk_in_endpoint(fsg); 2247 wedge_bulk_in_endpoint(fsg);
2233 set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2248 set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2234 return -EINVAL; 2249 return -EINVAL;
@@ -2241,8 +2256,10 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2241 "cmdlen %u\n", 2256 "cmdlen %u\n",
2242 cbw->Lun, cbw->Flags, cbw->Length); 2257 cbw->Lun, cbw->Flags, cbw->Length);
2243 2258
2244 /* We can do anything we want here, so let's stall the 2259 /*
2245 * bulk pipes if we are allowed to. */ 2260 * We can do anything we want here, so let's stall the
2261 * bulk pipes if we are allowed to.
2262 */
2246 if (common->can_stall) { 2263 if (common->can_stall) {
2247 fsg_set_halt(fsg, fsg->bulk_out); 2264 fsg_set_halt(fsg, fsg->bulk_out);
2248 halt_bulk_in_endpoint(fsg); 2265 halt_bulk_in_endpoint(fsg);
@@ -2265,7 +2282,6 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2265 return 0; 2282 return 0;
2266} 2283}
2267 2284
2268
2269static int get_next_command(struct fsg_common *common) 2285static int get_next_command(struct fsg_common *common)
2270{ 2286{
2271 struct fsg_buffhd *bh; 2287 struct fsg_buffhd *bh;
@@ -2282,14 +2298,15 @@ static int get_next_command(struct fsg_common *common)
2282 /* Queue a request to read a Bulk-only CBW */ 2298 /* Queue a request to read a Bulk-only CBW */
2283 set_bulk_out_req_length(common, bh, USB_BULK_CB_WRAP_LEN); 2299 set_bulk_out_req_length(common, bh, USB_BULK_CB_WRAP_LEN);
2284 bh->outreq->short_not_ok = 1; 2300 bh->outreq->short_not_ok = 1;
2285 START_TRANSFER_OR(common, bulk_out, bh->outreq, 2301 if (!start_out_transfer(common, bh))
2286 &bh->outreq_busy, &bh->state)
2287 /* Don't know what to do if common->fsg is NULL */ 2302 /* Don't know what to do if common->fsg is NULL */
2288 return -EIO; 2303 return -EIO;
2289 2304
2290 /* We will drain the buffer in software, which means we 2305 /*
2306 * We will drain the buffer in software, which means we
2291 * can reuse it for the next filling. No need to advance 2307 * can reuse it for the next filling. No need to advance
2292 * next_buffhd_to_fill. */ 2308 * next_buffhd_to_fill.
2309 */
2293 2310
2294 /* Wait for the CBW to arrive */ 2311 /* Wait for the CBW to arrive */
2295 while (bh->state != BUF_STATE_FULL) { 2312 while (bh->state != BUF_STATE_FULL) {
@@ -2420,13 +2437,12 @@ reset:
2420 2437
2421/****************************** ALT CONFIGS ******************************/ 2438/****************************** ALT CONFIGS ******************************/
2422 2439
2423
2424static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) 2440static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
2425{ 2441{
2426 struct fsg_dev *fsg = fsg_from_func(f); 2442 struct fsg_dev *fsg = fsg_from_func(f);
2427 fsg->common->new_fsg = fsg; 2443 fsg->common->new_fsg = fsg;
2428 raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); 2444 raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
2429 return 0; 2445 return USB_GADGET_DELAYED_STATUS;
2430} 2446}
2431 2447
2432static void fsg_disable(struct usb_function *f) 2448static void fsg_disable(struct usb_function *f)
@@ -2448,8 +2464,10 @@ static void handle_exception(struct fsg_common *common)
2448 struct fsg_lun *curlun; 2464 struct fsg_lun *curlun;
2449 unsigned int exception_req_tag; 2465 unsigned int exception_req_tag;
2450 2466
2451 /* Clear the existing signals. Anything but SIGUSR1 is converted 2467 /*
2452 * into a high-priority EXIT exception. */ 2468 * Clear the existing signals. Anything but SIGUSR1 is converted
2469 * into a high-priority EXIT exception.
2470 */
2453 for (;;) { 2471 for (;;) {
2454 int sig = 2472 int sig =
2455 dequeue_signal_lock(current, &current->blocked, &info); 2473 dequeue_signal_lock(current, &current->blocked, &info);
@@ -2493,8 +2511,10 @@ static void handle_exception(struct fsg_common *common)
2493 usb_ep_fifo_flush(common->fsg->bulk_out); 2511 usb_ep_fifo_flush(common->fsg->bulk_out);
2494 } 2512 }
2495 2513
2496 /* Reset the I/O buffer states and pointers, the SCSI 2514 /*
2497 * state, and the exception. Then invoke the handler. */ 2515 * Reset the I/O buffer states and pointers, the SCSI
2516 * state, and the exception. Then invoke the handler.
2517 */
2498 spin_lock_irq(&common->lock); 2518 spin_lock_irq(&common->lock);
2499 2519
2500 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 2520 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
@@ -2532,9 +2552,11 @@ static void handle_exception(struct fsg_common *common)
2532 break; 2552 break;
2533 2553
2534 case FSG_STATE_RESET: 2554 case FSG_STATE_RESET:
2535 /* In case we were forced against our will to halt a 2555 /*
2556 * In case we were forced against our will to halt a
2536 * bulk endpoint, clear the halt now. (The SuperH UDC 2557 * bulk endpoint, clear the halt now. (The SuperH UDC
2537 * requires this.) */ 2558 * requires this.)
2559 */
2538 if (!fsg_is_set(common)) 2560 if (!fsg_is_set(common))
2539 break; 2561 break;
2540 if (test_and_clear_bit(IGNORE_BULK_OUT, 2562 if (test_and_clear_bit(IGNORE_BULK_OUT,
@@ -2544,9 +2566,11 @@ static void handle_exception(struct fsg_common *common)
2544 if (common->ep0_req_tag == exception_req_tag) 2566 if (common->ep0_req_tag == exception_req_tag)
2545 ep0_queue(common); /* Complete the status stage */ 2567 ep0_queue(common); /* Complete the status stage */
2546 2568
2547 /* Technically this should go here, but it would only be 2569 /*
2570 * Technically this should go here, but it would only be
2548 * a waste of time. Ditto for the INTERFACE_CHANGE and 2571 * a waste of time. Ditto for the INTERFACE_CHANGE and
2549 * CONFIG_CHANGE cases. */ 2572 * CONFIG_CHANGE cases.
2573 */
2550 /* for (i = 0; i < common->nluns; ++i) */ 2574 /* for (i = 0; i < common->nluns; ++i) */
2551 /* common->luns[i].unit_attention_data = */ 2575 /* common->luns[i].unit_attention_data = */
2552 /* SS_RESET_OCCURRED; */ 2576 /* SS_RESET_OCCURRED; */
@@ -2554,6 +2578,8 @@ static void handle_exception(struct fsg_common *common)
2554 2578
2555 case FSG_STATE_CONFIG_CHANGE: 2579 case FSG_STATE_CONFIG_CHANGE:
2556 do_set_interface(common, common->new_fsg); 2580 do_set_interface(common, common->new_fsg);
2581 if (common->new_fsg)
2582 usb_composite_setup_continue(common->cdev);
2557 break; 2583 break;
2558 2584
2559 case FSG_STATE_EXIT: 2585 case FSG_STATE_EXIT:
@@ -2581,8 +2607,10 @@ static int fsg_main_thread(void *common_)
2581{ 2607{
2582 struct fsg_common *common = common_; 2608 struct fsg_common *common = common_;
2583 2609
2584 /* Allow the thread to be killed by a signal, but set the signal mask 2610 /*
2585 * to block everything but INT, TERM, KILL, and USR1. */ 2611 * Allow the thread to be killed by a signal, but set the signal mask
2612 * to block everything but INT, TERM, KILL, and USR1.
2613 */
2586 allow_signal(SIGINT); 2614 allow_signal(SIGINT);
2587 allow_signal(SIGTERM); 2615 allow_signal(SIGTERM);
2588 allow_signal(SIGKILL); 2616 allow_signal(SIGKILL);
@@ -2591,9 +2619,11 @@ static int fsg_main_thread(void *common_)
2591 /* Allow the thread to be frozen */ 2619 /* Allow the thread to be frozen */
2592 set_freezable(); 2620 set_freezable();
2593 2621
2594 /* Arrange for userspace references to be interpreted as kernel 2622 /*
2623 * Arrange for userspace references to be interpreted as kernel
2595 * pointers. That way we can pass a kernel pointer to a routine 2624 * pointers. That way we can pass a kernel pointer to a routine
2596 * that expects a __user pointer and it will work okay. */ 2625 * that expects a __user pointer and it will work okay.
2626 */
2597 set_fs(get_ds()); 2627 set_fs(get_ds());
2598 2628
2599 /* The main loop */ 2629 /* The main loop */
@@ -2653,7 +2683,7 @@ static int fsg_main_thread(void *common_)
2653 up_write(&common->filesem); 2683 up_write(&common->filesem);
2654 } 2684 }
2655 2685
2656 /* Let the unbind and cleanup routines know the thread has exited */ 2686 /* Let fsg_unbind() know the thread has exited */
2657 complete_and_exit(&common->thread_notifier, 0); 2687 complete_and_exit(&common->thread_notifier, 0);
2658} 2688}
2659 2689
@@ -2662,6 +2692,7 @@ static int fsg_main_thread(void *common_)
2662 2692
2663/* Write permission is checked per LUN in store_*() functions. */ 2693/* Write permission is checked per LUN in store_*() functions. */
2664static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro); 2694static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
2695static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua);
2665static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file); 2696static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
2666 2697
2667 2698
@@ -2684,7 +2715,6 @@ static inline void fsg_common_put(struct fsg_common *common)
2684 kref_put(&common->ref, fsg_common_release); 2715 kref_put(&common->ref, fsg_common_release);
2685} 2716}
2686 2717
2687
2688static struct fsg_common *fsg_common_init(struct fsg_common *common, 2718static struct fsg_common *fsg_common_init(struct fsg_common *common,
2689 struct usb_composite_dev *cdev, 2719 struct usb_composite_dev *cdev,
2690 struct fsg_config *cfg) 2720 struct fsg_config *cfg)
@@ -2710,7 +2740,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2710 return ERR_PTR(-ENOMEM); 2740 return ERR_PTR(-ENOMEM);
2711 common->free_storage_on_release = 1; 2741 common->free_storage_on_release = 1;
2712 } else { 2742 } else {
2713 memset(common, 0, sizeof common); 2743 memset(common, 0, sizeof *common);
2714 common->free_storage_on_release = 0; 2744 common->free_storage_on_release = 0;
2715 } 2745 }
2716 2746
@@ -2720,6 +2750,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2720 common->gadget = gadget; 2750 common->gadget = gadget;
2721 common->ep0 = gadget->ep0; 2751 common->ep0 = gadget->ep0;
2722 common->ep0req = cdev->req; 2752 common->ep0req = cdev->req;
2753 common->cdev = cdev;
2723 2754
2724 /* Maybe allocate device-global string IDs, and patch descriptors */ 2755 /* Maybe allocate device-global string IDs, and patch descriptors */
2725 if (fsg_strings[FSG_STRING_INTERFACE].id == 0) { 2756 if (fsg_strings[FSG_STRING_INTERFACE].id == 0) {
@@ -2730,8 +2761,10 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2730 fsg_intf_desc.iInterface = rc; 2761 fsg_intf_desc.iInterface = rc;
2731 } 2762 }
2732 2763
2733 /* Create the LUNs, open their backing files, and register the 2764 /*
2734 * LUN devices in sysfs. */ 2765 * Create the LUNs, open their backing files, and register the
2766 * LUN devices in sysfs.
2767 */
2735 curlun = kzalloc(nluns * sizeof *curlun, GFP_KERNEL); 2768 curlun = kzalloc(nluns * sizeof *curlun, GFP_KERNEL);
2736 if (unlikely(!curlun)) { 2769 if (unlikely(!curlun)) {
2737 rc = -ENOMEM; 2770 rc = -ENOMEM;
@@ -2744,6 +2777,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2744 for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun, ++lcfg) { 2777 for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun, ++lcfg) {
2745 curlun->cdrom = !!lcfg->cdrom; 2778 curlun->cdrom = !!lcfg->cdrom;
2746 curlun->ro = lcfg->cdrom || lcfg->ro; 2779 curlun->ro = lcfg->cdrom || lcfg->ro;
2780 curlun->initially_ro = curlun->ro;
2747 curlun->removable = lcfg->removable; 2781 curlun->removable = lcfg->removable;
2748 curlun->dev.release = fsg_lun_release; 2782 curlun->dev.release = fsg_lun_release;
2749 curlun->dev.parent = &gadget->dev; 2783 curlun->dev.parent = &gadget->dev;
@@ -2759,6 +2793,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2759 if (rc) { 2793 if (rc) {
2760 INFO(common, "failed to register LUN%d: %d\n", i, rc); 2794 INFO(common, "failed to register LUN%d: %d\n", i, rc);
2761 common->nluns = i; 2795 common->nluns = i;
2796 put_device(&curlun->dev);
2762 goto error_release; 2797 goto error_release;
2763 } 2798 }
2764 2799
@@ -2768,6 +2803,9 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2768 rc = device_create_file(&curlun->dev, &dev_attr_file); 2803 rc = device_create_file(&curlun->dev, &dev_attr_file);
2769 if (rc) 2804 if (rc)
2770 goto error_luns; 2805 goto error_luns;
2806 rc = device_create_file(&curlun->dev, &dev_attr_nofua);
2807 if (rc)
2808 goto error_luns;
2771 2809
2772 if (lcfg->filename) { 2810 if (lcfg->filename) {
2773 rc = fsg_lun_open(curlun, lcfg->filename); 2811 rc = fsg_lun_open(curlun, lcfg->filename);
@@ -2781,7 +2819,6 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2781 } 2819 }
2782 common->nluns = nluns; 2820 common->nluns = nluns;
2783 2821
2784
2785 /* Data buffers cyclic list */ 2822 /* Data buffers cyclic list */
2786 bh = common->buffhds; 2823 bh = common->buffhds;
2787 i = FSG_NUM_BUFFERS; 2824 i = FSG_NUM_BUFFERS;
@@ -2798,7 +2835,6 @@ buffhds_first_it:
2798 } while (--i); 2835 } while (--i);
2799 bh->next = common->buffhds; 2836 bh->next = common->buffhds;
2800 2837
2801
2802 /* Prepare inquiryString */ 2838 /* Prepare inquiryString */
2803 if (cfg->release != 0xffff) { 2839 if (cfg->release != 0xffff) {
2804 i = cfg->release; 2840 i = cfg->release;
@@ -2812,41 +2848,35 @@ buffhds_first_it:
2812 i = 0x0399; 2848 i = 0x0399;
2813 } 2849 }
2814 } 2850 }
2815#define OR(x, y) ((x) ? (x) : (y))
2816 snprintf(common->inquiry_string, sizeof common->inquiry_string, 2851 snprintf(common->inquiry_string, sizeof common->inquiry_string,
2817 "%-8s%-16s%04x", 2852 "%-8s%-16s%04x", cfg->vendor_name ?: "Linux",
2818 OR(cfg->vendor_name, "Linux "),
2819 /* Assume product name dependent on the first LUN */ 2853 /* Assume product name dependent on the first LUN */
2820 OR(cfg->product_name, common->luns->cdrom 2854 cfg->product_name ?: (common->luns->cdrom
2821 ? "File-Stor Gadget" 2855 ? "File-Stor Gadget"
2822 : "File-CD Gadget "), 2856 : "File-CD Gadget"),
2823 i); 2857 i);
2824 2858
2825 2859 /*
2826 /* Some peripheral controllers are known not to be able to 2860 * Some peripheral controllers are known not to be able to
2827 * halt bulk endpoints correctly. If one of them is present, 2861 * halt bulk endpoints correctly. If one of them is present,
2828 * disable stalls. 2862 * disable stalls.
2829 */ 2863 */
2830 common->can_stall = cfg->can_stall && 2864 common->can_stall = cfg->can_stall &&
2831 !(gadget_is_at91(common->gadget)); 2865 !(gadget_is_at91(common->gadget));
2832 2866
2833
2834 spin_lock_init(&common->lock); 2867 spin_lock_init(&common->lock);
2835 kref_init(&common->ref); 2868 kref_init(&common->ref);
2836 2869
2837
2838 /* Tell the thread to start working */ 2870 /* Tell the thread to start working */
2839 common->thread_task = 2871 common->thread_task =
2840 kthread_create(fsg_main_thread, common, 2872 kthread_create(fsg_main_thread, common,
2841 OR(cfg->thread_name, "file-storage")); 2873 cfg->thread_name ?: "file-storage");
2842 if (IS_ERR(common->thread_task)) { 2874 if (IS_ERR(common->thread_task)) {
2843 rc = PTR_ERR(common->thread_task); 2875 rc = PTR_ERR(common->thread_task);
2844 goto error_release; 2876 goto error_release;
2845 } 2877 }
2846 init_completion(&common->thread_notifier); 2878 init_completion(&common->thread_notifier);
2847 init_waitqueue_head(&common->fsg_wait); 2879 init_waitqueue_head(&common->fsg_wait);
2848#undef OR
2849
2850 2880
2851 /* Information */ 2881 /* Information */
2852 INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); 2882 INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
@@ -2880,18 +2910,15 @@ buffhds_first_it:
2880 2910
2881 return common; 2911 return common;
2882 2912
2883
2884error_luns: 2913error_luns:
2885 common->nluns = i + 1; 2914 common->nluns = i + 1;
2886error_release: 2915error_release:
2887 common->state = FSG_STATE_TERMINATED; /* The thread is dead */ 2916 common->state = FSG_STATE_TERMINATED; /* The thread is dead */
2888 /* Call fsg_common_release() directly, ref might be not 2917 /* Call fsg_common_release() directly, ref might be not initialised. */
2889 * initialised */
2890 fsg_common_release(&common->ref); 2918 fsg_common_release(&common->ref);
2891 return ERR_PTR(rc); 2919 return ERR_PTR(rc);
2892} 2920}
2893 2921
2894
2895static void fsg_common_release(struct kref *ref) 2922static void fsg_common_release(struct kref *ref)
2896{ 2923{
2897 struct fsg_common *common = container_of(ref, struct fsg_common, ref); 2924 struct fsg_common *common = container_of(ref, struct fsg_common, ref);
@@ -2900,9 +2927,6 @@ static void fsg_common_release(struct kref *ref)
2900 if (common->state != FSG_STATE_TERMINATED) { 2927 if (common->state != FSG_STATE_TERMINATED) {
2901 raise_exception(common, FSG_STATE_EXIT); 2928 raise_exception(common, FSG_STATE_EXIT);
2902 wait_for_completion(&common->thread_notifier); 2929 wait_for_completion(&common->thread_notifier);
2903
2904 /* The cleanup routine waits for this completion also */
2905 complete(&common->thread_notifier);
2906 } 2930 }
2907 2931
2908 if (likely(common->luns)) { 2932 if (likely(common->luns)) {
@@ -2911,6 +2935,7 @@ static void fsg_common_release(struct kref *ref)
2911 2935
2912 /* In error recovery common->nluns may be zero. */ 2936 /* In error recovery common->nluns may be zero. */
2913 for (; i; --i, ++lun) { 2937 for (; i; --i, ++lun) {
2938 device_remove_file(&lun->dev, &dev_attr_nofua);
2914 device_remove_file(&lun->dev, &dev_attr_ro); 2939 device_remove_file(&lun->dev, &dev_attr_ro);
2915 device_remove_file(&lun->dev, &dev_attr_file); 2940 device_remove_file(&lun->dev, &dev_attr_file);
2916 fsg_lun_close(lun); 2941 fsg_lun_close(lun);
@@ -2935,7 +2960,6 @@ static void fsg_common_release(struct kref *ref)
2935 2960
2936/*-------------------------------------------------------------------------*/ 2961/*-------------------------------------------------------------------------*/
2937 2962
2938
2939static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) 2963static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
2940{ 2964{
2941 struct fsg_dev *fsg = fsg_from_func(f); 2965 struct fsg_dev *fsg = fsg_from_func(f);
@@ -2955,7 +2979,6 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
2955 kfree(fsg); 2979 kfree(fsg);
2956} 2980}
2957 2981
2958
2959static int fsg_bind(struct usb_configuration *c, struct usb_function *f) 2982static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
2960{ 2983{
2961 struct fsg_dev *fsg = fsg_from_func(f); 2984 struct fsg_dev *fsg = fsg_from_func(f);
@@ -3038,11 +3061,13 @@ static int fsg_bind_config(struct usb_composite_dev *cdev,
3038 fsg->function.disable = fsg_disable; 3061 fsg->function.disable = fsg_disable;
3039 3062
3040 fsg->common = common; 3063 fsg->common = common;
3041 /* Our caller holds a reference to common structure so we 3064 /*
3065 * Our caller holds a reference to common structure so we
3042 * don't have to be worry about it being freed until we return 3066 * don't have to be worry about it being freed until we return
3043 * from this function. So instead of incrementing counter now 3067 * from this function. So instead of incrementing counter now
3044 * and decrement in error recovery we increment it only when 3068 * and decrement in error recovery we increment it only when
3045 * call to usb_add_function() was successful. */ 3069 * call to usb_add_function() was successful.
3070 */
3046 3071
3047 rc = usb_add_function(c, &fsg->function); 3072 rc = usb_add_function(c, &fsg->function);
3048 if (unlikely(rc)) 3073 if (unlikely(rc))
@@ -3053,8 +3078,7 @@ static int fsg_bind_config(struct usb_composite_dev *cdev,
3053} 3078}
3054 3079
3055static inline int __deprecated __maybe_unused 3080static inline int __deprecated __maybe_unused
3056fsg_add(struct usb_composite_dev *cdev, 3081fsg_add(struct usb_composite_dev *cdev, struct usb_configuration *c,
3057 struct usb_configuration *c,
3058 struct fsg_common *common) 3082 struct fsg_common *common)
3059{ 3083{
3060 return fsg_bind_config(cdev, c, common); 3084 return fsg_bind_config(cdev, c, common);
@@ -3063,19 +3087,19 @@ fsg_add(struct usb_composite_dev *cdev,
3063 3087
3064/************************* Module parameters *************************/ 3088/************************* Module parameters *************************/
3065 3089
3066
3067struct fsg_module_parameters { 3090struct fsg_module_parameters {
3068 char *file[FSG_MAX_LUNS]; 3091 char *file[FSG_MAX_LUNS];
3069 int ro[FSG_MAX_LUNS]; 3092 int ro[FSG_MAX_LUNS];
3070 int removable[FSG_MAX_LUNS]; 3093 int removable[FSG_MAX_LUNS];
3071 int cdrom[FSG_MAX_LUNS]; 3094 int cdrom[FSG_MAX_LUNS];
3095 int nofua[FSG_MAX_LUNS];
3072 3096
3073 unsigned int file_count, ro_count, removable_count, cdrom_count; 3097 unsigned int file_count, ro_count, removable_count, cdrom_count;
3098 unsigned int nofua_count;
3074 unsigned int luns; /* nluns */ 3099 unsigned int luns; /* nluns */
3075 int stall; /* can_stall */ 3100 int stall; /* can_stall */
3076}; 3101};
3077 3102
3078
3079#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \ 3103#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \
3080 module_param_array_named(prefix ## name, params.name, type, \ 3104 module_param_array_named(prefix ## name, params.name, type, \
3081 &prefix ## params.name ## _count, \ 3105 &prefix ## params.name ## _count, \
@@ -3096,12 +3120,13 @@ struct fsg_module_parameters {
3096 "true to simulate removable media"); \ 3120 "true to simulate removable media"); \
3097 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \ 3121 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
3098 "true to simulate CD-ROM instead of disk"); \ 3122 "true to simulate CD-ROM instead of disk"); \
3123 _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
3124 "true to ignore SCSI WRITE(10,12) FUA bit"); \
3099 _FSG_MODULE_PARAM(prefix, params, luns, uint, \ 3125 _FSG_MODULE_PARAM(prefix, params, luns, uint, \
3100 "number of LUNs"); \ 3126 "number of LUNs"); \
3101 _FSG_MODULE_PARAM(prefix, params, stall, bool, \ 3127 _FSG_MODULE_PARAM(prefix, params, stall, bool, \
3102 "false to prevent bulk stalls") 3128 "false to prevent bulk stalls")
3103 3129
3104
3105static void 3130static void
3106fsg_config_from_params(struct fsg_config *cfg, 3131fsg_config_from_params(struct fsg_config *cfg,
3107 const struct fsg_module_parameters *params) 3132 const struct fsg_module_parameters *params)
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c
new file mode 100644
index 000000000000..86902a60bcdb
--- /dev/null
+++ b/drivers/usb/gadget/f_ncm.c
@@ -0,0 +1,1407 @@
1/*
2 * f_ncm.c -- USB CDC Network (NCM) link function driver
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 * Contact: Yauheni Kaliuta <yauheni.kaliuta@nokia.com>
6 *
7 * The driver borrows from f_ecm.c which is:
8 *
9 * Copyright (C) 2003-2005,2008 David Brownell
10 * Copyright (C) 2008 Nokia Corporation
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 as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#include <linux/kernel.h>
28#include <linux/device.h>
29#include <linux/etherdevice.h>
30#include <linux/crc32.h>
31
32#include <linux/usb/cdc.h>
33
34#include "u_ether.h"
35
36/*
37 * This function is a "CDC Network Control Model" (CDC NCM) Ethernet link.
38 * NCM is intended to be used with high-speed network attachments.
39 *
40 * Note that NCM requires the use of "alternate settings" for its data
41 * interface. This means that the set_alt() method has real work to do,
42 * and also means that a get_alt() method is required.
43 */
44
45/* to trigger crc/non-crc ndp signature */
46
47#define NCM_NDP_HDR_CRC_MASK 0x01000000
48#define NCM_NDP_HDR_CRC 0x01000000
49#define NCM_NDP_HDR_NOCRC 0x00000000
50
51struct ncm_ep_descs {
52 struct usb_endpoint_descriptor *in;
53 struct usb_endpoint_descriptor *out;
54 struct usb_endpoint_descriptor *notify;
55};
56
57enum ncm_notify_state {
58 NCM_NOTIFY_NONE, /* don't notify */
59 NCM_NOTIFY_CONNECT, /* issue CONNECT next */
60 NCM_NOTIFY_SPEED, /* issue SPEED_CHANGE next */
61};
62
63struct f_ncm {
64 struct gether port;
65 u8 ctrl_id, data_id;
66
67 char ethaddr[14];
68
69 struct ncm_ep_descs fs;
70 struct ncm_ep_descs hs;
71
72 struct usb_ep *notify;
73 struct usb_endpoint_descriptor *notify_desc;
74 struct usb_request *notify_req;
75 u8 notify_state;
76 bool is_open;
77
78 struct ndp_parser_opts *parser_opts;
79 bool is_crc;
80
81 /*
82 * for notification, it is accessed from both
83 * callback and ethernet open/close
84 */
85 spinlock_t lock;
86};
87
88static inline struct f_ncm *func_to_ncm(struct usb_function *f)
89{
90 return container_of(f, struct f_ncm, port.func);
91}
92
93/* peak (theoretical) bulk transfer rate in bits-per-second */
94static inline unsigned ncm_bitrate(struct usb_gadget *g)
95{
96 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
97 return 13 * 512 * 8 * 1000 * 8;
98 else
99 return 19 * 64 * 1 * 1000 * 8;
100}
101
102/*-------------------------------------------------------------------------*/
103
104/*
105 * We cannot group frames so use just the minimal size which ok to put
106 * one max-size ethernet frame.
107 * If the host can group frames, allow it to do that, 16K is selected,
108 * because it's used by default by the current linux host driver
109 */
110#define NTB_DEFAULT_IN_SIZE USB_CDC_NCM_NTB_MIN_IN_SIZE
111#define NTB_OUT_SIZE 16384
112
113/*
114 * skbs of size less than that will not be aligned
115 * to NCM's dwNtbInMaxSize to save bus bandwidth
116 */
117
118#define MAX_TX_NONFIXED (512 * 3)
119
120#define FORMATS_SUPPORTED (USB_CDC_NCM_NTB16_SUPPORTED | \
121 USB_CDC_NCM_NTB32_SUPPORTED)
122
123static struct usb_cdc_ncm_ntb_parameters ntb_parameters = {
124 .wLength = sizeof ntb_parameters,
125 .bmNtbFormatsSupported = cpu_to_le16(FORMATS_SUPPORTED),
126 .dwNtbInMaxSize = cpu_to_le32(NTB_DEFAULT_IN_SIZE),
127 .wNdpInDivisor = cpu_to_le16(4),
128 .wNdpInPayloadRemainder = cpu_to_le16(0),
129 .wNdpInAlignment = cpu_to_le16(4),
130
131 .dwNtbOutMaxSize = cpu_to_le32(NTB_OUT_SIZE),
132 .wNdpOutDivisor = cpu_to_le16(4),
133 .wNdpOutPayloadRemainder = cpu_to_le16(0),
134 .wNdpOutAlignment = cpu_to_le16(4),
135};
136
137/*
138 * Use wMaxPacketSize big enough to fit CDC_NOTIFY_SPEED_CHANGE in one
139 * packet, to simplify cancellation; and a big transfer interval, to
140 * waste less bandwidth.
141 */
142
143#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
144#define NCM_STATUS_BYTECOUNT 16 /* 8 byte header + data */
145
146static struct usb_interface_assoc_descriptor ncm_iad_desc __initdata = {
147 .bLength = sizeof ncm_iad_desc,
148 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
149
150 /* .bFirstInterface = DYNAMIC, */
151 .bInterfaceCount = 2, /* control + data */
152 .bFunctionClass = USB_CLASS_COMM,
153 .bFunctionSubClass = USB_CDC_SUBCLASS_NCM,
154 .bFunctionProtocol = USB_CDC_PROTO_NONE,
155 /* .iFunction = DYNAMIC */
156};
157
158/* interface descriptor: */
159
160static struct usb_interface_descriptor ncm_control_intf __initdata = {
161 .bLength = sizeof ncm_control_intf,
162 .bDescriptorType = USB_DT_INTERFACE,
163
164 /* .bInterfaceNumber = DYNAMIC */
165 .bNumEndpoints = 1,
166 .bInterfaceClass = USB_CLASS_COMM,
167 .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM,
168 .bInterfaceProtocol = USB_CDC_PROTO_NONE,
169 /* .iInterface = DYNAMIC */
170};
171
172static struct usb_cdc_header_desc ncm_header_desc __initdata = {
173 .bLength = sizeof ncm_header_desc,
174 .bDescriptorType = USB_DT_CS_INTERFACE,
175 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
176
177 .bcdCDC = cpu_to_le16(0x0110),
178};
179
180static struct usb_cdc_union_desc ncm_union_desc __initdata = {
181 .bLength = sizeof(ncm_union_desc),
182 .bDescriptorType = USB_DT_CS_INTERFACE,
183 .bDescriptorSubType = USB_CDC_UNION_TYPE,
184 /* .bMasterInterface0 = DYNAMIC */
185 /* .bSlaveInterface0 = DYNAMIC */
186};
187
188static struct usb_cdc_ether_desc ecm_desc __initdata = {
189 .bLength = sizeof ecm_desc,
190 .bDescriptorType = USB_DT_CS_INTERFACE,
191 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
192
193 /* this descriptor actually adds value, surprise! */
194 /* .iMACAddress = DYNAMIC */
195 .bmEthernetStatistics = cpu_to_le32(0), /* no statistics */
196 .wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN),
197 .wNumberMCFilters = cpu_to_le16(0),
198 .bNumberPowerFilters = 0,
199};
200
201#define NCAPS (USB_CDC_NCM_NCAP_ETH_FILTER | USB_CDC_NCM_NCAP_CRC_MODE)
202
203static struct usb_cdc_ncm_desc ncm_desc __initdata = {
204 .bLength = sizeof ncm_desc,
205 .bDescriptorType = USB_DT_CS_INTERFACE,
206 .bDescriptorSubType = USB_CDC_NCM_TYPE,
207
208 .bcdNcmVersion = cpu_to_le16(0x0100),
209 /* can process SetEthernetPacketFilter */
210 .bmNetworkCapabilities = NCAPS,
211};
212
213/* the default data interface has no endpoints ... */
214
215static struct usb_interface_descriptor ncm_data_nop_intf __initdata = {
216 .bLength = sizeof ncm_data_nop_intf,
217 .bDescriptorType = USB_DT_INTERFACE,
218
219 .bInterfaceNumber = 1,
220 .bAlternateSetting = 0,
221 .bNumEndpoints = 0,
222 .bInterfaceClass = USB_CLASS_CDC_DATA,
223 .bInterfaceSubClass = 0,
224 .bInterfaceProtocol = USB_CDC_NCM_PROTO_NTB,
225 /* .iInterface = DYNAMIC */
226};
227
228/* ... but the "real" data interface has two bulk endpoints */
229
230static struct usb_interface_descriptor ncm_data_intf __initdata = {
231 .bLength = sizeof ncm_data_intf,
232 .bDescriptorType = USB_DT_INTERFACE,
233
234 .bInterfaceNumber = 1,
235 .bAlternateSetting = 1,
236 .bNumEndpoints = 2,
237 .bInterfaceClass = USB_CLASS_CDC_DATA,
238 .bInterfaceSubClass = 0,
239 .bInterfaceProtocol = USB_CDC_NCM_PROTO_NTB,
240 /* .iInterface = DYNAMIC */
241};
242
243/* full speed support: */
244
245static struct usb_endpoint_descriptor fs_ncm_notify_desc __initdata = {
246 .bLength = USB_DT_ENDPOINT_SIZE,
247 .bDescriptorType = USB_DT_ENDPOINT,
248
249 .bEndpointAddress = USB_DIR_IN,
250 .bmAttributes = USB_ENDPOINT_XFER_INT,
251 .wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT),
252 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
253};
254
255static struct usb_endpoint_descriptor fs_ncm_in_desc __initdata = {
256 .bLength = USB_DT_ENDPOINT_SIZE,
257 .bDescriptorType = USB_DT_ENDPOINT,
258
259 .bEndpointAddress = USB_DIR_IN,
260 .bmAttributes = USB_ENDPOINT_XFER_BULK,
261};
262
263static struct usb_endpoint_descriptor fs_ncm_out_desc __initdata = {
264 .bLength = USB_DT_ENDPOINT_SIZE,
265 .bDescriptorType = USB_DT_ENDPOINT,
266
267 .bEndpointAddress = USB_DIR_OUT,
268 .bmAttributes = USB_ENDPOINT_XFER_BULK,
269};
270
271static struct usb_descriptor_header *ncm_fs_function[] __initdata = {
272 (struct usb_descriptor_header *) &ncm_iad_desc,
273 /* CDC NCM control descriptors */
274 (struct usb_descriptor_header *) &ncm_control_intf,
275 (struct usb_descriptor_header *) &ncm_header_desc,
276 (struct usb_descriptor_header *) &ncm_union_desc,
277 (struct usb_descriptor_header *) &ecm_desc,
278 (struct usb_descriptor_header *) &ncm_desc,
279 (struct usb_descriptor_header *) &fs_ncm_notify_desc,
280 /* data interface, altsettings 0 and 1 */
281 (struct usb_descriptor_header *) &ncm_data_nop_intf,
282 (struct usb_descriptor_header *) &ncm_data_intf,
283 (struct usb_descriptor_header *) &fs_ncm_in_desc,
284 (struct usb_descriptor_header *) &fs_ncm_out_desc,
285 NULL,
286};
287
288/* high speed support: */
289
290static struct usb_endpoint_descriptor hs_ncm_notify_desc __initdata = {
291 .bLength = USB_DT_ENDPOINT_SIZE,
292 .bDescriptorType = USB_DT_ENDPOINT,
293
294 .bEndpointAddress = USB_DIR_IN,
295 .bmAttributes = USB_ENDPOINT_XFER_INT,
296 .wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT),
297 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
298};
299static struct usb_endpoint_descriptor hs_ncm_in_desc __initdata = {
300 .bLength = USB_DT_ENDPOINT_SIZE,
301 .bDescriptorType = USB_DT_ENDPOINT,
302
303 .bEndpointAddress = USB_DIR_IN,
304 .bmAttributes = USB_ENDPOINT_XFER_BULK,
305 .wMaxPacketSize = cpu_to_le16(512),
306};
307
308static struct usb_endpoint_descriptor hs_ncm_out_desc __initdata = {
309 .bLength = USB_DT_ENDPOINT_SIZE,
310 .bDescriptorType = USB_DT_ENDPOINT,
311
312 .bEndpointAddress = USB_DIR_OUT,
313 .bmAttributes = USB_ENDPOINT_XFER_BULK,
314 .wMaxPacketSize = cpu_to_le16(512),
315};
316
317static struct usb_descriptor_header *ncm_hs_function[] __initdata = {
318 (struct usb_descriptor_header *) &ncm_iad_desc,
319 /* CDC NCM control descriptors */
320 (struct usb_descriptor_header *) &ncm_control_intf,
321 (struct usb_descriptor_header *) &ncm_header_desc,
322 (struct usb_descriptor_header *) &ncm_union_desc,
323 (struct usb_descriptor_header *) &ecm_desc,
324 (struct usb_descriptor_header *) &ncm_desc,
325 (struct usb_descriptor_header *) &hs_ncm_notify_desc,
326 /* data interface, altsettings 0 and 1 */
327 (struct usb_descriptor_header *) &ncm_data_nop_intf,
328 (struct usb_descriptor_header *) &ncm_data_intf,
329 (struct usb_descriptor_header *) &hs_ncm_in_desc,
330 (struct usb_descriptor_header *) &hs_ncm_out_desc,
331 NULL,
332};
333
334/* string descriptors: */
335
336#define STRING_CTRL_IDX 0
337#define STRING_MAC_IDX 1
338#define STRING_DATA_IDX 2
339#define STRING_IAD_IDX 3
340
341static struct usb_string ncm_string_defs[] = {
342 [STRING_CTRL_IDX].s = "CDC Network Control Model (NCM)",
343 [STRING_MAC_IDX].s = NULL /* DYNAMIC */,
344 [STRING_DATA_IDX].s = "CDC Network Data",
345 [STRING_IAD_IDX].s = "CDC NCM",
346 { } /* end of list */
347};
348
349static struct usb_gadget_strings ncm_string_table = {
350 .language = 0x0409, /* en-us */
351 .strings = ncm_string_defs,
352};
353
354static struct usb_gadget_strings *ncm_strings[] = {
355 &ncm_string_table,
356 NULL,
357};
358
359/*
360 * Here are options for NCM Datagram Pointer table (NDP) parser.
361 * There are 2 different formats: NDP16 and NDP32 in the spec (ch. 3),
362 * in NDP16 offsets and sizes fields are 1 16bit word wide,
363 * in NDP32 -- 2 16bit words wide. Also signatures are different.
364 * To make the parser code the same, put the differences in the structure,
365 * and switch pointers to the structures when the format is changed.
366 */
367
368struct ndp_parser_opts {
369 u32 nth_sign;
370 u32 ndp_sign;
371 unsigned nth_size;
372 unsigned ndp_size;
373 unsigned ndplen_align;
374 /* sizes in u16 units */
375 unsigned dgram_item_len; /* index or length */
376 unsigned block_length;
377 unsigned fp_index;
378 unsigned reserved1;
379 unsigned reserved2;
380 unsigned next_fp_index;
381};
382
383#define INIT_NDP16_OPTS { \
384 .nth_sign = USB_CDC_NCM_NTH16_SIGN, \
385 .ndp_sign = USB_CDC_NCM_NDP16_NOCRC_SIGN, \
386 .nth_size = sizeof(struct usb_cdc_ncm_nth16), \
387 .ndp_size = sizeof(struct usb_cdc_ncm_ndp16), \
388 .ndplen_align = 4, \
389 .dgram_item_len = 1, \
390 .block_length = 1, \
391 .fp_index = 1, \
392 .reserved1 = 0, \
393 .reserved2 = 0, \
394 .next_fp_index = 1, \
395 }
396
397
398#define INIT_NDP32_OPTS { \
399 .nth_sign = USB_CDC_NCM_NTH32_SIGN, \
400 .ndp_sign = USB_CDC_NCM_NDP32_NOCRC_SIGN, \
401 .nth_size = sizeof(struct usb_cdc_ncm_nth32), \
402 .ndp_size = sizeof(struct usb_cdc_ncm_ndp32), \
403 .ndplen_align = 8, \
404 .dgram_item_len = 2, \
405 .block_length = 2, \
406 .fp_index = 2, \
407 .reserved1 = 1, \
408 .reserved2 = 2, \
409 .next_fp_index = 2, \
410 }
411
412static struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS;
413static struct ndp_parser_opts ndp32_opts = INIT_NDP32_OPTS;
414
415static inline void put_ncm(__le16 **p, unsigned size, unsigned val)
416{
417 switch (size) {
418 case 1:
419 put_unaligned_le16((u16)val, *p);
420 break;
421 case 2:
422 put_unaligned_le32((u32)val, *p);
423
424 break;
425 default:
426 BUG();
427 }
428
429 *p += size;
430}
431
432static inline unsigned get_ncm(__le16 **p, unsigned size)
433{
434 unsigned tmp;
435
436 switch (size) {
437 case 1:
438 tmp = get_unaligned_le16(*p);
439 break;
440 case 2:
441 tmp = get_unaligned_le32(*p);
442 break;
443 default:
444 BUG();
445 }
446
447 *p += size;
448 return tmp;
449}
450
451/*-------------------------------------------------------------------------*/
452
453static inline void ncm_reset_values(struct f_ncm *ncm)
454{
455 ncm->parser_opts = &ndp16_opts;
456 ncm->is_crc = false;
457 ncm->port.cdc_filter = DEFAULT_FILTER;
458
459 /* doesn't make sense for ncm, fixed size used */
460 ncm->port.header_len = 0;
461
462 ncm->port.fixed_out_len = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize);
463 ncm->port.fixed_in_len = NTB_DEFAULT_IN_SIZE;
464}
465
466/*
467 * Context: ncm->lock held
468 */
469static void ncm_do_notify(struct f_ncm *ncm)
470{
471 struct usb_request *req = ncm->notify_req;
472 struct usb_cdc_notification *event;
473 struct usb_composite_dev *cdev = ncm->port.func.config->cdev;
474 __le32 *data;
475 int status;
476
477 /* notification already in flight? */
478 if (!req)
479 return;
480
481 event = req->buf;
482 switch (ncm->notify_state) {
483 case NCM_NOTIFY_NONE:
484 return;
485
486 case NCM_NOTIFY_CONNECT:
487 event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION;
488 if (ncm->is_open)
489 event->wValue = cpu_to_le16(1);
490 else
491 event->wValue = cpu_to_le16(0);
492 event->wLength = 0;
493 req->length = sizeof *event;
494
495 DBG(cdev, "notify connect %s\n",
496 ncm->is_open ? "true" : "false");
497 ncm->notify_state = NCM_NOTIFY_NONE;
498 break;
499
500 case NCM_NOTIFY_SPEED:
501 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE;
502 event->wValue = cpu_to_le16(0);
503 event->wLength = cpu_to_le16(8);
504 req->length = NCM_STATUS_BYTECOUNT;
505
506 /* SPEED_CHANGE data is up/down speeds in bits/sec */
507 data = req->buf + sizeof *event;
508 data[0] = cpu_to_le32(ncm_bitrate(cdev->gadget));
509 data[1] = data[0];
510
511 DBG(cdev, "notify speed %d\n", ncm_bitrate(cdev->gadget));
512 ncm->notify_state = NCM_NOTIFY_CONNECT;
513 break;
514 }
515 event->bmRequestType = 0xA1;
516 event->wIndex = cpu_to_le16(ncm->ctrl_id);
517
518 ncm->notify_req = NULL;
519 /*
520 * In double buffering if there is a space in FIFO,
521 * completion callback can be called right after the call,
522 * so unlocking
523 */
524 spin_unlock(&ncm->lock);
525 status = usb_ep_queue(ncm->notify, req, GFP_ATOMIC);
526 spin_lock(&ncm->lock);
527 if (status < 0) {
528 ncm->notify_req = req;
529 DBG(cdev, "notify --> %d\n", status);
530 }
531}
532
533/*
534 * Context: ncm->lock held
535 */
536static void ncm_notify(struct f_ncm *ncm)
537{
538 /*
539 * NOTE on most versions of Linux, host side cdc-ethernet
540 * won't listen for notifications until its netdevice opens.
541 * The first notification then sits in the FIFO for a long
542 * time, and the second one is queued.
543 *
544 * If ncm_notify() is called before the second (CONNECT)
545 * notification is sent, then it will reset to send the SPEED
546 * notificaion again (and again, and again), but it's not a problem
547 */
548 ncm->notify_state = NCM_NOTIFY_SPEED;
549 ncm_do_notify(ncm);
550}
551
552static void ncm_notify_complete(struct usb_ep *ep, struct usb_request *req)
553{
554 struct f_ncm *ncm = req->context;
555 struct usb_composite_dev *cdev = ncm->port.func.config->cdev;
556 struct usb_cdc_notification *event = req->buf;
557
558 spin_lock(&ncm->lock);
559 switch (req->status) {
560 case 0:
561 VDBG(cdev, "Notification %02x sent\n",
562 event->bNotificationType);
563 break;
564 case -ECONNRESET:
565 case -ESHUTDOWN:
566 ncm->notify_state = NCM_NOTIFY_NONE;
567 break;
568 default:
569 DBG(cdev, "event %02x --> %d\n",
570 event->bNotificationType, req->status);
571 break;
572 }
573 ncm->notify_req = req;
574 ncm_do_notify(ncm);
575 spin_unlock(&ncm->lock);
576}
577
578static void ncm_ep0out_complete(struct usb_ep *ep, struct usb_request *req)
579{
580 /* now for SET_NTB_INPUT_SIZE only */
581 unsigned in_size;
582 struct usb_function *f = req->context;
583 struct f_ncm *ncm = func_to_ncm(f);
584 struct usb_composite_dev *cdev = ep->driver_data;
585
586 req->context = NULL;
587 if (req->status || req->actual != req->length) {
588 DBG(cdev, "Bad control-OUT transfer\n");
589 goto invalid;
590 }
591
592 in_size = get_unaligned_le32(req->buf);
593 if (in_size < USB_CDC_NCM_NTB_MIN_IN_SIZE ||
594 in_size > le32_to_cpu(ntb_parameters.dwNtbInMaxSize)) {
595 DBG(cdev, "Got wrong INPUT SIZE (%d) from host\n", in_size);
596 goto invalid;
597 }
598
599 ncm->port.fixed_in_len = in_size;
600 VDBG(cdev, "Set NTB INPUT SIZE %d\n", in_size);
601 return;
602
603invalid:
604 usb_ep_set_halt(ep);
605 return;
606}
607
608static int ncm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
609{
610 struct f_ncm *ncm = func_to_ncm(f);
611 struct usb_composite_dev *cdev = f->config->cdev;
612 struct usb_request *req = cdev->req;
613 int value = -EOPNOTSUPP;
614 u16 w_index = le16_to_cpu(ctrl->wIndex);
615 u16 w_value = le16_to_cpu(ctrl->wValue);
616 u16 w_length = le16_to_cpu(ctrl->wLength);
617
618 /*
619 * composite driver infrastructure handles everything except
620 * CDC class messages; interface activation uses set_alt().
621 */
622 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
623 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
624 | USB_CDC_SET_ETHERNET_PACKET_FILTER:
625 /*
626 * see 6.2.30: no data, wIndex = interface,
627 * wValue = packet filter bitmap
628 */
629 if (w_length != 0 || w_index != ncm->ctrl_id)
630 goto invalid;
631 DBG(cdev, "packet filter %02x\n", w_value);
632 /*
633 * REVISIT locking of cdc_filter. This assumes the UDC
634 * driver won't have a concurrent packet TX irq running on
635 * another CPU; or that if it does, this write is atomic...
636 */
637 ncm->port.cdc_filter = w_value;
638 value = 0;
639 break;
640 /*
641 * and optionally:
642 * case USB_CDC_SEND_ENCAPSULATED_COMMAND:
643 * case USB_CDC_GET_ENCAPSULATED_RESPONSE:
644 * case USB_CDC_SET_ETHERNET_MULTICAST_FILTERS:
645 * case USB_CDC_SET_ETHERNET_PM_PATTERN_FILTER:
646 * case USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER:
647 * case USB_CDC_GET_ETHERNET_STATISTIC:
648 */
649
650 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
651 | USB_CDC_GET_NTB_PARAMETERS:
652
653 if (w_length == 0 || w_value != 0 || w_index != ncm->ctrl_id)
654 goto invalid;
655 value = w_length > sizeof ntb_parameters ?
656 sizeof ntb_parameters : w_length;
657 memcpy(req->buf, &ntb_parameters, value);
658 VDBG(cdev, "Host asked NTB parameters\n");
659 break;
660
661 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
662 | USB_CDC_GET_NTB_INPUT_SIZE:
663
664 if (w_length < 4 || w_value != 0 || w_index != ncm->ctrl_id)
665 goto invalid;
666 put_unaligned_le32(ncm->port.fixed_in_len, req->buf);
667 value = 4;
668 VDBG(cdev, "Host asked INPUT SIZE, sending %d\n",
669 ncm->port.fixed_in_len);
670 break;
671
672 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
673 | USB_CDC_SET_NTB_INPUT_SIZE:
674 {
675 if (w_length != 4 || w_value != 0 || w_index != ncm->ctrl_id)
676 goto invalid;
677 req->complete = ncm_ep0out_complete;
678 req->length = w_length;
679 req->context = f;
680
681 value = req->length;
682 break;
683 }
684
685 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
686 | USB_CDC_GET_NTB_FORMAT:
687 {
688 uint16_t format;
689
690 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id)
691 goto invalid;
692 format = (ncm->parser_opts == &ndp16_opts) ? 0x0000 : 0x0001;
693 put_unaligned_le16(format, req->buf);
694 value = 2;
695 VDBG(cdev, "Host asked NTB FORMAT, sending %d\n", format);
696 break;
697 }
698
699 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
700 | USB_CDC_SET_NTB_FORMAT:
701 {
702 if (w_length != 0 || w_index != ncm->ctrl_id)
703 goto invalid;
704 switch (w_value) {
705 case 0x0000:
706 ncm->parser_opts = &ndp16_opts;
707 DBG(cdev, "NCM16 selected\n");
708 break;
709 case 0x0001:
710 ncm->parser_opts = &ndp32_opts;
711 DBG(cdev, "NCM32 selected\n");
712 break;
713 default:
714 goto invalid;
715 }
716 value = 0;
717 break;
718 }
719 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
720 | USB_CDC_GET_CRC_MODE:
721 {
722 uint16_t is_crc;
723
724 if (w_length < 2 || w_value != 0 || w_index != ncm->ctrl_id)
725 goto invalid;
726 is_crc = ncm->is_crc ? 0x0001 : 0x0000;
727 put_unaligned_le16(is_crc, req->buf);
728 value = 2;
729 VDBG(cdev, "Host asked CRC MODE, sending %d\n", is_crc);
730 break;
731 }
732
733 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
734 | USB_CDC_SET_CRC_MODE:
735 {
736 int ndp_hdr_crc = 0;
737
738 if (w_length != 0 || w_index != ncm->ctrl_id)
739 goto invalid;
740 switch (w_value) {
741 case 0x0000:
742 ncm->is_crc = false;
743 ndp_hdr_crc = NCM_NDP_HDR_NOCRC;
744 DBG(cdev, "non-CRC mode selected\n");
745 break;
746 case 0x0001:
747 ncm->is_crc = true;
748 ndp_hdr_crc = NCM_NDP_HDR_CRC;
749 DBG(cdev, "CRC mode selected\n");
750 break;
751 default:
752 goto invalid;
753 }
754 ncm->parser_opts->ndp_sign &= ~NCM_NDP_HDR_CRC_MASK;
755 ncm->parser_opts->ndp_sign |= ndp_hdr_crc;
756 value = 0;
757 break;
758 }
759
760 /* and disabled in ncm descriptor: */
761 /* case USB_CDC_GET_NET_ADDRESS: */
762 /* case USB_CDC_SET_NET_ADDRESS: */
763 /* case USB_CDC_GET_MAX_DATAGRAM_SIZE: */
764 /* case USB_CDC_SET_MAX_DATAGRAM_SIZE: */
765
766 default:
767invalid:
768 DBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
769 ctrl->bRequestType, ctrl->bRequest,
770 w_value, w_index, w_length);
771 }
772
773 /* respond with data transfer or status phase? */
774 if (value >= 0) {
775 DBG(cdev, "ncm req%02x.%02x v%04x i%04x l%d\n",
776 ctrl->bRequestType, ctrl->bRequest,
777 w_value, w_index, w_length);
778 req->zero = 0;
779 req->length = value;
780 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
781 if (value < 0)
782 ERROR(cdev, "ncm req %02x.%02x response err %d\n",
783 ctrl->bRequestType, ctrl->bRequest,
784 value);
785 }
786
787 /* device either stalls (value < 0) or reports success */
788 return value;
789}
790
791
792static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
793{
794 struct f_ncm *ncm = func_to_ncm(f);
795 struct usb_composite_dev *cdev = f->config->cdev;
796
797 /* Control interface has only altsetting 0 */
798 if (intf == ncm->ctrl_id) {
799 if (alt != 0)
800 goto fail;
801
802 if (ncm->notify->driver_data) {
803 DBG(cdev, "reset ncm control %d\n", intf);
804 usb_ep_disable(ncm->notify);
805 } else {
806 DBG(cdev, "init ncm ctrl %d\n", intf);
807 ncm->notify_desc = ep_choose(cdev->gadget,
808 ncm->hs.notify,
809 ncm->fs.notify);
810 }
811 usb_ep_enable(ncm->notify, ncm->notify_desc);
812 ncm->notify->driver_data = ncm;
813
814 /* Data interface has two altsettings, 0 and 1 */
815 } else if (intf == ncm->data_id) {
816 if (alt > 1)
817 goto fail;
818
819 if (ncm->port.in_ep->driver_data) {
820 DBG(cdev, "reset ncm\n");
821 gether_disconnect(&ncm->port);
822 ncm_reset_values(ncm);
823 }
824
825 /*
826 * CDC Network only sends data in non-default altsettings.
827 * Changing altsettings resets filters, statistics, etc.
828 */
829 if (alt == 1) {
830 struct net_device *net;
831
832 if (!ncm->port.in) {
833 DBG(cdev, "init ncm\n");
834 ncm->port.in = ep_choose(cdev->gadget,
835 ncm->hs.in,
836 ncm->fs.in);
837 ncm->port.out = ep_choose(cdev->gadget,
838 ncm->hs.out,
839 ncm->fs.out);
840 }
841
842 /* TODO */
843 /* Enable zlps by default for NCM conformance;
844 * override for musb_hdrc (avoids txdma ovhead)
845 */
846 ncm->port.is_zlp_ok = !(
847 gadget_is_musbhdrc(cdev->gadget)
848 );
849 ncm->port.cdc_filter = DEFAULT_FILTER;
850 DBG(cdev, "activate ncm\n");
851 net = gether_connect(&ncm->port);
852 if (IS_ERR(net))
853 return PTR_ERR(net);
854 }
855
856 spin_lock(&ncm->lock);
857 ncm_notify(ncm);
858 spin_unlock(&ncm->lock);
859 } else
860 goto fail;
861
862 return 0;
863fail:
864 return -EINVAL;
865}
866
867/*
868 * Because the data interface supports multiple altsettings,
869 * this NCM function *MUST* implement a get_alt() method.
870 */
871static int ncm_get_alt(struct usb_function *f, unsigned intf)
872{
873 struct f_ncm *ncm = func_to_ncm(f);
874
875 if (intf == ncm->ctrl_id)
876 return 0;
877 return ncm->port.in_ep->driver_data ? 1 : 0;
878}
879
880static struct sk_buff *ncm_wrap_ntb(struct gether *port,
881 struct sk_buff *skb)
882{
883 struct f_ncm *ncm = func_to_ncm(&port->func);
884 struct sk_buff *skb2;
885 int ncb_len = 0;
886 __le16 *tmp;
887 int div = ntb_parameters.wNdpInDivisor;
888 int rem = ntb_parameters.wNdpInPayloadRemainder;
889 int pad;
890 int ndp_align = ntb_parameters.wNdpInAlignment;
891 int ndp_pad;
892 unsigned max_size = ncm->port.fixed_in_len;
893 struct ndp_parser_opts *opts = ncm->parser_opts;
894 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
895
896 ncb_len += opts->nth_size;
897 ndp_pad = ALIGN(ncb_len, ndp_align) - ncb_len;
898 ncb_len += ndp_pad;
899 ncb_len += opts->ndp_size;
900 ncb_len += 2 * 2 * opts->dgram_item_len; /* Datagram entry */
901 ncb_len += 2 * 2 * opts->dgram_item_len; /* Zero datagram entry */
902 pad = ALIGN(ncb_len, div) + rem - ncb_len;
903 ncb_len += pad;
904
905 if (ncb_len + skb->len + crc_len > max_size) {
906 dev_kfree_skb_any(skb);
907 return NULL;
908 }
909
910 skb2 = skb_copy_expand(skb, ncb_len,
911 max_size - skb->len - ncb_len - crc_len,
912 GFP_ATOMIC);
913 dev_kfree_skb_any(skb);
914 if (!skb2)
915 return NULL;
916
917 skb = skb2;
918
919 tmp = (void *) skb_push(skb, ncb_len);
920 memset(tmp, 0, ncb_len);
921
922 put_unaligned_le32(opts->nth_sign, tmp); /* dwSignature */
923 tmp += 2;
924 /* wHeaderLength */
925 put_unaligned_le16(opts->nth_size, tmp++);
926 tmp++; /* skip wSequence */
927 put_ncm(&tmp, opts->block_length, skb->len); /* (d)wBlockLength */
928 /* (d)wFpIndex */
929 /* the first pointer is right after the NTH + align */
930 put_ncm(&tmp, opts->fp_index, opts->nth_size + ndp_pad);
931
932 tmp = (void *)tmp + ndp_pad;
933
934 /* NDP */
935 put_unaligned_le32(opts->ndp_sign, tmp); /* dwSignature */
936 tmp += 2;
937 /* wLength */
938 put_unaligned_le16(ncb_len - opts->nth_size - pad, tmp++);
939
940 tmp += opts->reserved1;
941 tmp += opts->next_fp_index; /* skip reserved (d)wNextFpIndex */
942 tmp += opts->reserved2;
943
944 if (ncm->is_crc) {
945 uint32_t crc;
946
947 crc = ~crc32_le(~0,
948 skb->data + ncb_len,
949 skb->len - ncb_len);
950 put_unaligned_le32(crc, skb->data + skb->len);
951 skb_put(skb, crc_len);
952 }
953
954 /* (d)wDatagramIndex[0] */
955 put_ncm(&tmp, opts->dgram_item_len, ncb_len);
956 /* (d)wDatagramLength[0] */
957 put_ncm(&tmp, opts->dgram_item_len, skb->len - ncb_len);
958 /* (d)wDatagramIndex[1] and (d)wDatagramLength[1] already zeroed */
959
960 if (skb->len > MAX_TX_NONFIXED)
961 memset(skb_put(skb, max_size - skb->len),
962 0, max_size - skb->len);
963
964 return skb;
965}
966
967static int ncm_unwrap_ntb(struct gether *port,
968 struct sk_buff *skb,
969 struct sk_buff_head *list)
970{
971 struct f_ncm *ncm = func_to_ncm(&port->func);
972 __le16 *tmp = (void *) skb->data;
973 unsigned index, index2;
974 unsigned dg_len, dg_len2;
975 unsigned ndp_len;
976 struct sk_buff *skb2;
977 int ret = -EINVAL;
978 unsigned max_size = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize);
979 struct ndp_parser_opts *opts = ncm->parser_opts;
980 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
981 int dgram_counter;
982
983 /* dwSignature */
984 if (get_unaligned_le32(tmp) != opts->nth_sign) {
985 INFO(port->func.config->cdev, "Wrong NTH SIGN, skblen %d\n",
986 skb->len);
987 print_hex_dump(KERN_INFO, "HEAD:", DUMP_PREFIX_ADDRESS, 32, 1,
988 skb->data, 32, false);
989
990 goto err;
991 }
992 tmp += 2;
993 /* wHeaderLength */
994 if (get_unaligned_le16(tmp++) != opts->nth_size) {
995 INFO(port->func.config->cdev, "Wrong NTB headersize\n");
996 goto err;
997 }
998 tmp++; /* skip wSequence */
999
1000 /* (d)wBlockLength */
1001 if (get_ncm(&tmp, opts->block_length) > max_size) {
1002 INFO(port->func.config->cdev, "OUT size exceeded\n");
1003 goto err;
1004 }
1005
1006 index = get_ncm(&tmp, opts->fp_index);
1007 /* NCM 3.2 */
1008 if (((index % 4) != 0) && (index < opts->nth_size)) {
1009 INFO(port->func.config->cdev, "Bad index: %x\n",
1010 index);
1011 goto err;
1012 }
1013
1014 /* walk through NDP */
1015 tmp = ((void *)skb->data) + index;
1016 if (get_unaligned_le32(tmp) != opts->ndp_sign) {
1017 INFO(port->func.config->cdev, "Wrong NDP SIGN\n");
1018 goto err;
1019 }
1020 tmp += 2;
1021
1022 ndp_len = get_unaligned_le16(tmp++);
1023 /*
1024 * NCM 3.3.1
1025 * entry is 2 items
1026 * item size is 16/32 bits, opts->dgram_item_len * 2 bytes
1027 * minimal: struct usb_cdc_ncm_ndpX + normal entry + zero entry
1028 */
1029 if ((ndp_len < opts->ndp_size + 2 * 2 * (opts->dgram_item_len * 2))
1030 || (ndp_len % opts->ndplen_align != 0)) {
1031 INFO(port->func.config->cdev, "Bad NDP length: %x\n", ndp_len);
1032 goto err;
1033 }
1034 tmp += opts->reserved1;
1035 tmp += opts->next_fp_index; /* skip reserved (d)wNextFpIndex */
1036 tmp += opts->reserved2;
1037
1038 ndp_len -= opts->ndp_size;
1039 index2 = get_ncm(&tmp, opts->dgram_item_len);
1040 dg_len2 = get_ncm(&tmp, opts->dgram_item_len);
1041 dgram_counter = 0;
1042
1043 do {
1044 index = index2;
1045 dg_len = dg_len2;
1046 if (dg_len < 14 + crc_len) { /* ethernet header + crc */
1047 INFO(port->func.config->cdev, "Bad dgram length: %x\n",
1048 dg_len);
1049 goto err;
1050 }
1051 if (ncm->is_crc) {
1052 uint32_t crc, crc2;
1053
1054 crc = get_unaligned_le32(skb->data +
1055 index + dg_len - crc_len);
1056 crc2 = ~crc32_le(~0,
1057 skb->data + index,
1058 dg_len - crc_len);
1059 if (crc != crc2) {
1060 INFO(port->func.config->cdev, "Bad CRC\n");
1061 goto err;
1062 }
1063 }
1064
1065 index2 = get_ncm(&tmp, opts->dgram_item_len);
1066 dg_len2 = get_ncm(&tmp, opts->dgram_item_len);
1067
1068 if (index2 == 0 || dg_len2 == 0) {
1069 skb2 = skb;
1070 } else {
1071 skb2 = skb_clone(skb, GFP_ATOMIC);
1072 if (skb2 == NULL)
1073 goto err;
1074 }
1075
1076 if (!skb_pull(skb2, index)) {
1077 ret = -EOVERFLOW;
1078 goto err;
1079 }
1080
1081 skb_trim(skb2, dg_len - crc_len);
1082 skb_queue_tail(list, skb2);
1083
1084 ndp_len -= 2 * (opts->dgram_item_len * 2);
1085
1086 dgram_counter++;
1087
1088 if (index2 == 0 || dg_len2 == 0)
1089 break;
1090 } while (ndp_len > 2 * (opts->dgram_item_len * 2)); /* zero entry */
1091
1092 VDBG(port->func.config->cdev,
1093 "Parsed NTB with %d frames\n", dgram_counter);
1094 return 0;
1095err:
1096 skb_queue_purge(list);
1097 dev_kfree_skb_any(skb);
1098 return ret;
1099}
1100
1101static void ncm_disable(struct usb_function *f)
1102{
1103 struct f_ncm *ncm = func_to_ncm(f);
1104 struct usb_composite_dev *cdev = f->config->cdev;
1105
1106 DBG(cdev, "ncm deactivated\n");
1107
1108 if (ncm->port.in_ep->driver_data)
1109 gether_disconnect(&ncm->port);
1110
1111 if (ncm->notify->driver_data) {
1112 usb_ep_disable(ncm->notify);
1113 ncm->notify->driver_data = NULL;
1114 ncm->notify_desc = NULL;
1115 }
1116}
1117
1118/*-------------------------------------------------------------------------*/
1119
1120/*
1121 * Callbacks let us notify the host about connect/disconnect when the
1122 * net device is opened or closed.
1123 *
1124 * For testing, note that link states on this side include both opened
1125 * and closed variants of:
1126 *
1127 * - disconnected/unconfigured
1128 * - configured but inactive (data alt 0)
1129 * - configured and active (data alt 1)
1130 *
1131 * Each needs to be tested with unplug, rmmod, SET_CONFIGURATION, and
1132 * SET_INTERFACE (altsetting). Remember also that "configured" doesn't
1133 * imply the host is actually polling the notification endpoint, and
1134 * likewise that "active" doesn't imply it's actually using the data
1135 * endpoints for traffic.
1136 */
1137
1138static void ncm_open(struct gether *geth)
1139{
1140 struct f_ncm *ncm = func_to_ncm(&geth->func);
1141
1142 DBG(ncm->port.func.config->cdev, "%s\n", __func__);
1143
1144 spin_lock(&ncm->lock);
1145 ncm->is_open = true;
1146 ncm_notify(ncm);
1147 spin_unlock(&ncm->lock);
1148}
1149
1150static void ncm_close(struct gether *geth)
1151{
1152 struct f_ncm *ncm = func_to_ncm(&geth->func);
1153
1154 DBG(ncm->port.func.config->cdev, "%s\n", __func__);
1155
1156 spin_lock(&ncm->lock);
1157 ncm->is_open = false;
1158 ncm_notify(ncm);
1159 spin_unlock(&ncm->lock);
1160}
1161
1162/*-------------------------------------------------------------------------*/
1163
1164/* ethernet function driver setup/binding */
1165
1166static int __init
1167ncm_bind(struct usb_configuration *c, struct usb_function *f)
1168{
1169 struct usb_composite_dev *cdev = c->cdev;
1170 struct f_ncm *ncm = func_to_ncm(f);
1171 int status;
1172 struct usb_ep *ep;
1173
1174 /* allocate instance-specific interface IDs */
1175 status = usb_interface_id(c, f);
1176 if (status < 0)
1177 goto fail;
1178 ncm->ctrl_id = status;
1179 ncm_iad_desc.bFirstInterface = status;
1180
1181 ncm_control_intf.bInterfaceNumber = status;
1182 ncm_union_desc.bMasterInterface0 = status;
1183
1184 status = usb_interface_id(c, f);
1185 if (status < 0)
1186 goto fail;
1187 ncm->data_id = status;
1188
1189 ncm_data_nop_intf.bInterfaceNumber = status;
1190 ncm_data_intf.bInterfaceNumber = status;
1191 ncm_union_desc.bSlaveInterface0 = status;
1192
1193 status = -ENODEV;
1194
1195 /* allocate instance-specific endpoints */
1196 ep = usb_ep_autoconfig(cdev->gadget, &fs_ncm_in_desc);
1197 if (!ep)
1198 goto fail;
1199 ncm->port.in_ep = ep;
1200 ep->driver_data = cdev; /* claim */
1201
1202 ep = usb_ep_autoconfig(cdev->gadget, &fs_ncm_out_desc);
1203 if (!ep)
1204 goto fail;
1205 ncm->port.out_ep = ep;
1206 ep->driver_data = cdev; /* claim */
1207
1208 ep = usb_ep_autoconfig(cdev->gadget, &fs_ncm_notify_desc);
1209 if (!ep)
1210 goto fail;
1211 ncm->notify = ep;
1212 ep->driver_data = cdev; /* claim */
1213
1214 status = -ENOMEM;
1215
1216 /* allocate notification request and buffer */
1217 ncm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
1218 if (!ncm->notify_req)
1219 goto fail;
1220 ncm->notify_req->buf = kmalloc(NCM_STATUS_BYTECOUNT, GFP_KERNEL);
1221 if (!ncm->notify_req->buf)
1222 goto fail;
1223 ncm->notify_req->context = ncm;
1224 ncm->notify_req->complete = ncm_notify_complete;
1225
1226 /* copy descriptors, and track endpoint copies */
1227 f->descriptors = usb_copy_descriptors(ncm_fs_function);
1228 if (!f->descriptors)
1229 goto fail;
1230
1231 ncm->fs.in = usb_find_endpoint(ncm_fs_function,
1232 f->descriptors, &fs_ncm_in_desc);
1233 ncm->fs.out = usb_find_endpoint(ncm_fs_function,
1234 f->descriptors, &fs_ncm_out_desc);
1235 ncm->fs.notify = usb_find_endpoint(ncm_fs_function,
1236 f->descriptors, &fs_ncm_notify_desc);
1237
1238 /*
1239 * support all relevant hardware speeds... we expect that when
1240 * hardware is dual speed, all bulk-capable endpoints work at
1241 * both speeds
1242 */
1243 if (gadget_is_dualspeed(c->cdev->gadget)) {
1244 hs_ncm_in_desc.bEndpointAddress =
1245 fs_ncm_in_desc.bEndpointAddress;
1246 hs_ncm_out_desc.bEndpointAddress =
1247 fs_ncm_out_desc.bEndpointAddress;
1248 hs_ncm_notify_desc.bEndpointAddress =
1249 fs_ncm_notify_desc.bEndpointAddress;
1250
1251 /* copy descriptors, and track endpoint copies */
1252 f->hs_descriptors = usb_copy_descriptors(ncm_hs_function);
1253 if (!f->hs_descriptors)
1254 goto fail;
1255
1256 ncm->hs.in = usb_find_endpoint(ncm_hs_function,
1257 f->hs_descriptors, &hs_ncm_in_desc);
1258 ncm->hs.out = usb_find_endpoint(ncm_hs_function,
1259 f->hs_descriptors, &hs_ncm_out_desc);
1260 ncm->hs.notify = usb_find_endpoint(ncm_hs_function,
1261 f->hs_descriptors, &hs_ncm_notify_desc);
1262 }
1263
1264 /*
1265 * NOTE: all that is done without knowing or caring about
1266 * the network link ... which is unavailable to this code
1267 * until we're activated via set_alt().
1268 */
1269
1270 ncm->port.open = ncm_open;
1271 ncm->port.close = ncm_close;
1272
1273 DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n",
1274 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
1275 ncm->port.in_ep->name, ncm->port.out_ep->name,
1276 ncm->notify->name);
1277 return 0;
1278
1279fail:
1280 if (f->descriptors)
1281 usb_free_descriptors(f->descriptors);
1282
1283 if (ncm->notify_req) {
1284 kfree(ncm->notify_req->buf);
1285 usb_ep_free_request(ncm->notify, ncm->notify_req);
1286 }
1287
1288 /* we might as well release our claims on endpoints */
1289 if (ncm->notify)
1290 ncm->notify->driver_data = NULL;
1291 if (ncm->port.out)
1292 ncm->port.out_ep->driver_data = NULL;
1293 if (ncm->port.in)
1294 ncm->port.in_ep->driver_data = NULL;
1295
1296 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
1297
1298 return status;
1299}
1300
1301static void
1302ncm_unbind(struct usb_configuration *c, struct usb_function *f)
1303{
1304 struct f_ncm *ncm = func_to_ncm(f);
1305
1306 DBG(c->cdev, "ncm unbind\n");
1307
1308 if (gadget_is_dualspeed(c->cdev->gadget))
1309 usb_free_descriptors(f->hs_descriptors);
1310 usb_free_descriptors(f->descriptors);
1311
1312 kfree(ncm->notify_req->buf);
1313 usb_ep_free_request(ncm->notify, ncm->notify_req);
1314
1315 ncm_string_defs[1].s = NULL;
1316 kfree(ncm);
1317}
1318
1319/**
1320 * ncm_bind_config - add CDC Network link to a configuration
1321 * @c: the configuration to support the network link
1322 * @ethaddr: a buffer in which the ethernet address of the host side
1323 * side of the link was recorded
1324 * Context: single threaded during gadget setup
1325 *
1326 * Returns zero on success, else negative errno.
1327 *
1328 * Caller must have called @gether_setup(). Caller is also responsible
1329 * for calling @gether_cleanup() before module unload.
1330 */
1331int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
1332{
1333 struct f_ncm *ncm;
1334 int status;
1335
1336 if (!can_support_ecm(c->cdev->gadget) || !ethaddr)
1337 return -EINVAL;
1338
1339 /* maybe allocate device-global string IDs */
1340 if (ncm_string_defs[0].id == 0) {
1341
1342 /* control interface label */
1343 status = usb_string_id(c->cdev);
1344 if (status < 0)
1345 return status;
1346 ncm_string_defs[STRING_CTRL_IDX].id = status;
1347 ncm_control_intf.iInterface = status;
1348
1349 /* data interface label */
1350 status = usb_string_id(c->cdev);
1351 if (status < 0)
1352 return status;
1353 ncm_string_defs[STRING_DATA_IDX].id = status;
1354 ncm_data_nop_intf.iInterface = status;
1355 ncm_data_intf.iInterface = status;
1356
1357 /* MAC address */
1358 status = usb_string_id(c->cdev);
1359 if (status < 0)
1360 return status;
1361 ncm_string_defs[STRING_MAC_IDX].id = status;
1362 ecm_desc.iMACAddress = status;
1363
1364 /* IAD */
1365 status = usb_string_id(c->cdev);
1366 if (status < 0)
1367 return status;
1368 ncm_string_defs[STRING_IAD_IDX].id = status;
1369 ncm_iad_desc.iFunction = status;
1370 }
1371
1372 /* allocate and initialize one new instance */
1373 ncm = kzalloc(sizeof *ncm, GFP_KERNEL);
1374 if (!ncm)
1375 return -ENOMEM;
1376
1377 /* export host's Ethernet address in CDC format */
1378 snprintf(ncm->ethaddr, sizeof ncm->ethaddr,
1379 "%02X%02X%02X%02X%02X%02X",
1380 ethaddr[0], ethaddr[1], ethaddr[2],
1381 ethaddr[3], ethaddr[4], ethaddr[5]);
1382 ncm_string_defs[1].s = ncm->ethaddr;
1383
1384 spin_lock_init(&ncm->lock);
1385 ncm_reset_values(ncm);
1386 ncm->port.is_fixed = true;
1387
1388 ncm->port.func.name = "cdc_network";
1389 ncm->port.func.strings = ncm_strings;
1390 /* descriptors are per-instance copies */
1391 ncm->port.func.bind = ncm_bind;
1392 ncm->port.func.unbind = ncm_unbind;
1393 ncm->port.func.set_alt = ncm_set_alt;
1394 ncm->port.func.get_alt = ncm_get_alt;
1395 ncm->port.func.setup = ncm_setup;
1396 ncm->port.func.disable = ncm_disable;
1397
1398 ncm->port.wrap = ncm_wrap_ntb;
1399 ncm->port.unwrap = ncm_unwrap_ntb;
1400
1401 status = usb_add_function(c, &ncm->port.func);
1402 if (status) {
1403 ncm_string_defs[1].s = NULL;
1404 kfree(ncm);
1405 }
1406 return status;
1407}
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
index 3c6e1a058745..5e1495097ec3 100644
--- a/drivers/usb/gadget/f_phonet.c
+++ b/drivers/usb/gadget/f_phonet.c
@@ -346,14 +346,19 @@ static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req)
346 346
347 if (unlikely(!skb)) 347 if (unlikely(!skb))
348 break; 348 break;
349 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, 0,
350 req->actual);
351 page = NULL;
352 349
353 if (req->actual < req->length) { /* Last fragment */ 350 if (skb->len == 0) { /* First fragment */
354 skb->protocol = htons(ETH_P_PHONET); 351 skb->protocol = htons(ETH_P_PHONET);
355 skb_reset_mac_header(skb); 352 skb_reset_mac_header(skb);
356 pskb_pull(skb, 1); 353 /* Can't use pskb_pull() on page in IRQ */
354 memcpy(skb_put(skb, 1), page_address(page), 1);
355 }
356
357 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
358 skb->len == 0, req->actual);
359 page = NULL;
360
361 if (req->actual < req->length) { /* Last fragment */
357 skb->dev = dev; 362 skb->dev = dev;
358 dev->stats.rx_packets++; 363 dev->stats.rx_packets++;
359 dev->stats.rx_bytes += skb->len; 364 dev->stats.rx_bytes += skb->len;
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 882484a40398..fa12ec8364ef 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -420,8 +420,7 @@ rndis_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
420 */ 420 */
421 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8) 421 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
422 | USB_CDC_SEND_ENCAPSULATED_COMMAND: 422 | USB_CDC_SEND_ENCAPSULATED_COMMAND:
423 if (w_length > req->length || w_value 423 if (w_value || w_index != rndis->ctrl_id)
424 || w_index != rndis->ctrl_id)
425 goto invalid; 424 goto invalid;
426 /* read the request; process it later */ 425 /* read the request; process it later */
427 value = w_length; 426 value = w_length;
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index 685d768f336e..e403a534dd55 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -404,7 +404,7 @@ static void sourcesink_disable(struct usb_function *f)
404 404
405/*-------------------------------------------------------------------------*/ 405/*-------------------------------------------------------------------------*/
406 406
407static int __ref sourcesink_bind_config(struct usb_configuration *c) 407static int __init sourcesink_bind_config(struct usb_configuration *c)
408{ 408{
409 struct f_sourcesink *ss; 409 struct f_sourcesink *ss;
410 int status; 410 int status;
@@ -498,7 +498,6 @@ unknown:
498static struct usb_configuration sourcesink_driver = { 498static struct usb_configuration sourcesink_driver = {
499 .label = "source/sink", 499 .label = "source/sink",
500 .strings = sourcesink_strings, 500 .strings = sourcesink_strings,
501 .bind = sourcesink_bind_config,
502 .setup = sourcesink_setup, 501 .setup = sourcesink_setup,
503 .bConfigurationValue = 3, 502 .bConfigurationValue = 3,
504 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 503 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -532,5 +531,5 @@ int __init sourcesink_add(struct usb_composite_dev *cdev, bool autoresume)
532 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 531 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
533 } 532 }
534 533
535 return usb_add_config(cdev, &sourcesink_driver); 534 return usb_add_config(cdev, &sourcesink_driver, sourcesink_bind_config);
536} 535}
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a857b7ac238c..0360f56221ea 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -89,6 +89,7 @@
89 * Required if "removable" is not set, names of 89 * Required if "removable" is not set, names of
90 * the files or block devices used for 90 * the files or block devices used for
91 * backing storage 91 * backing storage
92 * serial=HHHH... Required serial number (string of hex chars)
92 * ro=b[,b...] Default false, booleans for read-only access 93 * ro=b[,b...] Default false, booleans for read-only access
93 * removable Default false, boolean for removable media 94 * removable Default false, boolean for removable media
94 * luns=N Default N = number of filenames, number of 95 * luns=N Default N = number of filenames, number of
@@ -108,12 +109,11 @@
108 * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID 109 * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
109 * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID 110 * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
110 * release=0xRRRR Override the USB release number (bcdDevice) 111 * release=0xRRRR Override the USB release number (bcdDevice)
111 * serial=HHHH... Override serial number (string of hex chars)
112 * buflen=N Default N=16384, buffer size used (will be 112 * buflen=N Default N=16384, buffer size used (will be
113 * rounded down to a multiple of 113 * rounded down to a multiple of
114 * PAGE_CACHE_SIZE) 114 * PAGE_CACHE_SIZE)
115 * 115 *
116 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", 116 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
117 * "removable", "luns", "nofua", "stall", and "cdrom" options are available; 117 * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
118 * default values are used for everything else. 118 * default values are used for everything else.
119 * 119 *
@@ -273,13 +273,10 @@
273 273
274#define DRIVER_DESC "File-backed Storage Gadget" 274#define DRIVER_DESC "File-backed Storage Gadget"
275#define DRIVER_NAME "g_file_storage" 275#define DRIVER_NAME "g_file_storage"
276/* DRIVER_VERSION must be at least 6 characters long, as it is used 276#define DRIVER_VERSION "1 September 2010"
277 * to generate a fallback serial number. */
278#define DRIVER_VERSION "20 November 2008"
279 277
280static char fsg_string_manufacturer[64]; 278static char fsg_string_manufacturer[64];
281static const char fsg_string_product[] = DRIVER_DESC; 279static const char fsg_string_product[] = DRIVER_DESC;
282static char fsg_string_serial[13];
283static const char fsg_string_config[] = "Self-powered"; 280static const char fsg_string_config[] = "Self-powered";
284static const char fsg_string_interface[] = "Mass Storage"; 281static const char fsg_string_interface[] = "Mass Storage";
285 282
@@ -305,6 +302,7 @@ MODULE_LICENSE("Dual BSD/GPL");
305 302
306static struct { 303static struct {
307 char *file[FSG_MAX_LUNS]; 304 char *file[FSG_MAX_LUNS];
305 char *serial;
308 int ro[FSG_MAX_LUNS]; 306 int ro[FSG_MAX_LUNS];
309 int nofua[FSG_MAX_LUNS]; 307 int nofua[FSG_MAX_LUNS];
310 unsigned int num_filenames; 308 unsigned int num_filenames;
@@ -321,7 +319,6 @@ static struct {
321 unsigned short vendor; 319 unsigned short vendor;
322 unsigned short product; 320 unsigned short product;
323 unsigned short release; 321 unsigned short release;
324 char *serial;
325 unsigned int buflen; 322 unsigned int buflen;
326 323
327 int transport_type; 324 int transport_type;
@@ -346,6 +343,9 @@ module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
346 S_IRUGO); 343 S_IRUGO);
347MODULE_PARM_DESC(file, "names of backing files or devices"); 344MODULE_PARM_DESC(file, "names of backing files or devices");
348 345
346module_param_named(serial, mod_data.serial, charp, S_IRUGO);
347MODULE_PARM_DESC(serial, "USB serial number");
348
349module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO); 349module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
350MODULE_PARM_DESC(ro, "true to force read-only"); 350MODULE_PARM_DESC(ro, "true to force read-only");
351 351
@@ -365,9 +365,6 @@ MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
365module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); 365module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
366MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); 366MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
367 367
368module_param_named(serial, mod_data.serial, charp, S_IRUGO);
369MODULE_PARM_DESC(serial, "USB serial number");
370
371/* In the non-TEST version, only the module parameters listed above 368/* In the non-TEST version, only the module parameters listed above
372 * are available. */ 369 * are available. */
373#ifdef CONFIG_USB_FILE_STORAGE_TEST 370#ifdef CONFIG_USB_FILE_STORAGE_TEST
@@ -786,7 +783,7 @@ static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
786{ 783{
787 struct usb_request *req = fsg->ep0req; 784 struct usb_request *req = fsg->ep0req;
788 static u8 cbi_reset_cmnd[6] = { 785 static u8 cbi_reset_cmnd[6] = {
789 SC_SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff}; 786 SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
790 787
791 /* Error in command transfer? */ 788 /* Error in command transfer? */
792 if (req->status || req->length != req->actual || 789 if (req->status || req->length != req->actual ||
@@ -1138,7 +1135,7 @@ static int do_read(struct fsg_dev *fsg)
1138 1135
1139 /* Get the starting Logical Block Address and check that it's 1136 /* Get the starting Logical Block Address and check that it's
1140 * not too big */ 1137 * not too big */
1141 if (fsg->cmnd[0] == SC_READ_6) 1138 if (fsg->cmnd[0] == READ_6)
1142 lba = get_unaligned_be24(&fsg->cmnd[1]); 1139 lba = get_unaligned_be24(&fsg->cmnd[1]);
1143 else { 1140 else {
1144 lba = get_unaligned_be32(&fsg->cmnd[2]); 1141 lba = get_unaligned_be32(&fsg->cmnd[2]);
@@ -1273,7 +1270,7 @@ static int do_write(struct fsg_dev *fsg)
1273 1270
1274 /* Get the starting Logical Block Address and check that it's 1271 /* Get the starting Logical Block Address and check that it's
1275 * not too big */ 1272 * not too big */
1276 if (fsg->cmnd[0] == SC_WRITE_6) 1273 if (fsg->cmnd[0] == WRITE_6)
1277 lba = get_unaligned_be24(&fsg->cmnd[1]); 1274 lba = get_unaligned_be24(&fsg->cmnd[1]);
1278 else { 1275 else {
1279 lba = get_unaligned_be32(&fsg->cmnd[2]); 1276 lba = get_unaligned_be32(&fsg->cmnd[2]);
@@ -1581,7 +1578,7 @@ static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1581 } 1578 }
1582 1579
1583 memset(buf, 0, 8); 1580 memset(buf, 0, 8);
1584 buf[0] = (mod_data.cdrom ? TYPE_CDROM : TYPE_DISK); 1581 buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
1585 if (mod_data.removable) 1582 if (mod_data.removable)
1586 buf[1] = 0x80; 1583 buf[1] = 0x80;
1587 buf[2] = 2; // ANSI SCSI level 2 1584 buf[2] = 2; // ANSI SCSI level 2
@@ -1750,11 +1747,11 @@ static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1750 * The only variable value is the WriteProtect bit. We will fill in 1747 * The only variable value is the WriteProtect bit. We will fill in
1751 * the mode data length later. */ 1748 * the mode data length later. */
1752 memset(buf, 0, 8); 1749 memset(buf, 0, 8);
1753 if (mscmnd == SC_MODE_SENSE_6) { 1750 if (mscmnd == MODE_SENSE) {
1754 buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA 1751 buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
1755 buf += 4; 1752 buf += 4;
1756 limit = 255; 1753 limit = 255;
1757 } else { // SC_MODE_SENSE_10 1754 } else { // MODE_SENSE_10
1758 buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA 1755 buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
1759 buf += 8; 1756 buf += 8;
1760 limit = 65535; // Should really be mod_data.buflen 1757 limit = 65535; // Should really be mod_data.buflen
@@ -1794,7 +1791,7 @@ static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1794 } 1791 }
1795 1792
1796 /* Store the mode data length */ 1793 /* Store the mode data length */
1797 if (mscmnd == SC_MODE_SENSE_6) 1794 if (mscmnd == MODE_SENSE)
1798 buf0[0] = len - 1; 1795 buf0[0] = len - 1;
1799 else 1796 else
1800 put_unaligned_be16(len - 2, buf0); 1797 put_unaligned_be16(len - 2, buf0);
@@ -1950,37 +1947,6 @@ static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
1950 return rc; 1947 return rc;
1951} 1948}
1952 1949
1953static int pad_with_zeros(struct fsg_dev *fsg)
1954{
1955 struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
1956 u32 nkeep = bh->inreq->length;
1957 u32 nsend;
1958 int rc;
1959
1960 bh->state = BUF_STATE_EMPTY; // For the first iteration
1961 fsg->usb_amount_left = nkeep + fsg->residue;
1962 while (fsg->usb_amount_left > 0) {
1963
1964 /* Wait for the next buffer to be free */
1965 while (bh->state != BUF_STATE_EMPTY) {
1966 rc = sleep_thread(fsg);
1967 if (rc)
1968 return rc;
1969 }
1970
1971 nsend = min(fsg->usb_amount_left, (u32) mod_data.buflen);
1972 memset(bh->buf + nkeep, 0, nsend - nkeep);
1973 bh->inreq->length = nsend;
1974 bh->inreq->zero = 0;
1975 start_transfer(fsg, fsg->bulk_in, bh->inreq,
1976 &bh->inreq_busy, &bh->state);
1977 bh = fsg->next_buffhd_to_fill = bh->next;
1978 fsg->usb_amount_left -= nsend;
1979 nkeep = 0;
1980 }
1981 return 0;
1982}
1983
1984static int throw_away_data(struct fsg_dev *fsg) 1950static int throw_away_data(struct fsg_dev *fsg)
1985{ 1951{
1986 struct fsg_buffhd *bh; 1952 struct fsg_buffhd *bh;
@@ -2085,18 +2051,20 @@ static int finish_reply(struct fsg_dev *fsg)
2085 } 2051 }
2086 } 2052 }
2087 2053
2088 /* For Bulk-only, if we're allowed to stall then send the 2054 /*
2089 * short packet and halt the bulk-in endpoint. If we can't 2055 * For Bulk-only, mark the end of the data with a short
2090 * stall, pad out the remaining data with 0's. */ 2056 * packet. If we are allowed to stall, halt the bulk-in
2057 * endpoint. (Note: This violates the Bulk-Only Transport
2058 * specification, which requires us to pad the data if we
2059 * don't halt the endpoint. Presumably nobody will mind.)
2060 */
2091 else { 2061 else {
2092 if (mod_data.can_stall) { 2062 bh->inreq->zero = 1;
2093 bh->inreq->zero = 1; 2063 start_transfer(fsg, fsg->bulk_in, bh->inreq,
2094 start_transfer(fsg, fsg->bulk_in, bh->inreq, 2064 &bh->inreq_busy, &bh->state);
2095 &bh->inreq_busy, &bh->state); 2065 fsg->next_buffhd_to_fill = bh->next;
2096 fsg->next_buffhd_to_fill = bh->next; 2066 if (mod_data.can_stall)
2097 rc = halt_bulk_in_endpoint(fsg); 2067 rc = halt_bulk_in_endpoint(fsg);
2098 } else
2099 rc = pad_with_zeros(fsg);
2100 } 2068 }
2101 break; 2069 break;
2102 2070
@@ -2317,9 +2285,9 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2317 fsg->lun = lun; // Use LUN from the command 2285 fsg->lun = lun; // Use LUN from the command
2318 2286
2319 /* Check the LUN */ 2287 /* Check the LUN */
2320 if (fsg->lun >= 0 && fsg->lun < fsg->nluns) { 2288 if (fsg->lun < fsg->nluns) {
2321 fsg->curlun = curlun = &fsg->luns[fsg->lun]; 2289 fsg->curlun = curlun = &fsg->luns[fsg->lun];
2322 if (fsg->cmnd[0] != SC_REQUEST_SENSE) { 2290 if (fsg->cmnd[0] != REQUEST_SENSE) {
2323 curlun->sense_data = SS_NO_SENSE; 2291 curlun->sense_data = SS_NO_SENSE;
2324 curlun->sense_data_info = 0; 2292 curlun->sense_data_info = 0;
2325 curlun->info_valid = 0; 2293 curlun->info_valid = 0;
@@ -2330,8 +2298,8 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2330 2298
2331 /* INQUIRY and REQUEST SENSE commands are explicitly allowed 2299 /* INQUIRY and REQUEST SENSE commands are explicitly allowed
2332 * to use unsupported LUNs; all others may not. */ 2300 * to use unsupported LUNs; all others may not. */
2333 if (fsg->cmnd[0] != SC_INQUIRY && 2301 if (fsg->cmnd[0] != INQUIRY &&
2334 fsg->cmnd[0] != SC_REQUEST_SENSE) { 2302 fsg->cmnd[0] != REQUEST_SENSE) {
2335 DBG(fsg, "unsupported LUN %d\n", fsg->lun); 2303 DBG(fsg, "unsupported LUN %d\n", fsg->lun);
2336 return -EINVAL; 2304 return -EINVAL;
2337 } 2305 }
@@ -2340,8 +2308,8 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2340 /* If a unit attention condition exists, only INQUIRY and 2308 /* If a unit attention condition exists, only INQUIRY and
2341 * REQUEST SENSE commands are allowed; anything else must fail. */ 2309 * REQUEST SENSE commands are allowed; anything else must fail. */
2342 if (curlun && curlun->unit_attention_data != SS_NO_SENSE && 2310 if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
2343 fsg->cmnd[0] != SC_INQUIRY && 2311 fsg->cmnd[0] != INQUIRY &&
2344 fsg->cmnd[0] != SC_REQUEST_SENSE) { 2312 fsg->cmnd[0] != REQUEST_SENSE) {
2345 curlun->sense_data = curlun->unit_attention_data; 2313 curlun->sense_data = curlun->unit_attention_data;
2346 curlun->unit_attention_data = SS_NO_SENSE; 2314 curlun->unit_attention_data = SS_NO_SENSE;
2347 return -EINVAL; 2315 return -EINVAL;
@@ -2391,7 +2359,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2391 down_read(&fsg->filesem); // We're using the backing file 2359 down_read(&fsg->filesem); // We're using the backing file
2392 switch (fsg->cmnd[0]) { 2360 switch (fsg->cmnd[0]) {
2393 2361
2394 case SC_INQUIRY: 2362 case INQUIRY:
2395 fsg->data_size_from_cmnd = fsg->cmnd[4]; 2363 fsg->data_size_from_cmnd = fsg->cmnd[4];
2396 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, 2364 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
2397 (1<<4), 0, 2365 (1<<4), 0,
@@ -2399,7 +2367,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2399 reply = do_inquiry(fsg, bh); 2367 reply = do_inquiry(fsg, bh);
2400 break; 2368 break;
2401 2369
2402 case SC_MODE_SELECT_6: 2370 case MODE_SELECT:
2403 fsg->data_size_from_cmnd = fsg->cmnd[4]; 2371 fsg->data_size_from_cmnd = fsg->cmnd[4];
2404 if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST, 2372 if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
2405 (1<<1) | (1<<4), 0, 2373 (1<<1) | (1<<4), 0,
@@ -2407,7 +2375,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2407 reply = do_mode_select(fsg, bh); 2375 reply = do_mode_select(fsg, bh);
2408 break; 2376 break;
2409 2377
2410 case SC_MODE_SELECT_10: 2378 case MODE_SELECT_10:
2411 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2379 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
2412 if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST, 2380 if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
2413 (1<<1) | (3<<7), 0, 2381 (1<<1) | (3<<7), 0,
@@ -2415,7 +2383,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2415 reply = do_mode_select(fsg, bh); 2383 reply = do_mode_select(fsg, bh);
2416 break; 2384 break;
2417 2385
2418 case SC_MODE_SENSE_6: 2386 case MODE_SENSE:
2419 fsg->data_size_from_cmnd = fsg->cmnd[4]; 2387 fsg->data_size_from_cmnd = fsg->cmnd[4];
2420 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, 2388 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
2421 (1<<1) | (1<<2) | (1<<4), 0, 2389 (1<<1) | (1<<2) | (1<<4), 0,
@@ -2423,7 +2391,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2423 reply = do_mode_sense(fsg, bh); 2391 reply = do_mode_sense(fsg, bh);
2424 break; 2392 break;
2425 2393
2426 case SC_MODE_SENSE_10: 2394 case MODE_SENSE_10:
2427 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2395 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
2428 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, 2396 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
2429 (1<<1) | (1<<2) | (3<<7), 0, 2397 (1<<1) | (1<<2) | (3<<7), 0,
@@ -2431,7 +2399,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2431 reply = do_mode_sense(fsg, bh); 2399 reply = do_mode_sense(fsg, bh);
2432 break; 2400 break;
2433 2401
2434 case SC_PREVENT_ALLOW_MEDIUM_REMOVAL: 2402 case ALLOW_MEDIUM_REMOVAL:
2435 fsg->data_size_from_cmnd = 0; 2403 fsg->data_size_from_cmnd = 0;
2436 if ((reply = check_command(fsg, 6, DATA_DIR_NONE, 2404 if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
2437 (1<<4), 0, 2405 (1<<4), 0,
@@ -2439,7 +2407,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2439 reply = do_prevent_allow(fsg); 2407 reply = do_prevent_allow(fsg);
2440 break; 2408 break;
2441 2409
2442 case SC_READ_6: 2410 case READ_6:
2443 i = fsg->cmnd[4]; 2411 i = fsg->cmnd[4];
2444 fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; 2412 fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
2445 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, 2413 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
@@ -2448,7 +2416,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2448 reply = do_read(fsg); 2416 reply = do_read(fsg);
2449 break; 2417 break;
2450 2418
2451 case SC_READ_10: 2419 case READ_10:
2452 fsg->data_size_from_cmnd = 2420 fsg->data_size_from_cmnd =
2453 get_unaligned_be16(&fsg->cmnd[7]) << 9; 2421 get_unaligned_be16(&fsg->cmnd[7]) << 9;
2454 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, 2422 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
@@ -2457,7 +2425,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2457 reply = do_read(fsg); 2425 reply = do_read(fsg);
2458 break; 2426 break;
2459 2427
2460 case SC_READ_12: 2428 case READ_12:
2461 fsg->data_size_from_cmnd = 2429 fsg->data_size_from_cmnd =
2462 get_unaligned_be32(&fsg->cmnd[6]) << 9; 2430 get_unaligned_be32(&fsg->cmnd[6]) << 9;
2463 if ((reply = check_command(fsg, 12, DATA_DIR_TO_HOST, 2431 if ((reply = check_command(fsg, 12, DATA_DIR_TO_HOST,
@@ -2466,7 +2434,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2466 reply = do_read(fsg); 2434 reply = do_read(fsg);
2467 break; 2435 break;
2468 2436
2469 case SC_READ_CAPACITY: 2437 case READ_CAPACITY:
2470 fsg->data_size_from_cmnd = 8; 2438 fsg->data_size_from_cmnd = 8;
2471 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, 2439 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
2472 (0xf<<2) | (1<<8), 1, 2440 (0xf<<2) | (1<<8), 1,
@@ -2474,7 +2442,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2474 reply = do_read_capacity(fsg, bh); 2442 reply = do_read_capacity(fsg, bh);
2475 break; 2443 break;
2476 2444
2477 case SC_READ_HEADER: 2445 case READ_HEADER:
2478 if (!mod_data.cdrom) 2446 if (!mod_data.cdrom)
2479 goto unknown_cmnd; 2447 goto unknown_cmnd;
2480 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2448 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
@@ -2484,7 +2452,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2484 reply = do_read_header(fsg, bh); 2452 reply = do_read_header(fsg, bh);
2485 break; 2453 break;
2486 2454
2487 case SC_READ_TOC: 2455 case READ_TOC:
2488 if (!mod_data.cdrom) 2456 if (!mod_data.cdrom)
2489 goto unknown_cmnd; 2457 goto unknown_cmnd;
2490 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2458 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
@@ -2494,7 +2462,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2494 reply = do_read_toc(fsg, bh); 2462 reply = do_read_toc(fsg, bh);
2495 break; 2463 break;
2496 2464
2497 case SC_READ_FORMAT_CAPACITIES: 2465 case READ_FORMAT_CAPACITIES:
2498 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2466 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
2499 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, 2467 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
2500 (3<<7), 1, 2468 (3<<7), 1,
@@ -2502,7 +2470,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2502 reply = do_read_format_capacities(fsg, bh); 2470 reply = do_read_format_capacities(fsg, bh);
2503 break; 2471 break;
2504 2472
2505 case SC_REQUEST_SENSE: 2473 case REQUEST_SENSE:
2506 fsg->data_size_from_cmnd = fsg->cmnd[4]; 2474 fsg->data_size_from_cmnd = fsg->cmnd[4];
2507 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, 2475 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
2508 (1<<4), 0, 2476 (1<<4), 0,
@@ -2510,7 +2478,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2510 reply = do_request_sense(fsg, bh); 2478 reply = do_request_sense(fsg, bh);
2511 break; 2479 break;
2512 2480
2513 case SC_START_STOP_UNIT: 2481 case START_STOP:
2514 fsg->data_size_from_cmnd = 0; 2482 fsg->data_size_from_cmnd = 0;
2515 if ((reply = check_command(fsg, 6, DATA_DIR_NONE, 2483 if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
2516 (1<<1) | (1<<4), 0, 2484 (1<<1) | (1<<4), 0,
@@ -2518,7 +2486,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2518 reply = do_start_stop(fsg); 2486 reply = do_start_stop(fsg);
2519 break; 2487 break;
2520 2488
2521 case SC_SYNCHRONIZE_CACHE: 2489 case SYNCHRONIZE_CACHE:
2522 fsg->data_size_from_cmnd = 0; 2490 fsg->data_size_from_cmnd = 0;
2523 if ((reply = check_command(fsg, 10, DATA_DIR_NONE, 2491 if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
2524 (0xf<<2) | (3<<7), 1, 2492 (0xf<<2) | (3<<7), 1,
@@ -2526,7 +2494,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2526 reply = do_synchronize_cache(fsg); 2494 reply = do_synchronize_cache(fsg);
2527 break; 2495 break;
2528 2496
2529 case SC_TEST_UNIT_READY: 2497 case TEST_UNIT_READY:
2530 fsg->data_size_from_cmnd = 0; 2498 fsg->data_size_from_cmnd = 0;
2531 reply = check_command(fsg, 6, DATA_DIR_NONE, 2499 reply = check_command(fsg, 6, DATA_DIR_NONE,
2532 0, 1, 2500 0, 1,
@@ -2535,7 +2503,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2535 2503
2536 /* Although optional, this command is used by MS-Windows. We 2504 /* Although optional, this command is used by MS-Windows. We
2537 * support a minimal version: BytChk must be 0. */ 2505 * support a minimal version: BytChk must be 0. */
2538 case SC_VERIFY: 2506 case VERIFY:
2539 fsg->data_size_from_cmnd = 0; 2507 fsg->data_size_from_cmnd = 0;
2540 if ((reply = check_command(fsg, 10, DATA_DIR_NONE, 2508 if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
2541 (1<<1) | (0xf<<2) | (3<<7), 1, 2509 (1<<1) | (0xf<<2) | (3<<7), 1,
@@ -2543,7 +2511,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2543 reply = do_verify(fsg); 2511 reply = do_verify(fsg);
2544 break; 2512 break;
2545 2513
2546 case SC_WRITE_6: 2514 case WRITE_6:
2547 i = fsg->cmnd[4]; 2515 i = fsg->cmnd[4];
2548 fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; 2516 fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
2549 if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST, 2517 if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
@@ -2552,7 +2520,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2552 reply = do_write(fsg); 2520 reply = do_write(fsg);
2553 break; 2521 break;
2554 2522
2555 case SC_WRITE_10: 2523 case WRITE_10:
2556 fsg->data_size_from_cmnd = 2524 fsg->data_size_from_cmnd =
2557 get_unaligned_be16(&fsg->cmnd[7]) << 9; 2525 get_unaligned_be16(&fsg->cmnd[7]) << 9;
2558 if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST, 2526 if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
@@ -2561,7 +2529,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2561 reply = do_write(fsg); 2529 reply = do_write(fsg);
2562 break; 2530 break;
2563 2531
2564 case SC_WRITE_12: 2532 case WRITE_12:
2565 fsg->data_size_from_cmnd = 2533 fsg->data_size_from_cmnd =
2566 get_unaligned_be32(&fsg->cmnd[6]) << 9; 2534 get_unaligned_be32(&fsg->cmnd[6]) << 9;
2567 if ((reply = check_command(fsg, 12, DATA_DIR_FROM_HOST, 2535 if ((reply = check_command(fsg, 12, DATA_DIR_FROM_HOST,
@@ -2574,10 +2542,10 @@ static int do_scsi_command(struct fsg_dev *fsg)
2574 * They don't mean much in this setting. It's left as an exercise 2542 * They don't mean much in this setting. It's left as an exercise
2575 * for anyone interested to implement RESERVE and RELEASE in terms 2543 * for anyone interested to implement RESERVE and RELEASE in terms
2576 * of Posix locks. */ 2544 * of Posix locks. */
2577 case SC_FORMAT_UNIT: 2545 case FORMAT_UNIT:
2578 case SC_RELEASE: 2546 case RELEASE:
2579 case SC_RESERVE: 2547 case RESERVE:
2580 case SC_SEND_DIAGNOSTIC: 2548 case SEND_DIAGNOSTIC:
2581 // Fall through 2549 // Fall through
2582 2550
2583 default: 2551 default:
@@ -3178,6 +3146,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3178 for (i = 0; i < fsg->nluns; ++i) { 3146 for (i = 0; i < fsg->nluns; ++i) {
3179 curlun = &fsg->luns[i]; 3147 curlun = &fsg->luns[i];
3180 if (curlun->registered) { 3148 if (curlun->registered) {
3149 device_remove_file(&curlun->dev, &dev_attr_nofua);
3181 device_remove_file(&curlun->dev, &dev_attr_ro); 3150 device_remove_file(&curlun->dev, &dev_attr_ro);
3182 device_remove_file(&curlun->dev, &dev_attr_file); 3151 device_remove_file(&curlun->dev, &dev_attr_file);
3183 fsg_lun_close(curlun); 3152 fsg_lun_close(curlun);
@@ -3213,7 +3182,6 @@ static int __init check_parameters(struct fsg_dev *fsg)
3213{ 3182{
3214 int prot; 3183 int prot;
3215 int gcnum; 3184 int gcnum;
3216 int i;
3217 3185
3218 /* Store the default values */ 3186 /* Store the default values */
3219 mod_data.transport_type = USB_PR_BULK; 3187 mod_data.transport_type = USB_PR_BULK;
@@ -3309,45 +3277,29 @@ static int __init check_parameters(struct fsg_dev *fsg)
3309 if ((*ch < '0' || *ch > '9') && 3277 if ((*ch < '0' || *ch > '9') &&
3310 (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */ 3278 (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
3311 WARNING(fsg, 3279 WARNING(fsg,
3312 "Invalid serial string character: %c; " 3280 "Invalid serial string character: %c\n",
3313 "Failing back to default\n",
3314 *ch); 3281 *ch);
3315 goto fill_serial; 3282 goto no_serial;
3316 } 3283 }
3317 } 3284 }
3318 if (len > 126 || 3285 if (len > 126 ||
3319 (mod_data.transport_type == USB_PR_BULK && len < 12) || 3286 (mod_data.transport_type == USB_PR_BULK && len < 12) ||
3320 (mod_data.transport_type != USB_PR_BULK && len > 12)) { 3287 (mod_data.transport_type != USB_PR_BULK && len > 12)) {
3321 WARNING(fsg, 3288 WARNING(fsg, "Invalid serial string length!\n");
3322 "Invalid serial string length; " 3289 goto no_serial;
3323 "Failing back to default\n");
3324 goto fill_serial;
3325 } 3290 }
3326 fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial; 3291 fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
3327 } else { 3292 } else {
3328 WARNING(fsg, 3293 WARNING(fsg, "No serial-number string provided!\n");
3329 "Userspace failed to provide serial number; " 3294 no_serial:
3330 "Failing back to default\n"); 3295 device_desc.iSerialNumber = 0;
3331fill_serial:
3332 /* Serial number not specified or invalid, make our own.
3333 * We just encode it from the driver version string,
3334 * 12 characters to comply with both CB[I] and BBB spec.
3335 * Warning : Two devices running the same kernel will have
3336 * the same fallback serial number. */
3337 for (i = 0; i < 12; i += 2) {
3338 unsigned char c = DRIVER_VERSION[i / 2];
3339
3340 if (!c)
3341 break;
3342 sprintf(&fsg_string_serial[i], "%02X", c);
3343 }
3344 } 3296 }
3345 3297
3346 return 0; 3298 return 0;
3347} 3299}
3348 3300
3349 3301
3350static int __ref fsg_bind(struct usb_gadget *gadget) 3302static int __init fsg_bind(struct usb_gadget *gadget)
3351{ 3303{
3352 struct fsg_dev *fsg = the_fsg; 3304 struct fsg_dev *fsg = the_fsg;
3353 int rc; 3305 int rc;
@@ -3411,25 +3363,28 @@ static int __ref fsg_bind(struct usb_gadget *gadget)
3411 dev_set_name(&curlun->dev,"%s-lun%d", 3363 dev_set_name(&curlun->dev,"%s-lun%d",
3412 dev_name(&gadget->dev), i); 3364 dev_name(&gadget->dev), i);
3413 3365
3414 if ((rc = device_register(&curlun->dev)) != 0) { 3366 kref_get(&fsg->ref);
3367 rc = device_register(&curlun->dev);
3368 if (rc) {
3415 INFO(fsg, "failed to register LUN%d: %d\n", i, rc); 3369 INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
3416 goto out; 3370 put_device(&curlun->dev);
3417 }
3418 if ((rc = device_create_file(&curlun->dev,
3419 &dev_attr_ro)) != 0 ||
3420 (rc = device_create_file(&curlun->dev,
3421 &dev_attr_nofua)) != 0 ||
3422 (rc = device_create_file(&curlun->dev,
3423 &dev_attr_file)) != 0) {
3424 device_unregister(&curlun->dev);
3425 goto out; 3371 goto out;
3426 } 3372 }
3427 curlun->registered = 1; 3373 curlun->registered = 1;
3428 kref_get(&fsg->ref); 3374
3375 rc = device_create_file(&curlun->dev, &dev_attr_ro);
3376 if (rc)
3377 goto out;
3378 rc = device_create_file(&curlun->dev, &dev_attr_nofua);
3379 if (rc)
3380 goto out;
3381 rc = device_create_file(&curlun->dev, &dev_attr_file);
3382 if (rc)
3383 goto out;
3429 3384
3430 if (mod_data.file[i] && *mod_data.file[i]) { 3385 if (mod_data.file[i] && *mod_data.file[i]) {
3431 if ((rc = fsg_lun_open(curlun, 3386 rc = fsg_lun_open(curlun, mod_data.file[i]);
3432 mod_data.file[i])) != 0) 3387 if (rc)
3433 goto out; 3388 goto out;
3434 } else if (!mod_data.removable) { 3389 } else if (!mod_data.removable) {
3435 ERROR(fsg, "no file given for LUN%d\n", i); 3390 ERROR(fsg, "no file given for LUN%d\n", i);
@@ -3607,7 +3562,6 @@ static struct usb_gadget_driver fsg_driver = {
3607 .speed = USB_SPEED_FULL, 3562 .speed = USB_SPEED_FULL,
3608#endif 3563#endif
3609 .function = (char *) fsg_string_product, 3564 .function = (char *) fsg_string_product,
3610 .bind = fsg_bind,
3611 .unbind = fsg_unbind, 3565 .unbind = fsg_unbind,
3612 .disconnect = fsg_disconnect, 3566 .disconnect = fsg_disconnect,
3613 .setup = fsg_setup, 3567 .setup = fsg_setup,
@@ -3649,7 +3603,7 @@ static int __init fsg_init(void)
3649 if ((rc = fsg_alloc()) != 0) 3603 if ((rc = fsg_alloc()) != 0)
3650 return rc; 3604 return rc;
3651 fsg = the_fsg; 3605 fsg = the_fsg;
3652 if ((rc = usb_gadget_register_driver(&fsg_driver)) != 0) 3606 if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
3653 kref_put(&fsg->ref, fsg_release); 3607 kref_put(&fsg->ref, fsg_release);
3654 return rc; 3608 return rc;
3655} 3609}
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c
index eafa6d2c5ed7..43a49ecc1f36 100644
--- a/drivers/usb/gadget/fsl_mxc_udc.c
+++ b/drivers/usb/gadget/fsl_mxc_udc.c
@@ -22,6 +22,10 @@
22static struct clk *mxc_ahb_clk; 22static struct clk *mxc_ahb_clk;
23static struct clk *mxc_usb_clk; 23static struct clk *mxc_usb_clk;
24 24
25/* workaround ENGcm09152 for i.MX35 */
26#define USBPHYCTRL_OTGBASE_OFFSET 0x608
27#define USBPHYCTRL_EVDO (1 << 23)
28
25int fsl_udc_clk_init(struct platform_device *pdev) 29int fsl_udc_clk_init(struct platform_device *pdev)
26{ 30{
27 struct fsl_usb2_platform_data *pdata; 31 struct fsl_usb2_platform_data *pdata;
@@ -84,6 +88,20 @@ eenahb:
84void fsl_udc_clk_finalize(struct platform_device *pdev) 88void fsl_udc_clk_finalize(struct platform_device *pdev)
85{ 89{
86 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 90 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
91#if defined(CONFIG_SOC_IMX35)
92 if (cpu_is_mx35()) {
93 unsigned int v;
94
95 /* workaround ENGcm09152 for i.MX35 */
96 if (pdata->workaround & FLS_USB2_WORKAROUND_ENGCM09152) {
97 v = readl(MX35_IO_ADDRESS(MX35_USB_BASE_ADDR +
98 USBPHYCTRL_OTGBASE_OFFSET));
99 writel(v | USBPHYCTRL_EVDO,
100 MX35_IO_ADDRESS(MX35_USB_BASE_ADDR +
101 USBPHYCTRL_OTGBASE_OFFSET));
102 }
103 }
104#endif
87 105
88 /* ULPI transceivers don't need usbpll */ 106 /* ULPI transceivers don't need usbpll */
89 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) { 107 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index a5ea2c1d8c93..3a68e09309f7 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -1148,6 +1148,12 @@ static int qe_ep_tx(struct qe_ep *ep, struct qe_frame *frame)
1148static int txcomplete(struct qe_ep *ep, unsigned char restart) 1148static int txcomplete(struct qe_ep *ep, unsigned char restart)
1149{ 1149{
1150 if (ep->tx_req != NULL) { 1150 if (ep->tx_req != NULL) {
1151 struct qe_req *req = ep->tx_req;
1152 unsigned zlp = 0, last_len = 0;
1153
1154 last_len = min_t(unsigned, req->req.length - ep->sent,
1155 ep->ep.maxpacket);
1156
1151 if (!restart) { 1157 if (!restart) {
1152 int asent = ep->last; 1158 int asent = ep->last;
1153 ep->sent += asent; 1159 ep->sent += asent;
@@ -1156,9 +1162,18 @@ static int txcomplete(struct qe_ep *ep, unsigned char restart)
1156 ep->last = 0; 1162 ep->last = 0;
1157 } 1163 }
1158 1164
1165 /* zlp needed when req->re.zero is set */
1166 if (req->req.zero) {
1167 if (last_len == 0 ||
1168 (req->req.length % ep->ep.maxpacket) != 0)
1169 zlp = 0;
1170 else
1171 zlp = 1;
1172 } else
1173 zlp = 0;
1174
1159 /* a request already were transmitted completely */ 1175 /* a request already were transmitted completely */
1160 if ((ep->tx_req->req.length - ep->sent) <= 0) { 1176 if (((ep->tx_req->req.length - ep->sent) <= 0) && !zlp) {
1161 ep->tx_req->req.actual = (unsigned int)ep->sent;
1162 done(ep, ep->tx_req, 0); 1177 done(ep, ep->tx_req, 0);
1163 ep->tx_req = NULL; 1178 ep->tx_req = NULL;
1164 ep->last = 0; 1179 ep->last = 0;
@@ -1191,6 +1206,7 @@ static int qe_usb_senddata(struct qe_ep *ep, struct qe_frame *frame)
1191 buf = (u8 *)ep->tx_req->req.buf + ep->sent; 1206 buf = (u8 *)ep->tx_req->req.buf + ep->sent;
1192 if (buf && size) { 1207 if (buf && size) {
1193 ep->last = size; 1208 ep->last = size;
1209 ep->tx_req->req.actual += size;
1194 frame_set_data(frame, buf); 1210 frame_set_data(frame, buf);
1195 frame_set_length(frame, size); 1211 frame_set_length(frame, size);
1196 frame_set_status(frame, FRAME_OK); 1212 frame_set_status(frame, FRAME_OK);
@@ -2302,9 +2318,10 @@ static irqreturn_t qe_udc_irq(int irq, void *_udc)
2302} 2318}
2303 2319
2304/*------------------------------------------------------------------------- 2320/*-------------------------------------------------------------------------
2305 Gadget driver register and unregister. 2321 Gadget driver probe and unregister.
2306 --------------------------------------------------------------------------*/ 2322 --------------------------------------------------------------------------*/
2307int usb_gadget_register_driver(struct usb_gadget_driver *driver) 2323int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2324 int (*bind)(struct usb_gadget *))
2308{ 2325{
2309 int retval; 2326 int retval;
2310 unsigned long flags = 0; 2327 unsigned long flags = 0;
@@ -2315,8 +2332,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2315 2332
2316 if (!driver || (driver->speed != USB_SPEED_FULL 2333 if (!driver || (driver->speed != USB_SPEED_FULL
2317 && driver->speed != USB_SPEED_HIGH) 2334 && driver->speed != USB_SPEED_HIGH)
2318 || !driver->bind || !driver->disconnect 2335 || !bind || !driver->disconnect || !driver->setup)
2319 || !driver->setup)
2320 return -EINVAL; 2336 return -EINVAL;
2321 2337
2322 if (udc_controller->driver) 2338 if (udc_controller->driver)
@@ -2332,7 +2348,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2332 udc_controller->gadget.speed = (enum usb_device_speed)(driver->speed); 2348 udc_controller->gadget.speed = (enum usb_device_speed)(driver->speed);
2333 spin_unlock_irqrestore(&udc_controller->lock, flags); 2349 spin_unlock_irqrestore(&udc_controller->lock, flags);
2334 2350
2335 retval = driver->bind(&udc_controller->gadget); 2351 retval = bind(&udc_controller->gadget);
2336 if (retval) { 2352 if (retval) {
2337 dev_err(udc_controller->dev, "bind to %s --> %d", 2353 dev_err(udc_controller->dev, "bind to %s --> %d",
2338 driver->driver.name, retval); 2354 driver->driver.name, retval);
@@ -2353,7 +2369,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2353 udc_controller->gadget.name, driver->driver.name); 2369 udc_controller->gadget.name, driver->driver.name);
2354 return 0; 2370 return 0;
2355} 2371}
2356EXPORT_SYMBOL(usb_gadget_register_driver); 2372EXPORT_SYMBOL(usb_gadget_probe_driver);
2357 2373
2358int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2374int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2359{ 2375{
@@ -2523,15 +2539,20 @@ static void qe_udc_release(struct device *dev)
2523} 2539}
2524 2540
2525/* Driver probe functions */ 2541/* Driver probe functions */
2526static int __devinit qe_udc_probe(struct platform_device *ofdev, 2542static const struct of_device_id qe_udc_match[];
2527 const struct of_device_id *match) 2543static int __devinit qe_udc_probe(struct platform_device *ofdev)
2528{ 2544{
2545 const struct of_device_id *match;
2529 struct device_node *np = ofdev->dev.of_node; 2546 struct device_node *np = ofdev->dev.of_node;
2530 struct qe_ep *ep; 2547 struct qe_ep *ep;
2531 unsigned int ret = 0; 2548 unsigned int ret = 0;
2532 unsigned int i; 2549 unsigned int i;
2533 const void *prop; 2550 const void *prop;
2534 2551
2552 match = of_match_device(qe_udc_match, &ofdev->dev);
2553 if (!match)
2554 return -EINVAL;
2555
2535 prop = of_get_property(np, "mode", NULL); 2556 prop = of_get_property(np, "mode", NULL);
2536 if (!prop || strcmp(prop, "peripheral")) 2557 if (!prop || strcmp(prop, "peripheral"))
2537 return -ENODEV; 2558 return -ENODEV;
@@ -2768,7 +2789,7 @@ static const struct of_device_id qe_udc_match[] __devinitconst = {
2768 2789
2769MODULE_DEVICE_TABLE(of, qe_udc_match); 2790MODULE_DEVICE_TABLE(of, qe_udc_match);
2770 2791
2771static struct of_platform_driver udc_driver = { 2792static struct platform_driver udc_driver = {
2772 .driver = { 2793 .driver = {
2773 .name = (char *)driver_name, 2794 .name = (char *)driver_name,
2774 .owner = THIS_MODULE, 2795 .owner = THIS_MODULE,
@@ -2786,12 +2807,12 @@ static int __init qe_udc_init(void)
2786{ 2807{
2787 printk(KERN_INFO "%s: %s, %s\n", driver_name, driver_desc, 2808 printk(KERN_INFO "%s: %s, %s\n", driver_name, driver_desc,
2788 DRIVER_VERSION); 2809 DRIVER_VERSION);
2789 return of_register_platform_driver(&udc_driver); 2810 return platform_driver_register(&udc_driver);
2790} 2811}
2791 2812
2792static void __exit qe_udc_exit(void) 2813static void __exit qe_udc_exit(void)
2793{ 2814{
2794 of_unregister_platform_driver(&udc_driver); 2815 platform_driver_unregister(&udc_driver);
2795} 2816}
2796 2817
2797module_init(qe_udc_init); 2818module_init(qe_udc_init);
diff --git a/drivers/usb/gadget/fsl_qe_udc.h b/drivers/usb/gadget/fsl_qe_udc.h
index bea5b827bebe..1da5fb03d218 100644
--- a/drivers/usb/gadget/fsl_qe_udc.h
+++ b/drivers/usb/gadget/fsl_qe_udc.h
@@ -207,15 +207,15 @@ struct qe_frame{
207 207
208/* Frame status field */ 208/* Frame status field */
209/* Receive side */ 209/* Receive side */
210#define FRAME_OK 0x00000000 /* Frame tranmitted or received OK */ 210#define FRAME_OK 0x00000000 /* Frame transmitted or received OK */
211#define FRAME_ERROR 0x80000000 /* Error occured on frame */ 211#define FRAME_ERROR 0x80000000 /* Error occurred on frame */
212#define START_FRAME_LOST 0x40000000 /* START_FRAME_LOST */ 212#define START_FRAME_LOST 0x40000000 /* START_FRAME_LOST */
213#define END_FRAME_LOST 0x20000000 /* END_FRAME_LOST */ 213#define END_FRAME_LOST 0x20000000 /* END_FRAME_LOST */
214#define RX_ER_NONOCT 0x10000000 /* Rx Non Octet Aligned Packet */ 214#define RX_ER_NONOCT 0x10000000 /* Rx Non Octet Aligned Packet */
215#define RX_ER_BITSTUFF 0x08000000 /* Frame Aborted --Received packet 215#define RX_ER_BITSTUFF 0x08000000 /* Frame Aborted --Received packet
216 with bit stuff error */ 216 with bit stuff error */
217#define RX_ER_CRC 0x04000000 /* Received packet with CRC error */ 217#define RX_ER_CRC 0x04000000 /* Received packet with CRC error */
218#define RX_ER_OVERUN 0x02000000 /* Over-run occured on reception */ 218#define RX_ER_OVERUN 0x02000000 /* Over-run occurred on reception */
219#define RX_ER_PID 0x01000000 /* Wrong PID received */ 219#define RX_ER_PID 0x01000000 /* Wrong PID received */
220/* Tranmit side */ 220/* Tranmit side */
221#define TX_ER_NAK 0x00800000 /* Received NAK handshake */ 221#define TX_ER_NAK 0x00800000 /* Received NAK handshake */
@@ -379,7 +379,7 @@ struct qe_udc {
379#define T_LSP 0x01000000 /* Low-speed transaction */ 379#define T_LSP 0x01000000 /* Low-speed transaction */
380#define T_PID 0x00c00000 /* packet id */ 380#define T_PID 0x00c00000 /* packet id */
381#define T_NAK 0x00100000 /* No ack. */ 381#define T_NAK 0x00100000 /* No ack. */
382#define T_STAL 0x00080000 /* Stall recieved */ 382#define T_STAL 0x00080000 /* Stall received */
383#define T_TO 0x00040000 /* time out */ 383#define T_TO 0x00040000 /* time out */
384#define T_UN 0x00020000 /* underrun */ 384#define T_UN 0x00020000 /* underrun */
385 385
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 08a9a62a39e3..4e4833168087 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -1,12 +1,13 @@
1/* 1/*
2 * Copyright (C) 2004-2007 Freescale Semicondutor, Inc. All rights reserved. 2 * Copyright (C) 2004-2007,2011 Freescale Semiconductor, Inc.
3 * All rights reserved.
3 * 4 *
4 * Author: Li Yang <leoli@freescale.com> 5 * Author: Li Yang <leoli@freescale.com>
5 * Jiang Bo <tanya.jiang@freescale.com> 6 * Jiang Bo <tanya.jiang@freescale.com>
6 * 7 *
7 * Description: 8 * Description:
8 * Freescale high-speed USB SOC DR module device controller driver. 9 * Freescale high-speed USB SOC DR module device controller driver.
9 * This can be found on MPC8349E/MPC8313E cpus. 10 * This can be found on MPC8349E/MPC8313E/MPC5121E cpus.
10 * The driver is previously named as mpc_udc. Based on bare board 11 * The driver is previously named as mpc_udc. Based on bare board
11 * code from Dave Liu and Shlomi Gridish. 12 * code from Dave Liu and Shlomi Gridish.
12 * 13 *
@@ -77,12 +78,77 @@ fsl_ep0_desc = {
77static void fsl_ep_fifo_flush(struct usb_ep *_ep); 78static void fsl_ep_fifo_flush(struct usb_ep *_ep);
78 79
79#ifdef CONFIG_PPC32 80#ifdef CONFIG_PPC32
80#define fsl_readl(addr) in_le32(addr) 81/*
81#define fsl_writel(val32, addr) out_le32(addr, val32) 82 * On some SoCs, the USB controller registers can be big or little endian,
82#else 83 * depending on the version of the chip. In order to be able to run the
84 * same kernel binary on 2 different versions of an SoC, the BE/LE decision
85 * must be made at run time. _fsl_readl and fsl_writel are pointers to the
86 * BE or LE readl() and writel() functions, and fsl_readl() and fsl_writel()
87 * call through those pointers. Platform code for SoCs that have BE USB
88 * registers should set pdata->big_endian_mmio flag.
89 *
90 * This also applies to controller-to-cpu accessors for the USB descriptors,
91 * since their endianness is also SoC dependant. Platform code for SoCs that
92 * have BE USB descriptors should set pdata->big_endian_desc flag.
93 */
94static u32 _fsl_readl_be(const unsigned __iomem *p)
95{
96 return in_be32(p);
97}
98
99static u32 _fsl_readl_le(const unsigned __iomem *p)
100{
101 return in_le32(p);
102}
103
104static void _fsl_writel_be(u32 v, unsigned __iomem *p)
105{
106 out_be32(p, v);
107}
108
109static void _fsl_writel_le(u32 v, unsigned __iomem *p)
110{
111 out_le32(p, v);
112}
113
114static u32 (*_fsl_readl)(const unsigned __iomem *p);
115static void (*_fsl_writel)(u32 v, unsigned __iomem *p);
116
117#define fsl_readl(p) (*_fsl_readl)((p))
118#define fsl_writel(v, p) (*_fsl_writel)((v), (p))
119
120static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata)
121{
122 if (pdata->big_endian_mmio) {
123 _fsl_readl = _fsl_readl_be;
124 _fsl_writel = _fsl_writel_be;
125 } else {
126 _fsl_readl = _fsl_readl_le;
127 _fsl_writel = _fsl_writel_le;
128 }
129}
130
131static inline u32 cpu_to_hc32(const u32 x)
132{
133 return udc_controller->pdata->big_endian_desc
134 ? (__force u32)cpu_to_be32(x)
135 : (__force u32)cpu_to_le32(x);
136}
137
138static inline u32 hc32_to_cpu(const u32 x)
139{
140 return udc_controller->pdata->big_endian_desc
141 ? be32_to_cpu((__force __be32)x)
142 : le32_to_cpu((__force __le32)x);
143}
144#else /* !CONFIG_PPC32 */
145static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata) {}
146
83#define fsl_readl(addr) readl(addr) 147#define fsl_readl(addr) readl(addr)
84#define fsl_writel(val32, addr) writel(val32, addr) 148#define fsl_writel(val32, addr) writel(val32, addr)
85#endif 149#define cpu_to_hc32(x) cpu_to_le32(x)
150#define hc32_to_cpu(x) le32_to_cpu(x)
151#endif /* CONFIG_PPC32 */
86 152
87/******************************************************************** 153/********************************************************************
88 * Internal Used Function 154 * Internal Used Function
@@ -177,7 +243,8 @@ static void nuke(struct fsl_ep *ep, int status)
177 243
178static int dr_controller_setup(struct fsl_udc *udc) 244static int dr_controller_setup(struct fsl_udc *udc)
179{ 245{
180 unsigned int tmp, portctrl; 246 unsigned int tmp, portctrl, ep_num;
247 unsigned int max_no_of_ep;
181#ifndef CONFIG_ARCH_MXC 248#ifndef CONFIG_ARCH_MXC
182 unsigned int ctrl; 249 unsigned int ctrl;
183#endif 250#endif
@@ -226,9 +293,12 @@ static int dr_controller_setup(struct fsl_udc *udc)
226 293
227 /* Set the controller as device mode */ 294 /* Set the controller as device mode */
228 tmp = fsl_readl(&dr_regs->usbmode); 295 tmp = fsl_readl(&dr_regs->usbmode);
296 tmp &= ~USB_MODE_CTRL_MODE_MASK; /* clear mode bits */
229 tmp |= USB_MODE_CTRL_MODE_DEVICE; 297 tmp |= USB_MODE_CTRL_MODE_DEVICE;
230 /* Disable Setup Lockout */ 298 /* Disable Setup Lockout */
231 tmp |= USB_MODE_SETUP_LOCK_OFF; 299 tmp |= USB_MODE_SETUP_LOCK_OFF;
300 if (udc->pdata->es)
301 tmp |= USB_MODE_ES;
232 fsl_writel(tmp, &dr_regs->usbmode); 302 fsl_writel(tmp, &dr_regs->usbmode);
233 303
234 /* Clear the setup status */ 304 /* Clear the setup status */
@@ -242,22 +312,34 @@ static int dr_controller_setup(struct fsl_udc *udc)
242 udc->ep_qh, (int)tmp, 312 udc->ep_qh, (int)tmp,
243 fsl_readl(&dr_regs->endpointlistaddr)); 313 fsl_readl(&dr_regs->endpointlistaddr));
244 314
315 max_no_of_ep = (0x0000001F & fsl_readl(&dr_regs->dccparams));
316 for (ep_num = 1; ep_num < max_no_of_ep; ep_num++) {
317 tmp = fsl_readl(&dr_regs->endptctrl[ep_num]);
318 tmp &= ~(EPCTRL_TX_TYPE | EPCTRL_RX_TYPE);
319 tmp |= (EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT)
320 | (EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT);
321 fsl_writel(tmp, &dr_regs->endptctrl[ep_num]);
322 }
245 /* Config control enable i/o output, cpu endian register */ 323 /* Config control enable i/o output, cpu endian register */
246#ifndef CONFIG_ARCH_MXC 324#ifndef CONFIG_ARCH_MXC
247 ctrl = __raw_readl(&usb_sys_regs->control); 325 if (udc->pdata->have_sysif_regs) {
248 ctrl |= USB_CTRL_IOENB; 326 ctrl = __raw_readl(&usb_sys_regs->control);
249 __raw_writel(ctrl, &usb_sys_regs->control); 327 ctrl |= USB_CTRL_IOENB;
328 __raw_writel(ctrl, &usb_sys_regs->control);
329 }
250#endif 330#endif
251 331
252#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) 332#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
253 /* Turn on cache snooping hardware, since some PowerPC platforms 333 /* Turn on cache snooping hardware, since some PowerPC platforms
254 * wholly rely on hardware to deal with cache coherent. */ 334 * wholly rely on hardware to deal with cache coherent. */
255 335
256 /* Setup Snooping for all the 4GB space */ 336 if (udc->pdata->have_sysif_regs) {
257 tmp = SNOOP_SIZE_2GB; /* starts from 0x0, size 2G */ 337 /* Setup Snooping for all the 4GB space */
258 __raw_writel(tmp, &usb_sys_regs->snoop1); 338 tmp = SNOOP_SIZE_2GB; /* starts from 0x0, size 2G */
259 tmp |= 0x80000000; /* starts from 0x8000000, size 2G */ 339 __raw_writel(tmp, &usb_sys_regs->snoop1);
260 __raw_writel(tmp, &usb_sys_regs->snoop2); 340 tmp |= 0x80000000; /* starts from 0x8000000, size 2G */
341 __raw_writel(tmp, &usb_sys_regs->snoop2);
342 }
261#endif 343#endif
262 344
263 return 0; 345 return 0;
@@ -287,14 +369,25 @@ static void dr_controller_run(struct fsl_udc *udc)
287 temp = fsl_readl(&dr_regs->usbcmd); 369 temp = fsl_readl(&dr_regs->usbcmd);
288 temp |= USB_CMD_RUN_STOP; 370 temp |= USB_CMD_RUN_STOP;
289 fsl_writel(temp, &dr_regs->usbcmd); 371 fsl_writel(temp, &dr_regs->usbcmd);
290
291 return;
292} 372}
293 373
294static void dr_controller_stop(struct fsl_udc *udc) 374static void dr_controller_stop(struct fsl_udc *udc)
295{ 375{
296 unsigned int tmp; 376 unsigned int tmp;
297 377
378 pr_debug("%s\n", __func__);
379
380 /* if we're in OTG mode, and the Host is currently using the port,
381 * stop now and don't rip the controller out from under the
382 * ehci driver
383 */
384 if (udc->gadget.is_otg) {
385 if (!(fsl_readl(&dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
386 pr_debug("udc: Leaving early\n");
387 return;
388 }
389 }
390
298 /* disable all INTR */ 391 /* disable all INTR */
299 fsl_writel(0, &dr_regs->usbintr); 392 fsl_writel(0, &dr_regs->usbintr);
300 393
@@ -308,8 +401,6 @@ static void dr_controller_stop(struct fsl_udc *udc)
308 tmp = fsl_readl(&dr_regs->usbcmd); 401 tmp = fsl_readl(&dr_regs->usbcmd);
309 tmp &= ~USB_CMD_RUN_STOP; 402 tmp &= ~USB_CMD_RUN_STOP;
310 fsl_writel(tmp, &dr_regs->usbcmd); 403 fsl_writel(tmp, &dr_regs->usbcmd);
311
312 return;
313} 404}
314 405
315static void dr_ep_setup(unsigned char ep_num, unsigned char dir, 406static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
@@ -322,12 +413,14 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
322 if (ep_num) 413 if (ep_num)
323 tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST; 414 tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST;
324 tmp_epctrl |= EPCTRL_TX_ENABLE; 415 tmp_epctrl |= EPCTRL_TX_ENABLE;
416 tmp_epctrl &= ~EPCTRL_TX_TYPE;
325 tmp_epctrl |= ((unsigned int)(ep_type) 417 tmp_epctrl |= ((unsigned int)(ep_type)
326 << EPCTRL_TX_EP_TYPE_SHIFT); 418 << EPCTRL_TX_EP_TYPE_SHIFT);
327 } else { 419 } else {
328 if (ep_num) 420 if (ep_num)
329 tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST; 421 tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST;
330 tmp_epctrl |= EPCTRL_RX_ENABLE; 422 tmp_epctrl |= EPCTRL_RX_ENABLE;
423 tmp_epctrl &= ~EPCTRL_RX_TYPE;
331 tmp_epctrl |= ((unsigned int)(ep_type) 424 tmp_epctrl |= ((unsigned int)(ep_type)
332 << EPCTRL_RX_EP_TYPE_SHIFT); 425 << EPCTRL_RX_EP_TYPE_SHIFT);
333 } 426 }
@@ -413,11 +506,9 @@ static void struct_ep_qh_setup(struct fsl_udc *udc, unsigned char ep_num,
413 if (zlt) 506 if (zlt)
414 tmp |= EP_QUEUE_HEAD_ZLT_SEL; 507 tmp |= EP_QUEUE_HEAD_ZLT_SEL;
415 508
416 p_QH->max_pkt_length = cpu_to_le32(tmp); 509 p_QH->max_pkt_length = cpu_to_hc32(tmp);
417 p_QH->next_dtd_ptr = 1; 510 p_QH->next_dtd_ptr = 1;
418 p_QH->size_ioc_int_sts = 0; 511 p_QH->size_ioc_int_sts = 0;
419
420 return;
421} 512}
422 513
423/* Setup qh structure and ep register for ep0. */ 514/* Setup qh structure and ep register for ep0. */
@@ -470,7 +561,7 @@ static int fsl_ep_enable(struct usb_ep *_ep,
470 561
471 max = le16_to_cpu(desc->wMaxPacketSize); 562 max = le16_to_cpu(desc->wMaxPacketSize);
472 563
473 /* Disable automatic zlp generation. Driver is reponsible to indicate 564 /* Disable automatic zlp generation. Driver is responsible to indicate
474 * explicitly through req->req.zero. This is needed to enable multi-td 565 * explicitly through req->req.zero. This is needed to enable multi-td
475 * request. */ 566 * request. */
476 zlt = 1; 567 zlt = 1;
@@ -552,10 +643,13 @@ static int fsl_ep_disable(struct usb_ep *_ep)
552 /* disable ep on controller */ 643 /* disable ep on controller */
553 ep_num = ep_index(ep); 644 ep_num = ep_index(ep);
554 epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]); 645 epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
555 if (ep_is_in(ep)) 646 if (ep_is_in(ep)) {
556 epctrl &= ~EPCTRL_TX_ENABLE; 647 epctrl &= ~(EPCTRL_TX_ENABLE | EPCTRL_TX_TYPE);
557 else 648 epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT;
558 epctrl &= ~EPCTRL_RX_ENABLE; 649 } else {
650 epctrl &= ~(EPCTRL_RX_ENABLE | EPCTRL_TX_TYPE);
651 epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT;
652 }
559 fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]); 653 fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
560 654
561 udc = (struct fsl_udc *)ep->udc; 655 udc = (struct fsl_udc *)ep->udc;
@@ -622,7 +716,7 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
622 struct fsl_req *lastreq; 716 struct fsl_req *lastreq;
623 lastreq = list_entry(ep->queue.prev, struct fsl_req, queue); 717 lastreq = list_entry(ep->queue.prev, struct fsl_req, queue);
624 lastreq->tail->next_td_ptr = 718 lastreq->tail->next_td_ptr =
625 cpu_to_le32(req->head->td_dma & DTD_ADDR_MASK); 719 cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK);
626 /* Read prime bit, if 1 goto done */ 720 /* Read prime bit, if 1 goto done */
627 if (fsl_readl(&dr_regs->endpointprime) & bitmask) 721 if (fsl_readl(&dr_regs->endpointprime) & bitmask)
628 goto out; 722 goto out;
@@ -647,14 +741,14 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
647 741
648 /* Write dQH next pointer and terminate bit to 0 */ 742 /* Write dQH next pointer and terminate bit to 0 */
649 temp = req->head->td_dma & EP_QUEUE_HEAD_NEXT_POINTER_MASK; 743 temp = req->head->td_dma & EP_QUEUE_HEAD_NEXT_POINTER_MASK;
650 dQH->next_dtd_ptr = cpu_to_le32(temp); 744 dQH->next_dtd_ptr = cpu_to_hc32(temp);
651 745
652 /* Clear active and halt bit */ 746 /* Clear active and halt bit */
653 temp = cpu_to_le32(~(EP_QUEUE_HEAD_STATUS_ACTIVE 747 temp = cpu_to_hc32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
654 | EP_QUEUE_HEAD_STATUS_HALT)); 748 | EP_QUEUE_HEAD_STATUS_HALT));
655 dQH->size_ioc_int_sts &= temp; 749 dQH->size_ioc_int_sts &= temp;
656 750
657 /* Ensure that updates to the QH will occure before priming. */ 751 /* Ensure that updates to the QH will occur before priming. */
658 wmb(); 752 wmb();
659 753
660 /* Prime endpoint by writing 1 to ENDPTPRIME */ 754 /* Prime endpoint by writing 1 to ENDPTPRIME */
@@ -688,17 +782,17 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
688 782
689 dtd->td_dma = *dma; 783 dtd->td_dma = *dma;
690 /* Clear reserved field */ 784 /* Clear reserved field */
691 swap_temp = cpu_to_le32(dtd->size_ioc_sts); 785 swap_temp = hc32_to_cpu(dtd->size_ioc_sts);
692 swap_temp &= ~DTD_RESERVED_FIELDS; 786 swap_temp &= ~DTD_RESERVED_FIELDS;
693 dtd->size_ioc_sts = cpu_to_le32(swap_temp); 787 dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
694 788
695 /* Init all of buffer page pointers */ 789 /* Init all of buffer page pointers */
696 swap_temp = (u32) (req->req.dma + req->req.actual); 790 swap_temp = (u32) (req->req.dma + req->req.actual);
697 dtd->buff_ptr0 = cpu_to_le32(swap_temp); 791 dtd->buff_ptr0 = cpu_to_hc32(swap_temp);
698 dtd->buff_ptr1 = cpu_to_le32(swap_temp + 0x1000); 792 dtd->buff_ptr1 = cpu_to_hc32(swap_temp + 0x1000);
699 dtd->buff_ptr2 = cpu_to_le32(swap_temp + 0x2000); 793 dtd->buff_ptr2 = cpu_to_hc32(swap_temp + 0x2000);
700 dtd->buff_ptr3 = cpu_to_le32(swap_temp + 0x3000); 794 dtd->buff_ptr3 = cpu_to_hc32(swap_temp + 0x3000);
701 dtd->buff_ptr4 = cpu_to_le32(swap_temp + 0x4000); 795 dtd->buff_ptr4 = cpu_to_hc32(swap_temp + 0x4000);
702 796
703 req->req.actual += *length; 797 req->req.actual += *length;
704 798
@@ -722,7 +816,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
722 if (*is_last && !req->req.no_interrupt) 816 if (*is_last && !req->req.no_interrupt)
723 swap_temp |= DTD_IOC; 817 swap_temp |= DTD_IOC;
724 818
725 dtd->size_ioc_sts = cpu_to_le32(swap_temp); 819 dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
726 820
727 mb(); 821 mb();
728 822
@@ -749,7 +843,7 @@ static int fsl_req_to_dtd(struct fsl_req *req)
749 is_first = 0; 843 is_first = 0;
750 req->head = dtd; 844 req->head = dtd;
751 } else { 845 } else {
752 last_dtd->next_td_ptr = cpu_to_le32(dma); 846 last_dtd->next_td_ptr = cpu_to_hc32(dma);
753 last_dtd->next_td_virt = dtd; 847 last_dtd->next_td_virt = dtd;
754 } 848 }
755 last_dtd = dtd; 849 last_dtd = dtd;
@@ -757,7 +851,7 @@ static int fsl_req_to_dtd(struct fsl_req *req)
757 req->dtd_count++; 851 req->dtd_count++;
758 } while (!is_last); 852 } while (!is_last);
759 853
760 dtd->next_td_ptr = cpu_to_le32(DTD_NEXT_TERMINATE); 854 dtd->next_td_ptr = cpu_to_hc32(DTD_NEXT_TERMINATE);
761 855
762 req->tail = dtd; 856 req->tail = dtd;
763 857
@@ -772,7 +866,6 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
772 struct fsl_req *req = container_of(_req, struct fsl_req, req); 866 struct fsl_req *req = container_of(_req, struct fsl_req, req);
773 struct fsl_udc *udc; 867 struct fsl_udc *udc;
774 unsigned long flags; 868 unsigned long flags;
775 int is_iso = 0;
776 869
777 /* catch various bogus parameters */ 870 /* catch various bogus parameters */
778 if (!_req || !req->req.complete || !req->req.buf 871 if (!_req || !req->req.complete || !req->req.buf
@@ -787,7 +880,6 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
787 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 880 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
788 if (req->req.length > ep->ep.maxpacket) 881 if (req->req.length > ep->ep.maxpacket)
789 return -EMSGSIZE; 882 return -EMSGSIZE;
790 is_iso = 1;
791 } 883 }
792 884
793 udc = ep->udc; 885 udc = ep->udc;
@@ -970,6 +1062,36 @@ out:
970 return status; 1062 return status;
971} 1063}
972 1064
1065static int fsl_ep_fifo_status(struct usb_ep *_ep)
1066{
1067 struct fsl_ep *ep;
1068 struct fsl_udc *udc;
1069 int size = 0;
1070 u32 bitmask;
1071 struct ep_queue_head *d_qh;
1072
1073 ep = container_of(_ep, struct fsl_ep, ep);
1074 if (!_ep || (!ep->desc && ep_index(ep) != 0))
1075 return -ENODEV;
1076
1077 udc = (struct fsl_udc *)ep->udc;
1078
1079 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN)
1080 return -ESHUTDOWN;
1081
1082 d_qh = &ep->udc->ep_qh[ep_index(ep) * 2 + ep_is_in(ep)];
1083
1084 bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) :
1085 (1 << (ep_index(ep)));
1086
1087 if (fsl_readl(&dr_regs->endptstatus) & bitmask)
1088 size = (d_qh->size_ioc_int_sts & DTD_PACKET_SIZE)
1089 >> DTD_LENGTH_BIT_POS;
1090
1091 pr_debug("%s %u\n", __func__, size);
1092 return size;
1093}
1094
973static void fsl_ep_fifo_flush(struct usb_ep *_ep) 1095static void fsl_ep_fifo_flush(struct usb_ep *_ep)
974{ 1096{
975 struct fsl_ep *ep; 1097 struct fsl_ep *ep;
@@ -1022,6 +1144,7 @@ static struct usb_ep_ops fsl_ep_ops = {
1022 .dequeue = fsl_ep_dequeue, 1144 .dequeue = fsl_ep_dequeue,
1023 1145
1024 .set_halt = fsl_ep_set_halt, 1146 .set_halt = fsl_ep_set_halt,
1147 .fifo_status = fsl_ep_fifo_status,
1025 .fifo_flush = fsl_ep_fifo_flush, /* flush fifo */ 1148 .fifo_flush = fsl_ep_fifo_flush, /* flush fifo */
1026}; 1149};
1027 1150
@@ -1166,6 +1289,11 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
1166 req->req.complete = NULL; 1289 req->req.complete = NULL;
1167 req->dtd_count = 0; 1290 req->dtd_count = 0;
1168 1291
1292 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent,
1293 req->req.buf, req->req.length,
1294 ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
1295 req->mapped = 1;
1296
1169 if (fsl_req_to_dtd(req) == 0) 1297 if (fsl_req_to_dtd(req) == 0)
1170 fsl_queue_td(ep, req); 1298 fsl_queue_td(ep, req);
1171 else 1299 else
@@ -1236,6 +1364,7 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
1236 req = udc->status_req; 1364 req = udc->status_req;
1237 /* Fill in the reqest structure */ 1365 /* Fill in the reqest structure */
1238 *((u16 *) req->req.buf) = cpu_to_le16(tmp); 1366 *((u16 *) req->req.buf) = cpu_to_le16(tmp);
1367
1239 req->ep = ep; 1368 req->ep = ep;
1240 req->req.length = 2; 1369 req->req.length = 2;
1241 req->req.status = -EINPROGRESS; 1370 req->req.status = -EINPROGRESS;
@@ -1243,6 +1372,11 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
1243 req->req.complete = NULL; 1372 req->req.complete = NULL;
1244 req->dtd_count = 0; 1373 req->dtd_count = 0;
1245 1374
1375 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent,
1376 req->req.buf, req->req.length,
1377 ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
1378 req->mapped = 1;
1379
1246 /* prime the data phase */ 1380 /* prime the data phase */
1247 if ((fsl_req_to_dtd(req) == 0)) 1381 if ((fsl_req_to_dtd(req) == 0))
1248 fsl_queue_td(ep, req); 1382 fsl_queue_td(ep, req);
@@ -1288,6 +1422,7 @@ static void setup_received_irq(struct fsl_udc *udc,
1288 /* Status phase from udc */ 1422 /* Status phase from udc */
1289 { 1423 {
1290 int rc = -EOPNOTSUPP; 1424 int rc = -EOPNOTSUPP;
1425 u16 ptc = 0;
1291 1426
1292 if ((setup->bRequestType & (USB_RECIP_MASK | USB_TYPE_MASK)) 1427 if ((setup->bRequestType & (USB_RECIP_MASK | USB_TYPE_MASK))
1293 == (USB_RECIP_ENDPOINT | USB_TYPE_STANDARD)) { 1428 == (USB_RECIP_ENDPOINT | USB_TYPE_STANDARD)) {
@@ -1309,17 +1444,19 @@ static void setup_received_irq(struct fsl_udc *udc,
1309 | USB_TYPE_STANDARD)) { 1444 | USB_TYPE_STANDARD)) {
1310 /* Note: The driver has not include OTG support yet. 1445 /* Note: The driver has not include OTG support yet.
1311 * This will be set when OTG support is added */ 1446 * This will be set when OTG support is added */
1312 if (!gadget_is_otg(&udc->gadget)) 1447 if (wValue == USB_DEVICE_TEST_MODE)
1313 break; 1448 ptc = wIndex >> 8;
1314 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) 1449 else if (gadget_is_otg(&udc->gadget)) {
1315 udc->gadget.b_hnp_enable = 1; 1450 if (setup->bRequest ==
1316 else if (setup->bRequest == USB_DEVICE_A_HNP_SUPPORT) 1451 USB_DEVICE_B_HNP_ENABLE)
1317 udc->gadget.a_hnp_support = 1; 1452 udc->gadget.b_hnp_enable = 1;
1318 else if (setup->bRequest == 1453 else if (setup->bRequest ==
1319 USB_DEVICE_A_ALT_HNP_SUPPORT) 1454 USB_DEVICE_A_HNP_SUPPORT)
1320 udc->gadget.a_alt_hnp_support = 1; 1455 udc->gadget.a_hnp_support = 1;
1321 else 1456 else if (setup->bRequest ==
1322 break; 1457 USB_DEVICE_A_ALT_HNP_SUPPORT)
1458 udc->gadget.a_alt_hnp_support = 1;
1459 }
1323 rc = 0; 1460 rc = 0;
1324 } else 1461 } else
1325 break; 1462 break;
@@ -1328,6 +1465,15 @@ static void setup_received_irq(struct fsl_udc *udc,
1328 if (ep0_prime_status(udc, EP_DIR_IN)) 1465 if (ep0_prime_status(udc, EP_DIR_IN))
1329 ep0stall(udc); 1466 ep0stall(udc);
1330 } 1467 }
1468 if (ptc) {
1469 u32 tmp;
1470
1471 mdelay(10);
1472 tmp = fsl_readl(&dr_regs->portsc1) | (ptc << 16);
1473 fsl_writel(tmp, &dr_regs->portsc1);
1474 printk(KERN_INFO "udc: switch to test mode %d.\n", ptc);
1475 }
1476
1331 return; 1477 return;
1332 } 1478 }
1333 1479
@@ -1402,6 +1548,7 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
1402{ 1548{
1403 u32 temp; 1549 u32 temp;
1404 struct ep_queue_head *qh; 1550 struct ep_queue_head *qh;
1551 struct fsl_usb2_platform_data *pdata = udc->pdata;
1405 1552
1406 qh = &udc->ep_qh[ep_num * 2 + EP_DIR_OUT]; 1553 qh = &udc->ep_qh[ep_num * 2 + EP_DIR_OUT];
1407 1554
@@ -1416,7 +1563,16 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
1416 fsl_writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd); 1563 fsl_writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
1417 1564
1418 /* Copy the setup packet to local buffer */ 1565 /* Copy the setup packet to local buffer */
1419 memcpy(buffer_ptr, (u8 *) qh->setup_buffer, 8); 1566 if (pdata->le_setup_buf) {
1567 u32 *p = (u32 *)buffer_ptr;
1568 u32 *s = (u32 *)qh->setup_buffer;
1569
1570 /* Convert little endian setup buffer to CPU endian */
1571 *p++ = le32_to_cpu(*s++);
1572 *p = le32_to_cpu(*s);
1573 } else {
1574 memcpy(buffer_ptr, (u8 *) qh->setup_buffer, 8);
1575 }
1420 } while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_SUTW)); 1576 } while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
1421 1577
1422 /* Clear Setup Tripwire */ 1578 /* Clear Setup Tripwire */
@@ -1440,19 +1596,19 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
1440 actual = curr_req->req.length; 1596 actual = curr_req->req.length;
1441 1597
1442 for (j = 0; j < curr_req->dtd_count; j++) { 1598 for (j = 0; j < curr_req->dtd_count; j++) {
1443 remaining_length = (le32_to_cpu(curr_td->size_ioc_sts) 1599 remaining_length = (hc32_to_cpu(curr_td->size_ioc_sts)
1444 & DTD_PACKET_SIZE) 1600 & DTD_PACKET_SIZE)
1445 >> DTD_LENGTH_BIT_POS; 1601 >> DTD_LENGTH_BIT_POS;
1446 actual -= remaining_length; 1602 actual -= remaining_length;
1447 1603
1448 if ((errors = le32_to_cpu(curr_td->size_ioc_sts) & 1604 errors = hc32_to_cpu(curr_td->size_ioc_sts);
1449 DTD_ERROR_MASK)) { 1605 if (errors & DTD_ERROR_MASK) {
1450 if (errors & DTD_STATUS_HALTED) { 1606 if (errors & DTD_STATUS_HALTED) {
1451 ERR("dTD error %08x QH=%d\n", errors, pipe); 1607 ERR("dTD error %08x QH=%d\n", errors, pipe);
1452 /* Clear the errors and Halt condition */ 1608 /* Clear the errors and Halt condition */
1453 tmp = le32_to_cpu(curr_qh->size_ioc_int_sts); 1609 tmp = hc32_to_cpu(curr_qh->size_ioc_int_sts);
1454 tmp &= ~errors; 1610 tmp &= ~errors;
1455 curr_qh->size_ioc_int_sts = cpu_to_le32(tmp); 1611 curr_qh->size_ioc_int_sts = cpu_to_hc32(tmp);
1456 status = -EPIPE; 1612 status = -EPIPE;
1457 /* FIXME: continue with next queued TD? */ 1613 /* FIXME: continue with next queued TD? */
1458 1614
@@ -1467,10 +1623,10 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
1467 status = -EILSEQ; 1623 status = -EILSEQ;
1468 break; 1624 break;
1469 } else 1625 } else
1470 ERR("Unknown error has occured (0x%x)!\n", 1626 ERR("Unknown error has occurred (0x%x)!\n",
1471 errors); 1627 errors);
1472 1628
1473 } else if (le32_to_cpu(curr_td->size_ioc_sts) 1629 } else if (hc32_to_cpu(curr_td->size_ioc_sts)
1474 & DTD_STATUS_ACTIVE) { 1630 & DTD_STATUS_ACTIVE) {
1475 VDBG("Request not complete"); 1631 VDBG("Request not complete");
1476 status = REQ_UNCOMPLETE; 1632 status = REQ_UNCOMPLETE;
@@ -1559,6 +1715,9 @@ static void port_change_irq(struct fsl_udc *udc)
1559{ 1715{
1560 u32 speed; 1716 u32 speed;
1561 1717
1718 if (udc->bus_reset)
1719 udc->bus_reset = 0;
1720
1562 /* Bus resetting is finished */ 1721 /* Bus resetting is finished */
1563 if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET)) { 1722 if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET)) {
1564 /* Get the speed */ 1723 /* Get the speed */
@@ -1666,6 +1825,8 @@ static void reset_irq(struct fsl_udc *udc)
1666 1825
1667 if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) { 1826 if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
1668 VDBG("Bus reset"); 1827 VDBG("Bus reset");
1828 /* Bus is reseting */
1829 udc->bus_reset = 1;
1669 /* Reset all the queues, include XD, dTD, EP queue 1830 /* Reset all the queues, include XD, dTD, EP queue
1670 * head and TR Queue */ 1831 * head and TR Queue */
1671 reset_queues(udc); 1832 reset_queues(udc);
@@ -1743,6 +1904,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
1743 1904
1744 /* Reset Received */ 1905 /* Reset Received */
1745 if (irq_src & USB_STS_RESET) { 1906 if (irq_src & USB_STS_RESET) {
1907 VDBG("reset int");
1746 reset_irq(udc); 1908 reset_irq(udc);
1747 status = IRQ_HANDLED; 1909 status = IRQ_HANDLED;
1748 } 1910 }
@@ -1765,7 +1927,8 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
1765 * Hook to gadget drivers 1927 * Hook to gadget drivers
1766 * Called by initialization code of gadget drivers 1928 * Called by initialization code of gadget drivers
1767*----------------------------------------------------------------*/ 1929*----------------------------------------------------------------*/
1768int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1930int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1931 int (*bind)(struct usb_gadget *))
1769{ 1932{
1770 int retval = -ENODEV; 1933 int retval = -ENODEV;
1771 unsigned long flags = 0; 1934 unsigned long flags = 0;
@@ -1775,8 +1938,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1775 1938
1776 if (!driver || (driver->speed != USB_SPEED_FULL 1939 if (!driver || (driver->speed != USB_SPEED_FULL
1777 && driver->speed != USB_SPEED_HIGH) 1940 && driver->speed != USB_SPEED_HIGH)
1778 || !driver->bind || !driver->disconnect 1941 || !bind || !driver->disconnect || !driver->setup)
1779 || !driver->setup)
1780 return -EINVAL; 1942 return -EINVAL;
1781 1943
1782 if (udc_controller->driver) 1944 if (udc_controller->driver)
@@ -1792,7 +1954,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1792 spin_unlock_irqrestore(&udc_controller->lock, flags); 1954 spin_unlock_irqrestore(&udc_controller->lock, flags);
1793 1955
1794 /* bind udc driver to gadget driver */ 1956 /* bind udc driver to gadget driver */
1795 retval = driver->bind(&udc_controller->gadget); 1957 retval = bind(&udc_controller->gadget);
1796 if (retval) { 1958 if (retval) {
1797 VDBG("bind to %s --> %d", driver->driver.name, retval); 1959 VDBG("bind to %s --> %d", driver->driver.name, retval);
1798 udc_controller->gadget.dev.driver = NULL; 1960 udc_controller->gadget.dev.driver = NULL;
@@ -1800,11 +1962,30 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1800 goto out; 1962 goto out;
1801 } 1963 }
1802 1964
1803 /* Enable DR IRQ reg and Set usbcmd reg Run bit */ 1965 if (udc_controller->transceiver) {
1804 dr_controller_run(udc_controller); 1966 /* Suspend the controller until OTG enable it */
1805 udc_controller->usb_state = USB_STATE_ATTACHED; 1967 udc_controller->stopped = 1;
1806 udc_controller->ep0_state = WAIT_FOR_SETUP; 1968 printk(KERN_INFO "Suspend udc for OTG auto detect\n");
1807 udc_controller->ep0_dir = 0; 1969
1970 /* connect to bus through transceiver */
1971 if (udc_controller->transceiver) {
1972 retval = otg_set_peripheral(udc_controller->transceiver,
1973 &udc_controller->gadget);
1974 if (retval < 0) {
1975 ERR("can't bind to transceiver\n");
1976 driver->unbind(&udc_controller->gadget);
1977 udc_controller->gadget.dev.driver = 0;
1978 udc_controller->driver = 0;
1979 return retval;
1980 }
1981 }
1982 } else {
1983 /* Enable DR IRQ reg and set USBCMD reg Run bit */
1984 dr_controller_run(udc_controller);
1985 udc_controller->usb_state = USB_STATE_ATTACHED;
1986 udc_controller->ep0_state = WAIT_FOR_SETUP;
1987 udc_controller->ep0_dir = 0;
1988 }
1808 printk(KERN_INFO "%s: bind to driver %s\n", 1989 printk(KERN_INFO "%s: bind to driver %s\n",
1809 udc_controller->gadget.name, driver->driver.name); 1990 udc_controller->gadget.name, driver->driver.name);
1810 1991
@@ -1814,7 +1995,7 @@ out:
1814 retval); 1995 retval);
1815 return retval; 1996 return retval;
1816} 1997}
1817EXPORT_SYMBOL(usb_gadget_register_driver); 1998EXPORT_SYMBOL(usb_gadget_probe_driver);
1818 1999
1819/* Disconnect from gadget driver */ 2000/* Disconnect from gadget driver */
1820int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2001int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
@@ -2052,16 +2233,18 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
2052 next += t; 2233 next += t;
2053 2234
2054#ifndef CONFIG_ARCH_MXC 2235#ifndef CONFIG_ARCH_MXC
2055 tmp_reg = usb_sys_regs->snoop1; 2236 if (udc->pdata->have_sysif_regs) {
2056 t = scnprintf(next, size, "Snoop1 Reg : = [0x%x]\n\n", tmp_reg); 2237 tmp_reg = usb_sys_regs->snoop1;
2057 size -= t; 2238 t = scnprintf(next, size, "Snoop1 Reg : = [0x%x]\n\n", tmp_reg);
2058 next += t; 2239 size -= t;
2240 next += t;
2059 2241
2060 tmp_reg = usb_sys_regs->control; 2242 tmp_reg = usb_sys_regs->control;
2061 t = scnprintf(next, size, "General Control Reg : = [0x%x]\n\n", 2243 t = scnprintf(next, size, "General Control Reg : = [0x%x]\n\n",
2062 tmp_reg); 2244 tmp_reg);
2063 size -= t; 2245 size -= t;
2064 next += t; 2246 next += t;
2247 }
2065#endif 2248#endif
2066 2249
2067 /* ------fsl_udc, fsl_ep, fsl_request structure information ----- */ 2250 /* ------fsl_udc, fsl_ep, fsl_request structure information ----- */
@@ -2190,7 +2373,6 @@ static int __init struct_udc_setup(struct fsl_udc *udc,
2190 struct fsl_req, req); 2373 struct fsl_req, req);
2191 /* allocate a small amount of memory to get valid address */ 2374 /* allocate a small amount of memory to get valid address */
2192 udc->status_req->req.buf = kmalloc(8, GFP_KERNEL); 2375 udc->status_req->req.buf = kmalloc(8, GFP_KERNEL);
2193 udc->status_req->req.dma = virt_to_phys(udc->status_req->req.buf);
2194 2376
2195 udc->resume_state = USB_STATE_NOTATTACHED; 2377 udc->resume_state = USB_STATE_NOTATTACHED;
2196 udc->usb_state = USB_STATE_POWERED; 2378 udc->usb_state = USB_STATE_POWERED;
@@ -2241,6 +2423,7 @@ static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index,
2241 */ 2423 */
2242static int __init fsl_udc_probe(struct platform_device *pdev) 2424static int __init fsl_udc_probe(struct platform_device *pdev)
2243{ 2425{
2426 struct fsl_usb2_platform_data *pdata;
2244 struct resource *res; 2427 struct resource *res;
2245 int ret = -ENODEV; 2428 int ret = -ENODEV;
2246 unsigned int i; 2429 unsigned int i;
@@ -2257,20 +2440,35 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2257 return -ENOMEM; 2440 return -ENOMEM;
2258 } 2441 }
2259 2442
2443 pdata = pdev->dev.platform_data;
2444 udc_controller->pdata = pdata;
2260 spin_lock_init(&udc_controller->lock); 2445 spin_lock_init(&udc_controller->lock);
2261 udc_controller->stopped = 1; 2446 udc_controller->stopped = 1;
2262 2447
2448#ifdef CONFIG_USB_OTG
2449 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
2450 udc_controller->transceiver = otg_get_transceiver();
2451 if (!udc_controller->transceiver) {
2452 ERR("Can't find OTG driver!\n");
2453 ret = -ENODEV;
2454 goto err_kfree;
2455 }
2456 }
2457#endif
2458
2263 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2459 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2264 if (!res) { 2460 if (!res) {
2265 ret = -ENXIO; 2461 ret = -ENXIO;
2266 goto err_kfree; 2462 goto err_kfree;
2267 } 2463 }
2268 2464
2269 if (!request_mem_region(res->start, res->end - res->start + 1, 2465 if (pdata->operating_mode == FSL_USB2_DR_DEVICE) {
2270 driver_name)) { 2466 if (!request_mem_region(res->start, res->end - res->start + 1,
2271 ERR("request mem region for %s failed\n", pdev->name); 2467 driver_name)) {
2272 ret = -EBUSY; 2468 ERR("request mem region for %s failed\n", pdev->name);
2273 goto err_kfree; 2469 ret = -EBUSY;
2470 goto err_kfree;
2471 }
2274 } 2472 }
2275 2473
2276 dr_regs = ioremap(res->start, resource_size(res)); 2474 dr_regs = ioremap(res->start, resource_size(res));
@@ -2279,9 +2477,23 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2279 goto err_release_mem_region; 2477 goto err_release_mem_region;
2280 } 2478 }
2281 2479
2480 pdata->regs = (void *)dr_regs;
2481
2482 /*
2483 * do platform specific init: check the clock, grab/config pins, etc.
2484 */
2485 if (pdata->init && pdata->init(pdev)) {
2486 ret = -ENODEV;
2487 goto err_iounmap_noclk;
2488 }
2489
2490 /* Set accessors only after pdata->init() ! */
2491 fsl_set_accessors(pdata);
2492
2282#ifndef CONFIG_ARCH_MXC 2493#ifndef CONFIG_ARCH_MXC
2283 usb_sys_regs = (struct usb_sys_interface *) 2494 if (pdata->have_sysif_regs)
2284 ((u32)dr_regs + USB_DR_SYS_OFFSET); 2495 usb_sys_regs = (struct usb_sys_interface *)
2496 ((u32)dr_regs + USB_DR_SYS_OFFSET);
2285#endif 2497#endif
2286 2498
2287 /* Initialize USB clocks */ 2499 /* Initialize USB clocks */
@@ -2321,9 +2533,11 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2321 goto err_free_irq; 2533 goto err_free_irq;
2322 } 2534 }
2323 2535
2324 /* initialize usb hw reg except for regs for EP, 2536 if (!udc_controller->transceiver) {
2325 * leave usbintr reg untouched */ 2537 /* initialize usb hw reg except for regs for EP,
2326 dr_controller_setup(udc_controller); 2538 * leave usbintr reg untouched */
2539 dr_controller_setup(udc_controller);
2540 }
2327 2541
2328 fsl_udc_clk_finalize(pdev); 2542 fsl_udc_clk_finalize(pdev);
2329 2543
@@ -2343,6 +2557,9 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2343 if (ret < 0) 2557 if (ret < 0)
2344 goto err_free_irq; 2558 goto err_free_irq;
2345 2559
2560 if (udc_controller->transceiver)
2561 udc_controller->gadget.is_otg = 1;
2562
2346 /* setup QH and epctrl for ep0 */ 2563 /* setup QH and epctrl for ep0 */
2347 ep0_setup(udc_controller); 2564 ep0_setup(udc_controller);
2348 2565
@@ -2381,11 +2598,14 @@ err_unregister:
2381err_free_irq: 2598err_free_irq:
2382 free_irq(udc_controller->irq, udc_controller); 2599 free_irq(udc_controller->irq, udc_controller);
2383err_iounmap: 2600err_iounmap:
2601 if (pdata->exit)
2602 pdata->exit(pdev);
2384 fsl_udc_clk_release(); 2603 fsl_udc_clk_release();
2385err_iounmap_noclk: 2604err_iounmap_noclk:
2386 iounmap(dr_regs); 2605 iounmap(dr_regs);
2387err_release_mem_region: 2606err_release_mem_region:
2388 release_mem_region(res->start, res->end - res->start + 1); 2607 if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
2608 release_mem_region(res->start, res->end - res->start + 1);
2389err_kfree: 2609err_kfree:
2390 kfree(udc_controller); 2610 kfree(udc_controller);
2391 udc_controller = NULL; 2611 udc_controller = NULL;
@@ -2398,6 +2618,7 @@ err_kfree:
2398static int __exit fsl_udc_remove(struct platform_device *pdev) 2618static int __exit fsl_udc_remove(struct platform_device *pdev)
2399{ 2619{
2400 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2620 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2621 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
2401 2622
2402 DECLARE_COMPLETION(done); 2623 DECLARE_COMPLETION(done);
2403 2624
@@ -2418,12 +2639,20 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
2418 dma_pool_destroy(udc_controller->td_pool); 2639 dma_pool_destroy(udc_controller->td_pool);
2419 free_irq(udc_controller->irq, udc_controller); 2640 free_irq(udc_controller->irq, udc_controller);
2420 iounmap(dr_regs); 2641 iounmap(dr_regs);
2421 release_mem_region(res->start, res->end - res->start + 1); 2642 if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
2643 release_mem_region(res->start, res->end - res->start + 1);
2422 2644
2423 device_unregister(&udc_controller->gadget.dev); 2645 device_unregister(&udc_controller->gadget.dev);
2424 /* free udc --wait for the release() finished */ 2646 /* free udc --wait for the release() finished */
2425 wait_for_completion(&done); 2647 wait_for_completion(&done);
2426 2648
2649 /*
2650 * do platform specific un-initialization:
2651 * release iomux pins, etc.
2652 */
2653 if (pdata->exit)
2654 pdata->exit(pdev);
2655
2427 return 0; 2656 return 0;
2428} 2657}
2429 2658
@@ -2454,6 +2683,62 @@ static int fsl_udc_resume(struct platform_device *pdev)
2454 return 0; 2683 return 0;
2455} 2684}
2456 2685
2686static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
2687{
2688 struct fsl_udc *udc = udc_controller;
2689 u32 mode, usbcmd;
2690
2691 mode = fsl_readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
2692
2693 pr_debug("%s(): mode 0x%x stopped %d\n", __func__, mode, udc->stopped);
2694
2695 /*
2696 * If the controller is already stopped, then this must be a
2697 * PM suspend. Remember this fact, so that we will leave the
2698 * controller stopped at PM resume time.
2699 */
2700 if (udc->stopped) {
2701 pr_debug("gadget already stopped, leaving early\n");
2702 udc->already_stopped = 1;
2703 return 0;
2704 }
2705
2706 if (mode != USB_MODE_CTRL_MODE_DEVICE) {
2707 pr_debug("gadget not in device mode, leaving early\n");
2708 return 0;
2709 }
2710
2711 /* stop the controller */
2712 usbcmd = fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
2713 fsl_writel(usbcmd, &dr_regs->usbcmd);
2714
2715 udc->stopped = 1;
2716
2717 pr_info("USB Gadget suspended\n");
2718
2719 return 0;
2720}
2721
2722static int fsl_udc_otg_resume(struct device *dev)
2723{
2724 pr_debug("%s(): stopped %d already_stopped %d\n", __func__,
2725 udc_controller->stopped, udc_controller->already_stopped);
2726
2727 /*
2728 * If the controller was stopped at suspend time, then
2729 * don't resume it now.
2730 */
2731 if (udc_controller->already_stopped) {
2732 udc_controller->already_stopped = 0;
2733 pr_debug("gadget was already stopped, leaving early\n");
2734 return 0;
2735 }
2736
2737 pr_info("USB Gadget resume\n");
2738
2739 return fsl_udc_resume(NULL);
2740}
2741
2457/*------------------------------------------------------------------------- 2742/*-------------------------------------------------------------------------
2458 Register entry point for the peripheral controller driver 2743 Register entry point for the peripheral controller driver
2459--------------------------------------------------------------------------*/ 2744--------------------------------------------------------------------------*/
@@ -2466,6 +2751,9 @@ static struct platform_driver udc_driver = {
2466 .driver = { 2751 .driver = {
2467 .name = (char *)driver_name, 2752 .name = (char *)driver_name,
2468 .owner = THIS_MODULE, 2753 .owner = THIS_MODULE,
2754 /* udc suspend/resume called from OTG driver */
2755 .suspend = fsl_udc_otg_suspend,
2756 .resume = fsl_udc_otg_resume,
2469 }, 2757 },
2470}; 2758};
2471 2759
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 20aeceed48c7..1d51be83fda8 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -15,7 +15,7 @@ struct usb_dr_device {
15 u8 res1[256]; 15 u8 res1[256];
16 u16 caplength; /* Capability Register Length */ 16 u16 caplength; /* Capability Register Length */
17 u16 hciversion; /* Host Controller Interface Version */ 17 u16 hciversion; /* Host Controller Interface Version */
18 u32 hcsparams; /* Host Controller Structual Parameters */ 18 u32 hcsparams; /* Host Controller Structural Parameters */
19 u32 hccparams; /* Host Controller Capability Parameters */ 19 u32 hccparams; /* Host Controller Capability Parameters */
20 u8 res2[20]; 20 u8 res2[20];
21 u32 dciversion; /* Device Controller Interface Version */ 21 u32 dciversion; /* Device Controller Interface Version */
@@ -52,7 +52,7 @@ struct usb_dr_host {
52 u8 res1[256]; 52 u8 res1[256];
53 u16 caplength; /* Capability Register Length */ 53 u16 caplength; /* Capability Register Length */
54 u16 hciversion; /* Host Controller Interface Version */ 54 u16 hciversion; /* Host Controller Interface Version */
55 u32 hcsparams; /* Host Controller Structual Parameters */ 55 u32 hcsparams; /* Host Controller Structural Parameters */
56 u32 hccparams; /* Host Controller Capability Parameters */ 56 u32 hccparams; /* Host Controller Capability Parameters */
57 u8 res2[20]; 57 u8 res2[20];
58 u32 dciversion; /* Device Controller Interface Version */ 58 u32 dciversion; /* Device Controller Interface Version */
@@ -275,7 +275,9 @@ struct usb_sys_interface {
275#define USB_MODE_CTRL_MODE_IDLE 0x00000000 275#define USB_MODE_CTRL_MODE_IDLE 0x00000000
276#define USB_MODE_CTRL_MODE_DEVICE 0x00000002 276#define USB_MODE_CTRL_MODE_DEVICE 0x00000002
277#define USB_MODE_CTRL_MODE_HOST 0x00000003 277#define USB_MODE_CTRL_MODE_HOST 0x00000003
278#define USB_MODE_CTRL_MODE_MASK 0x00000003
278#define USB_MODE_CTRL_MODE_RSV 0x00000001 279#define USB_MODE_CTRL_MODE_RSV 0x00000001
280#define USB_MODE_ES 0x00000004 /* Endian Select */
279#define USB_MODE_SETUP_LOCK_OFF 0x00000008 281#define USB_MODE_SETUP_LOCK_OFF 0x00000008
280#define USB_MODE_STREAM_DISABLE 0x00000010 282#define USB_MODE_STREAM_DISABLE 0x00000010
281/* Endpoint Flush Register */ 283/* Endpoint Flush Register */
@@ -461,6 +463,7 @@ struct fsl_ep {
461struct fsl_udc { 463struct fsl_udc {
462 struct usb_gadget gadget; 464 struct usb_gadget gadget;
463 struct usb_gadget_driver *driver; 465 struct usb_gadget_driver *driver;
466 struct fsl_usb2_platform_data *pdata;
464 struct completion *done; /* to make sure release() is done */ 467 struct completion *done; /* to make sure release() is done */
465 struct fsl_ep *eps; 468 struct fsl_ep *eps;
466 unsigned int max_ep; 469 unsigned int max_ep;
@@ -473,6 +476,8 @@ struct fsl_udc {
473 unsigned vbus_active:1; 476 unsigned vbus_active:1;
474 unsigned stopped:1; 477 unsigned stopped:1;
475 unsigned remote_wakeup:1; 478 unsigned remote_wakeup:1;
479 unsigned already_stopped:1;
480 unsigned big_endian_desc:1;
476 481
477 struct ep_queue_head *ep_qh; /* Endpoints Queue-Head */ 482 struct ep_queue_head *ep_qh; /* Endpoints Queue-Head */
478 struct fsl_req *status_req; /* ep0 status request */ 483 struct fsl_req *status_req; /* ep0 status request */
@@ -483,6 +488,7 @@ struct fsl_udc {
483 dma_addr_t ep_qh_dma; /* dma address of QH */ 488 dma_addr_t ep_qh_dma; /* dma address of QH */
484 489
485 u32 max_pipes; /* Device max pipes */ 490 u32 max_pipes; /* Device max pipes */
491 u32 bus_reset; /* Device is bus resetting */
486 u32 resume_state; /* USB state to resume */ 492 u32 resume_state; /* USB state to resume */
487 u32 usb_state; /* USB current state */ 493 u32 usb_state; /* USB current state */
488 u32 ep0_state; /* Endpoint zero state */ 494 u32 ep0_state; /* Endpoint zero state */
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
new file mode 100644
index 000000000000..763d462454b9
--- /dev/null
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -0,0 +1,1744 @@
1/*
2 * Fusb300 UDC (USB gadget)
3 *
4 * Copyright (C) 2010 Faraday Technology Corp.
5 *
6 * Author : Yuan-hsin Chen <yhchen@faraday-tech.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22#include <linux/dma-mapping.h>
23#include <linux/err.h>
24#include <linux/interrupt.h>
25#include <linux/io.h>
26#include <linux/platform_device.h>
27#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h>
29
30#include "fusb300_udc.h"
31
32MODULE_DESCRIPTION("FUSB300 USB gadget driver");
33MODULE_LICENSE("GPL");
34MODULE_AUTHOR("Yuan Hsin Chen <yhchen@faraday-tech.com>");
35MODULE_ALIAS("platform:fusb300_udc");
36
37#define DRIVER_VERSION "20 October 2010"
38
39static const char udc_name[] = "fusb300_udc";
40static const char * const fusb300_ep_name[] = {
41 "ep0", "ep1", "ep2", "ep3", "ep4", "ep5", "ep6", "ep7", "ep8", "ep9",
42 "ep10", "ep11", "ep12", "ep13", "ep14", "ep15"
43};
44
45static void done(struct fusb300_ep *ep, struct fusb300_request *req,
46 int status);
47
48static void fusb300_enable_bit(struct fusb300 *fusb300, u32 offset,
49 u32 value)
50{
51 u32 reg = ioread32(fusb300->reg + offset);
52
53 reg |= value;
54 iowrite32(reg, fusb300->reg + offset);
55}
56
57static void fusb300_disable_bit(struct fusb300 *fusb300, u32 offset,
58 u32 value)
59{
60 u32 reg = ioread32(fusb300->reg + offset);
61
62 reg &= ~value;
63 iowrite32(reg, fusb300->reg + offset);
64}
65
66
67static void fusb300_ep_setting(struct fusb300_ep *ep,
68 struct fusb300_ep_info info)
69{
70 ep->epnum = info.epnum;
71 ep->type = info.type;
72}
73
74static int fusb300_ep_release(struct fusb300_ep *ep)
75{
76 if (!ep->epnum)
77 return 0;
78 ep->epnum = 0;
79 ep->stall = 0;
80 ep->wedged = 0;
81 return 0;
82}
83
84static void fusb300_set_fifo_entry(struct fusb300 *fusb300,
85 u32 ep)
86{
87 u32 val = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
88
89 val &= ~FUSB300_EPSET1_FIFOENTRY_MSK;
90 val |= FUSB300_EPSET1_FIFOENTRY(FUSB300_FIFO_ENTRY_NUM);
91 iowrite32(val, fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
92}
93
94static void fusb300_set_start_entry(struct fusb300 *fusb300,
95 u8 ep)
96{
97 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
98 u32 start_entry = fusb300->fifo_entry_num * FUSB300_FIFO_ENTRY_NUM;
99
100 reg &= ~FUSB300_EPSET1_START_ENTRY_MSK ;
101 reg |= FUSB300_EPSET1_START_ENTRY(start_entry);
102 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
103 if (fusb300->fifo_entry_num == FUSB300_MAX_FIFO_ENTRY) {
104 fusb300->fifo_entry_num = 0;
105 fusb300->addrofs = 0;
106 pr_err("fifo entry is over the maximum number!\n");
107 } else
108 fusb300->fifo_entry_num++;
109}
110
111/* set fusb300_set_start_entry first before fusb300_set_epaddrofs */
112static void fusb300_set_epaddrofs(struct fusb300 *fusb300,
113 struct fusb300_ep_info info)
114{
115 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
116
117 reg &= ~FUSB300_EPSET2_ADDROFS_MSK;
118 reg |= FUSB300_EPSET2_ADDROFS(fusb300->addrofs);
119 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
120 fusb300->addrofs += (info.maxpacket + 7) / 8 * FUSB300_FIFO_ENTRY_NUM;
121}
122
123static void ep_fifo_setting(struct fusb300 *fusb300,
124 struct fusb300_ep_info info)
125{
126 fusb300_set_fifo_entry(fusb300, info.epnum);
127 fusb300_set_start_entry(fusb300, info.epnum);
128 fusb300_set_epaddrofs(fusb300, info);
129}
130
131static void fusb300_set_eptype(struct fusb300 *fusb300,
132 struct fusb300_ep_info info)
133{
134 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
135
136 reg &= ~FUSB300_EPSET1_TYPE_MSK;
137 reg |= FUSB300_EPSET1_TYPE(info.type);
138 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
139}
140
141static void fusb300_set_epdir(struct fusb300 *fusb300,
142 struct fusb300_ep_info info)
143{
144 u32 reg;
145
146 if (!info.dir_in)
147 return;
148 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
149 reg &= ~FUSB300_EPSET1_DIR_MSK;
150 reg |= FUSB300_EPSET1_DIRIN;
151 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
152}
153
154static void fusb300_set_ep_active(struct fusb300 *fusb300,
155 u8 ep)
156{
157 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
158
159 reg |= FUSB300_EPSET1_ACTEN;
160 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
161}
162
163static void fusb300_set_epmps(struct fusb300 *fusb300,
164 struct fusb300_ep_info info)
165{
166 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
167
168 reg &= ~FUSB300_EPSET2_MPS_MSK;
169 reg |= FUSB300_EPSET2_MPS(info.maxpacket);
170 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
171}
172
173static void fusb300_set_interval(struct fusb300 *fusb300,
174 struct fusb300_ep_info info)
175{
176 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
177
178 reg &= ~FUSB300_EPSET1_INTERVAL(0x7);
179 reg |= FUSB300_EPSET1_INTERVAL(info.interval);
180 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
181}
182
183static void fusb300_set_bwnum(struct fusb300 *fusb300,
184 struct fusb300_ep_info info)
185{
186 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
187
188 reg &= ~FUSB300_EPSET1_BWNUM(0x3);
189 reg |= FUSB300_EPSET1_BWNUM(info.bw_num);
190 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
191}
192
193static void set_ep_reg(struct fusb300 *fusb300,
194 struct fusb300_ep_info info)
195{
196 fusb300_set_eptype(fusb300, info);
197 fusb300_set_epdir(fusb300, info);
198 fusb300_set_epmps(fusb300, info);
199
200 if (info.interval)
201 fusb300_set_interval(fusb300, info);
202
203 if (info.bw_num)
204 fusb300_set_bwnum(fusb300, info);
205
206 fusb300_set_ep_active(fusb300, info.epnum);
207}
208
209static int config_ep(struct fusb300_ep *ep,
210 const struct usb_endpoint_descriptor *desc)
211{
212 struct fusb300 *fusb300 = ep->fusb300;
213 struct fusb300_ep_info info;
214
215 ep->desc = desc;
216
217 info.interval = 0;
218 info.addrofs = 0;
219 info.bw_num = 0;
220
221 info.type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
222 info.dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0;
223 info.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
224 info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
225
226 if ((info.type == USB_ENDPOINT_XFER_INT) ||
227 (info.type == USB_ENDPOINT_XFER_ISOC)) {
228 info.interval = desc->bInterval;
229 if (info.type == USB_ENDPOINT_XFER_ISOC)
230 info.bw_num = ((desc->wMaxPacketSize & 0x1800) >> 11);
231 }
232
233 ep_fifo_setting(fusb300, info);
234
235 set_ep_reg(fusb300, info);
236
237 fusb300_ep_setting(ep, info);
238
239 fusb300->ep[info.epnum] = ep;
240
241 return 0;
242}
243
244static int fusb300_enable(struct usb_ep *_ep,
245 const struct usb_endpoint_descriptor *desc)
246{
247 struct fusb300_ep *ep;
248
249 ep = container_of(_ep, struct fusb300_ep, ep);
250
251 if (ep->fusb300->reenum) {
252 ep->fusb300->fifo_entry_num = 0;
253 ep->fusb300->addrofs = 0;
254 ep->fusb300->reenum = 0;
255 }
256
257 return config_ep(ep, desc);
258}
259
260static int fusb300_disable(struct usb_ep *_ep)
261{
262 struct fusb300_ep *ep;
263 struct fusb300_request *req;
264 unsigned long flags;
265
266 ep = container_of(_ep, struct fusb300_ep, ep);
267
268 BUG_ON(!ep);
269
270 while (!list_empty(&ep->queue)) {
271 req = list_entry(ep->queue.next, struct fusb300_request, queue);
272 spin_lock_irqsave(&ep->fusb300->lock, flags);
273 done(ep, req, -ECONNRESET);
274 spin_unlock_irqrestore(&ep->fusb300->lock, flags);
275 }
276
277 return fusb300_ep_release(ep);
278}
279
280static struct usb_request *fusb300_alloc_request(struct usb_ep *_ep,
281 gfp_t gfp_flags)
282{
283 struct fusb300_request *req;
284
285 req = kzalloc(sizeof(struct fusb300_request), gfp_flags);
286 if (!req)
287 return NULL;
288 INIT_LIST_HEAD(&req->queue);
289
290 return &req->req;
291}
292
293static void fusb300_free_request(struct usb_ep *_ep, struct usb_request *_req)
294{
295 struct fusb300_request *req;
296
297 req = container_of(_req, struct fusb300_request, req);
298 kfree(req);
299}
300
301static int enable_fifo_int(struct fusb300_ep *ep)
302{
303 struct fusb300 *fusb300 = ep->fusb300;
304
305 if (ep->epnum) {
306 fusb300_enable_bit(fusb300, FUSB300_OFFSET_IGER0,
307 FUSB300_IGER0_EEPn_FIFO_INT(ep->epnum));
308 } else {
309 pr_err("can't enable_fifo_int ep0\n");
310 return -EINVAL;
311 }
312
313 return 0;
314}
315
316static int disable_fifo_int(struct fusb300_ep *ep)
317{
318 struct fusb300 *fusb300 = ep->fusb300;
319
320 if (ep->epnum) {
321 fusb300_disable_bit(fusb300, FUSB300_OFFSET_IGER0,
322 FUSB300_IGER0_EEPn_FIFO_INT(ep->epnum));
323 } else {
324 pr_err("can't disable_fifo_int ep0\n");
325 return -EINVAL;
326 }
327
328 return 0;
329}
330
331static void fusb300_set_cxlen(struct fusb300 *fusb300, u32 length)
332{
333 u32 reg;
334
335 reg = ioread32(fusb300->reg + FUSB300_OFFSET_CSR);
336 reg &= ~FUSB300_CSR_LEN_MSK;
337 reg |= FUSB300_CSR_LEN(length);
338 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_CSR);
339}
340
341/* write data to cx fifo */
342static void fusb300_wrcxf(struct fusb300_ep *ep,
343 struct fusb300_request *req)
344{
345 int i = 0;
346 u8 *tmp;
347 u32 data;
348 struct fusb300 *fusb300 = ep->fusb300;
349 u32 length = req->req.length - req->req.actual;
350
351 tmp = req->req.buf + req->req.actual;
352
353 if (length > SS_CTL_MAX_PACKET_SIZE) {
354 fusb300_set_cxlen(fusb300, SS_CTL_MAX_PACKET_SIZE);
355 for (i = (SS_CTL_MAX_PACKET_SIZE >> 2); i > 0; i--) {
356 data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16 |
357 *(tmp + 3) << 24;
358 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
359 tmp += 4;
360 }
361 req->req.actual += SS_CTL_MAX_PACKET_SIZE;
362 } else { /* length is less than max packet size */
363 fusb300_set_cxlen(fusb300, length);
364 for (i = length >> 2; i > 0; i--) {
365 data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16 |
366 *(tmp + 3) << 24;
367 printk(KERN_DEBUG " 0x%x\n", data);
368 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
369 tmp = tmp + 4;
370 }
371 switch (length % 4) {
372 case 1:
373 data = *tmp;
374 printk(KERN_DEBUG " 0x%x\n", data);
375 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
376 break;
377 case 2:
378 data = *tmp | *(tmp + 1) << 8;
379 printk(KERN_DEBUG " 0x%x\n", data);
380 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
381 break;
382 case 3:
383 data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
384 printk(KERN_DEBUG " 0x%x\n", data);
385 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
386 break;
387 default:
388 break;
389 }
390 req->req.actual += length;
391 }
392}
393
394static void fusb300_set_epnstall(struct fusb300 *fusb300, u8 ep)
395{
396 fusb300_enable_bit(fusb300, FUSB300_OFFSET_EPSET0(ep),
397 FUSB300_EPSET0_STL);
398}
399
400static void fusb300_clear_epnstall(struct fusb300 *fusb300, u8 ep)
401{
402 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
403
404 if (reg & FUSB300_EPSET0_STL) {
405 printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep);
406 reg &= ~FUSB300_EPSET0_STL;
407 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
408 }
409}
410
411static void ep0_queue(struct fusb300_ep *ep, struct fusb300_request *req)
412{
413 if (ep->fusb300->ep0_dir) { /* if IN */
414 if (req->req.length) {
415 fusb300_wrcxf(ep, req);
416 } else
417 printk(KERN_DEBUG "%s : req->req.length = 0x%x\n",
418 __func__, req->req.length);
419 if ((req->req.length == req->req.actual) ||
420 (req->req.actual < ep->ep.maxpacket))
421 done(ep, req, 0);
422 } else { /* OUT */
423 if (!req->req.length)
424 done(ep, req, 0);
425 else
426 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER1,
427 FUSB300_IGER1_CX_OUT_INT);
428 }
429}
430
431static int fusb300_queue(struct usb_ep *_ep, struct usb_request *_req,
432 gfp_t gfp_flags)
433{
434 struct fusb300_ep *ep;
435 struct fusb300_request *req;
436 unsigned long flags;
437 int request = 0;
438
439 ep = container_of(_ep, struct fusb300_ep, ep);
440 req = container_of(_req, struct fusb300_request, req);
441
442 if (ep->fusb300->gadget.speed == USB_SPEED_UNKNOWN)
443 return -ESHUTDOWN;
444
445 spin_lock_irqsave(&ep->fusb300->lock, flags);
446
447 if (list_empty(&ep->queue))
448 request = 1;
449
450 list_add_tail(&req->queue, &ep->queue);
451
452 req->req.actual = 0;
453 req->req.status = -EINPROGRESS;
454
455 if (ep->desc == NULL) /* ep0 */
456 ep0_queue(ep, req);
457 else if (request && !ep->stall)
458 enable_fifo_int(ep);
459
460 spin_unlock_irqrestore(&ep->fusb300->lock, flags);
461
462 return 0;
463}
464
465static int fusb300_dequeue(struct usb_ep *_ep, struct usb_request *_req)
466{
467 struct fusb300_ep *ep;
468 struct fusb300_request *req;
469 unsigned long flags;
470
471 ep = container_of(_ep, struct fusb300_ep, ep);
472 req = container_of(_req, struct fusb300_request, req);
473
474 spin_lock_irqsave(&ep->fusb300->lock, flags);
475 if (!list_empty(&ep->queue))
476 done(ep, req, -ECONNRESET);
477 spin_unlock_irqrestore(&ep->fusb300->lock, flags);
478
479 return 0;
480}
481
482static int fusb300_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedge)
483{
484 struct fusb300_ep *ep;
485 struct fusb300 *fusb300;
486 unsigned long flags;
487 int ret = 0;
488
489 ep = container_of(_ep, struct fusb300_ep, ep);
490
491 fusb300 = ep->fusb300;
492
493 spin_lock_irqsave(&ep->fusb300->lock, flags);
494
495 if (!list_empty(&ep->queue)) {
496 ret = -EAGAIN;
497 goto out;
498 }
499
500 if (value) {
501 fusb300_set_epnstall(fusb300, ep->epnum);
502 ep->stall = 1;
503 if (wedge)
504 ep->wedged = 1;
505 } else {
506 fusb300_clear_epnstall(fusb300, ep->epnum);
507 ep->stall = 0;
508 ep->wedged = 0;
509 }
510
511out:
512 spin_unlock_irqrestore(&ep->fusb300->lock, flags);
513 return ret;
514}
515
516static int fusb300_set_halt(struct usb_ep *_ep, int value)
517{
518 return fusb300_set_halt_and_wedge(_ep, value, 0);
519}
520
521static int fusb300_set_wedge(struct usb_ep *_ep)
522{
523 return fusb300_set_halt_and_wedge(_ep, 1, 1);
524}
525
526static void fusb300_fifo_flush(struct usb_ep *_ep)
527{
528}
529
530static struct usb_ep_ops fusb300_ep_ops = {
531 .enable = fusb300_enable,
532 .disable = fusb300_disable,
533
534 .alloc_request = fusb300_alloc_request,
535 .free_request = fusb300_free_request,
536
537 .queue = fusb300_queue,
538 .dequeue = fusb300_dequeue,
539
540 .set_halt = fusb300_set_halt,
541 .fifo_flush = fusb300_fifo_flush,
542 .set_wedge = fusb300_set_wedge,
543};
544
545/*****************************************************************************/
546static void fusb300_clear_int(struct fusb300 *fusb300, u32 offset,
547 u32 value)
548{
549 iowrite32(value, fusb300->reg + offset);
550}
551
552static void fusb300_reset(void)
553{
554}
555
556static void fusb300_set_cxstall(struct fusb300 *fusb300)
557{
558 fusb300_enable_bit(fusb300, FUSB300_OFFSET_CSR,
559 FUSB300_CSR_STL);
560}
561
562static void fusb300_set_cxdone(struct fusb300 *fusb300)
563{
564 fusb300_enable_bit(fusb300, FUSB300_OFFSET_CSR,
565 FUSB300_CSR_DONE);
566}
567
568/* read data from cx fifo */
569void fusb300_rdcxf(struct fusb300 *fusb300,
570 u8 *buffer, u32 length)
571{
572 int i = 0;
573 u8 *tmp;
574 u32 data;
575
576 tmp = buffer;
577
578 for (i = (length >> 2); i > 0; i--) {
579 data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
580 printk(KERN_DEBUG " 0x%x\n", data);
581 *tmp = data & 0xFF;
582 *(tmp + 1) = (data >> 8) & 0xFF;
583 *(tmp + 2) = (data >> 16) & 0xFF;
584 *(tmp + 3) = (data >> 24) & 0xFF;
585 tmp = tmp + 4;
586 }
587
588 switch (length % 4) {
589 case 1:
590 data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
591 printk(KERN_DEBUG " 0x%x\n", data);
592 *tmp = data & 0xFF;
593 break;
594 case 2:
595 data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
596 printk(KERN_DEBUG " 0x%x\n", data);
597 *tmp = data & 0xFF;
598 *(tmp + 1) = (data >> 8) & 0xFF;
599 break;
600 case 3:
601 data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
602 printk(KERN_DEBUG " 0x%x\n", data);
603 *tmp = data & 0xFF;
604 *(tmp + 1) = (data >> 8) & 0xFF;
605 *(tmp + 2) = (data >> 16) & 0xFF;
606 break;
607 default:
608 break;
609 }
610}
611
612#if 0
613static void fusb300_dbg_fifo(struct fusb300_ep *ep,
614 u8 entry, u16 length)
615{
616 u32 reg;
617 u32 i = 0;
618 u32 j = 0;
619
620 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_GTM);
621 reg &= ~(FUSB300_GTM_TST_EP_ENTRY(0xF) |
622 FUSB300_GTM_TST_EP_NUM(0xF) | FUSB300_GTM_TST_FIFO_DEG);
623 reg |= (FUSB300_GTM_TST_EP_ENTRY(entry) |
624 FUSB300_GTM_TST_EP_NUM(ep->epnum) | FUSB300_GTM_TST_FIFO_DEG);
625 iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_GTM);
626
627 for (i = 0; i < (length >> 2); i++) {
628 if (i * 4 == 1024)
629 break;
630 reg = ioread32(ep->fusb300->reg +
631 FUSB300_OFFSET_BUFDBG_START + i * 4);
632 printk(KERN_DEBUG" 0x%-8x", reg);
633 j++;
634 if ((j % 4) == 0)
635 printk(KERN_DEBUG "\n");
636 }
637
638 if (length % 4) {
639 reg = ioread32(ep->fusb300->reg +
640 FUSB300_OFFSET_BUFDBG_START + i * 4);
641 printk(KERN_DEBUG " 0x%x\n", reg);
642 }
643
644 if ((j % 4) != 0)
645 printk(KERN_DEBUG "\n");
646
647 fusb300_disable_bit(ep->fusb300, FUSB300_OFFSET_GTM,
648 FUSB300_GTM_TST_FIFO_DEG);
649}
650
651static void fusb300_cmp_dbg_fifo(struct fusb300_ep *ep,
652 u8 entry, u16 length, u8 *golden)
653{
654 u32 reg;
655 u32 i = 0;
656 u32 golden_value;
657 u8 *tmp;
658
659 tmp = golden;
660
661 printk(KERN_DEBUG "fusb300_cmp_dbg_fifo (entry %d) : start\n", entry);
662
663 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_GTM);
664 reg &= ~(FUSB300_GTM_TST_EP_ENTRY(0xF) |
665 FUSB300_GTM_TST_EP_NUM(0xF) | FUSB300_GTM_TST_FIFO_DEG);
666 reg |= (FUSB300_GTM_TST_EP_ENTRY(entry) |
667 FUSB300_GTM_TST_EP_NUM(ep->epnum) | FUSB300_GTM_TST_FIFO_DEG);
668 iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_GTM);
669
670 for (i = 0; i < (length >> 2); i++) {
671 if (i * 4 == 1024)
672 break;
673 golden_value = *tmp | *(tmp + 1) << 8 |
674 *(tmp + 2) << 16 | *(tmp + 3) << 24;
675
676 reg = ioread32(ep->fusb300->reg +
677 FUSB300_OFFSET_BUFDBG_START + i*4);
678
679 if (reg != golden_value) {
680 printk(KERN_DEBUG "0x%x : ", (u32)(ep->fusb300->reg +
681 FUSB300_OFFSET_BUFDBG_START + i*4));
682 printk(KERN_DEBUG " golden = 0x%x, reg = 0x%x\n",
683 golden_value, reg);
684 }
685 tmp += 4;
686 }
687
688 switch (length % 4) {
689 case 1:
690 golden_value = *tmp;
691 case 2:
692 golden_value = *tmp | *(tmp + 1) << 8;
693 case 3:
694 golden_value = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
695 default:
696 break;
697
698 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_BUFDBG_START + i*4);
699 if (reg != golden_value) {
700 printk(KERN_DEBUG "0x%x:", (u32)(ep->fusb300->reg +
701 FUSB300_OFFSET_BUFDBG_START + i*4));
702 printk(KERN_DEBUG " golden = 0x%x, reg = 0x%x\n",
703 golden_value, reg);
704 }
705 }
706
707 printk(KERN_DEBUG "fusb300_cmp_dbg_fifo : end\n");
708 fusb300_disable_bit(ep->fusb300, FUSB300_OFFSET_GTM,
709 FUSB300_GTM_TST_FIFO_DEG);
710}
711#endif
712
713static void fusb300_rdfifo(struct fusb300_ep *ep,
714 struct fusb300_request *req,
715 u32 length)
716{
717 int i = 0;
718 u8 *tmp;
719 u32 data, reg;
720 struct fusb300 *fusb300 = ep->fusb300;
721
722 tmp = req->req.buf + req->req.actual;
723 req->req.actual += length;
724
725 if (req->req.actual > req->req.length)
726 printk(KERN_DEBUG "req->req.actual > req->req.length\n");
727
728 for (i = (length >> 2); i > 0; i--) {
729 data = ioread32(fusb300->reg +
730 FUSB300_OFFSET_EPPORT(ep->epnum));
731 *tmp = data & 0xFF;
732 *(tmp + 1) = (data >> 8) & 0xFF;
733 *(tmp + 2) = (data >> 16) & 0xFF;
734 *(tmp + 3) = (data >> 24) & 0xFF;
735 tmp = tmp + 4;
736 }
737
738 switch (length % 4) {
739 case 1:
740 data = ioread32(fusb300->reg +
741 FUSB300_OFFSET_EPPORT(ep->epnum));
742 *tmp = data & 0xFF;
743 break;
744 case 2:
745 data = ioread32(fusb300->reg +
746 FUSB300_OFFSET_EPPORT(ep->epnum));
747 *tmp = data & 0xFF;
748 *(tmp + 1) = (data >> 8) & 0xFF;
749 break;
750 case 3:
751 data = ioread32(fusb300->reg +
752 FUSB300_OFFSET_EPPORT(ep->epnum));
753 *tmp = data & 0xFF;
754 *(tmp + 1) = (data >> 8) & 0xFF;
755 *(tmp + 2) = (data >> 16) & 0xFF;
756 break;
757 default:
758 break;
759 }
760
761 do {
762 reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
763 reg &= FUSB300_IGR1_SYNF0_EMPTY_INT;
764 if (i)
765 printk(KERN_INFO "sync fifo is not empty!\n");
766 i++;
767 } while (!reg);
768}
769
770/* write data to fifo */
771static void fusb300_wrfifo(struct fusb300_ep *ep,
772 struct fusb300_request *req)
773{
774 int i = 0;
775 u8 *tmp;
776 u32 data, reg;
777 struct fusb300 *fusb300 = ep->fusb300;
778
779 tmp = req->req.buf;
780 req->req.actual = req->req.length;
781
782 for (i = (req->req.length >> 2); i > 0; i--) {
783 data = *tmp | *(tmp + 1) << 8 |
784 *(tmp + 2) << 16 | *(tmp + 3) << 24;
785
786 iowrite32(data, fusb300->reg +
787 FUSB300_OFFSET_EPPORT(ep->epnum));
788 tmp += 4;
789 }
790
791 switch (req->req.length % 4) {
792 case 1:
793 data = *tmp;
794 iowrite32(data, fusb300->reg +
795 FUSB300_OFFSET_EPPORT(ep->epnum));
796 break;
797 case 2:
798 data = *tmp | *(tmp + 1) << 8;
799 iowrite32(data, fusb300->reg +
800 FUSB300_OFFSET_EPPORT(ep->epnum));
801 break;
802 case 3:
803 data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
804 iowrite32(data, fusb300->reg +
805 FUSB300_OFFSET_EPPORT(ep->epnum));
806 break;
807 default:
808 break;
809 }
810
811 do {
812 reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
813 reg &= FUSB300_IGR1_SYNF0_EMPTY_INT;
814 if (i)
815 printk(KERN_INFO"sync fifo is not empty!\n");
816 i++;
817 } while (!reg);
818}
819
820static u8 fusb300_get_epnstall(struct fusb300 *fusb300, u8 ep)
821{
822 u8 value;
823 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
824
825 value = reg & FUSB300_EPSET0_STL;
826
827 return value;
828}
829
830static u8 fusb300_get_cxstall(struct fusb300 *fusb300)
831{
832 u8 value;
833 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_CSR);
834
835 value = (reg & FUSB300_CSR_STL) >> 1;
836
837 return value;
838}
839
840static void request_error(struct fusb300 *fusb300)
841{
842 fusb300_set_cxstall(fusb300);
843 printk(KERN_DEBUG "request error!!\n");
844}
845
846static void get_status(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
847__releases(fusb300->lock)
848__acquires(fusb300->lock)
849{
850 u8 ep;
851 u16 status = 0;
852 u16 w_index = ctrl->wIndex;
853
854 switch (ctrl->bRequestType & USB_RECIP_MASK) {
855 case USB_RECIP_DEVICE:
856 status = 1 << USB_DEVICE_SELF_POWERED;
857 break;
858 case USB_RECIP_INTERFACE:
859 status = 0;
860 break;
861 case USB_RECIP_ENDPOINT:
862 ep = w_index & USB_ENDPOINT_NUMBER_MASK;
863 if (ep) {
864 if (fusb300_get_epnstall(fusb300, ep))
865 status = 1 << USB_ENDPOINT_HALT;
866 } else {
867 if (fusb300_get_cxstall(fusb300))
868 status = 0;
869 }
870 break;
871
872 default:
873 request_error(fusb300);
874 return; /* exit */
875 }
876
877 fusb300->ep0_data = cpu_to_le16(status);
878 fusb300->ep0_req->buf = &fusb300->ep0_data;
879 fusb300->ep0_req->length = 2;
880
881 spin_unlock(&fusb300->lock);
882 fusb300_queue(fusb300->gadget.ep0, fusb300->ep0_req, GFP_KERNEL);
883 spin_lock(&fusb300->lock);
884}
885
886static void set_feature(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
887{
888 u8 ep;
889
890 switch (ctrl->bRequestType & USB_RECIP_MASK) {
891 case USB_RECIP_DEVICE:
892 fusb300_set_cxdone(fusb300);
893 break;
894 case USB_RECIP_INTERFACE:
895 fusb300_set_cxdone(fusb300);
896 break;
897 case USB_RECIP_ENDPOINT: {
898 u16 w_index = le16_to_cpu(ctrl->wIndex);
899
900 ep = w_index & USB_ENDPOINT_NUMBER_MASK;
901 if (ep)
902 fusb300_set_epnstall(fusb300, ep);
903 else
904 fusb300_set_cxstall(fusb300);
905 fusb300_set_cxdone(fusb300);
906 }
907 break;
908 default:
909 request_error(fusb300);
910 break;
911 }
912}
913
914static void fusb300_clear_seqnum(struct fusb300 *fusb300, u8 ep)
915{
916 fusb300_enable_bit(fusb300, FUSB300_OFFSET_EPSET0(ep),
917 FUSB300_EPSET0_CLRSEQNUM);
918}
919
920static void clear_feature(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
921{
922 struct fusb300_ep *ep =
923 fusb300->ep[ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK];
924
925 switch (ctrl->bRequestType & USB_RECIP_MASK) {
926 case USB_RECIP_DEVICE:
927 fusb300_set_cxdone(fusb300);
928 break;
929 case USB_RECIP_INTERFACE:
930 fusb300_set_cxdone(fusb300);
931 break;
932 case USB_RECIP_ENDPOINT:
933 if (ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK) {
934 if (ep->wedged) {
935 fusb300_set_cxdone(fusb300);
936 break;
937 }
938 if (ep->stall) {
939 ep->stall = 0;
940 fusb300_clear_seqnum(fusb300, ep->epnum);
941 fusb300_clear_epnstall(fusb300, ep->epnum);
942 if (!list_empty(&ep->queue))
943 enable_fifo_int(ep);
944 }
945 }
946 fusb300_set_cxdone(fusb300);
947 break;
948 default:
949 request_error(fusb300);
950 break;
951 }
952}
953
954static void fusb300_set_dev_addr(struct fusb300 *fusb300, u16 addr)
955{
956 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_DAR);
957
958 reg &= ~FUSB300_DAR_DRVADDR_MSK;
959 reg |= FUSB300_DAR_DRVADDR(addr);
960
961 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_DAR);
962}
963
964static void set_address(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
965{
966 if (ctrl->wValue >= 0x0100)
967 request_error(fusb300);
968 else {
969 fusb300_set_dev_addr(fusb300, ctrl->wValue);
970 fusb300_set_cxdone(fusb300);
971 }
972}
973
974#define UVC_COPY_DESCRIPTORS(mem, src) \
975 do { \
976 const struct usb_descriptor_header * const *__src; \
977 for (__src = src; *__src; ++__src) { \
978 memcpy(mem, *__src, (*__src)->bLength); \
979 mem += (*__src)->bLength; \
980 } \
981 } while (0)
982
983static void fusb300_ep0_complete(struct usb_ep *ep,
984 struct usb_request *req)
985{
986}
987
988static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
989{
990 u8 *p = (u8 *)ctrl;
991 u8 ret = 0;
992 u8 i = 0;
993
994 fusb300_rdcxf(fusb300, p, 8);
995 fusb300->ep0_dir = ctrl->bRequestType & USB_DIR_IN;
996 fusb300->ep0_length = ctrl->wLength;
997
998 /* check request */
999 if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
1000 switch (ctrl->bRequest) {
1001 case USB_REQ_GET_STATUS:
1002 get_status(fusb300, ctrl);
1003 break;
1004 case USB_REQ_CLEAR_FEATURE:
1005 clear_feature(fusb300, ctrl);
1006 break;
1007 case USB_REQ_SET_FEATURE:
1008 set_feature(fusb300, ctrl);
1009 break;
1010 case USB_REQ_SET_ADDRESS:
1011 set_address(fusb300, ctrl);
1012 break;
1013 case USB_REQ_SET_CONFIGURATION:
1014 fusb300_enable_bit(fusb300, FUSB300_OFFSET_DAR,
1015 FUSB300_DAR_SETCONFG);
1016 /* clear sequence number */
1017 for (i = 1; i <= FUSB300_MAX_NUM_EP; i++)
1018 fusb300_clear_seqnum(fusb300, i);
1019 fusb300->reenum = 1;
1020 ret = 1;
1021 break;
1022 default:
1023 ret = 1;
1024 break;
1025 }
1026 } else
1027 ret = 1;
1028
1029 return ret;
1030}
1031
1032static void fusb300_set_ep_bycnt(struct fusb300_ep *ep, u32 bycnt)
1033{
1034 struct fusb300 *fusb300 = ep->fusb300;
1035 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
1036
1037 reg &= ~FUSB300_FFR_BYCNT;
1038 reg |= bycnt & FUSB300_FFR_BYCNT;
1039
1040 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
1041}
1042
1043static void done(struct fusb300_ep *ep, struct fusb300_request *req,
1044 int status)
1045{
1046 list_del_init(&req->queue);
1047
1048 /* don't modify queue heads during completion callback */
1049 if (ep->fusb300->gadget.speed == USB_SPEED_UNKNOWN)
1050 req->req.status = -ESHUTDOWN;
1051 else
1052 req->req.status = status;
1053
1054 spin_unlock(&ep->fusb300->lock);
1055 req->req.complete(&ep->ep, &req->req);
1056 spin_lock(&ep->fusb300->lock);
1057
1058 if (ep->epnum) {
1059 disable_fifo_int(ep);
1060 if (!list_empty(&ep->queue))
1061 enable_fifo_int(ep);
1062 } else
1063 fusb300_set_cxdone(ep->fusb300);
1064}
1065
1066void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep,
1067 struct fusb300_request *req)
1068{
1069 u32 value;
1070 u32 reg;
1071
1072 /* wait SW owner */
1073 do {
1074 reg = ioread32(ep->fusb300->reg +
1075 FUSB300_OFFSET_EPPRD_W0(ep->epnum));
1076 reg &= FUSB300_EPPRD0_H;
1077 } while (reg);
1078
1079 iowrite32((u32) req->req.buf, ep->fusb300->reg +
1080 FUSB300_OFFSET_EPPRD_W1(ep->epnum));
1081
1082 value = FUSB300_EPPRD0_BTC(req->req.length) | FUSB300_EPPRD0_H |
1083 FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I;
1084 iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum));
1085
1086 iowrite32(0x0, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W2(ep->epnum));
1087
1088 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_EPPRDRDY,
1089 FUSB300_EPPRDR_EP_PRD_RDY(ep->epnum));
1090}
1091
1092static void fusb300_wait_idma_finished(struct fusb300_ep *ep)
1093{
1094 u32 reg;
1095
1096 do {
1097 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR1);
1098 if ((reg & FUSB300_IGR1_VBUS_CHG_INT) ||
1099 (reg & FUSB300_IGR1_WARM_RST_INT) ||
1100 (reg & FUSB300_IGR1_HOT_RST_INT) ||
1101 (reg & FUSB300_IGR1_USBRST_INT)
1102 )
1103 goto IDMA_RESET;
1104 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR0);
1105 reg &= FUSB300_IGR0_EPn_PRD_INT(ep->epnum);
1106 } while (!reg);
1107
1108 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0,
1109 FUSB300_IGR0_EPn_PRD_INT(ep->epnum));
1110IDMA_RESET:
1111 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGER0,
1112 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
1113}
1114
1115static void fusb300_set_idma(struct fusb300_ep *ep,
1116 struct fusb300_request *req)
1117{
1118 dma_addr_t d;
1119 u8 *tmp = NULL;
1120
1121 d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE);
1122
1123 if (dma_mapping_error(NULL, d)) {
1124 kfree(req->req.buf);
1125 printk(KERN_DEBUG "dma_mapping_error\n");
1126 }
1127
1128 dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE);
1129
1130 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0,
1131 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
1132
1133 tmp = req->req.buf;
1134 req->req.buf = (u8 *)d;
1135
1136 fusb300_fill_idma_prdtbl(ep, req);
1137 /* check idma is done */
1138 fusb300_wait_idma_finished(ep);
1139
1140 req->req.buf = tmp;
1141
1142 if (d)
1143 dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE);
1144}
1145
1146static void in_ep_fifo_handler(struct fusb300_ep *ep)
1147{
1148 struct fusb300_request *req = list_entry(ep->queue.next,
1149 struct fusb300_request, queue);
1150
1151 if (req->req.length) {
1152#if 0
1153 fusb300_set_ep_bycnt(ep, req->req.length);
1154 fusb300_wrfifo(ep, req);
1155#else
1156 fusb300_set_idma(ep, req);
1157#endif
1158 }
1159 done(ep, req, 0);
1160}
1161
1162static void out_ep_fifo_handler(struct fusb300_ep *ep)
1163{
1164 struct fusb300 *fusb300 = ep->fusb300;
1165 struct fusb300_request *req = list_entry(ep->queue.next,
1166 struct fusb300_request, queue);
1167 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
1168 u32 length = reg & FUSB300_FFR_BYCNT;
1169
1170 fusb300_rdfifo(ep, req, length);
1171
1172 /* finish out transfer */
1173 if ((req->req.length == req->req.actual) || (length < ep->ep.maxpacket))
1174 done(ep, req, 0);
1175}
1176
1177static void check_device_mode(struct fusb300 *fusb300)
1178{
1179 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_GCR);
1180
1181 switch (reg & FUSB300_GCR_DEVEN_MSK) {
1182 case FUSB300_GCR_DEVEN_SS:
1183 fusb300->gadget.speed = USB_SPEED_SUPER;
1184 break;
1185 case FUSB300_GCR_DEVEN_HS:
1186 fusb300->gadget.speed = USB_SPEED_HIGH;
1187 break;
1188 case FUSB300_GCR_DEVEN_FS:
1189 fusb300->gadget.speed = USB_SPEED_FULL;
1190 break;
1191 default:
1192 fusb300->gadget.speed = USB_SPEED_UNKNOWN;
1193 break;
1194 }
1195 printk(KERN_INFO "dev_mode = %d\n", (reg & FUSB300_GCR_DEVEN_MSK));
1196}
1197
1198
1199static void fusb300_ep0out(struct fusb300 *fusb300)
1200{
1201 struct fusb300_ep *ep = fusb300->ep[0];
1202 u32 reg;
1203
1204 if (!list_empty(&ep->queue)) {
1205 struct fusb300_request *req;
1206
1207 req = list_first_entry(&ep->queue,
1208 struct fusb300_request, queue);
1209 if (req->req.length)
1210 fusb300_rdcxf(ep->fusb300, req->req.buf,
1211 req->req.length);
1212 done(ep, req, 0);
1213 reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1);
1214 reg &= ~FUSB300_IGER1_CX_OUT_INT;
1215 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_IGER1);
1216 } else
1217 pr_err("%s : empty queue\n", __func__);
1218}
1219
1220static void fusb300_ep0in(struct fusb300 *fusb300)
1221{
1222 struct fusb300_request *req;
1223 struct fusb300_ep *ep = fusb300->ep[0];
1224
1225 if ((!list_empty(&ep->queue)) && (fusb300->ep0_dir)) {
1226 req = list_entry(ep->queue.next,
1227 struct fusb300_request, queue);
1228 if (req->req.length)
1229 fusb300_wrcxf(ep, req);
1230 if ((req->req.length - req->req.actual) < ep->ep.maxpacket)
1231 done(ep, req, 0);
1232 } else
1233 fusb300_set_cxdone(fusb300);
1234}
1235
1236static void fusb300_grp2_handler(void)
1237{
1238}
1239
1240static void fusb300_grp3_handler(void)
1241{
1242}
1243
1244static void fusb300_grp4_handler(void)
1245{
1246}
1247
1248static void fusb300_grp5_handler(void)
1249{
1250}
1251
1252static irqreturn_t fusb300_irq(int irq, void *_fusb300)
1253{
1254 struct fusb300 *fusb300 = _fusb300;
1255 u32 int_grp1 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
1256 u32 int_grp1_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1);
1257 u32 int_grp0 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR0);
1258 u32 int_grp0_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER0);
1259 struct usb_ctrlrequest ctrl;
1260 u8 in;
1261 u32 reg;
1262 int i;
1263
1264 spin_lock(&fusb300->lock);
1265
1266 int_grp1 &= int_grp1_en;
1267 int_grp0 &= int_grp0_en;
1268
1269 if (int_grp1 & FUSB300_IGR1_WARM_RST_INT) {
1270 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1271 FUSB300_IGR1_WARM_RST_INT);
1272 printk(KERN_INFO"fusb300_warmreset\n");
1273 fusb300_reset();
1274 }
1275
1276 if (int_grp1 & FUSB300_IGR1_HOT_RST_INT) {
1277 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1278 FUSB300_IGR1_HOT_RST_INT);
1279 printk(KERN_INFO"fusb300_hotreset\n");
1280 fusb300_reset();
1281 }
1282
1283 if (int_grp1 & FUSB300_IGR1_USBRST_INT) {
1284 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1285 FUSB300_IGR1_USBRST_INT);
1286 fusb300_reset();
1287 }
1288 /* COMABT_INT has a highest priority */
1289
1290 if (int_grp1 & FUSB300_IGR1_CX_COMABT_INT) {
1291 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1292 FUSB300_IGR1_CX_COMABT_INT);
1293 printk(KERN_INFO"fusb300_ep0abt\n");
1294 }
1295
1296 if (int_grp1 & FUSB300_IGR1_VBUS_CHG_INT) {
1297 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1298 FUSB300_IGR1_VBUS_CHG_INT);
1299 printk(KERN_INFO"fusb300_vbus_change\n");
1300 }
1301
1302 if (int_grp1 & FUSB300_IGR1_U3_EXIT_FAIL_INT) {
1303 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1304 FUSB300_IGR1_U3_EXIT_FAIL_INT);
1305 }
1306
1307 if (int_grp1 & FUSB300_IGR1_U2_EXIT_FAIL_INT) {
1308 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1309 FUSB300_IGR1_U2_EXIT_FAIL_INT);
1310 }
1311
1312 if (int_grp1 & FUSB300_IGR1_U1_EXIT_FAIL_INT) {
1313 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1314 FUSB300_IGR1_U1_EXIT_FAIL_INT);
1315 }
1316
1317 if (int_grp1 & FUSB300_IGR1_U2_ENTRY_FAIL_INT) {
1318 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1319 FUSB300_IGR1_U2_ENTRY_FAIL_INT);
1320 }
1321
1322 if (int_grp1 & FUSB300_IGR1_U1_ENTRY_FAIL_INT) {
1323 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1324 FUSB300_IGR1_U1_ENTRY_FAIL_INT);
1325 }
1326
1327 if (int_grp1 & FUSB300_IGR1_U3_EXIT_INT) {
1328 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1329 FUSB300_IGR1_U3_EXIT_INT);
1330 printk(KERN_INFO "FUSB300_IGR1_U3_EXIT_INT\n");
1331 }
1332
1333 if (int_grp1 & FUSB300_IGR1_U2_EXIT_INT) {
1334 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1335 FUSB300_IGR1_U2_EXIT_INT);
1336 printk(KERN_INFO "FUSB300_IGR1_U2_EXIT_INT\n");
1337 }
1338
1339 if (int_grp1 & FUSB300_IGR1_U1_EXIT_INT) {
1340 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1341 FUSB300_IGR1_U1_EXIT_INT);
1342 printk(KERN_INFO "FUSB300_IGR1_U1_EXIT_INT\n");
1343 }
1344
1345 if (int_grp1 & FUSB300_IGR1_U3_ENTRY_INT) {
1346 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1347 FUSB300_IGR1_U3_ENTRY_INT);
1348 printk(KERN_INFO "FUSB300_IGR1_U3_ENTRY_INT\n");
1349 fusb300_enable_bit(fusb300, FUSB300_OFFSET_SSCR1,
1350 FUSB300_SSCR1_GO_U3_DONE);
1351 }
1352
1353 if (int_grp1 & FUSB300_IGR1_U2_ENTRY_INT) {
1354 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1355 FUSB300_IGR1_U2_ENTRY_INT);
1356 printk(KERN_INFO "FUSB300_IGR1_U2_ENTRY_INT\n");
1357 }
1358
1359 if (int_grp1 & FUSB300_IGR1_U1_ENTRY_INT) {
1360 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1361 FUSB300_IGR1_U1_ENTRY_INT);
1362 printk(KERN_INFO "FUSB300_IGR1_U1_ENTRY_INT\n");
1363 }
1364
1365 if (int_grp1 & FUSB300_IGR1_RESM_INT) {
1366 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1367 FUSB300_IGR1_RESM_INT);
1368 printk(KERN_INFO "fusb300_resume\n");
1369 }
1370
1371 if (int_grp1 & FUSB300_IGR1_SUSP_INT) {
1372 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1373 FUSB300_IGR1_SUSP_INT);
1374 printk(KERN_INFO "fusb300_suspend\n");
1375 }
1376
1377 if (int_grp1 & FUSB300_IGR1_HS_LPM_INT) {
1378 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1379 FUSB300_IGR1_HS_LPM_INT);
1380 printk(KERN_INFO "fusb300_HS_LPM_INT\n");
1381 }
1382
1383 if (int_grp1 & FUSB300_IGR1_DEV_MODE_CHG_INT) {
1384 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1385 FUSB300_IGR1_DEV_MODE_CHG_INT);
1386 check_device_mode(fusb300);
1387 }
1388
1389 if (int_grp1 & FUSB300_IGR1_CX_COMFAIL_INT) {
1390 fusb300_set_cxstall(fusb300);
1391 printk(KERN_INFO "fusb300_ep0fail\n");
1392 }
1393
1394 if (int_grp1 & FUSB300_IGR1_CX_SETUP_INT) {
1395 printk(KERN_INFO "fusb300_ep0setup\n");
1396 if (setup_packet(fusb300, &ctrl)) {
1397 spin_unlock(&fusb300->lock);
1398 if (fusb300->driver->setup(&fusb300->gadget, &ctrl) < 0)
1399 fusb300_set_cxstall(fusb300);
1400 spin_lock(&fusb300->lock);
1401 }
1402 }
1403
1404 if (int_grp1 & FUSB300_IGR1_CX_CMDEND_INT)
1405 printk(KERN_INFO "fusb300_cmdend\n");
1406
1407
1408 if (int_grp1 & FUSB300_IGR1_CX_OUT_INT) {
1409 printk(KERN_INFO "fusb300_cxout\n");
1410 fusb300_ep0out(fusb300);
1411 }
1412
1413 if (int_grp1 & FUSB300_IGR1_CX_IN_INT) {
1414 printk(KERN_INFO "fusb300_cxin\n");
1415 fusb300_ep0in(fusb300);
1416 }
1417
1418 if (int_grp1 & FUSB300_IGR1_INTGRP5)
1419 fusb300_grp5_handler();
1420
1421 if (int_grp1 & FUSB300_IGR1_INTGRP4)
1422 fusb300_grp4_handler();
1423
1424 if (int_grp1 & FUSB300_IGR1_INTGRP3)
1425 fusb300_grp3_handler();
1426
1427 if (int_grp1 & FUSB300_IGR1_INTGRP2)
1428 fusb300_grp2_handler();
1429
1430 if (int_grp0) {
1431 for (i = 1; i < FUSB300_MAX_NUM_EP; i++) {
1432 if (int_grp0 & FUSB300_IGR0_EPn_FIFO_INT(i)) {
1433 reg = ioread32(fusb300->reg +
1434 FUSB300_OFFSET_EPSET1(i));
1435 in = (reg & FUSB300_EPSET1_DIRIN) ? 1 : 0;
1436 if (in)
1437 in_ep_fifo_handler(fusb300->ep[i]);
1438 else
1439 out_ep_fifo_handler(fusb300->ep[i]);
1440 }
1441 }
1442 }
1443
1444 spin_unlock(&fusb300->lock);
1445
1446 return IRQ_HANDLED;
1447}
1448
1449static void fusb300_set_u2_timeout(struct fusb300 *fusb300,
1450 u32 time)
1451{
1452 u32 reg;
1453
1454 reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT);
1455 reg &= ~0xff;
1456 reg |= FUSB300_SSCR2_U2TIMEOUT(time);
1457
1458 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT);
1459}
1460
1461static void fusb300_set_u1_timeout(struct fusb300 *fusb300,
1462 u32 time)
1463{
1464 u32 reg;
1465
1466 reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT);
1467 reg &= ~(0xff << 8);
1468 reg |= FUSB300_SSCR2_U1TIMEOUT(time);
1469
1470 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT);
1471}
1472
1473static void init_controller(struct fusb300 *fusb300)
1474{
1475 u32 reg;
1476 u32 mask = 0;
1477 u32 val = 0;
1478
1479 /* split on */
1480 mask = val = FUSB300_AHBBCR_S0_SPLIT_ON | FUSB300_AHBBCR_S1_SPLIT_ON;
1481 reg = ioread32(fusb300->reg + FUSB300_OFFSET_AHBCR);
1482 reg &= ~mask;
1483 reg |= val;
1484 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_AHBCR);
1485
1486 /* enable high-speed LPM */
1487 mask = val = FUSB300_HSCR_HS_LPM_PERMIT;
1488 reg = ioread32(fusb300->reg + FUSB300_OFFSET_HSCR);
1489 reg &= ~mask;
1490 reg |= val;
1491 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_HSCR);
1492
1493 /*set u1 u2 timmer*/
1494 fusb300_set_u2_timeout(fusb300, 0xff);
1495 fusb300_set_u1_timeout(fusb300, 0xff);
1496
1497 /* enable all grp1 interrupt */
1498 iowrite32(0xcfffff9f, fusb300->reg + FUSB300_OFFSET_IGER1);
1499}
1500/*------------------------------------------------------------------------*/
1501static struct fusb300 *the_controller;
1502
1503int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1504 int (*bind)(struct usb_gadget *))
1505{
1506 struct fusb300 *fusb300 = the_controller;
1507 int retval;
1508
1509 if (!driver
1510 || driver->speed < USB_SPEED_FULL
1511 || !bind
1512 || !driver->setup)
1513 return -EINVAL;
1514
1515 if (!fusb300)
1516 return -ENODEV;
1517
1518 if (fusb300->driver)
1519 return -EBUSY;
1520
1521 /* hook up the driver */
1522 driver->driver.bus = NULL;
1523 fusb300->driver = driver;
1524 fusb300->gadget.dev.driver = &driver->driver;
1525
1526 retval = device_add(&fusb300->gadget.dev);
1527 if (retval) {
1528 pr_err("device_add error (%d)\n", retval);
1529 goto error;
1530 }
1531
1532 retval = bind(&fusb300->gadget);
1533 if (retval) {
1534 pr_err("bind to driver error (%d)\n", retval);
1535 device_del(&fusb300->gadget.dev);
1536 goto error;
1537 }
1538
1539 return 0;
1540
1541error:
1542 fusb300->driver = NULL;
1543 fusb300->gadget.dev.driver = NULL;
1544
1545 return retval;
1546}
1547EXPORT_SYMBOL(usb_gadget_probe_driver);
1548
1549int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1550{
1551 struct fusb300 *fusb300 = the_controller;
1552
1553 if (driver != fusb300->driver || !driver->unbind)
1554 return -EINVAL;
1555
1556 driver->unbind(&fusb300->gadget);
1557 fusb300->gadget.dev.driver = NULL;
1558
1559 init_controller(fusb300);
1560 device_del(&fusb300->gadget.dev);
1561 fusb300->driver = NULL;
1562
1563 return 0;
1564}
1565EXPORT_SYMBOL(usb_gadget_unregister_driver);
1566/*--------------------------------------------------------------------------*/
1567
1568static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
1569{
1570 return 0;
1571}
1572
1573static struct usb_gadget_ops fusb300_gadget_ops = {
1574 .pullup = fusb300_udc_pullup,
1575};
1576
1577static int __exit fusb300_remove(struct platform_device *pdev)
1578{
1579 struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev);
1580
1581 iounmap(fusb300->reg);
1582 free_irq(platform_get_irq(pdev, 0), fusb300);
1583
1584 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
1585 kfree(fusb300);
1586
1587 return 0;
1588}
1589
1590static int __init fusb300_probe(struct platform_device *pdev)
1591{
1592 struct resource *res, *ires, *ires1;
1593 void __iomem *reg = NULL;
1594 struct fusb300 *fusb300 = NULL;
1595 struct fusb300_ep *_ep[FUSB300_MAX_NUM_EP];
1596 int ret = 0;
1597 int i;
1598
1599 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1600 if (!res) {
1601 ret = -ENODEV;
1602 pr_err("platform_get_resource error.\n");
1603 goto clean_up;
1604 }
1605
1606 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1607 if (!ires) {
1608 ret = -ENODEV;
1609 dev_err(&pdev->dev,
1610 "platform_get_resource IORESOURCE_IRQ error.\n");
1611 goto clean_up;
1612 }
1613
1614 ires1 = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
1615 if (!ires1) {
1616 ret = -ENODEV;
1617 dev_err(&pdev->dev,
1618 "platform_get_resource IORESOURCE_IRQ 1 error.\n");
1619 goto clean_up;
1620 }
1621
1622 reg = ioremap(res->start, resource_size(res));
1623 if (reg == NULL) {
1624 ret = -ENOMEM;
1625 pr_err("ioremap error.\n");
1626 goto clean_up;
1627 }
1628
1629 /* initialize udc */
1630 fusb300 = kzalloc(sizeof(struct fusb300), GFP_KERNEL);
1631 if (fusb300 == NULL) {
1632 pr_err("kzalloc error\n");
1633 goto clean_up;
1634 }
1635
1636 for (i = 0; i < FUSB300_MAX_NUM_EP; i++) {
1637 _ep[i] = kzalloc(sizeof(struct fusb300_ep), GFP_KERNEL);
1638 if (_ep[i] == NULL) {
1639 pr_err("_ep kzalloc error\n");
1640 goto clean_up;
1641 }
1642 fusb300->ep[i] = _ep[i];
1643 }
1644
1645 spin_lock_init(&fusb300->lock);
1646
1647 dev_set_drvdata(&pdev->dev, fusb300);
1648
1649 fusb300->gadget.ops = &fusb300_gadget_ops;
1650
1651 device_initialize(&fusb300->gadget.dev);
1652
1653 dev_set_name(&fusb300->gadget.dev, "gadget");
1654
1655 fusb300->gadget.is_dualspeed = 1;
1656 fusb300->gadget.dev.parent = &pdev->dev;
1657 fusb300->gadget.dev.dma_mask = pdev->dev.dma_mask;
1658 fusb300->gadget.dev.release = pdev->dev.release;
1659 fusb300->gadget.name = udc_name;
1660 fusb300->reg = reg;
1661
1662 ret = request_irq(ires->start, fusb300_irq, IRQF_DISABLED | IRQF_SHARED,
1663 udc_name, fusb300);
1664 if (ret < 0) {
1665 pr_err("request_irq error (%d)\n", ret);
1666 goto clean_up;
1667 }
1668
1669 ret = request_irq(ires1->start, fusb300_irq,
1670 IRQF_DISABLED | IRQF_SHARED, udc_name, fusb300);
1671 if (ret < 0) {
1672 pr_err("request_irq1 error (%d)\n", ret);
1673 goto clean_up;
1674 }
1675
1676 INIT_LIST_HEAD(&fusb300->gadget.ep_list);
1677
1678 for (i = 0; i < FUSB300_MAX_NUM_EP ; i++) {
1679 struct fusb300_ep *ep = fusb300->ep[i];
1680
1681 if (i != 0) {
1682 INIT_LIST_HEAD(&fusb300->ep[i]->ep.ep_list);
1683 list_add_tail(&fusb300->ep[i]->ep.ep_list,
1684 &fusb300->gadget.ep_list);
1685 }
1686 ep->fusb300 = fusb300;
1687 INIT_LIST_HEAD(&ep->queue);
1688 ep->ep.name = fusb300_ep_name[i];
1689 ep->ep.ops = &fusb300_ep_ops;
1690 ep->ep.maxpacket = HS_BULK_MAX_PACKET_SIZE;
1691 }
1692 fusb300->ep[0]->ep.maxpacket = HS_CTL_MAX_PACKET_SIZE;
1693 fusb300->ep[0]->epnum = 0;
1694 fusb300->gadget.ep0 = &fusb300->ep[0]->ep;
1695 INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list);
1696
1697 the_controller = fusb300;
1698
1699 fusb300->ep0_req = fusb300_alloc_request(&fusb300->ep[0]->ep,
1700 GFP_KERNEL);
1701 if (fusb300->ep0_req == NULL)
1702 goto clean_up3;
1703
1704 init_controller(fusb300);
1705 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1706
1707 return 0;
1708
1709clean_up3:
1710 free_irq(ires->start, fusb300);
1711
1712clean_up:
1713 if (fusb300) {
1714 if (fusb300->ep0_req)
1715 fusb300_free_request(&fusb300->ep[0]->ep,
1716 fusb300->ep0_req);
1717 kfree(fusb300);
1718 }
1719 if (reg)
1720 iounmap(reg);
1721
1722 return ret;
1723}
1724
1725static struct platform_driver fusb300_driver = {
1726 .remove = __exit_p(fusb300_remove),
1727 .driver = {
1728 .name = (char *) udc_name,
1729 .owner = THIS_MODULE,
1730 },
1731};
1732
1733static int __init fusb300_udc_init(void)
1734{
1735 return platform_driver_probe(&fusb300_driver, fusb300_probe);
1736}
1737
1738module_init(fusb300_udc_init);
1739
1740static void __exit fusb300_udc_cleanup(void)
1741{
1742 platform_driver_unregister(&fusb300_driver);
1743}
1744module_exit(fusb300_udc_cleanup);
diff --git a/drivers/usb/gadget/fusb300_udc.h b/drivers/usb/gadget/fusb300_udc.h
new file mode 100644
index 000000000000..f51aa2ef1f90
--- /dev/null
+++ b/drivers/usb/gadget/fusb300_udc.h
@@ -0,0 +1,687 @@
1/*
2 * Fusb300 UDC (USB gadget)
3 *
4 * Copyright (C) 2010 Faraday Technology Corp.
5 *
6 * Author : Yuan-hsin Chen <yhchen@faraday-tech.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23
24#ifndef __FUSB300_UDC_H__
25#define __FUSB300_UDC_H_
26
27#include <linux/kernel.h>
28
29#define FUSB300_OFFSET_GCR 0x00
30#define FUSB300_OFFSET_GTM 0x04
31#define FUSB300_OFFSET_DAR 0x08
32#define FUSB300_OFFSET_CSR 0x0C
33#define FUSB300_OFFSET_CXPORT 0x10
34#define FUSB300_OFFSET_EPSET0(n) (0x20 + (n - 1) * 0x30)
35#define FUSB300_OFFSET_EPSET1(n) (0x24 + (n - 1) * 0x30)
36#define FUSB300_OFFSET_EPSET2(n) (0x28 + (n - 1) * 0x30)
37#define FUSB300_OFFSET_EPFFR(n) (0x2c + (n - 1) * 0x30)
38#define FUSB300_OFFSET_EPSTRID(n) (0x40 + (n - 1) * 0x30)
39#define FUSB300_OFFSET_HSPTM 0x300
40#define FUSB300_OFFSET_HSCR 0x304
41#define FUSB300_OFFSET_SSCR0 0x308
42#define FUSB300_OFFSET_SSCR1 0x30C
43#define FUSB300_OFFSET_TT 0x310
44#define FUSB300_OFFSET_DEVNOTF 0x314
45#define FUSB300_OFFSET_DNC1 0x318
46#define FUSB300_OFFSET_CS 0x31C
47#define FUSB300_OFFSET_SOF 0x324
48#define FUSB300_OFFSET_EFCS 0x328
49#define FUSB300_OFFSET_IGR0 0x400
50#define FUSB300_OFFSET_IGR1 0x404
51#define FUSB300_OFFSET_IGR2 0x408
52#define FUSB300_OFFSET_IGR3 0x40C
53#define FUSB300_OFFSET_IGR4 0x410
54#define FUSB300_OFFSET_IGR5 0x414
55#define FUSB300_OFFSET_IGER0 0x420
56#define FUSB300_OFFSET_IGER1 0x424
57#define FUSB300_OFFSET_IGER2 0x428
58#define FUSB300_OFFSET_IGER3 0x42C
59#define FUSB300_OFFSET_IGER4 0x430
60#define FUSB300_OFFSET_IGER5 0x434
61#define FUSB300_OFFSET_DMAHMER 0x500
62#define FUSB300_OFFSET_EPPRDRDY 0x504
63#define FUSB300_OFFSET_DMAEPMR 0x508
64#define FUSB300_OFFSET_DMAENR 0x50C
65#define FUSB300_OFFSET_DMAAPR 0x510
66#define FUSB300_OFFSET_AHBCR 0x514
67#define FUSB300_OFFSET_EPPRD_W0(n) (0x520 + (n - 1) * 0x10)
68#define FUSB300_OFFSET_EPPRD_W1(n) (0x524 + (n - 1) * 0x10)
69#define FUSB300_OFFSET_EPPRD_W2(n) (0x528 + (n - 1) * 0x10)
70#define FUSB300_OFFSET_EPRD_PTR(n) (0x52C + (n - 1) * 0x10)
71#define FUSB300_OFFSET_BUFDBG_START 0x800
72#define FUSB300_OFFSET_BUFDBG_END 0xBFC
73#define FUSB300_OFFSET_EPPORT(n) (0x1010 + (n - 1) * 0x10)
74
75/*
76 * * Global Control Register (offset = 000H)
77 * */
78#define FUSB300_GCR_SF_RST (1 << 8)
79#define FUSB300_GCR_VBUS_STATUS (1 << 7)
80#define FUSB300_GCR_FORCE_HS_SUSP (1 << 6)
81#define FUSB300_GCR_SYNC_FIFO1_CLR (1 << 5)
82#define FUSB300_GCR_SYNC_FIFO0_CLR (1 << 4)
83#define FUSB300_GCR_FIFOCLR (1 << 3)
84#define FUSB300_GCR_GLINTEN (1 << 2)
85#define FUSB300_GCR_DEVEN_FS 0x3
86#define FUSB300_GCR_DEVEN_HS 0x2
87#define FUSB300_GCR_DEVEN_SS 0x1
88#define FUSB300_GCR_DEVDIS 0x0
89#define FUSB300_GCR_DEVEN_MSK 0x3
90
91
92/*
93 * *Global Test Mode (offset = 004H)
94 * */
95#define FUSB300_GTM_TST_DIS_SOFGEN (1 << 16)
96#define FUSB300_GTM_TST_CUR_EP_ENTRY(n) ((n & 0xF) << 12)
97#define FUSB300_GTM_TST_EP_ENTRY(n) ((n & 0xF) << 8)
98#define FUSB300_GTM_TST_EP_NUM(n) ((n & 0xF) << 4)
99#define FUSB300_GTM_TST_FIFO_DEG (1 << 1)
100#define FUSB300_GTM_TSTMODE (1 << 0)
101
102/*
103 * * Device Address Register (offset = 008H)
104 * */
105#define FUSB300_DAR_SETCONFG (1 << 7)
106#define FUSB300_DAR_DRVADDR(x) (x & 0x7F)
107#define FUSB300_DAR_DRVADDR_MSK 0x7F
108
109/*
110 * *Control Transfer Configuration and Status Register
111 * (CX_Config_Status, offset = 00CH)
112 * */
113#define FUSB300_CSR_LEN(x) ((x & 0xFFFF) << 8)
114#define FUSB300_CSR_LEN_MSK (0xFFFF << 8)
115#define FUSB300_CSR_EMP (1 << 4)
116#define FUSB300_CSR_FUL (1 << 3)
117#define FUSB300_CSR_CLR (1 << 2)
118#define FUSB300_CSR_STL (1 << 1)
119#define FUSB300_CSR_DONE (1 << 0)
120
121/*
122 * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 )
123 * */
124#define FUSB300_EPSET0_CLRSEQNUM (1 << 2)
125#define FUSB300_EPSET0_EPn_TX0BYTE (1 << 1)
126#define FUSB300_EPSET0_STL (1 << 0)
127
128/*
129 * * EPn Setting 1 (EPn_SET1, offset = 024H+(n-1)*30H, n=1~15)
130 * */
131#define FUSB300_EPSET1_START_ENTRY(x) ((x & 0xFF) << 24)
132#define FUSB300_EPSET1_START_ENTRY_MSK (0xFF << 24)
133#define FUSB300_EPSET1_FIFOENTRY(x) ((x & 0x1F) << 12)
134#define FUSB300_EPSET1_FIFOENTRY_MSK (0x1f << 12)
135#define FUSB300_EPSET1_INTERVAL(x) ((x & 0x7) << 6)
136#define FUSB300_EPSET1_BWNUM(x) ((x & 0x3) << 4)
137#define FUSB300_EPSET1_TYPEISO (1 << 2)
138#define FUSB300_EPSET1_TYPEBLK (2 << 2)
139#define FUSB300_EPSET1_TYPEINT (3 << 2)
140#define FUSB300_EPSET1_TYPE(x) ((x & 0x3) << 2)
141#define FUSB300_EPSET1_TYPE_MSK (0x3 << 2)
142#define FUSB300_EPSET1_DIROUT (0 << 1)
143#define FUSB300_EPSET1_DIRIN (1 << 1)
144#define FUSB300_EPSET1_DIR(x) ((x & 0x1) << 1)
145#define FUSB300_EPSET1_DIRIN (1 << 1)
146#define FUSB300_EPSET1_DIR_MSK ((0x1) << 1)
147#define FUSB300_EPSET1_ACTDIS 0
148#define FUSB300_EPSET1_ACTEN 1
149
150/*
151 * *EPn Setting 2 (EPn_SET2, offset = 028H+(n-1)*30H, n=1~15)
152 * */
153#define FUSB300_EPSET2_ADDROFS(x) ((x & 0x7FFF) << 16)
154#define FUSB300_EPSET2_ADDROFS_MSK (0x7fff << 16)
155#define FUSB300_EPSET2_MPS(x) (x & 0x7FF)
156#define FUSB300_EPSET2_MPS_MSK 0x7FF
157
158/*
159 * * EPn FIFO Register (offset = 2cH+(n-1)*30H)
160 * */
161#define FUSB300_FFR_RST (1 << 31)
162#define FUSB300_FF_FUL (1 << 30)
163#define FUSB300_FF_EMPTY (1 << 29)
164#define FUSB300_FFR_BYCNT 0x1FFFF
165
166/*
167 * *EPn Stream ID (EPn_STR_ID, offset = 040H+(n-1)*30H, n=1~15)
168 * */
169#define FUSB300_STRID_STREN (1 << 16)
170#define FUSB300_STRID_STRID(x) (x & 0xFFFF)
171
172/*
173 * *HS PHY Test Mode (offset = 300H)
174 * */
175#define FUSB300_HSPTM_TSTPKDONE (1 << 4)
176#define FUSB300_HSPTM_TSTPKT (1 << 3)
177#define FUSB300_HSPTM_TSTSET0NAK (1 << 2)
178#define FUSB300_HSPTM_TSTKSTA (1 << 1)
179#define FUSB300_HSPTM_TSTJSTA (1 << 0)
180
181/*
182 * *HS Control Register (offset = 304H)
183 * */
184#define FUSB300_HSCR_HS_LPM_PERMIT (1 << 8)
185#define FUSB300_HSCR_HS_LPM_RMWKUP (1 << 7)
186#define FUSB300_HSCR_CAP_LPM_RMWKUP (1 << 6)
187#define FUSB300_HSCR_HS_GOSUSP (1 << 5)
188#define FUSB300_HSCR_HS_GORMWKU (1 << 4)
189#define FUSB300_HSCR_CAP_RMWKUP (1 << 3)
190#define FUSB300_HSCR_IDLECNT_0MS 0
191#define FUSB300_HSCR_IDLECNT_1MS 1
192#define FUSB300_HSCR_IDLECNT_2MS 2
193#define FUSB300_HSCR_IDLECNT_3MS 3
194#define FUSB300_HSCR_IDLECNT_4MS 4
195#define FUSB300_HSCR_IDLECNT_5MS 5
196#define FUSB300_HSCR_IDLECNT_6MS 6
197#define FUSB300_HSCR_IDLECNT_7MS 7
198
199/*
200 * * SS Controller Register 0 (offset = 308H)
201 * */
202#define FUSB300_SSCR0_MAX_INTERVAL(x) ((x & 0x7) << 4)
203#define FUSB300_SSCR0_U2_FUN_EN (1 << 1)
204#define FUSB300_SSCR0_U1_FUN_EN (1 << 0)
205
206/*
207 * * SS Controller Register 1 (offset = 30CH)
208 * */
209#define FUSB300_SSCR1_GO_U3_DONE (1 << 8)
210#define FUSB300_SSCR1_TXDEEMPH_LEVEL (1 << 7)
211#define FUSB300_SSCR1_DIS_SCRMB (1 << 6)
212#define FUSB300_SSCR1_FORCE_RECOVERY (1 << 5)
213#define FUSB300_SSCR1_U3_WAKEUP_EN (1 << 4)
214#define FUSB300_SSCR1_U2_EXIT_EN (1 << 3)
215#define FUSB300_SSCR1_U1_EXIT_EN (1 << 2)
216#define FUSB300_SSCR1_U2_ENTRY_EN (1 << 1)
217#define FUSB300_SSCR1_U1_ENTRY_EN (1 << 0)
218
219/*
220 * *SS Controller Register 2 (offset = 310H)
221 * */
222#define FUSB300_SSCR2_SS_TX_SWING (1 << 25)
223#define FUSB300_SSCR2_FORCE_LINKPM_ACCEPT (1 << 24)
224#define FUSB300_SSCR2_U2_INACT_TIMEOUT(x) ((x & 0xFF) << 16)
225#define FUSB300_SSCR2_U1TIMEOUT(x) ((x & 0xFF) << 8)
226#define FUSB300_SSCR2_U2TIMEOUT(x) (x & 0xFF)
227
228/*
229 * *SS Device Notification Control (DEV_NOTF, offset = 314H)
230 * */
231#define FUSB300_DEVNOTF_CONTEXT0(x) ((x & 0xFFFFFF) << 8)
232#define FUSB300_DEVNOTF_TYPE_DIS 0
233#define FUSB300_DEVNOTF_TYPE_FUNCWAKE 1
234#define FUSB300_DEVNOTF_TYPE_LTM 2
235#define FUSB300_DEVNOTF_TYPE_BUSINT_ADJMSG 3
236
237/*
238 * *BFM Arbiter Priority Register (BFM_ARB offset = 31CH)
239 * */
240#define FUSB300_BFMARB_ARB_M1 (1 << 3)
241#define FUSB300_BFMARB_ARB_M0 (1 << 2)
242#define FUSB300_BFMARB_ARB_S1 (1 << 1)
243#define FUSB300_BFMARB_ARB_S0 1
244
245/*
246 * *Vendor Specific IO Control Register (offset = 320H)
247 * */
248#define FUSB300_VSIC_VCTLOAD_N (1 << 8)
249#define FUSB300_VSIC_VCTL(x) (x & 0x3F)
250
251/*
252 * *SOF Mask Timer (offset = 324H)
253 * */
254#define FUSB300_SOF_MASK_TIMER_HS 0x044c
255#define FUSB300_SOF_MASK_TIMER_FS 0x2710
256
257/*
258 * *Error Flag and Control Status (offset = 328H)
259 * */
260#define FUSB300_EFCS_PM_STATE_U3 3
261#define FUSB300_EFCS_PM_STATE_U2 2
262#define FUSB300_EFCS_PM_STATE_U1 1
263#define FUSB300_EFCS_PM_STATE_U0 0
264
265/*
266 * *Interrupt Group 0 Register (offset = 400H)
267 * */
268#define FUSB300_IGR0_EP15_PRD_INT (1 << 31)
269#define FUSB300_IGR0_EP14_PRD_INT (1 << 30)
270#define FUSB300_IGR0_EP13_PRD_INT (1 << 29)
271#define FUSB300_IGR0_EP12_PRD_INT (1 << 28)
272#define FUSB300_IGR0_EP11_PRD_INT (1 << 27)
273#define FUSB300_IGR0_EP10_PRD_INT (1 << 26)
274#define FUSB300_IGR0_EP9_PRD_INT (1 << 25)
275#define FUSB300_IGR0_EP8_PRD_INT (1 << 24)
276#define FUSB300_IGR0_EP7_PRD_INT (1 << 23)
277#define FUSB300_IGR0_EP6_PRD_INT (1 << 22)
278#define FUSB300_IGR0_EP5_PRD_INT (1 << 21)
279#define FUSB300_IGR0_EP4_PRD_INT (1 << 20)
280#define FUSB300_IGR0_EP3_PRD_INT (1 << 19)
281#define FUSB300_IGR0_EP2_PRD_INT (1 << 18)
282#define FUSB300_IGR0_EP1_PRD_INT (1 << 17)
283#define FUSB300_IGR0_EPn_PRD_INT(n) (1 << (n + 16))
284
285#define FUSB300_IGR0_EP15_FIFO_INT (1 << 15)
286#define FUSB300_IGR0_EP14_FIFO_INT (1 << 14)
287#define FUSB300_IGR0_EP13_FIFO_INT (1 << 13)
288#define FUSB300_IGR0_EP12_FIFO_INT (1 << 12)
289#define FUSB300_IGR0_EP11_FIFO_INT (1 << 11)
290#define FUSB300_IGR0_EP10_FIFO_INT (1 << 10)
291#define FUSB300_IGR0_EP9_FIFO_INT (1 << 9)
292#define FUSB300_IGR0_EP8_FIFO_INT (1 << 8)
293#define FUSB300_IGR0_EP7_FIFO_INT (1 << 7)
294#define FUSB300_IGR0_EP6_FIFO_INT (1 << 6)
295#define FUSB300_IGR0_EP5_FIFO_INT (1 << 5)
296#define FUSB300_IGR0_EP4_FIFO_INT (1 << 4)
297#define FUSB300_IGR0_EP3_FIFO_INT (1 << 3)
298#define FUSB300_IGR0_EP2_FIFO_INT (1 << 2)
299#define FUSB300_IGR0_EP1_FIFO_INT (1 << 1)
300#define FUSB300_IGR0_EPn_FIFO_INT(n) (1 << n)
301
302/*
303 * *Interrupt Group 1 Register (offset = 404H)
304 * */
305#define FUSB300_IGR1_INTGRP5 (1 << 31)
306#define FUSB300_IGR1_VBUS_CHG_INT (1 << 30)
307#define FUSB300_IGR1_SYNF1_EMPTY_INT (1 << 29)
308#define FUSB300_IGR1_SYNF0_EMPTY_INT (1 << 28)
309#define FUSB300_IGR1_U3_EXIT_FAIL_INT (1 << 27)
310#define FUSB300_IGR1_U2_EXIT_FAIL_INT (1 << 26)
311#define FUSB300_IGR1_U1_EXIT_FAIL_INT (1 << 25)
312#define FUSB300_IGR1_U2_ENTRY_FAIL_INT (1 << 24)
313#define FUSB300_IGR1_U1_ENTRY_FAIL_INT (1 << 23)
314#define FUSB300_IGR1_U3_EXIT_INT (1 << 22)
315#define FUSB300_IGR1_U2_EXIT_INT (1 << 21)
316#define FUSB300_IGR1_U1_EXIT_INT (1 << 20)
317#define FUSB300_IGR1_U3_ENTRY_INT (1 << 19)
318#define FUSB300_IGR1_U2_ENTRY_INT (1 << 18)
319#define FUSB300_IGR1_U1_ENTRY_INT (1 << 17)
320#define FUSB300_IGR1_HOT_RST_INT (1 << 16)
321#define FUSB300_IGR1_WARM_RST_INT (1 << 15)
322#define FUSB300_IGR1_RESM_INT (1 << 14)
323#define FUSB300_IGR1_SUSP_INT (1 << 13)
324#define FUSB300_IGR1_HS_LPM_INT (1 << 12)
325#define FUSB300_IGR1_USBRST_INT (1 << 11)
326#define FUSB300_IGR1_DEV_MODE_CHG_INT (1 << 9)
327#define FUSB300_IGR1_CX_COMABT_INT (1 << 8)
328#define FUSB300_IGR1_CX_COMFAIL_INT (1 << 7)
329#define FUSB300_IGR1_CX_CMDEND_INT (1 << 6)
330#define FUSB300_IGR1_CX_OUT_INT (1 << 5)
331#define FUSB300_IGR1_CX_IN_INT (1 << 4)
332#define FUSB300_IGR1_CX_SETUP_INT (1 << 3)
333#define FUSB300_IGR1_INTGRP4 (1 << 2)
334#define FUSB300_IGR1_INTGRP3 (1 << 1)
335#define FUSB300_IGR1_INTGRP2 (1 << 0)
336
337/*
338 * *Interrupt Group 2 Register (offset = 408H)
339 * */
340#define FUSB300_IGR2_EP6_STR_ACCEPT_INT (1 << 29)
341#define FUSB300_IGR2_EP6_STR_RESUME_INT (1 << 28)
342#define FUSB300_IGR2_EP6_STR_REQ_INT (1 << 27)
343#define FUSB300_IGR2_EP6_STR_NOTRDY_INT (1 << 26)
344#define FUSB300_IGR2_EP6_STR_PRIME_INT (1 << 25)
345#define FUSB300_IGR2_EP5_STR_ACCEPT_INT (1 << 24)
346#define FUSB300_IGR2_EP5_STR_RESUME_INT (1 << 23)
347#define FUSB300_IGR2_EP5_STR_REQ_INT (1 << 22)
348#define FUSB300_IGR2_EP5_STR_NOTRDY_INT (1 << 21)
349#define FUSB300_IGR2_EP5_STR_PRIME_INT (1 << 20)
350#define FUSB300_IGR2_EP4_STR_ACCEPT_INT (1 << 19)
351#define FUSB300_IGR2_EP4_STR_RESUME_INT (1 << 18)
352#define FUSB300_IGR2_EP4_STR_REQ_INT (1 << 17)
353#define FUSB300_IGR2_EP4_STR_NOTRDY_INT (1 << 16)
354#define FUSB300_IGR2_EP4_STR_PRIME_INT (1 << 15)
355#define FUSB300_IGR2_EP3_STR_ACCEPT_INT (1 << 14)
356#define FUSB300_IGR2_EP3_STR_RESUME_INT (1 << 13)
357#define FUSB300_IGR2_EP3_STR_REQ_INT (1 << 12)
358#define FUSB300_IGR2_EP3_STR_NOTRDY_INT (1 << 11)
359#define FUSB300_IGR2_EP3_STR_PRIME_INT (1 << 10)
360#define FUSB300_IGR2_EP2_STR_ACCEPT_INT (1 << 9)
361#define FUSB300_IGR2_EP2_STR_RESUME_INT (1 << 8)
362#define FUSB300_IGR2_EP2_STR_REQ_INT (1 << 7)
363#define FUSB300_IGR2_EP2_STR_NOTRDY_INT (1 << 6)
364#define FUSB300_IGR2_EP2_STR_PRIME_INT (1 << 5)
365#define FUSB300_IGR2_EP1_STR_ACCEPT_INT (1 << 4)
366#define FUSB300_IGR2_EP1_STR_RESUME_INT (1 << 3)
367#define FUSB300_IGR2_EP1_STR_REQ_INT (1 << 2)
368#define FUSB300_IGR2_EP1_STR_NOTRDY_INT (1 << 1)
369#define FUSB300_IGR2_EP1_STR_PRIME_INT (1 << 0)
370
371#define FUSB300_IGR2_EP_STR_ACCEPT_INT(n) (1 << (5 * n - 1))
372#define FUSB300_IGR2_EP_STR_RESUME_INT(n) (1 << (5 * n - 2))
373#define FUSB300_IGR2_EP_STR_REQ_INT(n) (1 << (5 * n - 3))
374#define FUSB300_IGR2_EP_STR_NOTRDY_INT(n) (1 << (5 * n - 4))
375#define FUSB300_IGR2_EP_STR_PRIME_INT(n) (1 << (5 * n - 5))
376
377/*
378 * *Interrupt Group 3 Register (offset = 40CH)
379 * */
380#define FUSB300_IGR3_EP12_STR_ACCEPT_INT (1 << 29)
381#define FUSB300_IGR3_EP12_STR_RESUME_INT (1 << 28)
382#define FUSB300_IGR3_EP12_STR_REQ_INT (1 << 27)
383#define FUSB300_IGR3_EP12_STR_NOTRDY_INT (1 << 26)
384#define FUSB300_IGR3_EP12_STR_PRIME_INT (1 << 25)
385#define FUSB300_IGR3_EP11_STR_ACCEPT_INT (1 << 24)
386#define FUSB300_IGR3_EP11_STR_RESUME_INT (1 << 23)
387#define FUSB300_IGR3_EP11_STR_REQ_INT (1 << 22)
388#define FUSB300_IGR3_EP11_STR_NOTRDY_INT (1 << 21)
389#define FUSB300_IGR3_EP11_STR_PRIME_INT (1 << 20)
390#define FUSB300_IGR3_EP10_STR_ACCEPT_INT (1 << 19)
391#define FUSB300_IGR3_EP10_STR_RESUME_INT (1 << 18)
392#define FUSB300_IGR3_EP10_STR_REQ_INT (1 << 17)
393#define FUSB300_IGR3_EP10_STR_NOTRDY_INT (1 << 16)
394#define FUSB300_IGR3_EP10_STR_PRIME_INT (1 << 15)
395#define FUSB300_IGR3_EP9_STR_ACCEPT_INT (1 << 14)
396#define FUSB300_IGR3_EP9_STR_RESUME_INT (1 << 13)
397#define FUSB300_IGR3_EP9_STR_REQ_INT (1 << 12)
398#define FUSB300_IGR3_EP9_STR_NOTRDY_INT (1 << 11)
399#define FUSB300_IGR3_EP9_STR_PRIME_INT (1 << 10)
400#define FUSB300_IGR3_EP8_STR_ACCEPT_INT (1 << 9)
401#define FUSB300_IGR3_EP8_STR_RESUME_INT (1 << 8)
402#define FUSB300_IGR3_EP8_STR_REQ_INT (1 << 7)
403#define FUSB300_IGR3_EP8_STR_NOTRDY_INT (1 << 6)
404#define FUSB300_IGR3_EP8_STR_PRIME_INT (1 << 5)
405#define FUSB300_IGR3_EP7_STR_ACCEPT_INT (1 << 4)
406#define FUSB300_IGR3_EP7_STR_RESUME_INT (1 << 3)
407#define FUSB300_IGR3_EP7_STR_REQ_INT (1 << 2)
408#define FUSB300_IGR3_EP7_STR_NOTRDY_INT (1 << 1)
409#define FUSB300_IGR3_EP7_STR_PRIME_INT (1 << 0)
410
411#define FUSB300_IGR3_EP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1))
412#define FUSB300_IGR3_EP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2))
413#define FUSB300_IGR3_EP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3))
414#define FUSB300_IGR3_EP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4))
415#define FUSB300_IGR3_EP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5))
416
417/*
418 * *Interrupt Group 4 Register (offset = 410H)
419 * */
420#define FUSB300_IGR4_EP15_RX0_INT (1 << 31)
421#define FUSB300_IGR4_EP14_RX0_INT (1 << 30)
422#define FUSB300_IGR4_EP13_RX0_INT (1 << 29)
423#define FUSB300_IGR4_EP12_RX0_INT (1 << 28)
424#define FUSB300_IGR4_EP11_RX0_INT (1 << 27)
425#define FUSB300_IGR4_EP10_RX0_INT (1 << 26)
426#define FUSB300_IGR4_EP9_RX0_INT (1 << 25)
427#define FUSB300_IGR4_EP8_RX0_INT (1 << 24)
428#define FUSB300_IGR4_EP7_RX0_INT (1 << 23)
429#define FUSB300_IGR4_EP6_RX0_INT (1 << 22)
430#define FUSB300_IGR4_EP5_RX0_INT (1 << 21)
431#define FUSB300_IGR4_EP4_RX0_INT (1 << 20)
432#define FUSB300_IGR4_EP3_RX0_INT (1 << 19)
433#define FUSB300_IGR4_EP2_RX0_INT (1 << 18)
434#define FUSB300_IGR4_EP1_RX0_INT (1 << 17)
435#define FUSB300_IGR4_EP_RX0_INT(x) (1 << (x + 16))
436#define FUSB300_IGR4_EP15_STR_ACCEPT_INT (1 << 14)
437#define FUSB300_IGR4_EP15_STR_RESUME_INT (1 << 13)
438#define FUSB300_IGR4_EP15_STR_REQ_INT (1 << 12)
439#define FUSB300_IGR4_EP15_STR_NOTRDY_INT (1 << 11)
440#define FUSB300_IGR4_EP15_STR_PRIME_INT (1 << 10)
441#define FUSB300_IGR4_EP14_STR_ACCEPT_INT (1 << 9)
442#define FUSB300_IGR4_EP14_STR_RESUME_INT (1 << 8)
443#define FUSB300_IGR4_EP14_STR_REQ_INT (1 << 7)
444#define FUSB300_IGR4_EP14_STR_NOTRDY_INT (1 << 6)
445#define FUSB300_IGR4_EP14_STR_PRIME_INT (1 << 5)
446#define FUSB300_IGR4_EP13_STR_ACCEPT_INT (1 << 4)
447#define FUSB300_IGR4_EP13_STR_RESUME_INT (1 << 3)
448#define FUSB300_IGR4_EP13_STR_REQ_INT (1 << 2)
449#define FUSB300_IGR4_EP13_STR_NOTRDY_INT (1 << 1)
450#define FUSB300_IGR4_EP13_STR_PRIME_INT (1 << 0)
451
452#define FUSB300_IGR4_EP_STR_ACCEPT_INT(n) (1 << (5 * (n - 12) - 1))
453#define FUSB300_IGR4_EP_STR_RESUME_INT(n) (1 << (5 * (n - 12) - 2))
454#define FUSB300_IGR4_EP_STR_REQ_INT(n) (1 << (5 * (n - 12) - 3))
455#define FUSB300_IGR4_EP_STR_NOTRDY_INT(n) (1 << (5 * (n - 12) - 4))
456#define FUSB300_IGR4_EP_STR_PRIME_INT(n) (1 << (5 * (n - 12) - 5))
457
458/*
459 * *Interrupt Group 5 Register (offset = 414H)
460 * */
461#define FUSB300_IGR5_EP_STL_INT(n) (1 << n)
462
463/*
464 * *Interrupt Enable Group 0 Register (offset = 420H)
465 * */
466#define FUSB300_IGER0_EEP15_PRD_INT (1 << 31)
467#define FUSB300_IGER0_EEP14_PRD_INT (1 << 30)
468#define FUSB300_IGER0_EEP13_PRD_INT (1 << 29)
469#define FUSB300_IGER0_EEP12_PRD_INT (1 << 28)
470#define FUSB300_IGER0_EEP11_PRD_INT (1 << 27)
471#define FUSB300_IGER0_EEP10_PRD_INT (1 << 26)
472#define FUSB300_IGER0_EEP9_PRD_INT (1 << 25)
473#define FUSB300_IGER0_EP8_PRD_INT (1 << 24)
474#define FUSB300_IGER0_EEP7_PRD_INT (1 << 23)
475#define FUSB300_IGER0_EEP6_PRD_INT (1 << 22)
476#define FUSB300_IGER0_EEP5_PRD_INT (1 << 21)
477#define FUSB300_IGER0_EEP4_PRD_INT (1 << 20)
478#define FUSB300_IGER0_EEP3_PRD_INT (1 << 19)
479#define FUSB300_IGER0_EEP2_PRD_INT (1 << 18)
480#define FUSB300_IGER0_EEP1_PRD_INT (1 << 17)
481#define FUSB300_IGER0_EEPn_PRD_INT(n) (1 << (n + 16))
482
483#define FUSB300_IGER0_EEP15_FIFO_INT (1 << 15)
484#define FUSB300_IGER0_EEP14_FIFO_INT (1 << 14)
485#define FUSB300_IGER0_EEP13_FIFO_INT (1 << 13)
486#define FUSB300_IGER0_EEP12_FIFO_INT (1 << 12)
487#define FUSB300_IGER0_EEP11_FIFO_INT (1 << 11)
488#define FUSB300_IGER0_EEP10_FIFO_INT (1 << 10)
489#define FUSB300_IGER0_EEP9_FIFO_INT (1 << 9)
490#define FUSB300_IGER0_EEP8_FIFO_INT (1 << 8)
491#define FUSB300_IGER0_EEP7_FIFO_INT (1 << 7)
492#define FUSB300_IGER0_EEP6_FIFO_INT (1 << 6)
493#define FUSB300_IGER0_EEP5_FIFO_INT (1 << 5)
494#define FUSB300_IGER0_EEP4_FIFO_INT (1 << 4)
495#define FUSB300_IGER0_EEP3_FIFO_INT (1 << 3)
496#define FUSB300_IGER0_EEP2_FIFO_INT (1 << 2)
497#define FUSB300_IGER0_EEP1_FIFO_INT (1 << 1)
498#define FUSB300_IGER0_EEPn_FIFO_INT(n) (1 << n)
499
500/*
501 * *Interrupt Enable Group 1 Register (offset = 424H)
502 * */
503#define FUSB300_IGER1_EINT_GRP5 (1 << 31)
504#define FUSB300_IGER1_VBUS_CHG_INT (1 << 30)
505#define FUSB300_IGER1_SYNF1_EMPTY_INT (1 << 29)
506#define FUSB300_IGER1_SYNF0_EMPTY_INT (1 << 28)
507#define FUSB300_IGER1_U3_EXIT_FAIL_INT (1 << 27)
508#define FUSB300_IGER1_U2_EXIT_FAIL_INT (1 << 26)
509#define FUSB300_IGER1_U1_EXIT_FAIL_INT (1 << 25)
510#define FUSB300_IGER1_U2_ENTRY_FAIL_INT (1 << 24)
511#define FUSB300_IGER1_U1_ENTRY_FAIL_INT (1 << 23)
512#define FUSB300_IGER1_U3_EXIT_INT (1 << 22)
513#define FUSB300_IGER1_U2_EXIT_INT (1 << 21)
514#define FUSB300_IGER1_U1_EXIT_INT (1 << 20)
515#define FUSB300_IGER1_U3_ENTRY_INT (1 << 19)
516#define FUSB300_IGER1_U2_ENTRY_INT (1 << 18)
517#define FUSB300_IGER1_U1_ENTRY_INT (1 << 17)
518#define FUSB300_IGER1_HOT_RST_INT (1 << 16)
519#define FUSB300_IGER1_WARM_RST_INT (1 << 15)
520#define FUSB300_IGER1_RESM_INT (1 << 14)
521#define FUSB300_IGER1_SUSP_INT (1 << 13)
522#define FUSB300_IGER1_LPM_INT (1 << 12)
523#define FUSB300_IGER1_HS_RST_INT (1 << 11)
524#define FUSB300_IGER1_EDEV_MODE_CHG_INT (1 << 9)
525#define FUSB300_IGER1_CX_COMABT_INT (1 << 8)
526#define FUSB300_IGER1_CX_COMFAIL_INT (1 << 7)
527#define FUSB300_IGER1_CX_CMDEND_INT (1 << 6)
528#define FUSB300_IGER1_CX_OUT_INT (1 << 5)
529#define FUSB300_IGER1_CX_IN_INT (1 << 4)
530#define FUSB300_IGER1_CX_SETUP_INT (1 << 3)
531#define FUSB300_IGER1_INTGRP4 (1 << 2)
532#define FUSB300_IGER1_INTGRP3 (1 << 1)
533#define FUSB300_IGER1_INTGRP2 (1 << 0)
534
535/*
536 * *Interrupt Enable Group 2 Register (offset = 428H)
537 * */
538#define FUSB300_IGER2_EEP_STR_ACCEPT_INT(n) (1 << (5 * n - 1))
539#define FUSB300_IGER2_EEP_STR_RESUME_INT(n) (1 << (5 * n - 2))
540#define FUSB300_IGER2_EEP_STR_REQ_INT(n) (1 << (5 * n - 3))
541#define FUSB300_IGER2_EEP_STR_NOTRDY_INT(n) (1 << (5 * n - 4))
542#define FUSB300_IGER2_EEP_STR_PRIME_INT(n) (1 << (5 * n - 5))
543
544/*
545 * *Interrupt Enable Group 3 Register (offset = 42CH)
546 * */
547
548#define FUSB300_IGER3_EEP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1))
549#define FUSB300_IGER3_EEP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2))
550#define FUSB300_IGER3_EEP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3))
551#define FUSB300_IGER3_EEP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4))
552#define FUSB300_IGER3_EEP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5))
553
554/*
555 * *Interrupt Enable Group 4 Register (offset = 430H)
556 * */
557
558#define FUSB300_IGER4_EEP_RX0_INT(n) (1 << (n + 16))
559#define FUSB300_IGER4_EEP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1))
560#define FUSB300_IGER4_EEP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2))
561#define FUSB300_IGER4_EEP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3))
562#define FUSB300_IGER4_EEP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4))
563#define FUSB300_IGER4_EEP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5))
564
565/* EP PRD Ready (EP_PRD_RDY, offset = 504H) */
566
567#define FUSB300_EPPRDR_EP15_PRD_RDY (1 << 15)
568#define FUSB300_EPPRDR_EP14_PRD_RDY (1 << 14)
569#define FUSB300_EPPRDR_EP13_PRD_RDY (1 << 13)
570#define FUSB300_EPPRDR_EP12_PRD_RDY (1 << 12)
571#define FUSB300_EPPRDR_EP11_PRD_RDY (1 << 11)
572#define FUSB300_EPPRDR_EP10_PRD_RDY (1 << 10)
573#define FUSB300_EPPRDR_EP9_PRD_RDY (1 << 9)
574#define FUSB300_EPPRDR_EP8_PRD_RDY (1 << 8)
575#define FUSB300_EPPRDR_EP7_PRD_RDY (1 << 7)
576#define FUSB300_EPPRDR_EP6_PRD_RDY (1 << 6)
577#define FUSB300_EPPRDR_EP5_PRD_RDY (1 << 5)
578#define FUSB300_EPPRDR_EP4_PRD_RDY (1 << 4)
579#define FUSB300_EPPRDR_EP3_PRD_RDY (1 << 3)
580#define FUSB300_EPPRDR_EP2_PRD_RDY (1 << 2)
581#define FUSB300_EPPRDR_EP1_PRD_RDY (1 << 1)
582#define FUSB300_EPPRDR_EP_PRD_RDY(n) (1 << n)
583
584/* AHB Bus Control Register (offset = 514H) */
585#define FUSB300_AHBBCR_S1_SPLIT_ON (1 << 17)
586#define FUSB300_AHBBCR_S0_SPLIT_ON (1 << 16)
587#define FUSB300_AHBBCR_S1_1entry (0 << 12)
588#define FUSB300_AHBBCR_S1_4entry (3 << 12)
589#define FUSB300_AHBBCR_S1_8entry (5 << 12)
590#define FUSB300_AHBBCR_S1_16entry (7 << 12)
591#define FUSB300_AHBBCR_S0_1entry (0 << 8)
592#define FUSB300_AHBBCR_S0_4entry (3 << 8)
593#define FUSB300_AHBBCR_S0_8entry (5 << 8)
594#define FUSB300_AHBBCR_S0_16entry (7 << 8)
595#define FUSB300_AHBBCR_M1_BURST_SINGLE (0 << 4)
596#define FUSB300_AHBBCR_M1_BURST_INCR (1 << 4)
597#define FUSB300_AHBBCR_M1_BURST_INCR4 (3 << 4)
598#define FUSB300_AHBBCR_M1_BURST_INCR8 (5 << 4)
599#define FUSB300_AHBBCR_M1_BURST_INCR16 (7 << 4)
600#define FUSB300_AHBBCR_M0_BURST_SINGLE 0
601#define FUSB300_AHBBCR_M0_BURST_INCR 1
602#define FUSB300_AHBBCR_M0_BURST_INCR4 3
603#define FUSB300_AHBBCR_M0_BURST_INCR8 5
604#define FUSB300_AHBBCR_M0_BURST_INCR16 7
605#define FUSB300_IGER5_EEP_STL_INT(n) (1 << n)
606
607/* WORD 0 Data Structure of PRD Table */
608#define FUSB300_EPPRD0_M (1 << 30)
609#define FUSB300_EPPRD0_O (1 << 29)
610/* The finished prd */
611#define FUSB300_EPPRD0_F (1 << 28)
612#define FUSB300_EPPRD0_I (1 << 27)
613#define FUSB300_EPPRD0_A (1 << 26)
614/* To decide HW point to first prd at next time */
615#define FUSB300_EPPRD0_L (1 << 25)
616#define FUSB300_EPPRD0_H (1 << 24)
617#define FUSB300_EPPRD0_BTC(n) (n & 0xFFFFFF)
618
619/*----------------------------------------------------------------------*/
620#define FUSB300_MAX_NUM_EP 16
621
622#define FUSB300_FIFO_ENTRY_NUM 8
623#define FUSB300_MAX_FIFO_ENTRY 8
624
625#define SS_CTL_MAX_PACKET_SIZE 0x200
626#define SS_BULK_MAX_PACKET_SIZE 0x400
627#define SS_INT_MAX_PACKET_SIZE 0x400
628#define SS_ISO_MAX_PACKET_SIZE 0x400
629
630#define HS_BULK_MAX_PACKET_SIZE 0x200
631#define HS_CTL_MAX_PACKET_SIZE 0x40
632#define HS_INT_MAX_PACKET_SIZE 0x400
633#define HS_ISO_MAX_PACKET_SIZE 0x400
634
635struct fusb300_ep_info {
636 u8 epnum;
637 u8 type;
638 u8 interval;
639 u8 dir_in;
640 u16 maxpacket;
641 u16 addrofs;
642 u16 bw_num;
643};
644
645struct fusb300_request {
646
647 struct usb_request req;
648 struct list_head queue;
649};
650
651
652struct fusb300_ep {
653 struct usb_ep ep;
654 struct fusb300 *fusb300;
655
656 struct list_head queue;
657 unsigned stall:1;
658 unsigned wedged:1;
659 unsigned use_dma:1;
660
661 unsigned char epnum;
662 unsigned char type;
663 const struct usb_endpoint_descriptor *desc;
664};
665
666struct fusb300 {
667 spinlock_t lock;
668 void __iomem *reg;
669
670 unsigned long irq_trigger;
671
672 struct usb_gadget gadget;
673 struct usb_gadget_driver *driver;
674
675 struct fusb300_ep *ep[FUSB300_MAX_NUM_EP];
676
677 struct usb_request *ep0_req; /* for internal request */
678 __le16 ep0_data;
679 u32 ep0_length; /* for internal request */
680 u8 ep0_dir; /* 0/0x80 out/in */
681
682 u8 fifo_entry_num; /* next start fifo entry */
683 u32 addrofs; /* next fifo address offset */
684 u8 reenum; /* if re-enumeration */
685};
686
687#endif
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index a9474f8d5325..ebf6970a10bf 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -1,7 +1,29 @@
1/*
2 * g_ffs.c -- user mode file system API for USB composite function controllers
3 *
4 * Copyright (C) 2010 Samsung Electronics
5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#define pr_fmt(fmt) "g_ffs: " fmt
23
1#include <linux/module.h> 24#include <linux/module.h>
2#include <linux/utsname.h> 25#include <linux/utsname.h>
3 26
4
5/* 27/*
6 * kbuild is not very cooperative with respect to linking separately 28 * kbuild is not very cooperative with respect to linking separately
7 * compiled library objects into one module. So for now we won't use 29 * compiled library objects into one module. So for now we won't use
@@ -43,7 +65,6 @@ static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
43 65
44#include "f_fs.c" 66#include "f_fs.c"
45 67
46
47#define DRIVER_NAME "g_ffs" 68#define DRIVER_NAME "g_ffs"
48#define DRIVER_DESC "USB Function Filesystem" 69#define DRIVER_DESC "USB Function Filesystem"
49#define DRIVER_VERSION "24 Aug 2004" 70#define DRIVER_VERSION "24 Aug 2004"
@@ -52,9 +73,8 @@ MODULE_DESCRIPTION(DRIVER_DESC);
52MODULE_AUTHOR("Michal Nazarewicz"); 73MODULE_AUTHOR("Michal Nazarewicz");
53MODULE_LICENSE("GPL"); 74MODULE_LICENSE("GPL");
54 75
55 76#define GFS_VENDOR_ID 0x1d6b /* Linux Foundation */
56static unsigned short gfs_vendor_id = 0x0525; /* XXX NetChip */ 77#define GFS_PRODUCT_ID 0x0105 /* FunctionFS Gadget */
57static unsigned short gfs_product_id = 0xa4ac; /* XXX */
58 78
59static struct usb_device_descriptor gfs_dev_desc = { 79static struct usb_device_descriptor gfs_dev_desc = {
60 .bLength = sizeof gfs_dev_desc, 80 .bLength = sizeof gfs_dev_desc,
@@ -63,31 +83,16 @@ static struct usb_device_descriptor gfs_dev_desc = {
63 .bcdUSB = cpu_to_le16(0x0200), 83 .bcdUSB = cpu_to_le16(0x0200),
64 .bDeviceClass = USB_CLASS_PER_INTERFACE, 84 .bDeviceClass = USB_CLASS_PER_INTERFACE,
65 85
66 /* Vendor and product id can be overridden by module parameters. */ 86 .idVendor = cpu_to_le16(GFS_VENDOR_ID),
67 /* .idVendor = cpu_to_le16(gfs_vendor_id), */ 87 .idProduct = cpu_to_le16(GFS_PRODUCT_ID),
68 /* .idProduct = cpu_to_le16(gfs_product_id), */
69 /* .bcdDevice = f(hardware) */
70 /* .iManufacturer = DYNAMIC */
71 /* .iProduct = DYNAMIC */
72 /* NO SERIAL NUMBER */
73 .bNumConfigurations = 1,
74}; 88};
75 89
76#define GFS_MODULE_PARAM_DESC(name, field) \ 90module_param_named(bDeviceClass, gfs_dev_desc.bDeviceClass, byte, 0644);
77 MODULE_PARM_DESC(name, "Value of the " #field " field of the device descriptor sent to the host. Takes effect only prior to the user-space driver registering to the FunctionFS.") 91MODULE_PARM_DESC(bDeviceClass, "USB Device class");
78 92module_param_named(bDeviceSubClass, gfs_dev_desc.bDeviceSubClass, byte, 0644);
79module_param_named(usb_class, gfs_dev_desc.bDeviceClass, byte, 0644); 93MODULE_PARM_DESC(bDeviceSubClass, "USB Device subclass");
80GFS_MODULE_PARAM_DESC(usb_class, bDeviceClass); 94module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644);
81module_param_named(usb_subclass, gfs_dev_desc.bDeviceSubClass, byte, 0644); 95MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol");
82GFS_MODULE_PARAM_DESC(usb_subclass, bDeviceSubClass);
83module_param_named(usb_protocol, gfs_dev_desc.bDeviceProtocol, byte, 0644);
84GFS_MODULE_PARAM_DESC(usb_protocol, bDeviceProtocol);
85module_param_named(usb_vendor, gfs_vendor_id, ushort, 0644);
86GFS_MODULE_PARAM_DESC(usb_vendor, idVendor);
87module_param_named(usb_product, gfs_product_id, ushort, 0644);
88GFS_MODULE_PARAM_DESC(usb_product, idProduct);
89
90
91 96
92static const struct usb_descriptor_header *gfs_otg_desc[] = { 97static const struct usb_descriptor_header *gfs_otg_desc[] = {
93 (const struct usb_descriptor_header *) 98 (const struct usb_descriptor_header *)
@@ -95,29 +100,18 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = {
95 .bLength = sizeof(struct usb_otg_descriptor), 100 .bLength = sizeof(struct usb_otg_descriptor),
96 .bDescriptorType = USB_DT_OTG, 101 .bDescriptorType = USB_DT_OTG,
97 102
98 /* REVISIT SRP-only hardware is possible, although 103 /*
99 * it would not be called "OTG" ... */ 104 * REVISIT SRP-only hardware is possible, although
105 * it would not be called "OTG" ...
106 */
100 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 107 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
101 }, 108 },
102 109
103 NULL 110 NULL
104}; 111};
105 112
106/* string IDs are assigned dynamically */ 113/* String IDs are assigned dynamically */
107
108enum {
109 GFS_STRING_MANUFACTURER_IDX,
110 GFS_STRING_PRODUCT_IDX,
111 GFS_STRING_FIRST_CONFIG_IDX,
112};
113
114static char gfs_manufacturer[50];
115static const char gfs_driver_desc[] = DRIVER_DESC;
116static const char gfs_short_name[] = DRIVER_NAME;
117
118static struct usb_string gfs_strings[] = { 114static struct usb_string gfs_strings[] = {
119 [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer,
120 [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc,
121#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 115#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
122 { .s = "FunctionFS + RNDIS" }, 116 { .s = "FunctionFS + RNDIS" },
123#endif 117#endif
@@ -138,8 +132,6 @@ static struct usb_gadget_strings *gfs_dev_strings[] = {
138 NULL, 132 NULL,
139}; 133};
140 134
141
142
143struct gfs_configuration { 135struct gfs_configuration {
144 struct usb_configuration c; 136 struct usb_configuration c;
145 int (*eth)(struct usb_configuration *c, u8 *ethaddr); 137 int (*eth)(struct usb_configuration *c, u8 *ethaddr);
@@ -162,24 +154,21 @@ struct gfs_configuration {
162#endif 154#endif
163}; 155};
164 156
165
166static int gfs_bind(struct usb_composite_dev *cdev); 157static int gfs_bind(struct usb_composite_dev *cdev);
167static int gfs_unbind(struct usb_composite_dev *cdev); 158static int gfs_unbind(struct usb_composite_dev *cdev);
168static int gfs_do_config(struct usb_configuration *c); 159static int gfs_do_config(struct usb_configuration *c);
169 160
170static struct usb_composite_driver gfs_driver = { 161static struct usb_composite_driver gfs_driver = {
171 .name = gfs_short_name, 162 .name = DRIVER_NAME,
172 .dev = &gfs_dev_desc, 163 .dev = &gfs_dev_desc,
173 .strings = gfs_dev_strings, 164 .strings = gfs_dev_strings,
174 .bind = gfs_bind,
175 .unbind = gfs_unbind, 165 .unbind = gfs_unbind,
166 .iProduct = DRIVER_DESC,
176}; 167};
177 168
178
179static struct ffs_data *gfs_ffs_data; 169static struct ffs_data *gfs_ffs_data;
180static unsigned long gfs_registered; 170static unsigned long gfs_registered;
181 171
182
183static int gfs_init(void) 172static int gfs_init(void)
184{ 173{
185 ENTER(); 174 ENTER();
@@ -199,7 +188,6 @@ static void gfs_exit(void)
199} 188}
200module_exit(gfs_exit); 189module_exit(gfs_exit);
201 190
202
203static int functionfs_ready_callback(struct ffs_data *ffs) 191static int functionfs_ready_callback(struct ffs_data *ffs)
204{ 192{
205 int ret; 193 int ret;
@@ -210,7 +198,7 @@ static int functionfs_ready_callback(struct ffs_data *ffs)
210 return -EBUSY; 198 return -EBUSY;
211 199
212 gfs_ffs_data = ffs; 200 gfs_ffs_data = ffs;
213 ret = usb_composite_register(&gfs_driver); 201 ret = usb_composite_probe(&gfs_driver, gfs_bind);
214 if (unlikely(ret < 0)) 202 if (unlikely(ret < 0))
215 clear_bit(0, &gfs_registered); 203 clear_bit(0, &gfs_registered);
216 return ret; 204 return ret;
@@ -224,14 +212,11 @@ static void functionfs_closed_callback(struct ffs_data *ffs)
224 usb_composite_unregister(&gfs_driver); 212 usb_composite_unregister(&gfs_driver);
225} 213}
226 214
227
228static int functionfs_check_dev_callback(const char *dev_name) 215static int functionfs_check_dev_callback(const char *dev_name)
229{ 216{
230 return 0; 217 return 0;
231} 218}
232 219
233
234
235static int gfs_bind(struct usb_composite_dev *cdev) 220static int gfs_bind(struct usb_composite_dev *cdev)
236{ 221{
237 int ret, i; 222 int ret, i;
@@ -245,20 +230,10 @@ static int gfs_bind(struct usb_composite_dev *cdev)
245 if (unlikely(ret < 0)) 230 if (unlikely(ret < 0))
246 goto error_quick; 231 goto error_quick;
247 232
248 gfs_dev_desc.idVendor = cpu_to_le16(gfs_vendor_id);
249 gfs_dev_desc.idProduct = cpu_to_le16(gfs_product_id);
250
251 snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s",
252 init_utsname()->sysname, init_utsname()->release,
253 cdev->gadget->name);
254
255 ret = usb_string_ids_tab(cdev, gfs_strings); 233 ret = usb_string_ids_tab(cdev, gfs_strings);
256 if (unlikely(ret < 0)) 234 if (unlikely(ret < 0))
257 goto error; 235 goto error;
258 236
259 gfs_dev_desc.iManufacturer = gfs_strings[GFS_STRING_MANUFACTURER_IDX].id;
260 gfs_dev_desc.iProduct = gfs_strings[GFS_STRING_PRODUCT_IDX].id;
261
262 ret = functionfs_bind(gfs_ffs_data, cdev); 237 ret = functionfs_bind(gfs_ffs_data, cdev);
263 if (unlikely(ret < 0)) 238 if (unlikely(ret < 0))
264 goto error; 239 goto error;
@@ -266,14 +241,12 @@ static int gfs_bind(struct usb_composite_dev *cdev)
266 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { 241 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) {
267 struct gfs_configuration *c = gfs_configurations + i; 242 struct gfs_configuration *c = gfs_configurations + i;
268 243
269 ret = GFS_STRING_FIRST_CONFIG_IDX + i; 244 c->c.label = gfs_strings[i].s;
270 c->c.label = gfs_strings[ret].s; 245 c->c.iConfiguration = gfs_strings[i].id;
271 c->c.iConfiguration = gfs_strings[ret].id;
272 c->c.bind = gfs_do_config;
273 c->c.bConfigurationValue = 1 + i; 246 c->c.bConfigurationValue = 1 + i;
274 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; 247 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER;
275 248
276 ret = usb_add_config(cdev, &c->c); 249 ret = usb_add_config(cdev, &c->c, gfs_do_config);
277 if (unlikely(ret < 0)) 250 if (unlikely(ret < 0))
278 goto error_unbind; 251 goto error_unbind;
279 } 252 }
@@ -293,13 +266,14 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
293{ 266{
294 ENTER(); 267 ENTER();
295 268
296 /* We may have been called in an error recovery frem 269 /*
270 * We may have been called in an error recovery from
297 * composite_bind() after gfs_unbind() failure so we need to 271 * composite_bind() after gfs_unbind() failure so we need to
298 * check if gfs_ffs_data is not NULL since gfs_bind() handles 272 * check if gfs_ffs_data is not NULL since gfs_bind() handles
299 * all error recovery itself. I'd rather we werent called 273 * all error recovery itself. I'd rather we werent called
300 * from composite on orror recovery, but what you're gonna 274 * from composite on orror recovery, but what you're gonna
301 * do...? */ 275 * do...?
302 276 */
303 if (gfs_ffs_data) { 277 if (gfs_ffs_data) {
304 gether_cleanup(); 278 gether_cleanup();
305 functionfs_unbind(gfs_ffs_data); 279 functionfs_unbind(gfs_ffs_data);
@@ -309,7 +283,6 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
309 return 0; 283 return 0;
310} 284}
311 285
312
313static int gfs_do_config(struct usb_configuration *c) 286static int gfs_do_config(struct usb_configuration *c)
314{ 287{
315 struct gfs_configuration *gc = 288 struct gfs_configuration *gc =
@@ -334,26 +307,29 @@ static int gfs_do_config(struct usb_configuration *c)
334 if (unlikely(ret < 0)) 307 if (unlikely(ret < 0))
335 return ret; 308 return ret;
336 309
337 /* After previous do_configs there may be some invalid 310 /*
311 * After previous do_configs there may be some invalid
338 * pointers in c->interface array. This happens every time 312 * pointers in c->interface array. This happens every time
339 * a user space function with fewer interfaces than a user 313 * a user space function with fewer interfaces than a user
340 * space function that was run before the new one is run. The 314 * space function that was run before the new one is run. The
341 * compasit's set_config() assumes that if there is no more 315 * compasit's set_config() assumes that if there is no more
342 * then MAX_CONFIG_INTERFACES interfaces in a configuration 316 * then MAX_CONFIG_INTERFACES interfaces in a configuration
343 * then there is a NULL pointer after the last interface in 317 * then there is a NULL pointer after the last interface in
344 * c->interface array. We need to make sure this is true. */ 318 * c->interface array. We need to make sure this is true.
319 */
345 if (c->next_interface_id < ARRAY_SIZE(c->interface)) 320 if (c->next_interface_id < ARRAY_SIZE(c->interface))
346 c->interface[c->next_interface_id] = NULL; 321 c->interface[c->next_interface_id] = NULL;
347 322
348 return 0; 323 return 0;
349} 324}
350 325
351
352#ifdef CONFIG_USB_FUNCTIONFS_ETH 326#ifdef CONFIG_USB_FUNCTIONFS_ETH
327
353static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 328static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
354{ 329{
355 return can_support_ecm(c->cdev->gadget) 330 return can_support_ecm(c->cdev->gadget)
356 ? ecm_bind_config(c, ethaddr) 331 ? ecm_bind_config(c, ethaddr)
357 : geth_bind_config(c, ethaddr); 332 : geth_bind_config(c, ethaddr);
358} 333}
334
359#endif 335#endif
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index e511fec9f26d..bcdac7c73e89 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -45,12 +45,6 @@
45#define gadget_is_goku(g) 0 45#define gadget_is_goku(g) 0
46#endif 46#endif
47 47
48#ifdef CONFIG_USB_GADGET_LH7A40X
49#define gadget_is_lh7a40x(g) !strcmp("lh7a40x_udc", (g)->name)
50#else
51#define gadget_is_lh7a40x(g) 0
52#endif
53
54#ifdef CONFIG_USB_GADGET_OMAP 48#ifdef CONFIG_USB_GADGET_OMAP
55#define gadget_is_omap(g) !strcmp("omap_udc", (g)->name) 49#define gadget_is_omap(g) !strcmp("omap_udc", (g)->name)
56#else 50#else
@@ -96,7 +90,7 @@
96 90
97/* Mentor high speed "dual role" controller, in peripheral role */ 91/* Mentor high speed "dual role" controller, in peripheral role */
98#ifdef CONFIG_USB_GADGET_MUSB_HDRC 92#ifdef CONFIG_USB_GADGET_MUSB_HDRC
99#define gadget_is_musbhdrc(g) !strcmp("musb_hdrc", (g)->name) 93#define gadget_is_musbhdrc(g) !strcmp("musb-hdrc", (g)->name)
100#else 94#else
101#define gadget_is_musbhdrc(g) 0 95#define gadget_is_musbhdrc(g) 0
102#endif 96#endif
@@ -120,10 +114,10 @@
120#define gadget_is_fsl_qe(g) 0 114#define gadget_is_fsl_qe(g) 0
121#endif 115#endif
122 116
123#ifdef CONFIG_USB_GADGET_CI13XXX 117#ifdef CONFIG_USB_GADGET_CI13XXX_PCI
124#define gadget_is_ci13xxx(g) (!strcmp("ci13xxx_udc", (g)->name)) 118#define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name))
125#else 119#else
126#define gadget_is_ci13xxx(g) 0 120#define gadget_is_ci13xxx_pci(g) 0
127#endif 121#endif
128 122
129// CONFIG_USB_GADGET_SX2 123// CONFIG_USB_GADGET_SX2
@@ -142,6 +136,29 @@
142#define gadget_is_s3c_hsotg(g) 0 136#define gadget_is_s3c_hsotg(g) 0
143#endif 137#endif
144 138
139#ifdef CONFIG_USB_S3C_HSUDC
140#define gadget_is_s3c_hsudc(g) (!strcmp("s3c-hsudc", (g)->name))
141#else
142#define gadget_is_s3c_hsudc(g) 0
143#endif
144
145#ifdef CONFIG_USB_GADGET_EG20T
146#define gadget_is_pch(g) (!strcmp("pch_udc", (g)->name))
147#else
148#define gadget_is_pch(g) 0
149#endif
150
151#ifdef CONFIG_USB_GADGET_CI13XXX_MSM
152#define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name))
153#else
154#define gadget_is_ci13xxx_msm(g) 0
155#endif
156
157#ifdef CONFIG_USB_GADGET_RENESAS_USBHS
158#define gadget_is_renesas_usbhs(g) (!strcmp("renesas_usbhs_udc", (g)->name))
159#else
160#define gadget_is_renesas_usbhs(g) 0
161#endif
145 162
146/** 163/**
147 * usb_gadget_controller_number - support bcdDevice id convention 164 * usb_gadget_controller_number - support bcdDevice id convention
@@ -170,8 +187,6 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
170 return 0x06; 187 return 0x06;
171 else if (gadget_is_omap(gadget)) 188 else if (gadget_is_omap(gadget))
172 return 0x08; 189 return 0x08;
173 else if (gadget_is_lh7a40x(gadget))
174 return 0x09;
175 else if (gadget_is_pxa27x(gadget)) 190 else if (gadget_is_pxa27x(gadget))
176 return 0x11; 191 return 0x11;
177 else if (gadget_is_s3c2410(gadget)) 192 else if (gadget_is_s3c2410(gadget))
@@ -192,7 +207,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
192 return 0x21; 207 return 0x21;
193 else if (gadget_is_fsl_qe(gadget)) 208 else if (gadget_is_fsl_qe(gadget))
194 return 0x22; 209 return 0x22;
195 else if (gadget_is_ci13xxx(gadget)) 210 else if (gadget_is_ci13xxx_pci(gadget))
196 return 0x23; 211 return 0x23;
197 else if (gadget_is_langwell(gadget)) 212 else if (gadget_is_langwell(gadget))
198 return 0x24; 213 return 0x24;
@@ -200,6 +215,15 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
200 return 0x25; 215 return 0x25;
201 else if (gadget_is_s3c_hsotg(gadget)) 216 else if (gadget_is_s3c_hsotg(gadget))
202 return 0x26; 217 return 0x26;
218 else if (gadget_is_pch(gadget))
219 return 0x27;
220 else if (gadget_is_ci13xxx_msm(gadget))
221 return 0x28;
222 else if (gadget_is_renesas_usbhs(gadget))
223 return 0x29;
224 else if (gadget_is_s3c_hsudc(gadget))
225 return 0x30;
226
203 return -ENOENT; 227 return -ENOENT;
204} 228}
205 229
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 1b413a5cc3f6..47b86b99d449 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -67,7 +67,7 @@ MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter.");
67module_param(id, charp, 0444); 67module_param(id, charp, 0444);
68MODULE_PARM_DESC(id, "ID string for the USB MIDI Gadget adapter."); 68MODULE_PARM_DESC(id, "ID string for the USB MIDI Gadget adapter.");
69 69
70/* Some systems will want different product identifers published in the 70/* Some systems will want different product identifiers published in the
71 * device descriptor, either numbers or strings or both. These string 71 * device descriptor, either numbers or strings or both. These string
72 * parameters are in UTF-8 (superset of ASCII's 7 bit characters). 72 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
73 */ 73 */
@@ -1157,7 +1157,7 @@ fail:
1157/* 1157/*
1158 * Creates an output endpoint, and initializes output ports. 1158 * Creates an output endpoint, and initializes output ports.
1159 */ 1159 */
1160static int __ref gmidi_bind(struct usb_gadget *gadget) 1160static int __init gmidi_bind(struct usb_gadget *gadget)
1161{ 1161{
1162 struct gmidi_device *dev; 1162 struct gmidi_device *dev;
1163 struct usb_ep *in_ep, *out_ep; 1163 struct usb_ep *in_ep, *out_ep;
@@ -1292,7 +1292,6 @@ static void gmidi_resume(struct usb_gadget *gadget)
1292static struct usb_gadget_driver gmidi_driver = { 1292static struct usb_gadget_driver gmidi_driver = {
1293 .speed = USB_SPEED_FULL, 1293 .speed = USB_SPEED_FULL,
1294 .function = (char *)longname, 1294 .function = (char *)longname,
1295 .bind = gmidi_bind,
1296 .unbind = gmidi_unbind, 1295 .unbind = gmidi_unbind,
1297 1296
1298 .setup = gmidi_setup, 1297 .setup = gmidi_setup,
@@ -1309,7 +1308,7 @@ static struct usb_gadget_driver gmidi_driver = {
1309 1308
1310static int __init gmidi_init(void) 1309static int __init gmidi_init(void)
1311{ 1310{
1312 return usb_gadget_register_driver(&gmidi_driver); 1311 return usb_gadget_probe_driver(&gmidi_driver, gmidi_bind);
1313} 1312}
1314module_init(gmidi_init); 1313module_init(gmidi_init);
1315 1314
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 1088d08c7ed8..bf6e11c758d5 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -38,6 +38,7 @@
38#include <linux/device.h> 38#include <linux/device.h>
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/prefetch.h>
41 42
42#include <asm/byteorder.h> 43#include <asm/byteorder.h>
43#include <asm/io.h> 44#include <asm/io.h>
@@ -1343,14 +1344,15 @@ static struct goku_udc *the_controller;
1343 * disconnect is reported. then a host may connect again, or 1344 * disconnect is reported. then a host may connect again, or
1344 * the driver might get unbound. 1345 * the driver might get unbound.
1345 */ 1346 */
1346int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1347int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1348 int (*bind)(struct usb_gadget *))
1347{ 1349{
1348 struct goku_udc *dev = the_controller; 1350 struct goku_udc *dev = the_controller;
1349 int retval; 1351 int retval;
1350 1352
1351 if (!driver 1353 if (!driver
1352 || driver->speed < USB_SPEED_FULL 1354 || driver->speed < USB_SPEED_FULL
1353 || !driver->bind 1355 || !bind
1354 || !driver->disconnect 1356 || !driver->disconnect
1355 || !driver->setup) 1357 || !driver->setup)
1356 return -EINVAL; 1358 return -EINVAL;
@@ -1363,7 +1365,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1363 driver->driver.bus = NULL; 1365 driver->driver.bus = NULL;
1364 dev->driver = driver; 1366 dev->driver = driver;
1365 dev->gadget.dev.driver = &driver->driver; 1367 dev->gadget.dev.driver = &driver->driver;
1366 retval = driver->bind(&dev->gadget); 1368 retval = bind(&dev->gadget);
1367 if (retval) { 1369 if (retval) {
1368 DBG(dev, "bind to driver %s --> error %d\n", 1370 DBG(dev, "bind to driver %s --> error %d\n",
1369 driver->driver.name, retval); 1371 driver->driver.name, retval);
@@ -1380,7 +1382,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1380 DBG(dev, "registered gadget driver '%s'\n", driver->driver.name); 1382 DBG(dev, "registered gadget driver '%s'\n", driver->driver.name);
1381 return 0; 1383 return 0;
1382} 1384}
1383EXPORT_SYMBOL(usb_gadget_register_driver); 1385EXPORT_SYMBOL(usb_gadget_probe_driver);
1384 1386
1385static void 1387static void
1386stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) 1388stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver)
@@ -1744,7 +1746,8 @@ static void goku_remove(struct pci_dev *pdev)
1744 pci_resource_len (pdev, 0)); 1746 pci_resource_len (pdev, 0));
1745 if (dev->enabled) 1747 if (dev->enabled)
1746 pci_disable_device(pdev); 1748 pci_disable_device(pdev);
1747 device_unregister(&dev->gadget.dev); 1749 if (dev->registered)
1750 device_unregister(&dev->gadget.dev);
1748 1751
1749 pci_set_drvdata(pdev, NULL); 1752 pci_set_drvdata(pdev, NULL);
1750 dev->regs = NULL; 1753 dev->regs = NULL;
@@ -1774,7 +1777,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1774 if (!pdev->irq) { 1777 if (!pdev->irq) {
1775 printk(KERN_ERR "Check PCI %s IRQ setup!\n", pci_name(pdev)); 1778 printk(KERN_ERR "Check PCI %s IRQ setup!\n", pci_name(pdev));
1776 retval = -ENODEV; 1779 retval = -ENODEV;
1777 goto done; 1780 goto err;
1778 } 1781 }
1779 1782
1780 /* alloc, and start init */ 1783 /* alloc, and start init */
@@ -1782,7 +1785,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1782 if (dev == NULL){ 1785 if (dev == NULL){
1783 pr_debug("enomem %s\n", pci_name(pdev)); 1786 pr_debug("enomem %s\n", pci_name(pdev));
1784 retval = -ENOMEM; 1787 retval = -ENOMEM;
1785 goto done; 1788 goto err;
1786 } 1789 }
1787 1790
1788 spin_lock_init(&dev->lock); 1791 spin_lock_init(&dev->lock);
@@ -1800,7 +1803,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1800 retval = pci_enable_device(pdev); 1803 retval = pci_enable_device(pdev);
1801 if (retval < 0) { 1804 if (retval < 0) {
1802 DBG(dev, "can't enable, %d\n", retval); 1805 DBG(dev, "can't enable, %d\n", retval);
1803 goto done; 1806 goto err;
1804 } 1807 }
1805 dev->enabled = 1; 1808 dev->enabled = 1;
1806 1809
@@ -1809,7 +1812,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1809 if (!request_mem_region(resource, len, driver_name)) { 1812 if (!request_mem_region(resource, len, driver_name)) {
1810 DBG(dev, "controller already in use\n"); 1813 DBG(dev, "controller already in use\n");
1811 retval = -EBUSY; 1814 retval = -EBUSY;
1812 goto done; 1815 goto err;
1813 } 1816 }
1814 dev->got_region = 1; 1817 dev->got_region = 1;
1815 1818
@@ -1817,7 +1820,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1817 if (base == NULL) { 1820 if (base == NULL) {
1818 DBG(dev, "can't map memory\n"); 1821 DBG(dev, "can't map memory\n");
1819 retval = -EFAULT; 1822 retval = -EFAULT;
1820 goto done; 1823 goto err;
1821 } 1824 }
1822 dev->regs = (struct goku_udc_regs __iomem *) base; 1825 dev->regs = (struct goku_udc_regs __iomem *) base;
1823 1826
@@ -1833,7 +1836,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1833 driver_name, dev) != 0) { 1836 driver_name, dev) != 0) {
1834 DBG(dev, "request interrupt %d failed\n", pdev->irq); 1837 DBG(dev, "request interrupt %d failed\n", pdev->irq);
1835 retval = -EBUSY; 1838 retval = -EBUSY;
1836 goto done; 1839 goto err;
1837 } 1840 }
1838 dev->got_irq = 1; 1841 dev->got_irq = 1;
1839 if (use_dma) 1842 if (use_dma)
@@ -1844,13 +1847,16 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1844 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev); 1847 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev);
1845#endif 1848#endif
1846 1849
1847 /* done */
1848 the_controller = dev; 1850 the_controller = dev;
1849 retval = device_register(&dev->gadget.dev); 1851 retval = device_register(&dev->gadget.dev);
1850 if (retval == 0) 1852 if (retval) {
1851 return 0; 1853 put_device(&dev->gadget.dev);
1854 goto err;
1855 }
1856 dev->registered = 1;
1857 return 0;
1852 1858
1853done: 1859err:
1854 if (dev) 1860 if (dev)
1855 goku_remove (pdev); 1861 goku_remove (pdev);
1856 return retval; 1862 return retval;
diff --git a/drivers/usb/gadget/goku_udc.h b/drivers/usb/gadget/goku_udc.h
index 566cb2319056..e7e0c69d3b1f 100644
--- a/drivers/usb/gadget/goku_udc.h
+++ b/drivers/usb/gadget/goku_udc.h
@@ -251,7 +251,8 @@ struct goku_udc {
251 got_region:1, 251 got_region:1,
252 req_config:1, 252 req_config:1,
253 configured:1, 253 configured:1,
254 enabled:1; 254 enabled:1,
255 registered:1;
255 256
256 /* pci state used to access those endpoints */ 257 /* pci state used to access those endpoints */
257 struct pci_dev *pdev; 258 struct pci_dev *pdev;
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index 735495bf8411..2523e54097bd 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -127,7 +127,7 @@ static struct usb_gadget_strings *dev_strings[] = {
127 127
128/****************************** Configurations ******************************/ 128/****************************** Configurations ******************************/
129 129
130static int __ref do_config(struct usb_configuration *c) 130static int __init do_config(struct usb_configuration *c)
131{ 131{
132 struct hidg_func_node *e; 132 struct hidg_func_node *e;
133 int func = 0, status = 0; 133 int func = 0, status = 0;
@@ -148,7 +148,6 @@ static int __ref do_config(struct usb_configuration *c)
148 148
149static struct usb_configuration config_driver = { 149static struct usb_configuration config_driver = {
150 .label = "HID Gadget", 150 .label = "HID Gadget",
151 .bind = do_config,
152 .bConfigurationValue = 1, 151 .bConfigurationValue = 1,
153 /* .iConfiguration = DYNAMIC */ 152 /* .iConfiguration = DYNAMIC */
154 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 153 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -156,7 +155,7 @@ static struct usb_configuration config_driver = {
156 155
157/****************************** Gadget Bind ******************************/ 156/****************************** Gadget Bind ******************************/
158 157
159static int __ref hid_bind(struct usb_composite_dev *cdev) 158static int __init hid_bind(struct usb_composite_dev *cdev)
160{ 159{
161 struct usb_gadget *gadget = cdev->gadget; 160 struct usb_gadget *gadget = cdev->gadget;
162 struct list_head *tmp; 161 struct list_head *tmp;
@@ -201,7 +200,7 @@ static int __ref hid_bind(struct usb_composite_dev *cdev)
201 device_desc.iProduct = status; 200 device_desc.iProduct = status;
202 201
203 /* register our configuration */ 202 /* register our configuration */
204 status = usb_add_config(cdev, &config_driver); 203 status = usb_add_config(cdev, &config_driver, do_config);
205 if (status < 0) 204 if (status < 0)
206 return status; 205 return status;
207 206
@@ -256,7 +255,6 @@ static struct usb_composite_driver hidg_driver = {
256 .name = "g_hid", 255 .name = "g_hid",
257 .dev = &device_desc, 256 .dev = &device_desc,
258 .strings = dev_strings, 257 .strings = dev_strings,
259 .bind = hid_bind,
260 .unbind = __exit_p(hid_unbind), 258 .unbind = __exit_p(hid_unbind),
261}; 259};
262 260
@@ -282,7 +280,7 @@ static int __init hidg_init(void)
282 if (status < 0) 280 if (status < 0)
283 return status; 281 return status;
284 282
285 status = usb_composite_register(&hidg_driver); 283 status = usb_composite_probe(&hidg_driver, hid_bind);
286 if (status < 0) 284 if (status < 0)
287 platform_driver_unregister(&hidg_plat_driver); 285 platform_driver_unregister(&hidg_plat_driver);
288 286
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index e743122fcd93..ade40066decf 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -30,6 +30,7 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/timer.h> 31#include <linux/timer.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/prefetch.h>
33 34
34#include <linux/usb/ch9.h> 35#include <linux/usb/ch9.h>
35#include <linux/usb/gadget.h> 36#include <linux/usb/gadget.h>
@@ -1191,13 +1192,17 @@ static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev)
1191 return IRQ_HANDLED; 1192 return IRQ_HANDLED;
1192} 1193}
1193 1194
1195#ifndef MX1_INT_USBD0
1196#define MX1_INT_USBD0 MX1_USBD_INT0
1197#endif
1198
1194static irqreturn_t imx_udc_bulk_irq(int irq, void *dev) 1199static irqreturn_t imx_udc_bulk_irq(int irq, void *dev)
1195{ 1200{
1196 struct imx_udc_struct *imx_usb = dev; 1201 struct imx_udc_struct *imx_usb = dev;
1197 struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[irq - USBD_INT0]; 1202 struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[irq - MX1_INT_USBD0];
1198 int intr = __raw_readl(imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); 1203 int intr = __raw_readl(imx_usb->base + USB_EP_INTR(EP_NO(imx_ep)));
1199 1204
1200 dump_ep_intr(__func__, irq - USBD_INT0, intr, imx_usb->dev); 1205 dump_ep_intr(__func__, irq - MX1_INT_USBD0, intr, imx_usb->dev);
1201 1206
1202 if (!imx_usb->driver) { 1207 if (!imx_usb->driver) {
1203 __raw_writel(intr, imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); 1208 __raw_writel(intr, imx_usb->base + USB_EP_INTR(EP_NO(imx_ep)));
@@ -1316,17 +1321,18 @@ static struct imx_udc_struct controller = {
1316}; 1321};
1317 1322
1318/******************************************************************************* 1323/*******************************************************************************
1319 * USB gadged driver functions 1324 * USB gadget driver functions
1320 ******************************************************************************* 1325 *******************************************************************************
1321 */ 1326 */
1322int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1327int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1328 int (*bind)(struct usb_gadget *))
1323{ 1329{
1324 struct imx_udc_struct *imx_usb = &controller; 1330 struct imx_udc_struct *imx_usb = &controller;
1325 int retval; 1331 int retval;
1326 1332
1327 if (!driver 1333 if (!driver
1328 || driver->speed < USB_SPEED_FULL 1334 || driver->speed < USB_SPEED_FULL
1329 || !driver->bind 1335 || !bind
1330 || !driver->disconnect 1336 || !driver->disconnect
1331 || !driver->setup) 1337 || !driver->setup)
1332 return -EINVAL; 1338 return -EINVAL;
@@ -1342,7 +1348,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1342 retval = device_add(&imx_usb->gadget.dev); 1348 retval = device_add(&imx_usb->gadget.dev);
1343 if (retval) 1349 if (retval)
1344 goto fail; 1350 goto fail;
1345 retval = driver->bind(&imx_usb->gadget); 1351 retval = bind(&imx_usb->gadget);
1346 if (retval) { 1352 if (retval) {
1347 D_ERR(imx_usb->dev, "<%s> bind to driver %s --> error %d\n", 1353 D_ERR(imx_usb->dev, "<%s> bind to driver %s --> error %d\n",
1348 __func__, driver->driver.name, retval); 1354 __func__, driver->driver.name, retval);
@@ -1362,7 +1368,7 @@ fail:
1362 imx_usb->gadget.dev.driver = NULL; 1368 imx_usb->gadget.dev.driver = NULL;
1363 return retval; 1369 return retval;
1364} 1370}
1365EXPORT_SYMBOL(usb_gadget_register_driver); 1371EXPORT_SYMBOL(usb_gadget_probe_driver);
1366 1372
1367int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1373int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1368{ 1374{
diff --git a/drivers/usb/gadget/imx_udc.h b/drivers/usb/gadget/imx_udc.h
index b48ad59603d1..7136c242b4ec 100644
--- a/drivers/usb/gadget/imx_udc.h
+++ b/drivers/usb/gadget/imx_udc.h
@@ -23,9 +23,6 @@
23/* Helper macros */ 23/* Helper macros */
24#define EP_NO(ep) ((ep->bEndpointAddress) & ~USB_DIR_IN) /* IN:1, OUT:0 */ 24#define EP_NO(ep) ((ep->bEndpointAddress) & ~USB_DIR_IN) /* IN:1, OUT:0 */
25#define EP_DIR(ep) ((ep->bEndpointAddress) & USB_DIR_IN ? 1 : 0) 25#define EP_DIR(ep) ((ep->bEndpointAddress) & USB_DIR_IN ? 1 : 0)
26#define irq_to_ep(irq) (((irq) >= USBD_INT0) || ((irq) <= USBD_INT6) \
27 ? ((irq) - USBD_INT0) : (USBD_INT6)) /*should not happen*/
28#define ep_to_irq(ep) (EP_NO((ep)) + USBD_INT0)
29#define IMX_USB_NB_EP 6 26#define IMX_USB_NB_EP 6
30 27
31/* Driver structures */ 28/* Driver structures */
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index fc35406fc80c..a56876aaf76c 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -33,7 +33,6 @@
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/poll.h> 35#include <linux/poll.h>
36#include <linux/smp_lock.h>
37 36
38#include <linux/device.h> 37#include <linux/device.h>
39#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
@@ -387,8 +386,10 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
387 386
388 /* halt any endpoint by doing a "wrong direction" i/o call */ 387 /* halt any endpoint by doing a "wrong direction" i/o call */
389 if (usb_endpoint_dir_in(&data->desc)) { 388 if (usb_endpoint_dir_in(&data->desc)) {
390 if (usb_endpoint_xfer_isoc(&data->desc)) 389 if (usb_endpoint_xfer_isoc(&data->desc)) {
390 mutex_unlock(&data->lock);
391 return -EINVAL; 391 return -EINVAL;
392 }
392 DBG (data->dev, "%s halt\n", data->name); 393 DBG (data->dev, "%s halt\n", data->name);
393 spin_lock_irq (&data->dev->lock); 394 spin_lock_irq (&data->dev->lock);
394 if (likely (data->ep != NULL)) 395 if (likely (data->ep != NULL))
@@ -430,8 +431,10 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
430 431
431 /* halt any endpoint by doing a "wrong direction" i/o call */ 432 /* halt any endpoint by doing a "wrong direction" i/o call */
432 if (!usb_endpoint_dir_in(&data->desc)) { 433 if (!usb_endpoint_dir_in(&data->desc)) {
433 if (usb_endpoint_xfer_isoc(&data->desc)) 434 if (usb_endpoint_xfer_isoc(&data->desc)) {
435 mutex_unlock(&data->lock);
434 return -EINVAL; 436 return -EINVAL;
437 }
435 DBG (data->dev, "%s halt\n", data->name); 438 DBG (data->dev, "%s halt\n", data->name);
436 spin_lock_irq (&data->dev->lock); 439 spin_lock_irq (&data->dev->lock);
437 if (likely (data->ep != NULL)) 440 if (likely (data->ep != NULL))
@@ -1775,7 +1778,6 @@ static struct usb_gadget_driver gadgetfs_driver = {
1775 .speed = USB_SPEED_FULL, 1778 .speed = USB_SPEED_FULL,
1776#endif 1779#endif
1777 .function = (char *) driver_desc, 1780 .function = (char *) driver_desc,
1778 .bind = gadgetfs_bind,
1779 .unbind = gadgetfs_unbind, 1781 .unbind = gadgetfs_unbind,
1780 .setup = gadgetfs_setup, 1782 .setup = gadgetfs_setup,
1781 .disconnect = gadgetfs_disconnect, 1783 .disconnect = gadgetfs_disconnect,
@@ -1798,7 +1800,6 @@ static int gadgetfs_probe (struct usb_gadget *gadget)
1798 1800
1799static struct usb_gadget_driver probe_driver = { 1801static struct usb_gadget_driver probe_driver = {
1800 .speed = USB_SPEED_HIGH, 1802 .speed = USB_SPEED_HIGH,
1801 .bind = gadgetfs_probe,
1802 .unbind = gadgetfs_nop, 1803 .unbind = gadgetfs_nop,
1803 .setup = (void *)gadgetfs_nop, 1804 .setup = (void *)gadgetfs_nop,
1804 .disconnect = gadgetfs_nop, 1805 .disconnect = gadgetfs_nop,
@@ -1908,7 +1909,7 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1908 1909
1909 /* triggers gadgetfs_bind(); then we can enumerate. */ 1910 /* triggers gadgetfs_bind(); then we can enumerate. */
1910 spin_unlock_irq (&dev->lock); 1911 spin_unlock_irq (&dev->lock);
1911 value = usb_gadget_register_driver (&gadgetfs_driver); 1912 value = usb_gadget_probe_driver(&gadgetfs_driver, gadgetfs_bind);
1912 if (value != 0) { 1913 if (value != 0) {
1913 kfree (dev->buf); 1914 kfree (dev->buf);
1914 dev->buf = NULL; 1915 dev->buf = NULL;
@@ -1994,6 +1995,7 @@ gadgetfs_make_inode (struct super_block *sb,
1994 struct inode *inode = new_inode (sb); 1995 struct inode *inode = new_inode (sb);
1995 1996
1996 if (inode) { 1997 if (inode) {
1998 inode->i_ino = get_next_ino();
1997 inode->i_mode = mode; 1999 inode->i_mode = mode;
1998 inode->i_uid = default_uid; 2000 inode->i_uid = default_uid;
1999 inode->i_gid = default_gid; 2001 inode->i_gid = default_gid;
@@ -2047,7 +2049,7 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)
2047 return -ESRCH; 2049 return -ESRCH;
2048 2050
2049 /* fake probe to determine $CHIP */ 2051 /* fake probe to determine $CHIP */
2050 (void) usb_gadget_register_driver (&probe_driver); 2052 (void) usb_gadget_probe_driver(&probe_driver, gadgetfs_probe);
2051 if (!CHIP) 2053 if (!CHIP)
2052 return -ENODEV; 2054 return -ENODEV;
2053 2055
@@ -2099,11 +2101,11 @@ enomem0:
2099} 2101}
2100 2102
2101/* "mount -t gadgetfs path /dev/gadget" ends up here */ 2103/* "mount -t gadgetfs path /dev/gadget" ends up here */
2102static int 2104static struct dentry *
2103gadgetfs_get_sb (struct file_system_type *t, int flags, 2105gadgetfs_mount (struct file_system_type *t, int flags,
2104 const char *path, void *opts, struct vfsmount *mnt) 2106 const char *path, void *opts)
2105{ 2107{
2106 return get_sb_single (t, flags, opts, gadgetfs_fill_super, mnt); 2108 return mount_single (t, flags, opts, gadgetfs_fill_super);
2107} 2109}
2108 2110
2109static void 2111static void
@@ -2121,7 +2123,7 @@ gadgetfs_kill_sb (struct super_block *sb)
2121static struct file_system_type gadgetfs_type = { 2123static struct file_system_type gadgetfs_type = {
2122 .owner = THIS_MODULE, 2124 .owner = THIS_MODULE,
2123 .name = shortname, 2125 .name = shortname,
2124 .get_sb = gadgetfs_get_sb, 2126 .mount = gadgetfs_mount,
2125 .kill_sb = gadgetfs_kill_sb, 2127 .kill_sb = gadgetfs_kill_sb,
2126}; 2128};
2127 2129
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index c2d2a201f84b..9cee88a43a73 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -19,7 +19,7 @@
19 19
20 20
21/* #undef DEBUG */ 21/* #undef DEBUG */
22/* #undef VERBOSE */ 22/* #undef VERBOSE_DEBUG */
23 23
24#if defined(CONFIG_USB_LANGWELL_OTG) 24#if defined(CONFIG_USB_LANGWELL_OTG)
25#define OTG_TRANSCEIVER 25#define OTG_TRANSCEIVER
@@ -77,141 +77,110 @@ langwell_ep0_desc = {
77/*-------------------------------------------------------------------------*/ 77/*-------------------------------------------------------------------------*/
78/* debugging */ 78/* debugging */
79 79
80#ifdef DEBUG 80#ifdef VERBOSE_DEBUG
81#define DBG(dev, fmt, args...) \
82 pr_debug("%s %s: " fmt , driver_name, \
83 pci_name(dev->pdev), ## args)
84#else
85#define DBG(dev, fmt, args...) \
86 do { } while (0)
87#endif /* DEBUG */
88
89
90#ifdef VERBOSE
91#define VDBG DBG
92#else
93#define VDBG(dev, fmt, args...) \
94 do { } while (0)
95#endif /* VERBOSE */
96
97
98#define ERROR(dev, fmt, args...) \
99 pr_err("%s %s: " fmt , driver_name, \
100 pci_name(dev->pdev), ## args)
101
102#define WARNING(dev, fmt, args...) \
103 pr_warning("%s %s: " fmt , driver_name, \
104 pci_name(dev->pdev), ## args)
105
106#define INFO(dev, fmt, args...) \
107 pr_info("%s %s: " fmt , driver_name, \
108 pci_name(dev->pdev), ## args)
109
110
111#ifdef VERBOSE
112static inline void print_all_registers(struct langwell_udc *dev) 81static inline void print_all_registers(struct langwell_udc *dev)
113{ 82{
114 int i; 83 int i;
115 84
116 /* Capability Registers */ 85 /* Capability Registers */
117 printk(KERN_DEBUG "Capability Registers (offset: " 86 dev_dbg(&dev->pdev->dev,
118 "0x%04x, length: 0x%08x)\n", 87 "Capability Registers (offset: 0x%04x, length: 0x%08x)\n",
119 CAP_REG_OFFSET, 88 CAP_REG_OFFSET, (u32)sizeof(struct langwell_cap_regs));
120 (u32)sizeof(struct langwell_cap_regs)); 89 dev_dbg(&dev->pdev->dev, "caplength=0x%02x\n",
121 printk(KERN_DEBUG "caplength=0x%02x\n",
122 readb(&dev->cap_regs->caplength)); 90 readb(&dev->cap_regs->caplength));
123 printk(KERN_DEBUG "hciversion=0x%04x\n", 91 dev_dbg(&dev->pdev->dev, "hciversion=0x%04x\n",
124 readw(&dev->cap_regs->hciversion)); 92 readw(&dev->cap_regs->hciversion));
125 printk(KERN_DEBUG "hcsparams=0x%08x\n", 93 dev_dbg(&dev->pdev->dev, "hcsparams=0x%08x\n",
126 readl(&dev->cap_regs->hcsparams)); 94 readl(&dev->cap_regs->hcsparams));
127 printk(KERN_DEBUG "hccparams=0x%08x\n", 95 dev_dbg(&dev->pdev->dev, "hccparams=0x%08x\n",
128 readl(&dev->cap_regs->hccparams)); 96 readl(&dev->cap_regs->hccparams));
129 printk(KERN_DEBUG "dciversion=0x%04x\n", 97 dev_dbg(&dev->pdev->dev, "dciversion=0x%04x\n",
130 readw(&dev->cap_regs->dciversion)); 98 readw(&dev->cap_regs->dciversion));
131 printk(KERN_DEBUG "dccparams=0x%08x\n", 99 dev_dbg(&dev->pdev->dev, "dccparams=0x%08x\n",
132 readl(&dev->cap_regs->dccparams)); 100 readl(&dev->cap_regs->dccparams));
133 101
134 /* Operational Registers */ 102 /* Operational Registers */
135 printk(KERN_DEBUG "Operational Registers (offset: " 103 dev_dbg(&dev->pdev->dev,
136 "0x%04x, length: 0x%08x)\n", 104 "Operational Registers (offset: 0x%04x, length: 0x%08x)\n",
137 OP_REG_OFFSET, 105 OP_REG_OFFSET, (u32)sizeof(struct langwell_op_regs));
138 (u32)sizeof(struct langwell_op_regs)); 106 dev_dbg(&dev->pdev->dev, "extsts=0x%08x\n",
139 printk(KERN_DEBUG "extsts=0x%08x\n",
140 readl(&dev->op_regs->extsts)); 107 readl(&dev->op_regs->extsts));
141 printk(KERN_DEBUG "extintr=0x%08x\n", 108 dev_dbg(&dev->pdev->dev, "extintr=0x%08x\n",
142 readl(&dev->op_regs->extintr)); 109 readl(&dev->op_regs->extintr));
143 printk(KERN_DEBUG "usbcmd=0x%08x\n", 110 dev_dbg(&dev->pdev->dev, "usbcmd=0x%08x\n",
144 readl(&dev->op_regs->usbcmd)); 111 readl(&dev->op_regs->usbcmd));
145 printk(KERN_DEBUG "usbsts=0x%08x\n", 112 dev_dbg(&dev->pdev->dev, "usbsts=0x%08x\n",
146 readl(&dev->op_regs->usbsts)); 113 readl(&dev->op_regs->usbsts));
147 printk(KERN_DEBUG "usbintr=0x%08x\n", 114 dev_dbg(&dev->pdev->dev, "usbintr=0x%08x\n",
148 readl(&dev->op_regs->usbintr)); 115 readl(&dev->op_regs->usbintr));
149 printk(KERN_DEBUG "frindex=0x%08x\n", 116 dev_dbg(&dev->pdev->dev, "frindex=0x%08x\n",
150 readl(&dev->op_regs->frindex)); 117 readl(&dev->op_regs->frindex));
151 printk(KERN_DEBUG "ctrldssegment=0x%08x\n", 118 dev_dbg(&dev->pdev->dev, "ctrldssegment=0x%08x\n",
152 readl(&dev->op_regs->ctrldssegment)); 119 readl(&dev->op_regs->ctrldssegment));
153 printk(KERN_DEBUG "deviceaddr=0x%08x\n", 120 dev_dbg(&dev->pdev->dev, "deviceaddr=0x%08x\n",
154 readl(&dev->op_regs->deviceaddr)); 121 readl(&dev->op_regs->deviceaddr));
155 printk(KERN_DEBUG "endpointlistaddr=0x%08x\n", 122 dev_dbg(&dev->pdev->dev, "endpointlistaddr=0x%08x\n",
156 readl(&dev->op_regs->endpointlistaddr)); 123 readl(&dev->op_regs->endpointlistaddr));
157 printk(KERN_DEBUG "ttctrl=0x%08x\n", 124 dev_dbg(&dev->pdev->dev, "ttctrl=0x%08x\n",
158 readl(&dev->op_regs->ttctrl)); 125 readl(&dev->op_regs->ttctrl));
159 printk(KERN_DEBUG "burstsize=0x%08x\n", 126 dev_dbg(&dev->pdev->dev, "burstsize=0x%08x\n",
160 readl(&dev->op_regs->burstsize)); 127 readl(&dev->op_regs->burstsize));
161 printk(KERN_DEBUG "txfilltuning=0x%08x\n", 128 dev_dbg(&dev->pdev->dev, "txfilltuning=0x%08x\n",
162 readl(&dev->op_regs->txfilltuning)); 129 readl(&dev->op_regs->txfilltuning));
163 printk(KERN_DEBUG "txttfilltuning=0x%08x\n", 130 dev_dbg(&dev->pdev->dev, "txttfilltuning=0x%08x\n",
164 readl(&dev->op_regs->txttfilltuning)); 131 readl(&dev->op_regs->txttfilltuning));
165 printk(KERN_DEBUG "ic_usb=0x%08x\n", 132 dev_dbg(&dev->pdev->dev, "ic_usb=0x%08x\n",
166 readl(&dev->op_regs->ic_usb)); 133 readl(&dev->op_regs->ic_usb));
167 printk(KERN_DEBUG "ulpi_viewport=0x%08x\n", 134 dev_dbg(&dev->pdev->dev, "ulpi_viewport=0x%08x\n",
168 readl(&dev->op_regs->ulpi_viewport)); 135 readl(&dev->op_regs->ulpi_viewport));
169 printk(KERN_DEBUG "configflag=0x%08x\n", 136 dev_dbg(&dev->pdev->dev, "configflag=0x%08x\n",
170 readl(&dev->op_regs->configflag)); 137 readl(&dev->op_regs->configflag));
171 printk(KERN_DEBUG "portsc1=0x%08x\n", 138 dev_dbg(&dev->pdev->dev, "portsc1=0x%08x\n",
172 readl(&dev->op_regs->portsc1)); 139 readl(&dev->op_regs->portsc1));
173 printk(KERN_DEBUG "devlc=0x%08x\n", 140 dev_dbg(&dev->pdev->dev, "devlc=0x%08x\n",
174 readl(&dev->op_regs->devlc)); 141 readl(&dev->op_regs->devlc));
175 printk(KERN_DEBUG "otgsc=0x%08x\n", 142 dev_dbg(&dev->pdev->dev, "otgsc=0x%08x\n",
176 readl(&dev->op_regs->otgsc)); 143 readl(&dev->op_regs->otgsc));
177 printk(KERN_DEBUG "usbmode=0x%08x\n", 144 dev_dbg(&dev->pdev->dev, "usbmode=0x%08x\n",
178 readl(&dev->op_regs->usbmode)); 145 readl(&dev->op_regs->usbmode));
179 printk(KERN_DEBUG "endptnak=0x%08x\n", 146 dev_dbg(&dev->pdev->dev, "endptnak=0x%08x\n",
180 readl(&dev->op_regs->endptnak)); 147 readl(&dev->op_regs->endptnak));
181 printk(KERN_DEBUG "endptnaken=0x%08x\n", 148 dev_dbg(&dev->pdev->dev, "endptnaken=0x%08x\n",
182 readl(&dev->op_regs->endptnaken)); 149 readl(&dev->op_regs->endptnaken));
183 printk(KERN_DEBUG "endptsetupstat=0x%08x\n", 150 dev_dbg(&dev->pdev->dev, "endptsetupstat=0x%08x\n",
184 readl(&dev->op_regs->endptsetupstat)); 151 readl(&dev->op_regs->endptsetupstat));
185 printk(KERN_DEBUG "endptprime=0x%08x\n", 152 dev_dbg(&dev->pdev->dev, "endptprime=0x%08x\n",
186 readl(&dev->op_regs->endptprime)); 153 readl(&dev->op_regs->endptprime));
187 printk(KERN_DEBUG "endptflush=0x%08x\n", 154 dev_dbg(&dev->pdev->dev, "endptflush=0x%08x\n",
188 readl(&dev->op_regs->endptflush)); 155 readl(&dev->op_regs->endptflush));
189 printk(KERN_DEBUG "endptstat=0x%08x\n", 156 dev_dbg(&dev->pdev->dev, "endptstat=0x%08x\n",
190 readl(&dev->op_regs->endptstat)); 157 readl(&dev->op_regs->endptstat));
191 printk(KERN_DEBUG "endptcomplete=0x%08x\n", 158 dev_dbg(&dev->pdev->dev, "endptcomplete=0x%08x\n",
192 readl(&dev->op_regs->endptcomplete)); 159 readl(&dev->op_regs->endptcomplete));
193 160
194 for (i = 0; i < dev->ep_max / 2; i++) { 161 for (i = 0; i < dev->ep_max / 2; i++) {
195 printk(KERN_DEBUG "endptctrl[%d]=0x%08x\n", 162 dev_dbg(&dev->pdev->dev, "endptctrl[%d]=0x%08x\n",
196 i, readl(&dev->op_regs->endptctrl[i])); 163 i, readl(&dev->op_regs->endptctrl[i]));
197 } 164 }
198} 165}
199#endif /* VERBOSE */ 166#else
167
168#define print_all_registers(dev) do { } while (0)
169
170#endif /* VERBOSE_DEBUG */
200 171
201 172
202/*-------------------------------------------------------------------------*/ 173/*-------------------------------------------------------------------------*/
203 174
204#define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out") 175#define is_in(ep) (((ep)->ep_num == 0) ? ((ep)->dev->ep0_dir == \
176 USB_DIR_IN) : (usb_endpoint_dir_in((ep)->desc)))
205 177
206#define is_in(ep) (((ep)->ep_num == 0) ? ((ep)->dev->ep0_dir == \ 178#define DIR_STRING(ep) (is_in(ep) ? "in" : "out")
207 USB_DIR_IN) : ((ep)->desc->bEndpointAddress \
208 & USB_DIR_IN) == USB_DIR_IN)
209 179
210 180
211#ifdef DEBUG 181static char *type_string(const struct usb_endpoint_descriptor *desc)
212static char *type_string(u8 bmAttributes)
213{ 182{
214 switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) { 183 switch (usb_endpoint_type(desc)) {
215 case USB_ENDPOINT_XFER_BULK: 184 case USB_ENDPOINT_XFER_BULK:
216 return "bulk"; 185 return "bulk";
217 case USB_ENDPOINT_XFER_ISOC: 186 case USB_ENDPOINT_XFER_ISOC:
@@ -222,7 +191,6 @@ static char *type_string(u8 bmAttributes)
222 191
223 return "control"; 192 return "control";
224} 193}
225#endif
226 194
227 195
228/* configure endpoint control registers */ 196/* configure endpoint control registers */
@@ -233,7 +201,7 @@ static void ep_reset(struct langwell_ep *ep, unsigned char ep_num,
233 u32 endptctrl; 201 u32 endptctrl;
234 202
235 dev = ep->dev; 203 dev = ep->dev;
236 VDBG(dev, "---> %s()\n", __func__); 204 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
237 205
238 endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); 206 endptctrl = readl(&dev->op_regs->endptctrl[ep_num]);
239 if (is_in) { /* TX */ 207 if (is_in) { /* TX */
@@ -250,7 +218,7 @@ static void ep_reset(struct langwell_ep *ep, unsigned char ep_num,
250 218
251 writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); 219 writel(endptctrl, &dev->op_regs->endptctrl[ep_num]);
252 220
253 VDBG(dev, "<--- %s()\n", __func__); 221 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
254} 222}
255 223
256 224
@@ -260,7 +228,7 @@ static void ep0_reset(struct langwell_udc *dev)
260 struct langwell_ep *ep; 228 struct langwell_ep *ep;
261 int i; 229 int i;
262 230
263 VDBG(dev, "---> %s()\n", __func__); 231 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
264 232
265 /* ep0 in and out */ 233 /* ep0 in and out */
266 for (i = 0; i < 2; i++) { 234 for (i = 0; i < 2; i++) {
@@ -274,17 +242,18 @@ static void ep0_reset(struct langwell_udc *dev)
274 ep->dqh->dqh_ios = 1; 242 ep->dqh->dqh_ios = 1;
275 ep->dqh->dqh_mpl = EP0_MAX_PKT_SIZE; 243 ep->dqh->dqh_mpl = EP0_MAX_PKT_SIZE;
276 244
277 /* FIXME: enable ep0-in HW zero length termination select */ 245 /* enable ep0-in HW zero length termination select */
278 if (is_in(ep)) 246 if (is_in(ep))
279 ep->dqh->dqh_zlt = 0; 247 ep->dqh->dqh_zlt = 0;
280 ep->dqh->dqh_mult = 0; 248 ep->dqh->dqh_mult = 0;
281 249
250 ep->dqh->dtd_next = DTD_TERM;
251
282 /* configure ep0 control registers */ 252 /* configure ep0 control registers */
283 ep_reset(&dev->ep[0], 0, i, USB_ENDPOINT_XFER_CONTROL); 253 ep_reset(&dev->ep[0], 0, i, USB_ENDPOINT_XFER_CONTROL);
284 } 254 }
285 255
286 VDBG(dev, "<--- %s()\n", __func__); 256 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
287 return;
288} 257}
289 258
290 259
@@ -300,12 +269,12 @@ static int langwell_ep_enable(struct usb_ep *_ep,
300 struct langwell_ep *ep; 269 struct langwell_ep *ep;
301 u16 max = 0; 270 u16 max = 0;
302 unsigned long flags; 271 unsigned long flags;
303 int retval = 0; 272 int i, retval = 0;
304 unsigned char zlt, ios = 0, mult = 0; 273 unsigned char zlt, ios = 0, mult = 0;
305 274
306 ep = container_of(_ep, struct langwell_ep, ep); 275 ep = container_of(_ep, struct langwell_ep, ep);
307 dev = ep->dev; 276 dev = ep->dev;
308 VDBG(dev, "---> %s()\n", __func__); 277 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
309 278
310 if (!_ep || !desc || ep->desc 279 if (!_ep || !desc || ep->desc
311 || desc->bDescriptorType != USB_DT_ENDPOINT) 280 || desc->bDescriptorType != USB_DT_ENDPOINT)
@@ -326,7 +295,7 @@ static int langwell_ep_enable(struct usb_ep *_ep,
326 * sanity check type, direction, address, and then 295 * sanity check type, direction, address, and then
327 * initialize the endpoint capabilities fields in dQH 296 * initialize the endpoint capabilities fields in dQH
328 */ 297 */
329 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 298 switch (usb_endpoint_type(desc)) {
330 case USB_ENDPOINT_XFER_CONTROL: 299 case USB_ENDPOINT_XFER_CONTROL:
331 ios = 1; 300 ios = 1;
332 break; 301 break;
@@ -386,33 +355,36 @@ static int langwell_ep_enable(struct usb_ep *_ep,
386 355
387 spin_lock_irqsave(&dev->lock, flags); 356 spin_lock_irqsave(&dev->lock, flags);
388 357
389 /* configure endpoint capabilities in dQH */
390 ep->dqh->dqh_ios = ios;
391 ep->dqh->dqh_mpl = cpu_to_le16(max);
392 ep->dqh->dqh_zlt = zlt;
393 ep->dqh->dqh_mult = mult;
394
395 ep->ep.maxpacket = max; 358 ep->ep.maxpacket = max;
396 ep->desc = desc; 359 ep->desc = desc;
397 ep->stopped = 0; 360 ep->stopped = 0;
398 ep->ep_num = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 361 ep->ep_num = usb_endpoint_num(desc);
399 362
400 /* ep_type */ 363 /* ep_type */
401 ep->ep_type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 364 ep->ep_type = usb_endpoint_type(desc);
402 365
403 /* configure endpoint control registers */ 366 /* configure endpoint control registers */
404 ep_reset(ep, ep->ep_num, is_in(ep), ep->ep_type); 367 ep_reset(ep, ep->ep_num, is_in(ep), ep->ep_type);
405 368
406 DBG(dev, "enabled %s (ep%d%s-%s), max %04x\n", 369 /* configure endpoint capabilities in dQH */
370 i = ep->ep_num * 2 + is_in(ep);
371 ep->dqh = &dev->ep_dqh[i];
372 ep->dqh->dqh_ios = ios;
373 ep->dqh->dqh_mpl = cpu_to_le16(max);
374 ep->dqh->dqh_zlt = zlt;
375 ep->dqh->dqh_mult = mult;
376 ep->dqh->dtd_next = DTD_TERM;
377
378 dev_dbg(&dev->pdev->dev, "enabled %s (ep%d%s-%s), max %04x\n",
407 _ep->name, 379 _ep->name,
408 ep->ep_num, 380 ep->ep_num,
409 DIR_STRING(desc->bEndpointAddress), 381 DIR_STRING(ep),
410 type_string(desc->bmAttributes), 382 type_string(desc),
411 max); 383 max);
412 384
413 spin_unlock_irqrestore(&dev->lock, flags); 385 spin_unlock_irqrestore(&dev->lock, flags);
414done: 386done:
415 VDBG(dev, "<--- %s()\n", __func__); 387 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
416 return retval; 388 return retval;
417} 389}
418 390
@@ -428,7 +400,7 @@ static void done(struct langwell_ep *ep, struct langwell_request *req,
428 struct langwell_dtd *curr_dtd, *next_dtd; 400 struct langwell_dtd *curr_dtd, *next_dtd;
429 int i; 401 int i;
430 402
431 VDBG(dev, "---> %s()\n", __func__); 403 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
432 404
433 /* remove the req from ep->queue */ 405 /* remove the req from ep->queue */
434 list_del_init(&req->queue); 406 list_del_init(&req->queue);
@@ -448,7 +420,8 @@ static void done(struct langwell_ep *ep, struct langwell_request *req,
448 } 420 }
449 421
450 if (req->mapped) { 422 if (req->mapped) {
451 dma_unmap_single(&dev->pdev->dev, req->req.dma, req->req.length, 423 dma_unmap_single(&dev->pdev->dev,
424 req->req.dma, req->req.length,
452 is_in(ep) ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); 425 is_in(ep) ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
453 req->req.dma = DMA_ADDR_INVALID; 426 req->req.dma = DMA_ADDR_INVALID;
454 req->mapped = 0; 427 req->mapped = 0;
@@ -458,9 +431,10 @@ static void done(struct langwell_ep *ep, struct langwell_request *req,
458 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 431 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
459 432
460 if (status != -ESHUTDOWN) 433 if (status != -ESHUTDOWN)
461 DBG(dev, "complete %s, req %p, stat %d, len %u/%u\n", 434 dev_dbg(&dev->pdev->dev,
462 ep->ep.name, &req->req, status, 435 "complete %s, req %p, stat %d, len %u/%u\n",
463 req->req.actual, req->req.length); 436 ep->ep.name, &req->req, status,
437 req->req.actual, req->req.length);
464 438
465 /* don't modify queue heads during completion callback */ 439 /* don't modify queue heads during completion callback */
466 ep->stopped = 1; 440 ep->stopped = 1;
@@ -473,7 +447,7 @@ static void done(struct langwell_ep *ep, struct langwell_request *req,
473 spin_lock(&dev->lock); 447 spin_lock(&dev->lock);
474 ep->stopped = stopped; 448 ep->stopped = stopped;
475 449
476 VDBG(dev, "<--- %s()\n", __func__); 450 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
477} 451}
478 452
479 453
@@ -511,7 +485,7 @@ static int langwell_ep_disable(struct usb_ep *_ep)
511 485
512 ep = container_of(_ep, struct langwell_ep, ep); 486 ep = container_of(_ep, struct langwell_ep, ep);
513 dev = ep->dev; 487 dev = ep->dev;
514 VDBG(dev, "---> %s()\n", __func__); 488 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
515 489
516 if (!_ep || !ep->desc) 490 if (!_ep || !ep->desc)
517 return -EINVAL; 491 return -EINVAL;
@@ -535,8 +509,8 @@ static int langwell_ep_disable(struct usb_ep *_ep)
535 509
536 spin_unlock_irqrestore(&dev->lock, flags); 510 spin_unlock_irqrestore(&dev->lock, flags);
537 511
538 DBG(dev, "disabled %s\n", _ep->name); 512 dev_dbg(&dev->pdev->dev, "disabled %s\n", _ep->name);
539 VDBG(dev, "<--- %s()\n", __func__); 513 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
540 514
541 return 0; 515 return 0;
542} 516}
@@ -555,7 +529,7 @@ static struct usb_request *langwell_alloc_request(struct usb_ep *_ep,
555 529
556 ep = container_of(_ep, struct langwell_ep, ep); 530 ep = container_of(_ep, struct langwell_ep, ep);
557 dev = ep->dev; 531 dev = ep->dev;
558 VDBG(dev, "---> %s()\n", __func__); 532 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
559 533
560 req = kzalloc(sizeof(*req), gfp_flags); 534 req = kzalloc(sizeof(*req), gfp_flags);
561 if (!req) 535 if (!req)
@@ -564,8 +538,8 @@ static struct usb_request *langwell_alloc_request(struct usb_ep *_ep,
564 req->req.dma = DMA_ADDR_INVALID; 538 req->req.dma = DMA_ADDR_INVALID;
565 INIT_LIST_HEAD(&req->queue); 539 INIT_LIST_HEAD(&req->queue);
566 540
567 VDBG(dev, "alloc request for %s\n", _ep->name); 541 dev_vdbg(&dev->pdev->dev, "alloc request for %s\n", _ep->name);
568 VDBG(dev, "<--- %s()\n", __func__); 542 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
569 return &req->req; 543 return &req->req;
570} 544}
571 545
@@ -580,7 +554,7 @@ static void langwell_free_request(struct usb_ep *_ep,
580 554
581 ep = container_of(_ep, struct langwell_ep, ep); 555 ep = container_of(_ep, struct langwell_ep, ep);
582 dev = ep->dev; 556 dev = ep->dev;
583 VDBG(dev, "---> %s()\n", __func__); 557 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
584 558
585 if (!_ep || !_req) 559 if (!_ep || !_req)
586 return; 560 return;
@@ -591,8 +565,8 @@ static void langwell_free_request(struct usb_ep *_ep,
591 if (_req) 565 if (_req)
592 kfree(req); 566 kfree(req);
593 567
594 VDBG(dev, "free request for %s\n", _ep->name); 568 dev_vdbg(&dev->pdev->dev, "free request for %s\n", _ep->name);
595 VDBG(dev, "<--- %s()\n", __func__); 569 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
596} 570}
597 571
598 572
@@ -608,23 +582,24 @@ static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req)
608 struct langwell_udc *dev; 582 struct langwell_udc *dev;
609 583
610 dev = ep->dev; 584 dev = ep->dev;
611 VDBG(dev, "---> %s()\n", __func__); 585 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
612 586
613 i = ep->ep_num * 2 + is_in(ep); 587 i = ep->ep_num * 2 + is_in(ep);
614 dqh = &dev->ep_dqh[i]; 588 dqh = &dev->ep_dqh[i];
615 589
616 if (ep->ep_num) 590 if (ep->ep_num)
617 VDBG(dev, "%s\n", ep->name); 591 dev_vdbg(&dev->pdev->dev, "%s\n", ep->name);
618 else 592 else
619 /* ep0 */ 593 /* ep0 */
620 VDBG(dev, "%s-%s\n", ep->name, is_in(ep) ? "in" : "out"); 594 dev_vdbg(&dev->pdev->dev, "%s-%s\n", ep->name, DIR_STRING(ep));
621 595
622 VDBG(dev, "ep_dqh[%d] addr: 0x%08x\n", i, (u32)&(dev->ep_dqh[i])); 596 dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%08x\n",
597 i, (u32)&(dev->ep_dqh[i]));
623 598
624 bit_mask = is_in(ep) ? 599 bit_mask = is_in(ep) ?
625 (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num)); 600 (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num));
626 601
627 VDBG(dev, "bit_mask = 0x%08x\n", bit_mask); 602 dev_vdbg(&dev->pdev->dev, "bit_mask = 0x%08x\n", bit_mask);
628 603
629 /* check if the pipe is empty */ 604 /* check if the pipe is empty */
630 if (!(list_empty(&ep->queue))) { 605 if (!(list_empty(&ep->queue))) {
@@ -665,14 +640,17 @@ static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req)
665 /* clear active and halt bit */ 640 /* clear active and halt bit */
666 dtd_status = (u8) ~(DTD_STS_ACTIVE | DTD_STS_HALTED); 641 dtd_status = (u8) ~(DTD_STS_ACTIVE | DTD_STS_HALTED);
667 dqh->dtd_status &= dtd_status; 642 dqh->dtd_status &= dtd_status;
668 VDBG(dev, "dqh->dtd_status = 0x%x\n", dqh->dtd_status); 643 dev_vdbg(&dev->pdev->dev, "dqh->dtd_status = 0x%x\n", dqh->dtd_status);
644
645 /* ensure that updates to the dQH will occur before priming */
646 wmb();
669 647
670 /* write 1 to endptprime register to PRIME endpoint */ 648 /* write 1 to endptprime register to PRIME endpoint */
671 bit_mask = is_in(ep) ? (1 << (ep->ep_num + 16)) : (1 << ep->ep_num); 649 bit_mask = is_in(ep) ? (1 << (ep->ep_num + 16)) : (1 << ep->ep_num);
672 VDBG(dev, "endprime bit_mask = 0x%08x\n", bit_mask); 650 dev_vdbg(&dev->pdev->dev, "endprime bit_mask = 0x%08x\n", bit_mask);
673 writel(bit_mask, &dev->op_regs->endptprime); 651 writel(bit_mask, &dev->op_regs->endptprime);
674out: 652out:
675 VDBG(dev, "<--- %s()\n", __func__); 653 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
676 return 0; 654 return 0;
677} 655}
678 656
@@ -687,7 +665,7 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req,
687 int i; 665 int i;
688 666
689 dev = req->ep->dev; 667 dev = req->ep->dev;
690 VDBG(dev, "---> %s()\n", __func__); 668 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
691 669
692 /* the maximum transfer length, up to 16k bytes */ 670 /* the maximum transfer length, up to 16k bytes */
693 *length = min(req->req.length - req->req.actual, 671 *length = min(req->req.length - req->req.actual,
@@ -708,7 +686,7 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req,
708 686
709 /* fill in total bytes with transfer size */ 687 /* fill in total bytes with transfer size */
710 dtd->dtd_total = cpu_to_le16(*length); 688 dtd->dtd_total = cpu_to_le16(*length);
711 VDBG(dev, "dtd->dtd_total = %d\n", dtd->dtd_total); 689 dev_vdbg(&dev->pdev->dev, "dtd->dtd_total = %d\n", dtd->dtd_total);
712 690
713 /* set is_last flag if req->req.zero is set or not */ 691 /* set is_last flag if req->req.zero is set or not */
714 if (req->req.zero) { 692 if (req->req.zero) {
@@ -722,7 +700,7 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req,
722 *is_last = 0; 700 *is_last = 0;
723 701
724 if (*is_last == 0) 702 if (*is_last == 0)
725 VDBG(dev, "multi-dtd request!\n"); 703 dev_vdbg(&dev->pdev->dev, "multi-dtd request!\n");
726 704
727 /* set interrupt on complete bit for the last dTD */ 705 /* set interrupt on complete bit for the last dTD */
728 if (*is_last && !req->req.no_interrupt) 706 if (*is_last && !req->req.no_interrupt)
@@ -733,10 +711,12 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req,
733 711
734 /* set the active bit of status field to 1 */ 712 /* set the active bit of status field to 1 */
735 dtd->dtd_status = DTD_STS_ACTIVE; 713 dtd->dtd_status = DTD_STS_ACTIVE;
736 VDBG(dev, "dtd->dtd_status = 0x%02x\n", dtd->dtd_status); 714 dev_vdbg(&dev->pdev->dev, "dtd->dtd_status = 0x%02x\n",
715 dtd->dtd_status);
737 716
738 VDBG(dev, "length = %d, dma addr= 0x%08x\n", *length, (int)*dma); 717 dev_vdbg(&dev->pdev->dev, "length = %d, dma addr= 0x%08x\n",
739 VDBG(dev, "<--- %s()\n", __func__); 718 *length, (int)*dma);
719 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
740 return dtd; 720 return dtd;
741} 721}
742 722
@@ -751,7 +731,7 @@ static int req_to_dtd(struct langwell_request *req)
751 dma_addr_t dma; 731 dma_addr_t dma;
752 732
753 dev = req->ep->dev; 733 dev = req->ep->dev;
754 VDBG(dev, "---> %s()\n", __func__); 734 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
755 do { 735 do {
756 dtd = build_dtd(req, &count, &dma, &is_last); 736 dtd = build_dtd(req, &count, &dma, &is_last);
757 if (dtd == NULL) 737 if (dtd == NULL)
@@ -773,7 +753,7 @@ static int req_to_dtd(struct langwell_request *req)
773 753
774 req->tail = dtd; 754 req->tail = dtd;
775 755
776 VDBG(dev, "<--- %s()\n", __func__); 756 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
777 return 0; 757 return 0;
778} 758}
779 759
@@ -803,9 +783,9 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
803 783
804 dev = ep->dev; 784 dev = ep->dev;
805 req->ep = ep; 785 req->ep = ep;
806 VDBG(dev, "---> %s()\n", __func__); 786 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
807 787
808 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 788 if (usb_endpoint_xfer_isoc(ep->desc)) {
809 if (req->req.length > ep->ep.maxpacket) 789 if (req->req.length > ep->ep.maxpacket)
810 return -EMSGSIZE; 790 return -EMSGSIZE;
811 is_iso = 1; 791 is_iso = 1;
@@ -818,7 +798,7 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
818 if (_req->dma == DMA_ADDR_INVALID) { 798 if (_req->dma == DMA_ADDR_INVALID) {
819 /* WORKAROUND: WARN_ON(size == 0) */ 799 /* WORKAROUND: WARN_ON(size == 0) */
820 if (_req->length == 0) { 800 if (_req->length == 0) {
821 VDBG(dev, "req->length: 0->1\n"); 801 dev_vdbg(&dev->pdev->dev, "req->length: 0->1\n");
822 zlflag = 1; 802 zlflag = 1;
823 _req->length++; 803 _req->length++;
824 } 804 }
@@ -827,24 +807,25 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
827 _req->buf, _req->length, 807 _req->buf, _req->length,
828 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 808 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
829 if (zlflag && (_req->length == 1)) { 809 if (zlflag && (_req->length == 1)) {
830 VDBG(dev, "req->length: 1->0\n"); 810 dev_vdbg(&dev->pdev->dev, "req->length: 1->0\n");
831 zlflag = 0; 811 zlflag = 0;
832 _req->length = 0; 812 _req->length = 0;
833 } 813 }
834 814
835 req->mapped = 1; 815 req->mapped = 1;
836 VDBG(dev, "req->mapped = 1\n"); 816 dev_vdbg(&dev->pdev->dev, "req->mapped = 1\n");
837 } else { 817 } else {
838 dma_sync_single_for_device(&dev->pdev->dev, 818 dma_sync_single_for_device(&dev->pdev->dev,
839 _req->dma, _req->length, 819 _req->dma, _req->length,
840 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 820 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
841 req->mapped = 0; 821 req->mapped = 0;
842 VDBG(dev, "req->mapped = 0\n"); 822 dev_vdbg(&dev->pdev->dev, "req->mapped = 0\n");
843 } 823 }
844 824
845 DBG(dev, "%s queue req %p, len %u, buf %p, dma 0x%08llx\n", 825 dev_dbg(&dev->pdev->dev,
846 _ep->name, 826 "%s queue req %p, len %u, buf %p, dma 0x%08x\n",
847 _req, _req->length, _req->buf, (unsigned long long)_req->dma); 827 _ep->name,
828 _req, _req->length, _req->buf, (int)_req->dma);
848 829
849 _req->status = -EINPROGRESS; 830 _req->status = -EINPROGRESS;
850 _req->actual = 0; 831 _req->actual = 0;
@@ -866,12 +847,12 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
866 847
867 if (likely(req != NULL)) { 848 if (likely(req != NULL)) {
868 list_add_tail(&req->queue, &ep->queue); 849 list_add_tail(&req->queue, &ep->queue);
869 VDBG(dev, "list_add_tail() \n"); 850 dev_vdbg(&dev->pdev->dev, "list_add_tail()\n");
870 } 851 }
871 852
872 spin_unlock_irqrestore(&dev->lock, flags); 853 spin_unlock_irqrestore(&dev->lock, flags);
873 854
874 VDBG(dev, "<--- %s()\n", __func__); 855 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
875 return 0; 856 return 0;
876} 857}
877 858
@@ -888,7 +869,7 @@ static int langwell_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
888 869
889 ep = container_of(_ep, struct langwell_ep, ep); 870 ep = container_of(_ep, struct langwell_ep, ep);
890 dev = ep->dev; 871 dev = ep->dev;
891 VDBG(dev, "---> %s()\n", __func__); 872 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
892 873
893 if (!_ep || !ep->desc || !_req) 874 if (!_ep || !ep->desc || !_req)
894 return -EINVAL; 875 return -EINVAL;
@@ -924,7 +905,7 @@ static int langwell_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
924 905
925 /* queue head may be partially complete. */ 906 /* queue head may be partially complete. */
926 if (ep->queue.next == &req->queue) { 907 if (ep->queue.next == &req->queue) {
927 DBG(dev, "unlink (%s) dma\n", _ep->name); 908 dev_dbg(&dev->pdev->dev, "unlink (%s) dma\n", _ep->name);
928 _req->status = -ECONNRESET; 909 _req->status = -ECONNRESET;
929 langwell_ep_fifo_flush(&ep->ep); 910 langwell_ep_fifo_flush(&ep->ep);
930 911
@@ -963,7 +944,7 @@ done:
963 ep->stopped = stopped; 944 ep->stopped = stopped;
964 spin_unlock_irqrestore(&dev->lock, flags); 945 spin_unlock_irqrestore(&dev->lock, flags);
965 946
966 VDBG(dev, "<--- %s()\n", __func__); 947 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
967 return retval; 948 return retval;
968} 949}
969 950
@@ -976,7 +957,7 @@ static void ep_set_halt(struct langwell_ep *ep, int value)
976 u32 endptctrl = 0; 957 u32 endptctrl = 0;
977 int ep_num; 958 int ep_num;
978 struct langwell_udc *dev = ep->dev; 959 struct langwell_udc *dev = ep->dev;
979 VDBG(dev, "---> %s()\n", __func__); 960 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
980 961
981 ep_num = ep->ep_num; 962 ep_num = ep->ep_num;
982 endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); 963 endptctrl = readl(&dev->op_regs->endptctrl[ep_num]);
@@ -1001,7 +982,7 @@ static void ep_set_halt(struct langwell_ep *ep, int value)
1001 982
1002 writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); 983 writel(endptctrl, &dev->op_regs->endptctrl[ep_num]);
1003 984
1004 VDBG(dev, "<--- %s()\n", __func__); 985 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1005} 986}
1006 987
1007 988
@@ -1016,7 +997,7 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value)
1016 ep = container_of(_ep, struct langwell_ep, ep); 997 ep = container_of(_ep, struct langwell_ep, ep);
1017 dev = ep->dev; 998 dev = ep->dev;
1018 999
1019 VDBG(dev, "---> %s()\n", __func__); 1000 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1020 1001
1021 if (!_ep || !ep->desc) 1002 if (!_ep || !ep->desc)
1022 return -EINVAL; 1003 return -EINVAL;
@@ -1024,8 +1005,7 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value)
1024 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) 1005 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
1025 return -ESHUTDOWN; 1006 return -ESHUTDOWN;
1026 1007
1027 if (ep->desc && (ep->desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) 1008 if (usb_endpoint_xfer_isoc(ep->desc))
1028 == USB_ENDPOINT_XFER_ISOC)
1029 return -EOPNOTSUPP; 1009 return -EOPNOTSUPP;
1030 1010
1031 spin_lock_irqsave(&dev->lock, flags); 1011 spin_lock_irqsave(&dev->lock, flags);
@@ -1036,7 +1016,7 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value)
1036 */ 1016 */
1037 if (!list_empty(&ep->queue) && is_in(ep) && value) { 1017 if (!list_empty(&ep->queue) && is_in(ep) && value) {
1038 /* IN endpoint FIFO holds bytes */ 1018 /* IN endpoint FIFO holds bytes */
1039 DBG(dev, "%s FIFO holds bytes\n", _ep->name); 1019 dev_dbg(&dev->pdev->dev, "%s FIFO holds bytes\n", _ep->name);
1040 retval = -EAGAIN; 1020 retval = -EAGAIN;
1041 goto done; 1021 goto done;
1042 } 1022 }
@@ -1050,8 +1030,9 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value)
1050 } 1030 }
1051done: 1031done:
1052 spin_unlock_irqrestore(&dev->lock, flags); 1032 spin_unlock_irqrestore(&dev->lock, flags);
1053 DBG(dev, "%s %s halt\n", _ep->name, value ? "set" : "clear"); 1033 dev_dbg(&dev->pdev->dev, "%s %s halt\n",
1054 VDBG(dev, "<--- %s()\n", __func__); 1034 _ep->name, value ? "set" : "clear");
1035 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1055 return retval; 1036 return retval;
1056} 1037}
1057 1038
@@ -1065,12 +1046,12 @@ static int langwell_ep_set_wedge(struct usb_ep *_ep)
1065 ep = container_of(_ep, struct langwell_ep, ep); 1046 ep = container_of(_ep, struct langwell_ep, ep);
1066 dev = ep->dev; 1047 dev = ep->dev;
1067 1048
1068 VDBG(dev, "---> %s()\n", __func__); 1049 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1069 1050
1070 if (!_ep || !ep->desc) 1051 if (!_ep || !ep->desc)
1071 return -EINVAL; 1052 return -EINVAL;
1072 1053
1073 VDBG(dev, "<--- %s()\n", __func__); 1054 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1074 return usb_ep_set_halt(_ep); 1055 return usb_ep_set_halt(_ep);
1075} 1056}
1076 1057
@@ -1086,15 +1067,16 @@ static void langwell_ep_fifo_flush(struct usb_ep *_ep)
1086 ep = container_of(_ep, struct langwell_ep, ep); 1067 ep = container_of(_ep, struct langwell_ep, ep);
1087 dev = ep->dev; 1068 dev = ep->dev;
1088 1069
1089 VDBG(dev, "---> %s()\n", __func__); 1070 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1090 1071
1091 if (!_ep || !ep->desc) { 1072 if (!_ep || !ep->desc) {
1092 VDBG(dev, "ep or ep->desc is NULL\n"); 1073 dev_vdbg(&dev->pdev->dev, "ep or ep->desc is NULL\n");
1093 VDBG(dev, "<--- %s()\n", __func__); 1074 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1094 return; 1075 return;
1095 } 1076 }
1096 1077
1097 VDBG(dev, "%s-%s fifo flush\n", _ep->name, is_in(ep) ? "in" : "out"); 1078 dev_vdbg(&dev->pdev->dev, "%s-%s fifo flush\n",
1079 _ep->name, DIR_STRING(ep));
1098 1080
1099 /* flush endpoint buffer */ 1081 /* flush endpoint buffer */
1100 if (ep->ep_num == 0) 1082 if (ep->ep_num == 0)
@@ -1110,14 +1092,14 @@ static void langwell_ep_fifo_flush(struct usb_ep *_ep)
1110 writel(flush_bit, &dev->op_regs->endptflush); 1092 writel(flush_bit, &dev->op_regs->endptflush);
1111 while (readl(&dev->op_regs->endptflush)) { 1093 while (readl(&dev->op_regs->endptflush)) {
1112 if (time_after(jiffies, timeout)) { 1094 if (time_after(jiffies, timeout)) {
1113 ERROR(dev, "ep flush timeout\n"); 1095 dev_err(&dev->pdev->dev, "ep flush timeout\n");
1114 goto done; 1096 goto done;
1115 } 1097 }
1116 cpu_relax(); 1098 cpu_relax();
1117 } 1099 }
1118 } while (readl(&dev->op_regs->endptstat) & flush_bit); 1100 } while (readl(&dev->op_regs->endptstat) & flush_bit);
1119done: 1101done:
1120 VDBG(dev, "<--- %s()\n", __func__); 1102 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1121} 1103}
1122 1104
1123 1105
@@ -1167,31 +1149,59 @@ static int langwell_get_frame(struct usb_gadget *_gadget)
1167 return -ENODEV; 1149 return -ENODEV;
1168 1150
1169 dev = container_of(_gadget, struct langwell_udc, gadget); 1151 dev = container_of(_gadget, struct langwell_udc, gadget);
1170 VDBG(dev, "---> %s()\n", __func__); 1152 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1171 1153
1172 retval = readl(&dev->op_regs->frindex) & FRINDEX_MASK; 1154 retval = readl(&dev->op_regs->frindex) & FRINDEX_MASK;
1173 1155
1174 VDBG(dev, "<--- %s()\n", __func__); 1156 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1175 return retval; 1157 return retval;
1176} 1158}
1177 1159
1178 1160
1161/* enter or exit PHY low power state */
1162static void langwell_phy_low_power(struct langwell_udc *dev, bool flag)
1163{
1164 u32 devlc;
1165 u8 devlc_byte2;
1166 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1167
1168 devlc = readl(&dev->op_regs->devlc);
1169 dev_vdbg(&dev->pdev->dev, "devlc = 0x%08x\n", devlc);
1170
1171 if (flag)
1172 devlc |= LPM_PHCD;
1173 else
1174 devlc &= ~LPM_PHCD;
1175
1176 /* FIXME: workaround for Langwell A1/A2/A3 sighting */
1177 devlc_byte2 = (devlc >> 16) & 0xff;
1178 writeb(devlc_byte2, (u8 *)&dev->op_regs->devlc + 2);
1179
1180 devlc = readl(&dev->op_regs->devlc);
1181 dev_vdbg(&dev->pdev->dev,
1182 "%s PHY low power suspend, devlc = 0x%08x\n",
1183 flag ? "enter" : "exit", devlc);
1184}
1185
1186
1179/* tries to wake up the host connected to this gadget */ 1187/* tries to wake up the host connected to this gadget */
1180static int langwell_wakeup(struct usb_gadget *_gadget) 1188static int langwell_wakeup(struct usb_gadget *_gadget)
1181{ 1189{
1182 struct langwell_udc *dev; 1190 struct langwell_udc *dev;
1183 u32 portsc1, devlc; 1191 u32 portsc1;
1184 unsigned long flags; 1192 unsigned long flags;
1185 1193
1186 if (!_gadget) 1194 if (!_gadget)
1187 return 0; 1195 return 0;
1188 1196
1189 dev = container_of(_gadget, struct langwell_udc, gadget); 1197 dev = container_of(_gadget, struct langwell_udc, gadget);
1190 VDBG(dev, "---> %s()\n", __func__); 1198 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1191 1199
1192 /* Remote Wakeup feature not enabled by host */ 1200 /* remote wakeup feature not enabled by host */
1193 if (!dev->remote_wakeup) 1201 if (!dev->remote_wakeup) {
1202 dev_info(&dev->pdev->dev, "remote wakeup is disabled\n");
1194 return -ENOTSUPP; 1203 return -ENOTSUPP;
1204 }
1195 1205
1196 spin_lock_irqsave(&dev->lock, flags); 1206 spin_lock_irqsave(&dev->lock, flags);
1197 1207
@@ -1201,27 +1211,23 @@ static int langwell_wakeup(struct usb_gadget *_gadget)
1201 return 0; 1211 return 0;
1202 } 1212 }
1203 1213
1204 /* LPM L1 to L0, remote wakeup */ 1214 /* LPM L1 to L0 or legacy remote wakeup */
1205 if (dev->lpm && dev->lpm_state == LPM_L1) { 1215 if (dev->lpm && dev->lpm_state == LPM_L1)
1206 portsc1 |= PORTS_SLP; 1216 dev_info(&dev->pdev->dev, "LPM L1 to L0 remote wakeup\n");
1207 writel(portsc1, &dev->op_regs->portsc1); 1217 else
1208 } 1218 dev_info(&dev->pdev->dev, "device remote wakeup\n");
1209
1210 /* force port resume */
1211 if (dev->usb_state == USB_STATE_SUSPENDED) {
1212 portsc1 |= PORTS_FPR;
1213 writel(portsc1, &dev->op_regs->portsc1);
1214 }
1215 1219
1216 /* exit PHY low power suspend */ 1220 /* exit PHY low power suspend */
1217 devlc = readl(&dev->op_regs->devlc); 1221 if (dev->pdev->device != 0x0829)
1218 VDBG(dev, "devlc = 0x%08x\n", devlc); 1222 langwell_phy_low_power(dev, 0);
1219 devlc &= ~LPM_PHCD; 1223
1220 writel(devlc, &dev->op_regs->devlc); 1224 /* force port resume */
1225 portsc1 |= PORTS_FPR;
1226 writel(portsc1, &dev->op_regs->portsc1);
1221 1227
1222 spin_unlock_irqrestore(&dev->lock, flags); 1228 spin_unlock_irqrestore(&dev->lock, flags);
1223 1229
1224 VDBG(dev, "<--- %s()\n", __func__); 1230 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1225 return 0; 1231 return 0;
1226} 1232}
1227 1233
@@ -1231,16 +1237,17 @@ static int langwell_vbus_session(struct usb_gadget *_gadget, int is_active)
1231{ 1237{
1232 struct langwell_udc *dev; 1238 struct langwell_udc *dev;
1233 unsigned long flags; 1239 unsigned long flags;
1234 u32 usbcmd; 1240 u32 usbcmd;
1235 1241
1236 if (!_gadget) 1242 if (!_gadget)
1237 return -ENODEV; 1243 return -ENODEV;
1238 1244
1239 dev = container_of(_gadget, struct langwell_udc, gadget); 1245 dev = container_of(_gadget, struct langwell_udc, gadget);
1240 VDBG(dev, "---> %s()\n", __func__); 1246 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1241 1247
1242 spin_lock_irqsave(&dev->lock, flags); 1248 spin_lock_irqsave(&dev->lock, flags);
1243 VDBG(dev, "VBUS status: %s\n", is_active ? "on" : "off"); 1249 dev_vdbg(&dev->pdev->dev, "VBUS status: %s\n",
1250 is_active ? "on" : "off");
1244 1251
1245 dev->vbus_active = (is_active != 0); 1252 dev->vbus_active = (is_active != 0);
1246 if (dev->driver && dev->softconnected && dev->vbus_active) { 1253 if (dev->driver && dev->softconnected && dev->vbus_active) {
@@ -1255,7 +1262,7 @@ static int langwell_vbus_session(struct usb_gadget *_gadget, int is_active)
1255 1262
1256 spin_unlock_irqrestore(&dev->lock, flags); 1263 spin_unlock_irqrestore(&dev->lock, flags);
1257 1264
1258 VDBG(dev, "<--- %s()\n", __func__); 1265 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1259 return 0; 1266 return 0;
1260} 1267}
1261 1268
@@ -1269,15 +1276,15 @@ static int langwell_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1269 return -ENODEV; 1276 return -ENODEV;
1270 1277
1271 dev = container_of(_gadget, struct langwell_udc, gadget); 1278 dev = container_of(_gadget, struct langwell_udc, gadget);
1272 VDBG(dev, "---> %s()\n", __func__); 1279 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1273 1280
1274 if (dev->transceiver) { 1281 if (dev->transceiver) {
1275 VDBG(dev, "otg_set_power\n"); 1282 dev_vdbg(&dev->pdev->dev, "otg_set_power\n");
1276 VDBG(dev, "<--- %s()\n", __func__); 1283 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1277 return otg_set_power(dev->transceiver, mA); 1284 return otg_set_power(dev->transceiver, mA);
1278 } 1285 }
1279 1286
1280 VDBG(dev, "<--- %s()\n", __func__); 1287 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1281 return -ENOTSUPP; 1288 return -ENOTSUPP;
1282} 1289}
1283 1290
@@ -1286,15 +1293,15 @@ static int langwell_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1286static int langwell_pullup(struct usb_gadget *_gadget, int is_on) 1293static int langwell_pullup(struct usb_gadget *_gadget, int is_on)
1287{ 1294{
1288 struct langwell_udc *dev; 1295 struct langwell_udc *dev;
1289 u32 usbcmd; 1296 u32 usbcmd;
1290 unsigned long flags; 1297 unsigned long flags;
1291 1298
1292 if (!_gadget) 1299 if (!_gadget)
1293 return -ENODEV; 1300 return -ENODEV;
1294 1301
1295 dev = container_of(_gadget, struct langwell_udc, gadget); 1302 dev = container_of(_gadget, struct langwell_udc, gadget);
1296 1303
1297 VDBG(dev, "---> %s()\n", __func__); 1304 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1298 1305
1299 spin_lock_irqsave(&dev->lock, flags); 1306 spin_lock_irqsave(&dev->lock, flags);
1300 dev->softconnected = (is_on != 0); 1307 dev->softconnected = (is_on != 0);
@@ -1310,7 +1317,7 @@ static int langwell_pullup(struct usb_gadget *_gadget, int is_on)
1310 } 1317 }
1311 spin_unlock_irqrestore(&dev->lock, flags); 1318 spin_unlock_irqrestore(&dev->lock, flags);
1312 1319
1313 VDBG(dev, "<--- %s()\n", __func__); 1320 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1314 return 0; 1321 return 0;
1315} 1322}
1316 1323
@@ -1346,12 +1353,13 @@ static const struct usb_gadget_ops langwell_ops = {
1346static int langwell_udc_reset(struct langwell_udc *dev) 1353static int langwell_udc_reset(struct langwell_udc *dev)
1347{ 1354{
1348 u32 usbcmd, usbmode, devlc, endpointlistaddr; 1355 u32 usbcmd, usbmode, devlc, endpointlistaddr;
1356 u8 devlc_byte0, devlc_byte2;
1349 unsigned long timeout; 1357 unsigned long timeout;
1350 1358
1351 if (!dev) 1359 if (!dev)
1352 return -EINVAL; 1360 return -EINVAL;
1353 1361
1354 DBG(dev, "---> %s()\n", __func__); 1362 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1355 1363
1356 /* set controller to stop state */ 1364 /* set controller to stop state */
1357 usbcmd = readl(&dev->op_regs->usbcmd); 1365 usbcmd = readl(&dev->op_regs->usbcmd);
@@ -1367,7 +1375,7 @@ static int langwell_udc_reset(struct langwell_udc *dev)
1367 timeout = jiffies + RESET_TIMEOUT; 1375 timeout = jiffies + RESET_TIMEOUT;
1368 while (readl(&dev->op_regs->usbcmd) & CMD_RST) { 1376 while (readl(&dev->op_regs->usbcmd) & CMD_RST) {
1369 if (time_after(jiffies, timeout)) { 1377 if (time_after(jiffies, timeout)) {
1370 ERROR(dev, "device reset timeout\n"); 1378 dev_err(&dev->pdev->dev, "device reset timeout\n");
1371 return -ETIMEDOUT; 1379 return -ETIMEDOUT;
1372 } 1380 }
1373 cpu_relax(); 1381 cpu_relax();
@@ -1382,7 +1390,7 @@ static int langwell_udc_reset(struct langwell_udc *dev)
1382 1390
1383 writel(usbmode, &dev->op_regs->usbmode); 1391 writel(usbmode, &dev->op_regs->usbmode);
1384 usbmode = readl(&dev->op_regs->usbmode); 1392 usbmode = readl(&dev->op_regs->usbmode);
1385 VDBG(dev, "usbmode=0x%08x\n", usbmode); 1393 dev_vdbg(&dev->pdev->dev, "usbmode=0x%08x\n", usbmode);
1386 1394
1387 /* Write-Clear setup status */ 1395 /* Write-Clear setup status */
1388 writel(0, &dev->op_regs->usbsts); 1396 writel(0, &dev->op_regs->usbsts);
@@ -1390,9 +1398,17 @@ static int langwell_udc_reset(struct langwell_udc *dev)
1390 /* if support USB LPM, ACK all LPM token */ 1398 /* if support USB LPM, ACK all LPM token */
1391 if (dev->lpm) { 1399 if (dev->lpm) {
1392 devlc = readl(&dev->op_regs->devlc); 1400 devlc = readl(&dev->op_regs->devlc);
1401 dev_vdbg(&dev->pdev->dev, "devlc = 0x%08x\n", devlc);
1402 /* FIXME: workaround for Langwell A1/A2/A3 sighting */
1393 devlc &= ~LPM_STL; /* don't STALL LPM token */ 1403 devlc &= ~LPM_STL; /* don't STALL LPM token */
1394 devlc &= ~LPM_NYT_ACK; /* ACK LPM token */ 1404 devlc &= ~LPM_NYT_ACK; /* ACK LPM token */
1395 writel(devlc, &dev->op_regs->devlc); 1405 devlc_byte0 = devlc & 0xff;
1406 devlc_byte2 = (devlc >> 16) & 0xff;
1407 writeb(devlc_byte0, (u8 *)&dev->op_regs->devlc);
1408 writeb(devlc_byte2, (u8 *)&dev->op_regs->devlc + 2);
1409 devlc = readl(&dev->op_regs->devlc);
1410 dev_vdbg(&dev->pdev->dev,
1411 "ACK LPM token, devlc = 0x%08x\n", devlc);
1396 } 1412 }
1397 1413
1398 /* fill endpointlistaddr register */ 1414 /* fill endpointlistaddr register */
@@ -1400,10 +1416,11 @@ static int langwell_udc_reset(struct langwell_udc *dev)
1400 endpointlistaddr &= ENDPOINTLISTADDR_MASK; 1416 endpointlistaddr &= ENDPOINTLISTADDR_MASK;
1401 writel(endpointlistaddr, &dev->op_regs->endpointlistaddr); 1417 writel(endpointlistaddr, &dev->op_regs->endpointlistaddr);
1402 1418
1403 VDBG(dev, "dQH base (vir: %p, phy: 0x%08x), endpointlistaddr=0x%08x\n", 1419 dev_vdbg(&dev->pdev->dev,
1404 dev->ep_dqh, endpointlistaddr, 1420 "dQH base (vir: %p, phy: 0x%08x), endpointlistaddr=0x%08x\n",
1405 readl(&dev->op_regs->endpointlistaddr)); 1421 dev->ep_dqh, endpointlistaddr,
1406 DBG(dev, "<--- %s()\n", __func__); 1422 readl(&dev->op_regs->endpointlistaddr));
1423 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1407 return 0; 1424 return 0;
1408} 1425}
1409 1426
@@ -1415,7 +1432,7 @@ static int eps_reinit(struct langwell_udc *dev)
1415 char name[14]; 1432 char name[14];
1416 int i; 1433 int i;
1417 1434
1418 VDBG(dev, "---> %s()\n", __func__); 1435 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1419 1436
1420 /* initialize ep0 */ 1437 /* initialize ep0 */
1421 ep = &dev->ep[0]; 1438 ep = &dev->ep[0];
@@ -1449,11 +1466,9 @@ static int eps_reinit(struct langwell_udc *dev)
1449 1466
1450 INIT_LIST_HEAD(&ep->queue); 1467 INIT_LIST_HEAD(&ep->queue);
1451 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); 1468 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
1452
1453 ep->dqh = &dev->ep_dqh[i];
1454 } 1469 }
1455 1470
1456 VDBG(dev, "<--- %s()\n", __func__); 1471 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1457 return 0; 1472 return 0;
1458} 1473}
1459 1474
@@ -1462,7 +1477,7 @@ static int eps_reinit(struct langwell_udc *dev)
1462static void langwell_udc_start(struct langwell_udc *dev) 1477static void langwell_udc_start(struct langwell_udc *dev)
1463{ 1478{
1464 u32 usbintr, usbcmd; 1479 u32 usbintr, usbcmd;
1465 DBG(dev, "---> %s()\n", __func__); 1480 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1466 1481
1467 /* enable interrupts */ 1482 /* enable interrupts */
1468 usbintr = INTR_ULPIE /* ULPI */ 1483 usbintr = INTR_ULPIE /* ULPI */
@@ -1485,8 +1500,7 @@ static void langwell_udc_start(struct langwell_udc *dev)
1485 usbcmd |= CMD_RUNSTOP; 1500 usbcmd |= CMD_RUNSTOP;
1486 writel(usbcmd, &dev->op_regs->usbcmd); 1501 writel(usbcmd, &dev->op_regs->usbcmd);
1487 1502
1488 DBG(dev, "<--- %s()\n", __func__); 1503 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1489 return;
1490} 1504}
1491 1505
1492 1506
@@ -1495,7 +1509,7 @@ static void langwell_udc_stop(struct langwell_udc *dev)
1495{ 1509{
1496 u32 usbcmd; 1510 u32 usbcmd;
1497 1511
1498 DBG(dev, "---> %s()\n", __func__); 1512 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1499 1513
1500 /* disable all interrupts */ 1514 /* disable all interrupts */
1501 writel(0, &dev->op_regs->usbintr); 1515 writel(0, &dev->op_regs->usbintr);
@@ -1508,8 +1522,7 @@ static void langwell_udc_stop(struct langwell_udc *dev)
1508 usbcmd &= ~CMD_RUNSTOP; 1522 usbcmd &= ~CMD_RUNSTOP;
1509 writel(usbcmd, &dev->op_regs->usbcmd); 1523 writel(usbcmd, &dev->op_regs->usbcmd);
1510 1524
1511 DBG(dev, "<--- %s()\n", __func__); 1525 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1512 return;
1513} 1526}
1514 1527
1515 1528
@@ -1518,7 +1531,7 @@ static void stop_activity(struct langwell_udc *dev,
1518 struct usb_gadget_driver *driver) 1531 struct usb_gadget_driver *driver)
1519{ 1532{
1520 struct langwell_ep *ep; 1533 struct langwell_ep *ep;
1521 DBG(dev, "---> %s()\n", __func__); 1534 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1522 1535
1523 nuke(&dev->ep[0], -ESHUTDOWN); 1536 nuke(&dev->ep[0], -ESHUTDOWN);
1524 1537
@@ -1533,7 +1546,7 @@ static void stop_activity(struct langwell_udc *dev,
1533 spin_lock(&dev->lock); 1546 spin_lock(&dev->lock);
1534 } 1547 }
1535 1548
1536 DBG(dev, "<--- %s()\n", __func__); 1549 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1537} 1550}
1538 1551
1539 1552
@@ -1659,13 +1672,15 @@ static ssize_t show_langwell_udc(struct device *_dev,
1659 "Over-current Change: %s\n" 1672 "Over-current Change: %s\n"
1660 "Port Enable/Disable Change: %s\n" 1673 "Port Enable/Disable Change: %s\n"
1661 "Port Enabled/Disabled: %s\n" 1674 "Port Enabled/Disabled: %s\n"
1662 "Current Connect Status: %s\n\n", 1675 "Current Connect Status: %s\n"
1676 "LPM Suspend Status: %s\n\n",
1663 (tmp_reg & PORTS_PR) ? "Reset" : "Not Reset", 1677 (tmp_reg & PORTS_PR) ? "Reset" : "Not Reset",
1664 (tmp_reg & PORTS_SUSP) ? "Suspend " : "Not Suspend", 1678 (tmp_reg & PORTS_SUSP) ? "Suspend " : "Not Suspend",
1665 (tmp_reg & PORTS_OCC) ? "Detected" : "No", 1679 (tmp_reg & PORTS_OCC) ? "Detected" : "No",
1666 (tmp_reg & PORTS_PEC) ? "Changed" : "Not Changed", 1680 (tmp_reg & PORTS_PEC) ? "Changed" : "Not Changed",
1667 (tmp_reg & PORTS_PE) ? "Enable" : "Not Correct", 1681 (tmp_reg & PORTS_PE) ? "Enable" : "Not Correct",
1668 (tmp_reg & PORTS_CCS) ? "Attached" : "Not Attached"); 1682 (tmp_reg & PORTS_CCS) ? "Attached" : "Not Attached",
1683 (tmp_reg & PORTS_SLP) ? "LPM L1" : "LPM L0");
1669 size -= t; 1684 size -= t;
1670 next += t; 1685 next += t;
1671 1686
@@ -1676,7 +1691,7 @@ static ssize_t show_langwell_udc(struct device *_dev,
1676 "Serial Transceiver : %d\n" 1691 "Serial Transceiver : %d\n"
1677 "Port Speed: %s\n" 1692 "Port Speed: %s\n"
1678 "Port Force Full Speed Connenct: %s\n" 1693 "Port Force Full Speed Connenct: %s\n"
1679 "PHY Low Power Suspend Clock Disable: %s\n" 1694 "PHY Low Power Suspend Clock: %s\n"
1680 "BmAttributes: %d\n\n", 1695 "BmAttributes: %d\n\n",
1681 LPM_PTS(tmp_reg), 1696 LPM_PTS(tmp_reg),
1682 (tmp_reg & LPM_STS) ? 1 : 0, 1697 (tmp_reg & LPM_STS) ? 1 : 0,
@@ -1797,6 +1812,36 @@ static ssize_t show_langwell_udc(struct device *_dev,
1797static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL); 1812static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL);
1798 1813
1799 1814
1815/* device "remote_wakeup" sysfs attribute file */
1816static ssize_t store_remote_wakeup(struct device *_dev,
1817 struct device_attribute *attr, const char *buf, size_t count)
1818{
1819 struct langwell_udc *dev = the_controller;
1820 unsigned long flags;
1821 ssize_t rc = count;
1822
1823 if (count > 2)
1824 return -EINVAL;
1825
1826 if (count > 0 && buf[count-1] == '\n')
1827 ((char *) buf)[count-1] = 0;
1828
1829 if (buf[0] != '1')
1830 return -EINVAL;
1831
1832 /* force remote wakeup enabled in case gadget driver doesn't support */
1833 spin_lock_irqsave(&dev->lock, flags);
1834 dev->remote_wakeup = 1;
1835 dev->dev_status |= (1 << USB_DEVICE_REMOTE_WAKEUP);
1836 spin_unlock_irqrestore(&dev->lock, flags);
1837
1838 langwell_wakeup(&dev->gadget);
1839
1840 return rc;
1841}
1842static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup);
1843
1844
1800/*-------------------------------------------------------------------------*/ 1845/*-------------------------------------------------------------------------*/
1801 1846
1802/* 1847/*
@@ -1807,7 +1852,8 @@ static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL);
1807 * the driver might get unbound. 1852 * the driver might get unbound.
1808 */ 1853 */
1809 1854
1810int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1855int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1856 int (*bind)(struct usb_gadget *))
1811{ 1857{
1812 struct langwell_udc *dev = the_controller; 1858 struct langwell_udc *dev = the_controller;
1813 unsigned long flags; 1859 unsigned long flags;
@@ -1816,7 +1862,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1816 if (!dev) 1862 if (!dev)
1817 return -ENODEV; 1863 return -ENODEV;
1818 1864
1819 DBG(dev, "---> %s()\n", __func__); 1865 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1820 1866
1821 if (dev->driver) 1867 if (dev->driver)
1822 return -EBUSY; 1868 return -EBUSY;
@@ -1830,9 +1876,9 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1830 1876
1831 spin_unlock_irqrestore(&dev->lock, flags); 1877 spin_unlock_irqrestore(&dev->lock, flags);
1832 1878
1833 retval = driver->bind(&dev->gadget); 1879 retval = bind(&dev->gadget);
1834 if (retval) { 1880 if (retval) {
1835 DBG(dev, "bind to driver %s --> %d\n", 1881 dev_dbg(&dev->pdev->dev, "bind to driver %s --> %d\n",
1836 driver->driver.name, retval); 1882 driver->driver.name, retval);
1837 dev->driver = NULL; 1883 dev->driver = NULL;
1838 dev->gadget.dev.driver = NULL; 1884 dev->gadget.dev.driver = NULL;
@@ -1851,13 +1897,13 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1851 if (dev->got_irq) 1897 if (dev->got_irq)
1852 langwell_udc_start(dev); 1898 langwell_udc_start(dev);
1853 1899
1854 VDBG(dev, "After langwell_udc_start(), print all registers:\n"); 1900 dev_vdbg(&dev->pdev->dev,
1855#ifdef VERBOSE 1901 "After langwell_udc_start(), print all registers:\n");
1856 print_all_registers(dev); 1902 print_all_registers(dev);
1857#endif
1858 1903
1859 INFO(dev, "register driver: %s\n", driver->driver.name); 1904 dev_info(&dev->pdev->dev, "register driver: %s\n",
1860 VDBG(dev, "<--- %s()\n", __func__); 1905 driver->driver.name);
1906 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1861 return 0; 1907 return 0;
1862 1908
1863err_unbind: 1909err_unbind:
@@ -1865,10 +1911,10 @@ err_unbind:
1865 dev->gadget.dev.driver = NULL; 1911 dev->gadget.dev.driver = NULL;
1866 dev->driver = NULL; 1912 dev->driver = NULL;
1867 1913
1868 DBG(dev, "<--- %s()\n", __func__); 1914 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1869 return retval; 1915 return retval;
1870} 1916}
1871EXPORT_SYMBOL(usb_gadget_register_driver); 1917EXPORT_SYMBOL(usb_gadget_probe_driver);
1872 1918
1873 1919
1874/* unregister gadget driver */ 1920/* unregister gadget driver */
@@ -1880,11 +1926,15 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1880 if (!dev) 1926 if (!dev)
1881 return -ENODEV; 1927 return -ENODEV;
1882 1928
1883 DBG(dev, "---> %s()\n", __func__); 1929 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1884 1930
1885 if (unlikely(!driver || !driver->bind || !driver->unbind)) 1931 if (unlikely(!driver || !driver->unbind))
1886 return -EINVAL; 1932 return -EINVAL;
1887 1933
1934 /* exit PHY low power suspend */
1935 if (dev->pdev->device != 0x0829)
1936 langwell_phy_low_power(dev, 0);
1937
1888 /* unbind OTG transceiver */ 1938 /* unbind OTG transceiver */
1889 if (dev->transceiver) 1939 if (dev->transceiver)
1890 (void)otg_set_peripheral(dev->transceiver, 0); 1940 (void)otg_set_peripheral(dev->transceiver, 0);
@@ -1910,8 +1960,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1910 1960
1911 device_remove_file(&dev->pdev->dev, &dev_attr_function); 1961 device_remove_file(&dev->pdev->dev, &dev_attr_function);
1912 1962
1913 INFO(dev, "unregistered driver '%s'\n", driver->driver.name); 1963 dev_info(&dev->pdev->dev, "unregistered driver '%s'\n",
1914 DBG(dev, "<--- %s()\n", __func__); 1964 driver->driver.name);
1965 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1915 return 0; 1966 return 0;
1916} 1967}
1917EXPORT_SYMBOL(usb_gadget_unregister_driver); 1968EXPORT_SYMBOL(usb_gadget_unregister_driver);
@@ -1930,7 +1981,7 @@ static void setup_tripwire(struct langwell_udc *dev)
1930 unsigned long timeout; 1981 unsigned long timeout;
1931 struct langwell_dqh *dqh; 1982 struct langwell_dqh *dqh;
1932 1983
1933 VDBG(dev, "---> %s()\n", __func__); 1984 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1934 1985
1935 /* ep0 OUT dQH */ 1986 /* ep0 OUT dQH */
1936 dqh = &dev->ep_dqh[EP_DIR_OUT]; 1987 dqh = &dev->ep_dqh[EP_DIR_OUT];
@@ -1943,7 +1994,7 @@ static void setup_tripwire(struct langwell_udc *dev)
1943 timeout = jiffies + SETUPSTAT_TIMEOUT; 1994 timeout = jiffies + SETUPSTAT_TIMEOUT;
1944 while (readl(&dev->op_regs->endptsetupstat)) { 1995 while (readl(&dev->op_regs->endptsetupstat)) {
1945 if (time_after(jiffies, timeout)) { 1996 if (time_after(jiffies, timeout)) {
1946 ERROR(dev, "setup_tripwire timeout\n"); 1997 dev_err(&dev->pdev->dev, "setup_tripwire timeout\n");
1947 break; 1998 break;
1948 } 1999 }
1949 cpu_relax(); 2000 cpu_relax();
@@ -1963,7 +2014,7 @@ static void setup_tripwire(struct langwell_udc *dev)
1963 usbcmd = readl(&dev->op_regs->usbcmd); 2014 usbcmd = readl(&dev->op_regs->usbcmd);
1964 writel(usbcmd & ~CMD_SUTW, &dev->op_regs->usbcmd); 2015 writel(usbcmd & ~CMD_SUTW, &dev->op_regs->usbcmd);
1965 2016
1966 VDBG(dev, "<--- %s()\n", __func__); 2017 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1967} 2018}
1968 2019
1969 2020
@@ -1972,7 +2023,7 @@ static void ep0_stall(struct langwell_udc *dev)
1972{ 2023{
1973 u32 endptctrl; 2024 u32 endptctrl;
1974 2025
1975 VDBG(dev, "---> %s()\n", __func__); 2026 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1976 2027
1977 /* set TX and RX to stall */ 2028 /* set TX and RX to stall */
1978 endptctrl = readl(&dev->op_regs->endptctrl[0]); 2029 endptctrl = readl(&dev->op_regs->endptctrl[0]);
@@ -1983,7 +2034,7 @@ static void ep0_stall(struct langwell_udc *dev)
1983 dev->ep0_state = WAIT_FOR_SETUP; 2034 dev->ep0_state = WAIT_FOR_SETUP;
1984 dev->ep0_dir = USB_DIR_OUT; 2035 dev->ep0_dir = USB_DIR_OUT;
1985 2036
1986 VDBG(dev, "<--- %s()\n", __func__); 2037 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1987} 2038}
1988 2039
1989 2040
@@ -1994,7 +2045,7 @@ static int prime_status_phase(struct langwell_udc *dev, int dir)
1994 struct langwell_ep *ep; 2045 struct langwell_ep *ep;
1995 int status = 0; 2046 int status = 0;
1996 2047
1997 VDBG(dev, "---> %s()\n", __func__); 2048 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1998 2049
1999 if (dir == EP_DIR_IN) 2050 if (dir == EP_DIR_IN)
2000 dev->ep0_dir = USB_DIR_IN; 2051 dev->ep0_dir = USB_DIR_IN;
@@ -2019,11 +2070,11 @@ static int prime_status_phase(struct langwell_udc *dev, int dir)
2019 return -ENOMEM; 2070 return -ENOMEM;
2020 2071
2021 if (status) 2072 if (status)
2022 ERROR(dev, "can't queue ep0 status request\n"); 2073 dev_err(&dev->pdev->dev, "can't queue ep0 status request\n");
2023 2074
2024 list_add_tail(&req->queue, &ep->queue); 2075 list_add_tail(&req->queue, &ep->queue);
2025 2076
2026 VDBG(dev, "<--- %s()\n", __func__); 2077 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2027 return status; 2078 return status;
2028} 2079}
2029 2080
@@ -2032,11 +2083,11 @@ static int prime_status_phase(struct langwell_udc *dev, int dir)
2032static void set_address(struct langwell_udc *dev, u16 value, 2083static void set_address(struct langwell_udc *dev, u16 value,
2033 u16 index, u16 length) 2084 u16 index, u16 length)
2034{ 2085{
2035 VDBG(dev, "---> %s()\n", __func__); 2086 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2036 2087
2037 /* save the new address to device struct */ 2088 /* save the new address to device struct */
2038 dev->dev_addr = (u8) value; 2089 dev->dev_addr = (u8) value;
2039 VDBG(dev, "dev->dev_addr = %d\n", dev->dev_addr); 2090 dev_vdbg(&dev->pdev->dev, "dev->dev_addr = %d\n", dev->dev_addr);
2040 2091
2041 /* update usb state */ 2092 /* update usb state */
2042 dev->usb_state = USB_STATE_ADDRESS; 2093 dev->usb_state = USB_STATE_ADDRESS;
@@ -2045,7 +2096,7 @@ static void set_address(struct langwell_udc *dev, u16 value,
2045 if (prime_status_phase(dev, EP_DIR_IN)) 2096 if (prime_status_phase(dev, EP_DIR_IN))
2046 ep0_stall(dev); 2097 ep0_stall(dev);
2047 2098
2048 VDBG(dev, "<--- %s()\n", __func__); 2099 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2049} 2100}
2050 2101
2051 2102
@@ -2054,7 +2105,7 @@ static struct langwell_ep *get_ep_by_windex(struct langwell_udc *dev,
2054 u16 wIndex) 2105 u16 wIndex)
2055{ 2106{
2056 struct langwell_ep *ep; 2107 struct langwell_ep *ep;
2057 VDBG(dev, "---> %s()\n", __func__); 2108 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2058 2109
2059 if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0) 2110 if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
2060 return &dev->ep[0]; 2111 return &dev->ep[0];
@@ -2073,7 +2124,7 @@ static struct langwell_ep *get_ep_by_windex(struct langwell_udc *dev,
2073 return ep; 2124 return ep;
2074 } 2125 }
2075 2126
2076 VDBG(dev, "<--- %s()\n", __func__); 2127 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2077 return NULL; 2128 return NULL;
2078} 2129}
2079 2130
@@ -2085,7 +2136,7 @@ static int ep_is_stall(struct langwell_ep *ep)
2085 u32 endptctrl; 2136 u32 endptctrl;
2086 int retval; 2137 int retval;
2087 2138
2088 VDBG(dev, "---> %s()\n", __func__); 2139 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2089 2140
2090 endptctrl = readl(&dev->op_regs->endptctrl[ep->ep_num]); 2141 endptctrl = readl(&dev->op_regs->endptctrl[ep->ep_num]);
2091 if (is_in(ep)) 2142 if (is_in(ep))
@@ -2093,7 +2144,7 @@ static int ep_is_stall(struct langwell_ep *ep)
2093 else 2144 else
2094 retval = endptctrl & EPCTRL_RXS ? 1 : 0; 2145 retval = endptctrl & EPCTRL_RXS ? 1 : 0;
2095 2146
2096 VDBG(dev, "<--- %s()\n", __func__); 2147 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2097 return retval; 2148 return retval;
2098} 2149}
2099 2150
@@ -2107,14 +2158,13 @@ static void get_status(struct langwell_udc *dev, u8 request_type, u16 value,
2107 u16 status_data = 0; /* 16 bits cpu view status data */ 2158 u16 status_data = 0; /* 16 bits cpu view status data */
2108 int status = 0; 2159 int status = 0;
2109 2160
2110 VDBG(dev, "---> %s()\n", __func__); 2161 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2111 2162
2112 ep = &dev->ep[0]; 2163 ep = &dev->ep[0];
2113 2164
2114 if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) { 2165 if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) {
2115 /* get device status */ 2166 /* get device status */
2116 status_data = 1 << USB_DEVICE_SELF_POWERED; 2167 status_data = dev->dev_status;
2117 status_data |= dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP;
2118 } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) { 2168 } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) {
2119 /* get interface status */ 2169 /* get interface status */
2120 status_data = 0; 2170 status_data = 0;
@@ -2129,6 +2179,8 @@ static void get_status(struct langwell_udc *dev, u8 request_type, u16 value,
2129 status_data = ep_is_stall(epn) << USB_ENDPOINT_HALT; 2179 status_data = ep_is_stall(epn) << USB_ENDPOINT_HALT;
2130 } 2180 }
2131 2181
2182 dev_dbg(&dev->pdev->dev, "get status data: 0x%04x\n", status_data);
2183
2132 dev->ep0_dir = USB_DIR_IN; 2184 dev->ep0_dir = USB_DIR_IN;
2133 2185
2134 /* borrow the per device status_req */ 2186 /* borrow the per device status_req */
@@ -2150,18 +2202,19 @@ static void get_status(struct langwell_udc *dev, u8 request_type, u16 value,
2150 goto stall; 2202 goto stall;
2151 2203
2152 if (status) { 2204 if (status) {
2153 ERROR(dev, "response error on GET_STATUS request\n"); 2205 dev_err(&dev->pdev->dev,
2206 "response error on GET_STATUS request\n");
2154 goto stall; 2207 goto stall;
2155 } 2208 }
2156 2209
2157 list_add_tail(&req->queue, &ep->queue); 2210 list_add_tail(&req->queue, &ep->queue);
2158 dev->ep0_state = DATA_STATE_XMIT; 2211 dev->ep0_state = DATA_STATE_XMIT;
2159 2212
2160 VDBG(dev, "<--- %s()\n", __func__); 2213 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2161 return; 2214 return;
2162stall: 2215stall:
2163 ep0_stall(dev); 2216 ep0_stall(dev);
2164 VDBG(dev, "<--- %s()\n", __func__); 2217 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2165} 2218}
2166 2219
2167 2220
@@ -2172,13 +2225,14 @@ static void handle_setup_packet(struct langwell_udc *dev,
2172 u16 wValue = le16_to_cpu(setup->wValue); 2225 u16 wValue = le16_to_cpu(setup->wValue);
2173 u16 wIndex = le16_to_cpu(setup->wIndex); 2226 u16 wIndex = le16_to_cpu(setup->wIndex);
2174 u16 wLength = le16_to_cpu(setup->wLength); 2227 u16 wLength = le16_to_cpu(setup->wLength);
2228 u32 portsc1;
2175 2229
2176 VDBG(dev, "---> %s()\n", __func__); 2230 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2177 2231
2178 /* ep0 fifo flush */ 2232 /* ep0 fifo flush */
2179 nuke(&dev->ep[0], -ESHUTDOWN); 2233 nuke(&dev->ep[0], -ESHUTDOWN);
2180 2234
2181 DBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n", 2235 dev_dbg(&dev->pdev->dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
2182 setup->bRequestType, setup->bRequest, 2236 setup->bRequestType, setup->bRequest,
2183 wValue, wIndex, wLength); 2237 wValue, wIndex, wLength);
2184 2238
@@ -2197,7 +2251,7 @@ static void handle_setup_packet(struct langwell_udc *dev,
2197 /* We process some stardard setup requests here */ 2251 /* We process some stardard setup requests here */
2198 switch (setup->bRequest) { 2252 switch (setup->bRequest) {
2199 case USB_REQ_GET_STATUS: 2253 case USB_REQ_GET_STATUS:
2200 DBG(dev, "SETUP: USB_REQ_GET_STATUS\n"); 2254 dev_dbg(&dev->pdev->dev, "SETUP: USB_REQ_GET_STATUS\n");
2201 /* get status, DATA and STATUS phase */ 2255 /* get status, DATA and STATUS phase */
2202 if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK)) 2256 if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK))
2203 != (USB_DIR_IN | USB_TYPE_STANDARD)) 2257 != (USB_DIR_IN | USB_TYPE_STANDARD))
@@ -2206,7 +2260,7 @@ static void handle_setup_packet(struct langwell_udc *dev,
2206 goto end; 2260 goto end;
2207 2261
2208 case USB_REQ_SET_ADDRESS: 2262 case USB_REQ_SET_ADDRESS:
2209 DBG(dev, "SETUP: USB_REQ_SET_ADDRESS\n"); 2263 dev_dbg(&dev->pdev->dev, "SETUP: USB_REQ_SET_ADDRESS\n");
2210 /* STATUS phase */ 2264 /* STATUS phase */
2211 if (setup->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD 2265 if (setup->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD
2212 | USB_RECIP_DEVICE)) 2266 | USB_RECIP_DEVICE))
@@ -2220,9 +2274,11 @@ static void handle_setup_packet(struct langwell_udc *dev,
2220 { 2274 {
2221 int rc = -EOPNOTSUPP; 2275 int rc = -EOPNOTSUPP;
2222 if (setup->bRequest == USB_REQ_SET_FEATURE) 2276 if (setup->bRequest == USB_REQ_SET_FEATURE)
2223 DBG(dev, "SETUP: USB_REQ_SET_FEATURE\n"); 2277 dev_dbg(&dev->pdev->dev,
2278 "SETUP: USB_REQ_SET_FEATURE\n");
2224 else if (setup->bRequest == USB_REQ_CLEAR_FEATURE) 2279 else if (setup->bRequest == USB_REQ_CLEAR_FEATURE)
2225 DBG(dev, "SETUP: USB_REQ_CLEAR_FEATURE\n"); 2280 dev_dbg(&dev->pdev->dev,
2281 "SETUP: USB_REQ_CLEAR_FEATURE\n");
2226 2282
2227 if ((setup->bRequestType & (USB_RECIP_MASK | USB_TYPE_MASK)) 2283 if ((setup->bRequestType & (USB_RECIP_MASK | USB_TYPE_MASK))
2228 == (USB_RECIP_ENDPOINT | USB_TYPE_STANDARD)) { 2284 == (USB_RECIP_ENDPOINT | USB_TYPE_STANDARD)) {
@@ -2240,13 +2296,51 @@ static void handle_setup_packet(struct langwell_udc *dev,
2240 2296
2241 spin_unlock(&dev->lock); 2297 spin_unlock(&dev->lock);
2242 rc = langwell_ep_set_halt(&epn->ep, 2298 rc = langwell_ep_set_halt(&epn->ep,
2243 (setup->bRequest == USB_REQ_SET_FEATURE) 2299 (setup->bRequest == USB_REQ_SET_FEATURE)
2244 ? 1 : 0); 2300 ? 1 : 0);
2245 spin_lock(&dev->lock); 2301 spin_lock(&dev->lock);
2246 2302
2247 } else if ((setup->bRequestType & (USB_RECIP_MASK 2303 } else if ((setup->bRequestType & (USB_RECIP_MASK
2248 | USB_TYPE_MASK)) == (USB_RECIP_DEVICE 2304 | USB_TYPE_MASK)) == (USB_RECIP_DEVICE
2249 | USB_TYPE_STANDARD)) { 2305 | USB_TYPE_STANDARD)) {
2306 rc = 0;
2307 switch (wValue) {
2308 case USB_DEVICE_REMOTE_WAKEUP:
2309 if (setup->bRequest == USB_REQ_SET_FEATURE) {
2310 dev->remote_wakeup = 1;
2311 dev->dev_status |= (1 << wValue);
2312 } else {
2313 dev->remote_wakeup = 0;
2314 dev->dev_status &= ~(1 << wValue);
2315 }
2316 break;
2317 case USB_DEVICE_TEST_MODE:
2318 dev_dbg(&dev->pdev->dev, "SETUP: TEST MODE\n");
2319 if ((wIndex & 0xff) ||
2320 (dev->gadget.speed != USB_SPEED_HIGH))
2321 ep0_stall(dev);
2322
2323 switch (wIndex >> 8) {
2324 case TEST_J:
2325 case TEST_K:
2326 case TEST_SE0_NAK:
2327 case TEST_PACKET:
2328 case TEST_FORCE_EN:
2329 if (prime_status_phase(dev, EP_DIR_IN))
2330 ep0_stall(dev);
2331 portsc1 = readl(&dev->op_regs->portsc1);
2332 portsc1 |= (wIndex & 0xf00) << 8;
2333 writel(portsc1, &dev->op_regs->portsc1);
2334 goto end;
2335 default:
2336 rc = -EOPNOTSUPP;
2337 }
2338 break;
2339 default:
2340 rc = -EOPNOTSUPP;
2341 break;
2342 }
2343
2250 if (!gadget_is_otg(&dev->gadget)) 2344 if (!gadget_is_otg(&dev->gadget))
2251 break; 2345 break;
2252 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) { 2346 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) {
@@ -2262,7 +2356,6 @@ static void handle_setup_packet(struct langwell_udc *dev,
2262 dev->gadget.a_alt_hnp_support = 1; 2356 dev->gadget.a_alt_hnp_support = 1;
2263 else 2357 else
2264 break; 2358 break;
2265 rc = 0;
2266 } else 2359 } else
2267 break; 2360 break;
2268 2361
@@ -2274,31 +2367,38 @@ static void handle_setup_packet(struct langwell_udc *dev,
2274 } 2367 }
2275 2368
2276 case USB_REQ_GET_DESCRIPTOR: 2369 case USB_REQ_GET_DESCRIPTOR:
2277 DBG(dev, "SETUP: USB_REQ_GET_DESCRIPTOR\n"); 2370 dev_dbg(&dev->pdev->dev,
2371 "SETUP: USB_REQ_GET_DESCRIPTOR\n");
2278 goto delegate; 2372 goto delegate;
2279 2373
2280 case USB_REQ_SET_DESCRIPTOR: 2374 case USB_REQ_SET_DESCRIPTOR:
2281 DBG(dev, "SETUP: USB_REQ_SET_DESCRIPTOR unsupported\n"); 2375 dev_dbg(&dev->pdev->dev,
2376 "SETUP: USB_REQ_SET_DESCRIPTOR unsupported\n");
2282 goto delegate; 2377 goto delegate;
2283 2378
2284 case USB_REQ_GET_CONFIGURATION: 2379 case USB_REQ_GET_CONFIGURATION:
2285 DBG(dev, "SETUP: USB_REQ_GET_CONFIGURATION\n"); 2380 dev_dbg(&dev->pdev->dev,
2381 "SETUP: USB_REQ_GET_CONFIGURATION\n");
2286 goto delegate; 2382 goto delegate;
2287 2383
2288 case USB_REQ_SET_CONFIGURATION: 2384 case USB_REQ_SET_CONFIGURATION:
2289 DBG(dev, "SETUP: USB_REQ_SET_CONFIGURATION\n"); 2385 dev_dbg(&dev->pdev->dev,
2386 "SETUP: USB_REQ_SET_CONFIGURATION\n");
2290 goto delegate; 2387 goto delegate;
2291 2388
2292 case USB_REQ_GET_INTERFACE: 2389 case USB_REQ_GET_INTERFACE:
2293 DBG(dev, "SETUP: USB_REQ_GET_INTERFACE\n"); 2390 dev_dbg(&dev->pdev->dev,
2391 "SETUP: USB_REQ_GET_INTERFACE\n");
2294 goto delegate; 2392 goto delegate;
2295 2393
2296 case USB_REQ_SET_INTERFACE: 2394 case USB_REQ_SET_INTERFACE:
2297 DBG(dev, "SETUP: USB_REQ_SET_INTERFACE\n"); 2395 dev_dbg(&dev->pdev->dev,
2396 "SETUP: USB_REQ_SET_INTERFACE\n");
2298 goto delegate; 2397 goto delegate;
2299 2398
2300 case USB_REQ_SYNCH_FRAME: 2399 case USB_REQ_SYNCH_FRAME:
2301 DBG(dev, "SETUP: USB_REQ_SYNCH_FRAME unsupported\n"); 2400 dev_dbg(&dev->pdev->dev,
2401 "SETUP: USB_REQ_SYNCH_FRAME unsupported\n");
2302 goto delegate; 2402 goto delegate;
2303 2403
2304 default: 2404 default:
@@ -2310,7 +2410,8 @@ delegate:
2310 /* DATA phase from gadget, STATUS phase from udc */ 2410 /* DATA phase from gadget, STATUS phase from udc */
2311 dev->ep0_dir = (setup->bRequestType & USB_DIR_IN) 2411 dev->ep0_dir = (setup->bRequestType & USB_DIR_IN)
2312 ? USB_DIR_IN : USB_DIR_OUT; 2412 ? USB_DIR_IN : USB_DIR_OUT;
2313 VDBG(dev, "dev->ep0_dir = 0x%x, wLength = %d\n", 2413 dev_vdbg(&dev->pdev->dev,
2414 "dev->ep0_dir = 0x%x, wLength = %d\n",
2314 dev->ep0_dir, wLength); 2415 dev->ep0_dir, wLength);
2315 spin_unlock(&dev->lock); 2416 spin_unlock(&dev->lock);
2316 if (dev->driver->setup(&dev->gadget, 2417 if (dev->driver->setup(&dev->gadget,
@@ -2322,7 +2423,8 @@ delegate:
2322 } else { 2423 } else {
2323 /* no DATA phase, IN STATUS phase from gadget */ 2424 /* no DATA phase, IN STATUS phase from gadget */
2324 dev->ep0_dir = USB_DIR_IN; 2425 dev->ep0_dir = USB_DIR_IN;
2325 VDBG(dev, "dev->ep0_dir = 0x%x, wLength = %d\n", 2426 dev_vdbg(&dev->pdev->dev,
2427 "dev->ep0_dir = 0x%x, wLength = %d\n",
2326 dev->ep0_dir, wLength); 2428 dev->ep0_dir, wLength);
2327 spin_unlock(&dev->lock); 2429 spin_unlock(&dev->lock);
2328 if (dev->driver->setup(&dev->gadget, 2430 if (dev->driver->setup(&dev->gadget,
@@ -2334,8 +2436,7 @@ delegate:
2334 break; 2436 break;
2335 } 2437 }
2336end: 2438end:
2337 VDBG(dev, "<--- %s()\n", __func__); 2439 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2338 return;
2339} 2440}
2340 2441
2341 2442
@@ -2359,23 +2460,27 @@ static int process_ep_req(struct langwell_udc *dev, int index,
2359 td_complete = 0; 2460 td_complete = 0;
2360 actual = curr_req->req.length; 2461 actual = curr_req->req.length;
2361 2462
2362 VDBG(dev, "---> %s()\n", __func__); 2463 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2363 2464
2364 for (i = 0; i < curr_req->dtd_count; i++) { 2465 for (i = 0; i < curr_req->dtd_count; i++) {
2365 remaining_length = le16_to_cpu(curr_dtd->dtd_total);
2366 actual -= remaining_length;
2367 2466
2368 /* command execution states by dTD */ 2467 /* command execution states by dTD */
2369 dtd_status = curr_dtd->dtd_status; 2468 dtd_status = curr_dtd->dtd_status;
2370 2469
2470 barrier();
2471 remaining_length = le16_to_cpu(curr_dtd->dtd_total);
2472 actual -= remaining_length;
2473
2371 if (!dtd_status) { 2474 if (!dtd_status) {
2372 /* transfers completed successfully */ 2475 /* transfers completed successfully */
2373 if (!remaining_length) { 2476 if (!remaining_length) {
2374 td_complete++; 2477 td_complete++;
2375 VDBG(dev, "dTD transmitted successfully\n"); 2478 dev_vdbg(&dev->pdev->dev,
2479 "dTD transmitted successfully\n");
2376 } else { 2480 } else {
2377 if (dir) { 2481 if (dir) {
2378 VDBG(dev, "TX dTD remains data\n"); 2482 dev_vdbg(&dev->pdev->dev,
2483 "TX dTD remains data\n");
2379 retval = -EPROTO; 2484 retval = -EPROTO;
2380 break; 2485 break;
2381 2486
@@ -2387,27 +2492,32 @@ static int process_ep_req(struct langwell_udc *dev, int index,
2387 } else { 2492 } else {
2388 /* transfers completed with errors */ 2493 /* transfers completed with errors */
2389 if (dtd_status & DTD_STS_ACTIVE) { 2494 if (dtd_status & DTD_STS_ACTIVE) {
2390 DBG(dev, "request not completed\n"); 2495 dev_dbg(&dev->pdev->dev,
2496 "dTD status ACTIVE dQH[%d]\n", index);
2391 retval = 1; 2497 retval = 1;
2392 return retval; 2498 return retval;
2393 } else if (dtd_status & DTD_STS_HALTED) { 2499 } else if (dtd_status & DTD_STS_HALTED) {
2394 ERROR(dev, "dTD error %08x dQH[%d]\n", 2500 dev_err(&dev->pdev->dev,
2395 dtd_status, index); 2501 "dTD error %08x dQH[%d]\n",
2502 dtd_status, index);
2396 /* clear the errors and halt condition */ 2503 /* clear the errors and halt condition */
2397 curr_dqh->dtd_status = 0; 2504 curr_dqh->dtd_status = 0;
2398 retval = -EPIPE; 2505 retval = -EPIPE;
2399 break; 2506 break;
2400 } else if (dtd_status & DTD_STS_DBE) { 2507 } else if (dtd_status & DTD_STS_DBE) {
2401 DBG(dev, "data buffer (overflow) error\n"); 2508 dev_dbg(&dev->pdev->dev,
2509 "data buffer (overflow) error\n");
2402 retval = -EPROTO; 2510 retval = -EPROTO;
2403 break; 2511 break;
2404 } else if (dtd_status & DTD_STS_TRE) { 2512 } else if (dtd_status & DTD_STS_TRE) {
2405 DBG(dev, "transaction(ISO) error\n"); 2513 dev_dbg(&dev->pdev->dev,
2514 "transaction(ISO) error\n");
2406 retval = -EILSEQ; 2515 retval = -EILSEQ;
2407 break; 2516 break;
2408 } else 2517 } else
2409 ERROR(dev, "unknown error (0x%x)!\n", 2518 dev_err(&dev->pdev->dev,
2410 dtd_status); 2519 "unknown error (0x%x)!\n",
2520 dtd_status);
2411 } 2521 }
2412 2522
2413 if (i != curr_req->dtd_count - 1) 2523 if (i != curr_req->dtd_count - 1)
@@ -2420,7 +2530,7 @@ static int process_ep_req(struct langwell_udc *dev, int index,
2420 2530
2421 curr_req->req.actual = actual; 2531 curr_req->req.actual = actual;
2422 2532
2423 VDBG(dev, "<--- %s()\n", __func__); 2533 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2424 return 0; 2534 return 0;
2425} 2535}
2426 2536
@@ -2430,7 +2540,7 @@ static void ep0_req_complete(struct langwell_udc *dev,
2430 struct langwell_ep *ep0, struct langwell_request *req) 2540 struct langwell_ep *ep0, struct langwell_request *req)
2431{ 2541{
2432 u32 new_addr; 2542 u32 new_addr;
2433 VDBG(dev, "---> %s()\n", __func__); 2543 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2434 2544
2435 if (dev->usb_state == USB_STATE_ADDRESS) { 2545 if (dev->usb_state == USB_STATE_ADDRESS) {
2436 /* set the new address */ 2546 /* set the new address */
@@ -2438,7 +2548,7 @@ static void ep0_req_complete(struct langwell_udc *dev,
2438 writel(new_addr << USBADR_SHIFT, &dev->op_regs->deviceaddr); 2548 writel(new_addr << USBADR_SHIFT, &dev->op_regs->deviceaddr);
2439 2549
2440 new_addr = USBADR(readl(&dev->op_regs->deviceaddr)); 2550 new_addr = USBADR(readl(&dev->op_regs->deviceaddr));
2441 VDBG(dev, "new_addr = %d\n", new_addr); 2551 dev_vdbg(&dev->pdev->dev, "new_addr = %d\n", new_addr);
2442 } 2552 }
2443 2553
2444 done(ep0, req, 0); 2554 done(ep0, req, 0);
@@ -2458,14 +2568,14 @@ static void ep0_req_complete(struct langwell_udc *dev,
2458 dev->ep0_state = WAIT_FOR_SETUP; 2568 dev->ep0_state = WAIT_FOR_SETUP;
2459 break; 2569 break;
2460 case WAIT_FOR_SETUP: 2570 case WAIT_FOR_SETUP:
2461 ERROR(dev, "unexpect ep0 packets\n"); 2571 dev_err(&dev->pdev->dev, "unexpect ep0 packets\n");
2462 break; 2572 break;
2463 default: 2573 default:
2464 ep0_stall(dev); 2574 ep0_stall(dev);
2465 break; 2575 break;
2466 } 2576 }
2467 2577
2468 VDBG(dev, "<--- %s()\n", __func__); 2578 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2469} 2579}
2470 2580
2471 2581
@@ -2477,16 +2587,17 @@ static void handle_trans_complete(struct langwell_udc *dev)
2477 struct langwell_ep *epn; 2587 struct langwell_ep *epn;
2478 struct langwell_request *curr_req, *temp_req; 2588 struct langwell_request *curr_req, *temp_req;
2479 2589
2480 VDBG(dev, "---> %s()\n", __func__); 2590 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2481 2591
2482 complete_bits = readl(&dev->op_regs->endptcomplete); 2592 complete_bits = readl(&dev->op_regs->endptcomplete);
2483 VDBG(dev, "endptcomplete register: 0x%08x\n", complete_bits); 2593 dev_vdbg(&dev->pdev->dev, "endptcomplete register: 0x%08x\n",
2594 complete_bits);
2484 2595
2485 /* Write-Clear the bits in endptcomplete register */ 2596 /* Write-Clear the bits in endptcomplete register */
2486 writel(complete_bits, &dev->op_regs->endptcomplete); 2597 writel(complete_bits, &dev->op_regs->endptcomplete);
2487 2598
2488 if (!complete_bits) { 2599 if (!complete_bits) {
2489 DBG(dev, "complete_bits = 0\n"); 2600 dev_dbg(&dev->pdev->dev, "complete_bits = 0\n");
2490 goto done; 2601 goto done;
2491 } 2602 }
2492 2603
@@ -2506,23 +2617,25 @@ static void handle_trans_complete(struct langwell_udc *dev)
2506 epn = &dev->ep[i]; 2617 epn = &dev->ep[i];
2507 2618
2508 if (epn->name == NULL) { 2619 if (epn->name == NULL) {
2509 WARNING(dev, "invalid endpoint\n"); 2620 dev_warn(&dev->pdev->dev, "invalid endpoint\n");
2510 continue; 2621 continue;
2511 } 2622 }
2512 2623
2513 if (i < 2) 2624 if (i < 2)
2514 /* ep0 in and out */ 2625 /* ep0 in and out */
2515 DBG(dev, "%s-%s transfer completed\n", 2626 dev_dbg(&dev->pdev->dev, "%s-%s transfer completed\n",
2516 epn->name, 2627 epn->name,
2517 is_in(epn) ? "in" : "out"); 2628 is_in(epn) ? "in" : "out");
2518 else 2629 else
2519 DBG(dev, "%s transfer completed\n", epn->name); 2630 dev_dbg(&dev->pdev->dev, "%s transfer completed\n",
2631 epn->name);
2520 2632
2521 /* process the req queue until an uncomplete request */ 2633 /* process the req queue until an uncomplete request */
2522 list_for_each_entry_safe(curr_req, temp_req, 2634 list_for_each_entry_safe(curr_req, temp_req,
2523 &epn->queue, queue) { 2635 &epn->queue, queue) {
2524 status = process_ep_req(dev, i, curr_req); 2636 status = process_ep_req(dev, i, curr_req);
2525 VDBG(dev, "%s req status: %d\n", epn->name, status); 2637 dev_vdbg(&dev->pdev->dev, "%s req status: %d\n",
2638 epn->name, status);
2526 2639
2527 if (status) 2640 if (status)
2528 break; 2641 break;
@@ -2540,8 +2653,7 @@ static void handle_trans_complete(struct langwell_udc *dev)
2540 } 2653 }
2541 } 2654 }
2542done: 2655done:
2543 VDBG(dev, "<--- %s()\n", __func__); 2656 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2544 return;
2545} 2657}
2546 2658
2547 2659
@@ -2551,14 +2663,14 @@ static void handle_port_change(struct langwell_udc *dev)
2551 u32 portsc1, devlc; 2663 u32 portsc1, devlc;
2552 u32 speed; 2664 u32 speed;
2553 2665
2554 VDBG(dev, "---> %s()\n", __func__); 2666 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2555 2667
2556 if (dev->bus_reset) 2668 if (dev->bus_reset)
2557 dev->bus_reset = 0; 2669 dev->bus_reset = 0;
2558 2670
2559 portsc1 = readl(&dev->op_regs->portsc1); 2671 portsc1 = readl(&dev->op_regs->portsc1);
2560 devlc = readl(&dev->op_regs->devlc); 2672 devlc = readl(&dev->op_regs->devlc);
2561 VDBG(dev, "portsc1 = 0x%08x, devlc = 0x%08x\n", 2673 dev_vdbg(&dev->pdev->dev, "portsc1 = 0x%08x, devlc = 0x%08x\n",
2562 portsc1, devlc); 2674 portsc1, devlc);
2563 2675
2564 /* bus reset is finished */ 2676 /* bus reset is finished */
@@ -2579,25 +2691,22 @@ static void handle_port_change(struct langwell_udc *dev)
2579 dev->gadget.speed = USB_SPEED_UNKNOWN; 2691 dev->gadget.speed = USB_SPEED_UNKNOWN;
2580 break; 2692 break;
2581 } 2693 }
2582 VDBG(dev, "speed = %d, dev->gadget.speed = %d\n", 2694 dev_vdbg(&dev->pdev->dev,
2695 "speed = %d, dev->gadget.speed = %d\n",
2583 speed, dev->gadget.speed); 2696 speed, dev->gadget.speed);
2584 } 2697 }
2585 2698
2586 /* LPM L0 to L1 */ 2699 /* LPM L0 to L1 */
2587 if (dev->lpm && dev->lpm_state == LPM_L0) 2700 if (dev->lpm && dev->lpm_state == LPM_L0)
2588 if (portsc1 & PORTS_SUSP && portsc1 & PORTS_SLP) { 2701 if (portsc1 & PORTS_SUSP && portsc1 & PORTS_SLP) {
2589 INFO(dev, "LPM L0 to L1\n"); 2702 dev_info(&dev->pdev->dev, "LPM L0 to L1\n");
2590 dev->lpm_state = LPM_L1; 2703 dev->lpm_state = LPM_L1;
2591 } 2704 }
2592 2705
2593 /* LPM L1 to L0, force resume or remote wakeup finished */ 2706 /* LPM L1 to L0, force resume or remote wakeup finished */
2594 if (dev->lpm && dev->lpm_state == LPM_L1) 2707 if (dev->lpm && dev->lpm_state == LPM_L1)
2595 if (!(portsc1 & PORTS_SUSP)) { 2708 if (!(portsc1 & PORTS_SUSP)) {
2596 if (portsc1 & PORTS_SLP) 2709 dev_info(&dev->pdev->dev, "LPM L1 to L0\n");
2597 INFO(dev, "LPM L1 to L0, force resume\n");
2598 else
2599 INFO(dev, "LPM L1 to L0, remote wakeup\n");
2600
2601 dev->lpm_state = LPM_L0; 2710 dev->lpm_state = LPM_L0;
2602 } 2711 }
2603 2712
@@ -2605,7 +2714,7 @@ static void handle_port_change(struct langwell_udc *dev)
2605 if (!dev->resume_state) 2714 if (!dev->resume_state)
2606 dev->usb_state = USB_STATE_DEFAULT; 2715 dev->usb_state = USB_STATE_DEFAULT;
2607 2716
2608 VDBG(dev, "<--- %s()\n", __func__); 2717 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2609} 2718}
2610 2719
2611 2720
@@ -2617,7 +2726,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
2617 endptcomplete; 2726 endptcomplete;
2618 unsigned long timeout; 2727 unsigned long timeout;
2619 2728
2620 VDBG(dev, "---> %s()\n", __func__); 2729 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2621 2730
2622 /* Write-Clear the device address */ 2731 /* Write-Clear the device address */
2623 deviceaddr = readl(&dev->op_regs->deviceaddr); 2732 deviceaddr = readl(&dev->op_regs->deviceaddr);
@@ -2634,7 +2743,10 @@ static void handle_usb_reset(struct langwell_udc *dev)
2634 2743
2635 dev->ep0_dir = USB_DIR_OUT; 2744 dev->ep0_dir = USB_DIR_OUT;
2636 dev->ep0_state = WAIT_FOR_SETUP; 2745 dev->ep0_state = WAIT_FOR_SETUP;
2637 dev->remote_wakeup = 0; /* default to 0 on reset */ 2746
2747 /* remote wakeup reset to 0 when the device is reset */
2748 dev->remote_wakeup = 0;
2749 dev->dev_status = 1 << USB_DEVICE_SELF_POWERED;
2638 dev->gadget.b_hnp_enable = 0; 2750 dev->gadget.b_hnp_enable = 0;
2639 dev->gadget.a_hnp_support = 0; 2751 dev->gadget.a_hnp_support = 0;
2640 dev->gadget.a_alt_hnp_support = 0; 2752 dev->gadget.a_alt_hnp_support = 0;
@@ -2651,7 +2763,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
2651 timeout = jiffies + PRIME_TIMEOUT; 2763 timeout = jiffies + PRIME_TIMEOUT;
2652 while (readl(&dev->op_regs->endptprime)) { 2764 while (readl(&dev->op_regs->endptprime)) {
2653 if (time_after(jiffies, timeout)) { 2765 if (time_after(jiffies, timeout)) {
2654 ERROR(dev, "USB reset timeout\n"); 2766 dev_err(&dev->pdev->dev, "USB reset timeout\n");
2655 break; 2767 break;
2656 } 2768 }
2657 cpu_relax(); 2769 cpu_relax();
@@ -2661,7 +2773,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
2661 writel((u32) ~0, &dev->op_regs->endptflush); 2773 writel((u32) ~0, &dev->op_regs->endptflush);
2662 2774
2663 if (readl(&dev->op_regs->portsc1) & PORTS_PR) { 2775 if (readl(&dev->op_regs->portsc1) & PORTS_PR) {
2664 VDBG(dev, "USB bus reset\n"); 2776 dev_vdbg(&dev->pdev->dev, "USB bus reset\n");
2665 /* bus is reseting */ 2777 /* bus is reseting */
2666 dev->bus_reset = 1; 2778 dev->bus_reset = 1;
2667 2779
@@ -2669,7 +2781,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
2669 stop_activity(dev, dev->driver); 2781 stop_activity(dev, dev->driver);
2670 dev->usb_state = USB_STATE_DEFAULT; 2782 dev->usb_state = USB_STATE_DEFAULT;
2671 } else { 2783 } else {
2672 VDBG(dev, "device controller reset\n"); 2784 dev_vdbg(&dev->pdev->dev, "device controller reset\n");
2673 /* controller reset */ 2785 /* controller reset */
2674 langwell_udc_reset(dev); 2786 langwell_udc_reset(dev);
2675 2787
@@ -2691,15 +2803,14 @@ static void handle_usb_reset(struct langwell_udc *dev)
2691 dev->lotg->hsm.b_hnp_enable = 0; 2803 dev->lotg->hsm.b_hnp_enable = 0;
2692#endif 2804#endif
2693 2805
2694 VDBG(dev, "<--- %s()\n", __func__); 2806 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2695} 2807}
2696 2808
2697 2809
2698/* USB bus suspend/resume interrupt */ 2810/* USB bus suspend/resume interrupt */
2699static void handle_bus_suspend(struct langwell_udc *dev) 2811static void handle_bus_suspend(struct langwell_udc *dev)
2700{ 2812{
2701 u32 devlc; 2813 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
2702 DBG(dev, "---> %s()\n", __func__);
2703 2814
2704 dev->resume_state = dev->usb_state; 2815 dev->resume_state = dev->usb_state;
2705 dev->usb_state = USB_STATE_SUSPENDED; 2816 dev->usb_state = USB_STATE_SUSPENDED;
@@ -2733,33 +2844,29 @@ static void handle_bus_suspend(struct langwell_udc *dev)
2733 spin_unlock(&dev->lock); 2844 spin_unlock(&dev->lock);
2734 dev->driver->suspend(&dev->gadget); 2845 dev->driver->suspend(&dev->gadget);
2735 spin_lock(&dev->lock); 2846 spin_lock(&dev->lock);
2736 DBG(dev, "suspend %s\n", dev->driver->driver.name); 2847 dev_dbg(&dev->pdev->dev, "suspend %s\n",
2848 dev->driver->driver.name);
2737 } 2849 }
2738 } 2850 }
2739 2851
2740 /* enter PHY low power suspend */ 2852 /* enter PHY low power suspend */
2741 devlc = readl(&dev->op_regs->devlc); 2853 if (dev->pdev->device != 0x0829)
2742 VDBG(dev, "devlc = 0x%08x\n", devlc); 2854 langwell_phy_low_power(dev, 0);
2743 devlc |= LPM_PHCD;
2744 writel(devlc, &dev->op_regs->devlc);
2745 2855
2746 DBG(dev, "<--- %s()\n", __func__); 2856 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2747} 2857}
2748 2858
2749 2859
2750static void handle_bus_resume(struct langwell_udc *dev) 2860static void handle_bus_resume(struct langwell_udc *dev)
2751{ 2861{
2752 u32 devlc; 2862 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
2753 DBG(dev, "---> %s()\n", __func__);
2754 2863
2755 dev->usb_state = dev->resume_state; 2864 dev->usb_state = dev->resume_state;
2756 dev->resume_state = 0; 2865 dev->resume_state = 0;
2757 2866
2758 /* exit PHY low power suspend */ 2867 /* exit PHY low power suspend */
2759 devlc = readl(&dev->op_regs->devlc); 2868 if (dev->pdev->device != 0x0829)
2760 VDBG(dev, "devlc = 0x%08x\n", devlc); 2869 langwell_phy_low_power(dev, 0);
2761 devlc &= ~LPM_PHCD;
2762 writel(devlc, &dev->op_regs->devlc);
2763 2870
2764#ifdef OTG_TRANSCEIVER 2871#ifdef OTG_TRANSCEIVER
2765 if (dev->lotg->otg.default_a == 0) 2872 if (dev->lotg->otg.default_a == 0)
@@ -2772,11 +2879,12 @@ static void handle_bus_resume(struct langwell_udc *dev)
2772 spin_unlock(&dev->lock); 2879 spin_unlock(&dev->lock);
2773 dev->driver->resume(&dev->gadget); 2880 dev->driver->resume(&dev->gadget);
2774 spin_lock(&dev->lock); 2881 spin_lock(&dev->lock);
2775 DBG(dev, "resume %s\n", dev->driver->driver.name); 2882 dev_dbg(&dev->pdev->dev, "resume %s\n",
2883 dev->driver->driver.name);
2776 } 2884 }
2777 } 2885 }
2778 2886
2779 DBG(dev, "<--- %s()\n", __func__); 2887 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2780} 2888}
2781 2889
2782 2890
@@ -2789,11 +2897,11 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2789 irq_sts, 2897 irq_sts,
2790 portsc1; 2898 portsc1;
2791 2899
2792 VDBG(dev, "---> %s()\n", __func__); 2900 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2793 2901
2794 if (dev->stopped) { 2902 if (dev->stopped) {
2795 VDBG(dev, "handle IRQ_NONE\n"); 2903 dev_vdbg(&dev->pdev->dev, "handle IRQ_NONE\n");
2796 VDBG(dev, "<--- %s()\n", __func__); 2904 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2797 return IRQ_NONE; 2905 return IRQ_NONE;
2798 } 2906 }
2799 2907
@@ -2806,12 +2914,13 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2806 usbintr = readl(&dev->op_regs->usbintr); 2914 usbintr = readl(&dev->op_regs->usbintr);
2807 2915
2808 irq_sts = usbsts & usbintr; 2916 irq_sts = usbsts & usbintr;
2809 VDBG(dev, "usbsts = 0x%08x, usbintr = 0x%08x, irq_sts = 0x%08x\n", 2917 dev_vdbg(&dev->pdev->dev,
2918 "usbsts = 0x%08x, usbintr = 0x%08x, irq_sts = 0x%08x\n",
2810 usbsts, usbintr, irq_sts); 2919 usbsts, usbintr, irq_sts);
2811 2920
2812 if (!irq_sts) { 2921 if (!irq_sts) {
2813 VDBG(dev, "handle IRQ_NONE\n"); 2922 dev_vdbg(&dev->pdev->dev, "handle IRQ_NONE\n");
2814 VDBG(dev, "<--- %s()\n", __func__); 2923 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2815 spin_unlock(&dev->lock); 2924 spin_unlock(&dev->lock);
2816 return IRQ_NONE; 2925 return IRQ_NONE;
2817 } 2926 }
@@ -2827,12 +2936,13 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2827 2936
2828 /* USB interrupt */ 2937 /* USB interrupt */
2829 if (irq_sts & STS_UI) { 2938 if (irq_sts & STS_UI) {
2830 VDBG(dev, "USB interrupt\n"); 2939 dev_vdbg(&dev->pdev->dev, "USB interrupt\n");
2831 2940
2832 /* setup packet received from ep0 */ 2941 /* setup packet received from ep0 */
2833 if (readl(&dev->op_regs->endptsetupstat) 2942 if (readl(&dev->op_regs->endptsetupstat)
2834 & EP0SETUPSTAT_MASK) { 2943 & EP0SETUPSTAT_MASK) {
2835 VDBG(dev, "USB SETUP packet received interrupt\n"); 2944 dev_vdbg(&dev->pdev->dev,
2945 "USB SETUP packet received interrupt\n");
2836 /* setup tripwire semaphone */ 2946 /* setup tripwire semaphone */
2837 setup_tripwire(dev); 2947 setup_tripwire(dev);
2838 handle_setup_packet(dev, &dev->local_setup_buff); 2948 handle_setup_packet(dev, &dev->local_setup_buff);
@@ -2840,7 +2950,8 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2840 2950
2841 /* USB transfer completion */ 2951 /* USB transfer completion */
2842 if (readl(&dev->op_regs->endptcomplete)) { 2952 if (readl(&dev->op_regs->endptcomplete)) {
2843 VDBG(dev, "USB transfer completion interrupt\n"); 2953 dev_vdbg(&dev->pdev->dev,
2954 "USB transfer completion interrupt\n");
2844 handle_trans_complete(dev); 2955 handle_trans_complete(dev);
2845 } 2956 }
2846 } 2957 }
@@ -2848,36 +2959,36 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2848 /* SOF received interrupt (for ISO transfer) */ 2959 /* SOF received interrupt (for ISO transfer) */
2849 if (irq_sts & STS_SRI) { 2960 if (irq_sts & STS_SRI) {
2850 /* FIXME */ 2961 /* FIXME */
2851 /* VDBG(dev, "SOF received interrupt\n"); */ 2962 /* dev_vdbg(&dev->pdev->dev, "SOF received interrupt\n"); */
2852 } 2963 }
2853 2964
2854 /* port change detect interrupt */ 2965 /* port change detect interrupt */
2855 if (irq_sts & STS_PCI) { 2966 if (irq_sts & STS_PCI) {
2856 VDBG(dev, "port change detect interrupt\n"); 2967 dev_vdbg(&dev->pdev->dev, "port change detect interrupt\n");
2857 handle_port_change(dev); 2968 handle_port_change(dev);
2858 } 2969 }
2859 2970
2860 /* suspend interrrupt */ 2971 /* suspend interrrupt */
2861 if (irq_sts & STS_SLI) { 2972 if (irq_sts & STS_SLI) {
2862 VDBG(dev, "suspend interrupt\n"); 2973 dev_vdbg(&dev->pdev->dev, "suspend interrupt\n");
2863 handle_bus_suspend(dev); 2974 handle_bus_suspend(dev);
2864 } 2975 }
2865 2976
2866 /* USB reset interrupt */ 2977 /* USB reset interrupt */
2867 if (irq_sts & STS_URI) { 2978 if (irq_sts & STS_URI) {
2868 VDBG(dev, "USB reset interrupt\n"); 2979 dev_vdbg(&dev->pdev->dev, "USB reset interrupt\n");
2869 handle_usb_reset(dev); 2980 handle_usb_reset(dev);
2870 } 2981 }
2871 2982
2872 /* USB error or system error interrupt */ 2983 /* USB error or system error interrupt */
2873 if (irq_sts & (STS_UEI | STS_SEI)) { 2984 if (irq_sts & (STS_UEI | STS_SEI)) {
2874 /* FIXME */ 2985 /* FIXME */
2875 WARNING(dev, "error IRQ, irq_sts: %x\n", irq_sts); 2986 dev_warn(&dev->pdev->dev, "error IRQ, irq_sts: %x\n", irq_sts);
2876 } 2987 }
2877 2988
2878 spin_unlock(&dev->lock); 2989 spin_unlock(&dev->lock);
2879 2990
2880 VDBG(dev, "<--- %s()\n", __func__); 2991 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2881 return IRQ_HANDLED; 2992 return IRQ_HANDLED;
2882} 2993}
2883 2994
@@ -2889,15 +3000,59 @@ static void gadget_release(struct device *_dev)
2889{ 3000{
2890 struct langwell_udc *dev = the_controller; 3001 struct langwell_udc *dev = the_controller;
2891 3002
2892 DBG(dev, "---> %s()\n", __func__); 3003 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
2893 3004
2894 complete(dev->done); 3005 complete(dev->done);
2895 3006
2896 DBG(dev, "<--- %s()\n", __func__); 3007 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2897 kfree(dev); 3008 kfree(dev);
2898} 3009}
2899 3010
2900 3011
3012/* enable SRAM caching if SRAM detected */
3013static void sram_init(struct langwell_udc *dev)
3014{
3015 struct pci_dev *pdev = dev->pdev;
3016
3017 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3018
3019 dev->sram_addr = pci_resource_start(pdev, 1);
3020 dev->sram_size = pci_resource_len(pdev, 1);
3021 dev_info(&dev->pdev->dev, "Found private SRAM at %x size:%x\n",
3022 dev->sram_addr, dev->sram_size);
3023 dev->got_sram = 1;
3024
3025 if (pci_request_region(pdev, 1, kobject_name(&pdev->dev.kobj))) {
3026 dev_warn(&dev->pdev->dev, "SRAM request failed\n");
3027 dev->got_sram = 0;
3028 } else if (!dma_declare_coherent_memory(&pdev->dev, dev->sram_addr,
3029 dev->sram_addr, dev->sram_size, DMA_MEMORY_MAP)) {
3030 dev_warn(&dev->pdev->dev, "SRAM DMA declare failed\n");
3031 pci_release_region(pdev, 1);
3032 dev->got_sram = 0;
3033 }
3034
3035 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3036}
3037
3038
3039/* release SRAM caching */
3040static void sram_deinit(struct langwell_udc *dev)
3041{
3042 struct pci_dev *pdev = dev->pdev;
3043
3044 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3045
3046 dma_release_declared_memory(&pdev->dev);
3047 pci_release_region(pdev, 1);
3048
3049 dev->got_sram = 0;
3050
3051 dev_info(&dev->pdev->dev, "release SRAM caching\n");
3052 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3053}
3054
3055
2901/* tear down the binding between this driver and the pci device */ 3056/* tear down the binding between this driver and the pci device */
2902static void langwell_udc_remove(struct pci_dev *pdev) 3057static void langwell_udc_remove(struct pci_dev *pdev)
2903{ 3058{
@@ -2906,26 +3061,32 @@ static void langwell_udc_remove(struct pci_dev *pdev)
2906 DECLARE_COMPLETION(done); 3061 DECLARE_COMPLETION(done);
2907 3062
2908 BUG_ON(dev->driver); 3063 BUG_ON(dev->driver);
2909 DBG(dev, "---> %s()\n", __func__); 3064 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
2910 3065
2911 dev->done = &done; 3066 dev->done = &done;
2912 3067
2913 /* free memory allocated in probe */ 3068#ifndef OTG_TRANSCEIVER
3069 /* free dTD dma_pool and dQH */
2914 if (dev->dtd_pool) 3070 if (dev->dtd_pool)
2915 dma_pool_destroy(dev->dtd_pool); 3071 dma_pool_destroy(dev->dtd_pool);
2916 3072
3073 if (dev->ep_dqh)
3074 dma_free_coherent(&pdev->dev, dev->ep_dqh_size,
3075 dev->ep_dqh, dev->ep_dqh_dma);
3076
3077 /* release SRAM caching */
3078 if (dev->has_sram && dev->got_sram)
3079 sram_deinit(dev);
3080#endif
3081
2917 if (dev->status_req) { 3082 if (dev->status_req) {
2918 kfree(dev->status_req->req.buf); 3083 kfree(dev->status_req->req.buf);
2919 kfree(dev->status_req); 3084 kfree(dev->status_req);
2920 } 3085 }
2921 3086
2922 if (dev->ep_dqh)
2923 dma_free_coherent(&pdev->dev, dev->ep_dqh_size,
2924 dev->ep_dqh, dev->ep_dqh_dma);
2925
2926 kfree(dev->ep); 3087 kfree(dev->ep);
2927 3088
2928 /* diable IRQ handler */ 3089 /* disable IRQ handler */
2929 if (dev->got_irq) 3090 if (dev->got_irq)
2930 free_irq(pdev->irq, dev); 3091 free_irq(pdev->irq, dev);
2931 3092
@@ -2949,11 +3110,12 @@ static void langwell_udc_remove(struct pci_dev *pdev)
2949 3110
2950 dev->cap_regs = NULL; 3111 dev->cap_regs = NULL;
2951 3112
2952 INFO(dev, "unbind\n"); 3113 dev_info(&dev->pdev->dev, "unbind\n");
2953 DBG(dev, "<--- %s()\n", __func__); 3114 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2954 3115
2955 device_unregister(&dev->gadget.dev); 3116 device_unregister(&dev->gadget.dev);
2956 device_remove_file(&pdev->dev, &dev_attr_langwell_udc); 3117 device_remove_file(&pdev->dev, &dev_attr_langwell_udc);
3118 device_remove_file(&pdev->dev, &dev_attr_remote_wakeup);
2957 3119
2958#ifndef OTG_TRANSCEIVER 3120#ifndef OTG_TRANSCEIVER
2959 pci_set_drvdata(pdev, NULL); 3121 pci_set_drvdata(pdev, NULL);
@@ -2997,7 +3159,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
2997 spin_lock_init(&dev->lock); 3159 spin_lock_init(&dev->lock);
2998 3160
2999 dev->pdev = pdev; 3161 dev->pdev = pdev;
3000 DBG(dev, "---> %s()\n", __func__); 3162 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3001 3163
3002#ifdef OTG_TRANSCEIVER 3164#ifdef OTG_TRANSCEIVER
3003 /* PCI device is already enabled by otg_transceiver driver */ 3165 /* PCI device is already enabled by otg_transceiver driver */
@@ -3022,7 +3184,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3022 resource = pci_resource_start(pdev, 0); 3184 resource = pci_resource_start(pdev, 0);
3023 len = pci_resource_len(pdev, 0); 3185 len = pci_resource_len(pdev, 0);
3024 if (!request_mem_region(resource, len, driver_name)) { 3186 if (!request_mem_region(resource, len, driver_name)) {
3025 ERROR(dev, "controller already in use\n"); 3187 dev_err(&dev->pdev->dev, "controller already in use\n");
3026 retval = -EBUSY; 3188 retval = -EBUSY;
3027 goto error; 3189 goto error;
3028 } 3190 }
@@ -3031,33 +3193,43 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3031 base = ioremap_nocache(resource, len); 3193 base = ioremap_nocache(resource, len);
3032#endif 3194#endif
3033 if (base == NULL) { 3195 if (base == NULL) {
3034 ERROR(dev, "can't map memory\n"); 3196 dev_err(&dev->pdev->dev, "can't map memory\n");
3035 retval = -EFAULT; 3197 retval = -EFAULT;
3036 goto error; 3198 goto error;
3037 } 3199 }
3038 3200
3039 dev->cap_regs = (struct langwell_cap_regs __iomem *) base; 3201 dev->cap_regs = (struct langwell_cap_regs __iomem *) base;
3040 VDBG(dev, "dev->cap_regs: %p\n", dev->cap_regs); 3202 dev_vdbg(&dev->pdev->dev, "dev->cap_regs: %p\n", dev->cap_regs);
3041 dev->op_regs = (struct langwell_op_regs __iomem *) 3203 dev->op_regs = (struct langwell_op_regs __iomem *)
3042 (base + OP_REG_OFFSET); 3204 (base + OP_REG_OFFSET);
3043 VDBG(dev, "dev->op_regs: %p\n", dev->op_regs); 3205 dev_vdbg(&dev->pdev->dev, "dev->op_regs: %p\n", dev->op_regs);
3044 3206
3045 /* irq setup after old hardware is cleaned up */ 3207 /* irq setup after old hardware is cleaned up */
3046 if (!pdev->irq) { 3208 if (!pdev->irq) {
3047 ERROR(dev, "No IRQ. Check PCI setup!\n"); 3209 dev_err(&dev->pdev->dev, "No IRQ. Check PCI setup!\n");
3048 retval = -ENODEV; 3210 retval = -ENODEV;
3049 goto error; 3211 goto error;
3050 } 3212 }
3051 3213
3214 dev->has_sram = 1;
3215 dev->got_sram = 0;
3216 dev_vdbg(&dev->pdev->dev, "dev->has_sram: %d\n", dev->has_sram);
3217
3052#ifndef OTG_TRANSCEIVER 3218#ifndef OTG_TRANSCEIVER
3053 INFO(dev, "irq %d, io mem: 0x%08lx, len: 0x%08lx, pci mem 0x%p\n", 3219 /* enable SRAM caching if detected */
3220 if (dev->has_sram && !dev->got_sram)
3221 sram_init(dev);
3222
3223 dev_info(&dev->pdev->dev,
3224 "irq %d, io mem: 0x%08lx, len: 0x%08lx, pci mem 0x%p\n",
3054 pdev->irq, resource, len, base); 3225 pdev->irq, resource, len, base);
3055 /* enables bus-mastering for device dev */ 3226 /* enables bus-mastering for device dev */
3056 pci_set_master(pdev); 3227 pci_set_master(pdev);
3057 3228
3058 if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED, 3229 if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED,
3059 driver_name, dev) != 0) { 3230 driver_name, dev) != 0) {
3060 ERROR(dev, "request interrupt %d failed\n", pdev->irq); 3231 dev_err(&dev->pdev->dev,
3232 "request interrupt %d failed\n", pdev->irq);
3061 retval = -EBUSY; 3233 retval = -EBUSY;
3062 goto error; 3234 goto error;
3063 } 3235 }
@@ -3071,32 +3243,34 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3071 dev->lpm = (readl(&dev->cap_regs->hccparams) & HCC_LEN) ? 1 : 0; 3243 dev->lpm = (readl(&dev->cap_regs->hccparams) & HCC_LEN) ? 1 : 0;
3072 dev->dciversion = readw(&dev->cap_regs->dciversion); 3244 dev->dciversion = readw(&dev->cap_regs->dciversion);
3073 dev->devcap = (readl(&dev->cap_regs->dccparams) & DEVCAP) ? 1 : 0; 3245 dev->devcap = (readl(&dev->cap_regs->dccparams) & DEVCAP) ? 1 : 0;
3074 VDBG(dev, "dev->lpm: %d\n", dev->lpm); 3246 dev_vdbg(&dev->pdev->dev, "dev->lpm: %d\n", dev->lpm);
3075 VDBG(dev, "dev->dciversion: 0x%04x\n", dev->dciversion); 3247 dev_vdbg(&dev->pdev->dev, "dev->dciversion: 0x%04x\n",
3076 VDBG(dev, "dccparams: 0x%08x\n", readl(&dev->cap_regs->dccparams)); 3248 dev->dciversion);
3077 VDBG(dev, "dev->devcap: %d\n", dev->devcap); 3249 dev_vdbg(&dev->pdev->dev, "dccparams: 0x%08x\n",
3250 readl(&dev->cap_regs->dccparams));
3251 dev_vdbg(&dev->pdev->dev, "dev->devcap: %d\n", dev->devcap);
3078 if (!dev->devcap) { 3252 if (!dev->devcap) {
3079 ERROR(dev, "can't support device mode\n"); 3253 dev_err(&dev->pdev->dev, "can't support device mode\n");
3080 retval = -ENODEV; 3254 retval = -ENODEV;
3081 goto error; 3255 goto error;
3082 } 3256 }
3083 3257
3084 /* a pair of endpoints (out/in) for each address */ 3258 /* a pair of endpoints (out/in) for each address */
3085 dev->ep_max = DEN(readl(&dev->cap_regs->dccparams)) * 2; 3259 dev->ep_max = DEN(readl(&dev->cap_regs->dccparams)) * 2;
3086 VDBG(dev, "dev->ep_max: %d\n", dev->ep_max); 3260 dev_vdbg(&dev->pdev->dev, "dev->ep_max: %d\n", dev->ep_max);
3087 3261
3088 /* allocate endpoints memory */ 3262 /* allocate endpoints memory */
3089 dev->ep = kzalloc(sizeof(struct langwell_ep) * dev->ep_max, 3263 dev->ep = kzalloc(sizeof(struct langwell_ep) * dev->ep_max,
3090 GFP_KERNEL); 3264 GFP_KERNEL);
3091 if (!dev->ep) { 3265 if (!dev->ep) {
3092 ERROR(dev, "allocate endpoints memory failed\n"); 3266 dev_err(&dev->pdev->dev, "allocate endpoints memory failed\n");
3093 retval = -ENOMEM; 3267 retval = -ENOMEM;
3094 goto error; 3268 goto error;
3095 } 3269 }
3096 3270
3097 /* allocate device dQH memory */ 3271 /* allocate device dQH memory */
3098 size = dev->ep_max * sizeof(struct langwell_dqh); 3272 size = dev->ep_max * sizeof(struct langwell_dqh);
3099 VDBG(dev, "orig size = %d\n", size); 3273 dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size);
3100 if (size < DQH_ALIGNMENT) 3274 if (size < DQH_ALIGNMENT)
3101 size = DQH_ALIGNMENT; 3275 size = DQH_ALIGNMENT;
3102 else if ((size % DQH_ALIGNMENT) != 0) { 3276 else if ((size % DQH_ALIGNMENT) != 0) {
@@ -3106,17 +3280,18 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3106 dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size, 3280 dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size,
3107 &dev->ep_dqh_dma, GFP_KERNEL); 3281 &dev->ep_dqh_dma, GFP_KERNEL);
3108 if (!dev->ep_dqh) { 3282 if (!dev->ep_dqh) {
3109 ERROR(dev, "allocate dQH memory failed\n"); 3283 dev_err(&dev->pdev->dev, "allocate dQH memory failed\n");
3110 retval = -ENOMEM; 3284 retval = -ENOMEM;
3111 goto error; 3285 goto error;
3112 } 3286 }
3113 dev->ep_dqh_size = size; 3287 dev->ep_dqh_size = size;
3114 VDBG(dev, "ep_dqh_size = %d\n", dev->ep_dqh_size); 3288 dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size);
3115 3289
3116 /* initialize ep0 status request structure */ 3290 /* initialize ep0 status request structure */
3117 dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL); 3291 dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL);
3118 if (!dev->status_req) { 3292 if (!dev->status_req) {
3119 ERROR(dev, "allocate status_req memory failed\n"); 3293 dev_err(&dev->pdev->dev,
3294 "allocate status_req memory failed\n");
3120 retval = -ENOMEM; 3295 retval = -ENOMEM;
3121 goto error; 3296 goto error;
3122 } 3297 }
@@ -3129,7 +3304,10 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3129 dev->resume_state = USB_STATE_NOTATTACHED; 3304 dev->resume_state = USB_STATE_NOTATTACHED;
3130 dev->usb_state = USB_STATE_POWERED; 3305 dev->usb_state = USB_STATE_POWERED;
3131 dev->ep0_dir = USB_DIR_OUT; 3306 dev->ep0_dir = USB_DIR_OUT;
3132 dev->remote_wakeup = 0; /* default to 0 on reset */ 3307
3308 /* remote wakeup reset to 0 when the device is reset */
3309 dev->remote_wakeup = 0;
3310 dev->dev_status = 1 << USB_DEVICE_SELF_POWERED;
3133 3311
3134#ifndef OTG_TRANSCEIVER 3312#ifndef OTG_TRANSCEIVER
3135 /* reset device controller */ 3313 /* reset device controller */
@@ -3174,18 +3352,20 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3174 } 3352 }
3175 3353
3176 /* done */ 3354 /* done */
3177 INFO(dev, "%s\n", driver_desc); 3355 dev_info(&dev->pdev->dev, "%s\n", driver_desc);
3178 INFO(dev, "irq %d, pci mem %p\n", pdev->irq, base); 3356 dev_info(&dev->pdev->dev, "irq %d, pci mem %p\n", pdev->irq, base);
3179 INFO(dev, "Driver version: " DRIVER_VERSION "\n"); 3357 dev_info(&dev->pdev->dev, "Driver version: " DRIVER_VERSION "\n");
3180 INFO(dev, "Support (max) %d endpoints\n", dev->ep_max); 3358 dev_info(&dev->pdev->dev, "Support (max) %d endpoints\n", dev->ep_max);
3181 INFO(dev, "Device interface version: 0x%04x\n", dev->dciversion); 3359 dev_info(&dev->pdev->dev, "Device interface version: 0x%04x\n",
3182 INFO(dev, "Controller mode: %s\n", dev->devcap ? "Device" : "Host"); 3360 dev->dciversion);
3183 INFO(dev, "Support USB LPM: %s\n", dev->lpm ? "Yes" : "No"); 3361 dev_info(&dev->pdev->dev, "Controller mode: %s\n",
3184 3362 dev->devcap ? "Device" : "Host");
3185 VDBG(dev, "After langwell_udc_probe(), print all registers:\n"); 3363 dev_info(&dev->pdev->dev, "Support USB LPM: %s\n",
3186#ifdef VERBOSE 3364 dev->lpm ? "Yes" : "No");
3365
3366 dev_vdbg(&dev->pdev->dev,
3367 "After langwell_udc_probe(), print all registers:\n");
3187 print_all_registers(dev); 3368 print_all_registers(dev);
3188#endif
3189 3369
3190 the_controller = dev; 3370 the_controller = dev;
3191 3371
@@ -3197,12 +3377,18 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3197 if (retval) 3377 if (retval)
3198 goto error; 3378 goto error;
3199 3379
3200 VDBG(dev, "<--- %s()\n", __func__); 3380 retval = device_create_file(&pdev->dev, &dev_attr_remote_wakeup);
3381 if (retval)
3382 goto error_attr1;
3383
3384 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3201 return 0; 3385 return 0;
3202 3386
3387error_attr1:
3388 device_remove_file(&pdev->dev, &dev_attr_langwell_udc);
3203error: 3389error:
3204 if (dev) { 3390 if (dev) {
3205 DBG(dev, "<--- %s()\n", __func__); 3391 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3206 langwell_udc_remove(pdev); 3392 langwell_udc_remove(pdev);
3207 } 3393 }
3208 3394
@@ -3214,32 +3400,45 @@ error:
3214static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state) 3400static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
3215{ 3401{
3216 struct langwell_udc *dev = the_controller; 3402 struct langwell_udc *dev = the_controller;
3217 u32 devlc;
3218 3403
3219 DBG(dev, "---> %s()\n", __func__); 3404 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3220 3405
3221 /* disable interrupt and set controller to stop state */ 3406 /* disable interrupt and set controller to stop state */
3222 langwell_udc_stop(dev); 3407 langwell_udc_stop(dev);
3223 3408
3224 /* diable IRQ handler */ 3409 /* disable IRQ handler */
3225 if (dev->got_irq) 3410 if (dev->got_irq)
3226 free_irq(pdev->irq, dev); 3411 free_irq(pdev->irq, dev);
3227 dev->got_irq = 0; 3412 dev->got_irq = 0;
3228 3413
3229
3230 /* save PCI state */ 3414 /* save PCI state */
3231 pci_save_state(pdev); 3415 pci_save_state(pdev);
3232 3416
3417 spin_lock_irq(&dev->lock);
3418 /* stop all usb activities */
3419 stop_activity(dev, dev->driver);
3420 spin_unlock_irq(&dev->lock);
3421
3422 /* free dTD dma_pool and dQH */
3423 if (dev->dtd_pool)
3424 dma_pool_destroy(dev->dtd_pool);
3425
3426 if (dev->ep_dqh)
3427 dma_free_coherent(&pdev->dev, dev->ep_dqh_size,
3428 dev->ep_dqh, dev->ep_dqh_dma);
3429
3430 /* release SRAM caching */
3431 if (dev->has_sram && dev->got_sram)
3432 sram_deinit(dev);
3433
3233 /* set device power state */ 3434 /* set device power state */
3234 pci_set_power_state(pdev, PCI_D3hot); 3435 pci_set_power_state(pdev, PCI_D3hot);
3235 3436
3236 /* enter PHY low power suspend */ 3437 /* enter PHY low power suspend */
3237 devlc = readl(&dev->op_regs->devlc); 3438 if (dev->pdev->device != 0x0829)
3238 VDBG(dev, "devlc = 0x%08x\n", devlc); 3439 langwell_phy_low_power(dev, 1);
3239 devlc |= LPM_PHCD;
3240 writel(devlc, &dev->op_regs->devlc);
3241 3440
3242 DBG(dev, "<--- %s()\n", __func__); 3441 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3243 return 0; 3442 return 0;
3244} 3443}
3245 3444
@@ -3248,27 +3447,58 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
3248static int langwell_udc_resume(struct pci_dev *pdev) 3447static int langwell_udc_resume(struct pci_dev *pdev)
3249{ 3448{
3250 struct langwell_udc *dev = the_controller; 3449 struct langwell_udc *dev = the_controller;
3251 u32 devlc; 3450 size_t size;
3252 3451
3253 DBG(dev, "---> %s()\n", __func__); 3452 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3254 3453
3255 /* exit PHY low power suspend */ 3454 /* exit PHY low power suspend */
3256 devlc = readl(&dev->op_regs->devlc); 3455 if (dev->pdev->device != 0x0829)
3257 VDBG(dev, "devlc = 0x%08x\n", devlc); 3456 langwell_phy_low_power(dev, 0);
3258 devlc &= ~LPM_PHCD;
3259 writel(devlc, &dev->op_regs->devlc);
3260 3457
3261 /* set device D0 power state */ 3458 /* set device D0 power state */
3262 pci_set_power_state(pdev, PCI_D0); 3459 pci_set_power_state(pdev, PCI_D0);
3263 3460
3461 /* enable SRAM caching if detected */
3462 if (dev->has_sram && !dev->got_sram)
3463 sram_init(dev);
3464
3465 /* allocate device dQH memory */
3466 size = dev->ep_max * sizeof(struct langwell_dqh);
3467 dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size);
3468 if (size < DQH_ALIGNMENT)
3469 size = DQH_ALIGNMENT;
3470 else if ((size % DQH_ALIGNMENT) != 0) {
3471 size += DQH_ALIGNMENT + 1;
3472 size &= ~(DQH_ALIGNMENT - 1);
3473 }
3474 dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size,
3475 &dev->ep_dqh_dma, GFP_KERNEL);
3476 if (!dev->ep_dqh) {
3477 dev_err(&dev->pdev->dev, "allocate dQH memory failed\n");
3478 return -ENOMEM;
3479 }
3480 dev->ep_dqh_size = size;
3481 dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size);
3482
3483 /* create dTD dma_pool resource */
3484 dev->dtd_pool = dma_pool_create("langwell_dtd",
3485 &dev->pdev->dev,
3486 sizeof(struct langwell_dtd),
3487 DTD_ALIGNMENT,
3488 DMA_BOUNDARY);
3489
3490 if (!dev->dtd_pool)
3491 return -ENOMEM;
3492
3264 /* restore PCI state */ 3493 /* restore PCI state */
3265 pci_restore_state(pdev); 3494 pci_restore_state(pdev);
3266 3495
3267 /* enable IRQ handler */ 3496 /* enable IRQ handler */
3268 if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED, driver_name, dev) 3497 if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED,
3269 != 0) { 3498 driver_name, dev) != 0) {
3270 ERROR(dev, "request interrupt %d failed\n", pdev->irq); 3499 dev_err(&dev->pdev->dev, "request interrupt %d failed\n",
3271 return -1; 3500 pdev->irq);
3501 return -EBUSY;
3272 } 3502 }
3273 dev->got_irq = 1; 3503 dev->got_irq = 1;
3274 3504
@@ -3290,7 +3520,7 @@ static int langwell_udc_resume(struct pci_dev *pdev)
3290 dev->ep0_state = WAIT_FOR_SETUP; 3520 dev->ep0_state = WAIT_FOR_SETUP;
3291 dev->ep0_dir = USB_DIR_OUT; 3521 dev->ep0_dir = USB_DIR_OUT;
3292 3522
3293 DBG(dev, "<--- %s()\n", __func__); 3523 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3294 return 0; 3524 return 0;
3295} 3525}
3296 3526
@@ -3301,15 +3531,15 @@ static void langwell_udc_shutdown(struct pci_dev *pdev)
3301 struct langwell_udc *dev = the_controller; 3531 struct langwell_udc *dev = the_controller;
3302 u32 usbmode; 3532 u32 usbmode;
3303 3533
3304 DBG(dev, "---> %s()\n", __func__); 3534 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3305 3535
3306 /* reset controller mode to IDLE */ 3536 /* reset controller mode to IDLE */
3307 usbmode = readl(&dev->op_regs->usbmode); 3537 usbmode = readl(&dev->op_regs->usbmode);
3308 DBG(dev, "usbmode = 0x%08x\n", usbmode); 3538 dev_dbg(&dev->pdev->dev, "usbmode = 0x%08x\n", usbmode);
3309 usbmode &= (~3 | MODE_IDLE); 3539 usbmode &= (~3 | MODE_IDLE);
3310 writel(usbmode, &dev->op_regs->usbmode); 3540 writel(usbmode, &dev->op_regs->usbmode);
3311 3541
3312 DBG(dev, "<--- %s()\n", __func__); 3542 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3313} 3543}
3314 3544
3315/*-------------------------------------------------------------------------*/ 3545/*-------------------------------------------------------------------------*/
@@ -3324,7 +3554,6 @@ static const struct pci_device_id pci_ids[] = { {
3324}, { /* end: all zeroes */ } 3554}, { /* end: all zeroes */ }
3325}; 3555};
3326 3556
3327
3328MODULE_DEVICE_TABLE(pci, pci_ids); 3557MODULE_DEVICE_TABLE(pci, pci_ids);
3329 3558
3330 3559
@@ -3343,12 +3572,6 @@ static struct pci_driver langwell_pci_driver = {
3343}; 3572};
3344 3573
3345 3574
3346MODULE_DESCRIPTION(DRIVER_DESC);
3347MODULE_AUTHOR("Xiaochen Shen <xiaochen.shen@intel.com>");
3348MODULE_VERSION(DRIVER_VERSION);
3349MODULE_LICENSE("GPL");
3350
3351
3352static int __init init(void) 3575static int __init init(void)
3353{ 3576{
3354#ifdef OTG_TRANSCEIVER 3577#ifdef OTG_TRANSCEIVER
@@ -3370,3 +3593,9 @@ static void __exit cleanup(void)
3370} 3593}
3371module_exit(cleanup); 3594module_exit(cleanup);
3372 3595
3596
3597MODULE_DESCRIPTION(DRIVER_DESC);
3598MODULE_AUTHOR("Xiaochen Shen <xiaochen.shen@intel.com>");
3599MODULE_VERSION(DRIVER_VERSION);
3600MODULE_LICENSE("GPL");
3601
diff --git a/drivers/usb/gadget/langwell_udc.h b/drivers/usb/gadget/langwell_udc.h
index 9719934e1c08..f1d9c1bb04f3 100644
--- a/drivers/usb/gadget/langwell_udc.h
+++ b/drivers/usb/gadget/langwell_udc.h
@@ -18,11 +18,7 @@
18 */ 18 */
19 19
20#include <linux/usb/langwell_udc.h> 20#include <linux/usb/langwell_udc.h>
21
22#if defined(CONFIG_USB_LANGWELL_OTG)
23#include <linux/usb/langwell_otg.h> 21#include <linux/usb/langwell_otg.h>
24#endif
25
26 22
27/*-------------------------------------------------------------------------*/ 23/*-------------------------------------------------------------------------*/
28 24
@@ -199,7 +195,9 @@ struct langwell_udc {
199 vbus_active:1, 195 vbus_active:1,
200 suspended:1, 196 suspended:1,
201 stopped:1, 197 stopped:1,
202 lpm:1; /* LPM capability */ 198 lpm:1, /* LPM capability */
199 has_sram:1, /* SRAM caching */
200 got_sram:1;
203 201
204 /* pci state used to access those endpoints */ 202 /* pci state used to access those endpoints */
205 struct pci_dev *pdev; 203 struct pci_dev *pdev;
@@ -224,5 +222,12 @@ struct langwell_udc {
224 222
225 /* make sure release() is done */ 223 /* make sure release() is done */
226 struct completion *done; 224 struct completion *done;
225
226 /* for private SRAM caching */
227 unsigned int sram_addr;
228 unsigned int sram_size;
229
230 /* device status data for get_status request */
231 u16 dev_status;
227}; 232};
228 233
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
deleted file mode 100644
index fded3fca793b..000000000000
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ /dev/null
@@ -1,2152 +0,0 @@
1/*
2 * linux/drivers/usb/gadget/lh7a40x_udc.c
3 * Sharp LH7A40x on-chip full speed USB device controllers
4 *
5 * Copyright (C) 2004 Mikko Lahteenmaki, Nordic ID
6 * Copyright (C) 2004 Bo Henriksen, Nordic ID
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <linux/platform_device.h>
25#include <linux/slab.h>
26
27#include "lh7a40x_udc.h"
28
29//#define DEBUG printk
30//#define DEBUG_EP0 printk
31//#define DEBUG_SETUP printk
32
33#ifndef DEBUG_EP0
34# define DEBUG_EP0(fmt,args...)
35#endif
36#ifndef DEBUG_SETUP
37# define DEBUG_SETUP(fmt,args...)
38#endif
39#ifndef DEBUG
40# define NO_STATES
41# define DEBUG(fmt,args...)
42#endif
43
44#define DRIVER_DESC "LH7A40x USB Device Controller"
45#define DRIVER_VERSION __DATE__
46
47#ifndef _BIT /* FIXME - what happended to _BIT in 2.6.7bk18? */
48#define _BIT(x) (1<<(x))
49#endif
50
51struct lh7a40x_udc *the_controller;
52
53static const char driver_name[] = "lh7a40x_udc";
54static const char driver_desc[] = DRIVER_DESC;
55static const char ep0name[] = "ep0-control";
56
57/*
58 Local definintions.
59*/
60
61#ifndef NO_STATES
62static char *state_names[] = {
63 "WAIT_FOR_SETUP",
64 "DATA_STATE_XMIT",
65 "DATA_STATE_NEED_ZLP",
66 "WAIT_FOR_OUT_STATUS",
67 "DATA_STATE_RECV"
68};
69#endif
70
71/*
72 Local declarations.
73*/
74static int lh7a40x_ep_enable(struct usb_ep *ep,
75 const struct usb_endpoint_descriptor *);
76static int lh7a40x_ep_disable(struct usb_ep *ep);
77static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep, gfp_t);
78static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *);
79static int lh7a40x_queue(struct usb_ep *ep, struct usb_request *, gfp_t);
80static int lh7a40x_dequeue(struct usb_ep *ep, struct usb_request *);
81static int lh7a40x_set_halt(struct usb_ep *ep, int);
82static int lh7a40x_fifo_status(struct usb_ep *ep);
83static void lh7a40x_fifo_flush(struct usb_ep *ep);
84static void lh7a40x_ep0_kick(struct lh7a40x_udc *dev, struct lh7a40x_ep *ep);
85static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr);
86
87static void done(struct lh7a40x_ep *ep, struct lh7a40x_request *req,
88 int status);
89static void pio_irq_enable(int bEndpointAddress);
90static void pio_irq_disable(int bEndpointAddress);
91static void stop_activity(struct lh7a40x_udc *dev,
92 struct usb_gadget_driver *driver);
93static void flush(struct lh7a40x_ep *ep);
94static void udc_enable(struct lh7a40x_udc *dev);
95static void udc_set_address(struct lh7a40x_udc *dev, unsigned char address);
96
97static struct usb_ep_ops lh7a40x_ep_ops = {
98 .enable = lh7a40x_ep_enable,
99 .disable = lh7a40x_ep_disable,
100
101 .alloc_request = lh7a40x_alloc_request,
102 .free_request = lh7a40x_free_request,
103
104 .queue = lh7a40x_queue,
105 .dequeue = lh7a40x_dequeue,
106
107 .set_halt = lh7a40x_set_halt,
108 .fifo_status = lh7a40x_fifo_status,
109 .fifo_flush = lh7a40x_fifo_flush,
110};
111
112/* Inline code */
113
114static __inline__ int write_packet(struct lh7a40x_ep *ep,
115 struct lh7a40x_request *req, int max)
116{
117 u8 *buf;
118 int length, count;
119 volatile u32 *fifo = (volatile u32 *)ep->fifo;
120
121 buf = req->req.buf + req->req.actual;
122 prefetch(buf);
123
124 length = req->req.length - req->req.actual;
125 length = min(length, max);
126 req->req.actual += length;
127
128 DEBUG("Write %d (max %d), fifo %p\n", length, max, fifo);
129
130 count = length;
131 while (count--) {
132 *fifo = *buf++;
133 }
134
135 return length;
136}
137
138static __inline__ void usb_set_index(u32 ep)
139{
140 *(volatile u32 *)io_p2v(USB_INDEX) = ep;
141}
142
143static __inline__ u32 usb_read(u32 port)
144{
145 return *(volatile u32 *)io_p2v(port);
146}
147
148static __inline__ void usb_write(u32 val, u32 port)
149{
150 *(volatile u32 *)io_p2v(port) = val;
151}
152
153static __inline__ void usb_set(u32 val, u32 port)
154{
155 volatile u32 *ioport = (volatile u32 *)io_p2v(port);
156 u32 after = (*ioport) | val;
157 *ioport = after;
158}
159
160static __inline__ void usb_clear(u32 val, u32 port)
161{
162 volatile u32 *ioport = (volatile u32 *)io_p2v(port);
163 u32 after = (*ioport) & ~val;
164 *ioport = after;
165}
166
167/*-------------------------------------------------------------------------*/
168
169#define GPIO_PORTC_DR (0x80000E08)
170#define GPIO_PORTC_DDR (0x80000E18)
171#define GPIO_PORTC_PDR (0x80000E70)
172
173/* get port C pin data register */
174#define get_portc_pdr(bit) ((usb_read(GPIO_PORTC_PDR) & _BIT(bit)) != 0)
175/* get port C data direction register */
176#define get_portc_ddr(bit) ((usb_read(GPIO_PORTC_DDR) & _BIT(bit)) != 0)
177/* set port C data register */
178#define set_portc_dr(bit, val) (val ? usb_set(_BIT(bit), GPIO_PORTC_DR) : usb_clear(_BIT(bit), GPIO_PORTC_DR))
179/* set port C data direction register */
180#define set_portc_ddr(bit, val) (val ? usb_set(_BIT(bit), GPIO_PORTC_DDR) : usb_clear(_BIT(bit), GPIO_PORTC_DDR))
181
182/*
183 * LPD7A404 GPIO's:
184 * Port C bit 1 = USB Port 1 Power Enable
185 * Port C bit 2 = USB Port 1 Data Carrier Detect
186 */
187#define is_usb_connected() get_portc_pdr(2)
188
189#ifdef CONFIG_USB_GADGET_DEBUG_FILES
190
191static const char proc_node_name[] = "driver/udc";
192
193static int
194udc_proc_read(char *page, char **start, off_t off, int count,
195 int *eof, void *_dev)
196{
197 char *buf = page;
198 struct lh7a40x_udc *dev = _dev;
199 char *next = buf;
200 unsigned size = count;
201 unsigned long flags;
202 int t;
203
204 if (off != 0)
205 return 0;
206
207 local_irq_save(flags);
208
209 /* basic device status */
210 t = scnprintf(next, size,
211 DRIVER_DESC "\n"
212 "%s version: %s\n"
213 "Gadget driver: %s\n"
214 "Host: %s\n\n",
215 driver_name, DRIVER_VERSION,
216 dev->driver ? dev->driver->driver.name : "(none)",
217 is_usb_connected()? "full speed" : "disconnected");
218 size -= t;
219 next += t;
220
221 t = scnprintf(next, size,
222 "GPIO:\n"
223 " Port C bit 1: %d, dir %d\n"
224 " Port C bit 2: %d, dir %d\n\n",
225 get_portc_pdr(1), get_portc_ddr(1),
226 get_portc_pdr(2), get_portc_ddr(2)
227 );
228 size -= t;
229 next += t;
230
231 t = scnprintf(next, size,
232 "DCP pullup: %d\n\n",
233 (usb_read(USB_PM) & PM_USB_DCP) != 0);
234 size -= t;
235 next += t;
236
237 local_irq_restore(flags);
238 *eof = 1;
239 return count - size;
240}
241
242#define create_proc_files() create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev)
243#define remove_proc_files() remove_proc_entry(proc_node_name, NULL)
244
245#else /* !CONFIG_USB_GADGET_DEBUG_FILES */
246
247#define create_proc_files() do {} while (0)
248#define remove_proc_files() do {} while (0)
249
250#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
251
252/*
253 * udc_disable - disable USB device controller
254 */
255static void udc_disable(struct lh7a40x_udc *dev)
256{
257 DEBUG("%s, %p\n", __func__, dev);
258
259 udc_set_address(dev, 0);
260
261 /* Disable interrupts */
262 usb_write(0, USB_IN_INT_EN);
263 usb_write(0, USB_OUT_INT_EN);
264 usb_write(0, USB_INT_EN);
265
266 /* Disable the USB */
267 usb_write(0, USB_PM);
268
269#ifdef CONFIG_ARCH_LH7A404
270 /* Disable USB power */
271 set_portc_dr(1, 0);
272#endif
273
274 /* if hardware supports it, disconnect from usb */
275 /* make_usb_disappear(); */
276
277 dev->ep0state = WAIT_FOR_SETUP;
278 dev->gadget.speed = USB_SPEED_UNKNOWN;
279 dev->usb_address = 0;
280}
281
282/*
283 * udc_reinit - initialize software state
284 */
285static void udc_reinit(struct lh7a40x_udc *dev)
286{
287 u32 i;
288
289 DEBUG("%s, %p\n", __func__, dev);
290
291 /* device/ep0 records init */
292 INIT_LIST_HEAD(&dev->gadget.ep_list);
293 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
294 dev->ep0state = WAIT_FOR_SETUP;
295
296 /* basic endpoint records init */
297 for (i = 0; i < UDC_MAX_ENDPOINTS; i++) {
298 struct lh7a40x_ep *ep = &dev->ep[i];
299
300 if (i != 0)
301 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
302
303 ep->desc = 0;
304 ep->stopped = 0;
305 INIT_LIST_HEAD(&ep->queue);
306 ep->pio_irqs = 0;
307 }
308
309 /* the rest was statically initialized, and is read-only */
310}
311
312#define BYTES2MAXP(x) (x / 8)
313#define MAXP2BYTES(x) (x * 8)
314
315/* until it's enabled, this UDC should be completely invisible
316 * to any USB host.
317 */
318static void udc_enable(struct lh7a40x_udc *dev)
319{
320 int ep;
321
322 DEBUG("%s, %p\n", __func__, dev);
323
324 dev->gadget.speed = USB_SPEED_UNKNOWN;
325
326#ifdef CONFIG_ARCH_LH7A404
327 /* Set Port C bit 1 & 2 as output */
328 set_portc_ddr(1, 1);
329 set_portc_ddr(2, 1);
330
331 /* Enable USB power */
332 set_portc_dr(1, 0);
333#endif
334
335 /*
336 * C.f Chapter 18.1.3.1 Initializing the USB
337 */
338
339 /* Disable the USB */
340 usb_clear(PM_USB_ENABLE, USB_PM);
341
342 /* Reset APB & I/O sides of the USB */
343 usb_set(USB_RESET_APB | USB_RESET_IO, USB_RESET);
344 mdelay(5);
345 usb_clear(USB_RESET_APB | USB_RESET_IO, USB_RESET);
346
347 /* Set MAXP values for each */
348 for (ep = 0; ep < UDC_MAX_ENDPOINTS; ep++) {
349 struct lh7a40x_ep *ep_reg = &dev->ep[ep];
350 u32 csr;
351
352 usb_set_index(ep);
353
354 switch (ep_reg->ep_type) {
355 case ep_bulk_in:
356 case ep_interrupt:
357 usb_clear(USB_IN_CSR2_USB_DMA_EN | USB_IN_CSR2_AUTO_SET,
358 ep_reg->csr2);
359 /* Fall through */
360 case ep_control:
361 usb_write(BYTES2MAXP(ep_maxpacket(ep_reg)),
362 USB_IN_MAXP);
363 break;
364 case ep_bulk_out:
365 usb_clear(USB_OUT_CSR2_USB_DMA_EN |
366 USB_OUT_CSR2_AUTO_CLR, ep_reg->csr2);
367 usb_write(BYTES2MAXP(ep_maxpacket(ep_reg)),
368 USB_OUT_MAXP);
369 break;
370 }
371
372 /* Read & Write CSR1, just in case */
373 csr = usb_read(ep_reg->csr1);
374 usb_write(csr, ep_reg->csr1);
375
376 flush(ep_reg);
377 }
378
379 /* Disable interrupts */
380 usb_write(0, USB_IN_INT_EN);
381 usb_write(0, USB_OUT_INT_EN);
382 usb_write(0, USB_INT_EN);
383
384 /* Enable interrupts */
385 usb_set(USB_IN_INT_EP0, USB_IN_INT_EN);
386 usb_set(USB_INT_RESET_INT | USB_INT_RESUME_INT, USB_INT_EN);
387 /* Dont enable rest of the interrupts */
388 /* usb_set(USB_IN_INT_EP3 | USB_IN_INT_EP1 | USB_IN_INT_EP0, USB_IN_INT_EN);
389 usb_set(USB_OUT_INT_EP2, USB_OUT_INT_EN); */
390
391 /* Enable SUSPEND */
392 usb_set(PM_ENABLE_SUSPEND, USB_PM);
393
394 /* Enable the USB */
395 usb_set(PM_USB_ENABLE, USB_PM);
396
397#ifdef CONFIG_ARCH_LH7A404
398 /* NOTE: DOES NOT WORK! */
399 /* Let host detect UDC:
400 * Software must write a 0 to the PMR:DCP_CTRL bit to turn this
401 * transistor on and pull the USBDP pin HIGH.
402 */
403 /* usb_clear(PM_USB_DCP, USB_PM);
404 usb_set(PM_USB_DCP, USB_PM); */
405#endif
406}
407
408/*
409 Register entry point for the peripheral controller driver.
410*/
411int usb_gadget_register_driver(struct usb_gadget_driver *driver)
412{
413 struct lh7a40x_udc *dev = the_controller;
414 int retval;
415
416 DEBUG("%s: %s\n", __func__, driver->driver.name);
417
418 if (!driver
419 || driver->speed != USB_SPEED_FULL
420 || !driver->bind
421 || !driver->disconnect
422 || !driver->setup)
423 return -EINVAL;
424 if (!dev)
425 return -ENODEV;
426 if (dev->driver)
427 return -EBUSY;
428
429 /* first hook up the driver ... */
430 dev->driver = driver;
431 dev->gadget.dev.driver = &driver->driver;
432
433 device_add(&dev->gadget.dev);
434 retval = driver->bind(&dev->gadget);
435 if (retval) {
436 printk(KERN_WARNING "%s: bind to driver %s --> error %d\n",
437 dev->gadget.name, driver->driver.name, retval);
438 device_del(&dev->gadget.dev);
439
440 dev->driver = 0;
441 dev->gadget.dev.driver = 0;
442 return retval;
443 }
444
445 /* ... then enable host detection and ep0; and we're ready
446 * for set_configuration as well as eventual disconnect.
447 * NOTE: this shouldn't power up until later.
448 */
449 printk(KERN_WARNING "%s: registered gadget driver '%s'\n",
450 dev->gadget.name, driver->driver.name);
451
452 udc_enable(dev);
453
454 return 0;
455}
456
457EXPORT_SYMBOL(usb_gadget_register_driver);
458
459/*
460 Unregister entry point for the peripheral controller driver.
461*/
462int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
463{
464 struct lh7a40x_udc *dev = the_controller;
465 unsigned long flags;
466
467 if (!dev)
468 return -ENODEV;
469 if (!driver || driver != dev->driver || !driver->unbind)
470 return -EINVAL;
471
472 spin_lock_irqsave(&dev->lock, flags);
473 dev->driver = 0;
474 stop_activity(dev, driver);
475 spin_unlock_irqrestore(&dev->lock, flags);
476
477 driver->unbind(&dev->gadget);
478 dev->gadget.dev.driver = NULL;
479 device_del(&dev->gadget.dev);
480
481 udc_disable(dev);
482
483 DEBUG("unregistered gadget driver '%s'\n", driver->driver.name);
484 return 0;
485}
486
487EXPORT_SYMBOL(usb_gadget_unregister_driver);
488
489/*-------------------------------------------------------------------------*/
490
491/** Write request to FIFO (max write == maxp size)
492 * Return: 0 = still running, 1 = completed, negative = errno
493 * NOTE: INDEX register must be set for EP
494 */
495static int write_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
496{
497 u32 max;
498 u32 csr;
499
500 max = le16_to_cpu(ep->desc->wMaxPacketSize);
501
502 csr = usb_read(ep->csr1);
503 DEBUG("CSR: %x %d\n", csr, csr & USB_IN_CSR1_FIFO_NOT_EMPTY);
504
505 if (!(csr & USB_IN_CSR1_FIFO_NOT_EMPTY)) {
506 unsigned count;
507 int is_last, is_short;
508
509 count = write_packet(ep, req, max);
510 usb_set(USB_IN_CSR1_IN_PKT_RDY, ep->csr1);
511
512 /* last packet is usually short (or a zlp) */
513 if (unlikely(count != max))
514 is_last = is_short = 1;
515 else {
516 if (likely(req->req.length != req->req.actual)
517 || req->req.zero)
518 is_last = 0;
519 else
520 is_last = 1;
521 /* interrupt/iso maxpacket may not fill the fifo */
522 is_short = unlikely(max < ep_maxpacket(ep));
523 }
524
525 DEBUG("%s: wrote %s %d bytes%s%s %d left %p\n", __func__,
526 ep->ep.name, count,
527 is_last ? "/L" : "", is_short ? "/S" : "",
528 req->req.length - req->req.actual, req);
529
530 /* requests complete when all IN data is in the FIFO */
531 if (is_last) {
532 done(ep, req, 0);
533 if (list_empty(&ep->queue)) {
534 pio_irq_disable(ep_index(ep));
535 }
536 return 1;
537 }
538 } else {
539 DEBUG("Hmm.. %d ep FIFO is not empty!\n", ep_index(ep));
540 }
541
542 return 0;
543}
544
545/** Read to request from FIFO (max read == bytes in fifo)
546 * Return: 0 = still running, 1 = completed, negative = errno
547 * NOTE: INDEX register must be set for EP
548 */
549static int read_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
550{
551 u32 csr;
552 u8 *buf;
553 unsigned bufferspace, count, is_short;
554 volatile u32 *fifo = (volatile u32 *)ep->fifo;
555
556 /* make sure there's a packet in the FIFO. */
557 csr = usb_read(ep->csr1);
558 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY)) {
559 DEBUG("%s: Packet NOT ready!\n", __func__);
560 return -EINVAL;
561 }
562
563 buf = req->req.buf + req->req.actual;
564 prefetchw(buf);
565 bufferspace = req->req.length - req->req.actual;
566
567 /* read all bytes from this packet */
568 count = usb_read(USB_OUT_FIFO_WC1);
569 req->req.actual += min(count, bufferspace);
570
571 is_short = (count < ep->ep.maxpacket);
572 DEBUG("read %s %02x, %d bytes%s req %p %d/%d\n",
573 ep->ep.name, csr, count,
574 is_short ? "/S" : "", req, req->req.actual, req->req.length);
575
576 while (likely(count-- != 0)) {
577 u8 byte = (u8) (*fifo & 0xff);
578
579 if (unlikely(bufferspace == 0)) {
580 /* this happens when the driver's buffer
581 * is smaller than what the host sent.
582 * discard the extra data.
583 */
584 if (req->req.status != -EOVERFLOW)
585 printk(KERN_WARNING "%s overflow %d\n",
586 ep->ep.name, count);
587 req->req.status = -EOVERFLOW;
588 } else {
589 *buf++ = byte;
590 bufferspace--;
591 }
592 }
593
594 usb_clear(USB_OUT_CSR1_OUT_PKT_RDY, ep->csr1);
595
596 /* completion */
597 if (is_short || req->req.actual == req->req.length) {
598 done(ep, req, 0);
599 usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1);
600
601 if (list_empty(&ep->queue))
602 pio_irq_disable(ep_index(ep));
603 return 1;
604 }
605
606 /* finished that packet. the next one may be waiting... */
607 return 0;
608}
609
610/*
611 * done - retire a request; caller blocked irqs
612 * INDEX register is preserved to keep same
613 */
614static void done(struct lh7a40x_ep *ep, struct lh7a40x_request *req, int status)
615{
616 unsigned int stopped = ep->stopped;
617 u32 index;
618
619 DEBUG("%s, %p\n", __func__, ep);
620 list_del_init(&req->queue);
621
622 if (likely(req->req.status == -EINPROGRESS))
623 req->req.status = status;
624 else
625 status = req->req.status;
626
627 if (status && status != -ESHUTDOWN)
628 DEBUG("complete %s req %p stat %d len %u/%u\n",
629 ep->ep.name, &req->req, status,
630 req->req.actual, req->req.length);
631
632 /* don't modify queue heads during completion callback */
633 ep->stopped = 1;
634 /* Read current index (completion may modify it) */
635 index = usb_read(USB_INDEX);
636
637 spin_unlock(&ep->dev->lock);
638 req->req.complete(&ep->ep, &req->req);
639 spin_lock(&ep->dev->lock);
640
641 /* Restore index */
642 usb_set_index(index);
643 ep->stopped = stopped;
644}
645
646/** Enable EP interrupt */
647static void pio_irq_enable(int ep)
648{
649 DEBUG("%s: %d\n", __func__, ep);
650
651 switch (ep) {
652 case 1:
653 usb_set(USB_IN_INT_EP1, USB_IN_INT_EN);
654 break;
655 case 2:
656 usb_set(USB_OUT_INT_EP2, USB_OUT_INT_EN);
657 break;
658 case 3:
659 usb_set(USB_IN_INT_EP3, USB_IN_INT_EN);
660 break;
661 default:
662 DEBUG("Unknown endpoint: %d\n", ep);
663 break;
664 }
665}
666
667/** Disable EP interrupt */
668static void pio_irq_disable(int ep)
669{
670 DEBUG("%s: %d\n", __func__, ep);
671
672 switch (ep) {
673 case 1:
674 usb_clear(USB_IN_INT_EP1, USB_IN_INT_EN);
675 break;
676 case 2:
677 usb_clear(USB_OUT_INT_EP2, USB_OUT_INT_EN);
678 break;
679 case 3:
680 usb_clear(USB_IN_INT_EP3, USB_IN_INT_EN);
681 break;
682 default:
683 DEBUG("Unknown endpoint: %d\n", ep);
684 break;
685 }
686}
687
688/*
689 * nuke - dequeue ALL requests
690 */
691void nuke(struct lh7a40x_ep *ep, int status)
692{
693 struct lh7a40x_request *req;
694
695 DEBUG("%s, %p\n", __func__, ep);
696
697 /* Flush FIFO */
698 flush(ep);
699
700 /* called with irqs blocked */
701 while (!list_empty(&ep->queue)) {
702 req = list_entry(ep->queue.next, struct lh7a40x_request, queue);
703 done(ep, req, status);
704 }
705
706 /* Disable IRQ if EP is enabled (has descriptor) */
707 if (ep->desc)
708 pio_irq_disable(ep_index(ep));
709}
710
711/*
712void nuke_all(struct lh7a40x_udc *dev)
713{
714 int n;
715 for(n=0; n<UDC_MAX_ENDPOINTS; n++) {
716 struct lh7a40x_ep *ep = &dev->ep[n];
717 usb_set_index(n);
718 nuke(ep, 0);
719 }
720}*/
721
722/*
723static void flush_all(struct lh7a40x_udc *dev)
724{
725 int n;
726 for (n = 0; n < UDC_MAX_ENDPOINTS; n++)
727 {
728 struct lh7a40x_ep *ep = &dev->ep[n];
729 flush(ep);
730 }
731}
732*/
733
734/** Flush EP
735 * NOTE: INDEX register must be set before this call
736 */
737static void flush(struct lh7a40x_ep *ep)
738{
739 DEBUG("%s, %p\n", __func__, ep);
740
741 switch (ep->ep_type) {
742 case ep_control:
743 /* check, by implication c.f. 15.1.2.11 */
744 break;
745
746 case ep_bulk_in:
747 case ep_interrupt:
748 /* if(csr & USB_IN_CSR1_IN_PKT_RDY) */
749 usb_set(USB_IN_CSR1_FIFO_FLUSH, ep->csr1);
750 break;
751
752 case ep_bulk_out:
753 /* if(csr & USB_OUT_CSR1_OUT_PKT_RDY) */
754 usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1);
755 break;
756 }
757}
758
759/**
760 * lh7a40x_in_epn - handle IN interrupt
761 */
762static void lh7a40x_in_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
763{
764 u32 csr;
765 struct lh7a40x_ep *ep = &dev->ep[ep_idx];
766 struct lh7a40x_request *req;
767
768 usb_set_index(ep_idx);
769
770 csr = usb_read(ep->csr1);
771 DEBUG("%s: %d, csr %x\n", __func__, ep_idx, csr);
772
773 if (csr & USB_IN_CSR1_SENT_STALL) {
774 DEBUG("USB_IN_CSR1_SENT_STALL\n");
775 usb_set(USB_IN_CSR1_SENT_STALL /*|USB_IN_CSR1_SEND_STALL */ ,
776 ep->csr1);
777 return;
778 }
779
780 if (!ep->desc) {
781 DEBUG("%s: NO EP DESC\n", __func__);
782 return;
783 }
784
785 if (list_empty(&ep->queue))
786 req = 0;
787 else
788 req = list_entry(ep->queue.next, struct lh7a40x_request, queue);
789
790 DEBUG("req: %p\n", req);
791
792 if (!req)
793 return;
794
795 write_fifo(ep, req);
796}
797
798/* ********************************************************************************************* */
799/* Bulk OUT (recv)
800 */
801
802static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
803{
804 struct lh7a40x_ep *ep = &dev->ep[ep_idx];
805 struct lh7a40x_request *req;
806
807 DEBUG("%s: %d\n", __func__, ep_idx);
808
809 usb_set_index(ep_idx);
810
811 if (ep->desc) {
812 u32 csr;
813 csr = usb_read(ep->csr1);
814
815 while ((csr =
816 usb_read(ep->
817 csr1)) & (USB_OUT_CSR1_OUT_PKT_RDY |
818 USB_OUT_CSR1_SENT_STALL)) {
819 DEBUG("%s: %x\n", __func__, csr);
820
821 if (csr & USB_OUT_CSR1_SENT_STALL) {
822 DEBUG("%s: stall sent, flush fifo\n",
823 __func__);
824 /* usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1); */
825 flush(ep);
826 } else if (csr & USB_OUT_CSR1_OUT_PKT_RDY) {
827 if (list_empty(&ep->queue))
828 req = 0;
829 else
830 req =
831 list_entry(ep->queue.next,
832 struct lh7a40x_request,
833 queue);
834
835 if (!req) {
836 printk(KERN_WARNING
837 "%s: NULL REQ %d\n",
838 __func__, ep_idx);
839 flush(ep);
840 break;
841 } else {
842 read_fifo(ep, req);
843 }
844 }
845
846 }
847
848 } else {
849 /* Throw packet away.. */
850 printk(KERN_WARNING "%s: No descriptor?!?\n", __func__);
851 flush(ep);
852 }
853}
854
855static void stop_activity(struct lh7a40x_udc *dev,
856 struct usb_gadget_driver *driver)
857{
858 int i;
859
860 /* don't disconnect drivers more than once */
861 if (dev->gadget.speed == USB_SPEED_UNKNOWN)
862 driver = 0;
863 dev->gadget.speed = USB_SPEED_UNKNOWN;
864
865 /* prevent new request submissions, kill any outstanding requests */
866 for (i = 0; i < UDC_MAX_ENDPOINTS; i++) {
867 struct lh7a40x_ep *ep = &dev->ep[i];
868 ep->stopped = 1;
869
870 usb_set_index(i);
871 nuke(ep, -ESHUTDOWN);
872 }
873
874 /* report disconnect; the driver is already quiesced */
875 if (driver) {
876 spin_unlock(&dev->lock);
877 driver->disconnect(&dev->gadget);
878 spin_lock(&dev->lock);
879 }
880
881 /* re-init driver-visible data structures */
882 udc_reinit(dev);
883}
884
885/** Handle USB RESET interrupt
886 */
887static void lh7a40x_reset_intr(struct lh7a40x_udc *dev)
888{
889#if 0 /* def CONFIG_ARCH_LH7A404 */
890 /* Does not work always... */
891
892 DEBUG("%s: %d\n", __func__, dev->usb_address);
893
894 if (!dev->usb_address) {
895 /*usb_set(USB_RESET_IO, USB_RESET);
896 mdelay(5);
897 usb_clear(USB_RESET_IO, USB_RESET); */
898 return;
899 }
900 /* Put the USB controller into reset. */
901 usb_set(USB_RESET_IO, USB_RESET);
902
903 /* Set Device ID to 0 */
904 udc_set_address(dev, 0);
905
906 /* Let PLL2 settle down */
907 mdelay(5);
908
909 /* Release the USB controller from reset */
910 usb_clear(USB_RESET_IO, USB_RESET);
911
912 /* Re-enable UDC */
913 udc_enable(dev);
914
915#endif
916 dev->gadget.speed = USB_SPEED_FULL;
917}
918
919/*
920 * lh7a40x usb client interrupt handler.
921 */
922static irqreturn_t lh7a40x_udc_irq(int irq, void *_dev)
923{
924 struct lh7a40x_udc *dev = _dev;
925
926 DEBUG("\n\n");
927
928 spin_lock(&dev->lock);
929
930 for (;;) {
931 u32 intr_in = usb_read(USB_IN_INT);
932 u32 intr_out = usb_read(USB_OUT_INT);
933 u32 intr_int = usb_read(USB_INT);
934
935 /* Test also against enable bits.. (lh7a40x errata).. Sigh.. */
936 u32 in_en = usb_read(USB_IN_INT_EN);
937 u32 out_en = usb_read(USB_OUT_INT_EN);
938
939 if (!intr_out && !intr_in && !intr_int)
940 break;
941
942 DEBUG("%s (on state %s)\n", __func__,
943 state_names[dev->ep0state]);
944 DEBUG("intr_out = %x\n", intr_out);
945 DEBUG("intr_in = %x\n", intr_in);
946 DEBUG("intr_int = %x\n", intr_int);
947
948 if (intr_in) {
949 usb_write(intr_in, USB_IN_INT);
950
951 if ((intr_in & USB_IN_INT_EP1)
952 && (in_en & USB_IN_INT_EP1)) {
953 DEBUG("USB_IN_INT_EP1\n");
954 lh7a40x_in_epn(dev, 1, intr_in);
955 }
956 if ((intr_in & USB_IN_INT_EP3)
957 && (in_en & USB_IN_INT_EP3)) {
958 DEBUG("USB_IN_INT_EP3\n");
959 lh7a40x_in_epn(dev, 3, intr_in);
960 }
961 if (intr_in & USB_IN_INT_EP0) {
962 DEBUG("USB_IN_INT_EP0 (control)\n");
963 lh7a40x_handle_ep0(dev, intr_in);
964 }
965 }
966
967 if (intr_out) {
968 usb_write(intr_out, USB_OUT_INT);
969
970 if ((intr_out & USB_OUT_INT_EP2)
971 && (out_en & USB_OUT_INT_EP2)) {
972 DEBUG("USB_OUT_INT_EP2\n");
973 lh7a40x_out_epn(dev, 2, intr_out);
974 }
975 }
976
977 if (intr_int) {
978 usb_write(intr_int, USB_INT);
979
980 if (intr_int & USB_INT_RESET_INT) {
981 lh7a40x_reset_intr(dev);
982 }
983
984 if (intr_int & USB_INT_RESUME_INT) {
985 DEBUG("USB resume\n");
986
987 if (dev->gadget.speed != USB_SPEED_UNKNOWN
988 && dev->driver
989 && dev->driver->resume
990 && is_usb_connected()) {
991 dev->driver->resume(&dev->gadget);
992 }
993 }
994
995 if (intr_int & USB_INT_SUSPEND_INT) {
996 DEBUG("USB suspend%s\n",
997 is_usb_connected()? "" : "+disconnect");
998 if (!is_usb_connected()) {
999 stop_activity(dev, dev->driver);
1000 } else if (dev->gadget.speed !=
1001 USB_SPEED_UNKNOWN && dev->driver
1002 && dev->driver->suspend) {
1003 dev->driver->suspend(&dev->gadget);
1004 }
1005 }
1006
1007 }
1008 }
1009
1010 spin_unlock(&dev->lock);
1011
1012 return IRQ_HANDLED;
1013}
1014
1015static int lh7a40x_ep_enable(struct usb_ep *_ep,
1016 const struct usb_endpoint_descriptor *desc)
1017{
1018 struct lh7a40x_ep *ep;
1019 struct lh7a40x_udc *dev;
1020 unsigned long flags;
1021
1022 DEBUG("%s, %p\n", __func__, _ep);
1023
1024 ep = container_of(_ep, struct lh7a40x_ep, ep);
1025 if (!_ep || !desc || ep->desc || _ep->name == ep0name
1026 || desc->bDescriptorType != USB_DT_ENDPOINT
1027 || ep->bEndpointAddress != desc->bEndpointAddress
1028 || ep_maxpacket(ep) < le16_to_cpu(desc->wMaxPacketSize)) {
1029 DEBUG("%s, bad ep or descriptor\n", __func__);
1030 return -EINVAL;
1031 }
1032
1033 /* xfer types must match, except that interrupt ~= bulk */
1034 if (ep->bmAttributes != desc->bmAttributes
1035 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
1036 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
1037 DEBUG("%s, %s type mismatch\n", __func__, _ep->name);
1038 return -EINVAL;
1039 }
1040
1041 /* hardware _could_ do smaller, but driver doesn't */
1042 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
1043 && le16_to_cpu(desc->wMaxPacketSize) != ep_maxpacket(ep))
1044 || !desc->wMaxPacketSize) {
1045 DEBUG("%s, bad %s maxpacket\n", __func__, _ep->name);
1046 return -ERANGE;
1047 }
1048
1049 dev = ep->dev;
1050 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
1051 DEBUG("%s, bogus device state\n", __func__);
1052 return -ESHUTDOWN;
1053 }
1054
1055 spin_lock_irqsave(&ep->dev->lock, flags);
1056
1057 ep->stopped = 0;
1058 ep->desc = desc;
1059 ep->pio_irqs = 0;
1060 ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
1061
1062 spin_unlock_irqrestore(&ep->dev->lock, flags);
1063
1064 /* Reset halt state (does flush) */
1065 lh7a40x_set_halt(_ep, 0);
1066
1067 DEBUG("%s: enabled %s\n", __func__, _ep->name);
1068 return 0;
1069}
1070
1071/** Disable EP
1072 * NOTE: Sets INDEX register
1073 */
1074static int lh7a40x_ep_disable(struct usb_ep *_ep)
1075{
1076 struct lh7a40x_ep *ep;
1077 unsigned long flags;
1078
1079 DEBUG("%s, %p\n", __func__, _ep);
1080
1081 ep = container_of(_ep, struct lh7a40x_ep, ep);
1082 if (!_ep || !ep->desc) {
1083 DEBUG("%s, %s not enabled\n", __func__,
1084 _ep ? ep->ep.name : NULL);
1085 return -EINVAL;
1086 }
1087
1088 spin_lock_irqsave(&ep->dev->lock, flags);
1089
1090 usb_set_index(ep_index(ep));
1091
1092 /* Nuke all pending requests (does flush) */
1093 nuke(ep, -ESHUTDOWN);
1094
1095 /* Disable ep IRQ */
1096 pio_irq_disable(ep_index(ep));
1097
1098 ep->desc = 0;
1099 ep->stopped = 1;
1100
1101 spin_unlock_irqrestore(&ep->dev->lock, flags);
1102
1103 DEBUG("%s: disabled %s\n", __func__, _ep->name);
1104 return 0;
1105}
1106
1107static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep,
1108 gfp_t gfp_flags)
1109{
1110 struct lh7a40x_request *req;
1111
1112 DEBUG("%s, %p\n", __func__, ep);
1113
1114 req = kzalloc(sizeof(*req), gfp_flags);
1115 if (!req)
1116 return 0;
1117
1118 INIT_LIST_HEAD(&req->queue);
1119
1120 return &req->req;
1121}
1122
1123static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *_req)
1124{
1125 struct lh7a40x_request *req;
1126
1127 DEBUG("%s, %p\n", __func__, ep);
1128
1129 req = container_of(_req, struct lh7a40x_request, req);
1130 WARN_ON(!list_empty(&req->queue));
1131 kfree(req);
1132}
1133
1134/** Queue one request
1135 * Kickstart transfer if needed
1136 * NOTE: Sets INDEX register
1137 */
1138static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req,
1139 gfp_t gfp_flags)
1140{
1141 struct lh7a40x_request *req;
1142 struct lh7a40x_ep *ep;
1143 struct lh7a40x_udc *dev;
1144 unsigned long flags;
1145
1146 DEBUG("\n\n\n%s, %p\n", __func__, _ep);
1147
1148 req = container_of(_req, struct lh7a40x_request, req);
1149 if (unlikely
1150 (!_req || !_req->complete || !_req->buf
1151 || !list_empty(&req->queue))) {
1152 DEBUG("%s, bad params\n", __func__);
1153 return -EINVAL;
1154 }
1155
1156 ep = container_of(_ep, struct lh7a40x_ep, ep);
1157 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1158 DEBUG("%s, bad ep\n", __func__);
1159 return -EINVAL;
1160 }
1161
1162 dev = ep->dev;
1163 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
1164 DEBUG("%s, bogus device state %p\n", __func__, dev->driver);
1165 return -ESHUTDOWN;
1166 }
1167
1168 DEBUG("%s queue req %p, len %d buf %p\n", _ep->name, _req, _req->length,
1169 _req->buf);
1170
1171 spin_lock_irqsave(&dev->lock, flags);
1172
1173 _req->status = -EINPROGRESS;
1174 _req->actual = 0;
1175
1176 /* kickstart this i/o queue? */
1177 DEBUG("Add to %d Q %d %d\n", ep_index(ep), list_empty(&ep->queue),
1178 ep->stopped);
1179 if (list_empty(&ep->queue) && likely(!ep->stopped)) {
1180 u32 csr;
1181
1182 if (unlikely(ep_index(ep) == 0)) {
1183 /* EP0 */
1184 list_add_tail(&req->queue, &ep->queue);
1185 lh7a40x_ep0_kick(dev, ep);
1186 req = 0;
1187 } else if (ep_is_in(ep)) {
1188 /* EP1 & EP3 */
1189 usb_set_index(ep_index(ep));
1190 csr = usb_read(ep->csr1);
1191 pio_irq_enable(ep_index(ep));
1192 if ((csr & USB_IN_CSR1_FIFO_NOT_EMPTY) == 0) {
1193 if (write_fifo(ep, req) == 1)
1194 req = 0;
1195 }
1196 } else {
1197 /* EP2 */
1198 usb_set_index(ep_index(ep));
1199 csr = usb_read(ep->csr1);
1200 pio_irq_enable(ep_index(ep));
1201 if (!(csr & USB_OUT_CSR1_FIFO_FULL)) {
1202 if (read_fifo(ep, req) == 1)
1203 req = 0;
1204 }
1205 }
1206 }
1207
1208 /* pio or dma irq handler advances the queue. */
1209 if (likely(req != 0))
1210 list_add_tail(&req->queue, &ep->queue);
1211
1212 spin_unlock_irqrestore(&dev->lock, flags);
1213
1214 return 0;
1215}
1216
1217/* dequeue JUST ONE request */
1218static int lh7a40x_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1219{
1220 struct lh7a40x_ep *ep;
1221 struct lh7a40x_request *req;
1222 unsigned long flags;
1223
1224 DEBUG("%s, %p\n", __func__, _ep);
1225
1226 ep = container_of(_ep, struct lh7a40x_ep, ep);
1227 if (!_ep || ep->ep.name == ep0name)
1228 return -EINVAL;
1229
1230 spin_lock_irqsave(&ep->dev->lock, flags);
1231
1232 /* make sure it's actually queued on this endpoint */
1233 list_for_each_entry(req, &ep->queue, queue) {
1234 if (&req->req == _req)
1235 break;
1236 }
1237 if (&req->req != _req) {
1238 spin_unlock_irqrestore(&ep->dev->lock, flags);
1239 return -EINVAL;
1240 }
1241
1242 done(ep, req, -ECONNRESET);
1243
1244 spin_unlock_irqrestore(&ep->dev->lock, flags);
1245 return 0;
1246}
1247
1248/** Halt specific EP
1249 * Return 0 if success
1250 * NOTE: Sets INDEX register to EP !
1251 */
1252static int lh7a40x_set_halt(struct usb_ep *_ep, int value)
1253{
1254 struct lh7a40x_ep *ep;
1255 unsigned long flags;
1256
1257 ep = container_of(_ep, struct lh7a40x_ep, ep);
1258 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1259 DEBUG("%s, bad ep\n", __func__);
1260 return -EINVAL;
1261 }
1262
1263 usb_set_index(ep_index(ep));
1264
1265 DEBUG("%s, ep %d, val %d\n", __func__, ep_index(ep), value);
1266
1267 spin_lock_irqsave(&ep->dev->lock, flags);
1268
1269 if (ep_index(ep) == 0) {
1270 /* EP0 */
1271 usb_set(EP0_SEND_STALL, ep->csr1);
1272 } else if (ep_is_in(ep)) {
1273 u32 csr = usb_read(ep->csr1);
1274 if (value && ((csr & USB_IN_CSR1_FIFO_NOT_EMPTY)
1275 || !list_empty(&ep->queue))) {
1276 /*
1277 * Attempts to halt IN endpoints will fail (returning -EAGAIN)
1278 * if any transfer requests are still queued, or if the controller
1279 * FIFO still holds bytes that the host hasn't collected.
1280 */
1281 spin_unlock_irqrestore(&ep->dev->lock, flags);
1282 DEBUG
1283 ("Attempt to halt IN endpoint failed (returning -EAGAIN) %d %d\n",
1284 (csr & USB_IN_CSR1_FIFO_NOT_EMPTY),
1285 !list_empty(&ep->queue));
1286 return -EAGAIN;
1287 }
1288 flush(ep);
1289 if (value)
1290 usb_set(USB_IN_CSR1_SEND_STALL, ep->csr1);
1291 else {
1292 usb_clear(USB_IN_CSR1_SEND_STALL, ep->csr1);
1293 usb_set(USB_IN_CSR1_CLR_DATA_TOGGLE, ep->csr1);
1294 }
1295
1296 } else {
1297
1298 flush(ep);
1299 if (value)
1300 usb_set(USB_OUT_CSR1_SEND_STALL, ep->csr1);
1301 else {
1302 usb_clear(USB_OUT_CSR1_SEND_STALL, ep->csr1);
1303 usb_set(USB_OUT_CSR1_CLR_DATA_REG, ep->csr1);
1304 }
1305 }
1306
1307 if (value) {
1308 ep->stopped = 1;
1309 } else {
1310 ep->stopped = 0;
1311 }
1312
1313 spin_unlock_irqrestore(&ep->dev->lock, flags);
1314
1315 DEBUG("%s %s halted\n", _ep->name, value == 0 ? "NOT" : "IS");
1316
1317 return 0;
1318}
1319
1320/** Return bytes in EP FIFO
1321 * NOTE: Sets INDEX register to EP
1322 */
1323static int lh7a40x_fifo_status(struct usb_ep *_ep)
1324{
1325 u32 csr;
1326 int count = 0;
1327 struct lh7a40x_ep *ep;
1328
1329 ep = container_of(_ep, struct lh7a40x_ep, ep);
1330 if (!_ep) {
1331 DEBUG("%s, bad ep\n", __func__);
1332 return -ENODEV;
1333 }
1334
1335 DEBUG("%s, %d\n", __func__, ep_index(ep));
1336
1337 /* LPD can't report unclaimed bytes from IN fifos */
1338 if (ep_is_in(ep))
1339 return -EOPNOTSUPP;
1340
1341 usb_set_index(ep_index(ep));
1342
1343 csr = usb_read(ep->csr1);
1344 if (ep->dev->gadget.speed != USB_SPEED_UNKNOWN ||
1345 csr & USB_OUT_CSR1_OUT_PKT_RDY) {
1346 count = usb_read(USB_OUT_FIFO_WC1);
1347 }
1348
1349 return count;
1350}
1351
1352/** Flush EP FIFO
1353 * NOTE: Sets INDEX register to EP
1354 */
1355static void lh7a40x_fifo_flush(struct usb_ep *_ep)
1356{
1357 struct lh7a40x_ep *ep;
1358
1359 ep = container_of(_ep, struct lh7a40x_ep, ep);
1360 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1361 DEBUG("%s, bad ep\n", __func__);
1362 return;
1363 }
1364
1365 usb_set_index(ep_index(ep));
1366 flush(ep);
1367}
1368
1369/****************************************************************/
1370/* End Point 0 related functions */
1371/****************************************************************/
1372
1373/* return: 0 = still running, 1 = completed, negative = errno */
1374static int write_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1375{
1376 u32 max;
1377 unsigned count;
1378 int is_last;
1379
1380 max = ep_maxpacket(ep);
1381
1382 DEBUG_EP0("%s\n", __func__);
1383
1384 count = write_packet(ep, req, max);
1385
1386 /* last packet is usually short (or a zlp) */
1387 if (unlikely(count != max))
1388 is_last = 1;
1389 else {
1390 if (likely(req->req.length != req->req.actual) || req->req.zero)
1391 is_last = 0;
1392 else
1393 is_last = 1;
1394 }
1395
1396 DEBUG_EP0("%s: wrote %s %d bytes%s %d left %p\n", __func__,
1397 ep->ep.name, count,
1398 is_last ? "/L" : "", req->req.length - req->req.actual, req);
1399
1400 /* requests complete when all IN data is in the FIFO */
1401 if (is_last) {
1402 done(ep, req, 0);
1403 return 1;
1404 }
1405
1406 return 0;
1407}
1408
1409static __inline__ int lh7a40x_fifo_read(struct lh7a40x_ep *ep,
1410 unsigned char *cp, int max)
1411{
1412 int bytes;
1413 int count = usb_read(USB_OUT_FIFO_WC1);
1414 volatile u32 *fifo = (volatile u32 *)ep->fifo;
1415
1416 if (count > max)
1417 count = max;
1418 bytes = count;
1419 while (count--)
1420 *cp++ = *fifo & 0xFF;
1421 return bytes;
1422}
1423
1424static __inline__ void lh7a40x_fifo_write(struct lh7a40x_ep *ep,
1425 unsigned char *cp, int count)
1426{
1427 volatile u32 *fifo = (volatile u32 *)ep->fifo;
1428 DEBUG_EP0("fifo_write: %d %d\n", ep_index(ep), count);
1429 while (count--)
1430 *fifo = *cp++;
1431}
1432
1433static int read_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1434{
1435 u32 csr;
1436 u8 *buf;
1437 unsigned bufferspace, count, is_short;
1438 volatile u32 *fifo = (volatile u32 *)ep->fifo;
1439
1440 DEBUG_EP0("%s\n", __func__);
1441
1442 csr = usb_read(USB_EP0_CSR);
1443 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY))
1444 return 0;
1445
1446 buf = req->req.buf + req->req.actual;
1447 prefetchw(buf);
1448 bufferspace = req->req.length - req->req.actual;
1449
1450 /* read all bytes from this packet */
1451 if (likely(csr & EP0_OUT_PKT_RDY)) {
1452 count = usb_read(USB_OUT_FIFO_WC1);
1453 req->req.actual += min(count, bufferspace);
1454 } else /* zlp */
1455 count = 0;
1456
1457 is_short = (count < ep->ep.maxpacket);
1458 DEBUG_EP0("read %s %02x, %d bytes%s req %p %d/%d\n",
1459 ep->ep.name, csr, count,
1460 is_short ? "/S" : "", req, req->req.actual, req->req.length);
1461
1462 while (likely(count-- != 0)) {
1463 u8 byte = (u8) (*fifo & 0xff);
1464
1465 if (unlikely(bufferspace == 0)) {
1466 /* this happens when the driver's buffer
1467 * is smaller than what the host sent.
1468 * discard the extra data.
1469 */
1470 if (req->req.status != -EOVERFLOW)
1471 DEBUG_EP0("%s overflow %d\n", ep->ep.name,
1472 count);
1473 req->req.status = -EOVERFLOW;
1474 } else {
1475 *buf++ = byte;
1476 bufferspace--;
1477 }
1478 }
1479
1480 /* completion */
1481 if (is_short || req->req.actual == req->req.length) {
1482 done(ep, req, 0);
1483 return 1;
1484 }
1485
1486 /* finished that packet. the next one may be waiting... */
1487 return 0;
1488}
1489
1490/**
1491 * udc_set_address - set the USB address for this device
1492 * @address:
1493 *
1494 * Called from control endpoint function after it decodes a set address setup packet.
1495 */
1496static void udc_set_address(struct lh7a40x_udc *dev, unsigned char address)
1497{
1498 DEBUG_EP0("%s: %d\n", __func__, address);
1499 /* c.f. 15.1.2.2 Table 15-4 address will be used after DATA_END is set */
1500 dev->usb_address = address;
1501 usb_set((address & USB_FA_FUNCTION_ADDR), USB_FA);
1502 usb_set(USB_FA_ADDR_UPDATE | (address & USB_FA_FUNCTION_ADDR), USB_FA);
1503 /* usb_read(USB_FA); */
1504}
1505
1506/*
1507 * DATA_STATE_RECV (OUT_PKT_RDY)
1508 * - if error
1509 * set EP0_CLR_OUT | EP0_DATA_END | EP0_SEND_STALL bits
1510 * - else
1511 * set EP0_CLR_OUT bit
1512 if last set EP0_DATA_END bit
1513 */
1514static void lh7a40x_ep0_out(struct lh7a40x_udc *dev, u32 csr)
1515{
1516 struct lh7a40x_request *req;
1517 struct lh7a40x_ep *ep = &dev->ep[0];
1518 int ret;
1519
1520 DEBUG_EP0("%s: %x\n", __func__, csr);
1521
1522 if (list_empty(&ep->queue))
1523 req = 0;
1524 else
1525 req = list_entry(ep->queue.next, struct lh7a40x_request, queue);
1526
1527 if (req) {
1528
1529 if (req->req.length == 0) {
1530 DEBUG_EP0("ZERO LENGTH OUT!\n");
1531 usb_set((EP0_CLR_OUT | EP0_DATA_END), USB_EP0_CSR);
1532 dev->ep0state = WAIT_FOR_SETUP;
1533 return;
1534 }
1535 ret = read_fifo_ep0(ep, req);
1536 if (ret) {
1537 /* Done! */
1538 DEBUG_EP0("%s: finished, waiting for status\n",
1539 __func__);
1540
1541 usb_set((EP0_CLR_OUT | EP0_DATA_END), USB_EP0_CSR);
1542 dev->ep0state = WAIT_FOR_SETUP;
1543 } else {
1544 /* Not done yet.. */
1545 DEBUG_EP0("%s: not finished\n", __func__);
1546 usb_set(EP0_CLR_OUT, USB_EP0_CSR);
1547 }
1548 } else {
1549 DEBUG_EP0("NO REQ??!\n");
1550 }
1551}
1552
1553/*
1554 * DATA_STATE_XMIT
1555 */
1556static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
1557{
1558 struct lh7a40x_request *req;
1559 struct lh7a40x_ep *ep = &dev->ep[0];
1560 int ret, need_zlp = 0;
1561
1562 DEBUG_EP0("%s: %x\n", __func__, csr);
1563
1564 if (list_empty(&ep->queue))
1565 req = 0;
1566 else
1567 req = list_entry(ep->queue.next, struct lh7a40x_request, queue);
1568
1569 if (!req) {
1570 DEBUG_EP0("%s: NULL REQ\n", __func__);
1571 return 0;
1572 }
1573
1574 if (req->req.length == 0) {
1575
1576 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
1577 dev->ep0state = WAIT_FOR_SETUP;
1578 return 1;
1579 }
1580
1581 if (req->req.length - req->req.actual == EP0_PACKETSIZE) {
1582 /* Next write will end with the packet size, */
1583 /* so we need Zero-length-packet */
1584 need_zlp = 1;
1585 }
1586
1587 ret = write_fifo_ep0(ep, req);
1588
1589 if (ret == 1 && !need_zlp) {
1590 /* Last packet */
1591 DEBUG_EP0("%s: finished, waiting for status\n", __func__);
1592
1593 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
1594 dev->ep0state = WAIT_FOR_SETUP;
1595 } else {
1596 DEBUG_EP0("%s: not finished\n", __func__);
1597 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR);
1598 }
1599
1600 if (need_zlp) {
1601 DEBUG_EP0("%s: Need ZLP!\n", __func__);
1602 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR);
1603 dev->ep0state = DATA_STATE_NEED_ZLP;
1604 }
1605
1606 return 1;
1607}
1608
1609static int lh7a40x_handle_get_status(struct lh7a40x_udc *dev,
1610 struct usb_ctrlrequest *ctrl)
1611{
1612 struct lh7a40x_ep *ep0 = &dev->ep[0];
1613 struct lh7a40x_ep *qep;
1614 int reqtype = (ctrl->bRequestType & USB_RECIP_MASK);
1615 u16 val = 0;
1616
1617 if (reqtype == USB_RECIP_INTERFACE) {
1618 /* This is not supported.
1619 * And according to the USB spec, this one does nothing..
1620 * Just return 0
1621 */
1622 DEBUG_SETUP("GET_STATUS: USB_RECIP_INTERFACE\n");
1623 } else if (reqtype == USB_RECIP_DEVICE) {
1624 DEBUG_SETUP("GET_STATUS: USB_RECIP_DEVICE\n");
1625 val |= (1 << 0); /* Self powered */
1626 /*val |= (1<<1); *//* Remote wakeup */
1627 } else if (reqtype == USB_RECIP_ENDPOINT) {
1628 int ep_num = (ctrl->wIndex & ~USB_DIR_IN);
1629
1630 DEBUG_SETUP
1631 ("GET_STATUS: USB_RECIP_ENDPOINT (%d), ctrl->wLength = %d\n",
1632 ep_num, ctrl->wLength);
1633
1634 if (ctrl->wLength > 2 || ep_num > 3)
1635 return -EOPNOTSUPP;
1636
1637 qep = &dev->ep[ep_num];
1638 if (ep_is_in(qep) != ((ctrl->wIndex & USB_DIR_IN) ? 1 : 0)
1639 && ep_index(qep) != 0) {
1640 return -EOPNOTSUPP;
1641 }
1642
1643 usb_set_index(ep_index(qep));
1644
1645 /* Return status on next IN token */
1646 switch (qep->ep_type) {
1647 case ep_control:
1648 val =
1649 (usb_read(qep->csr1) & EP0_SEND_STALL) ==
1650 EP0_SEND_STALL;
1651 break;
1652 case ep_bulk_in:
1653 case ep_interrupt:
1654 val =
1655 (usb_read(qep->csr1) & USB_IN_CSR1_SEND_STALL) ==
1656 USB_IN_CSR1_SEND_STALL;
1657 break;
1658 case ep_bulk_out:
1659 val =
1660 (usb_read(qep->csr1) & USB_OUT_CSR1_SEND_STALL) ==
1661 USB_OUT_CSR1_SEND_STALL;
1662 break;
1663 }
1664
1665 /* Back to EP0 index */
1666 usb_set_index(0);
1667
1668 DEBUG_SETUP("GET_STATUS, ep: %d (%x), val = %d\n", ep_num,
1669 ctrl->wIndex, val);
1670 } else {
1671 DEBUG_SETUP("Unknown REQ TYPE: %d\n", reqtype);
1672 return -EOPNOTSUPP;
1673 }
1674
1675 /* Clear "out packet ready" */
1676 usb_set((EP0_CLR_OUT), USB_EP0_CSR);
1677 /* Put status to FIFO */
1678 lh7a40x_fifo_write(ep0, (u8 *) & val, sizeof(val));
1679 /* Issue "In packet ready" */
1680 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
1681
1682 return 0;
1683}
1684
1685/*
1686 * WAIT_FOR_SETUP (OUT_PKT_RDY)
1687 * - read data packet from EP0 FIFO
1688 * - decode command
1689 * - if error
1690 * set EP0_CLR_OUT | EP0_DATA_END | EP0_SEND_STALL bits
1691 * - else
1692 * set EP0_CLR_OUT | EP0_DATA_END bits
1693 */
1694static void lh7a40x_ep0_setup(struct lh7a40x_udc *dev, u32 csr)
1695{
1696 struct lh7a40x_ep *ep = &dev->ep[0];
1697 struct usb_ctrlrequest ctrl;
1698 int i, bytes, is_in;
1699
1700 DEBUG_SETUP("%s: %x\n", __func__, csr);
1701
1702 /* Nuke all previous transfers */
1703 nuke(ep, -EPROTO);
1704
1705 /* read control req from fifo (8 bytes) */
1706 bytes = lh7a40x_fifo_read(ep, (unsigned char *)&ctrl, 8);
1707
1708 DEBUG_SETUP("Read CTRL REQ %d bytes\n", bytes);
1709 DEBUG_SETUP("CTRL.bRequestType = %d (is_in %d)\n", ctrl.bRequestType,
1710 ctrl.bRequestType == USB_DIR_IN);
1711 DEBUG_SETUP("CTRL.bRequest = %d\n", ctrl.bRequest);
1712 DEBUG_SETUP("CTRL.wLength = %d\n", ctrl.wLength);
1713 DEBUG_SETUP("CTRL.wValue = %d (%d)\n", ctrl.wValue, ctrl.wValue >> 8);
1714 DEBUG_SETUP("CTRL.wIndex = %d\n", ctrl.wIndex);
1715
1716 /* Set direction of EP0 */
1717 if (likely(ctrl.bRequestType & USB_DIR_IN)) {
1718 ep->bEndpointAddress |= USB_DIR_IN;
1719 is_in = 1;
1720 } else {
1721 ep->bEndpointAddress &= ~USB_DIR_IN;
1722 is_in = 0;
1723 }
1724
1725 dev->req_pending = 1;
1726
1727 /* Handle some SETUP packets ourselves */
1728 switch (ctrl.bRequest) {
1729 case USB_REQ_SET_ADDRESS:
1730 if (ctrl.bRequestType != (USB_TYPE_STANDARD | USB_RECIP_DEVICE))
1731 break;
1732
1733 DEBUG_SETUP("USB_REQ_SET_ADDRESS (%d)\n", ctrl.wValue);
1734 udc_set_address(dev, ctrl.wValue);
1735 usb_set((EP0_CLR_OUT | EP0_DATA_END), USB_EP0_CSR);
1736 return;
1737
1738 case USB_REQ_GET_STATUS:{
1739 if (lh7a40x_handle_get_status(dev, &ctrl) == 0)
1740 return;
1741
1742 case USB_REQ_CLEAR_FEATURE:
1743 case USB_REQ_SET_FEATURE:
1744 if (ctrl.bRequestType == USB_RECIP_ENDPOINT) {
1745 struct lh7a40x_ep *qep;
1746 int ep_num = (ctrl.wIndex & 0x0f);
1747
1748 /* Support only HALT feature */
1749 if (ctrl.wValue != 0 || ctrl.wLength != 0
1750 || ep_num > 3 || ep_num < 1)
1751 break;
1752
1753 qep = &dev->ep[ep_num];
1754 spin_unlock(&dev->lock);
1755 if (ctrl.bRequest == USB_REQ_SET_FEATURE) {
1756 DEBUG_SETUP("SET_FEATURE (%d)\n",
1757 ep_num);
1758 lh7a40x_set_halt(&qep->ep, 1);
1759 } else {
1760 DEBUG_SETUP("CLR_FEATURE (%d)\n",
1761 ep_num);
1762 lh7a40x_set_halt(&qep->ep, 0);
1763 }
1764 spin_lock(&dev->lock);
1765 usb_set_index(0);
1766
1767 /* Reply with a ZLP on next IN token */
1768 usb_set((EP0_CLR_OUT | EP0_DATA_END),
1769 USB_EP0_CSR);
1770 return;
1771 }
1772 break;
1773 }
1774
1775 default:
1776 break;
1777 }
1778
1779 if (likely(dev->driver)) {
1780 /* device-2-host (IN) or no data setup command, process immediately */
1781 spin_unlock(&dev->lock);
1782 i = dev->driver->setup(&dev->gadget, &ctrl);
1783 spin_lock(&dev->lock);
1784
1785 if (i < 0) {
1786 /* setup processing failed, force stall */
1787 DEBUG_SETUP
1788 (" --> ERROR: gadget setup FAILED (stalling), setup returned %d\n",
1789 i);
1790 usb_set_index(0);
1791 usb_set((EP0_CLR_OUT | EP0_DATA_END | EP0_SEND_STALL),
1792 USB_EP0_CSR);
1793
1794 /* ep->stopped = 1; */
1795 dev->ep0state = WAIT_FOR_SETUP;
1796 }
1797 }
1798}
1799
1800/*
1801 * DATA_STATE_NEED_ZLP
1802 */
1803static void lh7a40x_ep0_in_zlp(struct lh7a40x_udc *dev, u32 csr)
1804{
1805 DEBUG_EP0("%s: %x\n", __func__, csr);
1806
1807 /* c.f. Table 15-14 */
1808 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
1809 dev->ep0state = WAIT_FOR_SETUP;
1810}
1811
1812/*
1813 * handle ep0 interrupt
1814 */
1815static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1816{
1817 struct lh7a40x_ep *ep = &dev->ep[0];
1818 u32 csr;
1819
1820 /* Set index 0 */
1821 usb_set_index(0);
1822 csr = usb_read(USB_EP0_CSR);
1823
1824 DEBUG_EP0("%s: csr = %x\n", __func__, csr);
1825
1826 /*
1827 * For overview of what we should be doing see c.f. Chapter 18.1.2.4
1828 * We will follow that outline here modified by our own global state
1829 * indication which provides hints as to what we think should be
1830 * happening..
1831 */
1832
1833 /*
1834 * if SENT_STALL is set
1835 * - clear the SENT_STALL bit
1836 */
1837 if (csr & EP0_SENT_STALL) {
1838 DEBUG_EP0("%s: EP0_SENT_STALL is set: %x\n", __func__, csr);
1839 usb_clear((EP0_SENT_STALL | EP0_SEND_STALL), USB_EP0_CSR);
1840 nuke(ep, -ECONNABORTED);
1841 dev->ep0state = WAIT_FOR_SETUP;
1842 return;
1843 }
1844
1845 /*
1846 * if a transfer is in progress && IN_PKT_RDY and OUT_PKT_RDY are clear
1847 * - fill EP0 FIFO
1848 * - if last packet
1849 * - set IN_PKT_RDY | DATA_END
1850 * - else
1851 * set IN_PKT_RDY
1852 */
1853 if (!(csr & (EP0_IN_PKT_RDY | EP0_OUT_PKT_RDY))) {
1854 DEBUG_EP0("%s: IN_PKT_RDY and OUT_PKT_RDY are clear\n",
1855 __func__);
1856
1857 switch (dev->ep0state) {
1858 case DATA_STATE_XMIT:
1859 DEBUG_EP0("continue with DATA_STATE_XMIT\n");
1860 lh7a40x_ep0_in(dev, csr);
1861 return;
1862 case DATA_STATE_NEED_ZLP:
1863 DEBUG_EP0("continue with DATA_STATE_NEED_ZLP\n");
1864 lh7a40x_ep0_in_zlp(dev, csr);
1865 return;
1866 default:
1867 /* Stall? */
1868 DEBUG_EP0("Odd state!! state = %s\n",
1869 state_names[dev->ep0state]);
1870 dev->ep0state = WAIT_FOR_SETUP;
1871 /* nuke(ep, 0); */
1872 /* usb_set(EP0_SEND_STALL, ep->csr1); */
1873 break;
1874 }
1875 }
1876
1877 /*
1878 * if SETUP_END is set
1879 * - abort the last transfer
1880 * - set SERVICED_SETUP_END_BIT
1881 */
1882 if (csr & EP0_SETUP_END) {
1883 DEBUG_EP0("%s: EP0_SETUP_END is set: %x\n", __func__, csr);
1884
1885 usb_set(EP0_CLR_SETUP_END, USB_EP0_CSR);
1886
1887 nuke(ep, 0);
1888 dev->ep0state = WAIT_FOR_SETUP;
1889 }
1890
1891 /*
1892 * if EP0_OUT_PKT_RDY is set
1893 * - read data packet from EP0 FIFO
1894 * - decode command
1895 * - if error
1896 * set SERVICED_OUT_PKT_RDY | DATA_END bits | SEND_STALL
1897 * - else
1898 * set SERVICED_OUT_PKT_RDY | DATA_END bits
1899 */
1900 if (csr & EP0_OUT_PKT_RDY) {
1901
1902 DEBUG_EP0("%s: EP0_OUT_PKT_RDY is set: %x\n", __func__,
1903 csr);
1904
1905 switch (dev->ep0state) {
1906 case WAIT_FOR_SETUP:
1907 DEBUG_EP0("WAIT_FOR_SETUP\n");
1908 lh7a40x_ep0_setup(dev, csr);
1909 break;
1910
1911 case DATA_STATE_RECV:
1912 DEBUG_EP0("DATA_STATE_RECV\n");
1913 lh7a40x_ep0_out(dev, csr);
1914 break;
1915
1916 default:
1917 /* send stall? */
1918 DEBUG_EP0("strange state!! 2. send stall? state = %d\n",
1919 dev->ep0state);
1920 break;
1921 }
1922 }
1923}
1924
1925static void lh7a40x_ep0_kick(struct lh7a40x_udc *dev, struct lh7a40x_ep *ep)
1926{
1927 u32 csr;
1928
1929 usb_set_index(0);
1930 csr = usb_read(USB_EP0_CSR);
1931
1932 DEBUG_EP0("%s: %x\n", __func__, csr);
1933
1934 /* Clear "out packet ready" */
1935 usb_set(EP0_CLR_OUT, USB_EP0_CSR);
1936
1937 if (ep_is_in(ep)) {
1938 dev->ep0state = DATA_STATE_XMIT;
1939 lh7a40x_ep0_in(dev, csr);
1940 } else {
1941 dev->ep0state = DATA_STATE_RECV;
1942 lh7a40x_ep0_out(dev, csr);
1943 }
1944}
1945
1946/* ---------------------------------------------------------------------------
1947 * device-scoped parts of the api to the usb controller hardware
1948 * ---------------------------------------------------------------------------
1949 */
1950
1951static int lh7a40x_udc_get_frame(struct usb_gadget *_gadget)
1952{
1953 u32 frame1 = usb_read(USB_FRM_NUM1); /* Least significant 8 bits */
1954 u32 frame2 = usb_read(USB_FRM_NUM2); /* Most significant 3 bits */
1955 DEBUG("%s, %p\n", __func__, _gadget);
1956 return ((frame2 & 0x07) << 8) | (frame1 & 0xff);
1957}
1958
1959static int lh7a40x_udc_wakeup(struct usb_gadget *_gadget)
1960{
1961 /* host may not have enabled remote wakeup */
1962 /*if ((UDCCS0 & UDCCS0_DRWF) == 0)
1963 return -EHOSTUNREACH;
1964 udc_set_mask_UDCCR(UDCCR_RSM); */
1965 return -ENOTSUPP;
1966}
1967
1968static const struct usb_gadget_ops lh7a40x_udc_ops = {
1969 .get_frame = lh7a40x_udc_get_frame,
1970 .wakeup = lh7a40x_udc_wakeup,
1971 /* current versions must always be self-powered */
1972};
1973
1974static void nop_release(struct device *dev)
1975{
1976 DEBUG("%s %s\n", __func__, dev_name(dev));
1977}
1978
1979static struct lh7a40x_udc memory = {
1980 .usb_address = 0,
1981
1982 .gadget = {
1983 .ops = &lh7a40x_udc_ops,
1984 .ep0 = &memory.ep[0].ep,
1985 .name = driver_name,
1986 .dev = {
1987 .init_name = "gadget",
1988 .release = nop_release,
1989 },
1990 },
1991
1992 /* control endpoint */
1993 .ep[0] = {
1994 .ep = {
1995 .name = ep0name,
1996 .ops = &lh7a40x_ep_ops,
1997 .maxpacket = EP0_PACKETSIZE,
1998 },
1999 .dev = &memory,
2000
2001 .bEndpointAddress = 0,
2002 .bmAttributes = 0,
2003
2004 .ep_type = ep_control,
2005 .fifo = io_p2v(USB_EP0_FIFO),
2006 .csr1 = USB_EP0_CSR,
2007 .csr2 = USB_EP0_CSR,
2008 },
2009
2010 /* first group of endpoints */
2011 .ep[1] = {
2012 .ep = {
2013 .name = "ep1in-bulk",
2014 .ops = &lh7a40x_ep_ops,
2015 .maxpacket = 64,
2016 },
2017 .dev = &memory,
2018
2019 .bEndpointAddress = USB_DIR_IN | 1,
2020 .bmAttributes = USB_ENDPOINT_XFER_BULK,
2021
2022 .ep_type = ep_bulk_in,
2023 .fifo = io_p2v(USB_EP1_FIFO),
2024 .csr1 = USB_IN_CSR1,
2025 .csr2 = USB_IN_CSR2,
2026 },
2027
2028 .ep[2] = {
2029 .ep = {
2030 .name = "ep2out-bulk",
2031 .ops = &lh7a40x_ep_ops,
2032 .maxpacket = 64,
2033 },
2034 .dev = &memory,
2035
2036 .bEndpointAddress = 2,
2037 .bmAttributes = USB_ENDPOINT_XFER_BULK,
2038
2039 .ep_type = ep_bulk_out,
2040 .fifo = io_p2v(USB_EP2_FIFO),
2041 .csr1 = USB_OUT_CSR1,
2042 .csr2 = USB_OUT_CSR2,
2043 },
2044
2045 .ep[3] = {
2046 .ep = {
2047 .name = "ep3in-int",
2048 .ops = &lh7a40x_ep_ops,
2049 .maxpacket = 64,
2050 },
2051 .dev = &memory,
2052
2053 .bEndpointAddress = USB_DIR_IN | 3,
2054 .bmAttributes = USB_ENDPOINT_XFER_INT,
2055
2056 .ep_type = ep_interrupt,
2057 .fifo = io_p2v(USB_EP3_FIFO),
2058 .csr1 = USB_IN_CSR1,
2059 .csr2 = USB_IN_CSR2,
2060 },
2061};
2062
2063/*
2064 * probe - binds to the platform device
2065 */
2066static int lh7a40x_udc_probe(struct platform_device *pdev)
2067{
2068 struct lh7a40x_udc *dev = &memory;
2069 int retval;
2070
2071 DEBUG("%s: %p\n", __func__, pdev);
2072
2073 spin_lock_init(&dev->lock);
2074 dev->dev = &pdev->dev;
2075
2076 device_initialize(&dev->gadget.dev);
2077 dev->gadget.dev.parent = &pdev->dev;
2078
2079 the_controller = dev;
2080 platform_set_drvdata(pdev, dev);
2081
2082 udc_disable(dev);
2083 udc_reinit(dev);
2084
2085 /* irq setup after old hardware state is cleaned up */
2086 retval =
2087 request_irq(IRQ_USBINTR, lh7a40x_udc_irq, IRQF_DISABLED, driver_name,
2088 dev);
2089 if (retval != 0) {
2090 DEBUG(KERN_ERR "%s: can't get irq %i, err %d\n", driver_name,
2091 IRQ_USBINTR, retval);
2092 return -EBUSY;
2093 }
2094
2095 create_proc_files();
2096
2097 return retval;
2098}
2099
2100static int lh7a40x_udc_remove(struct platform_device *pdev)
2101{
2102 struct lh7a40x_udc *dev = platform_get_drvdata(pdev);
2103
2104 DEBUG("%s: %p\n", __func__, pdev);
2105
2106 if (dev->driver)
2107 return -EBUSY;
2108
2109 udc_disable(dev);
2110 remove_proc_files();
2111
2112 free_irq(IRQ_USBINTR, dev);
2113
2114 platform_set_drvdata(pdev, 0);
2115
2116 the_controller = 0;
2117
2118 return 0;
2119}
2120
2121/*-------------------------------------------------------------------------*/
2122
2123static struct platform_driver udc_driver = {
2124 .probe = lh7a40x_udc_probe,
2125 .remove = lh7a40x_udc_remove,
2126 /* FIXME power management support */
2127 /* .suspend = ... disable UDC */
2128 /* .resume = ... re-enable UDC */
2129 .driver = {
2130 .name = (char *)driver_name,
2131 .owner = THIS_MODULE,
2132 },
2133};
2134
2135static int __init udc_init(void)
2136{
2137 DEBUG("%s: %s version %s\n", __func__, driver_name, DRIVER_VERSION);
2138 return platform_driver_register(&udc_driver);
2139}
2140
2141static void __exit udc_exit(void)
2142{
2143 platform_driver_unregister(&udc_driver);
2144}
2145
2146module_init(udc_init);
2147module_exit(udc_exit);
2148
2149MODULE_DESCRIPTION(DRIVER_DESC);
2150MODULE_AUTHOR("Mikko Lahteenmaki, Bo Henriksen");
2151MODULE_LICENSE("GPL");
2152MODULE_ALIAS("platform:lh7a40x_udc");
diff --git a/drivers/usb/gadget/lh7a40x_udc.h b/drivers/usb/gadget/lh7a40x_udc.h
deleted file mode 100644
index ca861203a301..000000000000
--- a/drivers/usb/gadget/lh7a40x_udc.h
+++ /dev/null
@@ -1,259 +0,0 @@
1/*
2 * linux/drivers/usb/gadget/lh7a40x_udc.h
3 * Sharp LH7A40x on-chip full speed USB device controllers
4 *
5 * Copyright (C) 2004 Mikko Lahteenmaki, Nordic ID
6 * Copyright (C) 2004 Bo Henriksen, Nordic ID
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#ifndef __LH7A40X_H_
25#define __LH7A40X_H_
26
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/ioport.h>
30#include <linux/types.h>
31#include <linux/errno.h>
32#include <linux/delay.h>
33#include <linux/sched.h>
34#include <linux/slab.h>
35#include <linux/init.h>
36#include <linux/timer.h>
37#include <linux/list.h>
38#include <linux/interrupt.h>
39#include <linux/proc_fs.h>
40#include <linux/mm.h>
41#include <linux/device.h>
42#include <linux/dma-mapping.h>
43
44#include <asm/byteorder.h>
45#include <asm/dma.h>
46#include <asm/io.h>
47#include <asm/irq.h>
48#include <asm/system.h>
49#include <asm/unaligned.h>
50#include <mach/hardware.h>
51
52#include <linux/usb/ch9.h>
53#include <linux/usb/gadget.h>
54
55/*
56 * Memory map
57 */
58
59#define USB_FA 0x80000200 // function address register
60#define USB_PM 0x80000204 // power management register
61
62#define USB_IN_INT 0x80000208 // IN interrupt register bank (EP0-EP3)
63#define USB_OUT_INT 0x80000210 // OUT interrupt register bank (EP2)
64#define USB_INT 0x80000218 // interrupt register bank
65
66#define USB_IN_INT_EN 0x8000021C // IN interrupt enable register bank
67#define USB_OUT_INT_EN 0x80000224 // OUT interrupt enable register bank
68#define USB_INT_EN 0x8000022C // USB interrupt enable register bank
69
70#define USB_FRM_NUM1 0x80000230 // Frame number1 register
71#define USB_FRM_NUM2 0x80000234 // Frame number2 register
72#define USB_INDEX 0x80000238 // index register
73
74#define USB_IN_MAXP 0x80000240 // IN MAXP register
75#define USB_IN_CSR1 0x80000244 // IN CSR1 register/EP0 CSR register
76#define USB_EP0_CSR 0x80000244 // IN CSR1 register/EP0 CSR register
77#define USB_IN_CSR2 0x80000248 // IN CSR2 register
78#define USB_OUT_MAXP 0x8000024C // OUT MAXP register
79
80#define USB_OUT_CSR1 0x80000250 // OUT CSR1 register
81#define USB_OUT_CSR2 0x80000254 // OUT CSR2 register
82#define USB_OUT_FIFO_WC1 0x80000258 // OUT FIFO write count1 register
83#define USB_OUT_FIFO_WC2 0x8000025C // OUT FIFO write count2 register
84
85#define USB_RESET 0x8000044C // USB reset register
86
87#define USB_EP0_FIFO 0x80000280
88#define USB_EP1_FIFO 0x80000284
89#define USB_EP2_FIFO 0x80000288
90#define USB_EP3_FIFO 0x8000028c
91
92/*
93 * USB reset register
94 */
95#define USB_RESET_APB (1<<1) //resets USB APB control side WRITE
96#define USB_RESET_IO (1<<0) //resets USB IO side WRITE
97
98/*
99 * USB function address register
100 */
101#define USB_FA_ADDR_UPDATE (1<<7)
102#define USB_FA_FUNCTION_ADDR (0x7F)
103
104/*
105 * Power Management register
106 */
107#define PM_USB_DCP (1<<5)
108#define PM_USB_ENABLE (1<<4)
109#define PM_USB_RESET (1<<3)
110#define PM_UC_RESUME (1<<2)
111#define PM_SUSPEND_MODE (1<<1)
112#define PM_ENABLE_SUSPEND (1<<0)
113
114/*
115 * IN interrupt register
116 */
117#define USB_IN_INT_EP3 (1<<3)
118#define USB_IN_INT_EP1 (1<<1)
119#define USB_IN_INT_EP0 (1<<0)
120
121/*
122 * OUT interrupt register
123 */
124#define USB_OUT_INT_EP2 (1<<2)
125
126/*
127 * USB interrupt register
128 */
129#define USB_INT_RESET_INT (1<<2)
130#define USB_INT_RESUME_INT (1<<1)
131#define USB_INT_SUSPEND_INT (1<<0)
132
133/*
134 * USB interrupt enable register
135 */
136#define USB_INT_EN_USB_RESET_INTER (1<<2)
137#define USB_INT_EN_RESUME_INTER (1<<1)
138#define USB_INT_EN_SUSPEND_INTER (1<<0)
139
140/*
141 * INCSR1 register
142 */
143#define USB_IN_CSR1_CLR_DATA_TOGGLE (1<<6)
144#define USB_IN_CSR1_SENT_STALL (1<<5)
145#define USB_IN_CSR1_SEND_STALL (1<<4)
146#define USB_IN_CSR1_FIFO_FLUSH (1<<3)
147#define USB_IN_CSR1_FIFO_NOT_EMPTY (1<<1)
148#define USB_IN_CSR1_IN_PKT_RDY (1<<0)
149
150/*
151 * INCSR2 register
152 */
153#define USB_IN_CSR2_AUTO_SET (1<<7)
154#define USB_IN_CSR2_USB_DMA_EN (1<<4)
155
156/*
157 * OUT CSR1 register
158 */
159#define USB_OUT_CSR1_CLR_DATA_REG (1<<7)
160#define USB_OUT_CSR1_SENT_STALL (1<<6)
161#define USB_OUT_CSR1_SEND_STALL (1<<5)
162#define USB_OUT_CSR1_FIFO_FLUSH (1<<4)
163#define USB_OUT_CSR1_FIFO_FULL (1<<1)
164#define USB_OUT_CSR1_OUT_PKT_RDY (1<<0)
165
166/*
167 * OUT CSR2 register
168 */
169#define USB_OUT_CSR2_AUTO_CLR (1<<7)
170#define USB_OUT_CSR2_USB_DMA_EN (1<<4)
171
172/*
173 * EP0 CSR
174 */
175#define EP0_CLR_SETUP_END (1<<7) /* Clear "Setup Ends" Bit (w) */
176#define EP0_CLR_OUT (1<<6) /* Clear "Out packet ready" Bit (w) */
177#define EP0_SEND_STALL (1<<5) /* Send STALL Handshake (rw) */
178#define EP0_SETUP_END (1<<4) /* Setup Ends (r) */
179
180#define EP0_DATA_END (1<<3) /* Data end (rw) */
181#define EP0_SENT_STALL (1<<2) /* Sent Stall Handshake (r) */
182#define EP0_IN_PKT_RDY (1<<1) /* In packet ready (rw) */
183#define EP0_OUT_PKT_RDY (1<<0) /* Out packet ready (r) */
184
185/* general CSR */
186#define OUT_PKT_RDY (1<<0)
187#define IN_PKT_RDY (1<<0)
188
189/*
190 * IN/OUT MAXP register
191 */
192#define USB_OUT_MAXP_MAXP (0xF)
193#define USB_IN_MAXP_MAXP (0xF)
194
195// Max packet size
196//#define EP0_PACKETSIZE 0x10
197#define EP0_PACKETSIZE 0x8
198#define EP0_MAXPACKETSIZE 0x10
199
200#define UDC_MAX_ENDPOINTS 4
201
202#define WAIT_FOR_SETUP 0
203#define DATA_STATE_XMIT 1
204#define DATA_STATE_NEED_ZLP 2
205#define WAIT_FOR_OUT_STATUS 3
206#define DATA_STATE_RECV 4
207
208/* ********************************************************************************************* */
209/* IO
210 */
211
212typedef enum ep_type {
213 ep_control, ep_bulk_in, ep_bulk_out, ep_interrupt
214} ep_type_t;
215
216struct lh7a40x_ep {
217 struct usb_ep ep;
218 struct lh7a40x_udc *dev;
219
220 const struct usb_endpoint_descriptor *desc;
221 struct list_head queue;
222 unsigned long pio_irqs;
223
224 u8 stopped;
225 u8 bEndpointAddress;
226 u8 bmAttributes;
227
228 ep_type_t ep_type;
229 u32 fifo;
230 u32 csr1;
231 u32 csr2;
232};
233
234struct lh7a40x_request {
235 struct usb_request req;
236 struct list_head queue;
237};
238
239struct lh7a40x_udc {
240 struct usb_gadget gadget;
241 struct usb_gadget_driver *driver;
242 struct device *dev;
243 spinlock_t lock;
244
245 int ep0state;
246 struct lh7a40x_ep ep[UDC_MAX_ENDPOINTS];
247
248 unsigned char usb_address;
249
250 unsigned req_pending:1, req_std:1, req_config:1;
251};
252
253extern struct lh7a40x_udc *the_controller;
254
255#define ep_is_in(EP) (((EP)->bEndpointAddress&USB_DIR_IN)==USB_DIR_IN)
256#define ep_index(EP) ((EP)->bEndpointAddress&0xF)
257#define ep_maxpacket(EP) ((EP)->ep.maxpacket)
258
259#endif
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index e03058fe23cb..084aa080a2d5 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -258,7 +258,7 @@ static int pipe_buffer_setting(struct m66592 *m66592,
258 break; 258 break;
259 case M66592_BULK: 259 case M66592_BULK:
260 /* isochronous pipes may be used as bulk pipes */ 260 /* isochronous pipes may be used as bulk pipes */
261 if (info->pipe > M66592_BASE_PIPENUM_BULK) 261 if (info->pipe >= M66592_BASE_PIPENUM_BULK)
262 bufnum = info->pipe - M66592_BASE_PIPENUM_BULK; 262 bufnum = info->pipe - M66592_BASE_PIPENUM_BULK;
263 else 263 else
264 bufnum = info->pipe - M66592_BASE_PIPENUM_ISOC; 264 bufnum = info->pipe - M66592_BASE_PIPENUM_ISOC;
@@ -1454,14 +1454,15 @@ static struct usb_ep_ops m66592_ep_ops = {
1454/*-------------------------------------------------------------------------*/ 1454/*-------------------------------------------------------------------------*/
1455static struct m66592 *the_controller; 1455static struct m66592 *the_controller;
1456 1456
1457int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1457int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1458 int (*bind)(struct usb_gadget *))
1458{ 1459{
1459 struct m66592 *m66592 = the_controller; 1460 struct m66592 *m66592 = the_controller;
1460 int retval; 1461 int retval;
1461 1462
1462 if (!driver 1463 if (!driver
1463 || driver->speed != USB_SPEED_HIGH 1464 || driver->speed != USB_SPEED_HIGH
1464 || !driver->bind 1465 || !bind
1465 || !driver->setup) 1466 || !driver->setup)
1466 return -EINVAL; 1467 return -EINVAL;
1467 if (!m66592) 1468 if (!m66592)
@@ -1480,7 +1481,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1480 goto error; 1481 goto error;
1481 } 1482 }
1482 1483
1483 retval = driver->bind (&m66592->gadget); 1484 retval = bind(&m66592->gadget);
1484 if (retval) { 1485 if (retval) {
1485 pr_err("bind to driver error (%d)\n", retval); 1486 pr_err("bind to driver error (%d)\n", retval);
1486 device_del(&m66592->gadget.dev); 1487 device_del(&m66592->gadget.dev);
@@ -1505,7 +1506,7 @@ error:
1505 1506
1506 return retval; 1507 return retval;
1507} 1508}
1508EXPORT_SYMBOL(usb_gadget_register_driver); 1509EXPORT_SYMBOL(usb_gadget_probe_driver);
1509 1510
1510int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1511int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1511{ 1512{
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
index 585f2559484d..01822422c3e8 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -75,10 +75,6 @@ static struct usb_device_descriptor msg_device_desc = {
75 /* Vendor and product id can be overridden by module parameters. */ 75 /* Vendor and product id can be overridden by module parameters. */
76 .idVendor = cpu_to_le16(FSG_VENDOR_ID), 76 .idVendor = cpu_to_le16(FSG_VENDOR_ID),
77 .idProduct = cpu_to_le16(FSG_PRODUCT_ID), 77 .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
78 /* .bcdDevice = f(hardware) */
79 /* .iManufacturer = DYNAMIC */
80 /* .iProduct = DYNAMIC */
81 /* NO SERIAL NUMBER */
82 .bNumConfigurations = 1, 78 .bNumConfigurations = 1,
83}; 79};
84 80
@@ -86,7 +82,8 @@ static struct usb_otg_descriptor otg_descriptor = {
86 .bLength = sizeof otg_descriptor, 82 .bLength = sizeof otg_descriptor,
87 .bDescriptorType = USB_DT_OTG, 83 .bDescriptorType = USB_DT_OTG,
88 84
89 /* REVISIT SRP-only hardware is possible, although 85 /*
86 * REVISIT SRP-only hardware is possible, although
90 * it would not be called "OTG" ... 87 * it would not be called "OTG" ...
91 */ 88 */
92 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 89 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
@@ -98,33 +95,6 @@ static const struct usb_descriptor_header *otg_desc[] = {
98}; 95};
99 96
100 97
101/* string IDs are assigned dynamically */
102
103#define STRING_MANUFACTURER_IDX 0
104#define STRING_PRODUCT_IDX 1
105#define STRING_CONFIGURATION_IDX 2
106
107static char manufacturer[50];
108
109static struct usb_string strings_dev[] = {
110 [STRING_MANUFACTURER_IDX].s = manufacturer,
111 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
112 [STRING_CONFIGURATION_IDX].s = "Self Powered",
113 { } /* end of list */
114};
115
116static struct usb_gadget_strings stringtab_dev = {
117 .language = 0x0409, /* en-us */
118 .strings = strings_dev,
119};
120
121static struct usb_gadget_strings *dev_strings[] = {
122 &stringtab_dev,
123 NULL,
124};
125
126
127
128/****************************** Configurations ******************************/ 98/****************************** Configurations ******************************/
129 99
130static struct fsg_module_parameters mod_data = { 100static struct fsg_module_parameters mod_data = {
@@ -132,7 +102,7 @@ static struct fsg_module_parameters mod_data = {
132}; 102};
133FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); 103FSG_MODULE_PARAMETERS(/* no prefix */, mod_data);
134 104
135static unsigned long msg_registered = 0; 105static unsigned long msg_registered;
136static void msg_cleanup(void); 106static void msg_cleanup(void);
137 107
138static int msg_thread_exits(struct fsg_common *common) 108static int msg_thread_exits(struct fsg_common *common)
@@ -141,7 +111,7 @@ static int msg_thread_exits(struct fsg_common *common)
141 return 0; 111 return 0;
142} 112}
143 113
144static int __ref msg_do_config(struct usb_configuration *c) 114static int __init msg_do_config(struct usb_configuration *c)
145{ 115{
146 static const struct fsg_operations ops = { 116 static const struct fsg_operations ops = {
147 .thread_exits = msg_thread_exits, 117 .thread_exits = msg_thread_exits,
@@ -171,54 +141,23 @@ static int __ref msg_do_config(struct usb_configuration *c)
171 141
172static struct usb_configuration msg_config_driver = { 142static struct usb_configuration msg_config_driver = {
173 .label = "Linux File-Backed Storage", 143 .label = "Linux File-Backed Storage",
174 .bind = msg_do_config,
175 .bConfigurationValue = 1, 144 .bConfigurationValue = 1,
176 /* .iConfiguration = DYNAMIC */
177 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 145 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
178}; 146};
179 147
180 148
181
182/****************************** Gadget Bind ******************************/ 149/****************************** Gadget Bind ******************************/
183 150
184 151static int __init msg_bind(struct usb_composite_dev *cdev)
185static int __ref msg_bind(struct usb_composite_dev *cdev)
186{ 152{
187 struct usb_gadget *gadget = cdev->gadget;
188 int status; 153 int status;
189 154
190 /* Allocate string descriptor numbers ... note that string 155 status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
191 * contents can be overridden by the composite_dev glue.
192 */
193
194 /* device descriptor strings: manufacturer, product */
195 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
196 init_utsname()->sysname, init_utsname()->release,
197 gadget->name);
198 status = usb_string_id(cdev);
199 if (status < 0) 156 if (status < 0)
200 return status; 157 return status;
201 strings_dev[STRING_MANUFACTURER_IDX].id = status;
202 msg_device_desc.iManufacturer = status;
203 158
204 status = usb_string_id(cdev); 159 dev_info(&cdev->gadget->dev,
205 if (status < 0) 160 DRIVER_DESC ", version: " DRIVER_VERSION "\n");
206 return status;
207 strings_dev[STRING_PRODUCT_IDX].id = status;
208 msg_device_desc.iProduct = status;
209
210 status = usb_string_id(cdev);
211 if (status < 0)
212 return status;
213 strings_dev[STRING_CONFIGURATION_IDX].id = status;
214 msg_config_driver.iConfiguration = status;
215
216 /* register our second configuration */
217 status = usb_add_config(cdev, &msg_config_driver);
218 if (status < 0)
219 return status;
220
221 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
222 set_bit(0, &msg_registered); 161 set_bit(0, &msg_registered);
223 return 0; 162 return 0;
224} 163}
@@ -226,12 +165,11 @@ static int __ref msg_bind(struct usb_composite_dev *cdev)
226 165
227/****************************** Some noise ******************************/ 166/****************************** Some noise ******************************/
228 167
229
230static struct usb_composite_driver msg_driver = { 168static struct usb_composite_driver msg_driver = {
231 .name = "g_mass_storage", 169 .name = "g_mass_storage",
232 .dev = &msg_device_desc, 170 .dev = &msg_device_desc,
233 .strings = dev_strings, 171 .iProduct = DRIVER_DESC,
234 .bind = msg_bind, 172 .needs_serial = 1,
235}; 173};
236 174
237MODULE_DESCRIPTION(DRIVER_DESC); 175MODULE_DESCRIPTION(DRIVER_DESC);
@@ -240,7 +178,7 @@ MODULE_LICENSE("GPL");
240 178
241static int __init msg_init(void) 179static int __init msg_init(void)
242{ 180{
243 return usb_composite_register(&msg_driver); 181 return usb_composite_probe(&msg_driver, msg_bind);
244} 182}
245module_init(msg_init); 183module_init(msg_init);
246 184
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 795d76232167..d9feced348e3 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -74,8 +74,8 @@ MODULE_LICENSE("GPL");
74 74
75/***************************** Device Descriptor ****************************/ 75/***************************** Device Descriptor ****************************/
76 76
77#define MULTI_VENDOR_NUM 0x0525 /* XXX NetChip */ 77#define MULTI_VENDOR_NUM 0x1d6b /* Linux Foundation */
78#define MULTI_PRODUCT_NUM 0xa4ab /* XXX */ 78#define MULTI_PRODUCT_NUM 0x0104 /* Multifunction Composite Gadget */
79 79
80 80
81enum { 81enum {
@@ -121,8 +121,6 @@ static const struct usb_descriptor_header *otg_desc[] = {
121 121
122 122
123enum { 123enum {
124 MULTI_STRING_MANUFACTURER_IDX,
125 MULTI_STRING_PRODUCT_IDX,
126#ifdef CONFIG_USB_G_MULTI_RNDIS 124#ifdef CONFIG_USB_G_MULTI_RNDIS
127 MULTI_STRING_RNDIS_CONFIG_IDX, 125 MULTI_STRING_RNDIS_CONFIG_IDX,
128#endif 126#endif
@@ -131,11 +129,7 @@ enum {
131#endif 129#endif
132}; 130};
133 131
134static char manufacturer[50];
135
136static struct usb_string strings_dev[] = { 132static struct usb_string strings_dev[] = {
137 [MULTI_STRING_MANUFACTURER_IDX].s = manufacturer,
138 [MULTI_STRING_PRODUCT_IDX].s = DRIVER_DESC,
139#ifdef CONFIG_USB_G_MULTI_RNDIS 133#ifdef CONFIG_USB_G_MULTI_RNDIS
140 [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS", 134 [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS",
141#endif 135#endif
@@ -170,7 +164,7 @@ static u8 hostaddr[ETH_ALEN];
170 164
171#ifdef USB_ETH_RNDIS 165#ifdef USB_ETH_RNDIS
172 166
173static __ref int rndis_do_config(struct usb_configuration *c) 167static __init int rndis_do_config(struct usb_configuration *c)
174{ 168{
175 int ret; 169 int ret;
176 170
@@ -197,7 +191,6 @@ static __ref int rndis_do_config(struct usb_configuration *c)
197static int rndis_config_register(struct usb_composite_dev *cdev) 191static int rndis_config_register(struct usb_composite_dev *cdev)
198{ 192{
199 static struct usb_configuration config = { 193 static struct usb_configuration config = {
200 .bind = rndis_do_config,
201 .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM, 194 .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM,
202 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 195 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
203 }; 196 };
@@ -205,7 +198,7 @@ static int rndis_config_register(struct usb_composite_dev *cdev)
205 config.label = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].s; 198 config.label = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].s;
206 config.iConfiguration = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].id; 199 config.iConfiguration = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].id;
207 200
208 return usb_add_config(cdev, &config); 201 return usb_add_config(cdev, &config, rndis_do_config);
209} 202}
210 203
211#else 204#else
@@ -222,7 +215,7 @@ static int rndis_config_register(struct usb_composite_dev *cdev)
222 215
223#ifdef CONFIG_USB_G_MULTI_CDC 216#ifdef CONFIG_USB_G_MULTI_CDC
224 217
225static __ref int cdc_do_config(struct usb_configuration *c) 218static __init int cdc_do_config(struct usb_configuration *c)
226{ 219{
227 int ret; 220 int ret;
228 221
@@ -249,7 +242,6 @@ static __ref int cdc_do_config(struct usb_configuration *c)
249static int cdc_config_register(struct usb_composite_dev *cdev) 242static int cdc_config_register(struct usb_composite_dev *cdev)
250{ 243{
251 static struct usb_configuration config = { 244 static struct usb_configuration config = {
252 .bind = cdc_do_config,
253 .bConfigurationValue = MULTI_CDC_CONFIG_NUM, 245 .bConfigurationValue = MULTI_CDC_CONFIG_NUM,
254 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 246 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
255 }; 247 };
@@ -257,7 +249,7 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
257 config.label = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].s; 249 config.label = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].s;
258 config.iConfiguration = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].id; 250 config.iConfiguration = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].id;
259 251
260 return usb_add_config(cdev, &config); 252 return usb_add_config(cdev, &config, cdc_do_config);
261} 253}
262 254
263#else 255#else
@@ -314,20 +306,11 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
314 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099); 306 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
315 } 307 }
316 308
317 /* allocate string descriptor numbers */ 309 /* allocate string IDs */
318 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
319 init_utsname()->sysname, init_utsname()->release,
320 gadget->name);
321
322 status = usb_string_ids_tab(cdev, strings_dev); 310 status = usb_string_ids_tab(cdev, strings_dev);
323 if (unlikely(status < 0)) 311 if (unlikely(status < 0))
324 goto fail2; 312 goto fail2;
325 313
326 device_desc.iManufacturer =
327 strings_dev[MULTI_STRING_MANUFACTURER_IDX].id;
328 device_desc.iProduct =
329 strings_dev[MULTI_STRING_PRODUCT_IDX].id;
330
331 /* register configurations */ 314 /* register configurations */
332 status = rndis_config_register(cdev); 315 status = rndis_config_register(cdev);
333 if (unlikely(status < 0)) 316 if (unlikely(status < 0))
@@ -368,14 +351,15 @@ static struct usb_composite_driver multi_driver = {
368 .name = "g_multi", 351 .name = "g_multi",
369 .dev = &device_desc, 352 .dev = &device_desc,
370 .strings = dev_strings, 353 .strings = dev_strings,
371 .bind = multi_bind,
372 .unbind = __exit_p(multi_unbind), 354 .unbind = __exit_p(multi_unbind),
355 .iProduct = DRIVER_DESC,
356 .needs_serial = 1,
373}; 357};
374 358
375 359
376static int __init multi_init(void) 360static int __init multi_init(void)
377{ 361{
378 return usb_composite_register(&multi_driver); 362 return usb_composite_probe(&multi_driver, multi_bind);
379} 363}
380module_init(multi_init); 364module_init(multi_init);
381 365
diff --git a/drivers/usb/gadget/mv_udc.h b/drivers/usb/gadget/mv_udc.h
new file mode 100644
index 000000000000..65f1f7c3bd4e
--- /dev/null
+++ b/drivers/usb/gadget/mv_udc.h
@@ -0,0 +1,294 @@
1
2#ifndef __MV_UDC_H
3#define __MV_UDC_H
4
5#define VUSBHS_MAX_PORTS 8
6
7#define DQH_ALIGNMENT 2048
8#define DTD_ALIGNMENT 64
9#define DMA_BOUNDARY 4096
10
11#define EP_DIR_IN 1
12#define EP_DIR_OUT 0
13
14#define DMA_ADDR_INVALID (~(dma_addr_t)0)
15
16#define EP0_MAX_PKT_SIZE 64
17/* ep0 transfer state */
18#define WAIT_FOR_SETUP 0
19#define DATA_STATE_XMIT 1
20#define DATA_STATE_NEED_ZLP 2
21#define WAIT_FOR_OUT_STATUS 3
22#define DATA_STATE_RECV 4
23
24#define CAPLENGTH_MASK (0xff)
25#define DCCPARAMS_DEN_MASK (0x1f)
26
27#define HCSPARAMS_PPC (0x10)
28
29/* Frame Index Register Bit Masks */
30#define USB_FRINDEX_MASKS 0x3fff
31
32/* Command Register Bit Masks */
33#define USBCMD_RUN_STOP (0x00000001)
34#define USBCMD_CTRL_RESET (0x00000002)
35#define USBCMD_SETUP_TRIPWIRE_SET (0x00002000)
36#define USBCMD_SETUP_TRIPWIRE_CLEAR (~USBCMD_SETUP_TRIPWIRE_SET)
37
38#define USBCMD_ATDTW_TRIPWIRE_SET (0x00004000)
39#define USBCMD_ATDTW_TRIPWIRE_CLEAR (~USBCMD_ATDTW_TRIPWIRE_SET)
40
41/* bit 15,3,2 are for frame list size */
42#define USBCMD_FRAME_SIZE_1024 (0x00000000) /* 000 */
43#define USBCMD_FRAME_SIZE_512 (0x00000004) /* 001 */
44#define USBCMD_FRAME_SIZE_256 (0x00000008) /* 010 */
45#define USBCMD_FRAME_SIZE_128 (0x0000000C) /* 011 */
46#define USBCMD_FRAME_SIZE_64 (0x00008000) /* 100 */
47#define USBCMD_FRAME_SIZE_32 (0x00008004) /* 101 */
48#define USBCMD_FRAME_SIZE_16 (0x00008008) /* 110 */
49#define USBCMD_FRAME_SIZE_8 (0x0000800C) /* 111 */
50
51#define EPCTRL_TX_ALL_MASK (0xFFFF0000)
52#define EPCTRL_RX_ALL_MASK (0x0000FFFF)
53
54#define EPCTRL_TX_DATA_TOGGLE_RST (0x00400000)
55#define EPCTRL_TX_EP_STALL (0x00010000)
56#define EPCTRL_RX_EP_STALL (0x00000001)
57#define EPCTRL_RX_DATA_TOGGLE_RST (0x00000040)
58#define EPCTRL_RX_ENABLE (0x00000080)
59#define EPCTRL_TX_ENABLE (0x00800000)
60#define EPCTRL_CONTROL (0x00000000)
61#define EPCTRL_ISOCHRONOUS (0x00040000)
62#define EPCTRL_BULK (0x00080000)
63#define EPCTRL_INT (0x000C0000)
64#define EPCTRL_TX_TYPE (0x000C0000)
65#define EPCTRL_RX_TYPE (0x0000000C)
66#define EPCTRL_DATA_TOGGLE_INHIBIT (0x00000020)
67#define EPCTRL_TX_EP_TYPE_SHIFT (18)
68#define EPCTRL_RX_EP_TYPE_SHIFT (2)
69
70#define EPCOMPLETE_MAX_ENDPOINTS (16)
71
72/* endpoint list address bit masks */
73#define USB_EP_LIST_ADDRESS_MASK 0xfffff800
74
75#define PORTSCX_W1C_BITS 0x2a
76#define PORTSCX_PORT_RESET 0x00000100
77#define PORTSCX_PORT_POWER 0x00001000
78#define PORTSCX_FORCE_FULL_SPEED_CONNECT 0x01000000
79#define PORTSCX_PAR_XCVR_SELECT 0xC0000000
80#define PORTSCX_PORT_FORCE_RESUME 0x00000040
81#define PORTSCX_PORT_SUSPEND 0x00000080
82#define PORTSCX_PORT_SPEED_FULL 0x00000000
83#define PORTSCX_PORT_SPEED_LOW 0x04000000
84#define PORTSCX_PORT_SPEED_HIGH 0x08000000
85#define PORTSCX_PORT_SPEED_MASK 0x0C000000
86
87/* USB MODE Register Bit Masks */
88#define USBMODE_CTRL_MODE_IDLE 0x00000000
89#define USBMODE_CTRL_MODE_DEVICE 0x00000002
90#define USBMODE_CTRL_MODE_HOST 0x00000003
91#define USBMODE_CTRL_MODE_RSV 0x00000001
92#define USBMODE_SETUP_LOCK_OFF 0x00000008
93#define USBMODE_STREAM_DISABLE 0x00000010
94
95/* USB STS Register Bit Masks */
96#define USBSTS_INT 0x00000001
97#define USBSTS_ERR 0x00000002
98#define USBSTS_PORT_CHANGE 0x00000004
99#define USBSTS_FRM_LST_ROLL 0x00000008
100#define USBSTS_SYS_ERR 0x00000010
101#define USBSTS_IAA 0x00000020
102#define USBSTS_RESET 0x00000040
103#define USBSTS_SOF 0x00000080
104#define USBSTS_SUSPEND 0x00000100
105#define USBSTS_HC_HALTED 0x00001000
106#define USBSTS_RCL 0x00002000
107#define USBSTS_PERIODIC_SCHEDULE 0x00004000
108#define USBSTS_ASYNC_SCHEDULE 0x00008000
109
110
111/* Interrupt Enable Register Bit Masks */
112#define USBINTR_INT_EN (0x00000001)
113#define USBINTR_ERR_INT_EN (0x00000002)
114#define USBINTR_PORT_CHANGE_DETECT_EN (0x00000004)
115
116#define USBINTR_ASYNC_ADV_AAE (0x00000020)
117#define USBINTR_ASYNC_ADV_AAE_ENABLE (0x00000020)
118#define USBINTR_ASYNC_ADV_AAE_DISABLE (0xFFFFFFDF)
119
120#define USBINTR_RESET_EN (0x00000040)
121#define USBINTR_SOF_UFRAME_EN (0x00000080)
122#define USBINTR_DEVICE_SUSPEND (0x00000100)
123
124#define USB_DEVICE_ADDRESS_MASK (0xfe000000)
125#define USB_DEVICE_ADDRESS_BIT_SHIFT (25)
126
127struct mv_cap_regs {
128 u32 caplength_hciversion;
129 u32 hcsparams; /* HC structural parameters */
130 u32 hccparams; /* HC Capability Parameters*/
131 u32 reserved[5];
132 u32 dciversion; /* DC version number and reserved 16 bits */
133 u32 dccparams; /* DC Capability Parameters */
134};
135
136struct mv_op_regs {
137 u32 usbcmd; /* Command register */
138 u32 usbsts; /* Status register */
139 u32 usbintr; /* Interrupt enable */
140 u32 frindex; /* Frame index */
141 u32 reserved1[1];
142 u32 deviceaddr; /* Device Address */
143 u32 eplistaddr; /* Endpoint List Address */
144 u32 ttctrl; /* HOST TT status and control */
145 u32 burstsize; /* Programmable Burst Size */
146 u32 txfilltuning; /* Host Transmit Pre-Buffer Packet Tuning */
147 u32 reserved[4];
148 u32 epnak; /* Endpoint NAK */
149 u32 epnaken; /* Endpoint NAK Enable */
150 u32 configflag; /* Configured Flag register */
151 u32 portsc[VUSBHS_MAX_PORTS]; /* Port Status/Control x, x = 1..8 */
152 u32 otgsc;
153 u32 usbmode; /* USB Host/Device mode */
154 u32 epsetupstat; /* Endpoint Setup Status */
155 u32 epprime; /* Endpoint Initialize */
156 u32 epflush; /* Endpoint De-initialize */
157 u32 epstatus; /* Endpoint Status */
158 u32 epcomplete; /* Endpoint Interrupt On Complete */
159 u32 epctrlx[16]; /* Endpoint Control, where x = 0.. 15 */
160 u32 mcr; /* Mux Control */
161 u32 isr; /* Interrupt Status */
162 u32 ier; /* Interrupt Enable */
163};
164
165struct mv_udc {
166 struct usb_gadget gadget;
167 struct usb_gadget_driver *driver;
168 spinlock_t lock;
169 struct completion *done;
170 struct platform_device *dev;
171 int irq;
172
173 struct mv_cap_regs __iomem *cap_regs;
174 struct mv_op_regs __iomem *op_regs;
175 unsigned int phy_regs;
176 unsigned int max_eps;
177 struct mv_dqh *ep_dqh;
178 size_t ep_dqh_size;
179 dma_addr_t ep_dqh_dma;
180
181 struct dma_pool *dtd_pool;
182 struct mv_ep *eps;
183
184 struct mv_dtd *dtd_head;
185 struct mv_dtd *dtd_tail;
186 unsigned int dtd_entries;
187
188 struct mv_req *status_req;
189 struct usb_ctrlrequest local_setup_buff;
190
191 unsigned int resume_state; /* USB state to resume */
192 unsigned int usb_state; /* USB current state */
193 unsigned int ep0_state; /* Endpoint zero state */
194 unsigned int ep0_dir;
195
196 unsigned int dev_addr;
197
198 int errors;
199 unsigned softconnect:1,
200 vbus_active:1,
201 remote_wakeup:1,
202 softconnected:1,
203 force_fs:1;
204 struct clk *clk;
205};
206
207/* endpoint data structure */
208struct mv_ep {
209 struct usb_ep ep;
210 struct mv_udc *udc;
211 struct list_head queue;
212 struct mv_dqh *dqh;
213 const struct usb_endpoint_descriptor *desc;
214 u32 direction;
215 char name[14];
216 unsigned stopped:1,
217 wedge:1,
218 ep_type:2,
219 ep_num:8;
220};
221
222/* request data structure */
223struct mv_req {
224 struct usb_request req;
225 struct mv_dtd *dtd, *head, *tail;
226 struct mv_ep *ep;
227 struct list_head queue;
228 unsigned dtd_count;
229 unsigned mapped:1;
230};
231
232#define EP_QUEUE_HEAD_MULT_POS 30
233#define EP_QUEUE_HEAD_ZLT_SEL 0x20000000
234#define EP_QUEUE_HEAD_MAX_PKT_LEN_POS 16
235#define EP_QUEUE_HEAD_MAX_PKT_LEN(ep_info) (((ep_info)>>16)&0x07ff)
236#define EP_QUEUE_HEAD_IOS 0x00008000
237#define EP_QUEUE_HEAD_NEXT_TERMINATE 0x00000001
238#define EP_QUEUE_HEAD_IOC 0x00008000
239#define EP_QUEUE_HEAD_MULTO 0x00000C00
240#define EP_QUEUE_HEAD_STATUS_HALT 0x00000040
241#define EP_QUEUE_HEAD_STATUS_ACTIVE 0x00000080
242#define EP_QUEUE_CURRENT_OFFSET_MASK 0x00000FFF
243#define EP_QUEUE_HEAD_NEXT_POINTER_MASK 0xFFFFFFE0
244#define EP_QUEUE_FRINDEX_MASK 0x000007FF
245#define EP_MAX_LENGTH_TRANSFER 0x4000
246
247struct mv_dqh {
248 /* Bits 16..26 Bit 15 is Interrupt On Setup */
249 u32 max_packet_length;
250 u32 curr_dtd_ptr; /* Current dTD Pointer */
251 u32 next_dtd_ptr; /* Next dTD Pointer */
252 /* Total bytes (16..30), IOC (15), INT (8), STS (0-7) */
253 u32 size_ioc_int_sts;
254 u32 buff_ptr0; /* Buffer pointer Page 0 (12-31) */
255 u32 buff_ptr1; /* Buffer pointer Page 1 (12-31) */
256 u32 buff_ptr2; /* Buffer pointer Page 2 (12-31) */
257 u32 buff_ptr3; /* Buffer pointer Page 3 (12-31) */
258 u32 buff_ptr4; /* Buffer pointer Page 4 (12-31) */
259 u32 reserved1;
260 /* 8 bytes of setup data that follows the Setup PID */
261 u8 setup_buffer[8];
262 u32 reserved2[4];
263};
264
265
266#define DTD_NEXT_TERMINATE (0x00000001)
267#define DTD_IOC (0x00008000)
268#define DTD_STATUS_ACTIVE (0x00000080)
269#define DTD_STATUS_HALTED (0x00000040)
270#define DTD_STATUS_DATA_BUFF_ERR (0x00000020)
271#define DTD_STATUS_TRANSACTION_ERR (0x00000008)
272#define DTD_RESERVED_FIELDS (0x00007F00)
273#define DTD_ERROR_MASK (0x68)
274#define DTD_ADDR_MASK (0xFFFFFFE0)
275#define DTD_PACKET_SIZE 0x7FFF0000
276#define DTD_LENGTH_BIT_POS (16)
277
278struct mv_dtd {
279 u32 dtd_next;
280 u32 size_ioc_sts;
281 u32 buff_ptr0; /* Buffer pointer Page 0 */
282 u32 buff_ptr1; /* Buffer pointer Page 1 */
283 u32 buff_ptr2; /* Buffer pointer Page 2 */
284 u32 buff_ptr3; /* Buffer pointer Page 3 */
285 u32 buff_ptr4; /* Buffer pointer Page 4 */
286 u32 scratch_ptr;
287 /* 32 bytes */
288 dma_addr_t td_dma; /* dma address for this td */
289 struct mv_dtd *next_dtd_virt;
290};
291
292extern int mv_udc_phy_init(unsigned int base);
293
294#endif
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
new file mode 100644
index 000000000000..b1a8146b9d50
--- /dev/null
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -0,0 +1,2149 @@
1#include <linux/module.h>
2#include <linux/pci.h>
3#include <linux/dma-mapping.h>
4#include <linux/dmapool.h>
5#include <linux/kernel.h>
6#include <linux/delay.h>
7#include <linux/ioport.h>
8#include <linux/sched.h>
9#include <linux/slab.h>
10#include <linux/errno.h>
11#include <linux/init.h>
12#include <linux/timer.h>
13#include <linux/list.h>
14#include <linux/interrupt.h>
15#include <linux/moduleparam.h>
16#include <linux/device.h>
17#include <linux/usb/ch9.h>
18#include <linux/usb/gadget.h>
19#include <linux/usb/otg.h>
20#include <linux/pm.h>
21#include <linux/io.h>
22#include <linux/irq.h>
23#include <linux/platform_device.h>
24#include <linux/clk.h>
25#include <asm/system.h>
26#include <asm/unaligned.h>
27
28#include "mv_udc.h"
29
30#define DRIVER_DESC "Marvell PXA USB Device Controller driver"
31#define DRIVER_VERSION "8 Nov 2010"
32
33#define ep_dir(ep) (((ep)->ep_num == 0) ? \
34 ((ep)->udc->ep0_dir) : ((ep)->direction))
35
36/* timeout value -- usec */
37#define RESET_TIMEOUT 10000
38#define FLUSH_TIMEOUT 10000
39#define EPSTATUS_TIMEOUT 10000
40#define PRIME_TIMEOUT 10000
41#define READSAFE_TIMEOUT 1000
42#define DTD_TIMEOUT 1000
43
44#define LOOPS_USEC_SHIFT 4
45#define LOOPS_USEC (1 << LOOPS_USEC_SHIFT)
46#define LOOPS(timeout) ((timeout) >> LOOPS_USEC_SHIFT)
47
48static const char driver_name[] = "mv_udc";
49static const char driver_desc[] = DRIVER_DESC;
50
51/* controller device global variable */
52static struct mv_udc *the_controller;
53int mv_usb_otgsc;
54
55static void nuke(struct mv_ep *ep, int status);
56
57/* for endpoint 0 operations */
58static const struct usb_endpoint_descriptor mv_ep0_desc = {
59 .bLength = USB_DT_ENDPOINT_SIZE,
60 .bDescriptorType = USB_DT_ENDPOINT,
61 .bEndpointAddress = 0,
62 .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
63 .wMaxPacketSize = EP0_MAX_PKT_SIZE,
64};
65
66static void ep0_reset(struct mv_udc *udc)
67{
68 struct mv_ep *ep;
69 u32 epctrlx;
70 int i = 0;
71
72 /* ep0 in and out */
73 for (i = 0; i < 2; i++) {
74 ep = &udc->eps[i];
75 ep->udc = udc;
76
77 /* ep0 dQH */
78 ep->dqh = &udc->ep_dqh[i];
79
80 /* configure ep0 endpoint capabilities in dQH */
81 ep->dqh->max_packet_length =
82 (EP0_MAX_PKT_SIZE << EP_QUEUE_HEAD_MAX_PKT_LEN_POS)
83 | EP_QUEUE_HEAD_IOS;
84
85 epctrlx = readl(&udc->op_regs->epctrlx[0]);
86 if (i) { /* TX */
87 epctrlx |= EPCTRL_TX_ENABLE | EPCTRL_TX_DATA_TOGGLE_RST
88 | (USB_ENDPOINT_XFER_CONTROL
89 << EPCTRL_TX_EP_TYPE_SHIFT);
90
91 } else { /* RX */
92 epctrlx |= EPCTRL_RX_ENABLE | EPCTRL_RX_DATA_TOGGLE_RST
93 | (USB_ENDPOINT_XFER_CONTROL
94 << EPCTRL_RX_EP_TYPE_SHIFT);
95 }
96
97 writel(epctrlx, &udc->op_regs->epctrlx[0]);
98 }
99}
100
101/* protocol ep0 stall, will automatically be cleared on new transaction */
102static void ep0_stall(struct mv_udc *udc)
103{
104 u32 epctrlx;
105
106 /* set TX and RX to stall */
107 epctrlx = readl(&udc->op_regs->epctrlx[0]);
108 epctrlx |= EPCTRL_RX_EP_STALL | EPCTRL_TX_EP_STALL;
109 writel(epctrlx, &udc->op_regs->epctrlx[0]);
110
111 /* update ep0 state */
112 udc->ep0_state = WAIT_FOR_SETUP;
113 udc->ep0_dir = EP_DIR_OUT;
114}
115
116static int process_ep_req(struct mv_udc *udc, int index,
117 struct mv_req *curr_req)
118{
119 struct mv_dtd *curr_dtd;
120 struct mv_dqh *curr_dqh;
121 int td_complete, actual, remaining_length;
122 int i, direction;
123 int retval = 0;
124 u32 errors;
125
126 curr_dqh = &udc->ep_dqh[index];
127 direction = index % 2;
128
129 curr_dtd = curr_req->head;
130 td_complete = 0;
131 actual = curr_req->req.length;
132
133 for (i = 0; i < curr_req->dtd_count; i++) {
134 if (curr_dtd->size_ioc_sts & DTD_STATUS_ACTIVE) {
135 dev_dbg(&udc->dev->dev, "%s, dTD not completed\n",
136 udc->eps[index].name);
137 return 1;
138 }
139
140 errors = curr_dtd->size_ioc_sts & DTD_ERROR_MASK;
141 if (!errors) {
142 remaining_length +=
143 (curr_dtd->size_ioc_sts & DTD_PACKET_SIZE)
144 >> DTD_LENGTH_BIT_POS;
145 actual -= remaining_length;
146 } else {
147 dev_info(&udc->dev->dev,
148 "complete_tr error: ep=%d %s: error = 0x%x\n",
149 index >> 1, direction ? "SEND" : "RECV",
150 errors);
151 if (errors & DTD_STATUS_HALTED) {
152 /* Clear the errors and Halt condition */
153 curr_dqh->size_ioc_int_sts &= ~errors;
154 retval = -EPIPE;
155 } else if (errors & DTD_STATUS_DATA_BUFF_ERR) {
156 retval = -EPROTO;
157 } else if (errors & DTD_STATUS_TRANSACTION_ERR) {
158 retval = -EILSEQ;
159 }
160 }
161 if (i != curr_req->dtd_count - 1)
162 curr_dtd = (struct mv_dtd *)curr_dtd->next_dtd_virt;
163 }
164 if (retval)
165 return retval;
166
167 curr_req->req.actual = actual;
168
169 return 0;
170}
171
172/*
173 * done() - retire a request; caller blocked irqs
174 * @status : request status to be set, only works when
175 * request is still in progress.
176 */
177static void done(struct mv_ep *ep, struct mv_req *req, int status)
178{
179 struct mv_udc *udc = NULL;
180 unsigned char stopped = ep->stopped;
181 struct mv_dtd *curr_td, *next_td;
182 int j;
183
184 udc = (struct mv_udc *)ep->udc;
185 /* Removed the req from fsl_ep->queue */
186 list_del_init(&req->queue);
187
188 /* req.status should be set as -EINPROGRESS in ep_queue() */
189 if (req->req.status == -EINPROGRESS)
190 req->req.status = status;
191 else
192 status = req->req.status;
193
194 /* Free dtd for the request */
195 next_td = req->head;
196 for (j = 0; j < req->dtd_count; j++) {
197 curr_td = next_td;
198 if (j != req->dtd_count - 1)
199 next_td = curr_td->next_dtd_virt;
200 dma_pool_free(udc->dtd_pool, curr_td, curr_td->td_dma);
201 }
202
203 if (req->mapped) {
204 dma_unmap_single(ep->udc->gadget.dev.parent,
205 req->req.dma, req->req.length,
206 ((ep_dir(ep) == EP_DIR_IN) ?
207 DMA_TO_DEVICE : DMA_FROM_DEVICE));
208 req->req.dma = DMA_ADDR_INVALID;
209 req->mapped = 0;
210 } else
211 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
212 req->req.dma, req->req.length,
213 ((ep_dir(ep) == EP_DIR_IN) ?
214 DMA_TO_DEVICE : DMA_FROM_DEVICE));
215
216 if (status && (status != -ESHUTDOWN))
217 dev_info(&udc->dev->dev, "complete %s req %p stat %d len %u/%u",
218 ep->ep.name, &req->req, status,
219 req->req.actual, req->req.length);
220
221 ep->stopped = 1;
222
223 spin_unlock(&ep->udc->lock);
224 /*
225 * complete() is from gadget layer,
226 * eg fsg->bulk_in_complete()
227 */
228 if (req->req.complete)
229 req->req.complete(&ep->ep, &req->req);
230
231 spin_lock(&ep->udc->lock);
232 ep->stopped = stopped;
233}
234
235static int queue_dtd(struct mv_ep *ep, struct mv_req *req)
236{
237 u32 tmp, epstatus, bit_pos, direction;
238 struct mv_udc *udc;
239 struct mv_dqh *dqh;
240 unsigned int loops;
241 int readsafe, retval = 0;
242
243 udc = ep->udc;
244 direction = ep_dir(ep);
245 dqh = &(udc->ep_dqh[ep->ep_num * 2 + direction]);
246 bit_pos = 1 << (((direction == EP_DIR_OUT) ? 0 : 16) + ep->ep_num);
247
248 /* check if the pipe is empty */
249 if (!(list_empty(&ep->queue))) {
250 struct mv_req *lastreq;
251 lastreq = list_entry(ep->queue.prev, struct mv_req, queue);
252 lastreq->tail->dtd_next =
253 req->head->td_dma & EP_QUEUE_HEAD_NEXT_POINTER_MASK;
254 if (readl(&udc->op_regs->epprime) & bit_pos) {
255 loops = LOOPS(PRIME_TIMEOUT);
256 while (readl(&udc->op_regs->epprime) & bit_pos) {
257 if (loops == 0) {
258 retval = -ETIME;
259 goto done;
260 }
261 udelay(LOOPS_USEC);
262 loops--;
263 }
264 if (readl(&udc->op_regs->epstatus) & bit_pos)
265 goto done;
266 }
267 readsafe = 0;
268 loops = LOOPS(READSAFE_TIMEOUT);
269 while (readsafe == 0) {
270 if (loops == 0) {
271 retval = -ETIME;
272 goto done;
273 }
274 /* start with setting the semaphores */
275 tmp = readl(&udc->op_regs->usbcmd);
276 tmp |= USBCMD_ATDTW_TRIPWIRE_SET;
277 writel(tmp, &udc->op_regs->usbcmd);
278
279 /* read the endpoint status */
280 epstatus = readl(&udc->op_regs->epstatus) & bit_pos;
281
282 /*
283 * Reread the ATDTW semaphore bit to check if it is
284 * cleared. When hardware see a hazard, it will clear
285 * the bit or else we remain set to 1 and we can
286 * proceed with priming of endpoint if not already
287 * primed.
288 */
289 if (readl(&udc->op_regs->usbcmd)
290 & USBCMD_ATDTW_TRIPWIRE_SET) {
291 readsafe = 1;
292 }
293 loops--;
294 udelay(LOOPS_USEC);
295 }
296
297 /* Clear the semaphore */
298 tmp = readl(&udc->op_regs->usbcmd);
299 tmp &= USBCMD_ATDTW_TRIPWIRE_CLEAR;
300 writel(tmp, &udc->op_regs->usbcmd);
301
302 /* If endpoint is not active, we activate it now. */
303 if (!epstatus) {
304 if (direction == EP_DIR_IN) {
305 struct mv_dtd *curr_dtd = dma_to_virt(
306 &udc->dev->dev, dqh->curr_dtd_ptr);
307
308 loops = LOOPS(DTD_TIMEOUT);
309 while (curr_dtd->size_ioc_sts
310 & DTD_STATUS_ACTIVE) {
311 if (loops == 0) {
312 retval = -ETIME;
313 goto done;
314 }
315 loops--;
316 udelay(LOOPS_USEC);
317 }
318 }
319 /* No other transfers on the queue */
320
321 /* Write dQH next pointer and terminate bit to 0 */
322 dqh->next_dtd_ptr = req->head->td_dma
323 & EP_QUEUE_HEAD_NEXT_POINTER_MASK;
324 dqh->size_ioc_int_sts = 0;
325
326 /*
327 * Ensure that updates to the QH will
328 * occur before priming.
329 */
330 wmb();
331
332 /* Prime the Endpoint */
333 writel(bit_pos, &udc->op_regs->epprime);
334 }
335 } else {
336 /* Write dQH next pointer and terminate bit to 0 */
337 dqh->next_dtd_ptr = req->head->td_dma
338 & EP_QUEUE_HEAD_NEXT_POINTER_MASK;;
339 dqh->size_ioc_int_sts = 0;
340
341 /* Ensure that updates to the QH will occur before priming. */
342 wmb();
343
344 /* Prime the Endpoint */
345 writel(bit_pos, &udc->op_regs->epprime);
346
347 if (direction == EP_DIR_IN) {
348 /* FIXME add status check after prime the IN ep */
349 int prime_again;
350 u32 curr_dtd_ptr = dqh->curr_dtd_ptr;
351
352 loops = LOOPS(DTD_TIMEOUT);
353 prime_again = 0;
354 while ((curr_dtd_ptr != req->head->td_dma)) {
355 curr_dtd_ptr = dqh->curr_dtd_ptr;
356 if (loops == 0) {
357 dev_err(&udc->dev->dev,
358 "failed to prime %s\n",
359 ep->name);
360 retval = -ETIME;
361 goto done;
362 }
363 loops--;
364 udelay(LOOPS_USEC);
365
366 if (loops == (LOOPS(DTD_TIMEOUT) >> 2)) {
367 if (prime_again)
368 goto done;
369 dev_info(&udc->dev->dev,
370 "prime again\n");
371 writel(bit_pos,
372 &udc->op_regs->epprime);
373 prime_again = 1;
374 }
375 }
376 }
377 }
378done:
379 return retval;;
380}
381
382static struct mv_dtd *build_dtd(struct mv_req *req, unsigned *length,
383 dma_addr_t *dma, int *is_last)
384{
385 u32 temp;
386 struct mv_dtd *dtd;
387 struct mv_udc *udc;
388
389 /* how big will this transfer be? */
390 *length = min(req->req.length - req->req.actual,
391 (unsigned)EP_MAX_LENGTH_TRANSFER);
392
393 udc = req->ep->udc;
394
395 /*
396 * Be careful that no _GFP_HIGHMEM is set,
397 * or we can not use dma_to_virt
398 */
399 dtd = dma_pool_alloc(udc->dtd_pool, GFP_KERNEL, dma);
400 if (dtd == NULL)
401 return dtd;
402
403 dtd->td_dma = *dma;
404 /* initialize buffer page pointers */
405 temp = (u32)(req->req.dma + req->req.actual);
406 dtd->buff_ptr0 = cpu_to_le32(temp);
407 temp &= ~0xFFF;
408 dtd->buff_ptr1 = cpu_to_le32(temp + 0x1000);
409 dtd->buff_ptr2 = cpu_to_le32(temp + 0x2000);
410 dtd->buff_ptr3 = cpu_to_le32(temp + 0x3000);
411 dtd->buff_ptr4 = cpu_to_le32(temp + 0x4000);
412
413 req->req.actual += *length;
414
415 /* zlp is needed if req->req.zero is set */
416 if (req->req.zero) {
417 if (*length == 0 || (*length % req->ep->ep.maxpacket) != 0)
418 *is_last = 1;
419 else
420 *is_last = 0;
421 } else if (req->req.length == req->req.actual)
422 *is_last = 1;
423 else
424 *is_last = 0;
425
426 /* Fill in the transfer size; set active bit */
427 temp = ((*length << DTD_LENGTH_BIT_POS) | DTD_STATUS_ACTIVE);
428
429 /* Enable interrupt for the last dtd of a request */
430 if (*is_last && !req->req.no_interrupt)
431 temp |= DTD_IOC;
432
433 dtd->size_ioc_sts = temp;
434
435 mb();
436
437 return dtd;
438}
439
440/* generate dTD linked list for a request */
441static int req_to_dtd(struct mv_req *req)
442{
443 unsigned count;
444 int is_last, is_first = 1;
445 struct mv_dtd *dtd, *last_dtd = NULL;
446 struct mv_udc *udc;
447 dma_addr_t dma;
448
449 udc = req->ep->udc;
450
451 do {
452 dtd = build_dtd(req, &count, &dma, &is_last);
453 if (dtd == NULL)
454 return -ENOMEM;
455
456 if (is_first) {
457 is_first = 0;
458 req->head = dtd;
459 } else {
460 last_dtd->dtd_next = dma;
461 last_dtd->next_dtd_virt = dtd;
462 }
463 last_dtd = dtd;
464 req->dtd_count++;
465 } while (!is_last);
466
467 /* set terminate bit to 1 for the last dTD */
468 dtd->dtd_next = DTD_NEXT_TERMINATE;
469
470 req->tail = dtd;
471
472 return 0;
473}
474
475static int mv_ep_enable(struct usb_ep *_ep,
476 const struct usb_endpoint_descriptor *desc)
477{
478 struct mv_udc *udc;
479 struct mv_ep *ep;
480 struct mv_dqh *dqh;
481 u16 max = 0;
482 u32 bit_pos, epctrlx, direction;
483 unsigned char zlt = 0, ios = 0, mult = 0;
484
485 ep = container_of(_ep, struct mv_ep, ep);
486 udc = ep->udc;
487
488 if (!_ep || !desc || ep->desc
489 || desc->bDescriptorType != USB_DT_ENDPOINT)
490 return -EINVAL;
491
492 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN)
493 return -ESHUTDOWN;
494
495 direction = ep_dir(ep);
496 max = le16_to_cpu(desc->wMaxPacketSize);
497
498 /*
499 * disable HW zero length termination select
500 * driver handles zero length packet through req->req.zero
501 */
502 zlt = 1;
503
504 /* Get the endpoint queue head address */
505 dqh = (struct mv_dqh *)ep->dqh;
506
507 bit_pos = 1 << ((direction == EP_DIR_OUT ? 0 : 16) + ep->ep_num);
508
509 /* Check if the Endpoint is Primed */
510 if ((readl(&udc->op_regs->epprime) & bit_pos)
511 || (readl(&udc->op_regs->epstatus) & bit_pos)) {
512 dev_info(&udc->dev->dev,
513 "ep=%d %s: Init ERROR: ENDPTPRIME=0x%x,"
514 " ENDPTSTATUS=0x%x, bit_pos=0x%x\n",
515 (unsigned)ep->ep_num, direction ? "SEND" : "RECV",
516 (unsigned)readl(&udc->op_regs->epprime),
517 (unsigned)readl(&udc->op_regs->epstatus),
518 (unsigned)bit_pos);
519 goto en_done;
520 }
521 /* Set the max packet length, interrupt on Setup and Mult fields */
522 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
523 case USB_ENDPOINT_XFER_BULK:
524 zlt = 1;
525 mult = 0;
526 break;
527 case USB_ENDPOINT_XFER_CONTROL:
528 ios = 1;
529 case USB_ENDPOINT_XFER_INT:
530 mult = 0;
531 break;
532 case USB_ENDPOINT_XFER_ISOC:
533 /* Calculate transactions needed for high bandwidth iso */
534 mult = (unsigned char)(1 + ((max >> 11) & 0x03));
535 max = max & 0x8ff; /* bit 0~10 */
536 /* 3 transactions at most */
537 if (mult > 3)
538 goto en_done;
539 break;
540 default:
541 goto en_done;
542 }
543 dqh->max_packet_length = (max << EP_QUEUE_HEAD_MAX_PKT_LEN_POS)
544 | (mult << EP_QUEUE_HEAD_MULT_POS)
545 | (zlt ? EP_QUEUE_HEAD_ZLT_SEL : 0)
546 | (ios ? EP_QUEUE_HEAD_IOS : 0);
547 dqh->next_dtd_ptr = 1;
548 dqh->size_ioc_int_sts = 0;
549
550 ep->ep.maxpacket = max;
551 ep->desc = desc;
552 ep->stopped = 0;
553
554 /* Enable the endpoint for Rx or Tx and set the endpoint type */
555 epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]);
556 if (direction == EP_DIR_IN) {
557 epctrlx &= ~EPCTRL_TX_ALL_MASK;
558 epctrlx |= EPCTRL_TX_ENABLE | EPCTRL_TX_DATA_TOGGLE_RST
559 | ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
560 << EPCTRL_TX_EP_TYPE_SHIFT);
561 } else {
562 epctrlx &= ~EPCTRL_RX_ALL_MASK;
563 epctrlx |= EPCTRL_RX_ENABLE | EPCTRL_RX_DATA_TOGGLE_RST
564 | ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
565 << EPCTRL_RX_EP_TYPE_SHIFT);
566 }
567 writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]);
568
569 /*
570 * Implement Guideline (GL# USB-7) The unused endpoint type must
571 * be programmed to bulk.
572 */
573 epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]);
574 if ((epctrlx & EPCTRL_RX_ENABLE) == 0) {
575 epctrlx |= ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
576 << EPCTRL_RX_EP_TYPE_SHIFT);
577 writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]);
578 }
579
580 epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]);
581 if ((epctrlx & EPCTRL_TX_ENABLE) == 0) {
582 epctrlx |= ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
583 << EPCTRL_TX_EP_TYPE_SHIFT);
584 writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]);
585 }
586
587 return 0;
588en_done:
589 return -EINVAL;
590}
591
592static int mv_ep_disable(struct usb_ep *_ep)
593{
594 struct mv_udc *udc;
595 struct mv_ep *ep;
596 struct mv_dqh *dqh;
597 u32 bit_pos, epctrlx, direction;
598
599 ep = container_of(_ep, struct mv_ep, ep);
600 if ((_ep == NULL) || !ep->desc)
601 return -EINVAL;
602
603 udc = ep->udc;
604
605 /* Get the endpoint queue head address */
606 dqh = ep->dqh;
607
608 direction = ep_dir(ep);
609 bit_pos = 1 << ((direction == EP_DIR_OUT ? 0 : 16) + ep->ep_num);
610
611 /* Reset the max packet length and the interrupt on Setup */
612 dqh->max_packet_length = 0;
613
614 /* Disable the endpoint for Rx or Tx and reset the endpoint type */
615 epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]);
616 epctrlx &= ~((direction == EP_DIR_IN)
617 ? (EPCTRL_TX_ENABLE | EPCTRL_TX_TYPE)
618 : (EPCTRL_RX_ENABLE | EPCTRL_RX_TYPE));
619 writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]);
620
621 /* nuke all pending requests (does flush) */
622 nuke(ep, -ESHUTDOWN);
623
624 ep->desc = NULL;
625 ep->stopped = 1;
626 return 0;
627}
628
629static struct usb_request *
630mv_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
631{
632 struct mv_req *req = NULL;
633
634 req = kzalloc(sizeof *req, gfp_flags);
635 if (!req)
636 return NULL;
637
638 req->req.dma = DMA_ADDR_INVALID;
639 INIT_LIST_HEAD(&req->queue);
640
641 return &req->req;
642}
643
644static void mv_free_request(struct usb_ep *_ep, struct usb_request *_req)
645{
646 struct mv_req *req = NULL;
647
648 req = container_of(_req, struct mv_req, req);
649
650 if (_req)
651 kfree(req);
652}
653
654static void mv_ep_fifo_flush(struct usb_ep *_ep)
655{
656 struct mv_udc *udc;
657 u32 bit_pos, direction;
658 struct mv_ep *ep = container_of(_ep, struct mv_ep, ep);
659 unsigned int loops;
660
661 udc = ep->udc;
662 direction = ep_dir(ep);
663 bit_pos = 1 << ((direction == EP_DIR_OUT ? 0 : 16) + ep->ep_num);
664 /*
665 * Flushing will halt the pipe
666 * Write 1 to the Flush register
667 */
668 writel(bit_pos, &udc->op_regs->epflush);
669
670 /* Wait until flushing completed */
671 loops = LOOPS(FLUSH_TIMEOUT);
672 while (readl(&udc->op_regs->epflush) & bit_pos) {
673 /*
674 * ENDPTFLUSH bit should be cleared to indicate this
675 * operation is complete
676 */
677 if (loops == 0) {
678 dev_err(&udc->dev->dev,
679 "TIMEOUT for ENDPTFLUSH=0x%x, bit_pos=0x%x\n",
680 (unsigned)readl(&udc->op_regs->epflush),
681 (unsigned)bit_pos);
682 return;
683 }
684 loops--;
685 udelay(LOOPS_USEC);
686 }
687 loops = LOOPS(EPSTATUS_TIMEOUT);
688 while (readl(&udc->op_regs->epstatus) & bit_pos) {
689 unsigned int inter_loops;
690
691 if (loops == 0) {
692 dev_err(&udc->dev->dev,
693 "TIMEOUT for ENDPTSTATUS=0x%x, bit_pos=0x%x\n",
694 (unsigned)readl(&udc->op_regs->epstatus),
695 (unsigned)bit_pos);
696 return;
697 }
698 /* Write 1 to the Flush register */
699 writel(bit_pos, &udc->op_regs->epflush);
700
701 /* Wait until flushing completed */
702 inter_loops = LOOPS(FLUSH_TIMEOUT);
703 while (readl(&udc->op_regs->epflush) & bit_pos) {
704 /*
705 * ENDPTFLUSH bit should be cleared to indicate this
706 * operation is complete
707 */
708 if (inter_loops == 0) {
709 dev_err(&udc->dev->dev,
710 "TIMEOUT for ENDPTFLUSH=0x%x,"
711 "bit_pos=0x%x\n",
712 (unsigned)readl(&udc->op_regs->epflush),
713 (unsigned)bit_pos);
714 return;
715 }
716 inter_loops--;
717 udelay(LOOPS_USEC);
718 }
719 loops--;
720 }
721}
722
723/* queues (submits) an I/O request to an endpoint */
724static int
725mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
726{
727 struct mv_ep *ep = container_of(_ep, struct mv_ep, ep);
728 struct mv_req *req = container_of(_req, struct mv_req, req);
729 struct mv_udc *udc = ep->udc;
730 unsigned long flags;
731
732 /* catch various bogus parameters */
733 if (!_req || !req->req.complete || !req->req.buf
734 || !list_empty(&req->queue)) {
735 dev_err(&udc->dev->dev, "%s, bad params", __func__);
736 return -EINVAL;
737 }
738 if (unlikely(!_ep || !ep->desc)) {
739 dev_err(&udc->dev->dev, "%s, bad ep", __func__);
740 return -EINVAL;
741 }
742 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
743 if (req->req.length > ep->ep.maxpacket)
744 return -EMSGSIZE;
745 }
746
747 udc = ep->udc;
748 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN)
749 return -ESHUTDOWN;
750
751 req->ep = ep;
752
753 /* map virtual address to hardware */
754 if (req->req.dma == DMA_ADDR_INVALID) {
755 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent,
756 req->req.buf,
757 req->req.length, ep_dir(ep)
758 ? DMA_TO_DEVICE
759 : DMA_FROM_DEVICE);
760 req->mapped = 1;
761 } else {
762 dma_sync_single_for_device(ep->udc->gadget.dev.parent,
763 req->req.dma, req->req.length,
764 ep_dir(ep)
765 ? DMA_TO_DEVICE
766 : DMA_FROM_DEVICE);
767 req->mapped = 0;
768 }
769
770 req->req.status = -EINPROGRESS;
771 req->req.actual = 0;
772 req->dtd_count = 0;
773
774 spin_lock_irqsave(&udc->lock, flags);
775
776 /* build dtds and push them to device queue */
777 if (!req_to_dtd(req)) {
778 int retval;
779 retval = queue_dtd(ep, req);
780 if (retval) {
781 spin_unlock_irqrestore(&udc->lock, flags);
782 return retval;
783 }
784 } else {
785 spin_unlock_irqrestore(&udc->lock, flags);
786 return -ENOMEM;
787 }
788
789 /* Update ep0 state */
790 if (ep->ep_num == 0)
791 udc->ep0_state = DATA_STATE_XMIT;
792
793 /* irq handler advances the queue */
794 if (req != NULL)
795 list_add_tail(&req->queue, &ep->queue);
796 spin_unlock_irqrestore(&udc->lock, flags);
797
798 return 0;
799}
800
801/* dequeues (cancels, unlinks) an I/O request from an endpoint */
802static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
803{
804 struct mv_ep *ep = container_of(_ep, struct mv_ep, ep);
805 struct mv_req *req;
806 struct mv_udc *udc = ep->udc;
807 unsigned long flags;
808 int stopped, ret = 0;
809 u32 epctrlx;
810
811 if (!_ep || !_req)
812 return -EINVAL;
813
814 spin_lock_irqsave(&ep->udc->lock, flags);
815 stopped = ep->stopped;
816
817 /* Stop the ep before we deal with the queue */
818 ep->stopped = 1;
819 epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]);
820 if (ep_dir(ep) == EP_DIR_IN)
821 epctrlx &= ~EPCTRL_TX_ENABLE;
822 else
823 epctrlx &= ~EPCTRL_RX_ENABLE;
824 writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]);
825
826 /* make sure it's actually queued on this endpoint */
827 list_for_each_entry(req, &ep->queue, queue) {
828 if (&req->req == _req)
829 break;
830 }
831 if (&req->req != _req) {
832 ret = -EINVAL;
833 goto out;
834 }
835
836 /* The request is in progress, or completed but not dequeued */
837 if (ep->queue.next == &req->queue) {
838 _req->status = -ECONNRESET;
839 mv_ep_fifo_flush(_ep); /* flush current transfer */
840
841 /* The request isn't the last request in this ep queue */
842 if (req->queue.next != &ep->queue) {
843 struct mv_dqh *qh;
844 struct mv_req *next_req;
845
846 qh = ep->dqh;
847 next_req = list_entry(req->queue.next, struct mv_req,
848 queue);
849
850 /* Point the QH to the first TD of next request */
851 writel((u32) next_req->head, &qh->curr_dtd_ptr);
852 } else {
853 struct mv_dqh *qh;
854
855 qh = ep->dqh;
856 qh->next_dtd_ptr = 1;
857 qh->size_ioc_int_sts = 0;
858 }
859
860 /* The request hasn't been processed, patch up the TD chain */
861 } else {
862 struct mv_req *prev_req;
863
864 prev_req = list_entry(req->queue.prev, struct mv_req, queue);
865 writel(readl(&req->tail->dtd_next),
866 &prev_req->tail->dtd_next);
867
868 }
869
870 done(ep, req, -ECONNRESET);
871
872 /* Enable EP */
873out:
874 epctrlx = readl(&udc->op_regs->epctrlx[ep->ep_num]);
875 if (ep_dir(ep) == EP_DIR_IN)
876 epctrlx |= EPCTRL_TX_ENABLE;
877 else
878 epctrlx |= EPCTRL_RX_ENABLE;
879 writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]);
880 ep->stopped = stopped;
881
882 spin_unlock_irqrestore(&ep->udc->lock, flags);
883 return ret;
884}
885
886static void ep_set_stall(struct mv_udc *udc, u8 ep_num, u8 direction, int stall)
887{
888 u32 epctrlx;
889
890 epctrlx = readl(&udc->op_regs->epctrlx[ep_num]);
891
892 if (stall) {
893 if (direction == EP_DIR_IN)
894 epctrlx |= EPCTRL_TX_EP_STALL;
895 else
896 epctrlx |= EPCTRL_RX_EP_STALL;
897 } else {
898 if (direction == EP_DIR_IN) {
899 epctrlx &= ~EPCTRL_TX_EP_STALL;
900 epctrlx |= EPCTRL_TX_DATA_TOGGLE_RST;
901 } else {
902 epctrlx &= ~EPCTRL_RX_EP_STALL;
903 epctrlx |= EPCTRL_RX_DATA_TOGGLE_RST;
904 }
905 }
906 writel(epctrlx, &udc->op_regs->epctrlx[ep_num]);
907}
908
909static int ep_is_stall(struct mv_udc *udc, u8 ep_num, u8 direction)
910{
911 u32 epctrlx;
912
913 epctrlx = readl(&udc->op_regs->epctrlx[ep_num]);
914
915 if (direction == EP_DIR_OUT)
916 return (epctrlx & EPCTRL_RX_EP_STALL) ? 1 : 0;
917 else
918 return (epctrlx & EPCTRL_TX_EP_STALL) ? 1 : 0;
919}
920
921static int mv_ep_set_halt_wedge(struct usb_ep *_ep, int halt, int wedge)
922{
923 struct mv_ep *ep;
924 unsigned long flags = 0;
925 int status = 0;
926 struct mv_udc *udc;
927
928 ep = container_of(_ep, struct mv_ep, ep);
929 udc = ep->udc;
930 if (!_ep || !ep->desc) {
931 status = -EINVAL;
932 goto out;
933 }
934
935 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
936 status = -EOPNOTSUPP;
937 goto out;
938 }
939
940 /*
941 * Attempt to halt IN ep will fail if any transfer requests
942 * are still queue
943 */
944 if (halt && (ep_dir(ep) == EP_DIR_IN) && !list_empty(&ep->queue)) {
945 status = -EAGAIN;
946 goto out;
947 }
948
949 spin_lock_irqsave(&ep->udc->lock, flags);
950 ep_set_stall(udc, ep->ep_num, ep_dir(ep), halt);
951 if (halt && wedge)
952 ep->wedge = 1;
953 else if (!halt)
954 ep->wedge = 0;
955 spin_unlock_irqrestore(&ep->udc->lock, flags);
956
957 if (ep->ep_num == 0) {
958 udc->ep0_state = WAIT_FOR_SETUP;
959 udc->ep0_dir = EP_DIR_OUT;
960 }
961out:
962 return status;
963}
964
965static int mv_ep_set_halt(struct usb_ep *_ep, int halt)
966{
967 return mv_ep_set_halt_wedge(_ep, halt, 0);
968}
969
970static int mv_ep_set_wedge(struct usb_ep *_ep)
971{
972 return mv_ep_set_halt_wedge(_ep, 1, 1);
973}
974
975static struct usb_ep_ops mv_ep_ops = {
976 .enable = mv_ep_enable,
977 .disable = mv_ep_disable,
978
979 .alloc_request = mv_alloc_request,
980 .free_request = mv_free_request,
981
982 .queue = mv_ep_queue,
983 .dequeue = mv_ep_dequeue,
984
985 .set_wedge = mv_ep_set_wedge,
986 .set_halt = mv_ep_set_halt,
987 .fifo_flush = mv_ep_fifo_flush, /* flush fifo */
988};
989
990static void udc_stop(struct mv_udc *udc)
991{
992 u32 tmp;
993
994 /* Disable interrupts */
995 tmp = readl(&udc->op_regs->usbintr);
996 tmp &= ~(USBINTR_INT_EN | USBINTR_ERR_INT_EN |
997 USBINTR_PORT_CHANGE_DETECT_EN | USBINTR_RESET_EN);
998 writel(tmp, &udc->op_regs->usbintr);
999
1000 /* Reset the Run the bit in the command register to stop VUSB */
1001 tmp = readl(&udc->op_regs->usbcmd);
1002 tmp &= ~USBCMD_RUN_STOP;
1003 writel(tmp, &udc->op_regs->usbcmd);
1004}
1005
1006static void udc_start(struct mv_udc *udc)
1007{
1008 u32 usbintr;
1009
1010 usbintr = USBINTR_INT_EN | USBINTR_ERR_INT_EN
1011 | USBINTR_PORT_CHANGE_DETECT_EN
1012 | USBINTR_RESET_EN | USBINTR_DEVICE_SUSPEND;
1013 /* Enable interrupts */
1014 writel(usbintr, &udc->op_regs->usbintr);
1015
1016 /* Set the Run bit in the command register */
1017 writel(USBCMD_RUN_STOP, &udc->op_regs->usbcmd);
1018}
1019
1020static int udc_reset(struct mv_udc *udc)
1021{
1022 unsigned int loops;
1023 u32 tmp, portsc;
1024
1025 /* Stop the controller */
1026 tmp = readl(&udc->op_regs->usbcmd);
1027 tmp &= ~USBCMD_RUN_STOP;
1028 writel(tmp, &udc->op_regs->usbcmd);
1029
1030 /* Reset the controller to get default values */
1031 writel(USBCMD_CTRL_RESET, &udc->op_regs->usbcmd);
1032
1033 /* wait for reset to complete */
1034 loops = LOOPS(RESET_TIMEOUT);
1035 while (readl(&udc->op_regs->usbcmd) & USBCMD_CTRL_RESET) {
1036 if (loops == 0) {
1037 dev_err(&udc->dev->dev,
1038 "Wait for RESET completed TIMEOUT\n");
1039 return -ETIMEDOUT;
1040 }
1041 loops--;
1042 udelay(LOOPS_USEC);
1043 }
1044
1045 /* set controller to device mode */
1046 tmp = readl(&udc->op_regs->usbmode);
1047 tmp |= USBMODE_CTRL_MODE_DEVICE;
1048
1049 /* turn setup lockout off, require setup tripwire in usbcmd */
1050 tmp |= USBMODE_SETUP_LOCK_OFF | USBMODE_STREAM_DISABLE;
1051
1052 writel(tmp, &udc->op_regs->usbmode);
1053
1054 writel(0x0, &udc->op_regs->epsetupstat);
1055
1056 /* Configure the Endpoint List Address */
1057 writel(udc->ep_dqh_dma & USB_EP_LIST_ADDRESS_MASK,
1058 &udc->op_regs->eplistaddr);
1059
1060 portsc = readl(&udc->op_regs->portsc[0]);
1061 if (readl(&udc->cap_regs->hcsparams) & HCSPARAMS_PPC)
1062 portsc &= (~PORTSCX_W1C_BITS | ~PORTSCX_PORT_POWER);
1063
1064 if (udc->force_fs)
1065 portsc |= PORTSCX_FORCE_FULL_SPEED_CONNECT;
1066 else
1067 portsc &= (~PORTSCX_FORCE_FULL_SPEED_CONNECT);
1068
1069 writel(portsc, &udc->op_regs->portsc[0]);
1070
1071 tmp = readl(&udc->op_regs->epctrlx[0]);
1072 tmp &= ~(EPCTRL_TX_EP_STALL | EPCTRL_RX_EP_STALL);
1073 writel(tmp, &udc->op_regs->epctrlx[0]);
1074
1075 return 0;
1076}
1077
1078static int mv_udc_get_frame(struct usb_gadget *gadget)
1079{
1080 struct mv_udc *udc;
1081 u16 retval;
1082
1083 if (!gadget)
1084 return -ENODEV;
1085
1086 udc = container_of(gadget, struct mv_udc, gadget);
1087
1088 retval = readl(udc->op_regs->frindex) & USB_FRINDEX_MASKS;
1089
1090 return retval;
1091}
1092
1093/* Tries to wake up the host connected to this gadget */
1094static int mv_udc_wakeup(struct usb_gadget *gadget)
1095{
1096 struct mv_udc *udc = container_of(gadget, struct mv_udc, gadget);
1097 u32 portsc;
1098
1099 /* Remote wakeup feature not enabled by host */
1100 if (!udc->remote_wakeup)
1101 return -ENOTSUPP;
1102
1103 portsc = readl(&udc->op_regs->portsc);
1104 /* not suspended? */
1105 if (!(portsc & PORTSCX_PORT_SUSPEND))
1106 return 0;
1107 /* trigger force resume */
1108 portsc |= PORTSCX_PORT_FORCE_RESUME;
1109 writel(portsc, &udc->op_regs->portsc[0]);
1110 return 0;
1111}
1112
1113static int mv_udc_pullup(struct usb_gadget *gadget, int is_on)
1114{
1115 struct mv_udc *udc;
1116 unsigned long flags;
1117
1118 udc = container_of(gadget, struct mv_udc, gadget);
1119 spin_lock_irqsave(&udc->lock, flags);
1120
1121 udc->softconnect = (is_on != 0);
1122 if (udc->driver && udc->softconnect)
1123 udc_start(udc);
1124 else
1125 udc_stop(udc);
1126
1127 spin_unlock_irqrestore(&udc->lock, flags);
1128 return 0;
1129}
1130
1131/* device controller usb_gadget_ops structure */
1132static const struct usb_gadget_ops mv_ops = {
1133
1134 /* returns the current frame number */
1135 .get_frame = mv_udc_get_frame,
1136
1137 /* tries to wake up the host connected to this gadget */
1138 .wakeup = mv_udc_wakeup,
1139
1140 /* D+ pullup, software-controlled connect/disconnect to USB host */
1141 .pullup = mv_udc_pullup,
1142};
1143
1144static void mv_udc_testmode(struct mv_udc *udc, u16 index, bool enter)
1145{
1146 dev_info(&udc->dev->dev, "Test Mode is not support yet\n");
1147}
1148
1149static int eps_init(struct mv_udc *udc)
1150{
1151 struct mv_ep *ep;
1152 char name[14];
1153 int i;
1154
1155 /* initialize ep0 */
1156 ep = &udc->eps[0];
1157 ep->udc = udc;
1158 strncpy(ep->name, "ep0", sizeof(ep->name));
1159 ep->ep.name = ep->name;
1160 ep->ep.ops = &mv_ep_ops;
1161 ep->wedge = 0;
1162 ep->stopped = 0;
1163 ep->ep.maxpacket = EP0_MAX_PKT_SIZE;
1164 ep->ep_num = 0;
1165 ep->desc = &mv_ep0_desc;
1166 INIT_LIST_HEAD(&ep->queue);
1167
1168 ep->ep_type = USB_ENDPOINT_XFER_CONTROL;
1169
1170 /* initialize other endpoints */
1171 for (i = 2; i < udc->max_eps * 2; i++) {
1172 ep = &udc->eps[i];
1173 if (i % 2) {
1174 snprintf(name, sizeof(name), "ep%din", i / 2);
1175 ep->direction = EP_DIR_IN;
1176 } else {
1177 snprintf(name, sizeof(name), "ep%dout", i / 2);
1178 ep->direction = EP_DIR_OUT;
1179 }
1180 ep->udc = udc;
1181 strncpy(ep->name, name, sizeof(ep->name));
1182 ep->ep.name = ep->name;
1183
1184 ep->ep.ops = &mv_ep_ops;
1185 ep->stopped = 0;
1186 ep->ep.maxpacket = (unsigned short) ~0;
1187 ep->ep_num = i / 2;
1188
1189 INIT_LIST_HEAD(&ep->queue);
1190 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
1191
1192 ep->dqh = &udc->ep_dqh[i];
1193 }
1194
1195 return 0;
1196}
1197
1198/* delete all endpoint requests, called with spinlock held */
1199static void nuke(struct mv_ep *ep, int status)
1200{
1201 /* called with spinlock held */
1202 ep->stopped = 1;
1203
1204 /* endpoint fifo flush */
1205 mv_ep_fifo_flush(&ep->ep);
1206
1207 while (!list_empty(&ep->queue)) {
1208 struct mv_req *req = NULL;
1209 req = list_entry(ep->queue.next, struct mv_req, queue);
1210 done(ep, req, status);
1211 }
1212}
1213
1214/* stop all USB activities */
1215static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver)
1216{
1217 struct mv_ep *ep;
1218
1219 nuke(&udc->eps[0], -ESHUTDOWN);
1220
1221 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
1222 nuke(ep, -ESHUTDOWN);
1223 }
1224
1225 /* report disconnect; the driver is already quiesced */
1226 if (driver) {
1227 spin_unlock(&udc->lock);
1228 driver->disconnect(&udc->gadget);
1229 spin_lock(&udc->lock);
1230 }
1231}
1232
1233int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1234 int (*bind)(struct usb_gadget *))
1235{
1236 struct mv_udc *udc = the_controller;
1237 int retval = 0;
1238 unsigned long flags;
1239
1240 if (!udc)
1241 return -ENODEV;
1242
1243 if (udc->driver)
1244 return -EBUSY;
1245
1246 spin_lock_irqsave(&udc->lock, flags);
1247
1248 /* hook up the driver ... */
1249 driver->driver.bus = NULL;
1250 udc->driver = driver;
1251 udc->gadget.dev.driver = &driver->driver;
1252
1253 udc->usb_state = USB_STATE_ATTACHED;
1254 udc->ep0_state = WAIT_FOR_SETUP;
1255 udc->ep0_dir = USB_DIR_OUT;
1256
1257 spin_unlock_irqrestore(&udc->lock, flags);
1258
1259 retval = bind(&udc->gadget);
1260 if (retval) {
1261 dev_err(&udc->dev->dev, "bind to driver %s --> %d\n",
1262 driver->driver.name, retval);
1263 udc->driver = NULL;
1264 udc->gadget.dev.driver = NULL;
1265 return retval;
1266 }
1267 udc_reset(udc);
1268 ep0_reset(udc);
1269 udc_start(udc);
1270
1271 return 0;
1272}
1273EXPORT_SYMBOL(usb_gadget_probe_driver);
1274
1275int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1276{
1277 struct mv_udc *udc = the_controller;
1278 unsigned long flags;
1279
1280 if (!udc)
1281 return -ENODEV;
1282
1283 udc_stop(udc);
1284
1285 spin_lock_irqsave(&udc->lock, flags);
1286
1287 /* stop all usb activities */
1288 udc->gadget.speed = USB_SPEED_UNKNOWN;
1289 stop_activity(udc, driver);
1290 spin_unlock_irqrestore(&udc->lock, flags);
1291
1292 /* unbind gadget driver */
1293 driver->unbind(&udc->gadget);
1294 udc->gadget.dev.driver = NULL;
1295 udc->driver = NULL;
1296
1297 return 0;
1298}
1299EXPORT_SYMBOL(usb_gadget_unregister_driver);
1300
1301static int
1302udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty)
1303{
1304 int retval = 0;
1305 struct mv_req *req;
1306 struct mv_ep *ep;
1307
1308 ep = &udc->eps[0];
1309 udc->ep0_dir = direction;
1310
1311 req = udc->status_req;
1312
1313 /* fill in the reqest structure */
1314 if (empty == false) {
1315 *((u16 *) req->req.buf) = cpu_to_le16(status);
1316 req->req.length = 2;
1317 } else
1318 req->req.length = 0;
1319
1320 req->ep = ep;
1321 req->req.status = -EINPROGRESS;
1322 req->req.actual = 0;
1323 req->req.complete = NULL;
1324 req->dtd_count = 0;
1325
1326 /* prime the data phase */
1327 if (!req_to_dtd(req))
1328 retval = queue_dtd(ep, req);
1329 else{ /* no mem */
1330 retval = -ENOMEM;
1331 goto out;
1332 }
1333
1334 if (retval) {
1335 dev_err(&udc->dev->dev, "response error on GET_STATUS request\n");
1336 goto out;
1337 }
1338
1339 list_add_tail(&req->queue, &ep->queue);
1340
1341 return 0;
1342out:
1343 return retval;
1344}
1345
1346static void ch9setaddress(struct mv_udc *udc, struct usb_ctrlrequest *setup)
1347{
1348 udc->dev_addr = (u8)setup->wValue;
1349
1350 /* update usb state */
1351 udc->usb_state = USB_STATE_ADDRESS;
1352
1353 if (udc_prime_status(udc, EP_DIR_IN, 0, true))
1354 ep0_stall(udc);
1355}
1356
1357static void ch9getstatus(struct mv_udc *udc, u8 ep_num,
1358 struct usb_ctrlrequest *setup)
1359{
1360 u16 status;
1361 int retval;
1362
1363 if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK))
1364 != (USB_DIR_IN | USB_TYPE_STANDARD))
1365 return;
1366
1367 if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) {
1368 status = 1 << USB_DEVICE_SELF_POWERED;
1369 status |= udc->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP;
1370 } else if ((setup->bRequestType & USB_RECIP_MASK)
1371 == USB_RECIP_INTERFACE) {
1372 /* get interface status */
1373 status = 0;
1374 } else if ((setup->bRequestType & USB_RECIP_MASK)
1375 == USB_RECIP_ENDPOINT) {
1376 u8 ep_num, direction;
1377
1378 ep_num = setup->wIndex & USB_ENDPOINT_NUMBER_MASK;
1379 direction = (setup->wIndex & USB_ENDPOINT_DIR_MASK)
1380 ? EP_DIR_IN : EP_DIR_OUT;
1381 status = ep_is_stall(udc, ep_num, direction)
1382 << USB_ENDPOINT_HALT;
1383 }
1384
1385 retval = udc_prime_status(udc, EP_DIR_IN, status, false);
1386 if (retval)
1387 ep0_stall(udc);
1388}
1389
1390static void ch9clearfeature(struct mv_udc *udc, struct usb_ctrlrequest *setup)
1391{
1392 u8 ep_num;
1393 u8 direction;
1394 struct mv_ep *ep;
1395
1396 if ((setup->bRequestType & (USB_TYPE_MASK | USB_RECIP_MASK))
1397 == ((USB_TYPE_STANDARD | USB_RECIP_DEVICE))) {
1398 switch (setup->wValue) {
1399 case USB_DEVICE_REMOTE_WAKEUP:
1400 udc->remote_wakeup = 0;
1401 break;
1402 case USB_DEVICE_TEST_MODE:
1403 mv_udc_testmode(udc, 0, false);
1404 break;
1405 default:
1406 goto out;
1407 }
1408 } else if ((setup->bRequestType & (USB_TYPE_MASK | USB_RECIP_MASK))
1409 == ((USB_TYPE_STANDARD | USB_RECIP_ENDPOINT))) {
1410 switch (setup->wValue) {
1411 case USB_ENDPOINT_HALT:
1412 ep_num = setup->wIndex & USB_ENDPOINT_NUMBER_MASK;
1413 direction = (setup->wIndex & USB_ENDPOINT_DIR_MASK)
1414 ? EP_DIR_IN : EP_DIR_OUT;
1415 if (setup->wValue != 0 || setup->wLength != 0
1416 || ep_num > udc->max_eps)
1417 goto out;
1418 ep = &udc->eps[ep_num * 2 + direction];
1419 if (ep->wedge == 1)
1420 break;
1421 spin_unlock(&udc->lock);
1422 ep_set_stall(udc, ep_num, direction, 0);
1423 spin_lock(&udc->lock);
1424 break;
1425 default:
1426 goto out;
1427 }
1428 } else
1429 goto out;
1430
1431 if (udc_prime_status(udc, EP_DIR_IN, 0, true))
1432 ep0_stall(udc);
1433 else
1434 udc->ep0_state = DATA_STATE_XMIT;
1435out:
1436 return;
1437}
1438
1439static void ch9setfeature(struct mv_udc *udc, struct usb_ctrlrequest *setup)
1440{
1441 u8 ep_num;
1442 u8 direction;
1443
1444 if ((setup->bRequestType & (USB_TYPE_MASK | USB_RECIP_MASK))
1445 == ((USB_TYPE_STANDARD | USB_RECIP_DEVICE))) {
1446 switch (setup->wValue) {
1447 case USB_DEVICE_REMOTE_WAKEUP:
1448 udc->remote_wakeup = 1;
1449 break;
1450 case USB_DEVICE_TEST_MODE:
1451 if (setup->wIndex & 0xFF
1452 && udc->gadget.speed != USB_SPEED_HIGH)
1453 goto out;
1454 if (udc->usb_state == USB_STATE_CONFIGURED
1455 || udc->usb_state == USB_STATE_ADDRESS
1456 || udc->usb_state == USB_STATE_DEFAULT)
1457 mv_udc_testmode(udc,
1458 setup->wIndex & 0xFF00, true);
1459 else
1460 goto out;
1461 break;
1462 default:
1463 goto out;
1464 }
1465 } else if ((setup->bRequestType & (USB_TYPE_MASK | USB_RECIP_MASK))
1466 == ((USB_TYPE_STANDARD | USB_RECIP_ENDPOINT))) {
1467 switch (setup->wValue) {
1468 case USB_ENDPOINT_HALT:
1469 ep_num = setup->wIndex & USB_ENDPOINT_NUMBER_MASK;
1470 direction = (setup->wIndex & USB_ENDPOINT_DIR_MASK)
1471 ? EP_DIR_IN : EP_DIR_OUT;
1472 if (setup->wValue != 0 || setup->wLength != 0
1473 || ep_num > udc->max_eps)
1474 goto out;
1475 spin_unlock(&udc->lock);
1476 ep_set_stall(udc, ep_num, direction, 1);
1477 spin_lock(&udc->lock);
1478 break;
1479 default:
1480 goto out;
1481 }
1482 } else
1483 goto out;
1484
1485 if (udc_prime_status(udc, EP_DIR_IN, 0, true))
1486 ep0_stall(udc);
1487out:
1488 return;
1489}
1490
1491static void handle_setup_packet(struct mv_udc *udc, u8 ep_num,
1492 struct usb_ctrlrequest *setup)
1493{
1494 bool delegate = false;
1495
1496 nuke(&udc->eps[ep_num * 2 + EP_DIR_OUT], -ESHUTDOWN);
1497
1498 dev_dbg(&udc->dev->dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1499 setup->bRequestType, setup->bRequest,
1500 setup->wValue, setup->wIndex, setup->wLength);
1501 /* We process some stardard setup requests here */
1502 if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
1503 switch (setup->bRequest) {
1504 case USB_REQ_GET_STATUS:
1505 ch9getstatus(udc, ep_num, setup);
1506 break;
1507
1508 case USB_REQ_SET_ADDRESS:
1509 ch9setaddress(udc, setup);
1510 break;
1511
1512 case USB_REQ_CLEAR_FEATURE:
1513 ch9clearfeature(udc, setup);
1514 break;
1515
1516 case USB_REQ_SET_FEATURE:
1517 ch9setfeature(udc, setup);
1518 break;
1519
1520 default:
1521 delegate = true;
1522 }
1523 } else
1524 delegate = true;
1525
1526 /* delegate USB standard requests to the gadget driver */
1527 if (delegate == true) {
1528 /* USB requests handled by gadget */
1529 if (setup->wLength) {
1530 /* DATA phase from gadget, STATUS phase from udc */
1531 udc->ep0_dir = (setup->bRequestType & USB_DIR_IN)
1532 ? EP_DIR_IN : EP_DIR_OUT;
1533 spin_unlock(&udc->lock);
1534 if (udc->driver->setup(&udc->gadget,
1535 &udc->local_setup_buff) < 0)
1536 ep0_stall(udc);
1537 spin_lock(&udc->lock);
1538 udc->ep0_state = (setup->bRequestType & USB_DIR_IN)
1539 ? DATA_STATE_XMIT : DATA_STATE_RECV;
1540 } else {
1541 /* no DATA phase, IN STATUS phase from gadget */
1542 udc->ep0_dir = EP_DIR_IN;
1543 spin_unlock(&udc->lock);
1544 if (udc->driver->setup(&udc->gadget,
1545 &udc->local_setup_buff) < 0)
1546 ep0_stall(udc);
1547 spin_lock(&udc->lock);
1548 udc->ep0_state = WAIT_FOR_OUT_STATUS;
1549 }
1550 }
1551}
1552
1553/* complete DATA or STATUS phase of ep0 prime status phase if needed */
1554static void ep0_req_complete(struct mv_udc *udc,
1555 struct mv_ep *ep0, struct mv_req *req)
1556{
1557 u32 new_addr;
1558
1559 if (udc->usb_state == USB_STATE_ADDRESS) {
1560 /* set the new address */
1561 new_addr = (u32)udc->dev_addr;
1562 writel(new_addr << USB_DEVICE_ADDRESS_BIT_SHIFT,
1563 &udc->op_regs->deviceaddr);
1564 }
1565
1566 done(ep0, req, 0);
1567
1568 switch (udc->ep0_state) {
1569 case DATA_STATE_XMIT:
1570 /* receive status phase */
1571 if (udc_prime_status(udc, EP_DIR_OUT, 0, true))
1572 ep0_stall(udc);
1573 break;
1574 case DATA_STATE_RECV:
1575 /* send status phase */
1576 if (udc_prime_status(udc, EP_DIR_IN, 0 , true))
1577 ep0_stall(udc);
1578 break;
1579 case WAIT_FOR_OUT_STATUS:
1580 udc->ep0_state = WAIT_FOR_SETUP;
1581 break;
1582 case WAIT_FOR_SETUP:
1583 dev_err(&udc->dev->dev, "unexpect ep0 packets\n");
1584 break;
1585 default:
1586 ep0_stall(udc);
1587 break;
1588 }
1589}
1590
1591static void get_setup_data(struct mv_udc *udc, u8 ep_num, u8 *buffer_ptr)
1592{
1593 u32 temp;
1594 struct mv_dqh *dqh;
1595
1596 dqh = &udc->ep_dqh[ep_num * 2 + EP_DIR_OUT];
1597
1598 /* Clear bit in ENDPTSETUPSTAT */
1599 temp = readl(&udc->op_regs->epsetupstat);
1600 writel(temp | (1 << ep_num), &udc->op_regs->epsetupstat);
1601
1602 /* while a hazard exists when setup package arrives */
1603 do {
1604 /* Set Setup Tripwire */
1605 temp = readl(&udc->op_regs->usbcmd);
1606 writel(temp | USBCMD_SETUP_TRIPWIRE_SET, &udc->op_regs->usbcmd);
1607
1608 /* Copy the setup packet to local buffer */
1609 memcpy(buffer_ptr, (u8 *) dqh->setup_buffer, 8);
1610 } while (!(readl(&udc->op_regs->usbcmd) & USBCMD_SETUP_TRIPWIRE_SET));
1611
1612 /* Clear Setup Tripwire */
1613 temp = readl(&udc->op_regs->usbcmd);
1614 writel(temp & ~USBCMD_SETUP_TRIPWIRE_SET, &udc->op_regs->usbcmd);
1615}
1616
1617static void irq_process_tr_complete(struct mv_udc *udc)
1618{
1619 u32 tmp, bit_pos;
1620 int i, ep_num = 0, direction = 0;
1621 struct mv_ep *curr_ep;
1622 struct mv_req *curr_req, *temp_req;
1623 int status;
1624
1625 /*
1626 * We use separate loops for ENDPTSETUPSTAT and ENDPTCOMPLETE
1627 * because the setup packets are to be read ASAP
1628 */
1629
1630 /* Process all Setup packet received interrupts */
1631 tmp = readl(&udc->op_regs->epsetupstat);
1632
1633 if (tmp) {
1634 for (i = 0; i < udc->max_eps; i++) {
1635 if (tmp & (1 << i)) {
1636 get_setup_data(udc, i,
1637 (u8 *)(&udc->local_setup_buff));
1638 handle_setup_packet(udc, i,
1639 &udc->local_setup_buff);
1640 }
1641 }
1642 }
1643
1644 /* Don't clear the endpoint setup status register here.
1645 * It is cleared as a setup packet is read out of the buffer
1646 */
1647
1648 /* Process non-setup transaction complete interrupts */
1649 tmp = readl(&udc->op_regs->epcomplete);
1650
1651 if (!tmp)
1652 return;
1653
1654 writel(tmp, &udc->op_regs->epcomplete);
1655
1656 for (i = 0; i < udc->max_eps * 2; i++) {
1657 ep_num = i >> 1;
1658 direction = i % 2;
1659
1660 bit_pos = 1 << (ep_num + 16 * direction);
1661
1662 if (!(bit_pos & tmp))
1663 continue;
1664
1665 if (i == 1)
1666 curr_ep = &udc->eps[0];
1667 else
1668 curr_ep = &udc->eps[i];
1669 /* process the req queue until an uncomplete request */
1670 list_for_each_entry_safe(curr_req, temp_req,
1671 &curr_ep->queue, queue) {
1672 status = process_ep_req(udc, i, curr_req);
1673 if (status)
1674 break;
1675
1676 /* write back status to req */
1677 curr_req->req.status = status;
1678
1679 /* ep0 request completion */
1680 if (ep_num == 0) {
1681 ep0_req_complete(udc, curr_ep, curr_req);
1682 break;
1683 } else {
1684 done(curr_ep, curr_req, status);
1685 }
1686 }
1687 }
1688}
1689
1690void irq_process_reset(struct mv_udc *udc)
1691{
1692 u32 tmp;
1693 unsigned int loops;
1694
1695 udc->ep0_dir = EP_DIR_OUT;
1696 udc->ep0_state = WAIT_FOR_SETUP;
1697 udc->remote_wakeup = 0; /* default to 0 on reset */
1698
1699 /* The address bits are past bit 25-31. Set the address */
1700 tmp = readl(&udc->op_regs->deviceaddr);
1701 tmp &= ~(USB_DEVICE_ADDRESS_MASK);
1702 writel(tmp, &udc->op_regs->deviceaddr);
1703
1704 /* Clear all the setup token semaphores */
1705 tmp = readl(&udc->op_regs->epsetupstat);
1706 writel(tmp, &udc->op_regs->epsetupstat);
1707
1708 /* Clear all the endpoint complete status bits */
1709 tmp = readl(&udc->op_regs->epcomplete);
1710 writel(tmp, &udc->op_regs->epcomplete);
1711
1712 /* wait until all endptprime bits cleared */
1713 loops = LOOPS(PRIME_TIMEOUT);
1714 while (readl(&udc->op_regs->epprime) & 0xFFFFFFFF) {
1715 if (loops == 0) {
1716 dev_err(&udc->dev->dev,
1717 "Timeout for ENDPTPRIME = 0x%x\n",
1718 readl(&udc->op_regs->epprime));
1719 break;
1720 }
1721 loops--;
1722 udelay(LOOPS_USEC);
1723 }
1724
1725 /* Write 1s to the Flush register */
1726 writel((u32)~0, &udc->op_regs->epflush);
1727
1728 if (readl(&udc->op_regs->portsc[0]) & PORTSCX_PORT_RESET) {
1729 dev_info(&udc->dev->dev, "usb bus reset\n");
1730 udc->usb_state = USB_STATE_DEFAULT;
1731 /* reset all the queues, stop all USB activities */
1732 stop_activity(udc, udc->driver);
1733 } else {
1734 dev_info(&udc->dev->dev, "USB reset portsc 0x%x\n",
1735 readl(&udc->op_regs->portsc));
1736
1737 /*
1738 * re-initialize
1739 * controller reset
1740 */
1741 udc_reset(udc);
1742
1743 /* reset all the queues, stop all USB activities */
1744 stop_activity(udc, udc->driver);
1745
1746 /* reset ep0 dQH and endptctrl */
1747 ep0_reset(udc);
1748
1749 /* enable interrupt and set controller to run state */
1750 udc_start(udc);
1751
1752 udc->usb_state = USB_STATE_ATTACHED;
1753 }
1754}
1755
1756static void handle_bus_resume(struct mv_udc *udc)
1757{
1758 udc->usb_state = udc->resume_state;
1759 udc->resume_state = 0;
1760
1761 /* report resume to the driver */
1762 if (udc->driver) {
1763 if (udc->driver->resume) {
1764 spin_unlock(&udc->lock);
1765 udc->driver->resume(&udc->gadget);
1766 spin_lock(&udc->lock);
1767 }
1768 }
1769}
1770
1771static void irq_process_suspend(struct mv_udc *udc)
1772{
1773 udc->resume_state = udc->usb_state;
1774 udc->usb_state = USB_STATE_SUSPENDED;
1775
1776 if (udc->driver->suspend) {
1777 spin_unlock(&udc->lock);
1778 udc->driver->suspend(&udc->gadget);
1779 spin_lock(&udc->lock);
1780 }
1781}
1782
1783static void irq_process_port_change(struct mv_udc *udc)
1784{
1785 u32 portsc;
1786
1787 portsc = readl(&udc->op_regs->portsc[0]);
1788 if (!(portsc & PORTSCX_PORT_RESET)) {
1789 /* Get the speed */
1790 u32 speed = portsc & PORTSCX_PORT_SPEED_MASK;
1791 switch (speed) {
1792 case PORTSCX_PORT_SPEED_HIGH:
1793 udc->gadget.speed = USB_SPEED_HIGH;
1794 break;
1795 case PORTSCX_PORT_SPEED_FULL:
1796 udc->gadget.speed = USB_SPEED_FULL;
1797 break;
1798 case PORTSCX_PORT_SPEED_LOW:
1799 udc->gadget.speed = USB_SPEED_LOW;
1800 break;
1801 default:
1802 udc->gadget.speed = USB_SPEED_UNKNOWN;
1803 break;
1804 }
1805 }
1806
1807 if (portsc & PORTSCX_PORT_SUSPEND) {
1808 udc->resume_state = udc->usb_state;
1809 udc->usb_state = USB_STATE_SUSPENDED;
1810 if (udc->driver->suspend) {
1811 spin_unlock(&udc->lock);
1812 udc->driver->suspend(&udc->gadget);
1813 spin_lock(&udc->lock);
1814 }
1815 }
1816
1817 if (!(portsc & PORTSCX_PORT_SUSPEND)
1818 && udc->usb_state == USB_STATE_SUSPENDED) {
1819 handle_bus_resume(udc);
1820 }
1821
1822 if (!udc->resume_state)
1823 udc->usb_state = USB_STATE_DEFAULT;
1824}
1825
1826static void irq_process_error(struct mv_udc *udc)
1827{
1828 /* Increment the error count */
1829 udc->errors++;
1830}
1831
1832static irqreturn_t mv_udc_irq(int irq, void *dev)
1833{
1834 struct mv_udc *udc = (struct mv_udc *)dev;
1835 u32 status, intr;
1836
1837 spin_lock(&udc->lock);
1838
1839 status = readl(&udc->op_regs->usbsts);
1840 intr = readl(&udc->op_regs->usbintr);
1841 status &= intr;
1842
1843 if (status == 0) {
1844 spin_unlock(&udc->lock);
1845 return IRQ_NONE;
1846 }
1847
1848 /* Clear all the interrupts occurred */
1849 writel(status, &udc->op_regs->usbsts);
1850
1851 if (status & USBSTS_ERR)
1852 irq_process_error(udc);
1853
1854 if (status & USBSTS_RESET)
1855 irq_process_reset(udc);
1856
1857 if (status & USBSTS_PORT_CHANGE)
1858 irq_process_port_change(udc);
1859
1860 if (status & USBSTS_INT)
1861 irq_process_tr_complete(udc);
1862
1863 if (status & USBSTS_SUSPEND)
1864 irq_process_suspend(udc);
1865
1866 spin_unlock(&udc->lock);
1867
1868 return IRQ_HANDLED;
1869}
1870
1871/* release device structure */
1872static void gadget_release(struct device *_dev)
1873{
1874 struct mv_udc *udc = the_controller;
1875
1876 complete(udc->done);
1877 kfree(udc);
1878}
1879
1880static int mv_udc_remove(struct platform_device *dev)
1881{
1882 struct mv_udc *udc = the_controller;
1883
1884 DECLARE_COMPLETION(done);
1885
1886 udc->done = &done;
1887
1888 /* free memory allocated in probe */
1889 if (udc->dtd_pool)
1890 dma_pool_destroy(udc->dtd_pool);
1891
1892 if (udc->ep_dqh)
1893 dma_free_coherent(&dev->dev, udc->ep_dqh_size,
1894 udc->ep_dqh, udc->ep_dqh_dma);
1895
1896 kfree(udc->eps);
1897
1898 if (udc->irq)
1899 free_irq(udc->irq, &dev->dev);
1900
1901 if (udc->cap_regs)
1902 iounmap(udc->cap_regs);
1903 udc->cap_regs = NULL;
1904
1905 if (udc->phy_regs)
1906 iounmap((void *)udc->phy_regs);
1907 udc->phy_regs = 0;
1908
1909 if (udc->status_req) {
1910 kfree(udc->status_req->req.buf);
1911 kfree(udc->status_req);
1912 }
1913
1914 device_unregister(&udc->gadget.dev);
1915
1916 /* free dev, wait for the release() finished */
1917 wait_for_completion(&done);
1918
1919 the_controller = NULL;
1920
1921 return 0;
1922}
1923
1924int mv_udc_probe(struct platform_device *dev)
1925{
1926 struct mv_udc *udc;
1927 int retval = 0;
1928 struct resource *r;
1929 size_t size;
1930
1931 udc = kzalloc(sizeof *udc, GFP_KERNEL);
1932 if (udc == NULL) {
1933 dev_err(&dev->dev, "failed to allocate memory for udc\n");
1934 retval = -ENOMEM;
1935 goto error;
1936 }
1937
1938 spin_lock_init(&udc->lock);
1939
1940 udc->dev = dev;
1941
1942 udc->clk = clk_get(&dev->dev, "U2OCLK");
1943 if (IS_ERR(udc->clk)) {
1944 retval = PTR_ERR(udc->clk);
1945 goto error;
1946 }
1947
1948 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "u2o");
1949 if (r == NULL) {
1950 dev_err(&dev->dev, "no I/O memory resource defined\n");
1951 retval = -ENODEV;
1952 goto error;
1953 }
1954
1955 udc->cap_regs = (struct mv_cap_regs __iomem *)
1956 ioremap(r->start, resource_size(r));
1957 if (udc->cap_regs == NULL) {
1958 dev_err(&dev->dev, "failed to map I/O memory\n");
1959 retval = -EBUSY;
1960 goto error;
1961 }
1962
1963 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "u2ophy");
1964 if (r == NULL) {
1965 dev_err(&dev->dev, "no phy I/O memory resource defined\n");
1966 retval = -ENODEV;
1967 goto error;
1968 }
1969
1970 udc->phy_regs = (unsigned int)ioremap(r->start, resource_size(r));
1971 if (udc->phy_regs == 0) {
1972 dev_err(&dev->dev, "failed to map phy I/O memory\n");
1973 retval = -EBUSY;
1974 goto error;
1975 }
1976
1977 /* we will acces controller register, so enable the clk */
1978 clk_enable(udc->clk);
1979 retval = mv_udc_phy_init(udc->phy_regs);
1980 if (retval) {
1981 dev_err(&dev->dev, "phy initialization error %d\n", retval);
1982 goto error;
1983 }
1984
1985 udc->op_regs = (struct mv_op_regs __iomem *)((u32)udc->cap_regs
1986 + (readl(&udc->cap_regs->caplength_hciversion)
1987 & CAPLENGTH_MASK));
1988 udc->max_eps = readl(&udc->cap_regs->dccparams) & DCCPARAMS_DEN_MASK;
1989
1990 size = udc->max_eps * sizeof(struct mv_dqh) *2;
1991 size = (size + DQH_ALIGNMENT - 1) & ~(DQH_ALIGNMENT - 1);
1992 udc->ep_dqh = dma_alloc_coherent(&dev->dev, size,
1993 &udc->ep_dqh_dma, GFP_KERNEL);
1994
1995 if (udc->ep_dqh == NULL) {
1996 dev_err(&dev->dev, "allocate dQH memory failed\n");
1997 retval = -ENOMEM;
1998 goto error;
1999 }
2000 udc->ep_dqh_size = size;
2001
2002 /* create dTD dma_pool resource */
2003 udc->dtd_pool = dma_pool_create("mv_dtd",
2004 &dev->dev,
2005 sizeof(struct mv_dtd),
2006 DTD_ALIGNMENT,
2007 DMA_BOUNDARY);
2008
2009 if (!udc->dtd_pool) {
2010 retval = -ENOMEM;
2011 goto error;
2012 }
2013
2014 size = udc->max_eps * sizeof(struct mv_ep) *2;
2015 udc->eps = kzalloc(size, GFP_KERNEL);
2016 if (udc->eps == NULL) {
2017 dev_err(&dev->dev, "allocate ep memory failed\n");
2018 retval = -ENOMEM;
2019 goto error;
2020 }
2021
2022 /* initialize ep0 status request structure */
2023 udc->status_req = kzalloc(sizeof(struct mv_req), GFP_KERNEL);
2024 if (!udc->status_req) {
2025 dev_err(&dev->dev, "allocate status_req memory failed\n");
2026 retval = -ENOMEM;
2027 goto error;
2028 }
2029 INIT_LIST_HEAD(&udc->status_req->queue);
2030
2031 /* allocate a small amount of memory to get valid address */
2032 udc->status_req->req.buf = kzalloc(8, GFP_KERNEL);
2033 udc->status_req->req.dma = virt_to_phys(udc->status_req->req.buf);
2034
2035 udc->resume_state = USB_STATE_NOTATTACHED;
2036 udc->usb_state = USB_STATE_POWERED;
2037 udc->ep0_dir = EP_DIR_OUT;
2038 udc->remote_wakeup = 0;
2039
2040 r = platform_get_resource(udc->dev, IORESOURCE_IRQ, 0);
2041 if (r == NULL) {
2042 dev_err(&dev->dev, "no IRQ resource defined\n");
2043 retval = -ENODEV;
2044 goto error;
2045 }
2046 udc->irq = r->start;
2047 if (request_irq(udc->irq, mv_udc_irq,
2048 IRQF_DISABLED | IRQF_SHARED, driver_name, udc)) {
2049 dev_err(&dev->dev, "Request irq %d for UDC failed\n",
2050 udc->irq);
2051 retval = -ENODEV;
2052 goto error;
2053 }
2054
2055 /* initialize gadget structure */
2056 udc->gadget.ops = &mv_ops; /* usb_gadget_ops */
2057 udc->gadget.ep0 = &udc->eps[0].ep; /* gadget ep0 */
2058 INIT_LIST_HEAD(&udc->gadget.ep_list); /* ep_list */
2059 udc->gadget.speed = USB_SPEED_UNKNOWN; /* speed */
2060 udc->gadget.is_dualspeed = 1; /* support dual speed */
2061
2062 /* the "gadget" abstracts/virtualizes the controller */
2063 dev_set_name(&udc->gadget.dev, "gadget");
2064 udc->gadget.dev.parent = &dev->dev;
2065 udc->gadget.dev.dma_mask = dev->dev.dma_mask;
2066 udc->gadget.dev.release = gadget_release;
2067 udc->gadget.name = driver_name; /* gadget name */
2068
2069 retval = device_register(&udc->gadget.dev);
2070 if (retval)
2071 goto error;
2072
2073 eps_init(udc);
2074
2075 the_controller = udc;
2076
2077 goto out;
2078error:
2079 if (udc)
2080 mv_udc_remove(udc->dev);
2081out:
2082 return retval;
2083}
2084
2085#ifdef CONFIG_PM
2086static int mv_udc_suspend(struct device *_dev)
2087{
2088 struct mv_udc *udc = the_controller;
2089
2090 udc_stop(udc);
2091
2092 return 0;
2093}
2094
2095static int mv_udc_resume(struct device *_dev)
2096{
2097 struct mv_udc *udc = the_controller;
2098 int retval;
2099
2100 retval = mv_udc_phy_init(udc->phy_regs);
2101 if (retval) {
2102 dev_err(_dev, "phy initialization error %d\n", retval);
2103 return retval;
2104 }
2105 udc_reset(udc);
2106 ep0_reset(udc);
2107 udc_start(udc);
2108
2109 return 0;
2110}
2111
2112static const struct dev_pm_ops mv_udc_pm_ops = {
2113 .suspend = mv_udc_suspend,
2114 .resume = mv_udc_resume,
2115};
2116#endif
2117
2118static struct platform_driver udc_driver = {
2119 .probe = mv_udc_probe,
2120 .remove = __exit_p(mv_udc_remove),
2121 .driver = {
2122 .owner = THIS_MODULE,
2123 .name = "pxa-u2o",
2124#ifdef CONFIG_PM
2125 .pm = &mv_udc_pm_ops,
2126#endif
2127 },
2128};
2129
2130
2131MODULE_DESCRIPTION(DRIVER_DESC);
2132MODULE_AUTHOR("Chao Xie <chao.xie@marvell.com>");
2133MODULE_VERSION(DRIVER_VERSION);
2134MODULE_LICENSE("GPL");
2135
2136
2137static int __init init(void)
2138{
2139 return platform_driver_register(&udc_driver);
2140}
2141module_init(init);
2142
2143
2144static void __exit cleanup(void)
2145{
2146 platform_driver_unregister(&udc_driver);
2147}
2148module_exit(cleanup);
2149
diff --git a/drivers/usb/gadget/mv_udc_phy.c b/drivers/usb/gadget/mv_udc_phy.c
new file mode 100644
index 000000000000..d4dea97e38a5
--- /dev/null
+++ b/drivers/usb/gadget/mv_udc_phy.c
@@ -0,0 +1,214 @@
1#include <linux/delay.h>
2#include <linux/timer.h>
3#include <linux/io.h>
4#include <linux/errno.h>
5
6#include <mach/cputype.h>
7
8#ifdef CONFIG_ARCH_MMP
9
10#define UTMI_REVISION 0x0
11#define UTMI_CTRL 0x4
12#define UTMI_PLL 0x8
13#define UTMI_TX 0xc
14#define UTMI_RX 0x10
15#define UTMI_IVREF 0x14
16#define UTMI_T0 0x18
17#define UTMI_T1 0x1c
18#define UTMI_T2 0x20
19#define UTMI_T3 0x24
20#define UTMI_T4 0x28
21#define UTMI_T5 0x2c
22#define UTMI_RESERVE 0x30
23#define UTMI_USB_INT 0x34
24#define UTMI_DBG_CTL 0x38
25#define UTMI_OTG_ADDON 0x3c
26
27/* For UTMICTRL Register */
28#define UTMI_CTRL_USB_CLK_EN (1 << 31)
29/* pxa168 */
30#define UTMI_CTRL_SUSPEND_SET1 (1 << 30)
31#define UTMI_CTRL_SUSPEND_SET2 (1 << 29)
32#define UTMI_CTRL_RXBUF_PDWN (1 << 24)
33#define UTMI_CTRL_TXBUF_PDWN (1 << 11)
34
35#define UTMI_CTRL_INPKT_DELAY_SHIFT 30
36#define UTMI_CTRL_INPKT_DELAY_SOF_SHIFT 28
37#define UTMI_CTRL_PU_REF_SHIFT 20
38#define UTMI_CTRL_ARC_PULLDN_SHIFT 12
39#define UTMI_CTRL_PLL_PWR_UP_SHIFT 1
40#define UTMI_CTRL_PWR_UP_SHIFT 0
41/* For UTMI_PLL Register */
42#define UTMI_PLL_CLK_BLK_EN_SHIFT 24
43#define UTMI_PLL_FBDIV_SHIFT 4
44#define UTMI_PLL_REFDIV_SHIFT 0
45#define UTMI_PLL_FBDIV_MASK 0x00000FF0
46#define UTMI_PLL_REFDIV_MASK 0x0000000F
47#define UTMI_PLL_ICP_MASK 0x00007000
48#define UTMI_PLL_KVCO_MASK 0x00031000
49#define UTMI_PLL_PLLCALI12_SHIFT 29
50#define UTMI_PLL_PLLCALI12_MASK (0x3 << 29)
51#define UTMI_PLL_PLLVDD18_SHIFT 27
52#define UTMI_PLL_PLLVDD18_MASK (0x3 << 27)
53#define UTMI_PLL_PLLVDD12_SHIFT 25
54#define UTMI_PLL_PLLVDD12_MASK (0x3 << 25)
55#define UTMI_PLL_KVCO_SHIFT 15
56#define UTMI_PLL_ICP_SHIFT 12
57/* For UTMI_TX Register */
58#define UTMI_TX_REG_EXT_FS_RCAL_SHIFT 27
59#define UTMI_TX_REG_EXT_FS_RCAL_MASK (0xf << 27)
60#define UTMI_TX_REG_EXT_FS_RCAL_EN_MASK 26
61#define UTMI_TX_REG_EXT_FS_RCAL_EN (0x1 << 26)
62#define UTMI_TX_LOW_VDD_EN_SHIFT 11
63#define UTMI_TX_IMPCAL_VTH_SHIFT 14
64#define UTMI_TX_IMPCAL_VTH_MASK (0x7 << 14)
65#define UTMI_TX_CK60_PHSEL_SHIFT 17
66#define UTMI_TX_CK60_PHSEL_MASK (0xf << 17)
67#define UTMI_TX_TXVDD12_SHIFT 22
68#define UTMI_TX_TXVDD12_MASK (0x3 << 22)
69#define UTMI_TX_AMP_SHIFT 0
70#define UTMI_TX_AMP_MASK (0x7 << 0)
71/* For UTMI_RX Register */
72#define UTMI_RX_SQ_THRESH_SHIFT 4
73#define UTMI_RX_SQ_THRESH_MASK (0xf << 4)
74#define UTMI_REG_SQ_LENGTH_SHIFT 15
75#define UTMI_REG_SQ_LENGTH_MASK (0x3 << 15)
76
77#define REG_RCAL_START 0x00001000
78#define VCOCAL_START 0x00200000
79#define KVCO_EXT 0x00400000
80#define PLL_READY 0x00800000
81#define CLK_BLK_EN 0x01000000
82#endif
83
84static unsigned int u2o_read(unsigned int base, unsigned int offset)
85{
86 return readl(base + offset);
87}
88
89static void u2o_set(unsigned int base, unsigned int offset, unsigned int value)
90{
91 unsigned int reg;
92
93 reg = readl(base + offset);
94 reg |= value;
95 writel(reg, base + offset);
96 readl(base + offset);
97}
98
99static void u2o_clear(unsigned int base, unsigned int offset,
100 unsigned int value)
101{
102 unsigned int reg;
103
104 reg = readl(base + offset);
105 reg &= ~value;
106 writel(reg, base + offset);
107 readl(base + offset);
108}
109
110static void u2o_write(unsigned int base, unsigned int offset,
111 unsigned int value)
112{
113 writel(value, base + offset);
114 readl(base + offset);
115}
116
117#ifdef CONFIG_ARCH_MMP
118int mv_udc_phy_init(unsigned int base)
119{
120 unsigned long timeout;
121
122 /* Initialize the USB PHY power */
123 if (cpu_is_pxa910()) {
124 u2o_set(base, UTMI_CTRL, (1 << UTMI_CTRL_INPKT_DELAY_SOF_SHIFT)
125 | (1 << UTMI_CTRL_PU_REF_SHIFT));
126 }
127
128 u2o_set(base, UTMI_CTRL, 1 << UTMI_CTRL_PLL_PWR_UP_SHIFT);
129 u2o_set(base, UTMI_CTRL, 1 << UTMI_CTRL_PWR_UP_SHIFT);
130
131 /* UTMI_PLL settings */
132 u2o_clear(base, UTMI_PLL, UTMI_PLL_PLLVDD18_MASK
133 | UTMI_PLL_PLLVDD12_MASK | UTMI_PLL_PLLCALI12_MASK
134 | UTMI_PLL_FBDIV_MASK | UTMI_PLL_REFDIV_MASK
135 | UTMI_PLL_ICP_MASK | UTMI_PLL_KVCO_MASK);
136
137 u2o_set(base, UTMI_PLL, (0xee << UTMI_PLL_FBDIV_SHIFT)
138 | (0xb << UTMI_PLL_REFDIV_SHIFT)
139 | (3 << UTMI_PLL_PLLVDD18_SHIFT)
140 | (3 << UTMI_PLL_PLLVDD12_SHIFT)
141 | (3 << UTMI_PLL_PLLCALI12_SHIFT)
142 | (1 << UTMI_PLL_ICP_SHIFT) | (3 << UTMI_PLL_KVCO_SHIFT));
143
144 /* UTMI_TX */
145 u2o_clear(base, UTMI_TX, UTMI_TX_REG_EXT_FS_RCAL_EN_MASK
146 | UTMI_TX_TXVDD12_MASK
147 | UTMI_TX_CK60_PHSEL_MASK | UTMI_TX_IMPCAL_VTH_MASK
148 | UTMI_TX_REG_EXT_FS_RCAL_MASK | UTMI_TX_AMP_MASK);
149 u2o_set(base, UTMI_TX, (3 << UTMI_TX_TXVDD12_SHIFT)
150 | (4 << UTMI_TX_CK60_PHSEL_SHIFT)
151 | (4 << UTMI_TX_IMPCAL_VTH_SHIFT)
152 | (8 << UTMI_TX_REG_EXT_FS_RCAL_SHIFT)
153 | (3 << UTMI_TX_AMP_SHIFT));
154
155 /* UTMI_RX */
156 u2o_clear(base, UTMI_RX, UTMI_RX_SQ_THRESH_MASK
157 | UTMI_REG_SQ_LENGTH_MASK);
158 if (cpu_is_pxa168())
159 u2o_set(base, UTMI_RX, (7 << UTMI_RX_SQ_THRESH_SHIFT)
160 | (2 << UTMI_REG_SQ_LENGTH_SHIFT));
161 else
162 u2o_set(base, UTMI_RX, (0x7 << UTMI_RX_SQ_THRESH_SHIFT)
163 | (2 << UTMI_REG_SQ_LENGTH_SHIFT));
164
165 /* UTMI_IVREF */
166 if (cpu_is_pxa168())
167 /*
168 * fixing Microsoft Altair board interface with NEC hub issue -
169 * Set UTMI_IVREF from 0x4a3 to 0x4bf
170 */
171 u2o_write(base, UTMI_IVREF, 0x4bf);
172
173 /* calibrate */
174 timeout = jiffies + 100;
175 while ((u2o_read(base, UTMI_PLL) & PLL_READY) == 0) {
176 if (time_after(jiffies, timeout))
177 return -ETIME;
178 cpu_relax();
179 }
180
181 /* toggle VCOCAL_START bit of UTMI_PLL */
182 udelay(200);
183 u2o_set(base, UTMI_PLL, VCOCAL_START);
184 udelay(40);
185 u2o_clear(base, UTMI_PLL, VCOCAL_START);
186
187 /* toggle REG_RCAL_START bit of UTMI_TX */
188 udelay(200);
189 u2o_set(base, UTMI_TX, REG_RCAL_START);
190 udelay(40);
191 u2o_clear(base, UTMI_TX, REG_RCAL_START);
192 udelay(200);
193
194 /* make sure phy is ready */
195 timeout = jiffies + 100;
196 while ((u2o_read(base, UTMI_PLL) & PLL_READY) == 0) {
197 if (time_after(jiffies, timeout))
198 return -ETIME;
199 cpu_relax();
200 }
201
202 if (cpu_is_pxa168()) {
203 u2o_set(base, UTMI_RESERVE, 1 << 5);
204 /* Turn on UTMI PHY OTG extension */
205 u2o_write(base, UTMI_OTG_ADDON, 1);
206 }
207 return 0;
208}
209#else
210int mv_udc_phy_init(unsigned int base)
211{
212 return 0;
213}
214#endif
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c
new file mode 100644
index 000000000000..99c179ad729d
--- /dev/null
+++ b/drivers/usb/gadget/ncm.c
@@ -0,0 +1,248 @@
1/*
2 * ncm.c -- NCM gadget driver
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 * Contact: Yauheni Kaliuta <yauheni.kaliuta@nokia.com>
6 *
7 * The driver borrows from ether.c which is:
8 *
9 * Copyright (C) 2003-2005,2008 David Brownell
10 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
11 * Copyright (C) 2008 Nokia Corporation
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 */
27
28/* #define DEBUG */
29/* #define VERBOSE_DEBUG */
30
31#include <linux/kernel.h>
32#include <linux/utsname.h>
33
34
35#include "u_ether.h"
36
37#define DRIVER_DESC "NCM Gadget"
38
39/*-------------------------------------------------------------------------*/
40
41/*
42 * Kbuild is not very cooperative with respect to linking separately
43 * compiled library objects into one module. So for now we won't use
44 * separate compilation ... ensuring init/exit sections work to shrink
45 * the runtime footprint, and giving us at least some parts of what
46 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
47 */
48#include "composite.c"
49#include "usbstring.c"
50#include "config.c"
51#include "epautoconf.c"
52
53#include "f_ncm.c"
54#include "u_ether.c"
55
56/*-------------------------------------------------------------------------*/
57
58/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
59 * Instead: allocate your own, using normal USB-IF procedures.
60 */
61
62/* Thanks to NetChip Technologies for donating this product ID.
63 * It's for devices with only CDC Ethernet configurations.
64 */
65#define CDC_VENDOR_NUM 0x0525 /* NetChip */
66#define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
67
68/*-------------------------------------------------------------------------*/
69
70static struct usb_device_descriptor device_desc = {
71 .bLength = sizeof device_desc,
72 .bDescriptorType = USB_DT_DEVICE,
73
74 .bcdUSB = cpu_to_le16 (0x0200),
75
76 .bDeviceClass = USB_CLASS_COMM,
77 .bDeviceSubClass = 0,
78 .bDeviceProtocol = 0,
79 /* .bMaxPacketSize0 = f(hardware) */
80
81 /* Vendor and product id defaults change according to what configs
82 * we support. (As does bNumConfigurations.) These values can
83 * also be overridden by module parameters.
84 */
85 .idVendor = cpu_to_le16 (CDC_VENDOR_NUM),
86 .idProduct = cpu_to_le16 (CDC_PRODUCT_NUM),
87 /* .bcdDevice = f(hardware) */
88 /* .iManufacturer = DYNAMIC */
89 /* .iProduct = DYNAMIC */
90 /* NO SERIAL NUMBER */
91 .bNumConfigurations = 1,
92};
93
94static struct usb_otg_descriptor otg_descriptor = {
95 .bLength = sizeof otg_descriptor,
96 .bDescriptorType = USB_DT_OTG,
97
98 /* REVISIT SRP-only hardware is possible, although
99 * it would not be called "OTG" ...
100 */
101 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
102};
103
104static const struct usb_descriptor_header *otg_desc[] = {
105 (struct usb_descriptor_header *) &otg_descriptor,
106 NULL,
107};
108
109
110/* string IDs are assigned dynamically */
111
112#define STRING_MANUFACTURER_IDX 0
113#define STRING_PRODUCT_IDX 1
114
115static char manufacturer[50];
116
117static struct usb_string strings_dev[] = {
118 [STRING_MANUFACTURER_IDX].s = manufacturer,
119 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
120 { } /* end of list */
121};
122
123static struct usb_gadget_strings stringtab_dev = {
124 .language = 0x0409, /* en-us */
125 .strings = strings_dev,
126};
127
128static struct usb_gadget_strings *dev_strings[] = {
129 &stringtab_dev,
130 NULL,
131};
132
133static u8 hostaddr[ETH_ALEN];
134
135/*-------------------------------------------------------------------------*/
136
137static int __init ncm_do_config(struct usb_configuration *c)
138{
139 /* FIXME alloc iConfiguration string, set it in c->strings */
140
141 if (gadget_is_otg(c->cdev->gadget)) {
142 c->descriptors = otg_desc;
143 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
144 }
145
146 return ncm_bind_config(c, hostaddr);
147}
148
149static struct usb_configuration ncm_config_driver = {
150 /* .label = f(hardware) */
151 .label = "CDC Ethernet (NCM)",
152 .bConfigurationValue = 1,
153 /* .iConfiguration = DYNAMIC */
154 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
155};
156
157/*-------------------------------------------------------------------------*/
158
159static int __init gncm_bind(struct usb_composite_dev *cdev)
160{
161 int gcnum;
162 struct usb_gadget *gadget = cdev->gadget;
163 int status;
164
165 /* set up network link layer */
166 status = gether_setup(cdev->gadget, hostaddr);
167 if (status < 0)
168 return status;
169
170 gcnum = usb_gadget_controller_number(gadget);
171 if (gcnum >= 0)
172 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
173 else {
174 /* We assume that can_support_ecm() tells the truth;
175 * but if the controller isn't recognized at all then
176 * that assumption is a bit more likely to be wrong.
177 */
178 dev_warn(&gadget->dev,
179 "controller '%s' not recognized; trying %s\n",
180 gadget->name,
181 ncm_config_driver.label);
182 device_desc.bcdDevice =
183 cpu_to_le16(0x0300 | 0x0099);
184 }
185
186
187 /* Allocate string descriptor numbers ... note that string
188 * contents can be overridden by the composite_dev glue.
189 */
190
191 /* device descriptor strings: manufacturer, product */
192 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
193 init_utsname()->sysname, init_utsname()->release,
194 gadget->name);
195 status = usb_string_id(cdev);
196 if (status < 0)
197 goto fail;
198 strings_dev[STRING_MANUFACTURER_IDX].id = status;
199 device_desc.iManufacturer = status;
200
201 status = usb_string_id(cdev);
202 if (status < 0)
203 goto fail;
204 strings_dev[STRING_PRODUCT_IDX].id = status;
205 device_desc.iProduct = status;
206
207 status = usb_add_config(cdev, &ncm_config_driver,
208 ncm_do_config);
209 if (status < 0)
210 goto fail;
211
212 dev_info(&gadget->dev, "%s\n", DRIVER_DESC);
213
214 return 0;
215
216fail:
217 gether_cleanup();
218 return status;
219}
220
221static int __exit gncm_unbind(struct usb_composite_dev *cdev)
222{
223 gether_cleanup();
224 return 0;
225}
226
227static struct usb_composite_driver ncm_driver = {
228 .name = "g_ncm",
229 .dev = &device_desc,
230 .strings = dev_strings,
231 .unbind = __exit_p(gncm_unbind),
232};
233
234MODULE_DESCRIPTION(DRIVER_DESC);
235MODULE_AUTHOR("Yauheni Kaliuta");
236MODULE_LICENSE("GPL");
237
238static int __init init(void)
239{
240 return usb_composite_probe(&ncm_driver, gncm_bind);
241}
242module_init(init);
243
244static void __exit cleanup(void)
245{
246 usb_composite_unregister(&ncm_driver);
247}
248module_exit(cleanup);
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 9498be87a724..476d88e1ae97 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -63,6 +63,7 @@
63#include <linux/device.h> 63#include <linux/device.h>
64#include <linux/usb/ch9.h> 64#include <linux/usb/ch9.h>
65#include <linux/usb/gadget.h> 65#include <linux/usb/gadget.h>
66#include <linux/prefetch.h>
66 67
67#include <asm/byteorder.h> 68#include <asm/byteorder.h>
68#include <asm/io.h> 69#include <asm/io.h>
@@ -117,7 +118,7 @@ module_param (fifo_mode, ushort, 0644);
117 118
118/* enable_suspend -- When enabled, the driver will respond to 119/* enable_suspend -- When enabled, the driver will respond to
119 * USB suspend requests by powering down the NET2280. Otherwise, 120 * USB suspend requests by powering down the NET2280. Otherwise,
120 * USB suspend requests will be ignored. This is acceptible for 121 * USB suspend requests will be ignored. This is acceptable for
121 * self-powered devices 122 * self-powered devices
122 */ 123 */
123static int enable_suspend = 0; 124static int enable_suspend = 0;
@@ -1929,7 +1930,8 @@ static void ep0_start (struct net2280 *dev)
1929 * disconnect is reported. then a host may connect again, or 1930 * disconnect is reported. then a host may connect again, or
1930 * the driver might get unbound. 1931 * the driver might get unbound.
1931 */ 1932 */
1932int usb_gadget_register_driver (struct usb_gadget_driver *driver) 1933int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1934 int (*bind)(struct usb_gadget *))
1933{ 1935{
1934 struct net2280 *dev = the_controller; 1936 struct net2280 *dev = the_controller;
1935 int retval; 1937 int retval;
@@ -1941,8 +1943,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1941 */ 1943 */
1942 if (!driver 1944 if (!driver
1943 || driver->speed != USB_SPEED_HIGH 1945 || driver->speed != USB_SPEED_HIGH
1944 || !driver->bind 1946 || !bind || !driver->setup)
1945 || !driver->setup)
1946 return -EINVAL; 1947 return -EINVAL;
1947 if (!dev) 1948 if (!dev)
1948 return -ENODEV; 1949 return -ENODEV;
@@ -1957,7 +1958,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1957 driver->driver.bus = NULL; 1958 driver->driver.bus = NULL;
1958 dev->driver = driver; 1959 dev->driver = driver;
1959 dev->gadget.dev.driver = &driver->driver; 1960 dev->gadget.dev.driver = &driver->driver;
1960 retval = driver->bind (&dev->gadget); 1961 retval = bind(&dev->gadget);
1961 if (retval) { 1962 if (retval) {
1962 DEBUG (dev, "bind to driver %s --> %d\n", 1963 DEBUG (dev, "bind to driver %s --> %d\n",
1963 driver->driver.name, retval); 1964 driver->driver.name, retval);
@@ -1993,7 +1994,7 @@ err_unbind:
1993 dev->driver = NULL; 1994 dev->driver = NULL;
1994 return retval; 1995 return retval;
1995} 1996}
1996EXPORT_SYMBOL (usb_gadget_register_driver); 1997EXPORT_SYMBOL(usb_gadget_probe_driver);
1997 1998
1998static void 1999static void
1999stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) 2000stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index 7d6b66a85724..55ca63ad3506 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -135,7 +135,6 @@ static int __init nokia_bind_config(struct usb_configuration *c)
135 135
136static struct usb_configuration nokia_config_500ma_driver = { 136static struct usb_configuration nokia_config_500ma_driver = {
137 .label = "Bus Powered", 137 .label = "Bus Powered",
138 .bind = nokia_bind_config,
139 .bConfigurationValue = 1, 138 .bConfigurationValue = 1,
140 /* .iConfiguration = DYNAMIC */ 139 /* .iConfiguration = DYNAMIC */
141 .bmAttributes = USB_CONFIG_ATT_ONE, 140 .bmAttributes = USB_CONFIG_ATT_ONE,
@@ -144,7 +143,6 @@ static struct usb_configuration nokia_config_500ma_driver = {
144 143
145static struct usb_configuration nokia_config_100ma_driver = { 144static struct usb_configuration nokia_config_100ma_driver = {
146 .label = "Self Powered", 145 .label = "Self Powered",
147 .bind = nokia_bind_config,
148 .bConfigurationValue = 2, 146 .bConfigurationValue = 2,
149 /* .iConfiguration = DYNAMIC */ 147 /* .iConfiguration = DYNAMIC */
150 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, 148 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
@@ -205,12 +203,14 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
205 goto err_usb; 203 goto err_usb;
206 } 204 }
207 205
208 /* finaly register the configuration */ 206 /* finally register the configuration */
209 status = usb_add_config(cdev, &nokia_config_500ma_driver); 207 status = usb_add_config(cdev, &nokia_config_500ma_driver,
208 nokia_bind_config);
210 if (status < 0) 209 if (status < 0)
211 goto err_usb; 210 goto err_usb;
212 211
213 status = usb_add_config(cdev, &nokia_config_100ma_driver); 212 status = usb_add_config(cdev, &nokia_config_100ma_driver,
213 nokia_bind_config);
214 if (status < 0) 214 if (status < 0)
215 goto err_usb; 215 goto err_usb;
216 216
@@ -241,13 +241,12 @@ static struct usb_composite_driver nokia_driver = {
241 .name = "g_nokia", 241 .name = "g_nokia",
242 .dev = &device_desc, 242 .dev = &device_desc,
243 .strings = dev_strings, 243 .strings = dev_strings,
244 .bind = nokia_bind,
245 .unbind = __exit_p(nokia_unbind), 244 .unbind = __exit_p(nokia_unbind),
246}; 245};
247 246
248static int __init nokia_init(void) 247static int __init nokia_init(void)
249{ 248{
250 return usb_composite_register(&nokia_driver); 249 return usb_composite_probe(&nokia_driver, nokia_bind);
251} 250}
252module_init(nokia_init); 251module_init(nokia_init);
253 252
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index f81e4f025f23..82fd24935332 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -44,6 +44,7 @@
44#include <linux/usb/otg.h> 44#include <linux/usb/otg.h>
45#include <linux/dma-mapping.h> 45#include <linux/dma-mapping.h>
46#include <linux/clk.h> 46#include <linux/clk.h>
47#include <linux/prefetch.h>
47 48
48#include <asm/byteorder.h> 49#include <asm/byteorder.h>
49#include <asm/io.h> 50#include <asm/io.h>
@@ -54,7 +55,6 @@
54 55
55#include <plat/dma.h> 56#include <plat/dma.h>
56#include <plat/usb.h> 57#include <plat/usb.h>
57#include <plat/control.h>
58 58
59#include "omap_udc.h" 59#include "omap_udc.h"
60 60
@@ -2102,7 +2102,8 @@ static inline int machine_without_vbus_sense(void)
2102 ); 2102 );
2103} 2103}
2104 2104
2105int usb_gadget_register_driver (struct usb_gadget_driver *driver) 2105int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2106 int (*bind)(struct usb_gadget *))
2106{ 2107{
2107 int status = -ENODEV; 2108 int status = -ENODEV;
2108 struct omap_ep *ep; 2109 struct omap_ep *ep;
@@ -2114,8 +2115,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2114 if (!driver 2115 if (!driver
2115 // FIXME if otg, check: driver->is_otg 2116 // FIXME if otg, check: driver->is_otg
2116 || driver->speed < USB_SPEED_FULL 2117 || driver->speed < USB_SPEED_FULL
2117 || !driver->bind 2118 || !bind || !driver->setup)
2118 || !driver->setup)
2119 return -EINVAL; 2119 return -EINVAL;
2120 2120
2121 spin_lock_irqsave(&udc->lock, flags); 2121 spin_lock_irqsave(&udc->lock, flags);
@@ -2145,7 +2145,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2145 if (udc->dc_clk != NULL) 2145 if (udc->dc_clk != NULL)
2146 omap_udc_enable_clock(1); 2146 omap_udc_enable_clock(1);
2147 2147
2148 status = driver->bind (&udc->gadget); 2148 status = bind(&udc->gadget);
2149 if (status) { 2149 if (status) {
2150 DBG("bind to %s --> %d\n", driver->driver.name, status); 2150 DBG("bind to %s --> %d\n", driver->driver.name, status);
2151 udc->gadget.dev.driver = NULL; 2151 udc->gadget.dev.driver = NULL;
@@ -2186,7 +2186,7 @@ done:
2186 omap_udc_enable_clock(0); 2186 omap_udc_enable_clock(0);
2187 return status; 2187 return status;
2188} 2188}
2189EXPORT_SYMBOL(usb_gadget_register_driver); 2189EXPORT_SYMBOL(usb_gadget_probe_driver);
2190 2190
2191int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 2191int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2192{ 2192{
@@ -2309,21 +2309,12 @@ static char *trx_mode(unsigned m, int enabled)
2309static int proc_otg_show(struct seq_file *s) 2309static int proc_otg_show(struct seq_file *s)
2310{ 2310{
2311 u32 tmp; 2311 u32 tmp;
2312 u32 trans; 2312 u32 trans = 0;
2313 char *ctrl_name; 2313 char *ctrl_name = "(UNKNOWN)";
2314 2314
2315 /* XXX This needs major revision for OMAP2+ */
2315 tmp = omap_readl(OTG_REV); 2316 tmp = omap_readl(OTG_REV);
2316 if (cpu_is_omap24xx()) { 2317 if (cpu_class_is_omap1()) {
2317 /*
2318 * REVISIT: Not clear how this works on OMAP2. trans
2319 * is ANDed to produce bits 7 and 8, which might make
2320 * sense for USB_TRANSCEIVER_CTRL on OMAP1,
2321 * but with CONTROL_DEVCONF, these bits have something to
2322 * do with the frame adjustment counter and McBSP2.
2323 */
2324 ctrl_name = "control_devconf";
2325 trans = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
2326 } else {
2327 ctrl_name = "tranceiver_ctrl"; 2318 ctrl_name = "tranceiver_ctrl";
2328 trans = omap_readw(USB_TRANSCEIVER_CTRL); 2319 trans = omap_readw(USB_TRANSCEIVER_CTRL);
2329 } 2320 }
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
new file mode 100644
index 000000000000..68dbcc3e4cc2
--- /dev/null
+++ b/drivers/usb/gadget/pch_udc.c
@@ -0,0 +1,3004 @@
1/*
2 * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD.
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; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/pci.h>
21#include <linux/delay.h>
22#include <linux/errno.h>
23#include <linux/list.h>
24#include <linux/interrupt.h>
25#include <linux/usb/ch9.h>
26#include <linux/usb/gadget.h>
27
28/* Address offset of Registers */
29#define UDC_EP_REG_SHIFT 0x20 /* Offset to next EP */
30
31#define UDC_EPCTL_ADDR 0x00 /* Endpoint control */
32#define UDC_EPSTS_ADDR 0x04 /* Endpoint status */
33#define UDC_BUFIN_FRAMENUM_ADDR 0x08 /* buffer size in / frame number out */
34#define UDC_BUFOUT_MAXPKT_ADDR 0x0C /* buffer size out / maxpkt in */
35#define UDC_SUBPTR_ADDR 0x10 /* setup buffer pointer */
36#define UDC_DESPTR_ADDR 0x14 /* Data descriptor pointer */
37#define UDC_CONFIRM_ADDR 0x18 /* Write/Read confirmation */
38
39#define UDC_DEVCFG_ADDR 0x400 /* Device configuration */
40#define UDC_DEVCTL_ADDR 0x404 /* Device control */
41#define UDC_DEVSTS_ADDR 0x408 /* Device status */
42#define UDC_DEVIRQSTS_ADDR 0x40C /* Device irq status */
43#define UDC_DEVIRQMSK_ADDR 0x410 /* Device irq mask */
44#define UDC_EPIRQSTS_ADDR 0x414 /* Endpoint irq status */
45#define UDC_EPIRQMSK_ADDR 0x418 /* Endpoint irq mask */
46#define UDC_DEVLPM_ADDR 0x41C /* LPM control / status */
47#define UDC_CSR_BUSY_ADDR 0x4f0 /* UDC_CSR_BUSY Status register */
48#define UDC_SRST_ADDR 0x4fc /* SOFT RESET register */
49#define UDC_CSR_ADDR 0x500 /* USB_DEVICE endpoint register */
50
51/* Endpoint control register */
52/* Bit position */
53#define UDC_EPCTL_MRXFLUSH (1 << 12)
54#define UDC_EPCTL_RRDY (1 << 9)
55#define UDC_EPCTL_CNAK (1 << 8)
56#define UDC_EPCTL_SNAK (1 << 7)
57#define UDC_EPCTL_NAK (1 << 6)
58#define UDC_EPCTL_P (1 << 3)
59#define UDC_EPCTL_F (1 << 1)
60#define UDC_EPCTL_S (1 << 0)
61#define UDC_EPCTL_ET_SHIFT 4
62/* Mask patern */
63#define UDC_EPCTL_ET_MASK 0x00000030
64/* Value for ET field */
65#define UDC_EPCTL_ET_CONTROL 0
66#define UDC_EPCTL_ET_ISO 1
67#define UDC_EPCTL_ET_BULK 2
68#define UDC_EPCTL_ET_INTERRUPT 3
69
70/* Endpoint status register */
71/* Bit position */
72#define UDC_EPSTS_XFERDONE (1 << 27)
73#define UDC_EPSTS_RSS (1 << 26)
74#define UDC_EPSTS_RCS (1 << 25)
75#define UDC_EPSTS_TXEMPTY (1 << 24)
76#define UDC_EPSTS_TDC (1 << 10)
77#define UDC_EPSTS_HE (1 << 9)
78#define UDC_EPSTS_MRXFIFO_EMP (1 << 8)
79#define UDC_EPSTS_BNA (1 << 7)
80#define UDC_EPSTS_IN (1 << 6)
81#define UDC_EPSTS_OUT_SHIFT 4
82/* Mask patern */
83#define UDC_EPSTS_OUT_MASK 0x00000030
84#define UDC_EPSTS_ALL_CLR_MASK 0x1F0006F0
85/* Value for OUT field */
86#define UDC_EPSTS_OUT_SETUP 2
87#define UDC_EPSTS_OUT_DATA 1
88
89/* Device configuration register */
90/* Bit position */
91#define UDC_DEVCFG_CSR_PRG (1 << 17)
92#define UDC_DEVCFG_SP (1 << 3)
93/* SPD Valee */
94#define UDC_DEVCFG_SPD_HS 0x0
95#define UDC_DEVCFG_SPD_FS 0x1
96#define UDC_DEVCFG_SPD_LS 0x2
97
98/* Device control register */
99/* Bit position */
100#define UDC_DEVCTL_THLEN_SHIFT 24
101#define UDC_DEVCTL_BRLEN_SHIFT 16
102#define UDC_DEVCTL_CSR_DONE (1 << 13)
103#define UDC_DEVCTL_SD (1 << 10)
104#define UDC_DEVCTL_MODE (1 << 9)
105#define UDC_DEVCTL_BREN (1 << 8)
106#define UDC_DEVCTL_THE (1 << 7)
107#define UDC_DEVCTL_DU (1 << 4)
108#define UDC_DEVCTL_TDE (1 << 3)
109#define UDC_DEVCTL_RDE (1 << 2)
110#define UDC_DEVCTL_RES (1 << 0)
111
112/* Device status register */
113/* Bit position */
114#define UDC_DEVSTS_TS_SHIFT 18
115#define UDC_DEVSTS_ENUM_SPEED_SHIFT 13
116#define UDC_DEVSTS_ALT_SHIFT 8
117#define UDC_DEVSTS_INTF_SHIFT 4
118#define UDC_DEVSTS_CFG_SHIFT 0
119/* Mask patern */
120#define UDC_DEVSTS_TS_MASK 0xfffc0000
121#define UDC_DEVSTS_ENUM_SPEED_MASK 0x00006000
122#define UDC_DEVSTS_ALT_MASK 0x00000f00
123#define UDC_DEVSTS_INTF_MASK 0x000000f0
124#define UDC_DEVSTS_CFG_MASK 0x0000000f
125/* value for maximum speed for SPEED field */
126#define UDC_DEVSTS_ENUM_SPEED_FULL 1
127#define UDC_DEVSTS_ENUM_SPEED_HIGH 0
128#define UDC_DEVSTS_ENUM_SPEED_LOW 2
129#define UDC_DEVSTS_ENUM_SPEED_FULLX 3
130
131/* Device irq register */
132/* Bit position */
133#define UDC_DEVINT_RWKP (1 << 7)
134#define UDC_DEVINT_ENUM (1 << 6)
135#define UDC_DEVINT_SOF (1 << 5)
136#define UDC_DEVINT_US (1 << 4)
137#define UDC_DEVINT_UR (1 << 3)
138#define UDC_DEVINT_ES (1 << 2)
139#define UDC_DEVINT_SI (1 << 1)
140#define UDC_DEVINT_SC (1 << 0)
141/* Mask patern */
142#define UDC_DEVINT_MSK 0x7f
143
144/* Endpoint irq register */
145/* Bit position */
146#define UDC_EPINT_IN_SHIFT 0
147#define UDC_EPINT_OUT_SHIFT 16
148#define UDC_EPINT_IN_EP0 (1 << 0)
149#define UDC_EPINT_OUT_EP0 (1 << 16)
150/* Mask patern */
151#define UDC_EPINT_MSK_DISABLE_ALL 0xffffffff
152
153/* UDC_CSR_BUSY Status register */
154/* Bit position */
155#define UDC_CSR_BUSY (1 << 0)
156
157/* SOFT RESET register */
158/* Bit position */
159#define UDC_PSRST (1 << 1)
160#define UDC_SRST (1 << 0)
161
162/* USB_DEVICE endpoint register */
163/* Bit position */
164#define UDC_CSR_NE_NUM_SHIFT 0
165#define UDC_CSR_NE_DIR_SHIFT 4
166#define UDC_CSR_NE_TYPE_SHIFT 5
167#define UDC_CSR_NE_CFG_SHIFT 7
168#define UDC_CSR_NE_INTF_SHIFT 11
169#define UDC_CSR_NE_ALT_SHIFT 15
170#define UDC_CSR_NE_MAX_PKT_SHIFT 19
171/* Mask patern */
172#define UDC_CSR_NE_NUM_MASK 0x0000000f
173#define UDC_CSR_NE_DIR_MASK 0x00000010
174#define UDC_CSR_NE_TYPE_MASK 0x00000060
175#define UDC_CSR_NE_CFG_MASK 0x00000780
176#define UDC_CSR_NE_INTF_MASK 0x00007800
177#define UDC_CSR_NE_ALT_MASK 0x00078000
178#define UDC_CSR_NE_MAX_PKT_MASK 0x3ff80000
179
180#define PCH_UDC_CSR(ep) (UDC_CSR_ADDR + ep*4)
181#define PCH_UDC_EPINT(in, num)\
182 (1 << (num + (in ? UDC_EPINT_IN_SHIFT : UDC_EPINT_OUT_SHIFT)))
183
184/* Index of endpoint */
185#define UDC_EP0IN_IDX 0
186#define UDC_EP0OUT_IDX 1
187#define UDC_EPIN_IDX(ep) (ep * 2)
188#define UDC_EPOUT_IDX(ep) (ep * 2 + 1)
189#define PCH_UDC_EP0 0
190#define PCH_UDC_EP1 1
191#define PCH_UDC_EP2 2
192#define PCH_UDC_EP3 3
193
194/* Number of endpoint */
195#define PCH_UDC_EP_NUM 32 /* Total number of EPs (16 IN,16 OUT) */
196#define PCH_UDC_USED_EP_NUM 4 /* EP number of EP's really used */
197/* Length Value */
198#define PCH_UDC_BRLEN 0x0F /* Burst length */
199#define PCH_UDC_THLEN 0x1F /* Threshold length */
200/* Value of EP Buffer Size */
201#define UDC_EP0IN_BUFF_SIZE 16
202#define UDC_EPIN_BUFF_SIZE 256
203#define UDC_EP0OUT_BUFF_SIZE 16
204#define UDC_EPOUT_BUFF_SIZE 256
205/* Value of EP maximum packet size */
206#define UDC_EP0IN_MAX_PKT_SIZE 64
207#define UDC_EP0OUT_MAX_PKT_SIZE 64
208#define UDC_BULK_MAX_PKT_SIZE 512
209
210/* DMA */
211#define DMA_DIR_RX 1 /* DMA for data receive */
212#define DMA_DIR_TX 2 /* DMA for data transmit */
213#define DMA_ADDR_INVALID (~(dma_addr_t)0)
214#define UDC_DMA_MAXPACKET 65536 /* maximum packet size for DMA */
215
216/**
217 * struct pch_udc_data_dma_desc - Structure to hold DMA descriptor information
218 * for data
219 * @status: Status quadlet
220 * @reserved: Reserved
221 * @dataptr: Buffer descriptor
222 * @next: Next descriptor
223 */
224struct pch_udc_data_dma_desc {
225 u32 status;
226 u32 reserved;
227 u32 dataptr;
228 u32 next;
229};
230
231/**
232 * struct pch_udc_stp_dma_desc - Structure to hold DMA descriptor information
233 * for control data
234 * @status: Status
235 * @reserved: Reserved
236 * @data12: First setup word
237 * @data34: Second setup word
238 */
239struct pch_udc_stp_dma_desc {
240 u32 status;
241 u32 reserved;
242 struct usb_ctrlrequest request;
243} __attribute((packed));
244
245/* DMA status definitions */
246/* Buffer status */
247#define PCH_UDC_BUFF_STS 0xC0000000
248#define PCH_UDC_BS_HST_RDY 0x00000000
249#define PCH_UDC_BS_DMA_BSY 0x40000000
250#define PCH_UDC_BS_DMA_DONE 0x80000000
251#define PCH_UDC_BS_HST_BSY 0xC0000000
252/* Rx/Tx Status */
253#define PCH_UDC_RXTX_STS 0x30000000
254#define PCH_UDC_RTS_SUCC 0x00000000
255#define PCH_UDC_RTS_DESERR 0x10000000
256#define PCH_UDC_RTS_BUFERR 0x30000000
257/* Last Descriptor Indication */
258#define PCH_UDC_DMA_LAST 0x08000000
259/* Number of Rx/Tx Bytes Mask */
260#define PCH_UDC_RXTX_BYTES 0x0000ffff
261
262/**
263 * struct pch_udc_cfg_data - Structure to hold current configuration
264 * and interface information
265 * @cur_cfg: current configuration in use
266 * @cur_intf: current interface in use
267 * @cur_alt: current alt interface in use
268 */
269struct pch_udc_cfg_data {
270 u16 cur_cfg;
271 u16 cur_intf;
272 u16 cur_alt;
273};
274
275/**
276 * struct pch_udc_ep - Structure holding a PCH USB device Endpoint information
277 * @ep: embedded ep request
278 * @td_stp_phys: for setup request
279 * @td_data_phys: for data request
280 * @td_stp: for setup request
281 * @td_data: for data request
282 * @dev: reference to device struct
283 * @offset_addr: offset address of ep register
284 * @desc: for this ep
285 * @queue: queue for requests
286 * @num: endpoint number
287 * @in: endpoint is IN
288 * @halted: endpoint halted?
289 * @epsts: Endpoint status
290 */
291struct pch_udc_ep {
292 struct usb_ep ep;
293 dma_addr_t td_stp_phys;
294 dma_addr_t td_data_phys;
295 struct pch_udc_stp_dma_desc *td_stp;
296 struct pch_udc_data_dma_desc *td_data;
297 struct pch_udc_dev *dev;
298 unsigned long offset_addr;
299 const struct usb_endpoint_descriptor *desc;
300 struct list_head queue;
301 unsigned num:5,
302 in:1,
303 halted:1;
304 unsigned long epsts;
305};
306
307/**
308 * struct pch_udc_dev - Structure holding complete information
309 * of the PCH USB device
310 * @gadget: gadget driver data
311 * @driver: reference to gadget driver bound
312 * @pdev: reference to the PCI device
313 * @ep: array of endpoints
314 * @lock: protects all state
315 * @active: enabled the PCI device
316 * @stall: stall requested
317 * @prot_stall: protcol stall requested
318 * @irq_registered: irq registered with system
319 * @mem_region: device memory mapped
320 * @registered: driver regsitered with system
321 * @suspended: driver in suspended state
322 * @connected: gadget driver associated
323 * @set_cfg_not_acked: pending acknowledgement 4 setup
324 * @waiting_zlp_ack: pending acknowledgement 4 ZLP
325 * @data_requests: DMA pool for data requests
326 * @stp_requests: DMA pool for setup requests
327 * @dma_addr: DMA pool for received
328 * @ep0out_buf: Buffer for DMA
329 * @setup_data: Received setup data
330 * @phys_addr: of device memory
331 * @base_addr: for mapped device memory
332 * @irq: IRQ line for the device
333 * @cfg_data: current cfg, intf, and alt in use
334 */
335struct pch_udc_dev {
336 struct usb_gadget gadget;
337 struct usb_gadget_driver *driver;
338 struct pci_dev *pdev;
339 struct pch_udc_ep ep[PCH_UDC_EP_NUM];
340 spinlock_t lock; /* protects all state */
341 unsigned active:1,
342 stall:1,
343 prot_stall:1,
344 irq_registered:1,
345 mem_region:1,
346 registered:1,
347 suspended:1,
348 connected:1,
349 set_cfg_not_acked:1,
350 waiting_zlp_ack:1;
351 struct pci_pool *data_requests;
352 struct pci_pool *stp_requests;
353 dma_addr_t dma_addr;
354 void *ep0out_buf;
355 struct usb_ctrlrequest setup_data;
356 unsigned long phys_addr;
357 void __iomem *base_addr;
358 unsigned irq;
359 struct pch_udc_cfg_data cfg_data;
360};
361
362#define PCH_UDC_PCI_BAR 1
363#define PCI_DEVICE_ID_INTEL_EG20T_UDC 0x8808
364#define PCI_VENDOR_ID_ROHM 0x10DB
365#define PCI_DEVICE_ID_ML7213_IOH_UDC 0x801D
366
367static const char ep0_string[] = "ep0in";
368static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */
369struct pch_udc_dev *pch_udc; /* pointer to device object */
370static int speed_fs;
371module_param_named(speed_fs, speed_fs, bool, S_IRUGO);
372MODULE_PARM_DESC(speed_fs, "true for Full speed operation");
373
374/**
375 * struct pch_udc_request - Structure holding a PCH USB device request packet
376 * @req: embedded ep request
377 * @td_data_phys: phys. address
378 * @td_data: first dma desc. of chain
379 * @td_data_last: last dma desc. of chain
380 * @queue: associated queue
381 * @dma_going: DMA in progress for request
382 * @dma_mapped: DMA memory mapped for request
383 * @dma_done: DMA completed for request
384 * @chain_len: chain length
385 * @buf: Buffer memory for align adjustment
386 * @dma: DMA memory for align adjustment
387 */
388struct pch_udc_request {
389 struct usb_request req;
390 dma_addr_t td_data_phys;
391 struct pch_udc_data_dma_desc *td_data;
392 struct pch_udc_data_dma_desc *td_data_last;
393 struct list_head queue;
394 unsigned dma_going:1,
395 dma_mapped:1,
396 dma_done:1;
397 unsigned chain_len;
398 void *buf;
399 dma_addr_t dma;
400};
401
402static inline u32 pch_udc_readl(struct pch_udc_dev *dev, unsigned long reg)
403{
404 return ioread32(dev->base_addr + reg);
405}
406
407static inline void pch_udc_writel(struct pch_udc_dev *dev,
408 unsigned long val, unsigned long reg)
409{
410 iowrite32(val, dev->base_addr + reg);
411}
412
413static inline void pch_udc_bit_set(struct pch_udc_dev *dev,
414 unsigned long reg,
415 unsigned long bitmask)
416{
417 pch_udc_writel(dev, pch_udc_readl(dev, reg) | bitmask, reg);
418}
419
420static inline void pch_udc_bit_clr(struct pch_udc_dev *dev,
421 unsigned long reg,
422 unsigned long bitmask)
423{
424 pch_udc_writel(dev, pch_udc_readl(dev, reg) & ~(bitmask), reg);
425}
426
427static inline u32 pch_udc_ep_readl(struct pch_udc_ep *ep, unsigned long reg)
428{
429 return ioread32(ep->dev->base_addr + ep->offset_addr + reg);
430}
431
432static inline void pch_udc_ep_writel(struct pch_udc_ep *ep,
433 unsigned long val, unsigned long reg)
434{
435 iowrite32(val, ep->dev->base_addr + ep->offset_addr + reg);
436}
437
438static inline void pch_udc_ep_bit_set(struct pch_udc_ep *ep,
439 unsigned long reg,
440 unsigned long bitmask)
441{
442 pch_udc_ep_writel(ep, pch_udc_ep_readl(ep, reg) | bitmask, reg);
443}
444
445static inline void pch_udc_ep_bit_clr(struct pch_udc_ep *ep,
446 unsigned long reg,
447 unsigned long bitmask)
448{
449 pch_udc_ep_writel(ep, pch_udc_ep_readl(ep, reg) & ~(bitmask), reg);
450}
451
452/**
453 * pch_udc_csr_busy() - Wait till idle.
454 * @dev: Reference to pch_udc_dev structure
455 */
456static void pch_udc_csr_busy(struct pch_udc_dev *dev)
457{
458 unsigned int count = 200;
459
460 /* Wait till idle */
461 while ((pch_udc_readl(dev, UDC_CSR_BUSY_ADDR) & UDC_CSR_BUSY)
462 && --count)
463 cpu_relax();
464 if (!count)
465 dev_err(&dev->pdev->dev, "%s: wait error\n", __func__);
466}
467
468/**
469 * pch_udc_write_csr() - Write the command and status registers.
470 * @dev: Reference to pch_udc_dev structure
471 * @val: value to be written to CSR register
472 * @addr: address of CSR register
473 */
474static void pch_udc_write_csr(struct pch_udc_dev *dev, unsigned long val,
475 unsigned int ep)
476{
477 unsigned long reg = PCH_UDC_CSR(ep);
478
479 pch_udc_csr_busy(dev); /* Wait till idle */
480 pch_udc_writel(dev, val, reg);
481 pch_udc_csr_busy(dev); /* Wait till idle */
482}
483
484/**
485 * pch_udc_read_csr() - Read the command and status registers.
486 * @dev: Reference to pch_udc_dev structure
487 * @addr: address of CSR register
488 *
489 * Return codes: content of CSR register
490 */
491static u32 pch_udc_read_csr(struct pch_udc_dev *dev, unsigned int ep)
492{
493 unsigned long reg = PCH_UDC_CSR(ep);
494
495 pch_udc_csr_busy(dev); /* Wait till idle */
496 pch_udc_readl(dev, reg); /* Dummy read */
497 pch_udc_csr_busy(dev); /* Wait till idle */
498 return pch_udc_readl(dev, reg);
499}
500
501/**
502 * pch_udc_rmt_wakeup() - Initiate for remote wakeup
503 * @dev: Reference to pch_udc_dev structure
504 */
505static inline void pch_udc_rmt_wakeup(struct pch_udc_dev *dev)
506{
507 pch_udc_bit_set(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_RES);
508 mdelay(1);
509 pch_udc_bit_clr(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_RES);
510}
511
512/**
513 * pch_udc_get_frame() - Get the current frame from device status register
514 * @dev: Reference to pch_udc_dev structure
515 * Retern current frame
516 */
517static inline int pch_udc_get_frame(struct pch_udc_dev *dev)
518{
519 u32 frame = pch_udc_readl(dev, UDC_DEVSTS_ADDR);
520 return (frame & UDC_DEVSTS_TS_MASK) >> UDC_DEVSTS_TS_SHIFT;
521}
522
523/**
524 * pch_udc_clear_selfpowered() - Clear the self power control
525 * @dev: Reference to pch_udc_regs structure
526 */
527static inline void pch_udc_clear_selfpowered(struct pch_udc_dev *dev)
528{
529 pch_udc_bit_clr(dev, UDC_DEVCFG_ADDR, UDC_DEVCFG_SP);
530}
531
532/**
533 * pch_udc_set_selfpowered() - Set the self power control
534 * @dev: Reference to pch_udc_regs structure
535 */
536static inline void pch_udc_set_selfpowered(struct pch_udc_dev *dev)
537{
538 pch_udc_bit_set(dev, UDC_DEVCFG_ADDR, UDC_DEVCFG_SP);
539}
540
541/**
542 * pch_udc_set_disconnect() - Set the disconnect status.
543 * @dev: Reference to pch_udc_regs structure
544 */
545static inline void pch_udc_set_disconnect(struct pch_udc_dev *dev)
546{
547 pch_udc_bit_set(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_SD);
548}
549
550/**
551 * pch_udc_clear_disconnect() - Clear the disconnect status.
552 * @dev: Reference to pch_udc_regs structure
553 */
554static void pch_udc_clear_disconnect(struct pch_udc_dev *dev)
555{
556 /* Clear the disconnect */
557 pch_udc_bit_set(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_RES);
558 pch_udc_bit_clr(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_SD);
559 mdelay(1);
560 /* Resume USB signalling */
561 pch_udc_bit_clr(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_RES);
562}
563
564/**
565 * pch_udc_vbus_session() - set or clearr the disconnect status.
566 * @dev: Reference to pch_udc_regs structure
567 * @is_active: Parameter specifying the action
568 * 0: indicating VBUS power is ending
569 * !0: indicating VBUS power is starting
570 */
571static inline void pch_udc_vbus_session(struct pch_udc_dev *dev,
572 int is_active)
573{
574 if (is_active)
575 pch_udc_clear_disconnect(dev);
576 else
577 pch_udc_set_disconnect(dev);
578}
579
580/**
581 * pch_udc_ep_set_stall() - Set the stall of endpoint
582 * @ep: Reference to structure of type pch_udc_ep_regs
583 */
584static void pch_udc_ep_set_stall(struct pch_udc_ep *ep)
585{
586 if (ep->in) {
587 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_F);
588 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_S);
589 } else {
590 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_S);
591 }
592}
593
594/**
595 * pch_udc_ep_clear_stall() - Clear the stall of endpoint
596 * @ep: Reference to structure of type pch_udc_ep_regs
597 */
598static inline void pch_udc_ep_clear_stall(struct pch_udc_ep *ep)
599{
600 /* Clear the stall */
601 pch_udc_ep_bit_clr(ep, UDC_EPCTL_ADDR, UDC_EPCTL_S);
602 /* Clear NAK by writing CNAK */
603 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_CNAK);
604}
605
606/**
607 * pch_udc_ep_set_trfr_type() - Set the transfer type of endpoint
608 * @ep: Reference to structure of type pch_udc_ep_regs
609 * @type: Type of endpoint
610 */
611static inline void pch_udc_ep_set_trfr_type(struct pch_udc_ep *ep,
612 u8 type)
613{
614 pch_udc_ep_writel(ep, ((type << UDC_EPCTL_ET_SHIFT) &
615 UDC_EPCTL_ET_MASK), UDC_EPCTL_ADDR);
616}
617
618/**
619 * pch_udc_ep_set_bufsz() - Set the maximum packet size for the endpoint
620 * @ep: Reference to structure of type pch_udc_ep_regs
621 * @buf_size: The buffer word size
622 */
623static void pch_udc_ep_set_bufsz(struct pch_udc_ep *ep,
624 u32 buf_size, u32 ep_in)
625{
626 u32 data;
627 if (ep_in) {
628 data = pch_udc_ep_readl(ep, UDC_BUFIN_FRAMENUM_ADDR);
629 data = (data & 0xffff0000) | (buf_size & 0xffff);
630 pch_udc_ep_writel(ep, data, UDC_BUFIN_FRAMENUM_ADDR);
631 } else {
632 data = pch_udc_ep_readl(ep, UDC_BUFOUT_MAXPKT_ADDR);
633 data = (buf_size << 16) | (data & 0xffff);
634 pch_udc_ep_writel(ep, data, UDC_BUFOUT_MAXPKT_ADDR);
635 }
636}
637
638/**
639 * pch_udc_ep_set_maxpkt() - Set the Max packet size for the endpoint
640 * @ep: Reference to structure of type pch_udc_ep_regs
641 * @pkt_size: The packet byte size
642 */
643static void pch_udc_ep_set_maxpkt(struct pch_udc_ep *ep, u32 pkt_size)
644{
645 u32 data = pch_udc_ep_readl(ep, UDC_BUFOUT_MAXPKT_ADDR);
646 data = (data & 0xffff0000) | (pkt_size & 0xffff);
647 pch_udc_ep_writel(ep, data, UDC_BUFOUT_MAXPKT_ADDR);
648}
649
650/**
651 * pch_udc_ep_set_subptr() - Set the Setup buffer pointer for the endpoint
652 * @ep: Reference to structure of type pch_udc_ep_regs
653 * @addr: Address of the register
654 */
655static inline void pch_udc_ep_set_subptr(struct pch_udc_ep *ep, u32 addr)
656{
657 pch_udc_ep_writel(ep, addr, UDC_SUBPTR_ADDR);
658}
659
660/**
661 * pch_udc_ep_set_ddptr() - Set the Data descriptor pointer for the endpoint
662 * @ep: Reference to structure of type pch_udc_ep_regs
663 * @addr: Address of the register
664 */
665static inline void pch_udc_ep_set_ddptr(struct pch_udc_ep *ep, u32 addr)
666{
667 pch_udc_ep_writel(ep, addr, UDC_DESPTR_ADDR);
668}
669
670/**
671 * pch_udc_ep_set_pd() - Set the poll demand bit for the endpoint
672 * @ep: Reference to structure of type pch_udc_ep_regs
673 */
674static inline void pch_udc_ep_set_pd(struct pch_udc_ep *ep)
675{
676 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_P);
677}
678
679/**
680 * pch_udc_ep_set_rrdy() - Set the receive ready bit for the endpoint
681 * @ep: Reference to structure of type pch_udc_ep_regs
682 */
683static inline void pch_udc_ep_set_rrdy(struct pch_udc_ep *ep)
684{
685 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_RRDY);
686}
687
688/**
689 * pch_udc_ep_clear_rrdy() - Clear the receive ready bit for the endpoint
690 * @ep: Reference to structure of type pch_udc_ep_regs
691 */
692static inline void pch_udc_ep_clear_rrdy(struct pch_udc_ep *ep)
693{
694 pch_udc_ep_bit_clr(ep, UDC_EPCTL_ADDR, UDC_EPCTL_RRDY);
695}
696
697/**
698 * pch_udc_set_dma() - Set the 'TDE' or RDE bit of device control
699 * register depending on the direction specified
700 * @dev: Reference to structure of type pch_udc_regs
701 * @dir: whether Tx or Rx
702 * DMA_DIR_RX: Receive
703 * DMA_DIR_TX: Transmit
704 */
705static inline void pch_udc_set_dma(struct pch_udc_dev *dev, int dir)
706{
707 if (dir == DMA_DIR_RX)
708 pch_udc_bit_set(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_RDE);
709 else if (dir == DMA_DIR_TX)
710 pch_udc_bit_set(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_TDE);
711}
712
713/**
714 * pch_udc_clear_dma() - Clear the 'TDE' or RDE bit of device control
715 * register depending on the direction specified
716 * @dev: Reference to structure of type pch_udc_regs
717 * @dir: Whether Tx or Rx
718 * DMA_DIR_RX: Receive
719 * DMA_DIR_TX: Transmit
720 */
721static inline void pch_udc_clear_dma(struct pch_udc_dev *dev, int dir)
722{
723 if (dir == DMA_DIR_RX)
724 pch_udc_bit_clr(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_RDE);
725 else if (dir == DMA_DIR_TX)
726 pch_udc_bit_clr(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_TDE);
727}
728
729/**
730 * pch_udc_set_csr_done() - Set the device control register
731 * CSR done field (bit 13)
732 * @dev: reference to structure of type pch_udc_regs
733 */
734static inline void pch_udc_set_csr_done(struct pch_udc_dev *dev)
735{
736 pch_udc_bit_set(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_CSR_DONE);
737}
738
739/**
740 * pch_udc_disable_interrupts() - Disables the specified interrupts
741 * @dev: Reference to structure of type pch_udc_regs
742 * @mask: Mask to disable interrupts
743 */
744static inline void pch_udc_disable_interrupts(struct pch_udc_dev *dev,
745 u32 mask)
746{
747 pch_udc_bit_set(dev, UDC_DEVIRQMSK_ADDR, mask);
748}
749
750/**
751 * pch_udc_enable_interrupts() - Enable the specified interrupts
752 * @dev: Reference to structure of type pch_udc_regs
753 * @mask: Mask to enable interrupts
754 */
755static inline void pch_udc_enable_interrupts(struct pch_udc_dev *dev,
756 u32 mask)
757{
758 pch_udc_bit_clr(dev, UDC_DEVIRQMSK_ADDR, mask);
759}
760
761/**
762 * pch_udc_disable_ep_interrupts() - Disable endpoint interrupts
763 * @dev: Reference to structure of type pch_udc_regs
764 * @mask: Mask to disable interrupts
765 */
766static inline void pch_udc_disable_ep_interrupts(struct pch_udc_dev *dev,
767 u32 mask)
768{
769 pch_udc_bit_set(dev, UDC_EPIRQMSK_ADDR, mask);
770}
771
772/**
773 * pch_udc_enable_ep_interrupts() - Enable endpoint interrupts
774 * @dev: Reference to structure of type pch_udc_regs
775 * @mask: Mask to enable interrupts
776 */
777static inline void pch_udc_enable_ep_interrupts(struct pch_udc_dev *dev,
778 u32 mask)
779{
780 pch_udc_bit_clr(dev, UDC_EPIRQMSK_ADDR, mask);
781}
782
783/**
784 * pch_udc_read_device_interrupts() - Read the device interrupts
785 * @dev: Reference to structure of type pch_udc_regs
786 * Retern The device interrupts
787 */
788static inline u32 pch_udc_read_device_interrupts(struct pch_udc_dev *dev)
789{
790 return pch_udc_readl(dev, UDC_DEVIRQSTS_ADDR);
791}
792
793/**
794 * pch_udc_write_device_interrupts() - Write device interrupts
795 * @dev: Reference to structure of type pch_udc_regs
796 * @val: The value to be written to interrupt register
797 */
798static inline void pch_udc_write_device_interrupts(struct pch_udc_dev *dev,
799 u32 val)
800{
801 pch_udc_writel(dev, val, UDC_DEVIRQSTS_ADDR);
802}
803
804/**
805 * pch_udc_read_ep_interrupts() - Read the endpoint interrupts
806 * @dev: Reference to structure of type pch_udc_regs
807 * Retern The endpoint interrupt
808 */
809static inline u32 pch_udc_read_ep_interrupts(struct pch_udc_dev *dev)
810{
811 return pch_udc_readl(dev, UDC_EPIRQSTS_ADDR);
812}
813
814/**
815 * pch_udc_write_ep_interrupts() - Clear endpoint interupts
816 * @dev: Reference to structure of type pch_udc_regs
817 * @val: The value to be written to interrupt register
818 */
819static inline void pch_udc_write_ep_interrupts(struct pch_udc_dev *dev,
820 u32 val)
821{
822 pch_udc_writel(dev, val, UDC_EPIRQSTS_ADDR);
823}
824
825/**
826 * pch_udc_read_device_status() - Read the device status
827 * @dev: Reference to structure of type pch_udc_regs
828 * Retern The device status
829 */
830static inline u32 pch_udc_read_device_status(struct pch_udc_dev *dev)
831{
832 return pch_udc_readl(dev, UDC_DEVSTS_ADDR);
833}
834
835/**
836 * pch_udc_read_ep_control() - Read the endpoint control
837 * @ep: Reference to structure of type pch_udc_ep_regs
838 * Retern The endpoint control register value
839 */
840static inline u32 pch_udc_read_ep_control(struct pch_udc_ep *ep)
841{
842 return pch_udc_ep_readl(ep, UDC_EPCTL_ADDR);
843}
844
845/**
846 * pch_udc_clear_ep_control() - Clear the endpoint control register
847 * @ep: Reference to structure of type pch_udc_ep_regs
848 * Retern The endpoint control register value
849 */
850static inline void pch_udc_clear_ep_control(struct pch_udc_ep *ep)
851{
852 return pch_udc_ep_writel(ep, 0, UDC_EPCTL_ADDR);
853}
854
855/**
856 * pch_udc_read_ep_status() - Read the endpoint status
857 * @ep: Reference to structure of type pch_udc_ep_regs
858 * Retern The endpoint status
859 */
860static inline u32 pch_udc_read_ep_status(struct pch_udc_ep *ep)
861{
862 return pch_udc_ep_readl(ep, UDC_EPSTS_ADDR);
863}
864
865/**
866 * pch_udc_clear_ep_status() - Clear the endpoint status
867 * @ep: Reference to structure of type pch_udc_ep_regs
868 * @stat: Endpoint status
869 */
870static inline void pch_udc_clear_ep_status(struct pch_udc_ep *ep,
871 u32 stat)
872{
873 return pch_udc_ep_writel(ep, stat, UDC_EPSTS_ADDR);
874}
875
876/**
877 * pch_udc_ep_set_nak() - Set the bit 7 (SNAK field)
878 * of the endpoint control register
879 * @ep: Reference to structure of type pch_udc_ep_regs
880 */
881static inline void pch_udc_ep_set_nak(struct pch_udc_ep *ep)
882{
883 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_SNAK);
884}
885
886/**
887 * pch_udc_ep_clear_nak() - Set the bit 8 (CNAK field)
888 * of the endpoint control register
889 * @ep: reference to structure of type pch_udc_ep_regs
890 */
891static void pch_udc_ep_clear_nak(struct pch_udc_ep *ep)
892{
893 unsigned int loopcnt = 0;
894 struct pch_udc_dev *dev = ep->dev;
895
896 if (!(pch_udc_ep_readl(ep, UDC_EPCTL_ADDR) & UDC_EPCTL_NAK))
897 return;
898 if (!ep->in) {
899 loopcnt = 10000;
900 while (!(pch_udc_read_ep_status(ep) & UDC_EPSTS_MRXFIFO_EMP) &&
901 --loopcnt)
902 udelay(5);
903 if (!loopcnt)
904 dev_err(&dev->pdev->dev, "%s: RxFIFO not Empty\n",
905 __func__);
906 }
907 loopcnt = 10000;
908 while ((pch_udc_read_ep_control(ep) & UDC_EPCTL_NAK) && --loopcnt) {
909 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_CNAK);
910 udelay(5);
911 }
912 if (!loopcnt)
913 dev_err(&dev->pdev->dev, "%s: Clear NAK not set for ep%d%s\n",
914 __func__, ep->num, (ep->in ? "in" : "out"));
915}
916
917/**
918 * pch_udc_ep_fifo_flush() - Flush the endpoint fifo
919 * @ep: reference to structure of type pch_udc_ep_regs
920 * @dir: direction of endpoint
921 * 0: endpoint is OUT
922 * !0: endpoint is IN
923 */
924static void pch_udc_ep_fifo_flush(struct pch_udc_ep *ep, int dir)
925{
926 if (dir) { /* IN ep */
927 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_F);
928 return;
929 }
930}
931
932/**
933 * pch_udc_ep_enable() - This api enables endpoint
934 * @regs: Reference to structure pch_udc_ep_regs
935 * @desc: endpoint descriptor
936 */
937static void pch_udc_ep_enable(struct pch_udc_ep *ep,
938 struct pch_udc_cfg_data *cfg,
939 const struct usb_endpoint_descriptor *desc)
940{
941 u32 val = 0;
942 u32 buff_size = 0;
943
944 pch_udc_ep_set_trfr_type(ep, desc->bmAttributes);
945 if (ep->in)
946 buff_size = UDC_EPIN_BUFF_SIZE;
947 else
948 buff_size = UDC_EPOUT_BUFF_SIZE;
949 pch_udc_ep_set_bufsz(ep, buff_size, ep->in);
950 pch_udc_ep_set_maxpkt(ep, le16_to_cpu(desc->wMaxPacketSize));
951 pch_udc_ep_set_nak(ep);
952 pch_udc_ep_fifo_flush(ep, ep->in);
953 /* Configure the endpoint */
954 val = ep->num << UDC_CSR_NE_NUM_SHIFT | ep->in << UDC_CSR_NE_DIR_SHIFT |
955 ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) <<
956 UDC_CSR_NE_TYPE_SHIFT) |
957 (cfg->cur_cfg << UDC_CSR_NE_CFG_SHIFT) |
958 (cfg->cur_intf << UDC_CSR_NE_INTF_SHIFT) |
959 (cfg->cur_alt << UDC_CSR_NE_ALT_SHIFT) |
960 le16_to_cpu(desc->wMaxPacketSize) << UDC_CSR_NE_MAX_PKT_SHIFT;
961
962 if (ep->in)
963 pch_udc_write_csr(ep->dev, val, UDC_EPIN_IDX(ep->num));
964 else
965 pch_udc_write_csr(ep->dev, val, UDC_EPOUT_IDX(ep->num));
966}
967
968/**
969 * pch_udc_ep_disable() - This api disables endpoint
970 * @regs: Reference to structure pch_udc_ep_regs
971 */
972static void pch_udc_ep_disable(struct pch_udc_ep *ep)
973{
974 if (ep->in) {
975 /* flush the fifo */
976 pch_udc_ep_writel(ep, UDC_EPCTL_F, UDC_EPCTL_ADDR);
977 /* set NAK */
978 pch_udc_ep_writel(ep, UDC_EPCTL_SNAK, UDC_EPCTL_ADDR);
979 pch_udc_ep_bit_set(ep, UDC_EPSTS_ADDR, UDC_EPSTS_IN);
980 } else {
981 /* set NAK */
982 pch_udc_ep_writel(ep, UDC_EPCTL_SNAK, UDC_EPCTL_ADDR);
983 }
984 /* reset desc pointer */
985 pch_udc_ep_writel(ep, 0, UDC_DESPTR_ADDR);
986}
987
988/**
989 * pch_udc_wait_ep_stall() - Wait EP stall.
990 * @dev: Reference to pch_udc_dev structure
991 */
992static void pch_udc_wait_ep_stall(struct pch_udc_ep *ep)
993{
994 unsigned int count = 10000;
995
996 /* Wait till idle */
997 while ((pch_udc_read_ep_control(ep) & UDC_EPCTL_S) && --count)
998 udelay(5);
999 if (!count)
1000 dev_err(&ep->dev->pdev->dev, "%s: wait error\n", __func__);
1001}
1002
1003/**
1004 * pch_udc_init() - This API initializes usb device controller
1005 * @dev: Rreference to pch_udc_regs structure
1006 */
1007static void pch_udc_init(struct pch_udc_dev *dev)
1008{
1009 if (NULL == dev) {
1010 pr_err("%s: Invalid address\n", __func__);
1011 return;
1012 }
1013 /* Soft Reset and Reset PHY */
1014 pch_udc_writel(dev, UDC_SRST, UDC_SRST_ADDR);
1015 pch_udc_writel(dev, UDC_SRST | UDC_PSRST, UDC_SRST_ADDR);
1016 mdelay(1);
1017 pch_udc_writel(dev, UDC_SRST, UDC_SRST_ADDR);
1018 pch_udc_writel(dev, 0x00, UDC_SRST_ADDR);
1019 mdelay(1);
1020 /* mask and clear all device interrupts */
1021 pch_udc_bit_set(dev, UDC_DEVIRQMSK_ADDR, UDC_DEVINT_MSK);
1022 pch_udc_bit_set(dev, UDC_DEVIRQSTS_ADDR, UDC_DEVINT_MSK);
1023
1024 /* mask and clear all ep interrupts */
1025 pch_udc_bit_set(dev, UDC_EPIRQMSK_ADDR, UDC_EPINT_MSK_DISABLE_ALL);
1026 pch_udc_bit_set(dev, UDC_EPIRQSTS_ADDR, UDC_EPINT_MSK_DISABLE_ALL);
1027
1028 /* enable dynamic CSR programmingi, self powered and device speed */
1029 if (speed_fs)
1030 pch_udc_bit_set(dev, UDC_DEVCFG_ADDR, UDC_DEVCFG_CSR_PRG |
1031 UDC_DEVCFG_SP | UDC_DEVCFG_SPD_FS);
1032 else /* defaul high speed */
1033 pch_udc_bit_set(dev, UDC_DEVCFG_ADDR, UDC_DEVCFG_CSR_PRG |
1034 UDC_DEVCFG_SP | UDC_DEVCFG_SPD_HS);
1035 pch_udc_bit_set(dev, UDC_DEVCTL_ADDR,
1036 (PCH_UDC_THLEN << UDC_DEVCTL_THLEN_SHIFT) |
1037 (PCH_UDC_BRLEN << UDC_DEVCTL_BRLEN_SHIFT) |
1038 UDC_DEVCTL_MODE | UDC_DEVCTL_BREN |
1039 UDC_DEVCTL_THE);
1040}
1041
1042/**
1043 * pch_udc_exit() - This API exit usb device controller
1044 * @dev: Reference to pch_udc_regs structure
1045 */
1046static void pch_udc_exit(struct pch_udc_dev *dev)
1047{
1048 /* mask all device interrupts */
1049 pch_udc_bit_set(dev, UDC_DEVIRQMSK_ADDR, UDC_DEVINT_MSK);
1050 /* mask all ep interrupts */
1051 pch_udc_bit_set(dev, UDC_EPIRQMSK_ADDR, UDC_EPINT_MSK_DISABLE_ALL);
1052 /* put device in disconnected state */
1053 pch_udc_set_disconnect(dev);
1054}
1055
1056/**
1057 * pch_udc_pcd_get_frame() - This API is invoked to get the current frame number
1058 * @gadget: Reference to the gadget driver
1059 *
1060 * Return codes:
1061 * 0: Success
1062 * -EINVAL: If the gadget passed is NULL
1063 */
1064static int pch_udc_pcd_get_frame(struct usb_gadget *gadget)
1065{
1066 struct pch_udc_dev *dev;
1067
1068 if (!gadget)
1069 return -EINVAL;
1070 dev = container_of(gadget, struct pch_udc_dev, gadget);
1071 return pch_udc_get_frame(dev);
1072}
1073
1074/**
1075 * pch_udc_pcd_wakeup() - This API is invoked to initiate a remote wakeup
1076 * @gadget: Reference to the gadget driver
1077 *
1078 * Return codes:
1079 * 0: Success
1080 * -EINVAL: If the gadget passed is NULL
1081 */
1082static int pch_udc_pcd_wakeup(struct usb_gadget *gadget)
1083{
1084 struct pch_udc_dev *dev;
1085 unsigned long flags;
1086
1087 if (!gadget)
1088 return -EINVAL;
1089 dev = container_of(gadget, struct pch_udc_dev, gadget);
1090 spin_lock_irqsave(&dev->lock, flags);
1091 pch_udc_rmt_wakeup(dev);
1092 spin_unlock_irqrestore(&dev->lock, flags);
1093 return 0;
1094}
1095
1096/**
1097 * pch_udc_pcd_selfpowered() - This API is invoked to specify whether the device
1098 * is self powered or not
1099 * @gadget: Reference to the gadget driver
1100 * @value: Specifies self powered or not
1101 *
1102 * Return codes:
1103 * 0: Success
1104 * -EINVAL: If the gadget passed is NULL
1105 */
1106static int pch_udc_pcd_selfpowered(struct usb_gadget *gadget, int value)
1107{
1108 struct pch_udc_dev *dev;
1109
1110 if (!gadget)
1111 return -EINVAL;
1112 dev = container_of(gadget, struct pch_udc_dev, gadget);
1113 if (value)
1114 pch_udc_set_selfpowered(dev);
1115 else
1116 pch_udc_clear_selfpowered(dev);
1117 return 0;
1118}
1119
1120/**
1121 * pch_udc_pcd_pullup() - This API is invoked to make the device
1122 * visible/invisible to the host
1123 * @gadget: Reference to the gadget driver
1124 * @is_on: Specifies whether the pull up is made active or inactive
1125 *
1126 * Return codes:
1127 * 0: Success
1128 * -EINVAL: If the gadget passed is NULL
1129 */
1130static int pch_udc_pcd_pullup(struct usb_gadget *gadget, int is_on)
1131{
1132 struct pch_udc_dev *dev;
1133
1134 if (!gadget)
1135 return -EINVAL;
1136 dev = container_of(gadget, struct pch_udc_dev, gadget);
1137 pch_udc_vbus_session(dev, is_on);
1138 return 0;
1139}
1140
1141/**
1142 * pch_udc_pcd_vbus_session() - This API is used by a driver for an external
1143 * transceiver (or GPIO) that
1144 * detects a VBUS power session starting/ending
1145 * @gadget: Reference to the gadget driver
1146 * @is_active: specifies whether the session is starting or ending
1147 *
1148 * Return codes:
1149 * 0: Success
1150 * -EINVAL: If the gadget passed is NULL
1151 */
1152static int pch_udc_pcd_vbus_session(struct usb_gadget *gadget, int is_active)
1153{
1154 struct pch_udc_dev *dev;
1155
1156 if (!gadget)
1157 return -EINVAL;
1158 dev = container_of(gadget, struct pch_udc_dev, gadget);
1159 pch_udc_vbus_session(dev, is_active);
1160 return 0;
1161}
1162
1163/**
1164 * pch_udc_pcd_vbus_draw() - This API is used by gadget drivers during
1165 * SET_CONFIGURATION calls to
1166 * specify how much power the device can consume
1167 * @gadget: Reference to the gadget driver
1168 * @mA: specifies the current limit in 2mA unit
1169 *
1170 * Return codes:
1171 * -EINVAL: If the gadget passed is NULL
1172 * -EOPNOTSUPP:
1173 */
1174static int pch_udc_pcd_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
1175{
1176 return -EOPNOTSUPP;
1177}
1178
1179static const struct usb_gadget_ops pch_udc_ops = {
1180 .get_frame = pch_udc_pcd_get_frame,
1181 .wakeup = pch_udc_pcd_wakeup,
1182 .set_selfpowered = pch_udc_pcd_selfpowered,
1183 .pullup = pch_udc_pcd_pullup,
1184 .vbus_session = pch_udc_pcd_vbus_session,
1185 .vbus_draw = pch_udc_pcd_vbus_draw,
1186};
1187
1188/**
1189 * complete_req() - This API is invoked from the driver when processing
1190 * of a request is complete
1191 * @ep: Reference to the endpoint structure
1192 * @req: Reference to the request structure
1193 * @status: Indicates the success/failure of completion
1194 */
1195static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req,
1196 int status)
1197{
1198 struct pch_udc_dev *dev;
1199 unsigned halted = ep->halted;
1200
1201 list_del_init(&req->queue);
1202
1203 /* set new status if pending */
1204 if (req->req.status == -EINPROGRESS)
1205 req->req.status = status;
1206 else
1207 status = req->req.status;
1208
1209 dev = ep->dev;
1210 if (req->dma_mapped) {
1211 if (req->dma == DMA_ADDR_INVALID) {
1212 if (ep->in)
1213 dma_unmap_single(&dev->pdev->dev, req->req.dma,
1214 req->req.length,
1215 DMA_TO_DEVICE);
1216 else
1217 dma_unmap_single(&dev->pdev->dev, req->req.dma,
1218 req->req.length,
1219 DMA_FROM_DEVICE);
1220 req->req.dma = DMA_ADDR_INVALID;
1221 } else {
1222 if (ep->in)
1223 dma_unmap_single(&dev->pdev->dev, req->dma,
1224 req->req.length,
1225 DMA_TO_DEVICE);
1226 else {
1227 dma_unmap_single(&dev->pdev->dev, req->dma,
1228 req->req.length,
1229 DMA_FROM_DEVICE);
1230 memcpy(req->req.buf, req->buf, req->req.length);
1231 }
1232 kfree(req->buf);
1233 req->dma = DMA_ADDR_INVALID;
1234 }
1235 req->dma_mapped = 0;
1236 }
1237 ep->halted = 1;
1238 spin_unlock(&dev->lock);
1239 if (!ep->in)
1240 pch_udc_ep_clear_rrdy(ep);
1241 req->req.complete(&ep->ep, &req->req);
1242 spin_lock(&dev->lock);
1243 ep->halted = halted;
1244}
1245
1246/**
1247 * empty_req_queue() - This API empties the request queue of an endpoint
1248 * @ep: Reference to the endpoint structure
1249 */
1250static void empty_req_queue(struct pch_udc_ep *ep)
1251{
1252 struct pch_udc_request *req;
1253
1254 ep->halted = 1;
1255 while (!list_empty(&ep->queue)) {
1256 req = list_entry(ep->queue.next, struct pch_udc_request, queue);
1257 complete_req(ep, req, -ESHUTDOWN); /* Remove from list */
1258 }
1259}
1260
1261/**
1262 * pch_udc_free_dma_chain() - This function frees the DMA chain created
1263 * for the request
1264 * @dev Reference to the driver structure
1265 * @req Reference to the request to be freed
1266 *
1267 * Return codes:
1268 * 0: Success
1269 */
1270static void pch_udc_free_dma_chain(struct pch_udc_dev *dev,
1271 struct pch_udc_request *req)
1272{
1273 struct pch_udc_data_dma_desc *td = req->td_data;
1274 unsigned i = req->chain_len;
1275
1276 dma_addr_t addr2;
1277 dma_addr_t addr = (dma_addr_t)td->next;
1278 td->next = 0x00;
1279 for (; i > 1; --i) {
1280 /* do not free first desc., will be done by free for request */
1281 td = phys_to_virt(addr);
1282 addr2 = (dma_addr_t)td->next;
1283 pci_pool_free(dev->data_requests, td, addr);
1284 td->next = 0x00;
1285 addr = addr2;
1286 }
1287 req->chain_len = 1;
1288}
1289
1290/**
1291 * pch_udc_create_dma_chain() - This function creates or reinitializes
1292 * a DMA chain
1293 * @ep: Reference to the endpoint structure
1294 * @req: Reference to the request
1295 * @buf_len: The buffer length
1296 * @gfp_flags: Flags to be used while mapping the data buffer
1297 *
1298 * Return codes:
1299 * 0: success,
1300 * -ENOMEM: pci_pool_alloc invocation fails
1301 */
1302static int pch_udc_create_dma_chain(struct pch_udc_ep *ep,
1303 struct pch_udc_request *req,
1304 unsigned long buf_len,
1305 gfp_t gfp_flags)
1306{
1307 struct pch_udc_data_dma_desc *td = req->td_data, *last;
1308 unsigned long bytes = req->req.length, i = 0;
1309 dma_addr_t dma_addr;
1310 unsigned len = 1;
1311
1312 if (req->chain_len > 1)
1313 pch_udc_free_dma_chain(ep->dev, req);
1314
1315 if (req->dma == DMA_ADDR_INVALID)
1316 td->dataptr = req->req.dma;
1317 else
1318 td->dataptr = req->dma;
1319
1320 td->status = PCH_UDC_BS_HST_BSY;
1321 for (; ; bytes -= buf_len, ++len) {
1322 td->status = PCH_UDC_BS_HST_BSY | min(buf_len, bytes);
1323 if (bytes <= buf_len)
1324 break;
1325 last = td;
1326 td = pci_pool_alloc(ep->dev->data_requests, gfp_flags,
1327 &dma_addr);
1328 if (!td)
1329 goto nomem;
1330 i += buf_len;
1331 td->dataptr = req->td_data->dataptr + i;
1332 last->next = dma_addr;
1333 }
1334
1335 req->td_data_last = td;
1336 td->status |= PCH_UDC_DMA_LAST;
1337 td->next = req->td_data_phys;
1338 req->chain_len = len;
1339 return 0;
1340
1341nomem:
1342 if (len > 1) {
1343 req->chain_len = len;
1344 pch_udc_free_dma_chain(ep->dev, req);
1345 }
1346 req->chain_len = 1;
1347 return -ENOMEM;
1348}
1349
1350/**
1351 * prepare_dma() - This function creates and initializes the DMA chain
1352 * for the request
1353 * @ep: Reference to the endpoint structure
1354 * @req: Reference to the request
1355 * @gfp: Flag to be used while mapping the data buffer
1356 *
1357 * Return codes:
1358 * 0: Success
1359 * Other 0: linux error number on failure
1360 */
1361static int prepare_dma(struct pch_udc_ep *ep, struct pch_udc_request *req,
1362 gfp_t gfp)
1363{
1364 int retval;
1365
1366 /* Allocate and create a DMA chain */
1367 retval = pch_udc_create_dma_chain(ep, req, ep->ep.maxpacket, gfp);
1368 if (retval) {
1369 pr_err("%s: could not create DMA chain:%d\n", __func__, retval);
1370 return retval;
1371 }
1372 if (ep->in)
1373 req->td_data->status = (req->td_data->status &
1374 ~PCH_UDC_BUFF_STS) | PCH_UDC_BS_HST_RDY;
1375 return 0;
1376}
1377
1378/**
1379 * process_zlp() - This function process zero length packets
1380 * from the gadget driver
1381 * @ep: Reference to the endpoint structure
1382 * @req: Reference to the request
1383 */
1384static void process_zlp(struct pch_udc_ep *ep, struct pch_udc_request *req)
1385{
1386 struct pch_udc_dev *dev = ep->dev;
1387
1388 /* IN zlp's are handled by hardware */
1389 complete_req(ep, req, 0);
1390
1391 /* if set_config or set_intf is waiting for ack by zlp
1392 * then set CSR_DONE
1393 */
1394 if (dev->set_cfg_not_acked) {
1395 pch_udc_set_csr_done(dev);
1396 dev->set_cfg_not_acked = 0;
1397 }
1398 /* setup command is ACK'ed now by zlp */
1399 if (!dev->stall && dev->waiting_zlp_ack) {
1400 pch_udc_ep_clear_nak(&(dev->ep[UDC_EP0IN_IDX]));
1401 dev->waiting_zlp_ack = 0;
1402 }
1403}
1404
1405/**
1406 * pch_udc_start_rxrequest() - This function starts the receive requirement.
1407 * @ep: Reference to the endpoint structure
1408 * @req: Reference to the request structure
1409 */
1410static void pch_udc_start_rxrequest(struct pch_udc_ep *ep,
1411 struct pch_udc_request *req)
1412{
1413 struct pch_udc_data_dma_desc *td_data;
1414
1415 pch_udc_clear_dma(ep->dev, DMA_DIR_RX);
1416 td_data = req->td_data;
1417 /* Set the status bits for all descriptors */
1418 while (1) {
1419 td_data->status = (td_data->status & ~PCH_UDC_BUFF_STS) |
1420 PCH_UDC_BS_HST_RDY;
1421 if ((td_data->status & PCH_UDC_DMA_LAST) == PCH_UDC_DMA_LAST)
1422 break;
1423 td_data = phys_to_virt(td_data->next);
1424 }
1425 /* Write the descriptor pointer */
1426 pch_udc_ep_set_ddptr(ep, req->td_data_phys);
1427 req->dma_going = 1;
1428 pch_udc_enable_ep_interrupts(ep->dev, UDC_EPINT_OUT_EP0 << ep->num);
1429 pch_udc_set_dma(ep->dev, DMA_DIR_RX);
1430 pch_udc_ep_clear_nak(ep);
1431 pch_udc_ep_set_rrdy(ep);
1432}
1433
1434/**
1435 * pch_udc_pcd_ep_enable() - This API enables the endpoint. It is called
1436 * from gadget driver
1437 * @usbep: Reference to the USB endpoint structure
1438 * @desc: Reference to the USB endpoint descriptor structure
1439 *
1440 * Return codes:
1441 * 0: Success
1442 * -EINVAL:
1443 * -ESHUTDOWN:
1444 */
1445static int pch_udc_pcd_ep_enable(struct usb_ep *usbep,
1446 const struct usb_endpoint_descriptor *desc)
1447{
1448 struct pch_udc_ep *ep;
1449 struct pch_udc_dev *dev;
1450 unsigned long iflags;
1451
1452 if (!usbep || (usbep->name == ep0_string) || !desc ||
1453 (desc->bDescriptorType != USB_DT_ENDPOINT) || !desc->wMaxPacketSize)
1454 return -EINVAL;
1455
1456 ep = container_of(usbep, struct pch_udc_ep, ep);
1457 dev = ep->dev;
1458 if (!dev->driver || (dev->gadget.speed == USB_SPEED_UNKNOWN))
1459 return -ESHUTDOWN;
1460 spin_lock_irqsave(&dev->lock, iflags);
1461 ep->desc = desc;
1462 ep->halted = 0;
1463 pch_udc_ep_enable(ep, &ep->dev->cfg_data, desc);
1464 ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
1465 pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num));
1466 spin_unlock_irqrestore(&dev->lock, iflags);
1467 return 0;
1468}
1469
1470/**
1471 * pch_udc_pcd_ep_disable() - This API disables endpoint and is called
1472 * from gadget driver
1473 * @usbep Reference to the USB endpoint structure
1474 *
1475 * Return codes:
1476 * 0: Success
1477 * -EINVAL:
1478 */
1479static int pch_udc_pcd_ep_disable(struct usb_ep *usbep)
1480{
1481 struct pch_udc_ep *ep;
1482 struct pch_udc_dev *dev;
1483 unsigned long iflags;
1484
1485 if (!usbep)
1486 return -EINVAL;
1487
1488 ep = container_of(usbep, struct pch_udc_ep, ep);
1489 dev = ep->dev;
1490 if ((usbep->name == ep0_string) || !ep->desc)
1491 return -EINVAL;
1492
1493 spin_lock_irqsave(&ep->dev->lock, iflags);
1494 empty_req_queue(ep);
1495 ep->halted = 1;
1496 pch_udc_ep_disable(ep);
1497 pch_udc_disable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num));
1498 ep->desc = NULL;
1499 INIT_LIST_HEAD(&ep->queue);
1500 spin_unlock_irqrestore(&ep->dev->lock, iflags);
1501 return 0;
1502}
1503
1504/**
1505 * pch_udc_alloc_request() - This function allocates request structure.
1506 * It is called by gadget driver
1507 * @usbep: Reference to the USB endpoint structure
1508 * @gfp: Flag to be used while allocating memory
1509 *
1510 * Return codes:
1511 * NULL: Failure
1512 * Allocated address: Success
1513 */
1514static struct usb_request *pch_udc_alloc_request(struct usb_ep *usbep,
1515 gfp_t gfp)
1516{
1517 struct pch_udc_request *req;
1518 struct pch_udc_ep *ep;
1519 struct pch_udc_data_dma_desc *dma_desc;
1520 struct pch_udc_dev *dev;
1521
1522 if (!usbep)
1523 return NULL;
1524 ep = container_of(usbep, struct pch_udc_ep, ep);
1525 dev = ep->dev;
1526 req = kzalloc(sizeof *req, gfp);
1527 if (!req)
1528 return NULL;
1529 req->req.dma = DMA_ADDR_INVALID;
1530 req->dma = DMA_ADDR_INVALID;
1531 INIT_LIST_HEAD(&req->queue);
1532 if (!ep->dev->dma_addr)
1533 return &req->req;
1534 /* ep0 in requests are allocated from data pool here */
1535 dma_desc = pci_pool_alloc(ep->dev->data_requests, gfp,
1536 &req->td_data_phys);
1537 if (NULL == dma_desc) {
1538 kfree(req);
1539 return NULL;
1540 }
1541 /* prevent from using desc. - set HOST BUSY */
1542 dma_desc->status |= PCH_UDC_BS_HST_BSY;
1543 dma_desc->dataptr = __constant_cpu_to_le32(DMA_ADDR_INVALID);
1544 req->td_data = dma_desc;
1545 req->td_data_last = dma_desc;
1546 req->chain_len = 1;
1547 return &req->req;
1548}
1549
1550/**
1551 * pch_udc_free_request() - This function frees request structure.
1552 * It is called by gadget driver
1553 * @usbep: Reference to the USB endpoint structure
1554 * @usbreq: Reference to the USB request
1555 */
1556static void pch_udc_free_request(struct usb_ep *usbep,
1557 struct usb_request *usbreq)
1558{
1559 struct pch_udc_ep *ep;
1560 struct pch_udc_request *req;
1561 struct pch_udc_dev *dev;
1562
1563 if (!usbep || !usbreq)
1564 return;
1565 ep = container_of(usbep, struct pch_udc_ep, ep);
1566 req = container_of(usbreq, struct pch_udc_request, req);
1567 dev = ep->dev;
1568 if (!list_empty(&req->queue))
1569 dev_err(&dev->pdev->dev, "%s: %s req=0x%p queue not empty\n",
1570 __func__, usbep->name, req);
1571 if (req->td_data != NULL) {
1572 if (req->chain_len > 1)
1573 pch_udc_free_dma_chain(ep->dev, req);
1574 pci_pool_free(ep->dev->data_requests, req->td_data,
1575 req->td_data_phys);
1576 }
1577 kfree(req);
1578}
1579
1580/**
1581 * pch_udc_pcd_queue() - This function queues a request packet. It is called
1582 * by gadget driver
1583 * @usbep: Reference to the USB endpoint structure
1584 * @usbreq: Reference to the USB request
1585 * @gfp: Flag to be used while mapping the data buffer
1586 *
1587 * Return codes:
1588 * 0: Success
1589 * linux error number: Failure
1590 */
1591static int pch_udc_pcd_queue(struct usb_ep *usbep, struct usb_request *usbreq,
1592 gfp_t gfp)
1593{
1594 int retval = 0;
1595 struct pch_udc_ep *ep;
1596 struct pch_udc_dev *dev;
1597 struct pch_udc_request *req;
1598 unsigned long iflags;
1599
1600 if (!usbep || !usbreq || !usbreq->complete || !usbreq->buf)
1601 return -EINVAL;
1602 ep = container_of(usbep, struct pch_udc_ep, ep);
1603 dev = ep->dev;
1604 if (!ep->desc && ep->num)
1605 return -EINVAL;
1606 req = container_of(usbreq, struct pch_udc_request, req);
1607 if (!list_empty(&req->queue))
1608 return -EINVAL;
1609 if (!dev->driver || (dev->gadget.speed == USB_SPEED_UNKNOWN))
1610 return -ESHUTDOWN;
1611 spin_lock_irqsave(&dev->lock, iflags);
1612 /* map the buffer for dma */
1613 if (usbreq->length &&
1614 ((usbreq->dma == DMA_ADDR_INVALID) || !usbreq->dma)) {
1615 if (!((unsigned long)(usbreq->buf) & 0x03)) {
1616 if (ep->in)
1617 usbreq->dma = dma_map_single(&dev->pdev->dev,
1618 usbreq->buf,
1619 usbreq->length,
1620 DMA_TO_DEVICE);
1621 else
1622 usbreq->dma = dma_map_single(&dev->pdev->dev,
1623 usbreq->buf,
1624 usbreq->length,
1625 DMA_FROM_DEVICE);
1626 } else {
1627 req->buf = kzalloc(usbreq->length, GFP_ATOMIC);
1628 if (!req->buf) {
1629 retval = -ENOMEM;
1630 goto probe_end;
1631 }
1632 if (ep->in) {
1633 memcpy(req->buf, usbreq->buf, usbreq->length);
1634 req->dma = dma_map_single(&dev->pdev->dev,
1635 req->buf,
1636 usbreq->length,
1637 DMA_TO_DEVICE);
1638 } else
1639 req->dma = dma_map_single(&dev->pdev->dev,
1640 req->buf,
1641 usbreq->length,
1642 DMA_FROM_DEVICE);
1643 }
1644 req->dma_mapped = 1;
1645 }
1646 if (usbreq->length > 0) {
1647 retval = prepare_dma(ep, req, GFP_ATOMIC);
1648 if (retval)
1649 goto probe_end;
1650 }
1651 usbreq->actual = 0;
1652 usbreq->status = -EINPROGRESS;
1653 req->dma_done = 0;
1654 if (list_empty(&ep->queue) && !ep->halted) {
1655 /* no pending transfer, so start this req */
1656 if (!usbreq->length) {
1657 process_zlp(ep, req);
1658 retval = 0;
1659 goto probe_end;
1660 }
1661 if (!ep->in) {
1662 pch_udc_start_rxrequest(ep, req);
1663 } else {
1664 /*
1665 * For IN trfr the descriptors will be programmed and
1666 * P bit will be set when
1667 * we get an IN token
1668 */
1669 pch_udc_wait_ep_stall(ep);
1670 pch_udc_ep_clear_nak(ep);
1671 pch_udc_enable_ep_interrupts(ep->dev, (1 << ep->num));
1672 }
1673 }
1674 /* Now add this request to the ep's pending requests */
1675 if (req != NULL)
1676 list_add_tail(&req->queue, &ep->queue);
1677
1678probe_end:
1679 spin_unlock_irqrestore(&dev->lock, iflags);
1680 return retval;
1681}
1682
1683/**
1684 * pch_udc_pcd_dequeue() - This function de-queues a request packet.
1685 * It is called by gadget driver
1686 * @usbep: Reference to the USB endpoint structure
1687 * @usbreq: Reference to the USB request
1688 *
1689 * Return codes:
1690 * 0: Success
1691 * linux error number: Failure
1692 */
1693static int pch_udc_pcd_dequeue(struct usb_ep *usbep,
1694 struct usb_request *usbreq)
1695{
1696 struct pch_udc_ep *ep;
1697 struct pch_udc_request *req;
1698 struct pch_udc_dev *dev;
1699 unsigned long flags;
1700 int ret = -EINVAL;
1701
1702 ep = container_of(usbep, struct pch_udc_ep, ep);
1703 dev = ep->dev;
1704 if (!usbep || !usbreq || (!ep->desc && ep->num))
1705 return ret;
1706 req = container_of(usbreq, struct pch_udc_request, req);
1707 spin_lock_irqsave(&ep->dev->lock, flags);
1708 /* make sure it's still queued on this endpoint */
1709 list_for_each_entry(req, &ep->queue, queue) {
1710 if (&req->req == usbreq) {
1711 pch_udc_ep_set_nak(ep);
1712 if (!list_empty(&req->queue))
1713 complete_req(ep, req, -ECONNRESET);
1714 ret = 0;
1715 break;
1716 }
1717 }
1718 spin_unlock_irqrestore(&ep->dev->lock, flags);
1719 return ret;
1720}
1721
1722/**
1723 * pch_udc_pcd_set_halt() - This function Sets or clear the endpoint halt
1724 * feature
1725 * @usbep: Reference to the USB endpoint structure
1726 * @halt: Specifies whether to set or clear the feature
1727 *
1728 * Return codes:
1729 * 0: Success
1730 * linux error number: Failure
1731 */
1732static int pch_udc_pcd_set_halt(struct usb_ep *usbep, int halt)
1733{
1734 struct pch_udc_ep *ep;
1735 struct pch_udc_dev *dev;
1736 unsigned long iflags;
1737 int ret;
1738
1739 if (!usbep)
1740 return -EINVAL;
1741 ep = container_of(usbep, struct pch_udc_ep, ep);
1742 dev = ep->dev;
1743 if (!ep->desc && !ep->num)
1744 return -EINVAL;
1745 if (!ep->dev->driver || (ep->dev->gadget.speed == USB_SPEED_UNKNOWN))
1746 return -ESHUTDOWN;
1747 spin_lock_irqsave(&udc_stall_spinlock, iflags);
1748 if (list_empty(&ep->queue)) {
1749 if (halt) {
1750 if (ep->num == PCH_UDC_EP0)
1751 ep->dev->stall = 1;
1752 pch_udc_ep_set_stall(ep);
1753 pch_udc_enable_ep_interrupts(ep->dev,
1754 PCH_UDC_EPINT(ep->in,
1755 ep->num));
1756 } else {
1757 pch_udc_ep_clear_stall(ep);
1758 }
1759 ret = 0;
1760 } else {
1761 ret = -EAGAIN;
1762 }
1763 spin_unlock_irqrestore(&udc_stall_spinlock, iflags);
1764 return ret;
1765}
1766
1767/**
1768 * pch_udc_pcd_set_wedge() - This function Sets or clear the endpoint
1769 * halt feature
1770 * @usbep: Reference to the USB endpoint structure
1771 * @halt: Specifies whether to set or clear the feature
1772 *
1773 * Return codes:
1774 * 0: Success
1775 * linux error number: Failure
1776 */
1777static int pch_udc_pcd_set_wedge(struct usb_ep *usbep)
1778{
1779 struct pch_udc_ep *ep;
1780 struct pch_udc_dev *dev;
1781 unsigned long iflags;
1782 int ret;
1783
1784 if (!usbep)
1785 return -EINVAL;
1786 ep = container_of(usbep, struct pch_udc_ep, ep);
1787 dev = ep->dev;
1788 if (!ep->desc && !ep->num)
1789 return -EINVAL;
1790 if (!ep->dev->driver || (ep->dev->gadget.speed == USB_SPEED_UNKNOWN))
1791 return -ESHUTDOWN;
1792 spin_lock_irqsave(&udc_stall_spinlock, iflags);
1793 if (!list_empty(&ep->queue)) {
1794 ret = -EAGAIN;
1795 } else {
1796 if (ep->num == PCH_UDC_EP0)
1797 ep->dev->stall = 1;
1798 pch_udc_ep_set_stall(ep);
1799 pch_udc_enable_ep_interrupts(ep->dev,
1800 PCH_UDC_EPINT(ep->in, ep->num));
1801 ep->dev->prot_stall = 1;
1802 ret = 0;
1803 }
1804 spin_unlock_irqrestore(&udc_stall_spinlock, iflags);
1805 return ret;
1806}
1807
1808/**
1809 * pch_udc_pcd_fifo_flush() - This function Flush the FIFO of specified endpoint
1810 * @usbep: Reference to the USB endpoint structure
1811 */
1812static void pch_udc_pcd_fifo_flush(struct usb_ep *usbep)
1813{
1814 struct pch_udc_ep *ep;
1815
1816 if (!usbep)
1817 return;
1818
1819 ep = container_of(usbep, struct pch_udc_ep, ep);
1820 if (ep->desc || !ep->num)
1821 pch_udc_ep_fifo_flush(ep, ep->in);
1822}
1823
1824static const struct usb_ep_ops pch_udc_ep_ops = {
1825 .enable = pch_udc_pcd_ep_enable,
1826 .disable = pch_udc_pcd_ep_disable,
1827 .alloc_request = pch_udc_alloc_request,
1828 .free_request = pch_udc_free_request,
1829 .queue = pch_udc_pcd_queue,
1830 .dequeue = pch_udc_pcd_dequeue,
1831 .set_halt = pch_udc_pcd_set_halt,
1832 .set_wedge = pch_udc_pcd_set_wedge,
1833 .fifo_status = NULL,
1834 .fifo_flush = pch_udc_pcd_fifo_flush,
1835};
1836
1837/**
1838 * pch_udc_init_setup_buff() - This function initializes the SETUP buffer
1839 * @td_stp: Reference to the SETP buffer structure
1840 */
1841static void pch_udc_init_setup_buff(struct pch_udc_stp_dma_desc *td_stp)
1842{
1843 static u32 pky_marker;
1844
1845 if (!td_stp)
1846 return;
1847 td_stp->reserved = ++pky_marker;
1848 memset(&td_stp->request, 0xFF, sizeof td_stp->request);
1849 td_stp->status = PCH_UDC_BS_HST_RDY;
1850}
1851
1852/**
1853 * pch_udc_start_next_txrequest() - This function starts
1854 * the next transmission requirement
1855 * @ep: Reference to the endpoint structure
1856 */
1857static void pch_udc_start_next_txrequest(struct pch_udc_ep *ep)
1858{
1859 struct pch_udc_request *req;
1860 struct pch_udc_data_dma_desc *td_data;
1861
1862 if (pch_udc_read_ep_control(ep) & UDC_EPCTL_P)
1863 return;
1864
1865 if (list_empty(&ep->queue))
1866 return;
1867
1868 /* next request */
1869 req = list_entry(ep->queue.next, struct pch_udc_request, queue);
1870 if (req->dma_going)
1871 return;
1872 if (!req->td_data)
1873 return;
1874 pch_udc_wait_ep_stall(ep);
1875 req->dma_going = 1;
1876 pch_udc_ep_set_ddptr(ep, 0);
1877 td_data = req->td_data;
1878 while (1) {
1879 td_data->status = (td_data->status & ~PCH_UDC_BUFF_STS) |
1880 PCH_UDC_BS_HST_RDY;
1881 if ((td_data->status & PCH_UDC_DMA_LAST) == PCH_UDC_DMA_LAST)
1882 break;
1883 td_data = phys_to_virt(td_data->next);
1884 }
1885 pch_udc_ep_set_ddptr(ep, req->td_data_phys);
1886 pch_udc_set_dma(ep->dev, DMA_DIR_TX);
1887 pch_udc_ep_set_pd(ep);
1888 pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num));
1889 pch_udc_ep_clear_nak(ep);
1890}
1891
1892/**
1893 * pch_udc_complete_transfer() - This function completes a transfer
1894 * @ep: Reference to the endpoint structure
1895 */
1896static void pch_udc_complete_transfer(struct pch_udc_ep *ep)
1897{
1898 struct pch_udc_request *req;
1899 struct pch_udc_dev *dev = ep->dev;
1900
1901 if (list_empty(&ep->queue))
1902 return;
1903 req = list_entry(ep->queue.next, struct pch_udc_request, queue);
1904 if ((req->td_data_last->status & PCH_UDC_BUFF_STS) !=
1905 PCH_UDC_BS_DMA_DONE)
1906 return;
1907 if ((req->td_data_last->status & PCH_UDC_RXTX_STS) !=
1908 PCH_UDC_RTS_SUCC) {
1909 dev_err(&dev->pdev->dev, "Invalid RXTX status (0x%08x) "
1910 "epstatus=0x%08x\n",
1911 (req->td_data_last->status & PCH_UDC_RXTX_STS),
1912 (int)(ep->epsts));
1913 return;
1914 }
1915
1916 req->req.actual = req->req.length;
1917 req->td_data_last->status = PCH_UDC_BS_HST_BSY | PCH_UDC_DMA_LAST;
1918 req->td_data->status = PCH_UDC_BS_HST_BSY | PCH_UDC_DMA_LAST;
1919 complete_req(ep, req, 0);
1920 req->dma_going = 0;
1921 if (!list_empty(&ep->queue)) {
1922 pch_udc_wait_ep_stall(ep);
1923 pch_udc_ep_clear_nak(ep);
1924 pch_udc_enable_ep_interrupts(ep->dev,
1925 PCH_UDC_EPINT(ep->in, ep->num));
1926 } else {
1927 pch_udc_disable_ep_interrupts(ep->dev,
1928 PCH_UDC_EPINT(ep->in, ep->num));
1929 }
1930}
1931
1932/**
1933 * pch_udc_complete_receiver() - This function completes a receiver
1934 * @ep: Reference to the endpoint structure
1935 */
1936static void pch_udc_complete_receiver(struct pch_udc_ep *ep)
1937{
1938 struct pch_udc_request *req;
1939 struct pch_udc_dev *dev = ep->dev;
1940 unsigned int count;
1941 struct pch_udc_data_dma_desc *td;
1942 dma_addr_t addr;
1943
1944 if (list_empty(&ep->queue))
1945 return;
1946 /* next request */
1947 req = list_entry(ep->queue.next, struct pch_udc_request, queue);
1948 pch_udc_clear_dma(ep->dev, DMA_DIR_RX);
1949 pch_udc_ep_set_ddptr(ep, 0);
1950 if ((req->td_data_last->status & PCH_UDC_BUFF_STS) ==
1951 PCH_UDC_BS_DMA_DONE)
1952 td = req->td_data_last;
1953 else
1954 td = req->td_data;
1955
1956 while (1) {
1957 if ((td->status & PCH_UDC_RXTX_STS) != PCH_UDC_RTS_SUCC) {
1958 dev_err(&dev->pdev->dev, "Invalid RXTX status=0x%08x "
1959 "epstatus=0x%08x\n",
1960 (req->td_data->status & PCH_UDC_RXTX_STS),
1961 (int)(ep->epsts));
1962 return;
1963 }
1964 if ((td->status & PCH_UDC_BUFF_STS) == PCH_UDC_BS_DMA_DONE)
1965 if (td->status | PCH_UDC_DMA_LAST) {
1966 count = td->status & PCH_UDC_RXTX_BYTES;
1967 break;
1968 }
1969 if (td == req->td_data_last) {
1970 dev_err(&dev->pdev->dev, "Not complete RX descriptor");
1971 return;
1972 }
1973 addr = (dma_addr_t)td->next;
1974 td = phys_to_virt(addr);
1975 }
1976 /* on 64k packets the RXBYTES field is zero */
1977 if (!count && (req->req.length == UDC_DMA_MAXPACKET))
1978 count = UDC_DMA_MAXPACKET;
1979 req->td_data->status |= PCH_UDC_DMA_LAST;
1980 td->status |= PCH_UDC_BS_HST_BSY;
1981
1982 req->dma_going = 0;
1983 req->req.actual = count;
1984 complete_req(ep, req, 0);
1985 /* If there is a new/failed requests try that now */
1986 if (!list_empty(&ep->queue)) {
1987 req = list_entry(ep->queue.next, struct pch_udc_request, queue);
1988 pch_udc_start_rxrequest(ep, req);
1989 }
1990}
1991
1992/**
1993 * pch_udc_svc_data_in() - This function process endpoint interrupts
1994 * for IN endpoints
1995 * @dev: Reference to the device structure
1996 * @ep_num: Endpoint that generated the interrupt
1997 */
1998static void pch_udc_svc_data_in(struct pch_udc_dev *dev, int ep_num)
1999{
2000 u32 epsts;
2001 struct pch_udc_ep *ep;
2002
2003 ep = &dev->ep[UDC_EPIN_IDX(ep_num)];
2004 epsts = ep->epsts;
2005 ep->epsts = 0;
2006
2007 if (!(epsts & (UDC_EPSTS_IN | UDC_EPSTS_BNA | UDC_EPSTS_HE |
2008 UDC_EPSTS_TDC | UDC_EPSTS_RCS | UDC_EPSTS_TXEMPTY |
2009 UDC_EPSTS_RSS | UDC_EPSTS_XFERDONE)))
2010 return;
2011 if ((epsts & UDC_EPSTS_BNA))
2012 return;
2013 if (epsts & UDC_EPSTS_HE)
2014 return;
2015 if (epsts & UDC_EPSTS_RSS) {
2016 pch_udc_ep_set_stall(ep);
2017 pch_udc_enable_ep_interrupts(ep->dev,
2018 PCH_UDC_EPINT(ep->in, ep->num));
2019 }
2020 if (epsts & UDC_EPSTS_RCS) {
2021 if (!dev->prot_stall) {
2022 pch_udc_ep_clear_stall(ep);
2023 } else {
2024 pch_udc_ep_set_stall(ep);
2025 pch_udc_enable_ep_interrupts(ep->dev,
2026 PCH_UDC_EPINT(ep->in, ep->num));
2027 }
2028 }
2029 if (epsts & UDC_EPSTS_TDC)
2030 pch_udc_complete_transfer(ep);
2031 /* On IN interrupt, provide data if we have any */
2032 if ((epsts & UDC_EPSTS_IN) && !(epsts & UDC_EPSTS_RSS) &&
2033 !(epsts & UDC_EPSTS_TDC) && !(epsts & UDC_EPSTS_TXEMPTY))
2034 pch_udc_start_next_txrequest(ep);
2035}
2036
2037/**
2038 * pch_udc_svc_data_out() - Handles interrupts from OUT endpoint
2039 * @dev: Reference to the device structure
2040 * @ep_num: Endpoint that generated the interrupt
2041 */
2042static void pch_udc_svc_data_out(struct pch_udc_dev *dev, int ep_num)
2043{
2044 u32 epsts;
2045 struct pch_udc_ep *ep;
2046 struct pch_udc_request *req = NULL;
2047
2048 ep = &dev->ep[UDC_EPOUT_IDX(ep_num)];
2049 epsts = ep->epsts;
2050 ep->epsts = 0;
2051
2052 if ((epsts & UDC_EPSTS_BNA) && (!list_empty(&ep->queue))) {
2053 /* next request */
2054 req = list_entry(ep->queue.next, struct pch_udc_request,
2055 queue);
2056 if ((req->td_data_last->status & PCH_UDC_BUFF_STS) !=
2057 PCH_UDC_BS_DMA_DONE) {
2058 if (!req->dma_going)
2059 pch_udc_start_rxrequest(ep, req);
2060 return;
2061 }
2062 }
2063 if (epsts & UDC_EPSTS_HE)
2064 return;
2065 if (epsts & UDC_EPSTS_RSS) {
2066 pch_udc_ep_set_stall(ep);
2067 pch_udc_enable_ep_interrupts(ep->dev,
2068 PCH_UDC_EPINT(ep->in, ep->num));
2069 }
2070 if (epsts & UDC_EPSTS_RCS) {
2071 if (!dev->prot_stall) {
2072 pch_udc_ep_clear_stall(ep);
2073 } else {
2074 pch_udc_ep_set_stall(ep);
2075 pch_udc_enable_ep_interrupts(ep->dev,
2076 PCH_UDC_EPINT(ep->in, ep->num));
2077 }
2078 }
2079 if (((epsts & UDC_EPSTS_OUT_MASK) >> UDC_EPSTS_OUT_SHIFT) ==
2080 UDC_EPSTS_OUT_DATA) {
2081 if (ep->dev->prot_stall == 1) {
2082 pch_udc_ep_set_stall(ep);
2083 pch_udc_enable_ep_interrupts(ep->dev,
2084 PCH_UDC_EPINT(ep->in, ep->num));
2085 } else {
2086 pch_udc_complete_receiver(ep);
2087 }
2088 }
2089 if (list_empty(&ep->queue))
2090 pch_udc_set_dma(dev, DMA_DIR_RX);
2091}
2092
2093/**
2094 * pch_udc_svc_control_in() - Handle Control IN endpoint interrupts
2095 * @dev: Reference to the device structure
2096 */
2097static void pch_udc_svc_control_in(struct pch_udc_dev *dev)
2098{
2099 u32 epsts;
2100 struct pch_udc_ep *ep;
2101 struct pch_udc_ep *ep_out;
2102
2103 ep = &dev->ep[UDC_EP0IN_IDX];
2104 ep_out = &dev->ep[UDC_EP0OUT_IDX];
2105 epsts = ep->epsts;
2106 ep->epsts = 0;
2107
2108 if (!(epsts & (UDC_EPSTS_IN | UDC_EPSTS_BNA | UDC_EPSTS_HE |
2109 UDC_EPSTS_TDC | UDC_EPSTS_RCS | UDC_EPSTS_TXEMPTY |
2110 UDC_EPSTS_XFERDONE)))
2111 return;
2112 if ((epsts & UDC_EPSTS_BNA))
2113 return;
2114 if (epsts & UDC_EPSTS_HE)
2115 return;
2116 if ((epsts & UDC_EPSTS_TDC) && (!dev->stall)) {
2117 pch_udc_complete_transfer(ep);
2118 pch_udc_clear_dma(dev, DMA_DIR_RX);
2119 ep_out->td_data->status = (ep_out->td_data->status &
2120 ~PCH_UDC_BUFF_STS) |
2121 PCH_UDC_BS_HST_RDY;
2122 pch_udc_ep_clear_nak(ep_out);
2123 pch_udc_set_dma(dev, DMA_DIR_RX);
2124 pch_udc_ep_set_rrdy(ep_out);
2125 }
2126 /* On IN interrupt, provide data if we have any */
2127 if ((epsts & UDC_EPSTS_IN) && !(epsts & UDC_EPSTS_TDC) &&
2128 !(epsts & UDC_EPSTS_TXEMPTY))
2129 pch_udc_start_next_txrequest(ep);
2130}
2131
2132/**
2133 * pch_udc_svc_control_out() - Routine that handle Control
2134 * OUT endpoint interrupts
2135 * @dev: Reference to the device structure
2136 */
2137static void pch_udc_svc_control_out(struct pch_udc_dev *dev)
2138{
2139 u32 stat;
2140 int setup_supported;
2141 struct pch_udc_ep *ep;
2142
2143 ep = &dev->ep[UDC_EP0OUT_IDX];
2144 stat = ep->epsts;
2145 ep->epsts = 0;
2146
2147 /* If setup data */
2148 if (((stat & UDC_EPSTS_OUT_MASK) >> UDC_EPSTS_OUT_SHIFT) ==
2149 UDC_EPSTS_OUT_SETUP) {
2150 dev->stall = 0;
2151 dev->ep[UDC_EP0IN_IDX].halted = 0;
2152 dev->ep[UDC_EP0OUT_IDX].halted = 0;
2153 dev->setup_data = ep->td_stp->request;
2154 pch_udc_init_setup_buff(ep->td_stp);
2155 pch_udc_clear_dma(dev, DMA_DIR_RX);
2156 pch_udc_ep_fifo_flush(&(dev->ep[UDC_EP0IN_IDX]),
2157 dev->ep[UDC_EP0IN_IDX].in);
2158 if ((dev->setup_data.bRequestType & USB_DIR_IN))
2159 dev->gadget.ep0 = &dev->ep[UDC_EP0IN_IDX].ep;
2160 else /* OUT */
2161 dev->gadget.ep0 = &ep->ep;
2162 spin_unlock(&dev->lock);
2163 /* If Mass storage Reset */
2164 if ((dev->setup_data.bRequestType == 0x21) &&
2165 (dev->setup_data.bRequest == 0xFF))
2166 dev->prot_stall = 0;
2167 /* call gadget with setup data received */
2168 setup_supported = dev->driver->setup(&dev->gadget,
2169 &dev->setup_data);
2170 spin_lock(&dev->lock);
2171
2172 if (dev->setup_data.bRequestType & USB_DIR_IN) {
2173 ep->td_data->status = (ep->td_data->status &
2174 ~PCH_UDC_BUFF_STS) |
2175 PCH_UDC_BS_HST_RDY;
2176 pch_udc_ep_set_ddptr(ep, ep->td_data_phys);
2177 }
2178 /* ep0 in returns data on IN phase */
2179 if (setup_supported >= 0 && setup_supported <
2180 UDC_EP0IN_MAX_PKT_SIZE) {
2181 pch_udc_ep_clear_nak(&(dev->ep[UDC_EP0IN_IDX]));
2182 /* Gadget would have queued a request when
2183 * we called the setup */
2184 if (!(dev->setup_data.bRequestType & USB_DIR_IN)) {
2185 pch_udc_set_dma(dev, DMA_DIR_RX);
2186 pch_udc_ep_clear_nak(ep);
2187 }
2188 } else if (setup_supported < 0) {
2189 /* if unsupported request, then stall */
2190 pch_udc_ep_set_stall(&(dev->ep[UDC_EP0IN_IDX]));
2191 pch_udc_enable_ep_interrupts(ep->dev,
2192 PCH_UDC_EPINT(ep->in, ep->num));
2193 dev->stall = 0;
2194 pch_udc_set_dma(dev, DMA_DIR_RX);
2195 } else {
2196 dev->waiting_zlp_ack = 1;
2197 }
2198 } else if ((((stat & UDC_EPSTS_OUT_MASK) >> UDC_EPSTS_OUT_SHIFT) ==
2199 UDC_EPSTS_OUT_DATA) && !dev->stall) {
2200 pch_udc_clear_dma(dev, DMA_DIR_RX);
2201 pch_udc_ep_set_ddptr(ep, 0);
2202 if (!list_empty(&ep->queue)) {
2203 ep->epsts = stat;
2204 pch_udc_svc_data_out(dev, PCH_UDC_EP0);
2205 }
2206 pch_udc_set_dma(dev, DMA_DIR_RX);
2207 }
2208 pch_udc_ep_set_rrdy(ep);
2209}
2210
2211
2212/**
2213 * pch_udc_postsvc_epinters() - This function enables end point interrupts
2214 * and clears NAK status
2215 * @dev: Reference to the device structure
2216 * @ep_num: End point number
2217 */
2218static void pch_udc_postsvc_epinters(struct pch_udc_dev *dev, int ep_num)
2219{
2220 struct pch_udc_ep *ep;
2221 struct pch_udc_request *req;
2222
2223 ep = &dev->ep[UDC_EPIN_IDX(ep_num)];
2224 if (!list_empty(&ep->queue)) {
2225 req = list_entry(ep->queue.next, struct pch_udc_request, queue);
2226 pch_udc_enable_ep_interrupts(ep->dev,
2227 PCH_UDC_EPINT(ep->in, ep->num));
2228 pch_udc_ep_clear_nak(ep);
2229 }
2230}
2231
2232/**
2233 * pch_udc_read_all_epstatus() - This function read all endpoint status
2234 * @dev: Reference to the device structure
2235 * @ep_intr: Status of endpoint interrupt
2236 */
2237static void pch_udc_read_all_epstatus(struct pch_udc_dev *dev, u32 ep_intr)
2238{
2239 int i;
2240 struct pch_udc_ep *ep;
2241
2242 for (i = 0; i < PCH_UDC_USED_EP_NUM; i++) {
2243 /* IN */
2244 if (ep_intr & (0x1 << i)) {
2245 ep = &dev->ep[UDC_EPIN_IDX(i)];
2246 ep->epsts = pch_udc_read_ep_status(ep);
2247 pch_udc_clear_ep_status(ep, ep->epsts);
2248 }
2249 /* OUT */
2250 if (ep_intr & (0x10000 << i)) {
2251 ep = &dev->ep[UDC_EPOUT_IDX(i)];
2252 ep->epsts = pch_udc_read_ep_status(ep);
2253 pch_udc_clear_ep_status(ep, ep->epsts);
2254 }
2255 }
2256}
2257
2258/**
2259 * pch_udc_activate_control_ep() - This function enables the control endpoints
2260 * for traffic after a reset
2261 * @dev: Reference to the device structure
2262 */
2263static void pch_udc_activate_control_ep(struct pch_udc_dev *dev)
2264{
2265 struct pch_udc_ep *ep;
2266 u32 val;
2267
2268 /* Setup the IN endpoint */
2269 ep = &dev->ep[UDC_EP0IN_IDX];
2270 pch_udc_clear_ep_control(ep);
2271 pch_udc_ep_fifo_flush(ep, ep->in);
2272 pch_udc_ep_set_bufsz(ep, UDC_EP0IN_BUFF_SIZE, ep->in);
2273 pch_udc_ep_set_maxpkt(ep, UDC_EP0IN_MAX_PKT_SIZE);
2274 /* Initialize the IN EP Descriptor */
2275 ep->td_data = NULL;
2276 ep->td_stp = NULL;
2277 ep->td_data_phys = 0;
2278 ep->td_stp_phys = 0;
2279
2280 /* Setup the OUT endpoint */
2281 ep = &dev->ep[UDC_EP0OUT_IDX];
2282 pch_udc_clear_ep_control(ep);
2283 pch_udc_ep_fifo_flush(ep, ep->in);
2284 pch_udc_ep_set_bufsz(ep, UDC_EP0OUT_BUFF_SIZE, ep->in);
2285 pch_udc_ep_set_maxpkt(ep, UDC_EP0OUT_MAX_PKT_SIZE);
2286 val = UDC_EP0OUT_MAX_PKT_SIZE << UDC_CSR_NE_MAX_PKT_SHIFT;
2287 pch_udc_write_csr(ep->dev, val, UDC_EP0OUT_IDX);
2288
2289 /* Initialize the SETUP buffer */
2290 pch_udc_init_setup_buff(ep->td_stp);
2291 /* Write the pointer address of dma descriptor */
2292 pch_udc_ep_set_subptr(ep, ep->td_stp_phys);
2293 /* Write the pointer address of Setup descriptor */
2294 pch_udc_ep_set_ddptr(ep, ep->td_data_phys);
2295
2296 /* Initialize the dma descriptor */
2297 ep->td_data->status = PCH_UDC_DMA_LAST;
2298 ep->td_data->dataptr = dev->dma_addr;
2299 ep->td_data->next = ep->td_data_phys;
2300
2301 pch_udc_ep_clear_nak(ep);
2302}
2303
2304
2305/**
2306 * pch_udc_svc_ur_interrupt() - This function handles a USB reset interrupt
2307 * @dev: Reference to driver structure
2308 */
2309static void pch_udc_svc_ur_interrupt(struct pch_udc_dev *dev)
2310{
2311 struct pch_udc_ep *ep;
2312 int i;
2313
2314 pch_udc_clear_dma(dev, DMA_DIR_TX);
2315 pch_udc_clear_dma(dev, DMA_DIR_RX);
2316 /* Mask all endpoint interrupts */
2317 pch_udc_disable_ep_interrupts(dev, UDC_EPINT_MSK_DISABLE_ALL);
2318 /* clear all endpoint interrupts */
2319 pch_udc_write_ep_interrupts(dev, UDC_EPINT_MSK_DISABLE_ALL);
2320
2321 for (i = 0; i < PCH_UDC_EP_NUM; i++) {
2322 ep = &dev->ep[i];
2323 pch_udc_clear_ep_status(ep, UDC_EPSTS_ALL_CLR_MASK);
2324 pch_udc_clear_ep_control(ep);
2325 pch_udc_ep_set_ddptr(ep, 0);
2326 pch_udc_write_csr(ep->dev, 0x00, i);
2327 }
2328 dev->stall = 0;
2329 dev->prot_stall = 0;
2330 dev->waiting_zlp_ack = 0;
2331 dev->set_cfg_not_acked = 0;
2332
2333 /* disable ep to empty req queue. Skip the control EP's */
2334 for (i = 0; i < (PCH_UDC_USED_EP_NUM*2); i++) {
2335 ep = &dev->ep[i];
2336 pch_udc_ep_set_nak(ep);
2337 pch_udc_ep_fifo_flush(ep, ep->in);
2338 /* Complete request queue */
2339 empty_req_queue(ep);
2340 }
2341 if (dev->driver && dev->driver->disconnect)
2342 dev->driver->disconnect(&dev->gadget);
2343}
2344
2345/**
2346 * pch_udc_svc_enum_interrupt() - This function handles a USB speed enumeration
2347 * done interrupt
2348 * @dev: Reference to driver structure
2349 */
2350static void pch_udc_svc_enum_interrupt(struct pch_udc_dev *dev)
2351{
2352 u32 dev_stat, dev_speed;
2353 u32 speed = USB_SPEED_FULL;
2354
2355 dev_stat = pch_udc_read_device_status(dev);
2356 dev_speed = (dev_stat & UDC_DEVSTS_ENUM_SPEED_MASK) >>
2357 UDC_DEVSTS_ENUM_SPEED_SHIFT;
2358 switch (dev_speed) {
2359 case UDC_DEVSTS_ENUM_SPEED_HIGH:
2360 speed = USB_SPEED_HIGH;
2361 break;
2362 case UDC_DEVSTS_ENUM_SPEED_FULL:
2363 speed = USB_SPEED_FULL;
2364 break;
2365 case UDC_DEVSTS_ENUM_SPEED_LOW:
2366 speed = USB_SPEED_LOW;
2367 break;
2368 default:
2369 BUG();
2370 }
2371 dev->gadget.speed = speed;
2372 pch_udc_activate_control_ep(dev);
2373 pch_udc_enable_ep_interrupts(dev, UDC_EPINT_IN_EP0 | UDC_EPINT_OUT_EP0);
2374 pch_udc_set_dma(dev, DMA_DIR_TX);
2375 pch_udc_set_dma(dev, DMA_DIR_RX);
2376 pch_udc_ep_set_rrdy(&(dev->ep[UDC_EP0OUT_IDX]));
2377}
2378
2379/**
2380 * pch_udc_svc_intf_interrupt() - This function handles a set interface
2381 * interrupt
2382 * @dev: Reference to driver structure
2383 */
2384static void pch_udc_svc_intf_interrupt(struct pch_udc_dev *dev)
2385{
2386 u32 reg, dev_stat = 0;
2387 int i, ret;
2388
2389 dev_stat = pch_udc_read_device_status(dev);
2390 dev->cfg_data.cur_intf = (dev_stat & UDC_DEVSTS_INTF_MASK) >>
2391 UDC_DEVSTS_INTF_SHIFT;
2392 dev->cfg_data.cur_alt = (dev_stat & UDC_DEVSTS_ALT_MASK) >>
2393 UDC_DEVSTS_ALT_SHIFT;
2394 dev->set_cfg_not_acked = 1;
2395 /* Construct the usb request for gadget driver and inform it */
2396 memset(&dev->setup_data, 0 , sizeof dev->setup_data);
2397 dev->setup_data.bRequest = USB_REQ_SET_INTERFACE;
2398 dev->setup_data.bRequestType = USB_RECIP_INTERFACE;
2399 dev->setup_data.wValue = cpu_to_le16(dev->cfg_data.cur_alt);
2400 dev->setup_data.wIndex = cpu_to_le16(dev->cfg_data.cur_intf);
2401 /* programm the Endpoint Cfg registers */
2402 /* Only one end point cfg register */
2403 reg = pch_udc_read_csr(dev, UDC_EP0OUT_IDX);
2404 reg = (reg & ~UDC_CSR_NE_INTF_MASK) |
2405 (dev->cfg_data.cur_intf << UDC_CSR_NE_INTF_SHIFT);
2406 reg = (reg & ~UDC_CSR_NE_ALT_MASK) |
2407 (dev->cfg_data.cur_alt << UDC_CSR_NE_ALT_SHIFT);
2408 pch_udc_write_csr(dev, reg, UDC_EP0OUT_IDX);
2409 for (i = 0; i < PCH_UDC_USED_EP_NUM * 2; i++) {
2410 /* clear stall bits */
2411 pch_udc_ep_clear_stall(&(dev->ep[i]));
2412 dev->ep[i].halted = 0;
2413 }
2414 dev->stall = 0;
2415 spin_unlock(&dev->lock);
2416 ret = dev->driver->setup(&dev->gadget, &dev->setup_data);
2417 spin_lock(&dev->lock);
2418}
2419
2420/**
2421 * pch_udc_svc_cfg_interrupt() - This function handles a set configuration
2422 * interrupt
2423 * @dev: Reference to driver structure
2424 */
2425static void pch_udc_svc_cfg_interrupt(struct pch_udc_dev *dev)
2426{
2427 int i, ret;
2428 u32 reg, dev_stat = 0;
2429
2430 dev_stat = pch_udc_read_device_status(dev);
2431 dev->set_cfg_not_acked = 1;
2432 dev->cfg_data.cur_cfg = (dev_stat & UDC_DEVSTS_CFG_MASK) >>
2433 UDC_DEVSTS_CFG_SHIFT;
2434 /* make usb request for gadget driver */
2435 memset(&dev->setup_data, 0 , sizeof dev->setup_data);
2436 dev->setup_data.bRequest = USB_REQ_SET_CONFIGURATION;
2437 dev->setup_data.wValue = cpu_to_le16(dev->cfg_data.cur_cfg);
2438 /* program the NE registers */
2439 /* Only one end point cfg register */
2440 reg = pch_udc_read_csr(dev, UDC_EP0OUT_IDX);
2441 reg = (reg & ~UDC_CSR_NE_CFG_MASK) |
2442 (dev->cfg_data.cur_cfg << UDC_CSR_NE_CFG_SHIFT);
2443 pch_udc_write_csr(dev, reg, UDC_EP0OUT_IDX);
2444 for (i = 0; i < PCH_UDC_USED_EP_NUM * 2; i++) {
2445 /* clear stall bits */
2446 pch_udc_ep_clear_stall(&(dev->ep[i]));
2447 dev->ep[i].halted = 0;
2448 }
2449 dev->stall = 0;
2450
2451 /* call gadget zero with setup data received */
2452 spin_unlock(&dev->lock);
2453 ret = dev->driver->setup(&dev->gadget, &dev->setup_data);
2454 spin_lock(&dev->lock);
2455}
2456
2457/**
2458 * pch_udc_dev_isr() - This function services device interrupts
2459 * by invoking appropriate routines.
2460 * @dev: Reference to the device structure
2461 * @dev_intr: The Device interrupt status.
2462 */
2463static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr)
2464{
2465 /* USB Reset Interrupt */
2466 if (dev_intr & UDC_DEVINT_UR)
2467 pch_udc_svc_ur_interrupt(dev);
2468 /* Enumeration Done Interrupt */
2469 if (dev_intr & UDC_DEVINT_ENUM)
2470 pch_udc_svc_enum_interrupt(dev);
2471 /* Set Interface Interrupt */
2472 if (dev_intr & UDC_DEVINT_SI)
2473 pch_udc_svc_intf_interrupt(dev);
2474 /* Set Config Interrupt */
2475 if (dev_intr & UDC_DEVINT_SC)
2476 pch_udc_svc_cfg_interrupt(dev);
2477 /* USB Suspend interrupt */
2478 if (dev_intr & UDC_DEVINT_US)
2479 dev_dbg(&dev->pdev->dev, "USB_SUSPEND\n");
2480 /* Clear the SOF interrupt, if enabled */
2481 if (dev_intr & UDC_DEVINT_SOF)
2482 dev_dbg(&dev->pdev->dev, "SOF\n");
2483 /* ES interrupt, IDLE > 3ms on the USB */
2484 if (dev_intr & UDC_DEVINT_ES)
2485 dev_dbg(&dev->pdev->dev, "ES\n");
2486 /* RWKP interrupt */
2487 if (dev_intr & UDC_DEVINT_RWKP)
2488 dev_dbg(&dev->pdev->dev, "RWKP\n");
2489}
2490
2491/**
2492 * pch_udc_isr() - This function handles interrupts from the PCH USB Device
2493 * @irq: Interrupt request number
2494 * @dev: Reference to the device structure
2495 */
2496static irqreturn_t pch_udc_isr(int irq, void *pdev)
2497{
2498 struct pch_udc_dev *dev = (struct pch_udc_dev *) pdev;
2499 u32 dev_intr, ep_intr;
2500 int i;
2501
2502 dev_intr = pch_udc_read_device_interrupts(dev);
2503 ep_intr = pch_udc_read_ep_interrupts(dev);
2504
2505 if (dev_intr)
2506 /* Clear device interrupts */
2507 pch_udc_write_device_interrupts(dev, dev_intr);
2508 if (ep_intr)
2509 /* Clear ep interrupts */
2510 pch_udc_write_ep_interrupts(dev, ep_intr);
2511 if (!dev_intr && !ep_intr)
2512 return IRQ_NONE;
2513 spin_lock(&dev->lock);
2514 if (dev_intr)
2515 pch_udc_dev_isr(dev, dev_intr);
2516 if (ep_intr) {
2517 pch_udc_read_all_epstatus(dev, ep_intr);
2518 /* Process Control In interrupts, if present */
2519 if (ep_intr & UDC_EPINT_IN_EP0) {
2520 pch_udc_svc_control_in(dev);
2521 pch_udc_postsvc_epinters(dev, 0);
2522 }
2523 /* Process Control Out interrupts, if present */
2524 if (ep_intr & UDC_EPINT_OUT_EP0)
2525 pch_udc_svc_control_out(dev);
2526 /* Process data in end point interrupts */
2527 for (i = 1; i < PCH_UDC_USED_EP_NUM; i++) {
2528 if (ep_intr & (1 << i)) {
2529 pch_udc_svc_data_in(dev, i);
2530 pch_udc_postsvc_epinters(dev, i);
2531 }
2532 }
2533 /* Process data out end point interrupts */
2534 for (i = UDC_EPINT_OUT_SHIFT + 1; i < (UDC_EPINT_OUT_SHIFT +
2535 PCH_UDC_USED_EP_NUM); i++)
2536 if (ep_intr & (1 << i))
2537 pch_udc_svc_data_out(dev, i -
2538 UDC_EPINT_OUT_SHIFT);
2539 }
2540 spin_unlock(&dev->lock);
2541 return IRQ_HANDLED;
2542}
2543
2544/**
2545 * pch_udc_setup_ep0() - This function enables control endpoint for traffic
2546 * @dev: Reference to the device structure
2547 */
2548static void pch_udc_setup_ep0(struct pch_udc_dev *dev)
2549{
2550 /* enable ep0 interrupts */
2551 pch_udc_enable_ep_interrupts(dev, UDC_EPINT_IN_EP0 |
2552 UDC_EPINT_OUT_EP0);
2553 /* enable device interrupts */
2554 pch_udc_enable_interrupts(dev, UDC_DEVINT_UR | UDC_DEVINT_US |
2555 UDC_DEVINT_ES | UDC_DEVINT_ENUM |
2556 UDC_DEVINT_SI | UDC_DEVINT_SC);
2557}
2558
2559/**
2560 * gadget_release() - Free the gadget driver private data
2561 * @pdev reference to struct pci_dev
2562 */
2563static void gadget_release(struct device *pdev)
2564{
2565 struct pch_udc_dev *dev = dev_get_drvdata(pdev);
2566
2567 kfree(dev);
2568}
2569
2570/**
2571 * pch_udc_pcd_reinit() - This API initializes the endpoint structures
2572 * @dev: Reference to the driver structure
2573 */
2574static void pch_udc_pcd_reinit(struct pch_udc_dev *dev)
2575{
2576 const char *const ep_string[] = {
2577 ep0_string, "ep0out", "ep1in", "ep1out", "ep2in", "ep2out",
2578 "ep3in", "ep3out", "ep4in", "ep4out", "ep5in", "ep5out",
2579 "ep6in", "ep6out", "ep7in", "ep7out", "ep8in", "ep8out",
2580 "ep9in", "ep9out", "ep10in", "ep10out", "ep11in", "ep11out",
2581 "ep12in", "ep12out", "ep13in", "ep13out", "ep14in", "ep14out",
2582 "ep15in", "ep15out",
2583 };
2584 int i;
2585
2586 dev->gadget.speed = USB_SPEED_UNKNOWN;
2587 INIT_LIST_HEAD(&dev->gadget.ep_list);
2588
2589 /* Initialize the endpoints structures */
2590 memset(dev->ep, 0, sizeof dev->ep);
2591 for (i = 0; i < PCH_UDC_EP_NUM; i++) {
2592 struct pch_udc_ep *ep = &dev->ep[i];
2593 ep->dev = dev;
2594 ep->halted = 1;
2595 ep->num = i / 2;
2596 ep->in = ~i & 1;
2597 ep->ep.name = ep_string[i];
2598 ep->ep.ops = &pch_udc_ep_ops;
2599 if (ep->in)
2600 ep->offset_addr = ep->num * UDC_EP_REG_SHIFT;
2601 else
2602 ep->offset_addr = (UDC_EPINT_OUT_SHIFT + ep->num) *
2603 UDC_EP_REG_SHIFT;
2604 /* need to set ep->ep.maxpacket and set Default Configuration?*/
2605 ep->ep.maxpacket = UDC_BULK_MAX_PKT_SIZE;
2606 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
2607 INIT_LIST_HEAD(&ep->queue);
2608 }
2609 dev->ep[UDC_EP0IN_IDX].ep.maxpacket = UDC_EP0IN_MAX_PKT_SIZE;
2610 dev->ep[UDC_EP0OUT_IDX].ep.maxpacket = UDC_EP0OUT_MAX_PKT_SIZE;
2611
2612 /* remove ep0 in and out from the list. They have own pointer */
2613 list_del_init(&dev->ep[UDC_EP0IN_IDX].ep.ep_list);
2614 list_del_init(&dev->ep[UDC_EP0OUT_IDX].ep.ep_list);
2615
2616 dev->gadget.ep0 = &dev->ep[UDC_EP0IN_IDX].ep;
2617 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
2618}
2619
2620/**
2621 * pch_udc_pcd_init() - This API initializes the driver structure
2622 * @dev: Reference to the driver structure
2623 *
2624 * Return codes:
2625 * 0: Success
2626 */
2627static int pch_udc_pcd_init(struct pch_udc_dev *dev)
2628{
2629 pch_udc_init(dev);
2630 pch_udc_pcd_reinit(dev);
2631 return 0;
2632}
2633
2634/**
2635 * init_dma_pools() - create dma pools during initialization
2636 * @pdev: reference to struct pci_dev
2637 */
2638static int init_dma_pools(struct pch_udc_dev *dev)
2639{
2640 struct pch_udc_stp_dma_desc *td_stp;
2641 struct pch_udc_data_dma_desc *td_data;
2642
2643 /* DMA setup */
2644 dev->data_requests = pci_pool_create("data_requests", dev->pdev,
2645 sizeof(struct pch_udc_data_dma_desc), 0, 0);
2646 if (!dev->data_requests) {
2647 dev_err(&dev->pdev->dev, "%s: can't get request data pool\n",
2648 __func__);
2649 return -ENOMEM;
2650 }
2651
2652 /* dma desc for setup data */
2653 dev->stp_requests = pci_pool_create("setup requests", dev->pdev,
2654 sizeof(struct pch_udc_stp_dma_desc), 0, 0);
2655 if (!dev->stp_requests) {
2656 dev_err(&dev->pdev->dev, "%s: can't get setup request pool\n",
2657 __func__);
2658 return -ENOMEM;
2659 }
2660 /* setup */
2661 td_stp = pci_pool_alloc(dev->stp_requests, GFP_KERNEL,
2662 &dev->ep[UDC_EP0OUT_IDX].td_stp_phys);
2663 if (!td_stp) {
2664 dev_err(&dev->pdev->dev,
2665 "%s: can't allocate setup dma descriptor\n", __func__);
2666 return -ENOMEM;
2667 }
2668 dev->ep[UDC_EP0OUT_IDX].td_stp = td_stp;
2669
2670 /* data: 0 packets !? */
2671 td_data = pci_pool_alloc(dev->data_requests, GFP_KERNEL,
2672 &dev->ep[UDC_EP0OUT_IDX].td_data_phys);
2673 if (!td_data) {
2674 dev_err(&dev->pdev->dev,
2675 "%s: can't allocate data dma descriptor\n", __func__);
2676 return -ENOMEM;
2677 }
2678 dev->ep[UDC_EP0OUT_IDX].td_data = td_data;
2679 dev->ep[UDC_EP0IN_IDX].td_stp = NULL;
2680 dev->ep[UDC_EP0IN_IDX].td_stp_phys = 0;
2681 dev->ep[UDC_EP0IN_IDX].td_data = NULL;
2682 dev->ep[UDC_EP0IN_IDX].td_data_phys = 0;
2683
2684 dev->ep0out_buf = kzalloc(UDC_EP0OUT_BUFF_SIZE * 4, GFP_KERNEL);
2685 if (!dev->ep0out_buf)
2686 return -ENOMEM;
2687 dev->dma_addr = dma_map_single(&dev->pdev->dev, dev->ep0out_buf,
2688 UDC_EP0OUT_BUFF_SIZE * 4,
2689 DMA_FROM_DEVICE);
2690 return 0;
2691}
2692
2693int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2694 int (*bind)(struct usb_gadget *))
2695{
2696 struct pch_udc_dev *dev = pch_udc;
2697 int retval;
2698
2699 if (!driver || (driver->speed == USB_SPEED_UNKNOWN) || !bind ||
2700 !driver->setup || !driver->unbind || !driver->disconnect) {
2701 dev_err(&dev->pdev->dev,
2702 "%s: invalid driver parameter\n", __func__);
2703 return -EINVAL;
2704 }
2705
2706 if (!dev)
2707 return -ENODEV;
2708
2709 if (dev->driver) {
2710 dev_err(&dev->pdev->dev, "%s: already bound\n", __func__);
2711 return -EBUSY;
2712 }
2713 driver->driver.bus = NULL;
2714 dev->driver = driver;
2715 dev->gadget.dev.driver = &driver->driver;
2716
2717 /* Invoke the bind routine of the gadget driver */
2718 retval = bind(&dev->gadget);
2719
2720 if (retval) {
2721 dev_err(&dev->pdev->dev, "%s: binding to %s returning %d\n",
2722 __func__, driver->driver.name, retval);
2723 dev->driver = NULL;
2724 dev->gadget.dev.driver = NULL;
2725 return retval;
2726 }
2727 /* get ready for ep0 traffic */
2728 pch_udc_setup_ep0(dev);
2729
2730 /* clear SD */
2731 pch_udc_clear_disconnect(dev);
2732
2733 dev->connected = 1;
2734 return 0;
2735}
2736EXPORT_SYMBOL(usb_gadget_probe_driver);
2737
2738int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2739{
2740 struct pch_udc_dev *dev = pch_udc;
2741
2742 if (!dev)
2743 return -ENODEV;
2744
2745 if (!driver || (driver != dev->driver)) {
2746 dev_err(&dev->pdev->dev,
2747 "%s: invalid driver parameter\n", __func__);
2748 return -EINVAL;
2749 }
2750
2751 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK);
2752
2753 /* Assures that there are no pending requests with this driver */
2754 driver->disconnect(&dev->gadget);
2755 driver->unbind(&dev->gadget);
2756 dev->gadget.dev.driver = NULL;
2757 dev->driver = NULL;
2758 dev->connected = 0;
2759
2760 /* set SD */
2761 pch_udc_set_disconnect(dev);
2762 return 0;
2763}
2764EXPORT_SYMBOL(usb_gadget_unregister_driver);
2765
2766static void pch_udc_shutdown(struct pci_dev *pdev)
2767{
2768 struct pch_udc_dev *dev = pci_get_drvdata(pdev);
2769
2770 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK);
2771 pch_udc_disable_ep_interrupts(dev, UDC_EPINT_MSK_DISABLE_ALL);
2772
2773 /* disable the pullup so the host will think we're gone */
2774 pch_udc_set_disconnect(dev);
2775}
2776
2777static void pch_udc_remove(struct pci_dev *pdev)
2778{
2779 struct pch_udc_dev *dev = pci_get_drvdata(pdev);
2780
2781 /* gadget driver must not be registered */
2782 if (dev->driver)
2783 dev_err(&pdev->dev,
2784 "%s: gadget driver still bound!!!\n", __func__);
2785 /* dma pool cleanup */
2786 if (dev->data_requests)
2787 pci_pool_destroy(dev->data_requests);
2788
2789 if (dev->stp_requests) {
2790 /* cleanup DMA desc's for ep0in */
2791 if (dev->ep[UDC_EP0OUT_IDX].td_stp) {
2792 pci_pool_free(dev->stp_requests,
2793 dev->ep[UDC_EP0OUT_IDX].td_stp,
2794 dev->ep[UDC_EP0OUT_IDX].td_stp_phys);
2795 }
2796 if (dev->ep[UDC_EP0OUT_IDX].td_data) {
2797 pci_pool_free(dev->stp_requests,
2798 dev->ep[UDC_EP0OUT_IDX].td_data,
2799 dev->ep[UDC_EP0OUT_IDX].td_data_phys);
2800 }
2801 pci_pool_destroy(dev->stp_requests);
2802 }
2803
2804 if (dev->dma_addr)
2805 dma_unmap_single(&dev->pdev->dev, dev->dma_addr,
2806 UDC_EP0OUT_BUFF_SIZE * 4, DMA_FROM_DEVICE);
2807 kfree(dev->ep0out_buf);
2808
2809 pch_udc_exit(dev);
2810
2811 if (dev->irq_registered)
2812 free_irq(pdev->irq, dev);
2813 if (dev->base_addr)
2814 iounmap(dev->base_addr);
2815 if (dev->mem_region)
2816 release_mem_region(dev->phys_addr,
2817 pci_resource_len(pdev, PCH_UDC_PCI_BAR));
2818 if (dev->active)
2819 pci_disable_device(pdev);
2820 if (dev->registered)
2821 device_unregister(&dev->gadget.dev);
2822 kfree(dev);
2823 pci_set_drvdata(pdev, NULL);
2824}
2825
2826#ifdef CONFIG_PM
2827static int pch_udc_suspend(struct pci_dev *pdev, pm_message_t state)
2828{
2829 struct pch_udc_dev *dev = pci_get_drvdata(pdev);
2830
2831 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK);
2832 pch_udc_disable_ep_interrupts(dev, UDC_EPINT_MSK_DISABLE_ALL);
2833
2834 pci_disable_device(pdev);
2835 pci_enable_wake(pdev, PCI_D3hot, 0);
2836
2837 if (pci_save_state(pdev)) {
2838 dev_err(&pdev->dev,
2839 "%s: could not save PCI config state\n", __func__);
2840 return -ENOMEM;
2841 }
2842 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2843 return 0;
2844}
2845
2846static int pch_udc_resume(struct pci_dev *pdev)
2847{
2848 int ret;
2849
2850 pci_set_power_state(pdev, PCI_D0);
2851 pci_restore_state(pdev);
2852 ret = pci_enable_device(pdev);
2853 if (ret) {
2854 dev_err(&pdev->dev, "%s: pci_enable_device failed\n", __func__);
2855 return ret;
2856 }
2857 pci_enable_wake(pdev, PCI_D3hot, 0);
2858 return 0;
2859}
2860#else
2861#define pch_udc_suspend NULL
2862#define pch_udc_resume NULL
2863#endif /* CONFIG_PM */
2864
2865static int pch_udc_probe(struct pci_dev *pdev,
2866 const struct pci_device_id *id)
2867{
2868 unsigned long resource;
2869 unsigned long len;
2870 int retval;
2871 struct pch_udc_dev *dev;
2872
2873 /* one udc only */
2874 if (pch_udc) {
2875 pr_err("%s: already probed\n", __func__);
2876 return -EBUSY;
2877 }
2878 /* init */
2879 dev = kzalloc(sizeof *dev, GFP_KERNEL);
2880 if (!dev) {
2881 pr_err("%s: no memory for device structure\n", __func__);
2882 return -ENOMEM;
2883 }
2884 /* pci setup */
2885 if (pci_enable_device(pdev) < 0) {
2886 kfree(dev);
2887 pr_err("%s: pci_enable_device failed\n", __func__);
2888 return -ENODEV;
2889 }
2890 dev->active = 1;
2891 pci_set_drvdata(pdev, dev);
2892
2893 /* PCI resource allocation */
2894 resource = pci_resource_start(pdev, 1);
2895 len = pci_resource_len(pdev, 1);
2896
2897 if (!request_mem_region(resource, len, KBUILD_MODNAME)) {
2898 dev_err(&pdev->dev, "%s: pci device used already\n", __func__);
2899 retval = -EBUSY;
2900 goto finished;
2901 }
2902 dev->phys_addr = resource;
2903 dev->mem_region = 1;
2904
2905 dev->base_addr = ioremap_nocache(resource, len);
2906 if (!dev->base_addr) {
2907 pr_err("%s: device memory cannot be mapped\n", __func__);
2908 retval = -ENOMEM;
2909 goto finished;
2910 }
2911 if (!pdev->irq) {
2912 dev_err(&pdev->dev, "%s: irq not set\n", __func__);
2913 retval = -ENODEV;
2914 goto finished;
2915 }
2916 pch_udc = dev;
2917 /* initialize the hardware */
2918 if (pch_udc_pcd_init(dev))
2919 goto finished;
2920 if (request_irq(pdev->irq, pch_udc_isr, IRQF_SHARED, KBUILD_MODNAME,
2921 dev)) {
2922 dev_err(&pdev->dev, "%s: request_irq(%d) fail\n", __func__,
2923 pdev->irq);
2924 retval = -ENODEV;
2925 goto finished;
2926 }
2927 dev->irq = pdev->irq;
2928 dev->irq_registered = 1;
2929
2930 pci_set_master(pdev);
2931 pci_try_set_mwi(pdev);
2932
2933 /* device struct setup */
2934 spin_lock_init(&dev->lock);
2935 dev->pdev = pdev;
2936 dev->gadget.ops = &pch_udc_ops;
2937
2938 retval = init_dma_pools(dev);
2939 if (retval)
2940 goto finished;
2941
2942 dev_set_name(&dev->gadget.dev, "gadget");
2943 dev->gadget.dev.parent = &pdev->dev;
2944 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
2945 dev->gadget.dev.release = gadget_release;
2946 dev->gadget.name = KBUILD_MODNAME;
2947 dev->gadget.is_dualspeed = 1;
2948
2949 retval = device_register(&dev->gadget.dev);
2950 if (retval)
2951 goto finished;
2952 dev->registered = 1;
2953
2954 /* Put the device in disconnected state till a driver is bound */
2955 pch_udc_set_disconnect(dev);
2956 return 0;
2957
2958finished:
2959 pch_udc_remove(pdev);
2960 return retval;
2961}
2962
2963static DEFINE_PCI_DEVICE_TABLE(pch_udc_pcidev_id) = {
2964 {
2965 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EG20T_UDC),
2966 .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe,
2967 .class_mask = 0xffffffff,
2968 },
2969 {
2970 PCI_DEVICE(PCI_VENDOR_ID_ROHM, PCI_DEVICE_ID_ML7213_IOH_UDC),
2971 .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe,
2972 .class_mask = 0xffffffff,
2973 },
2974 { 0 },
2975};
2976
2977MODULE_DEVICE_TABLE(pci, pch_udc_pcidev_id);
2978
2979
2980static struct pci_driver pch_udc_driver = {
2981 .name = KBUILD_MODNAME,
2982 .id_table = pch_udc_pcidev_id,
2983 .probe = pch_udc_probe,
2984 .remove = pch_udc_remove,
2985 .suspend = pch_udc_suspend,
2986 .resume = pch_udc_resume,
2987 .shutdown = pch_udc_shutdown,
2988};
2989
2990static int __init pch_udc_pci_init(void)
2991{
2992 return pci_register_driver(&pch_udc_driver);
2993}
2994module_init(pch_udc_pci_init);
2995
2996static void __exit pch_udc_pci_exit(void)
2997{
2998 pci_unregister_driver(&pch_udc_driver);
2999}
3000module_exit(pch_udc_pci_exit);
3001
3002MODULE_DESCRIPTION("Intel EG20T USB Device Controller");
3003MODULE_AUTHOR("OKI SEMICONDUCTOR, <toshiharu-linux@dsn.okisemi.com>");
3004MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index cf241c371a71..271ef94668e7 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -126,36 +126,36 @@ static struct printer_dev usb_printer_gadget;
126#define PRINTER_VENDOR_NUM 0x0525 /* NetChip */ 126#define PRINTER_VENDOR_NUM 0x0525 /* NetChip */
127#define PRINTER_PRODUCT_NUM 0xa4a8 /* Linux-USB Printer Gadget */ 127#define PRINTER_PRODUCT_NUM 0xa4a8 /* Linux-USB Printer Gadget */
128 128
129/* Some systems will want different product identifers published in the 129/* Some systems will want different product identifiers published in the
130 * device descriptor, either numbers or strings or both. These string 130 * device descriptor, either numbers or strings or both. These string
131 * parameters are in UTF-8 (superset of ASCII's 7 bit characters). 131 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
132 */ 132 */
133 133
134static ushort __initdata idVendor; 134static ushort idVendor;
135module_param(idVendor, ushort, S_IRUGO); 135module_param(idVendor, ushort, S_IRUGO);
136MODULE_PARM_DESC(idVendor, "USB Vendor ID"); 136MODULE_PARM_DESC(idVendor, "USB Vendor ID");
137 137
138static ushort __initdata idProduct; 138static ushort idProduct;
139module_param(idProduct, ushort, S_IRUGO); 139module_param(idProduct, ushort, S_IRUGO);
140MODULE_PARM_DESC(idProduct, "USB Product ID"); 140MODULE_PARM_DESC(idProduct, "USB Product ID");
141 141
142static ushort __initdata bcdDevice; 142static ushort bcdDevice;
143module_param(bcdDevice, ushort, S_IRUGO); 143module_param(bcdDevice, ushort, S_IRUGO);
144MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); 144MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
145 145
146static char *__initdata iManufacturer; 146static char *iManufacturer;
147module_param(iManufacturer, charp, S_IRUGO); 147module_param(iManufacturer, charp, S_IRUGO);
148MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); 148MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
149 149
150static char *__initdata iProduct; 150static char *iProduct;
151module_param(iProduct, charp, S_IRUGO); 151module_param(iProduct, charp, S_IRUGO);
152MODULE_PARM_DESC(iProduct, "USB Product string"); 152MODULE_PARM_DESC(iProduct, "USB Product string");
153 153
154static char *__initdata iSerialNum; 154static char *iSerialNum;
155module_param(iSerialNum, charp, S_IRUGO); 155module_param(iSerialNum, charp, S_IRUGO);
156MODULE_PARM_DESC(iSerialNum, "1"); 156MODULE_PARM_DESC(iSerialNum, "1");
157 157
158static char *__initdata iPNPstring; 158static char *iPNPstring;
159module_param(iPNPstring, charp, S_IRUGO); 159module_param(iPNPstring, charp, S_IRUGO);
160MODULE_PARM_DESC(iPNPstring, "MFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;"); 160MODULE_PARM_DESC(iPNPstring, "MFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;");
161 161
@@ -884,7 +884,8 @@ static const struct file_operations printer_io_operations = {
884 .fsync = printer_fsync, 884 .fsync = printer_fsync,
885 .poll = printer_poll, 885 .poll = printer_poll,
886 .unlocked_ioctl = printer_ioctl, 886 .unlocked_ioctl = printer_ioctl,
887 .release = printer_close 887 .release = printer_close,
888 .llseek = noop_llseek,
888}; 889};
889 890
890/*-------------------------------------------------------------------------*/ 891/*-------------------------------------------------------------------------*/
@@ -1188,6 +1189,8 @@ printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1188 else if (gadget->a_alt_hnp_support) 1189 else if (gadget->a_alt_hnp_support)
1189 DBG(dev, "HNP needs a different root port\n"); 1190 DBG(dev, "HNP needs a different root port\n");
1190 value = printer_set_config(dev, wValue); 1191 value = printer_set_config(dev, wValue);
1192 if (!value)
1193 value = set_interface(dev, PRINTER_INTERFACE);
1191 break; 1194 break;
1192 case USB_REQ_GET_CONFIGURATION: 1195 case USB_REQ_GET_CONFIGURATION:
1193 if (ctrl->bRequestType != USB_DIR_IN) 1196 if (ctrl->bRequestType != USB_DIR_IN)
@@ -1347,7 +1350,7 @@ printer_unbind(struct usb_gadget *gadget)
1347 set_gadget_data(gadget, NULL); 1350 set_gadget_data(gadget, NULL);
1348} 1351}
1349 1352
1350static int __ref 1353static int __init
1351printer_bind(struct usb_gadget *gadget) 1354printer_bind(struct usb_gadget *gadget)
1352{ 1355{
1353 struct printer_dev *dev; 1356 struct printer_dev *dev;
@@ -1543,7 +1546,6 @@ static struct usb_gadget_driver printer_driver = {
1543 .speed = DEVSPEED, 1546 .speed = DEVSPEED,
1544 1547
1545 .function = (char *) driver_desc, 1548 .function = (char *) driver_desc,
1546 .bind = printer_bind,
1547 .unbind = printer_unbind, 1549 .unbind = printer_unbind,
1548 1550
1549 .setup = printer_setup, 1551 .setup = printer_setup,
@@ -1579,11 +1581,11 @@ init(void)
1579 return status; 1581 return status;
1580 } 1582 }
1581 1583
1582 status = usb_gadget_register_driver(&printer_driver); 1584 status = usb_gadget_probe_driver(&printer_driver, printer_bind);
1583 if (status) { 1585 if (status) {
1584 class_destroy(usb_gadget_class); 1586 class_destroy(usb_gadget_class);
1585 unregister_chrdev_region(g_printer_devno, 1); 1587 unregister_chrdev_region(g_printer_devno, 1);
1586 DBG(dev, "usb_gadget_register_driver %x\n", status); 1588 DBG(dev, "usb_gadget_probe_driver %x\n", status);
1587 } 1589 }
1588 1590
1589 return status; 1591 return status;
@@ -1596,13 +1598,12 @@ cleanup(void)
1596 int status; 1598 int status;
1597 1599
1598 mutex_lock(&usb_printer_gadget.lock_printer_io); 1600 mutex_lock(&usb_printer_gadget.lock_printer_io);
1599 class_destroy(usb_gadget_class);
1600 unregister_chrdev_region(g_printer_devno, 2);
1601
1602 status = usb_gadget_unregister_driver(&printer_driver); 1601 status = usb_gadget_unregister_driver(&printer_driver);
1603 if (status) 1602 if (status)
1604 ERROR(dev, "usb_gadget_unregister_driver %x\n", status); 1603 ERROR(dev, "usb_gadget_unregister_driver %x\n", status);
1605 1604
1605 unregister_chrdev_region(g_printer_devno, 2);
1606 class_destroy(usb_gadget_class);
1606 mutex_unlock(&usb_printer_gadget.lock_printer_io); 1607 mutex_unlock(&usb_printer_gadget.lock_printer_io);
1607} 1608}
1608module_exit(cleanup); 1609module_exit(cleanup);
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index be5fb34d9602..774545494cf2 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -46,6 +46,7 @@
46#include <linux/seq_file.h> 46#include <linux/seq_file.h>
47#include <linux/debugfs.h> 47#include <linux/debugfs.h>
48#include <linux/io.h> 48#include <linux/io.h>
49#include <linux/prefetch.h>
49 50
50#include <asm/byteorder.h> 51#include <asm/byteorder.h>
51#include <asm/dma.h> 52#include <asm/dma.h>
@@ -139,24 +140,6 @@ static const char ep0name [] = "ep0";
139static void pxa25x_ep_fifo_flush (struct usb_ep *ep); 140static void pxa25x_ep_fifo_flush (struct usb_ep *ep);
140static void nuke (struct pxa25x_ep *, int status); 141static void nuke (struct pxa25x_ep *, int status);
141 142
142/* one GPIO should be used to detect VBUS from the host */
143static int is_vbus_present(void)
144{
145 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
146
147 if (gpio_is_valid(mach->gpio_vbus)) {
148 int value = gpio_get_value(mach->gpio_vbus);
149
150 if (mach->gpio_vbus_inverted)
151 return !value;
152 else
153 return !!value;
154 }
155 if (mach->udc_is_connected)
156 return mach->udc_is_connected();
157 return 1;
158}
159
160/* one GPIO should control a D+ pullup, so host sees this device (or not) */ 143/* one GPIO should control a D+ pullup, so host sees this device (or not) */
161static void pullup_off(void) 144static void pullup_off(void)
162{ 145{
@@ -1055,7 +1038,7 @@ udc_seq_show(struct seq_file *m, void *_d)
1055 "%s version: %s\nGadget driver: %s\nHost %s\n\n", 1038 "%s version: %s\nGadget driver: %s\nHost %s\n\n",
1056 driver_name, DRIVER_VERSION SIZE_STR "(pio)", 1039 driver_name, DRIVER_VERSION SIZE_STR "(pio)",
1057 dev->driver ? dev->driver->driver.name : "(none)", 1040 dev->driver ? dev->driver->driver.name : "(none)",
1058 is_vbus_present() ? "full speed" : "disconnected"); 1041 dev->gadget.speed == USB_SPEED_FULL ? "full speed" : "disconnected");
1059 1042
1060 /* registers for device and ep0 */ 1043 /* registers for device and ep0 */
1061 seq_printf(m, 1044 seq_printf(m,
@@ -1094,7 +1077,7 @@ udc_seq_show(struct seq_file *m, void *_d)
1094 (tmp & UDCCFR_ACM) ? " acm" : ""); 1077 (tmp & UDCCFR_ACM) ? " acm" : "");
1095 } 1078 }
1096 1079
1097 if (!is_vbus_present() || !dev->driver) 1080 if (dev->gadget.speed != USB_SPEED_FULL || !dev->driver)
1098 goto done; 1081 goto done;
1099 1082
1100 seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n", 1083 seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
@@ -1280,14 +1263,15 @@ static void udc_enable (struct pxa25x_udc *dev)
1280 * disconnect is reported. then a host may connect again, or 1263 * disconnect is reported. then a host may connect again, or
1281 * the driver might get unbound. 1264 * the driver might get unbound.
1282 */ 1265 */
1283int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1266int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1267 int (*bind)(struct usb_gadget *))
1284{ 1268{
1285 struct pxa25x_udc *dev = the_controller; 1269 struct pxa25x_udc *dev = the_controller;
1286 int retval; 1270 int retval;
1287 1271
1288 if (!driver 1272 if (!driver
1289 || driver->speed < USB_SPEED_FULL 1273 || driver->speed < USB_SPEED_FULL
1290 || !driver->bind 1274 || !bind
1291 || !driver->disconnect 1275 || !driver->disconnect
1292 || !driver->setup) 1276 || !driver->setup)
1293 return -EINVAL; 1277 return -EINVAL;
@@ -1308,7 +1292,7 @@ fail:
1308 dev->gadget.dev.driver = NULL; 1292 dev->gadget.dev.driver = NULL;
1309 return retval; 1293 return retval;
1310 } 1294 }
1311 retval = driver->bind(&dev->gadget); 1295 retval = bind(&dev->gadget);
1312 if (retval) { 1296 if (retval) {
1313 DMSG("bind to driver %s --> error %d\n", 1297 DMSG("bind to driver %s --> error %d\n",
1314 driver->driver.name, retval); 1298 driver->driver.name, retval);
@@ -1338,7 +1322,7 @@ fail:
1338bind_fail: 1322bind_fail:
1339 return retval; 1323 return retval;
1340} 1324}
1341EXPORT_SYMBOL(usb_gadget_register_driver); 1325EXPORT_SYMBOL(usb_gadget_probe_driver);
1342 1326
1343static void 1327static void
1344stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) 1328stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
@@ -1434,14 +1418,6 @@ lubbock_vbus_irq(int irq, void *_dev)
1434 1418
1435#endif 1419#endif
1436 1420
1437static irqreturn_t udc_vbus_irq(int irq, void *_dev)
1438{
1439 struct pxa25x_udc *dev = _dev;
1440
1441 pxa25x_udc_vbus_session(&dev->gadget, is_vbus_present());
1442 return IRQ_HANDLED;
1443}
1444
1445 1421
1446/*-------------------------------------------------------------------------*/ 1422/*-------------------------------------------------------------------------*/
1447 1423
@@ -1765,12 +1741,9 @@ pxa25x_udc_irq(int irq, void *_dev)
1765 if (unlikely(udccr & UDCCR_SUSIR)) { 1741 if (unlikely(udccr & UDCCR_SUSIR)) {
1766 udc_ack_int_UDCCR(UDCCR_SUSIR); 1742 udc_ack_int_UDCCR(UDCCR_SUSIR);
1767 handled = 1; 1743 handled = 1;
1768 DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present() 1744 DBG(DBG_VERBOSE, "USB suspend\n");
1769 ? "" : "+disconnect");
1770 1745
1771 if (!is_vbus_present()) 1746 if (dev->gadget.speed != USB_SPEED_UNKNOWN
1772 stop_activity(dev, dev->driver);
1773 else if (dev->gadget.speed != USB_SPEED_UNKNOWN
1774 && dev->driver 1747 && dev->driver
1775 && dev->driver->suspend) 1748 && dev->driver->suspend)
1776 dev->driver->suspend(&dev->gadget); 1749 dev->driver->suspend(&dev->gadget);
@@ -1785,8 +1758,7 @@ pxa25x_udc_irq(int irq, void *_dev)
1785 1758
1786 if (dev->gadget.speed != USB_SPEED_UNKNOWN 1759 if (dev->gadget.speed != USB_SPEED_UNKNOWN
1787 && dev->driver 1760 && dev->driver
1788 && dev->driver->resume 1761 && dev->driver->resume)
1789 && is_vbus_present())
1790 dev->driver->resume(&dev->gadget); 1762 dev->driver->resume(&dev->gadget);
1791 } 1763 }
1792 1764
@@ -2136,7 +2108,7 @@ static struct pxa25x_udc memory = {
2136static int __init pxa25x_udc_probe(struct platform_device *pdev) 2108static int __init pxa25x_udc_probe(struct platform_device *pdev)
2137{ 2109{
2138 struct pxa25x_udc *dev = &memory; 2110 struct pxa25x_udc *dev = &memory;
2139 int retval, vbus_irq, irq; 2111 int retval, irq;
2140 u32 chiprev; 2112 u32 chiprev;
2141 2113
2142 /* insist on Intel/ARM/XScale */ 2114 /* insist on Intel/ARM/XScale */
@@ -2198,19 +2170,6 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2198 2170
2199 dev->transceiver = otg_get_transceiver(); 2171 dev->transceiver = otg_get_transceiver();
2200 2172
2201 if (gpio_is_valid(dev->mach->gpio_vbus)) {
2202 if ((retval = gpio_request(dev->mach->gpio_vbus,
2203 "pxa25x_udc GPIO VBUS"))) {
2204 dev_dbg(&pdev->dev,
2205 "can't get vbus gpio %d, err: %d\n",
2206 dev->mach->gpio_vbus, retval);
2207 goto err_gpio_vbus;
2208 }
2209 gpio_direction_input(dev->mach->gpio_vbus);
2210 vbus_irq = gpio_to_irq(dev->mach->gpio_vbus);
2211 } else
2212 vbus_irq = 0;
2213
2214 if (gpio_is_valid(dev->mach->gpio_pullup)) { 2173 if (gpio_is_valid(dev->mach->gpio_pullup)) {
2215 if ((retval = gpio_request(dev->mach->gpio_pullup, 2174 if ((retval = gpio_request(dev->mach->gpio_pullup,
2216 "pca25x_udc GPIO PULLUP"))) { 2175 "pca25x_udc GPIO PULLUP"))) {
@@ -2236,7 +2195,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2236 udc_disable(dev); 2195 udc_disable(dev);
2237 udc_reinit(dev); 2196 udc_reinit(dev);
2238 2197
2239 dev->vbus = !!is_vbus_present(); 2198 dev->vbus = 0;
2240 2199
2241 /* irq setup after old hardware state is cleaned up */ 2200 /* irq setup after old hardware state is cleaned up */
2242 retval = request_irq(irq, pxa25x_udc_irq, 2201 retval = request_irq(irq, pxa25x_udc_irq,
@@ -2257,7 +2216,6 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2257 if (retval != 0) { 2216 if (retval != 0) {
2258 pr_err("%s: can't get irq %i, err %d\n", 2217 pr_err("%s: can't get irq %i, err %d\n",
2259 driver_name, LUBBOCK_USB_DISC_IRQ, retval); 2218 driver_name, LUBBOCK_USB_DISC_IRQ, retval);
2260lubbock_fail0:
2261 goto err_irq_lub; 2219 goto err_irq_lub;
2262 } 2220 }
2263 retval = request_irq(LUBBOCK_USB_IRQ, 2221 retval = request_irq(LUBBOCK_USB_IRQ,
@@ -2267,39 +2225,24 @@ lubbock_fail0:
2267 if (retval != 0) { 2225 if (retval != 0) {
2268 pr_err("%s: can't get irq %i, err %d\n", 2226 pr_err("%s: can't get irq %i, err %d\n",
2269 driver_name, LUBBOCK_USB_IRQ, retval); 2227 driver_name, LUBBOCK_USB_IRQ, retval);
2270 free_irq(LUBBOCK_USB_DISC_IRQ, dev);
2271 goto lubbock_fail0; 2228 goto lubbock_fail0;
2272 } 2229 }
2273 } else 2230 } else
2274#endif 2231#endif
2275 if (vbus_irq) {
2276 retval = request_irq(vbus_irq, udc_vbus_irq,
2277 IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
2278 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
2279 driver_name, dev);
2280 if (retval != 0) {
2281 pr_err("%s: can't get irq %i, err %d\n",
2282 driver_name, vbus_irq, retval);
2283 goto err_vbus_irq;
2284 }
2285 }
2286 create_debug_files(dev); 2232 create_debug_files(dev);
2287 2233
2288 return 0; 2234 return 0;
2289 2235
2290 err_vbus_irq:
2291#ifdef CONFIG_ARCH_LUBBOCK 2236#ifdef CONFIG_ARCH_LUBBOCK
2237lubbock_fail0:
2292 free_irq(LUBBOCK_USB_DISC_IRQ, dev); 2238 free_irq(LUBBOCK_USB_DISC_IRQ, dev);
2293 err_irq_lub: 2239 err_irq_lub:
2294#endif
2295 free_irq(irq, dev); 2240 free_irq(irq, dev);
2241#endif
2296 err_irq1: 2242 err_irq1:
2297 if (gpio_is_valid(dev->mach->gpio_pullup)) 2243 if (gpio_is_valid(dev->mach->gpio_pullup))
2298 gpio_free(dev->mach->gpio_pullup); 2244 gpio_free(dev->mach->gpio_pullup);
2299 err_gpio_pullup: 2245 err_gpio_pullup:
2300 if (gpio_is_valid(dev->mach->gpio_vbus))
2301 gpio_free(dev->mach->gpio_vbus);
2302 err_gpio_vbus:
2303 if (dev->transceiver) { 2246 if (dev->transceiver) {
2304 otg_put_transceiver(dev->transceiver); 2247 otg_put_transceiver(dev->transceiver);
2305 dev->transceiver = NULL; 2248 dev->transceiver = NULL;
@@ -2336,10 +2279,6 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev)
2336 free_irq(LUBBOCK_USB_IRQ, dev); 2279 free_irq(LUBBOCK_USB_IRQ, dev);
2337 } 2280 }
2338#endif 2281#endif
2339 if (gpio_is_valid(dev->mach->gpio_vbus)) {
2340 free_irq(gpio_to_irq(dev->mach->gpio_vbus), dev);
2341 gpio_free(dev->mach->gpio_vbus);
2342 }
2343 if (gpio_is_valid(dev->mach->gpio_pullup)) 2282 if (gpio_is_valid(dev->mach->gpio_pullup))
2344 gpio_free(dev->mach->gpio_pullup); 2283 gpio_free(dev->mach->gpio_pullup);
2345 2284
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 980762453a9c..57607696735c 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -32,6 +32,7 @@
32#include <linux/irq.h> 32#include <linux/irq.h>
33#include <linux/gpio.h> 33#include <linux/gpio.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/prefetch.h>
35 36
36#include <asm/byteorder.h> 37#include <asm/byteorder.h>
37#include <mach/hardware.h> 38#include <mach/hardware.h>
@@ -602,7 +603,7 @@ static void inc_ep_stats_reqs(struct pxa_ep *ep, int is_in)
602/** 603/**
603 * inc_ep_stats_bytes - Update ep stats counts 604 * inc_ep_stats_bytes - Update ep stats counts
604 * @ep: physical endpoint 605 * @ep: physical endpoint
605 * @count: bytes transfered on endpoint 606 * @count: bytes transferred on endpoint
606 * @is_in: ep direction (USB_DIR_IN or 0) 607 * @is_in: ep direction (USB_DIR_IN or 0)
607 */ 608 */
608static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in) 609static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in)
@@ -877,7 +878,7 @@ static void nuke(struct pxa_ep *ep, int status)
877 * If there is less space in request than bytes received in OUT endpoint, 878 * If there is less space in request than bytes received in OUT endpoint,
878 * bytes are left in the OUT endpoint. 879 * bytes are left in the OUT endpoint.
879 * 880 *
880 * Returns how many bytes were actually transfered 881 * Returns how many bytes were actually transferred
881 */ 882 */
882static int read_packet(struct pxa_ep *ep, struct pxa27x_request *req) 883static int read_packet(struct pxa_ep *ep, struct pxa27x_request *req)
883{ 884{
@@ -914,7 +915,7 @@ static int read_packet(struct pxa_ep *ep, struct pxa27x_request *req)
914 * endpoint. If there are no bytes to transfer, doesn't write anything 915 * endpoint. If there are no bytes to transfer, doesn't write anything
915 * to physical endpoint. 916 * to physical endpoint.
916 * 917 *
917 * Returns how many bytes were actually transfered. 918 * Returns how many bytes were actually transferred.
918 */ 919 */
919static int write_packet(struct pxa_ep *ep, struct pxa27x_request *req, 920static int write_packet(struct pxa_ep *ep, struct pxa27x_request *req,
920 unsigned int max) 921 unsigned int max)
@@ -991,7 +992,7 @@ static int read_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
991 * caller guarantees at least one packet buffer is ready (or a zlp). 992 * caller guarantees at least one packet buffer is ready (or a zlp).
992 * Doesn't complete the request, that's the caller's job 993 * Doesn't complete the request, that's the caller's job
993 * 994 *
994 * Returns 1 if request fully transfered, 0 if partial transfer 995 * Returns 1 if request fully transferred, 0 if partial transfer
995 */ 996 */
996static int write_fifo(struct pxa_ep *ep, struct pxa27x_request *req) 997static int write_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
997{ 998{
@@ -1094,7 +1095,7 @@ static int read_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
1094 * Sends a request (or a part of the request) to the control endpoint (ep0 in). 1095 * Sends a request (or a part of the request) to the control endpoint (ep0 in).
1095 * If the request doesn't fit, the remaining part will be sent from irq. 1096 * If the request doesn't fit, the remaining part will be sent from irq.
1096 * The request is considered fully written only if either : 1097 * The request is considered fully written only if either :
1097 * - last write transfered all remaining bytes, but fifo was not fully filled 1098 * - last write transferred all remaining bytes, but fifo was not fully filled
1098 * - last write was a 0 length write 1099 * - last write was a 0 length write
1099 * 1100 *
1100 * Returns 1 if request fully written, 0 if request only partially sent 1101 * Returns 1 if request fully written, 0 if request only partially sent
@@ -1394,8 +1395,6 @@ static void pxa_ep_fifo_flush(struct usb_ep *_ep)
1394 } 1395 }
1395 1396
1396 spin_unlock_irqrestore(&ep->lock, flags); 1397 spin_unlock_irqrestore(&ep->lock, flags);
1397
1398 return;
1399} 1398}
1400 1399
1401/** 1400/**
@@ -1550,7 +1549,7 @@ static int pxa_udc_get_frame(struct usb_gadget *_gadget)
1550 * pxa_udc_wakeup - Force udc device out of suspend 1549 * pxa_udc_wakeup - Force udc device out of suspend
1551 * @_gadget: usb gadget 1550 * @_gadget: usb gadget
1552 * 1551 *
1553 * Returns 0 if successfull, error code otherwise 1552 * Returns 0 if successful, error code otherwise
1554 */ 1553 */
1555static int pxa_udc_wakeup(struct usb_gadget *_gadget) 1554static int pxa_udc_wakeup(struct usb_gadget *_gadget)
1556{ 1555{
@@ -1792,8 +1791,9 @@ static void udc_enable(struct pxa_udc *udc)
1792} 1791}
1793 1792
1794/** 1793/**
1795 * usb_gadget_register_driver - Register gadget driver 1794 * usb_gadget_probe_driver - Register gadget driver
1796 * @driver: gadget driver 1795 * @driver: gadget driver
1796 * @bind: bind function
1797 * 1797 *
1798 * When a driver is successfully registered, it will receive control requests 1798 * When a driver is successfully registered, it will receive control requests
1799 * including set_configuration(), which enables non-control requests. Then 1799 * including set_configuration(), which enables non-control requests. Then
@@ -1805,12 +1805,13 @@ static void udc_enable(struct pxa_udc *udc)
1805 * 1805 *
1806 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise 1806 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1807 */ 1807 */
1808int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1808int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1809 int (*bind)(struct usb_gadget *))
1809{ 1810{
1810 struct pxa_udc *udc = the_controller; 1811 struct pxa_udc *udc = the_controller;
1811 int retval; 1812 int retval;
1812 1813
1813 if (!driver || driver->speed < USB_SPEED_FULL || !driver->bind 1814 if (!driver || driver->speed < USB_SPEED_FULL || !bind
1814 || !driver->disconnect || !driver->setup) 1815 || !driver->disconnect || !driver->setup)
1815 return -EINVAL; 1816 return -EINVAL;
1816 if (!udc) 1817 if (!udc)
@@ -1828,7 +1829,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1828 dev_err(udc->dev, "device_add error %d\n", retval); 1829 dev_err(udc->dev, "device_add error %d\n", retval);
1829 goto add_fail; 1830 goto add_fail;
1830 } 1831 }
1831 retval = driver->bind(&udc->gadget); 1832 retval = bind(&udc->gadget);
1832 if (retval) { 1833 if (retval) {
1833 dev_err(udc->dev, "bind to driver %s --> error %d\n", 1834 dev_err(udc->dev, "bind to driver %s --> error %d\n",
1834 driver->driver.name, retval); 1835 driver->driver.name, retval);
@@ -1859,7 +1860,7 @@ add_fail:
1859 udc->gadget.dev.driver = NULL; 1860 udc->gadget.dev.driver = NULL;
1860 return retval; 1861 return retval;
1861} 1862}
1862EXPORT_SYMBOL(usb_gadget_register_driver); 1863EXPORT_SYMBOL(usb_gadget_probe_driver);
1863 1864
1864 1865
1865/** 1866/**
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index 2456ccd9965e..6dcc1f68fa60 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -42,6 +42,7 @@ static const char *r8a66597_ep_name[] = {
42 "ep8", "ep9", 42 "ep8", "ep9",
43}; 43};
44 44
45static void init_controller(struct r8a66597 *r8a66597);
45static void disable_controller(struct r8a66597 *r8a66597); 46static void disable_controller(struct r8a66597 *r8a66597);
46static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req); 47static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req);
47static void irq_packet_write(struct r8a66597_ep *ep, 48static void irq_packet_write(struct r8a66597_ep *ep,
@@ -104,6 +105,8 @@ __acquires(r8a66597->lock)
104 spin_lock(&r8a66597->lock); 105 spin_lock(&r8a66597->lock);
105 106
106 disable_controller(r8a66597); 107 disable_controller(r8a66597);
108 init_controller(r8a66597);
109 r8a66597_bset(r8a66597, VBSE, INTENB0);
107 INIT_LIST_HEAD(&r8a66597->ep[0].queue); 110 INIT_LIST_HEAD(&r8a66597->ep[0].queue);
108} 111}
109 112
@@ -255,7 +258,7 @@ static int pipe_buffer_setting(struct r8a66597 *r8a66597,
255 break; 258 break;
256 case R8A66597_BULK: 259 case R8A66597_BULK:
257 /* isochronous pipes may be used as bulk pipes */ 260 /* isochronous pipes may be used as bulk pipes */
258 if (info->pipe > R8A66597_BASE_PIPENUM_BULK) 261 if (info->pipe >= R8A66597_BASE_PIPENUM_BULK)
259 bufnum = info->pipe - R8A66597_BASE_PIPENUM_BULK; 262 bufnum = info->pipe - R8A66597_BASE_PIPENUM_BULK;
260 else 263 else
261 bufnum = info->pipe - R8A66597_BASE_PIPENUM_ISOC; 264 bufnum = info->pipe - R8A66597_BASE_PIPENUM_ISOC;
@@ -274,7 +277,7 @@ static int pipe_buffer_setting(struct r8a66597 *r8a66597,
274 } 277 }
275 278
276 if (buf_bsize && ((bufnum + 16) >= R8A66597_MAX_BUFNUM)) { 279 if (buf_bsize && ((bufnum + 16) >= R8A66597_MAX_BUFNUM)) {
277 pr_err(KERN_ERR "r8a66597 pipe memory is insufficient\n"); 280 pr_err("r8a66597 pipe memory is insufficient\n");
278 return -ENOMEM; 281 return -ENOMEM;
279 } 282 }
280 283
@@ -1080,7 +1083,9 @@ static void irq_device_state(struct r8a66597 *r8a66597)
1080 1083
1081 if (dvsq == DS_DFLT) { 1084 if (dvsq == DS_DFLT) {
1082 /* bus reset */ 1085 /* bus reset */
1086 spin_unlock(&r8a66597->lock);
1083 r8a66597->driver->disconnect(&r8a66597->gadget); 1087 r8a66597->driver->disconnect(&r8a66597->gadget);
1088 spin_lock(&r8a66597->lock);
1084 r8a66597_update_usb_speed(r8a66597); 1089 r8a66597_update_usb_speed(r8a66597);
1085 } 1090 }
1086 if (r8a66597->old_dvsq == DS_CNFG && dvsq != DS_CNFG) 1091 if (r8a66597->old_dvsq == DS_CNFG && dvsq != DS_CNFG)
@@ -1405,14 +1410,15 @@ static struct usb_ep_ops r8a66597_ep_ops = {
1405/*-------------------------------------------------------------------------*/ 1410/*-------------------------------------------------------------------------*/
1406static struct r8a66597 *the_controller; 1411static struct r8a66597 *the_controller;
1407 1412
1408int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1413int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1414 int (*bind)(struct usb_gadget *))
1409{ 1415{
1410 struct r8a66597 *r8a66597 = the_controller; 1416 struct r8a66597 *r8a66597 = the_controller;
1411 int retval; 1417 int retval;
1412 1418
1413 if (!driver 1419 if (!driver
1414 || driver->speed != USB_SPEED_HIGH 1420 || driver->speed != USB_SPEED_HIGH
1415 || !driver->bind 1421 || !bind
1416 || !driver->setup) 1422 || !driver->setup)
1417 return -EINVAL; 1423 return -EINVAL;
1418 if (!r8a66597) 1424 if (!r8a66597)
@@ -1431,7 +1437,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1431 goto error; 1437 goto error;
1432 } 1438 }
1433 1439
1434 retval = driver->bind(&r8a66597->gadget); 1440 retval = bind(&r8a66597->gadget);
1435 if (retval) { 1441 if (retval) {
1436 printk(KERN_ERR "bind to driver error (%d)\n", retval); 1442 printk(KERN_ERR "bind to driver error (%d)\n", retval);
1437 device_del(&r8a66597->gadget.dev); 1443 device_del(&r8a66597->gadget.dev);
@@ -1456,7 +1462,7 @@ error:
1456 1462
1457 return retval; 1463 return retval;
1458} 1464}
1459EXPORT_SYMBOL(usb_gadget_register_driver); 1465EXPORT_SYMBOL(usb_gadget_probe_driver);
1460 1466
1461int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1467int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1462{ 1468{
diff --git a/drivers/usb/gadget/r8a66597-udc.h b/drivers/usb/gadget/r8a66597-udc.h
index f763b5190afa..5fc22e09a0f1 100644
--- a/drivers/usb/gadget/r8a66597-udc.h
+++ b/drivers/usb/gadget/r8a66597-udc.h
@@ -136,7 +136,7 @@ static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597,
136 int len) 136 int len)
137{ 137{
138 void __iomem *fifoaddr = r8a66597->reg + offset; 138 void __iomem *fifoaddr = r8a66597->reg + offset;
139 unsigned int data; 139 unsigned int data = 0;
140 int i; 140 int i;
141 141
142 if (r8a66597->pdata->on_chip) { 142 if (r8a66597->pdata->on_chip) {
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 972d5ddd1e18..d3cdffea9c8a 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -61,17 +61,17 @@ MODULE_PARM_DESC (rndis_debug, "enable debugging");
61#define RNDIS_MAX_CONFIGS 1 61#define RNDIS_MAX_CONFIGS 1
62 62
63 63
64static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS]; 64static rndis_params rndis_per_dev_params[RNDIS_MAX_CONFIGS];
65 65
66/* Driver Version */ 66/* Driver Version */
67static const __le32 rndis_driver_version = cpu_to_le32 (1); 67static const __le32 rndis_driver_version = cpu_to_le32(1);
68 68
69/* Function Prototypes */ 69/* Function Prototypes */
70static rndis_resp_t *rndis_add_response (int configNr, u32 length); 70static rndis_resp_t *rndis_add_response(int configNr, u32 length);
71 71
72 72
73/* supported OIDs */ 73/* supported OIDs */
74static const u32 oid_supported_list [] = 74static const u32 oid_supported_list[] =
75{ 75{
76 /* the general stuff */ 76 /* the general stuff */
77 OID_GEN_SUPPORTED_LIST, 77 OID_GEN_SUPPORTED_LIST,
@@ -161,21 +161,20 @@ static const u32 oid_supported_list [] =
161 161
162 162
163/* NDIS Functions */ 163/* NDIS Functions */
164static int 164static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
165gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, 165 unsigned buf_len, rndis_resp_t *r)
166 rndis_resp_t *r)
167{ 166{
168 int retval = -ENOTSUPP; 167 int retval = -ENOTSUPP;
169 u32 length = 4; /* usually */ 168 u32 length = 4; /* usually */
170 __le32 *outbuf; 169 __le32 *outbuf;
171 int i, count; 170 int i, count;
172 rndis_query_cmplt_type *resp; 171 rndis_query_cmplt_type *resp;
173 struct net_device *net; 172 struct net_device *net;
174 struct rtnl_link_stats64 temp; 173 struct rtnl_link_stats64 temp;
175 const struct rtnl_link_stats64 *stats; 174 const struct rtnl_link_stats64 *stats;
176 175
177 if (!r) return -ENOMEM; 176 if (!r) return -ENOMEM;
178 resp = (rndis_query_cmplt_type *) r->buf; 177 resp = (rndis_query_cmplt_type *)r->buf;
179 178
180 if (!resp) return -ENOMEM; 179 if (!resp) return -ENOMEM;
181 180
@@ -191,8 +190,8 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
191 } 190 }
192 191
193 /* response goes here, right after the header */ 192 /* response goes here, right after the header */
194 outbuf = (__le32 *) &resp[1]; 193 outbuf = (__le32 *)&resp[1];
195 resp->InformationBufferOffset = cpu_to_le32 (16); 194 resp->InformationBufferOffset = cpu_to_le32(16);
196 195
197 net = rndis_per_dev_params[configNr].dev; 196 net = rndis_per_dev_params[configNr].dev;
198 stats = dev_get_stats(net, &temp); 197 stats = dev_get_stats(net, &temp);
@@ -204,10 +203,10 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
204 /* mandatory */ 203 /* mandatory */
205 case OID_GEN_SUPPORTED_LIST: 204 case OID_GEN_SUPPORTED_LIST:
206 pr_debug("%s: OID_GEN_SUPPORTED_LIST\n", __func__); 205 pr_debug("%s: OID_GEN_SUPPORTED_LIST\n", __func__);
207 length = sizeof (oid_supported_list); 206 length = sizeof(oid_supported_list);
208 count = length / sizeof (u32); 207 count = length / sizeof(u32);
209 for (i = 0; i < count; i++) 208 for (i = 0; i < count; i++)
210 outbuf[i] = cpu_to_le32 (oid_supported_list[i]); 209 outbuf[i] = cpu_to_le32(oid_supported_list[i]);
211 retval = 0; 210 retval = 0;
212 break; 211 break;
213 212
@@ -220,14 +219,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
220 * reddite ergo quae sunt Caesaris Caesari 219 * reddite ergo quae sunt Caesaris Caesari
221 * et quae sunt Dei Deo! 220 * et quae sunt Dei Deo!
222 */ 221 */
223 *outbuf = cpu_to_le32 (0); 222 *outbuf = cpu_to_le32(0);
224 retval = 0; 223 retval = 0;
225 break; 224 break;
226 225
227 /* mandatory */ 226 /* mandatory */
228 case OID_GEN_MEDIA_SUPPORTED: 227 case OID_GEN_MEDIA_SUPPORTED:
229 pr_debug("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__); 228 pr_debug("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__);
230 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 229 *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium);
231 retval = 0; 230 retval = 0;
232 break; 231 break;
233 232
@@ -235,16 +234,16 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
235 case OID_GEN_MEDIA_IN_USE: 234 case OID_GEN_MEDIA_IN_USE:
236 pr_debug("%s: OID_GEN_MEDIA_IN_USE\n", __func__); 235 pr_debug("%s: OID_GEN_MEDIA_IN_USE\n", __func__);
237 /* one medium, one transport... (maybe you do it better) */ 236 /* one medium, one transport... (maybe you do it better) */
238 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 237 *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium);
239 retval = 0; 238 retval = 0;
240 break; 239 break;
241 240
242 /* mandatory */ 241 /* mandatory */
243 case OID_GEN_MAXIMUM_FRAME_SIZE: 242 case OID_GEN_MAXIMUM_FRAME_SIZE:
244 pr_debug("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__); 243 pr_debug("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
245 if (rndis_per_dev_params [configNr].dev) { 244 if (rndis_per_dev_params[configNr].dev) {
246 *outbuf = cpu_to_le32 ( 245 *outbuf = cpu_to_le32(
247 rndis_per_dev_params [configNr].dev->mtu); 246 rndis_per_dev_params[configNr].dev->mtu);
248 retval = 0; 247 retval = 0;
249 } 248 }
250 break; 249 break;
@@ -253,21 +252,21 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
253 case OID_GEN_LINK_SPEED: 252 case OID_GEN_LINK_SPEED:
254 if (rndis_debug > 1) 253 if (rndis_debug > 1)
255 pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__); 254 pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__);
256 if (rndis_per_dev_params [configNr].media_state 255 if (rndis_per_dev_params[configNr].media_state
257 == NDIS_MEDIA_STATE_DISCONNECTED) 256 == NDIS_MEDIA_STATE_DISCONNECTED)
258 *outbuf = cpu_to_le32 (0); 257 *outbuf = cpu_to_le32(0);
259 else 258 else
260 *outbuf = cpu_to_le32 ( 259 *outbuf = cpu_to_le32(
261 rndis_per_dev_params [configNr].speed); 260 rndis_per_dev_params[configNr].speed);
262 retval = 0; 261 retval = 0;
263 break; 262 break;
264 263
265 /* mandatory */ 264 /* mandatory */
266 case OID_GEN_TRANSMIT_BLOCK_SIZE: 265 case OID_GEN_TRANSMIT_BLOCK_SIZE:
267 pr_debug("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__); 266 pr_debug("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
268 if (rndis_per_dev_params [configNr].dev) { 267 if (rndis_per_dev_params[configNr].dev) {
269 *outbuf = cpu_to_le32 ( 268 *outbuf = cpu_to_le32(
270 rndis_per_dev_params [configNr].dev->mtu); 269 rndis_per_dev_params[configNr].dev->mtu);
271 retval = 0; 270 retval = 0;
272 } 271 }
273 break; 272 break;
@@ -275,9 +274,9 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
275 /* mandatory */ 274 /* mandatory */
276 case OID_GEN_RECEIVE_BLOCK_SIZE: 275 case OID_GEN_RECEIVE_BLOCK_SIZE:
277 pr_debug("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__); 276 pr_debug("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
278 if (rndis_per_dev_params [configNr].dev) { 277 if (rndis_per_dev_params[configNr].dev) {
279 *outbuf = cpu_to_le32 ( 278 *outbuf = cpu_to_le32(
280 rndis_per_dev_params [configNr].dev->mtu); 279 rndis_per_dev_params[configNr].dev->mtu);
281 retval = 0; 280 retval = 0;
282 } 281 }
283 break; 282 break;
@@ -285,18 +284,20 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
285 /* mandatory */ 284 /* mandatory */
286 case OID_GEN_VENDOR_ID: 285 case OID_GEN_VENDOR_ID:
287 pr_debug("%s: OID_GEN_VENDOR_ID\n", __func__); 286 pr_debug("%s: OID_GEN_VENDOR_ID\n", __func__);
288 *outbuf = cpu_to_le32 ( 287 *outbuf = cpu_to_le32(
289 rndis_per_dev_params [configNr].vendorID); 288 rndis_per_dev_params[configNr].vendorID);
290 retval = 0; 289 retval = 0;
291 break; 290 break;
292 291
293 /* mandatory */ 292 /* mandatory */
294 case OID_GEN_VENDOR_DESCRIPTION: 293 case OID_GEN_VENDOR_DESCRIPTION:
295 pr_debug("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__); 294 pr_debug("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__);
296 if ( rndis_per_dev_params [configNr].vendorDescr ) { 295 if (rndis_per_dev_params[configNr].vendorDescr) {
297 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 296 length = strlen(rndis_per_dev_params[configNr].
298 memcpy (outbuf, 297 vendorDescr);
299 rndis_per_dev_params [configNr].vendorDescr, length); 298 memcpy(outbuf,
299 rndis_per_dev_params[configNr].vendorDescr,
300 length);
300 } else { 301 } else {
301 outbuf[0] = 0; 302 outbuf[0] = 0;
302 } 303 }
@@ -313,7 +314,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
313 /* mandatory */ 314 /* mandatory */
314 case OID_GEN_CURRENT_PACKET_FILTER: 315 case OID_GEN_CURRENT_PACKET_FILTER:
315 pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__); 316 pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
316 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); 317 *outbuf = cpu_to_le32(*rndis_per_dev_params[configNr].filter);
317 retval = 0; 318 retval = 0;
318 break; 319 break;
319 320
@@ -328,14 +329,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
328 case OID_GEN_MEDIA_CONNECT_STATUS: 329 case OID_GEN_MEDIA_CONNECT_STATUS:
329 if (rndis_debug > 1) 330 if (rndis_debug > 1)
330 pr_debug("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); 331 pr_debug("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
331 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 332 *outbuf = cpu_to_le32(rndis_per_dev_params[configNr]
332 .media_state); 333 .media_state);
333 retval = 0; 334 retval = 0;
334 break; 335 break;
335 336
336 case OID_GEN_PHYSICAL_MEDIUM: 337 case OID_GEN_PHYSICAL_MEDIUM:
337 pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__); 338 pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__);
338 *outbuf = cpu_to_le32 (0); 339 *outbuf = cpu_to_le32(0);
339 retval = 0; 340 retval = 0;
340 break; 341 break;
341 342
@@ -409,10 +410,10 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
409 /* mandatory */ 410 /* mandatory */
410 case OID_802_3_PERMANENT_ADDRESS: 411 case OID_802_3_PERMANENT_ADDRESS:
411 pr_debug("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__); 412 pr_debug("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__);
412 if (rndis_per_dev_params [configNr].dev) { 413 if (rndis_per_dev_params[configNr].dev) {
413 length = ETH_ALEN; 414 length = ETH_ALEN;
414 memcpy (outbuf, 415 memcpy(outbuf,
415 rndis_per_dev_params [configNr].host_mac, 416 rndis_per_dev_params[configNr].host_mac,
416 length); 417 length);
417 retval = 0; 418 retval = 0;
418 } 419 }
@@ -421,9 +422,9 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
421 /* mandatory */ 422 /* mandatory */
422 case OID_802_3_CURRENT_ADDRESS: 423 case OID_802_3_CURRENT_ADDRESS:
423 pr_debug("%s: OID_802_3_CURRENT_ADDRESS\n", __func__); 424 pr_debug("%s: OID_802_3_CURRENT_ADDRESS\n", __func__);
424 if (rndis_per_dev_params [configNr].dev) { 425 if (rndis_per_dev_params[configNr].dev) {
425 length = ETH_ALEN; 426 length = ETH_ALEN;
426 memcpy (outbuf, 427 memcpy(outbuf,
427 rndis_per_dev_params [configNr].host_mac, 428 rndis_per_dev_params [configNr].host_mac,
428 length); 429 length);
429 retval = 0; 430 retval = 0;
@@ -434,7 +435,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
434 case OID_802_3_MULTICAST_LIST: 435 case OID_802_3_MULTICAST_LIST:
435 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__); 436 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__);
436 /* Multicast base address only */ 437 /* Multicast base address only */
437 *outbuf = cpu_to_le32 (0xE0000000); 438 *outbuf = cpu_to_le32(0xE0000000);
438 retval = 0; 439 retval = 0;
439 break; 440 break;
440 441
@@ -442,7 +443,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
442 case OID_802_3_MAXIMUM_LIST_SIZE: 443 case OID_802_3_MAXIMUM_LIST_SIZE:
443 pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__); 444 pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
444 /* Multicast base address only */ 445 /* Multicast base address only */
445 *outbuf = cpu_to_le32 (1); 446 *outbuf = cpu_to_le32(1);
446 retval = 0; 447 retval = 0;
447 break; 448 break;
448 449
@@ -466,14 +467,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
466 /* mandatory */ 467 /* mandatory */
467 case OID_802_3_XMIT_ONE_COLLISION: 468 case OID_802_3_XMIT_ONE_COLLISION:
468 pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__); 469 pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__);
469 *outbuf = cpu_to_le32 (0); 470 *outbuf = cpu_to_le32(0);
470 retval = 0; 471 retval = 0;
471 break; 472 break;
472 473
473 /* mandatory */ 474 /* mandatory */
474 case OID_802_3_XMIT_MORE_COLLISIONS: 475 case OID_802_3_XMIT_MORE_COLLISIONS:
475 pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__); 476 pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
476 *outbuf = cpu_to_le32 (0); 477 *outbuf = cpu_to_le32(0);
477 retval = 0; 478 retval = 0;
478 break; 479 break;
479 480
@@ -484,22 +485,22 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
484 if (retval < 0) 485 if (retval < 0)
485 length = 0; 486 length = 0;
486 487
487 resp->InformationBufferLength = cpu_to_le32 (length); 488 resp->InformationBufferLength = cpu_to_le32(length);
488 r->length = length + sizeof *resp; 489 r->length = length + sizeof(*resp);
489 resp->MessageLength = cpu_to_le32 (r->length); 490 resp->MessageLength = cpu_to_le32(r->length);
490 return retval; 491 return retval;
491} 492}
492 493
493static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len, 494static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len,
494 rndis_resp_t *r) 495 rndis_resp_t *r)
495{ 496{
496 rndis_set_cmplt_type *resp; 497 rndis_set_cmplt_type *resp;
497 int i, retval = -ENOTSUPP; 498 int i, retval = -ENOTSUPP;
498 struct rndis_params *params; 499 struct rndis_params *params;
499 500
500 if (!r) 501 if (!r)
501 return -ENOMEM; 502 return -ENOMEM;
502 resp = (rndis_set_cmplt_type *) r->buf; 503 resp = (rndis_set_cmplt_type *)r->buf;
503 if (!resp) 504 if (!resp)
504 return -ENOMEM; 505 return -ENOMEM;
505 506
@@ -514,7 +515,7 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
514 } 515 }
515 } 516 }
516 517
517 params = &rndis_per_dev_params [configNr]; 518 params = &rndis_per_dev_params[configNr];
518 switch (OID) { 519 switch (OID) {
519 case OID_GEN_CURRENT_PACKET_FILTER: 520 case OID_GEN_CURRENT_PACKET_FILTER:
520 521
@@ -537,11 +538,11 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
537 params->state = RNDIS_DATA_INITIALIZED; 538 params->state = RNDIS_DATA_INITIALIZED;
538 netif_carrier_on(params->dev); 539 netif_carrier_on(params->dev);
539 if (netif_running(params->dev)) 540 if (netif_running(params->dev))
540 netif_wake_queue (params->dev); 541 netif_wake_queue(params->dev);
541 } else { 542 } else {
542 params->state = RNDIS_INITIALIZED; 543 params->state = RNDIS_INITIALIZED;
543 netif_carrier_off (params->dev); 544 netif_carrier_off(params->dev);
544 netif_stop_queue (params->dev); 545 netif_stop_queue(params->dev);
545 } 546 }
546 break; 547 break;
547 548
@@ -563,48 +564,47 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
563 * Response Functions 564 * Response Functions
564 */ 565 */
565 566
566static int rndis_init_response (int configNr, rndis_init_msg_type *buf) 567static int rndis_init_response(int configNr, rndis_init_msg_type *buf)
567{ 568{
568 rndis_init_cmplt_type *resp; 569 rndis_init_cmplt_type *resp;
569 rndis_resp_t *r; 570 rndis_resp_t *r;
570 struct rndis_params *params = rndis_per_dev_params + configNr; 571 struct rndis_params *params = rndis_per_dev_params + configNr;
571 572
572 if (!params->dev) 573 if (!params->dev)
573 return -ENOTSUPP; 574 return -ENOTSUPP;
574 575
575 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); 576 r = rndis_add_response(configNr, sizeof(rndis_init_cmplt_type));
576 if (!r) 577 if (!r)
577 return -ENOMEM; 578 return -ENOMEM;
578 resp = (rndis_init_cmplt_type *) r->buf; 579 resp = (rndis_init_cmplt_type *)r->buf;
579 580
580 resp->MessageType = cpu_to_le32 ( 581 resp->MessageType = cpu_to_le32(REMOTE_NDIS_INITIALIZE_CMPLT);
581 REMOTE_NDIS_INITIALIZE_CMPLT); 582 resp->MessageLength = cpu_to_le32(52);
582 resp->MessageLength = cpu_to_le32 (52);
583 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 583 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
584 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 584 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
585 resp->MajorVersion = cpu_to_le32 (RNDIS_MAJOR_VERSION); 585 resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION);
586 resp->MinorVersion = cpu_to_le32 (RNDIS_MINOR_VERSION); 586 resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION);
587 resp->DeviceFlags = cpu_to_le32 (RNDIS_DF_CONNECTIONLESS); 587 resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS);
588 resp->Medium = cpu_to_le32 (RNDIS_MEDIUM_802_3); 588 resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3);
589 resp->MaxPacketsPerTransfer = cpu_to_le32 (1); 589 resp->MaxPacketsPerTransfer = cpu_to_le32(1);
590 resp->MaxTransferSize = cpu_to_le32 ( 590 resp->MaxTransferSize = cpu_to_le32(
591 params->dev->mtu 591 params->dev->mtu
592 + sizeof (struct ethhdr) 592 + sizeof(struct ethhdr)
593 + sizeof (struct rndis_packet_msg_type) 593 + sizeof(struct rndis_packet_msg_type)
594 + 22); 594 + 22);
595 resp->PacketAlignmentFactor = cpu_to_le32 (0); 595 resp->PacketAlignmentFactor = cpu_to_le32(0);
596 resp->AFListOffset = cpu_to_le32 (0); 596 resp->AFListOffset = cpu_to_le32(0);
597 resp->AFListSize = cpu_to_le32 (0); 597 resp->AFListSize = cpu_to_le32(0);
598 598
599 params->resp_avail(params->v); 599 params->resp_avail(params->v);
600 return 0; 600 return 0;
601} 601}
602 602
603static int rndis_query_response (int configNr, rndis_query_msg_type *buf) 603static int rndis_query_response(int configNr, rndis_query_msg_type *buf)
604{ 604{
605 rndis_query_cmplt_type *resp; 605 rndis_query_cmplt_type *resp;
606 rndis_resp_t *r; 606 rndis_resp_t *r;
607 struct rndis_params *params = rndis_per_dev_params + configNr; 607 struct rndis_params *params = rndis_per_dev_params + configNr;
608 608
609 /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */ 609 /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */
610 if (!params->dev) 610 if (!params->dev)
@@ -616,47 +616,46 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
616 * rndis_query_cmplt_type followed by data. 616 * rndis_query_cmplt_type followed by data.
617 * oid_supported_list is the largest data reply 617 * oid_supported_list is the largest data reply
618 */ 618 */
619 r = rndis_add_response (configNr, 619 r = rndis_add_response(configNr,
620 sizeof (oid_supported_list) + sizeof(rndis_query_cmplt_type)); 620 sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type));
621 if (!r) 621 if (!r)
622 return -ENOMEM; 622 return -ENOMEM;
623 resp = (rndis_query_cmplt_type *) r->buf; 623 resp = (rndis_query_cmplt_type *)r->buf;
624 624
625 resp->MessageType = cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); 625 resp->MessageType = cpu_to_le32(REMOTE_NDIS_QUERY_CMPLT);
626 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 626 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
627 627
628 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), 628 if (gen_ndis_query_resp(configNr, le32_to_cpu(buf->OID),
629 le32_to_cpu(buf->InformationBufferOffset) 629 le32_to_cpu(buf->InformationBufferOffset)
630 + 8 + (u8 *) buf, 630 + 8 + (u8 *)buf,
631 le32_to_cpu(buf->InformationBufferLength), 631 le32_to_cpu(buf->InformationBufferLength),
632 r)) { 632 r)) {
633 /* OID not supported */ 633 /* OID not supported */
634 resp->Status = cpu_to_le32 ( 634 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
635 RNDIS_STATUS_NOT_SUPPORTED); 635 resp->MessageLength = cpu_to_le32(sizeof *resp);
636 resp->MessageLength = cpu_to_le32 (sizeof *resp); 636 resp->InformationBufferLength = cpu_to_le32(0);
637 resp->InformationBufferLength = cpu_to_le32 (0); 637 resp->InformationBufferOffset = cpu_to_le32(0);
638 resp->InformationBufferOffset = cpu_to_le32 (0);
639 } else 638 } else
640 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 639 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
641 640
642 params->resp_avail(params->v); 641 params->resp_avail(params->v);
643 return 0; 642 return 0;
644} 643}
645 644
646static int rndis_set_response (int configNr, rndis_set_msg_type *buf) 645static int rndis_set_response(int configNr, rndis_set_msg_type *buf)
647{ 646{
648 u32 BufLength, BufOffset; 647 u32 BufLength, BufOffset;
649 rndis_set_cmplt_type *resp; 648 rndis_set_cmplt_type *resp;
650 rndis_resp_t *r; 649 rndis_resp_t *r;
651 struct rndis_params *params = rndis_per_dev_params + configNr; 650 struct rndis_params *params = rndis_per_dev_params + configNr;
652 651
653 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); 652 r = rndis_add_response(configNr, sizeof(rndis_set_cmplt_type));
654 if (!r) 653 if (!r)
655 return -ENOMEM; 654 return -ENOMEM;
656 resp = (rndis_set_cmplt_type *) r->buf; 655 resp = (rndis_set_cmplt_type *)r->buf;
657 656
658 BufLength = le32_to_cpu (buf->InformationBufferLength); 657 BufLength = le32_to_cpu(buf->InformationBufferLength);
659 BufOffset = le32_to_cpu (buf->InformationBufferOffset); 658 BufOffset = le32_to_cpu(buf->InformationBufferOffset);
660 659
661#ifdef VERBOSE_DEBUG 660#ifdef VERBOSE_DEBUG
662 pr_debug("%s: Length: %d\n", __func__, BufLength); 661 pr_debug("%s: Length: %d\n", __func__, BufLength);
@@ -670,59 +669,59 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
670 pr_debug("\n"); 669 pr_debug("\n");
671#endif 670#endif
672 671
673 resp->MessageType = cpu_to_le32 (REMOTE_NDIS_SET_CMPLT); 672 resp->MessageType = cpu_to_le32(REMOTE_NDIS_SET_CMPLT);
674 resp->MessageLength = cpu_to_le32 (16); 673 resp->MessageLength = cpu_to_le32(16);
675 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 674 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
676 if (gen_ndis_set_resp (configNr, le32_to_cpu (buf->OID), 675 if (gen_ndis_set_resp(configNr, le32_to_cpu(buf->OID),
677 ((u8 *) buf) + 8 + BufOffset, BufLength, r)) 676 ((u8 *)buf) + 8 + BufOffset, BufLength, r))
678 resp->Status = cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED); 677 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
679 else 678 else
680 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 679 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
681 680
682 params->resp_avail(params->v); 681 params->resp_avail(params->v);
683 return 0; 682 return 0;
684} 683}
685 684
686static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf) 685static int rndis_reset_response(int configNr, rndis_reset_msg_type *buf)
687{ 686{
688 rndis_reset_cmplt_type *resp; 687 rndis_reset_cmplt_type *resp;
689 rndis_resp_t *r; 688 rndis_resp_t *r;
690 struct rndis_params *params = rndis_per_dev_params + configNr; 689 struct rndis_params *params = rndis_per_dev_params + configNr;
691 690
692 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); 691 r = rndis_add_response(configNr, sizeof(rndis_reset_cmplt_type));
693 if (!r) 692 if (!r)
694 return -ENOMEM; 693 return -ENOMEM;
695 resp = (rndis_reset_cmplt_type *) r->buf; 694 resp = (rndis_reset_cmplt_type *)r->buf;
696 695
697 resp->MessageType = cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); 696 resp->MessageType = cpu_to_le32(REMOTE_NDIS_RESET_CMPLT);
698 resp->MessageLength = cpu_to_le32 (16); 697 resp->MessageLength = cpu_to_le32(16);
699 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 698 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
700 /* resent information */ 699 /* resent information */
701 resp->AddressingReset = cpu_to_le32 (1); 700 resp->AddressingReset = cpu_to_le32(1);
702 701
703 params->resp_avail(params->v); 702 params->resp_avail(params->v);
704 return 0; 703 return 0;
705} 704}
706 705
707static int rndis_keepalive_response (int configNr, 706static int rndis_keepalive_response(int configNr,
708 rndis_keepalive_msg_type *buf) 707 rndis_keepalive_msg_type *buf)
709{ 708{
710 rndis_keepalive_cmplt_type *resp; 709 rndis_keepalive_cmplt_type *resp;
711 rndis_resp_t *r; 710 rndis_resp_t *r;
712 struct rndis_params *params = rndis_per_dev_params + configNr; 711 struct rndis_params *params = rndis_per_dev_params + configNr;
713 712
714 /* host "should" check only in RNDIS_DATA_INITIALIZED state */ 713 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
715 714
716 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type)); 715 r = rndis_add_response(configNr, sizeof(rndis_keepalive_cmplt_type));
717 if (!r) 716 if (!r)
718 return -ENOMEM; 717 return -ENOMEM;
719 resp = (rndis_keepalive_cmplt_type *) r->buf; 718 resp = (rndis_keepalive_cmplt_type *)r->buf;
720 719
721 resp->MessageType = cpu_to_le32 ( 720 resp->MessageType = cpu_to_le32(
722 REMOTE_NDIS_KEEPALIVE_CMPLT); 721 REMOTE_NDIS_KEEPALIVE_CMPLT);
723 resp->MessageLength = cpu_to_le32 (16); 722 resp->MessageLength = cpu_to_le32(16);
724 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 723 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
725 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 724 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
726 725
727 params->resp_avail(params->v); 726 params->resp_avail(params->v);
728 return 0; 727 return 0;
@@ -732,86 +731,85 @@ static int rndis_keepalive_response (int configNr,
732/* 731/*
733 * Device to Host Comunication 732 * Device to Host Comunication
734 */ 733 */
735static int rndis_indicate_status_msg (int configNr, u32 status) 734static int rndis_indicate_status_msg(int configNr, u32 status)
736{ 735{
737 rndis_indicate_status_msg_type *resp; 736 rndis_indicate_status_msg_type *resp;
738 rndis_resp_t *r; 737 rndis_resp_t *r;
739 struct rndis_params *params = rndis_per_dev_params + configNr; 738 struct rndis_params *params = rndis_per_dev_params + configNr;
740 739
741 if (params->state == RNDIS_UNINITIALIZED) 740 if (params->state == RNDIS_UNINITIALIZED)
742 return -ENOTSUPP; 741 return -ENOTSUPP;
743 742
744 r = rndis_add_response (configNr, 743 r = rndis_add_response(configNr,
745 sizeof (rndis_indicate_status_msg_type)); 744 sizeof(rndis_indicate_status_msg_type));
746 if (!r) 745 if (!r)
747 return -ENOMEM; 746 return -ENOMEM;
748 resp = (rndis_indicate_status_msg_type *) r->buf; 747 resp = (rndis_indicate_status_msg_type *)r->buf;
749 748
750 resp->MessageType = cpu_to_le32 ( 749 resp->MessageType = cpu_to_le32(REMOTE_NDIS_INDICATE_STATUS_MSG);
751 REMOTE_NDIS_INDICATE_STATUS_MSG); 750 resp->MessageLength = cpu_to_le32(20);
752 resp->MessageLength = cpu_to_le32 (20); 751 resp->Status = cpu_to_le32(status);
753 resp->Status = cpu_to_le32 (status); 752 resp->StatusBufferLength = cpu_to_le32(0);
754 resp->StatusBufferLength = cpu_to_le32 (0); 753 resp->StatusBufferOffset = cpu_to_le32(0);
755 resp->StatusBufferOffset = cpu_to_le32 (0);
756 754
757 params->resp_avail(params->v); 755 params->resp_avail(params->v);
758 return 0; 756 return 0;
759} 757}
760 758
761int rndis_signal_connect (int configNr) 759int rndis_signal_connect(int configNr)
762{ 760{
763 rndis_per_dev_params [configNr].media_state 761 rndis_per_dev_params[configNr].media_state
764 = NDIS_MEDIA_STATE_CONNECTED; 762 = NDIS_MEDIA_STATE_CONNECTED;
765 return rndis_indicate_status_msg (configNr, 763 return rndis_indicate_status_msg(configNr,
766 RNDIS_STATUS_MEDIA_CONNECT); 764 RNDIS_STATUS_MEDIA_CONNECT);
767} 765}
768 766
769int rndis_signal_disconnect (int configNr) 767int rndis_signal_disconnect(int configNr)
770{ 768{
771 rndis_per_dev_params [configNr].media_state 769 rndis_per_dev_params[configNr].media_state
772 = NDIS_MEDIA_STATE_DISCONNECTED; 770 = NDIS_MEDIA_STATE_DISCONNECTED;
773 return rndis_indicate_status_msg (configNr, 771 return rndis_indicate_status_msg(configNr,
774 RNDIS_STATUS_MEDIA_DISCONNECT); 772 RNDIS_STATUS_MEDIA_DISCONNECT);
775} 773}
776 774
777void rndis_uninit (int configNr) 775void rndis_uninit(int configNr)
778{ 776{
779 u8 *buf; 777 u8 *buf;
780 u32 length; 778 u32 length;
781 779
782 if (configNr >= RNDIS_MAX_CONFIGS) 780 if (configNr >= RNDIS_MAX_CONFIGS)
783 return; 781 return;
784 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED; 782 rndis_per_dev_params[configNr].state = RNDIS_UNINITIALIZED;
785 783
786 /* drain the response queue */ 784 /* drain the response queue */
787 while ((buf = rndis_get_next_response(configNr, &length))) 785 while ((buf = rndis_get_next_response(configNr, &length)))
788 rndis_free_response(configNr, buf); 786 rndis_free_response(configNr, buf);
789} 787}
790 788
791void rndis_set_host_mac (int configNr, const u8 *addr) 789void rndis_set_host_mac(int configNr, const u8 *addr)
792{ 790{
793 rndis_per_dev_params [configNr].host_mac = addr; 791 rndis_per_dev_params[configNr].host_mac = addr;
794} 792}
795 793
796/* 794/*
797 * Message Parser 795 * Message Parser
798 */ 796 */
799int rndis_msg_parser (u8 configNr, u8 *buf) 797int rndis_msg_parser(u8 configNr, u8 *buf)
800{ 798{
801 u32 MsgType, MsgLength; 799 u32 MsgType, MsgLength;
802 __le32 *tmp; 800 __le32 *tmp;
803 struct rndis_params *params; 801 struct rndis_params *params;
804 802
805 if (!buf) 803 if (!buf)
806 return -ENOMEM; 804 return -ENOMEM;
807 805
808 tmp = (__le32 *) buf; 806 tmp = (__le32 *)buf;
809 MsgType = get_unaligned_le32(tmp++); 807 MsgType = get_unaligned_le32(tmp++);
810 MsgLength = get_unaligned_le32(tmp++); 808 MsgLength = get_unaligned_le32(tmp++);
811 809
812 if (configNr >= RNDIS_MAX_CONFIGS) 810 if (configNr >= RNDIS_MAX_CONFIGS)
813 return -ENOTSUPP; 811 return -ENOTSUPP;
814 params = &rndis_per_dev_params [configNr]; 812 params = &rndis_per_dev_params[configNr];
815 813
816 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for 814 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
817 * rx/tx statistics and link status, in addition to KEEPALIVE traffic 815 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
@@ -822,41 +820,41 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
822 switch (MsgType) { 820 switch (MsgType) {
823 case REMOTE_NDIS_INITIALIZE_MSG: 821 case REMOTE_NDIS_INITIALIZE_MSG:
824 pr_debug("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 822 pr_debug("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
825 __func__ ); 823 __func__);
826 params->state = RNDIS_INITIALIZED; 824 params->state = RNDIS_INITIALIZED;
827 return rndis_init_response (configNr, 825 return rndis_init_response(configNr,
828 (rndis_init_msg_type *) buf); 826 (rndis_init_msg_type *)buf);
829 827
830 case REMOTE_NDIS_HALT_MSG: 828 case REMOTE_NDIS_HALT_MSG:
831 pr_debug("%s: REMOTE_NDIS_HALT_MSG\n", 829 pr_debug("%s: REMOTE_NDIS_HALT_MSG\n",
832 __func__ ); 830 __func__);
833 params->state = RNDIS_UNINITIALIZED; 831 params->state = RNDIS_UNINITIALIZED;
834 if (params->dev) { 832 if (params->dev) {
835 netif_carrier_off (params->dev); 833 netif_carrier_off(params->dev);
836 netif_stop_queue (params->dev); 834 netif_stop_queue(params->dev);
837 } 835 }
838 return 0; 836 return 0;
839 837
840 case REMOTE_NDIS_QUERY_MSG: 838 case REMOTE_NDIS_QUERY_MSG:
841 return rndis_query_response (configNr, 839 return rndis_query_response(configNr,
842 (rndis_query_msg_type *) buf); 840 (rndis_query_msg_type *)buf);
843 841
844 case REMOTE_NDIS_SET_MSG: 842 case REMOTE_NDIS_SET_MSG:
845 return rndis_set_response (configNr, 843 return rndis_set_response(configNr,
846 (rndis_set_msg_type *) buf); 844 (rndis_set_msg_type *)buf);
847 845
848 case REMOTE_NDIS_RESET_MSG: 846 case REMOTE_NDIS_RESET_MSG:
849 pr_debug("%s: REMOTE_NDIS_RESET_MSG\n", 847 pr_debug("%s: REMOTE_NDIS_RESET_MSG\n",
850 __func__ ); 848 __func__);
851 return rndis_reset_response (configNr, 849 return rndis_reset_response(configNr,
852 (rndis_reset_msg_type *) buf); 850 (rndis_reset_msg_type *)buf);
853 851
854 case REMOTE_NDIS_KEEPALIVE_MSG: 852 case REMOTE_NDIS_KEEPALIVE_MSG:
855 /* For USB: host does this every 5 seconds */ 853 /* For USB: host does this every 5 seconds */
856 if (rndis_debug > 1) 854 if (rndis_debug > 1)
857 pr_debug("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 855 pr_debug("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
858 __func__ ); 856 __func__);
859 return rndis_keepalive_response (configNr, 857 return rndis_keepalive_response(configNr,
860 (rndis_keepalive_msg_type *) 858 (rndis_keepalive_msg_type *)
861 buf); 859 buf);
862 860
@@ -866,7 +864,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
866 * suspending itself. 864 * suspending itself.
867 */ 865 */
868 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n", 866 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
869 __func__ , MsgType, MsgLength); 867 __func__, MsgType, MsgLength);
870 { 868 {
871 unsigned i; 869 unsigned i;
872 for (i = 0; i < MsgLength; i += 16) { 870 for (i = 0; i < MsgLength; i += 16) {
@@ -901,10 +899,10 @@ int rndis_register(void (*resp_avail)(void *v), void *v)
901 return -EINVAL; 899 return -EINVAL;
902 900
903 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { 901 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
904 if (!rndis_per_dev_params [i].used) { 902 if (!rndis_per_dev_params[i].used) {
905 rndis_per_dev_params [i].used = 1; 903 rndis_per_dev_params[i].used = 1;
906 rndis_per_dev_params [i].resp_avail = resp_avail; 904 rndis_per_dev_params[i].resp_avail = resp_avail;
907 rndis_per_dev_params [i].v = v; 905 rndis_per_dev_params[i].v = v;
908 pr_debug("%s: configNr = %d\n", __func__, i); 906 pr_debug("%s: configNr = %d\n", __func__, i);
909 return i; 907 return i;
910 } 908 }
@@ -914,14 +912,12 @@ int rndis_register(void (*resp_avail)(void *v), void *v)
914 return -ENODEV; 912 return -ENODEV;
915} 913}
916 914
917void rndis_deregister (int configNr) 915void rndis_deregister(int configNr)
918{ 916{
919 pr_debug("%s: \n", __func__); 917 pr_debug("%s:\n", __func__);
920 918
921 if (configNr >= RNDIS_MAX_CONFIGS) return; 919 if (configNr >= RNDIS_MAX_CONFIGS) return;
922 rndis_per_dev_params [configNr].used = 0; 920 rndis_per_dev_params[configNr].used = 0;
923
924 return;
925} 921}
926 922
927int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) 923int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter)
@@ -931,76 +927,76 @@ int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter)
931 return -EINVAL; 927 return -EINVAL;
932 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 928 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
933 929
934 rndis_per_dev_params [configNr].dev = dev; 930 rndis_per_dev_params[configNr].dev = dev;
935 rndis_per_dev_params [configNr].filter = cdc_filter; 931 rndis_per_dev_params[configNr].filter = cdc_filter;
936 932
937 return 0; 933 return 0;
938} 934}
939 935
940int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) 936int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr)
941{ 937{
942 pr_debug("%s:\n", __func__); 938 pr_debug("%s:\n", __func__);
943 if (!vendorDescr) return -1; 939 if (!vendorDescr) return -1;
944 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 940 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
945 941
946 rndis_per_dev_params [configNr].vendorID = vendorID; 942 rndis_per_dev_params[configNr].vendorID = vendorID;
947 rndis_per_dev_params [configNr].vendorDescr = vendorDescr; 943 rndis_per_dev_params[configNr].vendorDescr = vendorDescr;
948 944
949 return 0; 945 return 0;
950} 946}
951 947
952int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 948int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed)
953{ 949{
954 pr_debug("%s: %u %u\n", __func__, medium, speed); 950 pr_debug("%s: %u %u\n", __func__, medium, speed);
955 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 951 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
956 952
957 rndis_per_dev_params [configNr].medium = medium; 953 rndis_per_dev_params[configNr].medium = medium;
958 rndis_per_dev_params [configNr].speed = speed; 954 rndis_per_dev_params[configNr].speed = speed;
959 955
960 return 0; 956 return 0;
961} 957}
962 958
963void rndis_add_hdr (struct sk_buff *skb) 959void rndis_add_hdr(struct sk_buff *skb)
964{ 960{
965 struct rndis_packet_msg_type *header; 961 struct rndis_packet_msg_type *header;
966 962
967 if (!skb) 963 if (!skb)
968 return; 964 return;
969 header = (void *) skb_push (skb, sizeof *header); 965 header = (void *)skb_push(skb, sizeof(*header));
970 memset (header, 0, sizeof *header); 966 memset(header, 0, sizeof *header);
971 header->MessageType = cpu_to_le32(REMOTE_NDIS_PACKET_MSG); 967 header->MessageType = cpu_to_le32(REMOTE_NDIS_PACKET_MSG);
972 header->MessageLength = cpu_to_le32(skb->len); 968 header->MessageLength = cpu_to_le32(skb->len);
973 header->DataOffset = cpu_to_le32 (36); 969 header->DataOffset = cpu_to_le32(36);
974 header->DataLength = cpu_to_le32(skb->len - sizeof *header); 970 header->DataLength = cpu_to_le32(skb->len - sizeof(*header));
975} 971}
976 972
977void rndis_free_response (int configNr, u8 *buf) 973void rndis_free_response(int configNr, u8 *buf)
978{ 974{
979 rndis_resp_t *r; 975 rndis_resp_t *r;
980 struct list_head *act, *tmp; 976 struct list_head *act, *tmp;
981 977
982 list_for_each_safe (act, tmp, 978 list_for_each_safe(act, tmp,
983 &(rndis_per_dev_params [configNr].resp_queue)) 979 &(rndis_per_dev_params[configNr].resp_queue))
984 { 980 {
985 r = list_entry (act, rndis_resp_t, list); 981 r = list_entry(act, rndis_resp_t, list);
986 if (r && r->buf == buf) { 982 if (r && r->buf == buf) {
987 list_del (&r->list); 983 list_del(&r->list);
988 kfree (r); 984 kfree(r);
989 } 985 }
990 } 986 }
991} 987}
992 988
993u8 *rndis_get_next_response (int configNr, u32 *length) 989u8 *rndis_get_next_response(int configNr, u32 *length)
994{ 990{
995 rndis_resp_t *r; 991 rndis_resp_t *r;
996 struct list_head *act, *tmp; 992 struct list_head *act, *tmp;
997 993
998 if (!length) return NULL; 994 if (!length) return NULL;
999 995
1000 list_for_each_safe (act, tmp, 996 list_for_each_safe(act, tmp,
1001 &(rndis_per_dev_params [configNr].resp_queue)) 997 &(rndis_per_dev_params[configNr].resp_queue))
1002 { 998 {
1003 r = list_entry (act, rndis_resp_t, list); 999 r = list_entry(act, rndis_resp_t, list);
1004 if (!r->send) { 1000 if (!r->send) {
1005 r->send = 1; 1001 r->send = 1;
1006 *length = r->length; 1002 *length = r->length;
@@ -1011,20 +1007,20 @@ u8 *rndis_get_next_response (int configNr, u32 *length)
1011 return NULL; 1007 return NULL;
1012} 1008}
1013 1009
1014static rndis_resp_t *rndis_add_response (int configNr, u32 length) 1010static rndis_resp_t *rndis_add_response(int configNr, u32 length)
1015{ 1011{
1016 rndis_resp_t *r; 1012 rndis_resp_t *r;
1017 1013
1018 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */ 1014 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1019 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC); 1015 r = kmalloc(sizeof(rndis_resp_t) + length, GFP_ATOMIC);
1020 if (!r) return NULL; 1016 if (!r) return NULL;
1021 1017
1022 r->buf = (u8 *) (r + 1); 1018 r->buf = (u8 *)(r + 1);
1023 r->length = length; 1019 r->length = length;
1024 r->send = 0; 1020 r->send = 0;
1025 1021
1026 list_add_tail (&r->list, 1022 list_add_tail(&r->list,
1027 &(rndis_per_dev_params [configNr].resp_queue)); 1023 &(rndis_per_dev_params[configNr].resp_queue));
1028 return r; 1024 return r;
1029} 1025}
1030 1026
@@ -1033,7 +1029,7 @@ int rndis_rm_hdr(struct gether *port,
1033 struct sk_buff_head *list) 1029 struct sk_buff_head *list)
1034{ 1030{
1035 /* tmp points to a struct rndis_packet_msg_type */ 1031 /* tmp points to a struct rndis_packet_msg_type */
1036 __le32 *tmp = (void *) skb->data; 1032 __le32 *tmp = (void *)skb->data;
1037 1033
1038 /* MessageType, MessageLength */ 1034 /* MessageType, MessageLength */
1039 if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG) 1035 if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG)
@@ -1054,7 +1050,7 @@ int rndis_rm_hdr(struct gether *port,
1054 return 0; 1050 return 0;
1055} 1051}
1056 1052
1057#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1053#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1058 1054
1059static int rndis_proc_show(struct seq_file *m, void *v) 1055static int rndis_proc_show(struct seq_file *m, void *v)
1060{ 1056{
@@ -1087,7 +1083,7 @@ static int rndis_proc_show(struct seq_file *m, void *v)
1087} 1083}
1088 1084
1089static ssize_t rndis_proc_write(struct file *file, const char __user *buffer, 1085static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
1090 size_t count, loff_t *ppos) 1086 size_t count, loff_t *ppos)
1091{ 1087{
1092 rndis_params *p = PDE(file->f_path.dentry->d_inode)->data; 1088 rndis_params *p = PDE(file->f_path.dentry->d_inode)->data;
1093 u32 speed = 0; 1089 u32 speed = 0;
@@ -1109,11 +1105,11 @@ static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
1109 case '8': 1105 case '8':
1110 case '9': 1106 case '9':
1111 fl_speed = 1; 1107 fl_speed = 1;
1112 speed = speed*10 + c - '0'; 1108 speed = speed * 10 + c - '0';
1113 break; 1109 break;
1114 case 'C': 1110 case 'C':
1115 case 'c': 1111 case 'c':
1116 rndis_signal_connect (p->confignr); 1112 rndis_signal_connect(p->confignr);
1117 break; 1113 break;
1118 case 'D': 1114 case 'D':
1119 case 'd': 1115 case 'd':
@@ -1145,11 +1141,11 @@ static const struct file_operations rndis_proc_fops = {
1145 .write = rndis_proc_write, 1141 .write = rndis_proc_write,
1146}; 1142};
1147 1143
1148#define NAME_TEMPLATE "driver/rndis-%03d" 1144#define NAME_TEMPLATE "driver/rndis-%03d"
1149 1145
1150static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS]; 1146static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1151 1147
1152#endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1148#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1153 1149
1154 1150
1155int rndis_init(void) 1151int rndis_init(void)
@@ -1160,42 +1156,40 @@ int rndis_init(void)
1160#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1156#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1161 char name [20]; 1157 char name [20];
1162 1158
1163 sprintf (name, NAME_TEMPLATE, i); 1159 sprintf(name, NAME_TEMPLATE, i);
1164 if (!(rndis_connect_state [i] 1160 rndis_connect_state[i] = proc_create_data(name, 0660, NULL,
1165 = proc_create_data(name, 0660, NULL,
1166 &rndis_proc_fops, 1161 &rndis_proc_fops,
1167 (void *)(rndis_per_dev_params + i)))) 1162 (void *)(rndis_per_dev_params + i));
1168 { 1163 if (!rndis_connect_state[i]) {
1169 pr_debug("%s :remove entries", __func__); 1164 pr_debug("%s: remove entries", __func__);
1170 while (i) { 1165 while (i) {
1171 sprintf (name, NAME_TEMPLATE, --i); 1166 sprintf(name, NAME_TEMPLATE, --i);
1172 remove_proc_entry (name, NULL); 1167 remove_proc_entry(name, NULL);
1173 } 1168 }
1174 pr_debug("\n"); 1169 pr_debug("\n");
1175 return -EIO; 1170 return -EIO;
1176 } 1171 }
1177#endif 1172#endif
1178 rndis_per_dev_params [i].confignr = i; 1173 rndis_per_dev_params[i].confignr = i;
1179 rndis_per_dev_params [i].used = 0; 1174 rndis_per_dev_params[i].used = 0;
1180 rndis_per_dev_params [i].state = RNDIS_UNINITIALIZED; 1175 rndis_per_dev_params[i].state = RNDIS_UNINITIALIZED;
1181 rndis_per_dev_params [i].media_state 1176 rndis_per_dev_params[i].media_state
1182 = NDIS_MEDIA_STATE_DISCONNECTED; 1177 = NDIS_MEDIA_STATE_DISCONNECTED;
1183 INIT_LIST_HEAD (&(rndis_per_dev_params [i].resp_queue)); 1178 INIT_LIST_HEAD(&(rndis_per_dev_params[i].resp_queue));
1184 } 1179 }
1185 1180
1186 return 0; 1181 return 0;
1187} 1182}
1188 1183
1189void rndis_exit (void) 1184void rndis_exit(void)
1190{ 1185{
1191#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1186#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1192 u8 i; 1187 u8 i;
1193 char name [20]; 1188 char name[20];
1194 1189
1195 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { 1190 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1196 sprintf (name, NAME_TEMPLATE, i); 1191 sprintf(name, NAME_TEMPLATE, i);
1197 remove_proc_entry (name, NULL); 1192 remove_proc_entry(name, NULL);
1198 } 1193 }
1199#endif 1194#endif
1200} 1195}
1201
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index a229744a8c7d..0dfee282878a 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -1,5 +1,8 @@
1/* linux/drivers/usb/gadget/s3c-hsotg.c 1/* linux/drivers/usb/gadget/s3c-hsotg.c
2 * 2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
3 * Copyright 2008 Openmoko, Inc. 6 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics 7 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk> 8 * Ben Dooks <ben@simtec.co.uk>
@@ -41,8 +44,8 @@
41/* EP0_MPS_LIMIT 44/* EP0_MPS_LIMIT
42 * 45 *
43 * Unfortunately there seems to be a limit of the amount of data that can 46 * Unfortunately there seems to be a limit of the amount of data that can
44 * be transfered by IN transactions on EP0. This is either 127 bytes or 3 47 * be transferred by IN transactions on EP0. This is either 127 bytes or 3
45 * packets (which practially means 1 packet and 63 bytes of data) when the 48 * packets (which practically means 1 packet and 63 bytes of data) when the
46 * MPS is set to 64. 49 * MPS is set to 64.
47 * 50 *
48 * This means if we are wanting to move >127 bytes of data, we need to 51 * This means if we are wanting to move >127 bytes of data, we need to
@@ -613,11 +616,10 @@ static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep)
613 maxpkt = S3C_DxEPTSIZ_PktCnt_LIMIT + 1; 616 maxpkt = S3C_DxEPTSIZ_PktCnt_LIMIT + 1;
614 } else { 617 } else {
615 maxsize = 64+64; 618 maxsize = 64+64;
616 if (hs_ep->dir_in) { 619 if (hs_ep->dir_in)
617 maxpkt = S3C_DIEPTSIZ0_PktCnt_LIMIT + 1; 620 maxpkt = S3C_DIEPTSIZ0_PktCnt_LIMIT + 1;
618 } else { 621 else
619 maxpkt = 2; 622 maxpkt = 2;
620 }
621 } 623 }
622 624
623 /* we made the constant loading easier above by using +1 */ 625 /* we made the constant loading easier above by using +1 */
@@ -679,6 +681,14 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
679 __func__, readl(hsotg->regs + epctrl_reg), index, 681 __func__, readl(hsotg->regs + epctrl_reg), index,
680 hs_ep->dir_in ? "in" : "out"); 682 hs_ep->dir_in ? "in" : "out");
681 683
684 /* If endpoint is stalled, we will restart request later */
685 ctrl = readl(hsotg->regs + epctrl_reg);
686
687 if (ctrl & S3C_DxEPCTL_Stall) {
688 dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index);
689 return;
690 }
691
682 length = ureq->length - ureq->actual; 692 length = ureq->length - ureq->actual;
683 693
684 if (0) 694 if (0)
@@ -731,18 +741,6 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
731 /* write size / packets */ 741 /* write size / packets */
732 writel(epsize, hsotg->regs + epsize_reg); 742 writel(epsize, hsotg->regs + epsize_reg);
733 743
734 ctrl = readl(hsotg->regs + epctrl_reg);
735
736 if (ctrl & S3C_DxEPCTL_Stall) {
737 dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index);
738
739 /* not sure what we can do here, if it is EP0 then we should
740 * get this cleared once the endpoint has transmitted the
741 * STALL packet, otherwise it needs to be cleared by the
742 * host.
743 */
744 }
745
746 if (using_dma(hsotg)) { 744 if (using_dma(hsotg)) {
747 unsigned int dma_reg; 745 unsigned int dma_reg;
748 746
@@ -783,7 +781,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
783 hsotg->regs + S3C_DIEPINT(index)); 781 hsotg->regs + S3C_DIEPINT(index));
784 782
785 /* Note, trying to clear the NAK here causes problems with transmit 783 /* Note, trying to clear the NAK here causes problems with transmit
786 * on the S3C6400 ending up with the TXFIFO becomming full. */ 784 * on the S3C6400 ending up with the TXFIFO becoming full. */
787 785
788 /* check ep is enabled */ 786 /* check ep is enabled */
789 if (!(readl(hsotg->regs + epctrl_reg) & S3C_DxEPCTL_EPEna)) 787 if (!(readl(hsotg->regs + epctrl_reg) & S3C_DxEPCTL_EPEna))
@@ -1048,6 +1046,20 @@ static int s3c_hsotg_process_req_status(struct s3c_hsotg *hsotg,
1048static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value); 1046static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value);
1049 1047
1050/** 1048/**
1049 * get_ep_head - return the first request on the endpoint
1050 * @hs_ep: The controller endpoint to get
1051 *
1052 * Get the first request on the endpoint.
1053 */
1054static struct s3c_hsotg_req *get_ep_head(struct s3c_hsotg_ep *hs_ep)
1055{
1056 if (list_empty(&hs_ep->queue))
1057 return NULL;
1058
1059 return list_first_entry(&hs_ep->queue, struct s3c_hsotg_req, queue);
1060}
1061
1062/**
1051 * s3c_hsotg_process_req_featire - process request {SET,CLEAR}_FEATURE 1063 * s3c_hsotg_process_req_featire - process request {SET,CLEAR}_FEATURE
1052 * @hsotg: The device state 1064 * @hsotg: The device state
1053 * @ctrl: USB control request 1065 * @ctrl: USB control request
@@ -1055,8 +1067,12 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value);
1055static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, 1067static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1056 struct usb_ctrlrequest *ctrl) 1068 struct usb_ctrlrequest *ctrl)
1057{ 1069{
1070 struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
1071 struct s3c_hsotg_req *hs_req;
1072 bool restart;
1058 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); 1073 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE);
1059 struct s3c_hsotg_ep *ep; 1074 struct s3c_hsotg_ep *ep;
1075 int ret;
1060 1076
1061 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", 1077 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n",
1062 __func__, set ? "SET" : "CLEAR"); 1078 __func__, set ? "SET" : "CLEAR");
@@ -1072,6 +1088,36 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1072 switch (le16_to_cpu(ctrl->wValue)) { 1088 switch (le16_to_cpu(ctrl->wValue)) {
1073 case USB_ENDPOINT_HALT: 1089 case USB_ENDPOINT_HALT:
1074 s3c_hsotg_ep_sethalt(&ep->ep, set); 1090 s3c_hsotg_ep_sethalt(&ep->ep, set);
1091
1092 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0);
1093 if (ret) {
1094 dev_err(hsotg->dev,
1095 "%s: failed to send reply\n", __func__);
1096 return ret;
1097 }
1098
1099 if (!set) {
1100 /*
1101 * If we have request in progress,
1102 * then complete it
1103 */
1104 if (ep->req) {
1105 hs_req = ep->req;
1106 ep->req = NULL;
1107 list_del_init(&hs_req->queue);
1108 hs_req->req.complete(&ep->ep,
1109 &hs_req->req);
1110 }
1111
1112 /* If we have pending request, then start it */
1113 restart = !list_empty(&ep->queue);
1114 if (restart) {
1115 hs_req = get_ep_head(ep);
1116 s3c_hsotg_start_req(hsotg, ep,
1117 hs_req, false);
1118 }
1119 }
1120
1075 break; 1121 break;
1076 1122
1077 default: 1123 default:
@@ -1148,14 +1194,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,
1148 dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); 1194 dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret);
1149 } 1195 }
1150 1196
1151 if (ret > 0) {
1152 if (!ep0->dir_in) {
1153 /* need to generate zlp in reply or take data */
1154 /* todo - deal with any data we might be sent? */
1155 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0);
1156 }
1157 }
1158
1159 /* the request is either unhandlable, or is not formatted correctly 1197 /* the request is either unhandlable, or is not formatted correctly
1160 * so respond with a STALL for the status stage to indicate failure. 1198 * so respond with a STALL for the status stage to indicate failure.
1161 */ 1199 */
@@ -1176,10 +1214,10 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,
1176 writel(ctrl, hsotg->regs + reg); 1214 writel(ctrl, hsotg->regs + reg);
1177 1215
1178 dev_dbg(hsotg->dev, 1216 dev_dbg(hsotg->dev,
1179 "writen DxEPCTL=0x%08x to %08x (DxEPCTL=0x%08x)\n", 1217 "written DxEPCTL=0x%08x to %08x (DxEPCTL=0x%08x)\n",
1180 ctrl, reg, readl(hsotg->regs + reg)); 1218 ctrl, reg, readl(hsotg->regs + reg));
1181 1219
1182 /* don't belive we need to anything more to get the EP 1220 /* don't believe we need to anything more to get the EP
1183 * to reply with a STALL packet */ 1221 * to reply with a STALL packet */
1184 } 1222 }
1185} 1223}
@@ -1247,20 +1285,6 @@ static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg)
1247} 1285}
1248 1286
1249/** 1287/**
1250 * get_ep_head - return the first request on the endpoint
1251 * @hs_ep: The controller endpoint to get
1252 *
1253 * Get the first request on the endpoint.
1254*/
1255static struct s3c_hsotg_req *get_ep_head(struct s3c_hsotg_ep *hs_ep)
1256{
1257 if (list_empty(&hs_ep->queue))
1258 return NULL;
1259
1260 return list_first_entry(&hs_ep->queue, struct s3c_hsotg_req, queue);
1261}
1262
1263/**
1264 * s3c_hsotg_complete_request - complete a request given to us 1288 * s3c_hsotg_complete_request - complete a request given to us
1265 * @hsotg: The device state. 1289 * @hsotg: The device state.
1266 * @hs_ep: The endpoint the request was on. 1290 * @hs_ep: The endpoint the request was on.
@@ -1416,7 +1440,7 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size)
1416 * transaction. 1440 * transaction.
1417 * 1441 *
1418 * Note, since we don't write any data to the TxFIFO, then it is 1442 * Note, since we don't write any data to the TxFIFO, then it is
1419 * currently belived that we do not need to wait for any space in 1443 * currently believed that we do not need to wait for any space in
1420 * the TxFIFO. 1444 * the TxFIFO.
1421 */ 1445 */
1422static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, 1446static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg,
@@ -1540,7 +1564,7 @@ static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg)
1540 * that requires processing, so find out what is in there and do the 1564 * that requires processing, so find out what is in there and do the
1541 * appropriate read. 1565 * appropriate read.
1542 * 1566 *
1543 * The RXFIFO is a true FIFO, the packets comming out are still in packet 1567 * The RXFIFO is a true FIFO, the packets coming out are still in packet
1544 * chunks, so if you have x packets received on an endpoint you'll get x 1568 * chunks, so if you have x packets received on an endpoint you'll get x
1545 * FIFO events delivered, each with a packet's worth of data in it. 1569 * FIFO events delivered, each with a packet's worth of data in it.
1546 * 1570 *
@@ -1683,6 +1707,37 @@ bad_mps:
1683 dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps); 1707 dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps);
1684} 1708}
1685 1709
1710/**
1711 * s3c_hsotg_txfifo_flush - flush Tx FIFO
1712 * @hsotg: The driver state
1713 * @idx: The index for the endpoint (0..15)
1714 */
1715static void s3c_hsotg_txfifo_flush(struct s3c_hsotg *hsotg, unsigned int idx)
1716{
1717 int timeout;
1718 int val;
1719
1720 writel(S3C_GRSTCTL_TxFNum(idx) | S3C_GRSTCTL_TxFFlsh,
1721 hsotg->regs + S3C_GRSTCTL);
1722
1723 /* wait until the fifo is flushed */
1724 timeout = 100;
1725
1726 while (1) {
1727 val = readl(hsotg->regs + S3C_GRSTCTL);
1728
1729 if ((val & (S3C_GRSTCTL_TxFFlsh)) == 0)
1730 break;
1731
1732 if (--timeout == 0) {
1733 dev_err(hsotg->dev,
1734 "%s: timeout flushing fifo (GRSTCTL=%08x)\n",
1735 __func__, val);
1736 }
1737
1738 udelay(1);
1739 }
1740}
1686 1741
1687/** 1742/**
1688 * s3c_hsotg_trytx - check to see if anything needs transmitting 1743 * s3c_hsotg_trytx - check to see if anything needs transmitting
@@ -1775,10 +1830,12 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1775 u32 epctl_reg = dir_in ? S3C_DIEPCTL(idx) : S3C_DOEPCTL(idx); 1830 u32 epctl_reg = dir_in ? S3C_DIEPCTL(idx) : S3C_DOEPCTL(idx);
1776 u32 epsiz_reg = dir_in ? S3C_DIEPTSIZ(idx) : S3C_DOEPTSIZ(idx); 1831 u32 epsiz_reg = dir_in ? S3C_DIEPTSIZ(idx) : S3C_DOEPTSIZ(idx);
1777 u32 ints; 1832 u32 ints;
1778 u32 clear = 0;
1779 1833
1780 ints = readl(hsotg->regs + epint_reg); 1834 ints = readl(hsotg->regs + epint_reg);
1781 1835
1836 /* Clear endpoint interrupts */
1837 writel(ints, hsotg->regs + epint_reg);
1838
1782 dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", 1839 dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n",
1783 __func__, idx, dir_in ? "in" : "out", ints); 1840 __func__, idx, dir_in ? "in" : "out", ints);
1784 1841
@@ -1801,19 +1858,28 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1801 1858
1802 s3c_hsotg_handle_outdone(hsotg, idx, false); 1859 s3c_hsotg_handle_outdone(hsotg, idx, false);
1803 } 1860 }
1804
1805 clear |= S3C_DxEPINT_XferCompl;
1806 } 1861 }
1807 1862
1808 if (ints & S3C_DxEPINT_EPDisbld) { 1863 if (ints & S3C_DxEPINT_EPDisbld) {
1809 dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); 1864 dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__);
1810 clear |= S3C_DxEPINT_EPDisbld; 1865
1866 if (dir_in) {
1867 int epctl = readl(hsotg->regs + epctl_reg);
1868
1869 s3c_hsotg_txfifo_flush(hsotg, idx);
1870
1871 if ((epctl & S3C_DxEPCTL_Stall) &&
1872 (epctl & S3C_DxEPCTL_EPType_Bulk)) {
1873 int dctl = readl(hsotg->regs + S3C_DCTL);
1874
1875 dctl |= S3C_DCTL_CGNPInNAK;
1876 writel(dctl, hsotg->regs + S3C_DCTL);
1877 }
1878 }
1811 } 1879 }
1812 1880
1813 if (ints & S3C_DxEPINT_AHBErr) { 1881 if (ints & S3C_DxEPINT_AHBErr)
1814 dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); 1882 dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__);
1815 clear |= S3C_DxEPINT_AHBErr;
1816 }
1817 1883
1818 if (ints & S3C_DxEPINT_Setup) { /* Setup or Timeout */ 1884 if (ints & S3C_DxEPINT_Setup) { /* Setup or Timeout */
1819 dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); 1885 dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__);
@@ -1829,14 +1895,10 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1829 else 1895 else
1830 s3c_hsotg_handle_outdone(hsotg, 0, true); 1896 s3c_hsotg_handle_outdone(hsotg, 0, true);
1831 } 1897 }
1832
1833 clear |= S3C_DxEPINT_Setup;
1834 } 1898 }
1835 1899
1836 if (ints & S3C_DxEPINT_Back2BackSetup) { 1900 if (ints & S3C_DxEPINT_Back2BackSetup)
1837 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); 1901 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__);
1838 clear |= S3C_DxEPINT_Back2BackSetup;
1839 }
1840 1902
1841 if (dir_in) { 1903 if (dir_in) {
1842 /* not sure if this is important, but we'll clear it anyway 1904 /* not sure if this is important, but we'll clear it anyway
@@ -1844,14 +1906,12 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1844 if (ints & S3C_DIEPMSK_INTknTXFEmpMsk) { 1906 if (ints & S3C_DIEPMSK_INTknTXFEmpMsk) {
1845 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", 1907 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n",
1846 __func__, idx); 1908 __func__, idx);
1847 clear |= S3C_DIEPMSK_INTknTXFEmpMsk;
1848 } 1909 }
1849 1910
1850 /* this probably means something bad is happening */ 1911 /* this probably means something bad is happening */
1851 if (ints & S3C_DIEPMSK_INTknEPMisMsk) { 1912 if (ints & S3C_DIEPMSK_INTknEPMisMsk) {
1852 dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", 1913 dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n",
1853 __func__, idx); 1914 __func__, idx);
1854 clear |= S3C_DIEPMSK_INTknEPMisMsk;
1855 } 1915 }
1856 1916
1857 /* FIFO has space or is empty (see GAHBCFG) */ 1917 /* FIFO has space or is empty (see GAHBCFG) */
@@ -1860,11 +1920,8 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1860 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", 1920 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n",
1861 __func__, idx); 1921 __func__, idx);
1862 s3c_hsotg_trytx(hsotg, hs_ep); 1922 s3c_hsotg_trytx(hsotg, hs_ep);
1863 clear |= S3C_DIEPMSK_TxFIFOEmpty;
1864 } 1923 }
1865 } 1924 }
1866
1867 writel(clear, hsotg->regs + epint_reg);
1868} 1925}
1869 1926
1870/** 1927/**
@@ -2056,7 +2113,6 @@ irq_retry:
2056 dev_info(hsotg->dev, "OTGInt: %08x\n", otgint); 2113 dev_info(hsotg->dev, "OTGInt: %08x\n", otgint);
2057 2114
2058 writel(otgint, hsotg->regs + S3C_GOTGINT); 2115 writel(otgint, hsotg->regs + S3C_GOTGINT);
2059 writel(S3C_GINTSTS_OTGInt, hsotg->regs + S3C_GINTSTS);
2060 } 2116 }
2061 2117
2062 if (gintsts & S3C_GINTSTS_DisconnInt) { 2118 if (gintsts & S3C_GINTSTS_DisconnInt) {
@@ -2072,8 +2128,9 @@ irq_retry:
2072 } 2128 }
2073 2129
2074 if (gintsts & S3C_GINTSTS_EnumDone) { 2130 if (gintsts & S3C_GINTSTS_EnumDone) {
2075 s3c_hsotg_irq_enumdone(hsotg);
2076 writel(S3C_GINTSTS_EnumDone, hsotg->regs + S3C_GINTSTS); 2131 writel(S3C_GINTSTS_EnumDone, hsotg->regs + S3C_GINTSTS);
2132
2133 s3c_hsotg_irq_enumdone(hsotg);
2077 } 2134 }
2078 2135
2079 if (gintsts & S3C_GINTSTS_ConIDStsChng) { 2136 if (gintsts & S3C_GINTSTS_ConIDStsChng) {
@@ -2101,10 +2158,6 @@ irq_retry:
2101 if (daint_in & 1) 2158 if (daint_in & 1)
2102 s3c_hsotg_epint(hsotg, ep, 1); 2159 s3c_hsotg_epint(hsotg, ep, 1);
2103 } 2160 }
2104
2105 writel(daint, hsotg->regs + S3C_DAINT);
2106 writel(gintsts & (S3C_GINTSTS_OEPInt | S3C_GINTSTS_IEPInt),
2107 hsotg->regs + S3C_GINTSTS);
2108 } 2161 }
2109 2162
2110 if (gintsts & S3C_GINTSTS_USBRst) { 2163 if (gintsts & S3C_GINTSTS_USBRst) {
@@ -2112,6 +2165,8 @@ irq_retry:
2112 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", 2165 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n",
2113 readl(hsotg->regs + S3C_GNPTXSTS)); 2166 readl(hsotg->regs + S3C_GNPTXSTS));
2114 2167
2168 writel(S3C_GINTSTS_USBRst, hsotg->regs + S3C_GINTSTS);
2169
2115 kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true); 2170 kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true);
2116 2171
2117 /* it seems after a reset we can end up with a situation 2172 /* it seems after a reset we can end up with a situation
@@ -2123,8 +2178,6 @@ irq_retry:
2123 s3c_hsotg_init_fifo(hsotg); 2178 s3c_hsotg_init_fifo(hsotg);
2124 2179
2125 s3c_hsotg_enqueue_setup(hsotg); 2180 s3c_hsotg_enqueue_setup(hsotg);
2126
2127 writel(S3C_GINTSTS_USBRst, hsotg->regs + S3C_GINTSTS);
2128 } 2181 }
2129 2182
2130 /* check both FIFOs */ 2183 /* check both FIFOs */
@@ -2138,8 +2191,6 @@ irq_retry:
2138 2191
2139 s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_NPTxFEmp); 2192 s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_NPTxFEmp);
2140 s3c_hsotg_irq_fifoempty(hsotg, false); 2193 s3c_hsotg_irq_fifoempty(hsotg, false);
2141
2142 writel(S3C_GINTSTS_NPTxFEmp, hsotg->regs + S3C_GINTSTS);
2143 } 2194 }
2144 2195
2145 if (gintsts & S3C_GINTSTS_PTxFEmp) { 2196 if (gintsts & S3C_GINTSTS_PTxFEmp) {
@@ -2149,8 +2200,6 @@ irq_retry:
2149 2200
2150 s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_PTxFEmp); 2201 s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_PTxFEmp);
2151 s3c_hsotg_irq_fifoempty(hsotg, true); 2202 s3c_hsotg_irq_fifoempty(hsotg, true);
2152
2153 writel(S3C_GINTSTS_PTxFEmp, hsotg->regs + S3C_GINTSTS);
2154 } 2203 }
2155 2204
2156 if (gintsts & S3C_GINTSTS_RxFLvl) { 2205 if (gintsts & S3C_GINTSTS_RxFLvl) {
@@ -2159,7 +2208,6 @@ irq_retry:
2159 * set. */ 2208 * set. */
2160 2209
2161 s3c_hsotg_handle_rx(hsotg); 2210 s3c_hsotg_handle_rx(hsotg);
2162 writel(S3C_GINTSTS_RxFLvl, hsotg->regs + S3C_GINTSTS);
2163 } 2211 }
2164 2212
2165 if (gintsts & S3C_GINTSTS_ModeMis) { 2213 if (gintsts & S3C_GINTSTS_ModeMis) {
@@ -2188,24 +2236,22 @@ irq_retry:
2188 2236
2189 /* these next two seem to crop-up occasionally causing the core 2237 /* these next two seem to crop-up occasionally causing the core
2190 * to shutdown the USB transfer, so try clearing them and logging 2238 * to shutdown the USB transfer, so try clearing them and logging
2191 * the occurence. */ 2239 * the occurrence. */
2192 2240
2193 if (gintsts & S3C_GINTSTS_GOUTNakEff) { 2241 if (gintsts & S3C_GINTSTS_GOUTNakEff) {
2194 dev_info(hsotg->dev, "GOUTNakEff triggered\n"); 2242 dev_info(hsotg->dev, "GOUTNakEff triggered\n");
2195 2243
2196 s3c_hsotg_dump(hsotg);
2197
2198 writel(S3C_DCTL_CGOUTNak, hsotg->regs + S3C_DCTL); 2244 writel(S3C_DCTL_CGOUTNak, hsotg->regs + S3C_DCTL);
2199 writel(S3C_GINTSTS_GOUTNakEff, hsotg->regs + S3C_GINTSTS); 2245
2246 s3c_hsotg_dump(hsotg);
2200 } 2247 }
2201 2248
2202 if (gintsts & S3C_GINTSTS_GINNakEff) { 2249 if (gintsts & S3C_GINTSTS_GINNakEff) {
2203 dev_info(hsotg->dev, "GINNakEff triggered\n"); 2250 dev_info(hsotg->dev, "GINNakEff triggered\n");
2204 2251
2205 s3c_hsotg_dump(hsotg);
2206
2207 writel(S3C_DCTL_CGNPInNAK, hsotg->regs + S3C_DCTL); 2252 writel(S3C_DCTL_CGNPInNAK, hsotg->regs + S3C_DCTL);
2208 writel(S3C_GINTSTS_GINNakEff, hsotg->regs + S3C_GINTSTS); 2253
2254 s3c_hsotg_dump(hsotg);
2209 } 2255 }
2210 2256
2211 /* if we've had fifo events, we should try and go around the 2257 /* if we've had fifo events, we should try and go around the
@@ -2403,11 +2449,6 @@ static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
2403 2449
2404 dev_info(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); 2450 dev_info(hs->dev, "ep_dequeue(%p,%p)\n", ep, req);
2405 2451
2406 if (hs_req == hs_ep->req) {
2407 dev_dbg(hs->dev, "%s: already in progress\n", __func__);
2408 return -EINPROGRESS;
2409 }
2410
2411 spin_lock_irqsave(&hs_ep->lock, flags); 2452 spin_lock_irqsave(&hs_ep->lock, flags);
2412 2453
2413 if (!on_list(hs_ep, hs_req)) { 2454 if (!on_list(hs_ep, hs_req)) {
@@ -2429,6 +2470,7 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value)
2429 unsigned long irqflags; 2470 unsigned long irqflags;
2430 u32 epreg; 2471 u32 epreg;
2431 u32 epctl; 2472 u32 epctl;
2473 u32 xfertype;
2432 2474
2433 dev_info(hs->dev, "%s(ep %p %s, %d)\n", __func__, ep, ep->name, value); 2475 dev_info(hs->dev, "%s(ep %p %s, %d)\n", __func__, ep, ep->name, value);
2434 2476
@@ -2439,10 +2481,17 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value)
2439 epreg = S3C_DIEPCTL(index); 2481 epreg = S3C_DIEPCTL(index);
2440 epctl = readl(hs->regs + epreg); 2482 epctl = readl(hs->regs + epreg);
2441 2483
2442 if (value) 2484 if (value) {
2443 epctl |= S3C_DxEPCTL_Stall; 2485 epctl |= S3C_DxEPCTL_Stall + S3C_DxEPCTL_SNAK;
2444 else 2486 if (epctl & S3C_DxEPCTL_EPEna)
2487 epctl |= S3C_DxEPCTL_EPDis;
2488 } else {
2445 epctl &= ~S3C_DxEPCTL_Stall; 2489 epctl &= ~S3C_DxEPCTL_Stall;
2490 xfertype = epctl & S3C_DxEPCTL_EPType_MASK;
2491 if (xfertype == S3C_DxEPCTL_EPType_Bulk ||
2492 xfertype == S3C_DxEPCTL_EPType_Intterupt)
2493 epctl |= S3C_DxEPCTL_SetD0PID;
2494 }
2446 2495
2447 writel(epctl, hs->regs + epreg); 2496 writel(epctl, hs->regs + epreg);
2448 2497
@@ -2451,8 +2500,13 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value)
2451 2500
2452 if (value) 2501 if (value)
2453 epctl |= S3C_DxEPCTL_Stall; 2502 epctl |= S3C_DxEPCTL_Stall;
2454 else 2503 else {
2455 epctl &= ~S3C_DxEPCTL_Stall; 2504 epctl &= ~S3C_DxEPCTL_Stall;
2505 xfertype = epctl & S3C_DxEPCTL_EPType_MASK;
2506 if (xfertype == S3C_DxEPCTL_EPType_Bulk ||
2507 xfertype == S3C_DxEPCTL_EPType_Intterupt)
2508 epctl |= S3C_DxEPCTL_SetD0PID;
2509 }
2456 2510
2457 writel(epctl, hs->regs + epreg); 2511 writel(epctl, hs->regs + epreg);
2458 2512
@@ -2469,7 +2523,7 @@ static struct usb_ep_ops s3c_hsotg_ep_ops = {
2469 .queue = s3c_hsotg_ep_queue, 2523 .queue = s3c_hsotg_ep_queue,
2470 .dequeue = s3c_hsotg_ep_dequeue, 2524 .dequeue = s3c_hsotg_ep_dequeue,
2471 .set_halt = s3c_hsotg_ep_sethalt, 2525 .set_halt = s3c_hsotg_ep_sethalt,
2472 /* note, don't belive we have any call for the fifo routines */ 2526 /* note, don't believe we have any call for the fifo routines */
2473}; 2527};
2474 2528
2475/** 2529/**
@@ -2491,9 +2545,9 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
2491 timeout = 1000; 2545 timeout = 1000;
2492 do { 2546 do {
2493 grstctl = readl(hsotg->regs + S3C_GRSTCTL); 2547 grstctl = readl(hsotg->regs + S3C_GRSTCTL);
2494 } while (!(grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0); 2548 } while ((grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0);
2495 2549
2496 if (!(grstctl & S3C_GRSTCTL_CSftRst)) { 2550 if (grstctl & S3C_GRSTCTL_CSftRst) {
2497 dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); 2551 dev_err(hsotg->dev, "Failed to get CSftRst asserted\n");
2498 return -EINVAL; 2552 return -EINVAL;
2499 } 2553 }
@@ -2510,20 +2564,18 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
2510 return -ETIMEDOUT; 2564 return -ETIMEDOUT;
2511 } 2565 }
2512 2566
2513 if (grstctl & S3C_GRSTCTL_CSftRst)
2514 continue;
2515
2516 if (!(grstctl & S3C_GRSTCTL_AHBIdle)) 2567 if (!(grstctl & S3C_GRSTCTL_AHBIdle))
2517 continue; 2568 continue;
2518 2569
2519 break; /* reset done */ 2570 break; /* reset done */
2520 } 2571 }
2521 2572
2522 dev_dbg(hsotg->dev, "reset successful\n"); 2573 dev_dbg(hsotg->dev, "reset successful\n");
2523 return 0; 2574 return 0;
2524} 2575}
2525 2576
2526int usb_gadget_register_driver(struct usb_gadget_driver *driver) 2577int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2578 int (*bind)(struct usb_gadget *))
2527{ 2579{
2528 struct s3c_hsotg *hsotg = our_hsotg; 2580 struct s3c_hsotg *hsotg = our_hsotg;
2529 int ret; 2581 int ret;
@@ -2543,7 +2595,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2543 dev_err(hsotg->dev, "%s: bad speed\n", __func__); 2595 dev_err(hsotg->dev, "%s: bad speed\n", __func__);
2544 } 2596 }
2545 2597
2546 if (!driver->bind || !driver->setup) { 2598 if (!bind || !driver->setup) {
2547 dev_err(hsotg->dev, "%s: missing entry points\n", __func__); 2599 dev_err(hsotg->dev, "%s: missing entry points\n", __func__);
2548 return -EINVAL; 2600 return -EINVAL;
2549 } 2601 }
@@ -2562,7 +2614,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2562 goto err; 2614 goto err;
2563 } 2615 }
2564 2616
2565 ret = driver->bind(&hsotg->gadget); 2617 ret = bind(&hsotg->gadget);
2566 if (ret) { 2618 if (ret) {
2567 dev_err(hsotg->dev, "failed bind %s\n", driver->driver.name); 2619 dev_err(hsotg->dev, "failed bind %s\n", driver->driver.name);
2568 2620
@@ -2587,6 +2639,12 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2587 2639
2588 writel(1 << 18 | S3C_DCFG_DevSpd_HS, hsotg->regs + S3C_DCFG); 2640 writel(1 << 18 | S3C_DCFG_DevSpd_HS, hsotg->regs + S3C_DCFG);
2589 2641
2642 /* Clear any pending OTG interrupts */
2643 writel(0xffffffff, hsotg->regs + S3C_GOTGINT);
2644
2645 /* Clear any pending interrupts */
2646 writel(0xffffffff, hsotg->regs + S3C_GINTSTS);
2647
2590 writel(S3C_GINTSTS_DisconnInt | S3C_GINTSTS_SessReqInt | 2648 writel(S3C_GINTSTS_DisconnInt | S3C_GINTSTS_SessReqInt |
2591 S3C_GINTSTS_ConIDStsChng | S3C_GINTSTS_USBRst | 2649 S3C_GINTSTS_ConIDStsChng | S3C_GINTSTS_USBRst |
2592 S3C_GINTSTS_EnumDone | S3C_GINTSTS_OTGInt | 2650 S3C_GINTSTS_EnumDone | S3C_GINTSTS_OTGInt |
@@ -2622,9 +2680,9 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2622 2680
2623 writel(0, hsotg->regs + S3C_DAINTMSK); 2681 writel(0, hsotg->regs + S3C_DAINTMSK);
2624 2682
2625 dev_info(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", 2683 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
2626 readl(hsotg->regs + S3C_DIEPCTL0), 2684 readl(hsotg->regs + S3C_DIEPCTL0),
2627 readl(hsotg->regs + S3C_DOEPCTL0)); 2685 readl(hsotg->regs + S3C_DOEPCTL0));
2628 2686
2629 /* enable in and out endpoint interrupts */ 2687 /* enable in and out endpoint interrupts */
2630 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_OEPInt | S3C_GINTSTS_IEPInt); 2688 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_OEPInt | S3C_GINTSTS_IEPInt);
@@ -2643,7 +2701,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2643 udelay(10); /* see openiboot */ 2701 udelay(10); /* see openiboot */
2644 __bic32(hsotg->regs + S3C_DCTL, S3C_DCTL_PWROnPrgDone); 2702 __bic32(hsotg->regs + S3C_DCTL, S3C_DCTL_PWROnPrgDone);
2645 2703
2646 dev_info(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + S3C_DCTL)); 2704 dev_dbg(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + S3C_DCTL));
2647 2705
2648 /* S3C_DxEPCTL_USBActEp says RO in manual, but seems to be set by 2706 /* S3C_DxEPCTL_USBActEp says RO in manual, but seems to be set by
2649 writing to the EPCTL register.. */ 2707 writing to the EPCTL register.. */
@@ -2663,9 +2721,9 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2663 2721
2664 s3c_hsotg_enqueue_setup(hsotg); 2722 s3c_hsotg_enqueue_setup(hsotg);
2665 2723
2666 dev_info(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", 2724 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
2667 readl(hsotg->regs + S3C_DIEPCTL0), 2725 readl(hsotg->regs + S3C_DIEPCTL0),
2668 readl(hsotg->regs + S3C_DOEPCTL0)); 2726 readl(hsotg->regs + S3C_DOEPCTL0));
2669 2727
2670 /* clear global NAKs */ 2728 /* clear global NAKs */
2671 writel(S3C_DCTL_CGOUTNak | S3C_DCTL_CGNPInNAK, 2729 writel(S3C_DCTL_CGOUTNak | S3C_DCTL_CGNPInNAK,
@@ -2687,7 +2745,7 @@ err:
2687 hsotg->gadget.dev.driver = NULL; 2745 hsotg->gadget.dev.driver = NULL;
2688 return ret; 2746 return ret;
2689} 2747}
2690EXPORT_SYMBOL(usb_gadget_register_driver); 2748EXPORT_SYMBOL(usb_gadget_probe_driver);
2691 2749
2692int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2750int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2693{ 2751{
@@ -2863,9 +2921,9 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg)
2863 2921
2864 /* setup fifos */ 2922 /* setup fifos */
2865 2923
2866 dev_info(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", 2924 dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n",
2867 readl(hsotg->regs + S3C_GRXFSIZ), 2925 readl(hsotg->regs + S3C_GRXFSIZ),
2868 readl(hsotg->regs + S3C_GNPTXFSIZ)); 2926 readl(hsotg->regs + S3C_GNPTXFSIZ));
2869 2927
2870 s3c_hsotg_init_fifo(hsotg); 2928 s3c_hsotg_init_fifo(hsotg);
2871 2929
@@ -2887,6 +2945,7 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg)
2887 2945
2888static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) 2946static void s3c_hsotg_dump(struct s3c_hsotg *hsotg)
2889{ 2947{
2948#ifdef DEBUG
2890 struct device *dev = hsotg->dev; 2949 struct device *dev = hsotg->dev;
2891 void __iomem *regs = hsotg->regs; 2950 void __iomem *regs = hsotg->regs;
2892 u32 val; 2951 u32 val;
@@ -2929,6 +2988,7 @@ static void s3c_hsotg_dump(struct s3c_hsotg *hsotg)
2929 2988
2930 dev_info(dev, "DVBUSDIS=0x%08x, DVBUSPULSE=%08x\n", 2989 dev_info(dev, "DVBUSDIS=0x%08x, DVBUSPULSE=%08x\n",
2931 readl(regs + S3C_DVBUSDIS), readl(regs + S3C_DVBUSPULSE)); 2990 readl(regs + S3C_DVBUSDIS), readl(regs + S3C_DVBUSPULSE));
2991#endif
2932} 2992}
2933 2993
2934 2994
@@ -3260,7 +3320,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3260 hsotg->clk = clk_get(&pdev->dev, "otg"); 3320 hsotg->clk = clk_get(&pdev->dev, "otg");
3261 if (IS_ERR(hsotg->clk)) { 3321 if (IS_ERR(hsotg->clk)) {
3262 dev_err(dev, "cannot get otg clock\n"); 3322 dev_err(dev, "cannot get otg clock\n");
3263 ret = -EINVAL; 3323 ret = PTR_ERR(hsotg->clk);
3264 goto err_mem; 3324 goto err_mem;
3265 } 3325 }
3266 3326
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
new file mode 100644
index 000000000000..d5e3e1e58626
--- /dev/null
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -0,0 +1,1352 @@
1/* linux/drivers/usb/gadget/s3c-hsudc.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S3C24XX USB 2.0 High-speed USB controller gadget driver
7 *
8 * The S3C24XX USB 2.0 high-speed USB controller supports upto 9 endpoints.
9 * Each endpoint can be configured as either in or out endpoint. Endpoints
10 * can be configured for Bulk or Interrupt transfer mode.
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
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/spinlock.h>
20#include <linux/interrupt.h>
21#include <linux/platform_device.h>
22#include <linux/dma-mapping.h>
23#include <linux/delay.h>
24#include <linux/io.h>
25#include <linux/slab.h>
26#include <linux/clk.h>
27#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h>
29#include <linux/prefetch.h>
30
31#include <mach/regs-s3c2443-clock.h>
32#include <plat/udc.h>
33
34#define S3C_HSUDC_REG(x) (x)
35
36/* Non-Indexed Registers */
37#define S3C_IR S3C_HSUDC_REG(0x00) /* Index Register */
38#define S3C_EIR S3C_HSUDC_REG(0x04) /* EP Intr Status */
39#define S3C_EIR_EP0 (1<<0)
40#define S3C_EIER S3C_HSUDC_REG(0x08) /* EP Intr Enable */
41#define S3C_FAR S3C_HSUDC_REG(0x0c) /* Gadget Address */
42#define S3C_FNR S3C_HSUDC_REG(0x10) /* Frame Number */
43#define S3C_EDR S3C_HSUDC_REG(0x14) /* EP Direction */
44#define S3C_TR S3C_HSUDC_REG(0x18) /* Test Register */
45#define S3C_SSR S3C_HSUDC_REG(0x1c) /* System Status */
46#define S3C_SSR_DTZIEN_EN (0xff8f)
47#define S3C_SSR_ERR (0xff80)
48#define S3C_SSR_VBUSON (1 << 8)
49#define S3C_SSR_HSP (1 << 4)
50#define S3C_SSR_SDE (1 << 3)
51#define S3C_SSR_RESUME (1 << 2)
52#define S3C_SSR_SUSPEND (1 << 1)
53#define S3C_SSR_RESET (1 << 0)
54#define S3C_SCR S3C_HSUDC_REG(0x20) /* System Control */
55#define S3C_SCR_DTZIEN_EN (1 << 14)
56#define S3C_SCR_RRD_EN (1 << 5)
57#define S3C_SCR_SUS_EN (1 << 1)
58#define S3C_SCR_RST_EN (1 << 0)
59#define S3C_EP0SR S3C_HSUDC_REG(0x24) /* EP0 Status */
60#define S3C_EP0SR_EP0_LWO (1 << 6)
61#define S3C_EP0SR_STALL (1 << 4)
62#define S3C_EP0SR_TX_SUCCESS (1 << 1)
63#define S3C_EP0SR_RX_SUCCESS (1 << 0)
64#define S3C_EP0CR S3C_HSUDC_REG(0x28) /* EP0 Control */
65#define S3C_BR(_x) S3C_HSUDC_REG(0x60 + (_x * 4))
66
67/* Indexed Registers */
68#define S3C_ESR S3C_HSUDC_REG(0x2c) /* EPn Status */
69#define S3C_ESR_FLUSH (1 << 6)
70#define S3C_ESR_STALL (1 << 5)
71#define S3C_ESR_LWO (1 << 4)
72#define S3C_ESR_PSIF_ONE (1 << 2)
73#define S3C_ESR_PSIF_TWO (2 << 2)
74#define S3C_ESR_TX_SUCCESS (1 << 1)
75#define S3C_ESR_RX_SUCCESS (1 << 0)
76#define S3C_ECR S3C_HSUDC_REG(0x30) /* EPn Control */
77#define S3C_ECR_DUEN (1 << 7)
78#define S3C_ECR_FLUSH (1 << 6)
79#define S3C_ECR_STALL (1 << 1)
80#define S3C_ECR_IEMS (1 << 0)
81#define S3C_BRCR S3C_HSUDC_REG(0x34) /* Read Count */
82#define S3C_BWCR S3C_HSUDC_REG(0x38) /* Write Count */
83#define S3C_MPR S3C_HSUDC_REG(0x3c) /* Max Pkt Size */
84
85#define WAIT_FOR_SETUP (0)
86#define DATA_STATE_XMIT (1)
87#define DATA_STATE_RECV (2)
88
89/**
90 * struct s3c_hsudc_ep - Endpoint representation used by driver.
91 * @ep: USB gadget layer representation of device endpoint.
92 * @name: Endpoint name (as required by ep autoconfiguration).
93 * @dev: Reference to the device controller to which this EP belongs.
94 * @desc: Endpoint descriptor obtained from the gadget driver.
95 * @queue: Transfer request queue for the endpoint.
96 * @stopped: Maintains state of endpoint, set if EP is halted.
97 * @bEndpointAddress: EP address (including direction bit).
98 * @fifo: Base address of EP FIFO.
99 */
100struct s3c_hsudc_ep {
101 struct usb_ep ep;
102 char name[20];
103 struct s3c_hsudc *dev;
104 const struct usb_endpoint_descriptor *desc;
105 struct list_head queue;
106 u8 stopped;
107 u8 wedge;
108 u8 bEndpointAddress;
109 void __iomem *fifo;
110};
111
112/**
113 * struct s3c_hsudc_req - Driver encapsulation of USB gadget transfer request.
114 * @req: Reference to USB gadget transfer request.
115 * @queue: Used for inserting this request to the endpoint request queue.
116 */
117struct s3c_hsudc_req {
118 struct usb_request req;
119 struct list_head queue;
120};
121
122/**
123 * struct s3c_hsudc - Driver's abstraction of the device controller.
124 * @gadget: Instance of usb_gadget which is referenced by gadget driver.
125 * @driver: Reference to currenty active gadget driver.
126 * @dev: The device reference used by probe function.
127 * @lock: Lock to synchronize the usage of Endpoints (EP's are indexed).
128 * @regs: Remapped base address of controller's register space.
129 * @mem_rsrc: Device memory resource used for remapping device register space.
130 * irq: IRQ number used by the controller.
131 * uclk: Reference to the controller clock.
132 * ep0state: Current state of EP0.
133 * ep: List of endpoints supported by the controller.
134 */
135struct s3c_hsudc {
136 struct usb_gadget gadget;
137 struct usb_gadget_driver *driver;
138 struct device *dev;
139 struct s3c24xx_hsudc_platdata *pd;
140 spinlock_t lock;
141 void __iomem *regs;
142 struct resource *mem_rsrc;
143 int irq;
144 struct clk *uclk;
145 int ep0state;
146 struct s3c_hsudc_ep ep[];
147};
148
149#define ep_maxpacket(_ep) ((_ep)->ep.maxpacket)
150#define ep_is_in(_ep) ((_ep)->bEndpointAddress & USB_DIR_IN)
151#define ep_index(_ep) ((_ep)->bEndpointAddress & \
152 USB_ENDPOINT_NUMBER_MASK)
153
154static struct s3c_hsudc *the_controller;
155static const char driver_name[] = "s3c-udc";
156static const char ep0name[] = "ep0-control";
157
158static inline struct s3c_hsudc_req *our_req(struct usb_request *req)
159{
160 return container_of(req, struct s3c_hsudc_req, req);
161}
162
163static inline struct s3c_hsudc_ep *our_ep(struct usb_ep *ep)
164{
165 return container_of(ep, struct s3c_hsudc_ep, ep);
166}
167
168static inline struct s3c_hsudc *to_hsudc(struct usb_gadget *gadget)
169{
170 return container_of(gadget, struct s3c_hsudc, gadget);
171}
172
173static inline void set_index(struct s3c_hsudc *hsudc, int ep_addr)
174{
175 ep_addr &= USB_ENDPOINT_NUMBER_MASK;
176 writel(ep_addr, hsudc->regs + S3C_IR);
177}
178
179static inline void __orr32(void __iomem *ptr, u32 val)
180{
181 writel(readl(ptr) | val, ptr);
182}
183
184static void s3c_hsudc_init_phy(void)
185{
186 u32 cfg;
187
188 cfg = readl(S3C2443_PWRCFG) | S3C2443_PWRCFG_USBPHY;
189 writel(cfg, S3C2443_PWRCFG);
190
191 cfg = readl(S3C2443_URSTCON);
192 cfg |= (S3C2443_URSTCON_FUNCRST | S3C2443_URSTCON_PHYRST);
193 writel(cfg, S3C2443_URSTCON);
194 mdelay(1);
195
196 cfg = readl(S3C2443_URSTCON);
197 cfg &= ~(S3C2443_URSTCON_FUNCRST | S3C2443_URSTCON_PHYRST);
198 writel(cfg, S3C2443_URSTCON);
199
200 cfg = readl(S3C2443_PHYCTRL);
201 cfg &= ~(S3C2443_PHYCTRL_CLKSEL | S3C2443_PHYCTRL_DSPORT);
202 cfg |= (S3C2443_PHYCTRL_EXTCLK | S3C2443_PHYCTRL_PLLSEL);
203 writel(cfg, S3C2443_PHYCTRL);
204
205 cfg = readl(S3C2443_PHYPWR);
206 cfg &= ~(S3C2443_PHYPWR_FSUSPEND | S3C2443_PHYPWR_PLL_PWRDN |
207 S3C2443_PHYPWR_XO_ON | S3C2443_PHYPWR_PLL_REFCLK |
208 S3C2443_PHYPWR_ANALOG_PD);
209 cfg |= S3C2443_PHYPWR_COMMON_ON;
210 writel(cfg, S3C2443_PHYPWR);
211
212 cfg = readl(S3C2443_UCLKCON);
213 cfg |= (S3C2443_UCLKCON_DETECT_VBUS | S3C2443_UCLKCON_FUNC_CLKEN |
214 S3C2443_UCLKCON_TCLKEN);
215 writel(cfg, S3C2443_UCLKCON);
216}
217
218static void s3c_hsudc_uninit_phy(void)
219{
220 u32 cfg;
221
222 cfg = readl(S3C2443_PWRCFG) & ~S3C2443_PWRCFG_USBPHY;
223 writel(cfg, S3C2443_PWRCFG);
224
225 writel(S3C2443_PHYPWR_FSUSPEND, S3C2443_PHYPWR);
226
227 cfg = readl(S3C2443_UCLKCON) & ~S3C2443_UCLKCON_FUNC_CLKEN;
228 writel(cfg, S3C2443_UCLKCON);
229}
230
231/**
232 * s3c_hsudc_complete_request - Complete a transfer request.
233 * @hsep: Endpoint to which the request belongs.
234 * @hsreq: Transfer request to be completed.
235 * @status: Transfer completion status for the transfer request.
236 */
237static void s3c_hsudc_complete_request(struct s3c_hsudc_ep *hsep,
238 struct s3c_hsudc_req *hsreq, int status)
239{
240 unsigned int stopped = hsep->stopped;
241 struct s3c_hsudc *hsudc = hsep->dev;
242
243 list_del_init(&hsreq->queue);
244 hsreq->req.status = status;
245
246 if (!ep_index(hsep)) {
247 hsudc->ep0state = WAIT_FOR_SETUP;
248 hsep->bEndpointAddress &= ~USB_DIR_IN;
249 }
250
251 hsep->stopped = 1;
252 spin_unlock(&hsudc->lock);
253 if (hsreq->req.complete != NULL)
254 hsreq->req.complete(&hsep->ep, &hsreq->req);
255 spin_lock(&hsudc->lock);
256 hsep->stopped = stopped;
257}
258
259/**
260 * s3c_hsudc_nuke_ep - Terminate all requests queued for a endpoint.
261 * @hsep: Endpoint for which queued requests have to be terminated.
262 * @status: Transfer completion status for the transfer request.
263 */
264static void s3c_hsudc_nuke_ep(struct s3c_hsudc_ep *hsep, int status)
265{
266 struct s3c_hsudc_req *hsreq;
267
268 while (!list_empty(&hsep->queue)) {
269 hsreq = list_entry(hsep->queue.next,
270 struct s3c_hsudc_req, queue);
271 s3c_hsudc_complete_request(hsep, hsreq, status);
272 }
273}
274
275/**
276 * s3c_hsudc_stop_activity - Stop activity on all endpoints.
277 * @hsudc: Device controller for which EP activity is to be stopped.
278 * @driver: Reference to the gadget driver which is currently active.
279 *
280 * All the endpoints are stopped and any pending transfer requests if any on
281 * the endpoint are terminated.
282 */
283static void s3c_hsudc_stop_activity(struct s3c_hsudc *hsudc,
284 struct usb_gadget_driver *driver)
285{
286 struct s3c_hsudc_ep *hsep;
287 int epnum;
288
289 hsudc->gadget.speed = USB_SPEED_UNKNOWN;
290
291 for (epnum = 0; epnum < hsudc->pd->epnum; epnum++) {
292 hsep = &hsudc->ep[epnum];
293 hsep->stopped = 1;
294 s3c_hsudc_nuke_ep(hsep, -ESHUTDOWN);
295 }
296
297 spin_unlock(&hsudc->lock);
298 driver->disconnect(&hsudc->gadget);
299 spin_lock(&hsudc->lock);
300}
301
302/**
303 * s3c_hsudc_read_setup_pkt - Read the received setup packet from EP0 fifo.
304 * @hsudc: Device controller from which setup packet is to be read.
305 * @buf: The buffer into which the setup packet is read.
306 *
307 * The setup packet received in the EP0 fifo is read and stored into a
308 * given buffer address.
309 */
310
311static void s3c_hsudc_read_setup_pkt(struct s3c_hsudc *hsudc, u16 *buf)
312{
313 int count;
314
315 count = readl(hsudc->regs + S3C_BRCR);
316 while (count--)
317 *buf++ = (u16)readl(hsudc->regs + S3C_BR(0));
318
319 writel(S3C_EP0SR_RX_SUCCESS, hsudc->regs + S3C_EP0SR);
320}
321
322/**
323 * s3c_hsudc_write_fifo - Write next chunk of transfer data to EP fifo.
324 * @hsep: Endpoint to which the data is to be written.
325 * @hsreq: Transfer request from which the next chunk of data is written.
326 *
327 * Write the next chunk of data from a transfer request to the endpoint FIFO.
328 * If the transfer request completes, 1 is returned, otherwise 0 is returned.
329 */
330static int s3c_hsudc_write_fifo(struct s3c_hsudc_ep *hsep,
331 struct s3c_hsudc_req *hsreq)
332{
333 u16 *buf;
334 u32 max = ep_maxpacket(hsep);
335 u32 count, length;
336 bool is_last;
337 void __iomem *fifo = hsep->fifo;
338
339 buf = hsreq->req.buf + hsreq->req.actual;
340 prefetch(buf);
341
342 length = hsreq->req.length - hsreq->req.actual;
343 length = min(length, max);
344 hsreq->req.actual += length;
345
346 writel(length, hsep->dev->regs + S3C_BWCR);
347 for (count = 0; count < length; count += 2)
348 writel(*buf++, fifo);
349
350 if (count != max) {
351 is_last = true;
352 } else {
353 if (hsreq->req.length != hsreq->req.actual || hsreq->req.zero)
354 is_last = false;
355 else
356 is_last = true;
357 }
358
359 if (is_last) {
360 s3c_hsudc_complete_request(hsep, hsreq, 0);
361 return 1;
362 }
363
364 return 0;
365}
366
367/**
368 * s3c_hsudc_read_fifo - Read the next chunk of data from EP fifo.
369 * @hsep: Endpoint from which the data is to be read.
370 * @hsreq: Transfer request to which the next chunk of data read is written.
371 *
372 * Read the next chunk of data from the endpoint FIFO and a write it to the
373 * transfer request buffer. If the transfer request completes, 1 is returned,
374 * otherwise 0 is returned.
375 */
376static int s3c_hsudc_read_fifo(struct s3c_hsudc_ep *hsep,
377 struct s3c_hsudc_req *hsreq)
378{
379 struct s3c_hsudc *hsudc = hsep->dev;
380 u32 csr, offset;
381 u16 *buf, word;
382 u32 buflen, rcnt, rlen;
383 void __iomem *fifo = hsep->fifo;
384 u32 is_short = 0;
385
386 offset = (ep_index(hsep)) ? S3C_ESR : S3C_EP0SR;
387 csr = readl(hsudc->regs + offset);
388 if (!(csr & S3C_ESR_RX_SUCCESS))
389 return -EINVAL;
390
391 buf = hsreq->req.buf + hsreq->req.actual;
392 prefetchw(buf);
393 buflen = hsreq->req.length - hsreq->req.actual;
394
395 rcnt = readl(hsudc->regs + S3C_BRCR);
396 rlen = (csr & S3C_ESR_LWO) ? (rcnt * 2 - 1) : (rcnt * 2);
397
398 hsreq->req.actual += min(rlen, buflen);
399 is_short = (rlen < hsep->ep.maxpacket);
400
401 while (rcnt-- != 0) {
402 word = (u16)readl(fifo);
403 if (buflen) {
404 *buf++ = word;
405 buflen--;
406 } else {
407 hsreq->req.status = -EOVERFLOW;
408 }
409 }
410
411 writel(S3C_ESR_RX_SUCCESS, hsudc->regs + offset);
412
413 if (is_short || hsreq->req.actual == hsreq->req.length) {
414 s3c_hsudc_complete_request(hsep, hsreq, 0);
415 return 1;
416 }
417
418 return 0;
419}
420
421/**
422 * s3c_hsudc_epin_intr - Handle in-endpoint interrupt.
423 * @hsudc - Device controller for which the interrupt is to be handled.
424 * @ep_idx - Endpoint number on which an interrupt is pending.
425 *
426 * Handles interrupt for a in-endpoint. The interrupts that are handled are
427 * stall and data transmit complete interrupt.
428 */
429static void s3c_hsudc_epin_intr(struct s3c_hsudc *hsudc, u32 ep_idx)
430{
431 struct s3c_hsudc_ep *hsep = &hsudc->ep[ep_idx];
432 struct s3c_hsudc_req *hsreq;
433 u32 csr;
434
435 csr = readl((u32)hsudc->regs + S3C_ESR);
436 if (csr & S3C_ESR_STALL) {
437 writel(S3C_ESR_STALL, hsudc->regs + S3C_ESR);
438 return;
439 }
440
441 if (csr & S3C_ESR_TX_SUCCESS) {
442 writel(S3C_ESR_TX_SUCCESS, hsudc->regs + S3C_ESR);
443 if (list_empty(&hsep->queue))
444 return;
445
446 hsreq = list_entry(hsep->queue.next,
447 struct s3c_hsudc_req, queue);
448 if ((s3c_hsudc_write_fifo(hsep, hsreq) == 0) &&
449 (csr & S3C_ESR_PSIF_TWO))
450 s3c_hsudc_write_fifo(hsep, hsreq);
451 }
452}
453
454/**
455 * s3c_hsudc_epout_intr - Handle out-endpoint interrupt.
456 * @hsudc - Device controller for which the interrupt is to be handled.
457 * @ep_idx - Endpoint number on which an interrupt is pending.
458 *
459 * Handles interrupt for a out-endpoint. The interrupts that are handled are
460 * stall, flush and data ready interrupt.
461 */
462static void s3c_hsudc_epout_intr(struct s3c_hsudc *hsudc, u32 ep_idx)
463{
464 struct s3c_hsudc_ep *hsep = &hsudc->ep[ep_idx];
465 struct s3c_hsudc_req *hsreq;
466 u32 csr;
467
468 csr = readl((u32)hsudc->regs + S3C_ESR);
469 if (csr & S3C_ESR_STALL) {
470 writel(S3C_ESR_STALL, hsudc->regs + S3C_ESR);
471 return;
472 }
473
474 if (csr & S3C_ESR_FLUSH) {
475 __orr32(hsudc->regs + S3C_ECR, S3C_ECR_FLUSH);
476 return;
477 }
478
479 if (csr & S3C_ESR_RX_SUCCESS) {
480 if (list_empty(&hsep->queue))
481 return;
482
483 hsreq = list_entry(hsep->queue.next,
484 struct s3c_hsudc_req, queue);
485 if (((s3c_hsudc_read_fifo(hsep, hsreq)) == 0) &&
486 (csr & S3C_ESR_PSIF_TWO))
487 s3c_hsudc_read_fifo(hsep, hsreq);
488 }
489}
490
491/** s3c_hsudc_set_halt - Set or clear a endpoint halt.
492 * @_ep: Endpoint on which halt has to be set or cleared.
493 * @value: 1 for setting halt on endpoint, 0 to clear halt.
494 *
495 * Set or clear endpoint halt. If halt is set, the endpoint is stopped.
496 * If halt is cleared, for in-endpoints, if there are any pending
497 * transfer requests, transfers are started.
498 */
499static int s3c_hsudc_set_halt(struct usb_ep *_ep, int value)
500{
501 struct s3c_hsudc_ep *hsep = our_ep(_ep);
502 struct s3c_hsudc *hsudc = hsep->dev;
503 struct s3c_hsudc_req *hsreq;
504 unsigned long irqflags;
505 u32 ecr;
506 u32 offset;
507
508 if (value && ep_is_in(hsep) && !list_empty(&hsep->queue))
509 return -EAGAIN;
510
511 spin_lock_irqsave(&hsudc->lock, irqflags);
512 set_index(hsudc, ep_index(hsep));
513 offset = (ep_index(hsep)) ? S3C_ECR : S3C_EP0CR;
514 ecr = readl(hsudc->regs + offset);
515
516 if (value) {
517 ecr |= S3C_ECR_STALL;
518 if (ep_index(hsep))
519 ecr |= S3C_ECR_FLUSH;
520 hsep->stopped = 1;
521 } else {
522 ecr &= ~S3C_ECR_STALL;
523 hsep->stopped = hsep->wedge = 0;
524 }
525 writel(ecr, hsudc->regs + offset);
526
527 if (ep_is_in(hsep) && !list_empty(&hsep->queue) && !value) {
528 hsreq = list_entry(hsep->queue.next,
529 struct s3c_hsudc_req, queue);
530 if (hsreq)
531 s3c_hsudc_write_fifo(hsep, hsreq);
532 }
533
534 spin_unlock_irqrestore(&hsudc->lock, irqflags);
535 return 0;
536}
537
538/** s3c_hsudc_set_wedge - Sets the halt feature with the clear requests ignored
539 * @_ep: Endpoint on which wedge has to be set.
540 *
541 * Sets the halt feature with the clear requests ignored.
542 */
543static int s3c_hsudc_set_wedge(struct usb_ep *_ep)
544{
545 struct s3c_hsudc_ep *hsep = our_ep(_ep);
546
547 if (!hsep)
548 return -EINVAL;
549
550 hsep->wedge = 1;
551 return usb_ep_set_halt(_ep);
552}
553
554/** s3c_hsudc_handle_reqfeat - Handle set feature or clear feature requests.
555 * @_ep: Device controller on which the set/clear feature needs to be handled.
556 * @ctrl: Control request as received on the endpoint 0.
557 *
558 * Handle set feature or clear feature control requests on the control endpoint.
559 */
560static int s3c_hsudc_handle_reqfeat(struct s3c_hsudc *hsudc,
561 struct usb_ctrlrequest *ctrl)
562{
563 struct s3c_hsudc_ep *hsep;
564 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE);
565 u8 ep_num = ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK;
566
567 if (ctrl->bRequestType == USB_RECIP_ENDPOINT) {
568 hsep = &hsudc->ep[ep_num];
569 switch (le16_to_cpu(ctrl->wValue)) {
570 case USB_ENDPOINT_HALT:
571 if (set || (!set && !hsep->wedge))
572 s3c_hsudc_set_halt(&hsep->ep, set);
573 return 0;
574 }
575 }
576
577 return -ENOENT;
578}
579
580/**
581 * s3c_hsudc_process_req_status - Handle get status control request.
582 * @hsudc: Device controller on which get status request has be handled.
583 * @ctrl: Control request as received on the endpoint 0.
584 *
585 * Handle get status control request received on control endpoint.
586 */
587static void s3c_hsudc_process_req_status(struct s3c_hsudc *hsudc,
588 struct usb_ctrlrequest *ctrl)
589{
590 struct s3c_hsudc_ep *hsep0 = &hsudc->ep[0];
591 struct s3c_hsudc_req hsreq;
592 struct s3c_hsudc_ep *hsep;
593 __le16 reply;
594 u8 epnum;
595
596 switch (ctrl->bRequestType & USB_RECIP_MASK) {
597 case USB_RECIP_DEVICE:
598 reply = cpu_to_le16(0);
599 break;
600
601 case USB_RECIP_INTERFACE:
602 reply = cpu_to_le16(0);
603 break;
604
605 case USB_RECIP_ENDPOINT:
606 epnum = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK;
607 hsep = &hsudc->ep[epnum];
608 reply = cpu_to_le16(hsep->stopped ? 1 : 0);
609 break;
610 }
611
612 INIT_LIST_HEAD(&hsreq.queue);
613 hsreq.req.length = 2;
614 hsreq.req.buf = &reply;
615 hsreq.req.actual = 0;
616 hsreq.req.complete = NULL;
617 s3c_hsudc_write_fifo(hsep0, &hsreq);
618}
619
620/**
621 * s3c_hsudc_process_setup - Process control request received on endpoint 0.
622 * @hsudc: Device controller on which control request has been received.
623 *
624 * Read the control request received on endpoint 0, decode it and handle
625 * the request.
626 */
627static void s3c_hsudc_process_setup(struct s3c_hsudc *hsudc)
628{
629 struct s3c_hsudc_ep *hsep = &hsudc->ep[0];
630 struct usb_ctrlrequest ctrl = {0};
631 int ret;
632
633 s3c_hsudc_nuke_ep(hsep, -EPROTO);
634 s3c_hsudc_read_setup_pkt(hsudc, (u16 *)&ctrl);
635
636 if (ctrl.bRequestType & USB_DIR_IN) {
637 hsep->bEndpointAddress |= USB_DIR_IN;
638 hsudc->ep0state = DATA_STATE_XMIT;
639 } else {
640 hsep->bEndpointAddress &= ~USB_DIR_IN;
641 hsudc->ep0state = DATA_STATE_RECV;
642 }
643
644 switch (ctrl.bRequest) {
645 case USB_REQ_SET_ADDRESS:
646 if (ctrl.bRequestType != (USB_TYPE_STANDARD | USB_RECIP_DEVICE))
647 break;
648 hsudc->ep0state = WAIT_FOR_SETUP;
649 return;
650
651 case USB_REQ_GET_STATUS:
652 if ((ctrl.bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD)
653 break;
654 s3c_hsudc_process_req_status(hsudc, &ctrl);
655 return;
656
657 case USB_REQ_SET_FEATURE:
658 case USB_REQ_CLEAR_FEATURE:
659 if ((ctrl.bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD)
660 break;
661 s3c_hsudc_handle_reqfeat(hsudc, &ctrl);
662 hsudc->ep0state = WAIT_FOR_SETUP;
663 return;
664 }
665
666 if (hsudc->driver) {
667 spin_unlock(&hsudc->lock);
668 ret = hsudc->driver->setup(&hsudc->gadget, &ctrl);
669 spin_lock(&hsudc->lock);
670
671 if (ctrl.bRequest == USB_REQ_SET_CONFIGURATION) {
672 hsep->bEndpointAddress &= ~USB_DIR_IN;
673 hsudc->ep0state = WAIT_FOR_SETUP;
674 }
675
676 if (ret < 0) {
677 dev_err(hsudc->dev, "setup failed, returned %d\n",
678 ret);
679 s3c_hsudc_set_halt(&hsep->ep, 1);
680 hsudc->ep0state = WAIT_FOR_SETUP;
681 hsep->bEndpointAddress &= ~USB_DIR_IN;
682 }
683 }
684}
685
686/** s3c_hsudc_handle_ep0_intr - Handle endpoint 0 interrupt.
687 * @hsudc: Device controller on which endpoint 0 interrupt has occured.
688 *
689 * Handle endpoint 0 interrupt when it occurs. EP0 interrupt could occur
690 * when a stall handshake is sent to host or data is sent/received on
691 * endpoint 0.
692 */
693static void s3c_hsudc_handle_ep0_intr(struct s3c_hsudc *hsudc)
694{
695 struct s3c_hsudc_ep *hsep = &hsudc->ep[0];
696 struct s3c_hsudc_req *hsreq;
697 u32 csr = readl(hsudc->regs + S3C_EP0SR);
698 u32 ecr;
699
700 if (csr & S3C_EP0SR_STALL) {
701 ecr = readl(hsudc->regs + S3C_EP0CR);
702 ecr &= ~(S3C_ECR_STALL | S3C_ECR_FLUSH);
703 writel(ecr, hsudc->regs + S3C_EP0CR);
704
705 writel(S3C_EP0SR_STALL, hsudc->regs + S3C_EP0SR);
706 hsep->stopped = 0;
707
708 s3c_hsudc_nuke_ep(hsep, -ECONNABORTED);
709 hsudc->ep0state = WAIT_FOR_SETUP;
710 hsep->bEndpointAddress &= ~USB_DIR_IN;
711 return;
712 }
713
714 if (csr & S3C_EP0SR_TX_SUCCESS) {
715 writel(S3C_EP0SR_TX_SUCCESS, hsudc->regs + S3C_EP0SR);
716 if (ep_is_in(hsep)) {
717 if (list_empty(&hsep->queue))
718 return;
719
720 hsreq = list_entry(hsep->queue.next,
721 struct s3c_hsudc_req, queue);
722 s3c_hsudc_write_fifo(hsep, hsreq);
723 }
724 }
725
726 if (csr & S3C_EP0SR_RX_SUCCESS) {
727 if (hsudc->ep0state == WAIT_FOR_SETUP)
728 s3c_hsudc_process_setup(hsudc);
729 else {
730 if (!ep_is_in(hsep)) {
731 if (list_empty(&hsep->queue))
732 return;
733 hsreq = list_entry(hsep->queue.next,
734 struct s3c_hsudc_req, queue);
735 s3c_hsudc_read_fifo(hsep, hsreq);
736 }
737 }
738 }
739}
740
741/**
742 * s3c_hsudc_ep_enable - Enable a endpoint.
743 * @_ep: The endpoint to be enabled.
744 * @desc: Endpoint descriptor.
745 *
746 * Enables a endpoint when called from the gadget driver. Endpoint stall if
747 * any is cleared, transfer type is configured and endpoint interrupt is
748 * enabled.
749 */
750static int s3c_hsudc_ep_enable(struct usb_ep *_ep,
751 const struct usb_endpoint_descriptor *desc)
752{
753 struct s3c_hsudc_ep *hsep;
754 struct s3c_hsudc *hsudc;
755 unsigned long flags;
756 u32 ecr = 0;
757
758 hsep = container_of(_ep, struct s3c_hsudc_ep, ep);
759 if (!_ep || !desc || hsep->desc || _ep->name == ep0name
760 || desc->bDescriptorType != USB_DT_ENDPOINT
761 || hsep->bEndpointAddress != desc->bEndpointAddress
762 || ep_maxpacket(hsep) < le16_to_cpu(desc->wMaxPacketSize))
763 return -EINVAL;
764
765 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
766 && le16_to_cpu(desc->wMaxPacketSize) != ep_maxpacket(hsep))
767 || !desc->wMaxPacketSize)
768 return -ERANGE;
769
770 hsudc = hsep->dev;
771 if (!hsudc->driver || hsudc->gadget.speed == USB_SPEED_UNKNOWN)
772 return -ESHUTDOWN;
773
774 spin_lock_irqsave(&hsudc->lock, flags);
775
776 set_index(hsudc, hsep->bEndpointAddress);
777 ecr |= ((usb_endpoint_xfer_int(desc)) ? S3C_ECR_IEMS : S3C_ECR_DUEN);
778 writel(ecr, hsudc->regs + S3C_ECR);
779
780 hsep->stopped = hsep->wedge = 0;
781 hsep->desc = desc;
782 hsep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
783
784 s3c_hsudc_set_halt(_ep, 0);
785 __set_bit(ep_index(hsep), hsudc->regs + S3C_EIER);
786
787 spin_unlock_irqrestore(&hsudc->lock, flags);
788 return 0;
789}
790
791/**
792 * s3c_hsudc_ep_disable - Disable a endpoint.
793 * @_ep: The endpoint to be disabled.
794 * @desc: Endpoint descriptor.
795 *
796 * Disables a endpoint when called from the gadget driver.
797 */
798static int s3c_hsudc_ep_disable(struct usb_ep *_ep)
799{
800 struct s3c_hsudc_ep *hsep = our_ep(_ep);
801 struct s3c_hsudc *hsudc = hsep->dev;
802 unsigned long flags;
803
804 if (!_ep || !hsep->desc)
805 return -EINVAL;
806
807 spin_lock_irqsave(&hsudc->lock, flags);
808
809 set_index(hsudc, hsep->bEndpointAddress);
810 __clear_bit(ep_index(hsep), hsudc->regs + S3C_EIER);
811
812 s3c_hsudc_nuke_ep(hsep, -ESHUTDOWN);
813
814 hsep->desc = 0;
815 hsep->stopped = 1;
816
817 spin_unlock_irqrestore(&hsudc->lock, flags);
818 return 0;
819}
820
821/**
822 * s3c_hsudc_alloc_request - Allocate a new request.
823 * @_ep: Endpoint for which request is allocated (not used).
824 * @gfp_flags: Flags used for the allocation.
825 *
826 * Allocates a single transfer request structure when called from gadget driver.
827 */
828static struct usb_request *s3c_hsudc_alloc_request(struct usb_ep *_ep,
829 gfp_t gfp_flags)
830{
831 struct s3c_hsudc_req *hsreq;
832
833 hsreq = kzalloc(sizeof *hsreq, gfp_flags);
834 if (!hsreq)
835 return 0;
836
837 INIT_LIST_HEAD(&hsreq->queue);
838 return &hsreq->req;
839}
840
841/**
842 * s3c_hsudc_free_request - Deallocate a request.
843 * @ep: Endpoint for which request is deallocated (not used).
844 * @_req: Request to be deallocated.
845 *
846 * Allocates a single transfer request structure when called from gadget driver.
847 */
848static void s3c_hsudc_free_request(struct usb_ep *ep, struct usb_request *_req)
849{
850 struct s3c_hsudc_req *hsreq;
851
852 hsreq = container_of(_req, struct s3c_hsudc_req, req);
853 WARN_ON(!list_empty(&hsreq->queue));
854 kfree(hsreq);
855}
856
857/**
858 * s3c_hsudc_queue - Queue a transfer request for the endpoint.
859 * @_ep: Endpoint for which the request is queued.
860 * @_req: Request to be queued.
861 * @gfp_flags: Not used.
862 *
863 * Start or enqueue a request for a endpoint when called from gadget driver.
864 */
865static int s3c_hsudc_queue(struct usb_ep *_ep, struct usb_request *_req,
866 gfp_t gfp_flags)
867{
868 struct s3c_hsudc_req *hsreq;
869 struct s3c_hsudc_ep *hsep;
870 struct s3c_hsudc *hsudc;
871 unsigned long flags;
872 u32 offset;
873 u32 csr;
874
875 hsreq = container_of(_req, struct s3c_hsudc_req, req);
876 if ((!_req || !_req->complete || !_req->buf ||
877 !list_empty(&hsreq->queue)))
878 return -EINVAL;
879
880 hsep = container_of(_ep, struct s3c_hsudc_ep, ep);
881 hsudc = hsep->dev;
882 if (!hsudc->driver || hsudc->gadget.speed == USB_SPEED_UNKNOWN)
883 return -ESHUTDOWN;
884
885 spin_lock_irqsave(&hsudc->lock, flags);
886 set_index(hsudc, hsep->bEndpointAddress);
887
888 _req->status = -EINPROGRESS;
889 _req->actual = 0;
890
891 if (!ep_index(hsep) && _req->length == 0) {
892 hsudc->ep0state = WAIT_FOR_SETUP;
893 s3c_hsudc_complete_request(hsep, hsreq, 0);
894 spin_unlock_irqrestore(&hsudc->lock, flags);
895 return 0;
896 }
897
898 if (list_empty(&hsep->queue) && !hsep->stopped) {
899 offset = (ep_index(hsep)) ? S3C_ESR : S3C_EP0SR;
900 if (ep_is_in(hsep)) {
901 csr = readl((u32)hsudc->regs + offset);
902 if (!(csr & S3C_ESR_TX_SUCCESS) &&
903 (s3c_hsudc_write_fifo(hsep, hsreq) == 1))
904 hsreq = 0;
905 } else {
906 csr = readl((u32)hsudc->regs + offset);
907 if ((csr & S3C_ESR_RX_SUCCESS)
908 && (s3c_hsudc_read_fifo(hsep, hsreq) == 1))
909 hsreq = 0;
910 }
911 }
912
913 if (hsreq != 0)
914 list_add_tail(&hsreq->queue, &hsep->queue);
915
916 spin_unlock_irqrestore(&hsudc->lock, flags);
917 return 0;
918}
919
920/**
921 * s3c_hsudc_dequeue - Dequeue a transfer request from an endpoint.
922 * @_ep: Endpoint from which the request is dequeued.
923 * @_req: Request to be dequeued.
924 *
925 * Dequeue a request from a endpoint when called from gadget driver.
926 */
927static int s3c_hsudc_dequeue(struct usb_ep *_ep, struct usb_request *_req)
928{
929 struct s3c_hsudc_ep *hsep = our_ep(_ep);
930 struct s3c_hsudc *hsudc = hsep->dev;
931 struct s3c_hsudc_req *hsreq;
932 unsigned long flags;
933
934 hsep = container_of(_ep, struct s3c_hsudc_ep, ep);
935 if (!_ep || hsep->ep.name == ep0name)
936 return -EINVAL;
937
938 spin_lock_irqsave(&hsudc->lock, flags);
939
940 list_for_each_entry(hsreq, &hsep->queue, queue) {
941 if (&hsreq->req == _req)
942 break;
943 }
944 if (&hsreq->req != _req) {
945 spin_unlock_irqrestore(&hsudc->lock, flags);
946 return -EINVAL;
947 }
948
949 set_index(hsudc, hsep->bEndpointAddress);
950 s3c_hsudc_complete_request(hsep, hsreq, -ECONNRESET);
951
952 spin_unlock_irqrestore(&hsudc->lock, flags);
953 return 0;
954}
955
956static struct usb_ep_ops s3c_hsudc_ep_ops = {
957 .enable = s3c_hsudc_ep_enable,
958 .disable = s3c_hsudc_ep_disable,
959 .alloc_request = s3c_hsudc_alloc_request,
960 .free_request = s3c_hsudc_free_request,
961 .queue = s3c_hsudc_queue,
962 .dequeue = s3c_hsudc_dequeue,
963 .set_halt = s3c_hsudc_set_halt,
964 .set_wedge = s3c_hsudc_set_wedge,
965};
966
967/**
968 * s3c_hsudc_initep - Initialize a endpoint to default state.
969 * @hsudc - Reference to the device controller.
970 * @hsep - Endpoint to be initialized.
971 * @epnum - Address to be assigned to the endpoint.
972 *
973 * Initialize a endpoint with default configuration.
974 */
975static void s3c_hsudc_initep(struct s3c_hsudc *hsudc,
976 struct s3c_hsudc_ep *hsep, int epnum)
977{
978 char *dir;
979
980 if ((epnum % 2) == 0) {
981 dir = "out";
982 } else {
983 dir = "in";
984 hsep->bEndpointAddress = USB_DIR_IN;
985 }
986
987 hsep->bEndpointAddress |= epnum;
988 if (epnum)
989 snprintf(hsep->name, sizeof(hsep->name), "ep%d%s", epnum, dir);
990 else
991 snprintf(hsep->name, sizeof(hsep->name), "%s", ep0name);
992
993 INIT_LIST_HEAD(&hsep->queue);
994 INIT_LIST_HEAD(&hsep->ep.ep_list);
995 if (epnum)
996 list_add_tail(&hsep->ep.ep_list, &hsudc->gadget.ep_list);
997
998 hsep->dev = hsudc;
999 hsep->ep.name = hsep->name;
1000 hsep->ep.maxpacket = epnum ? 512 : 64;
1001 hsep->ep.ops = &s3c_hsudc_ep_ops;
1002 hsep->fifo = hsudc->regs + S3C_BR(epnum);
1003 hsep->desc = 0;
1004 hsep->stopped = 0;
1005 hsep->wedge = 0;
1006
1007 set_index(hsudc, epnum);
1008 writel(hsep->ep.maxpacket, hsudc->regs + S3C_MPR);
1009}
1010
1011/**
1012 * s3c_hsudc_setup_ep - Configure all endpoints to default state.
1013 * @hsudc: Reference to device controller.
1014 *
1015 * Configures all endpoints to default state.
1016 */
1017static void s3c_hsudc_setup_ep(struct s3c_hsudc *hsudc)
1018{
1019 int epnum;
1020
1021 hsudc->ep0state = WAIT_FOR_SETUP;
1022 INIT_LIST_HEAD(&hsudc->gadget.ep_list);
1023 for (epnum = 0; epnum < hsudc->pd->epnum; epnum++)
1024 s3c_hsudc_initep(hsudc, &hsudc->ep[epnum], epnum);
1025}
1026
1027/**
1028 * s3c_hsudc_reconfig - Reconfigure the device controller to default state.
1029 * @hsudc: Reference to device controller.
1030 *
1031 * Reconfigures the device controller registers to a default state.
1032 */
1033static void s3c_hsudc_reconfig(struct s3c_hsudc *hsudc)
1034{
1035 writel(0xAA, hsudc->regs + S3C_EDR);
1036 writel(1, hsudc->regs + S3C_EIER);
1037 writel(0, hsudc->regs + S3C_TR);
1038 writel(S3C_SCR_DTZIEN_EN | S3C_SCR_RRD_EN | S3C_SCR_SUS_EN |
1039 S3C_SCR_RST_EN, hsudc->regs + S3C_SCR);
1040 writel(0, hsudc->regs + S3C_EP0CR);
1041
1042 s3c_hsudc_setup_ep(hsudc);
1043}
1044
1045/**
1046 * s3c_hsudc_irq - Interrupt handler for device controller.
1047 * @irq: Not used.
1048 * @_dev: Reference to the device controller.
1049 *
1050 * Interrupt handler for the device controller. This handler handles controller
1051 * interrupts and endpoint interrupts.
1052 */
1053static irqreturn_t s3c_hsudc_irq(int irq, void *_dev)
1054{
1055 struct s3c_hsudc *hsudc = _dev;
1056 struct s3c_hsudc_ep *hsep;
1057 u32 ep_intr;
1058 u32 sys_status;
1059 u32 ep_idx;
1060
1061 spin_lock(&hsudc->lock);
1062
1063 sys_status = readl(hsudc->regs + S3C_SSR);
1064 ep_intr = readl(hsudc->regs + S3C_EIR) & 0x3FF;
1065
1066 if (!ep_intr && !(sys_status & S3C_SSR_DTZIEN_EN)) {
1067 spin_unlock(&hsudc->lock);
1068 return IRQ_HANDLED;
1069 }
1070
1071 if (sys_status) {
1072 if (sys_status & S3C_SSR_VBUSON)
1073 writel(S3C_SSR_VBUSON, hsudc->regs + S3C_SSR);
1074
1075 if (sys_status & S3C_SSR_ERR)
1076 writel(S3C_SSR_ERR, hsudc->regs + S3C_SSR);
1077
1078 if (sys_status & S3C_SSR_SDE) {
1079 writel(S3C_SSR_SDE, hsudc->regs + S3C_SSR);
1080 hsudc->gadget.speed = (sys_status & S3C_SSR_HSP) ?
1081 USB_SPEED_HIGH : USB_SPEED_FULL;
1082 }
1083
1084 if (sys_status & S3C_SSR_SUSPEND) {
1085 writel(S3C_SSR_SUSPEND, hsudc->regs + S3C_SSR);
1086 if (hsudc->gadget.speed != USB_SPEED_UNKNOWN
1087 && hsudc->driver && hsudc->driver->suspend)
1088 hsudc->driver->suspend(&hsudc->gadget);
1089 }
1090
1091 if (sys_status & S3C_SSR_RESUME) {
1092 writel(S3C_SSR_RESUME, hsudc->regs + S3C_SSR);
1093 if (hsudc->gadget.speed != USB_SPEED_UNKNOWN
1094 && hsudc->driver && hsudc->driver->resume)
1095 hsudc->driver->resume(&hsudc->gadget);
1096 }
1097
1098 if (sys_status & S3C_SSR_RESET) {
1099 writel(S3C_SSR_RESET, hsudc->regs + S3C_SSR);
1100 for (ep_idx = 0; ep_idx < hsudc->pd->epnum; ep_idx++) {
1101 hsep = &hsudc->ep[ep_idx];
1102 hsep->stopped = 1;
1103 s3c_hsudc_nuke_ep(hsep, -ECONNRESET);
1104 }
1105 s3c_hsudc_reconfig(hsudc);
1106 hsudc->ep0state = WAIT_FOR_SETUP;
1107 }
1108 }
1109
1110 if (ep_intr & S3C_EIR_EP0) {
1111 writel(S3C_EIR_EP0, hsudc->regs + S3C_EIR);
1112 set_index(hsudc, 0);
1113 s3c_hsudc_handle_ep0_intr(hsudc);
1114 }
1115
1116 ep_intr >>= 1;
1117 ep_idx = 1;
1118 while (ep_intr) {
1119 if (ep_intr & 1) {
1120 hsep = &hsudc->ep[ep_idx];
1121 set_index(hsudc, ep_idx);
1122 writel(1 << ep_idx, hsudc->regs + S3C_EIR);
1123 if (ep_is_in(hsep))
1124 s3c_hsudc_epin_intr(hsudc, ep_idx);
1125 else
1126 s3c_hsudc_epout_intr(hsudc, ep_idx);
1127 }
1128 ep_intr >>= 1;
1129 ep_idx++;
1130 }
1131
1132 spin_unlock(&hsudc->lock);
1133 return IRQ_HANDLED;
1134}
1135
1136int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1137 int (*bind)(struct usb_gadget *))
1138{
1139 struct s3c_hsudc *hsudc = the_controller;
1140 int ret;
1141
1142 if (!driver
1143 || (driver->speed != USB_SPEED_FULL &&
1144 driver->speed != USB_SPEED_HIGH)
1145 || !bind
1146 || !driver->unbind || !driver->disconnect || !driver->setup)
1147 return -EINVAL;
1148
1149 if (!hsudc)
1150 return -ENODEV;
1151
1152 if (hsudc->driver)
1153 return -EBUSY;
1154
1155 hsudc->driver = driver;
1156 hsudc->gadget.dev.driver = &driver->driver;
1157 hsudc->gadget.speed = USB_SPEED_UNKNOWN;
1158 ret = device_add(&hsudc->gadget.dev);
1159 if (ret) {
1160 dev_err(hsudc->dev, "failed to probe gadget device");
1161 return ret;
1162 }
1163
1164 ret = bind(&hsudc->gadget);
1165 if (ret) {
1166 dev_err(hsudc->dev, "%s: bind failed\n", hsudc->gadget.name);
1167 device_del(&hsudc->gadget.dev);
1168
1169 hsudc->driver = NULL;
1170 hsudc->gadget.dev.driver = NULL;
1171 return ret;
1172 }
1173
1174 enable_irq(hsudc->irq);
1175 dev_info(hsudc->dev, "bound driver %s\n", driver->driver.name);
1176
1177 s3c_hsudc_reconfig(hsudc);
1178 s3c_hsudc_init_phy();
1179 if (hsudc->pd->gpio_init)
1180 hsudc->pd->gpio_init();
1181
1182 return 0;
1183}
1184EXPORT_SYMBOL(usb_gadget_probe_driver);
1185
1186int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1187{
1188 struct s3c_hsudc *hsudc = the_controller;
1189 unsigned long flags;
1190
1191 if (!hsudc)
1192 return -ENODEV;
1193
1194 if (!driver || driver != hsudc->driver || !driver->unbind)
1195 return -EINVAL;
1196
1197 spin_lock_irqsave(&hsudc->lock, flags);
1198 hsudc->driver = 0;
1199 s3c_hsudc_uninit_phy();
1200 if (hsudc->pd->gpio_uninit)
1201 hsudc->pd->gpio_uninit();
1202 s3c_hsudc_stop_activity(hsudc, driver);
1203 spin_unlock_irqrestore(&hsudc->lock, flags);
1204
1205 driver->unbind(&hsudc->gadget);
1206 device_del(&hsudc->gadget.dev);
1207 disable_irq(hsudc->irq);
1208
1209 dev_info(hsudc->dev, "unregistered gadget driver '%s'\n",
1210 driver->driver.name);
1211 return 0;
1212}
1213EXPORT_SYMBOL(usb_gadget_unregister_driver);
1214
1215static inline u32 s3c_hsudc_read_frameno(struct s3c_hsudc *hsudc)
1216{
1217 return readl(hsudc->regs + S3C_FNR) & 0x3FF;
1218}
1219
1220static int s3c_hsudc_gadget_getframe(struct usb_gadget *gadget)
1221{
1222 return s3c_hsudc_read_frameno(to_hsudc(gadget));
1223}
1224
1225static struct usb_gadget_ops s3c_hsudc_gadget_ops = {
1226 .get_frame = s3c_hsudc_gadget_getframe,
1227};
1228
1229static int s3c_hsudc_probe(struct platform_device *pdev)
1230{
1231 struct device *dev = &pdev->dev;
1232 struct resource *res;
1233 struct s3c_hsudc *hsudc;
1234 struct s3c24xx_hsudc_platdata *pd = pdev->dev.platform_data;
1235 int ret;
1236
1237 hsudc = kzalloc(sizeof(struct s3c_hsudc) +
1238 sizeof(struct s3c_hsudc_ep) * pd->epnum,
1239 GFP_KERNEL);
1240 if (!hsudc) {
1241 dev_err(dev, "cannot allocate memory\n");
1242 return -ENOMEM;
1243 }
1244
1245 the_controller = hsudc;
1246 platform_set_drvdata(pdev, dev);
1247 hsudc->dev = dev;
1248 hsudc->pd = pdev->dev.platform_data;
1249
1250 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1251 if (!res) {
1252 dev_err(dev, "unable to obtain driver resource data\n");
1253 ret = -ENODEV;
1254 goto err_res;
1255 }
1256
1257 hsudc->mem_rsrc = request_mem_region(res->start, resource_size(res),
1258 dev_name(&pdev->dev));
1259 if (!hsudc->mem_rsrc) {
1260 dev_err(dev, "failed to reserve register area\n");
1261 ret = -ENODEV;
1262 goto err_res;
1263 }
1264
1265 hsudc->regs = ioremap(res->start, resource_size(res));
1266 if (!hsudc->regs) {
1267 dev_err(dev, "error mapping device register area\n");
1268 ret = -EBUSY;
1269 goto err_remap;
1270 }
1271
1272 ret = platform_get_irq(pdev, 0);
1273 if (ret < 0) {
1274 dev_err(dev, "unable to obtain IRQ number\n");
1275 goto err_irq;
1276 }
1277 hsudc->irq = ret;
1278
1279 ret = request_irq(hsudc->irq, s3c_hsudc_irq, 0, driver_name, hsudc);
1280 if (ret < 0) {
1281 dev_err(dev, "irq request failed\n");
1282 goto err_irq;
1283 }
1284
1285 spin_lock_init(&hsudc->lock);
1286
1287 device_initialize(&hsudc->gadget.dev);
1288 dev_set_name(&hsudc->gadget.dev, "gadget");
1289
1290 hsudc->gadget.is_dualspeed = 1;
1291 hsudc->gadget.ops = &s3c_hsudc_gadget_ops;
1292 hsudc->gadget.name = dev_name(dev);
1293 hsudc->gadget.dev.parent = dev;
1294 hsudc->gadget.dev.dma_mask = dev->dma_mask;
1295 hsudc->gadget.ep0 = &hsudc->ep[0].ep;
1296
1297 hsudc->gadget.is_otg = 0;
1298 hsudc->gadget.is_a_peripheral = 0;
1299
1300 s3c_hsudc_setup_ep(hsudc);
1301
1302 hsudc->uclk = clk_get(&pdev->dev, "usb-device");
1303 if (IS_ERR(hsudc->uclk)) {
1304 dev_err(dev, "failed to find usb-device clock source\n");
1305 ret = PTR_ERR(hsudc->uclk);
1306 goto err_clk;
1307 }
1308 clk_enable(hsudc->uclk);
1309
1310 local_irq_disable();
1311
1312 disable_irq(hsudc->irq);
1313 local_irq_enable();
1314 return 0;
1315err_clk:
1316 free_irq(hsudc->irq, hsudc);
1317err_irq:
1318 iounmap(hsudc->regs);
1319
1320err_remap:
1321 release_resource(hsudc->mem_rsrc);
1322 kfree(hsudc->mem_rsrc);
1323
1324err_res:
1325 kfree(hsudc);
1326 return ret;
1327}
1328
1329static struct platform_driver s3c_hsudc_driver = {
1330 .driver = {
1331 .owner = THIS_MODULE,
1332 .name = "s3c-hsudc",
1333 },
1334 .probe = s3c_hsudc_probe,
1335};
1336
1337static int __init s3c_hsudc_modinit(void)
1338{
1339 return platform_driver_register(&s3c_hsudc_driver);
1340}
1341
1342static void __exit s3c_hsudc_modexit(void)
1343{
1344 platform_driver_unregister(&s3c_hsudc_driver);
1345}
1346
1347module_init(s3c_hsudc_modinit);
1348module_exit(s3c_hsudc_modexit);
1349
1350MODULE_DESCRIPTION("Samsung S3C24XX USB high-speed controller driver");
1351MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com>");
1352MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index ea2b3c7ebee5..100f2635cf0a 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -36,6 +36,7 @@
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/clk.h> 37#include <linux/clk.h>
38#include <linux/gpio.h> 38#include <linux/gpio.h>
39#include <linux/prefetch.h>
39 40
40#include <linux/debugfs.h> 41#include <linux/debugfs.h>
41#include <linux/seq_file.h> 42#include <linux/seq_file.h>
@@ -902,7 +903,7 @@ static irqreturn_t s3c2410_udc_irq(int dummy, void *_dev)
902 int pwr_reg; 903 int pwr_reg;
903 int ep0csr; 904 int ep0csr;
904 int i; 905 int i;
905 u32 idx; 906 u32 idx, idx2;
906 unsigned long flags; 907 unsigned long flags;
907 908
908 spin_lock_irqsave(&dev->lock, flags); 909 spin_lock_irqsave(&dev->lock, flags);
@@ -1017,6 +1018,20 @@ static irqreturn_t s3c2410_udc_irq(int dummy, void *_dev)
1017 } 1018 }
1018 } 1019 }
1019 1020
1021 /* what else causes this interrupt? a receive! who is it? */
1022 if (!usb_status && !usbd_status && !pwr_reg && !ep0csr) {
1023 for (i = 1; i < S3C2410_ENDPOINTS; i++) {
1024 idx2 = udc_read(S3C2410_UDC_INDEX_REG);
1025 udc_write(i, S3C2410_UDC_INDEX_REG);
1026
1027 if (udc_read(S3C2410_UDC_OUT_CSR1_REG) & 0x1)
1028 s3c2410_udc_handle_ep(&dev->ep[i]);
1029
1030 /* restore index */
1031 udc_write(idx2, S3C2410_UDC_INDEX_REG);
1032 }
1033 }
1034
1020 dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", IRQ_USBD); 1035 dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", IRQ_USBD);
1021 1036
1022 /* Restore old index */ 1037 /* Restore old index */
@@ -1467,7 +1482,9 @@ static int s3c2410_udc_set_pullup(struct s3c2410_udc *udc, int is_on)
1467{ 1482{
1468 dprintk(DEBUG_NORMAL, "%s()\n", __func__); 1483 dprintk(DEBUG_NORMAL, "%s()\n", __func__);
1469 1484
1470 if (udc_info && udc_info->udc_command) { 1485 if (udc_info && (udc_info->udc_command ||
1486 gpio_is_valid(udc_info->pullup_pin))) {
1487
1471 if (is_on) 1488 if (is_on)
1472 s3c2410_udc_enable(udc); 1489 s3c2410_udc_enable(udc);
1473 else { 1490 else {
@@ -1544,6 +1561,32 @@ static const struct usb_gadget_ops s3c2410_ops = {
1544 .vbus_draw = s3c2410_vbus_draw, 1561 .vbus_draw = s3c2410_vbus_draw,
1545}; 1562};
1546 1563
1564static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd)
1565{
1566 if (!udc_info)
1567 return;
1568
1569 if (udc_info->udc_command) {
1570 udc_info->udc_command(S3C2410_UDC_P_DISABLE);
1571 } else if (gpio_is_valid(udc_info->pullup_pin)) {
1572 int value;
1573
1574 switch (cmd) {
1575 case S3C2410_UDC_P_ENABLE:
1576 value = 1;
1577 break;
1578 case S3C2410_UDC_P_DISABLE:
1579 value = 0;
1580 break;
1581 default:
1582 return;
1583 }
1584 value ^= udc_info->pullup_pin_inverted;
1585
1586 gpio_set_value(udc_info->pullup_pin, value);
1587 }
1588}
1589
1547/*------------------------- gadget driver handling---------------------------*/ 1590/*------------------------- gadget driver handling---------------------------*/
1548/* 1591/*
1549 * s3c2410_udc_disable 1592 * s3c2410_udc_disable
@@ -1565,8 +1608,7 @@ static void s3c2410_udc_disable(struct s3c2410_udc *dev)
1565 udc_write(0x1F, S3C2410_UDC_EP_INT_REG); 1608 udc_write(0x1F, S3C2410_UDC_EP_INT_REG);
1566 1609
1567 /* Good bye, cruel world */ 1610 /* Good bye, cruel world */
1568 if (udc_info && udc_info->udc_command) 1611 s3c2410_udc_command(S3C2410_UDC_P_DISABLE);
1569 udc_info->udc_command(S3C2410_UDC_P_DISABLE);
1570 1612
1571 /* Set speed to unknown */ 1613 /* Set speed to unknown */
1572 dev->gadget.speed = USB_SPEED_UNKNOWN; 1614 dev->gadget.speed = USB_SPEED_UNKNOWN;
@@ -1627,20 +1669,19 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev)
1627 udc_write(S3C2410_UDC_INT_EP0, S3C2410_UDC_EP_INT_EN_REG); 1669 udc_write(S3C2410_UDC_INT_EP0, S3C2410_UDC_EP_INT_EN_REG);
1628 1670
1629 /* time to say "hello, world" */ 1671 /* time to say "hello, world" */
1630 if (udc_info && udc_info->udc_command) 1672 s3c2410_udc_command(S3C2410_UDC_P_ENABLE);
1631 udc_info->udc_command(S3C2410_UDC_P_ENABLE);
1632} 1673}
1633 1674
1634/* 1675/*
1635 * usb_gadget_register_driver 1676 * usb_gadget_probe_driver
1636 */ 1677 */
1637int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1678int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1679 int (*bind)(struct usb_gadget *))
1638{ 1680{
1639 struct s3c2410_udc *udc = the_controller; 1681 struct s3c2410_udc *udc = the_controller;
1640 int retval; 1682 int retval;
1641 1683
1642 dprintk(DEBUG_NORMAL, "usb_gadget_register_driver() '%s'\n", 1684 dprintk(DEBUG_NORMAL, "%s() '%s'\n", __func__, driver->driver.name);
1643 driver->driver.name);
1644 1685
1645 /* Sanity checks */ 1686 /* Sanity checks */
1646 if (!udc) 1687 if (!udc)
@@ -1649,10 +1690,9 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1649 if (udc->driver) 1690 if (udc->driver)
1650 return -EBUSY; 1691 return -EBUSY;
1651 1692
1652 if (!driver->bind || !driver->setup 1693 if (!bind || !driver->setup || driver->speed < USB_SPEED_FULL) {
1653 || driver->speed < USB_SPEED_FULL) {
1654 printk(KERN_ERR "Invalid driver: bind %p setup %p speed %d\n", 1694 printk(KERN_ERR "Invalid driver: bind %p setup %p speed %d\n",
1655 driver->bind, driver->setup, driver->speed); 1695 bind, driver->setup, driver->speed);
1656 return -EINVAL; 1696 return -EINVAL;
1657 } 1697 }
1658#if defined(MODULE) 1698#if defined(MODULE)
@@ -1675,7 +1715,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1675 dprintk(DEBUG_NORMAL, "binding gadget driver '%s'\n", 1715 dprintk(DEBUG_NORMAL, "binding gadget driver '%s'\n",
1676 driver->driver.name); 1716 driver->driver.name);
1677 1717
1678 if ((retval = driver->bind (&udc->gadget)) != 0) { 1718 if ((retval = bind(&udc->gadget)) != 0) {
1679 device_del(&udc->gadget.dev); 1719 device_del(&udc->gadget.dev);
1680 goto register_error; 1720 goto register_error;
1681 } 1721 }
@@ -1690,6 +1730,7 @@ register_error:
1690 udc->gadget.dev.driver = NULL; 1730 udc->gadget.dev.driver = NULL;
1691 return retval; 1731 return retval;
1692} 1732}
1733EXPORT_SYMBOL(usb_gadget_probe_driver);
1693 1734
1694/* 1735/*
1695 * usb_gadget_unregister_driver 1736 * usb_gadget_unregister_driver
@@ -1903,6 +1944,17 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1903 udc->vbus = 1; 1944 udc->vbus = 1;
1904 } 1945 }
1905 1946
1947 if (udc_info && !udc_info->udc_command &&
1948 gpio_is_valid(udc_info->pullup_pin)) {
1949
1950 retval = gpio_request_one(udc_info->pullup_pin,
1951 udc_info->vbus_pin_inverted ?
1952 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
1953 "udc pullup");
1954 if (retval)
1955 goto err_vbus_irq;
1956 }
1957
1906 if (s3c2410_udc_debugfs_root) { 1958 if (s3c2410_udc_debugfs_root) {
1907 udc->regs_info = debugfs_create_file("registers", S_IRUGO, 1959 udc->regs_info = debugfs_create_file("registers", S_IRUGO,
1908 s3c2410_udc_debugfs_root, 1960 s3c2410_udc_debugfs_root,
@@ -1915,6 +1967,9 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1915 1967
1916 return 0; 1968 return 0;
1917 1969
1970err_vbus_irq:
1971 if (udc_info && udc_info->vbus_pin > 0)
1972 free_irq(gpio_to_irq(udc_info->vbus_pin), udc);
1918err_gpio_claim: 1973err_gpio_claim:
1919 if (udc_info && udc_info->vbus_pin > 0) 1974 if (udc_info && udc_info->vbus_pin > 0)
1920 gpio_free(udc_info->vbus_pin); 1975 gpio_free(udc_info->vbus_pin);
@@ -1942,6 +1997,10 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
1942 1997
1943 debugfs_remove(udc->regs_info); 1998 debugfs_remove(udc->regs_info);
1944 1999
2000 if (udc_info && !udc_info->udc_command &&
2001 gpio_is_valid(udc_info->pullup_pin))
2002 gpio_free(udc_info->pullup_pin);
2003
1945 if (udc_info && udc_info->vbus_pin > 0) { 2004 if (udc_info && udc_info->vbus_pin > 0) {
1946 irq = gpio_to_irq(udc_info->vbus_pin); 2005 irq = gpio_to_irq(udc_info->vbus_pin);
1947 free_irq(irq, udc); 2006 free_irq(irq, udc);
@@ -1973,16 +2032,14 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
1973#ifdef CONFIG_PM 2032#ifdef CONFIG_PM
1974static int s3c2410_udc_suspend(struct platform_device *pdev, pm_message_t message) 2033static int s3c2410_udc_suspend(struct platform_device *pdev, pm_message_t message)
1975{ 2034{
1976 if (udc_info && udc_info->udc_command) 2035 s3c2410_udc_command(S3C2410_UDC_P_DISABLE);
1977 udc_info->udc_command(S3C2410_UDC_P_DISABLE);
1978 2036
1979 return 0; 2037 return 0;
1980} 2038}
1981 2039
1982static int s3c2410_udc_resume(struct platform_device *pdev) 2040static int s3c2410_udc_resume(struct platform_device *pdev)
1983{ 2041{
1984 if (udc_info && udc_info->udc_command) 2042 s3c2410_udc_command(S3C2410_UDC_P_ENABLE);
1985 udc_info->udc_command(S3C2410_UDC_P_ENABLE);
1986 2043
1987 return 0; 2044 return 0;
1988} 2045}
@@ -2049,7 +2106,6 @@ static void __exit udc_exit(void)
2049} 2106}
2050 2107
2051EXPORT_SYMBOL(usb_gadget_unregister_driver); 2108EXPORT_SYMBOL(usb_gadget_unregister_driver);
2052EXPORT_SYMBOL(usb_gadget_register_driver);
2053 2109
2054module_init(udc_init); 2110module_init(udc_init);
2055module_exit(udc_exit); 2111module_exit(udc_exit);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index b22eedbc7dc5..1ac57a973aa9 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -137,7 +137,7 @@ MODULE_PARM_DESC(n_ports, "number of ports to create, default=1");
137 137
138/*-------------------------------------------------------------------------*/ 138/*-------------------------------------------------------------------------*/
139 139
140static int __ref serial_bind_config(struct usb_configuration *c) 140static int __init serial_bind_config(struct usb_configuration *c)
141{ 141{
142 unsigned i; 142 unsigned i;
143 int status = 0; 143 int status = 0;
@@ -155,13 +155,12 @@ static int __ref serial_bind_config(struct usb_configuration *c)
155 155
156static struct usb_configuration serial_config_driver = { 156static struct usb_configuration serial_config_driver = {
157 /* .label = f(use_acm) */ 157 /* .label = f(use_acm) */
158 .bind = serial_bind_config,
159 /* .bConfigurationValue = f(use_acm) */ 158 /* .bConfigurationValue = f(use_acm) */
160 /* .iConfiguration = DYNAMIC */ 159 /* .iConfiguration = DYNAMIC */
161 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 160 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
162}; 161};
163 162
164static int __ref gs_bind(struct usb_composite_dev *cdev) 163static int __init gs_bind(struct usb_composite_dev *cdev)
165{ 164{
166 int gcnum; 165 int gcnum;
167 struct usb_gadget *gadget = cdev->gadget; 166 struct usb_gadget *gadget = cdev->gadget;
@@ -225,7 +224,8 @@ static int __ref gs_bind(struct usb_composite_dev *cdev)
225 } 224 }
226 225
227 /* register our configuration */ 226 /* register our configuration */
228 status = usb_add_config(cdev, &serial_config_driver); 227 status = usb_add_config(cdev, &serial_config_driver,
228 serial_bind_config);
229 if (status < 0) 229 if (status < 0)
230 goto fail; 230 goto fail;
231 231
@@ -242,7 +242,6 @@ static struct usb_composite_driver gserial_driver = {
242 .name = "g_serial", 242 .name = "g_serial",
243 .dev = &device_desc, 243 .dev = &device_desc,
244 .strings = dev_strings, 244 .strings = dev_strings,
245 .bind = gs_bind,
246}; 245};
247 246
248static int __init init(void) 247static int __init init(void)
@@ -271,7 +270,7 @@ static int __init init(void)
271 } 270 }
272 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label; 271 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label;
273 272
274 return usb_composite_register(&gserial_driver); 273 return usb_composite_probe(&gserial_driver, gs_bind);
275} 274}
276module_init(init); 275module_init(init);
277 276
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 484acfb1a7c5..1fa4f705b0b4 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -26,7 +26,6 @@
26 * be defined (each of type pointer to char): 26 * be defined (each of type pointer to char):
27 * - fsg_string_manufacturer -- name of the manufacturer 27 * - fsg_string_manufacturer -- name of the manufacturer
28 * - fsg_string_product -- name of the product 28 * - fsg_string_product -- name of the product
29 * - fsg_string_serial -- product's serial
30 * - fsg_string_config -- name of the configuration 29 * - fsg_string_config -- name of the configuration
31 * - fsg_string_interface -- name of the interface 30 * - fsg_string_interface -- name of the interface
32 * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS 31 * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
@@ -54,6 +53,8 @@
54 */ 53 */
55 54
56 55
56#include <linux/usb/storage.h>
57#include <scsi/scsi.h>
57#include <asm/unaligned.h> 58#include <asm/unaligned.h>
58 59
59 60
@@ -153,23 +154,6 @@
153 154
154/*-------------------------------------------------------------------------*/ 155/*-------------------------------------------------------------------------*/
155 156
156/* SCSI device types */
157#define TYPE_DISK 0x00
158#define TYPE_CDROM 0x05
159
160/* USB protocol value = the transport method */
161#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */
162#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */
163#define USB_PR_BULK 0x50 /* Bulk-only */
164
165/* USB subclass value = the protocol encapsulation */
166#define USB_SC_RBC 0x01 /* Reduced Block Commands (flash) */
167#define USB_SC_8020 0x02 /* SFF-8020i, MMC-2, ATAPI (CD-ROM) */
168#define USB_SC_QIC 0x03 /* QIC-157 (tape) */
169#define USB_SC_UFI 0x04 /* UFI (floppy) */
170#define USB_SC_8070 0x05 /* SFF-8070i (removable) */
171#define USB_SC_SCSI 0x06 /* Transparent SCSI */
172
173/* Bulk-only data structures */ 157/* Bulk-only data structures */
174 158
175/* Command Block Wrapper */ 159/* Command Block Wrapper */
@@ -221,33 +205,6 @@ struct interrupt_data {
221/* Length of a SCSI Command Data Block */ 205/* Length of a SCSI Command Data Block */
222#define MAX_COMMAND_SIZE 16 206#define MAX_COMMAND_SIZE 16
223 207
224/* SCSI commands that we recognize */
225#define SC_FORMAT_UNIT 0x04
226#define SC_INQUIRY 0x12
227#define SC_MODE_SELECT_6 0x15
228#define SC_MODE_SELECT_10 0x55
229#define SC_MODE_SENSE_6 0x1a
230#define SC_MODE_SENSE_10 0x5a
231#define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
232#define SC_READ_6 0x08
233#define SC_READ_10 0x28
234#define SC_READ_12 0xa8
235#define SC_READ_CAPACITY 0x25
236#define SC_READ_FORMAT_CAPACITIES 0x23
237#define SC_READ_HEADER 0x44
238#define SC_READ_TOC 0x43
239#define SC_RELEASE 0x17
240#define SC_REQUEST_SENSE 0x03
241#define SC_RESERVE 0x16
242#define SC_SEND_DIAGNOSTIC 0x1d
243#define SC_START_STOP_UNIT 0x1b
244#define SC_SYNCHRONIZE_CACHE 0x35
245#define SC_TEST_UNIT_READY 0x00
246#define SC_VERIFY 0x2f
247#define SC_WRITE_6 0x0a
248#define SC_WRITE_10 0x2a
249#define SC_WRITE_12 0xaa
250
251/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ 208/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
252#define SS_NO_SENSE 0 209#define SS_NO_SENSE 0
253#define SS_COMMUNICATION_FAILURE 0x040800 210#define SS_COMMUNICATION_FAILURE 0x040800
@@ -552,7 +509,7 @@ static struct usb_string fsg_strings[] = {
552#ifndef FSG_NO_DEVICE_STRINGS 509#ifndef FSG_NO_DEVICE_STRINGS
553 {FSG_STRING_MANUFACTURER, fsg_string_manufacturer}, 510 {FSG_STRING_MANUFACTURER, fsg_string_manufacturer},
554 {FSG_STRING_PRODUCT, fsg_string_product}, 511 {FSG_STRING_PRODUCT, fsg_string_product},
555 {FSG_STRING_SERIAL, fsg_string_serial}, 512 {FSG_STRING_SERIAL, ""},
556 {FSG_STRING_CONFIG, fsg_string_config}, 513 {FSG_STRING_CONFIG, fsg_string_config},
557#endif 514#endif
558 {FSG_STRING_INTERFACE, fsg_string_interface}, 515 {FSG_STRING_INTERFACE, fsg_string_interface},
@@ -586,7 +543,7 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
586 ro = curlun->initially_ro; 543 ro = curlun->initially_ro;
587 if (!ro) { 544 if (!ro) {
588 filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0); 545 filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0);
589 if (-EROFS == PTR_ERR(filp)) 546 if (PTR_ERR(filp) == -EROFS || PTR_ERR(filp) == -EACCES)
590 ro = 1; 547 ro = 1;
591 } 548 }
592 if (ro) 549 if (ro)
@@ -601,10 +558,7 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
601 558
602 if (filp->f_path.dentry) 559 if (filp->f_path.dentry)
603 inode = filp->f_path.dentry->d_inode; 560 inode = filp->f_path.dentry->d_inode;
604 if (inode && S_ISBLK(inode->i_mode)) { 561 if (!inode || (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) {
605 if (bdev_read_only(inode->i_bdev))
606 ro = 1;
607 } else if (!inode || !S_ISREG(inode->i_mode)) {
608 LINFO(curlun, "invalid file type: %s\n", filename); 562 LINFO(curlun, "invalid file type: %s\n", filename);
609 goto out; 563 goto out;
610 } 564 }
@@ -754,13 +708,14 @@ static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
754static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr, 708static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
755 const char *buf, size_t count) 709 const char *buf, size_t count)
756{ 710{
757 ssize_t rc = count; 711 ssize_t rc;
758 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 712 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
759 struct rw_semaphore *filesem = dev_get_drvdata(dev); 713 struct rw_semaphore *filesem = dev_get_drvdata(dev);
760 unsigned long ro; 714 unsigned ro;
761 715
762 if (strict_strtoul(buf, 2, &ro)) 716 rc = kstrtouint(buf, 2, &ro);
763 return -EINVAL; 717 if (rc)
718 return rc;
764 719
765 /* 720 /*
766 * Allow the write-enable status to change only while the 721 * Allow the write-enable status to change only while the
@@ -774,6 +729,7 @@ static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
774 curlun->ro = ro; 729 curlun->ro = ro;
775 curlun->initially_ro = ro; 730 curlun->initially_ro = ro;
776 LDBG(curlun, "read-only status set to %d\n", curlun->ro); 731 LDBG(curlun, "read-only status set to %d\n", curlun->ro);
732 rc = count;
777 } 733 }
778 up_read(filesem); 734 up_read(filesem);
779 return rc; 735 return rc;
@@ -784,10 +740,12 @@ static ssize_t fsg_store_nofua(struct device *dev,
784 const char *buf, size_t count) 740 const char *buf, size_t count)
785{ 741{
786 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 742 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
787 unsigned long nofua; 743 unsigned nofua;
744 int ret;
788 745
789 if (strict_strtoul(buf, 2, &nofua)) 746 ret = kstrtouint(buf, 2, &nofua);
790 return -EINVAL; 747 if (ret)
748 return ret;
791 749
792 /* Sync data when switching from async mode to sync */ 750 /* Sync data when switching from async mode to sync */
793 if (!nofua && curlun->nofua) 751 if (!nofua && curlun->nofua)
diff --git a/drivers/usb/gadget/u_audio.c b/drivers/usb/gadget/u_audio.c
index 7a86d2c9109c..59ffe1ecf1c9 100644
--- a/drivers/usb/gadget/u_audio.c
+++ b/drivers/usb/gadget/u_audio.c
@@ -255,6 +255,7 @@ static int gaudio_open_snd_dev(struct gaudio *card)
255 ERROR(card, "No such PCM capture device: %s\n", fn_cap); 255 ERROR(card, "No such PCM capture device: %s\n", fn_cap);
256 snd->substream = NULL; 256 snd->substream = NULL;
257 snd->card = NULL; 257 snd->card = NULL;
258 snd->filp = NULL;
258 } else { 259 } else {
259 pcm_file = snd->filp->private_data; 260 pcm_file = snd->filp->private_data;
260 snd->substream = pcm_file->substream; 261 snd->substream = pcm_file->substream;
@@ -273,17 +274,17 @@ static int gaudio_close_snd_dev(struct gaudio *gau)
273 274
274 /* Close control device */ 275 /* Close control device */
275 snd = &gau->control; 276 snd = &gau->control;
276 if (!IS_ERR(snd->filp)) 277 if (snd->filp)
277 filp_close(snd->filp, current->files); 278 filp_close(snd->filp, current->files);
278 279
279 /* Close PCM playback device and setup substream */ 280 /* Close PCM playback device and setup substream */
280 snd = &gau->playback; 281 snd = &gau->playback;
281 if (!IS_ERR(snd->filp)) 282 if (snd->filp)
282 filp_close(snd->filp, current->files); 283 filp_close(snd->filp, current->files);
283 284
284 /* Close PCM capture device and setup substream */ 285 /* Close PCM capture device and setup substream */
285 snd = &gau->capture; 286 snd = &gau->capture;
286 if (!IS_ERR(snd->filp)) 287 if (snd->filp)
287 filp_close(snd->filp, current->files); 288 filp_close(snd->filp, current->files);
288 289
289 return 0; 290 return 0;
@@ -304,8 +305,7 @@ int __init gaudio_setup(struct gaudio *card)
304 ret = gaudio_open_snd_dev(card); 305 ret = gaudio_open_snd_dev(card);
305 if (ret) 306 if (ret)
306 ERROR(card, "we need at least one control device\n"); 307 ERROR(card, "we need at least one control device\n");
307 308 else if (!the_card)
308 if (!the_card)
309 the_card = card; 309 the_card = card;
310 310
311 return ret; 311 return ret;
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 6bb876d65252..2ac1d2147325 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -240,6 +240,9 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
240 size += out->maxpacket - 1; 240 size += out->maxpacket - 1;
241 size -= size % out->maxpacket; 241 size -= size % out->maxpacket;
242 242
243 if (dev->port_usb->is_fixed)
244 size = max_t(size_t, size, dev->port_usb->fixed_out_len);
245
243 skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags); 246 skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags);
244 if (skb == NULL) { 247 if (skb == NULL) {
245 DBG(dev, "no rx skb\n"); 248 DBG(dev, "no rx skb\n");
@@ -578,12 +581,19 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
578 req->context = skb; 581 req->context = skb;
579 req->complete = tx_complete; 582 req->complete = tx_complete;
580 583
584 /* NCM requires no zlp if transfer is dwNtbInMaxSize */
585 if (dev->port_usb->is_fixed &&
586 length == dev->port_usb->fixed_in_len &&
587 (length % in->maxpacket) == 0)
588 req->zero = 0;
589 else
590 req->zero = 1;
591
581 /* use zlp framing on tx for strict CDC-Ether conformance, 592 /* use zlp framing on tx for strict CDC-Ether conformance,
582 * though any robust network rx path ignores extra padding. 593 * though any robust network rx path ignores extra padding.
583 * and some hardware doesn't like to write zlps. 594 * and some hardware doesn't like to write zlps.
584 */ 595 */
585 req->zero = 1; 596 if (req->zero && !dev->zlp && (length % in->maxpacket) == 0)
586 if (!dev->zlp && (length % in->maxpacket) == 0)
587 length++; 597 length++;
588 598
589 req->length = length; 599 req->length = length;
@@ -797,7 +807,6 @@ int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
797 * - iff DATA transfer is active, carrier is "on" 807 * - iff DATA transfer is active, carrier is "on"
798 * - tx queueing enabled if open *and* carrier is "on" 808 * - tx queueing enabled if open *and* carrier is "on"
799 */ 809 */
800 netif_stop_queue(net);
801 netif_carrier_off(net); 810 netif_carrier_off(net);
802 811
803 dev->gadget = g; 812 dev->gadget = g;
@@ -830,11 +839,9 @@ void gether_cleanup(void)
830 return; 839 return;
831 840
832 unregister_netdev(the_dev->net); 841 unregister_netdev(the_dev->net);
842 flush_work_sync(&the_dev->work);
833 free_netdev(the_dev->net); 843 free_netdev(the_dev->net);
834 844
835 /* assuming we used keventd, it must quiesce too */
836 flush_scheduled_work();
837
838 the_dev = NULL; 845 the_dev = NULL;
839} 846}
840 847
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
index 3c8c0c9f9d72..b56e1e7d423c 100644
--- a/drivers/usb/gadget/u_ether.h
+++ b/drivers/usb/gadget/u_ether.h
@@ -62,6 +62,10 @@ struct gether {
62 62
63 /* hooks for added framing, as needed for RNDIS and EEM. */ 63 /* hooks for added framing, as needed for RNDIS and EEM. */
64 u32 header_len; 64 u32 header_len;
65 /* NCM requires fixed size bundles */
66 bool is_fixed;
67 u32 fixed_out_len;
68 u32 fixed_in_len;
65 struct sk_buff *(*wrap)(struct gether *port, 69 struct sk_buff *(*wrap)(struct gether *port,
66 struct sk_buff *skb); 70 struct sk_buff *skb);
67 int (*unwrap)(struct gether *port, 71 int (*unwrap)(struct gether *port,
@@ -103,6 +107,7 @@ static inline bool can_support_ecm(struct usb_gadget *gadget)
103/* each configuration may bind one instance of an ethernet link */ 107/* each configuration may bind one instance of an ethernet link */
104int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 108int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
105int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 109int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
110int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
106int eem_bind_config(struct usb_configuration *c); 111int eem_bind_config(struct usb_configuration *c);
107 112
108#ifdef USB_ETH_RNDIS 113#ifdef USB_ETH_RNDIS
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 01e5354a4c20..40f7716b31fc 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -105,11 +105,15 @@ struct gs_port {
105 wait_queue_head_t close_wait; /* wait for last close */ 105 wait_queue_head_t close_wait; /* wait for last close */
106 106
107 struct list_head read_pool; 107 struct list_head read_pool;
108 int read_started;
109 int read_allocated;
108 struct list_head read_queue; 110 struct list_head read_queue;
109 unsigned n_read; 111 unsigned n_read;
110 struct tasklet_struct push; 112 struct tasklet_struct push;
111 113
112 struct list_head write_pool; 114 struct list_head write_pool;
115 int write_started;
116 int write_allocated;
113 struct gs_buf port_write_buf; 117 struct gs_buf port_write_buf;
114 wait_queue_head_t drain_wait; /* wait while writes drain */ 118 wait_queue_head_t drain_wait; /* wait while writes drain */
115 119
@@ -363,6 +367,9 @@ __acquires(&port->port_lock)
363 struct usb_request *req; 367 struct usb_request *req;
364 int len; 368 int len;
365 369
370 if (port->write_started >= QUEUE_SIZE)
371 break;
372
366 req = list_entry(pool->next, struct usb_request, list); 373 req = list_entry(pool->next, struct usb_request, list);
367 len = gs_send_packet(port, req->buf, in->maxpacket); 374 len = gs_send_packet(port, req->buf, in->maxpacket);
368 if (len == 0) { 375 if (len == 0) {
@@ -397,6 +404,8 @@ __acquires(&port->port_lock)
397 break; 404 break;
398 } 405 }
399 406
407 port->write_started++;
408
400 /* abort immediately after disconnect */ 409 /* abort immediately after disconnect */
401 if (!port->port_usb) 410 if (!port->port_usb)
402 break; 411 break;
@@ -418,7 +427,6 @@ __acquires(&port->port_lock)
418{ 427{
419 struct list_head *pool = &port->read_pool; 428 struct list_head *pool = &port->read_pool;
420 struct usb_ep *out = port->port_usb->out; 429 struct usb_ep *out = port->port_usb->out;
421 unsigned started = 0;
422 430
423 while (!list_empty(pool)) { 431 while (!list_empty(pool)) {
424 struct usb_request *req; 432 struct usb_request *req;
@@ -430,6 +438,9 @@ __acquires(&port->port_lock)
430 if (!tty) 438 if (!tty)
431 break; 439 break;
432 440
441 if (port->read_started >= QUEUE_SIZE)
442 break;
443
433 req = list_entry(pool->next, struct usb_request, list); 444 req = list_entry(pool->next, struct usb_request, list);
434 list_del(&req->list); 445 list_del(&req->list);
435 req->length = out->maxpacket; 446 req->length = out->maxpacket;
@@ -447,13 +458,13 @@ __acquires(&port->port_lock)
447 list_add(&req->list, pool); 458 list_add(&req->list, pool);
448 break; 459 break;
449 } 460 }
450 started++; 461 port->read_started++;
451 462
452 /* abort immediately after disconnect */ 463 /* abort immediately after disconnect */
453 if (!port->port_usb) 464 if (!port->port_usb)
454 break; 465 break;
455 } 466 }
456 return started; 467 return port->read_started;
457} 468}
458 469
459/* 470/*
@@ -535,6 +546,7 @@ static void gs_rx_push(unsigned long _port)
535 } 546 }
536recycle: 547recycle:
537 list_move(&req->list, &port->read_pool); 548 list_move(&req->list, &port->read_pool);
549 port->read_started--;
538 } 550 }
539 551
540 /* Push from tty to ldisc; without low_latency set this is handled by 552 /* Push from tty to ldisc; without low_latency set this is handled by
@@ -587,6 +599,7 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
587 599
588 spin_lock(&port->port_lock); 600 spin_lock(&port->port_lock);
589 list_add(&req->list, &port->write_pool); 601 list_add(&req->list, &port->write_pool);
602 port->write_started--;
590 603
591 switch (req->status) { 604 switch (req->status) {
592 default: 605 default:
@@ -608,7 +621,8 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
608 spin_unlock(&port->port_lock); 621 spin_unlock(&port->port_lock);
609} 622}
610 623
611static void gs_free_requests(struct usb_ep *ep, struct list_head *head) 624static void gs_free_requests(struct usb_ep *ep, struct list_head *head,
625 int *allocated)
612{ 626{
613 struct usb_request *req; 627 struct usb_request *req;
614 628
@@ -616,25 +630,31 @@ static void gs_free_requests(struct usb_ep *ep, struct list_head *head)
616 req = list_entry(head->next, struct usb_request, list); 630 req = list_entry(head->next, struct usb_request, list);
617 list_del(&req->list); 631 list_del(&req->list);
618 gs_free_req(ep, req); 632 gs_free_req(ep, req);
633 if (allocated)
634 (*allocated)--;
619 } 635 }
620} 636}
621 637
622static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head, 638static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head,
623 void (*fn)(struct usb_ep *, struct usb_request *)) 639 void (*fn)(struct usb_ep *, struct usb_request *),
640 int *allocated)
624{ 641{
625 int i; 642 int i;
626 struct usb_request *req; 643 struct usb_request *req;
644 int n = allocated ? QUEUE_SIZE - *allocated : QUEUE_SIZE;
627 645
628 /* Pre-allocate up to QUEUE_SIZE transfers, but if we can't 646 /* Pre-allocate up to QUEUE_SIZE transfers, but if we can't
629 * do quite that many this time, don't fail ... we just won't 647 * do quite that many this time, don't fail ... we just won't
630 * be as speedy as we might otherwise be. 648 * be as speedy as we might otherwise be.
631 */ 649 */
632 for (i = 0; i < QUEUE_SIZE; i++) { 650 for (i = 0; i < n; i++) {
633 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC); 651 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
634 if (!req) 652 if (!req)
635 return list_empty(head) ? -ENOMEM : 0; 653 return list_empty(head) ? -ENOMEM : 0;
636 req->complete = fn; 654 req->complete = fn;
637 list_add_tail(&req->list, head); 655 list_add_tail(&req->list, head);
656 if (allocated)
657 (*allocated)++;
638 } 658 }
639 return 0; 659 return 0;
640} 660}
@@ -661,14 +681,15 @@ static int gs_start_io(struct gs_port *port)
661 * configurations may use different endpoints with a given port; 681 * configurations may use different endpoints with a given port;
662 * and high speed vs full speed changes packet sizes too. 682 * and high speed vs full speed changes packet sizes too.
663 */ 683 */
664 status = gs_alloc_requests(ep, head, gs_read_complete); 684 status = gs_alloc_requests(ep, head, gs_read_complete,
685 &port->read_allocated);
665 if (status) 686 if (status)
666 return status; 687 return status;
667 688
668 status = gs_alloc_requests(port->port_usb->in, &port->write_pool, 689 status = gs_alloc_requests(port->port_usb->in, &port->write_pool,
669 gs_write_complete); 690 gs_write_complete, &port->write_allocated);
670 if (status) { 691 if (status) {
671 gs_free_requests(ep, head); 692 gs_free_requests(ep, head, &port->read_allocated);
672 return status; 693 return status;
673 } 694 }
674 695
@@ -680,8 +701,9 @@ static int gs_start_io(struct gs_port *port)
680 if (started) { 701 if (started) {
681 tty_wakeup(port->port_tty); 702 tty_wakeup(port->port_tty);
682 } else { 703 } else {
683 gs_free_requests(ep, head); 704 gs_free_requests(ep, head, &port->read_allocated);
684 gs_free_requests(port->port_usb->in, &port->write_pool); 705 gs_free_requests(port->port_usb->in, &port->write_pool,
706 &port->write_allocated);
685 status = -EIO; 707 status = -EIO;
686 } 708 }
687 709
@@ -1315,8 +1337,12 @@ void gserial_disconnect(struct gserial *gser)
1315 spin_lock_irqsave(&port->port_lock, flags); 1337 spin_lock_irqsave(&port->port_lock, flags);
1316 if (port->open_count == 0 && !port->openclose) 1338 if (port->open_count == 0 && !port->openclose)
1317 gs_buf_free(&port->port_write_buf); 1339 gs_buf_free(&port->port_write_buf);
1318 gs_free_requests(gser->out, &port->read_pool); 1340 gs_free_requests(gser->out, &port->read_pool, NULL);
1319 gs_free_requests(gser->out, &port->read_queue); 1341 gs_free_requests(gser->out, &port->read_queue, NULL);
1320 gs_free_requests(gser->in, &port->write_pool); 1342 gs_free_requests(gser->in, &port->write_pool, NULL);
1343
1344 port->read_allocated = port->read_started =
1345 port->write_allocated = port->write_started = 0;
1346
1321 spin_unlock_irqrestore(&port->port_lock, flags); 1347 spin_unlock_irqrestore(&port->port_lock, flags);
1322} 1348}
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index de1deb7a3c63..a5a0fdb808c7 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -308,7 +308,7 @@ static const struct uvc_descriptor_header * const uvc_hs_streaming_cls[] = {
308 * USB configuration 308 * USB configuration
309 */ 309 */
310 310
311static int __ref 311static int __init
312webcam_config_bind(struct usb_configuration *c) 312webcam_config_bind(struct usb_configuration *c)
313{ 313{
314 return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls, 314 return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls,
@@ -317,7 +317,6 @@ webcam_config_bind(struct usb_configuration *c)
317 317
318static struct usb_configuration webcam_config_driver = { 318static struct usb_configuration webcam_config_driver = {
319 .label = webcam_config_label, 319 .label = webcam_config_label,
320 .bind = webcam_config_bind,
321 .bConfigurationValue = 1, 320 .bConfigurationValue = 1,
322 .iConfiguration = 0, /* dynamic */ 321 .iConfiguration = 0, /* dynamic */
323 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 322 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -330,7 +329,7 @@ webcam_unbind(struct usb_composite_dev *cdev)
330 return 0; 329 return 0;
331} 330}
332 331
333static int __ref 332static int __init
334webcam_bind(struct usb_composite_dev *cdev) 333webcam_bind(struct usb_composite_dev *cdev)
335{ 334{
336 int ret; 335 int ret;
@@ -354,7 +353,8 @@ webcam_bind(struct usb_composite_dev *cdev)
354 webcam_config_driver.iConfiguration = ret; 353 webcam_config_driver.iConfiguration = ret;
355 354
356 /* Register our configuration. */ 355 /* Register our configuration. */
357 if ((ret = usb_add_config(cdev, &webcam_config_driver)) < 0) 356 if ((ret = usb_add_config(cdev, &webcam_config_driver,
357 webcam_config_bind)) < 0)
358 goto error; 358 goto error;
359 359
360 INFO(cdev, "Webcam Video Gadget\n"); 360 INFO(cdev, "Webcam Video Gadget\n");
@@ -373,14 +373,13 @@ static struct usb_composite_driver webcam_driver = {
373 .name = "g_webcam", 373 .name = "g_webcam",
374 .dev = &webcam_device_descriptor, 374 .dev = &webcam_device_descriptor,
375 .strings = webcam_device_strings, 375 .strings = webcam_device_strings,
376 .bind = webcam_bind,
377 .unbind = webcam_unbind, 376 .unbind = webcam_unbind,
378}; 377};
379 378
380static int __init 379static int __init
381webcam_init(void) 380webcam_init(void)
382{ 381{
383 return usb_composite_register(&webcam_driver); 382 return usb_composite_probe(&webcam_driver, webcam_bind);
384} 383}
385 384
386static void __exit 385static void __exit
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index cf353920bb1c..6d16db9d9d2d 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -264,7 +264,7 @@ static void zero_resume(struct usb_composite_dev *cdev)
264 264
265/*-------------------------------------------------------------------------*/ 265/*-------------------------------------------------------------------------*/
266 266
267static int __ref zero_bind(struct usb_composite_dev *cdev) 267static int __init zero_bind(struct usb_composite_dev *cdev)
268{ 268{
269 int gcnum; 269 int gcnum;
270 struct usb_gadget *gadget = cdev->gadget; 270 struct usb_gadget *gadget = cdev->gadget;
@@ -340,7 +340,6 @@ static struct usb_composite_driver zero_driver = {
340 .name = "zero", 340 .name = "zero",
341 .dev = &device_desc, 341 .dev = &device_desc,
342 .strings = dev_strings, 342 .strings = dev_strings,
343 .bind = zero_bind,
344 .unbind = zero_unbind, 343 .unbind = zero_unbind,
345 .suspend = zero_suspend, 344 .suspend = zero_suspend,
346 .resume = zero_resume, 345 .resume = zero_resume,
@@ -351,7 +350,7 @@ MODULE_LICENSE("GPL");
351 350
352static int __init init(void) 351static int __init init(void)
353{ 352{
354 return usb_composite_register(&zero_driver); 353 return usb_composite_probe(&zero_driver, zero_bind);
355} 354}
356module_init(init); 355module_init(init);
357 356
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 2d926cec0725..ab085f12d570 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -91,14 +91,28 @@ config USB_EHCI_TT_NEWSCHED
91 91
92 If unsure, say Y. 92 If unsure, say Y.
93 93
94config USB_EHCI_HCD_PMC_MSP
95 tristate "EHCI support for on-chip PMC MSP71xx USB controller"
96 depends on USB_EHCI_HCD && MSP_HAS_USB
97 default n
98 select USB_EHCI_BIG_ENDIAN_DESC
99 select USB_EHCI_BIG_ENDIAN_MMIO
100 ---help---
101 Enables support for the onchip USB controller on the PMC_MSP7100 Family SoC's.
102 If unsure, say N.
103
94config USB_EHCI_BIG_ENDIAN_MMIO 104config USB_EHCI_BIG_ENDIAN_MMIO
95 bool 105 bool
96 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX) 106 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \
107 ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
108 PPC_MPC512x || CPU_CAVIUM_OCTEON || \
109 PMC_MSP || SPARC_LEON)
97 default y 110 default y
98 111
99config USB_EHCI_BIG_ENDIAN_DESC 112config USB_EHCI_BIG_ENDIAN_DESC
100 bool 113 bool
101 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX) 114 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
115 PPC_MPC512x || PMC_MSP || SPARC_LEON)
102 default y 116 default y
103 117
104config XPS_USB_HCD_XILINX 118config XPS_USB_HCD_XILINX
@@ -112,10 +126,14 @@ config XPS_USB_HCD_XILINX
112 support both high speed and full speed devices, or high speed 126 support both high speed and full speed devices, or high speed
113 devices only. 127 devices only.
114 128
129config USB_FSL_MPH_DR_OF
130 tristate
131
115config USB_EHCI_FSL 132config USB_EHCI_FSL
116 bool "Support for Freescale on-chip EHCI USB controller" 133 bool "Support for Freescale on-chip EHCI USB controller"
117 depends on USB_EHCI_HCD && FSL_SOC 134 depends on USB_EHCI_HCD && FSL_SOC
118 select USB_EHCI_ROOT_HUB_TT 135 select USB_EHCI_ROOT_HUB_TT
136 select USB_FSL_MPH_DR_OF if OF
119 ---help--- 137 ---help---
120 Variation of ARC USB block used in some Freescale chips. 138 Variation of ARC USB block used in some Freescale chips.
121 139
@@ -126,6 +144,35 @@ config USB_EHCI_MXC
126 ---help--- 144 ---help---
127 Variation of ARC USB block used in some Freescale chips. 145 Variation of ARC USB block used in some Freescale chips.
128 146
147config USB_EHCI_HCD_OMAP
148 bool "EHCI support for OMAP3 and later chips"
149 depends on USB_EHCI_HCD && ARCH_OMAP
150 default y
151 --- help ---
152 Enables support for the on-chip EHCI controller on
153 OMAP3 and later chips.
154
155config USB_EHCI_MSM
156 bool "Support for MSM on-chip EHCI USB controller"
157 depends on USB_EHCI_HCD && ARCH_MSM
158 select USB_EHCI_ROOT_HUB_TT
159 select USB_MSM_OTG
160 ---help---
161 Enables support for the USB Host controller present on the
162 Qualcomm chipsets. Root Hub has inbuilt TT.
163 This driver depends on OTG driver for PHY initialization,
164 clock management, powering up VBUS, and power management.
165 This driver is not supported on boards like trout which
166 has an external PHY.
167
168config USB_EHCI_TEGRA
169 boolean "NVIDIA Tegra HCD support"
170 depends on USB_EHCI_HCD && ARCH_TEGRA
171 select USB_EHCI_ROOT_HUB_TT
172 help
173 This driver enables support for the internal USB Host Controllers
174 found in NVIDIA Tegra SoCs. The controllers are EHCI compliant.
175
129config USB_EHCI_HCD_PPC_OF 176config USB_EHCI_HCD_PPC_OF
130 bool "EHCI support for PPC USB controller on OF platform bus" 177 bool "EHCI support for PPC USB controller on OF platform bus"
131 depends on USB_EHCI_HCD && PPC_OF 178 depends on USB_EHCI_HCD && PPC_OF
@@ -134,12 +181,42 @@ config USB_EHCI_HCD_PPC_OF
134 Enables support for the USB controller present on the PowerPC 181 Enables support for the USB controller present on the PowerPC
135 OpenFirmware platform bus. 182 OpenFirmware platform bus.
136 183
184config USB_EHCI_SH
185 bool "EHCI support for SuperH USB controller"
186 depends on USB_EHCI_HCD && SUPERH
187 ---help---
188 Enables support for the on-chip EHCI controller on the SuperH.
189 If you use the PCI EHCI controller, this option is not necessary.
190
191config USB_EHCI_S5P
192 boolean "S5P EHCI support"
193 depends on USB_EHCI_HCD && PLAT_S5P
194 help
195 Enable support for the S5P SOC's on-chip EHCI controller.
196
137config USB_W90X900_EHCI 197config USB_W90X900_EHCI
138 bool "W90X900(W90P910) EHCI support" 198 bool "W90X900(W90P910) EHCI support"
139 depends on USB_EHCI_HCD && ARCH_W90X900 199 depends on USB_EHCI_HCD && ARCH_W90X900
140 ---help--- 200 ---help---
141 Enables support for the W90X900 USB controller 201 Enables support for the W90X900 USB controller
142 202
203config USB_CNS3XXX_EHCI
204 bool "Cavium CNS3XXX EHCI Module"
205 depends on USB_EHCI_HCD && ARCH_CNS3XXX
206 ---help---
207 Enable support for the CNS3XXX SOC's on-chip EHCI controller.
208 It is needed for high-speed (480Mbit/sec) USB 2.0 device
209 support.
210
211config USB_EHCI_ATH79
212 bool "EHCI support for AR7XXX/AR9XXX SoCs"
213 depends on USB_EHCI_HCD && (SOC_AR71XX || SOC_AR724X || SOC_AR913X)
214 select USB_EHCI_ROOT_HUB_TT
215 default y
216 ---help---
217 Enables support for the built-in EHCI controller present
218 on the Atheros AR7XXX/AR9XXX SoCs.
219
143config USB_OXU210HP_HCD 220config USB_OXU210HP_HCD
144 tristate "OXU210HP HCD support" 221 tristate "OXU210HP HCD support"
145 depends on USB 222 depends on USB
@@ -225,6 +302,14 @@ config USB_OHCI_HCD_OMAP3
225 Enables support for the on-chip OHCI controller on 302 Enables support for the on-chip OHCI controller on
226 OMAP3 and later chips. 303 OMAP3 and later chips.
227 304
305config USB_OHCI_ATH79
306 bool "USB OHCI support for the Atheros AR71XX/AR7240 SoCs"
307 depends on USB_OHCI_HCD && (SOC_AR71XX || SOC_AR724X)
308 default y
309 help
310 Enables support for the built-in OHCI controller present on the
311 Atheros AR71XX/AR7240 SoCs.
312
228config USB_OHCI_HCD_PPC_SOC 313config USB_OHCI_HCD_PPC_SOC
229 bool "OHCI support for on-chip PPC USB controller" 314 bool "OHCI support for on-chip PPC USB controller"
230 depends on USB_OHCI_HCD && (STB03xxx || PPC_MPC52xx) 315 depends on USB_OHCI_HCD && (STB03xxx || PPC_MPC52xx)
@@ -279,6 +364,20 @@ config USB_OHCI_HCD_SSB
279 364
280 If unsure, say N. 365 If unsure, say N.
281 366
367config USB_OHCI_SH
368 bool "OHCI support for SuperH USB controller"
369 depends on USB_OHCI_HCD && SUPERH
370 ---help---
371 Enables support for the on-chip OHCI controller on the SuperH.
372 If you use the PCI OHCI controller, this option is not necessary.
373
374config USB_CNS3XXX_OHCI
375 bool "Cavium CNS3XXX OHCI Module"
376 depends on USB_OHCI_HCD && ARCH_CNS3XXX
377 ---help---
378 Enable support for the CNS3XXX SOC's on-chip OHCI controller.
379 It is needed for low-speed USB 1.0 device support.
380
282config USB_OHCI_BIG_ENDIAN_DESC 381config USB_OHCI_BIG_ENDIAN_DESC
283 bool 382 bool
284 depends on USB_OHCI_HCD 383 depends on USB_OHCI_HCD
@@ -297,7 +396,7 @@ config USB_OHCI_LITTLE_ENDIAN
297 396
298config USB_UHCI_HCD 397config USB_UHCI_HCD
299 tristate "UHCI HCD (most Intel and VIA) support" 398 tristate "UHCI HCD (most Intel and VIA) support"
300 depends on USB && PCI 399 depends on USB && (PCI || SPARC_LEON)
301 ---help--- 400 ---help---
302 The Universal Host Controller Interface is a standard by Intel for 401 The Universal Host Controller Interface is a standard by Intel for
303 accessing the USB hardware in the PC (which is also called the USB 402 accessing the USB hardware in the PC (which is also called the USB
@@ -306,11 +405,27 @@ config USB_UHCI_HCD
306 with Intel PCI chipsets (like intel 430TX, 440FX, 440LX, 440BX, 405 with Intel PCI chipsets (like intel 430TX, 440FX, 440LX, 440BX,
307 i810, i820) conform to this standard. Also all VIA PCI chipsets 406 i810, i820) conform to this standard. Also all VIA PCI chipsets
308 (like VIA VP2, VP3, MVP3, Apollo Pro, Apollo Pro II or Apollo Pro 407 (like VIA VP2, VP3, MVP3, Apollo Pro, Apollo Pro II or Apollo Pro
309 133). If unsure, say Y. 408 133) and LEON/GRLIB SoCs with the GRUSBHC controller.
409 If unsure, say Y.
310 410
311 To compile this driver as a module, choose M here: the 411 To compile this driver as a module, choose M here: the
312 module will be called uhci-hcd. 412 module will be called uhci-hcd.
313 413
414config USB_UHCI_SUPPORT_NON_PCI_HC
415 bool
416 depends on USB_UHCI_HCD
417 default y if SPARC_LEON
418
419config USB_UHCI_BIG_ENDIAN_MMIO
420 bool
421 depends on USB_UHCI_SUPPORT_NON_PCI_HC && SPARC_LEON
422 default y
423
424config USB_UHCI_BIG_ENDIAN_DESC
425 bool
426 depends on USB_UHCI_SUPPORT_NON_PCI_HC && SPARC_LEON
427 default y
428
314config USB_FHCI_HCD 429config USB_FHCI_HCD
315 tristate "Freescale QE USB Host Controller support" 430 tristate "Freescale QE USB Host Controller support"
316 depends on USB && OF_GPIO && QE_GPIO && QUICC_ENGINE 431 depends on USB && OF_GPIO && QE_GPIO && QUICC_ENGINE
@@ -326,7 +441,7 @@ config FHCI_DEBUG
326 depends on USB_FHCI_HCD && DEBUG_FS 441 depends on USB_FHCI_HCD && DEBUG_FS
327 help 442 help
328 Say "y" to see some FHCI debug information and statistics 443 Say "y" to see some FHCI debug information and statistics
329 throught debugfs. 444 through debugfs.
330 445
331config USB_U132_HCD 446config USB_U132_HCD
332 tristate "Elan U132 Adapter Host Controller" 447 tristate "Elan U132 Adapter Host Controller"
@@ -368,6 +483,16 @@ config USB_SL811_HCD
368 To compile this driver as a module, choose M here: the 483 To compile this driver as a module, choose M here: the
369 module will be called sl811-hcd. 484 module will be called sl811-hcd.
370 485
486config USB_SL811_HCD_ISO
487 bool "partial ISO support"
488 depends on USB_SL811_HCD
489 help
490 The driver doesn't support iso_frame_desc (yet), but for some simple
491 devices that just queue one ISO frame per URB, then ISO transfers
492 "should" work using the normal urb status fields.
493
494 If unsure, say N.
495
371config USB_SL811_CS 496config USB_SL811_CS
372 tristate "CF/PCMCIA support for SL811HS HCD" 497 tristate "CF/PCMCIA support for SL811HS HCD"
373 depends on USB_SL811_HCD && PCMCIA 498 depends on USB_SL811_HCD && PCMCIA
@@ -428,3 +553,28 @@ config USB_IMX21_HCD
428 To compile this driver as a module, choose M here: the 553 To compile this driver as a module, choose M here: the
429 module will be called "imx21-hcd". 554 module will be called "imx21-hcd".
430 555
556config USB_OCTEON_EHCI
557 bool "Octeon on-chip EHCI support"
558 depends on USB && USB_EHCI_HCD && CPU_CAVIUM_OCTEON
559 default n
560 select USB_EHCI_BIG_ENDIAN_MMIO
561 help
562 Enable support for the Octeon II SOC's on-chip EHCI
563 controller. It is needed for high-speed (480Mbit/sec)
564 USB 2.0 device support. All CN6XXX based chips with USB are
565 supported.
566
567config USB_OCTEON_OHCI
568 bool "Octeon on-chip OHCI support"
569 depends on USB && USB_OHCI_HCD && CPU_CAVIUM_OCTEON
570 default USB_OCTEON_EHCI
571 select USB_OHCI_BIG_ENDIAN_MMIO
572 select USB_OHCI_LITTLE_ENDIAN
573 help
574 Enable support for the Octeon II SOC's on-chip OHCI
575 controller. It is needed for low-speed USB 1.0 device
576 support. All CN6XXX based chips with USB are supported.
577
578config USB_OCTEON2_COMMON
579 bool
580 default y if USB_OCTEON_EHCI || USB_OCTEON_OHCI
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index b6315aa47f7a..624a362f2fee 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -2,17 +2,17 @@
2# Makefile for USB Host Controller Drivers 2# Makefile for USB Host Controller Drivers
3# 3#
4 4
5ifeq ($(CONFIG_USB_DEBUG),y) 5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6 EXTRA_CFLAGS += -DDEBUG 6
7endif 7isp1760-y := isp1760-hcd.o isp1760-if.o
8 8
9isp1760-objs := isp1760-hcd.o isp1760-if.o 9fhci-y := fhci-hcd.o fhci-hub.o fhci-q.o
10fhci-objs := fhci-hcd.o fhci-hub.o fhci-q.o fhci-mem.o \ 10fhci-y += fhci-mem.o fhci-tds.o fhci-sched.o
11 fhci-tds.o fhci-sched.o 11
12ifeq ($(CONFIG_FHCI_DEBUG),y) 12fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o
13fhci-objs += fhci-dbg.o 13
14endif 14xhci-hcd-y := xhci.o xhci-mem.o xhci-pci.o
15xhci-hcd-objs := xhci.o xhci-mem.o xhci-pci.o xhci-ring.o xhci-hub.o xhci-dbg.o 15xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o
16 16
17obj-$(CONFIG_USB_WHCI_HCD) += whci/ 17obj-$(CONFIG_USB_WHCI_HCD) += whci/
18 18
@@ -33,4 +33,5 @@ obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
33obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o 33obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
34obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o 34obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
35obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o 35obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
36 36obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
37obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
diff --git a/drivers/usb/host/ehci-ath79.c b/drivers/usb/host/ehci-ath79.c
new file mode 100644
index 000000000000..aa248c2f2c60
--- /dev/null
+++ b/drivers/usb/host/ehci-ath79.c
@@ -0,0 +1,204 @@
1/*
2 * Bus Glue for Atheros AR7XXX/AR9XXX built-in EHCI controller.
3 *
4 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * Parts of this file are based on Atheros' 2.6.15 BSP
8 * Copyright (C) 2007 Atheros Communications, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
15#include <linux/platform_device.h>
16
17enum {
18 EHCI_ATH79_IP_V1 = 0,
19 EHCI_ATH79_IP_V2,
20};
21
22static const struct platform_device_id ehci_ath79_id_table[] = {
23 {
24 .name = "ar71xx-ehci",
25 .driver_data = EHCI_ATH79_IP_V1,
26 },
27 {
28 .name = "ar724x-ehci",
29 .driver_data = EHCI_ATH79_IP_V2,
30 },
31 {
32 .name = "ar913x-ehci",
33 .driver_data = EHCI_ATH79_IP_V2,
34 },
35 {
36 /* terminating entry */
37 },
38};
39
40MODULE_DEVICE_TABLE(platform, ehci_ath79_id_table);
41
42static int ehci_ath79_init(struct usb_hcd *hcd)
43{
44 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
45 struct platform_device *pdev = to_platform_device(hcd->self.controller);
46 const struct platform_device_id *id;
47 int ret;
48
49 id = platform_get_device_id(pdev);
50 if (!id) {
51 dev_err(hcd->self.controller, "missing device id\n");
52 return -EINVAL;
53 }
54
55 switch (id->driver_data) {
56 case EHCI_ATH79_IP_V1:
57 ehci->has_synopsys_hc_bug = 1;
58
59 ehci->caps = hcd->regs;
60 ehci->regs = hcd->regs +
61 HC_LENGTH(ehci,
62 ehci_readl(ehci, &ehci->caps->hc_capbase));
63 break;
64
65 case EHCI_ATH79_IP_V2:
66 hcd->has_tt = 1;
67
68 ehci->caps = hcd->regs + 0x100;
69 ehci->regs = hcd->regs + 0x100 +
70 HC_LENGTH(ehci,
71 ehci_readl(ehci, &ehci->caps->hc_capbase));
72 break;
73
74 default:
75 BUG();
76 }
77
78 dbg_hcs_params(ehci, "reset");
79 dbg_hcc_params(ehci, "reset");
80 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
81 ehci->sbrn = 0x20;
82
83 ehci_reset(ehci);
84
85 ret = ehci_init(hcd);
86 if (ret)
87 return ret;
88
89 ehci_port_power(ehci, 0);
90
91 return 0;
92}
93
94static const struct hc_driver ehci_ath79_hc_driver = {
95 .description = hcd_name,
96 .product_desc = "Atheros built-in EHCI controller",
97 .hcd_priv_size = sizeof(struct ehci_hcd),
98 .irq = ehci_irq,
99 .flags = HCD_MEMORY | HCD_USB2,
100
101 .reset = ehci_ath79_init,
102 .start = ehci_run,
103 .stop = ehci_stop,
104 .shutdown = ehci_shutdown,
105
106 .urb_enqueue = ehci_urb_enqueue,
107 .urb_dequeue = ehci_urb_dequeue,
108 .endpoint_disable = ehci_endpoint_disable,
109 .endpoint_reset = ehci_endpoint_reset,
110
111 .get_frame_number = ehci_get_frame,
112
113 .hub_status_data = ehci_hub_status_data,
114 .hub_control = ehci_hub_control,
115
116 .relinquish_port = ehci_relinquish_port,
117 .port_handed_over = ehci_port_handed_over,
118
119 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
120};
121
122static int ehci_ath79_probe(struct platform_device *pdev)
123{
124 struct usb_hcd *hcd;
125 struct resource *res;
126 int irq;
127 int ret;
128
129 if (usb_disabled())
130 return -ENODEV;
131
132 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
133 if (!res) {
134 dev_dbg(&pdev->dev, "no IRQ specified\n");
135 return -ENODEV;
136 }
137 irq = res->start;
138
139 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
140 if (!res) {
141 dev_dbg(&pdev->dev, "no base address specified\n");
142 return -ENODEV;
143 }
144
145 hcd = usb_create_hcd(&ehci_ath79_hc_driver, &pdev->dev,
146 dev_name(&pdev->dev));
147 if (!hcd)
148 return -ENOMEM;
149
150 hcd->rsrc_start = res->start;
151 hcd->rsrc_len = res->end - res->start + 1;
152
153 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
154 dev_dbg(&pdev->dev, "controller already in use\n");
155 ret = -EBUSY;
156 goto err_put_hcd;
157 }
158
159 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
160 if (!hcd->regs) {
161 dev_dbg(&pdev->dev, "error mapping memory\n");
162 ret = -EFAULT;
163 goto err_release_region;
164 }
165
166 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
167 if (ret)
168 goto err_iounmap;
169
170 return 0;
171
172err_iounmap:
173 iounmap(hcd->regs);
174
175err_release_region:
176 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
177err_put_hcd:
178 usb_put_hcd(hcd);
179 return ret;
180}
181
182static int ehci_ath79_remove(struct platform_device *pdev)
183{
184 struct usb_hcd *hcd = platform_get_drvdata(pdev);
185
186 usb_remove_hcd(hcd);
187 iounmap(hcd->regs);
188 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
189 usb_put_hcd(hcd);
190
191 return 0;
192}
193
194static struct platform_driver ehci_ath79_driver = {
195 .probe = ehci_ath79_probe,
196 .remove = ehci_ath79_remove,
197 .id_table = ehci_ath79_id_table,
198 .driver = {
199 .owner = THIS_MODULE,
200 .name = "ath79-ehci",
201 }
202};
203
204MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ath79-ehci");
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index 51bd0edf544f..a5a3ef1f0096 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -56,7 +56,7 @@ static int ehci_atmel_setup(struct usb_hcd *hcd)
56 /* registers start at offset 0x0 */ 56 /* registers start at offset 0x0 */
57 ehci->caps = hcd->regs; 57 ehci->caps = hcd->regs;
58 ehci->regs = hcd->regs + 58 ehci->regs = hcd->regs +
59 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 59 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
60 dbg_hcs_params(ehci, "reset"); 60 dbg_hcs_params(ehci, "reset");
61 dbg_hcc_params(ehci, "reset"); 61 dbg_hcc_params(ehci, "reset");
62 62
@@ -99,6 +99,7 @@ static const struct hc_driver ehci_atmel_hc_driver = {
99 .urb_enqueue = ehci_urb_enqueue, 99 .urb_enqueue = ehci_urb_enqueue,
100 .urb_dequeue = ehci_urb_dequeue, 100 .urb_dequeue = ehci_urb_dequeue,
101 .endpoint_disable = ehci_endpoint_disable, 101 .endpoint_disable = ehci_endpoint_disable,
102 .endpoint_reset = ehci_endpoint_reset,
102 103
103 /* scheduling support */ 104 /* scheduling support */
104 .get_frame_number = ehci_get_frame, 105 .get_frame_number = ehci_get_frame,
@@ -110,9 +111,11 @@ static const struct hc_driver ehci_atmel_hc_driver = {
110 .bus_resume = ehci_bus_resume, 111 .bus_resume = ehci_bus_resume,
111 .relinquish_port = ehci_relinquish_port, 112 .relinquish_port = ehci_relinquish_port,
112 .port_handed_over = ehci_port_handed_over, 113 .port_handed_over = ehci_port_handed_over,
114
115 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
113}; 116};
114 117
115static int __init ehci_atmel_drv_probe(struct platform_device *pdev) 118static int __devinit ehci_atmel_drv_probe(struct platform_device *pdev)
116{ 119{
117 struct usb_hcd *hcd; 120 struct usb_hcd *hcd;
118 const struct hc_driver *driver = &ehci_atmel_hc_driver; 121 const struct hc_driver *driver = &ehci_atmel_hc_driver;
@@ -204,7 +207,7 @@ fail_create_hcd:
204 return retval; 207 return retval;
205} 208}
206 209
207static int __exit ehci_atmel_drv_remove(struct platform_device *pdev) 210static int __devexit ehci_atmel_drv_remove(struct platform_device *pdev)
208{ 211{
209 struct usb_hcd *hcd = platform_get_drvdata(pdev); 212 struct usb_hcd *hcd = platform_get_drvdata(pdev);
210 213
@@ -224,7 +227,7 @@ static int __exit ehci_atmel_drv_remove(struct platform_device *pdev)
224 227
225static struct platform_driver ehci_atmel_driver = { 228static struct platform_driver ehci_atmel_driver = {
226 .probe = ehci_atmel_drv_probe, 229 .probe = ehci_atmel_drv_probe,
227 .remove = __exit_p(ehci_atmel_drv_remove), 230 .remove = __devexit_p(ehci_atmel_drv_remove),
228 .shutdown = usb_hcd_platform_shutdown, 231 .shutdown = usb_hcd_platform_shutdown,
229 .driver.name = "atmel-ehci", 232 .driver.name = "atmel-ehci",
230}; 233};
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index 2baf8a849086..42ae57409908 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -175,7 +175,8 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
175 175
176 ehci = hcd_to_ehci(hcd); 176 ehci = hcd_to_ehci(hcd);
177 ehci->caps = hcd->regs; 177 ehci->caps = hcd->regs;
178 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase)); 178 ehci->regs = hcd->regs +
179 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
179 /* cache this readonly data; minimize chip reads */ 180 /* cache this readonly data; minimize chip reads */
180 ehci->hcs_params = readl(&ehci->caps->hcs_params); 181 ehci->hcs_params = readl(&ehci->caps->hcs_params);
181 182
@@ -215,10 +216,7 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
215 struct usb_hcd *hcd = dev_get_drvdata(dev); 216 struct usb_hcd *hcd = dev_get_drvdata(dev);
216 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 217 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
217 unsigned long flags; 218 unsigned long flags;
218 int rc; 219 int rc = 0;
219
220 return 0;
221 rc = 0;
222 220
223 if (time_before(jiffies, ehci->next_statechange)) 221 if (time_before(jiffies, ehci->next_statechange))
224 msleep(10); 222 msleep(10);
@@ -227,19 +225,19 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
227 * mark HW unaccessible. The PM and USB cores make sure that 225 * mark HW unaccessible. The PM and USB cores make sure that
228 * the root hub is either suspended or stopped. 226 * the root hub is either suspended or stopped.
229 */ 227 */
230 spin_lock_irqsave(&ehci->lock, flags);
231 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev)); 228 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
229 spin_lock_irqsave(&ehci->lock, flags);
232 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 230 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
233 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 231 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
234 232
235 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 233 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
236
237 au1xxx_stop_ehc();
238 spin_unlock_irqrestore(&ehci->lock, flags); 234 spin_unlock_irqrestore(&ehci->lock, flags);
239 235
240 // could save FLADJ in case of Vaux power loss 236 // could save FLADJ in case of Vaux power loss
241 // ... we'd only use it to handle clock skew 237 // ... we'd only use it to handle clock skew
242 238
239 au1xxx_stop_ehc();
240
243 return rc; 241 return rc;
244} 242}
245 243
diff --git a/drivers/usb/host/ehci-cns3xxx.c b/drivers/usb/host/ehci-cns3xxx.c
new file mode 100644
index 000000000000..d41745c6f0c4
--- /dev/null
+++ b/drivers/usb/host/ehci-cns3xxx.c
@@ -0,0 +1,171 @@
1/*
2 * Copyright 2008 Cavium Networks
3 *
4 * This file is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, Version 2, as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/platform_device.h>
10#include <linux/atomic.h>
11#include <mach/cns3xxx.h>
12#include <mach/pm.h>
13
14static int cns3xxx_ehci_init(struct usb_hcd *hcd)
15{
16 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
17 int retval;
18
19 /*
20 * EHCI and OHCI share the same clock and power,
21 * resetting twice would cause the 1st controller been reset.
22 * Therefore only do power up at the first up device, and
23 * power down at the last down device.
24 *
25 * Set USB AHB INCR length to 16
26 */
27 if (atomic_inc_return(&usb_pwr_ref) == 1) {
28 cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
29 cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
30 cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST);
31 __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG) | (0X2 << 24)),
32 MISC_CHIP_CONFIG_REG);
33 }
34
35 ehci->caps = hcd->regs;
36 ehci->regs = hcd->regs
37 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
38 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
39
40 hcd->has_tt = 0;
41 ehci_reset(ehci);
42
43 retval = ehci_init(hcd);
44 if (retval)
45 return retval;
46
47 ehci_port_power(ehci, 0);
48
49 return retval;
50}
51
52static const struct hc_driver cns3xxx_ehci_hc_driver = {
53 .description = hcd_name,
54 .product_desc = "CNS3XXX EHCI Host Controller",
55 .hcd_priv_size = sizeof(struct ehci_hcd),
56 .irq = ehci_irq,
57 .flags = HCD_MEMORY | HCD_USB2,
58 .reset = cns3xxx_ehci_init,
59 .start = ehci_run,
60 .stop = ehci_stop,
61 .shutdown = ehci_shutdown,
62 .urb_enqueue = ehci_urb_enqueue,
63 .urb_dequeue = ehci_urb_dequeue,
64 .endpoint_disable = ehci_endpoint_disable,
65 .endpoint_reset = ehci_endpoint_reset,
66 .get_frame_number = ehci_get_frame,
67 .hub_status_data = ehci_hub_status_data,
68 .hub_control = ehci_hub_control,
69#ifdef CONFIG_PM
70 .bus_suspend = ehci_bus_suspend,
71 .bus_resume = ehci_bus_resume,
72#endif
73 .relinquish_port = ehci_relinquish_port,
74 .port_handed_over = ehci_port_handed_over,
75
76 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
77};
78
79static int cns3xxx_ehci_probe(struct platform_device *pdev)
80{
81 struct device *dev = &pdev->dev;
82 struct usb_hcd *hcd;
83 const struct hc_driver *driver = &cns3xxx_ehci_hc_driver;
84 struct resource *res;
85 int irq;
86 int retval;
87
88 if (usb_disabled())
89 return -ENODEV;
90
91 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
92 if (!res) {
93 dev_err(dev, "Found HC with no IRQ.\n");
94 return -ENODEV;
95 }
96 irq = res->start;
97
98 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
99 if (!hcd)
100 return -ENOMEM;
101
102 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
103 if (!res) {
104 dev_err(dev, "Found HC with no register addr.\n");
105 retval = -ENODEV;
106 goto err1;
107 }
108
109 hcd->rsrc_start = res->start;
110 hcd->rsrc_len = res->end - res->start + 1;
111
112 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
113 driver->description)) {
114 dev_dbg(dev, "controller already in use\n");
115 retval = -EBUSY;
116 goto err1;
117 }
118
119 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
120 if (hcd->regs == NULL) {
121 dev_dbg(dev, "error mapping memory\n");
122 retval = -EFAULT;
123 goto err2;
124 }
125
126 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
127 if (retval == 0)
128 return retval;
129
130 iounmap(hcd->regs);
131err2:
132 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
133err1:
134 usb_put_hcd(hcd);
135
136 return retval;
137}
138
139static int cns3xxx_ehci_remove(struct platform_device *pdev)
140{
141 struct usb_hcd *hcd = platform_get_drvdata(pdev);
142
143 usb_remove_hcd(hcd);
144 iounmap(hcd->regs);
145 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
146
147 /*
148 * EHCI and OHCI share the same clock and power,
149 * resetting twice would cause the 1st controller been reset.
150 * Therefore only do power up at the first up device, and
151 * power down at the last down device.
152 */
153 if (atomic_dec_return(&usb_pwr_ref) == 0)
154 cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
155
156 usb_put_hcd(hcd);
157
158 platform_set_drvdata(pdev, NULL);
159
160 return 0;
161}
162
163MODULE_ALIAS("platform:cns3xxx-ehci");
164
165static struct platform_driver cns3xxx_ehci_driver = {
166 .probe = cns3xxx_ehci_probe,
167 .remove = cns3xxx_ehci_remove,
168 .driver = {
169 .name = "cns3xxx-ehci",
170 },
171};
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 76b7fd2d838a..40a844c1dbb4 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -28,11 +28,9 @@
28 dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args ) 28 dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
29 29
30#ifdef VERBOSE_DEBUG 30#ifdef VERBOSE_DEBUG
31# define vdbg dbg
32# define ehci_vdbg ehci_dbg 31# define ehci_vdbg ehci_dbg
33#else 32#else
34# define vdbg(fmt,args...) do { } while (0) 33 static inline void ehci_vdbg(struct ehci_hcd *ehci, ...) {}
35# define ehci_vdbg(ehci, fmt, args...) do { } while (0)
36#endif 34#endif
37 35
38#ifdef DEBUG 36#ifdef DEBUG
@@ -369,18 +367,21 @@ static const struct file_operations debug_async_fops = {
369 .open = debug_async_open, 367 .open = debug_async_open,
370 .read = debug_output, 368 .read = debug_output,
371 .release = debug_close, 369 .release = debug_close,
370 .llseek = default_llseek,
372}; 371};
373static const struct file_operations debug_periodic_fops = { 372static const struct file_operations debug_periodic_fops = {
374 .owner = THIS_MODULE, 373 .owner = THIS_MODULE,
375 .open = debug_periodic_open, 374 .open = debug_periodic_open,
376 .read = debug_output, 375 .read = debug_output,
377 .release = debug_close, 376 .release = debug_close,
377 .llseek = default_llseek,
378}; 378};
379static const struct file_operations debug_registers_fops = { 379static const struct file_operations debug_registers_fops = {
380 .owner = THIS_MODULE, 380 .owner = THIS_MODULE,
381 .open = debug_registers_open, 381 .open = debug_registers_open,
382 .read = debug_output, 382 .read = debug_output,
383 .release = debug_close, 383 .release = debug_close,
384 .llseek = default_llseek,
384}; 385};
385static const struct file_operations debug_lpm_fops = { 386static const struct file_operations debug_lpm_fops = {
386 .owner = THIS_MODULE, 387 .owner = THIS_MODULE,
@@ -388,6 +389,7 @@ static const struct file_operations debug_lpm_fops = {
388 .read = debug_lpm_read, 389 .read = debug_lpm_read,
389 .write = debug_lpm_write, 390 .write = debug_lpm_write,
390 .release = debug_lpm_close, 391 .release = debug_lpm_close,
392 .llseek = noop_llseek,
391}; 393};
392 394
393static struct dentry *ehci_debug_root; 395static struct dentry *ehci_debug_root;
@@ -724,7 +726,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
724 } 726 }
725 727
726 /* Capability Registers */ 728 /* Capability Registers */
727 i = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase)); 729 i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
728 temp = scnprintf (next, size, 730 temp = scnprintf (next, size,
729 "bus %s, device %s\n" 731 "bus %s, device %s\n"
730 "%s\n" 732 "%s\n"
@@ -875,7 +877,7 @@ static int fill_buffer(struct debug_buffer *buf)
875 int ret = 0; 877 int ret = 0;
876 878
877 if (!buf->output_buf) 879 if (!buf->output_buf)
878 buf->output_buf = (char *)vmalloc(buf->alloc_size); 880 buf->output_buf = vmalloc(buf->alloc_size);
879 881
880 if (!buf->output_buf) { 882 if (!buf->output_buf) {
881 ret = -ENOMEM; 883 ret = -ENOMEM;
@@ -1063,7 +1065,7 @@ static inline void create_debug_files (struct ehci_hcd *ehci)
1063 &debug_registers_fops)) 1065 &debug_registers_fops))
1064 goto file_error; 1066 goto file_error;
1065 1067
1066 if (!debugfs_create_file("lpm", S_IRUGO|S_IWUGO, ehci->debug_dir, bus, 1068 if (!debugfs_create_file("lpm", S_IRUGO|S_IWUSR, ehci->debug_dir, bus,
1067 &debug_lpm_fops)) 1069 &debug_lpm_fops))
1068 goto file_error; 1070 goto file_error;
1069 1071
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index a416421abfa2..f380bf97e5af 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -52,7 +52,6 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
52 struct resource *res; 52 struct resource *res;
53 int irq; 53 int irq;
54 int retval; 54 int retval;
55 unsigned int temp;
56 55
57 pr_debug("initializing FSL-SOC USB Controller\n"); 56 pr_debug("initializing FSL-SOC USB Controller\n");
58 57
@@ -116,17 +115,52 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
116 goto err3; 115 goto err3;
117 } 116 }
118 117
119 /* Enable USB controller */ 118 pdata->regs = hcd->regs;
120 temp = in_be32(hcd->regs + 0x500);
121 out_be32(hcd->regs + 0x500, temp | 0x4);
122 119
123 /* Set to Host mode */ 120 if (pdata->power_budget)
124 temp = in_le32(hcd->regs + 0x1a8); 121 hcd->power_budget = pdata->power_budget;
125 out_le32(hcd->regs + 0x1a8, temp | 0x3); 122
123 /*
124 * do platform specific init: check the clock, grab/config pins, etc.
125 */
126 if (pdata->init && pdata->init(pdev)) {
127 retval = -ENODEV;
128 goto err3;
129 }
130
131 /* Enable USB controller, 83xx or 8536 */
132 if (pdata->have_sysif_regs)
133 setbits32(hcd->regs + FSL_SOC_USB_CTRL, 0x4);
134
135 /* Don't need to set host mode here. It will be done by tdi_reset() */
126 136
127 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); 137 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
128 if (retval != 0) 138 if (retval != 0)
129 goto err4; 139 goto err4;
140
141#ifdef CONFIG_USB_OTG
142 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
143 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
144
145 ehci->transceiver = otg_get_transceiver();
146 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, transceiver=0x%p\n",
147 hcd, ehci, ehci->transceiver);
148
149 if (ehci->transceiver) {
150 retval = otg_set_host(ehci->transceiver,
151 &ehci_to_hcd(ehci)->self);
152 if (retval) {
153 if (ehci->transceiver)
154 put_device(ehci->transceiver->dev);
155 goto err4;
156 }
157 } else {
158 dev_err(&pdev->dev, "can't find transceiver\n");
159 retval = -ENODEV;
160 goto err4;
161 }
162 }
163#endif
130 return retval; 164 return retval;
131 165
132 err4: 166 err4:
@@ -137,6 +171,8 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
137 usb_put_hcd(hcd); 171 usb_put_hcd(hcd);
138 err1: 172 err1:
139 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval); 173 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
174 if (pdata->exit)
175 pdata->exit(pdev);
140 return retval; 176 return retval;
141} 177}
142 178
@@ -154,17 +190,36 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
154static void usb_hcd_fsl_remove(struct usb_hcd *hcd, 190static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
155 struct platform_device *pdev) 191 struct platform_device *pdev)
156{ 192{
193 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
194 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
195
196 if (ehci->transceiver) {
197 otg_set_host(ehci->transceiver, NULL);
198 put_device(ehci->transceiver->dev);
199 }
200
157 usb_remove_hcd(hcd); 201 usb_remove_hcd(hcd);
202
203 /*
204 * do platform specific un-initialization:
205 * release iomux pins, disable clock, etc.
206 */
207 if (pdata->exit)
208 pdata->exit(pdev);
158 iounmap(hcd->regs); 209 iounmap(hcd->regs);
159 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 210 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
160 usb_put_hcd(hcd); 211 usb_put_hcd(hcd);
161} 212}
162 213
163static void mpc83xx_setup_phy(struct ehci_hcd *ehci, 214static void ehci_fsl_setup_phy(struct ehci_hcd *ehci,
164 enum fsl_usb2_phy_modes phy_mode, 215 enum fsl_usb2_phy_modes phy_mode,
165 unsigned int port_offset) 216 unsigned int port_offset)
166{ 217{
167 u32 portsc = 0; 218 u32 portsc;
219
220 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]);
221 portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW);
222
168 switch (phy_mode) { 223 switch (phy_mode) {
169 case FSL_USB2_PHY_ULPI: 224 case FSL_USB2_PHY_ULPI:
170 portsc |= PORT_PTS_ULPI; 225 portsc |= PORT_PTS_ULPI;
@@ -184,20 +239,21 @@ static void mpc83xx_setup_phy(struct ehci_hcd *ehci,
184 ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]); 239 ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]);
185} 240}
186 241
187static void mpc83xx_usb_setup(struct usb_hcd *hcd) 242static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
188{ 243{
189 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 244 struct usb_hcd *hcd = ehci_to_hcd(ehci);
190 struct fsl_usb2_platform_data *pdata; 245 struct fsl_usb2_platform_data *pdata;
191 void __iomem *non_ehci = hcd->regs; 246 void __iomem *non_ehci = hcd->regs;
192 u32 temp; 247 u32 temp;
193 248
194 pdata = 249 pdata = hcd->self.controller->platform_data;
195 (struct fsl_usb2_platform_data *)hcd->self.controller-> 250
196 platform_data;
197 /* Enable PHY interface in the control reg. */ 251 /* Enable PHY interface in the control reg. */
198 temp = in_be32(non_ehci + FSL_SOC_USB_CTRL); 252 if (pdata->have_sysif_regs) {
199 out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x00000004); 253 temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
200 out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b); 254 out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x00000004);
255 out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b);
256 }
201 257
202#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) 258#if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
203 /* 259 /*
@@ -214,7 +270,7 @@ static void mpc83xx_usb_setup(struct usb_hcd *hcd)
214 270
215 if ((pdata->operating_mode == FSL_USB2_DR_HOST) || 271 if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
216 (pdata->operating_mode == FSL_USB2_DR_OTG)) 272 (pdata->operating_mode == FSL_USB2_DR_OTG))
217 mpc83xx_setup_phy(ehci, pdata->phy_mode, 0); 273 ehci_fsl_setup_phy(ehci, pdata->phy_mode, 0);
218 274
219 if (pdata->operating_mode == FSL_USB2_MPH_HOST) { 275 if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
220 unsigned int chip, rev, svr; 276 unsigned int chip, rev, svr;
@@ -228,27 +284,27 @@ static void mpc83xx_usb_setup(struct usb_hcd *hcd)
228 ehci->has_fsl_port_bug = 1; 284 ehci->has_fsl_port_bug = 1;
229 285
230 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED) 286 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
231 mpc83xx_setup_phy(ehci, pdata->phy_mode, 0); 287 ehci_fsl_setup_phy(ehci, pdata->phy_mode, 0);
232 if (pdata->port_enables & FSL_USB2_PORT1_ENABLED) 288 if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
233 mpc83xx_setup_phy(ehci, pdata->phy_mode, 1); 289 ehci_fsl_setup_phy(ehci, pdata->phy_mode, 1);
234 } 290 }
235 291
236 /* put controller in host mode. */ 292 if (pdata->have_sysif_regs) {
237 ehci_writel(ehci, 0x00000003, non_ehci + FSL_SOC_USB_USBMODE);
238#ifdef CONFIG_PPC_85xx 293#ifdef CONFIG_PPC_85xx
239 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x00000008); 294 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x00000008);
240 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000080); 295 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000080);
241#else 296#else
242 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c); 297 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
243 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040); 298 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
244#endif 299#endif
245 out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001); 300 out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
301 }
246} 302}
247 303
248/* called after powerup, by probe or system-pm "wakeup" */ 304/* called after powerup, by probe or system-pm "wakeup" */
249static int ehci_fsl_reinit(struct ehci_hcd *ehci) 305static int ehci_fsl_reinit(struct ehci_hcd *ehci)
250{ 306{
251 mpc83xx_usb_setup(ehci_to_hcd(ehci)); 307 ehci_fsl_usb_setup(ehci);
252 ehci_port_power(ehci, 0); 308 ehci_port_power(ehci, 0);
253 309
254 return 0; 310 return 0;
@@ -259,17 +315,24 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
259{ 315{
260 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 316 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
261 int retval; 317 int retval;
318 struct fsl_usb2_platform_data *pdata;
319
320 pdata = hcd->self.controller->platform_data;
321 ehci->big_endian_desc = pdata->big_endian_desc;
322 ehci->big_endian_mmio = pdata->big_endian_mmio;
262 323
263 /* EHCI registers start at offset 0x100 */ 324 /* EHCI registers start at offset 0x100 */
264 ehci->caps = hcd->regs + 0x100; 325 ehci->caps = hcd->regs + 0x100;
265 ehci->regs = hcd->regs + 0x100 + 326 ehci->regs = hcd->regs + 0x100 +
266 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 327 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
267 dbg_hcs_params(ehci, "reset"); 328 dbg_hcs_params(ehci, "reset");
268 dbg_hcc_params(ehci, "reset"); 329 dbg_hcc_params(ehci, "reset");
269 330
270 /* cache this readonly data; minimize chip reads */ 331 /* cache this readonly data; minimize chip reads */
271 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 332 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
272 333
334 hcd->has_tt = 1;
335
273 retval = ehci_halt(ehci); 336 retval = ehci_halt(ehci);
274 if (retval) 337 if (retval)
275 return retval; 338 return retval;
@@ -279,8 +342,6 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
279 if (retval) 342 if (retval)
280 return retval; 343 return retval;
281 344
282 hcd->has_tt = 1;
283
284 ehci->sbrn = 0x20; 345 ehci->sbrn = 0x20;
285 346
286 ehci_reset(ehci); 347 ehci_reset(ehci);
@@ -300,6 +361,149 @@ struct ehci_fsl {
300 361
301#ifdef CONFIG_PM 362#ifdef CONFIG_PM
302 363
364#ifdef CONFIG_PPC_MPC512x
365static int ehci_fsl_mpc512x_drv_suspend(struct device *dev)
366{
367 struct usb_hcd *hcd = dev_get_drvdata(dev);
368 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
369 struct fsl_usb2_platform_data *pdata = dev->platform_data;
370 u32 tmp;
371
372#ifdef DEBUG
373 u32 mode = ehci_readl(ehci, hcd->regs + FSL_SOC_USB_USBMODE);
374 mode &= USBMODE_CM_MASK;
375 tmp = ehci_readl(ehci, hcd->regs + 0x140); /* usbcmd */
376
377 dev_dbg(dev, "suspend=%d already_suspended=%d "
378 "mode=%d usbcmd %08x\n", pdata->suspended,
379 pdata->already_suspended, mode, tmp);
380#endif
381
382 /*
383 * If the controller is already suspended, then this must be a
384 * PM suspend. Remember this fact, so that we will leave the
385 * controller suspended at PM resume time.
386 */
387 if (pdata->suspended) {
388 dev_dbg(dev, "already suspended, leaving early\n");
389 pdata->already_suspended = 1;
390 return 0;
391 }
392
393 dev_dbg(dev, "suspending...\n");
394
395 hcd->state = HC_STATE_SUSPENDED;
396 dev->power.power_state = PMSG_SUSPEND;
397
398 /* ignore non-host interrupts */
399 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
400
401 /* stop the controller */
402 tmp = ehci_readl(ehci, &ehci->regs->command);
403 tmp &= ~CMD_RUN;
404 ehci_writel(ehci, tmp, &ehci->regs->command);
405
406 /* save EHCI registers */
407 pdata->pm_command = ehci_readl(ehci, &ehci->regs->command);
408 pdata->pm_command &= ~CMD_RUN;
409 pdata->pm_status = ehci_readl(ehci, &ehci->regs->status);
410 pdata->pm_intr_enable = ehci_readl(ehci, &ehci->regs->intr_enable);
411 pdata->pm_frame_index = ehci_readl(ehci, &ehci->regs->frame_index);
412 pdata->pm_segment = ehci_readl(ehci, &ehci->regs->segment);
413 pdata->pm_frame_list = ehci_readl(ehci, &ehci->regs->frame_list);
414 pdata->pm_async_next = ehci_readl(ehci, &ehci->regs->async_next);
415 pdata->pm_configured_flag =
416 ehci_readl(ehci, &ehci->regs->configured_flag);
417 pdata->pm_portsc = ehci_readl(ehci, &ehci->regs->port_status[0]);
418 pdata->pm_usbgenctrl = ehci_readl(ehci,
419 hcd->regs + FSL_SOC_USB_USBGENCTRL);
420
421 /* clear the W1C bits */
422 pdata->pm_portsc &= cpu_to_hc32(ehci, ~PORT_RWC_BITS);
423
424 pdata->suspended = 1;
425
426 /* clear PP to cut power to the port */
427 tmp = ehci_readl(ehci, &ehci->regs->port_status[0]);
428 tmp &= ~PORT_POWER;
429 ehci_writel(ehci, tmp, &ehci->regs->port_status[0]);
430
431 return 0;
432}
433
434static int ehci_fsl_mpc512x_drv_resume(struct device *dev)
435{
436 struct usb_hcd *hcd = dev_get_drvdata(dev);
437 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
438 struct fsl_usb2_platform_data *pdata = dev->platform_data;
439 u32 tmp;
440
441 dev_dbg(dev, "suspend=%d already_suspended=%d\n",
442 pdata->suspended, pdata->already_suspended);
443
444 /*
445 * If the controller was already suspended at suspend time,
446 * then don't resume it now.
447 */
448 if (pdata->already_suspended) {
449 dev_dbg(dev, "already suspended, leaving early\n");
450 pdata->already_suspended = 0;
451 return 0;
452 }
453
454 if (!pdata->suspended) {
455 dev_dbg(dev, "not suspended, leaving early\n");
456 return 0;
457 }
458
459 pdata->suspended = 0;
460
461 dev_dbg(dev, "resuming...\n");
462
463 /* set host mode */
464 tmp = USBMODE_CM_HOST | (pdata->es ? USBMODE_ES : 0);
465 ehci_writel(ehci, tmp, hcd->regs + FSL_SOC_USB_USBMODE);
466
467 ehci_writel(ehci, pdata->pm_usbgenctrl,
468 hcd->regs + FSL_SOC_USB_USBGENCTRL);
469 ehci_writel(ehci, ISIPHYCTRL_PXE | ISIPHYCTRL_PHYE,
470 hcd->regs + FSL_SOC_USB_ISIPHYCTRL);
471
472 /* restore EHCI registers */
473 ehci_writel(ehci, pdata->pm_command, &ehci->regs->command);
474 ehci_writel(ehci, pdata->pm_intr_enable, &ehci->regs->intr_enable);
475 ehci_writel(ehci, pdata->pm_frame_index, &ehci->regs->frame_index);
476 ehci_writel(ehci, pdata->pm_segment, &ehci->regs->segment);
477 ehci_writel(ehci, pdata->pm_frame_list, &ehci->regs->frame_list);
478 ehci_writel(ehci, pdata->pm_async_next, &ehci->regs->async_next);
479 ehci_writel(ehci, pdata->pm_configured_flag,
480 &ehci->regs->configured_flag);
481 ehci_writel(ehci, pdata->pm_portsc, &ehci->regs->port_status[0]);
482
483 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
484 hcd->state = HC_STATE_RUNNING;
485 dev->power.power_state = PMSG_ON;
486
487 tmp = ehci_readl(ehci, &ehci->regs->command);
488 tmp |= CMD_RUN;
489 ehci_writel(ehci, tmp, &ehci->regs->command);
490
491 usb_hcd_resume_root_hub(hcd);
492
493 return 0;
494}
495#else
496static inline int ehci_fsl_mpc512x_drv_suspend(struct device *dev)
497{
498 return 0;
499}
500
501static inline int ehci_fsl_mpc512x_drv_resume(struct device *dev)
502{
503 return 0;
504}
505#endif /* CONFIG_PPC_MPC512x */
506
303static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd) 507static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
304{ 508{
305 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 509 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
@@ -313,6 +517,11 @@ static int ehci_fsl_drv_suspend(struct device *dev)
313 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); 517 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
314 void __iomem *non_ehci = hcd->regs; 518 void __iomem *non_ehci = hcd->regs;
315 519
520 if (of_device_is_compatible(dev->parent->of_node,
521 "fsl,mpc5121-usb2-dr")) {
522 return ehci_fsl_mpc512x_drv_suspend(dev);
523 }
524
316 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), 525 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
317 device_may_wakeup(dev)); 526 device_may_wakeup(dev));
318 if (!fsl_deep_sleep()) 527 if (!fsl_deep_sleep())
@@ -329,6 +538,11 @@ static int ehci_fsl_drv_resume(struct device *dev)
329 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 538 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
330 void __iomem *non_ehci = hcd->regs; 539 void __iomem *non_ehci = hcd->regs;
331 540
541 if (of_device_is_compatible(dev->parent->of_node,
542 "fsl,mpc5121-usb2-dr")) {
543 return ehci_fsl_mpc512x_drv_resume(dev);
544 }
545
332 ehci_prepare_ports_for_controller_resume(ehci); 546 ehci_prepare_ports_for_controller_resume(ehci);
333 if (!fsl_deep_sleep()) 547 if (!fsl_deep_sleep())
334 return 0; 548 return 0;
@@ -363,6 +577,38 @@ static struct dev_pm_ops ehci_fsl_pm_ops = {
363#define EHCI_FSL_PM_OPS NULL 577#define EHCI_FSL_PM_OPS NULL
364#endif /* CONFIG_PM */ 578#endif /* CONFIG_PM */
365 579
580#ifdef CONFIG_USB_OTG
581static int ehci_start_port_reset(struct usb_hcd *hcd, unsigned port)
582{
583 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
584 u32 status;
585
586 if (!port)
587 return -EINVAL;
588
589 port--;
590
591 /* start port reset before HNP protocol time out */
592 status = readl(&ehci->regs->port_status[port]);
593 if (!(status & PORT_CONNECT))
594 return -ENODEV;
595
596 /* khubd will finish the reset later */
597 if (ehci_is_TDI(ehci)) {
598 writel(PORT_RESET |
599 (status & ~(PORT_CSC | PORT_PEC | PORT_OCC)),
600 &ehci->regs->port_status[port]);
601 } else {
602 writel(PORT_RESET, &ehci->regs->port_status[port]);
603 }
604
605 return 0;
606}
607#else
608#define ehci_start_port_reset NULL
609#endif /* CONFIG_USB_OTG */
610
611
366static const struct hc_driver ehci_fsl_hc_driver = { 612static const struct hc_driver ehci_fsl_hc_driver = {
367 .description = hcd_name, 613 .description = hcd_name,
368 .product_desc = "Freescale On-Chip EHCI Host Controller", 614 .product_desc = "Freescale On-Chip EHCI Host Controller",
@@ -372,7 +618,7 @@ static const struct hc_driver ehci_fsl_hc_driver = {
372 * generic hardware linkage 618 * generic hardware linkage
373 */ 619 */
374 .irq = ehci_irq, 620 .irq = ehci_irq,
375 .flags = HCD_USB2, 621 .flags = HCD_USB2 | HCD_MEMORY,
376 622
377 /* 623 /*
378 * basic lifecycle operations 624 * basic lifecycle operations
@@ -402,6 +648,7 @@ static const struct hc_driver ehci_fsl_hc_driver = {
402 .hub_control = ehci_hub_control, 648 .hub_control = ehci_hub_control,
403 .bus_suspend = ehci_bus_suspend, 649 .bus_suspend = ehci_bus_suspend,
404 .bus_resume = ehci_bus_resume, 650 .bus_resume = ehci_bus_resume,
651 .start_port_reset = ehci_start_port_reset,
405 .relinquish_port = ehci_relinquish_port, 652 .relinquish_port = ehci_relinquish_port,
406 .port_handed_over = ehci_port_handed_over, 653 .port_handed_over = ehci_port_handed_over,
407 654
diff --git a/drivers/usb/host/ehci-fsl.h b/drivers/usb/host/ehci-fsl.h
index b5e59db53347..491806221165 100644
--- a/drivers/usb/host/ehci-fsl.h
+++ b/drivers/usb/host/ehci-fsl.h
@@ -1,4 +1,4 @@
1/* Copyright (c) 2005 freescale semiconductor 1/* Copyright (C) 2005-2010 Freescale Semiconductor, Inc.
2 * Copyright (c) 2005 MontaVista Software 2 * Copyright (c) 2005 MontaVista Software
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
@@ -28,6 +28,17 @@
28#define PORT_PTS_PTW (1<<28) 28#define PORT_PTS_PTW (1<<28)
29#define FSL_SOC_USB_PORTSC2 0x188 29#define FSL_SOC_USB_PORTSC2 0x188
30#define FSL_SOC_USB_USBMODE 0x1a8 30#define FSL_SOC_USB_USBMODE 0x1a8
31#define USBMODE_CM_MASK (3 << 0) /* controller mode mask */
32#define USBMODE_CM_HOST (3 << 0) /* controller mode: host */
33#define USBMODE_ES (1 << 2) /* (Big) Endian Select */
34
35#define FSL_SOC_USB_USBGENCTRL 0x200
36#define USBGENCTRL_PPP (1 << 3)
37#define USBGENCTRL_PFP (1 << 2)
38#define FSL_SOC_USB_ISIPHYCTRL 0x204
39#define ISIPHYCTRL_PXE (1)
40#define ISIPHYCTRL_PHYE (1 << 4)
41
31#define FSL_SOC_USB_SNOOP1 0x400 /* NOTE: big-endian */ 42#define FSL_SOC_USB_SNOOP1 0x400 /* NOTE: big-endian */
32#define FSL_SOC_USB_SNOOP2 0x404 /* NOTE: big-endian */ 43#define FSL_SOC_USB_SNOOP2 0x404 /* NOTE: big-endian */
33#define FSL_SOC_USB_AGECNTTHRSH 0x408 /* NOTE: big-endian */ 44#define FSL_SOC_USB_AGECNTTHRSH 0x408 /* NOTE: big-endian */
diff --git a/drivers/usb/host/ehci-grlib.c b/drivers/usb/host/ehci-grlib.c
new file mode 100644
index 000000000000..93b230dc51a2
--- /dev/null
+++ b/drivers/usb/host/ehci-grlib.c
@@ -0,0 +1,242 @@
1/*
2 * Driver for Aeroflex Gaisler GRLIB GRUSBHC EHCI host controller
3 *
4 * GRUSBHC is typically found on LEON/GRLIB SoCs
5 *
6 * (c) Jan Andersson <jan@gaisler.com>
7 *
8 * Based on ehci-ppc-of.c which is:
9 * (c) Valentine Barshak <vbarshak@ru.mvista.com>
10 * and in turn based on "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
11 * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28
29#include <linux/signal.h>
30
31#include <linux/of_irq.h>
32#include <linux/of_address.h>
33#include <linux/of_platform.h>
34
35#define GRUSBHC_HCIVERSION 0x0100 /* Known value of cap. reg. HCIVERSION */
36
37/* called during probe() after chip reset completes */
38static int ehci_grlib_setup(struct usb_hcd *hcd)
39{
40 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
41 int retval;
42
43 retval = ehci_halt(ehci);
44 if (retval)
45 return retval;
46
47 retval = ehci_init(hcd);
48 if (retval)
49 return retval;
50
51 ehci->sbrn = 0x20;
52 ehci_port_power(ehci, 1);
53
54 return ehci_reset(ehci);
55}
56
57
58static const struct hc_driver ehci_grlib_hc_driver = {
59 .description = hcd_name,
60 .product_desc = "GRLIB GRUSBHC EHCI",
61 .hcd_priv_size = sizeof(struct ehci_hcd),
62
63 /*
64 * generic hardware linkage
65 */
66 .irq = ehci_irq,
67 .flags = HCD_MEMORY | HCD_USB2,
68
69 /*
70 * basic lifecycle operations
71 */
72 .reset = ehci_grlib_setup,
73 .start = ehci_run,
74 .stop = ehci_stop,
75 .shutdown = ehci_shutdown,
76
77 /*
78 * managing i/o requests and associated device resources
79 */
80 .urb_enqueue = ehci_urb_enqueue,
81 .urb_dequeue = ehci_urb_dequeue,
82 .endpoint_disable = ehci_endpoint_disable,
83 .endpoint_reset = ehci_endpoint_reset,
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#ifdef CONFIG_PM
96 .bus_suspend = ehci_bus_suspend,
97 .bus_resume = ehci_bus_resume,
98#endif
99 .relinquish_port = ehci_relinquish_port,
100 .port_handed_over = ehci_port_handed_over,
101
102 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
103};
104
105
106static int __devinit ehci_hcd_grlib_probe(struct platform_device *op)
107{
108 struct device_node *dn = op->dev.of_node;
109 struct usb_hcd *hcd;
110 struct ehci_hcd *ehci = NULL;
111 struct resource res;
112 u32 hc_capbase;
113 int irq;
114 int rv;
115
116 if (usb_disabled())
117 return -ENODEV;
118
119 dev_dbg(&op->dev, "initializing GRUSBHC EHCI USB Controller\n");
120
121 rv = of_address_to_resource(dn, 0, &res);
122 if (rv)
123 return rv;
124
125 /* usb_create_hcd requires dma_mask != NULL */
126 op->dev.dma_mask = &op->dev.coherent_dma_mask;
127 hcd = usb_create_hcd(&ehci_grlib_hc_driver, &op->dev,
128 "GRUSBHC EHCI USB");
129 if (!hcd)
130 return -ENOMEM;
131
132 hcd->rsrc_start = res.start;
133 hcd->rsrc_len = res.end - res.start + 1;
134
135 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
136 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
137 rv = -EBUSY;
138 goto err_rmr;
139 }
140
141 irq = irq_of_parse_and_map(dn, 0);
142 if (irq == NO_IRQ) {
143 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
144 rv = -EBUSY;
145 goto err_irq;
146 }
147
148 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
149 if (!hcd->regs) {
150 printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
151 rv = -ENOMEM;
152 goto err_ioremap;
153 }
154
155 ehci = hcd_to_ehci(hcd);
156
157 ehci->caps = hcd->regs;
158
159 /* determine endianness of this implementation */
160 hc_capbase = ehci_readl(ehci, &ehci->caps->hc_capbase);
161 if (HC_VERSION(ehci, hc_capbase) != GRUSBHC_HCIVERSION) {
162 ehci->big_endian_mmio = 1;
163 ehci->big_endian_desc = 1;
164 ehci->big_endian_capbase = 1;
165 }
166
167 ehci->regs = hcd->regs +
168 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
169
170 /* cache this readonly data; minimize chip reads */
171 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
172
173 rv = usb_add_hcd(hcd, irq, 0);
174 if (rv)
175 goto err_ehci;
176
177 return 0;
178
179err_ehci:
180 iounmap(hcd->regs);
181err_ioremap:
182 irq_dispose_mapping(irq);
183err_irq:
184 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
185err_rmr:
186 usb_put_hcd(hcd);
187
188 return rv;
189}
190
191
192static int ehci_hcd_grlib_remove(struct platform_device *op)
193{
194 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
195
196 dev_set_drvdata(&op->dev, NULL);
197
198 dev_dbg(&op->dev, "stopping GRLIB GRUSBHC EHCI USB Controller\n");
199
200 usb_remove_hcd(hcd);
201
202 iounmap(hcd->regs);
203 irq_dispose_mapping(hcd->irq);
204 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
205
206 usb_put_hcd(hcd);
207
208 return 0;
209}
210
211
212static void ehci_hcd_grlib_shutdown(struct platform_device *op)
213{
214 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
215
216 if (hcd->driver->shutdown)
217 hcd->driver->shutdown(hcd);
218}
219
220
221static const struct of_device_id ehci_hcd_grlib_of_match[] = {
222 {
223 .name = "GAISLER_EHCI",
224 },
225 {
226 .name = "01_026",
227 },
228 {},
229};
230MODULE_DEVICE_TABLE(of, ehci_hcd_grlib_of_match);
231
232
233static struct platform_driver ehci_grlib_driver = {
234 .probe = ehci_hcd_grlib_probe,
235 .remove = ehci_hcd_grlib_remove,
236 .shutdown = ehci_hcd_grlib_shutdown,
237 .driver = {
238 .name = "grlib-ehci",
239 .owner = THIS_MODULE,
240 .of_match_table = ehci_hcd_grlib_of_match,
241 },
242};
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 34a928d3b7d2..f8030ee928e8 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1,4 +1,8 @@
1/* 1/*
2 * Enhanced Host Controller Interface (EHCI) driver for USB.
3 *
4 * Maintainer: Alan Stern <stern@rowland.harvard.edu>
5 *
2 * Copyright (c) 2000-2004 by David Brownell 6 * Copyright (c) 2000-2004 by David Brownell
3 * 7 *
4 * This program is free software; you can redistribute it and/or modify it 8 * This program is free software; you can redistribute it and/or modify it
@@ -118,6 +122,7 @@ MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n");
118 122
119#include "ehci.h" 123#include "ehci.h"
120#include "ehci-dbg.c" 124#include "ehci-dbg.c"
125#include "pci-quirks.h"
121 126
122/*-------------------------------------------------------------------------*/ 127/*-------------------------------------------------------------------------*/
123 128
@@ -194,6 +199,17 @@ static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
194 return -ETIMEDOUT; 199 return -ETIMEDOUT;
195} 200}
196 201
202/* check TDI/ARC silicon is in host mode */
203static int tdi_in_host_mode (struct ehci_hcd *ehci)
204{
205 u32 __iomem *reg_ptr;
206 u32 tmp;
207
208 reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE);
209 tmp = ehci_readl(ehci, reg_ptr);
210 return (tmp & 3) == USBMODE_CM_HC;
211}
212
197/* force HC to halt state from unknown (EHCI spec section 2.3) */ 213/* force HC to halt state from unknown (EHCI spec section 2.3) */
198static int ehci_halt (struct ehci_hcd *ehci) 214static int ehci_halt (struct ehci_hcd *ehci)
199{ 215{
@@ -202,6 +218,10 @@ static int ehci_halt (struct ehci_hcd *ehci)
202 /* disable any irqs left enabled by previous code */ 218 /* disable any irqs left enabled by previous code */
203 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 219 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
204 220
221 if (ehci_is_TDI(ehci) && tdi_in_host_mode(ehci) == 0) {
222 return 0;
223 }
224
205 if ((temp & STS_HALT) != 0) 225 if ((temp & STS_HALT) != 0)
206 return 0; 226 return 0;
207 227
@@ -514,6 +534,9 @@ static void ehci_stop (struct usb_hcd *hcd)
514 spin_unlock_irq (&ehci->lock); 534 spin_unlock_irq (&ehci->lock);
515 ehci_mem_cleanup (ehci); 535 ehci_mem_cleanup (ehci);
516 536
537 if (ehci->amd_pll_fix == 1)
538 usb_amd_dev_put();
539
517#ifdef EHCI_STATS 540#ifdef EHCI_STATS
518 ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n", 541 ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
519 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim, 542 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
@@ -549,6 +572,8 @@ static int ehci_init(struct usb_hcd *hcd)
549 ehci->iaa_watchdog.function = ehci_iaa_watchdog; 572 ehci->iaa_watchdog.function = ehci_iaa_watchdog;
550 ehci->iaa_watchdog.data = (unsigned long) ehci; 573 ehci->iaa_watchdog.data = (unsigned long) ehci;
551 574
575 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
576
552 /* 577 /*
553 * hw default: 1K periodic list heads, one per frame. 578 * hw default: 1K periodic list heads, one per frame.
554 * periodic_size can shrink by USBCMD update if hcc_params allows. 579 * periodic_size can shrink by USBCMD update if hcc_params allows.
@@ -556,11 +581,20 @@ static int ehci_init(struct usb_hcd *hcd)
556 ehci->periodic_size = DEFAULT_I_TDPS; 581 ehci->periodic_size = DEFAULT_I_TDPS;
557 INIT_LIST_HEAD(&ehci->cached_itd_list); 582 INIT_LIST_HEAD(&ehci->cached_itd_list);
558 INIT_LIST_HEAD(&ehci->cached_sitd_list); 583 INIT_LIST_HEAD(&ehci->cached_sitd_list);
584
585 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
586 /* periodic schedule size can be smaller than default */
587 switch (EHCI_TUNE_FLS) {
588 case 0: ehci->periodic_size = 1024; break;
589 case 1: ehci->periodic_size = 512; break;
590 case 2: ehci->periodic_size = 256; break;
591 default: BUG();
592 }
593 }
559 if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0) 594 if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
560 return retval; 595 return retval;
561 596
562 /* controllers may cache some of the periodic schedule ... */ 597 /* controllers may cache some of the periodic schedule ... */
563 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
564 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache 598 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
565 ehci->i_thresh = 2 + 8; 599 ehci->i_thresh = 2 + 8;
566 else // N microframes cached 600 else // N microframes cached
@@ -614,12 +648,6 @@ static int ehci_init(struct usb_hcd *hcd)
614 /* periodic schedule size can be smaller than default */ 648 /* periodic schedule size can be smaller than default */
615 temp &= ~(3 << 2); 649 temp &= ~(3 << 2);
616 temp |= (EHCI_TUNE_FLS << 2); 650 temp |= (EHCI_TUNE_FLS << 2);
617 switch (EHCI_TUNE_FLS) {
618 case 0: ehci->periodic_size = 1024; break;
619 case 1: ehci->periodic_size = 512; break;
620 case 2: ehci->periodic_size = 256; break;
621 default: BUG();
622 }
623 } 651 }
624 if (HCC_LPM(hcc_params)) { 652 if (HCC_LPM(hcc_params)) {
625 /* support link power management EHCI 1.1 addendum */ 653 /* support link power management EHCI 1.1 addendum */
@@ -651,7 +679,12 @@ static int ehci_run (struct usb_hcd *hcd)
651 hcd->uses_new_polling = 1; 679 hcd->uses_new_polling = 1;
652 680
653 /* EHCI spec section 4.1 */ 681 /* EHCI spec section 4.1 */
654 if ((retval = ehci_reset(ehci)) != 0) { 682 /*
683 * TDI driver does the ehci_reset in their reset callback.
684 * Don't reset here, because configuration settings will
685 * vanish.
686 */
687 if (!ehci_is_TDI(ehci) && (retval = ehci_reset(ehci)) != 0) {
655 ehci_mem_cleanup(ehci); 688 ehci_mem_cleanup(ehci);
656 return retval; 689 return retval;
657 } 690 }
@@ -710,7 +743,7 @@ static int ehci_run (struct usb_hcd *hcd)
710 up_write(&ehci_cf_port_reset_rwsem); 743 up_write(&ehci_cf_port_reset_rwsem);
711 ehci->last_periodic_enable = ktime_get_real(); 744 ehci->last_periodic_enable = ktime_get_real();
712 745
713 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase)); 746 temp = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
714 ehci_info (ehci, 747 ehci_info (ehci,
715 "USB %x.%x started, EHCI %x.%02x%s\n", 748 "USB %x.%x started, EHCI %x.%02x%s\n",
716 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f), 749 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
@@ -748,8 +781,9 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
748 goto dead; 781 goto dead;
749 } 782 }
750 783
784 /* Shared IRQ? */
751 masked_status = status & INTR_MASK; 785 masked_status = status & INTR_MASK;
752 if (!masked_status) { /* irq sharing? */ 786 if (!masked_status || unlikely(hcd->state == HC_STATE_HALT)) {
753 spin_unlock(&ehci->lock); 787 spin_unlock(&ehci->lock);
754 return IRQ_NONE; 788 return IRQ_NONE;
755 } 789 }
@@ -844,6 +878,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
844dead: 878dead:
845 ehci_reset(ehci); 879 ehci_reset(ehci);
846 ehci_writel(ehci, 0, &ehci->regs->configured_flag); 880 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
881 usb_hc_died(hcd);
847 /* generic layer kills/unlinks all urbs, then 882 /* generic layer kills/unlinks all urbs, then
848 * uses ehci_stop to clean up the rest 883 * uses ehci_stop to clean up the rest
849 */ 884 */
@@ -1048,10 +1083,11 @@ rescan:
1048 tmp && tmp != qh; 1083 tmp && tmp != qh;
1049 tmp = tmp->qh_next.qh) 1084 tmp = tmp->qh_next.qh)
1050 continue; 1085 continue;
1051 /* periodic qh self-unlinks on empty */ 1086 /* periodic qh self-unlinks on empty, and a COMPLETING qh
1052 if (!tmp) 1087 * may already be unlinked.
1053 goto nogood; 1088 */
1054 unlink_async (ehci, qh); 1089 if (tmp)
1090 unlink_async(ehci, qh);
1055 /* FALL THROUGH */ 1091 /* FALL THROUGH */
1056 case QH_STATE_UNLINK: /* wait for hw to finish? */ 1092 case QH_STATE_UNLINK: /* wait for hw to finish? */
1057 case QH_STATE_UNLINK_WAIT: 1093 case QH_STATE_UNLINK_WAIT:
@@ -1068,7 +1104,6 @@ idle_timeout:
1068 } 1104 }
1069 /* else FALL THROUGH */ 1105 /* else FALL THROUGH */
1070 default: 1106 default:
1071nogood:
1072 /* caller was supposed to have unlinked any requests; 1107 /* caller was supposed to have unlinked any requests;
1073 * that's not our job. just leak this memory. 1108 * that's not our job. just leak this memory.
1074 */ 1109 */
@@ -1080,7 +1115,6 @@ nogood:
1080 ep->hcpriv = NULL; 1115 ep->hcpriv = NULL;
1081done: 1116done:
1082 spin_unlock_irqrestore (&ehci->lock, flags); 1117 spin_unlock_irqrestore (&ehci->lock, flags);
1083 return;
1084} 1118}
1085 1119
1086static void 1120static void
@@ -1152,12 +1186,17 @@ MODULE_LICENSE ("GPL");
1152#define PLATFORM_DRIVER ehci_mxc_driver 1186#define PLATFORM_DRIVER ehci_mxc_driver
1153#endif 1187#endif
1154 1188
1189#ifdef CONFIG_USB_EHCI_SH
1190#include "ehci-sh.c"
1191#define PLATFORM_DRIVER ehci_hcd_sh_driver
1192#endif
1193
1155#ifdef CONFIG_SOC_AU1200 1194#ifdef CONFIG_SOC_AU1200
1156#include "ehci-au1xxx.c" 1195#include "ehci-au1xxx.c"
1157#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver 1196#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
1158#endif 1197#endif
1159 1198
1160#ifdef CONFIG_ARCH_OMAP3 1199#ifdef CONFIG_USB_EHCI_HCD_OMAP
1161#include "ehci-omap.c" 1200#include "ehci-omap.c"
1162#define PLATFORM_DRIVER ehci_hcd_omap_driver 1201#define PLATFORM_DRIVER ehci_hcd_omap_driver
1163#endif 1202#endif
@@ -1197,6 +1236,56 @@ MODULE_LICENSE ("GPL");
1197#define PLATFORM_DRIVER ehci_atmel_driver 1236#define PLATFORM_DRIVER ehci_atmel_driver
1198#endif 1237#endif
1199 1238
1239#ifdef CONFIG_USB_OCTEON_EHCI
1240#include "ehci-octeon.c"
1241#define PLATFORM_DRIVER ehci_octeon_driver
1242#endif
1243
1244#ifdef CONFIG_USB_CNS3XXX_EHCI
1245#include "ehci-cns3xxx.c"
1246#define PLATFORM_DRIVER cns3xxx_ehci_driver
1247#endif
1248
1249#ifdef CONFIG_ARCH_VT8500
1250#include "ehci-vt8500.c"
1251#define PLATFORM_DRIVER vt8500_ehci_driver
1252#endif
1253
1254#ifdef CONFIG_PLAT_SPEAR
1255#include "ehci-spear.c"
1256#define PLATFORM_DRIVER spear_ehci_hcd_driver
1257#endif
1258
1259#ifdef CONFIG_USB_EHCI_MSM
1260#include "ehci-msm.c"
1261#define PLATFORM_DRIVER ehci_msm_driver
1262#endif
1263
1264#ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
1265#include "ehci-pmcmsp.c"
1266#define PLATFORM_DRIVER ehci_hcd_msp_driver
1267#endif
1268
1269#ifdef CONFIG_USB_EHCI_TEGRA
1270#include "ehci-tegra.c"
1271#define PLATFORM_DRIVER tegra_ehci_driver
1272#endif
1273
1274#ifdef CONFIG_USB_EHCI_S5P
1275#include "ehci-s5p.c"
1276#define PLATFORM_DRIVER s5p_ehci_driver
1277#endif
1278
1279#ifdef CONFIG_USB_EHCI_ATH79
1280#include "ehci-ath79.c"
1281#define PLATFORM_DRIVER ehci_ath79_driver
1282#endif
1283
1284#ifdef CONFIG_SPARC_LEON
1285#include "ehci-grlib.c"
1286#define PLATFORM_DRIVER ehci_grlib_driver
1287#endif
1288
1200#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ 1289#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
1201 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ 1290 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
1202 !defined(XILINX_OF_PLATFORM_DRIVER) 1291 !defined(XILINX_OF_PLATFORM_DRIVER)
@@ -1249,24 +1338,24 @@ static int __init ehci_hcd_init(void)
1249#endif 1338#endif
1250 1339
1251#ifdef OF_PLATFORM_DRIVER 1340#ifdef OF_PLATFORM_DRIVER
1252 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER); 1341 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1253 if (retval < 0) 1342 if (retval < 0)
1254 goto clean3; 1343 goto clean3;
1255#endif 1344#endif
1256 1345
1257#ifdef XILINX_OF_PLATFORM_DRIVER 1346#ifdef XILINX_OF_PLATFORM_DRIVER
1258 retval = of_register_platform_driver(&XILINX_OF_PLATFORM_DRIVER); 1347 retval = platform_driver_register(&XILINX_OF_PLATFORM_DRIVER);
1259 if (retval < 0) 1348 if (retval < 0)
1260 goto clean4; 1349 goto clean4;
1261#endif 1350#endif
1262 return retval; 1351 return retval;
1263 1352
1264#ifdef XILINX_OF_PLATFORM_DRIVER 1353#ifdef XILINX_OF_PLATFORM_DRIVER
1265 /* of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER); */ 1354 /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
1266clean4: 1355clean4:
1267#endif 1356#endif
1268#ifdef OF_PLATFORM_DRIVER 1357#ifdef OF_PLATFORM_DRIVER
1269 of_unregister_platform_driver(&OF_PLATFORM_DRIVER); 1358 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1270clean3: 1359clean3:
1271#endif 1360#endif
1272#ifdef PS3_SYSTEM_BUS_DRIVER 1361#ifdef PS3_SYSTEM_BUS_DRIVER
@@ -1294,10 +1383,10 @@ module_init(ehci_hcd_init);
1294static void __exit ehci_hcd_cleanup(void) 1383static void __exit ehci_hcd_cleanup(void)
1295{ 1384{
1296#ifdef XILINX_OF_PLATFORM_DRIVER 1385#ifdef XILINX_OF_PLATFORM_DRIVER
1297 of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER); 1386 platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
1298#endif 1387#endif
1299#ifdef OF_PLATFORM_DRIVER 1388#ifdef OF_PLATFORM_DRIVER
1300 of_unregister_platform_driver(&OF_PLATFORM_DRIVER); 1389 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1301#endif 1390#endif
1302#ifdef PLATFORM_DRIVER 1391#ifdef PLATFORM_DRIVER
1303 platform_driver_unregister(&PLATFORM_DRIVER); 1392 platform_driver_unregister(&PLATFORM_DRIVER);
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 796ea0c8900f..ea6184bf48d0 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -27,6 +27,7 @@
27 */ 27 */
28 28
29/*-------------------------------------------------------------------------*/ 29/*-------------------------------------------------------------------------*/
30#include <linux/usb/otg.h>
30 31
31#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) 32#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
32 33
@@ -106,11 +107,33 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
106 ehci->owned_ports = 0; 107 ehci->owned_ports = 0;
107} 108}
108 109
109static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 110static int ehci_port_change(struct ehci_hcd *ehci)
111{
112 int i = HCS_N_PORTS(ehci->hcs_params);
113
114 /* First check if the controller indicates a change event */
115
116 if (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)
117 return 1;
118
119 /*
120 * Not all controllers appear to update this while going from D3 to D0,
121 * so check the individual port status registers as well
122 */
123
124 while (i--)
125 if (ehci_readl(ehci, &ehci->regs->port_status[i]) & PORT_CSC)
126 return 1;
127
128 return 0;
129}
130
131static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
110 bool suspending, bool do_wakeup) 132 bool suspending, bool do_wakeup)
111{ 133{
112 int port; 134 int port;
113 u32 temp; 135 u32 temp;
136 unsigned long flags;
114 137
115 /* If remote wakeup is enabled for the root hub but disabled 138 /* If remote wakeup is enabled for the root hub but disabled
116 * for the controller, we must adjust all the port wakeup flags 139 * for the controller, we must adjust all the port wakeup flags
@@ -120,6 +143,8 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
120 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup) 143 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
121 return; 144 return;
122 145
146 spin_lock_irqsave(&ehci->lock, flags);
147
123 /* clear phy low-power mode before changing wakeup flags */ 148 /* clear phy low-power mode before changing wakeup flags */
124 if (ehci->has_hostpc) { 149 if (ehci->has_hostpc) {
125 port = HCS_N_PORTS(ehci->hcs_params); 150 port = HCS_N_PORTS(ehci->hcs_params);
@@ -131,7 +156,9 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
131 temp = ehci_readl(ehci, hostpc_reg); 156 temp = ehci_readl(ehci, hostpc_reg);
132 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg); 157 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
133 } 158 }
159 spin_unlock_irqrestore(&ehci->lock, flags);
134 msleep(5); 160 msleep(5);
161 spin_lock_irqsave(&ehci->lock, flags);
135 } 162 }
136 163
137 port = HCS_N_PORTS(ehci->hcs_params); 164 port = HCS_N_PORTS(ehci->hcs_params);
@@ -168,8 +195,10 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
168 } 195 }
169 196
170 /* Does the root hub have a port wakeup pending? */ 197 /* Does the root hub have a port wakeup pending? */
171 if (!suspending && (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)) 198 if (!suspending && ehci_port_change(ehci))
172 usb_hcd_resume_root_hub(ehci_to_hcd(ehci)); 199 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
200
201 spin_unlock_irqrestore(&ehci->lock, flags);
173} 202}
174 203
175static int ehci_bus_suspend (struct usb_hcd *hcd) 204static int ehci_bus_suspend (struct usb_hcd *hcd)
@@ -531,14 +560,15 @@ static ssize_t store_companion(struct device *dev,
531} 560}
532static DEVICE_ATTR(companion, 0644, show_companion, store_companion); 561static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
533 562
534static inline void create_companion_file(struct ehci_hcd *ehci) 563static inline int create_companion_file(struct ehci_hcd *ehci)
535{ 564{
536 int i; 565 int i = 0;
537 566
538 /* with integrated TT there is no companion! */ 567 /* with integrated TT there is no companion! */
539 if (!ehci_is_TDI(ehci)) 568 if (!ehci_is_TDI(ehci))
540 i = device_create_file(ehci_to_hcd(ehci)->self.controller, 569 i = device_create_file(ehci_to_hcd(ehci)->self.controller,
541 &dev_attr_companion); 570 &dev_attr_companion);
571 return i;
542} 572}
543 573
544static inline void remove_companion_file(struct ehci_hcd *ehci) 574static inline void remove_companion_file(struct ehci_hcd *ehci)
@@ -688,8 +718,8 @@ ehci_hub_descriptor (
688 desc->bDescLength = 7 + 2 * temp; 718 desc->bDescLength = 7 + 2 * temp;
689 719
690 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 720 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
691 memset (&desc->bitmap [0], 0, temp); 721 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
692 memset (&desc->bitmap [temp], 0xff, temp); 722 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
693 723
694 temp = 0x0008; /* per-port overcurrent reporting */ 724 temp = 0x0008; /* per-port overcurrent reporting */
695 if (HCS_PPC (ehci->hcs_params)) 725 if (HCS_PPC (ehci->hcs_params))
@@ -772,6 +802,13 @@ static int ehci_hub_control (
772 goto error; 802 goto error;
773 if (ehci->no_selective_suspend) 803 if (ehci->no_selective_suspend)
774 break; 804 break;
805#ifdef CONFIG_USB_OTG
806 if ((hcd->self.otg_port == (wIndex + 1))
807 && hcd->self.b_hnp_enable) {
808 otg_start_hnp(ehci->transceiver);
809 break;
810 }
811#endif
775 if (!(temp & PORT_SUSPEND)) 812 if (!(temp & PORT_SUSPEND))
776 break; 813 break;
777 if ((temp & PORT_PE) == 0) 814 if ((temp & PORT_PE) == 0)
diff --git a/drivers/usb/host/ehci-ixp4xx.c b/drivers/usb/host/ehci-ixp4xx.c
index 89b7c70c6ed6..50e600d26e28 100644
--- a/drivers/usb/host/ehci-ixp4xx.c
+++ b/drivers/usb/host/ehci-ixp4xx.c
@@ -23,7 +23,7 @@ static int ixp4xx_ehci_init(struct usb_hcd *hcd)
23 23
24 ehci->caps = hcd->regs + 0x100; 24 ehci->caps = hcd->regs + 0x100;
25 ehci->regs = hcd->regs + 0x100 25 ehci->regs = hcd->regs + 0x100
26 + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 26 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
27 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 27 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
28 28
29 hcd->has_tt = 1; 29 hcd->has_tt = 1;
diff --git a/drivers/usb/host/ehci-lpm.c b/drivers/usb/host/ehci-lpm.c
index b4d4d63c13ed..2111627a19de 100644
--- a/drivers/usb/host/ehci-lpm.c
+++ b/drivers/usb/host/ehci-lpm.c
@@ -17,7 +17,8 @@
17*/ 17*/
18 18
19/* this file is part of ehci-hcd.c */ 19/* this file is part of ehci-hcd.c */
20static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num) 20static int __maybe_unused ehci_lpm_set_da(struct ehci_hcd *ehci,
21 int dev_addr, int port_num)
21{ 22{
22 u32 __iomem portsc; 23 u32 __iomem portsc;
23 24
@@ -37,7 +38,7 @@ static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num)
37 * this function is used to check if the device support LPM 38 * this function is used to check if the device support LPM
38 * if yes, mark the PORTSC register with PORT_LPM bit 39 * if yes, mark the PORTSC register with PORT_LPM bit
39 */ 40 */
40static int ehci_lpm_check(struct ehci_hcd *ehci, int port) 41static int __maybe_unused ehci_lpm_check(struct ehci_hcd *ehci, int port)
41{ 42{
42 u32 __iomem *portsc ; 43 u32 __iomem *portsc ;
43 u32 val32; 44 u32 val32;
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index 1f3f01eacaf0..12f70c302b0b 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -40,7 +40,7 @@ static inline void ehci_qtd_init(struct ehci_hcd *ehci, struct ehci_qtd *qtd,
40{ 40{
41 memset (qtd, 0, sizeof *qtd); 41 memset (qtd, 0, sizeof *qtd);
42 qtd->qtd_dma = dma; 42 qtd->qtd_dma = dma;
43 qtd->hw_token = cpu_to_le32 (QTD_STS_HALT); 43 qtd->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
44 qtd->hw_next = EHCI_LIST_END(ehci); 44 qtd->hw_next = EHCI_LIST_END(ehci);
45 qtd->hw_alt_next = EHCI_LIST_END(ehci); 45 qtd->hw_alt_next = EHCI_LIST_END(ehci);
46 INIT_LIST_HEAD (&qtd->qtd_list); 46 INIT_LIST_HEAD (&qtd->qtd_list);
@@ -141,6 +141,10 @@ static void ehci_mem_cleanup (struct ehci_hcd *ehci)
141 qh_put (ehci->async); 141 qh_put (ehci->async);
142 ehci->async = NULL; 142 ehci->async = NULL;
143 143
144 if (ehci->dummy)
145 qh_put(ehci->dummy);
146 ehci->dummy = NULL;
147
144 /* DMA consistent memory and pools */ 148 /* DMA consistent memory and pools */
145 if (ehci->qtd_pool) 149 if (ehci->qtd_pool)
146 dma_pool_destroy (ehci->qtd_pool); 150 dma_pool_destroy (ehci->qtd_pool);
@@ -227,8 +231,26 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
227 if (ehci->periodic == NULL) { 231 if (ehci->periodic == NULL) {
228 goto fail; 232 goto fail;
229 } 233 }
230 for (i = 0; i < ehci->periodic_size; i++) 234
231 ehci->periodic [i] = EHCI_LIST_END(ehci); 235 if (ehci->use_dummy_qh) {
236 struct ehci_qh_hw *hw;
237 ehci->dummy = ehci_qh_alloc(ehci, flags);
238 if (!ehci->dummy)
239 goto fail;
240
241 hw = ehci->dummy->hw;
242 hw->hw_next = EHCI_LIST_END(ehci);
243 hw->hw_qtd_next = EHCI_LIST_END(ehci);
244 hw->hw_alt_next = EHCI_LIST_END(ehci);
245 hw->hw_token &= ~QTD_STS_ACTIVE;
246 ehci->dummy->hw = hw;
247
248 for (i = 0; i < ehci->periodic_size; i++)
249 ehci->periodic[i] = ehci->dummy->qh_dma;
250 } else {
251 for (i = 0; i < ehci->periodic_size; i++)
252 ehci->periodic[i] = EHCI_LIST_END(ehci);
253 }
232 254
233 /* software shadow of hardware table */ 255 /* software shadow of hardware table */
234 ehci->pshadow = kcalloc(ehci->periodic_size, sizeof(void *), flags); 256 ehci->pshadow = kcalloc(ehci->periodic_size, sizeof(void *), flags);
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
new file mode 100644
index 000000000000..b5a0bf649c95
--- /dev/null
+++ b/drivers/usb/host/ehci-msm.c
@@ -0,0 +1,265 @@
1/* ehci-msm.c - HSUSB Host Controller Driver Implementation
2 *
3 * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
4 *
5 * Partly derived from ehci-fsl.c and ehci-hcd.c
6 * Copyright (c) 2000-2004 by David Brownell
7 * Copyright (c) 2005 MontaVista Software
8 *
9 * All source code in this file is licensed under the following license except
10 * where indicated.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published
14 * 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.
19 *
20 * See the GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, you can find it at http://www.fsf.org
23 */
24
25#include <linux/platform_device.h>
26#include <linux/clk.h>
27#include <linux/err.h>
28#include <linux/pm_runtime.h>
29
30#include <linux/usb/otg.h>
31#include <linux/usb/msm_hsusb_hw.h>
32
33#define MSM_USB_BASE (hcd->regs)
34
35static struct otg_transceiver *otg;
36
37static int ehci_msm_reset(struct usb_hcd *hcd)
38{
39 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
40 int retval;
41
42 ehci->caps = USB_CAPLENGTH;
43 ehci->regs = USB_CAPLENGTH +
44 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
45 dbg_hcs_params(ehci, "reset");
46 dbg_hcc_params(ehci, "reset");
47
48 /* cache the data to minimize the chip reads*/
49 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
50
51 hcd->has_tt = 1;
52 ehci->sbrn = HCD_USB2;
53
54 retval = ehci_halt(ehci);
55 if (retval)
56 return retval;
57
58 /* data structure init */
59 retval = ehci_init(hcd);
60 if (retval)
61 return retval;
62
63 retval = ehci_reset(ehci);
64 if (retval)
65 return retval;
66
67 /* bursts of unspecified length. */
68 writel(0, USB_AHBBURST);
69 /* Use the AHB transactor */
70 writel(0, USB_AHBMODE);
71 /* Disable streaming mode and select host mode */
72 writel(0x13, USB_USBMODE);
73
74 ehci_port_power(ehci, 1);
75 return 0;
76}
77
78static struct hc_driver msm_hc_driver = {
79 .description = hcd_name,
80 .product_desc = "Qualcomm On-Chip EHCI Host Controller",
81 .hcd_priv_size = sizeof(struct ehci_hcd),
82
83 /*
84 * generic hardware linkage
85 */
86 .irq = ehci_irq,
87 .flags = HCD_USB2 | HCD_MEMORY,
88
89 .reset = ehci_msm_reset,
90 .start = ehci_run,
91
92 .stop = ehci_stop,
93 .shutdown = ehci_shutdown,
94
95 /*
96 * managing i/o requests and associated device resources
97 */
98 .urb_enqueue = ehci_urb_enqueue,
99 .urb_dequeue = ehci_urb_dequeue,
100 .endpoint_disable = ehci_endpoint_disable,
101 .endpoint_reset = ehci_endpoint_reset,
102 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
103
104 /*
105 * scheduling support
106 */
107 .get_frame_number = ehci_get_frame,
108
109 /*
110 * root hub support
111 */
112 .hub_status_data = ehci_hub_status_data,
113 .hub_control = ehci_hub_control,
114 .relinquish_port = ehci_relinquish_port,
115 .port_handed_over = ehci_port_handed_over,
116
117 /*
118 * PM support
119 */
120 .bus_suspend = ehci_bus_suspend,
121 .bus_resume = ehci_bus_resume,
122};
123
124static int ehci_msm_probe(struct platform_device *pdev)
125{
126 struct usb_hcd *hcd;
127 struct resource *res;
128 int ret;
129
130 dev_dbg(&pdev->dev, "ehci_msm proble\n");
131
132 hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
133 if (!hcd) {
134 dev_err(&pdev->dev, "Unable to create HCD\n");
135 return -ENOMEM;
136 }
137
138 hcd->irq = platform_get_irq(pdev, 0);
139 if (hcd->irq < 0) {
140 dev_err(&pdev->dev, "Unable to get IRQ resource\n");
141 ret = hcd->irq;
142 goto put_hcd;
143 }
144
145 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
146 if (!res) {
147 dev_err(&pdev->dev, "Unable to get memory resource\n");
148 ret = -ENODEV;
149 goto put_hcd;
150 }
151
152 hcd->rsrc_start = res->start;
153 hcd->rsrc_len = resource_size(res);
154 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
155 if (!hcd->regs) {
156 dev_err(&pdev->dev, "ioremap failed\n");
157 ret = -ENOMEM;
158 goto put_hcd;
159 }
160
161 /*
162 * OTG driver takes care of PHY initialization, clock management,
163 * powering up VBUS, mapping of registers address space and power
164 * management.
165 */
166 otg = otg_get_transceiver();
167 if (!otg) {
168 dev_err(&pdev->dev, "unable to find transceiver\n");
169 ret = -ENODEV;
170 goto unmap;
171 }
172
173 ret = otg_set_host(otg, &hcd->self);
174 if (ret < 0) {
175 dev_err(&pdev->dev, "unable to register with transceiver\n");
176 goto put_transceiver;
177 }
178
179 device_init_wakeup(&pdev->dev, 1);
180 /*
181 * OTG device parent of HCD takes care of putting
182 * hardware into low power mode.
183 */
184 pm_runtime_no_callbacks(&pdev->dev);
185 pm_runtime_enable(&pdev->dev);
186
187 return 0;
188
189put_transceiver:
190 otg_put_transceiver(otg);
191unmap:
192 iounmap(hcd->regs);
193put_hcd:
194 usb_put_hcd(hcd);
195
196 return ret;
197}
198
199static int __devexit ehci_msm_remove(struct platform_device *pdev)
200{
201 struct usb_hcd *hcd = platform_get_drvdata(pdev);
202
203 device_init_wakeup(&pdev->dev, 0);
204 pm_runtime_disable(&pdev->dev);
205 pm_runtime_set_suspended(&pdev->dev);
206
207 otg_set_host(otg, NULL);
208 otg_put_transceiver(otg);
209
210 usb_put_hcd(hcd);
211
212 return 0;
213}
214
215#ifdef CONFIG_PM
216static int ehci_msm_pm_suspend(struct device *dev)
217{
218 struct usb_hcd *hcd = dev_get_drvdata(dev);
219 bool wakeup = device_may_wakeup(dev);
220
221 dev_dbg(dev, "ehci-msm PM suspend\n");
222
223 /*
224 * EHCI helper function has also the same check before manipulating
225 * port wakeup flags. We do check here the same condition before
226 * calling the same helper function to avoid bringing hardware
227 * from Low power mode when there is no need for adjusting port
228 * wakeup flags.
229 */
230 if (hcd->self.root_hub->do_remote_wakeup && !wakeup) {
231 pm_runtime_resume(dev);
232 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
233 wakeup);
234 }
235
236 return 0;
237}
238
239static int ehci_msm_pm_resume(struct device *dev)
240{
241 struct usb_hcd *hcd = dev_get_drvdata(dev);
242
243 dev_dbg(dev, "ehci-msm PM resume\n");
244 ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
245
246 return 0;
247}
248#else
249#define ehci_msm_pm_suspend NULL
250#define ehci_msm_pm_resume NULL
251#endif
252
253static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
254 .suspend = ehci_msm_pm_suspend,
255 .resume = ehci_msm_pm_resume,
256};
257
258static struct platform_driver ehci_msm_driver = {
259 .probe = ehci_msm_probe,
260 .remove = __devexit_p(ehci_msm_remove),
261 .driver = {
262 .name = "msm_hsusb_host",
263 .pm = &ehci_msm_dev_pm_ops,
264 },
265};
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
index a8ad8ac120a2..0c058be35a38 100644
--- a/drivers/usb/host/ehci-mxc.c
+++ b/drivers/usb/host/ehci-mxc.c
@@ -21,17 +21,17 @@
21#include <linux/clk.h> 21#include <linux/clk.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/usb/otg.h> 23#include <linux/usb/otg.h>
24#include <linux/usb/ulpi.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25 26
26#include <mach/mxc_ehci.h> 27#include <mach/mxc_ehci.h>
27 28
29#include <asm/mach-types.h>
30
28#define ULPI_VIEWPORT_OFFSET 0x170 31#define ULPI_VIEWPORT_OFFSET 0x170
29#define PORTSC_OFFSET 0x184
30#define USBMODE_OFFSET 0x1a8
31#define USBMODE_CM_HOST 3
32 32
33struct ehci_mxc_priv { 33struct ehci_mxc_priv {
34 struct clk *usbclk, *ahbclk; 34 struct clk *usbclk, *ahbclk, *phy1clk;
35 struct usb_hcd *hcd; 35 struct usb_hcd *hcd;
36}; 36};
37 37
@@ -41,16 +41,14 @@ static int ehci_mxc_setup(struct usb_hcd *hcd)
41 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 41 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
42 int retval; 42 int retval;
43 43
44 /* EHCI registers start at offset 0x100 */
45 ehci->caps = hcd->regs + 0x100;
46 ehci->regs = hcd->regs + 0x100 +
47 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
48 dbg_hcs_params(ehci, "reset"); 44 dbg_hcs_params(ehci, "reset");
49 dbg_hcc_params(ehci, "reset"); 45 dbg_hcc_params(ehci, "reset");
50 46
51 /* cache this readonly data; minimize chip reads */ 47 /* cache this readonly data; minimize chip reads */
52 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 48 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
53 49
50 hcd->has_tt = 1;
51
54 retval = ehci_halt(ehci); 52 retval = ehci_halt(ehci);
55 if (retval) 53 if (retval)
56 return retval; 54 return retval;
@@ -60,8 +58,6 @@ static int ehci_mxc_setup(struct usb_hcd *hcd)
60 if (retval) 58 if (retval)
61 return retval; 59 return retval;
62 60
63 hcd->has_tt = 1;
64
65 ehci->sbrn = 0x20; 61 ehci->sbrn = 0x20;
66 62
67 ehci_reset(ehci); 63 ehci_reset(ehci);
@@ -95,6 +91,7 @@ static const struct hc_driver ehci_mxc_hc_driver = {
95 .urb_enqueue = ehci_urb_enqueue, 91 .urb_enqueue = ehci_urb_enqueue,
96 .urb_dequeue = ehci_urb_dequeue, 92 .urb_dequeue = ehci_urb_dequeue,
97 .endpoint_disable = ehci_endpoint_disable, 93 .endpoint_disable = ehci_endpoint_disable,
94 .endpoint_reset = ehci_endpoint_reset,
98 95
99 /* 96 /*
100 * scheduling support 97 * scheduling support
@@ -110,6 +107,8 @@ static const struct hc_driver ehci_mxc_hc_driver = {
110 .bus_resume = ehci_bus_resume, 107 .bus_resume = ehci_bus_resume,
111 .relinquish_port = ehci_relinquish_port, 108 .relinquish_port = ehci_relinquish_port,
112 .port_handed_over = ehci_port_handed_over, 109 .port_handed_over = ehci_port_handed_over,
110
111 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
113}; 112};
114 113
115static int ehci_mxc_drv_probe(struct platform_device *pdev) 114static int ehci_mxc_drv_probe(struct platform_device *pdev)
@@ -117,9 +116,11 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
117 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; 116 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
118 struct usb_hcd *hcd; 117 struct usb_hcd *hcd;
119 struct resource *res; 118 struct resource *res;
120 int irq, ret, temp; 119 int irq, ret;
120 unsigned int flags;
121 struct ehci_mxc_priv *priv; 121 struct ehci_mxc_priv *priv;
122 struct device *dev = &pdev->dev; 122 struct device *dev = &pdev->dev;
123 struct ehci_hcd *ehci;
123 124
124 dev_info(&pdev->dev, "initializing i.MX USB Controller\n"); 125 dev_info(&pdev->dev, "initializing i.MX USB Controller\n");
125 126
@@ -163,17 +164,6 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
163 goto err_ioremap; 164 goto err_ioremap;
164 } 165 }
165 166
166 /* call platform specific init function */
167 if (pdata->init) {
168 ret = pdata->init(pdev);
169 if (ret) {
170 dev_err(dev, "platform init failed\n");
171 goto err_init;
172 }
173 /* platforms need some time to settle changed IO settings */
174 mdelay(10);
175 }
176
177 /* enable clocks */ 167 /* enable clocks */
178 priv->usbclk = clk_get(dev, "usb"); 168 priv->usbclk = clk_get(dev, "usb");
179 if (IS_ERR(priv->usbclk)) { 169 if (IS_ERR(priv->usbclk)) {
@@ -191,18 +181,40 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
191 clk_enable(priv->ahbclk); 181 clk_enable(priv->ahbclk);
192 } 182 }
193 183
194 /* set USBMODE to host mode */ 184 /* "dr" device has its own clock on i.MX51 */
195 temp = readl(hcd->regs + USBMODE_OFFSET); 185 if (cpu_is_mx51() && (pdev->id == 0)) {
196 writel(temp | USBMODE_CM_HOST, hcd->regs + USBMODE_OFFSET); 186 priv->phy1clk = clk_get(dev, "usb_phy1");
187 if (IS_ERR(priv->phy1clk)) {
188 ret = PTR_ERR(priv->phy1clk);
189 goto err_clk_phy;
190 }
191 clk_enable(priv->phy1clk);
192 }
193
194
195 /* call platform specific init function */
196 if (pdata->init) {
197 ret = pdata->init(pdev);
198 if (ret) {
199 dev_err(dev, "platform init failed\n");
200 goto err_init;
201 }
202 /* platforms need some time to settle changed IO settings */
203 mdelay(10);
204 }
205
206 ehci = hcd_to_ehci(hcd);
207
208 /* EHCI registers start at offset 0x100 */
209 ehci->caps = hcd->regs + 0x100;
210 ehci->regs = hcd->regs + 0x100 +
211 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
197 212
198 /* set up the PORTSCx register */ 213 /* set up the PORTSCx register */
199 writel(pdata->portsc, hcd->regs + PORTSC_OFFSET); 214 ehci_writel(ehci, pdata->portsc, &ehci->regs->port_status[0]);
200 mdelay(10);
201 215
202 /* setup specific usb hw */ 216 /* is this really needed? */
203 ret = mxc_initialize_usb_hw(pdev->id, pdata->flags); 217 msleep(10);
204 if (ret < 0)
205 goto err_init;
206 218
207 /* Initialize the transceiver */ 219 /* Initialize the transceiver */
208 if (pdata->otg) { 220 if (pdata->otg) {
@@ -227,12 +239,34 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
227 if (ret) 239 if (ret)
228 goto err_add; 240 goto err_add;
229 241
242 if (pdata->otg) {
243 /*
244 * efikamx and efikasb have some hardware bug which is
245 * preventing usb to work unless CHRGVBUS is set.
246 * It's in violation of USB specs
247 */
248 if (machine_is_mx51_efikamx() || machine_is_mx51_efikasb()) {
249 flags = otg_io_read(pdata->otg, ULPI_OTG_CTRL);
250 flags |= ULPI_OTG_CTRL_CHRGVBUS;
251 ret = otg_io_write(pdata->otg, flags, ULPI_OTG_CTRL);
252 if (ret) {
253 dev_err(dev, "unable to set CHRVBUS\n");
254 goto err_add;
255 }
256 }
257 }
258
230 return 0; 259 return 0;
231 260
232err_add: 261err_add:
233 if (pdata && pdata->exit) 262 if (pdata && pdata->exit)
234 pdata->exit(pdev); 263 pdata->exit(pdev);
235err_init: 264err_init:
265 if (priv->phy1clk) {
266 clk_disable(priv->phy1clk);
267 clk_put(priv->phy1clk);
268 }
269err_clk_phy:
236 if (priv->ahbclk) { 270 if (priv->ahbclk) {
237 clk_disable(priv->ahbclk); 271 clk_disable(priv->ahbclk);
238 clk_put(priv->ahbclk); 272 clk_put(priv->ahbclk);
@@ -276,6 +310,10 @@ static int __exit ehci_mxc_drv_remove(struct platform_device *pdev)
276 clk_disable(priv->ahbclk); 310 clk_disable(priv->ahbclk);
277 clk_put(priv->ahbclk); 311 clk_put(priv->ahbclk);
278 } 312 }
313 if (priv->phy1clk) {
314 clk_disable(priv->phy1clk);
315 clk_put(priv->phy1clk);
316 }
279 317
280 kfree(priv); 318 kfree(priv);
281 319
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c
new file mode 100644
index 000000000000..ff55757ba7d8
--- /dev/null
+++ b/drivers/usb/host/ehci-octeon.c
@@ -0,0 +1,207 @@
1/*
2 * EHCI HCD glue for Cavium Octeon II SOCs.
3 *
4 * Loosely based on ehci-au1xxx.c
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 *
10 * Copyright (C) 2010 Cavium Networks
11 *
12 */
13
14#include <linux/platform_device.h>
15
16#include <asm/octeon/octeon.h>
17#include <asm/octeon/cvmx-uctlx-defs.h>
18
19#define OCTEON_EHCI_HCD_NAME "octeon-ehci"
20
21/* Common clock init code. */
22void octeon2_usb_clocks_start(void);
23void octeon2_usb_clocks_stop(void);
24
25static void ehci_octeon_start(void)
26{
27 union cvmx_uctlx_ehci_ctl ehci_ctl;
28
29 octeon2_usb_clocks_start();
30
31 ehci_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_EHCI_CTL(0));
32 /* Use 64-bit addressing. */
33 ehci_ctl.s.ehci_64b_addr_en = 1;
34 ehci_ctl.s.l2c_addr_msb = 0;
35 ehci_ctl.s.l2c_buff_emod = 1; /* Byte swapped. */
36 ehci_ctl.s.l2c_desc_emod = 1; /* Byte swapped. */
37 cvmx_write_csr(CVMX_UCTLX_EHCI_CTL(0), ehci_ctl.u64);
38}
39
40static void ehci_octeon_stop(void)
41{
42 octeon2_usb_clocks_stop();
43}
44
45static const struct hc_driver ehci_octeon_hc_driver = {
46 .description = hcd_name,
47 .product_desc = "Octeon EHCI",
48 .hcd_priv_size = sizeof(struct ehci_hcd),
49
50 /*
51 * generic hardware linkage
52 */
53 .irq = ehci_irq,
54 .flags = HCD_MEMORY | HCD_USB2,
55
56 /*
57 * basic lifecycle operations
58 */
59 .reset = ehci_init,
60 .start = ehci_run,
61 .stop = ehci_stop,
62 .shutdown = ehci_shutdown,
63
64 /*
65 * managing i/o requests and associated device resources
66 */
67 .urb_enqueue = ehci_urb_enqueue,
68 .urb_dequeue = ehci_urb_dequeue,
69 .endpoint_disable = ehci_endpoint_disable,
70 .endpoint_reset = ehci_endpoint_reset,
71
72 /*
73 * scheduling support
74 */
75 .get_frame_number = ehci_get_frame,
76
77 /*
78 * root hub support
79 */
80 .hub_status_data = ehci_hub_status_data,
81 .hub_control = ehci_hub_control,
82 .bus_suspend = ehci_bus_suspend,
83 .bus_resume = ehci_bus_resume,
84 .relinquish_port = ehci_relinquish_port,
85 .port_handed_over = ehci_port_handed_over,
86
87 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
88};
89
90static u64 ehci_octeon_dma_mask = DMA_BIT_MASK(64);
91
92static int ehci_octeon_drv_probe(struct platform_device *pdev)
93{
94 struct usb_hcd *hcd;
95 struct ehci_hcd *ehci;
96 struct resource *res_mem;
97 int irq;
98 int ret;
99
100 if (usb_disabled())
101 return -ENODEV;
102
103 irq = platform_get_irq(pdev, 0);
104 if (irq < 0) {
105 dev_err(&pdev->dev, "No irq assigned\n");
106 return -ENODEV;
107 }
108
109 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
110 if (res_mem == NULL) {
111 dev_err(&pdev->dev, "No register space assigned\n");
112 return -ENODEV;
113 }
114
115 /*
116 * We can DMA from anywhere. But the descriptors must be in
117 * the lower 4GB.
118 */
119 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
120 pdev->dev.dma_mask = &ehci_octeon_dma_mask;
121
122 hcd = usb_create_hcd(&ehci_octeon_hc_driver, &pdev->dev, "octeon");
123 if (!hcd)
124 return -ENOMEM;
125
126 hcd->rsrc_start = res_mem->start;
127 hcd->rsrc_len = res_mem->end - res_mem->start + 1;
128
129 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
130 OCTEON_EHCI_HCD_NAME)) {
131 dev_err(&pdev->dev, "request_mem_region failed\n");
132 ret = -EBUSY;
133 goto err1;
134 }
135
136 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
137 if (!hcd->regs) {
138 dev_err(&pdev->dev, "ioremap failed\n");
139 ret = -ENOMEM;
140 goto err2;
141 }
142
143 ehci_octeon_start();
144
145 ehci = hcd_to_ehci(hcd);
146
147 /* Octeon EHCI matches CPU endianness. */
148#ifdef __BIG_ENDIAN
149 ehci->big_endian_mmio = 1;
150#endif
151
152 ehci->caps = hcd->regs;
153 ehci->regs = hcd->regs +
154 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
155 /* cache this readonly data; minimize chip reads */
156 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
157
158 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
159 if (ret) {
160 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
161 goto err3;
162 }
163
164 platform_set_drvdata(pdev, hcd);
165
166 /* root ports should always stay powered */
167 ehci_port_power(ehci, 1);
168
169 return 0;
170err3:
171 ehci_octeon_stop();
172
173 iounmap(hcd->regs);
174err2:
175 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
176err1:
177 usb_put_hcd(hcd);
178 return ret;
179}
180
181static int ehci_octeon_drv_remove(struct platform_device *pdev)
182{
183 struct usb_hcd *hcd = platform_get_drvdata(pdev);
184
185 usb_remove_hcd(hcd);
186
187 ehci_octeon_stop();
188 iounmap(hcd->regs);
189 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
190 usb_put_hcd(hcd);
191
192 platform_set_drvdata(pdev, NULL);
193
194 return 0;
195}
196
197static struct platform_driver ehci_octeon_driver = {
198 .probe = ehci_octeon_drv_probe,
199 .remove = ehci_octeon_drv_remove,
200 .shutdown = usb_hcd_platform_shutdown,
201 .driver = {
202 .name = OCTEON_EHCI_HCD_NAME,
203 .owner = THIS_MODULE,
204 }
205};
206
207MODULE_ALIAS("platform:" OCTEON_EHCI_HCD_NAME);
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 116ae280053a..55a57c23dd0f 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -1,11 +1,13 @@
1/* 1/*
2 * ehci-omap.c - driver for USBHOST on OMAP 34xx processor 2 * ehci-omap.c - driver for USBHOST on OMAP3/4 processors
3 * 3 *
4 * Bus Glue for OMAP34xx USBHOST 3 port EHCI controller 4 * Bus Glue for the EHCI controllers in OMAP3/4
5 * Tested on OMAP3430 ES2.0 SDP 5 * Tested on several OMAP3 boards, and OMAP4 Pandaboard
6 * 6 *
7 * Copyright (C) 2007-2008 Texas Instruments, Inc. 7 * Copyright (C) 2007-2011 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>
10 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
9 * 11 *
10 * Copyright (C) 2009 Nokia Corporation 12 * Copyright (C) 2009 Nokia Corporation
11 * Contact: Felipe Balbi <felipe.balbi@nokia.com> 13 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
@@ -26,95 +28,19 @@
26 * along with this program; if not, write to the Free Software 28 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 30 *
29 * TODO (last updated Feb 12, 2010): 31 * TODO (last updated Feb 27, 2010):
30 * - add kernel-doc 32 * - add kernel-doc
31 * - enable AUTOIDLE 33 * - enable AUTOIDLE
32 * - add suspend/resume 34 * - add suspend/resume
33 * - move workarounds to board-files 35 * - add HSIC and TLL support
36 * - convert to use hwmod and runtime PM
34 */ 37 */
35 38
36#include <linux/platform_device.h> 39#include <linux/platform_device.h>
37#include <linux/clk.h>
38#include <linux/gpio.h>
39#include <linux/regulator/consumer.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/usb/ulpi.h> 41#include <linux/usb/ulpi.h>
42#include <plat/usb.h> 42#include <plat/usb.h>
43 43#include <linux/regulator/consumer.h>
44/*
45 * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
46 * Use ehci_omap_readl()/ehci_omap_writel() functions
47 */
48
49/* TLL Register Set */
50#define OMAP_USBTLL_REVISION (0x00)
51#define OMAP_USBTLL_SYSCONFIG (0x10)
52#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
53#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
54#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
55#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
56#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
57
58#define OMAP_USBTLL_SYSSTATUS (0x14)
59#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
60
61#define OMAP_USBTLL_IRQSTATUS (0x18)
62#define OMAP_USBTLL_IRQENABLE (0x1C)
63
64#define OMAP_TLL_SHARED_CONF (0x30)
65#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
66#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
67#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
68#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
69#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
70
71#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
72#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
73#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
74#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
75#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
76#define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
77
78#define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
79#define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
80#define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
81#define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
82#define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
83#define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
84#define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
85#define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
86#define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
87
88#define OMAP_TLL_CHANNEL_COUNT 3
89#define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 1)
90#define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 2)
91#define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 4)
92
93/* UHH Register Set */
94#define OMAP_UHH_REVISION (0x00)
95#define OMAP_UHH_SYSCONFIG (0x10)
96#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
97#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
98#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
99#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
100#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
101#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
102
103#define OMAP_UHH_SYSSTATUS (0x14)
104#define OMAP_UHH_HOSTCONFIG (0x40)
105#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
106#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
107#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
108#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
109#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
110#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
111#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
112#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
113#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
114#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
115#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
116
117#define OMAP_UHH_DEBUG_CSR (0x44)
118 44
119/* EHCI Register Set */ 45/* EHCI Register Set */
120#define EHCI_INSNREG04 (0xA0) 46#define EHCI_INSNREG04 (0xA0)
@@ -129,116 +55,22 @@
129 55
130/*-------------------------------------------------------------------------*/ 56/*-------------------------------------------------------------------------*/
131 57
132static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val) 58static const struct hc_driver ehci_omap_hc_driver;
133{
134 __raw_writel(val, base + reg);
135}
136 59
137static inline u32 ehci_omap_readl(void __iomem *base, u32 reg)
138{
139 return __raw_readl(base + reg);
140}
141 60
142static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val) 61static inline void ehci_write(void __iomem *base, u32 reg, u32 val)
143{ 62{
144 __raw_writeb(val, base + reg); 63 __raw_writel(val, base + reg);
145} 64}
146 65
147static inline u8 ehci_omap_readb(void __iomem *base, u8 reg) 66static inline u32 ehci_read(void __iomem *base, u32 reg)
148{ 67{
149 return __raw_readb(base + reg); 68 return __raw_readl(base + reg);
150}
151
152/*-------------------------------------------------------------------------*/
153
154struct ehci_hcd_omap {
155 struct ehci_hcd *ehci;
156 struct device *dev;
157
158 struct clk *usbhost_ick;
159 struct clk *usbhost2_120m_fck;
160 struct clk *usbhost1_48m_fck;
161 struct clk *usbtll_fck;
162 struct clk *usbtll_ick;
163
164 /* FIXME the following two workarounds are
165 * board specific not silicon-specific so these
166 * should be moved to board-file instead.
167 *
168 * Maybe someone from TI will know better which
169 * board is affected and needs the workarounds
170 * to be applied
171 */
172
173 /* gpio for resetting phy */
174 int reset_gpio_port[OMAP3_HS_USB_PORTS];
175
176 /* phy reset workaround */
177 int phy_reset;
178
179 /* desired phy_mode: TLL, PHY */
180 enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
181
182 void __iomem *uhh_base;
183 void __iomem *tll_base;
184 void __iomem *ehci_base;
185
186 /* Regulators for USB PHYs.
187 * Each PHY can have a separate regulator.
188 */
189 struct regulator *regulator[OMAP3_HS_USB_PORTS];
190};
191
192/*-------------------------------------------------------------------------*/
193
194static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask)
195{
196 unsigned reg;
197 int i;
198
199 /* Program the 3 TLL channels upfront */
200 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
201 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
202
203 /* Disable AutoIdle, BitStuffing and use SDR Mode */
204 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
205 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
206 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
207 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
208 }
209
210 /* Program Common TLL register */
211 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
212 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
213 | OMAP_TLL_SHARED_CONF_USB_DIVRATION
214 | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN);
215 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
216
217 ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
218
219 /* Enable channels now */
220 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
221 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
222
223 /* Enable only the reg that is needed */
224 if (!(tll_channel_mask & 1<<i))
225 continue;
226
227 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
228 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
229
230 ehci_omap_writeb(omap->tll_base,
231 OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
232 dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
233 i+1, ehci_omap_readb(omap->tll_base,
234 OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
235 }
236} 69}
237 70
238/*-------------------------------------------------------------------------*/ 71static void omap_ehci_soft_phy_reset(struct platform_device *pdev, u8 port)
239
240static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
241{ 72{
73 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
242 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 74 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
243 unsigned reg = 0; 75 unsigned reg = 0;
244 76
@@ -252,336 +84,20 @@ static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
252 /* start ULPI access*/ 84 /* start ULPI access*/
253 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT); 85 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
254 86
255 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg); 87 ehci_write(hcd->regs, EHCI_INSNREG05_ULPI, reg);
256 88
257 /* Wait for ULPI access completion */ 89 /* Wait for ULPI access completion */
258 while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI) 90 while ((ehci_read(hcd->regs, EHCI_INSNREG05_ULPI)
259 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) { 91 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
260 cpu_relax(); 92 cpu_relax();
261 93
262 if (time_after(jiffies, timeout)) { 94 if (time_after(jiffies, timeout)) {
263 dev_dbg(omap->dev, "phy reset operation timed out\n"); 95 dev_dbg(&pdev->dev, "phy reset operation timed out\n");
264 break; 96 break;
265 } 97 }
266 } 98 }
267} 99}
268 100
269/* omap_start_ehc
270 * - Start the TI USBHOST controller
271 */
272static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
273{
274 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
275 u8 tll_ch_mask = 0;
276 unsigned reg = 0;
277 int ret = 0;
278
279 dev_dbg(omap->dev, "starting TI EHCI USB Controller\n");
280
281 /* Enable Clocks for USBHOST */
282 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
283 if (IS_ERR(omap->usbhost_ick)) {
284 ret = PTR_ERR(omap->usbhost_ick);
285 goto err_host_ick;
286 }
287 clk_enable(omap->usbhost_ick);
288
289 omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck");
290 if (IS_ERR(omap->usbhost2_120m_fck)) {
291 ret = PTR_ERR(omap->usbhost2_120m_fck);
292 goto err_host_120m_fck;
293 }
294 clk_enable(omap->usbhost2_120m_fck);
295
296 omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck");
297 if (IS_ERR(omap->usbhost1_48m_fck)) {
298 ret = PTR_ERR(omap->usbhost1_48m_fck);
299 goto err_host_48m_fck;
300 }
301 clk_enable(omap->usbhost1_48m_fck);
302
303 if (omap->phy_reset) {
304 /* Refer: ISSUE1 */
305 if (gpio_is_valid(omap->reset_gpio_port[0])) {
306 gpio_request(omap->reset_gpio_port[0],
307 "USB1 PHY reset");
308 gpio_direction_output(omap->reset_gpio_port[0], 0);
309 }
310
311 if (gpio_is_valid(omap->reset_gpio_port[1])) {
312 gpio_request(omap->reset_gpio_port[1],
313 "USB2 PHY reset");
314 gpio_direction_output(omap->reset_gpio_port[1], 0);
315 }
316
317 /* Hold the PHY in RESET for enough time till DIR is high */
318 udelay(10);
319 }
320
321 /* Configure TLL for 60Mhz clk for ULPI */
322 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
323 if (IS_ERR(omap->usbtll_fck)) {
324 ret = PTR_ERR(omap->usbtll_fck);
325 goto err_tll_fck;
326 }
327 clk_enable(omap->usbtll_fck);
328
329 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
330 if (IS_ERR(omap->usbtll_ick)) {
331 ret = PTR_ERR(omap->usbtll_ick);
332 goto err_tll_ick;
333 }
334 clk_enable(omap->usbtll_ick);
335
336 /* perform TLL soft reset, and wait until reset is complete */
337 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
338 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
339
340 /* Wait for TLL reset to complete */
341 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
342 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
343 cpu_relax();
344
345 if (time_after(jiffies, timeout)) {
346 dev_dbg(omap->dev, "operation timed out\n");
347 ret = -EINVAL;
348 goto err_sys_status;
349 }
350 }
351
352 dev_dbg(omap->dev, "TLL RESET DONE\n");
353
354 /* (1<<3) = no idle mode only for initial debugging */
355 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
356 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
357 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
358 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
359
360
361 /* Put UHH in NoIdle/NoStandby mode */
362 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
363 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
364 | OMAP_UHH_SYSCONFIG_SIDLEMODE
365 | OMAP_UHH_SYSCONFIG_CACTIVITY
366 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
367 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
368
369 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
370
371 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
372
373 /* setup ULPI bypass and burst configurations */
374 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
375 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
376 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
377 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
378
379 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN)
380 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
381 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN)
382 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
383 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN)
384 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
385
386 /* Bypass the TLL module for PHY mode operation */
387 if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
388 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
389 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) ||
390 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) ||
391 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY))
392 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
393 else
394 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
395 } else {
396 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
397 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
398 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
399 else if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
400 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
401
402 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
403 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
404 else if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
405 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
406
407 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY)
408 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
409 else if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
410 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
411
412 }
413 ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
414 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
415
416
417 /*
418 * An undocumented "feature" in the OMAP3 EHCI controller,
419 * causes suspended ports to be taken out of suspend when
420 * the USBCMD.Run/Stop bit is cleared (for example when
421 * we do ehci_bus_suspend).
422 * This breaks suspend-resume if the root-hub is allowed
423 * to suspend. Writing 1 to this undocumented register bit
424 * disables this feature and restores normal behavior.
425 */
426 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG04,
427 EHCI_INSNREG04_DISABLE_UNSUSPEND);
428
429 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
430 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
431 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
432
433 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
434 tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK;
435 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
436 tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK;
437 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
438 tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK;
439
440 /* Enable UTMI mode for required TLL channels */
441 omap_usb_utmi_init(omap, tll_ch_mask);
442 }
443
444 if (omap->phy_reset) {
445 /* Refer ISSUE1:
446 * Hold the PHY in RESET for enough time till
447 * PHY is settled and ready
448 */
449 udelay(10);
450
451 if (gpio_is_valid(omap->reset_gpio_port[0]))
452 gpio_set_value(omap->reset_gpio_port[0], 1);
453
454 if (gpio_is_valid(omap->reset_gpio_port[1]))
455 gpio_set_value(omap->reset_gpio_port[1], 1);
456 }
457
458 /* Soft reset the PHY using PHY reset command over ULPI */
459 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
460 omap_ehci_soft_phy_reset(omap, 0);
461 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
462 omap_ehci_soft_phy_reset(omap, 1);
463
464 return 0;
465
466err_sys_status:
467 clk_disable(omap->usbtll_ick);
468 clk_put(omap->usbtll_ick);
469
470err_tll_ick:
471 clk_disable(omap->usbtll_fck);
472 clk_put(omap->usbtll_fck);
473
474err_tll_fck:
475 clk_disable(omap->usbhost1_48m_fck);
476 clk_put(omap->usbhost1_48m_fck);
477
478 if (omap->phy_reset) {
479 if (gpio_is_valid(omap->reset_gpio_port[0]))
480 gpio_free(omap->reset_gpio_port[0]);
481
482 if (gpio_is_valid(omap->reset_gpio_port[1]))
483 gpio_free(omap->reset_gpio_port[1]);
484 }
485
486err_host_48m_fck:
487 clk_disable(omap->usbhost2_120m_fck);
488 clk_put(omap->usbhost2_120m_fck);
489
490err_host_120m_fck:
491 clk_disable(omap->usbhost_ick);
492 clk_put(omap->usbhost_ick);
493
494err_host_ick:
495 return ret;
496}
497
498static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
499{
500 unsigned long timeout = jiffies + msecs_to_jiffies(100);
501
502 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
503
504 /* Reset OMAP modules for insmod/rmmod to work */
505 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
506 OMAP_UHH_SYSCONFIG_SOFTRESET);
507 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
508 & (1 << 0))) {
509 cpu_relax();
510
511 if (time_after(jiffies, timeout))
512 dev_dbg(omap->dev, "operation timed out\n");
513 }
514
515 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
516 & (1 << 1))) {
517 cpu_relax();
518
519 if (time_after(jiffies, timeout))
520 dev_dbg(omap->dev, "operation timed out\n");
521 }
522
523 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
524 & (1 << 2))) {
525 cpu_relax();
526
527 if (time_after(jiffies, timeout))
528 dev_dbg(omap->dev, "operation timed out\n");
529 }
530
531 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
532
533 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
534 & (1 << 0))) {
535 cpu_relax();
536
537 if (time_after(jiffies, timeout))
538 dev_dbg(omap->dev, "operation timed out\n");
539 }
540
541 if (omap->usbtll_fck != NULL) {
542 clk_disable(omap->usbtll_fck);
543 clk_put(omap->usbtll_fck);
544 omap->usbtll_fck = NULL;
545 }
546
547 if (omap->usbhost_ick != NULL) {
548 clk_disable(omap->usbhost_ick);
549 clk_put(omap->usbhost_ick);
550 omap->usbhost_ick = NULL;
551 }
552
553 if (omap->usbhost1_48m_fck != NULL) {
554 clk_disable(omap->usbhost1_48m_fck);
555 clk_put(omap->usbhost1_48m_fck);
556 omap->usbhost1_48m_fck = NULL;
557 }
558
559 if (omap->usbhost2_120m_fck != NULL) {
560 clk_disable(omap->usbhost2_120m_fck);
561 clk_put(omap->usbhost2_120m_fck);
562 omap->usbhost2_120m_fck = NULL;
563 }
564
565 if (omap->usbtll_ick != NULL) {
566 clk_disable(omap->usbtll_ick);
567 clk_put(omap->usbtll_ick);
568 omap->usbtll_ick = NULL;
569 }
570
571 if (omap->phy_reset) {
572 if (gpio_is_valid(omap->reset_gpio_port[0]))
573 gpio_free(omap->reset_gpio_port[0]);
574
575 if (gpio_is_valid(omap->reset_gpio_port[1]))
576 gpio_free(omap->reset_gpio_port[1]);
577 }
578
579 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
580}
581
582/*-------------------------------------------------------------------------*/
583
584static const struct hc_driver ehci_omap_hc_driver;
585 101
586/* configure so an HC device and id are always provided */ 102/* configure so an HC device and id are always provided */
587/* always called with process context; sleeping is OK */ 103/* always called with process context; sleeping is OK */
@@ -595,155 +111,132 @@ static const struct hc_driver ehci_omap_hc_driver;
595 */ 111 */
596static int ehci_hcd_omap_probe(struct platform_device *pdev) 112static int ehci_hcd_omap_probe(struct platform_device *pdev)
597{ 113{
598 struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data; 114 struct device *dev = &pdev->dev;
599 struct ehci_hcd_omap *omap; 115 struct ehci_hcd_omap_platform_data *pdata = dev->platform_data;
600 struct resource *res; 116 struct resource *res;
601 struct usb_hcd *hcd; 117 struct usb_hcd *hcd;
602 118 void __iomem *regs;
603 int irq = platform_get_irq(pdev, 0); 119 struct ehci_hcd *omap_ehci;
604 int ret = -ENODEV; 120 int ret = -ENODEV;
605 int i; 121 int irq;
606 char supply[7]; 122 int i;
607 123 char supply[7];
608 if (!pdata) {
609 dev_dbg(&pdev->dev, "missing platform_data\n");
610 goto err_pdata;
611 }
612 124
613 if (usb_disabled()) 125 if (usb_disabled())
614 goto err_disabled; 126 return -ENODEV;
615 127
616 omap = kzalloc(sizeof(*omap), GFP_KERNEL); 128 if (!dev->parent) {
617 if (!omap) { 129 dev_err(dev, "Missing parent device\n");
618 ret = -ENOMEM; 130 return -ENODEV;
619 goto err_disabled;
620 } 131 }
621 132
622 hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev, 133 irq = platform_get_irq_byname(pdev, "ehci-irq");
623 dev_name(&pdev->dev)); 134 if (irq < 0) {
624 if (!hcd) { 135 dev_err(dev, "EHCI irq failed\n");
625 dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret); 136 return -ENODEV;
626 ret = -ENOMEM;
627 goto err_create_hcd;
628 } 137 }
629 138
630 platform_set_drvdata(pdev, omap); 139 res = platform_get_resource_byname(pdev,
631 omap->dev = &pdev->dev; 140 IORESOURCE_MEM, "ehci");
632 omap->phy_reset = pdata->phy_reset; 141 if (!res) {
633 omap->reset_gpio_port[0] = pdata->reset_gpio_port[0]; 142 dev_err(dev, "UHH EHCI get resource failed\n");
634 omap->reset_gpio_port[1] = pdata->reset_gpio_port[1]; 143 return -ENODEV;
635 omap->reset_gpio_port[2] = pdata->reset_gpio_port[2];
636 omap->port_mode[0] = pdata->port_mode[0];
637 omap->port_mode[1] = pdata->port_mode[1];
638 omap->port_mode[2] = pdata->port_mode[2];
639 omap->ehci = hcd_to_ehci(hcd);
640 omap->ehci->sbrn = 0x20;
641
642 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
643
644 hcd->rsrc_start = res->start;
645 hcd->rsrc_len = resource_size(res);
646
647 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
648 if (!hcd->regs) {
649 dev_err(&pdev->dev, "EHCI ioremap failed\n");
650 ret = -ENOMEM;
651 goto err_ioremap;
652 } 144 }
653 145
654 /* we know this is the memory we want, no need to ioremap again */ 146 regs = ioremap(res->start, resource_size(res));
655 omap->ehci->caps = hcd->regs; 147 if (!regs) {
656 omap->ehci_base = hcd->regs; 148 dev_err(dev, "UHH EHCI ioremap failed\n");
657 149 return -ENOMEM;
658 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
659 omap->uhh_base = ioremap(res->start, resource_size(res));
660 if (!omap->uhh_base) {
661 dev_err(&pdev->dev, "UHH ioremap failed\n");
662 ret = -ENOMEM;
663 goto err_uhh_ioremap;
664 } 150 }
665 151
666 res = platform_get_resource(pdev, IORESOURCE_MEM, 2); 152 hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
667 omap->tll_base = ioremap(res->start, resource_size(res)); 153 dev_name(dev));
668 if (!omap->tll_base) { 154 if (!hcd) {
669 dev_err(&pdev->dev, "TLL ioremap failed\n"); 155 dev_err(dev, "failed to create hcd with err %d\n", ret);
670 ret = -ENOMEM; 156 ret = -ENOMEM;
671 goto err_tll_ioremap; 157 goto err_io;
672 } 158 }
673 159
160 hcd->rsrc_start = res->start;
161 hcd->rsrc_len = resource_size(res);
162 hcd->regs = regs;
163
674 /* get ehci regulator and enable */ 164 /* get ehci regulator and enable */
675 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { 165 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
676 if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) { 166 if (pdata->port_mode[i] != OMAP_EHCI_PORT_MODE_PHY) {
677 omap->regulator[i] = NULL; 167 pdata->regulator[i] = NULL;
678 continue; 168 continue;
679 } 169 }
680 snprintf(supply, sizeof(supply), "hsusb%d", i); 170 snprintf(supply, sizeof(supply), "hsusb%d", i);
681 omap->regulator[i] = regulator_get(omap->dev, supply); 171 pdata->regulator[i] = regulator_get(dev, supply);
682 if (IS_ERR(omap->regulator[i])) { 172 if (IS_ERR(pdata->regulator[i])) {
683 omap->regulator[i] = NULL; 173 pdata->regulator[i] = NULL;
684 dev_dbg(&pdev->dev, 174 dev_dbg(dev,
685 "failed to get ehci port%d regulator\n", i); 175 "failed to get ehci port%d regulator\n", i);
686 } else { 176 } else {
687 regulator_enable(omap->regulator[i]); 177 regulator_enable(pdata->regulator[i]);
688 } 178 }
689 } 179 }
690 180
691 ret = omap_start_ehc(omap, hcd); 181 ret = omap_usbhs_enable(dev);
692 if (ret) { 182 if (ret) {
693 dev_dbg(&pdev->dev, "failed to start ehci\n"); 183 dev_err(dev, "failed to start usbhs with err %d\n", ret);
694 goto err_start; 184 goto err_enable;
695 } 185 }
696 186
697 omap->ehci->regs = hcd->regs 187 /*
698 + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase)); 188 * An undocumented "feature" in the OMAP3 EHCI controller,
189 * causes suspended ports to be taken out of suspend when
190 * the USBCMD.Run/Stop bit is cleared (for example when
191 * we do ehci_bus_suspend).
192 * This breaks suspend-resume if the root-hub is allowed
193 * to suspend. Writing 1 to this undocumented register bit
194 * disables this feature and restores normal behavior.
195 */
196 ehci_write(regs, EHCI_INSNREG04,
197 EHCI_INSNREG04_DISABLE_UNSUSPEND);
198
199 /* Soft reset the PHY using PHY reset command over ULPI */
200 if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY)
201 omap_ehci_soft_phy_reset(pdev, 0);
202 if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY)
203 omap_ehci_soft_phy_reset(pdev, 1);
204
205 omap_ehci = hcd_to_ehci(hcd);
206 omap_ehci->sbrn = 0x20;
699 207
700 dbg_hcs_params(omap->ehci, "reset"); 208 /* we know this is the memory we want, no need to ioremap again */
701 dbg_hcc_params(omap->ehci, "reset"); 209 omap_ehci->caps = hcd->regs;
210 omap_ehci->regs = hcd->regs
211 + HC_LENGTH(ehci, readl(&omap_ehci->caps->hc_capbase));
212
213 dbg_hcs_params(omap_ehci, "reset");
214 dbg_hcc_params(omap_ehci, "reset");
702 215
703 /* cache this readonly data; minimize chip reads */ 216 /* cache this readonly data; minimize chip reads */
704 omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params); 217 omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params);
705 218
706 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); 219 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
707 if (ret) { 220 if (ret) {
708 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); 221 dev_err(dev, "failed to add hcd with err %d\n", ret);
709 goto err_add_hcd; 222 goto err_add_hcd;
710 } 223 }
711 224
712 /* root ports should always stay powered */ 225 /* root ports should always stay powered */
713 ehci_port_power(omap->ehci, 1); 226 ehci_port_power(omap_ehci, 1);
714 227
715 return 0; 228 return 0;
716 229
717err_add_hcd: 230err_add_hcd:
718 omap_stop_ehc(omap, hcd); 231 omap_usbhs_disable(dev);
719
720err_start:
721 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
722 if (omap->regulator[i]) {
723 regulator_disable(omap->regulator[i]);
724 regulator_put(omap->regulator[i]);
725 }
726 }
727 iounmap(omap->tll_base);
728
729err_tll_ioremap:
730 iounmap(omap->uhh_base);
731 232
732err_uhh_ioremap: 233err_enable:
733 iounmap(hcd->regs);
734
735err_ioremap:
736 usb_put_hcd(hcd); 234 usb_put_hcd(hcd);
737 235
738err_create_hcd: 236err_io:
739 kfree(omap);
740err_disabled:
741err_pdata:
742 return ret; 237 return ret;
743} 238}
744 239
745/* may be called without controller electrically present */
746/* may be called with controller, bus, and devices active */
747 240
748/** 241/**
749 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs 242 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
@@ -755,31 +248,18 @@ err_pdata:
755 */ 248 */
756static int ehci_hcd_omap_remove(struct platform_device *pdev) 249static int ehci_hcd_omap_remove(struct platform_device *pdev)
757{ 250{
758 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev); 251 struct device *dev = &pdev->dev;
759 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci); 252 struct usb_hcd *hcd = dev_get_drvdata(dev);
760 int i;
761 253
762 usb_remove_hcd(hcd); 254 usb_remove_hcd(hcd);
763 omap_stop_ehc(omap, hcd); 255 omap_usbhs_disable(dev);
764 iounmap(hcd->regs);
765 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
766 if (omap->regulator[i]) {
767 regulator_disable(omap->regulator[i]);
768 regulator_put(omap->regulator[i]);
769 }
770 }
771 iounmap(omap->tll_base);
772 iounmap(omap->uhh_base);
773 usb_put_hcd(hcd); 256 usb_put_hcd(hcd);
774 kfree(omap);
775
776 return 0; 257 return 0;
777} 258}
778 259
779static void ehci_hcd_omap_shutdown(struct platform_device *pdev) 260static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
780{ 261{
781 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev); 262 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
782 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
783 263
784 if (hcd->driver->shutdown) 264 if (hcd->driver->shutdown)
785 hcd->driver->shutdown(hcd); 265 hcd->driver->shutdown(hcd);
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 0f87dc72820a..395bdb0248d5 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -105,7 +105,8 @@ static int ehci_orion_setup(struct usb_hcd *hcd)
105 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 105 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
106 int retval; 106 int retval;
107 107
108 ehci_reset(ehci); 108 hcd->has_tt = 1;
109
109 retval = ehci_halt(ehci); 110 retval = ehci_halt(ehci);
110 if (retval) 111 if (retval)
111 return retval; 112 return retval;
@@ -117,7 +118,7 @@ static int ehci_orion_setup(struct usb_hcd *hcd)
117 if (retval) 118 if (retval)
118 return retval; 119 return retval;
119 120
120 hcd->has_tt = 1; 121 ehci_reset(ehci);
121 122
122 ehci_port_power(ehci, 0); 123 ehci_port_power(ehci, 0);
123 124
@@ -250,7 +251,7 @@ static int __devinit ehci_orion_drv_probe(struct platform_device *pdev)
250 ehci = hcd_to_ehci(hcd); 251 ehci = hcd_to_ehci(hcd);
251 ehci->caps = hcd->regs + 0x100; 252 ehci->caps = hcd->regs + 0x100;
252 ehci->regs = hcd->regs + 0x100 + 253 ehci->regs = hcd->regs + 0x100 +
253 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 254 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
254 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 255 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
255 hcd->has_tt = 1; 256 hcd->has_tt = 1;
256 ehci->sbrn = 0x20; 257 ehci->sbrn = 0x20;
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index a1e8d273103f..1102ce65a3a9 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -22,6 +22,9 @@
22#error "This file is PCI bus glue. CONFIG_PCI must be defined." 22#error "This file is PCI bus glue. CONFIG_PCI must be defined."
23#endif 23#endif
24 24
25/* defined here to avoid adding to pci_ids.h for single instance use */
26#define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70
27
25/*-------------------------------------------------------------------------*/ 28/*-------------------------------------------------------------------------*/
26 29
27/* called after powerup, by probe or system-pm "wakeup" */ 30/* called after powerup, by probe or system-pm "wakeup" */
@@ -67,7 +70,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
67 70
68 ehci->caps = hcd->regs; 71 ehci->caps = hcd->regs;
69 ehci->regs = hcd->regs + 72 ehci->regs = hcd->regs +
70 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 73 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
71 74
72 dbg_hcs_params(ehci, "reset"); 75 dbg_hcs_params(ehci, "reset");
73 dbg_hcc_params(ehci, "reset"); 76 dbg_hcc_params(ehci, "reset");
@@ -103,6 +106,19 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
103 if (retval) 106 if (retval)
104 return retval; 107 return retval;
105 108
109 if ((pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x7808) ||
110 (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x4396)) {
111 /* EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
112 * read/write memory space which does not belong to it when
113 * there is NULL pointer with T-bit set to 1 in the frame list
114 * table. To avoid the issue, the frame list link pointer
115 * should always contain a valid pointer to a inactive qh.
116 */
117 ehci->use_dummy_qh = 1;
118 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI "
119 "dummy qh workaround\n");
120 }
121
106 /* data structure init */ 122 /* data structure init */
107 retval = ehci_init(hcd); 123 retval = ehci_init(hcd);
108 if (retval) 124 if (retval)
@@ -124,6 +140,10 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
124 ehci_info(ehci, "disable lpm for langwell/penwell\n"); 140 ehci_info(ehci, "disable lpm for langwell/penwell\n");
125 ehci->has_lpm = 0; 141 ehci->has_lpm = 0;
126 } 142 }
143 if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB) {
144 hcd->has_tt = 1;
145 tdi_reset(ehci);
146 }
127 break; 147 break;
128 case PCI_VENDOR_ID_TDI: 148 case PCI_VENDOR_ID_TDI:
129 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 149 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
@@ -132,6 +152,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
132 } 152 }
133 break; 153 break;
134 case PCI_VENDOR_ID_AMD: 154 case PCI_VENDOR_ID_AMD:
155 /* AMD PLL quirk */
156 if (usb_amd_find_chipset_info())
157 ehci->amd_pll_fix = 1;
135 /* AMD8111 EHCI doesn't work, according to AMD errata */ 158 /* AMD8111 EHCI doesn't work, according to AMD errata */
136 if (pdev->device == 0x7463) { 159 if (pdev->device == 0x7463) {
137 ehci_info(ehci, "ignoring AMD8111 (errata)\n"); 160 ehci_info(ehci, "ignoring AMD8111 (errata)\n");
@@ -148,6 +171,18 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
148 if (pdev->revision < 0xa4) 171 if (pdev->revision < 0xa4)
149 ehci->no_selective_suspend = 1; 172 ehci->no_selective_suspend = 1;
150 break; 173 break;
174
175 /* MCP89 chips on the MacBookAir3,1 give EPROTO when
176 * fetching device descriptors unless LPM is disabled.
177 * There are also intermittent problems enumerating
178 * devices with PPCD enabled.
179 */
180 case 0x0d9d:
181 ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89");
182 ehci->has_lpm = 0;
183 ehci->has_ppcd = 0;
184 ehci->command &= ~CMD_PPCEE;
185 break;
151 } 186 }
152 break; 187 break;
153 case PCI_VENDOR_ID_VIA: 188 case PCI_VENDOR_ID_VIA:
@@ -165,6 +200,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
165 } 200 }
166 break; 201 break;
167 case PCI_VENDOR_ID_ATI: 202 case PCI_VENDOR_ID_ATI:
203 /* AMD PLL quirk */
204 if (usb_amd_find_chipset_info())
205 ehci->amd_pll_fix = 1;
168 /* SB600 and old version of SB700 have a bug in EHCI controller, 206 /* SB600 and old version of SB700 have a bug in EHCI controller,
169 * which causes usb devices lose response in some cases. 207 * which causes usb devices lose response in some cases.
170 */ 208 */
@@ -296,8 +334,8 @@ static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
296 * mark HW unaccessible. The PM and USB cores make sure that 334 * mark HW unaccessible. The PM and USB cores make sure that
297 * the root hub is either suspended or stopped. 335 * the root hub is either suspended or stopped.
298 */ 336 */
299 spin_lock_irqsave (&ehci->lock, flags);
300 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup); 337 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
338 spin_lock_irqsave (&ehci->lock, flags);
301 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 339 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
302 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 340 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
303 341
@@ -310,11 +348,50 @@ static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
310 return rc; 348 return rc;
311} 349}
312 350
351static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
352{
353 return pdev->class == PCI_CLASS_SERIAL_USB_EHCI &&
354 pdev->vendor == PCI_VENDOR_ID_INTEL &&
355 pdev->device == 0x1E26;
356}
357
358static void ehci_enable_xhci_companion(void)
359{
360 struct pci_dev *companion = NULL;
361
362 /* The xHCI and EHCI controllers are not on the same PCI slot */
363 for_each_pci_dev(companion) {
364 if (!usb_is_intel_switchable_xhci(companion))
365 continue;
366 usb_enable_xhci_ports(companion);
367 return;
368 }
369}
370
313static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated) 371static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
314{ 372{
315 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 373 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
316 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 374 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
317 375
376 /* The BIOS on systems with the Intel Panther Point chipset may or may
377 * not support xHCI natively. That means that during system resume, it
378 * may switch the ports back to EHCI so that users can use their
379 * keyboard to select a kernel from GRUB after resume from hibernate.
380 *
381 * The BIOS is supposed to remember whether the OS had xHCI ports
382 * enabled before resume, and switch the ports back to xHCI when the
383 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
384 * writers.
385 *
386 * Unconditionally switch the ports back to xHCI after a system resume.
387 * We can't tell whether the EHCI or xHCI controller will be resumed
388 * first, so we have to do the port switchover in both drivers. Writing
389 * a '1' to the port switchover registers should have no effect if the
390 * port was already switched over.
391 */
392 if (usb_is_intel_switchable_ehci(pdev))
393 ehci_enable_xhci_companion();
394
318 // maybe restore FLADJ 395 // maybe restore FLADJ
319 396
320 if (time_before(jiffies, ehci->next_statechange)) 397 if (time_before(jiffies, ehci->next_statechange))
diff --git a/drivers/usb/host/ehci-pmcmsp.c b/drivers/usb/host/ehci-pmcmsp.c
new file mode 100644
index 000000000000..cd69099cda19
--- /dev/null
+++ b/drivers/usb/host/ehci-pmcmsp.c
@@ -0,0 +1,383 @@
1/*
2 * PMC MSP EHCI (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 2006-2010 PMC-Sierra Inc
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 *
10 */
11
12/* includes */
13#include <linux/platform_device.h>
14#include <linux/gpio.h>
15#include <linux/usb.h>
16#include <msp_usb.h>
17
18/* stream disable*/
19#define USB_CTRL_MODE_STREAM_DISABLE 0x10
20
21/* threshold */
22#define USB_CTRL_FIFO_THRESH 0x00300000
23
24/* register offset for usb_mode */
25#define USB_EHCI_REG_USB_MODE 0x68
26
27/* register offset for usb fifo */
28#define USB_EHCI_REG_USB_FIFO 0x24
29
30/* register offset for usb status */
31#define USB_EHCI_REG_USB_STATUS 0x44
32
33/* serial/parallel transceiver */
34#define USB_EHCI_REG_BIT_STAT_STS (1<<29)
35
36/* TWI USB0 host device pin */
37#define MSP_PIN_USB0_HOST_DEV 49
38
39/* TWI USB1 host device pin */
40#define MSP_PIN_USB1_HOST_DEV 50
41
42
43static void usb_hcd_tdi_set_mode(struct ehci_hcd *ehci)
44{
45 u8 *base;
46 u8 *statreg;
47 u8 *fiforeg;
48 u32 val;
49 struct ehci_regs *reg_base = ehci->regs;
50
51 /* get register base */
52 base = (u8 *)reg_base + USB_EHCI_REG_USB_MODE;
53 statreg = (u8 *)reg_base + USB_EHCI_REG_USB_STATUS;
54 fiforeg = (u8 *)reg_base + USB_EHCI_REG_USB_FIFO;
55
56 /* Disable controller mode stream */
57 val = ehci_readl(ehci, (u32 *)base);
58 ehci_writel(ehci, (val | USB_CTRL_MODE_STREAM_DISABLE),
59 (u32 *)base);
60
61 /* clear STS to select parallel transceiver interface */
62 val = ehci_readl(ehci, (u32 *)statreg);
63 val = val & ~USB_EHCI_REG_BIT_STAT_STS;
64 ehci_writel(ehci, val, (u32 *)statreg);
65
66 /* write to set the proper fifo threshold */
67 ehci_writel(ehci, USB_CTRL_FIFO_THRESH, (u32 *)fiforeg);
68
69 /* set TWI GPIO USB_HOST_DEV pin high */
70 gpio_direction_output(MSP_PIN_USB0_HOST_DEV, 1);
71#ifdef CONFIG_MSP_HAS_DUAL_USB
72 gpio_direction_output(MSP_PIN_USB1_HOST_DEV, 1);
73#endif
74}
75
76/* called during probe() after chip reset completes */
77static int ehci_msp_setup(struct usb_hcd *hcd)
78{
79 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
80 int retval;
81 ehci->big_endian_mmio = 1;
82 ehci->big_endian_desc = 1;
83
84 ehci->caps = hcd->regs;
85 ehci->regs = hcd->regs +
86 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
87 dbg_hcs_params(ehci, "reset");
88 dbg_hcc_params(ehci, "reset");
89
90 /* cache this readonly data; minimize chip reads */
91 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
92 hcd->has_tt = 1;
93
94 retval = ehci_halt(ehci);
95 if (retval)
96 return retval;
97
98 ehci_reset(ehci);
99
100 /* data structure init */
101 retval = ehci_init(hcd);
102 if (retval)
103 return retval;
104
105 usb_hcd_tdi_set_mode(ehci);
106 ehci_port_power(ehci, 0);
107
108 return retval;
109}
110
111
112/* configure so an HC device and id are always provided
113 * always called with process context; sleeping is OK
114 */
115
116static int usb_hcd_msp_map_regs(struct mspusb_device *dev)
117{
118 struct resource *res;
119 struct platform_device *pdev = &dev->dev;
120 u32 res_len;
121 int retval;
122
123 /* MAB register space */
124 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
125 if (res == NULL)
126 return -ENOMEM;
127 res_len = res->end - res->start + 1;
128 if (!request_mem_region(res->start, res_len, "mab regs"))
129 return -EBUSY;
130
131 dev->mab_regs = ioremap_nocache(res->start, res_len);
132 if (dev->mab_regs == NULL) {
133 retval = -ENOMEM;
134 goto err1;
135 }
136
137 /* MSP USB register space */
138 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
139 if (res == NULL) {
140 retval = -ENOMEM;
141 goto err2;
142 }
143 res_len = res->end - res->start + 1;
144 if (!request_mem_region(res->start, res_len, "usbid regs")) {
145 retval = -EBUSY;
146 goto err2;
147 }
148 dev->usbid_regs = ioremap_nocache(res->start, res_len);
149 if (dev->usbid_regs == NULL) {
150 retval = -ENOMEM;
151 goto err3;
152 }
153
154 return 0;
155err3:
156 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
157 res_len = res->end - res->start + 1;
158 release_mem_region(res->start, res_len);
159err2:
160 iounmap(dev->mab_regs);
161err1:
162 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
163 res_len = res->end - res->start + 1;
164 release_mem_region(res->start, res_len);
165 dev_err(&pdev->dev, "Failed to map non-EHCI regs.\n");
166 return retval;
167}
168
169/**
170 * usb_hcd_msp_probe - initialize PMC MSP-based HCDs
171 * Context: !in_interrupt()
172 *
173 * Allocates basic resources for this USB host controller, and
174 * then invokes the start() method for the HCD associated with it
175 * through the hotplug entry's driver_data.
176 *
177 */
178int usb_hcd_msp_probe(const struct hc_driver *driver,
179 struct platform_device *dev)
180{
181 int retval;
182 struct usb_hcd *hcd;
183 struct resource *res;
184 struct ehci_hcd *ehci ;
185
186 hcd = usb_create_hcd(driver, &dev->dev, "pmcmsp");
187 if (!hcd)
188 return -ENOMEM;
189
190 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
191 if (res == NULL) {
192 pr_debug("No IOMEM resource info for %s.\n", dev->name);
193 retval = -ENOMEM;
194 goto err1;
195 }
196 hcd->rsrc_start = res->start;
197 hcd->rsrc_len = res->end - res->start + 1;
198 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, dev->name)) {
199 retval = -EBUSY;
200 goto err1;
201 }
202 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
203 if (!hcd->regs) {
204 pr_debug("ioremap failed");
205 retval = -ENOMEM;
206 goto err2;
207 }
208
209 res = platform_get_resource(dev, IORESOURCE_IRQ, 0);
210 if (res == NULL) {
211 dev_err(&dev->dev, "No IRQ resource info for %s.\n", dev->name);
212 retval = -ENOMEM;
213 goto err3;
214 }
215
216 /* Map non-EHCI register spaces */
217 retval = usb_hcd_msp_map_regs(to_mspusb_device(dev));
218 if (retval != 0)
219 goto err3;
220
221 ehci = hcd_to_ehci(hcd);
222 ehci->big_endian_mmio = 1;
223 ehci->big_endian_desc = 1;
224
225
226 retval = usb_add_hcd(hcd, res->start, IRQF_SHARED);
227 if (retval == 0)
228 return 0;
229
230 usb_remove_hcd(hcd);
231err3:
232 iounmap(hcd->regs);
233err2:
234 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
235err1:
236 usb_put_hcd(hcd);
237
238 return retval;
239}
240
241
242
243/**
244 * usb_hcd_msp_remove - shutdown processing for PMC MSP-based HCDs
245 * @dev: USB Host Controller being removed
246 * Context: !in_interrupt()
247 *
248 * Reverses the effect of usb_hcd_msp_probe(), first invoking
249 * the HCD's stop() method. It is always called from a thread
250 * context, normally "rmmod", "apmd", or something similar.
251 *
252 * may be called without controller electrically present
253 * may be called with controller, bus, and devices active
254 */
255void usb_hcd_msp_remove(struct usb_hcd *hcd, struct platform_device *dev)
256{
257 usb_remove_hcd(hcd);
258 iounmap(hcd->regs);
259 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
260 usb_put_hcd(hcd);
261}
262
263#ifdef CONFIG_MSP_HAS_DUAL_USB
264/*
265 * Wrapper around the main ehci_irq. Since both USB host controllers are
266 * sharing the same IRQ, need to first determine whether we're the intended
267 * recipient of this interrupt.
268 */
269static irqreturn_t ehci_msp_irq(struct usb_hcd *hcd)
270{
271 u32 int_src;
272 struct device *dev = hcd->self.controller;
273 struct platform_device *pdev;
274 struct mspusb_device *mdev;
275 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
276 /* need to reverse-map a couple of containers to get our device */
277 pdev = to_platform_device(dev);
278 mdev = to_mspusb_device(pdev);
279
280 /* Check to see if this interrupt is for this host controller */
281 int_src = ehci_readl(ehci, &mdev->mab_regs->int_stat);
282 if (int_src & (1 << pdev->id))
283 return ehci_irq(hcd);
284
285 /* Not for this device */
286 return IRQ_NONE;
287}
288#endif /* DUAL_USB */
289
290static const struct hc_driver ehci_msp_hc_driver = {
291 .description = hcd_name,
292 .product_desc = "PMC MSP EHCI",
293 .hcd_priv_size = sizeof(struct ehci_hcd),
294
295 /*
296 * generic hardware linkage
297 */
298#ifdef CONFIG_MSP_HAS_DUAL_USB
299 .irq = ehci_msp_irq,
300#else
301 .irq = ehci_irq,
302#endif
303 .flags = HCD_MEMORY | HCD_USB2,
304
305 /*
306 * basic lifecycle operations
307 */
308 .reset = ehci_msp_setup,
309 .start = ehci_run,
310 .shutdown = ehci_shutdown,
311 .start = ehci_run,
312 .stop = ehci_stop,
313
314 /*
315 * managing i/o requests and associated device resources
316 */
317 .urb_enqueue = ehci_urb_enqueue,
318 .urb_dequeue = ehci_urb_dequeue,
319 .endpoint_disable = ehci_endpoint_disable,
320 .endpoint_reset = ehci_endpoint_reset,
321
322 /*
323 * scheduling support
324 */
325 .get_frame_number = ehci_get_frame,
326
327 /*
328 * root hub support
329 */
330 .hub_status_data = ehci_hub_status_data,
331 .hub_control = ehci_hub_control,
332 .bus_suspend = ehci_bus_suspend,
333 .bus_resume = ehci_bus_resume,
334 .relinquish_port = ehci_relinquish_port,
335 .port_handed_over = ehci_port_handed_over,
336
337 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
338};
339
340static int ehci_hcd_msp_drv_probe(struct platform_device *pdev)
341{
342 int ret;
343
344 pr_debug("In ehci_hcd_msp_drv_probe");
345
346 if (usb_disabled())
347 return -ENODEV;
348
349 gpio_request(MSP_PIN_USB0_HOST_DEV, "USB0_HOST_DEV_GPIO");
350#ifdef CONFIG_MSP_HAS_DUAL_USB
351 gpio_request(MSP_PIN_USB1_HOST_DEV, "USB1_HOST_DEV_GPIO");
352#endif
353
354 ret = usb_hcd_msp_probe(&ehci_msp_hc_driver, pdev);
355
356 return ret;
357}
358
359static int ehci_hcd_msp_drv_remove(struct platform_device *pdev)
360{
361 struct usb_hcd *hcd = platform_get_drvdata(pdev);
362
363 usb_hcd_msp_remove(hcd, pdev);
364
365 /* free TWI GPIO USB_HOST_DEV pin */
366 gpio_free(MSP_PIN_USB0_HOST_DEV);
367#ifdef CONFIG_MSP_HAS_DUAL_USB
368 gpio_free(MSP_PIN_USB1_HOST_DEV);
369#endif
370
371 return 0;
372}
373
374MODULE_ALIAS("pmcmsp-ehci");
375
376static struct platform_driver ehci_hcd_msp_driver = {
377 .probe = ehci_hcd_msp_drv_probe,
378 .remove = ehci_hcd_msp_drv_remove,
379 .driver = {
380 .name = "pmcmsp-ehci",
381 .owner = THIS_MODULE,
382 },
383};
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index ba52be473027..8552db6c29c9 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -105,8 +105,7 @@ ppc44x_enable_bmt(struct device_node *dn)
105} 105}
106 106
107 107
108static int __devinit 108static int __devinit ehci_hcd_ppc_of_probe(struct platform_device *op)
109ehci_hcd_ppc_of_probe(struct platform_device *op, const struct of_device_id *match)
110{ 109{
111 struct device_node *dn = op->dev.of_node; 110 struct device_node *dn = op->dev.of_node;
112 struct usb_hcd *hcd; 111 struct usb_hcd *hcd;
@@ -180,7 +179,7 @@ ehci_hcd_ppc_of_probe(struct platform_device *op, const struct of_device_id *mat
180 179
181 ehci->caps = hcd->regs; 180 ehci->caps = hcd->regs;
182 ehci->regs = hcd->regs + 181 ehci->regs = hcd->regs +
183 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 182 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
184 183
185 /* cache this readonly data; minimize chip reads */ 184 /* cache this readonly data; minimize chip reads */
186 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 185 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
@@ -255,14 +254,12 @@ static int ehci_hcd_ppc_of_remove(struct platform_device *op)
255} 254}
256 255
257 256
258static int ehci_hcd_ppc_of_shutdown(struct platform_device *op) 257static void ehci_hcd_ppc_of_shutdown(struct platform_device *op)
259{ 258{
260 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 259 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
261 260
262 if (hcd->driver->shutdown) 261 if (hcd->driver->shutdown)
263 hcd->driver->shutdown(hcd); 262 hcd->driver->shutdown(hcd);
264
265 return 0;
266} 263}
267 264
268 265
@@ -275,7 +272,7 @@ static const struct of_device_id ehci_hcd_ppc_of_match[] = {
275MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match); 272MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match);
276 273
277 274
278static struct of_platform_driver ehci_hcd_ppc_of_driver = { 275static struct platform_driver ehci_hcd_ppc_of_driver = {
279 .probe = ehci_hcd_ppc_of_probe, 276 .probe = ehci_hcd_ppc_of_probe,
280 .remove = ehci_hcd_ppc_of_remove, 277 .remove = ehci_hcd_ppc_of_remove,
281 .shutdown = ehci_hcd_ppc_of_shutdown, 278 .shutdown = ehci_hcd_ppc_of_shutdown,
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index 1dee33b9139e..64626a777d61 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -29,7 +29,7 @@ static int ps3_ehci_hc_reset(struct usb_hcd *hcd)
29 ehci->big_endian_mmio = 1; 29 ehci->big_endian_mmio = 1;
30 30
31 ehci->caps = hcd->regs; 31 ehci->caps = hcd->regs;
32 ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci, 32 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
33 &ehci->caps->hc_capbase)); 33 &ehci->caps->hc_capbase));
34 34
35 dbg_hcs_params(ehci, "reset"); 35 dbg_hcs_params(ehci, "reset");
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 233c288e3f93..5d6bc624c961 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -315,7 +315,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
315 int stopped; 315 int stopped;
316 unsigned count = 0; 316 unsigned count = 0;
317 u8 state; 317 u8 state;
318 const __le32 halt = HALT_BIT(ehci);
319 struct ehci_qh_hw *hw = qh->hw; 318 struct ehci_qh_hw *hw = qh->hw;
320 319
321 if (unlikely (list_empty (&qh->qtd_list))) 320 if (unlikely (list_empty (&qh->qtd_list)))
@@ -422,7 +421,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
422 && !(qtd->hw_alt_next 421 && !(qtd->hw_alt_next
423 & EHCI_LIST_END(ehci))) { 422 & EHCI_LIST_END(ehci))) {
424 stopped = 1; 423 stopped = 1;
425 goto halt;
426 } 424 }
427 425
428 /* stop scanning when we reach qtds the hc is using */ 426 /* stop scanning when we reach qtds the hc is using */
@@ -456,16 +454,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
456 */ 454 */
457 ehci_clear_tt_buffer(ehci, qh, urb, token); 455 ehci_clear_tt_buffer(ehci, qh, urb, token);
458 } 456 }
459
460 /* force halt for unlinked or blocked qh, so we'll
461 * patch the qh later and so that completions can't
462 * activate it while we "know" it's stopped.
463 */
464 if ((halt & hw->hw_token) == 0) {
465halt:
466 hw->hw_token |= halt;
467 wmb ();
468 }
469 } 457 }
470 458
471 /* unless we already know the urb's status, collect qtd status 459 /* unless we already know the urb's status, collect qtd status
@@ -838,6 +826,7 @@ qh_make (
838 is_input, 0, 826 is_input, 0,
839 hb_mult(maxp) * max_packet(maxp))); 827 hb_mult(maxp) * max_packet(maxp)));
840 qh->start = NO_FRAME; 828 qh->start = NO_FRAME;
829 qh->stamp = ehci->periodic_stamp;
841 830
842 if (urb->dev->speed == USB_SPEED_HIGH) { 831 if (urb->dev->speed == USB_SPEED_HIGH) {
843 qh->c_usecs = 0; 832 qh->c_usecs = 0;
@@ -1107,22 +1096,24 @@ submit_async (
1107 struct list_head *qtd_list, 1096 struct list_head *qtd_list,
1108 gfp_t mem_flags 1097 gfp_t mem_flags
1109) { 1098) {
1110 struct ehci_qtd *qtd;
1111 int epnum; 1099 int epnum;
1112 unsigned long flags; 1100 unsigned long flags;
1113 struct ehci_qh *qh = NULL; 1101 struct ehci_qh *qh = NULL;
1114 int rc; 1102 int rc;
1115 1103
1116 qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);
1117 epnum = urb->ep->desc.bEndpointAddress; 1104 epnum = urb->ep->desc.bEndpointAddress;
1118 1105
1119#ifdef EHCI_URB_TRACE 1106#ifdef EHCI_URB_TRACE
1120 ehci_dbg (ehci, 1107 {
1121 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n", 1108 struct ehci_qtd *qtd;
1122 __func__, urb->dev->devpath, urb, 1109 qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list);
1123 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", 1110 ehci_dbg(ehci,
1124 urb->transfer_buffer_length, 1111 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
1125 qtd, urb->ep->hcpriv); 1112 __func__, urb->dev->devpath, urb,
1113 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out",
1114 urb->transfer_buffer_length,
1115 qtd, urb->ep->hcpriv);
1116 }
1126#endif 1117#endif
1127 1118
1128 spin_lock_irqsave (&ehci->lock, flags); 1119 spin_lock_irqsave (&ehci->lock, flags);
@@ -1193,6 +1184,10 @@ static void end_unlink_async (struct ehci_hcd *ehci)
1193 ehci->reclaim = NULL; 1184 ehci->reclaim = NULL;
1194 start_unlink_async (ehci, next); 1185 start_unlink_async (ehci, next);
1195 } 1186 }
1187
1188 if (ehci->has_synopsys_hc_bug)
1189 ehci_writel(ehci, (u32) ehci->async->qh_dma,
1190 &ehci->regs->async_next);
1196} 1191}
1197 1192
1198/* makes sure the async qh will become idle */ 1193/* makes sure the async qh will become idle */
@@ -1257,24 +1252,27 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1257 1252
1258static void scan_async (struct ehci_hcd *ehci) 1253static void scan_async (struct ehci_hcd *ehci)
1259{ 1254{
1255 bool stopped;
1260 struct ehci_qh *qh; 1256 struct ehci_qh *qh;
1261 enum ehci_timer_action action = TIMER_IO_WATCHDOG; 1257 enum ehci_timer_action action = TIMER_IO_WATCHDOG;
1262 1258
1263 ehci->stamp = ehci_readl(ehci, &ehci->regs->frame_index); 1259 ehci->stamp = ehci_readl(ehci, &ehci->regs->frame_index);
1264 timer_action_done (ehci, TIMER_ASYNC_SHRINK); 1260 timer_action_done (ehci, TIMER_ASYNC_SHRINK);
1265rescan: 1261rescan:
1262 stopped = !HC_IS_RUNNING(ehci_to_hcd(ehci)->state);
1266 qh = ehci->async->qh_next.qh; 1263 qh = ehci->async->qh_next.qh;
1267 if (likely (qh != NULL)) { 1264 if (likely (qh != NULL)) {
1268 do { 1265 do {
1269 /* clean any finished work for this qh */ 1266 /* clean any finished work for this qh */
1270 if (!list_empty (&qh->qtd_list) 1267 if (!list_empty(&qh->qtd_list) && (stopped ||
1271 && qh->stamp != ehci->stamp) { 1268 qh->stamp != ehci->stamp)) {
1272 int temp; 1269 int temp;
1273 1270
1274 /* unlinks could happen here; completion 1271 /* unlinks could happen here; completion
1275 * reporting drops the lock. rescan using 1272 * reporting drops the lock. rescan using
1276 * the latest schedule, but don't rescan 1273 * the latest schedule, but don't rescan
1277 * qhs we already finished (no looping). 1274 * qhs we already finished (no looping)
1275 * unless the controller is stopped.
1278 */ 1276 */
1279 qh = qh_get (qh); 1277 qh = qh_get (qh);
1280 qh->stamp = ehci->stamp; 1278 qh->stamp = ehci->stamp;
@@ -1295,9 +1293,9 @@ rescan:
1295 */ 1293 */
1296 if (list_empty(&qh->qtd_list) 1294 if (list_empty(&qh->qtd_list)
1297 && qh->qh_state == QH_STATE_LINKED) { 1295 && qh->qh_state == QH_STATE_LINKED) {
1298 if (!ehci->reclaim 1296 if (!ehci->reclaim && (stopped ||
1299 && ((ehci->stamp - qh->stamp) & 0x1fff) 1297 ((ehci->stamp - qh->stamp) & 0x1fff)
1300 >= (EHCI_SHRINK_FRAMES * 8)) 1298 >= EHCI_SHRINK_FRAMES * 8))
1301 start_unlink_async(ehci, qh); 1299 start_unlink_async(ehci, qh);
1302 else 1300 else
1303 action = TIMER_ASYNC_SHRINK; 1301 action = TIMER_ASYNC_SHRINK;
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c
new file mode 100644
index 000000000000..e3374c8f7b3f
--- /dev/null
+++ b/drivers/usb/host/ehci-s5p.c
@@ -0,0 +1,202 @@
1/*
2 * SAMSUNG S5P USB HOST EHCI Controller
3 *
4 * Copyright (C) 2011 Samsung Electronics Co.Ltd
5 * Author: Jingoo Han <jg1.han@samsung.com>
6 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
14
15#include <linux/clk.h>
16#include <linux/platform_device.h>
17#include <mach/regs-pmu.h>
18#include <plat/cpu.h>
19#include <plat/ehci.h>
20#include <plat/usb-phy.h>
21
22struct s5p_ehci_hcd {
23 struct device *dev;
24 struct usb_hcd *hcd;
25 struct clk *clk;
26};
27
28static const struct hc_driver s5p_ehci_hc_driver = {
29 .description = hcd_name,
30 .product_desc = "S5P EHCI Host Controller",
31 .hcd_priv_size = sizeof(struct ehci_hcd),
32
33 .irq = ehci_irq,
34 .flags = HCD_MEMORY | HCD_USB2,
35
36 .reset = ehci_init,
37 .start = ehci_run,
38 .stop = ehci_stop,
39 .shutdown = ehci_shutdown,
40
41 .get_frame_number = ehci_get_frame,
42
43 .urb_enqueue = ehci_urb_enqueue,
44 .urb_dequeue = ehci_urb_dequeue,
45 .endpoint_disable = ehci_endpoint_disable,
46 .endpoint_reset = ehci_endpoint_reset,
47
48 .hub_status_data = ehci_hub_status_data,
49 .hub_control = ehci_hub_control,
50 .bus_suspend = ehci_bus_suspend,
51 .bus_resume = ehci_bus_resume,
52
53 .relinquish_port = ehci_relinquish_port,
54 .port_handed_over = ehci_port_handed_over,
55
56 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
57};
58
59static int __devinit s5p_ehci_probe(struct platform_device *pdev)
60{
61 struct s5p_ehci_platdata *pdata;
62 struct s5p_ehci_hcd *s5p_ehci;
63 struct usb_hcd *hcd;
64 struct ehci_hcd *ehci;
65 struct resource *res;
66 int irq;
67 int err;
68
69 pdata = pdev->dev.platform_data;
70 if (!pdata) {
71 dev_err(&pdev->dev, "No platform data defined\n");
72 return -EINVAL;
73 }
74
75 s5p_ehci = kzalloc(sizeof(struct s5p_ehci_hcd), GFP_KERNEL);
76 if (!s5p_ehci)
77 return -ENOMEM;
78
79 s5p_ehci->dev = &pdev->dev;
80
81 hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev,
82 dev_name(&pdev->dev));
83 if (!hcd) {
84 dev_err(&pdev->dev, "Unable to create HCD\n");
85 err = -ENOMEM;
86 goto fail_hcd;
87 }
88
89 s5p_ehci->clk = clk_get(&pdev->dev, "usbhost");
90
91 if (IS_ERR(s5p_ehci->clk)) {
92 dev_err(&pdev->dev, "Failed to get usbhost clock\n");
93 err = PTR_ERR(s5p_ehci->clk);
94 goto fail_clk;
95 }
96
97 err = clk_enable(s5p_ehci->clk);
98 if (err)
99 goto fail_clken;
100
101 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
102 if (!res) {
103 dev_err(&pdev->dev, "Failed to get I/O memory\n");
104 err = -ENXIO;
105 goto fail_io;
106 }
107
108 hcd->rsrc_start = res->start;
109 hcd->rsrc_len = resource_size(res);
110 hcd->regs = ioremap(res->start, resource_size(res));
111 if (!hcd->regs) {
112 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
113 err = -ENOMEM;
114 goto fail_io;
115 }
116
117 irq = platform_get_irq(pdev, 0);
118 if (!irq) {
119 dev_err(&pdev->dev, "Failed to get IRQ\n");
120 err = -ENODEV;
121 goto fail;
122 }
123
124 if (pdata->phy_init)
125 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
126
127 ehci = hcd_to_ehci(hcd);
128 ehci->caps = hcd->regs;
129 ehci->regs = hcd->regs +
130 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
131
132 dbg_hcs_params(ehci, "reset");
133 dbg_hcc_params(ehci, "reset");
134
135 /* cache this readonly data; minimize chip reads */
136 ehci->hcs_params = readl(&ehci->caps->hcs_params);
137
138 err = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
139 if (err) {
140 dev_err(&pdev->dev, "Failed to add USB HCD\n");
141 goto fail;
142 }
143
144 platform_set_drvdata(pdev, s5p_ehci);
145
146 return 0;
147
148fail:
149 iounmap(hcd->regs);
150fail_io:
151 clk_disable(s5p_ehci->clk);
152fail_clken:
153 clk_put(s5p_ehci->clk);
154fail_clk:
155 usb_put_hcd(hcd);
156fail_hcd:
157 kfree(s5p_ehci);
158 return err;
159}
160
161static int __devexit s5p_ehci_remove(struct platform_device *pdev)
162{
163 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
164 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
165 struct usb_hcd *hcd = s5p_ehci->hcd;
166
167 usb_remove_hcd(hcd);
168
169 if (pdata && pdata->phy_exit)
170 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
171
172 iounmap(hcd->regs);
173
174 clk_disable(s5p_ehci->clk);
175 clk_put(s5p_ehci->clk);
176
177 usb_put_hcd(hcd);
178 kfree(s5p_ehci);
179
180 return 0;
181}
182
183static void s5p_ehci_shutdown(struct platform_device *pdev)
184{
185 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
186 struct usb_hcd *hcd = s5p_ehci->hcd;
187
188 if (hcd->driver->shutdown)
189 hcd->driver->shutdown(hcd);
190}
191
192static struct platform_driver s5p_ehci_driver = {
193 .probe = s5p_ehci_probe,
194 .remove = __devexit_p(s5p_ehci_remove),
195 .shutdown = s5p_ehci_shutdown,
196 .driver = {
197 .name = "s5p-ehci",
198 .owner = THIS_MODULE,
199 }
200};
201
202MODULE_ALIAS("platform:s5p-ehci");
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index a92526d6e5ae..6c9fbe352f73 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -98,7 +98,14 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr)
98 */ 98 */
99 *prev_p = *periodic_next_shadow(ehci, &here, 99 *prev_p = *periodic_next_shadow(ehci, &here,
100 Q_NEXT_TYPE(ehci, *hw_p)); 100 Q_NEXT_TYPE(ehci, *hw_p));
101 *hw_p = *shadow_next_periodic(ehci, &here, Q_NEXT_TYPE(ehci, *hw_p)); 101
102 if (!ehci->use_dummy_qh ||
103 *shadow_next_periodic(ehci, &here, Q_NEXT_TYPE(ehci, *hw_p))
104 != EHCI_LIST_END(ehci))
105 *hw_p = *shadow_next_periodic(ehci, &here,
106 Q_NEXT_TYPE(ehci, *hw_p));
107 else
108 *hw_p = ehci->dummy->qh_dma;
102} 109}
103 110
104/* how many of the uframe's 125 usecs are allocated? */ 111/* how many of the uframe's 125 usecs are allocated? */
@@ -464,8 +471,10 @@ static int enable_periodic (struct ehci_hcd *ehci)
464 */ 471 */
465 status = handshake_on_error_set_halt(ehci, &ehci->regs->status, 472 status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
466 STS_PSS, 0, 9 * 125); 473 STS_PSS, 0, 9 * 125);
467 if (status) 474 if (status) {
475 usb_hc_died(ehci_to_hcd(ehci));
468 return status; 476 return status;
477 }
469 478
470 cmd = ehci_readl(ehci, &ehci->regs->command) | CMD_PSE; 479 cmd = ehci_readl(ehci, &ehci->regs->command) | CMD_PSE;
471 ehci_writel(ehci, cmd, &ehci->regs->command); 480 ehci_writel(ehci, cmd, &ehci->regs->command);
@@ -503,8 +512,10 @@ static int disable_periodic (struct ehci_hcd *ehci)
503 */ 512 */
504 status = handshake_on_error_set_halt(ehci, &ehci->regs->status, 513 status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
505 STS_PSS, STS_PSS, 9 * 125); 514 STS_PSS, STS_PSS, 9 * 125);
506 if (status) 515 if (status) {
516 usb_hc_died(ehci_to_hcd(ehci));
507 return status; 517 return status;
518 }
508 519
509 cmd = ehci_readl(ehci, &ehci->regs->command) & ~CMD_PSE; 520 cmd = ehci_readl(ehci, &ehci->regs->command) & ~CMD_PSE;
510 ehci_writel(ehci, cmd, &ehci->regs->command); 521 ehci_writel(ehci, cmd, &ehci->regs->command);
@@ -1041,8 +1052,6 @@ iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream)
1041 * not like a QH -- no persistent state (toggle, halt) 1052 * not like a QH -- no persistent state (toggle, halt)
1042 */ 1053 */
1043 if (stream->refcount == 1) { 1054 if (stream->refcount == 1) {
1044 int is_in;
1045
1046 // BUG_ON (!list_empty(&stream->td_list)); 1055 // BUG_ON (!list_empty(&stream->td_list));
1047 1056
1048 while (!list_empty (&stream->free_list)) { 1057 while (!list_empty (&stream->free_list)) {
@@ -1069,7 +1078,6 @@ iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream)
1069 } 1078 }
1070 } 1079 }
1071 1080
1072 is_in = (stream->bEndpointAddress & USB_DIR_IN) ? 0x10 : 0;
1073 stream->bEndpointAddress &= 0x0f; 1081 stream->bEndpointAddress &= 0x0f;
1074 if (stream->ep) 1082 if (stream->ep)
1075 stream->ep->hcpriv = NULL; 1083 stream->ep->hcpriv = NULL;
@@ -1609,6 +1617,12 @@ itd_link_urb (
1609 urb->interval, 1617 urb->interval,
1610 next_uframe >> 3, next_uframe & 0x7); 1618 next_uframe >> 3, next_uframe & 0x7);
1611 } 1619 }
1620
1621 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
1622 if (ehci->amd_pll_fix == 1)
1623 usb_amd_quirk_pll_disable();
1624 }
1625
1612 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 1626 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
1613 1627
1614 /* fill iTDs uframe by uframe */ 1628 /* fill iTDs uframe by uframe */
@@ -1733,6 +1747,11 @@ itd_complete (
1733 (void) disable_periodic(ehci); 1747 (void) disable_periodic(ehci);
1734 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; 1748 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
1735 1749
1750 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
1751 if (ehci->amd_pll_fix == 1)
1752 usb_amd_quirk_pll_enable();
1753 }
1754
1736 if (unlikely(list_is_singular(&stream->td_list))) { 1755 if (unlikely(list_is_singular(&stream->td_list))) {
1737 ehci_to_hcd(ehci)->self.bandwidth_allocated 1756 ehci_to_hcd(ehci)->self.bandwidth_allocated
1738 -= stream->bandwidth; 1757 -= stream->bandwidth;
@@ -2018,6 +2037,12 @@ sitd_link_urb (
2018 (next_uframe >> 3) & (ehci->periodic_size - 1), 2037 (next_uframe >> 3) & (ehci->periodic_size - 1),
2019 stream->interval, hc32_to_cpu(ehci, stream->splits)); 2038 stream->interval, hc32_to_cpu(ehci, stream->splits));
2020 } 2039 }
2040
2041 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
2042 if (ehci->amd_pll_fix == 1)
2043 usb_amd_quirk_pll_disable();
2044 }
2045
2021 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 2046 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
2022 2047
2023 /* fill sITDs frame by frame */ 2048 /* fill sITDs frame by frame */
@@ -2118,6 +2143,11 @@ sitd_complete (
2118 (void) disable_periodic(ehci); 2143 (void) disable_periodic(ehci);
2119 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; 2144 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
2120 2145
2146 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
2147 if (ehci->amd_pll_fix == 1)
2148 usb_amd_quirk_pll_enable();
2149 }
2150
2121 if (list_is_singular(&stream->td_list)) { 2151 if (list_is_singular(&stream->td_list)) {
2122 ehci_to_hcd(ehci)->self.bandwidth_allocated 2152 ehci_to_hcd(ehci)->self.bandwidth_allocated
2123 -= stream->bandwidth; 2153 -= stream->bandwidth;
@@ -2261,6 +2291,7 @@ scan_periodic (struct ehci_hcd *ehci)
2261 } 2291 }
2262 clock &= mod - 1; 2292 clock &= mod - 1;
2263 clock_frame = clock >> 3; 2293 clock_frame = clock >> 3;
2294 ++ehci->periodic_stamp;
2264 2295
2265 for (;;) { 2296 for (;;) {
2266 union ehci_shadow q, *q_p; 2297 union ehci_shadow q, *q_p;
@@ -2289,10 +2320,14 @@ restart:
2289 temp.qh = qh_get (q.qh); 2320 temp.qh = qh_get (q.qh);
2290 type = Q_NEXT_TYPE(ehci, q.qh->hw->hw_next); 2321 type = Q_NEXT_TYPE(ehci, q.qh->hw->hw_next);
2291 q = q.qh->qh_next; 2322 q = q.qh->qh_next;
2292 modified = qh_completions (ehci, temp.qh); 2323 if (temp.qh->stamp != ehci->periodic_stamp) {
2293 if (unlikely(list_empty(&temp.qh->qtd_list) || 2324 modified = qh_completions(ehci, temp.qh);
2294 temp.qh->needs_rescan)) 2325 if (!modified)
2295 intr_deschedule (ehci, temp.qh); 2326 temp.qh->stamp = ehci->periodic_stamp;
2327 if (unlikely(list_empty(&temp.qh->qtd_list) ||
2328 temp.qh->needs_rescan))
2329 intr_deschedule(ehci, temp.qh);
2330 }
2296 qh_put (temp.qh); 2331 qh_put (temp.qh);
2297 break; 2332 break;
2298 case Q_TYPE_FSTN: 2333 case Q_TYPE_FSTN:
@@ -2335,7 +2370,11 @@ restart:
2335 * pointer for much longer, if at all. 2370 * pointer for much longer, if at all.
2336 */ 2371 */
2337 *q_p = q.itd->itd_next; 2372 *q_p = q.itd->itd_next;
2338 *hw_p = q.itd->hw_next; 2373 if (!ehci->use_dummy_qh ||
2374 q.itd->hw_next != EHCI_LIST_END(ehci))
2375 *hw_p = q.itd->hw_next;
2376 else
2377 *hw_p = ehci->dummy->qh_dma;
2339 type = Q_NEXT_TYPE(ehci, q.itd->hw_next); 2378 type = Q_NEXT_TYPE(ehci, q.itd->hw_next);
2340 wmb(); 2379 wmb();
2341 modified = itd_complete (ehci, q.itd); 2380 modified = itd_complete (ehci, q.itd);
@@ -2368,7 +2407,11 @@ restart:
2368 * URB completion. 2407 * URB completion.
2369 */ 2408 */
2370 *q_p = q.sitd->sitd_next; 2409 *q_p = q.sitd->sitd_next;
2371 *hw_p = q.sitd->hw_next; 2410 if (!ehci->use_dummy_qh ||
2411 q.sitd->hw_next != EHCI_LIST_END(ehci))
2412 *hw_p = q.sitd->hw_next;
2413 else
2414 *hw_p = ehci->dummy->qh_dma;
2372 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); 2415 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
2373 wmb(); 2416 wmb();
2374 modified = sitd_complete (ehci, q.sitd); 2417 modified = sitd_complete (ehci, q.sitd);
@@ -2426,6 +2469,7 @@ restart:
2426 if (ehci->clock_frame != clock_frame) { 2469 if (ehci->clock_frame != clock_frame) {
2427 free_cached_lists(ehci); 2470 free_cached_lists(ehci);
2428 ehci->clock_frame = clock_frame; 2471 ehci->clock_frame = clock_frame;
2472 ++ehci->periodic_stamp;
2429 } 2473 }
2430 } else { 2474 } else {
2431 now_uframe++; 2475 now_uframe++;
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
new file mode 100644
index 000000000000..86a95bb80a61
--- /dev/null
+++ b/drivers/usb/host/ehci-sh.c
@@ -0,0 +1,243 @@
1/*
2 * SuperH EHCI host controller driver
3 *
4 * Copyright (C) 2010 Paul Mundt
5 *
6 * Based on ohci-sh.c and ehci-atmel.c.
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/platform_device.h>
13#include <linux/clk.h>
14
15struct ehci_sh_priv {
16 struct clk *iclk, *fclk;
17 struct usb_hcd *hcd;
18};
19
20static int ehci_sh_reset(struct usb_hcd *hcd)
21{
22 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
23 int ret;
24
25 ehci->caps = hcd->regs;
26 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
27 &ehci->caps->hc_capbase));
28
29 dbg_hcs_params(ehci, "reset");
30 dbg_hcc_params(ehci, "reset");
31
32 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
33
34 ret = ehci_halt(ehci);
35 if (unlikely(ret))
36 return ret;
37
38 ret = ehci_init(hcd);
39 if (unlikely(ret))
40 return ret;
41
42 ehci->sbrn = 0x20;
43
44 ehci_reset(ehci);
45 ehci_port_power(ehci, 0);
46
47 return ret;
48}
49
50static const struct hc_driver ehci_sh_hc_driver = {
51 .description = hcd_name,
52 .product_desc = "SuperH EHCI",
53 .hcd_priv_size = sizeof(struct ehci_hcd),
54
55 /*
56 * generic hardware linkage
57 */
58 .irq = ehci_irq,
59 .flags = HCD_USB2 | HCD_MEMORY,
60
61 /*
62 * basic lifecycle operations
63 */
64 .reset = ehci_sh_reset,
65 .start = ehci_run,
66 .stop = ehci_stop,
67 .shutdown = ehci_shutdown,
68
69 /*
70 * managing i/o requests and associated device resources
71 */
72 .urb_enqueue = ehci_urb_enqueue,
73 .urb_dequeue = ehci_urb_dequeue,
74 .endpoint_disable = ehci_endpoint_disable,
75 .endpoint_reset = ehci_endpoint_reset,
76
77 /*
78 * scheduling support
79 */
80 .get_frame_number = ehci_get_frame,
81
82 /*
83 * root hub support
84 */
85 .hub_status_data = ehci_hub_status_data,
86 .hub_control = ehci_hub_control,
87
88#ifdef CONFIG_PM
89 .bus_suspend = ehci_bus_suspend,
90 .bus_resume = ehci_bus_resume,
91#endif
92
93 .relinquish_port = ehci_relinquish_port,
94 .port_handed_over = ehci_port_handed_over,
95 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
96};
97
98static int ehci_hcd_sh_probe(struct platform_device *pdev)
99{
100 const struct hc_driver *driver = &ehci_sh_hc_driver;
101 struct resource *res;
102 struct ehci_sh_priv *priv;
103 struct usb_hcd *hcd;
104 int irq, ret;
105
106 if (usb_disabled())
107 return -ENODEV;
108
109 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
110 if (!res) {
111 dev_err(&pdev->dev,
112 "Found HC with no register addr. Check %s setup!\n",
113 dev_name(&pdev->dev));
114 ret = -ENODEV;
115 goto fail_create_hcd;
116 }
117
118 irq = platform_get_irq(pdev, 0);
119 if (irq <= 0) {
120 dev_err(&pdev->dev,
121 "Found HC with no IRQ. Check %s setup!\n",
122 dev_name(&pdev->dev));
123 ret = -ENODEV;
124 goto fail_create_hcd;
125 }
126
127 /* initialize hcd */
128 hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
129 dev_name(&pdev->dev));
130 if (!hcd) {
131 ret = -ENOMEM;
132 goto fail_create_hcd;
133 }
134
135 hcd->rsrc_start = res->start;
136 hcd->rsrc_len = resource_size(res);
137
138 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
139 driver->description)) {
140 dev_dbg(&pdev->dev, "controller already in use\n");
141 ret = -EBUSY;
142 goto fail_request_resource;
143 }
144
145 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
146 if (hcd->regs == NULL) {
147 dev_dbg(&pdev->dev, "error mapping memory\n");
148 ret = -ENXIO;
149 goto fail_ioremap;
150 }
151
152 priv = kmalloc(sizeof(struct ehci_sh_priv), GFP_KERNEL);
153 if (!priv) {
154 dev_dbg(&pdev->dev, "error allocating priv data\n");
155 ret = -ENOMEM;
156 goto fail_alloc;
157 }
158
159 /* These are optional, we don't care if they fail */
160 priv->fclk = clk_get(&pdev->dev, "usb_fck");
161 if (IS_ERR(priv->fclk))
162 priv->fclk = NULL;
163
164 priv->iclk = clk_get(&pdev->dev, "usb_ick");
165 if (IS_ERR(priv->iclk))
166 priv->iclk = NULL;
167
168 clk_enable(priv->fclk);
169 clk_enable(priv->iclk);
170
171 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
172 if (ret != 0) {
173 dev_err(&pdev->dev, "Failed to add hcd");
174 goto fail_add_hcd;
175 }
176
177 priv->hcd = hcd;
178 platform_set_drvdata(pdev, priv);
179
180 return ret;
181
182fail_add_hcd:
183 clk_disable(priv->iclk);
184 clk_disable(priv->fclk);
185
186 clk_put(priv->iclk);
187 clk_put(priv->fclk);
188
189 kfree(priv);
190fail_alloc:
191 iounmap(hcd->regs);
192fail_ioremap:
193 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
194fail_request_resource:
195 usb_put_hcd(hcd);
196fail_create_hcd:
197 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
198
199 return ret;
200}
201
202static int __exit ehci_hcd_sh_remove(struct platform_device *pdev)
203{
204 struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
205 struct usb_hcd *hcd = priv->hcd;
206
207 usb_remove_hcd(hcd);
208 iounmap(hcd->regs);
209 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
210 usb_put_hcd(hcd);
211 platform_set_drvdata(pdev, NULL);
212
213 clk_disable(priv->fclk);
214 clk_disable(priv->iclk);
215
216 clk_put(priv->fclk);
217 clk_put(priv->iclk);
218
219 kfree(priv);
220
221 return 0;
222}
223
224static void ehci_hcd_sh_shutdown(struct platform_device *pdev)
225{
226 struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
227 struct usb_hcd *hcd = priv->hcd;
228
229 if (hcd->driver->shutdown)
230 hcd->driver->shutdown(hcd);
231}
232
233static struct platform_driver ehci_hcd_sh_driver = {
234 .probe = ehci_hcd_sh_probe,
235 .remove = __exit_p(ehci_hcd_sh_remove),
236 .shutdown = ehci_hcd_sh_shutdown,
237 .driver = {
238 .name = "sh_ehci",
239 .owner = THIS_MODULE,
240 },
241};
242
243MODULE_ALIAS("platform:sh_ehci");
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c
new file mode 100644
index 000000000000..dbf1e4ef3c17
--- /dev/null
+++ b/drivers/usb/host/ehci-spear.c
@@ -0,0 +1,212 @@
1/*
2* Driver for EHCI HCD on SPEAR SOC
3*
4* Copyright (C) 2010 ST Micro Electronics,
5* Deepak Sikri <deepak.sikri@st.com>
6*
7* Based on various ehci-*.c drivers
8*
9* This file is subject to the terms and conditions of the GNU General Public
10* License. See the file COPYING in the main directory of this archive for
11* more details.
12*/
13
14#include <linux/platform_device.h>
15#include <linux/clk.h>
16
17struct spear_ehci {
18 struct ehci_hcd ehci;
19 struct clk *clk;
20};
21
22#define to_spear_ehci(hcd) (struct spear_ehci *)hcd_to_ehci(hcd)
23
24static void spear_start_ehci(struct spear_ehci *ehci)
25{
26 clk_enable(ehci->clk);
27}
28
29static void spear_stop_ehci(struct spear_ehci *ehci)
30{
31 clk_disable(ehci->clk);
32}
33
34static int ehci_spear_setup(struct usb_hcd *hcd)
35{
36 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
37 int retval = 0;
38
39 /* registers start at offset 0x0 */
40 ehci->caps = hcd->regs;
41 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
42 &ehci->caps->hc_capbase));
43 /* cache this readonly data; minimize chip reads */
44 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
45 retval = ehci_halt(ehci);
46 if (retval)
47 return retval;
48
49 retval = ehci_init(hcd);
50 if (retval)
51 return retval;
52
53 ehci_reset(ehci);
54 ehci_port_power(ehci, 0);
55
56 return retval;
57}
58
59static const struct hc_driver ehci_spear_hc_driver = {
60 .description = hcd_name,
61 .product_desc = "SPEAr EHCI",
62 .hcd_priv_size = sizeof(struct spear_ehci),
63
64 /* generic hardware linkage */
65 .irq = ehci_irq,
66 .flags = HCD_MEMORY | HCD_USB2,
67
68 /* basic lifecycle operations */
69 .reset = ehci_spear_setup,
70 .start = ehci_run,
71 .stop = ehci_stop,
72 .shutdown = ehci_shutdown,
73
74 /* managing i/o requests and associated device resources */
75 .urb_enqueue = ehci_urb_enqueue,
76 .urb_dequeue = ehci_urb_dequeue,
77 .endpoint_disable = ehci_endpoint_disable,
78 .endpoint_reset = ehci_endpoint_reset,
79
80 /* scheduling support */
81 .get_frame_number = ehci_get_frame,
82
83 /* root hub support */
84 .hub_status_data = ehci_hub_status_data,
85 .hub_control = ehci_hub_control,
86 .bus_suspend = ehci_bus_suspend,
87 .bus_resume = ehci_bus_resume,
88 .relinquish_port = ehci_relinquish_port,
89 .port_handed_over = ehci_port_handed_over,
90 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
91};
92
93static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
94{
95 struct usb_hcd *hcd ;
96 struct spear_ehci *ehci;
97 struct resource *res;
98 struct clk *usbh_clk;
99 const struct hc_driver *driver = &ehci_spear_hc_driver;
100 int *pdata = pdev->dev.platform_data;
101 int irq, retval;
102 char clk_name[20] = "usbh_clk";
103
104 if (pdata == NULL)
105 return -EFAULT;
106
107 if (usb_disabled())
108 return -ENODEV;
109
110 irq = platform_get_irq(pdev, 0);
111 if (irq < 0) {
112 retval = irq;
113 goto fail_irq_get;
114 }
115
116 if (*pdata >= 0)
117 sprintf(clk_name, "usbh.%01d_clk", *pdata);
118
119 usbh_clk = clk_get(NULL, clk_name);
120 if (IS_ERR(usbh_clk)) {
121 dev_err(&pdev->dev, "Error getting interface clock\n");
122 retval = PTR_ERR(usbh_clk);
123 goto fail_get_usbh_clk;
124 }
125
126 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
127 if (!hcd) {
128 retval = -ENOMEM;
129 goto fail_create_hcd;
130 }
131
132 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
133 if (!res) {
134 retval = -ENODEV;
135 goto fail_request_resource;
136 }
137
138 hcd->rsrc_start = res->start;
139 hcd->rsrc_len = resource_size(res);
140 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
141 driver->description)) {
142 retval = -EBUSY;
143 goto fail_request_resource;
144 }
145
146 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
147 if (hcd->regs == NULL) {
148 dev_dbg(&pdev->dev, "error mapping memory\n");
149 retval = -ENOMEM;
150 goto fail_ioremap;
151 }
152
153 ehci = (struct spear_ehci *)hcd_to_ehci(hcd);
154 ehci->clk = usbh_clk;
155
156 spear_start_ehci(ehci);
157 retval = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED);
158 if (retval)
159 goto fail_add_hcd;
160
161 return retval;
162
163fail_add_hcd:
164 spear_stop_ehci(ehci);
165 iounmap(hcd->regs);
166fail_ioremap:
167 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
168fail_request_resource:
169 usb_put_hcd(hcd);
170fail_create_hcd:
171 clk_put(usbh_clk);
172fail_get_usbh_clk:
173fail_irq_get:
174 dev_err(&pdev->dev, "init fail, %d\n", retval);
175
176 return retval ;
177}
178
179static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
180{
181 struct usb_hcd *hcd = platform_get_drvdata(pdev);
182 struct spear_ehci *ehci_p = to_spear_ehci(hcd);
183
184 if (!hcd)
185 return 0;
186 if (in_interrupt())
187 BUG();
188 usb_remove_hcd(hcd);
189
190 if (ehci_p->clk)
191 spear_stop_ehci(ehci_p);
192 iounmap(hcd->regs);
193 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
194 usb_put_hcd(hcd);
195
196 if (ehci_p->clk)
197 clk_put(ehci_p->clk);
198
199 return 0;
200}
201
202static struct platform_driver spear_ehci_hcd_driver = {
203 .probe = spear_ehci_hcd_drv_probe,
204 .remove = spear_ehci_hcd_drv_remove,
205 .shutdown = usb_hcd_platform_shutdown,
206 .driver = {
207 .name = "spear-ehci",
208 .bus = &platform_bus_type
209 }
210};
211
212MODULE_ALIAS("platform:spear-ehci");
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
new file mode 100644
index 000000000000..02b2bfd49a10
--- /dev/null
+++ b/drivers/usb/host/ehci-tegra.c
@@ -0,0 +1,787 @@
1/*
2 * EHCI-compliant USB host controller driver for NVIDIA Tegra SoCs
3 *
4 * Copyright (C) 2010 Google, Inc.
5 * Copyright (C) 2009 NVIDIA Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 */
18
19#include <linux/clk.h>
20#include <linux/platform_device.h>
21#include <linux/platform_data/tegra_usb.h>
22#include <linux/irq.h>
23#include <linux/usb/otg.h>
24#include <mach/usb_phy.h>
25
26#define TEGRA_USB_DMA_ALIGN 32
27
28struct tegra_ehci_hcd {
29 struct ehci_hcd *ehci;
30 struct tegra_usb_phy *phy;
31 struct clk *clk;
32 struct clk *emc_clk;
33 struct otg_transceiver *transceiver;
34 int host_resumed;
35 int bus_suspended;
36 int port_resuming;
37 int power_down_on_bus_suspend;
38 enum tegra_usb_phy_port_speed port_speed;
39};
40
41static void tegra_ehci_power_up(struct usb_hcd *hcd)
42{
43 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
44
45 clk_enable(tegra->emc_clk);
46 clk_enable(tegra->clk);
47 tegra_usb_phy_power_on(tegra->phy);
48 tegra->host_resumed = 1;
49}
50
51static void tegra_ehci_power_down(struct usb_hcd *hcd)
52{
53 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
54
55 tegra->host_resumed = 0;
56 tegra_usb_phy_power_off(tegra->phy);
57 clk_disable(tegra->clk);
58 clk_disable(tegra->emc_clk);
59}
60
61static int tegra_ehci_internal_port_reset(
62 struct ehci_hcd *ehci,
63 u32 __iomem *portsc_reg
64)
65{
66 u32 temp;
67 unsigned long flags;
68 int retval = 0;
69 int i, tries;
70 u32 saved_usbintr;
71
72 spin_lock_irqsave(&ehci->lock, flags);
73 saved_usbintr = ehci_readl(ehci, &ehci->regs->intr_enable);
74 /* disable USB interrupt */
75 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
76 spin_unlock_irqrestore(&ehci->lock, flags);
77
78 /*
79 * Here we have to do Port Reset at most twice for
80 * Port Enable bit to be set.
81 */
82 for (i = 0; i < 2; i++) {
83 temp = ehci_readl(ehci, portsc_reg);
84 temp |= PORT_RESET;
85 ehci_writel(ehci, temp, portsc_reg);
86 mdelay(10);
87 temp &= ~PORT_RESET;
88 ehci_writel(ehci, temp, portsc_reg);
89 mdelay(1);
90 tries = 100;
91 do {
92 mdelay(1);
93 /*
94 * Up to this point, Port Enable bit is
95 * expected to be set after 2 ms waiting.
96 * USB1 usually takes extra 45 ms, for safety,
97 * we take 100 ms as timeout.
98 */
99 temp = ehci_readl(ehci, portsc_reg);
100 } while (!(temp & PORT_PE) && tries--);
101 if (temp & PORT_PE)
102 break;
103 }
104 if (i == 2)
105 retval = -ETIMEDOUT;
106
107 /*
108 * Clear Connect Status Change bit if it's set.
109 * We can't clear PORT_PEC. It will also cause PORT_PE to be cleared.
110 */
111 if (temp & PORT_CSC)
112 ehci_writel(ehci, PORT_CSC, portsc_reg);
113
114 /*
115 * Write to clear any interrupt status bits that might be set
116 * during port reset.
117 */
118 temp = ehci_readl(ehci, &ehci->regs->status);
119 ehci_writel(ehci, temp, &ehci->regs->status);
120
121 /* restore original interrupt enable bits */
122 ehci_writel(ehci, saved_usbintr, &ehci->regs->intr_enable);
123 return retval;
124}
125
126static int tegra_ehci_hub_control(
127 struct usb_hcd *hcd,
128 u16 typeReq,
129 u16 wValue,
130 u16 wIndex,
131 char *buf,
132 u16 wLength
133)
134{
135 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
136 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
137 u32 __iomem *status_reg;
138 u32 temp;
139 unsigned long flags;
140 int retval = 0;
141
142 status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1];
143
144 spin_lock_irqsave(&ehci->lock, flags);
145
146 /*
147 * In ehci_hub_control() for USB_PORT_FEAT_ENABLE clears the other bits
148 * that are write on clear, by writing back the register read value, so
149 * USB_PORT_FEAT_ENABLE is handled by masking the set on clear bits
150 */
151 if (typeReq == ClearPortFeature && wValue == USB_PORT_FEAT_ENABLE) {
152 temp = ehci_readl(ehci, status_reg) & ~PORT_RWC_BITS;
153 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
154 goto done;
155 }
156
157 else if (typeReq == GetPortStatus) {
158 temp = ehci_readl(ehci, status_reg);
159 if (tegra->port_resuming && !(temp & PORT_SUSPEND)) {
160 /* Resume completed, re-enable disconnect detection */
161 tegra->port_resuming = 0;
162 tegra_usb_phy_postresume(tegra->phy);
163 }
164 }
165
166 else if (typeReq == SetPortFeature && wValue == USB_PORT_FEAT_SUSPEND) {
167 temp = ehci_readl(ehci, status_reg);
168 if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) != 0) {
169 retval = -EPIPE;
170 goto done;
171 }
172
173 temp &= ~PORT_WKCONN_E;
174 temp |= PORT_WKDISC_E | PORT_WKOC_E;
175 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
176
177 /*
178 * If a transaction is in progress, there may be a delay in
179 * suspending the port. Poll until the port is suspended.
180 */
181 if (handshake(ehci, status_reg, PORT_SUSPEND,
182 PORT_SUSPEND, 5000))
183 pr_err("%s: timeout waiting for SUSPEND\n", __func__);
184
185 set_bit((wIndex & 0xff) - 1, &ehci->suspended_ports);
186 goto done;
187 }
188
189 /* For USB1 port we need to issue Port Reset twice internally */
190 if (tegra->phy->instance == 0 &&
191 (typeReq == SetPortFeature && wValue == USB_PORT_FEAT_RESET)) {
192 spin_unlock_irqrestore(&ehci->lock, flags);
193 return tegra_ehci_internal_port_reset(ehci, status_reg);
194 }
195
196 /*
197 * Tegra host controller will time the resume operation to clear the bit
198 * when the port control state switches to HS or FS Idle. This behavior
199 * is different from EHCI where the host controller driver is required
200 * to set this bit to a zero after the resume duration is timed in the
201 * driver.
202 */
203 else if (typeReq == ClearPortFeature &&
204 wValue == USB_PORT_FEAT_SUSPEND) {
205 temp = ehci_readl(ehci, status_reg);
206 if ((temp & PORT_RESET) || !(temp & PORT_PE)) {
207 retval = -EPIPE;
208 goto done;
209 }
210
211 if (!(temp & PORT_SUSPEND))
212 goto done;
213
214 /* Disable disconnect detection during port resume */
215 tegra_usb_phy_preresume(tegra->phy);
216
217 ehci->reset_done[wIndex-1] = jiffies + msecs_to_jiffies(25);
218
219 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
220 /* start resume signalling */
221 ehci_writel(ehci, temp | PORT_RESUME, status_reg);
222
223 spin_unlock_irqrestore(&ehci->lock, flags);
224 msleep(20);
225 spin_lock_irqsave(&ehci->lock, flags);
226
227 /* Poll until the controller clears RESUME and SUSPEND */
228 if (handshake(ehci, status_reg, PORT_RESUME, 0, 2000))
229 pr_err("%s: timeout waiting for RESUME\n", __func__);
230 if (handshake(ehci, status_reg, PORT_SUSPEND, 0, 2000))
231 pr_err("%s: timeout waiting for SUSPEND\n", __func__);
232
233 ehci->reset_done[wIndex-1] = 0;
234
235 tegra->port_resuming = 1;
236 goto done;
237 }
238
239 spin_unlock_irqrestore(&ehci->lock, flags);
240
241 /* Handle the hub control events here */
242 return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
243done:
244 spin_unlock_irqrestore(&ehci->lock, flags);
245 return retval;
246}
247
248static void tegra_ehci_restart(struct usb_hcd *hcd)
249{
250 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
251
252 ehci_reset(ehci);
253
254 /* setup the frame list and Async q heads */
255 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
256 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
257 /* setup the command register and set the controller in RUN mode */
258 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
259 ehci->command |= CMD_RUN;
260 ehci_writel(ehci, ehci->command, &ehci->regs->command);
261
262 down_write(&ehci_cf_port_reset_rwsem);
263 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
264 /* flush posted writes */
265 ehci_readl(ehci, &ehci->regs->command);
266 up_write(&ehci_cf_port_reset_rwsem);
267}
268
269static int tegra_usb_suspend(struct usb_hcd *hcd)
270{
271 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
272 struct ehci_regs __iomem *hw = tegra->ehci->regs;
273 unsigned long flags;
274
275 spin_lock_irqsave(&tegra->ehci->lock, flags);
276
277 tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3;
278 ehci_halt(tegra->ehci);
279 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
280
281 spin_unlock_irqrestore(&tegra->ehci->lock, flags);
282
283 tegra_ehci_power_down(hcd);
284 return 0;
285}
286
287static int tegra_usb_resume(struct usb_hcd *hcd)
288{
289 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
290 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
291 struct ehci_regs __iomem *hw = ehci->regs;
292 unsigned long val;
293
294 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
295 tegra_ehci_power_up(hcd);
296
297 if (tegra->port_speed > TEGRA_USB_PHY_PORT_SPEED_HIGH) {
298 /* Wait for the phy to detect new devices
299 * before we restart the controller */
300 msleep(10);
301 goto restart;
302 }
303
304 /* Force the phy to keep data lines in suspend state */
305 tegra_ehci_phy_restore_start(tegra->phy, tegra->port_speed);
306
307 /* Enable host mode */
308 tdi_reset(ehci);
309
310 /* Enable Port Power */
311 val = readl(&hw->port_status[0]);
312 val |= PORT_POWER;
313 writel(val, &hw->port_status[0]);
314 udelay(10);
315
316 /* Check if the phy resume from LP0. When the phy resume from LP0
317 * USB register will be reset. */
318 if (!readl(&hw->async_next)) {
319 /* Program the field PTC based on the saved speed mode */
320 val = readl(&hw->port_status[0]);
321 val &= ~PORT_TEST(~0);
322 if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_HIGH)
323 val |= PORT_TEST_FORCE;
324 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_FULL)
325 val |= PORT_TEST(6);
326 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
327 val |= PORT_TEST(7);
328 writel(val, &hw->port_status[0]);
329 udelay(10);
330
331 /* Disable test mode by setting PTC field to NORMAL_OP */
332 val = readl(&hw->port_status[0]);
333 val &= ~PORT_TEST(~0);
334 writel(val, &hw->port_status[0]);
335 udelay(10);
336 }
337
338 /* Poll until CCS is enabled */
339 if (handshake(ehci, &hw->port_status[0], PORT_CONNECT,
340 PORT_CONNECT, 2000)) {
341 pr_err("%s: timeout waiting for PORT_CONNECT\n", __func__);
342 goto restart;
343 }
344
345 /* Poll until PE is enabled */
346 if (handshake(ehci, &hw->port_status[0], PORT_PE,
347 PORT_PE, 2000)) {
348 pr_err("%s: timeout waiting for USB_PORTSC1_PE\n", __func__);
349 goto restart;
350 }
351
352 /* Clear the PCI status, to avoid an interrupt taken upon resume */
353 val = readl(&hw->status);
354 val |= STS_PCD;
355 writel(val, &hw->status);
356
357 /* Put controller in suspend mode by writing 1 to SUSP bit of PORTSC */
358 val = readl(&hw->port_status[0]);
359 if ((val & PORT_POWER) && (val & PORT_PE)) {
360 val |= PORT_SUSPEND;
361 writel(val, &hw->port_status[0]);
362
363 /* Wait until port suspend completes */
364 if (handshake(ehci, &hw->port_status[0], PORT_SUSPEND,
365 PORT_SUSPEND, 1000)) {
366 pr_err("%s: timeout waiting for PORT_SUSPEND\n",
367 __func__);
368 goto restart;
369 }
370 }
371
372 tegra_ehci_phy_restore_end(tegra->phy);
373 return 0;
374
375restart:
376 if (tegra->port_speed <= TEGRA_USB_PHY_PORT_SPEED_HIGH)
377 tegra_ehci_phy_restore_end(tegra->phy);
378
379 tegra_ehci_restart(hcd);
380 return 0;
381}
382
383static void tegra_ehci_shutdown(struct usb_hcd *hcd)
384{
385 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
386
387 /* ehci_shutdown touches the USB controller registers, make sure
388 * controller has clocks to it */
389 if (!tegra->host_resumed)
390 tegra_ehci_power_up(hcd);
391
392 ehci_shutdown(hcd);
393}
394
395static int tegra_ehci_setup(struct usb_hcd *hcd)
396{
397 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
398 int retval;
399
400 /* EHCI registers start at offset 0x100 */
401 ehci->caps = hcd->regs + 0x100;
402 ehci->regs = hcd->regs + 0x100 +
403 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
404
405 dbg_hcs_params(ehci, "reset");
406 dbg_hcc_params(ehci, "reset");
407
408 /* cache this readonly data; minimize chip reads */
409 ehci->hcs_params = readl(&ehci->caps->hcs_params);
410
411 /* switch to host mode */
412 hcd->has_tt = 1;
413 ehci_reset(ehci);
414
415 retval = ehci_halt(ehci);
416 if (retval)
417 return retval;
418
419 /* data structure init */
420 retval = ehci_init(hcd);
421 if (retval)
422 return retval;
423
424 ehci->sbrn = 0x20;
425
426 ehci_port_power(ehci, 1);
427 return retval;
428}
429
430#ifdef CONFIG_PM
431static int tegra_ehci_bus_suspend(struct usb_hcd *hcd)
432{
433 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
434 int error_status = 0;
435
436 error_status = ehci_bus_suspend(hcd);
437 if (!error_status && tegra->power_down_on_bus_suspend) {
438 tegra_usb_suspend(hcd);
439 tegra->bus_suspended = 1;
440 }
441
442 return error_status;
443}
444
445static int tegra_ehci_bus_resume(struct usb_hcd *hcd)
446{
447 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
448
449 if (tegra->bus_suspended && tegra->power_down_on_bus_suspend) {
450 tegra_usb_resume(hcd);
451 tegra->bus_suspended = 0;
452 }
453
454 tegra_usb_phy_preresume(tegra->phy);
455 tegra->port_resuming = 1;
456 return ehci_bus_resume(hcd);
457}
458#endif
459
460struct temp_buffer {
461 void *kmalloc_ptr;
462 void *old_xfer_buffer;
463 u8 data[0];
464};
465
466static void free_temp_buffer(struct urb *urb)
467{
468 enum dma_data_direction dir;
469 struct temp_buffer *temp;
470
471 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
472 return;
473
474 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
475
476 temp = container_of(urb->transfer_buffer, struct temp_buffer,
477 data);
478
479 if (dir == DMA_FROM_DEVICE)
480 memcpy(temp->old_xfer_buffer, temp->data,
481 urb->transfer_buffer_length);
482 urb->transfer_buffer = temp->old_xfer_buffer;
483 kfree(temp->kmalloc_ptr);
484
485 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
486}
487
488static int alloc_temp_buffer(struct urb *urb, gfp_t mem_flags)
489{
490 enum dma_data_direction dir;
491 struct temp_buffer *temp, *kmalloc_ptr;
492 size_t kmalloc_size;
493
494 if (urb->num_sgs || urb->sg ||
495 urb->transfer_buffer_length == 0 ||
496 !((uintptr_t)urb->transfer_buffer & (TEGRA_USB_DMA_ALIGN - 1)))
497 return 0;
498
499 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
500
501 /* Allocate a buffer with enough padding for alignment */
502 kmalloc_size = urb->transfer_buffer_length +
503 sizeof(struct temp_buffer) + TEGRA_USB_DMA_ALIGN - 1;
504
505 kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
506 if (!kmalloc_ptr)
507 return -ENOMEM;
508
509 /* Position our struct temp_buffer such that data is aligned */
510 temp = PTR_ALIGN(kmalloc_ptr + 1, TEGRA_USB_DMA_ALIGN) - 1;
511
512 temp->kmalloc_ptr = kmalloc_ptr;
513 temp->old_xfer_buffer = urb->transfer_buffer;
514 if (dir == DMA_TO_DEVICE)
515 memcpy(temp->data, urb->transfer_buffer,
516 urb->transfer_buffer_length);
517 urb->transfer_buffer = temp->data;
518
519 urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER;
520
521 return 0;
522}
523
524static int tegra_ehci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
525 gfp_t mem_flags)
526{
527 int ret;
528
529 ret = alloc_temp_buffer(urb, mem_flags);
530 if (ret)
531 return ret;
532
533 ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
534 if (ret)
535 free_temp_buffer(urb);
536
537 return ret;
538}
539
540static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
541{
542 usb_hcd_unmap_urb_for_dma(hcd, urb);
543 free_temp_buffer(urb);
544}
545
546static const struct hc_driver tegra_ehci_hc_driver = {
547 .description = hcd_name,
548 .product_desc = "Tegra EHCI Host Controller",
549 .hcd_priv_size = sizeof(struct ehci_hcd),
550
551 .flags = HCD_USB2 | HCD_MEMORY,
552
553 .reset = tegra_ehci_setup,
554 .irq = ehci_irq,
555
556 .start = ehci_run,
557 .stop = ehci_stop,
558 .shutdown = tegra_ehci_shutdown,
559 .urb_enqueue = ehci_urb_enqueue,
560 .urb_dequeue = ehci_urb_dequeue,
561 .map_urb_for_dma = tegra_ehci_map_urb_for_dma,
562 .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma,
563 .endpoint_disable = ehci_endpoint_disable,
564 .endpoint_reset = ehci_endpoint_reset,
565 .get_frame_number = ehci_get_frame,
566 .hub_status_data = ehci_hub_status_data,
567 .hub_control = tegra_ehci_hub_control,
568 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
569#ifdef CONFIG_PM
570 .bus_suspend = tegra_ehci_bus_suspend,
571 .bus_resume = tegra_ehci_bus_resume,
572#endif
573 .relinquish_port = ehci_relinquish_port,
574 .port_handed_over = ehci_port_handed_over,
575};
576
577static int tegra_ehci_probe(struct platform_device *pdev)
578{
579 struct resource *res;
580 struct usb_hcd *hcd;
581 struct tegra_ehci_hcd *tegra;
582 struct tegra_ehci_platform_data *pdata;
583 int err = 0;
584 int irq;
585 int instance = pdev->id;
586
587 pdata = pdev->dev.platform_data;
588 if (!pdata) {
589 dev_err(&pdev->dev, "Platform data missing\n");
590 return -EINVAL;
591 }
592
593 tegra = kzalloc(sizeof(struct tegra_ehci_hcd), GFP_KERNEL);
594 if (!tegra)
595 return -ENOMEM;
596
597 hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev,
598 dev_name(&pdev->dev));
599 if (!hcd) {
600 dev_err(&pdev->dev, "Unable to create HCD\n");
601 err = -ENOMEM;
602 goto fail_hcd;
603 }
604
605 platform_set_drvdata(pdev, tegra);
606
607 tegra->clk = clk_get(&pdev->dev, NULL);
608 if (IS_ERR(tegra->clk)) {
609 dev_err(&pdev->dev, "Can't get ehci clock\n");
610 err = PTR_ERR(tegra->clk);
611 goto fail_clk;
612 }
613
614 err = clk_enable(tegra->clk);
615 if (err)
616 goto fail_clken;
617
618 tegra->emc_clk = clk_get(&pdev->dev, "emc");
619 if (IS_ERR(tegra->emc_clk)) {
620 dev_err(&pdev->dev, "Can't get emc clock\n");
621 err = PTR_ERR(tegra->emc_clk);
622 goto fail_emc_clk;
623 }
624
625 clk_enable(tegra->emc_clk);
626 clk_set_rate(tegra->emc_clk, 400000000);
627
628 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
629 if (!res) {
630 dev_err(&pdev->dev, "Failed to get I/O memory\n");
631 err = -ENXIO;
632 goto fail_io;
633 }
634 hcd->rsrc_start = res->start;
635 hcd->rsrc_len = resource_size(res);
636 hcd->regs = ioremap(res->start, resource_size(res));
637 if (!hcd->regs) {
638 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
639 err = -ENOMEM;
640 goto fail_io;
641 }
642
643 tegra->phy = tegra_usb_phy_open(instance, hcd->regs, pdata->phy_config,
644 TEGRA_USB_PHY_MODE_HOST);
645 if (IS_ERR(tegra->phy)) {
646 dev_err(&pdev->dev, "Failed to open USB phy\n");
647 err = -ENXIO;
648 goto fail_phy;
649 }
650
651 err = tegra_usb_phy_power_on(tegra->phy);
652 if (err) {
653 dev_err(&pdev->dev, "Failed to power on the phy\n");
654 goto fail;
655 }
656
657 tegra->host_resumed = 1;
658 tegra->power_down_on_bus_suspend = pdata->power_down_on_bus_suspend;
659 tegra->ehci = hcd_to_ehci(hcd);
660
661 irq = platform_get_irq(pdev, 0);
662 if (!irq) {
663 dev_err(&pdev->dev, "Failed to get IRQ\n");
664 err = -ENODEV;
665 goto fail;
666 }
667 set_irq_flags(irq, IRQF_VALID);
668
669#ifdef CONFIG_USB_OTG_UTILS
670 if (pdata->operating_mode == TEGRA_USB_OTG) {
671 tegra->transceiver = otg_get_transceiver();
672 if (tegra->transceiver)
673 otg_set_host(tegra->transceiver, &hcd->self);
674 }
675#endif
676
677 err = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
678 if (err) {
679 dev_err(&pdev->dev, "Failed to add USB HCD\n");
680 goto fail;
681 }
682
683 return err;
684
685fail:
686#ifdef CONFIG_USB_OTG_UTILS
687 if (tegra->transceiver) {
688 otg_set_host(tegra->transceiver, NULL);
689 otg_put_transceiver(tegra->transceiver);
690 }
691#endif
692 tegra_usb_phy_close(tegra->phy);
693fail_phy:
694 iounmap(hcd->regs);
695fail_io:
696 clk_disable(tegra->emc_clk);
697 clk_put(tegra->emc_clk);
698fail_emc_clk:
699 clk_disable(tegra->clk);
700fail_clken:
701 clk_put(tegra->clk);
702fail_clk:
703 usb_put_hcd(hcd);
704fail_hcd:
705 kfree(tegra);
706 return err;
707}
708
709#ifdef CONFIG_PM
710static int tegra_ehci_resume(struct platform_device *pdev)
711{
712 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
713 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
714
715 if (tegra->bus_suspended)
716 return 0;
717
718 return tegra_usb_resume(hcd);
719}
720
721static int tegra_ehci_suspend(struct platform_device *pdev, pm_message_t state)
722{
723 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
724 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
725
726 if (tegra->bus_suspended)
727 return 0;
728
729 if (time_before(jiffies, tegra->ehci->next_statechange))
730 msleep(10);
731
732 return tegra_usb_suspend(hcd);
733}
734#endif
735
736static int tegra_ehci_remove(struct platform_device *pdev)
737{
738 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
739 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
740
741 if (tegra == NULL || hcd == NULL)
742 return -EINVAL;
743
744#ifdef CONFIG_USB_OTG_UTILS
745 if (tegra->transceiver) {
746 otg_set_host(tegra->transceiver, NULL);
747 otg_put_transceiver(tegra->transceiver);
748 }
749#endif
750
751 usb_remove_hcd(hcd);
752 usb_put_hcd(hcd);
753
754 tegra_usb_phy_close(tegra->phy);
755 iounmap(hcd->regs);
756
757 clk_disable(tegra->clk);
758 clk_put(tegra->clk);
759
760 clk_disable(tegra->emc_clk);
761 clk_put(tegra->emc_clk);
762
763 kfree(tegra);
764 return 0;
765}
766
767static void tegra_ehci_hcd_shutdown(struct platform_device *pdev)
768{
769 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
770 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
771
772 if (hcd->driver->shutdown)
773 hcd->driver->shutdown(hcd);
774}
775
776static struct platform_driver tegra_ehci_driver = {
777 .probe = tegra_ehci_probe,
778 .remove = tegra_ehci_remove,
779#ifdef CONFIG_PM
780 .suspend = tegra_ehci_suspend,
781 .resume = tegra_ehci_resume,
782#endif
783 .shutdown = tegra_ehci_hcd_shutdown,
784 .driver = {
785 .name = "tegra-ehci",
786 }
787};
diff --git a/drivers/usb/host/ehci-vt8500.c b/drivers/usb/host/ehci-vt8500.c
new file mode 100644
index 000000000000..47d749631bc7
--- /dev/null
+++ b/drivers/usb/host/ehci-vt8500.c
@@ -0,0 +1,173 @@
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/platform_device.h>
20
21static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
22{
23 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
24 int rc = 0;
25
26 if (!udev->parent) /* udev is root hub itself, impossible */
27 rc = -1;
28 /* we only support lpm device connected to root hub yet */
29 if (ehci->has_lpm && !udev->parent->parent) {
30 rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
31 if (!rc)
32 rc = ehci_lpm_check(ehci, udev->portnum);
33 }
34 return rc;
35}
36
37static const struct hc_driver vt8500_ehci_hc_driver = {
38 .description = hcd_name,
39 .product_desc = "VT8500 EHCI",
40 .hcd_priv_size = sizeof(struct ehci_hcd),
41
42 /*
43 * generic hardware linkage
44 */
45 .irq = ehci_irq,
46 .flags = HCD_MEMORY | HCD_USB2,
47
48 /*
49 * basic lifecycle operations
50 */
51 .reset = ehci_init,
52 .start = ehci_run,
53 .stop = ehci_stop,
54 .shutdown = ehci_shutdown,
55
56 /*
57 * managing i/o requests and associated device resources
58 */
59 .urb_enqueue = ehci_urb_enqueue,
60 .urb_dequeue = ehci_urb_dequeue,
61 .endpoint_disable = ehci_endpoint_disable,
62 .endpoint_reset = ehci_endpoint_reset,
63
64 /*
65 * scheduling support
66 */
67 .get_frame_number = ehci_get_frame,
68
69 /*
70 * root hub support
71 */
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
79 /*
80 * call back when device connected and addressed
81 */
82 .update_device = ehci_update_device,
83
84 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
85};
86
87static int vt8500_ehci_drv_probe(struct platform_device *pdev)
88{
89 struct usb_hcd *hcd;
90 struct ehci_hcd *ehci;
91 struct resource *res;
92 int ret;
93
94 if (usb_disabled())
95 return -ENODEV;
96
97 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
98 pr_debug("resource[1] is not IORESOURCE_IRQ");
99 return -ENOMEM;
100 }
101 hcd = usb_create_hcd(&vt8500_ehci_hc_driver, &pdev->dev, "VT8500");
102 if (!hcd)
103 return -ENOMEM;
104
105 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
106 hcd->rsrc_start = res->start;
107 hcd->rsrc_len = resource_size(res);
108
109 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
110 pr_debug("request_mem_region failed");
111 ret = -EBUSY;
112 goto err1;
113 }
114
115 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
116 if (!hcd->regs) {
117 pr_debug("ioremap failed");
118 ret = -ENOMEM;
119 goto err2;
120 }
121
122 ehci = hcd_to_ehci(hcd);
123 ehci->caps = hcd->regs;
124 ehci->regs = hcd->regs +
125 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
126
127 dbg_hcs_params(ehci, "reset");
128 dbg_hcc_params(ehci, "reset");
129
130 /* cache this readonly data; minimize chip reads */
131 ehci->hcs_params = readl(&ehci->caps->hcs_params);
132
133 ehci_port_power(ehci, 1);
134
135 ret = usb_add_hcd(hcd, pdev->resource[1].start,
136 IRQF_DISABLED | IRQF_SHARED);
137 if (ret == 0) {
138 platform_set_drvdata(pdev, hcd);
139 return ret;
140 }
141
142 iounmap(hcd->regs);
143err2:
144 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
145err1:
146 usb_put_hcd(hcd);
147 return ret;
148}
149
150static int vt8500_ehci_drv_remove(struct platform_device *pdev)
151{
152 struct usb_hcd *hcd = platform_get_drvdata(pdev);
153
154 usb_remove_hcd(hcd);
155 iounmap(hcd->regs);
156 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
157 usb_put_hcd(hcd);
158 platform_set_drvdata(pdev, NULL);
159
160 return 0;
161}
162
163static struct platform_driver vt8500_ehci_driver = {
164 .probe = vt8500_ehci_drv_probe,
165 .remove = vt8500_ehci_drv_remove,
166 .shutdown = usb_hcd_platform_shutdown,
167 .driver = {
168 .name = "vt8500-ehci",
169 .owner = THIS_MODULE,
170 }
171};
172
173MODULE_ALIAS("platform:vt8500-ehci");
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c
index cfa21ea20f82..52a027aaa370 100644
--- a/drivers/usb/host/ehci-w90x900.c
+++ b/drivers/usb/host/ehci-w90x900.c
@@ -57,7 +57,7 @@ static int __devinit usb_w90x900_probe(const struct hc_driver *driver,
57 ehci = hcd_to_ehci(hcd); 57 ehci = hcd_to_ehci(hcd);
58 ehci->caps = hcd->regs; 58 ehci->caps = hcd->regs;
59 ehci->regs = hcd->regs + 59 ehci->regs = hcd->regs +
60 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 60 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
61 61
62 /* enable PHY 0,1,the regs only apply to w90p910 62 /* enable PHY 0,1,the regs only apply to w90p910
63 * 0xA4,0xA8 were offsets of PHY0 and PHY1 controller of 63 * 0xA4,0xA8 were offsets of PHY0 and PHY1 controller of
@@ -130,6 +130,7 @@ static const struct hc_driver ehci_w90x900_hc_driver = {
130 .urb_enqueue = ehci_urb_enqueue, 130 .urb_enqueue = ehci_urb_enqueue,
131 .urb_dequeue = ehci_urb_dequeue, 131 .urb_dequeue = ehci_urb_dequeue,
132 .endpoint_disable = ehci_endpoint_disable, 132 .endpoint_disable = ehci_endpoint_disable,
133 .endpoint_reset = ehci_endpoint_reset,
133 134
134 /* 135 /*
135 * scheduling support 136 * scheduling support
@@ -147,6 +148,8 @@ static const struct hc_driver ehci_w90x900_hc_driver = {
147#endif 148#endif
148 .relinquish_port = ehci_relinquish_port, 149 .relinquish_port = ehci_relinquish_port,
149 .port_handed_over = ehci_port_handed_over, 150 .port_handed_over = ehci_port_handed_over,
151
152 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
150}; 153};
151 154
152static int __devinit ehci_w90x900_probe(struct platform_device *pdev) 155static int __devinit ehci_w90x900_probe(struct platform_device *pdev)
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c
index 6c8076ad821d..a64d6d66d760 100644
--- a/drivers/usb/host/ehci-xilinx-of.c
+++ b/drivers/usb/host/ehci-xilinx-of.c
@@ -29,6 +29,7 @@
29 29
30#include <linux/of.h> 30#include <linux/of.h>
31#include <linux/of_platform.h> 31#include <linux/of_platform.h>
32#include <linux/of_address.h>
32 33
33/** 34/**
34 * ehci_xilinx_of_setup - Initialize the device for ehci_reset() 35 * ehci_xilinx_of_setup - Initialize the device for ehci_reset()
@@ -117,6 +118,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
117 .urb_enqueue = ehci_urb_enqueue, 118 .urb_enqueue = ehci_urb_enqueue,
118 .urb_dequeue = ehci_urb_dequeue, 119 .urb_dequeue = ehci_urb_dequeue,
119 .endpoint_disable = ehci_endpoint_disable, 120 .endpoint_disable = ehci_endpoint_disable,
121 .endpoint_reset = ehci_endpoint_reset,
120 122
121 /* 123 /*
122 * scheduling support 124 * scheduling support
@@ -141,15 +143,13 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
141/** 143/**
142 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller 144 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
143 * @op: pointer to the platform_device bound to the host controller 145 * @op: pointer to the platform_device bound to the host controller
144 * @match: pointer to of_device_id structure, not used
145 * 146 *
146 * This function requests resources and sets up appropriate properties for the 147 * This function requests resources and sets up appropriate properties for the
147 * host controller. Because the Xilinx USB host controller can be configured 148 * host controller. Because the Xilinx USB host controller can be configured
148 * as HS only or HS/FS only, it checks the configuration in the device tree 149 * as HS only or HS/FS only, it checks the configuration in the device tree
149 * entry, and sets an appropriate value for hcd->has_tt. 150 * entry, and sets an appropriate value for hcd->has_tt.
150 */ 151 */
151static int __devinit 152static int __devinit ehci_hcd_xilinx_of_probe(struct platform_device *op)
152ehci_hcd_xilinx_of_probe(struct platform_device *op, const struct of_device_id *match)
153{ 153{
154 struct device_node *dn = op->dev.of_node; 154 struct device_node *dn = op->dev.of_node;
155 struct usb_hcd *hcd; 155 struct usb_hcd *hcd;
@@ -220,7 +220,7 @@ ehci_hcd_xilinx_of_probe(struct platform_device *op, const struct of_device_id *
220 */ 220 */
221 ehci->caps = hcd->regs + 0x100; 221 ehci->caps = hcd->regs + 0x100;
222 ehci->regs = hcd->regs + 0x100 + 222 ehci->regs = hcd->regs + 0x100 +
223 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 223 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
224 224
225 /* cache this readonly data; minimize chip reads */ 225 /* cache this readonly data; minimize chip reads */
226 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 226 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
@@ -287,7 +287,7 @@ static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
287}; 287};
288MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match); 288MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
289 289
290static struct of_platform_driver ehci_hcd_xilinx_of_driver = { 290static struct platform_driver ehci_hcd_xilinx_of_driver = {
291 .probe = ehci_hcd_xilinx_of_probe, 291 .probe = ehci_hcd_xilinx_of_probe,
292 .remove = ehci_hcd_xilinx_of_remove, 292 .remove = ehci_hcd_xilinx_of_remove,
293 .shutdown = ehci_hcd_xilinx_of_shutdown, 293 .shutdown = ehci_hcd_xilinx_of_shutdown,
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index bde823f704e9..bd6ff489baf9 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -73,6 +73,7 @@ struct ehci_hcd { /* one per controller */
73 73
74 /* async schedule support */ 74 /* async schedule support */
75 struct ehci_qh *async; 75 struct ehci_qh *async;
76 struct ehci_qh *dummy; /* For AMD quirk use */
76 struct ehci_qh *reclaim; 77 struct ehci_qh *reclaim;
77 unsigned scanning : 1; 78 unsigned scanning : 1;
78 79
@@ -117,6 +118,7 @@ struct ehci_hcd { /* one per controller */
117 struct timer_list watchdog; 118 struct timer_list watchdog;
118 unsigned long actions; 119 unsigned long actions;
119 unsigned stamp; 120 unsigned stamp;
121 unsigned periodic_stamp;
120 unsigned random_frame; 122 unsigned random_frame;
121 unsigned long next_statechange; 123 unsigned long next_statechange;
122 ktime_t last_periodic_enable; 124 ktime_t last_periodic_enable;
@@ -127,10 +129,14 @@ struct ehci_hcd { /* one per controller */
127 unsigned has_fsl_port_bug:1; /* FreeScale */ 129 unsigned has_fsl_port_bug:1; /* FreeScale */
128 unsigned big_endian_mmio:1; 130 unsigned big_endian_mmio:1;
129 unsigned big_endian_desc:1; 131 unsigned big_endian_desc:1;
132 unsigned big_endian_capbase:1;
130 unsigned has_amcc_usb23:1; 133 unsigned has_amcc_usb23:1;
131 unsigned need_io_watchdog:1; 134 unsigned need_io_watchdog:1;
132 unsigned broken_periodic:1; 135 unsigned broken_periodic:1;
136 unsigned amd_pll_fix:1;
133 unsigned fs_i_thresh:1; /* Intel iso scheduling */ 137 unsigned fs_i_thresh:1; /* Intel iso scheduling */
138 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/
139 unsigned has_synopsys_hc_bug:1; /* Synopsys HC */
134 140
135 /* required for usb32 quirk */ 141 /* required for usb32 quirk */
136 #define OHCI_CTRL_HCFS (3 << 6) 142 #define OHCI_CTRL_HCFS (3 << 6)
@@ -157,6 +163,10 @@ struct ehci_hcd { /* one per controller */
157#ifdef DEBUG 163#ifdef DEBUG
158 struct dentry *debug_dir; 164 struct dentry *debug_dir;
159#endif 165#endif
166 /*
167 * OTG controllers and transceivers need software interaction
168 */
169 struct otg_transceiver *transceiver;
160}; 170};
161 171
162/* convert between an HCD pointer and the corresponding EHCI_HCD */ 172/* convert between an HCD pointer and the corresponding EHCI_HCD */
@@ -597,12 +607,18 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
597 * This attempts to support either format at compile time without a 607 * This attempts to support either format at compile time without a
598 * runtime penalty, or both formats with the additional overhead 608 * runtime penalty, or both formats with the additional overhead
599 * of checking a flag bit. 609 * of checking a flag bit.
610 *
611 * ehci_big_endian_capbase is a special quirk for controllers that
612 * implement the HC capability registers as separate registers and not
613 * as fields of a 32-bit register.
600 */ 614 */
601 615
602#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO 616#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
603#define ehci_big_endian_mmio(e) ((e)->big_endian_mmio) 617#define ehci_big_endian_mmio(e) ((e)->big_endian_mmio)
618#define ehci_big_endian_capbase(e) ((e)->big_endian_capbase)
604#else 619#else
605#define ehci_big_endian_mmio(e) 0 620#define ehci_big_endian_mmio(e) 0
621#define ehci_big_endian_capbase(e) 0
606#endif 622#endif
607 623
608/* 624/*
@@ -641,7 +657,7 @@ static inline void ehci_writel(const struct ehci_hcd *ehci,
641/* 657/*
642 * On certain ppc-44x SoC there is a HW issue, that could only worked around with 658 * On certain ppc-44x SoC there is a HW issue, that could only worked around with
643 * explicit suspend/operate of OHCI. This function hereby makes sense only on that arch. 659 * explicit suspend/operate of OHCI. This function hereby makes sense only on that arch.
644 * Other common bits are dependant on has_amcc_usb23 quirk flag. 660 * Other common bits are dependent on has_amcc_usb23 quirk flag.
645 */ 661 */
646#ifdef CONFIG_44x 662#ifdef CONFIG_44x
647static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational) 663static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index 20092a27a1e8..19223c7449e1 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -98,13 +98,13 @@ void fhci_usb_enable_interrupt(struct fhci_usb *usb)
98 usb->intr_nesting_cnt--; 98 usb->intr_nesting_cnt--;
99} 99}
100 100
101/* diable the usb interrupt */ 101/* disable the usb interrupt */
102void fhci_usb_disable_interrupt(struct fhci_usb *usb) 102void fhci_usb_disable_interrupt(struct fhci_usb *usb)
103{ 103{
104 struct fhci_hcd *fhci = usb->fhci; 104 struct fhci_hcd *fhci = usb->fhci;
105 105
106 if (usb->intr_nesting_cnt == 0) { 106 if (usb->intr_nesting_cnt == 0) {
107 /* diable the timer interrupt */ 107 /* disable the timer interrupt */
108 disable_irq_nosync(fhci->timer->irq); 108 disable_irq_nosync(fhci->timer->irq);
109 109
110 /* disable the usb interrupt */ 110 /* disable the usb interrupt */
@@ -401,7 +401,7 @@ static int fhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
401 /* 1 td fro setup,1 for ack */ 401 /* 1 td fro setup,1 for ack */
402 size = 2; 402 size = 2;
403 case PIPE_BULK: 403 case PIPE_BULK:
404 /* one td for every 4096 bytes(can be upto 8k) */ 404 /* one td for every 4096 bytes(can be up to 8k) */
405 size += urb->transfer_buffer_length / 4096; 405 size += urb->transfer_buffer_length / 4096;
406 /* ...add for any remaining bytes... */ 406 /* ...add for any remaining bytes... */
407 if ((urb->transfer_buffer_length % 4096) != 0) 407 if ((urb->transfer_buffer_length % 4096) != 0)
@@ -561,8 +561,7 @@ static const struct hc_driver fhci_driver = {
561 .hub_control = fhci_hub_control, 561 .hub_control = fhci_hub_control,
562}; 562};
563 563
564static int __devinit of_fhci_probe(struct platform_device *ofdev, 564static int __devinit of_fhci_probe(struct platform_device *ofdev)
565 const struct of_device_id *ofid)
566{ 565{
567 struct device *dev = &ofdev->dev; 566 struct device *dev = &ofdev->dev;
568 struct device_node *node = dev->of_node; 567 struct device_node *node = dev->of_node;
@@ -812,7 +811,7 @@ static const struct of_device_id of_fhci_match[] = {
812}; 811};
813MODULE_DEVICE_TABLE(of, of_fhci_match); 812MODULE_DEVICE_TABLE(of, of_fhci_match);
814 813
815static struct of_platform_driver of_fhci_driver = { 814static struct platform_driver of_fhci_driver = {
816 .driver = { 815 .driver = {
817 .name = "fsl,usb-fhci", 816 .name = "fsl,usb-fhci",
818 .owner = THIS_MODULE, 817 .owner = THIS_MODULE,
@@ -824,13 +823,13 @@ static struct of_platform_driver of_fhci_driver = {
824 823
825static int __init fhci_module_init(void) 824static int __init fhci_module_init(void)
826{ 825{
827 return of_register_platform_driver(&of_fhci_driver); 826 return platform_driver_register(&of_fhci_driver);
828} 827}
829module_init(fhci_module_init); 828module_init(fhci_module_init);
830 829
831static void __exit fhci_module_exit(void) 830static void __exit fhci_module_exit(void)
832{ 831{
833 of_unregister_platform_driver(&of_fhci_driver); 832 platform_driver_unregister(&of_fhci_driver);
834} 833}
835module_exit(fhci_module_exit); 834module_exit(fhci_module_exit);
836 835
diff --git a/drivers/usb/host/fhci-tds.c b/drivers/usb/host/fhci-tds.c
index 7be548ca2183..0ea577bfca2a 100644
--- a/drivers/usb/host/fhci-tds.c
+++ b/drivers/usb/host/fhci-tds.c
@@ -40,7 +40,7 @@
40#define TD_RXER 0x0020 /* Rx error or not */ 40#define TD_RXER 0x0020 /* Rx error or not */
41 41
42#define TD_NAK 0x0010 /* No ack. */ 42#define TD_NAK 0x0010 /* No ack. */
43#define TD_STAL 0x0008 /* Stall recieved */ 43#define TD_STAL 0x0008 /* Stall received */
44#define TD_TO 0x0004 /* time out */ 44#define TD_TO 0x0004 /* time out */
45#define TD_UN 0x0002 /* underrun */ 45#define TD_UN 0x0002 /* underrun */
46#define TD_NO 0x0010 /* Rx Non Octet Aligned Packet */ 46#define TD_NO 0x0010 /* Rx Non Octet Aligned Packet */
@@ -271,10 +271,10 @@ void fhci_init_ep_registers(struct fhci_usb *usb, struct endpoint *ep,
271 271
272/* 272/*
273 * Collect the submitted frames and inform the application about them 273 * Collect the submitted frames and inform the application about them
274 * It is also prepearing the TDs for new frames. If the Tx interrupts 274 * It is also preparing the TDs for new frames. If the Tx interrupts
275 * are diabled, the application should call that routine to get 275 * are disabled, the application should call that routine to get
276 * confirmation about the submitted frames. Otherwise, the routine is 276 * confirmation about the submitted frames. Otherwise, the routine is
277 * called frome the interrupt service routine during the Tx interrupt. 277 * called from the interrupt service routine during the Tx interrupt.
278 * In that case the application is informed by calling the application 278 * In that case the application is informed by calling the application
279 * specific 'fhci_transaction_confirm' routine 279 * specific 'fhci_transaction_confirm' routine
280 */ 280 */
@@ -337,7 +337,7 @@ static void fhci_td_transaction_confirm(struct fhci_usb *usb)
337 pkt->status = USB_TD_RX_ER_NONOCT; 337 pkt->status = USB_TD_RX_ER_NONOCT;
338 else 338 else
339 fhci_err(usb->fhci, "illegal error " 339 fhci_err(usb->fhci, "illegal error "
340 "occured\n"); 340 "occurred\n");
341 } else if (td_status & TD_NAK) 341 } else if (td_status & TD_NAK)
342 pkt->status = USB_TD_TX_ER_NAK; 342 pkt->status = USB_TD_TX_ER_NAK;
343 else if (td_status & TD_TO) 343 else if (td_status & TD_TO)
@@ -347,7 +347,7 @@ static void fhci_td_transaction_confirm(struct fhci_usb *usb)
347 else if (td_status & TD_STAL) 347 else if (td_status & TD_STAL)
348 pkt->status = USB_TD_TX_ER_STALL; 348 pkt->status = USB_TD_TX_ER_STALL;
349 else 349 else
350 fhci_err(usb->fhci, "illegal error occured\n"); 350 fhci_err(usb->fhci, "illegal error occurred\n");
351 } else if ((extra_data & TD_TOK_IN) && 351 } else if ((extra_data & TD_TOK_IN) &&
352 pkt->len > td_length - CRC_SIZE) { 352 pkt->len > td_length - CRC_SIZE) {
353 pkt->status = USB_TD_RX_DATA_UNDERUN; 353 pkt->status = USB_TD_RX_DATA_UNDERUN;
diff --git a/drivers/usb/host/fhci.h b/drivers/usb/host/fhci.h
index 71c3caaea4c1..dc6939a44a1a 100644
--- a/drivers/usb/host/fhci.h
+++ b/drivers/usb/host/fhci.h
@@ -82,7 +82,7 @@
82#define USB_TD_RX_ER_NONOCT 0x40000000 /* Tx Non Octet Aligned Packet */ 82#define USB_TD_RX_ER_NONOCT 0x40000000 /* Tx Non Octet Aligned Packet */
83#define USB_TD_RX_ER_BITSTUFF 0x20000000 /* Frame Aborted-Received pkt */ 83#define USB_TD_RX_ER_BITSTUFF 0x20000000 /* Frame Aborted-Received pkt */
84#define USB_TD_RX_ER_CRC 0x10000000 /* CRC error */ 84#define USB_TD_RX_ER_CRC 0x10000000 /* CRC error */
85#define USB_TD_RX_ER_OVERUN 0x08000000 /* Over - run occured */ 85#define USB_TD_RX_ER_OVERUN 0x08000000 /* Over - run occurred */
86#define USB_TD_RX_ER_PID 0x04000000 /* wrong PID received */ 86#define USB_TD_RX_ER_PID 0x04000000 /* wrong PID received */
87#define USB_TD_RX_DATA_UNDERUN 0x02000000 /* shorter than expected */ 87#define USB_TD_RX_DATA_UNDERUN 0x02000000 /* shorter than expected */
88#define USB_TD_RX_DATA_OVERUN 0x01000000 /* longer than expected */ 88#define USB_TD_RX_DATA_OVERUN 0x01000000 /* longer than expected */
@@ -363,7 +363,7 @@ struct ed {
363struct td { 363struct td {
364 void *data; /* a pointer to the data buffer */ 364 void *data; /* a pointer to the data buffer */
365 unsigned int len; /* length of the data to be submitted */ 365 unsigned int len; /* length of the data to be submitted */
366 unsigned int actual_len; /* actual bytes transfered on this td */ 366 unsigned int actual_len; /* actual bytes transferred on this td */
367 enum fhci_ta_type type; /* transaction type */ 367 enum fhci_ta_type type; /* transaction type */
368 u8 toggle; /* toggle for next trans. within this TD */ 368 u8 toggle; /* toggle for next trans. within this TD */
369 u16 iso_index; /* ISO transaction index */ 369 u16 iso_index; /* ISO transaction index */
diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
new file mode 100644
index 000000000000..79a66d622f9c
--- /dev/null
+++ b/drivers/usb/host/fsl-mph-dr-of.c
@@ -0,0 +1,313 @@
1/*
2 * Setup platform devices needed by the Freescale multi-port host
3 * and/or dual-role USB controller modules based on the description
4 * in flat device tree.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/platform_device.h>
14#include <linux/fsl_devices.h>
15#include <linux/err.h>
16#include <linux/io.h>
17#include <linux/of_platform.h>
18#include <linux/clk.h>
19
20struct fsl_usb2_dev_data {
21 char *dr_mode; /* controller mode */
22 char *drivers[3]; /* drivers to instantiate for this mode */
23 enum fsl_usb2_operating_modes op_mode; /* operating mode */
24};
25
26struct fsl_usb2_dev_data dr_mode_data[] __devinitdata = {
27 {
28 .dr_mode = "host",
29 .drivers = { "fsl-ehci", NULL, NULL, },
30 .op_mode = FSL_USB2_DR_HOST,
31 },
32 {
33 .dr_mode = "otg",
34 .drivers = { "fsl-usb2-otg", "fsl-ehci", "fsl-usb2-udc", },
35 .op_mode = FSL_USB2_DR_OTG,
36 },
37 {
38 .dr_mode = "peripheral",
39 .drivers = { "fsl-usb2-udc", NULL, NULL, },
40 .op_mode = FSL_USB2_DR_DEVICE,
41 },
42};
43
44struct fsl_usb2_dev_data * __devinit get_dr_mode_data(struct device_node *np)
45{
46 const unsigned char *prop;
47 int i;
48
49 prop = of_get_property(np, "dr_mode", NULL);
50 if (prop) {
51 for (i = 0; i < ARRAY_SIZE(dr_mode_data); i++) {
52 if (!strcmp(prop, dr_mode_data[i].dr_mode))
53 return &dr_mode_data[i];
54 }
55 }
56 pr_warn("%s: Invalid 'dr_mode' property, fallback to host mode\n",
57 np->full_name);
58 return &dr_mode_data[0]; /* mode not specified, use host */
59}
60
61static enum fsl_usb2_phy_modes __devinit determine_usb_phy(const char *phy_type)
62{
63 if (!phy_type)
64 return FSL_USB2_PHY_NONE;
65 if (!strcasecmp(phy_type, "ulpi"))
66 return FSL_USB2_PHY_ULPI;
67 if (!strcasecmp(phy_type, "utmi"))
68 return FSL_USB2_PHY_UTMI;
69 if (!strcasecmp(phy_type, "utmi_wide"))
70 return FSL_USB2_PHY_UTMI_WIDE;
71 if (!strcasecmp(phy_type, "serial"))
72 return FSL_USB2_PHY_SERIAL;
73
74 return FSL_USB2_PHY_NONE;
75}
76
77struct platform_device * __devinit fsl_usb2_device_register(
78 struct platform_device *ofdev,
79 struct fsl_usb2_platform_data *pdata,
80 const char *name, int id)
81{
82 struct platform_device *pdev;
83 const struct resource *res = ofdev->resource;
84 unsigned int num = ofdev->num_resources;
85 int retval;
86
87 pdev = platform_device_alloc(name, id);
88 if (!pdev) {
89 retval = -ENOMEM;
90 goto error;
91 }
92
93 pdev->dev.parent = &ofdev->dev;
94
95 pdev->dev.coherent_dma_mask = ofdev->dev.coherent_dma_mask;
96 pdev->dev.dma_mask = &pdev->archdata.dma_mask;
97 *pdev->dev.dma_mask = *ofdev->dev.dma_mask;
98
99 retval = platform_device_add_data(pdev, pdata, sizeof(*pdata));
100 if (retval)
101 goto error;
102
103 if (num) {
104 retval = platform_device_add_resources(pdev, res, num);
105 if (retval)
106 goto error;
107 }
108
109 retval = platform_device_add(pdev);
110 if (retval)
111 goto error;
112
113 return pdev;
114
115error:
116 platform_device_put(pdev);
117 return ERR_PTR(retval);
118}
119
120static const struct of_device_id fsl_usb2_mph_dr_of_match[];
121
122static int __devinit fsl_usb2_mph_dr_of_probe(struct platform_device *ofdev)
123{
124 struct device_node *np = ofdev->dev.of_node;
125 struct platform_device *usb_dev;
126 struct fsl_usb2_platform_data data, *pdata;
127 struct fsl_usb2_dev_data *dev_data;
128 const struct of_device_id *match;
129 const unsigned char *prop;
130 static unsigned int idx;
131 int i;
132
133 if (!of_device_is_available(np))
134 return -ENODEV;
135
136 match = of_match_device(fsl_usb2_mph_dr_of_match, &ofdev->dev);
137 if (!match)
138 return -ENODEV;
139
140 pdata = &data;
141 if (match->data)
142 memcpy(pdata, match->data, sizeof(data));
143 else
144 memset(pdata, 0, sizeof(data));
145
146 dev_data = get_dr_mode_data(np);
147
148 if (of_device_is_compatible(np, "fsl-usb2-mph")) {
149 if (of_get_property(np, "port0", NULL))
150 pdata->port_enables |= FSL_USB2_PORT0_ENABLED;
151
152 if (of_get_property(np, "port1", NULL))
153 pdata->port_enables |= FSL_USB2_PORT1_ENABLED;
154
155 pdata->operating_mode = FSL_USB2_MPH_HOST;
156 } else {
157 if (of_get_property(np, "fsl,invert-drvvbus", NULL))
158 pdata->invert_drvvbus = 1;
159
160 if (of_get_property(np, "fsl,invert-pwr-fault", NULL))
161 pdata->invert_pwr_fault = 1;
162
163 /* setup mode selected in the device tree */
164 pdata->operating_mode = dev_data->op_mode;
165 }
166
167 prop = of_get_property(np, "phy_type", NULL);
168 pdata->phy_mode = determine_usb_phy(prop);
169
170 for (i = 0; i < ARRAY_SIZE(dev_data->drivers); i++) {
171 if (!dev_data->drivers[i])
172 continue;
173 usb_dev = fsl_usb2_device_register(ofdev, pdata,
174 dev_data->drivers[i], idx);
175 if (IS_ERR(usb_dev)) {
176 dev_err(&ofdev->dev, "Can't register usb device\n");
177 return PTR_ERR(usb_dev);
178 }
179 }
180 idx++;
181 return 0;
182}
183
184static int __devexit __unregister_subdev(struct device *dev, void *d)
185{
186 platform_device_unregister(to_platform_device(dev));
187 return 0;
188}
189
190static int __devexit fsl_usb2_mph_dr_of_remove(struct platform_device *ofdev)
191{
192 device_for_each_child(&ofdev->dev, NULL, __unregister_subdev);
193 return 0;
194}
195
196#ifdef CONFIG_PPC_MPC512x
197
198#define USBGENCTRL 0x200 /* NOTE: big endian */
199#define GC_WU_INT_CLR (1 << 5) /* Wakeup int clear */
200#define GC_ULPI_SEL (1 << 4) /* ULPI i/f select (usb0 only)*/
201#define GC_PPP (1 << 3) /* Inv. Port Power Polarity */
202#define GC_PFP (1 << 2) /* Inv. Power Fault Polarity */
203#define GC_WU_ULPI_EN (1 << 1) /* Wakeup on ULPI event */
204#define GC_WU_IE (1 << 1) /* Wakeup interrupt enable */
205
206#define ISIPHYCTRL 0x204 /* NOTE: big endian */
207#define PHYCTRL_PHYE (1 << 4) /* On-chip UTMI PHY enable */
208#define PHYCTRL_BSENH (1 << 3) /* Bit Stuff Enable High */
209#define PHYCTRL_BSEN (1 << 2) /* Bit Stuff Enable */
210#define PHYCTRL_LSFE (1 << 1) /* Line State Filter Enable */
211#define PHYCTRL_PXE (1 << 0) /* PHY oscillator enable */
212
213int fsl_usb2_mpc5121_init(struct platform_device *pdev)
214{
215 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
216 struct clk *clk;
217 char clk_name[10];
218 int base, clk_num;
219
220 base = pdev->resource->start & 0xf000;
221 if (base == 0x3000)
222 clk_num = 1;
223 else if (base == 0x4000)
224 clk_num = 2;
225 else
226 return -ENODEV;
227
228 snprintf(clk_name, sizeof(clk_name), "usb%d_clk", clk_num);
229 clk = clk_get(&pdev->dev, clk_name);
230 if (IS_ERR(clk)) {
231 dev_err(&pdev->dev, "failed to get clk\n");
232 return PTR_ERR(clk);
233 }
234
235 clk_enable(clk);
236 pdata->clk = clk;
237
238 if (pdata->phy_mode == FSL_USB2_PHY_UTMI_WIDE) {
239 u32 reg = 0;
240
241 if (pdata->invert_drvvbus)
242 reg |= GC_PPP;
243
244 if (pdata->invert_pwr_fault)
245 reg |= GC_PFP;
246
247 out_be32(pdata->regs + ISIPHYCTRL, PHYCTRL_PHYE | PHYCTRL_PXE);
248 out_be32(pdata->regs + USBGENCTRL, reg);
249 }
250 return 0;
251}
252
253static void fsl_usb2_mpc5121_exit(struct platform_device *pdev)
254{
255 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
256
257 pdata->regs = NULL;
258
259 if (pdata->clk) {
260 clk_disable(pdata->clk);
261 clk_put(pdata->clk);
262 }
263}
264
265static struct fsl_usb2_platform_data fsl_usb2_mpc5121_pd = {
266 .big_endian_desc = 1,
267 .big_endian_mmio = 1,
268 .es = 1,
269 .have_sysif_regs = 0,
270 .le_setup_buf = 1,
271 .init = fsl_usb2_mpc5121_init,
272 .exit = fsl_usb2_mpc5121_exit,
273};
274#endif /* CONFIG_PPC_MPC512x */
275
276static struct fsl_usb2_platform_data fsl_usb2_mpc8xxx_pd = {
277 .have_sysif_regs = 1,
278};
279
280static const struct of_device_id fsl_usb2_mph_dr_of_match[] = {
281 { .compatible = "fsl-usb2-mph", .data = &fsl_usb2_mpc8xxx_pd, },
282 { .compatible = "fsl-usb2-dr", .data = &fsl_usb2_mpc8xxx_pd, },
283#ifdef CONFIG_PPC_MPC512x
284 { .compatible = "fsl,mpc5121-usb2-dr", .data = &fsl_usb2_mpc5121_pd, },
285#endif
286 {},
287};
288
289static struct platform_driver fsl_usb2_mph_dr_driver = {
290 .driver = {
291 .name = "fsl-usb2-mph-dr",
292 .owner = THIS_MODULE,
293 .of_match_table = fsl_usb2_mph_dr_of_match,
294 },
295 .probe = fsl_usb2_mph_dr_of_probe,
296 .remove = __devexit_p(fsl_usb2_mph_dr_of_remove),
297};
298
299static int __init fsl_usb2_mph_dr_init(void)
300{
301 return platform_driver_register(&fsl_usb2_mph_dr_driver);
302}
303module_init(fsl_usb2_mph_dr_init);
304
305static void __exit fsl_usb2_mph_dr_exit(void)
306{
307 platform_driver_unregister(&fsl_usb2_mph_dr_driver);
308}
309module_exit(fsl_usb2_mph_dr_exit);
310
311MODULE_DESCRIPTION("FSL MPH DR OF devices driver");
312MODULE_AUTHOR("Anatolij Gustschin <agust@denx.de>");
313MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/imx21-dbg.c b/drivers/usb/host/imx21-dbg.c
index 512f647448ca..6d7533427163 100644
--- a/drivers/usb/host/imx21-dbg.c
+++ b/drivers/usb/host/imx21-dbg.c
@@ -384,7 +384,7 @@ static void debug_isoc_show_one(struct seq_file *s,
384 seq_printf(s, "%s %d:\n" 384 seq_printf(s, "%s %d:\n"
385 "cc=0X%02X\n" 385 "cc=0X%02X\n"
386 "scheduled frame %d (%d)\n" 386 "scheduled frame %d (%d)\n"
387 "submittted frame %d (%d)\n" 387 "submitted frame %d (%d)\n"
388 "completed frame %d (%d)\n" 388 "completed frame %d (%d)\n"
389 "requested length=%d\n" 389 "requested length=%d\n"
390 "completed length=%d\n\n", 390 "completed length=%d\n\n",
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index 3e5630369c31..af05718bdc73 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -27,8 +27,8 @@
27 * * 32 transfer descriptors (called ETDs) 27 * * 32 transfer descriptors (called ETDs)
28 * * 4Kb of Data memory 28 * * 4Kb of Data memory
29 * 29 *
30 * The data memory is shared between the host and fuction controlers 30 * The data memory is shared between the host and function controllers
31 * (but this driver only supports the host controler) 31 * (but this driver only supports the host controller)
32 * 32 *
33 * So setting up a transfer involves: 33 * So setting up a transfer involves:
34 * * Allocating a ETD 34 * * Allocating a ETD
@@ -57,6 +57,7 @@
57#include <linux/slab.h> 57#include <linux/slab.h>
58#include <linux/usb.h> 58#include <linux/usb.h>
59#include <linux/usb/hcd.h> 59#include <linux/usb/hcd.h>
60#include <linux/dma-mapping.h>
60 61
61#include "imx21-hcd.h" 62#include "imx21-hcd.h"
62 63
@@ -136,9 +137,18 @@ static int imx21_hc_get_frame(struct usb_hcd *hcd)
136 return wrap_frame(readl(imx21->regs + USBH_FRMNUB)); 137 return wrap_frame(readl(imx21->regs + USBH_FRMNUB));
137} 138}
138 139
140static inline bool unsuitable_for_dma(dma_addr_t addr)
141{
142 return (addr & 3) != 0;
143}
139 144
140#include "imx21-dbg.c" 145#include "imx21-dbg.c"
141 146
147static void nonisoc_urb_completed_for_etd(
148 struct imx21 *imx21, struct etd_priv *etd, int status);
149static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb);
150static void free_dmem(struct imx21 *imx21, struct etd_priv *etd);
151
142/* =========================================== */ 152/* =========================================== */
143/* ETD management */ 153/* ETD management */
144/* =========================================== */ 154/* =========================================== */
@@ -185,7 +195,8 @@ static void reset_etd(struct imx21 *imx21, int num)
185 etd_writel(imx21, num, i, 0); 195 etd_writel(imx21, num, i, 0);
186 etd->urb = NULL; 196 etd->urb = NULL;
187 etd->ep = NULL; 197 etd->ep = NULL;
188 etd->td = NULL;; 198 etd->td = NULL;
199 etd->bounce_buffer = NULL;
189} 200}
190 201
191static void free_etd(struct imx21 *imx21, int num) 202static void free_etd(struct imx21 *imx21, int num)
@@ -221,26 +232,94 @@ static void setup_etd_dword0(struct imx21 *imx21,
221 ((u32) maxpacket << DW0_MAXPKTSIZ)); 232 ((u32) maxpacket << DW0_MAXPKTSIZ));
222} 233}
223 234
224static void activate_etd(struct imx21 *imx21, 235/**
225 int etd_num, dma_addr_t dma, u8 dir) 236 * Copy buffer to data controller data memory.
237 * We cannot use memcpy_toio() because the hardware requires 32bit writes
238 */
239static void copy_to_dmem(
240 struct imx21 *imx21, int dmem_offset, void *src, int count)
241{
242 void __iomem *dmem = imx21->regs + USBOTG_DMEM + dmem_offset;
243 u32 word = 0;
244 u8 *p = src;
245 int byte = 0;
246 int i;
247
248 for (i = 0; i < count; i++) {
249 byte = i % 4;
250 word += (*p++ << (byte * 8));
251 if (byte == 3) {
252 writel(word, dmem);
253 dmem += 4;
254 word = 0;
255 }
256 }
257
258 if (count && byte != 3)
259 writel(word, dmem);
260}
261
262static void activate_etd(struct imx21 *imx21, int etd_num, u8 dir)
226{ 263{
227 u32 etd_mask = 1 << etd_num; 264 u32 etd_mask = 1 << etd_num;
228 struct etd_priv *etd = &imx21->etd[etd_num]; 265 struct etd_priv *etd = &imx21->etd[etd_num];
229 266
267 if (etd->dma_handle && unsuitable_for_dma(etd->dma_handle)) {
268 /* For non aligned isoc the condition below is always true */
269 if (etd->len <= etd->dmem_size) {
270 /* Fits into data memory, use PIO */
271 if (dir != TD_DIR_IN) {
272 copy_to_dmem(imx21,
273 etd->dmem_offset,
274 etd->cpu_buffer, etd->len);
275 }
276 etd->dma_handle = 0;
277
278 } else {
279 /* Too big for data memory, use bounce buffer */
280 enum dma_data_direction dmadir;
281
282 if (dir == TD_DIR_IN) {
283 dmadir = DMA_FROM_DEVICE;
284 etd->bounce_buffer = kmalloc(etd->len,
285 GFP_ATOMIC);
286 } else {
287 dmadir = DMA_TO_DEVICE;
288 etd->bounce_buffer = kmemdup(etd->cpu_buffer,
289 etd->len,
290 GFP_ATOMIC);
291 }
292 if (!etd->bounce_buffer) {
293 dev_err(imx21->dev, "failed bounce alloc\n");
294 goto err_bounce_alloc;
295 }
296
297 etd->dma_handle =
298 dma_map_single(imx21->dev,
299 etd->bounce_buffer,
300 etd->len,
301 dmadir);
302 if (dma_mapping_error(imx21->dev, etd->dma_handle)) {
303 dev_err(imx21->dev, "failed bounce map\n");
304 goto err_bounce_map;
305 }
306 }
307 }
308
230 clear_toggle_bit(imx21, USBH_ETDDONESTAT, etd_mask); 309 clear_toggle_bit(imx21, USBH_ETDDONESTAT, etd_mask);
231 set_register_bits(imx21, USBH_ETDDONEEN, etd_mask); 310 set_register_bits(imx21, USBH_ETDDONEEN, etd_mask);
232 clear_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask); 311 clear_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask);
233 clear_toggle_bit(imx21, USBH_YFILLSTAT, etd_mask); 312 clear_toggle_bit(imx21, USBH_YFILLSTAT, etd_mask);
234 313
235 if (dma) { 314 if (etd->dma_handle) {
236 set_register_bits(imx21, USB_ETDDMACHANLCLR, etd_mask); 315 set_register_bits(imx21, USB_ETDDMACHANLCLR, etd_mask);
237 clear_toggle_bit(imx21, USBH_XBUFSTAT, etd_mask); 316 clear_toggle_bit(imx21, USBH_XBUFSTAT, etd_mask);
238 clear_toggle_bit(imx21, USBH_YBUFSTAT, etd_mask); 317 clear_toggle_bit(imx21, USBH_YBUFSTAT, etd_mask);
239 writel(dma, imx21->regs + USB_ETDSMSA(etd_num)); 318 writel(etd->dma_handle, imx21->regs + USB_ETDSMSA(etd_num));
240 set_register_bits(imx21, USB_ETDDMAEN, etd_mask); 319 set_register_bits(imx21, USB_ETDDMAEN, etd_mask);
241 } else { 320 } else {
242 if (dir != TD_DIR_IN) { 321 if (dir != TD_DIR_IN) {
243 /* need to set for ZLP */ 322 /* need to set for ZLP and PIO */
244 set_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask); 323 set_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask);
245 set_toggle_bit(imx21, USBH_YFILLSTAT, etd_mask); 324 set_toggle_bit(imx21, USBH_YFILLSTAT, etd_mask);
246 } 325 }
@@ -263,6 +342,14 @@ static void activate_etd(struct imx21 *imx21,
263 342
264 etd->active_count = 1; 343 etd->active_count = 1;
265 writel(etd_mask, imx21->regs + USBH_ETDENSET); 344 writel(etd_mask, imx21->regs + USBH_ETDENSET);
345 return;
346
347err_bounce_map:
348 kfree(etd->bounce_buffer);
349
350err_bounce_alloc:
351 free_dmem(imx21, etd);
352 nonisoc_urb_completed_for_etd(imx21, etd, -ENOMEM);
266} 353}
267 354
268/* =========================================== */ 355/* =========================================== */
@@ -323,16 +410,23 @@ static void activate_queued_etd(struct imx21 *imx21,
323 etd_writel(imx21, etd_num, 1, 410 etd_writel(imx21, etd_num, 1,
324 ((dmem_offset + maxpacket) << DW1_YBUFSRTAD) | dmem_offset); 411 ((dmem_offset + maxpacket) << DW1_YBUFSRTAD) | dmem_offset);
325 412
413 etd->dmem_offset = dmem_offset;
326 urb_priv->active = 1; 414 urb_priv->active = 1;
327 activate_etd(imx21, etd_num, etd->dma_handle, dir); 415 activate_etd(imx21, etd_num, dir);
328} 416}
329 417
330static void free_dmem(struct imx21 *imx21, int offset) 418static void free_dmem(struct imx21 *imx21, struct etd_priv *etd)
331{ 419{
332 struct imx21_dmem_area *area; 420 struct imx21_dmem_area *area;
333 struct etd_priv *etd, *tmp; 421 struct etd_priv *tmp;
334 int found = 0; 422 int found = 0;
423 int offset;
335 424
425 if (!etd->dmem_size)
426 return;
427 etd->dmem_size = 0;
428
429 offset = etd->dmem_offset;
336 list_for_each_entry(area, &imx21->dmem_list, list) { 430 list_for_each_entry(area, &imx21->dmem_list, list) {
337 if (area->offset == offset) { 431 if (area->offset == offset) {
338 debug_dmem_freed(imx21, area->size); 432 debug_dmem_freed(imx21, area->size);
@@ -378,20 +472,23 @@ static void free_epdmem(struct imx21 *imx21, struct usb_host_endpoint *ep)
378/* =========================================== */ 472/* =========================================== */
379/* End handling */ 473/* End handling */
380/* =========================================== */ 474/* =========================================== */
381static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb);
382 475
383/* Endpoint now idle - release it's ETD(s) or asssign to queued request */ 476/* Endpoint now idle - release it's ETD(s) or asssign to queued request */
384static void ep_idle(struct imx21 *imx21, struct ep_priv *ep_priv) 477static void ep_idle(struct imx21 *imx21, struct ep_priv *ep_priv)
385{ 478{
386 int etd_num;
387 int i; 479 int i;
388 480
389 for (i = 0; i < NUM_ISO_ETDS; i++) { 481 for (i = 0; i < NUM_ISO_ETDS; i++) {
390 etd_num = ep_priv->etd[i]; 482 int etd_num = ep_priv->etd[i];
483 struct etd_priv *etd;
391 if (etd_num < 0) 484 if (etd_num < 0)
392 continue; 485 continue;
393 486
487 etd = &imx21->etd[etd_num];
394 ep_priv->etd[i] = -1; 488 ep_priv->etd[i] = -1;
489
490 free_dmem(imx21, etd); /* for isoc */
491
395 if (list_empty(&imx21->queue_for_etd)) { 492 if (list_empty(&imx21->queue_for_etd)) {
396 free_etd(imx21, etd_num); 493 free_etd(imx21, etd_num);
397 continue; 494 continue;
@@ -437,6 +534,24 @@ __acquires(imx21->lock)
437 ep_idle(imx21, ep_priv); 534 ep_idle(imx21, ep_priv);
438} 535}
439 536
537static void nonisoc_urb_completed_for_etd(
538 struct imx21 *imx21, struct etd_priv *etd, int status)
539{
540 struct usb_host_endpoint *ep = etd->ep;
541
542 urb_done(imx21->hcd, etd->urb, status);
543 etd->urb = NULL;
544
545 if (!list_empty(&ep->urb_list)) {
546 struct urb *urb = list_first_entry(
547 &ep->urb_list, struct urb, urb_list);
548
549 dev_vdbg(imx21->dev, "next URB %p\n", urb);
550 schedule_nonisoc_etd(imx21, urb);
551 }
552}
553
554
440/* =========================================== */ 555/* =========================================== */
441/* ISOC Handling ... */ 556/* ISOC Handling ... */
442/* =========================================== */ 557/* =========================================== */
@@ -489,6 +604,8 @@ too_late:
489 etd->ep = td->ep; 604 etd->ep = td->ep;
490 etd->urb = td->urb; 605 etd->urb = td->urb;
491 etd->len = td->len; 606 etd->len = td->len;
607 etd->dma_handle = td->dma_handle;
608 etd->cpu_buffer = td->cpu_buffer;
492 609
493 debug_isoc_submitted(imx21, cur_frame, td); 610 debug_isoc_submitted(imx21, cur_frame, td);
494 611
@@ -502,16 +619,17 @@ too_late:
502 (TD_NOTACCESSED << DW3_COMPCODE0) | 619 (TD_NOTACCESSED << DW3_COMPCODE0) |
503 (td->len << DW3_PKTLEN0)); 620 (td->len << DW3_PKTLEN0));
504 621
505 activate_etd(imx21, etd_num, td->data, dir); 622 activate_etd(imx21, etd_num, dir);
506 } 623 }
507} 624}
508 625
509static void isoc_etd_done(struct usb_hcd *hcd, struct urb *urb, int etd_num) 626static void isoc_etd_done(struct usb_hcd *hcd, int etd_num)
510{ 627{
511 struct imx21 *imx21 = hcd_to_imx21(hcd); 628 struct imx21 *imx21 = hcd_to_imx21(hcd);
512 int etd_mask = 1 << etd_num; 629 int etd_mask = 1 << etd_num;
513 struct urb_priv *urb_priv = urb->hcpriv;
514 struct etd_priv *etd = imx21->etd + etd_num; 630 struct etd_priv *etd = imx21->etd + etd_num;
631 struct urb *urb = etd->urb;
632 struct urb_priv *urb_priv = urb->hcpriv;
515 struct td *td = etd->td; 633 struct td *td = etd->td;
516 struct usb_host_endpoint *ep = etd->ep; 634 struct usb_host_endpoint *ep = etd->ep;
517 int isoc_index = td->isoc_index; 635 int isoc_index = td->isoc_index;
@@ -545,8 +663,13 @@ static void isoc_etd_done(struct usb_hcd *hcd, struct urb *urb, int etd_num)
545 bytes_xfrd, td->len, urb, etd_num, isoc_index); 663 bytes_xfrd, td->len, urb, etd_num, isoc_index);
546 } 664 }
547 665
548 if (dir_in) 666 if (dir_in) {
549 clear_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask); 667 clear_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask);
668 if (!etd->dma_handle)
669 memcpy_fromio(etd->cpu_buffer,
670 imx21->regs + USBOTG_DMEM + etd->dmem_offset,
671 bytes_xfrd);
672 }
550 673
551 urb->actual_length += bytes_xfrd; 674 urb->actual_length += bytes_xfrd;
552 urb->iso_frame_desc[isoc_index].actual_length = bytes_xfrd; 675 urb->iso_frame_desc[isoc_index].actual_length = bytes_xfrd;
@@ -569,30 +692,43 @@ static struct ep_priv *alloc_isoc_ep(
569 int i; 692 int i;
570 693
571 ep_priv = kzalloc(sizeof(struct ep_priv), GFP_ATOMIC); 694 ep_priv = kzalloc(sizeof(struct ep_priv), GFP_ATOMIC);
572 if (ep_priv == NULL) 695 if (!ep_priv)
573 return NULL; 696 return NULL;
574 697
575 /* Allocate the ETDs */ 698 for (i = 0; i < NUM_ISO_ETDS; i++)
576 for (i = 0; i < NUM_ISO_ETDS; i++) { 699 ep_priv->etd[i] = -1;
577 ep_priv->etd[i] = alloc_etd(imx21);
578 if (ep_priv->etd[i] < 0) {
579 int j;
580 dev_err(imx21->dev, "isoc: Couldn't allocate etd\n");
581 for (j = 0; j < i; j++)
582 free_etd(imx21, ep_priv->etd[j]);
583 goto alloc_etd_failed;
584 }
585 imx21->etd[ep_priv->etd[i]].ep = ep;
586 }
587 700
588 INIT_LIST_HEAD(&ep_priv->td_list); 701 INIT_LIST_HEAD(&ep_priv->td_list);
589 ep_priv->ep = ep; 702 ep_priv->ep = ep;
590 ep->hcpriv = ep_priv; 703 ep->hcpriv = ep_priv;
591 return ep_priv; 704 return ep_priv;
705}
706
707static int alloc_isoc_etds(struct imx21 *imx21, struct ep_priv *ep_priv)
708{
709 int i, j;
710 int etd_num;
711
712 /* Allocate the ETDs if required */
713 for (i = 0; i < NUM_ISO_ETDS; i++) {
714 if (ep_priv->etd[i] < 0) {
715 etd_num = alloc_etd(imx21);
716 if (etd_num < 0)
717 goto alloc_etd_failed;
718
719 ep_priv->etd[i] = etd_num;
720 imx21->etd[etd_num].ep = ep_priv->ep;
721 }
722 }
723 return 0;
592 724
593alloc_etd_failed: 725alloc_etd_failed:
594 kfree(ep_priv); 726 dev_err(imx21->dev, "isoc: Couldn't allocate etd\n");
595 return NULL; 727 for (j = 0; j < i; j++) {
728 free_etd(imx21, ep_priv->etd[j]);
729 ep_priv->etd[j] = -1;
730 }
731 return -ENOMEM;
596} 732}
597 733
598static int imx21_hc_urb_enqueue_isoc(struct usb_hcd *hcd, 734static int imx21_hc_urb_enqueue_isoc(struct usb_hcd *hcd,
@@ -632,6 +768,10 @@ static int imx21_hc_urb_enqueue_isoc(struct usb_hcd *hcd,
632 ep_priv = ep->hcpriv; 768 ep_priv = ep->hcpriv;
633 } 769 }
634 770
771 ret = alloc_isoc_etds(imx21, ep_priv);
772 if (ret)
773 goto alloc_etd_failed;
774
635 ret = usb_hcd_link_urb_to_ep(hcd, urb); 775 ret = usb_hcd_link_urb_to_ep(hcd, urb);
636 if (ret) 776 if (ret)
637 goto link_failed; 777 goto link_failed;
@@ -688,12 +828,14 @@ static int imx21_hc_urb_enqueue_isoc(struct usb_hcd *hcd,
688 /* set up transfers */ 828 /* set up transfers */
689 td = urb_priv->isoc_td; 829 td = urb_priv->isoc_td;
690 for (i = 0; i < urb->number_of_packets; i++, td++) { 830 for (i = 0; i < urb->number_of_packets; i++, td++) {
831 unsigned int offset = urb->iso_frame_desc[i].offset;
691 td->ep = ep; 832 td->ep = ep;
692 td->urb = urb; 833 td->urb = urb;
693 td->len = urb->iso_frame_desc[i].length; 834 td->len = urb->iso_frame_desc[i].length;
694 td->isoc_index = i; 835 td->isoc_index = i;
695 td->frame = wrap_frame(urb->start_frame + urb->interval * i); 836 td->frame = wrap_frame(urb->start_frame + urb->interval * i);
696 td->data = urb->transfer_dma + urb->iso_frame_desc[i].offset; 837 td->dma_handle = urb->transfer_dma + offset;
838 td->cpu_buffer = urb->transfer_buffer + offset;
697 list_add_tail(&td->list, &ep_priv->td_list); 839 list_add_tail(&td->list, &ep_priv->td_list);
698 } 840 }
699 841
@@ -711,6 +853,7 @@ alloc_dmem_failed:
711 usb_hcd_unlink_urb_from_ep(hcd, urb); 853 usb_hcd_unlink_urb_from_ep(hcd, urb);
712 854
713link_failed: 855link_failed:
856alloc_etd_failed:
714alloc_ep_failed: 857alloc_ep_failed:
715 spin_unlock_irqrestore(&imx21->lock, flags); 858 spin_unlock_irqrestore(&imx21->lock, flags);
716 kfree(urb_priv->isoc_td); 859 kfree(urb_priv->isoc_td);
@@ -734,9 +877,7 @@ static void dequeue_isoc_urb(struct imx21 *imx21,
734 struct etd_priv *etd = imx21->etd + etd_num; 877 struct etd_priv *etd = imx21->etd + etd_num;
735 878
736 reset_etd(imx21, etd_num); 879 reset_etd(imx21, etd_num);
737 if (etd->dmem_size) 880 free_dmem(imx21, etd);
738 free_dmem(imx21, etd->dmem_offset);
739 etd->dmem_size = 0;
740 } 881 }
741 } 882 }
742 } 883 }
@@ -761,7 +902,6 @@ static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb)
761 int state = urb_priv->state; 902 int state = urb_priv->state;
762 int etd_num = ep_priv->etd[0]; 903 int etd_num = ep_priv->etd[0];
763 struct etd_priv *etd; 904 struct etd_priv *etd;
764 int dmem_offset;
765 u32 count; 905 u32 count;
766 u16 etd_buf_size; 906 u16 etd_buf_size;
767 u16 maxpacket; 907 u16 maxpacket;
@@ -786,13 +926,16 @@ static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb)
786 if (usb_pipecontrol(pipe) && (state != US_CTRL_DATA)) { 926 if (usb_pipecontrol(pipe) && (state != US_CTRL_DATA)) {
787 if (state == US_CTRL_SETUP) { 927 if (state == US_CTRL_SETUP) {
788 dir = TD_DIR_SETUP; 928 dir = TD_DIR_SETUP;
929 if (unsuitable_for_dma(urb->setup_dma))
930 usb_hcd_unmap_urb_setup_for_dma(imx21->hcd,
931 urb);
789 etd->dma_handle = urb->setup_dma; 932 etd->dma_handle = urb->setup_dma;
933 etd->cpu_buffer = urb->setup_packet;
790 bufround = 0; 934 bufround = 0;
791 count = 8; 935 count = 8;
792 datatoggle = TD_TOGGLE_DATA0; 936 datatoggle = TD_TOGGLE_DATA0;
793 } else { /* US_CTRL_ACK */ 937 } else { /* US_CTRL_ACK */
794 dir = usb_pipeout(pipe) ? TD_DIR_IN : TD_DIR_OUT; 938 dir = usb_pipeout(pipe) ? TD_DIR_IN : TD_DIR_OUT;
795 etd->dma_handle = urb->transfer_dma;
796 bufround = 0; 939 bufround = 0;
797 count = 0; 940 count = 0;
798 datatoggle = TD_TOGGLE_DATA1; 941 datatoggle = TD_TOGGLE_DATA1;
@@ -800,7 +943,11 @@ static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb)
800 } else { 943 } else {
801 dir = usb_pipeout(pipe) ? TD_DIR_OUT : TD_DIR_IN; 944 dir = usb_pipeout(pipe) ? TD_DIR_OUT : TD_DIR_IN;
802 bufround = (dir == TD_DIR_IN) ? 1 : 0; 945 bufround = (dir == TD_DIR_IN) ? 1 : 0;
946 if (unsuitable_for_dma(urb->transfer_dma))
947 usb_hcd_unmap_urb_for_dma(imx21->hcd, urb);
948
803 etd->dma_handle = urb->transfer_dma; 949 etd->dma_handle = urb->transfer_dma;
950 etd->cpu_buffer = urb->transfer_buffer;
804 if (usb_pipebulk(pipe) && (state == US_BULK0)) 951 if (usb_pipebulk(pipe) && (state == US_BULK0))
805 count = 0; 952 count = 0;
806 else 953 else
@@ -855,8 +1002,8 @@ static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb)
855 1002
856 /* allocate x and y buffer space at once */ 1003 /* allocate x and y buffer space at once */
857 etd->dmem_size = (count > maxpacket) ? maxpacket * 2 : maxpacket; 1004 etd->dmem_size = (count > maxpacket) ? maxpacket * 2 : maxpacket;
858 dmem_offset = alloc_dmem(imx21, etd->dmem_size, urb_priv->ep); 1005 etd->dmem_offset = alloc_dmem(imx21, etd->dmem_size, urb_priv->ep);
859 if (dmem_offset < 0) { 1006 if (etd->dmem_offset < 0) {
860 /* Setup everything we can in HW and update when we get DMEM */ 1007 /* Setup everything we can in HW and update when we get DMEM */
861 etd_writel(imx21, etd_num, 1, (u32)maxpacket << 16); 1008 etd_writel(imx21, etd_num, 1, (u32)maxpacket << 16);
862 1009
@@ -867,26 +1014,26 @@ static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb)
867 } 1014 }
868 1015
869 etd_writel(imx21, etd_num, 1, 1016 etd_writel(imx21, etd_num, 1,
870 (((u32) dmem_offset + (u32) maxpacket) << DW1_YBUFSRTAD) | 1017 (((u32) etd->dmem_offset + (u32) maxpacket) << DW1_YBUFSRTAD) |
871 (u32) dmem_offset); 1018 (u32) etd->dmem_offset);
872 1019
873 urb_priv->active = 1; 1020 urb_priv->active = 1;
874 1021
875 /* enable the ETD to kick off transfer */ 1022 /* enable the ETD to kick off transfer */
876 dev_vdbg(imx21->dev, "Activating etd %d for %d bytes %s\n", 1023 dev_vdbg(imx21->dev, "Activating etd %d for %d bytes %s\n",
877 etd_num, count, dir != TD_DIR_IN ? "out" : "in"); 1024 etd_num, count, dir != TD_DIR_IN ? "out" : "in");
878 activate_etd(imx21, etd_num, etd->dma_handle, dir); 1025 activate_etd(imx21, etd_num, dir);
879 1026
880} 1027}
881 1028
882static void nonisoc_etd_done(struct usb_hcd *hcd, struct urb *urb, int etd_num) 1029static void nonisoc_etd_done(struct usb_hcd *hcd, int etd_num)
883{ 1030{
884 struct imx21 *imx21 = hcd_to_imx21(hcd); 1031 struct imx21 *imx21 = hcd_to_imx21(hcd);
885 struct etd_priv *etd = &imx21->etd[etd_num]; 1032 struct etd_priv *etd = &imx21->etd[etd_num];
1033 struct urb *urb = etd->urb;
886 u32 etd_mask = 1 << etd_num; 1034 u32 etd_mask = 1 << etd_num;
887 struct urb_priv *urb_priv = urb->hcpriv; 1035 struct urb_priv *urb_priv = urb->hcpriv;
888 int dir; 1036 int dir;
889 u16 xbufaddr;
890 int cc; 1037 int cc;
891 u32 bytes_xfrd; 1038 u32 bytes_xfrd;
892 int etd_done; 1039 int etd_done;
@@ -894,7 +1041,6 @@ static void nonisoc_etd_done(struct usb_hcd *hcd, struct urb *urb, int etd_num)
894 disactivate_etd(imx21, etd_num); 1041 disactivate_etd(imx21, etd_num);
895 1042
896 dir = (etd_readl(imx21, etd_num, 0) >> DW0_DIRECT) & 0x3; 1043 dir = (etd_readl(imx21, etd_num, 0) >> DW0_DIRECT) & 0x3;
897 xbufaddr = etd_readl(imx21, etd_num, 1) & 0xffff;
898 cc = (etd_readl(imx21, etd_num, 2) >> DW2_COMPCODE) & 0xf; 1044 cc = (etd_readl(imx21, etd_num, 2) >> DW2_COMPCODE) & 0xf;
899 bytes_xfrd = etd->len - (etd_readl(imx21, etd_num, 3) & 0x1fffff); 1045 bytes_xfrd = etd->len - (etd_readl(imx21, etd_num, 3) & 0x1fffff);
900 1046
@@ -906,8 +1052,21 @@ static void nonisoc_etd_done(struct usb_hcd *hcd, struct urb *urb, int etd_num)
906 if (dir == TD_DIR_IN) { 1052 if (dir == TD_DIR_IN) {
907 clear_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask); 1053 clear_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask);
908 clear_toggle_bit(imx21, USBH_YFILLSTAT, etd_mask); 1054 clear_toggle_bit(imx21, USBH_YFILLSTAT, etd_mask);
1055
1056 if (etd->bounce_buffer) {
1057 memcpy(etd->cpu_buffer, etd->bounce_buffer, bytes_xfrd);
1058 dma_unmap_single(imx21->dev,
1059 etd->dma_handle, etd->len, DMA_FROM_DEVICE);
1060 } else if (!etd->dma_handle && bytes_xfrd) {/* PIO */
1061 memcpy_fromio(etd->cpu_buffer,
1062 imx21->regs + USBOTG_DMEM + etd->dmem_offset,
1063 bytes_xfrd);
1064 }
909 } 1065 }
910 free_dmem(imx21, xbufaddr); 1066
1067 kfree(etd->bounce_buffer);
1068 etd->bounce_buffer = NULL;
1069 free_dmem(imx21, etd);
911 1070
912 urb->error_count = 0; 1071 urb->error_count = 0;
913 if (!(urb->transfer_flags & URB_SHORT_NOT_OK) 1072 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)
@@ -964,24 +1123,15 @@ static void nonisoc_etd_done(struct usb_hcd *hcd, struct urb *urb, int etd_num)
964 break; 1123 break;
965 } 1124 }
966 1125
967 if (!etd_done) { 1126 if (etd_done)
1127 nonisoc_urb_completed_for_etd(imx21, etd, cc_to_error[cc]);
1128 else {
968 dev_vdbg(imx21->dev, "next state=%d\n", urb_priv->state); 1129 dev_vdbg(imx21->dev, "next state=%d\n", urb_priv->state);
969 schedule_nonisoc_etd(imx21, urb); 1130 schedule_nonisoc_etd(imx21, urb);
970 } else {
971 struct usb_host_endpoint *ep = urb->ep;
972
973 urb_done(hcd, urb, cc_to_error[cc]);
974 etd->urb = NULL;
975
976 if (!list_empty(&ep->urb_list)) {
977 urb = list_first_entry(&ep->urb_list,
978 struct urb, urb_list);
979 dev_vdbg(imx21->dev, "next URB %p\n", urb);
980 schedule_nonisoc_etd(imx21, urb);
981 }
982 } 1131 }
983} 1132}
984 1133
1134
985static struct ep_priv *alloc_ep(void) 1135static struct ep_priv *alloc_ep(void)
986{ 1136{
987 int i; 1137 int i;
@@ -1007,7 +1157,6 @@ static int imx21_hc_urb_enqueue(struct usb_hcd *hcd,
1007 struct etd_priv *etd; 1157 struct etd_priv *etd;
1008 int ret; 1158 int ret;
1009 unsigned long flags; 1159 unsigned long flags;
1010 int new_ep = 0;
1011 1160
1012 dev_vdbg(imx21->dev, 1161 dev_vdbg(imx21->dev,
1013 "enqueue urb=%p ep=%p len=%d " 1162 "enqueue urb=%p ep=%p len=%d "
@@ -1035,7 +1184,6 @@ static int imx21_hc_urb_enqueue(struct usb_hcd *hcd,
1035 } 1184 }
1036 ep->hcpriv = ep_priv; 1185 ep->hcpriv = ep_priv;
1037 ep_priv->ep = ep; 1186 ep_priv->ep = ep;
1038 new_ep = 1;
1039 } 1187 }
1040 1188
1041 ret = usb_hcd_link_urb_to_ep(hcd, urb); 1189 ret = usb_hcd_link_urb_to_ep(hcd, urb);
@@ -1124,9 +1272,13 @@ static int imx21_hc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1124 } else if (urb_priv->active) { 1272 } else if (urb_priv->active) {
1125 int etd_num = ep_priv->etd[0]; 1273 int etd_num = ep_priv->etd[0];
1126 if (etd_num != -1) { 1274 if (etd_num != -1) {
1275 struct etd_priv *etd = &imx21->etd[etd_num];
1276
1127 disactivate_etd(imx21, etd_num); 1277 disactivate_etd(imx21, etd_num);
1128 free_dmem(imx21, etd_readl(imx21, etd_num, 1) & 0xffff); 1278 free_dmem(imx21, etd);
1129 imx21->etd[etd_num].urb = NULL; 1279 etd->urb = NULL;
1280 kfree(etd->bounce_buffer);
1281 etd->bounce_buffer = NULL;
1130 } 1282 }
1131 } 1283 }
1132 1284
@@ -1171,7 +1323,7 @@ static void process_etds(struct usb_hcd *hcd, struct imx21 *imx21, int sof)
1171 * (and hence no interrupt occurs). 1323 * (and hence no interrupt occurs).
1172 * This causes the transfer in question to hang. 1324 * This causes the transfer in question to hang.
1173 * The kludge below checks for this condition at each SOF and processes any 1325 * The kludge below checks for this condition at each SOF and processes any
1174 * blocked ETDs (after an arbitary 10 frame wait) 1326 * blocked ETDs (after an arbitrary 10 frame wait)
1175 * 1327 *
1176 * With a single active transfer the usbtest test suite will run for days 1328 * With a single active transfer the usbtest test suite will run for days
1177 * without the kludge. 1329 * without the kludge.
@@ -1226,9 +1378,9 @@ static void process_etds(struct usb_hcd *hcd, struct imx21 *imx21, int sof)
1226 } 1378 }
1227 1379
1228 if (usb_pipeisoc(etd->urb->pipe)) 1380 if (usb_pipeisoc(etd->urb->pipe))
1229 isoc_etd_done(hcd, etd->urb, etd_num); 1381 isoc_etd_done(hcd, etd_num);
1230 else 1382 else
1231 nonisoc_etd_done(hcd, etd->urb, etd_num); 1383 nonisoc_etd_done(hcd, etd_num);
1232 } 1384 }
1233 1385
1234 /* only enable SOF interrupt if it may be needed for the kludge */ 1386 /* only enable SOF interrupt if it may be needed for the kludge */
@@ -1320,8 +1472,8 @@ static int get_hub_descriptor(struct usb_hcd *hcd,
1320 0x0010 | /* No over current protection */ 1472 0x0010 | /* No over current protection */
1321 0); 1473 0);
1322 1474
1323 desc->bitmap[0] = 1 << 1; 1475 desc->u.hs.DeviceRemovable[0] = 1 << 1;
1324 desc->bitmap[1] = ~0; 1476 desc->u.hs.DeviceRemovable[1] = ~0;
1325 return 0; 1477 return 0;
1326} 1478}
1327 1479
@@ -1507,7 +1659,7 @@ static int imx21_hc_reset(struct usb_hcd *hcd)
1507 1659
1508 spin_lock_irqsave(&imx21->lock, flags); 1660 spin_lock_irqsave(&imx21->lock, flags);
1509 1661
1510 /* Reset the Host controler modules */ 1662 /* Reset the Host controller modules */
1511 writel(USBOTG_RST_RSTCTRL | USBOTG_RST_RSTRH | 1663 writel(USBOTG_RST_RSTCTRL | USBOTG_RST_RSTRH |
1512 USBOTG_RST_RSTHSIE | USBOTG_RST_RSTHC, 1664 USBOTG_RST_RSTHSIE | USBOTG_RST_RSTHC,
1513 imx21->regs + USBOTG_RST_CTRL); 1665 imx21->regs + USBOTG_RST_CTRL);
@@ -1696,6 +1848,7 @@ static int imx21_probe(struct platform_device *pdev)
1696 } 1848 }
1697 1849
1698 imx21 = hcd_to_imx21(hcd); 1850 imx21 = hcd_to_imx21(hcd);
1851 imx21->hcd = hcd;
1699 imx21->dev = &pdev->dev; 1852 imx21->dev = &pdev->dev;
1700 imx21->pdata = pdev->dev.platform_data; 1853 imx21->pdata = pdev->dev.platform_data;
1701 if (!imx21->pdata) 1854 if (!imx21->pdata)
@@ -1754,7 +1907,7 @@ failed_clock_set:
1754failed_clock_get: 1907failed_clock_get:
1755 iounmap(imx21->regs); 1908 iounmap(imx21->regs);
1756failed_ioremap: 1909failed_ioremap:
1757 release_mem_region(res->start, res->end - res->start); 1910 release_mem_region(res->start, resource_size(res));
1758failed_request_mem: 1911failed_request_mem:
1759 remove_debug_files(imx21); 1912 remove_debug_files(imx21);
1760 usb_put_hcd(hcd); 1913 usb_put_hcd(hcd);
diff --git a/drivers/usb/host/imx21-hcd.h b/drivers/usb/host/imx21-hcd.h
index 1b0d913780a5..87b29fd971b4 100644
--- a/drivers/usb/host/imx21-hcd.h
+++ b/drivers/usb/host/imx21-hcd.h
@@ -250,6 +250,7 @@
250#define USBCTRL_USB_BYP (1 << 2) 250#define USBCTRL_USB_BYP (1 << 2)
251#define USBCTRL_HOST1_TXEN_OE (1 << 1) 251#define USBCTRL_HOST1_TXEN_OE (1 << 1)
252 252
253#define USBOTG_DMEM 0x1000
253 254
254/* Values in TD blocks */ 255/* Values in TD blocks */
255#define TD_DIR_SETUP 0 256#define TD_DIR_SETUP 0
@@ -346,8 +347,8 @@ struct td {
346 struct list_head list; 347 struct list_head list;
347 struct urb *urb; 348 struct urb *urb;
348 struct usb_host_endpoint *ep; 349 struct usb_host_endpoint *ep;
349 dma_addr_t data; 350 dma_addr_t dma_handle;
350 unsigned long buf_addr; 351 void *cpu_buffer;
351 int len; 352 int len;
352 int frame; 353 int frame;
353 int isoc_index; 354 int isoc_index;
@@ -360,6 +361,8 @@ struct etd_priv {
360 struct td *td; 361 struct td *td;
361 struct list_head queue; 362 struct list_head queue;
362 dma_addr_t dma_handle; 363 dma_addr_t dma_handle;
364 void *cpu_buffer;
365 void *bounce_buffer;
363 int alloc; 366 int alloc;
364 int len; 367 int len;
365 int dmem_size; 368 int dmem_size;
@@ -412,6 +415,7 @@ struct debug_isoc_trace {
412struct imx21 { 415struct imx21 {
413 spinlock_t lock; 416 spinlock_t lock;
414 struct device *dev; 417 struct device *dev;
418 struct usb_hcd *hcd;
415 struct mx21_usbh_platform_data *pdata; 419 struct mx21_usbh_platform_data *pdata;
416 struct list_head dmem_list; 420 struct list_head dmem_list;
417 struct list_head queue_for_etd; /* eps queued due to etd shortage */ 421 struct list_head queue_for_etd; /* eps queued due to etd shortage */
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index d9e82123de2a..baae4ccd16ac 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -612,6 +612,7 @@ static irqreturn_t isp116x_irq(struct usb_hcd *hcd)
612 /* IRQ's are off, we do no DMA, 612 /* IRQ's are off, we do no DMA,
613 perfectly ready to die ... */ 613 perfectly ready to die ... */
614 hcd->state = HC_STATE_HALT; 614 hcd->state = HC_STATE_HALT;
615 usb_hc_died(hcd);
615 ret = IRQ_HANDLED; 616 ret = IRQ_HANDLED;
616 goto done; 617 goto done;
617 } 618 }
@@ -951,9 +952,9 @@ static void isp116x_hub_descriptor(struct isp116x *isp116x,
951 /* Power switching, device type, overcurrent. */ 952 /* Power switching, device type, overcurrent. */
952 desc->wHubCharacteristics = cpu_to_le16((u16) ((reg >> 8) & 0x1f)); 953 desc->wHubCharacteristics = cpu_to_le16((u16) ((reg >> 8) & 0x1f));
953 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff); 954 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
954 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ 955 /* ports removable, and legacy PortPwrCtrlMask */
955 desc->bitmap[0] = 0; 956 desc->u.hs.DeviceRemovable[0] = 0;
956 desc->bitmap[1] = ~0; 957 desc->u.hs.DeviceRemovable[1] = ~0;
957} 958}
958 959
959/* Perform reset of a given port. 960/* Perform reset of a given port.
@@ -1557,8 +1558,6 @@ static int isp116x_remove(struct platform_device *pdev)
1557 return 0; 1558 return 0;
1558} 1559}
1559 1560
1560#define resource_len(r) (((r)->end - (r)->start) + 1)
1561
1562static int __devinit isp116x_probe(struct platform_device *pdev) 1561static int __devinit isp116x_probe(struct platform_device *pdev)
1563{ 1562{
1564 struct usb_hcd *hcd; 1563 struct usb_hcd *hcd;
@@ -1597,7 +1596,7 @@ static int __devinit isp116x_probe(struct platform_device *pdev)
1597 ret = -EBUSY; 1596 ret = -EBUSY;
1598 goto err1; 1597 goto err1;
1599 } 1598 }
1600 addr_reg = ioremap(addr->start, resource_len(addr)); 1599 addr_reg = ioremap(addr->start, resource_size(addr));
1601 if (addr_reg == NULL) { 1600 if (addr_reg == NULL) {
1602 ret = -ENOMEM; 1601 ret = -ENOMEM;
1603 goto err2; 1602 goto err2;
@@ -1606,7 +1605,7 @@ static int __devinit isp116x_probe(struct platform_device *pdev)
1606 ret = -EBUSY; 1605 ret = -EBUSY;
1607 goto err3; 1606 goto err3;
1608 } 1607 }
1609 data_reg = ioremap(data->start, resource_len(data)); 1608 data_reg = ioremap(data->start, resource_size(data));
1610 if (data_reg == NULL) { 1609 if (data_reg == NULL) {
1611 ret = -ENOMEM; 1610 ret = -ENOMEM;
1612 goto err4; 1611 goto err4;
diff --git a/drivers/usb/host/isp116x.h b/drivers/usb/host/isp116x.h
index 12db961acdfb..9a2c400e6090 100644
--- a/drivers/usb/host/isp116x.h
+++ b/drivers/usb/host/isp116x.h
@@ -13,7 +13,7 @@
13 13
14/* Full speed: max # of bytes to transfer for a single urb 14/* Full speed: max # of bytes to transfer for a single urb
15 at a time must be < 1024 && must be multiple of 64. 15 at a time must be < 1024 && must be multiple of 64.
16 832 allows transfering 4kiB within 5 frames. */ 16 832 allows transferring 4kiB within 5 frames. */
17#define MAX_TRANSFER_SIZE_FULLSPEED 832 17#define MAX_TRANSFER_SIZE_FULLSPEED 832
18 18
19/* Low speed: there is no reason to schedule in very big 19/* Low speed: there is no reason to schedule in very big
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index 0587ad4ce5c2..9c37dad3e816 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -70,7 +70,6 @@
70#include <linux/ioport.h> 70#include <linux/ioport.h>
71#include <linux/sched.h> 71#include <linux/sched.h>
72#include <linux/slab.h> 72#include <linux/slab.h>
73#include <linux/smp_lock.h>
74#include <linux/errno.h> 73#include <linux/errno.h>
75#include <linux/init.h> 74#include <linux/init.h>
76#include <linux/list.h> 75#include <linux/list.h>
@@ -82,6 +81,7 @@
82#include <linux/pm.h> 81#include <linux/pm.h>
83#include <linux/io.h> 82#include <linux/io.h>
84#include <linux/bitmap.h> 83#include <linux/bitmap.h>
84#include <linux/prefetch.h>
85 85
86#include <asm/irq.h> 86#include <asm/irq.h>
87#include <asm/system.h> 87#include <asm/system.h>
@@ -227,7 +227,6 @@ static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
227 227
228static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1362_ep *ep) 228static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1362_ep *ep)
229{ 229{
230 int index = ep->ptd_index;
231 int last = ep->ptd_index + ep->num_ptds; 230 int last = ep->ptd_index + ep->num_ptds;
232 231
233 if (last > epq->buf_count) 232 if (last > epq->buf_count)
@@ -237,10 +236,8 @@ static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1
237 epq->buf_map, epq->skip_map); 236 epq->buf_map, epq->skip_map);
238 BUG_ON(last > epq->buf_count); 237 BUG_ON(last > epq->buf_count);
239 238
240 for (; index < last; index++) { 239 bitmap_clear(&epq->buf_map, ep->ptd_index, ep->num_ptds);
241 __clear_bit(index, &epq->buf_map); 240 bitmap_set(&epq->skip_map, ep->ptd_index, ep->num_ptds);
242 __set_bit(index, &epq->skip_map);
243 }
244 epq->buf_avail += ep->num_ptds; 241 epq->buf_avail += ep->num_ptds;
245 epq->ptd_count--; 242 epq->ptd_count--;
246 243
@@ -550,7 +547,7 @@ static void postproc_ep(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep)
550 if (usb_pipecontrol(urb->pipe)) { 547 if (usb_pipecontrol(urb->pipe)) {
551 ep->nextpid = USB_PID_ACK; 548 ep->nextpid = USB_PID_ACK;
552 /* save the data underrun error code for later and 549 /* save the data underrun error code for later and
553 * procede with the status stage 550 * proceed with the status stage
554 */ 551 */
555 urb->actual_length += PTD_GET_COUNT(ptd); 552 urb->actual_length += PTD_GET_COUNT(ptd);
556 BUG_ON(urb->actual_length > urb->transfer_buffer_length); 553 BUG_ON(urb->actual_length > urb->transfer_buffer_length);
@@ -1556,9 +1553,9 @@ static void isp1362_hub_descriptor(struct isp1362_hcd *isp1362_hcd,
1556 desc->wHubCharacteristics = cpu_to_le16((reg >> 8) & 0x1f); 1553 desc->wHubCharacteristics = cpu_to_le16((reg >> 8) & 0x1f);
1557 DBG(0, "%s: hubcharacteristics = %02x\n", __func__, cpu_to_le16((reg >> 8) & 0x1f)); 1554 DBG(0, "%s: hubcharacteristics = %02x\n", __func__, cpu_to_le16((reg >> 8) & 0x1f));
1558 desc->bPwrOn2PwrGood = (reg >> 24) & 0xff; 1555 desc->bPwrOn2PwrGood = (reg >> 24) & 0xff;
1559 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ 1556 /* ports removable, and legacy PortPwrCtrlMask */
1560 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1; 1557 desc->u.hs.DeviceRemovable[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
1561 desc->bitmap[1] = ~0; 1558 desc->u.hs.DeviceRemovable[1] = ~0;
1562 1559
1563 DBG(3, "%s: exit\n", __func__); 1560 DBG(3, "%s: exit\n", __func__);
1564} 1561}
@@ -1676,13 +1673,6 @@ static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1676 switch (wValue) { 1673 switch (wValue) {
1677 case USB_PORT_FEAT_SUSPEND: 1674 case USB_PORT_FEAT_SUSPEND:
1678 _DBG(0, "USB_PORT_FEAT_SUSPEND\n"); 1675 _DBG(0, "USB_PORT_FEAT_SUSPEND\n");
1679#ifdef CONFIG_USB_OTG
1680 if (ohci->hcd.self.otg_port == (wIndex + 1) &&
1681 ohci->hcd.self.b_hnp_enable) {
1682 start_hnp(ohci);
1683 break;
1684 }
1685#endif
1686 spin_lock_irqsave(&isp1362_hcd->lock, flags); 1676 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1687 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PSS); 1677 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PSS);
1688 isp1362_hcd->rhport[wIndex] = 1678 isp1362_hcd->rhport[wIndex] =
@@ -2656,8 +2646,6 @@ static struct hc_driver isp1362_hc_driver = {
2656 2646
2657/*-------------------------------------------------------------------------*/ 2647/*-------------------------------------------------------------------------*/
2658 2648
2659#define resource_len(r) (((r)->end - (r)->start) + 1)
2660
2661static int __devexit isp1362_remove(struct platform_device *pdev) 2649static int __devexit isp1362_remove(struct platform_device *pdev)
2662{ 2650{
2663 struct usb_hcd *hcd = platform_get_drvdata(pdev); 2651 struct usb_hcd *hcd = platform_get_drvdata(pdev);
@@ -2679,12 +2667,12 @@ static int __devexit isp1362_remove(struct platform_device *pdev)
2679 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 2667 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2680 DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start); 2668 DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start);
2681 if (res) 2669 if (res)
2682 release_mem_region(res->start, resource_len(res)); 2670 release_mem_region(res->start, resource_size(res));
2683 2671
2684 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2672 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2685 DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start); 2673 DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start);
2686 if (res) 2674 if (res)
2687 release_mem_region(res->start, resource_len(res)); 2675 release_mem_region(res->start, resource_size(res));
2688 2676
2689 DBG(0, "%s: put_hcd\n", __func__); 2677 DBG(0, "%s: put_hcd\n", __func__);
2690 usb_put_hcd(hcd); 2678 usb_put_hcd(hcd);
@@ -2693,7 +2681,7 @@ static int __devexit isp1362_remove(struct platform_device *pdev)
2693 return 0; 2681 return 0;
2694} 2682}
2695 2683
2696static int __init isp1362_probe(struct platform_device *pdev) 2684static int __devinit isp1362_probe(struct platform_device *pdev)
2697{ 2685{
2698 struct usb_hcd *hcd; 2686 struct usb_hcd *hcd;
2699 struct isp1362_hcd *isp1362_hcd; 2687 struct isp1362_hcd *isp1362_hcd;
@@ -2730,21 +2718,21 @@ static int __init isp1362_probe(struct platform_device *pdev)
2730 goto err1; 2718 goto err1;
2731 } 2719 }
2732 2720
2733 if (!request_mem_region(addr->start, resource_len(addr), hcd_name)) { 2721 if (!request_mem_region(addr->start, resource_size(addr), hcd_name)) {
2734 retval = -EBUSY; 2722 retval = -EBUSY;
2735 goto err1; 2723 goto err1;
2736 } 2724 }
2737 addr_reg = ioremap(addr->start, resource_len(addr)); 2725 addr_reg = ioremap(addr->start, resource_size(addr));
2738 if (addr_reg == NULL) { 2726 if (addr_reg == NULL) {
2739 retval = -ENOMEM; 2727 retval = -ENOMEM;
2740 goto err2; 2728 goto err2;
2741 } 2729 }
2742 2730
2743 if (!request_mem_region(data->start, resource_len(data), hcd_name)) { 2731 if (!request_mem_region(data->start, resource_size(data), hcd_name)) {
2744 retval = -EBUSY; 2732 retval = -EBUSY;
2745 goto err3; 2733 goto err3;
2746 } 2734 }
2747 data_reg = ioremap(data->start, resource_len(data)); 2735 data_reg = ioremap(data->start, resource_size(data));
2748 if (data_reg == NULL) { 2736 if (data_reg == NULL) {
2749 retval = -ENOMEM; 2737 retval = -ENOMEM;
2750 goto err4; 2738 goto err4;
@@ -2802,13 +2790,13 @@ static int __init isp1362_probe(struct platform_device *pdev)
2802 iounmap(data_reg); 2790 iounmap(data_reg);
2803 err4: 2791 err4:
2804 DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)data->start); 2792 DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)data->start);
2805 release_mem_region(data->start, resource_len(data)); 2793 release_mem_region(data->start, resource_size(data));
2806 err3: 2794 err3:
2807 DBG(0, "%s: Unmapping addr_reg @ %p\n", __func__, addr_reg); 2795 DBG(0, "%s: Unmapping addr_reg @ %p\n", __func__, addr_reg);
2808 iounmap(addr_reg); 2796 iounmap(addr_reg);
2809 err2: 2797 err2:
2810 DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)addr->start); 2798 DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)addr->start);
2811 release_mem_region(addr->start, resource_len(addr)); 2799 release_mem_region(addr->start, resource_size(addr));
2812 err1: 2800 err1:
2813 pr_err("%s: init error, %d\n", __func__, retval); 2801 pr_err("%s: init error, %d\n", __func__, retval);
2814 2802
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index bdba8c5d844a..55d3d5859ac5 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -8,6 +8,8 @@
8 * 8 *
9 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de> 9 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
10 * 10 *
11 * (c) 2011 Arvid Brodin <arvid.brodin@enea.com>
12 *
11 */ 13 */
12#include <linux/module.h> 14#include <linux/module.h>
13#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -26,13 +28,18 @@
26 28
27static struct kmem_cache *qtd_cachep; 29static struct kmem_cache *qtd_cachep;
28static struct kmem_cache *qh_cachep; 30static struct kmem_cache *qh_cachep;
31static struct kmem_cache *urb_listitem_cachep;
29 32
30struct isp1760_hcd { 33struct isp1760_hcd {
31 u32 hcs_params; 34 u32 hcs_params;
32 spinlock_t lock; 35 spinlock_t lock;
33 struct inter_packet_info atl_ints[32]; 36 struct slotinfo atl_slots[32];
34 struct inter_packet_info int_ints[32]; 37 int atl_done_map;
38 struct slotinfo int_slots[32];
39 int int_done_map;
35 struct memory_chunk memory_pool[BLOCKS]; 40 struct memory_chunk memory_pool[BLOCKS];
41 struct list_head controlqhs, bulkqhs, interruptqhs;
42 int active_ptds;
36 43
37 /* periodic schedule support */ 44 /* periodic schedule support */
38#define DEFAULT_I_TDPS 1024 45#define DEFAULT_I_TDPS 1024
@@ -47,10 +54,6 @@ static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd)
47{ 54{
48 return (struct isp1760_hcd *) (hcd->hcd_priv); 55 return (struct isp1760_hcd *) (hcd->hcd_priv);
49} 56}
50static inline struct usb_hcd *priv_to_hcd(struct isp1760_hcd *priv)
51{
52 return container_of((void *) priv, struct usb_hcd, hcd_priv);
53}
54 57
55/* Section 2.2 Host Controller Capability Registers */ 58/* Section 2.2 Host Controller Capability Registers */
56#define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */ 59#define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */
@@ -80,217 +83,270 @@ static inline struct usb_hcd *priv_to_hcd(struct isp1760_hcd *priv)
80#define PORT_RWC_BITS (PORT_CSC) 83#define PORT_RWC_BITS (PORT_CSC)
81 84
82struct isp1760_qtd { 85struct isp1760_qtd {
83 struct isp1760_qtd *hw_next;
84 u8 packet_type; 86 u8 packet_type;
85 u8 toggle;
86
87 void *data_buffer; 87 void *data_buffer;
88 u32 payload_addr;
89
88 /* the rest is HCD-private */ 90 /* the rest is HCD-private */
89 struct list_head qtd_list; 91 struct list_head qtd_list;
90 struct urb *urb; 92 struct urb *urb;
91 size_t length; 93 size_t length;
92 94 size_t actual_length;
93 /* isp special*/ 95
96 /* QTD_ENQUEUED: waiting for transfer (inactive) */
97 /* QTD_PAYLOAD_ALLOC: chip mem has been allocated for payload */
98 /* QTD_XFER_STARTED: valid ptd has been written to isp176x - only
99 interrupt handler may touch this qtd! */
100 /* QTD_XFER_COMPLETE: payload has been transferred successfully */
101 /* QTD_RETIRE: transfer error/abort qtd */
102#define QTD_ENQUEUED 0
103#define QTD_PAYLOAD_ALLOC 1
104#define QTD_XFER_STARTED 2
105#define QTD_XFER_COMPLETE 3
106#define QTD_RETIRE 4
94 u32 status; 107 u32 status;
95#define URB_COMPLETE_NOTIFY (1 << 0)
96#define URB_ENQUEUED (1 << 1)
97#define URB_TYPE_ATL (1 << 2)
98#define URB_TYPE_INT (1 << 3)
99}; 108};
100 109
110/* Queue head, one for each active endpoint */
101struct isp1760_qh { 111struct isp1760_qh {
102 /* first part defined by EHCI spec */ 112 struct list_head qh_list;
103 struct list_head qtd_list; 113 struct list_head qtd_list;
104 struct isp1760_hcd *priv;
105
106 /* periodic schedule info */
107 unsigned short period; /* polling interval */
108 struct usb_device *dev;
109
110 u32 toggle; 114 u32 toggle;
111 u32 ping; 115 u32 ping;
116 int slot;
112}; 117};
113 118
114#define ehci_port_speed(priv, portsc) USB_PORT_STAT_HIGH_SPEED 119struct urb_listitem {
120 struct list_head urb_list;
121 struct urb *urb;
122};
115 123
116static unsigned int isp1760_readl(__u32 __iomem *regs) 124/*
125 * Access functions for isp176x registers (addresses 0..0x03FF).
126 */
127static u32 reg_read32(void __iomem *base, u32 reg)
117{ 128{
118 return readl(regs); 129 return readl(base + reg);
119} 130}
120 131
121static void isp1760_writel(const unsigned int val, __u32 __iomem *regs) 132static void reg_write32(void __iomem *base, u32 reg, u32 val)
122{ 133{
123 writel(val, regs); 134 writel(val, base + reg);
124} 135}
125 136
126/* 137/*
127 * The next two copy via MMIO data to/from the device. memcpy_{to|from}io() 138 * Access functions for isp176x memory (offset >= 0x0400).
139 *
140 * bank_reads8() reads memory locations prefetched by an earlier write to
141 * HC_MEMORY_REG (see isp176x datasheet). Unless you want to do fancy multi-
142 * bank optimizations, you should use the more generic mem_reads8() below.
143 *
144 * For access to ptd memory, use the specialized ptd_read() and ptd_write()
145 * below.
146 *
147 * These functions copy via MMIO data to/from the device. memcpy_{to|from}io()
128 * doesn't quite work because some people have to enforce 32-bit access 148 * doesn't quite work because some people have to enforce 32-bit access
129 */ 149 */
130static void priv_read_copy(struct isp1760_hcd *priv, u32 *src, 150static void bank_reads8(void __iomem *src_base, u32 src_offset, u32 bank_addr,
131 __u32 __iomem *dst, u32 len) 151 __u32 *dst, u32 bytes)
132{ 152{
153 __u32 __iomem *src;
133 u32 val; 154 u32 val;
134 u8 *buff8; 155 __u8 *src_byteptr;
156 __u8 *dst_byteptr;
135 157
136 if (!src) { 158 src = src_base + (bank_addr | src_offset);
137 printk(KERN_ERR "ERROR: buffer: %p len: %d\n", src, len);
138 return;
139 }
140 159
141 while (len >= 4) { 160 if (src_offset < PAYLOAD_OFFSET) {
142 *src = __raw_readl(dst); 161 while (bytes >= 4) {
143 len -= 4; 162 *dst = le32_to_cpu(__raw_readl(src));
144 src++; 163 bytes -= 4;
145 dst++; 164 src++;
165 dst++;
166 }
167 } else {
168 while (bytes >= 4) {
169 *dst = __raw_readl(src);
170 bytes -= 4;
171 src++;
172 dst++;
173 }
146 } 174 }
147 175
148 if (!len) 176 if (!bytes)
149 return; 177 return;
150 178
151 /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully 179 /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully
152 * allocated. 180 * allocated.
153 */ 181 */
154 val = isp1760_readl(dst); 182 if (src_offset < PAYLOAD_OFFSET)
155 183 val = le32_to_cpu(__raw_readl(src));
156 buff8 = (u8 *)src; 184 else
157 while (len) { 185 val = __raw_readl(src);
158 186
159 *buff8 = val; 187 dst_byteptr = (void *) dst;
160 val >>= 8; 188 src_byteptr = (void *) &val;
161 len--; 189 while (bytes > 0) {
162 buff8++; 190 *dst_byteptr = *src_byteptr;
191 dst_byteptr++;
192 src_byteptr++;
193 bytes--;
163 } 194 }
164} 195}
165 196
166static void priv_write_copy(const struct isp1760_hcd *priv, const u32 *src, 197static void mem_reads8(void __iomem *src_base, u32 src_offset, void *dst,
167 __u32 __iomem *dst, u32 len) 198 u32 bytes)
168{ 199{
169 while (len >= 4) { 200 reg_write32(src_base, HC_MEMORY_REG, src_offset + ISP_BANK(0));
170 __raw_writel(*src, dst); 201 ndelay(90);
171 len -= 4; 202 bank_reads8(src_base, src_offset, ISP_BANK(0), dst, bytes);
172 src++; 203}
173 dst++; 204
205static void mem_writes8(void __iomem *dst_base, u32 dst_offset,
206 __u32 const *src, u32 bytes)
207{
208 __u32 __iomem *dst;
209
210 dst = dst_base + dst_offset;
211
212 if (dst_offset < PAYLOAD_OFFSET) {
213 while (bytes >= 4) {
214 __raw_writel(cpu_to_le32(*src), dst);
215 bytes -= 4;
216 src++;
217 dst++;
218 }
219 } else {
220 while (bytes >= 4) {
221 __raw_writel(*src, dst);
222 bytes -= 4;
223 src++;
224 dst++;
225 }
174 } 226 }
175 227
176 if (!len) 228 if (!bytes)
177 return; 229 return;
178 /* in case we have 3, 2 or 1 by left. The buffer is allocated and the 230 /* in case we have 3, 2 or 1 bytes left. The buffer is allocated and the
179 * extra bytes should not be read by the HW 231 * extra bytes should not be read by the HW.
180 */ 232 */
181 233
182 __raw_writel(*src, dst); 234 if (dst_offset < PAYLOAD_OFFSET)
235 __raw_writel(cpu_to_le32(*src), dst);
236 else
237 __raw_writel(*src, dst);
183} 238}
184 239
240/*
241 * Read and write ptds. 'ptd_offset' should be one of ISO_PTD_OFFSET,
242 * INT_PTD_OFFSET, and ATL_PTD_OFFSET. 'slot' should be less than 32.
243 */
244static void ptd_read(void __iomem *base, u32 ptd_offset, u32 slot,
245 struct ptd *ptd)
246{
247 reg_write32(base, HC_MEMORY_REG,
248 ISP_BANK(0) + ptd_offset + slot*sizeof(*ptd));
249 ndelay(90);
250 bank_reads8(base, ptd_offset + slot*sizeof(*ptd), ISP_BANK(0),
251 (void *) ptd, sizeof(*ptd));
252}
253
254static void ptd_write(void __iomem *base, u32 ptd_offset, u32 slot,
255 struct ptd *ptd)
256{
257 mem_writes8(base, ptd_offset + slot*sizeof(*ptd) + sizeof(ptd->dw0),
258 &ptd->dw1, 7*sizeof(ptd->dw1));
259 /* Make sure dw0 gets written last (after other dw's and after payload)
260 since it contains the enable bit */
261 wmb();
262 mem_writes8(base, ptd_offset + slot*sizeof(*ptd), &ptd->dw0,
263 sizeof(ptd->dw0));
264}
265
266
185/* memory management of the 60kb on the chip from 0x1000 to 0xffff */ 267/* memory management of the 60kb on the chip from 0x1000 to 0xffff */
186static void init_memory(struct isp1760_hcd *priv) 268static void init_memory(struct isp1760_hcd *priv)
187{ 269{
188 int i; 270 int i, curr;
189 u32 payload; 271 u32 payload_addr;
190 272
191 payload = 0x1000; 273 payload_addr = PAYLOAD_OFFSET;
192 for (i = 0; i < BLOCK_1_NUM; i++) { 274 for (i = 0; i < BLOCK_1_NUM; i++) {
193 priv->memory_pool[i].start = payload; 275 priv->memory_pool[i].start = payload_addr;
194 priv->memory_pool[i].size = BLOCK_1_SIZE; 276 priv->memory_pool[i].size = BLOCK_1_SIZE;
195 priv->memory_pool[i].free = 1; 277 priv->memory_pool[i].free = 1;
196 payload += priv->memory_pool[i].size; 278 payload_addr += priv->memory_pool[i].size;
197 } 279 }
198 280
199 281 curr = i;
200 for (i = BLOCK_1_NUM; i < BLOCK_1_NUM + BLOCK_2_NUM; i++) { 282 for (i = 0; i < BLOCK_2_NUM; i++) {
201 priv->memory_pool[i].start = payload; 283 priv->memory_pool[curr + i].start = payload_addr;
202 priv->memory_pool[i].size = BLOCK_2_SIZE; 284 priv->memory_pool[curr + i].size = BLOCK_2_SIZE;
203 priv->memory_pool[i].free = 1; 285 priv->memory_pool[curr + i].free = 1;
204 payload += priv->memory_pool[i].size; 286 payload_addr += priv->memory_pool[curr + i].size;
205 } 287 }
206 288
207 289 curr = i;
208 for (i = BLOCK_1_NUM + BLOCK_2_NUM; i < BLOCKS; i++) { 290 for (i = 0; i < BLOCK_3_NUM; i++) {
209 priv->memory_pool[i].start = payload; 291 priv->memory_pool[curr + i].start = payload_addr;
210 priv->memory_pool[i].size = BLOCK_3_SIZE; 292 priv->memory_pool[curr + i].size = BLOCK_3_SIZE;
211 priv->memory_pool[i].free = 1; 293 priv->memory_pool[curr + i].free = 1;
212 payload += priv->memory_pool[i].size; 294 payload_addr += priv->memory_pool[curr + i].size;
213 } 295 }
214 296
215 BUG_ON(payload - priv->memory_pool[i - 1].size > PAYLOAD_SIZE); 297 WARN_ON(payload_addr - priv->memory_pool[0].start > PAYLOAD_AREA_SIZE);
216} 298}
217 299
218static u32 alloc_mem(struct isp1760_hcd *priv, u32 size) 300static void alloc_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd)
219{ 301{
302 struct isp1760_hcd *priv = hcd_to_priv(hcd);
220 int i; 303 int i;
221 304
222 if (!size) 305 WARN_ON(qtd->payload_addr);
223 return ISP1760_NULL_POINTER; 306
307 if (!qtd->length)
308 return;
224 309
225 for (i = 0; i < BLOCKS; i++) { 310 for (i = 0; i < BLOCKS; i++) {
226 if (priv->memory_pool[i].size >= size && 311 if (priv->memory_pool[i].size >= qtd->length &&
227 priv->memory_pool[i].free) { 312 priv->memory_pool[i].free) {
228
229 priv->memory_pool[i].free = 0; 313 priv->memory_pool[i].free = 0;
230 return priv->memory_pool[i].start; 314 qtd->payload_addr = priv->memory_pool[i].start;
315 return;
231 } 316 }
232 } 317 }
233
234 printk(KERN_ERR "ISP1760 MEM: can not allocate %d bytes of memory\n",
235 size);
236 printk(KERN_ERR "Current memory map:\n");
237 for (i = 0; i < BLOCKS; i++) {
238 printk(KERN_ERR "Pool %2d size %4d status: %d\n",
239 i, priv->memory_pool[i].size,
240 priv->memory_pool[i].free);
241 }
242 /* XXX maybe -ENOMEM could be possible */
243 BUG();
244 return 0;
245} 318}
246 319
247static void free_mem(struct isp1760_hcd *priv, u32 mem) 320static void free_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd)
248{ 321{
322 struct isp1760_hcd *priv = hcd_to_priv(hcd);
249 int i; 323 int i;
250 324
251 if (mem == ISP1760_NULL_POINTER) 325 if (!qtd->payload_addr)
252 return; 326 return;
253 327
254 for (i = 0; i < BLOCKS; i++) { 328 for (i = 0; i < BLOCKS; i++) {
255 if (priv->memory_pool[i].start == mem) { 329 if (priv->memory_pool[i].start == qtd->payload_addr) {
256 330 WARN_ON(priv->memory_pool[i].free);
257 BUG_ON(priv->memory_pool[i].free);
258
259 priv->memory_pool[i].free = 1; 331 priv->memory_pool[i].free = 1;
260 return ; 332 qtd->payload_addr = 0;
333 return;
261 } 334 }
262 } 335 }
263 336
264 printk(KERN_ERR "Trying to free not-here-allocated memory :%08x\n", 337 dev_err(hcd->self.controller, "%s: Invalid pointer: %08x\n",
265 mem); 338 __func__, qtd->payload_addr);
266 BUG(); 339 WARN_ON(1);
267} 340 qtd->payload_addr = 0;
268
269static void isp1760_init_regs(struct usb_hcd *hcd)
270{
271 isp1760_writel(0, hcd->regs + HC_BUFFER_STATUS_REG);
272 isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs +
273 HC_ATL_PTD_SKIPMAP_REG);
274 isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs +
275 HC_INT_PTD_SKIPMAP_REG);
276 isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs +
277 HC_ISO_PTD_SKIPMAP_REG);
278
279 isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs +
280 HC_ATL_PTD_DONEMAP_REG);
281 isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs +
282 HC_INT_PTD_DONEMAP_REG);
283 isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs +
284 HC_ISO_PTD_DONEMAP_REG);
285} 341}
286 342
287static int handshake(struct isp1760_hcd *priv, void __iomem *ptr, 343static int handshake(struct usb_hcd *hcd, u32 reg,
288 u32 mask, u32 done, int usec) 344 u32 mask, u32 done, int usec)
289{ 345{
290 u32 result; 346 u32 result;
291 347
292 do { 348 do {
293 result = isp1760_readl(ptr); 349 result = reg_read32(hcd->regs, reg);
294 if (result == ~0) 350 if (result == ~0)
295 return -ENODEV; 351 return -ENODEV;
296 result &= mask; 352 result &= mask;
@@ -303,48 +359,43 @@ static int handshake(struct isp1760_hcd *priv, void __iomem *ptr,
303} 359}
304 360
305/* reset a non-running (STS_HALT == 1) controller */ 361/* reset a non-running (STS_HALT == 1) controller */
306static int ehci_reset(struct isp1760_hcd *priv) 362static int ehci_reset(struct usb_hcd *hcd)
307{ 363{
308 int retval; 364 int retval;
309 struct usb_hcd *hcd = priv_to_hcd(priv); 365 struct isp1760_hcd *priv = hcd_to_priv(hcd);
310 u32 command = isp1760_readl(hcd->regs + HC_USBCMD); 366
367 u32 command = reg_read32(hcd->regs, HC_USBCMD);
311 368
312 command |= CMD_RESET; 369 command |= CMD_RESET;
313 isp1760_writel(command, hcd->regs + HC_USBCMD); 370 reg_write32(hcd->regs, HC_USBCMD, command);
314 hcd->state = HC_STATE_HALT; 371 hcd->state = HC_STATE_HALT;
315 priv->next_statechange = jiffies; 372 priv->next_statechange = jiffies;
316 retval = handshake(priv, hcd->regs + HC_USBCMD, 373 retval = handshake(hcd, HC_USBCMD,
317 CMD_RESET, 0, 250 * 1000); 374 CMD_RESET, 0, 250 * 1000);
318 return retval; 375 return retval;
319} 376}
320 377
321static void qh_destroy(struct isp1760_qh *qh) 378static struct isp1760_qh *qh_alloc(gfp_t flags)
322{
323 BUG_ON(!list_empty(&qh->qtd_list));
324 kmem_cache_free(qh_cachep, qh);
325}
326
327static struct isp1760_qh *isp1760_qh_alloc(struct isp1760_hcd *priv,
328 gfp_t flags)
329{ 379{
330 struct isp1760_qh *qh; 380 struct isp1760_qh *qh;
331 381
332 qh = kmem_cache_zalloc(qh_cachep, flags); 382 qh = kmem_cache_zalloc(qh_cachep, flags);
333 if (!qh) 383 if (!qh)
334 return qh; 384 return NULL;
335 385
386 INIT_LIST_HEAD(&qh->qh_list);
336 INIT_LIST_HEAD(&qh->qtd_list); 387 INIT_LIST_HEAD(&qh->qtd_list);
337 qh->priv = priv; 388 qh->slot = -1;
389
338 return qh; 390 return qh;
339} 391}
340 392
341/* magic numbers that can affect system performance */ 393static void qh_free(struct isp1760_qh *qh)
342#define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ 394{
343#define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */ 395 WARN_ON(!list_empty(&qh->qtd_list));
344#define EHCI_TUNE_RL_TT 0 396 WARN_ON(qh->slot > -1);
345#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ 397 kmem_cache_free(qh_cachep, qh);
346#define EHCI_TUNE_MULT_TT 1 398}
347#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
348 399
349/* one-time init, only for memory state */ 400/* one-time init, only for memory state */
350static int priv_init(struct usb_hcd *hcd) 401static int priv_init(struct usb_hcd *hcd)
@@ -354,6 +405,10 @@ static int priv_init(struct usb_hcd *hcd)
354 405
355 spin_lock_init(&priv->lock); 406 spin_lock_init(&priv->lock);
356 407
408 INIT_LIST_HEAD(&priv->interruptqhs);
409 INIT_LIST_HEAD(&priv->controlqhs);
410 INIT_LIST_HEAD(&priv->bulkqhs);
411
357 /* 412 /*
358 * hw default: 1K periodic list heads, one per frame. 413 * hw default: 1K periodic list heads, one per frame.
359 * periodic_size can shrink by USBCMD update if hcc_params allows. 414 * periodic_size can shrink by USBCMD update if hcc_params allows.
@@ -361,7 +416,7 @@ static int priv_init(struct usb_hcd *hcd)
361 priv->periodic_size = DEFAULT_I_TDPS; 416 priv->periodic_size = DEFAULT_I_TDPS;
362 417
363 /* controllers may cache some of the periodic schedule ... */ 418 /* controllers may cache some of the periodic schedule ... */
364 hcc_params = isp1760_readl(hcd->regs + HC_HCCPARAMS); 419 hcc_params = reg_read32(hcd->regs, HC_HCCPARAMS);
365 /* full frame cache */ 420 /* full frame cache */
366 if (HCC_ISOC_CACHE(hcc_params)) 421 if (HCC_ISOC_CACHE(hcc_params))
367 priv->i_thresh = 8; 422 priv->i_thresh = 8;
@@ -398,46 +453,52 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
398 * Write it twice to ensure correct upper bits if switching 453 * Write it twice to ensure correct upper bits if switching
399 * to 16-bit mode. 454 * to 16-bit mode.
400 */ 455 */
401 isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL); 456 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
402 isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL); 457 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
403 458
404 isp1760_writel(0xdeadbabe, hcd->regs + HC_SCRATCH_REG); 459 reg_write32(hcd->regs, HC_SCRATCH_REG, 0xdeadbabe);
405 /* Change bus pattern */ 460 /* Change bus pattern */
406 scratch = isp1760_readl(hcd->regs + HC_CHIP_ID_REG); 461 scratch = reg_read32(hcd->regs, HC_CHIP_ID_REG);
407 scratch = isp1760_readl(hcd->regs + HC_SCRATCH_REG); 462 scratch = reg_read32(hcd->regs, HC_SCRATCH_REG);
408 if (scratch != 0xdeadbabe) { 463 if (scratch != 0xdeadbabe) {
409 printk(KERN_ERR "ISP1760: Scratch test failed.\n"); 464 dev_err(hcd->self.controller, "Scratch test failed.\n");
410 return -ENODEV; 465 return -ENODEV;
411 } 466 }
412 467
413 /* pre reset */ 468 /* pre reset */
414 isp1760_init_regs(hcd); 469 reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, 0);
470 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE);
471 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE);
472 reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE);
415 473
416 /* reset */ 474 /* reset */
417 isp1760_writel(SW_RESET_RESET_ALL, hcd->regs + HC_RESET_REG); 475 reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_ALL);
418 mdelay(100); 476 mdelay(100);
419 477
420 isp1760_writel(SW_RESET_RESET_HC, hcd->regs + HC_RESET_REG); 478 reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_HC);
421 mdelay(100); 479 mdelay(100);
422 480
423 result = ehci_reset(priv); 481 result = ehci_reset(hcd);
424 if (result) 482 if (result)
425 return result; 483 return result;
426 484
427 /* Step 11 passed */ 485 /* Step 11 passed */
428 486
429 isp1760_info(priv, "bus width: %d, oc: %s\n", 487 dev_info(hcd->self.controller, "bus width: %d, oc: %s\n",
430 (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ? 488 (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ?
431 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ? 489 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ?
432 "analog" : "digital"); 490 "analog" : "digital");
433 491
492 /* This is weird: at the first plug-in of a device there seems to be
493 one packet queued that never gets returned? */
494 priv->active_ptds = -1;
495
434 /* ATL reset */ 496 /* ATL reset */
435 isp1760_writel(hwmode | ALL_ATX_RESET, hcd->regs + HC_HW_MODE_CTRL); 497 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET);
436 mdelay(10); 498 mdelay(10);
437 isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL); 499 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
438 500
439 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_REG); 501 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, INTERRUPT_ENABLE_MASK);
440 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_ENABLE);
441 502
442 /* 503 /*
443 * PORT 1 Control register of the ISP1760 is the OTG control 504 * PORT 1 Control register of the ISP1760 is the OTG control
@@ -445,11 +506,10 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
445 * support in this driver, we use port 1 as a "normal" USB host port on 506 * support in this driver, we use port 1 as a "normal" USB host port on
446 * both chips. 507 * both chips.
447 */ 508 */
448 isp1760_writel(PORT1_POWER | PORT1_INIT2, 509 reg_write32(hcd->regs, HC_PORT1_CTRL, PORT1_POWER | PORT1_INIT2);
449 hcd->regs + HC_PORT1_CTRL);
450 mdelay(10); 510 mdelay(10);
451 511
452 priv->hcs_params = isp1760_readl(hcd->regs + HC_HCSPARAMS); 512 priv->hcs_params = reg_read32(hcd->regs, HC_HCSPARAMS);
453 513
454 return priv_init(hcd); 514 return priv_init(hcd);
455} 515}
@@ -457,25 +517,31 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
457static void isp1760_init_maps(struct usb_hcd *hcd) 517static void isp1760_init_maps(struct usb_hcd *hcd)
458{ 518{
459 /*set last maps, for iso its only 1, else 32 tds bitmap*/ 519 /*set last maps, for iso its only 1, else 32 tds bitmap*/
460 isp1760_writel(0x80000000, hcd->regs + HC_ATL_PTD_LASTPTD_REG); 520 reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000);
461 isp1760_writel(0x80000000, hcd->regs + HC_INT_PTD_LASTPTD_REG); 521 reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000);
462 isp1760_writel(0x00000001, hcd->regs + HC_ISO_PTD_LASTPTD_REG); 522 reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001);
523
524 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, 0xffffffff);
525 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, 0xffffffff);
526 reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, 0xffffffff);
527
528 reg_write32(hcd->regs, HC_BUFFER_STATUS_REG,
529 ATL_BUF_FILL | INT_BUF_FILL);
463} 530}
464 531
465static void isp1760_enable_interrupts(struct usb_hcd *hcd) 532static void isp1760_enable_interrupts(struct usb_hcd *hcd)
466{ 533{
467 isp1760_writel(0, hcd->regs + HC_ATL_IRQ_MASK_AND_REG); 534 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0);
468 isp1760_writel(0, hcd->regs + HC_ATL_IRQ_MASK_OR_REG); 535 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0xffffffff);
469 isp1760_writel(0, hcd->regs + HC_INT_IRQ_MASK_AND_REG); 536 reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0);
470 isp1760_writel(0, hcd->regs + HC_INT_IRQ_MASK_OR_REG); 537 reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0xffffffff);
471 isp1760_writel(0, hcd->regs + HC_ISO_IRQ_MASK_AND_REG); 538 reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0);
472 isp1760_writel(0xffffffff, hcd->regs + HC_ISO_IRQ_MASK_OR_REG); 539 reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff);
473 /* step 23 passed */ 540 /* step 23 passed */
474} 541}
475 542
476static int isp1760_run(struct usb_hcd *hcd) 543static int isp1760_run(struct usb_hcd *hcd)
477{ 544{
478 struct isp1760_hcd *priv = hcd_to_priv(hcd);
479 int retval; 545 int retval;
480 u32 temp; 546 u32 temp;
481 u32 command; 547 u32 command;
@@ -485,16 +551,15 @@ static int isp1760_run(struct usb_hcd *hcd)
485 551
486 hcd->state = HC_STATE_RUNNING; 552 hcd->state = HC_STATE_RUNNING;
487 isp1760_enable_interrupts(hcd); 553 isp1760_enable_interrupts(hcd);
488 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); 554 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
489 isp1760_writel(temp | HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL); 555 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN);
490 556
491 command = isp1760_readl(hcd->regs + HC_USBCMD); 557 command = reg_read32(hcd->regs, HC_USBCMD);
492 command &= ~(CMD_LRESET|CMD_RESET); 558 command &= ~(CMD_LRESET|CMD_RESET);
493 command |= CMD_RUN; 559 command |= CMD_RUN;
494 isp1760_writel(command, hcd->regs + HC_USBCMD); 560 reg_write32(hcd->regs, HC_USBCMD, command);
495 561
496 retval = handshake(priv, hcd->regs + HC_USBCMD, CMD_RUN, CMD_RUN, 562 retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, 250 * 1000);
497 250 * 1000);
498 if (retval) 563 if (retval)
499 return retval; 564 return retval;
500 565
@@ -504,17 +569,16 @@ static int isp1760_run(struct usb_hcd *hcd)
504 * the semaphore while doing so. 569 * the semaphore while doing so.
505 */ 570 */
506 down_write(&ehci_cf_port_reset_rwsem); 571 down_write(&ehci_cf_port_reset_rwsem);
507 isp1760_writel(FLAG_CF, hcd->regs + HC_CONFIGFLAG); 572 reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF);
508 573
509 retval = handshake(priv, hcd->regs + HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 574 retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000);
510 250 * 1000);
511 up_write(&ehci_cf_port_reset_rwsem); 575 up_write(&ehci_cf_port_reset_rwsem);
512 if (retval) 576 if (retval)
513 return retval; 577 return retval;
514 578
515 chipid = isp1760_readl(hcd->regs + HC_CHIP_ID_REG); 579 chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG);
516 isp1760_info(priv, "USB ISP %04x HW rev. %d started\n", chipid & 0xffff, 580 dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n",
517 chipid >> 16); 581 chipid & 0xffff, chipid >> 16);
518 582
519 /* PTD Register Init Part 2, Step 28 */ 583 /* PTD Register Init Part 2, Step 28 */
520 /* enable INTs */ 584 /* enable INTs */
@@ -532,378 +596,169 @@ static u32 base_to_chip(u32 base)
532 return ((base - 0x400) >> 3); 596 return ((base - 0x400) >> 3);
533} 597}
534 598
535static void transform_into_atl(struct isp1760_hcd *priv, struct isp1760_qh *qh, 599static int last_qtd_of_urb(struct isp1760_qtd *qtd, struct isp1760_qh *qh)
536 struct isp1760_qtd *qtd, struct urb *urb, 600{
537 u32 payload, struct ptd *ptd) 601 struct urb *urb;
602
603 if (list_is_last(&qtd->qtd_list, &qh->qtd_list))
604 return 1;
605
606 urb = qtd->urb;
607 qtd = list_entry(qtd->qtd_list.next, typeof(*qtd), qtd_list);
608 return (qtd->urb != urb);
609}
610
611/* magic numbers that can affect system performance */
612#define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
613#define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
614#define EHCI_TUNE_RL_TT 0
615#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
616#define EHCI_TUNE_MULT_TT 1
617#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
618
619static void create_ptd_atl(struct isp1760_qh *qh,
620 struct isp1760_qtd *qtd, struct ptd *ptd)
538{ 621{
539 u32 dw0;
540 u32 dw1;
541 u32 dw2;
542 u32 dw3;
543 u32 maxpacket; 622 u32 maxpacket;
544 u32 multi; 623 u32 multi;
545 u32 pid_code;
546 u32 rl = RL_COUNTER; 624 u32 rl = RL_COUNTER;
547 u32 nak = NAK_COUNTER; 625 u32 nak = NAK_COUNTER;
548 626
627 memset(ptd, 0, sizeof(*ptd));
628
549 /* according to 3.6.2, max packet len can not be > 0x400 */ 629 /* according to 3.6.2, max packet len can not be > 0x400 */
550 maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); 630 maxpacket = usb_maxpacket(qtd->urb->dev, qtd->urb->pipe,
631 usb_pipeout(qtd->urb->pipe));
551 multi = 1 + ((maxpacket >> 11) & 0x3); 632 multi = 1 + ((maxpacket >> 11) & 0x3);
552 maxpacket &= 0x7ff; 633 maxpacket &= 0x7ff;
553 634
554 /* DW0 */ 635 /* DW0 */
555 dw0 = PTD_VALID; 636 ptd->dw0 = DW0_VALID_BIT;
556 dw0 |= PTD_LENGTH(qtd->length); 637 ptd->dw0 |= TO_DW0_LENGTH(qtd->length);
557 dw0 |= PTD_MAXPACKET(maxpacket); 638 ptd->dw0 |= TO_DW0_MAXPACKET(maxpacket);
558 dw0 |= PTD_ENDPOINT(usb_pipeendpoint(urb->pipe)); 639 ptd->dw0 |= TO_DW0_ENDPOINT(usb_pipeendpoint(qtd->urb->pipe));
559 dw1 = usb_pipeendpoint(urb->pipe) >> 1;
560 640
561 /* DW1 */ 641 /* DW1 */
562 dw1 |= PTD_DEVICE_ADDR(usb_pipedevice(urb->pipe)); 642 ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1;
643 ptd->dw1 |= TO_DW1_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe));
644 ptd->dw1 |= TO_DW1_PID_TOKEN(qtd->packet_type);
563 645
564 pid_code = qtd->packet_type; 646 if (usb_pipebulk(qtd->urb->pipe))
565 dw1 |= PTD_PID_TOKEN(pid_code); 647 ptd->dw1 |= DW1_TRANS_BULK;
648 else if (usb_pipeint(qtd->urb->pipe))
649 ptd->dw1 |= DW1_TRANS_INT;
566 650
567 if (usb_pipebulk(urb->pipe)) 651 if (qtd->urb->dev->speed != USB_SPEED_HIGH) {
568 dw1 |= PTD_TRANS_BULK;
569 else if (usb_pipeint(urb->pipe))
570 dw1 |= PTD_TRANS_INT;
571
572 if (urb->dev->speed != USB_SPEED_HIGH) {
573 /* split transaction */ 652 /* split transaction */
574 653
575 dw1 |= PTD_TRANS_SPLIT; 654 ptd->dw1 |= DW1_TRANS_SPLIT;
576 if (urb->dev->speed == USB_SPEED_LOW) 655 if (qtd->urb->dev->speed == USB_SPEED_LOW)
577 dw1 |= PTD_SE_USB_LOSPEED; 656 ptd->dw1 |= DW1_SE_USB_LOSPEED;
578 657
579 dw1 |= PTD_PORT_NUM(urb->dev->ttport); 658 ptd->dw1 |= TO_DW1_PORT_NUM(qtd->urb->dev->ttport);
580 dw1 |= PTD_HUB_NUM(urb->dev->tt->hub->devnum); 659 ptd->dw1 |= TO_DW1_HUB_NUM(qtd->urb->dev->tt->hub->devnum);
581 660
582 /* SE bit for Split INT transfers */ 661 /* SE bit for Split INT transfers */
583 if (usb_pipeint(urb->pipe) && 662 if (usb_pipeint(qtd->urb->pipe) &&
584 (urb->dev->speed == USB_SPEED_LOW)) 663 (qtd->urb->dev->speed == USB_SPEED_LOW))
585 dw1 |= 2 << 16; 664 ptd->dw1 |= 2 << 16;
586 665
587 dw3 = 0;
588 rl = 0; 666 rl = 0;
589 nak = 0; 667 nak = 0;
590 } else { 668 } else {
591 dw0 |= PTD_MULTI(multi); 669 ptd->dw0 |= TO_DW0_MULTI(multi);
592 if (usb_pipecontrol(urb->pipe) || usb_pipebulk(urb->pipe)) 670 if (usb_pipecontrol(qtd->urb->pipe) ||
593 dw3 = qh->ping; 671 usb_pipebulk(qtd->urb->pipe))
594 else 672 ptd->dw3 |= TO_DW3_PING(qh->ping);
595 dw3 = 0;
596 } 673 }
597 /* DW2 */ 674 /* DW2 */
598 dw2 = 0; 675 ptd->dw2 = 0;
599 dw2 |= PTD_DATA_START_ADDR(base_to_chip(payload)); 676 ptd->dw2 |= TO_DW2_DATA_START_ADDR(base_to_chip(qtd->payload_addr));
600 dw2 |= PTD_RL_CNT(rl); 677 ptd->dw2 |= TO_DW2_RL(rl);
601 dw3 |= PTD_NAC_CNT(nak);
602 678
603 /* DW3 */ 679 /* DW3 */
604 if (usb_pipecontrol(urb->pipe)) 680 ptd->dw3 |= TO_DW3_NAKCOUNT(nak);
605 dw3 |= PTD_DATA_TOGGLE(qtd->toggle); 681 ptd->dw3 |= TO_DW3_DATA_TOGGLE(qh->toggle);
606 else 682 if (usb_pipecontrol(qtd->urb->pipe)) {
607 dw3 |= qh->toggle; 683 if (qtd->data_buffer == qtd->urb->setup_packet)
608 684 ptd->dw3 &= ~TO_DW3_DATA_TOGGLE(1);
685 else if (last_qtd_of_urb(qtd, qh))
686 ptd->dw3 |= TO_DW3_DATA_TOGGLE(1);
687 }
609 688
610 dw3 |= PTD_ACTIVE; 689 ptd->dw3 |= DW3_ACTIVE_BIT;
611 /* Cerr */ 690 /* Cerr */
612 dw3 |= PTD_CERR(ERR_COUNTER); 691 ptd->dw3 |= TO_DW3_CERR(ERR_COUNTER);
613
614 memset(ptd, 0, sizeof(*ptd));
615
616 ptd->dw0 = cpu_to_le32(dw0);
617 ptd->dw1 = cpu_to_le32(dw1);
618 ptd->dw2 = cpu_to_le32(dw2);
619 ptd->dw3 = cpu_to_le32(dw3);
620} 692}
621 693
622static void transform_add_int(struct isp1760_hcd *priv, struct isp1760_qh *qh, 694static void transform_add_int(struct isp1760_qh *qh,
623 struct isp1760_qtd *qtd, struct urb *urb, 695 struct isp1760_qtd *qtd, struct ptd *ptd)
624 u32 payload, struct ptd *ptd)
625{ 696{
626 u32 maxpacket; 697 u32 usof;
627 u32 multi;
628 u32 numberofusofs;
629 u32 i;
630 u32 usofmask, usof;
631 u32 period; 698 u32 period;
632 699
633 maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); 700 /*
634 multi = 1 + ((maxpacket >> 11) & 0x3); 701 * Most of this is guessing. ISP1761 datasheet is quite unclear, and
635 maxpacket &= 0x7ff; 702 * the algorithm from the original Philips driver code, which was
636 /* length of the data per uframe */ 703 * pretty much used in this driver before as well, is quite horrendous
637 maxpacket = multi * maxpacket; 704 * and, i believe, incorrect. The code below follows the datasheet and
638 705 * USB2.0 spec as far as I can tell, and plug/unplug seems to be much
639 numberofusofs = urb->transfer_buffer_length / maxpacket; 706 * more reliable this way (fingers crossed...).
640 if (urb->transfer_buffer_length % maxpacket) 707 */
641 numberofusofs += 1;
642
643 usofmask = 1;
644 usof = 0;
645 for (i = 0; i < numberofusofs; i++) {
646 usof |= usofmask;
647 usofmask <<= 1;
648 }
649
650 if (urb->dev->speed != USB_SPEED_HIGH) {
651 /* split */
652 ptd->dw5 = cpu_to_le32(0x1c);
653 708
654 if (qh->period >= 32) 709 if (qtd->urb->dev->speed == USB_SPEED_HIGH) {
655 period = qh->period / 2; 710 /* urb->interval is in units of microframes (1/8 ms) */
711 period = qtd->urb->interval >> 3;
712
713 if (qtd->urb->interval > 4)
714 usof = 0x01; /* One bit set =>
715 interval 1 ms * uFrame-match */
716 else if (qtd->urb->interval > 2)
717 usof = 0x22; /* Two bits set => interval 1/2 ms */
718 else if (qtd->urb->interval > 1)
719 usof = 0x55; /* Four bits set => interval 1/4 ms */
656 else 720 else
657 period = qh->period; 721 usof = 0xff; /* All bits set => interval 1/8 ms */
658
659 } else { 722 } else {
723 /* urb->interval is in units of frames (1 ms) */
724 period = qtd->urb->interval;
725 usof = 0x0f; /* Execute Start Split on any of the
726 four first uFrames */
660 727
661 if (qh->period >= 8) 728 /*
662 period = qh->period/8; 729 * First 8 bits in dw5 is uSCS and "specifies which uSOF the
663 else 730 * complete split needs to be sent. Valid only for IN." Also,
664 period = qh->period; 731 * "All bits can be set to one for every transfer." (p 82,
665 732 * ISP1761 data sheet.) 0x1c is from Philips driver. Where did
666 if (period >= 32) 733 * that number come from? 0xff seems to work fine...
667 period = 16; 734 */
668 735 /* ptd->dw5 = 0x1c; */
669 if (qh->period >= 8) { 736 ptd->dw5 = 0xff; /* Execute Complete Split on any uFrame */
670 /* millisecond period */
671 period = (period << 3);
672 } else {
673 /* usof based tranmsfers */
674 /* minimum 4 usofs */
675 usof = 0x11;
676 }
677 }
678
679 ptd->dw2 |= cpu_to_le32(period);
680 ptd->dw4 = cpu_to_le32(usof);
681}
682
683static void transform_into_int(struct isp1760_hcd *priv, struct isp1760_qh *qh,
684 struct isp1760_qtd *qtd, struct urb *urb,
685 u32 payload, struct ptd *ptd)
686{
687 transform_into_atl(priv, qh, qtd, urb, payload, ptd);
688 transform_add_int(priv, qh, qtd, urb, payload, ptd);
689}
690
691static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len,
692 u32 token)
693{
694 int count;
695
696 qtd->data_buffer = databuffer;
697 qtd->packet_type = GET_QTD_TOKEN_TYPE(token);
698 qtd->toggle = GET_DATA_TOGGLE(token);
699
700 if (len > HC_ATL_PL_SIZE)
701 count = HC_ATL_PL_SIZE;
702 else
703 count = len;
704
705 qtd->length = count;
706 return count;
707}
708
709static int check_error(struct ptd *ptd)
710{
711 int error = 0;
712 u32 dw3;
713
714 dw3 = le32_to_cpu(ptd->dw3);
715 if (dw3 & DW3_HALT_BIT) {
716 error = -EPIPE;
717
718 if (dw3 & DW3_ERROR_BIT)
719 pr_err("error bit is set in DW3\n");
720 }
721
722 if (dw3 & DW3_QTD_ACTIVE) {
723 printk(KERN_ERR "transfer active bit is set DW3\n");
724 printk(KERN_ERR "nak counter: %d, rl: %d\n", (dw3 >> 19) & 0xf,
725 (le32_to_cpu(ptd->dw2) >> 25) & 0xf);
726 }
727
728 return error;
729}
730
731static void check_int_err_status(u32 dw4)
732{
733 u32 i;
734
735 dw4 >>= 8;
736
737 for (i = 0; i < 8; i++) {
738 switch (dw4 & 0x7) {
739 case INT_UNDERRUN:
740 printk(KERN_ERR "ERROR: under run , %d\n", i);
741 break;
742
743 case INT_EXACT:
744 printk(KERN_ERR "ERROR: transaction error, %d\n", i);
745 break;
746
747 case INT_BABBLE:
748 printk(KERN_ERR "ERROR: babble error, %d\n", i);
749 break;
750 }
751 dw4 >>= 3;
752 }
753}
754
755static void enqueue_one_qtd(struct isp1760_qtd *qtd, struct isp1760_hcd *priv,
756 u32 payload)
757{
758 u32 token;
759 struct usb_hcd *hcd = priv_to_hcd(priv);
760
761 token = qtd->packet_type;
762
763 if (qtd->length && (qtd->length <= HC_ATL_PL_SIZE)) {
764 switch (token) {
765 case IN_PID:
766 break;
767 case OUT_PID:
768 case SETUP_PID:
769 priv_write_copy(priv, qtd->data_buffer,
770 hcd->regs + payload,
771 qtd->length);
772 }
773 } 737 }
774}
775
776static void enqueue_one_atl_qtd(u32 atl_regs, u32 payload,
777 struct isp1760_hcd *priv, struct isp1760_qh *qh,
778 struct urb *urb, u32 slot, struct isp1760_qtd *qtd)
779{
780 struct ptd ptd;
781 struct usb_hcd *hcd = priv_to_hcd(priv);
782
783 transform_into_atl(priv, qh, qtd, urb, payload, &ptd);
784 priv_write_copy(priv, (u32 *)&ptd, hcd->regs + atl_regs, sizeof(ptd));
785 enqueue_one_qtd(qtd, priv, payload);
786
787 priv->atl_ints[slot].urb = urb;
788 priv->atl_ints[slot].qh = qh;
789 priv->atl_ints[slot].qtd = qtd;
790 priv->atl_ints[slot].data_buffer = qtd->data_buffer;
791 priv->atl_ints[slot].payload = payload;
792 qtd->status |= URB_ENQUEUED | URB_TYPE_ATL;
793 qtd->status |= slot << 16;
794}
795
796static void enqueue_one_int_qtd(u32 int_regs, u32 payload,
797 struct isp1760_hcd *priv, struct isp1760_qh *qh,
798 struct urb *urb, u32 slot, struct isp1760_qtd *qtd)
799{
800 struct ptd ptd;
801 struct usb_hcd *hcd = priv_to_hcd(priv);
802
803 transform_into_int(priv, qh, qtd, urb, payload, &ptd);
804 priv_write_copy(priv, (u32 *)&ptd, hcd->regs + int_regs, sizeof(ptd));
805 enqueue_one_qtd(qtd, priv, payload);
806
807 priv->int_ints[slot].urb = urb;
808 priv->int_ints[slot].qh = qh;
809 priv->int_ints[slot].qtd = qtd;
810 priv->int_ints[slot].data_buffer = qtd->data_buffer;
811 priv->int_ints[slot].payload = payload;
812 qtd->status |= URB_ENQUEUED | URB_TYPE_INT;
813 qtd->status |= slot << 16;
814}
815
816static void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
817 struct isp1760_qtd *qtd)
818{
819 struct isp1760_hcd *priv = hcd_to_priv(hcd);
820 u32 skip_map, or_map;
821 u32 queue_entry;
822 u32 slot;
823 u32 atl_regs, payload;
824 u32 buffstatus;
825
826 /*
827 * When this function is called from the interrupt handler to enqueue
828 * a follow-up packet, the SKIP register gets written and read back
829 * almost immediately. With ISP1761, this register requires a delay of
830 * 195ns between a write and subsequent read (see section 15.1.1.3).
831 */
832 mmiowb();
833 ndelay(195);
834 skip_map = isp1760_readl(hcd->regs + HC_ATL_PTD_SKIPMAP_REG);
835
836 BUG_ON(!skip_map);
837 slot = __ffs(skip_map);
838 queue_entry = 1 << slot;
839
840 atl_regs = ATL_REGS_OFFSET + slot * sizeof(struct ptd);
841 738
842 payload = alloc_mem(priv, qtd->length); 739 period = period >> 1;/* Ensure equal or shorter period than requested */
740 period &= 0xf8; /* Mask off too large values and lowest unused 3 bits */
843 741
844 enqueue_one_atl_qtd(atl_regs, payload, priv, qh, qtd->urb, slot, qtd); 742 ptd->dw2 |= period;
845 743 ptd->dw4 = usof;
846 or_map = isp1760_readl(hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
847 or_map |= queue_entry;
848 isp1760_writel(or_map, hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
849
850 skip_map &= ~queue_entry;
851 isp1760_writel(skip_map, hcd->regs + HC_ATL_PTD_SKIPMAP_REG);
852
853 buffstatus = isp1760_readl(hcd->regs + HC_BUFFER_STATUS_REG);
854 buffstatus |= ATL_BUFFER;
855 isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG);
856} 744}
857 745
858static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, 746static void create_ptd_int(struct isp1760_qh *qh,
859 struct isp1760_qtd *qtd) 747 struct isp1760_qtd *qtd, struct ptd *ptd)
860{ 748{
861 struct isp1760_hcd *priv = hcd_to_priv(hcd); 749 create_ptd_atl(qh, qtd, ptd);
862 u32 skip_map, or_map; 750 transform_add_int(qh, qtd, ptd);
863 u32 queue_entry;
864 u32 slot;
865 u32 int_regs, payload;
866 u32 buffstatus;
867
868 /*
869 * When this function is called from the interrupt handler to enqueue
870 * a follow-up packet, the SKIP register gets written and read back
871 * almost immediately. With ISP1761, this register requires a delay of
872 * 195ns between a write and subsequent read (see section 15.1.1.3).
873 */
874 mmiowb();
875 ndelay(195);
876 skip_map = isp1760_readl(hcd->regs + HC_INT_PTD_SKIPMAP_REG);
877
878 BUG_ON(!skip_map);
879 slot = __ffs(skip_map);
880 queue_entry = 1 << slot;
881
882 int_regs = INT_REGS_OFFSET + slot * sizeof(struct ptd);
883
884 payload = alloc_mem(priv, qtd->length);
885
886 enqueue_one_int_qtd(int_regs, payload, priv, qh, qtd->urb, slot, qtd);
887
888 or_map = isp1760_readl(hcd->regs + HC_INT_IRQ_MASK_OR_REG);
889 or_map |= queue_entry;
890 isp1760_writel(or_map, hcd->regs + HC_INT_IRQ_MASK_OR_REG);
891
892 skip_map &= ~queue_entry;
893 isp1760_writel(skip_map, hcd->regs + HC_INT_PTD_SKIPMAP_REG);
894
895 buffstatus = isp1760_readl(hcd->regs + HC_BUFFER_STATUS_REG);
896 buffstatus |= INT_BUFFER;
897 isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG);
898} 751}
899 752
900static void isp1760_urb_done(struct isp1760_hcd *priv, struct urb *urb, int status) 753static void isp1760_urb_done(struct usb_hcd *hcd, struct urb *urb)
901__releases(priv->lock) 754__releases(priv->lock)
902__acquires(priv->lock) 755__acquires(priv->lock)
903{ 756{
757 struct isp1760_hcd *priv = hcd_to_priv(hcd);
758
904 if (!urb->unlinked) { 759 if (!urb->unlinked) {
905 if (status == -EINPROGRESS) 760 if (urb->status == -EINPROGRESS)
906 status = 0; 761 urb->status = 0;
907 } 762 }
908 763
909 if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) { 764 if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) {
@@ -915,679 +770,660 @@ __acquires(priv->lock)
915 } 770 }
916 771
917 /* complete() can reenter this HCD */ 772 /* complete() can reenter this HCD */
918 usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb); 773 usb_hcd_unlink_urb_from_ep(hcd, urb);
919 spin_unlock(&priv->lock); 774 spin_unlock(&priv->lock);
920 usb_hcd_giveback_urb(priv_to_hcd(priv), urb, status); 775 usb_hcd_giveback_urb(hcd, urb, urb->status);
921 spin_lock(&priv->lock); 776 spin_lock(&priv->lock);
922} 777}
923 778
924static void isp1760_qtd_free(struct isp1760_qtd *qtd) 779static struct isp1760_qtd *qtd_alloc(gfp_t flags, struct urb *urb,
780 u8 packet_type)
925{ 781{
926 kmem_cache_free(qtd_cachep, qtd); 782 struct isp1760_qtd *qtd;
927}
928
929static struct isp1760_qtd *clean_this_qtd(struct isp1760_qtd *qtd)
930{
931 struct isp1760_qtd *tmp_qtd;
932
933 tmp_qtd = qtd->hw_next;
934 list_del(&qtd->qtd_list);
935 isp1760_qtd_free(qtd);
936 return tmp_qtd;
937}
938 783
939/* 784 qtd = kmem_cache_zalloc(qtd_cachep, flags);
940 * Remove this QTD from the QH list and free its memory. If this QTD 785 if (!qtd)
941 * isn't the last one than remove also his successor(s). 786 return NULL;
942 * Returns the QTD which is part of an new URB and should be enqueued.
943 */
944static struct isp1760_qtd *clean_up_qtdlist(struct isp1760_qtd *qtd)
945{
946 struct isp1760_qtd *tmp_qtd;
947 int last_one;
948 787
949 do { 788 INIT_LIST_HEAD(&qtd->qtd_list);
950 tmp_qtd = qtd->hw_next; 789 qtd->urb = urb;
951 last_one = qtd->status & URB_COMPLETE_NOTIFY; 790 qtd->packet_type = packet_type;
952 list_del(&qtd->qtd_list); 791 qtd->status = QTD_ENQUEUED;
953 isp1760_qtd_free(qtd); 792 qtd->actual_length = 0;
954 qtd = tmp_qtd;
955 } while (!last_one && qtd);
956 793
957 return qtd; 794 return qtd;
958} 795}
959 796
960static void do_atl_int(struct usb_hcd *usb_hcd) 797static void qtd_free(struct isp1760_qtd *qtd)
961{ 798{
962 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); 799 WARN_ON(qtd->payload_addr);
963 u32 done_map, skip_map; 800 kmem_cache_free(qtd_cachep, qtd);
964 struct ptd ptd; 801}
965 struct urb *urb = NULL;
966 u32 atl_regs_base;
967 u32 atl_regs;
968 u32 queue_entry;
969 u32 payload;
970 u32 length;
971 u32 or_map;
972 u32 status = -EINVAL;
973 int error;
974 struct isp1760_qtd *qtd;
975 struct isp1760_qh *qh;
976 u32 rl;
977 u32 nakcount;
978
979 done_map = isp1760_readl(usb_hcd->regs +
980 HC_ATL_PTD_DONEMAP_REG);
981 skip_map = isp1760_readl(usb_hcd->regs +
982 HC_ATL_PTD_SKIPMAP_REG);
983
984 or_map = isp1760_readl(usb_hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
985 or_map &= ~done_map;
986 isp1760_writel(or_map, usb_hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
987
988 atl_regs_base = ATL_REGS_OFFSET;
989 while (done_map) {
990 u32 dw1;
991 u32 dw2;
992 u32 dw3;
993
994 status = 0;
995
996 queue_entry = __ffs(done_map);
997 done_map &= ~(1 << queue_entry);
998 skip_map |= 1 << queue_entry;
999
1000 atl_regs = atl_regs_base + queue_entry * sizeof(struct ptd);
1001
1002 urb = priv->atl_ints[queue_entry].urb;
1003 qtd = priv->atl_ints[queue_entry].qtd;
1004 qh = priv->atl_ints[queue_entry].qh;
1005 payload = priv->atl_ints[queue_entry].payload;
1006
1007 if (!qh) {
1008 printk(KERN_ERR "qh is 0\n");
1009 continue;
1010 }
1011 isp1760_writel(atl_regs + ISP_BANK(0), usb_hcd->regs +
1012 HC_MEMORY_REG);
1013 isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs +
1014 HC_MEMORY_REG);
1015 /*
1016 * write bank1 address twice to ensure the 90ns delay (time
1017 * between BANK0 write and the priv_read_copy() call is at
1018 * least 3*t_WHWL + 2*t_w11 = 3*25ns + 2*17ns = 109ns)
1019 */
1020 isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs +
1021 HC_MEMORY_REG);
1022
1023 priv_read_copy(priv, (u32 *)&ptd, usb_hcd->regs + atl_regs +
1024 ISP_BANK(0), sizeof(ptd));
1025 802
1026 dw1 = le32_to_cpu(ptd.dw1); 803static void start_bus_transfer(struct usb_hcd *hcd, u32 ptd_offset, int slot,
1027 dw2 = le32_to_cpu(ptd.dw2); 804 struct slotinfo *slots, struct isp1760_qtd *qtd,
1028 dw3 = le32_to_cpu(ptd.dw3); 805 struct isp1760_qh *qh, struct ptd *ptd)
1029 rl = (dw2 >> 25) & 0x0f; 806{
1030 nakcount = (dw3 >> 19) & 0xf; 807 struct isp1760_hcd *priv = hcd_to_priv(hcd);
808 int skip_map;
809
810 WARN_ON((slot < 0) || (slot > 31));
811 WARN_ON(qtd->length && !qtd->payload_addr);
812 WARN_ON(slots[slot].qtd);
813 WARN_ON(slots[slot].qh);
814 WARN_ON(qtd->status != QTD_PAYLOAD_ALLOC);
815
816 slots[slot].qtd = qtd;
817 slots[slot].qh = qh;
818 qh->slot = slot;
819 qtd->status = QTD_XFER_STARTED; /* Set this before writing ptd, since
820 interrupt routine may preempt and expects this value. */
821 ptd_write(hcd->regs, ptd_offset, slot, ptd);
822 priv->active_ptds++;
823
824 /* Make sure done map has not triggered from some unlinked transfer */
825 if (ptd_offset == ATL_PTD_OFFSET) {
826 priv->atl_done_map |= reg_read32(hcd->regs,
827 HC_ATL_PTD_DONEMAP_REG);
828 priv->atl_done_map &= ~(1 << qh->slot);
829
830 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
831 skip_map &= ~(1 << qh->slot);
832 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map);
833 } else {
834 priv->int_done_map |= reg_read32(hcd->regs,
835 HC_INT_PTD_DONEMAP_REG);
836 priv->int_done_map &= ~(1 << qh->slot);
1031 837
1032 /* Transfer Error, *but* active and no HALT -> reload */ 838 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
1033 if ((dw3 & DW3_ERROR_BIT) && (dw3 & DW3_QTD_ACTIVE) && 839 skip_map &= ~(1 << qh->slot);
1034 !(dw3 & DW3_HALT_BIT)) { 840 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map);
1035 841 }
1036 /* according to ppriv code, we have to 842}
1037 * reload this one if trasfered bytes != requested bytes
1038 * else act like everything went smooth..
1039 * XXX This just doesn't feel right and hasn't
1040 * triggered so far.
1041 */
1042 843
1043 length = PTD_XFERRED_LENGTH(dw3); 844static int is_short_bulk(struct isp1760_qtd *qtd)
1044 printk(KERN_ERR "Should reload now.... transfered %d " 845{
1045 "of %zu\n", length, qtd->length); 846 return (usb_pipebulk(qtd->urb->pipe) &&
1046 BUG(); 847 (qtd->actual_length < qtd->length));
1047 } 848}
1048 849
1049 if (!nakcount && (dw3 & DW3_QTD_ACTIVE)) { 850static void collect_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh,
1050 u32 buffstatus; 851 struct list_head *urb_list)
852{
853 int last_qtd;
854 struct isp1760_qtd *qtd, *qtd_next;
855 struct urb_listitem *urb_listitem;
1051 856
1052 /* 857 list_for_each_entry_safe(qtd, qtd_next, &qh->qtd_list, qtd_list) {
1053 * NAKs are handled in HW by the chip. Usually if the 858 if (qtd->status < QTD_XFER_COMPLETE)
1054 * device is not able to send data fast enough. 859 break;
1055 * This happens mostly on slower hardware.
1056 */
1057 printk(KERN_NOTICE "Reloading ptd %p/%p... qh %p read: "
1058 "%d of %zu done: %08x cur: %08x\n", qtd,
1059 urb, qh, PTD_XFERRED_LENGTH(dw3),
1060 qtd->length, done_map,
1061 (1 << queue_entry));
1062 860
1063 /* RL counter = ERR counter */ 861 if (list_is_last(&qtd->qtd_list, &qh->qtd_list))
1064 dw3 &= ~(0xf << 19); 862 last_qtd = 1;
1065 dw3 |= rl << 19; 863 else
1066 dw3 &= ~(3 << (55 - 32)); 864 last_qtd = qtd->urb != qtd_next->urb;
1067 dw3 |= ERR_COUNTER << (55 - 32); 865
1068 866 if ((!last_qtd) && (qtd->status == QTD_RETIRE))
1069 /* 867 qtd_next->status = QTD_RETIRE;
1070 * It is not needed to write skip map back because it 868
1071 * is unchanged. Just make sure that this entry is 869 if (qtd->status == QTD_XFER_COMPLETE) {
1072 * unskipped once it gets written to the HW. 870 if (qtd->actual_length) {
1073 */ 871 switch (qtd->packet_type) {
1074 skip_map &= ~(1 << queue_entry); 872 case IN_PID:
1075 or_map = isp1760_readl(usb_hcd->regs + 873 mem_reads8(hcd->regs, qtd->payload_addr,
1076 HC_ATL_IRQ_MASK_OR_REG); 874 qtd->data_buffer,
1077 or_map |= 1 << queue_entry; 875 qtd->actual_length);
1078 isp1760_writel(or_map, usb_hcd->regs + 876 /* Fall through (?) */
1079 HC_ATL_IRQ_MASK_OR_REG); 877 case OUT_PID:
1080 878 qtd->urb->actual_length +=
1081 ptd.dw3 = cpu_to_le32(dw3); 879 qtd->actual_length;
1082 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs + 880 /* Fall through ... */
1083 atl_regs, sizeof(ptd)); 881 case SETUP_PID:
1084 882 break;
1085 ptd.dw0 |= cpu_to_le32(PTD_VALID); 883 }
1086 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs + 884 }
1087 atl_regs, sizeof(ptd));
1088
1089 buffstatus = isp1760_readl(usb_hcd->regs +
1090 HC_BUFFER_STATUS_REG);
1091 buffstatus |= ATL_BUFFER;
1092 isp1760_writel(buffstatus, usb_hcd->regs +
1093 HC_BUFFER_STATUS_REG);
1094 continue;
1095 }
1096 885
1097 error = check_error(&ptd); 886 if (is_short_bulk(qtd)) {
1098 if (error) { 887 if (qtd->urb->transfer_flags & URB_SHORT_NOT_OK)
1099 status = error; 888 qtd->urb->status = -EREMOTEIO;
1100 priv->atl_ints[queue_entry].qh->toggle = 0; 889 if (!last_qtd)
1101 priv->atl_ints[queue_entry].qh->ping = 0; 890 qtd_next->status = QTD_RETIRE;
1102 urb->status = -EPIPE;
1103
1104#if 0
1105 printk(KERN_ERR "Error in %s().\n", __func__);
1106 printk(KERN_ERR "IN dw0: %08x dw1: %08x dw2: %08x "
1107 "dw3: %08x dw4: %08x dw5: %08x dw6: "
1108 "%08x dw7: %08x\n",
1109 ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3,
1110 ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7);
1111#endif
1112 } else {
1113 if (usb_pipetype(urb->pipe) == PIPE_BULK) {
1114 priv->atl_ints[queue_entry].qh->toggle = dw3 &
1115 (1 << 25);
1116 priv->atl_ints[queue_entry].qh->ping = dw3 &
1117 (1 << 26);
1118 } 891 }
1119 } 892 }
1120 893
1121 length = PTD_XFERRED_LENGTH(dw3); 894 if (qtd->payload_addr)
1122 if (length) { 895 free_mem(hcd, qtd);
1123 switch (DW1_GET_PID(dw1)) { 896
1124 case IN_PID: 897 if (last_qtd) {
1125 priv_read_copy(priv, 898 if ((qtd->status == QTD_RETIRE) &&
1126 priv->atl_ints[queue_entry].data_buffer, 899 (qtd->urb->status == -EINPROGRESS))
1127 usb_hcd->regs + payload + ISP_BANK(1), 900 qtd->urb->status = -EPIPE;
1128 length); 901 /* Defer calling of urb_done() since it releases lock */
1129 902 urb_listitem = kmem_cache_zalloc(urb_listitem_cachep,
1130 case OUT_PID: 903 GFP_ATOMIC);
1131 904 if (unlikely(!urb_listitem))
1132 urb->actual_length += length;
1133
1134 case SETUP_PID:
1135 break; 905 break;
1136 } 906 urb_listitem->urb = qtd->urb;
907 list_add_tail(&urb_listitem->urb_list, urb_list);
1137 } 908 }
1138 909
1139 priv->atl_ints[queue_entry].data_buffer = NULL; 910 list_del(&qtd->qtd_list);
1140 priv->atl_ints[queue_entry].urb = NULL; 911 qtd_free(qtd);
1141 priv->atl_ints[queue_entry].qtd = NULL; 912 }
1142 priv->atl_ints[queue_entry].qh = NULL; 913}
1143 914
1144 free_mem(priv, payload); 915#define ENQUEUE_DEPTH 2
916static void enqueue_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh)
917{
918 struct isp1760_hcd *priv = hcd_to_priv(hcd);
919 int ptd_offset;
920 struct slotinfo *slots;
921 int curr_slot, free_slot;
922 int n;
923 struct ptd ptd;
924 struct isp1760_qtd *qtd;
1145 925
1146 isp1760_writel(skip_map, usb_hcd->regs + 926 if (unlikely(list_empty(&qh->qtd_list))) {
1147 HC_ATL_PTD_SKIPMAP_REG); 927 WARN_ON(1);
928 return;
929 }
1148 930
1149 if (urb->status == -EPIPE) { 931 if (usb_pipeint(list_entry(qh->qtd_list.next, struct isp1760_qtd,
1150 /* HALT was received */ 932 qtd_list)->urb->pipe)) {
933 ptd_offset = INT_PTD_OFFSET;
934 slots = priv->int_slots;
935 } else {
936 ptd_offset = ATL_PTD_OFFSET;
937 slots = priv->atl_slots;
938 }
1151 939
1152 qtd = clean_up_qtdlist(qtd); 940 free_slot = -1;
1153 isp1760_urb_done(priv, urb, urb->status); 941 for (curr_slot = 0; curr_slot < 32; curr_slot++) {
942 if ((free_slot == -1) && (slots[curr_slot].qtd == NULL))
943 free_slot = curr_slot;
944 if (slots[curr_slot].qh == qh)
945 break;
946 }
1154 947
1155 } else if (usb_pipebulk(urb->pipe) && (length < qtd->length)) { 948 n = 0;
1156 /* short BULK received */ 949 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
950 if (qtd->status == QTD_ENQUEUED) {
951 WARN_ON(qtd->payload_addr);
952 alloc_mem(hcd, qtd);
953 if ((qtd->length) && (!qtd->payload_addr))
954 break;
1157 955
1158 if (urb->transfer_flags & URB_SHORT_NOT_OK) { 956 if ((qtd->length) &&
1159 urb->status = -EREMOTEIO; 957 ((qtd->packet_type == SETUP_PID) ||
1160 isp1760_dbg(priv, "short bulk, %d instead %zu " 958 (qtd->packet_type == OUT_PID))) {
1161 "with URB_SHORT_NOT_OK flag.\n", 959 mem_writes8(hcd->regs, qtd->payload_addr,
1162 length, qtd->length); 960 qtd->data_buffer, qtd->length);
1163 } 961 }
1164 962
1165 if (urb->status == -EINPROGRESS) 963 qtd->status = QTD_PAYLOAD_ALLOC;
1166 urb->status = 0;
1167
1168 qtd = clean_up_qtdlist(qtd);
1169
1170 isp1760_urb_done(priv, urb, urb->status);
1171
1172 } else if (qtd->status & URB_COMPLETE_NOTIFY) {
1173 /* that was the last qtd of that URB */
1174
1175 if (urb->status == -EINPROGRESS)
1176 urb->status = 0;
1177
1178 qtd = clean_this_qtd(qtd);
1179 isp1760_urb_done(priv, urb, urb->status);
1180
1181 } else {
1182 /* next QTD of this URB */
1183
1184 qtd = clean_this_qtd(qtd);
1185 BUG_ON(!qtd);
1186 } 964 }
1187 965
1188 if (qtd) 966 if (qtd->status == QTD_PAYLOAD_ALLOC) {
1189 enqueue_an_ATL_packet(usb_hcd, qh, qtd); 967/*
968 if ((curr_slot > 31) && (free_slot == -1))
969 dev_dbg(hcd->self.controller, "%s: No slot "
970 "available for transfer\n", __func__);
971*/
972 /* Start xfer for this endpoint if not already done */
973 if ((curr_slot > 31) && (free_slot > -1)) {
974 if (usb_pipeint(qtd->urb->pipe))
975 create_ptd_int(qh, qtd, &ptd);
976 else
977 create_ptd_atl(qh, qtd, &ptd);
978
979 start_bus_transfer(hcd, ptd_offset, free_slot,
980 slots, qtd, qh, &ptd);
981 curr_slot = free_slot;
982 }
1190 983
1191 skip_map = isp1760_readl(usb_hcd->regs + 984 n++;
1192 HC_ATL_PTD_SKIPMAP_REG); 985 if (n >= ENQUEUE_DEPTH)
986 break;
987 }
1193 } 988 }
1194} 989}
1195 990
1196static void do_intl_int(struct usb_hcd *usb_hcd) 991void schedule_ptds(struct usb_hcd *hcd)
1197{ 992{
1198 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); 993 struct isp1760_hcd *priv;
1199 u32 done_map, skip_map; 994 struct isp1760_qh *qh, *qh_next;
1200 struct ptd ptd; 995 struct list_head *ep_queue;
1201 struct urb *urb = NULL; 996 struct usb_host_endpoint *ep;
1202 u32 int_regs; 997 LIST_HEAD(urb_list);
1203 u32 int_regs_base; 998 struct urb_listitem *urb_listitem, *urb_listitem_next;
1204 u32 payload; 999
1205 u32 length; 1000 if (!hcd) {
1206 u32 or_map; 1001 WARN_ON(1);
1207 int error; 1002 return;
1208 u32 queue_entry; 1003 }
1209 struct isp1760_qtd *qtd;
1210 struct isp1760_qh *qh;
1211
1212 done_map = isp1760_readl(usb_hcd->regs +
1213 HC_INT_PTD_DONEMAP_REG);
1214 skip_map = isp1760_readl(usb_hcd->regs +
1215 HC_INT_PTD_SKIPMAP_REG);
1216 1004
1217 or_map = isp1760_readl(usb_hcd->regs + HC_INT_IRQ_MASK_OR_REG); 1005 priv = hcd_to_priv(hcd);
1218 or_map &= ~done_map;
1219 isp1760_writel(or_map, usb_hcd->regs + HC_INT_IRQ_MASK_OR_REG);
1220 1006
1221 int_regs_base = INT_REGS_OFFSET; 1007 /*
1008 * check finished/retired xfers, transfer payloads, call urb_done()
1009 */
1010 ep_queue = &priv->interruptqhs;
1011 while (ep_queue) {
1012 list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list) {
1013 ep = list_entry(qh->qtd_list.next, struct isp1760_qtd,
1014 qtd_list)->urb->ep;
1015 collect_qtds(hcd, qh, &urb_list);
1016 if (list_empty(&qh->qtd_list)) {
1017 list_del(&qh->qh_list);
1018 if (ep->hcpriv == NULL) {
1019 /* Endpoint has been disabled, so we
1020 can free the associated queue head. */
1021 qh_free(qh);
1022 }
1023 }
1024 }
1222 1025
1223 while (done_map) { 1026 if (ep_queue == &priv->interruptqhs)
1224 u32 dw1; 1027 ep_queue = &priv->controlqhs;
1225 u32 dw3; 1028 else if (ep_queue == &priv->controlqhs)
1029 ep_queue = &priv->bulkqhs;
1030 else
1031 ep_queue = NULL;
1032 }
1226 1033
1227 queue_entry = __ffs(done_map); 1034 list_for_each_entry_safe(urb_listitem, urb_listitem_next, &urb_list,
1228 done_map &= ~(1 << queue_entry); 1035 urb_list) {
1229 skip_map |= 1 << queue_entry; 1036 isp1760_urb_done(hcd, urb_listitem->urb);
1037 kmem_cache_free(urb_listitem_cachep, urb_listitem);
1038 }
1230 1039
1231 int_regs = int_regs_base + queue_entry * sizeof(struct ptd); 1040 /*
1232 urb = priv->int_ints[queue_entry].urb; 1041 * Schedule packets for transfer.
1233 qtd = priv->int_ints[queue_entry].qtd; 1042 *
1234 qh = priv->int_ints[queue_entry].qh; 1043 * According to USB2.0 specification:
1235 payload = priv->int_ints[queue_entry].payload; 1044 *
1045 * 1st prio: interrupt xfers, up to 80 % of bandwidth
1046 * 2nd prio: control xfers
1047 * 3rd prio: bulk xfers
1048 *
1049 * ... but let's use a simpler scheme here (mostly because ISP1761 doc
1050 * is very unclear on how to prioritize traffic):
1051 *
1052 * 1) Enqueue any queued control transfers, as long as payload chip mem
1053 * and PTD ATL slots are available.
1054 * 2) Enqueue any queued INT transfers, as long as payload chip mem
1055 * and PTD INT slots are available.
1056 * 3) Enqueue any queued bulk transfers, as long as payload chip mem
1057 * and PTD ATL slots are available.
1058 *
1059 * Use double buffering (ENQUEUE_DEPTH==2) as a compromise between
1060 * conservation of chip mem and performance.
1061 *
1062 * I'm sure this scheme could be improved upon!
1063 */
1064 ep_queue = &priv->controlqhs;
1065 while (ep_queue) {
1066 list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list)
1067 enqueue_qtds(hcd, qh);
1068
1069 if (ep_queue == &priv->controlqhs)
1070 ep_queue = &priv->interruptqhs;
1071 else if (ep_queue == &priv->interruptqhs)
1072 ep_queue = &priv->bulkqhs;
1073 else
1074 ep_queue = NULL;
1075 }
1076}
1236 1077
1237 if (!qh) { 1078#define PTD_STATE_QTD_DONE 1
1238 printk(KERN_ERR "(INT) qh is 0\n"); 1079#define PTD_STATE_QTD_RELOAD 2
1239 continue; 1080#define PTD_STATE_URB_RETIRE 3
1240 }
1241 1081
1242 isp1760_writel(int_regs + ISP_BANK(0), usb_hcd->regs + 1082static int check_int_transfer(struct usb_hcd *hcd, struct ptd *ptd,
1243 HC_MEMORY_REG); 1083 struct urb *urb)
1244 isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs + 1084{
1245 HC_MEMORY_REG); 1085 __dw dw4;
1246 /* 1086 int i;
1247 * write bank1 address twice to ensure the 90ns delay (time
1248 * between BANK0 write and the priv_read_copy() call is at
1249 * least 3*t_WHWL + 2*t_w11 = 3*25ns + 2*17ns = 92ns)
1250 */
1251 isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs +
1252 HC_MEMORY_REG);
1253
1254 priv_read_copy(priv, (u32 *)&ptd, usb_hcd->regs + int_regs +
1255 ISP_BANK(0), sizeof(ptd));
1256 dw1 = le32_to_cpu(ptd.dw1);
1257 dw3 = le32_to_cpu(ptd.dw3);
1258 check_int_err_status(le32_to_cpu(ptd.dw4));
1259
1260 error = check_error(&ptd);
1261 if (error) {
1262#if 0
1263 printk(KERN_ERR "Error in %s().\n", __func__);
1264 printk(KERN_ERR "IN dw0: %08x dw1: %08x dw2: %08x "
1265 "dw3: %08x dw4: %08x dw5: %08x dw6: "
1266 "%08x dw7: %08x\n",
1267 ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3,
1268 ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7);
1269#endif
1270 urb->status = -EPIPE;
1271 priv->int_ints[queue_entry].qh->toggle = 0;
1272 priv->int_ints[queue_entry].qh->ping = 0;
1273 1087
1274 } else { 1088 dw4 = ptd->dw4;
1275 priv->int_ints[queue_entry].qh->toggle = 1089 dw4 >>= 8;
1276 dw3 & (1 << 25);
1277 priv->int_ints[queue_entry].qh->ping = dw3 & (1 << 26);
1278 }
1279 1090
1280 if (urb->dev->speed != USB_SPEED_HIGH) 1091 /* FIXME: ISP1761 datasheet does not say what to do with these. Do we
1281 length = PTD_XFERRED_LENGTH_LO(dw3); 1092 need to handle these errors? Is it done in hardware? */
1282 else
1283 length = PTD_XFERRED_LENGTH(dw3);
1284 1093
1285 if (length) { 1094 if (ptd->dw3 & DW3_HALT_BIT) {
1286 switch (DW1_GET_PID(dw1)) {
1287 case IN_PID:
1288 priv_read_copy(priv,
1289 priv->int_ints[queue_entry].data_buffer,
1290 usb_hcd->regs + payload + ISP_BANK(1),
1291 length);
1292 case OUT_PID:
1293 1095
1294 urb->actual_length += length; 1096 urb->status = -EPROTO; /* Default unknown error */
1295 1097
1296 case SETUP_PID: 1098 for (i = 0; i < 8; i++) {
1099 switch (dw4 & 0x7) {
1100 case INT_UNDERRUN:
1101 dev_dbg(hcd->self.controller, "%s: underrun "
1102 "during uFrame %d\n",
1103 __func__, i);
1104 urb->status = -ECOMM; /* Could not write data */
1105 break;
1106 case INT_EXACT:
1107 dev_dbg(hcd->self.controller, "%s: transaction "
1108 "error during uFrame %d\n",
1109 __func__, i);
1110 urb->status = -EPROTO; /* timeout, bad CRC, PID
1111 error etc. */
1112 break;
1113 case INT_BABBLE:
1114 dev_dbg(hcd->self.controller, "%s: babble "
1115 "error during uFrame %d\n",
1116 __func__, i);
1117 urb->status = -EOVERFLOW;
1297 break; 1118 break;
1298 } 1119 }
1120 dw4 >>= 3;
1299 } 1121 }
1300 1122
1301 priv->int_ints[queue_entry].data_buffer = NULL; 1123 return PTD_STATE_URB_RETIRE;
1302 priv->int_ints[queue_entry].urb = NULL; 1124 }
1303 priv->int_ints[queue_entry].qtd = NULL;
1304 priv->int_ints[queue_entry].qh = NULL;
1305
1306 isp1760_writel(skip_map, usb_hcd->regs +
1307 HC_INT_PTD_SKIPMAP_REG);
1308 free_mem(priv, payload);
1309
1310 if (urb->status == -EPIPE) {
1311 /* HALT received */
1312
1313 qtd = clean_up_qtdlist(qtd);
1314 isp1760_urb_done(priv, urb, urb->status);
1315
1316 } else if (qtd->status & URB_COMPLETE_NOTIFY) {
1317
1318 if (urb->status == -EINPROGRESS)
1319 urb->status = 0;
1320
1321 qtd = clean_this_qtd(qtd);
1322 isp1760_urb_done(priv, urb, urb->status);
1323 1125
1324 } else { 1126 return PTD_STATE_QTD_DONE;
1325 /* next QTD of this URB */ 1127}
1326 1128
1327 qtd = clean_this_qtd(qtd); 1129static int check_atl_transfer(struct usb_hcd *hcd, struct ptd *ptd,
1328 BUG_ON(!qtd); 1130 struct urb *urb)
1329 } 1131{
1132 WARN_ON(!ptd);
1133 if (ptd->dw3 & DW3_HALT_BIT) {
1134 if (ptd->dw3 & DW3_BABBLE_BIT)
1135 urb->status = -EOVERFLOW;
1136 else if (FROM_DW3_CERR(ptd->dw3))
1137 urb->status = -EPIPE; /* Stall */
1138 else if (ptd->dw3 & DW3_ERROR_BIT)
1139 urb->status = -EPROTO; /* XactErr */
1140 else
1141 urb->status = -EPROTO; /* Unknown */
1142/*
1143 dev_dbg(hcd->self.controller, "%s: ptd error:\n"
1144 " dw0: %08x dw1: %08x dw2: %08x dw3: %08x\n"
1145 " dw4: %08x dw5: %08x dw6: %08x dw7: %08x\n",
1146 __func__,
1147 ptd->dw0, ptd->dw1, ptd->dw2, ptd->dw3,
1148 ptd->dw4, ptd->dw5, ptd->dw6, ptd->dw7);
1149*/
1150 return PTD_STATE_URB_RETIRE;
1151 }
1330 1152
1331 if (qtd) 1153 if ((ptd->dw3 & DW3_ERROR_BIT) && (ptd->dw3 & DW3_ACTIVE_BIT)) {
1332 enqueue_an_INT_packet(usb_hcd, qh, qtd); 1154 /* Transfer Error, *but* active and no HALT -> reload */
1155 dev_dbg(hcd->self.controller, "PID error; reloading ptd\n");
1156 return PTD_STATE_QTD_RELOAD;
1157 }
1333 1158
1334 skip_map = isp1760_readl(usb_hcd->regs + 1159 if (!FROM_DW3_NAKCOUNT(ptd->dw3) && (ptd->dw3 & DW3_ACTIVE_BIT)) {
1335 HC_INT_PTD_SKIPMAP_REG); 1160 /*
1161 * NAKs are handled in HW by the chip. Usually if the
1162 * device is not able to send data fast enough.
1163 * This happens mostly on slower hardware.
1164 */
1165 return PTD_STATE_QTD_RELOAD;
1336 } 1166 }
1167
1168 return PTD_STATE_QTD_DONE;
1337} 1169}
1338 1170
1339#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) 1171static irqreturn_t isp1760_irq(struct usb_hcd *hcd)
1340static struct isp1760_qh *qh_make(struct isp1760_hcd *priv, struct urb *urb,
1341 gfp_t flags)
1342{ 1172{
1173 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1174 u32 imask;
1175 irqreturn_t irqret = IRQ_NONE;
1176 struct ptd ptd;
1343 struct isp1760_qh *qh; 1177 struct isp1760_qh *qh;
1344 int is_input, type; 1178 int slot;
1345 1179 int state;
1346 qh = isp1760_qh_alloc(priv, flags); 1180 struct slotinfo *slots;
1347 if (!qh) 1181 u32 ptd_offset;
1348 return qh; 1182 struct isp1760_qtd *qtd;
1349 1183 int modified;
1350 /* 1184 static int last_active_ptds;
1351 * init endpoint/device data for this QH 1185 int int_skip_map, atl_skip_map;
1352 */
1353 is_input = usb_pipein(urb->pipe);
1354 type = usb_pipetype(urb->pipe);
1355 1186
1356 if (type == PIPE_INTERRUPT) { 1187 spin_lock(&priv->lock);
1357 1188
1358 if (urb->dev->speed == USB_SPEED_HIGH) { 1189 if (!(hcd->state & HC_STATE_RUNNING))
1190 goto leave;
1359 1191
1360 qh->period = urb->interval >> 3; 1192 imask = reg_read32(hcd->regs, HC_INTERRUPT_REG);
1361 if (qh->period == 0 && urb->interval != 1) { 1193 if (unlikely(!imask))
1362 /* NOTE interval 2 or 4 uframes could work. 1194 goto leave;
1363 * But interval 1 scheduling is simpler, and 1195 reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); /* Clear */
1364 * includes high bandwidth. 1196
1365 */ 1197 int_skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
1366 printk(KERN_ERR "intr period %d uframes, NYET!", 1198 atl_skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
1367 urb->interval); 1199 priv->int_done_map |= reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG);
1368 qh_destroy(qh); 1200 priv->atl_done_map |= reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG);
1369 return NULL; 1201 priv->int_done_map &= ~int_skip_map;
1202 priv->atl_done_map &= ~atl_skip_map;
1203
1204 modified = priv->int_done_map | priv->atl_done_map;
1205
1206 while (priv->int_done_map || priv->atl_done_map) {
1207 if (priv->int_done_map) {
1208 /* INT ptd */
1209 slot = __ffs(priv->int_done_map);
1210 priv->int_done_map &= ~(1 << slot);
1211 slots = priv->int_slots;
1212 /* This should not trigger, and could be removed if
1213 noone have any problems with it triggering: */
1214 if (!slots[slot].qh) {
1215 WARN_ON(1);
1216 continue;
1370 } 1217 }
1218 ptd_offset = INT_PTD_OFFSET;
1219 ptd_read(hcd->regs, INT_PTD_OFFSET, slot, &ptd);
1220 state = check_int_transfer(hcd, &ptd,
1221 slots[slot].qtd->urb);
1371 } else { 1222 } else {
1372 qh->period = urb->interval; 1223 /* ATL ptd */
1224 slot = __ffs(priv->atl_done_map);
1225 priv->atl_done_map &= ~(1 << slot);
1226 slots = priv->atl_slots;
1227 /* This should not trigger, and could be removed if
1228 noone have any problems with it triggering: */
1229 if (!slots[slot].qh) {
1230 WARN_ON(1);
1231 continue;
1232 }
1233 ptd_offset = ATL_PTD_OFFSET;
1234 ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd);
1235 state = check_atl_transfer(hcd, &ptd,
1236 slots[slot].qtd->urb);
1373 } 1237 }
1374 }
1375 1238
1376 /* support for tt scheduling, and access to toggles */ 1239 qtd = slots[slot].qtd;
1377 qh->dev = urb->dev; 1240 slots[slot].qtd = NULL;
1241 qh = slots[slot].qh;
1242 slots[slot].qh = NULL;
1243 priv->active_ptds--;
1244 qh->slot = -1;
1245
1246 WARN_ON(qtd->status != QTD_XFER_STARTED);
1247
1248 switch (state) {
1249 case PTD_STATE_QTD_DONE:
1250 if ((usb_pipeint(qtd->urb->pipe)) &&
1251 (qtd->urb->dev->speed != USB_SPEED_HIGH))
1252 qtd->actual_length =
1253 FROM_DW3_SCS_NRBYTESTRANSFERRED(ptd.dw3);
1254 else
1255 qtd->actual_length =
1256 FROM_DW3_NRBYTESTRANSFERRED(ptd.dw3);
1257
1258 qtd->status = QTD_XFER_COMPLETE;
1259 if (list_is_last(&qtd->qtd_list, &qh->qtd_list) ||
1260 is_short_bulk(qtd))
1261 qtd = NULL;
1262 else
1263 qtd = list_entry(qtd->qtd_list.next,
1264 typeof(*qtd), qtd_list);
1265
1266 qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3);
1267 qh->ping = FROM_DW3_PING(ptd.dw3);
1268 break;
1378 1269
1379 if (!usb_pipecontrol(urb->pipe)) 1270 case PTD_STATE_QTD_RELOAD: /* QTD_RETRY, for atls only */
1380 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1271 qtd->status = QTD_PAYLOAD_ALLOC;
1381 1); 1272 ptd.dw0 |= DW0_VALID_BIT;
1382 return qh; 1273 /* RL counter = ERR counter */
1383} 1274 ptd.dw3 &= ~TO_DW3_NAKCOUNT(0xf);
1275 ptd.dw3 |= TO_DW3_NAKCOUNT(FROM_DW2_RL(ptd.dw2));
1276 ptd.dw3 &= ~TO_DW3_CERR(3);
1277 ptd.dw3 |= TO_DW3_CERR(ERR_COUNTER);
1278 qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3);
1279 qh->ping = FROM_DW3_PING(ptd.dw3);
1280 break;
1384 1281
1385/* 1282 case PTD_STATE_URB_RETIRE:
1386 * For control/bulk/interrupt, return QH with these TDs appended. 1283 qtd->status = QTD_RETIRE;
1387 * Allocates and initializes the QH if necessary. 1284 qtd = NULL;
1388 * Returns null if it can't allocate a QH it needs to. 1285 qh->toggle = 0;
1389 * If the QH has TDs (urbs) already, that's great. 1286 qh->ping = 0;
1390 */ 1287 break;
1391static struct isp1760_qh *qh_append_tds(struct isp1760_hcd *priv,
1392 struct urb *urb, struct list_head *qtd_list, int epnum,
1393 void **ptr)
1394{
1395 struct isp1760_qh *qh;
1396 struct isp1760_qtd *qtd;
1397 struct isp1760_qtd *prev_qtd;
1398 1288
1399 qh = (struct isp1760_qh *)*ptr; 1289 default:
1400 if (!qh) { 1290 WARN_ON(1);
1401 /* can't sleep here, we have priv->lock... */ 1291 continue;
1402 qh = qh_make(priv, urb, GFP_ATOMIC); 1292 }
1403 if (!qh)
1404 return qh;
1405 *ptr = qh;
1406 }
1407 1293
1408 qtd = list_entry(qtd_list->next, struct isp1760_qtd, 1294 if (qtd && (qtd->status == QTD_PAYLOAD_ALLOC)) {
1409 qtd_list); 1295 if (slots == priv->int_slots) {
1410 if (!list_empty(&qh->qtd_list)) 1296 if (state == PTD_STATE_QTD_RELOAD)
1411 prev_qtd = list_entry(qh->qtd_list.prev, 1297 dev_err(hcd->self.controller,
1412 struct isp1760_qtd, qtd_list); 1298 "%s: PTD_STATE_QTD_RELOAD on "
1413 else 1299 "interrupt packet\n", __func__);
1414 prev_qtd = NULL; 1300 if (state != PTD_STATE_QTD_RELOAD)
1301 create_ptd_int(qh, qtd, &ptd);
1302 } else {
1303 if (state != PTD_STATE_QTD_RELOAD)
1304 create_ptd_atl(qh, qtd, &ptd);
1305 }
1415 1306
1416 list_splice(qtd_list, qh->qtd_list.prev); 1307 start_bus_transfer(hcd, ptd_offset, slot, slots, qtd,
1417 if (prev_qtd) { 1308 qh, &ptd);
1418 BUG_ON(prev_qtd->hw_next); 1309 }
1419 prev_qtd->hw_next = qtd;
1420 } 1310 }
1421 1311
1422 urb->hcpriv = qh; 1312 if (modified)
1423 return qh; 1313 schedule_ptds(hcd);
1424}
1425
1426static void qtd_list_free(struct isp1760_hcd *priv, struct urb *urb,
1427 struct list_head *qtd_list)
1428{
1429 struct list_head *entry, *temp;
1430 1314
1431 list_for_each_safe(entry, temp, qtd_list) { 1315 /* ISP1760 Errata 2 explains that interrupts may be missed (or not
1432 struct isp1760_qtd *qtd; 1316 happen?) if two USB devices are running simultaneously. Perhaps
1317 this happens when a PTD is finished during interrupt handling;
1318 enable SOF interrupts if PTDs are still scheduled when exiting this
1319 interrupt handler, just to be safe. */
1433 1320
1434 qtd = list_entry(entry, struct isp1760_qtd, qtd_list); 1321 if (priv->active_ptds != last_active_ptds) {
1435 list_del(&qtd->qtd_list); 1322 if (priv->active_ptds > 0)
1436 isp1760_qtd_free(qtd); 1323 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE,
1324 INTERRUPT_ENABLE_SOT_MASK);
1325 else
1326 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE,
1327 INTERRUPT_ENABLE_MASK);
1328 last_active_ptds = priv->active_ptds;
1437 } 1329 }
1438}
1439
1440static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb,
1441 struct list_head *qtd_list, gfp_t mem_flags, packet_enqueue *p)
1442{
1443 struct isp1760_qtd *qtd;
1444 int epnum;
1445 unsigned long flags;
1446 struct isp1760_qh *qh = NULL;
1447 int rc;
1448 int qh_busy;
1449
1450 qtd = list_entry(qtd_list->next, struct isp1760_qtd, qtd_list);
1451 epnum = urb->ep->desc.bEndpointAddress;
1452 1330
1453 spin_lock_irqsave(&priv->lock, flags); 1331 irqret = IRQ_HANDLED;
1454 if (!HCD_HW_ACCESSIBLE(priv_to_hcd(priv))) { 1332leave:
1455 rc = -ESHUTDOWN; 1333 spin_unlock(&priv->lock);
1456 goto done;
1457 }
1458 rc = usb_hcd_link_urb_to_ep(priv_to_hcd(priv), urb);
1459 if (rc)
1460 goto done;
1461 1334
1462 qh = urb->ep->hcpriv; 1335 return irqret;
1463 if (qh) 1336}
1464 qh_busy = !list_empty(&qh->qtd_list);
1465 else
1466 qh_busy = 0;
1467 1337
1468 qh = qh_append_tds(priv, urb, qtd_list, epnum, &urb->ep->hcpriv); 1338static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len)
1469 if (!qh) { 1339{
1470 usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb); 1340 qtd->data_buffer = databuffer;
1471 rc = -ENOMEM;
1472 goto done;
1473 }
1474 1341
1475 if (!qh_busy) 1342 if (len > MAX_PAYLOAD_SIZE)
1476 p(priv_to_hcd(priv), qh, qtd); 1343 len = MAX_PAYLOAD_SIZE;
1344 qtd->length = len;
1477 1345
1478done: 1346 return qtd->length;
1479 spin_unlock_irqrestore(&priv->lock, flags);
1480 if (!qh)
1481 qtd_list_free(priv, urb, qtd_list);
1482 return rc;
1483} 1347}
1484 1348
1485static struct isp1760_qtd *isp1760_qtd_alloc(struct isp1760_hcd *priv, 1349static void qtd_list_free(struct list_head *qtd_list)
1486 gfp_t flags)
1487{ 1350{
1488 struct isp1760_qtd *qtd; 1351 struct isp1760_qtd *qtd, *qtd_next;
1489 1352
1490 qtd = kmem_cache_zalloc(qtd_cachep, flags); 1353 list_for_each_entry_safe(qtd, qtd_next, qtd_list, qtd_list) {
1491 if (qtd) 1354 list_del(&qtd->qtd_list);
1492 INIT_LIST_HEAD(&qtd->qtd_list); 1355 qtd_free(qtd);
1493 1356 }
1494 return qtd;
1495} 1357}
1496 1358
1497/* 1359/*
1498 * create a list of filled qtds for this URB; won't link into qh. 1360 * Packetize urb->transfer_buffer into list of packets of size wMaxPacketSize.
1361 * Also calculate the PID type (SETUP/IN/OUT) for each packet.
1499 */ 1362 */
1500static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv, 1363#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
1364static void packetize_urb(struct usb_hcd *hcd,
1501 struct urb *urb, struct list_head *head, gfp_t flags) 1365 struct urb *urb, struct list_head *head, gfp_t flags)
1502{ 1366{
1503 struct isp1760_qtd *qtd, *qtd_prev; 1367 struct isp1760_qtd *qtd;
1504 void *buf; 1368 void *buf;
1505 int len, maxpacket; 1369 int len, maxpacketsize;
1506 int is_input; 1370 u8 packet_type;
1507 u32 token;
1508 1371
1509 /* 1372 /*
1510 * URBs map to sequences of QTDs: one logical transaction 1373 * URBs map to sequences of QTDs: one logical transaction
1511 */ 1374 */
1512 qtd = isp1760_qtd_alloc(priv, flags);
1513 if (!qtd)
1514 return NULL;
1515 1375
1516 list_add_tail(&qtd->qtd_list, head); 1376 if (!urb->transfer_buffer && urb->transfer_buffer_length) {
1517 qtd->urb = urb; 1377 /* XXX This looks like usb storage / SCSI bug */
1518 urb->status = -EINPROGRESS; 1378 dev_err(hcd->self.controller,
1379 "buf is null, dma is %08lx len is %d\n",
1380 (long unsigned)urb->transfer_dma,
1381 urb->transfer_buffer_length);
1382 WARN_ON(1);
1383 }
1519 1384
1520 token = 0; 1385 if (usb_pipein(urb->pipe))
1521 /* for split transactions, SplitXState initialized to zero */ 1386 packet_type = IN_PID;
1387 else
1388 packet_type = OUT_PID;
1522 1389
1523 len = urb->transfer_buffer_length;
1524 is_input = usb_pipein(urb->pipe);
1525 if (usb_pipecontrol(urb->pipe)) { 1390 if (usb_pipecontrol(urb->pipe)) {
1526 /* SETUP pid */ 1391 qtd = qtd_alloc(flags, urb, SETUP_PID);
1527 qtd_fill(qtd, urb->setup_packet,
1528 sizeof(struct usb_ctrlrequest),
1529 token | SETUP_PID);
1530
1531 /* ... and always at least one more pid */
1532 token ^= DATA_TOGGLE;
1533 qtd_prev = qtd;
1534 qtd = isp1760_qtd_alloc(priv, flags);
1535 if (!qtd) 1392 if (!qtd)
1536 goto cleanup; 1393 goto cleanup;
1537 qtd->urb = urb; 1394 qtd_fill(qtd, urb->setup_packet, sizeof(struct usb_ctrlrequest));
1538 qtd_prev->hw_next = qtd;
1539 list_add_tail(&qtd->qtd_list, head); 1395 list_add_tail(&qtd->qtd_list, head);
1540 1396
1541 /* for zero length DATA stages, STATUS is always IN */ 1397 /* for zero length DATA stages, STATUS is always IN */
1542 if (len == 0) 1398 if (urb->transfer_buffer_length == 0)
1543 token |= IN_PID; 1399 packet_type = IN_PID;
1544 } 1400 }
1545 1401
1546 /* 1402 maxpacketsize = max_packet(usb_maxpacket(urb->dev, urb->pipe,
1547 * data transfer stage: buffer setup 1403 usb_pipeout(urb->pipe)));
1548 */
1549 buf = urb->transfer_buffer;
1550
1551 if (is_input)
1552 token |= IN_PID;
1553 else
1554 token |= OUT_PID;
1555
1556 maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input));
1557 1404
1558 /* 1405 /*
1559 * buffer gets wrapped in one or more qtds; 1406 * buffer gets wrapped in one or more qtds;
1560 * last one may be "short" (including zero len) 1407 * last one may be "short" (including zero len)
1561 * and may serve as a control status ack 1408 * and may serve as a control status ack
1562 */ 1409 */
1410 buf = urb->transfer_buffer;
1411 len = urb->transfer_buffer_length;
1412
1563 for (;;) { 1413 for (;;) {
1564 int this_qtd_len; 1414 int this_qtd_len;
1565 1415
1566 if (!buf && len) { 1416 qtd = qtd_alloc(flags, urb, packet_type);
1567 /* XXX This looks like usb storage / SCSI bug */ 1417 if (!qtd)
1568 printk(KERN_ERR "buf is null, dma is %08lx len is %d\n", 1418 goto cleanup;
1569 (long unsigned)urb->transfer_dma, len); 1419 this_qtd_len = qtd_fill(qtd, buf, len);
1570 WARN_ON(1); 1420 list_add_tail(&qtd->qtd_list, head);
1571 }
1572 1421
1573 this_qtd_len = qtd_fill(qtd, buf, len, token);
1574 len -= this_qtd_len; 1422 len -= this_qtd_len;
1575 buf += this_qtd_len; 1423 buf += this_qtd_len;
1576 1424
1577 /* qh makes control packets use qtd toggle; maybe switch it */
1578 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
1579 token ^= DATA_TOGGLE;
1580
1581 if (len <= 0) 1425 if (len <= 0)
1582 break; 1426 break;
1583
1584 qtd_prev = qtd;
1585 qtd = isp1760_qtd_alloc(priv, flags);
1586 if (!qtd)
1587 goto cleanup;
1588 qtd->urb = urb;
1589 qtd_prev->hw_next = qtd;
1590 list_add_tail(&qtd->qtd_list, head);
1591 } 1427 }
1592 1428
1593 /* 1429 /*
@@ -1599,187 +1435,204 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv,
1599 1435
1600 if (usb_pipecontrol(urb->pipe)) { 1436 if (usb_pipecontrol(urb->pipe)) {
1601 one_more = 1; 1437 one_more = 1;
1602 /* "in" <--> "out" */ 1438 if (packet_type == IN_PID)
1603 token ^= IN_PID; 1439 packet_type = OUT_PID;
1604 /* force DATA1 */ 1440 else
1605 token |= DATA_TOGGLE; 1441 packet_type = IN_PID;
1606 } else if (usb_pipebulk(urb->pipe) 1442 } else if (usb_pipebulk(urb->pipe)
1607 && (urb->transfer_flags & URB_ZERO_PACKET) 1443 && (urb->transfer_flags & URB_ZERO_PACKET)
1608 && !(urb->transfer_buffer_length % maxpacket)) { 1444 && !(urb->transfer_buffer_length %
1445 maxpacketsize)) {
1609 one_more = 1; 1446 one_more = 1;
1610 } 1447 }
1611 if (one_more) { 1448 if (one_more) {
1612 qtd_prev = qtd; 1449 qtd = qtd_alloc(flags, urb, packet_type);
1613 qtd = isp1760_qtd_alloc(priv, flags);
1614 if (!qtd) 1450 if (!qtd)
1615 goto cleanup; 1451 goto cleanup;
1616 qtd->urb = urb;
1617 qtd_prev->hw_next = qtd;
1618 list_add_tail(&qtd->qtd_list, head);
1619 1452
1620 /* never any data in such packets */ 1453 /* never any data in such packets */
1621 qtd_fill(qtd, NULL, 0, token); 1454 qtd_fill(qtd, NULL, 0);
1455 list_add_tail(&qtd->qtd_list, head);
1622 } 1456 }
1623 } 1457 }
1624 1458
1625 qtd->status = URB_COMPLETE_NOTIFY; 1459 return;
1626 return head;
1627 1460
1628cleanup: 1461cleanup:
1629 qtd_list_free(priv, urb, head); 1462 qtd_list_free(head);
1630 return NULL;
1631} 1463}
1632 1464
1633static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, 1465static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1634 gfp_t mem_flags) 1466 gfp_t mem_flags)
1635{ 1467{
1636 struct isp1760_hcd *priv = hcd_to_priv(hcd); 1468 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1637 struct list_head qtd_list; 1469 struct list_head *ep_queue;
1638 packet_enqueue *pe; 1470 struct isp1760_qh *qh, *qhit;
1639 1471 unsigned long spinflags;
1640 INIT_LIST_HEAD(&qtd_list); 1472 LIST_HEAD(new_qtds);
1473 int retval;
1474 int qh_in_queue;
1641 1475
1642 switch (usb_pipetype(urb->pipe)) { 1476 switch (usb_pipetype(urb->pipe)) {
1643 case PIPE_CONTROL: 1477 case PIPE_CONTROL:
1478 ep_queue = &priv->controlqhs;
1479 break;
1644 case PIPE_BULK: 1480 case PIPE_BULK:
1645 1481 ep_queue = &priv->bulkqhs;
1646 if (!qh_urb_transaction(priv, urb, &qtd_list, mem_flags))
1647 return -ENOMEM;
1648 pe = enqueue_an_ATL_packet;
1649 break; 1482 break;
1650
1651 case PIPE_INTERRUPT: 1483 case PIPE_INTERRUPT:
1652 if (!qh_urb_transaction(priv, urb, &qtd_list, mem_flags)) 1484 if (urb->interval < 0)
1653 return -ENOMEM; 1485 return -EINVAL;
1654 pe = enqueue_an_INT_packet; 1486 /* FIXME: Check bandwidth */
1487 ep_queue = &priv->interruptqhs;
1655 break; 1488 break;
1656
1657 case PIPE_ISOCHRONOUS: 1489 case PIPE_ISOCHRONOUS:
1658 printk(KERN_ERR "PIPE_ISOCHRONOUS ain't supported\n"); 1490 dev_err(hcd->self.controller, "%s: isochronous USB packets "
1491 "not yet supported\n",
1492 __func__);
1493 return -EPIPE;
1659 default: 1494 default:
1495 dev_err(hcd->self.controller, "%s: unknown pipe type\n",
1496 __func__);
1660 return -EPIPE; 1497 return -EPIPE;
1661 } 1498 }
1662 1499
1663 return isp1760_prepare_enqueue(priv, urb, &qtd_list, mem_flags, pe); 1500 if (usb_pipein(urb->pipe))
1501 urb->actual_length = 0;
1502
1503 packetize_urb(hcd, urb, &new_qtds, mem_flags);
1504 if (list_empty(&new_qtds))
1505 return -ENOMEM;
1506 urb->hcpriv = NULL; /* Used to signal unlink to interrupt handler */
1507
1508 retval = 0;
1509 spin_lock_irqsave(&priv->lock, spinflags);
1510
1511 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
1512 retval = -ESHUTDOWN;
1513 goto out;
1514 }
1515 retval = usb_hcd_link_urb_to_ep(hcd, urb);
1516 if (retval)
1517 goto out;
1518
1519 qh = urb->ep->hcpriv;
1520 if (qh) {
1521 qh_in_queue = 0;
1522 list_for_each_entry(qhit, ep_queue, qh_list) {
1523 if (qhit == qh) {
1524 qh_in_queue = 1;
1525 break;
1526 }
1527 }
1528 if (!qh_in_queue)
1529 list_add_tail(&qh->qh_list, ep_queue);
1530 } else {
1531 qh = qh_alloc(GFP_ATOMIC);
1532 if (!qh) {
1533 retval = -ENOMEM;
1534 goto out;
1535 }
1536 list_add_tail(&qh->qh_list, ep_queue);
1537 urb->ep->hcpriv = qh;
1538 }
1539
1540 list_splice_tail(&new_qtds, &qh->qtd_list);
1541 schedule_ptds(hcd);
1542
1543out:
1544 spin_unlock_irqrestore(&priv->lock, spinflags);
1545 return retval;
1546}
1547
1548static void kill_transfer(struct usb_hcd *hcd, struct urb *urb,
1549 struct isp1760_qh *qh)
1550{
1551 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1552 int skip_map;
1553
1554 WARN_ON(qh->slot == -1);
1555
1556 /* We need to forcefully reclaim the slot since some transfers never
1557 return, e.g. interrupt transfers and NAKed bulk transfers. */
1558 if (usb_pipecontrol(urb->pipe) || usb_pipebulk(urb->pipe)) {
1559 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
1560 skip_map |= (1 << qh->slot);
1561 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map);
1562 priv->atl_slots[qh->slot].qh = NULL;
1563 priv->atl_slots[qh->slot].qtd = NULL;
1564 } else {
1565 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
1566 skip_map |= (1 << qh->slot);
1567 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map);
1568 priv->int_slots[qh->slot].qh = NULL;
1569 priv->int_slots[qh->slot].qtd = NULL;
1570 }
1571
1572 qh->slot = -1;
1573 priv->active_ptds--;
1664} 1574}
1665 1575
1666static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, 1576static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1667 int status) 1577 int status)
1668{ 1578{
1669 struct isp1760_hcd *priv = hcd_to_priv(hcd); 1579 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1670 struct inter_packet_info *ints; 1580 unsigned long spinflags;
1671 u32 i; 1581 struct isp1760_qh *qh;
1672 u32 reg_base, or_reg, skip_reg; 1582 struct isp1760_qtd *qtd;
1673 unsigned long flags; 1583 int retval = 0;
1674 struct ptd ptd;
1675 packet_enqueue *pe;
1676
1677 switch (usb_pipetype(urb->pipe)) {
1678 case PIPE_ISOCHRONOUS:
1679 return -EPIPE;
1680 break;
1681 1584
1682 case PIPE_INTERRUPT: 1585 spin_lock_irqsave(&priv->lock, spinflags);
1683 ints = priv->int_ints;
1684 reg_base = INT_REGS_OFFSET;
1685 or_reg = HC_INT_IRQ_MASK_OR_REG;
1686 skip_reg = HC_INT_PTD_SKIPMAP_REG;
1687 pe = enqueue_an_INT_packet;
1688 break;
1689 1586
1690 default: 1587 qh = urb->ep->hcpriv;
1691 ints = priv->atl_ints; 1588 if (!qh) {
1692 reg_base = ATL_REGS_OFFSET; 1589 retval = -EINVAL;
1693 or_reg = HC_ATL_IRQ_MASK_OR_REG; 1590 goto out;
1694 skip_reg = HC_ATL_PTD_SKIPMAP_REG;
1695 pe = enqueue_an_ATL_packet;
1696 break;
1697 } 1591 }
1698 1592
1699 memset(&ptd, 0, sizeof(ptd)); 1593 list_for_each_entry(qtd, &qh->qtd_list, qtd_list)
1700 spin_lock_irqsave(&priv->lock, flags); 1594 if (qtd->urb == urb) {
1701 1595 if (qtd->status == QTD_XFER_STARTED)
1702 for (i = 0; i < 32; i++) { 1596 kill_transfer(hcd, urb, qh);
1703 if (ints->urb == urb) { 1597 qtd->status = QTD_RETIRE;
1704 u32 skip_map;
1705 u32 or_map;
1706 struct isp1760_qtd *qtd;
1707 struct isp1760_qh *qh = ints->qh;
1708
1709 skip_map = isp1760_readl(hcd->regs + skip_reg);
1710 skip_map |= 1 << i;
1711 isp1760_writel(skip_map, hcd->regs + skip_reg);
1712
1713 or_map = isp1760_readl(hcd->regs + or_reg);
1714 or_map &= ~(1 << i);
1715 isp1760_writel(or_map, hcd->regs + or_reg);
1716
1717 priv_write_copy(priv, (u32 *)&ptd, hcd->regs + reg_base
1718 + i * sizeof(ptd), sizeof(ptd));
1719 qtd = ints->qtd;
1720 qtd = clean_up_qtdlist(qtd);
1721
1722 free_mem(priv, ints->payload);
1723
1724 ints->urb = NULL;
1725 ints->qh = NULL;
1726 ints->qtd = NULL;
1727 ints->data_buffer = NULL;
1728 ints->payload = 0;
1729
1730 isp1760_urb_done(priv, urb, status);
1731 if (qtd)
1732 pe(hcd, qh, qtd);
1733 break;
1734
1735 } else if (ints->qtd) {
1736 struct isp1760_qtd *qtd, *prev_qtd = ints->qtd;
1737
1738 for (qtd = ints->qtd->hw_next; qtd; qtd = qtd->hw_next) {
1739 if (qtd->urb == urb) {
1740 prev_qtd->hw_next = clean_up_qtdlist(qtd);
1741 isp1760_urb_done(priv, urb, status);
1742 break;
1743 }
1744 prev_qtd = qtd;
1745 }
1746 /* we found the urb before the end of the list */
1747 if (qtd)
1748 break;
1749 } 1598 }
1750 ints++;
1751 }
1752 1599
1753 spin_unlock_irqrestore(&priv->lock, flags); 1600 urb->status = status;
1754 return 0; 1601 schedule_ptds(hcd);
1602
1603out:
1604 spin_unlock_irqrestore(&priv->lock, spinflags);
1605 return retval;
1755} 1606}
1756 1607
1757static irqreturn_t isp1760_irq(struct usb_hcd *usb_hcd) 1608static void isp1760_endpoint_disable(struct usb_hcd *hcd,
1609 struct usb_host_endpoint *ep)
1758{ 1610{
1759 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); 1611 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1760 u32 imask; 1612 unsigned long spinflags;
1761 irqreturn_t irqret = IRQ_NONE; 1613 struct isp1760_qh *qh;
1614 struct isp1760_qtd *qtd;
1762 1615
1763 spin_lock(&priv->lock); 1616 spin_lock_irqsave(&priv->lock, spinflags);
1764 1617
1765 if (!(usb_hcd->state & HC_STATE_RUNNING)) 1618 qh = ep->hcpriv;
1766 goto leave; 1619 if (!qh)
1620 goto out;
1767 1621
1768 imask = isp1760_readl(usb_hcd->regs + HC_INTERRUPT_REG); 1622 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
1769 if (unlikely(!imask)) 1623 if (qtd->status == QTD_XFER_STARTED)
1770 goto leave; 1624 kill_transfer(hcd, qtd->urb, qh);
1625 qtd->status = QTD_RETIRE;
1626 qtd->urb->status = -ECONNRESET;
1627 }
1771 1628
1772 isp1760_writel(imask, usb_hcd->regs + HC_INTERRUPT_REG); 1629 ep->hcpriv = NULL;
1773 if (imask & HC_ATL_INT) 1630 /* Cannot free qh here since it will be parsed by schedule_ptds() */
1774 do_atl_int(usb_hcd);
1775 1631
1776 if (imask & HC_INTL_INT) 1632 schedule_ptds(hcd);
1777 do_intl_int(usb_hcd);
1778 1633
1779 irqret = IRQ_HANDLED; 1634out:
1780leave: 1635 spin_unlock_irqrestore(&priv->lock, spinflags);
1781 spin_unlock(&priv->lock);
1782 return irqret;
1783} 1636}
1784 1637
1785static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf) 1638static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf)
@@ -1799,12 +1652,12 @@ static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf)
1799 mask = PORT_CSC; 1652 mask = PORT_CSC;
1800 1653
1801 spin_lock_irqsave(&priv->lock, flags); 1654 spin_lock_irqsave(&priv->lock, flags);
1802 temp = isp1760_readl(hcd->regs + HC_PORTSC1); 1655 temp = reg_read32(hcd->regs, HC_PORTSC1);
1803 1656
1804 if (temp & PORT_OWNER) { 1657 if (temp & PORT_OWNER) {
1805 if (temp & PORT_CSC) { 1658 if (temp & PORT_CSC) {
1806 temp &= ~PORT_CSC; 1659 temp &= ~PORT_CSC;
1807 isp1760_writel(temp, hcd->regs + HC_PORTSC1); 1660 reg_write32(hcd->regs, HC_PORTSC1, temp);
1808 goto done; 1661 goto done;
1809 } 1662 }
1810 } 1663 }
@@ -1844,9 +1697,9 @@ static void isp1760_hub_descriptor(struct isp1760_hcd *priv,
1844 temp = 1 + (ports / 8); 1697 temp = 1 + (ports / 8);
1845 desc->bDescLength = 7 + 2 * temp; 1698 desc->bDescLength = 7 + 2 * temp;
1846 1699
1847 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 1700 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
1848 memset(&desc->bitmap[0], 0, temp); 1701 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
1849 memset(&desc->bitmap[temp], 0xff, temp); 1702 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
1850 1703
1851 /* per-port overcurrent reporting */ 1704 /* per-port overcurrent reporting */
1852 temp = 0x0008; 1705 temp = 0x0008;
@@ -1861,8 +1714,8 @@ static void isp1760_hub_descriptor(struct isp1760_hcd *priv,
1861 1714
1862#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) 1715#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
1863 1716
1864static int check_reset_complete(struct isp1760_hcd *priv, int index, 1717static int check_reset_complete(struct usb_hcd *hcd, int index,
1865 u32 __iomem *status_reg, int port_status) 1718 int port_status)
1866{ 1719{
1867 if (!(port_status & PORT_CONNECT)) 1720 if (!(port_status & PORT_CONNECT))
1868 return port_status; 1721 return port_status;
@@ -1870,15 +1723,17 @@ static int check_reset_complete(struct isp1760_hcd *priv, int index,
1870 /* if reset finished and it's still not enabled -- handoff */ 1723 /* if reset finished and it's still not enabled -- handoff */
1871 if (!(port_status & PORT_PE)) { 1724 if (!(port_status & PORT_PE)) {
1872 1725
1873 printk(KERN_ERR "port %d full speed --> companion\n", 1726 dev_info(hcd->self.controller,
1874 index + 1); 1727 "port %d full speed --> companion\n",
1728 index + 1);
1875 1729
1876 port_status |= PORT_OWNER; 1730 port_status |= PORT_OWNER;
1877 port_status &= ~PORT_RWC_BITS; 1731 port_status &= ~PORT_RWC_BITS;
1878 isp1760_writel(port_status, status_reg); 1732 reg_write32(hcd->regs, HC_PORTSC1, port_status);
1879 1733
1880 } else 1734 } else
1881 printk(KERN_ERR "port %d high speed\n", index + 1); 1735 dev_info(hcd->self.controller, "port %d high speed\n",
1736 index + 1);
1882 1737
1883 return port_status; 1738 return port_status;
1884} 1739}
@@ -1888,7 +1743,6 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1888{ 1743{
1889 struct isp1760_hcd *priv = hcd_to_priv(hcd); 1744 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1890 int ports = HCS_N_PORTS(priv->hcs_params); 1745 int ports = HCS_N_PORTS(priv->hcs_params);
1891 u32 __iomem *status_reg = hcd->regs + HC_PORTSC1;
1892 u32 temp, status; 1746 u32 temp, status;
1893 unsigned long flags; 1747 unsigned long flags;
1894 int retval = 0; 1748 int retval = 0;
@@ -1917,7 +1771,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1917 if (!wIndex || wIndex > ports) 1771 if (!wIndex || wIndex > ports)
1918 goto error; 1772 goto error;
1919 wIndex--; 1773 wIndex--;
1920 temp = isp1760_readl(status_reg); 1774 temp = reg_read32(hcd->regs, HC_PORTSC1);
1921 1775
1922 /* 1776 /*
1923 * Even if OWNER is set, so the port is owned by the 1777 * Even if OWNER is set, so the port is owned by the
@@ -1928,7 +1782,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1928 1782
1929 switch (wValue) { 1783 switch (wValue) {
1930 case USB_PORT_FEAT_ENABLE: 1784 case USB_PORT_FEAT_ENABLE:
1931 isp1760_writel(temp & ~PORT_PE, status_reg); 1785 reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_PE);
1932 break; 1786 break;
1933 case USB_PORT_FEAT_C_ENABLE: 1787 case USB_PORT_FEAT_C_ENABLE:
1934 /* XXX error? */ 1788 /* XXX error? */
@@ -1942,8 +1796,8 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1942 goto error; 1796 goto error;
1943 /* resume signaling for 20 msec */ 1797 /* resume signaling for 20 msec */
1944 temp &= ~(PORT_RWC_BITS); 1798 temp &= ~(PORT_RWC_BITS);
1945 isp1760_writel(temp | PORT_RESUME, 1799 reg_write32(hcd->regs, HC_PORTSC1,
1946 status_reg); 1800 temp | PORT_RESUME);
1947 priv->reset_done = jiffies + 1801 priv->reset_done = jiffies +
1948 msecs_to_jiffies(20); 1802 msecs_to_jiffies(20);
1949 } 1803 }
@@ -1953,11 +1807,11 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1953 break; 1807 break;
1954 case USB_PORT_FEAT_POWER: 1808 case USB_PORT_FEAT_POWER:
1955 if (HCS_PPC(priv->hcs_params)) 1809 if (HCS_PPC(priv->hcs_params))
1956 isp1760_writel(temp & ~PORT_POWER, status_reg); 1810 reg_write32(hcd->regs, HC_PORTSC1,
1811 temp & ~PORT_POWER);
1957 break; 1812 break;
1958 case USB_PORT_FEAT_C_CONNECTION: 1813 case USB_PORT_FEAT_C_CONNECTION:
1959 isp1760_writel(temp | PORT_CSC, 1814 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_CSC);
1960 status_reg);
1961 break; 1815 break;
1962 case USB_PORT_FEAT_C_OVER_CURRENT: 1816 case USB_PORT_FEAT_C_OVER_CURRENT:
1963 /* XXX error ?*/ 1817 /* XXX error ?*/
@@ -1968,7 +1822,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1968 default: 1822 default:
1969 goto error; 1823 goto error;
1970 } 1824 }
1971 isp1760_readl(hcd->regs + HC_USBCMD); 1825 reg_read32(hcd->regs, HC_USBCMD);
1972 break; 1826 break;
1973 case GetHubDescriptor: 1827 case GetHubDescriptor:
1974 isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *) 1828 isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *)
@@ -1983,7 +1837,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1983 goto error; 1837 goto error;
1984 wIndex--; 1838 wIndex--;
1985 status = 0; 1839 status = 0;
1986 temp = isp1760_readl(status_reg); 1840 temp = reg_read32(hcd->regs, HC_PORTSC1);
1987 1841
1988 /* wPortChange bits */ 1842 /* wPortChange bits */
1989 if (temp & PORT_CSC) 1843 if (temp & PORT_CSC)
@@ -1992,7 +1846,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1992 1846
1993 /* whoever resumes must GetPortStatus to complete it!! */ 1847 /* whoever resumes must GetPortStatus to complete it!! */
1994 if (temp & PORT_RESUME) { 1848 if (temp & PORT_RESUME) {
1995 printk(KERN_ERR "Port resume should be skipped.\n"); 1849 dev_err(hcd->self.controller, "Port resume should be skipped.\n");
1996 1850
1997 /* Remote Wakeup received? */ 1851 /* Remote Wakeup received? */
1998 if (!priv->reset_done) { 1852 if (!priv->reset_done) {
@@ -2000,8 +1854,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2000 priv->reset_done = jiffies 1854 priv->reset_done = jiffies
2001 + msecs_to_jiffies(20); 1855 + msecs_to_jiffies(20);
2002 /* check the port again */ 1856 /* check the port again */
2003 mod_timer(&priv_to_hcd(priv)->rh_timer, 1857 mod_timer(&hcd->rh_timer, priv->reset_done);
2004 priv->reset_done);
2005 } 1858 }
2006 1859
2007 /* resume completed? */ 1860 /* resume completed? */
@@ -2011,14 +1864,13 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2011 priv->reset_done = 0; 1864 priv->reset_done = 0;
2012 1865
2013 /* stop resume signaling */ 1866 /* stop resume signaling */
2014 temp = isp1760_readl(status_reg); 1867 temp = reg_read32(hcd->regs, HC_PORTSC1);
2015 isp1760_writel( 1868 reg_write32(hcd->regs, HC_PORTSC1,
2016 temp & ~(PORT_RWC_BITS | PORT_RESUME), 1869 temp & ~(PORT_RWC_BITS | PORT_RESUME));
2017 status_reg); 1870 retval = handshake(hcd, HC_PORTSC1,
2018 retval = handshake(priv, status_reg,
2019 PORT_RESUME, 0, 2000 /* 2msec */); 1871 PORT_RESUME, 0, 2000 /* 2msec */);
2020 if (retval != 0) { 1872 if (retval != 0) {
2021 isp1760_err(priv, 1873 dev_err(hcd->self.controller,
2022 "port %d resume error %d\n", 1874 "port %d resume error %d\n",
2023 wIndex + 1, retval); 1875 wIndex + 1, retval);
2024 goto error; 1876 goto error;
@@ -2035,22 +1887,21 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2035 priv->reset_done = 0; 1887 priv->reset_done = 0;
2036 1888
2037 /* force reset to complete */ 1889 /* force reset to complete */
2038 isp1760_writel(temp & ~PORT_RESET, 1890 reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_RESET);
2039 status_reg);
2040 /* REVISIT: some hardware needs 550+ usec to clear 1891 /* REVISIT: some hardware needs 550+ usec to clear
2041 * this bit; seems too long to spin routinely... 1892 * this bit; seems too long to spin routinely...
2042 */ 1893 */
2043 retval = handshake(priv, status_reg, 1894 retval = handshake(hcd, HC_PORTSC1,
2044 PORT_RESET, 0, 750); 1895 PORT_RESET, 0, 750);
2045 if (retval != 0) { 1896 if (retval != 0) {
2046 isp1760_err(priv, "port %d reset error %d\n", 1897 dev_err(hcd->self.controller, "port %d reset error %d\n",
2047 wIndex + 1, retval); 1898 wIndex + 1, retval);
2048 goto error; 1899 goto error;
2049 } 1900 }
2050 1901
2051 /* see what we found out */ 1902 /* see what we found out */
2052 temp = check_reset_complete(priv, wIndex, status_reg, 1903 temp = check_reset_complete(hcd, wIndex,
2053 isp1760_readl(status_reg)); 1904 reg_read32(hcd->regs, HC_PORTSC1));
2054 } 1905 }
2055 /* 1906 /*
2056 * Even if OWNER is set, there's no harm letting khubd 1907 * Even if OWNER is set, there's no harm letting khubd
@@ -2059,12 +1910,12 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2059 */ 1910 */
2060 1911
2061 if (temp & PORT_OWNER) 1912 if (temp & PORT_OWNER)
2062 printk(KERN_ERR "Warning: PORT_OWNER is set\n"); 1913 dev_err(hcd->self.controller, "PORT_OWNER is set\n");
2063 1914
2064 if (temp & PORT_CONNECT) { 1915 if (temp & PORT_CONNECT) {
2065 status |= USB_PORT_STAT_CONNECTION; 1916 status |= USB_PORT_STAT_CONNECTION;
2066 /* status may be from integrated TT */ 1917 /* status may be from integrated TT */
2067 status |= ehci_port_speed(priv, temp); 1918 status |= USB_PORT_STAT_HIGH_SPEED;
2068 } 1919 }
2069 if (temp & PORT_PE) 1920 if (temp & PORT_PE)
2070 status |= USB_PORT_STAT_ENABLE; 1921 status |= USB_PORT_STAT_ENABLE;
@@ -2093,14 +1944,14 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2093 if (!wIndex || wIndex > ports) 1944 if (!wIndex || wIndex > ports)
2094 goto error; 1945 goto error;
2095 wIndex--; 1946 wIndex--;
2096 temp = isp1760_readl(status_reg); 1947 temp = reg_read32(hcd->regs, HC_PORTSC1);
2097 if (temp & PORT_OWNER) 1948 if (temp & PORT_OWNER)
2098 break; 1949 break;
2099 1950
2100/* temp &= ~PORT_RWC_BITS; */ 1951/* temp &= ~PORT_RWC_BITS; */
2101 switch (wValue) { 1952 switch (wValue) {
2102 case USB_PORT_FEAT_ENABLE: 1953 case USB_PORT_FEAT_ENABLE:
2103 isp1760_writel(temp | PORT_PE, status_reg); 1954 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_PE);
2104 break; 1955 break;
2105 1956
2106 case USB_PORT_FEAT_SUSPEND: 1957 case USB_PORT_FEAT_SUSPEND:
@@ -2108,12 +1959,12 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2108 || (temp & PORT_RESET) != 0) 1959 || (temp & PORT_RESET) != 0)
2109 goto error; 1960 goto error;
2110 1961
2111 isp1760_writel(temp | PORT_SUSPEND, status_reg); 1962 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_SUSPEND);
2112 break; 1963 break;
2113 case USB_PORT_FEAT_POWER: 1964 case USB_PORT_FEAT_POWER:
2114 if (HCS_PPC(priv->hcs_params)) 1965 if (HCS_PPC(priv->hcs_params))
2115 isp1760_writel(temp | PORT_POWER, 1966 reg_write32(hcd->regs, HC_PORTSC1,
2116 status_reg); 1967 temp | PORT_POWER);
2117 break; 1968 break;
2118 case USB_PORT_FEAT_RESET: 1969 case USB_PORT_FEAT_RESET:
2119 if (temp & PORT_RESUME) 1970 if (temp & PORT_RESUME)
@@ -2136,12 +1987,12 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2136 priv->reset_done = jiffies + 1987 priv->reset_done = jiffies +
2137 msecs_to_jiffies(50); 1988 msecs_to_jiffies(50);
2138 } 1989 }
2139 isp1760_writel(temp, status_reg); 1990 reg_write32(hcd->regs, HC_PORTSC1, temp);
2140 break; 1991 break;
2141 default: 1992 default:
2142 goto error; 1993 goto error;
2143 } 1994 }
2144 isp1760_readl(hcd->regs + HC_USBCMD); 1995 reg_read32(hcd->regs, HC_USBCMD);
2145 break; 1996 break;
2146 1997
2147 default: 1998 default:
@@ -2153,57 +2004,12 @@ error:
2153 return retval; 2004 return retval;
2154} 2005}
2155 2006
2156static void isp1760_endpoint_disable(struct usb_hcd *usb_hcd,
2157 struct usb_host_endpoint *ep)
2158{
2159 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd);
2160 struct isp1760_qh *qh;
2161 struct isp1760_qtd *qtd;
2162 unsigned long flags;
2163
2164 spin_lock_irqsave(&priv->lock, flags);
2165 qh = ep->hcpriv;
2166 if (!qh)
2167 goto out;
2168
2169 ep->hcpriv = NULL;
2170 do {
2171 /* more than entry might get removed */
2172 if (list_empty(&qh->qtd_list))
2173 break;
2174
2175 qtd = list_first_entry(&qh->qtd_list, struct isp1760_qtd,
2176 qtd_list);
2177
2178 if (qtd->status & URB_ENQUEUED) {
2179
2180 spin_unlock_irqrestore(&priv->lock, flags);
2181 isp1760_urb_dequeue(usb_hcd, qtd->urb, -ECONNRESET);
2182 spin_lock_irqsave(&priv->lock, flags);
2183 } else {
2184 struct urb *urb;
2185
2186 urb = qtd->urb;
2187 clean_up_qtdlist(qtd);
2188 isp1760_urb_done(priv, urb, -ECONNRESET);
2189 }
2190 } while (1);
2191
2192 qh_destroy(qh);
2193 /* remove requests and leak them.
2194 * ATL are pretty fast done, INT could take a while...
2195 * The latter shoule be removed
2196 */
2197out:
2198 spin_unlock_irqrestore(&priv->lock, flags);
2199}
2200
2201static int isp1760_get_frame(struct usb_hcd *hcd) 2007static int isp1760_get_frame(struct usb_hcd *hcd)
2202{ 2008{
2203 struct isp1760_hcd *priv = hcd_to_priv(hcd); 2009 struct isp1760_hcd *priv = hcd_to_priv(hcd);
2204 u32 fr; 2010 u32 fr;
2205 2011
2206 fr = isp1760_readl(hcd->regs + HC_FRINDEX); 2012 fr = reg_read32(hcd->regs, HC_FRINDEX);
2207 return (fr >> 3) % priv->periodic_size; 2013 return (fr >> 3) % priv->periodic_size;
2208} 2014}
2209 2015
@@ -2217,13 +2023,13 @@ static void isp1760_stop(struct usb_hcd *hcd)
2217 mdelay(20); 2023 mdelay(20);
2218 2024
2219 spin_lock_irq(&priv->lock); 2025 spin_lock_irq(&priv->lock);
2220 ehci_reset(priv); 2026 ehci_reset(hcd);
2221 /* Disable IRQ */ 2027 /* Disable IRQ */
2222 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); 2028 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
2223 isp1760_writel(temp &= ~HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL); 2029 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN);
2224 spin_unlock_irq(&priv->lock); 2030 spin_unlock_irq(&priv->lock);
2225 2031
2226 isp1760_writel(0, hcd->regs + HC_CONFIGFLAG); 2032 reg_write32(hcd->regs, HC_CONFIGFLAG, 0);
2227} 2033}
2228 2034
2229static void isp1760_shutdown(struct usb_hcd *hcd) 2035static void isp1760_shutdown(struct usb_hcd *hcd)
@@ -2231,12 +2037,12 @@ static void isp1760_shutdown(struct usb_hcd *hcd)
2231 u32 command, temp; 2037 u32 command, temp;
2232 2038
2233 isp1760_stop(hcd); 2039 isp1760_stop(hcd);
2234 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); 2040 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
2235 isp1760_writel(temp &= ~HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL); 2041 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN);
2236 2042
2237 command = isp1760_readl(hcd->regs + HC_USBCMD); 2043 command = reg_read32(hcd->regs, HC_USBCMD);
2238 command &= ~CMD_RUN; 2044 command &= ~CMD_RUN;
2239 isp1760_writel(command, hcd->regs + HC_USBCMD); 2045 reg_write32(hcd->regs, HC_USBCMD, command);
2240} 2046}
2241 2047
2242static const struct hc_driver isp1760_hc_driver = { 2048static const struct hc_driver isp1760_hc_driver = {
@@ -2259,6 +2065,13 @@ static const struct hc_driver isp1760_hc_driver = {
2259 2065
2260int __init init_kmem_once(void) 2066int __init init_kmem_once(void)
2261{ 2067{
2068 urb_listitem_cachep = kmem_cache_create("isp1760 urb_listitem",
2069 sizeof(struct urb_listitem), 0, SLAB_TEMPORARY |
2070 SLAB_MEM_SPREAD, NULL);
2071
2072 if (!urb_listitem_cachep)
2073 return -ENOMEM;
2074
2262 qtd_cachep = kmem_cache_create("isp1760_qtd", 2075 qtd_cachep = kmem_cache_create("isp1760_qtd",
2263 sizeof(struct isp1760_qtd), 0, SLAB_TEMPORARY | 2076 sizeof(struct isp1760_qtd), 0, SLAB_TEMPORARY |
2264 SLAB_MEM_SPREAD, NULL); 2077 SLAB_MEM_SPREAD, NULL);
@@ -2281,6 +2094,7 @@ void deinit_kmem_cache(void)
2281{ 2094{
2282 kmem_cache_destroy(qtd_cachep); 2095 kmem_cache_destroy(qtd_cachep);
2283 kmem_cache_destroy(qh_cachep); 2096 kmem_cache_destroy(qh_cachep);
2097 kmem_cache_destroy(urb_listitem_cachep);
2284} 2098}
2285 2099
2286struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, 2100struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len,
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h
index 6931ef5c9650..014a7dfadf91 100644
--- a/drivers/usb/host/isp1760-hcd.h
+++ b/drivers/usb/host/isp1760-hcd.h
@@ -49,10 +49,9 @@ void deinit_kmem_cache(void);
49#define SW_RESET_RESET_ALL (1 << 0) 49#define SW_RESET_RESET_ALL (1 << 0)
50 50
51#define HC_BUFFER_STATUS_REG 0x334 51#define HC_BUFFER_STATUS_REG 0x334
52#define ATL_BUFFER 0x1 52#define ISO_BUF_FILL (1 << 2)
53#define INT_BUFFER 0x2 53#define INT_BUF_FILL (1 << 1)
54#define ISO_BUFFER 0x4 54#define ATL_BUF_FILL (1 << 0)
55#define BUFFER_MAP 0x7
56 55
57#define HC_MEMORY_REG 0x33c 56#define HC_MEMORY_REG 0x33c
58#define ISP_BANK(x) ((x) << 16) 57#define ISP_BANK(x) ((x) << 16)
@@ -68,13 +67,13 @@ void deinit_kmem_cache(void);
68#define HC_INTERRUPT_REG 0x310 67#define HC_INTERRUPT_REG 0x310
69 68
70#define HC_INTERRUPT_ENABLE 0x314 69#define HC_INTERRUPT_ENABLE 0x314
71#define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT | HC_EOT_INT)
72
73#define HC_ISO_INT (1 << 9) 70#define HC_ISO_INT (1 << 9)
74#define HC_ATL_INT (1 << 8) 71#define HC_ATL_INT (1 << 8)
75#define HC_INTL_INT (1 << 7) 72#define HC_INTL_INT (1 << 7)
76#define HC_EOT_INT (1 << 3) 73#define HC_EOT_INT (1 << 3)
77#define HC_SOT_INT (1 << 1) 74#define HC_SOT_INT (1 << 1)
75#define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT)
76#define INTERRUPT_ENABLE_SOT_MASK (HC_SOT_INT)
78 77
79#define HC_ISO_IRQ_MASK_OR_REG 0x318 78#define HC_ISO_IRQ_MASK_OR_REG 0x318
80#define HC_INT_IRQ_MASK_OR_REG 0x31C 79#define HC_INT_IRQ_MASK_OR_REG 0x31C
@@ -83,37 +82,29 @@ void deinit_kmem_cache(void);
83#define HC_INT_IRQ_MASK_AND_REG 0x328 82#define HC_INT_IRQ_MASK_AND_REG 0x328
84#define HC_ATL_IRQ_MASK_AND_REG 0x32C 83#define HC_ATL_IRQ_MASK_AND_REG 0x32C
85 84
86/* Register sets */
87#define HC_BEGIN_OF_ATL 0x0c00
88#define HC_BEGIN_OF_INT 0x0800
89#define HC_BEGIN_OF_ISO 0x0400
90#define HC_BEGIN_OF_PAYLOAD 0x1000
91
92/* urb state*/ 85/* urb state*/
93#define DELETE_URB (0x0008) 86#define DELETE_URB (0x0008)
94#define NO_TRANSFER_ACTIVE (0xffffffff) 87#define NO_TRANSFER_ACTIVE (0xffffffff)
95 88
96#define ATL_REGS_OFFSET (0xc00) 89/* Philips Proprietary Transfer Descriptor (PTD) */
97#define INT_REGS_OFFSET (0x800) 90typedef __u32 __bitwise __dw;
98
99/* Philips Transfer Descriptor (PTD) */
100struct ptd { 91struct ptd {
101 __le32 dw0; 92 __dw dw0;
102 __le32 dw1; 93 __dw dw1;
103 __le32 dw2; 94 __dw dw2;
104 __le32 dw3; 95 __dw dw3;
105 __le32 dw4; 96 __dw dw4;
106 __le32 dw5; 97 __dw dw5;
107 __le32 dw6; 98 __dw dw6;
108 __le32 dw7; 99 __dw dw7;
109}; 100};
101#define PTD_OFFSET 0x0400
102#define ISO_PTD_OFFSET 0x0400
103#define INT_PTD_OFFSET 0x0800
104#define ATL_PTD_OFFSET 0x0c00
105#define PAYLOAD_OFFSET 0x1000
110 106
111struct inter_packet_info { 107struct slotinfo {
112 void *data_buffer;
113 u32 payload;
114#define PTD_FIRE_NEXT (1 << 0)
115#define PTD_URB_FINISHED (1 << 1)
116 struct urb *urb;
117 struct isp1760_qh *qh; 108 struct isp1760_qh *qh;
118 struct isp1760_qtd *qtd; 109 struct isp1760_qtd *qtd;
119}; 110};
@@ -122,15 +113,6 @@ struct inter_packet_info {
122typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh, 113typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh,
123 struct isp1760_qtd *qtd); 114 struct isp1760_qtd *qtd);
124 115
125#define isp1760_dbg(priv, fmt, args...) \
126 dev_dbg(priv_to_hcd(priv)->self.controller, fmt, ##args)
127
128#define isp1760_info(priv, fmt, args...) \
129 dev_info(priv_to_hcd(priv)->self.controller, fmt, ##args)
130
131#define isp1760_err(priv, fmt, args...) \
132 dev_err(priv_to_hcd(priv)->self.controller, fmt, ##args)
133
134/* 116/*
135 * Device flags that can vary from board to board. All of these 117 * Device flags that can vary from board to board. All of these
136 * indicate the most "atypical" case, so that a devflags of 0 is 118 * indicate the most "atypical" case, so that a devflags of 0 is
@@ -167,63 +149,57 @@ struct memory_chunk {
167#define BLOCK_2_SIZE 1024 149#define BLOCK_2_SIZE 1024
168#define BLOCK_3_SIZE 8192 150#define BLOCK_3_SIZE 8192
169#define BLOCKS (BLOCK_1_NUM + BLOCK_2_NUM + BLOCK_3_NUM) 151#define BLOCKS (BLOCK_1_NUM + BLOCK_2_NUM + BLOCK_3_NUM)
170#define PAYLOAD_SIZE 0xf000 152#define MAX_PAYLOAD_SIZE BLOCK_3_SIZE
171 153#define PAYLOAD_AREA_SIZE 0xf000
172/* I saw if some reloads if the pointer was negative */
173#define ISP1760_NULL_POINTER (0x400)
174 154
175/* ATL */ 155/* ATL */
176/* DW0 */ 156/* DW0 */
177#define PTD_VALID 1 157#define DW0_VALID_BIT 1
178#define PTD_LENGTH(x) (((u32) x) << 3) 158#define FROM_DW0_VALID(x) ((x) & 0x01)
179#define PTD_MAXPACKET(x) (((u32) x) << 18) 159#define TO_DW0_LENGTH(x) (((u32) x) << 3)
180#define PTD_MULTI(x) (((u32) x) << 29) 160#define TO_DW0_MAXPACKET(x) (((u32) x) << 18)
181#define PTD_ENDPOINT(x) (((u32) x) << 31) 161#define TO_DW0_MULTI(x) (((u32) x) << 29)
162#define TO_DW0_ENDPOINT(x) (((u32) x) << 31)
182/* DW1 */ 163/* DW1 */
183#define PTD_DEVICE_ADDR(x) (((u32) x) << 3) 164#define TO_DW1_DEVICE_ADDR(x) (((u32) x) << 3)
184#define PTD_PID_TOKEN(x) (((u32) x) << 10) 165#define TO_DW1_PID_TOKEN(x) (((u32) x) << 10)
185#define PTD_TRANS_BULK ((u32) 2 << 12) 166#define DW1_TRANS_BULK ((u32) 2 << 12)
186#define PTD_TRANS_INT ((u32) 3 << 12) 167#define DW1_TRANS_INT ((u32) 3 << 12)
187#define PTD_TRANS_SPLIT ((u32) 1 << 14) 168#define DW1_TRANS_SPLIT ((u32) 1 << 14)
188#define PTD_SE_USB_LOSPEED ((u32) 2 << 16) 169#define DW1_SE_USB_LOSPEED ((u32) 2 << 16)
189#define PTD_PORT_NUM(x) (((u32) x) << 18) 170#define TO_DW1_PORT_NUM(x) (((u32) x) << 18)
190#define PTD_HUB_NUM(x) (((u32) x) << 25) 171#define TO_DW1_HUB_NUM(x) (((u32) x) << 25)
191#define PTD_PING(x) (((u32) x) << 26)
192/* DW2 */ 172/* DW2 */
193#define PTD_RL_CNT(x) (((u32) x) << 25) 173#define TO_DW2_DATA_START_ADDR(x) (((u32) x) << 8)
194#define PTD_DATA_START_ADDR(x) (((u32) x) << 8) 174#define TO_DW2_RL(x) ((x) << 25)
195#define BASE_ADDR 0x1000 175#define FROM_DW2_RL(x) (((x) >> 25) & 0xf)
196/* DW3 */ 176/* DW3 */
197#define PTD_CERR(x) (((u32) x) << 23) 177#define FROM_DW3_NRBYTESTRANSFERRED(x) ((x) & 0x7fff)
198#define PTD_NAC_CNT(x) (((u32) x) << 19) 178#define FROM_DW3_SCS_NRBYTESTRANSFERRED(x) ((x) & 0x07ff)
199#define PTD_ACTIVE ((u32) 1 << 31) 179#define TO_DW3_NAKCOUNT(x) ((x) << 19)
200#define PTD_DATA_TOGGLE(x) (((u32) x) << 25) 180#define FROM_DW3_NAKCOUNT(x) (((x) >> 19) & 0xf)
201 181#define TO_DW3_CERR(x) ((x) << 23)
202#define DW3_HALT_BIT (1 << 30) 182#define FROM_DW3_CERR(x) (((x) >> 23) & 0x3)
183#define TO_DW3_DATA_TOGGLE(x) ((x) << 25)
184#define FROM_DW3_DATA_TOGGLE(x) (((x) >> 25) & 0x1)
185#define TO_DW3_PING(x) ((x) << 26)
186#define FROM_DW3_PING(x) (((x) >> 26) & 0x1)
203#define DW3_ERROR_BIT (1 << 28) 187#define DW3_ERROR_BIT (1 << 28)
204#define DW3_QTD_ACTIVE (1 << 31) 188#define DW3_BABBLE_BIT (1 << 29)
189#define DW3_HALT_BIT (1 << 30)
190#define DW3_ACTIVE_BIT (1 << 31)
205 191
206#define INT_UNDERRUN (1 << 2) 192#define INT_UNDERRUN (1 << 2)
207#define INT_BABBLE (1 << 1) 193#define INT_BABBLE (1 << 1)
208#define INT_EXACT (1 << 0) 194#define INT_EXACT (1 << 0)
209 195
210#define DW1_GET_PID(x) (((x) >> 10) & 0x3)
211#define PTD_XFERRED_LENGTH(x) ((x) & 0x7fff)
212#define PTD_XFERRED_LENGTH_LO(x) ((x) & 0x7ff)
213
214#define SETUP_PID (2) 196#define SETUP_PID (2)
215#define IN_PID (1) 197#define IN_PID (1)
216#define OUT_PID (0) 198#define OUT_PID (0)
217#define GET_QTD_TOKEN_TYPE(x) ((x) & 0x3)
218
219#define DATA_TOGGLE (1 << 31)
220#define GET_DATA_TOGGLE(x) ((x) >> 31)
221 199
222/* Errata 1 */ 200/* Errata 1 */
223#define RL_COUNTER (0) 201#define RL_COUNTER (0)
224#define NAK_COUNTER (0) 202#define NAK_COUNTER (0)
225#define ERR_COUNTER (2) 203#define ERR_COUNTER (2)
226 204
227#define HC_ATL_PL_SIZE (8192) 205#endif /* _ISP1760_HCD_H_ */
228
229#endif
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index 3b28dbfca058..7ee30056f373 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -27,8 +27,7 @@
27#endif 27#endif
28 28
29#ifdef CONFIG_PPC_OF 29#ifdef CONFIG_PPC_OF
30static int of_isp1760_probe(struct platform_device *dev, 30static int of_isp1760_probe(struct platform_device *dev)
31 const struct of_device_id *match)
32{ 31{
33 struct usb_hcd *hcd; 32 struct usb_hcd *hcd;
34 struct device_node *dp = dev->dev.of_node; 33 struct device_node *dp = dev->dev.of_node;
@@ -119,7 +118,7 @@ static const struct of_device_id of_isp1760_match[] = {
119}; 118};
120MODULE_DEVICE_TABLE(of, of_isp1760_match); 119MODULE_DEVICE_TABLE(of, of_isp1760_match);
121 120
122static struct of_platform_driver isp1760_of_driver = { 121static struct platform_driver isp1760_of_driver = {
123 .driver = { 122 .driver = {
124 .name = "nxp-isp1760", 123 .name = "nxp-isp1760",
125 .owner = THIS_MODULE, 124 .owner = THIS_MODULE,
@@ -398,7 +397,7 @@ static int __init isp1760_init(void)
398 if (!ret) 397 if (!ret)
399 any_ret = 0; 398 any_ret = 0;
400#ifdef CONFIG_PPC_OF 399#ifdef CONFIG_PPC_OF
401 ret = of_register_platform_driver(&isp1760_of_driver); 400 ret = platform_driver_register(&isp1760_of_driver);
402 if (!ret) 401 if (!ret)
403 any_ret = 0; 402 any_ret = 0;
404#endif 403#endif
@@ -418,7 +417,7 @@ static void __exit isp1760_exit(void)
418{ 417{
419 platform_driver_unregister(&isp1760_plat_driver); 418 platform_driver_unregister(&isp1760_plat_driver);
420#ifdef CONFIG_PPC_OF 419#ifdef CONFIG_PPC_OF
421 of_unregister_platform_driver(&isp1760_of_driver); 420 platform_driver_unregister(&isp1760_of_driver);
422#endif 421#endif
423#ifdef CONFIG_PCI 422#ifdef CONFIG_PCI
424 pci_unregister_driver(&isp1761_pci_driver); 423 pci_unregister_driver(&isp1761_pci_driver);
diff --git a/drivers/usb/host/octeon2-common.c b/drivers/usb/host/octeon2-common.c
new file mode 100644
index 000000000000..d9df423f3d12
--- /dev/null
+++ b/drivers/usb/host/octeon2-common.c
@@ -0,0 +1,200 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2010, 2011 Cavium Networks
7 */
8
9#include <linux/module.h>
10#include <linux/mutex.h>
11#include <linux/delay.h>
12
13#include <asm/octeon/octeon.h>
14#include <asm/octeon/cvmx-uctlx-defs.h>
15
16static DEFINE_MUTEX(octeon2_usb_clocks_mutex);
17
18static int octeon2_usb_clock_start_cnt;
19
20void octeon2_usb_clocks_start(void)
21{
22 u64 div;
23 union cvmx_uctlx_if_ena if_ena;
24 union cvmx_uctlx_clk_rst_ctl clk_rst_ctl;
25 union cvmx_uctlx_uphy_ctl_status uphy_ctl_status;
26 union cvmx_uctlx_uphy_portx_ctl_status port_ctl_status;
27 int i;
28 unsigned long io_clk_64_to_ns;
29
30
31 mutex_lock(&octeon2_usb_clocks_mutex);
32
33 octeon2_usb_clock_start_cnt++;
34 if (octeon2_usb_clock_start_cnt != 1)
35 goto exit;
36
37 io_clk_64_to_ns = 64000000000ull / octeon_get_io_clock_rate();
38
39 /*
40 * Step 1: Wait for voltages stable. That surely happened
41 * before starting the kernel.
42 *
43 * Step 2: Enable SCLK of UCTL by writing UCTL0_IF_ENA[EN] = 1
44 */
45 if_ena.u64 = 0;
46 if_ena.s.en = 1;
47 cvmx_write_csr(CVMX_UCTLX_IF_ENA(0), if_ena.u64);
48
49 /* Step 3: Configure the reference clock, PHY, and HCLK */
50 clk_rst_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_CLK_RST_CTL(0));
51
52 /*
53 * If the UCTL looks like it has already been started, skip
54 * the initialization, otherwise bus errors are obtained.
55 */
56 if (clk_rst_ctl.s.hrst)
57 goto end_clock;
58 /* 3a */
59 clk_rst_ctl.s.p_por = 1;
60 clk_rst_ctl.s.hrst = 0;
61 clk_rst_ctl.s.p_prst = 0;
62 clk_rst_ctl.s.h_clkdiv_rst = 0;
63 clk_rst_ctl.s.o_clkdiv_rst = 0;
64 clk_rst_ctl.s.h_clkdiv_en = 0;
65 clk_rst_ctl.s.o_clkdiv_en = 0;
66 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
67
68 /* 3b */
69 /* 12MHz crystal. */
70 clk_rst_ctl.s.p_refclk_sel = 0;
71 clk_rst_ctl.s.p_refclk_div = 0;
72 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
73
74 /* 3c */
75 div = octeon_get_io_clock_rate() / 130000000ull;
76
77 switch (div) {
78 case 0:
79 div = 1;
80 break;
81 case 1:
82 case 2:
83 case 3:
84 case 4:
85 break;
86 case 5:
87 div = 4;
88 break;
89 case 6:
90 case 7:
91 div = 6;
92 break;
93 case 8:
94 case 9:
95 case 10:
96 case 11:
97 div = 8;
98 break;
99 default:
100 div = 12;
101 break;
102 }
103 clk_rst_ctl.s.h_div = div;
104 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
105 /* Read it back, */
106 clk_rst_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_CLK_RST_CTL(0));
107 clk_rst_ctl.s.h_clkdiv_en = 1;
108 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
109 /* 3d */
110 clk_rst_ctl.s.h_clkdiv_rst = 1;
111 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
112
113 /* 3e: delay 64 io clocks */
114 ndelay(io_clk_64_to_ns);
115
116 /*
117 * Step 4: Program the power-on reset field in the UCTL
118 * clock-reset-control register.
119 */
120 clk_rst_ctl.s.p_por = 0;
121 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
122
123 /* Step 5: Wait 1 ms for the PHY clock to start. */
124 mdelay(1);
125
126 /*
127 * Step 6: Program the reset input from automatic test
128 * equipment field in the UPHY CSR
129 */
130 uphy_ctl_status.u64 = cvmx_read_csr(CVMX_UCTLX_UPHY_CTL_STATUS(0));
131 uphy_ctl_status.s.ate_reset = 1;
132 cvmx_write_csr(CVMX_UCTLX_UPHY_CTL_STATUS(0), uphy_ctl_status.u64);
133
134 /* Step 7: Wait for at least 10ns. */
135 ndelay(10);
136
137 /* Step 8: Clear the ATE_RESET field in the UPHY CSR. */
138 uphy_ctl_status.s.ate_reset = 0;
139 cvmx_write_csr(CVMX_UCTLX_UPHY_CTL_STATUS(0), uphy_ctl_status.u64);
140
141 /*
142 * Step 9: Wait for at least 20ns for UPHY to output PHY clock
143 * signals and OHCI_CLK48
144 */
145 ndelay(20);
146
147 /* Step 10: Configure the OHCI_CLK48 and OHCI_CLK12 clocks. */
148 /* 10a */
149 clk_rst_ctl.s.o_clkdiv_rst = 1;
150 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
151
152 /* 10b */
153 clk_rst_ctl.s.o_clkdiv_en = 1;
154 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
155
156 /* 10c */
157 ndelay(io_clk_64_to_ns);
158
159 /*
160 * Step 11: Program the PHY reset field:
161 * UCTL0_CLK_RST_CTL[P_PRST] = 1
162 */
163 clk_rst_ctl.s.p_prst = 1;
164 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
165
166 /* Step 12: Wait 1 uS. */
167 udelay(1);
168
169 /* Step 13: Program the HRESET_N field: UCTL0_CLK_RST_CTL[HRST] = 1 */
170 clk_rst_ctl.s.hrst = 1;
171 cvmx_write_csr(CVMX_UCTLX_CLK_RST_CTL(0), clk_rst_ctl.u64);
172
173end_clock:
174 /* Now we can set some other registers. */
175
176 for (i = 0; i <= 1; i++) {
177 port_ctl_status.u64 =
178 cvmx_read_csr(CVMX_UCTLX_UPHY_PORTX_CTL_STATUS(i, 0));
179 /* Set txvreftune to 15 to obtain compliant 'eye' diagram. */
180 port_ctl_status.s.txvreftune = 15;
181 port_ctl_status.s.txrisetune = 1;
182 port_ctl_status.s.txpreemphasistune = 1;
183 cvmx_write_csr(CVMX_UCTLX_UPHY_PORTX_CTL_STATUS(i, 0),
184 port_ctl_status.u64);
185 }
186
187 /* Set uSOF cycle period to 60,000 bits. */
188 cvmx_write_csr(CVMX_UCTLX_EHCI_FLA(0), 0x20ull);
189exit:
190 mutex_unlock(&octeon2_usb_clocks_mutex);
191}
192EXPORT_SYMBOL(octeon2_usb_clocks_start);
193
194void octeon2_usb_clocks_stop(void)
195{
196 mutex_lock(&octeon2_usb_clocks_mutex);
197 octeon2_usb_clock_start_cnt--;
198 mutex_unlock(&octeon2_usb_clocks_mutex);
199}
200EXPORT_SYMBOL(octeon2_usb_clocks_stop);
diff --git a/drivers/usb/host/ohci-ath79.c b/drivers/usb/host/ohci-ath79.c
new file mode 100644
index 000000000000..ffea3e7cb0a8
--- /dev/null
+++ b/drivers/usb/host/ohci-ath79.c
@@ -0,0 +1,151 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * Bus Glue for Atheros AR71XX/AR724X built-in OHCI controller.
5 *
6 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
7 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
8 *
9 * Parts of this file are based on Atheros' 2.6.15 BSP
10 * Copyright (C) 2007 Atheros Communications, Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published
14 * by the Free Software Foundation.
15 */
16
17#include <linux/platform_device.h>
18
19static int __devinit ohci_ath79_start(struct usb_hcd *hcd)
20{
21 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
22 int ret;
23
24 ret = ohci_init(ohci);
25 if (ret < 0)
26 return ret;
27
28 ret = ohci_run(ohci);
29 if (ret < 0)
30 goto err;
31
32 return 0;
33
34err:
35 ohci_stop(hcd);
36 return ret;
37}
38
39static const struct hc_driver ohci_ath79_hc_driver = {
40 .description = hcd_name,
41 .product_desc = "Atheros built-in OHCI controller",
42 .hcd_priv_size = sizeof(struct ohci_hcd),
43
44 .irq = ohci_irq,
45 .flags = HCD_USB11 | HCD_MEMORY,
46
47 .start = ohci_ath79_start,
48 .stop = ohci_stop,
49 .shutdown = ohci_shutdown,
50
51 .urb_enqueue = ohci_urb_enqueue,
52 .urb_dequeue = ohci_urb_dequeue,
53 .endpoint_disable = ohci_endpoint_disable,
54
55 /*
56 * scheduling support
57 */
58 .get_frame_number = ohci_get_frame,
59
60 /*
61 * root hub support
62 */
63 .hub_status_data = ohci_hub_status_data,
64 .hub_control = ohci_hub_control,
65 .start_port_reset = ohci_start_port_reset,
66};
67
68static int ohci_ath79_probe(struct platform_device *pdev)
69{
70 struct usb_hcd *hcd;
71 struct resource *res;
72 int irq;
73 int ret;
74
75 if (usb_disabled())
76 return -ENODEV;
77
78 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
79 if (!res) {
80 dev_dbg(&pdev->dev, "no IRQ specified\n");
81 return -ENODEV;
82 }
83 irq = res->start;
84
85 hcd = usb_create_hcd(&ohci_ath79_hc_driver, &pdev->dev,
86 dev_name(&pdev->dev));
87 if (!hcd)
88 return -ENOMEM;
89
90 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
91 if (!res) {
92 dev_dbg(&pdev->dev, "no base address specified\n");
93 ret = -ENODEV;
94 goto err_put_hcd;
95 }
96 hcd->rsrc_start = res->start;
97 hcd->rsrc_len = res->end - res->start + 1;
98
99 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
100 dev_dbg(&pdev->dev, "controller already in use\n");
101 ret = -EBUSY;
102 goto err_put_hcd;
103 }
104
105 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
106 if (!hcd->regs) {
107 dev_dbg(&pdev->dev, "error mapping memory\n");
108 ret = -EFAULT;
109 goto err_release_region;
110 }
111
112 ohci_hcd_init(hcd_to_ohci(hcd));
113
114 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
115 if (ret)
116 goto err_stop_hcd;
117
118 return 0;
119
120err_stop_hcd:
121 iounmap(hcd->regs);
122err_release_region:
123 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
124err_put_hcd:
125 usb_put_hcd(hcd);
126 return ret;
127}
128
129static int ohci_ath79_remove(struct platform_device *pdev)
130{
131 struct usb_hcd *hcd = platform_get_drvdata(pdev);
132
133 usb_remove_hcd(hcd);
134 iounmap(hcd->regs);
135 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
136 usb_put_hcd(hcd);
137
138 return 0;
139}
140
141static struct platform_driver ohci_hcd_ath79_driver = {
142 .probe = ohci_ath79_probe,
143 .remove = ohci_ath79_remove,
144 .shutdown = usb_hcd_platform_shutdown,
145 .driver = {
146 .name = "ath79-ohci",
147 .owner = THIS_MODULE,
148 },
149};
150
151MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ath79-ohci");
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 17a6043c1fa0..958d985f2951 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -33,7 +33,7 @@
33 33
34#ifdef __LITTLE_ENDIAN 34#ifdef __LITTLE_ENDIAN
35#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C) 35#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
36#elif __BIG_ENDIAN 36#elif defined(__BIG_ENDIAN)
37#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \ 37#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \
38 USBH_ENABLE_BE) 38 USBH_ENABLE_BE)
39#else 39#else
diff --git a/drivers/usb/host/ohci-cns3xxx.c b/drivers/usb/host/ohci-cns3xxx.c
new file mode 100644
index 000000000000..f05ef87e934c
--- /dev/null
+++ b/drivers/usb/host/ohci-cns3xxx.c
@@ -0,0 +1,165 @@
1/*
2 * Copyright 2008 Cavium Networks
3 *
4 * This file is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, Version 2, as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/platform_device.h>
10#include <linux/atomic.h>
11#include <mach/cns3xxx.h>
12#include <mach/pm.h>
13
14static int __devinit
15cns3xxx_ohci_start(struct usb_hcd *hcd)
16{
17 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
18 int ret;
19
20 /*
21 * EHCI and OHCI share the same clock and power,
22 * resetting twice would cause the 1st controller been reset.
23 * Therefore only do power up at the first up device, and
24 * power down at the last down device.
25 *
26 * Set USB AHB INCR length to 16
27 */
28 if (atomic_inc_return(&usb_pwr_ref) == 1) {
29 cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
30 cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
31 cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST);
32 __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG) | (0X2 << 24)),
33 MISC_CHIP_CONFIG_REG);
34 }
35
36 ret = ohci_init(ohci);
37 if (ret < 0)
38 return ret;
39
40 ohci->num_ports = 1;
41
42 ret = ohci_run(ohci);
43 if (ret < 0) {
44 err("can't start %s", hcd->self.bus_name);
45 ohci_stop(hcd);
46 return ret;
47 }
48 return 0;
49}
50
51static const struct hc_driver cns3xxx_ohci_hc_driver = {
52 .description = hcd_name,
53 .product_desc = "CNS3XXX OHCI Host controller",
54 .hcd_priv_size = sizeof(struct ohci_hcd),
55 .irq = ohci_irq,
56 .flags = HCD_USB11 | HCD_MEMORY,
57 .start = cns3xxx_ohci_start,
58 .stop = ohci_stop,
59 .shutdown = ohci_shutdown,
60 .urb_enqueue = ohci_urb_enqueue,
61 .urb_dequeue = ohci_urb_dequeue,
62 .endpoint_disable = ohci_endpoint_disable,
63 .get_frame_number = ohci_get_frame,
64 .hub_status_data = ohci_hub_status_data,
65 .hub_control = ohci_hub_control,
66#ifdef CONFIG_PM
67 .bus_suspend = ohci_bus_suspend,
68 .bus_resume = ohci_bus_resume,
69#endif
70 .start_port_reset = ohci_start_port_reset,
71};
72
73static int cns3xxx_ohci_probe(struct platform_device *pdev)
74{
75 struct device *dev = &pdev->dev;
76 struct usb_hcd *hcd;
77 const struct hc_driver *driver = &cns3xxx_ohci_hc_driver;
78 struct resource *res;
79 int irq;
80 int retval;
81
82 if (usb_disabled())
83 return -ENODEV;
84
85 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
86 if (!res) {
87 dev_err(dev, "Found HC with no IRQ.\n");
88 return -ENODEV;
89 }
90 irq = res->start;
91
92 hcd = usb_create_hcd(driver, dev, dev_name(dev));
93 if (!hcd)
94 return -ENOMEM;
95
96 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
97 if (!res) {
98 dev_err(dev, "Found HC with no register addr.\n");
99 retval = -ENODEV;
100 goto err1;
101 }
102 hcd->rsrc_start = res->start;
103 hcd->rsrc_len = res->end - res->start + 1;
104
105 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
106 driver->description)) {
107 dev_dbg(dev, "controller already in use\n");
108 retval = -EBUSY;
109 goto err1;
110 }
111
112 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
113 if (!hcd->regs) {
114 dev_dbg(dev, "error mapping memory\n");
115 retval = -EFAULT;
116 goto err2;
117 }
118
119 ohci_hcd_init(hcd_to_ohci(hcd));
120
121 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
122 if (retval == 0)
123 return retval;
124
125 iounmap(hcd->regs);
126err2:
127 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
128err1:
129 usb_put_hcd(hcd);
130 return retval;
131}
132
133static int cns3xxx_ohci_remove(struct platform_device *pdev)
134{
135 struct usb_hcd *hcd = platform_get_drvdata(pdev);
136
137 usb_remove_hcd(hcd);
138 iounmap(hcd->regs);
139 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
140
141 /*
142 * EHCI and OHCI share the same clock and power,
143 * resetting twice would cause the 1st controller been reset.
144 * Therefore only do power up at the first up device, and
145 * power down at the last down device.
146 */
147 if (atomic_dec_return(&usb_pwr_ref) == 0)
148 cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
149
150 usb_put_hcd(hcd);
151
152 platform_set_drvdata(pdev, NULL);
153
154 return 0;
155}
156
157MODULE_ALIAS("platform:cns3xxx-ohci");
158
159static struct platform_driver ohci_hcd_cns3xxx_driver = {
160 .probe = cns3xxx_ohci_probe,
161 .remove = cns3xxx_ohci_remove,
162 .driver = {
163 .name = "cns3xxx-ohci",
164 },
165};
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 36abd2baa3ea..d7d34492934a 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -413,18 +413,21 @@ static const struct file_operations debug_async_fops = {
413 .open = debug_async_open, 413 .open = debug_async_open,
414 .read = debug_output, 414 .read = debug_output,
415 .release = debug_close, 415 .release = debug_close,
416 .llseek = default_llseek,
416}; 417};
417static const struct file_operations debug_periodic_fops = { 418static const struct file_operations debug_periodic_fops = {
418 .owner = THIS_MODULE, 419 .owner = THIS_MODULE,
419 .open = debug_periodic_open, 420 .open = debug_periodic_open,
420 .read = debug_output, 421 .read = debug_output,
421 .release = debug_close, 422 .release = debug_close,
423 .llseek = default_llseek,
422}; 424};
423static const struct file_operations debug_registers_fops = { 425static const struct file_operations debug_registers_fops = {
424 .owner = THIS_MODULE, 426 .owner = THIS_MODULE,
425 .open = debug_registers_open, 427 .open = debug_registers_open,
426 .read = debug_output, 428 .read = debug_output,
427 .release = debug_close, 429 .release = debug_close,
430 .llseek = default_llseek,
428}; 431};
429 432
430static struct dentry *ohci_debug_root; 433static struct dentry *ohci_debug_root;
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index c3b4ccc7337b..f9cf3f04b742 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1,5 +1,7 @@
1/* 1/*
2 * OHCI HCD (Host Controller Driver) for USB. 2 * Open Host Controller Interface (OHCI) driver for USB.
3 *
4 * Maintainer: Alan Stern <stern@rowland.harvard.edu>
3 * 5 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 6 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> 7 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
@@ -75,6 +77,7 @@ static const char hcd_name [] = "ohci_hcd";
75#define STATECHANGE_DELAY msecs_to_jiffies(300) 77#define STATECHANGE_DELAY msecs_to_jiffies(300)
76 78
77#include "ohci.h" 79#include "ohci.h"
80#include "pci-quirks.h"
78 81
79static void ohci_dump (struct ohci_hcd *ohci, int verbose); 82static void ohci_dump (struct ohci_hcd *ohci, int verbose);
80static int ohci_init (struct ohci_hcd *ohci); 83static int ohci_init (struct ohci_hcd *ohci);
@@ -85,18 +88,8 @@ static int ohci_restart (struct ohci_hcd *ohci);
85#endif 88#endif
86 89
87#ifdef CONFIG_PCI 90#ifdef CONFIG_PCI
88static void quirk_amd_pll(int state);
89static void amd_iso_dev_put(void);
90static void sb800_prefetch(struct ohci_hcd *ohci, int on); 91static void sb800_prefetch(struct ohci_hcd *ohci, int on);
91#else 92#else
92static inline void quirk_amd_pll(int state)
93{
94 return;
95}
96static inline void amd_iso_dev_put(void)
97{
98 return;
99}
100static inline void sb800_prefetch(struct ohci_hcd *ohci, int on) 93static inline void sb800_prefetch(struct ohci_hcd *ohci, int on)
101{ 94{
102 return; 95 return;
@@ -171,7 +164,7 @@ static int ohci_urb_enqueue (
171 // case PIPE_INTERRUPT: 164 // case PIPE_INTERRUPT:
172 // case PIPE_BULK: 165 // case PIPE_BULK:
173 default: 166 default:
174 /* one TD for every 4096 Bytes (can be upto 8K) */ 167 /* one TD for every 4096 Bytes (can be up to 8K) */
175 size += urb->transfer_buffer_length / 4096; 168 size += urb->transfer_buffer_length / 4096;
176 /* ... and for any remaining bytes ... */ 169 /* ... and for any remaining bytes ... */
177 if ((urb->transfer_buffer_length % 4096) != 0) 170 if ((urb->transfer_buffer_length % 4096) != 0)
@@ -370,7 +363,6 @@ sanitize:
370 } 363 }
371 ep->hcpriv = NULL; 364 ep->hcpriv = NULL;
372 spin_unlock_irqrestore (&ohci->lock, flags); 365 spin_unlock_irqrestore (&ohci->lock, flags);
373 return;
374} 366}
375 367
376static int ohci_get_frame (struct usb_hcd *hcd) 368static int ohci_get_frame (struct usb_hcd *hcd)
@@ -398,7 +390,14 @@ ohci_shutdown (struct usb_hcd *hcd)
398 390
399 ohci = hcd_to_ohci (hcd); 391 ohci = hcd_to_ohci (hcd);
400 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 392 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
401 ohci_usb_reset (ohci); 393 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
394
395 /* If the SHUTDOWN quirk is set, don't put the controller in RESET */
396 ohci->hc_control &= (ohci->flags & OHCI_QUIRK_SHUTDOWN ?
397 OHCI_CTRL_RWC | OHCI_CTRL_HCFS :
398 OHCI_CTRL_RWC);
399 ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
400
402 /* flush the writes */ 401 /* flush the writes */
403 (void) ohci_readl (ohci, &ohci->regs->control); 402 (void) ohci_readl (ohci, &ohci->regs->control);
404} 403}
@@ -767,6 +766,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
767 if (ints == ~(u32)0) { 766 if (ints == ~(u32)0) {
768 disable (ohci); 767 disable (ohci);
769 ohci_dbg (ohci, "device removed!\n"); 768 ohci_dbg (ohci, "device removed!\n");
769 usb_hc_died(hcd);
770 return IRQ_HANDLED; 770 return IRQ_HANDLED;
771 } 771 }
772 772
@@ -774,7 +774,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
774 ints &= ohci_readl(ohci, &regs->intrenable); 774 ints &= ohci_readl(ohci, &regs->intrenable);
775 775
776 /* interrupt for some other device? */ 776 /* interrupt for some other device? */
777 if (ints == 0) 777 if (ints == 0 || unlikely(hcd->state == HC_STATE_HALT))
778 return IRQ_NOTMINE; 778 return IRQ_NOTMINE;
779 779
780 if (ints & OHCI_INTR_UE) { 780 if (ints & OHCI_INTR_UE) {
@@ -791,6 +791,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
791 } else { 791 } else {
792 disable (ohci); 792 disable (ohci);
793 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n"); 793 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
794 usb_hc_died(hcd);
794 } 795 }
795 796
796 ohci_dump (ohci, 1); 797 ohci_dump (ohci, 1);
@@ -895,7 +896,8 @@ static void ohci_stop (struct usb_hcd *hcd)
895 896
896 ohci_dump (ohci, 1); 897 ohci_dump (ohci, 1);
897 898
898 flush_scheduled_work(); 899 if (quirk_nec(ohci))
900 flush_work_sync(&ohci->nec_work);
899 901
900 ohci_usb_reset (ohci); 902 ohci_usb_reset (ohci);
901 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 903 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
@@ -905,7 +907,7 @@ static void ohci_stop (struct usb_hcd *hcd)
905 if (quirk_zfmicro(ohci)) 907 if (quirk_zfmicro(ohci))
906 del_timer(&ohci->unlink_watchdog); 908 del_timer(&ohci->unlink_watchdog);
907 if (quirk_amdiso(ohci)) 909 if (quirk_amdiso(ohci))
908 amd_iso_dev_put(); 910 usb_amd_dev_put();
909 911
910 remove_debug_files (ohci); 912 remove_debug_files (ohci);
911 ohci_mem_cleanup (ohci); 913 ohci_mem_cleanup (ohci);
@@ -1016,11 +1018,6 @@ MODULE_LICENSE ("GPL");
1016#define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver 1018#define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver
1017#endif 1019#endif
1018 1020
1019#ifdef CONFIG_ARCH_LH7A404
1020#include "ohci-lh7a404.c"
1021#define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
1022#endif
1023
1024#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx) 1021#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
1025#include "ohci-pxa27x.c" 1022#include "ohci-pxa27x.c"
1026#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver 1023#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
@@ -1061,10 +1058,7 @@ MODULE_LICENSE ("GPL");
1061#define PLATFORM_DRIVER ohci_hcd_da8xx_driver 1058#define PLATFORM_DRIVER ohci_hcd_da8xx_driver
1062#endif 1059#endif
1063 1060
1064#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 1061#ifdef CONFIG_USB_OHCI_SH
1065 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
1066 defined(CONFIG_CPU_SUBTYPE_SH7763) || \
1067 defined(CONFIG_CPU_SUBTYPE_SH7786)
1068#include "ohci-sh.c" 1062#include "ohci-sh.c"
1069#define PLATFORM_DRIVER ohci_hcd_sh_driver 1063#define PLATFORM_DRIVER ohci_hcd_sh_driver
1070#endif 1064#endif
@@ -1075,6 +1069,11 @@ MODULE_LICENSE ("GPL");
1075#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver 1069#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1076#endif 1070#endif
1077 1071
1072#ifdef CONFIG_PLAT_SPEAR
1073#include "ohci-spear.c"
1074#define PLATFORM_DRIVER spear_ohci_hcd_driver
1075#endif
1076
1078#ifdef CONFIG_PPC_PS3 1077#ifdef CONFIG_PPC_PS3
1079#include "ohci-ps3.c" 1078#include "ohci-ps3.c"
1080#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver 1079#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
@@ -1100,6 +1099,21 @@ MODULE_LICENSE ("GPL");
1100#define PLATFORM_DRIVER ohci_hcd_jz4740_driver 1099#define PLATFORM_DRIVER ohci_hcd_jz4740_driver
1101#endif 1100#endif
1102 1101
1102#ifdef CONFIG_USB_OCTEON_OHCI
1103#include "ohci-octeon.c"
1104#define PLATFORM_DRIVER ohci_octeon_driver
1105#endif
1106
1107#ifdef CONFIG_USB_CNS3XXX_OHCI
1108#include "ohci-cns3xxx.c"
1109#define PLATFORM_DRIVER ohci_hcd_cns3xxx_driver
1110#endif
1111
1112#ifdef CONFIG_USB_OHCI_ATH79
1113#include "ohci-ath79.c"
1114#define PLATFORM_DRIVER ohci_hcd_ath79_driver
1115#endif
1116
1103#if !defined(PCI_DRIVER) && \ 1117#if !defined(PCI_DRIVER) && \
1104 !defined(PLATFORM_DRIVER) && \ 1118 !defined(PLATFORM_DRIVER) && \
1105 !defined(OMAP1_PLATFORM_DRIVER) && \ 1119 !defined(OMAP1_PLATFORM_DRIVER) && \
@@ -1158,7 +1172,7 @@ static int __init ohci_hcd_mod_init(void)
1158#endif 1172#endif
1159 1173
1160#ifdef OF_PLATFORM_DRIVER 1174#ifdef OF_PLATFORM_DRIVER
1161 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER); 1175 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1162 if (retval < 0) 1176 if (retval < 0)
1163 goto error_of_platform; 1177 goto error_of_platform;
1164#endif 1178#endif
@@ -1217,7 +1231,7 @@ static int __init ohci_hcd_mod_init(void)
1217 error_sa1111: 1231 error_sa1111:
1218#endif 1232#endif
1219#ifdef OF_PLATFORM_DRIVER 1233#ifdef OF_PLATFORM_DRIVER
1220 of_unregister_platform_driver(&OF_PLATFORM_DRIVER); 1234 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1221 error_of_platform: 1235 error_of_platform:
1222#endif 1236#endif
1223#ifdef PLATFORM_DRIVER 1237#ifdef PLATFORM_DRIVER
@@ -1265,11 +1279,14 @@ static void __exit ohci_hcd_mod_exit(void)
1265 sa1111_driver_unregister(&SA1111_DRIVER); 1279 sa1111_driver_unregister(&SA1111_DRIVER);
1266#endif 1280#endif
1267#ifdef OF_PLATFORM_DRIVER 1281#ifdef OF_PLATFORM_DRIVER
1268 of_unregister_platform_driver(&OF_PLATFORM_DRIVER); 1282 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1269#endif 1283#endif
1270#ifdef PLATFORM_DRIVER 1284#ifdef PLATFORM_DRIVER
1271 platform_driver_unregister(&PLATFORM_DRIVER); 1285 platform_driver_unregister(&PLATFORM_DRIVER);
1272#endif 1286#endif
1287#ifdef OMAP3_PLATFORM_DRIVER
1288 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1289#endif
1273#ifdef PS3_SYSTEM_BUS_DRIVER 1290#ifdef PS3_SYSTEM_BUS_DRIVER
1274 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1291 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1275#endif 1292#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index cddcda95b579..9154615292db 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -580,15 +580,16 @@ ohci_hub_descriptor (
580 temp |= 0x0008; 580 temp |= 0x0008;
581 desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); 581 desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp);
582 582
583 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 583 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
584 rh = roothub_b (ohci); 584 rh = roothub_b (ohci);
585 memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); 585 memset(desc->u.hs.DeviceRemovable, 0xff,
586 desc->bitmap [0] = rh & RH_B_DR; 586 sizeof(desc->u.hs.DeviceRemovable));
587 desc->u.hs.DeviceRemovable[0] = rh & RH_B_DR;
587 if (ohci->num_ports > 7) { 588 if (ohci->num_ports > 7) {
588 desc->bitmap [1] = (rh & RH_B_DR) >> 8; 589 desc->u.hs.DeviceRemovable[1] = (rh & RH_B_DR) >> 8;
589 desc->bitmap [2] = 0xff; 590 desc->u.hs.DeviceRemovable[2] = 0xff;
590 } else 591 } else
591 desc->bitmap [1] = 0xff; 592 desc->u.hs.DeviceRemovable[1] = 0xff;
592} 593}
593 594
594/*-------------------------------------------------------------------------*/ 595/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-jz4740.c b/drivers/usb/host/ohci-jz4740.c
index 10e1872f3ab9..931d588c3fb5 100644
--- a/drivers/usb/host/ohci-jz4740.c
+++ b/drivers/usb/host/ohci-jz4740.c
@@ -273,4 +273,4 @@ static struct platform_driver ohci_hcd_jz4740_driver = {
273 }, 273 },
274}; 274};
275 275
276MODULE_ALIAS("platfrom:jz4740-ohci"); 276MODULE_ALIAS("platform:jz4740-ohci");
diff --git a/drivers/usb/host/ohci-lh7a404.c b/drivers/usb/host/ohci-lh7a404.c
deleted file mode 100644
index 18d39f0463ee..000000000000
--- a/drivers/usb/host/ohci-lh7a404.c
+++ /dev/null
@@ -1,252 +0,0 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
7 *
8 * Bus Glue for Sharp LH7A404
9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
12 *
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
15 *
16 * This file is licenced under the GPL.
17 */
18
19#include <linux/platform_device.h>
20#include <linux/signal.h>
21
22#include <mach/hardware.h>
23
24
25extern int usb_disabled(void);
26
27/*-------------------------------------------------------------------------*/
28
29static void lh7a404_start_hc(struct platform_device *dev)
30{
31 printk(KERN_DEBUG "%s: starting LH7A404 OHCI USB Controller\n",
32 __FILE__);
33
34 /*
35 * Now, carefully enable the USB clock, and take
36 * the USB host controller out of reset.
37 */
38 CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */
39 udelay(1000);
40 USBH_CMDSTATUS = OHCI_HCR;
41
42 printk(KERN_DEBUG "%s: Clock to USB host has been enabled \n", __FILE__);
43}
44
45static void lh7a404_stop_hc(struct platform_device *dev)
46{
47 printk(KERN_DEBUG "%s: stopping LH7A404 OHCI USB Controller\n",
48 __FILE__);
49
50 CSC_PWRCNT &= ~CSC_PWRCNT_USBH_EN; /* Disable clock */
51}
52
53
54/*-------------------------------------------------------------------------*/
55
56/* configure so an HC device and id are always provided */
57/* always called with process context; sleeping is OK */
58
59
60/**
61 * usb_hcd_lh7a404_probe - initialize LH7A404-based HCDs
62 * Context: !in_interrupt()
63 *
64 * Allocates basic resources for this USB host controller, and
65 * then invokes the start() method for the HCD associated with it
66 * through the hotplug entry's driver_data.
67 *
68 */
69int usb_hcd_lh7a404_probe (const struct hc_driver *driver,
70 struct platform_device *dev)
71{
72 int retval;
73 struct usb_hcd *hcd;
74
75 if (dev->resource[1].flags != IORESOURCE_IRQ) {
76 pr_debug("resource[1] is not IORESOURCE_IRQ");
77 return -ENOMEM;
78 }
79
80 hcd = usb_create_hcd(driver, &dev->dev, "lh7a404");
81 if (!hcd)
82 return -ENOMEM;
83 hcd->rsrc_start = dev->resource[0].start;
84 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
85
86 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
87 pr_debug("request_mem_region failed");
88 retval = -EBUSY;
89 goto err1;
90 }
91
92 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
93 if (!hcd->regs) {
94 pr_debug("ioremap failed");
95 retval = -ENOMEM;
96 goto err2;
97 }
98
99 lh7a404_start_hc(dev);
100 ohci_hcd_init(hcd_to_ohci(hcd));
101
102 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
103 if (retval == 0)
104 return retval;
105
106 lh7a404_stop_hc(dev);
107 iounmap(hcd->regs);
108 err2:
109 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
110 err1:
111 usb_put_hcd(hcd);
112 return retval;
113}
114
115
116/* may be called without controller electrically present */
117/* may be called with controller, bus, and devices active */
118
119/**
120 * usb_hcd_lh7a404_remove - shutdown processing for LH7A404-based HCDs
121 * @dev: USB Host Controller being removed
122 * Context: !in_interrupt()
123 *
124 * Reverses the effect of usb_hcd_lh7a404_probe(), first invoking
125 * the HCD's stop() method. It is always called from a thread
126 * context, normally "rmmod", "apmd", or something similar.
127 *
128 */
129void usb_hcd_lh7a404_remove (struct usb_hcd *hcd, struct platform_device *dev)
130{
131 usb_remove_hcd(hcd);
132 lh7a404_stop_hc(dev);
133 iounmap(hcd->regs);
134 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
135 usb_put_hcd(hcd);
136}
137
138/*-------------------------------------------------------------------------*/
139
140static int __devinit
141ohci_lh7a404_start (struct usb_hcd *hcd)
142{
143 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
144 int ret;
145
146 ohci_dbg (ohci, "ohci_lh7a404_start, ohci:%p", ohci);
147 if ((ret = ohci_init(ohci)) < 0)
148 return ret;
149
150 if ((ret = ohci_run (ohci)) < 0) {
151 err ("can't start %s", hcd->self.bus_name);
152 ohci_stop (hcd);
153 return ret;
154 }
155 return 0;
156}
157
158/*-------------------------------------------------------------------------*/
159
160static const struct hc_driver ohci_lh7a404_hc_driver = {
161 .description = hcd_name,
162 .product_desc = "LH7A404 OHCI",
163 .hcd_priv_size = sizeof(struct ohci_hcd),
164
165 /*
166 * generic hardware linkage
167 */
168 .irq = ohci_irq,
169 .flags = HCD_USB11 | HCD_MEMORY,
170
171 /*
172 * basic lifecycle operations
173 */
174 .start = ohci_lh7a404_start,
175 .stop = ohci_stop,
176 .shutdown = ohci_shutdown,
177
178 /*
179 * managing i/o requests and associated device resources
180 */
181 .urb_enqueue = ohci_urb_enqueue,
182 .urb_dequeue = ohci_urb_dequeue,
183 .endpoint_disable = ohci_endpoint_disable,
184
185 /*
186 * scheduling support
187 */
188 .get_frame_number = ohci_get_frame,
189
190 /*
191 * root hub support
192 */
193 .hub_status_data = ohci_hub_status_data,
194 .hub_control = ohci_hub_control,
195#ifdef CONFIG_PM
196 .bus_suspend = ohci_bus_suspend,
197 .bus_resume = ohci_bus_resume,
198#endif
199 .start_port_reset = ohci_start_port_reset,
200};
201
202/*-------------------------------------------------------------------------*/
203
204static int ohci_hcd_lh7a404_drv_probe(struct platform_device *pdev)
205{
206 int ret;
207
208 pr_debug ("In ohci_hcd_lh7a404_drv_probe");
209
210 if (usb_disabled())
211 return -ENODEV;
212
213 ret = usb_hcd_lh7a404_probe(&ohci_lh7a404_hc_driver, pdev);
214 return ret;
215}
216
217static int ohci_hcd_lh7a404_drv_remove(struct platform_device *pdev)
218{
219 struct usb_hcd *hcd = platform_get_drvdata(pdev);
220
221 usb_hcd_lh7a404_remove(hcd, pdev);
222 return 0;
223}
224 /*TBD*/
225/*static int ohci_hcd_lh7a404_drv_suspend(struct platform_device *dev)
226{
227 struct usb_hcd *hcd = platform_get_drvdata(dev);
228
229 return 0;
230}
231static int ohci_hcd_lh7a404_drv_resume(struct platform_device *dev)
232{
233 struct usb_hcd *hcd = platform_get_drvdata(dev);
234
235
236 return 0;
237}
238*/
239
240static struct platform_driver ohci_hcd_lh7a404_driver = {
241 .probe = ohci_hcd_lh7a404_drv_probe,
242 .remove = ohci_hcd_lh7a404_drv_remove,
243 .shutdown = usb_hcd_platform_shutdown,
244 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */
245 /*.resume = ohci_hcd_lh7a404_drv_resume, */
246 .driver = {
247 .name = "lh7a404-ohci",
248 .owner = THIS_MODULE,
249 },
250};
251
252MODULE_ALIAS("platform:lh7a404-ohci");
diff --git a/drivers/usb/host/ohci-octeon.c b/drivers/usb/host/ohci-octeon.c
new file mode 100644
index 000000000000..e4ddfaf8870f
--- /dev/null
+++ b/drivers/usb/host/ohci-octeon.c
@@ -0,0 +1,214 @@
1/*
2 * EHCI HCD glue for Cavium Octeon II SOCs.
3 *
4 * Loosely based on ehci-au1xxx.c
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 *
10 * Copyright (C) 2010 Cavium Networks
11 *
12 */
13
14#include <linux/platform_device.h>
15
16#include <asm/octeon/octeon.h>
17#include <asm/octeon/cvmx-uctlx-defs.h>
18
19#define OCTEON_OHCI_HCD_NAME "octeon-ohci"
20
21/* Common clock init code. */
22void octeon2_usb_clocks_start(void);
23void octeon2_usb_clocks_stop(void);
24
25static void ohci_octeon_hw_start(void)
26{
27 union cvmx_uctlx_ohci_ctl ohci_ctl;
28
29 octeon2_usb_clocks_start();
30
31 ohci_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_OHCI_CTL(0));
32 ohci_ctl.s.l2c_addr_msb = 0;
33 ohci_ctl.s.l2c_buff_emod = 1; /* Byte swapped. */
34 ohci_ctl.s.l2c_desc_emod = 1; /* Byte swapped. */
35 cvmx_write_csr(CVMX_UCTLX_OHCI_CTL(0), ohci_ctl.u64);
36
37}
38
39static void ohci_octeon_hw_stop(void)
40{
41 /* Undo ohci_octeon_start() */
42 octeon2_usb_clocks_stop();
43}
44
45static int __devinit ohci_octeon_start(struct usb_hcd *hcd)
46{
47 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
48 int ret;
49
50 ret = ohci_init(ohci);
51
52 if (ret < 0)
53 return ret;
54
55 ret = ohci_run(ohci);
56
57 if (ret < 0) {
58 ohci_err(ohci, "can't start %s", hcd->self.bus_name);
59 ohci_stop(hcd);
60 return ret;
61 }
62
63 return 0;
64}
65
66static const struct hc_driver ohci_octeon_hc_driver = {
67 .description = hcd_name,
68 .product_desc = "Octeon OHCI",
69 .hcd_priv_size = sizeof(struct ohci_hcd),
70
71 /*
72 * generic hardware linkage
73 */
74 .irq = ohci_irq,
75 .flags = HCD_USB11 | HCD_MEMORY,
76
77 /*
78 * basic lifecycle operations
79 */
80 .start = ohci_octeon_start,
81 .stop = ohci_stop,
82 .shutdown = ohci_shutdown,
83
84 /*
85 * managing i/o requests and associated device resources
86 */
87 .urb_enqueue = ohci_urb_enqueue,
88 .urb_dequeue = ohci_urb_dequeue,
89 .endpoint_disable = ohci_endpoint_disable,
90
91 /*
92 * scheduling support
93 */
94 .get_frame_number = ohci_get_frame,
95
96 /*
97 * root hub support
98 */
99 .hub_status_data = ohci_hub_status_data,
100 .hub_control = ohci_hub_control,
101
102 .start_port_reset = ohci_start_port_reset,
103};
104
105static int ohci_octeon_drv_probe(struct platform_device *pdev)
106{
107 struct usb_hcd *hcd;
108 struct ohci_hcd *ohci;
109 void *reg_base;
110 struct resource *res_mem;
111 int irq;
112 int ret;
113
114 if (usb_disabled())
115 return -ENODEV;
116
117 irq = platform_get_irq(pdev, 0);
118 if (irq < 0) {
119 dev_err(&pdev->dev, "No irq assigned\n");
120 return -ENODEV;
121 }
122
123 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
124 if (res_mem == NULL) {
125 dev_err(&pdev->dev, "No register space assigned\n");
126 return -ENODEV;
127 }
128
129 /* Ohci is a 32-bit device. */
130 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
131 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
132
133 hcd = usb_create_hcd(&ohci_octeon_hc_driver, &pdev->dev, "octeon");
134 if (!hcd)
135 return -ENOMEM;
136
137 hcd->rsrc_start = res_mem->start;
138 hcd->rsrc_len = res_mem->end - res_mem->start + 1;
139
140 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
141 OCTEON_OHCI_HCD_NAME)) {
142 dev_err(&pdev->dev, "request_mem_region failed\n");
143 ret = -EBUSY;
144 goto err1;
145 }
146
147 reg_base = ioremap(hcd->rsrc_start, hcd->rsrc_len);
148 if (!reg_base) {
149 dev_err(&pdev->dev, "ioremap failed\n");
150 ret = -ENOMEM;
151 goto err2;
152 }
153
154 ohci_octeon_hw_start();
155
156 hcd->regs = reg_base;
157
158 ohci = hcd_to_ohci(hcd);
159
160 /* Octeon OHCI matches CPU endianness. */
161#ifdef __BIG_ENDIAN
162 ohci->flags |= OHCI_QUIRK_BE_MMIO;
163#endif
164
165 ohci_hcd_init(ohci);
166
167 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
168 if (ret) {
169 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
170 goto err3;
171 }
172
173 platform_set_drvdata(pdev, hcd);
174
175 return 0;
176
177err3:
178 ohci_octeon_hw_stop();
179
180 iounmap(hcd->regs);
181err2:
182 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
183err1:
184 usb_put_hcd(hcd);
185 return ret;
186}
187
188static int ohci_octeon_drv_remove(struct platform_device *pdev)
189{
190 struct usb_hcd *hcd = platform_get_drvdata(pdev);
191
192 usb_remove_hcd(hcd);
193
194 ohci_octeon_hw_stop();
195 iounmap(hcd->regs);
196 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
197 usb_put_hcd(hcd);
198
199 platform_set_drvdata(pdev, NULL);
200
201 return 0;
202}
203
204static struct platform_driver ohci_octeon_driver = {
205 .probe = ohci_octeon_drv_probe,
206 .remove = ohci_octeon_drv_remove,
207 .shutdown = usb_hcd_platform_shutdown,
208 .driver = {
209 .name = OCTEON_OHCI_HCD_NAME,
210 .owner = THIS_MODULE,
211 }
212};
213
214MODULE_ALIAS("platform:" OCTEON_OHCI_HCD_NAME);
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c
index 2cc8a504b18c..6048f2f64f73 100644
--- a/drivers/usb/host/ohci-omap3.c
+++ b/drivers/usb/host/ohci-omap3.c
@@ -7,6 +7,7 @@
7 * Copyright (C) 2007-2010 Texas Instruments, Inc. 7 * Copyright (C) 2007-2010 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 * 11 *
11 * Based on ehci-omap.c and some other ohci glue layers 12 * Based on ehci-omap.c and some other ohci glue layers
12 * 13 *
@@ -24,150 +25,15 @@
24 * along with this program; if not, write to the Free Software 25 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * 27 *
27 * TODO (last updated Mar 10th, 2010): 28 * TODO (last updated Feb 27, 2011):
28 * - add kernel-doc 29 * - add kernel-doc
29 * - Factor out code common to EHCI to a separate file
30 * - Make EHCI and OHCI coexist together
31 * - needs newer silicon versions to actually work
32 * - the last one to be loaded currently steps on the other's toes
33 * - Add hooks for configuring transceivers, etc. at init/exit
34 * - Add aggressive clock-management code
35 */ 30 */
36 31
37#include <linux/platform_device.h> 32#include <linux/platform_device.h>
38#include <linux/clk.h>
39
40#include <plat/usb.h> 33#include <plat/usb.h>
41 34
42/*
43 * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
44 * Use ohci_omap_readl()/ohci_omap_writel() functions
45 */
46
47/* TLL Register Set */
48#define OMAP_USBTLL_REVISION (0x00)
49#define OMAP_USBTLL_SYSCONFIG (0x10)
50#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
51#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
52#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
53#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
54#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
55
56#define OMAP_USBTLL_SYSSTATUS (0x14)
57#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
58
59#define OMAP_USBTLL_IRQSTATUS (0x18)
60#define OMAP_USBTLL_IRQENABLE (0x1C)
61
62#define OMAP_TLL_SHARED_CONF (0x30)
63#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
64#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
65#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
66#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
67#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
68
69#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
70#define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
71#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
72#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
73#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
74#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
75#define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1)
76#define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
77
78#define OMAP_TLL_CHANNEL_COUNT 3
79
80/* UHH Register Set */
81#define OMAP_UHH_REVISION (0x00)
82#define OMAP_UHH_SYSCONFIG (0x10)
83#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
84#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
85#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
86#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
87#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
88#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
89
90#define OMAP_UHH_SYSSTATUS (0x14)
91#define OMAP_UHH_SYSSTATUS_UHHRESETDONE (1 << 0)
92#define OMAP_UHH_SYSSTATUS_OHCIRESETDONE (1 << 1)
93#define OMAP_UHH_SYSSTATUS_EHCIRESETDONE (1 << 2)
94#define OMAP_UHH_HOSTCONFIG (0x40)
95#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
96#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
97#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
98#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
99#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
100#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
101#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
102#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
103#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
104#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
105#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
106
107#define OMAP_UHH_DEBUG_CSR (0x44)
108
109/*-------------------------------------------------------------------------*/ 35/*-------------------------------------------------------------------------*/
110 36
111static inline void ohci_omap_writel(void __iomem *base, u32 reg, u32 val)
112{
113 __raw_writel(val, base + reg);
114}
115
116static inline u32 ohci_omap_readl(void __iomem *base, u32 reg)
117{
118 return __raw_readl(base + reg);
119}
120
121static inline void ohci_omap_writeb(void __iomem *base, u8 reg, u8 val)
122{
123 __raw_writeb(val, base + reg);
124}
125
126static inline u8 ohci_omap_readb(void __iomem *base, u8 reg)
127{
128 return __raw_readb(base + reg);
129}
130
131/*-------------------------------------------------------------------------*/
132
133struct ohci_hcd_omap3 {
134 struct ohci_hcd *ohci;
135 struct device *dev;
136
137 struct clk *usbhost_ick;
138 struct clk *usbhost2_120m_fck;
139 struct clk *usbhost1_48m_fck;
140 struct clk *usbtll_fck;
141 struct clk *usbtll_ick;
142
143 /* port_mode: TLL/PHY, 2/3/4/6-PIN, DP-DM/DAT-SE0 */
144 enum ohci_omap3_port_mode port_mode[OMAP3_HS_USB_PORTS];
145 void __iomem *uhh_base;
146 void __iomem *tll_base;
147 void __iomem *ohci_base;
148
149 unsigned es2_compatibility:1;
150};
151
152/*-------------------------------------------------------------------------*/
153
154static void ohci_omap3_clock_power(struct ohci_hcd_omap3 *omap, int on)
155{
156 if (on) {
157 clk_enable(omap->usbtll_ick);
158 clk_enable(omap->usbtll_fck);
159 clk_enable(omap->usbhost_ick);
160 clk_enable(omap->usbhost1_48m_fck);
161 clk_enable(omap->usbhost2_120m_fck);
162 } else {
163 clk_disable(omap->usbhost2_120m_fck);
164 clk_disable(omap->usbhost1_48m_fck);
165 clk_disable(omap->usbhost_ick);
166 clk_disable(omap->usbtll_fck);
167 clk_disable(omap->usbtll_ick);
168 }
169}
170
171static int ohci_omap3_init(struct usb_hcd *hcd) 37static int ohci_omap3_init(struct usb_hcd *hcd)
172{ 38{
173 dev_dbg(hcd->self.controller, "starting OHCI controller\n"); 39 dev_dbg(hcd->self.controller, "starting OHCI controller\n");
@@ -175,7 +41,6 @@ static int ohci_omap3_init(struct usb_hcd *hcd)
175 return ohci_init(hcd_to_ohci(hcd)); 41 return ohci_init(hcd_to_ohci(hcd));
176} 42}
177 43
178
179/*-------------------------------------------------------------------------*/ 44/*-------------------------------------------------------------------------*/
180 45
181static int ohci_omap3_start(struct usb_hcd *hcd) 46static int ohci_omap3_start(struct usb_hcd *hcd)
@@ -202,325 +67,6 @@ static int ohci_omap3_start(struct usb_hcd *hcd)
202 67
203/*-------------------------------------------------------------------------*/ 68/*-------------------------------------------------------------------------*/
204 69
205/*
206 * convert the port-mode enum to a value we can use in the FSLSMODE
207 * field of USBTLL_CHANNEL_CONF
208 */
209static unsigned ohci_omap3_fslsmode(enum ohci_omap3_port_mode mode)
210{
211 switch (mode) {
212 case OMAP_OHCI_PORT_MODE_UNUSED:
213 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
214 return 0x0;
215
216 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
217 return 0x1;
218
219 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
220 return 0x2;
221
222 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
223 return 0x3;
224
225 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
226 return 0x4;
227
228 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
229 return 0x5;
230
231 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
232 return 0x6;
233
234 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
235 return 0x7;
236
237 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
238 return 0xA;
239
240 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
241 return 0xB;
242 default:
243 pr_warning("Invalid port mode, using default\n");
244 return 0x0;
245 }
246}
247
248static void ohci_omap3_tll_config(struct ohci_hcd_omap3 *omap)
249{
250 u32 reg;
251 int i;
252
253 /* Program TLL SHARED CONF */
254 reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
255 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
256 reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
257 reg |= OMAP_TLL_SHARED_CONF_USB_DIVRATION;
258 reg |= OMAP_TLL_SHARED_CONF_FCLK_IS_ON;
259 ohci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
260
261 /* Program each TLL channel */
262 /*
263 * REVISIT: Only the 3-pin and 4-pin PHY modes have
264 * actually been tested.
265 */
266 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
267
268 /* Enable only those channels that are actually used */
269 if (omap->port_mode[i] == OMAP_OHCI_PORT_MODE_UNUSED)
270 continue;
271
272 reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
273 reg |= ohci_omap3_fslsmode(omap->port_mode[i])
274 << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
275 reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
276 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
277 ohci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
278 }
279}
280
281/* omap3_start_ohci
282 * - Start the TI USBHOST controller
283 */
284static int omap3_start_ohci(struct ohci_hcd_omap3 *omap, struct usb_hcd *hcd)
285{
286 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
287 u32 reg = 0;
288 int ret = 0;
289
290 dev_dbg(omap->dev, "starting TI OHCI USB Controller\n");
291
292 /* Get all the clock handles we need */
293 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
294 if (IS_ERR(omap->usbhost_ick)) {
295 dev_err(omap->dev, "could not get usbhost_ick\n");
296 ret = PTR_ERR(omap->usbhost_ick);
297 goto err_host_ick;
298 }
299
300 omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck");
301 if (IS_ERR(omap->usbhost2_120m_fck)) {
302 dev_err(omap->dev, "could not get usbhost_120m_fck\n");
303 ret = PTR_ERR(omap->usbhost2_120m_fck);
304 goto err_host_120m_fck;
305 }
306
307 omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck");
308 if (IS_ERR(omap->usbhost1_48m_fck)) {
309 dev_err(omap->dev, "could not get usbhost_48m_fck\n");
310 ret = PTR_ERR(omap->usbhost1_48m_fck);
311 goto err_host_48m_fck;
312 }
313
314 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
315 if (IS_ERR(omap->usbtll_fck)) {
316 dev_err(omap->dev, "could not get usbtll_fck\n");
317 ret = PTR_ERR(omap->usbtll_fck);
318 goto err_tll_fck;
319 }
320
321 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
322 if (IS_ERR(omap->usbtll_ick)) {
323 dev_err(omap->dev, "could not get usbtll_ick\n");
324 ret = PTR_ERR(omap->usbtll_ick);
325 goto err_tll_ick;
326 }
327
328 /* Now enable all the clocks in the correct order */
329 ohci_omap3_clock_power(omap, 1);
330
331 /* perform TLL soft reset, and wait until reset is complete */
332 ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
333 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
334
335 /* Wait for TLL reset to complete */
336 while (!(ohci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
337 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
338 cpu_relax();
339
340 if (time_after(jiffies, timeout)) {
341 dev_dbg(omap->dev, "operation timed out\n");
342 ret = -EINVAL;
343 goto err_sys_status;
344 }
345 }
346
347 dev_dbg(omap->dev, "TLL reset done\n");
348
349 /* (1<<3) = no idle mode only for initial debugging */
350 ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
351 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
352 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
353 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
354
355
356 /* Put UHH in NoIdle/NoStandby mode */
357 reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
358 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
359 | OMAP_UHH_SYSCONFIG_SIDLEMODE
360 | OMAP_UHH_SYSCONFIG_CACTIVITY
361 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
362 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
363 reg &= ~OMAP_UHH_SYSCONFIG_SOFTRESET;
364
365 ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
366
367 reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
368
369 /* setup ULPI bypass and burst configurations */
370 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
371 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
372 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
373 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
374
375 /*
376 * REVISIT: Pi_CONNECT_STATUS controls MStandby
377 * assertion and Swakeup generation - let us not
378 * worry about this for now. OMAP HWMOD framework
379 * might take care of this later. If not, we can
380 * update these registers when adding aggressive
381 * clock management code.
382 *
383 * For now, turn off all the Pi_CONNECT_STATUS bits
384 *
385 if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED)
386 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
387 if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED)
388 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
389 if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED)
390 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
391 */
392 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
393 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
394 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
395
396 if (omap->es2_compatibility) {
397 /*
398 * All OHCI modes need to go through the TLL,
399 * unlike in the EHCI case. So use UTMI mode
400 * for all ports for OHCI, on ES2.x silicon
401 */
402 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
403 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
404 } else {
405 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
406 if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED)
407 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
408 else
409 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
410
411 if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED)
412 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
413 else
414 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
415
416 if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED)
417 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
418 else
419 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
420
421 }
422 ohci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
423 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
424
425 ohci_omap3_tll_config(omap);
426
427 return 0;
428
429err_sys_status:
430 ohci_omap3_clock_power(omap, 0);
431 clk_put(omap->usbtll_ick);
432
433err_tll_ick:
434 clk_put(omap->usbtll_fck);
435
436err_tll_fck:
437 clk_put(omap->usbhost1_48m_fck);
438
439err_host_48m_fck:
440 clk_put(omap->usbhost2_120m_fck);
441
442err_host_120m_fck:
443 clk_put(omap->usbhost_ick);
444
445err_host_ick:
446 return ret;
447}
448
449static void omap3_stop_ohci(struct ohci_hcd_omap3 *omap, struct usb_hcd *hcd)
450{
451 unsigned long timeout = jiffies + msecs_to_jiffies(100);
452
453 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
454
455 /* Reset USBHOST for insmod/rmmod to work */
456 ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
457 OMAP_UHH_SYSCONFIG_SOFTRESET);
458 while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
459 & OMAP_UHH_SYSSTATUS_UHHRESETDONE)) {
460 cpu_relax();
461
462 if (time_after(jiffies, timeout))
463 dev_dbg(omap->dev, "operation timed out\n");
464 }
465
466 while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
467 & OMAP_UHH_SYSSTATUS_OHCIRESETDONE)) {
468 cpu_relax();
469
470 if (time_after(jiffies, timeout))
471 dev_dbg(omap->dev, "operation timed out\n");
472 }
473
474 while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
475 & OMAP_UHH_SYSSTATUS_EHCIRESETDONE)) {
476 cpu_relax();
477
478 if (time_after(jiffies, timeout))
479 dev_dbg(omap->dev, "operation timed out\n");
480 }
481
482 ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
483
484 while (!(ohci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
485 & (1 << 0))) {
486 cpu_relax();
487
488 if (time_after(jiffies, timeout))
489 dev_dbg(omap->dev, "operation timed out\n");
490 }
491
492 ohci_omap3_clock_power(omap, 0);
493
494 if (omap->usbtll_fck != NULL) {
495 clk_put(omap->usbtll_fck);
496 omap->usbtll_fck = NULL;
497 }
498
499 if (omap->usbhost_ick != NULL) {
500 clk_put(omap->usbhost_ick);
501 omap->usbhost_ick = NULL;
502 }
503
504 if (omap->usbhost1_48m_fck != NULL) {
505 clk_put(omap->usbhost1_48m_fck);
506 omap->usbhost1_48m_fck = NULL;
507 }
508
509 if (omap->usbhost2_120m_fck != NULL) {
510 clk_put(omap->usbhost2_120m_fck);
511 omap->usbhost2_120m_fck = NULL;
512 }
513
514 if (omap->usbtll_ick != NULL) {
515 clk_put(omap->usbtll_ick);
516 omap->usbtll_ick = NULL;
517 }
518
519 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
520}
521
522/*-------------------------------------------------------------------------*/
523
524static const struct hc_driver ohci_omap3_hc_driver = { 70static const struct hc_driver ohci_omap3_hc_driver = {
525 .description = hcd_name, 71 .description = hcd_name,
526 .product_desc = "OMAP3 OHCI Host Controller", 72 .product_desc = "OMAP3 OHCI Host Controller",
@@ -580,107 +126,77 @@ static const struct hc_driver ohci_omap3_hc_driver = {
580 */ 126 */
581static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev) 127static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev)
582{ 128{
583 struct ohci_hcd_omap_platform_data *pdata = pdev->dev.platform_data; 129 struct device *dev = &pdev->dev;
584 struct ohci_hcd_omap3 *omap; 130 struct usb_hcd *hcd = NULL;
585 struct resource *res; 131 void __iomem *regs = NULL;
586 struct usb_hcd *hcd; 132 struct resource *res;
587 int ret = -ENODEV; 133 int ret = -ENODEV;
588 int irq; 134 int irq;
589 135
590 if (usb_disabled()) 136 if (usb_disabled())
591 goto err_disabled; 137 goto err_end;
592 138
593 if (!pdata) { 139 if (!dev->parent) {
594 dev_dbg(&pdev->dev, "missing platform_data\n"); 140 dev_err(dev, "Missing parent device\n");
595 goto err_pdata; 141 return -ENODEV;
596 } 142 }
597 143
598 irq = platform_get_irq(pdev, 0); 144 irq = platform_get_irq_byname(pdev, "ohci-irq");
145 if (irq < 0) {
146 dev_err(dev, "OHCI irq failed\n");
147 return -ENODEV;
148 }
599 149
600 omap = kzalloc(sizeof(*omap), GFP_KERNEL); 150 res = platform_get_resource_byname(pdev,
601 if (!omap) { 151 IORESOURCE_MEM, "ohci");
602 ret = -ENOMEM; 152 if (!ret) {
603 goto err_disabled; 153 dev_err(dev, "UHH OHCI get resource failed\n");
154 return -ENOMEM;
604 } 155 }
605 156
606 hcd = usb_create_hcd(&ohci_omap3_hc_driver, &pdev->dev, 157 regs = ioremap(res->start, resource_size(res));
607 dev_name(&pdev->dev)); 158 if (!regs) {
608 if (!hcd) { 159 dev_err(dev, "UHH OHCI ioremap failed\n");
609 ret = -ENOMEM; 160 return -ENOMEM;
610 goto err_create_hcd;
611 } 161 }
612 162
613 platform_set_drvdata(pdev, omap);
614 omap->dev = &pdev->dev;
615 omap->port_mode[0] = pdata->port_mode[0];
616 omap->port_mode[1] = pdata->port_mode[1];
617 omap->port_mode[2] = pdata->port_mode[2];
618 omap->es2_compatibility = pdata->es2_compatibility;
619 omap->ohci = hcd_to_ohci(hcd);
620 163
621 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 164 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
165 dev_name(dev));
166 if (!hcd) {
167 dev_err(dev, "usb_create_hcd failed\n");
168 goto err_io;
169 }
622 170
623 hcd->rsrc_start = res->start; 171 hcd->rsrc_start = res->start;
624 hcd->rsrc_len = resource_size(res); 172 hcd->rsrc_len = resource_size(res);
173 hcd->regs = regs;
625 174
626 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 175 ret = omap_usbhs_enable(dev);
627 if (!hcd->regs) {
628 dev_err(&pdev->dev, "OHCI ioremap failed\n");
629 ret = -ENOMEM;
630 goto err_ioremap;
631 }
632
633 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
634 omap->uhh_base = ioremap(res->start, resource_size(res));
635 if (!omap->uhh_base) {
636 dev_err(&pdev->dev, "UHH ioremap failed\n");
637 ret = -ENOMEM;
638 goto err_uhh_ioremap;
639 }
640
641 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
642 omap->tll_base = ioremap(res->start, resource_size(res));
643 if (!omap->tll_base) {
644 dev_err(&pdev->dev, "TLL ioremap failed\n");
645 ret = -ENOMEM;
646 goto err_tll_ioremap;
647 }
648
649 ret = omap3_start_ohci(omap, hcd);
650 if (ret) { 176 if (ret) {
651 dev_dbg(&pdev->dev, "failed to start ehci\n"); 177 dev_dbg(dev, "failed to start ohci\n");
652 goto err_start; 178 goto err_end;
653 } 179 }
654 180
655 ohci_hcd_init(omap->ohci); 181 ohci_hcd_init(hcd_to_ohci(hcd));
656 182
657 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); 183 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
658 if (ret) { 184 if (ret) {
659 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); 185 dev_dbg(dev, "failed to add hcd with err %d\n", ret);
660 goto err_add_hcd; 186 goto err_add_hcd;
661 } 187 }
662 188
663 return 0; 189 return 0;
664 190
665err_add_hcd: 191err_add_hcd:
666 omap3_stop_ohci(omap, hcd); 192 omap_usbhs_disable(dev);
667
668err_start:
669 iounmap(omap->tll_base);
670
671err_tll_ioremap:
672 iounmap(omap->uhh_base);
673
674err_uhh_ioremap:
675 iounmap(hcd->regs);
676 193
677err_ioremap: 194err_end:
678 usb_put_hcd(hcd); 195 usb_put_hcd(hcd);
679 196
680err_create_hcd: 197err_io:
681 kfree(omap); 198 iounmap(regs);
682err_pdata: 199
683err_disabled:
684 return ret; 200 return ret;
685} 201}
686 202
@@ -699,24 +215,20 @@ err_disabled:
699 */ 215 */
700static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev) 216static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev)
701{ 217{
702 struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev); 218 struct device *dev = &pdev->dev;
703 struct usb_hcd *hcd = ohci_to_hcd(omap->ohci); 219 struct usb_hcd *hcd = dev_get_drvdata(dev);
704 220
705 usb_remove_hcd(hcd);
706 omap3_stop_ohci(omap, hcd);
707 iounmap(hcd->regs); 221 iounmap(hcd->regs);
708 iounmap(omap->tll_base); 222 usb_remove_hcd(hcd);
709 iounmap(omap->uhh_base); 223 omap_usbhs_disable(dev);
710 usb_put_hcd(hcd); 224 usb_put_hcd(hcd);
711 kfree(omap);
712 225
713 return 0; 226 return 0;
714} 227}
715 228
716static void ohci_hcd_omap3_shutdown(struct platform_device *pdev) 229static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
717{ 230{
718 struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev); 231 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
719 struct usb_hcd *hcd = ohci_to_hcd(omap->ohci);
720 232
721 if (hcd->driver->shutdown) 233 if (hcd->driver->shutdown)
722 hcd->driver->shutdown(hcd); 234 hcd->driver->shutdown(hcd);
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index 6bdc8b25a6a1..ad8166c681e2 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -22,24 +22,6 @@
22#include <linux/io.h> 22#include <linux/io.h>
23 23
24 24
25/* constants used to work around PM-related transfer
26 * glitches in some AMD 700 series southbridges
27 */
28#define AB_REG_BAR 0xf0
29#define AB_INDX(addr) ((addr) + 0x00)
30#define AB_DATA(addr) ((addr) + 0x04)
31#define AX_INDXC 0X30
32#define AX_DATAC 0x34
33
34#define NB_PCIE_INDX_ADDR 0xe0
35#define NB_PCIE_INDX_DATA 0xe4
36#define PCIE_P_CNTL 0x10040
37#define BIF_NB 0x10002
38
39static struct pci_dev *amd_smbus_dev;
40static struct pci_dev *amd_hb_dev;
41static int amd_ohci_iso_count;
42
43/*-------------------------------------------------------------------------*/ 25/*-------------------------------------------------------------------------*/
44 26
45static int broken_suspend(struct usb_hcd *hcd) 27static int broken_suspend(struct usb_hcd *hcd)
@@ -168,15 +150,18 @@ static int ohci_quirk_nec(struct usb_hcd *hcd)
168static int ohci_quirk_amd700(struct usb_hcd *hcd) 150static int ohci_quirk_amd700(struct usb_hcd *hcd)
169{ 151{
170 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 152 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
171 u8 rev = 0; 153 struct pci_dev *amd_smbus_dev;
154 u8 rev;
172 155
173 if (!amd_smbus_dev) 156 if (usb_amd_find_chipset_info())
174 amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 157 ohci->flags |= OHCI_QUIRK_AMD_PLL;
175 PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL); 158
159 amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI,
160 PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL);
176 if (!amd_smbus_dev) 161 if (!amd_smbus_dev)
177 return 0; 162 return 0;
178 163
179 pci_read_config_byte(amd_smbus_dev, PCI_REVISION_ID, &rev); 164 rev = amd_smbus_dev->revision;
180 165
181 /* SB800 needs pre-fetch fix */ 166 /* SB800 needs pre-fetch fix */
182 if ((rev >= 0x40) && (rev <= 0x4f)) { 167 if ((rev >= 0x40) && (rev <= 0x4f)) {
@@ -184,89 +169,32 @@ static int ohci_quirk_amd700(struct usb_hcd *hcd)
184 ohci_dbg(ohci, "enabled AMD prefetch quirk\n"); 169 ohci_dbg(ohci, "enabled AMD prefetch quirk\n");
185 } 170 }
186 171
187 if ((rev > 0x3b) || (rev < 0x30)) { 172 pci_dev_put(amd_smbus_dev);
188 pci_dev_put(amd_smbus_dev); 173 amd_smbus_dev = NULL;
189 amd_smbus_dev = NULL;
190 return 0;
191 }
192
193 amd_ohci_iso_count++;
194
195 if (!amd_hb_dev)
196 amd_hb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9600, NULL);
197
198 ohci->flags |= OHCI_QUIRK_AMD_ISO;
199 ohci_dbg(ohci, "enabled AMD ISO transfers quirk\n");
200 174
201 return 0; 175 return 0;
202} 176}
203 177
204/* 178/* nVidia controllers continue to drive Reset signalling on the bus
205 * The hardware normally enables the A-link power management feature, which 179 * even after system shutdown, wasting power. This flag tells the
206 * lets the system lower the power consumption in idle states. 180 * shutdown routine to leave the controller OPERATIONAL instead of RESET.
207 *
208 * Assume the system is configured to have USB 1.1 ISO transfers going
209 * to or from a USB device. Without this quirk, that stream may stutter
210 * or have breaks occasionally. For transfers going to speakers, this
211 * makes a very audible mess...
212 *
213 * That audio playback corruption is due to the audio stream getting
214 * interrupted occasionally when the link goes in lower power state
215 * This USB quirk prevents the link going into that lower power state
216 * during audio playback or other ISO operations.
217 */ 181 */
218static void quirk_amd_pll(int on) 182static int ohci_quirk_nvidia_shutdown(struct usb_hcd *hcd)
219{ 183{
220 u32 addr; 184 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
221 u32 val; 185 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
222 u32 bit = (on > 0) ? 1 : 0;
223
224 pci_read_config_dword(amd_smbus_dev, AB_REG_BAR, &addr);
225
226 /* BIT names/meanings are NDA-protected, sorry ... */
227
228 outl(AX_INDXC, AB_INDX(addr));
229 outl(0x40, AB_DATA(addr));
230 outl(AX_DATAC, AB_INDX(addr));
231 val = inl(AB_DATA(addr));
232 val &= ~((1 << 3) | (1 << 4) | (1 << 9));
233 val |= (bit << 3) | ((!bit) << 4) | ((!bit) << 9);
234 outl(val, AB_DATA(addr));
235
236 if (amd_hb_dev) {
237 addr = PCIE_P_CNTL;
238 pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr);
239
240 pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val);
241 val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12));
242 val |= bit | (bit << 3) | (bit << 12);
243 val |= ((!bit) << 4) | ((!bit) << 9);
244 pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val);
245
246 addr = BIF_NB;
247 pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr);
248
249 pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val);
250 val &= ~(1 << 8);
251 val |= bit << 8;
252 pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val);
253 }
254}
255 186
256static void amd_iso_dev_put(void) 187 /* Evidently nVidia fixed their later hardware; this is a guess at
257{ 188 * the changeover point.
258 amd_ohci_iso_count--; 189 */
259 if (amd_ohci_iso_count == 0) { 190#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_USB 0x026d
260 if (amd_smbus_dev) { 191
261 pci_dev_put(amd_smbus_dev); 192 if (pdev->device < PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_USB) {
262 amd_smbus_dev = NULL; 193 ohci->flags |= OHCI_QUIRK_SHUTDOWN;
263 } 194 ohci_dbg(ohci, "enabled nVidia shutdown quirk\n");
264 if (amd_hb_dev) {
265 pci_dev_put(amd_hb_dev);
266 amd_hb_dev = NULL;
267 }
268 } 195 }
269 196
197 return 0;
270} 198}
271 199
272static void sb800_prefetch(struct ohci_hcd *ohci, int on) 200static void sb800_prefetch(struct ohci_hcd *ohci, int on)
@@ -332,6 +260,10 @@ static const struct pci_device_id ohci_pci_quirks[] = {
332 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399), 260 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399),
333 .driver_data = (unsigned long)ohci_quirk_amd700, 261 .driver_data = (unsigned long)ohci_quirk_amd700,
334 }, 262 },
263 {
264 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
265 .driver_data = (unsigned long) ohci_quirk_nvidia_shutdown,
266 },
335 267
336 /* FIXME for some of the early AMD 760 southbridges, OHCI 268 /* FIXME for some of the early AMD 760 southbridges, OHCI
337 * won't work at all. blacklist them. 269 * won't work at all. blacklist them.
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index b2c2dbf08766..1ca1821320f4 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -80,8 +80,7 @@ static const struct hc_driver ohci_ppc_of_hc_driver = {
80}; 80};
81 81
82 82
83static int __devinit 83static int __devinit ohci_hcd_ppc_of_probe(struct platform_device *op)
84ohci_hcd_ppc_of_probe(struct platform_device *op, const struct of_device_id *match)
85{ 84{
86 struct device_node *dn = op->dev.of_node; 85 struct device_node *dn = op->dev.of_node;
87 struct usb_hcd *hcd; 86 struct usb_hcd *hcd;
@@ -201,14 +200,12 @@ static int ohci_hcd_ppc_of_remove(struct platform_device *op)
201 return 0; 200 return 0;
202} 201}
203 202
204static int ohci_hcd_ppc_of_shutdown(struct platform_device *op) 203static void ohci_hcd_ppc_of_shutdown(struct platform_device *op)
205{ 204{
206 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 205 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
207 206
208 if (hcd->driver->shutdown) 207 if (hcd->driver->shutdown)
209 hcd->driver->shutdown(hcd); 208 hcd->driver->shutdown(hcd);
210
211 return 0;
212} 209}
213 210
214 211
@@ -243,7 +240,7 @@ MODULE_DEVICE_TABLE(of, ohci_hcd_ppc_of_match);
243#endif 240#endif
244 241
245 242
246static struct of_platform_driver ohci_hcd_ppc_of_driver = { 243static struct platform_driver ohci_hcd_ppc_of_driver = {
247 .probe = ohci_hcd_ppc_of_probe, 244 .probe = ohci_hcd_ppc_of_probe,
248 .remove = ohci_hcd_ppc_of_remove, 245 .remove = ohci_hcd_ppc_of_remove,
249 .shutdown = ohci_hcd_ppc_of_shutdown, 246 .shutdown = ohci_hcd_ppc_of_shutdown,
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index 418163894775..80be5472783a 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -24,6 +24,7 @@
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/clk.h> 25#include <linux/clk.h>
26#include <mach/ohci.h> 26#include <mach/ohci.h>
27#include <mach/pxa3xx-u2d.h>
27 28
28/* 29/*
29 * UHC: USB Host Controller (OHCI-like) register definitions 30 * UHC: USB Host Controller (OHCI-like) register definitions
@@ -235,6 +236,9 @@ static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev)
235 if (retval < 0) 236 if (retval < 0)
236 return retval; 237 return retval;
237 238
239 if (cpu_is_pxa3xx())
240 pxa3xx_u2d_start_hc(&ohci_to_hcd(&ohci->ohci)->self);
241
238 uhchr = __raw_readl(ohci->mmio_base + UHCHR) & ~UHCHR_SSE; 242 uhchr = __raw_readl(ohci->mmio_base + UHCHR) & ~UHCHR_SSE;
239 __raw_writel(uhchr, ohci->mmio_base + UHCHR); 243 __raw_writel(uhchr, ohci->mmio_base + UHCHR);
240 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, ohci->mmio_base + UHCHIE); 244 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, ohci->mmio_base + UHCHIE);
@@ -251,6 +255,9 @@ static void pxa27x_stop_hc(struct pxa27x_ohci *ohci, struct device *dev)
251 255
252 inf = dev->platform_data; 256 inf = dev->platform_data;
253 257
258 if (cpu_is_pxa3xx())
259 pxa3xx_u2d_stop_hc(&ohci_to_hcd(&ohci->ohci)->self);
260
254 if (inf->exit) 261 if (inf->exit)
255 inf->exit(dev); 262 inf->exit(dev);
256 263
@@ -305,8 +312,10 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
305 return PTR_ERR(usb_clk); 312 return PTR_ERR(usb_clk);
306 313
307 hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x"); 314 hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x");
308 if (!hcd) 315 if (!hcd) {
309 return -ENOMEM; 316 retval = -ENOMEM;
317 goto err0;
318 }
310 319
311 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 320 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
312 if (!r) { 321 if (!r) {
@@ -361,6 +370,7 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
361 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 370 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
362 err1: 371 err1:
363 usb_put_hcd(hcd); 372 usb_put_hcd(hcd);
373 err0:
364 clk_put(usb_clk); 374 clk_put(usb_clk);
365 return retval; 375 return retval;
366} 376}
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index 83094d067e0f..dd24fc115e48 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -52,7 +52,7 @@ __acquires(ohci->lock)
52 ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--; 52 ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--;
53 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { 53 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) {
54 if (quirk_amdiso(ohci)) 54 if (quirk_amdiso(ohci))
55 quirk_amd_pll(1); 55 usb_amd_quirk_pll_enable();
56 if (quirk_amdprefetch(ohci)) 56 if (quirk_amdprefetch(ohci))
57 sb800_prefetch(ohci, 0); 57 sb800_prefetch(ohci, 0);
58 } 58 }
@@ -686,7 +686,7 @@ static void td_submit_urb (
686 } 686 }
687 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { 687 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) {
688 if (quirk_amdiso(ohci)) 688 if (quirk_amdiso(ohci))
689 quirk_amd_pll(0); 689 usb_amd_quirk_pll_disable();
690 if (quirk_amdprefetch(ohci)) 690 if (quirk_amdprefetch(ohci))
691 sb800_prefetch(ohci, 1); 691 sb800_prefetch(ohci, 1);
692 } 692 }
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index a68af2dd55ca..7c9a4d55526b 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -56,9 +56,8 @@ static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
56 info->hcd = hcd; 56 info->hcd = hcd;
57 info->report_oc = s3c2410_hcd_oc; 57 info->report_oc = s3c2410_hcd_oc;
58 58
59 if (info->enable_oc != NULL) { 59 if (info->enable_oc != NULL)
60 (info->enable_oc)(info, 1); 60 (info->enable_oc)(info, 1);
61 }
62 } 61 }
63} 62}
64 63
@@ -72,9 +71,8 @@ static void s3c2410_stop_hc(struct platform_device *dev)
72 info->report_oc = NULL; 71 info->report_oc = NULL;
73 info->hcd = NULL; 72 info->hcd = NULL;
74 73
75 if (info->enable_oc != NULL) { 74 if (info->enable_oc != NULL)
76 (info->enable_oc)(info, 0); 75 (info->enable_oc)(info, 0);
77 }
78 } 76 }
79 77
80 clk_disable(clk); 78 clk_disable(clk);
@@ -88,14 +86,14 @@ static void s3c2410_stop_hc(struct platform_device *dev)
88*/ 86*/
89 87
90static int 88static int
91ohci_s3c2410_hub_status_data (struct usb_hcd *hcd, char *buf) 89ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf)
92{ 90{
93 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd); 91 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
94 struct s3c2410_hcd_port *port; 92 struct s3c2410_hcd_port *port;
95 int orig; 93 int orig;
96 int portno; 94 int portno;
97 95
98 orig = ohci_hub_status_data (hcd, buf); 96 orig = ohci_hub_status_data(hcd, buf);
99 97
100 if (info == NULL) 98 if (info == NULL)
101 return orig; 99 return orig;
@@ -145,7 +143,7 @@ static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info,
145 * request. 143 * request.
146*/ 144*/
147 145
148static int ohci_s3c2410_hub_control ( 146static int ohci_s3c2410_hub_control(
149 struct usb_hcd *hcd, 147 struct usb_hcd *hcd,
150 u16 typeReq, 148 u16 typeReq,
151 u16 wValue, 149 u16 wValue,
@@ -199,9 +197,8 @@ static int ohci_s3c2410_hub_control (
199 dev_dbg(hcd->self.controller, 197 dev_dbg(hcd->self.controller,
200 "ClearPortFeature: OVER_CURRENT\n"); 198 "ClearPortFeature: OVER_CURRENT\n");
201 199
202 if (valid_port(wIndex)) { 200 if (valid_port(wIndex))
203 info->port[wIndex-1].oc_status = 0; 201 info->port[wIndex-1].oc_status = 0;
204 }
205 202
206 goto out; 203 goto out;
207 204
@@ -242,8 +239,11 @@ static int ohci_s3c2410_hub_control (
242 desc->wHubCharacteristics |= cpu_to_le16(0x0001); 239 desc->wHubCharacteristics |= cpu_to_le16(0x0001);
243 240
244 if (info->enable_oc) { 241 if (info->enable_oc) {
245 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM); 242 desc->wHubCharacteristics &= ~cpu_to_le16(
246 desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001); 243 HUB_CHAR_OCPM);
244 desc->wHubCharacteristics |= cpu_to_le16(
245 0x0008 |
246 0x0001);
247 } 247 }
248 248
249 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n", 249 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
@@ -257,13 +257,11 @@ static int ohci_s3c2410_hub_control (
257 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); 257 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
258 258
259 if (valid_port(wIndex)) { 259 if (valid_port(wIndex)) {
260 if (info->port[wIndex-1].oc_changed) { 260 if (info->port[wIndex-1].oc_changed)
261 *data |= cpu_to_le32(RH_PS_OCIC); 261 *data |= cpu_to_le32(RH_PS_OCIC);
262 }
263 262
264 if (info->port[wIndex-1].oc_status) { 263 if (info->port[wIndex-1].oc_status)
265 *data |= cpu_to_le32(RH_PS_POCI); 264 *data |= cpu_to_le32(RH_PS_POCI);
266 }
267 } 265 }
268 } 266 }
269 267
@@ -321,7 +319,7 @@ static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc)
321*/ 319*/
322 320
323static void 321static void
324usb_hcd_s3c2410_remove (struct usb_hcd *hcd, struct platform_device *dev) 322usb_hcd_s3c2410_remove(struct usb_hcd *hcd, struct platform_device *dev)
325{ 323{
326 usb_remove_hcd(hcd); 324 usb_remove_hcd(hcd);
327 s3c2410_stop_hc(dev); 325 s3c2410_stop_hc(dev);
@@ -339,7 +337,7 @@ usb_hcd_s3c2410_remove (struct usb_hcd *hcd, struct platform_device *dev)
339 * through the hotplug entry's driver_data. 337 * through the hotplug entry's driver_data.
340 * 338 *
341 */ 339 */
342static int usb_hcd_s3c2410_probe (const struct hc_driver *driver, 340static int usb_hcd_s3c2410_probe(const struct hc_driver *driver,
343 struct platform_device *dev) 341 struct platform_device *dev)
344{ 342{
345 struct usb_hcd *hcd = NULL; 343 struct usb_hcd *hcd = NULL;
@@ -353,7 +351,7 @@ static int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
353 return -ENOMEM; 351 return -ENOMEM;
354 352
355 hcd->rsrc_start = dev->resource[0].start; 353 hcd->rsrc_start = dev->resource[0].start;
356 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1; 354 hcd->rsrc_len = resource_size(&dev->resource[0]);
357 355
358 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 356 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
359 dev_err(&dev->dev, "request_mem_region failed\n"); 357 dev_err(&dev->dev, "request_mem_region failed\n");
@@ -364,14 +362,14 @@ static int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
364 clk = clk_get(&dev->dev, "usb-host"); 362 clk = clk_get(&dev->dev, "usb-host");
365 if (IS_ERR(clk)) { 363 if (IS_ERR(clk)) {
366 dev_err(&dev->dev, "cannot get usb-host clock\n"); 364 dev_err(&dev->dev, "cannot get usb-host clock\n");
367 retval = -ENOENT; 365 retval = PTR_ERR(clk);
368 goto err_mem; 366 goto err_mem;
369 } 367 }
370 368
371 usb_clk = clk_get(&dev->dev, "usb-bus-host"); 369 usb_clk = clk_get(&dev->dev, "usb-bus-host");
372 if (IS_ERR(usb_clk)) { 370 if (IS_ERR(usb_clk)) {
373 dev_err(&dev->dev, "cannot get usb-bus-host clock\n"); 371 dev_err(&dev->dev, "cannot get usb-bus-host clock\n");
374 retval = -ENOENT; 372 retval = PTR_ERR(usb_clk);
375 goto err_clk; 373 goto err_clk;
376 } 374 }
377 375
@@ -411,17 +409,19 @@ static int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
411/*-------------------------------------------------------------------------*/ 409/*-------------------------------------------------------------------------*/
412 410
413static int 411static int
414ohci_s3c2410_start (struct usb_hcd *hcd) 412ohci_s3c2410_start(struct usb_hcd *hcd)
415{ 413{
416 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 414 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
417 int ret; 415 int ret;
418 416
419 if ((ret = ohci_init(ohci)) < 0) 417 ret = ohci_init(ohci);
418 if (ret < 0)
420 return ret; 419 return ret;
421 420
422 if ((ret = ohci_run (ohci)) < 0) { 421 ret = ohci_run(ohci);
423 err ("can't start %s", hcd->self.bus_name); 422 if (ret < 0) {
424 ohci_stop (hcd); 423 err("can't start %s", hcd->self.bus_name);
424 ohci_stop(hcd);
425 return ret; 425 return ret;
426 } 426 }
427 427
@@ -473,12 +473,12 @@ static const struct hc_driver ohci_s3c2410_hc_driver = {
473 473
474/* device driver */ 474/* device driver */
475 475
476static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev) 476static int __devinit ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev)
477{ 477{
478 return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver, pdev); 478 return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver, pdev);
479} 479}
480 480
481static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev) 481static int __devexit ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
482{ 482{
483 struct usb_hcd *hcd = platform_get_drvdata(pdev); 483 struct usb_hcd *hcd = platform_get_drvdata(pdev);
484 484
@@ -488,7 +488,7 @@ static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
488 488
489static struct platform_driver ohci_hcd_s3c2410_driver = { 489static struct platform_driver ohci_hcd_s3c2410_driver = {
490 .probe = ohci_hcd_s3c2410_drv_probe, 490 .probe = ohci_hcd_s3c2410_drv_probe,
491 .remove = ohci_hcd_s3c2410_drv_remove, 491 .remove = __devexit_p(ohci_hcd_s3c2410_drv_remove),
492 .shutdown = usb_hcd_platform_shutdown, 492 .shutdown = usb_hcd_platform_shutdown,
493 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */ 493 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */
494 /*.resume = ohci_hcd_s3c2410_drv_resume, */ 494 /*.resume = ohci_hcd_s3c2410_drv_resume, */
diff --git a/drivers/usb/host/ohci-sh.c b/drivers/usb/host/ohci-sh.c
index 60f03cc7ec4f..f47867ff78c7 100644
--- a/drivers/usb/host/ohci-sh.c
+++ b/drivers/usb/host/ohci-sh.c
@@ -77,7 +77,6 @@ static const struct hc_driver ohci_sh_hc_driver = {
77 77
78/*-------------------------------------------------------------------------*/ 78/*-------------------------------------------------------------------------*/
79 79
80#define resource_len(r) (((r)->end - (r)->start) + 1)
81static int ohci_hcd_sh_probe(struct platform_device *pdev) 80static int ohci_hcd_sh_probe(struct platform_device *pdev)
82{ 81{
83 struct resource *res = NULL; 82 struct resource *res = NULL;
@@ -109,8 +108,8 @@ static int ohci_hcd_sh_probe(struct platform_device *pdev)
109 108
110 hcd->regs = (void __iomem *)res->start; 109 hcd->regs = (void __iomem *)res->start;
111 hcd->rsrc_start = res->start; 110 hcd->rsrc_start = res->start;
112 hcd->rsrc_len = resource_len(res); 111 hcd->rsrc_len = resource_size(res);
113 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); 112 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
114 if (ret != 0) { 113 if (ret != 0) {
115 err("Failed to add hcd"); 114 err("Failed to add hcd");
116 usb_put_hcd(hcd); 115 usb_put_hcd(hcd);
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c
index cff23637cfcc..041d30f30c10 100644
--- a/drivers/usb/host/ohci-sm501.c
+++ b/drivers/usb/host/ohci-sm501.c
@@ -168,7 +168,7 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
168 168
169 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); 169 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
170 if (retval) 170 if (retval)
171 goto err4; 171 goto err5;
172 172
173 /* enable power and unmask interrupts */ 173 /* enable power and unmask interrupts */
174 174
@@ -176,6 +176,8 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
176 sm501_modify_reg(dev->parent, SM501_IRQ_MASK, 1 << 6, 0); 176 sm501_modify_reg(dev->parent, SM501_IRQ_MASK, 1 << 6, 0);
177 177
178 return 0; 178 return 0;
179err5:
180 iounmap(hcd->regs);
179err4: 181err4:
180 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 182 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
181err3: 183err3:
diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c
new file mode 100644
index 000000000000..4fd4bea9ac7a
--- /dev/null
+++ b/drivers/usb/host/ohci-spear.c
@@ -0,0 +1,240 @@
1/*
2* OHCI HCD (Host Controller Driver) for USB.
3*
4* Copyright (C) 2010 ST Microelectronics.
5* Deepak Sikri<deepak.sikri@st.com>
6*
7* Based on various ohci-*.c drivers
8*
9* This file is licensed under the terms of the GNU General Public
10* License version 2. This program is licensed "as is" without any
11* warranty of any kind, whether express or implied.
12*/
13
14#include <linux/signal.h>
15#include <linux/platform_device.h>
16#include <linux/clk.h>
17
18struct spear_ohci {
19 struct ohci_hcd ohci;
20 struct clk *clk;
21};
22
23#define to_spear_ohci(hcd) (struct spear_ohci *)hcd_to_ohci(hcd)
24
25static void spear_start_ohci(struct spear_ohci *ohci)
26{
27 clk_enable(ohci->clk);
28}
29
30static void spear_stop_ohci(struct spear_ohci *ohci)
31{
32 clk_disable(ohci->clk);
33}
34
35static int __devinit ohci_spear_start(struct usb_hcd *hcd)
36{
37 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
38 int ret;
39
40 ret = ohci_init(ohci);
41 if (ret < 0)
42 return ret;
43 ohci->regs = hcd->regs;
44
45 ret = ohci_run(ohci);
46 if (ret < 0) {
47 dev_err(hcd->self.controller, "can't start\n");
48 ohci_stop(hcd);
49 return ret;
50 }
51
52 create_debug_files(ohci);
53
54#ifdef DEBUG
55 ohci_dump(ohci, 1);
56#endif
57 return 0;
58}
59
60static const struct hc_driver ohci_spear_hc_driver = {
61 .description = hcd_name,
62 .product_desc = "SPEAr OHCI",
63 .hcd_priv_size = sizeof(struct spear_ohci),
64
65 /* generic hardware linkage */
66 .irq = ohci_irq,
67 .flags = HCD_USB11 | HCD_MEMORY,
68
69 /* basic lifecycle operations */
70 .start = ohci_spear_start,
71 .stop = ohci_stop,
72 .shutdown = ohci_shutdown,
73#ifdef CONFIG_PM
74 .bus_suspend = ohci_bus_suspend,
75 .bus_resume = ohci_bus_resume,
76#endif
77
78 /* managing i/o requests and associated device resources */
79 .urb_enqueue = ohci_urb_enqueue,
80 .urb_dequeue = ohci_urb_dequeue,
81 .endpoint_disable = ohci_endpoint_disable,
82
83 /* scheduling support */
84 .get_frame_number = ohci_get_frame,
85
86 /* root hub support */
87 .hub_status_data = ohci_hub_status_data,
88 .hub_control = ohci_hub_control,
89
90 .start_port_reset = ohci_start_port_reset,
91};
92
93static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
94{
95 const struct hc_driver *driver = &ohci_spear_hc_driver;
96 struct usb_hcd *hcd = NULL;
97 struct clk *usbh_clk;
98 struct spear_ohci *ohci_p;
99 struct resource *res;
100 int retval, irq;
101 int *pdata = pdev->dev.platform_data;
102 char clk_name[20] = "usbh_clk";
103
104 if (pdata == NULL)
105 return -EFAULT;
106
107 irq = platform_get_irq(pdev, 0);
108 if (irq < 0) {
109 retval = irq;
110 goto fail_irq_get;
111 }
112
113 if (*pdata >= 0)
114 sprintf(clk_name, "usbh.%01d_clk", *pdata);
115
116 usbh_clk = clk_get(NULL, clk_name);
117 if (IS_ERR(usbh_clk)) {
118 dev_err(&pdev->dev, "Error getting interface clock\n");
119 retval = PTR_ERR(usbh_clk);
120 goto fail_get_usbh_clk;
121 }
122
123 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
124 if (!hcd) {
125 retval = -ENOMEM;
126 goto fail_create_hcd;
127 }
128
129 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
130 if (!res) {
131 retval = -ENODEV;
132 goto fail_request_resource;
133 }
134
135 hcd->rsrc_start = pdev->resource[0].start;
136 hcd->rsrc_len = resource_size(res);
137 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
138 dev_dbg(&pdev->dev, "request_mem_region failed\n");
139 retval = -EBUSY;
140 goto fail_request_resource;
141 }
142
143 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
144 if (!hcd->regs) {
145 dev_dbg(&pdev->dev, "ioremap failed\n");
146 retval = -ENOMEM;
147 goto fail_ioremap;
148 }
149
150 ohci_p = (struct spear_ohci *)hcd_to_ohci(hcd);
151 ohci_p->clk = usbh_clk;
152 spear_start_ohci(ohci_p);
153 ohci_hcd_init(hcd_to_ohci(hcd));
154
155 retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), IRQF_DISABLED);
156 if (retval == 0)
157 return retval;
158
159 spear_stop_ohci(ohci_p);
160 iounmap(hcd->regs);
161fail_ioremap:
162 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
163fail_request_resource:
164 usb_put_hcd(hcd);
165fail_create_hcd:
166 clk_put(usbh_clk);
167fail_get_usbh_clk:
168fail_irq_get:
169 dev_err(&pdev->dev, "init fail, %d\n", retval);
170
171 return retval;
172}
173
174static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)
175{
176 struct usb_hcd *hcd = platform_get_drvdata(pdev);
177 struct spear_ohci *ohci_p = to_spear_ohci(hcd);
178
179 usb_remove_hcd(hcd);
180 if (ohci_p->clk)
181 spear_stop_ohci(ohci_p);
182
183 iounmap(hcd->regs);
184 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
185 usb_put_hcd(hcd);
186
187 if (ohci_p->clk)
188 clk_put(ohci_p->clk);
189 platform_set_drvdata(pdev, NULL);
190 return 0;
191}
192
193#if defined(CONFIG_PM)
194static int spear_ohci_hcd_drv_suspend(struct platform_device *dev,
195 pm_message_t message)
196{
197 struct usb_hcd *hcd = platform_get_drvdata(dev);
198 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
199 struct spear_ohci *ohci_p = to_spear_ohci(hcd);
200
201 if (time_before(jiffies, ohci->next_statechange))
202 msleep(5);
203 ohci->next_statechange = jiffies;
204
205 spear_stop_ohci(ohci_p);
206 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
207 return 0;
208}
209
210static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
211{
212 struct usb_hcd *hcd = platform_get_drvdata(dev);
213 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
214 struct spear_ohci *ohci_p = to_spear_ohci(hcd);
215
216 if (time_before(jiffies, ohci->next_statechange))
217 msleep(5);
218 ohci->next_statechange = jiffies;
219
220 spear_start_ohci(ohci_p);
221 ohci_finish_controller_resume(hcd);
222 return 0;
223}
224#endif
225
226/* Driver definition to register with the platform bus */
227static struct platform_driver spear_ohci_hcd_driver = {
228 .probe = spear_ohci_hcd_drv_probe,
229 .remove = spear_ohci_hcd_drv_remove,
230#ifdef CONFIG_PM
231 .suspend = spear_ohci_hcd_drv_suspend,
232 .resume = spear_ohci_hcd_drv_resume,
233#endif
234 .driver = {
235 .owner = THIS_MODULE,
236 .name = "spear-ohci",
237 },
238};
239
240MODULE_ALIAS("platform:spear-ohci");
diff --git a/drivers/usb/host/ohci-tmio.c b/drivers/usb/host/ohci-tmio.c
index 8dabe8e31d8c..3558491dd87d 100644
--- a/drivers/usb/host/ohci-tmio.c
+++ b/drivers/usb/host/ohci-tmio.c
@@ -185,7 +185,7 @@ static struct platform_driver ohci_hcd_tmio_driver;
185 185
186static int __devinit ohci_hcd_tmio_drv_probe(struct platform_device *dev) 186static int __devinit ohci_hcd_tmio_drv_probe(struct platform_device *dev)
187{ 187{
188 struct mfd_cell *cell = dev->dev.platform_data; 188 const struct mfd_cell *cell = mfd_get_cell(dev);
189 struct resource *regs = platform_get_resource(dev, IORESOURCE_MEM, 0); 189 struct resource *regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
190 struct resource *config = platform_get_resource(dev, IORESOURCE_MEM, 1); 190 struct resource *config = platform_get_resource(dev, IORESOURCE_MEM, 1);
191 struct resource *sram = platform_get_resource(dev, IORESOURCE_MEM, 2); 191 struct resource *sram = platform_get_resource(dev, IORESOURCE_MEM, 2);
@@ -274,7 +274,7 @@ static int __devexit ohci_hcd_tmio_drv_remove(struct platform_device *dev)
274{ 274{
275 struct usb_hcd *hcd = platform_get_drvdata(dev); 275 struct usb_hcd *hcd = platform_get_drvdata(dev);
276 struct tmio_hcd *tmio = hcd_to_tmio(hcd); 276 struct tmio_hcd *tmio = hcd_to_tmio(hcd);
277 struct mfd_cell *cell = dev->dev.platform_data; 277 const struct mfd_cell *cell = mfd_get_cell(dev);
278 278
279 usb_remove_hcd(hcd); 279 usb_remove_hcd(hcd);
280 tmio_stop_hc(dev); 280 tmio_stop_hc(dev);
@@ -293,7 +293,7 @@ static int __devexit ohci_hcd_tmio_drv_remove(struct platform_device *dev)
293#ifdef CONFIG_PM 293#ifdef CONFIG_PM
294static int ohci_hcd_tmio_drv_suspend(struct platform_device *dev, pm_message_t state) 294static int ohci_hcd_tmio_drv_suspend(struct platform_device *dev, pm_message_t state)
295{ 295{
296 struct mfd_cell *cell = dev->dev.platform_data; 296 const struct mfd_cell *cell = mfd_get_cell(dev);
297 struct usb_hcd *hcd = platform_get_drvdata(dev); 297 struct usb_hcd *hcd = platform_get_drvdata(dev);
298 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 298 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
299 struct tmio_hcd *tmio = hcd_to_tmio(hcd); 299 struct tmio_hcd *tmio = hcd_to_tmio(hcd);
@@ -326,7 +326,7 @@ static int ohci_hcd_tmio_drv_suspend(struct platform_device *dev, pm_message_t s
326 326
327static int ohci_hcd_tmio_drv_resume(struct platform_device *dev) 327static int ohci_hcd_tmio_drv_resume(struct platform_device *dev)
328{ 328{
329 struct mfd_cell *cell = dev->dev.platform_data; 329 const struct mfd_cell *cell = mfd_get_cell(dev);
330 struct usb_hcd *hcd = platform_get_drvdata(dev); 330 struct usb_hcd *hcd = platform_get_drvdata(dev);
331 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 331 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
332 struct tmio_hcd *tmio = hcd_to_tmio(hcd); 332 struct tmio_hcd *tmio = hcd_to_tmio(hcd);
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 5bf15fed0d9f..35e5fd640ce7 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -401,8 +401,9 @@ struct ohci_hcd {
401#define OHCI_QUIRK_NEC 0x40 /* lost interrupts */ 401#define OHCI_QUIRK_NEC 0x40 /* lost interrupts */
402#define OHCI_QUIRK_FRAME_NO 0x80 /* no big endian frame_no shift */ 402#define OHCI_QUIRK_FRAME_NO 0x80 /* no big endian frame_no shift */
403#define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */ 403#define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */
404#define OHCI_QUIRK_AMD_ISO 0x200 /* ISO transfers*/ 404#define OHCI_QUIRK_AMD_PLL 0x200 /* AMD PLL quirk*/
405#define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */ 405#define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */
406#define OHCI_QUIRK_SHUTDOWN 0x800 /* nVidia power bug */
406 // there are also chip quirks/bugs in init logic 407 // there are also chip quirks/bugs in init logic
407 408
408 struct work_struct nec_work; /* Worker for NEC quirk */ 409 struct work_struct nec_work; /* Worker for NEC quirk */
@@ -432,7 +433,7 @@ static inline int quirk_zfmicro(struct ohci_hcd *ohci)
432} 433}
433static inline int quirk_amdiso(struct ohci_hcd *ohci) 434static inline int quirk_amdiso(struct ohci_hcd *ohci)
434{ 435{
435 return ohci->flags & OHCI_QUIRK_AMD_ISO; 436 return ohci->flags & OHCI_QUIRK_AMD_PLL;
436} 437}
437static inline int quirk_amdprefetch(struct ohci_hcd *ohci) 438static inline int quirk_amdprefetch(struct ohci_hcd *ohci)
438{ 439{
@@ -574,18 +575,8 @@ static inline void _ohci_writel (const struct ohci_hcd *ohci,
574#endif 575#endif
575} 576}
576 577
577#ifdef CONFIG_ARCH_LH7A404
578/* Marc Singer: at the time this code was written, the LH7A404
579 * had a problem reading the USB host registers. This
580 * implementation of the ohci_readl function performs the read
581 * twice as a work-around.
582 */
583#define ohci_readl(o,r) (_ohci_readl(o,r),_ohci_readl(o,r))
584#define ohci_writel(o,v,r) _ohci_writel(o,v,r)
585#else
586#define ohci_readl(o,r) _ohci_readl(o,r) 578#define ohci_readl(o,r) _ohci_readl(o,r)
587#define ohci_writel(o,v,r) _ohci_writel(o,v,r) 579#define ohci_writel(o,v,r) _ohci_writel(o,v,r)
588#endif
589 580
590 581
591/*-------------------------------------------------------------------------*/ 582/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index d9c85a292737..5fbe997dc6df 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -451,9 +451,9 @@ static void ehci_hub_descriptor(struct oxu_hcd *oxu,
451 temp = 1 + (ports / 8); 451 temp = 1 + (ports / 8);
452 desc->bDescLength = 7 + 2 * temp; 452 desc->bDescLength = 7 + 2 * temp;
453 453
454 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 454 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
455 memset(&desc->bitmap[0], 0, temp); 455 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
456 memset(&desc->bitmap[temp], 0xff, temp); 456 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
457 457
458 temp = 0x0008; /* per-port overcurrent reporting */ 458 temp = 0x0008; /* per-port overcurrent reporting */
459 if (HCS_PPC(oxu->hcs_params)) 459 if (HCS_PPC(oxu->hcs_params))
@@ -544,8 +544,6 @@ static void oxu_buf_free(struct oxu_hcd *oxu, struct ehci_qtd *qtd)
544 qtd->buffer = NULL; 544 qtd->buffer = NULL;
545 545
546 spin_unlock(&oxu->mem_lock); 546 spin_unlock(&oxu->mem_lock);
547
548 return;
549} 547}
550 548
551static inline void ehci_qtd_init(struct ehci_qtd *qtd, dma_addr_t dma) 549static inline void ehci_qtd_init(struct ehci_qtd *qtd, dma_addr_t dma)
@@ -571,8 +569,6 @@ static inline void oxu_qtd_free(struct oxu_hcd *oxu, struct ehci_qtd *qtd)
571 oxu->qtd_used[index] = 0; 569 oxu->qtd_used[index] = 0;
572 570
573 spin_unlock(&oxu->mem_lock); 571 spin_unlock(&oxu->mem_lock);
574
575 return;
576} 572}
577 573
578static struct ehci_qtd *ehci_qtd_alloc(struct oxu_hcd *oxu) 574static struct ehci_qtd *ehci_qtd_alloc(struct oxu_hcd *oxu)
@@ -615,8 +611,6 @@ static void oxu_qh_free(struct oxu_hcd *oxu, struct ehci_qh *qh)
615 oxu->qh_used[index] = 0; 611 oxu->qh_used[index] = 0;
616 612
617 spin_unlock(&oxu->mem_lock); 613 spin_unlock(&oxu->mem_lock);
618
619 return;
620} 614}
621 615
622static void qh_destroy(struct kref *kref) 616static void qh_destroy(struct kref *kref)
@@ -693,8 +687,6 @@ static void oxu_murb_free(struct oxu_hcd *oxu, struct oxu_murb *murb)
693 oxu->murb_used[index] = 0; 687 oxu->murb_used[index] = 0;
694 688
695 spin_unlock(&oxu->mem_lock); 689 spin_unlock(&oxu->mem_lock);
696
697 return;
698} 690}
699 691
700static struct oxu_murb *oxu_murb_alloc(struct oxu_hcd *oxu) 692static struct oxu_murb *oxu_murb_alloc(struct oxu_hcd *oxu)
@@ -1892,6 +1884,7 @@ static int enable_periodic(struct oxu_hcd *oxu)
1892 status = handshake(oxu, &oxu->regs->status, STS_PSS, 0, 9 * 125); 1884 status = handshake(oxu, &oxu->regs->status, STS_PSS, 0, 9 * 125);
1893 if (status != 0) { 1885 if (status != 0) {
1894 oxu_to_hcd(oxu)->state = HC_STATE_HALT; 1886 oxu_to_hcd(oxu)->state = HC_STATE_HALT;
1887 usb_hc_died(oxu_to_hcd(oxu));
1895 return status; 1888 return status;
1896 } 1889 }
1897 1890
@@ -1917,6 +1910,7 @@ static int disable_periodic(struct oxu_hcd *oxu)
1917 status = handshake(oxu, &oxu->regs->status, STS_PSS, STS_PSS, 9 * 125); 1910 status = handshake(oxu, &oxu->regs->status, STS_PSS, STS_PSS, 9 * 125);
1918 if (status != 0) { 1911 if (status != 0) {
1919 oxu_to_hcd(oxu)->state = HC_STATE_HALT; 1912 oxu_to_hcd(oxu)->state = HC_STATE_HALT;
1913 usb_hc_died(oxu_to_hcd(oxu));
1920 return status; 1914 return status;
1921 } 1915 }
1922 1916
@@ -2457,8 +2451,9 @@ static irqreturn_t oxu210_hcd_irq(struct usb_hcd *hcd)
2457 goto dead; 2451 goto dead;
2458 } 2452 }
2459 2453
2454 /* Shared IRQ? */
2460 status &= INTR_MASK; 2455 status &= INTR_MASK;
2461 if (!status) { /* irq sharing? */ 2456 if (!status || unlikely(hcd->state == HC_STATE_HALT)) {
2462 spin_unlock(&oxu->lock); 2457 spin_unlock(&oxu->lock);
2463 return IRQ_NONE; 2458 return IRQ_NONE;
2464 } 2459 }
@@ -2524,6 +2519,7 @@ static irqreturn_t oxu210_hcd_irq(struct usb_hcd *hcd)
2524dead: 2519dead:
2525 ehci_reset(oxu); 2520 ehci_reset(oxu);
2526 writel(0, &oxu->regs->configured_flag); 2521 writel(0, &oxu->regs->configured_flag);
2522 usb_hc_died(hcd);
2527 /* generic layer kills/unlinks all urbs, then 2523 /* generic layer kills/unlinks all urbs, then
2528 * uses oxu_stop to clean up the rest 2524 * uses oxu_stop to clean up the rest
2529 */ 2525 */
@@ -2887,7 +2883,7 @@ static int oxu_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2887 /* Ok, we have more job to do! :) */ 2883 /* Ok, we have more job to do! :) */
2888 2884
2889 for (i = 0; i < num - 1; i++) { 2885 for (i = 0; i < num - 1; i++) {
2890 /* Get free micro URB poll till a free urb is recieved */ 2886 /* Get free micro URB poll till a free urb is received */
2891 2887
2892 do { 2888 do {
2893 murb = (struct urb *) oxu_murb_alloc(oxu); 2889 murb = (struct urb *) oxu_murb_alloc(oxu);
@@ -2919,7 +2915,7 @@ static int oxu_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2919 2915
2920 /* Last urb requires special handling */ 2916 /* Last urb requires special handling */
2921 2917
2922 /* Get free micro URB poll till a free urb is recieved */ 2918 /* Get free micro URB poll till a free urb is received */
2923 do { 2919 do {
2924 murb = (struct urb *) oxu_murb_alloc(oxu); 2920 murb = (struct urb *) oxu_murb_alloc(oxu);
2925 if (!murb) 2921 if (!murb)
@@ -3070,7 +3066,6 @@ nogood:
3070 ep->hcpriv = NULL; 3066 ep->hcpriv = NULL;
3071done: 3067done:
3072 spin_unlock_irqrestore(&oxu->lock, flags); 3068 spin_unlock_irqrestore(&oxu->lock, flags);
3073 return;
3074} 3069}
3075 3070
3076static int oxu_get_frame(struct usb_hcd *hcd) 3071static int oxu_get_frame(struct usb_hcd *hcd)
@@ -3103,7 +3098,7 @@ static int oxu_hub_status_data(struct usb_hcd *hcd, char *buf)
3103 3098
3104 /* Some boards (mostly VIA?) report bogus overcurrent indications, 3099 /* Some boards (mostly VIA?) report bogus overcurrent indications,
3105 * causing massive log spam unless we completely ignore them. It 3100 * causing massive log spam unless we completely ignore them. It
3106 * may be relevant that VIA VT8235 controlers, where PORT_POWER is 3101 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
3107 * always set, seem to clear PORT_OCC and PORT_CSC when writing to 3102 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
3108 * PORT_POWER; that's surprising, but maybe within-spec. 3103 * PORT_POWER; that's surprising, but maybe within-spec.
3109 */ 3104 */
@@ -3696,7 +3691,7 @@ static void oxu_configuration(struct platform_device *pdev, void *base)
3696static int oxu_verify_id(struct platform_device *pdev, void *base) 3691static int oxu_verify_id(struct platform_device *pdev, void *base)
3697{ 3692{
3698 u32 id; 3693 u32 id;
3699 char *bo[] = { 3694 static const char * const bo[] = {
3700 "reserved", 3695 "reserved",
3701 "128-pin LQFP", 3696 "128-pin LQFP",
3702 "84-pin TFBGA", 3697 "84-pin TFBGA",
@@ -3841,7 +3836,7 @@ static int oxu_drv_probe(struct platform_device *pdev)
3841 return -EBUSY; 3836 return -EBUSY;
3842 } 3837 }
3843 3838
3844 ret = set_irq_type(irq, IRQF_TRIGGER_FALLING); 3839 ret = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING);
3845 if (ret) { 3840 if (ret) {
3846 dev_err(&pdev->dev, "error setting irq type\n"); 3841 dev_err(&pdev->dev, "error setting irq type\n");
3847 ret = -EFAULT; 3842 ret = -EFAULT;
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 83b5f9cea85a..fd930618c28f 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -14,6 +14,7 @@
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/acpi.h> 16#include <linux/acpi.h>
17#include <linux/dmi.h>
17#include "pci-quirks.h" 18#include "pci-quirks.h"
18#include "xhci-ext-caps.h" 19#include "xhci-ext-caps.h"
19 20
@@ -52,6 +53,298 @@
52#define EHCI_USBLEGCTLSTS 4 /* legacy control/status */ 53#define EHCI_USBLEGCTLSTS 4 /* legacy control/status */
53#define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */ 54#define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */
54 55
56/* AMD quirk use */
57#define AB_REG_BAR_LOW 0xe0
58#define AB_REG_BAR_HIGH 0xe1
59#define AB_REG_BAR_SB700 0xf0
60#define AB_INDX(addr) ((addr) + 0x00)
61#define AB_DATA(addr) ((addr) + 0x04)
62#define AX_INDXC 0x30
63#define AX_DATAC 0x34
64
65#define NB_PCIE_INDX_ADDR 0xe0
66#define NB_PCIE_INDX_DATA 0xe4
67#define PCIE_P_CNTL 0x10040
68#define BIF_NB 0x10002
69#define NB_PIF0_PWRDOWN_0 0x01100012
70#define NB_PIF0_PWRDOWN_1 0x01100013
71
72#define USB_INTEL_XUSB2PR 0xD0
73#define USB_INTEL_USB3_PSSEN 0xD8
74
75static struct amd_chipset_info {
76 struct pci_dev *nb_dev;
77 struct pci_dev *smbus_dev;
78 int nb_type;
79 int sb_type;
80 int isoc_reqs;
81 int probe_count;
82 int probe_result;
83} amd_chipset;
84
85static DEFINE_SPINLOCK(amd_lock);
86
87int usb_amd_find_chipset_info(void)
88{
89 u8 rev = 0;
90 unsigned long flags;
91 struct amd_chipset_info info;
92 int ret;
93
94 spin_lock_irqsave(&amd_lock, flags);
95
96 /* probe only once */
97 if (amd_chipset.probe_count > 0) {
98 amd_chipset.probe_count++;
99 spin_unlock_irqrestore(&amd_lock, flags);
100 return amd_chipset.probe_result;
101 }
102 memset(&info, 0, sizeof(info));
103 spin_unlock_irqrestore(&amd_lock, flags);
104
105 info.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL);
106 if (info.smbus_dev) {
107 rev = info.smbus_dev->revision;
108 if (rev >= 0x40)
109 info.sb_type = 1;
110 else if (rev >= 0x30 && rev <= 0x3b)
111 info.sb_type = 3;
112 } else {
113 info.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
114 0x780b, NULL);
115 if (!info.smbus_dev) {
116 ret = 0;
117 goto commit;
118 }
119
120 rev = info.smbus_dev->revision;
121 if (rev >= 0x11 && rev <= 0x18)
122 info.sb_type = 2;
123 }
124
125 if (info.sb_type == 0) {
126 if (info.smbus_dev) {
127 pci_dev_put(info.smbus_dev);
128 info.smbus_dev = NULL;
129 }
130 ret = 0;
131 goto commit;
132 }
133
134 info.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9601, NULL);
135 if (info.nb_dev) {
136 info.nb_type = 1;
137 } else {
138 info.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x1510, NULL);
139 if (info.nb_dev) {
140 info.nb_type = 2;
141 } else {
142 info.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD,
143 0x9600, NULL);
144 if (info.nb_dev)
145 info.nb_type = 3;
146 }
147 }
148
149 ret = info.probe_result = 1;
150 printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n");
151
152commit:
153
154 spin_lock_irqsave(&amd_lock, flags);
155 if (amd_chipset.probe_count > 0) {
156 /* race - someone else was faster - drop devices */
157
158 /* Mark that we where here */
159 amd_chipset.probe_count++;
160 ret = amd_chipset.probe_result;
161
162 spin_unlock_irqrestore(&amd_lock, flags);
163
164 if (info.nb_dev)
165 pci_dev_put(info.nb_dev);
166 if (info.smbus_dev)
167 pci_dev_put(info.smbus_dev);
168
169 } else {
170 /* no race - commit the result */
171 info.probe_count++;
172 amd_chipset = info;
173 spin_unlock_irqrestore(&amd_lock, flags);
174 }
175
176 return ret;
177}
178EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info);
179
180/*
181 * The hardware normally enables the A-link power management feature, which
182 * lets the system lower the power consumption in idle states.
183 *
184 * This USB quirk prevents the link going into that lower power state
185 * during isochronous transfers.
186 *
187 * Without this quirk, isochronous stream on OHCI/EHCI/xHCI controllers of
188 * some AMD platforms may stutter or have breaks occasionally.
189 */
190static void usb_amd_quirk_pll(int disable)
191{
192 u32 addr, addr_low, addr_high, val;
193 u32 bit = disable ? 0 : 1;
194 unsigned long flags;
195
196 spin_lock_irqsave(&amd_lock, flags);
197
198 if (disable) {
199 amd_chipset.isoc_reqs++;
200 if (amd_chipset.isoc_reqs > 1) {
201 spin_unlock_irqrestore(&amd_lock, flags);
202 return;
203 }
204 } else {
205 amd_chipset.isoc_reqs--;
206 if (amd_chipset.isoc_reqs > 0) {
207 spin_unlock_irqrestore(&amd_lock, flags);
208 return;
209 }
210 }
211
212 if (amd_chipset.sb_type == 1 || amd_chipset.sb_type == 2) {
213 outb_p(AB_REG_BAR_LOW, 0xcd6);
214 addr_low = inb_p(0xcd7);
215 outb_p(AB_REG_BAR_HIGH, 0xcd6);
216 addr_high = inb_p(0xcd7);
217 addr = addr_high << 8 | addr_low;
218
219 outl_p(0x30, AB_INDX(addr));
220 outl_p(0x40, AB_DATA(addr));
221 outl_p(0x34, AB_INDX(addr));
222 val = inl_p(AB_DATA(addr));
223 } else if (amd_chipset.sb_type == 3) {
224 pci_read_config_dword(amd_chipset.smbus_dev,
225 AB_REG_BAR_SB700, &addr);
226 outl(AX_INDXC, AB_INDX(addr));
227 outl(0x40, AB_DATA(addr));
228 outl(AX_DATAC, AB_INDX(addr));
229 val = inl(AB_DATA(addr));
230 } else {
231 spin_unlock_irqrestore(&amd_lock, flags);
232 return;
233 }
234
235 if (disable) {
236 val &= ~0x08;
237 val |= (1 << 4) | (1 << 9);
238 } else {
239 val |= 0x08;
240 val &= ~((1 << 4) | (1 << 9));
241 }
242 outl_p(val, AB_DATA(addr));
243
244 if (!amd_chipset.nb_dev) {
245 spin_unlock_irqrestore(&amd_lock, flags);
246 return;
247 }
248
249 if (amd_chipset.nb_type == 1 || amd_chipset.nb_type == 3) {
250 addr = PCIE_P_CNTL;
251 pci_write_config_dword(amd_chipset.nb_dev,
252 NB_PCIE_INDX_ADDR, addr);
253 pci_read_config_dword(amd_chipset.nb_dev,
254 NB_PCIE_INDX_DATA, &val);
255
256 val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12));
257 val |= bit | (bit << 3) | (bit << 12);
258 val |= ((!bit) << 4) | ((!bit) << 9);
259 pci_write_config_dword(amd_chipset.nb_dev,
260 NB_PCIE_INDX_DATA, val);
261
262 addr = BIF_NB;
263 pci_write_config_dword(amd_chipset.nb_dev,
264 NB_PCIE_INDX_ADDR, addr);
265 pci_read_config_dword(amd_chipset.nb_dev,
266 NB_PCIE_INDX_DATA, &val);
267 val &= ~(1 << 8);
268 val |= bit << 8;
269
270 pci_write_config_dword(amd_chipset.nb_dev,
271 NB_PCIE_INDX_DATA, val);
272 } else if (amd_chipset.nb_type == 2) {
273 addr = NB_PIF0_PWRDOWN_0;
274 pci_write_config_dword(amd_chipset.nb_dev,
275 NB_PCIE_INDX_ADDR, addr);
276 pci_read_config_dword(amd_chipset.nb_dev,
277 NB_PCIE_INDX_DATA, &val);
278 if (disable)
279 val &= ~(0x3f << 7);
280 else
281 val |= 0x3f << 7;
282
283 pci_write_config_dword(amd_chipset.nb_dev,
284 NB_PCIE_INDX_DATA, val);
285
286 addr = NB_PIF0_PWRDOWN_1;
287 pci_write_config_dword(amd_chipset.nb_dev,
288 NB_PCIE_INDX_ADDR, addr);
289 pci_read_config_dword(amd_chipset.nb_dev,
290 NB_PCIE_INDX_DATA, &val);
291 if (disable)
292 val &= ~(0x3f << 7);
293 else
294 val |= 0x3f << 7;
295
296 pci_write_config_dword(amd_chipset.nb_dev,
297 NB_PCIE_INDX_DATA, val);
298 }
299
300 spin_unlock_irqrestore(&amd_lock, flags);
301 return;
302}
303
304void usb_amd_quirk_pll_disable(void)
305{
306 usb_amd_quirk_pll(1);
307}
308EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_disable);
309
310void usb_amd_quirk_pll_enable(void)
311{
312 usb_amd_quirk_pll(0);
313}
314EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_enable);
315
316void usb_amd_dev_put(void)
317{
318 struct pci_dev *nb, *smbus;
319 unsigned long flags;
320
321 spin_lock_irqsave(&amd_lock, flags);
322
323 amd_chipset.probe_count--;
324 if (amd_chipset.probe_count > 0) {
325 spin_unlock_irqrestore(&amd_lock, flags);
326 return;
327 }
328
329 /* save them to pci_dev_put outside of spinlock */
330 nb = amd_chipset.nb_dev;
331 smbus = amd_chipset.smbus_dev;
332
333 amd_chipset.nb_dev = NULL;
334 amd_chipset.smbus_dev = NULL;
335 amd_chipset.nb_type = 0;
336 amd_chipset.sb_type = 0;
337 amd_chipset.isoc_reqs = 0;
338 amd_chipset.probe_result = 0;
339
340 spin_unlock_irqrestore(&amd_lock, flags);
341
342 if (nb)
343 pci_dev_put(nb);
344 if (smbus)
345 pci_dev_put(smbus);
346}
347EXPORT_SYMBOL_GPL(usb_amd_dev_put);
55 348
56/* 349/*
57 * Make sure the controller is completely inactive, unable to 350 * Make sure the controller is completely inactive, unable to
@@ -169,6 +462,7 @@ static int __devinit mmio_resource_enabled(struct pci_dev *pdev, int idx)
169static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev) 462static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
170{ 463{
171 void __iomem *base; 464 void __iomem *base;
465 u32 control;
172 466
173 if (!mmio_resource_enabled(pdev, 0)) 467 if (!mmio_resource_enabled(pdev, 0))
174 return; 468 return;
@@ -177,10 +471,14 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
177 if (base == NULL) 471 if (base == NULL)
178 return; 472 return;
179 473
474 control = readl(base + OHCI_CONTROL);
475
180/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */ 476/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
181#ifndef __hppa__ 477#ifdef __hppa__
182{ 478#define OHCI_CTRL_MASK (OHCI_CTRL_RWC | OHCI_CTRL_IR)
183 u32 control = readl(base + OHCI_CONTROL); 479#else
480#define OHCI_CTRL_MASK OHCI_CTRL_RWC
481
184 if (control & OHCI_CTRL_IR) { 482 if (control & OHCI_CTRL_IR) {
185 int wait_time = 500; /* arbitrary; 5 seconds */ 483 int wait_time = 500; /* arbitrary; 5 seconds */
186 writel(OHCI_INTR_OC, base + OHCI_INTRENABLE); 484 writel(OHCI_INTR_OC, base + OHCI_INTRENABLE);
@@ -194,13 +492,12 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
194 dev_warn(&pdev->dev, "OHCI: BIOS handoff failed" 492 dev_warn(&pdev->dev, "OHCI: BIOS handoff failed"
195 " (BIOS bug?) %08x\n", 493 " (BIOS bug?) %08x\n",
196 readl(base + OHCI_CONTROL)); 494 readl(base + OHCI_CONTROL));
197
198 /* reset controller, preserving RWC */
199 writel(control & OHCI_CTRL_RWC, base + OHCI_CONTROL);
200 } 495 }
201}
202#endif 496#endif
203 497
498 /* reset controller, preserving RWC (and possibly IR) */
499 writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL);
500
204 /* 501 /*
205 * disable interrupts 502 * disable interrupts
206 */ 503 */
@@ -210,14 +507,84 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
210 iounmap(base); 507 iounmap(base);
211} 508}
212 509
510static void __devinit ehci_bios_handoff(struct pci_dev *pdev,
511 void __iomem *op_reg_base,
512 u32 cap, u8 offset)
513{
514 int try_handoff = 1, tried_handoff = 0;
515
516 /* The Pegatron Lucid (ExoPC) tablet sporadically waits for 90
517 * seconds trying the handoff on its unused controller. Skip
518 * it. */
519 if (pdev->vendor == 0x8086 && pdev->device == 0x283a) {
520 const char *dmi_bn = dmi_get_system_info(DMI_BOARD_NAME);
521 const char *dmi_bv = dmi_get_system_info(DMI_BIOS_VERSION);
522 if (dmi_bn && !strcmp(dmi_bn, "EXOPG06411") &&
523 dmi_bv && !strcmp(dmi_bv, "Lucid-CE-133"))
524 try_handoff = 0;
525 }
526
527 if (try_handoff && (cap & EHCI_USBLEGSUP_BIOS)) {
528 dev_dbg(&pdev->dev, "EHCI: BIOS handoff\n");
529
530#if 0
531/* aleksey_gorelov@phoenix.com reports that some systems need SMI forced on,
532 * but that seems dubious in general (the BIOS left it off intentionally)
533 * and is known to prevent some systems from booting. so we won't do this
534 * unless maybe we can determine when we're on a system that needs SMI forced.
535 */
536 /* BIOS workaround (?): be sure the pre-Linux code
537 * receives the SMI
538 */
539 pci_read_config_dword(pdev, offset + EHCI_USBLEGCTLSTS, &val);
540 pci_write_config_dword(pdev, offset + EHCI_USBLEGCTLSTS,
541 val | EHCI_USBLEGCTLSTS_SOOE);
542#endif
543
544 /* some systems get upset if this semaphore is
545 * set for any other reason than forcing a BIOS
546 * handoff..
547 */
548 pci_write_config_byte(pdev, offset + 3, 1);
549 }
550
551 /* if boot firmware now owns EHCI, spin till it hands it over. */
552 if (try_handoff) {
553 int msec = 1000;
554 while ((cap & EHCI_USBLEGSUP_BIOS) && (msec > 0)) {
555 tried_handoff = 1;
556 msleep(10);
557 msec -= 10;
558 pci_read_config_dword(pdev, offset, &cap);
559 }
560 }
561
562 if (cap & EHCI_USBLEGSUP_BIOS) {
563 /* well, possibly buggy BIOS... try to shut it down,
564 * and hope nothing goes too wrong
565 */
566 if (try_handoff)
567 dev_warn(&pdev->dev, "EHCI: BIOS handoff failed"
568 " (BIOS bug?) %08x\n", cap);
569 pci_write_config_byte(pdev, offset + 2, 0);
570 }
571
572 /* just in case, always disable EHCI SMIs */
573 pci_write_config_dword(pdev, offset + EHCI_USBLEGCTLSTS, 0);
574
575 /* If the BIOS ever owned the controller then we can't expect
576 * any power sessions to remain intact.
577 */
578 if (tried_handoff)
579 writel(0, op_reg_base + EHCI_CONFIGFLAG);
580}
581
213static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev) 582static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
214{ 583{
215 int wait_time, delta;
216 void __iomem *base, *op_reg_base; 584 void __iomem *base, *op_reg_base;
217 u32 hcc_params, val; 585 u32 hcc_params, cap, val;
218 u8 offset, cap_length; 586 u8 offset, cap_length;
219 int count = 256/4; 587 int wait_time, delta, count = 256/4;
220 int tried_handoff = 0;
221 588
222 if (!mmio_resource_enabled(pdev, 0)) 589 if (!mmio_resource_enabled(pdev, 0))
223 return; 590 return;
@@ -236,77 +603,17 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
236 hcc_params = readl(base + EHCI_HCC_PARAMS); 603 hcc_params = readl(base + EHCI_HCC_PARAMS);
237 offset = (hcc_params >> 8) & 0xff; 604 offset = (hcc_params >> 8) & 0xff;
238 while (offset && --count) { 605 while (offset && --count) {
239 u32 cap;
240 int msec;
241
242 pci_read_config_dword(pdev, offset, &cap); 606 pci_read_config_dword(pdev, offset, &cap);
243 switch (cap & 0xff) {
244 case 1: /* BIOS/SMM/... handoff support */
245 if ((cap & EHCI_USBLEGSUP_BIOS)) {
246 dev_dbg(&pdev->dev, "EHCI: BIOS handoff\n");
247 607
248#if 0 608 switch (cap & 0xff) {
249/* aleksey_gorelov@phoenix.com reports that some systems need SMI forced on, 609 case 1:
250 * but that seems dubious in general (the BIOS left it off intentionally) 610 ehci_bios_handoff(pdev, op_reg_base, cap, offset);
251 * and is known to prevent some systems from booting. so we won't do this
252 * unless maybe we can determine when we're on a system that needs SMI forced.
253 */
254 /* BIOS workaround (?): be sure the
255 * pre-Linux code receives the SMI
256 */
257 pci_read_config_dword(pdev,
258 offset + EHCI_USBLEGCTLSTS,
259 &val);
260 pci_write_config_dword(pdev,
261 offset + EHCI_USBLEGCTLSTS,
262 val | EHCI_USBLEGCTLSTS_SOOE);
263#endif
264
265 /* some systems get upset if this semaphore is
266 * set for any other reason than forcing a BIOS
267 * handoff..
268 */
269 pci_write_config_byte(pdev, offset + 3, 1);
270 }
271
272 /* if boot firmware now owns EHCI, spin till
273 * it hands it over.
274 */
275 msec = 1000;
276 while ((cap & EHCI_USBLEGSUP_BIOS) && (msec > 0)) {
277 tried_handoff = 1;
278 msleep(10);
279 msec -= 10;
280 pci_read_config_dword(pdev, offset, &cap);
281 }
282
283 if (cap & EHCI_USBLEGSUP_BIOS) {
284 /* well, possibly buggy BIOS... try to shut
285 * it down, and hope nothing goes too wrong
286 */
287 dev_warn(&pdev->dev, "EHCI: BIOS handoff failed"
288 " (BIOS bug?) %08x\n", cap);
289 pci_write_config_byte(pdev, offset + 2, 0);
290 }
291
292 /* just in case, always disable EHCI SMIs */
293 pci_write_config_dword(pdev,
294 offset + EHCI_USBLEGCTLSTS,
295 0);
296
297 /* If the BIOS ever owned the controller then we
298 * can't expect any power sessions to remain intact.
299 */
300 if (tried_handoff)
301 writel(0, op_reg_base + EHCI_CONFIGFLAG);
302 break; 611 break;
303 case 0: /* illegal reserved capability */ 612 case 0: /* Illegal reserved cap, set cap=0 so we exit */
304 cap = 0; 613 cap = 0; /* then fallthrough... */
305 /* FALLTHROUGH */
306 default: 614 default:
307 dev_warn(&pdev->dev, "EHCI: unrecognized capability " 615 dev_warn(&pdev->dev, "EHCI: unrecognized capability "
308 "%02x\n", cap & 0xff); 616 "%02x\n", cap & 0xff);
309 break;
310 } 617 }
311 offset = (cap >> 8) & 0xff; 618 offset = (cap >> 8) & 0xff;
312 } 619 }
@@ -338,8 +645,6 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
338 writel(0x3f, op_reg_base + EHCI_USBSTS); 645 writel(0x3f, op_reg_base + EHCI_USBSTS);
339 646
340 iounmap(base); 647 iounmap(base);
341
342 return;
343} 648}
344 649
345/* 650/*
@@ -371,6 +676,64 @@ static int handshake(void __iomem *ptr, u32 mask, u32 done,
371 return -ETIMEDOUT; 676 return -ETIMEDOUT;
372} 677}
373 678
679bool usb_is_intel_switchable_xhci(struct pci_dev *pdev)
680{
681 return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
682 pdev->vendor == PCI_VENDOR_ID_INTEL &&
683 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI;
684}
685EXPORT_SYMBOL_GPL(usb_is_intel_switchable_xhci);
686
687/*
688 * Intel's Panther Point chipset has two host controllers (EHCI and xHCI) that
689 * share some number of ports. These ports can be switched between either
690 * controller. Not all of the ports under the EHCI host controller may be
691 * switchable.
692 *
693 * The ports should be switched over to xHCI before PCI probes for any device
694 * start. This avoids active devices under EHCI being disconnected during the
695 * port switchover, which could cause loss of data on USB storage devices, or
696 * failed boot when the root file system is on a USB mass storage device and is
697 * enumerated under EHCI first.
698 *
699 * We write into the xHC's PCI configuration space in some Intel-specific
700 * registers to switch the ports over. The USB 3.0 terminations and the USB
701 * 2.0 data wires are switched separately. We want to enable the SuperSpeed
702 * terminations before switching the USB 2.0 wires over, so that USB 3.0
703 * devices connect at SuperSpeed, rather than at USB 2.0 speeds.
704 */
705void usb_enable_xhci_ports(struct pci_dev *xhci_pdev)
706{
707 u32 ports_available;
708
709 ports_available = 0xffffffff;
710 /* Write USB3_PSSEN, the USB 3.0 Port SuperSpeed Enable
711 * Register, to turn on SuperSpeed terminations for all
712 * available ports.
713 */
714 pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
715 cpu_to_le32(ports_available));
716
717 pci_read_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
718 &ports_available);
719 dev_dbg(&xhci_pdev->dev, "USB 3.0 ports that are now enabled "
720 "under xHCI: 0x%x\n", ports_available);
721
722 ports_available = 0xffffffff;
723 /* Write XUSB2PR, the xHC USB 2.0 Port Routing Register, to
724 * switch the USB 2.0 power and data lines over to the xHCI
725 * host.
726 */
727 pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
728 cpu_to_le32(ports_available));
729
730 pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
731 &ports_available);
732 dev_dbg(&xhci_pdev->dev, "USB 2.0 ports that are now switched over "
733 "to xHCI: 0x%x\n", ports_available);
734}
735EXPORT_SYMBOL_GPL(usb_enable_xhci_ports);
736
374/** 737/**
375 * PCI Quirks for xHCI. 738 * PCI Quirks for xHCI.
376 * 739 *
@@ -430,6 +793,8 @@ static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev)
430 writel(XHCI_LEGACY_DISABLE_SMI, 793 writel(XHCI_LEGACY_DISABLE_SMI,
431 base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET); 794 base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET);
432 795
796 if (usb_is_intel_switchable_xhci(pdev))
797 usb_enable_xhci_ports(pdev);
433hc_init: 798hc_init:
434 op_reg_base = base + XHCI_HC_LENGTH(readl(base)); 799 op_reg_base = base + XHCI_HC_LENGTH(readl(base));
435 800
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h
index 1564edfff6fe..b1002a8ef96f 100644
--- a/drivers/usb/host/pci-quirks.h
+++ b/drivers/usb/host/pci-quirks.h
@@ -1,7 +1,19 @@
1#ifndef __LINUX_USB_PCI_QUIRKS_H 1#ifndef __LINUX_USB_PCI_QUIRKS_H
2#define __LINUX_USB_PCI_QUIRKS_H 2#define __LINUX_USB_PCI_QUIRKS_H
3 3
4#ifdef CONFIG_PCI
4void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); 5void uhci_reset_hc(struct pci_dev *pdev, unsigned long base);
5int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base); 6int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base);
7int usb_amd_find_chipset_info(void);
8void usb_amd_dev_put(void);
9void usb_amd_quirk_pll_disable(void);
10void usb_amd_quirk_pll_enable(void);
11bool usb_is_intel_switchable_xhci(struct pci_dev *pdev);
12void usb_enable_xhci_ports(struct pci_dev *xhci_pdev);
13#else
14static inline void usb_amd_quirk_pll_disable(void) {}
15static inline void usb_amd_quirk_pll_enable(void) {}
16static inline void usb_amd_dev_put(void) {}
17#endif /* CONFIG_PCI */
6 18
7#endif /* __LINUX_USB_PCI_QUIRKS_H */ 19#endif /* __LINUX_USB_PCI_QUIRKS_H */
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 77be3c24a427..4586369dda00 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -2150,8 +2150,9 @@ static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597,
2150 desc->bDescLength = 9; 2150 desc->bDescLength = 9;
2151 desc->bPwrOn2PwrGood = 0; 2151 desc->bPwrOn2PwrGood = 0;
2152 desc->wHubCharacteristics = cpu_to_le16(0x0011); 2152 desc->wHubCharacteristics = cpu_to_le16(0x0011);
2153 desc->bitmap[0] = ((1 << r8a66597->max_root_hub) - 1) << 1; 2153 desc->u.hs.DeviceRemovable[0] =
2154 desc->bitmap[1] = ~0; 2154 ((1 << r8a66597->max_root_hub) - 1) << 1;
2155 desc->u.hs.DeviceRemovable[1] = ~0;
2155} 2156}
2156 2157
2157static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 2158static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
@@ -2397,7 +2398,7 @@ static const struct dev_pm_ops r8a66597_dev_pm_ops = {
2397#define R8A66597_DEV_PM_OPS NULL 2398#define R8A66597_DEV_PM_OPS NULL
2398#endif 2399#endif
2399 2400
2400static int __init_or_module r8a66597_remove(struct platform_device *pdev) 2401static int __devexit r8a66597_remove(struct platform_device *pdev)
2401{ 2402{
2402 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); 2403 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
2403 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); 2404 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
@@ -2516,6 +2517,7 @@ static int __devinit r8a66597_probe(struct platform_device *pdev)
2516 INIT_LIST_HEAD(&r8a66597->child_device); 2517 INIT_LIST_HEAD(&r8a66597->child_device);
2517 2518
2518 hcd->rsrc_start = res->start; 2519 hcd->rsrc_start = res->start;
2520 hcd->has_tt = 1;
2519 2521
2520 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | irq_trigger); 2522 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | irq_trigger);
2521 if (ret != 0) { 2523 if (ret != 0) {
@@ -2542,7 +2544,7 @@ clean_up:
2542 2544
2543static struct platform_driver r8a66597_driver = { 2545static struct platform_driver r8a66597_driver = {
2544 .probe = r8a66597_probe, 2546 .probe = r8a66597_probe,
2545 .remove = r8a66597_remove, 2547 .remove = __devexit_p(r8a66597_remove),
2546 .driver = { 2548 .driver = {
2547 .name = (char *) hcd_name, 2549 .name = (char *) hcd_name,
2548 .owner = THIS_MODULE, 2550 .owner = THIS_MODULE,
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h
index 95d0f5adfdcf..25563e9a90bc 100644
--- a/drivers/usb/host/r8a66597.h
+++ b/drivers/usb/host/r8a66597.h
@@ -227,7 +227,7 @@ static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597,
227 int odd = len & 0x0001; 227 int odd = len & 0x0001;
228 228
229 len = len / 2; 229 len = len / 2;
230 ioread16_rep(fifoaddr, buf, len); 230 iowrite16_rep(fifoaddr, buf, len);
231 if (unlikely(odd)) { 231 if (unlikely(odd)) {
232 buf = &buf[len]; 232 buf = &buf[len];
233 iowrite8((unsigned char)*buf, fifoaddr); 233 iowrite8((unsigned char)*buf, fifoaddr);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 990f06b89eaa..1a996245ab98 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -47,6 +47,7 @@
47#include <linux/usb/sl811.h> 47#include <linux/usb/sl811.h>
48#include <linux/usb/hcd.h> 48#include <linux/usb/hcd.h>
49#include <linux/platform_device.h> 49#include <linux/platform_device.h>
50#include <linux/prefetch.h>
50 51
51#include <asm/io.h> 52#include <asm/io.h>
52#include <asm/irq.h> 53#include <asm/irq.h>
@@ -71,12 +72,6 @@ MODULE_ALIAS("platform:sl811-hcd");
71/* for now, use only one transfer register bank */ 72/* for now, use only one transfer register bank */
72#undef USE_B 73#undef USE_B
73 74
74/* this doesn't understand urb->iso_frame_desc[], but if you had a driver
75 * that just queued one ISO frame per URB then iso transfers "should" work
76 * using the normal urb status fields.
77 */
78#define DISABLE_ISO
79
80// #define QUIRK2 75// #define QUIRK2
81#define QUIRK3 76#define QUIRK3
82 77
@@ -807,7 +802,7 @@ static int sl811h_urb_enqueue(
807 int retval; 802 int retval;
808 struct usb_host_endpoint *hep = urb->ep; 803 struct usb_host_endpoint *hep = urb->ep;
809 804
810#ifdef DISABLE_ISO 805#ifndef CONFIG_USB_SL811_HCD_ISO
811 if (type == PIPE_ISOCHRONOUS) 806 if (type == PIPE_ISOCHRONOUS)
812 return -ENOSPC; 807 return -ENOSPC;
813#endif 808#endif
@@ -861,6 +856,7 @@ static int sl811h_urb_enqueue(
861 DBG("dev %d ep%d maxpacket %d\n", 856 DBG("dev %d ep%d maxpacket %d\n",
862 udev->devnum, epnum, ep->maxpacket); 857 udev->devnum, epnum, ep->maxpacket);
863 retval = -EINVAL; 858 retval = -EINVAL;
859 kfree(ep);
864 goto fail; 860 goto fail;
865 } 861 }
866 862
@@ -1110,9 +1106,9 @@ sl811h_hub_descriptor (
1110 1106
1111 desc->wHubCharacteristics = cpu_to_le16(temp); 1107 desc->wHubCharacteristics = cpu_to_le16(temp);
1112 1108
1113 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ 1109 /* ports removable, and legacy PortPwrCtrlMask */
1114 desc->bitmap[0] = 0 << 1; 1110 desc->u.hs.DeviceRemovable[0] = 0 << 1;
1115 desc->bitmap[1] = ~0; 1111 desc->u.hs.DeviceRemovable[1] = ~0;
1116} 1112}
1117 1113
1118static void 1114static void
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index 0e13a00eb2ed..3b6f50eaec91 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -20,7 +20,6 @@
20#include <linux/ioport.h> 20#include <linux/ioport.h>
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22 22
23#include <pcmcia/cs.h>
24#include <pcmcia/cistpl.h> 23#include <pcmcia/cistpl.h>
25#include <pcmcia/cisreg.h> 24#include <pcmcia/cisreg.h>
26#include <pcmcia/ds.h> 25#include <pcmcia/ds.h>
@@ -132,49 +131,12 @@ static void sl811_cs_release(struct pcmcia_device * link)
132 platform_device_unregister(&platform_dev); 131 platform_device_unregister(&platform_dev);
133} 132}
134 133
135static int sl811_cs_config_check(struct pcmcia_device *p_dev, 134static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
136 cistpl_cftable_entry_t *cfg,
137 cistpl_cftable_entry_t *dflt,
138 unsigned int vcc,
139 void *priv_data)
140{ 135{
141 if (cfg->index == 0) 136 if (p_dev->config_index == 0)
142 return -ENODEV; 137 return -EINVAL;
143 138
144 /* Use power settings for Vcc and Vpp if present */ 139 return pcmcia_request_io(p_dev);
145 /* Note that the CIS values need to be rescaled */
146 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
147 if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
148 return -ENODEV;
149 } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
150 if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
151 return -ENODEV;
152 }
153
154 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
155 p_dev->conf.Vpp =
156 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
157 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
158 p_dev->conf.Vpp =
159 dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
160
161 /* we need an interrupt */
162 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
163
164 /* IO window settings */
165 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
166 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
167 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
168 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
169
170 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
171 p_dev->resource[0]->start = io->win[0].base;
172 p_dev->resource[0]->end = io->win[0].len;
173
174 return pcmcia_request_io(p_dev);
175 }
176 pcmcia_disable_device(p_dev);
177 return -ENODEV;
178} 140}
179 141
180 142
@@ -185,6 +147,9 @@ static int sl811_cs_config(struct pcmcia_device *link)
185 147
186 dev_dbg(&link->dev, "sl811_cs_config\n"); 148 dev_dbg(&link->dev, "sl811_cs_config\n");
187 149
150 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
151 CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO;
152
188 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL)) 153 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
189 goto failed; 154 goto failed;
190 155
@@ -195,18 +160,10 @@ static int sl811_cs_config(struct pcmcia_device *link)
195 if (!link->irq) 160 if (!link->irq)
196 goto failed; 161 goto failed;
197 162
198 ret = pcmcia_request_configuration(link, &link->conf); 163 ret = pcmcia_enable_device(link);
199 if (ret) 164 if (ret)
200 goto failed; 165 goto failed;
201 166
202 dev_info(&link->dev, "index 0x%02x: ",
203 link->conf.ConfigIndex);
204 if (link->conf.Vpp)
205 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
206 printk(", irq %d", link->irq);
207 printk(", io %pR", link->resource[0]);
208 printk("\n");
209
210 if (sl811_hc_init(parent, link->resource[0]->start, link->irq) 167 if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
211 < 0) { 168 < 0) {
212failed: 169failed:
@@ -227,13 +184,10 @@ static int sl811_cs_probe(struct pcmcia_device *link)
227 local->p_dev = link; 184 local->p_dev = link;
228 link->priv = local; 185 link->priv = local;
229 186
230 link->conf.Attributes = 0;
231 link->conf.IntType = INT_MEMORY_AND_IO;
232
233 return sl811_cs_config(link); 187 return sl811_cs_config(link);
234} 188}
235 189
236static struct pcmcia_device_id sl811_ids[] = { 190static const struct pcmcia_device_id sl811_ids[] = {
237 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */ 191 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
238 PCMCIA_DEVICE_NULL, 192 PCMCIA_DEVICE_NULL,
239}; 193};
@@ -241,9 +195,7 @@ MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
241 195
242static struct pcmcia_driver sl811_cs_driver = { 196static struct pcmcia_driver sl811_cs_driver = {
243 .owner = THIS_MODULE, 197 .owner = THIS_MODULE,
244 .drv = { 198 .name = "sl811_cs",
245 .name = "sl811_cs",
246 },
247 .probe = sl811_cs_probe, 199 .probe = sl811_cs_probe,
248 .remove = sl811_cs_detach, 200 .remove = sl811_cs_detach,
249 .id_table = sl811_ids, 201 .id_table = sl811_ids,
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 5b31bae92dbc..533d12cca371 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -316,7 +316,6 @@ static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
316 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0)) 316 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0))
317 return; 317 return;
318 kref_put(&u132->kref, u132_hcd_delete); 318 kref_put(&u132->kref, u132_hcd_delete);
319 return;
320} 319}
321 320
322static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring, 321static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
@@ -324,7 +323,6 @@ static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
324{ 323{
325 kref_get(&u132->kref); 324 kref_get(&u132->kref);
326 u132_ring_requeue_work(u132, ring, delta); 325 u132_ring_requeue_work(u132, ring, delta);
327 return;
328} 326}
329 327
330static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring) 328static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
@@ -543,7 +541,6 @@ static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
543 mutex_unlock(&u132->scheduler_lock); 541 mutex_unlock(&u132->scheduler_lock);
544 u132_endp_put_kref(u132, endp); 542 u132_endp_put_kref(u132, endp);
545 usb_hcd_giveback_urb(hcd, urb, status); 543 usb_hcd_giveback_urb(hcd, urb, status);
546 return;
547} 544}
548 545
549static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp, 546static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
@@ -574,8 +571,8 @@ static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
574 endp->active = 0; 571 endp->active = 0;
575 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 572 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
576 kfree(urbq); 573 kfree(urbq);
577 } usb_hcd_giveback_urb(hcd, urb, status); 574 }
578 return; 575 usb_hcd_giveback_urb(hcd, urb, status);
579} 576}
580 577
581static inline int edset_input(struct u132 *u132, struct u132_ring *ring, 578static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
@@ -2607,13 +2604,14 @@ static int u132_roothub_descriptor(struct u132 *u132,
2607 retval = u132_read_pcimem(u132, roothub.b, &rh_b); 2604 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2608 if (retval) 2605 if (retval)
2609 return retval; 2606 return retval;
2610 memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); 2607 memset(desc->u.hs.DeviceRemovable, 0xff,
2611 desc->bitmap[0] = rh_b & RH_B_DR; 2608 sizeof(desc->u.hs.DeviceRemovable));
2609 desc->u.hs.DeviceRemovable[0] = rh_b & RH_B_DR;
2612 if (u132->num_ports > 7) { 2610 if (u132->num_ports > 7) {
2613 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8; 2611 desc->u.hs.DeviceRemovable[1] = (rh_b & RH_B_DR) >> 8;
2614 desc->bitmap[2] = 0xff; 2612 desc->u.hs.DeviceRemovable[2] = 0xff;
2615 } else 2613 } else
2616 desc->bitmap[1] = 0xff; 2614 desc->u.hs.DeviceRemovable[1] = 0xff;
2617 return 0; 2615 return 0;
2618} 2616}
2619 2617
@@ -3085,7 +3083,6 @@ static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3085 u132->endp[endps] = NULL; 3083 u132->endp[endps] = NULL;
3086 3084
3087 mutex_unlock(&u132->sw_lock); 3085 mutex_unlock(&u132->sw_lock);
3088 return;
3089} 3086}
3090 3087
3091static int __devinit u132_probe(struct platform_device *pdev) 3088static int __devinit u132_probe(struct platform_device *pdev)
@@ -3233,8 +3230,7 @@ static int __init u132_hcd_init(void)
3233 mutex_init(&u132_module_lock); 3230 mutex_init(&u132_module_lock);
3234 if (usb_disabled()) 3231 if (usb_disabled())
3235 return -ENODEV; 3232 return -ENODEV;
3236 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__, 3233 printk(KERN_INFO "driver %s\n", hcd_name);
3237 __DATE__);
3238 workqueue = create_singlethread_workqueue("u132"); 3234 workqueue = create_singlethread_workqueue("u132");
3239 retval = platform_driver_register(&u132_platform_driver); 3235 retval = platform_driver_register(&u132_platform_driver);
3240 return retval; 3236 return retval;
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 6e7fb5f38db6..fc0b0daac93d 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -12,7 +12,6 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/debugfs.h> 14#include <linux/debugfs.h>
15#include <linux/smp_lock.h>
16#include <asm/io.h> 15#include <asm/io.h>
17 16
18#include "uhci-hcd.h" 17#include "uhci-hcd.h"
@@ -38,7 +37,8 @@ static void lprintk(char *buf)
38 } 37 }
39} 38}
40 39
41static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space) 40static int uhci_show_td(struct uhci_hcd *uhci, struct uhci_td *td, char *buf,
41 int len, int space)
42{ 42{
43 char *out = buf; 43 char *out = buf;
44 char *spid; 44 char *spid;
@@ -48,8 +48,9 @@ static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space)
48 if (len < 160) 48 if (len < 160)
49 return 0; 49 return 0;
50 50
51 status = td_status(td); 51 status = td_status(uhci, td);
52 out += sprintf(out, "%*s[%p] link (%08x) ", space, "", td, le32_to_cpu(td->link)); 52 out += sprintf(out, "%*s[%p] link (%08x) ", space, "", td,
53 hc32_to_cpu(uhci, td->link));
53 out += sprintf(out, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ", 54 out += sprintf(out, "e%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
54 ((status >> 27) & 3), 55 ((status >> 27) & 3),
55 (status & TD_CTRL_SPD) ? "SPD " : "", 56 (status & TD_CTRL_SPD) ? "SPD " : "",
@@ -64,7 +65,7 @@ static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space)
64 (status & TD_CTRL_BITSTUFF) ? "BitStuff " : "", 65 (status & TD_CTRL_BITSTUFF) ? "BitStuff " : "",
65 status & 0x7ff); 66 status & 0x7ff);
66 67
67 token = td_token(td); 68 token = td_token(uhci, td);
68 switch (uhci_packetid(token)) { 69 switch (uhci_packetid(token)) {
69 case USB_PID_SETUP: 70 case USB_PID_SETUP:
70 spid = "SETUP"; 71 spid = "SETUP";
@@ -87,12 +88,13 @@ static int uhci_show_td(struct uhci_td *td, char *buf, int len, int space)
87 (token >> 8) & 127, 88 (token >> 8) & 127,
88 (token & 0xff), 89 (token & 0xff),
89 spid); 90 spid);
90 out += sprintf(out, "(buf=%08x)\n", le32_to_cpu(td->buffer)); 91 out += sprintf(out, "(buf=%08x)\n", hc32_to_cpu(uhci, td->buffer));
91 92
92 return out - buf; 93 return out - buf;
93} 94}
94 95
95static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space) 96static int uhci_show_urbp(struct uhci_hcd *uhci, struct urb_priv *urbp,
97 char *buf, int len, int space)
96{ 98{
97 char *out = buf; 99 char *out = buf;
98 struct uhci_td *td; 100 struct uhci_td *td;
@@ -131,9 +133,10 @@ static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space)
131 if (urbp->qh->type != USB_ENDPOINT_XFER_ISOC && 133 if (urbp->qh->type != USB_ENDPOINT_XFER_ISOC &&
132 (++i <= 10 || debug > 2)) { 134 (++i <= 10 || debug > 2)) {
133 out += sprintf(out, "%*s%d: ", space + 2, "", i); 135 out += sprintf(out, "%*s%d: ", space + 2, "", i);
134 out += uhci_show_td(td, out, len - (out - buf), 0); 136 out += uhci_show_td(uhci, td, out,
137 len - (out - buf), 0);
135 } else { 138 } else {
136 if (td_status(td) & TD_CTRL_ACTIVE) 139 if (td_status(uhci, td) & TD_CTRL_ACTIVE)
137 ++nactive; 140 ++nactive;
138 else 141 else
139 ++ninactive; 142 ++ninactive;
@@ -152,7 +155,7 @@ static int uhci_show_qh(struct uhci_hcd *uhci,
152{ 155{
153 char *out = buf; 156 char *out = buf;
154 int i, nurbs; 157 int i, nurbs;
155 __le32 element = qh_element(qh); 158 __hc32 element = qh_element(qh);
156 char *qtype; 159 char *qtype;
157 160
158 /* Try to make sure there's enough memory */ 161 /* Try to make sure there's enough memory */
@@ -169,7 +172,8 @@ static int uhci_show_qh(struct uhci_hcd *uhci,
169 172
170 out += sprintf(out, "%*s[%p] %s QH link (%08x) element (%08x)\n", 173 out += sprintf(out, "%*s[%p] %s QH link (%08x) element (%08x)\n",
171 space, "", qh, qtype, 174 space, "", qh, qtype,
172 le32_to_cpu(qh->link), le32_to_cpu(element)); 175 hc32_to_cpu(uhci, qh->link),
176 hc32_to_cpu(uhci, element));
173 if (qh->type == USB_ENDPOINT_XFER_ISOC) 177 if (qh->type == USB_ENDPOINT_XFER_ISOC)
174 out += sprintf(out, "%*s period %d phase %d load %d us, " 178 out += sprintf(out, "%*s period %d phase %d load %d us, "
175 "frame %x desc [%p]\n", 179 "frame %x desc [%p]\n",
@@ -179,22 +183,22 @@ static int uhci_show_qh(struct uhci_hcd *uhci,
179 out += sprintf(out, "%*s period %d phase %d load %d us\n", 183 out += sprintf(out, "%*s period %d phase %d load %d us\n",
180 space, "", qh->period, qh->phase, qh->load); 184 space, "", qh->period, qh->phase, qh->load);
181 185
182 if (element & UHCI_PTR_QH) 186 if (element & UHCI_PTR_QH(uhci))
183 out += sprintf(out, "%*s Element points to QH (bug?)\n", space, ""); 187 out += sprintf(out, "%*s Element points to QH (bug?)\n", space, "");
184 188
185 if (element & UHCI_PTR_DEPTH) 189 if (element & UHCI_PTR_DEPTH(uhci))
186 out += sprintf(out, "%*s Depth traverse\n", space, ""); 190 out += sprintf(out, "%*s Depth traverse\n", space, "");
187 191
188 if (element & cpu_to_le32(8)) 192 if (element & cpu_to_hc32(uhci, 8))
189 out += sprintf(out, "%*s Bit 3 set (bug?)\n", space, ""); 193 out += sprintf(out, "%*s Bit 3 set (bug?)\n", space, "");
190 194
191 if (!(element & ~(UHCI_PTR_QH | UHCI_PTR_DEPTH))) 195 if (!(element & ~(UHCI_PTR_QH(uhci) | UHCI_PTR_DEPTH(uhci))))
192 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, ""); 196 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, "");
193 197
194 if (list_empty(&qh->queue)) { 198 if (list_empty(&qh->queue)) {
195 out += sprintf(out, "%*s queue is empty\n", space, ""); 199 out += sprintf(out, "%*s queue is empty\n", space, "");
196 if (qh == uhci->skel_async_qh) 200 if (qh == uhci->skel_async_qh)
197 out += uhci_show_td(uhci->term_td, out, 201 out += uhci_show_td(uhci, uhci->term_td, out,
198 len - (out - buf), 0); 202 len - (out - buf), 0);
199 } else { 203 } else {
200 struct urb_priv *urbp = list_entry(qh->queue.next, 204 struct urb_priv *urbp = list_entry(qh->queue.next,
@@ -202,13 +206,13 @@ static int uhci_show_qh(struct uhci_hcd *uhci,
202 struct uhci_td *td = list_entry(urbp->td_list.next, 206 struct uhci_td *td = list_entry(urbp->td_list.next,
203 struct uhci_td, list); 207 struct uhci_td, list);
204 208
205 if (element != LINK_TO_TD(td)) 209 if (element != LINK_TO_TD(uhci, td))
206 out += sprintf(out, "%*s Element != First TD\n", 210 out += sprintf(out, "%*s Element != First TD\n",
207 space, ""); 211 space, "");
208 i = nurbs = 0; 212 i = nurbs = 0;
209 list_for_each_entry(urbp, &qh->queue, node) { 213 list_for_each_entry(urbp, &qh->queue, node) {
210 if (++i <= 10) 214 if (++i <= 10)
211 out += uhci_show_urbp(urbp, out, 215 out += uhci_show_urbp(uhci, urbp, out,
212 len - (out - buf), space + 2); 216 len - (out - buf), space + 2);
213 else 217 else
214 ++nurbs; 218 ++nurbs;
@@ -220,7 +224,8 @@ static int uhci_show_qh(struct uhci_hcd *uhci,
220 224
221 if (qh->dummy_td) { 225 if (qh->dummy_td) {
222 out += sprintf(out, "%*s Dummy TD\n", space, ""); 226 out += sprintf(out, "%*s Dummy TD\n", space, "");
223 out += uhci_show_td(qh->dummy_td, out, len - (out - buf), 0); 227 out += uhci_show_td(uhci, qh->dummy_td, out,
228 len - (out - buf), 0);
224 } 229 }
225 230
226 return out - buf; 231 return out - buf;
@@ -286,7 +291,6 @@ static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len)
286static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) 291static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
287{ 292{
288 char *out = buf; 293 char *out = buf;
289 unsigned long io_addr = uhci->io_addr;
290 unsigned short usbcmd, usbstat, usbint, usbfrnum; 294 unsigned short usbcmd, usbstat, usbint, usbfrnum;
291 unsigned int flbaseadd; 295 unsigned int flbaseadd;
292 unsigned char sof; 296 unsigned char sof;
@@ -296,14 +300,14 @@ static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
296 if (len < 80 * 9) 300 if (len < 80 * 9)
297 return 0; 301 return 0;
298 302
299 usbcmd = inw(io_addr + 0); 303 usbcmd = uhci_readw(uhci, 0);
300 usbstat = inw(io_addr + 2); 304 usbstat = uhci_readw(uhci, 2);
301 usbint = inw(io_addr + 4); 305 usbint = uhci_readw(uhci, 4);
302 usbfrnum = inw(io_addr + 6); 306 usbfrnum = uhci_readw(uhci, 6);
303 flbaseadd = inl(io_addr + 8); 307 flbaseadd = uhci_readl(uhci, 8);
304 sof = inb(io_addr + 12); 308 sof = uhci_readb(uhci, 12);
305 portsc1 = inw(io_addr + 16); 309 portsc1 = uhci_readw(uhci, 16);
306 portsc2 = inw(io_addr + 18); 310 portsc2 = uhci_readw(uhci, 18);
307 311
308 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n", 312 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
309 usbcmd, 313 usbcmd,
@@ -348,8 +352,8 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
348 struct uhci_td *td; 352 struct uhci_td *td;
349 struct list_head *tmp, *head; 353 struct list_head *tmp, *head;
350 int nframes, nerrs; 354 int nframes, nerrs;
351 __le32 link; 355 __hc32 link;
352 __le32 fsbr_link; 356 __hc32 fsbr_link;
353 357
354 static const char * const qh_names[] = { 358 static const char * const qh_names[] = {
355 "unlink", "iso", "int128", "int64", "int32", "int16", 359 "unlink", "iso", "int128", "int64", "int32", "int16",
@@ -377,7 +381,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
377 nframes = 10; 381 nframes = 10;
378 nerrs = 0; 382 nerrs = 0;
379 for (i = 0; i < UHCI_NUMFRAMES; ++i) { 383 for (i = 0; i < UHCI_NUMFRAMES; ++i) {
380 __le32 qh_dma; 384 __hc32 qh_dma;
381 385
382 j = 0; 386 j = 0;
383 td = uhci->frame_cpu[i]; 387 td = uhci->frame_cpu[i];
@@ -387,7 +391,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
387 391
388 if (nframes > 0) { 392 if (nframes > 0) {
389 out += sprintf(out, "- Frame %d -> (%08x)\n", 393 out += sprintf(out, "- Frame %d -> (%08x)\n",
390 i, le32_to_cpu(link)); 394 i, hc32_to_cpu(uhci, link));
391 j = 1; 395 j = 1;
392 } 396 }
393 397
@@ -396,7 +400,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
396 do { 400 do {
397 td = list_entry(tmp, struct uhci_td, fl_list); 401 td = list_entry(tmp, struct uhci_td, fl_list);
398 tmp = tmp->next; 402 tmp = tmp->next;
399 if (link != LINK_TO_TD(td)) { 403 if (link != LINK_TO_TD(uhci, td)) {
400 if (nframes > 0) 404 if (nframes > 0)
401 out += sprintf(out, " link does " 405 out += sprintf(out, " link does "
402 "not match list entry!\n"); 406 "not match list entry!\n");
@@ -404,7 +408,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
404 ++nerrs; 408 ++nerrs;
405 } 409 }
406 if (nframes > 0) 410 if (nframes > 0)
407 out += uhci_show_td(td, out, 411 out += uhci_show_td(uhci, td, out,
408 len - (out - buf), 4); 412 len - (out - buf), 4);
409 link = td->link; 413 link = td->link;
410 } while (tmp != head); 414 } while (tmp != head);
@@ -416,11 +420,12 @@ check_link:
416 if (!j) { 420 if (!j) {
417 out += sprintf(out, 421 out += sprintf(out,
418 "- Frame %d -> (%08x)\n", 422 "- Frame %d -> (%08x)\n",
419 i, le32_to_cpu(link)); 423 i, hc32_to_cpu(uhci, link));
420 j = 1; 424 j = 1;
421 } 425 }
422 out += sprintf(out, " link does not match " 426 out += sprintf(out, " link does not match "
423 "QH (%08x)!\n", le32_to_cpu(qh_dma)); 427 "QH (%08x)!\n",
428 hc32_to_cpu(uhci, qh_dma));
424 } else 429 } else
425 ++nerrs; 430 ++nerrs;
426 } 431 }
@@ -441,11 +446,11 @@ check_link:
441 446
442 /* Last QH is the Terminating QH, it's different */ 447 /* Last QH is the Terminating QH, it's different */
443 if (i == SKEL_TERM) { 448 if (i == SKEL_TERM) {
444 if (qh_element(qh) != LINK_TO_TD(uhci->term_td)) 449 if (qh_element(qh) != LINK_TO_TD(uhci, uhci->term_td))
445 out += sprintf(out, " skel_term_qh element is not set to term_td!\n"); 450 out += sprintf(out, " skel_term_qh element is not set to term_td!\n");
446 link = fsbr_link; 451 link = fsbr_link;
447 if (!link) 452 if (!link)
448 link = LINK_TO_QH(uhci->skel_term_qh); 453 link = LINK_TO_QH(uhci, uhci->skel_term_qh);
449 goto check_qh_link; 454 goto check_qh_link;
450 } 455 }
451 456
@@ -459,20 +464,20 @@ check_link:
459 out += uhci_show_qh(uhci, qh, out, 464 out += uhci_show_qh(uhci, qh, out,
460 len - (out - buf), 4); 465 len - (out - buf), 4);
461 if (!fsbr_link && qh->skel >= SKEL_FSBR) 466 if (!fsbr_link && qh->skel >= SKEL_FSBR)
462 fsbr_link = LINK_TO_QH(qh); 467 fsbr_link = LINK_TO_QH(uhci, qh);
463 } 468 }
464 if ((cnt -= 10) > 0) 469 if ((cnt -= 10) > 0)
465 out += sprintf(out, " Skipped %d QHs\n", cnt); 470 out += sprintf(out, " Skipped %d QHs\n", cnt);
466 471
467 link = UHCI_PTR_TERM; 472 link = UHCI_PTR_TERM(uhci);
468 if (i <= SKEL_ISO) 473 if (i <= SKEL_ISO)
469 ; 474 ;
470 else if (i < SKEL_ASYNC) 475 else if (i < SKEL_ASYNC)
471 link = LINK_TO_QH(uhci->skel_async_qh); 476 link = LINK_TO_QH(uhci, uhci->skel_async_qh);
472 else if (!uhci->fsbr_is_on) 477 else if (!uhci->fsbr_is_on)
473 ; 478 ;
474 else 479 else
475 link = LINK_TO_QH(uhci->skel_term_qh); 480 link = LINK_TO_QH(uhci, uhci->skel_term_qh);
476check_qh_link: 481check_qh_link:
477 if (qh->link != link) 482 if (qh->link != link)
478 out += sprintf(out, " last QH not linked to next skeleton!\n"); 483 out += sprintf(out, " last QH not linked to next skeleton!\n");
diff --git a/drivers/usb/host/uhci-grlib.c b/drivers/usb/host/uhci-grlib.c
new file mode 100644
index 000000000000..d01c1e227681
--- /dev/null
+++ b/drivers/usb/host/uhci-grlib.c
@@ -0,0 +1,208 @@
1/*
2 * UHCI HCD (Host Controller Driver) for GRLIB GRUSBHC
3 *
4 * Copyright (c) 2011 Jan Andersson <jan@gaisler.com>
5 *
6 * This file is based on UHCI PCI HCD:
7 * (C) Copyright 1999 Linus Torvalds
8 * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com
9 * (C) Copyright 1999 Randy Dunlap
10 * (C) Copyright 1999 Georg Acher, acher@in.tum.de
11 * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de
12 * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch
13 * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at
14 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
15 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
16 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
17 * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
18 */
19
20#include <linux/of_irq.h>
21#include <linux/of_address.h>
22#include <linux/of_platform.h>
23
24static int uhci_grlib_init(struct usb_hcd *hcd)
25{
26 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
27
28 /*
29 * Probe to determine the endianness of the controller.
30 * We know that bit 7 of the PORTSC1 register is always set
31 * and bit 15 is always clear. If uhci_readw() yields a value
32 * with bit 7 (0x80) turned on then the current little-endian
33 * setting is correct. Otherwise we assume the value was
34 * byte-swapped; hence the register interface and presumably
35 * also the descriptors are big-endian.
36 */
37 if (!(uhci_readw(uhci, USBPORTSC1) & 0x80)) {
38 uhci->big_endian_mmio = 1;
39 uhci->big_endian_desc = 1;
40 }
41
42 uhci->rh_numports = uhci_count_ports(hcd);
43
44 /* Set up pointers to to generic functions */
45 uhci->reset_hc = uhci_generic_reset_hc;
46 uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc;
47 /* No special actions need to be taken for the functions below */
48 uhci->configure_hc = NULL;
49 uhci->resume_detect_interrupts_are_broken = NULL;
50 uhci->global_suspend_mode_is_broken = NULL;
51
52 /* Reset if the controller isn't already safely quiescent. */
53 check_and_reset_hc(uhci);
54 return 0;
55}
56
57static const struct hc_driver uhci_grlib_hc_driver = {
58 .description = hcd_name,
59 .product_desc = "GRLIB GRUSBHC UHCI Host Controller",
60 .hcd_priv_size = sizeof(struct uhci_hcd),
61
62 /* Generic hardware linkage */
63 .irq = uhci_irq,
64 .flags = HCD_MEMORY | HCD_USB11,
65
66 /* Basic lifecycle operations */
67 .reset = uhci_grlib_init,
68 .start = uhci_start,
69#ifdef CONFIG_PM
70 .pci_suspend = NULL,
71 .pci_resume = NULL,
72 .bus_suspend = uhci_rh_suspend,
73 .bus_resume = uhci_rh_resume,
74#endif
75 .stop = uhci_stop,
76
77 .urb_enqueue = uhci_urb_enqueue,
78 .urb_dequeue = uhci_urb_dequeue,
79
80 .endpoint_disable = uhci_hcd_endpoint_disable,
81 .get_frame_number = uhci_hcd_get_frame_number,
82
83 .hub_status_data = uhci_hub_status_data,
84 .hub_control = uhci_hub_control,
85};
86
87
88static int __devinit uhci_hcd_grlib_probe(struct platform_device *op)
89{
90 struct device_node *dn = op->dev.of_node;
91 struct usb_hcd *hcd;
92 struct uhci_hcd *uhci = NULL;
93 struct resource res;
94 int irq;
95 int rv;
96
97 if (usb_disabled())
98 return -ENODEV;
99
100 dev_dbg(&op->dev, "initializing GRUSBHC UHCI USB Controller\n");
101
102 rv = of_address_to_resource(dn, 0, &res);
103 if (rv)
104 return rv;
105
106 /* usb_create_hcd requires dma_mask != NULL */
107 op->dev.dma_mask = &op->dev.coherent_dma_mask;
108 hcd = usb_create_hcd(&uhci_grlib_hc_driver, &op->dev,
109 "GRUSBHC UHCI USB");
110 if (!hcd)
111 return -ENOMEM;
112
113 hcd->rsrc_start = res.start;
114 hcd->rsrc_len = res.end - res.start + 1;
115
116 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
117 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
118 rv = -EBUSY;
119 goto err_rmr;
120 }
121
122 irq = irq_of_parse_and_map(dn, 0);
123 if (irq == NO_IRQ) {
124 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
125 rv = -EBUSY;
126 goto err_irq;
127 }
128
129 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
130 if (!hcd->regs) {
131 printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
132 rv = -ENOMEM;
133 goto err_ioremap;
134 }
135
136 uhci = hcd_to_uhci(hcd);
137
138 uhci->regs = hcd->regs;
139
140 rv = usb_add_hcd(hcd, irq, 0);
141 if (rv)
142 goto err_uhci;
143
144 return 0;
145
146err_uhci:
147 iounmap(hcd->regs);
148err_ioremap:
149 irq_dispose_mapping(irq);
150err_irq:
151 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
152err_rmr:
153 usb_put_hcd(hcd);
154
155 return rv;
156}
157
158static int uhci_hcd_grlib_remove(struct platform_device *op)
159{
160 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
161
162 dev_set_drvdata(&op->dev, NULL);
163
164 dev_dbg(&op->dev, "stopping GRLIB GRUSBHC UHCI USB Controller\n");
165
166 usb_remove_hcd(hcd);
167
168 iounmap(hcd->regs);
169 irq_dispose_mapping(hcd->irq);
170 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
171
172 usb_put_hcd(hcd);
173
174 return 0;
175}
176
177/* Make sure the controller is quiescent and that we're not using it
178 * any more. This is mainly for the benefit of programs which, like kexec,
179 * expect the hardware to be idle: not doing DMA or generating IRQs.
180 *
181 * This routine may be called in a damaged or failing kernel. Hence we
182 * do not acquire the spinlock before shutting down the controller.
183 */
184static void uhci_hcd_grlib_shutdown(struct platform_device *op)
185{
186 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
187
188 uhci_hc_died(hcd_to_uhci(hcd));
189}
190
191static const struct of_device_id uhci_hcd_grlib_of_match[] = {
192 { .name = "GAISLER_UHCI", },
193 { .name = "01_027", },
194 {},
195};
196MODULE_DEVICE_TABLE(of, uhci_hcd_grlib_of_match);
197
198
199static struct platform_driver uhci_grlib_driver = {
200 .probe = uhci_hcd_grlib_probe,
201 .remove = uhci_hcd_grlib_remove,
202 .shutdown = uhci_hcd_grlib_shutdown,
203 .driver = {
204 .name = "grlib-uhci",
205 .owner = THIS_MODULE,
206 .of_match_table = uhci_hcd_grlib_of_match,
207 },
208};
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index f52d04db28f4..fba99b120588 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -48,14 +48,14 @@
48#include <asm/system.h> 48#include <asm/system.h>
49 49
50#include "uhci-hcd.h" 50#include "uhci-hcd.h"
51#include "pci-quirks.h"
52 51
53/* 52/*
54 * Version Information 53 * Version Information
55 */ 54 */
56#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, \ 55#define DRIVER_AUTHOR \
57Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \ 56 "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, " \
58Alan Stern" 57 "Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, " \
58 "Roman Weissgaerber, Alan Stern"
59#define DRIVER_DESC "USB Universal Host Controller Interface driver" 59#define DRIVER_DESC "USB Universal Host Controller Interface driver"
60 60
61/* for flakey hardware, ignore overcurrent indicators */ 61/* for flakey hardware, ignore overcurrent indicators */
@@ -93,7 +93,7 @@ static void uhci_get_current_frame_number(struct uhci_hcd *uhci);
93/* 93/*
94 * Calculate the link pointer DMA value for the first Skeleton QH in a frame. 94 * Calculate the link pointer DMA value for the first Skeleton QH in a frame.
95 */ 95 */
96static __le32 uhci_frame_skel_link(struct uhci_hcd *uhci, int frame) 96static __hc32 uhci_frame_skel_link(struct uhci_hcd *uhci, int frame)
97{ 97{
98 int skelnum; 98 int skelnum;
99 99
@@ -115,7 +115,7 @@ static __le32 uhci_frame_skel_link(struct uhci_hcd *uhci, int frame)
115 skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES); 115 skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES);
116 if (skelnum <= 1) 116 if (skelnum <= 1)
117 skelnum = 9; 117 skelnum = 9;
118 return LINK_TO_QH(uhci->skelqh[skelnum]); 118 return LINK_TO_QH(uhci, uhci->skelqh[skelnum]);
119} 119}
120 120
121#include "uhci-debug.c" 121#include "uhci-debug.c"
@@ -134,15 +134,12 @@ static void finish_reset(struct uhci_hcd *uhci)
134 * We have to clear them by hand. 134 * We have to clear them by hand.
135 */ 135 */
136 for (port = 0; port < uhci->rh_numports; ++port) 136 for (port = 0; port < uhci->rh_numports; ++port)
137 outw(0, uhci->io_addr + USBPORTSC1 + (port * 2)); 137 uhci_writew(uhci, 0, USBPORTSC1 + (port * 2));
138 138
139 uhci->port_c_suspend = uhci->resuming_ports = 0; 139 uhci->port_c_suspend = uhci->resuming_ports = 0;
140 uhci->rh_state = UHCI_RH_RESET; 140 uhci->rh_state = UHCI_RH_RESET;
141 uhci->is_stopped = UHCI_IS_STOPPED; 141 uhci->is_stopped = UHCI_IS_STOPPED;
142 uhci_to_hcd(uhci)->state = HC_STATE_HALT;
143 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); 142 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
144
145 uhci->dead = 0; /* Full reset resurrects the controller */
146} 143}
147 144
148/* 145/*
@@ -152,7 +149,7 @@ static void finish_reset(struct uhci_hcd *uhci)
152static void uhci_hc_died(struct uhci_hcd *uhci) 149static void uhci_hc_died(struct uhci_hcd *uhci)
153{ 150{
154 uhci_get_current_frame_number(uhci); 151 uhci_get_current_frame_number(uhci);
155 uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr); 152 uhci->reset_hc(uhci);
156 finish_reset(uhci); 153 finish_reset(uhci);
157 uhci->dead = 1; 154 uhci->dead = 1;
158 155
@@ -167,97 +164,118 @@ static void uhci_hc_died(struct uhci_hcd *uhci)
167 */ 164 */
168static void check_and_reset_hc(struct uhci_hcd *uhci) 165static void check_and_reset_hc(struct uhci_hcd *uhci)
169{ 166{
170 if (uhci_check_and_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr)) 167 if (uhci->check_and_reset_hc(uhci))
171 finish_reset(uhci); 168 finish_reset(uhci);
172} 169}
173 170
171#if defined(CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC)
172/*
173 * The two functions below are generic reset functions that are used on systems
174 * that do not have keyboard and mouse legacy support. We assume that we are
175 * running on such a system if CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC is defined.
176 */
177
178/*
179 * Make sure the controller is completely inactive, unable to
180 * generate interrupts or do DMA.
181 */
182static void uhci_generic_reset_hc(struct uhci_hcd *uhci)
183{
184 /* Reset the HC - this will force us to get a
185 * new notification of any already connected
186 * ports due to the virtual disconnect that it
187 * implies.
188 */
189 uhci_writew(uhci, USBCMD_HCRESET, USBCMD);
190 mb();
191 udelay(5);
192 if (uhci_readw(uhci, USBCMD) & USBCMD_HCRESET)
193 dev_warn(uhci_dev(uhci), "HCRESET not completed yet!\n");
194
195 /* Just to be safe, disable interrupt requests and
196 * make sure the controller is stopped.
197 */
198 uhci_writew(uhci, 0, USBINTR);
199 uhci_writew(uhci, 0, USBCMD);
200}
201
202/*
203 * Initialize a controller that was newly discovered or has just been
204 * resumed. In either case we can't be sure of its previous state.
205 *
206 * Returns: 1 if the controller was reset, 0 otherwise.
207 */
208static int uhci_generic_check_and_reset_hc(struct uhci_hcd *uhci)
209{
210 unsigned int cmd, intr;
211
212 /*
213 * When restarting a suspended controller, we expect all the
214 * settings to be the same as we left them:
215 *
216 * Controller is stopped and configured with EGSM set;
217 * No interrupts enabled except possibly Resume Detect.
218 *
219 * If any of these conditions are violated we do a complete reset.
220 */
221
222 cmd = uhci_readw(uhci, USBCMD);
223 if ((cmd & USBCMD_RS) || !(cmd & USBCMD_CF) || !(cmd & USBCMD_EGSM)) {
224 dev_dbg(uhci_dev(uhci), "%s: cmd = 0x%04x\n",
225 __func__, cmd);
226 goto reset_needed;
227 }
228
229 intr = uhci_readw(uhci, USBINTR);
230 if (intr & (~USBINTR_RESUME)) {
231 dev_dbg(uhci_dev(uhci), "%s: intr = 0x%04x\n",
232 __func__, intr);
233 goto reset_needed;
234 }
235 return 0;
236
237reset_needed:
238 dev_dbg(uhci_dev(uhci), "Performing full reset\n");
239 uhci_generic_reset_hc(uhci);
240 return 1;
241}
242#endif /* CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC */
243
174/* 244/*
175 * Store the basic register settings needed by the controller. 245 * Store the basic register settings needed by the controller.
176 */ 246 */
177static void configure_hc(struct uhci_hcd *uhci) 247static void configure_hc(struct uhci_hcd *uhci)
178{ 248{
179 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
180
181 /* Set the frame length to the default: 1 ms exactly */ 249 /* Set the frame length to the default: 1 ms exactly */
182 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF); 250 uhci_writeb(uhci, USBSOF_DEFAULT, USBSOF);
183 251
184 /* Store the frame list base address */ 252 /* Store the frame list base address */
185 outl(uhci->frame_dma_handle, uhci->io_addr + USBFLBASEADD); 253 uhci_writel(uhci, uhci->frame_dma_handle, USBFLBASEADD);
186 254
187 /* Set the current frame number */ 255 /* Set the current frame number */
188 outw(uhci->frame_number & UHCI_MAX_SOF_NUMBER, 256 uhci_writew(uhci, uhci->frame_number & UHCI_MAX_SOF_NUMBER,
189 uhci->io_addr + USBFRNUM); 257 USBFRNUM);
190
191 /* Mark controller as not halted before we enable interrupts */
192 uhci_to_hcd(uhci)->state = HC_STATE_SUSPENDED;
193 mb();
194
195 /* Enable PIRQ */
196 pci_write_config_word(pdev, USBLEGSUP, USBLEGSUP_DEFAULT);
197 258
198 /* Disable platform-specific non-PME# wakeup */ 259 /* perform any arch/bus specific configuration */
199 if (pdev->vendor == PCI_VENDOR_ID_INTEL) 260 if (uhci->configure_hc)
200 pci_write_config_byte(pdev, USBRES_INTEL, 0); 261 uhci->configure_hc(uhci);
201} 262}
202 263
203
204static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci) 264static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
205{ 265{
206 int port;
207
208 /* If we have to ignore overcurrent events then almost by definition 266 /* If we have to ignore overcurrent events then almost by definition
209 * we can't depend on resume-detect interrupts. */ 267 * we can't depend on resume-detect interrupts. */
210 if (ignore_oc) 268 if (ignore_oc)
211 return 1; 269 return 1;
212 270
213 switch (to_pci_dev(uhci_dev(uhci))->vendor) { 271 return uhci->resume_detect_interrupts_are_broken ?
214 default: 272 uhci->resume_detect_interrupts_are_broken(uhci) : 0;
215 break;
216
217 case PCI_VENDOR_ID_GENESYS:
218 /* Genesys Logic's GL880S controllers don't generate
219 * resume-detect interrupts.
220 */
221 return 1;
222
223 case PCI_VENDOR_ID_INTEL:
224 /* Some of Intel's USB controllers have a bug that causes
225 * resume-detect interrupts if any port has an over-current
226 * condition. To make matters worse, some motherboards
227 * hardwire unused USB ports' over-current inputs active!
228 * To prevent problems, we will not enable resume-detect
229 * interrupts if any ports are OC.
230 */
231 for (port = 0; port < uhci->rh_numports; ++port) {
232 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
233 USBPORTSC_OC)
234 return 1;
235 }
236 break;
237 }
238 return 0;
239} 273}
240 274
241static int global_suspend_mode_is_broken(struct uhci_hcd *uhci) 275static int global_suspend_mode_is_broken(struct uhci_hcd *uhci)
242{ 276{
243 int port; 277 return uhci->global_suspend_mode_is_broken ?
244 const char *sys_info; 278 uhci->global_suspend_mode_is_broken(uhci) : 0;
245 static char bad_Asus_board[] = "A7V8X";
246
247 /* One of Asus's motherboards has a bug which causes it to
248 * wake up immediately from suspend-to-RAM if any of the ports
249 * are connected. In such cases we will not set EGSM.
250 */
251 sys_info = dmi_get_system_info(DMI_BOARD_NAME);
252 if (sys_info && !strcmp(sys_info, bad_Asus_board)) {
253 for (port = 0; port < uhci->rh_numports; ++port) {
254 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
255 USBPORTSC_CCS)
256 return 1;
257 }
258 }
259
260 return 0;
261} 279}
262 280
263static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state) 281static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
@@ -320,8 +338,8 @@ __acquires(uhci->lock)
320 !int_enable) 338 !int_enable)
321 uhci->RD_enable = int_enable = 0; 339 uhci->RD_enable = int_enable = 0;
322 340
323 outw(int_enable, uhci->io_addr + USBINTR); 341 uhci_writew(uhci, int_enable, USBINTR);
324 outw(egsm_enable | USBCMD_CF, uhci->io_addr + USBCMD); 342 uhci_writew(uhci, egsm_enable | USBCMD_CF, USBCMD);
325 mb(); 343 mb();
326 udelay(5); 344 udelay(5);
327 345
@@ -330,7 +348,7 @@ __acquires(uhci->lock)
330 * controller should stop after a few microseconds. Otherwise 348 * controller should stop after a few microseconds. Otherwise
331 * we will give the controller one frame to stop. 349 * we will give the controller one frame to stop.
332 */ 350 */
333 if (!auto_stop && !(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) { 351 if (!auto_stop && !(uhci_readw(uhci, USBSTS) & USBSTS_HCH)) {
334 uhci->rh_state = UHCI_RH_SUSPENDING; 352 uhci->rh_state = UHCI_RH_SUSPENDING;
335 spin_unlock_irq(&uhci->lock); 353 spin_unlock_irq(&uhci->lock);
336 msleep(1); 354 msleep(1);
@@ -338,7 +356,7 @@ __acquires(uhci->lock)
338 if (uhci->dead) 356 if (uhci->dead)
339 return; 357 return;
340 } 358 }
341 if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) 359 if (!(uhci_readw(uhci, USBSTS) & USBSTS_HCH))
342 dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n"); 360 dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n");
343 361
344 uhci_get_current_frame_number(uhci); 362 uhci_get_current_frame_number(uhci);
@@ -360,15 +378,14 @@ __acquires(uhci->lock)
360 378
361static void start_rh(struct uhci_hcd *uhci) 379static void start_rh(struct uhci_hcd *uhci)
362{ 380{
363 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING;
364 uhci->is_stopped = 0; 381 uhci->is_stopped = 0;
365 382
366 /* Mark it configured and running with a 64-byte max packet. 383 /* Mark it configured and running with a 64-byte max packet.
367 * All interrupts are enabled, even though RESUME won't do anything. 384 * All interrupts are enabled, even though RESUME won't do anything.
368 */ 385 */
369 outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, uhci->io_addr + USBCMD); 386 uhci_writew(uhci, USBCMD_RS | USBCMD_CF | USBCMD_MAXP, USBCMD);
370 outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP, 387 uhci_writew(uhci, USBINTR_TIMEOUT | USBINTR_RESUME |
371 uhci->io_addr + USBINTR); 388 USBINTR_IOC | USBINTR_SP, USBINTR);
372 mb(); 389 mb();
373 uhci->rh_state = UHCI_RH_RUNNING; 390 uhci->rh_state = UHCI_RH_RUNNING;
374 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); 391 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
@@ -391,9 +408,9 @@ __acquires(uhci->lock)
391 unsigned egsm; 408 unsigned egsm;
392 409
393 /* Keep EGSM on if it was set before */ 410 /* Keep EGSM on if it was set before */
394 egsm = inw(uhci->io_addr + USBCMD) & USBCMD_EGSM; 411 egsm = uhci_readw(uhci, USBCMD) & USBCMD_EGSM;
395 uhci->rh_state = UHCI_RH_RESUMING; 412 uhci->rh_state = UHCI_RH_RESUMING;
396 outw(USBCMD_FGR | USBCMD_CF | egsm, uhci->io_addr + USBCMD); 413 uhci_writew(uhci, USBCMD_FGR | USBCMD_CF | egsm, USBCMD);
397 spin_unlock_irq(&uhci->lock); 414 spin_unlock_irq(&uhci->lock);
398 msleep(20); 415 msleep(20);
399 spin_lock_irq(&uhci->lock); 416 spin_lock_irq(&uhci->lock);
@@ -401,10 +418,10 @@ __acquires(uhci->lock)
401 return; 418 return;
402 419
403 /* End Global Resume and wait for EOP to be sent */ 420 /* End Global Resume and wait for EOP to be sent */
404 outw(USBCMD_CF, uhci->io_addr + USBCMD); 421 uhci_writew(uhci, USBCMD_CF, USBCMD);
405 mb(); 422 mb();
406 udelay(4); 423 udelay(4);
407 if (inw(uhci->io_addr + USBCMD) & USBCMD_FGR) 424 if (uhci_readw(uhci, USBCMD) & USBCMD_FGR)
408 dev_warn(uhci_dev(uhci), "FGR not stopped yet!\n"); 425 dev_warn(uhci_dev(uhci), "FGR not stopped yet!\n");
409 } 426 }
410 427
@@ -424,10 +441,10 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd)
424 * interrupt cause. Contrary to the UHCI specification, the 441 * interrupt cause. Contrary to the UHCI specification, the
425 * "HC Halted" status bit is persistent: it is RO, not R/WC. 442 * "HC Halted" status bit is persistent: it is RO, not R/WC.
426 */ 443 */
427 status = inw(uhci->io_addr + USBSTS); 444 status = uhci_readw(uhci, USBSTS);
428 if (!(status & ~USBSTS_HCH)) /* shared interrupt, not mine */ 445 if (!(status & ~USBSTS_HCH)) /* shared interrupt, not mine */
429 return IRQ_NONE; 446 return IRQ_NONE;
430 outw(status, uhci->io_addr + USBSTS); /* Clear it */ 447 uhci_writew(uhci, status, USBSTS); /* Clear it */
431 448
432 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) { 449 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) {
433 if (status & USBSTS_HSE) 450 if (status & USBSTS_HSE)
@@ -449,6 +466,7 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd)
449 lprintk(errbuf); 466 lprintk(errbuf);
450 } 467 }
451 uhci_hc_died(uhci); 468 uhci_hc_died(uhci);
469 usb_hc_died(hcd);
452 470
453 /* Force a callback in case there are 471 /* Force a callback in case there are
454 * pending unlinks */ 472 * pending unlinks */
@@ -471,7 +489,7 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd)
471 489
472/* 490/*
473 * Store the current frame number in uhci->frame_number if the controller 491 * Store the current frame number in uhci->frame_number if the controller
474 * is runnning. Expand from 11 bits (of which we use only 10) to a 492 * is running. Expand from 11 bits (of which we use only 10) to a
475 * full-sized integer. 493 * full-sized integer.
476 * 494 *
477 * Like many other parts of the driver, this code relies on being polled 495 * Like many other parts of the driver, this code relies on being polled
@@ -482,7 +500,7 @@ static void uhci_get_current_frame_number(struct uhci_hcd *uhci)
482 if (!uhci->is_stopped) { 500 if (!uhci->is_stopped) {
483 unsigned delta; 501 unsigned delta;
484 502
485 delta = (inw(uhci->io_addr + USBFRNUM) - uhci->frame_number) & 503 delta = (uhci_readw(uhci, USBFRNUM) - uhci->frame_number) &
486 (UHCI_NUMFRAMES - 1); 504 (UHCI_NUMFRAMES - 1);
487 uhci->frame_number += delta; 505 uhci->frame_number += delta;
488 } 506 }
@@ -519,61 +537,6 @@ static void release_uhci(struct uhci_hcd *uhci)
519 uhci->frame, uhci->frame_dma_handle); 537 uhci->frame, uhci->frame_dma_handle);
520} 538}
521 539
522static int uhci_init(struct usb_hcd *hcd)
523{
524 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
525 unsigned io_size = (unsigned) hcd->rsrc_len;
526 int port;
527
528 uhci->io_addr = (unsigned long) hcd->rsrc_start;
529
530 /* The UHCI spec says devices must have 2 ports, and goes on to say
531 * they may have more but gives no way to determine how many there
532 * are. However according to the UHCI spec, Bit 7 of the port
533 * status and control register is always set to 1. So we try to
534 * use this to our advantage. Another common failure mode when
535 * a nonexistent register is addressed is to return all ones, so
536 * we test for that also.
537 */
538 for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) {
539 unsigned int portstatus;
540
541 portstatus = inw(uhci->io_addr + USBPORTSC1 + (port * 2));
542 if (!(portstatus & 0x0080) || portstatus == 0xffff)
543 break;
544 }
545 if (debug)
546 dev_info(uhci_dev(uhci), "detected %d ports\n", port);
547
548 /* Anything greater than 7 is weird so we'll ignore it. */
549 if (port > UHCI_RH_MAXCHILD) {
550 dev_info(uhci_dev(uhci), "port count misdetected? "
551 "forcing to 2 ports\n");
552 port = 2;
553 }
554 uhci->rh_numports = port;
555
556 /* Kick BIOS off this hardware and reset if the controller
557 * isn't already safely quiescent.
558 */
559 check_and_reset_hc(uhci);
560 return 0;
561}
562
563/* Make sure the controller is quiescent and that we're not using it
564 * any more. This is mainly for the benefit of programs which, like kexec,
565 * expect the hardware to be idle: not doing DMA or generating IRQs.
566 *
567 * This routine may be called in a damaged or failing kernel. Hence we
568 * do not acquire the spinlock before shutting down the controller.
569 */
570static void uhci_shutdown(struct pci_dev *pdev)
571{
572 struct usb_hcd *hcd = (struct usb_hcd *) pci_get_drvdata(pdev);
573
574 uhci_hc_died(hcd_to_uhci(hcd));
575}
576
577/* 540/*
578 * Allocate a frame list, and then setup the skeleton 541 * Allocate a frame list, and then setup the skeleton
579 * 542 *
@@ -668,16 +631,16 @@ static int uhci_start(struct usb_hcd *hcd)
668 * 8 Interrupt queues; link all higher int queues to int1 = async 631 * 8 Interrupt queues; link all higher int queues to int1 = async
669 */ 632 */
670 for (i = SKEL_ISO + 1; i < SKEL_ASYNC; ++i) 633 for (i = SKEL_ISO + 1; i < SKEL_ASYNC; ++i)
671 uhci->skelqh[i]->link = LINK_TO_QH(uhci->skel_async_qh); 634 uhci->skelqh[i]->link = LINK_TO_QH(uhci, uhci->skel_async_qh);
672 uhci->skel_async_qh->link = UHCI_PTR_TERM; 635 uhci->skel_async_qh->link = UHCI_PTR_TERM(uhci);
673 uhci->skel_term_qh->link = LINK_TO_QH(uhci->skel_term_qh); 636 uhci->skel_term_qh->link = LINK_TO_QH(uhci, uhci->skel_term_qh);
674 637
675 /* This dummy TD is to work around a bug in Intel PIIX controllers */ 638 /* This dummy TD is to work around a bug in Intel PIIX controllers */
676 uhci_fill_td(uhci->term_td, 0, uhci_explen(0) | 639 uhci_fill_td(uhci, uhci->term_td, 0, uhci_explen(0) |
677 (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0); 640 (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0);
678 uhci->term_td->link = UHCI_PTR_TERM; 641 uhci->term_td->link = UHCI_PTR_TERM(uhci);
679 uhci->skel_async_qh->element = uhci->skel_term_qh->element = 642 uhci->skel_async_qh->element = uhci->skel_term_qh->element =
680 LINK_TO_TD(uhci->term_td); 643 LINK_TO_TD(uhci, uhci->term_td);
681 644
682 /* 645 /*
683 * Fill the frame list: make all entries point to the proper 646 * Fill the frame list: make all entries point to the proper
@@ -790,86 +753,6 @@ static int uhci_rh_resume(struct usb_hcd *hcd)
790 return rc; 753 return rc;
791} 754}
792 755
793static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
794{
795 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
796 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
797 int rc = 0;
798
799 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
800
801 spin_lock_irq(&uhci->lock);
802 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
803 goto done_okay; /* Already suspended or dead */
804
805 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
806 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
807 rc = -EBUSY;
808 goto done;
809 };
810
811 /* All PCI host controllers are required to disable IRQ generation
812 * at the source, so we must turn off PIRQ.
813 */
814 pci_write_config_word(pdev, USBLEGSUP, 0);
815 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
816
817 /* Enable platform-specific non-PME# wakeup */
818 if (do_wakeup) {
819 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
820 pci_write_config_byte(pdev, USBRES_INTEL,
821 USBPORT1EN | USBPORT2EN);
822 }
823
824done_okay:
825 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
826done:
827 spin_unlock_irq(&uhci->lock);
828 return rc;
829}
830
831static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
832{
833 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
834
835 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
836
837 /* Since we aren't in D3 any more, it's safe to set this flag
838 * even if the controller was dead.
839 */
840 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
841
842 spin_lock_irq(&uhci->lock);
843
844 /* Make sure resume from hibernation re-enumerates everything */
845 if (hibernated)
846 uhci_hc_died(uhci);
847
848 /* The firmware or a boot kernel may have changed the controller
849 * settings during a system wakeup. Check it and reconfigure
850 * to avoid problems.
851 */
852 check_and_reset_hc(uhci);
853
854 /* If the controller was dead before, it's back alive now */
855 configure_hc(uhci);
856
857 /* Tell the core if the controller had to be reset */
858 if (uhci->rh_state == UHCI_RH_RESET)
859 usb_root_hub_lost_power(hcd->self.root_hub);
860
861 spin_unlock_irq(&uhci->lock);
862
863 /* If interrupts don't work and remote wakeup is enabled then
864 * the suspended root hub needs to be polled.
865 */
866 if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup)
867 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
868
869 /* Does the root hub have a port wakeup pending? */
870 usb_hcd_poll_rh_status(hcd);
871 return 0;
872}
873#endif 756#endif
874 757
875/* Wait until a particular device/endpoint's QH is idle, and free it */ 758/* Wait until a particular device/endpoint's QH is idle, and free it */
@@ -907,67 +790,62 @@ static int uhci_hcd_get_frame_number(struct usb_hcd *hcd)
907 /* Minimize latency by avoiding the spinlock */ 790 /* Minimize latency by avoiding the spinlock */
908 frame_number = uhci->frame_number; 791 frame_number = uhci->frame_number;
909 barrier(); 792 barrier();
910 delta = (inw(uhci->io_addr + USBFRNUM) - frame_number) & 793 delta = (uhci_readw(uhci, USBFRNUM) - frame_number) &
911 (UHCI_NUMFRAMES - 1); 794 (UHCI_NUMFRAMES - 1);
912 return frame_number + delta; 795 return frame_number + delta;
913} 796}
914 797
915static const char hcd_name[] = "uhci_hcd"; 798/* Determines number of ports on controller */
916 799static int uhci_count_ports(struct usb_hcd *hcd)
917static const struct hc_driver uhci_driver = { 800{
918 .description = hcd_name, 801 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
919 .product_desc = "UHCI Host Controller", 802 unsigned io_size = (unsigned) hcd->rsrc_len;
920 .hcd_priv_size = sizeof(struct uhci_hcd), 803 int port;
921
922 /* Generic hardware linkage */
923 .irq = uhci_irq,
924 .flags = HCD_USB11,
925
926 /* Basic lifecycle operations */
927 .reset = uhci_init,
928 .start = uhci_start,
929#ifdef CONFIG_PM
930 .pci_suspend = uhci_pci_suspend,
931 .pci_resume = uhci_pci_resume,
932 .bus_suspend = uhci_rh_suspend,
933 .bus_resume = uhci_rh_resume,
934#endif
935 .stop = uhci_stop,
936 804
937 .urb_enqueue = uhci_urb_enqueue, 805 /* The UHCI spec says devices must have 2 ports, and goes on to say
938 .urb_dequeue = uhci_urb_dequeue, 806 * they may have more but gives no way to determine how many there
807 * are. However according to the UHCI spec, Bit 7 of the port
808 * status and control register is always set to 1. So we try to
809 * use this to our advantage. Another common failure mode when
810 * a nonexistent register is addressed is to return all ones, so
811 * we test for that also.
812 */
813 for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) {
814 unsigned int portstatus;
939 815
940 .endpoint_disable = uhci_hcd_endpoint_disable, 816 portstatus = uhci_readw(uhci, USBPORTSC1 + (port * 2));
941 .get_frame_number = uhci_hcd_get_frame_number, 817 if (!(portstatus & 0x0080) || portstatus == 0xffff)
818 break;
819 }
820 if (debug)
821 dev_info(uhci_dev(uhci), "detected %d ports\n", port);
942 822
943 .hub_status_data = uhci_hub_status_data, 823 /* Anything greater than 7 is weird so we'll ignore it. */
944 .hub_control = uhci_hub_control, 824 if (port > UHCI_RH_MAXCHILD) {
945}; 825 dev_info(uhci_dev(uhci), "port count misdetected? "
826 "forcing to 2 ports\n");
827 port = 2;
828 }
946 829
947static const struct pci_device_id uhci_pci_ids[] = { { 830 return port;
948 /* handle any USB UHCI controller */ 831}
949 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
950 .driver_data = (unsigned long) &uhci_driver,
951 }, { /* end: all zeroes */ }
952};
953 832
954MODULE_DEVICE_TABLE(pci, uhci_pci_ids); 833static const char hcd_name[] = "uhci_hcd";
955 834
956static struct pci_driver uhci_pci_driver = { 835#ifdef CONFIG_PCI
957 .name = (char *)hcd_name, 836#include "uhci-pci.c"
958 .id_table = uhci_pci_ids, 837#define PCI_DRIVER uhci_pci_driver
838#endif
959 839
960 .probe = usb_hcd_pci_probe, 840#ifdef CONFIG_SPARC_LEON
961 .remove = usb_hcd_pci_remove, 841#include "uhci-grlib.c"
962 .shutdown = uhci_shutdown, 842#define PLATFORM_DRIVER uhci_grlib_driver
843#endif
963 844
964#ifdef CONFIG_PM_SLEEP 845#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER)
965 .driver = { 846#error "missing bus glue for uhci-hcd"
966 .pm = &usb_hcd_pci_pm_ops
967 },
968#endif 847#endif
969}; 848
970
971static int __init uhci_hcd_init(void) 849static int __init uhci_hcd_init(void)
972{ 850{
973 int retval = -ENOMEM; 851 int retval = -ENOMEM;
@@ -993,13 +871,27 @@ static int __init uhci_hcd_init(void)
993 if (!uhci_up_cachep) 871 if (!uhci_up_cachep)
994 goto up_failed; 872 goto up_failed;
995 873
996 retval = pci_register_driver(&uhci_pci_driver); 874#ifdef PLATFORM_DRIVER
997 if (retval) 875 retval = platform_driver_register(&PLATFORM_DRIVER);
998 goto init_failed; 876 if (retval < 0)
877 goto clean0;
878#endif
879
880#ifdef PCI_DRIVER
881 retval = pci_register_driver(&PCI_DRIVER);
882 if (retval < 0)
883 goto clean1;
884#endif
999 885
1000 return 0; 886 return 0;
1001 887
1002init_failed: 888#ifdef PCI_DRIVER
889clean1:
890#endif
891#ifdef PLATFORM_DRIVER
892 platform_driver_unregister(&PLATFORM_DRIVER);
893clean0:
894#endif
1003 kmem_cache_destroy(uhci_up_cachep); 895 kmem_cache_destroy(uhci_up_cachep);
1004 896
1005up_failed: 897up_failed:
@@ -1016,7 +908,12 @@ errbuf_failed:
1016 908
1017static void __exit uhci_hcd_cleanup(void) 909static void __exit uhci_hcd_cleanup(void)
1018{ 910{
1019 pci_unregister_driver(&uhci_pci_driver); 911#ifdef PLATFORM_DRIVER
912 platform_driver_unregister(&PLATFORM_DRIVER);
913#endif
914#ifdef PCI_DRIVER
915 pci_unregister_driver(&PCI_DRIVER);
916#endif
1020 kmem_cache_destroy(uhci_up_cachep); 917 kmem_cache_destroy(uhci_up_cachep);
1021 debugfs_remove(uhci_debugfs_root); 918 debugfs_remove(uhci_debugfs_root);
1022 kfree(errbuf); 919 kfree(errbuf);
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 49bf2790f9c2..7af2b7052047 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -78,11 +78,11 @@
78#define USBPORT1EN 0x01 78#define USBPORT1EN 0x01
79#define USBPORT2EN 0x02 79#define USBPORT2EN 0x02
80 80
81#define UHCI_PTR_BITS cpu_to_le32(0x000F) 81#define UHCI_PTR_BITS(uhci) cpu_to_hc32((uhci), 0x000F)
82#define UHCI_PTR_TERM cpu_to_le32(0x0001) 82#define UHCI_PTR_TERM(uhci) cpu_to_hc32((uhci), 0x0001)
83#define UHCI_PTR_QH cpu_to_le32(0x0002) 83#define UHCI_PTR_QH(uhci) cpu_to_hc32((uhci), 0x0002)
84#define UHCI_PTR_DEPTH cpu_to_le32(0x0004) 84#define UHCI_PTR_DEPTH(uhci) cpu_to_hc32((uhci), 0x0004)
85#define UHCI_PTR_BREADTH cpu_to_le32(0x0000) 85#define UHCI_PTR_BREADTH(uhci) cpu_to_hc32((uhci), 0x0000)
86 86
87#define UHCI_NUMFRAMES 1024 /* in the frame list [array] */ 87#define UHCI_NUMFRAMES 1024 /* in the frame list [array] */
88#define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */ 88#define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */
@@ -99,6 +99,22 @@
99 99
100 100
101/* 101/*
102 * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to
103 * __leXX (normally) or __beXX (given UHCI_BIG_ENDIAN_DESC), depending on
104 * the host controller implementation.
105 *
106 * To facilitate the strongest possible byte-order checking from "sparse"
107 * and so on, we use __leXX unless that's not practical.
108 */
109#ifdef CONFIG_USB_UHCI_BIG_ENDIAN_DESC
110typedef __u32 __bitwise __hc32;
111typedef __u16 __bitwise __hc16;
112#else
113#define __hc32 __le32
114#define __hc16 __le16
115#endif
116
117/*
102 * Queue Headers 118 * Queue Headers
103 */ 119 */
104 120
@@ -130,8 +146,8 @@
130 146
131struct uhci_qh { 147struct uhci_qh {
132 /* Hardware fields */ 148 /* Hardware fields */
133 __le32 link; /* Next QH in the schedule */ 149 __hc32 link; /* Next QH in the schedule */
134 __le32 element; /* Queue element (TD) pointer */ 150 __hc32 element; /* Queue element (TD) pointer */
135 151
136 /* Software fields */ 152 /* Software fields */
137 dma_addr_t dma_handle; 153 dma_addr_t dma_handle;
@@ -168,14 +184,10 @@ struct uhci_qh {
168 * We need a special accessor for the element pointer because it is 184 * We need a special accessor for the element pointer because it is
169 * subject to asynchronous updates by the controller. 185 * subject to asynchronous updates by the controller.
170 */ 186 */
171static inline __le32 qh_element(struct uhci_qh *qh) { 187#define qh_element(qh) ACCESS_ONCE((qh)->element)
172 __le32 element = qh->element;
173 188
174 barrier(); 189#define LINK_TO_QH(uhci, qh) (UHCI_PTR_QH((uhci)) | \
175 return element; 190 cpu_to_hc32((uhci), (qh)->dma_handle))
176}
177
178#define LINK_TO_QH(qh) (UHCI_PTR_QH | cpu_to_le32((qh)->dma_handle))
179 191
180 192
181/* 193/*
@@ -212,7 +224,7 @@ static inline __le32 qh_element(struct uhci_qh *qh) {
212/* 224/*
213 * for TD <info>: (a.k.a. Token) 225 * for TD <info>: (a.k.a. Token)
214 */ 226 */
215#define td_token(td) le32_to_cpu((td)->token) 227#define td_token(uhci, td) hc32_to_cpu((uhci), (td)->token)
216#define TD_TOKEN_DEVADDR_SHIFT 8 228#define TD_TOKEN_DEVADDR_SHIFT 8
217#define TD_TOKEN_TOGGLE_SHIFT 19 229#define TD_TOKEN_TOGGLE_SHIFT 19
218#define TD_TOKEN_TOGGLE (1 << 19) 230#define TD_TOKEN_TOGGLE (1 << 19)
@@ -245,10 +257,10 @@ static inline __le32 qh_element(struct uhci_qh *qh) {
245 */ 257 */
246struct uhci_td { 258struct uhci_td {
247 /* Hardware fields */ 259 /* Hardware fields */
248 __le32 link; 260 __hc32 link;
249 __le32 status; 261 __hc32 status;
250 __le32 token; 262 __hc32 token;
251 __le32 buffer; 263 __hc32 buffer;
252 264
253 /* Software fields */ 265 /* Software fields */
254 dma_addr_t dma_handle; 266 dma_addr_t dma_handle;
@@ -263,14 +275,10 @@ struct uhci_td {
263 * We need a special accessor for the control/status word because it is 275 * We need a special accessor for the control/status word because it is
264 * subject to asynchronous updates by the controller. 276 * subject to asynchronous updates by the controller.
265 */ 277 */
266static inline u32 td_status(struct uhci_td *td) { 278#define td_status(uhci, td) hc32_to_cpu((uhci), \
267 __le32 status = td->status; 279 ACCESS_ONCE((td)->status))
268 280
269 barrier(); 281#define LINK_TO_TD(uhci, td) (cpu_to_hc32((uhci), (td)->dma_handle))
270 return le32_to_cpu(status);
271}
272
273#define LINK_TO_TD(td) (cpu_to_le32((td)->dma_handle))
274 282
275 283
276/* 284/*
@@ -380,6 +388,9 @@ struct uhci_hcd {
380 /* Grabbed from PCI */ 388 /* Grabbed from PCI */
381 unsigned long io_addr; 389 unsigned long io_addr;
382 390
391 /* Used when registers are memory mapped */
392 void __iomem *regs;
393
383 struct dma_pool *qh_pool; 394 struct dma_pool *qh_pool;
384 struct dma_pool *td_pool; 395 struct dma_pool *td_pool;
385 396
@@ -390,7 +401,7 @@ struct uhci_hcd {
390 spinlock_t lock; 401 spinlock_t lock;
391 402
392 dma_addr_t frame_dma_handle; /* Hardware frame list */ 403 dma_addr_t frame_dma_handle; /* Hardware frame list */
393 __le32 *frame; 404 __hc32 *frame;
394 void **frame_cpu; /* CPU's frame list */ 405 void **frame_cpu; /* CPU's frame list */
395 406
396 enum uhci_rh_state rh_state; 407 enum uhci_rh_state rh_state;
@@ -415,6 +426,12 @@ struct uhci_hcd {
415 426
416 struct timer_list fsbr_timer; /* For turning off FBSR */ 427 struct timer_list fsbr_timer; /* For turning off FBSR */
417 428
429 /* Silicon quirks */
430 unsigned int oc_low:1; /* OverCurrent bit active low */
431 unsigned int wait_for_hp:1; /* Wait for HP port reset */
432 unsigned int big_endian_mmio:1; /* Big endian registers */
433 unsigned int big_endian_desc:1; /* Big endian descriptors */
434
418 /* Support for port suspend/resume/reset */ 435 /* Support for port suspend/resume/reset */
419 unsigned long port_c_suspend; /* Bit-arrays of ports */ 436 unsigned long port_c_suspend; /* Bit-arrays of ports */
420 unsigned long resuming_ports; 437 unsigned long resuming_ports;
@@ -429,6 +446,16 @@ struct uhci_hcd {
429 446
430 int total_load; /* Sum of array values */ 447 int total_load; /* Sum of array values */
431 short load[MAX_PHASE]; /* Periodic allocations */ 448 short load[MAX_PHASE]; /* Periodic allocations */
449
450 /* Reset host controller */
451 void (*reset_hc) (struct uhci_hcd *uhci);
452 int (*check_and_reset_hc) (struct uhci_hcd *uhci);
453 /* configure_hc should perform arch specific settings, if needed */
454 void (*configure_hc) (struct uhci_hcd *uhci);
455 /* Check for broken resume detect interrupts */
456 int (*resume_detect_interrupts_are_broken) (struct uhci_hcd *uhci);
457 /* Check for broken global suspend */
458 int (*global_suspend_mode_is_broken) (struct uhci_hcd *uhci);
432}; 459};
433 460
434/* Convert between a usb_hcd pointer and the corresponding uhci_hcd */ 461/* Convert between a usb_hcd pointer and the corresponding uhci_hcd */
@@ -467,4 +494,171 @@ struct urb_priv {
467#define PCI_VENDOR_ID_GENESYS 0x17a0 494#define PCI_VENDOR_ID_GENESYS 0x17a0
468#define PCI_DEVICE_ID_GL880S_UHCI 0x8083 495#define PCI_DEVICE_ID_GL880S_UHCI 0x8083
469 496
497/*
498 * Functions used to access controller registers. The UCHI spec says that host
499 * controller I/O registers are mapped into PCI I/O space. For non-PCI hosts
500 * we use memory mapped registers.
501 */
502
503#ifndef CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC
504/* Support PCI only */
505static inline u32 uhci_readl(const struct uhci_hcd *uhci, int reg)
506{
507 return inl(uhci->io_addr + reg);
508}
509
510static inline void uhci_writel(const struct uhci_hcd *uhci, u32 val, int reg)
511{
512 outl(val, uhci->io_addr + reg);
513}
514
515static inline u16 uhci_readw(const struct uhci_hcd *uhci, int reg)
516{
517 return inw(uhci->io_addr + reg);
518}
519
520static inline void uhci_writew(const struct uhci_hcd *uhci, u16 val, int reg)
521{
522 outw(val, uhci->io_addr + reg);
523}
524
525static inline u8 uhci_readb(const struct uhci_hcd *uhci, int reg)
526{
527 return inb(uhci->io_addr + reg);
528}
529
530static inline void uhci_writeb(const struct uhci_hcd *uhci, u8 val, int reg)
531{
532 outb(val, uhci->io_addr + reg);
533}
534
535#else
536/* Support non-PCI host controllers */
537#ifdef CONFIG_PCI
538/* Support PCI and non-PCI host controllers */
539#define uhci_has_pci_registers(u) ((u)->io_addr != 0)
540#else
541/* Support non-PCI host controllers only */
542#define uhci_has_pci_registers(u) 0
543#endif
544
545#ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO
546/* Support (non-PCI) big endian host controllers */
547#define uhci_big_endian_mmio(u) ((u)->big_endian_mmio)
548#else
549#define uhci_big_endian_mmio(u) 0
550#endif
551
552static inline u32 uhci_readl(const struct uhci_hcd *uhci, int reg)
553{
554 if (uhci_has_pci_registers(uhci))
555 return inl(uhci->io_addr + reg);
556#ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO
557 else if (uhci_big_endian_mmio(uhci))
558 return readl_be(uhci->regs + reg);
559#endif
560 else
561 return readl(uhci->regs + reg);
562}
563
564static inline void uhci_writel(const struct uhci_hcd *uhci, u32 val, int reg)
565{
566 if (uhci_has_pci_registers(uhci))
567 outl(val, uhci->io_addr + reg);
568#ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO
569 else if (uhci_big_endian_mmio(uhci))
570 writel_be(val, uhci->regs + reg);
571#endif
572 else
573 writel(val, uhci->regs + reg);
574}
575
576static inline u16 uhci_readw(const struct uhci_hcd *uhci, int reg)
577{
578 if (uhci_has_pci_registers(uhci))
579 return inw(uhci->io_addr + reg);
580#ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO
581 else if (uhci_big_endian_mmio(uhci))
582 return readw_be(uhci->regs + reg);
583#endif
584 else
585 return readw(uhci->regs + reg);
586}
587
588static inline void uhci_writew(const struct uhci_hcd *uhci, u16 val, int reg)
589{
590 if (uhci_has_pci_registers(uhci))
591 outw(val, uhci->io_addr + reg);
592#ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO
593 else if (uhci_big_endian_mmio(uhci))
594 writew_be(val, uhci->regs + reg);
595#endif
596 else
597 writew(val, uhci->regs + reg);
598}
599
600static inline u8 uhci_readb(const struct uhci_hcd *uhci, int reg)
601{
602 if (uhci_has_pci_registers(uhci))
603 return inb(uhci->io_addr + reg);
604#ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO
605 else if (uhci_big_endian_mmio(uhci))
606 return readb_be(uhci->regs + reg);
607#endif
608 else
609 return readb(uhci->regs + reg);
610}
611
612static inline void uhci_writeb(const struct uhci_hcd *uhci, u8 val, int reg)
613{
614 if (uhci_has_pci_registers(uhci))
615 outb(val, uhci->io_addr + reg);
616#ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO
617 else if (uhci_big_endian_mmio(uhci))
618 writeb_be(val, uhci->regs + reg);
619#endif
620 else
621 writeb(val, uhci->regs + reg);
622}
623#endif /* CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC */
624
625/*
626 * The GRLIB GRUSBHC controller can use big endian format for its descriptors.
627 *
628 * UHCI controllers accessed through PCI work normally (little-endian
629 * everywhere), so we don't bother supporting a BE-only mode.
630 */
631#ifdef CONFIG_USB_UHCI_BIG_ENDIAN_DESC
632#define uhci_big_endian_desc(u) ((u)->big_endian_desc)
633
634/* cpu to uhci */
635static inline __hc32 cpu_to_hc32(const struct uhci_hcd *uhci, const u32 x)
636{
637 return uhci_big_endian_desc(uhci)
638 ? (__force __hc32)cpu_to_be32(x)
639 : (__force __hc32)cpu_to_le32(x);
640}
641
642/* uhci to cpu */
643static inline u32 hc32_to_cpu(const struct uhci_hcd *uhci, const __hc32 x)
644{
645 return uhci_big_endian_desc(uhci)
646 ? be32_to_cpu((__force __be32)x)
647 : le32_to_cpu((__force __le32)x);
648}
649
650#else
651/* cpu to uhci */
652static inline __hc32 cpu_to_hc32(const struct uhci_hcd *uhci, const u32 x)
653{
654 return cpu_to_le32(x);
655}
656
657/* uhci to cpu */
658static inline u32 hc32_to_cpu(const struct uhci_hcd *uhci, const __hc32 x)
659{
660 return le32_to_cpu(x);
661}
662#endif
663
470#endif 664#endif
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 6d59c0f77f25..045cde4cbc3d 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -44,7 +44,7 @@ static int any_ports_active(struct uhci_hcd *uhci)
44 int port; 44 int port;
45 45
46 for (port = 0; port < uhci->rh_numports; ++port) { 46 for (port = 0; port < uhci->rh_numports; ++port) {
47 if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) & 47 if ((uhci_readw(uhci, USBPORTSC1 + port * 2) &
48 (USBPORTSC_CCS | RWC_BITS)) || 48 (USBPORTSC_CCS | RWC_BITS)) ||
49 test_bit(port, &uhci->port_c_suspend)) 49 test_bit(port, &uhci->port_c_suspend))
50 return 1; 50 return 1;
@@ -68,7 +68,7 @@ static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
68 68
69 *buf = 0; 69 *buf = 0;
70 for (port = 0; port < uhci->rh_numports; ++port) { 70 for (port = 0; port < uhci->rh_numports; ++port) {
71 if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) & mask) || 71 if ((uhci_readw(uhci, USBPORTSC1 + port * 2) & mask) ||
72 test_bit(port, &uhci->port_c_suspend)) 72 test_bit(port, &uhci->port_c_suspend))
73 *buf |= (1 << (port + 1)); 73 *buf |= (1 << (port + 1));
74 } 74 }
@@ -78,17 +78,17 @@ static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
78#define OK(x) len = (x); break 78#define OK(x) len = (x); break
79 79
80#define CLR_RH_PORTSTAT(x) \ 80#define CLR_RH_PORTSTAT(x) \
81 status = inw(port_addr); \ 81 status = uhci_readw(uhci, port_addr); \
82 status &= ~(RWC_BITS|WZ_BITS); \ 82 status &= ~(RWC_BITS|WZ_BITS); \
83 status &= ~(x); \ 83 status &= ~(x); \
84 status |= RWC_BITS & (x); \ 84 status |= RWC_BITS & (x); \
85 outw(status, port_addr) 85 uhci_writew(uhci, status, port_addr)
86 86
87#define SET_RH_PORTSTAT(x) \ 87#define SET_RH_PORTSTAT(x) \
88 status = inw(port_addr); \ 88 status = uhci_readw(uhci, port_addr); \
89 status |= (x); \ 89 status |= (x); \
90 status &= ~(RWC_BITS|WZ_BITS); \ 90 status &= ~(RWC_BITS|WZ_BITS); \
91 outw(status, port_addr) 91 uhci_writew(uhci, status, port_addr)
92 92
93/* UHCI controllers don't automatically stop resume signalling after 20 msec, 93/* UHCI controllers don't automatically stop resume signalling after 20 msec,
94 * so we have to poll and check timeouts in order to take care of it. 94 * so we have to poll and check timeouts in order to take care of it.
@@ -99,7 +99,7 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
99 int status; 99 int status;
100 int i; 100 int i;
101 101
102 if (inw(port_addr) & SUSPEND_BITS) { 102 if (uhci_readw(uhci, port_addr) & SUSPEND_BITS) {
103 CLR_RH_PORTSTAT(SUSPEND_BITS); 103 CLR_RH_PORTSTAT(SUSPEND_BITS);
104 if (test_bit(port, &uhci->resuming_ports)) 104 if (test_bit(port, &uhci->resuming_ports))
105 set_bit(port, &uhci->port_c_suspend); 105 set_bit(port, &uhci->port_c_suspend);
@@ -110,7 +110,7 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
110 * Experiments show that some controllers take longer, so 110 * Experiments show that some controllers take longer, so
111 * we'll poll for completion. */ 111 * we'll poll for completion. */
112 for (i = 0; i < 10; ++i) { 112 for (i = 0; i < 10; ++i) {
113 if (!(inw(port_addr) & SUSPEND_BITS)) 113 if (!(uhci_readw(uhci, port_addr) & SUSPEND_BITS))
114 break; 114 break;
115 udelay(1); 115 udelay(1);
116 } 116 }
@@ -121,12 +121,12 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
121/* Wait for the UHCI controller in HP's iLO2 server management chip. 121/* Wait for the UHCI controller in HP's iLO2 server management chip.
122 * It can take up to 250 us to finish a reset and set the CSC bit. 122 * It can take up to 250 us to finish a reset and set the CSC bit.
123 */ 123 */
124static void wait_for_HP(unsigned long port_addr) 124static void wait_for_HP(struct uhci_hcd *uhci, unsigned long port_addr)
125{ 125{
126 int i; 126 int i;
127 127
128 for (i = 10; i < 250; i += 10) { 128 for (i = 10; i < 250; i += 10) {
129 if (inw(port_addr) & USBPORTSC_CSC) 129 if (uhci_readw(uhci, port_addr) & USBPORTSC_CSC)
130 return; 130 return;
131 udelay(10); 131 udelay(10);
132 } 132 }
@@ -140,8 +140,8 @@ static void uhci_check_ports(struct uhci_hcd *uhci)
140 int status; 140 int status;
141 141
142 for (port = 0; port < uhci->rh_numports; ++port) { 142 for (port = 0; port < uhci->rh_numports; ++port) {
143 port_addr = uhci->io_addr + USBPORTSC1 + 2 * port; 143 port_addr = USBPORTSC1 + 2 * port;
144 status = inw(port_addr); 144 status = uhci_readw(uhci, port_addr);
145 if (unlikely(status & USBPORTSC_PR)) { 145 if (unlikely(status & USBPORTSC_PR)) {
146 if (time_after_eq(jiffies, uhci->ports_timeout)) { 146 if (time_after_eq(jiffies, uhci->ports_timeout)) {
147 CLR_RH_PORTSTAT(USBPORTSC_PR); 147 CLR_RH_PORTSTAT(USBPORTSC_PR);
@@ -149,9 +149,8 @@ static void uhci_check_ports(struct uhci_hcd *uhci)
149 149
150 /* HP's server management chip requires 150 /* HP's server management chip requires
151 * a longer delay. */ 151 * a longer delay. */
152 if (to_pci_dev(uhci_dev(uhci))->vendor == 152 if (uhci->wait_for_hp)
153 PCI_VENDOR_ID_HP) 153 wait_for_HP(uhci, port_addr);
154 wait_for_HP(port_addr);
155 154
156 /* If the port was enabled before, turning 155 /* If the port was enabled before, turning
157 * reset on caused a port enable change. 156 * reset on caused a port enable change.
@@ -242,7 +241,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
242 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 241 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
243 int status, lstatus, retval = 0, len = 0; 242 int status, lstatus, retval = 0, len = 0;
244 unsigned int port = wIndex - 1; 243 unsigned int port = wIndex - 1;
245 unsigned long port_addr = uhci->io_addr + USBPORTSC1 + 2 * port; 244 unsigned long port_addr = USBPORTSC1 + 2 * port;
246 u16 wPortChange, wPortStatus; 245 u16 wPortChange, wPortStatus;
247 unsigned long flags; 246 unsigned long flags;
248 247
@@ -260,14 +259,13 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
260 goto err; 259 goto err;
261 260
262 uhci_check_ports(uhci); 261 uhci_check_ports(uhci);
263 status = inw(port_addr); 262 status = uhci_readw(uhci, port_addr);
264 263
265 /* Intel controllers report the OverCurrent bit active on. 264 /* Intel controllers report the OverCurrent bit active on.
266 * VIA controllers report it active off, so we'll adjust the 265 * VIA controllers report it active off, so we'll adjust the
267 * bit value. (It's not standardized in the UHCI spec.) 266 * bit value. (It's not standardized in the UHCI spec.)
268 */ 267 */
269 if (to_pci_dev(hcd->self.controller)->vendor == 268 if (uhci->oc_low)
270 PCI_VENDOR_ID_VIA)
271 status ^= USBPORTSC_OC; 269 status ^= USBPORTSC_OC;
272 270
273 /* UHCI doesn't support C_RESET (always false) */ 271 /* UHCI doesn't support C_RESET (always false) */
@@ -358,7 +356,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
358 CLR_RH_PORTSTAT(USBPORTSC_PEC); 356 CLR_RH_PORTSTAT(USBPORTSC_PEC);
359 OK(0); 357 OK(0);
360 case USB_PORT_FEAT_SUSPEND: 358 case USB_PORT_FEAT_SUSPEND:
361 if (!(inw(port_addr) & USBPORTSC_SUSP)) { 359 if (!(uhci_readw(uhci, port_addr) & USBPORTSC_SUSP)) {
362 360
363 /* Make certain the port isn't suspended */ 361 /* Make certain the port isn't suspended */
364 uhci_finish_suspend(uhci, port, port_addr); 362 uhci_finish_suspend(uhci, port, port_addr);
@@ -370,7 +368,8 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
370 * if the port is disabled. When this happens 368 * if the port is disabled. When this happens
371 * just skip the Resume signalling. 369 * just skip the Resume signalling.
372 */ 370 */
373 if (!(inw(port_addr) & USBPORTSC_RD)) 371 if (!(uhci_readw(uhci, port_addr) &
372 USBPORTSC_RD))
374 uhci_finish_suspend(uhci, port, 373 uhci_finish_suspend(uhci, port,
375 port_addr); 374 port_addr);
376 else 375 else
diff --git a/drivers/usb/host/uhci-pci.c b/drivers/usb/host/uhci-pci.c
new file mode 100644
index 000000000000..c300bd2f7d1c
--- /dev/null
+++ b/drivers/usb/host/uhci-pci.c
@@ -0,0 +1,301 @@
1/*
2 * UHCI HCD (Host Controller Driver) PCI Bus Glue.
3 *
4 * Extracted from uhci-hcd.c:
5 * Maintainer: Alan Stern <stern@rowland.harvard.edu>
6 *
7 * (C) Copyright 1999 Linus Torvalds
8 * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com
9 * (C) Copyright 1999 Randy Dunlap
10 * (C) Copyright 1999 Georg Acher, acher@in.tum.de
11 * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de
12 * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch
13 * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at
14 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
15 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
16 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
17 * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
18 */
19
20#include "pci-quirks.h"
21
22/*
23 * Make sure the controller is completely inactive, unable to
24 * generate interrupts or do DMA.
25 */
26static void uhci_pci_reset_hc(struct uhci_hcd *uhci)
27{
28 uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr);
29}
30
31/*
32 * Initialize a controller that was newly discovered or has just been
33 * resumed. In either case we can't be sure of its previous state.
34 *
35 * Returns: 1 if the controller was reset, 0 otherwise.
36 */
37static int uhci_pci_check_and_reset_hc(struct uhci_hcd *uhci)
38{
39 return uhci_check_and_reset_hc(to_pci_dev(uhci_dev(uhci)),
40 uhci->io_addr);
41}
42
43/*
44 * Store the basic register settings needed by the controller.
45 * This function is called at the end of configure_hc in uhci-hcd.c.
46 */
47static void uhci_pci_configure_hc(struct uhci_hcd *uhci)
48{
49 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
50
51 /* Enable PIRQ */
52 pci_write_config_word(pdev, USBLEGSUP, USBLEGSUP_DEFAULT);
53
54 /* Disable platform-specific non-PME# wakeup */
55 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
56 pci_write_config_byte(pdev, USBRES_INTEL, 0);
57}
58
59static int uhci_pci_resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
60{
61 int port;
62
63 switch (to_pci_dev(uhci_dev(uhci))->vendor) {
64 default:
65 break;
66
67 case PCI_VENDOR_ID_GENESYS:
68 /* Genesys Logic's GL880S controllers don't generate
69 * resume-detect interrupts.
70 */
71 return 1;
72
73 case PCI_VENDOR_ID_INTEL:
74 /* Some of Intel's USB controllers have a bug that causes
75 * resume-detect interrupts if any port has an over-current
76 * condition. To make matters worse, some motherboards
77 * hardwire unused USB ports' over-current inputs active!
78 * To prevent problems, we will not enable resume-detect
79 * interrupts if any ports are OC.
80 */
81 for (port = 0; port < uhci->rh_numports; ++port) {
82 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
83 USBPORTSC_OC)
84 return 1;
85 }
86 break;
87 }
88 return 0;
89}
90
91static int uhci_pci_global_suspend_mode_is_broken(struct uhci_hcd *uhci)
92{
93 int port;
94 const char *sys_info;
95 static const char bad_Asus_board[] = "A7V8X";
96
97 /* One of Asus's motherboards has a bug which causes it to
98 * wake up immediately from suspend-to-RAM if any of the ports
99 * are connected. In such cases we will not set EGSM.
100 */
101 sys_info = dmi_get_system_info(DMI_BOARD_NAME);
102 if (sys_info && !strcmp(sys_info, bad_Asus_board)) {
103 for (port = 0; port < uhci->rh_numports; ++port) {
104 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
105 USBPORTSC_CCS)
106 return 1;
107 }
108 }
109
110 return 0;
111}
112
113static int uhci_pci_init(struct usb_hcd *hcd)
114{
115 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
116
117 uhci->io_addr = (unsigned long) hcd->rsrc_start;
118
119 uhci->rh_numports = uhci_count_ports(hcd);
120
121 /* Intel controllers report the OverCurrent bit active on.
122 * VIA controllers report it active off, so we'll adjust the
123 * bit value. (It's not standardized in the UHCI spec.)
124 */
125 if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_VIA)
126 uhci->oc_low = 1;
127
128 /* HP's server management chip requires a longer port reset delay. */
129 if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_HP)
130 uhci->wait_for_hp = 1;
131
132 /* Set up pointers to PCI-specific functions */
133 uhci->reset_hc = uhci_pci_reset_hc;
134 uhci->check_and_reset_hc = uhci_pci_check_and_reset_hc;
135 uhci->configure_hc = uhci_pci_configure_hc;
136 uhci->resume_detect_interrupts_are_broken =
137 uhci_pci_resume_detect_interrupts_are_broken;
138 uhci->global_suspend_mode_is_broken =
139 uhci_pci_global_suspend_mode_is_broken;
140
141
142 /* Kick BIOS off this hardware and reset if the controller
143 * isn't already safely quiescent.
144 */
145 check_and_reset_hc(uhci);
146 return 0;
147}
148
149/* Make sure the controller is quiescent and that we're not using it
150 * any more. This is mainly for the benefit of programs which, like kexec,
151 * expect the hardware to be idle: not doing DMA or generating IRQs.
152 *
153 * This routine may be called in a damaged or failing kernel. Hence we
154 * do not acquire the spinlock before shutting down the controller.
155 */
156static void uhci_shutdown(struct pci_dev *pdev)
157{
158 struct usb_hcd *hcd = pci_get_drvdata(pdev);
159
160 uhci_hc_died(hcd_to_uhci(hcd));
161}
162
163#ifdef CONFIG_PM
164
165static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
166{
167 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
168 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
169 int rc = 0;
170
171 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
172
173 spin_lock_irq(&uhci->lock);
174 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
175 goto done_okay; /* Already suspended or dead */
176
177 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
178 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
179 rc = -EBUSY;
180 goto done;
181 };
182
183 /* All PCI host controllers are required to disable IRQ generation
184 * at the source, so we must turn off PIRQ.
185 */
186 pci_write_config_word(pdev, USBLEGSUP, 0);
187 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
188
189 /* Enable platform-specific non-PME# wakeup */
190 if (do_wakeup) {
191 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
192 pci_write_config_byte(pdev, USBRES_INTEL,
193 USBPORT1EN | USBPORT2EN);
194 }
195
196done_okay:
197 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
198done:
199 spin_unlock_irq(&uhci->lock);
200 return rc;
201}
202
203static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
204{
205 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
206
207 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
208
209 /* Since we aren't in D3 any more, it's safe to set this flag
210 * even if the controller was dead.
211 */
212 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
213
214 spin_lock_irq(&uhci->lock);
215
216 /* Make sure resume from hibernation re-enumerates everything */
217 if (hibernated) {
218 uhci->reset_hc(uhci);
219 finish_reset(uhci);
220 }
221
222 /* The firmware may have changed the controller settings during
223 * a system wakeup. Check it and reconfigure to avoid problems.
224 */
225 else {
226 check_and_reset_hc(uhci);
227 }
228 configure_hc(uhci);
229
230 /* Tell the core if the controller had to be reset */
231 if (uhci->rh_state == UHCI_RH_RESET)
232 usb_root_hub_lost_power(hcd->self.root_hub);
233
234 spin_unlock_irq(&uhci->lock);
235
236 /* If interrupts don't work and remote wakeup is enabled then
237 * the suspended root hub needs to be polled.
238 */
239 if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup)
240 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
241
242 /* Does the root hub have a port wakeup pending? */
243 usb_hcd_poll_rh_status(hcd);
244 return 0;
245}
246
247#endif
248
249static const struct hc_driver uhci_driver = {
250 .description = hcd_name,
251 .product_desc = "UHCI Host Controller",
252 .hcd_priv_size = sizeof(struct uhci_hcd),
253
254 /* Generic hardware linkage */
255 .irq = uhci_irq,
256 .flags = HCD_USB11,
257
258 /* Basic lifecycle operations */
259 .reset = uhci_pci_init,
260 .start = uhci_start,
261#ifdef CONFIG_PM
262 .pci_suspend = uhci_pci_suspend,
263 .pci_resume = uhci_pci_resume,
264 .bus_suspend = uhci_rh_suspend,
265 .bus_resume = uhci_rh_resume,
266#endif
267 .stop = uhci_stop,
268
269 .urb_enqueue = uhci_urb_enqueue,
270 .urb_dequeue = uhci_urb_dequeue,
271
272 .endpoint_disable = uhci_hcd_endpoint_disable,
273 .get_frame_number = uhci_hcd_get_frame_number,
274
275 .hub_status_data = uhci_hub_status_data,
276 .hub_control = uhci_hub_control,
277};
278
279static DEFINE_PCI_DEVICE_TABLE(uhci_pci_ids) = { {
280 /* handle any USB UHCI controller */
281 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
282 .driver_data = (unsigned long) &uhci_driver,
283 }, { /* end: all zeroes */ }
284};
285
286MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
287
288static struct pci_driver uhci_pci_driver = {
289 .name = (char *)hcd_name,
290 .id_table = uhci_pci_ids,
291
292 .probe = usb_hcd_pci_probe,
293 .remove = usb_hcd_pci_remove,
294 .shutdown = uhci_shutdown,
295
296#ifdef CONFIG_PM_SLEEP
297 .driver = {
298 .pm = &usb_hcd_pci_pm_ops
299 },
300#endif
301};
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index d3ade4018487..84ed28b34f93 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -29,12 +29,12 @@ static void uhci_set_next_interrupt(struct uhci_hcd *uhci)
29{ 29{
30 if (uhci->is_stopped) 30 if (uhci->is_stopped)
31 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies); 31 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies);
32 uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC); 32 uhci->term_td->status |= cpu_to_hc32(uhci, TD_CTRL_IOC);
33} 33}
34 34
35static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci) 35static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci)
36{ 36{
37 uhci->term_td->status &= ~cpu_to_le32(TD_CTRL_IOC); 37 uhci->term_td->status &= ~cpu_to_hc32(uhci, TD_CTRL_IOC);
38} 38}
39 39
40 40
@@ -53,7 +53,7 @@ static void uhci_fsbr_on(struct uhci_hcd *uhci)
53 uhci->fsbr_is_on = 1; 53 uhci->fsbr_is_on = 1;
54 lqh = list_entry(uhci->skel_async_qh->node.prev, 54 lqh = list_entry(uhci->skel_async_qh->node.prev,
55 struct uhci_qh, node); 55 struct uhci_qh, node);
56 lqh->link = LINK_TO_QH(uhci->skel_term_qh); 56 lqh->link = LINK_TO_QH(uhci, uhci->skel_term_qh);
57} 57}
58 58
59static void uhci_fsbr_off(struct uhci_hcd *uhci) 59static void uhci_fsbr_off(struct uhci_hcd *uhci)
@@ -65,7 +65,7 @@ static void uhci_fsbr_off(struct uhci_hcd *uhci)
65 uhci->fsbr_is_on = 0; 65 uhci->fsbr_is_on = 0;
66 lqh = list_entry(uhci->skel_async_qh->node.prev, 66 lqh = list_entry(uhci->skel_async_qh->node.prev,
67 struct uhci_qh, node); 67 struct uhci_qh, node);
68 lqh->link = UHCI_PTR_TERM; 68 lqh->link = UHCI_PTR_TERM(uhci);
69} 69}
70 70
71static void uhci_add_fsbr(struct uhci_hcd *uhci, struct urb *urb) 71static void uhci_add_fsbr(struct uhci_hcd *uhci, struct urb *urb)
@@ -131,12 +131,12 @@ static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td)
131 dma_pool_free(uhci->td_pool, td, td->dma_handle); 131 dma_pool_free(uhci->td_pool, td, td->dma_handle);
132} 132}
133 133
134static inline void uhci_fill_td(struct uhci_td *td, u32 status, 134static inline void uhci_fill_td(struct uhci_hcd *uhci, struct uhci_td *td,
135 u32 token, u32 buffer) 135 u32 status, u32 token, u32 buffer)
136{ 136{
137 td->status = cpu_to_le32(status); 137 td->status = cpu_to_hc32(uhci, status);
138 td->token = cpu_to_le32(token); 138 td->token = cpu_to_hc32(uhci, token);
139 td->buffer = cpu_to_le32(buffer); 139 td->buffer = cpu_to_hc32(uhci, buffer);
140} 140}
141 141
142static void uhci_add_td_to_urbp(struct uhci_td *td, struct urb_priv *urbp) 142static void uhci_add_td_to_urbp(struct uhci_td *td, struct urb_priv *urbp)
@@ -170,11 +170,11 @@ static inline void uhci_insert_td_in_frame_list(struct uhci_hcd *uhci,
170 170
171 td->link = ltd->link; 171 td->link = ltd->link;
172 wmb(); 172 wmb();
173 ltd->link = LINK_TO_TD(td); 173 ltd->link = LINK_TO_TD(uhci, td);
174 } else { 174 } else {
175 td->link = uhci->frame[framenum]; 175 td->link = uhci->frame[framenum];
176 wmb(); 176 wmb();
177 uhci->frame[framenum] = LINK_TO_TD(td); 177 uhci->frame[framenum] = LINK_TO_TD(uhci, td);
178 uhci->frame_cpu[framenum] = td; 178 uhci->frame_cpu[framenum] = td;
179 } 179 }
180} 180}
@@ -195,8 +195,10 @@ static inline void uhci_remove_td_from_frame_list(struct uhci_hcd *uhci,
195 } else { 195 } else {
196 struct uhci_td *ntd; 196 struct uhci_td *ntd;
197 197
198 ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list); 198 ntd = list_entry(td->fl_list.next,
199 uhci->frame[td->frame] = LINK_TO_TD(ntd); 199 struct uhci_td,
200 fl_list);
201 uhci->frame[td->frame] = LINK_TO_TD(uhci, ntd);
200 uhci->frame_cpu[td->frame] = ntd; 202 uhci->frame_cpu[td->frame] = ntd;
201 } 203 }
202 } else { 204 } else {
@@ -253,8 +255,8 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci,
253 memset(qh, 0, sizeof(*qh)); 255 memset(qh, 0, sizeof(*qh));
254 qh->dma_handle = dma_handle; 256 qh->dma_handle = dma_handle;
255 257
256 qh->element = UHCI_PTR_TERM; 258 qh->element = UHCI_PTR_TERM(uhci);
257 qh->link = UHCI_PTR_TERM; 259 qh->link = UHCI_PTR_TERM(uhci);
258 260
259 INIT_LIST_HEAD(&qh->queue); 261 INIT_LIST_HEAD(&qh->queue);
260 INIT_LIST_HEAD(&qh->node); 262 INIT_LIST_HEAD(&qh->node);
@@ -346,9 +348,9 @@ static int uhci_cleanup_queue(struct uhci_hcd *uhci, struct uhci_qh *qh,
346 348
347 /* If the QH element pointer is UHCI_PTR_TERM then then currently 349 /* If the QH element pointer is UHCI_PTR_TERM then then currently
348 * executing URB has already been unlinked, so this one isn't it. */ 350 * executing URB has already been unlinked, so this one isn't it. */
349 if (qh_element(qh) == UHCI_PTR_TERM) 351 if (qh_element(qh) == UHCI_PTR_TERM(uhci))
350 goto done; 352 goto done;
351 qh->element = UHCI_PTR_TERM; 353 qh->element = UHCI_PTR_TERM(uhci);
352 354
353 /* Control pipes don't have to worry about toggles */ 355 /* Control pipes don't have to worry about toggles */
354 if (qh->type == USB_ENDPOINT_XFER_CONTROL) 356 if (qh->type == USB_ENDPOINT_XFER_CONTROL)
@@ -358,7 +360,7 @@ static int uhci_cleanup_queue(struct uhci_hcd *uhci, struct uhci_qh *qh,
358 WARN_ON(list_empty(&urbp->td_list)); 360 WARN_ON(list_empty(&urbp->td_list));
359 td = list_entry(urbp->td_list.next, struct uhci_td, list); 361 td = list_entry(urbp->td_list.next, struct uhci_td, list);
360 qh->needs_fixup = 1; 362 qh->needs_fixup = 1;
361 qh->initial_toggle = uhci_toggle(td_token(td)); 363 qh->initial_toggle = uhci_toggle(td_token(uhci, td));
362 364
363done: 365done:
364 return ret; 366 return ret;
@@ -368,7 +370,8 @@ done:
368 * Fix up the data toggles for URBs in a queue, when one of them 370 * Fix up the data toggles for URBs in a queue, when one of them
369 * terminates early (short transfer, error, or dequeued). 371 * terminates early (short transfer, error, or dequeued).
370 */ 372 */
371static void uhci_fixup_toggles(struct uhci_qh *qh, int skip_first) 373static void uhci_fixup_toggles(struct uhci_hcd *uhci, struct uhci_qh *qh,
374 int skip_first)
372{ 375{
373 struct urb_priv *urbp = NULL; 376 struct urb_priv *urbp = NULL;
374 struct uhci_td *td; 377 struct uhci_td *td;
@@ -382,7 +385,7 @@ static void uhci_fixup_toggles(struct uhci_qh *qh, int skip_first)
382 385
383 /* When starting with the first URB, if the QH element pointer is 386 /* When starting with the first URB, if the QH element pointer is
384 * still valid then we know the URB's toggles are okay. */ 387 * still valid then we know the URB's toggles are okay. */
385 else if (qh_element(qh) != UHCI_PTR_TERM) 388 else if (qh_element(qh) != UHCI_PTR_TERM(uhci))
386 toggle = 2; 389 toggle = 2;
387 390
388 /* Fix up the toggle for the URBs in the queue. Normally this 391 /* Fix up the toggle for the URBs in the queue. Normally this
@@ -394,15 +397,15 @@ static void uhci_fixup_toggles(struct uhci_qh *qh, int skip_first)
394 /* If the first TD has the right toggle value, we don't 397 /* If the first TD has the right toggle value, we don't
395 * need to change any toggles in this URB */ 398 * need to change any toggles in this URB */
396 td = list_entry(urbp->td_list.next, struct uhci_td, list); 399 td = list_entry(urbp->td_list.next, struct uhci_td, list);
397 if (toggle > 1 || uhci_toggle(td_token(td)) == toggle) { 400 if (toggle > 1 || uhci_toggle(td_token(uhci, td)) == toggle) {
398 td = list_entry(urbp->td_list.prev, struct uhci_td, 401 td = list_entry(urbp->td_list.prev, struct uhci_td,
399 list); 402 list);
400 toggle = uhci_toggle(td_token(td)) ^ 1; 403 toggle = uhci_toggle(td_token(uhci, td)) ^ 1;
401 404
402 /* Otherwise all the toggles in the URB have to be switched */ 405 /* Otherwise all the toggles in the URB have to be switched */
403 } else { 406 } else {
404 list_for_each_entry(td, &urbp->td_list, list) { 407 list_for_each_entry(td, &urbp->td_list, list) {
405 td->token ^= cpu_to_le32( 408 td->token ^= cpu_to_hc32(uhci,
406 TD_TOKEN_TOGGLE); 409 TD_TOKEN_TOGGLE);
407 toggle ^= 1; 410 toggle ^= 1;
408 } 411 }
@@ -439,7 +442,7 @@ static void link_interrupt(struct uhci_hcd *uhci, struct uhci_qh *qh)
439 pqh = list_entry(qh->node.prev, struct uhci_qh, node); 442 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
440 qh->link = pqh->link; 443 qh->link = pqh->link;
441 wmb(); 444 wmb();
442 pqh->link = LINK_TO_QH(qh); 445 pqh->link = LINK_TO_QH(uhci, qh);
443} 446}
444 447
445/* 448/*
@@ -449,7 +452,7 @@ static void link_interrupt(struct uhci_hcd *uhci, struct uhci_qh *qh)
449static void link_async(struct uhci_hcd *uhci, struct uhci_qh *qh) 452static void link_async(struct uhci_hcd *uhci, struct uhci_qh *qh)
450{ 453{
451 struct uhci_qh *pqh; 454 struct uhci_qh *pqh;
452 __le32 link_to_new_qh; 455 __hc32 link_to_new_qh;
453 456
454 /* Find the predecessor QH for our new one and insert it in the list. 457 /* Find the predecessor QH for our new one and insert it in the list.
455 * The list of QHs is expected to be short, so linear search won't 458 * The list of QHs is expected to be short, so linear search won't
@@ -463,7 +466,7 @@ static void link_async(struct uhci_hcd *uhci, struct uhci_qh *qh)
463 /* Link it into the schedule */ 466 /* Link it into the schedule */
464 qh->link = pqh->link; 467 qh->link = pqh->link;
465 wmb(); 468 wmb();
466 link_to_new_qh = LINK_TO_QH(qh); 469 link_to_new_qh = LINK_TO_QH(uhci, qh);
467 pqh->link = link_to_new_qh; 470 pqh->link = link_to_new_qh;
468 471
469 /* If this is now the first FSBR QH, link the terminating skeleton 472 /* If this is now the first FSBR QH, link the terminating skeleton
@@ -481,13 +484,13 @@ static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
481 484
482 /* Set the element pointer if it isn't set already. 485 /* Set the element pointer if it isn't set already.
483 * This isn't needed for Isochronous queues, but it doesn't hurt. */ 486 * This isn't needed for Isochronous queues, but it doesn't hurt. */
484 if (qh_element(qh) == UHCI_PTR_TERM) { 487 if (qh_element(qh) == UHCI_PTR_TERM(uhci)) {
485 struct urb_priv *urbp = list_entry(qh->queue.next, 488 struct urb_priv *urbp = list_entry(qh->queue.next,
486 struct urb_priv, node); 489 struct urb_priv, node);
487 struct uhci_td *td = list_entry(urbp->td_list.next, 490 struct uhci_td *td = list_entry(urbp->td_list.next,
488 struct uhci_td, list); 491 struct uhci_td, list);
489 492
490 qh->element = LINK_TO_TD(td); 493 qh->element = LINK_TO_TD(uhci, td);
491 } 494 }
492 495
493 /* Treat the queue as if it has just advanced */ 496 /* Treat the queue as if it has just advanced */
@@ -531,7 +534,7 @@ static void unlink_interrupt(struct uhci_hcd *uhci, struct uhci_qh *qh)
531static void unlink_async(struct uhci_hcd *uhci, struct uhci_qh *qh) 534static void unlink_async(struct uhci_hcd *uhci, struct uhci_qh *qh)
532{ 535{
533 struct uhci_qh *pqh; 536 struct uhci_qh *pqh;
534 __le32 link_to_next_qh = qh->link; 537 __hc32 link_to_next_qh = qh->link;
535 538
536 pqh = list_entry(qh->node.prev, struct uhci_qh, node); 539 pqh = list_entry(qh->node.prev, struct uhci_qh, node);
537 pqh->link = link_to_next_qh; 540 pqh->link = link_to_next_qh;
@@ -728,7 +731,7 @@ static inline struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci,
728 731
729 urbp->urb = urb; 732 urbp->urb = urb;
730 urb->hcpriv = urbp; 733 urb->hcpriv = urbp;
731 734
732 INIT_LIST_HEAD(&urbp->node); 735 INIT_LIST_HEAD(&urbp->node);
733 INIT_LIST_HEAD(&urbp->td_list); 736 INIT_LIST_HEAD(&urbp->td_list);
734 737
@@ -755,8 +758,8 @@ static void uhci_free_urb_priv(struct uhci_hcd *uhci,
755/* 758/*
756 * Map status to standard result codes 759 * Map status to standard result codes
757 * 760 *
758 * <status> is (td_status(td) & 0xF60000), a.k.a. 761 * <status> is (td_status(uhci, td) & 0xF60000), a.k.a.
759 * uhci_status_bits(td_status(td)). 762 * uhci_status_bits(td_status(uhci, td)).
760 * Note: <status> does not include the TD_CTRL_NAK bit. 763 * Note: <status> does not include the TD_CTRL_NAK bit.
761 * <dir_out> is True for output TDs and False for input TDs. 764 * <dir_out> is True for output TDs and False for input TDs.
762 */ 765 */
@@ -792,7 +795,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
792 int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize); 795 int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize);
793 int len = urb->transfer_buffer_length; 796 int len = urb->transfer_buffer_length;
794 dma_addr_t data = urb->transfer_dma; 797 dma_addr_t data = urb->transfer_dma;
795 __le32 *plink; 798 __hc32 *plink;
796 struct urb_priv *urbp = urb->hcpriv; 799 struct urb_priv *urbp = urb->hcpriv;
797 int skel; 800 int skel;
798 801
@@ -809,7 +812,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
809 */ 812 */
810 td = qh->dummy_td; 813 td = qh->dummy_td;
811 uhci_add_td_to_urbp(td, urbp); 814 uhci_add_td_to_urbp(td, urbp);
812 uhci_fill_td(td, status, destination | uhci_explen(8), 815 uhci_fill_td(uhci, td, status, destination | uhci_explen(8),
813 urb->setup_dma); 816 urb->setup_dma);
814 plink = &td->link; 817 plink = &td->link;
815 status |= TD_CTRL_ACTIVE; 818 status |= TD_CTRL_ACTIVE;
@@ -842,14 +845,14 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
842 td = uhci_alloc_td(uhci); 845 td = uhci_alloc_td(uhci);
843 if (!td) 846 if (!td)
844 goto nomem; 847 goto nomem;
845 *plink = LINK_TO_TD(td); 848 *plink = LINK_TO_TD(uhci, td);
846 849
847 /* Alternate Data0/1 (start with Data1) */ 850 /* Alternate Data0/1 (start with Data1) */
848 destination ^= TD_TOKEN_TOGGLE; 851 destination ^= TD_TOKEN_TOGGLE;
849 852
850 uhci_add_td_to_urbp(td, urbp); 853 uhci_add_td_to_urbp(td, urbp);
851 uhci_fill_td(td, status, destination | uhci_explen(pktsze), 854 uhci_fill_td(uhci, td, status,
852 data); 855 destination | uhci_explen(pktsze), data);
853 plink = &td->link; 856 plink = &td->link;
854 857
855 data += pktsze; 858 data += pktsze;
@@ -857,19 +860,19 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
857 } 860 }
858 861
859 /* 862 /*
860 * Build the final TD for control status 863 * Build the final TD for control status
861 */ 864 */
862 td = uhci_alloc_td(uhci); 865 td = uhci_alloc_td(uhci);
863 if (!td) 866 if (!td)
864 goto nomem; 867 goto nomem;
865 *plink = LINK_TO_TD(td); 868 *plink = LINK_TO_TD(uhci, td);
866 869
867 /* Change direction for the status transaction */ 870 /* Change direction for the status transaction */
868 destination ^= (USB_PID_IN ^ USB_PID_OUT); 871 destination ^= (USB_PID_IN ^ USB_PID_OUT);
869 destination |= TD_TOKEN_TOGGLE; /* End in Data1 */ 872 destination |= TD_TOKEN_TOGGLE; /* End in Data1 */
870 873
871 uhci_add_td_to_urbp(td, urbp); 874 uhci_add_td_to_urbp(td, urbp);
872 uhci_fill_td(td, status | TD_CTRL_IOC, 875 uhci_fill_td(uhci, td, status | TD_CTRL_IOC,
873 destination | uhci_explen(0), 0); 876 destination | uhci_explen(0), 0);
874 plink = &td->link; 877 plink = &td->link;
875 878
@@ -879,11 +882,11 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
879 td = uhci_alloc_td(uhci); 882 td = uhci_alloc_td(uhci);
880 if (!td) 883 if (!td)
881 goto nomem; 884 goto nomem;
882 *plink = LINK_TO_TD(td); 885 *plink = LINK_TO_TD(uhci, td);
883 886
884 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); 887 uhci_fill_td(uhci, td, 0, USB_PID_OUT | uhci_explen(0), 0);
885 wmb(); 888 wmb();
886 qh->dummy_td->status |= cpu_to_le32(TD_CTRL_ACTIVE); 889 qh->dummy_td->status |= cpu_to_hc32(uhci, TD_CTRL_ACTIVE);
887 qh->dummy_td = td; 890 qh->dummy_td = td;
888 891
889 /* Low-speed transfers get a different queue, and won't hog the bus. 892 /* Low-speed transfers get a different queue, and won't hog the bus.
@@ -917,10 +920,13 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
917 unsigned long destination, status; 920 unsigned long destination, status;
918 int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize); 921 int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize);
919 int len = urb->transfer_buffer_length; 922 int len = urb->transfer_buffer_length;
920 dma_addr_t data = urb->transfer_dma; 923 int this_sg_len;
921 __le32 *plink; 924 dma_addr_t data;
925 __hc32 *plink;
922 struct urb_priv *urbp = urb->hcpriv; 926 struct urb_priv *urbp = urb->hcpriv;
923 unsigned int toggle; 927 unsigned int toggle;
928 struct scatterlist *sg;
929 int i;
924 930
925 if (len < 0) 931 if (len < 0)
926 return -EINVAL; 932 return -EINVAL;
@@ -937,12 +943,26 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
937 if (usb_pipein(urb->pipe)) 943 if (usb_pipein(urb->pipe))
938 status |= TD_CTRL_SPD; 944 status |= TD_CTRL_SPD;
939 945
946 i = urb->num_sgs;
947 if (len > 0 && i > 0) {
948 sg = urb->sg;
949 data = sg_dma_address(sg);
950
951 /* urb->transfer_buffer_length may be smaller than the
952 * size of the scatterlist (or vice versa)
953 */
954 this_sg_len = min_t(int, sg_dma_len(sg), len);
955 } else {
956 sg = NULL;
957 data = urb->transfer_dma;
958 this_sg_len = len;
959 }
940 /* 960 /*
941 * Build the DATA TDs 961 * Build the DATA TDs
942 */ 962 */
943 plink = NULL; 963 plink = NULL;
944 td = qh->dummy_td; 964 td = qh->dummy_td;
945 do { /* Allow zero length packets */ 965 for (;;) { /* Allow zero length packets */
946 int pktsze = maxsze; 966 int pktsze = maxsze;
947 967
948 if (len <= pktsze) { /* The last packet */ 968 if (len <= pktsze) { /* The last packet */
@@ -955,20 +975,28 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
955 td = uhci_alloc_td(uhci); 975 td = uhci_alloc_td(uhci);
956 if (!td) 976 if (!td)
957 goto nomem; 977 goto nomem;
958 *plink = LINK_TO_TD(td); 978 *plink = LINK_TO_TD(uhci, td);
959 } 979 }
960 uhci_add_td_to_urbp(td, urbp); 980 uhci_add_td_to_urbp(td, urbp);
961 uhci_fill_td(td, status, 981 uhci_fill_td(uhci, td, status,
962 destination | uhci_explen(pktsze) | 982 destination | uhci_explen(pktsze) |
963 (toggle << TD_TOKEN_TOGGLE_SHIFT), 983 (toggle << TD_TOKEN_TOGGLE_SHIFT),
964 data); 984 data);
965 plink = &td->link; 985 plink = &td->link;
966 status |= TD_CTRL_ACTIVE; 986 status |= TD_CTRL_ACTIVE;
967 987
988 toggle ^= 1;
968 data += pktsze; 989 data += pktsze;
990 this_sg_len -= pktsze;
969 len -= maxsze; 991 len -= maxsze;
970 toggle ^= 1; 992 if (this_sg_len <= 0) {
971 } while (len > 0); 993 if (--i <= 0 || len <= 0)
994 break;
995 sg = sg_next(sg);
996 data = sg_dma_address(sg);
997 this_sg_len = min_t(int, sg_dma_len(sg), len);
998 }
999 }
972 1000
973 /* 1001 /*
974 * URB_ZERO_PACKET means adding a 0-length packet, if direction 1002 * URB_ZERO_PACKET means adding a 0-length packet, if direction
@@ -983,10 +1011,10 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
983 td = uhci_alloc_td(uhci); 1011 td = uhci_alloc_td(uhci);
984 if (!td) 1012 if (!td)
985 goto nomem; 1013 goto nomem;
986 *plink = LINK_TO_TD(td); 1014 *plink = LINK_TO_TD(uhci, td);
987 1015
988 uhci_add_td_to_urbp(td, urbp); 1016 uhci_add_td_to_urbp(td, urbp);
989 uhci_fill_td(td, status, 1017 uhci_fill_td(uhci, td, status,
990 destination | uhci_explen(0) | 1018 destination | uhci_explen(0) |
991 (toggle << TD_TOKEN_TOGGLE_SHIFT), 1019 (toggle << TD_TOKEN_TOGGLE_SHIFT),
992 data); 1020 data);
@@ -1001,7 +1029,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
1001 * fast side but not enough to justify delaying an interrupt 1029 * fast side but not enough to justify delaying an interrupt
1002 * more than 2 or 3 URBs, so we will ignore the URB_NO_INTERRUPT 1030 * more than 2 or 3 URBs, so we will ignore the URB_NO_INTERRUPT
1003 * flag setting. */ 1031 * flag setting. */
1004 td->status |= cpu_to_le32(TD_CTRL_IOC); 1032 td->status |= cpu_to_hc32(uhci, TD_CTRL_IOC);
1005 1033
1006 /* 1034 /*
1007 * Build the new dummy TD and activate the old one 1035 * Build the new dummy TD and activate the old one
@@ -1009,11 +1037,11 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
1009 td = uhci_alloc_td(uhci); 1037 td = uhci_alloc_td(uhci);
1010 if (!td) 1038 if (!td)
1011 goto nomem; 1039 goto nomem;
1012 *plink = LINK_TO_TD(td); 1040 *plink = LINK_TO_TD(uhci, td);
1013 1041
1014 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); 1042 uhci_fill_td(uhci, td, 0, USB_PID_OUT | uhci_explen(0), 0);
1015 wmb(); 1043 wmb();
1016 qh->dummy_td->status |= cpu_to_le32(TD_CTRL_ACTIVE); 1044 qh->dummy_td->status |= cpu_to_hc32(uhci, TD_CTRL_ACTIVE);
1017 qh->dummy_td = td; 1045 qh->dummy_td = td;
1018 1046
1019 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), 1047 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
@@ -1106,7 +1134,7 @@ static int uhci_fixup_short_transfer(struct uhci_hcd *uhci,
1106 * the queue at the status stage transaction, which is 1134 * the queue at the status stage transaction, which is
1107 * the last TD. */ 1135 * the last TD. */
1108 WARN_ON(list_empty(&urbp->td_list)); 1136 WARN_ON(list_empty(&urbp->td_list));
1109 qh->element = LINK_TO_TD(td); 1137 qh->element = LINK_TO_TD(uhci, td);
1110 tmp = td->list.prev; 1138 tmp = td->list.prev;
1111 ret = -EINPROGRESS; 1139 ret = -EINPROGRESS;
1112 1140
@@ -1115,8 +1143,9 @@ static int uhci_fixup_short_transfer(struct uhci_hcd *uhci,
1115 /* When a bulk/interrupt transfer is short, we have to 1143 /* When a bulk/interrupt transfer is short, we have to
1116 * fix up the toggles of the following URBs on the queue 1144 * fix up the toggles of the following URBs on the queue
1117 * before restarting the queue at the next URB. */ 1145 * before restarting the queue at the next URB. */
1118 qh->initial_toggle = uhci_toggle(td_token(qh->post_td)) ^ 1; 1146 qh->initial_toggle =
1119 uhci_fixup_toggles(qh, 1); 1147 uhci_toggle(td_token(uhci, qh->post_td)) ^ 1;
1148 uhci_fixup_toggles(uhci, qh, 1);
1120 1149
1121 if (list_empty(&urbp->td_list)) 1150 if (list_empty(&urbp->td_list))
1122 td = qh->post_td; 1151 td = qh->post_td;
@@ -1151,7 +1180,7 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
1151 unsigned int ctrlstat; 1180 unsigned int ctrlstat;
1152 int len; 1181 int len;
1153 1182
1154 ctrlstat = td_status(td); 1183 ctrlstat = td_status(uhci, td);
1155 status = uhci_status_bits(ctrlstat); 1184 status = uhci_status_bits(ctrlstat);
1156 if (status & TD_CTRL_ACTIVE) 1185 if (status & TD_CTRL_ACTIVE)
1157 return -EINPROGRESS; 1186 return -EINPROGRESS;
@@ -1161,7 +1190,7 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
1161 1190
1162 if (status) { 1191 if (status) {
1163 ret = uhci_map_status(status, 1192 ret = uhci_map_status(status,
1164 uhci_packetout(td_token(td))); 1193 uhci_packetout(td_token(uhci, td)));
1165 if ((debug == 1 && ret != -EPIPE) || debug > 1) { 1194 if ((debug == 1 && ret != -EPIPE) || debug > 1) {
1166 /* Some debugging code */ 1195 /* Some debugging code */
1167 dev_dbg(&urb->dev->dev, 1196 dev_dbg(&urb->dev->dev,
@@ -1177,7 +1206,7 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
1177 } 1206 }
1178 1207
1179 /* Did we receive a short packet? */ 1208 /* Did we receive a short packet? */
1180 } else if (len < uhci_expected_length(td_token(td))) { 1209 } else if (len < uhci_expected_length(td_token(uhci, td))) {
1181 1210
1182 /* For control transfers, go to the status TD if 1211 /* For control transfers, go to the status TD if
1183 * this isn't already the last data TD */ 1212 * this isn't already the last data TD */
@@ -1209,10 +1238,10 @@ err:
1209 if (ret < 0) { 1238 if (ret < 0) {
1210 /* Note that the queue has stopped and save 1239 /* Note that the queue has stopped and save
1211 * the next toggle value */ 1240 * the next toggle value */
1212 qh->element = UHCI_PTR_TERM; 1241 qh->element = UHCI_PTR_TERM(uhci);
1213 qh->is_stopped = 1; 1242 qh->is_stopped = 1;
1214 qh->needs_fixup = (qh->type != USB_ENDPOINT_XFER_CONTROL); 1243 qh->needs_fixup = (qh->type != USB_ENDPOINT_XFER_CONTROL);
1215 qh->initial_toggle = uhci_toggle(td_token(td)) ^ 1244 qh->initial_toggle = uhci_toggle(td_token(uhci, td)) ^
1216 (ret == -EREMOTEIO); 1245 (ret == -EREMOTEIO);
1217 1246
1218 } else /* Short packet received */ 1247 } else /* Short packet received */
@@ -1308,14 +1337,14 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb,
1308 return -ENOMEM; 1337 return -ENOMEM;
1309 1338
1310 uhci_add_td_to_urbp(td, urbp); 1339 uhci_add_td_to_urbp(td, urbp);
1311 uhci_fill_td(td, status, destination | 1340 uhci_fill_td(uhci, td, status, destination |
1312 uhci_explen(urb->iso_frame_desc[i].length), 1341 uhci_explen(urb->iso_frame_desc[i].length),
1313 urb->transfer_dma + 1342 urb->transfer_dma +
1314 urb->iso_frame_desc[i].offset); 1343 urb->iso_frame_desc[i].offset);
1315 } 1344 }
1316 1345
1317 /* Set the interrupt-on-completion flag on the last packet. */ 1346 /* Set the interrupt-on-completion flag on the last packet. */
1318 td->status |= cpu_to_le32(TD_CTRL_IOC); 1347 td->status |= cpu_to_hc32(uhci, TD_CTRL_IOC);
1319 1348
1320 /* Add the TDs to the frame list */ 1349 /* Add the TDs to the frame list */
1321 frame = urb->start_frame; 1350 frame = urb->start_frame;
@@ -1351,7 +1380,7 @@ static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1351 1380
1352 uhci_remove_tds_from_frame(uhci, qh->iso_frame); 1381 uhci_remove_tds_from_frame(uhci, qh->iso_frame);
1353 1382
1354 ctrlstat = td_status(td); 1383 ctrlstat = td_status(uhci, td);
1355 if (ctrlstat & TD_CTRL_ACTIVE) { 1384 if (ctrlstat & TD_CTRL_ACTIVE) {
1356 status = -EXDEV; /* TD was added too late? */ 1385 status = -EXDEV; /* TD was added too late? */
1357 } else { 1386 } else {
@@ -1602,7 +1631,7 @@ restart:
1602 * queue, the QH can now be re-activated. */ 1631 * queue, the QH can now be re-activated. */
1603 if (!list_empty(&qh->queue)) { 1632 if (!list_empty(&qh->queue)) {
1604 if (qh->needs_fixup) 1633 if (qh->needs_fixup)
1605 uhci_fixup_toggles(qh, 0); 1634 uhci_fixup_toggles(uhci, qh, 0);
1606 1635
1607 /* If the first URB on the queue wants FSBR but its time 1636 /* If the first URB on the queue wants FSBR but its time
1608 * limit has expired, set the next TD to interrupt on 1637 * limit has expired, set the next TD to interrupt on
@@ -1612,7 +1641,7 @@ restart:
1612 struct uhci_td *td = list_entry(urbp->td_list.next, 1641 struct uhci_td *td = list_entry(urbp->td_list.next,
1613 struct uhci_td, list); 1642 struct uhci_td, list);
1614 1643
1615 td->status |= __cpu_to_le32(TD_CTRL_IOC); 1644 td->status |= cpu_to_hc32(uhci, TD_CTRL_IOC);
1616 } 1645 }
1617 1646
1618 uhci_activate_qh(uhci, qh); 1647 uhci_activate_qh(uhci, qh);
@@ -1659,7 +1688,7 @@ static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh)
1659 } else { 1688 } else {
1660 urbp = list_entry(qh->queue.next, struct urb_priv, node); 1689 urbp = list_entry(qh->queue.next, struct urb_priv, node);
1661 td = list_entry(urbp->td_list.next, struct uhci_td, list); 1690 td = list_entry(urbp->td_list.next, struct uhci_td, list);
1662 status = td_status(td); 1691 status = td_status(uhci, td);
1663 if (!(status & TD_CTRL_ACTIVE)) { 1692 if (!(status & TD_CTRL_ACTIVE)) {
1664 1693
1665 /* We're okay, the queue has advanced */ 1694 /* We're okay, the queue has advanced */
@@ -1677,7 +1706,8 @@ static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh)
1677 if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) { 1706 if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) {
1678 1707
1679 /* Detect the Intel bug and work around it */ 1708 /* Detect the Intel bug and work around it */
1680 if (qh->post_td && qh_element(qh) == LINK_TO_TD(qh->post_td)) { 1709 if (qh->post_td && qh_element(qh) ==
1710 LINK_TO_TD(uhci, qh->post_td)) {
1681 qh->element = qh->post_td->link; 1711 qh->element = qh->post_td->link;
1682 qh->advance_jiffies = jiffies; 1712 qh->advance_jiffies = jiffies;
1683 ret = 1; 1713 ret = 1;
diff --git a/drivers/usb/host/whci/Kbuild b/drivers/usb/host/whci/Kbuild
index 11e5040b8337..26df0138079e 100644
--- a/drivers/usb/host/whci/Kbuild
+++ b/drivers/usb/host/whci/Kbuild
@@ -3,7 +3,7 @@ obj-$(CONFIG_USB_WHCI_HCD) += whci-hcd.o
3whci-hcd-y := \ 3whci-hcd-y := \
4 asl.o \ 4 asl.o \
5 debug.o \ 5 debug.o \
6 hcd.o \ 6 hcd.o \
7 hw.o \ 7 hw.o \
8 init.o \ 8 init.o \
9 int.o \ 9 int.o \
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index 72b6892fda67..9546f6cd01f0 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -356,7 +356,7 @@ static void __exit whci_hc_driver_exit(void)
356module_exit(whci_hc_driver_exit); 356module_exit(whci_hc_driver_exit);
357 357
358/* PCI device ID's that we handle (so it gets loaded) */ 358/* PCI device ID's that we handle (so it gets loaded) */
359static struct pci_device_id whci_hcd_id_table[] = { 359static struct pci_device_id __used whci_hcd_id_table[] = {
360 { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) }, 360 { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) },
361 { /* empty last entry */ } 361 { /* empty last entry */ }
362}; 362};
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
index dc0ab8382f5d..d6e175428618 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -739,7 +739,7 @@ static int get_urb_status_from_qtd(struct urb *urb, u32 status)
739 * process_inactive_qtd - process an inactive (but not halted) qTD. 739 * process_inactive_qtd - process an inactive (but not halted) qTD.
740 * 740 *
741 * Update the urb with the transfer bytes from the qTD, if the urb is 741 * Update the urb with the transfer bytes from the qTD, if the urb is
742 * completely transfered or (in the case of an IN only) the LPF is 742 * completely transferred or (in the case of an IN only) the LPF is
743 * set, then the transfer is complete and the urb should be returned 743 * set, then the transfer is complete and the urb should be returned
744 * to the system. 744 * to the system.
745 */ 745 */
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index fcbf4abbf381..1f50b4468e87 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -147,7 +147,7 @@ static void xhci_print_op_regs(struct xhci_hcd *xhci)
147 147
148static void xhci_print_ports(struct xhci_hcd *xhci) 148static void xhci_print_ports(struct xhci_hcd *xhci)
149{ 149{
150 u32 __iomem *addr; 150 __le32 __iomem *addr;
151 int i, j; 151 int i, j;
152 int ports; 152 int ports;
153 char *names[NUM_PORT_REGS] = { 153 char *names[NUM_PORT_REGS] = {
@@ -169,9 +169,10 @@ static void xhci_print_ports(struct xhci_hcd *xhci)
169 } 169 }
170} 170}
171 171
172void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num) 172void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num)
173{ 173{
174 void *addr; 174 struct xhci_intr_reg __iomem *ir_set = &xhci->run_regs->ir_set[set_num];
175 void __iomem *addr;
175 u32 temp; 176 u32 temp;
176 u64 temp_64; 177 u64 temp_64;
177 178
@@ -252,27 +253,27 @@ void xhci_print_trb_offsets(struct xhci_hcd *xhci, union xhci_trb *trb)
252void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb) 253void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb)
253{ 254{
254 u64 address; 255 u64 address;
255 u32 type = xhci_readl(xhci, &trb->link.control) & TRB_TYPE_BITMASK; 256 u32 type = le32_to_cpu(trb->link.control) & TRB_TYPE_BITMASK;
256 257
257 switch (type) { 258 switch (type) {
258 case TRB_TYPE(TRB_LINK): 259 case TRB_TYPE(TRB_LINK):
259 xhci_dbg(xhci, "Link TRB:\n"); 260 xhci_dbg(xhci, "Link TRB:\n");
260 xhci_print_trb_offsets(xhci, trb); 261 xhci_print_trb_offsets(xhci, trb);
261 262
262 address = trb->link.segment_ptr; 263 address = le64_to_cpu(trb->link.segment_ptr);
263 xhci_dbg(xhci, "Next ring segment DMA address = 0x%llx\n", address); 264 xhci_dbg(xhci, "Next ring segment DMA address = 0x%llx\n", address);
264 265
265 xhci_dbg(xhci, "Interrupter target = 0x%x\n", 266 xhci_dbg(xhci, "Interrupter target = 0x%x\n",
266 GET_INTR_TARGET(trb->link.intr_target)); 267 GET_INTR_TARGET(le32_to_cpu(trb->link.intr_target)));
267 xhci_dbg(xhci, "Cycle bit = %u\n", 268 xhci_dbg(xhci, "Cycle bit = %u\n",
268 (unsigned int) (trb->link.control & TRB_CYCLE)); 269 (unsigned int) (le32_to_cpu(trb->link.control) & TRB_CYCLE));
269 xhci_dbg(xhci, "Toggle cycle bit = %u\n", 270 xhci_dbg(xhci, "Toggle cycle bit = %u\n",
270 (unsigned int) (trb->link.control & LINK_TOGGLE)); 271 (unsigned int) (le32_to_cpu(trb->link.control) & LINK_TOGGLE));
271 xhci_dbg(xhci, "No Snoop bit = %u\n", 272 xhci_dbg(xhci, "No Snoop bit = %u\n",
272 (unsigned int) (trb->link.control & TRB_NO_SNOOP)); 273 (unsigned int) (le32_to_cpu(trb->link.control) & TRB_NO_SNOOP));
273 break; 274 break;
274 case TRB_TYPE(TRB_TRANSFER): 275 case TRB_TYPE(TRB_TRANSFER):
275 address = trb->trans_event.buffer; 276 address = le64_to_cpu(trb->trans_event.buffer);
276 /* 277 /*
277 * FIXME: look at flags to figure out if it's an address or if 278 * FIXME: look at flags to figure out if it's an address or if
278 * the data is directly in the buffer field. 279 * the data is directly in the buffer field.
@@ -280,11 +281,12 @@ void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb)
280 xhci_dbg(xhci, "DMA address or buffer contents= %llu\n", address); 281 xhci_dbg(xhci, "DMA address or buffer contents= %llu\n", address);
281 break; 282 break;
282 case TRB_TYPE(TRB_COMPLETION): 283 case TRB_TYPE(TRB_COMPLETION):
283 address = trb->event_cmd.cmd_trb; 284 address = le64_to_cpu(trb->event_cmd.cmd_trb);
284 xhci_dbg(xhci, "Command TRB pointer = %llu\n", address); 285 xhci_dbg(xhci, "Command TRB pointer = %llu\n", address);
285 xhci_dbg(xhci, "Completion status = %u\n", 286 xhci_dbg(xhci, "Completion status = %u\n",
286 (unsigned int) GET_COMP_CODE(trb->event_cmd.status)); 287 (unsigned int) GET_COMP_CODE(le32_to_cpu(trb->event_cmd.status)));
287 xhci_dbg(xhci, "Flags = 0x%x\n", (unsigned int) trb->event_cmd.flags); 288 xhci_dbg(xhci, "Flags = 0x%x\n",
289 (unsigned int) le32_to_cpu(trb->event_cmd.flags));
288 break; 290 break;
289 default: 291 default:
290 xhci_dbg(xhci, "Unknown TRB with TRB type ID %u\n", 292 xhci_dbg(xhci, "Unknown TRB with TRB type ID %u\n",
@@ -310,16 +312,16 @@ void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb)
310void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg) 312void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg)
311{ 313{
312 int i; 314 int i;
313 u32 addr = (u32) seg->dma; 315 u64 addr = seg->dma;
314 union xhci_trb *trb = seg->trbs; 316 union xhci_trb *trb = seg->trbs;
315 317
316 for (i = 0; i < TRBS_PER_SEGMENT; ++i) { 318 for (i = 0; i < TRBS_PER_SEGMENT; ++i) {
317 trb = &seg->trbs[i]; 319 trb = &seg->trbs[i];
318 xhci_dbg(xhci, "@%08x %08x %08x %08x %08x\n", addr, 320 xhci_dbg(xhci, "@%016llx %08x %08x %08x %08x\n", addr,
319 lower_32_bits(trb->link.segment_ptr), 321 (u32)lower_32_bits(le64_to_cpu(trb->link.segment_ptr)),
320 upper_32_bits(trb->link.segment_ptr), 322 (u32)upper_32_bits(le64_to_cpu(trb->link.segment_ptr)),
321 (unsigned int) trb->link.intr_target, 323 (unsigned int) le32_to_cpu(trb->link.intr_target),
322 (unsigned int) trb->link.control); 324 (unsigned int) le32_to_cpu(trb->link.control));
323 addr += sizeof(*trb); 325 addr += sizeof(*trb);
324 } 326 }
325} 327}
@@ -390,18 +392,18 @@ void xhci_dbg_ep_rings(struct xhci_hcd *xhci,
390 392
391void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst) 393void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
392{ 394{
393 u32 addr = (u32) erst->erst_dma_addr; 395 u64 addr = erst->erst_dma_addr;
394 int i; 396 int i;
395 struct xhci_erst_entry *entry; 397 struct xhci_erst_entry *entry;
396 398
397 for (i = 0; i < erst->num_entries; ++i) { 399 for (i = 0; i < erst->num_entries; ++i) {
398 entry = &erst->entries[i]; 400 entry = &erst->entries[i];
399 xhci_dbg(xhci, "@%08x %08x %08x %08x %08x\n", 401 xhci_dbg(xhci, "@%016llx %08x %08x %08x %08x\n",
400 (unsigned int) addr, 402 addr,
401 lower_32_bits(entry->seg_addr), 403 lower_32_bits(le64_to_cpu(entry->seg_addr)),
402 upper_32_bits(entry->seg_addr), 404 upper_32_bits(le64_to_cpu(entry->seg_addr)),
403 (unsigned int) entry->seg_size, 405 (unsigned int) le32_to_cpu(entry->seg_size),
404 (unsigned int) entry->rsvd); 406 (unsigned int) le32_to_cpu(entry->rsvd));
405 addr += sizeof(*entry); 407 addr += sizeof(*entry);
406 } 408 }
407} 409}
@@ -435,21 +437,21 @@ char *xhci_get_slot_state(struct xhci_hcd *xhci,
435{ 437{
436 struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx); 438 struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx);
437 439
438 switch (GET_SLOT_STATE(slot_ctx->dev_state)) { 440 switch (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state))) {
439 case 0: 441 case SLOT_STATE_ENABLED:
440 return "enabled/disabled"; 442 return "enabled/disabled";
441 case 1: 443 case SLOT_STATE_DEFAULT:
442 return "default"; 444 return "default";
443 case 2: 445 case SLOT_STATE_ADDRESSED:
444 return "addressed"; 446 return "addressed";
445 case 3: 447 case SLOT_STATE_CONFIGURED:
446 return "configured"; 448 return "configured";
447 default: 449 default:
448 return "reserved"; 450 return "reserved";
449 } 451 }
450} 452}
451 453
452void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx) 454static void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx)
453{ 455{
454 /* Fields are 32 bits wide, DMA addresses are in bytes */ 456 /* Fields are 32 bits wide, DMA addresses are in bytes */
455 int field_size = 32 / 8; 457 int field_size = 32 / 8;
@@ -488,7 +490,7 @@ void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx)
488 dbg_rsvd64(xhci, (u64 *)slot_ctx, dma); 490 dbg_rsvd64(xhci, (u64 *)slot_ctx, dma);
489} 491}
490 492
491void xhci_dbg_ep_ctx(struct xhci_hcd *xhci, 493static void xhci_dbg_ep_ctx(struct xhci_hcd *xhci,
492 struct xhci_container_ctx *ctx, 494 struct xhci_container_ctx *ctx,
493 unsigned int last_ep) 495 unsigned int last_ep)
494{ 496{
diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h
index 78c4edac1db1..ce5c9e51748e 100644
--- a/drivers/usb/host/xhci-ext-caps.h
+++ b/drivers/usb/host/xhci-ext-caps.h
@@ -19,8 +19,8 @@
19 * along with this program; if not, write to the Free Software Foundation, 19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22/* Up to 16 microframes to halt an HC - one microframe is 125 microsectonds */ 22/* Up to 16 ms to halt an HC */
23#define XHCI_MAX_HALT_USEC (16*125) 23#define XHCI_MAX_HALT_USEC (16*1000)
24/* HC not running - set to 1 when run/stop bit is cleared. */ 24/* HC not running - set to 1 when run/stop bit is cleared. */
25#define XHCI_STS_HALT (1<<0) 25#define XHCI_STS_HALT (1<<0)
26 26
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index a1a7a9795536..0be788cc2fdb 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -24,27 +24,19 @@
24 24
25#include "xhci.h" 25#include "xhci.h"
26 26
27static void xhci_hub_descriptor(struct xhci_hcd *xhci, 27#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E)
28 struct usb_hub_descriptor *desc) 28#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
29 PORT_RC | PORT_PLC | PORT_PE)
30
31static void xhci_common_hub_descriptor(struct xhci_hcd *xhci,
32 struct usb_hub_descriptor *desc, int ports)
29{ 33{
30 int ports;
31 u16 temp; 34 u16 temp;
32 35
33 ports = HCS_MAX_PORTS(xhci->hcs_params1);
34
35 /* USB 3.0 hubs have a different descriptor, but we fake this for now */
36 desc->bDescriptorType = 0x29;
37 desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.9 says 20ms max */ 36 desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.9 says 20ms max */
38 desc->bHubContrCurrent = 0; 37 desc->bHubContrCurrent = 0;
39 38
40 desc->bNbrPorts = ports; 39 desc->bNbrPorts = ports;
41 temp = 1 + (ports / 8);
42 desc->bDescLength = 7 + 2 * temp;
43
44 /* Why does core/hcd.h define bitmap? It's just confusing. */
45 memset(&desc->DeviceRemovable[0], 0, temp);
46 memset(&desc->DeviceRemovable[temp], 0xff, temp);
47
48 /* Ugh, these should be #defines, FIXME */ 40 /* Ugh, these should be #defines, FIXME */
49 /* Using table 11-13 in USB 2.0 spec. */ 41 /* Using table 11-13 in USB 2.0 spec. */
50 temp = 0; 42 temp = 0;
@@ -58,7 +50,103 @@ static void xhci_hub_descriptor(struct xhci_hcd *xhci,
58 temp |= 0x0008; 50 temp |= 0x0008;
59 /* Bits 6:5 - no TTs in root ports */ 51 /* Bits 6:5 - no TTs in root ports */
60 /* Bit 7 - no port indicators */ 52 /* Bit 7 - no port indicators */
61 desc->wHubCharacteristics = (__force __u16) cpu_to_le16(temp); 53 desc->wHubCharacteristics = cpu_to_le16(temp);
54}
55
56/* Fill in the USB 2.0 roothub descriptor */
57static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
58 struct usb_hub_descriptor *desc)
59{
60 int ports;
61 u16 temp;
62 __u8 port_removable[(USB_MAXCHILDREN + 1 + 7) / 8];
63 u32 portsc;
64 unsigned int i;
65
66 ports = xhci->num_usb2_ports;
67
68 xhci_common_hub_descriptor(xhci, desc, ports);
69 desc->bDescriptorType = 0x29;
70 temp = 1 + (ports / 8);
71 desc->bDescLength = 7 + 2 * temp;
72
73 /* The Device Removable bits are reported on a byte granularity.
74 * If the port doesn't exist within that byte, the bit is set to 0.
75 */
76 memset(port_removable, 0, sizeof(port_removable));
77 for (i = 0; i < ports; i++) {
78 portsc = xhci_readl(xhci, xhci->usb3_ports[i]);
79 /* If a device is removable, PORTSC reports a 0, same as in the
80 * hub descriptor DeviceRemovable bits.
81 */
82 if (portsc & PORT_DEV_REMOVE)
83 /* This math is hairy because bit 0 of DeviceRemovable
84 * is reserved, and bit 1 is for port 1, etc.
85 */
86 port_removable[(i + 1) / 8] |= 1 << ((i + 1) % 8);
87 }
88
89 /* ch11.h defines a hub descriptor that has room for USB_MAXCHILDREN
90 * ports on it. The USB 2.0 specification says that there are two
91 * variable length fields at the end of the hub descriptor:
92 * DeviceRemovable and PortPwrCtrlMask. But since we can have less than
93 * USB_MAXCHILDREN ports, we may need to use the DeviceRemovable array
94 * to set PortPwrCtrlMask bits. PortPwrCtrlMask must always be set to
95 * 0xFF, so we initialize the both arrays (DeviceRemovable and
96 * PortPwrCtrlMask) to 0xFF. Then we set the DeviceRemovable for each
97 * set of ports that actually exist.
98 */
99 memset(desc->u.hs.DeviceRemovable, 0xff,
100 sizeof(desc->u.hs.DeviceRemovable));
101 memset(desc->u.hs.PortPwrCtrlMask, 0xff,
102 sizeof(desc->u.hs.PortPwrCtrlMask));
103
104 for (i = 0; i < (ports + 1 + 7) / 8; i++)
105 memset(&desc->u.hs.DeviceRemovable[i], port_removable[i],
106 sizeof(__u8));
107}
108
109/* Fill in the USB 3.0 roothub descriptor */
110static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
111 struct usb_hub_descriptor *desc)
112{
113 int ports;
114 u16 port_removable;
115 u32 portsc;
116 unsigned int i;
117
118 ports = xhci->num_usb3_ports;
119 xhci_common_hub_descriptor(xhci, desc, ports);
120 desc->bDescriptorType = 0x2a;
121 desc->bDescLength = 12;
122
123 /* header decode latency should be zero for roothubs,
124 * see section 4.23.5.2.
125 */
126 desc->u.ss.bHubHdrDecLat = 0;
127 desc->u.ss.wHubDelay = 0;
128
129 port_removable = 0;
130 /* bit 0 is reserved, bit 1 is for port 1, etc. */
131 for (i = 0; i < ports; i++) {
132 portsc = xhci_readl(xhci, xhci->usb3_ports[i]);
133 if (portsc & PORT_DEV_REMOVE)
134 port_removable |= 1 << (i + 1);
135 }
136 memset(&desc->u.ss.DeviceRemovable,
137 (__force __u16) cpu_to_le16(port_removable),
138 sizeof(__u16));
139}
140
141static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
142 struct usb_hub_descriptor *desc)
143{
144
145 if (hcd->speed == HCD_USB3)
146 xhci_usb3_hub_descriptor(hcd, xhci, desc);
147 else
148 xhci_usb2_hub_descriptor(hcd, xhci, desc);
149
62} 150}
63 151
64static unsigned int xhci_port_speed(unsigned int port_status) 152static unsigned int xhci_port_speed(unsigned int port_status)
@@ -67,8 +155,6 @@ static unsigned int xhci_port_speed(unsigned int port_status)
67 return USB_PORT_STAT_LOW_SPEED; 155 return USB_PORT_STAT_LOW_SPEED;
68 if (DEV_HIGHSPEED(port_status)) 156 if (DEV_HIGHSPEED(port_status))
69 return USB_PORT_STAT_HIGH_SPEED; 157 return USB_PORT_STAT_HIGH_SPEED;
70 if (DEV_SUPERSPEED(port_status))
71 return USB_PORT_STAT_SUPER_SPEED;
72 /* 158 /*
73 * FIXME: Yes, we should check for full speed, but the core uses that as 159 * FIXME: Yes, we should check for full speed, but the core uses that as
74 * a default in portspeed() in usb/core/hub.c (which is the only place 160 * a default in portspeed() in usb/core/hub.c (which is the only place
@@ -123,15 +209,120 @@ static unsigned int xhci_port_speed(unsigned int port_status)
123 * writing a 0 clears the bit and writing a 1 sets the bit (RWS). 209 * writing a 0 clears the bit and writing a 1 sets the bit (RWS).
124 * For all other types (RW1S, RW1CS, RW, and RZ), writing a '0' has no effect. 210 * For all other types (RW1S, RW1CS, RW, and RZ), writing a '0' has no effect.
125 */ 211 */
126static u32 xhci_port_state_to_neutral(u32 state) 212u32 xhci_port_state_to_neutral(u32 state)
127{ 213{
128 /* Save read-only status and port state */ 214 /* Save read-only status and port state */
129 return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS); 215 return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS);
130} 216}
131 217
132static void xhci_disable_port(struct xhci_hcd *xhci, u16 wIndex, 218/*
133 u32 __iomem *addr, u32 port_status) 219 * find slot id based on port number.
220 * @port: The one-based port number from one of the two split roothubs.
221 */
222int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
223 u16 port)
224{
225 int slot_id;
226 int i;
227 enum usb_device_speed speed;
228
229 slot_id = 0;
230 for (i = 0; i < MAX_HC_SLOTS; i++) {
231 if (!xhci->devs[i])
232 continue;
233 speed = xhci->devs[i]->udev->speed;
234 if (((speed == USB_SPEED_SUPER) == (hcd->speed == HCD_USB3))
235 && xhci->devs[i]->port == port) {
236 slot_id = i;
237 break;
238 }
239 }
240
241 return slot_id;
242}
243
244/*
245 * Stop device
246 * It issues stop endpoint command for EP 0 to 30. And wait the last command
247 * to complete.
248 * suspend will set to 1, if suspend bit need to set in command.
249 */
250static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
251{
252 struct xhci_virt_device *virt_dev;
253 struct xhci_command *cmd;
254 unsigned long flags;
255 int timeleft;
256 int ret;
257 int i;
258
259 ret = 0;
260 virt_dev = xhci->devs[slot_id];
261 cmd = xhci_alloc_command(xhci, false, true, GFP_NOIO);
262 if (!cmd) {
263 xhci_dbg(xhci, "Couldn't allocate command structure.\n");
264 return -ENOMEM;
265 }
266
267 spin_lock_irqsave(&xhci->lock, flags);
268 for (i = LAST_EP_INDEX; i > 0; i--) {
269 if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue)
270 xhci_queue_stop_endpoint(xhci, slot_id, i, suspend);
271 }
272 cmd->command_trb = xhci->cmd_ring->enqueue;
273 list_add_tail(&cmd->cmd_list, &virt_dev->cmd_list);
274 xhci_queue_stop_endpoint(xhci, slot_id, 0, suspend);
275 xhci_ring_cmd_db(xhci);
276 spin_unlock_irqrestore(&xhci->lock, flags);
277
278 /* Wait for last stop endpoint command to finish */
279 timeleft = wait_for_completion_interruptible_timeout(
280 cmd->completion,
281 USB_CTRL_SET_TIMEOUT);
282 if (timeleft <= 0) {
283 xhci_warn(xhci, "%s while waiting for stop endpoint command\n",
284 timeleft == 0 ? "Timeout" : "Signal");
285 spin_lock_irqsave(&xhci->lock, flags);
286 /* The timeout might have raced with the event ring handler, so
287 * only delete from the list if the item isn't poisoned.
288 */
289 if (cmd->cmd_list.next != LIST_POISON1)
290 list_del(&cmd->cmd_list);
291 spin_unlock_irqrestore(&xhci->lock, flags);
292 ret = -ETIME;
293 goto command_cleanup;
294 }
295
296command_cleanup:
297 xhci_free_command(xhci, cmd);
298 return ret;
299}
300
301/*
302 * Ring device, it rings the all doorbells unconditionally.
303 */
304void xhci_ring_device(struct xhci_hcd *xhci, int slot_id)
305{
306 int i;
307
308 for (i = 0; i < LAST_EP_INDEX + 1; i++)
309 if (xhci->devs[slot_id]->eps[i].ring &&
310 xhci->devs[slot_id]->eps[i].ring->dequeue)
311 xhci_ring_ep_doorbell(xhci, slot_id, i, 0);
312
313 return;
314}
315
316static void xhci_disable_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
317 u16 wIndex, __le32 __iomem *addr, u32 port_status)
134{ 318{
319 /* Don't allow the USB core to disable SuperSpeed ports. */
320 if (hcd->speed == HCD_USB3) {
321 xhci_dbg(xhci, "Ignoring request to disable "
322 "SuperSpeed port.\n");
323 return;
324 }
325
135 /* Write 1 to disable the port */ 326 /* Write 1 to disable the port */
136 xhci_writel(xhci, port_status | PORT_PE, addr); 327 xhci_writel(xhci, port_status | PORT_PE, addr);
137 port_status = xhci_readl(xhci, addr); 328 port_status = xhci_readl(xhci, addr);
@@ -140,7 +331,7 @@ static void xhci_disable_port(struct xhci_hcd *xhci, u16 wIndex,
140} 331}
141 332
142static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue, 333static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
143 u16 wIndex, u32 __iomem *addr, u32 port_status) 334 u16 wIndex, __le32 __iomem *addr, u32 port_status)
144{ 335{
145 char *port_change_bit; 336 char *port_change_bit;
146 u32 status; 337 u32 status;
@@ -150,6 +341,10 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
150 status = PORT_RC; 341 status = PORT_RC;
151 port_change_bit = "reset"; 342 port_change_bit = "reset";
152 break; 343 break;
344 case USB_PORT_FEAT_C_BH_PORT_RESET:
345 status = PORT_WRC;
346 port_change_bit = "warm(BH) reset";
347 break;
153 case USB_PORT_FEAT_C_CONNECTION: 348 case USB_PORT_FEAT_C_CONNECTION:
154 status = PORT_CSC; 349 status = PORT_CSC;
155 port_change_bit = "connect"; 350 port_change_bit = "connect";
@@ -162,6 +357,14 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
162 status = PORT_PEC; 357 status = PORT_PEC;
163 port_change_bit = "enable/disable"; 358 port_change_bit = "enable/disable";
164 break; 359 break;
360 case USB_PORT_FEAT_C_SUSPEND:
361 status = PORT_PLC;
362 port_change_bit = "suspend/resume";
363 break;
364 case USB_PORT_FEAT_C_PORT_LINK_STATE:
365 status = PORT_PLC;
366 port_change_bit = "link state";
367 break;
165 default: 368 default:
166 /* Should never happen */ 369 /* Should never happen */
167 return; 370 return;
@@ -173,17 +376,37 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
173 port_change_bit, wIndex, port_status); 376 port_change_bit, wIndex, port_status);
174} 377}
175 378
379static int xhci_get_ports(struct usb_hcd *hcd, __le32 __iomem ***port_array)
380{
381 int max_ports;
382 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
383
384 if (hcd->speed == HCD_USB3) {
385 max_ports = xhci->num_usb3_ports;
386 *port_array = xhci->usb3_ports;
387 } else {
388 max_ports = xhci->num_usb2_ports;
389 *port_array = xhci->usb2_ports;
390 }
391
392 return max_ports;
393}
394
176int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 395int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
177 u16 wIndex, char *buf, u16 wLength) 396 u16 wIndex, char *buf, u16 wLength)
178{ 397{
179 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 398 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
180 int ports; 399 int max_ports;
181 unsigned long flags; 400 unsigned long flags;
182 u32 temp, status; 401 u32 temp, temp1, status;
183 int retval = 0; 402 int retval = 0;
184 u32 __iomem *addr; 403 __le32 __iomem **port_array;
404 int slot_id;
405 struct xhci_bus_state *bus_state;
406 u16 link_state = 0;
185 407
186 ports = HCS_MAX_PORTS(xhci->hcs_params1); 408 max_ports = xhci_get_ports(hcd, &port_array);
409 bus_state = &xhci->bus_state[hcd_index(hcd)];
187 410
188 spin_lock_irqsave(&xhci->lock, flags); 411 spin_lock_irqsave(&xhci->lock, flags);
189 switch (typeReq) { 412 switch (typeReq) {
@@ -192,15 +415,30 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
192 memset(buf, 0, 4); 415 memset(buf, 0, 4);
193 break; 416 break;
194 case GetHubDescriptor: 417 case GetHubDescriptor:
195 xhci_hub_descriptor(xhci, (struct usb_hub_descriptor *) buf); 418 /* Check to make sure userspace is asking for the USB 3.0 hub
419 * descriptor for the USB 3.0 roothub. If not, we stall the
420 * endpoint, like external hubs do.
421 */
422 if (hcd->speed == HCD_USB3 &&
423 (wLength < USB_DT_SS_HUB_SIZE ||
424 wValue != (USB_DT_SS_HUB << 8))) {
425 xhci_dbg(xhci, "Wrong hub descriptor type for "
426 "USB 3.0 roothub.\n");
427 goto error;
428 }
429 xhci_hub_descriptor(hcd, xhci,
430 (struct usb_hub_descriptor *) buf);
196 break; 431 break;
197 case GetPortStatus: 432 case GetPortStatus:
198 if (!wIndex || wIndex > ports) 433 if (!wIndex || wIndex > max_ports)
199 goto error; 434 goto error;
200 wIndex--; 435 wIndex--;
201 status = 0; 436 status = 0;
202 addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS*(wIndex & 0xff); 437 temp = xhci_readl(xhci, port_array[wIndex]);
203 temp = xhci_readl(xhci, addr); 438 if (temp == 0xffffffff) {
439 retval = -ENODEV;
440 break;
441 }
204 xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n", wIndex, temp); 442 xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n", wIndex, temp);
205 443
206 /* wPortChange bits */ 444 /* wPortChange bits */
@@ -210,10 +448,54 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
210 status |= USB_PORT_STAT_C_ENABLE << 16; 448 status |= USB_PORT_STAT_C_ENABLE << 16;
211 if ((temp & PORT_OCC)) 449 if ((temp & PORT_OCC))
212 status |= USB_PORT_STAT_C_OVERCURRENT << 16; 450 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
213 /* 451 if ((temp & PORT_RC))
214 * FIXME ignoring suspend, reset, and USB 2.1/3.0 specific 452 status |= USB_PORT_STAT_C_RESET << 16;
215 * changes 453 /* USB3.0 only */
216 */ 454 if (hcd->speed == HCD_USB3) {
455 if ((temp & PORT_PLC))
456 status |= USB_PORT_STAT_C_LINK_STATE << 16;
457 if ((temp & PORT_WRC))
458 status |= USB_PORT_STAT_C_BH_RESET << 16;
459 }
460
461 if (hcd->speed != HCD_USB3) {
462 if ((temp & PORT_PLS_MASK) == XDEV_U3
463 && (temp & PORT_POWER))
464 status |= USB_PORT_STAT_SUSPEND;
465 }
466 if ((temp & PORT_PLS_MASK) == XDEV_RESUME) {
467 if ((temp & PORT_RESET) || !(temp & PORT_PE))
468 goto error;
469 if (!DEV_SUPERSPEED(temp) && time_after_eq(jiffies,
470 bus_state->resume_done[wIndex])) {
471 xhci_dbg(xhci, "Resume USB2 port %d\n",
472 wIndex + 1);
473 bus_state->resume_done[wIndex] = 0;
474 temp1 = xhci_port_state_to_neutral(temp);
475 temp1 &= ~PORT_PLS_MASK;
476 temp1 |= PORT_LINK_STROBE | XDEV_U0;
477 xhci_writel(xhci, temp1, port_array[wIndex]);
478
479 xhci_dbg(xhci, "set port %d resume\n",
480 wIndex + 1);
481 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
482 wIndex + 1);
483 if (!slot_id) {
484 xhci_dbg(xhci, "slot_id is zero\n");
485 goto error;
486 }
487 xhci_ring_device(xhci, slot_id);
488 bus_state->port_c_suspend |= 1 << wIndex;
489 bus_state->suspended_ports &= ~(1 << wIndex);
490 }
491 }
492 if ((temp & PORT_PLS_MASK) == XDEV_U0
493 && (temp & PORT_POWER)
494 && (bus_state->suspended_ports & (1 << wIndex))) {
495 bus_state->suspended_ports &= ~(1 << wIndex);
496 if (hcd->speed != HCD_USB3)
497 bus_state->port_c_suspend |= 1 << wIndex;
498 }
217 if (temp & PORT_CONNECT) { 499 if (temp & PORT_CONNECT) {
218 status |= USB_PORT_STAT_CONNECTION; 500 status |= USB_PORT_STAT_CONNECTION;
219 status |= xhci_port_speed(temp); 501 status |= xhci_port_speed(temp);
@@ -224,20 +506,114 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
224 status |= USB_PORT_STAT_OVERCURRENT; 506 status |= USB_PORT_STAT_OVERCURRENT;
225 if (temp & PORT_RESET) 507 if (temp & PORT_RESET)
226 status |= USB_PORT_STAT_RESET; 508 status |= USB_PORT_STAT_RESET;
227 if (temp & PORT_POWER) 509 if (temp & PORT_POWER) {
228 status |= USB_PORT_STAT_POWER; 510 if (hcd->speed == HCD_USB3)
511 status |= USB_SS_PORT_STAT_POWER;
512 else
513 status |= USB_PORT_STAT_POWER;
514 }
515 /* Port Link State */
516 if (hcd->speed == HCD_USB3) {
517 /* resume state is a xHCI internal state.
518 * Do not report it to usb core.
519 */
520 if ((temp & PORT_PLS_MASK) != XDEV_RESUME)
521 status |= (temp & PORT_PLS_MASK);
522 }
523 if (bus_state->port_c_suspend & (1 << wIndex))
524 status |= 1 << USB_PORT_FEAT_C_SUSPEND;
229 xhci_dbg(xhci, "Get port status returned 0x%x\n", status); 525 xhci_dbg(xhci, "Get port status returned 0x%x\n", status);
230 put_unaligned(cpu_to_le32(status), (__le32 *) buf); 526 put_unaligned(cpu_to_le32(status), (__le32 *) buf);
231 break; 527 break;
232 case SetPortFeature: 528 case SetPortFeature:
529 if (wValue == USB_PORT_FEAT_LINK_STATE)
530 link_state = (wIndex & 0xff00) >> 3;
233 wIndex &= 0xff; 531 wIndex &= 0xff;
234 if (!wIndex || wIndex > ports) 532 if (!wIndex || wIndex > max_ports)
235 goto error; 533 goto error;
236 wIndex--; 534 wIndex--;
237 addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS*(wIndex & 0xff); 535 temp = xhci_readl(xhci, port_array[wIndex]);
238 temp = xhci_readl(xhci, addr); 536 if (temp == 0xffffffff) {
537 retval = -ENODEV;
538 break;
539 }
239 temp = xhci_port_state_to_neutral(temp); 540 temp = xhci_port_state_to_neutral(temp);
541 /* FIXME: What new port features do we need to support? */
240 switch (wValue) { 542 switch (wValue) {
543 case USB_PORT_FEAT_SUSPEND:
544 temp = xhci_readl(xhci, port_array[wIndex]);
545 /* In spec software should not attempt to suspend
546 * a port unless the port reports that it is in the
547 * enabled (PED = ‘1’,PLS < ‘3’) state.
548 */
549 if ((temp & PORT_PE) == 0 || (temp & PORT_RESET)
550 || (temp & PORT_PLS_MASK) >= XDEV_U3) {
551 xhci_warn(xhci, "USB core suspending device "
552 "not in U0/U1/U2.\n");
553 goto error;
554 }
555
556 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
557 wIndex + 1);
558 if (!slot_id) {
559 xhci_warn(xhci, "slot_id is zero\n");
560 goto error;
561 }
562 /* unlock to execute stop endpoint commands */
563 spin_unlock_irqrestore(&xhci->lock, flags);
564 xhci_stop_device(xhci, slot_id, 1);
565 spin_lock_irqsave(&xhci->lock, flags);
566
567 temp = xhci_port_state_to_neutral(temp);
568 temp &= ~PORT_PLS_MASK;
569 temp |= PORT_LINK_STROBE | XDEV_U3;
570 xhci_writel(xhci, temp, port_array[wIndex]);
571
572 spin_unlock_irqrestore(&xhci->lock, flags);
573 msleep(10); /* wait device to enter */
574 spin_lock_irqsave(&xhci->lock, flags);
575
576 temp = xhci_readl(xhci, port_array[wIndex]);
577 bus_state->suspended_ports |= 1 << wIndex;
578 break;
579 case USB_PORT_FEAT_LINK_STATE:
580 temp = xhci_readl(xhci, port_array[wIndex]);
581 /* Software should not attempt to set
582 * port link state above '5' (Rx.Detect) and the port
583 * must be enabled.
584 */
585 if ((temp & PORT_PE) == 0 ||
586 (link_state > USB_SS_PORT_LS_RX_DETECT)) {
587 xhci_warn(xhci, "Cannot set link state.\n");
588 goto error;
589 }
590
591 if (link_state == USB_SS_PORT_LS_U3) {
592 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
593 wIndex + 1);
594 if (slot_id) {
595 /* unlock to execute stop endpoint
596 * commands */
597 spin_unlock_irqrestore(&xhci->lock,
598 flags);
599 xhci_stop_device(xhci, slot_id, 1);
600 spin_lock_irqsave(&xhci->lock, flags);
601 }
602 }
603
604 temp = xhci_port_state_to_neutral(temp);
605 temp &= ~PORT_PLS_MASK;
606 temp |= PORT_LINK_STROBE | link_state;
607 xhci_writel(xhci, temp, port_array[wIndex]);
608
609 spin_unlock_irqrestore(&xhci->lock, flags);
610 msleep(20); /* wait device to enter */
611 spin_lock_irqsave(&xhci->lock, flags);
612
613 temp = xhci_readl(xhci, port_array[wIndex]);
614 if (link_state == USB_SS_PORT_LS_U3)
615 bus_state->suspended_ports |= 1 << wIndex;
616 break;
241 case USB_PORT_FEAT_POWER: 617 case USB_PORT_FEAT_POWER:
242 /* 618 /*
243 * Turn on ports, even if there isn't per-port switching. 619 * Turn on ports, even if there isn't per-port switching.
@@ -245,41 +621,96 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
245 * However, khubd will ignore the roothub events until 621 * However, khubd will ignore the roothub events until
246 * the roothub is registered. 622 * the roothub is registered.
247 */ 623 */
248 xhci_writel(xhci, temp | PORT_POWER, addr); 624 xhci_writel(xhci, temp | PORT_POWER,
625 port_array[wIndex]);
249 626
250 temp = xhci_readl(xhci, addr); 627 temp = xhci_readl(xhci, port_array[wIndex]);
251 xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp); 628 xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp);
252 break; 629 break;
253 case USB_PORT_FEAT_RESET: 630 case USB_PORT_FEAT_RESET:
254 temp = (temp | PORT_RESET); 631 temp = (temp | PORT_RESET);
255 xhci_writel(xhci, temp, addr); 632 xhci_writel(xhci, temp, port_array[wIndex]);
256 633
257 temp = xhci_readl(xhci, addr); 634 temp = xhci_readl(xhci, port_array[wIndex]);
258 xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp); 635 xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp);
259 break; 636 break;
637 case USB_PORT_FEAT_BH_PORT_RESET:
638 temp |= PORT_WR;
639 xhci_writel(xhci, temp, port_array[wIndex]);
640
641 temp = xhci_readl(xhci, port_array[wIndex]);
642 break;
260 default: 643 default:
261 goto error; 644 goto error;
262 } 645 }
263 temp = xhci_readl(xhci, addr); /* unblock any posted writes */ 646 /* unblock any posted writes */
647 temp = xhci_readl(xhci, port_array[wIndex]);
264 break; 648 break;
265 case ClearPortFeature: 649 case ClearPortFeature:
266 if (!wIndex || wIndex > ports) 650 if (!wIndex || wIndex > max_ports)
267 goto error; 651 goto error;
268 wIndex--; 652 wIndex--;
269 addr = &xhci->op_regs->port_status_base + 653 temp = xhci_readl(xhci, port_array[wIndex]);
270 NUM_PORT_REGS*(wIndex & 0xff); 654 if (temp == 0xffffffff) {
271 temp = xhci_readl(xhci, addr); 655 retval = -ENODEV;
656 break;
657 }
658 /* FIXME: What new port features do we need to support? */
272 temp = xhci_port_state_to_neutral(temp); 659 temp = xhci_port_state_to_neutral(temp);
273 switch (wValue) { 660 switch (wValue) {
661 case USB_PORT_FEAT_SUSPEND:
662 temp = xhci_readl(xhci, port_array[wIndex]);
663 xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n");
664 xhci_dbg(xhci, "PORTSC %04x\n", temp);
665 if (temp & PORT_RESET)
666 goto error;
667 if (temp & XDEV_U3) {
668 if ((temp & PORT_PE) == 0)
669 goto error;
670
671 temp = xhci_port_state_to_neutral(temp);
672 temp &= ~PORT_PLS_MASK;
673 temp |= PORT_LINK_STROBE | XDEV_RESUME;
674 xhci_writel(xhci, temp,
675 port_array[wIndex]);
676
677 spin_unlock_irqrestore(&xhci->lock,
678 flags);
679 msleep(20);
680 spin_lock_irqsave(&xhci->lock, flags);
681
682 temp = xhci_readl(xhci,
683 port_array[wIndex]);
684 temp = xhci_port_state_to_neutral(temp);
685 temp &= ~PORT_PLS_MASK;
686 temp |= PORT_LINK_STROBE | XDEV_U0;
687 xhci_writel(xhci, temp,
688 port_array[wIndex]);
689 }
690 bus_state->port_c_suspend |= 1 << wIndex;
691
692 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
693 wIndex + 1);
694 if (!slot_id) {
695 xhci_dbg(xhci, "slot_id is zero\n");
696 goto error;
697 }
698 xhci_ring_device(xhci, slot_id);
699 break;
700 case USB_PORT_FEAT_C_SUSPEND:
701 bus_state->port_c_suspend &= ~(1 << wIndex);
274 case USB_PORT_FEAT_C_RESET: 702 case USB_PORT_FEAT_C_RESET:
703 case USB_PORT_FEAT_C_BH_PORT_RESET:
275 case USB_PORT_FEAT_C_CONNECTION: 704 case USB_PORT_FEAT_C_CONNECTION:
276 case USB_PORT_FEAT_C_OVER_CURRENT: 705 case USB_PORT_FEAT_C_OVER_CURRENT:
277 case USB_PORT_FEAT_C_ENABLE: 706 case USB_PORT_FEAT_C_ENABLE:
707 case USB_PORT_FEAT_C_PORT_LINK_STATE:
278 xhci_clear_port_change_bit(xhci, wValue, wIndex, 708 xhci_clear_port_change_bit(xhci, wValue, wIndex,
279 addr, temp); 709 port_array[wIndex], temp);
280 break; 710 break;
281 case USB_PORT_FEAT_ENABLE: 711 case USB_PORT_FEAT_ENABLE:
282 xhci_disable_port(xhci, wIndex, addr, temp); 712 xhci_disable_port(hcd, xhci, wIndex,
713 port_array[wIndex], temp);
283 break; 714 break;
284 default: 715 default:
285 goto error; 716 goto error;
@@ -306,25 +737,35 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
306{ 737{
307 unsigned long flags; 738 unsigned long flags;
308 u32 temp, status; 739 u32 temp, status;
740 u32 mask;
309 int i, retval; 741 int i, retval;
310 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 742 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
311 int ports; 743 int max_ports;
312 u32 __iomem *addr; 744 __le32 __iomem **port_array;
745 struct xhci_bus_state *bus_state;
313 746
314 ports = HCS_MAX_PORTS(xhci->hcs_params1); 747 max_ports = xhci_get_ports(hcd, &port_array);
748 bus_state = &xhci->bus_state[hcd_index(hcd)];
315 749
316 /* Initial status is no changes */ 750 /* Initial status is no changes */
317 retval = (ports + 8) / 8; 751 retval = (max_ports + 8) / 8;
318 memset(buf, 0, retval); 752 memset(buf, 0, retval);
319 status = 0; 753 status = 0;
320 754
755 mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC;
756
321 spin_lock_irqsave(&xhci->lock, flags); 757 spin_lock_irqsave(&xhci->lock, flags);
322 /* For each port, did anything change? If so, set that bit in buf. */ 758 /* For each port, did anything change? If so, set that bit in buf. */
323 for (i = 0; i < ports; i++) { 759 for (i = 0; i < max_ports; i++) {
324 addr = &xhci->op_regs->port_status_base + 760 temp = xhci_readl(xhci, port_array[i]);
325 NUM_PORT_REGS*i; 761 if (temp == 0xffffffff) {
326 temp = xhci_readl(xhci, addr); 762 retval = -ENODEV;
327 if (temp & (PORT_CSC | PORT_PEC | PORT_OCC)) { 763 break;
764 }
765 if ((temp & mask) != 0 ||
766 (bus_state->port_c_suspend & 1 << i) ||
767 (bus_state->resume_done[i] && time_after_eq(
768 jiffies, bus_state->resume_done[i]))) {
328 buf[(i + 1) / 8] |= 1 << (i + 1) % 8; 769 buf[(i + 1) / 8] |= 1 << (i + 1) % 8;
329 status = 1; 770 status = 1;
330 } 771 }
@@ -332,3 +773,202 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
332 spin_unlock_irqrestore(&xhci->lock, flags); 773 spin_unlock_irqrestore(&xhci->lock, flags);
333 return status ? retval : 0; 774 return status ? retval : 0;
334} 775}
776
777#ifdef CONFIG_PM
778
779int xhci_bus_suspend(struct usb_hcd *hcd)
780{
781 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
782 int max_ports, port_index;
783 __le32 __iomem **port_array;
784 struct xhci_bus_state *bus_state;
785 unsigned long flags;
786
787 max_ports = xhci_get_ports(hcd, &port_array);
788 bus_state = &xhci->bus_state[hcd_index(hcd)];
789
790 spin_lock_irqsave(&xhci->lock, flags);
791
792 if (hcd->self.root_hub->do_remote_wakeup) {
793 port_index = max_ports;
794 while (port_index--) {
795 if (bus_state->resume_done[port_index] != 0) {
796 spin_unlock_irqrestore(&xhci->lock, flags);
797 xhci_dbg(xhci, "suspend failed because "
798 "port %d is resuming\n",
799 port_index + 1);
800 return -EBUSY;
801 }
802 }
803 }
804
805 port_index = max_ports;
806 bus_state->bus_suspended = 0;
807 while (port_index--) {
808 /* suspend the port if the port is not suspended */
809 u32 t1, t2;
810 int slot_id;
811
812 t1 = xhci_readl(xhci, port_array[port_index]);
813 t2 = xhci_port_state_to_neutral(t1);
814
815 if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) {
816 xhci_dbg(xhci, "port %d not suspended\n", port_index);
817 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
818 port_index + 1);
819 if (slot_id) {
820 spin_unlock_irqrestore(&xhci->lock, flags);
821 xhci_stop_device(xhci, slot_id, 1);
822 spin_lock_irqsave(&xhci->lock, flags);
823 }
824 t2 &= ~PORT_PLS_MASK;
825 t2 |= PORT_LINK_STROBE | XDEV_U3;
826 set_bit(port_index, &bus_state->bus_suspended);
827 }
828 if (hcd->self.root_hub->do_remote_wakeup) {
829 if (t1 & PORT_CONNECT) {
830 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
831 t2 &= ~PORT_WKCONN_E;
832 } else {
833 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
834 t2 &= ~PORT_WKDISC_E;
835 }
836 } else
837 t2 &= ~PORT_WAKE_BITS;
838
839 t1 = xhci_port_state_to_neutral(t1);
840 if (t1 != t2)
841 xhci_writel(xhci, t2, port_array[port_index]);
842
843 if (hcd->speed != HCD_USB3) {
844 /* enable remote wake up for USB 2.0 */
845 __le32 __iomem *addr;
846 u32 tmp;
847
848 /* Add one to the port status register address to get
849 * the port power control register address.
850 */
851 addr = port_array[port_index] + 1;
852 tmp = xhci_readl(xhci, addr);
853 tmp |= PORT_RWE;
854 xhci_writel(xhci, tmp, addr);
855 }
856 }
857 hcd->state = HC_STATE_SUSPENDED;
858 bus_state->next_statechange = jiffies + msecs_to_jiffies(10);
859 spin_unlock_irqrestore(&xhci->lock, flags);
860 return 0;
861}
862
863int xhci_bus_resume(struct usb_hcd *hcd)
864{
865 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
866 int max_ports, port_index;
867 __le32 __iomem **port_array;
868 struct xhci_bus_state *bus_state;
869 u32 temp;
870 unsigned long flags;
871
872 max_ports = xhci_get_ports(hcd, &port_array);
873 bus_state = &xhci->bus_state[hcd_index(hcd)];
874
875 if (time_before(jiffies, bus_state->next_statechange))
876 msleep(5);
877
878 spin_lock_irqsave(&xhci->lock, flags);
879 if (!HCD_HW_ACCESSIBLE(hcd)) {
880 spin_unlock_irqrestore(&xhci->lock, flags);
881 return -ESHUTDOWN;
882 }
883
884 /* delay the irqs */
885 temp = xhci_readl(xhci, &xhci->op_regs->command);
886 temp &= ~CMD_EIE;
887 xhci_writel(xhci, temp, &xhci->op_regs->command);
888
889 port_index = max_ports;
890 while (port_index--) {
891 /* Check whether need resume ports. If needed
892 resume port and disable remote wakeup */
893 u32 temp;
894 int slot_id;
895
896 temp = xhci_readl(xhci, port_array[port_index]);
897 if (DEV_SUPERSPEED(temp))
898 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
899 else
900 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
901 if (test_bit(port_index, &bus_state->bus_suspended) &&
902 (temp & PORT_PLS_MASK)) {
903 if (DEV_SUPERSPEED(temp)) {
904 temp = xhci_port_state_to_neutral(temp);
905 temp &= ~PORT_PLS_MASK;
906 temp |= PORT_LINK_STROBE | XDEV_U0;
907 xhci_writel(xhci, temp, port_array[port_index]);
908 } else {
909 temp = xhci_port_state_to_neutral(temp);
910 temp &= ~PORT_PLS_MASK;
911 temp |= PORT_LINK_STROBE | XDEV_RESUME;
912 xhci_writel(xhci, temp, port_array[port_index]);
913
914 spin_unlock_irqrestore(&xhci->lock, flags);
915 msleep(20);
916 spin_lock_irqsave(&xhci->lock, flags);
917
918 temp = xhci_readl(xhci, port_array[port_index]);
919 temp = xhci_port_state_to_neutral(temp);
920 temp &= ~PORT_PLS_MASK;
921 temp |= PORT_LINK_STROBE | XDEV_U0;
922 xhci_writel(xhci, temp, port_array[port_index]);
923 }
924 /* wait for the port to enter U0 and report port link
925 * state change.
926 */
927 spin_unlock_irqrestore(&xhci->lock, flags);
928 msleep(20);
929 spin_lock_irqsave(&xhci->lock, flags);
930
931 /* Clear PLC */
932 temp = xhci_readl(xhci, port_array[port_index]);
933 if (temp & PORT_PLC) {
934 temp = xhci_port_state_to_neutral(temp);
935 temp |= PORT_PLC;
936 xhci_writel(xhci, temp, port_array[port_index]);
937 }
938
939 slot_id = xhci_find_slot_id_by_port(hcd,
940 xhci, port_index + 1);
941 if (slot_id)
942 xhci_ring_device(xhci, slot_id);
943 } else
944 xhci_writel(xhci, temp, port_array[port_index]);
945
946 if (hcd->speed != HCD_USB3) {
947 /* disable remote wake up for USB 2.0 */
948 __le32 __iomem *addr;
949 u32 tmp;
950
951 /* Add one to the port status register address to get
952 * the port power control register address.
953 */
954 addr = port_array[port_index] + 1;
955 tmp = xhci_readl(xhci, addr);
956 tmp &= ~PORT_RWE;
957 xhci_writel(xhci, tmp, addr);
958 }
959 }
960
961 (void) xhci_readl(xhci, &xhci->op_regs->command);
962
963 bus_state->next_statechange = jiffies + msecs_to_jiffies(5);
964 /* re-enable irqs */
965 temp = xhci_readl(xhci, &xhci->op_regs->command);
966 temp |= CMD_EIE;
967 xhci_writel(xhci, temp, &xhci->op_regs->command);
968 temp = xhci_readl(xhci, &xhci->op_regs->command);
969
970 spin_unlock_irqrestore(&xhci->lock, flags);
971 return 0;
972}
973
974#endif /* CONFIG_PM */
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 4e51343ddffc..fcb7f7efc86d 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -89,16 +89,17 @@ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev,
89 return; 89 return;
90 prev->next = next; 90 prev->next = next;
91 if (link_trbs) { 91 if (link_trbs) {
92 prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr = next->dma; 92 prev->trbs[TRBS_PER_SEGMENT-1].link.
93 segment_ptr = cpu_to_le64(next->dma);
93 94
94 /* Set the last TRB in the segment to have a TRB type ID of Link TRB */ 95 /* Set the last TRB in the segment to have a TRB type ID of Link TRB */
95 val = prev->trbs[TRBS_PER_SEGMENT-1].link.control; 96 val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control);
96 val &= ~TRB_TYPE_BITMASK; 97 val &= ~TRB_TYPE_BITMASK;
97 val |= TRB_TYPE(TRB_LINK); 98 val |= TRB_TYPE(TRB_LINK);
98 /* Always set the chain bit with 0.95 hardware */ 99 /* Always set the chain bit with 0.95 hardware */
99 if (xhci_link_trb_quirk(xhci)) 100 if (xhci_link_trb_quirk(xhci))
100 val |= TRB_CHAIN; 101 val |= TRB_CHAIN;
101 prev->trbs[TRBS_PER_SEGMENT-1].link.control = val; 102 prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val);
102 } 103 }
103 xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n", 104 xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n",
104 (unsigned long long)prev->dma, 105 (unsigned long long)prev->dma,
@@ -186,7 +187,8 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
186 187
187 if (link_trbs) { 188 if (link_trbs) {
188 /* See section 4.9.2.1 and 6.4.4.1 */ 189 /* See section 4.9.2.1 and 6.4.4.1 */
189 prev->trbs[TRBS_PER_SEGMENT-1].link.control |= (LINK_TOGGLE); 190 prev->trbs[TRBS_PER_SEGMENT-1].link.
191 control |= cpu_to_le32(LINK_TOGGLE);
190 xhci_dbg(xhci, "Wrote link toggle flag to" 192 xhci_dbg(xhci, "Wrote link toggle flag to"
191 " segment %p (virtual), 0x%llx (DMA)\n", 193 " segment %p (virtual), 0x%llx (DMA)\n",
192 prev, (unsigned long long)prev->dma); 194 prev, (unsigned long long)prev->dma);
@@ -207,14 +209,13 @@ void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
207 209
208 rings_cached = virt_dev->num_rings_cached; 210 rings_cached = virt_dev->num_rings_cached;
209 if (rings_cached < XHCI_MAX_RINGS_CACHED) { 211 if (rings_cached < XHCI_MAX_RINGS_CACHED) {
210 virt_dev->num_rings_cached++;
211 rings_cached = virt_dev->num_rings_cached;
212 virt_dev->ring_cache[rings_cached] = 212 virt_dev->ring_cache[rings_cached] =
213 virt_dev->eps[ep_index].ring; 213 virt_dev->eps[ep_index].ring;
214 virt_dev->num_rings_cached++;
214 xhci_dbg(xhci, "Cached old ring, " 215 xhci_dbg(xhci, "Cached old ring, "
215 "%d ring%s cached\n", 216 "%d ring%s cached\n",
216 rings_cached, 217 virt_dev->num_rings_cached,
217 (rings_cached > 1) ? "s" : ""); 218 (virt_dev->num_rings_cached > 1) ? "s" : "");
218 } else { 219 } else {
219 xhci_ring_free(xhci, virt_dev->eps[ep_index].ring); 220 xhci_ring_free(xhci, virt_dev->eps[ep_index].ring);
220 xhci_dbg(xhci, "Ring cache full (%d rings), " 221 xhci_dbg(xhci, "Ring cache full (%d rings), "
@@ -307,7 +308,7 @@ struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci,
307 308
308/***************** Streams structures manipulation *************************/ 309/***************** Streams structures manipulation *************************/
309 310
310void xhci_free_stream_ctx(struct xhci_hcd *xhci, 311static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
311 unsigned int num_stream_ctxs, 312 unsigned int num_stream_ctxs,
312 struct xhci_stream_ctx *stream_ctx, dma_addr_t dma) 313 struct xhci_stream_ctx *stream_ctx, dma_addr_t dma)
313{ 314{
@@ -335,7 +336,7 @@ void xhci_free_stream_ctx(struct xhci_hcd *xhci,
335 * The stream context array must be a power of 2, and can be as small as 336 * The stream context array must be a power of 2, and can be as small as
336 * 64 bytes or as large as 1MB. 337 * 64 bytes or as large as 1MB.
337 */ 338 */
338struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci, 339static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
339 unsigned int num_stream_ctxs, dma_addr_t *dma, 340 unsigned int num_stream_ctxs, dma_addr_t *dma,
340 gfp_t mem_flags) 341 gfp_t mem_flags)
341{ 342{
@@ -548,7 +549,8 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
548 addr = cur_ring->first_seg->dma | 549 addr = cur_ring->first_seg->dma |
549 SCT_FOR_CTX(SCT_PRI_TR) | 550 SCT_FOR_CTX(SCT_PRI_TR) |
550 cur_ring->cycle_state; 551 cur_ring->cycle_state;
551 stream_info->stream_ctx_array[cur_stream].stream_ring = addr; 552 stream_info->stream_ctx_array[cur_stream].
553 stream_ring = cpu_to_le64(addr);
552 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", 554 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n",
553 cur_stream, (unsigned long long) addr); 555 cur_stream, (unsigned long long) addr);
554 556
@@ -614,10 +616,10 @@ void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
614 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2; 616 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2;
615 xhci_dbg(xhci, "Setting number of stream ctx array entries to %u\n", 617 xhci_dbg(xhci, "Setting number of stream ctx array entries to %u\n",
616 1 << (max_primary_streams + 1)); 618 1 << (max_primary_streams + 1));
617 ep_ctx->ep_info &= ~EP_MAXPSTREAMS_MASK; 619 ep_ctx->ep_info &= cpu_to_le32(~EP_MAXPSTREAMS_MASK);
618 ep_ctx->ep_info |= EP_MAXPSTREAMS(max_primary_streams); 620 ep_ctx->ep_info |= cpu_to_le32(EP_MAXPSTREAMS(max_primary_streams)
619 ep_ctx->ep_info |= EP_HAS_LSA; 621 | EP_HAS_LSA);
620 ep_ctx->deq = stream_info->ctx_array_dma; 622 ep_ctx->deq = cpu_to_le64(stream_info->ctx_array_dma);
621} 623}
622 624
623/* 625/*
@@ -630,10 +632,9 @@ void xhci_setup_no_streams_ep_input_ctx(struct xhci_hcd *xhci,
630 struct xhci_virt_ep *ep) 632 struct xhci_virt_ep *ep)
631{ 633{
632 dma_addr_t addr; 634 dma_addr_t addr;
633 ep_ctx->ep_info &= ~EP_MAXPSTREAMS_MASK; 635 ep_ctx->ep_info &= cpu_to_le32(~(EP_MAXPSTREAMS_MASK | EP_HAS_LSA));
634 ep_ctx->ep_info &= ~EP_HAS_LSA;
635 addr = xhci_trb_virt_to_dma(ep->ring->deq_seg, ep->ring->dequeue); 636 addr = xhci_trb_virt_to_dma(ep->ring->deq_seg, ep->ring->dequeue);
636 ep_ctx->deq = addr | ep->ring->cycle_state; 637 ep_ctx->deq = cpu_to_le64(addr | ep->ring->cycle_state);
637} 638}
638 639
639/* Frees all stream contexts associated with the endpoint, 640/* Frees all stream contexts associated with the endpoint,
@@ -778,13 +779,14 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
778 779
779 init_completion(&dev->cmd_completion); 780 init_completion(&dev->cmd_completion);
780 INIT_LIST_HEAD(&dev->cmd_list); 781 INIT_LIST_HEAD(&dev->cmd_list);
782 dev->udev = udev;
781 783
782 /* Point to output device context in dcbaa. */ 784 /* Point to output device context in dcbaa. */
783 xhci->dcbaa->dev_context_ptrs[slot_id] = dev->out_ctx->dma; 785 xhci->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(dev->out_ctx->dma);
784 xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n", 786 xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n",
785 slot_id, 787 slot_id,
786 &xhci->dcbaa->dev_context_ptrs[slot_id], 788 &xhci->dcbaa->dev_context_ptrs[slot_id],
787 (unsigned long long) xhci->dcbaa->dev_context_ptrs[slot_id]); 789 (unsigned long long) le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id]));
788 790
789 return 1; 791 return 1;
790fail: 792fail:
@@ -809,8 +811,58 @@ void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci,
809 * configured device has reset, so all control transfers should have 811 * configured device has reset, so all control transfers should have
810 * been completed or cancelled before the reset. 812 * been completed or cancelled before the reset.
811 */ 813 */
812 ep0_ctx->deq = xhci_trb_virt_to_dma(ep_ring->enq_seg, ep_ring->enqueue); 814 ep0_ctx->deq = cpu_to_le64(xhci_trb_virt_to_dma(ep_ring->enq_seg,
813 ep0_ctx->deq |= ep_ring->cycle_state; 815 ep_ring->enqueue)
816 | ep_ring->cycle_state);
817}
818
819/*
820 * The xHCI roothub may have ports of differing speeds in any order in the port
821 * status registers. xhci->port_array provides an array of the port speed for
822 * each offset into the port status registers.
823 *
824 * The xHCI hardware wants to know the roothub port number that the USB device
825 * is attached to (or the roothub port its ancestor hub is attached to). All we
826 * know is the index of that port under either the USB 2.0 or the USB 3.0
827 * roothub, but that doesn't give us the real index into the HW port status
828 * registers. Scan through the xHCI roothub port array, looking for the Nth
829 * entry of the correct port speed. Return the port number of that entry.
830 */
831static u32 xhci_find_real_port_number(struct xhci_hcd *xhci,
832 struct usb_device *udev)
833{
834 struct usb_device *top_dev;
835 unsigned int num_similar_speed_ports;
836 unsigned int faked_port_num;
837 int i;
838
839 for (top_dev = udev; top_dev->parent && top_dev->parent->parent;
840 top_dev = top_dev->parent)
841 /* Found device below root hub */;
842 faked_port_num = top_dev->portnum;
843 for (i = 0, num_similar_speed_ports = 0;
844 i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
845 u8 port_speed = xhci->port_array[i];
846
847 /*
848 * Skip ports that don't have known speeds, or have duplicate
849 * Extended Capabilities port speed entries.
850 */
851 if (port_speed == 0 || port_speed == DUPLICATE_ENTRY)
852 continue;
853
854 /*
855 * USB 3.0 ports are always under a USB 3.0 hub. USB 2.0 and
856 * 1.1 ports are under the USB 2.0 hub. If the port speed
857 * matches the device speed, it's a similar speed port.
858 */
859 if ((port_speed == 0x03) == (udev->speed == USB_SPEED_SUPER))
860 num_similar_speed_ports++;
861 if (num_similar_speed_ports == faked_port_num)
862 /* Roothub ports are numbered from 1 to N */
863 return i+1;
864 }
865 return 0;
814} 866}
815 867
816/* Setup an xHCI virtual device for a Set Address command */ 868/* Setup an xHCI virtual device for a Set Address command */
@@ -818,9 +870,10 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
818{ 870{
819 struct xhci_virt_device *dev; 871 struct xhci_virt_device *dev;
820 struct xhci_ep_ctx *ep0_ctx; 872 struct xhci_ep_ctx *ep0_ctx;
821 struct usb_device *top_dev;
822 struct xhci_slot_ctx *slot_ctx; 873 struct xhci_slot_ctx *slot_ctx;
823 struct xhci_input_control_ctx *ctrl_ctx; 874 struct xhci_input_control_ctx *ctrl_ctx;
875 u32 port_num;
876 struct usb_device *top_dev;
824 877
825 dev = xhci->devs[udev->slot_id]; 878 dev = xhci->devs[udev->slot_id];
826 /* Slot ID 0 is reserved */ 879 /* Slot ID 0 is reserved */
@@ -834,24 +887,22 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
834 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); 887 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx);
835 888
836 /* 2) New slot context and endpoint 0 context are valid*/ 889 /* 2) New slot context and endpoint 0 context are valid*/
837 ctrl_ctx->add_flags = SLOT_FLAG | EP0_FLAG; 890 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG);
838 891
839 /* 3) Only the control endpoint is valid - one endpoint context */ 892 /* 3) Only the control endpoint is valid - one endpoint context */
840 slot_ctx->dev_info |= LAST_CTX(1); 893 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | (u32) udev->route);
841
842 slot_ctx->dev_info |= (u32) udev->route;
843 switch (udev->speed) { 894 switch (udev->speed) {
844 case USB_SPEED_SUPER: 895 case USB_SPEED_SUPER:
845 slot_ctx->dev_info |= (u32) SLOT_SPEED_SS; 896 slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_SS);
846 break; 897 break;
847 case USB_SPEED_HIGH: 898 case USB_SPEED_HIGH:
848 slot_ctx->dev_info |= (u32) SLOT_SPEED_HS; 899 slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_HS);
849 break; 900 break;
850 case USB_SPEED_FULL: 901 case USB_SPEED_FULL:
851 slot_ctx->dev_info |= (u32) SLOT_SPEED_FS; 902 slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_FS);
852 break; 903 break;
853 case USB_SPEED_LOW: 904 case USB_SPEED_LOW:
854 slot_ctx->dev_info |= (u32) SLOT_SPEED_LS; 905 slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_LS);
855 break; 906 break;
856 case USB_SPEED_WIRELESS: 907 case USB_SPEED_WIRELESS:
857 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); 908 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
@@ -862,40 +913,45 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
862 BUG(); 913 BUG();
863 } 914 }
864 /* Find the root hub port this device is under */ 915 /* Find the root hub port this device is under */
916 port_num = xhci_find_real_port_number(xhci, udev);
917 if (!port_num)
918 return -EINVAL;
919 slot_ctx->dev_info2 |= cpu_to_le32((u32) ROOT_HUB_PORT(port_num));
920 /* Set the port number in the virtual_device to the faked port number */
865 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; 921 for (top_dev = udev; top_dev->parent && top_dev->parent->parent;
866 top_dev = top_dev->parent) 922 top_dev = top_dev->parent)
867 /* Found device below root hub */; 923 /* Found device below root hub */;
868 slot_ctx->dev_info2 |= (u32) ROOT_HUB_PORT(top_dev->portnum); 924 dev->port = top_dev->portnum;
869 xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); 925 xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num);
870 926 xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->port);
871 /* Is this a LS/FS device under a HS hub? */ 927
872 if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) && 928 /* Is this a LS/FS device under an external HS hub? */
873 udev->tt) { 929 if (udev->tt && udev->tt->hub->parent) {
874 slot_ctx->tt_info = udev->tt->hub->slot_id; 930 slot_ctx->tt_info = cpu_to_le32(udev->tt->hub->slot_id |
875 slot_ctx->tt_info |= udev->ttport << 8; 931 (udev->ttport << 8));
876 if (udev->tt->multi) 932 if (udev->tt->multi)
877 slot_ctx->dev_info |= DEV_MTT; 933 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT);
878 } 934 }
879 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); 935 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt);
880 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); 936 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport);
881 937
882 /* Step 4 - ring already allocated */ 938 /* Step 4 - ring already allocated */
883 /* Step 5 */ 939 /* Step 5 */
884 ep0_ctx->ep_info2 = EP_TYPE(CTRL_EP); 940 ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP));
885 /* 941 /*
886 * XXX: Not sure about wireless USB devices. 942 * XXX: Not sure about wireless USB devices.
887 */ 943 */
888 switch (udev->speed) { 944 switch (udev->speed) {
889 case USB_SPEED_SUPER: 945 case USB_SPEED_SUPER:
890 ep0_ctx->ep_info2 |= MAX_PACKET(512); 946 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(512));
891 break; 947 break;
892 case USB_SPEED_HIGH: 948 case USB_SPEED_HIGH:
893 /* USB core guesses at a 64-byte max packet first for FS devices */ 949 /* USB core guesses at a 64-byte max packet first for FS devices */
894 case USB_SPEED_FULL: 950 case USB_SPEED_FULL:
895 ep0_ctx->ep_info2 |= MAX_PACKET(64); 951 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(64));
896 break; 952 break;
897 case USB_SPEED_LOW: 953 case USB_SPEED_LOW:
898 ep0_ctx->ep_info2 |= MAX_PACKET(8); 954 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(8));
899 break; 955 break;
900 case USB_SPEED_WIRELESS: 956 case USB_SPEED_WIRELESS:
901 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); 957 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
@@ -906,18 +962,67 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
906 BUG(); 962 BUG();
907 } 963 }
908 /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */ 964 /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */
909 ep0_ctx->ep_info2 |= MAX_BURST(0); 965 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3));
910 ep0_ctx->ep_info2 |= ERROR_COUNT(3);
911 966
912 ep0_ctx->deq = 967 ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma |
913 dev->eps[0].ring->first_seg->dma; 968 dev->eps[0].ring->cycle_state);
914 ep0_ctx->deq |= dev->eps[0].ring->cycle_state;
915 969
916 /* Steps 7 and 8 were done in xhci_alloc_virt_device() */ 970 /* Steps 7 and 8 were done in xhci_alloc_virt_device() */
917 971
918 return 0; 972 return 0;
919} 973}
920 974
975/*
976 * Convert interval expressed as 2^(bInterval - 1) == interval into
977 * straight exponent value 2^n == interval.
978 *
979 */
980static unsigned int xhci_parse_exponent_interval(struct usb_device *udev,
981 struct usb_host_endpoint *ep)
982{
983 unsigned int interval;
984
985 interval = clamp_val(ep->desc.bInterval, 1, 16) - 1;
986 if (interval != ep->desc.bInterval - 1)
987 dev_warn(&udev->dev,
988 "ep %#x - rounding interval to %d %sframes\n",
989 ep->desc.bEndpointAddress,
990 1 << interval,
991 udev->speed == USB_SPEED_FULL ? "" : "micro");
992
993 if (udev->speed == USB_SPEED_FULL) {
994 /*
995 * Full speed isoc endpoints specify interval in frames,
996 * not microframes. We are using microframes everywhere,
997 * so adjust accordingly.
998 */
999 interval += 3; /* 1 frame = 2^3 uframes */
1000 }
1001
1002 return interval;
1003}
1004
1005/*
1006 * Convert bInterval expressed in frames (in 1-255 range) to exponent of
1007 * microframes, rounded down to nearest power of 2.
1008 */
1009static unsigned int xhci_parse_frame_interval(struct usb_device *udev,
1010 struct usb_host_endpoint *ep)
1011{
1012 unsigned int interval;
1013
1014 interval = fls(8 * ep->desc.bInterval) - 1;
1015 interval = clamp_val(interval, 3, 10);
1016 if ((1 << interval) != 8 * ep->desc.bInterval)
1017 dev_warn(&udev->dev,
1018 "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n",
1019 ep->desc.bEndpointAddress,
1020 1 << interval,
1021 8 * ep->desc.bInterval);
1022
1023 return interval;
1024}
1025
921/* Return the polling or NAK interval. 1026/* Return the polling or NAK interval.
922 * 1027 *
923 * The polling interval is expressed in "microframes". If xHCI's Interval field 1028 * The polling interval is expressed in "microframes". If xHCI's Interval field
@@ -926,7 +1031,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
926 * The NAK interval is one NAK per 1 to 255 microframes, or no NAKs if interval 1031 * The NAK interval is one NAK per 1 to 255 microframes, or no NAKs if interval
927 * is set to 0. 1032 * is set to 0.
928 */ 1033 */
929static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev, 1034static unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
930 struct usb_host_endpoint *ep) 1035 struct usb_host_endpoint *ep)
931{ 1036{
932 unsigned int interval = 0; 1037 unsigned int interval = 0;
@@ -935,45 +1040,38 @@ static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
935 case USB_SPEED_HIGH: 1040 case USB_SPEED_HIGH:
936 /* Max NAK rate */ 1041 /* Max NAK rate */
937 if (usb_endpoint_xfer_control(&ep->desc) || 1042 if (usb_endpoint_xfer_control(&ep->desc) ||
938 usb_endpoint_xfer_bulk(&ep->desc)) 1043 usb_endpoint_xfer_bulk(&ep->desc)) {
939 interval = ep->desc.bInterval; 1044 interval = ep->desc.bInterval;
1045 break;
1046 }
940 /* Fall through - SS and HS isoc/int have same decoding */ 1047 /* Fall through - SS and HS isoc/int have same decoding */
1048
941 case USB_SPEED_SUPER: 1049 case USB_SPEED_SUPER:
942 if (usb_endpoint_xfer_int(&ep->desc) || 1050 if (usb_endpoint_xfer_int(&ep->desc) ||
943 usb_endpoint_xfer_isoc(&ep->desc)) { 1051 usb_endpoint_xfer_isoc(&ep->desc)) {
944 if (ep->desc.bInterval == 0) 1052 interval = xhci_parse_exponent_interval(udev, ep);
945 interval = 0;
946 else
947 interval = ep->desc.bInterval - 1;
948 if (interval > 15)
949 interval = 15;
950 if (interval != ep->desc.bInterval + 1)
951 dev_warn(&udev->dev, "ep %#x - rounding interval to %d microframes\n",
952 ep->desc.bEndpointAddress, 1 << interval);
953 } 1053 }
954 break; 1054 break;
955 /* Convert bInterval (in 1-255 frames) to microframes and round down to 1055
956 * nearest power of 2.
957 */
958 case USB_SPEED_FULL: 1056 case USB_SPEED_FULL:
1057 if (usb_endpoint_xfer_isoc(&ep->desc)) {
1058 interval = xhci_parse_exponent_interval(udev, ep);
1059 break;
1060 }
1061 /*
1062 * Fall through for interrupt endpoint interval decoding
1063 * since it uses the same rules as low speed interrupt
1064 * endpoints.
1065 */
1066
959 case USB_SPEED_LOW: 1067 case USB_SPEED_LOW:
960 if (usb_endpoint_xfer_int(&ep->desc) || 1068 if (usb_endpoint_xfer_int(&ep->desc) ||
961 usb_endpoint_xfer_isoc(&ep->desc)) { 1069 usb_endpoint_xfer_isoc(&ep->desc)) {
962 interval = fls(8*ep->desc.bInterval) - 1; 1070
963 if (interval > 10) 1071 interval = xhci_parse_frame_interval(udev, ep);
964 interval = 10;
965 if (interval < 3)
966 interval = 3;
967 if ((1 << interval) != 8*ep->desc.bInterval)
968 dev_warn(&udev->dev,
969 "ep %#x - rounding interval"
970 " to %d microframes, "
971 "ep desc says %d microframes\n",
972 ep->desc.bEndpointAddress,
973 1 << interval,
974 8*ep->desc.bInterval);
975 } 1072 }
976 break; 1073 break;
1074
977 default: 1075 default:
978 BUG(); 1076 BUG();
979 } 1077 }
@@ -985,7 +1083,7 @@ static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
985 * transaction opportunities per microframe", but that goes in the Max Burst 1083 * transaction opportunities per microframe", but that goes in the Max Burst
986 * endpoint context field. 1084 * endpoint context field.
987 */ 1085 */
988static inline u32 xhci_get_endpoint_mult(struct usb_device *udev, 1086static u32 xhci_get_endpoint_mult(struct usb_device *udev,
989 struct usb_host_endpoint *ep) 1087 struct usb_host_endpoint *ep)
990{ 1088{
991 if (udev->speed != USB_SPEED_SUPER || 1089 if (udev->speed != USB_SPEED_SUPER ||
@@ -994,7 +1092,7 @@ static inline u32 xhci_get_endpoint_mult(struct usb_device *udev,
994 return ep->ss_ep_comp.bmAttributes; 1092 return ep->ss_ep_comp.bmAttributes;
995} 1093}
996 1094
997static inline u32 xhci_get_endpoint_type(struct usb_device *udev, 1095static u32 xhci_get_endpoint_type(struct usb_device *udev,
998 struct usb_host_endpoint *ep) 1096 struct usb_host_endpoint *ep)
999{ 1097{
1000 int in; 1098 int in;
@@ -1028,7 +1126,7 @@ static inline u32 xhci_get_endpoint_type(struct usb_device *udev,
1028 * Basically, this is the maxpacket size, multiplied by the burst size 1126 * Basically, this is the maxpacket size, multiplied by the burst size
1029 * and mult size. 1127 * and mult size.
1030 */ 1128 */
1031static inline u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci, 1129static u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci,
1032 struct usb_device *udev, 1130 struct usb_device *udev,
1033 struct usb_host_endpoint *ep) 1131 struct usb_host_endpoint *ep)
1034{ 1132{
@@ -1041,10 +1139,10 @@ static inline u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci,
1041 return 0; 1139 return 0;
1042 1140
1043 if (udev->speed == USB_SPEED_SUPER) 1141 if (udev->speed == USB_SPEED_SUPER)
1044 return ep->ss_ep_comp.wBytesPerInterval; 1142 return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
1045 1143
1046 max_packet = ep->desc.wMaxPacketSize & 0x3ff; 1144 max_packet = GET_MAX_PACKET(le16_to_cpu(ep->desc.wMaxPacketSize));
1047 max_burst = (ep->desc.wMaxPacketSize & 0x1800) >> 11; 1145 max_burst = (le16_to_cpu(ep->desc.wMaxPacketSize) & 0x1800) >> 11;
1048 /* A 0 in max burst means 1 transfer per ESIT */ 1146 /* A 0 in max burst means 1 transfer per ESIT */
1049 return max_packet * (max_burst + 1); 1147 return max_packet * (max_burst + 1);
1050} 1148}
@@ -1093,33 +1191,31 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1093 } 1191 }
1094 virt_dev->eps[ep_index].skip = false; 1192 virt_dev->eps[ep_index].skip = false;
1095 ep_ring = virt_dev->eps[ep_index].new_ring; 1193 ep_ring = virt_dev->eps[ep_index].new_ring;
1096 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; 1194 ep_ctx->deq = cpu_to_le64(ep_ring->first_seg->dma | ep_ring->cycle_state);
1097 1195
1098 ep_ctx->ep_info = xhci_get_endpoint_interval(udev, ep); 1196 ep_ctx->ep_info = cpu_to_le32(xhci_get_endpoint_interval(udev, ep)
1099 ep_ctx->ep_info |= EP_MULT(xhci_get_endpoint_mult(udev, ep)); 1197 | EP_MULT(xhci_get_endpoint_mult(udev, ep)));
1100 1198
1101 /* FIXME dig Mult and streams info out of ep companion desc */ 1199 /* FIXME dig Mult and streams info out of ep companion desc */
1102 1200
1103 /* Allow 3 retries for everything but isoc; 1201 /* Allow 3 retries for everything but isoc;
1104 * error count = 0 means infinite retries. 1202 * CErr shall be set to 0 for Isoch endpoints.
1105 */ 1203 */
1106 if (!usb_endpoint_xfer_isoc(&ep->desc)) 1204 if (!usb_endpoint_xfer_isoc(&ep->desc))
1107 ep_ctx->ep_info2 = ERROR_COUNT(3); 1205 ep_ctx->ep_info2 = cpu_to_le32(ERROR_COUNT(3));
1108 else 1206 else
1109 ep_ctx->ep_info2 = ERROR_COUNT(1); 1207 ep_ctx->ep_info2 = cpu_to_le32(ERROR_COUNT(0));
1110 1208
1111 ep_ctx->ep_info2 |= xhci_get_endpoint_type(udev, ep); 1209 ep_ctx->ep_info2 |= cpu_to_le32(xhci_get_endpoint_type(udev, ep));
1112 1210
1113 /* Set the max packet size and max burst */ 1211 /* Set the max packet size and max burst */
1114 switch (udev->speed) { 1212 switch (udev->speed) {
1115 case USB_SPEED_SUPER: 1213 case USB_SPEED_SUPER:
1116 max_packet = ep->desc.wMaxPacketSize; 1214 max_packet = le16_to_cpu(ep->desc.wMaxPacketSize);
1117 ep_ctx->ep_info2 |= MAX_PACKET(max_packet); 1215 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet));
1118 /* dig out max burst from ep companion desc */ 1216 /* dig out max burst from ep companion desc */
1119 max_packet = ep->ss_ep_comp.bMaxBurst; 1217 max_packet = ep->ss_ep_comp.bMaxBurst;
1120 if (!max_packet) 1218 ep_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(max_packet));
1121 xhci_warn(xhci, "WARN no SS endpoint bMaxBurst\n");
1122 ep_ctx->ep_info2 |= MAX_BURST(max_packet);
1123 break; 1219 break;
1124 case USB_SPEED_HIGH: 1220 case USB_SPEED_HIGH:
1125 /* bits 11:12 specify the number of additional transaction 1221 /* bits 11:12 specify the number of additional transaction
@@ -1127,20 +1223,21 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1127 */ 1223 */
1128 if (usb_endpoint_xfer_isoc(&ep->desc) || 1224 if (usb_endpoint_xfer_isoc(&ep->desc) ||
1129 usb_endpoint_xfer_int(&ep->desc)) { 1225 usb_endpoint_xfer_int(&ep->desc)) {
1130 max_burst = (ep->desc.wMaxPacketSize & 0x1800) >> 11; 1226 max_burst = (le16_to_cpu(ep->desc.wMaxPacketSize)
1131 ep_ctx->ep_info2 |= MAX_BURST(max_burst); 1227 & 0x1800) >> 11;
1228 ep_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(max_burst));
1132 } 1229 }
1133 /* Fall through */ 1230 /* Fall through */
1134 case USB_SPEED_FULL: 1231 case USB_SPEED_FULL:
1135 case USB_SPEED_LOW: 1232 case USB_SPEED_LOW:
1136 max_packet = ep->desc.wMaxPacketSize & 0x3ff; 1233 max_packet = GET_MAX_PACKET(le16_to_cpu(ep->desc.wMaxPacketSize));
1137 ep_ctx->ep_info2 |= MAX_PACKET(max_packet); 1234 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet));
1138 break; 1235 break;
1139 default: 1236 default:
1140 BUG(); 1237 BUG();
1141 } 1238 }
1142 max_esit_payload = xhci_get_max_esit_payload(xhci, udev, ep); 1239 max_esit_payload = xhci_get_max_esit_payload(xhci, udev, ep);
1143 ep_ctx->tx_info = MAX_ESIT_PAYLOAD_FOR_EP(max_esit_payload); 1240 ep_ctx->tx_info = cpu_to_le32(MAX_ESIT_PAYLOAD_FOR_EP(max_esit_payload));
1144 1241
1145 /* 1242 /*
1146 * XXX no idea how to calculate the average TRB buffer length for bulk 1243 * XXX no idea how to calculate the average TRB buffer length for bulk
@@ -1156,8 +1253,15 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1156 * including link TRBs, No-op TRBs, and Event data TRBs. Since we don't 1253 * including link TRBs, No-op TRBs, and Event data TRBs. Since we don't
1157 * use Event Data TRBs, and we don't chain in a link TRB on short 1254 * use Event Data TRBs, and we don't chain in a link TRB on short
1158 * transfers, we're basically dividing by 1. 1255 * transfers, we're basically dividing by 1.
1256 *
1257 * xHCI 1.0 specification indicates that the Average TRB Length should
1258 * be set to 8 for control endpoints.
1159 */ 1259 */
1160 ep_ctx->tx_info |= AVG_TRB_LENGTH_FOR_EP(max_esit_payload); 1260 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version == 0x100)
1261 ep_ctx->tx_info |= cpu_to_le32(AVG_TRB_LENGTH_FOR_EP(8));
1262 else
1263 ep_ctx->tx_info |=
1264 cpu_to_le32(AVG_TRB_LENGTH_FOR_EP(max_esit_payload));
1161 1265
1162 /* FIXME Debug endpoint context */ 1266 /* FIXME Debug endpoint context */
1163 return 0; 1267 return 0;
@@ -1257,7 +1361,7 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
1257 if (!xhci->scratchpad->sp_dma_buffers) 1361 if (!xhci->scratchpad->sp_dma_buffers)
1258 goto fail_sp4; 1362 goto fail_sp4;
1259 1363
1260 xhci->dcbaa->dev_context_ptrs[0] = xhci->scratchpad->sp_dma; 1364 xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma);
1261 for (i = 0; i < num_sp; i++) { 1365 for (i = 0; i < num_sp; i++) {
1262 dma_addr_t dma; 1366 dma_addr_t dma;
1263 void *buf = pci_alloc_consistent(to_pci_dev(dev), 1367 void *buf = pci_alloc_consistent(to_pci_dev(dev),
@@ -1441,8 +1545,17 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1441 xhci->dcbaa = NULL; 1545 xhci->dcbaa = NULL;
1442 1546
1443 scratchpad_free(xhci); 1547 scratchpad_free(xhci);
1548
1549 xhci->num_usb2_ports = 0;
1550 xhci->num_usb3_ports = 0;
1551 kfree(xhci->usb2_ports);
1552 kfree(xhci->usb3_ports);
1553 kfree(xhci->port_array);
1554
1444 xhci->page_size = 0; 1555 xhci->page_size = 0;
1445 xhci->page_shift = 0; 1556 xhci->page_shift = 0;
1557 xhci->bus_state[0].bus_suspended = 0;
1558 xhci->bus_state[1].bus_suspended = 0;
1446} 1559}
1447 1560
1448static int xhci_test_trb_in_td(struct xhci_hcd *xhci, 1561static int xhci_test_trb_in_td(struct xhci_hcd *xhci,
@@ -1624,6 +1737,184 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
1624 &xhci->ir_set->erst_dequeue); 1737 &xhci->ir_set->erst_dequeue);
1625} 1738}
1626 1739
1740static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
1741 __le32 __iomem *addr, u8 major_revision)
1742{
1743 u32 temp, port_offset, port_count;
1744 int i;
1745
1746 if (major_revision > 0x03) {
1747 xhci_warn(xhci, "Ignoring unknown port speed, "
1748 "Ext Cap %p, revision = 0x%x\n",
1749 addr, major_revision);
1750 /* Ignoring port protocol we can't understand. FIXME */
1751 return;
1752 }
1753
1754 /* Port offset and count in the third dword, see section 7.2 */
1755 temp = xhci_readl(xhci, addr + 2);
1756 port_offset = XHCI_EXT_PORT_OFF(temp);
1757 port_count = XHCI_EXT_PORT_COUNT(temp);
1758 xhci_dbg(xhci, "Ext Cap %p, port offset = %u, "
1759 "count = %u, revision = 0x%x\n",
1760 addr, port_offset, port_count, major_revision);
1761 /* Port count includes the current port offset */
1762 if (port_offset == 0 || (port_offset + port_count - 1) > num_ports)
1763 /* WTF? "Valid values are ‘1’ to MaxPorts" */
1764 return;
1765 port_offset--;
1766 for (i = port_offset; i < (port_offset + port_count); i++) {
1767 /* Duplicate entry. Ignore the port if the revisions differ. */
1768 if (xhci->port_array[i] != 0) {
1769 xhci_warn(xhci, "Duplicate port entry, Ext Cap %p,"
1770 " port %u\n", addr, i);
1771 xhci_warn(xhci, "Port was marked as USB %u, "
1772 "duplicated as USB %u\n",
1773 xhci->port_array[i], major_revision);
1774 /* Only adjust the roothub port counts if we haven't
1775 * found a similar duplicate.
1776 */
1777 if (xhci->port_array[i] != major_revision &&
1778 xhci->port_array[i] != DUPLICATE_ENTRY) {
1779 if (xhci->port_array[i] == 0x03)
1780 xhci->num_usb3_ports--;
1781 else
1782 xhci->num_usb2_ports--;
1783 xhci->port_array[i] = DUPLICATE_ENTRY;
1784 }
1785 /* FIXME: Should we disable the port? */
1786 continue;
1787 }
1788 xhci->port_array[i] = major_revision;
1789 if (major_revision == 0x03)
1790 xhci->num_usb3_ports++;
1791 else
1792 xhci->num_usb2_ports++;
1793 }
1794 /* FIXME: Should we disable ports not in the Extended Capabilities? */
1795}
1796
1797/*
1798 * Scan the Extended Capabilities for the "Supported Protocol Capabilities" that
1799 * specify what speeds each port is supposed to be. We can't count on the port
1800 * speed bits in the PORTSC register being correct until a device is connected,
1801 * but we need to set up the two fake roothubs with the correct number of USB
1802 * 3.0 and USB 2.0 ports at host controller initialization time.
1803 */
1804static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
1805{
1806 __le32 __iomem *addr;
1807 u32 offset;
1808 unsigned int num_ports;
1809 int i, port_index;
1810
1811 addr = &xhci->cap_regs->hcc_params;
1812 offset = XHCI_HCC_EXT_CAPS(xhci_readl(xhci, addr));
1813 if (offset == 0) {
1814 xhci_err(xhci, "No Extended Capability registers, "
1815 "unable to set up roothub.\n");
1816 return -ENODEV;
1817 }
1818
1819 num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
1820 xhci->port_array = kzalloc(sizeof(*xhci->port_array)*num_ports, flags);
1821 if (!xhci->port_array)
1822 return -ENOMEM;
1823
1824 /*
1825 * For whatever reason, the first capability offset is from the
1826 * capability register base, not from the HCCPARAMS register.
1827 * See section 5.3.6 for offset calculation.
1828 */
1829 addr = &xhci->cap_regs->hc_capbase + offset;
1830 while (1) {
1831 u32 cap_id;
1832
1833 cap_id = xhci_readl(xhci, addr);
1834 if (XHCI_EXT_CAPS_ID(cap_id) == XHCI_EXT_CAPS_PROTOCOL)
1835 xhci_add_in_port(xhci, num_ports, addr,
1836 (u8) XHCI_EXT_PORT_MAJOR(cap_id));
1837 offset = XHCI_EXT_CAPS_NEXT(cap_id);
1838 if (!offset || (xhci->num_usb2_ports + xhci->num_usb3_ports)
1839 == num_ports)
1840 break;
1841 /*
1842 * Once you're into the Extended Capabilities, the offset is
1843 * always relative to the register holding the offset.
1844 */
1845 addr += offset;
1846 }
1847
1848 if (xhci->num_usb2_ports == 0 && xhci->num_usb3_ports == 0) {
1849 xhci_warn(xhci, "No ports on the roothubs?\n");
1850 return -ENODEV;
1851 }
1852 xhci_dbg(xhci, "Found %u USB 2.0 ports and %u USB 3.0 ports.\n",
1853 xhci->num_usb2_ports, xhci->num_usb3_ports);
1854
1855 /* Place limits on the number of roothub ports so that the hub
1856 * descriptors aren't longer than the USB core will allocate.
1857 */
1858 if (xhci->num_usb3_ports > 15) {
1859 xhci_dbg(xhci, "Limiting USB 3.0 roothub ports to 15.\n");
1860 xhci->num_usb3_ports = 15;
1861 }
1862 if (xhci->num_usb2_ports > USB_MAXCHILDREN) {
1863 xhci_dbg(xhci, "Limiting USB 2.0 roothub ports to %u.\n",
1864 USB_MAXCHILDREN);
1865 xhci->num_usb2_ports = USB_MAXCHILDREN;
1866 }
1867
1868 /*
1869 * Note we could have all USB 3.0 ports, or all USB 2.0 ports.
1870 * Not sure how the USB core will handle a hub with no ports...
1871 */
1872 if (xhci->num_usb2_ports) {
1873 xhci->usb2_ports = kmalloc(sizeof(*xhci->usb2_ports)*
1874 xhci->num_usb2_ports, flags);
1875 if (!xhci->usb2_ports)
1876 return -ENOMEM;
1877
1878 port_index = 0;
1879 for (i = 0; i < num_ports; i++) {
1880 if (xhci->port_array[i] == 0x03 ||
1881 xhci->port_array[i] == 0 ||
1882 xhci->port_array[i] == DUPLICATE_ENTRY)
1883 continue;
1884
1885 xhci->usb2_ports[port_index] =
1886 &xhci->op_regs->port_status_base +
1887 NUM_PORT_REGS*i;
1888 xhci_dbg(xhci, "USB 2.0 port at index %u, "
1889 "addr = %p\n", i,
1890 xhci->usb2_ports[port_index]);
1891 port_index++;
1892 if (port_index == xhci->num_usb2_ports)
1893 break;
1894 }
1895 }
1896 if (xhci->num_usb3_ports) {
1897 xhci->usb3_ports = kmalloc(sizeof(*xhci->usb3_ports)*
1898 xhci->num_usb3_ports, flags);
1899 if (!xhci->usb3_ports)
1900 return -ENOMEM;
1901
1902 port_index = 0;
1903 for (i = 0; i < num_ports; i++)
1904 if (xhci->port_array[i] == 0x03) {
1905 xhci->usb3_ports[port_index] =
1906 &xhci->op_regs->port_status_base +
1907 NUM_PORT_REGS*i;
1908 xhci_dbg(xhci, "USB 3.0 port at index %u, "
1909 "addr = %p\n", i,
1910 xhci->usb3_ports[port_index]);
1911 port_index++;
1912 if (port_index == xhci->num_usb3_ports)
1913 break;
1914 }
1915 }
1916 return 0;
1917}
1627 1918
1628int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) 1919int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1629{ 1920{
@@ -1730,11 +2021,11 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1730 val &= DBOFF_MASK; 2021 val &= DBOFF_MASK;
1731 xhci_dbg(xhci, "// Doorbell array is located at offset 0x%x" 2022 xhci_dbg(xhci, "// Doorbell array is located at offset 0x%x"
1732 " from cap regs base addr\n", val); 2023 " from cap regs base addr\n", val);
1733 xhci->dba = (void *) xhci->cap_regs + val; 2024 xhci->dba = (void __iomem *) xhci->cap_regs + val;
1734 xhci_dbg_regs(xhci); 2025 xhci_dbg_regs(xhci);
1735 xhci_print_run_regs(xhci); 2026 xhci_print_run_regs(xhci);
1736 /* Set ir_set to interrupt register set 0 */ 2027 /* Set ir_set to interrupt register set 0 */
1737 xhci->ir_set = (void *) xhci->run_regs->ir_set; 2028 xhci->ir_set = &xhci->run_regs->ir_set[0];
1738 2029
1739 /* 2030 /*
1740 * Event ring setup: Allocate a normal ring, but also setup 2031 * Event ring setup: Allocate a normal ring, but also setup
@@ -1765,8 +2056,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1765 /* set ring base address and size for each segment table entry */ 2056 /* set ring base address and size for each segment table entry */
1766 for (val = 0, seg = xhci->event_ring->first_seg; val < ERST_NUM_SEGS; val++) { 2057 for (val = 0, seg = xhci->event_ring->first_seg; val < ERST_NUM_SEGS; val++) {
1767 struct xhci_erst_entry *entry = &xhci->erst.entries[val]; 2058 struct xhci_erst_entry *entry = &xhci->erst.entries[val];
1768 entry->seg_addr = seg->dma; 2059 entry->seg_addr = cpu_to_le64(seg->dma);
1769 entry->seg_size = TRBS_PER_SEGMENT; 2060 entry->seg_size = cpu_to_le32(TRBS_PER_SEGMENT);
1770 entry->rsvd = 0; 2061 entry->rsvd = 0;
1771 seg = seg->next; 2062 seg = seg->next;
1772 } 2063 }
@@ -1791,7 +2082,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1791 /* Set the event ring dequeue address */ 2082 /* Set the event ring dequeue address */
1792 xhci_set_hc_event_deq(xhci); 2083 xhci_set_hc_event_deq(xhci);
1793 xhci_dbg(xhci, "Wrote ERST address to ir_set 0.\n"); 2084 xhci_dbg(xhci, "Wrote ERST address to ir_set 0.\n");
1794 xhci_print_ir_set(xhci, xhci->ir_set, 0); 2085 xhci_print_ir_set(xhci, 0);
1795 2086
1796 /* 2087 /*
1797 * XXX: Might need to set the Interrupter Moderation Register to 2088 * XXX: Might need to set the Interrupter Moderation Register to
@@ -1801,9 +2092,15 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1801 init_completion(&xhci->addr_dev); 2092 init_completion(&xhci->addr_dev);
1802 for (i = 0; i < MAX_HC_SLOTS; ++i) 2093 for (i = 0; i < MAX_HC_SLOTS; ++i)
1803 xhci->devs[i] = NULL; 2094 xhci->devs[i] = NULL;
2095 for (i = 0; i < USB_MAXCHILDREN; ++i) {
2096 xhci->bus_state[0].resume_done[i] = 0;
2097 xhci->bus_state[1].resume_done[i] = 0;
2098 }
1804 2099
1805 if (scratchpad_alloc(xhci, flags)) 2100 if (scratchpad_alloc(xhci, flags))
1806 goto fail; 2101 goto fail;
2102 if (xhci_setup_port_arrays(xhci, flags))
2103 goto fail;
1807 2104
1808 return 0; 2105 return 0;
1809 2106
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index f7efe025beda..cb16de213f64 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -21,6 +21,7 @@
21 */ 21 */
22 22
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/slab.h>
24 25
25#include "xhci.h" 26#include "xhci.h"
26 27
@@ -28,6 +29,9 @@
28#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73 29#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
29#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000 30#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
30 31
32#define PCI_VENDOR_ID_ETRON 0x1b6f
33#define PCI_DEVICE_ID_ASROCK_P67 0x7023
34
31static const char hcd_name[] = "xhci_hcd"; 35static const char hcd_name[] = "xhci_hcd";
32 36
33/* called after powerup, by probe or system-pm "wakeup" */ 37/* called after powerup, by probe or system-pm "wakeup" */
@@ -50,13 +54,45 @@ static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
50/* called during probe() after chip reset completes */ 54/* called during probe() after chip reset completes */
51static int xhci_pci_setup(struct usb_hcd *hcd) 55static int xhci_pci_setup(struct usb_hcd *hcd)
52{ 56{
53 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 57 struct xhci_hcd *xhci;
54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 58 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
55 int retval; 59 int retval;
56 u32 temp; 60 u32 temp;
57 61
58 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; 62 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2;
59 63
64 if (usb_hcd_is_primary_hcd(hcd)) {
65 xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL);
66 if (!xhci)
67 return -ENOMEM;
68 *((struct xhci_hcd **) hcd->hcd_priv) = xhci;
69 xhci->main_hcd = hcd;
70 /* Mark the first roothub as being USB 2.0.
71 * The xHCI driver will register the USB 3.0 roothub.
72 */
73 hcd->speed = HCD_USB2;
74 hcd->self.root_hub->speed = USB_SPEED_HIGH;
75 /*
76 * USB 2.0 roothub under xHCI has an integrated TT,
77 * (rate matching hub) as opposed to having an OHCI/UHCI
78 * companion controller.
79 */
80 hcd->has_tt = 1;
81 } else {
82 /* xHCI private pointer was set in xhci_pci_probe for the second
83 * registered roothub.
84 */
85 xhci = hcd_to_xhci(hcd);
86 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
87 if (HCC_64BIT_ADDR(temp)) {
88 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
89 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64));
90 } else {
91 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32));
92 }
93 return 0;
94 }
95
60 xhci->cap_regs = hcd->regs; 96 xhci->cap_regs = hcd->regs;
61 xhci->op_regs = hcd->regs + 97 xhci->op_regs = hcd->regs +
62 HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); 98 HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase));
@@ -73,25 +109,50 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
73 109
74 /* Look for vendor-specific quirks */ 110 /* Look for vendor-specific quirks */
75 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && 111 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
76 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK && 112 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK) {
77 pdev->revision == 0x0) { 113 if (pdev->revision == 0x0) {
78 xhci->quirks |= XHCI_RESET_EP_QUIRK; 114 xhci->quirks |= XHCI_RESET_EP_QUIRK;
79 xhci_dbg(xhci, "QUIRK: Fresco Logic xHC needs configure" 115 xhci_dbg(xhci, "QUIRK: Fresco Logic xHC needs configure"
80 " endpoint cmd after reset endpoint\n"); 116 " endpoint cmd after reset endpoint\n");
117 }
118 /* Fresco Logic confirms: all revisions of this chip do not
119 * support MSI, even though some of them claim to in their PCI
120 * capabilities.
121 */
122 xhci->quirks |= XHCI_BROKEN_MSI;
123 xhci_dbg(xhci, "QUIRK: Fresco Logic revision %u "
124 "has broken MSI implementation\n",
125 pdev->revision);
81 } 126 }
127
82 if (pdev->vendor == PCI_VENDOR_ID_NEC) 128 if (pdev->vendor == PCI_VENDOR_ID_NEC)
83 xhci->quirks |= XHCI_NEC_HOST; 129 xhci->quirks |= XHCI_NEC_HOST;
84 130
131 /* AMD PLL quirk */
132 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
133 xhci->quirks |= XHCI_AMD_PLL_FIX;
134 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
135 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
136 xhci->quirks |= XHCI_SPURIOUS_SUCCESS;
137 xhci->quirks |= XHCI_EP_LIMIT_QUIRK;
138 xhci->limit_active_eps = 64;
139 }
140 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
141 pdev->device == PCI_DEVICE_ID_ASROCK_P67) {
142 xhci->quirks |= XHCI_RESET_ON_RESUME;
143 xhci_dbg(xhci, "QUIRK: Resetting on resume\n");
144 }
145
85 /* Make sure the HC is halted. */ 146 /* Make sure the HC is halted. */
86 retval = xhci_halt(xhci); 147 retval = xhci_halt(xhci);
87 if (retval) 148 if (retval)
88 return retval; 149 goto error;
89 150
90 xhci_dbg(xhci, "Resetting HCD\n"); 151 xhci_dbg(xhci, "Resetting HCD\n");
91 /* Reset the internal HC memory state and registers. */ 152 /* Reset the internal HC memory state and registers. */
92 retval = xhci_reset(xhci); 153 retval = xhci_reset(xhci);
93 if (retval) 154 if (retval)
94 return retval; 155 goto error;
95 xhci_dbg(xhci, "Reset complete\n"); 156 xhci_dbg(xhci, "Reset complete\n");
96 157
97 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); 158 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
@@ -106,33 +167,152 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
106 /* Initialize HCD and host controller data structures. */ 167 /* Initialize HCD and host controller data structures. */
107 retval = xhci_init(hcd); 168 retval = xhci_init(hcd);
108 if (retval) 169 if (retval)
109 return retval; 170 goto error;
110 xhci_dbg(xhci, "Called HCD init\n"); 171 xhci_dbg(xhci, "Called HCD init\n");
111 172
112 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); 173 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn);
113 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); 174 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn);
114 175
115 /* Find any debug ports */ 176 /* Find any debug ports */
116 return xhci_pci_reinit(xhci, pdev); 177 retval = xhci_pci_reinit(xhci, pdev);
178 if (!retval)
179 return retval;
180
181error:
182 kfree(xhci);
183 return retval;
117} 184}
118 185
186/*
187 * We need to register our own PCI probe function (instead of the USB core's
188 * function) in order to create a second roothub under xHCI.
189 */
190static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
191{
192 int retval;
193 struct xhci_hcd *xhci;
194 struct hc_driver *driver;
195 struct usb_hcd *hcd;
196
197 driver = (struct hc_driver *)id->driver_data;
198 /* Register the USB 2.0 roothub.
199 * FIXME: USB core must know to register the USB 2.0 roothub first.
200 * This is sort of silly, because we could just set the HCD driver flags
201 * to say USB 2.0, but I'm not sure what the implications would be in
202 * the other parts of the HCD code.
203 */
204 retval = usb_hcd_pci_probe(dev, id);
205
206 if (retval)
207 return retval;
208
209 /* USB 2.0 roothub is stored in the PCI device now. */
210 hcd = dev_get_drvdata(&dev->dev);
211 xhci = hcd_to_xhci(hcd);
212 xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev,
213 pci_name(dev), hcd);
214 if (!xhci->shared_hcd) {
215 retval = -ENOMEM;
216 goto dealloc_usb2_hcd;
217 }
218
219 /* Set the xHCI pointer before xhci_pci_setup() (aka hcd_driver.reset)
220 * is called by usb_add_hcd().
221 */
222 *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
223
224 retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
225 IRQF_DISABLED | IRQF_SHARED);
226 if (retval)
227 goto put_usb3_hcd;
228 /* Roothub already marked as USB 3.0 speed */
229 return 0;
230
231put_usb3_hcd:
232 usb_put_hcd(xhci->shared_hcd);
233dealloc_usb2_hcd:
234 usb_hcd_pci_remove(dev);
235 return retval;
236}
237
238static void xhci_pci_remove(struct pci_dev *dev)
239{
240 struct xhci_hcd *xhci;
241
242 xhci = hcd_to_xhci(pci_get_drvdata(dev));
243 if (xhci->shared_hcd) {
244 usb_remove_hcd(xhci->shared_hcd);
245 usb_put_hcd(xhci->shared_hcd);
246 }
247 usb_hcd_pci_remove(dev);
248 kfree(xhci);
249}
250
251#ifdef CONFIG_PM
252static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
253{
254 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
255 int retval = 0;
256
257 if (hcd->state != HC_STATE_SUSPENDED ||
258 xhci->shared_hcd->state != HC_STATE_SUSPENDED)
259 return -EINVAL;
260
261 retval = xhci_suspend(xhci);
262
263 return retval;
264}
265
266static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
267{
268 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
269 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
270 int retval = 0;
271
272 /* The BIOS on systems with the Intel Panther Point chipset may or may
273 * not support xHCI natively. That means that during system resume, it
274 * may switch the ports back to EHCI so that users can use their
275 * keyboard to select a kernel from GRUB after resume from hibernate.
276 *
277 * The BIOS is supposed to remember whether the OS had xHCI ports
278 * enabled before resume, and switch the ports back to xHCI when the
279 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
280 * writers.
281 *
282 * Unconditionally switch the ports back to xHCI after a system resume.
283 * We can't tell whether the EHCI or xHCI controller will be resumed
284 * first, so we have to do the port switchover in both drivers. Writing
285 * a '1' to the port switchover registers should have no effect if the
286 * port was already switched over.
287 */
288 if (usb_is_intel_switchable_xhci(pdev))
289 usb_enable_xhci_ports(pdev);
290
291 retval = xhci_resume(xhci, hibernated);
292 return retval;
293}
294#endif /* CONFIG_PM */
295
119static const struct hc_driver xhci_pci_hc_driver = { 296static const struct hc_driver xhci_pci_hc_driver = {
120 .description = hcd_name, 297 .description = hcd_name,
121 .product_desc = "xHCI Host Controller", 298 .product_desc = "xHCI Host Controller",
122 .hcd_priv_size = sizeof(struct xhci_hcd), 299 .hcd_priv_size = sizeof(struct xhci_hcd *),
123 300
124 /* 301 /*
125 * generic hardware linkage 302 * generic hardware linkage
126 */ 303 */
127 .irq = xhci_irq, 304 .irq = xhci_irq,
128 .flags = HCD_MEMORY | HCD_USB3, 305 .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
129 306
130 /* 307 /*
131 * basic lifecycle operations 308 * basic lifecycle operations
132 */ 309 */
133 .reset = xhci_pci_setup, 310 .reset = xhci_pci_setup,
134 .start = xhci_run, 311 .start = xhci_run,
135 /* suspend and resume implemented later */ 312#ifdef CONFIG_PM
313 .pci_suspend = xhci_pci_suspend,
314 .pci_resume = xhci_pci_resume,
315#endif
136 .stop = xhci_stop, 316 .stop = xhci_stop,
137 .shutdown = xhci_shutdown, 317 .shutdown = xhci_shutdown,
138 318
@@ -152,7 +332,7 @@ static const struct hc_driver xhci_pci_hc_driver = {
152 .reset_bandwidth = xhci_reset_bandwidth, 332 .reset_bandwidth = xhci_reset_bandwidth,
153 .address_device = xhci_address_device, 333 .address_device = xhci_address_device,
154 .update_hub_device = xhci_update_hub_device, 334 .update_hub_device = xhci_update_hub_device,
155 .reset_device = xhci_reset_device, 335 .reset_device = xhci_discover_or_reset_device,
156 336
157 /* 337 /*
158 * scheduling support 338 * scheduling support
@@ -162,6 +342,8 @@ static const struct hc_driver xhci_pci_hc_driver = {
162 /* Root hub support */ 342 /* Root hub support */
163 .hub_control = xhci_hub_control, 343 .hub_control = xhci_hub_control,
164 .hub_status_data = xhci_hub_status_data, 344 .hub_status_data = xhci_hub_status_data,
345 .bus_suspend = xhci_bus_suspend,
346 .bus_resume = xhci_bus_resume,
165}; 347};
166 348
167/*-------------------------------------------------------------------------*/ 349/*-------------------------------------------------------------------------*/
@@ -181,11 +363,16 @@ static struct pci_driver xhci_pci_driver = {
181 .name = (char *) hcd_name, 363 .name = (char *) hcd_name,
182 .id_table = pci_ids, 364 .id_table = pci_ids,
183 365
184 .probe = usb_hcd_pci_probe, 366 .probe = xhci_pci_probe,
185 .remove = usb_hcd_pci_remove, 367 .remove = xhci_pci_remove,
186 /* suspend and resume implemented later */ 368 /* suspend and resume implemented later */
187 369
188 .shutdown = usb_hcd_pci_shutdown, 370 .shutdown = usb_hcd_pci_shutdown,
371#ifdef CONFIG_PM_SLEEP
372 .driver = {
373 .pm = &usb_hcd_pci_pm_ops
374 },
375#endif
189}; 376};
190 377
191int xhci_register_pci(void) 378int xhci_register_pci(void)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 48e60d166ff0..70cacbbe7fb9 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -68,6 +68,10 @@
68#include <linux/slab.h> 68#include <linux/slab.h>
69#include "xhci.h" 69#include "xhci.h"
70 70
71static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci,
72 struct xhci_virt_device *virt_dev,
73 struct xhci_event_cmd *event);
74
71/* 75/*
72 * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA 76 * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA
73 * address of the TRB. 77 * address of the TRB.
@@ -89,33 +93,35 @@ dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg,
89/* Does this link TRB point to the first segment in a ring, 93/* Does this link TRB point to the first segment in a ring,
90 * or was the previous TRB the last TRB on the last segment in the ERST? 94 * or was the previous TRB the last TRB on the last segment in the ERST?
91 */ 95 */
92static inline bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring *ring, 96static bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring *ring,
93 struct xhci_segment *seg, union xhci_trb *trb) 97 struct xhci_segment *seg, union xhci_trb *trb)
94{ 98{
95 if (ring == xhci->event_ring) 99 if (ring == xhci->event_ring)
96 return (trb == &seg->trbs[TRBS_PER_SEGMENT]) && 100 return (trb == &seg->trbs[TRBS_PER_SEGMENT]) &&
97 (seg->next == xhci->event_ring->first_seg); 101 (seg->next == xhci->event_ring->first_seg);
98 else 102 else
99 return trb->link.control & LINK_TOGGLE; 103 return le32_to_cpu(trb->link.control) & LINK_TOGGLE;
100} 104}
101 105
102/* Is this TRB a link TRB or was the last TRB the last TRB in this event ring 106/* Is this TRB a link TRB or was the last TRB the last TRB in this event ring
103 * segment? I.e. would the updated event TRB pointer step off the end of the 107 * segment? I.e. would the updated event TRB pointer step off the end of the
104 * event seg? 108 * event seg?
105 */ 109 */
106static inline int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, 110static int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
107 struct xhci_segment *seg, union xhci_trb *trb) 111 struct xhci_segment *seg, union xhci_trb *trb)
108{ 112{
109 if (ring == xhci->event_ring) 113 if (ring == xhci->event_ring)
110 return trb == &seg->trbs[TRBS_PER_SEGMENT]; 114 return trb == &seg->trbs[TRBS_PER_SEGMENT];
111 else 115 else
112 return (trb->link.control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK); 116 return (le32_to_cpu(trb->link.control) & TRB_TYPE_BITMASK)
117 == TRB_TYPE(TRB_LINK);
113} 118}
114 119
115static inline int enqueue_is_link_trb(struct xhci_ring *ring) 120static int enqueue_is_link_trb(struct xhci_ring *ring)
116{ 121{
117 struct xhci_link_trb *link = &ring->enqueue->link; 122 struct xhci_link_trb *link = &ring->enqueue->link;
118 return ((link->control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK)); 123 return ((le32_to_cpu(link->control) & TRB_TYPE_BITMASK) ==
124 TRB_TYPE(TRB_LINK));
119} 125}
120 126
121/* Updates trb to point to the next TRB in the ring, and updates seg if the next 127/* Updates trb to point to the next TRB in the ring, and updates seg if the next
@@ -161,12 +167,6 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer
161 next = ring->dequeue; 167 next = ring->dequeue;
162 } 168 }
163 addr = (unsigned long long) xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue); 169 addr = (unsigned long long) xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue);
164 if (ring == xhci->event_ring)
165 xhci_dbg(xhci, "Event ring deq = 0x%llx (DMA)\n", addr);
166 else if (ring == xhci->cmd_ring)
167 xhci_dbg(xhci, "Command ring deq = 0x%llx (DMA)\n", addr);
168 else
169 xhci_dbg(xhci, "Ring deq = 0x%llx (DMA)\n", addr);
170} 170}
171 171
172/* 172/*
@@ -193,7 +193,7 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring,
193 union xhci_trb *next; 193 union xhci_trb *next;
194 unsigned long long addr; 194 unsigned long long addr;
195 195
196 chain = ring->enqueue->generic.field[3] & TRB_CHAIN; 196 chain = le32_to_cpu(ring->enqueue->generic.field[3]) & TRB_CHAIN;
197 next = ++(ring->enqueue); 197 next = ++(ring->enqueue);
198 198
199 ring->enq_updates++; 199 ring->enq_updates++;
@@ -219,12 +219,14 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring,
219 * (which may mean the chain bit is cleared). 219 * (which may mean the chain bit is cleared).
220 */ 220 */
221 if (!xhci_link_trb_quirk(xhci)) { 221 if (!xhci_link_trb_quirk(xhci)) {
222 next->link.control &= ~TRB_CHAIN; 222 next->link.control &=
223 next->link.control |= chain; 223 cpu_to_le32(~TRB_CHAIN);
224 next->link.control |=
225 cpu_to_le32(chain);
224 } 226 }
225 /* Give this link TRB to the hardware */ 227 /* Give this link TRB to the hardware */
226 wmb(); 228 wmb();
227 next->link.control ^= TRB_CYCLE; 229 next->link.control ^= cpu_to_le32(TRB_CYCLE);
228 } 230 }
229 /* Toggle the cycle bit after the last ring segment. */ 231 /* Toggle the cycle bit after the last ring segment. */
230 if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) { 232 if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) {
@@ -240,12 +242,6 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring,
240 next = ring->enqueue; 242 next = ring->enqueue;
241 } 243 }
242 addr = (unsigned long long) xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue); 244 addr = (unsigned long long) xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue);
243 if (ring == xhci->event_ring)
244 xhci_dbg(xhci, "Event ring enq = 0x%llx (DMA)\n", addr);
245 else if (ring == xhci->cmd_ring)
246 xhci_dbg(xhci, "Command ring enq = 0x%llx (DMA)\n", addr);
247 else
248 xhci_dbg(xhci, "Ring enq = 0x%llx (DMA)\n", addr);
249} 245}
250 246
251/* 247/*
@@ -304,40 +300,35 @@ static int room_on_ring(struct xhci_hcd *xhci, struct xhci_ring *ring,
304/* Ring the host controller doorbell after placing a command on the ring */ 300/* Ring the host controller doorbell after placing a command on the ring */
305void xhci_ring_cmd_db(struct xhci_hcd *xhci) 301void xhci_ring_cmd_db(struct xhci_hcd *xhci)
306{ 302{
307 u32 temp;
308
309 xhci_dbg(xhci, "// Ding dong!\n"); 303 xhci_dbg(xhci, "// Ding dong!\n");
310 temp = xhci_readl(xhci, &xhci->dba->doorbell[0]) & DB_MASK; 304 xhci_writel(xhci, DB_VALUE_HOST, &xhci->dba->doorbell[0]);
311 xhci_writel(xhci, temp | DB_TARGET_HOST, &xhci->dba->doorbell[0]);
312 /* Flush PCI posted writes */ 305 /* Flush PCI posted writes */
313 xhci_readl(xhci, &xhci->dba->doorbell[0]); 306 xhci_readl(xhci, &xhci->dba->doorbell[0]);
314} 307}
315 308
316static void ring_ep_doorbell(struct xhci_hcd *xhci, 309void xhci_ring_ep_doorbell(struct xhci_hcd *xhci,
317 unsigned int slot_id, 310 unsigned int slot_id,
318 unsigned int ep_index, 311 unsigned int ep_index,
319 unsigned int stream_id) 312 unsigned int stream_id)
320{ 313{
321 struct xhci_virt_ep *ep; 314 __le32 __iomem *db_addr = &xhci->dba->doorbell[slot_id];
322 unsigned int ep_state; 315 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index];
323 u32 field; 316 unsigned int ep_state = ep->ep_state;
324 __u32 __iomem *db_addr = &xhci->dba->doorbell[slot_id];
325 317
326 ep = &xhci->devs[slot_id]->eps[ep_index];
327 ep_state = ep->ep_state;
328 /* Don't ring the doorbell for this endpoint if there are pending 318 /* Don't ring the doorbell for this endpoint if there are pending
329 * cancellations because the we don't want to interrupt processing. 319 * cancellations because we don't want to interrupt processing.
330 * We don't want to restart any stream rings if there's a set dequeue 320 * We don't want to restart any stream rings if there's a set dequeue
331 * pointer command pending because the device can choose to start any 321 * pointer command pending because the device can choose to start any
332 * stream once the endpoint is on the HW schedule. 322 * stream once the endpoint is on the HW schedule.
333 * FIXME - check all the stream rings for pending cancellations. 323 * FIXME - check all the stream rings for pending cancellations.
334 */ 324 */
335 if (!(ep_state & EP_HALT_PENDING) && !(ep_state & SET_DEQ_PENDING) 325 if ((ep_state & EP_HALT_PENDING) || (ep_state & SET_DEQ_PENDING) ||
336 && !(ep_state & EP_HALTED)) { 326 (ep_state & EP_HALTED))
337 field = xhci_readl(xhci, db_addr) & DB_MASK; 327 return;
338 field |= EPI_TO_DB(ep_index) | STREAM_ID_TO_DB(stream_id); 328 xhci_writel(xhci, DB_VALUE(ep_index, stream_id), db_addr);
339 xhci_writel(xhci, field, db_addr); 329 /* The CPU has better things to do at this point than wait for a
340 } 330 * write-posting flush. It'll get there soon enough.
331 */
341} 332}
342 333
343/* Ring the doorbell for any rings with pending URBs */ 334/* Ring the doorbell for any rings with pending URBs */
@@ -353,7 +344,7 @@ static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci,
353 /* A ring has pending URBs if its TD list is not empty */ 344 /* A ring has pending URBs if its TD list is not empty */
354 if (!(ep->ep_state & EP_HAS_STREAMS)) { 345 if (!(ep->ep_state & EP_HAS_STREAMS)) {
355 if (!(list_empty(&ep->ring->td_list))) 346 if (!(list_empty(&ep->ring->td_list)))
356 ring_ep_doorbell(xhci, slot_id, ep_index, 0); 347 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, 0);
357 return; 348 return;
358 } 349 }
359 350
@@ -361,7 +352,8 @@ static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci,
361 stream_id++) { 352 stream_id++) {
362 struct xhci_stream_info *stream_info = ep->stream_info; 353 struct xhci_stream_info *stream_info = ep->stream_info;
363 if (!list_empty(&stream_info->stream_rings[stream_id]->td_list)) 354 if (!list_empty(&stream_info->stream_rings[stream_id]->td_list))
364 ring_ep_doorbell(xhci, slot_id, ep_index, stream_id); 355 xhci_ring_ep_doorbell(xhci, slot_id, ep_index,
356 stream_id);
365 } 357 }
366} 358}
367 359
@@ -380,10 +372,8 @@ static struct xhci_segment *find_trb_seg(
380 while (cur_seg->trbs > trb || 372 while (cur_seg->trbs > trb ||
381 &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) { 373 &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) {
382 generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic; 374 generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic;
383 if ((generic_trb->field[3] & TRB_TYPE_BITMASK) == 375 if (le32_to_cpu(generic_trb->field[3]) & LINK_TOGGLE)
384 TRB_TYPE(TRB_LINK) && 376 *cycle_state ^= 0x1;
385 (generic_trb->field[3] & LINK_TOGGLE))
386 *cycle_state = ~(*cycle_state) & 0x1;
387 cur_seg = cur_seg->next; 377 cur_seg = cur_seg->next;
388 if (cur_seg == start_seg) 378 if (cur_seg == start_seg)
389 /* Looped over the entire list. Oops! */ 379 /* Looped over the entire list. Oops! */
@@ -449,6 +439,10 @@ static struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
449 * any link TRBs with the toggle cycle bit set. 439 * any link TRBs with the toggle cycle bit set.
450 * - Finally we move the dequeue state one TRB further, toggling the cycle bit 440 * - Finally we move the dequeue state one TRB further, toggling the cycle bit
451 * if we've moved it past a link TRB with the toggle cycle bit set. 441 * if we've moved it past a link TRB with the toggle cycle bit set.
442 *
443 * Some of the uses of xhci_generic_trb are grotty, but if they're done
444 * with correct __le32 accesses they should work fine. Only users of this are
445 * in here.
452 */ 446 */
453void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, 447void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
454 unsigned int slot_id, unsigned int ep_index, 448 unsigned int slot_id, unsigned int ep_index,
@@ -474,36 +468,52 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
474 state->new_deq_seg = find_trb_seg(cur_td->start_seg, 468 state->new_deq_seg = find_trb_seg(cur_td->start_seg,
475 dev->eps[ep_index].stopped_trb, 469 dev->eps[ep_index].stopped_trb,
476 &state->new_cycle_state); 470 &state->new_cycle_state);
477 if (!state->new_deq_seg) 471 if (!state->new_deq_seg) {
478 BUG(); 472 WARN_ON(1);
473 return;
474 }
475
479 /* Dig out the cycle state saved by the xHC during the stop ep cmd */ 476 /* Dig out the cycle state saved by the xHC during the stop ep cmd */
480 xhci_dbg(xhci, "Finding endpoint context\n"); 477 xhci_dbg(xhci, "Finding endpoint context\n");
481 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); 478 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
482 state->new_cycle_state = 0x1 & ep_ctx->deq; 479 state->new_cycle_state = 0x1 & le64_to_cpu(ep_ctx->deq);
483 480
484 state->new_deq_ptr = cur_td->last_trb; 481 state->new_deq_ptr = cur_td->last_trb;
485 xhci_dbg(xhci, "Finding segment containing last TRB in TD.\n"); 482 xhci_dbg(xhci, "Finding segment containing last TRB in TD.\n");
486 state->new_deq_seg = find_trb_seg(state->new_deq_seg, 483 state->new_deq_seg = find_trb_seg(state->new_deq_seg,
487 state->new_deq_ptr, 484 state->new_deq_ptr,
488 &state->new_cycle_state); 485 &state->new_cycle_state);
489 if (!state->new_deq_seg) 486 if (!state->new_deq_seg) {
490 BUG(); 487 WARN_ON(1);
488 return;
489 }
491 490
492 trb = &state->new_deq_ptr->generic; 491 trb = &state->new_deq_ptr->generic;
493 if ((trb->field[3] & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK) && 492 if ((le32_to_cpu(trb->field[3]) & TRB_TYPE_BITMASK) ==
494 (trb->field[3] & LINK_TOGGLE)) 493 TRB_TYPE(TRB_LINK) && (le32_to_cpu(trb->field[3]) & LINK_TOGGLE))
495 state->new_cycle_state = ~(state->new_cycle_state) & 0x1; 494 state->new_cycle_state ^= 0x1;
496 next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr); 495 next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr);
497 496
497 /*
498 * If there is only one segment in a ring, find_trb_seg()'s while loop
499 * will not run, and it will return before it has a chance to see if it
500 * needs to toggle the cycle bit. It can't tell if the stalled transfer
501 * ended just before the link TRB on a one-segment ring, or if the TD
502 * wrapped around the top of the ring, because it doesn't have the TD in
503 * question. Look for the one-segment case where stalled TRB's address
504 * is greater than the new dequeue pointer address.
505 */
506 if (ep_ring->first_seg == ep_ring->first_seg->next &&
507 state->new_deq_ptr < dev->eps[ep_index].stopped_trb)
508 state->new_cycle_state ^= 0x1;
509 xhci_dbg(xhci, "Cycle state = 0x%x\n", state->new_cycle_state);
510
498 /* Don't update the ring cycle state for the producer (us). */ 511 /* Don't update the ring cycle state for the producer (us). */
499 xhci_dbg(xhci, "New dequeue segment = %p (virtual)\n", 512 xhci_dbg(xhci, "New dequeue segment = %p (virtual)\n",
500 state->new_deq_seg); 513 state->new_deq_seg);
501 addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr); 514 addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr);
502 xhci_dbg(xhci, "New dequeue pointer = 0x%llx (DMA)\n", 515 xhci_dbg(xhci, "New dequeue pointer = 0x%llx (DMA)\n",
503 (unsigned long long) addr); 516 (unsigned long long) addr);
504 xhci_dbg(xhci, "Setting dequeue pointer in internal ring state.\n");
505 ep_ring->dequeue = state->new_deq_ptr;
506 ep_ring->deq_seg = state->new_deq_seg;
507} 517}
508 518
509static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, 519static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
@@ -515,12 +525,12 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
515 for (cur_seg = cur_td->start_seg, cur_trb = cur_td->first_trb; 525 for (cur_seg = cur_td->start_seg, cur_trb = cur_td->first_trb;
516 true; 526 true;
517 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 527 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
518 if ((cur_trb->generic.field[3] & TRB_TYPE_BITMASK) == 528 if ((le32_to_cpu(cur_trb->generic.field[3]) & TRB_TYPE_BITMASK)
519 TRB_TYPE(TRB_LINK)) { 529 == TRB_TYPE(TRB_LINK)) {
520 /* Unchain any chained Link TRBs, but 530 /* Unchain any chained Link TRBs, but
521 * leave the pointers intact. 531 * leave the pointers intact.
522 */ 532 */
523 cur_trb->generic.field[3] &= ~TRB_CHAIN; 533 cur_trb->generic.field[3] &= cpu_to_le32(~TRB_CHAIN);
524 xhci_dbg(xhci, "Cancel (unchain) link TRB\n"); 534 xhci_dbg(xhci, "Cancel (unchain) link TRB\n");
525 xhci_dbg(xhci, "Address = %p (0x%llx dma); " 535 xhci_dbg(xhci, "Address = %p (0x%llx dma); "
526 "in seg %p (0x%llx dma)\n", 536 "in seg %p (0x%llx dma)\n",
@@ -533,8 +543,9 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
533 cur_trb->generic.field[1] = 0; 543 cur_trb->generic.field[1] = 0;
534 cur_trb->generic.field[2] = 0; 544 cur_trb->generic.field[2] = 0;
535 /* Preserve only the cycle bit of this TRB */ 545 /* Preserve only the cycle bit of this TRB */
536 cur_trb->generic.field[3] &= TRB_CYCLE; 546 cur_trb->generic.field[3] &= cpu_to_le32(TRB_CYCLE);
537 cur_trb->generic.field[3] |= TRB_TYPE(TRB_TR_NOOP); 547 cur_trb->generic.field[3] |= cpu_to_le32(
548 TRB_TYPE(TRB_TR_NOOP));
538 xhci_dbg(xhci, "Cancel TRB %p (0x%llx dma) " 549 xhci_dbg(xhci, "Cancel TRB %p (0x%llx dma) "
539 "in seg %p (0x%llx dma)\n", 550 "in seg %p (0x%llx dma)\n",
540 cur_trb, 551 cur_trb,
@@ -578,7 +589,7 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
578 ep->ep_state |= SET_DEQ_PENDING; 589 ep->ep_state |= SET_DEQ_PENDING;
579} 590}
580 591
581static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, 592static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
582 struct xhci_virt_ep *ep) 593 struct xhci_virt_ep *ep)
583{ 594{
584 ep->ep_state &= ~EP_HALT_PENDING; 595 ep->ep_state &= ~EP_HALT_PENDING;
@@ -594,24 +605,30 @@ static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
594static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, 605static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
595 struct xhci_td *cur_td, int status, char *adjective) 606 struct xhci_td *cur_td, int status, char *adjective)
596{ 607{
597 struct usb_hcd *hcd = xhci_to_hcd(xhci); 608 struct usb_hcd *hcd;
598 struct urb *urb; 609 struct urb *urb;
599 struct urb_priv *urb_priv; 610 struct urb_priv *urb_priv;
600 611
601 urb = cur_td->urb; 612 urb = cur_td->urb;
602 urb_priv = urb->hcpriv; 613 urb_priv = urb->hcpriv;
603 urb_priv->td_cnt++; 614 urb_priv->td_cnt++;
615 hcd = bus_to_hcd(urb->dev->bus);
604 616
605 /* Only giveback urb when this is the last td in urb */ 617 /* Only giveback urb when this is the last td in urb */
606 if (urb_priv->td_cnt == urb_priv->length) { 618 if (urb_priv->td_cnt == urb_priv->length) {
619 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
620 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--;
621 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) {
622 if (xhci->quirks & XHCI_AMD_PLL_FIX)
623 usb_amd_quirk_pll_enable();
624 }
625 }
607 usb_hcd_unlink_urb_from_ep(hcd, urb); 626 usb_hcd_unlink_urb_from_ep(hcd, urb);
608 xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, urb);
609 627
610 spin_unlock(&xhci->lock); 628 spin_unlock(&xhci->lock);
611 usb_hcd_giveback_urb(hcd, urb, status); 629 usb_hcd_giveback_urb(hcd, urb, status);
612 xhci_urb_free_priv(xhci, urb_priv); 630 xhci_urb_free_priv(xhci, urb_priv);
613 spin_lock(&xhci->lock); 631 spin_lock(&xhci->lock);
614 xhci_dbg(xhci, "%s URB given back\n", adjective);
615 } 632 }
616} 633}
617 634
@@ -626,10 +643,11 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
626 * bit cleared) so that the HW will skip over them. 643 * bit cleared) so that the HW will skip over them.
627 */ 644 */
628static void handle_stopped_endpoint(struct xhci_hcd *xhci, 645static void handle_stopped_endpoint(struct xhci_hcd *xhci,
629 union xhci_trb *trb) 646 union xhci_trb *trb, struct xhci_event_cmd *event)
630{ 647{
631 unsigned int slot_id; 648 unsigned int slot_id;
632 unsigned int ep_index; 649 unsigned int ep_index;
650 struct xhci_virt_device *virt_dev;
633 struct xhci_ring *ep_ring; 651 struct xhci_ring *ep_ring;
634 struct xhci_virt_ep *ep; 652 struct xhci_virt_ep *ep;
635 struct list_head *entry; 653 struct list_head *entry;
@@ -638,13 +656,30 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
638 656
639 struct xhci_dequeue_state deq_state; 657 struct xhci_dequeue_state deq_state;
640 658
659 if (unlikely(TRB_TO_SUSPEND_PORT(
660 le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])))) {
661 slot_id = TRB_TO_SLOT_ID(
662 le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3]));
663 virt_dev = xhci->devs[slot_id];
664 if (virt_dev)
665 handle_cmd_in_cmd_wait_list(xhci, virt_dev,
666 event);
667 else
668 xhci_warn(xhci, "Stop endpoint command "
669 "completion for disabled slot %u\n",
670 slot_id);
671 return;
672 }
673
641 memset(&deq_state, 0, sizeof(deq_state)); 674 memset(&deq_state, 0, sizeof(deq_state));
642 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 675 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3]));
643 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 676 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3]));
644 ep = &xhci->devs[slot_id]->eps[ep_index]; 677 ep = &xhci->devs[slot_id]->eps[ep_index];
645 678
646 if (list_empty(&ep->cancelled_td_list)) { 679 if (list_empty(&ep->cancelled_td_list)) {
647 xhci_stop_watchdog_timer_in_irq(xhci, ep); 680 xhci_stop_watchdog_timer_in_irq(xhci, ep);
681 ep->stopped_td = NULL;
682 ep->stopped_trb = NULL;
648 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); 683 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
649 return; 684 return;
650 } 685 }
@@ -803,8 +838,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
803 if (ret < 0) { 838 if (ret < 0) {
804 /* This is bad; the host is not responding to commands and it's 839 /* This is bad; the host is not responding to commands and it's
805 * not allowing itself to be halted. At least interrupts are 840 * not allowing itself to be halted. At least interrupts are
806 * disabled, so we can set HC_STATE_HALT and notify the 841 * disabled. If we call usb_hc_died(), it will attempt to
807 * USB core. But if we call usb_hc_died(), it will attempt to
808 * disconnect all device drivers under this host. Those 842 * disconnect all device drivers under this host. Those
809 * disconnect() methods will wait for all URBs to be unlinked, 843 * disconnect() methods will wait for all URBs to be unlinked,
810 * so we must complete them. 844 * so we must complete them.
@@ -849,9 +883,8 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
849 } 883 }
850 } 884 }
851 spin_unlock(&xhci->lock); 885 spin_unlock(&xhci->lock);
852 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
853 xhci_dbg(xhci, "Calling usb_hc_died()\n"); 886 xhci_dbg(xhci, "Calling usb_hc_died()\n");
854 usb_hc_died(xhci_to_hcd(xhci)); 887 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd);
855 xhci_dbg(xhci, "xHCI host controller is dead.\n"); 888 xhci_dbg(xhci, "xHCI host controller is dead.\n");
856} 889}
857 890
@@ -874,9 +907,9 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
874 struct xhci_ep_ctx *ep_ctx; 907 struct xhci_ep_ctx *ep_ctx;
875 struct xhci_slot_ctx *slot_ctx; 908 struct xhci_slot_ctx *slot_ctx;
876 909
877 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 910 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3]));
878 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 911 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3]));
879 stream_id = TRB_TO_STREAM_ID(trb->generic.field[2]); 912 stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2]));
880 dev = xhci->devs[slot_id]; 913 dev = xhci->devs[slot_id];
881 914
882 ep_ring = xhci_stream_id_to_ring(dev, ep_index, stream_id); 915 ep_ring = xhci_stream_id_to_ring(dev, ep_index, stream_id);
@@ -892,11 +925,11 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
892 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); 925 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
893 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); 926 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
894 927
895 if (GET_COMP_CODE(event->status) != COMP_SUCCESS) { 928 if (GET_COMP_CODE(le32_to_cpu(event->status)) != COMP_SUCCESS) {
896 unsigned int ep_state; 929 unsigned int ep_state;
897 unsigned int slot_state; 930 unsigned int slot_state;
898 931
899 switch (GET_COMP_CODE(event->status)) { 932 switch (GET_COMP_CODE(le32_to_cpu(event->status))) {
900 case COMP_TRB_ERR: 933 case COMP_TRB_ERR:
901 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because " 934 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because "
902 "of stream ID configuration\n"); 935 "of stream ID configuration\n");
@@ -904,9 +937,9 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
904 case COMP_CTX_STATE: 937 case COMP_CTX_STATE:
905 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed due " 938 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed due "
906 "to incorrect slot or ep state.\n"); 939 "to incorrect slot or ep state.\n");
907 ep_state = ep_ctx->ep_info; 940 ep_state = le32_to_cpu(ep_ctx->ep_info);
908 ep_state &= EP_STATE_MASK; 941 ep_state &= EP_STATE_MASK;
909 slot_state = slot_ctx->dev_state; 942 slot_state = le32_to_cpu(slot_ctx->dev_state);
910 slot_state = GET_SLOT_STATE(slot_state); 943 slot_state = GET_SLOT_STATE(slot_state);
911 xhci_dbg(xhci, "Slot state = %u, EP state = %u\n", 944 xhci_dbg(xhci, "Slot state = %u, EP state = %u\n",
912 slot_state, ep_state); 945 slot_state, ep_state);
@@ -918,7 +951,7 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
918 default: 951 default:
919 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown " 952 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown "
920 "completion code of %u.\n", 953 "completion code of %u.\n",
921 GET_COMP_CODE(event->status)); 954 GET_COMP_CODE(le32_to_cpu(event->status)));
922 break; 955 break;
923 } 956 }
924 /* OK what do we do now? The endpoint state is hosed, and we 957 /* OK what do we do now? The endpoint state is hosed, and we
@@ -929,10 +962,27 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
929 */ 962 */
930 } else { 963 } else {
931 xhci_dbg(xhci, "Successful Set TR Deq Ptr cmd, deq = @%08llx\n", 964 xhci_dbg(xhci, "Successful Set TR Deq Ptr cmd, deq = @%08llx\n",
932 ep_ctx->deq); 965 le64_to_cpu(ep_ctx->deq));
966 if (xhci_trb_virt_to_dma(dev->eps[ep_index].queued_deq_seg,
967 dev->eps[ep_index].queued_deq_ptr) ==
968 (le64_to_cpu(ep_ctx->deq) & ~(EP_CTX_CYCLE_MASK))) {
969 /* Update the ring's dequeue segment and dequeue pointer
970 * to reflect the new position.
971 */
972 ep_ring->deq_seg = dev->eps[ep_index].queued_deq_seg;
973 ep_ring->dequeue = dev->eps[ep_index].queued_deq_ptr;
974 } else {
975 xhci_warn(xhci, "Mismatch between completed Set TR Deq "
976 "Ptr command & xHCI internal state.\n");
977 xhci_warn(xhci, "ep deq seg = %p, deq ptr = %p\n",
978 dev->eps[ep_index].queued_deq_seg,
979 dev->eps[ep_index].queued_deq_ptr);
980 }
933 } 981 }
934 982
935 dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING; 983 dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING;
984 dev->eps[ep_index].queued_deq_seg = NULL;
985 dev->eps[ep_index].queued_deq_ptr = NULL;
936 /* Restart any rings with pending URBs */ 986 /* Restart any rings with pending URBs */
937 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); 987 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
938} 988}
@@ -944,13 +994,13 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
944 int slot_id; 994 int slot_id;
945 unsigned int ep_index; 995 unsigned int ep_index;
946 996
947 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 997 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3]));
948 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 998 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3]));
949 /* This command will only fail if the endpoint wasn't halted, 999 /* This command will only fail if the endpoint wasn't halted,
950 * but we don't care. 1000 * but we don't care.
951 */ 1001 */
952 xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n", 1002 xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n",
953 (unsigned int) GET_COMP_CODE(event->status)); 1003 (unsigned int) GET_COMP_CODE(le32_to_cpu(event->status)));
954 1004
955 /* HW with the reset endpoint quirk needs to have a configure endpoint 1005 /* HW with the reset endpoint quirk needs to have a configure endpoint
956 * command complete before the endpoint can be used. Queue that here 1006 * command complete before the endpoint can be used. Queue that here
@@ -987,8 +1037,7 @@ static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci,
987 if (xhci->cmd_ring->dequeue != command->command_trb) 1037 if (xhci->cmd_ring->dequeue != command->command_trb)
988 return 0; 1038 return 0;
989 1039
990 command->status = 1040 command->status = GET_COMP_CODE(le32_to_cpu(event->status));
991 GET_COMP_CODE(event->status);
992 list_del(&command->cmd_list); 1041 list_del(&command->cmd_list);
993 if (command->completion) 1042 if (command->completion)
994 complete(command->completion); 1043 complete(command->completion);
@@ -1000,7 +1049,7 @@ static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci,
1000static void handle_cmd_completion(struct xhci_hcd *xhci, 1049static void handle_cmd_completion(struct xhci_hcd *xhci,
1001 struct xhci_event_cmd *event) 1050 struct xhci_event_cmd *event)
1002{ 1051{
1003 int slot_id = TRB_TO_SLOT_ID(event->flags); 1052 int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
1004 u64 cmd_dma; 1053 u64 cmd_dma;
1005 dma_addr_t cmd_dequeue_dma; 1054 dma_addr_t cmd_dequeue_dma;
1006 struct xhci_input_control_ctx *ctrl_ctx; 1055 struct xhci_input_control_ctx *ctrl_ctx;
@@ -1009,7 +1058,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1009 struct xhci_ring *ep_ring; 1058 struct xhci_ring *ep_ring;
1010 unsigned int ep_state; 1059 unsigned int ep_state;
1011 1060
1012 cmd_dma = event->cmd_trb; 1061 cmd_dma = le64_to_cpu(event->cmd_trb);
1013 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, 1062 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
1014 xhci->cmd_ring->dequeue); 1063 xhci->cmd_ring->dequeue);
1015 /* Is the command ring deq ptr out of sync with the deq seg ptr? */ 1064 /* Is the command ring deq ptr out of sync with the deq seg ptr? */
@@ -1022,17 +1071,23 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1022 xhci->error_bitmask |= 1 << 5; 1071 xhci->error_bitmask |= 1 << 5;
1023 return; 1072 return;
1024 } 1073 }
1025 switch (xhci->cmd_ring->dequeue->generic.field[3] & TRB_TYPE_BITMASK) { 1074 switch (le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])
1075 & TRB_TYPE_BITMASK) {
1026 case TRB_TYPE(TRB_ENABLE_SLOT): 1076 case TRB_TYPE(TRB_ENABLE_SLOT):
1027 if (GET_COMP_CODE(event->status) == COMP_SUCCESS) 1077 if (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_SUCCESS)
1028 xhci->slot_id = slot_id; 1078 xhci->slot_id = slot_id;
1029 else 1079 else
1030 xhci->slot_id = 0; 1080 xhci->slot_id = 0;
1031 complete(&xhci->addr_dev); 1081 complete(&xhci->addr_dev);
1032 break; 1082 break;
1033 case TRB_TYPE(TRB_DISABLE_SLOT): 1083 case TRB_TYPE(TRB_DISABLE_SLOT):
1034 if (xhci->devs[slot_id]) 1084 if (xhci->devs[slot_id]) {
1085 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK)
1086 /* Delete default control endpoint resources */
1087 xhci_free_device_endpoint_resources(xhci,
1088 xhci->devs[slot_id], true);
1035 xhci_free_virt_device(xhci, slot_id); 1089 xhci_free_virt_device(xhci, slot_id);
1090 }
1036 break; 1091 break;
1037 case TRB_TYPE(TRB_CONFIG_EP): 1092 case TRB_TYPE(TRB_CONFIG_EP):
1038 virt_dev = xhci->devs[slot_id]; 1093 virt_dev = xhci->devs[slot_id];
@@ -1049,7 +1104,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1049 ctrl_ctx = xhci_get_input_control_ctx(xhci, 1104 ctrl_ctx = xhci_get_input_control_ctx(xhci,
1050 virt_dev->in_ctx); 1105 virt_dev->in_ctx);
1051 /* Input ctx add_flags are the endpoint index plus one */ 1106 /* Input ctx add_flags are the endpoint index plus one */
1052 ep_index = xhci_last_valid_endpoint(ctrl_ctx->add_flags) - 1; 1107 ep_index = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags)) - 1;
1053 /* A usb_set_interface() call directly after clearing a halted 1108 /* A usb_set_interface() call directly after clearing a halted
1054 * condition may race on this quirky hardware. Not worth 1109 * condition may race on this quirky hardware. Not worth
1055 * worrying about, since this is prototype hardware. Not sure 1110 * worrying about, since this is prototype hardware. Not sure
@@ -1058,8 +1113,8 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1058 */ 1113 */
1059 if (xhci->quirks & XHCI_RESET_EP_QUIRK && 1114 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
1060 ep_index != (unsigned int) -1 && 1115 ep_index != (unsigned int) -1 &&
1061 ctrl_ctx->add_flags - SLOT_FLAG == 1116 le32_to_cpu(ctrl_ctx->add_flags) - SLOT_FLAG ==
1062 ctrl_ctx->drop_flags) { 1117 le32_to_cpu(ctrl_ctx->drop_flags)) {
1063 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; 1118 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
1064 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; 1119 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
1065 if (!(ep_state & EP_HALTED)) 1120 if (!(ep_state & EP_HALTED))
@@ -1076,28 +1131,27 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1076bandwidth_change: 1131bandwidth_change:
1077 xhci_dbg(xhci, "Completed config ep cmd\n"); 1132 xhci_dbg(xhci, "Completed config ep cmd\n");
1078 xhci->devs[slot_id]->cmd_status = 1133 xhci->devs[slot_id]->cmd_status =
1079 GET_COMP_CODE(event->status); 1134 GET_COMP_CODE(le32_to_cpu(event->status));
1080 complete(&xhci->devs[slot_id]->cmd_completion); 1135 complete(&xhci->devs[slot_id]->cmd_completion);
1081 break; 1136 break;
1082 case TRB_TYPE(TRB_EVAL_CONTEXT): 1137 case TRB_TYPE(TRB_EVAL_CONTEXT):
1083 virt_dev = xhci->devs[slot_id]; 1138 virt_dev = xhci->devs[slot_id];
1084 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) 1139 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1085 break; 1140 break;
1086 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status); 1141 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(le32_to_cpu(event->status));
1087 complete(&xhci->devs[slot_id]->cmd_completion); 1142 complete(&xhci->devs[slot_id]->cmd_completion);
1088 break; 1143 break;
1089 case TRB_TYPE(TRB_ADDR_DEV): 1144 case TRB_TYPE(TRB_ADDR_DEV):
1090 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status); 1145 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(le32_to_cpu(event->status));
1091 complete(&xhci->addr_dev); 1146 complete(&xhci->addr_dev);
1092 break; 1147 break;
1093 case TRB_TYPE(TRB_STOP_RING): 1148 case TRB_TYPE(TRB_STOP_RING):
1094 handle_stopped_endpoint(xhci, xhci->cmd_ring->dequeue); 1149 handle_stopped_endpoint(xhci, xhci->cmd_ring->dequeue, event);
1095 break; 1150 break;
1096 case TRB_TYPE(TRB_SET_DEQ): 1151 case TRB_TYPE(TRB_SET_DEQ):
1097 handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue); 1152 handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue);
1098 break; 1153 break;
1099 case TRB_TYPE(TRB_CMD_NOOP): 1154 case TRB_TYPE(TRB_CMD_NOOP):
1100 ++xhci->noops_handled;
1101 break; 1155 break;
1102 case TRB_TYPE(TRB_RESET_EP): 1156 case TRB_TYPE(TRB_RESET_EP):
1103 handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); 1157 handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue);
@@ -1105,7 +1159,7 @@ bandwidth_change:
1105 case TRB_TYPE(TRB_RESET_DEV): 1159 case TRB_TYPE(TRB_RESET_DEV):
1106 xhci_dbg(xhci, "Completed reset device command.\n"); 1160 xhci_dbg(xhci, "Completed reset device command.\n");
1107 slot_id = TRB_TO_SLOT_ID( 1161 slot_id = TRB_TO_SLOT_ID(
1108 xhci->cmd_ring->dequeue->generic.field[3]); 1162 le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3]));
1109 virt_dev = xhci->devs[slot_id]; 1163 virt_dev = xhci->devs[slot_id];
1110 if (virt_dev) 1164 if (virt_dev)
1111 handle_cmd_in_cmd_wait_list(xhci, virt_dev, event); 1165 handle_cmd_in_cmd_wait_list(xhci, virt_dev, event);
@@ -1119,8 +1173,8 @@ bandwidth_change:
1119 break; 1173 break;
1120 } 1174 }
1121 xhci_dbg(xhci, "NEC firmware version %2x.%02x\n", 1175 xhci_dbg(xhci, "NEC firmware version %2x.%02x\n",
1122 NEC_FW_MAJOR(event->status), 1176 NEC_FW_MAJOR(le32_to_cpu(event->status)),
1123 NEC_FW_MINOR(event->status)); 1177 NEC_FW_MINOR(le32_to_cpu(event->status)));
1124 break; 1178 break;
1125 default: 1179 default:
1126 /* Skip over unknown commands on the event ring */ 1180 /* Skip over unknown commands on the event ring */
@@ -1135,32 +1189,175 @@ static void handle_vendor_event(struct xhci_hcd *xhci,
1135{ 1189{
1136 u32 trb_type; 1190 u32 trb_type;
1137 1191
1138 trb_type = TRB_FIELD_TO_TYPE(event->generic.field[3]); 1192 trb_type = TRB_FIELD_TO_TYPE(le32_to_cpu(event->generic.field[3]));
1139 xhci_dbg(xhci, "Vendor specific event TRB type = %u\n", trb_type); 1193 xhci_dbg(xhci, "Vendor specific event TRB type = %u\n", trb_type);
1140 if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST)) 1194 if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST))
1141 handle_cmd_completion(xhci, &event->event_cmd); 1195 handle_cmd_completion(xhci, &event->event_cmd);
1142} 1196}
1143 1197
1198/* @port_id: the one-based port ID from the hardware (indexed from array of all
1199 * port registers -- USB 3.0 and USB 2.0).
1200 *
1201 * Returns a zero-based port number, which is suitable for indexing into each of
1202 * the split roothubs' port arrays and bus state arrays.
1203 */
1204static unsigned int find_faked_portnum_from_hw_portnum(struct usb_hcd *hcd,
1205 struct xhci_hcd *xhci, u32 port_id)
1206{
1207 unsigned int i;
1208 unsigned int num_similar_speed_ports = 0;
1209
1210 /* port_id from the hardware is 1-based, but port_array[], usb3_ports[],
1211 * and usb2_ports are 0-based indexes. Count the number of similar
1212 * speed ports, up to 1 port before this port.
1213 */
1214 for (i = 0; i < (port_id - 1); i++) {
1215 u8 port_speed = xhci->port_array[i];
1216
1217 /*
1218 * Skip ports that don't have known speeds, or have duplicate
1219 * Extended Capabilities port speed entries.
1220 */
1221 if (port_speed == 0 || port_speed == DUPLICATE_ENTRY)
1222 continue;
1223
1224 /*
1225 * USB 3.0 ports are always under a USB 3.0 hub. USB 2.0 and
1226 * 1.1 ports are under the USB 2.0 hub. If the port speed
1227 * matches the device speed, it's a similar speed port.
1228 */
1229 if ((port_speed == 0x03) == (hcd->speed == HCD_USB3))
1230 num_similar_speed_ports++;
1231 }
1232 return num_similar_speed_ports;
1233}
1234
1144static void handle_port_status(struct xhci_hcd *xhci, 1235static void handle_port_status(struct xhci_hcd *xhci,
1145 union xhci_trb *event) 1236 union xhci_trb *event)
1146{ 1237{
1238 struct usb_hcd *hcd;
1147 u32 port_id; 1239 u32 port_id;
1240 u32 temp, temp1;
1241 int max_ports;
1242 int slot_id;
1243 unsigned int faked_port_index;
1244 u8 major_revision;
1245 struct xhci_bus_state *bus_state;
1246 __le32 __iomem **port_array;
1247 bool bogus_port_status = false;
1148 1248
1149 /* Port status change events always have a successful completion code */ 1249 /* Port status change events always have a successful completion code */
1150 if (GET_COMP_CODE(event->generic.field[2]) != COMP_SUCCESS) { 1250 if (GET_COMP_CODE(le32_to_cpu(event->generic.field[2])) != COMP_SUCCESS) {
1151 xhci_warn(xhci, "WARN: xHC returned failed port status event\n"); 1251 xhci_warn(xhci, "WARN: xHC returned failed port status event\n");
1152 xhci->error_bitmask |= 1 << 8; 1252 xhci->error_bitmask |= 1 << 8;
1153 } 1253 }
1154 /* FIXME: core doesn't care about all port link state changes yet */ 1254 port_id = GET_PORT_ID(le32_to_cpu(event->generic.field[0]));
1155 port_id = GET_PORT_ID(event->generic.field[0]);
1156 xhci_dbg(xhci, "Port Status Change Event for port %d\n", port_id); 1255 xhci_dbg(xhci, "Port Status Change Event for port %d\n", port_id);
1157 1256
1257 max_ports = HCS_MAX_PORTS(xhci->hcs_params1);
1258 if ((port_id <= 0) || (port_id > max_ports)) {
1259 xhci_warn(xhci, "Invalid port id %d\n", port_id);
1260 bogus_port_status = true;
1261 goto cleanup;
1262 }
1263
1264 /* Figure out which usb_hcd this port is attached to:
1265 * is it a USB 3.0 port or a USB 2.0/1.1 port?
1266 */
1267 major_revision = xhci->port_array[port_id - 1];
1268 if (major_revision == 0) {
1269 xhci_warn(xhci, "Event for port %u not in "
1270 "Extended Capabilities, ignoring.\n",
1271 port_id);
1272 bogus_port_status = true;
1273 goto cleanup;
1274 }
1275 if (major_revision == DUPLICATE_ENTRY) {
1276 xhci_warn(xhci, "Event for port %u duplicated in"
1277 "Extended Capabilities, ignoring.\n",
1278 port_id);
1279 bogus_port_status = true;
1280 goto cleanup;
1281 }
1282
1283 /*
1284 * Hardware port IDs reported by a Port Status Change Event include USB
1285 * 3.0 and USB 2.0 ports. We want to check if the port has reported a
1286 * resume event, but we first need to translate the hardware port ID
1287 * into the index into the ports on the correct split roothub, and the
1288 * correct bus_state structure.
1289 */
1290 /* Find the right roothub. */
1291 hcd = xhci_to_hcd(xhci);
1292 if ((major_revision == 0x03) != (hcd->speed == HCD_USB3))
1293 hcd = xhci->shared_hcd;
1294 bus_state = &xhci->bus_state[hcd_index(hcd)];
1295 if (hcd->speed == HCD_USB3)
1296 port_array = xhci->usb3_ports;
1297 else
1298 port_array = xhci->usb2_ports;
1299 /* Find the faked port hub number */
1300 faked_port_index = find_faked_portnum_from_hw_portnum(hcd, xhci,
1301 port_id);
1302
1303 temp = xhci_readl(xhci, port_array[faked_port_index]);
1304 if (hcd->state == HC_STATE_SUSPENDED) {
1305 xhci_dbg(xhci, "resume root hub\n");
1306 usb_hcd_resume_root_hub(hcd);
1307 }
1308
1309 if ((temp & PORT_PLC) && (temp & PORT_PLS_MASK) == XDEV_RESUME) {
1310 xhci_dbg(xhci, "port resume event for port %d\n", port_id);
1311
1312 temp1 = xhci_readl(xhci, &xhci->op_regs->command);
1313 if (!(temp1 & CMD_RUN)) {
1314 xhci_warn(xhci, "xHC is not running.\n");
1315 goto cleanup;
1316 }
1317
1318 if (DEV_SUPERSPEED(temp)) {
1319 xhci_dbg(xhci, "resume SS port %d\n", port_id);
1320 temp = xhci_port_state_to_neutral(temp);
1321 temp &= ~PORT_PLS_MASK;
1322 temp |= PORT_LINK_STROBE | XDEV_U0;
1323 xhci_writel(xhci, temp, port_array[faked_port_index]);
1324 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1325 faked_port_index);
1326 if (!slot_id) {
1327 xhci_dbg(xhci, "slot_id is zero\n");
1328 goto cleanup;
1329 }
1330 xhci_ring_device(xhci, slot_id);
1331 xhci_dbg(xhci, "resume SS port %d finished\n", port_id);
1332 /* Clear PORT_PLC */
1333 temp = xhci_readl(xhci, port_array[faked_port_index]);
1334 temp = xhci_port_state_to_neutral(temp);
1335 temp |= PORT_PLC;
1336 xhci_writel(xhci, temp, port_array[faked_port_index]);
1337 } else {
1338 xhci_dbg(xhci, "resume HS port %d\n", port_id);
1339 bus_state->resume_done[faked_port_index] = jiffies +
1340 msecs_to_jiffies(20);
1341 mod_timer(&hcd->rh_timer,
1342 bus_state->resume_done[faked_port_index]);
1343 /* Do the rest in GetPortStatus */
1344 }
1345 }
1346
1347cleanup:
1158 /* Update event ring dequeue pointer before dropping the lock */ 1348 /* Update event ring dequeue pointer before dropping the lock */
1159 inc_deq(xhci, xhci->event_ring, true); 1349 inc_deq(xhci, xhci->event_ring, true);
1160 1350
1351 /* Don't make the USB core poll the roothub if we got a bad port status
1352 * change event. Besides, at that point we can't tell which roothub
1353 * (USB 2.0 or USB 3.0) to kick.
1354 */
1355 if (bogus_port_status)
1356 return;
1357
1161 spin_unlock(&xhci->lock); 1358 spin_unlock(&xhci->lock);
1162 /* Pass this up to the core */ 1359 /* Pass this up to the core */
1163 usb_hcd_poll_rh_status(xhci_to_hcd(xhci)); 1360 usb_hcd_poll_rh_status(hcd);
1164 spin_lock(&xhci->lock); 1361 spin_lock(&xhci->lock);
1165} 1362}
1166 1363
@@ -1261,7 +1458,7 @@ static int xhci_requires_manual_halt_cleanup(struct xhci_hcd *xhci,
1261 * endpoint anyway. Check if a babble halted the 1458 * endpoint anyway. Check if a babble halted the
1262 * endpoint. 1459 * endpoint.
1263 */ 1460 */
1264 if ((ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_HALTED) 1461 if ((le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK) == EP_STATE_HALTED)
1265 return 1; 1462 return 1;
1266 1463
1267 return 0; 1464 return 0;
@@ -1299,12 +1496,12 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td,
1299 struct urb_priv *urb_priv; 1496 struct urb_priv *urb_priv;
1300 u32 trb_comp_code; 1497 u32 trb_comp_code;
1301 1498
1302 slot_id = TRB_TO_SLOT_ID(event->flags); 1499 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
1303 xdev = xhci->devs[slot_id]; 1500 xdev = xhci->devs[slot_id];
1304 ep_index = TRB_TO_EP_ID(event->flags) - 1; 1501 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1;
1305 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1502 ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer));
1306 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1503 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1307 trb_comp_code = GET_COMP_CODE(event->transfer_len); 1504 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len));
1308 1505
1309 if (skip) 1506 if (skip)
1310 goto td_cleanup; 1507 goto td_cleanup;
@@ -1377,8 +1574,17 @@ td_cleanup:
1377 1574
1378 urb_priv->td_cnt++; 1575 urb_priv->td_cnt++;
1379 /* Giveback the urb when all the tds are completed */ 1576 /* Giveback the urb when all the tds are completed */
1380 if (urb_priv->td_cnt == urb_priv->length) 1577 if (urb_priv->td_cnt == urb_priv->length) {
1381 ret = 1; 1578 ret = 1;
1579 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
1580 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--;
1581 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs
1582 == 0) {
1583 if (xhci->quirks & XHCI_AMD_PLL_FIX)
1584 usb_amd_quirk_pll_enable();
1585 }
1586 }
1587 }
1382 } 1588 }
1383 1589
1384 return ret; 1590 return ret;
@@ -1398,12 +1604,12 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1398 struct xhci_ep_ctx *ep_ctx; 1604 struct xhci_ep_ctx *ep_ctx;
1399 u32 trb_comp_code; 1605 u32 trb_comp_code;
1400 1606
1401 slot_id = TRB_TO_SLOT_ID(event->flags); 1607 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
1402 xdev = xhci->devs[slot_id]; 1608 xdev = xhci->devs[slot_id];
1403 ep_index = TRB_TO_EP_ID(event->flags) - 1; 1609 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1;
1404 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1610 ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer));
1405 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1611 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1406 trb_comp_code = GET_COMP_CODE(event->transfer_len); 1612 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len));
1407 1613
1408 xhci_debug_trb(xhci, xhci->event_ring->dequeue); 1614 xhci_debug_trb(xhci, xhci->event_ring->dequeue);
1409 switch (trb_comp_code) { 1615 switch (trb_comp_code) {
@@ -1417,7 +1623,6 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1417 "without IOC set??\n"); 1623 "without IOC set??\n");
1418 *status = -ESHUTDOWN; 1624 *status = -ESHUTDOWN;
1419 } else { 1625 } else {
1420 xhci_dbg(xhci, "Successful control transfer!\n");
1421 *status = 0; 1626 *status = 0;
1422 } 1627 }
1423 break; 1628 break;
@@ -1428,6 +1633,9 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1428 else 1633 else
1429 *status = 0; 1634 *status = 0;
1430 break; 1635 break;
1636 case COMP_STOP_INVAL:
1637 case COMP_STOP:
1638 return finish_td(xhci, td, event_trb, event, ep, status, false);
1431 default: 1639 default:
1432 if (!xhci_requires_manual_halt_cleanup(xhci, 1640 if (!xhci_requires_manual_halt_cleanup(xhci,
1433 ep_ctx, trb_comp_code)) 1641 ep_ctx, trb_comp_code))
@@ -1442,7 +1650,7 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1442 event_trb != td->last_trb) 1650 event_trb != td->last_trb)
1443 td->urb->actual_length = 1651 td->urb->actual_length =
1444 td->urb->transfer_buffer_length 1652 td->urb->transfer_buffer_length
1445 - TRB_LEN(event->transfer_len); 1653 - TRB_LEN(le32_to_cpu(event->transfer_len));
1446 else 1654 else
1447 td->urb->actual_length = 0; 1655 td->urb->actual_length = 0;
1448 1656
@@ -1472,15 +1680,12 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1472 } 1680 }
1473 } else { 1681 } else {
1474 /* Maybe the event was for the data stage? */ 1682 /* Maybe the event was for the data stage? */
1475 if (trb_comp_code != COMP_STOP_INVAL) { 1683 td->urb->actual_length =
1476 /* We didn't stop on a link TRB in the middle */ 1684 td->urb->transfer_buffer_length -
1477 td->urb->actual_length = 1685 TRB_LEN(le32_to_cpu(event->transfer_len));
1478 td->urb->transfer_buffer_length - 1686 xhci_dbg(xhci, "Waiting for status "
1479 TRB_LEN(event->transfer_len); 1687 "stage event\n");
1480 xhci_dbg(xhci, "Waiting for status " 1688 return 0;
1481 "stage event\n");
1482 return 0;
1483 }
1484 } 1689 }
1485 } 1690 }
1486 1691
@@ -1498,97 +1703,102 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1498 struct urb_priv *urb_priv; 1703 struct urb_priv *urb_priv;
1499 int idx; 1704 int idx;
1500 int len = 0; 1705 int len = 0;
1501 int skip_td = 0;
1502 union xhci_trb *cur_trb; 1706 union xhci_trb *cur_trb;
1503 struct xhci_segment *cur_seg; 1707 struct xhci_segment *cur_seg;
1708 struct usb_iso_packet_descriptor *frame;
1504 u32 trb_comp_code; 1709 u32 trb_comp_code;
1710 bool skip_td = false;
1505 1711
1506 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1712 ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer));
1507 trb_comp_code = GET_COMP_CODE(event->transfer_len); 1713 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len));
1508 urb_priv = td->urb->hcpriv; 1714 urb_priv = td->urb->hcpriv;
1509 idx = urb_priv->td_cnt; 1715 idx = urb_priv->td_cnt;
1716 frame = &td->urb->iso_frame_desc[idx];
1510 1717
1511 if (ep->skip) { 1718 /* handle completion code */
1512 /* The transfer is partly done */ 1719 switch (trb_comp_code) {
1513 *status = -EXDEV; 1720 case COMP_SUCCESS:
1514 td->urb->iso_frame_desc[idx].status = -EXDEV; 1721 frame->status = 0;
1515 } else { 1722 break;
1516 /* handle completion code */ 1723 case COMP_SHORT_TX:
1517 switch (trb_comp_code) { 1724 frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ?
1518 case COMP_SUCCESS: 1725 -EREMOTEIO : 0;
1519 td->urb->iso_frame_desc[idx].status = 0; 1726 break;
1520 xhci_dbg(xhci, "Successful isoc transfer!\n"); 1727 case COMP_BW_OVER:
1521 break; 1728 frame->status = -ECOMM;
1522 case COMP_SHORT_TX: 1729 skip_td = true;
1523 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1730 break;
1524 td->urb->iso_frame_desc[idx].status = 1731 case COMP_BUFF_OVER:
1525 -EREMOTEIO; 1732 case COMP_BABBLE:
1526 else 1733 frame->status = -EOVERFLOW;
1527 td->urb->iso_frame_desc[idx].status = 0; 1734 skip_td = true;
1528 break; 1735 break;
1529 case COMP_BW_OVER: 1736 case COMP_DEV_ERR:
1530 td->urb->iso_frame_desc[idx].status = -ECOMM; 1737 case COMP_STALL:
1531 skip_td = 1; 1738 frame->status = -EPROTO;
1532 break; 1739 skip_td = true;
1533 case COMP_BUFF_OVER: 1740 break;
1534 case COMP_BABBLE: 1741 case COMP_STOP:
1535 td->urb->iso_frame_desc[idx].status = -EOVERFLOW; 1742 case COMP_STOP_INVAL:
1536 skip_td = 1; 1743 break;
1537 break; 1744 default:
1538 case COMP_STALL: 1745 frame->status = -1;
1539 td->urb->iso_frame_desc[idx].status = -EPROTO; 1746 break;
1540 skip_td = 1;
1541 break;
1542 case COMP_STOP:
1543 case COMP_STOP_INVAL:
1544 break;
1545 default:
1546 td->urb->iso_frame_desc[idx].status = -1;
1547 break;
1548 }
1549 }
1550
1551 /* calc actual length */
1552 if (ep->skip) {
1553 td->urb->iso_frame_desc[idx].actual_length = 0;
1554 /* Update ring dequeue pointer */
1555 while (ep_ring->dequeue != td->last_trb)
1556 inc_deq(xhci, ep_ring, false);
1557 inc_deq(xhci, ep_ring, false);
1558 return finish_td(xhci, td, event_trb, event, ep, status, true);
1559 } 1747 }
1560 1748
1561 if (trb_comp_code == COMP_SUCCESS || skip_td == 1) { 1749 if (trb_comp_code == COMP_SUCCESS || skip_td) {
1562 td->urb->iso_frame_desc[idx].actual_length = 1750 frame->actual_length = frame->length;
1563 td->urb->iso_frame_desc[idx].length; 1751 td->urb->actual_length += frame->length;
1564 td->urb->actual_length +=
1565 td->urb->iso_frame_desc[idx].length;
1566 } else { 1752 } else {
1567 for (cur_trb = ep_ring->dequeue, 1753 for (cur_trb = ep_ring->dequeue,
1568 cur_seg = ep_ring->deq_seg; cur_trb != event_trb; 1754 cur_seg = ep_ring->deq_seg; cur_trb != event_trb;
1569 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1755 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1570 if ((cur_trb->generic.field[3] & 1756 if ((le32_to_cpu(cur_trb->generic.field[3]) &
1571 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) && 1757 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) &&
1572 (cur_trb->generic.field[3] & 1758 (le32_to_cpu(cur_trb->generic.field[3]) &
1573 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK)) 1759 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1574 len += 1760 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2]));
1575 TRB_LEN(cur_trb->generic.field[2]);
1576 } 1761 }
1577 len += TRB_LEN(cur_trb->generic.field[2]) - 1762 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])) -
1578 TRB_LEN(event->transfer_len); 1763 TRB_LEN(le32_to_cpu(event->transfer_len));
1579 1764
1580 if (trb_comp_code != COMP_STOP_INVAL) { 1765 if (trb_comp_code != COMP_STOP_INVAL) {
1581 td->urb->iso_frame_desc[idx].actual_length = len; 1766 frame->actual_length = len;
1582 td->urb->actual_length += len; 1767 td->urb->actual_length += len;
1583 } 1768 }
1584 } 1769 }
1585 1770
1586 if ((idx == urb_priv->length - 1) && *status == -EINPROGRESS)
1587 *status = 0;
1588
1589 return finish_td(xhci, td, event_trb, event, ep, status, false); 1771 return finish_td(xhci, td, event_trb, event, ep, status, false);
1590} 1772}
1591 1773
1774static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1775 struct xhci_transfer_event *event,
1776 struct xhci_virt_ep *ep, int *status)
1777{
1778 struct xhci_ring *ep_ring;
1779 struct urb_priv *urb_priv;
1780 struct usb_iso_packet_descriptor *frame;
1781 int idx;
1782
1783 ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer));
1784 urb_priv = td->urb->hcpriv;
1785 idx = urb_priv->td_cnt;
1786 frame = &td->urb->iso_frame_desc[idx];
1787
1788 /* The transfer is partly done. */
1789 frame->status = -EXDEV;
1790
1791 /* calc actual length */
1792 frame->actual_length = 0;
1793
1794 /* Update ring dequeue pointer */
1795 while (ep_ring->dequeue != td->last_trb)
1796 inc_deq(xhci, ep_ring, false);
1797 inc_deq(xhci, ep_ring, false);
1798
1799 return finish_td(xhci, td, NULL, event, ep, status, true);
1800}
1801
1592/* 1802/*
1593 * Process bulk and interrupt tds, update urb status and actual_length. 1803 * Process bulk and interrupt tds, update urb status and actual_length.
1594 */ 1804 */
@@ -1601,8 +1811,8 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
1601 struct xhci_segment *cur_seg; 1811 struct xhci_segment *cur_seg;
1602 u32 trb_comp_code; 1812 u32 trb_comp_code;
1603 1813
1604 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1814 ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer));
1605 trb_comp_code = GET_COMP_CODE(event->transfer_len); 1815 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len));
1606 1816
1607 switch (trb_comp_code) { 1817 switch (trb_comp_code) {
1608 case COMP_SUCCESS: 1818 case COMP_SUCCESS:
@@ -1615,12 +1825,6 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
1615 else 1825 else
1616 *status = 0; 1826 *status = 0;
1617 } else { 1827 } else {
1618 if (usb_endpoint_xfer_bulk(&td->urb->ep->desc))
1619 xhci_dbg(xhci, "Successful bulk "
1620 "transfer!\n");
1621 else
1622 xhci_dbg(xhci, "Successful interrupt "
1623 "transfer!\n");
1624 *status = 0; 1828 *status = 0;
1625 } 1829 }
1626 break; 1830 break;
@@ -1634,23 +1838,23 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
1634 /* Others already handled above */ 1838 /* Others already handled above */
1635 break; 1839 break;
1636 } 1840 }
1637 dev_dbg(&td->urb->dev->dev, 1841 if (trb_comp_code == COMP_SHORT_TX)
1638 "ep %#x - asked for %d bytes, " 1842 xhci_dbg(xhci, "ep %#x - asked for %d bytes, "
1639 "%d bytes untransferred\n", 1843 "%d bytes untransferred\n",
1640 td->urb->ep->desc.bEndpointAddress, 1844 td->urb->ep->desc.bEndpointAddress,
1641 td->urb->transfer_buffer_length, 1845 td->urb->transfer_buffer_length,
1642 TRB_LEN(event->transfer_len)); 1846 TRB_LEN(le32_to_cpu(event->transfer_len)));
1643 /* Fast path - was this the last TRB in the TD for this URB? */ 1847 /* Fast path - was this the last TRB in the TD for this URB? */
1644 if (event_trb == td->last_trb) { 1848 if (event_trb == td->last_trb) {
1645 if (TRB_LEN(event->transfer_len) != 0) { 1849 if (TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) {
1646 td->urb->actual_length = 1850 td->urb->actual_length =
1647 td->urb->transfer_buffer_length - 1851 td->urb->transfer_buffer_length -
1648 TRB_LEN(event->transfer_len); 1852 TRB_LEN(le32_to_cpu(event->transfer_len));
1649 if (td->urb->transfer_buffer_length < 1853 if (td->urb->transfer_buffer_length <
1650 td->urb->actual_length) { 1854 td->urb->actual_length) {
1651 xhci_warn(xhci, "HC gave bad length " 1855 xhci_warn(xhci, "HC gave bad length "
1652 "of %d bytes left\n", 1856 "of %d bytes left\n",
1653 TRB_LEN(event->transfer_len)); 1857 TRB_LEN(le32_to_cpu(event->transfer_len)));
1654 td->urb->actual_length = 0; 1858 td->urb->actual_length = 0;
1655 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1859 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1656 *status = -EREMOTEIO; 1860 *status = -EREMOTEIO;
@@ -1681,20 +1885,20 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
1681 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg; 1885 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg;
1682 cur_trb != event_trb; 1886 cur_trb != event_trb;
1683 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1887 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1684 if ((cur_trb->generic.field[3] & 1888 if ((le32_to_cpu(cur_trb->generic.field[3]) &
1685 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) && 1889 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) &&
1686 (cur_trb->generic.field[3] & 1890 (le32_to_cpu(cur_trb->generic.field[3]) &
1687 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK)) 1891 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1688 td->urb->actual_length += 1892 td->urb->actual_length +=
1689 TRB_LEN(cur_trb->generic.field[2]); 1893 TRB_LEN(le32_to_cpu(cur_trb->generic.field[2]));
1690 } 1894 }
1691 /* If the ring didn't stop on a Link or No-op TRB, add 1895 /* If the ring didn't stop on a Link or No-op TRB, add
1692 * in the actual bytes transferred from the Normal TRB 1896 * in the actual bytes transferred from the Normal TRB
1693 */ 1897 */
1694 if (trb_comp_code != COMP_STOP_INVAL) 1898 if (trb_comp_code != COMP_STOP_INVAL)
1695 td->urb->actual_length += 1899 td->urb->actual_length +=
1696 TRB_LEN(cur_trb->generic.field[2]) - 1900 TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])) -
1697 TRB_LEN(event->transfer_len); 1901 TRB_LEN(le32_to_cpu(event->transfer_len));
1698 } 1902 }
1699 1903
1700 return finish_td(xhci, td, event_trb, event, ep, status, false); 1904 return finish_td(xhci, td, event_trb, event, ep, status, false);
@@ -1724,7 +1928,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1724 u32 trb_comp_code; 1928 u32 trb_comp_code;
1725 int ret = 0; 1929 int ret = 0;
1726 1930
1727 slot_id = TRB_TO_SLOT_ID(event->flags); 1931 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
1728 xdev = xhci->devs[slot_id]; 1932 xdev = xhci->devs[slot_id];
1729 if (!xdev) { 1933 if (!xdev) {
1730 xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n"); 1934 xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n");
@@ -1732,20 +1936,20 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1732 } 1936 }
1733 1937
1734 /* Endpoint ID is 1 based, our index is zero based */ 1938 /* Endpoint ID is 1 based, our index is zero based */
1735 ep_index = TRB_TO_EP_ID(event->flags) - 1; 1939 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1;
1736 xhci_dbg(xhci, "%s - ep index = %d\n", __func__, ep_index);
1737 ep = &xdev->eps[ep_index]; 1940 ep = &xdev->eps[ep_index];
1738 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1941 ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer));
1739 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1942 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1740 if (!ep_ring || 1943 if (!ep_ring ||
1741 (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) { 1944 (le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK) ==
1945 EP_STATE_DISABLED) {
1742 xhci_err(xhci, "ERROR Transfer event for disabled endpoint " 1946 xhci_err(xhci, "ERROR Transfer event for disabled endpoint "
1743 "or incorrect stream ring\n"); 1947 "or incorrect stream ring\n");
1744 return -ENODEV; 1948 return -ENODEV;
1745 } 1949 }
1746 1950
1747 event_dma = event->buffer; 1951 event_dma = le64_to_cpu(event->buffer);
1748 trb_comp_code = GET_COMP_CODE(event->transfer_len); 1952 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len));
1749 /* Look for common error cases */ 1953 /* Look for common error cases */
1750 switch (trb_comp_code) { 1954 switch (trb_comp_code) {
1751 /* Skip codes that require special handling depending on 1955 /* Skip codes that require special handling depending on
@@ -1798,15 +2002,21 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1798 if (!list_empty(&ep_ring->td_list)) 2002 if (!list_empty(&ep_ring->td_list))
1799 xhci_dbg(xhci, "Underrun Event for slot %d ep %d " 2003 xhci_dbg(xhci, "Underrun Event for slot %d ep %d "
1800 "still with TDs queued?\n", 2004 "still with TDs queued?\n",
1801 TRB_TO_SLOT_ID(event->flags), ep_index); 2005 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)),
2006 ep_index);
1802 goto cleanup; 2007 goto cleanup;
1803 case COMP_OVERRUN: 2008 case COMP_OVERRUN:
1804 xhci_dbg(xhci, "overrun event on endpoint\n"); 2009 xhci_dbg(xhci, "overrun event on endpoint\n");
1805 if (!list_empty(&ep_ring->td_list)) 2010 if (!list_empty(&ep_ring->td_list))
1806 xhci_dbg(xhci, "Overrun Event for slot %d ep %d " 2011 xhci_dbg(xhci, "Overrun Event for slot %d ep %d "
1807 "still with TDs queued?\n", 2012 "still with TDs queued?\n",
1808 TRB_TO_SLOT_ID(event->flags), ep_index); 2013 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)),
2014 ep_index);
1809 goto cleanup; 2015 goto cleanup;
2016 case COMP_DEV_ERR:
2017 xhci_warn(xhci, "WARN: detect an incompatible device");
2018 status = -EPROTO;
2019 break;
1810 case COMP_MISSED_INT: 2020 case COMP_MISSED_INT:
1811 /* 2021 /*
1812 * When encounter missed service error, one or more isoc tds 2022 * When encounter missed service error, one or more isoc tds
@@ -1834,9 +2044,11 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1834 if (list_empty(&ep_ring->td_list)) { 2044 if (list_empty(&ep_ring->td_list)) {
1835 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d " 2045 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d "
1836 "with no TDs queued?\n", 2046 "with no TDs queued?\n",
1837 TRB_TO_SLOT_ID(event->flags), ep_index); 2047 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)),
2048 ep_index);
1838 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n", 2049 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
1839 (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10); 2050 (unsigned int) (le32_to_cpu(event->flags)
2051 & TRB_TYPE_BITMASK)>>10);
1840 xhci_print_trb_offsets(xhci, (union xhci_trb *) event); 2052 xhci_print_trb_offsets(xhci, (union xhci_trb *) event);
1841 if (ep->skip) { 2053 if (ep->skip) {
1842 ep->skip = false; 2054 ep->skip = false;
@@ -1848,36 +2060,71 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1848 } 2060 }
1849 2061
1850 td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list); 2062 td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list);
2063
1851 /* Is this a TRB in the currently executing TD? */ 2064 /* Is this a TRB in the currently executing TD? */
1852 event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue, 2065 event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue,
1853 td->last_trb, event_dma); 2066 td->last_trb, event_dma);
1854 if (event_seg && ep->skip) { 2067
1855 xhci_dbg(xhci, "Found td. Clear skip flag.\n"); 2068 /*
1856 ep->skip = false; 2069 * Skip the Force Stopped Event. The event_trb(event_dma) of FSE
2070 * is not in the current TD pointed by ep_ring->dequeue because
2071 * that the hardware dequeue pointer still at the previous TRB
2072 * of the current TD. The previous TRB maybe a Link TD or the
2073 * last TRB of the previous TD. The command completion handle
2074 * will take care the rest.
2075 */
2076 if (!event_seg && trb_comp_code == COMP_STOP_INVAL) {
2077 ret = 0;
2078 goto cleanup;
1857 } 2079 }
1858 if (!event_seg && 2080
1859 (!ep->skip || !usb_endpoint_xfer_isoc(&td->urb->ep->desc))) { 2081 if (!event_seg) {
1860 /* HC is busted, give up! */ 2082 if (!ep->skip ||
1861 xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not " 2083 !usb_endpoint_xfer_isoc(&td->urb->ep->desc)) {
2084 /* Some host controllers give a spurious
2085 * successful event after a short transfer.
2086 * Ignore it.
2087 */
2088 if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) &&
2089 ep_ring->last_td_was_short) {
2090 ep_ring->last_td_was_short = false;
2091 ret = 0;
2092 goto cleanup;
2093 }
2094 /* HC is busted, give up! */
2095 xhci_err(xhci,
2096 "ERROR Transfer event TRB DMA ptr not "
1862 "part of current TD\n"); 2097 "part of current TD\n");
1863 return -ESHUTDOWN; 2098 return -ESHUTDOWN;
2099 }
2100
2101 ret = skip_isoc_td(xhci, td, event, ep, &status);
2102 goto cleanup;
1864 } 2103 }
2104 if (trb_comp_code == COMP_SHORT_TX)
2105 ep_ring->last_td_was_short = true;
2106 else
2107 ep_ring->last_td_was_short = false;
1865 2108
1866 if (event_seg) { 2109 if (ep->skip) {
1867 event_trb = &event_seg->trbs[(event_dma - 2110 xhci_dbg(xhci, "Found td. Clear skip flag.\n");
1868 event_seg->dma) / sizeof(*event_trb)]; 2111 ep->skip = false;
1869 /* 2112 }
1870 * No-op TRB should not trigger interrupts. 2113
1871 * If event_trb is a no-op TRB, it means the 2114 event_trb = &event_seg->trbs[(event_dma - event_seg->dma) /
1872 * corresponding TD has been cancelled. Just ignore 2115 sizeof(*event_trb)];
1873 * the TD. 2116 /*
1874 */ 2117 * No-op TRB should not trigger interrupts.
1875 if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK) 2118 * If event_trb is a no-op TRB, it means the
1876 == TRB_TYPE(TRB_TR_NOOP)) { 2119 * corresponding TD has been cancelled. Just ignore
1877 xhci_dbg(xhci, "event_trb is a no-op TRB. " 2120 * the TD.
1878 "Skip it\n"); 2121 */
1879 goto cleanup; 2122 if ((le32_to_cpu(event_trb->generic.field[3])
1880 } 2123 & TRB_TYPE_BITMASK)
2124 == TRB_TYPE(TRB_TR_NOOP)) {
2125 xhci_dbg(xhci,
2126 "event_trb is a no-op TRB. Skip it\n");
2127 goto cleanup;
1881 } 2128 }
1882 2129
1883 /* Now update the urb's actual_length and give back to 2130 /* Now update the urb's actual_length and give back to
@@ -1915,12 +2162,23 @@ cleanup:
1915 trb_comp_code != COMP_BABBLE)) 2162 trb_comp_code != COMP_BABBLE))
1916 xhci_urb_free_priv(xhci, urb_priv); 2163 xhci_urb_free_priv(xhci, urb_priv);
1917 2164
1918 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); 2165 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb);
1919 xhci_dbg(xhci, "Giveback URB %p, len = %d, " 2166 if ((urb->actual_length != urb->transfer_buffer_length &&
1920 "status = %d\n", 2167 (urb->transfer_flags &
1921 urb, urb->actual_length, status); 2168 URB_SHORT_NOT_OK)) ||
2169 status != 0)
2170 xhci_dbg(xhci, "Giveback URB %p, len = %d, "
2171 "expected = %x, status = %d\n",
2172 urb, urb->actual_length,
2173 urb->transfer_buffer_length,
2174 status);
1922 spin_unlock(&xhci->lock); 2175 spin_unlock(&xhci->lock);
1923 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); 2176 /* EHCI, UHCI, and OHCI always unconditionally set the
2177 * urb->status of an isochronous endpoint to 0.
2178 */
2179 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
2180 status = 0;
2181 usb_hcd_giveback_urb(bus_to_hcd(urb->dev->bus), urb, status);
1924 spin_lock(&xhci->lock); 2182 spin_lock(&xhci->lock);
1925 } 2183 }
1926 2184
@@ -1938,52 +2196,52 @@ cleanup:
1938/* 2196/*
1939 * This function handles all OS-owned events on the event ring. It may drop 2197 * This function handles all OS-owned events on the event ring. It may drop
1940 * xhci->lock between event processing (e.g. to pass up port status changes). 2198 * xhci->lock between event processing (e.g. to pass up port status changes).
2199 * Returns >0 for "possibly more events to process" (caller should call again),
2200 * otherwise 0 if done. In future, <0 returns should indicate error code.
1941 */ 2201 */
1942static void xhci_handle_event(struct xhci_hcd *xhci) 2202static int xhci_handle_event(struct xhci_hcd *xhci)
1943{ 2203{
1944 union xhci_trb *event; 2204 union xhci_trb *event;
1945 int update_ptrs = 1; 2205 int update_ptrs = 1;
1946 int ret; 2206 int ret;
1947 2207
1948 xhci_dbg(xhci, "In %s\n", __func__);
1949 if (!xhci->event_ring || !xhci->event_ring->dequeue) { 2208 if (!xhci->event_ring || !xhci->event_ring->dequeue) {
1950 xhci->error_bitmask |= 1 << 1; 2209 xhci->error_bitmask |= 1 << 1;
1951 return; 2210 return 0;
1952 } 2211 }
1953 2212
1954 event = xhci->event_ring->dequeue; 2213 event = xhci->event_ring->dequeue;
1955 /* Does the HC or OS own the TRB? */ 2214 /* Does the HC or OS own the TRB? */
1956 if ((event->event_cmd.flags & TRB_CYCLE) != 2215 if ((le32_to_cpu(event->event_cmd.flags) & TRB_CYCLE) !=
1957 xhci->event_ring->cycle_state) { 2216 xhci->event_ring->cycle_state) {
1958 xhci->error_bitmask |= 1 << 2; 2217 xhci->error_bitmask |= 1 << 2;
1959 return; 2218 return 0;
1960 } 2219 }
1961 xhci_dbg(xhci, "%s - OS owns TRB\n", __func__);
1962 2220
2221 /*
2222 * Barrier between reading the TRB_CYCLE (valid) flag above and any
2223 * speculative reads of the event's flags/data below.
2224 */
2225 rmb();
1963 /* FIXME: Handle more event types. */ 2226 /* FIXME: Handle more event types. */
1964 switch ((event->event_cmd.flags & TRB_TYPE_BITMASK)) { 2227 switch ((le32_to_cpu(event->event_cmd.flags) & TRB_TYPE_BITMASK)) {
1965 case TRB_TYPE(TRB_COMPLETION): 2228 case TRB_TYPE(TRB_COMPLETION):
1966 xhci_dbg(xhci, "%s - calling handle_cmd_completion\n", __func__);
1967 handle_cmd_completion(xhci, &event->event_cmd); 2229 handle_cmd_completion(xhci, &event->event_cmd);
1968 xhci_dbg(xhci, "%s - returned from handle_cmd_completion\n", __func__);
1969 break; 2230 break;
1970 case TRB_TYPE(TRB_PORT_STATUS): 2231 case TRB_TYPE(TRB_PORT_STATUS):
1971 xhci_dbg(xhci, "%s - calling handle_port_status\n", __func__);
1972 handle_port_status(xhci, event); 2232 handle_port_status(xhci, event);
1973 xhci_dbg(xhci, "%s - returned from handle_port_status\n", __func__);
1974 update_ptrs = 0; 2233 update_ptrs = 0;
1975 break; 2234 break;
1976 case TRB_TYPE(TRB_TRANSFER): 2235 case TRB_TYPE(TRB_TRANSFER):
1977 xhci_dbg(xhci, "%s - calling handle_tx_event\n", __func__);
1978 ret = handle_tx_event(xhci, &event->trans_event); 2236 ret = handle_tx_event(xhci, &event->trans_event);
1979 xhci_dbg(xhci, "%s - returned from handle_tx_event\n", __func__);
1980 if (ret < 0) 2237 if (ret < 0)
1981 xhci->error_bitmask |= 1 << 9; 2238 xhci->error_bitmask |= 1 << 9;
1982 else 2239 else
1983 update_ptrs = 0; 2240 update_ptrs = 0;
1984 break; 2241 break;
1985 default: 2242 default:
1986 if ((event->event_cmd.flags & TRB_TYPE_BITMASK) >= TRB_TYPE(48)) 2243 if ((le32_to_cpu(event->event_cmd.flags) & TRB_TYPE_BITMASK) >=
2244 TRB_TYPE(48))
1987 handle_vendor_event(xhci, event); 2245 handle_vendor_event(xhci, event);
1988 else 2246 else
1989 xhci->error_bitmask |= 1 << 3; 2247 xhci->error_bitmask |= 1 << 3;
@@ -1994,15 +2252,17 @@ static void xhci_handle_event(struct xhci_hcd *xhci)
1994 if (xhci->xhc_state & XHCI_STATE_DYING) { 2252 if (xhci->xhc_state & XHCI_STATE_DYING) {
1995 xhci_dbg(xhci, "xHCI host dying, returning from " 2253 xhci_dbg(xhci, "xHCI host dying, returning from "
1996 "event handler.\n"); 2254 "event handler.\n");
1997 return; 2255 return 0;
1998 } 2256 }
1999 2257
2000 if (update_ptrs) 2258 if (update_ptrs)
2001 /* Update SW event ring dequeue pointer */ 2259 /* Update SW event ring dequeue pointer */
2002 inc_deq(xhci, xhci->event_ring, true); 2260 inc_deq(xhci, xhci->event_ring, true);
2003 2261
2004 /* Are there more items on the event ring? */ 2262 /* Are there more items on the event ring? Caller will call us again to
2005 xhci_handle_event(xhci); 2263 * check.
2264 */
2265 return 1;
2006} 2266}
2007 2267
2008/* 2268/*
@@ -2028,24 +2288,12 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
2028 2288
2029 if (!(status & STS_EINT)) { 2289 if (!(status & STS_EINT)) {
2030 spin_unlock(&xhci->lock); 2290 spin_unlock(&xhci->lock);
2031 xhci_warn(xhci, "Spurious interrupt.\n");
2032 return IRQ_NONE; 2291 return IRQ_NONE;
2033 } 2292 }
2034 xhci_dbg(xhci, "op reg status = %08x\n", status);
2035 xhci_dbg(xhci, "Event ring dequeue ptr:\n");
2036 xhci_dbg(xhci, "@%llx %08x %08x %08x %08x\n",
2037 (unsigned long long)
2038 xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, trb),
2039 lower_32_bits(trb->link.segment_ptr),
2040 upper_32_bits(trb->link.segment_ptr),
2041 (unsigned int) trb->link.intr_target,
2042 (unsigned int) trb->link.control);
2043
2044 if (status & STS_FATAL) { 2293 if (status & STS_FATAL) {
2045 xhci_warn(xhci, "WARNING: Host System Error\n"); 2294 xhci_warn(xhci, "WARNING: Host System Error\n");
2046 xhci_halt(xhci); 2295 xhci_halt(xhci);
2047hw_died: 2296hw_died:
2048 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
2049 spin_unlock(&xhci->lock); 2297 spin_unlock(&xhci->lock);
2050 return -ESHUTDOWN; 2298 return -ESHUTDOWN;
2051 } 2299 }
@@ -2086,7 +2334,7 @@ hw_died:
2086 /* FIXME this should be a delayed service routine 2334 /* FIXME this should be a delayed service routine
2087 * that clears the EHB. 2335 * that clears the EHB.
2088 */ 2336 */
2089 xhci_handle_event(xhci); 2337 while (xhci_handle_event(xhci) > 0) {}
2090 2338
2091 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 2339 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2092 /* If necessary, update the HW's version of the event ring deq ptr. */ 2340 /* If necessary, update the HW's version of the event ring deq ptr. */
@@ -2113,8 +2361,12 @@ hw_died:
2113irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd) 2361irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd)
2114{ 2362{
2115 irqreturn_t ret; 2363 irqreturn_t ret;
2364 struct xhci_hcd *xhci;
2116 2365
2366 xhci = hcd_to_xhci(hcd);
2117 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 2367 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
2368 if (xhci->shared_hcd)
2369 set_bit(HCD_FLAG_SAW_IRQ, &xhci->shared_hcd->flags);
2118 2370
2119 ret = xhci_irq(hcd); 2371 ret = xhci_irq(hcd);
2120 2372
@@ -2137,10 +2389,10 @@ static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
2137 struct xhci_generic_trb *trb; 2389 struct xhci_generic_trb *trb;
2138 2390
2139 trb = &ring->enqueue->generic; 2391 trb = &ring->enqueue->generic;
2140 trb->field[0] = field1; 2392 trb->field[0] = cpu_to_le32(field1);
2141 trb->field[1] = field2; 2393 trb->field[1] = cpu_to_le32(field2);
2142 trb->field[2] = field3; 2394 trb->field[2] = cpu_to_le32(field3);
2143 trb->field[3] = field4; 2395 trb->field[3] = cpu_to_le32(field4);
2144 inc_enq(xhci, ring, consumer, more_trbs_coming); 2396 inc_enq(xhci, ring, consumer, more_trbs_coming);
2145} 2397}
2146 2398
@@ -2152,7 +2404,6 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
2152 u32 ep_state, unsigned int num_trbs, gfp_t mem_flags) 2404 u32 ep_state, unsigned int num_trbs, gfp_t mem_flags)
2153{ 2405{
2154 /* Make sure the endpoint has been added to xHC schedule */ 2406 /* Make sure the endpoint has been added to xHC schedule */
2155 xhci_dbg(xhci, "Endpoint state = 0x%x\n", ep_state);
2156 switch (ep_state) { 2407 switch (ep_state) {
2157 case EP_STATE_DISABLED: 2408 case EP_STATE_DISABLED:
2158 /* 2409 /*
@@ -2189,21 +2440,19 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
2189 struct xhci_ring *ring = ep_ring; 2440 struct xhci_ring *ring = ep_ring;
2190 union xhci_trb *next; 2441 union xhci_trb *next;
2191 2442
2192 xhci_dbg(xhci, "prepare_ring: pointing to link trb\n");
2193 next = ring->enqueue; 2443 next = ring->enqueue;
2194 2444
2195 while (last_trb(xhci, ring, ring->enq_seg, next)) { 2445 while (last_trb(xhci, ring, ring->enq_seg, next)) {
2196
2197 /* If we're not dealing with 0.95 hardware, 2446 /* If we're not dealing with 0.95 hardware,
2198 * clear the chain bit. 2447 * clear the chain bit.
2199 */ 2448 */
2200 if (!xhci_link_trb_quirk(xhci)) 2449 if (!xhci_link_trb_quirk(xhci))
2201 next->link.control &= ~TRB_CHAIN; 2450 next->link.control &= cpu_to_le32(~TRB_CHAIN);
2202 else 2451 else
2203 next->link.control |= TRB_CHAIN; 2452 next->link.control |= cpu_to_le32(TRB_CHAIN);
2204 2453
2205 wmb(); 2454 wmb();
2206 next->link.control ^= (u32) TRB_CYCLE; 2455 next->link.control ^= cpu_to_le32((u32) TRB_CYCLE);
2207 2456
2208 /* Toggle the cycle bit after the last ring segment. */ 2457 /* Toggle the cycle bit after the last ring segment. */
2209 if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) { 2458 if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) {
@@ -2246,8 +2495,8 @@ static int prepare_transfer(struct xhci_hcd *xhci,
2246 } 2495 }
2247 2496
2248 ret = prepare_ring(xhci, ep_ring, 2497 ret = prepare_ring(xhci, ep_ring,
2249 ep_ctx->ep_info & EP_STATE_MASK, 2498 le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK,
2250 num_trbs, mem_flags); 2499 num_trbs, mem_flags);
2251 if (ret) 2500 if (ret)
2252 return ret; 2501 return ret;
2253 2502
@@ -2258,7 +2507,7 @@ static int prepare_transfer(struct xhci_hcd *xhci,
2258 INIT_LIST_HEAD(&td->cancelled_td_list); 2507 INIT_LIST_HEAD(&td->cancelled_td_list);
2259 2508
2260 if (td_index == 0) { 2509 if (td_index == 0) {
2261 ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb); 2510 ret = usb_hcd_link_urb_to_ep(bus_to_hcd(urb->dev->bus), urb);
2262 if (unlikely(ret)) { 2511 if (unlikely(ret)) {
2263 xhci_urb_free_priv(xhci, urb_priv); 2512 xhci_urb_free_priv(xhci, urb_priv);
2264 urb->hcpriv = NULL; 2513 urb->hcpriv = NULL;
@@ -2294,12 +2543,13 @@ static unsigned int count_sg_trbs_needed(struct xhci_hcd *xhci, struct urb *urb)
2294 2543
2295 /* Scatter gather list entries may cross 64KB boundaries */ 2544 /* Scatter gather list entries may cross 64KB boundaries */
2296 running_total = TRB_MAX_BUFF_SIZE - 2545 running_total = TRB_MAX_BUFF_SIZE -
2297 (sg_dma_address(sg) & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); 2546 (sg_dma_address(sg) & (TRB_MAX_BUFF_SIZE - 1));
2547 running_total &= TRB_MAX_BUFF_SIZE - 1;
2298 if (running_total != 0) 2548 if (running_total != 0)
2299 num_trbs++; 2549 num_trbs++;
2300 2550
2301 /* How many more 64KB chunks to transfer, how many more TRBs? */ 2551 /* How many more 64KB chunks to transfer, how many more TRBs? */
2302 while (running_total < sg_dma_len(sg)) { 2552 while (running_total < sg_dma_len(sg) && running_total < temp) {
2303 num_trbs++; 2553 num_trbs++;
2304 running_total += TRB_MAX_BUFF_SIZE; 2554 running_total += TRB_MAX_BUFF_SIZE;
2305 } 2555 }
@@ -2314,7 +2564,8 @@ static unsigned int count_sg_trbs_needed(struct xhci_hcd *xhci, struct urb *urb)
2314 } 2564 }
2315 xhci_dbg(xhci, "\n"); 2565 xhci_dbg(xhci, "\n");
2316 if (!in_interrupt()) 2566 if (!in_interrupt())
2317 dev_dbg(&urb->dev->dev, "ep %#x - urb len = %d, sglist used, num_trbs = %d\n", 2567 xhci_dbg(xhci, "ep %#x - urb len = %d, sglist used, "
2568 "num_trbs = %d\n",
2318 urb->ep->desc.bEndpointAddress, 2569 urb->ep->desc.bEndpointAddress,
2319 urb->transfer_buffer_length, 2570 urb->transfer_buffer_length,
2320 num_trbs); 2571 num_trbs);
@@ -2324,11 +2575,11 @@ static unsigned int count_sg_trbs_needed(struct xhci_hcd *xhci, struct urb *urb)
2324static void check_trb_math(struct urb *urb, int num_trbs, int running_total) 2575static void check_trb_math(struct urb *urb, int num_trbs, int running_total)
2325{ 2576{
2326 if (num_trbs != 0) 2577 if (num_trbs != 0)
2327 dev_dbg(&urb->dev->dev, "%s - ep %#x - Miscalculated number of " 2578 dev_err(&urb->dev->dev, "%s - ep %#x - Miscalculated number of "
2328 "TRBs, %d left\n", __func__, 2579 "TRBs, %d left\n", __func__,
2329 urb->ep->desc.bEndpointAddress, num_trbs); 2580 urb->ep->desc.bEndpointAddress, num_trbs);
2330 if (running_total != urb->transfer_buffer_length) 2581 if (running_total != urb->transfer_buffer_length)
2331 dev_dbg(&urb->dev->dev, "%s - ep %#x - Miscalculated tx length, " 2582 dev_err(&urb->dev->dev, "%s - ep %#x - Miscalculated tx length, "
2332 "queued %#x (%d), asked for %#x (%d)\n", 2583 "queued %#x (%d), asked for %#x (%d)\n",
2333 __func__, 2584 __func__,
2334 urb->ep->desc.bEndpointAddress, 2585 urb->ep->desc.bEndpointAddress,
@@ -2339,15 +2590,18 @@ static void check_trb_math(struct urb *urb, int num_trbs, int running_total)
2339 2590
2340static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id, 2591static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id,
2341 unsigned int ep_index, unsigned int stream_id, int start_cycle, 2592 unsigned int ep_index, unsigned int stream_id, int start_cycle,
2342 struct xhci_generic_trb *start_trb, struct xhci_td *td) 2593 struct xhci_generic_trb *start_trb)
2343{ 2594{
2344 /* 2595 /*
2345 * Pass all the TRBs to the hardware at once and make sure this write 2596 * Pass all the TRBs to the hardware at once and make sure this write
2346 * isn't reordered. 2597 * isn't reordered.
2347 */ 2598 */
2348 wmb(); 2599 wmb();
2349 start_trb->field[3] |= start_cycle; 2600 if (start_cycle)
2350 ring_ep_doorbell(xhci, slot_id, ep_index, stream_id); 2601 start_trb->field[3] |= cpu_to_le32(start_cycle);
2602 else
2603 start_trb->field[3] &= cpu_to_le32(~TRB_CYCLE);
2604 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id);
2351} 2605}
2352 2606
2353/* 2607/*
@@ -2364,7 +2618,7 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2364 int xhci_interval; 2618 int xhci_interval;
2365 int ep_interval; 2619 int ep_interval;
2366 2620
2367 xhci_interval = EP_INTERVAL_TO_UFRAMES(ep_ctx->ep_info); 2621 xhci_interval = EP_INTERVAL_TO_UFRAMES(le32_to_cpu(ep_ctx->ep_info));
2368 ep_interval = urb->interval; 2622 ep_interval = urb->interval;
2369 /* Convert to microframes */ 2623 /* Convert to microframes */
2370 if (urb->dev->speed == USB_SPEED_LOW || 2624 if (urb->dev->speed == USB_SPEED_LOW ||
@@ -2374,7 +2628,7 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2374 * to set the polling interval (once the API is added). 2628 * to set the polling interval (once the API is added).
2375 */ 2629 */
2376 if (xhci_interval != ep_interval) { 2630 if (xhci_interval != ep_interval) {
2377 if (!printk_ratelimit()) 2631 if (printk_ratelimit())
2378 dev_dbg(&urb->dev->dev, "Driver uses different interval" 2632 dev_dbg(&urb->dev->dev, "Driver uses different interval"
2379 " (%d microframe%s) than xHCI " 2633 " (%d microframe%s) than xHCI "
2380 "(%d microframe%s)\n", 2634 "(%d microframe%s)\n",
@@ -2406,6 +2660,35 @@ static u32 xhci_td_remainder(unsigned int remainder)
2406 return (remainder >> 10) << 17; 2660 return (remainder >> 10) << 17;
2407} 2661}
2408 2662
2663/*
2664 * For xHCI 1.0 host controllers, TD size is the number of packets remaining in
2665 * the TD (*not* including this TRB).
2666 *
2667 * Total TD packet count = total_packet_count =
2668 * roundup(TD size in bytes / wMaxPacketSize)
2669 *
2670 * Packets transferred up to and including this TRB = packets_transferred =
2671 * rounddown(total bytes transferred including this TRB / wMaxPacketSize)
2672 *
2673 * TD size = total_packet_count - packets_transferred
2674 *
2675 * It must fit in bits 21:17, so it can't be bigger than 31.
2676 */
2677
2678static u32 xhci_v1_0_td_remainder(int running_total, int trb_buff_len,
2679 unsigned int total_packet_count, struct urb *urb)
2680{
2681 int packets_transferred;
2682
2683 /* All the TRB queueing functions don't count the current TRB in
2684 * running_total.
2685 */
2686 packets_transferred = (running_total + trb_buff_len) /
2687 le16_to_cpu(urb->ep->desc.wMaxPacketSize);
2688
2689 return xhci_td_remainder(total_packet_count - packets_transferred);
2690}
2691
2409static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, 2692static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2410 struct urb *urb, int slot_id, unsigned int ep_index) 2693 struct urb *urb, int slot_id, unsigned int ep_index)
2411{ 2694{
@@ -2416,6 +2699,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2416 struct scatterlist *sg; 2699 struct scatterlist *sg;
2417 int num_sgs; 2700 int num_sgs;
2418 int trb_buff_len, this_sg_len, running_total; 2701 int trb_buff_len, this_sg_len, running_total;
2702 unsigned int total_packet_count;
2419 bool first_trb; 2703 bool first_trb;
2420 u64 addr; 2704 u64 addr;
2421 bool more_trbs_coming; 2705 bool more_trbs_coming;
@@ -2429,6 +2713,8 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2429 2713
2430 num_trbs = count_sg_trbs_needed(xhci, urb); 2714 num_trbs = count_sg_trbs_needed(xhci, urb);
2431 num_sgs = urb->num_sgs; 2715 num_sgs = urb->num_sgs;
2716 total_packet_count = roundup(urb->transfer_buffer_length,
2717 le16_to_cpu(urb->ep->desc.wMaxPacketSize));
2432 2718
2433 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], 2719 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id],
2434 ep_index, urb->stream_id, 2720 ep_index, urb->stream_id,
@@ -2460,8 +2746,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2460 sg = urb->sg; 2746 sg = urb->sg;
2461 addr = (u64) sg_dma_address(sg); 2747 addr = (u64) sg_dma_address(sg);
2462 this_sg_len = sg_dma_len(sg); 2748 this_sg_len = sg_dma_len(sg);
2463 trb_buff_len = TRB_MAX_BUFF_SIZE - 2749 trb_buff_len = TRB_MAX_BUFF_SIZE - (addr & (TRB_MAX_BUFF_SIZE - 1));
2464 (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1));
2465 trb_buff_len = min_t(int, trb_buff_len, this_sg_len); 2750 trb_buff_len = min_t(int, trb_buff_len, this_sg_len);
2466 if (trb_buff_len > urb->transfer_buffer_length) 2751 if (trb_buff_len > urb->transfer_buffer_length)
2467 trb_buff_len = urb->transfer_buffer_length; 2752 trb_buff_len = urb->transfer_buffer_length;
@@ -2476,9 +2761,11 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2476 u32 remainder = 0; 2761 u32 remainder = 0;
2477 2762
2478 /* Don't change the cycle bit of the first TRB until later */ 2763 /* Don't change the cycle bit of the first TRB until later */
2479 if (first_trb) 2764 if (first_trb) {
2480 first_trb = false; 2765 first_trb = false;
2481 else 2766 if (start_cycle == 0)
2767 field |= 0x1;
2768 } else
2482 field |= ep_ring->cycle_state; 2769 field |= ep_ring->cycle_state;
2483 2770
2484 /* Chain all the TRBs together; clear the chain bit in the last 2771 /* Chain all the TRBs together; clear the chain bit in the last
@@ -2491,23 +2778,37 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2491 td->last_trb = ep_ring->enqueue; 2778 td->last_trb = ep_ring->enqueue;
2492 field |= TRB_IOC; 2779 field |= TRB_IOC;
2493 } 2780 }
2781
2782 /* Only set interrupt on short packet for IN endpoints */
2783 if (usb_urb_dir_in(urb))
2784 field |= TRB_ISP;
2785
2494 xhci_dbg(xhci, " sg entry: dma = %#x, len = %#x (%d), " 2786 xhci_dbg(xhci, " sg entry: dma = %#x, len = %#x (%d), "
2495 "64KB boundary at %#x, end dma = %#x\n", 2787 "64KB boundary at %#x, end dma = %#x\n",
2496 (unsigned int) addr, trb_buff_len, trb_buff_len, 2788 (unsigned int) addr, trb_buff_len, trb_buff_len,
2497 (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1), 2789 (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1),
2498 (unsigned int) addr + trb_buff_len); 2790 (unsigned int) addr + trb_buff_len);
2499 if (TRB_MAX_BUFF_SIZE - 2791 if (TRB_MAX_BUFF_SIZE -
2500 (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1)) < trb_buff_len) { 2792 (addr & (TRB_MAX_BUFF_SIZE - 1)) < trb_buff_len) {
2501 xhci_warn(xhci, "WARN: sg dma xfer crosses 64KB boundaries!\n"); 2793 xhci_warn(xhci, "WARN: sg dma xfer crosses 64KB boundaries!\n");
2502 xhci_dbg(xhci, "Next boundary at %#x, end dma = %#x\n", 2794 xhci_dbg(xhci, "Next boundary at %#x, end dma = %#x\n",
2503 (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1), 2795 (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1),
2504 (unsigned int) addr + trb_buff_len); 2796 (unsigned int) addr + trb_buff_len);
2505 } 2797 }
2506 remainder = xhci_td_remainder(urb->transfer_buffer_length - 2798
2507 running_total) ; 2799 /* Set the TRB length, TD size, and interrupter fields. */
2800 if (xhci->hci_version < 0x100) {
2801 remainder = xhci_td_remainder(
2802 urb->transfer_buffer_length -
2803 running_total);
2804 } else {
2805 remainder = xhci_v1_0_td_remainder(running_total,
2806 trb_buff_len, total_packet_count, urb);
2807 }
2508 length_field = TRB_LEN(trb_buff_len) | 2808 length_field = TRB_LEN(trb_buff_len) |
2509 remainder | 2809 remainder |
2510 TRB_INTR_TARGET(0); 2810 TRB_INTR_TARGET(0);
2811
2511 if (num_trbs > 1) 2812 if (num_trbs > 1)
2512 more_trbs_coming = true; 2813 more_trbs_coming = true;
2513 else 2814 else
@@ -2516,12 +2817,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2516 lower_32_bits(addr), 2817 lower_32_bits(addr),
2517 upper_32_bits(addr), 2818 upper_32_bits(addr),
2518 length_field, 2819 length_field,
2519 /* We always want to know if the TRB was short, 2820 field | TRB_TYPE(TRB_NORMAL));
2520 * or we won't get an event when it completes.
2521 * (Unless we use event data TRBs, which are a
2522 * waste of space and HC resources.)
2523 */
2524 field | TRB_ISP | TRB_TYPE(TRB_NORMAL));
2525 --num_trbs; 2821 --num_trbs;
2526 running_total += trb_buff_len; 2822 running_total += trb_buff_len;
2527 2823
@@ -2541,7 +2837,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2541 } 2837 }
2542 2838
2543 trb_buff_len = TRB_MAX_BUFF_SIZE - 2839 trb_buff_len = TRB_MAX_BUFF_SIZE -
2544 (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); 2840 (addr & (TRB_MAX_BUFF_SIZE - 1));
2545 trb_buff_len = min_t(int, trb_buff_len, this_sg_len); 2841 trb_buff_len = min_t(int, trb_buff_len, this_sg_len);
2546 if (running_total + trb_buff_len > urb->transfer_buffer_length) 2842 if (running_total + trb_buff_len > urb->transfer_buffer_length)
2547 trb_buff_len = 2843 trb_buff_len =
@@ -2550,7 +2846,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2550 2846
2551 check_trb_math(urb, num_trbs, running_total); 2847 check_trb_math(urb, num_trbs, running_total);
2552 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, 2848 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id,
2553 start_cycle, start_trb, td); 2849 start_cycle, start_trb);
2554 return 0; 2850 return 0;
2555} 2851}
2556 2852
@@ -2569,6 +2865,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2569 u32 field, length_field; 2865 u32 field, length_field;
2570 2866
2571 int running_total, trb_buff_len, ret; 2867 int running_total, trb_buff_len, ret;
2868 unsigned int total_packet_count;
2572 u64 addr; 2869 u64 addr;
2573 2870
2574 if (urb->num_sgs) 2871 if (urb->num_sgs)
@@ -2581,7 +2878,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2581 num_trbs = 0; 2878 num_trbs = 0;
2582 /* How much data is (potentially) left before the 64KB boundary? */ 2879 /* How much data is (potentially) left before the 64KB boundary? */
2583 running_total = TRB_MAX_BUFF_SIZE - 2880 running_total = TRB_MAX_BUFF_SIZE -
2584 (urb->transfer_dma & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); 2881 (urb->transfer_dma & (TRB_MAX_BUFF_SIZE - 1));
2882 running_total &= TRB_MAX_BUFF_SIZE - 1;
2585 2883
2586 /* If there's some data on this 64KB chunk, or we have to send a 2884 /* If there's some data on this 64KB chunk, or we have to send a
2587 * zero-length transfer, we need at least one TRB 2885 * zero-length transfer, we need at least one TRB
@@ -2596,7 +2894,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2596 /* FIXME: this doesn't deal with URB_ZERO_PACKET - need one more */ 2894 /* FIXME: this doesn't deal with URB_ZERO_PACKET - need one more */
2597 2895
2598 if (!in_interrupt()) 2896 if (!in_interrupt())
2599 dev_dbg(&urb->dev->dev, "ep %#x - urb len = %#x (%d), addr = %#llx, num_trbs = %d\n", 2897 xhci_dbg(xhci, "ep %#x - urb len = %#x (%d), "
2898 "addr = %#llx, num_trbs = %d\n",
2600 urb->ep->desc.bEndpointAddress, 2899 urb->ep->desc.bEndpointAddress,
2601 urb->transfer_buffer_length, 2900 urb->transfer_buffer_length,
2602 urb->transfer_buffer_length, 2901 urb->transfer_buffer_length,
@@ -2621,11 +2920,13 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2621 start_cycle = ep_ring->cycle_state; 2920 start_cycle = ep_ring->cycle_state;
2622 2921
2623 running_total = 0; 2922 running_total = 0;
2923 total_packet_count = roundup(urb->transfer_buffer_length,
2924 le16_to_cpu(urb->ep->desc.wMaxPacketSize));
2624 /* How much data is in the first TRB? */ 2925 /* How much data is in the first TRB? */
2625 addr = (u64) urb->transfer_dma; 2926 addr = (u64) urb->transfer_dma;
2626 trb_buff_len = TRB_MAX_BUFF_SIZE - 2927 trb_buff_len = TRB_MAX_BUFF_SIZE -
2627 (urb->transfer_dma & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); 2928 (urb->transfer_dma & (TRB_MAX_BUFF_SIZE - 1));
2628 if (urb->transfer_buffer_length < trb_buff_len) 2929 if (trb_buff_len > urb->transfer_buffer_length)
2629 trb_buff_len = urb->transfer_buffer_length; 2930 trb_buff_len = urb->transfer_buffer_length;
2630 2931
2631 first_trb = true; 2932 first_trb = true;
@@ -2636,9 +2937,11 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2636 field = 0; 2937 field = 0;
2637 2938
2638 /* Don't change the cycle bit of the first TRB until later */ 2939 /* Don't change the cycle bit of the first TRB until later */
2639 if (first_trb) 2940 if (first_trb) {
2640 first_trb = false; 2941 first_trb = false;
2641 else 2942 if (start_cycle == 0)
2943 field |= 0x1;
2944 } else
2642 field |= ep_ring->cycle_state; 2945 field |= ep_ring->cycle_state;
2643 2946
2644 /* Chain all the TRBs together; clear the chain bit in the last 2947 /* Chain all the TRBs together; clear the chain bit in the last
@@ -2651,11 +2954,24 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2651 td->last_trb = ep_ring->enqueue; 2954 td->last_trb = ep_ring->enqueue;
2652 field |= TRB_IOC; 2955 field |= TRB_IOC;
2653 } 2956 }
2654 remainder = xhci_td_remainder(urb->transfer_buffer_length - 2957
2655 running_total); 2958 /* Only set interrupt on short packet for IN endpoints */
2959 if (usb_urb_dir_in(urb))
2960 field |= TRB_ISP;
2961
2962 /* Set the TRB length, TD size, and interrupter fields. */
2963 if (xhci->hci_version < 0x100) {
2964 remainder = xhci_td_remainder(
2965 urb->transfer_buffer_length -
2966 running_total);
2967 } else {
2968 remainder = xhci_v1_0_td_remainder(running_total,
2969 trb_buff_len, total_packet_count, urb);
2970 }
2656 length_field = TRB_LEN(trb_buff_len) | 2971 length_field = TRB_LEN(trb_buff_len) |
2657 remainder | 2972 remainder |
2658 TRB_INTR_TARGET(0); 2973 TRB_INTR_TARGET(0);
2974
2659 if (num_trbs > 1) 2975 if (num_trbs > 1)
2660 more_trbs_coming = true; 2976 more_trbs_coming = true;
2661 else 2977 else
@@ -2664,12 +2980,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2664 lower_32_bits(addr), 2980 lower_32_bits(addr),
2665 upper_32_bits(addr), 2981 upper_32_bits(addr),
2666 length_field, 2982 length_field,
2667 /* We always want to know if the TRB was short, 2983 field | TRB_TYPE(TRB_NORMAL));
2668 * or we won't get an event when it completes.
2669 * (Unless we use event data TRBs, which are a
2670 * waste of space and HC resources.)
2671 */
2672 field | TRB_ISP | TRB_TYPE(TRB_NORMAL));
2673 --num_trbs; 2984 --num_trbs;
2674 running_total += trb_buff_len; 2985 running_total += trb_buff_len;
2675 2986
@@ -2682,7 +2993,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2682 2993
2683 check_trb_math(urb, num_trbs, running_total); 2994 check_trb_math(urb, num_trbs, running_total);
2684 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, 2995 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id,
2685 start_cycle, start_trb, td); 2996 start_cycle, start_trb);
2686 return 0; 2997 return 0;
2687} 2998}
2688 2999
@@ -2743,16 +3054,35 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2743 /* Queue setup TRB - see section 6.4.1.2.1 */ 3054 /* Queue setup TRB - see section 6.4.1.2.1 */
2744 /* FIXME better way to translate setup_packet into two u32 fields? */ 3055 /* FIXME better way to translate setup_packet into two u32 fields? */
2745 setup = (struct usb_ctrlrequest *) urb->setup_packet; 3056 setup = (struct usb_ctrlrequest *) urb->setup_packet;
3057 field = 0;
3058 field |= TRB_IDT | TRB_TYPE(TRB_SETUP);
3059 if (start_cycle == 0)
3060 field |= 0x1;
3061
3062 /* xHCI 1.0 6.4.1.2.1: Transfer Type field */
3063 if (xhci->hci_version == 0x100) {
3064 if (urb->transfer_buffer_length > 0) {
3065 if (setup->bRequestType & USB_DIR_IN)
3066 field |= TRB_TX_TYPE(TRB_DATA_IN);
3067 else
3068 field |= TRB_TX_TYPE(TRB_DATA_OUT);
3069 }
3070 }
3071
2746 queue_trb(xhci, ep_ring, false, true, 3072 queue_trb(xhci, ep_ring, false, true,
2747 /* FIXME endianness is probably going to bite my ass here. */ 3073 setup->bRequestType | setup->bRequest << 8 | le16_to_cpu(setup->wValue) << 16,
2748 setup->bRequestType | setup->bRequest << 8 | setup->wValue << 16, 3074 le16_to_cpu(setup->wIndex) | le16_to_cpu(setup->wLength) << 16,
2749 setup->wIndex | setup->wLength << 16, 3075 TRB_LEN(8) | TRB_INTR_TARGET(0),
2750 TRB_LEN(8) | TRB_INTR_TARGET(0), 3076 /* Immediate data in pointer */
2751 /* Immediate data in pointer */ 3077 field);
2752 TRB_IDT | TRB_TYPE(TRB_SETUP));
2753 3078
2754 /* If there's data, queue data TRBs */ 3079 /* If there's data, queue data TRBs */
2755 field = 0; 3080 /* Only set interrupt on short packet for IN endpoints */
3081 if (usb_urb_dir_in(urb))
3082 field = TRB_ISP | TRB_TYPE(TRB_DATA);
3083 else
3084 field = TRB_TYPE(TRB_DATA);
3085
2756 length_field = TRB_LEN(urb->transfer_buffer_length) | 3086 length_field = TRB_LEN(urb->transfer_buffer_length) |
2757 xhci_td_remainder(urb->transfer_buffer_length) | 3087 xhci_td_remainder(urb->transfer_buffer_length) |
2758 TRB_INTR_TARGET(0); 3088 TRB_INTR_TARGET(0);
@@ -2763,8 +3093,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2763 lower_32_bits(urb->transfer_dma), 3093 lower_32_bits(urb->transfer_dma),
2764 upper_32_bits(urb->transfer_dma), 3094 upper_32_bits(urb->transfer_dma),
2765 length_field, 3095 length_field,
2766 /* Event on short tx */ 3096 field | ep_ring->cycle_state);
2767 field | TRB_ISP | TRB_TYPE(TRB_DATA) | ep_ring->cycle_state);
2768 } 3097 }
2769 3098
2770 /* Save the DMA address of the last TRB in the TD */ 3099 /* Save the DMA address of the last TRB in the TD */
@@ -2784,7 +3113,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2784 field | TRB_IOC | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state); 3113 field | TRB_IOC | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state);
2785 3114
2786 giveback_first_trb(xhci, slot_id, ep_index, 0, 3115 giveback_first_trb(xhci, slot_id, ep_index, 0,
2787 start_cycle, start_trb, td); 3116 start_cycle, start_trb);
2788 return 0; 3117 return 0;
2789} 3118}
2790 3119
@@ -2797,8 +3126,8 @@ static int count_isoc_trbs_needed(struct xhci_hcd *xhci,
2797 addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset); 3126 addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset);
2798 td_len = urb->iso_frame_desc[i].length; 3127 td_len = urb->iso_frame_desc[i].length;
2799 3128
2800 running_total = TRB_MAX_BUFF_SIZE - 3129 running_total = TRB_MAX_BUFF_SIZE - (addr & (TRB_MAX_BUFF_SIZE - 1));
2801 (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); 3130 running_total &= TRB_MAX_BUFF_SIZE - 1;
2802 if (running_total != 0) 3131 if (running_total != 0)
2803 num_trbs++; 3132 num_trbs++;
2804 3133
@@ -2810,6 +3139,63 @@ static int count_isoc_trbs_needed(struct xhci_hcd *xhci,
2810 return num_trbs; 3139 return num_trbs;
2811} 3140}
2812 3141
3142/*
3143 * The transfer burst count field of the isochronous TRB defines the number of
3144 * bursts that are required to move all packets in this TD. Only SuperSpeed
3145 * devices can burst up to bMaxBurst number of packets per service interval.
3146 * This field is zero based, meaning a value of zero in the field means one
3147 * burst. Basically, for everything but SuperSpeed devices, this field will be
3148 * zero. Only xHCI 1.0 host controllers support this field.
3149 */
3150static unsigned int xhci_get_burst_count(struct xhci_hcd *xhci,
3151 struct usb_device *udev,
3152 struct urb *urb, unsigned int total_packet_count)
3153{
3154 unsigned int max_burst;
3155
3156 if (xhci->hci_version < 0x100 || udev->speed != USB_SPEED_SUPER)
3157 return 0;
3158
3159 max_burst = urb->ep->ss_ep_comp.bMaxBurst;
3160 return roundup(total_packet_count, max_burst + 1) - 1;
3161}
3162
3163/*
3164 * Returns the number of packets in the last "burst" of packets. This field is
3165 * valid for all speeds of devices. USB 2.0 devices can only do one "burst", so
3166 * the last burst packet count is equal to the total number of packets in the
3167 * TD. SuperSpeed endpoints can have up to 3 bursts. All but the last burst
3168 * must contain (bMaxBurst + 1) number of packets, but the last burst can
3169 * contain 1 to (bMaxBurst + 1) packets.
3170 */
3171static unsigned int xhci_get_last_burst_packet_count(struct xhci_hcd *xhci,
3172 struct usb_device *udev,
3173 struct urb *urb, unsigned int total_packet_count)
3174{
3175 unsigned int max_burst;
3176 unsigned int residue;
3177
3178 if (xhci->hci_version < 0x100)
3179 return 0;
3180
3181 switch (udev->speed) {
3182 case USB_SPEED_SUPER:
3183 /* bMaxBurst is zero based: 0 means 1 packet per burst */
3184 max_burst = urb->ep->ss_ep_comp.bMaxBurst;
3185 residue = total_packet_count % (max_burst + 1);
3186 /* If residue is zero, the last burst contains (max_burst + 1)
3187 * number of packets, but the TLBPC field is zero-based.
3188 */
3189 if (residue == 0)
3190 return max_burst;
3191 return residue - 1;
3192 default:
3193 if (total_packet_count == 0)
3194 return 0;
3195 return total_packet_count - 1;
3196 }
3197}
3198
2813/* This is for isoc transfer */ 3199/* This is for isoc transfer */
2814static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, 3200static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2815 struct urb *urb, int slot_id, unsigned int ep_index) 3201 struct urb *urb, int slot_id, unsigned int ep_index)
@@ -2825,6 +3211,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2825 int running_total, trb_buff_len, td_len, td_remain_len, ret; 3211 int running_total, trb_buff_len, td_len, td_remain_len, ret;
2826 u64 start_addr, addr; 3212 u64 start_addr, addr;
2827 int i, j; 3213 int i, j;
3214 bool more_trbs_coming;
2828 3215
2829 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; 3216 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
2830 3217
@@ -2835,7 +3222,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2835 } 3222 }
2836 3223
2837 if (!in_interrupt()) 3224 if (!in_interrupt())
2838 dev_dbg(&urb->dev->dev, "ep %#x - urb len = %#x (%d)," 3225 xhci_dbg(xhci, "ep %#x - urb len = %#x (%d),"
2839 " addr = %#llx, num_tds = %d\n", 3226 " addr = %#llx, num_tds = %d\n",
2840 urb->ep->desc.bEndpointAddress, 3227 urb->ep->desc.bEndpointAddress,
2841 urb->transfer_buffer_length, 3228 urb->transfer_buffer_length,
@@ -2849,12 +3236,22 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2849 3236
2850 /* Queue the first TRB, even if it's zero-length */ 3237 /* Queue the first TRB, even if it's zero-length */
2851 for (i = 0; i < num_tds; i++) { 3238 for (i = 0; i < num_tds; i++) {
2852 first_trb = true; 3239 unsigned int total_packet_count;
3240 unsigned int burst_count;
3241 unsigned int residue;
2853 3242
3243 first_trb = true;
2854 running_total = 0; 3244 running_total = 0;
2855 addr = start_addr + urb->iso_frame_desc[i].offset; 3245 addr = start_addr + urb->iso_frame_desc[i].offset;
2856 td_len = urb->iso_frame_desc[i].length; 3246 td_len = urb->iso_frame_desc[i].length;
2857 td_remain_len = td_len; 3247 td_remain_len = td_len;
3248 /* FIXME: Ignoring zero-length packets, can those happen? */
3249 total_packet_count = roundup(td_len,
3250 le16_to_cpu(urb->ep->desc.wMaxPacketSize));
3251 burst_count = xhci_get_burst_count(xhci, urb->dev, urb,
3252 total_packet_count);
3253 residue = xhci_get_last_burst_packet_count(xhci,
3254 urb->dev, urb, total_packet_count);
2858 3255
2859 trbs_per_td = count_isoc_trbs_needed(xhci, urb, i); 3256 trbs_per_td = count_isoc_trbs_needed(xhci, urb, i);
2860 3257
@@ -2868,14 +3265,17 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2868 3265
2869 for (j = 0; j < trbs_per_td; j++) { 3266 for (j = 0; j < trbs_per_td; j++) {
2870 u32 remainder = 0; 3267 u32 remainder = 0;
2871 field = 0; 3268 field = TRB_TBC(burst_count) | TRB_TLBPC(residue);
2872 3269
2873 if (first_trb) { 3270 if (first_trb) {
2874 /* Queue the isoc TRB */ 3271 /* Queue the isoc TRB */
2875 field |= TRB_TYPE(TRB_ISOC); 3272 field |= TRB_TYPE(TRB_ISOC);
2876 /* Assume URB_ISO_ASAP is set */ 3273 /* Assume URB_ISO_ASAP is set */
2877 field |= TRB_SIA; 3274 field |= TRB_SIA;
2878 if (i > 0) 3275 if (i == 0) {
3276 if (start_cycle == 0)
3277 field |= 0x1;
3278 } else
2879 field |= ep_ring->cycle_state; 3279 field |= ep_ring->cycle_state;
2880 first_trb = false; 3280 first_trb = false;
2881 } else { 3281 } else {
@@ -2884,15 +3284,26 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2884 field |= ep_ring->cycle_state; 3284 field |= ep_ring->cycle_state;
2885 } 3285 }
2886 3286
3287 /* Only set interrupt on short packet for IN EPs */
3288 if (usb_urb_dir_in(urb))
3289 field |= TRB_ISP;
3290
2887 /* Chain all the TRBs together; clear the chain bit in 3291 /* Chain all the TRBs together; clear the chain bit in
2888 * the last TRB to indicate it's the last TRB in the 3292 * the last TRB to indicate it's the last TRB in the
2889 * chain. 3293 * chain.
2890 */ 3294 */
2891 if (j < trbs_per_td - 1) { 3295 if (j < trbs_per_td - 1) {
2892 field |= TRB_CHAIN; 3296 field |= TRB_CHAIN;
3297 more_trbs_coming = true;
2893 } else { 3298 } else {
2894 td->last_trb = ep_ring->enqueue; 3299 td->last_trb = ep_ring->enqueue;
2895 field |= TRB_IOC; 3300 field |= TRB_IOC;
3301 if (xhci->hci_version == 0x100) {
3302 /* Set BEI bit except for the last td */
3303 if (i < num_tds - 1)
3304 field |= TRB_BEI;
3305 }
3306 more_trbs_coming = false;
2896 } 3307 }
2897 3308
2898 /* Calculate TRB length */ 3309 /* Calculate TRB length */
@@ -2901,20 +3312,24 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2901 if (trb_buff_len > td_remain_len) 3312 if (trb_buff_len > td_remain_len)
2902 trb_buff_len = td_remain_len; 3313 trb_buff_len = td_remain_len;
2903 3314
2904 remainder = xhci_td_remainder(td_len - running_total); 3315 /* Set the TRB length, TD size, & interrupter fields. */
3316 if (xhci->hci_version < 0x100) {
3317 remainder = xhci_td_remainder(
3318 td_len - running_total);
3319 } else {
3320 remainder = xhci_v1_0_td_remainder(
3321 running_total, trb_buff_len,
3322 total_packet_count, urb);
3323 }
2905 length_field = TRB_LEN(trb_buff_len) | 3324 length_field = TRB_LEN(trb_buff_len) |
2906 remainder | 3325 remainder |
2907 TRB_INTR_TARGET(0); 3326 TRB_INTR_TARGET(0);
2908 queue_trb(xhci, ep_ring, false, false, 3327
3328 queue_trb(xhci, ep_ring, false, more_trbs_coming,
2909 lower_32_bits(addr), 3329 lower_32_bits(addr),
2910 upper_32_bits(addr), 3330 upper_32_bits(addr),
2911 length_field, 3331 length_field,
2912 /* We always want to know if the TRB was short, 3332 field);
2913 * or we won't get an event when it completes.
2914 * (Unless we use event data TRBs, which are a
2915 * waste of space and HC resources.)
2916 */
2917 field | TRB_ISP);
2918 running_total += trb_buff_len; 3333 running_total += trb_buff_len;
2919 3334
2920 addr += trb_buff_len; 3335 addr += trb_buff_len;
@@ -2928,10 +3343,14 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2928 } 3343 }
2929 } 3344 }
2930 3345
2931 wmb(); 3346 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) {
2932 start_trb->field[3] |= start_cycle; 3347 if (xhci->quirks & XHCI_AMD_PLL_FIX)
3348 usb_amd_quirk_pll_disable();
3349 }
3350 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++;
2933 3351
2934 ring_ep_doorbell(xhci, slot_id, ep_index, urb->stream_id); 3352 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id,
3353 start_cycle, start_trb);
2935 return 0; 3354 return 0;
2936} 3355}
2937 3356
@@ -2966,8 +3385,8 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
2966 /* Check the ring to guarantee there is enough room for the whole urb. 3385 /* Check the ring to guarantee there is enough room for the whole urb.
2967 * Do not insert any td of the urb to the ring if the check failed. 3386 * Do not insert any td of the urb to the ring if the check failed.
2968 */ 3387 */
2969 ret = prepare_ring(xhci, ep_ring, ep_ctx->ep_info & EP_STATE_MASK, 3388 ret = prepare_ring(xhci, ep_ring, le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK,
2970 num_trbs, mem_flags); 3389 num_trbs, mem_flags);
2971 if (ret) 3390 if (ret)
2972 return ret; 3391 return ret;
2973 3392
@@ -2979,7 +3398,7 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
2979 urb->dev->speed == USB_SPEED_FULL) 3398 urb->dev->speed == USB_SPEED_FULL)
2980 urb->start_frame >>= 3; 3399 urb->start_frame >>= 3;
2981 3400
2982 xhci_interval = EP_INTERVAL_TO_UFRAMES(ep_ctx->ep_info); 3401 xhci_interval = EP_INTERVAL_TO_UFRAMES(le32_to_cpu(ep_ctx->ep_info));
2983 ep_interval = urb->interval; 3402 ep_interval = urb->interval;
2984 /* Convert to microframes */ 3403 /* Convert to microframes */
2985 if (urb->dev->speed == USB_SPEED_LOW || 3404 if (urb->dev->speed == USB_SPEED_LOW ||
@@ -2989,7 +3408,7 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
2989 * to set the polling interval (once the API is added). 3408 * to set the polling interval (once the API is added).
2990 */ 3409 */
2991 if (xhci_interval != ep_interval) { 3410 if (xhci_interval != ep_interval) {
2992 if (!printk_ratelimit()) 3411 if (printk_ratelimit())
2993 dev_dbg(&urb->dev->dev, "Driver uses different interval" 3412 dev_dbg(&urb->dev->dev, "Driver uses different interval"
2994 " (%d microframe%s) than xHCI " 3413 " (%d microframe%s) than xHCI "
2995 "(%d microframe%s)\n", 3414 "(%d microframe%s)\n",
@@ -3039,24 +3458,6 @@ static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2,
3039 return 0; 3458 return 0;
3040} 3459}
3041 3460
3042/* Queue a no-op command on the command ring */
3043static int queue_cmd_noop(struct xhci_hcd *xhci)
3044{
3045 return queue_command(xhci, 0, 0, 0, TRB_TYPE(TRB_CMD_NOOP), false);
3046}
3047
3048/*
3049 * Place a no-op command on the command ring to test the command and
3050 * event ring.
3051 */
3052void *xhci_setup_one_noop(struct xhci_hcd *xhci)
3053{
3054 if (queue_cmd_noop(xhci) < 0)
3055 return NULL;
3056 xhci->noops_submitted++;
3057 return xhci_ring_cmd_db;
3058}
3059
3060/* Queue a slot enable or disable request on the command ring */ 3461/* Queue a slot enable or disable request on the command ring */
3061int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) 3462int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id)
3062{ 3463{
@@ -3108,15 +3509,20 @@ int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
3108 false); 3509 false);
3109} 3510}
3110 3511
3512/*
3513 * Suspend is set to indicate "Stop Endpoint Command" is being issued to stop
3514 * activity on an endpoint that is about to be suspended.
3515 */
3111int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, 3516int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
3112 unsigned int ep_index) 3517 unsigned int ep_index, int suspend)
3113{ 3518{
3114 u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); 3519 u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id);
3115 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); 3520 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
3116 u32 type = TRB_TYPE(TRB_STOP_RING); 3521 u32 type = TRB_TYPE(TRB_STOP_RING);
3522 u32 trb_suspend = SUSPEND_PORT_FOR_TRB(suspend);
3117 3523
3118 return queue_command(xhci, 0, 0, 0, 3524 return queue_command(xhci, 0, 0, 0,
3119 trb_slot_id | trb_ep_index | type, false); 3525 trb_slot_id | trb_ep_index | type | trb_suspend, false);
3120} 3526}
3121 3527
3122/* Set Transfer Ring Dequeue Pointer command. 3528/* Set Transfer Ring Dequeue Pointer command.
@@ -3132,6 +3538,7 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
3132 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); 3538 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
3133 u32 trb_stream_id = STREAM_ID_FOR_TRB(stream_id); 3539 u32 trb_stream_id = STREAM_ID_FOR_TRB(stream_id);
3134 u32 type = TRB_TYPE(TRB_SET_DEQ); 3540 u32 type = TRB_TYPE(TRB_SET_DEQ);
3541 struct xhci_virt_ep *ep;
3135 3542
3136 addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr); 3543 addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr);
3137 if (addr == 0) { 3544 if (addr == 0) {
@@ -3140,6 +3547,14 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
3140 deq_seg, deq_ptr); 3547 deq_seg, deq_ptr);
3141 return 0; 3548 return 0;
3142 } 3549 }
3550 ep = &xhci->devs[slot_id]->eps[ep_index];
3551 if ((ep->ep_state & SET_DEQ_PENDING)) {
3552 xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n");
3553 xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n");
3554 return 0;
3555 }
3556 ep->queued_deq_seg = deq_seg;
3557 ep->queued_deq_ptr = deq_ptr;
3143 return queue_command(xhci, lower_32_bits(addr) | cycle_state, 3558 return queue_command(xhci, lower_32_bits(addr) | cycle_state,
3144 upper_32_bits(addr), trb_stream_id, 3559 upper_32_bits(addr), trb_stream_id,
3145 trb_slot_id | trb_ep_index | type, false); 3560 trb_slot_id | trb_ep_index | type, false);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index d5c550ea3e68..f5fe1ac301ab 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -93,23 +93,26 @@ void xhci_quiesce(struct xhci_hcd *xhci)
93 * 93 *
94 * Disable any IRQs and clear the run/stop bit. 94 * Disable any IRQs and clear the run/stop bit.
95 * HC will complete any current and actively pipelined transactions, and 95 * HC will complete any current and actively pipelined transactions, and
96 * should halt within 16 microframes of the run/stop bit being cleared. 96 * should halt within 16 ms of the run/stop bit being cleared.
97 * Read HC Halted bit in the status register to see when the HC is finished. 97 * Read HC Halted bit in the status register to see when the HC is finished.
98 * XXX: shouldn't we set HC_STATE_HALT here somewhere?
99 */ 98 */
100int xhci_halt(struct xhci_hcd *xhci) 99int xhci_halt(struct xhci_hcd *xhci)
101{ 100{
101 int ret;
102 xhci_dbg(xhci, "// Halt the HC\n"); 102 xhci_dbg(xhci, "// Halt the HC\n");
103 xhci_quiesce(xhci); 103 xhci_quiesce(xhci);
104 104
105 return handshake(xhci, &xhci->op_regs->status, 105 ret = handshake(xhci, &xhci->op_regs->status,
106 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); 106 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC);
107 if (!ret)
108 xhci->xhc_state |= XHCI_STATE_HALTED;
109 return ret;
107} 110}
108 111
109/* 112/*
110 * Set the run bit and wait for the host to be running. 113 * Set the run bit and wait for the host to be running.
111 */ 114 */
112int xhci_start(struct xhci_hcd *xhci) 115static int xhci_start(struct xhci_hcd *xhci)
113{ 116{
114 u32 temp; 117 u32 temp;
115 int ret; 118 int ret;
@@ -130,11 +133,13 @@ int xhci_start(struct xhci_hcd *xhci)
130 xhci_err(xhci, "Host took too long to start, " 133 xhci_err(xhci, "Host took too long to start, "
131 "waited %u microseconds.\n", 134 "waited %u microseconds.\n",
132 XHCI_MAX_HALT_USEC); 135 XHCI_MAX_HALT_USEC);
136 if (!ret)
137 xhci->xhc_state &= ~XHCI_STATE_HALTED;
133 return ret; 138 return ret;
134} 139}
135 140
136/* 141/*
137 * Reset a halted HC, and set the internal HC state to HC_STATE_HALT. 142 * Reset a halted HC.
138 * 143 *
139 * This resets pipelines, timers, counters, state machines, etc. 144 * This resets pipelines, timers, counters, state machines, etc.
140 * Transactions will be terminated immediately, and operational registers 145 * Transactions will be terminated immediately, and operational registers
@@ -156,8 +161,6 @@ int xhci_reset(struct xhci_hcd *xhci)
156 command = xhci_readl(xhci, &xhci->op_regs->command); 161 command = xhci_readl(xhci, &xhci->op_regs->command);
157 command |= CMD_RESET; 162 command |= CMD_RESET;
158 xhci_writel(xhci, command, &xhci->op_regs->command); 163 xhci_writel(xhci, command, &xhci->op_regs->command);
159 /* XXX: Why does EHCI set this here? Shouldn't other code do this? */
160 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
161 164
162 ret = handshake(xhci, &xhci->op_regs->command, 165 ret = handshake(xhci, &xhci->op_regs->command,
163 CMD_RESET, 0, 250 * 1000); 166 CMD_RESET, 0, 250 * 1000);
@@ -226,7 +229,8 @@ static int xhci_setup_msi(struct xhci_hcd *xhci)
226static int xhci_setup_msix(struct xhci_hcd *xhci) 229static int xhci_setup_msix(struct xhci_hcd *xhci)
227{ 230{
228 int i, ret = 0; 231 int i, ret = 0;
229 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 232 struct usb_hcd *hcd = xhci_to_hcd(xhci);
233 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
230 234
231 /* 235 /*
232 * calculate number of msi-x vectors supported. 236 * calculate number of msi-x vectors supported.
@@ -265,6 +269,7 @@ static int xhci_setup_msix(struct xhci_hcd *xhci)
265 goto disable_msix; 269 goto disable_msix;
266 } 270 }
267 271
272 hcd->msix_enabled = 1;
268 return ret; 273 return ret;
269 274
270disable_msix: 275disable_msix:
@@ -280,7 +285,8 @@ free_entries:
280/* Free any IRQs and disable MSI-X */ 285/* Free any IRQs and disable MSI-X */
281static void xhci_cleanup_msix(struct xhci_hcd *xhci) 286static void xhci_cleanup_msix(struct xhci_hcd *xhci)
282{ 287{
283 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 288 struct usb_hcd *hcd = xhci_to_hcd(xhci);
289 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
284 290
285 xhci_free_irq(xhci); 291 xhci_free_irq(xhci);
286 292
@@ -292,6 +298,7 @@ static void xhci_cleanup_msix(struct xhci_hcd *xhci)
292 pci_disable_msi(pdev); 298 pci_disable_msi(pdev);
293 } 299 }
294 300
301 hcd->msix_enabled = 0;
295 return; 302 return;
296} 303}
297 304
@@ -325,7 +332,7 @@ int xhci_init(struct usb_hcd *hcd)
325 332
326 333
327#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 334#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
328void xhci_event_ring_work(unsigned long arg) 335static void xhci_event_ring_work(unsigned long arg)
329{ 336{
330 unsigned long flags; 337 unsigned long flags;
331 int temp; 338 int temp;
@@ -346,7 +353,6 @@ void xhci_event_ring_work(unsigned long arg)
346 353
347 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); 354 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
348 xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp); 355 xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp);
349 xhci_dbg(xhci, "No-op commands handled = %d\n", xhci->noops_handled);
350 xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask); 356 xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask);
351 xhci->error_bitmask = 0; 357 xhci->error_bitmask = 0;
352 xhci_dbg(xhci, "Event ring:\n"); 358 xhci_dbg(xhci, "Event ring:\n");
@@ -366,10 +372,6 @@ void xhci_event_ring_work(unsigned long arg)
366 xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]); 372 xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]);
367 } 373 }
368 } 374 }
369
370 if (xhci->noops_submitted != NUM_TEST_NOOPS)
371 if (xhci_setup_one_noop(xhci))
372 xhci_ring_cmd_db(xhci);
373 spin_unlock_irqrestore(&xhci->lock, flags); 375 spin_unlock_irqrestore(&xhci->lock, flags);
374 376
375 if (!xhci->zombie) 377 if (!xhci->zombie)
@@ -379,6 +381,21 @@ void xhci_event_ring_work(unsigned long arg)
379} 381}
380#endif 382#endif
381 383
384static int xhci_run_finished(struct xhci_hcd *xhci)
385{
386 if (xhci_start(xhci)) {
387 xhci_halt(xhci);
388 return -ENODEV;
389 }
390 xhci->shared_hcd->state = HC_STATE_RUNNING;
391
392 if (xhci->quirks & XHCI_NEC_HOST)
393 xhci_ring_cmd_db(xhci);
394
395 xhci_dbg(xhci, "Finished xhci_run for USB3 roothub\n");
396 return 0;
397}
398
382/* 399/*
383 * Start the HC after it was halted. 400 * Start the HC after it was halted.
384 * 401 *
@@ -398,9 +415,14 @@ int xhci_run(struct usb_hcd *hcd)
398 u32 ret; 415 u32 ret;
399 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 416 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
400 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 417 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
401 void (*doorbell)(struct xhci_hcd *) = NULL; 418
419 /* Start the xHCI host controller running only after the USB 2.0 roothub
420 * is setup.
421 */
402 422
403 hcd->uses_new_polling = 1; 423 hcd->uses_new_polling = 1;
424 if (!usb_hcd_is_primary_hcd(hcd))
425 return xhci_run_finished(xhci);
404 426
405 xhci_dbg(xhci, "xhci_run\n"); 427 xhci_dbg(xhci, "xhci_run\n");
406 /* unregister the legacy interrupt */ 428 /* unregister the legacy interrupt */
@@ -408,12 +430,19 @@ int xhci_run(struct usb_hcd *hcd)
408 free_irq(hcd->irq, hcd); 430 free_irq(hcd->irq, hcd);
409 hcd->irq = -1; 431 hcd->irq = -1;
410 432
433 /* Some Fresco Logic host controllers advertise MSI, but fail to
434 * generate interrupts. Don't even try to enable MSI.
435 */
436 if (xhci->quirks & XHCI_BROKEN_MSI)
437 goto legacy_irq;
438
411 ret = xhci_setup_msix(xhci); 439 ret = xhci_setup_msix(xhci);
412 if (ret) 440 if (ret)
413 /* fall back to msi*/ 441 /* fall back to msi*/
414 ret = xhci_setup_msi(xhci); 442 ret = xhci_setup_msi(xhci);
415 443
416 if (ret) { 444 if (ret) {
445legacy_irq:
417 /* fall back to legacy interrupt*/ 446 /* fall back to legacy interrupt*/
418 ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, 447 ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED,
419 hcd->irq_descr, hcd); 448 hcd->irq_descr, hcd);
@@ -457,7 +486,6 @@ int xhci_run(struct usb_hcd *hcd)
457 xhci_writel(xhci, temp, &xhci->ir_set->irq_control); 486 xhci_writel(xhci, temp, &xhci->ir_set->irq_control);
458 487
459 /* Set the HCD state before we enable the irqs */ 488 /* Set the HCD state before we enable the irqs */
460 hcd->state = HC_STATE_RUNNING;
461 temp = xhci_readl(xhci, &xhci->op_regs->command); 489 temp = xhci_readl(xhci, &xhci->op_regs->command);
462 temp |= (CMD_EIE); 490 temp |= (CMD_EIE);
463 xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n", 491 xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n",
@@ -469,26 +497,29 @@ int xhci_run(struct usb_hcd *hcd)
469 xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp)); 497 xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp));
470 xhci_writel(xhci, ER_IRQ_ENABLE(temp), 498 xhci_writel(xhci, ER_IRQ_ENABLE(temp),
471 &xhci->ir_set->irq_pending); 499 &xhci->ir_set->irq_pending);
472 xhci_print_ir_set(xhci, xhci->ir_set, 0); 500 xhci_print_ir_set(xhci, 0);
473 501
474 if (NUM_TEST_NOOPS > 0)
475 doorbell = xhci_setup_one_noop(xhci);
476 if (xhci->quirks & XHCI_NEC_HOST) 502 if (xhci->quirks & XHCI_NEC_HOST)
477 xhci_queue_vendor_command(xhci, 0, 0, 0, 503 xhci_queue_vendor_command(xhci, 0, 0, 0,
478 TRB_TYPE(TRB_NEC_GET_FW)); 504 TRB_TYPE(TRB_NEC_GET_FW));
479 505
480 if (xhci_start(xhci)) { 506 xhci_dbg(xhci, "Finished xhci_run for USB2 roothub\n");
481 xhci_halt(xhci); 507 return 0;
482 return -ENODEV; 508}
483 }
484 509
485 if (doorbell) 510static void xhci_only_stop_hcd(struct usb_hcd *hcd)
486 (*doorbell)(xhci); 511{
487 if (xhci->quirks & XHCI_NEC_HOST) 512 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
488 xhci_ring_cmd_db(xhci);
489 513
490 xhci_dbg(xhci, "Finished xhci_run\n"); 514 spin_lock_irq(&xhci->lock);
491 return 0; 515 xhci_halt(xhci);
516
517 /* The shared_hcd is going to be deallocated shortly (the USB core only
518 * calls this function when allocation fails in usb_add_hcd(), or
519 * usb_remove_hcd() is called). So we need to unset xHCI's pointer.
520 */
521 xhci->shared_hcd = NULL;
522 spin_unlock_irq(&xhci->lock);
492} 523}
493 524
494/* 525/*
@@ -505,25 +536,37 @@ void xhci_stop(struct usb_hcd *hcd)
505 u32 temp; 536 u32 temp;
506 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 537 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
507 538
539 if (!usb_hcd_is_primary_hcd(hcd)) {
540 xhci_only_stop_hcd(xhci->shared_hcd);
541 return;
542 }
543
508 spin_lock_irq(&xhci->lock); 544 spin_lock_irq(&xhci->lock);
545 /* Make sure the xHC is halted for a USB3 roothub
546 * (xhci_stop() could be called as part of failed init).
547 */
509 xhci_halt(xhci); 548 xhci_halt(xhci);
510 xhci_reset(xhci); 549 xhci_reset(xhci);
511 xhci_cleanup_msix(xhci);
512 spin_unlock_irq(&xhci->lock); 550 spin_unlock_irq(&xhci->lock);
513 551
552 xhci_cleanup_msix(xhci);
553
514#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 554#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
515 /* Tell the event ring poll function not to reschedule */ 555 /* Tell the event ring poll function not to reschedule */
516 xhci->zombie = 1; 556 xhci->zombie = 1;
517 del_timer_sync(&xhci->event_ring_timer); 557 del_timer_sync(&xhci->event_ring_timer);
518#endif 558#endif
519 559
560 if (xhci->quirks & XHCI_AMD_PLL_FIX)
561 usb_amd_dev_put();
562
520 xhci_dbg(xhci, "// Disabling event ring interrupts\n"); 563 xhci_dbg(xhci, "// Disabling event ring interrupts\n");
521 temp = xhci_readl(xhci, &xhci->op_regs->status); 564 temp = xhci_readl(xhci, &xhci->op_regs->status);
522 xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status); 565 xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status);
523 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); 566 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
524 xhci_writel(xhci, ER_IRQ_DISABLE(temp), 567 xhci_writel(xhci, ER_IRQ_DISABLE(temp),
525 &xhci->ir_set->irq_pending); 568 &xhci->ir_set->irq_pending);
526 xhci_print_ir_set(xhci, xhci->ir_set, 0); 569 xhci_print_ir_set(xhci, 0);
527 570
528 xhci_dbg(xhci, "cleaning up memory\n"); 571 xhci_dbg(xhci, "cleaning up memory\n");
529 xhci_mem_cleanup(xhci); 572 xhci_mem_cleanup(xhci);
@@ -537,6 +580,8 @@ void xhci_stop(struct usb_hcd *hcd)
537 * This is called when the machine is rebooting or halting. We assume that the 580 * This is called when the machine is rebooting or halting. We assume that the
538 * machine will be powered off, and the HC's internal state will be reset. 581 * machine will be powered off, and the HC's internal state will be reset.
539 * Don't bother to free memory. 582 * Don't bother to free memory.
583 *
584 * This will only ever be called with the main usb_hcd (the USB3 roothub).
540 */ 585 */
541void xhci_shutdown(struct usb_hcd *hcd) 586void xhci_shutdown(struct usb_hcd *hcd)
542{ 587{
@@ -544,13 +589,284 @@ void xhci_shutdown(struct usb_hcd *hcd)
544 589
545 spin_lock_irq(&xhci->lock); 590 spin_lock_irq(&xhci->lock);
546 xhci_halt(xhci); 591 xhci_halt(xhci);
547 xhci_cleanup_msix(xhci);
548 spin_unlock_irq(&xhci->lock); 592 spin_unlock_irq(&xhci->lock);
549 593
594 xhci_cleanup_msix(xhci);
595
550 xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n", 596 xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n",
551 xhci_readl(xhci, &xhci->op_regs->status)); 597 xhci_readl(xhci, &xhci->op_regs->status));
552} 598}
553 599
600#ifdef CONFIG_PM
601static void xhci_save_registers(struct xhci_hcd *xhci)
602{
603 xhci->s3.command = xhci_readl(xhci, &xhci->op_regs->command);
604 xhci->s3.dev_nt = xhci_readl(xhci, &xhci->op_regs->dev_notification);
605 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
606 xhci->s3.config_reg = xhci_readl(xhci, &xhci->op_regs->config_reg);
607 xhci->s3.irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending);
608 xhci->s3.irq_control = xhci_readl(xhci, &xhci->ir_set->irq_control);
609 xhci->s3.erst_size = xhci_readl(xhci, &xhci->ir_set->erst_size);
610 xhci->s3.erst_base = xhci_read_64(xhci, &xhci->ir_set->erst_base);
611 xhci->s3.erst_dequeue = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
612}
613
614static void xhci_restore_registers(struct xhci_hcd *xhci)
615{
616 xhci_writel(xhci, xhci->s3.command, &xhci->op_regs->command);
617 xhci_writel(xhci, xhci->s3.dev_nt, &xhci->op_regs->dev_notification);
618 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr);
619 xhci_writel(xhci, xhci->s3.config_reg, &xhci->op_regs->config_reg);
620 xhci_writel(xhci, xhci->s3.irq_pending, &xhci->ir_set->irq_pending);
621 xhci_writel(xhci, xhci->s3.irq_control, &xhci->ir_set->irq_control);
622 xhci_writel(xhci, xhci->s3.erst_size, &xhci->ir_set->erst_size);
623 xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base);
624}
625
626static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
627{
628 u64 val_64;
629
630 /* step 2: initialize command ring buffer */
631 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
632 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
633 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
634 xhci->cmd_ring->dequeue) &
635 (u64) ~CMD_RING_RSVD_BITS) |
636 xhci->cmd_ring->cycle_state;
637 xhci_dbg(xhci, "// Setting command ring address to 0x%llx\n",
638 (long unsigned long) val_64);
639 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
640}
641
642/*
643 * The whole command ring must be cleared to zero when we suspend the host.
644 *
645 * The host doesn't save the command ring pointer in the suspend well, so we
646 * need to re-program it on resume. Unfortunately, the pointer must be 64-byte
647 * aligned, because of the reserved bits in the command ring dequeue pointer
648 * register. Therefore, we can't just set the dequeue pointer back in the
649 * middle of the ring (TRBs are 16-byte aligned).
650 */
651static void xhci_clear_command_ring(struct xhci_hcd *xhci)
652{
653 struct xhci_ring *ring;
654 struct xhci_segment *seg;
655
656 ring = xhci->cmd_ring;
657 seg = ring->deq_seg;
658 do {
659 memset(seg->trbs, 0, SEGMENT_SIZE);
660 seg = seg->next;
661 } while (seg != ring->deq_seg);
662
663 /* Reset the software enqueue and dequeue pointers */
664 ring->deq_seg = ring->first_seg;
665 ring->dequeue = ring->first_seg->trbs;
666 ring->enq_seg = ring->deq_seg;
667 ring->enqueue = ring->dequeue;
668
669 /*
670 * Ring is now zeroed, so the HW should look for change of ownership
671 * when the cycle bit is set to 1.
672 */
673 ring->cycle_state = 1;
674
675 /*
676 * Reset the hardware dequeue pointer.
677 * Yes, this will need to be re-written after resume, but we're paranoid
678 * and want to make sure the hardware doesn't access bogus memory
679 * because, say, the BIOS or an SMI started the host without changing
680 * the command ring pointers.
681 */
682 xhci_set_cmd_ring_deq(xhci);
683}
684
685/*
686 * Stop HC (not bus-specific)
687 *
688 * This is called when the machine transition into S3/S4 mode.
689 *
690 */
691int xhci_suspend(struct xhci_hcd *xhci)
692{
693 int rc = 0;
694 struct usb_hcd *hcd = xhci_to_hcd(xhci);
695 u32 command;
696 int i;
697
698 spin_lock_irq(&xhci->lock);
699 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
700 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
701 /* step 1: stop endpoint */
702 /* skipped assuming that port suspend has done */
703
704 /* step 2: clear Run/Stop bit */
705 command = xhci_readl(xhci, &xhci->op_regs->command);
706 command &= ~CMD_RUN;
707 xhci_writel(xhci, command, &xhci->op_regs->command);
708 if (handshake(xhci, &xhci->op_regs->status,
709 STS_HALT, STS_HALT, 100*100)) {
710 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n");
711 spin_unlock_irq(&xhci->lock);
712 return -ETIMEDOUT;
713 }
714 xhci_clear_command_ring(xhci);
715
716 /* step 3: save registers */
717 xhci_save_registers(xhci);
718
719 /* step 4: set CSS flag */
720 command = xhci_readl(xhci, &xhci->op_regs->command);
721 command |= CMD_CSS;
722 xhci_writel(xhci, command, &xhci->op_regs->command);
723 if (handshake(xhci, &xhci->op_regs->status, STS_SAVE, 0, 10*100)) {
724 xhci_warn(xhci, "WARN: xHC CMD_CSS timeout\n");
725 spin_unlock_irq(&xhci->lock);
726 return -ETIMEDOUT;
727 }
728 spin_unlock_irq(&xhci->lock);
729
730 /* step 5: remove core well power */
731 /* synchronize irq when using MSI-X */
732 if (xhci->msix_entries) {
733 for (i = 0; i < xhci->msix_count; i++)
734 synchronize_irq(xhci->msix_entries[i].vector);
735 }
736
737 return rc;
738}
739
740/*
741 * start xHC (not bus-specific)
742 *
743 * This is called when the machine transition from S3/S4 mode.
744 *
745 */
746int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
747{
748 u32 command, temp = 0;
749 struct usb_hcd *hcd = xhci_to_hcd(xhci);
750 struct usb_hcd *secondary_hcd;
751 int retval;
752
753 /* Wait a bit if either of the roothubs need to settle from the
754 * transition into bus suspend.
755 */
756 if (time_before(jiffies, xhci->bus_state[0].next_statechange) ||
757 time_before(jiffies,
758 xhci->bus_state[1].next_statechange))
759 msleep(100);
760
761 spin_lock_irq(&xhci->lock);
762 if (xhci->quirks & XHCI_RESET_ON_RESUME)
763 hibernated = true;
764
765 if (!hibernated) {
766 /* step 1: restore register */
767 xhci_restore_registers(xhci);
768 /* step 2: initialize command ring buffer */
769 xhci_set_cmd_ring_deq(xhci);
770 /* step 3: restore state and start state*/
771 /* step 3: set CRS flag */
772 command = xhci_readl(xhci, &xhci->op_regs->command);
773 command |= CMD_CRS;
774 xhci_writel(xhci, command, &xhci->op_regs->command);
775 if (handshake(xhci, &xhci->op_regs->status,
776 STS_RESTORE, 0, 10*100)) {
777 xhci_dbg(xhci, "WARN: xHC CMD_CSS timeout\n");
778 spin_unlock_irq(&xhci->lock);
779 return -ETIMEDOUT;
780 }
781 temp = xhci_readl(xhci, &xhci->op_regs->status);
782 }
783
784 /* If restore operation fails, re-initialize the HC during resume */
785 if ((temp & STS_SRE) || hibernated) {
786 /* Let the USB core know _both_ roothubs lost power. */
787 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub);
788 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub);
789
790 xhci_dbg(xhci, "Stop HCD\n");
791 xhci_halt(xhci);
792 xhci_reset(xhci);
793 spin_unlock_irq(&xhci->lock);
794 xhci_cleanup_msix(xhci);
795
796#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
797 /* Tell the event ring poll function not to reschedule */
798 xhci->zombie = 1;
799 del_timer_sync(&xhci->event_ring_timer);
800#endif
801
802 xhci_dbg(xhci, "// Disabling event ring interrupts\n");
803 temp = xhci_readl(xhci, &xhci->op_regs->status);
804 xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status);
805 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
806 xhci_writel(xhci, ER_IRQ_DISABLE(temp),
807 &xhci->ir_set->irq_pending);
808 xhci_print_ir_set(xhci, 0);
809
810 xhci_dbg(xhci, "cleaning up memory\n");
811 xhci_mem_cleanup(xhci);
812 xhci_dbg(xhci, "xhci_stop completed - status = %x\n",
813 xhci_readl(xhci, &xhci->op_regs->status));
814
815 /* USB core calls the PCI reinit and start functions twice:
816 * first with the primary HCD, and then with the secondary HCD.
817 * If we don't do the same, the host will never be started.
818 */
819 if (!usb_hcd_is_primary_hcd(hcd))
820 secondary_hcd = hcd;
821 else
822 secondary_hcd = xhci->shared_hcd;
823
824 xhci_dbg(xhci, "Initialize the xhci_hcd\n");
825 retval = xhci_init(hcd->primary_hcd);
826 if (retval)
827 return retval;
828 xhci_dbg(xhci, "Start the primary HCD\n");
829 retval = xhci_run(hcd->primary_hcd);
830 if (retval)
831 goto failed_restart;
832
833 xhci_dbg(xhci, "Start the secondary HCD\n");
834 retval = xhci_run(secondary_hcd);
835 if (!retval) {
836 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
837 set_bit(HCD_FLAG_HW_ACCESSIBLE,
838 &xhci->shared_hcd->flags);
839 }
840failed_restart:
841 hcd->state = HC_STATE_SUSPENDED;
842 xhci->shared_hcd->state = HC_STATE_SUSPENDED;
843 return retval;
844 }
845
846 /* step 4: set Run/Stop bit */
847 command = xhci_readl(xhci, &xhci->op_regs->command);
848 command |= CMD_RUN;
849 xhci_writel(xhci, command, &xhci->op_regs->command);
850 handshake(xhci, &xhci->op_regs->status, STS_HALT,
851 0, 250 * 1000);
852
853 /* step 5: walk topology and initialize portsc,
854 * portpmsc and portli
855 */
856 /* this is done in bus_resume */
857
858 /* step 6: restart each of the previously
859 * Running endpoints by ringing their doorbells
860 */
861
862 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
863 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
864
865 spin_unlock_irq(&xhci->lock);
866 return 0;
867}
868#endif /* CONFIG_PM */
869
554/*-------------------------------------------------------------------------*/ 870/*-------------------------------------------------------------------------*/
555 871
556/** 872/**
@@ -606,8 +922,12 @@ unsigned int xhci_last_valid_endpoint(u32 added_ctxs)
606/* Returns 1 if the arguments are OK; 922/* Returns 1 if the arguments are OK;
607 * returns 0 this is a root hub; returns -EINVAL for NULL pointers. 923 * returns 0 this is a root hub; returns -EINVAL for NULL pointers.
608 */ 924 */
609int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev, 925static int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev,
610 struct usb_host_endpoint *ep, int check_ep, const char *func) { 926 struct usb_host_endpoint *ep, int check_ep, bool check_virt_dev,
927 const char *func) {
928 struct xhci_hcd *xhci;
929 struct xhci_virt_device *virt_dev;
930
611 if (!hcd || (check_ep && !ep) || !udev) { 931 if (!hcd || (check_ep && !ep) || !udev) {
612 printk(KERN_DEBUG "xHCI %s called with invalid args\n", 932 printk(KERN_DEBUG "xHCI %s called with invalid args\n",
613 func); 933 func);
@@ -618,11 +938,24 @@ int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev,
618 func); 938 func);
619 return 0; 939 return 0;
620 } 940 }
621 if (!udev->slot_id) { 941
622 printk(KERN_DEBUG "xHCI %s called with unaddressed device\n", 942 if (check_virt_dev) {
623 func); 943 xhci = hcd_to_xhci(hcd);
624 return -EINVAL; 944 if (!udev->slot_id || !xhci->devs
945 || !xhci->devs[udev->slot_id]) {
946 printk(KERN_DEBUG "xHCI %s called with unaddressed "
947 "device\n", func);
948 return -EINVAL;
949 }
950
951 virt_dev = xhci->devs[udev->slot_id];
952 if (virt_dev->udev != udev) {
953 printk(KERN_DEBUG "xHCI %s called with udev and "
954 "virt_dev does not match\n", func);
955 return -EINVAL;
956 }
625 } 957 }
958
626 return 1; 959 return 1;
627} 960}
628 961
@@ -649,8 +982,8 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
649 982
650 out_ctx = xhci->devs[slot_id]->out_ctx; 983 out_ctx = xhci->devs[slot_id]->out_ctx;
651 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); 984 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
652 hw_max_packet_size = MAX_PACKET_DECODED(ep_ctx->ep_info2); 985 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2));
653 max_packet_size = urb->dev->ep0.desc.wMaxPacketSize; 986 max_packet_size = le16_to_cpu(urb->dev->ep0.desc.wMaxPacketSize);
654 if (hw_max_packet_size != max_packet_size) { 987 if (hw_max_packet_size != max_packet_size) {
655 xhci_dbg(xhci, "Max Packet Size for ep 0 changed.\n"); 988 xhci_dbg(xhci, "Max Packet Size for ep 0 changed.\n");
656 xhci_dbg(xhci, "Max packet size in usb_device = %d\n", 989 xhci_dbg(xhci, "Max packet size in usb_device = %d\n",
@@ -664,15 +997,15 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
664 xhci->devs[slot_id]->out_ctx, ep_index); 997 xhci->devs[slot_id]->out_ctx, ep_index);
665 in_ctx = xhci->devs[slot_id]->in_ctx; 998 in_ctx = xhci->devs[slot_id]->in_ctx;
666 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); 999 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
667 ep_ctx->ep_info2 &= ~MAX_PACKET_MASK; 1000 ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK);
668 ep_ctx->ep_info2 |= MAX_PACKET(max_packet_size); 1001 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size));
669 1002
670 /* Set up the input context flags for the command */ 1003 /* Set up the input context flags for the command */
671 /* FIXME: This won't work if a non-default control endpoint 1004 /* FIXME: This won't work if a non-default control endpoint
672 * changes max packet sizes. 1005 * changes max packet sizes.
673 */ 1006 */
674 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); 1007 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
675 ctrl_ctx->add_flags = EP0_FLAG; 1008 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG);
676 ctrl_ctx->drop_flags = 0; 1009 ctrl_ctx->drop_flags = 0;
677 1010
678 xhci_dbg(xhci, "Slot %d input context\n", slot_id); 1011 xhci_dbg(xhci, "Slot %d input context\n", slot_id);
@@ -686,7 +1019,7 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
686 /* Clean up the input context for later use by bandwidth 1019 /* Clean up the input context for later use by bandwidth
687 * functions. 1020 * functions.
688 */ 1021 */
689 ctrl_ctx->add_flags = SLOT_FLAG; 1022 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG);
690 } 1023 }
691 return ret; 1024 return ret;
692} 1025}
@@ -704,18 +1037,13 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
704 struct urb_priv *urb_priv; 1037 struct urb_priv *urb_priv;
705 int size, i; 1038 int size, i;
706 1039
707 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0) 1040 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep,
1041 true, true, __func__) <= 0)
708 return -EINVAL; 1042 return -EINVAL;
709 1043
710 slot_id = urb->dev->slot_id; 1044 slot_id = urb->dev->slot_id;
711 ep_index = xhci_get_endpoint_index(&urb->ep->desc); 1045 ep_index = xhci_get_endpoint_index(&urb->ep->desc);
712 1046
713 if (!xhci->devs || !xhci->devs[slot_id]) {
714 if (!in_interrupt())
715 dev_warn(&urb->dev->dev, "WARN: urb submitted for dev with no Slot ID\n");
716 ret = -EINVAL;
717 goto exit;
718 }
719 if (!HCD_HW_ACCESSIBLE(hcd)) { 1047 if (!HCD_HW_ACCESSIBLE(hcd)) {
720 if (!in_interrupt()) 1048 if (!in_interrupt())
721 xhci_dbg(xhci, "urb submitted during PCI suspend\n"); 1049 xhci_dbg(xhci, "urb submitted during PCI suspend\n");
@@ -904,13 +1232,13 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
904 if (ret || !urb->hcpriv) 1232 if (ret || !urb->hcpriv)
905 goto done; 1233 goto done;
906 temp = xhci_readl(xhci, &xhci->op_regs->status); 1234 temp = xhci_readl(xhci, &xhci->op_regs->status);
907 if (temp == 0xffffffff) { 1235 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) {
908 xhci_dbg(xhci, "HW died, freeing TD.\n"); 1236 xhci_dbg(xhci, "HW died, freeing TD.\n");
909 urb_priv = urb->hcpriv; 1237 urb_priv = urb->hcpriv;
910 1238
911 usb_hcd_unlink_urb_from_ep(hcd, urb); 1239 usb_hcd_unlink_urb_from_ep(hcd, urb);
912 spin_unlock_irqrestore(&xhci->lock, flags); 1240 spin_unlock_irqrestore(&xhci->lock, flags);
913 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, -ESHUTDOWN); 1241 usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN);
914 xhci_urb_free_priv(xhci, urb_priv); 1242 xhci_urb_free_priv(xhci, urb_priv);
915 return ret; 1243 return ret;
916 } 1244 }
@@ -956,7 +1284,7 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
956 ep->stop_cmd_timer.expires = jiffies + 1284 ep->stop_cmd_timer.expires = jiffies +
957 XHCI_STOP_EP_CMD_TIMEOUT * HZ; 1285 XHCI_STOP_EP_CMD_TIMEOUT * HZ;
958 add_timer(&ep->stop_cmd_timer); 1286 add_timer(&ep->stop_cmd_timer);
959 xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index); 1287 xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index, 0);
960 xhci_ring_cmd_db(xhci); 1288 xhci_ring_cmd_db(xhci);
961 } 1289 }
962done: 1290done:
@@ -991,12 +1319,14 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
991 u32 new_add_flags, new_drop_flags, new_slot_info; 1319 u32 new_add_flags, new_drop_flags, new_slot_info;
992 int ret; 1320 int ret;
993 1321
994 ret = xhci_check_args(hcd, udev, ep, 1, __func__); 1322 ret = xhci_check_args(hcd, udev, ep, 1, true, __func__);
995 if (ret <= 0) 1323 if (ret <= 0)
996 return ret; 1324 return ret;
997 xhci = hcd_to_xhci(hcd); 1325 xhci = hcd_to_xhci(hcd);
998 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); 1326 if (xhci->xhc_state & XHCI_STATE_DYING)
1327 return -ENODEV;
999 1328
1329 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev);
1000 drop_flag = xhci_get_endpoint_flag(&ep->desc); 1330 drop_flag = xhci_get_endpoint_flag(&ep->desc);
1001 if (drop_flag == SLOT_FLAG || drop_flag == EP0_FLAG) { 1331 if (drop_flag == SLOT_FLAG || drop_flag == EP0_FLAG) {
1002 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", 1332 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n",
@@ -1004,12 +1334,6 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1004 return 0; 1334 return 0;
1005 } 1335 }
1006 1336
1007 if (!xhci->devs || !xhci->devs[udev->slot_id]) {
1008 xhci_warn(xhci, "xHCI %s called with unaddressed device\n",
1009 __func__);
1010 return -EINVAL;
1011 }
1012
1013 in_ctx = xhci->devs[udev->slot_id]->in_ctx; 1337 in_ctx = xhci->devs[udev->slot_id]->in_ctx;
1014 out_ctx = xhci->devs[udev->slot_id]->out_ctx; 1338 out_ctx = xhci->devs[udev->slot_id]->out_ctx;
1015 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); 1339 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
@@ -1018,27 +1342,30 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1018 /* If the HC already knows the endpoint is disabled, 1342 /* If the HC already knows the endpoint is disabled,
1019 * or the HCD has noted it is disabled, ignore this request 1343 * or the HCD has noted it is disabled, ignore this request
1020 */ 1344 */
1021 if ((ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED || 1345 if ((le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK) ==
1022 ctrl_ctx->drop_flags & xhci_get_endpoint_flag(&ep->desc)) { 1346 EP_STATE_DISABLED ||
1347 le32_to_cpu(ctrl_ctx->drop_flags) &
1348 xhci_get_endpoint_flag(&ep->desc)) {
1023 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", 1349 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n",
1024 __func__, ep); 1350 __func__, ep);
1025 return 0; 1351 return 0;
1026 } 1352 }
1027 1353
1028 ctrl_ctx->drop_flags |= drop_flag; 1354 ctrl_ctx->drop_flags |= cpu_to_le32(drop_flag);
1029 new_drop_flags = ctrl_ctx->drop_flags; 1355 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags);
1030 1356
1031 ctrl_ctx->add_flags &= ~drop_flag; 1357 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag);
1032 new_add_flags = ctrl_ctx->add_flags; 1358 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags);
1033 1359
1034 last_ctx = xhci_last_valid_endpoint(ctrl_ctx->add_flags); 1360 last_ctx = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags));
1035 slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); 1361 slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
1036 /* Update the last valid endpoint context, if we deleted the last one */ 1362 /* Update the last valid endpoint context, if we deleted the last one */
1037 if ((slot_ctx->dev_info & LAST_CTX_MASK) > LAST_CTX(last_ctx)) { 1363 if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) >
1038 slot_ctx->dev_info &= ~LAST_CTX_MASK; 1364 LAST_CTX(last_ctx)) {
1039 slot_ctx->dev_info |= LAST_CTX(last_ctx); 1365 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
1366 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx));
1040 } 1367 }
1041 new_slot_info = slot_ctx->dev_info; 1368 new_slot_info = le32_to_cpu(slot_ctx->dev_info);
1042 1369
1043 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); 1370 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep);
1044 1371
@@ -1076,15 +1403,18 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1076 u32 added_ctxs; 1403 u32 added_ctxs;
1077 unsigned int last_ctx; 1404 unsigned int last_ctx;
1078 u32 new_add_flags, new_drop_flags, new_slot_info; 1405 u32 new_add_flags, new_drop_flags, new_slot_info;
1406 struct xhci_virt_device *virt_dev;
1079 int ret = 0; 1407 int ret = 0;
1080 1408
1081 ret = xhci_check_args(hcd, udev, ep, 1, __func__); 1409 ret = xhci_check_args(hcd, udev, ep, 1, true, __func__);
1082 if (ret <= 0) { 1410 if (ret <= 0) {
1083 /* So we won't queue a reset ep command for a root hub */ 1411 /* So we won't queue a reset ep command for a root hub */
1084 ep->hcpriv = NULL; 1412 ep->hcpriv = NULL;
1085 return ret; 1413 return ret;
1086 } 1414 }
1087 xhci = hcd_to_xhci(hcd); 1415 xhci = hcd_to_xhci(hcd);
1416 if (xhci->xhc_state & XHCI_STATE_DYING)
1417 return -ENODEV;
1088 1418
1089 added_ctxs = xhci_get_endpoint_flag(&ep->desc); 1419 added_ctxs = xhci_get_endpoint_flag(&ep->desc);
1090 last_ctx = xhci_last_valid_endpoint(added_ctxs); 1420 last_ctx = xhci_last_valid_endpoint(added_ctxs);
@@ -1098,21 +1428,30 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1098 return 0; 1428 return 0;
1099 } 1429 }
1100 1430
1101 if (!xhci->devs || !xhci->devs[udev->slot_id]) { 1431 virt_dev = xhci->devs[udev->slot_id];
1102 xhci_warn(xhci, "xHCI %s called with unaddressed device\n", 1432 in_ctx = virt_dev->in_ctx;
1103 __func__); 1433 out_ctx = virt_dev->out_ctx;
1104 return -EINVAL;
1105 }
1106
1107 in_ctx = xhci->devs[udev->slot_id]->in_ctx;
1108 out_ctx = xhci->devs[udev->slot_id]->out_ctx;
1109 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); 1434 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1110 ep_index = xhci_get_endpoint_index(&ep->desc); 1435 ep_index = xhci_get_endpoint_index(&ep->desc);
1111 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); 1436 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
1437
1438 /* If this endpoint is already in use, and the upper layers are trying
1439 * to add it again without dropping it, reject the addition.
1440 */
1441 if (virt_dev->eps[ep_index].ring &&
1442 !(le32_to_cpu(ctrl_ctx->drop_flags) &
1443 xhci_get_endpoint_flag(&ep->desc))) {
1444 xhci_warn(xhci, "Trying to add endpoint 0x%x "
1445 "without dropping it.\n",
1446 (unsigned int) ep->desc.bEndpointAddress);
1447 return -EINVAL;
1448 }
1449
1112 /* If the HCD has already noted the endpoint is enabled, 1450 /* If the HCD has already noted the endpoint is enabled,
1113 * ignore this request. 1451 * ignore this request.
1114 */ 1452 */
1115 if (ctrl_ctx->add_flags & xhci_get_endpoint_flag(&ep->desc)) { 1453 if (le32_to_cpu(ctrl_ctx->add_flags) &
1454 xhci_get_endpoint_flag(&ep->desc)) {
1116 xhci_warn(xhci, "xHCI %s called with enabled ep %p\n", 1455 xhci_warn(xhci, "xHCI %s called with enabled ep %p\n",
1117 __func__, ep); 1456 __func__, ep);
1118 return 0; 1457 return 0;
@@ -1123,15 +1462,14 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1123 * process context, not interrupt context (or so documenation 1462 * process context, not interrupt context (or so documenation
1124 * for usb_set_interface() and usb_set_configuration() claim). 1463 * for usb_set_interface() and usb_set_configuration() claim).
1125 */ 1464 */
1126 if (xhci_endpoint_init(xhci, xhci->devs[udev->slot_id], 1465 if (xhci_endpoint_init(xhci, virt_dev, udev, ep, GFP_NOIO) < 0) {
1127 udev, ep, GFP_NOIO) < 0) {
1128 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", 1466 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n",
1129 __func__, ep->desc.bEndpointAddress); 1467 __func__, ep->desc.bEndpointAddress);
1130 return -ENOMEM; 1468 return -ENOMEM;
1131 } 1469 }
1132 1470
1133 ctrl_ctx->add_flags |= added_ctxs; 1471 ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs);
1134 new_add_flags = ctrl_ctx->add_flags; 1472 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags);
1135 1473
1136 /* If xhci_endpoint_disable() was called for this endpoint, but the 1474 /* If xhci_endpoint_disable() was called for this endpoint, but the
1137 * xHC hasn't been notified yet through the check_bandwidth() call, 1475 * xHC hasn't been notified yet through the check_bandwidth() call,
@@ -1139,15 +1477,16 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1139 * descriptors. We must drop and re-add this endpoint, so we leave the 1477 * descriptors. We must drop and re-add this endpoint, so we leave the
1140 * drop flags alone. 1478 * drop flags alone.
1141 */ 1479 */
1142 new_drop_flags = ctrl_ctx->drop_flags; 1480 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags);
1143 1481
1144 slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); 1482 slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
1145 /* Update the last valid endpoint context, if we just added one past */ 1483 /* Update the last valid endpoint context, if we just added one past */
1146 if ((slot_ctx->dev_info & LAST_CTX_MASK) < LAST_CTX(last_ctx)) { 1484 if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) <
1147 slot_ctx->dev_info &= ~LAST_CTX_MASK; 1485 LAST_CTX(last_ctx)) {
1148 slot_ctx->dev_info |= LAST_CTX(last_ctx); 1486 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
1487 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx));
1149 } 1488 }
1150 new_slot_info = slot_ctx->dev_info; 1489 new_slot_info = le32_to_cpu(slot_ctx->dev_info);
1151 1490
1152 /* Store the usb_device pointer for later use */ 1491 /* Store the usb_device pointer for later use */
1153 ep->hcpriv = udev; 1492 ep->hcpriv = udev;
@@ -1177,9 +1516,9 @@ static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *vir
1177 ctrl_ctx->drop_flags = 0; 1516 ctrl_ctx->drop_flags = 0;
1178 ctrl_ctx->add_flags = 0; 1517 ctrl_ctx->add_flags = 0;
1179 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); 1518 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
1180 slot_ctx->dev_info &= ~LAST_CTX_MASK; 1519 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
1181 /* Endpoint 0 is always valid */ 1520 /* Endpoint 0 is always valid */
1182 slot_ctx->dev_info |= LAST_CTX(1); 1521 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1));
1183 for (i = 1; i < 31; ++i) { 1522 for (i = 1; i < 31; ++i) {
1184 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); 1523 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i);
1185 ep_ctx->ep_info = 0; 1524 ep_ctx->ep_info = 0;
@@ -1190,7 +1529,7 @@ static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *vir
1190} 1529}
1191 1530
1192static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, 1531static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
1193 struct usb_device *udev, int *cmd_status) 1532 struct usb_device *udev, u32 *cmd_status)
1194{ 1533{
1195 int ret; 1534 int ret;
1196 1535
@@ -1214,6 +1553,11 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
1214 "and endpoint is not disabled.\n"); 1553 "and endpoint is not disabled.\n");
1215 ret = -EINVAL; 1554 ret = -EINVAL;
1216 break; 1555 break;
1556 case COMP_DEV_ERR:
1557 dev_warn(&udev->dev, "ERROR: Incompatible device for endpoint "
1558 "configure command.\n");
1559 ret = -ENODEV;
1560 break;
1217 case COMP_SUCCESS: 1561 case COMP_SUCCESS:
1218 dev_dbg(&udev->dev, "Successful Endpoint Configure command\n"); 1562 dev_dbg(&udev->dev, "Successful Endpoint Configure command\n");
1219 ret = 0; 1563 ret = 0;
@@ -1228,7 +1572,7 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
1228} 1572}
1229 1573
1230static int xhci_evaluate_context_result(struct xhci_hcd *xhci, 1574static int xhci_evaluate_context_result(struct xhci_hcd *xhci,
1231 struct usb_device *udev, int *cmd_status) 1575 struct usb_device *udev, u32 *cmd_status)
1232{ 1576{
1233 int ret; 1577 int ret;
1234 struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id]; 1578 struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id];
@@ -1248,6 +1592,16 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci,
1248 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1); 1592 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1);
1249 ret = -EINVAL; 1593 ret = -EINVAL;
1250 break; 1594 break;
1595 case COMP_DEV_ERR:
1596 dev_warn(&udev->dev, "ERROR: Incompatible device for evaluate "
1597 "context command.\n");
1598 ret = -ENODEV;
1599 break;
1600 case COMP_MEL_ERR:
1601 /* Max Exit Latency too large error */
1602 dev_warn(&udev->dev, "WARN: Max Exit Latency too large\n");
1603 ret = -EINVAL;
1604 break;
1251 case COMP_SUCCESS: 1605 case COMP_SUCCESS:
1252 dev_dbg(&udev->dev, "Successful evaluate context command\n"); 1606 dev_dbg(&udev->dev, "Successful evaluate context command\n");
1253 ret = 0; 1607 ret = 0;
@@ -1261,6 +1615,113 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci,
1261 return ret; 1615 return ret;
1262} 1616}
1263 1617
1618static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci,
1619 struct xhci_container_ctx *in_ctx)
1620{
1621 struct xhci_input_control_ctx *ctrl_ctx;
1622 u32 valid_add_flags;
1623 u32 valid_drop_flags;
1624
1625 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1626 /* Ignore the slot flag (bit 0), and the default control endpoint flag
1627 * (bit 1). The default control endpoint is added during the Address
1628 * Device command and is never removed until the slot is disabled.
1629 */
1630 valid_add_flags = ctrl_ctx->add_flags >> 2;
1631 valid_drop_flags = ctrl_ctx->drop_flags >> 2;
1632
1633 /* Use hweight32 to count the number of ones in the add flags, or
1634 * number of endpoints added. Don't count endpoints that are changed
1635 * (both added and dropped).
1636 */
1637 return hweight32(valid_add_flags) -
1638 hweight32(valid_add_flags & valid_drop_flags);
1639}
1640
1641static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci,
1642 struct xhci_container_ctx *in_ctx)
1643{
1644 struct xhci_input_control_ctx *ctrl_ctx;
1645 u32 valid_add_flags;
1646 u32 valid_drop_flags;
1647
1648 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1649 valid_add_flags = ctrl_ctx->add_flags >> 2;
1650 valid_drop_flags = ctrl_ctx->drop_flags >> 2;
1651
1652 return hweight32(valid_drop_flags) -
1653 hweight32(valid_add_flags & valid_drop_flags);
1654}
1655
1656/*
1657 * We need to reserve the new number of endpoints before the configure endpoint
1658 * command completes. We can't subtract the dropped endpoints from the number
1659 * of active endpoints until the command completes because we can oversubscribe
1660 * the host in this case:
1661 *
1662 * - the first configure endpoint command drops more endpoints than it adds
1663 * - a second configure endpoint command that adds more endpoints is queued
1664 * - the first configure endpoint command fails, so the config is unchanged
1665 * - the second command may succeed, even though there isn't enough resources
1666 *
1667 * Must be called with xhci->lock held.
1668 */
1669static int xhci_reserve_host_resources(struct xhci_hcd *xhci,
1670 struct xhci_container_ctx *in_ctx)
1671{
1672 u32 added_eps;
1673
1674 added_eps = xhci_count_num_new_endpoints(xhci, in_ctx);
1675 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) {
1676 xhci_dbg(xhci, "Not enough ep ctxs: "
1677 "%u active, need to add %u, limit is %u.\n",
1678 xhci->num_active_eps, added_eps,
1679 xhci->limit_active_eps);
1680 return -ENOMEM;
1681 }
1682 xhci->num_active_eps += added_eps;
1683 xhci_dbg(xhci, "Adding %u ep ctxs, %u now active.\n", added_eps,
1684 xhci->num_active_eps);
1685 return 0;
1686}
1687
1688/*
1689 * The configure endpoint was failed by the xHC for some other reason, so we
1690 * need to revert the resources that failed configuration would have used.
1691 *
1692 * Must be called with xhci->lock held.
1693 */
1694static void xhci_free_host_resources(struct xhci_hcd *xhci,
1695 struct xhci_container_ctx *in_ctx)
1696{
1697 u32 num_failed_eps;
1698
1699 num_failed_eps = xhci_count_num_new_endpoints(xhci, in_ctx);
1700 xhci->num_active_eps -= num_failed_eps;
1701 xhci_dbg(xhci, "Removing %u failed ep ctxs, %u now active.\n",
1702 num_failed_eps,
1703 xhci->num_active_eps);
1704}
1705
1706/*
1707 * Now that the command has completed, clean up the active endpoint count by
1708 * subtracting out the endpoints that were dropped (but not changed).
1709 *
1710 * Must be called with xhci->lock held.
1711 */
1712static void xhci_finish_resource_reservation(struct xhci_hcd *xhci,
1713 struct xhci_container_ctx *in_ctx)
1714{
1715 u32 num_dropped_eps;
1716
1717 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, in_ctx);
1718 xhci->num_active_eps -= num_dropped_eps;
1719 if (num_dropped_eps)
1720 xhci_dbg(xhci, "Removing %u dropped ep ctxs, %u now active.\n",
1721 num_dropped_eps,
1722 xhci->num_active_eps);
1723}
1724
1264/* Issue a configure endpoint command or evaluate context command 1725/* Issue a configure endpoint command or evaluate context command
1265 * and wait for it to finish. 1726 * and wait for it to finish.
1266 */ 1727 */
@@ -1274,19 +1735,45 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1274 unsigned long flags; 1735 unsigned long flags;
1275 struct xhci_container_ctx *in_ctx; 1736 struct xhci_container_ctx *in_ctx;
1276 struct completion *cmd_completion; 1737 struct completion *cmd_completion;
1277 int *cmd_status; 1738 u32 *cmd_status;
1278 struct xhci_virt_device *virt_dev; 1739 struct xhci_virt_device *virt_dev;
1279 1740
1280 spin_lock_irqsave(&xhci->lock, flags); 1741 spin_lock_irqsave(&xhci->lock, flags);
1281 virt_dev = xhci->devs[udev->slot_id]; 1742 virt_dev = xhci->devs[udev->slot_id];
1282 if (command) { 1743 if (command) {
1283 in_ctx = command->in_ctx; 1744 in_ctx = command->in_ctx;
1745 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) &&
1746 xhci_reserve_host_resources(xhci, in_ctx)) {
1747 spin_unlock_irqrestore(&xhci->lock, flags);
1748 xhci_warn(xhci, "Not enough host resources, "
1749 "active endpoint contexts = %u\n",
1750 xhci->num_active_eps);
1751 return -ENOMEM;
1752 }
1753
1284 cmd_completion = command->completion; 1754 cmd_completion = command->completion;
1285 cmd_status = &command->status; 1755 cmd_status = &command->status;
1286 command->command_trb = xhci->cmd_ring->enqueue; 1756 command->command_trb = xhci->cmd_ring->enqueue;
1757
1758 /* Enqueue pointer can be left pointing to the link TRB,
1759 * we must handle that
1760 */
1761 if ((le32_to_cpu(command->command_trb->link.control)
1762 & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
1763 command->command_trb =
1764 xhci->cmd_ring->enq_seg->next->trbs;
1765
1287 list_add_tail(&command->cmd_list, &virt_dev->cmd_list); 1766 list_add_tail(&command->cmd_list, &virt_dev->cmd_list);
1288 } else { 1767 } else {
1289 in_ctx = virt_dev->in_ctx; 1768 in_ctx = virt_dev->in_ctx;
1769 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) &&
1770 xhci_reserve_host_resources(xhci, in_ctx)) {
1771 spin_unlock_irqrestore(&xhci->lock, flags);
1772 xhci_warn(xhci, "Not enough host resources, "
1773 "active endpoint contexts = %u\n",
1774 xhci->num_active_eps);
1775 return -ENOMEM;
1776 }
1290 cmd_completion = &virt_dev->cmd_completion; 1777 cmd_completion = &virt_dev->cmd_completion;
1291 cmd_status = &virt_dev->cmd_status; 1778 cmd_status = &virt_dev->cmd_status;
1292 } 1779 }
@@ -1301,6 +1788,8 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1301 if (ret < 0) { 1788 if (ret < 0) {
1302 if (command) 1789 if (command)
1303 list_del(&command->cmd_list); 1790 list_del(&command->cmd_list);
1791 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK))
1792 xhci_free_host_resources(xhci, in_ctx);
1304 spin_unlock_irqrestore(&xhci->lock, flags); 1793 spin_unlock_irqrestore(&xhci->lock, flags);
1305 xhci_dbg(xhci, "FIXME allocate a new ring segment\n"); 1794 xhci_dbg(xhci, "FIXME allocate a new ring segment\n");
1306 return -ENOMEM; 1795 return -ENOMEM;
@@ -1323,8 +1812,22 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1323 } 1812 }
1324 1813
1325 if (!ctx_change) 1814 if (!ctx_change)
1326 return xhci_configure_endpoint_result(xhci, udev, cmd_status); 1815 ret = xhci_configure_endpoint_result(xhci, udev, cmd_status);
1327 return xhci_evaluate_context_result(xhci, udev, cmd_status); 1816 else
1817 ret = xhci_evaluate_context_result(xhci, udev, cmd_status);
1818
1819 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) {
1820 spin_lock_irqsave(&xhci->lock, flags);
1821 /* If the command failed, remove the reserved resources.
1822 * Otherwise, clean up the estimate to include dropped eps.
1823 */
1824 if (ret)
1825 xhci_free_host_resources(xhci, in_ctx);
1826 else
1827 xhci_finish_resource_reservation(xhci, in_ctx);
1828 spin_unlock_irqrestore(&xhci->lock, flags);
1829 }
1830 return ret;
1328} 1831}
1329 1832
1330/* Called after one or more calls to xhci_add_endpoint() or 1833/* Called after one or more calls to xhci_add_endpoint() or
@@ -1346,29 +1849,25 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1346 struct xhci_input_control_ctx *ctrl_ctx; 1849 struct xhci_input_control_ctx *ctrl_ctx;
1347 struct xhci_slot_ctx *slot_ctx; 1850 struct xhci_slot_ctx *slot_ctx;
1348 1851
1349 ret = xhci_check_args(hcd, udev, NULL, 0, __func__); 1852 ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__);
1350 if (ret <= 0) 1853 if (ret <= 0)
1351 return ret; 1854 return ret;
1352 xhci = hcd_to_xhci(hcd); 1855 xhci = hcd_to_xhci(hcd);
1856 if (xhci->xhc_state & XHCI_STATE_DYING)
1857 return -ENODEV;
1353 1858
1354 if (!udev->slot_id || !xhci->devs || !xhci->devs[udev->slot_id]) {
1355 xhci_warn(xhci, "xHCI %s called with unaddressed device\n",
1356 __func__);
1357 return -EINVAL;
1358 }
1359 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); 1859 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev);
1360 virt_dev = xhci->devs[udev->slot_id]; 1860 virt_dev = xhci->devs[udev->slot_id];
1361 1861
1362 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ 1862 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */
1363 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); 1863 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
1364 ctrl_ctx->add_flags |= SLOT_FLAG; 1864 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
1365 ctrl_ctx->add_flags &= ~EP0_FLAG; 1865 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG);
1366 ctrl_ctx->drop_flags &= ~SLOT_FLAG; 1866 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG));
1367 ctrl_ctx->drop_flags &= ~EP0_FLAG;
1368 xhci_dbg(xhci, "New Input Control Context:\n"); 1867 xhci_dbg(xhci, "New Input Control Context:\n");
1369 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); 1868 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
1370 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 1869 xhci_dbg_ctx(xhci, virt_dev->in_ctx,
1371 LAST_CTX_TO_EP_NUM(slot_ctx->dev_info)); 1870 LAST_CTX_TO_EP_NUM(le32_to_cpu(slot_ctx->dev_info)));
1372 1871
1373 ret = xhci_configure_endpoint(xhci, udev, NULL, 1872 ret = xhci_configure_endpoint(xhci, udev, NULL,
1374 false, false); 1873 false, false);
@@ -1379,10 +1878,19 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1379 1878
1380 xhci_dbg(xhci, "Output context after successful config ep cmd:\n"); 1879 xhci_dbg(xhci, "Output context after successful config ep cmd:\n");
1381 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1880 xhci_dbg_ctx(xhci, virt_dev->out_ctx,
1382 LAST_CTX_TO_EP_NUM(slot_ctx->dev_info)); 1881 LAST_CTX_TO_EP_NUM(le32_to_cpu(slot_ctx->dev_info)));
1383 1882
1883 /* Free any rings that were dropped, but not changed. */
1884 for (i = 1; i < 31; ++i) {
1885 if ((le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1))) &&
1886 !(le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1))))
1887 xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i);
1888 }
1384 xhci_zero_in_ctx(xhci, virt_dev); 1889 xhci_zero_in_ctx(xhci, virt_dev);
1385 /* Install new rings and free or cache any old rings */ 1890 /*
1891 * Install any rings for completely new endpoints or changed endpoints,
1892 * and free or cache any old rings from changed endpoints.
1893 */
1386 for (i = 1; i < 31; ++i) { 1894 for (i = 1; i < 31; ++i) {
1387 if (!virt_dev->eps[i].new_ring) 1895 if (!virt_dev->eps[i].new_ring)
1388 continue; 1896 continue;
@@ -1405,16 +1913,11 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1405 struct xhci_virt_device *virt_dev; 1913 struct xhci_virt_device *virt_dev;
1406 int i, ret; 1914 int i, ret;
1407 1915
1408 ret = xhci_check_args(hcd, udev, NULL, 0, __func__); 1916 ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__);
1409 if (ret <= 0) 1917 if (ret <= 0)
1410 return; 1918 return;
1411 xhci = hcd_to_xhci(hcd); 1919 xhci = hcd_to_xhci(hcd);
1412 1920
1413 if (!xhci->devs || !xhci->devs[udev->slot_id]) {
1414 xhci_warn(xhci, "xHCI %s called with unaddressed device\n",
1415 __func__);
1416 return;
1417 }
1418 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); 1921 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev);
1419 virt_dev = xhci->devs[udev->slot_id]; 1922 virt_dev = xhci->devs[udev->slot_id];
1420 /* Free any rings allocated for added endpoints */ 1923 /* Free any rings allocated for added endpoints */
@@ -1434,16 +1937,16 @@ static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci,
1434{ 1937{
1435 struct xhci_input_control_ctx *ctrl_ctx; 1938 struct xhci_input_control_ctx *ctrl_ctx;
1436 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); 1939 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1437 ctrl_ctx->add_flags = add_flags; 1940 ctrl_ctx->add_flags = cpu_to_le32(add_flags);
1438 ctrl_ctx->drop_flags = drop_flags; 1941 ctrl_ctx->drop_flags = cpu_to_le32(drop_flags);
1439 xhci_slot_copy(xhci, in_ctx, out_ctx); 1942 xhci_slot_copy(xhci, in_ctx, out_ctx);
1440 ctrl_ctx->add_flags |= SLOT_FLAG; 1943 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
1441 1944
1442 xhci_dbg(xhci, "Input Context:\n"); 1945 xhci_dbg(xhci, "Input Context:\n");
1443 xhci_dbg_ctx(xhci, in_ctx, xhci_last_valid_endpoint(add_flags)); 1946 xhci_dbg_ctx(xhci, in_ctx, xhci_last_valid_endpoint(add_flags));
1444} 1947}
1445 1948
1446void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci, 1949static void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci,
1447 unsigned int slot_id, unsigned int ep_index, 1950 unsigned int slot_id, unsigned int ep_index,
1448 struct xhci_dequeue_state *deq_state) 1951 struct xhci_dequeue_state *deq_state)
1449{ 1952{
@@ -1466,7 +1969,7 @@ void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci,
1466 deq_state->new_deq_ptr); 1969 deq_state->new_deq_ptr);
1467 return; 1970 return;
1468 } 1971 }
1469 ep_ctx->deq = addr | deq_state->new_cycle_state; 1972 ep_ctx->deq = cpu_to_le64(addr | deq_state->new_cycle_state);
1470 1973
1471 added_ctxs = xhci_get_endpoint_flag_from_index(ep_index); 1974 added_ctxs = xhci_get_endpoint_flag_from_index(ep_index);
1472 xhci_setup_input_ctx_for_config_ep(xhci, xhci->devs[slot_id]->in_ctx, 1975 xhci_setup_input_ctx_for_config_ep(xhci, xhci->devs[slot_id]->in_ctx,
@@ -1575,7 +2078,7 @@ static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,
1575 2078
1576 if (!ep) 2079 if (!ep)
1577 return -EINVAL; 2080 return -EINVAL;
1578 ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, __func__); 2081 ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, true, __func__);
1579 if (ret <= 0) 2082 if (ret <= 0)
1580 return -EINVAL; 2083 return -EINVAL;
1581 if (ep->ss_ep_comp.bmAttributes == 0) { 2084 if (ep->ss_ep_comp.bmAttributes == 0) {
@@ -1771,7 +2274,7 @@ int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
1771 return -EINVAL; 2274 return -EINVAL;
1772 } 2275 }
1773 vdev = xhci->devs[udev->slot_id]; 2276 vdev = xhci->devs[udev->slot_id];
1774 /* Mark each endpoint as being in transistion, so 2277 /* Mark each endpoint as being in transition, so
1775 * xhci_urb_enqueue() will reject all URBs. 2278 * xhci_urb_enqueue() will reject all URBs.
1776 */ 2279 */
1777 for (i = 0; i < num_eps; i++) { 2280 for (i = 0; i < num_eps; i++) {
@@ -1942,6 +2445,34 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
1942} 2445}
1943 2446
1944/* 2447/*
2448 * Deletes endpoint resources for endpoints that were active before a Reset
2449 * Device command, or a Disable Slot command. The Reset Device command leaves
2450 * the control endpoint intact, whereas the Disable Slot command deletes it.
2451 *
2452 * Must be called with xhci->lock held.
2453 */
2454void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci,
2455 struct xhci_virt_device *virt_dev, bool drop_control_ep)
2456{
2457 int i;
2458 unsigned int num_dropped_eps = 0;
2459 unsigned int drop_flags = 0;
2460
2461 for (i = (drop_control_ep ? 0 : 1); i < 31; i++) {
2462 if (virt_dev->eps[i].ring) {
2463 drop_flags |= 1 << i;
2464 num_dropped_eps++;
2465 }
2466 }
2467 xhci->num_active_eps -= num_dropped_eps;
2468 if (num_dropped_eps)
2469 xhci_dbg(xhci, "Dropped %u ep ctxs, flags = 0x%x, "
2470 "%u now active.\n",
2471 num_dropped_eps, drop_flags,
2472 xhci->num_active_eps);
2473}
2474
2475/*
1945 * This submits a Reset Device Command, which will set the device state to 0, 2476 * This submits a Reset Device Command, which will set the device state to 0,
1946 * set the device address to 0, and disable all the endpoints except the default 2477 * set the device address to 0, and disable all the endpoints except the default
1947 * control endpoint. The USB core should come back and call 2478 * control endpoint. The USB core should come back and call
@@ -1953,8 +2484,13 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
1953 * Wait for the Reset Device command to finish. Remove all structures 2484 * Wait for the Reset Device command to finish. Remove all structures
1954 * associated with the endpoints that were disabled. Clear the input device 2485 * associated with the endpoints that were disabled. Clear the input device
1955 * structure? Cache the rings? Reset the control endpoint 0 max packet size? 2486 * structure? Cache the rings? Reset the control endpoint 0 max packet size?
2487 *
2488 * If the virt_dev to be reset does not exist or does not match the udev,
2489 * it means the device is lost, possibly due to the xHC restore error and
2490 * re-initialization during S3/S4. In this case, call xhci_alloc_dev() to
2491 * re-allocate the device.
1956 */ 2492 */
1957int xhci_reset_device(struct usb_hcd *hcd, struct usb_device *udev) 2493int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
1958{ 2494{
1959 int ret, i; 2495 int ret, i;
1960 unsigned long flags; 2496 unsigned long flags;
@@ -1964,19 +2500,45 @@ int xhci_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
1964 struct xhci_command *reset_device_cmd; 2500 struct xhci_command *reset_device_cmd;
1965 int timeleft; 2501 int timeleft;
1966 int last_freed_endpoint; 2502 int last_freed_endpoint;
2503 struct xhci_slot_ctx *slot_ctx;
1967 2504
1968 ret = xhci_check_args(hcd, udev, NULL, 0, __func__); 2505 ret = xhci_check_args(hcd, udev, NULL, 0, false, __func__);
1969 if (ret <= 0) 2506 if (ret <= 0)
1970 return ret; 2507 return ret;
1971 xhci = hcd_to_xhci(hcd); 2508 xhci = hcd_to_xhci(hcd);
1972 slot_id = udev->slot_id; 2509 slot_id = udev->slot_id;
1973 virt_dev = xhci->devs[slot_id]; 2510 virt_dev = xhci->devs[slot_id];
1974 if (!virt_dev) { 2511 if (!virt_dev) {
1975 xhci_dbg(xhci, "%s called with invalid slot ID %u\n", 2512 xhci_dbg(xhci, "The device to be reset with slot ID %u does "
1976 __func__, slot_id); 2513 "not exist. Re-allocate the device\n", slot_id);
1977 return -EINVAL; 2514 ret = xhci_alloc_dev(hcd, udev);
2515 if (ret == 1)
2516 return 0;
2517 else
2518 return -EINVAL;
1978 } 2519 }
1979 2520
2521 if (virt_dev->udev != udev) {
2522 /* If the virt_dev and the udev does not match, this virt_dev
2523 * may belong to another udev.
2524 * Re-allocate the device.
2525 */
2526 xhci_dbg(xhci, "The device to be reset with slot ID %u does "
2527 "not match the udev. Re-allocate the device\n",
2528 slot_id);
2529 ret = xhci_alloc_dev(hcd, udev);
2530 if (ret == 1)
2531 return 0;
2532 else
2533 return -EINVAL;
2534 }
2535
2536 /* If device is not setup, there is no point in resetting it */
2537 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx);
2538 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) ==
2539 SLOT_STATE_DISABLED)
2540 return 0;
2541
1980 xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id); 2542 xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id);
1981 /* Allocate the command structure that holds the struct completion. 2543 /* Allocate the command structure that holds the struct completion.
1982 * Assume we're in process context, since the normal device reset 2544 * Assume we're in process context, since the normal device reset
@@ -1993,6 +2555,15 @@ int xhci_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
1993 /* Attempt to submit the Reset Device command to the command ring */ 2555 /* Attempt to submit the Reset Device command to the command ring */
1994 spin_lock_irqsave(&xhci->lock, flags); 2556 spin_lock_irqsave(&xhci->lock, flags);
1995 reset_device_cmd->command_trb = xhci->cmd_ring->enqueue; 2557 reset_device_cmd->command_trb = xhci->cmd_ring->enqueue;
2558
2559 /* Enqueue pointer can be left pointing to the link TRB,
2560 * we must handle that
2561 */
2562 if ((le32_to_cpu(reset_device_cmd->command_trb->link.control)
2563 & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
2564 reset_device_cmd->command_trb =
2565 xhci->cmd_ring->enq_seg->next->trbs;
2566
1996 list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list); 2567 list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list);
1997 ret = xhci_queue_reset_device(xhci, slot_id); 2568 ret = xhci_queue_reset_device(xhci, slot_id);
1998 if (ret) { 2569 if (ret) {
@@ -2049,13 +2620,29 @@ int xhci_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
2049 goto command_cleanup; 2620 goto command_cleanup;
2050 } 2621 }
2051 2622
2623 /* Free up host controller endpoint resources */
2624 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) {
2625 spin_lock_irqsave(&xhci->lock, flags);
2626 /* Don't delete the default control endpoint resources */
2627 xhci_free_device_endpoint_resources(xhci, virt_dev, false);
2628 spin_unlock_irqrestore(&xhci->lock, flags);
2629 }
2630
2052 /* Everything but endpoint 0 is disabled, so free or cache the rings. */ 2631 /* Everything but endpoint 0 is disabled, so free or cache the rings. */
2053 last_freed_endpoint = 1; 2632 last_freed_endpoint = 1;
2054 for (i = 1; i < 31; ++i) { 2633 for (i = 1; i < 31; ++i) {
2055 if (!virt_dev->eps[i].ring) 2634 struct xhci_virt_ep *ep = &virt_dev->eps[i];
2056 continue; 2635
2057 xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i); 2636 if (ep->ep_state & EP_HAS_STREAMS) {
2058 last_freed_endpoint = i; 2637 xhci_free_stream_info(xhci, ep->stream_info);
2638 ep->stream_info = NULL;
2639 ep->ep_state &= ~EP_HAS_STREAMS;
2640 }
2641
2642 if (ep->ring) {
2643 xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i);
2644 last_freed_endpoint = i;
2645 }
2059 } 2646 }
2060 xhci_dbg(xhci, "Output context after successful reset device cmd:\n"); 2647 xhci_dbg(xhci, "Output context after successful reset device cmd:\n");
2061 xhci_dbg_ctx(xhci, virt_dev->out_ctx, last_freed_endpoint); 2648 xhci_dbg_ctx(xhci, virt_dev->out_ctx, last_freed_endpoint);
@@ -2077,13 +2664,13 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
2077 struct xhci_virt_device *virt_dev; 2664 struct xhci_virt_device *virt_dev;
2078 unsigned long flags; 2665 unsigned long flags;
2079 u32 state; 2666 u32 state;
2080 int i; 2667 int i, ret;
2081 2668
2082 if (udev->slot_id == 0) 2669 ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__);
2670 if (ret <= 0)
2083 return; 2671 return;
2672
2084 virt_dev = xhci->devs[udev->slot_id]; 2673 virt_dev = xhci->devs[udev->slot_id];
2085 if (!virt_dev)
2086 return;
2087 2674
2088 /* Stop any wayward timer functions (which may grab the lock) */ 2675 /* Stop any wayward timer functions (which may grab the lock) */
2089 for (i = 0; i < 31; ++i) { 2676 for (i = 0; i < 31; ++i) {
@@ -2114,6 +2701,27 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
2114} 2701}
2115 2702
2116/* 2703/*
2704 * Checks if we have enough host controller resources for the default control
2705 * endpoint.
2706 *
2707 * Must be called with xhci->lock held.
2708 */
2709static int xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci)
2710{
2711 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) {
2712 xhci_dbg(xhci, "Not enough ep ctxs: "
2713 "%u active, need to add 1, limit is %u.\n",
2714 xhci->num_active_eps, xhci->limit_active_eps);
2715 return -ENOMEM;
2716 }
2717 xhci->num_active_eps += 1;
2718 xhci_dbg(xhci, "Adding 1 ep ctx, %u now active.\n",
2719 xhci->num_active_eps);
2720 return 0;
2721}
2722
2723
2724/*
2117 * Returns 0 if the xHC ran out of device slots, the Enable Slot command 2725 * Returns 0 if the xHC ran out of device slots, the Enable Slot command
2118 * timed out, or allocating memory failed. Returns 1 on success. 2726 * timed out, or allocating memory failed. Returns 1 on success.
2119 */ 2727 */
@@ -2148,20 +2756,39 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
2148 xhci_err(xhci, "Error while assigning device slot ID\n"); 2756 xhci_err(xhci, "Error while assigning device slot ID\n");
2149 return 0; 2757 return 0;
2150 } 2758 }
2151 /* xhci_alloc_virt_device() does not touch rings; no need to lock */ 2759
2152 if (!xhci_alloc_virt_device(xhci, xhci->slot_id, udev, GFP_KERNEL)) { 2760 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) {
2153 /* Disable slot, if we can do it without mem alloc */
2154 xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n");
2155 spin_lock_irqsave(&xhci->lock, flags); 2761 spin_lock_irqsave(&xhci->lock, flags);
2156 if (!xhci_queue_slot_control(xhci, TRB_DISABLE_SLOT, udev->slot_id)) 2762 ret = xhci_reserve_host_control_ep_resources(xhci);
2157 xhci_ring_cmd_db(xhci); 2763 if (ret) {
2764 spin_unlock_irqrestore(&xhci->lock, flags);
2765 xhci_warn(xhci, "Not enough host resources, "
2766 "active endpoint contexts = %u\n",
2767 xhci->num_active_eps);
2768 goto disable_slot;
2769 }
2158 spin_unlock_irqrestore(&xhci->lock, flags); 2770 spin_unlock_irqrestore(&xhci->lock, flags);
2159 return 0; 2771 }
2772 /* Use GFP_NOIO, since this function can be called from
2773 * xhci_discover_or_reset_device(), which may be called as part of
2774 * mass storage driver error handling.
2775 */
2776 if (!xhci_alloc_virt_device(xhci, xhci->slot_id, udev, GFP_NOIO)) {
2777 xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n");
2778 goto disable_slot;
2160 } 2779 }
2161 udev->slot_id = xhci->slot_id; 2780 udev->slot_id = xhci->slot_id;
2162 /* Is this a LS or FS device under a HS hub? */ 2781 /* Is this a LS or FS device under a HS hub? */
2163 /* Hub or peripherial? */ 2782 /* Hub or peripherial? */
2164 return 1; 2783 return 1;
2784
2785disable_slot:
2786 /* Disable slot, if we can do it without mem alloc */
2787 spin_lock_irqsave(&xhci->lock, flags);
2788 if (!xhci_queue_slot_control(xhci, TRB_DISABLE_SLOT, udev->slot_id))
2789 xhci_ring_cmd_db(xhci);
2790 spin_unlock_irqrestore(&xhci->lock, flags);
2791 return 0;
2165} 2792}
2166 2793
2167/* 2794/*
@@ -2191,12 +2818,28 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
2191 2818
2192 virt_dev = xhci->devs[udev->slot_id]; 2819 virt_dev = xhci->devs[udev->slot_id];
2193 2820
2194 /* If this is a Set Address to an unconfigured device, setup ep 0 */ 2821 if (WARN_ON(!virt_dev)) {
2195 if (!udev->config) 2822 /*
2823 * In plug/unplug torture test with an NEC controller,
2824 * a zero-dereference was observed once due to virt_dev = 0.
2825 * Print useful debug rather than crash if it is observed again!
2826 */
2827 xhci_warn(xhci, "Virt dev invalid for slot_id 0x%x!\n",
2828 udev->slot_id);
2829 return -EINVAL;
2830 }
2831
2832 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
2833 /*
2834 * If this is the first Set Address since device plug-in or
2835 * virt_device realloaction after a resume with an xHCI power loss,
2836 * then set up the slot context.
2837 */
2838 if (!slot_ctx->dev_info)
2196 xhci_setup_addressable_virt_dev(xhci, udev); 2839 xhci_setup_addressable_virt_dev(xhci, udev);
2840 /* Otherwise, update the control endpoint ring enqueue pointer. */
2197 else 2841 else
2198 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); 2842 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev);
2199 /* Otherwise, assume the core has the device configured how it wants */
2200 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); 2843 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id);
2201 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); 2844 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2);
2202 2845
@@ -2236,6 +2879,11 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
2236 dev_warn(&udev->dev, "Device not responding to set address.\n"); 2879 dev_warn(&udev->dev, "Device not responding to set address.\n");
2237 ret = -EPROTO; 2880 ret = -EPROTO;
2238 break; 2881 break;
2882 case COMP_DEV_ERR:
2883 dev_warn(&udev->dev, "ERROR: Incompatible device for address "
2884 "device command.\n");
2885 ret = -ENODEV;
2886 break;
2239 case COMP_SUCCESS: 2887 case COMP_SUCCESS:
2240 xhci_dbg(xhci, "Successful Address Device command\n"); 2888 xhci_dbg(xhci, "Successful Address Device command\n");
2241 break; 2889 break;
@@ -2253,10 +2901,10 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
2253 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); 2901 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
2254 xhci_dbg(xhci, "Op regs DCBAA ptr = %#016llx\n", temp_64); 2902 xhci_dbg(xhci, "Op regs DCBAA ptr = %#016llx\n", temp_64);
2255 xhci_dbg(xhci, "Slot ID %d dcbaa entry @%p = %#016llx\n", 2903 xhci_dbg(xhci, "Slot ID %d dcbaa entry @%p = %#016llx\n",
2256 udev->slot_id, 2904 udev->slot_id,
2257 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], 2905 &xhci->dcbaa->dev_context_ptrs[udev->slot_id],
2258 (unsigned long long) 2906 (unsigned long long)
2259 xhci->dcbaa->dev_context_ptrs[udev->slot_id]); 2907 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id]));
2260 xhci_dbg(xhci, "Output Context DMA address = %#08llx\n", 2908 xhci_dbg(xhci, "Output Context DMA address = %#08llx\n",
2261 (unsigned long long)virt_dev->out_ctx->dma); 2909 (unsigned long long)virt_dev->out_ctx->dma);
2262 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); 2910 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id);
@@ -2268,15 +2916,16 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
2268 * address given back to us by the HC. 2916 * address given back to us by the HC.
2269 */ 2917 */
2270 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); 2918 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx);
2271 udev->devnum = (slot_ctx->dev_state & DEV_ADDR_MASK) + 1; 2919 /* Use kernel assigned address for devices; store xHC assigned
2920 * address locally. */
2921 virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK)
2922 + 1;
2272 /* Zero the input context control for later use */ 2923 /* Zero the input context control for later use */
2273 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); 2924 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
2274 ctrl_ctx->add_flags = 0; 2925 ctrl_ctx->add_flags = 0;
2275 ctrl_ctx->drop_flags = 0; 2926 ctrl_ctx->drop_flags = 0;
2276 2927
2277 xhci_dbg(xhci, "Device address = %d\n", udev->devnum); 2928 xhci_dbg(xhci, "Internal device address = %d\n", virt_dev->address);
2278 /* XXX Meh, not sure if anyone else but choose_address uses this. */
2279 set_bit(udev->devnum, udev->bus->devmap.devicemap);
2280 2929
2281 return 0; 2930 return 0;
2282} 2931}
@@ -2314,24 +2963,29 @@ int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
2314 spin_lock_irqsave(&xhci->lock, flags); 2963 spin_lock_irqsave(&xhci->lock, flags);
2315 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); 2964 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx);
2316 ctrl_ctx = xhci_get_input_control_ctx(xhci, config_cmd->in_ctx); 2965 ctrl_ctx = xhci_get_input_control_ctx(xhci, config_cmd->in_ctx);
2317 ctrl_ctx->add_flags |= SLOT_FLAG; 2966 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
2318 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); 2967 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx);
2319 slot_ctx->dev_info |= DEV_HUB; 2968 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB);
2320 if (tt->multi) 2969 if (tt->multi)
2321 slot_ctx->dev_info |= DEV_MTT; 2970 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT);
2322 if (xhci->hci_version > 0x95) { 2971 if (xhci->hci_version > 0x95) {
2323 xhci_dbg(xhci, "xHCI version %x needs hub " 2972 xhci_dbg(xhci, "xHCI version %x needs hub "
2324 "TT think time and number of ports\n", 2973 "TT think time and number of ports\n",
2325 (unsigned int) xhci->hci_version); 2974 (unsigned int) xhci->hci_version);
2326 slot_ctx->dev_info2 |= XHCI_MAX_PORTS(hdev->maxchild); 2975 slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(hdev->maxchild));
2327 /* Set TT think time - convert from ns to FS bit times. 2976 /* Set TT think time - convert from ns to FS bit times.
2328 * 0 = 8 FS bit times, 1 = 16 FS bit times, 2977 * 0 = 8 FS bit times, 1 = 16 FS bit times,
2329 * 2 = 24 FS bit times, 3 = 32 FS bit times. 2978 * 2 = 24 FS bit times, 3 = 32 FS bit times.
2979 *
2980 * xHCI 1.0: this field shall be 0 if the device is not a
2981 * High-spped hub.
2330 */ 2982 */
2331 think_time = tt->think_time; 2983 think_time = tt->think_time;
2332 if (think_time != 0) 2984 if (think_time != 0)
2333 think_time = (think_time / 666) - 1; 2985 think_time = (think_time / 666) - 1;
2334 slot_ctx->tt_info |= TT_THINK_TIME(think_time); 2986 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH)
2987 slot_ctx->tt_info |=
2988 cpu_to_le32(TT_THINK_TIME(think_time));
2335 } else { 2989 } else {
2336 xhci_dbg(xhci, "xHCI version %x doesn't need hub " 2990 xhci_dbg(xhci, "xHCI version %x doesn't need hub "
2337 "TT think time or number of ports\n", 2991 "TT think time or number of ports\n",
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 34a60d9f056a..d8bbf5ccb10d 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -30,6 +30,7 @@
30 30
31/* Code sharing between pci-quirks and xhci hcd */ 31/* Code sharing between pci-quirks and xhci hcd */
32#include "xhci-ext-caps.h" 32#include "xhci-ext-caps.h"
33#include "pci-quirks.h"
33 34
34/* xHCI PCI Configuration Registers */ 35/* xHCI PCI Configuration Registers */
35#define XHCI_SBRN_OFFSET (0x60) 36#define XHCI_SBRN_OFFSET (0x60)
@@ -56,13 +57,13 @@
56 * @run_regs_off: RTSOFF - Runtime register space offset 57 * @run_regs_off: RTSOFF - Runtime register space offset
57 */ 58 */
58struct xhci_cap_regs { 59struct xhci_cap_regs {
59 u32 hc_capbase; 60 __le32 hc_capbase;
60 u32 hcs_params1; 61 __le32 hcs_params1;
61 u32 hcs_params2; 62 __le32 hcs_params2;
62 u32 hcs_params3; 63 __le32 hcs_params3;
63 u32 hcc_params; 64 __le32 hcc_params;
64 u32 db_off; 65 __le32 db_off;
65 u32 run_regs_off; 66 __le32 run_regs_off;
66 /* Reserved up to (CAPLENGTH - 0x1C) */ 67 /* Reserved up to (CAPLENGTH - 0x1C) */
67}; 68};
68 69
@@ -154,26 +155,26 @@ struct xhci_cap_regs {
154 * devices. 155 * devices.
155 */ 156 */
156struct xhci_op_regs { 157struct xhci_op_regs {
157 u32 command; 158 __le32 command;
158 u32 status; 159 __le32 status;
159 u32 page_size; 160 __le32 page_size;
160 u32 reserved1; 161 __le32 reserved1;
161 u32 reserved2; 162 __le32 reserved2;
162 u32 dev_notification; 163 __le32 dev_notification;
163 u64 cmd_ring; 164 __le64 cmd_ring;
164 /* rsvd: offset 0x20-2F */ 165 /* rsvd: offset 0x20-2F */
165 u32 reserved3[4]; 166 __le32 reserved3[4];
166 u64 dcbaa_ptr; 167 __le64 dcbaa_ptr;
167 u32 config_reg; 168 __le32 config_reg;
168 /* rsvd: offset 0x3C-3FF */ 169 /* rsvd: offset 0x3C-3FF */
169 u32 reserved4[241]; 170 __le32 reserved4[241];
170 /* port 1 registers, which serve as a base address for other ports */ 171 /* port 1 registers, which serve as a base address for other ports */
171 u32 port_status_base; 172 __le32 port_status_base;
172 u32 port_power_base; 173 __le32 port_power_base;
173 u32 port_link_base; 174 __le32 port_link_base;
174 u32 reserved5; 175 __le32 reserved5;
175 /* registers for ports 2-255 */ 176 /* registers for ports 2-255 */
176 u32 reserved6[NUM_PORT_REGS*254]; 177 __le32 reserved6[NUM_PORT_REGS*254];
177}; 178};
178 179
179/* USBCMD - USB command - command bitmasks */ 180/* USBCMD - USB command - command bitmasks */
@@ -191,7 +192,7 @@ struct xhci_op_regs {
191/* bits 4:6 are reserved (and should be preserved on writes). */ 192/* bits 4:6 are reserved (and should be preserved on writes). */
192/* light reset (port status stays unchanged) - reset completed when this is 0 */ 193/* light reset (port status stays unchanged) - reset completed when this is 0 */
193#define CMD_LRESET (1 << 7) 194#define CMD_LRESET (1 << 7)
194/* FIXME: ignoring host controller save/restore state for now. */ 195/* host controller save/restore state. */
195#define CMD_CSS (1 << 8) 196#define CMD_CSS (1 << 8)
196#define CMD_CRS (1 << 9) 197#define CMD_CRS (1 << 9)
197/* Enable Wrap Event - '1' means xHC generates an event when MFINDEX wraps. */ 198/* Enable Wrap Event - '1' means xHC generates an event when MFINDEX wraps. */
@@ -232,7 +233,7 @@ struct xhci_op_regs {
232 * notification type that matches a bit set in this bit field. 233 * notification type that matches a bit set in this bit field.
233 */ 234 */
234#define DEV_NOTE_MASK (0xffff) 235#define DEV_NOTE_MASK (0xffff)
235#define ENABLE_DEV_NOTE(x) (1 << x) 236#define ENABLE_DEV_NOTE(x) (1 << (x))
236/* Most of the device notification types should only be used for debug. 237/* Most of the device notification types should only be used for debug.
237 * SW does need to pay attention to function wake notifications. 238 * SW does need to pay attention to function wake notifications.
238 */ 239 */
@@ -269,6 +270,10 @@ struct xhci_op_regs {
269 * A read gives the current link PM state of the port, 270 * A read gives the current link PM state of the port,
270 * a write with Link State Write Strobe set sets the link state. 271 * a write with Link State Write Strobe set sets the link state.
271 */ 272 */
273#define PORT_PLS_MASK (0xf << 5)
274#define XDEV_U0 (0x0 << 5)
275#define XDEV_U3 (0x3 << 5)
276#define XDEV_RESUME (0xf << 5)
272/* true: port has power (see HCC_PPC) */ 277/* true: port has power (see HCC_PPC) */
273#define PORT_POWER (1 << 9) 278#define PORT_POWER (1 << 9)
274/* bits 10:13 indicate device speed: 279/* bits 10:13 indicate device speed:
@@ -344,6 +349,9 @@ struct xhci_op_regs {
344/* Initiate a warm port reset - complete when PORT_WRC is '1' */ 349/* Initiate a warm port reset - complete when PORT_WRC is '1' */
345#define PORT_WR (1 << 31) 350#define PORT_WR (1 << 31)
346 351
352/* We mark duplicate entries with -1 */
353#define DUPLICATE_ENTRY ((u8)(-1))
354
347/* Port Power Management Status and Control - port_power_base bitmasks */ 355/* Port Power Management Status and Control - port_power_base bitmasks */
348/* Inactivity timer value for transitions into U1, in microseconds. 356/* Inactivity timer value for transitions into U1, in microseconds.
349 * Timeout can be up to 127us. 0xFF means an infinite timeout. 357 * Timeout can be up to 127us. 0xFF means an infinite timeout.
@@ -353,6 +361,8 @@ struct xhci_op_regs {
353#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8) 361#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
354/* Bits 24:31 for port testing */ 362/* Bits 24:31 for port testing */
355 363
364/* USB2 Protocol PORTSPMSC */
365#define PORT_RWE (1 << 0x3)
356 366
357/** 367/**
358 * struct xhci_intr_reg - Interrupt Register Set 368 * struct xhci_intr_reg - Interrupt Register Set
@@ -372,12 +382,12 @@ struct xhci_op_regs {
372 * updates the dequeue pointer. 382 * updates the dequeue pointer.
373 */ 383 */
374struct xhci_intr_reg { 384struct xhci_intr_reg {
375 u32 irq_pending; 385 __le32 irq_pending;
376 u32 irq_control; 386 __le32 irq_control;
377 u32 erst_size; 387 __le32 erst_size;
378 u32 rsvd; 388 __le32 rsvd;
379 u64 erst_base; 389 __le64 erst_base;
380 u64 erst_dequeue; 390 __le64 erst_dequeue;
381}; 391};
382 392
383/* irq_pending bitmasks */ 393/* irq_pending bitmasks */
@@ -422,30 +432,44 @@ struct xhci_intr_reg {
422 * or larger accesses" 432 * or larger accesses"
423 */ 433 */
424struct xhci_run_regs { 434struct xhci_run_regs {
425 u32 microframe_index; 435 __le32 microframe_index;
426 u32 rsvd[7]; 436 __le32 rsvd[7];
427 struct xhci_intr_reg ir_set[128]; 437 struct xhci_intr_reg ir_set[128];
428}; 438};
429 439
430/** 440/**
431 * struct doorbell_array 441 * struct doorbell_array
432 * 442 *
443 * Bits 0 - 7: Endpoint target
444 * Bits 8 - 15: RsvdZ
445 * Bits 16 - 31: Stream ID
446 *
433 * Section 5.6 447 * Section 5.6
434 */ 448 */
435struct xhci_doorbell_array { 449struct xhci_doorbell_array {
436 u32 doorbell[256]; 450 __le32 doorbell[256];
437}; 451};
438 452
439#define DB_TARGET_MASK 0xFFFFFF00 453#define DB_VALUE(ep, stream) ((((ep) + 1) & 0xff) | ((stream) << 16))
440#define DB_STREAM_ID_MASK 0x0000FFFF 454#define DB_VALUE_HOST 0x00000000
441#define DB_TARGET_HOST 0x0
442#define DB_STREAM_ID_HOST 0x0
443#define DB_MASK (0xff << 8)
444 455
445/* Endpoint Target - bits 0:7 */ 456/**
446#define EPI_TO_DB(p) (((p) + 1) & 0xff) 457 * struct xhci_protocol_caps
447#define STREAM_ID_TO_DB(p) (((p) & 0xffff) << 16) 458 * @revision: major revision, minor revision, capability ID,
459 * and next capability pointer.
460 * @name_string: Four ASCII characters to say which spec this xHC
461 * follows, typically "USB ".
462 * @port_info: Port offset, count, and protocol-defined information.
463 */
464struct xhci_protocol_caps {
465 u32 revision;
466 u32 name_string;
467 u32 port_info;
468};
448 469
470#define XHCI_EXT_PORT_MAJOR(x) (((x) >> 24) & 0xff)
471#define XHCI_EXT_PORT_OFF(x) ((x) & 0xff)
472#define XHCI_EXT_PORT_COUNT(x) (((x) >> 8) & 0xff)
449 473
450/** 474/**
451 * struct xhci_container_ctx 475 * struct xhci_container_ctx
@@ -480,12 +504,12 @@ struct xhci_container_ctx {
480 * reserved at the end of the slot context for HC internal use. 504 * reserved at the end of the slot context for HC internal use.
481 */ 505 */
482struct xhci_slot_ctx { 506struct xhci_slot_ctx {
483 u32 dev_info; 507 __le32 dev_info;
484 u32 dev_info2; 508 __le32 dev_info2;
485 u32 tt_info; 509 __le32 tt_info;
486 u32 dev_state; 510 __le32 dev_state;
487 /* offset 0x10 to 0x1f reserved for HC internal use */ 511 /* offset 0x10 to 0x1f reserved for HC internal use */
488 u32 reserved[4]; 512 __le32 reserved[4];
489}; 513};
490 514
491/* dev_info bitmasks */ 515/* dev_info bitmasks */
@@ -510,6 +534,7 @@ struct xhci_slot_ctx {
510#define MAX_EXIT (0xffff) 534#define MAX_EXIT (0xffff)
511/* Root hub port number that is needed to access the USB device */ 535/* Root hub port number that is needed to access the USB device */
512#define ROOT_HUB_PORT(p) (((p) & 0xff) << 16) 536#define ROOT_HUB_PORT(p) (((p) & 0xff) << 16)
537#define DEVINFO_TO_ROOT_HUB_PORT(p) (((p) >> 16) & 0xff)
513/* Maximum number of ports under a hub device */ 538/* Maximum number of ports under a hub device */
514#define XHCI_MAX_PORTS(p) (((p) & 0xff) << 24) 539#define XHCI_MAX_PORTS(p) (((p) & 0xff) << 24)
515 540
@@ -535,6 +560,11 @@ struct xhci_slot_ctx {
535#define SLOT_STATE (0x1f << 27) 560#define SLOT_STATE (0x1f << 27)
536#define GET_SLOT_STATE(p) (((p) & (0x1f << 27)) >> 27) 561#define GET_SLOT_STATE(p) (((p) & (0x1f << 27)) >> 27)
537 562
563#define SLOT_STATE_DISABLED 0
564#define SLOT_STATE_ENABLED SLOT_STATE_DISABLED
565#define SLOT_STATE_DEFAULT 1
566#define SLOT_STATE_ADDRESSED 2
567#define SLOT_STATE_CONFIGURED 3
538 568
539/** 569/**
540 * struct xhci_ep_ctx 570 * struct xhci_ep_ctx
@@ -555,12 +585,12 @@ struct xhci_slot_ctx {
555 * reserved at the end of the endpoint context for HC internal use. 585 * reserved at the end of the endpoint context for HC internal use.
556 */ 586 */
557struct xhci_ep_ctx { 587struct xhci_ep_ctx {
558 u32 ep_info; 588 __le32 ep_info;
559 u32 ep_info2; 589 __le32 ep_info2;
560 u64 deq; 590 __le64 deq;
561 u32 tx_info; 591 __le32 tx_info;
562 /* offset 0x14 - 0x1f reserved for HC internal use */ 592 /* offset 0x14 - 0x1f reserved for HC internal use */
563 u32 reserved[3]; 593 __le32 reserved[3];
564}; 594};
565 595
566/* ep_info bitmasks */ 596/* ep_info bitmasks */
@@ -580,11 +610,11 @@ struct xhci_ep_ctx {
580#define EP_STATE_STOPPED 3 610#define EP_STATE_STOPPED 3
581#define EP_STATE_ERROR 4 611#define EP_STATE_ERROR 4
582/* Mult - Max number of burtst within an interval, in EP companion desc. */ 612/* Mult - Max number of burtst within an interval, in EP companion desc. */
583#define EP_MULT(p) ((p & 0x3) << 8) 613#define EP_MULT(p) (((p) & 0x3) << 8)
584/* bits 10:14 are Max Primary Streams */ 614/* bits 10:14 are Max Primary Streams */
585/* bit 15 is Linear Stream Array */ 615/* bit 15 is Linear Stream Array */
586/* Interval - period between requests to an endpoint - 125u increments. */ 616/* Interval - period between requests to an endpoint - 125u increments. */
587#define EP_INTERVAL(p) ((p & 0xff) << 16) 617#define EP_INTERVAL(p) (((p) & 0xff) << 16)
588#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff)) 618#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
589#define EP_MAXPSTREAMS_MASK (0x1f << 10) 619#define EP_MAXPSTREAMS_MASK (0x1f << 10)
590#define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK) 620#define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK)
@@ -614,10 +644,18 @@ struct xhci_ep_ctx {
614#define MAX_PACKET_MASK (0xffff << 16) 644#define MAX_PACKET_MASK (0xffff << 16)
615#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff) 645#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
616 646
647/* Get max packet size from ep desc. Bit 10..0 specify the max packet size.
648 * USB2.0 spec 9.6.6.
649 */
650#define GET_MAX_PACKET(p) ((p) & 0x7ff)
651
617/* tx_info bitmasks */ 652/* tx_info bitmasks */
618#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff) 653#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff)
619#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16) 654#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16)
620 655
656/* deq bitmasks */
657#define EP_CTX_CYCLE_MASK (1 << 0)
658
621 659
622/** 660/**
623 * struct xhci_input_control_context 661 * struct xhci_input_control_context
@@ -627,9 +665,9 @@ struct xhci_ep_ctx {
627 * @add_context: set the bit of the endpoint context you want to enable 665 * @add_context: set the bit of the endpoint context you want to enable
628 */ 666 */
629struct xhci_input_control_ctx { 667struct xhci_input_control_ctx {
630 u32 drop_flags; 668 __le32 drop_flags;
631 u32 add_flags; 669 __le32 add_flags;
632 u32 rsvd2[6]; 670 __le32 rsvd2[6];
633}; 671};
634 672
635/* Represents everything that is needed to issue a command on the command ring. 673/* Represents everything that is needed to issue a command on the command ring.
@@ -655,9 +693,9 @@ struct xhci_command {
655 693
656struct xhci_stream_ctx { 694struct xhci_stream_ctx {
657 /* 64-bit stream ring address, cycle state, and stream type */ 695 /* 64-bit stream ring address, cycle state, and stream type */
658 u64 stream_ring; 696 __le64 stream_ring;
659 /* offset 0x14 - 0x1f reserved for HC internal use */ 697 /* offset 0x14 - 0x1f reserved for HC internal use */
660 u32 reserved[2]; 698 __le32 reserved[2];
661}; 699};
662 700
663/* Stream Context Types (section 6.4.1) - bits 3:1 of stream ctx deq ptr */ 701/* Stream Context Types (section 6.4.1) - bits 3:1 of stream ctx deq ptr */
@@ -720,6 +758,12 @@ struct xhci_virt_ep {
720 struct timer_list stop_cmd_timer; 758 struct timer_list stop_cmd_timer;
721 int stop_cmds_pending; 759 int stop_cmds_pending;
722 struct xhci_hcd *xhci; 760 struct xhci_hcd *xhci;
761 /* Dequeue pointer and dequeue segment for a submitted Set TR Dequeue
762 * command. We'll need to update the ring's dequeue segment and dequeue
763 * pointer after the command completes.
764 */
765 struct xhci_segment *queued_deq_seg;
766 union xhci_trb *queued_deq_ptr;
723 /* 767 /*
724 * Sometimes the xHC can not process isochronous endpoint ring quickly 768 * Sometimes the xHC can not process isochronous endpoint ring quickly
725 * enough, and it will miss some isoc tds on the ring and generate 769 * enough, and it will miss some isoc tds on the ring and generate
@@ -731,6 +775,7 @@ struct xhci_virt_ep {
731}; 775};
732 776
733struct xhci_virt_device { 777struct xhci_virt_device {
778 struct usb_device *udev;
734 /* 779 /*
735 * Commands to the hardware are passed an "input context" that 780 * Commands to the hardware are passed an "input context" that
736 * tells the hardware what to change in its data structures. 781 * tells the hardware what to change in its data structures.
@@ -745,12 +790,15 @@ struct xhci_virt_device {
745 /* Rings saved to ensure old alt settings can be re-instated */ 790 /* Rings saved to ensure old alt settings can be re-instated */
746 struct xhci_ring **ring_cache; 791 struct xhci_ring **ring_cache;
747 int num_rings_cached; 792 int num_rings_cached;
793 /* Store xHC assigned device address */
794 int address;
748#define XHCI_MAX_RINGS_CACHED 31 795#define XHCI_MAX_RINGS_CACHED 31
749 struct xhci_virt_ep eps[31]; 796 struct xhci_virt_ep eps[31];
750 struct completion cmd_completion; 797 struct completion cmd_completion;
751 /* Status of the last command issued for this device */ 798 /* Status of the last command issued for this device */
752 u32 cmd_status; 799 u32 cmd_status;
753 struct list_head cmd_list; 800 struct list_head cmd_list;
801 u8 port;
754}; 802};
755 803
756 804
@@ -760,7 +808,7 @@ struct xhci_virt_device {
760 */ 808 */
761struct xhci_device_context_array { 809struct xhci_device_context_array {
762 /* 64-bit device addresses; we only write 32-bit addresses */ 810 /* 64-bit device addresses; we only write 32-bit addresses */
763 u64 dev_context_ptrs[MAX_HC_SLOTS]; 811 __le64 dev_context_ptrs[MAX_HC_SLOTS];
764 /* private xHCD pointers */ 812 /* private xHCD pointers */
765 dma_addr_t dma; 813 dma_addr_t dma;
766}; 814};
@@ -773,10 +821,10 @@ struct xhci_device_context_array {
773 821
774struct xhci_transfer_event { 822struct xhci_transfer_event {
775 /* 64-bit buffer address, or immediate data */ 823 /* 64-bit buffer address, or immediate data */
776 u64 buffer; 824 __le64 buffer;
777 u32 transfer_len; 825 __le32 transfer_len;
778 /* This field is interpreted differently based on the type of TRB */ 826 /* This field is interpreted differently based on the type of TRB */
779 u32 flags; 827 __le32 flags;
780}; 828};
781 829
782/** Transfer Event bit fields **/ 830/** Transfer Event bit fields **/
@@ -826,6 +874,8 @@ struct xhci_transfer_event {
826#define COMP_PING_ERR 20 874#define COMP_PING_ERR 20
827/* Event Ring is full */ 875/* Event Ring is full */
828#define COMP_ER_FULL 21 876#define COMP_ER_FULL 21
877/* Incompatible Device Error */
878#define COMP_DEV_ERR 22
829/* Missed Service Error - HC couldn't service an isoc ep within interval */ 879/* Missed Service Error - HC couldn't service an isoc ep within interval */
830#define COMP_MISSED_INT 23 880#define COMP_MISSED_INT 23
831/* Successfully stopped command ring */ 881/* Successfully stopped command ring */
@@ -834,11 +884,13 @@ struct xhci_transfer_event {
834#define COMP_CMD_ABORT 25 884#define COMP_CMD_ABORT 25
835/* Stopped - transfer was terminated by a stop endpoint command */ 885/* Stopped - transfer was terminated by a stop endpoint command */
836#define COMP_STOP 26 886#define COMP_STOP 26
837/* Same as COMP_EP_STOPPED, but the transfered length in the event is invalid */ 887/* Same as COMP_EP_STOPPED, but the transferred length in the event is invalid */
838#define COMP_STOP_INVAL 27 888#define COMP_STOP_INVAL 27
839/* Control Abort Error - Debug Capability - control pipe aborted */ 889/* Control Abort Error - Debug Capability - control pipe aborted */
840#define COMP_DBG_ABORT 28 890#define COMP_DBG_ABORT 28
841/* TRB type 29 and 30 reserved */ 891/* Max Exit Latency Too Large Error */
892#define COMP_MEL_ERR 29
893/* TRB type 30 reserved */
842/* Isoc Buffer Overrun - an isoc IN ep sent more data than could fit in TD */ 894/* Isoc Buffer Overrun - an isoc IN ep sent more data than could fit in TD */
843#define COMP_BUFF_OVER 31 895#define COMP_BUFF_OVER 31
844/* Event Lost Error - xHC has an "internal event overrun condition" */ 896/* Event Lost Error - xHC has an "internal event overrun condition" */
@@ -855,9 +907,9 @@ struct xhci_transfer_event {
855 907
856struct xhci_link_trb { 908struct xhci_link_trb {
857 /* 64-bit segment pointer*/ 909 /* 64-bit segment pointer*/
858 u64 segment_ptr; 910 __le64 segment_ptr;
859 u32 intr_target; 911 __le32 intr_target;
860 u32 control; 912 __le32 control;
861}; 913};
862 914
863/* control bitfields */ 915/* control bitfields */
@@ -866,9 +918,9 @@ struct xhci_link_trb {
866/* Command completion event TRB */ 918/* Command completion event TRB */
867struct xhci_event_cmd { 919struct xhci_event_cmd {
868 /* Pointer to command TRB, or the value passed by the event data trb */ 920 /* Pointer to command TRB, or the value passed by the event data trb */
869 u64 cmd_trb; 921 __le64 cmd_trb;
870 u32 status; 922 __le32 status;
871 u32 flags; 923 __le32 flags;
872}; 924};
873 925
874/* flags bitmasks */ 926/* flags bitmasks */
@@ -881,6 +933,10 @@ struct xhci_event_cmd {
881#define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1) 933#define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1)
882#define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16) 934#define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
883 935
936#define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23)
937#define TRB_TO_SUSPEND_PORT(p) (((p) & (1 << 23)) >> 23)
938#define LAST_EP_INDEX 30
939
884/* Set TR Dequeue Pointer command TRB fields */ 940/* Set TR Dequeue Pointer command TRB fields */
885#define TRB_TO_STREAM_ID(p) ((((p) & (0xffff << 16)) >> 16)) 941#define TRB_TO_STREAM_ID(p) ((((p) & (0xffff << 16)) >> 16))
886#define STREAM_ID_FOR_TRB(p) ((((p)) & 0xffff) << 16) 942#define STREAM_ID_FOR_TRB(p) ((((p)) & 0xffff) << 16)
@@ -896,6 +952,8 @@ struct xhci_event_cmd {
896/* Interrupter Target - which MSI-X vector to target the completion event at */ 952/* Interrupter Target - which MSI-X vector to target the completion event at */
897#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22) 953#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
898#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff) 954#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
955#define TRB_TBC(p) (((p) & 0x3) << 7)
956#define TRB_TLBPC(p) (((p) & 0xf) << 16)
899 957
900/* Cycle bit - indicates TRB ownership by HC or HCD */ 958/* Cycle bit - indicates TRB ownership by HC or HCD */
901#define TRB_CYCLE (1<<0) 959#define TRB_CYCLE (1<<0)
@@ -915,15 +973,20 @@ struct xhci_event_cmd {
915/* The buffer pointer contains immediate data */ 973/* The buffer pointer contains immediate data */
916#define TRB_IDT (1<<6) 974#define TRB_IDT (1<<6)
917 975
976/* Block Event Interrupt */
977#define TRB_BEI (1<<9)
918 978
919/* Control transfer TRB specific fields */ 979/* Control transfer TRB specific fields */
920#define TRB_DIR_IN (1<<16) 980#define TRB_DIR_IN (1<<16)
981#define TRB_TX_TYPE(p) ((p) << 16)
982#define TRB_DATA_OUT 2
983#define TRB_DATA_IN 3
921 984
922/* Isochronous TRB specific fields */ 985/* Isochronous TRB specific fields */
923#define TRB_SIA (1<<31) 986#define TRB_SIA (1<<31)
924 987
925struct xhci_generic_trb { 988struct xhci_generic_trb {
926 u32 field[4]; 989 __le32 field[4];
927}; 990};
928 991
929union xhci_trb { 992union xhci_trb {
@@ -1067,14 +1130,15 @@ struct xhci_ring {
1067 */ 1130 */
1068 u32 cycle_state; 1131 u32 cycle_state;
1069 unsigned int stream_id; 1132 unsigned int stream_id;
1133 bool last_td_was_short;
1070}; 1134};
1071 1135
1072struct xhci_erst_entry { 1136struct xhci_erst_entry {
1073 /* 64-bit event ring segment address */ 1137 /* 64-bit event ring segment address */
1074 u64 seg_addr; 1138 __le64 seg_addr;
1075 u32 seg_size; 1139 __le32 seg_size;
1076 /* Set to zero */ 1140 /* Set to zero */
1077 u32 rsvd; 1141 __le32 rsvd;
1078}; 1142};
1079 1143
1080struct xhci_erst { 1144struct xhci_erst {
@@ -1115,9 +1179,41 @@ struct urb_priv {
1115#define XHCI_STOP_EP_CMD_TIMEOUT 5 1179#define XHCI_STOP_EP_CMD_TIMEOUT 5
1116/* XXX: Make these module parameters */ 1180/* XXX: Make these module parameters */
1117 1181
1182struct s3_save {
1183 u32 command;
1184 u32 dev_nt;
1185 u64 dcbaa_ptr;
1186 u32 config_reg;
1187 u32 irq_pending;
1188 u32 irq_control;
1189 u32 erst_size;
1190 u64 erst_base;
1191 u64 erst_dequeue;
1192};
1193
1194struct xhci_bus_state {
1195 unsigned long bus_suspended;
1196 unsigned long next_statechange;
1197
1198 /* Port suspend arrays are indexed by the portnum of the fake roothub */
1199 /* ports suspend status arrays - max 31 ports for USB2, 15 for USB3 */
1200 u32 port_c_suspend;
1201 u32 suspended_ports;
1202 unsigned long resume_done[USB_MAXCHILDREN];
1203};
1204
1205static inline unsigned int hcd_index(struct usb_hcd *hcd)
1206{
1207 if (hcd->speed == HCD_USB3)
1208 return 0;
1209 else
1210 return 1;
1211}
1118 1212
1119/* There is one ehci_hci structure per controller */ 1213/* There is one ehci_hci structure per controller */
1120struct xhci_hcd { 1214struct xhci_hcd {
1215 struct usb_hcd *main_hcd;
1216 struct usb_hcd *shared_hcd;
1121 /* glue to PCI and HCD framework */ 1217 /* glue to PCI and HCD framework */
1122 struct xhci_cap_regs __iomem *cap_regs; 1218 struct xhci_cap_regs __iomem *cap_regs;
1123 struct xhci_op_regs __iomem *op_regs; 1219 struct xhci_op_regs __iomem *op_regs;
@@ -1178,6 +1274,9 @@ struct xhci_hcd {
1178#endif 1274#endif
1179 /* Host controller watchdog timer structures */ 1275 /* Host controller watchdog timer structures */
1180 unsigned int xhc_state; 1276 unsigned int xhc_state;
1277
1278 u32 command;
1279 struct s3_save s3;
1181/* Host controller is dying - not responding to commands. "I'm not dead yet!" 1280/* Host controller is dying - not responding to commands. "I'm not dead yet!"
1182 * 1281 *
1183 * xHC interrupts have been disabled and a watchdog timer will (or has already) 1282 * xHC interrupts have been disabled and a watchdog timer will (or has already)
@@ -1191,28 +1290,50 @@ struct xhci_hcd {
1191 * There are no reports of xHCI host controllers that display this issue. 1290 * There are no reports of xHCI host controllers that display this issue.
1192 */ 1291 */
1193#define XHCI_STATE_DYING (1 << 0) 1292#define XHCI_STATE_DYING (1 << 0)
1293#define XHCI_STATE_HALTED (1 << 1)
1194 /* Statistics */ 1294 /* Statistics */
1195 int noops_submitted;
1196 int noops_handled;
1197 int error_bitmask; 1295 int error_bitmask;
1198 unsigned int quirks; 1296 unsigned int quirks;
1199#define XHCI_LINK_TRB_QUIRK (1 << 0) 1297#define XHCI_LINK_TRB_QUIRK (1 << 0)
1200#define XHCI_RESET_EP_QUIRK (1 << 1) 1298#define XHCI_RESET_EP_QUIRK (1 << 1)
1201#define XHCI_NEC_HOST (1 << 2) 1299#define XHCI_NEC_HOST (1 << 2)
1300#define XHCI_AMD_PLL_FIX (1 << 3)
1301#define XHCI_SPURIOUS_SUCCESS (1 << 4)
1302/*
1303 * Certain Intel host controllers have a limit to the number of endpoint
1304 * contexts they can handle. Ideally, they would signal that they can't handle
1305 * anymore endpoint contexts by returning a Resource Error for the Configure
1306 * Endpoint command, but they don't. Instead they expect software to keep track
1307 * of the number of active endpoints for them, across configure endpoint
1308 * commands, reset device commands, disable slot commands, and address device
1309 * commands.
1310 */
1311#define XHCI_EP_LIMIT_QUIRK (1 << 5)
1312#define XHCI_BROKEN_MSI (1 << 6)
1313#define XHCI_RESET_ON_RESUME (1 << 7)
1314 unsigned int num_active_eps;
1315 unsigned int limit_active_eps;
1316 /* There are two roothubs to keep track of bus suspend info for */
1317 struct xhci_bus_state bus_state[2];
1318 /* Is each xHCI roothub port a USB 3.0, USB 2.0, or USB 1.1 port? */
1319 u8 *port_array;
1320 /* Array of pointers to USB 3.0 PORTSC registers */
1321 __le32 __iomem **usb3_ports;
1322 unsigned int num_usb3_ports;
1323 /* Array of pointers to USB 2.0 PORTSC registers */
1324 __le32 __iomem **usb2_ports;
1325 unsigned int num_usb2_ports;
1202}; 1326};
1203 1327
1204/* For testing purposes */
1205#define NUM_TEST_NOOPS 0
1206
1207/* convert between an HCD pointer and the corresponding EHCI_HCD */ 1328/* convert between an HCD pointer and the corresponding EHCI_HCD */
1208static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd) 1329static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd)
1209{ 1330{
1210 return (struct xhci_hcd *) (hcd->hcd_priv); 1331 return *((struct xhci_hcd **) (hcd->hcd_priv));
1211} 1332}
1212 1333
1213static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci) 1334static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1214{ 1335{
1215 return container_of((void *) xhci, struct usb_hcd, hcd_priv); 1336 return xhci->main_hcd;
1216} 1337}
1217 1338
1218#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 1339#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
@@ -1233,16 +1354,13 @@ static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1233/* TODO: copied from ehci.h - can be refactored? */ 1354/* TODO: copied from ehci.h - can be refactored? */
1234/* xHCI spec says all registers are little endian */ 1355/* xHCI spec says all registers are little endian */
1235static inline unsigned int xhci_readl(const struct xhci_hcd *xhci, 1356static inline unsigned int xhci_readl(const struct xhci_hcd *xhci,
1236 __u32 __iomem *regs) 1357 __le32 __iomem *regs)
1237{ 1358{
1238 return readl(regs); 1359 return readl(regs);
1239} 1360}
1240static inline void xhci_writel(struct xhci_hcd *xhci, 1361static inline void xhci_writel(struct xhci_hcd *xhci,
1241 const unsigned int val, __u32 __iomem *regs) 1362 const unsigned int val, __le32 __iomem *regs)
1242{ 1363{
1243 xhci_dbg(xhci,
1244 "`MEM_WRITE_DWORD(3'b000, 32'h%p, 32'h%0x, 4'hf);\n",
1245 regs, val);
1246 writel(val, regs); 1364 writel(val, regs);
1247} 1365}
1248 1366
@@ -1256,7 +1374,7 @@ static inline void xhci_writel(struct xhci_hcd *xhci,
1256 * the high dword, and write order is irrelevant. 1374 * the high dword, and write order is irrelevant.
1257 */ 1375 */
1258static inline u64 xhci_read_64(const struct xhci_hcd *xhci, 1376static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
1259 __u64 __iomem *regs) 1377 __le64 __iomem *regs)
1260{ 1378{
1261 __u32 __iomem *ptr = (__u32 __iomem *) regs; 1379 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1262 u64 val_lo = readl(ptr); 1380 u64 val_lo = readl(ptr);
@@ -1264,15 +1382,12 @@ static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
1264 return val_lo + (val_hi << 32); 1382 return val_lo + (val_hi << 32);
1265} 1383}
1266static inline void xhci_write_64(struct xhci_hcd *xhci, 1384static inline void xhci_write_64(struct xhci_hcd *xhci,
1267 const u64 val, __u64 __iomem *regs) 1385 const u64 val, __le64 __iomem *regs)
1268{ 1386{
1269 __u32 __iomem *ptr = (__u32 __iomem *) regs; 1387 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1270 u32 val_lo = lower_32_bits(val); 1388 u32 val_lo = lower_32_bits(val);
1271 u32 val_hi = upper_32_bits(val); 1389 u32 val_hi = upper_32_bits(val);
1272 1390
1273 xhci_dbg(xhci,
1274 "`MEM_WRITE_DWORD(3'b000, 64'h%p, 64'h%0lx, 4'hf);\n",
1275 regs, (long unsigned int) val);
1276 writel(val_lo, ptr); 1391 writel(val_lo, ptr);
1277 writel(val_hi, ptr + 1); 1392 writel(val_hi, ptr + 1);
1278} 1393}
@@ -1285,7 +1400,7 @@ static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
1285} 1400}
1286 1401
1287/* xHCI debugging */ 1402/* xHCI debugging */
1288void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num); 1403void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num);
1289void xhci_print_registers(struct xhci_hcd *xhci); 1404void xhci_print_registers(struct xhci_hcd *xhci);
1290void xhci_dbg_regs(struct xhci_hcd *xhci); 1405void xhci_dbg_regs(struct xhci_hcd *xhci);
1291void xhci_print_run_regs(struct xhci_hcd *xhci); 1406void xhci_print_run_regs(struct xhci_hcd *xhci);
@@ -1341,6 +1456,8 @@ void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
1341void xhci_setup_no_streams_ep_input_ctx(struct xhci_hcd *xhci, 1456void xhci_setup_no_streams_ep_input_ctx(struct xhci_hcd *xhci,
1342 struct xhci_ep_ctx *ep_ctx, 1457 struct xhci_ep_ctx *ep_ctx,
1343 struct xhci_virt_ep *ep); 1458 struct xhci_virt_ep *ep);
1459void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci,
1460 struct xhci_virt_device *virt_dev, bool drop_control_ep);
1344struct xhci_ring *xhci_dma_to_transfer_ring( 1461struct xhci_ring *xhci_dma_to_transfer_ring(
1345 struct xhci_virt_ep *ep, 1462 struct xhci_virt_ep *ep,
1346 u64 address); 1463 u64 address);
@@ -1369,6 +1486,15 @@ int xhci_init(struct usb_hcd *hcd);
1369int xhci_run(struct usb_hcd *hcd); 1486int xhci_run(struct usb_hcd *hcd);
1370void xhci_stop(struct usb_hcd *hcd); 1487void xhci_stop(struct usb_hcd *hcd);
1371void xhci_shutdown(struct usb_hcd *hcd); 1488void xhci_shutdown(struct usb_hcd *hcd);
1489
1490#ifdef CONFIG_PM
1491int xhci_suspend(struct xhci_hcd *xhci);
1492int xhci_resume(struct xhci_hcd *xhci, bool hibernated);
1493#else
1494#define xhci_suspend NULL
1495#define xhci_resume NULL
1496#endif
1497
1372int xhci_get_frame(struct usb_hcd *hcd); 1498int xhci_get_frame(struct usb_hcd *hcd);
1373irqreturn_t xhci_irq(struct usb_hcd *hcd); 1499irqreturn_t xhci_irq(struct usb_hcd *hcd);
1374irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd); 1500irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd);
@@ -1388,7 +1514,7 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
1388int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); 1514int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
1389int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); 1515int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
1390void xhci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep); 1516void xhci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
1391int xhci_reset_device(struct usb_hcd *hcd, struct usb_device *udev); 1517int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev);
1392int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); 1518int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1393void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); 1519void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1394 1520
@@ -1399,14 +1525,13 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
1399 dma_addr_t suspect_dma); 1525 dma_addr_t suspect_dma);
1400int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); 1526int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
1401void xhci_ring_cmd_db(struct xhci_hcd *xhci); 1527void xhci_ring_cmd_db(struct xhci_hcd *xhci);
1402void *xhci_setup_one_noop(struct xhci_hcd *xhci);
1403int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); 1528int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
1404int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1529int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1405 u32 slot_id); 1530 u32 slot_id);
1406int xhci_queue_vendor_command(struct xhci_hcd *xhci, 1531int xhci_queue_vendor_command(struct xhci_hcd *xhci,
1407 u32 field1, u32 field2, u32 field3, u32 field4); 1532 u32 field1, u32 field2, u32 field3, u32 field4);
1408int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, 1533int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
1409 unsigned int ep_index); 1534 unsigned int ep_index, int suspend);
1410int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, 1535int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1411 int slot_id, unsigned int ep_index); 1536 int slot_id, unsigned int ep_index);
1412int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, 1537int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
@@ -1436,12 +1561,27 @@ void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
1436 unsigned int slot_id, unsigned int ep_index, 1561 unsigned int slot_id, unsigned int ep_index,
1437 struct xhci_dequeue_state *deq_state); 1562 struct xhci_dequeue_state *deq_state);
1438void xhci_stop_endpoint_command_watchdog(unsigned long arg); 1563void xhci_stop_endpoint_command_watchdog(unsigned long arg);
1564void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
1565 unsigned int ep_index, unsigned int stream_id);
1439 1566
1440/* xHCI roothub code */ 1567/* xHCI roothub code */
1441int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, 1568int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
1442 char *buf, u16 wLength); 1569 char *buf, u16 wLength);
1443int xhci_hub_status_data(struct usb_hcd *hcd, char *buf); 1570int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
1444 1571
1572#ifdef CONFIG_PM
1573int xhci_bus_suspend(struct usb_hcd *hcd);
1574int xhci_bus_resume(struct usb_hcd *hcd);
1575#else
1576#define xhci_bus_suspend NULL
1577#define xhci_bus_resume NULL
1578#endif /* CONFIG_PM */
1579
1580u32 xhci_port_state_to_neutral(u32 state);
1581int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
1582 u16 port);
1583void xhci_ring_device(struct xhci_hcd *xhci, int slot_id);
1584
1445/* xHCI contexts */ 1585/* xHCI contexts */
1446struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx); 1586struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
1447struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx); 1587struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index e192e8f7c560..575b56c79e97 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -963,6 +963,7 @@ static const struct file_operations mdc800_device_ops =
963 .write = mdc800_device_write, 963 .write = mdc800_device_write,
964 .open = mdc800_device_open, 964 .open = mdc800_device_open,
965 .release = mdc800_device_release, 965 .release = mdc800_device_release,
966 .llseek = noop_llseek,
966}; 967};
967 968
968 969
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 3a6bcd5fee09..a0037961e5bd 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -69,7 +69,7 @@
69 * 20000513 added IDs for all products supported by Windows driver (john) 69 * 20000513 added IDs for all products supported by Windows driver (john)
70 * 20000514 Rewrote mts_scsi_queuecommand to use URBs (john) 70 * 20000514 Rewrote mts_scsi_queuecommand to use URBs (john)
71 * 20000514 Version 0.0.8j 71 * 20000514 Version 0.0.8j
72 * 20000514 Fix reporting of non-existant devices to SCSI layer (john) 72 * 20000514 Fix reporting of non-existent devices to SCSI layer (john)
73 * 20000514 Added MTS_DEBUG_INT (john) 73 * 20000514 Added MTS_DEBUG_INT (john)
74 * 20000514 Changed "usb-microtek" to "microtek" for consistency (john) 74 * 20000514 Changed "usb-microtek" to "microtek" for consistency (john)
75 * 20000514 Stupid bug fixes (john) 75 * 20000514 Stupid bug fixes (john)
@@ -364,7 +364,7 @@ static int mts_scsi_host_reset(struct scsi_cmnd *srb)
364} 364}
365 365
366static int 366static int
367mts_scsi_queuecommand(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback); 367mts_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *srb);
368 368
369static void mts_transfer_cleanup( struct urb *transfer ); 369static void mts_transfer_cleanup( struct urb *transfer );
370static void mts_do_sg(struct urb * transfer); 370static void mts_do_sg(struct urb * transfer);
@@ -398,7 +398,6 @@ void mts_int_submit_urb (struct urb* transfer,
398 context->srb->result = DID_ERROR << 16; 398 context->srb->result = DID_ERROR << 16;
399 mts_transfer_cleanup(transfer); 399 mts_transfer_cleanup(transfer);
400 } 400 }
401 return;
402} 401}
403 402
404 403
@@ -409,7 +408,6 @@ static void mts_transfer_cleanup( struct urb *transfer )
409 408
410 if ( likely(context->final_callback != NULL) ) 409 if ( likely(context->final_callback != NULL) )
411 context->final_callback(context->srb); 410 context->final_callback(context->srb);
412
413} 411}
414 412
415static void mts_transfer_done( struct urb *transfer ) 413static void mts_transfer_done( struct urb *transfer )
@@ -420,8 +418,6 @@ static void mts_transfer_done( struct urb *transfer )
420 context->srb->result |= (unsigned)(*context->scsi_status)<<1; 418 context->srb->result |= (unsigned)(*context->scsi_status)<<1;
421 419
422 mts_transfer_cleanup(transfer); 420 mts_transfer_cleanup(transfer);
423
424 return;
425} 421}
426 422
427 423
@@ -452,8 +448,6 @@ static void mts_data_done( struct urb* transfer )
452 } 448 }
453 449
454 mts_get_status(transfer); 450 mts_get_status(transfer);
455
456 return;
457} 451}
458 452
459 453
@@ -496,8 +490,6 @@ static void mts_command_done( struct urb *transfer )
496 mts_get_status(transfer); 490 mts_get_status(transfer);
497 } 491 }
498 } 492 }
499
500 return;
501} 493}
502 494
503static void mts_do_sg (struct urb* transfer) 495static void mts_do_sg (struct urb* transfer)
@@ -522,7 +514,6 @@ static void mts_do_sg (struct urb* transfer)
522 sg[context->fragment].length, 514 sg[context->fragment].length,
523 context->fragment + 1 == scsi_sg_count(context->srb) ? 515 context->fragment + 1 == scsi_sg_count(context->srb) ?
524 mts_data_done : mts_do_sg); 516 mts_data_done : mts_do_sg);
525 return;
526} 517}
527 518
528static const u8 mts_read_image_sig[] = { 0x28, 00, 00, 00 }; 519static const u8 mts_read_image_sig[] = { 0x28, 00, 00, 00 };
@@ -566,14 +557,14 @@ mts_build_transfer_context(struct scsi_cmnd *srb, struct mts_desc* desc)
566 557
567 if ( !memcmp( srb->cmnd, mts_read_image_sig, mts_read_image_sig_len ) 558 if ( !memcmp( srb->cmnd, mts_read_image_sig, mts_read_image_sig_len )
568) { pipe = usb_rcvbulkpipe(desc->usb_dev,desc->ep_image); 559) { pipe = usb_rcvbulkpipe(desc->usb_dev,desc->ep_image);
569 MTS_DEBUG( "transfering from desc->ep_image == %d\n", 560 MTS_DEBUG( "transferring from desc->ep_image == %d\n",
570 (int)desc->ep_image ); 561 (int)desc->ep_image );
571 } else if ( MTS_DIRECTION_IS_IN(srb->cmnd[0]) ) { 562 } else if ( MTS_DIRECTION_IS_IN(srb->cmnd[0]) ) {
572 pipe = usb_rcvbulkpipe(desc->usb_dev,desc->ep_response); 563 pipe = usb_rcvbulkpipe(desc->usb_dev,desc->ep_response);
573 MTS_DEBUG( "transfering from desc->ep_response == %d\n", 564 MTS_DEBUG( "transferring from desc->ep_response == %d\n",
574 (int)desc->ep_response); 565 (int)desc->ep_response);
575 } else { 566 } else {
576 MTS_DEBUG("transfering to desc->ep_out == %d\n", 567 MTS_DEBUG("transferring to desc->ep_out == %d\n",
577 (int)desc->ep_out); 568 (int)desc->ep_out);
578 pipe = usb_sndbulkpipe(desc->usb_dev,desc->ep_out); 569 pipe = usb_sndbulkpipe(desc->usb_dev,desc->ep_out);
579 } 570 }
@@ -582,7 +573,7 @@ mts_build_transfer_context(struct scsi_cmnd *srb, struct mts_desc* desc)
582 573
583 574
584static int 575static int
585mts_scsi_queuecommand(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback) 576mts_scsi_queuecommand_lck(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback)
586{ 577{
587 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); 578 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
588 int err = 0; 579 int err = 0;
@@ -635,6 +626,8 @@ out:
635 return err; 626 return err;
636} 627}
637 628
629static DEF_SCSI_QCMD(mts_scsi_queuecommand)
630
638static struct scsi_host_template mts_scsi_host_template = { 631static struct scsi_host_template mts_scsi_host_template = {
639 .module = THIS_MODULE, 632 .module = THIS_MODULE,
640 .name = "microtekX6", 633 .name = "microtekX6",
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 55660eaf947c..1bfcd02ebeb5 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -231,3 +231,16 @@ config USB_ISIGHTFW
231 driver beforehand. Tools for doing so are available at 231 driver beforehand. Tools for doing so are available at
232 http://bersace03.free.fr 232 http://bersace03.free.fr
233 233
234config USB_YUREX
235 tristate "USB YUREX driver support"
236 depends on USB
237 help
238 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
240 <http://bbu.kayac.com/en/> for further information.
241 This driver supports read/write of leg-shakes counter and
242 fasync for the counter update via a device file /dev/yurex*.
243
244 To compile this driver as a module, choose M here: the
245 module will be called yurex.
246
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 717703e81425..796ce7ebccc8 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -3,28 +3,27 @@
3# (the ones that don't fit into any other categories) 3# (the ones that don't fit into any other categories)
4# 4#
5 5
6obj-$(CONFIG_USB_ADUTUX) += adutux.o 6ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
7obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o
8obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o
9obj-$(CONFIG_USB_CYTHERM) += cytherm.o
10obj-$(CONFIG_USB_EMI26) += emi26.o
11obj-$(CONFIG_USB_EMI62) += emi62.o
12obj-$(CONFIG_USB_FTDI_ELAN) += ftdi-elan.o
13obj-$(CONFIG_USB_IDMOUSE) += idmouse.o
14obj-$(CONFIG_USB_IOWARRIOR) += iowarrior.o
15obj-$(CONFIG_USB_ISIGHTFW) += isight_firmware.o
16obj-$(CONFIG_USB_LCD) += usblcd.o
17obj-$(CONFIG_USB_LD) += ldusb.o
18obj-$(CONFIG_USB_LED) += usbled.o
19obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
20obj-$(CONFIG_USB_RIO500) += rio500.o
21obj-$(CONFIG_USB_TEST) += usbtest.o
22obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
23obj-$(CONFIG_USB_USS720) += uss720.o
24obj-$(CONFIG_USB_SEVSEG) += usbsevseg.o
25 7
26obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/ 8obj-$(CONFIG_USB_ADUTUX) += adutux.o
9obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o
10obj-$(CONFIG_USB_CYPRESS_CY7C63) += cypress_cy7c63.o
11obj-$(CONFIG_USB_CYTHERM) += cytherm.o
12obj-$(CONFIG_USB_EMI26) += emi26.o
13obj-$(CONFIG_USB_EMI62) += emi62.o
14obj-$(CONFIG_USB_FTDI_ELAN) += ftdi-elan.o
15obj-$(CONFIG_USB_IDMOUSE) += idmouse.o
16obj-$(CONFIG_USB_IOWARRIOR) += iowarrior.o
17obj-$(CONFIG_USB_ISIGHTFW) += isight_firmware.o
18obj-$(CONFIG_USB_LCD) += usblcd.o
19obj-$(CONFIG_USB_LD) += ldusb.o
20obj-$(CONFIG_USB_LED) += usbled.o
21obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
22obj-$(CONFIG_USB_RIO500) += rio500.o
23obj-$(CONFIG_USB_TEST) += usbtest.o
24obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
25obj-$(CONFIG_USB_USS720) += uss720.o
26obj-$(CONFIG_USB_SEVSEG) += usbsevseg.o
27obj-$(CONFIG_USB_YUREX) += yurex.o
27 28
28ifeq ($(CONFIG_USB_DEBUG),y) 29obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/
29EXTRA_CFLAGS += -DDEBUG
30endif
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index 801324af9470..a6afd15f6a46 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -679,6 +679,7 @@ static const struct file_operations adu_fops = {
679 .write = adu_write, 679 .write = adu_write,
680 .open = adu_open, 680 .open = adu_open,
681 .release = adu_release, 681 .release = adu_release,
682 .llseek = noop_llseek,
682}; 683};
683 684
684/* 685/*
@@ -716,7 +717,7 @@ static int adu_probe(struct usb_interface *interface,
716 goto exit; 717 goto exit;
717 } 718 }
718 719
719 /* allocate memory for our device state and intialize it */ 720 /* allocate memory for our device state and initialize it */
720 dev = kzalloc(sizeof(struct adu_device), GFP_KERNEL); 721 dev = kzalloc(sizeof(struct adu_device), GFP_KERNEL);
721 if (dev == NULL) { 722 if (dev == NULL) {
722 dev_err(&interface->dev, "Out of memory\n"); 723 dev_err(&interface->dev, "Out of memory\n");
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index 1fa6ce3e4a23..68ab460a735c 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -282,6 +282,7 @@ static int appledisplay_probe(struct usb_interface *iface,
282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d", 282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
283 atomic_inc_return(&count_displays) - 1); 283 atomic_inc_return(&count_displays) - 1);
284 memset(&props, 0, sizeof(struct backlight_properties)); 284 memset(&props, 0, sizeof(struct backlight_properties));
285 props.type = BACKLIGHT_RAW;
285 props.max_brightness = 0xff; 286 props.max_brightness = 0xff;
286 pdata->bd = backlight_device_register(bl_name, NULL, pdata, 287 pdata->bd = backlight_device_register(bl_name, NULL, pdata,
287 &appledisplay_bl_data, &props); 288 &appledisplay_bl_data, &props);
diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c
index 2f43c57743c9..9251773ecef4 100644
--- a/drivers/usb/misc/cypress_cy7c63.c
+++ b/drivers/usb/misc/cypress_cy7c63.c
@@ -196,11 +196,9 @@ static ssize_t get_port1_handler(struct device *dev,
196 return read_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1); 196 return read_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1);
197} 197}
198 198
199static DEVICE_ATTR(port0, S_IWUGO | S_IRUGO, 199static DEVICE_ATTR(port0, S_IRUGO | S_IWUSR, get_port0_handler, set_port0_handler);
200 get_port0_handler, set_port0_handler);
201 200
202static DEVICE_ATTR(port1, S_IWUGO | S_IRUGO, 201static DEVICE_ATTR(port1, S_IRUGO | S_IWUSR, get_port1_handler, set_port1_handler);
203 get_port1_handler, set_port1_handler);
204 202
205 203
206static int cypress_probe(struct usb_interface *interface, 204static int cypress_probe(struct usb_interface *interface,
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index aecf380f6ecc..b16bd3ce3915 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -456,7 +456,6 @@ static void ftdi_elan_cancel_targets(struct usb_ftdi *ftdi)
456static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi) 456static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi)
457{ 457{
458 ftdi_command_queue_work(ftdi, 0); 458 ftdi_command_queue_work(ftdi, 0);
459 return;
460} 459}
461 460
462static void ftdi_elan_command_work(struct work_struct *work) 461static void ftdi_elan_command_work(struct work_struct *work)
@@ -483,7 +482,6 @@ static void ftdi_elan_command_work(struct work_struct *work)
483static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi) 482static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi)
484{ 483{
485 ftdi_respond_queue_work(ftdi, 0); 484 ftdi_respond_queue_work(ftdi, 0);
486 return;
487} 485}
488 486
489static void ftdi_elan_respond_work(struct work_struct *work) 487static void ftdi_elan_respond_work(struct work_struct *work)
@@ -2769,7 +2767,7 @@ static int ftdi_elan_probe(struct usb_interface *interface,
2769 ftdi->sequence_num = ++ftdi_instances; 2767 ftdi->sequence_num = ++ftdi_instances;
2770 mutex_unlock(&ftdi_module_lock); 2768 mutex_unlock(&ftdi_module_lock);
2771 ftdi_elan_init_kref(ftdi); 2769 ftdi_elan_init_kref(ftdi);
2772 init_MUTEX(&ftdi->sw_lock); 2770 sema_init(&ftdi->sw_lock, 1);
2773 ftdi->udev = usb_get_dev(interface_to_usbdev(interface)); 2771 ftdi->udev = usb_get_dev(interface_to_usbdev(interface));
2774 ftdi->interface = interface; 2772 ftdi->interface = interface;
2775 mutex_init(&ftdi->u132_lock); 2773 mutex_init(&ftdi->u132_lock);
@@ -2891,8 +2889,7 @@ static struct usb_driver ftdi_elan_driver = {
2891static int __init ftdi_elan_init(void) 2889static int __init ftdi_elan_init(void)
2892{ 2890{
2893 int result; 2891 int result;
2894 printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name, 2892 printk(KERN_INFO "driver %s\n", ftdi_elan_driver.name);
2895 __TIME__, __DATE__);
2896 mutex_init(&ftdi_module_lock); 2893 mutex_init(&ftdi_module_lock);
2897 INIT_LIST_HEAD(&ftdi_static_list); 2894 INIT_LIST_HEAD(&ftdi_static_list);
2898 status_queue = create_singlethread_workqueue("ftdi-status-control"); 2895 status_queue = create_singlethread_workqueue("ftdi-status-control");
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index a54c3cb804ce..c6184b4d1695 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -105,6 +105,7 @@ static const struct file_operations idmouse_fops = {
105 .read = idmouse_read, 105 .read = idmouse_read,
106 .open = idmouse_open, 106 .open = idmouse_open,
107 .release = idmouse_release, 107 .release = idmouse_release,
108 .llseek = default_llseek,
108}; 109};
109 110
110/* class driver information */ 111/* class driver information */
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index bc88c79875a1..a2190b983f52 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -40,7 +40,7 @@
40#ifdef CONFIG_USB_DYNAMIC_MINORS 40#ifdef CONFIG_USB_DYNAMIC_MINORS
41#define IOWARRIOR_MINOR_BASE 0 41#define IOWARRIOR_MINOR_BASE 0
42#else 42#else
43#define IOWARRIOR_MINOR_BASE 208 // SKELETON_MINOR_BASE 192 + 16, not offical yet 43#define IOWARRIOR_MINOR_BASE 208 // SKELETON_MINOR_BASE 192 + 16, not official yet
44#endif 44#endif
45 45
46/* interrupt input queue size */ 46/* interrupt input queue size */
@@ -374,7 +374,7 @@ static ssize_t iowarrior_write(struct file *file,
374 case USB_DEVICE_ID_CODEMERCS_IOWPV2: 374 case USB_DEVICE_ID_CODEMERCS_IOWPV2:
375 case USB_DEVICE_ID_CODEMERCS_IOW40: 375 case USB_DEVICE_ID_CODEMERCS_IOW40:
376 /* IOW24 and IOW40 use a synchronous call */ 376 /* IOW24 and IOW40 use a synchronous call */
377 buf = kmalloc(8, GFP_KERNEL); /* 8 bytes are enough for both products */ 377 buf = kmalloc(count, GFP_KERNEL);
378 if (!buf) { 378 if (!buf) {
379 retval = -ENOMEM; 379 retval = -ENOMEM;
380 goto exit; 380 goto exit;
@@ -553,6 +553,7 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd,
553 /* needed for power consumption */ 553 /* needed for power consumption */
554 struct usb_config_descriptor *cfg_descriptor = &dev->udev->actconfig->desc; 554 struct usb_config_descriptor *cfg_descriptor = &dev->udev->actconfig->desc;
555 555
556 memset(&info, 0, sizeof(info));
556 /* directly from the descriptor */ 557 /* directly from the descriptor */
557 info.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); 558 info.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
558 info.product = dev->product_id; 559 info.product = dev->product_id;
@@ -730,6 +731,7 @@ static const struct file_operations iowarrior_fops = {
730 .open = iowarrior_open, 731 .open = iowarrior_open,
731 .release = iowarrior_release, 732 .release = iowarrior_release,
732 .poll = iowarrior_poll, 733 .poll = iowarrior_poll,
734 .llseek = noop_llseek,
733}; 735};
734 736
735static char *iowarrior_devnode(struct device *dev, mode_t *mode) 737static char *iowarrior_devnode(struct device *dev, mode_t *mode)
@@ -767,7 +769,7 @@ static int iowarrior_probe(struct usb_interface *interface,
767 int i; 769 int i;
768 int retval = -ENOMEM; 770 int retval = -ENOMEM;
769 771
770 /* allocate memory for our device state and intialize it */ 772 /* allocate memory for our device state and initialize it */
771 dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL); 773 dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL);
772 if (dev == NULL) { 774 if (dev == NULL) {
773 dev_err(&interface->dev, "Out of memory\n"); 775 dev_err(&interface->dev, "Out of memory\n");
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index dd41d8710043..cb4096201e29 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -20,11 +20,6 @@
20 * Derived from Lego USB Tower driver 20 * Derived from Lego USB Tower driver
21 * Copyright (C) 2003 David Glance <advidgsf@sourceforge.net> 21 * Copyright (C) 2003 David Glance <advidgsf@sourceforge.net>
22 * 2001-2004 Juergen Stuber <starblue@users.sourceforge.net> 22 * 2001-2004 Juergen Stuber <starblue@users.sourceforge.net>
23 *
24 * V0.1 (mh) Initial version
25 * V0.11 (mh) Added raw support for HID 1.0 devices (no interrupt out endpoint)
26 * V0.12 (mh) Added kmalloc check for string buffer
27 * V0.13 (mh) Added support for LD X-Ray and Machine Test System
28 */ 23 */
29 24
30#include <linux/kernel.h> 25#include <linux/kernel.h>
@@ -41,20 +36,39 @@
41 36
42/* Define these values to match your devices */ 37/* Define these values to match your devices */
43#define USB_VENDOR_ID_LD 0x0f11 /* USB Vendor ID of LD Didactic GmbH */ 38#define USB_VENDOR_ID_LD 0x0f11 /* USB Vendor ID of LD Didactic GmbH */
44#define USB_DEVICE_ID_LD_CASSY 0x1000 /* USB Product ID of CASSY-S */ 39#define USB_DEVICE_ID_LD_CASSY 0x1000 /* USB Product ID of CASSY-S modules with 8 bytes endpoint size */
40#define USB_DEVICE_ID_LD_CASSY2 0x1001 /* USB Product ID of CASSY-S modules with 64 bytes endpoint size */
45#define USB_DEVICE_ID_LD_POCKETCASSY 0x1010 /* USB Product ID of Pocket-CASSY */ 41#define USB_DEVICE_ID_LD_POCKETCASSY 0x1010 /* USB Product ID of Pocket-CASSY */
42#define USB_DEVICE_ID_LD_POCKETCASSY2 0x1011 /* USB Product ID of Pocket-CASSY 2 (reserved) */
46#define USB_DEVICE_ID_LD_MOBILECASSY 0x1020 /* USB Product ID of Mobile-CASSY */ 43#define USB_DEVICE_ID_LD_MOBILECASSY 0x1020 /* USB Product ID of Mobile-CASSY */
44#define USB_DEVICE_ID_LD_MOBILECASSY2 0x1021 /* USB Product ID of Mobile-CASSY 2 (reserved) */
45#define USB_DEVICE_ID_LD_MICROCASSYVOLTAGE 0x1031 /* USB Product ID of Micro-CASSY Voltage */
46#define USB_DEVICE_ID_LD_MICROCASSYCURRENT 0x1032 /* USB Product ID of Micro-CASSY Current */
47#define USB_DEVICE_ID_LD_MICROCASSYTIME 0x1033 /* USB Product ID of Micro-CASSY Time (reserved) */
48#define USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE 0x1035 /* USB Product ID of Micro-CASSY Temperature */
49#define USB_DEVICE_ID_LD_MICROCASSYPH 0x1038 /* USB Product ID of Micro-CASSY pH */
47#define USB_DEVICE_ID_LD_JWM 0x1080 /* USB Product ID of Joule and Wattmeter */ 50#define USB_DEVICE_ID_LD_JWM 0x1080 /* USB Product ID of Joule and Wattmeter */
48#define USB_DEVICE_ID_LD_DMMP 0x1081 /* USB Product ID of Digital Multimeter P (reserved) */ 51#define USB_DEVICE_ID_LD_DMMP 0x1081 /* USB Product ID of Digital Multimeter P (reserved) */
49#define USB_DEVICE_ID_LD_UMIP 0x1090 /* USB Product ID of UMI P */ 52#define USB_DEVICE_ID_LD_UMIP 0x1090 /* USB Product ID of UMI P */
50#define USB_DEVICE_ID_LD_XRAY1 0x1100 /* USB Product ID of X-Ray Apparatus */ 53#define USB_DEVICE_ID_LD_UMIC 0x10A0 /* USB Product ID of UMI C */
51#define USB_DEVICE_ID_LD_XRAY2 0x1101 /* USB Product ID of X-Ray Apparatus */ 54#define USB_DEVICE_ID_LD_UMIB 0x10B0 /* USB Product ID of UMI B */
55#define USB_DEVICE_ID_LD_XRAY 0x1100 /* USB Product ID of X-Ray Apparatus 55481 */
56#define USB_DEVICE_ID_LD_XRAY2 0x1101 /* USB Product ID of X-Ray Apparatus 554800 */
57#define USB_DEVICE_ID_LD_XRAYCT 0x1110 /* USB Product ID of X-Ray Apparatus CT 554821*/
52#define USB_DEVICE_ID_LD_VIDEOCOM 0x1200 /* USB Product ID of VideoCom */ 58#define USB_DEVICE_ID_LD_VIDEOCOM 0x1200 /* USB Product ID of VideoCom */
59#define USB_DEVICE_ID_LD_MOTOR 0x1210 /* USB Product ID of Motor (reserved) */
53#define USB_DEVICE_ID_LD_COM3LAB 0x2000 /* USB Product ID of COM3LAB */ 60#define USB_DEVICE_ID_LD_COM3LAB 0x2000 /* USB Product ID of COM3LAB */
54#define USB_DEVICE_ID_LD_TELEPORT 0x2010 /* USB Product ID of Terminal Adapter */ 61#define USB_DEVICE_ID_LD_TELEPORT 0x2010 /* USB Product ID of Terminal Adapter */
55#define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020 /* USB Product ID of Network Analyser */ 62#define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020 /* USB Product ID of Network Analyser */
56#define USB_DEVICE_ID_LD_POWERCONTROL 0x2030 /* USB Product ID of Converter Control Unit */ 63#define USB_DEVICE_ID_LD_POWERCONTROL 0x2030 /* USB Product ID of Converter Control Unit */
57#define USB_DEVICE_ID_LD_MACHINETEST 0x2040 /* USB Product ID of Machine Test System */ 64#define USB_DEVICE_ID_LD_MACHINETEST 0x2040 /* USB Product ID of Machine Test System */
65#define USB_DEVICE_ID_LD_MOSTANALYSER 0x2050 /* USB Product ID of MOST Protocol Analyser */
66#define USB_DEVICE_ID_LD_MOSTANALYSER2 0x2051 /* USB Product ID of MOST Protocol Analyser 2 */
67#define USB_DEVICE_ID_LD_ABSESP 0x2060 /* USB Product ID of ABS ESP */
68#define USB_DEVICE_ID_LD_AUTODATABUS 0x2070 /* USB Product ID of Automotive Data Buses */
69#define USB_DEVICE_ID_LD_MCT 0x2080 /* USB Product ID of Microcontroller technique */
70#define USB_DEVICE_ID_LD_HYBRID 0x2090 /* USB Product ID of Automotive Hybrid */
71#define USB_DEVICE_ID_LD_HEATCONTROL 0x20A0 /* USB Product ID of Heat control */
58 72
59#define USB_VENDOR_ID_VERNIER 0x08f7 73#define USB_VENDOR_ID_VERNIER 0x08f7
60#define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002 74#define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
@@ -71,19 +85,37 @@
71/* table of devices that work with this driver */ 85/* table of devices that work with this driver */
72static const struct usb_device_id ld_usb_table[] = { 86static const struct usb_device_id ld_usb_table[] = {
73 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) }, 87 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
88 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
74 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) }, 89 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
90 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
75 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) }, 91 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
92 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
93 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
94 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
95 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
96 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
97 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
76 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, 98 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
77 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, 99 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
78 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) }, 100 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
79 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) }, 101 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
102 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
103 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
80 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) }, 104 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
81 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) }, 105 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
106 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
82 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) }, 107 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
83 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) }, 108 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
84 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) }, 109 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
85 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) }, 110 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
86 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) }, 111 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
112 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
113 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
114 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
115 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
116 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
117 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
118 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
87 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, 119 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
88 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, 120 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
89 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) }, 121 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
@@ -91,7 +123,7 @@ static const struct usb_device_id ld_usb_table[] = {
91 { } /* Terminating entry */ 123 { } /* Terminating entry */
92}; 124};
93MODULE_DEVICE_TABLE(usb, ld_usb_table); 125MODULE_DEVICE_TABLE(usb, ld_usb_table);
94MODULE_VERSION("V0.13"); 126MODULE_VERSION("V0.14");
95MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>"); 127MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>");
96MODULE_DESCRIPTION("LD USB Driver"); 128MODULE_DESCRIPTION("LD USB Driver");
97MODULE_LICENSE("GPL"); 129MODULE_LICENSE("GPL");
@@ -613,6 +645,7 @@ static const struct file_operations ld_usb_fops = {
613 .open = ld_usb_open, 645 .open = ld_usb_open,
614 .release = ld_usb_release, 646 .release = ld_usb_release,
615 .poll = ld_usb_poll, 647 .poll = ld_usb_poll,
648 .llseek = no_llseek,
616}; 649};
617 650
618/* 651/*
@@ -641,7 +674,7 @@ static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *
641 int i; 674 int i;
642 int retval = -ENOMEM; 675 int retval = -ENOMEM;
643 676
644 /* allocate memory for our device state and intialize it */ 677 /* allocate memory for our device state and initialize it */
645 678
646 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 679 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
647 if (dev == NULL) { 680 if (dev == NULL) {
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
index cc13ae61712a..4e23d3841b43 100644
--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -439,6 +439,7 @@ static const struct file_operations usb_rio_fops = {
439 .unlocked_ioctl = ioctl_rio, 439 .unlocked_ioctl = ioctl_rio,
440 .open = open_rio, 440 .open = open_rio,
441 .release = close_rio, 441 .release = close_rio,
442 .llseek = noop_llseek,
442}; 443};
443 444
444static struct usb_class_driver usb_rio_class = { 445static struct usb_class_driver usb_rio_class = {
diff --git a/drivers/usb/misc/sisusbvga/Makefile b/drivers/usb/misc/sisusbvga/Makefile
index 7f934cfc906c..3142476ccc8e 100644
--- a/drivers/usb/misc/sisusbvga/Makefile
+++ b/drivers/usb/misc/sisusbvga/Makefile
@@ -4,5 +4,4 @@
4 4
5obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga.o 5obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga.o
6 6
7sisusbvga-objs := sisusb.o sisusb_init.o sisusb_con.o 7sisusbvga-y := sisusb.o sisusb_init.o sisusb_con.o
8
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 70d00e99a4b4..dd573abd2d1e 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -3008,6 +3008,7 @@ sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3008#else 3008#else
3009 x.sisusb_conactive = 0; 3009 x.sisusb_conactive = 0;
3010#endif 3010#endif
3011 memset(x.sisusb_reserved, 0, sizeof(x.sisusb_reserved));
3011 3012
3012 if (copy_to_user((void __user *)arg, &x, sizeof(x))) 3013 if (copy_to_user((void __user *)arg, &x, sizeof(x)))
3013 retval = -EFAULT; 3014 retval = -EFAULT;
diff --git a/drivers/usb/misc/trancevibrator.c b/drivers/usb/misc/trancevibrator.c
index d77aba46ae85..f63776a48e2a 100644
--- a/drivers/usb/misc/trancevibrator.c
+++ b/drivers/usb/misc/trancevibrator.c
@@ -86,7 +86,7 @@ static ssize_t set_speed(struct device *dev, struct device_attribute *attr,
86 return count; 86 return count;
87} 87}
88 88
89static DEVICE_ATTR(speed, S_IWUGO | S_IRUGO, show_speed, set_speed); 89static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR, show_speed, set_speed);
90 90
91static int tv_probe(struct usb_interface *interface, 91static int tv_probe(struct usb_interface *interface,
92 const struct usb_device_id *id) 92 const struct usb_device_id *id)
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index d00dde19194c..51648154bb44 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -282,6 +282,7 @@ static const struct file_operations lcd_fops = {
282 .open = lcd_open, 282 .open = lcd_open,
283 .unlocked_ioctl = lcd_ioctl, 283 .unlocked_ioctl = lcd_ioctl,
284 .release = lcd_release, 284 .release = lcd_release,
285 .llseek = noop_llseek,
285}; 286};
286 287
287/* 288/*
diff --git a/drivers/usb/misc/usbled.c b/drivers/usb/misc/usbled.c
index 63da2c3c838f..1616ad1793a4 100644
--- a/drivers/usb/misc/usbled.c
+++ b/drivers/usb/misc/usbled.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * USB LED driver - 1.1 2 * USB LED driver
3 * 3 *
4 * Copyright (C) 2004 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 2004 Greg Kroah-Hartman (greg@kroah.com)
5 * 5 *
@@ -20,12 +20,17 @@
20#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com" 20#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com"
21#define DRIVER_DESC "USB LED Driver" 21#define DRIVER_DESC "USB LED Driver"
22 22
23#define VENDOR_ID 0x0fc5 23enum led_type {
24#define PRODUCT_ID 0x1223 24 DELCOM_VISUAL_SIGNAL_INDICATOR,
25 DREAM_CHEEKY_WEBMAIL_NOTIFIER,
26};
25 27
26/* table of devices that work with this driver */ 28/* table of devices that work with this driver */
27static const struct usb_device_id id_table[] = { 29static const struct usb_device_id id_table[] = {
28 { USB_DEVICE(VENDOR_ID, PRODUCT_ID) }, 30 { USB_DEVICE(0x0fc5, 0x1223),
31 .driver_info = DELCOM_VISUAL_SIGNAL_INDICATOR },
32 { USB_DEVICE(0x1d34, 0x0004),
33 .driver_info = DREAM_CHEEKY_WEBMAIL_NOTIFIER },
29 { }, 34 { },
30}; 35};
31MODULE_DEVICE_TABLE (usb, id_table); 36MODULE_DEVICE_TABLE (usb, id_table);
@@ -35,15 +40,12 @@ struct usb_led {
35 unsigned char blue; 40 unsigned char blue;
36 unsigned char red; 41 unsigned char red;
37 unsigned char green; 42 unsigned char green;
43 enum led_type type;
38}; 44};
39 45
40#define BLUE 0x04
41#define RED 0x02
42#define GREEN 0x01
43static void change_color(struct usb_led *led) 46static void change_color(struct usb_led *led)
44{ 47{
45 int retval; 48 int retval = 0;
46 unsigned char color = 0x07;
47 unsigned char *buffer; 49 unsigned char *buffer;
48 50
49 buffer = kmalloc(8, GFP_KERNEL); 51 buffer = kmalloc(8, GFP_KERNEL);
@@ -52,25 +54,59 @@ static void change_color(struct usb_led *led)
52 return; 54 return;
53 } 55 }
54 56
55 if (led->blue) 57 switch (led->type) {
56 color &= ~(BLUE); 58 case DELCOM_VISUAL_SIGNAL_INDICATOR: {
57 if (led->red) 59 unsigned char color = 0x07;
58 color &= ~(RED); 60
59 if (led->green) 61 if (led->blue)
60 color &= ~(GREEN); 62 color &= ~0x04;
61 dev_dbg(&led->udev->dev, 63 if (led->red)
62 "blue = %d, red = %d, green = %d, color = %.2x\n", 64 color &= ~0x02;
63 led->blue, led->red, led->green, color); 65 if (led->green)
64 66 color &= ~0x01;
65 retval = usb_control_msg(led->udev, 67 dev_dbg(&led->udev->dev,
66 usb_sndctrlpipe(led->udev, 0), 68 "blue = %d, red = %d, green = %d, color = %.2x\n",
67 0x12, 69 led->blue, led->red, led->green, color);
68 0xc8, 70
69 (0x02 * 0x100) + 0x0a, 71 retval = usb_control_msg(led->udev,
70 (0x00 * 0x100) + color, 72 usb_sndctrlpipe(led->udev, 0),
71 buffer, 73 0x12,
72 8, 74 0xc8,
73 2000); 75 (0x02 * 0x100) + 0x0a,
76 (0x00 * 0x100) + color,
77 buffer,
78 8,
79 2000);
80 break;
81 }
82
83 case DREAM_CHEEKY_WEBMAIL_NOTIFIER:
84 dev_dbg(&led->udev->dev,
85 "red = %d, green = %d, blue = %d\n",
86 led->red, led->green, led->blue);
87
88 buffer[0] = led->red;
89 buffer[1] = led->green;
90 buffer[2] = led->blue;
91 buffer[3] = buffer[4] = buffer[5] = 0;
92 buffer[6] = 0x1a;
93 buffer[7] = 0x05;
94
95 retval = usb_control_msg(led->udev,
96 usb_sndctrlpipe(led->udev, 0),
97 0x09,
98 0x21,
99 0x200,
100 0,
101 buffer,
102 8,
103 2000);
104 break;
105
106 default:
107 dev_err(&led->udev->dev, "unknown device type %d\n", led->type);
108 }
109
74 if (retval) 110 if (retval)
75 dev_dbg(&led->udev->dev, "retval = %d\n", retval); 111 dev_dbg(&led->udev->dev, "retval = %d\n", retval);
76 kfree(buffer); 112 kfree(buffer);
@@ -94,7 +130,7 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
94 change_color(led); \ 130 change_color(led); \
95 return count; \ 131 return count; \
96} \ 132} \
97static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 133static DEVICE_ATTR(value, S_IRUGO | S_IWUSR, show_##value, set_##value);
98show_set(blue); 134show_set(blue);
99show_set(red); 135show_set(red);
100show_set(green); 136show_set(green);
@@ -107,11 +143,12 @@ static int led_probe(struct usb_interface *interface, const struct usb_device_id
107 143
108 dev = kzalloc(sizeof(struct usb_led), GFP_KERNEL); 144 dev = kzalloc(sizeof(struct usb_led), GFP_KERNEL);
109 if (dev == NULL) { 145 if (dev == NULL) {
110 dev_err(&interface->dev, "Out of memory\n"); 146 dev_err(&interface->dev, "out of memory\n");
111 goto error_mem; 147 goto error_mem;
112 } 148 }
113 149
114 dev->udev = usb_get_dev(udev); 150 dev->udev = usb_get_dev(udev);
151 dev->type = id->driver_info;
115 152
116 usb_set_intfdata (interface, dev); 153 usb_set_intfdata (interface, dev);
117 154
@@ -125,6 +162,31 @@ static int led_probe(struct usb_interface *interface, const struct usb_device_id
125 if (retval) 162 if (retval)
126 goto error; 163 goto error;
127 164
165 if (dev->type == DREAM_CHEEKY_WEBMAIL_NOTIFIER) {
166 unsigned char *enable;
167
168 enable = kmemdup("\x1f\x02\0\x5f\0\0\x1a\x03", 8, GFP_KERNEL);
169 if (!enable) {
170 dev_err(&interface->dev, "out of memory\n");
171 retval = -ENOMEM;
172 goto error;
173 }
174
175 retval = usb_control_msg(udev,
176 usb_sndctrlpipe(udev, 0),
177 0x09,
178 0x21,
179 0x200,
180 0,
181 enable,
182 8,
183 2000);
184
185 kfree(enable);
186 if (retval != 8)
187 goto error;
188 }
189
128 dev_info(&interface->dev, "USB LED device now attached\n"); 190 dev_info(&interface->dev, "USB LED device now attached\n");
129 return 0; 191 return 0;
130 192
diff --git a/drivers/usb/misc/usbsevseg.c b/drivers/usb/misc/usbsevseg.c
index de8ef945b536..417b8f207e8b 100644
--- a/drivers/usb/misc/usbsevseg.c
+++ b/drivers/usb/misc/usbsevseg.c
@@ -192,7 +192,7 @@ static ssize_t set_attr_##name(struct device *dev, \
192 \ 192 \
193 return count; \ 193 return count; \
194} \ 194} \
195static DEVICE_ATTR(name, S_IWUGO | S_IRUGO, show_attr_##name, set_attr_##name); 195static DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show_attr_##name, set_attr_##name);
196 196
197static ssize_t show_attr_text(struct device *dev, 197static ssize_t show_attr_text(struct device *dev,
198 struct device_attribute *attr, char *buf) 198 struct device_attribute *attr, char *buf)
@@ -223,7 +223,7 @@ static ssize_t set_attr_text(struct device *dev,
223 return count; 223 return count;
224} 224}
225 225
226static DEVICE_ATTR(text, S_IWUGO | S_IRUGO, show_attr_text, set_attr_text); 226static DEVICE_ATTR(text, S_IRUGO | S_IWUSR, show_attr_text, set_attr_text);
227 227
228static ssize_t show_attr_decimals(struct device *dev, 228static ssize_t show_attr_decimals(struct device *dev,
229 struct device_attribute *attr, char *buf) 229 struct device_attribute *attr, char *buf)
@@ -272,8 +272,7 @@ static ssize_t set_attr_decimals(struct device *dev,
272 return count; 272 return count;
273} 273}
274 274
275static DEVICE_ATTR(decimals, S_IWUGO | S_IRUGO, 275static DEVICE_ATTR(decimals, S_IRUGO | S_IWUSR, show_attr_decimals, set_attr_decimals);
276 show_attr_decimals, set_attr_decimals);
277 276
278static ssize_t show_attr_textmode(struct device *dev, 277static ssize_t show_attr_textmode(struct device *dev,
279 struct device_attribute *attr, char *buf) 278 struct device_attribute *attr, char *buf)
@@ -319,8 +318,7 @@ static ssize_t set_attr_textmode(struct device *dev,
319 return -EINVAL; 318 return -EINVAL;
320} 319}
321 320
322static DEVICE_ATTR(textmode, S_IWUGO | S_IRUGO, 321static DEVICE_ATTR(textmode, S_IRUGO | S_IWUSR, show_attr_textmode, set_attr_textmode);
323 show_attr_textmode, set_attr_textmode);
324 322
325 323
326MYDEV_ATTR_SIMPLE_UNSIGNED(powered, update_display_powered); 324MYDEV_ATTR_SIMPLE_UNSIGNED(powered, update_display_powered);
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index eef370eb7a54..bb10846affc3 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -13,17 +13,16 @@
13 13
14/*-------------------------------------------------------------------------*/ 14/*-------------------------------------------------------------------------*/
15 15
16// FIXME make these public somewhere; usbdevfs.h? 16/* FIXME make these public somewhere; usbdevfs.h? */
17//
18struct usbtest_param { 17struct usbtest_param {
19 // inputs 18 /* inputs */
20 unsigned test_num; /* 0..(TEST_CASES-1) */ 19 unsigned test_num; /* 0..(TEST_CASES-1) */
21 unsigned iterations; 20 unsigned iterations;
22 unsigned length; 21 unsigned length;
23 unsigned vary; 22 unsigned vary;
24 unsigned sglen; 23 unsigned sglen;
25 24
26 // outputs 25 /* outputs */
27 struct timeval duration; 26 struct timeval duration;
28}; 27};
29#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param) 28#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param)
@@ -45,9 +44,9 @@ struct usbtest_info {
45 const char *name; 44 const char *name;
46 u8 ep_in; /* bulk/intr source */ 45 u8 ep_in; /* bulk/intr source */
47 u8 ep_out; /* bulk/intr sink */ 46 u8 ep_out; /* bulk/intr sink */
48 unsigned autoconf : 1; 47 unsigned autoconf:1;
49 unsigned ctrl_out : 1; 48 unsigned ctrl_out:1;
50 unsigned iso : 1; /* try iso in/out */ 49 unsigned iso:1; /* try iso in/out */
51 int alt; 50 int alt;
52}; 51};
53 52
@@ -71,9 +70,9 @@ struct usbtest_dev {
71 u8 *buf; 70 u8 *buf;
72}; 71};
73 72
74static struct usb_device *testdev_to_usbdev (struct usbtest_dev *test) 73static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
75{ 74{
76 return interface_to_usbdev (test->intf); 75 return interface_to_usbdev(test->intf);
77} 76}
78 77
79/* set up all urbs so they can be used with either bulk or interrupt */ 78/* set up all urbs so they can be used with either bulk or interrupt */
@@ -84,10 +83,12 @@ static struct usb_device *testdev_to_usbdev (struct usbtest_dev *test)
84#define WARNING(tdev, fmt, args...) \ 83#define WARNING(tdev, fmt, args...) \
85 dev_warn(&(tdev)->intf->dev , fmt , ## args) 84 dev_warn(&(tdev)->intf->dev , fmt , ## args)
86 85
86#define GUARD_BYTE 0xA5
87
87/*-------------------------------------------------------------------------*/ 88/*-------------------------------------------------------------------------*/
88 89
89static int 90static int
90get_endpoints (struct usbtest_dev *dev, struct usb_interface *intf) 91get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
91{ 92{
92 int tmp; 93 int tmp;
93 struct usb_host_interface *alt; 94 struct usb_host_interface *alt;
@@ -103,7 +104,7 @@ get_endpoints (struct usbtest_dev *dev, struct usb_interface *intf)
103 alt = intf->altsetting + tmp; 104 alt = intf->altsetting + tmp;
104 105
105 /* take the first altsetting with in-bulk + out-bulk; 106 /* take the first altsetting with in-bulk + out-bulk;
106 * ignore other endpoints and altsetttings. 107 * ignore other endpoints and altsettings.
107 */ 108 */
108 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { 109 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
109 struct usb_host_endpoint *e; 110 struct usb_host_endpoint *e;
@@ -115,7 +116,7 @@ get_endpoints (struct usbtest_dev *dev, struct usb_interface *intf)
115 case USB_ENDPOINT_XFER_ISOC: 116 case USB_ENDPOINT_XFER_ISOC:
116 if (dev->info->iso) 117 if (dev->info->iso)
117 goto try_iso; 118 goto try_iso;
118 // FALLTHROUGH 119 /* FALLTHROUGH */
119 default: 120 default:
120 continue; 121 continue;
121 } 122 }
@@ -142,9 +143,9 @@ try_iso:
142 return -EINVAL; 143 return -EINVAL;
143 144
144found: 145found:
145 udev = testdev_to_usbdev (dev); 146 udev = testdev_to_usbdev(dev);
146 if (alt->desc.bAlternateSetting != 0) { 147 if (alt->desc.bAlternateSetting != 0) {
147 tmp = usb_set_interface (udev, 148 tmp = usb_set_interface(udev,
148 alt->desc.bInterfaceNumber, 149 alt->desc.bInterfaceNumber,
149 alt->desc.bAlternateSetting); 150 alt->desc.bAlternateSetting);
150 if (tmp < 0) 151 if (tmp < 0)
@@ -152,21 +153,21 @@ found:
152 } 153 }
153 154
154 if (in) { 155 if (in) {
155 dev->in_pipe = usb_rcvbulkpipe (udev, 156 dev->in_pipe = usb_rcvbulkpipe(udev,
156 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 157 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
157 dev->out_pipe = usb_sndbulkpipe (udev, 158 dev->out_pipe = usb_sndbulkpipe(udev,
158 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 159 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
159 } 160 }
160 if (iso_in) { 161 if (iso_in) {
161 dev->iso_in = &iso_in->desc; 162 dev->iso_in = &iso_in->desc;
162 dev->in_iso_pipe = usb_rcvisocpipe (udev, 163 dev->in_iso_pipe = usb_rcvisocpipe(udev,
163 iso_in->desc.bEndpointAddress 164 iso_in->desc.bEndpointAddress
164 & USB_ENDPOINT_NUMBER_MASK); 165 & USB_ENDPOINT_NUMBER_MASK);
165 } 166 }
166 167
167 if (iso_out) { 168 if (iso_out) {
168 dev->iso_out = &iso_out->desc; 169 dev->iso_out = &iso_out->desc;
169 dev->out_iso_pipe = usb_sndisocpipe (udev, 170 dev->out_iso_pipe = usb_sndisocpipe(udev,
170 iso_out->desc.bEndpointAddress 171 iso_out->desc.bEndpointAddress
171 & USB_ENDPOINT_NUMBER_MASK); 172 & USB_ENDPOINT_NUMBER_MASK);
172 } 173 }
@@ -182,45 +183,73 @@ found:
182 * them with non-zero test data (or test for it) when appropriate. 183 * them with non-zero test data (or test for it) when appropriate.
183 */ 184 */
184 185
185static void simple_callback (struct urb *urb) 186static void simple_callback(struct urb *urb)
186{ 187{
187 complete(urb->context); 188 complete(urb->context);
188} 189}
189 190
190static struct urb *simple_alloc_urb ( 191static struct urb *usbtest_alloc_urb(
191 struct usb_device *udev, 192 struct usb_device *udev,
192 int pipe, 193 int pipe,
193 unsigned long bytes 194 unsigned long bytes,
194) 195 unsigned transfer_flags,
196 unsigned offset)
195{ 197{
196 struct urb *urb; 198 struct urb *urb;
197 199
198 urb = usb_alloc_urb (0, GFP_KERNEL); 200 urb = usb_alloc_urb(0, GFP_KERNEL);
199 if (!urb) 201 if (!urb)
200 return urb; 202 return urb;
201 usb_fill_bulk_urb (urb, udev, pipe, NULL, bytes, simple_callback, NULL); 203 usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, NULL);
202 urb->interval = (udev->speed == USB_SPEED_HIGH) 204 urb->interval = (udev->speed == USB_SPEED_HIGH)
203 ? (INTERRUPT_RATE << 3) 205 ? (INTERRUPT_RATE << 3)
204 : INTERRUPT_RATE; 206 : INTERRUPT_RATE;
205 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 207 urb->transfer_flags = transfer_flags;
206 if (usb_pipein (pipe)) 208 if (usb_pipein(pipe))
207 urb->transfer_flags |= URB_SHORT_NOT_OK; 209 urb->transfer_flags |= URB_SHORT_NOT_OK;
208 urb->transfer_buffer = usb_alloc_coherent (udev, bytes, GFP_KERNEL, 210
209 &urb->transfer_dma); 211 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
212 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
213 GFP_KERNEL, &urb->transfer_dma);
214 else
215 urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL);
216
210 if (!urb->transfer_buffer) { 217 if (!urb->transfer_buffer) {
211 usb_free_urb (urb); 218 usb_free_urb(urb);
212 urb = NULL; 219 return NULL;
213 } else 220 }
214 memset (urb->transfer_buffer, 0, bytes); 221
222 /* To test unaligned transfers add an offset and fill the
223 unused memory with a guard value */
224 if (offset) {
225 memset(urb->transfer_buffer, GUARD_BYTE, offset);
226 urb->transfer_buffer += offset;
227 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
228 urb->transfer_dma += offset;
229 }
230
231 /* For inbound transfers use guard byte so that test fails if
232 data not correctly copied */
233 memset(urb->transfer_buffer,
234 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
235 bytes);
215 return urb; 236 return urb;
216} 237}
217 238
218static unsigned pattern = 0; 239static struct urb *simple_alloc_urb(
240 struct usb_device *udev,
241 int pipe,
242 unsigned long bytes)
243{
244 return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0);
245}
246
247static unsigned pattern;
219static unsigned mod_pattern; 248static unsigned mod_pattern;
220module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR); 249module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR);
221MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)"); 250MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)");
222 251
223static inline void simple_fill_buf (struct urb *urb) 252static inline void simple_fill_buf(struct urb *urb)
224{ 253{
225 unsigned i; 254 unsigned i;
226 u8 *buf = urb->transfer_buffer; 255 u8 *buf = urb->transfer_buffer;
@@ -228,9 +257,9 @@ static inline void simple_fill_buf (struct urb *urb)
228 257
229 switch (pattern) { 258 switch (pattern) {
230 default: 259 default:
231 // FALLTHROUGH 260 /* FALLTHROUGH */
232 case 0: 261 case 0:
233 memset (buf, 0, len); 262 memset(buf, 0, len);
234 break; 263 break;
235 case 1: /* mod63 */ 264 case 1: /* mod63 */
236 for (i = 0; i < len; i++) 265 for (i = 0; i < len; i++)
@@ -239,13 +268,38 @@ static inline void simple_fill_buf (struct urb *urb)
239 } 268 }
240} 269}
241 270
242static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb) 271static inline unsigned long buffer_offset(void *buf)
272{
273 return (unsigned long)buf & (ARCH_KMALLOC_MINALIGN - 1);
274}
275
276static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb)
277{
278 u8 *buf = urb->transfer_buffer;
279 u8 *guard = buf - buffer_offset(buf);
280 unsigned i;
281
282 for (i = 0; guard < buf; i++, guard++) {
283 if (*guard != GUARD_BYTE) {
284 ERROR(tdev, "guard byte[%d] %d (not %d)\n",
285 i, *guard, GUARD_BYTE);
286 return -EINVAL;
287 }
288 }
289 return 0;
290}
291
292static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
243{ 293{
244 unsigned i; 294 unsigned i;
245 u8 expected; 295 u8 expected;
246 u8 *buf = urb->transfer_buffer; 296 u8 *buf = urb->transfer_buffer;
247 unsigned len = urb->actual_length; 297 unsigned len = urb->actual_length;
248 298
299 int ret = check_guard_bytes(tdev, urb);
300 if (ret)
301 return ret;
302
249 for (i = 0; i < len; i++, buf++) { 303 for (i = 0; i < len; i++, buf++) {
250 switch (pattern) { 304 switch (pattern) {
251 /* all-zeroes has no synchronization issues */ 305 /* all-zeroes has no synchronization issues */
@@ -273,14 +327,22 @@ static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
273 return 0; 327 return 0;
274} 328}
275 329
276static void simple_free_urb (struct urb *urb) 330static void simple_free_urb(struct urb *urb)
277{ 331{
278 usb_free_coherent(urb->dev, urb->transfer_buffer_length, 332 unsigned long offset = buffer_offset(urb->transfer_buffer);
279 urb->transfer_buffer, urb->transfer_dma); 333
280 usb_free_urb (urb); 334 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
335 usb_free_coherent(
336 urb->dev,
337 urb->transfer_buffer_length + offset,
338 urb->transfer_buffer - offset,
339 urb->transfer_dma - offset);
340 else
341 kfree(urb->transfer_buffer - offset);
342 usb_free_urb(urb);
281} 343}
282 344
283static int simple_io ( 345static int simple_io(
284 struct usbtest_dev *tdev, 346 struct usbtest_dev *tdev,
285 struct urb *urb, 347 struct urb *urb,
286 int iterations, 348 int iterations,
@@ -296,17 +358,18 @@ static int simple_io (
296 358
297 urb->context = &completion; 359 urb->context = &completion;
298 while (retval == 0 && iterations-- > 0) { 360 while (retval == 0 && iterations-- > 0) {
299 init_completion (&completion); 361 init_completion(&completion);
300 if (usb_pipeout (urb->pipe)) 362 if (usb_pipeout(urb->pipe))
301 simple_fill_buf (urb); 363 simple_fill_buf(urb);
302 if ((retval = usb_submit_urb (urb, GFP_KERNEL)) != 0) 364 retval = usb_submit_urb(urb, GFP_KERNEL);
365 if (retval != 0)
303 break; 366 break;
304 367
305 /* NOTE: no timeouts; can't be broken out of by interrupt */ 368 /* NOTE: no timeouts; can't be broken out of by interrupt */
306 wait_for_completion (&completion); 369 wait_for_completion(&completion);
307 retval = urb->status; 370 retval = urb->status;
308 urb->dev = udev; 371 urb->dev = udev;
309 if (retval == 0 && usb_pipein (urb->pipe)) 372 if (retval == 0 && usb_pipein(urb->pipe))
310 retval = simple_check_buf(tdev, urb); 373 retval = simple_check_buf(tdev, urb);
311 374
312 if (vary) { 375 if (vary) {
@@ -337,7 +400,7 @@ static int simple_io (
337 * Yes, this also tests the scatterlist primitives. 400 * Yes, this also tests the scatterlist primitives.
338 */ 401 */
339 402
340static void free_sglist (struct scatterlist *sg, int nents) 403static void free_sglist(struct scatterlist *sg, int nents)
341{ 404{
342 unsigned i; 405 unsigned i;
343 406
@@ -346,19 +409,19 @@ static void free_sglist (struct scatterlist *sg, int nents)
346 for (i = 0; i < nents; i++) { 409 for (i = 0; i < nents; i++) {
347 if (!sg_page(&sg[i])) 410 if (!sg_page(&sg[i]))
348 continue; 411 continue;
349 kfree (sg_virt(&sg[i])); 412 kfree(sg_virt(&sg[i]));
350 } 413 }
351 kfree (sg); 414 kfree(sg);
352} 415}
353 416
354static struct scatterlist * 417static struct scatterlist *
355alloc_sglist (int nents, int max, int vary) 418alloc_sglist(int nents, int max, int vary)
356{ 419{
357 struct scatterlist *sg; 420 struct scatterlist *sg;
358 unsigned i; 421 unsigned i;
359 unsigned size = max; 422 unsigned size = max;
360 423
361 sg = kmalloc (nents * sizeof *sg, GFP_KERNEL); 424 sg = kmalloc(nents * sizeof *sg, GFP_KERNEL);
362 if (!sg) 425 if (!sg)
363 return NULL; 426 return NULL;
364 sg_init_table(sg, nents); 427 sg_init_table(sg, nents);
@@ -367,9 +430,9 @@ alloc_sglist (int nents, int max, int vary)
367 char *buf; 430 char *buf;
368 unsigned j; 431 unsigned j;
369 432
370 buf = kzalloc (size, GFP_KERNEL); 433 buf = kzalloc(size, GFP_KERNEL);
371 if (!buf) { 434 if (!buf) {
372 free_sglist (sg, i); 435 free_sglist(sg, i);
373 return NULL; 436 return NULL;
374 } 437 }
375 438
@@ -397,7 +460,7 @@ alloc_sglist (int nents, int max, int vary)
397 return sg; 460 return sg;
398} 461}
399 462
400static int perform_sglist ( 463static int perform_sglist(
401 struct usbtest_dev *tdev, 464 struct usbtest_dev *tdev,
402 unsigned iterations, 465 unsigned iterations,
403 int pipe, 466 int pipe,
@@ -410,7 +473,7 @@ static int perform_sglist (
410 int retval = 0; 473 int retval = 0;
411 474
412 while (retval == 0 && iterations-- > 0) { 475 while (retval == 0 && iterations-- > 0) {
413 retval = usb_sg_init (req, udev, pipe, 476 retval = usb_sg_init(req, udev, pipe,
414 (udev->speed == USB_SPEED_HIGH) 477 (udev->speed == USB_SPEED_HIGH)
415 ? (INTERRUPT_RATE << 3) 478 ? (INTERRUPT_RATE << 3)
416 : INTERRUPT_RATE, 479 : INTERRUPT_RATE,
@@ -418,7 +481,7 @@ static int perform_sglist (
418 481
419 if (retval) 482 if (retval)
420 break; 483 break;
421 usb_sg_wait (req); 484 usb_sg_wait(req);
422 retval = req->status; 485 retval = req->status;
423 486
424 /* FIXME check resulting data pattern */ 487 /* FIXME check resulting data pattern */
@@ -426,9 +489,9 @@ static int perform_sglist (
426 /* FIXME if endpoint halted, clear halt (and log) */ 489 /* FIXME if endpoint halted, clear halt (and log) */
427 } 490 }
428 491
429 // FIXME for unlink or fault handling tests, don't report 492 /* FIXME for unlink or fault handling tests, don't report
430 // failure if retval is as we expected ... 493 * failure if retval is as we expected ...
431 494 */
432 if (retval) 495 if (retval)
433 ERROR(tdev, "perform_sglist failed, " 496 ERROR(tdev, "perform_sglist failed, "
434 "iterations left %d, status %d\n", 497 "iterations left %d, status %d\n",
@@ -452,31 +515,31 @@ static int perform_sglist (
452 */ 515 */
453 516
454static unsigned realworld = 1; 517static unsigned realworld = 1;
455module_param (realworld, uint, 0); 518module_param(realworld, uint, 0);
456MODULE_PARM_DESC (realworld, "clear to demand stricter spec compliance"); 519MODULE_PARM_DESC(realworld, "clear to demand stricter spec compliance");
457 520
458static int get_altsetting (struct usbtest_dev *dev) 521static int get_altsetting(struct usbtest_dev *dev)
459{ 522{
460 struct usb_interface *iface = dev->intf; 523 struct usb_interface *iface = dev->intf;
461 struct usb_device *udev = interface_to_usbdev (iface); 524 struct usb_device *udev = interface_to_usbdev(iface);
462 int retval; 525 int retval;
463 526
464 retval = usb_control_msg (udev, usb_rcvctrlpipe (udev, 0), 527 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
465 USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE, 528 USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE,
466 0, iface->altsetting [0].desc.bInterfaceNumber, 529 0, iface->altsetting[0].desc.bInterfaceNumber,
467 dev->buf, 1, USB_CTRL_GET_TIMEOUT); 530 dev->buf, 1, USB_CTRL_GET_TIMEOUT);
468 switch (retval) { 531 switch (retval) {
469 case 1: 532 case 1:
470 return dev->buf [0]; 533 return dev->buf[0];
471 case 0: 534 case 0:
472 retval = -ERANGE; 535 retval = -ERANGE;
473 // FALLTHROUGH 536 /* FALLTHROUGH */
474 default: 537 default:
475 return retval; 538 return retval;
476 } 539 }
477} 540}
478 541
479static int set_altsetting (struct usbtest_dev *dev, int alternate) 542static int set_altsetting(struct usbtest_dev *dev, int alternate)
480{ 543{
481 struct usb_interface *iface = dev->intf; 544 struct usb_interface *iface = dev->intf;
482 struct usb_device *udev; 545 struct usb_device *udev;
@@ -484,9 +547,9 @@ static int set_altsetting (struct usbtest_dev *dev, int alternate)
484 if (alternate < 0 || alternate >= 256) 547 if (alternate < 0 || alternate >= 256)
485 return -EINVAL; 548 return -EINVAL;
486 549
487 udev = interface_to_usbdev (iface); 550 udev = interface_to_usbdev(iface);
488 return usb_set_interface (udev, 551 return usb_set_interface(udev,
489 iface->altsetting [0].desc.bInterfaceNumber, 552 iface->altsetting[0].desc.bInterfaceNumber,
490 alternate); 553 alternate);
491} 554}
492 555
@@ -519,9 +582,9 @@ static int is_good_config(struct usbtest_dev *tdev, int len)
519 return 0; 582 return 0;
520 } 583 }
521 584
522 if (le16_to_cpu(config->wTotalLength) == len) /* read it all */ 585 if (le16_to_cpu(config->wTotalLength) == len) /* read it all */
523 return 1; 586 return 1;
524 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */ 587 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */
525 return 1; 588 return 1;
526 ERROR(tdev, "bogus config descriptor read size\n"); 589 ERROR(tdev, "bogus config descriptor read size\n");
527 return 0; 590 return 0;
@@ -542,10 +605,10 @@ static int is_good_config(struct usbtest_dev *tdev, int len)
542 * to see if usbcore, hcd, and device all behave right. such testing would 605 * to see if usbcore, hcd, and device all behave right. such testing would
543 * involve varied read sizes and other operation sequences. 606 * involve varied read sizes and other operation sequences.
544 */ 607 */
545static int ch9_postconfig (struct usbtest_dev *dev) 608static int ch9_postconfig(struct usbtest_dev *dev)
546{ 609{
547 struct usb_interface *iface = dev->intf; 610 struct usb_interface *iface = dev->intf;
548 struct usb_device *udev = interface_to_usbdev (iface); 611 struct usb_device *udev = interface_to_usbdev(iface);
549 int i, alt, retval; 612 int i, alt, retval;
550 613
551 /* [9.2.3] if there's more than one altsetting, we need to be able to 614 /* [9.2.3] if there's more than one altsetting, we need to be able to
@@ -554,7 +617,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
554 for (i = 0; i < iface->num_altsetting; i++) { 617 for (i = 0; i < iface->num_altsetting; i++) {
555 618
556 /* 9.2.3 constrains the range here */ 619 /* 9.2.3 constrains the range here */
557 alt = iface->altsetting [i].desc.bAlternateSetting; 620 alt = iface->altsetting[i].desc.bAlternateSetting;
558 if (alt < 0 || alt >= iface->num_altsetting) { 621 if (alt < 0 || alt >= iface->num_altsetting) {
559 dev_err(&iface->dev, 622 dev_err(&iface->dev,
560 "invalid alt [%d].bAltSetting = %d\n", 623 "invalid alt [%d].bAltSetting = %d\n",
@@ -566,7 +629,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
566 continue; 629 continue;
567 630
568 /* [9.4.10] set_interface */ 631 /* [9.4.10] set_interface */
569 retval = set_altsetting (dev, alt); 632 retval = set_altsetting(dev, alt);
570 if (retval) { 633 if (retval) {
571 dev_err(&iface->dev, "can't set_interface = %d, %d\n", 634 dev_err(&iface->dev, "can't set_interface = %d, %d\n",
572 alt, retval); 635 alt, retval);
@@ -574,7 +637,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
574 } 637 }
575 638
576 /* [9.4.4] get_interface always works */ 639 /* [9.4.4] get_interface always works */
577 retval = get_altsetting (dev); 640 retval = get_altsetting(dev);
578 if (retval != alt) { 641 if (retval != alt) {
579 dev_err(&iface->dev, "get alt should be %d, was %d\n", 642 dev_err(&iface->dev, "get alt should be %d, was %d\n",
580 alt, retval); 643 alt, retval);
@@ -591,11 +654,11 @@ static int ch9_postconfig (struct usbtest_dev *dev)
591 * ... although some cheap devices (like one TI Hub I've got) 654 * ... although some cheap devices (like one TI Hub I've got)
592 * won't return config descriptors except before set_config. 655 * won't return config descriptors except before set_config.
593 */ 656 */
594 retval = usb_control_msg (udev, usb_rcvctrlpipe (udev, 0), 657 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
595 USB_REQ_GET_CONFIGURATION, 658 USB_REQ_GET_CONFIGURATION,
596 USB_DIR_IN | USB_RECIP_DEVICE, 659 USB_DIR_IN | USB_RECIP_DEVICE,
597 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); 660 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT);
598 if (retval != 1 || dev->buf [0] != expected) { 661 if (retval != 1 || dev->buf[0] != expected) {
599 dev_err(&iface->dev, "get config --> %d %d (1 %d)\n", 662 dev_err(&iface->dev, "get config --> %d %d (1 %d)\n",
600 retval, dev->buf[0], expected); 663 retval, dev->buf[0], expected);
601 return (retval < 0) ? retval : -EDOM; 664 return (retval < 0) ? retval : -EDOM;
@@ -603,7 +666,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
603 } 666 }
604 667
605 /* there's always [9.4.3] a device descriptor [9.6.1] */ 668 /* there's always [9.4.3] a device descriptor [9.6.1] */
606 retval = usb_get_descriptor (udev, USB_DT_DEVICE, 0, 669 retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0,
607 dev->buf, sizeof udev->descriptor); 670 dev->buf, sizeof udev->descriptor);
608 if (retval != sizeof udev->descriptor) { 671 if (retval != sizeof udev->descriptor) {
609 dev_err(&iface->dev, "dev descriptor --> %d\n", retval); 672 dev_err(&iface->dev, "dev descriptor --> %d\n", retval);
@@ -612,7 +675,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
612 675
613 /* there's always [9.4.3] at least one config descriptor [9.6.3] */ 676 /* there's always [9.4.3] at least one config descriptor [9.6.3] */
614 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { 677 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) {
615 retval = usb_get_descriptor (udev, USB_DT_CONFIG, i, 678 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i,
616 dev->buf, TBUF_SIZE); 679 dev->buf, TBUF_SIZE);
617 if (!is_good_config(dev, retval)) { 680 if (!is_good_config(dev, retval)) {
618 dev_err(&iface->dev, 681 dev_err(&iface->dev,
@@ -621,18 +684,19 @@ static int ch9_postconfig (struct usbtest_dev *dev)
621 return (retval < 0) ? retval : -EDOM; 684 return (retval < 0) ? retval : -EDOM;
622 } 685 }
623 686
624 // FIXME cross-checking udev->config[i] to make sure usbcore 687 /* FIXME cross-checking udev->config[i] to make sure usbcore
625 // parsed it right (etc) would be good testing paranoia 688 * parsed it right (etc) would be good testing paranoia
689 */
626 } 690 }
627 691
628 /* and sometimes [9.2.6.6] speed dependent descriptors */ 692 /* and sometimes [9.2.6.6] speed dependent descriptors */
629 if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) { 693 if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) {
630 struct usb_qualifier_descriptor *d = NULL; 694 struct usb_qualifier_descriptor *d = NULL;
631 695
632 /* device qualifier [9.6.2] */ 696 /* device qualifier [9.6.2] */
633 retval = usb_get_descriptor (udev, 697 retval = usb_get_descriptor(udev,
634 USB_DT_DEVICE_QUALIFIER, 0, dev->buf, 698 USB_DT_DEVICE_QUALIFIER, 0, dev->buf,
635 sizeof (struct usb_qualifier_descriptor)); 699 sizeof(struct usb_qualifier_descriptor));
636 if (retval == -EPIPE) { 700 if (retval == -EPIPE) {
637 if (udev->speed == USB_SPEED_HIGH) { 701 if (udev->speed == USB_SPEED_HIGH) {
638 dev_err(&iface->dev, 702 dev_err(&iface->dev,
@@ -641,7 +705,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
641 return (retval < 0) ? retval : -EDOM; 705 return (retval < 0) ? retval : -EDOM;
642 } 706 }
643 /* usb2.0 but not high-speed capable; fine */ 707 /* usb2.0 but not high-speed capable; fine */
644 } else if (retval != sizeof (struct usb_qualifier_descriptor)) { 708 } else if (retval != sizeof(struct usb_qualifier_descriptor)) {
645 dev_err(&iface->dev, "dev qualifier --> %d\n", retval); 709 dev_err(&iface->dev, "dev qualifier --> %d\n", retval);
646 return (retval < 0) ? retval : -EDOM; 710 return (retval < 0) ? retval : -EDOM;
647 } else 711 } else
@@ -651,7 +715,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
651 if (d) { 715 if (d) {
652 unsigned max = d->bNumConfigurations; 716 unsigned max = d->bNumConfigurations;
653 for (i = 0; i < max; i++) { 717 for (i = 0; i < max; i++) {
654 retval = usb_get_descriptor (udev, 718 retval = usb_get_descriptor(udev,
655 USB_DT_OTHER_SPEED_CONFIG, i, 719 USB_DT_OTHER_SPEED_CONFIG, i,
656 dev->buf, TBUF_SIZE); 720 dev->buf, TBUF_SIZE);
657 if (!is_good_config(dev, retval)) { 721 if (!is_good_config(dev, retval)) {
@@ -663,25 +727,26 @@ static int ch9_postconfig (struct usbtest_dev *dev)
663 } 727 }
664 } 728 }
665 } 729 }
666 // FIXME fetch strings from at least the device descriptor 730 /* FIXME fetch strings from at least the device descriptor */
667 731
668 /* [9.4.5] get_status always works */ 732 /* [9.4.5] get_status always works */
669 retval = usb_get_status (udev, USB_RECIP_DEVICE, 0, dev->buf); 733 retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf);
670 if (retval != 2) { 734 if (retval != 2) {
671 dev_err(&iface->dev, "get dev status --> %d\n", retval); 735 dev_err(&iface->dev, "get dev status --> %d\n", retval);
672 return (retval < 0) ? retval : -EDOM; 736 return (retval < 0) ? retval : -EDOM;
673 } 737 }
674 738
675 // FIXME configuration.bmAttributes says if we could try to set/clear 739 /* FIXME configuration.bmAttributes says if we could try to set/clear
676 // the device's remote wakeup feature ... if we can, test that here 740 * the device's remote wakeup feature ... if we can, test that here
741 */
677 742
678 retval = usb_get_status (udev, USB_RECIP_INTERFACE, 743 retval = usb_get_status(udev, USB_RECIP_INTERFACE,
679 iface->altsetting [0].desc.bInterfaceNumber, dev->buf); 744 iface->altsetting[0].desc.bInterfaceNumber, dev->buf);
680 if (retval != 2) { 745 if (retval != 2) {
681 dev_err(&iface->dev, "get interface status --> %d\n", retval); 746 dev_err(&iface->dev, "get interface status --> %d\n", retval);
682 return (retval < 0) ? retval : -EDOM; 747 return (retval < 0) ? retval : -EDOM;
683 } 748 }
684 // FIXME get status for each endpoint in the interface 749 /* FIXME get status for each endpoint in the interface */
685 750
686 return 0; 751 return 0;
687} 752}
@@ -717,7 +782,7 @@ struct subcase {
717 int expected; 782 int expected;
718}; 783};
719 784
720static void ctrl_complete (struct urb *urb) 785static void ctrl_complete(struct urb *urb)
721{ 786{
722 struct ctrl_ctx *ctx = urb->context; 787 struct ctrl_ctx *ctx = urb->context;
723 struct usb_ctrlrequest *reqp; 788 struct usb_ctrlrequest *reqp;
@@ -725,9 +790,9 @@ static void ctrl_complete (struct urb *urb)
725 int status = urb->status; 790 int status = urb->status;
726 791
727 reqp = (struct usb_ctrlrequest *)urb->setup_packet; 792 reqp = (struct usb_ctrlrequest *)urb->setup_packet;
728 subcase = container_of (reqp, struct subcase, setup); 793 subcase = container_of(reqp, struct subcase, setup);
729 794
730 spin_lock (&ctx->lock); 795 spin_lock(&ctx->lock);
731 ctx->count--; 796 ctx->count--;
732 ctx->pending--; 797 ctx->pending--;
733 798
@@ -787,14 +852,14 @@ error:
787 852
788 /* unlink whatever's still pending */ 853 /* unlink whatever's still pending */
789 for (i = 1; i < ctx->param->sglen; i++) { 854 for (i = 1; i < ctx->param->sglen; i++) {
790 struct urb *u = ctx->urb [ 855 struct urb *u = ctx->urb[
791 (i + subcase->number) 856 (i + subcase->number)
792 % ctx->param->sglen]; 857 % ctx->param->sglen];
793 858
794 if (u == urb || !u->dev) 859 if (u == urb || !u->dev)
795 continue; 860 continue;
796 spin_unlock(&ctx->lock); 861 spin_unlock(&ctx->lock);
797 status = usb_unlink_urb (u); 862 status = usb_unlink_urb(u);
798 spin_lock(&ctx->lock); 863 spin_lock(&ctx->lock);
799 switch (status) { 864 switch (status) {
800 case -EINPROGRESS: 865 case -EINPROGRESS:
@@ -812,7 +877,8 @@ error:
812 877
813 /* resubmit if we need to, else mark this as done */ 878 /* resubmit if we need to, else mark this as done */
814 if ((status == 0) && (ctx->pending < ctx->count)) { 879 if ((status == 0) && (ctx->pending < ctx->count)) {
815 if ((status = usb_submit_urb (urb, GFP_ATOMIC)) != 0) { 880 status = usb_submit_urb(urb, GFP_ATOMIC);
881 if (status != 0) {
816 ERROR(ctx->dev, 882 ERROR(ctx->dev,
817 "can't resubmit ctrl %02x.%02x, err %d\n", 883 "can't resubmit ctrl %02x.%02x, err %d\n",
818 reqp->bRequestType, reqp->bRequest, status); 884 reqp->bRequestType, reqp->bRequest, status);
@@ -824,21 +890,21 @@ error:
824 890
825 /* signal completion when nothing's queued */ 891 /* signal completion when nothing's queued */
826 if (ctx->pending == 0) 892 if (ctx->pending == 0)
827 complete (&ctx->complete); 893 complete(&ctx->complete);
828 spin_unlock (&ctx->lock); 894 spin_unlock(&ctx->lock);
829} 895}
830 896
831static int 897static int
832test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param) 898test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
833{ 899{
834 struct usb_device *udev = testdev_to_usbdev (dev); 900 struct usb_device *udev = testdev_to_usbdev(dev);
835 struct urb **urb; 901 struct urb **urb;
836 struct ctrl_ctx context; 902 struct ctrl_ctx context;
837 int i; 903 int i;
838 904
839 spin_lock_init (&context.lock); 905 spin_lock_init(&context.lock);
840 context.dev = dev; 906 context.dev = dev;
841 init_completion (&context.complete); 907 init_completion(&context.complete);
842 context.count = param->sglen * param->iterations; 908 context.count = param->sglen * param->iterations;
843 context.pending = 0; 909 context.pending = 0;
844 context.status = -ENOMEM; 910 context.status = -ENOMEM;
@@ -853,7 +919,7 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
853 if (!urb) 919 if (!urb)
854 return -ENOMEM; 920 return -ENOMEM;
855 for (i = 0; i < param->sglen; i++) { 921 for (i = 0; i < param->sglen; i++) {
856 int pipe = usb_rcvctrlpipe (udev, 0); 922 int pipe = usb_rcvctrlpipe(udev, 0);
857 unsigned len; 923 unsigned len;
858 struct urb *u; 924 struct urb *u;
859 struct usb_ctrlrequest req; 925 struct usb_ctrlrequest req;
@@ -869,104 +935,110 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
869 * device, but some are chosen to trigger protocol stalls 935 * device, but some are chosen to trigger protocol stalls
870 * or short reads. 936 * or short reads.
871 */ 937 */
872 memset (&req, 0, sizeof req); 938 memset(&req, 0, sizeof req);
873 req.bRequest = USB_REQ_GET_DESCRIPTOR; 939 req.bRequest = USB_REQ_GET_DESCRIPTOR;
874 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 940 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
875 941
876 switch (i % NUM_SUBCASES) { 942 switch (i % NUM_SUBCASES) {
877 case 0: // get device descriptor 943 case 0: /* get device descriptor */
878 req.wValue = cpu_to_le16 (USB_DT_DEVICE << 8); 944 req.wValue = cpu_to_le16(USB_DT_DEVICE << 8);
879 len = sizeof (struct usb_device_descriptor); 945 len = sizeof(struct usb_device_descriptor);
880 break; 946 break;
881 case 1: // get first config descriptor (only) 947 case 1: /* get first config descriptor (only) */
882 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 948 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
883 len = sizeof (struct usb_config_descriptor); 949 len = sizeof(struct usb_config_descriptor);
884 break; 950 break;
885 case 2: // get altsetting (OFTEN STALLS) 951 case 2: /* get altsetting (OFTEN STALLS) */
886 req.bRequest = USB_REQ_GET_INTERFACE; 952 req.bRequest = USB_REQ_GET_INTERFACE;
887 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; 953 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
888 // index = 0 means first interface 954 /* index = 0 means first interface */
889 len = 1; 955 len = 1;
890 expected = EPIPE; 956 expected = EPIPE;
891 break; 957 break;
892 case 3: // get interface status 958 case 3: /* get interface status */
893 req.bRequest = USB_REQ_GET_STATUS; 959 req.bRequest = USB_REQ_GET_STATUS;
894 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; 960 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
895 // interface 0 961 /* interface 0 */
896 len = 2; 962 len = 2;
897 break; 963 break;
898 case 4: // get device status 964 case 4: /* get device status */
899 req.bRequest = USB_REQ_GET_STATUS; 965 req.bRequest = USB_REQ_GET_STATUS;
900 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 966 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
901 len = 2; 967 len = 2;
902 break; 968 break;
903 case 5: // get device qualifier (MAY STALL) 969 case 5: /* get device qualifier (MAY STALL) */
904 req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8); 970 req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8);
905 len = sizeof (struct usb_qualifier_descriptor); 971 len = sizeof(struct usb_qualifier_descriptor);
906 if (udev->speed != USB_SPEED_HIGH) 972 if (udev->speed != USB_SPEED_HIGH)
907 expected = EPIPE; 973 expected = EPIPE;
908 break; 974 break;
909 case 6: // get first config descriptor, plus interface 975 case 6: /* get first config descriptor, plus interface */
910 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 976 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
911 len = sizeof (struct usb_config_descriptor); 977 len = sizeof(struct usb_config_descriptor);
912 len += sizeof (struct usb_interface_descriptor); 978 len += sizeof(struct usb_interface_descriptor);
913 break; 979 break;
914 case 7: // get interface descriptor (ALWAYS STALLS) 980 case 7: /* get interface descriptor (ALWAYS STALLS) */
915 req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8); 981 req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8);
916 // interface == 0 982 /* interface == 0 */
917 len = sizeof (struct usb_interface_descriptor); 983 len = sizeof(struct usb_interface_descriptor);
918 expected = -EPIPE; 984 expected = -EPIPE;
919 break; 985 break;
920 // NOTE: two consecutive stalls in the queue here. 986 /* NOTE: two consecutive stalls in the queue here.
921 // that tests fault recovery a bit more aggressively. 987 * that tests fault recovery a bit more aggressively. */
922 case 8: // clear endpoint halt (MAY STALL) 988 case 8: /* clear endpoint halt (MAY STALL) */
923 req.bRequest = USB_REQ_CLEAR_FEATURE; 989 req.bRequest = USB_REQ_CLEAR_FEATURE;
924 req.bRequestType = USB_RECIP_ENDPOINT; 990 req.bRequestType = USB_RECIP_ENDPOINT;
925 // wValue 0 == ep halt 991 /* wValue 0 == ep halt */
926 // wIndex 0 == ep0 (shouldn't halt!) 992 /* wIndex 0 == ep0 (shouldn't halt!) */
927 len = 0; 993 len = 0;
928 pipe = usb_sndctrlpipe (udev, 0); 994 pipe = usb_sndctrlpipe(udev, 0);
929 expected = EPIPE; 995 expected = EPIPE;
930 break; 996 break;
931 case 9: // get endpoint status 997 case 9: /* get endpoint status */
932 req.bRequest = USB_REQ_GET_STATUS; 998 req.bRequest = USB_REQ_GET_STATUS;
933 req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT; 999 req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT;
934 // endpoint 0 1000 /* endpoint 0 */
935 len = 2; 1001 len = 2;
936 break; 1002 break;
937 case 10: // trigger short read (EREMOTEIO) 1003 case 10: /* trigger short read (EREMOTEIO) */
938 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 1004 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
939 len = 1024; 1005 len = 1024;
940 expected = -EREMOTEIO; 1006 expected = -EREMOTEIO;
941 break; 1007 break;
942 // NOTE: two consecutive _different_ faults in the queue. 1008 /* NOTE: two consecutive _different_ faults in the queue. */
943 case 11: // get endpoint descriptor (ALWAYS STALLS) 1009 case 11: /* get endpoint descriptor (ALWAYS STALLS) */
944 req.wValue = cpu_to_le16 (USB_DT_ENDPOINT << 8); 1010 req.wValue = cpu_to_le16(USB_DT_ENDPOINT << 8);
945 // endpoint == 0 1011 /* endpoint == 0 */
946 len = sizeof (struct usb_interface_descriptor); 1012 len = sizeof(struct usb_interface_descriptor);
947 expected = EPIPE; 1013 expected = EPIPE;
948 break; 1014 break;
949 // NOTE: sometimes even a third fault in the queue! 1015 /* NOTE: sometimes even a third fault in the queue! */
950 case 12: // get string 0 descriptor (MAY STALL) 1016 case 12: /* get string 0 descriptor (MAY STALL) */
951 req.wValue = cpu_to_le16 (USB_DT_STRING << 8); 1017 req.wValue = cpu_to_le16(USB_DT_STRING << 8);
952 // string == 0, for language IDs 1018 /* string == 0, for language IDs */
953 len = sizeof (struct usb_interface_descriptor); 1019 len = sizeof(struct usb_interface_descriptor);
954 // may succeed when > 4 languages 1020 /* may succeed when > 4 languages */
955 expected = EREMOTEIO; // or EPIPE, if no strings 1021 expected = EREMOTEIO; /* or EPIPE, if no strings */
956 break; 1022 break;
957 case 13: // short read, resembling case 10 1023 case 13: /* short read, resembling case 10 */
958 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 1024 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
959 // last data packet "should" be DATA1, not DATA0 1025 /* last data packet "should" be DATA1, not DATA0 */
960 len = 1024 - udev->descriptor.bMaxPacketSize0; 1026 len = 1024 - udev->descriptor.bMaxPacketSize0;
961 expected = -EREMOTEIO; 1027 expected = -EREMOTEIO;
962 break; 1028 break;
963 case 14: // short read; try to fill the last packet 1029 case 14: /* short read; try to fill the last packet */
964 req.wValue = cpu_to_le16 ((USB_DT_DEVICE << 8) | 0); 1030 req.wValue = cpu_to_le16((USB_DT_DEVICE << 8) | 0);
965 /* device descriptor size == 18 bytes */ 1031 /* device descriptor size == 18 bytes */
966 len = udev->descriptor.bMaxPacketSize0; 1032 len = udev->descriptor.bMaxPacketSize0;
1033 if (udev->speed == USB_SPEED_SUPER)
1034 len = 512;
967 switch (len) { 1035 switch (len) {
968 case 8: len = 24; break; 1036 case 8:
969 case 16: len = 32; break; 1037 len = 24;
1038 break;
1039 case 16:
1040 len = 32;
1041 break;
970 } 1042 }
971 expected = -EREMOTEIO; 1043 expected = -EREMOTEIO;
972 break; 1044 break;
@@ -975,8 +1047,8 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
975 context.status = -EINVAL; 1047 context.status = -EINVAL;
976 goto cleanup; 1048 goto cleanup;
977 } 1049 }
978 req.wLength = cpu_to_le16 (len); 1050 req.wLength = cpu_to_le16(len);
979 urb [i] = u = simple_alloc_urb (udev, pipe, len); 1051 urb[i] = u = simple_alloc_urb(udev, pipe, len);
980 if (!u) 1052 if (!u)
981 goto cleanup; 1053 goto cleanup;
982 1054
@@ -994,9 +1066,9 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
994 1066
995 /* queue the urbs */ 1067 /* queue the urbs */
996 context.urb = urb; 1068 context.urb = urb;
997 spin_lock_irq (&context.lock); 1069 spin_lock_irq(&context.lock);
998 for (i = 0; i < param->sglen; i++) { 1070 for (i = 0; i < param->sglen; i++) {
999 context.status = usb_submit_urb (urb [i], GFP_ATOMIC); 1071 context.status = usb_submit_urb(urb[i], GFP_ATOMIC);
1000 if (context.status != 0) { 1072 if (context.status != 0) {
1001 ERROR(dev, "can't submit urb[%d], status %d\n", 1073 ERROR(dev, "can't submit urb[%d], status %d\n",
1002 i, context.status); 1074 i, context.status);
@@ -1005,23 +1077,23 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
1005 } 1077 }
1006 context.pending++; 1078 context.pending++;
1007 } 1079 }
1008 spin_unlock_irq (&context.lock); 1080 spin_unlock_irq(&context.lock);
1009 1081
1010 /* FIXME set timer and time out; provide a disconnect hook */ 1082 /* FIXME set timer and time out; provide a disconnect hook */
1011 1083
1012 /* wait for the last one to complete */ 1084 /* wait for the last one to complete */
1013 if (context.pending > 0) 1085 if (context.pending > 0)
1014 wait_for_completion (&context.complete); 1086 wait_for_completion(&context.complete);
1015 1087
1016cleanup: 1088cleanup:
1017 for (i = 0; i < param->sglen; i++) { 1089 for (i = 0; i < param->sglen; i++) {
1018 if (!urb [i]) 1090 if (!urb[i])
1019 continue; 1091 continue;
1020 urb [i]->dev = udev; 1092 urb[i]->dev = udev;
1021 kfree(urb[i]->setup_packet); 1093 kfree(urb[i]->setup_packet);
1022 simple_free_urb (urb [i]); 1094 simple_free_urb(urb[i]);
1023 } 1095 }
1024 kfree (urb); 1096 kfree(urb);
1025 return context.status; 1097 return context.status;
1026} 1098}
1027#undef NUM_SUBCASES 1099#undef NUM_SUBCASES
@@ -1029,27 +1101,27 @@ cleanup:
1029 1101
1030/*-------------------------------------------------------------------------*/ 1102/*-------------------------------------------------------------------------*/
1031 1103
1032static void unlink1_callback (struct urb *urb) 1104static void unlink1_callback(struct urb *urb)
1033{ 1105{
1034 int status = urb->status; 1106 int status = urb->status;
1035 1107
1036 // we "know" -EPIPE (stall) never happens 1108 /* we "know" -EPIPE (stall) never happens */
1037 if (!status) 1109 if (!status)
1038 status = usb_submit_urb (urb, GFP_ATOMIC); 1110 status = usb_submit_urb(urb, GFP_ATOMIC);
1039 if (status) { 1111 if (status) {
1040 urb->status = status; 1112 urb->status = status;
1041 complete(urb->context); 1113 complete(urb->context);
1042 } 1114 }
1043} 1115}
1044 1116
1045static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async) 1117static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async)
1046{ 1118{
1047 struct urb *urb; 1119 struct urb *urb;
1048 struct completion completion; 1120 struct completion completion;
1049 int retval = 0; 1121 int retval = 0;
1050 1122
1051 init_completion (&completion); 1123 init_completion(&completion);
1052 urb = simple_alloc_urb (testdev_to_usbdev (dev), pipe, size); 1124 urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size);
1053 if (!urb) 1125 if (!urb)
1054 return -ENOMEM; 1126 return -ENOMEM;
1055 urb->context = &completion; 1127 urb->context = &completion;
@@ -1061,7 +1133,8 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1061 * FIXME want additional tests for when endpoint is STALLing 1133 * FIXME want additional tests for when endpoint is STALLing
1062 * due to errors, or is just NAKing requests. 1134 * due to errors, or is just NAKing requests.
1063 */ 1135 */
1064 if ((retval = usb_submit_urb (urb, GFP_KERNEL)) != 0) { 1136 retval = usb_submit_urb(urb, GFP_KERNEL);
1137 if (retval != 0) {
1065 dev_err(&dev->intf->dev, "submit fail %d\n", retval); 1138 dev_err(&dev->intf->dev, "submit fail %d\n", retval);
1066 return retval; 1139 return retval;
1067 } 1140 }
@@ -1069,7 +1142,7 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1069 /* unlinking that should always work. variable delay tests more 1142 /* unlinking that should always work. variable delay tests more
1070 * hcd states and code paths, even with little other system load. 1143 * hcd states and code paths, even with little other system load.
1071 */ 1144 */
1072 msleep (jiffies % (2 * INTERRUPT_RATE)); 1145 msleep(jiffies % (2 * INTERRUPT_RATE));
1073 if (async) { 1146 if (async) {
1074 while (!completion_done(&completion)) { 1147 while (!completion_done(&completion)) {
1075 retval = usb_unlink_urb(urb); 1148 retval = usb_unlink_urb(urb);
@@ -1098,11 +1171,11 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1098 break; 1171 break;
1099 } 1172 }
1100 } else 1173 } else
1101 usb_kill_urb (urb); 1174 usb_kill_urb(urb);
1102 1175
1103 wait_for_completion (&completion); 1176 wait_for_completion(&completion);
1104 retval = urb->status; 1177 retval = urb->status;
1105 simple_free_urb (urb); 1178 simple_free_urb(urb);
1106 1179
1107 if (async) 1180 if (async)
1108 return (retval == -ECONNRESET) ? 0 : retval - 1000; 1181 return (retval == -ECONNRESET) ? 0 : retval - 1000;
@@ -1111,14 +1184,112 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1111 0 : retval - 2000; 1184 0 : retval - 2000;
1112} 1185}
1113 1186
1114static int unlink_simple (struct usbtest_dev *dev, int pipe, int len) 1187static int unlink_simple(struct usbtest_dev *dev, int pipe, int len)
1115{ 1188{
1116 int retval = 0; 1189 int retval = 0;
1117 1190
1118 /* test sync and async paths */ 1191 /* test sync and async paths */
1119 retval = unlink1 (dev, pipe, len, 1); 1192 retval = unlink1(dev, pipe, len, 1);
1120 if (!retval) 1193 if (!retval)
1121 retval = unlink1 (dev, pipe, len, 0); 1194 retval = unlink1(dev, pipe, len, 0);
1195 return retval;
1196}
1197
1198/*-------------------------------------------------------------------------*/
1199
1200struct queued_ctx {
1201 struct completion complete;
1202 atomic_t pending;
1203 unsigned num;
1204 int status;
1205 struct urb **urbs;
1206};
1207
1208static void unlink_queued_callback(struct urb *urb)
1209{
1210 int status = urb->status;
1211 struct queued_ctx *ctx = urb->context;
1212
1213 if (ctx->status)
1214 goto done;
1215 if (urb == ctx->urbs[ctx->num - 4] || urb == ctx->urbs[ctx->num - 2]) {
1216 if (status == -ECONNRESET)
1217 goto done;
1218 /* What error should we report if the URB completed normally? */
1219 }
1220 if (status != 0)
1221 ctx->status = status;
1222
1223 done:
1224 if (atomic_dec_and_test(&ctx->pending))
1225 complete(&ctx->complete);
1226}
1227
1228static int unlink_queued(struct usbtest_dev *dev, int pipe, unsigned num,
1229 unsigned size)
1230{
1231 struct queued_ctx ctx;
1232 struct usb_device *udev = testdev_to_usbdev(dev);
1233 void *buf;
1234 dma_addr_t buf_dma;
1235 int i;
1236 int retval = -ENOMEM;
1237
1238 init_completion(&ctx.complete);
1239 atomic_set(&ctx.pending, 1); /* One more than the actual value */
1240 ctx.num = num;
1241 ctx.status = 0;
1242
1243 buf = usb_alloc_coherent(udev, size, GFP_KERNEL, &buf_dma);
1244 if (!buf)
1245 return retval;
1246 memset(buf, 0, size);
1247
1248 /* Allocate and init the urbs we'll queue */
1249 ctx.urbs = kcalloc(num, sizeof(struct urb *), GFP_KERNEL);
1250 if (!ctx.urbs)
1251 goto free_buf;
1252 for (i = 0; i < num; i++) {
1253 ctx.urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1254 if (!ctx.urbs[i])
1255 goto free_urbs;
1256 usb_fill_bulk_urb(ctx.urbs[i], udev, pipe, buf, size,
1257 unlink_queued_callback, &ctx);
1258 ctx.urbs[i]->transfer_dma = buf_dma;
1259 ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1260 }
1261
1262 /* Submit all the URBs and then unlink URBs num - 4 and num - 2. */
1263 for (i = 0; i < num; i++) {
1264 atomic_inc(&ctx.pending);
1265 retval = usb_submit_urb(ctx.urbs[i], GFP_KERNEL);
1266 if (retval != 0) {
1267 dev_err(&dev->intf->dev, "submit urbs[%d] fail %d\n",
1268 i, retval);
1269 atomic_dec(&ctx.pending);
1270 ctx.status = retval;
1271 break;
1272 }
1273 }
1274 if (i == num) {
1275 usb_unlink_urb(ctx.urbs[num - 4]);
1276 usb_unlink_urb(ctx.urbs[num - 2]);
1277 } else {
1278 while (--i >= 0)
1279 usb_unlink_urb(ctx.urbs[i]);
1280 }
1281
1282 if (atomic_dec_and_test(&ctx.pending)) /* The extra count */
1283 complete(&ctx.complete);
1284 wait_for_completion(&ctx.complete);
1285 retval = ctx.status;
1286
1287 free_urbs:
1288 for (i = 0; i < num; i++)
1289 usb_free_urb(ctx.urbs[i]);
1290 kfree(ctx.urbs);
1291 free_buf:
1292 usb_free_coherent(udev, size, buf, buf_dma);
1122 return retval; 1293 return retval;
1123} 1294}
1124 1295
@@ -1130,7 +1301,7 @@ static int verify_not_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
1130 u16 status; 1301 u16 status;
1131 1302
1132 /* shouldn't look or act halted */ 1303 /* shouldn't look or act halted */
1133 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status); 1304 retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
1134 if (retval < 0) { 1305 if (retval < 0) {
1135 ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n", 1306 ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n",
1136 ep, retval); 1307 ep, retval);
@@ -1152,7 +1323,7 @@ static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
1152 u16 status; 1323 u16 status;
1153 1324
1154 /* should look and act halted */ 1325 /* should look and act halted */
1155 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status); 1326 retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
1156 if (retval < 0) { 1327 if (retval < 0) {
1157 ERROR(tdev, "ep %02x couldn't get halt status, %d\n", 1328 ERROR(tdev, "ep %02x couldn't get halt status, %d\n",
1158 ep, retval); 1329 ep, retval);
@@ -1182,7 +1353,7 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
1182 return retval; 1353 return retval;
1183 1354
1184 /* set halt (protocol test only), verify it worked */ 1355 /* set halt (protocol test only), verify it worked */
1185 retval = usb_control_msg (urb->dev, usb_sndctrlpipe (urb->dev, 0), 1356 retval = usb_control_msg(urb->dev, usb_sndctrlpipe(urb->dev, 0),
1186 USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT, 1357 USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT,
1187 USB_ENDPOINT_HALT, ep, 1358 USB_ENDPOINT_HALT, ep,
1188 NULL, 0, USB_CTRL_SET_TIMEOUT); 1359 NULL, 0, USB_CTRL_SET_TIMEOUT);
@@ -1195,7 +1366,7 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
1195 return retval; 1366 return retval;
1196 1367
1197 /* clear halt (tests API + protocol), verify it worked */ 1368 /* clear halt (tests API + protocol), verify it worked */
1198 retval = usb_clear_halt (urb->dev, urb->pipe); 1369 retval = usb_clear_halt(urb->dev, urb->pipe);
1199 if (retval < 0) { 1370 if (retval < 0) {
1200 ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval); 1371 ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval);
1201 return retval; 1372 return retval;
@@ -1209,18 +1380,18 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
1209 return 0; 1380 return 0;
1210} 1381}
1211 1382
1212static int halt_simple (struct usbtest_dev *dev) 1383static int halt_simple(struct usbtest_dev *dev)
1213{ 1384{
1214 int ep; 1385 int ep;
1215 int retval = 0; 1386 int retval = 0;
1216 struct urb *urb; 1387 struct urb *urb;
1217 1388
1218 urb = simple_alloc_urb (testdev_to_usbdev (dev), 0, 512); 1389 urb = simple_alloc_urb(testdev_to_usbdev(dev), 0, 512);
1219 if (urb == NULL) 1390 if (urb == NULL)
1220 return -ENOMEM; 1391 return -ENOMEM;
1221 1392
1222 if (dev->in_pipe) { 1393 if (dev->in_pipe) {
1223 ep = usb_pipeendpoint (dev->in_pipe) | USB_DIR_IN; 1394 ep = usb_pipeendpoint(dev->in_pipe) | USB_DIR_IN;
1224 urb->pipe = dev->in_pipe; 1395 urb->pipe = dev->in_pipe;
1225 retval = test_halt(dev, ep, urb); 1396 retval = test_halt(dev, ep, urb);
1226 if (retval < 0) 1397 if (retval < 0)
@@ -1228,12 +1399,12 @@ static int halt_simple (struct usbtest_dev *dev)
1228 } 1399 }
1229 1400
1230 if (dev->out_pipe) { 1401 if (dev->out_pipe) {
1231 ep = usb_pipeendpoint (dev->out_pipe); 1402 ep = usb_pipeendpoint(dev->out_pipe);
1232 urb->pipe = dev->out_pipe; 1403 urb->pipe = dev->out_pipe;
1233 retval = test_halt(dev, ep, urb); 1404 retval = test_halt(dev, ep, urb);
1234 } 1405 }
1235done: 1406done:
1236 simple_free_urb (urb); 1407 simple_free_urb(urb);
1237 return retval; 1408 return retval;
1238} 1409}
1239 1410
@@ -1247,8 +1418,8 @@ done:
1247 * need to be able to handle more than one OUT data packet. We'll 1418 * need to be able to handle more than one OUT data packet. We'll
1248 * try whatever we're told to try. 1419 * try whatever we're told to try.
1249 */ 1420 */
1250static int ctrl_out (struct usbtest_dev *dev, 1421static int ctrl_out(struct usbtest_dev *dev,
1251 unsigned count, unsigned length, unsigned vary) 1422 unsigned count, unsigned length, unsigned vary, unsigned offset)
1252{ 1423{
1253 unsigned i, j, len; 1424 unsigned i, j, len;
1254 int retval; 1425 int retval;
@@ -1259,11 +1430,12 @@ static int ctrl_out (struct usbtest_dev *dev,
1259 if (length < 1 || length > 0xffff || vary >= length) 1430 if (length < 1 || length > 0xffff || vary >= length)
1260 return -EINVAL; 1431 return -EINVAL;
1261 1432
1262 buf = kmalloc(length, GFP_KERNEL); 1433 buf = kmalloc(length + offset, GFP_KERNEL);
1263 if (!buf) 1434 if (!buf)
1264 return -ENOMEM; 1435 return -ENOMEM;
1265 1436
1266 udev = testdev_to_usbdev (dev); 1437 buf += offset;
1438 udev = testdev_to_usbdev(dev);
1267 len = length; 1439 len = length;
1268 retval = 0; 1440 retval = 0;
1269 1441
@@ -1273,8 +1445,8 @@ static int ctrl_out (struct usbtest_dev *dev,
1273 for (i = 0; i < count; i++) { 1445 for (i = 0; i < count; i++) {
1274 /* write patterned data */ 1446 /* write patterned data */
1275 for (j = 0; j < len; j++) 1447 for (j = 0; j < len; j++)
1276 buf [j] = i + j; 1448 buf[j] = i + j;
1277 retval = usb_control_msg (udev, usb_sndctrlpipe (udev,0), 1449 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1278 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR, 1450 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR,
1279 0, 0, buf, len, USB_CTRL_SET_TIMEOUT); 1451 0, 0, buf, len, USB_CTRL_SET_TIMEOUT);
1280 if (retval != len) { 1452 if (retval != len) {
@@ -1288,7 +1460,7 @@ static int ctrl_out (struct usbtest_dev *dev,
1288 } 1460 }
1289 1461
1290 /* read it back -- assuming nothing intervened!! */ 1462 /* read it back -- assuming nothing intervened!! */
1291 retval = usb_control_msg (udev, usb_rcvctrlpipe (udev,0), 1463 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1292 0x5c, USB_DIR_IN|USB_TYPE_VENDOR, 1464 0x5c, USB_DIR_IN|USB_TYPE_VENDOR,
1293 0, 0, buf, len, USB_CTRL_GET_TIMEOUT); 1465 0, 0, buf, len, USB_CTRL_GET_TIMEOUT);
1294 if (retval != len) { 1466 if (retval != len) {
@@ -1303,9 +1475,9 @@ static int ctrl_out (struct usbtest_dev *dev,
1303 1475
1304 /* fail if we can't verify */ 1476 /* fail if we can't verify */
1305 for (j = 0; j < len; j++) { 1477 for (j = 0; j < len; j++) {
1306 if (buf [j] != (u8) (i + j)) { 1478 if (buf[j] != (u8) (i + j)) {
1307 ERROR(dev, "ctrl_out, byte %d is %d not %d\n", 1479 ERROR(dev, "ctrl_out, byte %d is %d not %d\n",
1308 j, buf [j], (u8) i + j); 1480 j, buf[j], (u8) i + j);
1309 retval = -EBADMSG; 1481 retval = -EBADMSG;
1310 break; 1482 break;
1311 } 1483 }
@@ -1326,10 +1498,10 @@ static int ctrl_out (struct usbtest_dev *dev,
1326 } 1498 }
1327 1499
1328 if (retval < 0) 1500 if (retval < 0)
1329 ERROR (dev, "ctrl_out %s failed, code %d, count %d\n", 1501 ERROR(dev, "ctrl_out %s failed, code %d, count %d\n",
1330 what, retval, i); 1502 what, retval, i);
1331 1503
1332 kfree (buf); 1504 kfree(buf - offset);
1333 return retval; 1505 return retval;
1334} 1506}
1335 1507
@@ -1351,7 +1523,7 @@ struct iso_context {
1351 struct usbtest_dev *dev; 1523 struct usbtest_dev *dev;
1352}; 1524};
1353 1525
1354static void iso_callback (struct urb *urb) 1526static void iso_callback(struct urb *urb)
1355{ 1527{
1356 struct iso_context *ctx = urb->context; 1528 struct iso_context *ctx = urb->context;
1357 1529
@@ -1363,10 +1535,14 @@ static void iso_callback (struct urb *urb)
1363 ctx->errors += urb->error_count; 1535 ctx->errors += urb->error_count;
1364 else if (urb->status != 0) 1536 else if (urb->status != 0)
1365 ctx->errors += urb->number_of_packets; 1537 ctx->errors += urb->number_of_packets;
1538 else if (urb->actual_length != urb->transfer_buffer_length)
1539 ctx->errors++;
1540 else if (check_guard_bytes(ctx->dev, urb) != 0)
1541 ctx->errors++;
1366 1542
1367 if (urb->status == 0 && ctx->count > (ctx->pending - 1) 1543 if (urb->status == 0 && ctx->count > (ctx->pending - 1)
1368 && !ctx->submit_error) { 1544 && !ctx->submit_error) {
1369 int status = usb_submit_urb (urb, GFP_ATOMIC); 1545 int status = usb_submit_urb(urb, GFP_ATOMIC);
1370 switch (status) { 1546 switch (status) {
1371 case 0: 1547 case 0:
1372 goto done; 1548 goto done;
@@ -1388,17 +1564,18 @@ static void iso_callback (struct urb *urb)
1388 dev_err(&ctx->dev->intf->dev, 1564 dev_err(&ctx->dev->intf->dev,
1389 "iso test, %lu errors out of %lu\n", 1565 "iso test, %lu errors out of %lu\n",
1390 ctx->errors, ctx->packet_count); 1566 ctx->errors, ctx->packet_count);
1391 complete (&ctx->done); 1567 complete(&ctx->done);
1392 } 1568 }
1393done: 1569done:
1394 spin_unlock(&ctx->lock); 1570 spin_unlock(&ctx->lock);
1395} 1571}
1396 1572
1397static struct urb *iso_alloc_urb ( 1573static struct urb *iso_alloc_urb(
1398 struct usb_device *udev, 1574 struct usb_device *udev,
1399 int pipe, 1575 int pipe,
1400 struct usb_endpoint_descriptor *desc, 1576 struct usb_endpoint_descriptor *desc,
1401 long bytes 1577 long bytes,
1578 unsigned offset
1402) 1579)
1403{ 1580{
1404 struct urb *urb; 1581 struct urb *urb;
@@ -1410,7 +1587,7 @@ static struct urb *iso_alloc_urb (
1410 maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11)); 1587 maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11));
1411 packets = DIV_ROUND_UP(bytes, maxp); 1588 packets = DIV_ROUND_UP(bytes, maxp);
1412 1589
1413 urb = usb_alloc_urb (packets, GFP_KERNEL); 1590 urb = usb_alloc_urb(packets, GFP_KERNEL);
1414 if (!urb) 1591 if (!urb)
1415 return urb; 1592 return urb;
1416 urb->dev = udev; 1593 urb->dev = udev;
@@ -1418,31 +1595,42 @@ static struct urb *iso_alloc_urb (
1418 1595
1419 urb->number_of_packets = packets; 1596 urb->number_of_packets = packets;
1420 urb->transfer_buffer_length = bytes; 1597 urb->transfer_buffer_length = bytes;
1421 urb->transfer_buffer = usb_alloc_coherent (udev, bytes, GFP_KERNEL, 1598 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
1422 &urb->transfer_dma); 1599 GFP_KERNEL,
1600 &urb->transfer_dma);
1423 if (!urb->transfer_buffer) { 1601 if (!urb->transfer_buffer) {
1424 usb_free_urb (urb); 1602 usb_free_urb(urb);
1425 return NULL; 1603 return NULL;
1426 } 1604 }
1427 memset (urb->transfer_buffer, 0, bytes); 1605 if (offset) {
1606 memset(urb->transfer_buffer, GUARD_BYTE, offset);
1607 urb->transfer_buffer += offset;
1608 urb->transfer_dma += offset;
1609 }
1610 /* For inbound transfers use guard byte so that test fails if
1611 data not correctly copied */
1612 memset(urb->transfer_buffer,
1613 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
1614 bytes);
1615
1428 for (i = 0; i < packets; i++) { 1616 for (i = 0; i < packets; i++) {
1429 /* here, only the last packet will be short */ 1617 /* here, only the last packet will be short */
1430 urb->iso_frame_desc[i].length = min ((unsigned) bytes, maxp); 1618 urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp);
1431 bytes -= urb->iso_frame_desc[i].length; 1619 bytes -= urb->iso_frame_desc[i].length;
1432 1620
1433 urb->iso_frame_desc[i].offset = maxp * i; 1621 urb->iso_frame_desc[i].offset = maxp * i;
1434 } 1622 }
1435 1623
1436 urb->complete = iso_callback; 1624 urb->complete = iso_callback;
1437 // urb->context = SET BY CALLER 1625 /* urb->context = SET BY CALLER */
1438 urb->interval = 1 << (desc->bInterval - 1); 1626 urb->interval = 1 << (desc->bInterval - 1);
1439 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 1627 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
1440 return urb; 1628 return urb;
1441} 1629}
1442 1630
1443static int 1631static int
1444test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param, 1632test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
1445 int pipe, struct usb_endpoint_descriptor *desc) 1633 int pipe, struct usb_endpoint_descriptor *desc, unsigned offset)
1446{ 1634{
1447 struct iso_context context; 1635 struct iso_context context;
1448 struct usb_device *udev; 1636 struct usb_device *udev;
@@ -1457,11 +1645,11 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1457 memset(&context, 0, sizeof context); 1645 memset(&context, 0, sizeof context);
1458 context.count = param->iterations * param->sglen; 1646 context.count = param->iterations * param->sglen;
1459 context.dev = dev; 1647 context.dev = dev;
1460 init_completion (&context.done); 1648 init_completion(&context.done);
1461 spin_lock_init (&context.lock); 1649 spin_lock_init(&context.lock);
1462 1650
1463 memset (urbs, 0, sizeof urbs); 1651 memset(urbs, 0, sizeof urbs);
1464 udev = testdev_to_usbdev (dev); 1652 udev = testdev_to_usbdev(dev);
1465 dev_info(&dev->intf->dev, 1653 dev_info(&dev->intf->dev,
1466 "... iso period %d %sframes, wMaxPacket %04x\n", 1654 "... iso period %d %sframes, wMaxPacket %04x\n",
1467 1 << (desc->bInterval - 1), 1655 1 << (desc->bInterval - 1),
@@ -1469,14 +1657,14 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1469 le16_to_cpu(desc->wMaxPacketSize)); 1657 le16_to_cpu(desc->wMaxPacketSize));
1470 1658
1471 for (i = 0; i < param->sglen; i++) { 1659 for (i = 0; i < param->sglen; i++) {
1472 urbs [i] = iso_alloc_urb (udev, pipe, desc, 1660 urbs[i] = iso_alloc_urb(udev, pipe, desc,
1473 param->length); 1661 param->length, offset);
1474 if (!urbs [i]) { 1662 if (!urbs[i]) {
1475 status = -ENOMEM; 1663 status = -ENOMEM;
1476 goto fail; 1664 goto fail;
1477 } 1665 }
1478 packets += urbs[i]->number_of_packets; 1666 packets += urbs[i]->number_of_packets;
1479 urbs [i]->context = &context; 1667 urbs[i]->context = &context;
1480 } 1668 }
1481 packets *= param->iterations; 1669 packets *= param->iterations;
1482 dev_info(&dev->intf->dev, 1670 dev_info(&dev->intf->dev,
@@ -1485,27 +1673,27 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1485 / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1), 1673 / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1),
1486 packets); 1674 packets);
1487 1675
1488 spin_lock_irq (&context.lock); 1676 spin_lock_irq(&context.lock);
1489 for (i = 0; i < param->sglen; i++) { 1677 for (i = 0; i < param->sglen; i++) {
1490 ++context.pending; 1678 ++context.pending;
1491 status = usb_submit_urb (urbs [i], GFP_ATOMIC); 1679 status = usb_submit_urb(urbs[i], GFP_ATOMIC);
1492 if (status < 0) { 1680 if (status < 0) {
1493 ERROR (dev, "submit iso[%d], error %d\n", i, status); 1681 ERROR(dev, "submit iso[%d], error %d\n", i, status);
1494 if (i == 0) { 1682 if (i == 0) {
1495 spin_unlock_irq (&context.lock); 1683 spin_unlock_irq(&context.lock);
1496 goto fail; 1684 goto fail;
1497 } 1685 }
1498 1686
1499 simple_free_urb (urbs [i]); 1687 simple_free_urb(urbs[i]);
1500 urbs[i] = NULL; 1688 urbs[i] = NULL;
1501 context.pending--; 1689 context.pending--;
1502 context.submit_error = 1; 1690 context.submit_error = 1;
1503 break; 1691 break;
1504 } 1692 }
1505 } 1693 }
1506 spin_unlock_irq (&context.lock); 1694 spin_unlock_irq(&context.lock);
1507 1695
1508 wait_for_completion (&context.done); 1696 wait_for_completion(&context.done);
1509 1697
1510 for (i = 0; i < param->sglen; i++) { 1698 for (i = 0; i < param->sglen; i++) {
1511 if (urbs[i]) 1699 if (urbs[i])
@@ -1526,12 +1714,32 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1526 1714
1527fail: 1715fail:
1528 for (i = 0; i < param->sglen; i++) { 1716 for (i = 0; i < param->sglen; i++) {
1529 if (urbs [i]) 1717 if (urbs[i])
1530 simple_free_urb (urbs [i]); 1718 simple_free_urb(urbs[i]);
1531 } 1719 }
1532 return status; 1720 return status;
1533} 1721}
1534 1722
1723static int test_unaligned_bulk(
1724 struct usbtest_dev *tdev,
1725 int pipe,
1726 unsigned length,
1727 int iterations,
1728 unsigned transfer_flags,
1729 const char *label)
1730{
1731 int retval;
1732 struct urb *urb = usbtest_alloc_urb(
1733 testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1);
1734
1735 if (!urb)
1736 return -ENOMEM;
1737
1738 retval = simple_io(tdev, urb, iterations, 0, 0, label);
1739 simple_free_urb(urb);
1740 return retval;
1741}
1742
1535/*-------------------------------------------------------------------------*/ 1743/*-------------------------------------------------------------------------*/
1536 1744
1537/* We only have this one interface to user space, through usbfs. 1745/* We only have this one interface to user space, through usbfs.
@@ -1557,10 +1765,10 @@ fail:
1557 1765
1558/* No BKL needed */ 1766/* No BKL needed */
1559static int 1767static int
1560usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) 1768usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
1561{ 1769{
1562 struct usbtest_dev *dev = usb_get_intfdata (intf); 1770 struct usbtest_dev *dev = usb_get_intfdata(intf);
1563 struct usb_device *udev = testdev_to_usbdev (dev); 1771 struct usb_device *udev = testdev_to_usbdev(dev);
1564 struct usbtest_param *param = buf; 1772 struct usbtest_param *param = buf;
1565 int retval = -EOPNOTSUPP; 1773 int retval = -EOPNOTSUPP;
1566 struct urb *urb; 1774 struct urb *urb;
@@ -1569,7 +1777,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1569 struct timeval start; 1777 struct timeval start;
1570 unsigned i; 1778 unsigned i;
1571 1779
1572 // FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. 1780 /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */
1573 1781
1574 pattern = mod_pattern; 1782 pattern = mod_pattern;
1575 1783
@@ -1595,9 +1803,9 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1595 mutex_unlock(&dev->lock); 1803 mutex_unlock(&dev->lock);
1596 return -ENODEV; 1804 return -ENODEV;
1597 } 1805 }
1598 res = set_altsetting (dev, dev->info->alt); 1806 res = set_altsetting(dev, dev->info->alt);
1599 if (res) { 1807 if (res) {
1600 dev_err (&intf->dev, 1808 dev_err(&intf->dev,
1601 "set altsetting to %d failed, %d\n", 1809 "set altsetting to %d failed, %d\n",
1602 dev->info->alt, res); 1810 dev->info->alt, res);
1603 mutex_unlock(&dev->lock); 1811 mutex_unlock(&dev->lock);
@@ -1614,7 +1822,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1614 * FIXME add more tests! cancel requests, verify the data, control 1822 * FIXME add more tests! cancel requests, verify the data, control
1615 * queueing, concurrent read+write threads, and so on. 1823 * queueing, concurrent read+write threads, and so on.
1616 */ 1824 */
1617 do_gettimeofday (&start); 1825 do_gettimeofday(&start);
1618 switch (param->test_num) { 1826 switch (param->test_num) {
1619 1827
1620 case 0: 1828 case 0:
@@ -1629,14 +1837,14 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1629 dev_info(&intf->dev, 1837 dev_info(&intf->dev,
1630 "TEST 1: write %d bytes %u times\n", 1838 "TEST 1: write %d bytes %u times\n",
1631 param->length, param->iterations); 1839 param->length, param->iterations);
1632 urb = simple_alloc_urb (udev, dev->out_pipe, param->length); 1840 urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
1633 if (!urb) { 1841 if (!urb) {
1634 retval = -ENOMEM; 1842 retval = -ENOMEM;
1635 break; 1843 break;
1636 } 1844 }
1637 // FIRMWARE: bulk sink (maybe accepts short writes) 1845 /* FIRMWARE: bulk sink (maybe accepts short writes) */
1638 retval = simple_io(dev, urb, param->iterations, 0, 0, "test1"); 1846 retval = simple_io(dev, urb, param->iterations, 0, 0, "test1");
1639 simple_free_urb (urb); 1847 simple_free_urb(urb);
1640 break; 1848 break;
1641 case 2: 1849 case 2:
1642 if (dev->in_pipe == 0) 1850 if (dev->in_pipe == 0)
@@ -1644,14 +1852,14 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1644 dev_info(&intf->dev, 1852 dev_info(&intf->dev,
1645 "TEST 2: read %d bytes %u times\n", 1853 "TEST 2: read %d bytes %u times\n",
1646 param->length, param->iterations); 1854 param->length, param->iterations);
1647 urb = simple_alloc_urb (udev, dev->in_pipe, param->length); 1855 urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
1648 if (!urb) { 1856 if (!urb) {
1649 retval = -ENOMEM; 1857 retval = -ENOMEM;
1650 break; 1858 break;
1651 } 1859 }
1652 // FIRMWARE: bulk source (maybe generates short writes) 1860 /* FIRMWARE: bulk source (maybe generates short writes) */
1653 retval = simple_io(dev, urb, param->iterations, 0, 0, "test2"); 1861 retval = simple_io(dev, urb, param->iterations, 0, 0, "test2");
1654 simple_free_urb (urb); 1862 simple_free_urb(urb);
1655 break; 1863 break;
1656 case 3: 1864 case 3:
1657 if (dev->out_pipe == 0 || param->vary == 0) 1865 if (dev->out_pipe == 0 || param->vary == 0)
@@ -1659,15 +1867,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1659 dev_info(&intf->dev, 1867 dev_info(&intf->dev,
1660 "TEST 3: write/%d 0..%d bytes %u times\n", 1868 "TEST 3: write/%d 0..%d bytes %u times\n",
1661 param->vary, param->length, param->iterations); 1869 param->vary, param->length, param->iterations);
1662 urb = simple_alloc_urb (udev, dev->out_pipe, param->length); 1870 urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
1663 if (!urb) { 1871 if (!urb) {
1664 retval = -ENOMEM; 1872 retval = -ENOMEM;
1665 break; 1873 break;
1666 } 1874 }
1667 // FIRMWARE: bulk sink (maybe accepts short writes) 1875 /* FIRMWARE: bulk sink (maybe accepts short writes) */
1668 retval = simple_io(dev, urb, param->iterations, param->vary, 1876 retval = simple_io(dev, urb, param->iterations, param->vary,
1669 0, "test3"); 1877 0, "test3");
1670 simple_free_urb (urb); 1878 simple_free_urb(urb);
1671 break; 1879 break;
1672 case 4: 1880 case 4:
1673 if (dev->in_pipe == 0 || param->vary == 0) 1881 if (dev->in_pipe == 0 || param->vary == 0)
@@ -1675,15 +1883,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1675 dev_info(&intf->dev, 1883 dev_info(&intf->dev,
1676 "TEST 4: read/%d 0..%d bytes %u times\n", 1884 "TEST 4: read/%d 0..%d bytes %u times\n",
1677 param->vary, param->length, param->iterations); 1885 param->vary, param->length, param->iterations);
1678 urb = simple_alloc_urb (udev, dev->in_pipe, param->length); 1886 urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
1679 if (!urb) { 1887 if (!urb) {
1680 retval = -ENOMEM; 1888 retval = -ENOMEM;
1681 break; 1889 break;
1682 } 1890 }
1683 // FIRMWARE: bulk source (maybe generates short writes) 1891 /* FIRMWARE: bulk source (maybe generates short writes) */
1684 retval = simple_io(dev, urb, param->iterations, param->vary, 1892 retval = simple_io(dev, urb, param->iterations, param->vary,
1685 0, "test4"); 1893 0, "test4");
1686 simple_free_urb (urb); 1894 simple_free_urb(urb);
1687 break; 1895 break;
1688 1896
1689 /* Queued bulk I/O tests */ 1897 /* Queued bulk I/O tests */
@@ -1694,15 +1902,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1694 "TEST 5: write %d sglists %d entries of %d bytes\n", 1902 "TEST 5: write %d sglists %d entries of %d bytes\n",
1695 param->iterations, 1903 param->iterations,
1696 param->sglen, param->length); 1904 param->sglen, param->length);
1697 sg = alloc_sglist (param->sglen, param->length, 0); 1905 sg = alloc_sglist(param->sglen, param->length, 0);
1698 if (!sg) { 1906 if (!sg) {
1699 retval = -ENOMEM; 1907 retval = -ENOMEM;
1700 break; 1908 break;
1701 } 1909 }
1702 // FIRMWARE: bulk sink (maybe accepts short writes) 1910 /* FIRMWARE: bulk sink (maybe accepts short writes) */
1703 retval = perform_sglist(dev, param->iterations, dev->out_pipe, 1911 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
1704 &req, sg, param->sglen); 1912 &req, sg, param->sglen);
1705 free_sglist (sg, param->sglen); 1913 free_sglist(sg, param->sglen);
1706 break; 1914 break;
1707 1915
1708 case 6: 1916 case 6:
@@ -1712,15 +1920,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1712 "TEST 6: read %d sglists %d entries of %d bytes\n", 1920 "TEST 6: read %d sglists %d entries of %d bytes\n",
1713 param->iterations, 1921 param->iterations,
1714 param->sglen, param->length); 1922 param->sglen, param->length);
1715 sg = alloc_sglist (param->sglen, param->length, 0); 1923 sg = alloc_sglist(param->sglen, param->length, 0);
1716 if (!sg) { 1924 if (!sg) {
1717 retval = -ENOMEM; 1925 retval = -ENOMEM;
1718 break; 1926 break;
1719 } 1927 }
1720 // FIRMWARE: bulk source (maybe generates short writes) 1928 /* FIRMWARE: bulk source (maybe generates short writes) */
1721 retval = perform_sglist(dev, param->iterations, dev->in_pipe, 1929 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
1722 &req, sg, param->sglen); 1930 &req, sg, param->sglen);
1723 free_sglist (sg, param->sglen); 1931 free_sglist(sg, param->sglen);
1724 break; 1932 break;
1725 case 7: 1933 case 7:
1726 if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0) 1934 if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0)
@@ -1729,15 +1937,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1729 "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n", 1937 "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n",
1730 param->vary, param->iterations, 1938 param->vary, param->iterations,
1731 param->sglen, param->length); 1939 param->sglen, param->length);
1732 sg = alloc_sglist (param->sglen, param->length, param->vary); 1940 sg = alloc_sglist(param->sglen, param->length, param->vary);
1733 if (!sg) { 1941 if (!sg) {
1734 retval = -ENOMEM; 1942 retval = -ENOMEM;
1735 break; 1943 break;
1736 } 1944 }
1737 // FIRMWARE: bulk sink (maybe accepts short writes) 1945 /* FIRMWARE: bulk sink (maybe accepts short writes) */
1738 retval = perform_sglist(dev, param->iterations, dev->out_pipe, 1946 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
1739 &req, sg, param->sglen); 1947 &req, sg, param->sglen);
1740 free_sglist (sg, param->sglen); 1948 free_sglist(sg, param->sglen);
1741 break; 1949 break;
1742 case 8: 1950 case 8:
1743 if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0) 1951 if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0)
@@ -1746,15 +1954,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1746 "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n", 1954 "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n",
1747 param->vary, param->iterations, 1955 param->vary, param->iterations,
1748 param->sglen, param->length); 1956 param->sglen, param->length);
1749 sg = alloc_sglist (param->sglen, param->length, param->vary); 1957 sg = alloc_sglist(param->sglen, param->length, param->vary);
1750 if (!sg) { 1958 if (!sg) {
1751 retval = -ENOMEM; 1959 retval = -ENOMEM;
1752 break; 1960 break;
1753 } 1961 }
1754 // FIRMWARE: bulk source (maybe generates short writes) 1962 /* FIRMWARE: bulk source (maybe generates short writes) */
1755 retval = perform_sglist(dev, param->iterations, dev->in_pipe, 1963 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
1756 &req, sg, param->sglen); 1964 &req, sg, param->sglen);
1757 free_sglist (sg, param->sglen); 1965 free_sglist(sg, param->sglen);
1758 break; 1966 break;
1759 1967
1760 /* non-queued sanity tests for control (chapter 9 subset) */ 1968 /* non-queued sanity tests for control (chapter 9 subset) */
@@ -1764,7 +1972,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1764 "TEST 9: ch9 (subset) control tests, %d times\n", 1972 "TEST 9: ch9 (subset) control tests, %d times\n",
1765 param->iterations); 1973 param->iterations);
1766 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1974 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1767 retval = ch9_postconfig (dev); 1975 retval = ch9_postconfig(dev);
1768 if (retval) 1976 if (retval)
1769 dev_err(&intf->dev, "ch9 subset failed, " 1977 dev_err(&intf->dev, "ch9 subset failed, "
1770 "iterations left %d\n", i); 1978 "iterations left %d\n", i);
@@ -1779,7 +1987,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1779 "TEST 10: queue %d control calls, %d times\n", 1987 "TEST 10: queue %d control calls, %d times\n",
1780 param->sglen, 1988 param->sglen,
1781 param->iterations); 1989 param->iterations);
1782 retval = test_ctrl_queue (dev, param); 1990 retval = test_ctrl_queue(dev, param);
1783 break; 1991 break;
1784 1992
1785 /* simple non-queued unlinks (ring with one urb) */ 1993 /* simple non-queued unlinks (ring with one urb) */
@@ -1790,7 +1998,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1790 dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n", 1998 dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n",
1791 param->iterations, param->length); 1999 param->iterations, param->length);
1792 for (i = param->iterations; retval == 0 && i--; /* NOP */) 2000 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1793 retval = unlink_simple (dev, dev->in_pipe, 2001 retval = unlink_simple(dev, dev->in_pipe,
1794 param->length); 2002 param->length);
1795 if (retval) 2003 if (retval)
1796 dev_err(&intf->dev, "unlink reads failed %d, " 2004 dev_err(&intf->dev, "unlink reads failed %d, "
@@ -1803,7 +2011,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1803 dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n", 2011 dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n",
1804 param->iterations, param->length); 2012 param->iterations, param->length);
1805 for (i = param->iterations; retval == 0 && i--; /* NOP */) 2013 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1806 retval = unlink_simple (dev, dev->out_pipe, 2014 retval = unlink_simple(dev, dev->out_pipe,
1807 param->length); 2015 param->length);
1808 if (retval) 2016 if (retval)
1809 dev_err(&intf->dev, "unlink writes failed %d, " 2017 dev_err(&intf->dev, "unlink writes failed %d, "
@@ -1818,7 +2026,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1818 dev_info(&intf->dev, "TEST 13: set/clear %d halts\n", 2026 dev_info(&intf->dev, "TEST 13: set/clear %d halts\n",
1819 param->iterations); 2027 param->iterations);
1820 for (i = param->iterations; retval == 0 && i--; /* NOP */) 2028 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1821 retval = halt_simple (dev); 2029 retval = halt_simple(dev);
1822 2030
1823 if (retval) 2031 if (retval)
1824 ERROR(dev, "halts failed, iterations left %d\n", i); 2032 ERROR(dev, "halts failed, iterations left %d\n", i);
@@ -1833,7 +2041,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1833 realworld ? 1 : 0, param->length, 2041 realworld ? 1 : 0, param->length,
1834 param->vary); 2042 param->vary);
1835 retval = ctrl_out(dev, param->iterations, 2043 retval = ctrl_out(dev, param->iterations,
1836 param->length, param->vary); 2044 param->length, param->vary, 0);
1837 break; 2045 break;
1838 2046
1839 /* iso write tests */ 2047 /* iso write tests */
@@ -1844,9 +2052,9 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1844 "TEST 15: write %d iso, %d entries of %d bytes\n", 2052 "TEST 15: write %d iso, %d entries of %d bytes\n",
1845 param->iterations, 2053 param->iterations,
1846 param->sglen, param->length); 2054 param->sglen, param->length);
1847 // FIRMWARE: iso sink 2055 /* FIRMWARE: iso sink */
1848 retval = test_iso_queue (dev, param, 2056 retval = test_iso_queue(dev, param,
1849 dev->out_iso_pipe, dev->iso_out); 2057 dev->out_iso_pipe, dev->iso_out, 0);
1850 break; 2058 break;
1851 2059
1852 /* iso read tests */ 2060 /* iso read tests */
@@ -1857,17 +2065,125 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1857 "TEST 16: read %d iso, %d entries of %d bytes\n", 2065 "TEST 16: read %d iso, %d entries of %d bytes\n",
1858 param->iterations, 2066 param->iterations,
1859 param->sglen, param->length); 2067 param->sglen, param->length);
1860 // FIRMWARE: iso source 2068 /* FIRMWARE: iso source */
1861 retval = test_iso_queue (dev, param, 2069 retval = test_iso_queue(dev, param,
1862 dev->in_iso_pipe, dev->iso_in); 2070 dev->in_iso_pipe, dev->iso_in, 0);
2071 break;
2072
2073 /* FIXME scatterlist cancel (needs helper thread) */
2074
2075 /* Tests for bulk I/O using DMA mapping by core and odd address */
2076 case 17:
2077 if (dev->out_pipe == 0)
2078 break;
2079 dev_info(&intf->dev,
2080 "TEST 17: write odd addr %d bytes %u times core map\n",
2081 param->length, param->iterations);
2082
2083 retval = test_unaligned_bulk(
2084 dev, dev->out_pipe,
2085 param->length, param->iterations,
2086 0, "test17");
2087 break;
2088
2089 case 18:
2090 if (dev->in_pipe == 0)
2091 break;
2092 dev_info(&intf->dev,
2093 "TEST 18: read odd addr %d bytes %u times core map\n",
2094 param->length, param->iterations);
2095
2096 retval = test_unaligned_bulk(
2097 dev, dev->in_pipe,
2098 param->length, param->iterations,
2099 0, "test18");
2100 break;
2101
2102 /* Tests for bulk I/O using premapped coherent buffer and odd address */
2103 case 19:
2104 if (dev->out_pipe == 0)
2105 break;
2106 dev_info(&intf->dev,
2107 "TEST 19: write odd addr %d bytes %u times premapped\n",
2108 param->length, param->iterations);
2109
2110 retval = test_unaligned_bulk(
2111 dev, dev->out_pipe,
2112 param->length, param->iterations,
2113 URB_NO_TRANSFER_DMA_MAP, "test19");
2114 break;
2115
2116 case 20:
2117 if (dev->in_pipe == 0)
2118 break;
2119 dev_info(&intf->dev,
2120 "TEST 20: read odd addr %d bytes %u times premapped\n",
2121 param->length, param->iterations);
2122
2123 retval = test_unaligned_bulk(
2124 dev, dev->in_pipe,
2125 param->length, param->iterations,
2126 URB_NO_TRANSFER_DMA_MAP, "test20");
2127 break;
2128
2129 /* control write tests with unaligned buffer */
2130 case 21:
2131 if (!dev->info->ctrl_out)
2132 break;
2133 dev_info(&intf->dev,
2134 "TEST 21: %d ep0out odd addr, %d..%d vary %d\n",
2135 param->iterations,
2136 realworld ? 1 : 0, param->length,
2137 param->vary);
2138 retval = ctrl_out(dev, param->iterations,
2139 param->length, param->vary, 1);
2140 break;
2141
2142 /* unaligned iso tests */
2143 case 22:
2144 if (dev->out_iso_pipe == 0 || param->sglen == 0)
2145 break;
2146 dev_info(&intf->dev,
2147 "TEST 22: write %d iso odd, %d entries of %d bytes\n",
2148 param->iterations,
2149 param->sglen, param->length);
2150 retval = test_iso_queue(dev, param,
2151 dev->out_iso_pipe, dev->iso_out, 1);
1863 break; 2152 break;
1864 2153
1865 // FIXME unlink from queue (ring with N urbs) 2154 case 23:
2155 if (dev->in_iso_pipe == 0 || param->sglen == 0)
2156 break;
2157 dev_info(&intf->dev,
2158 "TEST 23: read %d iso odd, %d entries of %d bytes\n",
2159 param->iterations,
2160 param->sglen, param->length);
2161 retval = test_iso_queue(dev, param,
2162 dev->in_iso_pipe, dev->iso_in, 1);
2163 break;
1866 2164
1867 // FIXME scatterlist cancel (needs helper thread) 2165 /* unlink URBs from a bulk-OUT queue */
2166 case 24:
2167 if (dev->out_pipe == 0 || !param->length || param->sglen < 4)
2168 break;
2169 retval = 0;
2170 dev_info(&intf->dev, "TEST 17: unlink from %d queues of "
2171 "%d %d-byte writes\n",
2172 param->iterations, param->sglen, param->length);
2173 for (i = param->iterations; retval == 0 && i > 0; --i) {
2174 retval = unlink_queued(dev, dev->out_pipe,
2175 param->sglen, param->length);
2176 if (retval) {
2177 dev_err(&intf->dev,
2178 "unlink queued writes failed %d, "
2179 "iterations left %d\n", retval, i);
2180 break;
2181 }
2182 }
2183 break;
1868 2184
1869 } 2185 }
1870 do_gettimeofday (&param->duration); 2186 do_gettimeofday(&param->duration);
1871 param->duration.tv_sec -= start.tv_sec; 2187 param->duration.tv_sec -= start.tv_sec;
1872 param->duration.tv_usec -= start.tv_usec; 2188 param->duration.tv_usec -= start.tv_usec;
1873 if (param->duration.tv_usec < 0) { 2189 if (param->duration.tv_usec < 0) {
@@ -1880,22 +2196,22 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1880 2196
1881/*-------------------------------------------------------------------------*/ 2197/*-------------------------------------------------------------------------*/
1882 2198
1883static unsigned force_interrupt = 0; 2199static unsigned force_interrupt;
1884module_param (force_interrupt, uint, 0); 2200module_param(force_interrupt, uint, 0);
1885MODULE_PARM_DESC (force_interrupt, "0 = test default; else interrupt"); 2201MODULE_PARM_DESC(force_interrupt, "0 = test default; else interrupt");
1886 2202
1887#ifdef GENERIC 2203#ifdef GENERIC
1888static unsigned short vendor; 2204static unsigned short vendor;
1889module_param(vendor, ushort, 0); 2205module_param(vendor, ushort, 0);
1890MODULE_PARM_DESC (vendor, "vendor code (from usb-if)"); 2206MODULE_PARM_DESC(vendor, "vendor code (from usb-if)");
1891 2207
1892static unsigned short product; 2208static unsigned short product;
1893module_param(product, ushort, 0); 2209module_param(product, ushort, 0);
1894MODULE_PARM_DESC (product, "product code (from vendor)"); 2210MODULE_PARM_DESC(product, "product code (from vendor)");
1895#endif 2211#endif
1896 2212
1897static int 2213static int
1898usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id) 2214usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
1899{ 2215{
1900 struct usb_device *udev; 2216 struct usb_device *udev;
1901 struct usbtest_dev *dev; 2217 struct usbtest_dev *dev;
@@ -1903,7 +2219,7 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1903 char *rtest, *wtest; 2219 char *rtest, *wtest;
1904 char *irtest, *iwtest; 2220 char *irtest, *iwtest;
1905 2221
1906 udev = interface_to_usbdev (intf); 2222 udev = interface_to_usbdev(intf);
1907 2223
1908#ifdef GENERIC 2224#ifdef GENERIC
1909 /* specify devices by module parameters? */ 2225 /* specify devices by module parameters? */
@@ -1930,8 +2246,9 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1930 dev->intf = intf; 2246 dev->intf = intf;
1931 2247
1932 /* cacheline-aligned scratch for i/o */ 2248 /* cacheline-aligned scratch for i/o */
1933 if ((dev->buf = kmalloc (TBUF_SIZE, GFP_KERNEL)) == NULL) { 2249 dev->buf = kmalloc(TBUF_SIZE, GFP_KERNEL);
1934 kfree (dev); 2250 if (dev->buf == NULL) {
2251 kfree(dev);
1935 return -ENOMEM; 2252 return -ENOMEM;
1936 } 2253 }
1937 2254
@@ -1943,18 +2260,18 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1943 irtest = iwtest = ""; 2260 irtest = iwtest = "";
1944 if (force_interrupt || udev->speed == USB_SPEED_LOW) { 2261 if (force_interrupt || udev->speed == USB_SPEED_LOW) {
1945 if (info->ep_in) { 2262 if (info->ep_in) {
1946 dev->in_pipe = usb_rcvintpipe (udev, info->ep_in); 2263 dev->in_pipe = usb_rcvintpipe(udev, info->ep_in);
1947 rtest = " intr-in"; 2264 rtest = " intr-in";
1948 } 2265 }
1949 if (info->ep_out) { 2266 if (info->ep_out) {
1950 dev->out_pipe = usb_sndintpipe (udev, info->ep_out); 2267 dev->out_pipe = usb_sndintpipe(udev, info->ep_out);
1951 wtest = " intr-out"; 2268 wtest = " intr-out";
1952 } 2269 }
1953 } else { 2270 } else {
1954 if (info->autoconf) { 2271 if (info->autoconf) {
1955 int status; 2272 int status;
1956 2273
1957 status = get_endpoints (dev, intf); 2274 status = get_endpoints(dev, intf);
1958 if (status < 0) { 2275 if (status < 0) {
1959 WARNING(dev, "couldn't get endpoints, %d\n", 2276 WARNING(dev, "couldn't get endpoints, %d\n",
1960 status); 2277 status);
@@ -1963,10 +2280,10 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1963 /* may find bulk or ISO pipes */ 2280 /* may find bulk or ISO pipes */
1964 } else { 2281 } else {
1965 if (info->ep_in) 2282 if (info->ep_in)
1966 dev->in_pipe = usb_rcvbulkpipe (udev, 2283 dev->in_pipe = usb_rcvbulkpipe(udev,
1967 info->ep_in); 2284 info->ep_in);
1968 if (info->ep_out) 2285 if (info->ep_out)
1969 dev->out_pipe = usb_sndbulkpipe (udev, 2286 dev->out_pipe = usb_sndbulkpipe(udev,
1970 info->ep_out); 2287 info->ep_out);
1971 } 2288 }
1972 if (dev->in_pipe) 2289 if (dev->in_pipe)
@@ -1979,15 +2296,26 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1979 iwtest = " iso-out"; 2296 iwtest = " iso-out";
1980 } 2297 }
1981 2298
1982 usb_set_intfdata (intf, dev); 2299 usb_set_intfdata(intf, dev);
1983 dev_info (&intf->dev, "%s\n", info->name); 2300 dev_info(&intf->dev, "%s\n", info->name);
1984 dev_info (&intf->dev, "%s speed {control%s%s%s%s%s} tests%s\n", 2301 dev_info(&intf->dev, "%s speed {control%s%s%s%s%s} tests%s\n",
1985 ({ char *tmp; 2302 ({ char *tmp;
1986 switch (udev->speed) { 2303 switch (udev->speed) {
1987 case USB_SPEED_LOW: tmp = "low"; break; 2304 case USB_SPEED_LOW:
1988 case USB_SPEED_FULL: tmp = "full"; break; 2305 tmp = "low";
1989 case USB_SPEED_HIGH: tmp = "high"; break; 2306 break;
1990 default: tmp = "unknown"; break; 2307 case USB_SPEED_FULL:
2308 tmp = "full";
2309 break;
2310 case USB_SPEED_HIGH:
2311 tmp = "high";
2312 break;
2313 case USB_SPEED_SUPER:
2314 tmp = "super";
2315 break;
2316 default:
2317 tmp = "unknown";
2318 break;
1991 }; tmp; }), 2319 }; tmp; }),
1992 info->ctrl_out ? " in/out" : "", 2320 info->ctrl_out ? " in/out" : "",
1993 rtest, wtest, 2321 rtest, wtest,
@@ -1996,24 +2324,24 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1996 return 0; 2324 return 0;
1997} 2325}
1998 2326
1999static int usbtest_suspend (struct usb_interface *intf, pm_message_t message) 2327static int usbtest_suspend(struct usb_interface *intf, pm_message_t message)
2000{ 2328{
2001 return 0; 2329 return 0;
2002} 2330}
2003 2331
2004static int usbtest_resume (struct usb_interface *intf) 2332static int usbtest_resume(struct usb_interface *intf)
2005{ 2333{
2006 return 0; 2334 return 0;
2007} 2335}
2008 2336
2009 2337
2010static void usbtest_disconnect (struct usb_interface *intf) 2338static void usbtest_disconnect(struct usb_interface *intf)
2011{ 2339{
2012 struct usbtest_dev *dev = usb_get_intfdata (intf); 2340 struct usbtest_dev *dev = usb_get_intfdata(intf);
2013 2341
2014 usb_set_intfdata (intf, NULL); 2342 usb_set_intfdata(intf, NULL);
2015 dev_dbg (&intf->dev, "disconnect\n"); 2343 dev_dbg(&intf->dev, "disconnect\n");
2016 kfree (dev); 2344 kfree(dev);
2017} 2345}
2018 2346
2019/* Basic testing only needs a device that can source or sink bulk traffic. 2347/* Basic testing only needs a device that can source or sink bulk traffic.
@@ -2050,9 +2378,9 @@ static struct usbtest_info fw_info = {
2050 .ep_in = 2, 2378 .ep_in = 2,
2051 .ep_out = 2, 2379 .ep_out = 2,
2052 .alt = 1, 2380 .alt = 1,
2053 .autoconf = 1, // iso and ctrl_out need autoconf 2381 .autoconf = 1, /* iso and ctrl_out need autoconf */
2054 .ctrl_out = 1, 2382 .ctrl_out = 1,
2055 .iso = 1, // iso_ep's are #8 in/out 2383 .iso = 1, /* iso_ep's are #8 in/out */
2056}; 2384};
2057 2385
2058/* peripheral running Linux and 'zero.c' test firmware, or 2386/* peripheral running Linux and 'zero.c' test firmware, or
@@ -2109,56 +2437,56 @@ static const struct usb_device_id id_table[] = {
2109 */ 2437 */
2110 2438
2111 /* generic EZ-USB FX controller */ 2439 /* generic EZ-USB FX controller */
2112 { USB_DEVICE (0x0547, 0x2235), 2440 { USB_DEVICE(0x0547, 0x2235),
2113 .driver_info = (unsigned long) &ez1_info, 2441 .driver_info = (unsigned long) &ez1_info,
2114 }, 2442 },
2115 2443
2116 /* CY3671 development board with EZ-USB FX */ 2444 /* CY3671 development board with EZ-USB FX */
2117 { USB_DEVICE (0x0547, 0x0080), 2445 { USB_DEVICE(0x0547, 0x0080),
2118 .driver_info = (unsigned long) &ez1_info, 2446 .driver_info = (unsigned long) &ez1_info,
2119 }, 2447 },
2120 2448
2121 /* generic EZ-USB FX2 controller (or development board) */ 2449 /* generic EZ-USB FX2 controller (or development board) */
2122 { USB_DEVICE (0x04b4, 0x8613), 2450 { USB_DEVICE(0x04b4, 0x8613),
2123 .driver_info = (unsigned long) &ez2_info, 2451 .driver_info = (unsigned long) &ez2_info,
2124 }, 2452 },
2125 2453
2126 /* re-enumerated usb test device firmware */ 2454 /* re-enumerated usb test device firmware */
2127 { USB_DEVICE (0xfff0, 0xfff0), 2455 { USB_DEVICE(0xfff0, 0xfff0),
2128 .driver_info = (unsigned long) &fw_info, 2456 .driver_info = (unsigned long) &fw_info,
2129 }, 2457 },
2130 2458
2131 /* "Gadget Zero" firmware runs under Linux */ 2459 /* "Gadget Zero" firmware runs under Linux */
2132 { USB_DEVICE (0x0525, 0xa4a0), 2460 { USB_DEVICE(0x0525, 0xa4a0),
2133 .driver_info = (unsigned long) &gz_info, 2461 .driver_info = (unsigned long) &gz_info,
2134 }, 2462 },
2135 2463
2136 /* so does a user-mode variant */ 2464 /* so does a user-mode variant */
2137 { USB_DEVICE (0x0525, 0xa4a4), 2465 { USB_DEVICE(0x0525, 0xa4a4),
2138 .driver_info = (unsigned long) &um_info, 2466 .driver_info = (unsigned long) &um_info,
2139 }, 2467 },
2140 2468
2141 /* ... and a user-mode variant that talks iso */ 2469 /* ... and a user-mode variant that talks iso */
2142 { USB_DEVICE (0x0525, 0xa4a3), 2470 { USB_DEVICE(0x0525, 0xa4a3),
2143 .driver_info = (unsigned long) &um2_info, 2471 .driver_info = (unsigned long) &um2_info,
2144 }, 2472 },
2145 2473
2146#ifdef KEYSPAN_19Qi 2474#ifdef KEYSPAN_19Qi
2147 /* Keyspan 19qi uses an21xx (original EZ-USB) */ 2475 /* Keyspan 19qi uses an21xx (original EZ-USB) */
2148 // this does not coexist with the real Keyspan 19qi driver! 2476 /* this does not coexist with the real Keyspan 19qi driver! */
2149 { USB_DEVICE (0x06cd, 0x010b), 2477 { USB_DEVICE(0x06cd, 0x010b),
2150 .driver_info = (unsigned long) &ez1_info, 2478 .driver_info = (unsigned long) &ez1_info,
2151 }, 2479 },
2152#endif 2480#endif
2153 2481
2154 /*-------------------------------------------------------------*/ 2482 /*-------------------------------------------------------------*/
2155 2483
2156#ifdef IBOT2 2484#ifdef IBOT2
2157 /* iBOT2 makes a nice source of high speed bulk-in data */ 2485 /* iBOT2 makes a nice source of high speed bulk-in data */
2158 // this does not coexist with a real iBOT2 driver! 2486 /* this does not coexist with a real iBOT2 driver! */
2159 { USB_DEVICE (0x0b62, 0x0059), 2487 { USB_DEVICE(0x0b62, 0x0059),
2160 .driver_info = (unsigned long) &ibot2_info, 2488 .driver_info = (unsigned long) &ibot2_info,
2161 }, 2489 },
2162#endif 2490#endif
2163 2491
2164 /*-------------------------------------------------------------*/ 2492 /*-------------------------------------------------------------*/
@@ -2172,7 +2500,7 @@ static const struct usb_device_id id_table[] = {
2172 2500
2173 { } 2501 { }
2174}; 2502};
2175MODULE_DEVICE_TABLE (usb, id_table); 2503MODULE_DEVICE_TABLE(usb, id_table);
2176 2504
2177static struct usb_driver usbtest_driver = { 2505static struct usb_driver usbtest_driver = {
2178 .name = "usbtest", 2506 .name = "usbtest",
@@ -2186,22 +2514,22 @@ static struct usb_driver usbtest_driver = {
2186 2514
2187/*-------------------------------------------------------------------------*/ 2515/*-------------------------------------------------------------------------*/
2188 2516
2189static int __init usbtest_init (void) 2517static int __init usbtest_init(void)
2190{ 2518{
2191#ifdef GENERIC 2519#ifdef GENERIC
2192 if (vendor) 2520 if (vendor)
2193 pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product); 2521 pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product);
2194#endif 2522#endif
2195 return usb_register (&usbtest_driver); 2523 return usb_register(&usbtest_driver);
2196} 2524}
2197module_init (usbtest_init); 2525module_init(usbtest_init);
2198 2526
2199static void __exit usbtest_exit (void) 2527static void __exit usbtest_exit(void)
2200{ 2528{
2201 usb_deregister (&usbtest_driver); 2529 usb_deregister(&usbtest_driver);
2202} 2530}
2203module_exit (usbtest_exit); 2531module_exit(usbtest_exit);
2204 2532
2205MODULE_DESCRIPTION ("USB Core/HCD Testing Driver"); 2533MODULE_DESCRIPTION("USB Core/HCD Testing Driver");
2206MODULE_LICENSE ("GPL"); 2534MODULE_LICENSE("GPL");
2207 2535
diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
index 796e2f68f749..8b1d94a76914 100644
--- a/drivers/usb/misc/uss720.c
+++ b/drivers/usb/misc/uss720.c
@@ -3,7 +3,7 @@
3/* 3/*
4 * uss720.c -- USS720 USB Parport Cable. 4 * uss720.c -- USS720 USB Parport Cable.
5 * 5 *
6 * Copyright (C) 1999, 2005 6 * Copyright (C) 1999, 2005, 2010
7 * Thomas Sailer (t.sailer@alumni.ethz.ch) 7 * Thomas Sailer (t.sailer@alumni.ethz.ch)
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
@@ -177,12 +177,11 @@ static struct uss720_async_request *submit_async_request(struct parport_uss720_p
177 spin_lock_irqsave(&priv->asynclock, flags); 177 spin_lock_irqsave(&priv->asynclock, flags);
178 list_add_tail(&rq->asynclist, &priv->asynclist); 178 list_add_tail(&rq->asynclist, &priv->asynclist);
179 spin_unlock_irqrestore(&priv->asynclock, flags); 179 spin_unlock_irqrestore(&priv->asynclock, flags);
180 kref_get(&rq->ref_count);
180 ret = usb_submit_urb(rq->urb, mem_flags); 181 ret = usb_submit_urb(rq->urb, mem_flags);
181 if (!ret) { 182 if (!ret)
182 kref_get(&rq->ref_count);
183 return rq; 183 return rq;
184 } 184 destroy_async(&rq->ref_count);
185 kref_put(&rq->ref_count, destroy_async);
186 err("submit_async_request submit_urb failed with %d", ret); 185 err("submit_async_request submit_urb failed with %d", ret);
187 return NULL; 186 return NULL;
188} 187}
@@ -776,6 +775,7 @@ static const struct usb_device_id uss720_table[] = {
776 { USB_DEVICE(0x0557, 0x2001) }, 775 { USB_DEVICE(0x0557, 0x2001) },
777 { USB_DEVICE(0x0729, 0x1284) }, 776 { USB_DEVICE(0x0729, 0x1284) },
778 { USB_DEVICE(0x1293, 0x0002) }, 777 { USB_DEVICE(0x1293, 0x0002) },
778 { USB_DEVICE(0x050d, 0x0002) },
779 { } /* Terminating entry */ 779 { } /* Terminating entry */
780}; 780};
781 781
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
new file mode 100644
index 000000000000..ac5bfd619e62
--- /dev/null
+++ b/drivers/usb/misc/yurex.c
@@ -0,0 +1,564 @@
1/*
2 * Driver for Meywa-Denki & KAYAC YUREX
3 *
4 * Copyright (C) 2010 Tomoki Sekiyama (tomoki.sekiyama@gmail.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/module.h>
17#include <linux/kref.h>
18#include <linux/mutex.h>
19#include <linux/uaccess.h>
20#include <linux/usb.h>
21#include <linux/hid.h>
22
23#define DRIVER_AUTHOR "Tomoki Sekiyama"
24#define DRIVER_DESC "Driver for Meywa-Denki & KAYAC YUREX"
25
26#define YUREX_VENDOR_ID 0x0c45
27#define YUREX_PRODUCT_ID 0x1010
28
29#define CMD_ACK '!'
30#define CMD_ANIMATE 'A'
31#define CMD_COUNT 'C'
32#define CMD_LED 'L'
33#define CMD_READ 'R'
34#define CMD_SET 'S'
35#define CMD_VERSION 'V'
36#define CMD_EOF 0x0d
37#define CMD_PADDING 0xff
38
39#define YUREX_BUF_SIZE 8
40#define YUREX_WRITE_TIMEOUT (HZ*2)
41
42/* table of devices that work with this driver */
43static struct usb_device_id yurex_table[] = {
44 { USB_DEVICE(YUREX_VENDOR_ID, YUREX_PRODUCT_ID) },
45 { } /* Terminating entry */
46};
47MODULE_DEVICE_TABLE(usb, yurex_table);
48
49#ifdef CONFIG_USB_DYNAMIC_MINORS
50#define YUREX_MINOR_BASE 0
51#else
52#define YUREX_MINOR_BASE 192
53#endif
54
55/* Structure to hold all of our device specific stuff */
56struct usb_yurex {
57 struct usb_device *udev;
58 struct usb_interface *interface;
59 __u8 int_in_endpointAddr;
60 struct urb *urb; /* URB for interrupt in */
61 unsigned char *int_buffer; /* buffer for intterupt in */
62 struct urb *cntl_urb; /* URB for control msg */
63 struct usb_ctrlrequest *cntl_req; /* req for control msg */
64 unsigned char *cntl_buffer; /* buffer for control msg */
65
66 struct kref kref;
67 struct mutex io_mutex;
68 struct fasync_struct *async_queue;
69 wait_queue_head_t waitq;
70
71 spinlock_t lock;
72 __s64 bbu; /* BBU from device */
73};
74#define to_yurex_dev(d) container_of(d, struct usb_yurex, kref)
75
76static struct usb_driver yurex_driver;
77static const struct file_operations yurex_fops;
78
79
80static void yurex_control_callback(struct urb *urb)
81{
82 struct usb_yurex *dev = urb->context;
83 int status = urb->status;
84
85 if (status) {
86 err("%s - control failed: %d\n", __func__, status);
87 wake_up_interruptible(&dev->waitq);
88 return;
89 }
90 /* on success, sender woken up by CMD_ACK int in, or timeout */
91}
92
93static void yurex_delete(struct kref *kref)
94{
95 struct usb_yurex *dev = to_yurex_dev(kref);
96
97 dbg("yurex_delete");
98
99 usb_put_dev(dev->udev);
100 if (dev->cntl_urb) {
101 usb_kill_urb(dev->cntl_urb);
102 if (dev->cntl_req)
103 usb_free_coherent(dev->udev, YUREX_BUF_SIZE,
104 dev->cntl_req, dev->cntl_urb->setup_dma);
105 if (dev->cntl_buffer)
106 usb_free_coherent(dev->udev, YUREX_BUF_SIZE,
107 dev->cntl_buffer, dev->cntl_urb->transfer_dma);
108 usb_free_urb(dev->cntl_urb);
109 }
110 if (dev->urb) {
111 usb_kill_urb(dev->urb);
112 if (dev->int_buffer)
113 usb_free_coherent(dev->udev, YUREX_BUF_SIZE,
114 dev->int_buffer, dev->urb->transfer_dma);
115 usb_free_urb(dev->urb);
116 }
117 kfree(dev);
118}
119
120/*
121 * usb class driver info in order to get a minor number from the usb core,
122 * and to have the device registered with the driver core
123 */
124static struct usb_class_driver yurex_class = {
125 .name = "yurex%d",
126 .fops = &yurex_fops,
127 .minor_base = YUREX_MINOR_BASE,
128};
129
130static void yurex_interrupt(struct urb *urb)
131{
132 struct usb_yurex *dev = urb->context;
133 unsigned char *buf = dev->int_buffer;
134 int status = urb->status;
135 unsigned long flags;
136 int retval, i;
137
138 switch (status) {
139 case 0: /*success*/
140 break;
141 case -EOVERFLOW:
142 err("%s - overflow with length %d, actual length is %d",
143 __func__, YUREX_BUF_SIZE, dev->urb->actual_length);
144 case -ECONNRESET:
145 case -ENOENT:
146 case -ESHUTDOWN:
147 case -EILSEQ:
148 /* The device is terminated, clean up */
149 return;
150 default:
151 err("%s - unknown status received: %d", __func__, status);
152 goto exit;
153 }
154
155 /* handle received message */
156 switch (buf[0]) {
157 case CMD_COUNT:
158 case CMD_READ:
159 if (buf[6] == CMD_EOF) {
160 spin_lock_irqsave(&dev->lock, flags);
161 dev->bbu = 0;
162 for (i = 1; i < 6; i++) {
163 dev->bbu += buf[i];
164 if (i != 5)
165 dev->bbu <<= 8;
166 }
167 dbg("%s count: %lld", __func__, dev->bbu);
168 spin_unlock_irqrestore(&dev->lock, flags);
169
170 kill_fasync(&dev->async_queue, SIGIO, POLL_IN);
171 }
172 else
173 dbg("data format error - no EOF");
174 break;
175 case CMD_ACK:
176 dbg("%s ack: %c", __func__, buf[1]);
177 wake_up_interruptible(&dev->waitq);
178 break;
179 }
180
181exit:
182 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
183 if (retval) {
184 err("%s - usb_submit_urb failed: %d",
185 __func__, retval);
186 }
187}
188
189static int yurex_probe(struct usb_interface *interface, const struct usb_device_id *id)
190{
191 struct usb_yurex *dev;
192 struct usb_host_interface *iface_desc;
193 struct usb_endpoint_descriptor *endpoint;
194 int retval = -ENOMEM;
195 int i;
196 DEFINE_WAIT(wait);
197
198 /* allocate memory for our device state and initialize it */
199 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
200 if (!dev) {
201 err("Out of memory");
202 goto error;
203 }
204 kref_init(&dev->kref);
205 mutex_init(&dev->io_mutex);
206 spin_lock_init(&dev->lock);
207 init_waitqueue_head(&dev->waitq);
208
209 dev->udev = usb_get_dev(interface_to_usbdev(interface));
210 dev->interface = interface;
211
212 /* set up the endpoint information */
213 iface_desc = interface->cur_altsetting;
214 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
215 endpoint = &iface_desc->endpoint[i].desc;
216
217 if (usb_endpoint_is_int_in(endpoint)) {
218 dev->int_in_endpointAddr = endpoint->bEndpointAddress;
219 break;
220 }
221 }
222 if (!dev->int_in_endpointAddr) {
223 retval = -ENODEV;
224 err("Could not find endpoints");
225 goto error;
226 }
227
228
229 /* allocate control URB */
230 dev->cntl_urb = usb_alloc_urb(0, GFP_KERNEL);
231 if (!dev->cntl_urb) {
232 err("Could not allocate control URB");
233 goto error;
234 }
235
236 /* allocate buffer for control req */
237 dev->cntl_req = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE,
238 GFP_KERNEL,
239 &dev->cntl_urb->setup_dma);
240 if (!dev->cntl_req) {
241 err("Could not allocate cntl_req");
242 goto error;
243 }
244
245 /* allocate buffer for control msg */
246 dev->cntl_buffer = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE,
247 GFP_KERNEL,
248 &dev->cntl_urb->transfer_dma);
249 if (!dev->cntl_buffer) {
250 err("Could not allocate cntl_buffer");
251 goto error;
252 }
253
254 /* configure control URB */
255 dev->cntl_req->bRequestType = USB_DIR_OUT | USB_TYPE_CLASS |
256 USB_RECIP_INTERFACE;
257 dev->cntl_req->bRequest = HID_REQ_SET_REPORT;
258 dev->cntl_req->wValue = cpu_to_le16((HID_OUTPUT_REPORT + 1) << 8);
259 dev->cntl_req->wIndex = cpu_to_le16(iface_desc->desc.bInterfaceNumber);
260 dev->cntl_req->wLength = cpu_to_le16(YUREX_BUF_SIZE);
261
262 usb_fill_control_urb(dev->cntl_urb, dev->udev,
263 usb_sndctrlpipe(dev->udev, 0),
264 (void *)dev->cntl_req, dev->cntl_buffer,
265 YUREX_BUF_SIZE, yurex_control_callback, dev);
266 dev->cntl_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
267
268
269 /* allocate interrupt URB */
270 dev->urb = usb_alloc_urb(0, GFP_KERNEL);
271 if (!dev->urb) {
272 err("Could not allocate URB");
273 goto error;
274 }
275
276 /* allocate buffer for interrupt in */
277 dev->int_buffer = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE,
278 GFP_KERNEL, &dev->urb->transfer_dma);
279 if (!dev->int_buffer) {
280 err("Could not allocate int_buffer");
281 goto error;
282 }
283
284 /* configure interrupt URB */
285 usb_fill_int_urb(dev->urb, dev->udev,
286 usb_rcvintpipe(dev->udev, dev->int_in_endpointAddr),
287 dev->int_buffer, YUREX_BUF_SIZE, yurex_interrupt,
288 dev, 1);
289 dev->cntl_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
290 if (usb_submit_urb(dev->urb, GFP_KERNEL)) {
291 retval = -EIO;
292 err("Could not submitting URB");
293 goto error;
294 }
295
296 /* save our data pointer in this interface device */
297 usb_set_intfdata(interface, dev);
298
299 /* we can register the device now, as it is ready */
300 retval = usb_register_dev(interface, &yurex_class);
301 if (retval) {
302 err("Not able to get a minor for this device.");
303 usb_set_intfdata(interface, NULL);
304 goto error;
305 }
306
307 dev->bbu = -1;
308
309 dev_info(&interface->dev,
310 "USB YUREX device now attached to Yurex #%d\n",
311 interface->minor);
312
313 return 0;
314
315error:
316 if (dev)
317 /* this frees allocated memory */
318 kref_put(&dev->kref, yurex_delete);
319 return retval;
320}
321
322static void yurex_disconnect(struct usb_interface *interface)
323{
324 struct usb_yurex *dev;
325 int minor = interface->minor;
326
327 dev = usb_get_intfdata(interface);
328 usb_set_intfdata(interface, NULL);
329
330 /* give back our minor */
331 usb_deregister_dev(interface, &yurex_class);
332
333 /* prevent more I/O from starting */
334 mutex_lock(&dev->io_mutex);
335 dev->interface = NULL;
336 mutex_unlock(&dev->io_mutex);
337
338 /* wakeup waiters */
339 kill_fasync(&dev->async_queue, SIGIO, POLL_IN);
340 wake_up_interruptible(&dev->waitq);
341
342 /* decrement our usage count */
343 kref_put(&dev->kref, yurex_delete);
344
345 dev_info(&interface->dev, "USB YUREX #%d now disconnected\n", minor);
346}
347
348static struct usb_driver yurex_driver = {
349 .name = "yurex",
350 .probe = yurex_probe,
351 .disconnect = yurex_disconnect,
352 .id_table = yurex_table,
353};
354
355
356static int yurex_fasync(int fd, struct file *file, int on)
357{
358 struct usb_yurex *dev;
359
360 dev = (struct usb_yurex *)file->private_data;
361 return fasync_helper(fd, file, on, &dev->async_queue);
362}
363
364static int yurex_open(struct inode *inode, struct file *file)
365{
366 struct usb_yurex *dev;
367 struct usb_interface *interface;
368 int subminor;
369 int retval = 0;
370
371 subminor = iminor(inode);
372
373 interface = usb_find_interface(&yurex_driver, subminor);
374 if (!interface) {
375 err("%s - error, can't find device for minor %d",
376 __func__, subminor);
377 retval = -ENODEV;
378 goto exit;
379 }
380
381 dev = usb_get_intfdata(interface);
382 if (!dev) {
383 retval = -ENODEV;
384 goto exit;
385 }
386
387 /* increment our usage count for the device */
388 kref_get(&dev->kref);
389
390 /* save our object in the file's private structure */
391 mutex_lock(&dev->io_mutex);
392 file->private_data = dev;
393 mutex_unlock(&dev->io_mutex);
394
395exit:
396 return retval;
397}
398
399static int yurex_release(struct inode *inode, struct file *file)
400{
401 struct usb_yurex *dev;
402
403 dev = (struct usb_yurex *)file->private_data;
404 if (dev == NULL)
405 return -ENODEV;
406
407 yurex_fasync(-1, file, 0);
408
409 /* decrement the count on our device */
410 kref_put(&dev->kref, yurex_delete);
411 return 0;
412}
413
414static ssize_t yurex_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
415{
416 struct usb_yurex *dev;
417 int retval = 0;
418 int bytes_read = 0;
419 char in_buffer[20];
420 unsigned long flags;
421
422 dev = (struct usb_yurex *)file->private_data;
423
424 mutex_lock(&dev->io_mutex);
425 if (!dev->interface) { /* already disconnected */
426 retval = -ENODEV;
427 goto exit;
428 }
429
430 spin_lock_irqsave(&dev->lock, flags);
431 bytes_read = snprintf(in_buffer, 20, "%lld\n", dev->bbu);
432 spin_unlock_irqrestore(&dev->lock, flags);
433
434 if (*ppos < bytes_read) {
435 if (copy_to_user(buffer, in_buffer + *ppos, bytes_read - *ppos))
436 retval = -EFAULT;
437 else {
438 retval = bytes_read - *ppos;
439 *ppos += bytes_read;
440 }
441 }
442
443exit:
444 mutex_unlock(&dev->io_mutex);
445 return retval;
446}
447
448static ssize_t yurex_write(struct file *file, const char *user_buffer, size_t count, loff_t *ppos)
449{
450 struct usb_yurex *dev;
451 int i, set = 0, retval = 0;
452 char buffer[16];
453 char *data = buffer;
454 unsigned long long c, c2 = 0;
455 signed long timeout = 0;
456 DEFINE_WAIT(wait);
457
458 count = min(sizeof(buffer), count);
459 dev = (struct usb_yurex *)file->private_data;
460
461 /* verify that we actually have some data to write */
462 if (count == 0)
463 goto error;
464
465 mutex_lock(&dev->io_mutex);
466 if (!dev->interface) { /* alreaday disconnected */
467 mutex_unlock(&dev->io_mutex);
468 retval = -ENODEV;
469 goto error;
470 }
471
472 if (copy_from_user(buffer, user_buffer, count)) {
473 mutex_unlock(&dev->io_mutex);
474 retval = -EFAULT;
475 goto error;
476 }
477 memset(dev->cntl_buffer, CMD_PADDING, YUREX_BUF_SIZE);
478
479 switch (buffer[0]) {
480 case CMD_ANIMATE:
481 case CMD_LED:
482 dev->cntl_buffer[0] = buffer[0];
483 dev->cntl_buffer[1] = buffer[1];
484 dev->cntl_buffer[2] = CMD_EOF;
485 break;
486 case CMD_READ:
487 case CMD_VERSION:
488 dev->cntl_buffer[0] = buffer[0];
489 dev->cntl_buffer[1] = 0x00;
490 dev->cntl_buffer[2] = CMD_EOF;
491 break;
492 case CMD_SET:
493 data++;
494 /* FALL THROUGH */
495 case '0' ... '9':
496 set = 1;
497 c = c2 = simple_strtoull(data, NULL, 0);
498 dev->cntl_buffer[0] = CMD_SET;
499 for (i = 1; i < 6; i++) {
500 dev->cntl_buffer[i] = (c>>32) & 0xff;
501 c <<= 8;
502 }
503 buffer[6] = CMD_EOF;
504 break;
505 default:
506 mutex_unlock(&dev->io_mutex);
507 return -EINVAL;
508 }
509
510 /* send the data as the control msg */
511 prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);
512 dbg("%s - submit %c", __func__, dev->cntl_buffer[0]);
513 retval = usb_submit_urb(dev->cntl_urb, GFP_KERNEL);
514 if (retval >= 0)
515 timeout = schedule_timeout(YUREX_WRITE_TIMEOUT);
516 finish_wait(&dev->waitq, &wait);
517
518 mutex_unlock(&dev->io_mutex);
519
520 if (retval < 0) {
521 err("%s - failed to send bulk msg, error %d", __func__, retval);
522 goto error;
523 }
524 if (set && timeout)
525 dev->bbu = c2;
526 return timeout ? count : -EIO;
527
528error:
529 return retval;
530}
531
532static const struct file_operations yurex_fops = {
533 .owner = THIS_MODULE,
534 .read = yurex_read,
535 .write = yurex_write,
536 .open = yurex_open,
537 .release = yurex_release,
538 .fasync = yurex_fasync,
539 .llseek = default_llseek,
540};
541
542
543static int __init usb_yurex_init(void)
544{
545 int result;
546
547 /* register this driver with the USB subsystem */
548 result = usb_register(&yurex_driver);
549 if (result)
550 err("usb_register failed. Error number %d", result);
551
552 return result;
553}
554
555static void __exit usb_yurex_exit(void)
556{
557 /* deregister this driver with the USB subsystem */
558 usb_deregister(&yurex_driver);
559}
560
561module_init(usb_yurex_init);
562module_exit(usb_yurex_exit);
563
564MODULE_LICENSE("GPL");
diff --git a/drivers/usb/mon/Makefile b/drivers/usb/mon/Makefile
index 384b198faa7c..8ed24ab08698 100644
--- a/drivers/usb/mon/Makefile
+++ b/drivers/usb/mon/Makefile
@@ -2,6 +2,6 @@
2# Makefile for USB monitor 2# Makefile for USB monitor
3# 3#
4 4
5usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_bin.o 5usbmon-y := mon_main.o mon_stat.o mon_text.o mon_bin.o
6 6
7obj-$(CONFIG_USB_MON) += usbmon.o 7obj-$(CONFIG_USB_MON) += usbmon.o
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 44cb37b5a4dc..a09dbd243eb3 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -15,7 +15,6 @@
15#include <linux/poll.h> 15#include <linux/poll.h>
16#include <linux/compat.h> 16#include <linux/compat.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/smp_lock.h>
19#include <linux/scatterlist.h> 18#include <linux/scatterlist.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21 20
@@ -437,6 +436,28 @@ static unsigned int mon_bin_get_data(const struct mon_reader_bin *rp,
437 return length; 436 return length;
438} 437}
439 438
439/*
440 * This is the look-ahead pass in case of 'C Zi', when actual_length cannot
441 * be used to determine the length of the whole contiguous buffer.
442 */
443static unsigned int mon_bin_collate_isodesc(const struct mon_reader_bin *rp,
444 struct urb *urb, unsigned int ndesc)
445{
446 struct usb_iso_packet_descriptor *fp;
447 unsigned int length;
448
449 length = 0;
450 fp = urb->iso_frame_desc;
451 while (ndesc-- != 0) {
452 if (fp->actual_length != 0) {
453 if (fp->offset + fp->actual_length > length)
454 length = fp->offset + fp->actual_length;
455 }
456 fp++;
457 }
458 return length;
459}
460
440static void mon_bin_get_isodesc(const struct mon_reader_bin *rp, 461static void mon_bin_get_isodesc(const struct mon_reader_bin *rp,
441 unsigned int offset, struct urb *urb, char ev_type, unsigned int ndesc) 462 unsigned int offset, struct urb *urb, char ev_type, unsigned int ndesc)
442{ 463{
@@ -479,6 +500,10 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
479 /* 500 /*
480 * Find the maximum allowable length, then allocate space. 501 * Find the maximum allowable length, then allocate space.
481 */ 502 */
503 urb_length = (ev_type == 'S') ?
504 urb->transfer_buffer_length : urb->actual_length;
505 length = urb_length;
506
482 if (usb_endpoint_xfer_isoc(epd)) { 507 if (usb_endpoint_xfer_isoc(epd)) {
483 if (urb->number_of_packets < 0) { 508 if (urb->number_of_packets < 0) {
484 ndesc = 0; 509 ndesc = 0;
@@ -487,14 +512,16 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
487 } else { 512 } else {
488 ndesc = urb->number_of_packets; 513 ndesc = urb->number_of_packets;
489 } 514 }
515 if (ev_type == 'C' && usb_urb_dir_in(urb))
516 length = mon_bin_collate_isodesc(rp, urb, ndesc);
490 } else { 517 } else {
491 ndesc = 0; 518 ndesc = 0;
492 } 519 }
493 lendesc = ndesc*sizeof(struct mon_bin_isodesc); 520 lendesc = ndesc*sizeof(struct mon_bin_isodesc);
494 521
495 urb_length = (ev_type == 'S') ? 522 /* not an issue unless there's a subtle bug in a HCD somewhere */
496 urb->transfer_buffer_length : urb->actual_length; 523 if (length >= urb->transfer_buffer_length)
497 length = urb_length; 524 length = urb->transfer_buffer_length;
498 525
499 if (length >= rp->b_size/5) 526 if (length >= rp->b_size/5)
500 length = rp->b_size/5; 527 length = rp->b_size/5;
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index 812dc288bb8c..10405119985c 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -90,7 +90,6 @@ static void mon_bus_submit(struct mon_bus *mbus, struct urb *urb)
90 r->rnf_submit(r->r_data, urb); 90 r->rnf_submit(r->r_data, urb);
91 } 91 }
92 spin_unlock_irqrestore(&mbus->lock, flags); 92 spin_unlock_irqrestore(&mbus->lock, flags);
93 return;
94} 93}
95 94
96static void mon_submit(struct usb_bus *ubus, struct urb *urb) 95static void mon_submit(struct usb_bus *ubus, struct urb *urb)
@@ -117,7 +116,6 @@ static void mon_bus_submit_error(struct mon_bus *mbus, struct urb *urb, int erro
117 r->rnf_error(r->r_data, urb, error); 116 r->rnf_error(r->r_data, urb, error);
118 } 117 }
119 spin_unlock_irqrestore(&mbus->lock, flags); 118 spin_unlock_irqrestore(&mbus->lock, flags);
120 return;
121} 119}
122 120
123static void mon_submit_error(struct usb_bus *ubus, struct urb *urb, int error) 121static void mon_submit_error(struct usb_bus *ubus, struct urb *urb, int error)
diff --git a/drivers/usb/mon/mon_stat.c b/drivers/usb/mon/mon_stat.c
index 8ec94f15a738..e5ce42bd316e 100644
--- a/drivers/usb/mon/mon_stat.c
+++ b/drivers/usb/mon/mon_stat.c
@@ -11,7 +11,6 @@
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/usb.h> 12#include <linux/usb.h>
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/smp_lock.h>
15#include <asm/uaccess.h> 14#include <asm/uaccess.h>
16 15
17#include "usb_mon.h" 16#include "usb_mon.h"
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index a545d65f6e57..c302e1983c70 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -236,6 +236,9 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb,
236 fp++; 236 fp++;
237 dp++; 237 dp++;
238 } 238 }
239 /* Wasteful, but simple to understand: ISO 'C' is sparse. */
240 if (ev_type == 'C')
241 ep->length = urb->transfer_buffer_length;
239 } 242 }
240 243
241 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus); 244 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus);
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index cfd38edfcf9e..13093481f918 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -12,6 +12,7 @@ config USB_MUSB_HDRC
12 depends on (ARM || (BF54x && !BF544) || (BF52x && !BF522 && !BF523)) 12 depends on (ARM || (BF54x && !BF544) || (BF52x && !BF522 && !BF523))
13 select NOP_USB_XCEIV if (ARCH_DAVINCI || MACH_OMAP3EVM || BLACKFIN) 13 select NOP_USB_XCEIV if (ARCH_DAVINCI || MACH_OMAP3EVM || BLACKFIN)
14 select TWL4030_USB if MACH_OMAP_3430SDP 14 select TWL4030_USB if MACH_OMAP_3430SDP
15 select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
15 select USB_OTG_UTILS 16 select USB_OTG_UTILS
16 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' 17 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
17 help 18 help
@@ -30,43 +31,41 @@ config USB_MUSB_HDRC
30 If you do not know what this is, please say N. 31 If you do not know what this is, please say N.
31 32
32 To compile this driver as a module, choose M here; the 33 To compile this driver as a module, choose M here; the
33 module will be called "musb_hdrc". 34 module will be called "musb-hdrc".
34 35
35config USB_MUSB_SOC 36choice
36 boolean 37 prompt "Platform Glue Layer"
37 depends on USB_MUSB_HDRC 38 depends on USB_MUSB_HDRC
38 default y if ARCH_DAVINCI
39 default y if ARCH_OMAP2430
40 default y if ARCH_OMAP3
41 default y if ARCH_OMAP4
42 default y if (BF54x && !BF544)
43 default y if (BF52x && !BF522 && !BF523)
44 39
45comment "DaVinci 35x and 644x USB support" 40config USB_MUSB_DAVINCI
46 depends on USB_MUSB_HDRC && ARCH_DAVINCI_DMx 41 tristate "DaVinci"
42 depends on ARCH_DAVINCI_DMx
47 43
48comment "OMAP 243x high speed USB support" 44config USB_MUSB_DA8XX
49 depends on USB_MUSB_HDRC && ARCH_OMAP2430 45 tristate "DA8xx/OMAP-L1x"
46 depends on ARCH_DAVINCI_DA8XX
50 47
51comment "OMAP 343x high speed USB support" 48config USB_MUSB_TUSB6010
52 depends on USB_MUSB_HDRC && ARCH_OMAP3 49 tristate "TUSB6010"
50 depends on ARCH_OMAP
53 51
54comment "OMAP 44xx high speed USB support" 52config USB_MUSB_OMAP2PLUS
55 depends on USB_MUSB_HDRC && ARCH_OMAP4 53 tristate "OMAP2430 and onwards"
54 depends on ARCH_OMAP2PLUS
56 55
57comment "Blackfin high speed USB Support" 56config USB_MUSB_AM35X
58 depends on USB_MUSB_HDRC && ((BF54x && !BF544) || (BF52x && !BF522 && !BF523)) 57 tristate "AM35x"
58 depends on ARCH_OMAP
59 59
60config USB_TUSB6010 60config USB_MUSB_BLACKFIN
61 boolean "TUSB 6010 support" 61 tristate "Blackfin"
62 depends on USB_MUSB_HDRC && !USB_MUSB_SOC 62 depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523)
63 select NOP_USB_XCEIV 63
64 default y 64config USB_MUSB_UX500
65 help 65 tristate "U8500 and U5500"
66 The TUSB 6010 chip, from Texas Instruments, connects a discrete 66 depends on (ARCH_U8500 && AB8500_USB) || (ARCH_U5500)
67 HDRC core using a 16-bit parallel bus (NOR flash style) or VLYNQ 67
68 (a high speed serial link). It can use system-specific external 68endchoice
69 DMA controllers.
70 69
71choice 70choice
72 prompt "Driver Mode" 71 prompt "Driver Mode"
@@ -144,7 +143,7 @@ config USB_MUSB_HDRC_HCD
144config MUSB_PIO_ONLY 143config MUSB_PIO_ONLY
145 bool 'Disable DMA (always use PIO)' 144 bool 'Disable DMA (always use PIO)'
146 depends on USB_MUSB_HDRC 145 depends on USB_MUSB_HDRC
147 default y if USB_TUSB6010 146 default USB_MUSB_TUSB6010 || USB_MUSB_DA8XX || USB_MUSB_AM35X
148 help 147 help
149 All data is copied between memory and FIFO by the CPU. 148 All data is copied between memory and FIFO by the CPU.
150 DMA controllers are ignored. 149 DMA controllers are ignored.
@@ -154,34 +153,33 @@ config MUSB_PIO_ONLY
154 you can still disable it at run time using the "use_dma=n" module 153 you can still disable it at run time using the "use_dma=n" module
155 parameter. 154 parameter.
156 155
156config USB_UX500_DMA
157 bool
158 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
159 default USB_MUSB_UX500
160 help
161 Enable DMA transfers on UX500 platforms.
162
157config USB_INVENTRA_DMA 163config USB_INVENTRA_DMA
158 bool 164 bool
159 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY 165 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
160 default ARCH_OMAP2430 || ARCH_OMAP3 || BLACKFIN || ARCH_OMAP4 166 default USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN
161 help 167 help
162 Enable DMA transfers using Mentor's engine. 168 Enable DMA transfers using Mentor's engine.
163 169
164config USB_TI_CPPI_DMA 170config USB_TI_CPPI_DMA
165 bool 171 bool
166 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY 172 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
167 default ARCH_DAVINCI 173 default USB_MUSB_DAVINCI
168 help 174 help
169 Enable DMA transfers when TI CPPI DMA is available. 175 Enable DMA transfers when TI CPPI DMA is available.
170 176
171config USB_TUSB_OMAP_DMA 177config USB_TUSB_OMAP_DMA
172 bool 178 bool
173 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY 179 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
174 depends on USB_TUSB6010 180 depends on USB_MUSB_TUSB6010
175 depends on ARCH_OMAP 181 depends on ARCH_OMAP
176 default y 182 default y
177 help 183 help
178 Enable DMA transfers on TUSB 6010 when OMAP DMA is available. 184 Enable DMA transfers on TUSB 6010 when OMAP DMA is available.
179 185
180config USB_MUSB_DEBUG
181 depends on USB_MUSB_HDRC
182 bool "Enable debugging messages"
183 default n
184 help
185 This enables musb debugging. To set the logging level use the debug
186 module parameter. Starting at level 3, per-transfer (urb, usb_request,
187 packet, or dma transfer) tracing may kick in.
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index 9705f716386e..c4d228b6ef8a 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -2,49 +2,22 @@
2# for USB OTG silicon based on Mentor Graphics INVENTRA designs 2# for USB OTG silicon based on Mentor Graphics INVENTRA designs
3# 3#
4 4
5musb_hdrc-objs := musb_core.o 5obj-$(CONFIG_USB_MUSB_HDRC) += musb_hdrc.o
6 6
7obj-$(CONFIG_USB_MUSB_HDRC) += musb_hdrc.o 7musb_hdrc-y := musb_core.o
8 8
9ifeq ($(CONFIG_ARCH_DAVINCI_DMx),y) 9musb_hdrc-$(CONFIG_USB_GADGET_MUSB_HDRC) += musb_gadget_ep0.o musb_gadget.o
10 musb_hdrc-objs += davinci.o 10musb_hdrc-$(CONFIG_USB_MUSB_HDRC_HCD) += musb_virthub.o musb_host.o
11endif 11musb_hdrc-$(CONFIG_DEBUG_FS) += musb_debugfs.o
12
13ifeq ($(CONFIG_USB_TUSB6010),y)
14 musb_hdrc-objs += tusb6010.o
15endif
16
17ifeq ($(CONFIG_ARCH_OMAP2430),y)
18 musb_hdrc-objs += omap2430.o
19endif
20
21ifeq ($(CONFIG_ARCH_OMAP3430),y)
22 musb_hdrc-objs += omap2430.o
23endif
24
25ifeq ($(CONFIG_ARCH_OMAP4),y)
26 musb_hdrc-objs += omap2430.o
27endif
28
29ifeq ($(CONFIG_BF54x),y)
30 musb_hdrc-objs += blackfin.o
31endif
32
33ifeq ($(CONFIG_BF52x),y)
34 musb_hdrc-objs += blackfin.o
35endif
36
37ifeq ($(CONFIG_USB_GADGET_MUSB_HDRC),y)
38 musb_hdrc-objs += musb_gadget_ep0.o musb_gadget.o
39endif
40 12
41ifeq ($(CONFIG_USB_MUSB_HDRC_HCD),y) 13# Hardware Glue Layer
42 musb_hdrc-objs += musb_virthub.o musb_host.o 14obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o
43endif 15obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o
44 16obj-$(CONFIG_USB_MUSB_TUSB6010) += tusb6010.o
45ifeq ($(CONFIG_DEBUG_FS),y) 17obj-$(CONFIG_USB_MUSB_DAVINCI) += davinci.o
46 musb_hdrc-objs += musb_debugfs.o 18obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o
47endif 19obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o
20obj-$(CONFIG_USB_MUSB_UX500) += ux500.o
48 21
49# the kconfig must guarantee that only one of the 22# the kconfig must guarantee that only one of the
50# possible I/O schemes will be enabled at a time ... 23# possible I/O schemes will be enabled at a time ...
@@ -54,26 +27,22 @@ endif
54ifneq ($(CONFIG_MUSB_PIO_ONLY),y) 27ifneq ($(CONFIG_MUSB_PIO_ONLY),y)
55 28
56 ifeq ($(CONFIG_USB_INVENTRA_DMA),y) 29 ifeq ($(CONFIG_USB_INVENTRA_DMA),y)
57 musb_hdrc-objs += musbhsdma.o 30 musb_hdrc-y += musbhsdma.o
58 31
59 else 32 else
60 ifeq ($(CONFIG_USB_TI_CPPI_DMA),y) 33 ifeq ($(CONFIG_USB_TI_CPPI_DMA),y)
61 musb_hdrc-objs += cppi_dma.o 34 musb_hdrc-y += cppi_dma.o
62 35
63 else 36 else
64 ifeq ($(CONFIG_USB_TUSB_OMAP_DMA),y) 37 ifeq ($(CONFIG_USB_TUSB_OMAP_DMA),y)
65 musb_hdrc-objs += tusb6010_omap.o 38 musb_hdrc-y += tusb6010_omap.o
66 39
40 else
41 ifeq ($(CONFIG_USB_UX500_DMA),y)
42 musb_hdrc-y += ux500_dma.o
43
44 endif
67 endif 45 endif
68 endif 46 endif
69 endif 47 endif
70endif 48endif
71
72
73################################################################################
74
75# Debugging
76
77ifeq ($(CONFIG_USB_MUSB_DEBUG),y)
78 EXTRA_CFLAGS += -DDEBUG
79endif
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
new file mode 100644
index 000000000000..23ac28f98d91
--- /dev/null
+++ b/drivers/usb/musb/am35x.c
@@ -0,0 +1,657 @@
1/*
2 * Texas Instruments AM35x "glue layer"
3 *
4 * Copyright (c) 2010, by Texas Instruments
5 *
6 * Based on the DA8xx "glue layer" code.
7 * Copyright (c) 2008-2009, MontaVista Software, Inc. <source@mvista.com>
8 *
9 * This file is part of the Inventra Controller Driver for Linux.
10 *
11 * The Inventra Controller Driver for Linux is free software; you
12 * can redistribute it and/or modify it under the terms of the GNU
13 * General Public License version 2 as published by the Free Software
14 * Foundation.
15 *
16 * The Inventra Controller Driver for Linux is distributed in
17 * the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 * License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with The Inventra Controller Driver for Linux ; if not,
24 * write to the Free Software Foundation, Inc., 59 Temple Place,
25 * Suite 330, Boston, MA 02111-1307 USA
26 *
27 */
28
29#include <linux/init.h>
30#include <linux/clk.h>
31#include <linux/io.h>
32#include <linux/platform_device.h>
33#include <linux/dma-mapping.h>
34
35#include <plat/usb.h>
36
37#include "musb_core.h"
38
39/*
40 * AM35x specific definitions
41 */
42/* USB 2.0 OTG module registers */
43#define USB_REVISION_REG 0x00
44#define USB_CTRL_REG 0x04
45#define USB_STAT_REG 0x08
46#define USB_EMULATION_REG 0x0c
47/* 0x10 Reserved */
48#define USB_AUTOREQ_REG 0x14
49#define USB_SRP_FIX_TIME_REG 0x18
50#define USB_TEARDOWN_REG 0x1c
51#define EP_INTR_SRC_REG 0x20
52#define EP_INTR_SRC_SET_REG 0x24
53#define EP_INTR_SRC_CLEAR_REG 0x28
54#define EP_INTR_MASK_REG 0x2c
55#define EP_INTR_MASK_SET_REG 0x30
56#define EP_INTR_MASK_CLEAR_REG 0x34
57#define EP_INTR_SRC_MASKED_REG 0x38
58#define CORE_INTR_SRC_REG 0x40
59#define CORE_INTR_SRC_SET_REG 0x44
60#define CORE_INTR_SRC_CLEAR_REG 0x48
61#define CORE_INTR_MASK_REG 0x4c
62#define CORE_INTR_MASK_SET_REG 0x50
63#define CORE_INTR_MASK_CLEAR_REG 0x54
64#define CORE_INTR_SRC_MASKED_REG 0x58
65/* 0x5c Reserved */
66#define USB_END_OF_INTR_REG 0x60
67
68/* Control register bits */
69#define AM35X_SOFT_RESET_MASK 1
70
71/* USB interrupt register bits */
72#define AM35X_INTR_USB_SHIFT 16
73#define AM35X_INTR_USB_MASK (0x1ff << AM35X_INTR_USB_SHIFT)
74#define AM35X_INTR_DRVVBUS 0x100
75#define AM35X_INTR_RX_SHIFT 16
76#define AM35X_INTR_TX_SHIFT 0
77#define AM35X_TX_EP_MASK 0xffff /* EP0 + 15 Tx EPs */
78#define AM35X_RX_EP_MASK 0xfffe /* 15 Rx EPs */
79#define AM35X_TX_INTR_MASK (AM35X_TX_EP_MASK << AM35X_INTR_TX_SHIFT)
80#define AM35X_RX_INTR_MASK (AM35X_RX_EP_MASK << AM35X_INTR_RX_SHIFT)
81
82#define USB_MENTOR_CORE_OFFSET 0x400
83
84struct am35x_glue {
85 struct device *dev;
86 struct platform_device *musb;
87 struct clk *phy_clk;
88 struct clk *clk;
89};
90#define glue_to_musb(g) platform_get_drvdata(g->musb)
91
92/*
93 * am35x_musb_enable - enable interrupts
94 */
95static void am35x_musb_enable(struct musb *musb)
96{
97 void __iomem *reg_base = musb->ctrl_base;
98 u32 epmask;
99
100 /* Workaround: setup IRQs through both register sets. */
101 epmask = ((musb->epmask & AM35X_TX_EP_MASK) << AM35X_INTR_TX_SHIFT) |
102 ((musb->epmask & AM35X_RX_EP_MASK) << AM35X_INTR_RX_SHIFT);
103
104 musb_writel(reg_base, EP_INTR_MASK_SET_REG, epmask);
105 musb_writel(reg_base, CORE_INTR_MASK_SET_REG, AM35X_INTR_USB_MASK);
106
107 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
108 if (is_otg_enabled(musb))
109 musb_writel(reg_base, CORE_INTR_SRC_SET_REG,
110 AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT);
111}
112
113/*
114 * am35x_musb_disable - disable HDRC and flush interrupts
115 */
116static void am35x_musb_disable(struct musb *musb)
117{
118 void __iomem *reg_base = musb->ctrl_base;
119
120 musb_writel(reg_base, CORE_INTR_MASK_CLEAR_REG, AM35X_INTR_USB_MASK);
121 musb_writel(reg_base, EP_INTR_MASK_CLEAR_REG,
122 AM35X_TX_INTR_MASK | AM35X_RX_INTR_MASK);
123 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
124 musb_writel(reg_base, USB_END_OF_INTR_REG, 0);
125}
126
127#ifdef CONFIG_USB_MUSB_HDRC_HCD
128#define portstate(stmt) stmt
129#else
130#define portstate(stmt)
131#endif
132
133static void am35x_musb_set_vbus(struct musb *musb, int is_on)
134{
135 WARN_ON(is_on && is_peripheral_active(musb));
136}
137
138#define POLL_SECONDS 2
139
140static struct timer_list otg_workaround;
141
142static void otg_timer(unsigned long _musb)
143{
144 struct musb *musb = (void *)_musb;
145 void __iomem *mregs = musb->mregs;
146 u8 devctl;
147 unsigned long flags;
148
149 /*
150 * We poll because AM35x's won't expose several OTG-critical
151 * status change events (from the transceiver) otherwise.
152 */
153 devctl = musb_readb(mregs, MUSB_DEVCTL);
154 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
155 otg_state_string(musb->xceiv->state));
156
157 spin_lock_irqsave(&musb->lock, flags);
158 switch (musb->xceiv->state) {
159 case OTG_STATE_A_WAIT_BCON:
160 devctl &= ~MUSB_DEVCTL_SESSION;
161 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
162
163 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
164 if (devctl & MUSB_DEVCTL_BDEVICE) {
165 musb->xceiv->state = OTG_STATE_B_IDLE;
166 MUSB_DEV_MODE(musb);
167 } else {
168 musb->xceiv->state = OTG_STATE_A_IDLE;
169 MUSB_HST_MODE(musb);
170 }
171 break;
172 case OTG_STATE_A_WAIT_VFALL:
173 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
174 musb_writel(musb->ctrl_base, CORE_INTR_SRC_SET_REG,
175 MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT);
176 break;
177 case OTG_STATE_B_IDLE:
178 if (!is_peripheral_enabled(musb))
179 break;
180
181 devctl = musb_readb(mregs, MUSB_DEVCTL);
182 if (devctl & MUSB_DEVCTL_BDEVICE)
183 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
184 else
185 musb->xceiv->state = OTG_STATE_A_IDLE;
186 break;
187 default:
188 break;
189 }
190 spin_unlock_irqrestore(&musb->lock, flags);
191}
192
193static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
194{
195 static unsigned long last_timer;
196
197 if (!is_otg_enabled(musb))
198 return;
199
200 if (timeout == 0)
201 timeout = jiffies + msecs_to_jiffies(3);
202
203 /* Never idle if active, or when VBUS timeout is not set as host */
204 if (musb->is_active || (musb->a_wait_bcon == 0 &&
205 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
206 dev_dbg(musb->controller, "%s active, deleting timer\n",
207 otg_state_string(musb->xceiv->state));
208 del_timer(&otg_workaround);
209 last_timer = jiffies;
210 return;
211 }
212
213 if (time_after(last_timer, timeout) && timer_pending(&otg_workaround)) {
214 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n");
215 return;
216 }
217 last_timer = timeout;
218
219 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
220 otg_state_string(musb->xceiv->state),
221 jiffies_to_msecs(timeout - jiffies));
222 mod_timer(&otg_workaround, timeout);
223}
224
225static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
226{
227 struct musb *musb = hci;
228 void __iomem *reg_base = musb->ctrl_base;
229 struct device *dev = musb->controller;
230 struct musb_hdrc_platform_data *plat = dev->platform_data;
231 struct omap_musb_board_data *data = plat->board_data;
232 unsigned long flags;
233 irqreturn_t ret = IRQ_NONE;
234 u32 epintr, usbintr;
235
236 spin_lock_irqsave(&musb->lock, flags);
237
238 /* Get endpoint interrupts */
239 epintr = musb_readl(reg_base, EP_INTR_SRC_MASKED_REG);
240
241 if (epintr) {
242 musb_writel(reg_base, EP_INTR_SRC_CLEAR_REG, epintr);
243
244 musb->int_rx =
245 (epintr & AM35X_RX_INTR_MASK) >> AM35X_INTR_RX_SHIFT;
246 musb->int_tx =
247 (epintr & AM35X_TX_INTR_MASK) >> AM35X_INTR_TX_SHIFT;
248 }
249
250 /* Get usb core interrupts */
251 usbintr = musb_readl(reg_base, CORE_INTR_SRC_MASKED_REG);
252 if (!usbintr && !epintr)
253 goto eoi;
254
255 if (usbintr) {
256 musb_writel(reg_base, CORE_INTR_SRC_CLEAR_REG, usbintr);
257
258 musb->int_usb =
259 (usbintr & AM35X_INTR_USB_MASK) >> AM35X_INTR_USB_SHIFT;
260 }
261 /*
262 * DRVVBUS IRQs are the only proxy we have (a very poor one!) for
263 * AM35x's missing ID change IRQ. We need an ID change IRQ to
264 * switch appropriately between halves of the OTG state machine.
265 * Managing DEVCTL.SESSION per Mentor docs requires that we know its
266 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
267 * Also, DRVVBUS pulses for SRP (but not at 5V) ...
268 */
269 if (usbintr & (AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT)) {
270 int drvvbus = musb_readl(reg_base, USB_STAT_REG);
271 void __iomem *mregs = musb->mregs;
272 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
273 int err;
274
275 err = is_host_enabled(musb) && (musb->int_usb &
276 MUSB_INTR_VBUSERROR);
277 if (err) {
278 /*
279 * The Mentor core doesn't debounce VBUS as needed
280 * to cope with device connect current spikes. This
281 * means it's not uncommon for bus-powered devices
282 * to get VBUS errors during enumeration.
283 *
284 * This is a workaround, but newer RTL from Mentor
285 * seems to allow a better one: "re"-starting sessions
286 * without waiting for VBUS to stop registering in
287 * devctl.
288 */
289 musb->int_usb &= ~MUSB_INTR_VBUSERROR;
290 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
291 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
292 WARNING("VBUS error workaround (delay coming)\n");
293 } else if (is_host_enabled(musb) && drvvbus) {
294 MUSB_HST_MODE(musb);
295 musb->xceiv->default_a = 1;
296 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
297 portstate(musb->port1_status |= USB_PORT_STAT_POWER);
298 del_timer(&otg_workaround);
299 } else {
300 musb->is_active = 0;
301 MUSB_DEV_MODE(musb);
302 musb->xceiv->default_a = 0;
303 musb->xceiv->state = OTG_STATE_B_IDLE;
304 portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
305 }
306
307 /* NOTE: this must complete power-on within 100 ms. */
308 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
309 drvvbus ? "on" : "off",
310 otg_state_string(musb->xceiv->state),
311 err ? " ERROR" : "",
312 devctl);
313 ret = IRQ_HANDLED;
314 }
315
316 if (musb->int_tx || musb->int_rx || musb->int_usb)
317 ret |= musb_interrupt(musb);
318
319eoi:
320 /* EOI needs to be written for the IRQ to be re-asserted. */
321 if (ret == IRQ_HANDLED || epintr || usbintr) {
322 /* clear level interrupt */
323 if (data->clear_irq)
324 data->clear_irq();
325 /* write EOI */
326 musb_writel(reg_base, USB_END_OF_INTR_REG, 0);
327 }
328
329 /* Poll for ID change */
330 if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE)
331 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
332
333 spin_unlock_irqrestore(&musb->lock, flags);
334
335 return ret;
336}
337
338static int am35x_musb_set_mode(struct musb *musb, u8 musb_mode)
339{
340 struct device *dev = musb->controller;
341 struct musb_hdrc_platform_data *plat = dev->platform_data;
342 struct omap_musb_board_data *data = plat->board_data;
343 int retval = 0;
344
345 if (data->set_mode)
346 data->set_mode(musb_mode);
347 else
348 retval = -EIO;
349
350 return retval;
351}
352
353static int am35x_musb_init(struct musb *musb)
354{
355 struct device *dev = musb->controller;
356 struct musb_hdrc_platform_data *plat = dev->platform_data;
357 struct omap_musb_board_data *data = plat->board_data;
358 void __iomem *reg_base = musb->ctrl_base;
359 u32 rev;
360
361 musb->mregs += USB_MENTOR_CORE_OFFSET;
362
363 /* Returns zero if e.g. not clocked */
364 rev = musb_readl(reg_base, USB_REVISION_REG);
365 if (!rev)
366 return -ENODEV;
367
368 usb_nop_xceiv_register();
369 musb->xceiv = otg_get_transceiver();
370 if (!musb->xceiv)
371 return -ENODEV;
372
373 if (is_host_enabled(musb))
374 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
375
376 /* Reset the musb */
377 if (data->reset)
378 data->reset();
379
380 /* Reset the controller */
381 musb_writel(reg_base, USB_CTRL_REG, AM35X_SOFT_RESET_MASK);
382
383 /* Start the on-chip PHY and its PLL. */
384 if (data->set_phy_power)
385 data->set_phy_power(1);
386
387 msleep(5);
388
389 musb->isr = am35x_musb_interrupt;
390
391 /* clear level interrupt */
392 if (data->clear_irq)
393 data->clear_irq();
394
395 return 0;
396}
397
398static int am35x_musb_exit(struct musb *musb)
399{
400 struct device *dev = musb->controller;
401 struct musb_hdrc_platform_data *plat = dev->platform_data;
402 struct omap_musb_board_data *data = plat->board_data;
403
404 if (is_host_enabled(musb))
405 del_timer_sync(&otg_workaround);
406
407 /* Shutdown the on-chip PHY and its PLL. */
408 if (data->set_phy_power)
409 data->set_phy_power(0);
410
411 otg_put_transceiver(musb->xceiv);
412 usb_nop_xceiv_unregister();
413
414 return 0;
415}
416
417/* AM35x supports only 32bit read operation */
418void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
419{
420 void __iomem *fifo = hw_ep->fifo;
421 u32 val;
422 int i;
423
424 /* Read for 32bit-aligned destination address */
425 if (likely((0x03 & (unsigned long) dst) == 0) && len >= 4) {
426 readsl(fifo, dst, len >> 2);
427 dst += len & ~0x03;
428 len &= 0x03;
429 }
430 /*
431 * Now read the remaining 1 to 3 byte or complete length if
432 * unaligned address.
433 */
434 if (len > 4) {
435 for (i = 0; i < (len >> 2); i++) {
436 *(u32 *) dst = musb_readl(fifo, 0);
437 dst += 4;
438 }
439 len &= 0x03;
440 }
441 if (len > 0) {
442 val = musb_readl(fifo, 0);
443 memcpy(dst, &val, len);
444 }
445}
446
447static const struct musb_platform_ops am35x_ops = {
448 .init = am35x_musb_init,
449 .exit = am35x_musb_exit,
450
451 .enable = am35x_musb_enable,
452 .disable = am35x_musb_disable,
453
454 .set_mode = am35x_musb_set_mode,
455 .try_idle = am35x_musb_try_idle,
456
457 .set_vbus = am35x_musb_set_vbus,
458};
459
460static u64 am35x_dmamask = DMA_BIT_MASK(32);
461
462static int __init am35x_probe(struct platform_device *pdev)
463{
464 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
465 struct platform_device *musb;
466 struct am35x_glue *glue;
467
468 struct clk *phy_clk;
469 struct clk *clk;
470
471 int ret = -ENOMEM;
472
473 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
474 if (!glue) {
475 dev_err(&pdev->dev, "failed to allocate glue context\n");
476 goto err0;
477 }
478
479 musb = platform_device_alloc("musb-hdrc", -1);
480 if (!musb) {
481 dev_err(&pdev->dev, "failed to allocate musb device\n");
482 goto err1;
483 }
484
485 phy_clk = clk_get(&pdev->dev, "fck");
486 if (IS_ERR(phy_clk)) {
487 dev_err(&pdev->dev, "failed to get PHY clock\n");
488 ret = PTR_ERR(phy_clk);
489 goto err2;
490 }
491
492 clk = clk_get(&pdev->dev, "ick");
493 if (IS_ERR(clk)) {
494 dev_err(&pdev->dev, "failed to get clock\n");
495 ret = PTR_ERR(clk);
496 goto err3;
497 }
498
499 ret = clk_enable(phy_clk);
500 if (ret) {
501 dev_err(&pdev->dev, "failed to enable PHY clock\n");
502 goto err4;
503 }
504
505 ret = clk_enable(clk);
506 if (ret) {
507 dev_err(&pdev->dev, "failed to enable clock\n");
508 goto err5;
509 }
510
511 musb->dev.parent = &pdev->dev;
512 musb->dev.dma_mask = &am35x_dmamask;
513 musb->dev.coherent_dma_mask = am35x_dmamask;
514
515 glue->dev = &pdev->dev;
516 glue->musb = musb;
517 glue->phy_clk = phy_clk;
518 glue->clk = clk;
519
520 pdata->platform_ops = &am35x_ops;
521
522 platform_set_drvdata(pdev, glue);
523
524 ret = platform_device_add_resources(musb, pdev->resource,
525 pdev->num_resources);
526 if (ret) {
527 dev_err(&pdev->dev, "failed to add resources\n");
528 goto err6;
529 }
530
531 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
532 if (ret) {
533 dev_err(&pdev->dev, "failed to add platform_data\n");
534 goto err6;
535 }
536
537 ret = platform_device_add(musb);
538 if (ret) {
539 dev_err(&pdev->dev, "failed to register musb device\n");
540 goto err6;
541 }
542
543 return 0;
544
545err6:
546 clk_disable(clk);
547
548err5:
549 clk_disable(phy_clk);
550
551err4:
552 clk_put(clk);
553
554err3:
555 clk_put(phy_clk);
556
557err2:
558 platform_device_put(musb);
559
560err1:
561 kfree(glue);
562
563err0:
564 return ret;
565}
566
567static int __exit am35x_remove(struct platform_device *pdev)
568{
569 struct am35x_glue *glue = platform_get_drvdata(pdev);
570
571 platform_device_del(glue->musb);
572 platform_device_put(glue->musb);
573 clk_disable(glue->clk);
574 clk_disable(glue->phy_clk);
575 clk_put(glue->clk);
576 clk_put(glue->phy_clk);
577 kfree(glue);
578
579 return 0;
580}
581
582#ifdef CONFIG_PM
583static int am35x_suspend(struct device *dev)
584{
585 struct am35x_glue *glue = dev_get_drvdata(dev);
586 struct musb_hdrc_platform_data *plat = dev->platform_data;
587 struct omap_musb_board_data *data = plat->board_data;
588
589 /* Shutdown the on-chip PHY and its PLL. */
590 if (data->set_phy_power)
591 data->set_phy_power(0);
592
593 clk_disable(glue->phy_clk);
594 clk_disable(glue->clk);
595
596 return 0;
597}
598
599static int am35x_resume(struct device *dev)
600{
601 struct am35x_glue *glue = dev_get_drvdata(dev);
602 struct musb_hdrc_platform_data *plat = dev->platform_data;
603 struct omap_musb_board_data *data = plat->board_data;
604 int ret;
605
606 /* Start the on-chip PHY and its PLL. */
607 if (data->set_phy_power)
608 data->set_phy_power(1);
609
610 ret = clk_enable(glue->phy_clk);
611 if (ret) {
612 dev_err(dev, "failed to enable PHY clock\n");
613 return ret;
614 }
615
616 ret = clk_enable(glue->clk);
617 if (ret) {
618 dev_err(dev, "failed to enable clock\n");
619 return ret;
620 }
621
622 return 0;
623}
624
625static struct dev_pm_ops am35x_pm_ops = {
626 .suspend = am35x_suspend,
627 .resume = am35x_resume,
628};
629
630#define DEV_PM_OPS &am35x_pm_ops
631#else
632#define DEV_PM_OPS NULL
633#endif
634
635static struct platform_driver am35x_driver = {
636 .remove = __exit_p(am35x_remove),
637 .driver = {
638 .name = "musb-am35x",
639 .pm = DEV_PM_OPS,
640 },
641};
642
643MODULE_DESCRIPTION("AM35x MUSB Glue Layer");
644MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>");
645MODULE_LICENSE("GPL v2");
646
647static int __init am35x_init(void)
648{
649 return platform_driver_probe(&am35x_driver, am35x_probe);
650}
651subsys_initcall(am35x_init);
652
653static void __exit am35x_exit(void)
654{
655 platform_driver_unregister(&am35x_driver);
656}
657module_exit(am35x_exit);
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index b611420a8050..ae8c39617743 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -15,17 +15,27 @@
15#include <linux/list.h> 15#include <linux/list.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/platform_device.h>
19#include <linux/dma-mapping.h>
18 20
19#include <asm/cacheflush.h> 21#include <asm/cacheflush.h>
20 22
21#include "musb_core.h" 23#include "musb_core.h"
24#include "musbhsdma.h"
22#include "blackfin.h" 25#include "blackfin.h"
23 26
27struct bfin_glue {
28 struct device *dev;
29 struct platform_device *musb;
30};
31#define glue_to_musb(g) platform_get_drvdata(g->musb)
32
24/* 33/*
25 * Load an endpoint's FIFO 34 * Load an endpoint's FIFO
26 */ 35 */
27void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) 36void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
28{ 37{
38 struct musb *musb = hw_ep->musb;
29 void __iomem *fifo = hw_ep->fifo; 39 void __iomem *fifo = hw_ep->fifo;
30 void __iomem *epio = hw_ep->regs; 40 void __iomem *epio = hw_ep->regs;
31 u8 epnum = hw_ep->epnum; 41 u8 epnum = hw_ep->epnum;
@@ -34,7 +44,7 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
34 44
35 musb_writew(epio, MUSB_TXCOUNT, len); 45 musb_writew(epio, MUSB_TXCOUNT, len);
36 46
37 DBG(4, "TX ep%d fifo %p count %d buf %p, epio %p\n", 47 dev_dbg(musb->controller, "TX ep%d fifo %p count %d buf %p, epio %p\n",
38 hw_ep->epnum, fifo, len, src, epio); 48 hw_ep->epnum, fifo, len, src, epio);
39 49
40 dump_fifo_data(src, len); 50 dump_fifo_data(src, len);
@@ -89,6 +99,7 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
89 */ 99 */
90void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) 100void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
91{ 101{
102 struct musb *musb = hw_ep->musb;
92 void __iomem *fifo = hw_ep->fifo; 103 void __iomem *fifo = hw_ep->fifo;
93 u8 epnum = hw_ep->epnum; 104 u8 epnum = hw_ep->epnum;
94 105
@@ -145,7 +156,7 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
145 *(dst + len - 1) = (u8)inw((unsigned long)fifo + 4); 156 *(dst + len - 1) = (u8)inw((unsigned long)fifo + 4);
146 } 157 }
147 } 158 }
148 DBG(4, "%cX ep%d fifo %p count %d buf %p\n", 159 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
149 'R', hw_ep->epnum, fifo, len, dst); 160 'R', hw_ep->epnum, fifo, len, dst);
150 161
151 dump_fifo_data(dst, len); 162 dump_fifo_data(dst, len);
@@ -171,8 +182,9 @@ static irqreturn_t blackfin_interrupt(int irq, void *__hci)
171 } 182 }
172 183
173 /* Start sampling ID pin, when plug is removed from MUSB */ 184 /* Start sampling ID pin, when plug is removed from MUSB */
174 if (is_otg_enabled(musb) && (musb->xceiv->state == OTG_STATE_B_IDLE 185 if ((is_otg_enabled(musb) && (musb->xceiv->state == OTG_STATE_B_IDLE
175 || musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 186 || musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) ||
187 (musb->int_usb & MUSB_INTR_DISCONNECT && is_host_active(musb))) {
176 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 188 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
177 musb->a_wait_bcon = TIMER_DELAY; 189 musb->a_wait_bcon = TIMER_DELAY;
178 } 190 }
@@ -269,15 +281,17 @@ static void musb_conn_timer_handler(unsigned long _musb)
269 } 281 }
270 break; 282 break;
271 default: 283 default:
272 DBG(1, "%s state not handled\n", otg_state_string(musb)); 284 dev_dbg(musb->controller, "%s state not handled\n",
285 otg_state_string(musb->xceiv->state));
273 break; 286 break;
274 } 287 }
275 spin_unlock_irqrestore(&musb->lock, flags); 288 spin_unlock_irqrestore(&musb->lock, flags);
276 289
277 DBG(4, "state is %s\n", otg_state_string(musb)); 290 dev_dbg(musb->controller, "state is %s\n",
291 otg_state_string(musb->xceiv->state));
278} 292}
279 293
280void musb_platform_enable(struct musb *musb) 294static void bfin_musb_enable(struct musb *musb)
281{ 295{
282 if (!is_otg_enabled(musb) && is_host_enabled(musb)) { 296 if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
283 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 297 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
@@ -285,66 +299,67 @@ void musb_platform_enable(struct musb *musb)
285 } 299 }
286} 300}
287 301
288void musb_platform_disable(struct musb *musb) 302static void bfin_musb_disable(struct musb *musb)
289{ 303{
290} 304}
291 305
292static void bfin_set_vbus(struct musb *musb, int is_on) 306static void bfin_musb_set_vbus(struct musb *musb, int is_on)
293{ 307{
294 int value = musb->config->gpio_vrsel_active; 308 int value = musb->config->gpio_vrsel_active;
295 if (!is_on) 309 if (!is_on)
296 value = !value; 310 value = !value;
297 gpio_set_value(musb->config->gpio_vrsel, value); 311 gpio_set_value(musb->config->gpio_vrsel, value);
298 312
299 DBG(1, "VBUS %s, devctl %02x " 313 dev_dbg(musb->controller, "VBUS %s, devctl %02x "
300 /* otg %3x conf %08x prcm %08x */ "\n", 314 /* otg %3x conf %08x prcm %08x */ "\n",
301 otg_state_string(musb), 315 otg_state_string(musb->xceiv->state),
302 musb_readb(musb->mregs, MUSB_DEVCTL)); 316 musb_readb(musb->mregs, MUSB_DEVCTL));
303} 317}
304 318
305static int bfin_set_power(struct otg_transceiver *x, unsigned mA) 319static int bfin_musb_set_power(struct otg_transceiver *x, unsigned mA)
306{ 320{
307 return 0; 321 return 0;
308} 322}
309 323
310void musb_platform_try_idle(struct musb *musb, unsigned long timeout) 324static void bfin_musb_try_idle(struct musb *musb, unsigned long timeout)
311{ 325{
312 if (!is_otg_enabled(musb) && is_host_enabled(musb)) 326 if (!is_otg_enabled(musb) && is_host_enabled(musb))
313 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 327 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
314} 328}
315 329
316int musb_platform_get_vbus_status(struct musb *musb) 330static int bfin_musb_vbus_status(struct musb *musb)
317{ 331{
318 return 0; 332 return 0;
319} 333}
320 334
321int musb_platform_set_mode(struct musb *musb, u8 musb_mode) 335static int bfin_musb_set_mode(struct musb *musb, u8 musb_mode)
322{ 336{
323 return -EIO; 337 return -EIO;
324} 338}
325 339
326int __init musb_platform_init(struct musb *musb, void *board_data) 340static int bfin_musb_adjust_channel_params(struct dma_channel *channel,
341 u16 packet_sz, u8 *mode,
342 dma_addr_t *dma_addr, u32 *len)
327{ 343{
344 struct musb_dma_channel *musb_channel = channel->private_data;
328 345
329 /* 346 /*
330 * Rev 1.0 BF549 EZ-KITs require PE7 to be high for both DEVICE 347 * Anomaly 05000450 might cause data corruption when using DMA
331 * and OTG HOST modes, while rev 1.1 and greater require PE7 to 348 * MODE 1 transmits with short packet. So to work around this,
332 * be low for DEVICE mode and high for HOST mode. We set it high 349 * we truncate all MODE 1 transfers down to a multiple of the
333 * here because we are in host mode 350 * max packet size, and then do the last short packet transfer
351 * (if there is any) using MODE 0.
334 */ 352 */
335 353 if (ANOMALY_05000450) {
336 if (gpio_request(musb->config->gpio_vrsel, "USB_VRSEL")) { 354 if (musb_channel->transmit && *mode == 1)
337 printk(KERN_ERR "Failed ro request USB_VRSEL GPIO_%d \n", 355 *len = *len - (*len % packet_sz);
338 musb->config->gpio_vrsel);
339 return -ENODEV;
340 } 356 }
341 gpio_direction_output(musb->config->gpio_vrsel, 0);
342 357
343 usb_nop_xceiv_register(); 358 return 0;
344 musb->xceiv = otg_get_transceiver(); 359}
345 if (!musb->xceiv)
346 return -ENODEV;
347 360
361static void bfin_musb_reg_init(struct musb *musb)
362{
348 if (ANOMALY_05000346) { 363 if (ANOMALY_05000346) {
349 bfin_write_USB_APHY_CALIB(ANOMALY_05000346_value); 364 bfin_write_USB_APHY_CALIB(ANOMALY_05000346_value);
350 SSYNC(); 365 SSYNC();
@@ -356,7 +371,8 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
356 } 371 }
357 372
358 /* Configure PLL oscillator register */ 373 /* Configure PLL oscillator register */
359 bfin_write_USB_PLLOSC_CTRL(0x30a8); 374 bfin_write_USB_PLLOSC_CTRL(0x3080 |
375 ((480/musb->config->clkin) << 1));
360 SSYNC(); 376 SSYNC();
361 377
362 bfin_write_USB_SRP_CLKDIV((get_sclk()/1000) / 32 - 1); 378 bfin_write_USB_SRP_CLKDIV((get_sclk()/1000) / 32 - 1);
@@ -378,24 +394,205 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
378 EP2_RX_ENA | EP3_RX_ENA | EP4_RX_ENA | 394 EP2_RX_ENA | EP3_RX_ENA | EP4_RX_ENA |
379 EP5_RX_ENA | EP6_RX_ENA | EP7_RX_ENA); 395 EP5_RX_ENA | EP6_RX_ENA | EP7_RX_ENA);
380 SSYNC(); 396 SSYNC();
397}
398
399static int bfin_musb_init(struct musb *musb)
400{
401
402 /*
403 * Rev 1.0 BF549 EZ-KITs require PE7 to be high for both DEVICE
404 * and OTG HOST modes, while rev 1.1 and greater require PE7 to
405 * be low for DEVICE mode and high for HOST mode. We set it high
406 * here because we are in host mode
407 */
408
409 if (gpio_request(musb->config->gpio_vrsel, "USB_VRSEL")) {
410 printk(KERN_ERR "Failed ro request USB_VRSEL GPIO_%d\n",
411 musb->config->gpio_vrsel);
412 return -ENODEV;
413 }
414 gpio_direction_output(musb->config->gpio_vrsel, 0);
415
416 usb_nop_xceiv_register();
417 musb->xceiv = otg_get_transceiver();
418 if (!musb->xceiv) {
419 gpio_free(musb->config->gpio_vrsel);
420 return -ENODEV;
421 }
422
423 bfin_musb_reg_init(musb);
381 424
382 if (is_host_enabled(musb)) { 425 if (is_host_enabled(musb)) {
383 musb->board_set_vbus = bfin_set_vbus;
384 setup_timer(&musb_conn_timer, 426 setup_timer(&musb_conn_timer,
385 musb_conn_timer_handler, (unsigned long) musb); 427 musb_conn_timer_handler, (unsigned long) musb);
386 } 428 }
387 if (is_peripheral_enabled(musb)) 429 if (is_peripheral_enabled(musb))
388 musb->xceiv->set_power = bfin_set_power; 430 musb->xceiv->set_power = bfin_musb_set_power;
389 431
390 musb->isr = blackfin_interrupt; 432 musb->isr = blackfin_interrupt;
433 musb->double_buffer_not_ok = true;
391 434
392 return 0; 435 return 0;
393} 436}
394 437
395int musb_platform_exit(struct musb *musb) 438static int bfin_musb_exit(struct musb *musb)
396{ 439{
397
398 gpio_free(musb->config->gpio_vrsel); 440 gpio_free(musb->config->gpio_vrsel);
399 441
442 otg_put_transceiver(musb->xceiv);
443 usb_nop_xceiv_unregister();
444 return 0;
445}
446
447static const struct musb_platform_ops bfin_ops = {
448 .init = bfin_musb_init,
449 .exit = bfin_musb_exit,
450
451 .enable = bfin_musb_enable,
452 .disable = bfin_musb_disable,
453
454 .set_mode = bfin_musb_set_mode,
455 .try_idle = bfin_musb_try_idle,
456
457 .vbus_status = bfin_musb_vbus_status,
458 .set_vbus = bfin_musb_set_vbus,
459
460 .adjust_channel_params = bfin_musb_adjust_channel_params,
461};
462
463static u64 bfin_dmamask = DMA_BIT_MASK(32);
464
465static int __init bfin_probe(struct platform_device *pdev)
466{
467 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
468 struct platform_device *musb;
469 struct bfin_glue *glue;
470
471 int ret = -ENOMEM;
472
473 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
474 if (!glue) {
475 dev_err(&pdev->dev, "failed to allocate glue context\n");
476 goto err0;
477 }
478
479 musb = platform_device_alloc("musb-hdrc", -1);
480 if (!musb) {
481 dev_err(&pdev->dev, "failed to allocate musb device\n");
482 goto err1;
483 }
484
485 musb->dev.parent = &pdev->dev;
486 musb->dev.dma_mask = &bfin_dmamask;
487 musb->dev.coherent_dma_mask = bfin_dmamask;
488
489 glue->dev = &pdev->dev;
490 glue->musb = musb;
491
492 pdata->platform_ops = &bfin_ops;
493
494 platform_set_drvdata(pdev, glue);
495
496 ret = platform_device_add_resources(musb, pdev->resource,
497 pdev->num_resources);
498 if (ret) {
499 dev_err(&pdev->dev, "failed to add resources\n");
500 goto err2;
501 }
502
503 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
504 if (ret) {
505 dev_err(&pdev->dev, "failed to add platform_data\n");
506 goto err2;
507 }
508
509 ret = platform_device_add(musb);
510 if (ret) {
511 dev_err(&pdev->dev, "failed to register musb device\n");
512 goto err2;
513 }
514
515 return 0;
516
517err2:
518 platform_device_put(musb);
519
520err1:
521 kfree(glue);
522
523err0:
524 return ret;
525}
526
527static int __exit bfin_remove(struct platform_device *pdev)
528{
529 struct bfin_glue *glue = platform_get_drvdata(pdev);
530
531 platform_device_del(glue->musb);
532 platform_device_put(glue->musb);
533 kfree(glue);
534
535 return 0;
536}
537
538#ifdef CONFIG_PM
539static int bfin_suspend(struct device *dev)
540{
541 struct bfin_glue *glue = dev_get_drvdata(dev);
542 struct musb *musb = glue_to_musb(glue);
543
544 if (is_host_active(musb))
545 /*
546 * During hibernate gpio_vrsel will change from high to low
547 * low which will generate wakeup event resume the system
548 * immediately. Set it to 0 before hibernate to avoid this
549 * wakeup event.
550 */
551 gpio_set_value(musb->config->gpio_vrsel, 0);
552
400 return 0; 553 return 0;
401} 554}
555
556static int bfin_resume(struct device *dev)
557{
558 struct bfin_glue *glue = dev_get_drvdata(dev);
559 struct musb *musb = glue_to_musb(glue);
560
561 bfin_musb_reg_init(musb);
562
563 return 0;
564}
565
566static struct dev_pm_ops bfin_pm_ops = {
567 .suspend = bfin_suspend,
568 .resume = bfin_resume,
569};
570
571#define DEV_PM_OPS &bfin_pm_ops
572#else
573#define DEV_PM_OPS NULL
574#endif
575
576static struct platform_driver bfin_driver = {
577 .remove = __exit_p(bfin_remove),
578 .driver = {
579 .name = "musb-blackfin",
580 .pm = DEV_PM_OPS,
581 },
582};
583
584MODULE_DESCRIPTION("Blackfin MUSB Glue Layer");
585MODULE_AUTHOR("Bryan Wy <cooloney@kernel.org>");
586MODULE_LICENSE("GPL v2");
587
588static int __init bfin_init(void)
589{
590 return platform_driver_probe(&bfin_driver, bfin_probe);
591}
592subsys_initcall(bfin_init);
593
594static void __exit bfin_exit(void)
595{
596 platform_driver_unregister(&bfin_driver);
597}
598module_exit(bfin_exit);
diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index 5ab5bb89bae3..149f3f310a0a 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -236,7 +236,7 @@ static int cppi_controller_stop(struct dma_controller *c)
236 musb_writel(tibase, DAVINCI_RXCPPI_INTCLR_REG, 236 musb_writel(tibase, DAVINCI_RXCPPI_INTCLR_REG,
237 DAVINCI_DMA_ALL_CHANNELS_ENABLE); 237 DAVINCI_DMA_ALL_CHANNELS_ENABLE);
238 238
239 DBG(1, "Tearing down RX and TX Channels\n"); 239 dev_dbg(musb->controller, "Tearing down RX and TX Channels\n");
240 for (i = 0; i < ARRAY_SIZE(controller->tx); i++) { 240 for (i = 0; i < ARRAY_SIZE(controller->tx); i++) {
241 /* FIXME restructure of txdma to use bds like rxdma */ 241 /* FIXME restructure of txdma to use bds like rxdma */
242 controller->tx[i].last_processed = NULL; 242 controller->tx[i].last_processed = NULL;
@@ -301,13 +301,13 @@ cppi_channel_allocate(struct dma_controller *c,
301 */ 301 */
302 if (transmit) { 302 if (transmit) {
303 if (index >= ARRAY_SIZE(controller->tx)) { 303 if (index >= ARRAY_SIZE(controller->tx)) {
304 DBG(1, "no %cX%d CPPI channel\n", 'T', index); 304 dev_dbg(musb->controller, "no %cX%d CPPI channel\n", 'T', index);
305 return NULL; 305 return NULL;
306 } 306 }
307 cppi_ch = controller->tx + index; 307 cppi_ch = controller->tx + index;
308 } else { 308 } else {
309 if (index >= ARRAY_SIZE(controller->rx)) { 309 if (index >= ARRAY_SIZE(controller->rx)) {
310 DBG(1, "no %cX%d CPPI channel\n", 'R', index); 310 dev_dbg(musb->controller, "no %cX%d CPPI channel\n", 'R', index);
311 return NULL; 311 return NULL;
312 } 312 }
313 cppi_ch = controller->rx + index; 313 cppi_ch = controller->rx + index;
@@ -318,13 +318,13 @@ cppi_channel_allocate(struct dma_controller *c,
318 * with the other DMA engine too 318 * with the other DMA engine too
319 */ 319 */
320 if (cppi_ch->hw_ep) 320 if (cppi_ch->hw_ep)
321 DBG(1, "re-allocating DMA%d %cX channel %p\n", 321 dev_dbg(musb->controller, "re-allocating DMA%d %cX channel %p\n",
322 index, transmit ? 'T' : 'R', cppi_ch); 322 index, transmit ? 'T' : 'R', cppi_ch);
323 cppi_ch->hw_ep = ep; 323 cppi_ch->hw_ep = ep;
324 cppi_ch->channel.status = MUSB_DMA_STATUS_FREE; 324 cppi_ch->channel.status = MUSB_DMA_STATUS_FREE;
325 cppi_ch->channel.max_len = 0x7fffffff; 325 cppi_ch->channel.max_len = 0x7fffffff;
326 326
327 DBG(4, "Allocate CPPI%d %cX\n", index, transmit ? 'T' : 'R'); 327 dev_dbg(musb->controller, "Allocate CPPI%d %cX\n", index, transmit ? 'T' : 'R');
328 return &cppi_ch->channel; 328 return &cppi_ch->channel;
329} 329}
330 330
@@ -339,7 +339,7 @@ static void cppi_channel_release(struct dma_channel *channel)
339 c = container_of(channel, struct cppi_channel, channel); 339 c = container_of(channel, struct cppi_channel, channel);
340 tibase = c->controller->tibase; 340 tibase = c->controller->tibase;
341 if (!c->hw_ep) 341 if (!c->hw_ep)
342 DBG(1, "releasing idle DMA channel %p\n", c); 342 dev_dbg(musb->controller, "releasing idle DMA channel %p\n", c);
343 else if (!c->transmit) 343 else if (!c->transmit)
344 core_rxirq_enable(tibase, c->index + 1); 344 core_rxirq_enable(tibase, c->index + 1);
345 345
@@ -597,12 +597,12 @@ cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx)
597 length = min(n_bds * maxpacket, length); 597 length = min(n_bds * maxpacket, length);
598 } 598 }
599 599
600 DBG(4, "TX DMA%d, pktSz %d %s bds %d dma 0x%x len %u\n", 600 dev_dbg(musb->controller, "TX DMA%d, pktSz %d %s bds %d dma 0x%llx len %u\n",
601 tx->index, 601 tx->index,
602 maxpacket, 602 maxpacket,
603 rndis ? "rndis" : "transparent", 603 rndis ? "rndis" : "transparent",
604 n_bds, 604 n_bds,
605 addr, length); 605 (unsigned long long)addr, length);
606 606
607 cppi_rndis_update(tx, 0, musb->ctrl_base, rndis); 607 cppi_rndis_update(tx, 0, musb->ctrl_base, rndis);
608 608
@@ -654,7 +654,7 @@ cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx)
654 bd->hw_options |= CPPI_ZERO_SET; 654 bd->hw_options |= CPPI_ZERO_SET;
655 } 655 }
656 656
657 DBG(5, "TXBD %p: nxt %08x buf %08x len %04x opt %08x\n", 657 dev_dbg(musb->controller, "TXBD %p: nxt %08x buf %08x len %04x opt %08x\n",
658 bd, bd->hw_next, bd->hw_bufp, 658 bd, bd->hw_next, bd->hw_bufp,
659 bd->hw_off_len, bd->hw_options); 659 bd->hw_off_len, bd->hw_options);
660 660
@@ -819,8 +819,8 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
819 819
820 length = min(n_bds * maxpacket, length); 820 length = min(n_bds * maxpacket, length);
821 821
822 DBG(4, "RX DMA%d seg, maxp %d %s bds %d (cnt %d) " 822 dev_dbg(musb->controller, "RX DMA%d seg, maxp %d %s bds %d (cnt %d) "
823 "dma 0x%x len %u %u/%u\n", 823 "dma 0x%llx len %u %u/%u\n",
824 rx->index, maxpacket, 824 rx->index, maxpacket,
825 onepacket 825 onepacket
826 ? (is_rndis ? "rndis" : "onepacket") 826 ? (is_rndis ? "rndis" : "onepacket")
@@ -829,7 +829,8 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
829 musb_readl(tibase, 829 musb_readl(tibase,
830 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4)) 830 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4))
831 & 0xffff, 831 & 0xffff,
832 addr, length, rx->channel.actual_len, rx->buf_len); 832 (unsigned long long)addr, length,
833 rx->channel.actual_len, rx->buf_len);
833 834
834 /* only queue one segment at a time, since the hardware prevents 835 /* only queue one segment at a time, since the hardware prevents
835 * correct queue shutdown after unexpected short packets 836 * correct queue shutdown after unexpected short packets
@@ -935,7 +936,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
935 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4)) 936 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4))
936 & 0xffff; 937 & 0xffff;
937 if (i < (2 + n_bds)) { 938 if (i < (2 + n_bds)) {
938 DBG(2, "bufcnt%d underrun - %d (for %d)\n", 939 dev_dbg(musb->controller, "bufcnt%d underrun - %d (for %d)\n",
939 rx->index, i, n_bds); 940 rx->index, i, n_bds);
940 musb_writel(tibase, 941 musb_writel(tibase,
941 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4), 942 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4),
@@ -984,7 +985,7 @@ static int cppi_channel_program(struct dma_channel *ch,
984 /* WARN_ON(1); */ 985 /* WARN_ON(1); */
985 break; 986 break;
986 case MUSB_DMA_STATUS_UNKNOWN: 987 case MUSB_DMA_STATUS_UNKNOWN:
987 DBG(1, "%cX DMA%d not allocated!\n", 988 dev_dbg(musb->controller, "%cX DMA%d not allocated!\n",
988 cppi_ch->transmit ? 'T' : 'R', 989 cppi_ch->transmit ? 'T' : 'R',
989 cppi_ch->index); 990 cppi_ch->index);
990 /* FALLTHROUGH */ 991 /* FALLTHROUGH */
@@ -1039,9 +1040,9 @@ static bool cppi_rx_scan(struct cppi *cppi, unsigned ch)
1039 if (!completed && (bd->hw_options & CPPI_OWN_SET)) 1040 if (!completed && (bd->hw_options & CPPI_OWN_SET))
1040 break; 1041 break;
1041 1042
1042 DBG(5, "C/RXBD %08x: nxt %08x buf %08x " 1043 dev_dbg(musb->controller, "C/RXBD %llx: nxt %08x buf %08x "
1043 "off.len %08x opt.len %08x (%d)\n", 1044 "off.len %08x opt.len %08x (%d)\n",
1044 bd->dma, bd->hw_next, bd->hw_bufp, 1045 (unsigned long long)bd->dma, bd->hw_next, bd->hw_bufp,
1045 bd->hw_off_len, bd->hw_options, 1046 bd->hw_off_len, bd->hw_options,
1046 rx->channel.actual_len); 1047 rx->channel.actual_len);
1047 1048
@@ -1061,7 +1062,7 @@ static bool cppi_rx_scan(struct cppi *cppi, unsigned ch)
1061 * CPPI ignores those BDs even though OWN is still set. 1062 * CPPI ignores those BDs even though OWN is still set.
1062 */ 1063 */
1063 completed = true; 1064 completed = true;
1064 DBG(3, "rx short %d/%d (%d)\n", 1065 dev_dbg(musb->controller, "rx short %d/%d (%d)\n",
1065 len, bd->buflen, 1066 len, bd->buflen,
1066 rx->channel.actual_len); 1067 rx->channel.actual_len);
1067 } 1068 }
@@ -1111,11 +1112,12 @@ static bool cppi_rx_scan(struct cppi *cppi, unsigned ch)
1111 musb_ep_select(cppi->mregs, rx->index + 1); 1112 musb_ep_select(cppi->mregs, rx->index + 1);
1112 csr = musb_readw(regs, MUSB_RXCSR); 1113 csr = musb_readw(regs, MUSB_RXCSR);
1113 if (csr & MUSB_RXCSR_DMAENAB) { 1114 if (csr & MUSB_RXCSR_DMAENAB) {
1114 DBG(4, "list%d %p/%p, last %08x%s, csr %04x\n", 1115 dev_dbg(musb->controller, "list%d %p/%p, last %llx%s, csr %04x\n",
1115 rx->index, 1116 rx->index,
1116 rx->head, rx->tail, 1117 rx->head, rx->tail,
1117 rx->last_processed 1118 rx->last_processed
1118 ? rx->last_processed->dma 1119 ? (unsigned long long)
1120 rx->last_processed->dma
1119 : 0, 1121 : 0,
1120 completed ? ", completed" : "", 1122 completed ? ", completed" : "",
1121 csr); 1123 csr);
@@ -1156,7 +1158,7 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
1156 struct musb_hw_ep *hw_ep = NULL; 1158 struct musb_hw_ep *hw_ep = NULL;
1157 u32 rx, tx; 1159 u32 rx, tx;
1158 int i, index; 1160 int i, index;
1159 unsigned long flags; 1161 unsigned long uninitialized_var(flags);
1160 1162
1161 cppi = container_of(musb->dma_controller, struct cppi, controller); 1163 cppi = container_of(musb->dma_controller, struct cppi, controller);
1162 if (cppi->irq) 1164 if (cppi->irq)
@@ -1167,10 +1169,13 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
1167 tx = musb_readl(tibase, DAVINCI_TXCPPI_MASKED_REG); 1169 tx = musb_readl(tibase, DAVINCI_TXCPPI_MASKED_REG);
1168 rx = musb_readl(tibase, DAVINCI_RXCPPI_MASKED_REG); 1170 rx = musb_readl(tibase, DAVINCI_RXCPPI_MASKED_REG);
1169 1171
1170 if (!tx && !rx) 1172 if (!tx && !rx) {
1173 if (cppi->irq)
1174 spin_unlock_irqrestore(&musb->lock, flags);
1171 return IRQ_NONE; 1175 return IRQ_NONE;
1176 }
1172 1177
1173 DBG(4, "CPPI IRQ Tx%x Rx%x\n", tx, rx); 1178 dev_dbg(musb->controller, "CPPI IRQ Tx%x Rx%x\n", tx, rx);
1174 1179
1175 /* process TX channels */ 1180 /* process TX channels */
1176 for (index = 0; tx; tx = tx >> 1, index++) { 1181 for (index = 0; tx; tx = tx >> 1, index++) {
@@ -1198,8 +1203,8 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
1198 * that needs to be acknowledged. 1203 * that needs to be acknowledged.
1199 */ 1204 */
1200 if (NULL == bd) { 1205 if (NULL == bd) {
1201 DBG(1, "null BD\n"); 1206 dev_dbg(musb->controller, "null BD\n");
1202 tx_ram->tx_complete = 0; 1207 musb_writel(&tx_ram->tx_complete, 0, 0);
1203 continue; 1208 continue;
1204 } 1209 }
1205 1210
@@ -1213,7 +1218,7 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
1213 if (bd->hw_options & CPPI_OWN_SET) 1218 if (bd->hw_options & CPPI_OWN_SET)
1214 break; 1219 break;
1215 1220
1216 DBG(5, "C/TXBD %p n %x b %x off %x opt %x\n", 1221 dev_dbg(musb->controller, "C/TXBD %p n %x b %x off %x opt %x\n",
1217 bd, bd->hw_next, bd->hw_bufp, 1222 bd, bd->hw_next, bd->hw_bufp,
1218 bd->hw_off_len, bd->hw_options); 1223 bd->hw_off_len, bd->hw_options);
1219 1224
@@ -1308,7 +1313,7 @@ dma_controller_create(struct musb *musb, void __iomem *mregs)
1308 struct cppi *controller; 1313 struct cppi *controller;
1309 struct device *dev = musb->controller; 1314 struct device *dev = musb->controller;
1310 struct platform_device *pdev = to_platform_device(dev); 1315 struct platform_device *pdev = to_platform_device(dev);
1311 int irq = platform_get_irq(pdev, 1); 1316 int irq = platform_get_irq_byname(pdev, "dma");
1312 1317
1313 controller = kzalloc(sizeof *controller, GFP_KERNEL); 1318 controller = kzalloc(sizeof *controller, GFP_KERNEL);
1314 if (!controller) 1319 if (!controller)
@@ -1452,7 +1457,7 @@ static int cppi_channel_abort(struct dma_channel *channel)
1452 * compare mode by writing 1 to the tx_complete register. 1457 * compare mode by writing 1 to the tx_complete register.
1453 */ 1458 */
1454 cppi_reset_tx(tx_ram, 1); 1459 cppi_reset_tx(tx_ram, 1);
1455 cppi_ch->head = 0; 1460 cppi_ch->head = NULL;
1456 musb_writel(&tx_ram->tx_complete, 0, 1); 1461 musb_writel(&tx_ram->tx_complete, 0, 1);
1457 cppi_dump_tx(5, cppi_ch, " (done teardown)"); 1462 cppi_dump_tx(5, cppi_ch, " (done teardown)");
1458 1463
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
new file mode 100644
index 000000000000..662ed34980bd
--- /dev/null
+++ b/drivers/usb/musb/da8xx.c
@@ -0,0 +1,608 @@
1/*
2 * Texas Instruments DA8xx/OMAP-L1x "glue layer"
3 *
4 * Copyright (c) 2008-2009 MontaVista Software, Inc. <source@mvista.com>
5 *
6 * Based on the DaVinci "glue layer" code.
7 * Copyright (C) 2005-2006 by Texas Instruments
8 *
9 * This file is part of the Inventra Controller Driver for Linux.
10 *
11 * The Inventra Controller Driver for Linux is free software; you
12 * can redistribute it and/or modify it under the terms of the GNU
13 * General Public License version 2 as published by the Free Software
14 * Foundation.
15 *
16 * The Inventra Controller Driver for Linux is distributed in
17 * the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 * License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with The Inventra Controller Driver for Linux ; if not,
24 * write to the Free Software Foundation, Inc., 59 Temple Place,
25 * Suite 330, Boston, MA 02111-1307 USA
26 *
27 */
28
29#include <linux/init.h>
30#include <linux/clk.h>
31#include <linux/io.h>
32#include <linux/platform_device.h>
33#include <linux/dma-mapping.h>
34
35#include <mach/da8xx.h>
36#include <mach/usb.h>
37
38#include "musb_core.h"
39
40/*
41 * DA8XX specific definitions
42 */
43
44/* USB 2.0 OTG module registers */
45#define DA8XX_USB_REVISION_REG 0x00
46#define DA8XX_USB_CTRL_REG 0x04
47#define DA8XX_USB_STAT_REG 0x08
48#define DA8XX_USB_EMULATION_REG 0x0c
49#define DA8XX_USB_MODE_REG 0x10 /* Transparent, CDC, [Generic] RNDIS */
50#define DA8XX_USB_AUTOREQ_REG 0x14
51#define DA8XX_USB_SRP_FIX_TIME_REG 0x18
52#define DA8XX_USB_TEARDOWN_REG 0x1c
53#define DA8XX_USB_INTR_SRC_REG 0x20
54#define DA8XX_USB_INTR_SRC_SET_REG 0x24
55#define DA8XX_USB_INTR_SRC_CLEAR_REG 0x28
56#define DA8XX_USB_INTR_MASK_REG 0x2c
57#define DA8XX_USB_INTR_MASK_SET_REG 0x30
58#define DA8XX_USB_INTR_MASK_CLEAR_REG 0x34
59#define DA8XX_USB_INTR_SRC_MASKED_REG 0x38
60#define DA8XX_USB_END_OF_INTR_REG 0x3c
61#define DA8XX_USB_GENERIC_RNDIS_EP_SIZE_REG(n) (0x50 + (((n) - 1) << 2))
62
63/* Control register bits */
64#define DA8XX_SOFT_RESET_MASK 1
65
66#define DA8XX_USB_TX_EP_MASK 0x1f /* EP0 + 4 Tx EPs */
67#define DA8XX_USB_RX_EP_MASK 0x1e /* 4 Rx EPs */
68
69/* USB interrupt register bits */
70#define DA8XX_INTR_USB_SHIFT 16
71#define DA8XX_INTR_USB_MASK (0x1ff << DA8XX_INTR_USB_SHIFT) /* 8 Mentor */
72 /* interrupts and DRVVBUS interrupt */
73#define DA8XX_INTR_DRVVBUS 0x100
74#define DA8XX_INTR_RX_SHIFT 8
75#define DA8XX_INTR_RX_MASK (DA8XX_USB_RX_EP_MASK << DA8XX_INTR_RX_SHIFT)
76#define DA8XX_INTR_TX_SHIFT 0
77#define DA8XX_INTR_TX_MASK (DA8XX_USB_TX_EP_MASK << DA8XX_INTR_TX_SHIFT)
78
79#define DA8XX_MENTOR_CORE_OFFSET 0x400
80
81#define CFGCHIP2 IO_ADDRESS(DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP2_REG)
82
83struct da8xx_glue {
84 struct device *dev;
85 struct platform_device *musb;
86 struct clk *clk;
87};
88
89/*
90 * REVISIT (PM): we should be able to keep the PHY in low power mode most
91 * of the time (24 MHz oscillator and PLL off, etc.) by setting POWER.D0
92 * and, when in host mode, autosuspending idle root ports... PHY_PLLON
93 * (overriding SUSPENDM?) then likely needs to stay off.
94 */
95
96static inline void phy_on(void)
97{
98 u32 cfgchip2 = __raw_readl(CFGCHIP2);
99
100 /*
101 * Start the on-chip PHY and its PLL.
102 */
103 cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN);
104 cfgchip2 |= CFGCHIP2_PHY_PLLON;
105 __raw_writel(cfgchip2, CFGCHIP2);
106
107 pr_info("Waiting for USB PHY clock good...\n");
108 while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD))
109 cpu_relax();
110}
111
112static inline void phy_off(void)
113{
114 u32 cfgchip2 = __raw_readl(CFGCHIP2);
115
116 /*
117 * Ensure that USB 1.1 reference clock is not being sourced from
118 * USB 2.0 PHY. Otherwise do not power down the PHY.
119 */
120 if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX) &&
121 (cfgchip2 & CFGCHIP2_USB1SUSPENDM)) {
122 pr_warning("USB 1.1 clocked from USB 2.0 PHY -- "
123 "can't power it down\n");
124 return;
125 }
126
127 /*
128 * Power down the on-chip PHY.
129 */
130 cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN;
131 __raw_writel(cfgchip2, CFGCHIP2);
132}
133
134/*
135 * Because we don't set CTRL.UINT, it's "important" to:
136 * - not read/write INTRUSB/INTRUSBE (except during
137 * initial setup, as a workaround);
138 * - use INTSET/INTCLR instead.
139 */
140
141/**
142 * da8xx_musb_enable - enable interrupts
143 */
144static void da8xx_musb_enable(struct musb *musb)
145{
146 void __iomem *reg_base = musb->ctrl_base;
147 u32 mask;
148
149 /* Workaround: setup IRQs through both register sets. */
150 mask = ((musb->epmask & DA8XX_USB_TX_EP_MASK) << DA8XX_INTR_TX_SHIFT) |
151 ((musb->epmask & DA8XX_USB_RX_EP_MASK) << DA8XX_INTR_RX_SHIFT) |
152 DA8XX_INTR_USB_MASK;
153 musb_writel(reg_base, DA8XX_USB_INTR_MASK_SET_REG, mask);
154
155 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
156 if (is_otg_enabled(musb))
157 musb_writel(reg_base, DA8XX_USB_INTR_SRC_SET_REG,
158 DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT);
159}
160
161/**
162 * da8xx_musb_disable - disable HDRC and flush interrupts
163 */
164static void da8xx_musb_disable(struct musb *musb)
165{
166 void __iomem *reg_base = musb->ctrl_base;
167
168 musb_writel(reg_base, DA8XX_USB_INTR_MASK_CLEAR_REG,
169 DA8XX_INTR_USB_MASK |
170 DA8XX_INTR_TX_MASK | DA8XX_INTR_RX_MASK);
171 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
172 musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
173}
174
175#ifdef CONFIG_USB_MUSB_HDRC_HCD
176#define portstate(stmt) stmt
177#else
178#define portstate(stmt)
179#endif
180
181static void da8xx_musb_set_vbus(struct musb *musb, int is_on)
182{
183 WARN_ON(is_on && is_peripheral_active(musb));
184}
185
186#define POLL_SECONDS 2
187
188static struct timer_list otg_workaround;
189
190static void otg_timer(unsigned long _musb)
191{
192 struct musb *musb = (void *)_musb;
193 void __iomem *mregs = musb->mregs;
194 u8 devctl;
195 unsigned long flags;
196
197 /*
198 * We poll because DaVinci's won't expose several OTG-critical
199 * status change events (from the transceiver) otherwise.
200 */
201 devctl = musb_readb(mregs, MUSB_DEVCTL);
202 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
203 otg_state_string(musb->xceiv->state));
204
205 spin_lock_irqsave(&musb->lock, flags);
206 switch (musb->xceiv->state) {
207 case OTG_STATE_A_WAIT_BCON:
208 devctl &= ~MUSB_DEVCTL_SESSION;
209 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
210
211 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
212 if (devctl & MUSB_DEVCTL_BDEVICE) {
213 musb->xceiv->state = OTG_STATE_B_IDLE;
214 MUSB_DEV_MODE(musb);
215 } else {
216 musb->xceiv->state = OTG_STATE_A_IDLE;
217 MUSB_HST_MODE(musb);
218 }
219 break;
220 case OTG_STATE_A_WAIT_VFALL:
221 /*
222 * Wait till VBUS falls below SessionEnd (~0.2 V); the 1.3
223 * RTL seems to mis-handle session "start" otherwise (or in
224 * our case "recover"), in routine "VBUS was valid by the time
225 * VBUSERR got reported during enumeration" cases.
226 */
227 if (devctl & MUSB_DEVCTL_VBUS) {
228 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
229 break;
230 }
231 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
232 musb_writel(musb->ctrl_base, DA8XX_USB_INTR_SRC_SET_REG,
233 MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT);
234 break;
235 case OTG_STATE_B_IDLE:
236 if (!is_peripheral_enabled(musb))
237 break;
238
239 /*
240 * There's no ID-changed IRQ, so we have no good way to tell
241 * when to switch to the A-Default state machine (by setting
242 * the DEVCTL.Session bit).
243 *
244 * Workaround: whenever we're in B_IDLE, try setting the
245 * session flag every few seconds. If it works, ID was
246 * grounded and we're now in the A-Default state machine.
247 *
248 * NOTE: setting the session flag is _supposed_ to trigger
249 * SRP but clearly it doesn't.
250 */
251 musb_writeb(mregs, MUSB_DEVCTL, devctl | MUSB_DEVCTL_SESSION);
252 devctl = musb_readb(mregs, MUSB_DEVCTL);
253 if (devctl & MUSB_DEVCTL_BDEVICE)
254 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
255 else
256 musb->xceiv->state = OTG_STATE_A_IDLE;
257 break;
258 default:
259 break;
260 }
261 spin_unlock_irqrestore(&musb->lock, flags);
262}
263
264static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
265{
266 static unsigned long last_timer;
267
268 if (!is_otg_enabled(musb))
269 return;
270
271 if (timeout == 0)
272 timeout = jiffies + msecs_to_jiffies(3);
273
274 /* Never idle if active, or when VBUS timeout is not set as host */
275 if (musb->is_active || (musb->a_wait_bcon == 0 &&
276 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
277 dev_dbg(musb->controller, "%s active, deleting timer\n",
278 otg_state_string(musb->xceiv->state));
279 del_timer(&otg_workaround);
280 last_timer = jiffies;
281 return;
282 }
283
284 if (time_after(last_timer, timeout) && timer_pending(&otg_workaround)) {
285 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n");
286 return;
287 }
288 last_timer = timeout;
289
290 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
291 otg_state_string(musb->xceiv->state),
292 jiffies_to_msecs(timeout - jiffies));
293 mod_timer(&otg_workaround, timeout);
294}
295
296static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
297{
298 struct musb *musb = hci;
299 void __iomem *reg_base = musb->ctrl_base;
300 unsigned long flags;
301 irqreturn_t ret = IRQ_NONE;
302 u32 status;
303
304 spin_lock_irqsave(&musb->lock, flags);
305
306 /*
307 * NOTE: DA8XX shadows the Mentor IRQs. Don't manage them through
308 * the Mentor registers (except for setup), use the TI ones and EOI.
309 */
310
311 /* Acknowledge and handle non-CPPI interrupts */
312 status = musb_readl(reg_base, DA8XX_USB_INTR_SRC_MASKED_REG);
313 if (!status)
314 goto eoi;
315
316 musb_writel(reg_base, DA8XX_USB_INTR_SRC_CLEAR_REG, status);
317 dev_dbg(musb->controller, "USB IRQ %08x\n", status);
318
319 musb->int_rx = (status & DA8XX_INTR_RX_MASK) >> DA8XX_INTR_RX_SHIFT;
320 musb->int_tx = (status & DA8XX_INTR_TX_MASK) >> DA8XX_INTR_TX_SHIFT;
321 musb->int_usb = (status & DA8XX_INTR_USB_MASK) >> DA8XX_INTR_USB_SHIFT;
322
323 /*
324 * DRVVBUS IRQs are the only proxy we have (a very poor one!) for
325 * DA8xx's missing ID change IRQ. We need an ID change IRQ to
326 * switch appropriately between halves of the OTG state machine.
327 * Managing DEVCTL.Session per Mentor docs requires that we know its
328 * value but DEVCTL.BDevice is invalid without DEVCTL.Session set.
329 * Also, DRVVBUS pulses for SRP (but not at 5 V)...
330 */
331 if (status & (DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT)) {
332 int drvvbus = musb_readl(reg_base, DA8XX_USB_STAT_REG);
333 void __iomem *mregs = musb->mregs;
334 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
335 int err;
336
337 err = is_host_enabled(musb) && (musb->int_usb &
338 MUSB_INTR_VBUSERROR);
339 if (err) {
340 /*
341 * The Mentor core doesn't debounce VBUS as needed
342 * to cope with device connect current spikes. This
343 * means it's not uncommon for bus-powered devices
344 * to get VBUS errors during enumeration.
345 *
346 * This is a workaround, but newer RTL from Mentor
347 * seems to allow a better one: "re"-starting sessions
348 * without waiting for VBUS to stop registering in
349 * devctl.
350 */
351 musb->int_usb &= ~MUSB_INTR_VBUSERROR;
352 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
353 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
354 WARNING("VBUS error workaround (delay coming)\n");
355 } else if (is_host_enabled(musb) && drvvbus) {
356 MUSB_HST_MODE(musb);
357 musb->xceiv->default_a = 1;
358 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
359 portstate(musb->port1_status |= USB_PORT_STAT_POWER);
360 del_timer(&otg_workaround);
361 } else {
362 musb->is_active = 0;
363 MUSB_DEV_MODE(musb);
364 musb->xceiv->default_a = 0;
365 musb->xceiv->state = OTG_STATE_B_IDLE;
366 portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
367 }
368
369 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
370 drvvbus ? "on" : "off",
371 otg_state_string(musb->xceiv->state),
372 err ? " ERROR" : "",
373 devctl);
374 ret = IRQ_HANDLED;
375 }
376
377 if (musb->int_tx || musb->int_rx || musb->int_usb)
378 ret |= musb_interrupt(musb);
379
380 eoi:
381 /* EOI needs to be written for the IRQ to be re-asserted. */
382 if (ret == IRQ_HANDLED || status)
383 musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
384
385 /* Poll for ID change */
386 if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE)
387 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
388
389 spin_unlock_irqrestore(&musb->lock, flags);
390
391 return ret;
392}
393
394static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode)
395{
396 u32 cfgchip2 = __raw_readl(CFGCHIP2);
397
398 cfgchip2 &= ~CFGCHIP2_OTGMODE;
399 switch (musb_mode) {
400#ifdef CONFIG_USB_MUSB_HDRC_HCD
401 case MUSB_HOST: /* Force VBUS valid, ID = 0 */
402 cfgchip2 |= CFGCHIP2_FORCE_HOST;
403 break;
404#endif
405#ifdef CONFIG_USB_GADGET_MUSB_HDRC
406 case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */
407 cfgchip2 |= CFGCHIP2_FORCE_DEVICE;
408 break;
409#endif
410#ifdef CONFIG_USB_MUSB_OTG
411 case MUSB_OTG: /* Don't override the VBUS/ID comparators */
412 cfgchip2 |= CFGCHIP2_NO_OVERRIDE;
413 break;
414#endif
415 default:
416 dev_dbg(musb->controller, "Trying to set unsupported mode %u\n", musb_mode);
417 }
418
419 __raw_writel(cfgchip2, CFGCHIP2);
420 return 0;
421}
422
423static int da8xx_musb_init(struct musb *musb)
424{
425 void __iomem *reg_base = musb->ctrl_base;
426 u32 rev;
427
428 musb->mregs += DA8XX_MENTOR_CORE_OFFSET;
429
430 /* Returns zero if e.g. not clocked */
431 rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG);
432 if (!rev)
433 goto fail;
434
435 usb_nop_xceiv_register();
436 musb->xceiv = otg_get_transceiver();
437 if (!musb->xceiv)
438 goto fail;
439
440 if (is_host_enabled(musb))
441 setup_timer(&otg_workaround, otg_timer, (unsigned long)musb);
442
443 /* Reset the controller */
444 musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK);
445
446 /* Start the on-chip PHY and its PLL. */
447 phy_on();
448
449 msleep(5);
450
451 /* NOTE: IRQs are in mixed mode, not bypass to pure MUSB */
452 pr_debug("DA8xx OTG revision %08x, PHY %03x, control %02x\n",
453 rev, __raw_readl(CFGCHIP2),
454 musb_readb(reg_base, DA8XX_USB_CTRL_REG));
455
456 musb->isr = da8xx_musb_interrupt;
457 return 0;
458fail:
459 return -ENODEV;
460}
461
462static int da8xx_musb_exit(struct musb *musb)
463{
464 if (is_host_enabled(musb))
465 del_timer_sync(&otg_workaround);
466
467 phy_off();
468
469 otg_put_transceiver(musb->xceiv);
470 usb_nop_xceiv_unregister();
471
472 return 0;
473}
474
475static const struct musb_platform_ops da8xx_ops = {
476 .init = da8xx_musb_init,
477 .exit = da8xx_musb_exit,
478
479 .enable = da8xx_musb_enable,
480 .disable = da8xx_musb_disable,
481
482 .set_mode = da8xx_musb_set_mode,
483 .try_idle = da8xx_musb_try_idle,
484
485 .set_vbus = da8xx_musb_set_vbus,
486};
487
488static u64 da8xx_dmamask = DMA_BIT_MASK(32);
489
490static int __init da8xx_probe(struct platform_device *pdev)
491{
492 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
493 struct platform_device *musb;
494 struct da8xx_glue *glue;
495
496 struct clk *clk;
497
498 int ret = -ENOMEM;
499
500 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
501 if (!glue) {
502 dev_err(&pdev->dev, "failed to allocate glue context\n");
503 goto err0;
504 }
505
506 musb = platform_device_alloc("musb-hdrc", -1);
507 if (!musb) {
508 dev_err(&pdev->dev, "failed to allocate musb device\n");
509 goto err1;
510 }
511
512 clk = clk_get(&pdev->dev, "usb20");
513 if (IS_ERR(clk)) {
514 dev_err(&pdev->dev, "failed to get clock\n");
515 ret = PTR_ERR(clk);
516 goto err2;
517 }
518
519 ret = clk_enable(clk);
520 if (ret) {
521 dev_err(&pdev->dev, "failed to enable clock\n");
522 goto err3;
523 }
524
525 musb->dev.parent = &pdev->dev;
526 musb->dev.dma_mask = &da8xx_dmamask;
527 musb->dev.coherent_dma_mask = da8xx_dmamask;
528
529 glue->dev = &pdev->dev;
530 glue->musb = musb;
531 glue->clk = clk;
532
533 pdata->platform_ops = &da8xx_ops;
534
535 platform_set_drvdata(pdev, glue);
536
537 ret = platform_device_add_resources(musb, pdev->resource,
538 pdev->num_resources);
539 if (ret) {
540 dev_err(&pdev->dev, "failed to add resources\n");
541 goto err4;
542 }
543
544 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
545 if (ret) {
546 dev_err(&pdev->dev, "failed to add platform_data\n");
547 goto err4;
548 }
549
550 ret = platform_device_add(musb);
551 if (ret) {
552 dev_err(&pdev->dev, "failed to register musb device\n");
553 goto err4;
554 }
555
556 return 0;
557
558err4:
559 clk_disable(clk);
560
561err3:
562 clk_put(clk);
563
564err2:
565 platform_device_put(musb);
566
567err1:
568 kfree(glue);
569
570err0:
571 return ret;
572}
573
574static int __exit da8xx_remove(struct platform_device *pdev)
575{
576 struct da8xx_glue *glue = platform_get_drvdata(pdev);
577
578 platform_device_del(glue->musb);
579 platform_device_put(glue->musb);
580 clk_disable(glue->clk);
581 clk_put(glue->clk);
582 kfree(glue);
583
584 return 0;
585}
586
587static struct platform_driver da8xx_driver = {
588 .remove = __exit_p(da8xx_remove),
589 .driver = {
590 .name = "musb-da8xx",
591 },
592};
593
594MODULE_DESCRIPTION("DA8xx/OMAP-L1x MUSB Glue Layer");
595MODULE_AUTHOR("Sergei Shtylyov <sshtylyov@ru.mvista.com>");
596MODULE_LICENSE("GPL v2");
597
598static int __init da8xx_init(void)
599{
600 return platform_driver_probe(&da8xx_driver, da8xx_probe);
601}
602subsys_initcall(da8xx_init);
603
604static void __exit da8xx_exit(void)
605{
606 platform_driver_unregister(&da8xx_driver);
607}
608module_exit(da8xx_exit);
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 57624361c1de..2a2adf6492cd 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -30,6 +30,8 @@
30#include <linux/clk.h> 30#include <linux/clk.h>
31#include <linux/io.h> 31#include <linux/io.h>
32#include <linux/gpio.h> 32#include <linux/gpio.h>
33#include <linux/platform_device.h>
34#include <linux/dma-mapping.h>
33 35
34#include <mach/hardware.h> 36#include <mach/hardware.h>
35#include <mach/memory.h> 37#include <mach/memory.h>
@@ -51,6 +53,12 @@
51#define USB_PHY_CTRL IO_ADDRESS(USBPHY_CTL_PADDR) 53#define USB_PHY_CTRL IO_ADDRESS(USBPHY_CTL_PADDR)
52#define DM355_DEEPSLEEP IO_ADDRESS(DM355_DEEPSLEEP_PADDR) 54#define DM355_DEEPSLEEP IO_ADDRESS(DM355_DEEPSLEEP_PADDR)
53 55
56struct davinci_glue {
57 struct device *dev;
58 struct platform_device *musb;
59 struct clk *clk;
60};
61
54/* REVISIT (PM) we should be able to keep the PHY in low power mode most 62/* REVISIT (PM) we should be able to keep the PHY in low power mode most
55 * of the time (24 MHZ oscillator and PLL off, etc) by setting POWER.D0 63 * of the time (24 MHZ oscillator and PLL off, etc) by setting POWER.D0
56 * and, when in host mode, autosuspending idle root ports... PHYPLLON 64 * and, when in host mode, autosuspending idle root ports... PHYPLLON
@@ -83,7 +91,7 @@ static inline void phy_off(void)
83 91
84static int dma_off = 1; 92static int dma_off = 1;
85 93
86void musb_platform_enable(struct musb *musb) 94static void davinci_musb_enable(struct musb *musb)
87{ 95{
88 u32 tmp, old, val; 96 u32 tmp, old, val;
89 97
@@ -116,7 +124,7 @@ void musb_platform_enable(struct musb *musb)
116/* 124/*
117 * Disable the HDRC and flush interrupts 125 * Disable the HDRC and flush interrupts
118 */ 126 */
119void musb_platform_disable(struct musb *musb) 127static void davinci_musb_disable(struct musb *musb)
120{ 128{
121 /* because we don't set CTRLR.UINT, "important" to: 129 /* because we don't set CTRLR.UINT, "important" to:
122 * - not read/write INTRUSB/INTRUSBE 130 * - not read/write INTRUSB/INTRUSBE
@@ -167,7 +175,7 @@ static void evm_deferred_drvvbus(struct work_struct *ignored)
167 175
168#endif /* EVM */ 176#endif /* EVM */
169 177
170static void davinci_source_power(struct musb *musb, int is_on, int immediate) 178static void davinci_musb_source_power(struct musb *musb, int is_on, int immediate)
171{ 179{
172#ifdef CONFIG_MACH_DAVINCI_EVM 180#ifdef CONFIG_MACH_DAVINCI_EVM
173 if (is_on) 181 if (is_on)
@@ -190,10 +198,10 @@ static void davinci_source_power(struct musb *musb, int is_on, int immediate)
190#endif 198#endif
191} 199}
192 200
193static void davinci_set_vbus(struct musb *musb, int is_on) 201static void davinci_musb_set_vbus(struct musb *musb, int is_on)
194{ 202{
195 WARN_ON(is_on && is_peripheral_active(musb)); 203 WARN_ON(is_on && is_peripheral_active(musb));
196 davinci_source_power(musb, is_on, 0); 204 davinci_musb_source_power(musb, is_on, 0);
197} 205}
198 206
199 207
@@ -212,7 +220,8 @@ static void otg_timer(unsigned long _musb)
212 * status change events (from the transceiver) otherwise. 220 * status change events (from the transceiver) otherwise.
213 */ 221 */
214 devctl = musb_readb(mregs, MUSB_DEVCTL); 222 devctl = musb_readb(mregs, MUSB_DEVCTL);
215 DBG(7, "poll devctl %02x (%s)\n", devctl, otg_state_string(musb)); 223 dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl,
224 otg_state_string(musb->xceiv->state));
216 225
217 spin_lock_irqsave(&musb->lock, flags); 226 spin_lock_irqsave(&musb->lock, flags);
218 switch (musb->xceiv->state) { 227 switch (musb->xceiv->state) {
@@ -259,7 +268,7 @@ static void otg_timer(unsigned long _musb)
259 spin_unlock_irqrestore(&musb->lock, flags); 268 spin_unlock_irqrestore(&musb->lock, flags);
260} 269}
261 270
262static irqreturn_t davinci_interrupt(int irq, void *__hci) 271static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
263{ 272{
264 unsigned long flags; 273 unsigned long flags;
265 irqreturn_t retval = IRQ_NONE; 274 irqreturn_t retval = IRQ_NONE;
@@ -289,7 +298,7 @@ static irqreturn_t davinci_interrupt(int irq, void *__hci)
289 /* ack and handle non-CPPI interrupts */ 298 /* ack and handle non-CPPI interrupts */
290 tmp = musb_readl(tibase, DAVINCI_USB_INT_SRC_MASKED_REG); 299 tmp = musb_readl(tibase, DAVINCI_USB_INT_SRC_MASKED_REG);
291 musb_writel(tibase, DAVINCI_USB_INT_SRC_CLR_REG, tmp); 300 musb_writel(tibase, DAVINCI_USB_INT_SRC_CLR_REG, tmp);
292 DBG(4, "IRQ %08x\n", tmp); 301 dev_dbg(musb->controller, "IRQ %08x\n", tmp);
293 302
294 musb->int_rx = (tmp & DAVINCI_USB_RXINT_MASK) 303 musb->int_rx = (tmp & DAVINCI_USB_RXINT_MASK)
295 >> DAVINCI_USB_RXINT_SHIFT; 304 >> DAVINCI_USB_RXINT_SHIFT;
@@ -345,10 +354,10 @@ static irqreturn_t davinci_interrupt(int irq, void *__hci)
345 /* NOTE: this must complete poweron within 100 msec 354 /* NOTE: this must complete poweron within 100 msec
346 * (OTG_TIME_A_WAIT_VRISE) but we don't check for that. 355 * (OTG_TIME_A_WAIT_VRISE) but we don't check for that.
347 */ 356 */
348 davinci_source_power(musb, drvvbus, 0); 357 davinci_musb_source_power(musb, drvvbus, 0);
349 DBG(2, "VBUS %s (%s)%s, devctl %02x\n", 358 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
350 drvvbus ? "on" : "off", 359 drvvbus ? "on" : "off",
351 otg_state_string(musb), 360 otg_state_string(musb->xceiv->state),
352 err ? " ERROR" : "", 361 err ? " ERROR" : "",
353 devctl); 362 devctl);
354 retval = IRQ_HANDLED; 363 retval = IRQ_HANDLED;
@@ -370,13 +379,13 @@ static irqreturn_t davinci_interrupt(int irq, void *__hci)
370 return retval; 379 return retval;
371} 380}
372 381
373int musb_platform_set_mode(struct musb *musb, u8 mode) 382static int davinci_musb_set_mode(struct musb *musb, u8 mode)
374{ 383{
375 /* EVM can't do this (right?) */ 384 /* EVM can't do this (right?) */
376 return -EIO; 385 return -EIO;
377} 386}
378 387
379int __init musb_platform_init(struct musb *musb, void *board_data) 388static int davinci_musb_init(struct musb *musb)
380{ 389{
381 void __iomem *tibase = musb->ctrl_base; 390 void __iomem *tibase = musb->ctrl_base;
382 u32 revision; 391 u32 revision;
@@ -388,8 +397,6 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
388 397
389 musb->mregs += DAVINCI_BASE_OFFSET; 398 musb->mregs += DAVINCI_BASE_OFFSET;
390 399
391 clk_enable(musb->clock);
392
393 /* returns zero if e.g. not clocked */ 400 /* returns zero if e.g. not clocked */
394 revision = musb_readl(tibase, DAVINCI_USB_VERSION_REG); 401 revision = musb_readl(tibase, DAVINCI_USB_VERSION_REG);
395 if (revision == 0) 402 if (revision == 0)
@@ -398,8 +405,7 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
398 if (is_host_enabled(musb)) 405 if (is_host_enabled(musb))
399 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb); 406 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
400 407
401 musb->board_set_vbus = davinci_set_vbus; 408 davinci_musb_source_power(musb, 0, 1);
402 davinci_source_power(musb, 0, 1);
403 409
404 /* dm355 EVM swaps D+/D- for signal integrity, and 410 /* dm355 EVM swaps D+/D- for signal integrity, and
405 * is clocked from the main 24 MHz crystal. 411 * is clocked from the main 24 MHz crystal.
@@ -440,17 +446,16 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
440 revision, __raw_readl(USB_PHY_CTRL), 446 revision, __raw_readl(USB_PHY_CTRL),
441 musb_readb(tibase, DAVINCI_USB_CTRL_REG)); 447 musb_readb(tibase, DAVINCI_USB_CTRL_REG));
442 448
443 musb->isr = davinci_interrupt; 449 musb->isr = davinci_musb_interrupt;
444 return 0; 450 return 0;
445 451
446fail: 452fail:
447 clk_disable(musb->clock); 453 otg_put_transceiver(musb->xceiv);
448
449 usb_nop_xceiv_unregister(); 454 usb_nop_xceiv_unregister();
450 return -ENODEV; 455 return -ENODEV;
451} 456}
452 457
453int musb_platform_exit(struct musb *musb) 458static int davinci_musb_exit(struct musb *musb)
454{ 459{
455 if (is_host_enabled(musb)) 460 if (is_host_enabled(musb))
456 del_timer_sync(&otg_workaround); 461 del_timer_sync(&otg_workaround);
@@ -464,7 +469,7 @@ int musb_platform_exit(struct musb *musb)
464 __raw_writel(deepsleep, DM355_DEEPSLEEP); 469 __raw_writel(deepsleep, DM355_DEEPSLEEP);
465 } 470 }
466 471
467 davinci_source_power(musb, 0 /*off*/, 1); 472 davinci_musb_source_power(musb, 0 /*off*/, 1);
468 473
469 /* delay, to avoid problems with module reload */ 474 /* delay, to avoid problems with module reload */
470 if (is_host_enabled(musb) && musb->xceiv->default_a) { 475 if (is_host_enabled(musb) && musb->xceiv->default_a) {
@@ -480,7 +485,7 @@ int musb_platform_exit(struct musb *musb)
480 break; 485 break;
481 if ((devctl & MUSB_DEVCTL_VBUS) != warn) { 486 if ((devctl & MUSB_DEVCTL_VBUS) != warn) {
482 warn = devctl & MUSB_DEVCTL_VBUS; 487 warn = devctl & MUSB_DEVCTL_VBUS;
483 DBG(1, "VBUS %d\n", 488 dev_dbg(musb->controller, "VBUS %d\n",
484 warn >> MUSB_DEVCTL_VBUS_SHIFT); 489 warn >> MUSB_DEVCTL_VBUS_SHIFT);
485 } 490 }
486 msleep(1000); 491 msleep(1000);
@@ -489,14 +494,146 @@ int musb_platform_exit(struct musb *musb)
489 494
490 /* in OTG mode, another host might be connected */ 495 /* in OTG mode, another host might be connected */
491 if (devctl & MUSB_DEVCTL_VBUS) 496 if (devctl & MUSB_DEVCTL_VBUS)
492 DBG(1, "VBUS off timeout (devctl %02x)\n", devctl); 497 dev_dbg(musb->controller, "VBUS off timeout (devctl %02x)\n", devctl);
493 } 498 }
494 499
495 phy_off(); 500 phy_off();
496 501
497 clk_disable(musb->clock); 502 otg_put_transceiver(musb->xceiv);
498
499 usb_nop_xceiv_unregister(); 503 usb_nop_xceiv_unregister();
500 504
501 return 0; 505 return 0;
502} 506}
507
508static const struct musb_platform_ops davinci_ops = {
509 .init = davinci_musb_init,
510 .exit = davinci_musb_exit,
511
512 .enable = davinci_musb_enable,
513 .disable = davinci_musb_disable,
514
515 .set_mode = davinci_musb_set_mode,
516
517 .set_vbus = davinci_musb_set_vbus,
518};
519
520static u64 davinci_dmamask = DMA_BIT_MASK(32);
521
522static int __init davinci_probe(struct platform_device *pdev)
523{
524 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
525 struct platform_device *musb;
526 struct davinci_glue *glue;
527 struct clk *clk;
528
529 int ret = -ENOMEM;
530
531 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
532 if (!glue) {
533 dev_err(&pdev->dev, "failed to allocate glue context\n");
534 goto err0;
535 }
536
537 musb = platform_device_alloc("musb-hdrc", -1);
538 if (!musb) {
539 dev_err(&pdev->dev, "failed to allocate musb device\n");
540 goto err1;
541 }
542
543 clk = clk_get(&pdev->dev, "usb");
544 if (IS_ERR(clk)) {
545 dev_err(&pdev->dev, "failed to get clock\n");
546 ret = PTR_ERR(clk);
547 goto err2;
548 }
549
550 ret = clk_enable(clk);
551 if (ret) {
552 dev_err(&pdev->dev, "failed to enable clock\n");
553 goto err3;
554 }
555
556 musb->dev.parent = &pdev->dev;
557 musb->dev.dma_mask = &davinci_dmamask;
558 musb->dev.coherent_dma_mask = davinci_dmamask;
559
560 glue->dev = &pdev->dev;
561 glue->musb = musb;
562 glue->clk = clk;
563
564 pdata->platform_ops = &davinci_ops;
565
566 platform_set_drvdata(pdev, glue);
567
568 ret = platform_device_add_resources(musb, pdev->resource,
569 pdev->num_resources);
570 if (ret) {
571 dev_err(&pdev->dev, "failed to add resources\n");
572 goto err4;
573 }
574
575 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
576 if (ret) {
577 dev_err(&pdev->dev, "failed to add platform_data\n");
578 goto err4;
579 }
580
581 ret = platform_device_add(musb);
582 if (ret) {
583 dev_err(&pdev->dev, "failed to register musb device\n");
584 goto err4;
585 }
586
587 return 0;
588
589err4:
590 clk_disable(clk);
591
592err3:
593 clk_put(clk);
594
595err2:
596 platform_device_put(musb);
597
598err1:
599 kfree(glue);
600
601err0:
602 return ret;
603}
604
605static int __exit davinci_remove(struct platform_device *pdev)
606{
607 struct davinci_glue *glue = platform_get_drvdata(pdev);
608
609 platform_device_del(glue->musb);
610 platform_device_put(glue->musb);
611 clk_disable(glue->clk);
612 clk_put(glue->clk);
613 kfree(glue);
614
615 return 0;
616}
617
618static struct platform_driver davinci_driver = {
619 .remove = __exit_p(davinci_remove),
620 .driver = {
621 .name = "musb-davinci",
622 },
623};
624
625MODULE_DESCRIPTION("DaVinci MUSB Glue Layer");
626MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
627MODULE_LICENSE("GPL v2");
628
629static int __init davinci_init(void)
630{
631 return platform_driver_probe(&davinci_driver, davinci_probe);
632}
633subsys_initcall(davinci_init);
634
635static void __exit davinci_exit(void)
636{
637 platform_driver_unregister(&davinci_driver);
638}
639module_exit(davinci_exit);
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 540c766c4f86..c71b0372786e 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -96,29 +96,15 @@
96#include <linux/init.h> 96#include <linux/init.h>
97#include <linux/list.h> 97#include <linux/list.h>
98#include <linux/kobject.h> 98#include <linux/kobject.h>
99#include <linux/prefetch.h>
99#include <linux/platform_device.h> 100#include <linux/platform_device.h>
100#include <linux/io.h> 101#include <linux/io.h>
101 102
102#ifdef CONFIG_ARM
103#include <mach/hardware.h>
104#include <mach/memory.h>
105#include <asm/mach-types.h>
106#endif
107
108#include "musb_core.h" 103#include "musb_core.h"
109 104
110
111#ifdef CONFIG_ARCH_DAVINCI
112#include "davinci.h"
113#endif
114
115#define TA_WAIT_BCON(m) max_t(int, (m)->a_wait_bcon, OTG_TIME_A_WAIT_BCON) 105#define TA_WAIT_BCON(m) max_t(int, (m)->a_wait_bcon, OTG_TIME_A_WAIT_BCON)
116 106
117 107
118unsigned musb_debug;
119module_param_named(debug, musb_debug, uint, S_IRUGO | S_IWUSR);
120MODULE_PARM_DESC(debug, "Debug message level. Default = 0");
121
122#define DRIVER_AUTHOR "Mentor Graphics, Texas Instruments, Nokia" 108#define DRIVER_AUTHOR "Mentor Graphics, Texas Instruments, Nokia"
123#define DRIVER_DESC "Inventra Dual-Role USB Controller Driver" 109#define DRIVER_DESC "Inventra Dual-Role USB Controller Driver"
124 110
@@ -126,7 +112,7 @@ MODULE_PARM_DESC(debug, "Debug message level. Default = 0");
126 112
127#define DRIVER_INFO DRIVER_DESC ", v" MUSB_VERSION 113#define DRIVER_INFO DRIVER_DESC ", v" MUSB_VERSION
128 114
129#define MUSB_DRIVER_NAME "musb_hdrc" 115#define MUSB_DRIVER_NAME "musb-hdrc"
130const char musb_driver_name[] = MUSB_DRIVER_NAME; 116const char musb_driver_name[] = MUSB_DRIVER_NAME;
131 117
132MODULE_DESCRIPTION(DRIVER_INFO); 118MODULE_DESCRIPTION(DRIVER_INFO);
@@ -139,12 +125,7 @@ MODULE_ALIAS("platform:" MUSB_DRIVER_NAME);
139 125
140static inline struct musb *dev_to_musb(struct device *dev) 126static inline struct musb *dev_to_musb(struct device *dev)
141{ 127{
142#ifdef CONFIG_USB_MUSB_HDRC_HCD
143 /* usbcore insists dev->driver_data is a "struct hcd *" */
144 return hcd_to_musb(dev_get_drvdata(dev));
145#else
146 return dev_get_drvdata(dev); 128 return dev_get_drvdata(dev);
147#endif
148} 129}
149 130
150/*-------------------------------------------------------------------------*/ 131/*-------------------------------------------------------------------------*/
@@ -173,10 +154,8 @@ static int musb_ulpi_read(struct otg_transceiver *otg, u32 offset)
173 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL) 154 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
174 & MUSB_ULPI_REG_CMPLT)) { 155 & MUSB_ULPI_REG_CMPLT)) {
175 i++; 156 i++;
176 if (i == 10000) { 157 if (i == 10000)
177 DBG(3, "ULPI read timed out\n");
178 return -ETIMEDOUT; 158 return -ETIMEDOUT;
179 }
180 159
181 } 160 }
182 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL); 161 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
@@ -206,10 +185,8 @@ static int musb_ulpi_write(struct otg_transceiver *otg,
206 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL) 185 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
207 & MUSB_ULPI_REG_CMPLT)) { 186 & MUSB_ULPI_REG_CMPLT)) {
208 i++; 187 i++;
209 if (i == 10000) { 188 if (i == 10000)
210 DBG(3, "ULPI write timed out\n");
211 return -ETIMEDOUT; 189 return -ETIMEDOUT;
212 }
213 } 190 }
214 191
215 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL); 192 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
@@ -230,18 +207,19 @@ static struct otg_io_access_ops musb_ulpi_access = {
230 207
231/*-------------------------------------------------------------------------*/ 208/*-------------------------------------------------------------------------*/
232 209
233#if !defined(CONFIG_USB_TUSB6010) && !defined(CONFIG_BLACKFIN) 210#if !defined(CONFIG_USB_MUSB_TUSB6010) && !defined(CONFIG_USB_MUSB_BLACKFIN)
234 211
235/* 212/*
236 * Load an endpoint's FIFO 213 * Load an endpoint's FIFO
237 */ 214 */
238void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) 215void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
239{ 216{
217 struct musb *musb = hw_ep->musb;
240 void __iomem *fifo = hw_ep->fifo; 218 void __iomem *fifo = hw_ep->fifo;
241 219
242 prefetch((u8 *)src); 220 prefetch((u8 *)src);
243 221
244 DBG(4, "%cX ep%d fifo %p count %d buf %p\n", 222 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
245 'T', hw_ep->epnum, fifo, len, src); 223 'T', hw_ep->epnum, fifo, len, src);
246 224
247 /* we can't assume unaligned reads work */ 225 /* we can't assume unaligned reads work */
@@ -272,14 +250,16 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
272 } 250 }
273} 251}
274 252
253#if !defined(CONFIG_USB_MUSB_AM35X)
275/* 254/*
276 * Unload an endpoint's FIFO 255 * Unload an endpoint's FIFO
277 */ 256 */
278void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) 257void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
279{ 258{
259 struct musb *musb = hw_ep->musb;
280 void __iomem *fifo = hw_ep->fifo; 260 void __iomem *fifo = hw_ep->fifo;
281 261
282 DBG(4, "%cX ep%d fifo %p count %d buf %p\n", 262 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
283 'R', hw_ep->epnum, fifo, len, dst); 263 'R', hw_ep->epnum, fifo, len, dst);
284 264
285 /* we can't assume unaligned writes work */ 265 /* we can't assume unaligned writes work */
@@ -309,6 +289,7 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
309 readsb(fifo, dst, len); 289 readsb(fifo, dst, len);
310 } 290 }
311} 291}
292#endif
312 293
313#endif /* normal PIO */ 294#endif /* normal PIO */
314 295
@@ -347,26 +328,6 @@ void musb_load_testpacket(struct musb *musb)
347 328
348/*-------------------------------------------------------------------------*/ 329/*-------------------------------------------------------------------------*/
349 330
350const char *otg_state_string(struct musb *musb)
351{
352 switch (musb->xceiv->state) {
353 case OTG_STATE_A_IDLE: return "a_idle";
354 case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
355 case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
356 case OTG_STATE_A_HOST: return "a_host";
357 case OTG_STATE_A_SUSPEND: return "a_suspend";
358 case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
359 case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
360 case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
361 case OTG_STATE_B_IDLE: return "b_idle";
362 case OTG_STATE_B_SRP_INIT: return "b_srp_init";
363 case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
364 case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
365 case OTG_STATE_B_HOST: return "b_host";
366 default: return "UNDEFINED";
367 }
368}
369
370#ifdef CONFIG_USB_MUSB_OTG 331#ifdef CONFIG_USB_MUSB_OTG
371 332
372/* 333/*
@@ -380,19 +341,21 @@ void musb_otg_timer_func(unsigned long data)
380 spin_lock_irqsave(&musb->lock, flags); 341 spin_lock_irqsave(&musb->lock, flags);
381 switch (musb->xceiv->state) { 342 switch (musb->xceiv->state) {
382 case OTG_STATE_B_WAIT_ACON: 343 case OTG_STATE_B_WAIT_ACON:
383 DBG(1, "HNP: b_wait_acon timeout; back to b_peripheral\n"); 344 dev_dbg(musb->controller, "HNP: b_wait_acon timeout; back to b_peripheral\n");
384 musb_g_disconnect(musb); 345 musb_g_disconnect(musb);
385 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 346 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
386 musb->is_active = 0; 347 musb->is_active = 0;
387 break; 348 break;
388 case OTG_STATE_A_SUSPEND: 349 case OTG_STATE_A_SUSPEND:
389 case OTG_STATE_A_WAIT_BCON: 350 case OTG_STATE_A_WAIT_BCON:
390 DBG(1, "HNP: %s timeout\n", otg_state_string(musb)); 351 dev_dbg(musb->controller, "HNP: %s timeout\n",
391 musb_set_vbus(musb, 0); 352 otg_state_string(musb->xceiv->state));
353 musb_platform_set_vbus(musb, 0);
392 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 354 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
393 break; 355 break;
394 default: 356 default:
395 DBG(1, "HNP: Unhandled mode %s\n", otg_state_string(musb)); 357 dev_dbg(musb->controller, "HNP: Unhandled mode %s\n",
358 otg_state_string(musb->xceiv->state));
396 } 359 }
397 musb->ignore_disconnect = 0; 360 musb->ignore_disconnect = 0;
398 spin_unlock_irqrestore(&musb->lock, flags); 361 spin_unlock_irqrestore(&musb->lock, flags);
@@ -407,15 +370,16 @@ void musb_hnp_stop(struct musb *musb)
407 void __iomem *mbase = musb->mregs; 370 void __iomem *mbase = musb->mregs;
408 u8 reg; 371 u8 reg;
409 372
410 DBG(1, "HNP: stop from %s\n", otg_state_string(musb)); 373 dev_dbg(musb->controller, "HNP: stop from %s\n", otg_state_string(musb->xceiv->state));
411 374
412 switch (musb->xceiv->state) { 375 switch (musb->xceiv->state) {
413 case OTG_STATE_A_PERIPHERAL: 376 case OTG_STATE_A_PERIPHERAL:
414 musb_g_disconnect(musb); 377 musb_g_disconnect(musb);
415 DBG(1, "HNP: back to %s\n", otg_state_string(musb)); 378 dev_dbg(musb->controller, "HNP: back to %s\n",
379 otg_state_string(musb->xceiv->state));
416 break; 380 break;
417 case OTG_STATE_B_HOST: 381 case OTG_STATE_B_HOST:
418 DBG(1, "HNP: Disabling HR\n"); 382 dev_dbg(musb->controller, "HNP: Disabling HR\n");
419 hcd->self.is_b_host = 0; 383 hcd->self.is_b_host = 0;
420 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 384 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
421 MUSB_DEV_MODE(musb); 385 MUSB_DEV_MODE(musb);
@@ -425,8 +389,8 @@ void musb_hnp_stop(struct musb *musb)
425 /* REVISIT: Start SESSION_REQUEST here? */ 389 /* REVISIT: Start SESSION_REQUEST here? */
426 break; 390 break;
427 default: 391 default:
428 DBG(1, "HNP: Stopping in unknown state %s\n", 392 dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n",
429 otg_state_string(musb)); 393 otg_state_string(musb->xceiv->state));
430 } 394 }
431 395
432 /* 396 /*
@@ -456,7 +420,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
456{ 420{
457 irqreturn_t handled = IRQ_NONE; 421 irqreturn_t handled = IRQ_NONE;
458 422
459 DBG(3, "<== Power=%02x, DevCtl=%02x, int_usb=0x%x\n", power, devctl, 423 dev_dbg(musb->controller, "<== Power=%02x, DevCtl=%02x, int_usb=0x%x\n", power, devctl,
460 int_usb); 424 int_usb);
461 425
462 /* in host mode, the peripheral may issue remote wakeup. 426 /* in host mode, the peripheral may issue remote wakeup.
@@ -465,7 +429,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
465 */ 429 */
466 if (int_usb & MUSB_INTR_RESUME) { 430 if (int_usb & MUSB_INTR_RESUME) {
467 handled = IRQ_HANDLED; 431 handled = IRQ_HANDLED;
468 DBG(3, "RESUME (%s)\n", otg_state_string(musb)); 432 dev_dbg(musb->controller, "RESUME (%s)\n", otg_state_string(musb->xceiv->state));
469 433
470 if (devctl & MUSB_DEVCTL_HM) { 434 if (devctl & MUSB_DEVCTL_HM) {
471#ifdef CONFIG_USB_MUSB_HDRC_HCD 435#ifdef CONFIG_USB_MUSB_HDRC_HCD
@@ -480,7 +444,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
480 if (power & MUSB_POWER_SUSPENDM) { 444 if (power & MUSB_POWER_SUSPENDM) {
481 /* spurious */ 445 /* spurious */
482 musb->int_usb &= ~MUSB_INTR_SUSPEND; 446 musb->int_usb &= ~MUSB_INTR_SUSPEND;
483 DBG(2, "Spurious SUSPENDM\n"); 447 dev_dbg(musb->controller, "Spurious SUSPENDM\n");
484 break; 448 break;
485 } 449 }
486 450
@@ -506,7 +470,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
506 default: 470 default:
507 WARNING("bogus %s RESUME (%s)\n", 471 WARNING("bogus %s RESUME (%s)\n",
508 "host", 472 "host",
509 otg_state_string(musb)); 473 otg_state_string(musb->xceiv->state));
510 } 474 }
511#endif 475#endif
512 } else { 476 } else {
@@ -540,7 +504,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
540 default: 504 default:
541 WARNING("bogus %s RESUME (%s)\n", 505 WARNING("bogus %s RESUME (%s)\n",
542 "peripheral", 506 "peripheral",
543 otg_state_string(musb)); 507 otg_state_string(musb->xceiv->state));
544 } 508 }
545 } 509 }
546 } 510 }
@@ -550,7 +514,14 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
550 if (int_usb & MUSB_INTR_SESSREQ) { 514 if (int_usb & MUSB_INTR_SESSREQ) {
551 void __iomem *mbase = musb->mregs; 515 void __iomem *mbase = musb->mregs;
552 516
553 DBG(1, "SESSION_REQUEST (%s)\n", otg_state_string(musb)); 517 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS
518 && (devctl & MUSB_DEVCTL_BDEVICE)) {
519 dev_dbg(musb->controller, "SessReq while on B state\n");
520 return IRQ_HANDLED;
521 }
522
523 dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n",
524 otg_state_string(musb->xceiv->state));
554 525
555 /* IRQ arrives from ID pin sense or (later, if VBUS power 526 /* IRQ arrives from ID pin sense or (later, if VBUS power
556 * is removed) SRP. responses are time critical: 527 * is removed) SRP. responses are time critical:
@@ -563,7 +534,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
563 musb->ep0_stage = MUSB_EP0_START; 534 musb->ep0_stage = MUSB_EP0_START;
564 musb->xceiv->state = OTG_STATE_A_IDLE; 535 musb->xceiv->state = OTG_STATE_A_IDLE;
565 MUSB_HST_MODE(musb); 536 MUSB_HST_MODE(musb);
566 musb_set_vbus(musb, 1); 537 musb_platform_set_vbus(musb, 1);
567 538
568 handled = IRQ_HANDLED; 539 handled = IRQ_HANDLED;
569 } 540 }
@@ -614,8 +585,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
614 break; 585 break;
615 } 586 }
616 587
617 DBG(1, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n", 588 dev_dbg(musb->controller, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
618 otg_state_string(musb), 589 otg_state_string(musb->xceiv->state),
619 devctl, 590 devctl,
620 ({ char *s; 591 ({ char *s;
621 switch (devctl & MUSB_DEVCTL_VBUS) { 592 switch (devctl & MUSB_DEVCTL_VBUS) {
@@ -634,14 +605,14 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
634 605
635 /* go through A_WAIT_VFALL then start a new session */ 606 /* go through A_WAIT_VFALL then start a new session */
636 if (!ignore) 607 if (!ignore)
637 musb_set_vbus(musb, 0); 608 musb_platform_set_vbus(musb, 0);
638 handled = IRQ_HANDLED; 609 handled = IRQ_HANDLED;
639 } 610 }
640 611
641#endif 612#endif
642 if (int_usb & MUSB_INTR_SUSPEND) { 613 if (int_usb & MUSB_INTR_SUSPEND) {
643 DBG(1, "SUSPEND (%s) devctl %02x power %02x\n", 614 dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x power %02x\n",
644 otg_state_string(musb), devctl, power); 615 otg_state_string(musb->xceiv->state), devctl, power);
645 handled = IRQ_HANDLED; 616 handled = IRQ_HANDLED;
646 617
647 switch (musb->xceiv->state) { 618 switch (musb->xceiv->state) {
@@ -673,7 +644,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
673 if (musb->is_active) { 644 if (musb->is_active) {
674#ifdef CONFIG_USB_MUSB_OTG 645#ifdef CONFIG_USB_MUSB_OTG
675 musb->xceiv->state = OTG_STATE_B_WAIT_ACON; 646 musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
676 DBG(1, "HNP: Setting timer for b_ase0_brst\n"); 647 dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n");
677 mod_timer(&musb->otg_timer, jiffies 648 mod_timer(&musb->otg_timer, jiffies
678 + msecs_to_jiffies( 649 + msecs_to_jiffies(
679 OTG_TIME_B_ASE0_BRST)); 650 OTG_TIME_B_ASE0_BRST));
@@ -692,7 +663,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
692 break; 663 break;
693 case OTG_STATE_B_HOST: 664 case OTG_STATE_B_HOST:
694 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */ 665 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
695 DBG(1, "REVISIT: SUSPEND as B_HOST\n"); 666 dev_dbg(musb->controller, "REVISIT: SUSPEND as B_HOST\n");
696 break; 667 break;
697 default: 668 default:
698 /* "should not happen" */ 669 /* "should not happen" */
@@ -735,14 +706,14 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
735 switch (musb->xceiv->state) { 706 switch (musb->xceiv->state) {
736 case OTG_STATE_B_PERIPHERAL: 707 case OTG_STATE_B_PERIPHERAL:
737 if (int_usb & MUSB_INTR_SUSPEND) { 708 if (int_usb & MUSB_INTR_SUSPEND) {
738 DBG(1, "HNP: SUSPEND+CONNECT, now b_host\n"); 709 dev_dbg(musb->controller, "HNP: SUSPEND+CONNECT, now b_host\n");
739 int_usb &= ~MUSB_INTR_SUSPEND; 710 int_usb &= ~MUSB_INTR_SUSPEND;
740 goto b_host; 711 goto b_host;
741 } else 712 } else
742 DBG(1, "CONNECT as b_peripheral???\n"); 713 dev_dbg(musb->controller, "CONNECT as b_peripheral???\n");
743 break; 714 break;
744 case OTG_STATE_B_WAIT_ACON: 715 case OTG_STATE_B_WAIT_ACON:
745 DBG(1, "HNP: CONNECT, now b_host\n"); 716 dev_dbg(musb->controller, "HNP: CONNECT, now b_host\n");
746b_host: 717b_host:
747 musb->xceiv->state = OTG_STATE_B_HOST; 718 musb->xceiv->state = OTG_STATE_B_HOST;
748 hcd->self.is_b_host = 1; 719 hcd->self.is_b_host = 1;
@@ -765,14 +736,14 @@ b_host:
765 else 736 else
766 usb_hcd_resume_root_hub(hcd); 737 usb_hcd_resume_root_hub(hcd);
767 738
768 DBG(1, "CONNECT (%s) devctl %02x\n", 739 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n",
769 otg_state_string(musb), devctl); 740 otg_state_string(musb->xceiv->state), devctl);
770 } 741 }
771#endif /* CONFIG_USB_MUSB_HDRC_HCD */ 742#endif /* CONFIG_USB_MUSB_HDRC_HCD */
772 743
773 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { 744 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) {
774 DBG(1, "DISCONNECT (%s) as %s, devctl %02x\n", 745 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n",
775 otg_state_string(musb), 746 otg_state_string(musb->xceiv->state),
776 MUSB_MODE(musb), devctl); 747 MUSB_MODE(musb), devctl);
777 handled = IRQ_HANDLED; 748 handled = IRQ_HANDLED;
778 749
@@ -815,7 +786,7 @@ b_host:
815#endif /* GADGET */ 786#endif /* GADGET */
816 default: 787 default:
817 WARNING("unhandled DISCONNECT transition (%s)\n", 788 WARNING("unhandled DISCONNECT transition (%s)\n",
818 otg_state_string(musb)); 789 otg_state_string(musb->xceiv->state));
819 break; 790 break;
820 } 791 }
821 } 792 }
@@ -834,13 +805,14 @@ b_host:
834 * stop the session. 805 * stop the session.
835 */ 806 */
836 if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV)) 807 if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV))
837 DBG(1, "BABBLE devctl: %02x\n", devctl); 808 dev_dbg(musb->controller, "BABBLE devctl: %02x\n", devctl);
838 else { 809 else {
839 ERR("Stopping host session -- babble\n"); 810 ERR("Stopping host session -- babble\n");
840 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 811 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
841 } 812 }
842 } else if (is_peripheral_capable()) { 813 } else if (is_peripheral_capable()) {
843 DBG(1, "BUS RESET as %s\n", otg_state_string(musb)); 814 dev_dbg(musb->controller, "BUS RESET as %s\n",
815 otg_state_string(musb->xceiv->state));
844 switch (musb->xceiv->state) { 816 switch (musb->xceiv->state) {
845#ifdef CONFIG_USB_OTG 817#ifdef CONFIG_USB_OTG
846 case OTG_STATE_A_SUSPEND: 818 case OTG_STATE_A_SUSPEND:
@@ -853,9 +825,9 @@ b_host:
853 /* FALLTHROUGH */ 825 /* FALLTHROUGH */
854 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ 826 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
855 /* never use invalid T(a_wait_bcon) */ 827 /* never use invalid T(a_wait_bcon) */
856 DBG(1, "HNP: in %s, %d msec timeout\n", 828 dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n",
857 otg_state_string(musb), 829 otg_state_string(musb->xceiv->state),
858 TA_WAIT_BCON(musb)); 830 TA_WAIT_BCON(musb));
859 mod_timer(&musb->otg_timer, jiffies 831 mod_timer(&musb->otg_timer, jiffies
860 + msecs_to_jiffies(TA_WAIT_BCON(musb))); 832 + msecs_to_jiffies(TA_WAIT_BCON(musb)));
861 break; 833 break;
@@ -865,8 +837,8 @@ b_host:
865 musb_g_reset(musb); 837 musb_g_reset(musb);
866 break; 838 break;
867 case OTG_STATE_B_WAIT_ACON: 839 case OTG_STATE_B_WAIT_ACON:
868 DBG(1, "HNP: RESET (%s), to b_peripheral\n", 840 dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n",
869 otg_state_string(musb)); 841 otg_state_string(musb->xceiv->state));
870 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 842 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
871 musb_g_reset(musb); 843 musb_g_reset(musb);
872 break; 844 break;
@@ -878,8 +850,8 @@ b_host:
878 musb_g_reset(musb); 850 musb_g_reset(musb);
879 break; 851 break;
880 default: 852 default:
881 DBG(1, "Unhandled BUS RESET as %s\n", 853 dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n",
882 otg_state_string(musb)); 854 otg_state_string(musb->xceiv->state));
883 } 855 }
884 } 856 }
885 } 857 }
@@ -902,7 +874,7 @@ b_host:
902 u8 epnum; 874 u8 epnum;
903 u16 frame; 875 u16 frame;
904 876
905 DBG(6, "START_OF_FRAME\n"); 877 dev_dbg(musb->controller, "START_OF_FRAME\n");
906 handled = IRQ_HANDLED; 878 handled = IRQ_HANDLED;
907 879
908 /* start any periodic Tx transfers waiting for current frame */ 880 /* start any periodic Tx transfers waiting for current frame */
@@ -944,7 +916,7 @@ void musb_start(struct musb *musb)
944 void __iomem *regs = musb->mregs; 916 void __iomem *regs = musb->mregs;
945 u8 devctl = musb_readb(regs, MUSB_DEVCTL); 917 u8 devctl = musb_readb(regs, MUSB_DEVCTL);
946 918
947 DBG(2, "<== devctl %02x\n", devctl); 919 dev_dbg(musb->controller, "<== devctl %02x\n", devctl);
948 920
949 /* Set INT enable registers, enable interrupts */ 921 /* Set INT enable registers, enable interrupts */
950 musb_writew(regs, MUSB_INTRTXE, musb->epmask); 922 musb_writew(regs, MUSB_INTRTXE, musb->epmask);
@@ -1021,7 +993,7 @@ void musb_stop(struct musb *musb)
1021 /* stop IRQs, timers, ... */ 993 /* stop IRQs, timers, ... */
1022 musb_platform_disable(musb); 994 musb_platform_disable(musb);
1023 musb_generic_disable(musb); 995 musb_generic_disable(musb);
1024 DBG(3, "HDRC disabled\n"); 996 dev_dbg(musb->controller, "HDRC disabled\n");
1025 997
1026 /* FIXME 998 /* FIXME
1027 * - mark host and/or peripheral drivers unusable/inactive 999 * - mark host and/or peripheral drivers unusable/inactive
@@ -1038,13 +1010,18 @@ static void musb_shutdown(struct platform_device *pdev)
1038 struct musb *musb = dev_to_musb(&pdev->dev); 1010 struct musb *musb = dev_to_musb(&pdev->dev);
1039 unsigned long flags; 1011 unsigned long flags;
1040 1012
1013 pm_runtime_get_sync(musb->controller);
1041 spin_lock_irqsave(&musb->lock, flags); 1014 spin_lock_irqsave(&musb->lock, flags);
1042 musb_platform_disable(musb); 1015 musb_platform_disable(musb);
1043 musb_generic_disable(musb); 1016 musb_generic_disable(musb);
1044 if (musb->clock)
1045 clk_put(musb->clock);
1046 spin_unlock_irqrestore(&musb->lock, flags); 1017 spin_unlock_irqrestore(&musb->lock, flags);
1047 1018
1019 if (!is_otg_enabled(musb) && is_host_enabled(musb))
1020 usb_remove_hcd(musb_to_hcd(musb));
1021 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
1022 musb_platform_exit(musb);
1023
1024 pm_runtime_put(musb->controller);
1048 /* FIXME power down */ 1025 /* FIXME power down */
1049} 1026}
1050 1027
@@ -1061,10 +1038,11 @@ static void musb_shutdown(struct platform_device *pdev)
1061 * We don't currently use dynamic fifo setup capability to do anything 1038 * We don't currently use dynamic fifo setup capability to do anything
1062 * more than selecting one of a bunch of predefined configurations. 1039 * more than selecting one of a bunch of predefined configurations.
1063 */ 1040 */
1064#if defined(CONFIG_USB_TUSB6010) || \ 1041#if defined(CONFIG_USB_MUSB_TUSB6010) || defined(CONFIG_USB_MUSB_OMAP2PLUS) \
1065 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) \ 1042 || defined(CONFIG_USB_MUSB_AM35X)
1066 || defined(CONFIG_ARCH_OMAP4)
1067static ushort __initdata fifo_mode = 4; 1043static ushort __initdata fifo_mode = 4;
1044#elif defined(CONFIG_USB_MUSB_UX500)
1045static ushort __initdata fifo_mode = 5;
1068#else 1046#else
1069static ushort __initdata fifo_mode = 2; 1047static ushort __initdata fifo_mode = 2;
1070#endif 1048#endif
@@ -1361,7 +1339,7 @@ static int __init ep_config_from_hw(struct musb *musb)
1361 void *mbase = musb->mregs; 1339 void *mbase = musb->mregs;
1362 int ret = 0; 1340 int ret = 0;
1363 1341
1364 DBG(2, "<== static silicon ep config\n"); 1342 dev_dbg(musb->controller, "<== static silicon ep config\n");
1365 1343
1366 /* FIXME pick up ep0 maxpacket size */ 1344 /* FIXME pick up ep0 maxpacket size */
1367 1345
@@ -1488,7 +1466,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1488 struct musb_hw_ep *hw_ep = musb->endpoints + i; 1466 struct musb_hw_ep *hw_ep = musb->endpoints + i;
1489 1467
1490 hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase; 1468 hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
1491#ifdef CONFIG_USB_TUSB6010 1469#ifdef CONFIG_USB_MUSB_TUSB6010
1492 hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i); 1470 hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i);
1493 hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i); 1471 hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i);
1494 hw_ep->fifo_sync_va = 1472 hw_ep->fifo_sync_va =
@@ -1508,7 +1486,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1508#endif 1486#endif
1509 1487
1510 if (hw_ep->max_packet_sz_tx) { 1488 if (hw_ep->max_packet_sz_tx) {
1511 DBG(1, 1489 dev_dbg(musb->controller,
1512 "%s: hw_ep %d%s, %smax %d\n", 1490 "%s: hw_ep %d%s, %smax %d\n",
1513 musb_driver_name, i, 1491 musb_driver_name, i,
1514 hw_ep->is_shared_fifo ? "shared" : "tx", 1492 hw_ep->is_shared_fifo ? "shared" : "tx",
@@ -1517,7 +1495,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1517 hw_ep->max_packet_sz_tx); 1495 hw_ep->max_packet_sz_tx);
1518 } 1496 }
1519 if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) { 1497 if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) {
1520 DBG(1, 1498 dev_dbg(musb->controller,
1521 "%s: hw_ep %d%s, %smax %d\n", 1499 "%s: hw_ep %d%s, %smax %d\n",
1522 musb_driver_name, i, 1500 musb_driver_name, i,
1523 "rx", 1501 "rx",
@@ -1526,7 +1504,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1526 hw_ep->max_packet_sz_rx); 1504 hw_ep->max_packet_sz_rx);
1527 } 1505 }
1528 if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx)) 1506 if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx))
1529 DBG(1, "hw_ep %d not configured\n", i); 1507 dev_dbg(musb->controller, "hw_ep %d not configured\n", i);
1530 } 1508 }
1531 1509
1532 return 0; 1510 return 0;
@@ -1534,8 +1512,9 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1534 1512
1535/*-------------------------------------------------------------------------*/ 1513/*-------------------------------------------------------------------------*/
1536 1514
1537#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) || \ 1515#if defined(CONFIG_SOC_OMAP2430) || defined(CONFIG_SOC_OMAP3430) || \
1538 defined(CONFIG_ARCH_OMAP4) 1516 defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_ARCH_U8500) || \
1517 defined(CONFIG_ARCH_U5500)
1539 1518
1540static irqreturn_t generic_interrupt(int irq, void *__hci) 1519static irqreturn_t generic_interrupt(int irq, void *__hci)
1541{ 1520{
@@ -1578,14 +1557,14 @@ irqreturn_t musb_interrupt(struct musb *musb)
1578 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 1557 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
1579 power = musb_readb(musb->mregs, MUSB_POWER); 1558 power = musb_readb(musb->mregs, MUSB_POWER);
1580 1559
1581 DBG(4, "** IRQ %s usb%04x tx%04x rx%04x\n", 1560 dev_dbg(musb->controller, "** IRQ %s usb%04x tx%04x rx%04x\n",
1582 (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral", 1561 (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
1583 musb->int_usb, musb->int_tx, musb->int_rx); 1562 musb->int_usb, musb->int_tx, musb->int_rx);
1584 1563
1585#ifdef CONFIG_USB_GADGET_MUSB_HDRC 1564#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1586 if (is_otg_enabled(musb) || is_peripheral_enabled(musb)) 1565 if (is_otg_enabled(musb) || is_peripheral_enabled(musb))
1587 if (!musb->gadget_driver) { 1566 if (!musb->gadget_driver) {
1588 DBG(5, "No gadget driver loaded\n"); 1567 dev_dbg(musb->controller, "No gadget driver loaded\n");
1589 return IRQ_HANDLED; 1568 return IRQ_HANDLED;
1590 } 1569 }
1591#endif 1570#endif
@@ -1650,7 +1629,7 @@ irqreturn_t musb_interrupt(struct musb *musb)
1650 1629
1651 return retval; 1630 return retval;
1652} 1631}
1653 1632EXPORT_SYMBOL_GPL(musb_interrupt);
1654 1633
1655#ifndef CONFIG_MUSB_PIO_ONLY 1634#ifndef CONFIG_MUSB_PIO_ONLY
1656static int __initdata use_dma = 1; 1635static int __initdata use_dma = 1;
@@ -1714,7 +1693,7 @@ musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1714 int ret = -EINVAL; 1693 int ret = -EINVAL;
1715 1694
1716 spin_lock_irqsave(&musb->lock, flags); 1695 spin_lock_irqsave(&musb->lock, flags);
1717 ret = sprintf(buf, "%s\n", otg_state_string(musb)); 1696 ret = sprintf(buf, "%s\n", otg_state_string(musb->xceiv->state));
1718 spin_unlock_irqrestore(&musb->lock, flags); 1697 spin_unlock_irqrestore(&musb->lock, flags);
1719 1698
1720 return ret; 1699 return ret;
@@ -1867,6 +1846,7 @@ allocate_instance(struct device *dev,
1867 INIT_LIST_HEAD(&musb->out_bulk); 1846 INIT_LIST_HEAD(&musb->out_bulk);
1868 1847
1869 hcd->uses_new_polling = 1; 1848 hcd->uses_new_polling = 1;
1849 hcd->has_tt = 1;
1870 1850
1871 musb->vbuserr_retry = VBUSERR_RETRY_COUNT; 1851 musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
1872 musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON; 1852 musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON;
@@ -1874,10 +1854,9 @@ allocate_instance(struct device *dev,
1874 musb = kzalloc(sizeof *musb, GFP_KERNEL); 1854 musb = kzalloc(sizeof *musb, GFP_KERNEL);
1875 if (!musb) 1855 if (!musb)
1876 return NULL; 1856 return NULL;
1877 dev_set_drvdata(dev, musb);
1878 1857
1879#endif 1858#endif
1880 1859 dev_set_drvdata(dev, musb);
1881 musb->mregs = mbase; 1860 musb->mregs = mbase;
1882 musb->ctrl_base = mbase; 1861 musb->ctrl_base = mbase;
1883 musb->nIrq = -ENODEV; 1862 musb->nIrq = -ENODEV;
@@ -1891,6 +1870,7 @@ allocate_instance(struct device *dev,
1891 } 1870 }
1892 1871
1893 musb->controller = dev; 1872 musb->controller = dev;
1873
1894 return musb; 1874 return musb;
1895} 1875}
1896 1876
@@ -1921,10 +1901,6 @@ static void musb_free(struct musb *musb)
1921 dma_controller_destroy(c); 1901 dma_controller_destroy(c);
1922 } 1902 }
1923 1903
1924#ifdef CONFIG_USB_MUSB_OTG
1925 put_device(musb->xceiv->dev);
1926#endif
1927
1928#ifdef CONFIG_USB_MUSB_HDRC_HCD 1904#ifdef CONFIG_USB_MUSB_HDRC_HCD
1929 usb_put_hcd(musb_to_hcd(musb)); 1905 usb_put_hcd(musb_to_hcd(musb));
1930#else 1906#else
@@ -1956,31 +1932,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1956 goto fail0; 1932 goto fail0;
1957 } 1933 }
1958 1934
1959 switch (plat->mode) {
1960 case MUSB_HOST:
1961#ifdef CONFIG_USB_MUSB_HDRC_HCD
1962 break;
1963#else
1964 goto bad_config;
1965#endif
1966 case MUSB_PERIPHERAL:
1967#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1968 break;
1969#else
1970 goto bad_config;
1971#endif
1972 case MUSB_OTG:
1973#ifdef CONFIG_USB_MUSB_OTG
1974 break;
1975#else
1976bad_config:
1977#endif
1978 default:
1979 dev_err(dev, "incompatible Kconfig role setting\n");
1980 status = -EINVAL;
1981 goto fail0;
1982 }
1983
1984 /* allocate */ 1935 /* allocate */
1985 musb = allocate_instance(dev, plat->config, ctrl); 1936 musb = allocate_instance(dev, plat->config, ctrl);
1986 if (!musb) { 1937 if (!musb) {
@@ -1988,33 +1939,21 @@ bad_config:
1988 goto fail0; 1939 goto fail0;
1989 } 1940 }
1990 1941
1942 pm_runtime_use_autosuspend(musb->controller);
1943 pm_runtime_set_autosuspend_delay(musb->controller, 200);
1944 pm_runtime_enable(musb->controller);
1945
1991 spin_lock_init(&musb->lock); 1946 spin_lock_init(&musb->lock);
1992 musb->board_mode = plat->mode; 1947 musb->board_mode = plat->mode;
1993 musb->board_set_power = plat->set_power; 1948 musb->board_set_power = plat->set_power;
1994 musb->set_clock = plat->set_clock;
1995 musb->min_power = plat->min_power; 1949 musb->min_power = plat->min_power;
1996 1950 musb->ops = plat->platform_ops;
1997 /* Clock usage is chip-specific ... functional clock (DaVinci,
1998 * OMAP2430), or PHY ref (some TUSB6010 boards). All this core
1999 * code does is make sure a clock handle is available; platform
2000 * code manages it during start/stop and suspend/resume.
2001 */
2002 if (plat->clock) {
2003 musb->clock = clk_get(dev, plat->clock);
2004 if (IS_ERR(musb->clock)) {
2005 status = PTR_ERR(musb->clock);
2006 musb->clock = NULL;
2007 goto fail1;
2008 }
2009 }
2010 1951
2011 /* The musb_platform_init() call: 1952 /* The musb_platform_init() call:
2012 * - adjusts musb->mregs and musb->isr if needed, 1953 * - adjusts musb->mregs and musb->isr if needed,
2013 * - may initialize an integrated tranceiver 1954 * - may initialize an integrated tranceiver
2014 * - initializes musb->xceiv, usually by otg_get_transceiver() 1955 * - initializes musb->xceiv, usually by otg_get_transceiver()
2015 * - activates clocks.
2016 * - stops powering VBUS 1956 * - stops powering VBUS
2017 * - assigns musb->board_set_vbus if host mode is enabled
2018 * 1957 *
2019 * There are various transciever configurations. Blackfin, 1958 * There are various transciever configurations. Blackfin,
2020 * DaVinci, TUSB60x0, and others integrate them. OMAP3 uses 1959 * DaVinci, TUSB60x0, and others integrate them. OMAP3 uses
@@ -2022,9 +1961,9 @@ bad_config:
2022 * isp1504, non-OTG, etc) mostly hooking up through ULPI. 1961 * isp1504, non-OTG, etc) mostly hooking up through ULPI.
2023 */ 1962 */
2024 musb->isr = generic_interrupt; 1963 musb->isr = generic_interrupt;
2025 status = musb_platform_init(musb, plat->board_data); 1964 status = musb_platform_init(musb);
2026 if (status < 0) 1965 if (status < 0)
2027 goto fail2; 1966 goto fail1;
2028 1967
2029 if (!musb->isr) { 1968 if (!musb->isr) {
2030 status = -ENODEV; 1969 status = -ENODEV;
@@ -2107,13 +2046,16 @@ bad_config:
2107 * Otherwise, wait till the gadget driver hooks up. 2046 * Otherwise, wait till the gadget driver hooks up.
2108 */ 2047 */
2109 if (!is_otg_enabled(musb) && is_host_enabled(musb)) { 2048 if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
2049 struct usb_hcd *hcd = musb_to_hcd(musb);
2050
2110 MUSB_HST_MODE(musb); 2051 MUSB_HST_MODE(musb);
2111 musb->xceiv->default_a = 1; 2052 musb->xceiv->default_a = 1;
2112 musb->xceiv->state = OTG_STATE_A_IDLE; 2053 musb->xceiv->state = OTG_STATE_A_IDLE;
2113 2054
2114 status = usb_add_hcd(musb_to_hcd(musb), -1, 0); 2055 status = usb_add_hcd(musb_to_hcd(musb), -1, 0);
2115 2056
2116 DBG(1, "%s mode, status %d, devctl %02x %c\n", 2057 hcd->self.uses_pio_for_control = 1;
2058 dev_dbg(musb->controller, "%s mode, status %d, devctl %02x %c\n",
2117 "HOST", status, 2059 "HOST", status,
2118 musb_readb(musb->mregs, MUSB_DEVCTL), 2060 musb_readb(musb->mregs, MUSB_DEVCTL),
2119 (musb_readb(musb->mregs, MUSB_DEVCTL) 2061 (musb_readb(musb->mregs, MUSB_DEVCTL)
@@ -2127,7 +2069,7 @@ bad_config:
2127 2069
2128 status = musb_gadget_setup(musb); 2070 status = musb_gadget_setup(musb);
2129 2071
2130 DBG(1, "%s mode, status %d, dev%02x\n", 2072 dev_dbg(musb->controller, "%s mode, status %d, dev%02x\n",
2131 is_otg_enabled(musb) ? "OTG" : "PERIPHERAL", 2073 is_otg_enabled(musb) ? "OTG" : "PERIPHERAL",
2132 status, 2074 status,
2133 musb_readb(musb->mregs, MUSB_DEVCTL)); 2075 musb_readb(musb->mregs, MUSB_DEVCTL));
@@ -2136,6 +2078,8 @@ bad_config:
2136 if (status < 0) 2078 if (status < 0)
2137 goto fail3; 2079 goto fail3;
2138 2080
2081 pm_runtime_put(musb->controller);
2082
2139 status = musb_init_debugfs(musb); 2083 status = musb_init_debugfs(musb);
2140 if (status < 0) 2084 if (status < 0)
2141 goto fail4; 2085 goto fail4;
@@ -2174,10 +2118,6 @@ fail3:
2174 device_init_wakeup(dev, 0); 2118 device_init_wakeup(dev, 0);
2175 musb_platform_exit(musb); 2119 musb_platform_exit(musb);
2176 2120
2177fail2:
2178 if (musb->clock)
2179 clk_put(musb->clock);
2180
2181fail1: 2121fail1:
2182 dev_err(musb->controller, 2122 dev_err(musb->controller,
2183 "musb_init_controller failed with status %d\n", status); 2123 "musb_init_controller failed with status %d\n", status);
@@ -2203,13 +2143,13 @@ static u64 *orig_dma_mask;
2203static int __init musb_probe(struct platform_device *pdev) 2143static int __init musb_probe(struct platform_device *pdev)
2204{ 2144{
2205 struct device *dev = &pdev->dev; 2145 struct device *dev = &pdev->dev;
2206 int irq = platform_get_irq(pdev, 0); 2146 int irq = platform_get_irq_byname(pdev, "mc");
2207 int status; 2147 int status;
2208 struct resource *iomem; 2148 struct resource *iomem;
2209 void __iomem *base; 2149 void __iomem *base;
2210 2150
2211 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2151 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2212 if (!iomem || irq == 0) 2152 if (!iomem || irq <= 0)
2213 return -ENODEV; 2153 return -ENODEV;
2214 2154
2215 base = ioremap(iomem->start, resource_size(iomem)); 2155 base = ioremap(iomem->start, resource_size(iomem));
@@ -2239,16 +2179,11 @@ static int __exit musb_remove(struct platform_device *pdev)
2239 * - Peripheral mode: peripheral is deactivated (or never-activated) 2179 * - Peripheral mode: peripheral is deactivated (or never-activated)
2240 * - OTG mode: both roles are deactivated (or never-activated) 2180 * - OTG mode: both roles are deactivated (or never-activated)
2241 */ 2181 */
2182 pm_runtime_get_sync(musb->controller);
2242 musb_exit_debugfs(musb); 2183 musb_exit_debugfs(musb);
2243 musb_shutdown(pdev); 2184 musb_shutdown(pdev);
2244#ifdef CONFIG_USB_MUSB_HDRC_HCD
2245 if (musb->board_mode == MUSB_HOST)
2246 usb_remove_hcd(musb_to_hcd(musb));
2247#endif
2248 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
2249 musb_platform_exit(musb);
2250 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
2251 2185
2186 pm_runtime_put(musb->controller);
2252 musb_free(musb); 2187 musb_free(musb);
2253 iounmap(ctrl_base); 2188 iounmap(ctrl_base);
2254 device_init_wakeup(&pdev->dev, 0); 2189 device_init_wakeup(&pdev->dev, 0);
@@ -2260,148 +2195,140 @@ static int __exit musb_remove(struct platform_device *pdev)
2260 2195
2261#ifdef CONFIG_PM 2196#ifdef CONFIG_PM
2262 2197
2263static struct musb_context_registers musb_context; 2198static void musb_save_context(struct musb *musb)
2264
2265void musb_save_context(struct musb *musb)
2266{ 2199{
2267 int i; 2200 int i;
2268 void __iomem *musb_base = musb->mregs; 2201 void __iomem *musb_base = musb->mregs;
2202 void __iomem *epio;
2269 2203
2270 if (is_host_enabled(musb)) { 2204 if (is_host_enabled(musb)) {
2271 musb_context.frame = musb_readw(musb_base, MUSB_FRAME); 2205 musb->context.frame = musb_readw(musb_base, MUSB_FRAME);
2272 musb_context.testmode = musb_readb(musb_base, MUSB_TESTMODE); 2206 musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE);
2273 musb_context.busctl = musb_read_ulpi_buscontrol(musb->mregs); 2207 musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
2274 } 2208 }
2275 musb_context.power = musb_readb(musb_base, MUSB_POWER); 2209 musb->context.power = musb_readb(musb_base, MUSB_POWER);
2276 musb_context.intrtxe = musb_readw(musb_base, MUSB_INTRTXE); 2210 musb->context.intrtxe = musb_readw(musb_base, MUSB_INTRTXE);
2277 musb_context.intrrxe = musb_readw(musb_base, MUSB_INTRRXE); 2211 musb->context.intrrxe = musb_readw(musb_base, MUSB_INTRRXE);
2278 musb_context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE); 2212 musb->context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE);
2279 musb_context.index = musb_readb(musb_base, MUSB_INDEX); 2213 musb->context.index = musb_readb(musb_base, MUSB_INDEX);
2280 musb_context.devctl = musb_readb(musb_base, MUSB_DEVCTL); 2214 musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL);
2281 2215
2282 for (i = 0; i < MUSB_C_NUM_EPS; ++i) { 2216 for (i = 0; i < musb->config->num_eps; ++i) {
2283 musb_writeb(musb_base, MUSB_INDEX, i); 2217 epio = musb->endpoints[i].regs;
2284 musb_context.index_regs[i].txmaxp = 2218 musb->context.index_regs[i].txmaxp =
2285 musb_readw(musb_base, 0x10 + MUSB_TXMAXP); 2219 musb_readw(epio, MUSB_TXMAXP);
2286 musb_context.index_regs[i].txcsr = 2220 musb->context.index_regs[i].txcsr =
2287 musb_readw(musb_base, 0x10 + MUSB_TXCSR); 2221 musb_readw(epio, MUSB_TXCSR);
2288 musb_context.index_regs[i].rxmaxp = 2222 musb->context.index_regs[i].rxmaxp =
2289 musb_readw(musb_base, 0x10 + MUSB_RXMAXP); 2223 musb_readw(epio, MUSB_RXMAXP);
2290 musb_context.index_regs[i].rxcsr = 2224 musb->context.index_regs[i].rxcsr =
2291 musb_readw(musb_base, 0x10 + MUSB_RXCSR); 2225 musb_readw(epio, MUSB_RXCSR);
2292 2226
2293 if (musb->dyn_fifo) { 2227 if (musb->dyn_fifo) {
2294 musb_context.index_regs[i].txfifoadd = 2228 musb->context.index_regs[i].txfifoadd =
2295 musb_read_txfifoadd(musb_base); 2229 musb_read_txfifoadd(musb_base);
2296 musb_context.index_regs[i].rxfifoadd = 2230 musb->context.index_regs[i].rxfifoadd =
2297 musb_read_rxfifoadd(musb_base); 2231 musb_read_rxfifoadd(musb_base);
2298 musb_context.index_regs[i].txfifosz = 2232 musb->context.index_regs[i].txfifosz =
2299 musb_read_txfifosz(musb_base); 2233 musb_read_txfifosz(musb_base);
2300 musb_context.index_regs[i].rxfifosz = 2234 musb->context.index_regs[i].rxfifosz =
2301 musb_read_rxfifosz(musb_base); 2235 musb_read_rxfifosz(musb_base);
2302 } 2236 }
2303 if (is_host_enabled(musb)) { 2237 if (is_host_enabled(musb)) {
2304 musb_context.index_regs[i].txtype = 2238 musb->context.index_regs[i].txtype =
2305 musb_readb(musb_base, 0x10 + MUSB_TXTYPE); 2239 musb_readb(epio, MUSB_TXTYPE);
2306 musb_context.index_regs[i].txinterval = 2240 musb->context.index_regs[i].txinterval =
2307 musb_readb(musb_base, 0x10 + MUSB_TXINTERVAL); 2241 musb_readb(epio, MUSB_TXINTERVAL);
2308 musb_context.index_regs[i].rxtype = 2242 musb->context.index_regs[i].rxtype =
2309 musb_readb(musb_base, 0x10 + MUSB_RXTYPE); 2243 musb_readb(epio, MUSB_RXTYPE);
2310 musb_context.index_regs[i].rxinterval = 2244 musb->context.index_regs[i].rxinterval =
2311 musb_readb(musb_base, 0x10 + MUSB_RXINTERVAL); 2245 musb_readb(epio, MUSB_RXINTERVAL);
2312 2246
2313 musb_context.index_regs[i].txfunaddr = 2247 musb->context.index_regs[i].txfunaddr =
2314 musb_read_txfunaddr(musb_base, i); 2248 musb_read_txfunaddr(musb_base, i);
2315 musb_context.index_regs[i].txhubaddr = 2249 musb->context.index_regs[i].txhubaddr =
2316 musb_read_txhubaddr(musb_base, i); 2250 musb_read_txhubaddr(musb_base, i);
2317 musb_context.index_regs[i].txhubport = 2251 musb->context.index_regs[i].txhubport =
2318 musb_read_txhubport(musb_base, i); 2252 musb_read_txhubport(musb_base, i);
2319 2253
2320 musb_context.index_regs[i].rxfunaddr = 2254 musb->context.index_regs[i].rxfunaddr =
2321 musb_read_rxfunaddr(musb_base, i); 2255 musb_read_rxfunaddr(musb_base, i);
2322 musb_context.index_regs[i].rxhubaddr = 2256 musb->context.index_regs[i].rxhubaddr =
2323 musb_read_rxhubaddr(musb_base, i); 2257 musb_read_rxhubaddr(musb_base, i);
2324 musb_context.index_regs[i].rxhubport = 2258 musb->context.index_regs[i].rxhubport =
2325 musb_read_rxhubport(musb_base, i); 2259 musb_read_rxhubport(musb_base, i);
2326 } 2260 }
2327 } 2261 }
2328
2329 musb_writeb(musb_base, MUSB_INDEX, musb_context.index);
2330
2331 musb_platform_save_context(musb, &musb_context);
2332} 2262}
2333 2263
2334void musb_restore_context(struct musb *musb) 2264static void musb_restore_context(struct musb *musb)
2335{ 2265{
2336 int i; 2266 int i;
2337 void __iomem *musb_base = musb->mregs; 2267 void __iomem *musb_base = musb->mregs;
2338 void __iomem *ep_target_regs; 2268 void __iomem *ep_target_regs;
2339 2269 void __iomem *epio;
2340 musb_platform_restore_context(musb, &musb_context);
2341 2270
2342 if (is_host_enabled(musb)) { 2271 if (is_host_enabled(musb)) {
2343 musb_writew(musb_base, MUSB_FRAME, musb_context.frame); 2272 musb_writew(musb_base, MUSB_FRAME, musb->context.frame);
2344 musb_writeb(musb_base, MUSB_TESTMODE, musb_context.testmode); 2273 musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode);
2345 musb_write_ulpi_buscontrol(musb->mregs, musb_context.busctl); 2274 musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
2346 } 2275 }
2347 musb_writeb(musb_base, MUSB_POWER, musb_context.power); 2276 musb_writeb(musb_base, MUSB_POWER, musb->context.power);
2348 musb_writew(musb_base, MUSB_INTRTXE, musb_context.intrtxe); 2277 musb_writew(musb_base, MUSB_INTRTXE, musb->context.intrtxe);
2349 musb_writew(musb_base, MUSB_INTRRXE, musb_context.intrrxe); 2278 musb_writew(musb_base, MUSB_INTRRXE, musb->context.intrrxe);
2350 musb_writeb(musb_base, MUSB_INTRUSBE, musb_context.intrusbe); 2279 musb_writeb(musb_base, MUSB_INTRUSBE, musb->context.intrusbe);
2351 musb_writeb(musb_base, MUSB_DEVCTL, musb_context.devctl); 2280 musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl);
2352 2281
2353 for (i = 0; i < MUSB_C_NUM_EPS; ++i) { 2282 for (i = 0; i < musb->config->num_eps; ++i) {
2354 musb_writeb(musb_base, MUSB_INDEX, i); 2283 epio = musb->endpoints[i].regs;
2355 musb_writew(musb_base, 0x10 + MUSB_TXMAXP, 2284 musb_writew(epio, MUSB_TXMAXP,
2356 musb_context.index_regs[i].txmaxp); 2285 musb->context.index_regs[i].txmaxp);
2357 musb_writew(musb_base, 0x10 + MUSB_TXCSR, 2286 musb_writew(epio, MUSB_TXCSR,
2358 musb_context.index_regs[i].txcsr); 2287 musb->context.index_regs[i].txcsr);
2359 musb_writew(musb_base, 0x10 + MUSB_RXMAXP, 2288 musb_writew(epio, MUSB_RXMAXP,
2360 musb_context.index_regs[i].rxmaxp); 2289 musb->context.index_regs[i].rxmaxp);
2361 musb_writew(musb_base, 0x10 + MUSB_RXCSR, 2290 musb_writew(epio, MUSB_RXCSR,
2362 musb_context.index_regs[i].rxcsr); 2291 musb->context.index_regs[i].rxcsr);
2363 2292
2364 if (musb->dyn_fifo) { 2293 if (musb->dyn_fifo) {
2365 musb_write_txfifosz(musb_base, 2294 musb_write_txfifosz(musb_base,
2366 musb_context.index_regs[i].txfifosz); 2295 musb->context.index_regs[i].txfifosz);
2367 musb_write_rxfifosz(musb_base, 2296 musb_write_rxfifosz(musb_base,
2368 musb_context.index_regs[i].rxfifosz); 2297 musb->context.index_regs[i].rxfifosz);
2369 musb_write_txfifoadd(musb_base, 2298 musb_write_txfifoadd(musb_base,
2370 musb_context.index_regs[i].txfifoadd); 2299 musb->context.index_regs[i].txfifoadd);
2371 musb_write_rxfifoadd(musb_base, 2300 musb_write_rxfifoadd(musb_base,
2372 musb_context.index_regs[i].rxfifoadd); 2301 musb->context.index_regs[i].rxfifoadd);
2373 } 2302 }
2374 2303
2375 if (is_host_enabled(musb)) { 2304 if (is_host_enabled(musb)) {
2376 musb_writeb(musb_base, 0x10 + MUSB_TXTYPE, 2305 musb_writeb(epio, MUSB_TXTYPE,
2377 musb_context.index_regs[i].txtype); 2306 musb->context.index_regs[i].txtype);
2378 musb_writeb(musb_base, 0x10 + MUSB_TXINTERVAL, 2307 musb_writeb(epio, MUSB_TXINTERVAL,
2379 musb_context.index_regs[i].txinterval); 2308 musb->context.index_regs[i].txinterval);
2380 musb_writeb(musb_base, 0x10 + MUSB_RXTYPE, 2309 musb_writeb(epio, MUSB_RXTYPE,
2381 musb_context.index_regs[i].rxtype); 2310 musb->context.index_regs[i].rxtype);
2382 musb_writeb(musb_base, 0x10 + MUSB_RXINTERVAL, 2311 musb_writeb(epio, MUSB_RXINTERVAL,
2383 2312
2384 musb_context.index_regs[i].rxinterval); 2313 musb->context.index_regs[i].rxinterval);
2385 musb_write_txfunaddr(musb_base, i, 2314 musb_write_txfunaddr(musb_base, i,
2386 musb_context.index_regs[i].txfunaddr); 2315 musb->context.index_regs[i].txfunaddr);
2387 musb_write_txhubaddr(musb_base, i, 2316 musb_write_txhubaddr(musb_base, i,
2388 musb_context.index_regs[i].txhubaddr); 2317 musb->context.index_regs[i].txhubaddr);
2389 musb_write_txhubport(musb_base, i, 2318 musb_write_txhubport(musb_base, i,
2390 musb_context.index_regs[i].txhubport); 2319 musb->context.index_regs[i].txhubport);
2391 2320
2392 ep_target_regs = 2321 ep_target_regs =
2393 musb_read_target_reg_base(i, musb_base); 2322 musb_read_target_reg_base(i, musb_base);
2394 2323
2395 musb_write_rxfunaddr(ep_target_regs, 2324 musb_write_rxfunaddr(ep_target_regs,
2396 musb_context.index_regs[i].rxfunaddr); 2325 musb->context.index_regs[i].rxfunaddr);
2397 musb_write_rxhubaddr(ep_target_regs, 2326 musb_write_rxhubaddr(ep_target_regs,
2398 musb_context.index_regs[i].rxhubaddr); 2327 musb->context.index_regs[i].rxhubaddr);
2399 musb_write_rxhubport(ep_target_regs, 2328 musb_write_rxhubport(ep_target_regs,
2400 musb_context.index_regs[i].rxhubport); 2329 musb->context.index_regs[i].rxhubport);
2401 } 2330 }
2402 } 2331 }
2403
2404 musb_writeb(musb_base, MUSB_INDEX, musb_context.index);
2405} 2332}
2406 2333
2407static int musb_suspend(struct device *dev) 2334static int musb_suspend(struct device *dev)
@@ -2410,9 +2337,6 @@ static int musb_suspend(struct device *dev)
2410 unsigned long flags; 2337 unsigned long flags;
2411 struct musb *musb = dev_to_musb(&pdev->dev); 2338 struct musb *musb = dev_to_musb(&pdev->dev);
2412 2339
2413 if (!musb->clock)
2414 return 0;
2415
2416 spin_lock_irqsave(&musb->lock, flags); 2340 spin_lock_irqsave(&musb->lock, flags);
2417 2341
2418 if (is_peripheral_active(musb)) { 2342 if (is_peripheral_active(musb)) {
@@ -2427,10 +2351,6 @@ static int musb_suspend(struct device *dev)
2427 2351
2428 musb_save_context(musb); 2352 musb_save_context(musb);
2429 2353
2430 if (musb->set_clock)
2431 musb->set_clock(musb->clock, 0);
2432 else
2433 clk_disable(musb->clock);
2434 spin_unlock_irqrestore(&musb->lock, flags); 2354 spin_unlock_irqrestore(&musb->lock, flags);
2435 return 0; 2355 return 0;
2436} 2356}
@@ -2440,14 +2360,6 @@ static int musb_resume_noirq(struct device *dev)
2440 struct platform_device *pdev = to_platform_device(dev); 2360 struct platform_device *pdev = to_platform_device(dev);
2441 struct musb *musb = dev_to_musb(&pdev->dev); 2361 struct musb *musb = dev_to_musb(&pdev->dev);
2442 2362
2443 if (!musb->clock)
2444 return 0;
2445
2446 if (musb->set_clock)
2447 musb->set_clock(musb->clock, 1);
2448 else
2449 clk_enable(musb->clock);
2450
2451 musb_restore_context(musb); 2363 musb_restore_context(musb);
2452 2364
2453 /* for static cmos like DaVinci, register values were preserved 2365 /* for static cmos like DaVinci, register values were preserved
@@ -2457,9 +2369,41 @@ static int musb_resume_noirq(struct device *dev)
2457 return 0; 2369 return 0;
2458} 2370}
2459 2371
2372static int musb_runtime_suspend(struct device *dev)
2373{
2374 struct musb *musb = dev_to_musb(dev);
2375
2376 musb_save_context(musb);
2377
2378 return 0;
2379}
2380
2381static int musb_runtime_resume(struct device *dev)
2382{
2383 struct musb *musb = dev_to_musb(dev);
2384 static int first = 1;
2385
2386 /*
2387 * When pm_runtime_get_sync called for the first time in driver
2388 * init, some of the structure is still not initialized which is
2389 * used in restore function. But clock needs to be
2390 * enabled before any register access, so
2391 * pm_runtime_get_sync has to be called.
2392 * Also context restore without save does not make
2393 * any sense
2394 */
2395 if (!first)
2396 musb_restore_context(musb);
2397 first = 0;
2398
2399 return 0;
2400}
2401
2460static const struct dev_pm_ops musb_dev_pm_ops = { 2402static const struct dev_pm_ops musb_dev_pm_ops = {
2461 .suspend = musb_suspend, 2403 .suspend = musb_suspend,
2462 .resume_noirq = musb_resume_noirq, 2404 .resume_noirq = musb_resume_noirq,
2405 .runtime_suspend = musb_runtime_suspend,
2406 .runtime_resume = musb_runtime_resume,
2463}; 2407};
2464 2408
2465#define MUSB_DEV_PM_OPS (&musb_dev_pm_ops) 2409#define MUSB_DEV_PM_OPS (&musb_dev_pm_ops)
@@ -2496,6 +2440,8 @@ static int __init musb_init(void)
2496 "musb-dma" 2440 "musb-dma"
2497#elif defined(CONFIG_USB_TUSB_OMAP_DMA) 2441#elif defined(CONFIG_USB_TUSB_OMAP_DMA)
2498 "tusb-omap-dma" 2442 "tusb-omap-dma"
2443#elif defined(CONFIG_USB_UX500_DMA)
2444 "ux500-dma"
2499#else 2445#else
2500 "?dma?" 2446 "?dma?"
2501#endif 2447#endif
@@ -2507,8 +2453,8 @@ static int __init musb_init(void)
2507#elif defined(CONFIG_USB_MUSB_HDRC_HCD) 2453#elif defined(CONFIG_USB_MUSB_HDRC_HCD)
2508 "host" 2454 "host"
2509#endif 2455#endif
2510 ", debug=%d\n", 2456 ,
2511 musb_driver_name, musb_debug); 2457 musb_driver_name);
2512 return platform_driver_probe(&musb_driver, musb_probe); 2458 return platform_driver_probe(&musb_driver, musb_probe);
2513} 2459}
2514 2460
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 91d67794e350..0e053b587960 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -212,8 +212,8 @@ enum musb_g_ep0_state {
212 * directly with the "flat" model, or after setting up an index register. 212 * directly with the "flat" model, or after setting up an index register.
213 */ 213 */
214 214
215#if defined(CONFIG_ARCH_DAVINCI) || defined(CONFIG_ARCH_OMAP2430) \ 215#if defined(CONFIG_ARCH_DAVINCI) || defined(CONFIG_SOC_OMAP2430) \
216 || defined(CONFIG_ARCH_OMAP3430) || defined(CONFIG_BLACKFIN) \ 216 || defined(CONFIG_SOC_OMAP3430) || defined(CONFIG_BLACKFIN) \
217 || defined(CONFIG_ARCH_OMAP4) 217 || defined(CONFIG_ARCH_OMAP4)
218/* REVISIT indexed access seemed to 218/* REVISIT indexed access seemed to
219 * misbehave (on DaVinci) for at least peripheral IN ... 219 * misbehave (on DaVinci) for at least peripheral IN ...
@@ -222,7 +222,7 @@ enum musb_g_ep0_state {
222#endif 222#endif
223 223
224/* TUSB mapping: "flat" plus ep0 special cases */ 224/* TUSB mapping: "flat" plus ep0 special cases */
225#if defined(CONFIG_USB_TUSB6010) 225#if defined(CONFIG_USB_MUSB_TUSB6010)
226#define musb_ep_select(_mbase, _epnum) \ 226#define musb_ep_select(_mbase, _epnum) \
227 musb_writeb((_mbase), MUSB_INDEX, (_epnum)) 227 musb_writeb((_mbase), MUSB_INDEX, (_epnum))
228#define MUSB_EP_OFFSET MUSB_TUSB_OFFSET 228#define MUSB_EP_OFFSET MUSB_TUSB_OFFSET
@@ -253,6 +253,34 @@ enum musb_g_ep0_state {
253 253
254/******************************** TYPES *************************************/ 254/******************************** TYPES *************************************/
255 255
256/**
257 * struct musb_platform_ops - Operations passed to musb_core by HW glue layer
258 * @init: turns on clocks, sets up platform-specific registers, etc
259 * @exit: undoes @init
260 * @set_mode: forcefully changes operating mode
261 * @try_ilde: tries to idle the IP
262 * @vbus_status: returns vbus status if possible
263 * @set_vbus: forces vbus status
264 * @channel_program: pre check for standard dma channel_program func
265 */
266struct musb_platform_ops {
267 int (*init)(struct musb *musb);
268 int (*exit)(struct musb *musb);
269
270 void (*enable)(struct musb *musb);
271 void (*disable)(struct musb *musb);
272
273 int (*set_mode)(struct musb *musb, u8 mode);
274 void (*try_idle)(struct musb *musb, unsigned long timeout);
275
276 int (*vbus_status)(struct musb *musb);
277 void (*set_vbus)(struct musb *musb, int on);
278
279 int (*adjust_channel_params)(struct dma_channel *channel,
280 u16 packet_sz, u8 *mode,
281 dma_addr_t *dma_addr, u32 *len);
282};
283
256/* 284/*
257 * struct musb_hw_ep - endpoint hardware (bidirectional) 285 * struct musb_hw_ep - endpoint hardware (bidirectional)
258 * 286 *
@@ -263,7 +291,7 @@ struct musb_hw_ep {
263 void __iomem *fifo; 291 void __iomem *fifo;
264 void __iomem *regs; 292 void __iomem *regs;
265 293
266#ifdef CONFIG_USB_TUSB6010 294#ifdef CONFIG_USB_MUSB_TUSB6010
267 void __iomem *conf; 295 void __iomem *conf;
268#endif 296#endif
269 297
@@ -280,7 +308,7 @@ struct musb_hw_ep {
280 struct dma_channel *tx_channel; 308 struct dma_channel *tx_channel;
281 struct dma_channel *rx_channel; 309 struct dma_channel *rx_channel;
282 310
283#ifdef CONFIG_USB_TUSB6010 311#ifdef CONFIG_USB_MUSB_TUSB6010
284 /* TUSB has "asynchronous" and "synchronous" dma modes */ 312 /* TUSB has "asynchronous" and "synchronous" dma modes */
285 dma_addr_t fifo_async; 313 dma_addr_t fifo_async;
286 dma_addr_t fifo_sync; 314 dma_addr_t fifo_sync;
@@ -305,7 +333,7 @@ struct musb_hw_ep {
305#endif 333#endif
306}; 334};
307 335
308static inline struct usb_request *next_in_request(struct musb_hw_ep *hw_ep) 336static inline struct musb_request *next_in_request(struct musb_hw_ep *hw_ep)
309{ 337{
310#ifdef CONFIG_USB_GADGET_MUSB_HDRC 338#ifdef CONFIG_USB_GADGET_MUSB_HDRC
311 return next_request(&hw_ep->ep_in); 339 return next_request(&hw_ep->ep_in);
@@ -314,7 +342,7 @@ static inline struct usb_request *next_in_request(struct musb_hw_ep *hw_ep)
314#endif 342#endif
315} 343}
316 344
317static inline struct usb_request *next_out_request(struct musb_hw_ep *hw_ep) 345static inline struct musb_request *next_out_request(struct musb_hw_ep *hw_ep)
318{ 346{
319#ifdef CONFIG_USB_GADGET_MUSB_HDRC 347#ifdef CONFIG_USB_GADGET_MUSB_HDRC
320 return next_request(&hw_ep->ep_out); 348 return next_request(&hw_ep->ep_out);
@@ -323,13 +351,39 @@ static inline struct usb_request *next_out_request(struct musb_hw_ep *hw_ep)
323#endif 351#endif
324} 352}
325 353
354struct musb_csr_regs {
355 /* FIFO registers */
356 u16 txmaxp, txcsr, rxmaxp, rxcsr;
357 u16 rxfifoadd, txfifoadd;
358 u8 txtype, txinterval, rxtype, rxinterval;
359 u8 rxfifosz, txfifosz;
360 u8 txfunaddr, txhubaddr, txhubport;
361 u8 rxfunaddr, rxhubaddr, rxhubport;
362};
363
364struct musb_context_registers {
365
366 u8 power;
367 u16 intrtxe, intrrxe;
368 u8 intrusbe;
369 u16 frame;
370 u8 index, testmode;
371
372 u8 devctl, busctl, misc;
373
374 struct musb_csr_regs index_regs[MUSB_C_NUM_EPS];
375};
376
326/* 377/*
327 * struct musb - Driver instance data. 378 * struct musb - Driver instance data.
328 */ 379 */
329struct musb { 380struct musb {
330 /* device lock */ 381 /* device lock */
331 spinlock_t lock; 382 spinlock_t lock;
332 struct clk *clock; 383
384 const struct musb_platform_ops *ops;
385 struct musb_context_registers context;
386
333 irqreturn_t (*isr)(int, void *); 387 irqreturn_t (*isr)(int, void *);
334 struct work_struct irq_work; 388 struct work_struct irq_work;
335 u16 hwvers; 389 u16 hwvers;
@@ -358,11 +412,7 @@ struct musb {
358 412
359 struct timer_list otg_timer; 413 struct timer_list otg_timer;
360#endif 414#endif
361 415 struct notifier_block nb;
362 /* called with IRQs blocked; ON/nonzero implies starting a session,
363 * and waiting at least a_wait_vrise_tmout.
364 */
365 void (*board_set_vbus)(struct musb *, int is_on);
366 416
367 struct dma_controller *dma_controller; 417 struct dma_controller *dma_controller;
368 418
@@ -370,7 +420,7 @@ struct musb {
370 void __iomem *ctrl_base; 420 void __iomem *ctrl_base;
371 void __iomem *mregs; 421 void __iomem *mregs;
372 422
373#ifdef CONFIG_USB_TUSB6010 423#ifdef CONFIG_USB_MUSB_TUSB6010
374 dma_addr_t async; 424 dma_addr_t async;
375 dma_addr_t sync; 425 dma_addr_t sync;
376 void __iomem *sync_va; 426 void __iomem *sync_va;
@@ -397,8 +447,6 @@ struct musb {
397 u8 board_mode; /* enum musb_mode */ 447 u8 board_mode; /* enum musb_mode */
398 int (*board_set_power)(int state); 448 int (*board_set_power)(int state);
399 449
400 int (*set_clock)(struct clk *clk, int is_active);
401
402 u8 min_power; /* vbus for periph, in mA/2 */ 450 u8 min_power; /* vbus for periph, in mA/2 */
403 451
404 bool is_host; 452 bool is_host;
@@ -450,6 +498,19 @@ struct musb {
450 struct usb_gadget_driver *gadget_driver; /* its driver */ 498 struct usb_gadget_driver *gadget_driver; /* its driver */
451#endif 499#endif
452 500
501 /*
502 * FIXME: Remove this flag.
503 *
504 * This is only added to allow Blackfin to work
505 * with current driver. For some unknown reason
506 * Blackfin doesn't work with double buffering
507 * and that's enabled by default.
508 *
509 * We added this flag to forcefully disable double
510 * buffering until we get it working.
511 */
512 unsigned double_buffer_not_ok:1 __deprecated;
513
453 struct musb_hdrc_config *config; 514 struct musb_hdrc_config *config;
454 515
455#ifdef MUSB_CONFIG_PROC_FS 516#ifdef MUSB_CONFIG_PROC_FS
@@ -457,52 +518,6 @@ struct musb {
457#endif 518#endif
458}; 519};
459 520
460#ifdef CONFIG_PM
461struct musb_csr_regs {
462 /* FIFO registers */
463 u16 txmaxp, txcsr, rxmaxp, rxcsr;
464 u16 rxfifoadd, txfifoadd;
465 u8 txtype, txinterval, rxtype, rxinterval;
466 u8 rxfifosz, txfifosz;
467 u8 txfunaddr, txhubaddr, txhubport;
468 u8 rxfunaddr, rxhubaddr, rxhubport;
469};
470
471struct musb_context_registers {
472
473#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \
474 defined(CONFIG_ARCH_OMAP4)
475 u32 otg_sysconfig, otg_forcestandby;
476#endif
477 u8 power;
478 u16 intrtxe, intrrxe;
479 u8 intrusbe;
480 u16 frame;
481 u8 index, testmode;
482
483 u8 devctl, busctl, misc;
484
485 struct musb_csr_regs index_regs[MUSB_C_NUM_EPS];
486};
487
488#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \
489 defined(CONFIG_ARCH_OMAP4)
490extern void musb_platform_save_context(struct musb *musb,
491 struct musb_context_registers *musb_context);
492extern void musb_platform_restore_context(struct musb *musb,
493 struct musb_context_registers *musb_context);
494#else
495#define musb_platform_save_context(m, x) do {} while (0)
496#define musb_platform_restore_context(m, x) do {} while (0)
497#endif
498
499#endif
500
501static inline void musb_set_vbus(struct musb *musb, int is_on)
502{
503 musb->board_set_vbus(musb, is_on);
504}
505
506#ifdef CONFIG_USB_GADGET_MUSB_HDRC 521#ifdef CONFIG_USB_GADGET_MUSB_HDRC
507static inline struct musb *gadget_to_musb(struct usb_gadget *g) 522static inline struct musb *gadget_to_musb(struct usb_gadget *g)
508{ 523{
@@ -591,28 +606,63 @@ extern void musb_load_testpacket(struct musb *);
591 606
592extern irqreturn_t musb_interrupt(struct musb *); 607extern irqreturn_t musb_interrupt(struct musb *);
593 608
594extern void musb_platform_enable(struct musb *musb);
595extern void musb_platform_disable(struct musb *musb);
596
597extern void musb_hnp_stop(struct musb *musb); 609extern void musb_hnp_stop(struct musb *musb);
598 610
599extern int musb_platform_set_mode(struct musb *musb, u8 musb_mode); 611static inline void musb_platform_set_vbus(struct musb *musb, int is_on)
612{
613 if (musb->ops->set_vbus)
614 musb->ops->set_vbus(musb, is_on);
615}
600 616
601#if defined(CONFIG_USB_TUSB6010) || defined(CONFIG_BLACKFIN) || \ 617static inline void musb_platform_enable(struct musb *musb)
602 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \ 618{
603 defined(CONFIG_ARCH_OMAP4) 619 if (musb->ops->enable)
604extern void musb_platform_try_idle(struct musb *musb, unsigned long timeout); 620 musb->ops->enable(musb);
605#else 621}
606#define musb_platform_try_idle(x, y) do {} while (0)
607#endif
608 622
609#if defined(CONFIG_USB_TUSB6010) || defined(CONFIG_BLACKFIN) 623static inline void musb_platform_disable(struct musb *musb)
610extern int musb_platform_get_vbus_status(struct musb *musb); 624{
611#else 625 if (musb->ops->disable)
612#define musb_platform_get_vbus_status(x) 0 626 musb->ops->disable(musb);
613#endif 627}
628
629static inline int musb_platform_set_mode(struct musb *musb, u8 mode)
630{
631 if (!musb->ops->set_mode)
632 return 0;
633
634 return musb->ops->set_mode(musb, mode);
635}
636
637static inline void musb_platform_try_idle(struct musb *musb,
638 unsigned long timeout)
639{
640 if (musb->ops->try_idle)
641 musb->ops->try_idle(musb, timeout);
642}
614 643
615extern int __init musb_platform_init(struct musb *musb, void *board_data); 644static inline int musb_platform_get_vbus_status(struct musb *musb)
616extern int musb_platform_exit(struct musb *musb); 645{
646 if (!musb->ops->vbus_status)
647 return 0;
648
649 return musb->ops->vbus_status(musb);
650}
651
652static inline int musb_platform_init(struct musb *musb)
653{
654 if (!musb->ops->init)
655 return -EINVAL;
656
657 return musb->ops->init(musb);
658}
659
660static inline int musb_platform_exit(struct musb *musb)
661{
662 if (!musb->ops->exit)
663 return -EINVAL;
664
665 return musb->ops->exit(musb);
666}
617 667
618#endif /* __MUSB_CORE_H__ */ 668#endif /* __MUSB_CORE_H__ */
diff --git a/drivers/usb/musb/musb_debug.h b/drivers/usb/musb/musb_debug.h
index d73afdbde3ee..742eada5002e 100644
--- a/drivers/usb/musb/musb_debug.h
+++ b/drivers/usb/musb/musb_debug.h
@@ -42,23 +42,6 @@
42#define INFO(fmt, args...) yprintk(KERN_INFO, fmt, ## args) 42#define INFO(fmt, args...) yprintk(KERN_INFO, fmt, ## args)
43#define ERR(fmt, args...) yprintk(KERN_ERR, fmt, ## args) 43#define ERR(fmt, args...) yprintk(KERN_ERR, fmt, ## args)
44 44
45#define xprintk(level, facility, format, args...) do { \
46 if (_dbg_level(level)) { \
47 printk(facility "%s %d: " format , \
48 __func__, __LINE__ , ## args); \
49 } } while (0)
50
51extern unsigned musb_debug;
52
53static inline int _dbg_level(unsigned l)
54{
55 return musb_debug >= l;
56}
57
58#define DBG(level, fmt, args...) xprintk(level, KERN_DEBUG, fmt, ## args)
59
60extern const char *otg_state_string(struct musb *);
61
62#ifdef CONFIG_DEBUG_FS 45#ifdef CONFIG_DEBUG_FS
63extern int musb_init_debugfs(struct musb *musb); 46extern int musb_init_debugfs(struct musb *musb);
64extern void musb_exit_debugfs(struct musb *musb); 47extern void musb_exit_debugfs(struct musb *musb);
diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
index 9e8639d4e862..b0176e4569e0 100644
--- a/drivers/usb/musb/musb_debugfs.c
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -36,7 +36,6 @@
36#include <linux/sched.h> 36#include <linux/sched.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/list.h> 38#include <linux/list.h>
39#include <linux/kobject.h>
40#include <linux/platform_device.h> 39#include <linux/platform_device.h>
41#include <linux/io.h> 40#include <linux/io.h>
42#include <linux/debugfs.h> 41#include <linux/debugfs.h>
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 916065ba9e70..3a97c4e2d4f5 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -169,6 +169,9 @@ struct dma_controller {
169 dma_addr_t dma_addr, 169 dma_addr_t dma_addr,
170 u32 length); 170 u32 length);
171 int (*channel_abort)(struct dma_channel *); 171 int (*channel_abort)(struct dma_channel *);
172 int (*is_compatible)(struct dma_channel *channel,
173 u16 maxpacket,
174 void *buf, u32 length);
172}; 175};
173 176
174/* called after channel_program(), may indicate a fault */ 177/* called after channel_program(), may indicate a fault */
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index d065e23f123e..6aeb363e63e7 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -92,6 +92,84 @@
92 92
93/* ----------------------------------------------------------------------- */ 93/* ----------------------------------------------------------------------- */
94 94
95#define is_buffer_mapped(req) (is_dma_capable() && \
96 (req->map_state != UN_MAPPED))
97
98/* Maps the buffer to dma */
99
100static inline void map_dma_buffer(struct musb_request *request,
101 struct musb *musb, struct musb_ep *musb_ep)
102{
103 int compatible = true;
104 struct dma_controller *dma = musb->dma_controller;
105
106 request->map_state = UN_MAPPED;
107
108 if (!is_dma_capable() || !musb_ep->dma)
109 return;
110
111 /* Check if DMA engine can handle this request.
112 * DMA code must reject the USB request explicitly.
113 * Default behaviour is to map the request.
114 */
115 if (dma->is_compatible)
116 compatible = dma->is_compatible(musb_ep->dma,
117 musb_ep->packet_sz, request->request.buf,
118 request->request.length);
119 if (!compatible)
120 return;
121
122 if (request->request.dma == DMA_ADDR_INVALID) {
123 request->request.dma = dma_map_single(
124 musb->controller,
125 request->request.buf,
126 request->request.length,
127 request->tx
128 ? DMA_TO_DEVICE
129 : DMA_FROM_DEVICE);
130 request->map_state = MUSB_MAPPED;
131 } else {
132 dma_sync_single_for_device(musb->controller,
133 request->request.dma,
134 request->request.length,
135 request->tx
136 ? DMA_TO_DEVICE
137 : DMA_FROM_DEVICE);
138 request->map_state = PRE_MAPPED;
139 }
140}
141
142/* Unmap the buffer from dma and maps it back to cpu */
143static inline void unmap_dma_buffer(struct musb_request *request,
144 struct musb *musb)
145{
146 if (!is_buffer_mapped(request))
147 return;
148
149 if (request->request.dma == DMA_ADDR_INVALID) {
150 dev_vdbg(musb->controller,
151 "not unmapping a never mapped buffer\n");
152 return;
153 }
154 if (request->map_state == MUSB_MAPPED) {
155 dma_unmap_single(musb->controller,
156 request->request.dma,
157 request->request.length,
158 request->tx
159 ? DMA_TO_DEVICE
160 : DMA_FROM_DEVICE);
161 request->request.dma = DMA_ADDR_INVALID;
162 } else { /* PRE_MAPPED */
163 dma_sync_single_for_cpu(musb->controller,
164 request->request.dma,
165 request->request.length,
166 request->tx
167 ? DMA_TO_DEVICE
168 : DMA_FROM_DEVICE);
169 }
170 request->map_state = UN_MAPPED;
171}
172
95/* 173/*
96 * Immediately complete a request. 174 * Immediately complete a request.
97 * 175 *
@@ -112,37 +190,20 @@ __acquires(ep->musb->lock)
112 190
113 req = to_musb_request(request); 191 req = to_musb_request(request);
114 192
115 list_del(&request->list); 193 list_del(&req->list);
116 if (req->request.status == -EINPROGRESS) 194 if (req->request.status == -EINPROGRESS)
117 req->request.status = status; 195 req->request.status = status;
118 musb = req->musb; 196 musb = req->musb;
119 197
120 ep->busy = 1; 198 ep->busy = 1;
121 spin_unlock(&musb->lock); 199 spin_unlock(&musb->lock);
122 if (is_dma_capable()) { 200 unmap_dma_buffer(req, musb);
123 if (req->mapped) {
124 dma_unmap_single(musb->controller,
125 req->request.dma,
126 req->request.length,
127 req->tx
128 ? DMA_TO_DEVICE
129 : DMA_FROM_DEVICE);
130 req->request.dma = DMA_ADDR_INVALID;
131 req->mapped = 0;
132 } else if (req->request.dma != DMA_ADDR_INVALID)
133 dma_sync_single_for_cpu(musb->controller,
134 req->request.dma,
135 req->request.length,
136 req->tx
137 ? DMA_TO_DEVICE
138 : DMA_FROM_DEVICE);
139 }
140 if (request->status == 0) 201 if (request->status == 0)
141 DBG(5, "%s done request %p, %d/%d\n", 202 dev_dbg(musb->controller, "%s done request %p, %d/%d\n",
142 ep->end_point.name, request, 203 ep->end_point.name, request,
143 req->request.actual, req->request.length); 204 req->request.actual, req->request.length);
144 else 205 else
145 DBG(2, "%s request %p, %d/%d fault %d\n", 206 dev_dbg(musb->controller, "%s request %p, %d/%d fault %d\n",
146 ep->end_point.name, request, 207 ep->end_point.name, request,
147 req->request.actual, req->request.length, 208 req->request.actual, req->request.length,
148 request->status); 209 request->status);
@@ -159,6 +220,7 @@ __acquires(ep->musb->lock)
159 */ 220 */
160static void nuke(struct musb_ep *ep, const int status) 221static void nuke(struct musb_ep *ep, const int status)
161{ 222{
223 struct musb *musb = ep->musb;
162 struct musb_request *req = NULL; 224 struct musb_request *req = NULL;
163 void __iomem *epio = ep->musb->endpoints[ep->current_epnum].regs; 225 void __iomem *epio = ep->musb->endpoints[ep->current_epnum].regs;
164 226
@@ -186,14 +248,14 @@ static void nuke(struct musb_ep *ep, const int status)
186 } 248 }
187 249
188 value = c->channel_abort(ep->dma); 250 value = c->channel_abort(ep->dma);
189 DBG(value ? 1 : 6, "%s: abort DMA --> %d\n", ep->name, value); 251 dev_dbg(musb->controller, "%s: abort DMA --> %d\n",
252 ep->name, value);
190 c->channel_release(ep->dma); 253 c->channel_release(ep->dma);
191 ep->dma = NULL; 254 ep->dma = NULL;
192 } 255 }
193 256
194 while (!list_empty(&(ep->req_list))) { 257 while (!list_empty(&ep->req_list)) {
195 req = container_of(ep->req_list.next, struct musb_request, 258 req = list_first_entry(&ep->req_list, struct musb_request, list);
196 request.list);
197 musb_g_giveback(ep, &req->request, status); 259 musb_g_giveback(ep, &req->request, status);
198 } 260 }
199} 261}
@@ -270,7 +332,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
270 332
271 /* we shouldn't get here while DMA is active ... but we do ... */ 333 /* we shouldn't get here while DMA is active ... but we do ... */
272 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) { 334 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) {
273 DBG(4, "dma pending...\n"); 335 dev_dbg(musb->controller, "dma pending...\n");
274 return; 336 return;
275 } 337 }
276 338
@@ -282,23 +344,23 @@ static void txstate(struct musb *musb, struct musb_request *req)
282 (int)(request->length - request->actual)); 344 (int)(request->length - request->actual));
283 345
284 if (csr & MUSB_TXCSR_TXPKTRDY) { 346 if (csr & MUSB_TXCSR_TXPKTRDY) {
285 DBG(5, "%s old packet still ready , txcsr %03x\n", 347 dev_dbg(musb->controller, "%s old packet still ready , txcsr %03x\n",
286 musb_ep->end_point.name, csr); 348 musb_ep->end_point.name, csr);
287 return; 349 return;
288 } 350 }
289 351
290 if (csr & MUSB_TXCSR_P_SENDSTALL) { 352 if (csr & MUSB_TXCSR_P_SENDSTALL) {
291 DBG(5, "%s stalling, txcsr %03x\n", 353 dev_dbg(musb->controller, "%s stalling, txcsr %03x\n",
292 musb_ep->end_point.name, csr); 354 musb_ep->end_point.name, csr);
293 return; 355 return;
294 } 356 }
295 357
296 DBG(4, "hw_ep%d, maxpacket %d, fifo count %d, txcsr %03x\n", 358 dev_dbg(musb->controller, "hw_ep%d, maxpacket %d, fifo count %d, txcsr %03x\n",
297 epnum, musb_ep->packet_sz, fifo_count, 359 epnum, musb_ep->packet_sz, fifo_count,
298 csr); 360 csr);
299 361
300#ifndef CONFIG_MUSB_PIO_ONLY 362#ifndef CONFIG_MUSB_PIO_ONLY
301 if (is_dma_capable() && musb_ep->dma) { 363 if (is_buffer_mapped(req)) {
302 struct dma_controller *c = musb->dma_controller; 364 struct dma_controller *c = musb->dma_controller;
303 size_t request_size; 365 size_t request_size;
304 366
@@ -310,7 +372,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
310 372
311 /* MUSB_TXCSR_P_ISO is still set correctly */ 373 /* MUSB_TXCSR_P_ISO is still set correctly */
312 374
313#ifdef CONFIG_USB_INVENTRA_DMA 375#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA)
314 { 376 {
315 if (request_size < musb_ep->packet_sz) 377 if (request_size < musb_ep->packet_sz)
316 musb_ep->dma->desired_mode = 0; 378 musb_ep->dma->desired_mode = 0;
@@ -337,13 +399,15 @@ static void txstate(struct musb *musb, struct musb_request *req)
337 csr |= (MUSB_TXCSR_DMAENAB | 399 csr |= (MUSB_TXCSR_DMAENAB |
338 MUSB_TXCSR_MODE); 400 MUSB_TXCSR_MODE);
339 /* against programming guide */ 401 /* against programming guide */
340 } else 402 } else {
341 csr |= (MUSB_TXCSR_AUTOSET 403 csr |= (MUSB_TXCSR_DMAENAB
342 | MUSB_TXCSR_DMAENAB
343 | MUSB_TXCSR_DMAMODE 404 | MUSB_TXCSR_DMAMODE
344 | MUSB_TXCSR_MODE); 405 | MUSB_TXCSR_MODE);
345 406 if (!musb_ep->hb_mult)
407 csr |= MUSB_TXCSR_AUTOSET;
408 }
346 csr &= ~MUSB_TXCSR_P_UNDERRUN; 409 csr &= ~MUSB_TXCSR_P_UNDERRUN;
410
347 musb_writew(epio, MUSB_TXCSR, csr); 411 musb_writew(epio, MUSB_TXCSR, csr);
348 } 412 }
349 } 413 }
@@ -393,6 +457,12 @@ static void txstate(struct musb *musb, struct musb_request *req)
393#endif 457#endif
394 458
395 if (!use_dma) { 459 if (!use_dma) {
460 /*
461 * Unmap the dma buffer back to cpu if dma channel
462 * programming fails
463 */
464 unmap_dma_buffer(req, musb);
465
396 musb_write_fifo(musb_ep->hw_ep, fifo_count, 466 musb_write_fifo(musb_ep->hw_ep, fifo_count,
397 (u8 *) (request->buf + request->actual)); 467 (u8 *) (request->buf + request->actual));
398 request->actual += fifo_count; 468 request->actual += fifo_count;
@@ -402,7 +472,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
402 } 472 }
403 473
404 /* host may already have the data when this message shows... */ 474 /* host may already have the data when this message shows... */
405 DBG(3, "%s TX/IN %s len %d/%d, txcsr %04x, fifo %d/%d\n", 475 dev_dbg(musb->controller, "%s TX/IN %s len %d/%d, txcsr %04x, fifo %d/%d\n",
406 musb_ep->end_point.name, use_dma ? "dma" : "pio", 476 musb_ep->end_point.name, use_dma ? "dma" : "pio",
407 request->actual, request->length, 477 request->actual, request->length,
408 musb_readw(epio, MUSB_TXCSR), 478 musb_readw(epio, MUSB_TXCSR),
@@ -417,6 +487,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
417void musb_g_tx(struct musb *musb, u8 epnum) 487void musb_g_tx(struct musb *musb, u8 epnum)
418{ 488{
419 u16 csr; 489 u16 csr;
490 struct musb_request *req;
420 struct usb_request *request; 491 struct usb_request *request;
421 u8 __iomem *mbase = musb->mregs; 492 u8 __iomem *mbase = musb->mregs;
422 struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_in; 493 struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_in;
@@ -424,10 +495,11 @@ void musb_g_tx(struct musb *musb, u8 epnum)
424 struct dma_channel *dma; 495 struct dma_channel *dma;
425 496
426 musb_ep_select(mbase, epnum); 497 musb_ep_select(mbase, epnum);
427 request = next_request(musb_ep); 498 req = next_request(musb_ep);
499 request = &req->request;
428 500
429 csr = musb_readw(epio, MUSB_TXCSR); 501 csr = musb_readw(epio, MUSB_TXCSR);
430 DBG(4, "<== %s, txcsr %04x\n", musb_ep->end_point.name, csr); 502 dev_dbg(musb->controller, "<== %s, txcsr %04x\n", musb_ep->end_point.name, csr);
431 503
432 dma = is_dma_capable() ? musb_ep->dma : NULL; 504 dma = is_dma_capable() ? musb_ep->dma : NULL;
433 505
@@ -447,7 +519,8 @@ void musb_g_tx(struct musb *musb, u8 epnum)
447 csr |= MUSB_TXCSR_P_WZC_BITS; 519 csr |= MUSB_TXCSR_P_WZC_BITS;
448 csr &= ~(MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY); 520 csr &= ~(MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY);
449 musb_writew(epio, MUSB_TXCSR, csr); 521 musb_writew(epio, MUSB_TXCSR, csr);
450 DBG(20, "underrun on ep%d, req %p\n", epnum, request); 522 dev_vdbg(musb->controller, "underrun on ep%d, req %p\n",
523 epnum, request);
451 } 524 }
452 525
453 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { 526 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
@@ -455,7 +528,7 @@ void musb_g_tx(struct musb *musb, u8 epnum)
455 * SHOULD NOT HAPPEN... has with CPPI though, after 528 * SHOULD NOT HAPPEN... has with CPPI though, after
456 * changing SENDSTALL (and other cases); harmless? 529 * changing SENDSTALL (and other cases); harmless?
457 */ 530 */
458 DBG(5, "%s dma still busy?\n", musb_ep->end_point.name); 531 dev_dbg(musb->controller, "%s dma still busy?\n", musb_ep->end_point.name);
459 return; 532 return;
460 } 533 }
461 534
@@ -466,53 +539,52 @@ void musb_g_tx(struct musb *musb, u8 epnum)
466 is_dma = 1; 539 is_dma = 1;
467 csr |= MUSB_TXCSR_P_WZC_BITS; 540 csr |= MUSB_TXCSR_P_WZC_BITS;
468 csr &= ~(MUSB_TXCSR_DMAENAB | MUSB_TXCSR_P_UNDERRUN | 541 csr &= ~(MUSB_TXCSR_DMAENAB | MUSB_TXCSR_P_UNDERRUN |
469 MUSB_TXCSR_TXPKTRDY); 542 MUSB_TXCSR_TXPKTRDY | MUSB_TXCSR_AUTOSET);
470 musb_writew(epio, MUSB_TXCSR, csr); 543 musb_writew(epio, MUSB_TXCSR, csr);
471 /* Ensure writebuffer is empty. */ 544 /* Ensure writebuffer is empty. */
472 csr = musb_readw(epio, MUSB_TXCSR); 545 csr = musb_readw(epio, MUSB_TXCSR);
473 request->actual += musb_ep->dma->actual_len; 546 request->actual += musb_ep->dma->actual_len;
474 DBG(4, "TXCSR%d %04x, DMA off, len %zu, req %p\n", 547 dev_dbg(musb->controller, "TXCSR%d %04x, DMA off, len %zu, req %p\n",
475 epnum, csr, musb_ep->dma->actual_len, request); 548 epnum, csr, musb_ep->dma->actual_len, request);
476 } 549 }
477 550
478 if (is_dma || request->actual == request->length) { 551 /*
552 * First, maybe a terminating short packet. Some DMA
553 * engines might handle this by themselves.
554 */
555 if ((request->zero && request->length
556 && (request->length % musb_ep->packet_sz == 0)
557 && (request->actual == request->length))
558#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA)
559 || (is_dma && (!dma->desired_mode ||
560 (request->actual &
561 (musb_ep->packet_sz - 1))))
562#endif
563 ) {
479 /* 564 /*
480 * First, maybe a terminating short packet. Some DMA 565 * On DMA completion, FIFO may not be
481 * engines might handle this by themselves. 566 * available yet...
482 */ 567 */
483 if ((request->zero && request->length 568 if (csr & MUSB_TXCSR_TXPKTRDY)
484 && request->length % musb_ep->packet_sz == 0) 569 return;
485#ifdef CONFIG_USB_INVENTRA_DMA
486 || (is_dma && (!dma->desired_mode ||
487 (request->actual &
488 (musb_ep->packet_sz - 1))))
489#endif
490 ) {
491 /*
492 * On DMA completion, FIFO may not be
493 * available yet...
494 */
495 if (csr & MUSB_TXCSR_TXPKTRDY)
496 return;
497 570
498 DBG(4, "sending zero pkt\n"); 571 dev_dbg(musb->controller, "sending zero pkt\n");
499 musb_writew(epio, MUSB_TXCSR, MUSB_TXCSR_MODE 572 musb_writew(epio, MUSB_TXCSR, MUSB_TXCSR_MODE
500 | MUSB_TXCSR_TXPKTRDY); 573 | MUSB_TXCSR_TXPKTRDY);
501 request->zero = 0; 574 request->zero = 0;
502 } 575 }
503 576
504 if (request->actual == request->length) { 577 if (request->actual == request->length) {
505 musb_g_giveback(musb_ep, request, 0); 578 musb_g_giveback(musb_ep, request, 0);
506 request = musb_ep->desc ? next_request(musb_ep) : NULL; 579 req = musb_ep->desc ? next_request(musb_ep) : NULL;
507 if (!request) { 580 if (!req) {
508 DBG(4, "%s idle now\n", 581 dev_dbg(musb->controller, "%s idle now\n",
509 musb_ep->end_point.name); 582 musb_ep->end_point.name);
510 return; 583 return;
511 }
512 } 584 }
513 } 585 }
514 586
515 txstate(musb, to_musb_request(request)); 587 txstate(musb, req);
516 } 588 }
517} 589}
518 590
@@ -572,17 +644,17 @@ static void rxstate(struct musb *musb, struct musb_request *req)
572 644
573 /* We shouldn't get here while DMA is active, but we do... */ 645 /* We shouldn't get here while DMA is active, but we do... */
574 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) { 646 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) {
575 DBG(4, "DMA pending...\n"); 647 dev_dbg(musb->controller, "DMA pending...\n");
576 return; 648 return;
577 } 649 }
578 650
579 if (csr & MUSB_RXCSR_P_SENDSTALL) { 651 if (csr & MUSB_RXCSR_P_SENDSTALL) {
580 DBG(5, "%s stalling, RXCSR %04x\n", 652 dev_dbg(musb->controller, "%s stalling, RXCSR %04x\n",
581 musb_ep->end_point.name, csr); 653 musb_ep->end_point.name, csr);
582 return; 654 return;
583 } 655 }
584 656
585 if (is_cppi_enabled() && musb_ep->dma) { 657 if (is_cppi_enabled() && is_buffer_mapped(req)) {
586 struct dma_controller *c = musb->dma_controller; 658 struct dma_controller *c = musb->dma_controller;
587 struct dma_channel *channel = musb_ep->dma; 659 struct dma_channel *channel = musb_ep->dma;
588 660
@@ -613,7 +685,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
613 len = musb_readw(epio, MUSB_RXCOUNT); 685 len = musb_readw(epio, MUSB_RXCOUNT);
614 if (request->actual < request->length) { 686 if (request->actual < request->length) {
615#ifdef CONFIG_USB_INVENTRA_DMA 687#ifdef CONFIG_USB_INVENTRA_DMA
616 if (is_dma_capable() && musb_ep->dma) { 688 if (is_buffer_mapped(req)) {
617 struct dma_controller *c; 689 struct dma_controller *c;
618 struct dma_channel *channel; 690 struct dma_channel *channel;
619 int use_dma = 0; 691 int use_dma = 0;
@@ -643,8 +715,8 @@ static void rxstate(struct musb *musb, struct musb_request *req)
643 */ 715 */
644 716
645 csr |= MUSB_RXCSR_DMAENAB; 717 csr |= MUSB_RXCSR_DMAENAB;
646 csr |= MUSB_RXCSR_AUTOCLEAR;
647#ifdef USE_MODE1 718#ifdef USE_MODE1
719 csr |= MUSB_RXCSR_AUTOCLEAR;
648 /* csr |= MUSB_RXCSR_DMAMODE; */ 720 /* csr |= MUSB_RXCSR_DMAMODE; */
649 721
650 /* this special sequence (enabling and then 722 /* this special sequence (enabling and then
@@ -653,6 +725,10 @@ static void rxstate(struct musb *musb, struct musb_request *req)
653 */ 725 */
654 musb_writew(epio, MUSB_RXCSR, 726 musb_writew(epio, MUSB_RXCSR,
655 csr | MUSB_RXCSR_DMAMODE); 727 csr | MUSB_RXCSR_DMAMODE);
728#else
729 if (!musb_ep->hb_mult &&
730 musb_ep->hw_ep->rx_double_buffered)
731 csr |= MUSB_RXCSR_AUTOCLEAR;
656#endif 732#endif
657 musb_writew(epio, MUSB_RXCSR, csr); 733 musb_writew(epio, MUSB_RXCSR, csr);
658 734
@@ -682,10 +758,57 @@ static void rxstate(struct musb *musb, struct musb_request *req)
682 if (use_dma) 758 if (use_dma)
683 return; 759 return;
684 } 760 }
761#elif defined(CONFIG_USB_UX500_DMA)
762 if ((is_buffer_mapped(req)) &&
763 (request->actual < request->length)) {
764
765 struct dma_controller *c;
766 struct dma_channel *channel;
767 int transfer_size = 0;
768
769 c = musb->dma_controller;
770 channel = musb_ep->dma;
771
772 /* In case first packet is short */
773 if (len < musb_ep->packet_sz)
774 transfer_size = len;
775 else if (request->short_not_ok)
776 transfer_size = min(request->length -
777 request->actual,
778 channel->max_len);
779 else
780 transfer_size = min(request->length -
781 request->actual,
782 (unsigned)len);
783
784 csr &= ~MUSB_RXCSR_DMAMODE;
785 csr |= (MUSB_RXCSR_DMAENAB |
786 MUSB_RXCSR_AUTOCLEAR);
787
788 musb_writew(epio, MUSB_RXCSR, csr);
789
790 if (transfer_size <= musb_ep->packet_sz) {
791 musb_ep->dma->desired_mode = 0;
792 } else {
793 musb_ep->dma->desired_mode = 1;
794 /* Mode must be set after DMAENAB */
795 csr |= MUSB_RXCSR_DMAMODE;
796 musb_writew(epio, MUSB_RXCSR, csr);
797 }
798
799 if (c->channel_program(channel,
800 musb_ep->packet_sz,
801 channel->desired_mode,
802 request->dma
803 + request->actual,
804 transfer_size))
805
806 return;
807 }
685#endif /* Mentor's DMA */ 808#endif /* Mentor's DMA */
686 809
687 fifo_count = request->length - request->actual; 810 fifo_count = request->length - request->actual;
688 DBG(3, "%s OUT/RX pio fifo %d/%d, maxpacket %d\n", 811 dev_dbg(musb->controller, "%s OUT/RX pio fifo %d/%d, maxpacket %d\n",
689 musb_ep->end_point.name, 812 musb_ep->end_point.name,
690 len, fifo_count, 813 len, fifo_count,
691 musb_ep->packet_sz); 814 musb_ep->packet_sz);
@@ -693,7 +816,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
693 fifo_count = min_t(unsigned, len, fifo_count); 816 fifo_count = min_t(unsigned, len, fifo_count);
694 817
695#ifdef CONFIG_USB_TUSB_OMAP_DMA 818#ifdef CONFIG_USB_TUSB_OMAP_DMA
696 if (tusb_dma_omap() && musb_ep->dma) { 819 if (tusb_dma_omap() && is_buffer_mapped(req)) {
697 struct dma_controller *c = musb->dma_controller; 820 struct dma_controller *c = musb->dma_controller;
698 struct dma_channel *channel = musb_ep->dma; 821 struct dma_channel *channel = musb_ep->dma;
699 u32 dma_addr = request->dma + request->actual; 822 u32 dma_addr = request->dma + request->actual;
@@ -708,6 +831,21 @@ static void rxstate(struct musb *musb, struct musb_request *req)
708 return; 831 return;
709 } 832 }
710#endif 833#endif
834 /*
835 * Unmap the dma buffer back to cpu if dma channel
836 * programming fails. This buffer is mapped if the
837 * channel allocation is successful
838 */
839 if (is_buffer_mapped(req)) {
840 unmap_dma_buffer(req, musb);
841
842 /*
843 * Clear DMAENAB and AUTOCLEAR for the
844 * PIO mode transfer
845 */
846 csr &= ~(MUSB_RXCSR_DMAENAB | MUSB_RXCSR_AUTOCLEAR);
847 musb_writew(epio, MUSB_RXCSR, csr);
848 }
711 849
712 musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *) 850 musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *)
713 (request->buf + request->actual)); 851 (request->buf + request->actual));
@@ -735,6 +873,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
735void musb_g_rx(struct musb *musb, u8 epnum) 873void musb_g_rx(struct musb *musb, u8 epnum)
736{ 874{
737 u16 csr; 875 u16 csr;
876 struct musb_request *req;
738 struct usb_request *request; 877 struct usb_request *request;
739 void __iomem *mbase = musb->mregs; 878 void __iomem *mbase = musb->mregs;
740 struct musb_ep *musb_ep; 879 struct musb_ep *musb_ep;
@@ -749,14 +888,16 @@ void musb_g_rx(struct musb *musb, u8 epnum)
749 888
750 musb_ep_select(mbase, epnum); 889 musb_ep_select(mbase, epnum);
751 890
752 request = next_request(musb_ep); 891 req = next_request(musb_ep);
753 if (!request) 892 if (!req)
754 return; 893 return;
755 894
895 request = &req->request;
896
756 csr = musb_readw(epio, MUSB_RXCSR); 897 csr = musb_readw(epio, MUSB_RXCSR);
757 dma = is_dma_capable() ? musb_ep->dma : NULL; 898 dma = is_dma_capable() ? musb_ep->dma : NULL;
758 899
759 DBG(4, "<== %s, rxcsr %04x%s %p\n", musb_ep->end_point.name, 900 dev_dbg(musb->controller, "<== %s, rxcsr %04x%s %p\n", musb_ep->end_point.name,
760 csr, dma ? " (dma)" : "", request); 901 csr, dma ? " (dma)" : "", request);
761 902
762 if (csr & MUSB_RXCSR_P_SENTSTALL) { 903 if (csr & MUSB_RXCSR_P_SENTSTALL) {
@@ -771,19 +912,18 @@ void musb_g_rx(struct musb *musb, u8 epnum)
771 csr &= ~MUSB_RXCSR_P_OVERRUN; 912 csr &= ~MUSB_RXCSR_P_OVERRUN;
772 musb_writew(epio, MUSB_RXCSR, csr); 913 musb_writew(epio, MUSB_RXCSR, csr);
773 914
774 DBG(3, "%s iso overrun on %p\n", musb_ep->name, request); 915 dev_dbg(musb->controller, "%s iso overrun on %p\n", musb_ep->name, request);
775 if (request && request->status == -EINPROGRESS) 916 if (request->status == -EINPROGRESS)
776 request->status = -EOVERFLOW; 917 request->status = -EOVERFLOW;
777 } 918 }
778 if (csr & MUSB_RXCSR_INCOMPRX) { 919 if (csr & MUSB_RXCSR_INCOMPRX) {
779 /* REVISIT not necessarily an error */ 920 /* REVISIT not necessarily an error */
780 DBG(4, "%s, incomprx\n", musb_ep->end_point.name); 921 dev_dbg(musb->controller, "%s, incomprx\n", musb_ep->end_point.name);
781 } 922 }
782 923
783 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { 924 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
784 /* "should not happen"; likely RXPKTRDY pending for DMA */ 925 /* "should not happen"; likely RXPKTRDY pending for DMA */
785 DBG((csr & MUSB_RXCSR_DMAENAB) ? 4 : 1, 926 dev_dbg(musb->controller, "%s busy, csr %04x\n",
786 "%s busy, csr %04x\n",
787 musb_ep->end_point.name, csr); 927 musb_ep->end_point.name, csr);
788 return; 928 return;
789 } 929 }
@@ -797,14 +937,15 @@ void musb_g_rx(struct musb *musb, u8 epnum)
797 937
798 request->actual += musb_ep->dma->actual_len; 938 request->actual += musb_ep->dma->actual_len;
799 939
800 DBG(4, "RXCSR%d %04x, dma off, %04x, len %zu, req %p\n", 940 dev_dbg(musb->controller, "RXCSR%d %04x, dma off, %04x, len %zu, req %p\n",
801 epnum, csr, 941 epnum, csr,
802 musb_readw(epio, MUSB_RXCSR), 942 musb_readw(epio, MUSB_RXCSR),
803 musb_ep->dma->actual_len, request); 943 musb_ep->dma->actual_len, request);
804 944
805#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA) 945#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA) || \
946 defined(CONFIG_USB_UX500_DMA)
806 /* Autoclear doesn't clear RxPktRdy for short packets */ 947 /* Autoclear doesn't clear RxPktRdy for short packets */
807 if ((dma->desired_mode == 0) 948 if ((dma->desired_mode == 0 && !hw_ep->rx_double_buffered)
808 || (dma->actual_len 949 || (dma->actual_len
809 & (musb_ep->packet_sz - 1))) { 950 & (musb_ep->packet_sz - 1))) {
810 /* ack the read! */ 951 /* ack the read! */
@@ -815,24 +956,29 @@ void musb_g_rx(struct musb *musb, u8 epnum)
815 /* incomplete, and not short? wait for next IN packet */ 956 /* incomplete, and not short? wait for next IN packet */
816 if ((request->actual < request->length) 957 if ((request->actual < request->length)
817 && (musb_ep->dma->actual_len 958 && (musb_ep->dma->actual_len
818 == musb_ep->packet_sz)) 959 == musb_ep->packet_sz)) {
960 /* In double buffer case, continue to unload fifo if
961 * there is Rx packet in FIFO.
962 **/
963 csr = musb_readw(epio, MUSB_RXCSR);
964 if ((csr & MUSB_RXCSR_RXPKTRDY) &&
965 hw_ep->rx_double_buffered)
966 goto exit;
819 return; 967 return;
968 }
820#endif 969#endif
821 musb_g_giveback(musb_ep, request, 0); 970 musb_g_giveback(musb_ep, request, 0);
822 971
823 request = next_request(musb_ep); 972 req = next_request(musb_ep);
824 if (!request) 973 if (!req)
825 return; 974 return;
826 } 975 }
827 976#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA) || \
828 /* analyze request if the ep is hot */ 977 defined(CONFIG_USB_UX500_DMA)
829 if (request) 978exit:
830 rxstate(musb, to_musb_request(request)); 979#endif
831 else 980 /* Analyze request */
832 DBG(3, "packet waiting for %s%s request\n", 981 rxstate(musb, req);
833 musb_ep->desc ? "" : "inactive ",
834 musb_ep->end_point.name);
835 return;
836} 982}
837 983
838/* ------------------------------------------------------------ */ 984/* ------------------------------------------------------------ */
@@ -875,9 +1021,25 @@ static int musb_gadget_enable(struct usb_ep *ep,
875 1021
876 /* REVISIT this rules out high bandwidth periodic transfers */ 1022 /* REVISIT this rules out high bandwidth periodic transfers */
877 tmp = le16_to_cpu(desc->wMaxPacketSize); 1023 tmp = le16_to_cpu(desc->wMaxPacketSize);
878 if (tmp & ~0x07ff) 1024 if (tmp & ~0x07ff) {
879 goto fail; 1025 int ok;
880 musb_ep->packet_sz = tmp; 1026
1027 if (usb_endpoint_dir_in(desc))
1028 ok = musb->hb_iso_tx;
1029 else
1030 ok = musb->hb_iso_rx;
1031
1032 if (!ok) {
1033 dev_dbg(musb->controller, "no support for high bandwidth ISO\n");
1034 goto fail;
1035 }
1036 musb_ep->hb_mult = (tmp >> 11) & 3;
1037 } else {
1038 musb_ep->hb_mult = 0;
1039 }
1040
1041 musb_ep->packet_sz = tmp & 0x7ff;
1042 tmp = musb_ep->packet_sz * (musb_ep->hb_mult + 1);
881 1043
882 /* enable the interrupts for the endpoint, set the endpoint 1044 /* enable the interrupts for the endpoint, set the endpoint
883 * packet size (or fail), set the mode, clear the fifo 1045 * packet size (or fail), set the mode, clear the fifo
@@ -890,8 +1052,11 @@ static int musb_gadget_enable(struct usb_ep *ep,
890 musb_ep->is_in = 1; 1052 musb_ep->is_in = 1;
891 if (!musb_ep->is_in) 1053 if (!musb_ep->is_in)
892 goto fail; 1054 goto fail;
893 if (tmp > hw_ep->max_packet_sz_tx) 1055
1056 if (tmp > hw_ep->max_packet_sz_tx) {
1057 dev_dbg(musb->controller, "packet size beyond hardware FIFO size\n");
894 goto fail; 1058 goto fail;
1059 }
895 1060
896 int_txe |= (1 << epnum); 1061 int_txe |= (1 << epnum);
897 musb_writew(mbase, MUSB_INTRTXE, int_txe); 1062 musb_writew(mbase, MUSB_INTRTXE, int_txe);
@@ -900,13 +1065,13 @@ static int musb_gadget_enable(struct usb_ep *ep,
900 * likewise high bandwidth periodic tx 1065 * likewise high bandwidth periodic tx
901 */ 1066 */
902 /* Set TXMAXP with the FIFO size of the endpoint 1067 /* Set TXMAXP with the FIFO size of the endpoint
903 * to disable double buffering mode. Currently, It seems that double 1068 * to disable double buffering mode.
904 * buffering has problem if musb RTL revision number < 2.0.
905 */ 1069 */
906 if (musb->hwvers < MUSB_HWVERS_2000) 1070 if (musb->double_buffer_not_ok)
907 musb_writew(regs, MUSB_TXMAXP, hw_ep->max_packet_sz_tx); 1071 musb_writew(regs, MUSB_TXMAXP, hw_ep->max_packet_sz_tx);
908 else 1072 else
909 musb_writew(regs, MUSB_TXMAXP, tmp); 1073 musb_writew(regs, MUSB_TXMAXP, musb_ep->packet_sz
1074 | (musb_ep->hb_mult << 11));
910 1075
911 csr = MUSB_TXCSR_MODE | MUSB_TXCSR_CLRDATATOG; 1076 csr = MUSB_TXCSR_MODE | MUSB_TXCSR_CLRDATATOG;
912 if (musb_readw(regs, MUSB_TXCSR) 1077 if (musb_readw(regs, MUSB_TXCSR)
@@ -927,8 +1092,11 @@ static int musb_gadget_enable(struct usb_ep *ep,
927 musb_ep->is_in = 0; 1092 musb_ep->is_in = 0;
928 if (musb_ep->is_in) 1093 if (musb_ep->is_in)
929 goto fail; 1094 goto fail;
930 if (tmp > hw_ep->max_packet_sz_rx) 1095
1096 if (tmp > hw_ep->max_packet_sz_rx) {
1097 dev_dbg(musb->controller, "packet size beyond hardware FIFO size\n");
931 goto fail; 1098 goto fail;
1099 }
932 1100
933 int_rxe |= (1 << epnum); 1101 int_rxe |= (1 << epnum);
934 musb_writew(mbase, MUSB_INTRRXE, int_rxe); 1102 musb_writew(mbase, MUSB_INTRRXE, int_rxe);
@@ -939,10 +1107,11 @@ static int musb_gadget_enable(struct usb_ep *ep,
939 /* Set RXMAXP with the FIFO size of the endpoint 1107 /* Set RXMAXP with the FIFO size of the endpoint
940 * to disable double buffering mode. 1108 * to disable double buffering mode.
941 */ 1109 */
942 if (musb->hwvers < MUSB_HWVERS_2000) 1110 if (musb->double_buffer_not_ok)
943 musb_writew(regs, MUSB_RXMAXP, hw_ep->max_packet_sz_rx); 1111 musb_writew(regs, MUSB_RXMAXP, hw_ep->max_packet_sz_tx);
944 else 1112 else
945 musb_writew(regs, MUSB_RXMAXP, tmp); 1113 musb_writew(regs, MUSB_RXMAXP, musb_ep->packet_sz
1114 | (musb_ep->hb_mult << 11));
946 1115
947 /* force shared fifo to OUT-only mode */ 1116 /* force shared fifo to OUT-only mode */
948 if (hw_ep->is_shared_fifo) { 1117 if (hw_ep->is_shared_fifo) {
@@ -1038,7 +1207,7 @@ static int musb_gadget_disable(struct usb_ep *ep)
1038 1207
1039 spin_unlock_irqrestore(&(musb->lock), flags); 1208 spin_unlock_irqrestore(&(musb->lock), flags);
1040 1209
1041 DBG(2, "%s\n", musb_ep->end_point.name); 1210 dev_dbg(musb->controller, "%s\n", musb_ep->end_point.name);
1042 1211
1043 return status; 1212 return status;
1044} 1213}
@@ -1050,16 +1219,19 @@ static int musb_gadget_disable(struct usb_ep *ep)
1050struct usb_request *musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) 1219struct usb_request *musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
1051{ 1220{
1052 struct musb_ep *musb_ep = to_musb_ep(ep); 1221 struct musb_ep *musb_ep = to_musb_ep(ep);
1222 struct musb *musb = musb_ep->musb;
1053 struct musb_request *request = NULL; 1223 struct musb_request *request = NULL;
1054 1224
1055 request = kzalloc(sizeof *request, gfp_flags); 1225 request = kzalloc(sizeof *request, gfp_flags);
1056 if (request) { 1226 if (!request) {
1057 INIT_LIST_HEAD(&request->request.list); 1227 dev_dbg(musb->controller, "not enough memory\n");
1058 request->request.dma = DMA_ADDR_INVALID; 1228 return NULL;
1059 request->epnum = musb_ep->current_epnum;
1060 request->ep = musb_ep;
1061 } 1229 }
1062 1230
1231 request->request.dma = DMA_ADDR_INVALID;
1232 request->epnum = musb_ep->current_epnum;
1233 request->ep = musb_ep;
1234
1063 return &request->request; 1235 return &request->request;
1064} 1236}
1065 1237
@@ -1086,7 +1258,7 @@ struct free_record {
1086 */ 1258 */
1087void musb_ep_restart(struct musb *musb, struct musb_request *req) 1259void musb_ep_restart(struct musb *musb, struct musb_request *req)
1088{ 1260{
1089 DBG(3, "<== %s request %p len %u on hw_ep%d\n", 1261 dev_dbg(musb->controller, "<== %s request %p len %u on hw_ep%d\n",
1090 req->tx ? "TX/IN" : "RX/OUT", 1262 req->tx ? "TX/IN" : "RX/OUT",
1091 &req->request, req->request.length, req->epnum); 1263 &req->request, req->request.length, req->epnum);
1092 1264
@@ -1120,7 +1292,7 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1120 if (request->ep != musb_ep) 1292 if (request->ep != musb_ep)
1121 return -EINVAL; 1293 return -EINVAL;
1122 1294
1123 DBG(4, "<== to %s request=%p\n", ep->name, req); 1295 dev_dbg(musb->controller, "<== to %s request=%p\n", ep->name, req);
1124 1296
1125 /* request is mine now... */ 1297 /* request is mine now... */
1126 request->request.actual = 0; 1298 request->request.actual = 0;
@@ -1128,45 +1300,23 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1128 request->epnum = musb_ep->current_epnum; 1300 request->epnum = musb_ep->current_epnum;
1129 request->tx = musb_ep->is_in; 1301 request->tx = musb_ep->is_in;
1130 1302
1131 if (is_dma_capable() && musb_ep->dma) { 1303 map_dma_buffer(request, musb, musb_ep);
1132 if (request->request.dma == DMA_ADDR_INVALID) {
1133 request->request.dma = dma_map_single(
1134 musb->controller,
1135 request->request.buf,
1136 request->request.length,
1137 request->tx
1138 ? DMA_TO_DEVICE
1139 : DMA_FROM_DEVICE);
1140 request->mapped = 1;
1141 } else {
1142 dma_sync_single_for_device(musb->controller,
1143 request->request.dma,
1144 request->request.length,
1145 request->tx
1146 ? DMA_TO_DEVICE
1147 : DMA_FROM_DEVICE);
1148 request->mapped = 0;
1149 }
1150 } else if (!req->buf) {
1151 return -ENODATA;
1152 } else
1153 request->mapped = 0;
1154 1304
1155 spin_lock_irqsave(&musb->lock, lockflags); 1305 spin_lock_irqsave(&musb->lock, lockflags);
1156 1306
1157 /* don't queue if the ep is down */ 1307 /* don't queue if the ep is down */
1158 if (!musb_ep->desc) { 1308 if (!musb_ep->desc) {
1159 DBG(4, "req %p queued to %s while ep %s\n", 1309 dev_dbg(musb->controller, "req %p queued to %s while ep %s\n",
1160 req, ep->name, "disabled"); 1310 req, ep->name, "disabled");
1161 status = -ESHUTDOWN; 1311 status = -ESHUTDOWN;
1162 goto cleanup; 1312 goto cleanup;
1163 } 1313 }
1164 1314
1165 /* add request to the list */ 1315 /* add request to the list */
1166 list_add_tail(&(request->request.list), &(musb_ep->req_list)); 1316 list_add_tail(&request->list, &musb_ep->req_list);
1167 1317
1168 /* it this is the head of the queue, start i/o ... */ 1318 /* it this is the head of the queue, start i/o ... */
1169 if (!musb_ep->busy && &request->request.list == musb_ep->req_list.next) 1319 if (!musb_ep->busy && &request->list == musb_ep->req_list.next)
1170 musb_ep_restart(musb, request); 1320 musb_ep_restart(musb, request);
1171 1321
1172cleanup: 1322cleanup:
@@ -1177,7 +1327,8 @@ cleanup:
1177static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request) 1327static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request)
1178{ 1328{
1179 struct musb_ep *musb_ep = to_musb_ep(ep); 1329 struct musb_ep *musb_ep = to_musb_ep(ep);
1180 struct usb_request *r; 1330 struct musb_request *req = to_musb_request(request);
1331 struct musb_request *r;
1181 unsigned long flags; 1332 unsigned long flags;
1182 int status = 0; 1333 int status = 0;
1183 struct musb *musb = musb_ep->musb; 1334 struct musb *musb = musb_ep->musb;
@@ -1188,17 +1339,17 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request)
1188 spin_lock_irqsave(&musb->lock, flags); 1339 spin_lock_irqsave(&musb->lock, flags);
1189 1340
1190 list_for_each_entry(r, &musb_ep->req_list, list) { 1341 list_for_each_entry(r, &musb_ep->req_list, list) {
1191 if (r == request) 1342 if (r == req)
1192 break; 1343 break;
1193 } 1344 }
1194 if (r != request) { 1345 if (r != req) {
1195 DBG(3, "request %p not queued to %s\n", request, ep->name); 1346 dev_dbg(musb->controller, "request %p not queued to %s\n", request, ep->name);
1196 status = -EINVAL; 1347 status = -EINVAL;
1197 goto done; 1348 goto done;
1198 } 1349 }
1199 1350
1200 /* if the hardware doesn't have the request, easy ... */ 1351 /* if the hardware doesn't have the request, easy ... */
1201 if (musb_ep->req_list.next != &request->list || musb_ep->busy) 1352 if (musb_ep->req_list.next != &req->list || musb_ep->busy)
1202 musb_g_giveback(musb_ep, request, -ECONNRESET); 1353 musb_g_giveback(musb_ep, request, -ECONNRESET);
1203 1354
1204 /* ... else abort the dma transfer ... */ 1355 /* ... else abort the dma transfer ... */
@@ -1255,10 +1406,10 @@ static int musb_gadget_set_halt(struct usb_ep *ep, int value)
1255 1406
1256 musb_ep_select(mbase, epnum); 1407 musb_ep_select(mbase, epnum);
1257 1408
1258 request = to_musb_request(next_request(musb_ep)); 1409 request = next_request(musb_ep);
1259 if (value) { 1410 if (value) {
1260 if (request) { 1411 if (request) {
1261 DBG(3, "request in progress, cannot halt %s\n", 1412 dev_dbg(musb->controller, "request in progress, cannot halt %s\n",
1262 ep->name); 1413 ep->name);
1263 status = -EAGAIN; 1414 status = -EAGAIN;
1264 goto done; 1415 goto done;
@@ -1267,7 +1418,7 @@ static int musb_gadget_set_halt(struct usb_ep *ep, int value)
1267 if (musb_ep->is_in) { 1418 if (musb_ep->is_in) {
1268 csr = musb_readw(epio, MUSB_TXCSR); 1419 csr = musb_readw(epio, MUSB_TXCSR);
1269 if (csr & MUSB_TXCSR_FIFONOTEMPTY) { 1420 if (csr & MUSB_TXCSR_FIFONOTEMPTY) {
1270 DBG(3, "FIFO busy, cannot halt %s\n", ep->name); 1421 dev_dbg(musb->controller, "FIFO busy, cannot halt %s\n", ep->name);
1271 status = -EAGAIN; 1422 status = -EAGAIN;
1272 goto done; 1423 goto done;
1273 } 1424 }
@@ -1276,7 +1427,7 @@ static int musb_gadget_set_halt(struct usb_ep *ep, int value)
1276 musb_ep->wedged = 0; 1427 musb_ep->wedged = 0;
1277 1428
1278 /* set/clear the stall and toggle bits */ 1429 /* set/clear the stall and toggle bits */
1279 DBG(2, "%s: %s stall\n", ep->name, value ? "set" : "clear"); 1430 dev_dbg(musb->controller, "%s: %s stall\n", ep->name, value ? "set" : "clear");
1280 if (musb_ep->is_in) { 1431 if (musb_ep->is_in) {
1281 csr = musb_readw(epio, MUSB_TXCSR); 1432 csr = musb_readw(epio, MUSB_TXCSR);
1282 csr |= MUSB_TXCSR_P_WZC_BITS 1433 csr |= MUSB_TXCSR_P_WZC_BITS
@@ -1303,7 +1454,7 @@ static int musb_gadget_set_halt(struct usb_ep *ep, int value)
1303 1454
1304 /* maybe start the first request in the queue */ 1455 /* maybe start the first request in the queue */
1305 if (!musb_ep->busy && !value && request) { 1456 if (!musb_ep->busy && !value && request) {
1306 DBG(3, "restarting the request\n"); 1457 dev_dbg(musb->controller, "restarting the request\n");
1307 musb_ep_restart(musb, request); 1458 musb_ep_restart(musb, request);
1308 } 1459 }
1309 1460
@@ -1373,6 +1524,12 @@ static void musb_gadget_fifo_flush(struct usb_ep *ep)
1373 csr = musb_readw(epio, MUSB_TXCSR); 1524 csr = musb_readw(epio, MUSB_TXCSR);
1374 if (csr & MUSB_TXCSR_FIFONOTEMPTY) { 1525 if (csr & MUSB_TXCSR_FIFONOTEMPTY) {
1375 csr |= MUSB_TXCSR_FLUSHFIFO | MUSB_TXCSR_P_WZC_BITS; 1526 csr |= MUSB_TXCSR_FLUSHFIFO | MUSB_TXCSR_P_WZC_BITS;
1527 /*
1528 * Setting both TXPKTRDY and FLUSHFIFO makes controller
1529 * to interrupt current FIFO loading, but not flushing
1530 * the already loaded ones.
1531 */
1532 csr &= ~MUSB_TXCSR_TXPKTRDY;
1376 musb_writew(epio, MUSB_TXCSR, csr); 1533 musb_writew(epio, MUSB_TXCSR, csr);
1377 /* REVISIT may be inappropriate w/o FIFONOTEMPTY ... */ 1534 /* REVISIT may be inappropriate w/o FIFONOTEMPTY ... */
1378 musb_writew(epio, MUSB_TXCSR, csr); 1535 musb_writew(epio, MUSB_TXCSR, csr);
@@ -1434,7 +1591,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
1434 case OTG_STATE_B_IDLE: 1591 case OTG_STATE_B_IDLE:
1435 /* Start SRP ... OTG not required. */ 1592 /* Start SRP ... OTG not required. */
1436 devctl = musb_readb(mregs, MUSB_DEVCTL); 1593 devctl = musb_readb(mregs, MUSB_DEVCTL);
1437 DBG(2, "Sending SRP: devctl: %02x\n", devctl); 1594 dev_dbg(musb->controller, "Sending SRP: devctl: %02x\n", devctl);
1438 devctl |= MUSB_DEVCTL_SESSION; 1595 devctl |= MUSB_DEVCTL_SESSION;
1439 musb_writeb(mregs, MUSB_DEVCTL, devctl); 1596 musb_writeb(mregs, MUSB_DEVCTL, devctl);
1440 devctl = musb_readb(mregs, MUSB_DEVCTL); 1597 devctl = musb_readb(mregs, MUSB_DEVCTL);
@@ -1451,6 +1608,10 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
1451 break; 1608 break;
1452 } 1609 }
1453 1610
1611 spin_unlock_irqrestore(&musb->lock, flags);
1612 otg_start_srp(musb->xceiv);
1613 spin_lock_irqsave(&musb->lock, flags);
1614
1454 /* Block idling for at least 1s */ 1615 /* Block idling for at least 1s */
1455 musb_platform_try_idle(musb, 1616 musb_platform_try_idle(musb,
1456 jiffies + msecs_to_jiffies(1 * HZ)); 1617 jiffies + msecs_to_jiffies(1 * HZ));
@@ -1458,7 +1619,8 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
1458 status = 0; 1619 status = 0;
1459 goto done; 1620 goto done;
1460 default: 1621 default:
1461 DBG(2, "Unhandled wake: %s\n", otg_state_string(musb)); 1622 dev_dbg(musb->controller, "Unhandled wake: %s\n",
1623 otg_state_string(musb->xceiv->state));
1462 goto done; 1624 goto done;
1463 } 1625 }
1464 1626
@@ -1467,7 +1629,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
1467 power = musb_readb(mregs, MUSB_POWER); 1629 power = musb_readb(mregs, MUSB_POWER);
1468 power |= MUSB_POWER_RESUME; 1630 power |= MUSB_POWER_RESUME;
1469 musb_writeb(mregs, MUSB_POWER, power); 1631 musb_writeb(mregs, MUSB_POWER, power);
1470 DBG(2, "issue wakeup\n"); 1632 dev_dbg(musb->controller, "issue wakeup\n");
1471 1633
1472 /* FIXME do this next chunk in a timer callback, no udelay */ 1634 /* FIXME do this next chunk in a timer callback, no udelay */
1473 mdelay(2); 1635 mdelay(2);
@@ -1501,7 +1663,7 @@ static void musb_pullup(struct musb *musb, int is_on)
1501 1663
1502 /* FIXME if on, HdrcStart; if off, HdrcStop */ 1664 /* FIXME if on, HdrcStart; if off, HdrcStop */
1503 1665
1504 DBG(3, "gadget %s D+ pullup %s\n", 1666 dev_dbg(musb->controller, "gadget %s D+ pullup %s\n",
1505 musb->gadget_driver->function, is_on ? "on" : "off"); 1667 musb->gadget_driver->function, is_on ? "on" : "off");
1506 musb_writeb(musb->mregs, MUSB_POWER, power); 1668 musb_writeb(musb->mregs, MUSB_POWER, power);
1507} 1669}
@@ -1509,7 +1671,7 @@ static void musb_pullup(struct musb *musb, int is_on)
1509#if 0 1671#if 0
1510static int musb_gadget_vbus_session(struct usb_gadget *gadget, int is_active) 1672static int musb_gadget_vbus_session(struct usb_gadget *gadget, int is_active)
1511{ 1673{
1512 DBG(2, "<= %s =>\n", __func__); 1674 dev_dbg(musb->controller, "<= %s =>\n", __func__);
1513 1675
1514 /* 1676 /*
1515 * FIXME iff driver's softconnect flag is set (as it is during probe, 1677 * FIXME iff driver's softconnect flag is set (as it is during probe,
@@ -1617,7 +1779,7 @@ static inline void __init musb_g_init_endpoints(struct musb *musb)
1617 struct musb_hw_ep *hw_ep; 1779 struct musb_hw_ep *hw_ep;
1618 unsigned count = 0; 1780 unsigned count = 0;
1619 1781
1620 /* intialize endpoint list just once */ 1782 /* initialize endpoint list just once */
1621 INIT_LIST_HEAD(&(musb->g.ep_list)); 1783 INIT_LIST_HEAD(&(musb->g.ep_list));
1622 1784
1623 for (epnum = 0, hw_ep = musb->endpoints; 1785 for (epnum = 0, hw_ep = musb->endpoints;
@@ -1676,8 +1838,10 @@ int __init musb_gadget_setup(struct musb *musb)
1676 musb_platform_try_idle(musb, 0); 1838 musb_platform_try_idle(musb, 0);
1677 1839
1678 status = device_register(&musb->g.dev); 1840 status = device_register(&musb->g.dev);
1679 if (status != 0) 1841 if (status != 0) {
1842 put_device(&musb->g.dev);
1680 the_gadget = NULL; 1843 the_gadget = NULL;
1844 }
1681 return status; 1845 return status;
1682} 1846}
1683 1847
@@ -1696,97 +1860,115 @@ void musb_gadget_cleanup(struct musb *musb)
1696 * 1860 *
1697 * -EINVAL something went wrong (not driver) 1861 * -EINVAL something went wrong (not driver)
1698 * -EBUSY another gadget is already using the controller 1862 * -EBUSY another gadget is already using the controller
1699 * -ENOMEM no memeory to perform the operation 1863 * -ENOMEM no memory to perform the operation
1700 * 1864 *
1701 * @param driver the gadget driver 1865 * @param driver the gadget driver
1866 * @param bind the driver's bind function
1702 * @return <0 if error, 0 if everything is fine 1867 * @return <0 if error, 0 if everything is fine
1703 */ 1868 */
1704int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1869int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1870 int (*bind)(struct usb_gadget *))
1705{ 1871{
1706 int retval; 1872 struct musb *musb = the_gadget;
1707 unsigned long flags; 1873 unsigned long flags;
1708 struct musb *musb = the_gadget; 1874 int retval = -EINVAL;
1709 1875
1710 if (!driver 1876 if (!driver
1711 || driver->speed != USB_SPEED_HIGH 1877 || driver->speed != USB_SPEED_HIGH
1712 || !driver->bind 1878 || !bind || !driver->setup)
1713 || !driver->setup) 1879 goto err0;
1714 return -EINVAL;
1715 1880
1716 /* driver must be initialized to support peripheral mode */ 1881 /* driver must be initialized to support peripheral mode */
1717 if (!musb) { 1882 if (!musb) {
1718 DBG(1, "%s, no dev??\n", __func__); 1883 dev_dbg(musb->controller, "no dev??\n");
1719 return -ENODEV; 1884 retval = -ENODEV;
1885 goto err0;
1720 } 1886 }
1721 1887
1722 DBG(3, "registering driver %s\n", driver->function); 1888 pm_runtime_get_sync(musb->controller);
1723 spin_lock_irqsave(&musb->lock, flags); 1889
1890 dev_dbg(musb->controller, "registering driver %s\n", driver->function);
1724 1891
1725 if (musb->gadget_driver) { 1892 if (musb->gadget_driver) {
1726 DBG(1, "%s is already bound to %s\n", 1893 dev_dbg(musb->controller, "%s is already bound to %s\n",
1727 musb_driver_name, 1894 musb_driver_name,
1728 musb->gadget_driver->driver.name); 1895 musb->gadget_driver->driver.name);
1729 retval = -EBUSY; 1896 retval = -EBUSY;
1730 } else { 1897 goto err0;
1731 musb->gadget_driver = driver;
1732 musb->g.dev.driver = &driver->driver;
1733 driver->driver.bus = NULL;
1734 musb->softconnect = 1;
1735 retval = 0;
1736 } 1898 }
1737 1899
1900 spin_lock_irqsave(&musb->lock, flags);
1901 musb->gadget_driver = driver;
1902 musb->g.dev.driver = &driver->driver;
1903 driver->driver.bus = NULL;
1904 musb->softconnect = 1;
1738 spin_unlock_irqrestore(&musb->lock, flags); 1905 spin_unlock_irqrestore(&musb->lock, flags);
1739 1906
1740 if (retval == 0) { 1907 retval = bind(&musb->g);
1741 retval = driver->bind(&musb->g); 1908 if (retval) {
1742 if (retval != 0) { 1909 dev_dbg(musb->controller, "bind to driver %s failed --> %d\n",
1743 DBG(3, "bind to driver %s failed --> %d\n", 1910 driver->driver.name, retval);
1744 driver->driver.name, retval); 1911 goto err1;
1745 musb->gadget_driver = NULL; 1912 }
1746 musb->g.dev.driver = NULL;
1747 }
1748 1913
1749 spin_lock_irqsave(&musb->lock, flags); 1914 spin_lock_irqsave(&musb->lock, flags);
1750 1915
1751 otg_set_peripheral(musb->xceiv, &musb->g); 1916 otg_set_peripheral(musb->xceiv, &musb->g);
1752 musb->xceiv->state = OTG_STATE_B_IDLE; 1917 musb->xceiv->state = OTG_STATE_B_IDLE;
1753 musb->is_active = 1; 1918 musb->is_active = 1;
1754 1919
1755 /* FIXME this ignores the softconnect flag. Drivers are 1920 /*
1756 * allowed hold the peripheral inactive until for example 1921 * FIXME this ignores the softconnect flag. Drivers are
1757 * userspace hooks up printer hardware or DSP codecs, so 1922 * allowed hold the peripheral inactive until for example
1758 * hosts only see fully functional devices. 1923 * userspace hooks up printer hardware or DSP codecs, so
1759 */ 1924 * hosts only see fully functional devices.
1925 */
1760 1926
1761 if (!is_otg_enabled(musb)) 1927 if (!is_otg_enabled(musb))
1762 musb_start(musb); 1928 musb_start(musb);
1763 1929
1764 otg_set_peripheral(musb->xceiv, &musb->g); 1930 otg_set_peripheral(musb->xceiv, &musb->g);
1765 1931
1766 spin_unlock_irqrestore(&musb->lock, flags); 1932 spin_unlock_irqrestore(&musb->lock, flags);
1767 1933
1768 if (is_otg_enabled(musb)) { 1934 if (is_otg_enabled(musb)) {
1769 DBG(3, "OTG startup...\n"); 1935 struct usb_hcd *hcd = musb_to_hcd(musb);
1770 1936
1771 /* REVISIT: funcall to other code, which also 1937 dev_dbg(musb->controller, "OTG startup...\n");
1772 * handles power budgeting ... this way also 1938
1773 * ensures HdrcStart is indirectly called. 1939 /* REVISIT: funcall to other code, which also
1774 */ 1940 * handles power budgeting ... this way also
1775 retval = usb_add_hcd(musb_to_hcd(musb), -1, 0); 1941 * ensures HdrcStart is indirectly called.
1776 if (retval < 0) { 1942 */
1777 DBG(1, "add_hcd failed, %d\n", retval); 1943 retval = usb_add_hcd(musb_to_hcd(musb), -1, 0);
1778 spin_lock_irqsave(&musb->lock, flags); 1944 if (retval < 0) {
1779 otg_set_peripheral(musb->xceiv, NULL); 1945 dev_dbg(musb->controller, "add_hcd failed, %d\n", retval);
1780 musb->gadget_driver = NULL; 1946 goto err2;
1781 musb->g.dev.driver = NULL;
1782 spin_unlock_irqrestore(&musb->lock, flags);
1783 }
1784 } 1947 }
1948
1949 if ((musb->xceiv->last_event == USB_EVENT_ID)
1950 && musb->xceiv->set_vbus)
1951 otg_set_vbus(musb->xceiv, 1);
1952
1953 hcd->self.uses_pio_for_control = 1;
1785 } 1954 }
1955 if (musb->xceiv->last_event == USB_EVENT_NONE)
1956 pm_runtime_put(musb->controller);
1957
1958 return 0;
1786 1959
1960err2:
1961 if (!is_otg_enabled(musb))
1962 musb_stop(musb);
1963
1964err1:
1965 musb->gadget_driver = NULL;
1966 musb->g.dev.driver = NULL;
1967
1968err0:
1787 return retval; 1969 return retval;
1788} 1970}
1789EXPORT_SYMBOL(usb_gadget_register_driver); 1971EXPORT_SYMBOL(usb_gadget_probe_driver);
1790 1972
1791static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver) 1973static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver)
1792{ 1974{
@@ -1838,14 +2020,20 @@ static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver)
1838 */ 2020 */
1839int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2021int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1840{ 2022{
1841 unsigned long flags;
1842 int retval = 0;
1843 struct musb *musb = the_gadget; 2023 struct musb *musb = the_gadget;
2024 unsigned long flags;
1844 2025
1845 if (!driver || !driver->unbind || !musb) 2026 if (!driver || !driver->unbind || !musb)
1846 return -EINVAL; 2027 return -EINVAL;
1847 2028
1848 /* REVISIT always use otg_set_peripheral() here too; 2029 if (!musb->gadget_driver)
2030 return -EINVAL;
2031
2032 if (musb->xceiv->last_event == USB_EVENT_NONE)
2033 pm_runtime_get_sync(musb->controller);
2034
2035 /*
2036 * REVISIT always use otg_set_peripheral() here too;
1849 * this needs to shut down the OTG engine. 2037 * this needs to shut down the OTG engine.
1850 */ 2038 */
1851 2039
@@ -1855,29 +2043,26 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1855 musb_hnp_stop(musb); 2043 musb_hnp_stop(musb);
1856#endif 2044#endif
1857 2045
1858 if (musb->gadget_driver == driver) { 2046 (void) musb_gadget_vbus_draw(&musb->g, 0);
1859 2047
1860 (void) musb_gadget_vbus_draw(&musb->g, 0); 2048 musb->xceiv->state = OTG_STATE_UNDEFINED;
2049 stop_activity(musb, driver);
2050 otg_set_peripheral(musb->xceiv, NULL);
1861 2051
1862 musb->xceiv->state = OTG_STATE_UNDEFINED; 2052 dev_dbg(musb->controller, "unregistering driver %s\n", driver->function);
1863 stop_activity(musb, driver);
1864 otg_set_peripheral(musb->xceiv, NULL);
1865 2053
1866 DBG(3, "unregistering driver %s\n", driver->function); 2054 spin_unlock_irqrestore(&musb->lock, flags);
1867 spin_unlock_irqrestore(&musb->lock, flags); 2055 driver->unbind(&musb->g);
1868 driver->unbind(&musb->g); 2056 spin_lock_irqsave(&musb->lock, flags);
1869 spin_lock_irqsave(&musb->lock, flags);
1870 2057
1871 musb->gadget_driver = NULL; 2058 musb->gadget_driver = NULL;
1872 musb->g.dev.driver = NULL; 2059 musb->g.dev.driver = NULL;
1873 2060
1874 musb->is_active = 0; 2061 musb->is_active = 0;
1875 musb_platform_try_idle(musb, 0); 2062 musb_platform_try_idle(musb, 0);
1876 } else
1877 retval = -EINVAL;
1878 spin_unlock_irqrestore(&musb->lock, flags); 2063 spin_unlock_irqrestore(&musb->lock, flags);
1879 2064
1880 if (is_otg_enabled(musb) && retval == 0) { 2065 if (is_otg_enabled(musb)) {
1881 usb_remove_hcd(musb_to_hcd(musb)); 2066 usb_remove_hcd(musb_to_hcd(musb));
1882 /* FIXME we need to be able to register another 2067 /* FIXME we need to be able to register another
1883 * gadget driver here and have everything work; 2068 * gadget driver here and have everything work;
@@ -1885,7 +2070,12 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1885 */ 2070 */
1886 } 2071 }
1887 2072
1888 return retval; 2073 if (!is_otg_enabled(musb))
2074 musb_stop(musb);
2075
2076 pm_runtime_put(musb->controller);
2077
2078 return 0;
1889} 2079}
1890EXPORT_SYMBOL(usb_gadget_unregister_driver); 2080EXPORT_SYMBOL(usb_gadget_unregister_driver);
1891 2081
@@ -1911,7 +2101,7 @@ void musb_g_resume(struct musb *musb)
1911 break; 2101 break;
1912 default: 2102 default:
1913 WARNING("unhandled RESUME transition (%s)\n", 2103 WARNING("unhandled RESUME transition (%s)\n",
1914 otg_state_string(musb)); 2104 otg_state_string(musb->xceiv->state));
1915 } 2105 }
1916} 2106}
1917 2107
@@ -1921,7 +2111,7 @@ void musb_g_suspend(struct musb *musb)
1921 u8 devctl; 2111 u8 devctl;
1922 2112
1923 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 2113 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
1924 DBG(3, "devctl %02x\n", devctl); 2114 dev_dbg(musb->controller, "devctl %02x\n", devctl);
1925 2115
1926 switch (musb->xceiv->state) { 2116 switch (musb->xceiv->state) {
1927 case OTG_STATE_B_IDLE: 2117 case OTG_STATE_B_IDLE:
@@ -1941,7 +2131,7 @@ void musb_g_suspend(struct musb *musb)
1941 * A_PERIPHERAL may need care too 2131 * A_PERIPHERAL may need care too
1942 */ 2132 */
1943 WARNING("unhandled SUSPEND transition (%s)\n", 2133 WARNING("unhandled SUSPEND transition (%s)\n",
1944 otg_state_string(musb)); 2134 otg_state_string(musb->xceiv->state));
1945 } 2135 }
1946} 2136}
1947 2137
@@ -1957,7 +2147,7 @@ void musb_g_disconnect(struct musb *musb)
1957 void __iomem *mregs = musb->mregs; 2147 void __iomem *mregs = musb->mregs;
1958 u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 2148 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
1959 2149
1960 DBG(3, "devctl %02x\n", devctl); 2150 dev_dbg(musb->controller, "devctl %02x\n", devctl);
1961 2151
1962 /* clear HR */ 2152 /* clear HR */
1963 musb_writeb(mregs, MUSB_DEVCTL, devctl & MUSB_DEVCTL_SESSION); 2153 musb_writeb(mregs, MUSB_DEVCTL, devctl & MUSB_DEVCTL_SESSION);
@@ -1975,8 +2165,8 @@ void musb_g_disconnect(struct musb *musb)
1975 switch (musb->xceiv->state) { 2165 switch (musb->xceiv->state) {
1976 default: 2166 default:
1977#ifdef CONFIG_USB_MUSB_OTG 2167#ifdef CONFIG_USB_MUSB_OTG
1978 DBG(2, "Unhandled disconnect %s, setting a_idle\n", 2168 dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n",
1979 otg_state_string(musb)); 2169 otg_state_string(musb->xceiv->state));
1980 musb->xceiv->state = OTG_STATE_A_IDLE; 2170 musb->xceiv->state = OTG_STATE_A_IDLE;
1981 MUSB_HST_MODE(musb); 2171 MUSB_HST_MODE(musb);
1982 break; 2172 break;
@@ -2006,7 +2196,7 @@ __acquires(musb->lock)
2006 u8 devctl = musb_readb(mbase, MUSB_DEVCTL); 2196 u8 devctl = musb_readb(mbase, MUSB_DEVCTL);
2007 u8 power; 2197 u8 power;
2008 2198
2009 DBG(3, "<== %s addr=%x driver '%s'\n", 2199 dev_dbg(musb->controller, "<== %s addr=%x driver '%s'\n",
2010 (devctl & MUSB_DEVCTL_BDEVICE) 2200 (devctl & MUSB_DEVCTL_BDEVICE)
2011 ? "B-Device" : "A-Device", 2201 ? "B-Device" : "A-Device",
2012 musb_readb(mbase, MUSB_FADDR), 2202 musb_readb(mbase, MUSB_FADDR),
diff --git a/drivers/usb/musb/musb_gadget.h b/drivers/usb/musb/musb_gadget.h
index 572b1da7f2dc..66b7c5e0fb44 100644
--- a/drivers/usb/musb/musb_gadget.h
+++ b/drivers/usb/musb/musb_gadget.h
@@ -35,13 +35,22 @@
35#ifndef __MUSB_GADGET_H 35#ifndef __MUSB_GADGET_H
36#define __MUSB_GADGET_H 36#define __MUSB_GADGET_H
37 37
38#include <linux/list.h>
39
40enum buffer_map_state {
41 UN_MAPPED = 0,
42 PRE_MAPPED,
43 MUSB_MAPPED
44};
45
38struct musb_request { 46struct musb_request {
39 struct usb_request request; 47 struct usb_request request;
48 struct list_head list;
40 struct musb_ep *ep; 49 struct musb_ep *ep;
41 struct musb *musb; 50 struct musb *musb;
42 u8 tx; /* endpoint direction */ 51 u8 tx; /* endpoint direction */
43 u8 epnum; 52 u8 epnum;
44 u8 mapped; 53 enum buffer_map_state map_state;
45}; 54};
46 55
47static inline struct musb_request *to_musb_request(struct usb_request *req) 56static inline struct musb_request *to_musb_request(struct usb_request *req)
@@ -79,6 +88,8 @@ struct musb_ep {
79 88
80 /* true if lock must be dropped but req_list may not be advanced */ 89 /* true if lock must be dropped but req_list may not be advanced */
81 u8 busy; 90 u8 busy;
91
92 u8 hb_mult;
82}; 93};
83 94
84static inline struct musb_ep *to_musb_ep(struct usb_ep *ep) 95static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
@@ -86,13 +97,13 @@ static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
86 return ep ? container_of(ep, struct musb_ep, end_point) : NULL; 97 return ep ? container_of(ep, struct musb_ep, end_point) : NULL;
87} 98}
88 99
89static inline struct usb_request *next_request(struct musb_ep *ep) 100static inline struct musb_request *next_request(struct musb_ep *ep)
90{ 101{
91 struct list_head *queue = &ep->req_list; 102 struct list_head *queue = &ep->req_list;
92 103
93 if (list_empty(queue)) 104 if (list_empty(queue))
94 return NULL; 105 return NULL;
95 return container_of(queue->next, struct usb_request, list); 106 return container_of(queue->next, struct musb_request, list);
96} 107}
97 108
98extern void musb_g_tx(struct musb *musb, u8 epnum); 109extern void musb_g_tx(struct musb *musb, u8 epnum);
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 6dd03f4c5f49..b2faff235507 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -209,7 +209,7 @@ static inline void musb_try_b_hnp_enable(struct musb *musb)
209 void __iomem *mbase = musb->mregs; 209 void __iomem *mbase = musb->mregs;
210 u8 devctl; 210 u8 devctl;
211 211
212 DBG(1, "HNP: Setting HR\n"); 212 dev_dbg(musb->controller, "HNP: Setting HR\n");
213 devctl = musb_readb(mbase, MUSB_DEVCTL); 213 devctl = musb_readb(mbase, MUSB_DEVCTL);
214 musb_writeb(mbase, MUSB_DEVCTL, devctl | MUSB_DEVCTL_HR); 214 musb_writeb(mbase, MUSB_DEVCTL, devctl | MUSB_DEVCTL_HR);
215} 215}
@@ -304,10 +304,9 @@ __acquires(musb->lock)
304 } 304 }
305 305
306 /* Maybe start the first request in the queue */ 306 /* Maybe start the first request in the queue */
307 request = to_musb_request( 307 request = next_request(musb_ep);
308 next_request(musb_ep));
309 if (!musb_ep->busy && request) { 308 if (!musb_ep->busy && request) {
310 DBG(3, "restarting the request\n"); 309 dev_dbg(musb->controller, "restarting the request\n");
311 musb_ep_restart(musb, request); 310 musb_ep_restart(musb, request);
312 } 311 }
313 312
@@ -491,10 +490,12 @@ stall:
491static void ep0_rxstate(struct musb *musb) 490static void ep0_rxstate(struct musb *musb)
492{ 491{
493 void __iomem *regs = musb->control_ep->regs; 492 void __iomem *regs = musb->control_ep->regs;
493 struct musb_request *request;
494 struct usb_request *req; 494 struct usb_request *req;
495 u16 count, csr; 495 u16 count, csr;
496 496
497 req = next_ep0_request(musb); 497 request = next_ep0_request(musb);
498 req = &request->request;
498 499
499 /* read packet and ack; or stall because of gadget driver bug: 500 /* read packet and ack; or stall because of gadget driver bug:
500 * should have provided the rx buffer before setup() returned. 501 * should have provided the rx buffer before setup() returned.
@@ -544,17 +545,20 @@ static void ep0_rxstate(struct musb *musb)
544static void ep0_txstate(struct musb *musb) 545static void ep0_txstate(struct musb *musb)
545{ 546{
546 void __iomem *regs = musb->control_ep->regs; 547 void __iomem *regs = musb->control_ep->regs;
547 struct usb_request *request = next_ep0_request(musb); 548 struct musb_request *req = next_ep0_request(musb);
549 struct usb_request *request;
548 u16 csr = MUSB_CSR0_TXPKTRDY; 550 u16 csr = MUSB_CSR0_TXPKTRDY;
549 u8 *fifo_src; 551 u8 *fifo_src;
550 u8 fifo_count; 552 u8 fifo_count;
551 553
552 if (!request) { 554 if (!req) {
553 /* WARN_ON(1); */ 555 /* WARN_ON(1); */
554 DBG(2, "odd; csr0 %04x\n", musb_readw(regs, MUSB_CSR0)); 556 dev_dbg(musb->controller, "odd; csr0 %04x\n", musb_readw(regs, MUSB_CSR0));
555 return; 557 return;
556 } 558 }
557 559
560 request = &req->request;
561
558 /* load the data */ 562 /* load the data */
559 fifo_src = (u8 *) request->buf + request->actual; 563 fifo_src = (u8 *) request->buf + request->actual;
560 fifo_count = min((unsigned) MUSB_EP0_FIFOSIZE, 564 fifo_count = min((unsigned) MUSB_EP0_FIFOSIZE,
@@ -598,7 +602,7 @@ static void ep0_txstate(struct musb *musb)
598static void 602static void
599musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req) 603musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req)
600{ 604{
601 struct usb_request *r; 605 struct musb_request *r;
602 void __iomem *regs = musb->control_ep->regs; 606 void __iomem *regs = musb->control_ep->regs;
603 607
604 musb_read_fifo(&musb->endpoints[0], sizeof *req, (u8 *)req); 608 musb_read_fifo(&musb->endpoints[0], sizeof *req, (u8 *)req);
@@ -606,7 +610,7 @@ musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req)
606 /* NOTE: earlier 2.6 versions changed setup packets to host 610 /* NOTE: earlier 2.6 versions changed setup packets to host
607 * order, but now USB packets always stay in USB byte order. 611 * order, but now USB packets always stay in USB byte order.
608 */ 612 */
609 DBG(3, "SETUP req%02x.%02x v%04x i%04x l%d\n", 613 dev_dbg(musb->controller, "SETUP req%02x.%02x v%04x i%04x l%d\n",
610 req->bRequestType, 614 req->bRequestType,
611 req->bRequest, 615 req->bRequest,
612 le16_to_cpu(req->wValue), 616 le16_to_cpu(req->wValue),
@@ -616,7 +620,7 @@ musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req)
616 /* clean up any leftover transfers */ 620 /* clean up any leftover transfers */
617 r = next_ep0_request(musb); 621 r = next_ep0_request(musb);
618 if (r) 622 if (r)
619 musb_g_ep0_giveback(musb, r); 623 musb_g_ep0_giveback(musb, &r->request);
620 624
621 /* For zero-data requests we want to delay the STATUS stage to 625 /* For zero-data requests we want to delay the STATUS stage to
622 * avoid SETUPEND errors. If we read data (OUT), delay accepting 626 * avoid SETUPEND errors. If we read data (OUT), delay accepting
@@ -674,7 +678,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *musb)
674 csr = musb_readw(regs, MUSB_CSR0); 678 csr = musb_readw(regs, MUSB_CSR0);
675 len = musb_readb(regs, MUSB_COUNT0); 679 len = musb_readb(regs, MUSB_COUNT0);
676 680
677 DBG(4, "csr %04x, count %d, myaddr %d, ep0stage %s\n", 681 dev_dbg(musb->controller, "csr %04x, count %d, myaddr %d, ep0stage %s\n",
678 csr, len, 682 csr, len,
679 musb_readb(mbase, MUSB_FADDR), 683 musb_readb(mbase, MUSB_FADDR),
680 decode_ep0stage(musb->ep0_state)); 684 decode_ep0stage(musb->ep0_state));
@@ -745,7 +749,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *musb)
745 749
746 /* enter test mode if needed (exit by reset) */ 750 /* enter test mode if needed (exit by reset) */
747 else if (musb->test_mode) { 751 else if (musb->test_mode) {
748 DBG(1, "entering TESTMODE\n"); 752 dev_dbg(musb->controller, "entering TESTMODE\n");
749 753
750 if (MUSB_TEST_PACKET == musb->test_mode_nr) 754 if (MUSB_TEST_PACKET == musb->test_mode_nr)
751 musb_load_testpacket(musb); 755 musb_load_testpacket(musb);
@@ -758,11 +762,11 @@ irqreturn_t musb_g_ep0_irq(struct musb *musb)
758 case MUSB_EP0_STAGE_STATUSOUT: 762 case MUSB_EP0_STAGE_STATUSOUT:
759 /* end of sequence #1: write to host (TX state) */ 763 /* end of sequence #1: write to host (TX state) */
760 { 764 {
761 struct usb_request *req; 765 struct musb_request *req;
762 766
763 req = next_ep0_request(musb); 767 req = next_ep0_request(musb);
764 if (req) 768 if (req)
765 musb_g_ep0_giveback(musb, req); 769 musb_g_ep0_giveback(musb, &req->request);
766 } 770 }
767 771
768 /* 772 /*
@@ -857,7 +861,7 @@ setup:
857 break; 861 break;
858 } 862 }
859 863
860 DBG(3, "handled %d, csr %04x, ep0stage %s\n", 864 dev_dbg(musb->controller, "handled %d, csr %04x, ep0stage %s\n",
861 handled, csr, 865 handled, csr,
862 decode_ep0stage(musb->ep0_state)); 866 decode_ep0stage(musb->ep0_state));
863 867
@@ -874,7 +878,7 @@ setup:
874 if (handled < 0) { 878 if (handled < 0) {
875 musb_ep_select(mbase, 0); 879 musb_ep_select(mbase, 0);
876stall: 880stall:
877 DBG(3, "stall (%d)\n", handled); 881 dev_dbg(musb->controller, "stall (%d)\n", handled);
878 musb->ackpend |= MUSB_CSR0_P_SENDSTALL; 882 musb->ackpend |= MUSB_CSR0_P_SENDSTALL;
879 musb->ep0_state = MUSB_EP0_STAGE_IDLE; 883 musb->ep0_state = MUSB_EP0_STAGE_IDLE;
880finish: 884finish:
@@ -954,16 +958,16 @@ musb_g_ep0_queue(struct usb_ep *e, struct usb_request *r, gfp_t gfp_flags)
954 status = 0; 958 status = 0;
955 break; 959 break;
956 default: 960 default:
957 DBG(1, "ep0 request queued in state %d\n", 961 dev_dbg(musb->controller, "ep0 request queued in state %d\n",
958 musb->ep0_state); 962 musb->ep0_state);
959 status = -EINVAL; 963 status = -EINVAL;
960 goto cleanup; 964 goto cleanup;
961 } 965 }
962 966
963 /* add request to the list */ 967 /* add request to the list */
964 list_add_tail(&(req->request.list), &(ep->req_list)); 968 list_add_tail(&req->list, &ep->req_list);
965 969
966 DBG(3, "queue to %s (%s), length=%d\n", 970 dev_dbg(musb->controller, "queue to %s (%s), length=%d\n",
967 ep->name, ep->is_in ? "IN/TX" : "OUT/RX", 971 ep->name, ep->is_in ? "IN/TX" : "OUT/RX",
968 req->request.length); 972 req->request.length);
969 973
@@ -1056,7 +1060,7 @@ static int musb_g_ep0_halt(struct usb_ep *e, int value)
1056 musb->ackpend = 0; 1060 musb->ackpend = 0;
1057 break; 1061 break;
1058 default: 1062 default:
1059 DBG(1, "ep0 can't halt in state %d\n", musb->ep0_state); 1063 dev_dbg(musb->controller, "ep0 can't halt in state %d\n", musb->ep0_state);
1060 status = -EINVAL; 1064 status = -EINVAL;
1061 } 1065 }
1062 1066
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 9e65c47cc98b..8b2473fa0f47 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -41,6 +41,7 @@
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/list.h> 43#include <linux/list.h>
44#include <linux/dma-mapping.h>
44 45
45#include "musb_core.h" 46#include "musb_core.h"
46#include "musb_host.h" 47#include "musb_host.h"
@@ -105,6 +106,7 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
105 */ 106 */
106static void musb_h_tx_flush_fifo(struct musb_hw_ep *ep) 107static void musb_h_tx_flush_fifo(struct musb_hw_ep *ep)
107{ 108{
109 struct musb *musb = ep->musb;
108 void __iomem *epio = ep->regs; 110 void __iomem *epio = ep->regs;
109 u16 csr; 111 u16 csr;
110 u16 lastcsr = 0; 112 u16 lastcsr = 0;
@@ -113,7 +115,7 @@ static void musb_h_tx_flush_fifo(struct musb_hw_ep *ep)
113 csr = musb_readw(epio, MUSB_TXCSR); 115 csr = musb_readw(epio, MUSB_TXCSR);
114 while (csr & MUSB_TXCSR_FIFONOTEMPTY) { 116 while (csr & MUSB_TXCSR_FIFONOTEMPTY) {
115 if (csr != lastcsr) 117 if (csr != lastcsr)
116 DBG(3, "Host TX FIFONOTEMPTY csr: %02x\n", csr); 118 dev_dbg(musb->controller, "Host TX FIFONOTEMPTY csr: %02x\n", csr);
117 lastcsr = csr; 119 lastcsr = csr;
118 csr |= MUSB_TXCSR_FLUSHFIFO; 120 csr |= MUSB_TXCSR_FLUSHFIFO;
119 musb_writew(epio, MUSB_TXCSR, csr); 121 musb_writew(epio, MUSB_TXCSR, csr);
@@ -239,7 +241,7 @@ musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh)
239 len = urb->transfer_buffer_length - urb->actual_length; 241 len = urb->transfer_buffer_length - urb->actual_length;
240 } 242 }
241 243
242 DBG(4, "qh %p urb %p dev%d ep%d%s%s, hw_ep %d, %p/%d\n", 244 dev_dbg(musb->controller, "qh %p urb %p dev%d ep%d%s%s, hw_ep %d, %p/%d\n",
243 qh, urb, address, qh->epnum, 245 qh, urb, address, qh->epnum,
244 is_in ? "in" : "out", 246 is_in ? "in" : "out",
245 ({char *s; switch (qh->type) { 247 ({char *s; switch (qh->type) {
@@ -262,7 +264,7 @@ musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh)
262 switch (qh->type) { 264 switch (qh->type) {
263 case USB_ENDPOINT_XFER_ISOC: 265 case USB_ENDPOINT_XFER_ISOC:
264 case USB_ENDPOINT_XFER_INT: 266 case USB_ENDPOINT_XFER_INT:
265 DBG(3, "check whether there's still time for periodic Tx\n"); 267 dev_dbg(musb->controller, "check whether there's still time for periodic Tx\n");
266 frame = musb_readw(mbase, MUSB_FRAME); 268 frame = musb_readw(mbase, MUSB_FRAME);
267 /* FIXME this doesn't implement that scheduling policy ... 269 /* FIXME this doesn't implement that scheduling policy ...
268 * or handle framecounter wrapping 270 * or handle framecounter wrapping
@@ -277,7 +279,7 @@ musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh)
277 } else { 279 } else {
278 qh->frame = urb->start_frame; 280 qh->frame = urb->start_frame;
279 /* enable SOF interrupt so we can count down */ 281 /* enable SOF interrupt so we can count down */
280 DBG(1, "SOF for %d\n", epnum); 282 dev_dbg(musb->controller, "SOF for %d\n", epnum);
281#if 1 /* ifndef CONFIG_ARCH_DAVINCI */ 283#if 1 /* ifndef CONFIG_ARCH_DAVINCI */
282 musb_writeb(mbase, MUSB_INTRUSBE, 0xff); 284 musb_writeb(mbase, MUSB_INTRUSBE, 0xff);
283#endif 285#endif
@@ -285,7 +287,7 @@ musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh)
285 break; 287 break;
286 default: 288 default:
287start: 289start:
288 DBG(4, "Start TX%d %s\n", epnum, 290 dev_dbg(musb->controller, "Start TX%d %s\n", epnum,
289 hw_ep->tx_channel ? "dma" : "pio"); 291 hw_ep->tx_channel ? "dma" : "pio");
290 292
291 if (!hw_ep->tx_channel) 293 if (!hw_ep->tx_channel)
@@ -300,21 +302,7 @@ static void musb_giveback(struct musb *musb, struct urb *urb, int status)
300__releases(musb->lock) 302__releases(musb->lock)
301__acquires(musb->lock) 303__acquires(musb->lock)
302{ 304{
303 DBG(({ int level; switch (status) { 305 dev_dbg(musb->controller,
304 case 0:
305 level = 4;
306 break;
307 /* common/boring faults */
308 case -EREMOTEIO:
309 case -ESHUTDOWN:
310 case -ECONNRESET:
311 case -EPIPE:
312 level = 3;
313 break;
314 default:
315 level = 2;
316 break;
317 }; level; }),
318 "complete %p %pF (%d), dev%d ep%d%s, %d/%d\n", 306 "complete %p %pF (%d), dev%d ep%d%s, %d/%d\n",
319 urb, urb->complete, status, 307 urb, urb->complete, status,
320 usb_pipedevice(urb->pipe), 308 usb_pipedevice(urb->pipe),
@@ -425,7 +413,7 @@ static void musb_advance_schedule(struct musb *musb, struct urb *urb,
425 } 413 }
426 414
427 if (qh != NULL && qh->is_ready) { 415 if (qh != NULL && qh->is_ready) {
428 DBG(4, "... next ep%d %cX urb %p\n", 416 dev_dbg(musb->controller, "... next ep%d %cX urb %p\n",
429 hw_ep->epnum, is_in ? 'R' : 'T', next_urb(qh)); 417 hw_ep->epnum, is_in ? 'R' : 'T', next_urb(qh));
430 musb_start_urb(musb, is_in, qh); 418 musb_start_urb(musb, is_in, qh);
431 } 419 }
@@ -470,7 +458,7 @@ musb_host_packet_rx(struct musb *musb, struct urb *urb, u8 epnum, u8 iso_err)
470 458
471 /* musb_ep_select(mbase, epnum); */ 459 /* musb_ep_select(mbase, epnum); */
472 rx_count = musb_readw(epio, MUSB_RXCOUNT); 460 rx_count = musb_readw(epio, MUSB_RXCOUNT);
473 DBG(3, "RX%d count %d, buffer %p len %d/%d\n", epnum, rx_count, 461 dev_dbg(musb->controller, "RX%d count %d, buffer %p len %d/%d\n", epnum, rx_count,
474 urb->transfer_buffer, qh->offset, 462 urb->transfer_buffer, qh->offset,
475 urb->transfer_buffer_length); 463 urb->transfer_buffer_length);
476 464
@@ -492,7 +480,7 @@ musb_host_packet_rx(struct musb *musb, struct urb *urb, u8 epnum, u8 iso_err)
492 status = -EOVERFLOW; 480 status = -EOVERFLOW;
493 urb->error_count++; 481 urb->error_count++;
494 } 482 }
495 DBG(2, "** OVERFLOW %d into %d\n", rx_count, length); 483 dev_dbg(musb->controller, "** OVERFLOW %d into %d\n", rx_count, length);
496 do_flush = 1; 484 do_flush = 1;
497 } else 485 } else
498 length = rx_count; 486 length = rx_count;
@@ -510,7 +498,7 @@ musb_host_packet_rx(struct musb *musb, struct urb *urb, u8 epnum, u8 iso_err)
510 if (rx_count > length) { 498 if (rx_count > length) {
511 if (urb->status == -EINPROGRESS) 499 if (urb->status == -EINPROGRESS)
512 urb->status = -EOVERFLOW; 500 urb->status = -EOVERFLOW;
513 DBG(2, "** OVERFLOW %d into %d\n", rx_count, length); 501 dev_dbg(musb->controller, "** OVERFLOW %d into %d\n", rx_count, length);
514 do_flush = 1; 502 do_flush = 1;
515 } else 503 } else
516 length = rx_count; 504 length = rx_count;
@@ -608,7 +596,7 @@ musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep)
608 /* Set RXMAXP with the FIFO size of the endpoint 596 /* Set RXMAXP with the FIFO size of the endpoint
609 * to disable double buffer mode. 597 * to disable double buffer mode.
610 */ 598 */
611 if (musb->hwvers < MUSB_HWVERS_2000) 599 if (musb->double_buffer_not_ok)
612 musb_writew(ep->regs, MUSB_RXMAXP, ep->max_packet_sz_rx); 600 musb_writew(ep->regs, MUSB_RXMAXP, ep->max_packet_sz_rx);
613 else 601 else
614 musb_writew(ep->regs, MUSB_RXMAXP, 602 musb_writew(ep->regs, MUSB_RXMAXP,
@@ -696,7 +684,7 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
696 struct musb_qh *qh = musb_ep_get_qh(hw_ep, !is_out); 684 struct musb_qh *qh = musb_ep_get_qh(hw_ep, !is_out);
697 u16 packet_sz = qh->maxpacket; 685 u16 packet_sz = qh->maxpacket;
698 686
699 DBG(3, "%s hw%d urb %p spd%d dev%d ep%d%s " 687 dev_dbg(musb->controller, "%s hw%d urb %p spd%d dev%d ep%d%s "
700 "h_addr%02x h_port%02x bytes %d\n", 688 "h_addr%02x h_port%02x bytes %d\n",
701 is_out ? "-->" : "<--", 689 is_out ? "-->" : "<--",
702 epnum, urb, urb->dev->speed, 690 epnum, urb, urb->dev->speed,
@@ -783,14 +771,13 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
783 /* protocol/endpoint/interval/NAKlimit */ 771 /* protocol/endpoint/interval/NAKlimit */
784 if (epnum) { 772 if (epnum) {
785 musb_writeb(epio, MUSB_TXTYPE, qh->type_reg); 773 musb_writeb(epio, MUSB_TXTYPE, qh->type_reg);
786 if (can_bulk_split(musb, qh->type)) 774 if (musb->double_buffer_not_ok)
787 musb_writew(epio, MUSB_TXMAXP, 775 musb_writew(epio, MUSB_TXMAXP,
788 packet_sz 776 hw_ep->max_packet_sz_tx);
789 | ((hw_ep->max_packet_sz_tx /
790 packet_sz) - 1) << 11);
791 else 777 else
792 musb_writew(epio, MUSB_TXMAXP, 778 musb_writew(epio, MUSB_TXMAXP,
793 packet_sz); 779 qh->maxpacket |
780 ((qh->hb_mult - 1) << 11));
794 musb_writeb(epio, MUSB_TXINTERVAL, qh->intv_reg); 781 musb_writeb(epio, MUSB_TXINTERVAL, qh->intv_reg);
795 } else { 782 } else {
796 musb_writeb(epio, MUSB_NAKLIMIT0, qh->intv_reg); 783 musb_writeb(epio, MUSB_NAKLIMIT0, qh->intv_reg);
@@ -850,37 +837,32 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
850 /* kick things off */ 837 /* kick things off */
851 838
852 if ((is_cppi_enabled() || tusb_dma_omap()) && dma_channel) { 839 if ((is_cppi_enabled() || tusb_dma_omap()) && dma_channel) {
853 /* candidate for DMA */ 840 /* Candidate for DMA */
854 if (dma_channel) { 841 dma_channel->actual_len = 0L;
855 dma_channel->actual_len = 0L; 842 qh->segsize = len;
856 qh->segsize = len; 843
857 844 /* AUTOREQ is in a DMA register */
858 /* AUTOREQ is in a DMA register */ 845 musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
859 musb_writew(hw_ep->regs, MUSB_RXCSR, csr); 846 csr = musb_readw(hw_ep->regs, MUSB_RXCSR);
860 csr = musb_readw(hw_ep->regs, 847
861 MUSB_RXCSR); 848 /*
862 849 * Unless caller treats short RX transfers as
863 /* unless caller treats short rx transfers as 850 * errors, we dare not queue multiple transfers.
864 * errors, we dare not queue multiple transfers. 851 */
865 */ 852 dma_ok = dma_controller->channel_program(dma_channel,
866 dma_ok = dma_controller->channel_program( 853 packet_sz, !(urb->transfer_flags &
867 dma_channel, packet_sz, 854 URB_SHORT_NOT_OK),
868 !(urb->transfer_flags 855 urb->transfer_dma + offset,
869 & URB_SHORT_NOT_OK), 856 qh->segsize);
870 urb->transfer_dma + offset, 857 if (!dma_ok) {
871 qh->segsize); 858 dma_controller->channel_release(dma_channel);
872 if (!dma_ok) { 859 hw_ep->rx_channel = dma_channel = NULL;
873 dma_controller->channel_release( 860 } else
874 dma_channel); 861 csr |= MUSB_RXCSR_DMAENAB;
875 hw_ep->rx_channel = NULL;
876 dma_channel = NULL;
877 } else
878 csr |= MUSB_RXCSR_DMAENAB;
879 }
880 } 862 }
881 863
882 csr |= MUSB_RXCSR_H_REQPKT; 864 csr |= MUSB_RXCSR_H_REQPKT;
883 DBG(7, "RXCSR%d := %04x\n", epnum, csr); 865 dev_dbg(musb->controller, "RXCSR%d := %04x\n", epnum, csr);
884 musb_writew(hw_ep->regs, MUSB_RXCSR, csr); 866 musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
885 csr = musb_readw(hw_ep->regs, MUSB_RXCSR); 867 csr = musb_readw(hw_ep->regs, MUSB_RXCSR);
886 } 868 }
@@ -923,15 +905,15 @@ static bool musb_h_ep0_continue(struct musb *musb, u16 len, struct urb *urb)
923 request = (struct usb_ctrlrequest *) urb->setup_packet; 905 request = (struct usb_ctrlrequest *) urb->setup_packet;
924 906
925 if (!request->wLength) { 907 if (!request->wLength) {
926 DBG(4, "start no-DATA\n"); 908 dev_dbg(musb->controller, "start no-DATA\n");
927 break; 909 break;
928 } else if (request->bRequestType & USB_DIR_IN) { 910 } else if (request->bRequestType & USB_DIR_IN) {
929 DBG(4, "start IN-DATA\n"); 911 dev_dbg(musb->controller, "start IN-DATA\n");
930 musb->ep0_stage = MUSB_EP0_IN; 912 musb->ep0_stage = MUSB_EP0_IN;
931 more = true; 913 more = true;
932 break; 914 break;
933 } else { 915 } else {
934 DBG(4, "start OUT-DATA\n"); 916 dev_dbg(musb->controller, "start OUT-DATA\n");
935 musb->ep0_stage = MUSB_EP0_OUT; 917 musb->ep0_stage = MUSB_EP0_OUT;
936 more = true; 918 more = true;
937 } 919 }
@@ -943,7 +925,7 @@ static bool musb_h_ep0_continue(struct musb *musb, u16 len, struct urb *urb)
943 if (fifo_count) { 925 if (fifo_count) {
944 fifo_dest = (u8 *) (urb->transfer_buffer 926 fifo_dest = (u8 *) (urb->transfer_buffer
945 + urb->actual_length); 927 + urb->actual_length);
946 DBG(3, "Sending %d byte%s to ep0 fifo %p\n", 928 dev_dbg(musb->controller, "Sending %d byte%s to ep0 fifo %p\n",
947 fifo_count, 929 fifo_count,
948 (fifo_count == 1) ? "" : "s", 930 (fifo_count == 1) ? "" : "s",
949 fifo_dest); 931 fifo_dest);
@@ -988,7 +970,7 @@ irqreturn_t musb_h_ep0_irq(struct musb *musb)
988 ? musb_readb(epio, MUSB_COUNT0) 970 ? musb_readb(epio, MUSB_COUNT0)
989 : 0; 971 : 0;
990 972
991 DBG(4, "<== csr0 %04x, qh %p, count %d, urb %p, stage %d\n", 973 dev_dbg(musb->controller, "<== csr0 %04x, qh %p, count %d, urb %p, stage %d\n",
992 csr, qh, len, urb, musb->ep0_stage); 974 csr, qh, len, urb, musb->ep0_stage);
993 975
994 /* if we just did status stage, we are done */ 976 /* if we just did status stage, we are done */
@@ -999,15 +981,15 @@ irqreturn_t musb_h_ep0_irq(struct musb *musb)
999 981
1000 /* prepare status */ 982 /* prepare status */
1001 if (csr & MUSB_CSR0_H_RXSTALL) { 983 if (csr & MUSB_CSR0_H_RXSTALL) {
1002 DBG(6, "STALLING ENDPOINT\n"); 984 dev_dbg(musb->controller, "STALLING ENDPOINT\n");
1003 status = -EPIPE; 985 status = -EPIPE;
1004 986
1005 } else if (csr & MUSB_CSR0_H_ERROR) { 987 } else if (csr & MUSB_CSR0_H_ERROR) {
1006 DBG(2, "no response, csr0 %04x\n", csr); 988 dev_dbg(musb->controller, "no response, csr0 %04x\n", csr);
1007 status = -EPROTO; 989 status = -EPROTO;
1008 990
1009 } else if (csr & MUSB_CSR0_H_NAKTIMEOUT) { 991 } else if (csr & MUSB_CSR0_H_NAKTIMEOUT) {
1010 DBG(2, "control NAK timeout\n"); 992 dev_dbg(musb->controller, "control NAK timeout\n");
1011 993
1012 /* NOTE: this code path would be a good place to PAUSE a 994 /* NOTE: this code path would be a good place to PAUSE a
1013 * control transfer, if another one is queued, so that 995 * control transfer, if another one is queued, so that
@@ -1022,7 +1004,7 @@ irqreturn_t musb_h_ep0_irq(struct musb *musb)
1022 } 1004 }
1023 1005
1024 if (status) { 1006 if (status) {
1025 DBG(6, "aborting\n"); 1007 dev_dbg(musb->controller, "aborting\n");
1026 retval = IRQ_HANDLED; 1008 retval = IRQ_HANDLED;
1027 if (urb) 1009 if (urb)
1028 urb->status = status; 1010 urb->status = status;
@@ -1072,7 +1054,7 @@ irqreturn_t musb_h_ep0_irq(struct musb *musb)
1072 /* flag status stage */ 1054 /* flag status stage */
1073 musb->ep0_stage = MUSB_EP0_STATUS; 1055 musb->ep0_stage = MUSB_EP0_STATUS;
1074 1056
1075 DBG(5, "ep0 STATUS, csr %04x\n", csr); 1057 dev_dbg(musb->controller, "ep0 STATUS, csr %04x\n", csr);
1076 1058
1077 } 1059 }
1078 musb_writew(epio, MUSB_CSR0, csr); 1060 musb_writew(epio, MUSB_CSR0, csr);
@@ -1119,37 +1101,38 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1119 u32 status = 0; 1101 u32 status = 0;
1120 void __iomem *mbase = musb->mregs; 1102 void __iomem *mbase = musb->mregs;
1121 struct dma_channel *dma; 1103 struct dma_channel *dma;
1104 bool transfer_pending = false;
1122 1105
1123 musb_ep_select(mbase, epnum); 1106 musb_ep_select(mbase, epnum);
1124 tx_csr = musb_readw(epio, MUSB_TXCSR); 1107 tx_csr = musb_readw(epio, MUSB_TXCSR);
1125 1108
1126 /* with CPPI, DMA sometimes triggers "extra" irqs */ 1109 /* with CPPI, DMA sometimes triggers "extra" irqs */
1127 if (!urb) { 1110 if (!urb) {
1128 DBG(4, "extra TX%d ready, csr %04x\n", epnum, tx_csr); 1111 dev_dbg(musb->controller, "extra TX%d ready, csr %04x\n", epnum, tx_csr);
1129 return; 1112 return;
1130 } 1113 }
1131 1114
1132 pipe = urb->pipe; 1115 pipe = urb->pipe;
1133 dma = is_dma_capable() ? hw_ep->tx_channel : NULL; 1116 dma = is_dma_capable() ? hw_ep->tx_channel : NULL;
1134 DBG(4, "OUT/TX%d end, csr %04x%s\n", epnum, tx_csr, 1117 dev_dbg(musb->controller, "OUT/TX%d end, csr %04x%s\n", epnum, tx_csr,
1135 dma ? ", dma" : ""); 1118 dma ? ", dma" : "");
1136 1119
1137 /* check for errors */ 1120 /* check for errors */
1138 if (tx_csr & MUSB_TXCSR_H_RXSTALL) { 1121 if (tx_csr & MUSB_TXCSR_H_RXSTALL) {
1139 /* dma was disabled, fifo flushed */ 1122 /* dma was disabled, fifo flushed */
1140 DBG(3, "TX end %d stall\n", epnum); 1123 dev_dbg(musb->controller, "TX end %d stall\n", epnum);
1141 1124
1142 /* stall; record URB status */ 1125 /* stall; record URB status */
1143 status = -EPIPE; 1126 status = -EPIPE;
1144 1127
1145 } else if (tx_csr & MUSB_TXCSR_H_ERROR) { 1128 } else if (tx_csr & MUSB_TXCSR_H_ERROR) {
1146 /* (NON-ISO) dma was disabled, fifo flushed */ 1129 /* (NON-ISO) dma was disabled, fifo flushed */
1147 DBG(3, "TX 3strikes on ep=%d\n", epnum); 1130 dev_dbg(musb->controller, "TX 3strikes on ep=%d\n", epnum);
1148 1131
1149 status = -ETIMEDOUT; 1132 status = -ETIMEDOUT;
1150 1133
1151 } else if (tx_csr & MUSB_TXCSR_H_NAKTIMEOUT) { 1134 } else if (tx_csr & MUSB_TXCSR_H_NAKTIMEOUT) {
1152 DBG(6, "TX end=%d device not responding\n", epnum); 1135 dev_dbg(musb->controller, "TX end=%d device not responding\n", epnum);
1153 1136
1154 /* NOTE: this code path would be a good place to PAUSE a 1137 /* NOTE: this code path would be a good place to PAUSE a
1155 * transfer, if there's some other (nonperiodic) tx urb 1138 * transfer, if there's some other (nonperiodic) tx urb
@@ -1194,7 +1177,7 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1194 1177
1195 /* second cppi case */ 1178 /* second cppi case */
1196 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { 1179 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
1197 DBG(4, "extra TX%d ready, csr %04x\n", epnum, tx_csr); 1180 dev_dbg(musb->controller, "extra TX%d ready, csr %04x\n", epnum, tx_csr);
1198 return; 1181 return;
1199 } 1182 }
1200 1183
@@ -1253,7 +1236,7 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1253 * FIFO mode too... 1236 * FIFO mode too...
1254 */ 1237 */
1255 if (tx_csr & (MUSB_TXCSR_FIFONOTEMPTY | MUSB_TXCSR_TXPKTRDY)) { 1238 if (tx_csr & (MUSB_TXCSR_FIFONOTEMPTY | MUSB_TXCSR_TXPKTRDY)) {
1256 DBG(2, "DMA complete but packet still in FIFO, " 1239 dev_dbg(musb->controller, "DMA complete but packet still in FIFO, "
1257 "CSR %04x\n", tx_csr); 1240 "CSR %04x\n", tx_csr);
1258 return; 1241 return;
1259 } 1242 }
@@ -1279,7 +1262,7 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1279 offset = d->offset; 1262 offset = d->offset;
1280 length = d->length; 1263 length = d->length;
1281 } 1264 }
1282 } else if (dma) { 1265 } else if (dma && urb->transfer_buffer_length == qh->offset) {
1283 done = true; 1266 done = true;
1284 } else { 1267 } else {
1285 /* see if we need to send more data, or ZLP */ 1268 /* see if we need to send more data, or ZLP */
@@ -1292,6 +1275,7 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1292 if (!done) { 1275 if (!done) {
1293 offset = qh->offset; 1276 offset = qh->offset;
1294 length = urb->transfer_buffer_length - offset; 1277 length = urb->transfer_buffer_length - offset;
1278 transfer_pending = true;
1295 } 1279 }
1296 } 1280 }
1297 } 1281 }
@@ -1311,7 +1295,7 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1311 urb->actual_length = qh->offset; 1295 urb->actual_length = qh->offset;
1312 musb_advance_schedule(musb, urb, hw_ep, USB_DIR_OUT); 1296 musb_advance_schedule(musb, urb, hw_ep, USB_DIR_OUT);
1313 return; 1297 return;
1314 } else if (usb_pipeisoc(pipe) && dma) { 1298 } else if ((usb_pipeisoc(pipe) || transfer_pending) && dma) {
1315 if (musb_tx_dma_program(musb->dma_controller, hw_ep, qh, urb, 1299 if (musb_tx_dma_program(musb->dma_controller, hw_ep, qh, urb,
1316 offset, length)) { 1300 offset, length)) {
1317 if (is_cppi_enabled() || tusb_dma_omap()) 1301 if (is_cppi_enabled() || tusb_dma_omap())
@@ -1319,7 +1303,7 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1319 return; 1303 return;
1320 } 1304 }
1321 } else if (tx_csr & MUSB_TXCSR_DMAENAB) { 1305 } else if (tx_csr & MUSB_TXCSR_DMAENAB) {
1322 DBG(1, "not complete, but DMA enabled?\n"); 1306 dev_dbg(musb->controller, "not complete, but DMA enabled?\n");
1323 return; 1307 return;
1324 } 1308 }
1325 1309
@@ -1332,6 +1316,8 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1332 */ 1316 */
1333 if (length > qh->maxpacket) 1317 if (length > qh->maxpacket)
1334 length = qh->maxpacket; 1318 length = qh->maxpacket;
1319 /* Unmap the buffer so that CPU can use it */
1320 usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb);
1335 musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset); 1321 musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset);
1336 qh->segsize = length; 1322 qh->segsize = length;
1337 1323
@@ -1458,7 +1444,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1458 * usbtest #11 (unlinks) triggers it regularly, sometimes 1444 * usbtest #11 (unlinks) triggers it regularly, sometimes
1459 * with fifo full. (Only with DMA??) 1445 * with fifo full. (Only with DMA??)
1460 */ 1446 */
1461 DBG(3, "BOGUS RX%d ready, csr %04x, count %d\n", epnum, val, 1447 dev_dbg(musb->controller, "BOGUS RX%d ready, csr %04x, count %d\n", epnum, val,
1462 musb_readw(epio, MUSB_RXCOUNT)); 1448 musb_readw(epio, MUSB_RXCOUNT));
1463 musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG); 1449 musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG);
1464 return; 1450 return;
@@ -1466,20 +1452,20 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1466 1452
1467 pipe = urb->pipe; 1453 pipe = urb->pipe;
1468 1454
1469 DBG(5, "<== hw %d rxcsr %04x, urb actual %d (+dma %zu)\n", 1455 dev_dbg(musb->controller, "<== hw %d rxcsr %04x, urb actual %d (+dma %zu)\n",
1470 epnum, rx_csr, urb->actual_length, 1456 epnum, rx_csr, urb->actual_length,
1471 dma ? dma->actual_len : 0); 1457 dma ? dma->actual_len : 0);
1472 1458
1473 /* check for errors, concurrent stall & unlink is not really 1459 /* check for errors, concurrent stall & unlink is not really
1474 * handled yet! */ 1460 * handled yet! */
1475 if (rx_csr & MUSB_RXCSR_H_RXSTALL) { 1461 if (rx_csr & MUSB_RXCSR_H_RXSTALL) {
1476 DBG(3, "RX end %d STALL\n", epnum); 1462 dev_dbg(musb->controller, "RX end %d STALL\n", epnum);
1477 1463
1478 /* stall; record URB status */ 1464 /* stall; record URB status */
1479 status = -EPIPE; 1465 status = -EPIPE;
1480 1466
1481 } else if (rx_csr & MUSB_RXCSR_H_ERROR) { 1467 } else if (rx_csr & MUSB_RXCSR_H_ERROR) {
1482 DBG(3, "end %d RX proto error\n", epnum); 1468 dev_dbg(musb->controller, "end %d RX proto error\n", epnum);
1483 1469
1484 status = -EPROTO; 1470 status = -EPROTO;
1485 musb_writeb(epio, MUSB_RXINTERVAL, 0); 1471 musb_writeb(epio, MUSB_RXINTERVAL, 0);
@@ -1487,7 +1473,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1487 } else if (rx_csr & MUSB_RXCSR_DATAERROR) { 1473 } else if (rx_csr & MUSB_RXCSR_DATAERROR) {
1488 1474
1489 if (USB_ENDPOINT_XFER_ISOC != qh->type) { 1475 if (USB_ENDPOINT_XFER_ISOC != qh->type) {
1490 DBG(6, "RX end %d NAK timeout\n", epnum); 1476 dev_dbg(musb->controller, "RX end %d NAK timeout\n", epnum);
1491 1477
1492 /* NOTE: NAKing is *NOT* an error, so we want to 1478 /* NOTE: NAKing is *NOT* an error, so we want to
1493 * continue. Except ... if there's a request for 1479 * continue. Except ... if there's a request for
@@ -1510,12 +1496,12 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1510 1496
1511 goto finish; 1497 goto finish;
1512 } else { 1498 } else {
1513 DBG(4, "RX end %d ISO data error\n", epnum); 1499 dev_dbg(musb->controller, "RX end %d ISO data error\n", epnum);
1514 /* packet error reported later */ 1500 /* packet error reported later */
1515 iso_err = true; 1501 iso_err = true;
1516 } 1502 }
1517 } else if (rx_csr & MUSB_RXCSR_INCOMPRX) { 1503 } else if (rx_csr & MUSB_RXCSR_INCOMPRX) {
1518 DBG(3, "end %d high bandwidth incomplete ISO packet RX\n", 1504 dev_dbg(musb->controller, "end %d high bandwidth incomplete ISO packet RX\n",
1519 epnum); 1505 epnum);
1520 status = -EPROTO; 1506 status = -EPROTO;
1521 } 1507 }
@@ -1561,7 +1547,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1561 done = true; 1547 done = true;
1562 } 1548 }
1563 1549
1564 DBG(2, "RXCSR%d %04x, reqpkt, len %zu%s\n", epnum, rx_csr, 1550 dev_dbg(musb->controller, "RXCSR%d %04x, reqpkt, len %zu%s\n", epnum, rx_csr,
1565 xfer_len, dma ? ", dma" : ""); 1551 xfer_len, dma ? ", dma" : "");
1566 rx_csr &= ~MUSB_RXCSR_H_REQPKT; 1552 rx_csr &= ~MUSB_RXCSR_H_REQPKT;
1567 1553
@@ -1589,7 +1575,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1589 /* even if there was an error, we did the dma 1575 /* even if there was an error, we did the dma
1590 * for iso_frame_desc->length 1576 * for iso_frame_desc->length
1591 */ 1577 */
1592 if (d->status != EILSEQ && d->status != -EOVERFLOW) 1578 if (d->status != -EILSEQ && d->status != -EOVERFLOW)
1593 d->status = 0; 1579 d->status = 0;
1594 1580
1595 if (++qh->iso_idx >= urb->number_of_packets) 1581 if (++qh->iso_idx >= urb->number_of_packets)
@@ -1611,7 +1597,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1611 MUSB_RXCSR_H_WZC_BITS | val); 1597 MUSB_RXCSR_H_WZC_BITS | val);
1612 } 1598 }
1613 1599
1614 DBG(4, "ep %d dma %s, rxcsr %04x, rxcount %d\n", epnum, 1600 dev_dbg(musb->controller, "ep %d dma %s, rxcsr %04x, rxcount %d\n", epnum,
1615 done ? "off" : "reset", 1601 done ? "off" : "reset",
1616 musb_readw(epio, MUSB_RXCSR), 1602 musb_readw(epio, MUSB_RXCSR),
1617 musb_readw(epio, MUSB_RXCOUNT)); 1603 musb_readw(epio, MUSB_RXCOUNT));
@@ -1644,7 +1630,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1644 1630
1645 rx_count = musb_readw(epio, MUSB_RXCOUNT); 1631 rx_count = musb_readw(epio, MUSB_RXCOUNT);
1646 1632
1647 DBG(2, "RX%d count %d, buffer 0x%x len %d/%d\n", 1633 dev_dbg(musb->controller, "RX%d count %d, buffer 0x%x len %d/%d\n",
1648 epnum, rx_count, 1634 epnum, rx_count,
1649 urb->transfer_dma 1635 urb->transfer_dma
1650 + urb->actual_length, 1636 + urb->actual_length,
@@ -1668,7 +1654,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1668 d_status = -EOVERFLOW; 1654 d_status = -EOVERFLOW;
1669 urb->error_count++; 1655 urb->error_count++;
1670 } 1656 }
1671 DBG(2, "** OVERFLOW %d into %d\n",\ 1657 dev_dbg(musb->controller, "** OVERFLOW %d into %d\n",\
1672 rx_count, d->length); 1658 rx_count, d->length);
1673 1659
1674 length = d->length; 1660 length = d->length;
@@ -1752,9 +1738,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1752#endif /* Mentor DMA */ 1738#endif /* Mentor DMA */
1753 1739
1754 if (!dma) { 1740 if (!dma) {
1741 /* Unmap the buffer so that CPU can use it */
1742 usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb);
1755 done = musb_host_packet_rx(musb, urb, 1743 done = musb_host_packet_rx(musb, urb,
1756 epnum, iso_err); 1744 epnum, iso_err);
1757 DBG(6, "read %spacket\n", done ? "last " : ""); 1745 dev_dbg(musb->controller, "read %spacket\n", done ? "last " : "");
1758 } 1746 }
1759 } 1747 }
1760 1748
@@ -1875,7 +1863,7 @@ static int musb_schedule(
1875 idle = 1; 1863 idle = 1;
1876 qh->mux = 0; 1864 qh->mux = 0;
1877 hw_ep = musb->endpoints + best_end; 1865 hw_ep = musb->endpoints + best_end;
1878 DBG(4, "qh %p periodic slot %d\n", qh, best_end); 1866 dev_dbg(musb->controller, "qh %p periodic slot %d\n", qh, best_end);
1879success: 1867success:
1880 if (head) { 1868 if (head) {
1881 idle = list_empty(head); 1869 idle = list_empty(head);
@@ -2081,6 +2069,7 @@ done:
2081static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh) 2069static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh)
2082{ 2070{
2083 struct musb_hw_ep *ep = qh->hw_ep; 2071 struct musb_hw_ep *ep = qh->hw_ep;
2072 struct musb *musb = ep->musb;
2084 void __iomem *epio = ep->regs; 2073 void __iomem *epio = ep->regs;
2085 unsigned hw_end = ep->epnum; 2074 unsigned hw_end = ep->epnum;
2086 void __iomem *regs = ep->musb->mregs; 2075 void __iomem *regs = ep->musb->mregs;
@@ -2096,7 +2085,7 @@ static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh)
2096 dma = is_in ? ep->rx_channel : ep->tx_channel; 2085 dma = is_in ? ep->rx_channel : ep->tx_channel;
2097 if (dma) { 2086 if (dma) {
2098 status = ep->musb->dma_controller->channel_abort(dma); 2087 status = ep->musb->dma_controller->channel_abort(dma);
2099 DBG(status ? 1 : 3, 2088 dev_dbg(musb->controller,
2100 "abort %cX%d DMA for urb %p --> %d\n", 2089 "abort %cX%d DMA for urb %p --> %d\n",
2101 is_in ? 'R' : 'T', ep->epnum, 2090 is_in ? 'R' : 'T', ep->epnum,
2102 urb, status); 2091 urb, status);
@@ -2143,7 +2132,7 @@ static int musb_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2143 int is_in = usb_pipein(urb->pipe); 2132 int is_in = usb_pipein(urb->pipe);
2144 int ret; 2133 int ret;
2145 2134
2146 DBG(4, "urb=%p, dev%d ep%d%s\n", urb, 2135 dev_dbg(musb->controller, "urb=%p, dev%d ep%d%s\n", urb,
2147 usb_pipedevice(urb->pipe), 2136 usb_pipedevice(urb->pipe),
2148 usb_pipeendpoint(urb->pipe), 2137 usb_pipeendpoint(urb->pipe),
2149 is_in ? "in" : "out"); 2138 is_in ? "in" : "out");
@@ -2298,7 +2287,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd)
2298 2287
2299 if (musb->is_active) { 2288 if (musb->is_active) {
2300 WARNING("trying to suspend as %s while active\n", 2289 WARNING("trying to suspend as %s while active\n",
2301 otg_state_string(musb)); 2290 otg_state_string(musb->xceiv->state));
2302 return -EBUSY; 2291 return -EBUSY;
2303 } else 2292 } else
2304 return 0; 2293 return 0;
diff --git a/drivers/usb/musb/musb_io.h b/drivers/usb/musb/musb_io.h
index b06e9ef00cfc..03c6ccdbb3be 100644
--- a/drivers/usb/musb/musb_io.h
+++ b/drivers/usb/musb/musb_io.h
@@ -74,7 +74,7 @@ static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
74 { __raw_writel(data, addr + offset); } 74 { __raw_writel(data, addr + offset); }
75 75
76 76
77#ifdef CONFIG_USB_TUSB6010 77#ifdef CONFIG_USB_MUSB_TUSB6010
78 78
79/* 79/*
80 * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum. 80 * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
@@ -114,7 +114,7 @@ static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
114static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data) 114static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
115 { __raw_writeb(data, addr + offset); } 115 { __raw_writeb(data, addr + offset); }
116 116
117#endif /* CONFIG_USB_TUSB6010 */ 117#endif /* CONFIG_USB_MUSB_TUSB6010 */
118 118
119#else 119#else
120 120
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h
index 244267527a60..82410703dcd3 100644
--- a/drivers/usb/musb/musb_regs.h
+++ b/drivers/usb/musb/musb_regs.h
@@ -234,7 +234,7 @@
234#define MUSB_TESTMODE 0x0F /* 8 bit */ 234#define MUSB_TESTMODE 0x0F /* 8 bit */
235 235
236/* Get offset for a given FIFO from musb->mregs */ 236/* Get offset for a given FIFO from musb->mregs */
237#ifdef CONFIG_USB_TUSB6010 237#ifdef CONFIG_USB_MUSB_TUSB6010
238#define MUSB_FIFO_OFFSET(epnum) (0x200 + ((epnum) * 0x20)) 238#define MUSB_FIFO_OFFSET(epnum) (0x200 + ((epnum) * 0x20))
239#else 239#else
240#define MUSB_FIFO_OFFSET(epnum) (0x20 + ((epnum) * 4)) 240#define MUSB_FIFO_OFFSET(epnum) (0x20 + ((epnum) * 4))
@@ -295,7 +295,7 @@
295#define MUSB_FLAT_OFFSET(_epnum, _offset) \ 295#define MUSB_FLAT_OFFSET(_epnum, _offset) \
296 (0x100 + (0x10*(_epnum)) + (_offset)) 296 (0x100 + (0x10*(_epnum)) + (_offset))
297 297
298#ifdef CONFIG_USB_TUSB6010 298#ifdef CONFIG_USB_MUSB_TUSB6010
299/* TUSB6010 EP0 configuration register is special */ 299/* TUSB6010 EP0 configuration register is special */
300#define MUSB_TUSB_OFFSET(_epnum, _offset) \ 300#define MUSB_TUSB_OFFSET(_epnum, _offset) \
301 (0x10 + _offset) 301 (0x10 + _offset)
@@ -633,8 +633,9 @@ static inline u8 musb_read_txhubaddr(void __iomem *mbase, u8 epnum)
633 return 0; 633 return 0;
634} 634}
635 635
636static inline void musb_read_txhubport(void __iomem *mbase, u8 epnum) 636static inline u8 musb_read_txhubport(void __iomem *mbase, u8 epnum)
637{ 637{
638 return 0;
638} 639}
639 640
640#endif /* CONFIG_BLACKFIN */ 641#endif /* CONFIG_BLACKFIN */
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index 43233c397b6e..2d80a5758838 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -74,7 +74,7 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend)
74 break; 74 break;
75 } 75 }
76 76
77 DBG(3, "Root port suspended, power %02x\n", power); 77 dev_dbg(musb->controller, "Root port suspended, power %02x\n", power);
78 78
79 musb->port1_status |= USB_PORT_STAT_SUSPEND; 79 musb->port1_status |= USB_PORT_STAT_SUSPEND;
80 switch (musb->xceiv->state) { 80 switch (musb->xceiv->state) {
@@ -97,15 +97,15 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend)
97 break; 97 break;
98#endif 98#endif
99 default: 99 default:
100 DBG(1, "bogus rh suspend? %s\n", 100 dev_dbg(musb->controller, "bogus rh suspend? %s\n",
101 otg_state_string(musb)); 101 otg_state_string(musb->xceiv->state));
102 } 102 }
103 } else if (power & MUSB_POWER_SUSPENDM) { 103 } else if (power & MUSB_POWER_SUSPENDM) {
104 power &= ~MUSB_POWER_SUSPENDM; 104 power &= ~MUSB_POWER_SUSPENDM;
105 power |= MUSB_POWER_RESUME; 105 power |= MUSB_POWER_RESUME;
106 musb_writeb(mbase, MUSB_POWER, power); 106 musb_writeb(mbase, MUSB_POWER, power);
107 107
108 DBG(3, "Root port resuming, power %02x\n", power); 108 dev_dbg(musb->controller, "Root port resuming, power %02x\n", power);
109 109
110 /* later, GetPortStatus will stop RESUME signaling */ 110 /* later, GetPortStatus will stop RESUME signaling */
111 musb->port1_status |= MUSB_PORT_STAT_RESUME; 111 musb->port1_status |= MUSB_PORT_STAT_RESUME;
@@ -120,7 +120,7 @@ static void musb_port_reset(struct musb *musb, bool do_reset)
120 120
121#ifdef CONFIG_USB_MUSB_OTG 121#ifdef CONFIG_USB_MUSB_OTG
122 if (musb->xceiv->state == OTG_STATE_B_IDLE) { 122 if (musb->xceiv->state == OTG_STATE_B_IDLE) {
123 DBG(2, "HNP: Returning from HNP; no hub reset from b_idle\n"); 123 dev_dbg(musb->controller, "HNP: Returning from HNP; no hub reset from b_idle\n");
124 musb->port1_status &= ~USB_PORT_STAT_RESET; 124 musb->port1_status &= ~USB_PORT_STAT_RESET;
125 return; 125 return;
126 } 126 }
@@ -159,7 +159,7 @@ static void musb_port_reset(struct musb *musb, bool do_reset)
159 musb->port1_status &= ~USB_PORT_STAT_ENABLE; 159 musb->port1_status &= ~USB_PORT_STAT_ENABLE;
160 musb->rh_timer = jiffies + msecs_to_jiffies(50); 160 musb->rh_timer = jiffies + msecs_to_jiffies(50);
161 } else { 161 } else {
162 DBG(4, "root port reset stopped\n"); 162 dev_dbg(musb->controller, "root port reset stopped\n");
163 musb_writeb(mbase, MUSB_POWER, 163 musb_writeb(mbase, MUSB_POWER,
164 power & ~MUSB_POWER_RESET); 164 power & ~MUSB_POWER_RESET);
165 165
@@ -167,7 +167,7 @@ static void musb_port_reset(struct musb *musb, bool do_reset)
167 167
168 power = musb_readb(mbase, MUSB_POWER); 168 power = musb_readb(mbase, MUSB_POWER);
169 if (power & MUSB_POWER_HSMODE) { 169 if (power & MUSB_POWER_HSMODE) {
170 DBG(4, "high-speed device connected\n"); 170 dev_dbg(musb->controller, "high-speed device connected\n");
171 musb->port1_status |= USB_PORT_STAT_HIGH_SPEED; 171 musb->port1_status |= USB_PORT_STAT_HIGH_SPEED;
172 } 172 }
173 173
@@ -208,7 +208,8 @@ void musb_root_disconnect(struct musb *musb)
208 musb->xceiv->state = OTG_STATE_B_IDLE; 208 musb->xceiv->state = OTG_STATE_B_IDLE;
209 break; 209 break;
210 default: 210 default:
211 DBG(1, "host disconnect (%s)\n", otg_state_string(musb)); 211 dev_dbg(musb->controller, "host disconnect (%s)\n",
212 otg_state_string(musb->xceiv->state));
212 } 213 }
213} 214}
214 215
@@ -276,7 +277,7 @@ int musb_hub_control(
276 break; 277 break;
277 case USB_PORT_FEAT_POWER: 278 case USB_PORT_FEAT_POWER:
278 if (!(is_otg_enabled(musb) && hcd->self.is_b_host)) 279 if (!(is_otg_enabled(musb) && hcd->self.is_b_host))
279 musb_set_vbus(musb, 0); 280 musb_platform_set_vbus(musb, 0);
280 break; 281 break;
281 case USB_PORT_FEAT_C_CONNECTION: 282 case USB_PORT_FEAT_C_CONNECTION:
282 case USB_PORT_FEAT_C_ENABLE: 283 case USB_PORT_FEAT_C_ENABLE:
@@ -287,7 +288,7 @@ int musb_hub_control(
287 default: 288 default:
288 goto error; 289 goto error;
289 } 290 }
290 DBG(5, "clear feature %d\n", wValue); 291 dev_dbg(musb->controller, "clear feature %d\n", wValue);
291 musb->port1_status &= ~(1 << wValue); 292 musb->port1_status &= ~(1 << wValue);
292 break; 293 break;
293 case GetHubDescriptor: 294 case GetHubDescriptor:
@@ -305,8 +306,8 @@ int musb_hub_control(
305 desc->bHubContrCurrent = 0; 306 desc->bHubContrCurrent = 0;
306 307
307 /* workaround bogus struct definition */ 308 /* workaround bogus struct definition */
308 desc->DeviceRemovable[0] = 0x02; /* port 1 */ 309 desc->u.hs.DeviceRemovable[0] = 0x02; /* port 1 */
309 desc->DeviceRemovable[1] = 0xff; 310 desc->u.hs.DeviceRemovable[1] = 0xff;
310 } 311 }
311 break; 312 break;
312 case GetHubStatus: 313 case GetHubStatus:
@@ -329,7 +330,7 @@ int musb_hub_control(
329 330
330 power = musb_readb(musb->mregs, MUSB_POWER); 331 power = musb_readb(musb->mregs, MUSB_POWER);
331 power &= ~MUSB_POWER_RESUME; 332 power &= ~MUSB_POWER_RESUME;
332 DBG(4, "root port resume stopped, power %02x\n", 333 dev_dbg(musb->controller, "root port resume stopped, power %02x\n",
333 power); 334 power);
334 musb_writeb(musb->mregs, MUSB_POWER, power); 335 musb_writeb(musb->mregs, MUSB_POWER, power);
335 336
@@ -352,7 +353,7 @@ int musb_hub_control(
352 (__le32 *) buf); 353 (__le32 *) buf);
353 354
354 /* port change status is more interesting */ 355 /* port change status is more interesting */
355 DBG(get_unaligned((u16 *)(buf+2)) ? 2 : 5, "port status %08x\n", 356 dev_dbg(musb->controller, "port status %08x\n",
356 musb->port1_status); 357 musb->port1_status);
357 break; 358 break;
358 case SetPortFeature: 359 case SetPortFeature:
@@ -423,7 +424,7 @@ int musb_hub_control(
423 default: 424 default:
424 goto error; 425 goto error;
425 } 426 }
426 DBG(5, "set feature %d\n", wValue); 427 dev_dbg(musb->controller, "set feature %d\n", wValue);
427 musb->port1_status |= 1 << wValue; 428 musb->port1_status |= 1 << wValue;
428 break; 429 break;
429 430
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index 6dc107f25245..f70c5a577736 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -91,7 +91,7 @@ static struct dma_channel *dma_channel_allocate(struct dma_controller *c,
91 channel = &(musb_channel->channel); 91 channel = &(musb_channel->channel);
92 channel->private_data = musb_channel; 92 channel->private_data = musb_channel;
93 channel->status = MUSB_DMA_STATUS_FREE; 93 channel->status = MUSB_DMA_STATUS_FREE;
94 channel->max_len = 0x10000; 94 channel->max_len = 0x100000;
95 /* Tx => mode 1; Rx => mode 0 */ 95 /* Tx => mode 1; Rx => mode 0 */
96 channel->desired_mode = transmit; 96 channel->desired_mode = transmit;
97 channel->actual_len = 0; 97 channel->actual_len = 0;
@@ -122,11 +122,12 @@ static void configure_channel(struct dma_channel *channel,
122{ 122{
123 struct musb_dma_channel *musb_channel = channel->private_data; 123 struct musb_dma_channel *musb_channel = channel->private_data;
124 struct musb_dma_controller *controller = musb_channel->controller; 124 struct musb_dma_controller *controller = musb_channel->controller;
125 struct musb *musb = controller->private_data;
125 void __iomem *mbase = controller->base; 126 void __iomem *mbase = controller->base;
126 u8 bchannel = musb_channel->idx; 127 u8 bchannel = musb_channel->idx;
127 u16 csr = 0; 128 u16 csr = 0;
128 129
129 DBG(4, "%p, pkt_sz %d, addr 0x%x, len %d, mode %d\n", 130 dev_dbg(musb->controller, "%p, pkt_sz %d, addr 0x%x, len %d, mode %d\n",
130 channel, packet_sz, dma_addr, len, mode); 131 channel, packet_sz, dma_addr, len, mode);
131 132
132 if (mode) { 133 if (mode) {
@@ -158,8 +159,10 @@ static int dma_channel_program(struct dma_channel *channel,
158 dma_addr_t dma_addr, u32 len) 159 dma_addr_t dma_addr, u32 len)
159{ 160{
160 struct musb_dma_channel *musb_channel = channel->private_data; 161 struct musb_dma_channel *musb_channel = channel->private_data;
162 struct musb_dma_controller *controller = musb_channel->controller;
163 struct musb *musb = controller->private_data;
161 164
162 DBG(2, "ep%d-%s pkt_sz %d, dma_addr 0x%x length %d, mode %d\n", 165 dev_dbg(musb->controller, "ep%d-%s pkt_sz %d, dma_addr 0x%x length %d, mode %d\n",
163 musb_channel->epnum, 166 musb_channel->epnum,
164 musb_channel->transmit ? "Tx" : "Rx", 167 musb_channel->transmit ? "Tx" : "Rx",
165 packet_sz, dma_addr, len, mode); 168 packet_sz, dma_addr, len, mode);
@@ -167,6 +170,26 @@ static int dma_channel_program(struct dma_channel *channel,
167 BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN || 170 BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN ||
168 channel->status == MUSB_DMA_STATUS_BUSY); 171 channel->status == MUSB_DMA_STATUS_BUSY);
169 172
173 /* Let targets check/tweak the arguments */
174 if (musb->ops->adjust_channel_params) {
175 int ret = musb->ops->adjust_channel_params(channel,
176 packet_sz, &mode, &dma_addr, &len);
177 if (ret)
178 return ret;
179 }
180
181 /*
182 * The DMA engine in RTL1.8 and above cannot handle
183 * DMA addresses that are not aligned to a 4 byte boundary.
184 * It ends up masking the last two bits of the address
185 * programmed in DMA_ADDR.
186 *
187 * Fail such DMA transfers, so that the backup PIO mode
188 * can carry out the transfer
189 */
190 if ((musb->hwvers >= MUSB_HWVERS_1800) && (dma_addr % 4))
191 return false;
192
170 channel->actual_len = 0; 193 channel->actual_len = 0;
171 musb_channel->start_addr = dma_addr; 194 musb_channel->start_addr = dma_addr;
172 musb_channel->len = len; 195 musb_channel->len = len;
@@ -252,7 +275,7 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data)
252#endif 275#endif
253 276
254 if (!int_hsdma) { 277 if (!int_hsdma) {
255 DBG(2, "spurious DMA irq\n"); 278 dev_dbg(musb->controller, "spurious DMA irq\n");
256 279
257 for (bchannel = 0; bchannel < MUSB_HSDMA_CHANNELS; bchannel++) { 280 for (bchannel = 0; bchannel < MUSB_HSDMA_CHANNELS; bchannel++) {
258 musb_channel = (struct musb_dma_channel *) 281 musb_channel = (struct musb_dma_channel *)
@@ -266,7 +289,7 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data)
266 } 289 }
267 } 290 }
268 291
269 DBG(2, "int_hsdma = 0x%x\n", int_hsdma); 292 dev_dbg(musb->controller, "int_hsdma = 0x%x\n", int_hsdma);
270 293
271 if (!int_hsdma) 294 if (!int_hsdma)
272 goto done; 295 goto done;
@@ -293,7 +316,7 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data)
293 channel->actual_len = addr 316 channel->actual_len = addr
294 - musb_channel->start_addr; 317 - musb_channel->start_addr;
295 318
296 DBG(2, "ch %p, 0x%x -> 0x%x (%zu / %d) %s\n", 319 dev_dbg(musb->controller, "ch %p, 0x%x -> 0x%x (%zu / %d) %s\n",
297 channel, musb_channel->start_addr, 320 channel, musb_channel->start_addr,
298 addr, channel->actual_len, 321 addr, channel->actual_len,
299 musb_channel->len, 322 musb_channel->len,
@@ -363,7 +386,7 @@ dma_controller_create(struct musb *musb, void __iomem *base)
363 struct musb_dma_controller *controller; 386 struct musb_dma_controller *controller;
364 struct device *dev = musb->controller; 387 struct device *dev = musb->controller;
365 struct platform_device *pdev = to_platform_device(dev); 388 struct platform_device *pdev = to_platform_device(dev);
366 int irq = platform_get_irq(pdev, 1); 389 int irq = platform_get_irq_byname(pdev, "dma");
367 390
368 if (irq == 0) { 391 if (irq == 0) {
369 dev_err(dev, "No DMA interrupt line!\n"); 392 dev_err(dev, "No DMA interrupt line!\n");
diff --git a/drivers/usb/musb/musbhsdma.h b/drivers/usb/musb/musbhsdma.h
index f763d62f151c..320fd4afb93f 100644
--- a/drivers/usb/musb/musbhsdma.h
+++ b/drivers/usb/musb/musbhsdma.h
@@ -31,7 +31,7 @@
31 * 31 *
32 */ 32 */
33 33
34#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) 34#if defined(CONFIG_SOC_OMAP2430) || defined(CONFIG_SOC_OMAP3430)
35#include "omap2430.h" 35#include "omap2430.h"
36#endif 36#endif
37 37
@@ -94,24 +94,33 @@ static inline void musb_write_hsdma_addr(void __iomem *mbase,
94{ 94{
95 musb_writew(mbase, 95 musb_writew(mbase,
96 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_LOW), 96 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_LOW),
97 ((u16)((u32) dma_addr & 0xFFFF))); 97 dma_addr);
98 musb_writew(mbase, 98 musb_writew(mbase,
99 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_HIGH), 99 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_HIGH),
100 ((u16)(((u32) dma_addr >> 16) & 0xFFFF))); 100 (dma_addr >> 16));
101} 101}
102 102
103static inline u32 musb_read_hsdma_count(void __iomem *mbase, u8 bchannel) 103static inline u32 musb_read_hsdma_count(void __iomem *mbase, u8 bchannel)
104{ 104{
105 return musb_readl(mbase, 105 u32 count = musb_readw(mbase,
106 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH)); 106 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH));
107
108 count = count << 16;
109
110 count |= musb_readw(mbase,
111 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_LOW));
112
113 return count;
107} 114}
108 115
109static inline void musb_write_hsdma_count(void __iomem *mbase, 116static inline void musb_write_hsdma_count(void __iomem *mbase,
110 u8 bchannel, u32 len) 117 u8 bchannel, u32 len)
111{ 118{
112 musb_writel(mbase, 119 musb_writew(mbase,
120 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_LOW),len);
121 musb_writew(mbase,
113 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH), 122 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH),
114 len); 123 (len >> 16));
115} 124}
116 125
117#endif /* CONFIG_BLACKFIN */ 126#endif /* CONFIG_BLACKFIN */
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 2111a241dd03..c5d4c44d0ffa 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -31,10 +31,19 @@
31#include <linux/list.h> 31#include <linux/list.h>
32#include <linux/clk.h> 32#include <linux/clk.h>
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/platform_device.h>
35#include <linux/dma-mapping.h>
36#include <linux/pm_runtime.h>
37#include <linux/err.h>
34 38
35#include "musb_core.h" 39#include "musb_core.h"
36#include "omap2430.h" 40#include "omap2430.h"
37 41
42struct omap2430_glue {
43 struct device *dev;
44 struct platform_device *musb;
45};
46#define glue_to_musb(g) platform_get_drvdata(g->musb)
38 47
39static struct timer_list musb_idle_timer; 48static struct timer_list musb_idle_timer;
40 49
@@ -49,12 +58,8 @@ static void musb_do_idle(unsigned long _musb)
49 58
50 spin_lock_irqsave(&musb->lock, flags); 59 spin_lock_irqsave(&musb->lock, flags);
51 60
52 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
53
54 switch (musb->xceiv->state) { 61 switch (musb->xceiv->state) {
55 case OTG_STATE_A_WAIT_BCON: 62 case OTG_STATE_A_WAIT_BCON:
56 devctl &= ~MUSB_DEVCTL_SESSION;
57 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
58 63
59 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 64 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
60 if (devctl & MUSB_DEVCTL_BDEVICE) { 65 if (devctl & MUSB_DEVCTL_BDEVICE) {
@@ -71,7 +76,7 @@ static void musb_do_idle(unsigned long _musb)
71 if (musb->port1_status & MUSB_PORT_STAT_RESUME) { 76 if (musb->port1_status & MUSB_PORT_STAT_RESUME) {
72 power = musb_readb(musb->mregs, MUSB_POWER); 77 power = musb_readb(musb->mregs, MUSB_POWER);
73 power &= ~MUSB_POWER_RESUME; 78 power &= ~MUSB_POWER_RESUME;
74 DBG(1, "root port resume stopped, power %02x\n", power); 79 dev_dbg(musb->controller, "root port resume stopped, power %02x\n", power);
75 musb_writeb(musb->mregs, MUSB_POWER, power); 80 musb_writeb(musb->mregs, MUSB_POWER, power);
76 musb->is_active = 1; 81 musb->is_active = 1;
77 musb->port1_status &= ~(USB_PORT_STAT_SUSPEND 82 musb->port1_status &= ~(USB_PORT_STAT_SUSPEND
@@ -98,7 +103,7 @@ static void musb_do_idle(unsigned long _musb)
98} 103}
99 104
100 105
101void musb_platform_try_idle(struct musb *musb, unsigned long timeout) 106static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout)
102{ 107{
103 unsigned long default_timeout = jiffies + msecs_to_jiffies(3); 108 unsigned long default_timeout = jiffies + msecs_to_jiffies(3);
104 static unsigned long last_timer; 109 static unsigned long last_timer;
@@ -109,7 +114,8 @@ void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
109 /* Never idle if active, or when VBUS timeout is not set as host */ 114 /* Never idle if active, or when VBUS timeout is not set as host */
110 if (musb->is_active || ((musb->a_wait_bcon == 0) 115 if (musb->is_active || ((musb->a_wait_bcon == 0)
111 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { 116 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
112 DBG(4, "%s active, deleting timer\n", otg_state_string(musb)); 117 dev_dbg(musb->controller, "%s active, deleting timer\n",
118 otg_state_string(musb->xceiv->state));
113 del_timer(&musb_idle_timer); 119 del_timer(&musb_idle_timer);
114 last_timer = jiffies; 120 last_timer = jiffies;
115 return; 121 return;
@@ -119,27 +125,23 @@ void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
119 if (!timer_pending(&musb_idle_timer)) 125 if (!timer_pending(&musb_idle_timer))
120 last_timer = timeout; 126 last_timer = timeout;
121 else { 127 else {
122 DBG(4, "Longer idle timer already pending, ignoring\n"); 128 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring\n");
123 return; 129 return;
124 } 130 }
125 } 131 }
126 last_timer = timeout; 132 last_timer = timeout;
127 133
128 DBG(4, "%s inactive, for idle timer for %lu ms\n", 134 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
129 otg_state_string(musb), 135 otg_state_string(musb->xceiv->state),
130 (unsigned long)jiffies_to_msecs(timeout - jiffies)); 136 (unsigned long)jiffies_to_msecs(timeout - jiffies));
131 mod_timer(&musb_idle_timer, timeout); 137 mod_timer(&musb_idle_timer, timeout);
132} 138}
133 139
134void musb_platform_enable(struct musb *musb) 140static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
135{
136}
137void musb_platform_disable(struct musb *musb)
138{
139}
140static void omap_set_vbus(struct musb *musb, int is_on)
141{ 141{
142 u8 devctl; 142 u8 devctl;
143 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
144 int ret = 1;
143 /* HDRC controls CPEN, but beware current surges during device 145 /* HDRC controls CPEN, but beware current surges during device
144 * connect. They can trigger transient overcurrent conditions 146 * connect. They can trigger transient overcurrent conditions
145 * that must be ignored. 147 * that must be ignored.
@@ -148,12 +150,35 @@ static void omap_set_vbus(struct musb *musb, int is_on)
148 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 150 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
149 151
150 if (is_on) { 152 if (is_on) {
151 musb->is_active = 1; 153 if (musb->xceiv->state == OTG_STATE_A_IDLE) {
152 musb->xceiv->default_a = 1; 154 /* start the session */
153 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 155 devctl |= MUSB_DEVCTL_SESSION;
154 devctl |= MUSB_DEVCTL_SESSION; 156 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
155 157 /*
156 MUSB_HST_MODE(musb); 158 * Wait for the musb to set as A device to enable the
159 * VBUS
160 */
161 while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) {
162
163 cpu_relax();
164
165 if (time_after(jiffies, timeout)) {
166 dev_err(musb->controller,
167 "configured as A device timeout");
168 ret = -EINVAL;
169 break;
170 }
171 }
172
173 if (ret && musb->xceiv->set_vbus)
174 otg_set_vbus(musb->xceiv, 1);
175 } else {
176 musb->is_active = 1;
177 musb->xceiv->default_a = 1;
178 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
179 devctl |= MUSB_DEVCTL_SESSION;
180 MUSB_HST_MODE(musb);
181 }
157 } else { 182 } else {
158 musb->is_active = 0; 183 musb->is_active = 0;
159 184
@@ -169,15 +194,13 @@ static void omap_set_vbus(struct musb *musb, int is_on)
169 } 194 }
170 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); 195 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
171 196
172 DBG(1, "VBUS %s, devctl %02x " 197 dev_dbg(musb->controller, "VBUS %s, devctl %02x "
173 /* otg %3x conf %08x prcm %08x */ "\n", 198 /* otg %3x conf %08x prcm %08x */ "\n",
174 otg_state_string(musb), 199 otg_state_string(musb->xceiv->state),
175 musb_readb(musb->mregs, MUSB_DEVCTL)); 200 musb_readb(musb->mregs, MUSB_DEVCTL));
176} 201}
177 202
178static int musb_platform_resume(struct musb *musb); 203static int omap2430_musb_set_mode(struct musb *musb, u8 musb_mode)
179
180int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
181{ 204{
182 u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 205 u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
183 206
@@ -187,10 +210,95 @@ int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
187 return 0; 210 return 0;
188} 211}
189 212
190int __init musb_platform_init(struct musb *musb, void *board_data) 213static inline void omap2430_low_level_exit(struct musb *musb)
191{ 214{
192 u32 l; 215 u32 l;
193 struct omap_musb_board_data *data = board_data; 216
217 /* in any role */
218 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
219 l |= ENABLEFORCE; /* enable MSTANDBY */
220 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
221}
222
223static inline void omap2430_low_level_init(struct musb *musb)
224{
225 u32 l;
226
227 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
228 l &= ~ENABLEFORCE; /* disable MSTANDBY */
229 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
230}
231
232/* blocking notifier support */
233static int musb_otg_notifications(struct notifier_block *nb,
234 unsigned long event, void *unused)
235{
236 struct musb *musb = container_of(nb, struct musb, nb);
237 struct device *dev = musb->controller;
238 struct musb_hdrc_platform_data *pdata = dev->platform_data;
239 struct omap_musb_board_data *data = pdata->board_data;
240
241 switch (event) {
242 case USB_EVENT_ID:
243 dev_dbg(musb->controller, "ID GND\n");
244
245 if (is_otg_enabled(musb)) {
246#ifdef CONFIG_USB_GADGET_MUSB_HDRC
247 if (musb->gadget_driver) {
248 pm_runtime_get_sync(musb->controller);
249 otg_init(musb->xceiv);
250 omap2430_musb_set_vbus(musb, 1);
251 }
252#endif
253 } else {
254 pm_runtime_get_sync(musb->controller);
255 otg_init(musb->xceiv);
256 omap2430_musb_set_vbus(musb, 1);
257 }
258 break;
259
260 case USB_EVENT_VBUS:
261 dev_dbg(musb->controller, "VBUS Connect\n");
262
263#ifdef CONFIG_USB_GADGET_MUSB_HDRC
264 if (musb->gadget_driver)
265 pm_runtime_get_sync(musb->controller);
266#endif
267 otg_init(musb->xceiv);
268 break;
269
270 case USB_EVENT_NONE:
271 dev_dbg(musb->controller, "VBUS Disconnect\n");
272
273#ifdef CONFIG_USB_GADGET_MUSB_HDRC
274 if (is_otg_enabled(musb) || is_peripheral_enabled(musb))
275 if (musb->gadget_driver)
276#endif
277 {
278 pm_runtime_mark_last_busy(musb->controller);
279 pm_runtime_put_autosuspend(musb->controller);
280 }
281
282 if (data->interface_type == MUSB_INTERFACE_UTMI) {
283 if (musb->xceiv->set_vbus)
284 otg_set_vbus(musb->xceiv, 0);
285 }
286 otg_shutdown(musb->xceiv);
287 break;
288 default:
289 dev_dbg(musb->controller, "ID float\n");
290 return NOTIFY_DONE;
291 }
292
293 return NOTIFY_OK;
294}
295
296static int omap2430_musb_init(struct musb *musb)
297{
298 u32 l, status = 0;
299 struct device *dev = musb->controller;
300 struct musb_hdrc_platform_data *plat = dev->platform_data;
301 struct omap_musb_board_data *data = plat->board_data;
194 302
195 /* We require some kind of external transceiver, hooked 303 /* We require some kind of external transceiver, hooked
196 * up through ULPI. TWL4030-family PMICs include one, 304 * up through ULPI. TWL4030-family PMICs include one,
@@ -202,22 +310,11 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
202 return -ENODEV; 310 return -ENODEV;
203 } 311 }
204 312
205 musb_platform_resume(musb); 313 status = pm_runtime_get_sync(dev);
206 314 if (status < 0) {
207 l = musb_readl(musb->mregs, OTG_SYSCONFIG); 315 dev_err(dev, "pm_runtime_get_sync FAILED");
208 l &= ~ENABLEWAKEUP; /* disable wakeup */ 316 goto err1;
209 l &= ~NOSTDBY; /* remove possible nostdby */ 317 }
210 l |= SMARTSTDBY; /* enable smart standby */
211 l &= ~AUTOIDLE; /* disable auto idle */
212 l &= ~NOIDLE; /* remove possible noidle */
213 l |= SMARTIDLE; /* enable smart idle */
214 /*
215 * MUSB AUTOIDLE don't work in 3430.
216 * Workaround by Richard Woodruff/TI
217 */
218 if (!cpu_is_omap3430())
219 l |= AUTOIDLE; /* enable auto idle */
220 musb_writel(musb->mregs, OTG_SYSCONFIG, l);
221 318
222 l = musb_readl(musb->mregs, OTG_INTERFSEL); 319 l = musb_readl(musb->mregs, OTG_INTERFSEL);
223 320
@@ -239,86 +336,221 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
239 musb_readl(musb->mregs, OTG_INTERFSEL), 336 musb_readl(musb->mregs, OTG_INTERFSEL),
240 musb_readl(musb->mregs, OTG_SIMENABLE)); 337 musb_readl(musb->mregs, OTG_SIMENABLE));
241 338
242 if (is_host_enabled(musb)) 339 musb->nb.notifier_call = musb_otg_notifications;
243 musb->board_set_vbus = omap_set_vbus; 340 status = otg_register_notifier(musb->xceiv, &musb->nb);
341
342 if (status)
343 dev_dbg(musb->controller, "notification register failed\n");
244 344
245 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 345 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
246 346
247 return 0; 347 return 0;
348
349err1:
350 pm_runtime_disable(dev);
351 return status;
248} 352}
249 353
250#ifdef CONFIG_PM 354static void omap2430_musb_enable(struct musb *musb)
251void musb_platform_save_context(struct musb *musb,
252 struct musb_context_registers *musb_context)
253{ 355{
254 musb_context->otg_sysconfig = musb_readl(musb->mregs, OTG_SYSCONFIG); 356 u8 devctl;
255 musb_context->otg_forcestandby = musb_readl(musb->mregs, OTG_FORCESTDBY); 357 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
358 struct device *dev = musb->controller;
359 struct musb_hdrc_platform_data *pdata = dev->platform_data;
360 struct omap_musb_board_data *data = pdata->board_data;
361
362 switch (musb->xceiv->last_event) {
363
364 case USB_EVENT_ID:
365 otg_init(musb->xceiv);
366 if (data->interface_type == MUSB_INTERFACE_UTMI) {
367 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
368 /* start the session */
369 devctl |= MUSB_DEVCTL_SESSION;
370 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
371 while (musb_readb(musb->mregs, MUSB_DEVCTL) &
372 MUSB_DEVCTL_BDEVICE) {
373 cpu_relax();
374
375 if (time_after(jiffies, timeout)) {
376 dev_err(musb->controller,
377 "configured as A device timeout");
378 break;
379 }
380 }
381 }
382 break;
383
384 case USB_EVENT_VBUS:
385 otg_init(musb->xceiv);
386 break;
387
388 default:
389 break;
390 }
256} 391}
257 392
258void musb_platform_restore_context(struct musb *musb, 393static void omap2430_musb_disable(struct musb *musb)
259 struct musb_context_registers *musb_context)
260{ 394{
261 musb_writel(musb->mregs, OTG_SYSCONFIG, musb_context->otg_sysconfig); 395 if (musb->xceiv->last_event)
262 musb_writel(musb->mregs, OTG_FORCESTDBY, musb_context->otg_forcestandby); 396 otg_shutdown(musb->xceiv);
263} 397}
264#endif
265 398
266static int musb_platform_suspend(struct musb *musb) 399static int omap2430_musb_exit(struct musb *musb)
267{ 400{
268 u32 l; 401 del_timer_sync(&musb_idle_timer);
269 402
270 if (!musb->clock) 403 omap2430_low_level_exit(musb);
271 return 0; 404 otg_put_transceiver(musb->xceiv);
272 405
273 /* in any role */ 406 return 0;
274 l = musb_readl(musb->mregs, OTG_FORCESTDBY); 407}
275 l |= ENABLEFORCE; /* enable MSTANDBY */
276 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
277 408
278 l = musb_readl(musb->mregs, OTG_SYSCONFIG); 409static const struct musb_platform_ops omap2430_ops = {
279 l |= ENABLEWAKEUP; /* enable wakeup */ 410 .init = omap2430_musb_init,
280 musb_writel(musb->mregs, OTG_SYSCONFIG, l); 411 .exit = omap2430_musb_exit,
281 412
282 otg_set_suspend(musb->xceiv, 1); 413 .set_mode = omap2430_musb_set_mode,
414 .try_idle = omap2430_musb_try_idle,
415
416 .set_vbus = omap2430_musb_set_vbus,
417
418 .enable = omap2430_musb_enable,
419 .disable = omap2430_musb_disable,
420};
283 421
284 if (musb->set_clock) 422static u64 omap2430_dmamask = DMA_BIT_MASK(32);
285 musb->set_clock(musb->clock, 0); 423
286 else 424static int __init omap2430_probe(struct platform_device *pdev)
287 clk_disable(musb->clock); 425{
426 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
427 struct platform_device *musb;
428 struct omap2430_glue *glue;
429 int ret = -ENOMEM;
430
431 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
432 if (!glue) {
433 dev_err(&pdev->dev, "failed to allocate glue context\n");
434 goto err0;
435 }
436
437 musb = platform_device_alloc("musb-hdrc", -1);
438 if (!musb) {
439 dev_err(&pdev->dev, "failed to allocate musb device\n");
440 goto err1;
441 }
442
443 musb->dev.parent = &pdev->dev;
444 musb->dev.dma_mask = &omap2430_dmamask;
445 musb->dev.coherent_dma_mask = omap2430_dmamask;
446
447 glue->dev = &pdev->dev;
448 glue->musb = musb;
449
450 pdata->platform_ops = &omap2430_ops;
451
452 platform_set_drvdata(pdev, glue);
453
454 ret = platform_device_add_resources(musb, pdev->resource,
455 pdev->num_resources);
456 if (ret) {
457 dev_err(&pdev->dev, "failed to add resources\n");
458 goto err2;
459 }
460
461 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
462 if (ret) {
463 dev_err(&pdev->dev, "failed to add platform_data\n");
464 goto err2;
465 }
466
467 ret = platform_device_add(musb);
468 if (ret) {
469 dev_err(&pdev->dev, "failed to register musb device\n");
470 goto err2;
471 }
472
473 pm_runtime_enable(&pdev->dev);
288 474
289 return 0; 475 return 0;
476
477err2:
478 platform_device_put(musb);
479
480err1:
481 kfree(glue);
482
483err0:
484 return ret;
290} 485}
291 486
292static int musb_platform_resume(struct musb *musb) 487static int __exit omap2430_remove(struct platform_device *pdev)
293{ 488{
294 u32 l; 489 struct omap2430_glue *glue = platform_get_drvdata(pdev);
295 490
296 if (!musb->clock) 491 platform_device_del(glue->musb);
297 return 0; 492 platform_device_put(glue->musb);
493 pm_runtime_put(&pdev->dev);
494 pm_runtime_disable(&pdev->dev);
495 kfree(glue);
298 496
299 otg_set_suspend(musb->xceiv, 0); 497 return 0;
498}
300 499
301 if (musb->set_clock) 500#ifdef CONFIG_PM
302 musb->set_clock(musb->clock, 1);
303 else
304 clk_enable(musb->clock);
305 501
306 l = musb_readl(musb->mregs, OTG_SYSCONFIG); 502static int omap2430_runtime_suspend(struct device *dev)
307 l &= ~ENABLEWAKEUP; /* disable wakeup */ 503{
308 musb_writel(musb->mregs, OTG_SYSCONFIG, l); 504 struct omap2430_glue *glue = dev_get_drvdata(dev);
505 struct musb *musb = glue_to_musb(glue);
309 506
310 l = musb_readl(musb->mregs, OTG_FORCESTDBY); 507 omap2430_low_level_exit(musb);
311 l &= ~ENABLEFORCE; /* disable MSTANDBY */ 508 otg_set_suspend(musb->xceiv, 1);
312 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
313 509
314 return 0; 510 return 0;
315} 511}
316 512
317 513static int omap2430_runtime_resume(struct device *dev)
318int musb_platform_exit(struct musb *musb)
319{ 514{
515 struct omap2430_glue *glue = dev_get_drvdata(dev);
516 struct musb *musb = glue_to_musb(glue);
320 517
321 musb_platform_suspend(musb); 518 omap2430_low_level_init(musb);
519 otg_set_suspend(musb->xceiv, 0);
322 520
323 return 0; 521 return 0;
324} 522}
523
524static struct dev_pm_ops omap2430_pm_ops = {
525 .runtime_suspend = omap2430_runtime_suspend,
526 .runtime_resume = omap2430_runtime_resume,
527};
528
529#define DEV_PM_OPS (&omap2430_pm_ops)
530#else
531#define DEV_PM_OPS NULL
532#endif
533
534static struct platform_driver omap2430_driver = {
535 .remove = __exit_p(omap2430_remove),
536 .driver = {
537 .name = "musb-omap2430",
538 .pm = DEV_PM_OPS,
539 },
540};
541
542MODULE_DESCRIPTION("OMAP2PLUS MUSB Glue Layer");
543MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
544MODULE_LICENSE("GPL v2");
545
546static int __init omap2430_init(void)
547{
548 return platform_driver_probe(&omap2430_driver, omap2430_probe);
549}
550subsys_initcall(omap2430_init);
551
552static void __exit omap2430_exit(void)
553{
554 platform_driver_unregister(&omap2430_driver);
555}
556module_exit(omap2430_exit);
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 3c48e77a0aa2..b410357cf016 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -21,10 +21,16 @@
21#include <linux/usb.h> 21#include <linux/usb.h>
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/dma-mapping.h>
24 25
25#include "musb_core.h" 26#include "musb_core.h"
26 27
27static void tusb_source_power(struct musb *musb, int is_on); 28struct tusb6010_glue {
29 struct device *dev;
30 struct platform_device *musb;
31};
32
33static void tusb_musb_set_vbus(struct musb *musb, int is_on);
28 34
29#define TUSB_REV_MAJOR(reg_val) ((reg_val >> 4) & 0xf) 35#define TUSB_REV_MAJOR(reg_val) ((reg_val >> 4) & 0xf)
30#define TUSB_REV_MINOR(reg_val) (reg_val & 0xf) 36#define TUSB_REV_MINOR(reg_val) (reg_val & 0xf)
@@ -50,7 +56,7 @@ u8 tusb_get_revision(struct musb *musb)
50 return rev; 56 return rev;
51} 57}
52 58
53static int __init tusb_print_revision(struct musb *musb) 59static int tusb_print_revision(struct musb *musb)
54{ 60{
55 void __iomem *tbase = musb->ctrl_base; 61 void __iomem *tbase = musb->ctrl_base;
56 u8 rev; 62 u8 rev;
@@ -100,7 +106,7 @@ static void tusb_wbus_quirk(struct musb *musb, int enabled)
100 tmp = phy_otg_ena & ~WBUS_QUIRK_MASK; 106 tmp = phy_otg_ena & ~WBUS_QUIRK_MASK;
101 tmp |= TUSB_PHY_OTG_CTRL_WRPROTECT | TUSB_PHY_OTG_CTRL_TESTM2; 107 tmp |= TUSB_PHY_OTG_CTRL_WRPROTECT | TUSB_PHY_OTG_CTRL_TESTM2;
102 musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, tmp); 108 musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, tmp);
103 DBG(2, "Enabled tusb wbus quirk ctrl %08x ena %08x\n", 109 dev_dbg(musb->controller, "Enabled tusb wbus quirk ctrl %08x ena %08x\n",
104 musb_readl(tbase, TUSB_PHY_OTG_CTRL), 110 musb_readl(tbase, TUSB_PHY_OTG_CTRL),
105 musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE)); 111 musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE));
106 } else if (musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE) 112 } else if (musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE)
@@ -109,7 +115,7 @@ static void tusb_wbus_quirk(struct musb *musb, int enabled)
109 musb_writel(tbase, TUSB_PHY_OTG_CTRL, tmp); 115 musb_writel(tbase, TUSB_PHY_OTG_CTRL, tmp);
110 tmp = TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ena; 116 tmp = TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ena;
111 musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, tmp); 117 musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, tmp);
112 DBG(2, "Disabled tusb wbus quirk ctrl %08x ena %08x\n", 118 dev_dbg(musb->controller, "Disabled tusb wbus quirk ctrl %08x ena %08x\n",
113 musb_readl(tbase, TUSB_PHY_OTG_CTRL), 119 musb_readl(tbase, TUSB_PHY_OTG_CTRL),
114 musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE)); 120 musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE));
115 phy_otg_ctrl = 0; 121 phy_otg_ctrl = 0;
@@ -166,13 +172,14 @@ static inline void tusb_fifo_read_unaligned(void __iomem *fifo,
166 172
167void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf) 173void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf)
168{ 174{
175 struct musb *musb = hw_ep->musb;
169 void __iomem *ep_conf = hw_ep->conf; 176 void __iomem *ep_conf = hw_ep->conf;
170 void __iomem *fifo = hw_ep->fifo; 177 void __iomem *fifo = hw_ep->fifo;
171 u8 epnum = hw_ep->epnum; 178 u8 epnum = hw_ep->epnum;
172 179
173 prefetch(buf); 180 prefetch(buf);
174 181
175 DBG(4, "%cX ep%d fifo %p count %d buf %p\n", 182 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
176 'T', epnum, fifo, len, buf); 183 'T', epnum, fifo, len, buf);
177 184
178 if (epnum) 185 if (epnum)
@@ -215,11 +222,12 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf)
215 222
216void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *buf) 223void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *buf)
217{ 224{
225 struct musb *musb = hw_ep->musb;
218 void __iomem *ep_conf = hw_ep->conf; 226 void __iomem *ep_conf = hw_ep->conf;
219 void __iomem *fifo = hw_ep->fifo; 227 void __iomem *fifo = hw_ep->fifo;
220 u8 epnum = hw_ep->epnum; 228 u8 epnum = hw_ep->epnum;
221 229
222 DBG(4, "%cX ep%d fifo %p count %d buf %p\n", 230 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
223 'R', epnum, fifo, len, buf); 231 'R', epnum, fifo, len, buf);
224 232
225 if (epnum) 233 if (epnum)
@@ -275,17 +283,6 @@ static int tusb_draw_power(struct otg_transceiver *x, unsigned mA)
275 void __iomem *tbase = musb->ctrl_base; 283 void __iomem *tbase = musb->ctrl_base;
276 u32 reg; 284 u32 reg;
277 285
278 /*
279 * Keep clock active when enabled. Note that this is not tied to
280 * drawing VBUS, as with OTG mA can be less than musb->min_power.
281 */
282 if (musb->set_clock) {
283 if (mA)
284 musb->set_clock(musb->clock, 1);
285 else
286 musb->set_clock(musb->clock, 0);
287 }
288
289 /* tps65030 seems to consume max 100mA, with maybe 60mA available 286 /* tps65030 seems to consume max 100mA, with maybe 60mA available
290 * (measured on one board) for things other than tps and tusb. 287 * (measured on one board) for things other than tps and tusb.
291 * 288 *
@@ -309,7 +306,7 @@ static int tusb_draw_power(struct otg_transceiver *x, unsigned mA)
309 } 306 }
310 musb_writel(tbase, TUSB_PRCM_MNGMT, reg); 307 musb_writel(tbase, TUSB_PRCM_MNGMT, reg);
311 308
312 DBG(2, "draw max %d mA VBUS\n", mA); 309 dev_dbg(musb->controller, "draw max %d mA VBUS\n", mA);
313 return 0; 310 return 0;
314} 311}
315 312
@@ -348,7 +345,7 @@ static void tusb_set_clock_source(struct musb *musb, unsigned mode)
348 * USB link is not suspended ... and tells us the relevant wakeup 345 * USB link is not suspended ... and tells us the relevant wakeup
349 * events. SW_EN for voltage is handled separately. 346 * events. SW_EN for voltage is handled separately.
350 */ 347 */
351void tusb_allow_idle(struct musb *musb, u32 wakeup_enables) 348static void tusb_allow_idle(struct musb *musb, u32 wakeup_enables)
352{ 349{
353 void __iomem *tbase = musb->ctrl_base; 350 void __iomem *tbase = musb->ctrl_base;
354 u32 reg; 351 u32 reg;
@@ -379,13 +376,13 @@ void tusb_allow_idle(struct musb *musb, u32 wakeup_enables)
379 reg |= TUSB_PRCM_MNGMT_PM_IDLE | TUSB_PRCM_MNGMT_DEV_IDLE; 376 reg |= TUSB_PRCM_MNGMT_PM_IDLE | TUSB_PRCM_MNGMT_DEV_IDLE;
380 musb_writel(tbase, TUSB_PRCM_MNGMT, reg); 377 musb_writel(tbase, TUSB_PRCM_MNGMT, reg);
381 378
382 DBG(6, "idle, wake on %02x\n", wakeup_enables); 379 dev_dbg(musb->controller, "idle, wake on %02x\n", wakeup_enables);
383} 380}
384 381
385/* 382/*
386 * Updates cable VBUS status. Caller must take care of locking. 383 * Updates cable VBUS status. Caller must take care of locking.
387 */ 384 */
388int musb_platform_get_vbus_status(struct musb *musb) 385static int tusb_musb_vbus_status(struct musb *musb)
389{ 386{
390 void __iomem *tbase = musb->ctrl_base; 387 void __iomem *tbase = musb->ctrl_base;
391 u32 otg_stat, prcm_mngmt; 388 u32 otg_stat, prcm_mngmt;
@@ -426,12 +423,12 @@ static void musb_do_idle(unsigned long _musb)
426 if ((musb->a_wait_bcon != 0) 423 if ((musb->a_wait_bcon != 0)
427 && (musb->idle_timeout == 0 424 && (musb->idle_timeout == 0
428 || time_after(jiffies, musb->idle_timeout))) { 425 || time_after(jiffies, musb->idle_timeout))) {
429 DBG(4, "Nothing connected %s, turning off VBUS\n", 426 dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n",
430 otg_state_string(musb)); 427 otg_state_string(musb->xceiv->state));
431 } 428 }
432 /* FALLTHROUGH */ 429 /* FALLTHROUGH */
433 case OTG_STATE_A_IDLE: 430 case OTG_STATE_A_IDLE:
434 tusb_source_power(musb, 0); 431 tusb_musb_set_vbus(musb, 0);
435 default: 432 default:
436 break; 433 break;
437 } 434 }
@@ -475,7 +472,7 @@ done:
475 * we don't want to treat that full speed J as a wakeup event. 472 * we don't want to treat that full speed J as a wakeup event.
476 * ... peripherals must draw only suspend current after 10 msec. 473 * ... peripherals must draw only suspend current after 10 msec.
477 */ 474 */
478void musb_platform_try_idle(struct musb *musb, unsigned long timeout) 475static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout)
479{ 476{
480 unsigned long default_timeout = jiffies + msecs_to_jiffies(3); 477 unsigned long default_timeout = jiffies + msecs_to_jiffies(3);
481 static unsigned long last_timer; 478 static unsigned long last_timer;
@@ -486,7 +483,8 @@ void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
486 /* Never idle if active, or when VBUS timeout is not set as host */ 483 /* Never idle if active, or when VBUS timeout is not set as host */
487 if (musb->is_active || ((musb->a_wait_bcon == 0) 484 if (musb->is_active || ((musb->a_wait_bcon == 0)
488 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { 485 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
489 DBG(4, "%s active, deleting timer\n", otg_state_string(musb)); 486 dev_dbg(musb->controller, "%s active, deleting timer\n",
487 otg_state_string(musb->xceiv->state));
490 del_timer(&musb_idle_timer); 488 del_timer(&musb_idle_timer);
491 last_timer = jiffies; 489 last_timer = jiffies;
492 return; 490 return;
@@ -496,14 +494,14 @@ void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
496 if (!timer_pending(&musb_idle_timer)) 494 if (!timer_pending(&musb_idle_timer))
497 last_timer = timeout; 495 last_timer = timeout;
498 else { 496 else {
499 DBG(4, "Longer idle timer already pending, ignoring\n"); 497 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring\n");
500 return; 498 return;
501 } 499 }
502 } 500 }
503 last_timer = timeout; 501 last_timer = timeout;
504 502
505 DBG(4, "%s inactive, for idle timer for %lu ms\n", 503 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
506 otg_state_string(musb), 504 otg_state_string(musb->xceiv->state),
507 (unsigned long)jiffies_to_msecs(timeout - jiffies)); 505 (unsigned long)jiffies_to_msecs(timeout - jiffies));
508 mod_timer(&musb_idle_timer, timeout); 506 mod_timer(&musb_idle_timer, timeout);
509} 507}
@@ -515,7 +513,7 @@ void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
515 | TUSB_DEV_OTG_TIMER_ENABLE) \ 513 | TUSB_DEV_OTG_TIMER_ENABLE) \
516 : 0) 514 : 0)
517 515
518static void tusb_source_power(struct musb *musb, int is_on) 516static void tusb_musb_set_vbus(struct musb *musb, int is_on)
519{ 517{
520 void __iomem *tbase = musb->ctrl_base; 518 void __iomem *tbase = musb->ctrl_base;
521 u32 conf, prcm, timer; 519 u32 conf, prcm, timer;
@@ -531,8 +529,6 @@ static void tusb_source_power(struct musb *musb, int is_on)
531 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 529 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
532 530
533 if (is_on) { 531 if (is_on) {
534 if (musb->set_clock)
535 musb->set_clock(musb->clock, 1);
536 timer = OTG_TIMER_MS(OTG_TIME_A_WAIT_VRISE); 532 timer = OTG_TIMER_MS(OTG_TIME_A_WAIT_VRISE);
537 musb->xceiv->default_a = 1; 533 musb->xceiv->default_a = 1;
538 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 534 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
@@ -571,8 +567,6 @@ static void tusb_source_power(struct musb *musb, int is_on)
571 567
572 devctl &= ~MUSB_DEVCTL_SESSION; 568 devctl &= ~MUSB_DEVCTL_SESSION;
573 conf &= ~TUSB_DEV_CONF_USB_HOST_MODE; 569 conf &= ~TUSB_DEV_CONF_USB_HOST_MODE;
574 if (musb->set_clock)
575 musb->set_clock(musb->clock, 0);
576 } 570 }
577 prcm &= ~(TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN); 571 prcm &= ~(TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN);
578 572
@@ -581,8 +575,8 @@ static void tusb_source_power(struct musb *musb, int is_on)
581 musb_writel(tbase, TUSB_DEV_CONF, conf); 575 musb_writel(tbase, TUSB_DEV_CONF, conf);
582 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); 576 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
583 577
584 DBG(1, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", 578 dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n",
585 otg_state_string(musb), 579 otg_state_string(musb->xceiv->state),
586 musb_readb(musb->mregs, MUSB_DEVCTL), 580 musb_readb(musb->mregs, MUSB_DEVCTL),
587 musb_readl(tbase, TUSB_DEV_OTG_STAT), 581 musb_readl(tbase, TUSB_DEV_OTG_STAT),
588 conf, prcm); 582 conf, prcm);
@@ -599,7 +593,7 @@ static void tusb_source_power(struct musb *musb, int is_on)
599 * and peripheral modes in non-OTG configurations by reconfiguring hardware 593 * and peripheral modes in non-OTG configurations by reconfiguring hardware
600 * and then setting musb->board_mode. For now, only support OTG mode. 594 * and then setting musb->board_mode. For now, only support OTG mode.
601 */ 595 */
602int musb_platform_set_mode(struct musb *musb, u8 musb_mode) 596static int tusb_musb_set_mode(struct musb *musb, u8 musb_mode)
603{ 597{
604 void __iomem *tbase = musb->ctrl_base; 598 void __iomem *tbase = musb->ctrl_base;
605 u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf; 599 u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf;
@@ -642,7 +636,7 @@ int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
642#endif 636#endif
643 637
644 default: 638 default:
645 DBG(2, "Trying to set mode %i\n", musb_mode); 639 dev_dbg(musb->controller, "Trying to set mode %i\n", musb_mode);
646 return -EINVAL; 640 return -EINVAL;
647 } 641 }
648 642
@@ -675,9 +669,9 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
675 default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS); 669 default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS);
676 else 670 else
677 default_a = is_host_enabled(musb); 671 default_a = is_host_enabled(musb);
678 DBG(2, "Default-%c\n", default_a ? 'A' : 'B'); 672 dev_dbg(musb->controller, "Default-%c\n", default_a ? 'A' : 'B');
679 musb->xceiv->default_a = default_a; 673 musb->xceiv->default_a = default_a;
680 tusb_source_power(musb, default_a); 674 tusb_musb_set_vbus(musb, default_a);
681 675
682 /* Don't allow idling immediately */ 676 /* Don't allow idling immediately */
683 if (default_a) 677 if (default_a)
@@ -702,7 +696,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
702#endif 696#endif
703 697
704 if (otg_stat & TUSB_DEV_OTG_STAT_SESS_END) { 698 if (otg_stat & TUSB_DEV_OTG_STAT_SESS_END) {
705 DBG(1, "Forcing disconnect (no interrupt)\n"); 699 dev_dbg(musb->controller, "Forcing disconnect (no interrupt)\n");
706 if (musb->xceiv->state != OTG_STATE_B_IDLE) { 700 if (musb->xceiv->state != OTG_STATE_B_IDLE) {
707 /* INTR_DISCONNECT can hide... */ 701 /* INTR_DISCONNECT can hide... */
708 musb->xceiv->state = OTG_STATE_B_IDLE; 702 musb->xceiv->state = OTG_STATE_B_IDLE;
@@ -710,19 +704,19 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
710 } 704 }
711 musb->is_active = 0; 705 musb->is_active = 0;
712 } 706 }
713 DBG(2, "vbus change, %s, otg %03x\n", 707 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
714 otg_state_string(musb), otg_stat); 708 otg_state_string(musb->xceiv->state), otg_stat);
715 idle_timeout = jiffies + (1 * HZ); 709 idle_timeout = jiffies + (1 * HZ);
716 schedule_work(&musb->irq_work); 710 schedule_work(&musb->irq_work);
717 711
718 } else /* A-dev state machine */ { 712 } else /* A-dev state machine */ {
719 DBG(2, "vbus change, %s, otg %03x\n", 713 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
720 otg_state_string(musb), otg_stat); 714 otg_state_string(musb->xceiv->state), otg_stat);
721 715
722 switch (musb->xceiv->state) { 716 switch (musb->xceiv->state) {
723 case OTG_STATE_A_IDLE: 717 case OTG_STATE_A_IDLE:
724 DBG(2, "Got SRP, turning on VBUS\n"); 718 dev_dbg(musb->controller, "Got SRP, turning on VBUS\n");
725 musb_set_vbus(musb, 1); 719 musb_platform_set_vbus(musb, 1);
726 720
727 /* CONNECT can wake if a_wait_bcon is set */ 721 /* CONNECT can wake if a_wait_bcon is set */
728 if (musb->a_wait_bcon != 0) 722 if (musb->a_wait_bcon != 0)
@@ -748,11 +742,11 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
748 */ 742 */
749 if (musb->vbuserr_retry) { 743 if (musb->vbuserr_retry) {
750 musb->vbuserr_retry--; 744 musb->vbuserr_retry--;
751 tusb_source_power(musb, 1); 745 tusb_musb_set_vbus(musb, 1);
752 } else { 746 } else {
753 musb->vbuserr_retry 747 musb->vbuserr_retry
754 = VBUSERR_RETRY_COUNT; 748 = VBUSERR_RETRY_COUNT;
755 tusb_source_power(musb, 0); 749 tusb_musb_set_vbus(musb, 0);
756 } 750 }
757 break; 751 break;
758 default: 752 default:
@@ -765,7 +759,8 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
765 if (int_src & TUSB_INT_SRC_OTG_TIMEOUT) { 759 if (int_src & TUSB_INT_SRC_OTG_TIMEOUT) {
766 u8 devctl; 760 u8 devctl;
767 761
768 DBG(4, "%s timer, %03x\n", otg_state_string(musb), otg_stat); 762 dev_dbg(musb->controller, "%s timer, %03x\n",
763 otg_state_string(musb->xceiv->state), otg_stat);
769 764
770 switch (musb->xceiv->state) { 765 switch (musb->xceiv->state) {
771 case OTG_STATE_A_WAIT_VRISE: 766 case OTG_STATE_A_WAIT_VRISE:
@@ -776,7 +771,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
776 if (otg_stat & TUSB_DEV_OTG_STAT_VBUS_VALID) { 771 if (otg_stat & TUSB_DEV_OTG_STAT_VBUS_VALID) {
777 if ((devctl & MUSB_DEVCTL_VBUS) 772 if ((devctl & MUSB_DEVCTL_VBUS)
778 != MUSB_DEVCTL_VBUS) { 773 != MUSB_DEVCTL_VBUS) {
779 DBG(2, "devctl %02x\n", devctl); 774 dev_dbg(musb->controller, "devctl %02x\n", devctl);
780 break; 775 break;
781 } 776 }
782 musb->xceiv->state = OTG_STATE_A_WAIT_BCON; 777 musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
@@ -786,7 +781,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
786 } else { 781 } else {
787 /* REVISIT report overcurrent to hub? */ 782 /* REVISIT report overcurrent to hub? */
788 ERR("vbus too slow, devctl %02x\n", devctl); 783 ERR("vbus too slow, devctl %02x\n", devctl);
789 tusb_source_power(musb, 0); 784 tusb_musb_set_vbus(musb, 0);
790 } 785 }
791 break; 786 break;
792 case OTG_STATE_A_WAIT_BCON: 787 case OTG_STATE_A_WAIT_BCON:
@@ -807,7 +802,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
807 return idle_timeout; 802 return idle_timeout;
808} 803}
809 804
810static irqreturn_t tusb_interrupt(int irq, void *__hci) 805static irqreturn_t tusb_musb_interrupt(int irq, void *__hci)
811{ 806{
812 struct musb *musb = __hci; 807 struct musb *musb = __hci;
813 void __iomem *tbase = musb->ctrl_base; 808 void __iomem *tbase = musb->ctrl_base;
@@ -821,7 +816,7 @@ static irqreturn_t tusb_interrupt(int irq, void *__hci)
821 musb_writel(tbase, TUSB_INT_MASK, ~TUSB_INT_MASK_RESERVED_BITS); 816 musb_writel(tbase, TUSB_INT_MASK, ~TUSB_INT_MASK_RESERVED_BITS);
822 817
823 int_src = musb_readl(tbase, TUSB_INT_SRC) & ~TUSB_INT_SRC_RESERVED_BITS; 818 int_src = musb_readl(tbase, TUSB_INT_SRC) & ~TUSB_INT_SRC_RESERVED_BITS;
824 DBG(3, "TUSB IRQ %08x\n", int_src); 819 dev_dbg(musb->controller, "TUSB IRQ %08x\n", int_src);
825 820
826 musb->int_usb = (u8) int_src; 821 musb->int_usb = (u8) int_src;
827 822
@@ -842,7 +837,7 @@ static irqreturn_t tusb_interrupt(int irq, void *__hci)
842 reg = musb_readl(tbase, TUSB_SCRATCH_PAD); 837 reg = musb_readl(tbase, TUSB_SCRATCH_PAD);
843 if (reg == i) 838 if (reg == i)
844 break; 839 break;
845 DBG(6, "TUSB NOR not ready\n"); 840 dev_dbg(musb->controller, "TUSB NOR not ready\n");
846 } 841 }
847 842
848 /* work around issue 13 (2nd half) */ 843 /* work around issue 13 (2nd half) */
@@ -854,7 +849,7 @@ static irqreturn_t tusb_interrupt(int irq, void *__hci)
854 musb->is_active = 1; 849 musb->is_active = 1;
855 schedule_work(&musb->irq_work); 850 schedule_work(&musb->irq_work);
856 } 851 }
857 DBG(3, "wake %sactive %02x\n", 852 dev_dbg(musb->controller, "wake %sactive %02x\n",
858 musb->is_active ? "" : "in", reg); 853 musb->is_active ? "" : "in", reg);
859 854
860 /* REVISIT host side TUSB_PRCM_WHOSTDISCON, TUSB_PRCM_WBUS */ 855 /* REVISIT host side TUSB_PRCM_WHOSTDISCON, TUSB_PRCM_WBUS */
@@ -876,7 +871,7 @@ static irqreturn_t tusb_interrupt(int irq, void *__hci)
876 u32 dma_src = musb_readl(tbase, TUSB_DMA_INT_SRC); 871 u32 dma_src = musb_readl(tbase, TUSB_DMA_INT_SRC);
877 u32 real_dma_src = musb_readl(tbase, TUSB_DMA_INT_MASK); 872 u32 real_dma_src = musb_readl(tbase, TUSB_DMA_INT_MASK);
878 873
879 DBG(3, "DMA IRQ %08x\n", dma_src); 874 dev_dbg(musb->controller, "DMA IRQ %08x\n", dma_src);
880 real_dma_src = ~real_dma_src & dma_src; 875 real_dma_src = ~real_dma_src & dma_src;
881 if (tusb_dma_omap() && real_dma_src) { 876 if (tusb_dma_omap() && real_dma_src) {
882 int tx_source = (real_dma_src & 0xffff); 877 int tx_source = (real_dma_src & 0xffff);
@@ -884,7 +879,7 @@ static irqreturn_t tusb_interrupt(int irq, void *__hci)
884 879
885 for (i = 1; i <= 15; i++) { 880 for (i = 1; i <= 15; i++) {
886 if (tx_source & (1 << i)) { 881 if (tx_source & (1 << i)) {
887 DBG(3, "completing ep%i %s\n", i, "tx"); 882 dev_dbg(musb->controller, "completing ep%i %s\n", i, "tx");
888 musb_dma_completion(musb, i, 1); 883 musb_dma_completion(musb, i, 1);
889 } 884 }
890 } 885 }
@@ -911,7 +906,7 @@ static irqreturn_t tusb_interrupt(int irq, void *__hci)
911 musb_writel(tbase, TUSB_INT_SRC_CLEAR, 906 musb_writel(tbase, TUSB_INT_SRC_CLEAR,
912 int_src & ~TUSB_INT_MASK_RESERVED_BITS); 907 int_src & ~TUSB_INT_MASK_RESERVED_BITS);
913 908
914 musb_platform_try_idle(musb, idle_timeout); 909 tusb_musb_try_idle(musb, idle_timeout);
915 910
916 musb_writel(tbase, TUSB_INT_MASK, int_mask); 911 musb_writel(tbase, TUSB_INT_MASK, int_mask);
917 spin_unlock_irqrestore(&musb->lock, flags); 912 spin_unlock_irqrestore(&musb->lock, flags);
@@ -926,7 +921,7 @@ static int dma_off;
926 * REVISIT: 921 * REVISIT:
927 * - Check what is unnecessary in MGC_HdrcStart() 922 * - Check what is unnecessary in MGC_HdrcStart()
928 */ 923 */
929void musb_platform_enable(struct musb *musb) 924static void tusb_musb_enable(struct musb *musb)
930{ 925{
931 void __iomem *tbase = musb->ctrl_base; 926 void __iomem *tbase = musb->ctrl_base;
932 927
@@ -952,7 +947,7 @@ void musb_platform_enable(struct musb *musb)
952 musb_writel(tbase, TUSB_INT_CTRL_CONF, 947 musb_writel(tbase, TUSB_INT_CTRL_CONF,
953 TUSB_INT_CTRL_CONF_INT_RELCYC(0)); 948 TUSB_INT_CTRL_CONF_INT_RELCYC(0));
954 949
955 set_irq_type(musb->nIrq, IRQ_TYPE_LEVEL_LOW); 950 irq_set_irq_type(musb->nIrq, IRQ_TYPE_LEVEL_LOW);
956 951
957 /* maybe force into the Default-A OTG state machine */ 952 /* maybe force into the Default-A OTG state machine */
958 if (!(musb_readl(tbase, TUSB_DEV_OTG_STAT) 953 if (!(musb_readl(tbase, TUSB_DEV_OTG_STAT)
@@ -970,7 +965,7 @@ void musb_platform_enable(struct musb *musb)
970/* 965/*
971 * Disables TUSB6010. Caller must take care of locking. 966 * Disables TUSB6010. Caller must take care of locking.
972 */ 967 */
973void musb_platform_disable(struct musb *musb) 968static void tusb_musb_disable(struct musb *musb)
974{ 969{
975 void __iomem *tbase = musb->ctrl_base; 970 void __iomem *tbase = musb->ctrl_base;
976 971
@@ -995,7 +990,7 @@ void musb_platform_disable(struct musb *musb)
995 * Sets up TUSB6010 CPU interface specific signals and registers 990 * Sets up TUSB6010 CPU interface specific signals and registers
996 * Note: Settings optimized for OMAP24xx 991 * Note: Settings optimized for OMAP24xx
997 */ 992 */
998static void __init tusb_setup_cpu_interface(struct musb *musb) 993static void tusb_setup_cpu_interface(struct musb *musb)
999{ 994{
1000 void __iomem *tbase = musb->ctrl_base; 995 void __iomem *tbase = musb->ctrl_base;
1001 996
@@ -1022,7 +1017,7 @@ static void __init tusb_setup_cpu_interface(struct musb *musb)
1022 musb_writel(tbase, TUSB_WAIT_COUNT, 1); 1017 musb_writel(tbase, TUSB_WAIT_COUNT, 1);
1023} 1018}
1024 1019
1025static int __init tusb_start(struct musb *musb) 1020static int tusb_musb_start(struct musb *musb)
1026{ 1021{
1027 void __iomem *tbase = musb->ctrl_base; 1022 void __iomem *tbase = musb->ctrl_base;
1028 int ret = 0; 1023 int ret = 0;
@@ -1091,7 +1086,7 @@ err:
1091 return -ENODEV; 1086 return -ENODEV;
1092} 1087}
1093 1088
1094int __init musb_platform_init(struct musb *musb, void *board_data) 1089static int tusb_musb_init(struct musb *musb)
1095{ 1090{
1096 struct platform_device *pdev; 1091 struct platform_device *pdev;
1097 struct resource *mem; 1092 struct resource *mem;
@@ -1131,16 +1126,14 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
1131 */ 1126 */
1132 musb->mregs += TUSB_BASE_OFFSET; 1127 musb->mregs += TUSB_BASE_OFFSET;
1133 1128
1134 ret = tusb_start(musb); 1129 ret = tusb_musb_start(musb);
1135 if (ret) { 1130 if (ret) {
1136 printk(KERN_ERR "Could not start tusb6010 (%d)\n", 1131 printk(KERN_ERR "Could not start tusb6010 (%d)\n",
1137 ret); 1132 ret);
1138 goto done; 1133 goto done;
1139 } 1134 }
1140 musb->isr = tusb_interrupt; 1135 musb->isr = tusb_musb_interrupt;
1141 1136
1142 if (is_host_enabled(musb))
1143 musb->board_set_vbus = tusb_source_power;
1144 if (is_peripheral_enabled(musb)) { 1137 if (is_peripheral_enabled(musb)) {
1145 musb->xceiv->set_power = tusb_draw_power; 1138 musb->xceiv->set_power = tusb_draw_power;
1146 the_musb = musb; 1139 the_musb = musb;
@@ -1152,12 +1145,14 @@ done:
1152 if (ret < 0) { 1145 if (ret < 0) {
1153 if (sync) 1146 if (sync)
1154 iounmap(sync); 1147 iounmap(sync);
1148
1149 otg_put_transceiver(musb->xceiv);
1155 usb_nop_xceiv_unregister(); 1150 usb_nop_xceiv_unregister();
1156 } 1151 }
1157 return ret; 1152 return ret;
1158} 1153}
1159 1154
1160int musb_platform_exit(struct musb *musb) 1155static int tusb_musb_exit(struct musb *musb)
1161{ 1156{
1162 del_timer_sync(&musb_idle_timer); 1157 del_timer_sync(&musb_idle_timer);
1163 the_musb = NULL; 1158 the_musb = NULL;
@@ -1166,6 +1161,120 @@ int musb_platform_exit(struct musb *musb)
1166 musb->board_set_power(0); 1161 musb->board_set_power(0);
1167 1162
1168 iounmap(musb->sync_va); 1163 iounmap(musb->sync_va);
1164
1165 otg_put_transceiver(musb->xceiv);
1169 usb_nop_xceiv_unregister(); 1166 usb_nop_xceiv_unregister();
1170 return 0; 1167 return 0;
1171} 1168}
1169
1170static const struct musb_platform_ops tusb_ops = {
1171 .init = tusb_musb_init,
1172 .exit = tusb_musb_exit,
1173
1174 .enable = tusb_musb_enable,
1175 .disable = tusb_musb_disable,
1176
1177 .set_mode = tusb_musb_set_mode,
1178 .try_idle = tusb_musb_try_idle,
1179
1180 .vbus_status = tusb_musb_vbus_status,
1181 .set_vbus = tusb_musb_set_vbus,
1182};
1183
1184static u64 tusb_dmamask = DMA_BIT_MASK(32);
1185
1186static int __init tusb_probe(struct platform_device *pdev)
1187{
1188 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
1189 struct platform_device *musb;
1190 struct tusb6010_glue *glue;
1191
1192 int ret = -ENOMEM;
1193
1194 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
1195 if (!glue) {
1196 dev_err(&pdev->dev, "failed to allocate glue context\n");
1197 goto err0;
1198 }
1199
1200 musb = platform_device_alloc("musb-hdrc", -1);
1201 if (!musb) {
1202 dev_err(&pdev->dev, "failed to allocate musb device\n");
1203 goto err1;
1204 }
1205
1206 musb->dev.parent = &pdev->dev;
1207 musb->dev.dma_mask = &tusb_dmamask;
1208 musb->dev.coherent_dma_mask = tusb_dmamask;
1209
1210 glue->dev = &pdev->dev;
1211 glue->musb = musb;
1212
1213 pdata->platform_ops = &tusb_ops;
1214
1215 platform_set_drvdata(pdev, glue);
1216
1217 ret = platform_device_add_resources(musb, pdev->resource,
1218 pdev->num_resources);
1219 if (ret) {
1220 dev_err(&pdev->dev, "failed to add resources\n");
1221 goto err2;
1222 }
1223
1224 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
1225 if (ret) {
1226 dev_err(&pdev->dev, "failed to add platform_data\n");
1227 goto err2;
1228 }
1229
1230 ret = platform_device_add(musb);
1231 if (ret) {
1232 dev_err(&pdev->dev, "failed to register musb device\n");
1233 goto err1;
1234 }
1235
1236 return 0;
1237
1238err2:
1239 platform_device_put(musb);
1240
1241err1:
1242 kfree(glue);
1243
1244err0:
1245 return ret;
1246}
1247
1248static int __exit tusb_remove(struct platform_device *pdev)
1249{
1250 struct tusb6010_glue *glue = platform_get_drvdata(pdev);
1251
1252 platform_device_del(glue->musb);
1253 platform_device_put(glue->musb);
1254 kfree(glue);
1255
1256 return 0;
1257}
1258
1259static struct platform_driver tusb_driver = {
1260 .remove = __exit_p(tusb_remove),
1261 .driver = {
1262 .name = "musb-tusb",
1263 },
1264};
1265
1266MODULE_DESCRIPTION("TUSB6010 MUSB Glue Layer");
1267MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
1268MODULE_LICENSE("GPL v2");
1269
1270static int __init tusb_init(void)
1271{
1272 return platform_driver_probe(&tusb_driver, tusb_probe);
1273}
1274subsys_initcall(tusb_init);
1275
1276static void __exit tusb_exit(void)
1277{
1278 platform_driver_unregister(&tusb_driver);
1279}
1280module_exit(tusb_exit);
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c
index c061a88f2b0f..c784e6c03aac 100644
--- a/drivers/usb/musb/tusb6010_omap.c
+++ b/drivers/usb/musb/tusb6010_omap.c
@@ -65,7 +65,7 @@ static int tusb_omap_dma_start(struct dma_controller *c)
65 65
66 tusb_dma = container_of(c, struct tusb_omap_dma, controller); 66 tusb_dma = container_of(c, struct tusb_omap_dma, controller);
67 67
68 /* DBG(3, "ep%i ch: %i\n", chdat->epnum, chdat->ch); */ 68 /* dev_dbg(musb->controller, "ep%i ch: %i\n", chdat->epnum, chdat->ch); */
69 69
70 return 0; 70 return 0;
71} 71}
@@ -76,7 +76,7 @@ static int tusb_omap_dma_stop(struct dma_controller *c)
76 76
77 tusb_dma = container_of(c, struct tusb_omap_dma, controller); 77 tusb_dma = container_of(c, struct tusb_omap_dma, controller);
78 78
79 /* DBG(3, "ep%i ch: %i\n", chdat->epnum, chdat->ch); */ 79 /* dev_dbg(musb->controller, "ep%i ch: %i\n", chdat->epnum, chdat->ch); */
80 80
81 return 0; 81 return 0;
82} 82}
@@ -89,7 +89,7 @@ static inline int tusb_omap_use_shared_dmareq(struct tusb_omap_dma_ch *chdat)
89 u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP); 89 u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP);
90 90
91 if (reg != 0) { 91 if (reg != 0) {
92 DBG(3, "ep%i dmareq0 is busy for ep%i\n", 92 dev_dbg(musb->controller, "ep%i dmareq0 is busy for ep%i\n",
93 chdat->epnum, reg & 0xf); 93 chdat->epnum, reg & 0xf);
94 return -EAGAIN; 94 return -EAGAIN;
95 } 95 }
@@ -143,7 +143,7 @@ static void tusb_omap_dma_cb(int lch, u16 ch_status, void *data)
143 if (ch_status != OMAP_DMA_BLOCK_IRQ) 143 if (ch_status != OMAP_DMA_BLOCK_IRQ)
144 printk(KERN_ERR "TUSB DMA error status: %i\n", ch_status); 144 printk(KERN_ERR "TUSB DMA error status: %i\n", ch_status);
145 145
146 DBG(3, "ep%i %s dma callback ch: %i status: %x\n", 146 dev_dbg(musb->controller, "ep%i %s dma callback ch: %i status: %x\n",
147 chdat->epnum, chdat->tx ? "tx" : "rx", 147 chdat->epnum, chdat->tx ? "tx" : "rx",
148 ch, ch_status); 148 ch, ch_status);
149 149
@@ -156,7 +156,7 @@ static void tusb_omap_dma_cb(int lch, u16 ch_status, void *data)
156 156
157 /* HW issue #10: XFR_SIZE may get corrupt on DMA (both async & sync) */ 157 /* HW issue #10: XFR_SIZE may get corrupt on DMA (both async & sync) */
158 if (unlikely(remaining > chdat->transfer_len)) { 158 if (unlikely(remaining > chdat->transfer_len)) {
159 DBG(2, "Corrupt %s dma ch%i XFR_SIZE: 0x%08lx\n", 159 dev_dbg(musb->controller, "Corrupt %s dma ch%i XFR_SIZE: 0x%08lx\n",
160 chdat->tx ? "tx" : "rx", chdat->ch, 160 chdat->tx ? "tx" : "rx", chdat->ch,
161 remaining); 161 remaining);
162 remaining = 0; 162 remaining = 0;
@@ -165,13 +165,13 @@ static void tusb_omap_dma_cb(int lch, u16 ch_status, void *data)
165 channel->actual_len = chdat->transfer_len - remaining; 165 channel->actual_len = chdat->transfer_len - remaining;
166 pio = chdat->len - channel->actual_len; 166 pio = chdat->len - channel->actual_len;
167 167
168 DBG(3, "DMA remaining %lu/%u\n", remaining, chdat->transfer_len); 168 dev_dbg(musb->controller, "DMA remaining %lu/%u\n", remaining, chdat->transfer_len);
169 169
170 /* Transfer remaining 1 - 31 bytes */ 170 /* Transfer remaining 1 - 31 bytes */
171 if (pio > 0 && pio < 32) { 171 if (pio > 0 && pio < 32) {
172 u8 *buf; 172 u8 *buf;
173 173
174 DBG(3, "Using PIO for remaining %lu bytes\n", pio); 174 dev_dbg(musb->controller, "Using PIO for remaining %lu bytes\n", pio);
175 buf = phys_to_virt((u32)chdat->dma_addr) + chdat->transfer_len; 175 buf = phys_to_virt((u32)chdat->dma_addr) + chdat->transfer_len;
176 if (chdat->tx) { 176 if (chdat->tx) {
177 dma_unmap_single(dev, chdat->dma_addr, 177 dma_unmap_single(dev, chdat->dma_addr,
@@ -209,7 +209,7 @@ static void tusb_omap_dma_cb(int lch, u16 ch_status, void *data)
209 u16 csr; 209 u16 csr;
210 210
211 if (chdat->tx) { 211 if (chdat->tx) {
212 DBG(3, "terminating short tx packet\n"); 212 dev_dbg(musb->controller, "terminating short tx packet\n");
213 musb_ep_select(mbase, chdat->epnum); 213 musb_ep_select(mbase, chdat->epnum);
214 csr = musb_readw(hw_ep->regs, MUSB_TXCSR); 214 csr = musb_readw(hw_ep->regs, MUSB_TXCSR);
215 csr |= MUSB_TXCSR_MODE | MUSB_TXCSR_TXPKTRDY 215 csr |= MUSB_TXCSR_MODE | MUSB_TXCSR_TXPKTRDY
@@ -264,7 +264,7 @@ static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz,
264 264
265 dma_remaining = TUSB_EP_CONFIG_XFR_SIZE(dma_remaining); 265 dma_remaining = TUSB_EP_CONFIG_XFR_SIZE(dma_remaining);
266 if (dma_remaining) { 266 if (dma_remaining) {
267 DBG(2, "Busy %s dma ch%i, not using: %08x\n", 267 dev_dbg(musb->controller, "Busy %s dma ch%i, not using: %08x\n",
268 chdat->tx ? "tx" : "rx", chdat->ch, 268 chdat->tx ? "tx" : "rx", chdat->ch,
269 dma_remaining); 269 dma_remaining);
270 return false; 270 return false;
@@ -283,7 +283,7 @@ static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz,
283 sync_dev = chdat->sync_dev; 283 sync_dev = chdat->sync_dev;
284 } else { 284 } else {
285 if (tusb_omap_use_shared_dmareq(chdat) != 0) { 285 if (tusb_omap_use_shared_dmareq(chdat) != 0) {
286 DBG(3, "could not get dma for ep%i\n", chdat->epnum); 286 dev_dbg(musb->controller, "could not get dma for ep%i\n", chdat->epnum);
287 return false; 287 return false;
288 } 288 }
289 if (tusb_dma->ch < 0) { 289 if (tusb_dma->ch < 0) {
@@ -326,7 +326,7 @@ static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz,
326 326
327 dma_params.frame_count = chdat->transfer_len / 32; /* Burst sz frame */ 327 dma_params.frame_count = chdat->transfer_len / 32; /* Burst sz frame */
328 328
329 DBG(3, "ep%i %s dma ch%i dma: %08x len: %u(%u) packet_sz: %i(%i)\n", 329 dev_dbg(musb->controller, "ep%i %s dma ch%i dma: %08x len: %u(%u) packet_sz: %i(%i)\n",
330 chdat->epnum, chdat->tx ? "tx" : "rx", 330 chdat->epnum, chdat->tx ? "tx" : "rx",
331 ch, dma_addr, chdat->transfer_len, len, 331 ch, dma_addr, chdat->transfer_len, len,
332 chdat->transfer_packet_sz, packet_sz); 332 chdat->transfer_packet_sz, packet_sz);
@@ -370,7 +370,7 @@ static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz,
370 dst_burst = OMAP_DMA_DATA_BURST_16; /* 16x32 write */ 370 dst_burst = OMAP_DMA_DATA_BURST_16; /* 16x32 write */
371 } 371 }
372 372
373 DBG(3, "ep%i %s using %i-bit %s dma from 0x%08lx to 0x%08lx\n", 373 dev_dbg(musb->controller, "ep%i %s using %i-bit %s dma from 0x%08lx to 0x%08lx\n",
374 chdat->epnum, chdat->tx ? "tx" : "rx", 374 chdat->epnum, chdat->tx ? "tx" : "rx",
375 (dma_params.data_type == OMAP_DMA_DATA_TYPE_S32) ? 32 : 16, 375 (dma_params.data_type == OMAP_DMA_DATA_TYPE_S32) ? 32 : 16,
376 ((dma_addr & 0x3) == 0) ? "sync" : "async", 376 ((dma_addr & 0x3) == 0) ? "sync" : "async",
@@ -525,7 +525,7 @@ tusb_omap_dma_allocate(struct dma_controller *c,
525 525
526 /* REVISIT: Why does dmareq5 not work? */ 526 /* REVISIT: Why does dmareq5 not work? */
527 if (hw_ep->epnum == 0) { 527 if (hw_ep->epnum == 0) {
528 DBG(3, "Not allowing DMA for ep0 %s\n", tx ? "tx" : "rx"); 528 dev_dbg(musb->controller, "Not allowing DMA for ep0 %s\n", tx ? "tx" : "rx");
529 return NULL; 529 return NULL;
530 } 530 }
531 531
@@ -585,7 +585,7 @@ tusb_omap_dma_allocate(struct dma_controller *c,
585 chdat->ch = -1; 585 chdat->ch = -1;
586 } 586 }
587 587
588 DBG(3, "ep%i %s dma: %s dma%i dmareq%i sync%i\n", 588 dev_dbg(musb->controller, "ep%i %s dma: %s dma%i dmareq%i sync%i\n",
589 chdat->epnum, 589 chdat->epnum,
590 chdat->tx ? "tx" : "rx", 590 chdat->tx ? "tx" : "rx",
591 chdat->ch >= 0 ? "dedicated" : "shared", 591 chdat->ch >= 0 ? "dedicated" : "shared",
@@ -598,7 +598,7 @@ tusb_omap_dma_allocate(struct dma_controller *c,
598free_dmareq: 598free_dmareq:
599 tusb_omap_dma_free_dmareq(chdat); 599 tusb_omap_dma_free_dmareq(chdat);
600 600
601 DBG(3, "ep%i: Could not get a DMA channel\n", chdat->epnum); 601 dev_dbg(musb->controller, "ep%i: Could not get a DMA channel\n", chdat->epnum);
602 channel->status = MUSB_DMA_STATUS_UNKNOWN; 602 channel->status = MUSB_DMA_STATUS_UNKNOWN;
603 603
604 return NULL; 604 return NULL;
@@ -611,7 +611,7 @@ static void tusb_omap_dma_release(struct dma_channel *channel)
611 void __iomem *tbase = musb->ctrl_base; 611 void __iomem *tbase = musb->ctrl_base;
612 u32 reg; 612 u32 reg;
613 613
614 DBG(3, "ep%i ch%i\n", chdat->epnum, chdat->ch); 614 dev_dbg(musb->controller, "ep%i ch%i\n", chdat->epnum, chdat->ch);
615 615
616 reg = musb_readl(tbase, TUSB_DMA_INT_MASK); 616 reg = musb_readl(tbase, TUSB_DMA_INT_MASK);
617 if (chdat->tx) 617 if (chdat->tx)
@@ -680,7 +680,7 @@ dma_controller_create(struct musb *musb, void __iomem *base)
680 680
681 tusb_dma = kzalloc(sizeof(struct tusb_omap_dma), GFP_KERNEL); 681 tusb_dma = kzalloc(sizeof(struct tusb_omap_dma), GFP_KERNEL);
682 if (!tusb_dma) 682 if (!tusb_dma)
683 goto cleanup; 683 goto out;
684 684
685 tusb_dma->musb = musb; 685 tusb_dma->musb = musb;
686 tusb_dma->tbase = musb->ctrl_base; 686 tusb_dma->tbase = musb->ctrl_base;
@@ -721,6 +721,6 @@ dma_controller_create(struct musb *musb, void __iomem *base)
721 721
722cleanup: 722cleanup:
723 dma_controller_destroy(&tusb_dma->controller); 723 dma_controller_destroy(&tusb_dma->controller);
724 724out:
725 return NULL; 725 return NULL;
726} 726}
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
new file mode 100644
index 000000000000..f7e04bf34a13
--- /dev/null
+++ b/drivers/usb/musb/ux500.c
@@ -0,0 +1,218 @@
1/*
2 * Copyright (C) 2010 ST-Ericsson AB
3 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
4 *
5 * Based on omap2430.c
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/init.h>
25#include <linux/clk.h>
26#include <linux/io.h>
27#include <linux/platform_device.h>
28
29#include "musb_core.h"
30
31struct ux500_glue {
32 struct device *dev;
33 struct platform_device *musb;
34 struct clk *clk;
35};
36#define glue_to_musb(g) platform_get_drvdata(g->musb)
37
38static int ux500_musb_init(struct musb *musb)
39{
40 musb->xceiv = otg_get_transceiver();
41 if (!musb->xceiv) {
42 pr_err("HS USB OTG: no transceiver configured\n");
43 return -ENODEV;
44 }
45
46 return 0;
47}
48
49static int ux500_musb_exit(struct musb *musb)
50{
51 otg_put_transceiver(musb->xceiv);
52
53 return 0;
54}
55
56static const struct musb_platform_ops ux500_ops = {
57 .init = ux500_musb_init,
58 .exit = ux500_musb_exit,
59};
60
61static int __init ux500_probe(struct platform_device *pdev)
62{
63 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
64 struct platform_device *musb;
65 struct ux500_glue *glue;
66 struct clk *clk;
67
68 int ret = -ENOMEM;
69
70 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
71 if (!glue) {
72 dev_err(&pdev->dev, "failed to allocate glue context\n");
73 goto err0;
74 }
75
76 musb = platform_device_alloc("musb-hdrc", -1);
77 if (!musb) {
78 dev_err(&pdev->dev, "failed to allocate musb device\n");
79 goto err1;
80 }
81
82 clk = clk_get(&pdev->dev, "usb");
83 if (IS_ERR(clk)) {
84 dev_err(&pdev->dev, "failed to get clock\n");
85 ret = PTR_ERR(clk);
86 goto err2;
87 }
88
89 ret = clk_enable(clk);
90 if (ret) {
91 dev_err(&pdev->dev, "failed to enable clock\n");
92 goto err3;
93 }
94
95 musb->dev.parent = &pdev->dev;
96 musb->dev.dma_mask = pdev->dev.dma_mask;
97 musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask;
98
99 glue->dev = &pdev->dev;
100 glue->musb = musb;
101 glue->clk = clk;
102
103 pdata->platform_ops = &ux500_ops;
104
105 platform_set_drvdata(pdev, glue);
106
107 ret = platform_device_add_resources(musb, pdev->resource,
108 pdev->num_resources);
109 if (ret) {
110 dev_err(&pdev->dev, "failed to add resources\n");
111 goto err4;
112 }
113
114 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
115 if (ret) {
116 dev_err(&pdev->dev, "failed to add platform_data\n");
117 goto err4;
118 }
119
120 ret = platform_device_add(musb);
121 if (ret) {
122 dev_err(&pdev->dev, "failed to register musb device\n");
123 goto err4;
124 }
125
126 return 0;
127
128err4:
129 clk_disable(clk);
130
131err3:
132 clk_put(clk);
133
134err2:
135 platform_device_put(musb);
136
137err1:
138 kfree(glue);
139
140err0:
141 return ret;
142}
143
144static int __exit ux500_remove(struct platform_device *pdev)
145{
146 struct ux500_glue *glue = platform_get_drvdata(pdev);
147
148 platform_device_del(glue->musb);
149 platform_device_put(glue->musb);
150 clk_disable(glue->clk);
151 clk_put(glue->clk);
152 kfree(glue);
153
154 return 0;
155}
156
157#ifdef CONFIG_PM
158static int ux500_suspend(struct device *dev)
159{
160 struct ux500_glue *glue = dev_get_drvdata(dev);
161 struct musb *musb = glue_to_musb(glue);
162
163 otg_set_suspend(musb->xceiv, 1);
164 clk_disable(glue->clk);
165
166 return 0;
167}
168
169static int ux500_resume(struct device *dev)
170{
171 struct ux500_glue *glue = dev_get_drvdata(dev);
172 struct musb *musb = glue_to_musb(glue);
173 int ret;
174
175 ret = clk_enable(glue->clk);
176 if (ret) {
177 dev_err(dev, "failed to enable clock\n");
178 return ret;
179 }
180
181 otg_set_suspend(musb->xceiv, 0);
182
183 return 0;
184}
185
186static const struct dev_pm_ops ux500_pm_ops = {
187 .suspend = ux500_suspend,
188 .resume = ux500_resume,
189};
190
191#define DEV_PM_OPS (&ux500_pm_ops)
192#else
193#define DEV_PM_OPS NULL
194#endif
195
196static struct platform_driver ux500_driver = {
197 .remove = __exit_p(ux500_remove),
198 .driver = {
199 .name = "musb-ux500",
200 .pm = DEV_PM_OPS,
201 },
202};
203
204MODULE_DESCRIPTION("UX500 MUSB Glue Layer");
205MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>");
206MODULE_LICENSE("GPL v2");
207
208static int __init ux500_init(void)
209{
210 return platform_driver_probe(&ux500_driver, ux500_probe);
211}
212subsys_initcall(ux500_init);
213
214static void __exit ux500_exit(void)
215{
216 platform_driver_unregister(&ux500_driver);
217}
218module_exit(ux500_exit);
diff --git a/drivers/usb/musb/ux500_dma.c b/drivers/usb/musb/ux500_dma.c
new file mode 100644
index 000000000000..cecace411832
--- /dev/null
+++ b/drivers/usb/musb/ux500_dma.c
@@ -0,0 +1,422 @@
1/*
2 * drivers/usb/musb/ux500_dma.c
3 *
4 * U8500 and U5500 DMA support code
5 *
6 * Copyright (C) 2009 STMicroelectronics
7 * Copyright (C) 2011 ST-Ericsson SA
8 * Authors:
9 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
10 * Praveena Nadahally <praveen.nadahally@stericsson.com>
11 * Rajaram Regupathy <ragupathy.rajaram@stericsson.com>
12 *
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27#include <linux/device.h>
28#include <linux/interrupt.h>
29#include <linux/platform_device.h>
30#include <linux/dma-mapping.h>
31#include <linux/dmaengine.h>
32#include <linux/pfn.h>
33#include <mach/usb.h>
34#include "musb_core.h"
35
36struct ux500_dma_channel {
37 struct dma_channel channel;
38 struct ux500_dma_controller *controller;
39 struct musb_hw_ep *hw_ep;
40 struct work_struct channel_work;
41 struct dma_chan *dma_chan;
42 unsigned int cur_len;
43 dma_cookie_t cookie;
44 u8 ch_num;
45 u8 is_tx;
46 u8 is_allocated;
47};
48
49struct ux500_dma_controller {
50 struct dma_controller controller;
51 struct ux500_dma_channel rx_channel[UX500_MUSB_DMA_NUM_RX_CHANNELS];
52 struct ux500_dma_channel tx_channel[UX500_MUSB_DMA_NUM_TX_CHANNELS];
53 u32 num_rx_channels;
54 u32 num_tx_channels;
55 void *private_data;
56 dma_addr_t phy_base;
57};
58
59/* Work function invoked from DMA callback to handle tx transfers. */
60static void ux500_tx_work(struct work_struct *data)
61{
62 struct ux500_dma_channel *ux500_channel = container_of(data,
63 struct ux500_dma_channel, channel_work);
64 struct musb_hw_ep *hw_ep = ux500_channel->hw_ep;
65 struct musb *musb = hw_ep->musb;
66 unsigned long flags;
67
68 DBG(4, "DMA tx transfer done on hw_ep=%d\n", hw_ep->epnum);
69
70 spin_lock_irqsave(&musb->lock, flags);
71 ux500_channel->channel.actual_len = ux500_channel->cur_len;
72 ux500_channel->channel.status = MUSB_DMA_STATUS_FREE;
73 musb_dma_completion(musb, hw_ep->epnum,
74 ux500_channel->is_tx);
75 spin_unlock_irqrestore(&musb->lock, flags);
76}
77
78/* Work function invoked from DMA callback to handle rx transfers. */
79static void ux500_rx_work(struct work_struct *data)
80{
81 struct ux500_dma_channel *ux500_channel = container_of(data,
82 struct ux500_dma_channel, channel_work);
83 struct musb_hw_ep *hw_ep = ux500_channel->hw_ep;
84 struct musb *musb = hw_ep->musb;
85 unsigned long flags;
86
87 DBG(4, "DMA rx transfer done on hw_ep=%d\n", hw_ep->epnum);
88
89 spin_lock_irqsave(&musb->lock, flags);
90 ux500_channel->channel.actual_len = ux500_channel->cur_len;
91 ux500_channel->channel.status = MUSB_DMA_STATUS_FREE;
92 musb_dma_completion(musb, hw_ep->epnum,
93 ux500_channel->is_tx);
94 spin_unlock_irqrestore(&musb->lock, flags);
95}
96
97void ux500_dma_callback(void *private_data)
98{
99 struct dma_channel *channel = (struct dma_channel *)private_data;
100 struct ux500_dma_channel *ux500_channel = channel->private_data;
101
102 schedule_work(&ux500_channel->channel_work);
103}
104
105static bool ux500_configure_channel(struct dma_channel *channel,
106 u16 packet_sz, u8 mode,
107 dma_addr_t dma_addr, u32 len)
108{
109 struct ux500_dma_channel *ux500_channel = channel->private_data;
110 struct musb_hw_ep *hw_ep = ux500_channel->hw_ep;
111 struct dma_chan *dma_chan = ux500_channel->dma_chan;
112 struct dma_async_tx_descriptor *dma_desc;
113 enum dma_data_direction direction;
114 struct scatterlist sg;
115 struct dma_slave_config slave_conf;
116 enum dma_slave_buswidth addr_width;
117 dma_addr_t usb_fifo_addr = (MUSB_FIFO_OFFSET(hw_ep->epnum) +
118 ux500_channel->controller->phy_base);
119
120 DBG(4, "packet_sz=%d, mode=%d, dma_addr=0x%x, len=%d is_tx=%d\n",
121 packet_sz, mode, dma_addr, len, ux500_channel->is_tx);
122
123 ux500_channel->cur_len = len;
124
125 sg_init_table(&sg, 1);
126 sg_set_page(&sg, pfn_to_page(PFN_DOWN(dma_addr)), len,
127 offset_in_page(dma_addr));
128 sg_dma_address(&sg) = dma_addr;
129 sg_dma_len(&sg) = len;
130
131 direction = ux500_channel->is_tx ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
132 addr_width = (len & 0x3) ? DMA_SLAVE_BUSWIDTH_1_BYTE :
133 DMA_SLAVE_BUSWIDTH_4_BYTES;
134
135 slave_conf.direction = direction;
136 if (direction == DMA_FROM_DEVICE) {
137 slave_conf.src_addr = usb_fifo_addr;
138 slave_conf.src_addr_width = addr_width;
139 slave_conf.src_maxburst = 16;
140 } else {
141 slave_conf.dst_addr = usb_fifo_addr;
142 slave_conf.dst_addr_width = addr_width;
143 slave_conf.dst_maxburst = 16;
144 }
145 dma_chan->device->device_control(dma_chan, DMA_SLAVE_CONFIG,
146 (unsigned long) &slave_conf);
147
148 dma_desc = dma_chan->device->
149 device_prep_slave_sg(dma_chan, &sg, 1, direction,
150 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
151 if (!dma_desc)
152 return false;
153
154 dma_desc->callback = ux500_dma_callback;
155 dma_desc->callback_param = channel;
156 ux500_channel->cookie = dma_desc->tx_submit(dma_desc);
157
158 dma_async_issue_pending(dma_chan);
159
160 return true;
161}
162
163static struct dma_channel *ux500_dma_channel_allocate(struct dma_controller *c,
164 struct musb_hw_ep *hw_ep, u8 is_tx)
165{
166 struct ux500_dma_controller *controller = container_of(c,
167 struct ux500_dma_controller, controller);
168 struct ux500_dma_channel *ux500_channel = NULL;
169 u8 ch_num = hw_ep->epnum - 1;
170 u32 max_ch;
171
172 /* Max 8 DMA channels (0 - 7). Each DMA channel can only be allocated
173 * to specified hw_ep. For example DMA channel 0 can only be allocated
174 * to hw_ep 1 and 9.
175 */
176 if (ch_num > 7)
177 ch_num -= 8;
178
179 max_ch = is_tx ? controller->num_tx_channels :
180 controller->num_rx_channels;
181
182 if (ch_num >= max_ch)
183 return NULL;
184
185 ux500_channel = is_tx ? &(controller->tx_channel[ch_num]) :
186 &(controller->rx_channel[ch_num]) ;
187
188 /* Check if channel is already used. */
189 if (ux500_channel->is_allocated)
190 return NULL;
191
192 ux500_channel->hw_ep = hw_ep;
193 ux500_channel->is_allocated = 1;
194
195 DBG(7, "hw_ep=%d, is_tx=0x%x, channel=%d\n",
196 hw_ep->epnum, is_tx, ch_num);
197
198 return &(ux500_channel->channel);
199}
200
201static void ux500_dma_channel_release(struct dma_channel *channel)
202{
203 struct ux500_dma_channel *ux500_channel = channel->private_data;
204
205 DBG(7, "channel=%d\n", ux500_channel->ch_num);
206
207 if (ux500_channel->is_allocated) {
208 ux500_channel->is_allocated = 0;
209 channel->status = MUSB_DMA_STATUS_FREE;
210 channel->actual_len = 0;
211 }
212}
213
214static int ux500_dma_is_compatible(struct dma_channel *channel,
215 u16 maxpacket, void *buf, u32 length)
216{
217 if ((maxpacket & 0x3) ||
218 ((int)buf & 0x3) ||
219 (length < 512) ||
220 (length & 0x3))
221 return false;
222 else
223 return true;
224}
225
226static int ux500_dma_channel_program(struct dma_channel *channel,
227 u16 packet_sz, u8 mode,
228 dma_addr_t dma_addr, u32 len)
229{
230 int ret;
231
232 BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN ||
233 channel->status == MUSB_DMA_STATUS_BUSY);
234
235 if (!ux500_dma_is_compatible(channel, packet_sz, (void *)dma_addr, len))
236 return false;
237
238 channel->status = MUSB_DMA_STATUS_BUSY;
239 channel->actual_len = 0;
240 ret = ux500_configure_channel(channel, packet_sz, mode, dma_addr, len);
241 if (!ret)
242 channel->status = MUSB_DMA_STATUS_FREE;
243
244 return ret;
245}
246
247static int ux500_dma_channel_abort(struct dma_channel *channel)
248{
249 struct ux500_dma_channel *ux500_channel = channel->private_data;
250 struct ux500_dma_controller *controller = ux500_channel->controller;
251 struct musb *musb = controller->private_data;
252 void __iomem *epio = musb->endpoints[ux500_channel->hw_ep->epnum].regs;
253 u16 csr;
254
255 DBG(4, "channel=%d, is_tx=%d\n", ux500_channel->ch_num,
256 ux500_channel->is_tx);
257
258 if (channel->status == MUSB_DMA_STATUS_BUSY) {
259 if (ux500_channel->is_tx) {
260 csr = musb_readw(epio, MUSB_TXCSR);
261 csr &= ~(MUSB_TXCSR_AUTOSET |
262 MUSB_TXCSR_DMAENAB |
263 MUSB_TXCSR_DMAMODE);
264 musb_writew(epio, MUSB_TXCSR, csr);
265 } else {
266 csr = musb_readw(epio, MUSB_RXCSR);
267 csr &= ~(MUSB_RXCSR_AUTOCLEAR |
268 MUSB_RXCSR_DMAENAB |
269 MUSB_RXCSR_DMAMODE);
270 musb_writew(epio, MUSB_RXCSR, csr);
271 }
272
273 ux500_channel->dma_chan->device->
274 device_control(ux500_channel->dma_chan,
275 DMA_TERMINATE_ALL, 0);
276 channel->status = MUSB_DMA_STATUS_FREE;
277 }
278 return 0;
279}
280
281static int ux500_dma_controller_stop(struct dma_controller *c)
282{
283 struct ux500_dma_controller *controller = container_of(c,
284 struct ux500_dma_controller, controller);
285 struct ux500_dma_channel *ux500_channel;
286 struct dma_channel *channel;
287 u8 ch_num;
288
289 for (ch_num = 0; ch_num < controller->num_rx_channels; ch_num++) {
290 channel = &controller->rx_channel[ch_num].channel;
291 ux500_channel = channel->private_data;
292
293 ux500_dma_channel_release(channel);
294
295 if (ux500_channel->dma_chan)
296 dma_release_channel(ux500_channel->dma_chan);
297 }
298
299 for (ch_num = 0; ch_num < controller->num_tx_channels; ch_num++) {
300 channel = &controller->tx_channel[ch_num].channel;
301 ux500_channel = channel->private_data;
302
303 ux500_dma_channel_release(channel);
304
305 if (ux500_channel->dma_chan)
306 dma_release_channel(ux500_channel->dma_chan);
307 }
308
309 return 0;
310}
311
312static int ux500_dma_controller_start(struct dma_controller *c)
313{
314 struct ux500_dma_controller *controller = container_of(c,
315 struct ux500_dma_controller, controller);
316 struct ux500_dma_channel *ux500_channel = NULL;
317 struct musb *musb = controller->private_data;
318 struct device *dev = musb->controller;
319 struct musb_hdrc_platform_data *plat = dev->platform_data;
320 struct ux500_musb_board_data *data = plat->board_data;
321 struct dma_channel *dma_channel = NULL;
322 u32 ch_num;
323 u8 dir;
324 u8 is_tx = 0;
325
326 void **param_array;
327 struct ux500_dma_channel *channel_array;
328 u32 ch_count;
329 void (*musb_channel_work)(struct work_struct *);
330 dma_cap_mask_t mask;
331
332 if ((data->num_rx_channels > UX500_MUSB_DMA_NUM_RX_CHANNELS) ||
333 (data->num_tx_channels > UX500_MUSB_DMA_NUM_TX_CHANNELS))
334 return -EINVAL;
335
336 controller->num_rx_channels = data->num_rx_channels;
337 controller->num_tx_channels = data->num_tx_channels;
338
339 dma_cap_zero(mask);
340 dma_cap_set(DMA_SLAVE, mask);
341
342 /* Prepare the loop for RX channels */
343 channel_array = controller->rx_channel;
344 ch_count = data->num_rx_channels;
345 param_array = data->dma_rx_param_array;
346 musb_channel_work = ux500_rx_work;
347
348 for (dir = 0; dir < 2; dir++) {
349 for (ch_num = 0; ch_num < ch_count; ch_num++) {
350 ux500_channel = &channel_array[ch_num];
351 ux500_channel->controller = controller;
352 ux500_channel->ch_num = ch_num;
353 ux500_channel->is_tx = is_tx;
354
355 dma_channel = &(ux500_channel->channel);
356 dma_channel->private_data = ux500_channel;
357 dma_channel->status = MUSB_DMA_STATUS_FREE;
358 dma_channel->max_len = SZ_16M;
359
360 ux500_channel->dma_chan = dma_request_channel(mask,
361 data->dma_filter,
362 param_array[ch_num]);
363 if (!ux500_channel->dma_chan) {
364 ERR("Dma pipe allocation error dir=%d ch=%d\n",
365 dir, ch_num);
366
367 /* Release already allocated channels */
368 ux500_dma_controller_stop(c);
369
370 return -EBUSY;
371 }
372
373 INIT_WORK(&ux500_channel->channel_work,
374 musb_channel_work);
375 }
376
377 /* Prepare the loop for TX channels */
378 channel_array = controller->tx_channel;
379 ch_count = data->num_tx_channels;
380 param_array = data->dma_tx_param_array;
381 musb_channel_work = ux500_tx_work;
382 is_tx = 1;
383 }
384
385 return 0;
386}
387
388void dma_controller_destroy(struct dma_controller *c)
389{
390 struct ux500_dma_controller *controller = container_of(c,
391 struct ux500_dma_controller, controller);
392
393 kfree(controller);
394}
395
396struct dma_controller *__init
397dma_controller_create(struct musb *musb, void __iomem *base)
398{
399 struct ux500_dma_controller *controller;
400 struct platform_device *pdev = to_platform_device(musb->controller);
401 struct resource *iomem;
402
403 controller = kzalloc(sizeof(*controller), GFP_KERNEL);
404 if (!controller)
405 return NULL;
406
407 controller->private_data = musb;
408
409 /* Save physical address for DMA controller. */
410 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
411 controller->phy_base = (dma_addr_t) iomem->start;
412
413 controller->controller.start = ux500_dma_controller_start;
414 controller->controller.stop = ux500_dma_controller_stop;
415 controller->controller.channel_alloc = ux500_dma_channel_allocate;
416 controller->controller.channel_release = ux500_dma_channel_release;
417 controller->controller.channel_program = ux500_dma_channel_program;
418 controller->controller.channel_abort = ux500_dma_channel_abort;
419 controller->controller.is_compatible = ux500_dma_is_compatible;
420
421 return &controller->controller;
422}
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 3b1289572d72..c66481ad98d7 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -49,6 +49,13 @@ config USB_ULPI
49 Enable this to support ULPI connected USB OTG transceivers which 49 Enable this to support ULPI connected USB OTG transceivers which
50 are likely found on embedded boards. 50 are likely found on embedded boards.
51 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
52config TWL4030_USB 59config TWL4030_USB
53 tristate "TWL4030 USB Transceiver Driver" 60 tristate "TWL4030 USB Transceiver Driver"
54 depends on TWL4030_CORE && REGULATOR_TWL4030 61 depends on TWL4030_CORE && REGULATOR_TWL4030
@@ -59,6 +66,18 @@ config TWL4030_USB
59 This transceiver supports high and full speed devices plus, 66 This transceiver supports high and full speed devices plus,
60 in host mode, low speed. 67 in host mode, low speed.
61 68
69config TWL6030_USB
70 tristate "TWL6030 USB Transceiver Driver"
71 depends on TWL4030_CORE
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
62config NOP_USB_XCEIV 81config NOP_USB_XCEIV
63 tristate "NOP USB Transceiver Driver" 82 tristate "NOP USB Transceiver Driver"
64 select USB_OTG_UTILS 83 select USB_OTG_UTILS
@@ -67,4 +86,48 @@ config NOP_USB_XCEIV
67 built-in with usb ip or which are autonomous and doesn't require any 86 built-in with usb ip or which are autonomous and doesn't require any
68 phy programming such as ISP1x04 etc. 87 phy programming such as ISP1x04 etc.
69 88
89config USB_LANGWELL_OTG
90 tristate "Intel Langwell USB OTG dual-role support"
91 depends on USB && PCI && INTEL_SCU_IPC
92 select USB_OTG
93 select USB_OTG_UTILS
94 help
95 Say Y here if you want to build Intel Langwell USB OTG
96 transciever driver in kernel. This driver implements role
97 switch between EHCI host driver and Langwell USB OTG
98 client driver.
99
100 To compile this driver as a module, choose M here: the
101 module will be called langwell_otg.
102
103config USB_MSM_OTG
104 tristate "OTG support for Qualcomm on-chip USB controller"
105 depends on (USB || USB_GADGET) && ARCH_MSM
106 select USB_OTG_UTILS
107 help
108 Enable this to support the USB OTG transceiver on MSM chips. It
109 handles PHY initialization, clock management, and workarounds
110 required after resetting the hardware and power management.
111 This driver is required even for peripheral only or host only
112 mode configurations.
113 This driver is not supported on boards like trout which
114 has an external PHY.
115
116config AB8500_USB
117 tristate "AB8500 USB Transceiver Driver"
118 depends on AB8500_CORE
119 select USB_OTG_UTILS
120 help
121 Enable this to support the USB OTG transceiver in AB8500 chip.
122 This transceiver supports high and full speed devices plus,
123 in host mode, low speed.
124
125config FSL_USB2_OTG
126 bool "Freescale USB OTG Transceiver Driver"
127 depends on USB_EHCI_FSL && USB_GADGET_FSL_USB2
128 select USB_OTG
129 select USB_OTG_UTILS
130 help
131 Enable this to support Freescale USB OTG transceiver.
132
70endif # USB || OTG 133endif # USB || OTG
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index aeb49a8ec412..566655c53331 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -2,6 +2,9 @@
2# OTG infrastructure and transceiver drivers 2# OTG infrastructure and transceiver drivers
3# 3#
4 4
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG
7
5# infrastructure 8# infrastructure
6obj-$(CONFIG_USB_OTG_UTILS) += otg.o 9obj-$(CONFIG_USB_OTG_UTILS) += otg.o
7 10
@@ -9,9 +12,12 @@ obj-$(CONFIG_USB_OTG_UTILS) += otg.o
9obj-$(CONFIG_USB_GPIO_VBUS) += gpio_vbus.o 12obj-$(CONFIG_USB_GPIO_VBUS) += gpio_vbus.o
10obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 13obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
11obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o 14obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o
15obj-$(CONFIG_TWL6030_USB) += twl6030-usb.o
16obj-$(CONFIG_USB_LANGWELL_OTG) += langwell_otg.o
12obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o 17obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o
13obj-$(CONFIG_USB_ULPI) += ulpi.o 18obj-$(CONFIG_USB_ULPI) += ulpi.o
14 19obj-$(CONFIG_USB_ULPI_VIEWPORT) += ulpi_viewport.o
15ccflags-$(CONFIG_USB_DEBUG) += -DDEBUG 20obj-$(CONFIG_USB_MSM_OTG) += msm_otg.o
16ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG 21obj-$(CONFIG_AB8500_USB) += ab8500-usb.o
17 22fsl_usb2_otg-objs := fsl_otg.o otg_fsm.o
23obj-$(CONFIG_FSL_USB2_OTG) += fsl_usb2_otg.o
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c
new file mode 100644
index 000000000000..07ccea9ada40
--- /dev/null
+++ b/drivers/usb/otg/ab8500-usb.c
@@ -0,0 +1,585 @@
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/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 otg_transceiver otg;
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 *xceiv_to_ab(struct otg_transceiver *x)
86{
87 return container_of(x, struct ab8500_usb, otg);
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_xceiv_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->otg.state = OTG_STATE_B_IDLE;
173 ab->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->otg.gadget) {
185 /* TODO: Enable regulators. */
186 ab8500_usb_peri_phy_en(ab);
187 v = ab->otg.gadget;
188 }
189 event = USB_EVENT_VBUS;
190 break;
191
192 case USB_LINK_HM_IDGND:
193 if (ab->otg.host) {
194 /* TODO: Enable regulators. */
195 ab8500_usb_host_phy_en(ab);
196 v = ab->otg.host;
197 }
198 ab->otg.state = OTG_STATE_A_IDLE;
199 ab->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->otg.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->otg.host)
266 ab8500_usb_host_phy_dis(ab);
267
268 if (!ab->otg.gadget)
269 ab8500_usb_peri_phy_dis(ab);
270}
271
272static int ab8500_usb_set_power(struct otg_transceiver *otg, unsigned mA)
273{
274 struct ab8500_usb *ab;
275
276 if (!otg)
277 return -ENODEV;
278
279 ab = xceiv_to_ab(otg);
280
281 ab->vbus_draw = mA;
282
283 if (mA)
284 atomic_notifier_call_chain(&ab->otg.notifier,
285 USB_EVENT_ENUMERATED, ab->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 otg_transceiver *x, int suspend)
294{
295 /* TODO */
296 return 0;
297}
298
299static int ab8500_usb_set_peripheral(struct otg_transceiver *otg,
300 struct usb_gadget *gadget)
301{
302 struct ab8500_usb *ab;
303
304 if (!otg)
305 return -ENODEV;
306
307 ab = xceiv_to_ab(otg);
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 ab->otg.gadget = NULL;
317 schedule_work(&ab->phy_dis_work);
318 } else {
319 ab->otg.gadget = gadget;
320 ab->otg.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 otg_transceiver *otg,
333 struct usb_bus *host)
334{
335 struct ab8500_usb *ab;
336
337 if (!otg)
338 return -ENODEV;
339
340 ab = xceiv_to_ab(otg);
341
342 /* Some drivers call this function in atomic context.
343 * Do not update ab8500 registers directly till this
344 * is fixed.
345 */
346
347 if (!host) {
348 /* TODO: Disable regulators. */
349 ab->otg.host = NULL;
350 schedule_work(&ab->phy_dis_work);
351 } else {
352 ab->otg.host = host;
353 /* Phy will not be enabled if cable is already
354 * plugged-in. Schedule to enable phy.
355 * Use same delay to avoid any race condition.
356 */
357 schedule_delayed_work(&ab->dwork, ab->link_status_wait);
358 }
359
360 return 0;
361}
362
363static void ab8500_usb_irq_free(struct ab8500_usb *ab)
364{
365 if (ab->rev < 0x20) {
366 free_irq(ab->irq_num_id_rise, ab);
367 free_irq(ab->irq_num_id_fall, ab);
368 free_irq(ab->irq_num_vbus_rise, ab);
369 free_irq(ab->irq_num_vbus_fall, ab);
370 } else {
371 free_irq(ab->irq_num_link_status, ab);
372 }
373}
374
375static int ab8500_usb_v1x_res_setup(struct platform_device *pdev,
376 struct ab8500_usb *ab)
377{
378 int err;
379
380 ab->irq_num_id_rise = platform_get_irq_byname(pdev, "ID_WAKEUP_R");
381 if (ab->irq_num_id_rise < 0) {
382 dev_err(&pdev->dev, "ID rise irq not found\n");
383 return ab->irq_num_id_rise;
384 }
385 err = request_threaded_irq(ab->irq_num_id_rise, NULL,
386 ab8500_usb_v1x_common_irq,
387 IRQF_NO_SUSPEND | IRQF_SHARED,
388 "usb-id-rise", ab);
389 if (err < 0) {
390 dev_err(ab->dev, "request_irq failed for ID rise irq\n");
391 goto fail0;
392 }
393
394 ab->irq_num_id_fall = platform_get_irq_byname(pdev, "ID_WAKEUP_F");
395 if (ab->irq_num_id_fall < 0) {
396 dev_err(&pdev->dev, "ID fall irq not found\n");
397 return ab->irq_num_id_fall;
398 }
399 err = request_threaded_irq(ab->irq_num_id_fall, NULL,
400 ab8500_usb_v1x_common_irq,
401 IRQF_NO_SUSPEND | IRQF_SHARED,
402 "usb-id-fall", ab);
403 if (err < 0) {
404 dev_err(ab->dev, "request_irq failed for ID fall irq\n");
405 goto fail1;
406 }
407
408 ab->irq_num_vbus_rise = platform_get_irq_byname(pdev, "VBUS_DET_R");
409 if (ab->irq_num_vbus_rise < 0) {
410 dev_err(&pdev->dev, "VBUS rise irq not found\n");
411 return ab->irq_num_vbus_rise;
412 }
413 err = request_threaded_irq(ab->irq_num_vbus_rise, NULL,
414 ab8500_usb_v1x_common_irq,
415 IRQF_NO_SUSPEND | IRQF_SHARED,
416 "usb-vbus-rise", ab);
417 if (err < 0) {
418 dev_err(ab->dev, "request_irq failed for Vbus rise irq\n");
419 goto fail2;
420 }
421
422 ab->irq_num_vbus_fall = platform_get_irq_byname(pdev, "VBUS_DET_F");
423 if (ab->irq_num_vbus_fall < 0) {
424 dev_err(&pdev->dev, "VBUS fall irq not found\n");
425 return ab->irq_num_vbus_fall;
426 }
427 err = request_threaded_irq(ab->irq_num_vbus_fall, NULL,
428 ab8500_usb_v1x_vbus_fall_irq,
429 IRQF_NO_SUSPEND | IRQF_SHARED,
430 "usb-vbus-fall", ab);
431 if (err < 0) {
432 dev_err(ab->dev, "request_irq failed for Vbus fall irq\n");
433 goto fail3;
434 }
435
436 return 0;
437fail3:
438 free_irq(ab->irq_num_vbus_rise, ab);
439fail2:
440 free_irq(ab->irq_num_id_fall, ab);
441fail1:
442 free_irq(ab->irq_num_id_rise, ab);
443fail0:
444 return err;
445}
446
447static int ab8500_usb_v2_res_setup(struct platform_device *pdev,
448 struct ab8500_usb *ab)
449{
450 int err;
451
452 ab->irq_num_link_status = platform_get_irq_byname(pdev,
453 "USB_LINK_STATUS");
454 if (ab->irq_num_link_status < 0) {
455 dev_err(&pdev->dev, "Link status irq not found\n");
456 return ab->irq_num_link_status;
457 }
458
459 err = request_threaded_irq(ab->irq_num_link_status, NULL,
460 ab8500_usb_v20_irq,
461 IRQF_NO_SUSPEND | IRQF_SHARED,
462 "usb-link-status", ab);
463 if (err < 0) {
464 dev_err(ab->dev,
465 "request_irq failed for link status irq\n");
466 return err;
467 }
468
469 return 0;
470}
471
472static int __devinit ab8500_usb_probe(struct platform_device *pdev)
473{
474 struct ab8500_usb *ab;
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 ab->dev = &pdev->dev;
492 ab->rev = rev;
493 ab->otg.dev = ab->dev;
494 ab->otg.label = "ab8500";
495 ab->otg.state = OTG_STATE_UNDEFINED;
496 ab->otg.set_host = ab8500_usb_set_host;
497 ab->otg.set_peripheral = ab8500_usb_set_peripheral;
498 ab->otg.set_suspend = ab8500_usb_set_suspend;
499 ab->otg.set_power = ab8500_usb_set_power;
500
501 platform_set_drvdata(pdev, ab);
502
503 ATOMIC_INIT_NOTIFIER_HEAD(&ab->otg.notifier);
504
505 /* v1: Wait for link status to become stable.
506 * all: Updates form set_host and set_peripheral as they are atomic.
507 */
508 INIT_DELAYED_WORK(&ab->dwork, ab8500_usb_delayed_work);
509
510 /* all: Disable phy when called from set_host and set_peripheral */
511 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
512
513 if (ab->rev < 0x20) {
514 err = ab8500_usb_v1x_res_setup(pdev, ab);
515 ab->link_status_wait = AB8500_V1x_LINK_STAT_WAIT;
516 } else {
517 err = ab8500_usb_v2_res_setup(pdev, ab);
518 }
519
520 if (err < 0)
521 goto fail0;
522
523 err = otg_set_transceiver(&ab->otg);
524 if (err) {
525 dev_err(&pdev->dev, "Can't register transceiver\n");
526 goto fail1;
527 }
528
529 dev_info(&pdev->dev, "AB8500 usb driver initialized\n");
530
531 return 0;
532fail1:
533 ab8500_usb_irq_free(ab);
534fail0:
535 kfree(ab);
536 return err;
537}
538
539static int __devexit ab8500_usb_remove(struct platform_device *pdev)
540{
541 struct ab8500_usb *ab = platform_get_drvdata(pdev);
542
543 ab8500_usb_irq_free(ab);
544
545 cancel_delayed_work_sync(&ab->dwork);
546
547 cancel_work_sync(&ab->phy_dis_work);
548
549 otg_set_transceiver(NULL);
550
551 ab8500_usb_host_phy_dis(ab);
552 ab8500_usb_peri_phy_dis(ab);
553
554 platform_set_drvdata(pdev, NULL);
555
556 kfree(ab);
557
558 return 0;
559}
560
561static struct platform_driver ab8500_usb_driver = {
562 .probe = ab8500_usb_probe,
563 .remove = __devexit_p(ab8500_usb_remove),
564 .driver = {
565 .name = "ab8500-usb",
566 .owner = THIS_MODULE,
567 },
568};
569
570static int __init ab8500_usb_init(void)
571{
572 return platform_driver_register(&ab8500_usb_driver);
573}
574subsys_initcall(ab8500_usb_init);
575
576static void __exit ab8500_usb_exit(void)
577{
578 platform_driver_unregister(&ab8500_usb_driver);
579}
580module_exit(ab8500_usb_exit);
581
582MODULE_ALIAS("platform:ab8500_usb");
583MODULE_AUTHOR("ST-Ericsson AB");
584MODULE_DESCRIPTION("AB8500 usb transceiver driver");
585MODULE_LICENSE("GPL");
diff --git a/drivers/usb/otg/fsl_otg.c b/drivers/usb/otg/fsl_otg.c
new file mode 100644
index 000000000000..0f420b25e9a9
--- /dev/null
+++ b/drivers/usb/otg/fsl_otg.c
@@ -0,0 +1,1169 @@
1/*
2 * Copyright (C) 2007,2008 Freescale semiconductor, Inc.
3 *
4 * Author: Li Yang <LeoLi@freescale.com>
5 * Jerry Huang <Chang-Ming.Huang@freescale.com>
6 *
7 * Initialization based on code from Shlomi Gridish.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/module.h>
25#include <linux/kernel.h>
26#include <linux/delay.h>
27#include <linux/slab.h>
28#include <linux/proc_fs.h>
29#include <linux/errno.h>
30#include <linux/init.h>
31#include <linux/interrupt.h>
32#include <linux/io.h>
33#include <linux/timer.h>
34#include <linux/usb.h>
35#include <linux/device.h>
36#include <linux/usb/ch9.h>
37#include <linux/usb/gadget.h>
38#include <linux/workqueue.h>
39#include <linux/time.h>
40#include <linux/fsl_devices.h>
41#include <linux/platform_device.h>
42#include <linux/uaccess.h>
43
44#include <asm/unaligned.h>
45
46#include "fsl_otg.h"
47
48#define DRIVER_VERSION "Rev. 1.55"
49#define DRIVER_AUTHOR "Jerry Huang/Li Yang"
50#define DRIVER_DESC "Freescale USB OTG Transceiver Driver"
51#define DRIVER_INFO DRIVER_DESC " " DRIVER_VERSION
52
53static const char driver_name[] = "fsl-usb2-otg";
54
55const pm_message_t otg_suspend_state = {
56 .event = 1,
57};
58
59#define HA_DATA_PULSE
60
61static struct usb_dr_mmap *usb_dr_regs;
62static struct fsl_otg *fsl_otg_dev;
63static int srp_wait_done;
64
65/* FSM timers */
66struct fsl_otg_timer *a_wait_vrise_tmr, *a_wait_bcon_tmr, *a_aidl_bdis_tmr,
67 *b_ase0_brst_tmr, *b_se0_srp_tmr;
68
69/* Driver specific timers */
70struct fsl_otg_timer *b_data_pulse_tmr, *b_vbus_pulse_tmr, *b_srp_fail_tmr,
71 *b_srp_wait_tmr, *a_wait_enum_tmr;
72
73static struct list_head active_timers;
74
75static struct fsl_otg_config fsl_otg_initdata = {
76 .otg_port = 1,
77};
78
79#ifdef CONFIG_PPC32
80static u32 _fsl_readl_be(const unsigned __iomem *p)
81{
82 return in_be32(p);
83}
84
85static u32 _fsl_readl_le(const unsigned __iomem *p)
86{
87 return in_le32(p);
88}
89
90static void _fsl_writel_be(u32 v, unsigned __iomem *p)
91{
92 out_be32(p, v);
93}
94
95static void _fsl_writel_le(u32 v, unsigned __iomem *p)
96{
97 out_le32(p, v);
98}
99
100static u32 (*_fsl_readl)(const unsigned __iomem *p);
101static void (*_fsl_writel)(u32 v, unsigned __iomem *p);
102
103#define fsl_readl(p) (*_fsl_readl)((p))
104#define fsl_writel(v, p) (*_fsl_writel)((v), (p))
105
106#else
107#define fsl_readl(addr) readl(addr)
108#define fsl_writel(val, addr) writel(val, addr)
109#endif /* CONFIG_PPC32 */
110
111/* Routines to access transceiver ULPI registers */
112u8 view_ulpi(u8 addr)
113{
114 u32 temp;
115
116 temp = 0x40000000 | (addr << 16);
117 fsl_writel(temp, &usb_dr_regs->ulpiview);
118 udelay(1000);
119 while (temp & 0x40)
120 temp = fsl_readl(&usb_dr_regs->ulpiview);
121 return (le32_to_cpu(temp) & 0x0000ff00) >> 8;
122}
123
124int write_ulpi(u8 addr, u8 data)
125{
126 u32 temp;
127
128 temp = 0x60000000 | (addr << 16) | data;
129 fsl_writel(temp, &usb_dr_regs->ulpiview);
130 return 0;
131}
132
133/* -------------------------------------------------------------*/
134/* Operations that will be called from OTG Finite State Machine */
135
136/* Charge vbus for vbus pulsing in SRP */
137void fsl_otg_chrg_vbus(int on)
138{
139 u32 tmp;
140
141 tmp = fsl_readl(&usb_dr_regs->otgsc) & ~OTGSC_INTSTS_MASK;
142
143 if (on)
144 /* stop discharging, start charging */
145 tmp = (tmp & ~OTGSC_CTRL_VBUS_DISCHARGE) |
146 OTGSC_CTRL_VBUS_CHARGE;
147 else
148 /* stop charging */
149 tmp &= ~OTGSC_CTRL_VBUS_CHARGE;
150
151 fsl_writel(tmp, &usb_dr_regs->otgsc);
152}
153
154/* Discharge vbus through a resistor to ground */
155void fsl_otg_dischrg_vbus(int on)
156{
157 u32 tmp;
158
159 tmp = fsl_readl(&usb_dr_regs->otgsc) & ~OTGSC_INTSTS_MASK;
160
161 if (on)
162 /* stop charging, start discharging */
163 tmp = (tmp & ~OTGSC_CTRL_VBUS_CHARGE) |
164 OTGSC_CTRL_VBUS_DISCHARGE;
165 else
166 /* stop discharging */
167 tmp &= ~OTGSC_CTRL_VBUS_DISCHARGE;
168
169 fsl_writel(tmp, &usb_dr_regs->otgsc);
170}
171
172/* A-device driver vbus, controlled through PP bit in PORTSC */
173void fsl_otg_drv_vbus(int on)
174{
175 u32 tmp;
176
177 if (on) {
178 tmp = fsl_readl(&usb_dr_regs->portsc) & ~PORTSC_W1C_BITS;
179 fsl_writel(tmp | PORTSC_PORT_POWER, &usb_dr_regs->portsc);
180 } else {
181 tmp = fsl_readl(&usb_dr_regs->portsc) &
182 ~PORTSC_W1C_BITS & ~PORTSC_PORT_POWER;
183 fsl_writel(tmp, &usb_dr_regs->portsc);
184 }
185}
186
187/*
188 * Pull-up D+, signalling connect by periperal. Also used in
189 * data-line pulsing in SRP
190 */
191void fsl_otg_loc_conn(int on)
192{
193 u32 tmp;
194
195 tmp = fsl_readl(&usb_dr_regs->otgsc) & ~OTGSC_INTSTS_MASK;
196
197 if (on)
198 tmp |= OTGSC_CTRL_DATA_PULSING;
199 else
200 tmp &= ~OTGSC_CTRL_DATA_PULSING;
201
202 fsl_writel(tmp, &usb_dr_regs->otgsc);
203}
204
205/*
206 * Generate SOF by host. This is controlled through suspend/resume the
207 * port. In host mode, controller will automatically send SOF.
208 * Suspend will block the data on the port.
209 */
210void fsl_otg_loc_sof(int on)
211{
212 u32 tmp;
213
214 tmp = fsl_readl(&fsl_otg_dev->dr_mem_map->portsc) & ~PORTSC_W1C_BITS;
215 if (on)
216 tmp |= PORTSC_PORT_FORCE_RESUME;
217 else
218 tmp |= PORTSC_PORT_SUSPEND;
219
220 fsl_writel(tmp, &fsl_otg_dev->dr_mem_map->portsc);
221
222}
223
224/* Start SRP pulsing by data-line pulsing, followed with v-bus pulsing. */
225void fsl_otg_start_pulse(void)
226{
227 u32 tmp;
228
229 srp_wait_done = 0;
230#ifdef HA_DATA_PULSE
231 tmp = fsl_readl(&usb_dr_regs->otgsc) & ~OTGSC_INTSTS_MASK;
232 tmp |= OTGSC_HA_DATA_PULSE;
233 fsl_writel(tmp, &usb_dr_regs->otgsc);
234#else
235 fsl_otg_loc_conn(1);
236#endif
237
238 fsl_otg_add_timer(b_data_pulse_tmr);
239}
240
241void b_data_pulse_end(unsigned long foo)
242{
243#ifdef HA_DATA_PULSE
244#else
245 fsl_otg_loc_conn(0);
246#endif
247
248 /* Do VBUS pulse after data pulse */
249 fsl_otg_pulse_vbus();
250}
251
252void fsl_otg_pulse_vbus(void)
253{
254 srp_wait_done = 0;
255 fsl_otg_chrg_vbus(1);
256 /* start the timer to end vbus charge */
257 fsl_otg_add_timer(b_vbus_pulse_tmr);
258}
259
260void b_vbus_pulse_end(unsigned long foo)
261{
262 fsl_otg_chrg_vbus(0);
263
264 /*
265 * As USB3300 using the same a_sess_vld and b_sess_vld voltage
266 * we need to discharge the bus for a while to distinguish
267 * residual voltage of vbus pulsing and A device pull up
268 */
269 fsl_otg_dischrg_vbus(1);
270 fsl_otg_add_timer(b_srp_wait_tmr);
271}
272
273void b_srp_end(unsigned long foo)
274{
275 fsl_otg_dischrg_vbus(0);
276 srp_wait_done = 1;
277
278 if ((fsl_otg_dev->otg.state == OTG_STATE_B_SRP_INIT) &&
279 fsl_otg_dev->fsm.b_sess_vld)
280 fsl_otg_dev->fsm.b_srp_done = 1;
281}
282
283/*
284 * Workaround for a_host suspending too fast. When a_bus_req=0,
285 * a_host will start by SRP. It needs to set b_hnp_enable before
286 * actually suspending to start HNP
287 */
288void a_wait_enum(unsigned long foo)
289{
290 VDBG("a_wait_enum timeout\n");
291 if (!fsl_otg_dev->otg.host->b_hnp_enable)
292 fsl_otg_add_timer(a_wait_enum_tmr);
293 else
294 otg_statemachine(&fsl_otg_dev->fsm);
295}
296
297/* The timeout callback function to set time out bit */
298void set_tmout(unsigned long indicator)
299{
300 *(int *)indicator = 1;
301}
302
303/* Initialize timers */
304int fsl_otg_init_timers(struct otg_fsm *fsm)
305{
306 /* FSM used timers */
307 a_wait_vrise_tmr = otg_timer_initializer(&set_tmout, TA_WAIT_VRISE,
308 (unsigned long)&fsm->a_wait_vrise_tmout);
309 if (!a_wait_vrise_tmr)
310 return -ENOMEM;
311
312 a_wait_bcon_tmr = otg_timer_initializer(&set_tmout, TA_WAIT_BCON,
313 (unsigned long)&fsm->a_wait_bcon_tmout);
314 if (!a_wait_bcon_tmr)
315 return -ENOMEM;
316
317 a_aidl_bdis_tmr = otg_timer_initializer(&set_tmout, TA_AIDL_BDIS,
318 (unsigned long)&fsm->a_aidl_bdis_tmout);
319 if (!a_aidl_bdis_tmr)
320 return -ENOMEM;
321
322 b_ase0_brst_tmr = otg_timer_initializer(&set_tmout, TB_ASE0_BRST,
323 (unsigned long)&fsm->b_ase0_brst_tmout);
324 if (!b_ase0_brst_tmr)
325 return -ENOMEM;
326
327 b_se0_srp_tmr = otg_timer_initializer(&set_tmout, TB_SE0_SRP,
328 (unsigned long)&fsm->b_se0_srp);
329 if (!b_se0_srp_tmr)
330 return -ENOMEM;
331
332 b_srp_fail_tmr = otg_timer_initializer(&set_tmout, TB_SRP_FAIL,
333 (unsigned long)&fsm->b_srp_done);
334 if (!b_srp_fail_tmr)
335 return -ENOMEM;
336
337 a_wait_enum_tmr = otg_timer_initializer(&a_wait_enum, 10,
338 (unsigned long)&fsm);
339 if (!a_wait_enum_tmr)
340 return -ENOMEM;
341
342 /* device driver used timers */
343 b_srp_wait_tmr = otg_timer_initializer(&b_srp_end, TB_SRP_WAIT, 0);
344 if (!b_srp_wait_tmr)
345 return -ENOMEM;
346
347 b_data_pulse_tmr = otg_timer_initializer(&b_data_pulse_end,
348 TB_DATA_PLS, 0);
349 if (!b_data_pulse_tmr)
350 return -ENOMEM;
351
352 b_vbus_pulse_tmr = otg_timer_initializer(&b_vbus_pulse_end,
353 TB_VBUS_PLS, 0);
354 if (!b_vbus_pulse_tmr)
355 return -ENOMEM;
356
357 return 0;
358}
359
360/* Uninitialize timers */
361void fsl_otg_uninit_timers(void)
362{
363 /* FSM used timers */
364 if (a_wait_vrise_tmr != NULL)
365 kfree(a_wait_vrise_tmr);
366 if (a_wait_bcon_tmr != NULL)
367 kfree(a_wait_bcon_tmr);
368 if (a_aidl_bdis_tmr != NULL)
369 kfree(a_aidl_bdis_tmr);
370 if (b_ase0_brst_tmr != NULL)
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
379 /* device driver used timers */
380 if (b_srp_wait_tmr != NULL)
381 kfree(b_srp_wait_tmr);
382 if (b_data_pulse_tmr != NULL)
383 kfree(b_data_pulse_tmr);
384 if (b_vbus_pulse_tmr != NULL)
385 kfree(b_vbus_pulse_tmr);
386}
387
388/* Add timer to timer list */
389void fsl_otg_add_timer(void *gtimer)
390{
391 struct fsl_otg_timer *timer = gtimer;
392 struct fsl_otg_timer *tmp_timer;
393
394 /*
395 * Check if the timer is already in the active list,
396 * if so update timer count
397 */
398 list_for_each_entry(tmp_timer, &active_timers, list)
399 if (tmp_timer == timer) {
400 timer->count = timer->expires;
401 return;
402 }
403 timer->count = timer->expires;
404 list_add_tail(&timer->list, &active_timers);
405}
406
407/* Remove timer from the timer list; clear timeout status */
408void fsl_otg_del_timer(void *gtimer)
409{
410 struct fsl_otg_timer *timer = gtimer;
411 struct fsl_otg_timer *tmp_timer, *del_tmp;
412
413 list_for_each_entry_safe(tmp_timer, del_tmp, &active_timers, list)
414 if (tmp_timer == timer)
415 list_del(&timer->list);
416}
417
418/*
419 * Reduce timer count by 1, and find timeout conditions.
420 * Called by fsl_otg 1ms timer interrupt
421 */
422int fsl_otg_tick_timer(void)
423{
424 struct fsl_otg_timer *tmp_timer, *del_tmp;
425 int expired = 0;
426
427 list_for_each_entry_safe(tmp_timer, del_tmp, &active_timers, list) {
428 tmp_timer->count--;
429 /* check if timer expires */
430 if (!tmp_timer->count) {
431 list_del(&tmp_timer->list);
432 tmp_timer->function(tmp_timer->data);
433 expired = 1;
434 }
435 }
436
437 return expired;
438}
439
440/* Reset controller, not reset the bus */
441void otg_reset_controller(void)
442{
443 u32 command;
444
445 command = fsl_readl(&usb_dr_regs->usbcmd);
446 command |= (1 << 1);
447 fsl_writel(command, &usb_dr_regs->usbcmd);
448 while (fsl_readl(&usb_dr_regs->usbcmd) & (1 << 1))
449 ;
450}
451
452/* Call suspend/resume routines in host driver */
453int fsl_otg_start_host(struct otg_fsm *fsm, int on)
454{
455 struct otg_transceiver *xceiv = fsm->transceiver;
456 struct device *dev;
457 struct fsl_otg *otg_dev = container_of(xceiv, struct fsl_otg, otg);
458 u32 retval = 0;
459
460 if (!xceiv->host)
461 return -ENODEV;
462 dev = xceiv->host->controller;
463
464 /*
465 * Update a_vbus_vld state as a_vbus_vld int is disabled
466 * in device mode
467 */
468 fsm->a_vbus_vld =
469 !!(fsl_readl(&usb_dr_regs->otgsc) & OTGSC_STS_A_VBUS_VALID);
470 if (on) {
471 /* start fsl usb host controller */
472 if (otg_dev->host_working)
473 goto end;
474 else {
475 otg_reset_controller();
476 VDBG("host on......\n");
477 if (dev->driver->pm && dev->driver->pm->resume) {
478 retval = dev->driver->pm->resume(dev);
479 if (fsm->id) {
480 /* default-b */
481 fsl_otg_drv_vbus(1);
482 /*
483 * Workaround: b_host can't driver
484 * vbus, but PP in PORTSC needs to
485 * be 1 for host to work.
486 * So we set drv_vbus bit in
487 * transceiver to 0 thru ULPI.
488 */
489 write_ulpi(0x0c, 0x20);
490 }
491 }
492
493 otg_dev->host_working = 1;
494 }
495 } else {
496 /* stop fsl usb host controller */
497 if (!otg_dev->host_working)
498 goto end;
499 else {
500 VDBG("host off......\n");
501 if (dev && dev->driver) {
502 if (dev->driver->pm && dev->driver->pm->suspend)
503 retval = dev->driver->pm->suspend(dev);
504 if (fsm->id)
505 /* default-b */
506 fsl_otg_drv_vbus(0);
507 }
508 otg_dev->host_working = 0;
509 }
510 }
511end:
512 return retval;
513}
514
515/*
516 * Call suspend and resume function in udc driver
517 * to stop and start udc driver.
518 */
519int fsl_otg_start_gadget(struct otg_fsm *fsm, int on)
520{
521 struct otg_transceiver *xceiv = fsm->transceiver;
522 struct device *dev;
523
524 if (!xceiv->gadget || !xceiv->gadget->dev.parent)
525 return -ENODEV;
526
527 VDBG("gadget %s\n", on ? "on" : "off");
528 dev = xceiv->gadget->dev.parent;
529
530 if (on) {
531 if (dev->driver->resume)
532 dev->driver->resume(dev);
533 } else {
534 if (dev->driver->suspend)
535 dev->driver->suspend(dev, otg_suspend_state);
536 }
537
538 return 0;
539}
540
541/*
542 * Called by initialization code of host driver. Register host controller
543 * to the OTG. Suspend host for OTG role detection.
544 */
545static int fsl_otg_set_host(struct otg_transceiver *otg_p, struct usb_bus *host)
546{
547 struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
548
549 if (!otg_p || otg_dev != fsl_otg_dev)
550 return -ENODEV;
551
552 otg_p->host = host;
553
554 otg_dev->fsm.a_bus_drop = 0;
555 otg_dev->fsm.a_bus_req = 1;
556
557 if (host) {
558 VDBG("host off......\n");
559
560 otg_p->host->otg_port = fsl_otg_initdata.otg_port;
561 otg_p->host->is_b_host = otg_dev->fsm.id;
562 /*
563 * must leave time for khubd to finish its thing
564 * before yanking the host driver out from under it,
565 * so suspend the host after a short delay.
566 */
567 otg_dev->host_working = 1;
568 schedule_delayed_work(&otg_dev->otg_event, 100);
569 return 0;
570 } else {
571 /* host driver going away */
572 if (!(fsl_readl(&otg_dev->dr_mem_map->otgsc) &
573 OTGSC_STS_USB_ID)) {
574 /* Mini-A cable connected */
575 struct otg_fsm *fsm = &otg_dev->fsm;
576
577 otg_p->state = OTG_STATE_UNDEFINED;
578 fsm->protocol = PROTO_UNDEF;
579 }
580 }
581
582 otg_dev->host_working = 0;
583
584 otg_statemachine(&otg_dev->fsm);
585
586 return 0;
587}
588
589/* Called by initialization code of udc. Register udc to OTG. */
590static int fsl_otg_set_peripheral(struct otg_transceiver *otg_p,
591 struct usb_gadget *gadget)
592{
593 struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
594
595 VDBG("otg_dev 0x%x\n", (int)otg_dev);
596 VDBG("fsl_otg_dev 0x%x\n", (int)fsl_otg_dev);
597
598 if (!otg_p || otg_dev != fsl_otg_dev)
599 return -ENODEV;
600
601 if (!gadget) {
602 if (!otg_dev->otg.default_a)
603 otg_p->gadget->ops->vbus_draw(otg_p->gadget, 0);
604 usb_gadget_vbus_disconnect(otg_dev->otg.gadget);
605 otg_dev->otg.gadget = 0;
606 otg_dev->fsm.b_bus_req = 0;
607 otg_statemachine(&otg_dev->fsm);
608 return 0;
609 }
610
611 otg_p->gadget = gadget;
612 otg_p->gadget->is_a_peripheral = !otg_dev->fsm.id;
613
614 otg_dev->fsm.b_bus_req = 1;
615
616 /* start the gadget right away if the ID pin says Mini-B */
617 DBG("ID pin=%d\n", otg_dev->fsm.id);
618 if (otg_dev->fsm.id == 1) {
619 fsl_otg_start_host(&otg_dev->fsm, 0);
620 otg_drv_vbus(&otg_dev->fsm, 0);
621 fsl_otg_start_gadget(&otg_dev->fsm, 1);
622 }
623
624 return 0;
625}
626
627/* Set OTG port power, only for B-device */
628static int fsl_otg_set_power(struct otg_transceiver *otg_p, unsigned mA)
629{
630 if (!fsl_otg_dev)
631 return -ENODEV;
632 if (otg_p->state == OTG_STATE_B_PERIPHERAL)
633 pr_info("FSL OTG: Draw %d mA\n", mA);
634
635 return 0;
636}
637
638/*
639 * Delayed pin detect interrupt processing.
640 *
641 * When the Mini-A cable is disconnected from the board,
642 * the pin-detect interrupt happens before the disconnnect
643 * interrupts for the connected device(s). In order to
644 * process the disconnect interrupt(s) prior to switching
645 * roles, the pin-detect interrupts are delayed, and handled
646 * by this routine.
647 */
648static void fsl_otg_event(struct work_struct *work)
649{
650 struct fsl_otg *og = container_of(work, struct fsl_otg, otg_event.work);
651 struct otg_fsm *fsm = &og->fsm;
652
653 if (fsm->id) { /* switch to gadget */
654 fsl_otg_start_host(fsm, 0);
655 otg_drv_vbus(fsm, 0);
656 fsl_otg_start_gadget(fsm, 1);
657 }
658}
659
660/* B-device start SRP */
661static int fsl_otg_start_srp(struct otg_transceiver *otg_p)
662{
663 struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
664
665 if (!otg_p || otg_dev != fsl_otg_dev
666 || otg_p->state != OTG_STATE_B_IDLE)
667 return -ENODEV;
668
669 otg_dev->fsm.b_bus_req = 1;
670 otg_statemachine(&otg_dev->fsm);
671
672 return 0;
673}
674
675/* A_host suspend will call this function to start hnp */
676static int fsl_otg_start_hnp(struct otg_transceiver *otg_p)
677{
678 struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg);
679
680 if (!otg_p || otg_dev != fsl_otg_dev)
681 return -ENODEV;
682
683 DBG("start_hnp...n");
684
685 /* clear a_bus_req to enter a_suspend state */
686 otg_dev->fsm.a_bus_req = 0;
687 otg_statemachine(&otg_dev->fsm);
688
689 return 0;
690}
691
692/*
693 * Interrupt handler. OTG/host/peripheral share the same int line.
694 * OTG driver clears OTGSC interrupts and leaves USB interrupts
695 * intact. It needs to have knowledge of some USB interrupts
696 * such as port change.
697 */
698irqreturn_t fsl_otg_isr(int irq, void *dev_id)
699{
700 struct otg_fsm *fsm = &((struct fsl_otg *)dev_id)->fsm;
701 struct otg_transceiver *otg = &((struct fsl_otg *)dev_id)->otg;
702 u32 otg_int_src, otg_sc;
703
704 otg_sc = fsl_readl(&usb_dr_regs->otgsc);
705 otg_int_src = otg_sc & OTGSC_INTSTS_MASK & (otg_sc >> 8);
706
707 /* Only clear otg interrupts */
708 fsl_writel(otg_sc, &usb_dr_regs->otgsc);
709
710 /*FIXME: ID change not generate when init to 0 */
711 fsm->id = (otg_sc & OTGSC_STS_USB_ID) ? 1 : 0;
712 otg->default_a = (fsm->id == 0);
713
714 /* process OTG interrupts */
715 if (otg_int_src) {
716 if (otg_int_src & OTGSC_INTSTS_USB_ID) {
717 fsm->id = (otg_sc & OTGSC_STS_USB_ID) ? 1 : 0;
718 otg->default_a = (fsm->id == 0);
719 /* clear conn information */
720 if (fsm->id)
721 fsm->b_conn = 0;
722 else
723 fsm->a_conn = 0;
724
725 if (otg->host)
726 otg->host->is_b_host = fsm->id;
727 if (otg->gadget)
728 otg->gadget->is_a_peripheral = !fsm->id;
729 VDBG("ID int (ID is %d)\n", fsm->id);
730
731 if (fsm->id) { /* switch to gadget */
732 schedule_delayed_work(
733 &((struct fsl_otg *)dev_id)->otg_event,
734 100);
735 } else { /* switch to host */
736 cancel_delayed_work(&
737 ((struct fsl_otg *)dev_id)->
738 otg_event);
739 fsl_otg_start_gadget(fsm, 0);
740 otg_drv_vbus(fsm, 1);
741 fsl_otg_start_host(fsm, 1);
742 }
743 return IRQ_HANDLED;
744 }
745 }
746 return IRQ_NONE;
747}
748
749static struct otg_fsm_ops fsl_otg_ops = {
750 .chrg_vbus = fsl_otg_chrg_vbus,
751 .drv_vbus = fsl_otg_drv_vbus,
752 .loc_conn = fsl_otg_loc_conn,
753 .loc_sof = fsl_otg_loc_sof,
754 .start_pulse = fsl_otg_start_pulse,
755
756 .add_timer = fsl_otg_add_timer,
757 .del_timer = fsl_otg_del_timer,
758
759 .start_host = fsl_otg_start_host,
760 .start_gadget = fsl_otg_start_gadget,
761};
762
763/* Initialize the global variable fsl_otg_dev and request IRQ for OTG */
764static int fsl_otg_conf(struct platform_device *pdev)
765{
766 struct fsl_otg *fsl_otg_tc;
767 int status;
768
769 if (fsl_otg_dev)
770 return 0;
771
772 /* allocate space to fsl otg device */
773 fsl_otg_tc = kzalloc(sizeof(struct fsl_otg), GFP_KERNEL);
774 if (!fsl_otg_tc)
775 return -ENOMEM;
776
777 INIT_DELAYED_WORK(&fsl_otg_tc->otg_event, fsl_otg_event);
778
779 INIT_LIST_HEAD(&active_timers);
780 status = fsl_otg_init_timers(&fsl_otg_tc->fsm);
781 if (status) {
782 pr_info("Couldn't init OTG timers\n");
783 goto err;
784 }
785 spin_lock_init(&fsl_otg_tc->fsm.lock);
786
787 /* Set OTG state machine operations */
788 fsl_otg_tc->fsm.ops = &fsl_otg_ops;
789
790 /* initialize the otg structure */
791 fsl_otg_tc->otg.label = DRIVER_DESC;
792 fsl_otg_tc->otg.set_host = fsl_otg_set_host;
793 fsl_otg_tc->otg.set_peripheral = fsl_otg_set_peripheral;
794 fsl_otg_tc->otg.set_power = fsl_otg_set_power;
795 fsl_otg_tc->otg.start_hnp = fsl_otg_start_hnp;
796 fsl_otg_tc->otg.start_srp = fsl_otg_start_srp;
797
798 fsl_otg_dev = fsl_otg_tc;
799
800 /* Store the otg transceiver */
801 status = otg_set_transceiver(&fsl_otg_tc->otg);
802 if (status) {
803 pr_warn(FSL_OTG_NAME ": unable to register OTG transceiver.\n");
804 goto err;
805 }
806
807 return 0;
808err:
809 fsl_otg_uninit_timers();
810 kfree(fsl_otg_tc);
811 return status;
812}
813
814/* OTG Initialization */
815int usb_otg_start(struct platform_device *pdev)
816{
817 struct fsl_otg *p_otg;
818 struct otg_transceiver *otg_trans = otg_get_transceiver();
819 struct otg_fsm *fsm;
820 int status;
821 struct resource *res;
822 u32 temp;
823 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
824
825 p_otg = container_of(otg_trans, struct fsl_otg, otg);
826 fsm = &p_otg->fsm;
827
828 /* Initialize the state machine structure with default values */
829 SET_OTG_STATE(otg_trans, OTG_STATE_UNDEFINED);
830 fsm->transceiver = &p_otg->otg;
831
832 /* We don't require predefined MEM/IRQ resource index */
833 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
834 if (!res)
835 return -ENXIO;
836
837 /* We don't request_mem_region here to enable resource sharing
838 * with host/device */
839
840 usb_dr_regs = ioremap(res->start, sizeof(struct usb_dr_mmap));
841 p_otg->dr_mem_map = (struct usb_dr_mmap *)usb_dr_regs;
842 pdata->regs = (void *)usb_dr_regs;
843
844 if (pdata->init && pdata->init(pdev) != 0)
845 return -EINVAL;
846
847 if (pdata->big_endian_mmio) {
848 _fsl_readl = _fsl_readl_be;
849 _fsl_writel = _fsl_writel_be;
850 } else {
851 _fsl_readl = _fsl_readl_le;
852 _fsl_writel = _fsl_writel_le;
853 }
854
855 /* request irq */
856 p_otg->irq = platform_get_irq(pdev, 0);
857 status = request_irq(p_otg->irq, fsl_otg_isr,
858 IRQF_SHARED, driver_name, p_otg);
859 if (status) {
860 dev_dbg(p_otg->otg.dev, "can't get IRQ %d, error %d\n",
861 p_otg->irq, status);
862 iounmap(p_otg->dr_mem_map);
863 kfree(p_otg);
864 return status;
865 }
866
867 /* stop the controller */
868 temp = fsl_readl(&p_otg->dr_mem_map->usbcmd);
869 temp &= ~USB_CMD_RUN_STOP;
870 fsl_writel(temp, &p_otg->dr_mem_map->usbcmd);
871
872 /* reset the controller */
873 temp = fsl_readl(&p_otg->dr_mem_map->usbcmd);
874 temp |= USB_CMD_CTRL_RESET;
875 fsl_writel(temp, &p_otg->dr_mem_map->usbcmd);
876
877 /* wait reset completed */
878 while (fsl_readl(&p_otg->dr_mem_map->usbcmd) & USB_CMD_CTRL_RESET)
879 ;
880
881 /* configure the VBUSHS as IDLE(both host and device) */
882 temp = USB_MODE_STREAM_DISABLE | (pdata->es ? USB_MODE_ES : 0);
883 fsl_writel(temp, &p_otg->dr_mem_map->usbmode);
884
885 /* configure PHY interface */
886 temp = fsl_readl(&p_otg->dr_mem_map->portsc);
887 temp &= ~(PORTSC_PHY_TYPE_SEL | PORTSC_PTW);
888 switch (pdata->phy_mode) {
889 case FSL_USB2_PHY_ULPI:
890 temp |= PORTSC_PTS_ULPI;
891 break;
892 case FSL_USB2_PHY_UTMI_WIDE:
893 temp |= PORTSC_PTW_16BIT;
894 /* fall through */
895 case FSL_USB2_PHY_UTMI:
896 temp |= PORTSC_PTS_UTMI;
897 /* fall through */
898 default:
899 break;
900 }
901 fsl_writel(temp, &p_otg->dr_mem_map->portsc);
902
903 if (pdata->have_sysif_regs) {
904 /* configure control enable IO output, big endian register */
905 temp = __raw_readl(&p_otg->dr_mem_map->control);
906 temp |= USB_CTRL_IOENB;
907 __raw_writel(temp, &p_otg->dr_mem_map->control);
908 }
909
910 /* disable all interrupt and clear all OTGSC status */
911 temp = fsl_readl(&p_otg->dr_mem_map->otgsc);
912 temp &= ~OTGSC_INTERRUPT_ENABLE_BITS_MASK;
913 temp |= OTGSC_INTERRUPT_STATUS_BITS_MASK | OTGSC_CTRL_VBUS_DISCHARGE;
914 fsl_writel(temp, &p_otg->dr_mem_map->otgsc);
915
916 /*
917 * The identification (id) input is FALSE when a Mini-A plug is inserted
918 * in the devices Mini-AB receptacle. Otherwise, this input is TRUE.
919 * Also: record initial state of ID pin
920 */
921 if (fsl_readl(&p_otg->dr_mem_map->otgsc) & OTGSC_STS_USB_ID) {
922 p_otg->otg.state = OTG_STATE_UNDEFINED;
923 p_otg->fsm.id = 1;
924 } else {
925 p_otg->otg.state = OTG_STATE_A_IDLE;
926 p_otg->fsm.id = 0;
927 }
928
929 DBG("initial ID pin=%d\n", p_otg->fsm.id);
930
931 /* enable OTG ID pin interrupt */
932 temp = fsl_readl(&p_otg->dr_mem_map->otgsc);
933 temp |= OTGSC_INTR_USB_ID_EN;
934 temp &= ~(OTGSC_CTRL_VBUS_DISCHARGE | OTGSC_INTR_1MS_TIMER_EN);
935 fsl_writel(temp, &p_otg->dr_mem_map->otgsc);
936
937 return 0;
938}
939
940/*
941 * state file in sysfs
942 */
943static int show_fsl_usb2_otg_state(struct device *dev,
944 struct device_attribute *attr, char *buf)
945{
946 struct otg_fsm *fsm = &fsl_otg_dev->fsm;
947 char *next = buf;
948 unsigned size = PAGE_SIZE;
949 unsigned long flags;
950 int t;
951
952 spin_lock_irqsave(&fsm->lock, flags);
953
954 /* basic driver infomation */
955 t = scnprintf(next, size,
956 DRIVER_DESC "\n" "fsl_usb2_otg version: %s\n\n",
957 DRIVER_VERSION);
958 size -= t;
959 next += t;
960
961 /* Registers */
962 t = scnprintf(next, size,
963 "OTGSC: 0x%08x\n"
964 "PORTSC: 0x%08x\n"
965 "USBMODE: 0x%08x\n"
966 "USBCMD: 0x%08x\n"
967 "USBSTS: 0x%08x\n"
968 "USBINTR: 0x%08x\n",
969 fsl_readl(&usb_dr_regs->otgsc),
970 fsl_readl(&usb_dr_regs->portsc),
971 fsl_readl(&usb_dr_regs->usbmode),
972 fsl_readl(&usb_dr_regs->usbcmd),
973 fsl_readl(&usb_dr_regs->usbsts),
974 fsl_readl(&usb_dr_regs->usbintr));
975 size -= t;
976 next += t;
977
978 /* State */
979 t = scnprintf(next, size,
980 "OTG state: %s\n\n",
981 otg_state_string(fsl_otg_dev->otg.state));
982 size -= t;
983 next += t;
984
985 /* State Machine Variables */
986 t = scnprintf(next, size,
987 "a_bus_req: %d\n"
988 "b_bus_req: %d\n"
989 "a_bus_resume: %d\n"
990 "a_bus_suspend: %d\n"
991 "a_conn: %d\n"
992 "a_sess_vld: %d\n"
993 "a_srp_det: %d\n"
994 "a_vbus_vld: %d\n"
995 "b_bus_resume: %d\n"
996 "b_bus_suspend: %d\n"
997 "b_conn: %d\n"
998 "b_se0_srp: %d\n"
999 "b_sess_end: %d\n"
1000 "b_sess_vld: %d\n"
1001 "id: %d\n",
1002 fsm->a_bus_req,
1003 fsm->b_bus_req,
1004 fsm->a_bus_resume,
1005 fsm->a_bus_suspend,
1006 fsm->a_conn,
1007 fsm->a_sess_vld,
1008 fsm->a_srp_det,
1009 fsm->a_vbus_vld,
1010 fsm->b_bus_resume,
1011 fsm->b_bus_suspend,
1012 fsm->b_conn,
1013 fsm->b_se0_srp,
1014 fsm->b_sess_end,
1015 fsm->b_sess_vld,
1016 fsm->id);
1017 size -= t;
1018 next += t;
1019
1020 spin_unlock_irqrestore(&fsm->lock, flags);
1021
1022 return PAGE_SIZE - size;
1023}
1024
1025static DEVICE_ATTR(fsl_usb2_otg_state, S_IRUGO, show_fsl_usb2_otg_state, NULL);
1026
1027
1028/* Char driver interface to control some OTG input */
1029
1030/*
1031 * Handle some ioctl command, such as get otg
1032 * status and set host suspend
1033 */
1034static long fsl_otg_ioctl(struct file *file, unsigned int cmd,
1035 unsigned long arg)
1036{
1037 u32 retval = 0;
1038
1039 switch (cmd) {
1040 case GET_OTG_STATUS:
1041 retval = fsl_otg_dev->host_working;
1042 break;
1043
1044 case SET_A_SUSPEND_REQ:
1045 fsl_otg_dev->fsm.a_suspend_req = arg;
1046 break;
1047
1048 case SET_A_BUS_DROP:
1049 fsl_otg_dev->fsm.a_bus_drop = arg;
1050 break;
1051
1052 case SET_A_BUS_REQ:
1053 fsl_otg_dev->fsm.a_bus_req = arg;
1054 break;
1055
1056 case SET_B_BUS_REQ:
1057 fsl_otg_dev->fsm.b_bus_req = arg;
1058 break;
1059
1060 default:
1061 break;
1062 }
1063
1064 otg_statemachine(&fsl_otg_dev->fsm);
1065
1066 return retval;
1067}
1068
1069static int fsl_otg_open(struct inode *inode, struct file *file)
1070{
1071 return 0;
1072}
1073
1074static int fsl_otg_release(struct inode *inode, struct file *file)
1075{
1076 return 0;
1077}
1078
1079static const struct file_operations otg_fops = {
1080 .owner = THIS_MODULE,
1081 .llseek = NULL,
1082 .read = NULL,
1083 .write = NULL,
1084 .unlocked_ioctl = fsl_otg_ioctl,
1085 .open = fsl_otg_open,
1086 .release = fsl_otg_release,
1087};
1088
1089static int __devinit fsl_otg_probe(struct platform_device *pdev)
1090{
1091 int ret;
1092
1093 if (!pdev->dev.platform_data)
1094 return -ENODEV;
1095
1096 /* configure the OTG */
1097 ret = fsl_otg_conf(pdev);
1098 if (ret) {
1099 dev_err(&pdev->dev, "Couldn't configure OTG module\n");
1100 return ret;
1101 }
1102
1103 /* start OTG */
1104 ret = usb_otg_start(pdev);
1105 if (ret) {
1106 dev_err(&pdev->dev, "Can't init FSL OTG device\n");
1107 return ret;
1108 }
1109
1110 ret = register_chrdev(FSL_OTG_MAJOR, FSL_OTG_NAME, &otg_fops);
1111 if (ret) {
1112 dev_err(&pdev->dev, "unable to register FSL OTG device\n");
1113 return ret;
1114 }
1115
1116 ret = device_create_file(&pdev->dev, &dev_attr_fsl_usb2_otg_state);
1117 if (ret)
1118 dev_warn(&pdev->dev, "Can't register sysfs attribute\n");
1119
1120 return ret;
1121}
1122
1123static int __devexit fsl_otg_remove(struct platform_device *pdev)
1124{
1125 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
1126
1127 otg_set_transceiver(NULL);
1128 free_irq(fsl_otg_dev->irq, fsl_otg_dev);
1129
1130 iounmap((void *)usb_dr_regs);
1131
1132 fsl_otg_uninit_timers();
1133 kfree(fsl_otg_dev);
1134
1135 device_remove_file(&pdev->dev, &dev_attr_fsl_usb2_otg_state);
1136
1137 unregister_chrdev(FSL_OTG_MAJOR, FSL_OTG_NAME);
1138
1139 if (pdata->exit)
1140 pdata->exit(pdev);
1141
1142 return 0;
1143}
1144
1145struct platform_driver fsl_otg_driver = {
1146 .probe = fsl_otg_probe,
1147 .remove = __devexit_p(fsl_otg_remove),
1148 .driver = {
1149 .name = driver_name,
1150 .owner = THIS_MODULE,
1151 },
1152};
1153
1154static int __init fsl_usb_otg_init(void)
1155{
1156 pr_info(DRIVER_INFO "\n");
1157 return platform_driver_register(&fsl_otg_driver);
1158}
1159module_init(fsl_usb_otg_init);
1160
1161static void __exit fsl_usb_otg_exit(void)
1162{
1163 platform_driver_unregister(&fsl_otg_driver);
1164}
1165module_exit(fsl_usb_otg_exit);
1166
1167MODULE_DESCRIPTION(DRIVER_INFO);
1168MODULE_AUTHOR(DRIVER_AUTHOR);
1169MODULE_LICENSE("GPL");
diff --git a/drivers/usb/otg/fsl_otg.h b/drivers/usb/otg/fsl_otg.h
new file mode 100644
index 000000000000..3f8ef731aac9
--- /dev/null
+++ b/drivers/usb/otg/fsl_otg.h
@@ -0,0 +1,406 @@
1/* Copyright (C) 2007,2008 Freescale Semiconductor, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2 of the License, or (at your
6 * option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#include "otg_fsm.h"
19#include <linux/usb/otg.h>
20#include <linux/ioctl.h>
21
22/* USB Command Register Bit Masks */
23#define USB_CMD_RUN_STOP (0x1<<0)
24#define USB_CMD_CTRL_RESET (0x1<<1)
25#define USB_CMD_PERIODIC_SCHEDULE_EN (0x1<<4)
26#define USB_CMD_ASYNC_SCHEDULE_EN (0x1<<5)
27#define USB_CMD_INT_AA_DOORBELL (0x1<<6)
28#define USB_CMD_ASP (0x3<<8)
29#define USB_CMD_ASYNC_SCH_PARK_EN (0x1<<11)
30#define USB_CMD_SUTW (0x1<<13)
31#define USB_CMD_ATDTW (0x1<<14)
32#define USB_CMD_ITC (0xFF<<16)
33
34/* bit 15,3,2 are frame list size */
35#define USB_CMD_FRAME_SIZE_1024 (0x0<<15 | 0x0<<2)
36#define USB_CMD_FRAME_SIZE_512 (0x0<<15 | 0x1<<2)
37#define USB_CMD_FRAME_SIZE_256 (0x0<<15 | 0x2<<2)
38#define USB_CMD_FRAME_SIZE_128 (0x0<<15 | 0x3<<2)
39#define USB_CMD_FRAME_SIZE_64 (0x1<<15 | 0x0<<2)
40#define USB_CMD_FRAME_SIZE_32 (0x1<<15 | 0x1<<2)
41#define USB_CMD_FRAME_SIZE_16 (0x1<<15 | 0x2<<2)
42#define USB_CMD_FRAME_SIZE_8 (0x1<<15 | 0x3<<2)
43
44/* bit 9-8 are async schedule park mode count */
45#define USB_CMD_ASP_00 (0x0<<8)
46#define USB_CMD_ASP_01 (0x1<<8)
47#define USB_CMD_ASP_10 (0x2<<8)
48#define USB_CMD_ASP_11 (0x3<<8)
49#define USB_CMD_ASP_BIT_POS (8)
50
51/* bit 23-16 are interrupt threshold control */
52#define USB_CMD_ITC_NO_THRESHOLD (0x00<<16)
53#define USB_CMD_ITC_1_MICRO_FRM (0x01<<16)
54#define USB_CMD_ITC_2_MICRO_FRM (0x02<<16)
55#define USB_CMD_ITC_4_MICRO_FRM (0x04<<16)
56#define USB_CMD_ITC_8_MICRO_FRM (0x08<<16)
57#define USB_CMD_ITC_16_MICRO_FRM (0x10<<16)
58#define USB_CMD_ITC_32_MICRO_FRM (0x20<<16)
59#define USB_CMD_ITC_64_MICRO_FRM (0x40<<16)
60#define USB_CMD_ITC_BIT_POS (16)
61
62/* USB Status Register Bit Masks */
63#define USB_STS_INT (0x1<<0)
64#define USB_STS_ERR (0x1<<1)
65#define USB_STS_PORT_CHANGE (0x1<<2)
66#define USB_STS_FRM_LST_ROLL (0x1<<3)
67#define USB_STS_SYS_ERR (0x1<<4)
68#define USB_STS_IAA (0x1<<5)
69#define USB_STS_RESET_RECEIVED (0x1<<6)
70#define USB_STS_SOF (0x1<<7)
71#define USB_STS_DCSUSPEND (0x1<<8)
72#define USB_STS_HC_HALTED (0x1<<12)
73#define USB_STS_RCL (0x1<<13)
74#define USB_STS_PERIODIC_SCHEDULE (0x1<<14)
75#define USB_STS_ASYNC_SCHEDULE (0x1<<15)
76
77/* USB Interrupt Enable Register Bit Masks */
78#define USB_INTR_INT_EN (0x1<<0)
79#define USB_INTR_ERR_INT_EN (0x1<<1)
80#define USB_INTR_PC_DETECT_EN (0x1<<2)
81#define USB_INTR_FRM_LST_ROLL_EN (0x1<<3)
82#define USB_INTR_SYS_ERR_EN (0x1<<4)
83#define USB_INTR_ASYN_ADV_EN (0x1<<5)
84#define USB_INTR_RESET_EN (0x1<<6)
85#define USB_INTR_SOF_EN (0x1<<7)
86#define USB_INTR_DEVICE_SUSPEND (0x1<<8)
87
88/* Device Address bit masks */
89#define USB_DEVICE_ADDRESS_MASK (0x7F<<25)
90#define USB_DEVICE_ADDRESS_BIT_POS (25)
91/* PORTSC Register Bit Masks,Only one PORT in OTG mode*/
92#define PORTSC_CURRENT_CONNECT_STATUS (0x1<<0)
93#define PORTSC_CONNECT_STATUS_CHANGE (0x1<<1)
94#define PORTSC_PORT_ENABLE (0x1<<2)
95#define PORTSC_PORT_EN_DIS_CHANGE (0x1<<3)
96#define PORTSC_OVER_CURRENT_ACT (0x1<<4)
97#define PORTSC_OVER_CUURENT_CHG (0x1<<5)
98#define PORTSC_PORT_FORCE_RESUME (0x1<<6)
99#define PORTSC_PORT_SUSPEND (0x1<<7)
100#define PORTSC_PORT_RESET (0x1<<8)
101#define PORTSC_LINE_STATUS_BITS (0x3<<10)
102#define PORTSC_PORT_POWER (0x1<<12)
103#define PORTSC_PORT_INDICTOR_CTRL (0x3<<14)
104#define PORTSC_PORT_TEST_CTRL (0xF<<16)
105#define PORTSC_WAKE_ON_CONNECT_EN (0x1<<20)
106#define PORTSC_WAKE_ON_CONNECT_DIS (0x1<<21)
107#define PORTSC_WAKE_ON_OVER_CURRENT (0x1<<22)
108#define PORTSC_PHY_LOW_POWER_SPD (0x1<<23)
109#define PORTSC_PORT_FORCE_FULL_SPEED (0x1<<24)
110#define PORTSC_PORT_SPEED_MASK (0x3<<26)
111#define PORTSC_TRANSCEIVER_WIDTH (0x1<<28)
112#define PORTSC_PHY_TYPE_SEL (0x3<<30)
113/* bit 11-10 are line status */
114#define PORTSC_LINE_STATUS_SE0 (0x0<<10)
115#define PORTSC_LINE_STATUS_JSTATE (0x1<<10)
116#define PORTSC_LINE_STATUS_KSTATE (0x2<<10)
117#define PORTSC_LINE_STATUS_UNDEF (0x3<<10)
118#define PORTSC_LINE_STATUS_BIT_POS (10)
119
120/* bit 15-14 are port indicator control */
121#define PORTSC_PIC_OFF (0x0<<14)
122#define PORTSC_PIC_AMBER (0x1<<14)
123#define PORTSC_PIC_GREEN (0x2<<14)
124#define PORTSC_PIC_UNDEF (0x3<<14)
125#define PORTSC_PIC_BIT_POS (14)
126
127/* bit 19-16 are port test control */
128#define PORTSC_PTC_DISABLE (0x0<<16)
129#define PORTSC_PTC_JSTATE (0x1<<16)
130#define PORTSC_PTC_KSTATE (0x2<<16)
131#define PORTSC_PTC_SEQNAK (0x3<<16)
132#define PORTSC_PTC_PACKET (0x4<<16)
133#define PORTSC_PTC_FORCE_EN (0x5<<16)
134#define PORTSC_PTC_BIT_POS (16)
135
136/* bit 27-26 are port speed */
137#define PORTSC_PORT_SPEED_FULL (0x0<<26)
138#define PORTSC_PORT_SPEED_LOW (0x1<<26)
139#define PORTSC_PORT_SPEED_HIGH (0x2<<26)
140#define PORTSC_PORT_SPEED_UNDEF (0x3<<26)
141#define PORTSC_SPEED_BIT_POS (26)
142
143/* bit 28 is parallel transceiver width for UTMI interface */
144#define PORTSC_PTW (0x1<<28)
145#define PORTSC_PTW_8BIT (0x0<<28)
146#define PORTSC_PTW_16BIT (0x1<<28)
147
148/* bit 31-30 are port transceiver select */
149#define PORTSC_PTS_UTMI (0x0<<30)
150#define PORTSC_PTS_ULPI (0x2<<30)
151#define PORTSC_PTS_FSLS_SERIAL (0x3<<30)
152#define PORTSC_PTS_BIT_POS (30)
153
154#define PORTSC_W1C_BITS \
155 (PORTSC_CONNECT_STATUS_CHANGE | \
156 PORTSC_PORT_EN_DIS_CHANGE | \
157 PORTSC_OVER_CUURENT_CHG)
158
159/* OTG Status Control Register Bit Masks */
160#define OTGSC_CTRL_VBUS_DISCHARGE (0x1<<0)
161#define OTGSC_CTRL_VBUS_CHARGE (0x1<<1)
162#define OTGSC_CTRL_OTG_TERMINATION (0x1<<3)
163#define OTGSC_CTRL_DATA_PULSING (0x1<<4)
164#define OTGSC_CTRL_ID_PULL_EN (0x1<<5)
165#define OTGSC_HA_DATA_PULSE (0x1<<6)
166#define OTGSC_HA_BA (0x1<<7)
167#define OTGSC_STS_USB_ID (0x1<<8)
168#define OTGSC_STS_A_VBUS_VALID (0x1<<9)
169#define OTGSC_STS_A_SESSION_VALID (0x1<<10)
170#define OTGSC_STS_B_SESSION_VALID (0x1<<11)
171#define OTGSC_STS_B_SESSION_END (0x1<<12)
172#define OTGSC_STS_1MS_TOGGLE (0x1<<13)
173#define OTGSC_STS_DATA_PULSING (0x1<<14)
174#define OTGSC_INTSTS_USB_ID (0x1<<16)
175#define OTGSC_INTSTS_A_VBUS_VALID (0x1<<17)
176#define OTGSC_INTSTS_A_SESSION_VALID (0x1<<18)
177#define OTGSC_INTSTS_B_SESSION_VALID (0x1<<19)
178#define OTGSC_INTSTS_B_SESSION_END (0x1<<20)
179#define OTGSC_INTSTS_1MS (0x1<<21)
180#define OTGSC_INTSTS_DATA_PULSING (0x1<<22)
181#define OTGSC_INTR_USB_ID_EN (0x1<<24)
182#define OTGSC_INTR_A_VBUS_VALID_EN (0x1<<25)
183#define OTGSC_INTR_A_SESSION_VALID_EN (0x1<<26)
184#define OTGSC_INTR_B_SESSION_VALID_EN (0x1<<27)
185#define OTGSC_INTR_B_SESSION_END_EN (0x1<<28)
186#define OTGSC_INTR_1MS_TIMER_EN (0x1<<29)
187#define OTGSC_INTR_DATA_PULSING_EN (0x1<<30)
188#define OTGSC_INTSTS_MASK (0x00ff0000)
189
190/* USB MODE Register Bit Masks */
191#define USB_MODE_CTRL_MODE_IDLE (0x0<<0)
192#define USB_MODE_CTRL_MODE_DEVICE (0x2<<0)
193#define USB_MODE_CTRL_MODE_HOST (0x3<<0)
194#define USB_MODE_CTRL_MODE_RSV (0x1<<0)
195#define USB_MODE_SETUP_LOCK_OFF (0x1<<3)
196#define USB_MODE_STREAM_DISABLE (0x1<<4)
197#define USB_MODE_ES (0x1<<2) /* Endian Select */
198
199/* control Register Bit Masks */
200#define USB_CTRL_IOENB (0x1<<2)
201#define USB_CTRL_ULPI_INT0EN (0x1<<0)
202
203/* BCSR5 */
204#define BCSR5_INT_USB (0x02)
205
206/* USB module clk cfg */
207#define SCCR_OFFS (0xA08)
208#define SCCR_USB_CLK_DISABLE (0x00000000) /* USB clk disable */
209#define SCCR_USB_MPHCM_11 (0x00c00000)
210#define SCCR_USB_MPHCM_01 (0x00400000)
211#define SCCR_USB_MPHCM_10 (0x00800000)
212#define SCCR_USB_DRCM_11 (0x00300000)
213#define SCCR_USB_DRCM_01 (0x00100000)
214#define SCCR_USB_DRCM_10 (0x00200000)
215
216#define SICRL_OFFS (0x114)
217#define SICRL_USB0 (0x40000000)
218#define SICRL_USB1 (0x20000000)
219
220#define SICRH_OFFS (0x118)
221#define SICRH_USB_UTMI (0x00020000)
222
223/* OTG interrupt enable bit masks */
224#define OTGSC_INTERRUPT_ENABLE_BITS_MASK \
225 (OTGSC_INTR_USB_ID_EN | \
226 OTGSC_INTR_1MS_TIMER_EN | \
227 OTGSC_INTR_A_VBUS_VALID_EN | \
228 OTGSC_INTR_A_SESSION_VALID_EN | \
229 OTGSC_INTR_B_SESSION_VALID_EN | \
230 OTGSC_INTR_B_SESSION_END_EN | \
231 OTGSC_INTR_DATA_PULSING_EN)
232
233/* OTG interrupt status bit masks */
234#define OTGSC_INTERRUPT_STATUS_BITS_MASK \
235 (OTGSC_INTSTS_USB_ID | \
236 OTGSC_INTR_1MS_TIMER_EN | \
237 OTGSC_INTSTS_A_VBUS_VALID | \
238 OTGSC_INTSTS_A_SESSION_VALID | \
239 OTGSC_INTSTS_B_SESSION_VALID | \
240 OTGSC_INTSTS_B_SESSION_END | \
241 OTGSC_INTSTS_DATA_PULSING)
242
243/*
244 * A-DEVICE timing constants
245 */
246
247/* Wait for VBUS Rise */
248#define TA_WAIT_VRISE (100) /* a_wait_vrise 100 ms, section: 6.6.5.1 */
249
250/* Wait for B-Connect */
251#define TA_WAIT_BCON (10000) /* a_wait_bcon > 1 sec, section: 6.6.5.2
252 * This is only used to get out of
253 * OTG_STATE_A_WAIT_BCON state if there was
254 * no connection for these many milliseconds
255 */
256
257/* A-Idle to B-Disconnect */
258/* It is necessary for this timer to be more than 750 ms because of a bug in OPT
259 * test 5.4 in which B OPT disconnects after 750 ms instead of 75ms as stated
260 * in the test description
261 */
262#define TA_AIDL_BDIS (5000) /* a_suspend minimum 200 ms, section: 6.6.5.3 */
263
264/* B-Idle to A-Disconnect */
265#define TA_BIDL_ADIS (12) /* 3 to 200 ms */
266
267/* B-device timing constants */
268
269
270/* Data-Line Pulse Time*/
271#define TB_DATA_PLS (10) /* b_srp_init,continue 5~10ms, section:5.3.3 */
272#define TB_DATA_PLS_MIN (5) /* minimum 5 ms */
273#define TB_DATA_PLS_MAX (10) /* maximum 10 ms */
274
275/* SRP Initiate Time */
276#define TB_SRP_INIT (100) /* b_srp_init,maximum 100 ms, section:5.3.8 */
277
278/* SRP Fail Time */
279#define TB_SRP_FAIL (7000) /* b_srp_init,Fail time 5~30s, section:6.8.2.2*/
280
281/* SRP result wait time */
282#define TB_SRP_WAIT (60)
283
284/* VBus time */
285#define TB_VBUS_PLS (30) /* time to keep vbus pulsing asserted */
286
287/* Discharge time */
288/* This time should be less than 10ms. It varies from system to system. */
289#define TB_VBUS_DSCHRG (8)
290
291/* A-SE0 to B-Reset */
292#define TB_ASE0_BRST (20) /* b_wait_acon, mini 3.125 ms,section:6.8.2.4 */
293
294/* A bus suspend timer before we can switch to b_wait_aconn */
295#define TB_A_SUSPEND (7)
296#define TB_BUS_RESUME (12)
297
298/* SE0 Time Before SRP */
299#define TB_SE0_SRP (2) /* b_idle,minimum 2 ms, section:5.3.2 */
300
301#define SET_OTG_STATE(otg_ptr, newstate) ((otg_ptr)->state = newstate)
302
303struct usb_dr_mmap {
304 /* Capability register */
305 u8 res1[256];
306 u16 caplength; /* Capability Register Length */
307 u16 hciversion; /* Host Controller Interface Version */
308 u32 hcsparams; /* Host Controller Structual Parameters */
309 u32 hccparams; /* Host Controller Capability Parameters */
310 u8 res2[20];
311 u32 dciversion; /* Device Controller Interface Version */
312 u32 dccparams; /* Device Controller Capability Parameters */
313 u8 res3[24];
314 /* Operation register */
315 u32 usbcmd; /* USB Command Register */
316 u32 usbsts; /* USB Status Register */
317 u32 usbintr; /* USB Interrupt Enable Register */
318 u32 frindex; /* Frame Index Register */
319 u8 res4[4];
320 u32 deviceaddr; /* Device Address */
321 u32 endpointlistaddr; /* Endpoint List Address Register */
322 u8 res5[4];
323 u32 burstsize; /* Master Interface Data Burst Size Register */
324 u32 txttfilltuning; /* Transmit FIFO Tuning Controls Register */
325 u8 res6[8];
326 u32 ulpiview; /* ULPI register access */
327 u8 res7[12];
328 u32 configflag; /* Configure Flag Register */
329 u32 portsc; /* Port 1 Status and Control Register */
330 u8 res8[28];
331 u32 otgsc; /* On-The-Go Status and Control */
332 u32 usbmode; /* USB Mode Register */
333 u32 endptsetupstat; /* Endpoint Setup Status Register */
334 u32 endpointprime; /* Endpoint Initialization Register */
335 u32 endptflush; /* Endpoint Flush Register */
336 u32 endptstatus; /* Endpoint Status Register */
337 u32 endptcomplete; /* Endpoint Complete Register */
338 u32 endptctrl[6]; /* Endpoint Control Registers */
339 u8 res9[552];
340 u32 snoop1;
341 u32 snoop2;
342 u32 age_cnt_thresh; /* Age Count Threshold Register */
343 u32 pri_ctrl; /* Priority Control Register */
344 u32 si_ctrl; /* System Interface Control Register */
345 u8 res10[236];
346 u32 control; /* General Purpose Control Register */
347};
348
349struct fsl_otg_timer {
350 unsigned long expires; /* Number of count increase to timeout */
351 unsigned long count; /* Tick counter */
352 void (*function)(unsigned long); /* Timeout function */
353 unsigned long data; /* Data passed to function */
354 struct list_head list;
355};
356
357inline struct fsl_otg_timer *otg_timer_initializer
358(void (*function)(unsigned long), unsigned long expires, unsigned long data)
359{
360 struct fsl_otg_timer *timer;
361
362 timer = kmalloc(sizeof(struct fsl_otg_timer), GFP_KERNEL);
363 if (!timer)
364 return NULL;
365 timer->function = function;
366 timer->expires = expires;
367 timer->data = data;
368 return timer;
369}
370
371struct fsl_otg {
372 struct otg_transceiver otg;
373 struct otg_fsm fsm;
374 struct usb_dr_mmap *dr_mem_map;
375 struct delayed_work otg_event;
376
377 /* used for usb host */
378 struct work_struct work_wq;
379 u8 host_working;
380
381 int irq;
382};
383
384struct fsl_otg_config {
385 u8 otg_port;
386};
387
388/* For SRP and HNP handle */
389#define FSL_OTG_MAJOR 240
390#define FSL_OTG_NAME "fsl-usb2-otg"
391/* Command to OTG driver ioctl */
392#define OTG_IOCTL_MAGIC FSL_OTG_MAJOR
393/* if otg work as host, it should return 1, otherwise return 0 */
394#define GET_OTG_STATUS _IOR(OTG_IOCTL_MAGIC, 1, int)
395#define SET_A_SUSPEND_REQ _IOW(OTG_IOCTL_MAGIC, 2, int)
396#define SET_A_BUS_DROP _IOW(OTG_IOCTL_MAGIC, 3, int)
397#define SET_A_BUS_REQ _IOW(OTG_IOCTL_MAGIC, 4, int)
398#define SET_B_BUS_REQ _IOW(OTG_IOCTL_MAGIC, 5, int)
399#define GET_A_SUSPEND_REQ _IOR(OTG_IOCTL_MAGIC, 6, int)
400#define GET_A_BUS_DROP _IOR(OTG_IOCTL_MAGIC, 7, int)
401#define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int)
402#define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int)
403
404void fsl_otg_add_timer(void *timer);
405void fsl_otg_del_timer(void *timer);
406void fsl_otg_pulse_vbus(void);
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c
index 221c44444ec6..52733d9959b4 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/otg/gpio_vbus.c
@@ -279,6 +279,13 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
279 } 279 }
280 INIT_WORK(&gpio_vbus->work, gpio_vbus_work); 280 INIT_WORK(&gpio_vbus->work, gpio_vbus_work);
281 281
282 gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw");
283 if (IS_ERR(gpio_vbus->vbus_draw)) {
284 dev_dbg(&pdev->dev, "can't get vbus_draw regulator, err: %ld\n",
285 PTR_ERR(gpio_vbus->vbus_draw));
286 gpio_vbus->vbus_draw = NULL;
287 }
288
282 /* only active when a gadget is registered */ 289 /* only active when a gadget is registered */
283 err = otg_set_transceiver(&gpio_vbus->otg); 290 err = otg_set_transceiver(&gpio_vbus->otg);
284 if (err) { 291 if (err) {
@@ -287,13 +294,6 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
287 goto err_otg; 294 goto err_otg;
288 } 295 }
289 296
290 gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw");
291 if (IS_ERR(gpio_vbus->vbus_draw)) {
292 dev_dbg(&pdev->dev, "can't get vbus_draw regulator, err: %ld\n",
293 PTR_ERR(gpio_vbus->vbus_draw));
294 gpio_vbus->vbus_draw = NULL;
295 }
296
297 return 0; 297 return 0;
298err_otg: 298err_otg:
299 free_irq(irq, &pdev->dev); 299 free_irq(irq, &pdev->dev);
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c
index 456969492410..8c282258e1bd 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/otg/isp1301_omap.c
@@ -234,29 +234,9 @@ isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
234 234
235/*-------------------------------------------------------------------------*/ 235/*-------------------------------------------------------------------------*/
236 236
237static const char *state_string(enum usb_otg_state state)
238{
239 switch (state) {
240 case OTG_STATE_A_IDLE: return "a_idle";
241 case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
242 case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
243 case OTG_STATE_A_HOST: return "a_host";
244 case OTG_STATE_A_SUSPEND: return "a_suspend";
245 case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
246 case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
247 case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
248 case OTG_STATE_B_IDLE: return "b_idle";
249 case OTG_STATE_B_SRP_INIT: return "b_srp_init";
250 case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
251 case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
252 case OTG_STATE_B_HOST: return "b_host";
253 default: return "UNDEFINED";
254 }
255}
256
257static inline const char *state_name(struct isp1301 *isp) 237static inline const char *state_name(struct isp1301 *isp)
258{ 238{
259 return state_string(isp->otg.state); 239 return otg_state_string(isp->otg.state);
260} 240}
261 241
262/*-------------------------------------------------------------------------*/ 242/*-------------------------------------------------------------------------*/
@@ -501,7 +481,7 @@ static void check_state(struct isp1301 *isp, const char *tag)
501 if (isp->otg.state == state && !extra) 481 if (isp->otg.state == state && !extra)
502 return; 482 return;
503 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, 483 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
504 state_string(state), fsm, state_name(isp), 484 otg_state_string(state), fsm, state_name(isp),
505 omap_readl(OTG_CTRL)); 485 omap_readl(OTG_CTRL));
506} 486}
507 487
@@ -1095,7 +1075,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
1095 1075
1096 if (state != isp->otg.state) 1076 if (state != isp->otg.state)
1097 pr_debug(" isp, %s -> %s\n", 1077 pr_debug(" isp, %s -> %s\n",
1098 state_string(state), state_name(isp)); 1078 otg_state_string(state), state_name(isp));
1099 1079
1100#ifdef CONFIG_USB_OTG 1080#ifdef CONFIG_USB_OTG
1101 /* update the OTG controller state to match the isp1301; may 1081 /* update the OTG controller state to match the isp1301; may
@@ -1247,7 +1227,7 @@ static int __exit isp1301_remove(struct i2c_client *i2c)
1247 isp->timer.data = 0; 1227 isp->timer.data = 0;
1248 set_bit(WORK_STOP, &isp->todo); 1228 set_bit(WORK_STOP, &isp->todo);
1249 del_timer_sync(&isp->timer); 1229 del_timer_sync(&isp->timer);
1250 flush_scheduled_work(); 1230 flush_work_sync(&isp->work);
1251 1231
1252 put_device(&i2c->dev); 1232 put_device(&i2c->dev);
1253 the_transceiver = NULL; 1233 the_transceiver = NULL;
@@ -1510,7 +1490,7 @@ isp1301_start_hnp(struct otg_transceiver *dev)
1510 1490
1511/*-------------------------------------------------------------------------*/ 1491/*-------------------------------------------------------------------------*/
1512 1492
1513static int __init 1493static int __devinit
1514isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id) 1494isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
1515{ 1495{
1516 int status; 1496 int status;
@@ -1531,7 +1511,7 @@ isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
1531 i2c_set_clientdata(i2c, isp); 1511 i2c_set_clientdata(i2c, isp);
1532 isp->client = i2c; 1512 isp->client = i2c;
1533 1513
1534 /* verify the chip (shouldn't be necesary) */ 1514 /* verify the chip (shouldn't be necessary) */
1535 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID); 1515 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1536 if (status != I2C_VENDOR_ID_PHILIPS) { 1516 if (status != I2C_VENDOR_ID_PHILIPS) {
1537 dev_dbg(&i2c->dev, "not philips id: %d\n", status); 1517 dev_dbg(&i2c->dev, "not philips id: %d\n", status);
diff --git a/drivers/usb/otg/langwell_otg.c b/drivers/usb/otg/langwell_otg.c
new file mode 100644
index 000000000000..f08f784086f7
--- /dev/null
+++ b/drivers/usb/otg/langwell_otg.c
@@ -0,0 +1,2347 @@
1/*
2 * Intel Langwell USB OTG transceiver driver
3 * Copyright (C) 2008 - 2010, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 */
19/* This driver helps to switch Langwell OTG controller function between host
20 * and peripheral. It works with EHCI driver and Langwell client controller
21 * driver together.
22 */
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/pci.h>
26#include <linux/errno.h>
27#include <linux/interrupt.h>
28#include <linux/kernel.h>
29#include <linux/device.h>
30#include <linux/moduleparam.h>
31#include <linux/usb/ch9.h>
32#include <linux/usb/gadget.h>
33#include <linux/usb.h>
34#include <linux/usb/otg.h>
35#include <linux/usb/hcd.h>
36#include <linux/notifier.h>
37#include <linux/delay.h>
38#include <asm/intel_scu_ipc.h>
39
40#include <linux/usb/langwell_otg.h>
41
42#define DRIVER_DESC "Intel Langwell USB OTG transceiver driver"
43#define DRIVER_VERSION "July 10, 2010"
44
45MODULE_DESCRIPTION(DRIVER_DESC);
46MODULE_AUTHOR("Henry Yuan <hang.yuan@intel.com>, Hao Wu <hao.wu@intel.com>");
47MODULE_VERSION(DRIVER_VERSION);
48MODULE_LICENSE("GPL");
49
50static const char driver_name[] = "langwell_otg";
51
52static int langwell_otg_probe(struct pci_dev *pdev,
53 const struct pci_device_id *id);
54static void langwell_otg_remove(struct pci_dev *pdev);
55static int langwell_otg_suspend(struct pci_dev *pdev, pm_message_t message);
56static int langwell_otg_resume(struct pci_dev *pdev);
57
58static int langwell_otg_set_host(struct otg_transceiver *otg,
59 struct usb_bus *host);
60static int langwell_otg_set_peripheral(struct otg_transceiver *otg,
61 struct usb_gadget *gadget);
62static int langwell_otg_start_srp(struct otg_transceiver *otg);
63
64static const struct pci_device_id pci_ids[] = {{
65 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
66 .class_mask = ~0,
67 .vendor = 0x8086,
68 .device = 0x0811,
69 .subvendor = PCI_ANY_ID,
70 .subdevice = PCI_ANY_ID,
71}, { /* end: all zeroes */ }
72};
73
74static struct pci_driver otg_pci_driver = {
75 .name = (char *) driver_name,
76 .id_table = pci_ids,
77
78 .probe = langwell_otg_probe,
79 .remove = langwell_otg_remove,
80
81 .suspend = langwell_otg_suspend,
82 .resume = langwell_otg_resume,
83};
84
85/* HSM timers */
86static inline struct langwell_otg_timer *otg_timer_initializer
87(void (*function)(unsigned long), unsigned long expires, unsigned long data)
88{
89 struct langwell_otg_timer *timer;
90 timer = kmalloc(sizeof(struct langwell_otg_timer), GFP_KERNEL);
91 if (timer == NULL)
92 return timer;
93
94 timer->function = function;
95 timer->expires = expires;
96 timer->data = data;
97 return timer;
98}
99
100static struct langwell_otg_timer *a_wait_vrise_tmr, *a_aidl_bdis_tmr,
101 *b_se0_srp_tmr, *b_srp_init_tmr;
102
103static struct list_head active_timers;
104
105static struct langwell_otg *the_transceiver;
106
107/* host/client notify transceiver when event affects HNP state */
108void langwell_update_transceiver(void)
109{
110 struct langwell_otg *lnw = the_transceiver;
111
112 dev_dbg(lnw->dev, "transceiver is updated\n");
113
114 if (!lnw->qwork)
115 return ;
116
117 queue_work(lnw->qwork, &lnw->work);
118}
119EXPORT_SYMBOL(langwell_update_transceiver);
120
121static int langwell_otg_set_host(struct otg_transceiver *otg,
122 struct usb_bus *host)
123{
124 otg->host = host;
125
126 return 0;
127}
128
129static int langwell_otg_set_peripheral(struct otg_transceiver *otg,
130 struct usb_gadget *gadget)
131{
132 otg->gadget = gadget;
133
134 return 0;
135}
136
137static int langwell_otg_set_power(struct otg_transceiver *otg,
138 unsigned mA)
139{
140 return 0;
141}
142
143/* A-device drives vbus, controlled through IPC commands */
144static int langwell_otg_set_vbus(struct otg_transceiver *otg, bool enabled)
145{
146 struct langwell_otg *lnw = the_transceiver;
147 u8 sub_id;
148
149 dev_dbg(lnw->dev, "%s <--- %s\n", __func__, enabled ? "on" : "off");
150
151 if (enabled)
152 sub_id = 0x8; /* Turn on the VBus */
153 else
154 sub_id = 0x9; /* Turn off the VBus */
155
156 if (intel_scu_ipc_simple_command(0xef, sub_id)) {
157 dev_dbg(lnw->dev, "Failed to set Vbus via IPC commands\n");
158 return -EBUSY;
159 }
160
161 dev_dbg(lnw->dev, "%s --->\n", __func__);
162
163 return 0;
164}
165
166/* charge vbus or discharge vbus through a resistor to ground */
167static void langwell_otg_chrg_vbus(int on)
168{
169 struct langwell_otg *lnw = the_transceiver;
170 u32 val;
171
172 val = readl(lnw->iotg.base + CI_OTGSC);
173
174 if (on)
175 writel((val & ~OTGSC_INTSTS_MASK) | OTGSC_VC,
176 lnw->iotg.base + CI_OTGSC);
177 else
178 writel((val & ~OTGSC_INTSTS_MASK) | OTGSC_VD,
179 lnw->iotg.base + CI_OTGSC);
180}
181
182/* Start SRP */
183static int langwell_otg_start_srp(struct otg_transceiver *otg)
184{
185 struct langwell_otg *lnw = the_transceiver;
186 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
187 u32 val;
188
189 dev_dbg(lnw->dev, "%s --->\n", __func__);
190
191 val = readl(iotg->base + CI_OTGSC);
192
193 writel((val & ~OTGSC_INTSTS_MASK) | OTGSC_HADP,
194 iotg->base + CI_OTGSC);
195
196 /* Check if the data plus is finished or not */
197 msleep(8);
198 val = readl(iotg->base + CI_OTGSC);
199 if (val & (OTGSC_HADP | OTGSC_DP))
200 dev_dbg(lnw->dev, "DataLine SRP Error\n");
201
202 /* Disable interrupt - b_sess_vld */
203 val = readl(iotg->base + CI_OTGSC);
204 val &= (~(OTGSC_BSVIE | OTGSC_BSEIE));
205 writel(val, iotg->base + CI_OTGSC);
206
207 /* Start VBus SRP, drive vbus to generate VBus pulse */
208 iotg->otg.set_vbus(&iotg->otg, true);
209 msleep(15);
210 iotg->otg.set_vbus(&iotg->otg, false);
211
212 /* Enable interrupt - b_sess_vld*/
213 val = readl(iotg->base + CI_OTGSC);
214 dev_dbg(lnw->dev, "after VBUS pulse otgsc = %x\n", val);
215
216 val |= (OTGSC_BSVIE | OTGSC_BSEIE);
217 writel(val, iotg->base + CI_OTGSC);
218
219 /* If Vbus is valid, then update the hsm */
220 if (val & OTGSC_BSV) {
221 dev_dbg(lnw->dev, "no b_sess_vld interrupt\n");
222
223 lnw->iotg.hsm.b_sess_vld = 1;
224 langwell_update_transceiver();
225 }
226
227 dev_dbg(lnw->dev, "%s <---\n", __func__);
228 return 0;
229}
230
231/* stop SOF via bus_suspend */
232static void langwell_otg_loc_sof(int on)
233{
234 struct langwell_otg *lnw = the_transceiver;
235 struct usb_hcd *hcd;
236 int err;
237
238 dev_dbg(lnw->dev, "%s ---> %s\n", __func__, on ? "suspend" : "resume");
239
240 hcd = bus_to_hcd(lnw->iotg.otg.host);
241 if (on)
242 err = hcd->driver->bus_resume(hcd);
243 else
244 err = hcd->driver->bus_suspend(hcd);
245
246 if (err)
247 dev_dbg(lnw->dev, "Fail to resume/suspend USB bus - %d\n", err);
248
249 dev_dbg(lnw->dev, "%s <---\n", __func__);
250}
251
252static int langwell_otg_check_otgsc(void)
253{
254 struct langwell_otg *lnw = the_transceiver;
255 u32 otgsc, usbcfg;
256
257 dev_dbg(lnw->dev, "check sync OTGSC and USBCFG registers\n");
258
259 otgsc = readl(lnw->iotg.base + CI_OTGSC);
260 usbcfg = readl(lnw->usbcfg);
261
262 dev_dbg(lnw->dev, "OTGSC = %08x, USBCFG = %08x\n",
263 otgsc, usbcfg);
264 dev_dbg(lnw->dev, "OTGSC_AVV = %d\n", !!(otgsc & OTGSC_AVV));
265 dev_dbg(lnw->dev, "USBCFG.VBUSVAL = %d\n",
266 !!(usbcfg & USBCFG_VBUSVAL));
267 dev_dbg(lnw->dev, "OTGSC_ASV = %d\n", !!(otgsc & OTGSC_ASV));
268 dev_dbg(lnw->dev, "USBCFG.AVALID = %d\n",
269 !!(usbcfg & USBCFG_AVALID));
270 dev_dbg(lnw->dev, "OTGSC_BSV = %d\n", !!(otgsc & OTGSC_BSV));
271 dev_dbg(lnw->dev, "USBCFG.BVALID = %d\n",
272 !!(usbcfg & USBCFG_BVALID));
273 dev_dbg(lnw->dev, "OTGSC_BSE = %d\n", !!(otgsc & OTGSC_BSE));
274 dev_dbg(lnw->dev, "USBCFG.SESEND = %d\n",
275 !!(usbcfg & USBCFG_SESEND));
276
277 /* Check USBCFG VBusValid/AValid/BValid/SessEnd */
278 if (!!(otgsc & OTGSC_AVV) ^ !!(usbcfg & USBCFG_VBUSVAL)) {
279 dev_dbg(lnw->dev, "OTGSC.AVV != USBCFG.VBUSVAL\n");
280 goto err;
281 }
282 if (!!(otgsc & OTGSC_ASV) ^ !!(usbcfg & USBCFG_AVALID)) {
283 dev_dbg(lnw->dev, "OTGSC.ASV != USBCFG.AVALID\n");
284 goto err;
285 }
286 if (!!(otgsc & OTGSC_BSV) ^ !!(usbcfg & USBCFG_BVALID)) {
287 dev_dbg(lnw->dev, "OTGSC.BSV != USBCFG.BVALID\n");
288 goto err;
289 }
290 if (!!(otgsc & OTGSC_BSE) ^ !!(usbcfg & USBCFG_SESEND)) {
291 dev_dbg(lnw->dev, "OTGSC.BSE != USBCFG.SESSEN\n");
292 goto err;
293 }
294
295 dev_dbg(lnw->dev, "OTGSC and USBCFG are synced\n");
296
297 return 0;
298
299err:
300 dev_warn(lnw->dev, "OTGSC isn't equal to USBCFG\n");
301 return -EPIPE;
302}
303
304
305static void langwell_otg_phy_low_power(int on)
306{
307 struct langwell_otg *lnw = the_transceiver;
308 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
309 u8 val, phcd;
310 int retval;
311
312 dev_dbg(lnw->dev, "%s ---> %s mode\n",
313 __func__, on ? "Low power" : "Normal");
314
315 phcd = 0x40;
316
317 val = readb(iotg->base + CI_HOSTPC1 + 2);
318
319 if (on) {
320 /* Due to hardware issue, after set PHCD, sync will failed
321 * between USBCFG and OTGSC, so before set PHCD, check if
322 * sync is in process now. If the answer is "yes", then do
323 * not touch PHCD bit */
324 retval = langwell_otg_check_otgsc();
325 if (retval) {
326 dev_dbg(lnw->dev, "Skip PHCD programming..\n");
327 return ;
328 }
329
330 writeb(val | phcd, iotg->base + CI_HOSTPC1 + 2);
331 } else
332 writeb(val & ~phcd, iotg->base + CI_HOSTPC1 + 2);
333
334 dev_dbg(lnw->dev, "%s <--- done\n", __func__);
335}
336
337/* After drv vbus, add 5 ms delay to set PHCD */
338static void langwell_otg_phy_low_power_wait(int on)
339{
340 struct langwell_otg *lnw = the_transceiver;
341
342 dev_dbg(lnw->dev, "add 5ms delay before programing PHCD\n");
343
344 mdelay(5);
345 langwell_otg_phy_low_power(on);
346}
347
348/* Enable/Disable OTG interrupt */
349static void langwell_otg_intr(int on)
350{
351 struct langwell_otg *lnw = the_transceiver;
352 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
353 u32 val;
354
355 dev_dbg(lnw->dev, "%s ---> %s\n", __func__, on ? "on" : "off");
356
357 val = readl(iotg->base + CI_OTGSC);
358
359 /* OTGSC_INT_MASK doesn't contains 1msInt */
360 if (on) {
361 val = val | (OTGSC_INT_MASK);
362 writel(val, iotg->base + CI_OTGSC);
363 } else {
364 val = val & ~(OTGSC_INT_MASK);
365 writel(val, iotg->base + CI_OTGSC);
366 }
367
368 dev_dbg(lnw->dev, "%s <---\n", __func__);
369}
370
371/* set HAAR: Hardware Assist Auto-Reset */
372static void langwell_otg_HAAR(int on)
373{
374 struct langwell_otg *lnw = the_transceiver;
375 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
376 u32 val;
377
378 dev_dbg(lnw->dev, "%s ---> %s\n", __func__, on ? "on" : "off");
379
380 val = readl(iotg->base + CI_OTGSC);
381 if (on)
382 writel((val & ~OTGSC_INTSTS_MASK) | OTGSC_HAAR,
383 iotg->base + CI_OTGSC);
384 else
385 writel((val & ~OTGSC_INTSTS_MASK) & ~OTGSC_HAAR,
386 iotg->base + CI_OTGSC);
387
388 dev_dbg(lnw->dev, "%s <---\n", __func__);
389}
390
391/* set HABA: Hardware Assist B-Disconnect to A-Connect */
392static void langwell_otg_HABA(int on)
393{
394 struct langwell_otg *lnw = the_transceiver;
395 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
396 u32 val;
397
398 dev_dbg(lnw->dev, "%s ---> %s\n", __func__, on ? "on" : "off");
399
400 val = readl(iotg->base + CI_OTGSC);
401 if (on)
402 writel((val & ~OTGSC_INTSTS_MASK) | OTGSC_HABA,
403 iotg->base + CI_OTGSC);
404 else
405 writel((val & ~OTGSC_INTSTS_MASK) & ~OTGSC_HABA,
406 iotg->base + CI_OTGSC);
407
408 dev_dbg(lnw->dev, "%s <---\n", __func__);
409}
410
411static int langwell_otg_check_se0_srp(int on)
412{
413 struct langwell_otg *lnw = the_transceiver;
414 int delay_time = TB_SE0_SRP * 10;
415 u32 val;
416
417 dev_dbg(lnw->dev, "%s --->\n", __func__);
418
419 do {
420 udelay(100);
421 if (!delay_time--)
422 break;
423 val = readl(lnw->iotg.base + CI_PORTSC1);
424 val &= PORTSC_LS;
425 } while (!val);
426
427 dev_dbg(lnw->dev, "%s <---\n", __func__);
428 return val;
429}
430
431/* The timeout callback function to set time out bit */
432static void set_tmout(unsigned long indicator)
433{
434 *(int *)indicator = 1;
435}
436
437void langwell_otg_nsf_msg(unsigned long indicator)
438{
439 struct langwell_otg *lnw = the_transceiver;
440
441 switch (indicator) {
442 case 2:
443 case 4:
444 case 6:
445 case 7:
446 dev_warn(lnw->dev,
447 "OTG:NSF-%lu - deivce not responding\n", indicator);
448 break;
449 case 3:
450 dev_warn(lnw->dev,
451 "OTG:NSF-%lu - deivce not supported\n", indicator);
452 break;
453 default:
454 dev_warn(lnw->dev, "Do not have this kind of NSF\n");
455 break;
456 }
457}
458
459/* Initialize timers */
460static int langwell_otg_init_timers(struct otg_hsm *hsm)
461{
462 /* HSM used timers */
463 a_wait_vrise_tmr = otg_timer_initializer(&set_tmout, TA_WAIT_VRISE,
464 (unsigned long)&hsm->a_wait_vrise_tmout);
465 if (a_wait_vrise_tmr == NULL)
466 return -ENOMEM;
467 a_aidl_bdis_tmr = otg_timer_initializer(&set_tmout, TA_AIDL_BDIS,
468 (unsigned long)&hsm->a_aidl_bdis_tmout);
469 if (a_aidl_bdis_tmr == NULL)
470 return -ENOMEM;
471 b_se0_srp_tmr = otg_timer_initializer(&set_tmout, TB_SE0_SRP,
472 (unsigned long)&hsm->b_se0_srp);
473 if (b_se0_srp_tmr == NULL)
474 return -ENOMEM;
475 b_srp_init_tmr = otg_timer_initializer(&set_tmout, TB_SRP_INIT,
476 (unsigned long)&hsm->b_srp_init_tmout);
477 if (b_srp_init_tmr == NULL)
478 return -ENOMEM;
479
480 return 0;
481}
482
483/* Free timers */
484static void langwell_otg_free_timers(void)
485{
486 kfree(a_wait_vrise_tmr);
487 kfree(a_aidl_bdis_tmr);
488 kfree(b_se0_srp_tmr);
489 kfree(b_srp_init_tmr);
490}
491
492/* The timeout callback function to set time out bit */
493static void langwell_otg_timer_fn(unsigned long indicator)
494{
495 struct langwell_otg *lnw = the_transceiver;
496
497 *(int *)indicator = 1;
498
499 dev_dbg(lnw->dev, "kernel timer - timeout\n");
500
501 langwell_update_transceiver();
502}
503
504/* kernel timer used instead of HW based interrupt */
505static void langwell_otg_add_ktimer(enum langwell_otg_timer_type timers)
506{
507 struct langwell_otg *lnw = the_transceiver;
508 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
509 unsigned long j = jiffies;
510 unsigned long data, time;
511
512 switch (timers) {
513 case TA_WAIT_VRISE_TMR:
514 iotg->hsm.a_wait_vrise_tmout = 0;
515 data = (unsigned long)&iotg->hsm.a_wait_vrise_tmout;
516 time = TA_WAIT_VRISE;
517 break;
518 case TA_WAIT_BCON_TMR:
519 iotg->hsm.a_wait_bcon_tmout = 0;
520 data = (unsigned long)&iotg->hsm.a_wait_bcon_tmout;
521 time = TA_WAIT_BCON;
522 break;
523 case TA_AIDL_BDIS_TMR:
524 iotg->hsm.a_aidl_bdis_tmout = 0;
525 data = (unsigned long)&iotg->hsm.a_aidl_bdis_tmout;
526 time = TA_AIDL_BDIS;
527 break;
528 case TB_ASE0_BRST_TMR:
529 iotg->hsm.b_ase0_brst_tmout = 0;
530 data = (unsigned long)&iotg->hsm.b_ase0_brst_tmout;
531 time = TB_ASE0_BRST;
532 break;
533 case TB_SRP_INIT_TMR:
534 iotg->hsm.b_srp_init_tmout = 0;
535 data = (unsigned long)&iotg->hsm.b_srp_init_tmout;
536 time = TB_SRP_INIT;
537 break;
538 case TB_SRP_FAIL_TMR:
539 iotg->hsm.b_srp_fail_tmout = 0;
540 data = (unsigned long)&iotg->hsm.b_srp_fail_tmout;
541 time = TB_SRP_FAIL;
542 break;
543 case TB_BUS_SUSPEND_TMR:
544 iotg->hsm.b_bus_suspend_tmout = 0;
545 data = (unsigned long)&iotg->hsm.b_bus_suspend_tmout;
546 time = TB_BUS_SUSPEND;
547 break;
548 default:
549 dev_dbg(lnw->dev, "unknown timer, cannot enable it\n");
550 return;
551 }
552
553 lnw->hsm_timer.data = data;
554 lnw->hsm_timer.function = langwell_otg_timer_fn;
555 lnw->hsm_timer.expires = j + time * HZ / 1000; /* milliseconds */
556
557 add_timer(&lnw->hsm_timer);
558
559 dev_dbg(lnw->dev, "add timer successfully\n");
560}
561
562/* Add timer to timer list */
563static void langwell_otg_add_timer(void *gtimer)
564{
565 struct langwell_otg_timer *timer = (struct langwell_otg_timer *)gtimer;
566 struct langwell_otg_timer *tmp_timer;
567 struct intel_mid_otg_xceiv *iotg = &the_transceiver->iotg;
568 u32 val32;
569
570 /* Check if the timer is already in the active list,
571 * if so update timer count
572 */
573 list_for_each_entry(tmp_timer, &active_timers, list)
574 if (tmp_timer == timer) {
575 timer->count = timer->expires;
576 return;
577 }
578 timer->count = timer->expires;
579
580 if (list_empty(&active_timers)) {
581 val32 = readl(iotg->base + CI_OTGSC);
582 writel(val32 | OTGSC_1MSE, iotg->base + CI_OTGSC);
583 }
584
585 list_add_tail(&timer->list, &active_timers);
586}
587
588/* Remove timer from the timer list; clear timeout status */
589static void langwell_otg_del_timer(void *gtimer)
590{
591 struct langwell_otg *lnw = the_transceiver;
592 struct langwell_otg_timer *timer = (struct langwell_otg_timer *)gtimer;
593 struct langwell_otg_timer *tmp_timer, *del_tmp;
594 u32 val32;
595
596 list_for_each_entry_safe(tmp_timer, del_tmp, &active_timers, list)
597 if (tmp_timer == timer)
598 list_del(&timer->list);
599
600 if (list_empty(&active_timers)) {
601 val32 = readl(lnw->iotg.base + CI_OTGSC);
602 writel(val32 & ~OTGSC_1MSE, lnw->iotg.base + CI_OTGSC);
603 }
604}
605
606/* Reduce timer count by 1, and find timeout conditions.*/
607static int langwell_otg_tick_timer(u32 *int_sts)
608{
609 struct langwell_otg *lnw = the_transceiver;
610 struct langwell_otg_timer *tmp_timer, *del_tmp;
611 int expired = 0;
612
613 list_for_each_entry_safe(tmp_timer, del_tmp, &active_timers, list) {
614 tmp_timer->count--;
615 /* check if timer expires */
616 if (!tmp_timer->count) {
617 list_del(&tmp_timer->list);
618 tmp_timer->function(tmp_timer->data);
619 expired = 1;
620 }
621 }
622
623 if (list_empty(&active_timers)) {
624 dev_dbg(lnw->dev, "tick timer: disable 1ms int\n");
625 *int_sts = *int_sts & ~OTGSC_1MSE;
626 }
627 return expired;
628}
629
630static void reset_otg(void)
631{
632 struct langwell_otg *lnw = the_transceiver;
633 int delay_time = 1000;
634 u32 val;
635
636 dev_dbg(lnw->dev, "reseting OTG controller ...\n");
637 val = readl(lnw->iotg.base + CI_USBCMD);
638 writel(val | USBCMD_RST, lnw->iotg.base + CI_USBCMD);
639 do {
640 udelay(100);
641 if (!delay_time--)
642 dev_dbg(lnw->dev, "reset timeout\n");
643 val = readl(lnw->iotg.base + CI_USBCMD);
644 val &= USBCMD_RST;
645 } while (val != 0);
646 dev_dbg(lnw->dev, "reset done.\n");
647}
648
649static void set_host_mode(void)
650{
651 struct langwell_otg *lnw = the_transceiver;
652 u32 val;
653
654 reset_otg();
655 val = readl(lnw->iotg.base + CI_USBMODE);
656 val = (val & (~USBMODE_CM)) | USBMODE_HOST;
657 writel(val, lnw->iotg.base + CI_USBMODE);
658}
659
660static void set_client_mode(void)
661{
662 struct langwell_otg *lnw = the_transceiver;
663 u32 val;
664
665 reset_otg();
666 val = readl(lnw->iotg.base + CI_USBMODE);
667 val = (val & (~USBMODE_CM)) | USBMODE_DEVICE;
668 writel(val, lnw->iotg.base + CI_USBMODE);
669}
670
671static void init_hsm(void)
672{
673 struct langwell_otg *lnw = the_transceiver;
674 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
675 u32 val32;
676
677 /* read OTGSC after reset */
678 val32 = readl(lnw->iotg.base + CI_OTGSC);
679 dev_dbg(lnw->dev, "%s: OTGSC init value = 0x%x\n", __func__, val32);
680
681 /* set init state */
682 if (val32 & OTGSC_ID) {
683 iotg->hsm.id = 1;
684 iotg->otg.default_a = 0;
685 set_client_mode();
686 iotg->otg.state = OTG_STATE_B_IDLE;
687 } else {
688 iotg->hsm.id = 0;
689 iotg->otg.default_a = 1;
690 set_host_mode();
691 iotg->otg.state = OTG_STATE_A_IDLE;
692 }
693
694 /* set session indicator */
695 if (val32 & OTGSC_BSE)
696 iotg->hsm.b_sess_end = 1;
697 if (val32 & OTGSC_BSV)
698 iotg->hsm.b_sess_vld = 1;
699 if (val32 & OTGSC_ASV)
700 iotg->hsm.a_sess_vld = 1;
701 if (val32 & OTGSC_AVV)
702 iotg->hsm.a_vbus_vld = 1;
703
704 /* defautly power the bus */
705 iotg->hsm.a_bus_req = 1;
706 iotg->hsm.a_bus_drop = 0;
707 /* defautly don't request bus as B device */
708 iotg->hsm.b_bus_req = 0;
709 /* no system error */
710 iotg->hsm.a_clr_err = 0;
711
712 langwell_otg_phy_low_power_wait(1);
713}
714
715static void update_hsm(void)
716{
717 struct langwell_otg *lnw = the_transceiver;
718 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
719 u32 val32;
720
721 /* read OTGSC */
722 val32 = readl(lnw->iotg.base + CI_OTGSC);
723 dev_dbg(lnw->dev, "%s: OTGSC value = 0x%x\n", __func__, val32);
724
725 iotg->hsm.id = !!(val32 & OTGSC_ID);
726 iotg->hsm.b_sess_end = !!(val32 & OTGSC_BSE);
727 iotg->hsm.b_sess_vld = !!(val32 & OTGSC_BSV);
728 iotg->hsm.a_sess_vld = !!(val32 & OTGSC_ASV);
729 iotg->hsm.a_vbus_vld = !!(val32 & OTGSC_AVV);
730}
731
732static irqreturn_t otg_dummy_irq(int irq, void *_dev)
733{
734 struct langwell_otg *lnw = the_transceiver;
735 void __iomem *reg_base = _dev;
736 u32 val;
737 u32 int_mask = 0;
738
739 val = readl(reg_base + CI_USBMODE);
740 if ((val & USBMODE_CM) != USBMODE_DEVICE)
741 return IRQ_NONE;
742
743 val = readl(reg_base + CI_USBSTS);
744 int_mask = val & INTR_DUMMY_MASK;
745
746 if (int_mask == 0)
747 return IRQ_NONE;
748
749 /* clear hsm.b_conn here since host driver can't detect it
750 * otg_dummy_irq called means B-disconnect happened.
751 */
752 if (lnw->iotg.hsm.b_conn) {
753 lnw->iotg.hsm.b_conn = 0;
754 if (spin_trylock(&lnw->wq_lock)) {
755 langwell_update_transceiver();
756 spin_unlock(&lnw->wq_lock);
757 }
758 }
759
760 /* Clear interrupts */
761 writel(int_mask, reg_base + CI_USBSTS);
762 return IRQ_HANDLED;
763}
764
765static irqreturn_t otg_irq(int irq, void *_dev)
766{
767 struct langwell_otg *lnw = _dev;
768 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
769 u32 int_sts, int_en;
770 u32 int_mask = 0;
771 int flag = 0;
772
773 int_sts = readl(lnw->iotg.base + CI_OTGSC);
774 int_en = (int_sts & OTGSC_INTEN_MASK) >> 8;
775 int_mask = int_sts & int_en;
776 if (int_mask == 0)
777 return IRQ_NONE;
778
779 if (int_mask & OTGSC_IDIS) {
780 dev_dbg(lnw->dev, "%s: id change int\n", __func__);
781 iotg->hsm.id = (int_sts & OTGSC_ID) ? 1 : 0;
782 dev_dbg(lnw->dev, "id = %d\n", iotg->hsm.id);
783 flag = 1;
784 }
785 if (int_mask & OTGSC_DPIS) {
786 dev_dbg(lnw->dev, "%s: data pulse int\n", __func__);
787 iotg->hsm.a_srp_det = (int_sts & OTGSC_DPS) ? 1 : 0;
788 dev_dbg(lnw->dev, "data pulse = %d\n", iotg->hsm.a_srp_det);
789 flag = 1;
790 }
791 if (int_mask & OTGSC_BSEIS) {
792 dev_dbg(lnw->dev, "%s: b session end int\n", __func__);
793 iotg->hsm.b_sess_end = (int_sts & OTGSC_BSE) ? 1 : 0;
794 dev_dbg(lnw->dev, "b_sess_end = %d\n", iotg->hsm.b_sess_end);
795 flag = 1;
796 }
797 if (int_mask & OTGSC_BSVIS) {
798 dev_dbg(lnw->dev, "%s: b session valid int\n", __func__);
799 iotg->hsm.b_sess_vld = (int_sts & OTGSC_BSV) ? 1 : 0;
800 dev_dbg(lnw->dev, "b_sess_vld = %d\n", iotg->hsm.b_sess_end);
801 flag = 1;
802 }
803 if (int_mask & OTGSC_ASVIS) {
804 dev_dbg(lnw->dev, "%s: a session valid int\n", __func__);
805 iotg->hsm.a_sess_vld = (int_sts & OTGSC_ASV) ? 1 : 0;
806 dev_dbg(lnw->dev, "a_sess_vld = %d\n", iotg->hsm.a_sess_vld);
807 flag = 1;
808 }
809 if (int_mask & OTGSC_AVVIS) {
810 dev_dbg(lnw->dev, "%s: a vbus valid int\n", __func__);
811 iotg->hsm.a_vbus_vld = (int_sts & OTGSC_AVV) ? 1 : 0;
812 dev_dbg(lnw->dev, "a_vbus_vld = %d\n", iotg->hsm.a_vbus_vld);
813 flag = 1;
814 }
815
816 if (int_mask & OTGSC_1MSS) {
817 /* need to schedule otg_work if any timer is expired */
818 if (langwell_otg_tick_timer(&int_sts))
819 flag = 1;
820 }
821
822 writel((int_sts & ~OTGSC_INTSTS_MASK) | int_mask,
823 lnw->iotg.base + CI_OTGSC);
824 if (flag)
825 langwell_update_transceiver();
826
827 return IRQ_HANDLED;
828}
829
830static int langwell_otg_iotg_notify(struct notifier_block *nb,
831 unsigned long action, void *data)
832{
833 struct langwell_otg *lnw = the_transceiver;
834 struct intel_mid_otg_xceiv *iotg = data;
835 int flag = 0;
836
837 if (iotg == NULL)
838 return NOTIFY_BAD;
839
840 if (lnw == NULL)
841 return NOTIFY_BAD;
842
843 switch (action) {
844 case MID_OTG_NOTIFY_CONNECT:
845 dev_dbg(lnw->dev, "Lnw OTG Notify Connect Event\n");
846 if (iotg->otg.default_a == 1)
847 iotg->hsm.b_conn = 1;
848 else
849 iotg->hsm.a_conn = 1;
850 flag = 1;
851 break;
852 case MID_OTG_NOTIFY_DISCONN:
853 dev_dbg(lnw->dev, "Lnw OTG Notify Disconnect Event\n");
854 if (iotg->otg.default_a == 1)
855 iotg->hsm.b_conn = 0;
856 else
857 iotg->hsm.a_conn = 0;
858 flag = 1;
859 break;
860 case MID_OTG_NOTIFY_HSUSPEND:
861 dev_dbg(lnw->dev, "Lnw OTG Notify Host Bus suspend Event\n");
862 if (iotg->otg.default_a == 1)
863 iotg->hsm.a_suspend_req = 1;
864 else
865 iotg->hsm.b_bus_req = 0;
866 flag = 1;
867 break;
868 case MID_OTG_NOTIFY_HRESUME:
869 dev_dbg(lnw->dev, "Lnw OTG Notify Host Bus resume Event\n");
870 if (iotg->otg.default_a == 1)
871 iotg->hsm.b_bus_resume = 1;
872 flag = 1;
873 break;
874 case MID_OTG_NOTIFY_CSUSPEND:
875 dev_dbg(lnw->dev, "Lnw OTG Notify Client Bus suspend Event\n");
876 if (iotg->otg.default_a == 1) {
877 if (iotg->hsm.b_bus_suspend_vld == 2) {
878 iotg->hsm.b_bus_suspend = 1;
879 iotg->hsm.b_bus_suspend_vld = 0;
880 flag = 1;
881 } else {
882 iotg->hsm.b_bus_suspend_vld++;
883 flag = 0;
884 }
885 } else {
886 if (iotg->hsm.a_bus_suspend == 0) {
887 iotg->hsm.a_bus_suspend = 1;
888 flag = 1;
889 }
890 }
891 break;
892 case MID_OTG_NOTIFY_CRESUME:
893 dev_dbg(lnw->dev, "Lnw OTG Notify Client Bus resume Event\n");
894 if (iotg->otg.default_a == 0)
895 iotg->hsm.a_bus_suspend = 0;
896 flag = 0;
897 break;
898 case MID_OTG_NOTIFY_HOSTADD:
899 dev_dbg(lnw->dev, "Lnw OTG Nofity Host Driver Add\n");
900 flag = 1;
901 break;
902 case MID_OTG_NOTIFY_HOSTREMOVE:
903 dev_dbg(lnw->dev, "Lnw OTG Nofity Host Driver remove\n");
904 flag = 1;
905 break;
906 case MID_OTG_NOTIFY_CLIENTADD:
907 dev_dbg(lnw->dev, "Lnw OTG Nofity Client Driver Add\n");
908 flag = 1;
909 break;
910 case MID_OTG_NOTIFY_CLIENTREMOVE:
911 dev_dbg(lnw->dev, "Lnw OTG Nofity Client Driver remove\n");
912 flag = 1;
913 break;
914 default:
915 dev_dbg(lnw->dev, "Lnw OTG Nofity unknown notify message\n");
916 return NOTIFY_DONE;
917 }
918
919 if (flag)
920 langwell_update_transceiver();
921
922 return NOTIFY_OK;
923}
924
925static void langwell_otg_work(struct work_struct *work)
926{
927 struct langwell_otg *lnw;
928 struct intel_mid_otg_xceiv *iotg;
929 int retval;
930 struct pci_dev *pdev;
931
932 lnw = container_of(work, struct langwell_otg, work);
933 iotg = &lnw->iotg;
934 pdev = to_pci_dev(lnw->dev);
935
936 dev_dbg(lnw->dev, "%s: old state = %s\n", __func__,
937 otg_state_string(iotg->otg.state));
938
939 switch (iotg->otg.state) {
940 case OTG_STATE_UNDEFINED:
941 case OTG_STATE_B_IDLE:
942 if (!iotg->hsm.id) {
943 langwell_otg_del_timer(b_srp_init_tmr);
944 del_timer_sync(&lnw->hsm_timer);
945
946 iotg->otg.default_a = 1;
947 iotg->hsm.a_srp_det = 0;
948
949 langwell_otg_chrg_vbus(0);
950 set_host_mode();
951 langwell_otg_phy_low_power(1);
952
953 iotg->otg.state = OTG_STATE_A_IDLE;
954 langwell_update_transceiver();
955 } else if (iotg->hsm.b_sess_vld) {
956 langwell_otg_del_timer(b_srp_init_tmr);
957 del_timer_sync(&lnw->hsm_timer);
958 iotg->hsm.b_sess_end = 0;
959 iotg->hsm.a_bus_suspend = 0;
960 langwell_otg_chrg_vbus(0);
961
962 if (lnw->iotg.start_peripheral) {
963 lnw->iotg.start_peripheral(&lnw->iotg);
964 iotg->otg.state = OTG_STATE_B_PERIPHERAL;
965 } else
966 dev_dbg(lnw->dev, "client driver not loaded\n");
967
968 } else if (iotg->hsm.b_srp_init_tmout) {
969 iotg->hsm.b_srp_init_tmout = 0;
970 dev_warn(lnw->dev, "SRP init timeout\n");
971 } else if (iotg->hsm.b_srp_fail_tmout) {
972 iotg->hsm.b_srp_fail_tmout = 0;
973 iotg->hsm.b_bus_req = 0;
974
975 /* No silence failure */
976 langwell_otg_nsf_msg(6);
977 } else if (iotg->hsm.b_bus_req && iotg->hsm.b_sess_end) {
978 del_timer_sync(&lnw->hsm_timer);
979 /* workaround for b_se0_srp detection */
980 retval = langwell_otg_check_se0_srp(0);
981 if (retval) {
982 iotg->hsm.b_bus_req = 0;
983 dev_dbg(lnw->dev, "LS isn't SE0, try later\n");
984 } else {
985 /* clear the PHCD before start srp */
986 langwell_otg_phy_low_power(0);
987
988 /* Start SRP */
989 langwell_otg_add_timer(b_srp_init_tmr);
990 iotg->otg.start_srp(&iotg->otg);
991 langwell_otg_del_timer(b_srp_init_tmr);
992 langwell_otg_add_ktimer(TB_SRP_FAIL_TMR);
993
994 /* reset PHY low power mode here */
995 langwell_otg_phy_low_power_wait(1);
996 }
997 }
998 break;
999 case OTG_STATE_B_SRP_INIT:
1000 if (!iotg->hsm.id) {
1001 iotg->otg.default_a = 1;
1002 iotg->hsm.a_srp_det = 0;
1003
1004 /* Turn off VBus */
1005 iotg->otg.set_vbus(&iotg->otg, false);
1006 langwell_otg_chrg_vbus(0);
1007 set_host_mode();
1008 langwell_otg_phy_low_power(1);
1009 iotg->otg.state = OTG_STATE_A_IDLE;
1010 langwell_update_transceiver();
1011 } else if (iotg->hsm.b_sess_vld) {
1012 langwell_otg_chrg_vbus(0);
1013 if (lnw->iotg.start_peripheral) {
1014 lnw->iotg.start_peripheral(&lnw->iotg);
1015 iotg->otg.state = OTG_STATE_B_PERIPHERAL;
1016 } else
1017 dev_dbg(lnw->dev, "client driver not loaded\n");
1018 }
1019 break;
1020 case OTG_STATE_B_PERIPHERAL:
1021 if (!iotg->hsm.id) {
1022 iotg->otg.default_a = 1;
1023 iotg->hsm.a_srp_det = 0;
1024
1025 langwell_otg_chrg_vbus(0);
1026
1027 if (lnw->iotg.stop_peripheral)
1028 lnw->iotg.stop_peripheral(&lnw->iotg);
1029 else
1030 dev_dbg(lnw->dev,
1031 "client driver has been removed.\n");
1032
1033 set_host_mode();
1034 langwell_otg_phy_low_power(1);
1035 iotg->otg.state = OTG_STATE_A_IDLE;
1036 langwell_update_transceiver();
1037 } else if (!iotg->hsm.b_sess_vld) {
1038 iotg->hsm.b_hnp_enable = 0;
1039
1040 if (lnw->iotg.stop_peripheral)
1041 lnw->iotg.stop_peripheral(&lnw->iotg);
1042 else
1043 dev_dbg(lnw->dev,
1044 "client driver has been removed.\n");
1045
1046 iotg->otg.state = OTG_STATE_B_IDLE;
1047 } else if (iotg->hsm.b_bus_req && iotg->otg.gadget &&
1048 iotg->otg.gadget->b_hnp_enable &&
1049 iotg->hsm.a_bus_suspend) {
1050
1051 if (lnw->iotg.stop_peripheral)
1052 lnw->iotg.stop_peripheral(&lnw->iotg);
1053 else
1054 dev_dbg(lnw->dev,
1055 "client driver has been removed.\n");
1056
1057 langwell_otg_HAAR(1);
1058 iotg->hsm.a_conn = 0;
1059
1060 if (lnw->iotg.start_host) {
1061 lnw->iotg.start_host(&lnw->iotg);
1062 iotg->otg.state = OTG_STATE_B_WAIT_ACON;
1063 } else
1064 dev_dbg(lnw->dev,
1065 "host driver not loaded.\n");
1066
1067 iotg->hsm.a_bus_resume = 0;
1068 langwell_otg_add_ktimer(TB_ASE0_BRST_TMR);
1069 }
1070 break;
1071
1072 case OTG_STATE_B_WAIT_ACON:
1073 if (!iotg->hsm.id) {
1074 /* delete hsm timer for b_ase0_brst_tmr */
1075 del_timer_sync(&lnw->hsm_timer);
1076
1077 iotg->otg.default_a = 1;
1078 iotg->hsm.a_srp_det = 0;
1079
1080 langwell_otg_chrg_vbus(0);
1081
1082 langwell_otg_HAAR(0);
1083 if (lnw->iotg.stop_host)
1084 lnw->iotg.stop_host(&lnw->iotg);
1085 else
1086 dev_dbg(lnw->dev,
1087 "host driver has been removed.\n");
1088
1089 set_host_mode();
1090 langwell_otg_phy_low_power(1);
1091 iotg->otg.state = OTG_STATE_A_IDLE;
1092 langwell_update_transceiver();
1093 } else if (!iotg->hsm.b_sess_vld) {
1094 /* delete hsm timer for b_ase0_brst_tmr */
1095 del_timer_sync(&lnw->hsm_timer);
1096
1097 iotg->hsm.b_hnp_enable = 0;
1098 iotg->hsm.b_bus_req = 0;
1099
1100 langwell_otg_chrg_vbus(0);
1101 langwell_otg_HAAR(0);
1102
1103 if (lnw->iotg.stop_host)
1104 lnw->iotg.stop_host(&lnw->iotg);
1105 else
1106 dev_dbg(lnw->dev,
1107 "host driver has been removed.\n");
1108
1109 set_client_mode();
1110 langwell_otg_phy_low_power(1);
1111 iotg->otg.state = OTG_STATE_B_IDLE;
1112 } else if (iotg->hsm.a_conn) {
1113 /* delete hsm timer for b_ase0_brst_tmr */
1114 del_timer_sync(&lnw->hsm_timer);
1115
1116 langwell_otg_HAAR(0);
1117 iotg->otg.state = OTG_STATE_B_HOST;
1118 langwell_update_transceiver();
1119 } else if (iotg->hsm.a_bus_resume ||
1120 iotg->hsm.b_ase0_brst_tmout) {
1121 /* delete hsm timer for b_ase0_brst_tmr */
1122 del_timer_sync(&lnw->hsm_timer);
1123
1124 langwell_otg_HAAR(0);
1125 langwell_otg_nsf_msg(7);
1126
1127 if (lnw->iotg.stop_host)
1128 lnw->iotg.stop_host(&lnw->iotg);
1129 else
1130 dev_dbg(lnw->dev,
1131 "host driver has been removed.\n");
1132
1133 iotg->hsm.a_bus_suspend = 0;
1134 iotg->hsm.b_bus_req = 0;
1135
1136 if (lnw->iotg.start_peripheral)
1137 lnw->iotg.start_peripheral(&lnw->iotg);
1138 else
1139 dev_dbg(lnw->dev,
1140 "client driver not loaded.\n");
1141
1142 iotg->otg.state = OTG_STATE_B_PERIPHERAL;
1143 }
1144 break;
1145
1146 case OTG_STATE_B_HOST:
1147 if (!iotg->hsm.id) {
1148 iotg->otg.default_a = 1;
1149 iotg->hsm.a_srp_det = 0;
1150
1151 langwell_otg_chrg_vbus(0);
1152
1153 if (lnw->iotg.stop_host)
1154 lnw->iotg.stop_host(&lnw->iotg);
1155 else
1156 dev_dbg(lnw->dev,
1157 "host driver has been removed.\n");
1158
1159 set_host_mode();
1160 langwell_otg_phy_low_power(1);
1161 iotg->otg.state = OTG_STATE_A_IDLE;
1162 langwell_update_transceiver();
1163 } else if (!iotg->hsm.b_sess_vld) {
1164 iotg->hsm.b_hnp_enable = 0;
1165 iotg->hsm.b_bus_req = 0;
1166
1167 langwell_otg_chrg_vbus(0);
1168 if (lnw->iotg.stop_host)
1169 lnw->iotg.stop_host(&lnw->iotg);
1170 else
1171 dev_dbg(lnw->dev,
1172 "host driver has been removed.\n");
1173
1174 set_client_mode();
1175 langwell_otg_phy_low_power(1);
1176 iotg->otg.state = OTG_STATE_B_IDLE;
1177 } else if ((!iotg->hsm.b_bus_req) ||
1178 (!iotg->hsm.a_conn)) {
1179 iotg->hsm.b_bus_req = 0;
1180 langwell_otg_loc_sof(0);
1181
1182 if (lnw->iotg.stop_host)
1183 lnw->iotg.stop_host(&lnw->iotg);
1184 else
1185 dev_dbg(lnw->dev,
1186 "host driver has been removed.\n");
1187
1188 iotg->hsm.a_bus_suspend = 0;
1189
1190 if (lnw->iotg.start_peripheral)
1191 lnw->iotg.start_peripheral(&lnw->iotg);
1192 else
1193 dev_dbg(lnw->dev,
1194 "client driver not loaded.\n");
1195
1196 iotg->otg.state = OTG_STATE_B_PERIPHERAL;
1197 }
1198 break;
1199
1200 case OTG_STATE_A_IDLE:
1201 iotg->otg.default_a = 1;
1202 if (iotg->hsm.id) {
1203 iotg->otg.default_a = 0;
1204 iotg->hsm.b_bus_req = 0;
1205 iotg->hsm.vbus_srp_up = 0;
1206
1207 langwell_otg_chrg_vbus(0);
1208 set_client_mode();
1209 langwell_otg_phy_low_power(1);
1210 iotg->otg.state = OTG_STATE_B_IDLE;
1211 langwell_update_transceiver();
1212 } else if (!iotg->hsm.a_bus_drop &&
1213 (iotg->hsm.a_srp_det || iotg->hsm.a_bus_req)) {
1214 langwell_otg_phy_low_power(0);
1215
1216 /* Turn on VBus */
1217 iotg->otg.set_vbus(&iotg->otg, true);
1218
1219 iotg->hsm.vbus_srp_up = 0;
1220 iotg->hsm.a_wait_vrise_tmout = 0;
1221 langwell_otg_add_timer(a_wait_vrise_tmr);
1222 iotg->otg.state = OTG_STATE_A_WAIT_VRISE;
1223 langwell_update_transceiver();
1224 } else if (!iotg->hsm.a_bus_drop && iotg->hsm.a_sess_vld) {
1225 iotg->hsm.vbus_srp_up = 1;
1226 } else if (!iotg->hsm.a_sess_vld && iotg->hsm.vbus_srp_up) {
1227 msleep(10);
1228 langwell_otg_phy_low_power(0);
1229
1230 /* Turn on VBus */
1231 iotg->otg.set_vbus(&iotg->otg, true);
1232 iotg->hsm.a_srp_det = 1;
1233 iotg->hsm.vbus_srp_up = 0;
1234 iotg->hsm.a_wait_vrise_tmout = 0;
1235 langwell_otg_add_timer(a_wait_vrise_tmr);
1236 iotg->otg.state = OTG_STATE_A_WAIT_VRISE;
1237 langwell_update_transceiver();
1238 } else if (!iotg->hsm.a_sess_vld &&
1239 !iotg->hsm.vbus_srp_up) {
1240 langwell_otg_phy_low_power(1);
1241 }
1242 break;
1243 case OTG_STATE_A_WAIT_VRISE:
1244 if (iotg->hsm.id) {
1245 langwell_otg_del_timer(a_wait_vrise_tmr);
1246 iotg->hsm.b_bus_req = 0;
1247 iotg->otg.default_a = 0;
1248
1249 /* Turn off VBus */
1250 iotg->otg.set_vbus(&iotg->otg, false);
1251 set_client_mode();
1252 langwell_otg_phy_low_power_wait(1);
1253 iotg->otg.state = OTG_STATE_B_IDLE;
1254 } else if (iotg->hsm.a_vbus_vld) {
1255 langwell_otg_del_timer(a_wait_vrise_tmr);
1256 iotg->hsm.b_conn = 0;
1257 if (lnw->iotg.start_host)
1258 lnw->iotg.start_host(&lnw->iotg);
1259 else {
1260 dev_dbg(lnw->dev, "host driver not loaded.\n");
1261 break;
1262 }
1263
1264 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR);
1265 iotg->otg.state = OTG_STATE_A_WAIT_BCON;
1266 } else if (iotg->hsm.a_wait_vrise_tmout) {
1267 iotg->hsm.b_conn = 0;
1268 if (iotg->hsm.a_vbus_vld) {
1269 if (lnw->iotg.start_host)
1270 lnw->iotg.start_host(&lnw->iotg);
1271 else {
1272 dev_dbg(lnw->dev,
1273 "host driver not loaded.\n");
1274 break;
1275 }
1276 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR);
1277 iotg->otg.state = OTG_STATE_A_WAIT_BCON;
1278 } else {
1279
1280 /* Turn off VBus */
1281 iotg->otg.set_vbus(&iotg->otg, false);
1282 langwell_otg_phy_low_power_wait(1);
1283 iotg->otg.state = OTG_STATE_A_VBUS_ERR;
1284 }
1285 }
1286 break;
1287 case OTG_STATE_A_WAIT_BCON:
1288 if (iotg->hsm.id) {
1289 /* delete hsm timer for a_wait_bcon_tmr */
1290 del_timer_sync(&lnw->hsm_timer);
1291
1292 iotg->otg.default_a = 0;
1293 iotg->hsm.b_bus_req = 0;
1294
1295 if (lnw->iotg.stop_host)
1296 lnw->iotg.stop_host(&lnw->iotg);
1297 else
1298 dev_dbg(lnw->dev,
1299 "host driver has been removed.\n");
1300
1301 /* Turn off VBus */
1302 iotg->otg.set_vbus(&iotg->otg, false);
1303 set_client_mode();
1304 langwell_otg_phy_low_power_wait(1);
1305 iotg->otg.state = OTG_STATE_B_IDLE;
1306 langwell_update_transceiver();
1307 } else if (!iotg->hsm.a_vbus_vld) {
1308 /* delete hsm timer for a_wait_bcon_tmr */
1309 del_timer_sync(&lnw->hsm_timer);
1310
1311 if (lnw->iotg.stop_host)
1312 lnw->iotg.stop_host(&lnw->iotg);
1313 else
1314 dev_dbg(lnw->dev,
1315 "host driver has been removed.\n");
1316
1317 /* Turn off VBus */
1318 iotg->otg.set_vbus(&iotg->otg, false);
1319 langwell_otg_phy_low_power_wait(1);
1320 iotg->otg.state = OTG_STATE_A_VBUS_ERR;
1321 } else if (iotg->hsm.a_bus_drop ||
1322 (iotg->hsm.a_wait_bcon_tmout &&
1323 !iotg->hsm.a_bus_req)) {
1324 /* delete hsm timer for a_wait_bcon_tmr */
1325 del_timer_sync(&lnw->hsm_timer);
1326
1327 if (lnw->iotg.stop_host)
1328 lnw->iotg.stop_host(&lnw->iotg);
1329 else
1330 dev_dbg(lnw->dev,
1331 "host driver has been removed.\n");
1332
1333 /* Turn off VBus */
1334 iotg->otg.set_vbus(&iotg->otg, false);
1335 iotg->otg.state = OTG_STATE_A_WAIT_VFALL;
1336 } else if (iotg->hsm.b_conn) {
1337 /* delete hsm timer for a_wait_bcon_tmr */
1338 del_timer_sync(&lnw->hsm_timer);
1339
1340 iotg->hsm.a_suspend_req = 0;
1341 iotg->otg.state = OTG_STATE_A_HOST;
1342 if (iotg->hsm.a_srp_det && iotg->otg.host &&
1343 !iotg->otg.host->b_hnp_enable) {
1344 /* SRP capable peripheral-only device */
1345 iotg->hsm.a_bus_req = 1;
1346 iotg->hsm.a_srp_det = 0;
1347 } else if (!iotg->hsm.a_bus_req && iotg->otg.host &&
1348 iotg->otg.host->b_hnp_enable) {
1349 /* It is not safe enough to do a fast
1350 * transition from A_WAIT_BCON to
1351 * A_SUSPEND */
1352 msleep(10000);
1353 if (iotg->hsm.a_bus_req)
1354 break;
1355
1356 if (request_irq(pdev->irq,
1357 otg_dummy_irq, IRQF_SHARED,
1358 driver_name, iotg->base) != 0) {
1359 dev_dbg(lnw->dev,
1360 "request interrupt %d fail\n",
1361 pdev->irq);
1362 }
1363
1364 langwell_otg_HABA(1);
1365 iotg->hsm.b_bus_resume = 0;
1366 iotg->hsm.a_aidl_bdis_tmout = 0;
1367
1368 langwell_otg_loc_sof(0);
1369 /* clear PHCD to enable HW timer */
1370 langwell_otg_phy_low_power(0);
1371 langwell_otg_add_timer(a_aidl_bdis_tmr);
1372 iotg->otg.state = OTG_STATE_A_SUSPEND;
1373 } else if (!iotg->hsm.a_bus_req && iotg->otg.host &&
1374 !iotg->otg.host->b_hnp_enable) {
1375 if (lnw->iotg.stop_host)
1376 lnw->iotg.stop_host(&lnw->iotg);
1377 else
1378 dev_dbg(lnw->dev,
1379 "host driver removed.\n");
1380
1381 /* Turn off VBus */
1382 iotg->otg.set_vbus(&iotg->otg, false);
1383 iotg->otg.state = OTG_STATE_A_WAIT_VFALL;
1384 }
1385 }
1386 break;
1387 case OTG_STATE_A_HOST:
1388 if (iotg->hsm.id) {
1389 iotg->otg.default_a = 0;
1390 iotg->hsm.b_bus_req = 0;
1391
1392 if (lnw->iotg.stop_host)
1393 lnw->iotg.stop_host(&lnw->iotg);
1394 else
1395 dev_dbg(lnw->dev,
1396 "host driver has been removed.\n");
1397
1398 /* Turn off VBus */
1399 iotg->otg.set_vbus(&iotg->otg, false);
1400 set_client_mode();
1401 langwell_otg_phy_low_power_wait(1);
1402 iotg->otg.state = OTG_STATE_B_IDLE;
1403 langwell_update_transceiver();
1404 } else if (iotg->hsm.a_bus_drop ||
1405 (iotg->otg.host &&
1406 !iotg->otg.host->b_hnp_enable &&
1407 !iotg->hsm.a_bus_req)) {
1408 if (lnw->iotg.stop_host)
1409 lnw->iotg.stop_host(&lnw->iotg);
1410 else
1411 dev_dbg(lnw->dev,
1412 "host driver has been removed.\n");
1413
1414 /* Turn off VBus */
1415 iotg->otg.set_vbus(&iotg->otg, false);
1416 iotg->otg.state = OTG_STATE_A_WAIT_VFALL;
1417 } else if (!iotg->hsm.a_vbus_vld) {
1418 if (lnw->iotg.stop_host)
1419 lnw->iotg.stop_host(&lnw->iotg);
1420 else
1421 dev_dbg(lnw->dev,
1422 "host driver has been removed.\n");
1423
1424 /* Turn off VBus */
1425 iotg->otg.set_vbus(&iotg->otg, false);
1426 langwell_otg_phy_low_power_wait(1);
1427 iotg->otg.state = OTG_STATE_A_VBUS_ERR;
1428 } else if (iotg->otg.host &&
1429 iotg->otg.host->b_hnp_enable &&
1430 !iotg->hsm.a_bus_req) {
1431 /* Set HABA to enable hardware assistance to signal
1432 * A-connect after receiver B-disconnect. Hardware
1433 * will then set client mode and enable URE, SLE and
1434 * PCE after the assistance. otg_dummy_irq is used to
1435 * clean these ints when client driver is not resumed.
1436 */
1437 if (request_irq(pdev->irq, otg_dummy_irq, IRQF_SHARED,
1438 driver_name, iotg->base) != 0) {
1439 dev_dbg(lnw->dev,
1440 "request interrupt %d failed\n",
1441 pdev->irq);
1442 }
1443
1444 /* set HABA */
1445 langwell_otg_HABA(1);
1446 iotg->hsm.b_bus_resume = 0;
1447 iotg->hsm.a_aidl_bdis_tmout = 0;
1448 langwell_otg_loc_sof(0);
1449 /* clear PHCD to enable HW timer */
1450 langwell_otg_phy_low_power(0);
1451 langwell_otg_add_timer(a_aidl_bdis_tmr);
1452 iotg->otg.state = OTG_STATE_A_SUSPEND;
1453 } else if (!iotg->hsm.b_conn || !iotg->hsm.a_bus_req) {
1454 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR);
1455 iotg->otg.state = OTG_STATE_A_WAIT_BCON;
1456 }
1457 break;
1458 case OTG_STATE_A_SUSPEND:
1459 if (iotg->hsm.id) {
1460 langwell_otg_del_timer(a_aidl_bdis_tmr);
1461 langwell_otg_HABA(0);
1462 free_irq(pdev->irq, iotg->base);
1463 iotg->otg.default_a = 0;
1464 iotg->hsm.b_bus_req = 0;
1465
1466 if (lnw->iotg.stop_host)
1467 lnw->iotg.stop_host(&lnw->iotg);
1468 else
1469 dev_dbg(lnw->dev,
1470 "host driver has been removed.\n");
1471
1472 /* Turn off VBus */
1473 iotg->otg.set_vbus(&iotg->otg, false);
1474 set_client_mode();
1475 langwell_otg_phy_low_power(1);
1476 iotg->otg.state = OTG_STATE_B_IDLE;
1477 langwell_update_transceiver();
1478 } else if (iotg->hsm.a_bus_req ||
1479 iotg->hsm.b_bus_resume) {
1480 langwell_otg_del_timer(a_aidl_bdis_tmr);
1481 langwell_otg_HABA(0);
1482 free_irq(pdev->irq, iotg->base);
1483 iotg->hsm.a_suspend_req = 0;
1484 langwell_otg_loc_sof(1);
1485 iotg->otg.state = OTG_STATE_A_HOST;
1486 } else if (iotg->hsm.a_aidl_bdis_tmout ||
1487 iotg->hsm.a_bus_drop) {
1488 langwell_otg_del_timer(a_aidl_bdis_tmr);
1489 langwell_otg_HABA(0);
1490 free_irq(pdev->irq, iotg->base);
1491 if (lnw->iotg.stop_host)
1492 lnw->iotg.stop_host(&lnw->iotg);
1493 else
1494 dev_dbg(lnw->dev,
1495 "host driver has been removed.\n");
1496
1497 /* Turn off VBus */
1498 iotg->otg.set_vbus(&iotg->otg, false);
1499 iotg->otg.state = OTG_STATE_A_WAIT_VFALL;
1500 } else if (!iotg->hsm.b_conn && iotg->otg.host &&
1501 iotg->otg.host->b_hnp_enable) {
1502 langwell_otg_del_timer(a_aidl_bdis_tmr);
1503 langwell_otg_HABA(0);
1504 free_irq(pdev->irq, iotg->base);
1505
1506 if (lnw->iotg.stop_host)
1507 lnw->iotg.stop_host(&lnw->iotg);
1508 else
1509 dev_dbg(lnw->dev,
1510 "host driver has been removed.\n");
1511
1512 iotg->hsm.b_bus_suspend = 0;
1513 iotg->hsm.b_bus_suspend_vld = 0;
1514
1515 /* msleep(200); */
1516 if (lnw->iotg.start_peripheral)
1517 lnw->iotg.start_peripheral(&lnw->iotg);
1518 else
1519 dev_dbg(lnw->dev,
1520 "client driver not loaded.\n");
1521
1522 langwell_otg_add_ktimer(TB_BUS_SUSPEND_TMR);
1523 iotg->otg.state = OTG_STATE_A_PERIPHERAL;
1524 break;
1525 } else if (!iotg->hsm.a_vbus_vld) {
1526 langwell_otg_del_timer(a_aidl_bdis_tmr);
1527 langwell_otg_HABA(0);
1528 free_irq(pdev->irq, iotg->base);
1529 if (lnw->iotg.stop_host)
1530 lnw->iotg.stop_host(&lnw->iotg);
1531 else
1532 dev_dbg(lnw->dev,
1533 "host driver has been removed.\n");
1534
1535 /* Turn off VBus */
1536 iotg->otg.set_vbus(&iotg->otg, false);
1537 langwell_otg_phy_low_power_wait(1);
1538 iotg->otg.state = OTG_STATE_A_VBUS_ERR;
1539 }
1540 break;
1541 case OTG_STATE_A_PERIPHERAL:
1542 if (iotg->hsm.id) {
1543 /* delete hsm timer for b_bus_suspend_tmr */
1544 del_timer_sync(&lnw->hsm_timer);
1545 iotg->otg.default_a = 0;
1546 iotg->hsm.b_bus_req = 0;
1547 if (lnw->iotg.stop_peripheral)
1548 lnw->iotg.stop_peripheral(&lnw->iotg);
1549 else
1550 dev_dbg(lnw->dev,
1551 "client driver has been removed.\n");
1552
1553 /* Turn off VBus */
1554 iotg->otg.set_vbus(&iotg->otg, false);
1555 set_client_mode();
1556 langwell_otg_phy_low_power_wait(1);
1557 iotg->otg.state = OTG_STATE_B_IDLE;
1558 langwell_update_transceiver();
1559 } else if (!iotg->hsm.a_vbus_vld) {
1560 /* delete hsm timer for b_bus_suspend_tmr */
1561 del_timer_sync(&lnw->hsm_timer);
1562
1563 if (lnw->iotg.stop_peripheral)
1564 lnw->iotg.stop_peripheral(&lnw->iotg);
1565 else
1566 dev_dbg(lnw->dev,
1567 "client driver has been removed.\n");
1568
1569 /* Turn off VBus */
1570 iotg->otg.set_vbus(&iotg->otg, false);
1571 langwell_otg_phy_low_power_wait(1);
1572 iotg->otg.state = OTG_STATE_A_VBUS_ERR;
1573 } else if (iotg->hsm.a_bus_drop) {
1574 /* delete hsm timer for b_bus_suspend_tmr */
1575 del_timer_sync(&lnw->hsm_timer);
1576
1577 if (lnw->iotg.stop_peripheral)
1578 lnw->iotg.stop_peripheral(&lnw->iotg);
1579 else
1580 dev_dbg(lnw->dev,
1581 "client driver has been removed.\n");
1582
1583 /* Turn off VBus */
1584 iotg->otg.set_vbus(&iotg->otg, false);
1585 iotg->otg.state = OTG_STATE_A_WAIT_VFALL;
1586 } else if (iotg->hsm.b_bus_suspend) {
1587 /* delete hsm timer for b_bus_suspend_tmr */
1588 del_timer_sync(&lnw->hsm_timer);
1589
1590 if (lnw->iotg.stop_peripheral)
1591 lnw->iotg.stop_peripheral(&lnw->iotg);
1592 else
1593 dev_dbg(lnw->dev,
1594 "client driver has been removed.\n");
1595
1596 if (lnw->iotg.start_host)
1597 lnw->iotg.start_host(&lnw->iotg);
1598 else
1599 dev_dbg(lnw->dev,
1600 "host driver not loaded.\n");
1601 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR);
1602 iotg->otg.state = OTG_STATE_A_WAIT_BCON;
1603 } else if (iotg->hsm.b_bus_suspend_tmout) {
1604 u32 val;
1605 val = readl(lnw->iotg.base + CI_PORTSC1);
1606 if (!(val & PORTSC_SUSP))
1607 break;
1608
1609 if (lnw->iotg.stop_peripheral)
1610 lnw->iotg.stop_peripheral(&lnw->iotg);
1611 else
1612 dev_dbg(lnw->dev,
1613 "client driver has been removed.\n");
1614
1615 if (lnw->iotg.start_host)
1616 lnw->iotg.start_host(&lnw->iotg);
1617 else
1618 dev_dbg(lnw->dev,
1619 "host driver not loaded.\n");
1620 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR);
1621 iotg->otg.state = OTG_STATE_A_WAIT_BCON;
1622 }
1623 break;
1624 case OTG_STATE_A_VBUS_ERR:
1625 if (iotg->hsm.id) {
1626 iotg->otg.default_a = 0;
1627 iotg->hsm.a_clr_err = 0;
1628 iotg->hsm.a_srp_det = 0;
1629 set_client_mode();
1630 langwell_otg_phy_low_power(1);
1631 iotg->otg.state = OTG_STATE_B_IDLE;
1632 langwell_update_transceiver();
1633 } else if (iotg->hsm.a_clr_err) {
1634 iotg->hsm.a_clr_err = 0;
1635 iotg->hsm.a_srp_det = 0;
1636 reset_otg();
1637 init_hsm();
1638 if (iotg->otg.state == OTG_STATE_A_IDLE)
1639 langwell_update_transceiver();
1640 } else {
1641 /* FW will clear PHCD bit when any VBus
1642 * event detected. Reset PHCD to 1 again */
1643 langwell_otg_phy_low_power(1);
1644 }
1645 break;
1646 case OTG_STATE_A_WAIT_VFALL:
1647 if (iotg->hsm.id) {
1648 iotg->otg.default_a = 0;
1649 set_client_mode();
1650 langwell_otg_phy_low_power(1);
1651 iotg->otg.state = OTG_STATE_B_IDLE;
1652 langwell_update_transceiver();
1653 } else if (iotg->hsm.a_bus_req) {
1654
1655 /* Turn on VBus */
1656 iotg->otg.set_vbus(&iotg->otg, true);
1657 iotg->hsm.a_wait_vrise_tmout = 0;
1658 langwell_otg_add_timer(a_wait_vrise_tmr);
1659 iotg->otg.state = OTG_STATE_A_WAIT_VRISE;
1660 } else if (!iotg->hsm.a_sess_vld) {
1661 iotg->hsm.a_srp_det = 0;
1662 set_host_mode();
1663 langwell_otg_phy_low_power(1);
1664 iotg->otg.state = OTG_STATE_A_IDLE;
1665 }
1666 break;
1667 default:
1668 ;
1669 }
1670
1671 dev_dbg(lnw->dev, "%s: new state = %s\n", __func__,
1672 otg_state_string(iotg->otg.state));
1673}
1674
1675static ssize_t
1676show_registers(struct device *_dev, struct device_attribute *attr, char *buf)
1677{
1678 struct langwell_otg *lnw = the_transceiver;
1679 char *next;
1680 unsigned size, t;
1681
1682 next = buf;
1683 size = PAGE_SIZE;
1684
1685 t = scnprintf(next, size,
1686 "\n"
1687 "USBCMD = 0x%08x\n"
1688 "USBSTS = 0x%08x\n"
1689 "USBINTR = 0x%08x\n"
1690 "ASYNCLISTADDR = 0x%08x\n"
1691 "PORTSC1 = 0x%08x\n"
1692 "HOSTPC1 = 0x%08x\n"
1693 "OTGSC = 0x%08x\n"
1694 "USBMODE = 0x%08x\n",
1695 readl(lnw->iotg.base + 0x30),
1696 readl(lnw->iotg.base + 0x34),
1697 readl(lnw->iotg.base + 0x38),
1698 readl(lnw->iotg.base + 0x48),
1699 readl(lnw->iotg.base + 0x74),
1700 readl(lnw->iotg.base + 0xb4),
1701 readl(lnw->iotg.base + 0xf4),
1702 readl(lnw->iotg.base + 0xf8)
1703 );
1704 size -= t;
1705 next += t;
1706
1707 return PAGE_SIZE - size;
1708}
1709static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
1710
1711static ssize_t
1712show_hsm(struct device *_dev, struct device_attribute *attr, char *buf)
1713{
1714 struct langwell_otg *lnw = the_transceiver;
1715 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
1716 char *next;
1717 unsigned size, t;
1718
1719 next = buf;
1720 size = PAGE_SIZE;
1721
1722 if (iotg->otg.host)
1723 iotg->hsm.a_set_b_hnp_en = iotg->otg.host->b_hnp_enable;
1724
1725 if (iotg->otg.gadget)
1726 iotg->hsm.b_hnp_enable = iotg->otg.gadget->b_hnp_enable;
1727
1728 t = scnprintf(next, size,
1729 "\n"
1730 "current state = %s\n"
1731 "a_bus_resume = \t%d\n"
1732 "a_bus_suspend = \t%d\n"
1733 "a_conn = \t%d\n"
1734 "a_sess_vld = \t%d\n"
1735 "a_srp_det = \t%d\n"
1736 "a_vbus_vld = \t%d\n"
1737 "b_bus_resume = \t%d\n"
1738 "b_bus_suspend = \t%d\n"
1739 "b_conn = \t%d\n"
1740 "b_se0_srp = \t%d\n"
1741 "b_sess_end = \t%d\n"
1742 "b_sess_vld = \t%d\n"
1743 "id = \t%d\n"
1744 "a_set_b_hnp_en = \t%d\n"
1745 "b_srp_done = \t%d\n"
1746 "b_hnp_enable = \t%d\n"
1747 "a_wait_vrise_tmout = \t%d\n"
1748 "a_wait_bcon_tmout = \t%d\n"
1749 "a_aidl_bdis_tmout = \t%d\n"
1750 "b_ase0_brst_tmout = \t%d\n"
1751 "a_bus_drop = \t%d\n"
1752 "a_bus_req = \t%d\n"
1753 "a_clr_err = \t%d\n"
1754 "a_suspend_req = \t%d\n"
1755 "b_bus_req = \t%d\n"
1756 "b_bus_suspend_tmout = \t%d\n"
1757 "b_bus_suspend_vld = \t%d\n",
1758 otg_state_string(iotg->otg.state),
1759 iotg->hsm.a_bus_resume,
1760 iotg->hsm.a_bus_suspend,
1761 iotg->hsm.a_conn,
1762 iotg->hsm.a_sess_vld,
1763 iotg->hsm.a_srp_det,
1764 iotg->hsm.a_vbus_vld,
1765 iotg->hsm.b_bus_resume,
1766 iotg->hsm.b_bus_suspend,
1767 iotg->hsm.b_conn,
1768 iotg->hsm.b_se0_srp,
1769 iotg->hsm.b_sess_end,
1770 iotg->hsm.b_sess_vld,
1771 iotg->hsm.id,
1772 iotg->hsm.a_set_b_hnp_en,
1773 iotg->hsm.b_srp_done,
1774 iotg->hsm.b_hnp_enable,
1775 iotg->hsm.a_wait_vrise_tmout,
1776 iotg->hsm.a_wait_bcon_tmout,
1777 iotg->hsm.a_aidl_bdis_tmout,
1778 iotg->hsm.b_ase0_brst_tmout,
1779 iotg->hsm.a_bus_drop,
1780 iotg->hsm.a_bus_req,
1781 iotg->hsm.a_clr_err,
1782 iotg->hsm.a_suspend_req,
1783 iotg->hsm.b_bus_req,
1784 iotg->hsm.b_bus_suspend_tmout,
1785 iotg->hsm.b_bus_suspend_vld
1786 );
1787 size -= t;
1788 next += t;
1789
1790 return PAGE_SIZE - size;
1791}
1792static DEVICE_ATTR(hsm, S_IRUGO, show_hsm, NULL);
1793
1794static ssize_t
1795get_a_bus_req(struct device *dev, struct device_attribute *attr, char *buf)
1796{
1797 struct langwell_otg *lnw = the_transceiver;
1798 char *next;
1799 unsigned size, t;
1800
1801 next = buf;
1802 size = PAGE_SIZE;
1803
1804 t = scnprintf(next, size, "%d", lnw->iotg.hsm.a_bus_req);
1805 size -= t;
1806 next += t;
1807
1808 return PAGE_SIZE - size;
1809}
1810
1811static ssize_t
1812set_a_bus_req(struct device *dev, struct device_attribute *attr,
1813 const char *buf, size_t count)
1814{
1815 struct langwell_otg *lnw = the_transceiver;
1816 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
1817
1818 if (!iotg->otg.default_a)
1819 return -1;
1820 if (count > 2)
1821 return -1;
1822
1823 if (buf[0] == '0') {
1824 iotg->hsm.a_bus_req = 0;
1825 dev_dbg(lnw->dev, "User request: a_bus_req = 0\n");
1826 } else if (buf[0] == '1') {
1827 /* If a_bus_drop is TRUE, a_bus_req can't be set */
1828 if (iotg->hsm.a_bus_drop)
1829 return -1;
1830 iotg->hsm.a_bus_req = 1;
1831 dev_dbg(lnw->dev, "User request: a_bus_req = 1\n");
1832 }
1833 if (spin_trylock(&lnw->wq_lock)) {
1834 langwell_update_transceiver();
1835 spin_unlock(&lnw->wq_lock);
1836 }
1837 return count;
1838}
1839static DEVICE_ATTR(a_bus_req, S_IRUGO | S_IWUSR, get_a_bus_req, set_a_bus_req);
1840
1841static ssize_t
1842get_a_bus_drop(struct device *dev, struct device_attribute *attr, char *buf)
1843{
1844 struct langwell_otg *lnw = the_transceiver;
1845 char *next;
1846 unsigned size, t;
1847
1848 next = buf;
1849 size = PAGE_SIZE;
1850
1851 t = scnprintf(next, size, "%d", lnw->iotg.hsm.a_bus_drop);
1852 size -= t;
1853 next += t;
1854
1855 return PAGE_SIZE - size;
1856}
1857
1858static ssize_t
1859set_a_bus_drop(struct device *dev, struct device_attribute *attr,
1860 const char *buf, size_t count)
1861{
1862 struct langwell_otg *lnw = the_transceiver;
1863 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
1864
1865 if (!iotg->otg.default_a)
1866 return -1;
1867 if (count > 2)
1868 return -1;
1869
1870 if (buf[0] == '0') {
1871 iotg->hsm.a_bus_drop = 0;
1872 dev_dbg(lnw->dev, "User request: a_bus_drop = 0\n");
1873 } else if (buf[0] == '1') {
1874 iotg->hsm.a_bus_drop = 1;
1875 iotg->hsm.a_bus_req = 0;
1876 dev_dbg(lnw->dev, "User request: a_bus_drop = 1\n");
1877 dev_dbg(lnw->dev, "User request: and a_bus_req = 0\n");
1878 }
1879 if (spin_trylock(&lnw->wq_lock)) {
1880 langwell_update_transceiver();
1881 spin_unlock(&lnw->wq_lock);
1882 }
1883 return count;
1884}
1885static DEVICE_ATTR(a_bus_drop, S_IRUGO | S_IWUSR, get_a_bus_drop, set_a_bus_drop);
1886
1887static ssize_t
1888get_b_bus_req(struct device *dev, struct device_attribute *attr, char *buf)
1889{
1890 struct langwell_otg *lnw = the_transceiver;
1891 char *next;
1892 unsigned size, t;
1893
1894 next = buf;
1895 size = PAGE_SIZE;
1896
1897 t = scnprintf(next, size, "%d", lnw->iotg.hsm.b_bus_req);
1898 size -= t;
1899 next += t;
1900
1901 return PAGE_SIZE - size;
1902}
1903
1904static ssize_t
1905set_b_bus_req(struct device *dev, struct device_attribute *attr,
1906 const char *buf, size_t count)
1907{
1908 struct langwell_otg *lnw = the_transceiver;
1909 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
1910
1911 if (iotg->otg.default_a)
1912 return -1;
1913
1914 if (count > 2)
1915 return -1;
1916
1917 if (buf[0] == '0') {
1918 iotg->hsm.b_bus_req = 0;
1919 dev_dbg(lnw->dev, "User request: b_bus_req = 0\n");
1920 } else if (buf[0] == '1') {
1921 iotg->hsm.b_bus_req = 1;
1922 dev_dbg(lnw->dev, "User request: b_bus_req = 1\n");
1923 }
1924 if (spin_trylock(&lnw->wq_lock)) {
1925 langwell_update_transceiver();
1926 spin_unlock(&lnw->wq_lock);
1927 }
1928 return count;
1929}
1930static DEVICE_ATTR(b_bus_req, S_IRUGO | S_IWUSR, get_b_bus_req, set_b_bus_req);
1931
1932static ssize_t
1933set_a_clr_err(struct device *dev, struct device_attribute *attr,
1934 const char *buf, size_t count)
1935{
1936 struct langwell_otg *lnw = the_transceiver;
1937 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
1938
1939 if (!iotg->otg.default_a)
1940 return -1;
1941 if (count > 2)
1942 return -1;
1943
1944 if (buf[0] == '1') {
1945 iotg->hsm.a_clr_err = 1;
1946 dev_dbg(lnw->dev, "User request: a_clr_err = 1\n");
1947 }
1948 if (spin_trylock(&lnw->wq_lock)) {
1949 langwell_update_transceiver();
1950 spin_unlock(&lnw->wq_lock);
1951 }
1952 return count;
1953}
1954static DEVICE_ATTR(a_clr_err, S_IWUSR, NULL, set_a_clr_err);
1955
1956static struct attribute *inputs_attrs[] = {
1957 &dev_attr_a_bus_req.attr,
1958 &dev_attr_a_bus_drop.attr,
1959 &dev_attr_b_bus_req.attr,
1960 &dev_attr_a_clr_err.attr,
1961 NULL,
1962};
1963
1964static struct attribute_group debug_dev_attr_group = {
1965 .name = "inputs",
1966 .attrs = inputs_attrs,
1967};
1968
1969static int langwell_otg_probe(struct pci_dev *pdev,
1970 const struct pci_device_id *id)
1971{
1972 unsigned long resource, len;
1973 void __iomem *base = NULL;
1974 int retval;
1975 u32 val32;
1976 struct langwell_otg *lnw;
1977 char qname[] = "langwell_otg_queue";
1978
1979 retval = 0;
1980 dev_dbg(&pdev->dev, "\notg controller is detected.\n");
1981 if (pci_enable_device(pdev) < 0) {
1982 retval = -ENODEV;
1983 goto done;
1984 }
1985
1986 lnw = kzalloc(sizeof *lnw, GFP_KERNEL);
1987 if (lnw == NULL) {
1988 retval = -ENOMEM;
1989 goto done;
1990 }
1991 the_transceiver = lnw;
1992
1993 /* control register: BAR 0 */
1994 resource = pci_resource_start(pdev, 0);
1995 len = pci_resource_len(pdev, 0);
1996 if (!request_mem_region(resource, len, driver_name)) {
1997 retval = -EBUSY;
1998 goto err;
1999 }
2000 lnw->region = 1;
2001
2002 base = ioremap_nocache(resource, len);
2003 if (base == NULL) {
2004 retval = -EFAULT;
2005 goto err;
2006 }
2007 lnw->iotg.base = base;
2008
2009 if (!request_mem_region(USBCFG_ADDR, USBCFG_LEN, driver_name)) {
2010 retval = -EBUSY;
2011 goto err;
2012 }
2013 lnw->cfg_region = 1;
2014
2015 /* For the SCCB.USBCFG register */
2016 base = ioremap_nocache(USBCFG_ADDR, USBCFG_LEN);
2017 if (base == NULL) {
2018 retval = -EFAULT;
2019 goto err;
2020 }
2021 lnw->usbcfg = base;
2022
2023 if (!pdev->irq) {
2024 dev_dbg(&pdev->dev, "No IRQ.\n");
2025 retval = -ENODEV;
2026 goto err;
2027 }
2028
2029 lnw->qwork = create_singlethread_workqueue(qname);
2030 if (!lnw->qwork) {
2031 dev_dbg(&pdev->dev, "cannot create workqueue %s\n", qname);
2032 retval = -ENOMEM;
2033 goto err;
2034 }
2035 INIT_WORK(&lnw->work, langwell_otg_work);
2036
2037 /* OTG common part */
2038 lnw->dev = &pdev->dev;
2039 lnw->iotg.otg.dev = lnw->dev;
2040 lnw->iotg.otg.label = driver_name;
2041 lnw->iotg.otg.set_host = langwell_otg_set_host;
2042 lnw->iotg.otg.set_peripheral = langwell_otg_set_peripheral;
2043 lnw->iotg.otg.set_power = langwell_otg_set_power;
2044 lnw->iotg.otg.set_vbus = langwell_otg_set_vbus;
2045 lnw->iotg.otg.start_srp = langwell_otg_start_srp;
2046 lnw->iotg.otg.state = OTG_STATE_UNDEFINED;
2047
2048 if (otg_set_transceiver(&lnw->iotg.otg)) {
2049 dev_dbg(lnw->dev, "can't set transceiver\n");
2050 retval = -EBUSY;
2051 goto err;
2052 }
2053
2054 reset_otg();
2055 init_hsm();
2056
2057 spin_lock_init(&lnw->lock);
2058 spin_lock_init(&lnw->wq_lock);
2059 INIT_LIST_HEAD(&active_timers);
2060 retval = langwell_otg_init_timers(&lnw->iotg.hsm);
2061 if (retval) {
2062 dev_dbg(&pdev->dev, "Failed to init timers\n");
2063 goto err;
2064 }
2065
2066 init_timer(&lnw->hsm_timer);
2067 ATOMIC_INIT_NOTIFIER_HEAD(&lnw->iotg.iotg_notifier);
2068
2069 lnw->iotg_notifier.notifier_call = langwell_otg_iotg_notify;
2070
2071 retval = intel_mid_otg_register_notifier(&lnw->iotg,
2072 &lnw->iotg_notifier);
2073 if (retval) {
2074 dev_dbg(lnw->dev, "Failed to register notifier\n");
2075 goto err;
2076 }
2077
2078 if (request_irq(pdev->irq, otg_irq, IRQF_SHARED,
2079 driver_name, lnw) != 0) {
2080 dev_dbg(lnw->dev, "request interrupt %d failed\n", pdev->irq);
2081 retval = -EBUSY;
2082 goto err;
2083 }
2084
2085 /* enable OTGSC int */
2086 val32 = OTGSC_DPIE | OTGSC_BSEIE | OTGSC_BSVIE |
2087 OTGSC_ASVIE | OTGSC_AVVIE | OTGSC_IDIE | OTGSC_IDPU;
2088 writel(val32, lnw->iotg.base + CI_OTGSC);
2089
2090 retval = device_create_file(&pdev->dev, &dev_attr_registers);
2091 if (retval < 0) {
2092 dev_dbg(lnw->dev,
2093 "Can't register sysfs attribute: %d\n", retval);
2094 goto err;
2095 }
2096
2097 retval = device_create_file(&pdev->dev, &dev_attr_hsm);
2098 if (retval < 0) {
2099 dev_dbg(lnw->dev, "Can't hsm sysfs attribute: %d\n", retval);
2100 goto err;
2101 }
2102
2103 retval = sysfs_create_group(&pdev->dev.kobj, &debug_dev_attr_group);
2104 if (retval < 0) {
2105 dev_dbg(lnw->dev,
2106 "Can't register sysfs attr group: %d\n", retval);
2107 goto err;
2108 }
2109
2110 if (lnw->iotg.otg.state == OTG_STATE_A_IDLE)
2111 langwell_update_transceiver();
2112
2113 return 0;
2114
2115err:
2116 if (the_transceiver)
2117 langwell_otg_remove(pdev);
2118done:
2119 return retval;
2120}
2121
2122static void langwell_otg_remove(struct pci_dev *pdev)
2123{
2124 struct langwell_otg *lnw = the_transceiver;
2125
2126 if (lnw->qwork) {
2127 flush_workqueue(lnw->qwork);
2128 destroy_workqueue(lnw->qwork);
2129 }
2130 intel_mid_otg_unregister_notifier(&lnw->iotg, &lnw->iotg_notifier);
2131 langwell_otg_free_timers();
2132
2133 /* disable OTGSC interrupt as OTGSC doesn't change in reset */
2134 writel(0, lnw->iotg.base + CI_OTGSC);
2135
2136 if (pdev->irq)
2137 free_irq(pdev->irq, lnw);
2138 if (lnw->usbcfg)
2139 iounmap(lnw->usbcfg);
2140 if (lnw->cfg_region)
2141 release_mem_region(USBCFG_ADDR, USBCFG_LEN);
2142 if (lnw->iotg.base)
2143 iounmap(lnw->iotg.base);
2144 if (lnw->region)
2145 release_mem_region(pci_resource_start(pdev, 0),
2146 pci_resource_len(pdev, 0));
2147
2148 otg_set_transceiver(NULL);
2149 pci_disable_device(pdev);
2150 sysfs_remove_group(&pdev->dev.kobj, &debug_dev_attr_group);
2151 device_remove_file(&pdev->dev, &dev_attr_hsm);
2152 device_remove_file(&pdev->dev, &dev_attr_registers);
2153 kfree(lnw);
2154 lnw = NULL;
2155}
2156
2157static void transceiver_suspend(struct pci_dev *pdev)
2158{
2159 pci_save_state(pdev);
2160 pci_set_power_state(pdev, PCI_D3hot);
2161 langwell_otg_phy_low_power(1);
2162}
2163
2164static int langwell_otg_suspend(struct pci_dev *pdev, pm_message_t message)
2165{
2166 struct langwell_otg *lnw = the_transceiver;
2167 struct intel_mid_otg_xceiv *iotg = &lnw->iotg;
2168 int ret = 0;
2169
2170 /* Disbale OTG interrupts */
2171 langwell_otg_intr(0);
2172
2173 if (pdev->irq)
2174 free_irq(pdev->irq, lnw);
2175
2176 /* Prevent more otg_work */
2177 flush_workqueue(lnw->qwork);
2178 destroy_workqueue(lnw->qwork);
2179 lnw->qwork = NULL;
2180
2181 /* start actions */
2182 switch (iotg->otg.state) {
2183 case OTG_STATE_A_WAIT_VFALL:
2184 iotg->otg.state = OTG_STATE_A_IDLE;
2185 case OTG_STATE_A_IDLE:
2186 case OTG_STATE_B_IDLE:
2187 case OTG_STATE_A_VBUS_ERR:
2188 transceiver_suspend(pdev);
2189 break;
2190 case OTG_STATE_A_WAIT_VRISE:
2191 langwell_otg_del_timer(a_wait_vrise_tmr);
2192 iotg->hsm.a_srp_det = 0;
2193
2194 /* Turn off VBus */
2195 iotg->otg.set_vbus(&iotg->otg, false);
2196 iotg->otg.state = OTG_STATE_A_IDLE;
2197 transceiver_suspend(pdev);
2198 break;
2199 case OTG_STATE_A_WAIT_BCON:
2200 del_timer_sync(&lnw->hsm_timer);
2201 if (lnw->iotg.stop_host)
2202 lnw->iotg.stop_host(&lnw->iotg);
2203 else
2204 dev_dbg(&pdev->dev, "host driver has been removed.\n");
2205
2206 iotg->hsm.a_srp_det = 0;
2207
2208 /* Turn off VBus */
2209 iotg->otg.set_vbus(&iotg->otg, false);
2210 iotg->otg.state = OTG_STATE_A_IDLE;
2211 transceiver_suspend(pdev);
2212 break;
2213 case OTG_STATE_A_HOST:
2214 if (lnw->iotg.stop_host)
2215 lnw->iotg.stop_host(&lnw->iotg);
2216 else
2217 dev_dbg(&pdev->dev, "host driver has been removed.\n");
2218
2219 iotg->hsm.a_srp_det = 0;
2220
2221 /* Turn off VBus */
2222 iotg->otg.set_vbus(&iotg->otg, false);
2223
2224 iotg->otg.state = OTG_STATE_A_IDLE;
2225 transceiver_suspend(pdev);
2226 break;
2227 case OTG_STATE_A_SUSPEND:
2228 langwell_otg_del_timer(a_aidl_bdis_tmr);
2229 langwell_otg_HABA(0);
2230 if (lnw->iotg.stop_host)
2231 lnw->iotg.stop_host(&lnw->iotg);
2232 else
2233 dev_dbg(lnw->dev, "host driver has been removed.\n");
2234 iotg->hsm.a_srp_det = 0;
2235
2236 /* Turn off VBus */
2237 iotg->otg.set_vbus(&iotg->otg, false);
2238 iotg->otg.state = OTG_STATE_A_IDLE;
2239 transceiver_suspend(pdev);
2240 break;
2241 case OTG_STATE_A_PERIPHERAL:
2242 del_timer_sync(&lnw->hsm_timer);
2243
2244 if (lnw->iotg.stop_peripheral)
2245 lnw->iotg.stop_peripheral(&lnw->iotg);
2246 else
2247 dev_dbg(&pdev->dev,
2248 "client driver has been removed.\n");
2249 iotg->hsm.a_srp_det = 0;
2250
2251 /* Turn off VBus */
2252 iotg->otg.set_vbus(&iotg->otg, false);
2253 iotg->otg.state = OTG_STATE_A_IDLE;
2254 transceiver_suspend(pdev);
2255 break;
2256 case OTG_STATE_B_HOST:
2257 if (lnw->iotg.stop_host)
2258 lnw->iotg.stop_host(&lnw->iotg);
2259 else
2260 dev_dbg(&pdev->dev, "host driver has been removed.\n");
2261 iotg->hsm.b_bus_req = 0;
2262 iotg->otg.state = OTG_STATE_B_IDLE;
2263 transceiver_suspend(pdev);
2264 break;
2265 case OTG_STATE_B_PERIPHERAL:
2266 if (lnw->iotg.stop_peripheral)
2267 lnw->iotg.stop_peripheral(&lnw->iotg);
2268 else
2269 dev_dbg(&pdev->dev,
2270 "client driver has been removed.\n");
2271 iotg->otg.state = OTG_STATE_B_IDLE;
2272 transceiver_suspend(pdev);
2273 break;
2274 case OTG_STATE_B_WAIT_ACON:
2275 /* delete hsm timer for b_ase0_brst_tmr */
2276 del_timer_sync(&lnw->hsm_timer);
2277
2278 langwell_otg_HAAR(0);
2279
2280 if (lnw->iotg.stop_host)
2281 lnw->iotg.stop_host(&lnw->iotg);
2282 else
2283 dev_dbg(&pdev->dev, "host driver has been removed.\n");
2284 iotg->hsm.b_bus_req = 0;
2285 iotg->otg.state = OTG_STATE_B_IDLE;
2286 transceiver_suspend(pdev);
2287 break;
2288 default:
2289 dev_dbg(lnw->dev, "error state before suspend\n");
2290 break;
2291 }
2292
2293 return ret;
2294}
2295
2296static void transceiver_resume(struct pci_dev *pdev)
2297{
2298 pci_restore_state(pdev);
2299 pci_set_power_state(pdev, PCI_D0);
2300}
2301
2302static int langwell_otg_resume(struct pci_dev *pdev)
2303{
2304 struct langwell_otg *lnw = the_transceiver;
2305 int ret = 0;
2306
2307 transceiver_resume(pdev);
2308
2309 lnw->qwork = create_singlethread_workqueue("langwell_otg_queue");
2310 if (!lnw->qwork) {
2311 dev_dbg(&pdev->dev, "cannot create langwell otg workqueuen");
2312 ret = -ENOMEM;
2313 goto error;
2314 }
2315
2316 if (request_irq(pdev->irq, otg_irq, IRQF_SHARED,
2317 driver_name, lnw) != 0) {
2318 dev_dbg(&pdev->dev, "request interrupt %d failed\n", pdev->irq);
2319 ret = -EBUSY;
2320 goto error;
2321 }
2322
2323 /* enable OTG interrupts */
2324 langwell_otg_intr(1);
2325
2326 update_hsm();
2327
2328 langwell_update_transceiver();
2329
2330 return ret;
2331error:
2332 langwell_otg_intr(0);
2333 transceiver_suspend(pdev);
2334 return ret;
2335}
2336
2337static int __init langwell_otg_init(void)
2338{
2339 return pci_register_driver(&otg_pci_driver);
2340}
2341module_init(langwell_otg_init);
2342
2343static void __exit langwell_otg_cleanup(void)
2344{
2345 pci_unregister_driver(&otg_pci_driver);
2346}
2347module_exit(langwell_otg_cleanup);
diff --git a/drivers/usb/otg/msm_otg.c b/drivers/usb/otg/msm_otg.c
new file mode 100644
index 000000000000..b276f8fcdeba
--- /dev/null
+++ b/drivers/usb/otg/msm_otg.c
@@ -0,0 +1,1761 @@
1/* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 *
17 */
18
19#include <linux/module.h>
20#include <linux/device.h>
21#include <linux/platform_device.h>
22#include <linux/clk.h>
23#include <linux/slab.h>
24#include <linux/interrupt.h>
25#include <linux/err.h>
26#include <linux/delay.h>
27#include <linux/io.h>
28#include <linux/ioport.h>
29#include <linux/uaccess.h>
30#include <linux/debugfs.h>
31#include <linux/seq_file.h>
32#include <linux/pm_runtime.h>
33
34#include <linux/usb.h>
35#include <linux/usb/otg.h>
36#include <linux/usb/ulpi.h>
37#include <linux/usb/gadget.h>
38#include <linux/usb/hcd.h>
39#include <linux/usb/msm_hsusb.h>
40#include <linux/usb/msm_hsusb_hw.h>
41#include <linux/regulator/consumer.h>
42
43#include <mach/clk.h>
44
45#define MSM_USB_BASE (motg->regs)
46#define DRIVER_NAME "msm_otg"
47
48#define ULPI_IO_TIMEOUT_USEC (10 * 1000)
49
50#define USB_PHY_3P3_VOL_MIN 3050000 /* uV */
51#define USB_PHY_3P3_VOL_MAX 3300000 /* uV */
52#define USB_PHY_3P3_HPM_LOAD 50000 /* uA */
53#define USB_PHY_3P3_LPM_LOAD 4000 /* uA */
54
55#define USB_PHY_1P8_VOL_MIN 1800000 /* uV */
56#define USB_PHY_1P8_VOL_MAX 1800000 /* uV */
57#define USB_PHY_1P8_HPM_LOAD 50000 /* uA */
58#define USB_PHY_1P8_LPM_LOAD 4000 /* uA */
59
60#define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */
61#define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */
62
63static struct regulator *hsusb_3p3;
64static struct regulator *hsusb_1p8;
65static struct regulator *hsusb_vddcx;
66
67static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init)
68{
69 int ret = 0;
70
71 if (init) {
72 hsusb_vddcx = regulator_get(motg->otg.dev, "HSUSB_VDDCX");
73 if (IS_ERR(hsusb_vddcx)) {
74 dev_err(motg->otg.dev, "unable to get hsusb vddcx\n");
75 return PTR_ERR(hsusb_vddcx);
76 }
77
78 ret = regulator_set_voltage(hsusb_vddcx,
79 USB_PHY_VDD_DIG_VOL_MIN,
80 USB_PHY_VDD_DIG_VOL_MAX);
81 if (ret) {
82 dev_err(motg->otg.dev, "unable to set the voltage "
83 "for hsusb vddcx\n");
84 regulator_put(hsusb_vddcx);
85 return ret;
86 }
87
88 ret = regulator_enable(hsusb_vddcx);
89 if (ret) {
90 dev_err(motg->otg.dev, "unable to enable hsusb vddcx\n");
91 regulator_put(hsusb_vddcx);
92 }
93 } else {
94 ret = regulator_set_voltage(hsusb_vddcx, 0,
95 USB_PHY_VDD_DIG_VOL_MAX);
96 if (ret)
97 dev_err(motg->otg.dev, "unable to set the voltage "
98 "for hsusb vddcx\n");
99 ret = regulator_disable(hsusb_vddcx);
100 if (ret)
101 dev_err(motg->otg.dev, "unable to disable hsusb vddcx\n");
102
103 regulator_put(hsusb_vddcx);
104 }
105
106 return ret;
107}
108
109static int msm_hsusb_ldo_init(struct msm_otg *motg, int init)
110{
111 int rc = 0;
112
113 if (init) {
114 hsusb_3p3 = regulator_get(motg->otg.dev, "HSUSB_3p3");
115 if (IS_ERR(hsusb_3p3)) {
116 dev_err(motg->otg.dev, "unable to get hsusb 3p3\n");
117 return PTR_ERR(hsusb_3p3);
118 }
119
120 rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN,
121 USB_PHY_3P3_VOL_MAX);
122 if (rc) {
123 dev_err(motg->otg.dev, "unable to set voltage level "
124 "for hsusb 3p3\n");
125 goto put_3p3;
126 }
127 rc = regulator_enable(hsusb_3p3);
128 if (rc) {
129 dev_err(motg->otg.dev, "unable to enable the hsusb 3p3\n");
130 goto put_3p3;
131 }
132 hsusb_1p8 = regulator_get(motg->otg.dev, "HSUSB_1p8");
133 if (IS_ERR(hsusb_1p8)) {
134 dev_err(motg->otg.dev, "unable to get hsusb 1p8\n");
135 rc = PTR_ERR(hsusb_1p8);
136 goto disable_3p3;
137 }
138 rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN,
139 USB_PHY_1P8_VOL_MAX);
140 if (rc) {
141 dev_err(motg->otg.dev, "unable to set voltage level "
142 "for hsusb 1p8\n");
143 goto put_1p8;
144 }
145 rc = regulator_enable(hsusb_1p8);
146 if (rc) {
147 dev_err(motg->otg.dev, "unable to enable the hsusb 1p8\n");
148 goto put_1p8;
149 }
150
151 return 0;
152 }
153
154 regulator_disable(hsusb_1p8);
155put_1p8:
156 regulator_put(hsusb_1p8);
157disable_3p3:
158 regulator_disable(hsusb_3p3);
159put_3p3:
160 regulator_put(hsusb_3p3);
161 return rc;
162}
163
164#ifdef CONFIG_PM_SLEEP
165#define USB_PHY_SUSP_DIG_VOL 500000
166static int msm_hsusb_config_vddcx(int high)
167{
168 int max_vol = USB_PHY_VDD_DIG_VOL_MAX;
169 int min_vol;
170 int ret;
171
172 if (high)
173 min_vol = USB_PHY_VDD_DIG_VOL_MIN;
174 else
175 min_vol = USB_PHY_SUSP_DIG_VOL;
176
177 ret = regulator_set_voltage(hsusb_vddcx, min_vol, max_vol);
178 if (ret) {
179 pr_err("%s: unable to set the voltage for regulator "
180 "HSUSB_VDDCX\n", __func__);
181 return ret;
182 }
183
184 pr_debug("%s: min_vol:%d max_vol:%d\n", __func__, min_vol, max_vol);
185
186 return ret;
187}
188#endif
189
190static int msm_hsusb_ldo_set_mode(int on)
191{
192 int ret = 0;
193
194 if (!hsusb_1p8 || IS_ERR(hsusb_1p8)) {
195 pr_err("%s: HSUSB_1p8 is not initialized\n", __func__);
196 return -ENODEV;
197 }
198
199 if (!hsusb_3p3 || IS_ERR(hsusb_3p3)) {
200 pr_err("%s: HSUSB_3p3 is not initialized\n", __func__);
201 return -ENODEV;
202 }
203
204 if (on) {
205 ret = regulator_set_optimum_mode(hsusb_1p8,
206 USB_PHY_1P8_HPM_LOAD);
207 if (ret < 0) {
208 pr_err("%s: Unable to set HPM of the regulator "
209 "HSUSB_1p8\n", __func__);
210 return ret;
211 }
212 ret = regulator_set_optimum_mode(hsusb_3p3,
213 USB_PHY_3P3_HPM_LOAD);
214 if (ret < 0) {
215 pr_err("%s: Unable to set HPM of the regulator "
216 "HSUSB_3p3\n", __func__);
217 regulator_set_optimum_mode(hsusb_1p8,
218 USB_PHY_1P8_LPM_LOAD);
219 return ret;
220 }
221 } else {
222 ret = regulator_set_optimum_mode(hsusb_1p8,
223 USB_PHY_1P8_LPM_LOAD);
224 if (ret < 0)
225 pr_err("%s: Unable to set LPM of the regulator "
226 "HSUSB_1p8\n", __func__);
227 ret = regulator_set_optimum_mode(hsusb_3p3,
228 USB_PHY_3P3_LPM_LOAD);
229 if (ret < 0)
230 pr_err("%s: Unable to set LPM of the regulator "
231 "HSUSB_3p3\n", __func__);
232 }
233
234 pr_debug("reg (%s)\n", on ? "HPM" : "LPM");
235 return ret < 0 ? ret : 0;
236}
237
238static int ulpi_read(struct otg_transceiver *otg, u32 reg)
239{
240 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
241 int cnt = 0;
242
243 /* initiate read operation */
244 writel(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg),
245 USB_ULPI_VIEWPORT);
246
247 /* wait for completion */
248 while (cnt < ULPI_IO_TIMEOUT_USEC) {
249 if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN))
250 break;
251 udelay(1);
252 cnt++;
253 }
254
255 if (cnt >= ULPI_IO_TIMEOUT_USEC) {
256 dev_err(otg->dev, "ulpi_read: timeout %08x\n",
257 readl(USB_ULPI_VIEWPORT));
258 return -ETIMEDOUT;
259 }
260 return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT));
261}
262
263static int ulpi_write(struct otg_transceiver *otg, u32 val, u32 reg)
264{
265 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
266 int cnt = 0;
267
268 /* initiate write operation */
269 writel(ULPI_RUN | ULPI_WRITE |
270 ULPI_ADDR(reg) | ULPI_DATA(val),
271 USB_ULPI_VIEWPORT);
272
273 /* wait for completion */
274 while (cnt < ULPI_IO_TIMEOUT_USEC) {
275 if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN))
276 break;
277 udelay(1);
278 cnt++;
279 }
280
281 if (cnt >= ULPI_IO_TIMEOUT_USEC) {
282 dev_err(otg->dev, "ulpi_write: timeout\n");
283 return -ETIMEDOUT;
284 }
285 return 0;
286}
287
288static struct otg_io_access_ops msm_otg_io_ops = {
289 .read = ulpi_read,
290 .write = ulpi_write,
291};
292
293static void ulpi_init(struct msm_otg *motg)
294{
295 struct msm_otg_platform_data *pdata = motg->pdata;
296 int *seq = pdata->phy_init_seq;
297
298 if (!seq)
299 return;
300
301 while (seq[0] >= 0) {
302 dev_vdbg(motg->otg.dev, "ulpi: write 0x%02x to 0x%02x\n",
303 seq[0], seq[1]);
304 ulpi_write(&motg->otg, seq[0], seq[1]);
305 seq += 2;
306 }
307}
308
309static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert)
310{
311 int ret;
312
313 if (assert) {
314 ret = clk_reset(motg->clk, CLK_RESET_ASSERT);
315 if (ret)
316 dev_err(motg->otg.dev, "usb hs_clk assert failed\n");
317 } else {
318 ret = clk_reset(motg->clk, CLK_RESET_DEASSERT);
319 if (ret)
320 dev_err(motg->otg.dev, "usb hs_clk deassert failed\n");
321 }
322 return ret;
323}
324
325static int msm_otg_phy_clk_reset(struct msm_otg *motg)
326{
327 int ret;
328
329 ret = clk_reset(motg->phy_reset_clk, CLK_RESET_ASSERT);
330 if (ret) {
331 dev_err(motg->otg.dev, "usb phy clk assert failed\n");
332 return ret;
333 }
334 usleep_range(10000, 12000);
335 ret = clk_reset(motg->phy_reset_clk, CLK_RESET_DEASSERT);
336 if (ret)
337 dev_err(motg->otg.dev, "usb phy clk deassert failed\n");
338 return ret;
339}
340
341static int msm_otg_phy_reset(struct msm_otg *motg)
342{
343 u32 val;
344 int ret;
345 int retries;
346
347 ret = msm_otg_link_clk_reset(motg, 1);
348 if (ret)
349 return ret;
350 ret = msm_otg_phy_clk_reset(motg);
351 if (ret)
352 return ret;
353 ret = msm_otg_link_clk_reset(motg, 0);
354 if (ret)
355 return ret;
356
357 val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK;
358 writel(val | PORTSC_PTS_ULPI, USB_PORTSC);
359
360 for (retries = 3; retries > 0; retries--) {
361 ret = ulpi_write(&motg->otg, ULPI_FUNC_CTRL_SUSPENDM,
362 ULPI_CLR(ULPI_FUNC_CTRL));
363 if (!ret)
364 break;
365 ret = msm_otg_phy_clk_reset(motg);
366 if (ret)
367 return ret;
368 }
369 if (!retries)
370 return -ETIMEDOUT;
371
372 /* This reset calibrates the phy, if the above write succeeded */
373 ret = msm_otg_phy_clk_reset(motg);
374 if (ret)
375 return ret;
376
377 for (retries = 3; retries > 0; retries--) {
378 ret = ulpi_read(&motg->otg, ULPI_DEBUG);
379 if (ret != -ETIMEDOUT)
380 break;
381 ret = msm_otg_phy_clk_reset(motg);
382 if (ret)
383 return ret;
384 }
385 if (!retries)
386 return -ETIMEDOUT;
387
388 dev_info(motg->otg.dev, "phy_reset: success\n");
389 return 0;
390}
391
392#define LINK_RESET_TIMEOUT_USEC (250 * 1000)
393static int msm_otg_reset(struct otg_transceiver *otg)
394{
395 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
396 struct msm_otg_platform_data *pdata = motg->pdata;
397 int cnt = 0;
398 int ret;
399 u32 val = 0;
400 u32 ulpi_val = 0;
401
402 ret = msm_otg_phy_reset(motg);
403 if (ret) {
404 dev_err(otg->dev, "phy_reset failed\n");
405 return ret;
406 }
407
408 ulpi_init(motg);
409
410 writel(USBCMD_RESET, USB_USBCMD);
411 while (cnt < LINK_RESET_TIMEOUT_USEC) {
412 if (!(readl(USB_USBCMD) & USBCMD_RESET))
413 break;
414 udelay(1);
415 cnt++;
416 }
417 if (cnt >= LINK_RESET_TIMEOUT_USEC)
418 return -ETIMEDOUT;
419
420 /* select ULPI phy */
421 writel(0x80000000, USB_PORTSC);
422
423 msleep(100);
424
425 writel(0x0, USB_AHBBURST);
426 writel(0x00, USB_AHBMODE);
427
428 if (pdata->otg_control == OTG_PHY_CONTROL) {
429 val = readl(USB_OTGSC);
430 if (pdata->mode == USB_OTG) {
431 ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID;
432 val |= OTGSC_IDIE | OTGSC_BSVIE;
433 } else if (pdata->mode == USB_PERIPHERAL) {
434 ulpi_val = ULPI_INT_SESS_VALID;
435 val |= OTGSC_BSVIE;
436 }
437 writel(val, USB_OTGSC);
438 ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_RISE);
439 ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_FALL);
440 }
441
442 return 0;
443}
444
445#define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000)
446#define PHY_RESUME_TIMEOUT_USEC (100 * 1000)
447
448#ifdef CONFIG_PM_SLEEP
449static int msm_otg_suspend(struct msm_otg *motg)
450{
451 struct otg_transceiver *otg = &motg->otg;
452 struct usb_bus *bus = otg->host;
453 struct msm_otg_platform_data *pdata = motg->pdata;
454 int cnt = 0;
455
456 if (atomic_read(&motg->in_lpm))
457 return 0;
458
459 disable_irq(motg->irq);
460 /*
461 * Chipidea 45-nm PHY suspend sequence:
462 *
463 * Interrupt Latch Register auto-clear feature is not present
464 * in all PHY versions. Latch register is clear on read type.
465 * Clear latch register to avoid spurious wakeup from
466 * low power mode (LPM).
467 *
468 * PHY comparators are disabled when PHY enters into low power
469 * mode (LPM). Keep PHY comparators ON in LPM only when we expect
470 * VBUS/Id notifications from USB PHY. Otherwise turn off USB
471 * PHY comparators. This save significant amount of power.
472 *
473 * PLL is not turned off when PHY enters into low power mode (LPM).
474 * Disable PLL for maximum power savings.
475 */
476
477 if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) {
478 ulpi_read(otg, 0x14);
479 if (pdata->otg_control == OTG_PHY_CONTROL)
480 ulpi_write(otg, 0x01, 0x30);
481 ulpi_write(otg, 0x08, 0x09);
482 }
483
484 /*
485 * PHY may take some time or even fail to enter into low power
486 * mode (LPM). Hence poll for 500 msec and reset the PHY and link
487 * in failure case.
488 */
489 writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC);
490 while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
491 if (readl(USB_PORTSC) & PORTSC_PHCD)
492 break;
493 udelay(1);
494 cnt++;
495 }
496
497 if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) {
498 dev_err(otg->dev, "Unable to suspend PHY\n");
499 msm_otg_reset(otg);
500 enable_irq(motg->irq);
501 return -ETIMEDOUT;
502 }
503
504 /*
505 * PHY has capability to generate interrupt asynchronously in low
506 * power mode (LPM). This interrupt is level triggered. So USB IRQ
507 * line must be disabled till async interrupt enable bit is cleared
508 * in USBCMD register. Assert STP (ULPI interface STOP signal) to
509 * block data communication from PHY.
510 */
511 writel(readl(USB_USBCMD) | ASYNC_INTR_CTRL | ULPI_STP_CTRL, USB_USBCMD);
512
513 if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
514 motg->pdata->otg_control == OTG_PMIC_CONTROL)
515 writel(readl(USB_PHY_CTRL) | PHY_RETEN, USB_PHY_CTRL);
516
517 clk_disable(motg->pclk);
518 clk_disable(motg->clk);
519 if (motg->core_clk)
520 clk_disable(motg->core_clk);
521
522 if (!IS_ERR(motg->pclk_src))
523 clk_disable(motg->pclk_src);
524
525 if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
526 motg->pdata->otg_control == OTG_PMIC_CONTROL) {
527 msm_hsusb_ldo_set_mode(0);
528 msm_hsusb_config_vddcx(0);
529 }
530
531 if (device_may_wakeup(otg->dev))
532 enable_irq_wake(motg->irq);
533 if (bus)
534 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags);
535
536 atomic_set(&motg->in_lpm, 1);
537 enable_irq(motg->irq);
538
539 dev_info(otg->dev, "USB in low power mode\n");
540
541 return 0;
542}
543
544static int msm_otg_resume(struct msm_otg *motg)
545{
546 struct otg_transceiver *otg = &motg->otg;
547 struct usb_bus *bus = otg->host;
548 int cnt = 0;
549 unsigned temp;
550
551 if (!atomic_read(&motg->in_lpm))
552 return 0;
553
554 if (!IS_ERR(motg->pclk_src))
555 clk_enable(motg->pclk_src);
556
557 clk_enable(motg->pclk);
558 clk_enable(motg->clk);
559 if (motg->core_clk)
560 clk_enable(motg->core_clk);
561
562 if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
563 motg->pdata->otg_control == OTG_PMIC_CONTROL) {
564 msm_hsusb_ldo_set_mode(1);
565 msm_hsusb_config_vddcx(1);
566 writel(readl(USB_PHY_CTRL) & ~PHY_RETEN, USB_PHY_CTRL);
567 }
568
569 temp = readl(USB_USBCMD);
570 temp &= ~ASYNC_INTR_CTRL;
571 temp &= ~ULPI_STP_CTRL;
572 writel(temp, USB_USBCMD);
573
574 /*
575 * PHY comes out of low power mode (LPM) in case of wakeup
576 * from asynchronous interrupt.
577 */
578 if (!(readl(USB_PORTSC) & PORTSC_PHCD))
579 goto skip_phy_resume;
580
581 writel(readl(USB_PORTSC) & ~PORTSC_PHCD, USB_PORTSC);
582 while (cnt < PHY_RESUME_TIMEOUT_USEC) {
583 if (!(readl(USB_PORTSC) & PORTSC_PHCD))
584 break;
585 udelay(1);
586 cnt++;
587 }
588
589 if (cnt >= PHY_RESUME_TIMEOUT_USEC) {
590 /*
591 * This is a fatal error. Reset the link and
592 * PHY. USB state can not be restored. Re-insertion
593 * of USB cable is the only way to get USB working.
594 */
595 dev_err(otg->dev, "Unable to resume USB."
596 "Re-plugin the cable\n");
597 msm_otg_reset(otg);
598 }
599
600skip_phy_resume:
601 if (device_may_wakeup(otg->dev))
602 disable_irq_wake(motg->irq);
603 if (bus)
604 set_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags);
605
606 atomic_set(&motg->in_lpm, 0);
607
608 if (motg->async_int) {
609 motg->async_int = 0;
610 pm_runtime_put(otg->dev);
611 enable_irq(motg->irq);
612 }
613
614 dev_info(otg->dev, "USB exited from low power mode\n");
615
616 return 0;
617}
618#endif
619
620static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA)
621{
622 if (motg->cur_power == mA)
623 return;
624
625 /* TODO: Notify PMIC about available current */
626 dev_info(motg->otg.dev, "Avail curr from USB = %u\n", mA);
627 motg->cur_power = mA;
628}
629
630static int msm_otg_set_power(struct otg_transceiver *otg, unsigned mA)
631{
632 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
633
634 /*
635 * Gadget driver uses set_power method to notify about the
636 * available current based on suspend/configured states.
637 *
638 * IDEV_CHG can be drawn irrespective of suspend/un-configured
639 * states when CDP/ACA is connected.
640 */
641 if (motg->chg_type == USB_SDP_CHARGER)
642 msm_otg_notify_charger(motg, mA);
643
644 return 0;
645}
646
647static void msm_otg_start_host(struct otg_transceiver *otg, int on)
648{
649 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
650 struct msm_otg_platform_data *pdata = motg->pdata;
651 struct usb_hcd *hcd;
652
653 if (!otg->host)
654 return;
655
656 hcd = bus_to_hcd(otg->host);
657
658 if (on) {
659 dev_dbg(otg->dev, "host on\n");
660
661 if (pdata->vbus_power)
662 pdata->vbus_power(1);
663 /*
664 * Some boards have a switch cotrolled by gpio
665 * to enable/disable internal HUB. Enable internal
666 * HUB before kicking the host.
667 */
668 if (pdata->setup_gpio)
669 pdata->setup_gpio(OTG_STATE_A_HOST);
670#ifdef CONFIG_USB
671 usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
672#endif
673 } else {
674 dev_dbg(otg->dev, "host off\n");
675
676#ifdef CONFIG_USB
677 usb_remove_hcd(hcd);
678#endif
679 if (pdata->setup_gpio)
680 pdata->setup_gpio(OTG_STATE_UNDEFINED);
681 if (pdata->vbus_power)
682 pdata->vbus_power(0);
683 }
684}
685
686static int msm_otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
687{
688 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
689 struct usb_hcd *hcd;
690
691 /*
692 * Fail host registration if this board can support
693 * only peripheral configuration.
694 */
695 if (motg->pdata->mode == USB_PERIPHERAL) {
696 dev_info(otg->dev, "Host mode is not supported\n");
697 return -ENODEV;
698 }
699
700 if (!host) {
701 if (otg->state == OTG_STATE_A_HOST) {
702 pm_runtime_get_sync(otg->dev);
703 msm_otg_start_host(otg, 0);
704 otg->host = NULL;
705 otg->state = OTG_STATE_UNDEFINED;
706 schedule_work(&motg->sm_work);
707 } else {
708 otg->host = NULL;
709 }
710
711 return 0;
712 }
713
714 hcd = bus_to_hcd(host);
715 hcd->power_budget = motg->pdata->power_budget;
716
717 otg->host = host;
718 dev_dbg(otg->dev, "host driver registered w/ tranceiver\n");
719
720 /*
721 * Kick the state machine work, if peripheral is not supported
722 * or peripheral is already registered with us.
723 */
724 if (motg->pdata->mode == USB_HOST || otg->gadget) {
725 pm_runtime_get_sync(otg->dev);
726 schedule_work(&motg->sm_work);
727 }
728
729 return 0;
730}
731
732static void msm_otg_start_peripheral(struct otg_transceiver *otg, int on)
733{
734 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
735 struct msm_otg_platform_data *pdata = motg->pdata;
736
737 if (!otg->gadget)
738 return;
739
740 if (on) {
741 dev_dbg(otg->dev, "gadget on\n");
742 /*
743 * Some boards have a switch cotrolled by gpio
744 * to enable/disable internal HUB. Disable internal
745 * HUB before kicking the gadget.
746 */
747 if (pdata->setup_gpio)
748 pdata->setup_gpio(OTG_STATE_B_PERIPHERAL);
749 usb_gadget_vbus_connect(otg->gadget);
750 } else {
751 dev_dbg(otg->dev, "gadget off\n");
752 usb_gadget_vbus_disconnect(otg->gadget);
753 if (pdata->setup_gpio)
754 pdata->setup_gpio(OTG_STATE_UNDEFINED);
755 }
756
757}
758
759static int msm_otg_set_peripheral(struct otg_transceiver *otg,
760 struct usb_gadget *gadget)
761{
762 struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
763
764 /*
765 * Fail peripheral registration if this board can support
766 * only host configuration.
767 */
768 if (motg->pdata->mode == USB_HOST) {
769 dev_info(otg->dev, "Peripheral mode is not supported\n");
770 return -ENODEV;
771 }
772
773 if (!gadget) {
774 if (otg->state == OTG_STATE_B_PERIPHERAL) {
775 pm_runtime_get_sync(otg->dev);
776 msm_otg_start_peripheral(otg, 0);
777 otg->gadget = NULL;
778 otg->state = OTG_STATE_UNDEFINED;
779 schedule_work(&motg->sm_work);
780 } else {
781 otg->gadget = NULL;
782 }
783
784 return 0;
785 }
786 otg->gadget = gadget;
787 dev_dbg(otg->dev, "peripheral driver registered w/ tranceiver\n");
788
789 /*
790 * Kick the state machine work, if host is not supported
791 * or host is already registered with us.
792 */
793 if (motg->pdata->mode == USB_PERIPHERAL || otg->host) {
794 pm_runtime_get_sync(otg->dev);
795 schedule_work(&motg->sm_work);
796 }
797
798 return 0;
799}
800
801static bool msm_chg_check_secondary_det(struct msm_otg *motg)
802{
803 struct otg_transceiver *otg = &motg->otg;
804 u32 chg_det;
805 bool ret = false;
806
807 switch (motg->pdata->phy_type) {
808 case CI_45NM_INTEGRATED_PHY:
809 chg_det = ulpi_read(otg, 0x34);
810 ret = chg_det & (1 << 4);
811 break;
812 case SNPS_28NM_INTEGRATED_PHY:
813 chg_det = ulpi_read(otg, 0x87);
814 ret = chg_det & 1;
815 break;
816 default:
817 break;
818 }
819 return ret;
820}
821
822static void msm_chg_enable_secondary_det(struct msm_otg *motg)
823{
824 struct otg_transceiver *otg = &motg->otg;
825 u32 chg_det;
826
827 switch (motg->pdata->phy_type) {
828 case CI_45NM_INTEGRATED_PHY:
829 chg_det = ulpi_read(otg, 0x34);
830 /* Turn off charger block */
831 chg_det |= ~(1 << 1);
832 ulpi_write(otg, chg_det, 0x34);
833 udelay(20);
834 /* control chg block via ULPI */
835 chg_det &= ~(1 << 3);
836 ulpi_write(otg, chg_det, 0x34);
837 /* put it in host mode for enabling D- source */
838 chg_det &= ~(1 << 2);
839 ulpi_write(otg, chg_det, 0x34);
840 /* Turn on chg detect block */
841 chg_det &= ~(1 << 1);
842 ulpi_write(otg, chg_det, 0x34);
843 udelay(20);
844 /* enable chg detection */
845 chg_det &= ~(1 << 0);
846 ulpi_write(otg, chg_det, 0x34);
847 break;
848 case SNPS_28NM_INTEGRATED_PHY:
849 /*
850 * Configure DM as current source, DP as current sink
851 * and enable battery charging comparators.
852 */
853 ulpi_write(otg, 0x8, 0x85);
854 ulpi_write(otg, 0x2, 0x85);
855 ulpi_write(otg, 0x1, 0x85);
856 break;
857 default:
858 break;
859 }
860}
861
862static bool msm_chg_check_primary_det(struct msm_otg *motg)
863{
864 struct otg_transceiver *otg = &motg->otg;
865 u32 chg_det;
866 bool ret = false;
867
868 switch (motg->pdata->phy_type) {
869 case CI_45NM_INTEGRATED_PHY:
870 chg_det = ulpi_read(otg, 0x34);
871 ret = chg_det & (1 << 4);
872 break;
873 case SNPS_28NM_INTEGRATED_PHY:
874 chg_det = ulpi_read(otg, 0x87);
875 ret = chg_det & 1;
876 break;
877 default:
878 break;
879 }
880 return ret;
881}
882
883static void msm_chg_enable_primary_det(struct msm_otg *motg)
884{
885 struct otg_transceiver *otg = &motg->otg;
886 u32 chg_det;
887
888 switch (motg->pdata->phy_type) {
889 case CI_45NM_INTEGRATED_PHY:
890 chg_det = ulpi_read(otg, 0x34);
891 /* enable chg detection */
892 chg_det &= ~(1 << 0);
893 ulpi_write(otg, chg_det, 0x34);
894 break;
895 case SNPS_28NM_INTEGRATED_PHY:
896 /*
897 * Configure DP as current source, DM as current sink
898 * and enable battery charging comparators.
899 */
900 ulpi_write(otg, 0x2, 0x85);
901 ulpi_write(otg, 0x1, 0x85);
902 break;
903 default:
904 break;
905 }
906}
907
908static bool msm_chg_check_dcd(struct msm_otg *motg)
909{
910 struct otg_transceiver *otg = &motg->otg;
911 u32 line_state;
912 bool ret = false;
913
914 switch (motg->pdata->phy_type) {
915 case CI_45NM_INTEGRATED_PHY:
916 line_state = ulpi_read(otg, 0x15);
917 ret = !(line_state & 1);
918 break;
919 case SNPS_28NM_INTEGRATED_PHY:
920 line_state = ulpi_read(otg, 0x87);
921 ret = line_state & 2;
922 break;
923 default:
924 break;
925 }
926 return ret;
927}
928
929static void msm_chg_disable_dcd(struct msm_otg *motg)
930{
931 struct otg_transceiver *otg = &motg->otg;
932 u32 chg_det;
933
934 switch (motg->pdata->phy_type) {
935 case CI_45NM_INTEGRATED_PHY:
936 chg_det = ulpi_read(otg, 0x34);
937 chg_det &= ~(1 << 5);
938 ulpi_write(otg, chg_det, 0x34);
939 break;
940 case SNPS_28NM_INTEGRATED_PHY:
941 ulpi_write(otg, 0x10, 0x86);
942 break;
943 default:
944 break;
945 }
946}
947
948static void msm_chg_enable_dcd(struct msm_otg *motg)
949{
950 struct otg_transceiver *otg = &motg->otg;
951 u32 chg_det;
952
953 switch (motg->pdata->phy_type) {
954 case CI_45NM_INTEGRATED_PHY:
955 chg_det = ulpi_read(otg, 0x34);
956 /* Turn on D+ current source */
957 chg_det |= (1 << 5);
958 ulpi_write(otg, chg_det, 0x34);
959 break;
960 case SNPS_28NM_INTEGRATED_PHY:
961 /* Data contact detection enable */
962 ulpi_write(otg, 0x10, 0x85);
963 break;
964 default:
965 break;
966 }
967}
968
969static void msm_chg_block_on(struct msm_otg *motg)
970{
971 struct otg_transceiver *otg = &motg->otg;
972 u32 func_ctrl, chg_det;
973
974 /* put the controller in non-driving mode */
975 func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL);
976 func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
977 func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
978 ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL);
979
980 switch (motg->pdata->phy_type) {
981 case CI_45NM_INTEGRATED_PHY:
982 chg_det = ulpi_read(otg, 0x34);
983 /* control chg block via ULPI */
984 chg_det &= ~(1 << 3);
985 ulpi_write(otg, chg_det, 0x34);
986 /* Turn on chg detect block */
987 chg_det &= ~(1 << 1);
988 ulpi_write(otg, chg_det, 0x34);
989 udelay(20);
990 break;
991 case SNPS_28NM_INTEGRATED_PHY:
992 /* Clear charger detecting control bits */
993 ulpi_write(otg, 0x3F, 0x86);
994 /* Clear alt interrupt latch and enable bits */
995 ulpi_write(otg, 0x1F, 0x92);
996 ulpi_write(otg, 0x1F, 0x95);
997 udelay(100);
998 break;
999 default:
1000 break;
1001 }
1002}
1003
1004static void msm_chg_block_off(struct msm_otg *motg)
1005{
1006 struct otg_transceiver *otg = &motg->otg;
1007 u32 func_ctrl, chg_det;
1008
1009 switch (motg->pdata->phy_type) {
1010 case CI_45NM_INTEGRATED_PHY:
1011 chg_det = ulpi_read(otg, 0x34);
1012 /* Turn off charger block */
1013 chg_det |= ~(1 << 1);
1014 ulpi_write(otg, chg_det, 0x34);
1015 break;
1016 case SNPS_28NM_INTEGRATED_PHY:
1017 /* Clear charger detecting control bits */
1018 ulpi_write(otg, 0x3F, 0x86);
1019 /* Clear alt interrupt latch and enable bits */
1020 ulpi_write(otg, 0x1F, 0x92);
1021 ulpi_write(otg, 0x1F, 0x95);
1022 break;
1023 default:
1024 break;
1025 }
1026
1027 /* put the controller in normal mode */
1028 func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL);
1029 func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
1030 func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL;
1031 ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL);
1032}
1033
1034#define MSM_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */
1035#define MSM_CHG_DCD_MAX_RETRIES 6 /* Tdcd_tmout = 6 * 100 msec */
1036#define MSM_CHG_PRIMARY_DET_TIME (40 * HZ/1000) /* TVDPSRC_ON */
1037#define MSM_CHG_SECONDARY_DET_TIME (40 * HZ/1000) /* TVDMSRC_ON */
1038static void msm_chg_detect_work(struct work_struct *w)
1039{
1040 struct msm_otg *motg = container_of(w, struct msm_otg, chg_work.work);
1041 struct otg_transceiver *otg = &motg->otg;
1042 bool is_dcd, tmout, vout;
1043 unsigned long delay;
1044
1045 dev_dbg(otg->dev, "chg detection work\n");
1046 switch (motg->chg_state) {
1047 case USB_CHG_STATE_UNDEFINED:
1048 pm_runtime_get_sync(otg->dev);
1049 msm_chg_block_on(motg);
1050 msm_chg_enable_dcd(motg);
1051 motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD;
1052 motg->dcd_retries = 0;
1053 delay = MSM_CHG_DCD_POLL_TIME;
1054 break;
1055 case USB_CHG_STATE_WAIT_FOR_DCD:
1056 is_dcd = msm_chg_check_dcd(motg);
1057 tmout = ++motg->dcd_retries == MSM_CHG_DCD_MAX_RETRIES;
1058 if (is_dcd || tmout) {
1059 msm_chg_disable_dcd(motg);
1060 msm_chg_enable_primary_det(motg);
1061 delay = MSM_CHG_PRIMARY_DET_TIME;
1062 motg->chg_state = USB_CHG_STATE_DCD_DONE;
1063 } else {
1064 delay = MSM_CHG_DCD_POLL_TIME;
1065 }
1066 break;
1067 case USB_CHG_STATE_DCD_DONE:
1068 vout = msm_chg_check_primary_det(motg);
1069 if (vout) {
1070 msm_chg_enable_secondary_det(motg);
1071 delay = MSM_CHG_SECONDARY_DET_TIME;
1072 motg->chg_state = USB_CHG_STATE_PRIMARY_DONE;
1073 } else {
1074 motg->chg_type = USB_SDP_CHARGER;
1075 motg->chg_state = USB_CHG_STATE_DETECTED;
1076 delay = 0;
1077 }
1078 break;
1079 case USB_CHG_STATE_PRIMARY_DONE:
1080 vout = msm_chg_check_secondary_det(motg);
1081 if (vout)
1082 motg->chg_type = USB_DCP_CHARGER;
1083 else
1084 motg->chg_type = USB_CDP_CHARGER;
1085 motg->chg_state = USB_CHG_STATE_SECONDARY_DONE;
1086 /* fall through */
1087 case USB_CHG_STATE_SECONDARY_DONE:
1088 motg->chg_state = USB_CHG_STATE_DETECTED;
1089 case USB_CHG_STATE_DETECTED:
1090 msm_chg_block_off(motg);
1091 dev_dbg(otg->dev, "charger = %d\n", motg->chg_type);
1092 schedule_work(&motg->sm_work);
1093 return;
1094 default:
1095 return;
1096 }
1097
1098 schedule_delayed_work(&motg->chg_work, delay);
1099}
1100
1101/*
1102 * We support OTG, Peripheral only and Host only configurations. In case
1103 * of OTG, mode switch (host-->peripheral/peripheral-->host) can happen
1104 * via Id pin status or user request (debugfs). Id/BSV interrupts are not
1105 * enabled when switch is controlled by user and default mode is supplied
1106 * by board file, which can be changed by userspace later.
1107 */
1108static void msm_otg_init_sm(struct msm_otg *motg)
1109{
1110 struct msm_otg_platform_data *pdata = motg->pdata;
1111 u32 otgsc = readl(USB_OTGSC);
1112
1113 switch (pdata->mode) {
1114 case USB_OTG:
1115 if (pdata->otg_control == OTG_PHY_CONTROL) {
1116 if (otgsc & OTGSC_ID)
1117 set_bit(ID, &motg->inputs);
1118 else
1119 clear_bit(ID, &motg->inputs);
1120
1121 if (otgsc & OTGSC_BSV)
1122 set_bit(B_SESS_VLD, &motg->inputs);
1123 else
1124 clear_bit(B_SESS_VLD, &motg->inputs);
1125 } else if (pdata->otg_control == OTG_USER_CONTROL) {
1126 if (pdata->default_mode == USB_HOST) {
1127 clear_bit(ID, &motg->inputs);
1128 } else if (pdata->default_mode == USB_PERIPHERAL) {
1129 set_bit(ID, &motg->inputs);
1130 set_bit(B_SESS_VLD, &motg->inputs);
1131 } else {
1132 set_bit(ID, &motg->inputs);
1133 clear_bit(B_SESS_VLD, &motg->inputs);
1134 }
1135 }
1136 break;
1137 case USB_HOST:
1138 clear_bit(ID, &motg->inputs);
1139 break;
1140 case USB_PERIPHERAL:
1141 set_bit(ID, &motg->inputs);
1142 if (otgsc & OTGSC_BSV)
1143 set_bit(B_SESS_VLD, &motg->inputs);
1144 else
1145 clear_bit(B_SESS_VLD, &motg->inputs);
1146 break;
1147 default:
1148 break;
1149 }
1150}
1151
1152static void msm_otg_sm_work(struct work_struct *w)
1153{
1154 struct msm_otg *motg = container_of(w, struct msm_otg, sm_work);
1155 struct otg_transceiver *otg = &motg->otg;
1156
1157 switch (otg->state) {
1158 case OTG_STATE_UNDEFINED:
1159 dev_dbg(otg->dev, "OTG_STATE_UNDEFINED state\n");
1160 msm_otg_reset(otg);
1161 msm_otg_init_sm(motg);
1162 otg->state = OTG_STATE_B_IDLE;
1163 /* FALL THROUGH */
1164 case OTG_STATE_B_IDLE:
1165 dev_dbg(otg->dev, "OTG_STATE_B_IDLE state\n");
1166 if (!test_bit(ID, &motg->inputs) && otg->host) {
1167 /* disable BSV bit */
1168 writel(readl(USB_OTGSC) & ~OTGSC_BSVIE, USB_OTGSC);
1169 msm_otg_start_host(otg, 1);
1170 otg->state = OTG_STATE_A_HOST;
1171 } else if (test_bit(B_SESS_VLD, &motg->inputs)) {
1172 switch (motg->chg_state) {
1173 case USB_CHG_STATE_UNDEFINED:
1174 msm_chg_detect_work(&motg->chg_work.work);
1175 break;
1176 case USB_CHG_STATE_DETECTED:
1177 switch (motg->chg_type) {
1178 case USB_DCP_CHARGER:
1179 msm_otg_notify_charger(motg,
1180 IDEV_CHG_MAX);
1181 break;
1182 case USB_CDP_CHARGER:
1183 msm_otg_notify_charger(motg,
1184 IDEV_CHG_MAX);
1185 msm_otg_start_peripheral(otg, 1);
1186 otg->state = OTG_STATE_B_PERIPHERAL;
1187 break;
1188 case USB_SDP_CHARGER:
1189 msm_otg_notify_charger(motg, IUNIT);
1190 msm_otg_start_peripheral(otg, 1);
1191 otg->state = OTG_STATE_B_PERIPHERAL;
1192 break;
1193 default:
1194 break;
1195 }
1196 break;
1197 default:
1198 break;
1199 }
1200 } else {
1201 /*
1202 * If charger detection work is pending, decrement
1203 * the pm usage counter to balance with the one that
1204 * is incremented in charger detection work.
1205 */
1206 if (cancel_delayed_work_sync(&motg->chg_work)) {
1207 pm_runtime_put_sync(otg->dev);
1208 msm_otg_reset(otg);
1209 }
1210 msm_otg_notify_charger(motg, 0);
1211 motg->chg_state = USB_CHG_STATE_UNDEFINED;
1212 motg->chg_type = USB_INVALID_CHARGER;
1213 }
1214 pm_runtime_put_sync(otg->dev);
1215 break;
1216 case OTG_STATE_B_PERIPHERAL:
1217 dev_dbg(otg->dev, "OTG_STATE_B_PERIPHERAL state\n");
1218 if (!test_bit(B_SESS_VLD, &motg->inputs) ||
1219 !test_bit(ID, &motg->inputs)) {
1220 msm_otg_notify_charger(motg, 0);
1221 msm_otg_start_peripheral(otg, 0);
1222 motg->chg_state = USB_CHG_STATE_UNDEFINED;
1223 motg->chg_type = USB_INVALID_CHARGER;
1224 otg->state = OTG_STATE_B_IDLE;
1225 msm_otg_reset(otg);
1226 schedule_work(w);
1227 }
1228 break;
1229 case OTG_STATE_A_HOST:
1230 dev_dbg(otg->dev, "OTG_STATE_A_HOST state\n");
1231 if (test_bit(ID, &motg->inputs)) {
1232 msm_otg_start_host(otg, 0);
1233 otg->state = OTG_STATE_B_IDLE;
1234 msm_otg_reset(otg);
1235 schedule_work(w);
1236 }
1237 break;
1238 default:
1239 break;
1240 }
1241}
1242
1243static irqreturn_t msm_otg_irq(int irq, void *data)
1244{
1245 struct msm_otg *motg = data;
1246 struct otg_transceiver *otg = &motg->otg;
1247 u32 otgsc = 0;
1248
1249 if (atomic_read(&motg->in_lpm)) {
1250 disable_irq_nosync(irq);
1251 motg->async_int = 1;
1252 pm_runtime_get(otg->dev);
1253 return IRQ_HANDLED;
1254 }
1255
1256 otgsc = readl(USB_OTGSC);
1257 if (!(otgsc & (OTGSC_IDIS | OTGSC_BSVIS)))
1258 return IRQ_NONE;
1259
1260 if ((otgsc & OTGSC_IDIS) && (otgsc & OTGSC_IDIE)) {
1261 if (otgsc & OTGSC_ID)
1262 set_bit(ID, &motg->inputs);
1263 else
1264 clear_bit(ID, &motg->inputs);
1265 dev_dbg(otg->dev, "ID set/clear\n");
1266 pm_runtime_get_noresume(otg->dev);
1267 } else if ((otgsc & OTGSC_BSVIS) && (otgsc & OTGSC_BSVIE)) {
1268 if (otgsc & OTGSC_BSV)
1269 set_bit(B_SESS_VLD, &motg->inputs);
1270 else
1271 clear_bit(B_SESS_VLD, &motg->inputs);
1272 dev_dbg(otg->dev, "BSV set/clear\n");
1273 pm_runtime_get_noresume(otg->dev);
1274 }
1275
1276 writel(otgsc, USB_OTGSC);
1277 schedule_work(&motg->sm_work);
1278 return IRQ_HANDLED;
1279}
1280
1281static int msm_otg_mode_show(struct seq_file *s, void *unused)
1282{
1283 struct msm_otg *motg = s->private;
1284 struct otg_transceiver *otg = &motg->otg;
1285
1286 switch (otg->state) {
1287 case OTG_STATE_A_HOST:
1288 seq_printf(s, "host\n");
1289 break;
1290 case OTG_STATE_B_PERIPHERAL:
1291 seq_printf(s, "peripheral\n");
1292 break;
1293 default:
1294 seq_printf(s, "none\n");
1295 break;
1296 }
1297
1298 return 0;
1299}
1300
1301static int msm_otg_mode_open(struct inode *inode, struct file *file)
1302{
1303 return single_open(file, msm_otg_mode_show, inode->i_private);
1304}
1305
1306static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf,
1307 size_t count, loff_t *ppos)
1308{
1309 struct seq_file *s = file->private_data;
1310 struct msm_otg *motg = s->private;
1311 char buf[16];
1312 struct otg_transceiver *otg = &motg->otg;
1313 int status = count;
1314 enum usb_mode_type req_mode;
1315
1316 memset(buf, 0x00, sizeof(buf));
1317
1318 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) {
1319 status = -EFAULT;
1320 goto out;
1321 }
1322
1323 if (!strncmp(buf, "host", 4)) {
1324 req_mode = USB_HOST;
1325 } else if (!strncmp(buf, "peripheral", 10)) {
1326 req_mode = USB_PERIPHERAL;
1327 } else if (!strncmp(buf, "none", 4)) {
1328 req_mode = USB_NONE;
1329 } else {
1330 status = -EINVAL;
1331 goto out;
1332 }
1333
1334 switch (req_mode) {
1335 case USB_NONE:
1336 switch (otg->state) {
1337 case OTG_STATE_A_HOST:
1338 case OTG_STATE_B_PERIPHERAL:
1339 set_bit(ID, &motg->inputs);
1340 clear_bit(B_SESS_VLD, &motg->inputs);
1341 break;
1342 default:
1343 goto out;
1344 }
1345 break;
1346 case USB_PERIPHERAL:
1347 switch (otg->state) {
1348 case OTG_STATE_B_IDLE:
1349 case OTG_STATE_A_HOST:
1350 set_bit(ID, &motg->inputs);
1351 set_bit(B_SESS_VLD, &motg->inputs);
1352 break;
1353 default:
1354 goto out;
1355 }
1356 break;
1357 case USB_HOST:
1358 switch (otg->state) {
1359 case OTG_STATE_B_IDLE:
1360 case OTG_STATE_B_PERIPHERAL:
1361 clear_bit(ID, &motg->inputs);
1362 break;
1363 default:
1364 goto out;
1365 }
1366 break;
1367 default:
1368 goto out;
1369 }
1370
1371 pm_runtime_get_sync(otg->dev);
1372 schedule_work(&motg->sm_work);
1373out:
1374 return status;
1375}
1376
1377const struct file_operations msm_otg_mode_fops = {
1378 .open = msm_otg_mode_open,
1379 .read = seq_read,
1380 .write = msm_otg_mode_write,
1381 .llseek = seq_lseek,
1382 .release = single_release,
1383};
1384
1385static struct dentry *msm_otg_dbg_root;
1386static struct dentry *msm_otg_dbg_mode;
1387
1388static int msm_otg_debugfs_init(struct msm_otg *motg)
1389{
1390 msm_otg_dbg_root = debugfs_create_dir("msm_otg", NULL);
1391
1392 if (!msm_otg_dbg_root || IS_ERR(msm_otg_dbg_root))
1393 return -ENODEV;
1394
1395 msm_otg_dbg_mode = debugfs_create_file("mode", S_IRUGO | S_IWUSR,
1396 msm_otg_dbg_root, motg, &msm_otg_mode_fops);
1397 if (!msm_otg_dbg_mode) {
1398 debugfs_remove(msm_otg_dbg_root);
1399 msm_otg_dbg_root = NULL;
1400 return -ENODEV;
1401 }
1402
1403 return 0;
1404}
1405
1406static void msm_otg_debugfs_cleanup(void)
1407{
1408 debugfs_remove(msm_otg_dbg_mode);
1409 debugfs_remove(msm_otg_dbg_root);
1410}
1411
1412static int __init msm_otg_probe(struct platform_device *pdev)
1413{
1414 int ret = 0;
1415 struct resource *res;
1416 struct msm_otg *motg;
1417 struct otg_transceiver *otg;
1418
1419 dev_info(&pdev->dev, "msm_otg probe\n");
1420 if (!pdev->dev.platform_data) {
1421 dev_err(&pdev->dev, "No platform data given. Bailing out\n");
1422 return -ENODEV;
1423 }
1424
1425 motg = kzalloc(sizeof(struct msm_otg), GFP_KERNEL);
1426 if (!motg) {
1427 dev_err(&pdev->dev, "unable to allocate msm_otg\n");
1428 return -ENOMEM;
1429 }
1430
1431 motg->pdata = pdev->dev.platform_data;
1432 otg = &motg->otg;
1433 otg->dev = &pdev->dev;
1434
1435 motg->phy_reset_clk = clk_get(&pdev->dev, "usb_phy_clk");
1436 if (IS_ERR(motg->phy_reset_clk)) {
1437 dev_err(&pdev->dev, "failed to get usb_phy_clk\n");
1438 ret = PTR_ERR(motg->phy_reset_clk);
1439 goto free_motg;
1440 }
1441
1442 motg->clk = clk_get(&pdev->dev, "usb_hs_clk");
1443 if (IS_ERR(motg->clk)) {
1444 dev_err(&pdev->dev, "failed to get usb_hs_clk\n");
1445 ret = PTR_ERR(motg->clk);
1446 goto put_phy_reset_clk;
1447 }
1448 clk_set_rate(motg->clk, 60000000);
1449
1450 /*
1451 * If USB Core is running its protocol engine based on CORE CLK,
1452 * CORE CLK must be running at >55Mhz for correct HSUSB
1453 * operation and USB core cannot tolerate frequency changes on
1454 * CORE CLK. For such USB cores, vote for maximum clk frequency
1455 * on pclk source
1456 */
1457 if (motg->pdata->pclk_src_name) {
1458 motg->pclk_src = clk_get(&pdev->dev,
1459 motg->pdata->pclk_src_name);
1460 if (IS_ERR(motg->pclk_src))
1461 goto put_clk;
1462 clk_set_rate(motg->pclk_src, INT_MAX);
1463 clk_enable(motg->pclk_src);
1464 } else
1465 motg->pclk_src = ERR_PTR(-ENOENT);
1466
1467
1468 motg->pclk = clk_get(&pdev->dev, "usb_hs_pclk");
1469 if (IS_ERR(motg->pclk)) {
1470 dev_err(&pdev->dev, "failed to get usb_hs_pclk\n");
1471 ret = PTR_ERR(motg->pclk);
1472 goto put_pclk_src;
1473 }
1474
1475 /*
1476 * USB core clock is not present on all MSM chips. This
1477 * clock is introduced to remove the dependency on AXI
1478 * bus frequency.
1479 */
1480 motg->core_clk = clk_get(&pdev->dev, "usb_hs_core_clk");
1481 if (IS_ERR(motg->core_clk))
1482 motg->core_clk = NULL;
1483
1484 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1485 if (!res) {
1486 dev_err(&pdev->dev, "failed to get platform resource mem\n");
1487 ret = -ENODEV;
1488 goto put_core_clk;
1489 }
1490
1491 motg->regs = ioremap(res->start, resource_size(res));
1492 if (!motg->regs) {
1493 dev_err(&pdev->dev, "ioremap failed\n");
1494 ret = -ENOMEM;
1495 goto put_core_clk;
1496 }
1497 dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs);
1498
1499 motg->irq = platform_get_irq(pdev, 0);
1500 if (!motg->irq) {
1501 dev_err(&pdev->dev, "platform_get_irq failed\n");
1502 ret = -ENODEV;
1503 goto free_regs;
1504 }
1505
1506 clk_enable(motg->clk);
1507 clk_enable(motg->pclk);
1508
1509 ret = msm_hsusb_init_vddcx(motg, 1);
1510 if (ret) {
1511 dev_err(&pdev->dev, "hsusb vddcx configuration failed\n");
1512 goto free_regs;
1513 }
1514
1515 ret = msm_hsusb_ldo_init(motg, 1);
1516 if (ret) {
1517 dev_err(&pdev->dev, "hsusb vreg configuration failed\n");
1518 goto vddcx_exit;
1519 }
1520 ret = msm_hsusb_ldo_set_mode(1);
1521 if (ret) {
1522 dev_err(&pdev->dev, "hsusb vreg enable failed\n");
1523 goto ldo_exit;
1524 }
1525
1526 if (motg->core_clk)
1527 clk_enable(motg->core_clk);
1528
1529 writel(0, USB_USBINTR);
1530 writel(0, USB_OTGSC);
1531
1532 INIT_WORK(&motg->sm_work, msm_otg_sm_work);
1533 INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work);
1534 ret = request_irq(motg->irq, msm_otg_irq, IRQF_SHARED,
1535 "msm_otg", motg);
1536 if (ret) {
1537 dev_err(&pdev->dev, "request irq failed\n");
1538 goto disable_clks;
1539 }
1540
1541 otg->init = msm_otg_reset;
1542 otg->set_host = msm_otg_set_host;
1543 otg->set_peripheral = msm_otg_set_peripheral;
1544 otg->set_power = msm_otg_set_power;
1545
1546 otg->io_ops = &msm_otg_io_ops;
1547
1548 ret = otg_set_transceiver(&motg->otg);
1549 if (ret) {
1550 dev_err(&pdev->dev, "otg_set_transceiver failed\n");
1551 goto free_irq;
1552 }
1553
1554 platform_set_drvdata(pdev, motg);
1555 device_init_wakeup(&pdev->dev, 1);
1556
1557 if (motg->pdata->mode == USB_OTG &&
1558 motg->pdata->otg_control == OTG_USER_CONTROL) {
1559 ret = msm_otg_debugfs_init(motg);
1560 if (ret)
1561 dev_dbg(&pdev->dev, "mode debugfs file is"
1562 "not available\n");
1563 }
1564
1565 pm_runtime_set_active(&pdev->dev);
1566 pm_runtime_enable(&pdev->dev);
1567
1568 return 0;
1569free_irq:
1570 free_irq(motg->irq, motg);
1571disable_clks:
1572 clk_disable(motg->pclk);
1573 clk_disable(motg->clk);
1574ldo_exit:
1575 msm_hsusb_ldo_init(motg, 0);
1576vddcx_exit:
1577 msm_hsusb_init_vddcx(motg, 0);
1578free_regs:
1579 iounmap(motg->regs);
1580put_core_clk:
1581 if (motg->core_clk)
1582 clk_put(motg->core_clk);
1583 clk_put(motg->pclk);
1584put_pclk_src:
1585 if (!IS_ERR(motg->pclk_src)) {
1586 clk_disable(motg->pclk_src);
1587 clk_put(motg->pclk_src);
1588 }
1589put_clk:
1590 clk_put(motg->clk);
1591put_phy_reset_clk:
1592 clk_put(motg->phy_reset_clk);
1593free_motg:
1594 kfree(motg);
1595 return ret;
1596}
1597
1598static int __devexit msm_otg_remove(struct platform_device *pdev)
1599{
1600 struct msm_otg *motg = platform_get_drvdata(pdev);
1601 struct otg_transceiver *otg = &motg->otg;
1602 int cnt = 0;
1603
1604 if (otg->host || otg->gadget)
1605 return -EBUSY;
1606
1607 msm_otg_debugfs_cleanup();
1608 cancel_delayed_work_sync(&motg->chg_work);
1609 cancel_work_sync(&motg->sm_work);
1610
1611 pm_runtime_resume(&pdev->dev);
1612
1613 device_init_wakeup(&pdev->dev, 0);
1614 pm_runtime_disable(&pdev->dev);
1615
1616 otg_set_transceiver(NULL);
1617 free_irq(motg->irq, motg);
1618
1619 /*
1620 * Put PHY in low power mode.
1621 */
1622 ulpi_read(otg, 0x14);
1623 ulpi_write(otg, 0x08, 0x09);
1624
1625 writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC);
1626 while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
1627 if (readl(USB_PORTSC) & PORTSC_PHCD)
1628 break;
1629 udelay(1);
1630 cnt++;
1631 }
1632 if (cnt >= PHY_SUSPEND_TIMEOUT_USEC)
1633 dev_err(otg->dev, "Unable to suspend PHY\n");
1634
1635 clk_disable(motg->pclk);
1636 clk_disable(motg->clk);
1637 if (motg->core_clk)
1638 clk_disable(motg->core_clk);
1639 if (!IS_ERR(motg->pclk_src)) {
1640 clk_disable(motg->pclk_src);
1641 clk_put(motg->pclk_src);
1642 }
1643 msm_hsusb_ldo_init(motg, 0);
1644
1645 iounmap(motg->regs);
1646 pm_runtime_set_suspended(&pdev->dev);
1647
1648 clk_put(motg->phy_reset_clk);
1649 clk_put(motg->pclk);
1650 clk_put(motg->clk);
1651 if (motg->core_clk)
1652 clk_put(motg->core_clk);
1653
1654 kfree(motg);
1655
1656 return 0;
1657}
1658
1659#ifdef CONFIG_PM_RUNTIME
1660static int msm_otg_runtime_idle(struct device *dev)
1661{
1662 struct msm_otg *motg = dev_get_drvdata(dev);
1663 struct otg_transceiver *otg = &motg->otg;
1664
1665 dev_dbg(dev, "OTG runtime idle\n");
1666
1667 /*
1668 * It is observed some times that a spurious interrupt
1669 * comes when PHY is put into LPM immediately after PHY reset.
1670 * This 1 sec delay also prevents entering into LPM immediately
1671 * after asynchronous interrupt.
1672 */
1673 if (otg->state != OTG_STATE_UNDEFINED)
1674 pm_schedule_suspend(dev, 1000);
1675
1676 return -EAGAIN;
1677}
1678
1679static int msm_otg_runtime_suspend(struct device *dev)
1680{
1681 struct msm_otg *motg = dev_get_drvdata(dev);
1682
1683 dev_dbg(dev, "OTG runtime suspend\n");
1684 return msm_otg_suspend(motg);
1685}
1686
1687static int msm_otg_runtime_resume(struct device *dev)
1688{
1689 struct msm_otg *motg = dev_get_drvdata(dev);
1690
1691 dev_dbg(dev, "OTG runtime resume\n");
1692 return msm_otg_resume(motg);
1693}
1694#endif
1695
1696#ifdef CONFIG_PM_SLEEP
1697static int msm_otg_pm_suspend(struct device *dev)
1698{
1699 struct msm_otg *motg = dev_get_drvdata(dev);
1700
1701 dev_dbg(dev, "OTG PM suspend\n");
1702 return msm_otg_suspend(motg);
1703}
1704
1705static int msm_otg_pm_resume(struct device *dev)
1706{
1707 struct msm_otg *motg = dev_get_drvdata(dev);
1708 int ret;
1709
1710 dev_dbg(dev, "OTG PM resume\n");
1711
1712 ret = msm_otg_resume(motg);
1713 if (ret)
1714 return ret;
1715
1716 /*
1717 * Runtime PM Documentation recommends bringing the
1718 * device to full powered state upon resume.
1719 */
1720 pm_runtime_disable(dev);
1721 pm_runtime_set_active(dev);
1722 pm_runtime_enable(dev);
1723
1724 return 0;
1725}
1726#endif
1727
1728#ifdef CONFIG_PM
1729static const struct dev_pm_ops msm_otg_dev_pm_ops = {
1730 SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume)
1731 SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume,
1732 msm_otg_runtime_idle)
1733};
1734#endif
1735
1736static struct platform_driver msm_otg_driver = {
1737 .remove = __devexit_p(msm_otg_remove),
1738 .driver = {
1739 .name = DRIVER_NAME,
1740 .owner = THIS_MODULE,
1741#ifdef CONFIG_PM
1742 .pm = &msm_otg_dev_pm_ops,
1743#endif
1744 },
1745};
1746
1747static int __init msm_otg_init(void)
1748{
1749 return platform_driver_probe(&msm_otg_driver, msm_otg_probe);
1750}
1751
1752static void __exit msm_otg_exit(void)
1753{
1754 platform_driver_unregister(&msm_otg_driver);
1755}
1756
1757module_init(msm_otg_init);
1758module_exit(msm_otg_exit);
1759
1760MODULE_LICENSE("GPL v2");
1761MODULE_DESCRIPTION("MSM USB transceiver driver");
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
index e70014ab0976..c1e360046435 100644
--- a/drivers/usb/otg/nop-usb-xceiv.c
+++ b/drivers/usb/otg/nop-usb-xceiv.c
@@ -132,6 +132,8 @@ static int __devinit nop_usb_xceiv_probe(struct platform_device *pdev)
132 132
133 platform_set_drvdata(pdev, nop); 133 platform_set_drvdata(pdev, nop);
134 134
135 ATOMIC_INIT_NOTIFIER_HEAD(&nop->otg.notifier);
136
135 return 0; 137 return 0;
136exit: 138exit:
137 kfree(nop); 139 kfree(nop);
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index 0a43a7db750f..fb7adeff9ffa 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -64,3 +64,38 @@ int otg_set_transceiver(struct otg_transceiver *x)
64 return 0; 64 return 0;
65} 65}
66EXPORT_SYMBOL(otg_set_transceiver); 66EXPORT_SYMBOL(otg_set_transceiver);
67
68const char *otg_state_string(enum usb_otg_state state)
69{
70 switch (state) {
71 case OTG_STATE_A_IDLE:
72 return "a_idle";
73 case OTG_STATE_A_WAIT_VRISE:
74 return "a_wait_vrise";
75 case OTG_STATE_A_WAIT_BCON:
76 return "a_wait_bcon";
77 case OTG_STATE_A_HOST:
78 return "a_host";
79 case OTG_STATE_A_SUSPEND:
80 return "a_suspend";
81 case OTG_STATE_A_PERIPHERAL:
82 return "a_peripheral";
83 case OTG_STATE_A_WAIT_VFALL:
84 return "a_wait_vfall";
85 case OTG_STATE_A_VBUS_ERR:
86 return "a_vbus_err";
87 case OTG_STATE_B_IDLE:
88 return "b_idle";
89 case OTG_STATE_B_SRP_INIT:
90 return "b_srp_init";
91 case OTG_STATE_B_PERIPHERAL:
92 return "b_peripheral";
93 case OTG_STATE_B_WAIT_ACON:
94 return "b_wait_acon";
95 case OTG_STATE_B_HOST:
96 return "b_host";
97 default:
98 return "UNDEFINED";
99 }
100}
101EXPORT_SYMBOL(otg_state_string);
diff --git a/drivers/usb/otg/otg_fsm.c b/drivers/usb/otg/otg_fsm.c
new file mode 100644
index 000000000000..b0cc422f2ff9
--- /dev/null
+++ b/drivers/usb/otg/otg_fsm.c
@@ -0,0 +1,349 @@
1/*
2 * OTG Finite State Machine from OTG spec
3 *
4 * Copyright (C) 2007,2008 Freescale Semiconductor, Inc.
5 *
6 * Author: Li Yang <LeoLi@freescale.com>
7 * Jerry Huang <Chang-Ming.Huang@freescale.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/kernel.h>
25#include <linux/types.h>
26#include <linux/spinlock.h>
27#include <linux/delay.h>
28#include <linux/usb.h>
29#include <linux/usb/gadget.h>
30#include <linux/usb/otg.h>
31#include <linux/types.h>
32
33#include "otg_fsm.h"
34
35/* Change USB protocol when there is a protocol change */
36static int otg_set_protocol(struct otg_fsm *fsm, int protocol)
37{
38 int ret = 0;
39
40 if (fsm->protocol != protocol) {
41 VDBG("Changing role fsm->protocol= %d; new protocol= %d\n",
42 fsm->protocol, protocol);
43 /* stop old protocol */
44 if (fsm->protocol == PROTO_HOST)
45 ret = fsm->ops->start_host(fsm, 0);
46 else if (fsm->protocol == PROTO_GADGET)
47 ret = fsm->ops->start_gadget(fsm, 0);
48 if (ret)
49 return ret;
50
51 /* start new protocol */
52 if (protocol == PROTO_HOST)
53 ret = fsm->ops->start_host(fsm, 1);
54 else if (protocol == PROTO_GADGET)
55 ret = fsm->ops->start_gadget(fsm, 1);
56 if (ret)
57 return ret;
58
59 fsm->protocol = protocol;
60 return 0;
61 }
62
63 return 0;
64}
65
66static int state_changed;
67
68/* Called when leaving a state. Do state clean up jobs here */
69void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state)
70{
71 switch (old_state) {
72 case OTG_STATE_B_IDLE:
73 otg_del_timer(fsm, b_se0_srp_tmr);
74 fsm->b_se0_srp = 0;
75 break;
76 case OTG_STATE_B_SRP_INIT:
77 fsm->b_srp_done = 0;
78 break;
79 case OTG_STATE_B_PERIPHERAL:
80 break;
81 case OTG_STATE_B_WAIT_ACON:
82 otg_del_timer(fsm, b_ase0_brst_tmr);
83 fsm->b_ase0_brst_tmout = 0;
84 break;
85 case OTG_STATE_B_HOST:
86 break;
87 case OTG_STATE_A_IDLE:
88 break;
89 case OTG_STATE_A_WAIT_VRISE:
90 otg_del_timer(fsm, a_wait_vrise_tmr);
91 fsm->a_wait_vrise_tmout = 0;
92 break;
93 case OTG_STATE_A_WAIT_BCON:
94 otg_del_timer(fsm, a_wait_bcon_tmr);
95 fsm->a_wait_bcon_tmout = 0;
96 break;
97 case OTG_STATE_A_HOST:
98 otg_del_timer(fsm, a_wait_enum_tmr);
99 break;
100 case OTG_STATE_A_SUSPEND:
101 otg_del_timer(fsm, a_aidl_bdis_tmr);
102 fsm->a_aidl_bdis_tmout = 0;
103 fsm->a_suspend_req = 0;
104 break;
105 case OTG_STATE_A_PERIPHERAL:
106 break;
107 case OTG_STATE_A_WAIT_VFALL:
108 otg_del_timer(fsm, a_wait_vrise_tmr);
109 break;
110 case OTG_STATE_A_VBUS_ERR:
111 break;
112 default:
113 break;
114 }
115}
116
117/* Called when entering a state */
118int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
119{
120 state_changed = 1;
121 if (fsm->transceiver->state == new_state)
122 return 0;
123 VDBG("Set state: %s\n", otg_state_string(new_state));
124 otg_leave_state(fsm, fsm->transceiver->state);
125 switch (new_state) {
126 case OTG_STATE_B_IDLE:
127 otg_drv_vbus(fsm, 0);
128 otg_chrg_vbus(fsm, 0);
129 otg_loc_conn(fsm, 0);
130 otg_loc_sof(fsm, 0);
131 otg_set_protocol(fsm, PROTO_UNDEF);
132 otg_add_timer(fsm, b_se0_srp_tmr);
133 break;
134 case OTG_STATE_B_SRP_INIT:
135 otg_start_pulse(fsm);
136 otg_loc_sof(fsm, 0);
137 otg_set_protocol(fsm, PROTO_UNDEF);
138 otg_add_timer(fsm, b_srp_fail_tmr);
139 break;
140 case OTG_STATE_B_PERIPHERAL:
141 otg_chrg_vbus(fsm, 0);
142 otg_loc_conn(fsm, 1);
143 otg_loc_sof(fsm, 0);
144 otg_set_protocol(fsm, PROTO_GADGET);
145 break;
146 case OTG_STATE_B_WAIT_ACON:
147 otg_chrg_vbus(fsm, 0);
148 otg_loc_conn(fsm, 0);
149 otg_loc_sof(fsm, 0);
150 otg_set_protocol(fsm, PROTO_HOST);
151 otg_add_timer(fsm, b_ase0_brst_tmr);
152 fsm->a_bus_suspend = 0;
153 break;
154 case OTG_STATE_B_HOST:
155 otg_chrg_vbus(fsm, 0);
156 otg_loc_conn(fsm, 0);
157 otg_loc_sof(fsm, 1);
158 otg_set_protocol(fsm, PROTO_HOST);
159 usb_bus_start_enum(fsm->transceiver->host,
160 fsm->transceiver->host->otg_port);
161 break;
162 case OTG_STATE_A_IDLE:
163 otg_drv_vbus(fsm, 0);
164 otg_chrg_vbus(fsm, 0);
165 otg_loc_conn(fsm, 0);
166 otg_loc_sof(fsm, 0);
167 otg_set_protocol(fsm, PROTO_HOST);
168 break;
169 case OTG_STATE_A_WAIT_VRISE:
170 otg_drv_vbus(fsm, 1);
171 otg_loc_conn(fsm, 0);
172 otg_loc_sof(fsm, 0);
173 otg_set_protocol(fsm, PROTO_HOST);
174 otg_add_timer(fsm, a_wait_vrise_tmr);
175 break;
176 case OTG_STATE_A_WAIT_BCON:
177 otg_drv_vbus(fsm, 1);
178 otg_loc_conn(fsm, 0);
179 otg_loc_sof(fsm, 0);
180 otg_set_protocol(fsm, PROTO_HOST);
181 otg_add_timer(fsm, a_wait_bcon_tmr);
182 break;
183 case OTG_STATE_A_HOST:
184 otg_drv_vbus(fsm, 1);
185 otg_loc_conn(fsm, 0);
186 otg_loc_sof(fsm, 1);
187 otg_set_protocol(fsm, PROTO_HOST);
188 /*
189 * When HNP is triggered while a_bus_req = 0, a_host will
190 * suspend too fast to complete a_set_b_hnp_en
191 */
192 if (!fsm->a_bus_req || fsm->a_suspend_req)
193 otg_add_timer(fsm, a_wait_enum_tmr);
194 break;
195 case OTG_STATE_A_SUSPEND:
196 otg_drv_vbus(fsm, 1);
197 otg_loc_conn(fsm, 0);
198 otg_loc_sof(fsm, 0);
199 otg_set_protocol(fsm, PROTO_HOST);
200 otg_add_timer(fsm, a_aidl_bdis_tmr);
201
202 break;
203 case OTG_STATE_A_PERIPHERAL:
204 otg_loc_conn(fsm, 1);
205 otg_loc_sof(fsm, 0);
206 otg_set_protocol(fsm, PROTO_GADGET);
207 otg_drv_vbus(fsm, 1);
208 break;
209 case OTG_STATE_A_WAIT_VFALL:
210 otg_drv_vbus(fsm, 0);
211 otg_loc_conn(fsm, 0);
212 otg_loc_sof(fsm, 0);
213 otg_set_protocol(fsm, PROTO_HOST);
214 break;
215 case OTG_STATE_A_VBUS_ERR:
216 otg_drv_vbus(fsm, 0);
217 otg_loc_conn(fsm, 0);
218 otg_loc_sof(fsm, 0);
219 otg_set_protocol(fsm, PROTO_UNDEF);
220 break;
221 default:
222 break;
223 }
224
225 fsm->transceiver->state = new_state;
226 return 0;
227}
228
229/* State change judgement */
230int otg_statemachine(struct otg_fsm *fsm)
231{
232 enum usb_otg_state state;
233 unsigned long flags;
234
235 spin_lock_irqsave(&fsm->lock, flags);
236
237 state = fsm->transceiver->state;
238 state_changed = 0;
239 /* State machine state change judgement */
240
241 switch (state) {
242 case OTG_STATE_UNDEFINED:
243 VDBG("fsm->id = %d\n", fsm->id);
244 if (fsm->id)
245 otg_set_state(fsm, OTG_STATE_B_IDLE);
246 else
247 otg_set_state(fsm, OTG_STATE_A_IDLE);
248 break;
249 case OTG_STATE_B_IDLE:
250 if (!fsm->id)
251 otg_set_state(fsm, OTG_STATE_A_IDLE);
252 else if (fsm->b_sess_vld && fsm->transceiver->gadget)
253 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
254 else if (fsm->b_bus_req && fsm->b_sess_end && fsm->b_se0_srp)
255 otg_set_state(fsm, OTG_STATE_B_SRP_INIT);
256 break;
257 case OTG_STATE_B_SRP_INIT:
258 if (!fsm->id || fsm->b_srp_done)
259 otg_set_state(fsm, OTG_STATE_B_IDLE);
260 break;
261 case OTG_STATE_B_PERIPHERAL:
262 if (!fsm->id || !fsm->b_sess_vld)
263 otg_set_state(fsm, OTG_STATE_B_IDLE);
264 else if (fsm->b_bus_req && fsm->transceiver->
265 gadget->b_hnp_enable && fsm->a_bus_suspend)
266 otg_set_state(fsm, OTG_STATE_B_WAIT_ACON);
267 break;
268 case OTG_STATE_B_WAIT_ACON:
269 if (fsm->a_conn)
270 otg_set_state(fsm, OTG_STATE_B_HOST);
271 else if (!fsm->id || !fsm->b_sess_vld)
272 otg_set_state(fsm, OTG_STATE_B_IDLE);
273 else if (fsm->a_bus_resume || fsm->b_ase0_brst_tmout) {
274 fsm->b_ase0_brst_tmout = 0;
275 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
276 }
277 break;
278 case OTG_STATE_B_HOST:
279 if (!fsm->id || !fsm->b_sess_vld)
280 otg_set_state(fsm, OTG_STATE_B_IDLE);
281 else if (!fsm->b_bus_req || !fsm->a_conn)
282 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
283 break;
284 case OTG_STATE_A_IDLE:
285 if (fsm->id)
286 otg_set_state(fsm, OTG_STATE_B_IDLE);
287 else if (!fsm->a_bus_drop && (fsm->a_bus_req || fsm->a_srp_det))
288 otg_set_state(fsm, OTG_STATE_A_WAIT_VRISE);
289 break;
290 case OTG_STATE_A_WAIT_VRISE:
291 if (fsm->id || fsm->a_bus_drop || fsm->a_vbus_vld ||
292 fsm->a_wait_vrise_tmout) {
293 otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
294 }
295 break;
296 case OTG_STATE_A_WAIT_BCON:
297 if (!fsm->a_vbus_vld)
298 otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
299 else if (fsm->b_conn)
300 otg_set_state(fsm, OTG_STATE_A_HOST);
301 else if (fsm->id | fsm->a_bus_drop | fsm->a_wait_bcon_tmout)
302 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
303 break;
304 case OTG_STATE_A_HOST:
305 if ((!fsm->a_bus_req || fsm->a_suspend_req) &&
306 fsm->transceiver->host->b_hnp_enable)
307 otg_set_state(fsm, OTG_STATE_A_SUSPEND);
308 else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop)
309 otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
310 else if (!fsm->a_vbus_vld)
311 otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
312 break;
313 case OTG_STATE_A_SUSPEND:
314 if (!fsm->b_conn && fsm->transceiver->host->b_hnp_enable)
315 otg_set_state(fsm, OTG_STATE_A_PERIPHERAL);
316 else if (!fsm->b_conn && !fsm->transceiver->host->b_hnp_enable)
317 otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
318 else if (fsm->a_bus_req || fsm->b_bus_resume)
319 otg_set_state(fsm, OTG_STATE_A_HOST);
320 else if (fsm->id || fsm->a_bus_drop || fsm->a_aidl_bdis_tmout)
321 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
322 else if (!fsm->a_vbus_vld)
323 otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
324 break;
325 case OTG_STATE_A_PERIPHERAL:
326 if (fsm->id || fsm->a_bus_drop)
327 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
328 else if (fsm->b_bus_suspend)
329 otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
330 else if (!fsm->a_vbus_vld)
331 otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
332 break;
333 case OTG_STATE_A_WAIT_VFALL:
334 if (fsm->id || fsm->a_bus_req || (!fsm->a_sess_vld &&
335 !fsm->b_conn))
336 otg_set_state(fsm, OTG_STATE_A_IDLE);
337 break;
338 case OTG_STATE_A_VBUS_ERR:
339 if (fsm->id || fsm->a_bus_drop || fsm->a_clr_err)
340 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
341 break;
342 default:
343 break;
344 }
345 spin_unlock_irqrestore(&fsm->lock, flags);
346
347 VDBG("quit statemachine, changed = %d\n", state_changed);
348 return state_changed;
349}
diff --git a/drivers/usb/otg/otg_fsm.h b/drivers/usb/otg/otg_fsm.h
new file mode 100644
index 000000000000..0cecf1d593a0
--- /dev/null
+++ b/drivers/usb/otg/otg_fsm.h
@@ -0,0 +1,154 @@
1/* Copyright (C) 2007,2008 Freescale Semiconductor, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2 of the License, or (at your
6 * option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#undef DEBUG
19#undef VERBOSE
20
21#ifdef DEBUG
22#define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt , \
23 __func__, ## args)
24#else
25#define DBG(fmt, args...) do {} while (0)
26#endif
27
28#ifdef VERBOSE
29#define VDBG DBG
30#else
31#define VDBG(stuff...) do {} while (0)
32#endif
33
34#ifdef VERBOSE
35#define MPC_LOC printk("Current Location [%s]:[%d]\n", __FILE__, __LINE__)
36#else
37#define MPC_LOC do {} while (0)
38#endif
39
40#define PROTO_UNDEF (0)
41#define PROTO_HOST (1)
42#define PROTO_GADGET (2)
43
44/* OTG state machine according to the OTG spec */
45struct otg_fsm {
46 /* Input */
47 int a_bus_resume;
48 int a_bus_suspend;
49 int a_conn;
50 int a_sess_vld;
51 int a_srp_det;
52 int a_vbus_vld;
53 int b_bus_resume;
54 int b_bus_suspend;
55 int b_conn;
56 int b_se0_srp;
57 int b_sess_end;
58 int b_sess_vld;
59 int id;
60
61 /* Internal variables */
62 int a_set_b_hnp_en;
63 int b_srp_done;
64 int b_hnp_enable;
65
66 /* Timeout indicator for timers */
67 int a_wait_vrise_tmout;
68 int a_wait_bcon_tmout;
69 int a_aidl_bdis_tmout;
70 int b_ase0_brst_tmout;
71
72 /* Informative variables */
73 int a_bus_drop;
74 int a_bus_req;
75 int a_clr_err;
76 int a_suspend_req;
77 int b_bus_req;
78
79 /* Output */
80 int drv_vbus;
81 int loc_conn;
82 int loc_sof;
83
84 struct otg_fsm_ops *ops;
85 struct otg_transceiver *transceiver;
86
87 /* Current usb protocol used: 0:undefine; 1:host; 2:client */
88 int protocol;
89 spinlock_t lock;
90};
91
92struct otg_fsm_ops {
93 void (*chrg_vbus)(int on);
94 void (*drv_vbus)(int on);
95 void (*loc_conn)(int on);
96 void (*loc_sof)(int on);
97 void (*start_pulse)(void);
98 void (*add_timer)(void *timer);
99 void (*del_timer)(void *timer);
100 int (*start_host)(struct otg_fsm *fsm, int on);
101 int (*start_gadget)(struct otg_fsm *fsm, int on);
102};
103
104
105static inline void otg_chrg_vbus(struct otg_fsm *fsm, int on)
106{
107 fsm->ops->chrg_vbus(on);
108}
109
110static inline void otg_drv_vbus(struct otg_fsm *fsm, int on)
111{
112 if (fsm->drv_vbus != on) {
113 fsm->drv_vbus = on;
114 fsm->ops->drv_vbus(on);
115 }
116}
117
118static inline void otg_loc_conn(struct otg_fsm *fsm, int on)
119{
120 if (fsm->loc_conn != on) {
121 fsm->loc_conn = on;
122 fsm->ops->loc_conn(on);
123 }
124}
125
126static inline void otg_loc_sof(struct otg_fsm *fsm, int on)
127{
128 if (fsm->loc_sof != on) {
129 fsm->loc_sof = on;
130 fsm->ops->loc_sof(on);
131 }
132}
133
134static inline void otg_start_pulse(struct otg_fsm *fsm)
135{
136 fsm->ops->start_pulse();
137}
138
139static inline void otg_add_timer(struct otg_fsm *fsm, void *timer)
140{
141 fsm->ops->add_timer(timer);
142}
143
144static inline void otg_del_timer(struct otg_fsm *fsm, void *timer)
145{
146 fsm->ops->del_timer(timer);
147}
148
149int otg_statemachine(struct otg_fsm *fsm);
150
151/* Defined by device specific driver, for different timer implementation */
152extern struct fsl_otg_timer *a_wait_vrise_tmr, *a_wait_bcon_tmr,
153 *a_aidl_bdis_tmr, *b_ase0_brst_tmr, *b_se0_srp_tmr, *b_srp_fail_tmr,
154 *a_wait_enum_tmr;
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index 0bc97698af15..efeb4d1517ff 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -124,7 +124,6 @@
124#define PHY_DPLL_CLK (1 << 0) 124#define PHY_DPLL_CLK (1 << 0)
125 125
126/* In module TWL4030_MODULE_PM_MASTER */ 126/* In module TWL4030_MODULE_PM_MASTER */
127#define PROTECT_KEY 0x0E
128#define STS_HW_CONDITIONS 0x0F 127#define STS_HW_CONDITIONS 0x0F
129 128
130/* In module TWL4030_MODULE_PM_RECEIVER */ 129/* In module TWL4030_MODULE_PM_RECEIVER */
@@ -161,6 +160,7 @@ struct twl4030_usb {
161 160
162 int irq; 161 int irq;
163 u8 linkstat; 162 u8 linkstat;
163 bool vbus_supplied;
164 u8 asleep; 164 u8 asleep;
165 bool irq_enabled; 165 bool irq_enabled;
166}; 166};
@@ -251,6 +251,8 @@ static enum usb_xceiv_events twl4030_usb_linkstat(struct twl4030_usb *twl)
251 int status; 251 int status;
252 int linkstat = USB_EVENT_NONE; 252 int linkstat = USB_EVENT_NONE;
253 253
254 twl->vbus_supplied = false;
255
254 /* 256 /*
255 * For ID/VBUS sensing, see manual section 15.4.8 ... 257 * For ID/VBUS sensing, see manual section 15.4.8 ...
256 * except when using only battery backup power, two 258 * except when using only battery backup power, two
@@ -266,6 +268,9 @@ static enum usb_xceiv_events twl4030_usb_linkstat(struct twl4030_usb *twl)
266 if (status < 0) 268 if (status < 0)
267 dev_err(twl->dev, "USB link status err %d\n", status); 269 dev_err(twl->dev, "USB link status err %d\n", status);
268 else if (status & (BIT(7) | BIT(2))) { 270 else if (status & (BIT(7) | BIT(2))) {
271 if (status & (BIT(7)))
272 twl->vbus_supplied = true;
273
269 if (status & BIT(2)) 274 if (status & BIT(2))
270 linkstat = USB_EVENT_ID; 275 linkstat = USB_EVENT_ID;
271 else 276 else
@@ -276,6 +281,8 @@ static enum usb_xceiv_events twl4030_usb_linkstat(struct twl4030_usb *twl)
276 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", 281 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
277 status, status, linkstat); 282 status, status, linkstat);
278 283
284 twl->otg.last_event = linkstat;
285
279 /* REVISIT this assumes host and peripheral controllers 286 /* REVISIT this assumes host and peripheral controllers
280 * are registered, and that both are active... 287 * are registered, and that both are active...
281 */ 288 */
@@ -418,8 +425,13 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
418static int twl4030_usb_ldo_init(struct twl4030_usb *twl) 425static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
419{ 426{
420 /* Enable writing to power configuration registers */ 427 /* Enable writing to power configuration registers */
421 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xC0, PROTECT_KEY); 428 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
422 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x0C, PROTECT_KEY); 429 TWL4030_PM_MASTER_KEY_CFG1,
430 TWL4030_PM_MASTER_PROTECT_KEY);
431
432 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
433 TWL4030_PM_MASTER_KEY_CFG2,
434 TWL4030_PM_MASTER_PROTECT_KEY);
423 435
424 /* Keep VUSB3V1 LDO in sleep state until VBUS/ID change detected*/ 436 /* Keep VUSB3V1 LDO in sleep state until VBUS/ID change detected*/
425 /*twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2);*/ 437 /*twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2);*/
@@ -455,7 +467,8 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
455 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE); 467 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE);
456 468
457 /* disable access to power configuration registers */ 469 /* disable access to power configuration registers */
458 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, PROTECT_KEY); 470 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0,
471 TWL4030_PM_MASTER_PROTECT_KEY);
459 472
460 return 0; 473 return 0;
461 474
@@ -477,7 +490,7 @@ static ssize_t twl4030_usb_vbus_show(struct device *dev,
477 490
478 spin_lock_irqsave(&twl->lock, flags); 491 spin_lock_irqsave(&twl->lock, flags);
479 ret = sprintf(buf, "%s\n", 492 ret = sprintf(buf, "%s\n",
480 (twl->linkstat == USB_EVENT_VBUS) ? "on" : "off"); 493 twl->vbus_supplied ? "on" : "off");
481 spin_unlock_irqrestore(&twl->lock, flags); 494 spin_unlock_irqrestore(&twl->lock, flags);
482 495
483 return ret; 496 return ret;
@@ -507,7 +520,7 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
507 else 520 else
508 twl4030_phy_resume(twl); 521 twl4030_phy_resume(twl);
509 522
510 blocking_notifier_call_chain(&twl->otg.notifier, status, 523 atomic_notifier_call_chain(&twl->otg.notifier, status,
511 twl->otg.gadget); 524 twl->otg.gadget);
512 } 525 }
513 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 526 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
@@ -529,7 +542,7 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl)
529 twl->asleep = 0; 542 twl->asleep = 0;
530 } 543 }
531 544
532 blocking_notifier_call_chain(&twl->otg.notifier, status, 545 atomic_notifier_call_chain(&twl->otg.notifier, status,
533 twl->otg.gadget); 546 twl->otg.gadget);
534 } 547 }
535 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 548 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
@@ -601,6 +614,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
601 twl->otg.set_peripheral = twl4030_set_peripheral; 614 twl->otg.set_peripheral = twl4030_set_peripheral;
602 twl->otg.set_suspend = twl4030_set_suspend; 615 twl->otg.set_suspend = twl4030_set_suspend;
603 twl->usb_mode = pdata->usb_mode; 616 twl->usb_mode = pdata->usb_mode;
617 twl->vbus_supplied = false;
604 twl->asleep = 1; 618 twl->asleep = 1;
605 619
606 /* init spinlock for workqueue */ 620 /* init spinlock for workqueue */
@@ -618,7 +632,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
618 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 632 if (device_create_file(&pdev->dev, &dev_attr_vbus))
619 dev_warn(&pdev->dev, "could not create sysfs file\n"); 633 dev_warn(&pdev->dev, "could not create sysfs file\n");
620 634
621 BLOCKING_INIT_NOTIFIER_HEAD(&twl->otg.notifier); 635 ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier);
622 636
623 /* Our job is to use irqs and status from the power module 637 /* Our job is to use irqs and status from the power module
624 * to keep the transceiver disabled when nothing's connected. 638 * to keep the transceiver disabled when nothing's connected.
@@ -673,7 +687,8 @@ static int __exit twl4030_usb_remove(struct platform_device *pdev)
673 /* disable complete OTG block */ 687 /* disable complete OTG block */
674 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); 688 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB);
675 689
676 twl4030_phy_power(twl, 0); 690 if (!twl->asleep)
691 twl4030_phy_power(twl, 0);
677 regulator_put(twl->usb1v5); 692 regulator_put(twl->usb1v5);
678 regulator_put(twl->usb1v8); 693 regulator_put(twl->usb1v8);
679 regulator_put(twl->usb3v1); 694 regulator_put(twl->usb3v1);
diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/otg/twl6030-usb.c
new file mode 100644
index 000000000000..cfb5aa72b196
--- /dev/null
+++ b/drivers/usb/otg/twl6030-usb.c
@@ -0,0 +1,526 @@
1/*
2 * twl6030_usb - TWL6030 USB transceiver, talking to OMAP OTG driver.
3 *
4 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * Author: Hema HK <hemahk@ti.com>
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/platform_device.h>
27#include <linux/io.h>
28#include <linux/usb/otg.h>
29#include <linux/i2c/twl.h>
30#include <linux/regulator/consumer.h>
31#include <linux/err.h>
32#include <linux/notifier.h>
33#include <linux/slab.h>
34#include <linux/delay.h>
35
36/* usb register definitions */
37#define USB_VENDOR_ID_LSB 0x00
38#define USB_VENDOR_ID_MSB 0x01
39#define USB_PRODUCT_ID_LSB 0x02
40#define USB_PRODUCT_ID_MSB 0x03
41#define USB_VBUS_CTRL_SET 0x04
42#define USB_VBUS_CTRL_CLR 0x05
43#define USB_ID_CTRL_SET 0x06
44#define USB_ID_CTRL_CLR 0x07
45#define USB_VBUS_INT_SRC 0x08
46#define USB_VBUS_INT_LATCH_SET 0x09
47#define USB_VBUS_INT_LATCH_CLR 0x0A
48#define USB_VBUS_INT_EN_LO_SET 0x0B
49#define USB_VBUS_INT_EN_LO_CLR 0x0C
50#define USB_VBUS_INT_EN_HI_SET 0x0D
51#define USB_VBUS_INT_EN_HI_CLR 0x0E
52#define USB_ID_INT_SRC 0x0F
53#define USB_ID_INT_LATCH_SET 0x10
54#define USB_ID_INT_LATCH_CLR 0x11
55
56#define USB_ID_INT_EN_LO_SET 0x12
57#define USB_ID_INT_EN_LO_CLR 0x13
58#define USB_ID_INT_EN_HI_SET 0x14
59#define USB_ID_INT_EN_HI_CLR 0x15
60#define USB_OTG_ADP_CTRL 0x16
61#define USB_OTG_ADP_HIGH 0x17
62#define USB_OTG_ADP_LOW 0x18
63#define USB_OTG_ADP_RISE 0x19
64#define USB_OTG_REVISION 0x1A
65
66/* to be moved to LDO */
67#define TWL6030_MISC2 0xE5
68#define TWL6030_CFG_LDO_PD2 0xF5
69#define TWL6030_BACKUP_REG 0xFA
70
71#define STS_HW_CONDITIONS 0x21
72
73/* In module TWL6030_MODULE_PM_MASTER */
74#define STS_HW_CONDITIONS 0x21
75#define STS_USB_ID BIT(2)
76
77/* In module TWL6030_MODULE_PM_RECEIVER */
78#define VUSB_CFG_TRANS 0x71
79#define VUSB_CFG_STATE 0x72
80#define VUSB_CFG_VOLTAGE 0x73
81
82/* in module TWL6030_MODULE_MAIN_CHARGE */
83
84#define CHARGERUSB_CTRL1 0x8
85
86#define CONTROLLER_STAT1 0x03
87#define VBUS_DET BIT(2)
88
89struct twl6030_usb {
90 struct otg_transceiver otg;
91 struct device *dev;
92
93 /* for vbus reporting with irqs disabled */
94 spinlock_t lock;
95
96 struct regulator *usb3v3;
97
98 int irq1;
99 int irq2;
100 u8 linkstat;
101 u8 asleep;
102 bool irq_enabled;
103 unsigned long features;
104};
105
106#define xceiv_to_twl(x) container_of((x), struct twl6030_usb, otg)
107
108/*-------------------------------------------------------------------------*/
109
110static inline int twl6030_writeb(struct twl6030_usb *twl, u8 module,
111 u8 data, u8 address)
112{
113 int ret = 0;
114
115 ret = twl_i2c_write_u8(module, data, address);
116 if (ret < 0)
117 dev_err(twl->dev,
118 "Write[0x%x] Error %d\n", address, ret);
119 return ret;
120}
121
122static inline u8 twl6030_readb(struct twl6030_usb *twl, u8 module, u8 address)
123{
124 u8 data, ret = 0;
125
126 ret = twl_i2c_read_u8(module, &data, address);
127 if (ret >= 0)
128 ret = data;
129 else
130 dev_err(twl->dev,
131 "readb[0x%x,0x%x] Error %d\n",
132 module, address, ret);
133 return ret;
134}
135
136/*-------------------------------------------------------------------------*/
137static int twl6030_set_phy_clk(struct otg_transceiver *x, int on)
138{
139 struct twl6030_usb *twl;
140 struct device *dev;
141 struct twl4030_usb_data *pdata;
142
143 twl = xceiv_to_twl(x);
144 dev = twl->dev;
145 pdata = dev->platform_data;
146
147 pdata->phy_set_clock(twl->dev, on);
148
149 return 0;
150}
151
152static int twl6030_phy_init(struct otg_transceiver *x)
153{
154 struct twl6030_usb *twl;
155 struct device *dev;
156 struct twl4030_usb_data *pdata;
157
158 twl = xceiv_to_twl(x);
159 dev = twl->dev;
160 pdata = dev->platform_data;
161
162 if (twl->linkstat == USB_EVENT_ID)
163 pdata->phy_power(twl->dev, 1, 1);
164 else
165 pdata->phy_power(twl->dev, 0, 1);
166
167 return 0;
168}
169
170static void twl6030_phy_shutdown(struct otg_transceiver *x)
171{
172 struct twl6030_usb *twl;
173 struct device *dev;
174 struct twl4030_usb_data *pdata;
175
176 twl = xceiv_to_twl(x);
177 dev = twl->dev;
178 pdata = dev->platform_data;
179 pdata->phy_power(twl->dev, 0, 0);
180}
181
182static int twl6030_phy_suspend(struct otg_transceiver *x, int suspend)
183{
184 struct twl6030_usb *twl = xceiv_to_twl(x);
185 struct device *dev = twl->dev;
186 struct twl4030_usb_data *pdata = dev->platform_data;
187
188 pdata->phy_suspend(dev, suspend);
189
190 return 0;
191}
192
193static int twl6030_start_srp(struct otg_transceiver *x)
194{
195 struct twl6030_usb *twl = xceiv_to_twl(x);
196
197 twl6030_writeb(twl, TWL_MODULE_USB, 0x24, USB_VBUS_CTRL_SET);
198 twl6030_writeb(twl, TWL_MODULE_USB, 0x84, USB_VBUS_CTRL_SET);
199
200 mdelay(100);
201 twl6030_writeb(twl, TWL_MODULE_USB, 0xa0, USB_VBUS_CTRL_CLR);
202
203 return 0;
204}
205
206static int twl6030_usb_ldo_init(struct twl6030_usb *twl)
207{
208 char *regulator_name;
209
210 if (twl->features & TWL6025_SUBCLASS)
211 regulator_name = "ldousb";
212 else
213 regulator_name = "vusb";
214
215 /* Set to OTG_REV 1.3 and turn on the ID_WAKEUP_COMP */
216 twl6030_writeb(twl, TWL6030_MODULE_ID0 , 0x1, TWL6030_BACKUP_REG);
217
218 /* Program CFG_LDO_PD2 register and set VUSB bit */
219 twl6030_writeb(twl, TWL6030_MODULE_ID0 , 0x1, TWL6030_CFG_LDO_PD2);
220
221 /* Program MISC2 register and set bit VUSB_IN_VBAT */
222 twl6030_writeb(twl, TWL6030_MODULE_ID0 , 0x10, TWL6030_MISC2);
223
224 twl->usb3v3 = regulator_get(twl->dev, regulator_name);
225 if (IS_ERR(twl->usb3v3))
226 return -ENODEV;
227
228 /* Program the USB_VBUS_CTRL_SET and set VBUS_ACT_COMP bit */
229 twl6030_writeb(twl, TWL_MODULE_USB, 0x4, USB_VBUS_CTRL_SET);
230
231 /*
232 * Program the USB_ID_CTRL_SET register to enable GND drive
233 * and the ID comparators
234 */
235 twl6030_writeb(twl, TWL_MODULE_USB, 0x14, USB_ID_CTRL_SET);
236
237 return 0;
238}
239
240static ssize_t twl6030_usb_vbus_show(struct device *dev,
241 struct device_attribute *attr, char *buf)
242{
243 struct twl6030_usb *twl = dev_get_drvdata(dev);
244 unsigned long flags;
245 int ret = -EINVAL;
246
247 spin_lock_irqsave(&twl->lock, flags);
248
249 switch (twl->linkstat) {
250 case USB_EVENT_VBUS:
251 ret = snprintf(buf, PAGE_SIZE, "vbus\n");
252 break;
253 case USB_EVENT_ID:
254 ret = snprintf(buf, PAGE_SIZE, "id\n");
255 break;
256 case USB_EVENT_NONE:
257 ret = snprintf(buf, PAGE_SIZE, "none\n");
258 break;
259 default:
260 ret = snprintf(buf, PAGE_SIZE, "UNKNOWN\n");
261 }
262 spin_unlock_irqrestore(&twl->lock, flags);
263
264 return ret;
265}
266static DEVICE_ATTR(vbus, 0444, twl6030_usb_vbus_show, NULL);
267
268static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
269{
270 struct twl6030_usb *twl = _twl;
271 int status;
272 u8 vbus_state, hw_state;
273
274 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
275
276 vbus_state = twl6030_readb(twl, TWL_MODULE_MAIN_CHARGE,
277 CONTROLLER_STAT1);
278 if (!(hw_state & STS_USB_ID)) {
279 if (vbus_state & VBUS_DET) {
280 regulator_enable(twl->usb3v3);
281 twl->asleep = 1;
282 status = USB_EVENT_VBUS;
283 twl->otg.default_a = false;
284 twl->otg.state = OTG_STATE_B_IDLE;
285 twl->linkstat = status;
286 twl->otg.last_event = status;
287 atomic_notifier_call_chain(&twl->otg.notifier,
288 status, twl->otg.gadget);
289 } else {
290 status = USB_EVENT_NONE;
291 twl->linkstat = status;
292 twl->otg.last_event = status;
293 atomic_notifier_call_chain(&twl->otg.notifier,
294 status, twl->otg.gadget);
295 if (twl->asleep) {
296 regulator_disable(twl->usb3v3);
297 twl->asleep = 0;
298 }
299 }
300 }
301 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
302
303 return IRQ_HANDLED;
304}
305
306static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
307{
308 struct twl6030_usb *twl = _twl;
309 int status = USB_EVENT_NONE;
310 u8 hw_state;
311
312 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
313
314 if (hw_state & STS_USB_ID) {
315
316 regulator_enable(twl->usb3v3);
317 twl->asleep = 1;
318 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR, 0x1);
319 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET,
320 0x10);
321 status = USB_EVENT_ID;
322 twl->otg.default_a = true;
323 twl->otg.state = OTG_STATE_A_IDLE;
324 twl->linkstat = status;
325 twl->otg.last_event = status;
326 atomic_notifier_call_chain(&twl->otg.notifier, status,
327 twl->otg.gadget);
328 } else {
329 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR,
330 0x10);
331 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET,
332 0x1);
333 }
334 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_LATCH_CLR, status);
335
336 return IRQ_HANDLED;
337}
338
339static int twl6030_set_peripheral(struct otg_transceiver *x,
340 struct usb_gadget *gadget)
341{
342 struct twl6030_usb *twl;
343
344 if (!x)
345 return -ENODEV;
346
347 twl = xceiv_to_twl(x);
348 twl->otg.gadget = gadget;
349 if (!gadget)
350 twl->otg.state = OTG_STATE_UNDEFINED;
351
352 return 0;
353}
354
355static int twl6030_enable_irq(struct otg_transceiver *x)
356{
357 struct twl6030_usb *twl = xceiv_to_twl(x);
358
359 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET, 0x1);
360 twl6030_interrupt_unmask(0x05, REG_INT_MSK_LINE_C);
361 twl6030_interrupt_unmask(0x05, REG_INT_MSK_STS_C);
362
363 twl6030_interrupt_unmask(TWL6030_CHARGER_CTRL_INT_MASK,
364 REG_INT_MSK_LINE_C);
365 twl6030_interrupt_unmask(TWL6030_CHARGER_CTRL_INT_MASK,
366 REG_INT_MSK_STS_C);
367 twl6030_usb_irq(twl->irq2, twl);
368 twl6030_usbotg_irq(twl->irq1, twl);
369
370 return 0;
371}
372
373static int twl6030_set_vbus(struct otg_transceiver *x, bool enabled)
374{
375 struct twl6030_usb *twl = xceiv_to_twl(x);
376
377 /*
378 * Start driving VBUS. Set OPA_MODE bit in CHARGERUSB_CTRL1
379 * register. This enables boost mode.
380 */
381 if (enabled)
382 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x40,
383 CHARGERUSB_CTRL1);
384 else
385 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x00,
386 CHARGERUSB_CTRL1);
387 return 0;
388}
389
390static int twl6030_set_host(struct otg_transceiver *x, struct usb_bus *host)
391{
392 struct twl6030_usb *twl;
393
394 if (!x)
395 return -ENODEV;
396
397 twl = xceiv_to_twl(x);
398 twl->otg.host = host;
399 if (!host)
400 twl->otg.state = OTG_STATE_UNDEFINED;
401 return 0;
402}
403
404static int __devinit twl6030_usb_probe(struct platform_device *pdev)
405{
406 struct twl6030_usb *twl;
407 int status, err;
408 struct twl4030_usb_data *pdata;
409 struct device *dev = &pdev->dev;
410 pdata = dev->platform_data;
411
412 twl = kzalloc(sizeof *twl, GFP_KERNEL);
413 if (!twl)
414 return -ENOMEM;
415
416 twl->dev = &pdev->dev;
417 twl->irq1 = platform_get_irq(pdev, 0);
418 twl->irq2 = platform_get_irq(pdev, 1);
419 twl->features = pdata->features;
420 twl->otg.dev = twl->dev;
421 twl->otg.label = "twl6030";
422 twl->otg.set_host = twl6030_set_host;
423 twl->otg.set_peripheral = twl6030_set_peripheral;
424 twl->otg.set_vbus = twl6030_set_vbus;
425 twl->otg.init = twl6030_phy_init;
426 twl->otg.shutdown = twl6030_phy_shutdown;
427 twl->otg.set_suspend = twl6030_phy_suspend;
428 twl->otg.start_srp = twl6030_start_srp;
429
430 /* init spinlock for workqueue */
431 spin_lock_init(&twl->lock);
432
433 err = twl6030_usb_ldo_init(twl);
434 if (err) {
435 dev_err(&pdev->dev, "ldo init failed\n");
436 kfree(twl);
437 return err;
438 }
439 otg_set_transceiver(&twl->otg);
440
441 platform_set_drvdata(pdev, twl);
442 if (device_create_file(&pdev->dev, &dev_attr_vbus))
443 dev_warn(&pdev->dev, "could not create sysfs file\n");
444
445 ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier);
446
447 twl->irq_enabled = true;
448 status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq,
449 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
450 "twl6030_usb", twl);
451 if (status < 0) {
452 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
453 twl->irq1, status);
454 device_remove_file(twl->dev, &dev_attr_vbus);
455 kfree(twl);
456 return status;
457 }
458
459 status = request_threaded_irq(twl->irq2, NULL, twl6030_usb_irq,
460 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
461 "twl6030_usb", twl);
462 if (status < 0) {
463 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
464 twl->irq2, status);
465 free_irq(twl->irq1, twl);
466 device_remove_file(twl->dev, &dev_attr_vbus);
467 kfree(twl);
468 return status;
469 }
470
471 twl->asleep = 0;
472 pdata->phy_init(dev);
473 twl6030_phy_suspend(&twl->otg, 0);
474 twl6030_enable_irq(&twl->otg);
475 dev_info(&pdev->dev, "Initialized TWL6030 USB module\n");
476
477 return 0;
478}
479
480static int __exit twl6030_usb_remove(struct platform_device *pdev)
481{
482 struct twl6030_usb *twl = platform_get_drvdata(pdev);
483
484 struct twl4030_usb_data *pdata;
485 struct device *dev = &pdev->dev;
486 pdata = dev->platform_data;
487
488 twl6030_interrupt_mask(TWL6030_USBOTG_INT_MASK,
489 REG_INT_MSK_LINE_C);
490 twl6030_interrupt_mask(TWL6030_USBOTG_INT_MASK,
491 REG_INT_MSK_STS_C);
492 free_irq(twl->irq1, twl);
493 free_irq(twl->irq2, twl);
494 regulator_put(twl->usb3v3);
495 pdata->phy_exit(twl->dev);
496 device_remove_file(twl->dev, &dev_attr_vbus);
497 kfree(twl);
498
499 return 0;
500}
501
502static struct platform_driver twl6030_usb_driver = {
503 .probe = twl6030_usb_probe,
504 .remove = __exit_p(twl6030_usb_remove),
505 .driver = {
506 .name = "twl6030_usb",
507 .owner = THIS_MODULE,
508 },
509};
510
511static int __init twl6030_usb_init(void)
512{
513 return platform_driver_register(&twl6030_usb_driver);
514}
515subsys_initcall(twl6030_usb_init);
516
517static void __exit twl6030_usb_exit(void)
518{
519 platform_driver_unregister(&twl6030_usb_driver);
520}
521module_exit(twl6030_usb_exit);
522
523MODULE_ALIAS("platform:twl6030_usb");
524MODULE_AUTHOR("Hema HK <hemahk@ti.com>");
525MODULE_DESCRIPTION("TWL6030 USB transceiver driver");
526MODULE_LICENSE("GPL");
diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/otg/ulpi.c
index ccc81950822b..770d799d5afb 100644
--- a/drivers/usb/otg/ulpi.c
+++ b/drivers/usb/otg/ulpi.c
@@ -29,12 +29,23 @@
29#include <linux/usb/otg.h> 29#include <linux/usb/otg.h>
30#include <linux/usb/ulpi.h> 30#include <linux/usb/ulpi.h>
31 31
32
33struct ulpi_info {
34 unsigned int id;
35 char *name;
36};
37
32#define ULPI_ID(vendor, product) (((vendor) << 16) | (product)) 38#define ULPI_ID(vendor, product) (((vendor) << 16) | (product))
39#define ULPI_INFO(_id, _name) \
40 { \
41 .id = (_id), \
42 .name = (_name), \
43 }
33 44
34/* ULPI hardcoded IDs, used for probing */ 45/* ULPI hardcoded IDs, used for probing */
35static unsigned int ulpi_ids[] = { 46static struct ulpi_info ulpi_ids[] = {
36 ULPI_ID(0x04cc, 0x1504), /* NXP ISP1504 */ 47 ULPI_INFO(ULPI_ID(0x04cc, 0x1504), "NXP ISP1504"),
37 ULPI_ID(0x0424, 0x0006), /* SMSC USB3319 */ 48 ULPI_INFO(ULPI_ID(0x0424, 0x0006), "SMSC USB331x"),
38}; 49};
39 50
40static int ulpi_set_otg_flags(struct otg_transceiver *otg) 51static int ulpi_set_otg_flags(struct otg_transceiver *otg)
@@ -137,6 +148,32 @@ static int ulpi_set_flags(struct otg_transceiver *otg)
137 return ulpi_set_fc_flags(otg); 148 return ulpi_set_fc_flags(otg);
138} 149}
139 150
151static int ulpi_check_integrity(struct otg_transceiver *otg)
152{
153 int ret, i;
154 unsigned int val = 0x55;
155
156 for (i = 0; i < 2; i++) {
157 ret = otg_io_write(otg, val, ULPI_SCRATCH);
158 if (ret < 0)
159 return ret;
160
161 ret = otg_io_read(otg, ULPI_SCRATCH);
162 if (ret < 0)
163 return ret;
164
165 if (ret != val) {
166 pr_err("ULPI integrity check: failed!");
167 return -ENODEV;
168 }
169 val = val << 1;
170 }
171
172 pr_info("ULPI integrity check: passed.\n");
173
174 return 0;
175}
176
140static int ulpi_init(struct otg_transceiver *otg) 177static int ulpi_init(struct otg_transceiver *otg)
141{ 178{
142 int i, vid, pid, ret; 179 int i, vid, pid, ret;
@@ -153,12 +190,19 @@ static int ulpi_init(struct otg_transceiver *otg)
153 190
154 pr_info("ULPI transceiver vendor/product ID 0x%04x/0x%04x\n", vid, pid); 191 pr_info("ULPI transceiver vendor/product ID 0x%04x/0x%04x\n", vid, pid);
155 192
156 for (i = 0; i < ARRAY_SIZE(ulpi_ids); i++) 193 for (i = 0; i < ARRAY_SIZE(ulpi_ids); i++) {
157 if (ulpi_ids[i] == ULPI_ID(vid, pid)) 194 if (ulpi_ids[i].id == ULPI_ID(vid, pid)) {
158 return ulpi_set_flags(otg); 195 pr_info("Found %s ULPI transceiver.\n",
196 ulpi_ids[i].name);
197 break;
198 }
199 }
200
201 ret = ulpi_check_integrity(otg);
202 if (ret)
203 return ret;
159 204
160 pr_err("ULPI ID does not match any known transceiver.\n"); 205 return ulpi_set_flags(otg);
161 return -ENODEV;
162} 206}
163 207
164static int ulpi_set_host(struct otg_transceiver *otg, struct usb_bus *host) 208static int ulpi_set_host(struct otg_transceiver *otg, struct usb_bus *host)
diff --git a/drivers/usb/otg/ulpi_viewport.c b/drivers/usb/otg/ulpi_viewport.c
new file mode 100644
index 000000000000..e9a37f90994f
--- /dev/null
+++ b/drivers/usb/otg/ulpi_viewport.c
@@ -0,0 +1,80 @@
1/*
2 * Copyright (C) 2011 Google, Inc.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#include <linux/kernel.h>
16#include <linux/usb.h>
17#include <linux/io.h>
18#include <linux/usb/otg.h>
19#include <linux/usb/ulpi.h>
20
21#define ULPI_VIEW_WAKEUP (1 << 31)
22#define ULPI_VIEW_RUN (1 << 30)
23#define ULPI_VIEW_WRITE (1 << 29)
24#define ULPI_VIEW_READ (0 << 29)
25#define ULPI_VIEW_ADDR(x) (((x) & 0xff) << 16)
26#define ULPI_VIEW_DATA_READ(x) (((x) >> 8) & 0xff)
27#define ULPI_VIEW_DATA_WRITE(x) ((x) & 0xff)
28
29static int ulpi_viewport_wait(void __iomem *view, u32 mask)
30{
31 unsigned long usec = 2000;
32
33 while (usec--) {
34 if (!(readl(view) & mask))
35 return 0;
36
37 udelay(1);
38 };
39
40 return -ETIMEDOUT;
41}
42
43static int ulpi_viewport_read(struct otg_transceiver *otg, u32 reg)
44{
45 int ret;
46 void __iomem *view = otg->io_priv;
47
48 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
49 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
50 if (ret)
51 return ret;
52
53 writel(ULPI_VIEW_RUN | ULPI_VIEW_READ | ULPI_VIEW_ADDR(reg), view);
54 ret = ulpi_viewport_wait(view, ULPI_VIEW_RUN);
55 if (ret)
56 return ret;
57
58 return ULPI_VIEW_DATA_READ(readl(view));
59}
60
61static int ulpi_viewport_write(struct otg_transceiver *otg, u32 val, u32 reg)
62{
63 int ret;
64 void __iomem *view = otg->io_priv;
65
66 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
67 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
68 if (ret)
69 return ret;
70
71 writel(ULPI_VIEW_RUN | ULPI_VIEW_WRITE | ULPI_VIEW_DATA_WRITE(val) |
72 ULPI_VIEW_ADDR(reg), view);
73
74 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
75}
76
77struct otg_io_access_ops ulpi_viewport_access_ops = {
78 .read = ulpi_viewport_read,
79 .write = ulpi_viewport_write,
80};
diff --git a/drivers/usb/renesas_usbhs/Kconfig b/drivers/usb/renesas_usbhs/Kconfig
new file mode 100644
index 000000000000..b2e64918884c
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/Kconfig
@@ -0,0 +1,16 @@
1#
2# Renesas USB Controller Drivers
3#
4
5config USB_RENESAS_USBHS
6 tristate 'Renesas USBHS controller'
7 depends on SUPERH || ARCH_SHMOBILE
8 default n
9 help
10 Renesas USBHS is a discrete USB host and peripheral controller chip
11 that supports both full and high speed USB 2.0 data transfers.
12 It has nine or more configurable endpoints, and endpoint zero.
13
14 Say "y" to link the driver statically, or "m" to build a
15 dynamically linked module called "renesas_usbhs" and force all
16 gadget drivers to also be dynamically linked.
diff --git a/drivers/usb/renesas_usbhs/Makefile b/drivers/usb/renesas_usbhs/Makefile
new file mode 100644
index 000000000000..b8798ad16278
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/Makefile
@@ -0,0 +1,9 @@
1#
2# for Renesas USB
3#
4
5obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs.o
6
7renesas_usbhs-y := common.o mod.o pipe.o
8
9renesas_usbhs-$(CONFIG_USB_RENESAS_USBHS_UDC) += mod_gadget.o
diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
new file mode 100644
index 000000000000..f3664d6af661
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -0,0 +1,437 @@
1/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/pm_runtime.h>
20#include <linux/slab.h>
21#include <linux/sysfs.h>
22#include "./common.h"
23
24#define USBHSF_RUNTIME_PWCTRL (1 << 0)
25
26/* status */
27#define usbhsc_flags_init(p) do {(p)->flags = 0; } while (0)
28#define usbhsc_flags_set(p, b) ((p)->flags |= (b))
29#define usbhsc_flags_clr(p, b) ((p)->flags &= ~(b))
30#define usbhsc_flags_has(p, b) ((p)->flags & (b))
31
32/*
33 * platform call back
34 *
35 * renesas usb support platform callback function.
36 * Below macro call it.
37 * if platform doesn't have callback, it return 0 (no error)
38 */
39#define usbhs_platform_call(priv, func, args...)\
40 (!(priv) ? -ENODEV : \
41 !((priv)->pfunc->func) ? 0 : \
42 (priv)->pfunc->func(args))
43
44/*
45 * common functions
46 */
47u16 usbhs_read(struct usbhs_priv *priv, u32 reg)
48{
49 return ioread16(priv->base + reg);
50}
51
52void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data)
53{
54 iowrite16(data, priv->base + reg);
55}
56
57void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data)
58{
59 u16 val = usbhs_read(priv, reg);
60
61 val &= ~mask;
62 val |= data & mask;
63
64 usbhs_write(priv, reg, val);
65}
66
67struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev)
68{
69 return dev_get_drvdata(&pdev->dev);
70}
71
72/*
73 * syscfg functions
74 */
75void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable)
76{
77 usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0);
78}
79
80void usbhs_sys_hispeed_ctrl(struct usbhs_priv *priv, int enable)
81{
82 usbhs_bset(priv, SYSCFG, HSE, enable ? HSE : 0);
83}
84
85void usbhs_sys_usb_ctrl(struct usbhs_priv *priv, int enable)
86{
87 usbhs_bset(priv, SYSCFG, USBE, enable ? USBE : 0);
88}
89
90void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
91{
92 u16 mask = DCFM | DRPD | DPRPU;
93 u16 val = DCFM | DRPD;
94
95 /*
96 * if enable
97 *
98 * - select Host mode
99 * - D+ Line/D- Line Pull-down
100 */
101 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
102}
103
104void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
105{
106 u16 mask = DCFM | DRPD | DPRPU;
107 u16 val = DPRPU;
108
109 /*
110 * if enable
111 *
112 * - select Function mode
113 * - D+ Line Pull-up
114 */
115 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
116}
117
118/*
119 * frame functions
120 */
121int usbhs_frame_get_num(struct usbhs_priv *priv)
122{
123 return usbhs_read(priv, FRMNUM) & FRNM_MASK;
124}
125
126/*
127 * local functions
128 */
129static void usbhsc_bus_ctrl(struct usbhs_priv *priv, int enable)
130{
131 int wait = usbhs_get_dparam(priv, buswait_bwait);
132 u16 data = 0;
133
134 if (enable) {
135 /* set bus wait if platform have */
136 if (wait)
137 usbhs_bset(priv, BUSWAIT, 0x000F, wait);
138 }
139 usbhs_write(priv, DVSTCTR, data);
140}
141
142/*
143 * platform default param
144 */
145static u32 usbhsc_default_pipe_type[] = {
146 USB_ENDPOINT_XFER_CONTROL,
147 USB_ENDPOINT_XFER_ISOC,
148 USB_ENDPOINT_XFER_ISOC,
149 USB_ENDPOINT_XFER_BULK,
150 USB_ENDPOINT_XFER_BULK,
151 USB_ENDPOINT_XFER_BULK,
152 USB_ENDPOINT_XFER_INT,
153 USB_ENDPOINT_XFER_INT,
154 USB_ENDPOINT_XFER_INT,
155 USB_ENDPOINT_XFER_INT,
156};
157
158/*
159 * power control
160 */
161static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable)
162{
163 struct device *dev = usbhs_priv_to_dev(priv);
164
165 if (enable) {
166 /* enable PM */
167 pm_runtime_get_sync(dev);
168
169 /* USB on */
170 usbhs_sys_clock_ctrl(priv, enable);
171 usbhsc_bus_ctrl(priv, enable);
172 } else {
173 /* USB off */
174 usbhsc_bus_ctrl(priv, enable);
175 usbhs_sys_clock_ctrl(priv, enable);
176
177 /* disable PM */
178 pm_runtime_put_sync(dev);
179 }
180}
181
182/*
183 * notify hotplug
184 */
185static void usbhsc_notify_hotplug(struct work_struct *work)
186{
187 struct usbhs_priv *priv = container_of(work,
188 struct usbhs_priv,
189 notify_hotplug_work.work);
190 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
191 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
192 int id;
193 int enable;
194 int ret;
195
196 /*
197 * get vbus status from platform
198 */
199 enable = usbhs_platform_call(priv, get_vbus, pdev);
200
201 /*
202 * get id from platform
203 */
204 id = usbhs_platform_call(priv, get_id, pdev);
205
206 if (enable && !mod) {
207 ret = usbhs_mod_change(priv, id);
208 if (ret < 0)
209 return;
210
211 dev_dbg(&pdev->dev, "%s enable\n", __func__);
212
213 /* power on */
214 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
215 usbhsc_power_ctrl(priv, enable);
216
217 /* module start */
218 usbhs_mod_call(priv, start, priv);
219
220 } else if (!enable && mod) {
221 dev_dbg(&pdev->dev, "%s disable\n", __func__);
222
223 /* module stop */
224 usbhs_mod_call(priv, stop, priv);
225
226 /* power off */
227 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
228 usbhsc_power_ctrl(priv, enable);
229
230 usbhs_mod_change(priv, -1);
231
232 /* reset phy for next connection */
233 usbhs_platform_call(priv, phy_reset, pdev);
234 }
235}
236
237int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
238{
239 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
240 int delay = usbhs_get_dparam(priv, detection_delay);
241
242 /*
243 * This functions will be called in interrupt.
244 * To make sure safety context,
245 * use workqueue for usbhs_notify_hotplug
246 */
247 schedule_delayed_work(&priv->notify_hotplug_work, delay);
248 return 0;
249}
250
251/*
252 * platform functions
253 */
254static int __devinit usbhs_probe(struct platform_device *pdev)
255{
256 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
257 struct renesas_usbhs_driver_callback *dfunc;
258 struct usbhs_priv *priv;
259 struct resource *res;
260 unsigned int irq;
261 int ret;
262
263 /* check platform information */
264 if (!info ||
265 !info->platform_callback.get_id) {
266 dev_err(&pdev->dev, "no platform information\n");
267 return -EINVAL;
268 }
269
270 /* platform data */
271 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
272 irq = platform_get_irq(pdev, 0);
273 if (!res || (int)irq <= 0) {
274 dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n");
275 return -ENODEV;
276 }
277
278 /* usb private data */
279 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
280 if (!priv) {
281 dev_err(&pdev->dev, "Could not allocate priv\n");
282 return -ENOMEM;
283 }
284
285 priv->base = ioremap_nocache(res->start, resource_size(res));
286 if (!priv->base) {
287 dev_err(&pdev->dev, "ioremap error.\n");
288 ret = -ENOMEM;
289 goto probe_end_kfree;
290 }
291
292 /*
293 * care platform info
294 */
295 priv->pfunc = &info->platform_callback;
296 priv->dparam = &info->driver_param;
297
298 /* set driver callback functions for platform */
299 dfunc = &info->driver_callback;
300 dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug;
301
302 /* set default param if platform doesn't have */
303 if (!priv->dparam->pipe_type) {
304 priv->dparam->pipe_type = usbhsc_default_pipe_type;
305 priv->dparam->pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type);
306 }
307
308 /* FIXME */
309 /* runtime power control ? */
310 if (priv->pfunc->get_vbus)
311 usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL);
312
313 /*
314 * priv settings
315 */
316 priv->irq = irq;
317 priv->pdev = pdev;
318 INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug);
319 spin_lock_init(usbhs_priv_to_lock(priv));
320
321 /* call pipe and module init */
322 ret = usbhs_pipe_probe(priv);
323 if (ret < 0)
324 goto probe_end_iounmap;
325
326 ret = usbhs_mod_probe(priv);
327 if (ret < 0)
328 goto probe_end_pipe_exit;
329
330 /* dev_set_drvdata should be called after usbhs_mod_init */
331 dev_set_drvdata(&pdev->dev, priv);
332
333 /*
334 * deviece reset here because
335 * USB device might be used in boot loader.
336 */
337 usbhs_sys_clock_ctrl(priv, 0);
338
339 /*
340 * platform call
341 *
342 * USB phy setup might depend on CPU/Board.
343 * If platform has its callback functions,
344 * call it here.
345 */
346 ret = usbhs_platform_call(priv, hardware_init, pdev);
347 if (ret < 0) {
348 dev_err(&pdev->dev, "platform prove failed.\n");
349 goto probe_end_mod_exit;
350 }
351
352 /* reset phy for connection */
353 usbhs_platform_call(priv, phy_reset, pdev);
354
355 /* power control */
356 pm_runtime_enable(&pdev->dev);
357 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) {
358 usbhsc_power_ctrl(priv, 1);
359 usbhs_mod_autonomy_mode(priv);
360 }
361
362 /*
363 * manual call notify_hotplug for cold plug
364 */
365 ret = usbhsc_drvcllbck_notify_hotplug(pdev);
366 if (ret < 0)
367 goto probe_end_call_remove;
368
369 dev_info(&pdev->dev, "probed\n");
370
371 return ret;
372
373probe_end_call_remove:
374 usbhs_platform_call(priv, hardware_exit, pdev);
375probe_end_mod_exit:
376 usbhs_mod_remove(priv);
377probe_end_pipe_exit:
378 usbhs_pipe_remove(priv);
379probe_end_iounmap:
380 iounmap(priv->base);
381probe_end_kfree:
382 kfree(priv);
383
384 dev_info(&pdev->dev, "probe failed\n");
385
386 return ret;
387}
388
389static int __devexit usbhs_remove(struct platform_device *pdev)
390{
391 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
392 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
393 struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback;
394
395 dev_dbg(&pdev->dev, "usb remove\n");
396
397 dfunc->notify_hotplug = NULL;
398
399 /* power off */
400 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
401 usbhsc_power_ctrl(priv, 0);
402
403 pm_runtime_disable(&pdev->dev);
404
405 usbhs_platform_call(priv, hardware_exit, pdev);
406 usbhs_mod_remove(priv);
407 usbhs_pipe_remove(priv);
408 iounmap(priv->base);
409 kfree(priv);
410
411 return 0;
412}
413
414static struct platform_driver renesas_usbhs_driver = {
415 .driver = {
416 .name = "renesas_usbhs",
417 },
418 .probe = usbhs_probe,
419 .remove = __devexit_p(usbhs_remove),
420};
421
422static int __init usbhs_init(void)
423{
424 return platform_driver_register(&renesas_usbhs_driver);
425}
426
427static void __exit usbhs_exit(void)
428{
429 platform_driver_unregister(&renesas_usbhs_driver);
430}
431
432module_init(usbhs_init);
433module_exit(usbhs_exit);
434
435MODULE_LICENSE("GPL");
436MODULE_DESCRIPTION("Renesas USB driver");
437MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h
new file mode 100644
index 000000000000..0aadcb402764
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -0,0 +1,230 @@
1/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#ifndef RENESAS_USB_DRIVER_H
18#define RENESAS_USB_DRIVER_H
19
20#include <linux/platform_device.h>
21#include <linux/usb/renesas_usbhs.h>
22
23struct usbhs_priv;
24
25#include "./mod.h"
26#include "./pipe.h"
27
28/*
29 *
30 * register define
31 *
32 */
33#define SYSCFG 0x0000
34#define BUSWAIT 0x0002
35#define DVSTCTR 0x0008
36#define CFIFO 0x0014
37#define CFIFOSEL 0x0020
38#define CFIFOCTR 0x0022
39#define INTENB0 0x0030
40#define INTENB1 0x0032
41#define BRDYENB 0x0036
42#define NRDYENB 0x0038
43#define BEMPENB 0x003A
44#define INTSTS0 0x0040
45#define INTSTS1 0x0042
46#define BRDYSTS 0x0046
47#define NRDYSTS 0x0048
48#define BEMPSTS 0x004A
49#define FRMNUM 0x004C
50#define USBREQ 0x0054 /* USB request type register */
51#define USBVAL 0x0056 /* USB request value register */
52#define USBINDX 0x0058 /* USB request index register */
53#define USBLENG 0x005A /* USB request length register */
54#define DCPCFG 0x005C
55#define DCPMAXP 0x005E
56#define DCPCTR 0x0060
57#define PIPESEL 0x0064
58#define PIPECFG 0x0068
59#define PIPEBUF 0x006A
60#define PIPEMAXP 0x006C
61#define PIPEPERI 0x006E
62#define PIPEnCTR 0x0070
63
64/* SYSCFG */
65#define SCKE (1 << 10) /* USB Module Clock Enable */
66#define HSE (1 << 7) /* High-Speed Operation Enable */
67#define DCFM (1 << 6) /* Controller Function Select */
68#define DRPD (1 << 5) /* D+ Line/D- Line Resistance Control */
69#define DPRPU (1 << 4) /* D+ Line Resistance Control */
70#define USBE (1 << 0) /* USB Module Operation Enable */
71
72/* DVSTCTR */
73#define EXTLP (1 << 10) /* Controls the EXTLP pin output state */
74#define PWEN (1 << 9) /* Controls the PWEN pin output state */
75#define RHST (0x7) /* Reset Handshake */
76#define RHST_LOW_SPEED 1 /* Low-speed connection */
77#define RHST_FULL_SPEED 2 /* Full-speed connection */
78#define RHST_HIGH_SPEED 3 /* High-speed connection */
79
80/* CFIFOSEL */
81#define MBW_32 (0x2 << 10) /* CFIFO Port Access Bit Width */
82
83/* CFIFOCTR */
84#define BVAL (1 << 15) /* Buffer Memory Enable Flag */
85#define BCLR (1 << 14) /* CPU buffer clear */
86#define FRDY (1 << 13) /* FIFO Port Ready */
87#define DTLN_MASK (0x0FFF) /* Receive Data Length */
88
89/* INTENB0 */
90#define VBSE (1 << 15) /* Enable IRQ VBUS_0 and VBUSIN_0 */
91#define RSME (1 << 14) /* Enable IRQ Resume */
92#define SOFE (1 << 13) /* Enable IRQ Frame Number Update */
93#define DVSE (1 << 12) /* Enable IRQ Device State Transition */
94#define CTRE (1 << 11) /* Enable IRQ Control Stage Transition */
95#define BEMPE (1 << 10) /* Enable IRQ Buffer Empty */
96#define NRDYE (1 << 9) /* Enable IRQ Buffer Not Ready Response */
97#define BRDYE (1 << 8) /* Enable IRQ Buffer Ready */
98
99/* INTENB1 */
100#define BCHGE (1 << 14) /* USB Bus Change Interrupt Enable */
101#define DTCHE (1 << 12) /* Disconnection Detect Interrupt Enable */
102#define ATTCHE (1 << 11) /* Connection Detect Interrupt Enable */
103#define EOFERRE (1 << 6) /* EOF Error Detect Interrupt Enable */
104#define SIGNE (1 << 5) /* Setup Transaction Error Interrupt Enable */
105#define SACKE (1 << 4) /* Setup Transaction ACK Interrupt Enable */
106
107/* INTSTS0 */
108#define VBINT (1 << 15) /* VBUS0_0 and VBUS1_0 Interrupt Status */
109#define DVST (1 << 12) /* Device State Transition Interrupt Status */
110#define CTRT (1 << 11) /* Control Stage Interrupt Status */
111#define BEMP (1 << 10) /* Buffer Empty Interrupt Status */
112#define BRDY (1 << 8) /* Buffer Ready Interrupt Status */
113#define VBSTS (1 << 7) /* VBUS_0 and VBUSIN_0 Input Status */
114#define VALID (1 << 3) /* USB Request Receive */
115
116#define DVSQ_MASK (0x3 << 4) /* Device State */
117#define POWER_STATE (0 << 4)
118#define DEFAULT_STATE (1 << 4)
119#define ADDRESS_STATE (2 << 4)
120#define CONFIGURATION_STATE (3 << 4)
121
122#define CTSQ_MASK (0x7) /* Control Transfer Stage */
123#define IDLE_SETUP_STAGE 0 /* Idle stage or setup stage */
124#define READ_DATA_STAGE 1 /* Control read data stage */
125#define READ_STATUS_STAGE 2 /* Control read status stage */
126#define WRITE_DATA_STAGE 3 /* Control write data stage */
127#define WRITE_STATUS_STAGE 4 /* Control write status stage */
128#define NODATA_STATUS_STAGE 5 /* Control write NoData status stage */
129#define SEQUENCE_ERROR 6 /* Control transfer sequence error */
130
131/* PIPECFG */
132/* DCPCFG */
133#define TYPE_NONE (0 << 14) /* Transfer Type */
134#define TYPE_BULK (1 << 14)
135#define TYPE_INT (2 << 14)
136#define TYPE_ISO (3 << 14)
137#define DBLB (1 << 9) /* Double Buffer Mode */
138#define SHTNAK (1 << 7) /* Pipe Disable in Transfer End */
139#define DIR_OUT (1 << 4) /* Transfer Direction */
140
141/* PIPEMAXP */
142/* DCPMAXP */
143#define DEVSEL_MASK (0xF << 12) /* Device Select */
144#define DCP_MAXP_MASK (0x7F)
145#define PIPE_MAXP_MASK (0x7FF)
146
147/* PIPEBUF */
148#define BUFSIZE_SHIFT 10
149#define BUFSIZE_MASK (0x1F << BUFSIZE_SHIFT)
150#define BUFNMB_MASK (0xFF)
151
152/* PIPEnCTR */
153/* DCPCTR */
154#define BSTS (1 << 15) /* Buffer Status */
155#define CSSTS (1 << 12) /* CSSTS Status */
156#define SQCLR (1 << 8) /* Toggle Bit Clear */
157#define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */
158#define PBUSY (1 << 5) /* Pipe Busy */
159#define PID_MASK (0x3) /* Response PID */
160#define PID_NAK 0
161#define PID_BUF 1
162#define PID_STALL10 2
163#define PID_STALL11 3
164
165#define CCPL (1 << 2) /* Control Transfer End Enable */
166
167/* FRMNUM */
168#define FRNM_MASK (0x7FF)
169
170/*
171 * struct
172 */
173struct usbhs_priv {
174
175 void __iomem *base;
176 unsigned int irq;
177
178 struct renesas_usbhs_platform_callback *pfunc;
179 struct renesas_usbhs_driver_param *dparam;
180
181 struct delayed_work notify_hotplug_work;
182 struct platform_device *pdev;
183
184 spinlock_t lock;
185
186 u32 flags;
187
188 /*
189 * module control
190 */
191 struct usbhs_mod_info mod_info;
192
193 /*
194 * pipe control
195 */
196 struct usbhs_pipe_info pipe_info;
197};
198
199/*
200 * common
201 */
202u16 usbhs_read(struct usbhs_priv *priv, u32 reg);
203void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data);
204void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data);
205
206int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev);
207/*
208 * sysconfig
209 */
210void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable);
211void usbhs_sys_hispeed_ctrl(struct usbhs_priv *priv, int enable);
212void usbhs_sys_usb_ctrl(struct usbhs_priv *priv, int enable);
213void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable);
214void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable);
215
216/*
217 * frame
218 */
219int usbhs_frame_get_num(struct usbhs_priv *priv);
220
221/*
222 * data
223 */
224struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev);
225#define usbhs_get_dparam(priv, param) (priv->dparam->param)
226#define usbhs_priv_to_pdev(priv) (priv->pdev)
227#define usbhs_priv_to_dev(priv) (&priv->pdev->dev)
228#define usbhs_priv_to_lock(priv) (&priv->lock)
229
230#endif /* RENESAS_USB_DRIVER_H */
diff --git a/drivers/usb/renesas_usbhs/mod.c b/drivers/usb/renesas_usbhs/mod.c
new file mode 100644
index 000000000000..a577f8f4064c
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/mod.c
@@ -0,0 +1,328 @@
1/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#include <linux/interrupt.h>
18
19#include "./common.h"
20#include "./mod.h"
21
22#define usbhs_priv_to_modinfo(priv) (&priv->mod_info)
23#define usbhs_mod_info_call(priv, func, param...) \
24({ \
25 struct usbhs_mod_info *info; \
26 info = usbhs_priv_to_modinfo(priv); \
27 !info->func ? 0 : \
28 info->func(param); \
29})
30
31/*
32 * autonomy
33 *
34 * these functions are used if platform doesn't have external phy.
35 * -> there is no "notify_hotplug" callback from platform
36 * -> call "notify_hotplug" by itself
37 * -> use own interrupt to connect/disconnect
38 * -> it mean module clock is always ON
39 * ~~~~~~~~~~~~~~~~~~~~~~~~~
40 */
41static int usbhsm_autonomy_get_vbus(struct platform_device *pdev)
42{
43 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
44
45 return VBSTS & usbhs_read(priv, INTSTS0);
46}
47
48static int usbhsm_autonomy_irq_vbus(struct usbhs_priv *priv,
49 struct usbhs_irq_state *irq_state)
50{
51 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
52
53 return usbhsc_drvcllbck_notify_hotplug(pdev);
54}
55
56void usbhs_mod_autonomy_mode(struct usbhs_priv *priv)
57{
58 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
59
60 info->irq_vbus = usbhsm_autonomy_irq_vbus;
61 priv->pfunc->get_vbus = usbhsm_autonomy_get_vbus;
62
63 usbhs_irq_callback_update(priv, NULL);
64}
65
66/*
67 * host / gadget functions
68 *
69 * renesas_usbhs host/gadget can register itself by below functions.
70 * these functions are called when probe
71 *
72 */
73void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *mod, int id)
74{
75 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
76
77 info->mod[id] = mod;
78 mod->priv = priv;
79}
80
81struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id)
82{
83 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
84 struct usbhs_mod *ret = NULL;
85
86 switch (id) {
87 case USBHS_HOST:
88 case USBHS_GADGET:
89 ret = info->mod[id];
90 break;
91 }
92
93 return ret;
94}
95
96int usbhs_mod_is_host(struct usbhs_priv *priv, struct usbhs_mod *mod)
97{
98 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
99
100 if (!mod)
101 return -EINVAL;
102
103 return info->mod[USBHS_HOST] == mod;
104}
105
106struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv)
107{
108 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
109
110 return info->curt;
111}
112
113int usbhs_mod_change(struct usbhs_priv *priv, int id)
114{
115 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
116 struct usbhs_mod *mod = NULL;
117 int ret = 0;
118
119 /* id < 0 mean no current */
120 switch (id) {
121 case USBHS_HOST:
122 case USBHS_GADGET:
123 mod = info->mod[id];
124 break;
125 default:
126 ret = -EINVAL;
127 }
128 info->curt = mod;
129
130 return ret;
131}
132
133static irqreturn_t usbhs_interrupt(int irq, void *data);
134int usbhs_mod_probe(struct usbhs_priv *priv)
135{
136 struct device *dev = usbhs_priv_to_dev(priv);
137 int ret;
138
139 /*
140 * install host/gadget driver
141 */
142 ret = usbhs_mod_gadget_probe(priv);
143 if (ret < 0)
144 return ret;
145
146 /* irq settings */
147 ret = request_irq(priv->irq, usbhs_interrupt,
148 IRQF_DISABLED, dev_name(dev), priv);
149 if (ret) {
150 dev_err(dev, "irq request err\n");
151 goto mod_init_gadget_err;
152 }
153
154 return ret;
155
156mod_init_gadget_err:
157 usbhs_mod_gadget_remove(priv);
158
159 return ret;
160}
161
162void usbhs_mod_remove(struct usbhs_priv *priv)
163{
164 usbhs_mod_gadget_remove(priv);
165 free_irq(priv->irq, priv);
166}
167
168/*
169 * status functions
170 */
171int usbhs_status_get_usb_speed(struct usbhs_irq_state *irq_state)
172{
173 switch (irq_state->dvstctr & RHST) {
174 case RHST_LOW_SPEED:
175 return USB_SPEED_LOW;
176 case RHST_FULL_SPEED:
177 return USB_SPEED_FULL;
178 case RHST_HIGH_SPEED:
179 return USB_SPEED_HIGH;
180 }
181
182 return USB_SPEED_UNKNOWN;
183}
184
185int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state)
186{
187 int state = irq_state->intsts0 & DVSQ_MASK;
188
189 switch (state) {
190 case POWER_STATE:
191 case DEFAULT_STATE:
192 case ADDRESS_STATE:
193 case CONFIGURATION_STATE:
194 return state;
195 }
196
197 return -EIO;
198}
199
200int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state)
201{
202 /*
203 * return value
204 *
205 * IDLE_SETUP_STAGE
206 * READ_DATA_STAGE
207 * READ_STATUS_STAGE
208 * WRITE_DATA_STAGE
209 * WRITE_STATUS_STAGE
210 * NODATA_STATUS_STAGE
211 * SEQUENCE_ERROR
212 */
213 return (int)irq_state->intsts0 & CTSQ_MASK;
214}
215
216static void usbhs_status_get_each_irq(struct usbhs_priv *priv,
217 struct usbhs_irq_state *state)
218{
219 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
220
221 state->intsts0 = usbhs_read(priv, INTSTS0);
222 state->intsts1 = usbhs_read(priv, INTSTS1);
223
224 state->dvstctr = usbhs_read(priv, DVSTCTR);
225
226 /* mask */
227 if (mod) {
228 state->brdysts = usbhs_read(priv, BRDYSTS);
229 state->nrdysts = usbhs_read(priv, NRDYSTS);
230 state->bempsts = usbhs_read(priv, BEMPSTS);
231
232 state->bempsts &= mod->irq_bempsts;
233 state->brdysts &= mod->irq_brdysts;
234 }
235}
236
237/*
238 * interrupt
239 */
240#define INTSTS0_MAGIC 0xF800 /* acknowledge magical interrupt sources */
241#define INTSTS1_MAGIC 0xA870 /* acknowledge magical interrupt sources */
242static irqreturn_t usbhs_interrupt(int irq, void *data)
243{
244 struct usbhs_priv *priv = data;
245 struct usbhs_irq_state irq_state;
246
247 usbhs_status_get_each_irq(priv, &irq_state);
248
249 /*
250 * clear interrupt
251 *
252 * The hardware is _very_ picky to clear interrupt bit.
253 * Especially INTSTS0_MAGIC, INTSTS1_MAGIC value.
254 *
255 * see
256 * "Operation"
257 * - "Control Transfer (DCP)"
258 * - Function :: VALID bit should 0
259 */
260 usbhs_write(priv, INTSTS0, ~irq_state.intsts0 & INTSTS0_MAGIC);
261 usbhs_write(priv, INTSTS1, ~irq_state.intsts1 & INTSTS1_MAGIC);
262
263 usbhs_write(priv, BRDYSTS, 0);
264 usbhs_write(priv, NRDYSTS, 0);
265 usbhs_write(priv, BEMPSTS, 0);
266
267 /*
268 * call irq callback functions
269 * see also
270 * usbhs_irq_setting_update
271 */
272 if (irq_state.intsts0 & VBINT)
273 usbhs_mod_info_call(priv, irq_vbus, priv, &irq_state);
274
275 if (irq_state.intsts0 & DVST)
276 usbhs_mod_call(priv, irq_dev_state, priv, &irq_state);
277
278 if (irq_state.intsts0 & CTRT)
279 usbhs_mod_call(priv, irq_ctrl_stage, priv, &irq_state);
280
281 if (irq_state.intsts0 & BEMP)
282 usbhs_mod_call(priv, irq_empty, priv, &irq_state);
283
284 if (irq_state.intsts0 & BRDY)
285 usbhs_mod_call(priv, irq_ready, priv, &irq_state);
286
287 return IRQ_HANDLED;
288}
289
290void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod)
291{
292 u16 intenb0 = 0;
293 struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv);
294
295 usbhs_write(priv, INTENB0, 0);
296
297 usbhs_write(priv, BEMPENB, 0);
298 usbhs_write(priv, BRDYENB, 0);
299
300 /*
301 * see also
302 * usbhs_interrupt
303 */
304
305 /*
306 * it don't enable DVSE (intenb0) here
307 * but "mod->irq_dev_state" will be called.
308 */
309 if (info->irq_vbus)
310 intenb0 |= VBSE;
311
312 if (mod) {
313 if (mod->irq_ctrl_stage)
314 intenb0 |= CTRE;
315
316 if (mod->irq_empty && mod->irq_bempsts) {
317 usbhs_write(priv, BEMPENB, mod->irq_bempsts);
318 intenb0 |= BEMPE;
319 }
320
321 if (mod->irq_ready && mod->irq_brdysts) {
322 usbhs_write(priv, BRDYENB, mod->irq_brdysts);
323 intenb0 |= BRDYE;
324 }
325 }
326
327 usbhs_write(priv, INTENB0, intenb0);
328}
diff --git a/drivers/usb/renesas_usbhs/mod.h b/drivers/usb/renesas_usbhs/mod.h
new file mode 100644
index 000000000000..5c845a28a21c
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/mod.h
@@ -0,0 +1,137 @@
1/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#ifndef RENESAS_USB_MOD_H
18#define RENESAS_USB_MOD_H
19
20#include <linux/spinlock.h>
21#include <linux/usb/renesas_usbhs.h>
22#include "./common.h"
23
24/*
25 * struct
26 */
27struct usbhs_irq_state {
28 u16 intsts0;
29 u16 intsts1;
30 u16 brdysts;
31 u16 nrdysts;
32 u16 bempsts;
33 u16 dvstctr;
34};
35
36struct usbhs_mod {
37 char *name;
38
39 /*
40 * entry point from common.c
41 */
42 int (*start)(struct usbhs_priv *priv);
43 int (*stop)(struct usbhs_priv *priv);
44
45 /* INTSTS0 :: DVST (DVSQ) */
46 int (*irq_dev_state)(struct usbhs_priv *priv,
47 struct usbhs_irq_state *irq_state);
48
49 /* INTSTS0 :: CTRT (CTSQ) */
50 int (*irq_ctrl_stage)(struct usbhs_priv *priv,
51 struct usbhs_irq_state *irq_state);
52
53 /* INTSTS0 :: BEMP */
54 /* BEMPSTS */
55 int (*irq_empty)(struct usbhs_priv *priv,
56 struct usbhs_irq_state *irq_state);
57 u16 irq_bempsts;
58
59 /* INTSTS0 :: BRDY */
60 /* BRDYSTS */
61 int (*irq_ready)(struct usbhs_priv *priv,
62 struct usbhs_irq_state *irq_state);
63 u16 irq_brdysts;
64
65 struct usbhs_priv *priv;
66};
67
68struct usbhs_mod_info {
69 struct usbhs_mod *mod[USBHS_MAX];
70 struct usbhs_mod *curt; /* current mod */
71
72 /*
73 * INTSTS0 :: VBINT
74 *
75 * This function will be used as autonomy mode
76 * when platform cannot call notify_hotplug.
77 *
78 * This callback cannot be member of "struct usbhs_mod"
79 * because it will be used even though
80 * host/gadget has not been selected.
81 */
82 int (*irq_vbus)(struct usbhs_priv *priv,
83 struct usbhs_irq_state *irq_state);
84};
85
86/*
87 * for host/gadget module
88 */
89struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
90struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
91void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
92int usbhs_mod_is_host(struct usbhs_priv *priv, struct usbhs_mod *mod);
93int usbhs_mod_change(struct usbhs_priv *priv, int id);
94int usbhs_mod_probe(struct usbhs_priv *priv);
95void usbhs_mod_remove(struct usbhs_priv *priv);
96
97void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
98
99/*
100 * status functions
101 */
102int usbhs_status_get_usb_speed(struct usbhs_irq_state *irq_state);
103int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
104int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
105
106/*
107 * callback functions
108 */
109void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
110
111
112#define usbhs_mod_call(priv, func, param...) \
113 ({ \
114 struct usbhs_mod *mod; \
115 mod = usbhs_mod_get_current(priv); \
116 !mod ? -ENODEV : \
117 !mod->func ? 0 : \
118 mod->func(param); \
119 })
120
121/*
122 * gadget control
123 */
124#ifdef CONFIG_USB_RENESAS_USBHS_UDC
125extern int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv);
126extern void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv);
127#else
128static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
129{
130 return 0;
131}
132static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
133{
134}
135#endif
136
137#endif /* RENESAS_USB_MOD_H */
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
new file mode 100644
index 000000000000..547486ccd059
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -0,0 +1,1385 @@
1/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/usb/ch9.h>
21#include <linux/usb/gadget.h>
22#include "common.h"
23
24/*
25 * struct
26 */
27struct usbhsg_request {
28 struct usb_request req;
29 struct list_head node;
30};
31
32#define EP_NAME_SIZE 8
33struct usbhsg_gpriv;
34struct usbhsg_pipe_handle;
35struct usbhsg_uep {
36 struct usb_ep ep;
37 struct usbhs_pipe *pipe;
38 struct list_head list;
39
40 char ep_name[EP_NAME_SIZE];
41
42 struct usbhsg_gpriv *gpriv;
43 struct usbhsg_pipe_handle *handler;
44};
45
46struct usbhsg_gpriv {
47 struct usb_gadget gadget;
48 struct usbhs_mod mod;
49
50 struct usbhsg_uep *uep;
51 int uep_size;
52
53 struct usb_gadget_driver *driver;
54
55 u32 status;
56#define USBHSG_STATUS_STARTED (1 << 0)
57#define USBHSG_STATUS_REGISTERD (1 << 1)
58#define USBHSG_STATUS_WEDGE (1 << 2)
59};
60
61struct usbhsg_pipe_handle {
62 int (*prepare)(struct usbhsg_uep *uep, struct usbhsg_request *ureq);
63 int (*try_run)(struct usbhsg_uep *uep, struct usbhsg_request *ureq);
64 void (*irq_mask)(struct usbhsg_uep *uep, int enable);
65};
66
67struct usbhsg_recip_handle {
68 char *name;
69 int (*device)(struct usbhs_priv *priv, struct usbhsg_uep *uep,
70 struct usb_ctrlrequest *ctrl);
71 int (*interface)(struct usbhs_priv *priv, struct usbhsg_uep *uep,
72 struct usb_ctrlrequest *ctrl);
73 int (*endpoint)(struct usbhs_priv *priv, struct usbhsg_uep *uep,
74 struct usb_ctrlrequest *ctrl);
75};
76
77/*
78 * macro
79 */
80#define usbhsg_priv_to_gpriv(priv) \
81 container_of( \
82 usbhs_mod_get(priv, USBHS_GADGET), \
83 struct usbhsg_gpriv, mod)
84
85#define __usbhsg_for_each_uep(start, pos, g, i) \
86 for (i = start, pos = (g)->uep; \
87 i < (g)->uep_size; \
88 i++, pos = (g)->uep + i)
89
90#define usbhsg_for_each_uep(pos, gpriv, i) \
91 __usbhsg_for_each_uep(1, pos, gpriv, i)
92
93#define usbhsg_for_each_uep_with_dcp(pos, gpriv, i) \
94 __usbhsg_for_each_uep(0, pos, gpriv, i)
95
96#define usbhsg_gadget_to_gpriv(g)\
97 container_of(g, struct usbhsg_gpriv, gadget)
98
99#define usbhsg_req_to_ureq(r)\
100 container_of(r, struct usbhsg_request, req)
101
102#define usbhsg_ep_to_uep(e) container_of(e, struct usbhsg_uep, ep)
103#define usbhsg_gpriv_to_lock(gp) usbhs_priv_to_lock((gp)->mod.priv)
104#define usbhsg_gpriv_to_dev(gp) usbhs_priv_to_dev((gp)->mod.priv)
105#define usbhsg_gpriv_to_priv(gp) ((gp)->mod.priv)
106#define usbhsg_gpriv_to_dcp(gp) ((gp)->uep)
107#define usbhsg_gpriv_to_nth_uep(gp, i) ((gp)->uep + i)
108#define usbhsg_uep_to_gpriv(u) ((u)->gpriv)
109#define usbhsg_uep_to_pipe(u) ((u)->pipe)
110#define usbhsg_pipe_to_uep(p) ((p)->mod_private)
111#define usbhsg_is_dcp(u) ((u) == usbhsg_gpriv_to_dcp((u)->gpriv))
112
113#define usbhsg_is_not_connected(gp) ((gp)->gadget.speed == USB_SPEED_UNKNOWN)
114
115/* status */
116#define usbhsg_status_init(gp) do {(gp)->status = 0; } while (0)
117#define usbhsg_status_set(gp, b) (gp->status |= b)
118#define usbhsg_status_clr(gp, b) (gp->status &= ~b)
119#define usbhsg_status_has(gp, b) (gp->status & b)
120
121/*
122 * usbhsg_trylock
123 *
124 * This driver don't use spin_try_lock
125 * to avoid warning of CONFIG_DEBUG_SPINLOCK
126 */
127static spinlock_t *usbhsg_trylock(struct usbhsg_gpriv *gpriv,
128 unsigned long *flags)
129{
130 spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
131
132 /* check spin lock status
133 * to avoid deadlock/nest */
134 if (spin_is_locked(lock))
135 return NULL;
136
137 spin_lock_irqsave(lock, *flags);
138
139 return lock;
140}
141
142static void usbhsg_unlock(spinlock_t *lock, unsigned long *flags)
143{
144 if (!lock)
145 return;
146
147 spin_unlock_irqrestore(lock, *flags);
148}
149
150/*
151 * list push/pop
152 */
153static void usbhsg_queue_push(struct usbhsg_uep *uep,
154 struct usbhsg_request *ureq)
155{
156 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
157 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
158 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
159
160 /*
161 ********* assume under spin lock *********
162 */
163 list_del_init(&ureq->node);
164 list_add_tail(&ureq->node, &uep->list);
165 ureq->req.actual = 0;
166 ureq->req.status = -EINPROGRESS;
167
168 dev_dbg(dev, "pipe %d : queue push (%d)\n",
169 usbhs_pipe_number(pipe),
170 ureq->req.length);
171}
172
173static struct usbhsg_request *usbhsg_queue_get(struct usbhsg_uep *uep)
174{
175 /*
176 ********* assume under spin lock *********
177 */
178 if (list_empty(&uep->list))
179 return NULL;
180
181 return list_entry(uep->list.next, struct usbhsg_request, node);
182}
183
184#define usbhsg_queue_prepare(uep) __usbhsg_queue_handler(uep, 1);
185#define usbhsg_queue_handle(uep) __usbhsg_queue_handler(uep, 0);
186static int __usbhsg_queue_handler(struct usbhsg_uep *uep, int prepare)
187{
188 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
189 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
190 struct usbhsg_request *ureq;
191 spinlock_t *lock;
192 unsigned long flags;
193 int ret = 0;
194
195 if (!uep->handler) {
196 dev_err(dev, "no handler function\n");
197 return -EIO;
198 }
199
200 /*
201 * CAUTION [*queue handler*]
202 *
203 * This function will be called for start/restart queue operation.
204 * OTOH the most much worry for USB driver is spinlock nest.
205 * Specially it are
206 * - usb_ep_ops :: queue
207 * - usb_request :: complete
208 *
209 * But the caller of this function need not care about spinlock.
210 * This function is using usbhsg_trylock for it.
211 * if "is_locked" is 1, this mean this function lock it.
212 * but if it is 0, this mean it is already under spin lock.
213 * see also
214 * CAUTION [*endpoint queue*]
215 * CAUTION [*request complete*]
216 */
217
218 /****************** spin try lock *******************/
219 lock = usbhsg_trylock(gpriv, &flags);
220
221 ureq = usbhsg_queue_get(uep);
222 if (ureq) {
223 if (prepare)
224 ret = uep->handler->prepare(uep, ureq);
225 else
226 ret = uep->handler->try_run(uep, ureq);
227 }
228 usbhsg_unlock(lock, &flags);
229 /******************** spin unlock ******************/
230
231 return ret;
232}
233
234static void usbhsg_queue_pop(struct usbhsg_uep *uep,
235 struct usbhsg_request *ureq,
236 int status)
237{
238 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
239 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
240 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
241
242 /*
243 ********* assume under spin lock *********
244 */
245
246 /*
247 * CAUTION [*request complete*]
248 *
249 * There is a possibility not to be called in correct order
250 * if "complete" is called without spinlock.
251 *
252 * So, this function assume it is under spinlock,
253 * and call usb_request :: complete.
254 *
255 * But this "complete" will push next usb_request.
256 * It mean "usb_ep_ops :: queue" which is using spinlock is called
257 * under spinlock.
258 *
259 * To avoid dead-lock, this driver is using usbhsg_trylock.
260 * CAUTION [*endpoint queue*]
261 * CAUTION [*queue handler*]
262 */
263
264 dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe));
265
266 list_del_init(&ureq->node);
267
268 ureq->req.status = status;
269 ureq->req.complete(&uep->ep, &ureq->req);
270
271 /* more request ? */
272 if (0 == status)
273 usbhsg_queue_prepare(uep);
274}
275
276/*
277 * irq enable/disable function
278 */
279#define usbhsg_irq_callback_ctrl(uep, status, enable) \
280 ({ \
281 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); \
282 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); \
283 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); \
284 struct usbhs_mod *mod = usbhs_mod_get_current(priv); \
285 if (!mod) \
286 return; \
287 if (enable) \
288 mod->irq_##status |= (1 << usbhs_pipe_number(pipe)); \
289 else \
290 mod->irq_##status &= ~(1 << usbhs_pipe_number(pipe)); \
291 usbhs_irq_callback_update(priv, mod); \
292 })
293
294static void usbhsg_irq_empty_ctrl(struct usbhsg_uep *uep, int enable)
295{
296 usbhsg_irq_callback_ctrl(uep, bempsts, enable);
297}
298
299static void usbhsg_irq_ready_ctrl(struct usbhsg_uep *uep, int enable)
300{
301 usbhsg_irq_callback_ctrl(uep, brdysts, enable);
302}
303
304/*
305 * handler function
306 */
307static int usbhsg_try_run_ctrl_stage_end(struct usbhsg_uep *uep,
308 struct usbhsg_request *ureq)
309{
310 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
311
312 /*
313 ********* assume under spin lock *********
314 */
315
316 usbhs_dcp_control_transfer_done(pipe);
317 usbhsg_queue_pop(uep, ureq, 0);
318
319 return 0;
320}
321
322static int usbhsg_try_run_send_packet(struct usbhsg_uep *uep,
323 struct usbhsg_request *ureq)
324{
325 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
326 struct usb_request *req = &ureq->req;
327 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
328 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
329 void *buf;
330 int remainder, send;
331 int is_done = 0;
332 int enable;
333 int maxp;
334
335 /*
336 ********* assume under spin lock *********
337 */
338
339 maxp = usbhs_pipe_get_maxpacket(pipe);
340 buf = req->buf + req->actual;
341 remainder = req->length - req->actual;
342
343 send = usbhs_fifo_write(pipe, buf, remainder);
344
345 /*
346 * send < 0 : pipe busy
347 * send = 0 : send zero packet
348 * send > 0 : send data
349 *
350 * send <= max_packet
351 */
352 if (send > 0)
353 req->actual += send;
354
355 /* send all packet ? */
356 if (send < remainder)
357 is_done = 0; /* there are remainder data */
358 else if (send < maxp)
359 is_done = 1; /* short packet */
360 else
361 is_done = !req->zero; /* send zero packet ? */
362
363 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
364 usbhs_pipe_number(pipe),
365 remainder, send, is_done, req->zero);
366
367 /*
368 * enable interrupt and send again in irq handler
369 * if it still have remainder data which should be sent.
370 */
371 enable = !is_done;
372 uep->handler->irq_mask(uep, enable);
373
374 /*
375 * usbhs_fifo_enable execute
376 * - after callback_update,
377 * - before queue_pop / stage_end
378 */
379 usbhs_fifo_enable(pipe);
380
381 /*
382 * all data were sent ?
383 */
384 if (is_done) {
385 /* it care below call in
386 "function mode" */
387 if (usbhsg_is_dcp(uep))
388 usbhs_dcp_control_transfer_done(pipe);
389
390 usbhsg_queue_pop(uep, ureq, 0);
391 }
392
393 return 0;
394}
395
396static int usbhsg_prepare_send_packet(struct usbhsg_uep *uep,
397 struct usbhsg_request *ureq)
398{
399 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
400
401 /*
402 ********* assume under spin lock *********
403 */
404
405 usbhs_fifo_prepare_write(pipe);
406 usbhsg_try_run_send_packet(uep, ureq);
407
408 return 0;
409}
410
411static int usbhsg_try_run_receive_packet(struct usbhsg_uep *uep,
412 struct usbhsg_request *ureq)
413{
414 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
415 struct usb_request *req = &ureq->req;
416 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
417 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
418 void *buf;
419 int maxp;
420 int remainder, recv;
421 int is_done = 0;
422
423 /*
424 ********* assume under spin lock *********
425 */
426
427 maxp = usbhs_pipe_get_maxpacket(pipe);
428 buf = req->buf + req->actual;
429 remainder = req->length - req->actual;
430
431 recv = usbhs_fifo_read(pipe, buf, remainder);
432 /*
433 * recv < 0 : pipe busy
434 * recv >= 0 : receive data
435 *
436 * recv <= max_packet
437 */
438 if (recv < 0)
439 return -EBUSY;
440
441 /* update parameters */
442 req->actual += recv;
443
444 if ((recv == remainder) || /* receive all data */
445 (recv < maxp)) /* short packet */
446 is_done = 1;
447
448 dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
449 usbhs_pipe_number(pipe),
450 remainder, recv, is_done, req->zero);
451
452 /* read all data ? */
453 if (is_done) {
454 int disable = 0;
455
456 uep->handler->irq_mask(uep, disable);
457 usbhs_fifo_disable(pipe);
458 usbhsg_queue_pop(uep, ureq, 0);
459 }
460
461 return 0;
462}
463
464static int usbhsg_prepare_receive_packet(struct usbhsg_uep *uep,
465 struct usbhsg_request *ureq)
466{
467 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
468 int enable = 1;
469 int ret;
470
471 /*
472 ********* assume under spin lock *********
473 */
474
475 ret = usbhs_fifo_prepare_read(pipe);
476 if (ret < 0)
477 return ret;
478
479 /*
480 * data will be read in interrupt handler
481 */
482 uep->handler->irq_mask(uep, enable);
483
484 return ret;
485}
486
487static struct usbhsg_pipe_handle usbhsg_handler_send_by_empty = {
488 .prepare = usbhsg_prepare_send_packet,
489 .try_run = usbhsg_try_run_send_packet,
490 .irq_mask = usbhsg_irq_empty_ctrl,
491};
492
493static struct usbhsg_pipe_handle usbhsg_handler_send_by_ready = {
494 .prepare = usbhsg_prepare_send_packet,
495 .try_run = usbhsg_try_run_send_packet,
496 .irq_mask = usbhsg_irq_ready_ctrl,
497};
498
499static struct usbhsg_pipe_handle usbhsg_handler_recv_by_ready = {
500 .prepare = usbhsg_prepare_receive_packet,
501 .try_run = usbhsg_try_run_receive_packet,
502 .irq_mask = usbhsg_irq_ready_ctrl,
503};
504
505static struct usbhsg_pipe_handle usbhsg_handler_ctrl_stage_end = {
506 .prepare = usbhsg_try_run_ctrl_stage_end,
507 .try_run = usbhsg_try_run_ctrl_stage_end,
508};
509
510/*
511 * DCP pipe can NOT use "ready interrupt" for "send"
512 * it should use "empty" interrupt.
513 * see
514 * "Operation" - "Interrupt Function" - "BRDY Interrupt"
515 *
516 * on the other hand, normal pipe can use "ready interrupt" for "send"
517 * even though it is single/double buffer
518 */
519#define usbhsg_handler_send_ctrl usbhsg_handler_send_by_empty
520#define usbhsg_handler_recv_ctrl usbhsg_handler_recv_by_ready
521
522#define usbhsg_handler_send_packet usbhsg_handler_send_by_ready
523#define usbhsg_handler_recv_packet usbhsg_handler_recv_by_ready
524
525/*
526 * USB_TYPE_STANDARD / clear feature functions
527 */
528static int usbhsg_recip_handler_std_control_done(struct usbhs_priv *priv,
529 struct usbhsg_uep *uep,
530 struct usb_ctrlrequest *ctrl)
531{
532 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
533 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
534 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(dcp);
535
536 usbhs_dcp_control_transfer_done(pipe);
537
538 return 0;
539}
540
541static int usbhsg_recip_handler_std_clear_endpoint(struct usbhs_priv *priv,
542 struct usbhsg_uep *uep,
543 struct usb_ctrlrequest *ctrl)
544{
545 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
546 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
547
548 if (!usbhsg_status_has(gpriv, USBHSG_STATUS_WEDGE)) {
549 usbhs_fifo_disable(pipe);
550 usbhs_pipe_clear_sequence(pipe);
551 usbhs_fifo_enable(pipe);
552 }
553
554 usbhsg_recip_handler_std_control_done(priv, uep, ctrl);
555
556 usbhsg_queue_prepare(uep);
557
558 return 0;
559}
560
561struct usbhsg_recip_handle req_clear_feature = {
562 .name = "clear feature",
563 .device = usbhsg_recip_handler_std_control_done,
564 .interface = usbhsg_recip_handler_std_control_done,
565 .endpoint = usbhsg_recip_handler_std_clear_endpoint,
566};
567
568/*
569 * USB_TYPE handler
570 */
571static int usbhsg_recip_run_handle(struct usbhs_priv *priv,
572 struct usbhsg_recip_handle *handler,
573 struct usb_ctrlrequest *ctrl)
574{
575 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
576 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
577 struct usbhsg_uep *uep;
578 int recip = ctrl->bRequestType & USB_RECIP_MASK;
579 int nth = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK;
580 int ret;
581 int (*func)(struct usbhs_priv *priv, struct usbhsg_uep *uep,
582 struct usb_ctrlrequest *ctrl);
583 char *msg;
584
585 uep = usbhsg_gpriv_to_nth_uep(gpriv, nth);
586 if (!usbhsg_uep_to_pipe(uep)) {
587 dev_err(dev, "wrong recip request\n");
588 return -EINVAL;
589 }
590
591 switch (recip) {
592 case USB_RECIP_DEVICE:
593 msg = "DEVICE";
594 func = handler->device;
595 break;
596 case USB_RECIP_INTERFACE:
597 msg = "INTERFACE";
598 func = handler->interface;
599 break;
600 case USB_RECIP_ENDPOINT:
601 msg = "ENDPOINT";
602 func = handler->endpoint;
603 break;
604 default:
605 dev_warn(dev, "unsupported RECIP(%d)\n", recip);
606 func = NULL;
607 ret = -EINVAL;
608 }
609
610 if (func) {
611 dev_dbg(dev, "%s (pipe %d :%s)\n", handler->name, nth, msg);
612 ret = func(priv, uep, ctrl);
613 }
614
615 return ret;
616}
617
618/*
619 * irq functions
620 *
621 * it will be called from usbhs_interrupt
622 */
623static int usbhsg_irq_dev_state(struct usbhs_priv *priv,
624 struct usbhs_irq_state *irq_state)
625{
626 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
627 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
628
629 gpriv->gadget.speed = usbhs_status_get_usb_speed(irq_state);
630
631 dev_dbg(dev, "state = %x : speed : %d\n",
632 usbhs_status_get_device_state(irq_state),
633 gpriv->gadget.speed);
634
635 return 0;
636}
637
638static int usbhsg_irq_ctrl_stage(struct usbhs_priv *priv,
639 struct usbhs_irq_state *irq_state)
640{
641 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
642 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
643 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(dcp);
644 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
645 struct usb_ctrlrequest ctrl;
646 struct usbhsg_recip_handle *recip_handler = NULL;
647 int stage = usbhs_status_get_ctrl_stage(irq_state);
648 int ret = 0;
649
650 dev_dbg(dev, "stage = %d\n", stage);
651
652 /*
653 * see Manual
654 *
655 * "Operation"
656 * - "Interrupt Function"
657 * - "Control Transfer Stage Transition Interrupt"
658 * - Fig. "Control Transfer Stage Transitions"
659 */
660
661 switch (stage) {
662 case READ_DATA_STAGE:
663 dcp->handler = &usbhsg_handler_send_ctrl;
664 break;
665 case WRITE_DATA_STAGE:
666 dcp->handler = &usbhsg_handler_recv_ctrl;
667 break;
668 case NODATA_STATUS_STAGE:
669 dcp->handler = &usbhsg_handler_ctrl_stage_end;
670 break;
671 default:
672 return ret;
673 }
674
675 /*
676 * get usb request
677 */
678 usbhs_usbreq_get_val(priv, &ctrl);
679
680 switch (ctrl.bRequestType & USB_TYPE_MASK) {
681 case USB_TYPE_STANDARD:
682 switch (ctrl.bRequest) {
683 case USB_REQ_CLEAR_FEATURE:
684 recip_handler = &req_clear_feature;
685 break;
686 }
687 }
688
689 /*
690 * setup stage / run recip
691 */
692 if (recip_handler)
693 ret = usbhsg_recip_run_handle(priv, recip_handler, &ctrl);
694 else
695 ret = gpriv->driver->setup(&gpriv->gadget, &ctrl);
696
697 if (ret < 0)
698 usbhs_fifo_stall(pipe);
699
700 return ret;
701}
702
703static int usbhsg_irq_empty(struct usbhs_priv *priv,
704 struct usbhs_irq_state *irq_state)
705{
706 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
707 struct usbhsg_uep *uep;
708 struct usbhs_pipe *pipe;
709 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
710 int i, ret;
711
712 if (!irq_state->bempsts) {
713 dev_err(dev, "debug %s !!\n", __func__);
714 return -EIO;
715 }
716
717 dev_dbg(dev, "irq empty [0x%04x]\n", irq_state->bempsts);
718
719 /*
720 * search interrupted "pipe"
721 * not "uep".
722 */
723 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
724 if (!(irq_state->bempsts & (1 << i)))
725 continue;
726
727 uep = usbhsg_pipe_to_uep(pipe);
728 ret = usbhsg_queue_handle(uep);
729 if (ret < 0)
730 dev_err(dev, "send error %d : %d\n", i, ret);
731 }
732
733 return 0;
734}
735
736static int usbhsg_irq_ready(struct usbhs_priv *priv,
737 struct usbhs_irq_state *irq_state)
738{
739 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
740 struct usbhsg_uep *uep;
741 struct usbhs_pipe *pipe;
742 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
743 int i, ret;
744
745 if (!irq_state->brdysts) {
746 dev_err(dev, "debug %s !!\n", __func__);
747 return -EIO;
748 }
749
750 dev_dbg(dev, "irq ready [0x%04x]\n", irq_state->brdysts);
751
752 /*
753 * search interrupted "pipe"
754 * not "uep".
755 */
756 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
757 if (!(irq_state->brdysts & (1 << i)))
758 continue;
759
760 uep = usbhsg_pipe_to_uep(pipe);
761 ret = usbhsg_queue_handle(uep);
762 if (ret < 0)
763 dev_err(dev, "receive error %d : %d\n", i, ret);
764 }
765
766 return 0;
767}
768
769/*
770 *
771 * usb_dcp_ops
772 *
773 */
774static int usbhsg_dcp_enable(struct usbhsg_uep *uep)
775{
776 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
777 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
778 struct usbhs_pipe *pipe;
779
780 /*
781 ********* assume under spin lock *********
782 */
783
784 pipe = usbhs_dcp_malloc(priv);
785 if (!pipe)
786 return -EIO;
787
788 uep->pipe = pipe;
789 uep->pipe->mod_private = uep;
790 INIT_LIST_HEAD(&uep->list);
791
792 return 0;
793}
794
795#define usbhsg_dcp_disable usbhsg_pipe_disable
796static int usbhsg_pipe_disable(struct usbhsg_uep *uep)
797{
798 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
799 struct usbhsg_request *ureq;
800 int disable = 0;
801
802 /*
803 ********* assume under spin lock *********
804 */
805
806 usbhs_fifo_disable(pipe);
807
808 /*
809 * disable pipe irq
810 */
811 usbhsg_irq_empty_ctrl(uep, disable);
812 usbhsg_irq_ready_ctrl(uep, disable);
813
814 while (1) {
815 ureq = usbhsg_queue_get(uep);
816 if (!ureq)
817 break;
818
819 usbhsg_queue_pop(uep, ureq, -ECONNRESET);
820 }
821
822 return 0;
823}
824
825static void usbhsg_uep_init(struct usbhsg_gpriv *gpriv)
826{
827 int i;
828 struct usbhsg_uep *uep;
829
830 usbhsg_for_each_uep_with_dcp(uep, gpriv, i)
831 uep->pipe = NULL;
832}
833
834/*
835 *
836 * usb_ep_ops
837 *
838 */
839static int usbhsg_ep_enable(struct usb_ep *ep,
840 const struct usb_endpoint_descriptor *desc)
841{
842 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
843 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
844 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
845 struct usbhs_pipe *pipe;
846 spinlock_t *lock;
847 unsigned long flags;
848 int ret = -EIO;
849
850 /*
851 * if it already have pipe,
852 * nothing to do
853 */
854 if (uep->pipe)
855 return 0;
856
857 /******************** spin lock ********************/
858 lock = usbhsg_trylock(gpriv, &flags);
859
860 pipe = usbhs_pipe_malloc(priv, desc);
861 if (pipe) {
862 uep->pipe = pipe;
863 pipe->mod_private = uep;
864 INIT_LIST_HEAD(&uep->list);
865
866 if (usb_endpoint_dir_in(desc))
867 uep->handler = &usbhsg_handler_send_packet;
868 else
869 uep->handler = &usbhsg_handler_recv_packet;
870
871 ret = 0;
872 }
873
874 usbhsg_unlock(lock, &flags);
875 /******************** spin unlock ******************/
876
877 return ret;
878}
879
880static int usbhsg_ep_disable(struct usb_ep *ep)
881{
882 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
883 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
884 spinlock_t *lock;
885 unsigned long flags;
886 int ret;
887
888 /******************** spin lock ********************/
889 lock = usbhsg_trylock(gpriv, &flags);
890
891 ret = usbhsg_pipe_disable(uep);
892
893 usbhsg_unlock(lock, &flags);
894 /******************** spin unlock ******************/
895
896 return ret;
897}
898
899static struct usb_request *usbhsg_ep_alloc_request(struct usb_ep *ep,
900 gfp_t gfp_flags)
901{
902 struct usbhsg_request *ureq;
903
904 ureq = kzalloc(sizeof *ureq, gfp_flags);
905 if (!ureq)
906 return NULL;
907
908 INIT_LIST_HEAD(&ureq->node);
909 return &ureq->req;
910}
911
912static void usbhsg_ep_free_request(struct usb_ep *ep,
913 struct usb_request *req)
914{
915 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
916
917 WARN_ON(!list_empty(&ureq->node));
918 kfree(ureq);
919}
920
921static int usbhsg_ep_queue(struct usb_ep *ep, struct usb_request *req,
922 gfp_t gfp_flags)
923{
924 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
925 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
926 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
927 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
928 spinlock_t *lock;
929 unsigned long flags;
930 int ret = 0;
931
932 /*
933 * CAUTION [*endpoint queue*]
934 *
935 * This function will be called from usb_request :: complete
936 * or usb driver timing.
937 * If this function is called from usb_request :: complete,
938 * it is already under spinlock on this driver.
939 * but it is called frm usb driver, this function should call spinlock.
940 *
941 * This function is using usbshg_trylock to solve this issue.
942 * if "is_locked" is 1, this mean this function lock it.
943 * but if it is 0, this mean it is already under spin lock.
944 * see also
945 * CAUTION [*queue handler*]
946 * CAUTION [*request complete*]
947 */
948
949 /******************** spin lock ********************/
950 lock = usbhsg_trylock(gpriv, &flags);
951
952 /* param check */
953 if (usbhsg_is_not_connected(gpriv) ||
954 unlikely(!gpriv->driver) ||
955 unlikely(!pipe))
956 ret = -ESHUTDOWN;
957 else
958 usbhsg_queue_push(uep, ureq);
959
960 usbhsg_unlock(lock, &flags);
961 /******************** spin unlock ******************/
962
963 usbhsg_queue_prepare(uep);
964
965 return ret;
966}
967
968static int usbhsg_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
969{
970 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
971 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
972 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
973 spinlock_t *lock;
974 unsigned long flags;
975
976 /*
977 * see
978 * CAUTION [*queue handler*]
979 * CAUTION [*endpoint queue*]
980 * CAUTION [*request complete*]
981 */
982
983 /******************** spin lock ********************/
984 lock = usbhsg_trylock(gpriv, &flags);
985
986 usbhsg_queue_pop(uep, ureq, -ECONNRESET);
987
988 usbhsg_unlock(lock, &flags);
989 /******************** spin unlock ******************/
990
991 return 0;
992}
993
994static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
995{
996 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
997 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
998 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
999 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
1000 spinlock_t *lock;
1001 unsigned long flags;
1002 int ret = -EAGAIN;
1003
1004 /*
1005 * see
1006 * CAUTION [*queue handler*]
1007 * CAUTION [*endpoint queue*]
1008 * CAUTION [*request complete*]
1009 */
1010
1011 /******************** spin lock ********************/
1012 lock = usbhsg_trylock(gpriv, &flags);
1013 if (!usbhsg_queue_get(uep)) {
1014
1015 dev_dbg(dev, "set halt %d (pipe %d)\n",
1016 halt, usbhs_pipe_number(pipe));
1017
1018 if (halt)
1019 usbhs_fifo_stall(pipe);
1020 else
1021 usbhs_fifo_disable(pipe);
1022
1023 if (halt && wedge)
1024 usbhsg_status_set(gpriv, USBHSG_STATUS_WEDGE);
1025 else
1026 usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE);
1027
1028 ret = 0;
1029 }
1030
1031 usbhsg_unlock(lock, &flags);
1032 /******************** spin unlock ******************/
1033
1034 return ret;
1035}
1036
1037static int usbhsg_ep_set_halt(struct usb_ep *ep, int value)
1038{
1039 return __usbhsg_ep_set_halt_wedge(ep, value, 0);
1040}
1041
1042static int usbhsg_ep_set_wedge(struct usb_ep *ep)
1043{
1044 return __usbhsg_ep_set_halt_wedge(ep, 1, 1);
1045}
1046
1047static struct usb_ep_ops usbhsg_ep_ops = {
1048 .enable = usbhsg_ep_enable,
1049 .disable = usbhsg_ep_disable,
1050
1051 .alloc_request = usbhsg_ep_alloc_request,
1052 .free_request = usbhsg_ep_free_request,
1053
1054 .queue = usbhsg_ep_queue,
1055 .dequeue = usbhsg_ep_dequeue,
1056
1057 .set_halt = usbhsg_ep_set_halt,
1058 .set_wedge = usbhsg_ep_set_wedge,
1059};
1060
1061/*
1062 * usb module start/end
1063 */
1064static int usbhsg_try_start(struct usbhs_priv *priv, u32 status)
1065{
1066 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
1067 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
1068 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
1069 struct device *dev = usbhs_priv_to_dev(priv);
1070 spinlock_t *lock;
1071 unsigned long flags;
1072
1073 /******************** spin lock ********************/
1074 lock = usbhsg_trylock(gpriv, &flags);
1075
1076 /*
1077 * enable interrupt and systems if ready
1078 */
1079 usbhsg_status_set(gpriv, status);
1080 if (!(usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) &&
1081 usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD)))
1082 goto usbhsg_try_start_unlock;
1083
1084 dev_dbg(dev, "start gadget\n");
1085
1086 /*
1087 * pipe initialize and enable DCP
1088 */
1089 usbhs_pipe_init(priv);
1090 usbhsg_uep_init(gpriv);
1091 usbhsg_dcp_enable(dcp);
1092
1093 /*
1094 * system config enble
1095 * - HI speed
1096 * - function
1097 * - usb module
1098 */
1099 usbhs_sys_hispeed_ctrl(priv, 1);
1100 usbhs_sys_function_ctrl(priv, 1);
1101 usbhs_sys_usb_ctrl(priv, 1);
1102
1103 /*
1104 * enable irq callback
1105 */
1106 mod->irq_dev_state = usbhsg_irq_dev_state;
1107 mod->irq_ctrl_stage = usbhsg_irq_ctrl_stage;
1108 mod->irq_empty = usbhsg_irq_empty;
1109 mod->irq_ready = usbhsg_irq_ready;
1110 mod->irq_bempsts = 0;
1111 mod->irq_brdysts = 0;
1112 usbhs_irq_callback_update(priv, mod);
1113
1114usbhsg_try_start_unlock:
1115 usbhsg_unlock(lock, &flags);
1116 /******************** spin unlock ********************/
1117
1118 return 0;
1119}
1120
1121static int usbhsg_try_stop(struct usbhs_priv *priv, u32 status)
1122{
1123 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
1124 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
1125 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
1126 struct device *dev = usbhs_priv_to_dev(priv);
1127 spinlock_t *lock;
1128 unsigned long flags;
1129
1130 /******************** spin lock ********************/
1131 lock = usbhsg_trylock(gpriv, &flags);
1132
1133 /*
1134 * disable interrupt and systems if 1st try
1135 */
1136 usbhsg_status_clr(gpriv, status);
1137 if (!usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) &&
1138 !usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD))
1139 goto usbhsg_try_stop_unlock;
1140
1141 /* disable all irq */
1142 mod->irq_dev_state = NULL;
1143 mod->irq_ctrl_stage = NULL;
1144 mod->irq_empty = NULL;
1145 mod->irq_ready = NULL;
1146 mod->irq_bempsts = 0;
1147 mod->irq_brdysts = 0;
1148 usbhs_irq_callback_update(priv, mod);
1149
1150 usbhsg_dcp_disable(dcp);
1151
1152 gpriv->gadget.speed = USB_SPEED_UNKNOWN;
1153
1154 /* disable sys */
1155 usbhs_sys_hispeed_ctrl(priv, 0);
1156 usbhs_sys_function_ctrl(priv, 0);
1157 usbhs_sys_usb_ctrl(priv, 0);
1158
1159 usbhsg_unlock(lock, &flags);
1160 /******************** spin unlock ********************/
1161
1162 if (gpriv->driver &&
1163 gpriv->driver->disconnect)
1164 gpriv->driver->disconnect(&gpriv->gadget);
1165
1166 dev_dbg(dev, "stop gadget\n");
1167
1168 return 0;
1169
1170usbhsg_try_stop_unlock:
1171 usbhsg_unlock(lock, &flags);
1172
1173 return 0;
1174}
1175
1176/*
1177 *
1178 * linux usb function
1179 *
1180 */
1181struct usbhsg_gpriv *the_controller;
1182int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1183 int (*bind)(struct usb_gadget *))
1184{
1185 struct usbhsg_gpriv *gpriv = the_controller;
1186 struct usbhs_priv *priv;
1187 struct device *dev;
1188 int ret;
1189
1190 if (!bind ||
1191 !driver ||
1192 !driver->setup ||
1193 driver->speed != USB_SPEED_HIGH)
1194 return -EINVAL;
1195 if (!gpriv)
1196 return -ENODEV;
1197 if (gpriv->driver)
1198 return -EBUSY;
1199
1200 dev = usbhsg_gpriv_to_dev(gpriv);
1201 priv = usbhsg_gpriv_to_priv(gpriv);
1202
1203 /* first hook up the driver ... */
1204 gpriv->driver = driver;
1205 gpriv->gadget.dev.driver = &driver->driver;
1206
1207 ret = device_add(&gpriv->gadget.dev);
1208 if (ret) {
1209 dev_err(dev, "device_add error %d\n", ret);
1210 goto add_fail;
1211 }
1212
1213 ret = bind(&gpriv->gadget);
1214 if (ret) {
1215 dev_err(dev, "bind to driver %s error %d\n",
1216 driver->driver.name, ret);
1217 goto bind_fail;
1218 }
1219
1220 dev_dbg(dev, "bind %s\n", driver->driver.name);
1221
1222 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD);
1223
1224bind_fail:
1225 device_del(&gpriv->gadget.dev);
1226add_fail:
1227 gpriv->driver = NULL;
1228 gpriv->gadget.dev.driver = NULL;
1229
1230 return ret;
1231}
1232EXPORT_SYMBOL(usb_gadget_probe_driver);
1233
1234int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1235{
1236 struct usbhsg_gpriv *gpriv = the_controller;
1237 struct usbhs_priv *priv;
1238 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
1239
1240 if (!gpriv)
1241 return -ENODEV;
1242
1243 if (!driver ||
1244 !driver->unbind ||
1245 driver != gpriv->driver)
1246 return -EINVAL;
1247
1248 dev = usbhsg_gpriv_to_dev(gpriv);
1249 priv = usbhsg_gpriv_to_priv(gpriv);
1250
1251 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD);
1252 device_del(&gpriv->gadget.dev);
1253 gpriv->driver = NULL;
1254
1255 if (driver->disconnect)
1256 driver->disconnect(&gpriv->gadget);
1257
1258 driver->unbind(&gpriv->gadget);
1259 dev_dbg(dev, "unbind %s\n", driver->driver.name);
1260
1261 return 0;
1262}
1263EXPORT_SYMBOL(usb_gadget_unregister_driver);
1264
1265/*
1266 * usb gadget ops
1267 */
1268static int usbhsg_get_frame(struct usb_gadget *gadget)
1269{
1270 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget);
1271 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
1272
1273 return usbhs_frame_get_num(priv);
1274}
1275
1276static struct usb_gadget_ops usbhsg_gadget_ops = {
1277 .get_frame = usbhsg_get_frame,
1278};
1279
1280static int usbhsg_start(struct usbhs_priv *priv)
1281{
1282 return usbhsg_try_start(priv, USBHSG_STATUS_STARTED);
1283}
1284
1285static int usbhsg_stop(struct usbhs_priv *priv)
1286{
1287 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED);
1288}
1289
1290int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1291{
1292 struct usbhsg_gpriv *gpriv;
1293 struct usbhsg_uep *uep;
1294 struct device *dev = usbhs_priv_to_dev(priv);
1295 int pipe_size = usbhs_get_dparam(priv, pipe_size);
1296 int i;
1297
1298 gpriv = kzalloc(sizeof(struct usbhsg_gpriv), GFP_KERNEL);
1299 if (!gpriv) {
1300 dev_err(dev, "Could not allocate gadget priv\n");
1301 return -ENOMEM;
1302 }
1303
1304 uep = kzalloc(sizeof(struct usbhsg_uep) * pipe_size, GFP_KERNEL);
1305 if (!uep) {
1306 dev_err(dev, "Could not allocate ep\n");
1307 goto usbhs_mod_gadget_probe_err_gpriv;
1308 }
1309
1310 /*
1311 * CAUTION
1312 *
1313 * There is no guarantee that it is possible to access usb module here.
1314 * Don't accesses to it.
1315 * The accesse will be enable after "usbhsg_start"
1316 */
1317
1318 /*
1319 * register itself
1320 */
1321 usbhs_mod_register(priv, &gpriv->mod, USBHS_GADGET);
1322
1323 /* init gpriv */
1324 gpriv->mod.name = "gadget";
1325 gpriv->mod.start = usbhsg_start;
1326 gpriv->mod.stop = usbhsg_stop;
1327 gpriv->uep = uep;
1328 gpriv->uep_size = pipe_size;
1329 usbhsg_status_init(gpriv);
1330
1331 /*
1332 * init gadget
1333 */
1334 device_initialize(&gpriv->gadget.dev);
1335 dev_set_name(&gpriv->gadget.dev, "gadget");
1336 gpriv->gadget.dev.parent = dev;
1337 gpriv->gadget.name = "renesas_usbhs_udc";
1338 gpriv->gadget.ops = &usbhsg_gadget_ops;
1339 gpriv->gadget.is_dualspeed = 1;
1340
1341 INIT_LIST_HEAD(&gpriv->gadget.ep_list);
1342
1343 /*
1344 * init usb_ep
1345 */
1346 usbhsg_for_each_uep_with_dcp(uep, gpriv, i) {
1347 uep->gpriv = gpriv;
1348 snprintf(uep->ep_name, EP_NAME_SIZE, "ep%d", i);
1349
1350 uep->ep.name = uep->ep_name;
1351 uep->ep.ops = &usbhsg_ep_ops;
1352 INIT_LIST_HEAD(&uep->ep.ep_list);
1353 INIT_LIST_HEAD(&uep->list);
1354
1355 /* init DCP */
1356 if (usbhsg_is_dcp(uep)) {
1357 gpriv->gadget.ep0 = &uep->ep;
1358 uep->ep.maxpacket = 64;
1359 }
1360 /* init normal pipe */
1361 else {
1362 uep->ep.maxpacket = 512;
1363 list_add_tail(&uep->ep.ep_list, &gpriv->gadget.ep_list);
1364 }
1365 }
1366
1367 the_controller = gpriv;
1368
1369 dev_info(dev, "gadget probed\n");
1370
1371 return 0;
1372
1373usbhs_mod_gadget_probe_err_gpriv:
1374 kfree(gpriv);
1375
1376 return -ENOMEM;
1377}
1378
1379void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv)
1380{
1381 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
1382
1383 kfree(gpriv->uep);
1384 kfree(gpriv);
1385}
diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c
new file mode 100644
index 000000000000..bc4521c54261
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/pipe.c
@@ -0,0 +1,874 @@
1/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#include <linux/delay.h>
18#include <linux/io.h>
19#include <linux/slab.h>
20#include "./common.h"
21#include "./pipe.h"
22
23/*
24 * macros
25 */
26#define usbhsp_priv_to_pipeinfo(pr) (&(pr)->pipe_info)
27#define usbhsp_pipe_to_priv(p) ((p)->priv)
28
29#define usbhsp_addr_offset(p) ((usbhs_pipe_number(p) - 1) * 2)
30
31#define usbhsp_is_dcp(p) ((p)->priv->pipe_info.pipe == (p))
32
33#define usbhsp_flags_set(p, f) ((p)->flags |= USBHS_PIPE_FLAGS_##f)
34#define usbhsp_flags_clr(p, f) ((p)->flags &= ~USBHS_PIPE_FLAGS_##f)
35#define usbhsp_flags_has(p, f) ((p)->flags & USBHS_PIPE_FLAGS_##f)
36#define usbhsp_flags_init(p) do {(p)->flags = 0; } while (0)
37
38#define usbhsp_type(p) ((p)->pipe_type)
39#define usbhsp_type_is(p, t) ((p)->pipe_type == t)
40
41/*
42 * for debug
43 */
44static char *usbhsp_pipe_name[] = {
45 [USB_ENDPOINT_XFER_CONTROL] = "DCP",
46 [USB_ENDPOINT_XFER_BULK] = "BULK",
47 [USB_ENDPOINT_XFER_INT] = "INT",
48 [USB_ENDPOINT_XFER_ISOC] = "ISO",
49};
50
51/*
52 * usb request functions
53 */
54void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
55{
56 u16 val;
57
58 val = usbhs_read(priv, USBREQ);
59 req->bRequest = (val >> 8) & 0xFF;
60 req->bRequestType = (val >> 0) & 0xFF;
61
62 req->wValue = usbhs_read(priv, USBVAL);
63 req->wIndex = usbhs_read(priv, USBINDX);
64 req->wLength = usbhs_read(priv, USBLENG);
65}
66
67void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
68{
69 usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType);
70 usbhs_write(priv, USBVAL, req->wValue);
71 usbhs_write(priv, USBINDX, req->wIndex);
72 usbhs_write(priv, USBLENG, req->wLength);
73}
74
75/*
76 * DCPCTR/PIPEnCTR functions
77 */
78static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
79{
80 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
81 int offset = usbhsp_addr_offset(pipe);
82
83 if (usbhsp_is_dcp(pipe))
84 usbhs_bset(priv, DCPCTR, mask, val);
85 else
86 usbhs_bset(priv, PIPEnCTR + offset, mask, val);
87}
88
89static u16 usbhsp_pipectrl_get(struct usbhs_pipe *pipe)
90{
91 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
92 int offset = usbhsp_addr_offset(pipe);
93
94 if (usbhsp_is_dcp(pipe))
95 return usbhs_read(priv, DCPCTR);
96 else
97 return usbhs_read(priv, PIPEnCTR + offset);
98}
99
100/*
101 * DCP/PIPE functions
102 */
103static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe,
104 u16 dcp_reg, u16 pipe_reg,
105 u16 mask, u16 val)
106{
107 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
108
109 if (usbhsp_is_dcp(pipe))
110 usbhs_bset(priv, dcp_reg, mask, val);
111 else
112 usbhs_bset(priv, pipe_reg, mask, val);
113}
114
115static u16 __usbhsp_pipe_xxx_get(struct usbhs_pipe *pipe,
116 u16 dcp_reg, u16 pipe_reg)
117{
118 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
119
120 if (usbhsp_is_dcp(pipe))
121 return usbhs_read(priv, dcp_reg);
122 else
123 return usbhs_read(priv, pipe_reg);
124}
125
126/*
127 * DCPCFG/PIPECFG functions
128 */
129static void usbhsp_pipe_cfg_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
130{
131 __usbhsp_pipe_xxx_set(pipe, DCPCFG, PIPECFG, mask, val);
132}
133
134/*
135 * PIPEBUF
136 */
137static void usbhsp_pipe_buf_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
138{
139 if (usbhsp_is_dcp(pipe))
140 return;
141
142 __usbhsp_pipe_xxx_set(pipe, 0, PIPEBUF, mask, val);
143}
144
145/*
146 * DCPMAXP/PIPEMAXP
147 */
148static void usbhsp_pipe_maxp_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
149{
150 __usbhsp_pipe_xxx_set(pipe, DCPMAXP, PIPEMAXP, mask, val);
151}
152
153static u16 usbhsp_pipe_maxp_get(struct usbhs_pipe *pipe)
154{
155 return __usbhsp_pipe_xxx_get(pipe, DCPMAXP, PIPEMAXP);
156}
157
158/*
159 * pipe control functions
160 */
161static void usbhsp_pipe_select(struct usbhs_pipe *pipe)
162{
163 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
164
165 /*
166 * On pipe, this is necessary before
167 * accesses to below registers.
168 *
169 * PIPESEL : usbhsp_pipe_select
170 * PIPECFG : usbhsp_pipe_cfg_xxx
171 * PIPEBUF : usbhsp_pipe_buf_xxx
172 * PIPEMAXP : usbhsp_pipe_maxp_xxx
173 * PIPEPERI
174 */
175
176 /*
177 * if pipe is dcp, no pipe is selected.
178 * it is no problem, because dcp have its register
179 */
180 usbhs_write(priv, PIPESEL, 0xF & usbhs_pipe_number(pipe));
181}
182
183static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe)
184{
185 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
186 int timeout = 1024;
187 u16 val;
188
189 /*
190 * make sure....
191 *
192 * Modify these bits when CSSTS = 0, PID = NAK, and no pipe number is
193 * specified by the CURPIPE bits.
194 * When changing the setting of this bit after changing
195 * the PID bits for the selected pipe from BUF to NAK,
196 * check that CSSTS = 0 and PBUSY = 0.
197 */
198
199 /*
200 * CURPIPE bit = 0
201 *
202 * see also
203 * "Operation"
204 * - "Pipe Control"
205 * - "Pipe Control Registers Switching Procedure"
206 */
207 usbhs_write(priv, CFIFOSEL, 0);
208 usbhs_fifo_disable(pipe);
209
210 do {
211 val = usbhsp_pipectrl_get(pipe);
212 val &= CSSTS | PID_MASK;
213 if (!val)
214 return 0;
215
216 udelay(10);
217
218 } while (timeout--);
219
220 return -EBUSY;
221}
222
223static int usbhsp_pipe_is_accessible(struct usbhs_pipe *pipe)
224{
225 u16 val;
226
227 val = usbhsp_pipectrl_get(pipe);
228 if (val & BSTS)
229 return 0;
230
231 return -EBUSY;
232}
233
234/*
235 * PID ctrl
236 */
237static void __usbhsp_pid_try_nak_if_stall(struct usbhs_pipe *pipe)
238{
239 u16 pid = usbhsp_pipectrl_get(pipe);
240
241 pid &= PID_MASK;
242
243 /*
244 * see
245 * "Pipe n Control Register" - "PID"
246 */
247 switch (pid) {
248 case PID_STALL11:
249 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
250 /* fall-through */
251 case PID_STALL10:
252 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
253 }
254}
255
256void usbhs_fifo_disable(struct usbhs_pipe *pipe)
257{
258 int timeout = 1024;
259 u16 val;
260
261 /* see "Pipe n Control Register" - "PID" */
262 __usbhsp_pid_try_nak_if_stall(pipe);
263
264 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
265
266 do {
267 val = usbhsp_pipectrl_get(pipe);
268 val &= PBUSY;
269 if (!val)
270 break;
271
272 udelay(10);
273 } while (timeout--);
274}
275
276void usbhs_fifo_enable(struct usbhs_pipe *pipe)
277{
278 /* see "Pipe n Control Register" - "PID" */
279 __usbhsp_pid_try_nak_if_stall(pipe);
280
281 usbhsp_pipectrl_set(pipe, PID_MASK, PID_BUF);
282}
283
284void usbhs_fifo_stall(struct usbhs_pipe *pipe)
285{
286 u16 pid = usbhsp_pipectrl_get(pipe);
287
288 pid &= PID_MASK;
289
290 /*
291 * see
292 * "Pipe n Control Register" - "PID"
293 */
294 switch (pid) {
295 case PID_NAK:
296 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
297 break;
298 case PID_BUF:
299 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL11);
300 break;
301 }
302}
303
304/*
305 * CFIFO ctrl
306 */
307void usbhs_fifo_send_terminator(struct usbhs_pipe *pipe)
308{
309 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
310
311 usbhs_bset(priv, CFIFOCTR, BVAL, BVAL);
312}
313
314static void usbhsp_fifo_clear(struct usbhs_pipe *pipe)
315{
316 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
317
318 usbhs_write(priv, CFIFOCTR, BCLR);
319}
320
321static int usbhsp_fifo_barrier(struct usbhs_priv *priv)
322{
323 int timeout = 1024;
324
325 do {
326 /* The FIFO port is accessible */
327 if (usbhs_read(priv, CFIFOCTR) & FRDY)
328 return 0;
329
330 udelay(10);
331 } while (timeout--);
332
333 return -EBUSY;
334}
335
336static int usbhsp_fifo_rcv_len(struct usbhs_priv *priv)
337{
338 return usbhs_read(priv, CFIFOCTR) & DTLN_MASK;
339}
340
341static int usbhsp_fifo_select(struct usbhs_pipe *pipe, int write)
342{
343 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
344 struct device *dev = usbhs_priv_to_dev(priv);
345 int timeout = 1024;
346 u16 mask = ((1 << 5) | 0xF); /* mask of ISEL | CURPIPE */
347 u16 base = usbhs_pipe_number(pipe); /* CURPIPE */
348
349 if (usbhsp_is_dcp(pipe))
350 base |= (1 == write) << 5; /* ISEL */
351
352 /* "base" will be used below */
353 usbhs_write(priv, CFIFOSEL, base | MBW_32);
354
355 /* check ISEL and CURPIPE value */
356 while (timeout--) {
357 if (base == (mask & usbhs_read(priv, CFIFOSEL)))
358 return 0;
359 udelay(10);
360 }
361
362 dev_err(dev, "fifo select error\n");
363
364 return -EIO;
365}
366
367int usbhs_fifo_prepare_write(struct usbhs_pipe *pipe)
368{
369 return usbhsp_fifo_select(pipe, 1);
370}
371
372int usbhs_fifo_write(struct usbhs_pipe *pipe, u8 *buf, int len)
373{
374 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
375 void __iomem *addr = priv->base + CFIFO;
376 int maxp = usbhs_pipe_get_maxpacket(pipe);
377 int total_len;
378 int i, ret;
379
380 ret = usbhsp_pipe_is_accessible(pipe);
381 if (ret < 0)
382 return ret;
383
384 ret = usbhsp_fifo_select(pipe, 1);
385 if (ret < 0)
386 return ret;
387
388 ret = usbhsp_fifo_barrier(priv);
389 if (ret < 0)
390 return ret;
391
392 len = min(len, maxp);
393 total_len = len;
394
395 /*
396 * FIXME
397 *
398 * 32-bit access only
399 */
400 if (len >= 4 &&
401 !((unsigned long)buf & 0x03)) {
402 iowrite32_rep(addr, buf, len / 4);
403 len %= 4;
404 buf += total_len - len;
405 }
406
407 /* the rest operation */
408 for (i = 0; i < len; i++)
409 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
410
411 if (total_len < maxp)
412 usbhs_fifo_send_terminator(pipe);
413
414 return total_len;
415}
416
417int usbhs_fifo_prepare_read(struct usbhs_pipe *pipe)
418{
419 int ret;
420
421 /*
422 * select pipe and enable it to prepare packet receive
423 */
424 ret = usbhsp_fifo_select(pipe, 0);
425 if (ret < 0)
426 return ret;
427
428 usbhs_fifo_enable(pipe);
429
430 return ret;
431}
432
433int usbhs_fifo_read(struct usbhs_pipe *pipe, u8 *buf, int len)
434{
435 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
436 void __iomem *addr = priv->base + CFIFO;
437 int rcv_len;
438 int i, ret;
439 int total_len;
440 u32 data = 0;
441
442 ret = usbhsp_fifo_select(pipe, 0);
443 if (ret < 0)
444 return ret;
445
446 ret = usbhsp_fifo_barrier(priv);
447 if (ret < 0)
448 return ret;
449
450 rcv_len = usbhsp_fifo_rcv_len(priv);
451
452 /*
453 * Buffer clear if Zero-Length packet
454 *
455 * see
456 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
457 */
458 if (0 == rcv_len) {
459 usbhsp_fifo_clear(pipe);
460 return 0;
461 }
462
463 len = min(rcv_len, len);
464 total_len = len;
465
466 /*
467 * FIXME
468 *
469 * 32-bit access only
470 */
471 if (len >= 4 &&
472 !((unsigned long)buf & 0x03)) {
473 ioread32_rep(addr, buf, len / 4);
474 len %= 4;
475 buf += rcv_len - len;
476 }
477
478 /* the rest operation */
479 for (i = 0; i < len; i++) {
480 if (!(i & 0x03))
481 data = ioread32(addr);
482
483 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
484 }
485
486 return total_len;
487}
488
489/*
490 * pipe setup
491 */
492static int usbhsp_possible_double_buffer(struct usbhs_pipe *pipe)
493{
494 /*
495 * only ISO / BULK pipe can use double buffer
496 */
497 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK) ||
498 usbhsp_type_is(pipe, USB_ENDPOINT_XFER_ISOC))
499 return 1;
500
501 return 0;
502}
503
504static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
505 const struct usb_endpoint_descriptor *desc,
506 int is_host)
507{
508 u16 type = 0;
509 u16 bfre = 0;
510 u16 dblb = 0;
511 u16 cntmd = 0;
512 u16 dir = 0;
513 u16 epnum = 0;
514 u16 shtnak = 0;
515 u16 type_array[] = {
516 [USB_ENDPOINT_XFER_BULK] = TYPE_BULK,
517 [USB_ENDPOINT_XFER_INT] = TYPE_INT,
518 [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO,
519 };
520 int is_double = usbhsp_possible_double_buffer(pipe);
521
522 if (usbhsp_is_dcp(pipe))
523 return -EINVAL;
524
525 /*
526 * PIPECFG
527 *
528 * see
529 * - "Register Descriptions" - "PIPECFG" register
530 * - "Features" - "Pipe configuration"
531 * - "Operation" - "Pipe Control"
532 */
533
534 /* TYPE */
535 type = type_array[usbhsp_type(pipe)];
536
537 /* BFRE */
538 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
539 usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK))
540 bfre = 0; /* FIXME */
541
542 /* DBLB */
543 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
544 usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK))
545 dblb = (is_double) ? DBLB : 0;
546
547 /* CNTMD */
548 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK))
549 cntmd = 0; /* FIXME */
550
551 /* DIR */
552 if (usb_endpoint_dir_in(desc))
553 usbhsp_flags_set(pipe, IS_DIR_IN);
554
555 if ((is_host && usb_endpoint_dir_out(desc)) ||
556 (!is_host && usb_endpoint_dir_in(desc)))
557 dir |= DIR_OUT;
558
559 /* SHTNAK */
560 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK) &&
561 !dir)
562 shtnak = SHTNAK;
563
564 /* EPNUM */
565 epnum = 0xF & usb_endpoint_num(desc);
566
567 return type |
568 bfre |
569 dblb |
570 cntmd |
571 dir |
572 shtnak |
573 epnum;
574}
575
576static u16 usbhsp_setup_pipemaxp(struct usbhs_pipe *pipe,
577 const struct usb_endpoint_descriptor *desc,
578 int is_host)
579{
580 /* host should set DEVSEL */
581
582 /* reutn MXPS */
583 return PIPE_MAXP_MASK & le16_to_cpu(desc->wMaxPacketSize);
584}
585
586static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe,
587 const struct usb_endpoint_descriptor *desc,
588 int is_host)
589{
590 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
591 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
592 struct device *dev = usbhs_priv_to_dev(priv);
593 int pipe_num = usbhs_pipe_number(pipe);
594 int is_double = usbhsp_possible_double_buffer(pipe);
595 u16 buff_size;
596 u16 bufnmb;
597 u16 bufnmb_cnt;
598
599 /*
600 * PIPEBUF
601 *
602 * see
603 * - "Register Descriptions" - "PIPEBUF" register
604 * - "Features" - "Pipe configuration"
605 * - "Operation" - "FIFO Buffer Memory"
606 * - "Operation" - "Pipe Control"
607 *
608 * ex) if pipe6 - pipe9 are USB_ENDPOINT_XFER_INT (SH7724)
609 *
610 * BUFNMB: PIPE
611 * 0: pipe0 (DCP 256byte)
612 * 1: -
613 * 2: -
614 * 3: -
615 * 4: pipe6 (INT 64byte)
616 * 5: pipe7 (INT 64byte)
617 * 6: pipe8 (INT 64byte)
618 * 7: pipe9 (INT 64byte)
619 * 8 - xx: free (for BULK, ISOC)
620 */
621
622 /*
623 * FIXME
624 *
625 * it doesn't have good buffer allocator
626 *
627 * DCP : 256 byte
628 * BULK: 512 byte
629 * INT : 64 byte
630 * ISOC: 512 byte
631 */
632 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_CONTROL))
633 buff_size = 256;
634 else if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_INT))
635 buff_size = 64;
636 else
637 buff_size = 512;
638
639 /* change buff_size to register value */
640 bufnmb_cnt = (buff_size / 64) - 1;
641
642 /* BUFNMB has been reserved for INT pipe
643 * see above */
644 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_INT)) {
645 bufnmb = pipe_num - 2;
646 } else {
647 bufnmb = info->bufnmb_last;
648 info->bufnmb_last += bufnmb_cnt + 1;
649
650 /*
651 * double buffer
652 */
653 if (is_double)
654 info->bufnmb_last += bufnmb_cnt + 1;
655 }
656
657 dev_dbg(dev, "pipe : %d : buff_size 0x%x: bufnmb 0x%x\n",
658 pipe_num, buff_size, bufnmb);
659
660 return (0x1f & bufnmb_cnt) << 10 |
661 (0xff & bufnmb) << 0;
662}
663
664/*
665 * pipe control
666 */
667int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe)
668{
669 u16 mask = usbhsp_is_dcp(pipe) ? DCP_MAXP_MASK : PIPE_MAXP_MASK;
670
671 usbhsp_pipe_select(pipe);
672
673 return (int)(usbhsp_pipe_maxp_get(pipe) & mask);
674}
675
676int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe)
677{
678 return usbhsp_flags_has(pipe, IS_DIR_IN);
679}
680
681void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe)
682{
683 usbhsp_pipectrl_set(pipe, SQCLR, SQCLR);
684}
685
686static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type)
687{
688 struct usbhs_pipe *pos, *pipe;
689 int i;
690
691 /*
692 * find target pipe
693 */
694 pipe = NULL;
695 usbhs_for_each_pipe_with_dcp(pos, priv, i) {
696 if (!usbhsp_type_is(pos, type))
697 continue;
698 if (usbhsp_flags_has(pos, IS_USED))
699 continue;
700
701 pipe = pos;
702 break;
703 }
704
705 if (!pipe)
706 return NULL;
707
708 /*
709 * initialize pipe flags
710 */
711 usbhsp_flags_init(pipe);
712 usbhsp_flags_set(pipe, IS_USED);
713
714 return pipe;
715}
716
717void usbhs_pipe_init(struct usbhs_priv *priv)
718{
719 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
720 struct usbhs_pipe *pipe;
721 int i;
722
723 /*
724 * FIXME
725 *
726 * driver needs good allocator.
727 *
728 * find first free buffer area (BULK, ISOC)
729 * (DCP, INT area is fixed)
730 *
731 * buffer number 0 - 3 have been reserved for DCP
732 * see
733 * usbhsp_to_bufnmb
734 */
735 info->bufnmb_last = 4;
736 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
737 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_INT))
738 info->bufnmb_last++;
739
740 usbhsp_flags_init(pipe);
741 pipe->mod_private = NULL;
742
743 usbhsp_fifo_clear(pipe);
744 }
745}
746
747struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
748 const struct usb_endpoint_descriptor *desc)
749{
750 struct device *dev = usbhs_priv_to_dev(priv);
751 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
752 struct usbhs_pipe *pipe;
753 int is_host = usbhs_mod_is_host(priv, mod);
754 int ret;
755 u16 pipecfg, pipebuf, pipemaxp;
756
757 pipe = usbhsp_get_pipe(priv, usb_endpoint_type(desc));
758 if (!pipe) {
759 dev_err(dev, "can't get pipe (%s)\n",
760 usbhsp_pipe_name[usb_endpoint_type(desc)]);
761 return NULL;
762 }
763
764 usbhs_fifo_disable(pipe);
765
766 /* make sure pipe is not busy */
767 ret = usbhsp_pipe_barrier(pipe);
768 if (ret < 0) {
769 dev_err(dev, "pipe setup failed %d\n", usbhs_pipe_number(pipe));
770 return NULL;
771 }
772
773 pipecfg = usbhsp_setup_pipecfg(pipe, desc, is_host);
774 pipebuf = usbhsp_setup_pipebuff(pipe, desc, is_host);
775 pipemaxp = usbhsp_setup_pipemaxp(pipe, desc, is_host);
776
777 /* buffer clear
778 * see PIPECFG :: BFRE */
779 usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
780 usbhsp_pipectrl_set(pipe, ACLRM, 0);
781
782 usbhsp_pipe_select(pipe);
783 usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg);
784 usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf);
785 usbhsp_pipe_maxp_set(pipe, 0xFFFF, pipemaxp);
786
787 usbhs_pipe_clear_sequence(pipe);
788
789 dev_dbg(dev, "enable pipe %d : %s (%s)\n",
790 usbhs_pipe_number(pipe),
791 usbhsp_pipe_name[usb_endpoint_type(desc)],
792 usbhs_pipe_is_dir_in(pipe) ? "in" : "out");
793
794 return pipe;
795}
796
797/*
798 * dcp control
799 */
800struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv)
801{
802 struct usbhs_pipe *pipe;
803
804 pipe = usbhsp_get_pipe(priv, USB_ENDPOINT_XFER_CONTROL);
805 if (!pipe)
806 return NULL;
807
808 /*
809 * dcpcfg : default
810 * dcpmaxp : default
811 * pipebuf : nothing to do
812 */
813
814 usbhsp_pipe_select(pipe);
815 usbhs_pipe_clear_sequence(pipe);
816
817 return pipe;
818}
819
820void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe)
821{
822 WARN_ON(!usbhsp_is_dcp(pipe));
823
824 usbhs_fifo_enable(pipe);
825 usbhsp_pipectrl_set(pipe, CCPL, CCPL);
826}
827
828
829/*
830 * pipe module function
831 */
832int usbhs_pipe_probe(struct usbhs_priv *priv)
833{
834 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
835 struct usbhs_pipe *pipe;
836 struct device *dev = usbhs_priv_to_dev(priv);
837 u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
838 int pipe_size = usbhs_get_dparam(priv, pipe_size);
839 int i;
840
841 /* This driver expects 1st pipe is DCP */
842 if (pipe_type[0] != USB_ENDPOINT_XFER_CONTROL) {
843 dev_err(dev, "1st PIPE is not DCP\n");
844 return -EINVAL;
845 }
846
847 info->pipe = kzalloc(sizeof(struct usbhs_pipe) * pipe_size, GFP_KERNEL);
848 if (!info->pipe) {
849 dev_err(dev, "Could not allocate pipe\n");
850 return -ENOMEM;
851 }
852
853 info->size = pipe_size;
854
855 /*
856 * init pipe
857 */
858 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
859 pipe->priv = priv;
860 usbhsp_type(pipe) = pipe_type[i] & USB_ENDPOINT_XFERTYPE_MASK;
861
862 dev_dbg(dev, "pipe %x\t: %s\n",
863 i, usbhsp_pipe_name[pipe_type[i]]);
864 }
865
866 return 0;
867}
868
869void usbhs_pipe_remove(struct usbhs_priv *priv)
870{
871 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
872
873 kfree(info->pipe);
874}
diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h
new file mode 100644
index 000000000000..1cca9b7fb266
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/pipe.h
@@ -0,0 +1,104 @@
1/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#ifndef RENESAS_USB_PIPE_H
18#define RENESAS_USB_PIPE_H
19
20#include "./common.h"
21
22/*
23 * struct
24 */
25struct usbhs_pipe {
26 u32 pipe_type; /* USB_ENDPOINT_XFER_xxx */
27
28 struct usbhs_priv *priv;
29
30 u32 flags;
31#define USBHS_PIPE_FLAGS_IS_USED (1 << 0)
32#define USBHS_PIPE_FLAGS_IS_DIR_IN (1 << 1)
33
34 void *mod_private;
35};
36
37struct usbhs_pipe_info {
38 struct usbhs_pipe *pipe;
39 int size; /* array size of "pipe" */
40 int bufnmb_last; /* FIXME : driver needs good allocator */
41};
42
43/*
44 * pipe list
45 */
46#define __usbhs_for_each_pipe(start, pos, info, i) \
47 for (i = start, pos = (info)->pipe; \
48 i < (info)->size; \
49 i++, pos = (info)->pipe + i)
50
51#define usbhs_for_each_pipe(pos, priv, i) \
52 __usbhs_for_each_pipe(1, pos, &((priv)->pipe_info), i)
53
54#define usbhs_for_each_pipe_with_dcp(pos, priv, i) \
55 __usbhs_for_each_pipe(0, pos, &((priv)->pipe_info), i)
56
57/*
58 * pipe module probe / remove
59 */
60int usbhs_pipe_probe(struct usbhs_priv *priv);
61void usbhs_pipe_remove(struct usbhs_priv *priv);
62
63/*
64 * cfifo
65 */
66int usbhs_fifo_write(struct usbhs_pipe *pipe, u8 *buf, int len);
67int usbhs_fifo_read(struct usbhs_pipe *pipe, u8 *buf, int len);
68int usbhs_fifo_prepare_write(struct usbhs_pipe *pipe);
69int usbhs_fifo_prepare_read(struct usbhs_pipe *pipe);
70
71void usbhs_fifo_enable(struct usbhs_pipe *pipe);
72void usbhs_fifo_disable(struct usbhs_pipe *pipe);
73void usbhs_fifo_stall(struct usbhs_pipe *pipe);
74
75void usbhs_fifo_send_terminator(struct usbhs_pipe *pipe);
76
77
78/*
79 * usb request
80 */
81void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req);
82void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req);
83
84/*
85 * pipe control
86 */
87struct usbhs_pipe
88*usbhs_pipe_malloc(struct usbhs_priv *priv,
89 const struct usb_endpoint_descriptor *desc);
90
91int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe);
92void usbhs_pipe_init(struct usbhs_priv *priv);
93int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe);
94void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe);
95
96#define usbhs_pipe_number(p) (int)((p) - (p)->priv->pipe_info.pipe)
97
98/*
99 * dcp control
100 */
101struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv);
102void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe);
103
104#endif /* RENESAS_USB_PIPE_H */
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 916b2b6d765f..b71e309116a3 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -176,7 +176,7 @@ config USB_SERIAL_VISOR
176 help 176 help
177 Say Y here if you want to connect to your HandSpring Visor, Palm 177 Say Y here if you want to connect to your HandSpring Visor, Palm
178 m500 or m505 through its USB docking station. See 178 m500 or m505 through its USB docking station. See
179 <http://usbvisor.sourceforge.net/> for more information on using this 179 <http://usbvisor.sourceforge.net/index.php3> for more information on using this
180 driver. 180 driver.
181 181
182 To compile this driver as a module, choose M here: the 182 To compile this driver as a module, choose M here: the
@@ -289,7 +289,7 @@ config USB_SERIAL_KEYSPAN
289 and was developed with their support. You must also include 289 and was developed with their support. You must also include
290 firmware to support your particular device(s). 290 firmware to support your particular device(s).
291 291
292 See <http://misc.nu/hugh/keyspan.html> for more information. 292 See <http://blemings.org/hugh/keyspan.html> for more information.
293 293
294 To compile this driver as a module, choose M here: the 294 To compile this driver as a module, choose M here: the
295 module will be called keyspan. 295 module will be called keyspan.
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 40ebe17b6ea8..9e536eefb32c 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -6,10 +6,10 @@
6 6
7obj-$(CONFIG_USB_SERIAL) += usbserial.o 7obj-$(CONFIG_USB_SERIAL) += usbserial.o
8 8
9usbserial-obj-$(CONFIG_USB_SERIAL_CONSOLE) += console.o 9usbserial-y := usb-serial.o generic.o bus.o
10usbserial-obj-$(CONFIG_USB_EZUSB) += ezusb.o
11 10
12usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y) 11usbserial-$(CONFIG_USB_SERIAL_CONSOLE) += console.o
12usbserial-$(CONFIG_USB_EZUSB) += ezusb.o
13 13
14obj-$(CONFIG_USB_SERIAL_AIRCABLE) += aircable.o 14obj-$(CONFIG_USB_SERIAL_AIRCABLE) += aircable.o
15obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o 15obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o
@@ -58,6 +58,5 @@ obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
58obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o 58obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o
59obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 59obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
60obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o 60obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o
61obj-$(CONFIG_USB_SERIAL_VIVOPAY_SERIAL) += vivopay-serial.o 61obj-$(CONFIG_USB_SERIAL_VIVOPAY_SERIAL) += vivopay-serial.o
62obj-$(CONFIG_USB_SERIAL_ZIO) += zio.o 62obj-$(CONFIG_USB_SERIAL_ZIO) += zio.o
63
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index 0db6ace16f7b..aba201cb872c 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -16,7 +16,7 @@
16 * When reading the process is almost equal except that the header starts with 16 * When reading the process is almost equal except that the header starts with
17 * 0x00 0x20. 17 * 0x00 0x20.
18 * 18 *
19 * The device simply need some stuff to understand data comming from the usb 19 * The device simply need some stuff to understand data coming from the usb
20 * buffer: The First and Second byte is used for a Header, the Third and Fourth 20 * buffer: The First and Second byte is used for a Header, the Third and Fourth
21 * tells the device the amount of information the package holds. 21 * tells the device the amount of information the package holds.
22 * Packages are 60 bytes long Header Stuff. 22 * Packages are 60 bytes long Header Stuff.
@@ -30,7 +30,7 @@
30 * one. 30 * one.
31 * 31 *
32 * The driver registers himself with the USB-serial core and the USB Core. I had 32 * The driver registers himself with the USB-serial core and the USB Core. I had
33 * to implement a probe function agains USB-serial, because other way, the 33 * to implement a probe function against USB-serial, because other way, the
34 * driver was attaching himself to both interfaces. I have tryed with different 34 * driver was attaching himself to both interfaces. I have tryed with different
35 * configurations of usb_serial_driver with out exit, only the probe function 35 * configurations of usb_serial_driver with out exit, only the probe function
36 * could handle this correctly. 36 * could handle this correctly.
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 4e41a2a39422..5cdb9d912275 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -411,7 +411,27 @@ err_out:
411 return result; 411 return result;
412} 412}
413 413
414static int ark3116_ioctl(struct tty_struct *tty, struct file *file, 414static int ark3116_get_icount(struct tty_struct *tty,
415 struct serial_icounter_struct *icount)
416{
417 struct usb_serial_port *port = tty->driver_data;
418 struct ark3116_private *priv = usb_get_serial_port_data(port);
419 struct async_icount cnow = priv->icount;
420 icount->cts = cnow.cts;
421 icount->dsr = cnow.dsr;
422 icount->rng = cnow.rng;
423 icount->dcd = cnow.dcd;
424 icount->rx = cnow.rx;
425 icount->tx = cnow.tx;
426 icount->frame = cnow.frame;
427 icount->overrun = cnow.overrun;
428 icount->parity = cnow.parity;
429 icount->brk = cnow.brk;
430 icount->buf_overrun = cnow.buf_overrun;
431 return 0;
432}
433
434static int ark3116_ioctl(struct tty_struct *tty,
415 unsigned int cmd, unsigned long arg) 435 unsigned int cmd, unsigned long arg)
416{ 436{
417 struct usb_serial_port *port = tty->driver_data; 437 struct usb_serial_port *port = tty->driver_data;
@@ -460,31 +480,12 @@ static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
460 return 0; 480 return 0;
461 } 481 }
462 break; 482 break;
463 case TIOCGICOUNT: {
464 struct serial_icounter_struct icount;
465 struct async_icount cnow = priv->icount;
466 memset(&icount, 0, sizeof(icount));
467 icount.cts = cnow.cts;
468 icount.dsr = cnow.dsr;
469 icount.rng = cnow.rng;
470 icount.dcd = cnow.dcd;
471 icount.rx = cnow.rx;
472 icount.tx = cnow.tx;
473 icount.frame = cnow.frame;
474 icount.overrun = cnow.overrun;
475 icount.parity = cnow.parity;
476 icount.brk = cnow.brk;
477 icount.buf_overrun = cnow.buf_overrun;
478 if (copy_to_user(user_arg, &icount, sizeof(icount)))
479 return -EFAULT;
480 return 0;
481 }
482 } 483 }
483 484
484 return -ENOIOCTLCMD; 485 return -ENOIOCTLCMD;
485} 486}
486 487
487static int ark3116_tiocmget(struct tty_struct *tty, struct file *file) 488static int ark3116_tiocmget(struct tty_struct *tty)
488{ 489{
489 struct usb_serial_port *port = tty->driver_data; 490 struct usb_serial_port *port = tty->driver_data;
490 struct ark3116_private *priv = usb_get_serial_port_data(port); 491 struct ark3116_private *priv = usb_get_serial_port_data(port);
@@ -510,7 +511,7 @@ static int ark3116_tiocmget(struct tty_struct *tty, struct file *file)
510 (ctrl & UART_MCR_OUT2 ? TIOCM_OUT2 : 0); 511 (ctrl & UART_MCR_OUT2 ? TIOCM_OUT2 : 0);
511} 512}
512 513
513static int ark3116_tiocmset(struct tty_struct *tty, struct file *file, 514static int ark3116_tiocmset(struct tty_struct *tty,
514 unsigned set, unsigned clr) 515 unsigned set, unsigned clr)
515{ 516{
516 struct usb_serial_port *port = tty->driver_data; 517 struct usb_serial_port *port = tty->driver_data;
@@ -736,6 +737,7 @@ static struct usb_serial_driver ark3116_device = {
736 .ioctl = ark3116_ioctl, 737 .ioctl = ark3116_ioctl,
737 .tiocmget = ark3116_tiocmget, 738 .tiocmget = ark3116_tiocmget,
738 .tiocmset = ark3116_tiocmset, 739 .tiocmset = ark3116_tiocmset,
740 .get_icount = ark3116_get_icount,
739 .open = ark3116_open, 741 .open = ark3116_open,
740 .close = ark3116_close, 742 .close = ark3116_close,
741 .break_ctl = ark3116_break_ctl, 743 .break_ctl = ark3116_break_ctl,
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 36df35295db2..d6921fa1403c 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -100,8 +100,8 @@ static void belkin_sa_process_read_urb(struct urb *urb);
100static void belkin_sa_set_termios(struct tty_struct *tty, 100static void belkin_sa_set_termios(struct tty_struct *tty,
101 struct usb_serial_port *port, struct ktermios * old); 101 struct usb_serial_port *port, struct ktermios * old);
102static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state); 102static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state);
103static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file); 103static int belkin_sa_tiocmget(struct tty_struct *tty);
104static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file, 104static int belkin_sa_tiocmset(struct tty_struct *tty,
105 unsigned int set, unsigned int clear); 105 unsigned int set, unsigned int clear);
106 106
107 107
@@ -497,7 +497,7 @@ static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state)
497 dev_err(&port->dev, "Set break_ctl %d\n", break_state); 497 dev_err(&port->dev, "Set break_ctl %d\n", break_state);
498} 498}
499 499
500static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file) 500static int belkin_sa_tiocmget(struct tty_struct *tty)
501{ 501{
502 struct usb_serial_port *port = tty->driver_data; 502 struct usb_serial_port *port = tty->driver_data;
503 struct belkin_sa_private *priv = usb_get_serial_port_data(port); 503 struct belkin_sa_private *priv = usb_get_serial_port_data(port);
@@ -513,7 +513,7 @@ static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file)
513 return control_state; 513 return control_state;
514} 514}
515 515
516static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file, 516static int belkin_sa_tiocmset(struct tty_struct *tty,
517 unsigned int set, unsigned int clear) 517 unsigned int set, unsigned int clear)
518{ 518{
519 struct usb_serial_port *port = tty->driver_data; 519 struct usb_serial_port *port = tty->driver_data;
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 63f7cc45bcac..6ae1c0688b5e 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -75,6 +75,7 @@ static int debug;
75static const struct usb_device_id id_table[] = { 75static const struct usb_device_id id_table[] = {
76 { USB_DEVICE(0x4348, 0x5523) }, 76 { USB_DEVICE(0x4348, 0x5523) },
77 { USB_DEVICE(0x1a86, 0x7523) }, 77 { USB_DEVICE(0x1a86, 0x7523) },
78 { USB_DEVICE(0x1a86, 0x5523) },
78 { }, 79 { },
79}; 80};
80MODULE_DEVICE_TABLE(usb, id_table); 81MODULE_DEVICE_TABLE(usb, id_table);
@@ -431,7 +432,7 @@ out:
431 kfree(break_reg); 432 kfree(break_reg);
432} 433}
433 434
434static int ch341_tiocmset(struct tty_struct *tty, struct file *file, 435static int ch341_tiocmset(struct tty_struct *tty,
435 unsigned int set, unsigned int clear) 436 unsigned int set, unsigned int clear)
436{ 437{
437 struct usb_serial_port *port = tty->driver_data; 438 struct usb_serial_port *port = tty->driver_data;
@@ -486,12 +487,22 @@ static void ch341_read_int_callback(struct urb *urb)
486 if (actual_length >= 4) { 487 if (actual_length >= 4) {
487 struct ch341_private *priv = usb_get_serial_port_data(port); 488 struct ch341_private *priv = usb_get_serial_port_data(port);
488 unsigned long flags; 489 unsigned long flags;
490 u8 prev_line_status = priv->line_status;
489 491
490 spin_lock_irqsave(&priv->lock, flags); 492 spin_lock_irqsave(&priv->lock, flags);
491 priv->line_status = (~(data[2])) & CH341_BITS_MODEM_STAT; 493 priv->line_status = (~(data[2])) & CH341_BITS_MODEM_STAT;
492 if ((data[1] & CH341_MULT_STAT)) 494 if ((data[1] & CH341_MULT_STAT))
493 priv->multi_status_change = 1; 495 priv->multi_status_change = 1;
494 spin_unlock_irqrestore(&priv->lock, flags); 496 spin_unlock_irqrestore(&priv->lock, flags);
497
498 if ((priv->line_status ^ prev_line_status) & CH341_BIT_DCD) {
499 struct tty_struct *tty = tty_port_tty_get(&port->port);
500 if (tty)
501 usb_serial_handle_dcd_change(port, tty,
502 priv->line_status & CH341_BIT_DCD);
503 tty_kref_put(tty);
504 }
505
495 wake_up_interruptible(&priv->delta_msr_wait); 506 wake_up_interruptible(&priv->delta_msr_wait);
496 } 507 }
497 508
@@ -542,8 +553,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
542 return 0; 553 return 0;
543} 554}
544 555
545/*static int ch341_ioctl(struct usb_serial_port *port, struct file *file,*/ 556static int ch341_ioctl(struct tty_struct *tty,
546static int ch341_ioctl(struct tty_struct *tty, struct file *file,
547 unsigned int cmd, unsigned long arg) 557 unsigned int cmd, unsigned long arg)
548{ 558{
549 struct usb_serial_port *port = tty->driver_data; 559 struct usb_serial_port *port = tty->driver_data;
@@ -562,7 +572,7 @@ static int ch341_ioctl(struct tty_struct *tty, struct file *file,
562 return -ENOIOCTLCMD; 572 return -ENOIOCTLCMD;
563} 573}
564 574
565static int ch341_tiocmget(struct tty_struct *tty, struct file *file) 575static int ch341_tiocmget(struct tty_struct *tty)
566{ 576{
567 struct usb_serial_port *port = tty->driver_data; 577 struct usb_serial_port *port = tty->driver_data;
568 struct ch341_private *priv = usb_get_serial_port_data(port); 578 struct ch341_private *priv = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 4f1744c5871f..fd67cc53545b 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -41,19 +41,18 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
41 unsigned int *cflagp, unsigned int *baudp); 41 unsigned int *cflagp, unsigned int *baudp);
42static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *, 42static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *,
43 struct ktermios*); 43 struct ktermios*);
44static int cp210x_tiocmget(struct tty_struct *, struct file *); 44static int cp210x_tiocmget(struct tty_struct *);
45static int cp210x_tiocmset(struct tty_struct *, struct file *, 45static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int);
46 unsigned int, unsigned int); 46static int cp210x_tiocmset_port(struct usb_serial_port *port,
47static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *,
48 unsigned int, unsigned int); 47 unsigned int, unsigned int);
49static void cp210x_break_ctl(struct tty_struct *, int); 48static void cp210x_break_ctl(struct tty_struct *, int);
50static int cp210x_startup(struct usb_serial *); 49static int cp210x_startup(struct usb_serial *);
51static void cp210x_dtr_rts(struct usb_serial_port *p, int on); 50static void cp210x_dtr_rts(struct usb_serial_port *p, int on);
52static int cp210x_carrier_raised(struct usb_serial_port *p);
53 51
54static int debug; 52static int debug;
55 53
56static const struct usb_device_id id_table[] = { 54static const struct usb_device_id id_table[] = {
55 { USB_DEVICE(0x045B, 0x0053) }, /* Renesas RX610 RX-Stick */
57 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */ 56 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
58 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ 57 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
59 { USB_DEVICE(0x0489, 0xE003) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ 58 { USB_DEVICE(0x0489, 0xE003) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
@@ -86,7 +85,6 @@ static const struct usb_device_id id_table[] = {
86 { USB_DEVICE(0x10C4, 0x8115) }, /* Arygon NFC/Mifare Reader */ 85 { USB_DEVICE(0x10C4, 0x8115) }, /* Arygon NFC/Mifare Reader */
87 { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */ 86 { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */
88 { USB_DEVICE(0x10C4, 0x813F) }, /* Tams Master Easy Control */ 87 { USB_DEVICE(0x10C4, 0x813F) }, /* Tams Master Easy Control */
89 { USB_DEVICE(0x10C4, 0x8149) }, /* West Mountain Radio Computerized Battery Analyzer */
90 { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */ 88 { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */
91 { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */ 89 { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */
92 { USB_DEVICE(0x10C4, 0x8156) }, /* B&G H3000 link cable */ 90 { USB_DEVICE(0x10C4, 0x8156) }, /* B&G H3000 link cable */
@@ -103,15 +101,21 @@ static const struct usb_device_id id_table[] = {
103 { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */ 101 { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */
104 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 102 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
105 { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */ 103 { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */
106 { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */ 104 { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demonstration module */
107 { USB_DEVICE(0x10C4, 0x8293) }, /* Telegesys ETRX2USB */ 105 { USB_DEVICE(0x10C4, 0x8293) }, /* Telegesis ETRX2USB */
108 { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */ 106 { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */
109 { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */ 107 { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */
110 { USB_DEVICE(0x10C4, 0x8382) }, /* Cygnal Integrated Products, Inc. */ 108 { USB_DEVICE(0x10C4, 0x8382) }, /* Cygnal Integrated Products, Inc. */
111 { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */ 109 { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */
110 { USB_DEVICE(0x10C4, 0x83D8) }, /* DekTec DTA Plus VHF/UHF Booster/Attenuator */
112 { USB_DEVICE(0x10C4, 0x8411) }, /* Kyocera GPS Module */ 111 { USB_DEVICE(0x10C4, 0x8411) }, /* Kyocera GPS Module */
112 { USB_DEVICE(0x10C4, 0x8418) }, /* IRZ Automation Teleport SG-10 GSM/GPRS Modem */
113 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */ 113 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */
114 { USB_DEVICE(0x10C4, 0x8477) }, /* Balluff RFID */ 114 { USB_DEVICE(0x10C4, 0x8477) }, /* Balluff RFID */
115 { USB_DEVICE(0x10C4, 0x85EA) }, /* AC-Services IBUS-IF */
116 { USB_DEVICE(0x10C4, 0x85EB) }, /* AC-Services CIS-IBUS */
117 { USB_DEVICE(0x10C4, 0x8664) }, /* AC-Services CAN-IF */
118 { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */
115 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 119 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
116 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 120 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
117 { USB_DEVICE(0x10C4, 0xEA71) }, /* Infinity GPS-MIC-1 Radio Monophone */ 121 { USB_DEVICE(0x10C4, 0xEA71) }, /* Infinity GPS-MIC-1 Radio Monophone */
@@ -132,6 +136,7 @@ static const struct usb_device_id id_table[] = {
132 { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */ 136 { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */
133 { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */ 137 { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */
134 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ 138 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */
139 { USB_DEVICE(0x1BE3, 0x07A6) }, /* WAGO 750-923 USB Service Cable */
135 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */ 140 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
136 { } /* Terminating Entry */ 141 { } /* Terminating Entry */
137}; 142};
@@ -163,8 +168,7 @@ static struct usb_serial_driver cp210x_device = {
163 .tiocmget = cp210x_tiocmget, 168 .tiocmget = cp210x_tiocmget,
164 .tiocmset = cp210x_tiocmset, 169 .tiocmset = cp210x_tiocmset,
165 .attach = cp210x_startup, 170 .attach = cp210x_startup,
166 .dtr_rts = cp210x_dtr_rts, 171 .dtr_rts = cp210x_dtr_rts
167 .carrier_raised = cp210x_carrier_raised
168}; 172};
169 173
170/* Config request types */ 174/* Config request types */
@@ -697,14 +701,14 @@ static void cp210x_set_termios(struct tty_struct *tty,
697 701
698} 702}
699 703
700static int cp210x_tiocmset (struct tty_struct *tty, struct file *file, 704static int cp210x_tiocmset (struct tty_struct *tty,
701 unsigned int set, unsigned int clear) 705 unsigned int set, unsigned int clear)
702{ 706{
703 struct usb_serial_port *port = tty->driver_data; 707 struct usb_serial_port *port = tty->driver_data;
704 return cp210x_tiocmset_port(port, file, set, clear); 708 return cp210x_tiocmset_port(port, set, clear);
705} 709}
706 710
707static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *file, 711static int cp210x_tiocmset_port(struct usb_serial_port *port,
708 unsigned int set, unsigned int clear) 712 unsigned int set, unsigned int clear)
709{ 713{
710 unsigned int control = 0; 714 unsigned int control = 0;
@@ -736,12 +740,12 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *file,
736static void cp210x_dtr_rts(struct usb_serial_port *p, int on) 740static void cp210x_dtr_rts(struct usb_serial_port *p, int on)
737{ 741{
738 if (on) 742 if (on)
739 cp210x_tiocmset_port(p, NULL, TIOCM_DTR|TIOCM_RTS, 0); 743 cp210x_tiocmset_port(p, TIOCM_DTR|TIOCM_RTS, 0);
740 else 744 else
741 cp210x_tiocmset_port(p, NULL, 0, TIOCM_DTR|TIOCM_RTS); 745 cp210x_tiocmset_port(p, 0, TIOCM_DTR|TIOCM_RTS);
742} 746}
743 747
744static int cp210x_tiocmget (struct tty_struct *tty, struct file *file) 748static int cp210x_tiocmget (struct tty_struct *tty)
745{ 749{
746 struct usb_serial_port *port = tty->driver_data; 750 struct usb_serial_port *port = tty->driver_data;
747 unsigned int control; 751 unsigned int control;
@@ -763,15 +767,6 @@ static int cp210x_tiocmget (struct tty_struct *tty, struct file *file)
763 return result; 767 return result;
764} 768}
765 769
766static int cp210x_carrier_raised(struct usb_serial_port *p)
767{
768 unsigned int control;
769 cp210x_get_config(p, CP210X_GET_MDMSTS, &control, 1);
770 if (control & CONTROL_DCD)
771 return 1;
772 return 0;
773}
774
775static void cp210x_break_ctl (struct tty_struct *tty, int break_state) 770static void cp210x_break_ctl (struct tty_struct *tty, int break_state)
776{ 771{
777 struct usb_serial_port *port = tty->driver_data; 772 struct usb_serial_port *port = tty->driver_data;
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index f5d06746cc3b..d9906eb9d16a 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -35,7 +35,7 @@
35 * 35 *
36 * Lonnie Mendez <dignome@gmail.com> 36 * Lonnie Mendez <dignome@gmail.com>
37 * 04-10-2004 37 * 04-10-2004
38 * Driver modified to support dynamic line settings. Various improvments 38 * Driver modified to support dynamic line settings. Various improvements
39 * and features. 39 * and features.
40 * 40 *
41 * Neil Whelchel 41 * Neil Whelchel
@@ -169,12 +169,12 @@ static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
169 const unsigned char *buf, int count); 169 const unsigned char *buf, int count);
170static void cypress_send(struct usb_serial_port *port); 170static void cypress_send(struct usb_serial_port *port);
171static int cypress_write_room(struct tty_struct *tty); 171static int cypress_write_room(struct tty_struct *tty);
172static int cypress_ioctl(struct tty_struct *tty, struct file *file, 172static int cypress_ioctl(struct tty_struct *tty,
173 unsigned int cmd, unsigned long arg); 173 unsigned int cmd, unsigned long arg);
174static void cypress_set_termios(struct tty_struct *tty, 174static void cypress_set_termios(struct tty_struct *tty,
175 struct usb_serial_port *port, struct ktermios *old); 175 struct usb_serial_port *port, struct ktermios *old);
176static int cypress_tiocmget(struct tty_struct *tty, struct file *file); 176static int cypress_tiocmget(struct tty_struct *tty);
177static int cypress_tiocmset(struct tty_struct *tty, struct file *file, 177static int cypress_tiocmset(struct tty_struct *tty,
178 unsigned int set, unsigned int clear); 178 unsigned int set, unsigned int clear);
179static int cypress_chars_in_buffer(struct tty_struct *tty); 179static int cypress_chars_in_buffer(struct tty_struct *tty);
180static void cypress_throttle(struct tty_struct *tty); 180static void cypress_throttle(struct tty_struct *tty);
@@ -864,7 +864,7 @@ static int cypress_write_room(struct tty_struct *tty)
864} 864}
865 865
866 866
867static int cypress_tiocmget(struct tty_struct *tty, struct file *file) 867static int cypress_tiocmget(struct tty_struct *tty)
868{ 868{
869 struct usb_serial_port *port = tty->driver_data; 869 struct usb_serial_port *port = tty->driver_data;
870 struct cypress_private *priv = usb_get_serial_port_data(port); 870 struct cypress_private *priv = usb_get_serial_port_data(port);
@@ -892,7 +892,7 @@ static int cypress_tiocmget(struct tty_struct *tty, struct file *file)
892} 892}
893 893
894 894
895static int cypress_tiocmset(struct tty_struct *tty, struct file *file, 895static int cypress_tiocmset(struct tty_struct *tty,
896 unsigned int set, unsigned int clear) 896 unsigned int set, unsigned int clear)
897{ 897{
898 struct usb_serial_port *port = tty->driver_data; 898 struct usb_serial_port *port = tty->driver_data;
@@ -917,7 +917,7 @@ static int cypress_tiocmset(struct tty_struct *tty, struct file *file,
917} 917}
918 918
919 919
920static int cypress_ioctl(struct tty_struct *tty, struct file *file, 920static int cypress_ioctl(struct tty_struct *tty,
921 unsigned int cmd, unsigned long arg) 921 unsigned int cmd, unsigned long arg)
922{ 922{
923 struct usb_serial_port *port = tty->driver_data; 923 struct usb_serial_port *port = tty->driver_data;
@@ -1320,8 +1320,6 @@ continue_read:
1320 cypress_set_dead(port); 1320 cypress_set_dead(port);
1321 } 1321 }
1322 } 1322 }
1323
1324 return;
1325} /* cypress_read_int_callback */ 1323} /* cypress_read_int_callback */
1326 1324
1327 1325
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index b92070c103cd..86fbba6336c9 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -445,17 +445,16 @@ static void digi_rx_unthrottle(struct tty_struct *tty);
445static void digi_set_termios(struct tty_struct *tty, 445static void digi_set_termios(struct tty_struct *tty,
446 struct usb_serial_port *port, struct ktermios *old_termios); 446 struct usb_serial_port *port, struct ktermios *old_termios);
447static void digi_break_ctl(struct tty_struct *tty, int break_state); 447static void digi_break_ctl(struct tty_struct *tty, int break_state);
448static int digi_tiocmget(struct tty_struct *tty, struct file *file); 448static int digi_tiocmget(struct tty_struct *tty);
449static int digi_tiocmset(struct tty_struct *tty, struct file *file, 449static int digi_tiocmset(struct tty_struct *tty, unsigned int set,
450 unsigned int set, unsigned int clear); 450 unsigned int clear);
451static int digi_write(struct tty_struct *tty, struct usb_serial_port *port, 451static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
452 const unsigned char *buf, int count); 452 const unsigned char *buf, int count);
453static void digi_write_bulk_callback(struct urb *urb); 453static void digi_write_bulk_callback(struct urb *urb);
454static int digi_write_room(struct tty_struct *tty); 454static int digi_write_room(struct tty_struct *tty);
455static int digi_chars_in_buffer(struct tty_struct *tty); 455static int digi_chars_in_buffer(struct tty_struct *tty);
456static int digi_open(struct tty_struct *tty, struct usb_serial_port *port); 456static int digi_open(struct tty_struct *tty, struct usb_serial_port *port);
457static void digi_close(struct usb_serial_port *port); 457static void digi_close(struct usb_serial_port *port);
458static int digi_carrier_raised(struct usb_serial_port *port);
459static void digi_dtr_rts(struct usb_serial_port *port, int on); 458static void digi_dtr_rts(struct usb_serial_port *port, int on);
460static int digi_startup_device(struct usb_serial *serial); 459static int digi_startup_device(struct usb_serial *serial);
461static int digi_startup(struct usb_serial *serial); 460static int digi_startup(struct usb_serial *serial);
@@ -511,7 +510,6 @@ static struct usb_serial_driver digi_acceleport_2_device = {
511 .open = digi_open, 510 .open = digi_open,
512 .close = digi_close, 511 .close = digi_close,
513 .dtr_rts = digi_dtr_rts, 512 .dtr_rts = digi_dtr_rts,
514 .carrier_raised = digi_carrier_raised,
515 .write = digi_write, 513 .write = digi_write,
516 .write_room = digi_write_room, 514 .write_room = digi_write_room,
517 .write_bulk_callback = digi_write_bulk_callback, 515 .write_bulk_callback = digi_write_bulk_callback,
@@ -1120,7 +1118,7 @@ static void digi_break_ctl(struct tty_struct *tty, int break_state)
1120} 1118}
1121 1119
1122 1120
1123static int digi_tiocmget(struct tty_struct *tty, struct file *file) 1121static int digi_tiocmget(struct tty_struct *tty)
1124{ 1122{
1125 struct usb_serial_port *port = tty->driver_data; 1123 struct usb_serial_port *port = tty->driver_data;
1126 struct digi_port *priv = usb_get_serial_port_data(port); 1124 struct digi_port *priv = usb_get_serial_port_data(port);
@@ -1136,8 +1134,8 @@ static int digi_tiocmget(struct tty_struct *tty, struct file *file)
1136} 1134}
1137 1135
1138 1136
1139static int digi_tiocmset(struct tty_struct *tty, struct file *file, 1137static int digi_tiocmset(struct tty_struct *tty,
1140 unsigned int set, unsigned int clear) 1138 unsigned int set, unsigned int clear)
1141{ 1139{
1142 struct usb_serial_port *port = tty->driver_data; 1140 struct usb_serial_port *port = tty->driver_data;
1143 struct digi_port *priv = usb_get_serial_port_data(port); 1141 struct digi_port *priv = usb_get_serial_port_data(port);
@@ -1339,14 +1337,6 @@ static void digi_dtr_rts(struct usb_serial_port *port, int on)
1339 digi_set_modem_signals(port, on * (TIOCM_DTR|TIOCM_RTS), 1); 1337 digi_set_modem_signals(port, on * (TIOCM_DTR|TIOCM_RTS), 1);
1340} 1338}
1341 1339
1342static int digi_carrier_raised(struct usb_serial_port *port)
1343{
1344 struct digi_port *priv = usb_get_serial_port_data(port);
1345 if (priv->dp_modem_signals & TIOCM_CD)
1346 return 1;
1347 return 0;
1348}
1349
1350static int digi_open(struct tty_struct *tty, struct usb_serial_port *port) 1340static int digi_open(struct tty_struct *tty, struct usb_serial_port *port)
1351{ 1341{
1352 int ret; 1342 int ret;
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 97cc87d654ce..2e06b90aa1f8 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -17,7 +17,7 @@
17 * See Documentation/usb/usb-serial.txt for more information on using this 17 * See Documentation/usb/usb-serial.txt for more information on using this
18 * driver 18 * driver
19 * 19 *
20 * See http://ftdi-usb-sio.sourceforge.net for upto date testing info 20 * See http://ftdi-usb-sio.sourceforge.net for up to date testing info
21 * and extra documentation 21 * and extra documentation
22 * 22 *
23 * Change entries from 2004 and earlier can be found in versions of this 23 * Change entries from 2004 and earlier can be found in versions of this
@@ -75,6 +75,7 @@ struct ftdi_private {
75 unsigned long last_dtr_rts; /* saved modem control outputs */ 75 unsigned long last_dtr_rts; /* saved modem control outputs */
76 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ 76 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
77 char prev_status, diff_status; /* Used for TIOCMIWAIT */ 77 char prev_status, diff_status; /* Used for TIOCMIWAIT */
78 char transmit_empty; /* If transmitter is empty or not */
78 struct usb_serial_port *port; 79 struct usb_serial_port *port;
79 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface 80 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface
80 (0 for FT232/245) */ 81 (0 for FT232/245) */
@@ -99,6 +100,7 @@ struct ftdi_sio_quirk {
99static int ftdi_jtag_probe(struct usb_serial *serial); 100static int ftdi_jtag_probe(struct usb_serial *serial);
100static int ftdi_mtxorb_hack_setup(struct usb_serial *serial); 101static int ftdi_mtxorb_hack_setup(struct usb_serial *serial);
101static int ftdi_NDI_device_setup(struct usb_serial *serial); 102static int ftdi_NDI_device_setup(struct usb_serial *serial);
103static int ftdi_stmclite_probe(struct usb_serial *serial);
102static void ftdi_USB_UIRT_setup(struct ftdi_private *priv); 104static void ftdi_USB_UIRT_setup(struct ftdi_private *priv);
103static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv); 105static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
104 106
@@ -122,6 +124,10 @@ static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
122 .port_probe = ftdi_HE_TIRA1_setup, 124 .port_probe = ftdi_HE_TIRA1_setup,
123}; 125};
124 126
127static struct ftdi_sio_quirk ftdi_stmclite_quirk = {
128 .probe = ftdi_stmclite_probe,
129};
130
125/* 131/*
126 * The 8U232AM has the same API as the sio except for: 132 * The 8U232AM has the same API as the sio except for:
127 * - it can support MUCH higher baudrates; up to: 133 * - it can support MUCH higher baudrates; up to:
@@ -145,6 +151,8 @@ static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
145 * /sys/bus/usb/ftdi_sio/new_id, then send patch/report! 151 * /sys/bus/usb/ftdi_sio/new_id, then send patch/report!
146 */ 152 */
147static struct usb_device_id id_table_combined [] = { 153static struct usb_device_id id_table_combined [] = {
154 { USB_DEVICE(FTDI_VID, FTDI_CTI_MINI_PID) },
155 { USB_DEVICE(FTDI_VID, FTDI_CTI_NANO_PID) },
148 { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) }, 156 { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) },
149 { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) }, 157 { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) },
150 { USB_DEVICE(FTDI_VID, FTDI_CANDAPTER_PID) }, 158 { USB_DEVICE(FTDI_VID, FTDI_CANDAPTER_PID) },
@@ -171,12 +179,14 @@ static struct usb_device_id id_table_combined [] = {
171 { USB_DEVICE(FTDI_VID, FTDI_232RL_PID) }, 179 { USB_DEVICE(FTDI_VID, FTDI_232RL_PID) },
172 { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) }, 180 { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) },
173 { USB_DEVICE(FTDI_VID, FTDI_4232H_PID) }, 181 { USB_DEVICE(FTDI_VID, FTDI_4232H_PID) },
182 { USB_DEVICE(FTDI_VID, FTDI_232H_PID) },
174 { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) }, 183 { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) },
175 { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, 184 { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) },
176 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) }, 185 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) },
177 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_SNIFFER_PID) }, 186 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_SNIFFER_PID) },
178 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_THROTTLE_PID) }, 187 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_THROTTLE_PID) },
179 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GATEWAY_PID) }, 188 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GATEWAY_PID) },
189 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GBM_PID) },
180 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) }, 190 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
181 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) }, 191 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
182 { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) }, 192 { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) },
@@ -200,6 +210,7 @@ static struct usb_device_id id_table_combined [] = {
200 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) }, 210 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) },
201 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) }, 211 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
202 { USB_DEVICE(FTDI_VID, FTDI_R2000KU_TRUE_RNG) }, 212 { USB_DEVICE(FTDI_VID, FTDI_R2000KU_TRUE_RNG) },
213 { USB_DEVICE(FTDI_VID, FTDI_VARDAAN_PID) },
203 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0100_PID) }, 214 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0100_PID) },
204 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0101_PID) }, 215 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0101_PID) },
205 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0102_PID) }, 216 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_0102_PID) },
@@ -517,6 +528,7 @@ static struct usb_device_id id_table_combined [] = {
517 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) }, 528 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) },
518 { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) }, 529 { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) },
519 { USB_DEVICE(OCT_VID, OCT_US101_PID) }, 530 { USB_DEVICE(OCT_VID, OCT_US101_PID) },
531 { USB_DEVICE(OCT_VID, OCT_DK201_PID) },
520 { USB_DEVICE(FTDI_VID, FTDI_HE_TIRA1_PID), 532 { USB_DEVICE(FTDI_VID, FTDI_HE_TIRA1_PID),
521 .driver_info = (kernel_ulong_t)&ftdi_HE_TIRA1_quirk }, 533 .driver_info = (kernel_ulong_t)&ftdi_HE_TIRA1_quirk },
522 { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID), 534 { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID),
@@ -555,6 +567,7 @@ static struct usb_device_id id_table_combined [] = {
555 { USB_DEVICE(FTDI_VID, FTDI_IBS_APP70_PID) }, 567 { USB_DEVICE(FTDI_VID, FTDI_IBS_APP70_PID) },
556 { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) }, 568 { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) },
557 { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) }, 569 { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) },
570 { USB_DEVICE(FTDI_VID, FTDI_TAVIR_STK500_PID) },
558 /* 571 /*
559 * ELV devices: 572 * ELV devices:
560 */ 573 */
@@ -613,6 +626,7 @@ static struct usb_device_id id_table_combined [] = {
613 { USB_DEVICE(FTDI_VID, FTDI_OCEANIC_PID) }, 626 { USB_DEVICE(FTDI_VID, FTDI_OCEANIC_PID) },
614 { USB_DEVICE(TTI_VID, TTI_QL355P_PID) }, 627 { USB_DEVICE(TTI_VID, TTI_QL355P_PID) },
615 { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) }, 628 { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) },
629 { USB_DEVICE(ACTON_VID, ACTON_SPECTRAPRO_PID) },
616 { USB_DEVICE(CONTEC_VID, CONTEC_COM1USBH_PID) }, 630 { USB_DEVICE(CONTEC_VID, CONTEC_COM1USBH_PID) },
617 { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) }, 631 { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) },
618 { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) }, 632 { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) },
@@ -634,6 +648,7 @@ static struct usb_device_id id_table_combined [] = {
634 { USB_DEVICE(FTDI_VID, EVER_ECO_PRO_CDS) }, 648 { USB_DEVICE(FTDI_VID, EVER_ECO_PRO_CDS) },
635 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) }, 649 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) },
636 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) }, 650 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) },
651 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_3_PID) },
637 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_0_PID) }, 652 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_0_PID) },
638 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_1_PID) }, 653 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_1_PID) },
639 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_2_PID) }, 654 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_2_PID) },
@@ -673,8 +688,17 @@ static struct usb_device_id id_table_combined [] = {
673 { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) }, 688 { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) },
674 { USB_DEVICE(FTDI_VID, FTDI_RRCIRKITS_LOCOBUFFER_PID) }, 689 { USB_DEVICE(FTDI_VID, FTDI_RRCIRKITS_LOCOBUFFER_PID) },
675 { USB_DEVICE(FTDI_VID, FTDI_ASK_RDR400_PID) }, 690 { USB_DEVICE(FTDI_VID, FTDI_ASK_RDR400_PID) },
676 { USB_DEVICE(ICOM_ID1_VID, ICOM_ID1_PID) }, 691 { USB_DEVICE(ICOM_VID, ICOM_ID_1_PID) },
677 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_TMU_PID) }, 692 { USB_DEVICE(ICOM_VID, ICOM_OPC_U_UC_PID) },
693 { USB_DEVICE(ICOM_VID, ICOM_ID_RP2C1_PID) },
694 { USB_DEVICE(ICOM_VID, ICOM_ID_RP2C2_PID) },
695 { USB_DEVICE(ICOM_VID, ICOM_ID_RP2D_PID) },
696 { USB_DEVICE(ICOM_VID, ICOM_ID_RP2VT_PID) },
697 { USB_DEVICE(ICOM_VID, ICOM_ID_RP2VR_PID) },
698 { USB_DEVICE(ICOM_VID, ICOM_ID_RP4KVT_PID) },
699 { USB_DEVICE(ICOM_VID, ICOM_ID_RP4KVR_PID) },
700 { USB_DEVICE(ICOM_VID, ICOM_ID_RP2KVT_PID) },
701 { USB_DEVICE(ICOM_VID, ICOM_ID_RP2KVR_PID) },
678 { USB_DEVICE(FTDI_VID, FTDI_ACG_HFDUAL_PID) }, 702 { USB_DEVICE(FTDI_VID, FTDI_ACG_HFDUAL_PID) },
679 { USB_DEVICE(FTDI_VID, FTDI_YEI_SERVOCENTER31_PID) }, 703 { USB_DEVICE(FTDI_VID, FTDI_YEI_SERVOCENTER31_PID) },
680 { USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) }, 704 { USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) },
@@ -696,6 +720,7 @@ static struct usb_device_id id_table_combined [] = {
696 .driver_info = (kernel_ulong_t)&ftdi_NDI_device_quirk }, 720 .driver_info = (kernel_ulong_t)&ftdi_NDI_device_quirk },
697 { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) }, 721 { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) },
698 { USB_DEVICE(RTSYSTEMS_VID, RTSYSTEMS_SERIAL_VX7_PID) }, 722 { USB_DEVICE(RTSYSTEMS_VID, RTSYSTEMS_SERIAL_VX7_PID) },
723 { USB_DEVICE(RTSYSTEMS_VID, RTSYSTEMS_CT29B_PID) },
699 { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) }, 724 { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) },
700 { USB_DEVICE(FTDI_VID, FTDI_PHI_FISCO_PID) }, 725 { USB_DEVICE(FTDI_VID, FTDI_PHI_FISCO_PID) },
701 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) }, 726 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) },
@@ -703,6 +728,8 @@ static struct usb_device_id id_table_combined [] = {
703 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) }, 728 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) },
704 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID), 729 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID),
705 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 730 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
731 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_H_PID),
732 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
706 { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID), 733 { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID),
707 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 734 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
708 { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID), 735 { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID),
@@ -715,8 +742,37 @@ static struct usb_device_id id_table_combined [] = {
715 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 742 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
716 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) }, 743 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) },
717 { USB_DEVICE(FTDI_VID, FTDI_REU_TINY_PID) }, 744 { USB_DEVICE(FTDI_VID, FTDI_REU_TINY_PID) },
745
746 /* Papouch devices based on FTDI chip */
747 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_SB485_PID) },
748 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_AP485_PID) },
749 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_SB422_PID) },
750 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_SB485_2_PID) },
751 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_AP485_2_PID) },
752 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_SB422_2_PID) },
753 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_SB485S_PID) },
754 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_SB485C_PID) },
755 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_LEC_PID) },
756 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_SB232_PID) },
757 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_TMU_PID) },
758 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_IRAMP_PID) },
759 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_DRAK5_PID) },
760 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO8x8_PID) },
718 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO4x4_PID) }, 761 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO4x4_PID) },
762 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO2x2_PID) },
763 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO10x1_PID) },
764 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO30x3_PID) },
765 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO60x3_PID) },
766 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO2x16_PID) },
767 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO3x32_PID) },
768 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_DRAK6_PID) },
769 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_UPSUSB_PID) },
770 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_MU_PID) },
771 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_SIMUKEY_PID) },
719 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_AD4USB_PID) }, 772 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_AD4USB_PID) },
773 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_GMUX_PID) },
774 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_GMSR_PID) },
775
720 { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DGQG_PID) }, 776 { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DGQG_PID) },
721 { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DUSB_PID) }, 777 { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DUSB_PID) },
722 { USB_DEVICE(ALTI2_VID, ALTI2_N3_PID) }, 778 { USB_DEVICE(ALTI2_VID, ALTI2_N3_PID) },
@@ -737,6 +793,8 @@ static struct usb_device_id id_table_combined [] = {
737 { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID), 793 { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID),
738 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 794 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
739 { USB_DEVICE(FTDI_VID, HAMEG_HO820_PID) }, 795 { USB_DEVICE(FTDI_VID, HAMEG_HO820_PID) },
796 { USB_DEVICE(FTDI_VID, HAMEG_HO720_PID) },
797 { USB_DEVICE(FTDI_VID, HAMEG_HO730_PID) },
740 { USB_DEVICE(FTDI_VID, HAMEG_HO870_PID) }, 798 { USB_DEVICE(FTDI_VID, HAMEG_HO870_PID) },
741 { USB_DEVICE(FTDI_VID, MJSG_GENERIC_PID) }, 799 { USB_DEVICE(FTDI_VID, MJSG_GENERIC_PID) },
742 { USB_DEVICE(FTDI_VID, MJSG_SR_RADIO_PID) }, 800 { USB_DEVICE(FTDI_VID, MJSG_SR_RADIO_PID) },
@@ -751,6 +809,7 @@ static struct usb_device_id id_table_combined [] = {
751 { USB_DEVICE(FTDI_VID, XVERVE_SIGNALYZER_SH4_PID), 809 { USB_DEVICE(FTDI_VID, XVERVE_SIGNALYZER_SH4_PID),
752 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 810 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
753 { USB_DEVICE(FTDI_VID, SEGWAY_RMP200_PID) }, 811 { USB_DEVICE(FTDI_VID, SEGWAY_RMP200_PID) },
812 { USB_DEVICE(FTDI_VID, ACCESIO_COM4SM_PID) },
754 { USB_DEVICE(IONICS_VID, IONICS_PLUGCOMPUTER_PID), 813 { USB_DEVICE(IONICS_VID, IONICS_PLUGCOMPUTER_PID),
755 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 814 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
756 { USB_DEVICE(FTDI_VID, FTDI_CHAMSYS_24_MASTER_WING_PID) }, 815 { USB_DEVICE(FTDI_VID, FTDI_CHAMSYS_24_MASTER_WING_PID) },
@@ -761,6 +820,14 @@ static struct usb_device_id id_table_combined [] = {
761 { USB_DEVICE(FTDI_VID, FTDI_CHAMSYS_MAXI_WING_PID) }, 820 { USB_DEVICE(FTDI_VID, FTDI_CHAMSYS_MAXI_WING_PID) },
762 { USB_DEVICE(FTDI_VID, FTDI_CHAMSYS_MEDIA_WING_PID) }, 821 { USB_DEVICE(FTDI_VID, FTDI_CHAMSYS_MEDIA_WING_PID) },
763 { USB_DEVICE(FTDI_VID, FTDI_CHAMSYS_WING_PID) }, 822 { USB_DEVICE(FTDI_VID, FTDI_CHAMSYS_WING_PID) },
823 { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_LOGBOOKML_PID) },
824 { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_LS_LOGBOOK_PID) },
825 { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_HS_LOGBOOK_PID) },
826 { USB_DEVICE(FTDI_VID, FTDI_DOTEC_PID) },
827 { USB_DEVICE(QIHARDWARE_VID, MILKYMISTONE_JTAGSERIAL_PID),
828 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
829 { USB_DEVICE(ST_VID, ST_STMCLT1030_PID),
830 .driver_info = (kernel_ulong_t)&ftdi_stmclite_quirk },
764 { }, /* Optional parameter entry */ 831 { }, /* Optional parameter entry */
765 { } /* Terminating entry */ 832 { } /* Terminating entry */
766}; 833};
@@ -782,7 +849,8 @@ static const char *ftdi_chip_name[] = {
782 [FT2232C] = "FT2232C", 849 [FT2232C] = "FT2232C",
783 [FT232RL] = "FT232RL", 850 [FT232RL] = "FT232RL",
784 [FT2232H] = "FT2232H", 851 [FT2232H] = "FT2232H",
785 [FT4232H] = "FT4232H" 852 [FT4232H] = "FT4232H",
853 [FT232H] = "FT232H"
786}; 854};
787 855
788 856
@@ -807,10 +875,10 @@ static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
807 void *dest, size_t size); 875 void *dest, size_t size);
808static void ftdi_set_termios(struct tty_struct *tty, 876static void ftdi_set_termios(struct tty_struct *tty,
809 struct usb_serial_port *port, struct ktermios *old); 877 struct usb_serial_port *port, struct ktermios *old);
810static int ftdi_tiocmget(struct tty_struct *tty, struct file *file); 878static int ftdi_tiocmget(struct tty_struct *tty);
811static int ftdi_tiocmset(struct tty_struct *tty, struct file *file, 879static int ftdi_tiocmset(struct tty_struct *tty,
812 unsigned int set, unsigned int clear); 880 unsigned int set, unsigned int clear);
813static int ftdi_ioctl(struct tty_struct *tty, struct file *file, 881static int ftdi_ioctl(struct tty_struct *tty,
814 unsigned int cmd, unsigned long arg); 882 unsigned int cmd, unsigned long arg);
815static void ftdi_break_ctl(struct tty_struct *tty, int break_state); 883static void ftdi_break_ctl(struct tty_struct *tty, int break_state);
816 884
@@ -916,7 +984,7 @@ static __u32 ftdi_2232h_baud_base_to_divisor(int baud, int base)
916 int divisor3; 984 int divisor3;
917 985
918 /* hi-speed baud rate is 10-bit sampling instead of 16-bit */ 986 /* hi-speed baud rate is 10-bit sampling instead of 16-bit */
919 divisor3 = (base / 10 / baud) * 8; 987 divisor3 = base * 8 / (baud * 10);
920 988
921 divisor = divisor3 >> 3; 989 divisor = divisor3 >> 3;
922 divisor |= (__u32)divfrac[divisor3 & 0x7] << 14; 990 divisor |= (__u32)divfrac[divisor3 & 0x7] << 14;
@@ -1102,6 +1170,7 @@ static __u32 get_ftdi_divisor(struct tty_struct *tty,
1102 break; 1170 break;
1103 case FT2232H: /* FT2232H chip */ 1171 case FT2232H: /* FT2232H chip */
1104 case FT4232H: /* FT4232H chip */ 1172 case FT4232H: /* FT4232H chip */
1173 case FT232H: /* FT232H chip */
1105 if ((baud <= 12000000) & (baud >= 1200)) { 1174 if ((baud <= 12000000) & (baud >= 1200)) {
1106 div_value = ftdi_2232h_baud_to_divisor(baud); 1175 div_value = ftdi_2232h_baud_to_divisor(baud);
1107 } else if (baud < 1200) { 1176 } else if (baud < 1200) {
@@ -1285,6 +1354,23 @@ check_and_exit:
1285 return 0; 1354 return 0;
1286} 1355}
1287 1356
1357static int get_lsr_info(struct usb_serial_port *port,
1358 struct serial_struct __user *retinfo)
1359{
1360 struct ftdi_private *priv = usb_get_serial_port_data(port);
1361 unsigned int result = 0;
1362
1363 if (!retinfo)
1364 return -EFAULT;
1365
1366 if (priv->transmit_empty)
1367 result = TIOCSER_TEMT;
1368
1369 if (copy_to_user(retinfo, &result, sizeof(unsigned int)))
1370 return -EFAULT;
1371 return 0;
1372}
1373
1288 1374
1289/* Determine type of FTDI chip based on USB config and descriptor. */ 1375/* Determine type of FTDI chip based on USB config and descriptor. */
1290static void ftdi_determine_type(struct usb_serial_port *port) 1376static void ftdi_determine_type(struct usb_serial_port *port)
@@ -1346,9 +1432,12 @@ static void ftdi_determine_type(struct usb_serial_port *port)
1346 } else if (version < 0x600) { 1432 } else if (version < 0x600) {
1347 /* Assume it's an FT232BM (or FT245BM) */ 1433 /* Assume it's an FT232BM (or FT245BM) */
1348 priv->chip_type = FT232BM; 1434 priv->chip_type = FT232BM;
1349 } else { 1435 } else if (version < 0x900) {
1350 /* Assume it's an FT232R */ 1436 /* Assume it's an FT232RL */
1351 priv->chip_type = FT232RL; 1437 priv->chip_type = FT232RL;
1438 } else {
1439 /* Assume it's an FT232H */
1440 priv->chip_type = FT232H;
1352 } 1441 }
1353 dev_info(&udev->dev, "Detected %s\n", ftdi_chip_name[priv->chip_type]); 1442 dev_info(&udev->dev, "Detected %s\n", ftdi_chip_name[priv->chip_type]);
1354} 1443}
@@ -1476,7 +1565,8 @@ static int create_sysfs_attrs(struct usb_serial_port *port)
1476 priv->chip_type == FT2232C || 1565 priv->chip_type == FT2232C ||
1477 priv->chip_type == FT232RL || 1566 priv->chip_type == FT232RL ||
1478 priv->chip_type == FT2232H || 1567 priv->chip_type == FT2232H ||
1479 priv->chip_type == FT4232H)) { 1568 priv->chip_type == FT4232H ||
1569 priv->chip_type == FT232H)) {
1480 retval = device_create_file(&port->dev, 1570 retval = device_create_file(&port->dev,
1481 &dev_attr_latency_timer); 1571 &dev_attr_latency_timer);
1482 } 1572 }
@@ -1497,7 +1587,8 @@ static void remove_sysfs_attrs(struct usb_serial_port *port)
1497 priv->chip_type == FT2232C || 1587 priv->chip_type == FT2232C ||
1498 priv->chip_type == FT232RL || 1588 priv->chip_type == FT232RL ||
1499 priv->chip_type == FT2232H || 1589 priv->chip_type == FT2232H ||
1500 priv->chip_type == FT4232H) { 1590 priv->chip_type == FT4232H ||
1591 priv->chip_type == FT232H) {
1501 device_remove_file(&port->dev, &dev_attr_latency_timer); 1592 device_remove_file(&port->dev, &dev_attr_latency_timer);
1502 } 1593 }
1503 } 1594 }
@@ -1559,6 +1650,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1559 ftdi_set_max_packet_size(port); 1650 ftdi_set_max_packet_size(port);
1560 if (read_latency_timer(port) < 0) 1651 if (read_latency_timer(port) < 0)
1561 priv->latency = 16; 1652 priv->latency = 16;
1653 write_latency_timer(port);
1562 create_sysfs_attrs(port); 1654 create_sysfs_attrs(port);
1563 return 0; 1655 return 0;
1564} 1656}
@@ -1642,6 +1734,25 @@ static int ftdi_jtag_probe(struct usb_serial *serial)
1642} 1734}
1643 1735
1644/* 1736/*
1737 * First and second port on STMCLiteadaptors is reserved for JTAG interface
1738 * and the forth port for pio
1739 */
1740static int ftdi_stmclite_probe(struct usb_serial *serial)
1741{
1742 struct usb_device *udev = serial->dev;
1743 struct usb_interface *interface = serial->interface;
1744
1745 dbg("%s", __func__);
1746
1747 if (interface == udev->actconfig->interface[2])
1748 return 0;
1749
1750 dev_info(&udev->dev, "Ignoring serial port reserved for JTAG\n");
1751
1752 return -ENODEV;
1753}
1754
1755/*
1645 * The Matrix Orbital VK204-25-USB has an invalid IN endpoint. 1756 * The Matrix Orbital VK204-25-USB has an invalid IN endpoint.
1646 * We have to correct it if we want to read from it. 1757 * We have to correct it if we want to read from it.
1647 */ 1758 */
@@ -1687,8 +1798,6 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1687 1798
1688 dbg("%s", __func__); 1799 dbg("%s", __func__);
1689 1800
1690 write_latency_timer(port);
1691
1692 /* No error checking for this (will get errors later anyway) */ 1801 /* No error checking for this (will get errors later anyway) */
1693 /* See ftdi_sio.h for description of what is reset */ 1802 /* See ftdi_sio.h for description of what is reset */
1694 usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1803 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
@@ -1835,6 +1944,12 @@ static int ftdi_process_packet(struct tty_struct *tty,
1835 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 1944 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1836 } 1945 }
1837 1946
1947 /* save if the transmitter is empty or not */
1948 if (packet[1] & FTDI_RS_TEMT)
1949 priv->transmit_empty = 1;
1950 else
1951 priv->transmit_empty = 0;
1952
1838 len -= 2; 1953 len -= 2;
1839 if (!len) 1954 if (!len)
1840 return 0; /* status only */ 1955 return 0; /* status only */
@@ -2028,8 +2143,6 @@ static void ftdi_set_termios(struct tty_struct *tty,
2028 "urb failed to set to rts/cts flow control\n"); 2143 "urb failed to set to rts/cts flow control\n");
2029 } 2144 }
2030 2145
2031 /* raise DTR/RTS */
2032 set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2033 } else { 2146 } else {
2034 /* 2147 /*
2035 * Xon/Xoff code 2148 * Xon/Xoff code
@@ -2077,13 +2190,10 @@ static void ftdi_set_termios(struct tty_struct *tty,
2077 } 2190 }
2078 } 2191 }
2079 2192
2080 /* lower DTR/RTS */
2081 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2082 } 2193 }
2083 return;
2084} 2194}
2085 2195
2086static int ftdi_tiocmget(struct tty_struct *tty, struct file *file) 2196static int ftdi_tiocmget(struct tty_struct *tty)
2087{ 2197{
2088 struct usb_serial_port *port = tty->driver_data; 2198 struct usb_serial_port *port = tty->driver_data;
2089 struct ftdi_private *priv = usb_get_serial_port_data(port); 2199 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -2110,6 +2220,7 @@ static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
2110 case FT232RL: 2220 case FT232RL:
2111 case FT2232H: 2221 case FT2232H:
2112 case FT4232H: 2222 case FT4232H:
2223 case FT232H:
2113 len = 2; 2224 len = 2;
2114 break; 2225 break;
2115 default: 2226 default:
@@ -2136,7 +2247,7 @@ out:
2136 return ret; 2247 return ret;
2137} 2248}
2138 2249
2139static int ftdi_tiocmset(struct tty_struct *tty, struct file *file, 2250static int ftdi_tiocmset(struct tty_struct *tty,
2140 unsigned int set, unsigned int clear) 2251 unsigned int set, unsigned int clear)
2141{ 2252{
2142 struct usb_serial_port *port = tty->driver_data; 2253 struct usb_serial_port *port = tty->driver_data;
@@ -2144,7 +2255,7 @@ static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
2144 return update_mctrl(port, set, clear); 2255 return update_mctrl(port, set, clear);
2145} 2256}
2146 2257
2147static int ftdi_ioctl(struct tty_struct *tty, struct file *file, 2258static int ftdi_ioctl(struct tty_struct *tty,
2148 unsigned int cmd, unsigned long arg) 2259 unsigned int cmd, unsigned long arg)
2149{ 2260{
2150 struct usb_serial_port *port = tty->driver_data; 2261 struct usb_serial_port *port = tty->driver_data;
@@ -2168,6 +2279,7 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2168 * - mask passed in arg for lines of interest 2279 * - mask passed in arg for lines of interest
2169 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 2280 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
2170 * Caller should use TIOCGICOUNT to see which one it was. 2281 * Caller should use TIOCGICOUNT to see which one it was.
2282 * (except that the driver doesn't support it !)
2171 * 2283 *
2172 * This code is borrowed from linux/drivers/char/serial.c 2284 * This code is borrowed from linux/drivers/char/serial.c
2173 */ 2285 */
@@ -2202,6 +2314,9 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2202 } 2314 }
2203 } 2315 }
2204 return 0; 2316 return 0;
2317 case TIOCSERGETLSR:
2318 return get_lsr_info(port, (struct serial_struct __user *)arg);
2319 break;
2205 default: 2320 default:
2206 break; 2321 break;
2207 } 2322 }
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 213fe3d61282..19584faa86f9 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -156,7 +156,8 @@ enum ftdi_chip_type {
156 FT2232C = 4, 156 FT2232C = 4,
157 FT232RL = 5, 157 FT232RL = 5,
158 FT2232H = 6, 158 FT2232H = 6,
159 FT4232H = 7 159 FT4232H = 7,
160 FT232H = 8
160}; 161};
161 162
162enum ftdi_sio_baudrate { 163enum ftdi_sio_baudrate {
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 15a4583775ad..19156d1049fe 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -22,6 +22,7 @@
22#define FTDI_8U232AM_ALT_PID 0x6006 /* FTDI's alternate PID for above */ 22#define FTDI_8U232AM_ALT_PID 0x6006 /* FTDI's alternate PID for above */
23#define FTDI_8U2232C_PID 0x6010 /* Dual channel device */ 23#define FTDI_8U2232C_PID 0x6010 /* Dual channel device */
24#define FTDI_4232H_PID 0x6011 /* Quad channel hi-speed device */ 24#define FTDI_4232H_PID 0x6011 /* Quad channel hi-speed device */
25#define FTDI_232H_PID 0x6014 /* Single channel hi-speed device */
25#define FTDI_SIO_PID 0x8372 /* Product Id SIO application of 8U100AX */ 26#define FTDI_SIO_PID 0x8372 /* Product Id SIO application of 8U100AX */
26#define FTDI_232RL_PID 0xFBFA /* Product ID for FT232RL */ 27#define FTDI_232RL_PID 0xFBFA /* Product ID for FT232RL */
27 28
@@ -46,7 +47,7 @@
46#define FTDI_USINT_RS232_PID 0xb812 /* Navigator RS232 and CONFIG lines */ 47#define FTDI_USINT_RS232_PID 0xb812 /* Navigator RS232 and CONFIG lines */
47 48
48/* OOCDlink by Joern Kaipf <joernk@web.de> 49/* OOCDlink by Joern Kaipf <joernk@web.de>
49 * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */ 50 * (http://www.joernonline.de/) */
50#define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */ 51#define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */
51 52
52/* Luminary Micro Stellaris Boards, VID = FTDI_VID */ 53/* Luminary Micro Stellaris Boards, VID = FTDI_VID */
@@ -61,6 +62,7 @@
61#define FTDI_OPENDCC_SNIFFER_PID 0xBFD9 62#define FTDI_OPENDCC_SNIFFER_PID 0xBFD9
62#define FTDI_OPENDCC_THROTTLE_PID 0xBFDA 63#define FTDI_OPENDCC_THROTTLE_PID 0xBFDA
63#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB 64#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB
65#define FTDI_OPENDCC_GBM_PID 0xBFDC
64 66
65/* 67/*
66 * RR-CirKits LocoBuffer USB (http://www.rr-cirkits.com) 68 * RR-CirKits LocoBuffer USB (http://www.rr-cirkits.com)
@@ -113,6 +115,9 @@
113/* Lenz LI-USB Computer Interface. */ 115/* Lenz LI-USB Computer Interface. */
114#define FTDI_LENZ_LIUSB_PID 0xD780 116#define FTDI_LENZ_LIUSB_PID 0xD780
115 117
118/* Vardaan Enterprises Serial Interface VEUSB422R3 */
119#define FTDI_VARDAAN_PID 0xF070
120
116/* 121/*
117 * Xsens Technologies BV products (http://www.xsens.com). 122 * Xsens Technologies BV products (http://www.xsens.com).
118 */ 123 */
@@ -296,6 +301,8 @@
296 * Hameg HO820 and HO870 interface (using VID 0x0403) 301 * Hameg HO820 and HO870 interface (using VID 0x0403)
297 */ 302 */
298#define HAMEG_HO820_PID 0xed74 303#define HAMEG_HO820_PID 0xed74
304#define HAMEG_HO730_PID 0xed73
305#define HAMEG_HO720_PID 0xed72
299#define HAMEG_HO870_PID 0xed71 306#define HAMEG_HO870_PID 0xed71
300 307
301/* 308/*
@@ -335,7 +342,7 @@
335#define FTDI_PIEGROUP_PID 0xF208 /* Product Id */ 342#define FTDI_PIEGROUP_PID 0xF208 /* Product Id */
336 343
337/* ACT Solutions HomePro ZWave interface 344/* ACT Solutions HomePro ZWave interface
338 (http://www.act-solutions.com/HomePro.htm) */ 345 (http://www.act-solutions.com/HomePro-Product-Matrix.html) */
339#define FTDI_ACTZWAVE_PID 0xF2D0 346#define FTDI_ACTZWAVE_PID 0xF2D0
340 347
341/* 348/*
@@ -345,6 +352,7 @@
345 */ 352 */
346#define FTDI_4N_GALAXY_DE_1_PID 0xF3C0 353#define FTDI_4N_GALAXY_DE_1_PID 0xF3C0
347#define FTDI_4N_GALAXY_DE_2_PID 0xF3C1 354#define FTDI_4N_GALAXY_DE_2_PID 0xF3C1
355#define FTDI_4N_GALAXY_DE_3_PID 0xF3C2
348 356
349/* 357/*
350 * Linx Technologies product ids 358 * Linx Technologies product ids
@@ -366,7 +374,7 @@
366#define FTDI_SUUNTO_SPORTS_PID 0xF680 /* Suunto Sports instrument */ 374#define FTDI_SUUNTO_SPORTS_PID 0xF680 /* Suunto Sports instrument */
367 375
368/* USB-UIRT - An infrared receiver and transmitter using the 8U232AM chip */ 376/* USB-UIRT - An infrared receiver and transmitter using the 8U232AM chip */
369/* http://home.earthlink.net/~jrhees/USBUIRT/index.htm */ 377/* http://www.usbuirt.com/ */
370#define FTDI_USB_UIRT_PID 0xF850 /* Product Id */ 378#define FTDI_USB_UIRT_PID 0xF850 /* Product Id */
371 379
372/* CCS Inc. ICDU/ICDU40 product ID - 380/* CCS Inc. ICDU/ICDU40 product ID -
@@ -395,7 +403,7 @@
395 */ 403 */
396#define FTDI_HE_TIRA1_PID 0xFA78 /* Tira-1 IR transceiver */ 404#define FTDI_HE_TIRA1_PID 0xFA78 /* Tira-1 IR transceiver */
397 405
398/* Inside Accesso contactless reader (http://www.insidefr.com) */ 406/* Inside Accesso contactless reader (http://www.insidecontactless.com/) */
399#define INSIDE_ACCESSO 0xFAD0 407#define INSIDE_ACCESSO 0xFAD0
400 408
401/* 409/*
@@ -485,6 +493,11 @@
485/* www.canusb.com Lawicel CANUSB device (FTDI_VID) */ 493/* www.canusb.com Lawicel CANUSB device (FTDI_VID) */
486#define FTDI_CANUSB_PID 0xFFA8 /* Product Id */ 494#define FTDI_CANUSB_PID 0xFFA8 /* Product Id */
487 495
496/*
497 * TavIR AVR product ids (FTDI_VID)
498 */
499#define FTDI_TAVIR_STK500_PID 0xFA33 /* STK500 AVR programmer */
500
488 501
489 502
490/********************************/ 503/********************************/
@@ -514,6 +527,12 @@
514#define RATOC_PRODUCT_ID_USB60F 0xb020 527#define RATOC_PRODUCT_ID_USB60F 0xb020
515 528
516/* 529/*
530 * Acton Research Corp.
531 */
532#define ACTON_VID 0x0647 /* Vendor ID */
533#define ACTON_SPECTRAPRO_PID 0x0100
534
535/*
517 * Contec products (http://www.contec.com) 536 * Contec products (http://www.contec.com)
518 * Submitted by Daniel Sangorrin 537 * Submitted by Daniel Sangorrin
519 */ 538 */
@@ -562,14 +581,27 @@
562/* Note: OCT US101 is also rebadged as Dick Smith Electronics (NZ) XH6381 */ 581/* Note: OCT US101 is also rebadged as Dick Smith Electronics (NZ) XH6381 */
563/* Also rebadged as Dick Smith Electronics (Aus) XH6451 */ 582/* Also rebadged as Dick Smith Electronics (Aus) XH6451 */
564/* Also rebadged as SIIG Inc. model US2308 hardware version 1 */ 583/* Also rebadged as SIIG Inc. model US2308 hardware version 1 */
584#define OCT_DK201_PID 0x0103 /* OCT DK201 USB docking station */
565#define OCT_US101_PID 0x0421 /* OCT US101 USB to RS-232 */ 585#define OCT_US101_PID 0x0421 /* OCT US101 USB to RS-232 */
566 586
567/* 587/*
568 * Icom ID-1 digital transceiver 588 * Definitions for Icom Inc. devices
569 */ 589 */
570 590#define ICOM_VID 0x0C26 /* Icom vendor ID */
571#define ICOM_ID1_VID 0x0C26 591/* Note: ID-1 is a communications tranceiver for HAM-radio operators */
572#define ICOM_ID1_PID 0x0004 592#define ICOM_ID_1_PID 0x0004 /* ID-1 USB to RS-232 */
593/* Note: OPC is an Optional cable to connect an Icom Tranceiver */
594#define ICOM_OPC_U_UC_PID 0x0018 /* OPC-478UC, OPC-1122U cloning cable */
595/* Note: ID-RP* devices are Icom Repeater Devices for HAM-radio */
596#define ICOM_ID_RP2C1_PID 0x0009 /* ID-RP2C Asset 1 to RS-232 */
597#define ICOM_ID_RP2C2_PID 0x000A /* ID-RP2C Asset 2 to RS-232 */
598#define ICOM_ID_RP2D_PID 0x000B /* ID-RP2D configuration port*/
599#define ICOM_ID_RP2VT_PID 0x000C /* ID-RP2V Transmit config port */
600#define ICOM_ID_RP2VR_PID 0x000D /* ID-RP2V Receive config port */
601#define ICOM_ID_RP4KVT_PID 0x0010 /* ID-RP4000V Transmit config port */
602#define ICOM_ID_RP4KVR_PID 0x0011 /* ID-RP4000V Receive config port */
603#define ICOM_ID_RP2KVT_PID 0x0012 /* ID-RP2000V Transmit config port */
604#define ICOM_ID_RP2KVR_PID 0x0013 /* ID-RP2000V Receive config port */
573 605
574/* 606/*
575 * GN Otometrics (http://www.otometrics.com) 607 * GN Otometrics (http://www.otometrics.com)
@@ -634,14 +666,14 @@
634 666
635/* 667/*
636 * JETI SPECTROMETER SPECBOS 1201 668 * JETI SPECTROMETER SPECBOS 1201
637 * http://www.jeti.com/products/sys/scb/scb1201.php 669 * http://www.jeti.com/cms/index.php/instruments/other-instruments/specbos-2101
638 */ 670 */
639#define JETI_VID 0x0c6c 671#define JETI_VID 0x0c6c
640#define JETI_SPC1201_PID 0x04b2 672#define JETI_SPC1201_PID 0x04b2
641 673
642/* 674/*
643 * FTDI USB UART chips used in construction projects from the 675 * FTDI USB UART chips used in construction projects from the
644 * Elektor Electronics magazine (http://elektor-electronics.co.uk) 676 * Elektor Electronics magazine (http://www.elektor.com/)
645 */ 677 */
646#define ELEKTOR_VID 0x0C7D 678#define ELEKTOR_VID 0x0C7D
647#define ELEKTOR_FT323R_PID 0x0005 /* RFID-Reader, issue 09-2006 */ 679#define ELEKTOR_FT323R_PID 0x0005 /* RFID-Reader, issue 09-2006 */
@@ -708,6 +740,7 @@
708/* Olimex */ 740/* Olimex */
709#define OLIMEX_VID 0x15BA 741#define OLIMEX_VID 0x15BA
710#define OLIMEX_ARM_USB_OCD_PID 0x0003 742#define OLIMEX_ARM_USB_OCD_PID 0x0003
743#define OLIMEX_ARM_USB_OCD_H_PID 0x002b
711 744
712/* 745/*
713 * Telldus Technologies 746 * Telldus Technologies
@@ -720,6 +753,7 @@
720 */ 753 */
721#define RTSYSTEMS_VID 0x2100 /* Vendor ID */ 754#define RTSYSTEMS_VID 0x2100 /* Vendor ID */
722#define RTSYSTEMS_SERIAL_VX7_PID 0x9e52 /* Serial converter for VX-7 Radios using FT232RL */ 755#define RTSYSTEMS_SERIAL_VX7_PID 0x9e52 /* Serial converter for VX-7 Radios using FT232RL */
756#define RTSYSTEMS_CT29B_PID 0x9e54 /* CT29B Radio Cable */
723 757
724/* 758/*
725 * Bayer Ascensia Contour blood glucose meter USB-converter cable. 759 * Bayer Ascensia Contour blood glucose meter USB-converter cable.
@@ -1017,14 +1051,45 @@
1017#define WHT_PID 0x0004 /* Wireless Handheld Terminal */ 1051#define WHT_PID 0x0004 /* Wireless Handheld Terminal */
1018 1052
1019/* 1053/*
1054 * STMicroelectonics
1055 */
1056#define ST_VID 0x0483
1057#define ST_STMCLT1030_PID 0x3747 /* ST Micro Connect Lite STMCLT1030 */
1058
1059/*
1020 * Papouch products (http://www.papouch.com/) 1060 * Papouch products (http://www.papouch.com/)
1021 * Submitted by Folkert van Heusden 1061 * Submitted by Folkert van Heusden
1022 */ 1062 */
1023 1063
1024#define PAPOUCH_VID 0x5050 /* Vendor ID */ 1064#define PAPOUCH_VID 0x5050 /* Vendor ID */
1065#define PAPOUCH_SB485_PID 0x0100 /* Papouch SB485 USB-485/422 Converter */
1066#define PAPOUCH_AP485_PID 0x0101 /* AP485 USB-RS485 Converter */
1067#define PAPOUCH_SB422_PID 0x0102 /* Papouch SB422 USB-RS422 Converter */
1068#define PAPOUCH_SB485_2_PID 0x0103 /* Papouch SB485 USB-485/422 Converter */
1069#define PAPOUCH_AP485_2_PID 0x0104 /* AP485 USB-RS485 Converter */
1070#define PAPOUCH_SB422_2_PID 0x0105 /* Papouch SB422 USB-RS422 Converter */
1071#define PAPOUCH_SB485S_PID 0x0106 /* Papouch SB485S USB-485/422 Converter */
1072#define PAPOUCH_SB485C_PID 0x0107 /* Papouch SB485C USB-485/422 Converter */
1073#define PAPOUCH_LEC_PID 0x0300 /* LEC USB Converter */
1074#define PAPOUCH_SB232_PID 0x0301 /* Papouch SB232 USB-RS232 Converter */
1025#define PAPOUCH_TMU_PID 0x0400 /* TMU USB Thermometer */ 1075#define PAPOUCH_TMU_PID 0x0400 /* TMU USB Thermometer */
1026#define PAPOUCH_QUIDO4x4_PID 0x0900 /* Quido 4/4 Module */ 1076#define PAPOUCH_IRAMP_PID 0x0500 /* Papouch IRAmp Duplex */
1077#define PAPOUCH_DRAK5_PID 0x0700 /* Papouch DRAK5 */
1078#define PAPOUCH_QUIDO8x8_PID 0x0800 /* Papouch Quido 8/8 Module */
1079#define PAPOUCH_QUIDO4x4_PID 0x0900 /* Papouch Quido 4/4 Module */
1080#define PAPOUCH_QUIDO2x2_PID 0x0a00 /* Papouch Quido 2/2 Module */
1081#define PAPOUCH_QUIDO10x1_PID 0x0b00 /* Papouch Quido 10/1 Module */
1082#define PAPOUCH_QUIDO30x3_PID 0x0c00 /* Papouch Quido 30/3 Module */
1083#define PAPOUCH_QUIDO60x3_PID 0x0d00 /* Papouch Quido 60(100)/3 Module */
1084#define PAPOUCH_QUIDO2x16_PID 0x0e00 /* Papouch Quido 2/16 Module */
1085#define PAPOUCH_QUIDO3x32_PID 0x0f00 /* Papouch Quido 3/32 Module */
1086#define PAPOUCH_DRAK6_PID 0x1000 /* Papouch DRAK6 */
1087#define PAPOUCH_UPSUSB_PID 0x8000 /* Papouch UPS-USB adapter */
1088#define PAPOUCH_MU_PID 0x8001 /* MU controller */
1089#define PAPOUCH_SIMUKEY_PID 0x8002 /* Papouch SimuKey */
1027#define PAPOUCH_AD4USB_PID 0x8003 /* AD4USB Measurement Module */ 1090#define PAPOUCH_AD4USB_PID 0x8003 /* AD4USB Measurement Module */
1091#define PAPOUCH_GMUX_PID 0x8004 /* Papouch GOLIATH MUX */
1092#define PAPOUCH_GMSR_PID 0x8005 /* Papouch GOLIATH MSR */
1028 1093
1029/* 1094/*
1030 * Marvell SheevaPlug 1095 * Marvell SheevaPlug
@@ -1051,6 +1116,11 @@
1051#define MJSG_HD_RADIO_PID 0x937C 1116#define MJSG_HD_RADIO_PID 0x937C
1052 1117
1053/* 1118/*
1119 * D.O.Tec products (http://www.directout.eu)
1120 */
1121#define FTDI_DOTEC_PID 0x9868
1122
1123/*
1054 * Xverve Signalyzer tools (http://www.signalyzer.com/) 1124 * Xverve Signalyzer tools (http://www.signalyzer.com/)
1055 */ 1125 */
1056#define XVERVE_SIGNALYZER_ST_PID 0xBCA0 1126#define XVERVE_SIGNALYZER_ST_PID 0xBCA0
@@ -1063,3 +1133,30 @@
1063 * Submitted by John G. Rogers 1133 * Submitted by John G. Rogers
1064 */ 1134 */
1065#define SEGWAY_RMP200_PID 0xe729 1135#define SEGWAY_RMP200_PID 0xe729
1136
1137
1138/*
1139 * Accesio USB Data Acquisition products (http://www.accesio.com/)
1140 */
1141#define ACCESIO_COM4SM_PID 0xD578
1142
1143/* www.sciencescope.co.uk educational dataloggers */
1144#define FTDI_SCIENCESCOPE_LOGBOOKML_PID 0xFF18
1145#define FTDI_SCIENCESCOPE_LS_LOGBOOK_PID 0xFF1C
1146#define FTDI_SCIENCESCOPE_HS_LOGBOOK_PID 0xFF1D
1147
1148/*
1149 * Milkymist One JTAG/Serial
1150 */
1151#define QIHARDWARE_VID 0x20B7
1152#define MILKYMISTONE_JTAGSERIAL_PID 0x0713
1153
1154/*
1155 * CTI GmbH RS485 Converter http://www.cti-lean.com/
1156 */
1157/* USB-485-Mini*/
1158#define FTDI_CTI_MINI_PID 0xF608
1159/* USB-Nano-485*/
1160#define FTDI_CTI_NANO_PID 0xF60B
1161
1162
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index a42b29a695b2..b0a7a9e909a4 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Garmin GPS driver 2 * Garmin GPS driver
3 * 3 *
4 * Copyright (C) 2006-2009 Hermann Kneissel herkne@users.sourceforge.net 4 * Copyright (C) 2006-2011 Hermann Kneissel herkne@gmx.de
5 * 5 *
6 * The latest version of the driver can be found at 6 * The latest version of the driver can be found at
7 * http://sourceforge.net/projects/garmin-gps/ 7 * http://sourceforge.net/projects/garmin-gps/
@@ -51,7 +51,7 @@ static int debug;
51 */ 51 */
52 52
53#define VERSION_MAJOR 0 53#define VERSION_MAJOR 0
54#define VERSION_MINOR 33 54#define VERSION_MINOR 36
55 55
56#define _STR(s) #s 56#define _STR(s) #s
57#define _DRIVER_VERSION(a, b) "v" _STR(a) "." _STR(b) 57#define _DRIVER_VERSION(a, b) "v" _STR(a) "." _STR(b)
@@ -410,6 +410,7 @@ static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id)
410 */ 410 */
411static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count) 411static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count)
412{ 412{
413 unsigned long flags;
413 const __u8 *recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; 414 const __u8 *recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET;
414 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; 415 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer;
415 416
@@ -458,7 +459,9 @@ static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count)
458 /* if this was an abort-transfer command, flush all 459 /* if this was an abort-transfer command, flush all
459 queued data. */ 460 queued data. */
460 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { 461 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) {
462 spin_lock_irqsave(&garmin_data_p->lock, flags);
461 garmin_data_p->flags |= FLAGS_DROP_DATA; 463 garmin_data_p->flags |= FLAGS_DROP_DATA;
464 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
462 pkt_clear(garmin_data_p); 465 pkt_clear(garmin_data_p);
463 } 466 }
464 467
@@ -943,7 +946,7 @@ static int garmin_open(struct tty_struct *tty, struct usb_serial_port *port)
943 spin_lock_irqsave(&garmin_data_p->lock, flags); 946 spin_lock_irqsave(&garmin_data_p->lock, flags);
944 garmin_data_p->mode = initial_mode; 947 garmin_data_p->mode = initial_mode;
945 garmin_data_p->count = 0; 948 garmin_data_p->count = 0;
946 garmin_data_p->flags = 0; 949 garmin_data_p->flags &= FLAGS_SESSION_REPLY1_SEEN;
947 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 950 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
948 951
949 /* shutdown any bulk reads that might be going on */ 952 /* shutdown any bulk reads that might be going on */
@@ -1178,7 +1181,8 @@ static int garmin_write_room(struct tty_struct *tty)
1178 1181
1179 1182
1180static void garmin_read_process(struct garmin_data *garmin_data_p, 1183static void garmin_read_process(struct garmin_data *garmin_data_p,
1181 unsigned char *data, unsigned data_length) 1184 unsigned char *data, unsigned data_length,
1185 int bulk_data)
1182{ 1186{
1183 unsigned long flags; 1187 unsigned long flags;
1184 1188
@@ -1193,7 +1197,8 @@ static void garmin_read_process(struct garmin_data *garmin_data_p,
1193 send it directly to the tty port */ 1197 send it directly to the tty port */
1194 if (garmin_data_p->flags & FLAGS_QUEUING) { 1198 if (garmin_data_p->flags & FLAGS_QUEUING) {
1195 pkt_add(garmin_data_p, data, data_length); 1199 pkt_add(garmin_data_p, data, data_length);
1196 } else if (getLayerId(data) == GARMIN_LAYERID_APPL) { 1200 } else if (bulk_data ||
1201 getLayerId(data) == GARMIN_LAYERID_APPL) {
1197 1202
1198 spin_lock_irqsave(&garmin_data_p->lock, flags); 1203 spin_lock_irqsave(&garmin_data_p->lock, flags);
1199 garmin_data_p->flags |= APP_RESP_SEEN; 1204 garmin_data_p->flags |= APP_RESP_SEEN;
@@ -1237,7 +1242,7 @@ static void garmin_read_bulk_callback(struct urb *urb)
1237 usb_serial_debug_data(debug, &port->dev, 1242 usb_serial_debug_data(debug, &port->dev,
1238 __func__, urb->actual_length, data); 1243 __func__, urb->actual_length, data);
1239 1244
1240 garmin_read_process(garmin_data_p, data, urb->actual_length); 1245 garmin_read_process(garmin_data_p, data, urb->actual_length, 1);
1241 1246
1242 if (urb->actual_length == 0 && 1247 if (urb->actual_length == 0 &&
1243 0 != (garmin_data_p->flags & FLAGS_BULK_IN_RESTART)) { 1248 0 != (garmin_data_p->flags & FLAGS_BULK_IN_RESTART)) {
@@ -1264,7 +1269,6 @@ static void garmin_read_bulk_callback(struct urb *urb)
1264 garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE; 1269 garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE;
1265 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1270 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1266 } 1271 }
1267 return;
1268} 1272}
1269 1273
1270 1274
@@ -1347,7 +1351,7 @@ static void garmin_read_int_callback(struct urb *urb)
1347 __func__, garmin_data_p->serial_num); 1351 __func__, garmin_data_p->serial_num);
1348 } 1352 }
1349 1353
1350 garmin_read_process(garmin_data_p, data, urb->actual_length); 1354 garmin_read_process(garmin_data_p, data, urb->actual_length, 0);
1351 1355
1352 port->interrupt_in_urb->dev = port->serial->dev; 1356 port->interrupt_in_urb->dev = port->serial->dev;
1353 retval = usb_submit_urb(urb, GFP_ATOMIC); 1357 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -1462,6 +1466,7 @@ static int garmin_attach(struct usb_serial *serial)
1462 garmin_data_p->timer.function = timeout_handler; 1466 garmin_data_p->timer.function = timeout_handler;
1463 garmin_data_p->port = port; 1467 garmin_data_p->port = port;
1464 garmin_data_p->state = 0; 1468 garmin_data_p->state = 0;
1469 garmin_data_p->flags = 0;
1465 garmin_data_p->count = 0; 1470 garmin_data_p->count = 0;
1466 usb_set_serial_port_data(port, garmin_data_p); 1471 usb_set_serial_port_data(port, garmin_data_p);
1467 1472
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index e6833e216fc9..e4db5ad2bc55 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -479,6 +479,26 @@ int usb_serial_handle_break(struct usb_serial_port *port)
479} 479}
480EXPORT_SYMBOL_GPL(usb_serial_handle_break); 480EXPORT_SYMBOL_GPL(usb_serial_handle_break);
481 481
482/**
483 * usb_serial_handle_dcd_change - handle a change of carrier detect state
484 * @port: usb_serial_port structure for the open port
485 * @tty: tty_struct structure for the port
486 * @status: new carrier detect status, nonzero if active
487 */
488void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
489 struct tty_struct *tty, unsigned int status)
490{
491 struct tty_port *port = &usb_port->port;
492
493 dbg("%s - port %d, status %d", __func__, usb_port->number, status);
494
495 if (status)
496 wake_up_interruptible(&port->open_wait);
497 else if (tty && !C_CLOCAL(tty))
498 tty_hangup(tty);
499}
500EXPORT_SYMBOL_GPL(usb_serial_handle_dcd_change);
501
482int usb_serial_generic_resume(struct usb_serial *serial) 502int usb_serial_generic_resume(struct usb_serial *serial)
483{ 503{
484 struct usb_serial_port *port; 504 struct usb_serial_port *port;
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 76e6fb3aab7a..abf095be5753 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -216,12 +216,14 @@ static void edge_unthrottle(struct tty_struct *tty);
216static void edge_set_termios(struct tty_struct *tty, 216static void edge_set_termios(struct tty_struct *tty,
217 struct usb_serial_port *port, 217 struct usb_serial_port *port,
218 struct ktermios *old_termios); 218 struct ktermios *old_termios);
219static int edge_ioctl(struct tty_struct *tty, struct file *file, 219static int edge_ioctl(struct tty_struct *tty,
220 unsigned int cmd, unsigned long arg); 220 unsigned int cmd, unsigned long arg);
221static void edge_break(struct tty_struct *tty, int break_state); 221static void edge_break(struct tty_struct *tty, int break_state);
222static int edge_tiocmget(struct tty_struct *tty, struct file *file); 222static int edge_tiocmget(struct tty_struct *tty);
223static int edge_tiocmset(struct tty_struct *tty, struct file *file, 223static int edge_tiocmset(struct tty_struct *tty,
224 unsigned int set, unsigned int clear); 224 unsigned int set, unsigned int clear);
225static int edge_get_icount(struct tty_struct *tty,
226 struct serial_icounter_struct *icount);
225static int edge_startup(struct usb_serial *serial); 227static int edge_startup(struct usb_serial *serial);
226static void edge_disconnect(struct usb_serial *serial); 228static void edge_disconnect(struct usb_serial *serial);
227static void edge_release(struct usb_serial *serial); 229static void edge_release(struct usb_serial *serial);
@@ -1465,8 +1467,6 @@ static void edge_throttle(struct tty_struct *tty)
1465 if (status != 0) 1467 if (status != 0)
1466 return; 1468 return;
1467 } 1469 }
1468
1469 return;
1470} 1470}
1471 1471
1472 1472
@@ -1568,7 +1568,7 @@ static int get_lsr_info(struct edgeport_port *edge_port,
1568 return 0; 1568 return 0;
1569} 1569}
1570 1570
1571static int edge_tiocmset(struct tty_struct *tty, struct file *file, 1571static int edge_tiocmset(struct tty_struct *tty,
1572 unsigned int set, unsigned int clear) 1572 unsigned int set, unsigned int clear)
1573{ 1573{
1574 struct usb_serial_port *port = tty->driver_data; 1574 struct usb_serial_port *port = tty->driver_data;
@@ -1599,7 +1599,7 @@ static int edge_tiocmset(struct tty_struct *tty, struct file *file,
1599 return 0; 1599 return 0;
1600} 1600}
1601 1601
1602static int edge_tiocmget(struct tty_struct *tty, struct file *file) 1602static int edge_tiocmget(struct tty_struct *tty)
1603{ 1603{
1604 struct usb_serial_port *port = tty->driver_data; 1604 struct usb_serial_port *port = tty->driver_data;
1605 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1605 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
@@ -1624,6 +1624,31 @@ static int edge_tiocmget(struct tty_struct *tty, struct file *file)
1624 return result; 1624 return result;
1625} 1625}
1626 1626
1627static int edge_get_icount(struct tty_struct *tty,
1628 struct serial_icounter_struct *icount)
1629{
1630 struct usb_serial_port *port = tty->driver_data;
1631 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1632 struct async_icount cnow;
1633 cnow = edge_port->icount;
1634
1635 icount->cts = cnow.cts;
1636 icount->dsr = cnow.dsr;
1637 icount->rng = cnow.rng;
1638 icount->dcd = cnow.dcd;
1639 icount->rx = cnow.rx;
1640 icount->tx = cnow.tx;
1641 icount->frame = cnow.frame;
1642 icount->overrun = cnow.overrun;
1643 icount->parity = cnow.parity;
1644 icount->brk = cnow.brk;
1645 icount->buf_overrun = cnow.buf_overrun;
1646
1647 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d",
1648 __func__, port->number, icount->rx, icount->tx);
1649 return 0;
1650}
1651
1627static int get_serial_info(struct edgeport_port *edge_port, 1652static int get_serial_info(struct edgeport_port *edge_port,
1628 struct serial_struct __user *retinfo) 1653 struct serial_struct __user *retinfo)
1629{ 1654{
@@ -1650,12 +1675,11 @@ static int get_serial_info(struct edgeport_port *edge_port,
1650} 1675}
1651 1676
1652 1677
1653
1654/***************************************************************************** 1678/*****************************************************************************
1655 * SerialIoctl 1679 * SerialIoctl
1656 * this function handles any ioctl calls to the driver 1680 * this function handles any ioctl calls to the driver
1657 *****************************************************************************/ 1681 *****************************************************************************/
1658static int edge_ioctl(struct tty_struct *tty, struct file *file, 1682static int edge_ioctl(struct tty_struct *tty,
1659 unsigned int cmd, unsigned long arg) 1683 unsigned int cmd, unsigned long arg)
1660{ 1684{
1661 struct usb_serial_port *port = tty->driver_data; 1685 struct usb_serial_port *port = tty->driver_data;
@@ -1663,7 +1687,6 @@ static int edge_ioctl(struct tty_struct *tty, struct file *file,
1663 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1687 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1664 struct async_icount cnow; 1688 struct async_icount cnow;
1665 struct async_icount cprev; 1689 struct async_icount cprev;
1666 struct serial_icounter_struct icount;
1667 1690
1668 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 1691 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1669 1692
@@ -1702,26 +1725,6 @@ static int edge_ioctl(struct tty_struct *tty, struct file *file,
1702 /* NOTREACHED */ 1725 /* NOTREACHED */
1703 break; 1726 break;
1704 1727
1705 case TIOCGICOUNT:
1706 cnow = edge_port->icount;
1707 memset(&icount, 0, sizeof(icount));
1708 icount.cts = cnow.cts;
1709 icount.dsr = cnow.dsr;
1710 icount.rng = cnow.rng;
1711 icount.dcd = cnow.dcd;
1712 icount.rx = cnow.rx;
1713 icount.tx = cnow.tx;
1714 icount.frame = cnow.frame;
1715 icount.overrun = cnow.overrun;
1716 icount.parity = cnow.parity;
1717 icount.brk = cnow.brk;
1718 icount.buf_overrun = cnow.buf_overrun;
1719
1720 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d",
1721 __func__, port->number, icount.rx, icount.tx);
1722 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1723 return -EFAULT;
1724 return 0;
1725 } 1728 }
1726 return -ENOIOCTLCMD; 1729 return -ENOIOCTLCMD;
1727} 1730}
@@ -1770,8 +1773,6 @@ static void edge_break(struct tty_struct *tty, int break_state)
1770 dbg("%s - error sending break set/clear command.", 1773 dbg("%s - error sending break set/clear command.",
1771 __func__); 1774 __func__);
1772 } 1775 }
1773
1774 return;
1775} 1776}
1776 1777
1777 1778
@@ -1980,7 +1981,7 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial,
1980 if (code == IOSP_STATUS_OPEN_RSP) { 1981 if (code == IOSP_STATUS_OPEN_RSP) {
1981 edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3); 1982 edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3);
1982 edge_port->maxTxCredits = edge_port->txCredits; 1983 edge_port->maxTxCredits = edge_port->txCredits;
1983 dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits); 1984 dbg("%s - Port %u Open Response Initial MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits);
1984 handle_new_msr(edge_port, byte2); 1985 handle_new_msr(edge_port, byte2);
1985 1986
1986 /* send the current line settings to the port so we are 1987 /* send the current line settings to the port so we are
@@ -2042,7 +2043,6 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial,
2042 dbg("%s - Unrecognized IOSP status code %u", __func__, code); 2043 dbg("%s - Unrecognized IOSP status code %u", __func__, code);
2043 break; 2044 break;
2044 } 2045 }
2045 return;
2046} 2046}
2047 2047
2048 2048
@@ -2095,8 +2095,6 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2095 2095
2096 /* Save the new modem status */ 2096 /* Save the new modem status */
2097 edge_port->shadowMSR = newMsr & 0xf0; 2097 edge_port->shadowMSR = newMsr & 0xf0;
2098
2099 return;
2100} 2098}
2101 2099
2102 2100
@@ -2143,8 +2141,6 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
2143 icount->parity++; 2141 icount->parity++;
2144 if (newLsr & LSR_FRM_ERR) 2142 if (newLsr & LSR_FRM_ERR)
2145 icount->frame++; 2143 icount->frame++;
2146
2147 return;
2148} 2144}
2149 2145
2150 2146
@@ -2347,7 +2343,6 @@ static int write_cmd_usb(struct edgeport_port *edge_port,
2347 usb_get_serial_data(edge_port->port->serial); 2343 usb_get_serial_data(edge_port->port->serial);
2348 int status = 0; 2344 int status = 0;
2349 struct urb *urb; 2345 struct urb *urb;
2350 int timeout;
2351 2346
2352 usb_serial_debug_data(debug, &edge_port->port->dev, 2347 usb_serial_debug_data(debug, &edge_port->port->dev,
2353 __func__, length, buffer); 2348 __func__, length, buffer);
@@ -2380,8 +2375,6 @@ static int write_cmd_usb(struct edgeport_port *edge_port,
2380 return status; 2375 return status;
2381 } 2376 }
2382 2377
2383 /* wait for command to finish */
2384 timeout = COMMAND_TIMEOUT;
2385#if 0 2378#if 0
2386 wait_event(&edge_port->wait_command, !edge_port->commandPending); 2379 wait_event(&edge_port->wait_command, !edge_port->commandPending);
2387 2380
@@ -2720,7 +2713,6 @@ static void change_port_settings(struct tty_struct *tty,
2720 baud = tty_termios_baud_rate(old_termios); 2713 baud = tty_termios_baud_rate(old_termios);
2721 tty_encode_baud_rate(tty, baud, baud); 2714 tty_encode_baud_rate(tty, baud, baud);
2722 } 2715 }
2723 return;
2724} 2716}
2725 2717
2726 2718
@@ -2894,8 +2886,8 @@ static void load_application_firmware(struct edgeport_serial *edge_serial)
2894 2886
2895 dbg("%s %d.%d.%d", fw_info, rec->data[0], rec->data[1], build); 2887 dbg("%s %d.%d.%d", fw_info, rec->data[0], rec->data[1], build);
2896 2888
2897 edge_serial->product_info.FirmwareMajorVersion = fw->data[0]; 2889 edge_serial->product_info.FirmwareMajorVersion = rec->data[0];
2898 edge_serial->product_info.FirmwareMinorVersion = fw->data[1]; 2890 edge_serial->product_info.FirmwareMinorVersion = rec->data[1];
2899 edge_serial->product_info.FirmwareBuildNumber = cpu_to_le16(build); 2891 edge_serial->product_info.FirmwareBuildNumber = cpu_to_le16(build);
2900 2892
2901 for (rec = ihex_next_binrec(rec); rec; 2893 for (rec = ihex_next_binrec(rec); rec;
@@ -2922,7 +2914,6 @@ static void load_application_firmware(struct edgeport_serial *edge_serial)
2922 0x40, 0x4000, 0x0001, NULL, 0, 3000); 2914 0x40, 0x4000, 0x0001, NULL, 0, 3000);
2923 2915
2924 release_firmware(fw); 2916 release_firmware(fw);
2925 return;
2926} 2917}
2927 2918
2928 2919
diff --git a/drivers/usb/serial/io_edgeport.h b/drivers/usb/serial/io_edgeport.h
index dced7ec65470..ad9c1d47a619 100644
--- a/drivers/usb/serial/io_edgeport.h
+++ b/drivers/usb/serial/io_edgeport.h
@@ -68,7 +68,7 @@ struct comMapper {
68#define PROC_SET_COM_ENTRY 2 68#define PROC_SET_COM_ENTRY 2
69 69
70 70
71/* The following sturcture is passed to the write */ 71/* The following structure is passed to the write */
72struct procWrite { 72struct procWrite {
73 int Command; 73 int Command;
74 union { 74 union {
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index feb56a4ca799..178b22eb32b1 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -123,6 +123,7 @@ static struct usb_serial_driver edgeport_2port_device = {
123 .set_termios = edge_set_termios, 123 .set_termios = edge_set_termios,
124 .tiocmget = edge_tiocmget, 124 .tiocmget = edge_tiocmget,
125 .tiocmset = edge_tiocmset, 125 .tiocmset = edge_tiocmset,
126 .get_icount = edge_get_icount,
126 .write = edge_write, 127 .write = edge_write,
127 .write_room = edge_write_room, 128 .write_room = edge_write_room,
128 .chars_in_buffer = edge_chars_in_buffer, 129 .chars_in_buffer = edge_chars_in_buffer,
@@ -152,6 +153,7 @@ static struct usb_serial_driver edgeport_4port_device = {
152 .set_termios = edge_set_termios, 153 .set_termios = edge_set_termios,
153 .tiocmget = edge_tiocmget, 154 .tiocmget = edge_tiocmget,
154 .tiocmset = edge_tiocmset, 155 .tiocmset = edge_tiocmset,
156 .get_icount = edge_get_icount,
155 .write = edge_write, 157 .write = edge_write,
156 .write_room = edge_write_room, 158 .write_room = edge_write_room,
157 .chars_in_buffer = edge_chars_in_buffer, 159 .chars_in_buffer = edge_chars_in_buffer,
@@ -181,6 +183,7 @@ static struct usb_serial_driver edgeport_8port_device = {
181 .set_termios = edge_set_termios, 183 .set_termios = edge_set_termios,
182 .tiocmget = edge_tiocmget, 184 .tiocmget = edge_tiocmget,
183 .tiocmset = edge_tiocmset, 185 .tiocmset = edge_tiocmset,
186 .get_icount = edge_get_icount,
184 .write = edge_write, 187 .write = edge_write,
185 .write_room = edge_write_room, 188 .write_room = edge_write_room,
186 .chars_in_buffer = edge_chars_in_buffer, 189 .chars_in_buffer = edge_chars_in_buffer,
@@ -196,6 +199,7 @@ static struct usb_serial_driver epic_device = {
196 .name = "epic", 199 .name = "epic",
197 }, 200 },
198 .description = "EPiC device", 201 .description = "EPiC device",
202 .usb_driver = &io_driver,
199 .id_table = Epic_port_id_table, 203 .id_table = Epic_port_id_table,
200 .num_ports = 1, 204 .num_ports = 1,
201 .open = edge_open, 205 .open = edge_open,
@@ -209,6 +213,7 @@ static struct usb_serial_driver epic_device = {
209 .set_termios = edge_set_termios, 213 .set_termios = edge_set_termios,
210 .tiocmget = edge_tiocmget, 214 .tiocmget = edge_tiocmget,
211 .tiocmset = edge_tiocmset, 215 .tiocmset = edge_tiocmset,
216 .get_icount = edge_get_icount,
212 .write = edge_write, 217 .write = edge_write,
213 .write_room = edge_write_room, 218 .write_room = edge_write_room,
214 .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 a7cfc5952937..0aac00afb5c8 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -433,7 +433,7 @@ static int write_i2c_mem(struct edgeport_serial *serial,
433 433
434 /* We can only send a maximum of 1 aligned byte page at a time */ 434 /* We can only send a maximum of 1 aligned byte page at a time */
435 435
436 /* calulate the number of bytes left in the first page */ 436 /* calculate the number of bytes left in the first page */
437 write_length = EPROM_PAGE_SIZE - 437 write_length = EPROM_PAGE_SIZE -
438 (start_address & (EPROM_PAGE_SIZE - 1)); 438 (start_address & (EPROM_PAGE_SIZE - 1));
439 439
@@ -1571,8 +1571,6 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1571 } 1571 }
1572 } 1572 }
1573 tty_kref_put(tty); 1573 tty_kref_put(tty);
1574
1575 return;
1576} 1574}
1577 1575
1578static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data, 1576static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
@@ -2424,7 +2422,6 @@ static void change_port_settings(struct tty_struct *tty,
2424 dbg("%s - error %d when trying to write config to device", 2422 dbg("%s - error %d when trying to write config to device",
2425 __func__, status); 2423 __func__, status);
2426 kfree(config); 2424 kfree(config);
2427 return;
2428} 2425}
2429 2426
2430static void edge_set_termios(struct tty_struct *tty, 2427static void edge_set_termios(struct tty_struct *tty,
@@ -2445,10 +2442,9 @@ static void edge_set_termios(struct tty_struct *tty,
2445 return; 2442 return;
2446 /* change the port settings to the new ones specified */ 2443 /* change the port settings to the new ones specified */
2447 change_port_settings(tty, edge_port, old_termios); 2444 change_port_settings(tty, edge_port, old_termios);
2448 return;
2449} 2445}
2450 2446
2451static int edge_tiocmset(struct tty_struct *tty, struct file *file, 2447static int edge_tiocmset(struct tty_struct *tty,
2452 unsigned int set, unsigned int clear) 2448 unsigned int set, unsigned int clear)
2453{ 2449{
2454 struct usb_serial_port *port = tty->driver_data; 2450 struct usb_serial_port *port = tty->driver_data;
@@ -2481,7 +2477,7 @@ static int edge_tiocmset(struct tty_struct *tty, struct file *file,
2481 return 0; 2477 return 0;
2482} 2478}
2483 2479
2484static int edge_tiocmget(struct tty_struct *tty, struct file *file) 2480static int edge_tiocmget(struct tty_struct *tty)
2485{ 2481{
2486 struct usb_serial_port *port = tty->driver_data; 2482 struct usb_serial_port *port = tty->driver_data;
2487 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2483 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
@@ -2510,6 +2506,27 @@ static int edge_tiocmget(struct tty_struct *tty, struct file *file)
2510 return result; 2506 return result;
2511} 2507}
2512 2508
2509static int edge_get_icount(struct tty_struct *tty,
2510 struct serial_icounter_struct *icount)
2511{
2512 struct usb_serial_port *port = tty->driver_data;
2513 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2514 struct async_icount *ic = &edge_port->icount;
2515
2516 icount->cts = ic->cts;
2517 icount->dsr = ic->dsr;
2518 icount->rng = ic->rng;
2519 icount->dcd = ic->dcd;
2520 icount->tx = ic->tx;
2521 icount->rx = ic->rx;
2522 icount->frame = ic->frame;
2523 icount->parity = ic->parity;
2524 icount->overrun = ic->overrun;
2525 icount->brk = ic->brk;
2526 icount->buf_overrun = ic->buf_overrun;
2527 return 0;
2528}
2529
2513static int get_serial_info(struct edgeport_port *edge_port, 2530static int get_serial_info(struct edgeport_port *edge_port,
2514 struct serial_struct __user *retinfo) 2531 struct serial_struct __user *retinfo)
2515{ 2532{
@@ -2535,7 +2552,7 @@ static int get_serial_info(struct edgeport_port *edge_port,
2535 return 0; 2552 return 0;
2536} 2553}
2537 2554
2538static int edge_ioctl(struct tty_struct *tty, struct file *file, 2555static int edge_ioctl(struct tty_struct *tty,
2539 unsigned int cmd, unsigned long arg) 2556 unsigned int cmd, unsigned long arg)
2540{ 2557{
2541 struct usb_serial_port *port = tty->driver_data; 2558 struct usb_serial_port *port = tty->driver_data;
@@ -2572,13 +2589,6 @@ static int edge_ioctl(struct tty_struct *tty, struct file *file,
2572 } 2589 }
2573 /* not reached */ 2590 /* not reached */
2574 break; 2591 break;
2575 case TIOCGICOUNT:
2576 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2577 port->number, edge_port->icount.rx, edge_port->icount.tx);
2578 if (copy_to_user((void __user *)arg, &edge_port->icount,
2579 sizeof(edge_port->icount)))
2580 return -EFAULT;
2581 return 0;
2582 } 2592 }
2583 return -ENOIOCTLCMD; 2593 return -ENOIOCTLCMD;
2584} 2594}
@@ -2758,6 +2768,7 @@ static struct usb_serial_driver edgeport_1port_device = {
2758 .set_termios = edge_set_termios, 2768 .set_termios = edge_set_termios,
2759 .tiocmget = edge_tiocmget, 2769 .tiocmget = edge_tiocmget,
2760 .tiocmset = edge_tiocmset, 2770 .tiocmset = edge_tiocmset,
2771 .get_icount = edge_get_icount,
2761 .write = edge_write, 2772 .write = edge_write,
2762 .write_room = edge_write_room, 2773 .write_room = edge_write_room,
2763 .chars_in_buffer = edge_chars_in_buffer, 2774 .chars_in_buffer = edge_chars_in_buffer,
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index efc72113216b..6aca631a407a 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -150,7 +150,7 @@ static void iuu_release(struct usb_serial *serial)
150 } 150 }
151} 151}
152 152
153static int iuu_tiocmset(struct tty_struct *tty, struct file *file, 153static int iuu_tiocmset(struct tty_struct *tty,
154 unsigned int set, unsigned int clear) 154 unsigned int set, unsigned int clear)
155{ 155{
156 struct usb_serial_port *port = tty->driver_data; 156 struct usb_serial_port *port = tty->driver_data;
@@ -179,7 +179,7 @@ static int iuu_tiocmset(struct tty_struct *tty, struct file *file,
179 * When no card , the reader respond with TIOCM_CD 179 * When no card , the reader respond with TIOCM_CD
180 * This is known as CD autodetect mechanism 180 * This is known as CD autodetect mechanism
181 */ 181 */
182static int iuu_tiocmget(struct tty_struct *tty, struct file *file) 182static int iuu_tiocmget(struct tty_struct *tty)
183{ 183{
184 struct usb_serial_port *port = tty->driver_data; 184 struct usb_serial_port *port = tty->driver_data;
185 struct iuu_private *priv = usb_get_serial_port_data(port); 185 struct iuu_private *priv = usb_get_serial_port_data(port);
@@ -807,7 +807,6 @@ static void read_rxcmd_callback(struct urb *urb)
807 iuu_uart_read_callback, port); 807 iuu_uart_read_callback, port);
808 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 808 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
809 dbg("%s - submit result = %d", __func__, result); 809 dbg("%s - submit result = %d", __func__, result);
810 return;
811} 810}
812 811
813static int iuu_uart_on(struct usb_serial_port *port) 812static int iuu_uart_on(struct usb_serial_port *port)
@@ -1276,6 +1275,7 @@ static struct usb_serial_driver iuu_device = {
1276 .name = "iuu_phoenix", 1275 .name = "iuu_phoenix",
1277 }, 1276 },
1278 .id_table = id_table, 1277 .id_table = id_table,
1278 .usb_driver = &iuu_driver,
1279 .num_ports = 1, 1279 .num_ports = 1,
1280 .bulk_in_size = 512, 1280 .bulk_in_size = 512,
1281 .bulk_out_size = 512, 1281 .bulk_out_size = 512,
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 297163c3c610..a442352d7b61 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -9,7 +9,7 @@
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 See http://misc.nu/hugh/keyspan.html for more information. 12 See http://blemings.org/hugh/keyspan.html for more information.
13 13
14 Code in this driver inspired by and in a number of places taken 14 Code in this driver inspired by and in a number of places taken
15 from Brian Warner's original Keyspan-PDA driver. 15 from Brian Warner's original Keyspan-PDA driver.
@@ -301,7 +301,7 @@ static void keyspan_set_termios(struct tty_struct *tty,
301 keyspan_send_setup(port, 0); 301 keyspan_send_setup(port, 0);
302} 302}
303 303
304static int keyspan_tiocmget(struct tty_struct *tty, struct file *file) 304static int keyspan_tiocmget(struct tty_struct *tty)
305{ 305{
306 struct usb_serial_port *port = tty->driver_data; 306 struct usb_serial_port *port = tty->driver_data;
307 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port); 307 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
@@ -317,7 +317,7 @@ static int keyspan_tiocmget(struct tty_struct *tty, struct file *file)
317 return value; 317 return value;
318} 318}
319 319
320static int keyspan_tiocmset(struct tty_struct *tty, struct file *file, 320static int keyspan_tiocmset(struct tty_struct *tty,
321 unsigned int set, unsigned int clear) 321 unsigned int set, unsigned int clear)
322{ 322{
323 struct usb_serial_port *port = tty->driver_data; 323 struct usb_serial_port *port = tty->driver_data;
@@ -2121,16 +2121,16 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2121 /* Work out which port within the device is being setup */ 2121 /* Work out which port within the device is being setup */
2122 device_port = port->number - port->serial->minor; 2122 device_port = port->number - port->serial->minor;
2123 2123
2124 dbg("%s - endpoint %d port %d (%d)", 2124 /* Make sure we have an urb then send the message */
2125 __func__, usb_pipeendpoint(this_urb->pipe),
2126 port->number, device_port);
2127
2128 /* Make sure we have an urb then send the message */
2129 if (this_urb == NULL) { 2125 if (this_urb == NULL) {
2130 dbg("%s - oops no urb for port %d.", __func__, port->number); 2126 dbg("%s - oops no urb for port %d.", __func__, port->number);
2131 return -1; 2127 return -1;
2132 } 2128 }
2133 2129
2130 dbg("%s - endpoint %d port %d (%d)",
2131 __func__, usb_pipeendpoint(this_urb->pipe),
2132 port->number, device_port);
2133
2134 /* Save reset port val for resend. 2134 /* Save reset port val for resend.
2135 Don't overwrite resend for open/close condition. */ 2135 Don't overwrite resend for open/close condition. */
2136 if ((reset_port + 1) > p_priv->resend_cont) 2136 if ((reset_port + 1) > p_priv->resend_cont)
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h
index bf3297ddd186..13fa1d1cc900 100644
--- a/drivers/usb/serial/keyspan.h
+++ b/drivers/usb/serial/keyspan.h
@@ -9,7 +9,7 @@
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 See http://misc.nu/hugh/keyspan.html for more information. 12 See http://blemings.org/hugh/keyspan.html for more information.
13 13
14 Code in this driver inspired by and in a number of places taken 14 Code in this driver inspired by and in a number of places taken
15 from Brian Warner's original Keyspan-PDA driver. 15 from Brian Warner's original Keyspan-PDA driver.
@@ -58,10 +58,9 @@ static void keyspan_set_termios (struct tty_struct *tty,
58 struct ktermios *old); 58 struct ktermios *old);
59static void keyspan_break_ctl (struct tty_struct *tty, 59static void keyspan_break_ctl (struct tty_struct *tty,
60 int break_state); 60 int break_state);
61static int keyspan_tiocmget (struct tty_struct *tty, 61static int keyspan_tiocmget (struct tty_struct *tty);
62 struct file *file);
63static int keyspan_tiocmset (struct tty_struct *tty, 62static int keyspan_tiocmset (struct tty_struct *tty,
64 struct file *file, unsigned int set, 63 unsigned int set,
65 unsigned int clear); 64 unsigned int clear);
66static int keyspan_fake_startup (struct usb_serial *serial); 65static int keyspan_fake_startup (struct usb_serial *serial);
67 66
@@ -546,6 +545,7 @@ static struct usb_serial_driver keyspan_pre_device = {
546 .name = "keyspan_no_firm", 545 .name = "keyspan_no_firm",
547 }, 546 },
548 .description = "Keyspan - (without firmware)", 547 .description = "Keyspan - (without firmware)",
548 .usb_driver = &keyspan_driver,
549 .id_table = keyspan_pre_ids, 549 .id_table = keyspan_pre_ids,
550 .num_ports = 1, 550 .num_ports = 1,
551 .attach = keyspan_fake_startup, 551 .attach = keyspan_fake_startup,
@@ -557,6 +557,7 @@ static struct usb_serial_driver keyspan_1port_device = {
557 .name = "keyspan_1", 557 .name = "keyspan_1",
558 }, 558 },
559 .description = "Keyspan 1 port adapter", 559 .description = "Keyspan 1 port adapter",
560 .usb_driver = &keyspan_driver,
560 .id_table = keyspan_1port_ids, 561 .id_table = keyspan_1port_ids,
561 .num_ports = 1, 562 .num_ports = 1,
562 .open = keyspan_open, 563 .open = keyspan_open,
@@ -579,6 +580,7 @@ static struct usb_serial_driver keyspan_2port_device = {
579 .name = "keyspan_2", 580 .name = "keyspan_2",
580 }, 581 },
581 .description = "Keyspan 2 port adapter", 582 .description = "Keyspan 2 port adapter",
583 .usb_driver = &keyspan_driver,
582 .id_table = keyspan_2port_ids, 584 .id_table = keyspan_2port_ids,
583 .num_ports = 2, 585 .num_ports = 2,
584 .open = keyspan_open, 586 .open = keyspan_open,
@@ -601,6 +603,7 @@ static struct usb_serial_driver keyspan_4port_device = {
601 .name = "keyspan_4", 603 .name = "keyspan_4",
602 }, 604 },
603 .description = "Keyspan 4 port adapter", 605 .description = "Keyspan 4 port adapter",
606 .usb_driver = &keyspan_driver,
604 .id_table = keyspan_4port_ids, 607 .id_table = keyspan_4port_ids,
605 .num_ports = 4, 608 .num_ports = 4,
606 .open = keyspan_open, 609 .open = keyspan_open,
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 185fe9a7d4e0..d5c0c6ab4966 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -173,7 +173,8 @@ static void keyspan_pda_wakeup_write(struct work_struct *work)
173 container_of(work, struct keyspan_pda_private, wakeup_work); 173 container_of(work, struct keyspan_pda_private, wakeup_work);
174 struct usb_serial_port *port = priv->port; 174 struct usb_serial_port *port = priv->port;
175 struct tty_struct *tty = tty_port_tty_get(&port->port); 175 struct tty_struct *tty = tty_port_tty_get(&port->port);
176 tty_wakeup(tty); 176 if (tty)
177 tty_wakeup(tty);
177 tty_kref_put(tty); 178 tty_kref_put(tty);
178} 179}
179 180
@@ -206,7 +207,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
206static void keyspan_pda_rx_interrupt(struct urb *urb) 207static void keyspan_pda_rx_interrupt(struct urb *urb)
207{ 208{
208 struct usb_serial_port *port = urb->context; 209 struct usb_serial_port *port = urb->context;
209 struct tty_struct *tty = tty_port_tty_get(&port->port); 210 struct tty_struct *tty;
210 unsigned char *data = urb->transfer_buffer; 211 unsigned char *data = urb->transfer_buffer;
211 int retval; 212 int retval;
212 int status = urb->status; 213 int status = urb->status;
@@ -223,7 +224,7 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
223 /* this urb is terminated, clean up */ 224 /* this urb is terminated, clean up */
224 dbg("%s - urb shutting down with status: %d", 225 dbg("%s - urb shutting down with status: %d",
225 __func__, status); 226 __func__, status);
226 goto out; 227 return;
227 default: 228 default:
228 dbg("%s - nonzero urb status received: %d", 229 dbg("%s - nonzero urb status received: %d",
229 __func__, status); 230 __func__, status);
@@ -233,12 +234,14 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
233 /* see if the message is data or a status interrupt */ 234 /* see if the message is data or a status interrupt */
234 switch (data[0]) { 235 switch (data[0]) {
235 case 0: 236 case 0:
236 /* rest of message is rx data */ 237 tty = tty_port_tty_get(&port->port);
237 if (urb->actual_length) { 238 /* rest of message is rx data */
239 if (tty && urb->actual_length) {
238 tty_insert_flip_string(tty, data + 1, 240 tty_insert_flip_string(tty, data + 1,
239 urb->actual_length - 1); 241 urb->actual_length - 1);
240 tty_flip_buffer_push(tty); 242 tty_flip_buffer_push(tty);
241 } 243 }
244 tty_kref_put(tty);
242 break; 245 break;
243 case 1: 246 case 1:
244 /* status interrupt */ 247 /* status interrupt */
@@ -265,8 +268,6 @@ exit:
265 dev_err(&port->dev, 268 dev_err(&port->dev,
266 "%s - usb_submit_urb failed with result %d", 269 "%s - usb_submit_urb failed with result %d",
267 __func__, retval); 270 __func__, retval);
268out:
269 tty_kref_put(tty);
270} 271}
271 272
272 273
@@ -292,7 +293,6 @@ static void keyspan_pda_rx_unthrottle(struct tty_struct *tty)
292 port->interrupt_in_urb->dev = port->serial->dev; 293 port->interrupt_in_urb->dev = port->serial->dev;
293 if (usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL)) 294 if (usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL))
294 dbg(" usb_submit_urb(read urb) failed"); 295 dbg(" usb_submit_urb(read urb) failed");
295 return;
296} 296}
297 297
298 298
@@ -458,7 +458,7 @@ static int keyspan_pda_set_modem_info(struct usb_serial *serial,
458 return rc; 458 return rc;
459} 459}
460 460
461static int keyspan_pda_tiocmget(struct tty_struct *tty, struct file *file) 461static int keyspan_pda_tiocmget(struct tty_struct *tty)
462{ 462{
463 struct usb_serial_port *port = tty->driver_data; 463 struct usb_serial_port *port = tty->driver_data;
464 struct usb_serial *serial = port->serial; 464 struct usb_serial *serial = port->serial;
@@ -479,7 +479,7 @@ static int keyspan_pda_tiocmget(struct tty_struct *tty, struct file *file)
479 return value; 479 return value;
480} 480}
481 481
482static int keyspan_pda_tiocmset(struct tty_struct *tty, struct file *file, 482static int keyspan_pda_tiocmset(struct tty_struct *tty,
483 unsigned int set, unsigned int clear) 483 unsigned int set, unsigned int clear)
484{ 484{
485 struct usb_serial_port *port = tty->driver_data; 485 struct usb_serial_port *port = tty->driver_data;
@@ -680,22 +680,6 @@ static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on)
680 } 680 }
681} 681}
682 682
683static int keyspan_pda_carrier_raised(struct usb_serial_port *port)
684{
685 struct usb_serial *serial = port->serial;
686 unsigned char modembits;
687
688 /* If we can read the modem status and the DCD is low then
689 carrier is not raised yet */
690 if (keyspan_pda_get_modem_info(serial, &modembits) >= 0) {
691 if (!(modembits & (1>>6)))
692 return 0;
693 }
694 /* Carrier raised, or we failed (eg disconnected) so
695 progress accordingly */
696 return 1;
697}
698
699 683
700static int keyspan_pda_open(struct tty_struct *tty, 684static int keyspan_pda_open(struct tty_struct *tty,
701 struct usb_serial_port *port) 685 struct usb_serial_port *port)
@@ -882,7 +866,6 @@ static struct usb_serial_driver keyspan_pda_device = {
882 .id_table = id_table_std, 866 .id_table = id_table_std,
883 .num_ports = 1, 867 .num_ports = 1,
884 .dtr_rts = keyspan_pda_dtr_rts, 868 .dtr_rts = keyspan_pda_dtr_rts,
885 .carrier_raised = keyspan_pda_carrier_raised,
886 .open = keyspan_pda_open, 869 .open = keyspan_pda_open,
887 .close = keyspan_pda_close, 870 .close = keyspan_pda_close,
888 .write = keyspan_pda_write, 871 .write = keyspan_pda_write,
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index e8a65ce45a2f..19373cb7c5bf 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -68,8 +68,8 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port);
68static void klsi_105_close(struct usb_serial_port *port); 68static void klsi_105_close(struct usb_serial_port *port);
69static void klsi_105_set_termios(struct tty_struct *tty, 69static void klsi_105_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 int klsi_105_tiocmget(struct tty_struct *tty, struct file *file); 71static int klsi_105_tiocmget(struct tty_struct *tty);
72static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file, 72static int klsi_105_tiocmset(struct tty_struct *tty,
73 unsigned int set, unsigned int clear); 73 unsigned int set, unsigned int clear);
74static void klsi_105_process_read_urb(struct urb *urb); 74static void klsi_105_process_read_urb(struct urb *urb);
75static int klsi_105_prepare_write_buffer(struct usb_serial_port *port, 75static int klsi_105_prepare_write_buffer(struct usb_serial_port *port,
@@ -637,7 +637,7 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
637} 637}
638#endif 638#endif
639 639
640static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file) 640static int klsi_105_tiocmget(struct tty_struct *tty)
641{ 641{
642 struct usb_serial_port *port = tty->driver_data; 642 struct usb_serial_port *port = tty->driver_data;
643 struct klsi_105_private *priv = usb_get_serial_port_data(port); 643 struct klsi_105_private *priv = usb_get_serial_port_data(port);
@@ -661,7 +661,7 @@ static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file)
661 return (int)line_state; 661 return (int)line_state;
662} 662}
663 663
664static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file, 664static int klsi_105_tiocmset(struct tty_struct *tty,
665 unsigned int set, unsigned int clear) 665 unsigned int set, unsigned int clear)
666{ 666{
667 int retval = -EINVAL; 667 int retval = -EINVAL;
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index bd5bd8589e04..ddd146300ddb 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -75,10 +75,10 @@ static void kobil_close(struct usb_serial_port *port);
75static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, 75static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
76 const unsigned char *buf, int count); 76 const unsigned char *buf, int count);
77static int kobil_write_room(struct tty_struct *tty); 77static int kobil_write_room(struct tty_struct *tty);
78static int kobil_ioctl(struct tty_struct *tty, struct file *file, 78static int kobil_ioctl(struct tty_struct *tty,
79 unsigned int cmd, unsigned long arg); 79 unsigned int cmd, unsigned long arg);
80static int kobil_tiocmget(struct tty_struct *tty, struct file *file); 80static int kobil_tiocmget(struct tty_struct *tty);
81static int kobil_tiocmset(struct tty_struct *tty, struct file *file, 81static int kobil_tiocmset(struct tty_struct *tty,
82 unsigned int set, unsigned int clear); 82 unsigned int set, unsigned int clear);
83static void kobil_read_int_callback(struct urb *urb); 83static void kobil_read_int_callback(struct urb *urb);
84static void kobil_write_callback(struct urb *purb); 84static void kobil_write_callback(struct urb *purb);
@@ -372,7 +372,7 @@ static void kobil_read_int_callback(struct urb *urb)
372 } 372 }
373 373
374 tty = tty_port_tty_get(&port->port); 374 tty = tty_port_tty_get(&port->port);
375 if (urb->actual_length) { 375 if (tty && urb->actual_length) {
376 376
377 /* BEGIN DEBUG */ 377 /* BEGIN DEBUG */
378 /* 378 /*
@@ -504,7 +504,7 @@ static int kobil_write_room(struct tty_struct *tty)
504} 504}
505 505
506 506
507static int kobil_tiocmget(struct tty_struct *tty, struct file *file) 507static int kobil_tiocmget(struct tty_struct *tty)
508{ 508{
509 struct usb_serial_port *port = tty->driver_data; 509 struct usb_serial_port *port = tty->driver_data;
510 struct kobil_private *priv; 510 struct kobil_private *priv;
@@ -544,7 +544,7 @@ static int kobil_tiocmget(struct tty_struct *tty, struct file *file)
544 return result; 544 return result;
545} 545}
546 546
547static int kobil_tiocmset(struct tty_struct *tty, struct file *file, 547static int kobil_tiocmset(struct tty_struct *tty,
548 unsigned int set, unsigned int clear) 548 unsigned int set, unsigned int clear)
549{ 549{
550 struct usb_serial_port *port = tty->driver_data; 550 struct usb_serial_port *port = tty->driver_data;
@@ -668,7 +668,7 @@ static void kobil_set_termios(struct tty_struct *tty,
668 ); 668 );
669} 669}
670 670
671static int kobil_ioctl(struct tty_struct *tty, struct file *file, 671static int kobil_ioctl(struct tty_struct *tty,
672 unsigned int cmd, unsigned long arg) 672 unsigned int cmd, unsigned long arg)
673{ 673{
674 struct usb_serial_port *port = tty->driver_data; 674 struct usb_serial_port *port = tty->driver_data;
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 7aa01b95b1d4..ba0d28727ccb 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -78,6 +78,8 @@
78#include <asm/unaligned.h> 78#include <asm/unaligned.h>
79#include <linux/usb.h> 79#include <linux/usb.h>
80#include <linux/usb/serial.h> 80#include <linux/usb/serial.h>
81#include <linux/serial.h>
82#include <linux/ioctl.h>
81#include "mct_u232.h" 83#include "mct_u232.h"
82 84
83/* 85/*
@@ -101,9 +103,13 @@ static void mct_u232_read_int_callback(struct urb *urb);
101static void mct_u232_set_termios(struct tty_struct *tty, 103static void mct_u232_set_termios(struct tty_struct *tty,
102 struct usb_serial_port *port, struct ktermios *old); 104 struct usb_serial_port *port, struct ktermios *old);
103static void mct_u232_break_ctl(struct tty_struct *tty, int break_state); 105static void mct_u232_break_ctl(struct tty_struct *tty, int break_state);
104static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file); 106static int mct_u232_tiocmget(struct tty_struct *tty);
105static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file, 107static int mct_u232_tiocmset(struct tty_struct *tty,
106 unsigned int set, unsigned int clear); 108 unsigned int set, unsigned int clear);
109static int mct_u232_ioctl(struct tty_struct *tty,
110 unsigned int cmd, unsigned long arg);
111static int mct_u232_get_icount(struct tty_struct *tty,
112 struct serial_icounter_struct *icount);
107static void mct_u232_throttle(struct tty_struct *tty); 113static void mct_u232_throttle(struct tty_struct *tty);
108static void mct_u232_unthrottle(struct tty_struct *tty); 114static void mct_u232_unthrottle(struct tty_struct *tty);
109 115
@@ -150,9 +156,10 @@ static struct usb_serial_driver mct_u232_device = {
150 .tiocmset = mct_u232_tiocmset, 156 .tiocmset = mct_u232_tiocmset,
151 .attach = mct_u232_startup, 157 .attach = mct_u232_startup,
152 .release = mct_u232_release, 158 .release = mct_u232_release,
159 .ioctl = mct_u232_ioctl,
160 .get_icount = mct_u232_get_icount,
153}; 161};
154 162
155
156struct mct_u232_private { 163struct mct_u232_private {
157 spinlock_t lock; 164 spinlock_t lock;
158 unsigned int control_state; /* Modem Line Setting (TIOCM) */ 165 unsigned int control_state; /* Modem Line Setting (TIOCM) */
@@ -160,6 +167,9 @@ struct mct_u232_private {
160 unsigned char last_lsr; /* Line Status Register */ 167 unsigned char last_lsr; /* Line Status Register */
161 unsigned char last_msr; /* Modem Status Register */ 168 unsigned char last_msr; /* Modem Status Register */
162 unsigned int rx_flags; /* Throttling flags */ 169 unsigned int rx_flags; /* Throttling flags */
170 struct async_icount icount;
171 wait_queue_head_t msr_wait; /* for handling sleeping while waiting
172 for msr change to happen */
163}; 173};
164 174
165#define THROTTLED 0x01 175#define THROTTLED 0x01
@@ -386,6 +396,20 @@ static int mct_u232_get_modem_stat(struct usb_serial *serial,
386 return rc; 396 return rc;
387} /* mct_u232_get_modem_stat */ 397} /* mct_u232_get_modem_stat */
388 398
399static void mct_u232_msr_to_icount(struct async_icount *icount,
400 unsigned char msr)
401{
402 /* Translate Control Line states */
403 if (msr & MCT_U232_MSR_DDSR)
404 icount->dsr++;
405 if (msr & MCT_U232_MSR_DCTS)
406 icount->cts++;
407 if (msr & MCT_U232_MSR_DRI)
408 icount->rng++;
409 if (msr & MCT_U232_MSR_DCD)
410 icount->dcd++;
411} /* mct_u232_msr_to_icount */
412
389static void mct_u232_msr_to_state(unsigned int *control_state, 413static void mct_u232_msr_to_state(unsigned int *control_state,
390 unsigned char msr) 414 unsigned char msr)
391{ 415{
@@ -422,6 +446,7 @@ static int mct_u232_startup(struct usb_serial *serial)
422 if (!priv) 446 if (!priv)
423 return -ENOMEM; 447 return -ENOMEM;
424 spin_lock_init(&priv->lock); 448 spin_lock_init(&priv->lock);
449 init_waitqueue_head(&priv->msr_wait);
425 usb_set_serial_port_data(serial->port[0], priv); 450 usb_set_serial_port_data(serial->port[0], priv);
426 451
427 init_waitqueue_head(&serial->port[0]->write_wait); 452 init_waitqueue_head(&serial->port[0]->write_wait);
@@ -549,9 +574,12 @@ static void mct_u232_close(struct usb_serial_port *port)
549{ 574{
550 dbg("%s port %d", __func__, port->number); 575 dbg("%s port %d", __func__, port->number);
551 576
552 usb_serial_generic_close(port); 577 if (port->serial->dev) {
553 if (port->serial->dev) 578 /* shutdown our urbs */
579 usb_kill_urb(port->write_urb);
580 usb_kill_urb(port->read_urb);
554 usb_kill_urb(port->interrupt_in_urb); 581 usb_kill_urb(port->interrupt_in_urb);
582 }
555} /* mct_u232_close */ 583} /* mct_u232_close */
556 584
557 585
@@ -618,6 +646,8 @@ static void mct_u232_read_int_callback(struct urb *urb)
618 /* Record Control Line states */ 646 /* Record Control Line states */
619 mct_u232_msr_to_state(&priv->control_state, priv->last_msr); 647 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
620 648
649 mct_u232_msr_to_icount(&priv->icount, priv->last_msr);
650
621#if 0 651#if 0
622 /* Not yet handled. See belkin_sa.c for further information */ 652 /* Not yet handled. See belkin_sa.c for further information */
623 /* Now to report any errors */ 653 /* Now to report any errors */
@@ -644,6 +674,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
644 tty_kref_put(tty); 674 tty_kref_put(tty);
645 } 675 }
646#endif 676#endif
677 wake_up_interruptible(&priv->msr_wait);
647 spin_unlock_irqrestore(&priv->lock, flags); 678 spin_unlock_irqrestore(&priv->lock, flags);
648exit: 679exit:
649 retval = usb_submit_urb(urb, GFP_ATOMIC); 680 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -759,7 +790,7 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
759} /* mct_u232_break_ctl */ 790} /* mct_u232_break_ctl */
760 791
761 792
762static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file) 793static int mct_u232_tiocmget(struct tty_struct *tty)
763{ 794{
764 struct usb_serial_port *port = tty->driver_data; 795 struct usb_serial_port *port = tty->driver_data;
765 struct mct_u232_private *priv = usb_get_serial_port_data(port); 796 struct mct_u232_private *priv = usb_get_serial_port_data(port);
@@ -775,7 +806,7 @@ static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file)
775 return control_state; 806 return control_state;
776} 807}
777 808
778static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file, 809static int mct_u232_tiocmset(struct tty_struct *tty,
779 unsigned int set, unsigned int clear) 810 unsigned int set, unsigned int clear)
780{ 811{
781 struct usb_serial_port *port = tty->driver_data; 812 struct usb_serial_port *port = tty->driver_data;
@@ -823,7 +854,6 @@ static void mct_u232_throttle(struct tty_struct *tty)
823 } 854 }
824} 855}
825 856
826
827static void mct_u232_unthrottle(struct tty_struct *tty) 857static void mct_u232_unthrottle(struct tty_struct *tty)
828{ 858{
829 struct usb_serial_port *port = tty->driver_data; 859 struct usb_serial_port *port = tty->driver_data;
@@ -844,6 +874,82 @@ static void mct_u232_unthrottle(struct tty_struct *tty)
844 } 874 }
845} 875}
846 876
877static int mct_u232_ioctl(struct tty_struct *tty,
878 unsigned int cmd, unsigned long arg)
879{
880 DEFINE_WAIT(wait);
881 struct usb_serial_port *port = tty->driver_data;
882 struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port);
883 struct async_icount cnow, cprev;
884 unsigned long flags;
885
886 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
887
888 switch (cmd) {
889
890 case TIOCMIWAIT:
891
892 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
893
894 spin_lock_irqsave(&mct_u232_port->lock, flags);
895 cprev = mct_u232_port->icount;
896 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
897 for ( ; ; ) {
898 prepare_to_wait(&mct_u232_port->msr_wait,
899 &wait, TASK_INTERRUPTIBLE);
900 schedule();
901 finish_wait(&mct_u232_port->msr_wait, &wait);
902 /* see if a signal did it */
903 if (signal_pending(current))
904 return -ERESTARTSYS;
905 spin_lock_irqsave(&mct_u232_port->lock, flags);
906 cnow = mct_u232_port->icount;
907 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
908 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
909 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
910 return -EIO; /* no change => error */
911 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
912 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
913 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
914 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
915 return 0;
916 }
917 cprev = cnow;
918 }
919
920 }
921 return -ENOIOCTLCMD;
922}
923
924static int mct_u232_get_icount(struct tty_struct *tty,
925 struct serial_icounter_struct *icount)
926{
927 struct usb_serial_port *port = tty->driver_data;
928 struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port);
929 struct async_icount *ic = &mct_u232_port->icount;
930 unsigned long flags;
931
932 spin_lock_irqsave(&mct_u232_port->lock, flags);
933
934 icount->cts = ic->cts;
935 icount->dsr = ic->dsr;
936 icount->rng = ic->rng;
937 icount->dcd = ic->dcd;
938 icount->rx = ic->rx;
939 icount->tx = ic->tx;
940 icount->frame = ic->frame;
941 icount->overrun = ic->overrun;
942 icount->parity = ic->parity;
943 icount->brk = ic->brk;
944 icount->buf_overrun = ic->buf_overrun;
945
946 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
947
948 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d",
949 __func__, port->number, icount->rx, icount->tx);
950 return 0;
951}
952
847static int __init mct_u232_init(void) 953static int __init mct_u232_init(void)
848{ 954{
849 int retval; 955 int retval;
diff --git a/drivers/usb/serial/mct_u232.h b/drivers/usb/serial/mct_u232.h
index 3a3f5e6b8f96..d325bb8cb583 100644
--- a/drivers/usb/serial/mct_u232.h
+++ b/drivers/usb/serial/mct_u232.h
@@ -10,10 +10,9 @@
10 * 10 *
11 * This driver is for the device MCT USB-RS232 Converter (25 pin, Model No. 11 * This driver is for the device MCT USB-RS232 Converter (25 pin, Model No.
12 * U232-P25) from Magic Control Technology Corp. (there is also a 9 pin 12 * U232-P25) from Magic Control Technology Corp. (there is also a 9 pin
13 * Model No. U232-P9). See http://www.mct.com.tw/p_u232.html for further 13 * Model No. U232-P9). See http://www.mct.com.tw/products/product_us232.html
14 * information. The properties of this device are listed at the end of this 14 * for further information. The properties of this device are listed at the end
15 * file. This device is available from various distributors. I know Hana, 15 * of this file. This device was used in the Dlink DSB-S25.
16 * http://www.hana.de and D-Link, http://www.dlink.com/products/usb/dsbs25.
17 * 16 *
18 * All of the information about the device was acquired by using SniffUSB 17 * All of the information about the device was acquired by using SniffUSB
19 * on Windows98. The technical details of the reverse engineering are 18 * on Windows98. The technical details of the reverse engineering are
@@ -458,7 +457,7 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
458 * embedded UART. Exhaustive documentation for these is available at: 457 * embedded UART. Exhaustive documentation for these is available at:
459 * 458 *
460 * http://www.semiconductors.philips.com/pip/p87c52ubaa 459 * http://www.semiconductors.philips.com/pip/p87c52ubaa
461 * http://www.semiconductors.philips.com/pip/pdiusbd12 460 * http://www.nxp.com/acrobat_download/various/PDIUSBD12_PROGRAMMING_GUIDE.pdf
462 * 461 *
463 * Thanks to Julian Highfield for the pointer to the Philips database. 462 * Thanks to Julian Highfield for the pointer to the Philips database.
464 * 463 *
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index aa665817a272..40abedbc5943 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -827,7 +827,6 @@ exit:
827 dev_err(&urb->dev->dev, 827 dev_err(&urb->dev->dev,
828 "%s - Error %d submitting control urb\n", 828 "%s - Error %d submitting control urb\n",
829 __func__, result); 829 __func__, result);
830 return;
831} 830}
832 831
833/* 832/*
@@ -907,7 +906,6 @@ exit:
907 dev_err(&urb->dev->dev, 906 dev_err(&urb->dev->dev,
908 "%s - Error %d submitting control urb\n", 907 "%s - Error %d submitting control urb\n",
909 __func__, result); 908 __func__, result);
910 return;
911} 909}
912 910
913/* 911/*
@@ -1227,8 +1225,6 @@ static void mos7720_break(struct tty_struct *tty, int break_state)
1227 mos7720_port->shadowLCR = data; 1225 mos7720_port->shadowLCR = data;
1228 write_mos_reg(serial, port->number - port->serial->minor, 1226 write_mos_reg(serial, port->number - port->serial->minor,
1229 LCR, mos7720_port->shadowLCR); 1227 LCR, mos7720_port->shadowLCR);
1230
1231 return;
1232} 1228}
1233 1229
1234/* 1230/*
@@ -1746,7 +1742,6 @@ static void change_port_settings(struct tty_struct *tty,
1746 dbg("usb_submit_urb(read bulk) failed, status = %d", 1742 dbg("usb_submit_urb(read bulk) failed, status = %d",
1747 status); 1743 status);
1748 } 1744 }
1749 return;
1750} 1745}
1751 1746
1752/* 1747/*
@@ -1803,7 +1798,6 @@ static void mos7720_set_termios(struct tty_struct *tty,
1803 dbg("usb_submit_urb(read bulk) failed, status = %d", 1798 dbg("usb_submit_urb(read bulk) failed, status = %d",
1804 status); 1799 status);
1805 } 1800 }
1806 return;
1807} 1801}
1808 1802
1809/* 1803/*
@@ -1839,7 +1833,7 @@ static int get_lsr_info(struct tty_struct *tty,
1839 return 0; 1833 return 0;
1840} 1834}
1841 1835
1842static int mos7720_tiocmget(struct tty_struct *tty, struct file *file) 1836static int mos7720_tiocmget(struct tty_struct *tty)
1843{ 1837{
1844 struct usb_serial_port *port = tty->driver_data; 1838 struct usb_serial_port *port = tty->driver_data;
1845 struct moschip_port *mos7720_port = usb_get_serial_port_data(port); 1839 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
@@ -1864,14 +1858,14 @@ static int mos7720_tiocmget(struct tty_struct *tty, struct file *file)
1864 return result; 1858 return result;
1865} 1859}
1866 1860
1867static int mos7720_tiocmset(struct tty_struct *tty, struct file *file, 1861static int mos7720_tiocmset(struct tty_struct *tty,
1868 unsigned int set, unsigned int clear) 1862 unsigned int set, unsigned int clear)
1869{ 1863{
1870 struct usb_serial_port *port = tty->driver_data; 1864 struct usb_serial_port *port = tty->driver_data;
1871 struct moschip_port *mos7720_port = usb_get_serial_port_data(port); 1865 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1872 unsigned int mcr ; 1866 unsigned int mcr ;
1873 dbg("%s - port %d", __func__, port->number); 1867 dbg("%s - port %d", __func__, port->number);
1874 dbg("he was at tiocmget"); 1868 dbg("he was at tiocmset");
1875 1869
1876 mcr = mos7720_port->shadowMCR; 1870 mcr = mos7720_port->shadowMCR;
1877 1871
@@ -1896,10 +1890,37 @@ static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
1896 return 0; 1890 return 0;
1897} 1891}
1898 1892
1893static int mos7720_get_icount(struct tty_struct *tty,
1894 struct serial_icounter_struct *icount)
1895{
1896 struct usb_serial_port *port = tty->driver_data;
1897 struct moschip_port *mos7720_port;
1898 struct async_icount cnow;
1899
1900 mos7720_port = usb_get_serial_port_data(port);
1901 cnow = mos7720_port->icount;
1902
1903 icount->cts = cnow.cts;
1904 icount->dsr = cnow.dsr;
1905 icount->rng = cnow.rng;
1906 icount->dcd = cnow.dcd;
1907 icount->rx = cnow.rx;
1908 icount->tx = cnow.tx;
1909 icount->frame = cnow.frame;
1910 icount->overrun = cnow.overrun;
1911 icount->parity = cnow.parity;
1912 icount->brk = cnow.brk;
1913 icount->buf_overrun = cnow.buf_overrun;
1914
1915 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
1916 port->number, icount->rx, icount->tx);
1917 return 0;
1918}
1919
1899static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd, 1920static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1900 unsigned int __user *value) 1921 unsigned int __user *value)
1901{ 1922{
1902 unsigned int mcr ; 1923 unsigned int mcr;
1903 unsigned int arg; 1924 unsigned int arg;
1904 1925
1905 struct usb_serial_port *port; 1926 struct usb_serial_port *port;
@@ -1966,14 +1987,13 @@ static int get_serial_info(struct moschip_port *mos7720_port,
1966 return 0; 1987 return 0;
1967} 1988}
1968 1989
1969static int mos7720_ioctl(struct tty_struct *tty, struct file *file, 1990static int mos7720_ioctl(struct tty_struct *tty,
1970 unsigned int cmd, unsigned long arg) 1991 unsigned int cmd, unsigned long arg)
1971{ 1992{
1972 struct usb_serial_port *port = tty->driver_data; 1993 struct usb_serial_port *port = tty->driver_data;
1973 struct moschip_port *mos7720_port; 1994 struct moschip_port *mos7720_port;
1974 struct async_icount cnow; 1995 struct async_icount cnow;
1975 struct async_icount cprev; 1996 struct async_icount cprev;
1976 struct serial_icounter_struct icount;
1977 1997
1978 mos7720_port = usb_get_serial_port_data(port); 1998 mos7720_port = usb_get_serial_port_data(port);
1979 if (mos7720_port == NULL) 1999 if (mos7720_port == NULL)
@@ -2021,29 +2041,6 @@ static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
2021 } 2041 }
2022 /* NOTREACHED */ 2042 /* NOTREACHED */
2023 break; 2043 break;
2024
2025 case TIOCGICOUNT:
2026 cnow = mos7720_port->icount;
2027
2028 memset(&icount, 0, sizeof(struct serial_icounter_struct));
2029
2030 icount.cts = cnow.cts;
2031 icount.dsr = cnow.dsr;
2032 icount.rng = cnow.rng;
2033 icount.dcd = cnow.dcd;
2034 icount.rx = cnow.rx;
2035 icount.tx = cnow.tx;
2036 icount.frame = cnow.frame;
2037 icount.overrun = cnow.overrun;
2038 icount.parity = cnow.parity;
2039 icount.brk = cnow.brk;
2040 icount.buf_overrun = cnow.buf_overrun;
2041
2042 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2043 port->number, icount.rx, icount.tx);
2044 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
2045 return -EFAULT;
2046 return 0;
2047 } 2044 }
2048 2045
2049 return -ENOIOCTLCMD; 2046 return -ENOIOCTLCMD;
@@ -2055,7 +2052,7 @@ static int mos7720_startup(struct usb_serial *serial)
2055 struct usb_device *dev; 2052 struct usb_device *dev;
2056 int i; 2053 int i;
2057 char data; 2054 char data;
2058 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); 2055 u16 product;
2059 int ret_val; 2056 int ret_val;
2060 2057
2061 dbg("%s: Entering ..........", __func__); 2058 dbg("%s: Entering ..........", __func__);
@@ -2065,6 +2062,7 @@ static int mos7720_startup(struct usb_serial *serial)
2065 return -ENODEV; 2062 return -ENODEV;
2066 } 2063 }
2067 2064
2065 product = le16_to_cpu(serial->dev->descriptor.idProduct);
2068 dev = serial->dev; 2066 dev = serial->dev;
2069 2067
2070 /* 2068 /*
@@ -2212,6 +2210,7 @@ static struct usb_serial_driver moschip7720_2port_driver = {
2212 .ioctl = mos7720_ioctl, 2210 .ioctl = mos7720_ioctl,
2213 .tiocmget = mos7720_tiocmget, 2211 .tiocmget = mos7720_tiocmget,
2214 .tiocmset = mos7720_tiocmset, 2212 .tiocmset = mos7720_tiocmset,
2213 .get_icount = mos7720_get_icount,
2215 .set_termios = mos7720_set_termios, 2214 .set_termios = mos7720_set_termios,
2216 .write = mos7720_write, 2215 .write = mos7720_write,
2217 .write_room = mos7720_write_room, 2216 .write_room = mos7720_write_room,
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 1a42bc213799..7b50aa122752 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1367,8 +1367,6 @@ static void mos7840_break(struct tty_struct *tty, int break_state)
1367 mos7840_port->shadowLCR); 1367 mos7840_port->shadowLCR);
1368 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, 1368 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER,
1369 mos7840_port->shadowLCR); 1369 mos7840_port->shadowLCR);
1370
1371 return;
1372} 1370}
1373 1371
1374/***************************************************************************** 1372/*****************************************************************************
@@ -1599,8 +1597,6 @@ static void mos7840_throttle(struct tty_struct *tty)
1599 if (status < 0) 1597 if (status < 0)
1600 return; 1598 return;
1601 } 1599 }
1602
1603 return;
1604} 1600}
1605 1601
1606/***************************************************************************** 1602/*****************************************************************************
@@ -1648,7 +1644,7 @@ static void mos7840_unthrottle(struct tty_struct *tty)
1648 } 1644 }
1649} 1645}
1650 1646
1651static int mos7840_tiocmget(struct tty_struct *tty, struct file *file) 1647static int mos7840_tiocmget(struct tty_struct *tty)
1652{ 1648{
1653 struct usb_serial_port *port = tty->driver_data; 1649 struct usb_serial_port *port = tty->driver_data;
1654 struct moschip_port *mos7840_port; 1650 struct moschip_port *mos7840_port;
@@ -1678,7 +1674,7 @@ static int mos7840_tiocmget(struct tty_struct *tty, struct file *file)
1678 return result; 1674 return result;
1679} 1675}
1680 1676
1681static int mos7840_tiocmset(struct tty_struct *tty, struct file *file, 1677static int mos7840_tiocmset(struct tty_struct *tty,
1682 unsigned int set, unsigned int clear) 1678 unsigned int set, unsigned int clear)
1683{ 1679{
1684 struct usb_serial_port *port = tty->driver_data; 1680 struct usb_serial_port *port = tty->driver_data;
@@ -2075,8 +2071,6 @@ static void mos7840_change_port_settings(struct tty_struct *tty,
2075 mos7840_port->delta_msr_cond = 1; 2071 mos7840_port->delta_msr_cond = 1;
2076 dbg("mos7840_change_port_settings mos7840_port->shadowLCR is End %x", 2072 dbg("mos7840_change_port_settings mos7840_port->shadowLCR is End %x",
2077 mos7840_port->shadowLCR); 2073 mos7840_port->shadowLCR);
2078
2079 return;
2080} 2074}
2081 2075
2082/***************************************************************************** 2076/*****************************************************************************
@@ -2145,7 +2139,6 @@ static void mos7840_set_termios(struct tty_struct *tty,
2145 mos7840_port->read_urb_busy = false; 2139 mos7840_port->read_urb_busy = false;
2146 } 2140 }
2147 } 2141 }
2148 return;
2149} 2142}
2150 2143
2151/***************************************************************************** 2144/*****************************************************************************
@@ -2209,12 +2202,40 @@ static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
2209 return 0; 2202 return 0;
2210} 2203}
2211 2204
2205static int mos7840_get_icount(struct tty_struct *tty,
2206 struct serial_icounter_struct *icount)
2207{
2208 struct usb_serial_port *port = tty->driver_data;
2209 struct moschip_port *mos7840_port;
2210 struct async_icount cnow;
2211
2212 mos7840_port = mos7840_get_port_private(port);
2213 cnow = mos7840_port->icount;
2214
2215 smp_rmb();
2216 icount->cts = cnow.cts;
2217 icount->dsr = cnow.dsr;
2218 icount->rng = cnow.rng;
2219 icount->dcd = cnow.dcd;
2220 icount->rx = cnow.rx;
2221 icount->tx = cnow.tx;
2222 icount->frame = cnow.frame;
2223 icount->overrun = cnow.overrun;
2224 icount->parity = cnow.parity;
2225 icount->brk = cnow.brk;
2226 icount->buf_overrun = cnow.buf_overrun;
2227
2228 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2229 port->number, icount->rx, icount->tx);
2230 return 0;
2231}
2232
2212/***************************************************************************** 2233/*****************************************************************************
2213 * SerialIoctl 2234 * SerialIoctl
2214 * this function handles any ioctl calls to the driver 2235 * this function handles any ioctl calls to the driver
2215 *****************************************************************************/ 2236 *****************************************************************************/
2216 2237
2217static int mos7840_ioctl(struct tty_struct *tty, struct file *file, 2238static int mos7840_ioctl(struct tty_struct *tty,
2218 unsigned int cmd, unsigned long arg) 2239 unsigned int cmd, unsigned long arg)
2219{ 2240{
2220 struct usb_serial_port *port = tty->driver_data; 2241 struct usb_serial_port *port = tty->driver_data;
@@ -2223,7 +2244,6 @@ static int mos7840_ioctl(struct tty_struct *tty, struct file *file,
2223 2244
2224 struct async_icount cnow; 2245 struct async_icount cnow;
2225 struct async_icount cprev; 2246 struct async_icount cprev;
2226 struct serial_icounter_struct icount;
2227 2247
2228 if (mos7840_port_paranoia_check(port, __func__)) { 2248 if (mos7840_port_paranoia_check(port, __func__)) {
2229 dbg("%s", "Invalid port"); 2249 dbg("%s", "Invalid port");
@@ -2282,29 +2302,6 @@ static int mos7840_ioctl(struct tty_struct *tty, struct file *file,
2282 /* NOTREACHED */ 2302 /* NOTREACHED */
2283 break; 2303 break;
2284 2304
2285 case TIOCGICOUNT:
2286 cnow = mos7840_port->icount;
2287 smp_rmb();
2288
2289 memset(&icount, 0, sizeof(struct serial_icounter_struct));
2290
2291 icount.cts = cnow.cts;
2292 icount.dsr = cnow.dsr;
2293 icount.rng = cnow.rng;
2294 icount.dcd = cnow.dcd;
2295 icount.rx = cnow.rx;
2296 icount.tx = cnow.tx;
2297 icount.frame = cnow.frame;
2298 icount.overrun = cnow.overrun;
2299 icount.parity = cnow.parity;
2300 icount.brk = cnow.brk;
2301 icount.buf_overrun = cnow.buf_overrun;
2302
2303 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2304 port->number, icount.rx, icount.tx);
2305 if (copy_to_user(argp, &icount, sizeof(icount)))
2306 return -EFAULT;
2307 return 0;
2308 default: 2305 default:
2309 break; 2306 break;
2310 } 2307 }
@@ -2674,6 +2671,7 @@ static struct usb_serial_driver moschip7840_4port_device = {
2674 .break_ctl = mos7840_break, 2671 .break_ctl = mos7840_break,
2675 .tiocmget = mos7840_tiocmget, 2672 .tiocmget = mos7840_tiocmget,
2676 .tiocmset = mos7840_tiocmset, 2673 .tiocmset = mos7840_tiocmset,
2674 .get_icount = mos7840_get_icount,
2677 .attach = mos7840_startup, 2675 .attach = mos7840_startup,
2678 .disconnect = mos7840_disconnect, 2676 .disconnect = mos7840_disconnect,
2679 .release = mos7840_release, 2677 .release = mos7840_release,
diff --git a/drivers/usb/serial/moto_modem.c b/drivers/usb/serial/moto_modem.c
index cf1718394e18..e2bfecc46402 100644
--- a/drivers/usb/serial/moto_modem.c
+++ b/drivers/usb/serial/moto_modem.c
@@ -25,6 +25,7 @@ static const struct usb_device_id id_table[] = {
25 { USB_DEVICE(0x05c6, 0x3197) }, /* unknown Motorola phone */ 25 { USB_DEVICE(0x05c6, 0x3197) }, /* unknown Motorola phone */
26 { USB_DEVICE(0x0c44, 0x0022) }, /* unknown Mororola phone */ 26 { USB_DEVICE(0x0c44, 0x0022) }, /* unknown Mororola phone */
27 { USB_DEVICE(0x22b8, 0x2a64) }, /* Motorola KRZR K1m */ 27 { USB_DEVICE(0x22b8, 0x2a64) }, /* Motorola KRZR K1m */
28 { USB_DEVICE(0x22b8, 0x2c84) }, /* Motorola VE240 phone */
28 { USB_DEVICE(0x22b8, 0x2c64) }, /* Motorola V950 phone */ 29 { USB_DEVICE(0x22b8, 0x2c64) }, /* Motorola V950 phone */
29 { }, 30 { },
30}; 31};
@@ -44,6 +45,7 @@ static struct usb_serial_driver moto_device = {
44 .name = "moto-modem", 45 .name = "moto-modem",
45 }, 46 },
46 .id_table = id_table, 47 .id_table = id_table,
48 .usb_driver = &moto_driver,
47 .num_ports = 1, 49 .num_ports = 1,
48}; 50};
49 51
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index 89c724c0ac0a..60f38d5e64fc 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -246,8 +246,6 @@ static void omninet_read_bulk_callback(struct urb *urb)
246 dev_err(&port->dev, 246 dev_err(&port->dev,
247 "%s - failed resubmitting read urb, error %d\n", 247 "%s - failed resubmitting read urb, error %d\n",
248 __func__, result); 248 __func__, result);
249
250 return;
251} 249}
252 250
253static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, 251static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index ed01f3b2de8c..96423f3c8ef3 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Opticon USB barcode to serial driver 2 * Opticon USB barcode to serial driver
3 * 3 *
4 * Copyright (C) 2011 Martin Jansen <martin.jansen@opticon.com>
4 * Copyright (C) 2008 - 2009 Greg Kroah-Hartman <gregkh@suse.de> 5 * Copyright (C) 2008 - 2009 Greg Kroah-Hartman <gregkh@suse.de>
5 * Copyright (C) 2008 - 2009 Novell Inc. 6 * Copyright (C) 2008 - 2009 Novell Inc.
6 * 7 *
@@ -21,6 +22,16 @@
21#include <linux/usb/serial.h> 22#include <linux/usb/serial.h>
22#include <linux/uaccess.h> 23#include <linux/uaccess.h>
23 24
25#define CONTROL_RTS 0x02
26#define RESEND_CTS_STATE 0x03
27
28/* max number of write urbs in flight */
29#define URB_UPPER_LIMIT 8
30
31/* This driver works for the Opticon 1D barcode reader
32 * an examples of 1D barcode types are EAN, UPC, Code39, IATA etc.. */
33#define DRIVER_DESC "Opticon USB barcode to serial driver (1D)"
34
24static int debug; 35static int debug;
25 36
26static const struct usb_device_id id_table[] = { 37static const struct usb_device_id id_table[] = {
@@ -42,13 +53,13 @@ struct opticon_private {
42 bool throttled; 53 bool throttled;
43 bool actually_throttled; 54 bool actually_throttled;
44 bool rts; 55 bool rts;
56 bool cts;
45 int outstanding_urbs; 57 int outstanding_urbs;
46}; 58};
47 59
48/* max number of write urbs in flight */
49#define URB_UPPER_LIMIT 4
50 60
51static void opticon_bulk_callback(struct urb *urb) 61
62static void opticon_read_bulk_callback(struct urb *urb)
52{ 63{
53 struct opticon_private *priv = urb->context; 64 struct opticon_private *priv = urb->context;
54 unsigned char *data = urb->transfer_buffer; 65 unsigned char *data = urb->transfer_buffer;
@@ -57,6 +68,7 @@ static void opticon_bulk_callback(struct urb *urb)
57 struct tty_struct *tty; 68 struct tty_struct *tty;
58 int result; 69 int result;
59 int data_length; 70 int data_length;
71 unsigned long flags;
60 72
61 dbg("%s - port %d", __func__, port->number); 73 dbg("%s - port %d", __func__, port->number);
62 74
@@ -87,31 +99,34 @@ static void opticon_bulk_callback(struct urb *urb)
87 * Data from the device comes with a 2 byte header: 99 * Data from the device comes with a 2 byte header:
88 * 100 *
89 * <0x00><0x00>data... 101 * <0x00><0x00>data...
90 * This is real data to be sent to the tty layer 102 * This is real data to be sent to the tty layer
91 * <0x00><0x01)level 103 * <0x00><0x01)level
92 * This is a RTS level change, the third byte is the RTS 104 * This is a CTS level change, the third byte is the CTS
93 * value (0 for low, 1 for high). 105 * value (0 for low, 1 for high).
94 */ 106 */
95 if ((data[0] == 0x00) && (data[1] == 0x00)) { 107 if ((data[0] == 0x00) && (data[1] == 0x00)) {
96 /* real data, send it to the tty layer */ 108 /* real data, send it to the tty layer */
97 tty = tty_port_tty_get(&port->port); 109 tty = tty_port_tty_get(&port->port);
98 if (tty) { 110 if (tty) {
99 tty_insert_flip_string(tty, data, 111 tty_insert_flip_string(tty, data + 2,
100 data_length); 112 data_length);
101 tty_flip_buffer_push(tty); 113 tty_flip_buffer_push(tty);
102 tty_kref_put(tty); 114 tty_kref_put(tty);
103 } 115 }
104 } else { 116 } else {
105 if ((data[0] == 0x00) && (data[1] == 0x01)) { 117 if ((data[0] == 0x00) && (data[1] == 0x01)) {
118 spin_lock_irqsave(&priv->lock, flags);
119 /* CTS status information package */
106 if (data[2] == 0x00) 120 if (data[2] == 0x00)
107 priv->rts = false; 121 priv->cts = false;
108 else 122 else
109 priv->rts = true; 123 priv->cts = true;
124 spin_unlock_irqrestore(&priv->lock, flags);
110 } else { 125 } else {
111 dev_dbg(&priv->udev->dev, 126 dev_dbg(&priv->udev->dev,
112 "Unknown data packet received from the device:" 127 "Unknown data packet received from the device:"
113 " %2x %2x\n", 128 " %2x %2x\n",
114 data[0], data[1]); 129 data[0], data[1]);
115 } 130 }
116 } 131 }
117 } else { 132 } else {
@@ -129,8 +144,8 @@ exit:
129 usb_rcvbulkpipe(priv->udev, 144 usb_rcvbulkpipe(priv->udev,
130 priv->bulk_address), 145 priv->bulk_address),
131 priv->bulk_in_buffer, priv->buffer_size, 146 priv->bulk_in_buffer, priv->buffer_size,
132 opticon_bulk_callback, priv); 147 opticon_read_bulk_callback, priv);
133 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 148 result = usb_submit_urb(priv->bulk_read_urb, GFP_ATOMIC);
134 if (result) 149 if (result)
135 dev_err(&port->dev, 150 dev_err(&port->dev,
136 "%s - failed resubmitting read urb, error %d\n", 151 "%s - failed resubmitting read urb, error %d\n",
@@ -140,6 +155,24 @@ exit:
140 spin_unlock(&priv->lock); 155 spin_unlock(&priv->lock);
141} 156}
142 157
158static int send_control_msg(struct usb_serial_port *port, u8 requesttype,
159 u8 val)
160{
161 struct usb_serial *serial = port->serial;
162 int retval;
163 u8 buffer[2];
164
165 buffer[0] = val;
166 /* Send the message to the vendor control endpoint
167 * of the connected device */
168 retval = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
169 requesttype,
170 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
171 0, 0, buffer, 1, 0);
172
173 return retval;
174}
175
143static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) 176static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
144{ 177{
145 struct opticon_private *priv = usb_get_serial_data(port->serial); 178 struct opticon_private *priv = usb_get_serial_data(port->serial);
@@ -152,19 +185,30 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
152 priv->throttled = false; 185 priv->throttled = false;
153 priv->actually_throttled = false; 186 priv->actually_throttled = false;
154 priv->port = port; 187 priv->port = port;
188 priv->rts = false;
155 spin_unlock_irqrestore(&priv->lock, flags); 189 spin_unlock_irqrestore(&priv->lock, flags);
156 190
157 /* Start reading from the device */ 191 /* Clear RTS line */
192 send_control_msg(port, CONTROL_RTS, 0);
193
194 /* Setup the read URB and start reading from the device */
158 usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev, 195 usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev,
159 usb_rcvbulkpipe(priv->udev, 196 usb_rcvbulkpipe(priv->udev,
160 priv->bulk_address), 197 priv->bulk_address),
161 priv->bulk_in_buffer, priv->buffer_size, 198 priv->bulk_in_buffer, priv->buffer_size,
162 opticon_bulk_callback, priv); 199 opticon_read_bulk_callback, priv);
200
201 /* clear the halt status of the enpoint */
202 usb_clear_halt(priv->udev, priv->bulk_read_urb->pipe);
203
163 result = usb_submit_urb(priv->bulk_read_urb, GFP_KERNEL); 204 result = usb_submit_urb(priv->bulk_read_urb, GFP_KERNEL);
164 if (result) 205 if (result)
165 dev_err(&port->dev, 206 dev_err(&port->dev,
166 "%s - failed resubmitting read urb, error %d\n", 207 "%s - failed resubmitting read urb, error %d\n",
167 __func__, result); 208 __func__, result);
209 /* Request CTS line state, sometimes during opening the current
210 * CTS state can be missed. */
211 send_control_msg(port, RESEND_CTS_STATE, 1);
168 return result; 212 return result;
169} 213}
170 214
@@ -178,7 +222,7 @@ static void opticon_close(struct usb_serial_port *port)
178 usb_kill_urb(priv->bulk_read_urb); 222 usb_kill_urb(priv->bulk_read_urb);
179} 223}
180 224
181static void opticon_write_bulk_callback(struct urb *urb) 225static void opticon_write_control_callback(struct urb *urb)
182{ 226{
183 struct opticon_private *priv = urb->context; 227 struct opticon_private *priv = urb->context;
184 int status = urb->status; 228 int status = urb->status;
@@ -187,6 +231,9 @@ static void opticon_write_bulk_callback(struct urb *urb)
187 /* free up the transfer buffer, as usb_free_urb() does not do this */ 231 /* free up the transfer buffer, as usb_free_urb() does not do this */
188 kfree(urb->transfer_buffer); 232 kfree(urb->transfer_buffer);
189 233
234 /* setup packet may be set if we're using it for writing */
235 kfree(urb->setup_packet);
236
190 if (status) 237 if (status)
191 dbg("%s - nonzero write bulk status received: %d", 238 dbg("%s - nonzero write bulk status received: %d",
192 __func__, status); 239 __func__, status);
@@ -207,6 +254,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
207 unsigned char *buffer; 254 unsigned char *buffer;
208 unsigned long flags; 255 unsigned long flags;
209 int status; 256 int status;
257 struct usb_ctrlrequest *dr;
210 258
211 dbg("%s - port %d", __func__, port->number); 259 dbg("%s - port %d", __func__, port->number);
212 260
@@ -223,6 +271,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
223 if (!buffer) { 271 if (!buffer) {
224 dev_err(&port->dev, "out of memory\n"); 272 dev_err(&port->dev, "out of memory\n");
225 count = -ENOMEM; 273 count = -ENOMEM;
274
226 goto error_no_buffer; 275 goto error_no_buffer;
227 } 276 }
228 277
@@ -237,16 +286,31 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
237 286
238 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); 287 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
239 288
240 usb_fill_bulk_urb(urb, serial->dev, 289 /* The conncected devices do not have a bulk write endpoint,
241 usb_sndbulkpipe(serial->dev, 290 * to transmit data to de barcode device the control endpoint is used */
242 port->bulk_out_endpointAddress), 291 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
243 buffer, count, opticon_write_bulk_callback, priv); 292 if (!dr) {
293 dev_err(&port->dev, "out of memory\n");
294 count = -ENOMEM;
295 goto error;
296 }
297
298 dr->bRequestType = USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT;
299 dr->bRequest = 0x01;
300 dr->wValue = 0;
301 dr->wIndex = 0;
302 dr->wLength = cpu_to_le16(count);
303
304 usb_fill_control_urb(urb, serial->dev,
305 usb_sndctrlpipe(serial->dev, 0),
306 (unsigned char *)dr, buffer, count,
307 opticon_write_control_callback, priv);
244 308
245 /* send it down the pipe */ 309 /* send it down the pipe */
246 status = usb_submit_urb(urb, GFP_ATOMIC); 310 status = usb_submit_urb(urb, GFP_ATOMIC);
247 if (status) { 311 if (status) {
248 dev_err(&port->dev, 312 dev_err(&port->dev,
249 "%s - usb_submit_urb(write bulk) failed with status = %d\n", 313 "%s - usb_submit_urb(write endpoint) failed status = %d\n",
250 __func__, status); 314 __func__, status);
251 count = status; 315 count = status;
252 goto error; 316 goto error;
@@ -330,7 +394,7 @@ static void opticon_unthrottle(struct tty_struct *tty)
330 } 394 }
331} 395}
332 396
333static int opticon_tiocmget(struct tty_struct *tty, struct file *file) 397static int opticon_tiocmget(struct tty_struct *tty)
334{ 398{
335 struct usb_serial_port *port = tty->driver_data; 399 struct usb_serial_port *port = tty->driver_data;
336 struct opticon_private *priv = usb_get_serial_data(port->serial); 400 struct opticon_private *priv = usb_get_serial_data(port->serial);
@@ -338,16 +402,49 @@ static int opticon_tiocmget(struct tty_struct *tty, struct file *file)
338 int result = 0; 402 int result = 0;
339 403
340 dbg("%s - port %d", __func__, port->number); 404 dbg("%s - port %d", __func__, port->number);
405 if (!usb_get_intfdata(port->serial->interface))
406 return -ENODEV;
341 407
342 spin_lock_irqsave(&priv->lock, flags); 408 spin_lock_irqsave(&priv->lock, flags);
343 if (priv->rts) 409 if (priv->rts)
344 result = TIOCM_RTS; 410 result |= TIOCM_RTS;
411 if (priv->cts)
412 result |= TIOCM_CTS;
345 spin_unlock_irqrestore(&priv->lock, flags); 413 spin_unlock_irqrestore(&priv->lock, flags);
346 414
347 dbg("%s - %x", __func__, result); 415 dbg("%s - %x", __func__, result);
348 return result; 416 return result;
349} 417}
350 418
419static int opticon_tiocmset(struct tty_struct *tty,
420 unsigned int set, unsigned int clear)
421{
422 struct usb_serial_port *port = tty->driver_data;
423 struct opticon_private *priv = usb_get_serial_data(port->serial);
424 unsigned long flags;
425 bool rts;
426 bool changed = false;
427
428 if (!usb_get_intfdata(port->serial->interface))
429 return -ENODEV;
430 /* We only support RTS so we only handle that */
431 spin_lock_irqsave(&priv->lock, flags);
432
433 rts = priv->rts;
434 if (set & TIOCM_RTS)
435 priv->rts = true;
436 if (clear & TIOCM_RTS)
437 priv->rts = false;
438 changed = rts ^ priv->rts;
439 spin_unlock_irqrestore(&priv->lock, flags);
440
441 if (!changed)
442 return 0;
443
444 /* Send the new RTS state to the connected device */
445 return send_control_msg(port, CONTROL_RTS, !rts);
446}
447
351static int get_serial_info(struct opticon_private *priv, 448static int get_serial_info(struct opticon_private *priv,
352 struct serial_struct __user *serial) 449 struct serial_struct __user *serial)
353{ 450{
@@ -374,7 +471,7 @@ static int get_serial_info(struct opticon_private *priv,
374 return 0; 471 return 0;
375} 472}
376 473
377static int opticon_ioctl(struct tty_struct *tty, struct file *file, 474static int opticon_ioctl(struct tty_struct *tty,
378 unsigned int cmd, unsigned long arg) 475 unsigned int cmd, unsigned long arg)
379{ 476{
380 struct usb_serial_port *port = tty->driver_data; 477 struct usb_serial_port *port = tty->driver_data;
@@ -409,6 +506,7 @@ static int opticon_startup(struct usb_serial *serial)
409 priv->serial = serial; 506 priv->serial = serial;
410 priv->port = serial->port[0]; 507 priv->port = serial->port[0];
411 priv->udev = serial->dev; 508 priv->udev = serial->dev;
509 priv->outstanding_urbs = 0; /* Init the outstanding urbs */
412 510
413 /* find our bulk endpoint */ 511 /* find our bulk endpoint */
414 intf = serial->interface->altsetting; 512 intf = serial->interface->altsetting;
@@ -434,13 +532,6 @@ static int opticon_startup(struct usb_serial *serial)
434 532
435 priv->bulk_address = endpoint->bEndpointAddress; 533 priv->bulk_address = endpoint->bEndpointAddress;
436 534
437 /* set up our bulk urb */
438 usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev,
439 usb_rcvbulkpipe(priv->udev,
440 endpoint->bEndpointAddress),
441 priv->bulk_in_buffer, priv->buffer_size,
442 opticon_bulk_callback, priv);
443
444 bulk_in_found = true; 535 bulk_in_found = true;
445 break; 536 break;
446 } 537 }
@@ -536,6 +627,7 @@ static struct usb_serial_driver opticon_device = {
536 .unthrottle = opticon_unthrottle, 627 .unthrottle = opticon_unthrottle,
537 .ioctl = opticon_ioctl, 628 .ioctl = opticon_ioctl,
538 .tiocmget = opticon_tiocmget, 629 .tiocmget = opticon_tiocmget,
630 .tiocmset = opticon_tiocmset,
539}; 631};
540 632
541static int __init opticon_init(void) 633static int __init opticon_init(void)
@@ -559,6 +651,7 @@ static void __exit opticon_exit(void)
559 651
560module_init(opticon_init); 652module_init(opticon_init);
561module_exit(opticon_exit); 653module_exit(opticon_exit);
654MODULE_DESCRIPTION(DRIVER_DESC);
562MODULE_LICENSE("GPL"); 655MODULE_LICENSE("GPL");
563 656
564module_param(debug, bool, S_IRUGO | S_IWUSR); 657module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index c46911af282f..60b25d8ea0e2 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -149,6 +149,7 @@ static void option_instat_callback(struct urb *urb);
149#define HUAWEI_PRODUCT_K3765 0x1465 149#define HUAWEI_PRODUCT_K3765 0x1465
150#define HUAWEI_PRODUCT_E14AC 0x14AC 150#define HUAWEI_PRODUCT_E14AC 0x14AC
151#define HUAWEI_PRODUCT_ETS1220 0x1803 151#define HUAWEI_PRODUCT_ETS1220 0x1803
152#define HUAWEI_PRODUCT_E353 0x1506
152 153
153#define QUANTA_VENDOR_ID 0x0408 154#define QUANTA_VENDOR_ID 0x0408
154#define QUANTA_PRODUCT_Q101 0xEA02 155#define QUANTA_PRODUCT_Q101 0xEA02
@@ -310,10 +311,6 @@ static void option_instat_callback(struct urb *urb);
310#define ZTE_PRODUCT_AC2726 0xfff5 311#define ZTE_PRODUCT_AC2726 0xfff5
311#define ZTE_PRODUCT_AC8710T 0xffff 312#define ZTE_PRODUCT_AC8710T 0xffff
312 313
313/* ZTE PRODUCTS -- alternate vendor ID */
314#define ZTE_VENDOR_ID2 0x1d6b
315#define ZTE_PRODUCT_MF_330 0x0002
316
317#define BENQ_VENDOR_ID 0x04a5 314#define BENQ_VENDOR_ID 0x04a5
318#define BENQ_PRODUCT_H10 0x4068 315#define BENQ_PRODUCT_H10 0x4068
319 316
@@ -339,11 +336,12 @@ static void option_instat_callback(struct urb *urb);
339#define TOSHIBA_PRODUCT_G450 0x0d45 336#define TOSHIBA_PRODUCT_G450 0x0d45
340 337
341#define ALINK_VENDOR_ID 0x1e0e 338#define ALINK_VENDOR_ID 0x1e0e
339#define ALINK_PRODUCT_PH300 0x9100
342#define ALINK_PRODUCT_3GU 0x9200 340#define ALINK_PRODUCT_3GU 0x9200
343 341
344/* ALCATEL PRODUCTS */ 342/* ALCATEL PRODUCTS */
345#define ALCATEL_VENDOR_ID 0x1bbb 343#define ALCATEL_VENDOR_ID 0x1bbb
346#define ALCATEL_PRODUCT_X060S 0x0000 344#define ALCATEL_PRODUCT_X060S_X200 0x0000
347 345
348#define PIRELLI_VENDOR_ID 0x1266 346#define PIRELLI_VENDOR_ID 0x1266
349#define PIRELLI_PRODUCT_C100_1 0x1002 347#define PIRELLI_PRODUCT_C100_1 0x1002
@@ -378,11 +376,23 @@ static void option_instat_callback(struct urb *urb);
378 * It seems to contain a Qualcomm QSC6240/6290 chipset */ 376 * It seems to contain a Qualcomm QSC6240/6290 chipset */
379#define FOUR_G_SYSTEMS_PRODUCT_W14 0x9603 377#define FOUR_G_SYSTEMS_PRODUCT_W14 0x9603
380 378
379/* Zoom */
380#define ZOOM_PRODUCT_4597 0x9607
381
381/* Haier products */ 382/* Haier products */
382#define HAIER_VENDOR_ID 0x201e 383#define HAIER_VENDOR_ID 0x201e
383#define HAIER_PRODUCT_CE100 0x2009 384#define HAIER_PRODUCT_CE100 0x2009
384 385
385#define CINTERION_VENDOR_ID 0x0681 386/* Cinterion (formerly Siemens) products */
387#define SIEMENS_VENDOR_ID 0x0681
388#define CINTERION_VENDOR_ID 0x1e2d
389#define CINTERION_PRODUCT_HC25_MDM 0x0047
390#define CINTERION_PRODUCT_HC25_MDMNET 0x0040
391#define CINTERION_PRODUCT_HC28_MDM 0x004C
392#define CINTERION_PRODUCT_HC28_MDMNET 0x004A /* same for HC28J */
393#define CINTERION_PRODUCT_EU3_E 0x0051
394#define CINTERION_PRODUCT_EU3_P 0x0052
395#define CINTERION_PRODUCT_PH8 0x0053
386 396
387/* Olivetti products */ 397/* Olivetti products */
388#define OLIVETTI_VENDOR_ID 0x0b3c 398#define OLIVETTI_VENDOR_ID 0x0b3c
@@ -392,6 +402,16 @@ static void option_instat_callback(struct urb *urb);
392#define CELOT_VENDOR_ID 0x211f 402#define CELOT_VENDOR_ID 0x211f
393#define CELOT_PRODUCT_CT680M 0x6801 403#define CELOT_PRODUCT_CT680M 0x6801
394 404
405/* ONDA Communication vendor id */
406#define ONDA_VENDOR_ID 0x1ee8
407
408/* ONDA MT825UP HSDPA 14.2 modem */
409#define ONDA_MT825UP 0x000b
410
411/* Samsung products */
412#define SAMSUNG_VENDOR_ID 0x04e8
413#define SAMSUNG_PRODUCT_GT_B3730 0x6889
414
395/* some devices interfaces need special handling due to a number of reasons */ 415/* some devices interfaces need special handling due to a number of reasons */
396enum option_blacklist_reason { 416enum option_blacklist_reason {
397 OPTION_BLACKLIST_NONE = 0, 417 OPTION_BLACKLIST_NONE = 0,
@@ -412,6 +432,20 @@ static const struct option_blacklist_info four_g_w14_blacklist = {
412 .reason = OPTION_BLACKLIST_SENDSETUP 432 .reason = OPTION_BLACKLIST_SENDSETUP
413}; 433};
414 434
435static const u8 alcatel_x200_no_sendsetup[] = { 0, 1 };
436static const struct option_blacklist_info alcatel_x200_blacklist = {
437 .infolen = ARRAY_SIZE(alcatel_x200_no_sendsetup),
438 .ifaceinfo = alcatel_x200_no_sendsetup,
439 .reason = OPTION_BLACKLIST_SENDSETUP
440};
441
442static const u8 zte_k3765_z_no_sendsetup[] = { 0, 1, 2 };
443static const struct option_blacklist_info zte_k3765_z_blacklist = {
444 .infolen = ARRAY_SIZE(zte_k3765_z_no_sendsetup),
445 .ifaceinfo = zte_k3765_z_no_sendsetup,
446 .reason = OPTION_BLACKLIST_SENDSETUP
447};
448
415static const struct usb_device_id option_ids[] = { 449static const struct usb_device_id option_ids[] = {
416 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) }, 450 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
417 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) }, 451 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
@@ -512,7 +546,8 @@ static const struct usb_device_id option_ids[] = {
512 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff) }, 546 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff) },
513 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff) }, 547 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff) },
514 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ETS1220, 0xff, 0xff, 0xff) }, 548 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ETS1220, 0xff, 0xff, 0xff) },
515 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC) }, 549 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC, 0xff, 0xff, 0xff) },
550 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x01) },
516 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, 551 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) },
517 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) }, 552 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) },
518 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) }, 553 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) },
@@ -609,7 +644,6 @@ static const struct usb_device_id option_ids[] = {
609 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0004, 0xff, 0xff, 0xff) }, 644 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0004, 0xff, 0xff, 0xff) },
610 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0005, 0xff, 0xff, 0xff) }, 645 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0005, 0xff, 0xff, 0xff) },
611 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0006, 0xff, 0xff, 0xff) }, 646 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0006, 0xff, 0xff, 0xff) },
612 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0007, 0xff, 0xff, 0xff) },
613 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0008, 0xff, 0xff, 0xff) }, 647 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0008, 0xff, 0xff, 0xff) },
614 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0009, 0xff, 0xff, 0xff) }, 648 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0009, 0xff, 0xff, 0xff) },
615 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x000a, 0xff, 0xff, 0xff) }, 649 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x000a, 0xff, 0xff, 0xff) },
@@ -622,6 +656,7 @@ static const struct usb_device_id option_ids[] = {
622 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0011, 0xff, 0xff, 0xff) }, 656 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0011, 0xff, 0xff, 0xff) },
623 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0012, 0xff, 0xff, 0xff) }, 657 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0012, 0xff, 0xff, 0xff) },
624 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0013, 0xff, 0xff, 0xff) }, 658 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0013, 0xff, 0xff, 0xff) },
659 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0014, 0xff, 0xff, 0xff) },
625 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF628, 0xff, 0xff, 0xff) }, 660 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF628, 0xff, 0xff, 0xff) },
626 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0016, 0xff, 0xff, 0xff) }, 661 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0016, 0xff, 0xff, 0xff) },
627 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0017, 0xff, 0xff, 0xff) }, 662 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0017, 0xff, 0xff, 0xff) },
@@ -633,38 +668,53 @@ static const struct usb_device_id option_ids[] = {
633 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0023, 0xff, 0xff, 0xff) }, 668 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0023, 0xff, 0xff, 0xff) },
634 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0024, 0xff, 0xff, 0xff) }, 669 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0024, 0xff, 0xff, 0xff) },
635 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0025, 0xff, 0xff, 0xff) }, 670 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0025, 0xff, 0xff, 0xff) },
636 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0026, 0xff, 0xff, 0xff) }, 671 /* { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0026, 0xff, 0xff, 0xff) }, */
637 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0028, 0xff, 0xff, 0xff) }, 672 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0028, 0xff, 0xff, 0xff) },
638 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0029, 0xff, 0xff, 0xff) }, 673 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0029, 0xff, 0xff, 0xff) },
639 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0030, 0xff, 0xff, 0xff) }, 674 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0030, 0xff, 0xff, 0xff) },
640 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF626, 0xff, 0xff, 0xff) }, 675 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF626, 0xff,
676 0xff, 0xff), .driver_info = (kernel_ulong_t)&four_g_w14_blacklist },
641 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0032, 0xff, 0xff, 0xff) }, 677 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0032, 0xff, 0xff, 0xff) },
642 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0033, 0xff, 0xff, 0xff) }, 678 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0033, 0xff, 0xff, 0xff) },
679 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0034, 0xff, 0xff, 0xff) },
643 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0037, 0xff, 0xff, 0xff) }, 680 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0037, 0xff, 0xff, 0xff) },
681 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0038, 0xff, 0xff, 0xff) },
644 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0039, 0xff, 0xff, 0xff) }, 682 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0039, 0xff, 0xff, 0xff) },
683 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0040, 0xff, 0xff, 0xff) },
645 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0042, 0xff, 0xff, 0xff) }, 684 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0042, 0xff, 0xff, 0xff) },
646 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0043, 0xff, 0xff, 0xff) }, 685 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0043, 0xff, 0xff, 0xff) },
686 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0044, 0xff, 0xff, 0xff) },
647 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0048, 0xff, 0xff, 0xff) }, 687 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0048, 0xff, 0xff, 0xff) },
648 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0049, 0xff, 0xff, 0xff) }, 688 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0049, 0xff, 0xff, 0xff) },
689 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0050, 0xff, 0xff, 0xff) },
649 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0051, 0xff, 0xff, 0xff) }, 690 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0051, 0xff, 0xff, 0xff) },
650 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0052, 0xff, 0xff, 0xff) }, 691 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0052, 0xff, 0xff, 0xff) },
692 /* { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0053, 0xff, 0xff, 0xff) }, */
651 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0054, 0xff, 0xff, 0xff) }, 693 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0054, 0xff, 0xff, 0xff) },
652 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0055, 0xff, 0xff, 0xff) }, 694 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0055, 0xff, 0xff, 0xff) },
695 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0056, 0xff, 0xff, 0xff) },
653 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0057, 0xff, 0xff, 0xff) }, 696 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0057, 0xff, 0xff, 0xff) },
654 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0058, 0xff, 0xff, 0xff) }, 697 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0058, 0xff, 0xff, 0xff) },
698 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0059, 0xff, 0xff, 0xff) },
655 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0061, 0xff, 0xff, 0xff) }, 699 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0061, 0xff, 0xff, 0xff) },
656 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0062, 0xff, 0xff, 0xff) }, 700 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0062, 0xff, 0xff, 0xff) },
657 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0063, 0xff, 0xff, 0xff) }, 701 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0063, 0xff, 0xff, 0xff) },
658 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0064, 0xff, 0xff, 0xff) }, 702 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0064, 0xff, 0xff, 0xff) },
703 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0065, 0xff, 0xff, 0xff) },
659 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0066, 0xff, 0xff, 0xff) }, 704 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0066, 0xff, 0xff, 0xff) },
705 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0067, 0xff, 0xff, 0xff) },
660 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0069, 0xff, 0xff, 0xff) }, 706 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0069, 0xff, 0xff, 0xff) },
707 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0070, 0xff, 0xff, 0xff) },
661 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0076, 0xff, 0xff, 0xff) }, 708 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0076, 0xff, 0xff, 0xff) },
709 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0077, 0xff, 0xff, 0xff) },
662 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0078, 0xff, 0xff, 0xff) }, 710 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0078, 0xff, 0xff, 0xff) },
711 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0079, 0xff, 0xff, 0xff) },
663 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0082, 0xff, 0xff, 0xff) }, 712 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0082, 0xff, 0xff, 0xff) },
713 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0083, 0xff, 0xff, 0xff) },
664 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0086, 0xff, 0xff, 0xff) }, 714 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0086, 0xff, 0xff, 0xff) },
665 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff, 0xff, 0xff) }, 715 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0087, 0xff, 0xff, 0xff) },
666 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) },
667 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0104, 0xff, 0xff, 0xff) }, 716 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0104, 0xff, 0xff, 0xff) },
717 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0105, 0xff, 0xff, 0xff) },
668 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0106, 0xff, 0xff, 0xff) }, 718 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0106, 0xff, 0xff, 0xff) },
669 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0108, 0xff, 0xff, 0xff) }, 719 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0108, 0xff, 0xff, 0xff) },
670 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0113, 0xff, 0xff, 0xff) }, 720 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0113, 0xff, 0xff, 0xff) },
@@ -880,11 +930,13 @@ static const struct usb_device_id option_ids[] = {
880 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) }, 930 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) },
881 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0130, 0xff, 0xff, 0xff) }, 931 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0130, 0xff, 0xff, 0xff) },
882 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0141, 0xff, 0xff, 0xff) }, 932 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0141, 0xff, 0xff, 0xff) },
933 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff,
934 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist },
935 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) },
883 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) }, 936 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) },
884 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) }, 937 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) },
885 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) }, 938 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) },
886 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710T, 0xff, 0xff, 0xff) }, 939 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710T, 0xff, 0xff, 0xff) },
887 { USB_DEVICE(ZTE_VENDOR_ID2, ZTE_PRODUCT_MF_330) },
888 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) }, 940 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) },
889 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) }, 941 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) },
890 { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5) }, /* Yes, ALINK_VENDOR_ID */ 942 { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5) }, /* Yes, ALINK_VENDOR_ID */
@@ -897,13 +949,17 @@ static const struct usb_device_id option_ids[] = {
897 { USB_DEVICE(TOSHIBA_VENDOR_ID, TOSHIBA_PRODUCT_G450) }, 949 { USB_DEVICE(TOSHIBA_VENDOR_ID, TOSHIBA_PRODUCT_G450) },
898 { USB_DEVICE(TOSHIBA_VENDOR_ID, TOSHIBA_PRODUCT_HSDPA_MINICARD ) }, /* Toshiba 3G HSDPA == Novatel Expedite EU870D MiniCard */ 950 { USB_DEVICE(TOSHIBA_VENDOR_ID, TOSHIBA_PRODUCT_HSDPA_MINICARD ) }, /* Toshiba 3G HSDPA == Novatel Expedite EU870D MiniCard */
899 { USB_DEVICE(ALINK_VENDOR_ID, 0x9000) }, 951 { USB_DEVICE(ALINK_VENDOR_ID, 0x9000) },
952 { USB_DEVICE(ALINK_VENDOR_ID, ALINK_PRODUCT_PH300) },
900 { USB_DEVICE_AND_INTERFACE_INFO(ALINK_VENDOR_ID, ALINK_PRODUCT_3GU, 0xff, 0xff, 0xff) }, 953 { USB_DEVICE_AND_INTERFACE_INFO(ALINK_VENDOR_ID, ALINK_PRODUCT_3GU, 0xff, 0xff, 0xff) },
901 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_X060S) }, 954 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_X060S_X200),
955 .driver_info = (kernel_ulong_t)&alcatel_x200_blacklist
956 },
902 { USB_DEVICE(AIRPLUS_VENDOR_ID, AIRPLUS_PRODUCT_MCD650) }, 957 { USB_DEVICE(AIRPLUS_VENDOR_ID, AIRPLUS_PRODUCT_MCD650) },
903 { USB_DEVICE(TLAYTECH_VENDOR_ID, TLAYTECH_PRODUCT_TEU800) }, 958 { USB_DEVICE(TLAYTECH_VENDOR_ID, TLAYTECH_PRODUCT_TEU800) },
904 { USB_DEVICE(LONGCHEER_VENDOR_ID, FOUR_G_SYSTEMS_PRODUCT_W14), 959 { USB_DEVICE(LONGCHEER_VENDOR_ID, FOUR_G_SYSTEMS_PRODUCT_W14),
905 .driver_info = (kernel_ulong_t)&four_g_w14_blacklist 960 .driver_info = (kernel_ulong_t)&four_g_w14_blacklist
906 }, 961 },
962 { USB_DEVICE(LONGCHEER_VENDOR_ID, ZOOM_PRODUCT_4597) },
907 { USB_DEVICE(HAIER_VENDOR_ID, HAIER_PRODUCT_CE100) }, 963 { USB_DEVICE(HAIER_VENDOR_ID, HAIER_PRODUCT_CE100) },
908 /* Pirelli */ 964 /* Pirelli */
909 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_C100_1)}, 965 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_C100_1)},
@@ -922,9 +978,21 @@ static const struct usb_device_id option_ids[] = {
922 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_100F) }, 978 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_100F) },
923 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1011)}, 979 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1011)},
924 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1012)}, 980 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1012)},
925 { USB_DEVICE(CINTERION_VENDOR_ID, 0x0047) }, 981 /* Cinterion */
982 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_EU3_E) },
983 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_EU3_P) },
984 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_PH8) },
985 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDM) },
986 { USB_DEVICE(CINTERION_VENDOR_ID, CINTERION_PRODUCT_HC28_MDMNET) },
987 { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC25_MDM) },
988 { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC25_MDMNET) },
989 { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC28_MDM) }, /* HC28 enumerates with Siemens or Cinterion VID depending on FW revision */
990 { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC28_MDMNET) },
991
926 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) }, 992 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) },
927 { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */ 993 { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */
994 { USB_DEVICE(ONDA_VENDOR_ID, ONDA_MT825UP) }, /* ONDA MT825UP modem */
995 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_GT_B3730, USB_CLASS_CDC_DATA, 0x00, 0x00) }, /* Samsung GT-B3730 LTE USB modem.*/
928 { } /* Terminating entry */ 996 { } /* Terminating entry */
929}; 997};
930MODULE_DEVICE_TABLE(usb, option_ids); 998MODULE_DEVICE_TABLE(usb, option_ids);
@@ -965,6 +1033,7 @@ static struct usb_serial_driver option_1port_device = {
965 .set_termios = usb_wwan_set_termios, 1033 .set_termios = usb_wwan_set_termios,
966 .tiocmget = usb_wwan_tiocmget, 1034 .tiocmget = usb_wwan_tiocmget,
967 .tiocmset = usb_wwan_tiocmset, 1035 .tiocmset = usb_wwan_tiocmset,
1036 .ioctl = usb_wwan_ioctl,
968 .attach = usb_wwan_startup, 1037 .attach = usb_wwan_startup,
969 .disconnect = usb_wwan_disconnect, 1038 .disconnect = usb_wwan_disconnect,
970 .release = usb_wwan_release, 1039 .release = usb_wwan_release,
@@ -1060,6 +1129,12 @@ static int option_probe(struct usb_serial *serial,
1060 serial->interface->cur_altsetting->desc.bInterfaceNumber == 1) 1129 serial->interface->cur_altsetting->desc.bInterfaceNumber == 1)
1061 return -ENODEV; 1130 return -ENODEV;
1062 1131
1132 /* Don't bind network interface on Samsung GT-B3730, it is handled by a separate module */
1133 if (serial->dev->descriptor.idVendor == SAMSUNG_VENDOR_ID &&
1134 serial->dev->descriptor.idProduct == SAMSUNG_PRODUCT_GT_B3730 &&
1135 serial->interface->cur_altsetting->desc.bInterfaceClass != USB_CLASS_CDC_DATA)
1136 return -ENODEV;
1137
1063 data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL); 1138 data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL);
1064 1139
1065 if (!data) 1140 if (!data)
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index e199b0f4f99c..4c29e6c2bda7 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -135,7 +135,7 @@ static void oti6858_close(struct usb_serial_port *port);
135static void oti6858_set_termios(struct tty_struct *tty, 135static void oti6858_set_termios(struct tty_struct *tty,
136 struct usb_serial_port *port, struct ktermios *old); 136 struct usb_serial_port *port, struct ktermios *old);
137static void oti6858_init_termios(struct tty_struct *tty); 137static void oti6858_init_termios(struct tty_struct *tty);
138static int oti6858_ioctl(struct tty_struct *tty, struct file *file, 138static int oti6858_ioctl(struct tty_struct *tty,
139 unsigned int cmd, unsigned long arg); 139 unsigned int cmd, unsigned long arg);
140static void oti6858_read_int_callback(struct urb *urb); 140static void oti6858_read_int_callback(struct urb *urb);
141static void oti6858_read_bulk_callback(struct urb *urb); 141static void oti6858_read_bulk_callback(struct urb *urb);
@@ -144,8 +144,8 @@ static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
144 const unsigned char *buf, int count); 144 const unsigned char *buf, int count);
145static int oti6858_write_room(struct tty_struct *tty); 145static int oti6858_write_room(struct tty_struct *tty);
146static int oti6858_chars_in_buffer(struct tty_struct *tty); 146static int oti6858_chars_in_buffer(struct tty_struct *tty);
147static int oti6858_tiocmget(struct tty_struct *tty, struct file *file); 147static int oti6858_tiocmget(struct tty_struct *tty);
148static int oti6858_tiocmset(struct tty_struct *tty, struct file *file, 148static int oti6858_tiocmset(struct tty_struct *tty,
149 unsigned int set, unsigned int clear); 149 unsigned int set, unsigned int clear);
150static int oti6858_startup(struct usb_serial *serial); 150static int oti6858_startup(struct usb_serial *serial);
151static void oti6858_release(struct usb_serial *serial); 151static void oti6858_release(struct usb_serial *serial);
@@ -157,6 +157,7 @@ static struct usb_serial_driver oti6858_device = {
157 .name = "oti6858", 157 .name = "oti6858",
158 }, 158 },
159 .id_table = id_table, 159 .id_table = id_table,
160 .usb_driver = &oti6858_driver,
160 .num_ports = 1, 161 .num_ports = 1,
161 .open = oti6858_open, 162 .open = oti6858_open,
162 .close = oti6858_close, 163 .close = oti6858_close,
@@ -613,9 +614,8 @@ static void oti6858_close(struct usb_serial_port *port)
613 dbg("%s(): after buf_clear()", __func__); 614 dbg("%s(): after buf_clear()", __func__);
614 615
615 /* cancel scheduled setup */ 616 /* cancel scheduled setup */
616 cancel_delayed_work(&priv->delayed_setup_work); 617 cancel_delayed_work_sync(&priv->delayed_setup_work);
617 cancel_delayed_work(&priv->delayed_write_work); 618 cancel_delayed_work_sync(&priv->delayed_write_work);
618 flush_scheduled_work();
619 619
620 /* shutdown our urbs */ 620 /* shutdown our urbs */
621 dbg("%s(): shutting down urbs", __func__); 621 dbg("%s(): shutting down urbs", __func__);
@@ -624,7 +624,7 @@ static void oti6858_close(struct usb_serial_port *port)
624 usb_kill_urb(port->interrupt_in_urb); 624 usb_kill_urb(port->interrupt_in_urb);
625} 625}
626 626
627static int oti6858_tiocmset(struct tty_struct *tty, struct file *file, 627static int oti6858_tiocmset(struct tty_struct *tty,
628 unsigned int set, unsigned int clear) 628 unsigned int set, unsigned int clear)
629{ 629{
630 struct usb_serial_port *port = tty->driver_data; 630 struct usb_serial_port *port = tty->driver_data;
@@ -657,7 +657,7 @@ static int oti6858_tiocmset(struct tty_struct *tty, struct file *file,
657 return 0; 657 return 0;
658} 658}
659 659
660static int oti6858_tiocmget(struct tty_struct *tty, struct file *file) 660static int oti6858_tiocmget(struct tty_struct *tty)
661{ 661{
662 struct usb_serial_port *port = tty->driver_data; 662 struct usb_serial_port *port = tty->driver_data;
663 struct oti6858_private *priv = usb_get_serial_port_data(port); 663 struct oti6858_private *priv = usb_get_serial_port_data(port);
@@ -728,7 +728,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
728 return 0; 728 return 0;
729} 729}
730 730
731static int oti6858_ioctl(struct tty_struct *tty, struct file *file, 731static int oti6858_ioctl(struct tty_struct *tty,
732 unsigned int cmd, unsigned long arg) 732 unsigned int cmd, unsigned long arg)
733{ 733{
734 struct usb_serial_port *port = tty->driver_data; 734 struct usb_serial_port *port = tty->driver_data;
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 8ae4c6cbc38a..30461fcc2206 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -50,6 +50,7 @@ static const struct usb_device_id id_table[] = {
50 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MMX) }, 50 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MMX) },
51 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GPRS) }, 51 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GPRS) },
52 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_HCR331) }, 52 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_HCR331) },
53 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MOTOROLA) },
53 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) }, 54 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
54 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) }, 55 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) },
55 { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) }, 56 { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) },
@@ -504,7 +505,7 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
504 return 0; 505 return 0;
505} 506}
506 507
507static int pl2303_tiocmset(struct tty_struct *tty, struct file *file, 508static int pl2303_tiocmset(struct tty_struct *tty,
508 unsigned int set, unsigned int clear) 509 unsigned int set, unsigned int clear)
509{ 510{
510 struct usb_serial_port *port = tty->driver_data; 511 struct usb_serial_port *port = tty->driver_data;
@@ -530,7 +531,7 @@ static int pl2303_tiocmset(struct tty_struct *tty, struct file *file,
530 return set_control_lines(port->serial->dev, control); 531 return set_control_lines(port->serial->dev, control);
531} 532}
532 533
533static int pl2303_tiocmget(struct tty_struct *tty, struct file *file) 534static int pl2303_tiocmget(struct tty_struct *tty)
534{ 535{
535 struct usb_serial_port *port = tty->driver_data; 536 struct usb_serial_port *port = tty->driver_data;
536 struct pl2303_private *priv = usb_get_serial_port_data(port); 537 struct pl2303_private *priv = usb_get_serial_port_data(port);
@@ -605,7 +606,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
605 return 0; 606 return 0;
606} 607}
607 608
608static int pl2303_ioctl(struct tty_struct *tty, struct file *file, 609static int pl2303_ioctl(struct tty_struct *tty,
609 unsigned int cmd, unsigned long arg) 610 unsigned int cmd, unsigned long arg)
610{ 611{
611 struct serial_struct ser; 612 struct serial_struct ser;
@@ -677,9 +678,11 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
677{ 678{
678 679
679 struct pl2303_private *priv = usb_get_serial_port_data(port); 680 struct pl2303_private *priv = usb_get_serial_port_data(port);
681 struct tty_struct *tty;
680 unsigned long flags; 682 unsigned long flags;
681 u8 status_idx = UART_STATE; 683 u8 status_idx = UART_STATE;
682 u8 length = UART_STATE + 1; 684 u8 length = UART_STATE + 1;
685 u8 prev_line_status;
683 u16 idv, idp; 686 u16 idv, idp;
684 687
685 idv = le16_to_cpu(port->serial->dev->descriptor.idVendor); 688 idv = le16_to_cpu(port->serial->dev->descriptor.idVendor);
@@ -701,11 +704,20 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
701 704
702 /* Save off the uart status for others to look at */ 705 /* Save off the uart status for others to look at */
703 spin_lock_irqsave(&priv->lock, flags); 706 spin_lock_irqsave(&priv->lock, flags);
707 prev_line_status = priv->line_status;
704 priv->line_status = data[status_idx]; 708 priv->line_status = data[status_idx];
705 spin_unlock_irqrestore(&priv->lock, flags); 709 spin_unlock_irqrestore(&priv->lock, flags);
706 if (priv->line_status & UART_BREAK_ERROR) 710 if (priv->line_status & UART_BREAK_ERROR)
707 usb_serial_handle_break(port); 711 usb_serial_handle_break(port);
708 wake_up_interruptible(&priv->delta_msr_wait); 712 wake_up_interruptible(&priv->delta_msr_wait);
713
714 tty = tty_port_tty_get(&port->port);
715 if (!tty)
716 return;
717 if ((priv->line_status ^ prev_line_status) & UART_DCD)
718 usb_serial_handle_dcd_change(port, tty,
719 priv->line_status & UART_DCD);
720 tty_kref_put(tty);
709} 721}
710 722
711static void pl2303_read_int_callback(struct urb *urb) 723static void pl2303_read_int_callback(struct urb *urb)
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 43eb9bdad422..1b025f75dafd 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -21,6 +21,7 @@
21#define PL2303_PRODUCT_ID_MMX 0x0612 21#define PL2303_PRODUCT_ID_MMX 0x0612
22#define PL2303_PRODUCT_ID_GPRS 0x0609 22#define PL2303_PRODUCT_ID_GPRS 0x0609
23#define PL2303_PRODUCT_ID_HCR331 0x331a 23#define PL2303_PRODUCT_ID_HCR331 0x331a
24#define PL2303_PRODUCT_ID_MOTOROLA 0x0307
24 25
25#define ATEN_VENDOR_ID 0x0557 26#define ATEN_VENDOR_ID 0x0557
26#define ATEN_VENDOR_ID2 0x0547 27#define ATEN_VENDOR_ID2 0x0547
diff --git a/drivers/usb/serial/qcaux.c b/drivers/usb/serial/qcaux.c
index 214a3e504292..30b73e68a904 100644
--- a/drivers/usb/serial/qcaux.c
+++ b/drivers/usb/serial/qcaux.c
@@ -36,6 +36,7 @@
36#define UTSTARCOM_PRODUCT_UM175_V1 0x3712 36#define UTSTARCOM_PRODUCT_UM175_V1 0x3712
37#define UTSTARCOM_PRODUCT_UM175_V2 0x3714 37#define UTSTARCOM_PRODUCT_UM175_V2 0x3714
38#define UTSTARCOM_PRODUCT_UM175_ALLTEL 0x3715 38#define UTSTARCOM_PRODUCT_UM175_ALLTEL 0x3715
39#define PANTECH_PRODUCT_UML290_VZW 0x3718
39 40
40/* CMOTECH devices */ 41/* CMOTECH devices */
41#define CMOTECH_VENDOR_ID 0x16d8 42#define CMOTECH_VENDOR_ID 0x16d8
@@ -66,6 +67,7 @@ static struct usb_device_id id_table[] = {
66 { USB_DEVICE_AND_INTERFACE_INFO(LG_VENDOR_ID, LG_PRODUCT_VX4400_6000, 0xff, 0xff, 0x00) }, 67 { USB_DEVICE_AND_INTERFACE_INFO(LG_VENDOR_ID, LG_PRODUCT_VX4400_6000, 0xff, 0xff, 0x00) },
67 { USB_DEVICE_AND_INTERFACE_INFO(SANYO_VENDOR_ID, SANYO_PRODUCT_KATANA_LX, 0xff, 0xff, 0x00) }, 68 { USB_DEVICE_AND_INTERFACE_INFO(SANYO_VENDOR_ID, SANYO_PRODUCT_KATANA_LX, 0xff, 0xff, 0x00) },
68 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_U520, 0xff, 0x00, 0x00) }, 69 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_U520, 0xff, 0x00, 0x00) },
70 { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, PANTECH_PRODUCT_UML290_VZW, 0xff, 0xff, 0xff) },
69 { }, 71 { },
70}; 72};
71MODULE_DEVICE_TABLE(usb, id_table); 73MODULE_DEVICE_TABLE(usb, id_table);
@@ -84,6 +86,7 @@ static struct usb_serial_driver qcaux_device = {
84 .name = "qcaux", 86 .name = "qcaux",
85 }, 87 },
86 .id_table = id_table, 88 .id_table = id_table,
89 .usb_driver = &qcaux_driver,
87 .num_ports = 1, 90 .num_ports = 1,
88}; 91};
89 92
diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c
index cde67cacb2c3..54a9dab1f33b 100644
--- a/drivers/usb/serial/qcserial.c
+++ b/drivers/usb/serial/qcserial.c
@@ -111,13 +111,15 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
111 ifnum = intf->desc.bInterfaceNumber; 111 ifnum = intf->desc.bInterfaceNumber;
112 dbg("This Interface = %d", ifnum); 112 dbg("This Interface = %d", ifnum);
113 113
114 data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), 114 data = kzalloc(sizeof(struct usb_wwan_intf_private),
115 GFP_KERNEL); 115 GFP_KERNEL);
116 if (!data) 116 if (!data)
117 return -ENOMEM; 117 return -ENOMEM;
118 118
119 spin_lock_init(&data->susp_lock); 119 spin_lock_init(&data->susp_lock);
120 120
121 usb_enable_autosuspend(serial->dev);
122
121 switch (nintf) { 123 switch (nintf) {
122 case 1: 124 case 1:
123 /* QDL mode */ 125 /* QDL mode */
@@ -132,8 +134,10 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
132 usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) { 134 usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) {
133 dbg("QDL port found"); 135 dbg("QDL port found");
134 136
135 if (serial->interface->num_altsetting == 1) 137 if (serial->interface->num_altsetting == 1) {
136 return 0; 138 retval = 0; /* Success */
139 break;
140 }
137 141
138 retval = usb_set_interface(serial->dev, ifnum, 1); 142 retval = usb_set_interface(serial->dev, ifnum, 1);
139 if (retval < 0) { 143 if (retval < 0) {
@@ -143,14 +147,29 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
143 retval = -ENODEV; 147 retval = -ENODEV;
144 kfree(data); 148 kfree(data);
145 } 149 }
146 return retval;
147 } 150 }
148 break; 151 break;
149 152
150 case 3: 153 case 3:
151 case 4: 154 case 4:
152 /* Composite mode */ 155 /* Composite mode */
153 if (ifnum == 2) { 156 /* ifnum == 0 is a broadband network adapter */
157 if (ifnum == 1) {
158 /*
159 * Diagnostics Monitor (serial line 9600 8N1)
160 * Qualcomm DM protocol
161 * use "libqcdm" (ModemManager) for communication
162 */
163 dbg("Diagnostics Monitor found");
164 retval = usb_set_interface(serial->dev, ifnum, 0);
165 if (retval < 0) {
166 dev_err(&serial->dev->dev,
167 "Could not set interface, error %d\n",
168 retval);
169 retval = -ENODEV;
170 kfree(data);
171 }
172 } else if (ifnum == 2) {
154 dbg("Modem port found"); 173 dbg("Modem port found");
155 retval = usb_set_interface(serial->dev, ifnum, 0); 174 retval = usb_set_interface(serial->dev, ifnum, 0);
156 if (retval < 0) { 175 if (retval < 0) {
@@ -160,7 +179,21 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
160 retval = -ENODEV; 179 retval = -ENODEV;
161 kfree(data); 180 kfree(data);
162 } 181 }
163 return retval; 182 } else if (ifnum==3) {
183 /*
184 * NMEA (serial line 9600 8N1)
185 * # echo "\$GPS_START" > /dev/ttyUSBx
186 * # echo "\$GPS_STOP" > /dev/ttyUSBx
187 */
188 dbg("NMEA GPS interface found");
189 retval = usb_set_interface(serial->dev, ifnum, 0);
190 if (retval < 0) {
191 dev_err(&serial->dev->dev,
192 "Could not set interface, error %d\n",
193 retval);
194 retval = -ENODEV;
195 kfree(data);
196 }
164 } 197 }
165 break; 198 break;
166 199
@@ -168,12 +201,27 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
168 dev_err(&serial->dev->dev, 201 dev_err(&serial->dev->dev,
169 "unknown number of interfaces: %d\n", nintf); 202 "unknown number of interfaces: %d\n", nintf);
170 kfree(data); 203 kfree(data);
171 return -ENODEV; 204 retval = -ENODEV;
172 } 205 }
173 206
207 /* Set serial->private if not returning -ENODEV */
208 if (retval != -ENODEV)
209 usb_set_serial_data(serial, data);
174 return retval; 210 return retval;
175} 211}
176 212
213static void qc_release(struct usb_serial *serial)
214{
215 struct usb_wwan_intf_private *priv = usb_get_serial_data(serial);
216
217 dbg("%s", __func__);
218
219 /* Call usb_wwan release & free the private data allocated in qcprobe */
220 usb_wwan_release(serial);
221 usb_set_serial_data(serial, NULL);
222 kfree(priv);
223}
224
177static struct usb_serial_driver qcdevice = { 225static struct usb_serial_driver qcdevice = {
178 .driver = { 226 .driver = {
179 .owner = THIS_MODULE, 227 .owner = THIS_MODULE,
@@ -191,7 +239,7 @@ static struct usb_serial_driver qcdevice = {
191 .chars_in_buffer = usb_wwan_chars_in_buffer, 239 .chars_in_buffer = usb_wwan_chars_in_buffer,
192 .attach = usb_wwan_startup, 240 .attach = usb_wwan_startup,
193 .disconnect = usb_wwan_disconnect, 241 .disconnect = usb_wwan_disconnect,
194 .release = usb_wwan_release, 242 .release = qc_release,
195#ifdef CONFIG_PM 243#ifdef CONFIG_PM
196 .suspend = usb_wwan_suspend, 244 .suspend = usb_wwan_suspend,
197 .resume = usb_wwan_resume, 245 .resume = usb_wwan_resume,
diff --git a/drivers/usb/serial/siemens_mpi.c b/drivers/usb/serial/siemens_mpi.c
index cb8195cabfde..74cd4ccdb3fc 100644
--- a/drivers/usb/serial/siemens_mpi.c
+++ b/drivers/usb/serial/siemens_mpi.c
@@ -42,6 +42,7 @@ static struct usb_serial_driver siemens_usb_mpi_device = {
42 .name = "siemens_mpi", 42 .name = "siemens_mpi",
43 }, 43 },
44 .id_table = id_table, 44 .id_table = id_table,
45 .usb_driver = &siemens_usb_mpi_driver,
45 .num_ports = 1, 46 .num_ports = 1,
46}; 47};
47 48
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index d47b56e9e8ce..d5d136a53b61 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -301,6 +301,9 @@ static const struct usb_device_id id_table[] = {
301 { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */ 301 { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */
302 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist 302 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist
303 }, 303 },
304 { USB_DEVICE(0x0f3d, 0x68A3), /* Airprime/Sierra Wireless Direct IP modems */
305 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist
306 },
304 { USB_DEVICE(0x413C, 0x08133) }, /* Dell Computer Corp. Wireless 5720 VZW Mobile Broadband (EVDO Rev-A) Minicard GPS Port */ 307 { USB_DEVICE(0x413C, 0x08133) }, /* Dell Computer Corp. Wireless 5720 VZW Mobile Broadband (EVDO Rev-A) Minicard GPS Port */
305 308
306 { } 309 { }
@@ -373,7 +376,10 @@ static int sierra_send_setup(struct usb_serial_port *port)
373 if (!do_send) 376 if (!do_send)
374 return 0; 377 return 0;
375 378
376 usb_autopm_get_interface(serial->interface); 379 retval = usb_autopm_get_interface(serial->interface);
380 if (retval < 0)
381 return retval;
382
377 retval = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 383 retval = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
378 0x22, 0x21, val, interface, NULL, 0, USB_CTRL_SET_TIMEOUT); 384 0x22, 0x21, val, interface, NULL, 0, USB_CTRL_SET_TIMEOUT);
379 usb_autopm_put_interface(serial->interface); 385 usb_autopm_put_interface(serial->interface);
@@ -389,7 +395,7 @@ static void sierra_set_termios(struct tty_struct *tty,
389 sierra_send_setup(port); 395 sierra_send_setup(port);
390} 396}
391 397
392static int sierra_tiocmget(struct tty_struct *tty, struct file *file) 398static int sierra_tiocmget(struct tty_struct *tty)
393{ 399{
394 struct usb_serial_port *port = tty->driver_data; 400 struct usb_serial_port *port = tty->driver_data;
395 unsigned int value; 401 unsigned int value;
@@ -408,7 +414,7 @@ static int sierra_tiocmget(struct tty_struct *tty, struct file *file)
408 return value; 414 return value;
409} 415}
410 416
411static int sierra_tiocmset(struct tty_struct *tty, struct file *file, 417static int sierra_tiocmset(struct tty_struct *tty,
412 unsigned int set, unsigned int clear) 418 unsigned int set, unsigned int clear)
413{ 419{
414 struct usb_serial_port *port = tty->driver_data; 420 struct usb_serial_port *port = tty->driver_data;
@@ -620,8 +626,6 @@ static void sierra_indat_callback(struct urb *urb)
620 dev_err(&port->dev, "resubmit read urb failed." 626 dev_err(&port->dev, "resubmit read urb failed."
621 "(%d)\n", err); 627 "(%d)\n", err);
622 } 628 }
623
624 return;
625} 629}
626 630
627static void sierra_instat_callback(struct urb *urb) 631static void sierra_instat_callback(struct urb *urb)
@@ -810,8 +814,12 @@ static void sierra_close(struct usb_serial_port *port)
810 mutex_lock(&serial->disc_mutex); 814 mutex_lock(&serial->disc_mutex);
811 if (!serial->disconnected) { 815 if (!serial->disconnected) {
812 serial->interface->needs_remote_wakeup = 0; 816 serial->interface->needs_remote_wakeup = 0;
813 usb_autopm_get_interface(serial->interface); 817 /* odd error handling due to pm counters */
814 sierra_send_setup(port); 818 if (!usb_autopm_get_interface(serial->interface))
819 sierra_send_setup(port);
820 else
821 usb_autopm_get_interface_no_resume(serial->interface);
822
815 } 823 }
816 mutex_unlock(&serial->disc_mutex); 824 mutex_unlock(&serial->disc_mutex);
817 spin_lock_irq(&intfdata->susp_lock); 825 spin_lock_irq(&intfdata->susp_lock);
@@ -864,7 +872,8 @@ static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port)
864 /* get rid of everything as in close */ 872 /* get rid of everything as in close */
865 sierra_close(port); 873 sierra_close(port);
866 /* restore balance for autopm */ 874 /* restore balance for autopm */
867 usb_autopm_put_interface(serial->interface); 875 if (!serial->disconnected)
876 usb_autopm_put_interface(serial->interface);
868 return err; 877 return err;
869 } 878 }
870 sierra_send_setup(port); 879 sierra_send_setup(port);
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 329d311a35d9..180ea6c7911c 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -133,7 +133,7 @@ struct spcp8x5_usb_ctrl_arg {
133 133
134/* how come ??? */ 134/* how come ??? */
135#define UART_STATE 0x08 135#define UART_STATE 0x08
136#define UART_STATE_TRANSIENT_MASK 0x74 136#define UART_STATE_TRANSIENT_MASK 0x75
137#define UART_DCD 0x01 137#define UART_DCD 0x01
138#define UART_DSR 0x02 138#define UART_DSR 0x02
139#define UART_BREAK_ERROR 0x04 139#define UART_BREAK_ERROR 0x04
@@ -441,7 +441,6 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
441 spcp8x5_set_workMode(serial->dev, 0x000a, 441 spcp8x5_set_workMode(serial->dev, 0x000a,
442 SET_WORKING_MODE_U2C, priv->type); 442 SET_WORKING_MODE_U2C, priv->type);
443 } 443 }
444 return;
445} 444}
446 445
447/* open the serial port. do some usb system call. set termios and get the line 446/* open the serial port. do some usb system call. set termios and get the line
@@ -526,6 +525,10 @@ static void spcp8x5_process_read_urb(struct urb *urb)
526 /* overrun is special, not associated with a char */ 525 /* overrun is special, not associated with a char */
527 if (status & UART_OVERRUN_ERROR) 526 if (status & UART_OVERRUN_ERROR)
528 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 527 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
528
529 if (status & UART_DCD)
530 usb_serial_handle_dcd_change(port, tty,
531 priv->line_status & MSR_STATUS_LINE_DCD);
529 } 532 }
530 533
531 tty_insert_flip_string_fixed_flag(tty, data, tty_flag, 534 tty_insert_flip_string_fixed_flag(tty, data, tty_flag,
@@ -573,7 +576,7 @@ static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
573 return 0; 576 return 0;
574} 577}
575 578
576static int spcp8x5_ioctl(struct tty_struct *tty, struct file *file, 579static int spcp8x5_ioctl(struct tty_struct *tty,
577 unsigned int cmd, unsigned long arg) 580 unsigned int cmd, unsigned long arg)
578{ 581{
579 struct usb_serial_port *port = tty->driver_data; 582 struct usb_serial_port *port = tty->driver_data;
@@ -592,7 +595,7 @@ static int spcp8x5_ioctl(struct tty_struct *tty, struct file *file,
592 return -ENOIOCTLCMD; 595 return -ENOIOCTLCMD;
593} 596}
594 597
595static int spcp8x5_tiocmset(struct tty_struct *tty, struct file *file, 598static int spcp8x5_tiocmset(struct tty_struct *tty,
596 unsigned int set, unsigned int clear) 599 unsigned int set, unsigned int clear)
597{ 600{
598 struct usb_serial_port *port = tty->driver_data; 601 struct usb_serial_port *port = tty->driver_data;
@@ -615,7 +618,7 @@ static int spcp8x5_tiocmset(struct tty_struct *tty, struct file *file,
615 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 618 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
616} 619}
617 620
618static int spcp8x5_tiocmget(struct tty_struct *tty, struct file *file) 621static int spcp8x5_tiocmget(struct tty_struct *tty)
619{ 622{
620 struct usb_serial_port *port = tty->driver_data; 623 struct usb_serial_port *port = tty->driver_data;
621 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 624 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
@@ -646,6 +649,7 @@ static struct usb_serial_driver spcp8x5_device = {
646 .name = "SPCP8x5", 649 .name = "SPCP8x5",
647 }, 650 },
648 .id_table = id_table, 651 .id_table = id_table,
652 .usb_driver = &spcp8x5_driver,
649 .num_ports = 1, 653 .num_ports = 1,
650 .open = spcp8x5_open, 654 .open = spcp8x5_open,
651 .dtr_rts = spcp8x5_dtr_rts, 655 .dtr_rts = spcp8x5_dtr_rts,
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index e986002b3844..87362e48796e 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -79,7 +79,6 @@ struct ssu100_port_private {
79 u8 shadowLSR; 79 u8 shadowLSR;
80 u8 shadowMSR; 80 u8 shadowMSR;
81 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ 81 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
82 unsigned short max_packet_size;
83 struct async_icount icount; 82 struct async_icount icount;
84}; 83};
85 84
@@ -416,12 +415,34 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
416 return 0; 415 return 0;
417} 416}
418 417
419static int ssu100_ioctl(struct tty_struct *tty, struct file *file, 418static int ssu100_get_icount(struct tty_struct *tty,
420 unsigned int cmd, unsigned long arg) 419 struct serial_icounter_struct *icount)
421{ 420{
422 struct usb_serial_port *port = tty->driver_data; 421 struct usb_serial_port *port = tty->driver_data;
423 struct ssu100_port_private *priv = usb_get_serial_port_data(port); 422 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
424 void __user *user_arg = (void __user *)arg; 423 struct async_icount cnow = priv->icount;
424
425 icount->cts = cnow.cts;
426 icount->dsr = cnow.dsr;
427 icount->rng = cnow.rng;
428 icount->dcd = cnow.dcd;
429 icount->rx = cnow.rx;
430 icount->tx = cnow.tx;
431 icount->frame = cnow.frame;
432 icount->overrun = cnow.overrun;
433 icount->parity = cnow.parity;
434 icount->brk = cnow.brk;
435 icount->buf_overrun = cnow.buf_overrun;
436
437 return 0;
438}
439
440
441
442static int ssu100_ioctl(struct tty_struct *tty,
443 unsigned int cmd, unsigned long arg)
444{
445 struct usb_serial_port *port = tty->driver_data;
425 446
426 dbg("%s cmd 0x%04x", __func__, cmd); 447 dbg("%s cmd 0x%04x", __func__, cmd);
427 448
@@ -433,27 +454,6 @@ static int ssu100_ioctl(struct tty_struct *tty, struct file *file,
433 case TIOCMIWAIT: 454 case TIOCMIWAIT:
434 return wait_modem_info(port, arg); 455 return wait_modem_info(port, arg);
435 456
436 case TIOCGICOUNT:
437 {
438 struct serial_icounter_struct icount;
439 struct async_icount cnow = priv->icount;
440 memset(&icount, 0, sizeof(icount));
441 icount.cts = cnow.cts;
442 icount.dsr = cnow.dsr;
443 icount.rng = cnow.rng;
444 icount.dcd = cnow.dcd;
445 icount.rx = cnow.rx;
446 icount.tx = cnow.tx;
447 icount.frame = cnow.frame;
448 icount.overrun = cnow.overrun;
449 icount.parity = cnow.parity;
450 icount.brk = cnow.brk;
451 icount.buf_overrun = cnow.buf_overrun;
452 if (copy_to_user(user_arg, &icount, sizeof(icount)))
453 return -EFAULT;
454 return 0;
455 }
456
457 default: 457 default:
458 break; 458 break;
459 } 459 }
@@ -463,36 +463,6 @@ static int ssu100_ioctl(struct tty_struct *tty, struct file *file,
463 return -ENOIOCTLCMD; 463 return -ENOIOCTLCMD;
464} 464}
465 465
466static void ssu100_set_max_packet_size(struct usb_serial_port *port)
467{
468 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
469 struct usb_serial *serial = port->serial;
470 struct usb_device *udev = serial->dev;
471
472 struct usb_interface *interface = serial->interface;
473 struct usb_endpoint_descriptor *ep_desc = &interface->cur_altsetting->endpoint[1].desc;
474
475 unsigned num_endpoints;
476 int i;
477 unsigned long flags;
478
479 num_endpoints = interface->cur_altsetting->desc.bNumEndpoints;
480 dev_info(&udev->dev, "Number of endpoints %d\n", num_endpoints);
481
482 for (i = 0; i < num_endpoints; i++) {
483 dev_info(&udev->dev, "Endpoint %d MaxPacketSize %d\n", i+1,
484 interface->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
485 ep_desc = &interface->cur_altsetting->endpoint[i].desc;
486 }
487
488 /* set max packet size based on descriptor */
489 spin_lock_irqsave(&priv->status_lock, flags);
490 priv->max_packet_size = ep_desc->wMaxPacketSize;
491 spin_unlock_irqrestore(&priv->status_lock, flags);
492
493 dev_info(&udev->dev, "Setting MaxPacketSize %d\n", priv->max_packet_size);
494}
495
496static int ssu100_attach(struct usb_serial *serial) 466static int ssu100_attach(struct usb_serial *serial)
497{ 467{
498 struct ssu100_port_private *priv; 468 struct ssu100_port_private *priv;
@@ -510,12 +480,11 @@ static int ssu100_attach(struct usb_serial *serial)
510 spin_lock_init(&priv->status_lock); 480 spin_lock_init(&priv->status_lock);
511 init_waitqueue_head(&priv->delta_msr_wait); 481 init_waitqueue_head(&priv->delta_msr_wait);
512 usb_set_serial_port_data(port, priv); 482 usb_set_serial_port_data(port, priv);
513 ssu100_set_max_packet_size(port);
514 483
515 return ssu100_initdevice(serial->dev); 484 return ssu100_initdevice(serial->dev);
516} 485}
517 486
518static int ssu100_tiocmget(struct tty_struct *tty, struct file *file) 487static int ssu100_tiocmget(struct tty_struct *tty)
519{ 488{
520 struct usb_serial_port *port = tty->driver_data; 489 struct usb_serial_port *port = tty->driver_data;
521 struct usb_device *dev = port->serial->dev; 490 struct usb_device *dev = port->serial->dev;
@@ -548,7 +517,7 @@ mget_out:
548 return r; 517 return r;
549} 518}
550 519
551static int ssu100_tiocmset(struct tty_struct *tty, struct file *file, 520static int ssu100_tiocmset(struct tty_struct *tty,
552 unsigned int set, unsigned int clear) 521 unsigned int set, unsigned int clear)
553{ 522{
554 struct usb_serial_port *port = tty->driver_data; 523 struct usb_serial_port *port = tty->driver_data;
@@ -640,13 +609,14 @@ static void ssu100_update_lsr(struct usb_serial_port *port, u8 lsr,
640 609
641} 610}
642 611
643static int ssu100_process_packet(struct tty_struct *tty, 612static int ssu100_process_packet(struct urb *urb,
644 struct usb_serial_port *port, 613 struct tty_struct *tty)
645 struct ssu100_port_private *priv,
646 char *packet, int len)
647{ 614{
648 int i; 615 struct usb_serial_port *port = urb->context;
616 char *packet = (char *)urb->transfer_buffer;
649 char flag = TTY_NORMAL; 617 char flag = TTY_NORMAL;
618 u32 len = urb->actual_length;
619 int i;
650 char *ch; 620 char *ch;
651 621
652 dbg("%s - port %d", __func__, port->number); 622 dbg("%s - port %d", __func__, port->number);
@@ -684,12 +654,8 @@ static int ssu100_process_packet(struct tty_struct *tty,
684static void ssu100_process_read_urb(struct urb *urb) 654static void ssu100_process_read_urb(struct urb *urb)
685{ 655{
686 struct usb_serial_port *port = urb->context; 656 struct usb_serial_port *port = urb->context;
687 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
688 char *data = (char *)urb->transfer_buffer;
689 struct tty_struct *tty; 657 struct tty_struct *tty;
690 int count = 0; 658 int count;
691 int i;
692 int len;
693 659
694 dbg("%s", __func__); 660 dbg("%s", __func__);
695 661
@@ -697,10 +663,7 @@ static void ssu100_process_read_urb(struct urb *urb)
697 if (!tty) 663 if (!tty)
698 return; 664 return;
699 665
700 for (i = 0; i < urb->actual_length; i += priv->max_packet_size) { 666 count = ssu100_process_packet(urb, tty);
701 len = min_t(int, urb->actual_length - i, priv->max_packet_size);
702 count += ssu100_process_packet(tty, port, priv, &data[i], len);
703 }
704 667
705 if (count) 668 if (count)
706 tty_flip_buffer_push(tty); 669 tty_flip_buffer_push(tty);
@@ -716,8 +679,6 @@ static struct usb_serial_driver ssu100_device = {
716 .id_table = id_table, 679 .id_table = id_table,
717 .usb_driver = &ssu100_driver, 680 .usb_driver = &ssu100_driver,
718 .num_ports = 1, 681 .num_ports = 1,
719 .bulk_in_size = 256,
720 .bulk_out_size = 256,
721 .open = ssu100_open, 682 .open = ssu100_open,
722 .close = ssu100_close, 683 .close = ssu100_close,
723 .attach = ssu100_attach, 684 .attach = ssu100_attach,
@@ -726,6 +687,7 @@ static struct usb_serial_driver ssu100_device = {
726 .process_read_urb = ssu100_process_read_urb, 687 .process_read_urb = ssu100_process_read_urb,
727 .tiocmget = ssu100_tiocmget, 688 .tiocmget = ssu100_tiocmget,
728 .tiocmset = ssu100_tiocmset, 689 .tiocmset = ssu100_tiocmset,
690 .get_icount = ssu100_get_icount,
729 .ioctl = ssu100_ioctl, 691 .ioctl = ssu100_ioctl,
730 .set_termios = ssu100_set_termios, 692 .set_termios = ssu100_set_termios,
731 .disconnect = usb_serial_generic_disconnect, 693 .disconnect = usb_serial_generic_disconnect,
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 90979a1f5311..ea8445689c85 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -106,12 +106,14 @@ static int ti_write_room(struct tty_struct *tty);
106static int ti_chars_in_buffer(struct tty_struct *tty); 106static int ti_chars_in_buffer(struct tty_struct *tty);
107static void ti_throttle(struct tty_struct *tty); 107static void ti_throttle(struct tty_struct *tty);
108static void ti_unthrottle(struct tty_struct *tty); 108static void ti_unthrottle(struct tty_struct *tty);
109static int ti_ioctl(struct tty_struct *tty, struct file *file, 109static int ti_ioctl(struct tty_struct *tty,
110 unsigned int cmd, unsigned long arg); 110 unsigned int cmd, unsigned long arg);
111static int ti_get_icount(struct tty_struct *tty,
112 struct serial_icounter_struct *icount);
111static void ti_set_termios(struct tty_struct *tty, 113static void ti_set_termios(struct tty_struct *tty,
112 struct usb_serial_port *port, struct ktermios *old_termios); 114 struct usb_serial_port *port, struct ktermios *old_termios);
113static int ti_tiocmget(struct tty_struct *tty, struct file *file); 115static int ti_tiocmget(struct tty_struct *tty);
114static int ti_tiocmset(struct tty_struct *tty, struct file *file, 116static int ti_tiocmset(struct tty_struct *tty,
115 unsigned int set, unsigned int clear); 117 unsigned int set, unsigned int clear);
116static void ti_break(struct tty_struct *tty, int break_state); 118static void ti_break(struct tty_struct *tty, int break_state);
117static void ti_interrupt_callback(struct urb *urb); 119static void ti_interrupt_callback(struct urb *urb);
@@ -237,6 +239,7 @@ static struct usb_serial_driver ti_1port_device = {
237 .set_termios = ti_set_termios, 239 .set_termios = ti_set_termios,
238 .tiocmget = ti_tiocmget, 240 .tiocmget = ti_tiocmget,
239 .tiocmset = ti_tiocmset, 241 .tiocmset = ti_tiocmset,
242 .get_icount = ti_get_icount,
240 .break_ctl = ti_break, 243 .break_ctl = ti_break,
241 .read_int_callback = ti_interrupt_callback, 244 .read_int_callback = ti_interrupt_callback,
242 .read_bulk_callback = ti_bulk_in_callback, 245 .read_bulk_callback = ti_bulk_in_callback,
@@ -265,6 +268,7 @@ static struct usb_serial_driver ti_2port_device = {
265 .set_termios = ti_set_termios, 268 .set_termios = ti_set_termios,
266 .tiocmget = ti_tiocmget, 269 .tiocmget = ti_tiocmget,
267 .tiocmset = ti_tiocmset, 270 .tiocmset = ti_tiocmset,
271 .get_icount = ti_get_icount,
268 .break_ctl = ti_break, 272 .break_ctl = ti_break,
269 .read_int_callback = ti_interrupt_callback, 273 .read_int_callback = ti_interrupt_callback,
270 .read_bulk_callback = ti_bulk_in_callback, 274 .read_bulk_callback = ti_bulk_in_callback,
@@ -365,9 +369,9 @@ failed_1port:
365 369
366static void __exit ti_exit(void) 370static void __exit ti_exit(void)
367{ 371{
372 usb_deregister(&ti_usb_driver);
368 usb_serial_deregister(&ti_1port_device); 373 usb_serial_deregister(&ti_1port_device);
369 usb_serial_deregister(&ti_2port_device); 374 usb_serial_deregister(&ti_2port_device);
370 usb_deregister(&ti_usb_driver);
371} 375}
372 376
373 377
@@ -788,8 +792,33 @@ static void ti_unthrottle(struct tty_struct *tty)
788 } 792 }
789} 793}
790 794
795static int ti_get_icount(struct tty_struct *tty,
796 struct serial_icounter_struct *icount)
797{
798 struct usb_serial_port *port = tty->driver_data;
799 struct ti_port *tport = usb_get_serial_port_data(port);
800 struct async_icount cnow = tport->tp_icount;
801
802 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d",
803 __func__, port->number,
804 cnow.rx, cnow.tx);
805
806 icount->cts = cnow.cts;
807 icount->dsr = cnow.dsr;
808 icount->rng = cnow.rng;
809 icount->dcd = cnow.dcd;
810 icount->rx = cnow.rx;
811 icount->tx = cnow.tx;
812 icount->frame = cnow.frame;
813 icount->overrun = cnow.overrun;
814 icount->parity = cnow.parity;
815 icount->brk = cnow.brk;
816 icount->buf_overrun = cnow.buf_overrun;
791 817
792static int ti_ioctl(struct tty_struct *tty, struct file *file, 818 return 0;
819}
820
821static int ti_ioctl(struct tty_struct *tty,
793 unsigned int cmd, unsigned long arg) 822 unsigned int cmd, unsigned long arg)
794{ 823{
795 struct usb_serial_port *port = tty->driver_data; 824 struct usb_serial_port *port = tty->driver_data;
@@ -830,14 +859,6 @@ static int ti_ioctl(struct tty_struct *tty, struct file *file,
830 cprev = cnow; 859 cprev = cnow;
831 } 860 }
832 break; 861 break;
833 case TIOCGICOUNT:
834 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d",
835 __func__, port->number,
836 tport->tp_icount.rx, tport->tp_icount.tx);
837 if (copy_to_user((void __user *)arg, &tport->tp_icount,
838 sizeof(tport->tp_icount)))
839 return -EFAULT;
840 return 0;
841 } 862 }
842 return -ENOIOCTLCMD; 863 return -ENOIOCTLCMD;
843} 864}
@@ -979,7 +1000,7 @@ static void ti_set_termios(struct tty_struct *tty,
979} 1000}
980 1001
981 1002
982static int ti_tiocmget(struct tty_struct *tty, struct file *file) 1003static int ti_tiocmget(struct tty_struct *tty)
983{ 1004{
984 struct usb_serial_port *port = tty->driver_data; 1005 struct usb_serial_port *port = tty->driver_data;
985 struct ti_port *tport = usb_get_serial_port_data(port); 1006 struct ti_port *tport = usb_get_serial_port_data(port);
@@ -1012,8 +1033,8 @@ static int ti_tiocmget(struct tty_struct *tty, struct file *file)
1012} 1033}
1013 1034
1014 1035
1015static int ti_tiocmset(struct tty_struct *tty, struct file *file, 1036static int ti_tiocmset(struct tty_struct *tty,
1016 unsigned int set, unsigned int clear) 1037 unsigned int set, unsigned int clear)
1017{ 1038{
1018 struct usb_serial_port *port = tty->driver_data; 1039 struct usb_serial_port *port = tty->driver_data;
1019 struct ti_port *tport = usb_get_serial_port_data(port); 1040 struct ti_port *tport = usb_get_serial_port_data(port);
@@ -1724,6 +1745,7 @@ static int ti_download_firmware(struct ti_device *tdev)
1724 } 1745 }
1725 if (fw_p->size > TI_FIRMWARE_BUF_SIZE) { 1746 if (fw_p->size > TI_FIRMWARE_BUF_SIZE) {
1726 dev_err(&dev->dev, "%s - firmware too large %zu\n", __func__, fw_p->size); 1747 dev_err(&dev->dev, "%s - firmware too large %zu\n", __func__, fw_p->size);
1748 release_firmware(fw_p);
1727 return -ENOENT; 1749 return -ENOENT;
1728 } 1750 }
1729 1751
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 7a2177c79bde..1c031309ab25 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -21,7 +21,6 @@
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/smp_lock.h>
25#include <linux/tty.h> 24#include <linux/tty.h>
26#include <linux/tty_driver.h> 25#include <linux/tty_driver.h>
27#include <linux/tty_flip.h> 26#include <linux/tty_flip.h>
@@ -52,6 +51,7 @@ static struct usb_driver usb_serial_driver = {
52 .suspend = usb_serial_suspend, 51 .suspend = usb_serial_suspend,
53 .resume = usb_serial_resume, 52 .resume = usb_serial_resume,
54 .no_dynamic_id = 1, 53 .no_dynamic_id = 1,
54 .supports_autosuspend = 1,
55}; 55};
56 56
57/* There is no MODULE_DEVICE_TABLE for usbserial.c. Instead 57/* There is no MODULE_DEVICE_TABLE for usbserial.c. Instead
@@ -406,7 +406,7 @@ static void serial_unthrottle(struct tty_struct *tty)
406 port->serial->type->unthrottle(tty); 406 port->serial->type->unthrottle(tty);
407} 407}
408 408
409static int serial_ioctl(struct tty_struct *tty, struct file *file, 409static int serial_ioctl(struct tty_struct *tty,
410 unsigned int cmd, unsigned long arg) 410 unsigned int cmd, unsigned long arg)
411{ 411{
412 struct usb_serial_port *port = tty->driver_data; 412 struct usb_serial_port *port = tty->driver_data;
@@ -417,7 +417,7 @@ static int serial_ioctl(struct tty_struct *tty, struct file *file,
417 /* pass on to the driver specific version of this function 417 /* pass on to the driver specific version of this function
418 if it is available */ 418 if it is available */
419 if (port->serial->type->ioctl) { 419 if (port->serial->type->ioctl) {
420 retval = port->serial->type->ioctl(tty, file, cmd, arg); 420 retval = port->serial->type->ioctl(tty, cmd, arg);
421 } else 421 } else
422 retval = -ENOIOCTLCMD; 422 retval = -ENOIOCTLCMD;
423 return retval; 423 return retval;
@@ -496,18 +496,18 @@ static const struct file_operations serial_proc_fops = {
496 .release = single_release, 496 .release = single_release,
497}; 497};
498 498
499static int serial_tiocmget(struct tty_struct *tty, struct file *file) 499static int serial_tiocmget(struct tty_struct *tty)
500{ 500{
501 struct usb_serial_port *port = tty->driver_data; 501 struct usb_serial_port *port = tty->driver_data;
502 502
503 dbg("%s - port %d", __func__, port->number); 503 dbg("%s - port %d", __func__, port->number);
504 504
505 if (port->serial->type->tiocmget) 505 if (port->serial->type->tiocmget)
506 return port->serial->type->tiocmget(tty, file); 506 return port->serial->type->tiocmget(tty);
507 return -EINVAL; 507 return -EINVAL;
508} 508}
509 509
510static int serial_tiocmset(struct tty_struct *tty, struct file *file, 510static int serial_tiocmset(struct tty_struct *tty,
511 unsigned int set, unsigned int clear) 511 unsigned int set, unsigned int clear)
512{ 512{
513 struct usb_serial_port *port = tty->driver_data; 513 struct usb_serial_port *port = tty->driver_data;
@@ -515,7 +515,19 @@ static int serial_tiocmset(struct tty_struct *tty, struct file *file,
515 dbg("%s - port %d", __func__, port->number); 515 dbg("%s - port %d", __func__, port->number);
516 516
517 if (port->serial->type->tiocmset) 517 if (port->serial->type->tiocmset)
518 return port->serial->type->tiocmset(tty, file, set, clear); 518 return port->serial->type->tiocmset(tty, set, clear);
519 return -EINVAL;
520}
521
522static int serial_get_icount(struct tty_struct *tty,
523 struct serial_icounter_struct *icount)
524{
525 struct usb_serial_port *port = tty->driver_data;
526
527 dbg("%s - port %d", __func__, port->number);
528
529 if (port->serial->type->get_icount)
530 return port->serial->type->get_icount(tty, icount);
519 return -EINVAL; 531 return -EINVAL;
520} 532}
521 533
@@ -899,9 +911,8 @@ int usb_serial_probe(struct usb_interface *interface,
899 dev_err(&interface->dev, "No free urbs available\n"); 911 dev_err(&interface->dev, "No free urbs available\n");
900 goto probe_error; 912 goto probe_error;
901 } 913 }
902 buffer_size = serial->type->bulk_in_size; 914 buffer_size = max_t(int, serial->type->bulk_in_size,
903 if (!buffer_size) 915 le16_to_cpu(endpoint->wMaxPacketSize));
904 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
905 port->bulk_in_size = buffer_size; 916 port->bulk_in_size = buffer_size;
906 port->bulk_in_endpointAddress = endpoint->bEndpointAddress; 917 port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
907 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 918 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
@@ -1195,6 +1206,7 @@ static const struct tty_operations serial_ops = {
1195 .chars_in_buffer = serial_chars_in_buffer, 1206 .chars_in_buffer = serial_chars_in_buffer,
1196 .tiocmget = serial_tiocmget, 1207 .tiocmget = serial_tiocmget,
1197 .tiocmset = serial_tiocmset, 1208 .tiocmset = serial_tiocmset,
1209 .get_icount = serial_get_icount,
1198 .cleanup = serial_cleanup, 1210 .cleanup = serial_cleanup,
1199 .install = serial_install, 1211 .install = serial_install,
1200 .proc_fops = &serial_proc_fops, 1212 .proc_fops = &serial_proc_fops,
@@ -1334,6 +1346,12 @@ int usb_serial_register(struct usb_serial_driver *driver)
1334 1346
1335 if (!driver->description) 1347 if (!driver->description)
1336 driver->description = driver->driver.name; 1348 driver->description = driver->driver.name;
1349 if (!driver->usb_driver) {
1350 WARN(1, "Serial driver %s has no usb_driver\n",
1351 driver->description);
1352 return -EINVAL;
1353 }
1354 driver->usb_driver->supports_autosuspend = 1;
1337 1355
1338 /* Add this device to our list of devices */ 1356 /* Add this device to our list of devices */
1339 mutex_lock(&table_lock); 1357 mutex_lock(&table_lock);
diff --git a/drivers/usb/serial/usb-wwan.h b/drivers/usb/serial/usb-wwan.h
index 2be298a1305b..c47b6ec03063 100644
--- a/drivers/usb/serial/usb-wwan.h
+++ b/drivers/usb/serial/usb-wwan.h
@@ -15,9 +15,11 @@ extern int usb_wwan_write_room(struct tty_struct *tty);
15extern void usb_wwan_set_termios(struct tty_struct *tty, 15extern void usb_wwan_set_termios(struct tty_struct *tty,
16 struct usb_serial_port *port, 16 struct usb_serial_port *port,
17 struct ktermios *old); 17 struct ktermios *old);
18extern int usb_wwan_tiocmget(struct tty_struct *tty, struct file *file); 18extern int usb_wwan_tiocmget(struct tty_struct *tty);
19extern int usb_wwan_tiocmset(struct tty_struct *tty, struct file *file, 19extern int usb_wwan_tiocmset(struct tty_struct *tty,
20 unsigned int set, unsigned int clear); 20 unsigned int set, unsigned int clear);
21extern int usb_wwan_ioctl(struct tty_struct *tty,
22 unsigned int cmd, unsigned long arg);
21extern int usb_wwan_send_setup(struct usb_serial_port *port); 23extern int usb_wwan_send_setup(struct usb_serial_port *port);
22extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, 24extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
23 const unsigned char *buf, int count); 25 const unsigned char *buf, int count);
diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c
index f2ed6a31be77..95a82148ee81 100644
--- a/drivers/usb/serial/usb_debug.c
+++ b/drivers/usb/serial/usb_debug.c
@@ -75,6 +75,7 @@ static struct usb_serial_driver debug_device = {
75 .name = "debug", 75 .name = "debug",
76 }, 76 },
77 .id_table = id_table, 77 .id_table = id_table,
78 .usb_driver = &debug_driver,
78 .num_ports = 1, 79 .num_ports = 1,
79 .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE, 80 .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE,
80 .break_ctl = usb_debug_break_ctl, 81 .break_ctl = usb_debug_break_ctl,
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
index 0c70b4a621bb..e4fad5e643d7 100644
--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -31,8 +31,10 @@
31#include <linux/tty_flip.h> 31#include <linux/tty_flip.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/bitops.h> 33#include <linux/bitops.h>
34#include <linux/uaccess.h>
34#include <linux/usb.h> 35#include <linux/usb.h>
35#include <linux/usb/serial.h> 36#include <linux/usb/serial.h>
37#include <linux/serial.h>
36#include "usb-wwan.h" 38#include "usb-wwan.h"
37 39
38static int debug; 40static int debug;
@@ -77,7 +79,7 @@ void usb_wwan_set_termios(struct tty_struct *tty,
77} 79}
78EXPORT_SYMBOL(usb_wwan_set_termios); 80EXPORT_SYMBOL(usb_wwan_set_termios);
79 81
80int usb_wwan_tiocmget(struct tty_struct *tty, struct file *file) 82int usb_wwan_tiocmget(struct tty_struct *tty)
81{ 83{
82 struct usb_serial_port *port = tty->driver_data; 84 struct usb_serial_port *port = tty->driver_data;
83 unsigned int value; 85 unsigned int value;
@@ -96,7 +98,7 @@ int usb_wwan_tiocmget(struct tty_struct *tty, struct file *file)
96} 98}
97EXPORT_SYMBOL(usb_wwan_tiocmget); 99EXPORT_SYMBOL(usb_wwan_tiocmget);
98 100
99int usb_wwan_tiocmset(struct tty_struct *tty, struct file *file, 101int usb_wwan_tiocmset(struct tty_struct *tty,
100 unsigned int set, unsigned int clear) 102 unsigned int set, unsigned int clear)
101{ 103{
102 struct usb_serial_port *port = tty->driver_data; 104 struct usb_serial_port *port = tty->driver_data;
@@ -123,6 +125,83 @@ int usb_wwan_tiocmset(struct tty_struct *tty, struct file *file,
123} 125}
124EXPORT_SYMBOL(usb_wwan_tiocmset); 126EXPORT_SYMBOL(usb_wwan_tiocmset);
125 127
128static int get_serial_info(struct usb_serial_port *port,
129 struct serial_struct __user *retinfo)
130{
131 struct serial_struct tmp;
132
133 if (!retinfo)
134 return -EFAULT;
135
136 memset(&tmp, 0, sizeof(tmp));
137 tmp.line = port->serial->minor;
138 tmp.port = port->number;
139 tmp.baud_base = tty_get_baud_rate(port->port.tty);
140 tmp.close_delay = port->port.close_delay / 10;
141 tmp.closing_wait = port->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
142 ASYNC_CLOSING_WAIT_NONE :
143 port->port.closing_wait / 10;
144
145 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
146 return -EFAULT;
147 return 0;
148}
149
150static int set_serial_info(struct usb_serial_port *port,
151 struct serial_struct __user *newinfo)
152{
153 struct serial_struct new_serial;
154 unsigned int closing_wait, close_delay;
155 int retval = 0;
156
157 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
158 return -EFAULT;
159
160 close_delay = new_serial.close_delay * 10;
161 closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
162 ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
163
164 mutex_lock(&port->port.mutex);
165
166 if (!capable(CAP_SYS_ADMIN)) {
167 if ((close_delay != port->port.close_delay) ||
168 (closing_wait != port->port.closing_wait))
169 retval = -EPERM;
170 else
171 retval = -EOPNOTSUPP;
172 } else {
173 port->port.close_delay = close_delay;
174 port->port.closing_wait = closing_wait;
175 }
176
177 mutex_unlock(&port->port.mutex);
178 return retval;
179}
180
181int usb_wwan_ioctl(struct tty_struct *tty,
182 unsigned int cmd, unsigned long arg)
183{
184 struct usb_serial_port *port = tty->driver_data;
185
186 dbg("%s cmd 0x%04x", __func__, cmd);
187
188 switch (cmd) {
189 case TIOCGSERIAL:
190 return get_serial_info(port,
191 (struct serial_struct __user *) arg);
192 case TIOCSSERIAL:
193 return set_serial_info(port,
194 (struct serial_struct __user *) arg);
195 default:
196 break;
197 }
198
199 dbg("%s arg not supported", __func__);
200
201 return -ENOIOCTLCMD;
202}
203EXPORT_SYMBOL(usb_wwan_ioctl);
204
126/* Write */ 205/* Write */
127int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, 206int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
128 const unsigned char *buf, int count) 207 const unsigned char *buf, int count)
@@ -182,7 +261,8 @@ int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
182 intfdata->in_flight--; 261 intfdata->in_flight--;
183 spin_unlock_irqrestore(&intfdata->susp_lock, 262 spin_unlock_irqrestore(&intfdata->susp_lock,
184 flags); 263 flags);
185 continue; 264 usb_autopm_put_interface_async(port->serial->interface);
265 break;
186 } 266 }
187 } 267 }
188 268
@@ -216,25 +296,32 @@ static void usb_wwan_indat_callback(struct urb *urb)
216 __func__, status, endpoint); 296 __func__, status, endpoint);
217 } else { 297 } else {
218 tty = tty_port_tty_get(&port->port); 298 tty = tty_port_tty_get(&port->port);
219 if (urb->actual_length) { 299 if (tty) {
220 tty_insert_flip_string(tty, data, urb->actual_length); 300 if (urb->actual_length) {
221 tty_flip_buffer_push(tty); 301 tty_insert_flip_string(tty, data,
222 } else 302 urb->actual_length);
223 dbg("%s: empty read urb received", __func__); 303 tty_flip_buffer_push(tty);
224 tty_kref_put(tty); 304 } else
305 dbg("%s: empty read urb received", __func__);
306 tty_kref_put(tty);
307 }
225 308
226 /* Resubmit urb so we continue receiving */ 309 /* Resubmit urb so we continue receiving */
227 if (status != -ESHUTDOWN) { 310 if (status != -ESHUTDOWN) {
228 err = usb_submit_urb(urb, GFP_ATOMIC); 311 err = usb_submit_urb(urb, GFP_ATOMIC);
229 if (err && err != -EPERM) 312 if (err) {
230 printk(KERN_ERR "%s: resubmit read urb failed. " 313 if (err != -EPERM) {
231 "(%d)", __func__, err); 314 printk(KERN_ERR "%s: resubmit read urb failed. "
232 else 315 "(%d)", __func__, err);
316 /* busy also in error unless we are killed */
317 usb_mark_last_busy(port->serial->dev);
318 }
319 } else {
233 usb_mark_last_busy(port->serial->dev); 320 usb_mark_last_busy(port->serial->dev);
321 }
234 } 322 }
235 323
236 } 324 }
237 return;
238} 325}
239 326
240static void usb_wwan_outdat_callback(struct urb *urb) 327static void usb_wwan_outdat_callback(struct urb *urb)
@@ -340,6 +427,7 @@ int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port)
340 spin_lock_irq(&intfdata->susp_lock); 427 spin_lock_irq(&intfdata->susp_lock);
341 portdata->opened = 1; 428 portdata->opened = 1;
342 spin_unlock_irq(&intfdata->susp_lock); 429 spin_unlock_irq(&intfdata->susp_lock);
430 /* this balances a get in the generic USB serial code */
343 usb_autopm_put_interface(serial->interface); 431 usb_autopm_put_interface(serial->interface);
344 432
345 return 0; 433 return 0;
@@ -366,7 +454,8 @@ void usb_wwan_close(struct usb_serial_port *port)
366 usb_kill_urb(portdata->in_urbs[i]); 454 usb_kill_urb(portdata->in_urbs[i]);
367 for (i = 0; i < N_OUT_URB; i++) 455 for (i = 0; i < N_OUT_URB; i++)
368 usb_kill_urb(portdata->out_urbs[i]); 456 usb_kill_urb(portdata->out_urbs[i]);
369 usb_autopm_get_interface(serial->interface); 457 /* balancing - important as an error cannot be handled*/
458 usb_autopm_get_interface_no_resume(serial->interface);
370 serial->interface->needs_remote_wakeup = 0; 459 serial->interface->needs_remote_wakeup = 0;
371 } 460 }
372} 461}
@@ -580,6 +669,18 @@ int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message)
580} 669}
581EXPORT_SYMBOL(usb_wwan_suspend); 670EXPORT_SYMBOL(usb_wwan_suspend);
582 671
672static void unbusy_queued_urb(struct urb *urb, struct usb_wwan_port_private *portdata)
673{
674 int i;
675
676 for (i = 0; i < N_OUT_URB; i++) {
677 if (urb == portdata->out_urbs[i]) {
678 clear_bit(i, &portdata->out_busy);
679 break;
680 }
681 }
682}
683
583static void play_delayed(struct usb_serial_port *port) 684static void play_delayed(struct usb_serial_port *port)
584{ 685{
585 struct usb_wwan_intf_private *data; 686 struct usb_wwan_intf_private *data;
@@ -591,8 +692,16 @@ static void play_delayed(struct usb_serial_port *port)
591 data = port->serial->private; 692 data = port->serial->private;
592 while ((urb = usb_get_from_anchor(&portdata->delayed))) { 693 while ((urb = usb_get_from_anchor(&portdata->delayed))) {
593 err = usb_submit_urb(urb, GFP_ATOMIC); 694 err = usb_submit_urb(urb, GFP_ATOMIC);
594 if (!err) 695 if (!err) {
595 data->in_flight++; 696 data->in_flight++;
697 } else {
698 /* we have to throw away the rest */
699 do {
700 unbusy_queued_urb(urb, portdata);
701 usb_autopm_put_interface_no_suspend(port->serial->interface);
702 } while ((urb = usb_get_from_anchor(&portdata->delayed)));
703 break;
704 }
596 } 705 }
597} 706}
598 707
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index eb76aaef4268..1c11959a7d58 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -27,6 +27,7 @@
27#include <linux/uaccess.h> 27#include <linux/uaccess.h>
28#include <linux/usb.h> 28#include <linux/usb.h>
29#include <linux/usb/serial.h> 29#include <linux/usb/serial.h>
30#include <linux/usb/cdc.h>
30#include "visor.h" 31#include "visor.h"
31 32
32/* 33/*
@@ -479,6 +480,17 @@ static int visor_probe(struct usb_serial *serial,
479 480
480 dbg("%s", __func__); 481 dbg("%s", __func__);
481 482
483 /*
484 * some Samsung Android phones in modem mode have the same ID
485 * as SPH-I500, but they are ACM devices, so dont bind to them
486 */
487 if (id->idVendor == SAMSUNG_VENDOR_ID &&
488 id->idProduct == SAMSUNG_SPH_I500_ID &&
489 serial->dev->descriptor.bDeviceClass == USB_CLASS_COMM &&
490 serial->dev->descriptor.bDeviceSubClass ==
491 USB_CDC_SUBCLASS_ACM)
492 return -ENODEV;
493
482 if (serial->dev->actconfig->desc.bConfigurationValue != 1) { 494 if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
483 dev_err(&serial->dev->dev, "active config #%d != 1 ??\n", 495 dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
484 serial->dev->actconfig->desc.bConfigurationValue); 496 serial->dev->actconfig->desc.bConfigurationValue);
@@ -606,6 +618,10 @@ static int treo_attach(struct usb_serial *serial)
606 618
607static int clie_5_attach(struct usb_serial *serial) 619static int clie_5_attach(struct usb_serial *serial)
608{ 620{
621 struct usb_serial_port *port;
622 unsigned int pipe;
623 int j;
624
609 dbg("%s", __func__); 625 dbg("%s", __func__);
610 626
611 /* TH55 registers 2 ports. 627 /* TH55 registers 2 ports.
@@ -621,9 +637,14 @@ static int clie_5_attach(struct usb_serial *serial)
621 return -1; 637 return -1;
622 638
623 /* port 0 now uses the modified endpoint Address */ 639 /* port 0 now uses the modified endpoint Address */
624 serial->port[0]->bulk_out_endpointAddress = 640 port = serial->port[0];
641 port->bulk_out_endpointAddress =
625 serial->port[1]->bulk_out_endpointAddress; 642 serial->port[1]->bulk_out_endpointAddress;
626 643
644 pipe = usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress);
645 for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j)
646 port->write_urbs[j]->pipe = pipe;
647
627 return 0; 648 return 0;
628} 649}
629 650
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 12ed8209ca72..5b073bcc807b 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -152,12 +152,12 @@ static int whiteheat_write(struct tty_struct *tty,
152 struct usb_serial_port *port, 152 struct usb_serial_port *port,
153 const unsigned char *buf, int count); 153 const unsigned char *buf, int count);
154static int whiteheat_write_room(struct tty_struct *tty); 154static int whiteheat_write_room(struct tty_struct *tty);
155static int whiteheat_ioctl(struct tty_struct *tty, struct file *file, 155static int whiteheat_ioctl(struct tty_struct *tty,
156 unsigned int cmd, unsigned long arg); 156 unsigned int cmd, unsigned long arg);
157static void whiteheat_set_termios(struct tty_struct *tty, 157static void whiteheat_set_termios(struct tty_struct *tty,
158 struct usb_serial_port *port, struct ktermios *old); 158 struct usb_serial_port *port, struct ktermios *old);
159static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file); 159static int whiteheat_tiocmget(struct tty_struct *tty);
160static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file, 160static int whiteheat_tiocmset(struct tty_struct *tty,
161 unsigned int set, unsigned int clear); 161 unsigned int set, unsigned int clear);
162static void whiteheat_break_ctl(struct tty_struct *tty, int break_state); 162static void whiteheat_break_ctl(struct tty_struct *tty, int break_state);
163static int whiteheat_chars_in_buffer(struct tty_struct *tty); 163static int whiteheat_chars_in_buffer(struct tty_struct *tty);
@@ -655,8 +655,6 @@ static void whiteheat_release(struct usb_serial *serial)
655 } 655 }
656 kfree(info); 656 kfree(info);
657 } 657 }
658
659 return;
660} 658}
661 659
662static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port) 660static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port)
@@ -835,7 +833,7 @@ static int whiteheat_write_room(struct tty_struct *tty)
835 return (room); 833 return (room);
836} 834}
837 835
838static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file) 836static int whiteheat_tiocmget(struct tty_struct *tty)
839{ 837{
840 struct usb_serial_port *port = tty->driver_data; 838 struct usb_serial_port *port = tty->driver_data;
841 struct whiteheat_private *info = usb_get_serial_port_data(port); 839 struct whiteheat_private *info = usb_get_serial_port_data(port);
@@ -852,7 +850,7 @@ static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file)
852 return modem_signals; 850 return modem_signals;
853} 851}
854 852
855static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file, 853static int whiteheat_tiocmset(struct tty_struct *tty,
856 unsigned int set, unsigned int clear) 854 unsigned int set, unsigned int clear)
857{ 855{
858 struct usb_serial_port *port = tty->driver_data; 856 struct usb_serial_port *port = tty->driver_data;
@@ -876,7 +874,7 @@ static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file,
876} 874}
877 875
878 876
879static int whiteheat_ioctl(struct tty_struct *tty, struct file *file, 877static int whiteheat_ioctl(struct tty_struct *tty,
880 unsigned int cmd, unsigned long arg) 878 unsigned int cmd, unsigned long arg)
881{ 879{
882 struct usb_serial_port *port = tty->driver_data; 880 struct usb_serial_port *port = tty->driver_data;
@@ -955,8 +953,6 @@ static void whiteheat_throttle(struct tty_struct *tty)
955 spin_lock_irq(&info->lock); 953 spin_lock_irq(&info->lock);
956 info->flags |= THROTTLED; 954 info->flags |= THROTTLED;
957 spin_unlock_irq(&info->lock); 955 spin_unlock_irq(&info->lock);
958
959 return;
960} 956}
961 957
962 958
@@ -975,8 +971,6 @@ static void whiteheat_unthrottle(struct tty_struct *tty)
975 971
976 if (actually_throttled) 972 if (actually_throttled)
977 rx_data_softint(&info->rx_work); 973 rx_data_softint(&info->rx_work);
978
979 return;
980} 974}
981 975
982 976
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index 8a372bac0e43..97987255be75 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -31,12 +31,22 @@ config USB_STORAGE_DEBUG
31 Say Y here in order to have the USB Mass Storage code generate 31 Say Y here in order to have the USB Mass Storage code generate
32 verbose debugging messages. 32 verbose debugging messages.
33 33
34config USB_STORAGE_REALTEK
35 tristate "Realtek Card Reader support"
36 depends on USB_STORAGE
37 help
38 Say Y here to include additional code to support the power-saving function
39 for Realtek RTS51xx USB card readers.
40
41 If this driver is compiled as a module, it will be named ums-realtek.
42
43
34config USB_STORAGE_DATAFAB 44config USB_STORAGE_DATAFAB
35 tristate "Datafab Compact Flash Reader support" 45 tristate "Datafab Compact Flash Reader support"
36 depends on USB_STORAGE 46 depends on USB_STORAGE
37 help 47 help
38 Support for certain Datafab CompactFlash readers. 48 Support for certain Datafab CompactFlash readers.
39 Datafab has a web page at <http://www.datafabusa.com/>. 49 Datafab has a web page at <http://www.datafab.com/>.
40 50
41 If this driver is compiled as a module, it will be named ums-datafab. 51 If this driver is compiled as a module, it will be named ums-datafab.
42 52
@@ -172,6 +182,34 @@ config USB_STORAGE_CYPRESS_ATACB
172 182
173 If this driver is compiled as a module, it will be named ums-cypress. 183 If this driver is compiled as a module, it will be named ums-cypress.
174 184
185config USB_STORAGE_ENE_UB6250
186 tristate "USB ENE card reader support"
187 depends on USB && SCSI
188 depends on USB_STORAGE
189 ---help---
190 Say Y here if you wish to control a ENE SD Card reader.
191 To use SM/MS card, please build driver/staging/keucr/keucr.ko
192
193 This option depends on 'SCSI' support being enabled, but you
194 probably also need 'SCSI device support: SCSI disk support'
195 (BLK_DEV_SD) for most USB storage devices.
196
197 To compile this driver as a module, choose M here: the
198 module will be called ums-eneub6250.
199
200config USB_UAS
201 tristate "USB Attached SCSI"
202 depends on USB && SCSI
203 help
204 The USB Attached SCSI protocol is supported by some USB
205 storage devices. It permits higher performance by supporting
206 multiple outstanding commands.
207
208 If you don't know whether you have a UAS device, it is safe to
209 say 'Y' or 'M' here and the kernel will use the right driver.
210
211 If you compile this driver as a module, it will be named uas.
212
175config USB_LIBUSUAL 213config USB_LIBUSUAL
176 bool "The shared table of common (or usual) storage devices" 214 bool "The shared table of common (or usual) storage devices"
177 depends on USB 215 depends on USB
diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile
index ef7e5a8ceab5..82e6416a2d47 100644
--- a/drivers/usb/storage/Makefile
+++ b/drivers/usb/storage/Makefile
@@ -5,42 +5,47 @@
5# Rewritten to use lists instead of if-statements. 5# Rewritten to use lists instead of if-statements.
6# 6#
7 7
8EXTRA_CFLAGS := -Idrivers/scsi 8ccflags-y := -Idrivers/scsi
9 9
10obj-$(CONFIG_USB_UAS) += uas.o
10obj-$(CONFIG_USB_STORAGE) += usb-storage.o 11obj-$(CONFIG_USB_STORAGE) += usb-storage.o
11 12
12usb-storage-obj-$(CONFIG_USB_STORAGE_DEBUG) += debug.o 13usb-storage-y := scsiglue.o protocol.o transport.o usb.o
14usb-storage-y += initializers.o sierra_ms.o option_ms.o
13 15
14usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ 16usb-storage-$(CONFIG_USB_STORAGE_DEBUG) += debug.o
15 initializers.o sierra_ms.o option_ms.o $(usb-storage-obj-y)
16 17
17ifeq ($(CONFIG_USB_LIBUSUAL),) 18ifeq ($(CONFIG_USB_LIBUSUAL),)
18 usb-storage-objs += usual-tables.o 19 usb-storage-y += usual-tables.o
19else 20else
20 obj-$(CONFIG_USB) += usb-libusual.o 21 obj-$(CONFIG_USB) += usb-libusual.o
21 usb-libusual-objs := libusual.o usual-tables.o 22 usb-libusual-y := libusual.o usual-tables.o
22endif 23endif
23 24
24obj-$(CONFIG_USB_STORAGE_ALAUDA) += ums-alauda.o 25obj-$(CONFIG_USB_STORAGE_ALAUDA) += ums-alauda.o
25obj-$(CONFIG_USB_STORAGE_CYPRESS_ATACB) += ums-cypress.o 26obj-$(CONFIG_USB_STORAGE_CYPRESS_ATACB) += ums-cypress.o
26obj-$(CONFIG_USB_STORAGE_DATAFAB) += ums-datafab.o 27obj-$(CONFIG_USB_STORAGE_DATAFAB) += ums-datafab.o
28obj-$(CONFIG_USB_STORAGE_ENE_UB6250) += ums-eneub6250.o
27obj-$(CONFIG_USB_STORAGE_FREECOM) += ums-freecom.o 29obj-$(CONFIG_USB_STORAGE_FREECOM) += ums-freecom.o
28obj-$(CONFIG_USB_STORAGE_ISD200) += ums-isd200.o 30obj-$(CONFIG_USB_STORAGE_ISD200) += ums-isd200.o
29obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += ums-jumpshot.o 31obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += ums-jumpshot.o
30obj-$(CONFIG_USB_STORAGE_KARMA) += ums-karma.o 32obj-$(CONFIG_USB_STORAGE_KARMA) += ums-karma.o
31obj-$(CONFIG_USB_STORAGE_ONETOUCH) += ums-onetouch.o 33obj-$(CONFIG_USB_STORAGE_ONETOUCH) += ums-onetouch.o
34obj-$(CONFIG_USB_STORAGE_REALTEK) += ums-realtek.o
32obj-$(CONFIG_USB_STORAGE_SDDR09) += ums-sddr09.o 35obj-$(CONFIG_USB_STORAGE_SDDR09) += ums-sddr09.o
33obj-$(CONFIG_USB_STORAGE_SDDR55) += ums-sddr55.o 36obj-$(CONFIG_USB_STORAGE_SDDR55) += ums-sddr55.o
34obj-$(CONFIG_USB_STORAGE_USBAT) += ums-usbat.o 37obj-$(CONFIG_USB_STORAGE_USBAT) += ums-usbat.o
35 38
36ums-alauda-objs := alauda.o 39ums-alauda-y := alauda.o
37ums-cypress-objs := cypress_atacb.o 40ums-cypress-y := cypress_atacb.o
38ums-datafab-objs := datafab.o 41ums-datafab-y := datafab.o
39ums-freecom-objs := freecom.o 42ums-eneub6250-y := ene_ub6250.o
40ums-isd200-objs := isd200.o 43ums-freecom-y := freecom.o
41ums-jumpshot-objs := jumpshot.o 44ums-isd200-y := isd200.o
42ums-karma-objs := karma.o 45ums-jumpshot-y := jumpshot.o
43ums-onetouch-objs := onetouch.o 46ums-karma-y := karma.o
44ums-sddr09-objs := sddr09.o 47ums-onetouch-y := onetouch.o
45ums-sddr55-objs := sddr55.o 48ums-realtek-y := realtek_cr.o
46ums-usbat-objs := shuttle_usbat.o 49ums-sddr09-y := sddr09.o
50ums-sddr55-y := sddr55.o
51ums-usbat-y := shuttle_usbat.o
diff --git a/drivers/usb/storage/ene_ub6250.c b/drivers/usb/storage/ene_ub6250.c
new file mode 100644
index 000000000000..31645afff5fc
--- /dev/null
+++ b/drivers/usb/storage/ene_ub6250.c
@@ -0,0 +1,803 @@
1/*
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
6 * later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17#include <linux/jiffies.h>
18#include <linux/errno.h>
19#include <linux/module.h>
20#include <linux/slab.h>
21
22#include <scsi/scsi.h>
23#include <scsi/scsi_cmnd.h>
24
25#include <linux/firmware.h>
26
27#include "usb.h"
28#include "transport.h"
29#include "protocol.h"
30#include "debug.h"
31
32MODULE_DESCRIPTION("Driver for ENE UB6250 reader");
33MODULE_LICENSE("GPL");
34
35
36/*
37 * The table of devices
38 */
39#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
40 vendorName, productName, useProtocol, useTransport, \
41 initFunction, flags) \
42{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
43 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
44
45struct usb_device_id ene_ub6250_usb_ids[] = {
46# include "unusual_ene_ub6250.h"
47 { } /* Terminating entry */
48};
49MODULE_DEVICE_TABLE(usb, ene_ub6250_usb_ids);
50
51#undef UNUSUAL_DEV
52
53/*
54 * The flags table
55 */
56#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
57 vendor_name, product_name, use_protocol, use_transport, \
58 init_function, Flags) \
59{ \
60 .vendorName = vendor_name, \
61 .productName = product_name, \
62 .useProtocol = use_protocol, \
63 .useTransport = use_transport, \
64 .initFunction = init_function, \
65}
66
67static struct us_unusual_dev ene_ub6250_unusual_dev_list[] = {
68# include "unusual_ene_ub6250.h"
69 { } /* Terminating entry */
70};
71
72#undef UNUSUAL_DEV
73
74
75
76/* ENE bin code len */
77#define ENE_BIN_CODE_LEN 0x800
78/* EnE HW Register */
79#define REG_CARD_STATUS 0xFF83
80#define REG_HW_TRAP1 0xFF89
81
82/* SRB Status */
83#define SS_SUCCESS 0x00 /* No Sense */
84#define SS_NOT_READY 0x02
85#define SS_MEDIUM_ERR 0x03
86#define SS_HW_ERR 0x04
87#define SS_ILLEGAL_REQUEST 0x05
88#define SS_UNIT_ATTENTION 0x06
89
90/* ENE Load FW Pattern */
91#define SD_INIT1_PATTERN 1
92#define SD_INIT2_PATTERN 2
93#define SD_RW_PATTERN 3
94#define MS_INIT_PATTERN 4
95#define MSP_RW_PATTERN 5
96#define MS_RW_PATTERN 6
97#define SM_INIT_PATTERN 7
98#define SM_RW_PATTERN 8
99
100#define FDIR_WRITE 0
101#define FDIR_READ 1
102
103
104struct SD_STATUS {
105 u8 Insert:1;
106 u8 Ready:1;
107 u8 MediaChange:1;
108 u8 IsMMC:1;
109 u8 HiCapacity:1;
110 u8 HiSpeed:1;
111 u8 WtP:1;
112 u8 Reserved:1;
113};
114
115struct MS_STATUS {
116 u8 Insert:1;
117 u8 Ready:1;
118 u8 MediaChange:1;
119 u8 IsMSPro:1;
120 u8 IsMSPHG:1;
121 u8 Reserved1:1;
122 u8 WtP:1;
123 u8 Reserved2:1;
124};
125
126struct SM_STATUS {
127 u8 Insert:1;
128 u8 Ready:1;
129 u8 MediaChange:1;
130 u8 Reserved:3;
131 u8 WtP:1;
132 u8 IsMS:1;
133};
134
135
136/* SD Block Length */
137/* 2^9 = 512 Bytes, The HW maximum read/write data length */
138#define SD_BLOCK_LEN 9
139
140struct ene_ub6250_info {
141 /* for 6250 code */
142 struct SD_STATUS SD_Status;
143 struct MS_STATUS MS_Status;
144 struct SM_STATUS SM_Status;
145
146 /* ----- SD Control Data ---------------- */
147 /*SD_REGISTER SD_Regs; */
148 u16 SD_Block_Mult;
149 u8 SD_READ_BL_LEN;
150 u16 SD_C_SIZE;
151 u8 SD_C_SIZE_MULT;
152
153 /* SD/MMC New spec. */
154 u8 SD_SPEC_VER;
155 u8 SD_CSD_VER;
156 u8 SD20_HIGH_CAPACITY;
157 u32 HC_C_SIZE;
158 u8 MMC_SPEC_VER;
159 u8 MMC_BusWidth;
160 u8 MMC_HIGH_CAPACITY;
161
162 /*----- MS Control Data ---------------- */
163 bool MS_SWWP;
164 u32 MSP_TotalBlock;
165 /*MS_LibControl MS_Lib;*/
166 bool MS_IsRWPage;
167 u16 MS_Model;
168
169 /*----- SM Control Data ---------------- */
170 u8 SM_DeviceID;
171 u8 SM_CardID;
172
173 unsigned char *testbuf;
174 u8 BIN_FLAG;
175 u32 bl_num;
176 int SrbStatus;
177
178 /*------Power Managerment ---------------*/
179 bool Power_IsResum;
180};
181
182static int ene_sd_init(struct us_data *us);
183static int ene_load_bincode(struct us_data *us, unsigned char flag);
184
185static void ene_ub6250_info_destructor(void *extra)
186{
187 if (!extra)
188 return;
189}
190
191static int ene_send_scsi_cmd(struct us_data *us, u8 fDir, void *buf, int use_sg)
192{
193 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
194 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
195
196 int result;
197 unsigned int residue;
198 unsigned int cswlen = 0, partial = 0;
199 unsigned int transfer_length = bcb->DataTransferLength;
200
201 /* US_DEBUGP("transport --- ene_send_scsi_cmd\n"); */
202 /* send cmd to out endpoint */
203 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
204 bcb, US_BULK_CB_WRAP_LEN, NULL);
205 if (result != USB_STOR_XFER_GOOD) {
206 US_DEBUGP("send cmd to out endpoint fail ---\n");
207 return USB_STOR_TRANSPORT_ERROR;
208 }
209
210 if (buf) {
211 unsigned int pipe = fDir;
212
213 if (fDir == FDIR_READ)
214 pipe = us->recv_bulk_pipe;
215 else
216 pipe = us->send_bulk_pipe;
217
218 /* Bulk */
219 if (use_sg) {
220 result = usb_stor_bulk_srb(us, pipe, us->srb);
221 } else {
222 result = usb_stor_bulk_transfer_sg(us, pipe, buf,
223 transfer_length, 0, &partial);
224 }
225 if (result != USB_STOR_XFER_GOOD) {
226 US_DEBUGP("data transfer fail ---\n");
227 return USB_STOR_TRANSPORT_ERROR;
228 }
229 }
230
231 /* Get CSW for device status */
232 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
233 US_BULK_CS_WRAP_LEN, &cswlen);
234
235 if (result == USB_STOR_XFER_SHORT && cswlen == 0) {
236 US_DEBUGP("Received 0-length CSW; retrying...\n");
237 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
238 bcs, US_BULK_CS_WRAP_LEN, &cswlen);
239 }
240
241 if (result == USB_STOR_XFER_STALLED) {
242 /* get the status again */
243 US_DEBUGP("Attempting to get CSW (2nd try)...\n");
244 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
245 bcs, US_BULK_CS_WRAP_LEN, NULL);
246 }
247
248 if (result != USB_STOR_XFER_GOOD)
249 return USB_STOR_TRANSPORT_ERROR;
250
251 /* check bulk status */
252 residue = le32_to_cpu(bcs->Residue);
253
254 /* try to compute the actual residue, based on how much data
255 * was really transferred and what the device tells us */
256 if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) {
257 residue = min(residue, transfer_length);
258 if (us->srb != NULL)
259 scsi_set_resid(us->srb, max(scsi_get_resid(us->srb),
260 (int)residue));
261 }
262
263 if (bcs->Status != US_BULK_STAT_OK)
264 return USB_STOR_TRANSPORT_ERROR;
265
266 return USB_STOR_TRANSPORT_GOOD;
267}
268
269static int sd_scsi_test_unit_ready(struct us_data *us, struct scsi_cmnd *srb)
270{
271 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
272
273 if (info->SD_Status.Insert && info->SD_Status.Ready)
274 return USB_STOR_TRANSPORT_GOOD;
275 else {
276 ene_sd_init(us);
277 return USB_STOR_TRANSPORT_GOOD;
278 }
279
280 return USB_STOR_TRANSPORT_GOOD;
281}
282
283static int sd_scsi_inquiry(struct us_data *us, struct scsi_cmnd *srb)
284{
285 unsigned char data_ptr[36] = {
286 0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55,
287 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61,
288 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20,
289 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30 };
290
291 usb_stor_set_xfer_buf(data_ptr, 36, srb);
292 return USB_STOR_TRANSPORT_GOOD;
293}
294
295static int sd_scsi_mode_sense(struct us_data *us, struct scsi_cmnd *srb)
296{
297 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
298 unsigned char mediaNoWP[12] = {
299 0x0b, 0x00, 0x00, 0x08, 0x00, 0x00,
300 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
301 unsigned char mediaWP[12] = {
302 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00,
303 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
304
305 if (info->SD_Status.WtP)
306 usb_stor_set_xfer_buf(mediaWP, 12, srb);
307 else
308 usb_stor_set_xfer_buf(mediaNoWP, 12, srb);
309
310
311 return USB_STOR_TRANSPORT_GOOD;
312}
313
314static int sd_scsi_read_capacity(struct us_data *us, struct scsi_cmnd *srb)
315{
316 u32 bl_num;
317 u16 bl_len;
318 unsigned int offset = 0;
319 unsigned char buf[8];
320 struct scatterlist *sg = NULL;
321 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
322
323 US_DEBUGP("sd_scsi_read_capacity\n");
324 if (info->SD_Status.HiCapacity) {
325 bl_len = 0x200;
326 if (info->SD_Status.IsMMC)
327 bl_num = info->HC_C_SIZE-1;
328 else
329 bl_num = (info->HC_C_SIZE + 1) * 1024 - 1;
330 } else {
331 bl_len = 1<<(info->SD_READ_BL_LEN);
332 bl_num = info->SD_Block_Mult * (info->SD_C_SIZE + 1)
333 * (1 << (info->SD_C_SIZE_MULT + 2)) - 1;
334 }
335 info->bl_num = bl_num;
336 US_DEBUGP("bl_len = %x\n", bl_len);
337 US_DEBUGP("bl_num = %x\n", bl_num);
338
339 /*srb->request_bufflen = 8; */
340 buf[0] = (bl_num >> 24) & 0xff;
341 buf[1] = (bl_num >> 16) & 0xff;
342 buf[2] = (bl_num >> 8) & 0xff;
343 buf[3] = (bl_num >> 0) & 0xff;
344 buf[4] = (bl_len >> 24) & 0xff;
345 buf[5] = (bl_len >> 16) & 0xff;
346 buf[6] = (bl_len >> 8) & 0xff;
347 buf[7] = (bl_len >> 0) & 0xff;
348
349 usb_stor_access_xfer_buf(buf, 8, srb, &sg, &offset, TO_XFER_BUF);
350
351 return USB_STOR_TRANSPORT_GOOD;
352}
353
354static int sd_scsi_read(struct us_data *us, struct scsi_cmnd *srb)
355{
356 int result;
357 unsigned char *cdb = srb->cmnd;
358 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
359 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
360
361 u32 bn = ((cdb[2] << 24) & 0xff000000) | ((cdb[3] << 16) & 0x00ff0000) |
362 ((cdb[4] << 8) & 0x0000ff00) | ((cdb[5] << 0) & 0x000000ff);
363 u16 blen = ((cdb[7] << 8) & 0xff00) | ((cdb[8] << 0) & 0x00ff);
364 u32 bnByte = bn * 0x200;
365 u32 blenByte = blen * 0x200;
366
367 if (bn > info->bl_num)
368 return USB_STOR_TRANSPORT_ERROR;
369
370 result = ene_load_bincode(us, SD_RW_PATTERN);
371 if (result != USB_STOR_XFER_GOOD) {
372 US_DEBUGP("Load SD RW pattern Fail !!\n");
373 return USB_STOR_TRANSPORT_ERROR;
374 }
375
376 if (info->SD_Status.HiCapacity)
377 bnByte = bn;
378
379 /* set up the command wrapper */
380 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
381 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
382 bcb->DataTransferLength = blenByte;
383 bcb->Flags = 0x80;
384 bcb->CDB[0] = 0xF1;
385 bcb->CDB[5] = (unsigned char)(bnByte);
386 bcb->CDB[4] = (unsigned char)(bnByte>>8);
387 bcb->CDB[3] = (unsigned char)(bnByte>>16);
388 bcb->CDB[2] = (unsigned char)(bnByte>>24);
389
390 result = ene_send_scsi_cmd(us, FDIR_READ, scsi_sglist(srb), 1);
391 return result;
392}
393
394static int sd_scsi_write(struct us_data *us, struct scsi_cmnd *srb)
395{
396 int result;
397 unsigned char *cdb = srb->cmnd;
398 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
399 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
400
401 u32 bn = ((cdb[2] << 24) & 0xff000000) | ((cdb[3] << 16) & 0x00ff0000) |
402 ((cdb[4] << 8) & 0x0000ff00) | ((cdb[5] << 0) & 0x000000ff);
403 u16 blen = ((cdb[7] << 8) & 0xff00) | ((cdb[8] << 0) & 0x00ff);
404 u32 bnByte = bn * 0x200;
405 u32 blenByte = blen * 0x200;
406
407 if (bn > info->bl_num)
408 return USB_STOR_TRANSPORT_ERROR;
409
410 result = ene_load_bincode(us, SD_RW_PATTERN);
411 if (result != USB_STOR_XFER_GOOD) {
412 US_DEBUGP("Load SD RW pattern Fail !!\n");
413 return USB_STOR_TRANSPORT_ERROR;
414 }
415
416 if (info->SD_Status.HiCapacity)
417 bnByte = bn;
418
419 /* set up the command wrapper */
420 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
421 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
422 bcb->DataTransferLength = blenByte;
423 bcb->Flags = 0x00;
424 bcb->CDB[0] = 0xF0;
425 bcb->CDB[5] = (unsigned char)(bnByte);
426 bcb->CDB[4] = (unsigned char)(bnByte>>8);
427 bcb->CDB[3] = (unsigned char)(bnByte>>16);
428 bcb->CDB[2] = (unsigned char)(bnByte>>24);
429
430 result = ene_send_scsi_cmd(us, FDIR_WRITE, scsi_sglist(srb), 1);
431 return result;
432}
433
434static int ene_get_card_type(struct us_data *us, u16 index, void *buf)
435{
436 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
437 int result;
438
439 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
440 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
441 bcb->DataTransferLength = 0x01;
442 bcb->Flags = 0x80;
443 bcb->CDB[0] = 0xED;
444 bcb->CDB[2] = (unsigned char)(index>>8);
445 bcb->CDB[3] = (unsigned char)index;
446
447 result = ene_send_scsi_cmd(us, FDIR_READ, buf, 0);
448 return result;
449}
450
451static int ene_get_card_status(struct us_data *us, u8 *buf)
452{
453 u16 tmpreg;
454 u32 reg4b;
455 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
456
457 /*US_DEBUGP("transport --- ENE_ReadSDReg\n");*/
458 reg4b = *(u32 *)&buf[0x18];
459 info->SD_READ_BL_LEN = (u8)((reg4b >> 8) & 0x0f);
460
461 tmpreg = (u16) reg4b;
462 reg4b = *(u32 *)(&buf[0x14]);
463 if (info->SD_Status.HiCapacity && !info->SD_Status.IsMMC)
464 info->HC_C_SIZE = (reg4b >> 8) & 0x3fffff;
465
466 info->SD_C_SIZE = ((tmpreg & 0x03) << 10) | (u16)(reg4b >> 22);
467 info->SD_C_SIZE_MULT = (u8)(reg4b >> 7) & 0x07;
468 if (info->SD_Status.HiCapacity && info->SD_Status.IsMMC)
469 info->HC_C_SIZE = *(u32 *)(&buf[0x100]);
470
471 if (info->SD_READ_BL_LEN > SD_BLOCK_LEN) {
472 info->SD_Block_Mult = 1 << (info->SD_READ_BL_LEN-SD_BLOCK_LEN);
473 info->SD_READ_BL_LEN = SD_BLOCK_LEN;
474 } else {
475 info->SD_Block_Mult = 1;
476 }
477
478 return USB_STOR_TRANSPORT_GOOD;
479}
480
481static int ene_load_bincode(struct us_data *us, unsigned char flag)
482{
483 int err;
484 char *fw_name = NULL;
485 unsigned char *buf = NULL;
486 const struct firmware *sd_fw = NULL;
487 int result = USB_STOR_TRANSPORT_ERROR;
488 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
489 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
490
491 if (info->BIN_FLAG == flag)
492 return USB_STOR_TRANSPORT_GOOD;
493
494 switch (flag) {
495 /* For SD */
496 case SD_INIT1_PATTERN:
497 US_DEBUGP("SD_INIT1_PATTERN\n");
498 fw_name = "ene-ub6250/sd_init1.bin";
499 break;
500 case SD_INIT2_PATTERN:
501 US_DEBUGP("SD_INIT2_PATTERN\n");
502 fw_name = "ene-ub6250/sd_init2.bin";
503 break;
504 case SD_RW_PATTERN:
505 US_DEBUGP("SD_RDWR_PATTERN\n");
506 fw_name = "ene-ub6250/sd_rdwr.bin";
507 break;
508 default:
509 US_DEBUGP("----------- Unknown PATTERN ----------\n");
510 goto nofw;
511 }
512
513 err = request_firmware(&sd_fw, fw_name, &us->pusb_dev->dev);
514 if (err) {
515 US_DEBUGP("load firmware %s failed\n", fw_name);
516 goto nofw;
517 }
518 buf = kmalloc(sd_fw->size, GFP_KERNEL);
519 if (buf == NULL) {
520 US_DEBUGP("Malloc memory for fireware failed!\n");
521 goto nofw;
522 }
523 memcpy(buf, sd_fw->data, sd_fw->size);
524 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
525 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
526 bcb->DataTransferLength = sd_fw->size;
527 bcb->Flags = 0x00;
528 bcb->CDB[0] = 0xEF;
529
530 result = ene_send_scsi_cmd(us, FDIR_WRITE, buf, 0);
531 info->BIN_FLAG = flag;
532 kfree(buf);
533
534nofw:
535 if (sd_fw != NULL) {
536 release_firmware(sd_fw);
537 sd_fw = NULL;
538 }
539
540 return result;
541}
542
543static int ene_sd_init(struct us_data *us)
544{
545 int result;
546 u8 buf[0x200];
547 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
548 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
549
550 US_DEBUGP("transport --- ENE_SDInit\n");
551 /* SD Init Part-1 */
552 result = ene_load_bincode(us, SD_INIT1_PATTERN);
553 if (result != USB_STOR_XFER_GOOD) {
554 US_DEBUGP("Load SD Init Code Part-1 Fail !!\n");
555 return USB_STOR_TRANSPORT_ERROR;
556 }
557
558 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
559 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
560 bcb->Flags = 0x80;
561 bcb->CDB[0] = 0xF2;
562
563 result = ene_send_scsi_cmd(us, FDIR_READ, NULL, 0);
564 if (result != USB_STOR_XFER_GOOD) {
565 US_DEBUGP("Execution SD Init Code Fail !!\n");
566 return USB_STOR_TRANSPORT_ERROR;
567 }
568
569 /* SD Init Part-2 */
570 result = ene_load_bincode(us, SD_INIT2_PATTERN);
571 if (result != USB_STOR_XFER_GOOD) {
572 US_DEBUGP("Load SD Init Code Part-2 Fail !!\n");
573 return USB_STOR_TRANSPORT_ERROR;
574 }
575
576 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
577 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
578 bcb->DataTransferLength = 0x200;
579 bcb->Flags = 0x80;
580 bcb->CDB[0] = 0xF1;
581
582 result = ene_send_scsi_cmd(us, FDIR_READ, &buf, 0);
583 if (result != USB_STOR_XFER_GOOD) {
584 US_DEBUGP("Execution SD Init Code Fail !!\n");
585 return USB_STOR_TRANSPORT_ERROR;
586 }
587
588 info->SD_Status = *(struct SD_STATUS *)&buf[0];
589 if (info->SD_Status.Insert && info->SD_Status.Ready) {
590 ene_get_card_status(us, (unsigned char *)&buf);
591 US_DEBUGP("Insert = %x\n", info->SD_Status.Insert);
592 US_DEBUGP("Ready = %x\n", info->SD_Status.Ready);
593 US_DEBUGP("IsMMC = %x\n", info->SD_Status.IsMMC);
594 US_DEBUGP("HiCapacity = %x\n", info->SD_Status.HiCapacity);
595 US_DEBUGP("HiSpeed = %x\n", info->SD_Status.HiSpeed);
596 US_DEBUGP("WtP = %x\n", info->SD_Status.WtP);
597 } else {
598 US_DEBUGP("SD Card Not Ready --- %x\n", buf[0]);
599 return USB_STOR_TRANSPORT_ERROR;
600 }
601 return USB_STOR_TRANSPORT_GOOD;
602}
603
604
605static int ene_init(struct us_data *us)
606{
607 int result;
608 u8 misc_reg03 = 0;
609 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra);
610
611 result = ene_get_card_type(us, REG_CARD_STATUS, &misc_reg03);
612 if (result != USB_STOR_XFER_GOOD)
613 return USB_STOR_TRANSPORT_ERROR;
614
615 if (misc_reg03 & 0x01) {
616 if (!info->SD_Status.Ready) {
617 result = ene_sd_init(us);
618 if (result != USB_STOR_XFER_GOOD)
619 return USB_STOR_TRANSPORT_ERROR;
620 }
621 }
622
623 return result;
624}
625
626/*----- sd_scsi_irp() ---------*/
627static int sd_scsi_irp(struct us_data *us, struct scsi_cmnd *srb)
628{
629 int result;
630 struct ene_ub6250_info *info = (struct ene_ub6250_info *)us->extra;
631
632 info->SrbStatus = SS_SUCCESS;
633 switch (srb->cmnd[0]) {
634 case TEST_UNIT_READY:
635 result = sd_scsi_test_unit_ready(us, srb);
636 break; /* 0x00 */
637 case INQUIRY:
638 result = sd_scsi_inquiry(us, srb);
639 break; /* 0x12 */
640 case MODE_SENSE:
641 result = sd_scsi_mode_sense(us, srb);
642 break; /* 0x1A */
643 /*
644 case START_STOP:
645 result = SD_SCSI_Start_Stop(us, srb);
646 break; //0x1B
647 */
648 case READ_CAPACITY:
649 result = sd_scsi_read_capacity(us, srb);
650 break; /* 0x25 */
651 case READ_10:
652 result = sd_scsi_read(us, srb);
653 break; /* 0x28 */
654 case WRITE_10:
655 result = sd_scsi_write(us, srb);
656 break; /* 0x2A */
657 default:
658 info->SrbStatus = SS_ILLEGAL_REQUEST;
659 result = USB_STOR_TRANSPORT_FAILED;
660 break;
661 }
662 return result;
663}
664
665static int ene_transport(struct scsi_cmnd *srb, struct us_data *us)
666{
667 int result = 0;
668 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra);
669
670 /*US_DEBUG(usb_stor_show_command(srb)); */
671 scsi_set_resid(srb, 0);
672 if (unlikely(!info->SD_Status.Ready))
673 result = ene_init(us);
674 else
675 result = sd_scsi_irp(us, srb);
676
677 return 0;
678}
679
680
681static int ene_ub6250_probe(struct usb_interface *intf,
682 const struct usb_device_id *id)
683{
684 int result;
685 u8 misc_reg03 = 0;
686 struct us_data *us;
687
688 result = usb_stor_probe1(&us, intf, id,
689 (id - ene_ub6250_usb_ids) + ene_ub6250_unusual_dev_list);
690 if (result)
691 return result;
692
693 /* FIXME: where should the code alloc extra buf ? */
694 if (!us->extra) {
695 us->extra = kzalloc(sizeof(struct ene_ub6250_info), GFP_KERNEL);
696 if (!us->extra)
697 return -ENOMEM;
698 us->extra_destructor = ene_ub6250_info_destructor;
699 }
700
701 us->transport_name = "ene_ub6250";
702 us->transport = ene_transport;
703 us->max_lun = 0;
704
705 result = usb_stor_probe2(us);
706 if (result)
707 return result;
708
709 /* probe card type */
710 result = ene_get_card_type(us, REG_CARD_STATUS, &misc_reg03);
711 if (result != USB_STOR_XFER_GOOD) {
712 usb_stor_disconnect(intf);
713 return USB_STOR_TRANSPORT_ERROR;
714 }
715
716 if (!(misc_reg03 & 0x01)) {
717 result = -ENODEV;
718 printk(KERN_NOTICE "ums_eneub6250: The driver only supports SD card. "
719 "To use SM/MS card, please build driver/staging/keucr\n");
720 usb_stor_disconnect(intf);
721 }
722
723 return result;
724}
725
726
727#ifdef CONFIG_PM
728
729static int ene_ub6250_resume(struct usb_interface *iface)
730{
731 u8 tmp = 0;
732 struct us_data *us = usb_get_intfdata(iface);
733 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra);
734
735 mutex_lock(&us->dev_mutex);
736
737 US_DEBUGP("%s\n", __func__);
738 if (us->suspend_resume_hook)
739 (us->suspend_resume_hook)(us, US_RESUME);
740
741 mutex_unlock(&us->dev_mutex);
742
743 info->Power_IsResum = true;
744 /*info->SD_Status.Ready = 0; */
745 info->SD_Status = *(struct SD_STATUS *)&tmp;
746 info->MS_Status = *(struct MS_STATUS *)&tmp;
747 info->SM_Status = *(struct SM_STATUS *)&tmp;
748
749 return 0;
750}
751
752static int ene_ub6250_reset_resume(struct usb_interface *iface)
753{
754 u8 tmp = 0;
755 struct us_data *us = usb_get_intfdata(iface);
756 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra);
757 US_DEBUGP("%s\n", __func__);
758 /* Report the reset to the SCSI core */
759 usb_stor_reset_resume(iface);
760
761 /* FIXME: Notify the subdrivers that they need to reinitialize
762 * the device */
763 info->Power_IsResum = true;
764 /*info->SD_Status.Ready = 0; */
765 info->SD_Status = *(struct SD_STATUS *)&tmp;
766 info->MS_Status = *(struct MS_STATUS *)&tmp;
767 info->SM_Status = *(struct SM_STATUS *)&tmp;
768
769 return 0;
770}
771
772#else
773
774#define ene_ub6250_resume NULL
775#define ene_ub6250_reset_resume NULL
776
777#endif
778
779static struct usb_driver ene_ub6250_driver = {
780 .name = "ums_eneub6250",
781 .probe = ene_ub6250_probe,
782 .disconnect = usb_stor_disconnect,
783 .suspend = usb_stor_suspend,
784 .resume = ene_ub6250_resume,
785 .reset_resume = ene_ub6250_reset_resume,
786 .pre_reset = usb_stor_pre_reset,
787 .post_reset = usb_stor_post_reset,
788 .id_table = ene_ub6250_usb_ids,
789 .soft_unbind = 1,
790};
791
792static int __init ene_ub6250_init(void)
793{
794 return usb_register(&ene_ub6250_driver);
795}
796
797static void __exit ene_ub6250_exit(void)
798{
799 usb_deregister(&ene_ub6250_driver);
800}
801
802module_init(ene_ub6250_init);
803module_exit(ene_ub6250_exit);
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index 6b9982cd5423..ffc4193e9505 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -499,7 +499,6 @@ static int isd200_action( struct us_data *us, int action,
499 memset(&ata, 0, sizeof(ata)); 499 memset(&ata, 0, sizeof(ata));
500 srb->cmnd = info->cmnd; 500 srb->cmnd = info->cmnd;
501 srb->device = &srb_dev; 501 srb->device = &srb_dev;
502 ++srb->serial_number;
503 502
504 ata.generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; 503 ata.generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
505 ata.generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; 504 ata.generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
@@ -1510,7 +1509,7 @@ static int isd200_Initialization(struct us_data *us)
1510 * Protocol and Transport for the ISD200 ASIC 1509 * Protocol and Transport for the ISD200 ASIC
1511 * 1510 *
1512 * This protocol and transport are for ATA devices connected to an ISD200 1511 * This protocol and transport are for ATA devices connected to an ISD200
1513 * ASIC. An ATAPI device that is conected as a slave device will be 1512 * ASIC. An ATAPI device that is connected as a slave device will be
1514 * detected in the driver initialization function and the protocol will 1513 * detected in the driver initialization function and the protocol will
1515 * be changed to an ATAPI protocol (Transparent SCSI). 1514 * be changed to an ATAPI protocol (Transparent SCSI).
1516 * 1515 *
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
new file mode 100644
index 000000000000..d509a4a7d74f
--- /dev/null
+++ b/drivers/usb/storage/realtek_cr.c
@@ -0,0 +1,675 @@
1/* Driver for Realtek RTS51xx USB card reader
2 *
3 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
8 * later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 * wwang (wei_wang@realsil.com.cn)
20 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
21 */
22
23#include <linux/module.h>
24#include <linux/blkdev.h>
25#include <linux/kthread.h>
26#include <linux/sched.h>
27#include <linux/workqueue.h>
28#include <linux/kernel.h>
29#include <linux/version.h>
30
31#include <scsi/scsi.h>
32#include <scsi/scsi_cmnd.h>
33#include <scsi/scsi_device.h>
34#include <linux/cdrom.h>
35
36#include <linux/usb.h>
37#include <linux/slab.h>
38#include <linux/usb_usual.h>
39
40#include "usb.h"
41#include "transport.h"
42#include "protocol.h"
43#include "debug.h"
44
45MODULE_DESCRIPTION("Driver for Realtek USB Card Reader");
46MODULE_AUTHOR("wwang <wei_wang@realsil.com.cn>");
47MODULE_LICENSE("GPL");
48MODULE_VERSION("1.03");
49
50static int auto_delink_en = 1;
51module_param(auto_delink_en, int, S_IRUGO | S_IWUSR);
52MODULE_PARM_DESC(auto_delink_en, "enable auto delink");
53
54struct rts51x_status {
55 u16 vid;
56 u16 pid;
57 u8 cur_lun;
58 u8 card_type;
59 u8 total_lun;
60 u16 fw_ver;
61 u8 phy_exist;
62 u8 multi_flag;
63 u8 multi_card;
64 u8 log_exist;
65 union {
66 u8 detailed_type1;
67 u8 detailed_type2;
68 } detailed_type;
69 u8 function[2];
70};
71
72struct rts51x_chip {
73 u16 vendor_id;
74 u16 product_id;
75 char max_lun;
76
77 struct rts51x_status *status;
78 int status_len;
79
80 u32 flag;
81};
82
83/* flag definition */
84#define FLIDX_AUTO_DELINK 0x01
85
86#define SCSI_LUN(srb) ((srb)->device->lun)
87
88/* Bit Operation */
89#define SET_BIT(data, idx) ((data) |= 1 << (idx))
90#define CLR_BIT(data, idx) ((data) &= ~(1 << (idx)))
91#define CHK_BIT(data, idx) ((data) & (1 << (idx)))
92
93#define SET_AUTO_DELINK(chip) ((chip)->flag |= FLIDX_AUTO_DELINK)
94#define CLR_AUTO_DELINK(chip) ((chip)->flag &= ~FLIDX_AUTO_DELINK)
95#define CHK_AUTO_DELINK(chip) ((chip)->flag & FLIDX_AUTO_DELINK)
96
97#define RTS51X_GET_VID(chip) ((chip)->vendor_id)
98#define RTS51X_GET_PID(chip) ((chip)->product_id)
99
100#define FW_VERSION(chip) ((chip)->status[0].fw_ver)
101#define STATUS_LEN(chip) ((chip)->status_len)
102
103/* Check card reader function */
104#define SUPPORT_DETAILED_TYPE1(chip) \
105 CHK_BIT((chip)->status[0].function[0], 1)
106#define SUPPORT_OT(chip) \
107 CHK_BIT((chip)->status[0].function[0], 2)
108#define SUPPORT_OC(chip) \
109 CHK_BIT((chip)->status[0].function[0], 3)
110#define SUPPORT_AUTO_DELINK(chip) \
111 CHK_BIT((chip)->status[0].function[0], 4)
112#define SUPPORT_SDIO(chip) \
113 CHK_BIT((chip)->status[0].function[1], 0)
114#define SUPPORT_DETAILED_TYPE2(chip) \
115 CHK_BIT((chip)->status[0].function[1], 1)
116
117#define CHECK_PID(chip, pid) (RTS51X_GET_PID(chip) == (pid))
118#define CHECK_FW_VER(chip, fw_ver) (FW_VERSION(chip) == (fw_ver))
119#define CHECK_ID(chip, pid, fw_ver) \
120 (CHECK_PID((chip), (pid)) && CHECK_FW_VER((chip), (fw_ver)))
121
122#define wait_timeout_x(task_state, msecs) \
123do { \
124 set_current_state((task_state)); \
125 schedule_timeout((msecs) * HZ / 1000); \
126} while (0)
127
128#define wait_timeout(msecs) \
129 wait_timeout_x(TASK_INTERRUPTIBLE, (msecs))
130
131static int init_realtek_cr(struct us_data *us);
132
133/*
134 * The table of devices
135 */
136#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
137 vendorName, productName, useProtocol, useTransport, \
138 initFunction, flags) \
139{\
140 USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
141 .driver_info = (flags)|(USB_US_TYPE_STOR<<24)\
142}
143
144static const struct usb_device_id realtek_cr_ids[] = {
145# include "unusual_realtek.h"
146 { } /* Terminating entry */
147};
148MODULE_DEVICE_TABLE(usb, realtek_cr_ids);
149
150#undef UNUSUAL_DEV
151
152/*
153 * The flags table
154 */
155#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
156 vendor_name, product_name, use_protocol, use_transport, \
157 init_function, Flags) \
158{ \
159 .vendorName = vendor_name, \
160 .productName = product_name, \
161 .useProtocol = use_protocol, \
162 .useTransport = use_transport, \
163 .initFunction = init_function, \
164}
165
166static struct us_unusual_dev realtek_cr_unusual_dev_list[] = {
167# include "unusual_realtek.h"
168 { } /* Terminating entry */
169};
170
171#undef UNUSUAL_DEV
172
173static int rts51x_bulk_transport(struct us_data *us, u8 lun,
174 u8 *cmd, int cmd_len, u8 *buf, int buf_len,
175 enum dma_data_direction dir, int *act_len)
176{
177 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
178 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
179 int result;
180 unsigned int residue;
181 unsigned int cswlen;
182 unsigned int cbwlen = US_BULK_CB_WRAP_LEN;
183
184 /* set up the command wrapper */
185 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
186 bcb->DataTransferLength = cpu_to_le32(buf_len);
187 bcb->Flags = (dir == DMA_FROM_DEVICE) ? 1 << 7 : 0;
188 bcb->Tag = ++us->tag;
189 bcb->Lun = lun;
190 bcb->Length = cmd_len;
191
192 /* copy the command payload */
193 memset(bcb->CDB, 0, sizeof(bcb->CDB));
194 memcpy(bcb->CDB, cmd, bcb->Length);
195
196 /* send it to out endpoint */
197 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
198 bcb, cbwlen, NULL);
199 if (result != USB_STOR_XFER_GOOD)
200 return USB_STOR_TRANSPORT_ERROR;
201
202 /* DATA STAGE */
203 /* send/receive data payload, if there is any */
204
205 if (buf && buf_len) {
206 unsigned int pipe = (dir == DMA_FROM_DEVICE) ?
207 us->recv_bulk_pipe : us->send_bulk_pipe;
208 result = usb_stor_bulk_transfer_buf(us, pipe,
209 buf, buf_len, NULL);
210 if (result == USB_STOR_XFER_ERROR)
211 return USB_STOR_TRANSPORT_ERROR;
212 }
213
214 /* get CSW for device status */
215 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
216 bcs, US_BULK_CS_WRAP_LEN, &cswlen);
217 if (result != USB_STOR_XFER_GOOD)
218 return USB_STOR_TRANSPORT_ERROR;
219
220 /* check bulk status */
221 if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN)) {
222 US_DEBUGP("Signature mismatch: got %08X, expecting %08X\n",
223 le32_to_cpu(bcs->Signature),
224 US_BULK_CS_SIGN);
225 return USB_STOR_TRANSPORT_ERROR;
226 }
227
228 residue = bcs->Residue;
229 if (bcs->Tag != us->tag)
230 return USB_STOR_TRANSPORT_ERROR;
231
232 /* try to compute the actual residue, based on how much data
233 * was really transferred and what the device tells us */
234 if (residue)
235 residue = residue < buf_len ? residue : buf_len;
236
237 if (act_len)
238 *act_len = buf_len - residue;
239
240 /* based on the status code, we report good or bad */
241 switch (bcs->Status) {
242 case US_BULK_STAT_OK:
243 /* command good -- note that data could be short */
244 return USB_STOR_TRANSPORT_GOOD;
245
246 case US_BULK_STAT_FAIL:
247 /* command failed */
248 return USB_STOR_TRANSPORT_FAILED;
249
250 case US_BULK_STAT_PHASE:
251 /* phase error -- note that a transport reset will be
252 * invoked by the invoke_transport() function
253 */
254 return USB_STOR_TRANSPORT_ERROR;
255 }
256
257 /* we should never get here, but if we do, we're in trouble */
258 return USB_STOR_TRANSPORT_ERROR;
259}
260
261/* Determine what the maximum LUN supported is */
262static int rts51x_get_max_lun(struct us_data *us)
263{
264 int result;
265
266 /* issue the command */
267 us->iobuf[0] = 0;
268 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
269 US_BULK_GET_MAX_LUN,
270 USB_DIR_IN | USB_TYPE_CLASS |
271 USB_RECIP_INTERFACE,
272 0, us->ifnum, us->iobuf, 1, 10*HZ);
273
274 US_DEBUGP("GetMaxLUN command result is %d, data is %d\n",
275 result, us->iobuf[0]);
276
277 /* if we have a successful request, return the result */
278 if (result > 0)
279 return us->iobuf[0];
280
281 return 0;
282}
283
284static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
285{
286 int retval;
287 u8 cmnd[12] = {0};
288
289 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
290
291 cmnd[0] = 0xF0;
292 cmnd[1] = 0x0D;
293 cmnd[2] = (u8)(addr >> 8);
294 cmnd[3] = (u8)addr;
295 cmnd[4] = (u8)(len >> 8);
296 cmnd[5] = (u8)len;
297
298 retval = rts51x_bulk_transport(us, 0, cmnd, 12,
299 data, len, DMA_FROM_DEVICE, NULL);
300 if (retval != USB_STOR_TRANSPORT_GOOD)
301 return -EIO;
302
303 return 0;
304}
305
306static int rts51x_write_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
307{
308 int retval;
309 u8 cmnd[12] = {0};
310
311 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
312
313 cmnd[0] = 0xF0;
314 cmnd[1] = 0x0E;
315 cmnd[2] = (u8)(addr >> 8);
316 cmnd[3] = (u8)addr;
317 cmnd[4] = (u8)(len >> 8);
318 cmnd[5] = (u8)len;
319
320 retval = rts51x_bulk_transport(us, 0, cmnd, 12,
321 data, len, DMA_TO_DEVICE, NULL);
322 if (retval != USB_STOR_TRANSPORT_GOOD)
323 return -EIO;
324
325 return 0;
326}
327
328static int rts51x_read_status(struct us_data *us,
329 u8 lun, u8 *status, int len, int *actlen)
330{
331 int retval;
332 u8 cmnd[12] = {0};
333
334 US_DEBUGP("%s, lun = %d\n", __func__, lun);
335
336 cmnd[0] = 0xF0;
337 cmnd[1] = 0x09;
338
339 retval = rts51x_bulk_transport(us, lun, cmnd, 12,
340 status, len, DMA_FROM_DEVICE, actlen);
341 if (retval != USB_STOR_TRANSPORT_GOOD)
342 return -EIO;
343
344 return 0;
345}
346
347static int rts51x_check_status(struct us_data *us, u8 lun)
348{
349 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
350 int retval;
351 u8 buf[16];
352
353 retval = rts51x_read_status(us, lun, buf, 16, &(chip->status_len));
354 if (retval < 0)
355 return -EIO;
356
357 US_DEBUGP("chip->status_len = %d\n", chip->status_len);
358
359 chip->status[lun].vid = ((u16)buf[0] << 8) | buf[1];
360 chip->status[lun].pid = ((u16)buf[2] << 8) | buf[3];
361 chip->status[lun].cur_lun = buf[4];
362 chip->status[lun].card_type = buf[5];
363 chip->status[lun].total_lun = buf[6];
364 chip->status[lun].fw_ver = ((u16)buf[7] << 8) | buf[8];
365 chip->status[lun].phy_exist = buf[9];
366 chip->status[lun].multi_flag = buf[10];
367 chip->status[lun].multi_card = buf[11];
368 chip->status[lun].log_exist = buf[12];
369 if (chip->status_len == 16) {
370 chip->status[lun].detailed_type.detailed_type1 = buf[13];
371 chip->status[lun].function[0] = buf[14];
372 chip->status[lun].function[1] = buf[15];
373 }
374
375 return 0;
376}
377
378static int enable_oscillator(struct us_data *us)
379{
380 int retval;
381 u8 value;
382
383 retval = rts51x_read_mem(us, 0xFE77, &value, 1);
384 if (retval < 0)
385 return -EIO;
386
387 value |= 0x04;
388 retval = rts51x_write_mem(us, 0xFE77, &value, 1);
389 if (retval < 0)
390 return -EIO;
391
392 retval = rts51x_read_mem(us, 0xFE77, &value, 1);
393 if (retval < 0)
394 return -EIO;
395
396 if (!(value & 0x04))
397 return -EIO;
398
399 return 0;
400}
401
402static int do_config_autodelink(struct us_data *us, int enable, int force)
403{
404 int retval;
405 u8 value;
406
407 retval = rts51x_read_mem(us, 0xFE47, &value, 1);
408 if (retval < 0)
409 return -EIO;
410
411 if (enable) {
412 if (force)
413 value |= 0x03;
414 else
415 value |= 0x01;
416 } else {
417 value &= ~0x03;
418 }
419
420 US_DEBUGP("In %s,set 0xfe47 to 0x%x\n", __func__, value);
421
422 retval = rts51x_write_mem(us, 0xFE47, &value, 1);
423 if (retval < 0)
424 return -EIO;
425
426 return 0;
427}
428
429static int config_autodelink_after_power_on(struct us_data *us)
430{
431 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
432 int retval;
433 u8 value;
434
435 if (!CHK_AUTO_DELINK(chip))
436 return 0;
437
438 retval = rts51x_read_mem(us, 0xFE47, &value, 1);
439 if (retval < 0)
440 return -EIO;
441
442 if (auto_delink_en) {
443 CLR_BIT(value, 0);
444 CLR_BIT(value, 1);
445 SET_BIT(value, 2);
446
447 if (CHECK_ID(chip, 0x0138, 0x3882))
448 CLR_BIT(value, 2);
449
450 SET_BIT(value, 7);
451
452 retval = rts51x_write_mem(us, 0xFE47, &value, 1);
453 if (retval < 0)
454 return -EIO;
455
456 retval = enable_oscillator(us);
457 if (retval == 0)
458 (void)do_config_autodelink(us, 1, 0);
459 } else {
460 /* Autodelink controlled by firmware */
461
462 SET_BIT(value, 2);
463
464 if (CHECK_ID(chip, 0x0138, 0x3882))
465 CLR_BIT(value, 2);
466
467 if (CHECK_ID(chip, 0x0159, 0x5889) ||
468 CHECK_ID(chip, 0x0138, 0x3880)) {
469 CLR_BIT(value, 0);
470 CLR_BIT(value, 7);
471 }
472
473 retval = rts51x_write_mem(us, 0xFE47, &value, 1);
474 if (retval < 0)
475 return -EIO;
476
477 if (CHECK_ID(chip, 0x0159, 0x5888)) {
478 value = 0xFF;
479 retval = rts51x_write_mem(us, 0xFE79, &value, 1);
480 if (retval < 0)
481 return -EIO;
482
483 value = 0x01;
484 retval = rts51x_write_mem(us, 0x48, &value, 1);
485 if (retval < 0)
486 return -EIO;
487 }
488 }
489
490 return 0;
491}
492
493static int config_autodelink_before_power_down(struct us_data *us)
494{
495 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
496 int retval;
497 u8 value;
498
499 if (!CHK_AUTO_DELINK(chip))
500 return 0;
501
502 if (auto_delink_en) {
503 retval = rts51x_read_mem(us, 0xFE77, &value, 1);
504 if (retval < 0)
505 return -EIO;
506
507 SET_BIT(value, 2);
508 retval = rts51x_write_mem(us, 0xFE77, &value, 1);
509 if (retval < 0)
510 return -EIO;
511
512 if (CHECK_ID(chip, 0x0159, 0x5888)) {
513 value = 0x01;
514 retval = rts51x_write_mem(us, 0x48, &value, 1);
515 if (retval < 0)
516 return -EIO;
517 }
518
519 retval = rts51x_read_mem(us, 0xFE47, &value, 1);
520 if (retval < 0)
521 return -EIO;
522
523 SET_BIT(value, 0);
524 if (CHECK_ID(chip, 0x0138, 0x3882))
525 SET_BIT(value, 2);
526 retval = rts51x_write_mem(us, 0xFE77, &value, 1);
527 if (retval < 0)
528 return -EIO;
529 } else {
530 if (CHECK_ID(chip, 0x0159, 0x5889) ||
531 CHECK_ID(chip, 0x0138, 0x3880) ||
532 CHECK_ID(chip, 0x0138, 0x3882)) {
533 retval = rts51x_read_mem(us, 0xFE47, &value, 1);
534 if (retval < 0)
535 return -EIO;
536
537 if (CHECK_ID(chip, 0x0159, 0x5889) ||
538 CHECK_ID(chip, 0x0138, 0x3880)) {
539 SET_BIT(value, 0);
540 SET_BIT(value, 7);
541 }
542
543 if (CHECK_ID(chip, 0x0138, 0x3882))
544 SET_BIT(value, 2);
545
546 retval = rts51x_write_mem(us, 0xFE47, &value, 1);
547 if (retval < 0)
548 return -EIO;
549 }
550
551 if (CHECK_ID(chip, 0x0159, 0x5888)) {
552 value = 0x01;
553 retval = rts51x_write_mem(us, 0x48, &value, 1);
554 if (retval < 0)
555 return -EIO;
556 }
557 }
558
559 return 0;
560}
561
562static void realtek_cr_destructor(void *extra)
563{
564 struct rts51x_chip *chip = (struct rts51x_chip *)extra;
565
566 if (!chip)
567 return;
568
569 kfree(chip->status);
570}
571
572#ifdef CONFIG_PM
573static void realtek_pm_hook(struct us_data *us, int pm_state)
574{
575 if (pm_state == US_SUSPEND)
576 (void)config_autodelink_before_power_down(us);
577}
578#endif
579
580static int init_realtek_cr(struct us_data *us)
581{
582 struct rts51x_chip *chip;
583 int size, i, retval;
584
585 chip = kzalloc(sizeof(struct rts51x_chip), GFP_KERNEL);
586 if (!chip)
587 return -ENOMEM;
588
589 us->extra = chip;
590 us->extra_destructor = realtek_cr_destructor;
591#ifdef CONFIG_PM
592 us->suspend_resume_hook = realtek_pm_hook;
593#endif
594
595 us->max_lun = chip->max_lun = rts51x_get_max_lun(us);
596
597 US_DEBUGP("chip->max_lun = %d\n", chip->max_lun);
598
599 size = (chip->max_lun + 1) * sizeof(struct rts51x_status);
600 chip->status = kzalloc(size, GFP_KERNEL);
601 if (!chip->status)
602 goto INIT_FAIL;
603
604 for (i = 0; i <= (int)(chip->max_lun); i++) {
605 retval = rts51x_check_status(us, (u8)i);
606 if (retval < 0)
607 goto INIT_FAIL;
608 }
609
610 if (CHECK_FW_VER(chip, 0x5888) || CHECK_FW_VER(chip, 0x5889) ||
611 CHECK_FW_VER(chip, 0x5901))
612 SET_AUTO_DELINK(chip);
613 if (STATUS_LEN(chip) == 16) {
614 if (SUPPORT_AUTO_DELINK(chip))
615 SET_AUTO_DELINK(chip);
616 }
617
618 US_DEBUGP("chip->flag = 0x%x\n", chip->flag);
619
620 (void)config_autodelink_after_power_on(us);
621
622 return 0;
623
624INIT_FAIL:
625 if (us->extra) {
626 kfree(chip->status);
627 kfree(us->extra);
628 us->extra = NULL;
629 }
630
631 return -EIO;
632}
633
634static int realtek_cr_probe(struct usb_interface *intf,
635 const struct usb_device_id *id)
636{
637 struct us_data *us;
638 int result;
639
640 US_DEBUGP("Probe Realtek Card Reader!\n");
641
642 result = usb_stor_probe1(&us, intf, id,
643 (id - realtek_cr_ids) + realtek_cr_unusual_dev_list);
644 if (result)
645 return result;
646
647 result = usb_stor_probe2(us);
648 return result;
649}
650
651static struct usb_driver realtek_cr_driver = {
652 .name = "ums-realtek",
653 .probe = realtek_cr_probe,
654 .disconnect = usb_stor_disconnect,
655 .suspend = usb_stor_suspend,
656 .resume = usb_stor_resume,
657 .reset_resume = usb_stor_reset_resume,
658 .pre_reset = usb_stor_pre_reset,
659 .post_reset = usb_stor_post_reset,
660 .id_table = realtek_cr_ids,
661 .soft_unbind = 1,
662};
663
664static int __init realtek_cr_init(void)
665{
666 return usb_register(&realtek_cr_driver);
667}
668
669static void __exit realtek_cr_exit(void)
670{
671 usb_deregister(&realtek_cr_driver);
672}
673
674module_init(realtek_cr_init);
675module_exit(realtek_cr_exit);
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index d8d98cfecada..13b8bcdf3dba 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -113,7 +113,7 @@ static int slave_alloc (struct scsi_device *sdev)
113 * Let the scanning code know if this target merely sets 113 * Let the scanning code know if this target merely sets
114 * Peripheral Device Type to 0x1f to indicate no LUN. 114 * Peripheral Device Type to 0x1f to indicate no LUN.
115 */ 115 */
116 if (us->subclass == US_SC_UFI) 116 if (us->subclass == USB_SC_UFI)
117 sdev->sdev_target->pdt_1f_for_no_lun = 1; 117 sdev->sdev_target->pdt_1f_for_no_lun = 1;
118 118
119 return 0; 119 return 0;
@@ -123,7 +123,7 @@ static int slave_configure(struct scsi_device *sdev)
123{ 123{
124 struct us_data *us = host_to_us(sdev->host); 124 struct us_data *us = host_to_us(sdev->host);
125 125
126 /* Many devices have trouble transfering more than 32KB at a time, 126 /* Many devices have trouble transferring more than 32KB at a time,
127 * while others have trouble with more than 64K. At this time we 127 * while others have trouble with more than 64K. At this time we
128 * are limiting both to 32K (64 sectores). 128 * are limiting both to 32K (64 sectores).
129 */ 129 */
@@ -176,7 +176,7 @@ static int slave_configure(struct scsi_device *sdev)
176 /* Disk-type devices use MODE SENSE(6) if the protocol 176 /* Disk-type devices use MODE SENSE(6) if the protocol
177 * (SubClass) is Transparent SCSI, otherwise they use 177 * (SubClass) is Transparent SCSI, otherwise they use
178 * MODE SENSE(10). */ 178 * MODE SENSE(10). */
179 if (us->subclass != US_SC_SCSI && us->subclass != US_SC_CYP_ATACB) 179 if (us->subclass != USB_SC_SCSI && us->subclass != USB_SC_CYP_ATACB)
180 sdev->use_10_for_ms = 1; 180 sdev->use_10_for_ms = 1;
181 181
182 /* Many disks only accept MODE SENSE transfer lengths of 182 /* Many disks only accept MODE SENSE transfer lengths of
@@ -209,6 +209,10 @@ static int slave_configure(struct scsi_device *sdev)
209 if (us->fflags & US_FL_CAPACITY_HEURISTICS) 209 if (us->fflags & US_FL_CAPACITY_HEURISTICS)
210 sdev->guess_capacity = 1; 210 sdev->guess_capacity = 1;
211 211
212 /* Some devices cannot handle READ_CAPACITY_16 */
213 if (us->fflags & US_FL_NO_READ_CAPACITY_16)
214 sdev->no_read_capacity_16 = 1;
215
212 /* assume SPC3 or latter devices support sense size > 18 */ 216 /* assume SPC3 or latter devices support sense size > 18 */
213 if (sdev->scsi_level > SCSI_SPC_2) 217 if (sdev->scsi_level > SCSI_SPC_2)
214 us->fflags |= US_FL_SANE_SENSE; 218 us->fflags |= US_FL_SANE_SENSE;
@@ -245,7 +249,7 @@ static int slave_configure(struct scsi_device *sdev)
245 * capacity will be decremented or is correct. */ 249 * capacity will be decremented or is correct. */
246 if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK | 250 if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK |
247 US_FL_SCM_MULT_TARG)) && 251 US_FL_SCM_MULT_TARG)) &&
248 us->protocol == US_PR_BULK) 252 us->protocol == USB_PR_BULK)
249 us->use_last_sector_hacks = 1; 253 us->use_last_sector_hacks = 1;
250 } else { 254 } else {
251 255
@@ -253,6 +257,10 @@ static int slave_configure(struct scsi_device *sdev)
253 * or to force 192-byte transfer lengths for MODE SENSE. 257 * or to force 192-byte transfer lengths for MODE SENSE.
254 * But they do need to use MODE SENSE(10). */ 258 * But they do need to use MODE SENSE(10). */
255 sdev->use_10_for_ms = 1; 259 sdev->use_10_for_ms = 1;
260
261 /* Some (fake) usb cdrom devices don't like READ_DISC_INFO */
262 if (us->fflags & US_FL_NO_READ_DISC_INFO)
263 sdev->no_read_disc_info = 1;
256 } 264 }
257 265
258 /* The CB and CBI transports have no way to pass LUN values 266 /* The CB and CBI transports have no way to pass LUN values
@@ -261,7 +269,7 @@ static int slave_configure(struct scsi_device *sdev)
261 * scsi_level == 0 (UNKNOWN). Hence such devices must necessarily 269 * scsi_level == 0 (UNKNOWN). Hence such devices must necessarily
262 * be single-LUN. 270 * be single-LUN.
263 */ 271 */
264 if ((us->protocol == US_PR_CB || us->protocol == US_PR_CBI) && 272 if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_CBI) &&
265 sdev->scsi_level == SCSI_UNKNOWN) 273 sdev->scsi_level == SCSI_UNKNOWN)
266 us->max_lun = 0; 274 us->max_lun = 0;
267 275
@@ -277,7 +285,7 @@ static int slave_configure(struct scsi_device *sdev)
277 285
278/* queue a command */ 286/* queue a command */
279/* This is always called with scsi_lock(host) held */ 287/* This is always called with scsi_lock(host) held */
280static int queuecommand(struct scsi_cmnd *srb, 288static int queuecommand_lck(struct scsi_cmnd *srb,
281 void (*done)(struct scsi_cmnd *)) 289 void (*done)(struct scsi_cmnd *))
282{ 290{
283 struct us_data *us = host_to_us(srb->device->host); 291 struct us_data *us = host_to_us(srb->device->host);
@@ -307,6 +315,8 @@ static int queuecommand(struct scsi_cmnd *srb,
307 return 0; 315 return 0;
308} 316}
309 317
318static DEF_SCSI_QCMD(queuecommand)
319
310/*********************************************************************** 320/***********************************************************************
311 * Error handling functions 321 * Error handling functions
312 ***********************************************************************/ 322 ***********************************************************************/
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c
index ab5f9f37575a..bcb9a709d349 100644
--- a/drivers/usb/storage/sddr09.c
+++ b/drivers/usb/storage/sddr09.c
@@ -1760,7 +1760,7 @@ static int sddr09_probe(struct usb_interface *intf,
1760 if (result) 1760 if (result)
1761 return result; 1761 return result;
1762 1762
1763 if (us->protocol == US_PR_DPCM_USB) { 1763 if (us->protocol == USB_PR_DPCM_USB) {
1764 us->transport_name = "Control/Bulk-EUSB/SDDR09"; 1764 us->transport_name = "Control/Bulk-EUSB/SDDR09";
1765 us->transport = dpcm_transport; 1765 us->transport = dpcm_transport;
1766 us->transport_reset = usb_stor_CB_reset; 1766 us->transport_reset = usb_stor_CB_reset;
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index bd3f415893d8..0b00091d2ae9 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -340,7 +340,7 @@ static int usbat_check_status(struct us_data *us)
340} 340}
341 341
342/* 342/*
343 * Stores critical information in internal registers in prepartion for the execution 343 * Stores critical information in internal registers in preparation for the execution
344 * of a conditional usbat_read_blocks or usbat_write_blocks call. 344 * of a conditional usbat_read_blocks or usbat_write_blocks call.
345 */ 345 */
346static int usbat_set_shuttle_features(struct us_data *us, 346static int usbat_set_shuttle_features(struct us_data *us,
diff --git a/drivers/usb/storage/sierra_ms.c b/drivers/usb/storage/sierra_ms.c
index 57fc2f532cab..1deca07c8265 100644
--- a/drivers/usb/storage/sierra_ms.c
+++ b/drivers/usb/storage/sierra_ms.c
@@ -121,18 +121,16 @@ static ssize_t show_truinst(struct device *dev, struct device_attribute *attr,
121 } 121 }
122 return result; 122 return result;
123} 123}
124static DEVICE_ATTR(truinst, S_IWUGO | S_IRUGO, show_truinst, NULL); 124static DEVICE_ATTR(truinst, S_IRUGO, show_truinst, NULL);
125 125
126int sierra_ms_init(struct us_data *us) 126int sierra_ms_init(struct us_data *us)
127{ 127{
128 int result, retries; 128 int result, retries;
129 signed long delay_t;
130 struct swoc_info *swocInfo; 129 struct swoc_info *swocInfo;
131 struct usb_device *udev; 130 struct usb_device *udev;
132 struct Scsi_Host *sh; 131 struct Scsi_Host *sh;
133 struct scsi_device *sd; 132 struct scsi_device *sd;
134 133
135 delay_t = 2;
136 retries = 3; 134 retries = 3;
137 result = 0; 135 result = 0;
138 udev = us->pusb_dev; 136 udev = us->pusb_dev;
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 64ec073e89de..e8ae21b2d387 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -642,7 +642,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
642 * unless the operation involved a data-in transfer. Devices 642 * unless the operation involved a data-in transfer. Devices
643 * can signal most data-in errors by stalling the bulk-in pipe. 643 * can signal most data-in errors by stalling the bulk-in pipe.
644 */ 644 */
645 if ((us->protocol == US_PR_CB || us->protocol == US_PR_DPCM_USB) && 645 if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_DPCM_USB) &&
646 srb->sc_data_direction != DMA_FROM_DEVICE) { 646 srb->sc_data_direction != DMA_FROM_DEVICE) {
647 US_DEBUGP("-- CB transport device requiring auto-sense\n"); 647 US_DEBUGP("-- CB transport device requiring auto-sense\n");
648 need_auto_sense = 1; 648 need_auto_sense = 1;
@@ -701,8 +701,8 @@ Retry_Sense:
701 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, sense_size); 701 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, sense_size);
702 702
703 /* FIXME: we must do the protocol translation here */ 703 /* FIXME: we must do the protocol translation here */
704 if (us->subclass == US_SC_RBC || us->subclass == US_SC_SCSI || 704 if (us->subclass == USB_SC_RBC || us->subclass == USB_SC_SCSI ||
705 us->subclass == US_SC_CYP_ATACB) 705 us->subclass == USB_SC_CYP_ATACB)
706 srb->cmd_len = 6; 706 srb->cmd_len = 6;
707 else 707 else
708 srb->cmd_len = 12; 708 srb->cmd_len = 12;
@@ -819,6 +819,35 @@ Retry_Sense:
819 } 819 }
820 } 820 }
821 821
822 /*
823 * Some devices don't work or return incorrect data the first
824 * time they get a READ(10) command, or for the first READ(10)
825 * after a media change. If the INITIAL_READ10 flag is set,
826 * keep track of whether READ(10) commands succeed. If the
827 * previous one succeeded and this one failed, set the REDO_READ10
828 * flag to force a retry.
829 */
830 if (unlikely((us->fflags & US_FL_INITIAL_READ10) &&
831 srb->cmnd[0] == READ_10)) {
832 if (srb->result == SAM_STAT_GOOD) {
833 set_bit(US_FLIDX_READ10_WORKED, &us->dflags);
834 } else if (test_bit(US_FLIDX_READ10_WORKED, &us->dflags)) {
835 clear_bit(US_FLIDX_READ10_WORKED, &us->dflags);
836 set_bit(US_FLIDX_REDO_READ10, &us->dflags);
837 }
838
839 /*
840 * Next, if the REDO_READ10 flag is set, return a result
841 * code that will cause the SCSI core to retry the READ(10)
842 * command immediately.
843 */
844 if (test_bit(US_FLIDX_REDO_READ10, &us->dflags)) {
845 clear_bit(US_FLIDX_REDO_READ10, &us->dflags);
846 srb->result = DID_IMM_RETRY << 16;
847 srb->sense_buffer[0] = 0;
848 }
849 }
850
822 /* Did we transfer less than the minimum amount required? */ 851 /* Did we transfer less than the minimum amount required? */
823 if ((srb->result == SAM_STAT_GOOD || srb->sense_buffer[2] == 0) && 852 if ((srb->result == SAM_STAT_GOOD || srb->sense_buffer[2] == 0) &&
824 scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow) 853 scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow)
@@ -926,7 +955,7 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
926 /* NOTE: CB does not have a status stage. Silly, I know. So 955 /* NOTE: CB does not have a status stage. Silly, I know. So
927 * we have to catch this at a higher level. 956 * we have to catch this at a higher level.
928 */ 957 */
929 if (us->protocol != US_PR_CBI) 958 if (us->protocol != USB_PR_CBI)
930 return USB_STOR_TRANSPORT_GOOD; 959 return USB_STOR_TRANSPORT_GOOD;
931 960
932 result = usb_stor_intr_transfer(us, us->iobuf, 2); 961 result = usb_stor_intr_transfer(us, us->iobuf, 2);
@@ -942,7 +971,7 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
942 * that this means we could be ignoring a real error on these 971 * that this means we could be ignoring a real error on these
943 * commands, but that can't be helped. 972 * commands, but that can't be helped.
944 */ 973 */
945 if (us->subclass == US_SC_UFI) { 974 if (us->subclass == USB_SC_UFI) {
946 if (srb->cmnd[0] == REQUEST_SENSE || 975 if (srb->cmnd[0] == REQUEST_SENSE ||
947 srb->cmnd[0] == INQUIRY) 976 srb->cmnd[0] == INQUIRY)
948 return USB_STOR_TRANSPORT_GOOD; 977 return USB_STOR_TRANSPORT_GOOD;
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
new file mode 100644
index 000000000000..23f0dd9c36d4
--- /dev/null
+++ b/drivers/usb/storage/uas.c
@@ -0,0 +1,776 @@
1/*
2 * USB Attached SCSI
3 * Note that this is not the same as the USB Mass Storage driver
4 *
5 * Copyright Matthew Wilcox for Intel Corp, 2010
6 * Copyright Sarah Sharp for Intel Corp, 2010
7 *
8 * Distributed under the terms of the GNU GPL, version two.
9 */
10
11#include <linux/blkdev.h>
12#include <linux/slab.h>
13#include <linux/types.h>
14#include <linux/usb.h>
15#include <linux/usb/storage.h>
16
17#include <scsi/scsi.h>
18#include <scsi/scsi_dbg.h>
19#include <scsi/scsi_cmnd.h>
20#include <scsi/scsi_device.h>
21#include <scsi/scsi_host.h>
22#include <scsi/scsi_tcq.h>
23
24/* Common header for all IUs */
25struct iu {
26 __u8 iu_id;
27 __u8 rsvd1;
28 __be16 tag;
29};
30
31enum {
32 IU_ID_COMMAND = 0x01,
33 IU_ID_STATUS = 0x03,
34 IU_ID_RESPONSE = 0x04,
35 IU_ID_TASK_MGMT = 0x05,
36 IU_ID_READ_READY = 0x06,
37 IU_ID_WRITE_READY = 0x07,
38};
39
40struct command_iu {
41 __u8 iu_id;
42 __u8 rsvd1;
43 __be16 tag;
44 __u8 prio_attr;
45 __u8 rsvd5;
46 __u8 len;
47 __u8 rsvd7;
48 struct scsi_lun lun;
49 __u8 cdb[16]; /* XXX: Overflow-checking tools may misunderstand */
50};
51
52/*
53 * Also used for the Read Ready and Write Ready IUs since they have the
54 * same first four bytes
55 */
56struct sense_iu {
57 __u8 iu_id;
58 __u8 rsvd1;
59 __be16 tag;
60 __be16 status_qual;
61 __u8 status;
62 __u8 rsvd7[7];
63 __be16 len;
64 __u8 sense[SCSI_SENSE_BUFFERSIZE];
65};
66
67/*
68 * The r00-r01c specs define this version of the SENSE IU data structure.
69 * It's still in use by several different firmware releases.
70 */
71struct sense_iu_old {
72 __u8 iu_id;
73 __u8 rsvd1;
74 __be16 tag;
75 __be16 len;
76 __u8 status;
77 __u8 service_response;
78 __u8 sense[SCSI_SENSE_BUFFERSIZE];
79};
80
81enum {
82 CMD_PIPE_ID = 1,
83 STATUS_PIPE_ID = 2,
84 DATA_IN_PIPE_ID = 3,
85 DATA_OUT_PIPE_ID = 4,
86
87 UAS_SIMPLE_TAG = 0,
88 UAS_HEAD_TAG = 1,
89 UAS_ORDERED_TAG = 2,
90 UAS_ACA = 4,
91};
92
93struct uas_dev_info {
94 struct usb_interface *intf;
95 struct usb_device *udev;
96 int qdepth;
97 unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe;
98 unsigned use_streams:1;
99 unsigned uas_sense_old:1;
100};
101
102enum {
103 ALLOC_STATUS_URB = (1 << 0),
104 SUBMIT_STATUS_URB = (1 << 1),
105 ALLOC_DATA_IN_URB = (1 << 2),
106 SUBMIT_DATA_IN_URB = (1 << 3),
107 ALLOC_DATA_OUT_URB = (1 << 4),
108 SUBMIT_DATA_OUT_URB = (1 << 5),
109 ALLOC_CMD_URB = (1 << 6),
110 SUBMIT_CMD_URB = (1 << 7),
111};
112
113/* Overrides scsi_pointer */
114struct uas_cmd_info {
115 unsigned int state;
116 unsigned int stream;
117 struct urb *cmd_urb;
118 struct urb *status_urb;
119 struct urb *data_in_urb;
120 struct urb *data_out_urb;
121 struct list_head list;
122};
123
124/* I hate forward declarations, but I actually have a loop */
125static int uas_submit_urbs(struct scsi_cmnd *cmnd,
126 struct uas_dev_info *devinfo, gfp_t gfp);
127
128static DEFINE_SPINLOCK(uas_work_lock);
129static LIST_HEAD(uas_work_list);
130
131static void uas_do_work(struct work_struct *work)
132{
133 struct uas_cmd_info *cmdinfo;
134 struct list_head list;
135
136 spin_lock_irq(&uas_work_lock);
137 list_replace_init(&uas_work_list, &list);
138 spin_unlock_irq(&uas_work_lock);
139
140 list_for_each_entry(cmdinfo, &list, list) {
141 struct scsi_pointer *scp = (void *)cmdinfo;
142 struct scsi_cmnd *cmnd = container_of(scp,
143 struct scsi_cmnd, SCp);
144 uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_NOIO);
145 }
146}
147
148static DECLARE_WORK(uas_work, uas_do_work);
149
150static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd)
151{
152 struct sense_iu *sense_iu = urb->transfer_buffer;
153 struct scsi_device *sdev = cmnd->device;
154
155 if (urb->actual_length > 16) {
156 unsigned len = be16_to_cpup(&sense_iu->len);
157 if (len + 16 != urb->actual_length) {
158 int newlen = min(len + 16, urb->actual_length) - 16;
159 if (newlen < 0)
160 newlen = 0;
161 sdev_printk(KERN_INFO, sdev, "%s: urb length %d "
162 "disagrees with IU sense data length %d, "
163 "using %d bytes of sense data\n", __func__,
164 urb->actual_length, len, newlen);
165 len = newlen;
166 }
167 memcpy(cmnd->sense_buffer, sense_iu->sense, len);
168 }
169
170 cmnd->result = sense_iu->status;
171 if (sdev->current_cmnd)
172 sdev->current_cmnd = NULL;
173 cmnd->scsi_done(cmnd);
174 usb_free_urb(urb);
175}
176
177static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd)
178{
179 struct sense_iu_old *sense_iu = urb->transfer_buffer;
180 struct scsi_device *sdev = cmnd->device;
181
182 if (urb->actual_length > 8) {
183 unsigned len = be16_to_cpup(&sense_iu->len) - 2;
184 if (len + 8 != urb->actual_length) {
185 int newlen = min(len + 8, urb->actual_length) - 8;
186 if (newlen < 0)
187 newlen = 0;
188 sdev_printk(KERN_INFO, sdev, "%s: urb length %d "
189 "disagrees with IU sense data length %d, "
190 "using %d bytes of sense data\n", __func__,
191 urb->actual_length, len, newlen);
192 len = newlen;
193 }
194 memcpy(cmnd->sense_buffer, sense_iu->sense, len);
195 }
196
197 cmnd->result = sense_iu->status;
198 if (sdev->current_cmnd)
199 sdev->current_cmnd = NULL;
200 cmnd->scsi_done(cmnd);
201 usb_free_urb(urb);
202}
203
204static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd,
205 unsigned direction)
206{
207 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
208 int err;
209
210 cmdinfo->state = direction | SUBMIT_STATUS_URB;
211 err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC);
212 if (err) {
213 spin_lock(&uas_work_lock);
214 list_add_tail(&cmdinfo->list, &uas_work_list);
215 spin_unlock(&uas_work_lock);
216 schedule_work(&uas_work);
217 }
218}
219
220static void uas_stat_cmplt(struct urb *urb)
221{
222 struct iu *iu = urb->transfer_buffer;
223 struct scsi_device *sdev = urb->context;
224 struct uas_dev_info *devinfo = sdev->hostdata;
225 struct scsi_cmnd *cmnd;
226 u16 tag;
227
228 if (urb->status) {
229 dev_err(&urb->dev->dev, "URB BAD STATUS %d\n", urb->status);
230 usb_free_urb(urb);
231 return;
232 }
233
234 tag = be16_to_cpup(&iu->tag) - 1;
235 if (sdev->current_cmnd)
236 cmnd = sdev->current_cmnd;
237 else
238 cmnd = scsi_find_tag(sdev, tag);
239 if (!cmnd)
240 return;
241
242 switch (iu->iu_id) {
243 case IU_ID_STATUS:
244 if (urb->actual_length < 16)
245 devinfo->uas_sense_old = 1;
246 if (devinfo->uas_sense_old)
247 uas_sense_old(urb, cmnd);
248 else
249 uas_sense(urb, cmnd);
250 break;
251 case IU_ID_READ_READY:
252 uas_xfer_data(urb, cmnd, SUBMIT_DATA_IN_URB);
253 break;
254 case IU_ID_WRITE_READY:
255 uas_xfer_data(urb, cmnd, SUBMIT_DATA_OUT_URB);
256 break;
257 default:
258 scmd_printk(KERN_ERR, cmnd,
259 "Bogus IU (%d) received on status pipe\n", iu->iu_id);
260 }
261}
262
263static void uas_data_cmplt(struct urb *urb)
264{
265 struct scsi_data_buffer *sdb = urb->context;
266 sdb->resid = sdb->length - urb->actual_length;
267 usb_free_urb(urb);
268}
269
270static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp,
271 unsigned int pipe, u16 stream_id,
272 struct scsi_data_buffer *sdb,
273 enum dma_data_direction dir)
274{
275 struct usb_device *udev = devinfo->udev;
276 struct urb *urb = usb_alloc_urb(0, gfp);
277
278 if (!urb)
279 goto out;
280 usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length, uas_data_cmplt,
281 sdb);
282 if (devinfo->use_streams)
283 urb->stream_id = stream_id;
284 urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0;
285 urb->sg = sdb->table.sgl;
286 out:
287 return urb;
288}
289
290static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp,
291 struct scsi_cmnd *cmnd, u16 stream_id)
292{
293 struct usb_device *udev = devinfo->udev;
294 struct urb *urb = usb_alloc_urb(0, gfp);
295 struct sense_iu *iu;
296
297 if (!urb)
298 goto out;
299
300 iu = kzalloc(sizeof(*iu), gfp);
301 if (!iu)
302 goto free;
303
304 usb_fill_bulk_urb(urb, udev, devinfo->status_pipe, iu, sizeof(*iu),
305 uas_stat_cmplt, cmnd->device);
306 urb->stream_id = stream_id;
307 urb->transfer_flags |= URB_FREE_BUFFER;
308 out:
309 return urb;
310 free:
311 usb_free_urb(urb);
312 return NULL;
313}
314
315static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp,
316 struct scsi_cmnd *cmnd, u16 stream_id)
317{
318 struct usb_device *udev = devinfo->udev;
319 struct scsi_device *sdev = cmnd->device;
320 struct urb *urb = usb_alloc_urb(0, gfp);
321 struct command_iu *iu;
322 int len;
323
324 if (!urb)
325 goto out;
326
327 len = cmnd->cmd_len - 16;
328 if (len < 0)
329 len = 0;
330 len = ALIGN(len, 4);
331 iu = kzalloc(sizeof(*iu) + len, gfp);
332 if (!iu)
333 goto free;
334
335 iu->iu_id = IU_ID_COMMAND;
336 iu->tag = cpu_to_be16(stream_id);
337 iu->prio_attr = UAS_SIMPLE_TAG;
338 iu->len = len;
339 int_to_scsilun(sdev->lun, &iu->lun);
340 memcpy(iu->cdb, cmnd->cmnd, cmnd->cmd_len);
341
342 usb_fill_bulk_urb(urb, udev, devinfo->cmd_pipe, iu, sizeof(*iu) + len,
343 usb_free_urb, NULL);
344 urb->transfer_flags |= URB_FREE_BUFFER;
345 out:
346 return urb;
347 free:
348 usb_free_urb(urb);
349 return NULL;
350}
351
352/*
353 * Why should I request the Status IU before sending the Command IU? Spec
354 * says to, but also says the device may receive them in any order. Seems
355 * daft to me.
356 */
357
358static int uas_submit_urbs(struct scsi_cmnd *cmnd,
359 struct uas_dev_info *devinfo, gfp_t gfp)
360{
361 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
362
363 if (cmdinfo->state & ALLOC_STATUS_URB) {
364 cmdinfo->status_urb = uas_alloc_sense_urb(devinfo, gfp, cmnd,
365 cmdinfo->stream);
366 if (!cmdinfo->status_urb)
367 return SCSI_MLQUEUE_DEVICE_BUSY;
368 cmdinfo->state &= ~ALLOC_STATUS_URB;
369 }
370
371 if (cmdinfo->state & SUBMIT_STATUS_URB) {
372 if (usb_submit_urb(cmdinfo->status_urb, gfp)) {
373 scmd_printk(KERN_INFO, cmnd,
374 "sense urb submission failure\n");
375 return SCSI_MLQUEUE_DEVICE_BUSY;
376 }
377 cmdinfo->state &= ~SUBMIT_STATUS_URB;
378 }
379
380 if (cmdinfo->state & ALLOC_DATA_IN_URB) {
381 cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp,
382 devinfo->data_in_pipe, cmdinfo->stream,
383 scsi_in(cmnd), DMA_FROM_DEVICE);
384 if (!cmdinfo->data_in_urb)
385 return SCSI_MLQUEUE_DEVICE_BUSY;
386 cmdinfo->state &= ~ALLOC_DATA_IN_URB;
387 }
388
389 if (cmdinfo->state & SUBMIT_DATA_IN_URB) {
390 if (usb_submit_urb(cmdinfo->data_in_urb, gfp)) {
391 scmd_printk(KERN_INFO, cmnd,
392 "data in urb submission failure\n");
393 return SCSI_MLQUEUE_DEVICE_BUSY;
394 }
395 cmdinfo->state &= ~SUBMIT_DATA_IN_URB;
396 }
397
398 if (cmdinfo->state & ALLOC_DATA_OUT_URB) {
399 cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp,
400 devinfo->data_out_pipe, cmdinfo->stream,
401 scsi_out(cmnd), DMA_TO_DEVICE);
402 if (!cmdinfo->data_out_urb)
403 return SCSI_MLQUEUE_DEVICE_BUSY;
404 cmdinfo->state &= ~ALLOC_DATA_OUT_URB;
405 }
406
407 if (cmdinfo->state & SUBMIT_DATA_OUT_URB) {
408 if (usb_submit_urb(cmdinfo->data_out_urb, gfp)) {
409 scmd_printk(KERN_INFO, cmnd,
410 "data out urb submission failure\n");
411 return SCSI_MLQUEUE_DEVICE_BUSY;
412 }
413 cmdinfo->state &= ~SUBMIT_DATA_OUT_URB;
414 }
415
416 if (cmdinfo->state & ALLOC_CMD_URB) {
417 cmdinfo->cmd_urb = uas_alloc_cmd_urb(devinfo, gfp, cmnd,
418 cmdinfo->stream);
419 if (!cmdinfo->cmd_urb)
420 return SCSI_MLQUEUE_DEVICE_BUSY;
421 cmdinfo->state &= ~ALLOC_CMD_URB;
422 }
423
424 if (cmdinfo->state & SUBMIT_CMD_URB) {
425 if (usb_submit_urb(cmdinfo->cmd_urb, gfp)) {
426 scmd_printk(KERN_INFO, cmnd,
427 "cmd urb submission failure\n");
428 return SCSI_MLQUEUE_DEVICE_BUSY;
429 }
430 cmdinfo->state &= ~SUBMIT_CMD_URB;
431 }
432
433 return 0;
434}
435
436static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
437 void (*done)(struct scsi_cmnd *))
438{
439 struct scsi_device *sdev = cmnd->device;
440 struct uas_dev_info *devinfo = sdev->hostdata;
441 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
442 int err;
443
444 BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer));
445
446 if (!cmdinfo->status_urb && sdev->current_cmnd)
447 return SCSI_MLQUEUE_DEVICE_BUSY;
448
449 if (blk_rq_tagged(cmnd->request)) {
450 cmdinfo->stream = cmnd->request->tag + 1;
451 } else {
452 sdev->current_cmnd = cmnd;
453 cmdinfo->stream = 1;
454 }
455
456 cmnd->scsi_done = done;
457
458 cmdinfo->state = ALLOC_STATUS_URB | SUBMIT_STATUS_URB |
459 ALLOC_CMD_URB | SUBMIT_CMD_URB;
460
461 switch (cmnd->sc_data_direction) {
462 case DMA_FROM_DEVICE:
463 cmdinfo->state |= ALLOC_DATA_IN_URB | SUBMIT_DATA_IN_URB;
464 break;
465 case DMA_BIDIRECTIONAL:
466 cmdinfo->state |= ALLOC_DATA_IN_URB | SUBMIT_DATA_IN_URB;
467 case DMA_TO_DEVICE:
468 cmdinfo->state |= ALLOC_DATA_OUT_URB | SUBMIT_DATA_OUT_URB;
469 case DMA_NONE:
470 break;
471 }
472
473 if (!devinfo->use_streams) {
474 cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB);
475 cmdinfo->stream = 0;
476 }
477
478 err = uas_submit_urbs(cmnd, devinfo, GFP_ATOMIC);
479 if (err) {
480 /* If we did nothing, give up now */
481 if (cmdinfo->state & SUBMIT_STATUS_URB) {
482 usb_free_urb(cmdinfo->status_urb);
483 return SCSI_MLQUEUE_DEVICE_BUSY;
484 }
485 spin_lock(&uas_work_lock);
486 list_add_tail(&cmdinfo->list, &uas_work_list);
487 spin_unlock(&uas_work_lock);
488 schedule_work(&uas_work);
489 }
490
491 return 0;
492}
493
494static DEF_SCSI_QCMD(uas_queuecommand)
495
496static int uas_eh_abort_handler(struct scsi_cmnd *cmnd)
497{
498 struct scsi_device *sdev = cmnd->device;
499 sdev_printk(KERN_INFO, sdev, "%s tag %d\n", __func__,
500 cmnd->request->tag);
501
502/* XXX: Send ABORT TASK Task Management command */
503 return FAILED;
504}
505
506static int uas_eh_device_reset_handler(struct scsi_cmnd *cmnd)
507{
508 struct scsi_device *sdev = cmnd->device;
509 sdev_printk(KERN_INFO, sdev, "%s tag %d\n", __func__,
510 cmnd->request->tag);
511
512/* XXX: Send LOGICAL UNIT RESET Task Management command */
513 return FAILED;
514}
515
516static int uas_eh_target_reset_handler(struct scsi_cmnd *cmnd)
517{
518 struct scsi_device *sdev = cmnd->device;
519 sdev_printk(KERN_INFO, sdev, "%s tag %d\n", __func__,
520 cmnd->request->tag);
521
522/* XXX: Can we reset just the one USB interface?
523 * Would calling usb_set_interface() have the right effect?
524 */
525 return FAILED;
526}
527
528static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd)
529{
530 struct scsi_device *sdev = cmnd->device;
531 struct uas_dev_info *devinfo = sdev->hostdata;
532 struct usb_device *udev = devinfo->udev;
533
534 sdev_printk(KERN_INFO, sdev, "%s tag %d\n", __func__,
535 cmnd->request->tag);
536
537 if (usb_reset_device(udev))
538 return SUCCESS;
539
540 return FAILED;
541}
542
543static int uas_slave_alloc(struct scsi_device *sdev)
544{
545 sdev->hostdata = (void *)sdev->host->hostdata[0];
546 return 0;
547}
548
549static int uas_slave_configure(struct scsi_device *sdev)
550{
551 struct uas_dev_info *devinfo = sdev->hostdata;
552 scsi_set_tag_type(sdev, MSG_ORDERED_TAG);
553 scsi_activate_tcq(sdev, devinfo->qdepth - 1);
554 return 0;
555}
556
557static struct scsi_host_template uas_host_template = {
558 .module = THIS_MODULE,
559 .name = "uas",
560 .queuecommand = uas_queuecommand,
561 .slave_alloc = uas_slave_alloc,
562 .slave_configure = uas_slave_configure,
563 .eh_abort_handler = uas_eh_abort_handler,
564 .eh_device_reset_handler = uas_eh_device_reset_handler,
565 .eh_target_reset_handler = uas_eh_target_reset_handler,
566 .eh_bus_reset_handler = uas_eh_bus_reset_handler,
567 .can_queue = 65536, /* Is there a limit on the _host_ ? */
568 .this_id = -1,
569 .sg_tablesize = SG_NONE,
570 .cmd_per_lun = 1, /* until we override it */
571 .skip_settle_delay = 1,
572 .ordered_tag = 1,
573};
574
575static struct usb_device_id uas_usb_ids[] = {
576 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_BULK) },
577 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_UAS) },
578 /* 0xaa is a prototype device I happen to have access to */
579 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, 0xaa) },
580 { }
581};
582MODULE_DEVICE_TABLE(usb, uas_usb_ids);
583
584static int uas_is_interface(struct usb_host_interface *intf)
585{
586 return (intf->desc.bInterfaceClass == USB_CLASS_MASS_STORAGE &&
587 intf->desc.bInterfaceSubClass == USB_SC_SCSI &&
588 intf->desc.bInterfaceProtocol == USB_PR_UAS);
589}
590
591static int uas_switch_interface(struct usb_device *udev,
592 struct usb_interface *intf)
593{
594 int i;
595
596 if (uas_is_interface(intf->cur_altsetting))
597 return 0;
598
599 for (i = 0; i < intf->num_altsetting; i++) {
600 struct usb_host_interface *alt = &intf->altsetting[i];
601 if (alt == intf->cur_altsetting)
602 continue;
603 if (uas_is_interface(alt))
604 return usb_set_interface(udev,
605 alt->desc.bInterfaceNumber,
606 alt->desc.bAlternateSetting);
607 }
608
609 return -ENODEV;
610}
611
612static void uas_configure_endpoints(struct uas_dev_info *devinfo)
613{
614 struct usb_host_endpoint *eps[4] = { };
615 struct usb_interface *intf = devinfo->intf;
616 struct usb_device *udev = devinfo->udev;
617 struct usb_host_endpoint *endpoint = intf->cur_altsetting->endpoint;
618 unsigned i, n_endpoints = intf->cur_altsetting->desc.bNumEndpoints;
619
620 devinfo->uas_sense_old = 0;
621
622 for (i = 0; i < n_endpoints; i++) {
623 unsigned char *extra = endpoint[i].extra;
624 int len = endpoint[i].extralen;
625 while (len > 1) {
626 if (extra[1] == USB_DT_PIPE_USAGE) {
627 unsigned pipe_id = extra[2];
628 if (pipe_id > 0 && pipe_id < 5)
629 eps[pipe_id - 1] = &endpoint[i];
630 break;
631 }
632 len -= extra[0];
633 extra += extra[0];
634 }
635 }
636
637 /*
638 * Assume that if we didn't find a control pipe descriptor, we're
639 * using a device with old firmware that happens to be set up like
640 * this.
641 */
642 if (!eps[0]) {
643 devinfo->cmd_pipe = usb_sndbulkpipe(udev, 1);
644 devinfo->status_pipe = usb_rcvbulkpipe(udev, 1);
645 devinfo->data_in_pipe = usb_rcvbulkpipe(udev, 2);
646 devinfo->data_out_pipe = usb_sndbulkpipe(udev, 2);
647
648 eps[1] = usb_pipe_endpoint(udev, devinfo->status_pipe);
649 eps[2] = usb_pipe_endpoint(udev, devinfo->data_in_pipe);
650 eps[3] = usb_pipe_endpoint(udev, devinfo->data_out_pipe);
651 } else {
652 devinfo->cmd_pipe = usb_sndbulkpipe(udev,
653 eps[0]->desc.bEndpointAddress);
654 devinfo->status_pipe = usb_rcvbulkpipe(udev,
655 eps[1]->desc.bEndpointAddress);
656 devinfo->data_in_pipe = usb_rcvbulkpipe(udev,
657 eps[2]->desc.bEndpointAddress);
658 devinfo->data_out_pipe = usb_sndbulkpipe(udev,
659 eps[3]->desc.bEndpointAddress);
660 }
661
662 devinfo->qdepth = usb_alloc_streams(devinfo->intf, eps + 1, 3, 256,
663 GFP_KERNEL);
664 if (devinfo->qdepth < 0) {
665 devinfo->qdepth = 256;
666 devinfo->use_streams = 0;
667 } else {
668 devinfo->use_streams = 1;
669 }
670}
671
672/*
673 * XXX: What I'd like to do here is register a SCSI host for each USB host in
674 * the system. Follow usb-storage's design of registering a SCSI host for
675 * each USB device for the moment. Can implement this by walking up the
676 * USB hierarchy until we find a USB host.
677 */
678static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
679{
680 int result;
681 struct Scsi_Host *shost;
682 struct uas_dev_info *devinfo;
683 struct usb_device *udev = interface_to_usbdev(intf);
684
685 if (uas_switch_interface(udev, intf))
686 return -ENODEV;
687
688 devinfo = kmalloc(sizeof(struct uas_dev_info), GFP_KERNEL);
689 if (!devinfo)
690 return -ENOMEM;
691
692 result = -ENOMEM;
693 shost = scsi_host_alloc(&uas_host_template, sizeof(void *));
694 if (!shost)
695 goto free;
696
697 shost->max_cmd_len = 16 + 252;
698 shost->max_id = 1;
699 shost->sg_tablesize = udev->bus->sg_tablesize;
700
701 result = scsi_add_host(shost, &intf->dev);
702 if (result)
703 goto free;
704 shost->hostdata[0] = (unsigned long)devinfo;
705
706 devinfo->intf = intf;
707 devinfo->udev = udev;
708 uas_configure_endpoints(devinfo);
709
710 scsi_scan_host(shost);
711 usb_set_intfdata(intf, shost);
712 return result;
713 free:
714 kfree(devinfo);
715 if (shost)
716 scsi_host_put(shost);
717 return result;
718}
719
720static int uas_pre_reset(struct usb_interface *intf)
721{
722/* XXX: Need to return 1 if it's not our device in error handling */
723 return 0;
724}
725
726static int uas_post_reset(struct usb_interface *intf)
727{
728/* XXX: Need to return 1 if it's not our device in error handling */
729 return 0;
730}
731
732static void uas_disconnect(struct usb_interface *intf)
733{
734 struct usb_device *udev = interface_to_usbdev(intf);
735 struct usb_host_endpoint *eps[3];
736 struct Scsi_Host *shost = usb_get_intfdata(intf);
737 struct uas_dev_info *devinfo = (void *)shost->hostdata[0];
738
739 scsi_remove_host(shost);
740
741 eps[0] = usb_pipe_endpoint(udev, devinfo->status_pipe);
742 eps[1] = usb_pipe_endpoint(udev, devinfo->data_in_pipe);
743 eps[2] = usb_pipe_endpoint(udev, devinfo->data_out_pipe);
744 usb_free_streams(intf, eps, 3, GFP_KERNEL);
745
746 kfree(devinfo);
747}
748
749/*
750 * XXX: Should this plug into libusual so we can auto-upgrade devices from
751 * Bulk-Only to UAS?
752 */
753static struct usb_driver uas_driver = {
754 .name = "uas",
755 .probe = uas_probe,
756 .disconnect = uas_disconnect,
757 .pre_reset = uas_pre_reset,
758 .post_reset = uas_post_reset,
759 .id_table = uas_usb_ids,
760};
761
762static int uas_init(void)
763{
764 return usb_register(&uas_driver);
765}
766
767static void uas_exit(void)
768{
769 usb_deregister(&uas_driver);
770}
771
772module_init(uas_init);
773module_exit(uas_exit);
774
775MODULE_LICENSE("GPL");
776MODULE_AUTHOR("Matthew Wilcox and Sarah Sharp");
diff --git a/drivers/usb/storage/unusual_alauda.h b/drivers/usb/storage/unusual_alauda.h
index 8c412f885dd2..fa3e9edaa2cf 100644
--- a/drivers/usb/storage/unusual_alauda.h
+++ b/drivers/usb/storage/unusual_alauda.h
@@ -21,11 +21,11 @@
21UNUSUAL_DEV( 0x0584, 0x0008, 0x0102, 0x0102, 21UNUSUAL_DEV( 0x0584, 0x0008, 0x0102, 0x0102,
22 "Fujifilm", 22 "Fujifilm",
23 "DPC-R1 (Alauda)", 23 "DPC-R1 (Alauda)",
24 US_SC_SCSI, US_PR_ALAUDA, init_alauda, 0), 24 USB_SC_SCSI, USB_PR_ALAUDA, init_alauda, 0),
25 25
26UNUSUAL_DEV( 0x07b4, 0x010a, 0x0102, 0x0102, 26UNUSUAL_DEV( 0x07b4, 0x010a, 0x0102, 0x0102,
27 "Olympus", 27 "Olympus",
28 "MAUSB-10 (Alauda)", 28 "MAUSB-10 (Alauda)",
29 US_SC_SCSI, US_PR_ALAUDA, init_alauda, 0), 29 USB_SC_SCSI, USB_PR_ALAUDA, init_alauda, 0),
30 30
31#endif /* defined(CONFIG_USB_STORAGE_ALAUDA) || ... */ 31#endif /* defined(CONFIG_USB_STORAGE_ALAUDA) || ... */
diff --git a/drivers/usb/storage/unusual_cypress.h b/drivers/usb/storage/unusual_cypress.h
index 44be6d75dab6..2c8553026222 100644
--- a/drivers/usb/storage/unusual_cypress.h
+++ b/drivers/usb/storage/unusual_cypress.h
@@ -23,12 +23,17 @@
23UNUSUAL_DEV( 0x04b4, 0x6830, 0x0000, 0x9999, 23UNUSUAL_DEV( 0x04b4, 0x6830, 0x0000, 0x9999,
24 "Cypress", 24 "Cypress",
25 "Cypress AT2LP", 25 "Cypress AT2LP",
26 US_SC_CYP_ATACB, US_PR_DEVICE, NULL, 0), 26 USB_SC_CYP_ATACB, USB_PR_DEVICE, NULL, 0),
27 27
28/* CY7C68310 : support atacb and atacb2 */ 28/* CY7C68310 : support atacb and atacb2 */
29UNUSUAL_DEV( 0x04b4, 0x6831, 0x0000, 0x9999, 29UNUSUAL_DEV( 0x04b4, 0x6831, 0x0000, 0x9999,
30 "Cypress", 30 "Cypress",
31 "Cypress ISD-300LP", 31 "Cypress ISD-300LP",
32 US_SC_CYP_ATACB, US_PR_DEVICE, NULL, 0), 32 USB_SC_CYP_ATACB, USB_PR_DEVICE, NULL, 0),
33
34UNUSUAL_DEV( 0x14cd, 0x6116, 0x0000, 0x9999,
35 "Super Top",
36 "USB 2.0 SATA BRIDGE",
37 USB_SC_CYP_ATACB, USB_PR_DEVICE, NULL, 0),
33 38
34#endif /* defined(CONFIG_USB_STORAGE_CYPRESS_ATACB) || ... */ 39#endif /* defined(CONFIG_USB_STORAGE_CYPRESS_ATACB) || ... */
diff --git a/drivers/usb/storage/unusual_datafab.h b/drivers/usb/storage/unusual_datafab.h
index c9298ce9f223..582a603c78be 100644
--- a/drivers/usb/storage/unusual_datafab.h
+++ b/drivers/usb/storage/unusual_datafab.h
@@ -21,7 +21,7 @@
21UNUSUAL_DEV( 0x07c4, 0xa000, 0x0000, 0x0015, 21UNUSUAL_DEV( 0x07c4, 0xa000, 0x0000, 0x0015,
22 "Datafab", 22 "Datafab",
23 "MDCFE-B USB CF Reader", 23 "MDCFE-B USB CF Reader",
24 US_SC_SCSI, US_PR_DATAFAB, NULL, 24 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
25 0), 25 0),
26 26
27/* 27/*
@@ -38,45 +38,45 @@ UNUSUAL_DEV( 0x07c4, 0xa000, 0x0000, 0x0015,
38UNUSUAL_DEV( 0x07c4, 0xa001, 0x0000, 0xffff, 38UNUSUAL_DEV( 0x07c4, 0xa001, 0x0000, 0xffff,
39 "SIIG/Datafab", 39 "SIIG/Datafab",
40 "SIIG/Datafab Memory Stick+CF Reader/Writer", 40 "SIIG/Datafab Memory Stick+CF Reader/Writer",
41 US_SC_SCSI, US_PR_DATAFAB, NULL, 41 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
42 0), 42 0),
43 43
44/* Reported by Josef Reisinger <josef.reisinger@netcologne.de> */ 44/* Reported by Josef Reisinger <josef.reisinger@netcologne.de> */
45UNUSUAL_DEV( 0x07c4, 0xa002, 0x0000, 0xffff, 45UNUSUAL_DEV( 0x07c4, 0xa002, 0x0000, 0xffff,
46 "Datafab/Unknown", 46 "Datafab/Unknown",
47 "MD2/MD3 Disk enclosure", 47 "MD2/MD3 Disk enclosure",
48 US_SC_SCSI, US_PR_DATAFAB, NULL, 48 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
49 US_FL_SINGLE_LUN), 49 US_FL_SINGLE_LUN),
50 50
51UNUSUAL_DEV( 0x07c4, 0xa003, 0x0000, 0xffff, 51UNUSUAL_DEV( 0x07c4, 0xa003, 0x0000, 0xffff,
52 "Datafab/Unknown", 52 "Datafab/Unknown",
53 "Datafab-based Reader", 53 "Datafab-based Reader",
54 US_SC_SCSI, US_PR_DATAFAB, NULL, 54 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
55 0), 55 0),
56 56
57UNUSUAL_DEV( 0x07c4, 0xa004, 0x0000, 0xffff, 57UNUSUAL_DEV( 0x07c4, 0xa004, 0x0000, 0xffff,
58 "Datafab/Unknown", 58 "Datafab/Unknown",
59 "Datafab-based Reader", 59 "Datafab-based Reader",
60 US_SC_SCSI, US_PR_DATAFAB, NULL, 60 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
61 0), 61 0),
62 62
63UNUSUAL_DEV( 0x07c4, 0xa005, 0x0000, 0xffff, 63UNUSUAL_DEV( 0x07c4, 0xa005, 0x0000, 0xffff,
64 "PNY/Datafab", 64 "PNY/Datafab",
65 "PNY/Datafab CF+SM Reader", 65 "PNY/Datafab CF+SM Reader",
66 US_SC_SCSI, US_PR_DATAFAB, NULL, 66 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
67 0), 67 0),
68 68
69UNUSUAL_DEV( 0x07c4, 0xa006, 0x0000, 0xffff, 69UNUSUAL_DEV( 0x07c4, 0xa006, 0x0000, 0xffff,
70 "Simple Tech/Datafab", 70 "Simple Tech/Datafab",
71 "Simple Tech/Datafab CF+SM Reader", 71 "Simple Tech/Datafab CF+SM Reader",
72 US_SC_SCSI, US_PR_DATAFAB, NULL, 72 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
73 0), 73 0),
74 74
75/* Submitted by Olaf Hering <olh@suse.de> */ 75/* Submitted by Olaf Hering <olh@suse.de> */
76UNUSUAL_DEV( 0x07c4, 0xa109, 0x0000, 0xffff, 76UNUSUAL_DEV( 0x07c4, 0xa109, 0x0000, 0xffff,
77 "Datafab Systems, Inc.", 77 "Datafab Systems, Inc.",
78 "USB to CF + SM Combo (LC1)", 78 "USB to CF + SM Combo (LC1)",
79 US_SC_SCSI, US_PR_DATAFAB, NULL, 79 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
80 0), 80 0),
81 81
82/* Reported by Felix Moeller <felix@derklecks.de> 82/* Reported by Felix Moeller <felix@derklecks.de>
@@ -86,13 +86,13 @@ UNUSUAL_DEV( 0x07c4, 0xa109, 0x0000, 0xffff,
86UNUSUAL_DEV( 0x07c4, 0xa10b, 0x0000, 0xffff, 86UNUSUAL_DEV( 0x07c4, 0xa10b, 0x0000, 0xffff,
87 "DataFab Systems Inc.", 87 "DataFab Systems Inc.",
88 "USB CF+MS", 88 "USB CF+MS",
89 US_SC_SCSI, US_PR_DATAFAB, NULL, 89 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
90 0), 90 0),
91 91
92UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff, 92UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff,
93 "Acomdata", 93 "Acomdata",
94 "CF", 94 "CF",
95 US_SC_SCSI, US_PR_DATAFAB, NULL, 95 USB_SC_SCSI, USB_PR_DATAFAB, NULL,
96 US_FL_SINGLE_LUN), 96 US_FL_SINGLE_LUN),
97 97
98#endif /* defined(CONFIG_USB_STORAGE_DATAFAB) || ... */ 98#endif /* defined(CONFIG_USB_STORAGE_DATAFAB) || ... */
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 2c897eefadde..ccff3483eebc 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -63,26 +63,26 @@
63UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100, 63UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100,
64 "ATMEL", 64 "ATMEL",
65 "SND1 Storage", 65 "SND1 Storage",
66 US_SC_DEVICE, US_PR_DEVICE, NULL, 66 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
67 US_FL_IGNORE_RESIDUE), 67 US_FL_IGNORE_RESIDUE),
68 68
69/* Reported by Rodolfo Quesada <rquesada@roqz.net> */ 69/* Reported by Rodolfo Quesada <rquesada@roqz.net> */
70UNUSUAL_DEV( 0x03ee, 0x6906, 0x0003, 0x0003, 70UNUSUAL_DEV( 0x03ee, 0x6906, 0x0003, 0x0003,
71 "VIA Technologies Inc.", 71 "VIA Technologies Inc.",
72 "Mitsumi multi cardreader", 72 "Mitsumi multi cardreader",
73 US_SC_DEVICE, US_PR_DEVICE, NULL, 73 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
74 US_FL_IGNORE_RESIDUE ), 74 US_FL_IGNORE_RESIDUE ),
75 75
76UNUSUAL_DEV( 0x03f0, 0x0107, 0x0200, 0x0200, 76UNUSUAL_DEV( 0x03f0, 0x0107, 0x0200, 0x0200,
77 "HP", 77 "HP",
78 "CD-Writer+", 78 "CD-Writer+",
79 US_SC_8070, US_PR_CB, NULL, 0), 79 USB_SC_8070, USB_PR_CB, NULL, 0),
80 80
81/* Reported by Ben Efros <ben@pc-doctor.com> */ 81/* Reported by Ben Efros <ben@pc-doctor.com> */
82UNUSUAL_DEV( 0x03f0, 0x070c, 0x0000, 0x0000, 82UNUSUAL_DEV( 0x03f0, 0x070c, 0x0000, 0x0000,
83 "HP", 83 "HP",
84 "Personal Media Drive", 84 "Personal Media Drive",
85 US_SC_DEVICE, US_PR_DEVICE, NULL, 85 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
86 US_FL_SANE_SENSE ), 86 US_FL_SANE_SENSE ),
87 87
88/* Reported by Grant Grundler <grundler@parisc-linux.org> 88/* Reported by Grant Grundler <grundler@parisc-linux.org>
@@ -91,7 +91,7 @@ UNUSUAL_DEV( 0x03f0, 0x070c, 0x0000, 0x0000,
91UNUSUAL_DEV( 0x03f0, 0x4002, 0x0001, 0x0001, 91UNUSUAL_DEV( 0x03f0, 0x4002, 0x0001, 0x0001,
92 "HP", 92 "HP",
93 "PhotoSmart R707", 93 "PhotoSmart R707",
94 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_CAPACITY), 94 USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_FIX_CAPACITY),
95 95
96/* Reported by Sebastian Kapfer <sebastian_kapfer@gmx.net> 96/* Reported by Sebastian Kapfer <sebastian_kapfer@gmx.net>
97 * and Olaf Hering <olh@suse.de> (different bcd's, same vendor/product) 97 * and Olaf Hering <olh@suse.de> (different bcd's, same vendor/product)
@@ -100,14 +100,14 @@ UNUSUAL_DEV( 0x03f0, 0x4002, 0x0001, 0x0001,
100UNUSUAL_DEV( 0x0409, 0x0040, 0x0000, 0x9999, 100UNUSUAL_DEV( 0x0409, 0x0040, 0x0000, 0x9999,
101 "NEC", 101 "NEC",
102 "NEC USB UF000x", 102 "NEC USB UF000x",
103 US_SC_DEVICE, US_PR_DEVICE, NULL, 103 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
104 US_FL_SINGLE_LUN ), 104 US_FL_SINGLE_LUN ),
105 105
106/* Patch submitted by Mihnea-Costin Grigore <mihnea@zulu.ro> */ 106/* Patch submitted by Mihnea-Costin Grigore <mihnea@zulu.ro> */
107UNUSUAL_DEV( 0x040d, 0x6205, 0x0003, 0x0003, 107UNUSUAL_DEV( 0x040d, 0x6205, 0x0003, 0x0003,
108 "VIA Technologies Inc.", 108 "VIA Technologies Inc.",
109 "USB 2.0 Card Reader", 109 "USB 2.0 Card Reader",
110 US_SC_DEVICE, US_PR_DEVICE, NULL, 110 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
111 US_FL_IGNORE_RESIDUE ), 111 US_FL_IGNORE_RESIDUE ),
112 112
113/* Deduced by Jonathan Woithe <jwoithe@physics.adelaide.edu.au> 113/* Deduced by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
@@ -117,40 +117,40 @@ UNUSUAL_DEV( 0x040d, 0x6205, 0x0003, 0x0003,
117UNUSUAL_DEV( 0x0411, 0x001c, 0x0113, 0x0113, 117UNUSUAL_DEV( 0x0411, 0x001c, 0x0113, 0x0113,
118 "Buffalo", 118 "Buffalo",
119 "DUB-P40G HDD", 119 "DUB-P40G HDD",
120 US_SC_DEVICE, US_PR_DEVICE, NULL, 120 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
121 US_FL_FIX_INQUIRY ), 121 US_FL_FIX_INQUIRY ),
122 122
123/* Submitted by Ernestas Vaiciukevicius <ernisv@gmail.com> */ 123/* Submitted by Ernestas Vaiciukevicius <ernisv@gmail.com> */
124UNUSUAL_DEV( 0x0419, 0x0100, 0x0100, 0x0100, 124UNUSUAL_DEV( 0x0419, 0x0100, 0x0100, 0x0100,
125 "Samsung Info. Systems America, Inc.", 125 "Samsung Info. Systems America, Inc.",
126 "MP3 Player", 126 "MP3 Player",
127 US_SC_DEVICE, US_PR_DEVICE, NULL, 127 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
128 US_FL_IGNORE_RESIDUE ), 128 US_FL_IGNORE_RESIDUE ),
129 129
130/* Reported by Orgad Shaneh <orgads@gmail.com> */ 130/* Reported by Orgad Shaneh <orgads@gmail.com> */
131UNUSUAL_DEV( 0x0419, 0xaace, 0x0100, 0x0100, 131UNUSUAL_DEV( 0x0419, 0xaace, 0x0100, 0x0100,
132 "Samsung", "MP3 Player", 132 "Samsung", "MP3 Player",
133 US_SC_DEVICE, US_PR_DEVICE, NULL, 133 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
134 US_FL_IGNORE_RESIDUE ), 134 US_FL_IGNORE_RESIDUE ),
135 135
136/* Reported by Christian Leber <christian@leber.de> */ 136/* Reported by Christian Leber <christian@leber.de> */
137UNUSUAL_DEV( 0x0419, 0xaaf5, 0x0100, 0x0100, 137UNUSUAL_DEV( 0x0419, 0xaaf5, 0x0100, 0x0100,
138 "TrekStor", 138 "TrekStor",
139 "i.Beat 115 2.0", 139 "i.Beat 115 2.0",
140 US_SC_DEVICE, US_PR_DEVICE, NULL, 140 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
141 US_FL_IGNORE_RESIDUE | US_FL_NOT_LOCKABLE ), 141 US_FL_IGNORE_RESIDUE | US_FL_NOT_LOCKABLE ),
142 142
143/* Reported by Stefan Werner <dustbln@gmx.de> */ 143/* Reported by Stefan Werner <dustbln@gmx.de> */
144UNUSUAL_DEV( 0x0419, 0xaaf6, 0x0100, 0x0100, 144UNUSUAL_DEV( 0x0419, 0xaaf6, 0x0100, 0x0100,
145 "TrekStor", 145 "TrekStor",
146 "i.Beat Joy 2.0", 146 "i.Beat Joy 2.0",
147 US_SC_DEVICE, US_PR_DEVICE, NULL, 147 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
148 US_FL_IGNORE_RESIDUE ), 148 US_FL_IGNORE_RESIDUE ),
149 149
150/* Reported by Pete Zaitcev <zaitcev@redhat.com>, bz#176584 */ 150/* Reported by Pete Zaitcev <zaitcev@redhat.com>, bz#176584 */
151UNUSUAL_DEV( 0x0420, 0x0001, 0x0100, 0x0100, 151UNUSUAL_DEV( 0x0420, 0x0001, 0x0100, 0x0100,
152 "GENERIC", "MP3 PLAYER", /* MyMusix PD-205 on the outside. */ 152 "GENERIC", "MP3 PLAYER", /* MyMusix PD-205 on the outside. */
153 US_SC_DEVICE, US_PR_DEVICE, NULL, 153 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
154 US_FL_IGNORE_RESIDUE ), 154 US_FL_IGNORE_RESIDUE ),
155 155
156/* Reported by Andrew Nayenko <relan@bk.ru> 156/* Reported by Andrew Nayenko <relan@bk.ru>
@@ -158,28 +158,28 @@ UNUSUAL_DEV( 0x0420, 0x0001, 0x0100, 0x0100,
158UNUSUAL_DEV( 0x0421, 0x0019, 0x0592, 0x0610, 158UNUSUAL_DEV( 0x0421, 0x0019, 0x0592, 0x0610,
159 "Nokia", 159 "Nokia",
160 "Nokia 6288", 160 "Nokia 6288",
161 US_SC_DEVICE, US_PR_DEVICE, NULL, 161 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
162 US_FL_MAX_SECTORS_64 ), 162 US_FL_MAX_SECTORS_64 ),
163 163
164/* Reported by Mario Rettig <mariorettig@web.de> */ 164/* Reported by Mario Rettig <mariorettig@web.de> */
165UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100, 165UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100,
166 "Nokia", 166 "Nokia",
167 "Nokia 3250", 167 "Nokia 3250",
168 US_SC_DEVICE, US_PR_DEVICE, NULL, 168 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
169 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 169 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
170 170
171/* Reported by <honkkis@gmail.com> */ 171/* Reported by <honkkis@gmail.com> */
172UNUSUAL_DEV( 0x0421, 0x0433, 0x0100, 0x0100, 172UNUSUAL_DEV( 0x0421, 0x0433, 0x0100, 0x0100,
173 "Nokia", 173 "Nokia",
174 "E70", 174 "E70",
175 US_SC_DEVICE, US_PR_DEVICE, NULL, 175 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
176 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 176 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
177 177
178/* Reported by Jon Hart <Jon.Hart@web.de> */ 178/* Reported by Jon Hart <Jon.Hart@web.de> */
179UNUSUAL_DEV( 0x0421, 0x0434, 0x0100, 0x0100, 179UNUSUAL_DEV( 0x0421, 0x0434, 0x0100, 0x0100,
180 "Nokia", 180 "Nokia",
181 "E60", 181 "E60",
182 US_SC_DEVICE, US_PR_DEVICE, NULL, 182 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
183 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), 183 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
184 184
185/* Reported by Sumedha Swamy <sumedhaswamy@gmail.com> and 185/* Reported by Sumedha Swamy <sumedhaswamy@gmail.com> and
@@ -187,7 +187,7 @@ UNUSUAL_DEV( 0x0421, 0x0434, 0x0100, 0x0100,
187UNUSUAL_DEV( 0x0421, 0x0444, 0x0100, 0x0100, 187UNUSUAL_DEV( 0x0421, 0x0444, 0x0100, 0x0100,
188 "Nokia", 188 "Nokia",
189 "N91", 189 "N91",
190 US_SC_DEVICE, US_PR_DEVICE, NULL, 190 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
191 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 191 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
192 192
193/* Reported by Jiri Slaby <jirislaby@gmail.com> and 193/* Reported by Jiri Slaby <jirislaby@gmail.com> and
@@ -195,42 +195,42 @@ UNUSUAL_DEV( 0x0421, 0x0444, 0x0100, 0x0100,
195UNUSUAL_DEV( 0x0421, 0x0446, 0x0100, 0x0100, 195UNUSUAL_DEV( 0x0421, 0x0446, 0x0100, 0x0100,
196 "Nokia", 196 "Nokia",
197 "N80", 197 "N80",
198 US_SC_DEVICE, US_PR_DEVICE, NULL, 198 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
199 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 199 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
200 200
201/* Reported by Matthew Bloch <matthew@bytemark.co.uk> */ 201/* Reported by Matthew Bloch <matthew@bytemark.co.uk> */
202UNUSUAL_DEV( 0x0421, 0x044e, 0x0100, 0x0100, 202UNUSUAL_DEV( 0x0421, 0x044e, 0x0100, 0x0100,
203 "Nokia", 203 "Nokia",
204 "E61", 204 "E61",
205 US_SC_DEVICE, US_PR_DEVICE, NULL, 205 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
206 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 206 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
207 207
208/* Reported by Bardur Arantsson <bardur@scientician.net> */ 208/* Reported by Bardur Arantsson <bardur@scientician.net> */
209UNUSUAL_DEV( 0x0421, 0x047c, 0x0370, 0x0610, 209UNUSUAL_DEV( 0x0421, 0x047c, 0x0370, 0x0610,
210 "Nokia", 210 "Nokia",
211 "6131", 211 "6131",
212 US_SC_DEVICE, US_PR_DEVICE, NULL, 212 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
213 US_FL_MAX_SECTORS_64 ), 213 US_FL_MAX_SECTORS_64 ),
214 214
215/* Reported by Manuel Osdoba <manuel.osdoba@tu-ilmenau.de> */ 215/* Reported by Manuel Osdoba <manuel.osdoba@tu-ilmenau.de> */
216UNUSUAL_DEV( 0x0421, 0x0492, 0x0452, 0x9999, 216UNUSUAL_DEV( 0x0421, 0x0492, 0x0452, 0x9999,
217 "Nokia", 217 "Nokia",
218 "Nokia 6233", 218 "Nokia 6233",
219 US_SC_DEVICE, US_PR_DEVICE, NULL, 219 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
220 US_FL_MAX_SECTORS_64 ), 220 US_FL_MAX_SECTORS_64 ),
221 221
222/* Reported by Alex Corcoles <alex@corcoles.net> */ 222/* Reported by Alex Corcoles <alex@corcoles.net> */
223UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370, 223UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370,
224 "Nokia", 224 "Nokia",
225 "6234", 225 "6234",
226 US_SC_DEVICE, US_PR_DEVICE, NULL, 226 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
227 US_FL_MAX_SECTORS_64 ), 227 US_FL_MAX_SECTORS_64 ),
228 228
229#ifdef NO_SDDR09 229#ifdef NO_SDDR09
230UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, 230UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
231 "Microtech", 231 "Microtech",
232 "CameraMate", 232 "CameraMate",
233 US_SC_SCSI, US_PR_CB, NULL, 233 USB_SC_SCSI, USB_PR_CB, NULL,
234 US_FL_SINGLE_LUN ), 234 US_FL_SINGLE_LUN ),
235#endif 235#endif
236 236
@@ -239,7 +239,7 @@ UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
239UNUSUAL_DEV( 0x0451, 0x5416, 0x0100, 0x0100, 239UNUSUAL_DEV( 0x0451, 0x5416, 0x0100, 0x0100,
240 "Neuros Audio", 240 "Neuros Audio",
241 "USB 2.0 HD 2.5", 241 "USB 2.0 HD 2.5",
242 US_SC_DEVICE, US_PR_BULK, NULL, 242 USB_SC_DEVICE, USB_PR_BULK, NULL,
243 US_FL_NEED_OVERRIDE ), 243 US_FL_NEED_OVERRIDE ),
244 244
245/* 245/*
@@ -250,7 +250,7 @@ UNUSUAL_DEV( 0x0451, 0x5416, 0x0100, 0x0100,
250UNUSUAL_DEV( 0x0457, 0x0150, 0x0100, 0x0100, 250UNUSUAL_DEV( 0x0457, 0x0150, 0x0100, 0x0100,
251 "USBest Technology", /* sold by Transcend */ 251 "USBest Technology", /* sold by Transcend */
252 "USB Mass Storage Device", 252 "USB Mass Storage Device",
253 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ), 253 USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ),
254 254
255/* 255/*
256* Bohdan Linda <bohdan.linda@gmail.com> 256* Bohdan Linda <bohdan.linda@gmail.com>
@@ -260,7 +260,7 @@ UNUSUAL_DEV( 0x0457, 0x0150, 0x0100, 0x0100,
260UNUSUAL_DEV( 0x0457, 0x0151, 0x0100, 0x0100, 260UNUSUAL_DEV( 0x0457, 0x0151, 0x0100, 0x0100,
261 "USB 2.0", 261 "USB 2.0",
262 "Flash Disk", 262 "Flash Disk",
263 US_SC_DEVICE, US_PR_DEVICE, NULL, 263 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
264 US_FL_NOT_LOCKABLE ), 264 US_FL_NOT_LOCKABLE ),
265 265
266/* Reported by Tamas Kerecsen <kerecsen@bigfoot.com> 266/* Reported by Tamas Kerecsen <kerecsen@bigfoot.com>
@@ -272,7 +272,7 @@ UNUSUAL_DEV( 0x0457, 0x0151, 0x0100, 0x0100,
272UNUSUAL_DEV( 0x045e, 0xffff, 0x0000, 0x0000, 272UNUSUAL_DEV( 0x045e, 0xffff, 0x0000, 0x0000,
273 "Mitac", 273 "Mitac",
274 "GPS", 274 "GPS",
275 US_SC_DEVICE, US_PR_DEVICE, NULL, 275 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
276 US_FL_MAX_SECTORS_64 ), 276 US_FL_MAX_SECTORS_64 ),
277 277
278/* 278/*
@@ -284,32 +284,32 @@ UNUSUAL_DEV( 0x045e, 0xffff, 0x0000, 0x0000,
284UNUSUAL_DEV( 0x046b, 0xff40, 0x0100, 0x0100, 284UNUSUAL_DEV( 0x046b, 0xff40, 0x0100, 0x0100,
285 "AMI", 285 "AMI",
286 "Virtual Floppy", 286 "Virtual Floppy",
287 US_SC_DEVICE, US_PR_DEVICE, NULL, 287 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
288 US_FL_NO_WP_DETECT), 288 US_FL_NO_WP_DETECT),
289 289
290/* Patch submitted by Philipp Friedrich <philipp@void.at> */ 290/* Patch submitted by Philipp Friedrich <philipp@void.at> */
291UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100, 291UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100,
292 "Kyocera", 292 "Kyocera",
293 "Finecam S3x", 293 "Finecam S3x",
294 US_SC_8070, US_PR_CB, NULL, US_FL_FIX_INQUIRY), 294 USB_SC_8070, USB_PR_CB, NULL, US_FL_FIX_INQUIRY),
295 295
296/* Patch submitted by Philipp Friedrich <philipp@void.at> */ 296/* Patch submitted by Philipp Friedrich <philipp@void.at> */
297UNUSUAL_DEV( 0x0482, 0x0101, 0x0100, 0x0100, 297UNUSUAL_DEV( 0x0482, 0x0101, 0x0100, 0x0100,
298 "Kyocera", 298 "Kyocera",
299 "Finecam S4", 299 "Finecam S4",
300 US_SC_8070, US_PR_CB, NULL, US_FL_FIX_INQUIRY), 300 USB_SC_8070, USB_PR_CB, NULL, US_FL_FIX_INQUIRY),
301 301
302/* Patch submitted by Stephane Galles <stephane.galles@free.fr> */ 302/* Patch submitted by Stephane Galles <stephane.galles@free.fr> */
303UNUSUAL_DEV( 0x0482, 0x0103, 0x0100, 0x0100, 303UNUSUAL_DEV( 0x0482, 0x0103, 0x0100, 0x0100,
304 "Kyocera", 304 "Kyocera",
305 "Finecam S5", 305 "Finecam S5",
306 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY), 306 USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_FIX_INQUIRY),
307 307
308/* Patch submitted by Jens Taprogge <jens.taprogge@taprogge.org> */ 308/* Patch submitted by Jens Taprogge <jens.taprogge@taprogge.org> */
309UNUSUAL_DEV( 0x0482, 0x0107, 0x0100, 0x0100, 309UNUSUAL_DEV( 0x0482, 0x0107, 0x0100, 0x0100,
310 "Kyocera", 310 "Kyocera",
311 "CONTAX SL300R T*", 311 "CONTAX SL300R T*",
312 US_SC_DEVICE, US_PR_DEVICE, NULL, 312 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
313 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE), 313 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE),
314 314
315/* Reported by Paul Stewart <stewart@wetlogic.net> 315/* Reported by Paul Stewart <stewart@wetlogic.net>
@@ -317,7 +317,7 @@ UNUSUAL_DEV( 0x0482, 0x0107, 0x0100, 0x0100,
317UNUSUAL_DEV( 0x04a4, 0x0004, 0x0001, 0x0001, 317UNUSUAL_DEV( 0x04a4, 0x0004, 0x0001, 0x0001,
318 "Hitachi", 318 "Hitachi",
319 "DVD-CAM DZ-MV100A Camcorder", 319 "DVD-CAM DZ-MV100A Camcorder",
320 US_SC_SCSI, US_PR_CB, NULL, US_FL_SINGLE_LUN), 320 USB_SC_SCSI, USB_PR_CB, NULL, US_FL_SINGLE_LUN),
321 321
322/* BENQ DC5330 322/* BENQ DC5330
323 * Reported by Manuel Fombuena <mfombuena@ya.com> and 323 * Reported by Manuel Fombuena <mfombuena@ya.com> and
@@ -325,7 +325,7 @@ UNUSUAL_DEV( 0x04a4, 0x0004, 0x0001, 0x0001,
325UNUSUAL_DEV( 0x04a5, 0x3010, 0x0100, 0x0100, 325UNUSUAL_DEV( 0x04a5, 0x3010, 0x0100, 0x0100,
326 "Tekom Technologies, Inc", 326 "Tekom Technologies, Inc",
327 "300_CAMERA", 327 "300_CAMERA",
328 US_SC_DEVICE, US_PR_DEVICE, NULL, 328 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
329 US_FL_IGNORE_RESIDUE ), 329 US_FL_IGNORE_RESIDUE ),
330 330
331/* Patch for Nikon coolpix 2000 331/* Patch for Nikon coolpix 2000
@@ -333,14 +333,14 @@ UNUSUAL_DEV( 0x04a5, 0x3010, 0x0100, 0x0100,
333UNUSUAL_DEV( 0x04b0, 0x0301, 0x0010, 0x0010, 333UNUSUAL_DEV( 0x04b0, 0x0301, 0x0010, 0x0010,
334 "NIKON", 334 "NIKON",
335 "NIKON DSC E2000", 335 "NIKON DSC E2000",
336 US_SC_DEVICE, US_PR_DEVICE,NULL, 336 USB_SC_DEVICE, USB_PR_DEVICE,NULL,
337 US_FL_NOT_LOCKABLE ), 337 US_FL_NOT_LOCKABLE ),
338 338
339/* Reported by Doug Maxey (dwm@austin.ibm.com) */ 339/* Reported by Doug Maxey (dwm@austin.ibm.com) */
340UNUSUAL_DEV( 0x04b3, 0x4001, 0x0110, 0x0110, 340UNUSUAL_DEV( 0x04b3, 0x4001, 0x0110, 0x0110,
341 "IBM", 341 "IBM",
342 "IBM RSA2", 342 "IBM RSA2",
343 US_SC_DEVICE, US_PR_CB, NULL, 343 USB_SC_DEVICE, USB_PR_CB, NULL,
344 US_FL_MAX_SECTORS_MIN), 344 US_FL_MAX_SECTORS_MIN),
345 345
346/* Reported by Simon Levitt <simon@whattf.com> 346/* Reported by Simon Levitt <simon@whattf.com>
@@ -348,14 +348,14 @@ UNUSUAL_DEV( 0x04b3, 0x4001, 0x0110, 0x0110,
348UNUSUAL_DEV( 0x04b8, 0x0601, 0x0100, 0x0100, 348UNUSUAL_DEV( 0x04b8, 0x0601, 0x0100, 0x0100,
349 "Epson", 349 "Epson",
350 "875DC Storage", 350 "875DC Storage",
351 US_SC_SCSI, US_PR_CB, NULL, US_FL_FIX_INQUIRY), 351 USB_SC_SCSI, USB_PR_CB, NULL, US_FL_FIX_INQUIRY),
352 352
353/* Reported by Khalid Aziz <khalid@gonehiking.org> 353/* Reported by Khalid Aziz <khalid@gonehiking.org>
354 * This entry is needed because the device reports Sub=ff */ 354 * This entry is needed because the device reports Sub=ff */
355UNUSUAL_DEV( 0x04b8, 0x0602, 0x0110, 0x0110, 355UNUSUAL_DEV( 0x04b8, 0x0602, 0x0110, 0x0110,
356 "Epson", 356 "Epson",
357 "785EPX Storage", 357 "785EPX Storage",
358 US_SC_SCSI, US_PR_BULK, NULL, US_FL_SINGLE_LUN), 358 USB_SC_SCSI, USB_PR_BULK, NULL, US_FL_SINGLE_LUN),
359 359
360/* Not sure who reported this originally but 360/* Not sure who reported this originally but
361 * Pavel Machek <pavel@ucw.cz> reported that the extra US_FL_SINGLE_LUN 361 * Pavel Machek <pavel@ucw.cz> reported that the extra US_FL_SINGLE_LUN
@@ -363,7 +363,7 @@ UNUSUAL_DEV( 0x04b8, 0x0602, 0x0110, 0x0110,
363UNUSUAL_DEV( 0x04cb, 0x0100, 0x0000, 0x2210, 363UNUSUAL_DEV( 0x04cb, 0x0100, 0x0000, 0x2210,
364 "Fujifilm", 364 "Fujifilm",
365 "FinePix 1400Zoom", 365 "FinePix 1400Zoom",
366 US_SC_UFI, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY | US_FL_SINGLE_LUN), 366 USB_SC_UFI, USB_PR_DEVICE, NULL, US_FL_FIX_INQUIRY | US_FL_SINGLE_LUN),
367 367
368/* Reported by Ondrej Zary <linux@rainbow-software.org> 368/* Reported by Ondrej Zary <linux@rainbow-software.org>
369 * The device reports one sector more and breaks when that sector is accessed 369 * The device reports one sector more and breaks when that sector is accessed
@@ -371,7 +371,7 @@ UNUSUAL_DEV( 0x04cb, 0x0100, 0x0000, 0x2210,
371UNUSUAL_DEV( 0x04ce, 0x0002, 0x026c, 0x026c, 371UNUSUAL_DEV( 0x04ce, 0x0002, 0x026c, 0x026c,
372 "ScanLogic", 372 "ScanLogic",
373 "SL11R-IDE", 373 "SL11R-IDE",
374 US_SC_DEVICE, US_PR_DEVICE, NULL, 374 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
375 US_FL_FIX_CAPACITY), 375 US_FL_FIX_CAPACITY),
376 376
377/* Reported by Kriston Fincher <kriston@airmail.net> 377/* Reported by Kriston Fincher <kriston@airmail.net>
@@ -382,27 +382,27 @@ UNUSUAL_DEV( 0x04ce, 0x0002, 0x026c, 0x026c,
382UNUSUAL_DEV( 0x04da, 0x0901, 0x0100, 0x0200, 382UNUSUAL_DEV( 0x04da, 0x0901, 0x0100, 0x0200,
383 "Panasonic", 383 "Panasonic",
384 "LS-120 Camera", 384 "LS-120 Camera",
385 US_SC_UFI, US_PR_DEVICE, NULL, 0), 385 USB_SC_UFI, USB_PR_DEVICE, NULL, 0),
386 386
387/* From Yukihiro Nakai, via zaitcev@yahoo.com. 387/* From Yukihiro Nakai, via zaitcev@yahoo.com.
388 * This is needed for CB instead of CBI */ 388 * This is needed for CB instead of CBI */
389UNUSUAL_DEV( 0x04da, 0x0d05, 0x0000, 0x0000, 389UNUSUAL_DEV( 0x04da, 0x0d05, 0x0000, 0x0000,
390 "Sharp CE-CW05", 390 "Sharp CE-CW05",
391 "CD-R/RW Drive", 391 "CD-R/RW Drive",
392 US_SC_8070, US_PR_CB, NULL, 0), 392 USB_SC_8070, USB_PR_CB, NULL, 0),
393 393
394/* Reported by Adriaan Penning <a.penning@luon.net> */ 394/* Reported by Adriaan Penning <a.penning@luon.net> */
395UNUSUAL_DEV( 0x04da, 0x2372, 0x0000, 0x9999, 395UNUSUAL_DEV( 0x04da, 0x2372, 0x0000, 0x9999,
396 "Panasonic", 396 "Panasonic",
397 "DMC-LCx Camera", 397 "DMC-LCx Camera",
398 US_SC_DEVICE, US_PR_DEVICE, NULL, 398 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
399 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ), 399 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ),
400 400
401/* Reported by Simeon Simeonov <simeonov_2000@yahoo.com> */ 401/* Reported by Simeon Simeonov <simeonov_2000@yahoo.com> */
402UNUSUAL_DEV( 0x04da, 0x2373, 0x0000, 0x9999, 402UNUSUAL_DEV( 0x04da, 0x2373, 0x0000, 0x9999,
403 "LEICA", 403 "LEICA",
404 "D-LUX Camera", 404 "D-LUX Camera",
405 US_SC_DEVICE, US_PR_DEVICE, NULL, 405 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
406 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ), 406 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ),
407 407
408/* Most of the following entries were developed with the help of 408/* Most of the following entries were developed with the help of
@@ -411,19 +411,19 @@ UNUSUAL_DEV( 0x04da, 0x2373, 0x0000, 0x9999,
411UNUSUAL_DEV( 0x04e6, 0x0001, 0x0200, 0x0200, 411UNUSUAL_DEV( 0x04e6, 0x0001, 0x0200, 0x0200,
412 "Matshita", 412 "Matshita",
413 "LS-120", 413 "LS-120",
414 US_SC_8020, US_PR_CB, NULL, 0), 414 USB_SC_8020, USB_PR_CB, NULL, 0),
415 415
416UNUSUAL_DEV( 0x04e6, 0x0002, 0x0100, 0x0100, 416UNUSUAL_DEV( 0x04e6, 0x0002, 0x0100, 0x0100,
417 "Shuttle", 417 "Shuttle",
418 "eUSCSI Bridge", 418 "eUSCSI Bridge",
419 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init, 419 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_euscsi_init,
420 US_FL_SCM_MULT_TARG ), 420 US_FL_SCM_MULT_TARG ),
421 421
422#ifdef NO_SDDR09 422#ifdef NO_SDDR09
423UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208, 423UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208,
424 "SCM Microsystems", 424 "SCM Microsystems",
425 "eUSB CompactFlash Adapter", 425 "eUSB CompactFlash Adapter",
426 US_SC_SCSI, US_PR_CB, NULL, 426 USB_SC_SCSI, USB_PR_CB, NULL,
427 US_FL_SINGLE_LUN), 427 US_FL_SINGLE_LUN),
428#endif 428#endif
429 429
@@ -431,56 +431,63 @@ UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208,
431UNUSUAL_DEV( 0x04e6, 0x0006, 0x0100, 0x0100, 431UNUSUAL_DEV( 0x04e6, 0x0006, 0x0100, 0x0100,
432 "SCM Microsystems Inc.", 432 "SCM Microsystems Inc.",
433 "eUSB MMC Adapter", 433 "eUSB MMC Adapter",
434 US_SC_SCSI, US_PR_CB, NULL, 434 USB_SC_SCSI, USB_PR_CB, NULL,
435 US_FL_SINGLE_LUN), 435 US_FL_SINGLE_LUN),
436 436
437/* Reported by Daniel Nouri <dpunktnpunkt@web.de> */ 437/* Reported by Daniel Nouri <dpunktnpunkt@web.de> */
438UNUSUAL_DEV( 0x04e6, 0x0006, 0x0205, 0x0205, 438UNUSUAL_DEV( 0x04e6, 0x0006, 0x0205, 0x0205,
439 "Shuttle", 439 "Shuttle",
440 "eUSB MMC Adapter", 440 "eUSB MMC Adapter",
441 US_SC_SCSI, US_PR_DEVICE, NULL, 441 USB_SC_SCSI, USB_PR_DEVICE, NULL,
442 US_FL_SINGLE_LUN), 442 US_FL_SINGLE_LUN),
443 443
444UNUSUAL_DEV( 0x04e6, 0x0007, 0x0100, 0x0200, 444UNUSUAL_DEV( 0x04e6, 0x0007, 0x0100, 0x0200,
445 "Sony", 445 "Sony",
446 "Hifd", 446 "Hifd",
447 US_SC_SCSI, US_PR_CB, NULL, 447 USB_SC_SCSI, USB_PR_CB, NULL,
448 US_FL_SINGLE_LUN), 448 US_FL_SINGLE_LUN),
449 449
450UNUSUAL_DEV( 0x04e6, 0x0009, 0x0200, 0x0200, 450UNUSUAL_DEV( 0x04e6, 0x0009, 0x0200, 0x0200,
451 "Shuttle", 451 "Shuttle",
452 "eUSB ATA/ATAPI Adapter", 452 "eUSB ATA/ATAPI Adapter",
453 US_SC_8020, US_PR_CB, NULL, 0), 453 USB_SC_8020, USB_PR_CB, NULL, 0),
454 454
455UNUSUAL_DEV( 0x04e6, 0x000a, 0x0200, 0x0200, 455UNUSUAL_DEV( 0x04e6, 0x000a, 0x0200, 0x0200,
456 "Shuttle", 456 "Shuttle",
457 "eUSB CompactFlash Adapter", 457 "eUSB CompactFlash Adapter",
458 US_SC_8020, US_PR_CB, NULL, 0), 458 USB_SC_8020, USB_PR_CB, NULL, 0),
459 459
460UNUSUAL_DEV( 0x04e6, 0x000B, 0x0100, 0x0100, 460UNUSUAL_DEV( 0x04e6, 0x000B, 0x0100, 0x0100,
461 "Shuttle", 461 "Shuttle",
462 "eUSCSI Bridge", 462 "eUSCSI Bridge",
463 US_SC_SCSI, US_PR_BULK, usb_stor_euscsi_init, 463 USB_SC_SCSI, USB_PR_BULK, usb_stor_euscsi_init,
464 US_FL_SCM_MULT_TARG ), 464 US_FL_SCM_MULT_TARG ),
465 465
466UNUSUAL_DEV( 0x04e6, 0x000C, 0x0100, 0x0100, 466UNUSUAL_DEV( 0x04e6, 0x000C, 0x0100, 0x0100,
467 "Shuttle", 467 "Shuttle",
468 "eUSCSI Bridge", 468 "eUSCSI Bridge",
469 US_SC_SCSI, US_PR_BULK, usb_stor_euscsi_init, 469 USB_SC_SCSI, USB_PR_BULK, usb_stor_euscsi_init,
470 US_FL_SCM_MULT_TARG ), 470 US_FL_SCM_MULT_TARG ),
471 471
472UNUSUAL_DEV( 0x04e6, 0x0101, 0x0200, 0x0200, 472UNUSUAL_DEV( 0x04e6, 0x0101, 0x0200, 0x0200,
473 "Shuttle", 473 "Shuttle",
474 "CD-RW Device", 474 "CD-RW Device",
475 US_SC_8020, US_PR_CB, NULL, 0), 475 USB_SC_8020, USB_PR_CB, NULL, 0),
476 476
477/* Reported by Dmitry Khlystov <adminimus@gmail.com> */ 477/* Reported by Dmitry Khlystov <adminimus@gmail.com> */
478UNUSUAL_DEV( 0x04e8, 0x507c, 0x0220, 0x0220, 478UNUSUAL_DEV( 0x04e8, 0x507c, 0x0220, 0x0220,
479 "Samsung", 479 "Samsung",
480 "YP-U3", 480 "YP-U3",
481 US_SC_DEVICE, US_PR_DEVICE, NULL, 481 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
482 US_FL_MAX_SECTORS_64), 482 US_FL_MAX_SECTORS_64),
483 483
484/* Reported by Vitaly Kuznetsov <vitty@altlinux.ru> */
485UNUSUAL_DEV( 0x04e8, 0x5122, 0x0000, 0x9999,
486 "Samsung",
487 "YP-CP3",
488 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
489 US_FL_MAX_SECTORS_64 | US_FL_BULK_IGNORE_TAG),
490
484/* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>. 491/* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>.
485 * Device uses standards-violating 32-byte Bulk Command Block Wrappers and 492 * Device uses standards-violating 32-byte Bulk Command Block Wrappers and
486 * reports itself as "Proprietary SCSI Bulk." Cf. device entry 0x084d:0x0011. 493 * reports itself as "Proprietary SCSI Bulk." Cf. device entry 0x084d:0x0011.
@@ -488,14 +495,14 @@ UNUSUAL_DEV( 0x04e8, 0x507c, 0x0220, 0x0220,
488UNUSUAL_DEV( 0x04fc, 0x80c2, 0x0100, 0x0100, 495UNUSUAL_DEV( 0x04fc, 0x80c2, 0x0100, 0x0100,
489 "Kobian Mercury", 496 "Kobian Mercury",
490 "Binocam DCB-132", 497 "Binocam DCB-132",
491 US_SC_DEVICE, US_PR_DEVICE, NULL, 498 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
492 US_FL_BULK32), 499 US_FL_BULK32),
493 500
494/* Reported by Bob Sass <rls@vectordb.com> -- only rev 1.33 tested */ 501/* Reported by Bob Sass <rls@vectordb.com> -- only rev 1.33 tested */
495UNUSUAL_DEV( 0x050d, 0x0115, 0x0133, 0x0133, 502UNUSUAL_DEV( 0x050d, 0x0115, 0x0133, 0x0133,
496 "Belkin", 503 "Belkin",
497 "USB SCSI Adaptor", 504 "USB SCSI Adaptor",
498 US_SC_SCSI, US_PR_BULK, usb_stor_euscsi_init, 505 USB_SC_SCSI, USB_PR_BULK, usb_stor_euscsi_init,
499 US_FL_SCM_MULT_TARG ), 506 US_FL_SCM_MULT_TARG ),
500 507
501/* Iomega Clik! Drive 508/* Iomega Clik! Drive
@@ -505,14 +512,14 @@ UNUSUAL_DEV( 0x050d, 0x0115, 0x0133, 0x0133,
505UNUSUAL_DEV( 0x0525, 0xa140, 0x0100, 0x0100, 512UNUSUAL_DEV( 0x0525, 0xa140, 0x0100, 0x0100,
506 "Iomega", 513 "Iomega",
507 "USB Clik! 40", 514 "USB Clik! 40",
508 US_SC_8070, US_PR_DEVICE, NULL, 515 USB_SC_8070, USB_PR_DEVICE, NULL,
509 US_FL_FIX_INQUIRY ), 516 US_FL_FIX_INQUIRY ),
510 517
511/* Added by Alan Stern <stern@rowland.harvard.edu> */ 518/* Added by Alan Stern <stern@rowland.harvard.edu> */
512COMPLIANT_DEV(0x0525, 0xa4a5, 0x0000, 0x9999, 519COMPLIANT_DEV(0x0525, 0xa4a5, 0x0000, 0x9999,
513 "Linux", 520 "Linux",
514 "File-backed Storage Gadget", 521 "File-backed Storage Gadget",
515 US_SC_DEVICE, US_PR_DEVICE, NULL, 522 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
516 US_FL_CAPACITY_OK ), 523 US_FL_CAPACITY_OK ),
517 524
518/* Yakumo Mega Image 37 525/* Yakumo Mega Image 37
@@ -520,7 +527,7 @@ COMPLIANT_DEV(0x0525, 0xa4a5, 0x0000, 0x9999,
520UNUSUAL_DEV( 0x052b, 0x1801, 0x0100, 0x0100, 527UNUSUAL_DEV( 0x052b, 0x1801, 0x0100, 0x0100,
521 "Tekom Technologies, Inc", 528 "Tekom Technologies, Inc",
522 "300_CAMERA", 529 "300_CAMERA",
523 US_SC_DEVICE, US_PR_DEVICE, NULL, 530 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
524 US_FL_IGNORE_RESIDUE ), 531 US_FL_IGNORE_RESIDUE ),
525 532
526/* Another Yakumo camera. 533/* Another Yakumo camera.
@@ -528,14 +535,14 @@ UNUSUAL_DEV( 0x052b, 0x1801, 0x0100, 0x0100,
528UNUSUAL_DEV( 0x052b, 0x1804, 0x0100, 0x0100, 535UNUSUAL_DEV( 0x052b, 0x1804, 0x0100, 0x0100,
529 "Tekom Technologies, Inc", 536 "Tekom Technologies, Inc",
530 "300_CAMERA", 537 "300_CAMERA",
531 US_SC_DEVICE, US_PR_DEVICE, NULL, 538 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
532 US_FL_IGNORE_RESIDUE ), 539 US_FL_IGNORE_RESIDUE ),
533 540
534/* Reported by Iacopo Spalletti <avvisi@spalletti.it> */ 541/* Reported by Iacopo Spalletti <avvisi@spalletti.it> */
535UNUSUAL_DEV( 0x052b, 0x1807, 0x0100, 0x0100, 542UNUSUAL_DEV( 0x052b, 0x1807, 0x0100, 0x0100,
536 "Tekom Technologies, Inc", 543 "Tekom Technologies, Inc",
537 "300_CAMERA", 544 "300_CAMERA",
538 US_SC_DEVICE, US_PR_DEVICE, NULL, 545 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
539 US_FL_IGNORE_RESIDUE ), 546 US_FL_IGNORE_RESIDUE ),
540 547
541/* Yakumo Mega Image 47 548/* Yakumo Mega Image 47
@@ -543,7 +550,7 @@ UNUSUAL_DEV( 0x052b, 0x1807, 0x0100, 0x0100,
543UNUSUAL_DEV( 0x052b, 0x1905, 0x0100, 0x0100, 550UNUSUAL_DEV( 0x052b, 0x1905, 0x0100, 0x0100,
544 "Tekom Technologies, Inc", 551 "Tekom Technologies, Inc",
545 "400_CAMERA", 552 "400_CAMERA",
546 US_SC_DEVICE, US_PR_DEVICE, NULL, 553 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
547 US_FL_IGNORE_RESIDUE ), 554 US_FL_IGNORE_RESIDUE ),
548 555
549/* Reported by Paul Ortyl <ortylp@3miasto.net> 556/* Reported by Paul Ortyl <ortylp@3miasto.net>
@@ -551,13 +558,13 @@ UNUSUAL_DEV( 0x052b, 0x1905, 0x0100, 0x0100,
551UNUSUAL_DEV( 0x052b, 0x1911, 0x0100, 0x0100, 558UNUSUAL_DEV( 0x052b, 0x1911, 0x0100, 0x0100,
552 "Tekom Technologies, Inc", 559 "Tekom Technologies, Inc",
553 "400_CAMERA", 560 "400_CAMERA",
554 US_SC_DEVICE, US_PR_DEVICE, NULL, 561 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
555 US_FL_IGNORE_RESIDUE ), 562 US_FL_IGNORE_RESIDUE ),
556 563
557UNUSUAL_DEV( 0x054c, 0x0010, 0x0106, 0x0450, 564UNUSUAL_DEV( 0x054c, 0x0010, 0x0106, 0x0450,
558 "Sony", 565 "Sony",
559 "DSC-S30/S70/S75/505V/F505/F707/F717/P8", 566 "DSC-S30/S70/S75/505V/F505/F707/F717/P8",
560 US_SC_SCSI, US_PR_DEVICE, NULL, 567 USB_SC_SCSI, USB_PR_DEVICE, NULL,
561 US_FL_SINGLE_LUN | US_FL_NOT_LOCKABLE | US_FL_NO_WP_DETECT ), 568 US_FL_SINGLE_LUN | US_FL_NOT_LOCKABLE | US_FL_NO_WP_DETECT ),
562 569
563/* Submitted by Lars Jacob <jacob.lars@googlemail.com> 570/* Submitted by Lars Jacob <jacob.lars@googlemail.com>
@@ -565,7 +572,7 @@ UNUSUAL_DEV( 0x054c, 0x0010, 0x0106, 0x0450,
565UNUSUAL_DEV( 0x054c, 0x0010, 0x0500, 0x0610, 572UNUSUAL_DEV( 0x054c, 0x0010, 0x0500, 0x0610,
566 "Sony", 573 "Sony",
567 "DSC-T1/T5/H5", 574 "DSC-T1/T5/H5",
568 US_SC_8070, US_PR_DEVICE, NULL, 575 USB_SC_8070, USB_PR_DEVICE, NULL,
569 US_FL_SINGLE_LUN ), 576 US_FL_SINGLE_LUN ),
570 577
571 578
@@ -573,88 +580,88 @@ UNUSUAL_DEV( 0x054c, 0x0010, 0x0500, 0x0610,
573UNUSUAL_DEV( 0x054c, 0x0025, 0x0100, 0x0100, 580UNUSUAL_DEV( 0x054c, 0x0025, 0x0100, 0x0100,
574 "Sony", 581 "Sony",
575 "Memorystick NW-MS7", 582 "Memorystick NW-MS7",
576 US_SC_DEVICE, US_PR_DEVICE, NULL, 583 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
577 US_FL_SINGLE_LUN ), 584 US_FL_SINGLE_LUN ),
578 585
579/* Submitted by Olaf Hering, <olh@suse.de> SuSE Bugzilla #49049 */ 586/* Submitted by Olaf Hering, <olh@suse.de> SuSE Bugzilla #49049 */
580UNUSUAL_DEV( 0x054c, 0x002c, 0x0501, 0x2000, 587UNUSUAL_DEV( 0x054c, 0x002c, 0x0501, 0x2000,
581 "Sony", 588 "Sony",
582 "USB Floppy Drive", 589 "USB Floppy Drive",
583 US_SC_DEVICE, US_PR_DEVICE, NULL, 590 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
584 US_FL_SINGLE_LUN ), 591 US_FL_SINGLE_LUN ),
585 592
586UNUSUAL_DEV( 0x054c, 0x002d, 0x0100, 0x0100, 593UNUSUAL_DEV( 0x054c, 0x002d, 0x0100, 0x0100,
587 "Sony", 594 "Sony",
588 "Memorystick MSAC-US1", 595 "Memorystick MSAC-US1",
589 US_SC_DEVICE, US_PR_DEVICE, NULL, 596 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
590 US_FL_SINGLE_LUN ), 597 US_FL_SINGLE_LUN ),
591 598
592/* Submitted by Klaus Mueller <k.mueller@intershop.de> */ 599/* Submitted by Klaus Mueller <k.mueller@intershop.de> */
593UNUSUAL_DEV( 0x054c, 0x002e, 0x0106, 0x0310, 600UNUSUAL_DEV( 0x054c, 0x002e, 0x0106, 0x0310,
594 "Sony", 601 "Sony",
595 "Handycam", 602 "Handycam",
596 US_SC_SCSI, US_PR_DEVICE, NULL, 603 USB_SC_SCSI, USB_PR_DEVICE, NULL,
597 US_FL_SINGLE_LUN ), 604 US_FL_SINGLE_LUN ),
598 605
599/* Submitted by Rajesh Kumble Nayak <nayak@obs-nice.fr> */ 606/* Submitted by Rajesh Kumble Nayak <nayak@obs-nice.fr> */
600UNUSUAL_DEV( 0x054c, 0x002e, 0x0500, 0x0500, 607UNUSUAL_DEV( 0x054c, 0x002e, 0x0500, 0x0500,
601 "Sony", 608 "Sony",
602 "Handycam HC-85", 609 "Handycam HC-85",
603 US_SC_UFI, US_PR_DEVICE, NULL, 610 USB_SC_UFI, USB_PR_DEVICE, NULL,
604 US_FL_SINGLE_LUN ), 611 US_FL_SINGLE_LUN ),
605 612
606UNUSUAL_DEV( 0x054c, 0x0032, 0x0000, 0x9999, 613UNUSUAL_DEV( 0x054c, 0x0032, 0x0000, 0x9999,
607 "Sony", 614 "Sony",
608 "Memorystick MSC-U01N", 615 "Memorystick MSC-U01N",
609 US_SC_DEVICE, US_PR_DEVICE, NULL, 616 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
610 US_FL_SINGLE_LUN ), 617 US_FL_SINGLE_LUN ),
611 618
612/* Submitted by Michal Mlotek <mlotek@foobar.pl> */ 619/* Submitted by Michal Mlotek <mlotek@foobar.pl> */
613UNUSUAL_DEV( 0x054c, 0x0058, 0x0000, 0x9999, 620UNUSUAL_DEV( 0x054c, 0x0058, 0x0000, 0x9999,
614 "Sony", 621 "Sony",
615 "PEG N760c Memorystick", 622 "PEG N760c Memorystick",
616 US_SC_DEVICE, US_PR_DEVICE, NULL, 623 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
617 US_FL_FIX_INQUIRY ), 624 US_FL_FIX_INQUIRY ),
618 625
619UNUSUAL_DEV( 0x054c, 0x0069, 0x0000, 0x9999, 626UNUSUAL_DEV( 0x054c, 0x0069, 0x0000, 0x9999,
620 "Sony", 627 "Sony",
621 "Memorystick MSC-U03", 628 "Memorystick MSC-U03",
622 US_SC_UFI, US_PR_CB, NULL, 629 USB_SC_UFI, USB_PR_CB, NULL,
623 US_FL_SINGLE_LUN ), 630 US_FL_SINGLE_LUN ),
624 631
625/* Submitted by Nathan Babb <nathan@lexi.com> */ 632/* Submitted by Nathan Babb <nathan@lexi.com> */
626UNUSUAL_DEV( 0x054c, 0x006d, 0x0000, 0x9999, 633UNUSUAL_DEV( 0x054c, 0x006d, 0x0000, 0x9999,
627 "Sony", 634 "Sony",
628 "PEG Mass Storage", 635 "PEG Mass Storage",
629 US_SC_DEVICE, US_PR_DEVICE, NULL, 636 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
630 US_FL_FIX_INQUIRY ), 637 US_FL_FIX_INQUIRY ),
631 638
632/* Submitted by Frank Engel <frankie@cse.unsw.edu.au> */ 639/* Submitted by Frank Engel <frankie@cse.unsw.edu.au> */
633UNUSUAL_DEV( 0x054c, 0x0099, 0x0000, 0x9999, 640UNUSUAL_DEV( 0x054c, 0x0099, 0x0000, 0x9999,
634 "Sony", 641 "Sony",
635 "PEG Mass Storage", 642 "PEG Mass Storage",
636 US_SC_DEVICE, US_PR_DEVICE, NULL, 643 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
637 US_FL_FIX_INQUIRY ), 644 US_FL_FIX_INQUIRY ),
638 645
639/* Submitted by Mike Alborn <malborn@deandra.homeip.net> */ 646/* Submitted by Mike Alborn <malborn@deandra.homeip.net> */
640UNUSUAL_DEV( 0x054c, 0x016a, 0x0000, 0x9999, 647UNUSUAL_DEV( 0x054c, 0x016a, 0x0000, 0x9999,
641 "Sony", 648 "Sony",
642 "PEG Mass Storage", 649 "PEG Mass Storage",
643 US_SC_DEVICE, US_PR_DEVICE, NULL, 650 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
644 US_FL_FIX_INQUIRY ), 651 US_FL_FIX_INQUIRY ),
645 652
646/* floppy reports multiple luns */ 653/* floppy reports multiple luns */
647UNUSUAL_DEV( 0x055d, 0x2020, 0x0000, 0x0210, 654UNUSUAL_DEV( 0x055d, 0x2020, 0x0000, 0x0210,
648 "SAMSUNG", 655 "SAMSUNG",
649 "SFD-321U [FW 0C]", 656 "SFD-321U [FW 0C]",
650 US_SC_DEVICE, US_PR_DEVICE, NULL, 657 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
651 US_FL_SINGLE_LUN ), 658 US_FL_SINGLE_LUN ),
652 659
653/* We keep this entry to force the transport; firmware 3.00 and later is ok. */ 660/* We keep this entry to force the transport; firmware 3.00 and later is ok. */
654UNUSUAL_DEV( 0x057b, 0x0000, 0x0000, 0x0299, 661UNUSUAL_DEV( 0x057b, 0x0000, 0x0000, 0x0299,
655 "Y-E Data", 662 "Y-E Data",
656 "Flashbuster-U", 663 "Flashbuster-U",
657 US_SC_DEVICE, US_PR_CB, NULL, 664 USB_SC_DEVICE, USB_PR_CB, NULL,
658 US_FL_SINGLE_LUN), 665 US_FL_SINGLE_LUN),
659 666
660/* Reported by Johann Cardon <johann.cardon@free.fr> 667/* Reported by Johann Cardon <johann.cardon@free.fr>
@@ -664,20 +671,20 @@ UNUSUAL_DEV( 0x057b, 0x0000, 0x0000, 0x0299,
664UNUSUAL_DEV( 0x057b, 0x0022, 0x0000, 0x9999, 671UNUSUAL_DEV( 0x057b, 0x0022, 0x0000, 0x9999,
665 "Y-E Data", 672 "Y-E Data",
666 "Silicon Media R/W", 673 "Silicon Media R/W",
667 US_SC_DEVICE, US_PR_DEVICE, NULL, 0), 674 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 0),
668 675
669/* Reported by RTE <raszilki@yandex.ru> */ 676/* Reported by RTE <raszilki@yandex.ru> */
670UNUSUAL_DEV( 0x058f, 0x6387, 0x0141, 0x0141, 677UNUSUAL_DEV( 0x058f, 0x6387, 0x0141, 0x0141,
671 "JetFlash", 678 "JetFlash",
672 "TS1GJF2A/120", 679 "TS1GJF2A/120",
673 US_SC_DEVICE, US_PR_DEVICE, NULL, 680 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
674 US_FL_MAX_SECTORS_64 ), 681 US_FL_MAX_SECTORS_64 ),
675 682
676/* Fabrizio Fellini <fello@libero.it> */ 683/* Fabrizio Fellini <fello@libero.it> */
677UNUSUAL_DEV( 0x0595, 0x4343, 0x0000, 0x2210, 684UNUSUAL_DEV( 0x0595, 0x4343, 0x0000, 0x2210,
678 "Fujifilm", 685 "Fujifilm",
679 "Digital Camera EX-20 DSC", 686 "Digital Camera EX-20 DSC",
680 US_SC_8070, US_PR_DEVICE, NULL, 0 ), 687 USB_SC_8070, USB_PR_DEVICE, NULL, 0 ),
681 688
682/* Reported by Andre Welter <a.r.welter@gmx.de> 689/* Reported by Andre Welter <a.r.welter@gmx.de>
683 * This antique device predates the release of the Bulk-only Transport 690 * This antique device predates the release of the Bulk-only Transport
@@ -688,14 +695,14 @@ UNUSUAL_DEV( 0x0595, 0x4343, 0x0000, 0x2210,
688UNUSUAL_DEV( 0x059b, 0x0001, 0x0100, 0x0100, 695UNUSUAL_DEV( 0x059b, 0x0001, 0x0100, 0x0100,
689 "Iomega", 696 "Iomega",
690 "ZIP 100", 697 "ZIP 100",
691 US_SC_DEVICE, US_PR_DEVICE, NULL, 698 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
692 US_FL_SINGLE_LUN ), 699 US_FL_SINGLE_LUN ),
693 700
694/* Reported by <Hendryk.Pfeiffer@gmx.de> */ 701/* Reported by <Hendryk.Pfeiffer@gmx.de> */
695UNUSUAL_DEV( 0x059f, 0x0643, 0x0000, 0x0000, 702UNUSUAL_DEV( 0x059f, 0x0643, 0x0000, 0x0000,
696 "LaCie", 703 "LaCie",
697 "DVD+-RW", 704 "DVD+-RW",
698 US_SC_DEVICE, US_PR_DEVICE, NULL, 705 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
699 US_FL_GO_SLOW ), 706 US_FL_GO_SLOW ),
700 707
701/* Submitted by Joel Bourquard <numlock@freesurf.ch> 708/* Submitted by Joel Bourquard <numlock@freesurf.ch>
@@ -705,7 +712,7 @@ UNUSUAL_DEV( 0x059f, 0x0643, 0x0000, 0x0000,
705UNUSUAL_DEV( 0x05ab, 0x0060, 0x1104, 0x1110, 712UNUSUAL_DEV( 0x05ab, 0x0060, 0x1104, 0x1110,
706 "In-System", 713 "In-System",
707 "PyroGate External CD-ROM Enclosure (FCD-523)", 714 "PyroGate External CD-ROM Enclosure (FCD-523)",
708 US_SC_SCSI, US_PR_BULK, NULL, 715 USB_SC_SCSI, USB_PR_BULK, NULL,
709 US_FL_NEED_OVERRIDE ), 716 US_FL_NEED_OVERRIDE ),
710 717
711/* Submitted by Sven Anderson <sven-linux@anderson.de> 718/* Submitted by Sven Anderson <sven-linux@anderson.de>
@@ -717,26 +724,26 @@ UNUSUAL_DEV( 0x05ab, 0x0060, 0x1104, 0x1110,
717UNUSUAL_DEV( 0x05ac, 0x1202, 0x0000, 0x9999, 724UNUSUAL_DEV( 0x05ac, 0x1202, 0x0000, 0x9999,
718 "Apple", 725 "Apple",
719 "iPod", 726 "iPod",
720 US_SC_DEVICE, US_PR_DEVICE, NULL, 727 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
721 US_FL_FIX_CAPACITY ), 728 US_FL_FIX_CAPACITY ),
722 729
723/* Reported by Avi Kivity <avi@argo.co.il> */ 730/* Reported by Avi Kivity <avi@argo.co.il> */
724UNUSUAL_DEV( 0x05ac, 0x1203, 0x0000, 0x9999, 731UNUSUAL_DEV( 0x05ac, 0x1203, 0x0000, 0x9999,
725 "Apple", 732 "Apple",
726 "iPod", 733 "iPod",
727 US_SC_DEVICE, US_PR_DEVICE, NULL, 734 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
728 US_FL_FIX_CAPACITY ), 735 US_FL_FIX_CAPACITY ),
729 736
730UNUSUAL_DEV( 0x05ac, 0x1204, 0x0000, 0x9999, 737UNUSUAL_DEV( 0x05ac, 0x1204, 0x0000, 0x9999,
731 "Apple", 738 "Apple",
732 "iPod", 739 "iPod",
733 US_SC_DEVICE, US_PR_DEVICE, NULL, 740 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
734 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ), 741 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ),
735 742
736UNUSUAL_DEV( 0x05ac, 0x1205, 0x0000, 0x9999, 743UNUSUAL_DEV( 0x05ac, 0x1205, 0x0000, 0x9999,
737 "Apple", 744 "Apple",
738 "iPod", 745 "iPod",
739 US_SC_DEVICE, US_PR_DEVICE, NULL, 746 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
740 US_FL_FIX_CAPACITY ), 747 US_FL_FIX_CAPACITY ),
741 748
742/* 749/*
@@ -746,7 +753,7 @@ UNUSUAL_DEV( 0x05ac, 0x1205, 0x0000, 0x9999,
746UNUSUAL_DEV( 0x05ac, 0x120a, 0x0000, 0x9999, 753UNUSUAL_DEV( 0x05ac, 0x120a, 0x0000, 0x9999,
747 "Apple", 754 "Apple",
748 "iPod", 755 "iPod",
749 US_SC_DEVICE, US_PR_DEVICE, NULL, 756 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
750 US_FL_FIX_CAPACITY ), 757 US_FL_FIX_CAPACITY ),
751 758
752/* Reported by Dan Williams <dcbw@redhat.com> 759/* Reported by Dan Williams <dcbw@redhat.com>
@@ -758,14 +765,14 @@ UNUSUAL_DEV( 0x05ac, 0x120a, 0x0000, 0x9999,
758UNUSUAL_DEV( 0x05c6, 0x1000, 0x0000, 0x9999, 765UNUSUAL_DEV( 0x05c6, 0x1000, 0x0000, 0x9999,
759 "Option N.V.", 766 "Option N.V.",
760 "Mass Storage", 767 "Mass Storage",
761 US_SC_DEVICE, US_PR_DEVICE, option_ms_init, 768 USB_SC_DEVICE, USB_PR_DEVICE, option_ms_init,
762 0), 769 0),
763 770
764/* Reported by Blake Matheny <bmatheny@purdue.edu> */ 771/* Reported by Blake Matheny <bmatheny@purdue.edu> */
765UNUSUAL_DEV( 0x05dc, 0xb002, 0x0000, 0x0113, 772UNUSUAL_DEV( 0x05dc, 0xb002, 0x0000, 0x0113,
766 "Lexar", 773 "Lexar",
767 "USB CF Reader", 774 "USB CF Reader",
768 US_SC_DEVICE, US_PR_DEVICE, NULL, 775 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
769 US_FL_FIX_INQUIRY ), 776 US_FL_FIX_INQUIRY ),
770 777
771/* The following two entries are for a Genesys USB to IDE 778/* The following two entries are for a Genesys USB to IDE
@@ -782,20 +789,20 @@ UNUSUAL_DEV( 0x05dc, 0xb002, 0x0000, 0x0113,
782UNUSUAL_DEV( 0x05e3, 0x0701, 0x0000, 0xffff, 789UNUSUAL_DEV( 0x05e3, 0x0701, 0x0000, 0xffff,
783 "Genesys Logic", 790 "Genesys Logic",
784 "USB to IDE Optical", 791 "USB to IDE Optical",
785 US_SC_DEVICE, US_PR_DEVICE, NULL, 792 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
786 US_FL_GO_SLOW | US_FL_MAX_SECTORS_64 | US_FL_IGNORE_RESIDUE ), 793 US_FL_GO_SLOW | US_FL_MAX_SECTORS_64 | US_FL_IGNORE_RESIDUE ),
787 794
788UNUSUAL_DEV( 0x05e3, 0x0702, 0x0000, 0xffff, 795UNUSUAL_DEV( 0x05e3, 0x0702, 0x0000, 0xffff,
789 "Genesys Logic", 796 "Genesys Logic",
790 "USB to IDE Disk", 797 "USB to IDE Disk",
791 US_SC_DEVICE, US_PR_DEVICE, NULL, 798 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
792 US_FL_GO_SLOW | US_FL_MAX_SECTORS_64 | US_FL_IGNORE_RESIDUE ), 799 US_FL_GO_SLOW | US_FL_MAX_SECTORS_64 | US_FL_IGNORE_RESIDUE ),
793 800
794/* Reported by Ben Efros <ben@pc-doctor.com> */ 801/* Reported by Ben Efros <ben@pc-doctor.com> */
795UNUSUAL_DEV( 0x05e3, 0x0723, 0x9451, 0x9451, 802UNUSUAL_DEV( 0x05e3, 0x0723, 0x9451, 0x9451,
796 "Genesys Logic", 803 "Genesys Logic",
797 "USB to SATA", 804 "USB to SATA",
798 US_SC_DEVICE, US_PR_DEVICE, NULL, 805 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
799 US_FL_SANE_SENSE ), 806 US_FL_SANE_SENSE ),
800 807
801/* Reported by Hanno Boeck <hanno@gmx.de> 808/* Reported by Hanno Boeck <hanno@gmx.de>
@@ -803,33 +810,33 @@ UNUSUAL_DEV( 0x05e3, 0x0723, 0x9451, 0x9451,
803UNUSUAL_DEV( 0x0636, 0x0003, 0x0000, 0x9999, 810UNUSUAL_DEV( 0x0636, 0x0003, 0x0000, 0x9999,
804 "Vivitar", 811 "Vivitar",
805 "Vivicam 35Xx", 812 "Vivicam 35Xx",
806 US_SC_SCSI, US_PR_BULK, NULL, 813 USB_SC_SCSI, USB_PR_BULK, NULL,
807 US_FL_FIX_INQUIRY ), 814 US_FL_FIX_INQUIRY ),
808 815
809UNUSUAL_DEV( 0x0644, 0x0000, 0x0100, 0x0100, 816UNUSUAL_DEV( 0x0644, 0x0000, 0x0100, 0x0100,
810 "TEAC", 817 "TEAC",
811 "Floppy Drive", 818 "Floppy Drive",
812 US_SC_UFI, US_PR_CB, NULL, 0 ), 819 USB_SC_UFI, USB_PR_CB, NULL, 0 ),
813 820
814/* Reported by Darsen Lu <darsen@micro.ee.nthu.edu.tw> */ 821/* Reported by Darsen Lu <darsen@micro.ee.nthu.edu.tw> */
815UNUSUAL_DEV( 0x066f, 0x8000, 0x0001, 0x0001, 822UNUSUAL_DEV( 0x066f, 0x8000, 0x0001, 0x0001,
816 "SigmaTel", 823 "SigmaTel",
817 "USBMSC Audio Player", 824 "USBMSC Audio Player",
818 US_SC_DEVICE, US_PR_DEVICE, NULL, 825 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
819 US_FL_FIX_CAPACITY ), 826 US_FL_FIX_CAPACITY ),
820 827
821/* Reported by Daniel Kukula <daniel.kuku@gmail.com> */ 828/* Reported by Daniel Kukula <daniel.kuku@gmail.com> */
822UNUSUAL_DEV( 0x067b, 0x1063, 0x0100, 0x0100, 829UNUSUAL_DEV( 0x067b, 0x1063, 0x0100, 0x0100,
823 "Prolific Technology, Inc.", 830 "Prolific Technology, Inc.",
824 "Prolific Storage Gadget", 831 "Prolific Storage Gadget",
825 US_SC_DEVICE, US_PR_DEVICE, NULL, 832 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
826 US_FL_BAD_SENSE ), 833 US_FL_BAD_SENSE ),
827 834
828/* Reported by Rogerio Brito <rbrito@ime.usp.br> */ 835/* Reported by Rogerio Brito <rbrito@ime.usp.br> */
829UNUSUAL_DEV( 0x067b, 0x2317, 0x0001, 0x001, 836UNUSUAL_DEV( 0x067b, 0x2317, 0x0001, 0x001,
830 "Prolific Technology, Inc.", 837 "Prolific Technology, Inc.",
831 "Mass Storage Device", 838 "Mass Storage Device",
832 US_SC_DEVICE, US_PR_DEVICE, NULL, 839 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
833 US_FL_NOT_LOCKABLE ), 840 US_FL_NOT_LOCKABLE ),
834 841
835/* Reported by Richard -=[]=- <micro_flyer@hotmail.com> */ 842/* Reported by Richard -=[]=- <micro_flyer@hotmail.com> */
@@ -838,46 +845,47 @@ UNUSUAL_DEV( 0x067b, 0x2317, 0x0001, 0x001,
838UNUSUAL_DEV( 0x067b, 0x2507, 0x0001, 0x0100, 845UNUSUAL_DEV( 0x067b, 0x2507, 0x0001, 0x0100,
839 "Prolific Technology Inc.", 846 "Prolific Technology Inc.",
840 "Mass Storage Device", 847 "Mass Storage Device",
841 US_SC_DEVICE, US_PR_DEVICE, NULL, 848 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
842 US_FL_FIX_CAPACITY | US_FL_GO_SLOW ), 849 US_FL_FIX_CAPACITY | US_FL_GO_SLOW ),
843 850
844/* Reported by Alex Butcher <alex.butcher@assursys.co.uk> */ 851/* Reported by Alex Butcher <alex.butcher@assursys.co.uk> */
845UNUSUAL_DEV( 0x067b, 0x3507, 0x0001, 0x0101, 852UNUSUAL_DEV( 0x067b, 0x3507, 0x0001, 0x0101,
846 "Prolific Technology Inc.", 853 "Prolific Technology Inc.",
847 "ATAPI-6 Bridge Controller", 854 "ATAPI-6 Bridge Controller",
848 US_SC_DEVICE, US_PR_DEVICE, NULL, 855 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
849 US_FL_FIX_CAPACITY | US_FL_GO_SLOW ), 856 US_FL_FIX_CAPACITY | US_FL_GO_SLOW ),
850 857
851/* Submitted by Benny Sjostrand <benny@hostmobility.com> */ 858/* Submitted by Benny Sjostrand <benny@hostmobility.com> */
852UNUSUAL_DEV( 0x0686, 0x4011, 0x0001, 0x0001, 859UNUSUAL_DEV( 0x0686, 0x4011, 0x0001, 0x0001,
853 "Minolta", 860 "Minolta",
854 "Dimage F300", 861 "Dimage F300",
855 US_SC_SCSI, US_PR_BULK, NULL, 0 ), 862 USB_SC_SCSI, USB_PR_BULK, NULL, 0 ),
856 863
857/* Reported by Miguel A. Fosas <amn3s1a@ono.com> */ 864/* Reported by Miguel A. Fosas <amn3s1a@ono.com> */
858UNUSUAL_DEV( 0x0686, 0x4017, 0x0001, 0x0001, 865UNUSUAL_DEV( 0x0686, 0x4017, 0x0001, 0x0001,
859 "Minolta", 866 "Minolta",
860 "DIMAGE E223", 867 "DIMAGE E223",
861 US_SC_SCSI, US_PR_DEVICE, NULL, 0 ), 868 USB_SC_SCSI, USB_PR_DEVICE, NULL, 0 ),
862 869
863UNUSUAL_DEV( 0x0693, 0x0005, 0x0100, 0x0100, 870UNUSUAL_DEV( 0x0693, 0x0005, 0x0100, 0x0100,
864 "Hagiwara", 871 "Hagiwara",
865 "Flashgate", 872 "Flashgate",
866 US_SC_SCSI, US_PR_BULK, NULL, 0 ), 873 USB_SC_SCSI, USB_PR_BULK, NULL, 0 ),
867 874
868/* Reported by David Hamilton <niftimusmaximus@lycos.com> */ 875/* Reported by David Hamilton <niftimusmaximus@lycos.com> */
869UNUSUAL_DEV( 0x069b, 0x3004, 0x0001, 0x0001, 876UNUSUAL_DEV( 0x069b, 0x3004, 0x0001, 0x0001,
870 "Thomson Multimedia Inc.", 877 "Thomson Multimedia Inc.",
871 "RCA RD1080 MP3 Player", 878 "RCA RD1080 MP3 Player",
872 US_SC_DEVICE, US_PR_DEVICE, NULL, 879 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
873 US_FL_FIX_CAPACITY ), 880 US_FL_FIX_CAPACITY ),
874 881
875/* Reported by Adrian Pilchowiec <adi1981@epf.pl> */ 882/* Reported by Adrian Pilchowiec <adi1981@epf.pl> */
876UNUSUAL_DEV( 0x071b, 0x3203, 0x0000, 0x0000, 883UNUSUAL_DEV( 0x071b, 0x3203, 0x0000, 0x0000,
877 "RockChip", 884 "RockChip",
878 "MP3", 885 "MP3",
879 US_SC_DEVICE, US_PR_DEVICE, NULL, 886 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
880 US_FL_NO_WP_DETECT | US_FL_MAX_SECTORS_64), 887 US_FL_NO_WP_DETECT | US_FL_MAX_SECTORS_64 |
888 US_FL_NO_READ_CAPACITY_16),
881 889
882/* Reported by Jean-Baptiste Onofre <jb@nanthrax.net> 890/* Reported by Jean-Baptiste Onofre <jb@nanthrax.net>
883 * Support the following product : 891 * Support the following product :
@@ -886,7 +894,7 @@ UNUSUAL_DEV( 0x071b, 0x3203, 0x0000, 0x0000,
886UNUSUAL_DEV( 0x071b, 0x32bb, 0x0000, 0x0000, 894UNUSUAL_DEV( 0x071b, 0x32bb, 0x0000, 0x0000,
887 "RockChip", 895 "RockChip",
888 "MTP", 896 "MTP",
889 US_SC_DEVICE, US_PR_DEVICE, NULL, 897 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
890 US_FL_NO_WP_DETECT | US_FL_MAX_SECTORS_64), 898 US_FL_NO_WP_DETECT | US_FL_MAX_SECTORS_64),
891 899
892/* Reported by Massimiliano Ghilardi <massimiliano.ghilardi@gmail.com> 900/* Reported by Massimiliano Ghilardi <massimiliano.ghilardi@gmail.com>
@@ -902,59 +910,59 @@ UNUSUAL_DEV( 0x071b, 0x32bb, 0x0000, 0x0000,
902UNUSUAL_DEV( 0x071b, 0x3203, 0x0100, 0x0100, 910UNUSUAL_DEV( 0x071b, 0x3203, 0x0100, 0x0100,
903 "RockChip", 911 "RockChip",
904 "ROCK MP3", 912 "ROCK MP3",
905 US_SC_DEVICE, US_PR_DEVICE, NULL, 913 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
906 US_FL_MAX_SECTORS_64), 914 US_FL_MAX_SECTORS_64),
907 915
908/* Reported by Olivier Blondeau <zeitoun@gmail.com> */ 916/* Reported by Olivier Blondeau <zeitoun@gmail.com> */
909UNUSUAL_DEV( 0x0727, 0x0306, 0x0100, 0x0100, 917UNUSUAL_DEV( 0x0727, 0x0306, 0x0100, 0x0100,
910 "ATMEL", 918 "ATMEL",
911 "SND1 Storage", 919 "SND1 Storage",
912 US_SC_DEVICE, US_PR_DEVICE, NULL, 920 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
913 US_FL_IGNORE_RESIDUE), 921 US_FL_IGNORE_RESIDUE),
914 922
915/* Submitted by Roman Hodek <roman@hodek.net> */ 923/* Submitted by Roman Hodek <roman@hodek.net> */
916UNUSUAL_DEV( 0x0781, 0x0001, 0x0200, 0x0200, 924UNUSUAL_DEV( 0x0781, 0x0001, 0x0200, 0x0200,
917 "Sandisk", 925 "Sandisk",
918 "ImageMate SDDR-05a", 926 "ImageMate SDDR-05a",
919 US_SC_SCSI, US_PR_CB, NULL, 927 USB_SC_SCSI, USB_PR_CB, NULL,
920 US_FL_SINGLE_LUN ), 928 US_FL_SINGLE_LUN ),
921 929
922UNUSUAL_DEV( 0x0781, 0x0002, 0x0009, 0x0009, 930UNUSUAL_DEV( 0x0781, 0x0002, 0x0009, 0x0009,
923 "SanDisk Corporation", 931 "SanDisk Corporation",
924 "ImageMate CompactFlash USB", 932 "ImageMate CompactFlash USB",
925 US_SC_DEVICE, US_PR_DEVICE, NULL, 933 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
926 US_FL_FIX_CAPACITY ), 934 US_FL_FIX_CAPACITY ),
927 935
928UNUSUAL_DEV( 0x0781, 0x0100, 0x0100, 0x0100, 936UNUSUAL_DEV( 0x0781, 0x0100, 0x0100, 0x0100,
929 "Sandisk", 937 "Sandisk",
930 "ImageMate SDDR-12", 938 "ImageMate SDDR-12",
931 US_SC_SCSI, US_PR_CB, NULL, 939 USB_SC_SCSI, USB_PR_CB, NULL,
932 US_FL_SINGLE_LUN ), 940 US_FL_SINGLE_LUN ),
933 941
934/* Reported by Eero Volotinen <eero@ping-viini.org> */ 942/* Reported by Eero Volotinen <eero@ping-viini.org> */
935UNUSUAL_DEV( 0x07ab, 0xfccd, 0x0000, 0x9999, 943UNUSUAL_DEV( 0x07ab, 0xfccd, 0x0000, 0x9999,
936 "Freecom Technologies", 944 "Freecom Technologies",
937 "FHD-Classic", 945 "FHD-Classic",
938 US_SC_DEVICE, US_PR_DEVICE, NULL, 946 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
939 US_FL_FIX_CAPACITY), 947 US_FL_FIX_CAPACITY),
940 948
941UNUSUAL_DEV( 0x07af, 0x0004, 0x0100, 0x0133, 949UNUSUAL_DEV( 0x07af, 0x0004, 0x0100, 0x0133,
942 "Microtech", 950 "Microtech",
943 "USB-SCSI-DB25", 951 "USB-SCSI-DB25",
944 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init, 952 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_euscsi_init,
945 US_FL_SCM_MULT_TARG ), 953 US_FL_SCM_MULT_TARG ),
946 954
947UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100, 955UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100,
948 "Microtech", 956 "Microtech",
949 "USB-SCSI-HD50", 957 "USB-SCSI-HD50",
950 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init, 958 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_euscsi_init,
951 US_FL_SCM_MULT_TARG ), 959 US_FL_SCM_MULT_TARG ),
952 960
953#ifdef NO_SDDR09 961#ifdef NO_SDDR09
954UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100, 962UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100,
955 "Microtech", 963 "Microtech",
956 "CameraMate", 964 "CameraMate",
957 US_SC_SCSI, US_PR_CB, NULL, 965 USB_SC_SCSI, USB_PR_CB, NULL,
958 US_FL_SINGLE_LUN ), 966 US_FL_SINGLE_LUN ),
959#endif 967#endif
960 968
@@ -967,7 +975,7 @@ UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100,
967UNUSUAL_DEV( 0x07c4, 0xa400, 0x0000, 0xffff, 975UNUSUAL_DEV( 0x07c4, 0xa400, 0x0000, 0xffff,
968 "Datafab", 976 "Datafab",
969 "KECF-USB", 977 "KECF-USB",
970 US_SC_DEVICE, US_PR_DEVICE, NULL, 978 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
971 US_FL_FIX_INQUIRY | US_FL_FIX_CAPACITY ), 979 US_FL_FIX_INQUIRY | US_FL_FIX_CAPACITY ),
972 980
973/* Reported by Rauch Wolke <rauchwolke@gmx.net> 981/* Reported by Rauch Wolke <rauchwolke@gmx.net>
@@ -976,7 +984,7 @@ UNUSUAL_DEV( 0x07c4, 0xa400, 0x0000, 0xffff,
976UNUSUAL_DEV( 0x07c4, 0xa4a5, 0x0000, 0xffff, 984UNUSUAL_DEV( 0x07c4, 0xa4a5, 0x0000, 0xffff,
977 "Simple Tech/Datafab", 985 "Simple Tech/Datafab",
978 "CF+SM Reader", 986 "CF+SM Reader",
979 US_SC_DEVICE, US_PR_DEVICE, NULL, 987 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
980 US_FL_IGNORE_RESIDUE | US_FL_MAX_SECTORS_64 ), 988 US_FL_IGNORE_RESIDUE | US_FL_MAX_SECTORS_64 ),
981 989
982/* Casio QV 2x00/3x00/4000/8000 digital still cameras are not conformant 990/* Casio QV 2x00/3x00/4000/8000 digital still cameras are not conformant
@@ -986,42 +994,42 @@ UNUSUAL_DEV( 0x07c4, 0xa4a5, 0x0000, 0xffff,
986 * - They don't like the INQUIRY command. So we must handle this command 994 * - They don't like the INQUIRY command. So we must handle this command
987 * of the SCSI layer ourselves. 995 * of the SCSI layer ourselves.
988 * - Some cameras with idProduct=0x1001 and bcdDevice=0x1000 have 996 * - Some cameras with idProduct=0x1001 and bcdDevice=0x1000 have
989 * bInterfaceProtocol=0x00 (US_PR_CBI) while others have 0x01 (US_PR_CB). 997 * bInterfaceProtocol=0x00 (USB_PR_CBI) while others have 0x01 (USB_PR_CB).
990 * So don't remove the US_PR_CB override! 998 * So don't remove the USB_PR_CB override!
991 * - Cameras with bcdDevice=0x9009 require the US_SC_8070 override. 999 * - Cameras with bcdDevice=0x9009 require the USB_SC_8070 override.
992 */ 1000 */
993UNUSUAL_DEV( 0x07cf, 0x1001, 0x1000, 0x9999, 1001UNUSUAL_DEV( 0x07cf, 0x1001, 0x1000, 0x9999,
994 "Casio", 1002 "Casio",
995 "QV DigitalCamera", 1003 "QV DigitalCamera",
996 US_SC_8070, US_PR_CB, NULL, 1004 USB_SC_8070, USB_PR_CB, NULL,
997 US_FL_NEED_OVERRIDE | US_FL_FIX_INQUIRY ), 1005 US_FL_NEED_OVERRIDE | US_FL_FIX_INQUIRY ),
998 1006
999/* Submitted by Hartmut Wahl <hwahl@hwahl.de>*/ 1007/* Submitted by Hartmut Wahl <hwahl@hwahl.de>*/
1000UNUSUAL_DEV( 0x0839, 0x000a, 0x0001, 0x0001, 1008UNUSUAL_DEV( 0x0839, 0x000a, 0x0001, 0x0001,
1001 "Samsung", 1009 "Samsung",
1002 "Digimax 410", 1010 "Digimax 410",
1003 US_SC_DEVICE, US_PR_DEVICE, NULL, 1011 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1004 US_FL_FIX_INQUIRY), 1012 US_FL_FIX_INQUIRY),
1005 1013
1006/* Reported by Luciano Rocha <luciano@eurotux.com> */ 1014/* Reported by Luciano Rocha <luciano@eurotux.com> */
1007UNUSUAL_DEV( 0x0840, 0x0082, 0x0001, 0x0001, 1015UNUSUAL_DEV( 0x0840, 0x0082, 0x0001, 0x0001,
1008 "Argosy", 1016 "Argosy",
1009 "Storage", 1017 "Storage",
1010 US_SC_DEVICE, US_PR_DEVICE, NULL, 1018 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1011 US_FL_FIX_CAPACITY), 1019 US_FL_FIX_CAPACITY),
1012 1020
1013/* Reported and patched by Nguyen Anh Quynh <aquynh@gmail.com> */ 1021/* Reported and patched by Nguyen Anh Quynh <aquynh@gmail.com> */
1014UNUSUAL_DEV( 0x0840, 0x0084, 0x0001, 0x0001, 1022UNUSUAL_DEV( 0x0840, 0x0084, 0x0001, 0x0001,
1015 "Argosy", 1023 "Argosy",
1016 "Storage", 1024 "Storage",
1017 US_SC_DEVICE, US_PR_DEVICE, NULL, 1025 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1018 US_FL_FIX_CAPACITY), 1026 US_FL_FIX_CAPACITY),
1019 1027
1020/* Reported by Martijn Hijdra <martijn.hijdra@gmail.com> */ 1028/* Reported by Martijn Hijdra <martijn.hijdra@gmail.com> */
1021UNUSUAL_DEV( 0x0840, 0x0085, 0x0001, 0x0001, 1029UNUSUAL_DEV( 0x0840, 0x0085, 0x0001, 0x0001,
1022 "Argosy", 1030 "Argosy",
1023 "Storage", 1031 "Storage",
1024 US_SC_DEVICE, US_PR_DEVICE, NULL, 1032 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1025 US_FL_FIX_CAPACITY), 1033 US_FL_FIX_CAPACITY),
1026 1034
1027/* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>. 1035/* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>.
@@ -1033,9 +1041,18 @@ UNUSUAL_DEV( 0x0840, 0x0085, 0x0001, 0x0001,
1033UNUSUAL_DEV( 0x084d, 0x0011, 0x0110, 0x0110, 1041UNUSUAL_DEV( 0x084d, 0x0011, 0x0110, 0x0110,
1034 "Grandtech", 1042 "Grandtech",
1035 "DC2MEGA", 1043 "DC2MEGA",
1036 US_SC_DEVICE, US_PR_DEVICE, NULL, 1044 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1037 US_FL_BULK32), 1045 US_FL_BULK32),
1038 1046
1047/* Reported by <ttkspam@free.fr>
1048 * The device reports a vendor-specific device class, requiring an
1049 * explicit vendor/product match.
1050 */
1051UNUSUAL_DEV( 0x0851, 0x1542, 0x0002, 0x0002,
1052 "MagicPixel",
1053 "FW_Omega2",
1054 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 0),
1055
1039/* Andrew Lunn <andrew@lunn.ch> 1056/* Andrew Lunn <andrew@lunn.ch>
1040 * PanDigital Digital Picture Frame. Does not like ALLOW_MEDIUM_REMOVAL 1057 * PanDigital Digital Picture Frame. Does not like ALLOW_MEDIUM_REMOVAL
1041 * on LUN 4. 1058 * on LUN 4.
@@ -1044,14 +1061,14 @@ UNUSUAL_DEV( 0x084d, 0x0011, 0x0110, 0x0110,
1044UNUSUAL_DEV( 0x0851, 0x1543, 0x0200, 0x0200, 1061UNUSUAL_DEV( 0x0851, 0x1543, 0x0200, 0x0200,
1045 "PanDigital", 1062 "PanDigital",
1046 "Photo Frame", 1063 "Photo Frame",
1047 US_SC_DEVICE, US_PR_DEVICE, NULL, 1064 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1048 US_FL_NOT_LOCKABLE), 1065 US_FL_NOT_LOCKABLE),
1049 1066
1050/* Submitted by Jan De Luyck <lkml@kcore.org> */ 1067/* Submitted by Jan De Luyck <lkml@kcore.org> */
1051UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000, 1068UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000,
1052 "CITIZEN", 1069 "CITIZEN",
1053 "X1DE-USB", 1070 "X1DE-USB",
1054 US_SC_DEVICE, US_PR_DEVICE, NULL, 1071 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1055 US_FL_SINGLE_LUN), 1072 US_FL_SINGLE_LUN),
1056 1073
1057/* Submitted by Dylan Taft <d13f00l@gmail.com> 1074/* Submitted by Dylan Taft <d13f00l@gmail.com>
@@ -1060,7 +1077,7 @@ UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000,
1060UNUSUAL_DEV( 0x08ca, 0x3103, 0x0100, 0x0100, 1077UNUSUAL_DEV( 0x08ca, 0x3103, 0x0100, 0x0100,
1061 "AIPTEK", 1078 "AIPTEK",
1062 "Aiptek USB Keychain MP3 Player", 1079 "Aiptek USB Keychain MP3 Player",
1063 US_SC_DEVICE, US_PR_DEVICE, NULL, 1080 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1064 US_FL_IGNORE_RESIDUE), 1081 US_FL_IGNORE_RESIDUE),
1065 1082
1066/* Entry needed for flags. Moreover, all devices with this ID use 1083/* Entry needed for flags. Moreover, all devices with this ID use
@@ -1071,7 +1088,7 @@ UNUSUAL_DEV( 0x08ca, 0x3103, 0x0100, 0x0100,
1071UNUSUAL_DEV( 0x090a, 0x1001, 0x0100, 0x0100, 1088UNUSUAL_DEV( 0x090a, 0x1001, 0x0100, 0x0100,
1072 "Trumpion", 1089 "Trumpion",
1073 "t33520 USB Flash Card Controller", 1090 "t33520 USB Flash Card Controller",
1074 US_SC_DEVICE, US_PR_BULK, NULL, 1091 USB_SC_DEVICE, USB_PR_BULK, NULL,
1075 US_FL_NEED_OVERRIDE ), 1092 US_FL_NEED_OVERRIDE ),
1076 1093
1077/* Reported by Filippo Bardelli <filibard@libero.it> 1094/* Reported by Filippo Bardelli <filibard@libero.it>
@@ -1080,23 +1097,33 @@ UNUSUAL_DEV( 0x090a, 0x1001, 0x0100, 0x0100,
1080UNUSUAL_DEV( 0x090a, 0x1050, 0x0100, 0x0100, 1097UNUSUAL_DEV( 0x090a, 0x1050, 0x0100, 0x0100,
1081 "Trumpion Microelectronics, Inc.", 1098 "Trumpion Microelectronics, Inc.",
1082 "33520 USB Digital Voice Recorder", 1099 "33520 USB Digital Voice Recorder",
1083 US_SC_UFI, US_PR_DEVICE, NULL, 1100 USB_SC_UFI, USB_PR_DEVICE, NULL,
1084 0), 1101 0),
1085 1102
1086/* Trumpion Microelectronics MP3 player (felipe_alfaro@linuxmail.org) */ 1103/* Trumpion Microelectronics MP3 player (felipe_alfaro@linuxmail.org) */
1087UNUSUAL_DEV( 0x090a, 0x1200, 0x0000, 0x9999, 1104UNUSUAL_DEV( 0x090a, 0x1200, 0x0000, 0x9999,
1088 "Trumpion", 1105 "Trumpion",
1089 "MP3 player", 1106 "MP3 player",
1090 US_SC_RBC, US_PR_BULK, NULL, 1107 USB_SC_RBC, USB_PR_BULK, NULL,
1091 0 ), 1108 0 ),
1092 1109
1093/* aeb */ 1110/* aeb */
1094UNUSUAL_DEV( 0x090c, 0x1132, 0x0000, 0xffff, 1111UNUSUAL_DEV( 0x090c, 0x1132, 0x0000, 0xffff,
1095 "Feiya", 1112 "Feiya",
1096 "5-in-1 Card Reader", 1113 "5-in-1 Card Reader",
1097 US_SC_DEVICE, US_PR_DEVICE, NULL, 1114 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1098 US_FL_FIX_CAPACITY ), 1115 US_FL_FIX_CAPACITY ),
1099 1116
1117/* Reported by Paul Hartman <paul.hartman+linux@gmail.com>
1118 * This card reader returns "Illegal Request, Logical Block Address
1119 * Out of Range" for the first READ(10) after a new card is inserted.
1120 */
1121UNUSUAL_DEV( 0x090c, 0x6000, 0x0100, 0x0100,
1122 "Feiya",
1123 "SD/SDHC Card Reader",
1124 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1125 US_FL_INITIAL_READ10 ),
1126
1100/* This Pentax still camera is not conformant 1127/* This Pentax still camera is not conformant
1101 * to the USB storage specification: - 1128 * to the USB storage specification: -
1102 * - It does not like the INQUIRY command. So we must handle this command 1129 * - It does not like the INQUIRY command. So we must handle this command
@@ -1107,7 +1134,7 @@ UNUSUAL_DEV( 0x090c, 0x1132, 0x0000, 0xffff,
1107UNUSUAL_DEV( 0x0a17, 0x0004, 0x1000, 0x1000, 1134UNUSUAL_DEV( 0x0a17, 0x0004, 0x1000, 0x1000,
1108 "Pentax", 1135 "Pentax",
1109 "Optio 2/3/400", 1136 "Optio 2/3/400",
1110 US_SC_DEVICE, US_PR_DEVICE, NULL, 1137 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1111 US_FL_FIX_INQUIRY ), 1138 US_FL_FIX_INQUIRY ),
1112 1139
1113/* These are virtual windows driver CDs, which the zd1211rw driver 1140/* These are virtual windows driver CDs, which the zd1211rw driver
@@ -1115,13 +1142,13 @@ UNUSUAL_DEV( 0x0a17, 0x0004, 0x1000, 0x1000,
1115UNUSUAL_DEV( 0x0ace, 0x2011, 0x0101, 0x0101, 1142UNUSUAL_DEV( 0x0ace, 0x2011, 0x0101, 0x0101,
1116 "ZyXEL", 1143 "ZyXEL",
1117 "G-220F USB-WLAN Install", 1144 "G-220F USB-WLAN Install",
1118 US_SC_DEVICE, US_PR_DEVICE, NULL, 1145 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1119 US_FL_IGNORE_DEVICE ), 1146 US_FL_IGNORE_DEVICE ),
1120 1147
1121UNUSUAL_DEV( 0x0ace, 0x20ff, 0x0101, 0x0101, 1148UNUSUAL_DEV( 0x0ace, 0x20ff, 0x0101, 0x0101,
1122 "SiteCom", 1149 "SiteCom",
1123 "WL-117 USB-WLAN Install", 1150 "WL-117 USB-WLAN Install",
1124 US_SC_DEVICE, US_PR_DEVICE, NULL, 1151 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1125 US_FL_IGNORE_DEVICE ), 1152 US_FL_IGNORE_DEVICE ),
1126 1153
1127/* Reported by Dan Williams <dcbw@redhat.com> 1154/* Reported by Dan Williams <dcbw@redhat.com>
@@ -1133,7 +1160,7 @@ UNUSUAL_DEV( 0x0ace, 0x20ff, 0x0101, 0x0101,
1133UNUSUAL_DEV( 0x0af0, 0x6971, 0x0000, 0x9999, 1160UNUSUAL_DEV( 0x0af0, 0x6971, 0x0000, 0x9999,
1134 "Option N.V.", 1161 "Option N.V.",
1135 "Mass Storage", 1162 "Mass Storage",
1136 US_SC_DEVICE, US_PR_DEVICE, option_ms_init, 1163 USB_SC_DEVICE, USB_PR_DEVICE, option_ms_init,
1137 0), 1164 0),
1138 1165
1139/* Reported by F. Aben <f.aben@option.com> 1166/* Reported by F. Aben <f.aben@option.com>
@@ -1143,7 +1170,7 @@ UNUSUAL_DEV( 0x0af0, 0x6971, 0x0000, 0x9999,
1143UNUSUAL_DEV( 0x0af0, 0x7401, 0x0000, 0x0000, 1170UNUSUAL_DEV( 0x0af0, 0x7401, 0x0000, 0x0000,
1144 "Option", 1171 "Option",
1145 "GI 0401 SD-Card", 1172 "GI 0401 SD-Card",
1146 US_SC_DEVICE, US_PR_DEVICE, NULL, 1173 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1147 0 ), 1174 0 ),
1148 1175
1149/* Reported by Jan Dumon <j.dumon@option.com> 1176/* Reported by Jan Dumon <j.dumon@option.com>
@@ -1153,104 +1180,104 @@ UNUSUAL_DEV( 0x0af0, 0x7401, 0x0000, 0x0000,
1153UNUSUAL_DEV( 0x0af0, 0x7501, 0x0000, 0x0000, 1180UNUSUAL_DEV( 0x0af0, 0x7501, 0x0000, 0x0000,
1154 "Option", 1181 "Option",
1155 "GI 0431 SD-Card", 1182 "GI 0431 SD-Card",
1156 US_SC_DEVICE, US_PR_DEVICE, NULL, 1183 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1157 0 ), 1184 0 ),
1158 1185
1159UNUSUAL_DEV( 0x0af0, 0x7701, 0x0000, 0x0000, 1186UNUSUAL_DEV( 0x0af0, 0x7701, 0x0000, 0x0000,
1160 "Option", 1187 "Option",
1161 "GI 0451 SD-Card", 1188 "GI 0451 SD-Card",
1162 US_SC_DEVICE, US_PR_DEVICE, NULL, 1189 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1163 0 ), 1190 0 ),
1164 1191
1165UNUSUAL_DEV( 0x0af0, 0x7706, 0x0000, 0x0000, 1192UNUSUAL_DEV( 0x0af0, 0x7706, 0x0000, 0x0000,
1166 "Option", 1193 "Option",
1167 "GI 0451 SD-Card", 1194 "GI 0451 SD-Card",
1168 US_SC_DEVICE, US_PR_DEVICE, NULL, 1195 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1169 0 ), 1196 0 ),
1170 1197
1171UNUSUAL_DEV( 0x0af0, 0x7901, 0x0000, 0x0000, 1198UNUSUAL_DEV( 0x0af0, 0x7901, 0x0000, 0x0000,
1172 "Option", 1199 "Option",
1173 "GI 0452 SD-Card", 1200 "GI 0452 SD-Card",
1174 US_SC_DEVICE, US_PR_DEVICE, NULL, 1201 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1175 0 ), 1202 0 ),
1176 1203
1177UNUSUAL_DEV( 0x0af0, 0x7A01, 0x0000, 0x0000, 1204UNUSUAL_DEV( 0x0af0, 0x7A01, 0x0000, 0x0000,
1178 "Option", 1205 "Option",
1179 "GI 0461 SD-Card", 1206 "GI 0461 SD-Card",
1180 US_SC_DEVICE, US_PR_DEVICE, NULL, 1207 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1181 0 ), 1208 0 ),
1182 1209
1183UNUSUAL_DEV( 0x0af0, 0x7A05, 0x0000, 0x0000, 1210UNUSUAL_DEV( 0x0af0, 0x7A05, 0x0000, 0x0000,
1184 "Option", 1211 "Option",
1185 "GI 0461 SD-Card", 1212 "GI 0461 SD-Card",
1186 US_SC_DEVICE, US_PR_DEVICE, NULL, 1213 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1187 0 ), 1214 0 ),
1188 1215
1189UNUSUAL_DEV( 0x0af0, 0x8300, 0x0000, 0x0000, 1216UNUSUAL_DEV( 0x0af0, 0x8300, 0x0000, 0x0000,
1190 "Option", 1217 "Option",
1191 "GI 033x SD-Card", 1218 "GI 033x SD-Card",
1192 US_SC_DEVICE, US_PR_DEVICE, NULL, 1219 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1193 0 ), 1220 0 ),
1194 1221
1195UNUSUAL_DEV( 0x0af0, 0x8302, 0x0000, 0x0000, 1222UNUSUAL_DEV( 0x0af0, 0x8302, 0x0000, 0x0000,
1196 "Option", 1223 "Option",
1197 "GI 033x SD-Card", 1224 "GI 033x SD-Card",
1198 US_SC_DEVICE, US_PR_DEVICE, NULL, 1225 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1199 0 ), 1226 0 ),
1200 1227
1201UNUSUAL_DEV( 0x0af0, 0x8304, 0x0000, 0x0000, 1228UNUSUAL_DEV( 0x0af0, 0x8304, 0x0000, 0x0000,
1202 "Option", 1229 "Option",
1203 "GI 033x SD-Card", 1230 "GI 033x SD-Card",
1204 US_SC_DEVICE, US_PR_DEVICE, NULL, 1231 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1205 0 ), 1232 0 ),
1206 1233
1207UNUSUAL_DEV( 0x0af0, 0xc100, 0x0000, 0x0000, 1234UNUSUAL_DEV( 0x0af0, 0xc100, 0x0000, 0x0000,
1208 "Option", 1235 "Option",
1209 "GI 070x SD-Card", 1236 "GI 070x SD-Card",
1210 US_SC_DEVICE, US_PR_DEVICE, NULL, 1237 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1211 0 ), 1238 0 ),
1212 1239
1213UNUSUAL_DEV( 0x0af0, 0xd057, 0x0000, 0x0000, 1240UNUSUAL_DEV( 0x0af0, 0xd057, 0x0000, 0x0000,
1214 "Option", 1241 "Option",
1215 "GI 1505 SD-Card", 1242 "GI 1505 SD-Card",
1216 US_SC_DEVICE, US_PR_DEVICE, NULL, 1243 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1217 0 ), 1244 0 ),
1218 1245
1219UNUSUAL_DEV( 0x0af0, 0xd058, 0x0000, 0x0000, 1246UNUSUAL_DEV( 0x0af0, 0xd058, 0x0000, 0x0000,
1220 "Option", 1247 "Option",
1221 "GI 1509 SD-Card", 1248 "GI 1509 SD-Card",
1222 US_SC_DEVICE, US_PR_DEVICE, NULL, 1249 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1223 0 ), 1250 0 ),
1224 1251
1225UNUSUAL_DEV( 0x0af0, 0xd157, 0x0000, 0x0000, 1252UNUSUAL_DEV( 0x0af0, 0xd157, 0x0000, 0x0000,
1226 "Option", 1253 "Option",
1227 "GI 1515 SD-Card", 1254 "GI 1515 SD-Card",
1228 US_SC_DEVICE, US_PR_DEVICE, NULL, 1255 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1229 0 ), 1256 0 ),
1230 1257
1231UNUSUAL_DEV( 0x0af0, 0xd257, 0x0000, 0x0000, 1258UNUSUAL_DEV( 0x0af0, 0xd257, 0x0000, 0x0000,
1232 "Option", 1259 "Option",
1233 "GI 1215 SD-Card", 1260 "GI 1215 SD-Card",
1234 US_SC_DEVICE, US_PR_DEVICE, NULL, 1261 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1235 0 ), 1262 0 ),
1236 1263
1237UNUSUAL_DEV( 0x0af0, 0xd357, 0x0000, 0x0000, 1264UNUSUAL_DEV( 0x0af0, 0xd357, 0x0000, 0x0000,
1238 "Option", 1265 "Option",
1239 "GI 1505 SD-Card", 1266 "GI 1505 SD-Card",
1240 US_SC_DEVICE, US_PR_DEVICE, NULL, 1267 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1241 0 ), 1268 0 ),
1242 1269
1243/* Reported by Ben Efros <ben@pc-doctor.com> */ 1270/* Reported by Ben Efros <ben@pc-doctor.com> */
1244UNUSUAL_DEV( 0x0bc2, 0x3010, 0x0000, 0x0000, 1271UNUSUAL_DEV( 0x0bc2, 0x3010, 0x0000, 0x0000,
1245 "Seagate", 1272 "Seagate",
1246 "FreeAgent Pro", 1273 "FreeAgent Pro",
1247 US_SC_DEVICE, US_PR_DEVICE, NULL, 1274 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1248 US_FL_SANE_SENSE ), 1275 US_FL_SANE_SENSE ),
1249 1276
1250UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999, 1277UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999,
1251 "Maxtor", 1278 "Maxtor",
1252 "USB to SATA", 1279 "USB to SATA",
1253 US_SC_DEVICE, US_PR_DEVICE, NULL, 1280 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1254 US_FL_SANE_SENSE), 1281 US_FL_SANE_SENSE),
1255 1282
1256/* 1283/*
@@ -1260,14 +1287,14 @@ UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999,
1260UNUSUAL_DEV( 0x0c45, 0x1060, 0x0100, 0x0100, 1287UNUSUAL_DEV( 0x0c45, 0x1060, 0x0100, 0x0100,
1261 "Unknown", 1288 "Unknown",
1262 "Unknown", 1289 "Unknown",
1263 US_SC_DEVICE, US_PR_DEVICE, NULL, 1290 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1264 US_FL_SINGLE_LUN ), 1291 US_FL_SINGLE_LUN ),
1265 1292
1266/* Submitted by Joris Struyve <joris@struyve.be> */ 1293/* Submitted by Joris Struyve <joris@struyve.be> */
1267UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff, 1294UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff,
1268 "Medion", 1295 "Medion",
1269 "MD 7425", 1296 "MD 7425",
1270 US_SC_DEVICE, US_PR_DEVICE, NULL, 1297 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1271 US_FL_FIX_INQUIRY), 1298 US_FL_FIX_INQUIRY),
1272 1299
1273/* 1300/*
@@ -1278,13 +1305,13 @@ UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff,
1278UNUSUAL_DEV( 0x0d96, 0x5200, 0x0001, 0x0200, 1305UNUSUAL_DEV( 0x0d96, 0x5200, 0x0001, 0x0200,
1279 "Jenoptik", 1306 "Jenoptik",
1280 "JD 5200 z3", 1307 "JD 5200 z3",
1281 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY), 1308 USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_FIX_INQUIRY),
1282 1309
1283/* Reported by Jason Johnston <killean@shaw.ca> */ 1310/* Reported by Jason Johnston <killean@shaw.ca> */
1284UNUSUAL_DEV( 0x0dc4, 0x0073, 0x0000, 0x0000, 1311UNUSUAL_DEV( 0x0dc4, 0x0073, 0x0000, 0x0000,
1285 "Macpower Technology Co.LTD.", 1312 "Macpower Technology Co.LTD.",
1286 "USB 2.0 3.5\" DEVICE", 1313 "USB 2.0 3.5\" DEVICE",
1287 US_SC_DEVICE, US_PR_DEVICE, NULL, 1314 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1288 US_FL_FIX_CAPACITY), 1315 US_FL_FIX_CAPACITY),
1289 1316
1290/* Reported by Lubomir Blaha <tritol@trilogic.cz> 1317/* Reported by Lubomir Blaha <tritol@trilogic.cz>
@@ -1295,7 +1322,7 @@ UNUSUAL_DEV( 0x0dc4, 0x0073, 0x0000, 0x0000,
1295UNUSUAL_DEV( 0x0dd8, 0x1060, 0x0000, 0xffff, 1322UNUSUAL_DEV( 0x0dd8, 0x1060, 0x0000, 0xffff,
1296 "Netac", 1323 "Netac",
1297 "USB-CF-Card", 1324 "USB-CF-Card",
1298 US_SC_DEVICE, US_PR_DEVICE, NULL, 1325 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1299 US_FL_FIX_INQUIRY ), 1326 US_FL_FIX_INQUIRY ),
1300 1327
1301/* Reported by Edward Chapman (taken from linux-usb mailing list) 1328/* Reported by Edward Chapman (taken from linux-usb mailing list)
@@ -1303,7 +1330,7 @@ UNUSUAL_DEV( 0x0dd8, 0x1060, 0x0000, 0xffff,
1303UNUSUAL_DEV( 0x0dd8, 0xd202, 0x0000, 0x9999, 1330UNUSUAL_DEV( 0x0dd8, 0xd202, 0x0000, 0x9999,
1304 "Netac", 1331 "Netac",
1305 "USB Flash Disk", 1332 "USB Flash Disk",
1306 US_SC_DEVICE, US_PR_DEVICE, NULL, 1333 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1307 US_FL_IGNORE_RESIDUE ), 1334 US_FL_IGNORE_RESIDUE ),
1308 1335
1309 1336
@@ -1312,28 +1339,28 @@ UNUSUAL_DEV( 0x0dd8, 0xd202, 0x0000, 0x9999,
1312UNUSUAL_DEV( 0x0dda, 0x0001, 0x0012, 0x0012, 1339UNUSUAL_DEV( 0x0dda, 0x0001, 0x0012, 0x0012,
1313 "WINWARD", 1340 "WINWARD",
1314 "Music Disk", 1341 "Music Disk",
1315 US_SC_DEVICE, US_PR_DEVICE, NULL, 1342 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1316 US_FL_IGNORE_RESIDUE ), 1343 US_FL_IGNORE_RESIDUE ),
1317 1344
1318/* Reported by Ian McConnell <ian at emit.demon.co.uk> */ 1345/* Reported by Ian McConnell <ian at emit.demon.co.uk> */
1319UNUSUAL_DEV( 0x0dda, 0x0301, 0x0012, 0x0012, 1346UNUSUAL_DEV( 0x0dda, 0x0301, 0x0012, 0x0012,
1320 "PNP_MP3", 1347 "PNP_MP3",
1321 "PNP_MP3 PLAYER", 1348 "PNP_MP3 PLAYER",
1322 US_SC_DEVICE, US_PR_DEVICE, NULL, 1349 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1323 US_FL_IGNORE_RESIDUE ), 1350 US_FL_IGNORE_RESIDUE ),
1324 1351
1325/* Reported by Jim McCloskey <mcclosk@ucsc.edu> */ 1352/* Reported by Jim McCloskey <mcclosk@ucsc.edu> */
1326UNUSUAL_DEV( 0x0e21, 0x0520, 0x0100, 0x0100, 1353UNUSUAL_DEV( 0x0e21, 0x0520, 0x0100, 0x0100,
1327 "Cowon Systems", 1354 "Cowon Systems",
1328 "iAUDIO M5", 1355 "iAUDIO M5",
1329 US_SC_DEVICE, US_PR_BULK, NULL, 1356 USB_SC_DEVICE, USB_PR_BULK, NULL,
1330 US_FL_NEED_OVERRIDE ), 1357 US_FL_NEED_OVERRIDE ),
1331 1358
1332/* Submitted by Antoine Mairesse <antoine.mairesse@free.fr> */ 1359/* Submitted by Antoine Mairesse <antoine.mairesse@free.fr> */
1333UNUSUAL_DEV( 0x0ed1, 0x6660, 0x0100, 0x0300, 1360UNUSUAL_DEV( 0x0ed1, 0x6660, 0x0100, 0x0300,
1334 "USB", 1361 "USB",
1335 "Solid state disk", 1362 "Solid state disk",
1336 US_SC_DEVICE, US_PR_DEVICE, NULL, 1363 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1337 US_FL_FIX_INQUIRY ), 1364 US_FL_FIX_INQUIRY ),
1338 1365
1339/* Submitted by Daniel Drake <dsd@gentoo.org> 1366/* Submitted by Daniel Drake <dsd@gentoo.org>
@@ -1341,14 +1368,14 @@ UNUSUAL_DEV( 0x0ed1, 0x6660, 0x0100, 0x0300,
1341UNUSUAL_DEV( 0x0ea0, 0x2168, 0x0110, 0x0110, 1368UNUSUAL_DEV( 0x0ea0, 0x2168, 0x0110, 0x0110,
1342 "Ours Technology", 1369 "Ours Technology",
1343 "Flash Disk", 1370 "Flash Disk",
1344 US_SC_DEVICE, US_PR_DEVICE, NULL, 1371 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1345 US_FL_IGNORE_RESIDUE ), 1372 US_FL_IGNORE_RESIDUE ),
1346 1373
1347/* Reported by Rastislav Stanik <rs_kernel@yahoo.com> */ 1374/* Reported by Rastislav Stanik <rs_kernel@yahoo.com> */
1348UNUSUAL_DEV( 0x0ea0, 0x6828, 0x0110, 0x0110, 1375UNUSUAL_DEV( 0x0ea0, 0x6828, 0x0110, 0x0110,
1349 "USB", 1376 "USB",
1350 "Flash Disk", 1377 "Flash Disk",
1351 US_SC_DEVICE, US_PR_DEVICE, NULL, 1378 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1352 US_FL_IGNORE_RESIDUE ), 1379 US_FL_IGNORE_RESIDUE ),
1353 1380
1354/* Reported by Benjamin Schiller <sbenni@gmx.de> 1381/* Reported by Benjamin Schiller <sbenni@gmx.de>
@@ -1356,7 +1383,7 @@ UNUSUAL_DEV( 0x0ea0, 0x6828, 0x0110, 0x0110,
1356UNUSUAL_DEV( 0x0ed1, 0x7636, 0x0103, 0x0103, 1383UNUSUAL_DEV( 0x0ed1, 0x7636, 0x0103, 0x0103,
1357 "Typhoon", 1384 "Typhoon",
1358 "My DJ 1820", 1385 "My DJ 1820",
1359 US_SC_DEVICE, US_PR_DEVICE, NULL, 1386 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1360 US_FL_IGNORE_RESIDUE | US_FL_GO_SLOW | US_FL_MAX_SECTORS_64), 1387 US_FL_IGNORE_RESIDUE | US_FL_GO_SLOW | US_FL_MAX_SECTORS_64),
1361 1388
1362/* Patch by Leonid Petrov mail at lpetrov.net 1389/* Patch by Leonid Petrov mail at lpetrov.net
@@ -1367,7 +1394,7 @@ UNUSUAL_DEV( 0x0ed1, 0x7636, 0x0103, 0x0103,
1367UNUSUAL_DEV( 0x0f19, 0x0103, 0x0100, 0x0100, 1394UNUSUAL_DEV( 0x0f19, 0x0103, 0x0100, 0x0100,
1368 "Oracom Co., Ltd", 1395 "Oracom Co., Ltd",
1369 "ORC-200M", 1396 "ORC-200M",
1370 US_SC_DEVICE, US_PR_DEVICE, NULL, 1397 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1371 US_FL_IGNORE_RESIDUE ), 1398 US_FL_IGNORE_RESIDUE ),
1372 1399
1373/* David Kuehling <dvdkhlng@gmx.de>: 1400/* David Kuehling <dvdkhlng@gmx.de>:
@@ -1377,21 +1404,28 @@ UNUSUAL_DEV( 0x0f19, 0x0103, 0x0100, 0x0100,
1377UNUSUAL_DEV( 0x0f19, 0x0105, 0x0100, 0x0100, 1404UNUSUAL_DEV( 0x0f19, 0x0105, 0x0100, 0x0100,
1378 "C-MEX", 1405 "C-MEX",
1379 "A-VOX", 1406 "A-VOX",
1380 US_SC_DEVICE, US_PR_DEVICE, NULL, 1407 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1381 US_FL_IGNORE_RESIDUE ), 1408 US_FL_IGNORE_RESIDUE ),
1382 1409
1410/* Submitted by Nick Holloway */
1411UNUSUAL_DEV( 0x0f88, 0x042e, 0x0100, 0x0100,
1412 "VTech",
1413 "Kidizoom",
1414 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1415 US_FL_FIX_CAPACITY ),
1416
1383/* Reported by Michael Stattmann <michael@stattmann.com> */ 1417/* Reported by Michael Stattmann <michael@stattmann.com> */
1384UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000, 1418UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000,
1385 "Sony Ericsson", 1419 "Sony Ericsson",
1386 "V800-Vodafone 802", 1420 "V800-Vodafone 802",
1387 US_SC_DEVICE, US_PR_DEVICE, NULL, 1421 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1388 US_FL_NO_WP_DETECT ), 1422 US_FL_NO_WP_DETECT ),
1389 1423
1390/* Reported by The Solutor <thesolutor@gmail.com> */ 1424/* Reported by The Solutor <thesolutor@gmail.com> */
1391UNUSUAL_DEV( 0x0fce, 0xd0e1, 0x0000, 0x0000, 1425UNUSUAL_DEV( 0x0fce, 0xd0e1, 0x0000, 0x0000,
1392 "Sony Ericsson", 1426 "Sony Ericsson",
1393 "MD400", 1427 "MD400",
1394 US_SC_DEVICE, US_PR_DEVICE, NULL, 1428 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1395 US_FL_IGNORE_DEVICE), 1429 US_FL_IGNORE_DEVICE),
1396 1430
1397/* Reported by Jan Mate <mate@fiit.stuba.sk> 1431/* Reported by Jan Mate <mate@fiit.stuba.sk>
@@ -1399,21 +1433,21 @@ UNUSUAL_DEV( 0x0fce, 0xd0e1, 0x0000, 0x0000,
1399UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000, 1433UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000,
1400 "Sony Ericsson", 1434 "Sony Ericsson",
1401 "P990i", 1435 "P990i",
1402 US_SC_DEVICE, US_PR_DEVICE, NULL, 1436 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1403 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), 1437 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
1404 1438
1405/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */ 1439/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */
1406UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, 1440UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000,
1407 "Sony Ericsson", 1441 "Sony Ericsson",
1408 "M600i", 1442 "M600i",
1409 US_SC_DEVICE, US_PR_DEVICE, NULL, 1443 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1410 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 1444 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
1411 1445
1412/* Reported by Ricardo Barberis <ricardo@dattatec.com> */ 1446/* Reported by Ricardo Barberis <ricardo@dattatec.com> */
1413UNUSUAL_DEV( 0x0fce, 0xe092, 0x0000, 0x0000, 1447UNUSUAL_DEV( 0x0fce, 0xe092, 0x0000, 0x0000,
1414 "Sony Ericsson", 1448 "Sony Ericsson",
1415 "P1i", 1449 "P1i",
1416 US_SC_DEVICE, US_PR_DEVICE, NULL, 1450 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1417 US_FL_IGNORE_RESIDUE ), 1451 US_FL_IGNORE_RESIDUE ),
1418 1452
1419/* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu> 1453/* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu>
@@ -1425,13 +1459,13 @@ UNUSUAL_DEV( 0x0fce, 0xe092, 0x0000, 0x0000,
1425UNUSUAL_DEV( 0x1019, 0x0c55, 0x0000, 0x0110, 1459UNUSUAL_DEV( 0x1019, 0x0c55, 0x0000, 0x0110,
1426 "Desknote", 1460 "Desknote",
1427 "UCR-61S2B", 1461 "UCR-61S2B",
1428 US_SC_DEVICE, US_PR_DEVICE, usb_stor_ucr61s2b_init, 1462 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_ucr61s2b_init,
1429 0 ), 1463 0 ),
1430 1464
1431UNUSUAL_DEV( 0x1058, 0x0704, 0x0000, 0x9999, 1465UNUSUAL_DEV( 0x1058, 0x0704, 0x0000, 0x9999,
1432 "Western Digital", 1466 "Western Digital",
1433 "External HDD", 1467 "External HDD",
1434 US_SC_DEVICE, US_PR_DEVICE, NULL, 1468 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1435 US_FL_SANE_SENSE), 1469 US_FL_SANE_SENSE),
1436 1470
1437/* Reported by Fabio Venturi <f.venturi@tdnet.it> 1471/* Reported by Fabio Venturi <f.venturi@tdnet.it>
@@ -1440,7 +1474,7 @@ UNUSUAL_DEV( 0x1058, 0x0704, 0x0000, 0x9999,
1440UNUSUAL_DEV( 0x10d6, 0x2200, 0x0100, 0x0100, 1474UNUSUAL_DEV( 0x10d6, 0x2200, 0x0100, 0x0100,
1441 "Actions Semiconductor", 1475 "Actions Semiconductor",
1442 "Mtp device", 1476 "Mtp device",
1443 US_SC_DEVICE, US_PR_DEVICE, NULL, 1477 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1444 0), 1478 0),
1445 1479
1446/* Reported by Pascal Terjan <pterjan@mandriva.com> 1480/* Reported by Pascal Terjan <pterjan@mandriva.com>
@@ -1449,7 +1483,7 @@ UNUSUAL_DEV( 0x10d6, 0x2200, 0x0100, 0x0100,
1449UNUSUAL_DEV( 0x1186, 0x3e04, 0x0000, 0x0000, 1483UNUSUAL_DEV( 0x1186, 0x3e04, 0x0000, 0x0000,
1450 "D-Link", 1484 "D-Link",
1451 "USB Mass Storage", 1485 "USB Mass Storage",
1452 US_SC_DEVICE, US_PR_DEVICE, option_ms_init, US_FL_IGNORE_DEVICE), 1486 USB_SC_DEVICE, USB_PR_DEVICE, option_ms_init, US_FL_IGNORE_DEVICE),
1453 1487
1454/* Reported by Kevin Lloyd <linux@sierrawireless.com> 1488/* Reported by Kevin Lloyd <linux@sierrawireless.com>
1455 * Entry is needed for the initializer function override, 1489 * Entry is needed for the initializer function override,
@@ -1459,7 +1493,7 @@ UNUSUAL_DEV( 0x1186, 0x3e04, 0x0000, 0x0000,
1459UNUSUAL_DEV( 0x1199, 0x0fff, 0x0000, 0x9999, 1493UNUSUAL_DEV( 0x1199, 0x0fff, 0x0000, 0x9999,
1460 "Sierra Wireless", 1494 "Sierra Wireless",
1461 "USB MMC Storage", 1495 "USB MMC Storage",
1462 US_SC_DEVICE, US_PR_DEVICE, sierra_ms_init, 1496 USB_SC_DEVICE, USB_PR_DEVICE, sierra_ms_init,
1463 0), 1497 0),
1464 1498
1465/* Reported by Jaco Kroon <jaco@kroon.co.za> 1499/* Reported by Jaco Kroon <jaco@kroon.co.za>
@@ -1469,7 +1503,7 @@ UNUSUAL_DEV( 0x1199, 0x0fff, 0x0000, 0x9999,
1469UNUSUAL_DEV( 0x1210, 0x0003, 0x0100, 0x0100, 1503UNUSUAL_DEV( 0x1210, 0x0003, 0x0100, 0x0100,
1470 "Digitech HMG", 1504 "Digitech HMG",
1471 "DigiTech Mass Storage", 1505 "DigiTech Mass Storage",
1472 US_SC_DEVICE, US_PR_DEVICE, NULL, 1506 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1473 US_FL_IGNORE_RESIDUE ), 1507 US_FL_IGNORE_RESIDUE ),
1474 1508
1475/* Reported by fangxiaozhi <huananhu@huawei.com> 1509/* Reported by fangxiaozhi <huananhu@huawei.com>
@@ -1478,353 +1512,353 @@ UNUSUAL_DEV( 0x1210, 0x0003, 0x0100, 0x0100,
1478UNUSUAL_DEV( 0x12d1, 0x1001, 0x0000, 0x0000, 1512UNUSUAL_DEV( 0x12d1, 0x1001, 0x0000, 0x0000,
1479 "HUAWEI MOBILE", 1513 "HUAWEI MOBILE",
1480 "Mass Storage", 1514 "Mass Storage",
1481 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1515 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1482 0), 1516 0),
1483UNUSUAL_DEV( 0x12d1, 0x1003, 0x0000, 0x0000, 1517UNUSUAL_DEV( 0x12d1, 0x1003, 0x0000, 0x0000,
1484 "HUAWEI MOBILE", 1518 "HUAWEI MOBILE",
1485 "Mass Storage", 1519 "Mass Storage",
1486 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1520 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1487 0), 1521 0),
1488UNUSUAL_DEV( 0x12d1, 0x1004, 0x0000, 0x0000, 1522UNUSUAL_DEV( 0x12d1, 0x1004, 0x0000, 0x0000,
1489 "HUAWEI MOBILE", 1523 "HUAWEI MOBILE",
1490 "Mass Storage", 1524 "Mass Storage",
1491 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1525 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1492 0), 1526 0),
1493UNUSUAL_DEV( 0x12d1, 0x1401, 0x0000, 0x0000, 1527UNUSUAL_DEV( 0x12d1, 0x1401, 0x0000, 0x0000,
1494 "HUAWEI MOBILE", 1528 "HUAWEI MOBILE",
1495 "Mass Storage", 1529 "Mass Storage",
1496 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1530 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1497 0), 1531 0),
1498UNUSUAL_DEV( 0x12d1, 0x1402, 0x0000, 0x0000, 1532UNUSUAL_DEV( 0x12d1, 0x1402, 0x0000, 0x0000,
1499 "HUAWEI MOBILE", 1533 "HUAWEI MOBILE",
1500 "Mass Storage", 1534 "Mass Storage",
1501 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1535 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1502 0), 1536 0),
1503UNUSUAL_DEV( 0x12d1, 0x1403, 0x0000, 0x0000, 1537UNUSUAL_DEV( 0x12d1, 0x1403, 0x0000, 0x0000,
1504 "HUAWEI MOBILE", 1538 "HUAWEI MOBILE",
1505 "Mass Storage", 1539 "Mass Storage",
1506 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1540 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1507 0), 1541 0),
1508UNUSUAL_DEV( 0x12d1, 0x1404, 0x0000, 0x0000, 1542UNUSUAL_DEV( 0x12d1, 0x1404, 0x0000, 0x0000,
1509 "HUAWEI MOBILE", 1543 "HUAWEI MOBILE",
1510 "Mass Storage", 1544 "Mass Storage",
1511 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1545 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1512 0), 1546 0),
1513UNUSUAL_DEV( 0x12d1, 0x1405, 0x0000, 0x0000, 1547UNUSUAL_DEV( 0x12d1, 0x1405, 0x0000, 0x0000,
1514 "HUAWEI MOBILE", 1548 "HUAWEI MOBILE",
1515 "Mass Storage", 1549 "Mass Storage",
1516 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1550 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1517 0), 1551 0),
1518UNUSUAL_DEV( 0x12d1, 0x1406, 0x0000, 0x0000, 1552UNUSUAL_DEV( 0x12d1, 0x1406, 0x0000, 0x0000,
1519 "HUAWEI MOBILE", 1553 "HUAWEI MOBILE",
1520 "Mass Storage", 1554 "Mass Storage",
1521 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1555 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1522 0), 1556 0),
1523UNUSUAL_DEV( 0x12d1, 0x1407, 0x0000, 0x0000, 1557UNUSUAL_DEV( 0x12d1, 0x1407, 0x0000, 0x0000,
1524 "HUAWEI MOBILE", 1558 "HUAWEI MOBILE",
1525 "Mass Storage", 1559 "Mass Storage",
1526 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1560 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1527 0), 1561 0),
1528UNUSUAL_DEV( 0x12d1, 0x1408, 0x0000, 0x0000, 1562UNUSUAL_DEV( 0x12d1, 0x1408, 0x0000, 0x0000,
1529 "HUAWEI MOBILE", 1563 "HUAWEI MOBILE",
1530 "Mass Storage", 1564 "Mass Storage",
1531 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1565 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1532 0), 1566 0),
1533UNUSUAL_DEV( 0x12d1, 0x1409, 0x0000, 0x0000, 1567UNUSUAL_DEV( 0x12d1, 0x1409, 0x0000, 0x0000,
1534 "HUAWEI MOBILE", 1568 "HUAWEI MOBILE",
1535 "Mass Storage", 1569 "Mass Storage",
1536 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1570 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1537 0), 1571 0),
1538UNUSUAL_DEV( 0x12d1, 0x140A, 0x0000, 0x0000, 1572UNUSUAL_DEV( 0x12d1, 0x140A, 0x0000, 0x0000,
1539 "HUAWEI MOBILE", 1573 "HUAWEI MOBILE",
1540 "Mass Storage", 1574 "Mass Storage",
1541 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1575 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1542 0), 1576 0),
1543UNUSUAL_DEV( 0x12d1, 0x140B, 0x0000, 0x0000, 1577UNUSUAL_DEV( 0x12d1, 0x140B, 0x0000, 0x0000,
1544 "HUAWEI MOBILE", 1578 "HUAWEI MOBILE",
1545 "Mass Storage", 1579 "Mass Storage",
1546 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1580 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1547 0), 1581 0),
1548UNUSUAL_DEV( 0x12d1, 0x140C, 0x0000, 0x0000, 1582UNUSUAL_DEV( 0x12d1, 0x140C, 0x0000, 0x0000,
1549 "HUAWEI MOBILE", 1583 "HUAWEI MOBILE",
1550 "Mass Storage", 1584 "Mass Storage",
1551 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1585 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1552 0), 1586 0),
1553UNUSUAL_DEV( 0x12d1, 0x140D, 0x0000, 0x0000, 1587UNUSUAL_DEV( 0x12d1, 0x140D, 0x0000, 0x0000,
1554 "HUAWEI MOBILE", 1588 "HUAWEI MOBILE",
1555 "Mass Storage", 1589 "Mass Storage",
1556 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1590 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1557 0), 1591 0),
1558UNUSUAL_DEV( 0x12d1, 0x140E, 0x0000, 0x0000, 1592UNUSUAL_DEV( 0x12d1, 0x140E, 0x0000, 0x0000,
1559 "HUAWEI MOBILE", 1593 "HUAWEI MOBILE",
1560 "Mass Storage", 1594 "Mass Storage",
1561 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1595 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1562 0), 1596 0),
1563UNUSUAL_DEV( 0x12d1, 0x140F, 0x0000, 0x0000, 1597UNUSUAL_DEV( 0x12d1, 0x140F, 0x0000, 0x0000,
1564 "HUAWEI MOBILE", 1598 "HUAWEI MOBILE",
1565 "Mass Storage", 1599 "Mass Storage",
1566 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1600 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1567 0), 1601 0),
1568UNUSUAL_DEV( 0x12d1, 0x1410, 0x0000, 0x0000, 1602UNUSUAL_DEV( 0x12d1, 0x1410, 0x0000, 0x0000,
1569 "HUAWEI MOBILE", 1603 "HUAWEI MOBILE",
1570 "Mass Storage", 1604 "Mass Storage",
1571 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1605 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1572 0), 1606 0),
1573UNUSUAL_DEV( 0x12d1, 0x1411, 0x0000, 0x0000, 1607UNUSUAL_DEV( 0x12d1, 0x1411, 0x0000, 0x0000,
1574 "HUAWEI MOBILE", 1608 "HUAWEI MOBILE",
1575 "Mass Storage", 1609 "Mass Storage",
1576 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1610 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1577 0), 1611 0),
1578UNUSUAL_DEV( 0x12d1, 0x1412, 0x0000, 0x0000, 1612UNUSUAL_DEV( 0x12d1, 0x1412, 0x0000, 0x0000,
1579 "HUAWEI MOBILE", 1613 "HUAWEI MOBILE",
1580 "Mass Storage", 1614 "Mass Storage",
1581 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1615 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1582 0), 1616 0),
1583UNUSUAL_DEV( 0x12d1, 0x1413, 0x0000, 0x0000, 1617UNUSUAL_DEV( 0x12d1, 0x1413, 0x0000, 0x0000,
1584 "HUAWEI MOBILE", 1618 "HUAWEI MOBILE",
1585 "Mass Storage", 1619 "Mass Storage",
1586 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1620 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1587 0), 1621 0),
1588UNUSUAL_DEV( 0x12d1, 0x1414, 0x0000, 0x0000, 1622UNUSUAL_DEV( 0x12d1, 0x1414, 0x0000, 0x0000,
1589 "HUAWEI MOBILE", 1623 "HUAWEI MOBILE",
1590 "Mass Storage", 1624 "Mass Storage",
1591 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1625 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1592 0), 1626 0),
1593UNUSUAL_DEV( 0x12d1, 0x1415, 0x0000, 0x0000, 1627UNUSUAL_DEV( 0x12d1, 0x1415, 0x0000, 0x0000,
1594 "HUAWEI MOBILE", 1628 "HUAWEI MOBILE",
1595 "Mass Storage", 1629 "Mass Storage",
1596 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1630 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1597 0), 1631 0),
1598UNUSUAL_DEV( 0x12d1, 0x1416, 0x0000, 0x0000, 1632UNUSUAL_DEV( 0x12d1, 0x1416, 0x0000, 0x0000,
1599 "HUAWEI MOBILE", 1633 "HUAWEI MOBILE",
1600 "Mass Storage", 1634 "Mass Storage",
1601 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1635 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1602 0), 1636 0),
1603UNUSUAL_DEV( 0x12d1, 0x1417, 0x0000, 0x0000, 1637UNUSUAL_DEV( 0x12d1, 0x1417, 0x0000, 0x0000,
1604 "HUAWEI MOBILE", 1638 "HUAWEI MOBILE",
1605 "Mass Storage", 1639 "Mass Storage",
1606 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1640 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1607 0), 1641 0),
1608UNUSUAL_DEV( 0x12d1, 0x1418, 0x0000, 0x0000, 1642UNUSUAL_DEV( 0x12d1, 0x1418, 0x0000, 0x0000,
1609 "HUAWEI MOBILE", 1643 "HUAWEI MOBILE",
1610 "Mass Storage", 1644 "Mass Storage",
1611 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1645 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1612 0), 1646 0),
1613UNUSUAL_DEV( 0x12d1, 0x1419, 0x0000, 0x0000, 1647UNUSUAL_DEV( 0x12d1, 0x1419, 0x0000, 0x0000,
1614 "HUAWEI MOBILE", 1648 "HUAWEI MOBILE",
1615 "Mass Storage", 1649 "Mass Storage",
1616 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1650 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1617 0), 1651 0),
1618UNUSUAL_DEV( 0x12d1, 0x141A, 0x0000, 0x0000, 1652UNUSUAL_DEV( 0x12d1, 0x141A, 0x0000, 0x0000,
1619 "HUAWEI MOBILE", 1653 "HUAWEI MOBILE",
1620 "Mass Storage", 1654 "Mass Storage",
1621 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1655 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1622 0), 1656 0),
1623UNUSUAL_DEV( 0x12d1, 0x141B, 0x0000, 0x0000, 1657UNUSUAL_DEV( 0x12d1, 0x141B, 0x0000, 0x0000,
1624 "HUAWEI MOBILE", 1658 "HUAWEI MOBILE",
1625 "Mass Storage", 1659 "Mass Storage",
1626 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1660 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1627 0), 1661 0),
1628UNUSUAL_DEV( 0x12d1, 0x141C, 0x0000, 0x0000, 1662UNUSUAL_DEV( 0x12d1, 0x141C, 0x0000, 0x0000,
1629 "HUAWEI MOBILE", 1663 "HUAWEI MOBILE",
1630 "Mass Storage", 1664 "Mass Storage",
1631 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1665 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1632 0), 1666 0),
1633UNUSUAL_DEV( 0x12d1, 0x141D, 0x0000, 0x0000, 1667UNUSUAL_DEV( 0x12d1, 0x141D, 0x0000, 0x0000,
1634 "HUAWEI MOBILE", 1668 "HUAWEI MOBILE",
1635 "Mass Storage", 1669 "Mass Storage",
1636 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1670 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1637 0), 1671 0),
1638UNUSUAL_DEV( 0x12d1, 0x141E, 0x0000, 0x0000, 1672UNUSUAL_DEV( 0x12d1, 0x141E, 0x0000, 0x0000,
1639 "HUAWEI MOBILE", 1673 "HUAWEI MOBILE",
1640 "Mass Storage", 1674 "Mass Storage",
1641 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1675 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1642 0), 1676 0),
1643UNUSUAL_DEV( 0x12d1, 0x141F, 0x0000, 0x0000, 1677UNUSUAL_DEV( 0x12d1, 0x141F, 0x0000, 0x0000,
1644 "HUAWEI MOBILE", 1678 "HUAWEI MOBILE",
1645 "Mass Storage", 1679 "Mass Storage",
1646 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1680 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1647 0), 1681 0),
1648UNUSUAL_DEV( 0x12d1, 0x1420, 0x0000, 0x0000, 1682UNUSUAL_DEV( 0x12d1, 0x1420, 0x0000, 0x0000,
1649 "HUAWEI MOBILE", 1683 "HUAWEI MOBILE",
1650 "Mass Storage", 1684 "Mass Storage",
1651 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1685 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1652 0), 1686 0),
1653UNUSUAL_DEV( 0x12d1, 0x1421, 0x0000, 0x0000, 1687UNUSUAL_DEV( 0x12d1, 0x1421, 0x0000, 0x0000,
1654 "HUAWEI MOBILE", 1688 "HUAWEI MOBILE",
1655 "Mass Storage", 1689 "Mass Storage",
1656 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1690 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1657 0), 1691 0),
1658UNUSUAL_DEV( 0x12d1, 0x1422, 0x0000, 0x0000, 1692UNUSUAL_DEV( 0x12d1, 0x1422, 0x0000, 0x0000,
1659 "HUAWEI MOBILE", 1693 "HUAWEI MOBILE",
1660 "Mass Storage", 1694 "Mass Storage",
1661 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1695 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1662 0), 1696 0),
1663UNUSUAL_DEV( 0x12d1, 0x1423, 0x0000, 0x0000, 1697UNUSUAL_DEV( 0x12d1, 0x1423, 0x0000, 0x0000,
1664 "HUAWEI MOBILE", 1698 "HUAWEI MOBILE",
1665 "Mass Storage", 1699 "Mass Storage",
1666 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1700 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1667 0), 1701 0),
1668UNUSUAL_DEV( 0x12d1, 0x1424, 0x0000, 0x0000, 1702UNUSUAL_DEV( 0x12d1, 0x1424, 0x0000, 0x0000,
1669 "HUAWEI MOBILE", 1703 "HUAWEI MOBILE",
1670 "Mass Storage", 1704 "Mass Storage",
1671 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1705 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1672 0), 1706 0),
1673UNUSUAL_DEV( 0x12d1, 0x1425, 0x0000, 0x0000, 1707UNUSUAL_DEV( 0x12d1, 0x1425, 0x0000, 0x0000,
1674 "HUAWEI MOBILE", 1708 "HUAWEI MOBILE",
1675 "Mass Storage", 1709 "Mass Storage",
1676 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1710 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1677 0), 1711 0),
1678UNUSUAL_DEV( 0x12d1, 0x1426, 0x0000, 0x0000, 1712UNUSUAL_DEV( 0x12d1, 0x1426, 0x0000, 0x0000,
1679 "HUAWEI MOBILE", 1713 "HUAWEI MOBILE",
1680 "Mass Storage", 1714 "Mass Storage",
1681 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1715 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1682 0), 1716 0),
1683UNUSUAL_DEV( 0x12d1, 0x1427, 0x0000, 0x0000, 1717UNUSUAL_DEV( 0x12d1, 0x1427, 0x0000, 0x0000,
1684 "HUAWEI MOBILE", 1718 "HUAWEI MOBILE",
1685 "Mass Storage", 1719 "Mass Storage",
1686 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1720 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1687 0), 1721 0),
1688UNUSUAL_DEV( 0x12d1, 0x1428, 0x0000, 0x0000, 1722UNUSUAL_DEV( 0x12d1, 0x1428, 0x0000, 0x0000,
1689 "HUAWEI MOBILE", 1723 "HUAWEI MOBILE",
1690 "Mass Storage", 1724 "Mass Storage",
1691 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1725 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1692 0), 1726 0),
1693UNUSUAL_DEV( 0x12d1, 0x1429, 0x0000, 0x0000, 1727UNUSUAL_DEV( 0x12d1, 0x1429, 0x0000, 0x0000,
1694 "HUAWEI MOBILE", 1728 "HUAWEI MOBILE",
1695 "Mass Storage", 1729 "Mass Storage",
1696 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1730 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1697 0), 1731 0),
1698UNUSUAL_DEV( 0x12d1, 0x142A, 0x0000, 0x0000, 1732UNUSUAL_DEV( 0x12d1, 0x142A, 0x0000, 0x0000,
1699 "HUAWEI MOBILE", 1733 "HUAWEI MOBILE",
1700 "Mass Storage", 1734 "Mass Storage",
1701 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1735 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1702 0), 1736 0),
1703UNUSUAL_DEV( 0x12d1, 0x142B, 0x0000, 0x0000, 1737UNUSUAL_DEV( 0x12d1, 0x142B, 0x0000, 0x0000,
1704 "HUAWEI MOBILE", 1738 "HUAWEI MOBILE",
1705 "Mass Storage", 1739 "Mass Storage",
1706 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1740 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1707 0), 1741 0),
1708UNUSUAL_DEV( 0x12d1, 0x142C, 0x0000, 0x0000, 1742UNUSUAL_DEV( 0x12d1, 0x142C, 0x0000, 0x0000,
1709 "HUAWEI MOBILE", 1743 "HUAWEI MOBILE",
1710 "Mass Storage", 1744 "Mass Storage",
1711 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1745 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1712 0), 1746 0),
1713UNUSUAL_DEV( 0x12d1, 0x142D, 0x0000, 0x0000, 1747UNUSUAL_DEV( 0x12d1, 0x142D, 0x0000, 0x0000,
1714 "HUAWEI MOBILE", 1748 "HUAWEI MOBILE",
1715 "Mass Storage", 1749 "Mass Storage",
1716 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1750 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1717 0), 1751 0),
1718UNUSUAL_DEV( 0x12d1, 0x142E, 0x0000, 0x0000, 1752UNUSUAL_DEV( 0x12d1, 0x142E, 0x0000, 0x0000,
1719 "HUAWEI MOBILE", 1753 "HUAWEI MOBILE",
1720 "Mass Storage", 1754 "Mass Storage",
1721 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1755 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1722 0), 1756 0),
1723UNUSUAL_DEV( 0x12d1, 0x142F, 0x0000, 0x0000, 1757UNUSUAL_DEV( 0x12d1, 0x142F, 0x0000, 0x0000,
1724 "HUAWEI MOBILE", 1758 "HUAWEI MOBILE",
1725 "Mass Storage", 1759 "Mass Storage",
1726 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1760 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1727 0), 1761 0),
1728UNUSUAL_DEV( 0x12d1, 0x1430, 0x0000, 0x0000, 1762UNUSUAL_DEV( 0x12d1, 0x1430, 0x0000, 0x0000,
1729 "HUAWEI MOBILE", 1763 "HUAWEI MOBILE",
1730 "Mass Storage", 1764 "Mass Storage",
1731 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1765 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1732 0), 1766 0),
1733UNUSUAL_DEV( 0x12d1, 0x1431, 0x0000, 0x0000, 1767UNUSUAL_DEV( 0x12d1, 0x1431, 0x0000, 0x0000,
1734 "HUAWEI MOBILE", 1768 "HUAWEI MOBILE",
1735 "Mass Storage", 1769 "Mass Storage",
1736 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1770 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1737 0), 1771 0),
1738UNUSUAL_DEV( 0x12d1, 0x1432, 0x0000, 0x0000, 1772UNUSUAL_DEV( 0x12d1, 0x1432, 0x0000, 0x0000,
1739 "HUAWEI MOBILE", 1773 "HUAWEI MOBILE",
1740 "Mass Storage", 1774 "Mass Storage",
1741 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1775 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1742 0), 1776 0),
1743UNUSUAL_DEV( 0x12d1, 0x1433, 0x0000, 0x0000, 1777UNUSUAL_DEV( 0x12d1, 0x1433, 0x0000, 0x0000,
1744 "HUAWEI MOBILE", 1778 "HUAWEI MOBILE",
1745 "Mass Storage", 1779 "Mass Storage",
1746 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1780 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1747 0), 1781 0),
1748UNUSUAL_DEV( 0x12d1, 0x1434, 0x0000, 0x0000, 1782UNUSUAL_DEV( 0x12d1, 0x1434, 0x0000, 0x0000,
1749 "HUAWEI MOBILE", 1783 "HUAWEI MOBILE",
1750 "Mass Storage", 1784 "Mass Storage",
1751 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1785 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1752 0), 1786 0),
1753UNUSUAL_DEV( 0x12d1, 0x1435, 0x0000, 0x0000, 1787UNUSUAL_DEV( 0x12d1, 0x1435, 0x0000, 0x0000,
1754 "HUAWEI MOBILE", 1788 "HUAWEI MOBILE",
1755 "Mass Storage", 1789 "Mass Storage",
1756 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1790 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1757 0), 1791 0),
1758UNUSUAL_DEV( 0x12d1, 0x1436, 0x0000, 0x0000, 1792UNUSUAL_DEV( 0x12d1, 0x1436, 0x0000, 0x0000,
1759 "HUAWEI MOBILE", 1793 "HUAWEI MOBILE",
1760 "Mass Storage", 1794 "Mass Storage",
1761 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1795 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1762 0), 1796 0),
1763UNUSUAL_DEV( 0x12d1, 0x1437, 0x0000, 0x0000, 1797UNUSUAL_DEV( 0x12d1, 0x1437, 0x0000, 0x0000,
1764 "HUAWEI MOBILE", 1798 "HUAWEI MOBILE",
1765 "Mass Storage", 1799 "Mass Storage",
1766 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1800 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1767 0), 1801 0),
1768UNUSUAL_DEV( 0x12d1, 0x1438, 0x0000, 0x0000, 1802UNUSUAL_DEV( 0x12d1, 0x1438, 0x0000, 0x0000,
1769 "HUAWEI MOBILE", 1803 "HUAWEI MOBILE",
1770 "Mass Storage", 1804 "Mass Storage",
1771 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1805 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1772 0), 1806 0),
1773UNUSUAL_DEV( 0x12d1, 0x1439, 0x0000, 0x0000, 1807UNUSUAL_DEV( 0x12d1, 0x1439, 0x0000, 0x0000,
1774 "HUAWEI MOBILE", 1808 "HUAWEI MOBILE",
1775 "Mass Storage", 1809 "Mass Storage",
1776 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1810 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1777 0), 1811 0),
1778UNUSUAL_DEV( 0x12d1, 0x143A, 0x0000, 0x0000, 1812UNUSUAL_DEV( 0x12d1, 0x143A, 0x0000, 0x0000,
1779 "HUAWEI MOBILE", 1813 "HUAWEI MOBILE",
1780 "Mass Storage", 1814 "Mass Storage",
1781 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1815 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1782 0), 1816 0),
1783UNUSUAL_DEV( 0x12d1, 0x143B, 0x0000, 0x0000, 1817UNUSUAL_DEV( 0x12d1, 0x143B, 0x0000, 0x0000,
1784 "HUAWEI MOBILE", 1818 "HUAWEI MOBILE",
1785 "Mass Storage", 1819 "Mass Storage",
1786 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1820 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1787 0), 1821 0),
1788UNUSUAL_DEV( 0x12d1, 0x143C, 0x0000, 0x0000, 1822UNUSUAL_DEV( 0x12d1, 0x143C, 0x0000, 0x0000,
1789 "HUAWEI MOBILE", 1823 "HUAWEI MOBILE",
1790 "Mass Storage", 1824 "Mass Storage",
1791 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1825 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1792 0), 1826 0),
1793UNUSUAL_DEV( 0x12d1, 0x143D, 0x0000, 0x0000, 1827UNUSUAL_DEV( 0x12d1, 0x143D, 0x0000, 0x0000,
1794 "HUAWEI MOBILE", 1828 "HUAWEI MOBILE",
1795 "Mass Storage", 1829 "Mass Storage",
1796 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1830 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1797 0), 1831 0),
1798UNUSUAL_DEV( 0x12d1, 0x143E, 0x0000, 0x0000, 1832UNUSUAL_DEV( 0x12d1, 0x143E, 0x0000, 0x0000,
1799 "HUAWEI MOBILE", 1833 "HUAWEI MOBILE",
1800 "Mass Storage", 1834 "Mass Storage",
1801 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1835 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1802 0), 1836 0),
1803UNUSUAL_DEV( 0x12d1, 0x143F, 0x0000, 0x0000, 1837UNUSUAL_DEV( 0x12d1, 0x143F, 0x0000, 0x0000,
1804 "HUAWEI MOBILE", 1838 "HUAWEI MOBILE",
1805 "Mass Storage", 1839 "Mass Storage",
1806 US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init, 1840 USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_huawei_e220_init,
1807 0), 1841 0),
1808 1842
1809/* Reported by Vilius Bilinkevicius <vilisas AT xxx DOT lt) */ 1843/* Reported by Vilius Bilinkevicius <vilisas AT xxx DOT lt) */
1810UNUSUAL_DEV( 0x132b, 0x000b, 0x0001, 0x0001, 1844UNUSUAL_DEV( 0x132b, 0x000b, 0x0001, 0x0001,
1811 "Minolta", 1845 "Minolta",
1812 "Dimage Z10", 1846 "Dimage Z10",
1813 US_SC_DEVICE, US_PR_DEVICE, NULL, 1847 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1814 0 ), 1848 0 ),
1815 1849
1816/* Reported by Kotrla Vitezslav <kotrla@ceb.cz> */ 1850/* Reported by Kotrla Vitezslav <kotrla@ceb.cz> */
1817UNUSUAL_DEV( 0x1370, 0x6828, 0x0110, 0x0110, 1851UNUSUAL_DEV( 0x1370, 0x6828, 0x0110, 0x0110,
1818 "SWISSBIT", 1852 "SWISSBIT",
1819 "Black Silver", 1853 "Black Silver",
1820 US_SC_DEVICE, US_PR_DEVICE, NULL, 1854 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1821 US_FL_IGNORE_RESIDUE ), 1855 US_FL_IGNORE_RESIDUE ),
1822 1856
1823/* Reported by Francesco Foresti <frafore@tiscali.it> */ 1857/* Reported by Francesco Foresti <frafore@tiscali.it> */
1824UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201, 1858UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201,
1825 "Super Top", 1859 "Super Top",
1826 "IDE DEVICE", 1860 "IDE DEVICE",
1827 US_SC_DEVICE, US_PR_DEVICE, NULL, 1861 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1828 US_FL_IGNORE_RESIDUE ), 1862 US_FL_IGNORE_RESIDUE ),
1829 1863
1830/* Reported by Alexandre Oliva <oliva@lsd.ic.unicamp.br> 1864/* Reported by Alexandre Oliva <oliva@lsd.ic.unicamp.br>
@@ -1833,7 +1867,7 @@ UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201,
1833UNUSUAL_DEV( 0x152d, 0x2329, 0x0100, 0x0100, 1867UNUSUAL_DEV( 0x152d, 0x2329, 0x0100, 0x0100,
1834 "JMicron", 1868 "JMicron",
1835 "USB to ATA/ATAPI Bridge", 1869 "USB to ATA/ATAPI Bridge",
1836 US_SC_DEVICE, US_PR_DEVICE, NULL, 1870 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1837 US_FL_IGNORE_RESIDUE | US_FL_SANE_SENSE ), 1871 US_FL_IGNORE_RESIDUE | US_FL_SANE_SENSE ),
1838 1872
1839/* Reported by Robert Schedel <r.schedel@yahoo.de> 1873/* Reported by Robert Schedel <r.schedel@yahoo.de>
@@ -1841,7 +1875,7 @@ UNUSUAL_DEV( 0x152d, 0x2329, 0x0100, 0x0100,
1841UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201, 1875UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1842 "Teac", 1876 "Teac",
1843 "HD-35PUK-B", 1877 "HD-35PUK-B",
1844 US_SC_DEVICE, US_PR_DEVICE, NULL, 1878 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1845 US_FL_IGNORE_RESIDUE ), 1879 US_FL_IGNORE_RESIDUE ),
1846 1880
1847/* Reported by Hans de Goede <hdegoede@redhat.com> 1881/* Reported by Hans de Goede <hdegoede@redhat.com>
@@ -1851,18 +1885,48 @@ UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1851UNUSUAL_DEV( 0x1908, 0x1315, 0x0000, 0x0000, 1885UNUSUAL_DEV( 0x1908, 0x1315, 0x0000, 0x0000,
1852 "BUILDWIN", 1886 "BUILDWIN",
1853 "Photo Frame", 1887 "Photo Frame",
1854 US_SC_DEVICE, US_PR_DEVICE, NULL, 1888 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1855 US_FL_BAD_SENSE ), 1889 US_FL_BAD_SENSE ),
1856UNUSUAL_DEV( 0x1908, 0x1320, 0x0000, 0x0000, 1890UNUSUAL_DEV( 0x1908, 0x1320, 0x0000, 0x0000,
1857 "BUILDWIN", 1891 "BUILDWIN",
1858 "Photo Frame", 1892 "Photo Frame",
1859 US_SC_DEVICE, US_PR_DEVICE, NULL, 1893 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1860 US_FL_BAD_SENSE ), 1894 US_FL_BAD_SENSE ),
1895UNUSUAL_DEV( 0x1908, 0x3335, 0x0200, 0x0200,
1896 "BUILDWIN",
1897 "Photo Frame",
1898 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1899 US_FL_NO_READ_DISC_INFO ),
1900
1901/* Reported by Sven Geggus <sven-usbst@geggus.net>
1902 * This encrypted pen drive returns bogus data for the initial READ(10).
1903 */
1904UNUSUAL_DEV( 0x1b1c, 0x1ab5, 0x0200, 0x0200,
1905 "Corsair",
1906 "Padlock v2",
1907 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1908 US_FL_INITIAL_READ10 ),
1909
1910/* Patch by Richard Schütz <r.schtz@t-online.de>
1911 * This external hard drive enclosure uses a JMicron chip which
1912 * needs the US_FL_IGNORE_RESIDUE flag to work properly. */
1913UNUSUAL_DEV( 0x1e68, 0x001b, 0x0000, 0x0000,
1914 "TrekStor GmbH & Co. KG",
1915 "DataStation maxi g.u",
1916 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1917 US_FL_IGNORE_RESIDUE | US_FL_SANE_SENSE ),
1918
1919/* Reported by Jasper Mackenzie <scarletpimpernal@hotmail.com> */
1920UNUSUAL_DEV( 0x1e74, 0x4621, 0x0000, 0x0000,
1921 "Coby Electronics",
1922 "MP3 Player",
1923 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1924 US_FL_BULK_IGNORE_TAG | US_FL_MAX_SECTORS_64 ),
1861 1925
1862UNUSUAL_DEV( 0x2116, 0x0320, 0x0001, 0x0001, 1926UNUSUAL_DEV( 0x2116, 0x0320, 0x0001, 0x0001,
1863 "ST", 1927 "ST",
1864 "2A", 1928 "2A",
1865 US_SC_DEVICE, US_PR_DEVICE, NULL, 1929 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1866 US_FL_FIX_CAPACITY), 1930 US_FL_FIX_CAPACITY),
1867 1931
1868/* patch submitted by Davide Perini <perini.davide@dpsoftware.org> 1932/* patch submitted by Davide Perini <perini.davide@dpsoftware.org>
@@ -1871,7 +1935,7 @@ UNUSUAL_DEV( 0x2116, 0x0320, 0x0001, 0x0001,
1871UNUSUAL_DEV( 0x22b8, 0x3010, 0x0001, 0x0001, 1935UNUSUAL_DEV( 0x22b8, 0x3010, 0x0001, 0x0001,
1872 "Motorola", 1936 "Motorola",
1873 "RAZR V3x", 1937 "RAZR V3x",
1874 US_SC_DEVICE, US_PR_DEVICE, NULL, 1938 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1875 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), 1939 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
1876 1940
1877/* 1941/*
@@ -1882,14 +1946,14 @@ UNUSUAL_DEV( 0x22b8, 0x3010, 0x0001, 0x0001,
1882UNUSUAL_DEV( 0x22b8, 0x6426, 0x0101, 0x0101, 1946UNUSUAL_DEV( 0x22b8, 0x6426, 0x0101, 0x0101,
1883 "Motorola", 1947 "Motorola",
1884 "MSnc.", 1948 "MSnc.",
1885 US_SC_DEVICE, US_PR_DEVICE, NULL, 1949 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1886 US_FL_FIX_INQUIRY | US_FL_FIX_CAPACITY | US_FL_BULK_IGNORE_TAG), 1950 US_FL_FIX_INQUIRY | US_FL_FIX_CAPACITY | US_FL_BULK_IGNORE_TAG),
1887 1951
1888/* Reported by Radovan Garabik <garabik@kassiopeia.juls.savba.sk> */ 1952/* Reported by Radovan Garabik <garabik@kassiopeia.juls.savba.sk> */
1889UNUSUAL_DEV( 0x2735, 0x100b, 0x0000, 0x9999, 1953UNUSUAL_DEV( 0x2735, 0x100b, 0x0000, 0x9999,
1890 "MPIO", 1954 "MPIO",
1891 "HS200", 1955 "HS200",
1892 US_SC_DEVICE, US_PR_DEVICE, NULL, 1956 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1893 US_FL_GO_SLOW ), 1957 US_FL_GO_SLOW ),
1894 1958
1895/* Reported by Frederic Marchal <frederic.marchal@wowcompany.com> 1959/* Reported by Frederic Marchal <frederic.marchal@wowcompany.com>
@@ -1898,21 +1962,21 @@ UNUSUAL_DEV( 0x2735, 0x100b, 0x0000, 0x9999,
1898UNUSUAL_DEV( 0x3340, 0xffff, 0x0000, 0x0000, 1962UNUSUAL_DEV( 0x3340, 0xffff, 0x0000, 0x0000,
1899 "Mitac", 1963 "Mitac",
1900 "Mio DigiWalker USB Sync", 1964 "Mio DigiWalker USB Sync",
1901 US_SC_DEVICE,US_PR_DEVICE,NULL, 1965 USB_SC_DEVICE,USB_PR_DEVICE,NULL,
1902 US_FL_MAX_SECTORS_64 ), 1966 US_FL_MAX_SECTORS_64 ),
1903 1967
1904/* Reported by Andrey Rahmatullin <wrar@altlinux.org> */ 1968/* Reported by Andrey Rahmatullin <wrar@altlinux.org> */
1905UNUSUAL_DEV( 0x4102, 0x1020, 0x0100, 0x0100, 1969UNUSUAL_DEV( 0x4102, 0x1020, 0x0100, 0x0100,
1906 "iRiver", 1970 "iRiver",
1907 "MP3 T10", 1971 "MP3 T10",
1908 US_SC_DEVICE, US_PR_DEVICE, NULL, 1972 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1909 US_FL_IGNORE_RESIDUE ), 1973 US_FL_IGNORE_RESIDUE ),
1910 1974
1911/* Reported by Sergey Pinaev <dfo@antex.ru> */ 1975/* Reported by Sergey Pinaev <dfo@antex.ru> */
1912UNUSUAL_DEV( 0x4102, 0x1059, 0x0000, 0x0000, 1976UNUSUAL_DEV( 0x4102, 0x1059, 0x0000, 0x0000,
1913 "iRiver", 1977 "iRiver",
1914 "P7K", 1978 "P7K",
1915 US_SC_DEVICE, US_PR_DEVICE, NULL, 1979 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1916 US_FL_MAX_SECTORS_64 ), 1980 US_FL_MAX_SECTORS_64 ),
1917 1981
1918/* 1982/*
@@ -1922,41 +1986,41 @@ UNUSUAL_DEV( 0x4102, 0x1059, 0x0000, 0x0000,
1922UNUSUAL_DEV( 0x4146, 0xba01, 0x0100, 0x0100, 1986UNUSUAL_DEV( 0x4146, 0xba01, 0x0100, 0x0100,
1923 "Iomega", 1987 "Iomega",
1924 "Micro Mini 1GB", 1988 "Micro Mini 1GB",
1925 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ), 1989 USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ),
1926 1990
1927/* Reported by Andrew Simmons <andrew.simmons@gmail.com> */ 1991/* Reported by Andrew Simmons <andrew.simmons@gmail.com> */
1928UNUSUAL_DEV( 0xed06, 0x4500, 0x0001, 0x0001, 1992UNUSUAL_DEV( 0xed06, 0x4500, 0x0001, 0x0001,
1929 "DataStor", 1993 "DataStor",
1930 "USB4500 FW1.04", 1994 "USB4500 FW1.04",
1931 US_SC_DEVICE, US_PR_DEVICE, NULL, 1995 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1932 US_FL_CAPACITY_HEURISTICS), 1996 US_FL_CAPACITY_HEURISTICS),
1933 1997
1934/* Reported by Alessio Treglia <quadrispro@ubuntu.com> */ 1998/* Reported by Alessio Treglia <quadrispro@ubuntu.com> */
1935UNUSUAL_DEV( 0xed10, 0x7636, 0x0001, 0x0001, 1999UNUSUAL_DEV( 0xed10, 0x7636, 0x0001, 0x0001,
1936 "TGE", 2000 "TGE",
1937 "Digital MP3 Audio Player", 2001 "Digital MP3 Audio Player",
1938 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ), 2002 USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ),
1939 2003
1940/* Control/Bulk transport for all SubClass values */ 2004/* Control/Bulk transport for all SubClass values */
1941USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR), 2005USUAL_DEV(USB_SC_RBC, USB_PR_CB, USB_US_TYPE_STOR),
1942USUAL_DEV(US_SC_8020, US_PR_CB, USB_US_TYPE_STOR), 2006USUAL_DEV(USB_SC_8020, USB_PR_CB, USB_US_TYPE_STOR),
1943USUAL_DEV(US_SC_QIC, US_PR_CB, USB_US_TYPE_STOR), 2007USUAL_DEV(USB_SC_QIC, USB_PR_CB, USB_US_TYPE_STOR),
1944USUAL_DEV(US_SC_UFI, US_PR_CB, USB_US_TYPE_STOR), 2008USUAL_DEV(USB_SC_UFI, USB_PR_CB, USB_US_TYPE_STOR),
1945USUAL_DEV(US_SC_8070, US_PR_CB, USB_US_TYPE_STOR), 2009USUAL_DEV(USB_SC_8070, USB_PR_CB, USB_US_TYPE_STOR),
1946USUAL_DEV(US_SC_SCSI, US_PR_CB, USB_US_TYPE_STOR), 2010USUAL_DEV(USB_SC_SCSI, USB_PR_CB, USB_US_TYPE_STOR),
1947 2011
1948/* Control/Bulk/Interrupt transport for all SubClass values */ 2012/* Control/Bulk/Interrupt transport for all SubClass values */
1949USUAL_DEV(US_SC_RBC, US_PR_CBI, USB_US_TYPE_STOR), 2013USUAL_DEV(USB_SC_RBC, USB_PR_CBI, USB_US_TYPE_STOR),
1950USUAL_DEV(US_SC_8020, US_PR_CBI, USB_US_TYPE_STOR), 2014USUAL_DEV(USB_SC_8020, USB_PR_CBI, USB_US_TYPE_STOR),
1951USUAL_DEV(US_SC_QIC, US_PR_CBI, USB_US_TYPE_STOR), 2015USUAL_DEV(USB_SC_QIC, USB_PR_CBI, USB_US_TYPE_STOR),
1952USUAL_DEV(US_SC_UFI, US_PR_CBI, USB_US_TYPE_STOR), 2016USUAL_DEV(USB_SC_UFI, USB_PR_CBI, USB_US_TYPE_STOR),
1953USUAL_DEV(US_SC_8070, US_PR_CBI, USB_US_TYPE_STOR), 2017USUAL_DEV(USB_SC_8070, USB_PR_CBI, USB_US_TYPE_STOR),
1954USUAL_DEV(US_SC_SCSI, US_PR_CBI, USB_US_TYPE_STOR), 2018USUAL_DEV(USB_SC_SCSI, USB_PR_CBI, USB_US_TYPE_STOR),
1955 2019
1956/* Bulk-only transport for all SubClass values */ 2020/* Bulk-only transport for all SubClass values */
1957USUAL_DEV(US_SC_RBC, US_PR_BULK, USB_US_TYPE_STOR), 2021USUAL_DEV(USB_SC_RBC, USB_PR_BULK, USB_US_TYPE_STOR),
1958USUAL_DEV(US_SC_8020, US_PR_BULK, USB_US_TYPE_STOR), 2022USUAL_DEV(USB_SC_8020, USB_PR_BULK, USB_US_TYPE_STOR),
1959USUAL_DEV(US_SC_QIC, US_PR_BULK, USB_US_TYPE_STOR), 2023USUAL_DEV(USB_SC_QIC, USB_PR_BULK, USB_US_TYPE_STOR),
1960USUAL_DEV(US_SC_UFI, US_PR_BULK, USB_US_TYPE_STOR), 2024USUAL_DEV(USB_SC_UFI, USB_PR_BULK, USB_US_TYPE_STOR),
1961USUAL_DEV(US_SC_8070, US_PR_BULK, USB_US_TYPE_STOR), 2025USUAL_DEV(USB_SC_8070, USB_PR_BULK, USB_US_TYPE_STOR),
1962USUAL_DEV(US_SC_SCSI, US_PR_BULK, 0), 2026USUAL_DEV(USB_SC_SCSI, USB_PR_BULK, 0),
diff --git a/drivers/usb/storage/unusual_ene_ub6250.h b/drivers/usb/storage/unusual_ene_ub6250.h
new file mode 100644
index 000000000000..5667f5d365c6
--- /dev/null
+++ b/drivers/usb/storage/unusual_ene_ub6250.h
@@ -0,0 +1,26 @@
1/*
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
6 * later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#if defined(CONFIG_USB_STORAGE_ENE_UB6250) || \
19 defined(CONFIG_USB_STORAGE_ENE_UB6250_MODULE)
20
21UNUSUAL_DEV(0x0cf2, 0x6250, 0x0000, 0x9999,
22 "ENE",
23 "ENE UB6250 reader",
24 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 0),
25
26#endif /* defined(CONFIG_USB_STORAGE_ENE_UB6250) || ... */
diff --git a/drivers/usb/storage/unusual_freecom.h b/drivers/usb/storage/unusual_freecom.h
index 375867942391..59a261155b98 100644
--- a/drivers/usb/storage/unusual_freecom.h
+++ b/drivers/usb/storage/unusual_freecom.h
@@ -21,6 +21,6 @@
21UNUSUAL_DEV( 0x07ab, 0xfc01, 0x0000, 0x9999, 21UNUSUAL_DEV( 0x07ab, 0xfc01, 0x0000, 0x9999,
22 "Freecom", 22 "Freecom",
23 "USB-IDE", 23 "USB-IDE",
24 US_SC_QIC, US_PR_FREECOM, init_freecom, 0), 24 USB_SC_QIC, USB_PR_FREECOM, init_freecom, 0),
25 25
26#endif /* defined(CONFIG_USB_STORAGE_FREECOM) || ... */ 26#endif /* defined(CONFIG_USB_STORAGE_FREECOM) || ... */
diff --git a/drivers/usb/storage/unusual_isd200.h b/drivers/usb/storage/unusual_isd200.h
index 0d99dde3382a..14cca0c48302 100644
--- a/drivers/usb/storage/unusual_isd200.h
+++ b/drivers/usb/storage/unusual_isd200.h
@@ -21,37 +21,37 @@
21UNUSUAL_DEV( 0x054c, 0x002b, 0x0100, 0x0110, 21UNUSUAL_DEV( 0x054c, 0x002b, 0x0100, 0x0110,
22 "Sony", 22 "Sony",
23 "Portable USB Harddrive V2", 23 "Portable USB Harddrive V2",
24 US_SC_ISD200, US_PR_BULK, isd200_Initialization, 24 USB_SC_ISD200, USB_PR_BULK, isd200_Initialization,
25 0), 25 0),
26 26
27UNUSUAL_DEV( 0x05ab, 0x0031, 0x0100, 0x0110, 27UNUSUAL_DEV( 0x05ab, 0x0031, 0x0100, 0x0110,
28 "In-System", 28 "In-System",
29 "USB/IDE Bridge (ATA/ATAPI)", 29 "USB/IDE Bridge (ATA/ATAPI)",
30 US_SC_ISD200, US_PR_BULK, isd200_Initialization, 30 USB_SC_ISD200, USB_PR_BULK, isd200_Initialization,
31 0), 31 0),
32 32
33UNUSUAL_DEV( 0x05ab, 0x0301, 0x0100, 0x0110, 33UNUSUAL_DEV( 0x05ab, 0x0301, 0x0100, 0x0110,
34 "In-System", 34 "In-System",
35 "Portable USB Harddrive V2", 35 "Portable USB Harddrive V2",
36 US_SC_ISD200, US_PR_BULK, isd200_Initialization, 36 USB_SC_ISD200, USB_PR_BULK, isd200_Initialization,
37 0), 37 0),
38 38
39UNUSUAL_DEV( 0x05ab, 0x0351, 0x0100, 0x0110, 39UNUSUAL_DEV( 0x05ab, 0x0351, 0x0100, 0x0110,
40 "In-System", 40 "In-System",
41 "Portable USB Harddrive V2", 41 "Portable USB Harddrive V2",
42 US_SC_ISD200, US_PR_BULK, isd200_Initialization, 42 USB_SC_ISD200, USB_PR_BULK, isd200_Initialization,
43 0), 43 0),
44 44
45UNUSUAL_DEV( 0x05ab, 0x5701, 0x0100, 0x0110, 45UNUSUAL_DEV( 0x05ab, 0x5701, 0x0100, 0x0110,
46 "In-System", 46 "In-System",
47 "USB Storage Adapter V2", 47 "USB Storage Adapter V2",
48 US_SC_ISD200, US_PR_BULK, isd200_Initialization, 48 USB_SC_ISD200, USB_PR_BULK, isd200_Initialization,
49 0), 49 0),
50 50
51UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110, 51UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110,
52 "ATI", 52 "ATI",
53 "USB Cable 205", 53 "USB Cable 205",
54 US_SC_ISD200, US_PR_BULK, isd200_Initialization, 54 USB_SC_ISD200, USB_PR_BULK, isd200_Initialization,
55 0), 55 0),
56 56
57#endif /* defined(CONFIG_USB_STORAGE_ISD200) || ... */ 57#endif /* defined(CONFIG_USB_STORAGE_ISD200) || ... */
diff --git a/drivers/usb/storage/unusual_jumpshot.h b/drivers/usb/storage/unusual_jumpshot.h
index 2e549b1c2c62..54be78b5d643 100644
--- a/drivers/usb/storage/unusual_jumpshot.h
+++ b/drivers/usb/storage/unusual_jumpshot.h
@@ -21,7 +21,7 @@
21UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001, 21UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001,
22 "Lexar", 22 "Lexar",
23 "Jumpshot USB CF Reader", 23 "Jumpshot USB CF Reader",
24 US_SC_SCSI, US_PR_JUMPSHOT, NULL, 24 USB_SC_SCSI, USB_PR_JUMPSHOT, NULL,
25 US_FL_NEED_OVERRIDE), 25 US_FL_NEED_OVERRIDE),
26 26
27#endif /* defined(CONFIG_USB_STORAGE_JUMPSHOT) || ... */ 27#endif /* defined(CONFIG_USB_STORAGE_JUMPSHOT) || ... */
diff --git a/drivers/usb/storage/unusual_karma.h b/drivers/usb/storage/unusual_karma.h
index 12ae3a03e802..6df03972a22c 100644
--- a/drivers/usb/storage/unusual_karma.h
+++ b/drivers/usb/storage/unusual_karma.h
@@ -21,6 +21,6 @@
21UNUSUAL_DEV( 0x045a, 0x5210, 0x0101, 0x0101, 21UNUSUAL_DEV( 0x045a, 0x5210, 0x0101, 0x0101,
22 "Rio", 22 "Rio",
23 "Rio Karma", 23 "Rio Karma",
24 US_SC_SCSI, US_PR_KARMA, rio_karma_init, 0), 24 USB_SC_SCSI, USB_PR_KARMA, rio_karma_init, 0),
25 25
26#endif /* defined(CONFIG_USB_STORAGE_KARMA) || ... */ 26#endif /* defined(CONFIG_USB_STORAGE_KARMA) || ... */
diff --git a/drivers/usb/storage/unusual_onetouch.h b/drivers/usb/storage/unusual_onetouch.h
index bd9306b637df..0abb819c7405 100644
--- a/drivers/usb/storage/unusual_onetouch.h
+++ b/drivers/usb/storage/unusual_onetouch.h
@@ -24,13 +24,13 @@
24UNUSUAL_DEV( 0x0d49, 0x7000, 0x0000, 0x9999, 24UNUSUAL_DEV( 0x0d49, 0x7000, 0x0000, 0x9999,
25 "Maxtor", 25 "Maxtor",
26 "OneTouch External Harddrive", 26 "OneTouch External Harddrive",
27 US_SC_DEVICE, US_PR_DEVICE, onetouch_connect_input, 27 USB_SC_DEVICE, USB_PR_DEVICE, onetouch_connect_input,
28 0), 28 0),
29 29
30UNUSUAL_DEV( 0x0d49, 0x7010, 0x0000, 0x9999, 30UNUSUAL_DEV( 0x0d49, 0x7010, 0x0000, 0x9999,
31 "Maxtor", 31 "Maxtor",
32 "OneTouch External Harddrive", 32 "OneTouch External Harddrive",
33 US_SC_DEVICE, US_PR_DEVICE, onetouch_connect_input, 33 USB_SC_DEVICE, USB_PR_DEVICE, onetouch_connect_input,
34 0), 34 0),
35 35
36#endif /* defined(CONFIG_USB_STORAGE_ONETOUCH) || ... */ 36#endif /* defined(CONFIG_USB_STORAGE_ONETOUCH) || ... */
diff --git a/drivers/usb/storage/unusual_realtek.h b/drivers/usb/storage/unusual_realtek.h
new file mode 100644
index 000000000000..e41f50c95ed4
--- /dev/null
+++ b/drivers/usb/storage/unusual_realtek.h
@@ -0,0 +1,41 @@
1/* Driver for Realtek RTS51xx USB card reader
2 *
3 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
8 * later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 * wwang (wei_wang@realsil.com.cn)
20 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
21 */
22
23#if defined(CONFIG_USB_STORAGE_REALTEK) || \
24 defined(CONFIG_USB_STORAGE_REALTEK_MODULE)
25
26UNUSUAL_DEV(0x0bda, 0x0138, 0x0000, 0x9999,
27 "Realtek",
28 "USB Card Reader",
29 USB_SC_DEVICE, USB_PR_DEVICE, init_realtek_cr, 0),
30
31UNUSUAL_DEV(0x0bda, 0x0158, 0x0000, 0x9999,
32 "Realtek",
33 "USB Card Reader",
34 USB_SC_DEVICE, USB_PR_DEVICE, init_realtek_cr, 0),
35
36UNUSUAL_DEV(0x0bda, 0x0159, 0x0000, 0x9999,
37 "Realtek",
38 "USB Card Reader",
39 USB_SC_DEVICE, USB_PR_DEVICE, init_realtek_cr, 0),
40
41#endif /* defined(CONFIG_USB_STORAGE_REALTEK) || ... */
diff --git a/drivers/usb/storage/unusual_sddr09.h b/drivers/usb/storage/unusual_sddr09.h
index 50cab511a4d7..59a7e37b6c11 100644
--- a/drivers/usb/storage/unusual_sddr09.h
+++ b/drivers/usb/storage/unusual_sddr09.h
@@ -21,36 +21,36 @@
21UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, 21UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
22 "Microtech", 22 "Microtech",
23 "CameraMate (DPCM_USB)", 23 "CameraMate (DPCM_USB)",
24 US_SC_SCSI, US_PR_DPCM_USB, NULL, 0), 24 USB_SC_SCSI, USB_PR_DPCM_USB, NULL, 0),
25 25
26UNUSUAL_DEV( 0x04e6, 0x0003, 0x0000, 0x9999, 26UNUSUAL_DEV( 0x04e6, 0x0003, 0x0000, 0x9999,
27 "Sandisk", 27 "Sandisk",
28 "ImageMate SDDR09", 28 "ImageMate SDDR09",
29 US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init, 29 USB_SC_SCSI, USB_PR_EUSB_SDDR09, usb_stor_sddr09_init,
30 0), 30 0),
31 31
32/* This entry is from Andries.Brouwer@cwi.nl */ 32/* This entry is from Andries.Brouwer@cwi.nl */
33UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208, 33UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208,
34 "SCM Microsystems", 34 "SCM Microsystems",
35 "eUSB SmartMedia / CompactFlash Adapter", 35 "eUSB SmartMedia / CompactFlash Adapter",
36 US_SC_SCSI, US_PR_DPCM_USB, usb_stor_sddr09_dpcm_init, 36 USB_SC_SCSI, USB_PR_DPCM_USB, usb_stor_sddr09_dpcm_init,
37 0), 37 0),
38 38
39UNUSUAL_DEV( 0x066b, 0x0105, 0x0100, 0x0100, 39UNUSUAL_DEV( 0x066b, 0x0105, 0x0100, 0x0100,
40 "Olympus", 40 "Olympus",
41 "Camedia MAUSB-2", 41 "Camedia MAUSB-2",
42 US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init, 42 USB_SC_SCSI, USB_PR_EUSB_SDDR09, usb_stor_sddr09_init,
43 0), 43 0),
44 44
45UNUSUAL_DEV( 0x0781, 0x0200, 0x0000, 0x9999, 45UNUSUAL_DEV( 0x0781, 0x0200, 0x0000, 0x9999,
46 "Sandisk", 46 "Sandisk",
47 "ImageMate SDDR-09", 47 "ImageMate SDDR-09",
48 US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init, 48 USB_SC_SCSI, USB_PR_EUSB_SDDR09, usb_stor_sddr09_init,
49 0), 49 0),
50 50
51UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100, 51UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100,
52 "Microtech", 52 "Microtech",
53 "CameraMate (DPCM_USB)", 53 "CameraMate (DPCM_USB)",
54 US_SC_SCSI, US_PR_DPCM_USB, NULL, 0), 54 USB_SC_SCSI, USB_PR_DPCM_USB, NULL, 0),
55 55
56#endif /* defined(CONFIG_USB_STORAGE_SDDR09) || ... */ 56#endif /* defined(CONFIG_USB_STORAGE_SDDR09) || ... */
diff --git a/drivers/usb/storage/unusual_sddr55.h b/drivers/usb/storage/unusual_sddr55.h
index ae81ef7a1cfd..fcb7e12c598f 100644
--- a/drivers/usb/storage/unusual_sddr55.h
+++ b/drivers/usb/storage/unusual_sddr55.h
@@ -22,23 +22,23 @@
22UNUSUAL_DEV( 0x07c4, 0xa103, 0x0000, 0x9999, 22UNUSUAL_DEV( 0x07c4, 0xa103, 0x0000, 0x9999,
23 "Datafab", 23 "Datafab",
24 "MDSM-B reader", 24 "MDSM-B reader",
25 US_SC_SCSI, US_PR_SDDR55, NULL, 25 USB_SC_SCSI, USB_PR_SDDR55, NULL,
26 US_FL_FIX_INQUIRY), 26 US_FL_FIX_INQUIRY),
27 27
28/* SM part - aeb <Andries.Brouwer@cwi.nl> */ 28/* SM part - aeb <Andries.Brouwer@cwi.nl> */
29UNUSUAL_DEV( 0x07c4, 0xa109, 0x0000, 0xffff, 29UNUSUAL_DEV( 0x07c4, 0xa109, 0x0000, 0xffff,
30 "Datafab Systems, Inc.", 30 "Datafab Systems, Inc.",
31 "USB to CF + SM Combo (LC1)", 31 "USB to CF + SM Combo (LC1)",
32 US_SC_SCSI, US_PR_SDDR55, NULL, 0), 32 USB_SC_SCSI, USB_PR_SDDR55, NULL, 0),
33 33
34UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff, 34UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff,
35 "Acomdata", 35 "Acomdata",
36 "SM", 36 "SM",
37 US_SC_SCSI, US_PR_SDDR55, NULL, 0), 37 USB_SC_SCSI, USB_PR_SDDR55, NULL, 0),
38 38
39UNUSUAL_DEV( 0x55aa, 0xa103, 0x0000, 0x9999, 39UNUSUAL_DEV( 0x55aa, 0xa103, 0x0000, 0x9999,
40 "Sandisk", 40 "Sandisk",
41 "ImageMate SDDR55", 41 "ImageMate SDDR55",
42 US_SC_SCSI, US_PR_SDDR55, NULL, 0), 42 USB_SC_SCSI, USB_PR_SDDR55, NULL, 0),
43 43
44#endif /* defined(CONFIG_USB_STORAGE_SDDR55) || ... */ 44#endif /* defined(CONFIG_USB_STORAGE_SDDR55) || ... */
diff --git a/drivers/usb/storage/unusual_usbat.h b/drivers/usb/storage/unusual_usbat.h
index 80e869f10180..38e79c4e6d6a 100644
--- a/drivers/usb/storage/unusual_usbat.h
+++ b/drivers/usb/storage/unusual_usbat.h
@@ -21,23 +21,23 @@
21UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001, 21UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001,
22 "HP", 22 "HP",
23 "CD-Writer+ 8200e", 23 "CD-Writer+ 8200e",
24 US_SC_8070, US_PR_USBAT, init_usbat_cd, 0), 24 USB_SC_8070, USB_PR_USBAT, init_usbat_cd, 0),
25 25
26UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001, 26UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001,
27 "HP", 27 "HP",
28 "CD-Writer+ CD-4e", 28 "CD-Writer+ CD-4e",
29 US_SC_8070, US_PR_USBAT, init_usbat_cd, 0), 29 USB_SC_8070, USB_PR_USBAT, init_usbat_cd, 0),
30 30
31UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999, 31UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999,
32 "Shuttle/SCM", 32 "Shuttle/SCM",
33 "USBAT-02", 33 "USBAT-02",
34 US_SC_SCSI, US_PR_USBAT, init_usbat_flash, 34 USB_SC_SCSI, USB_PR_USBAT, init_usbat_flash,
35 US_FL_SINGLE_LUN), 35 US_FL_SINGLE_LUN),
36 36
37UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005, 37UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005,
38 "Sandisk", 38 "Sandisk",
39 "ImageMate SDDR-05b", 39 "ImageMate SDDR-05b",
40 US_SC_SCSI, US_PR_USBAT, init_usbat_flash, 40 USB_SC_SCSI, USB_PR_USBAT, init_usbat_flash,
41 US_FL_SINGLE_LUN), 41 US_FL_SINGLE_LUN),
42 42
43#endif /* defined(CONFIG_USB_STORAGE_USBAT) || ... */ 43#endif /* defined(CONFIG_USB_STORAGE_USBAT) || ... */
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 90bb0175a152..0ca095820f3e 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -439,7 +439,9 @@ static void adjust_quirks(struct us_data *us)
439 US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE | 439 US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE |
440 US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 | 440 US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 |
441 US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE | 441 US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE |
442 US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT); 442 US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT |
443 US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 |
444 US_FL_INITIAL_READ10);
443 445
444 p = quirks; 446 p = quirks;
445 while (*p) { 447 while (*p) {
@@ -471,6 +473,12 @@ static void adjust_quirks(struct us_data *us)
471 case 'c': 473 case 'c':
472 f |= US_FL_FIX_CAPACITY; 474 f |= US_FL_FIX_CAPACITY;
473 break; 475 break;
476 case 'd':
477 f |= US_FL_NO_READ_DISC_INFO;
478 break;
479 case 'e':
480 f |= US_FL_NO_READ_CAPACITY_16;
481 break;
474 case 'h': 482 case 'h':
475 f |= US_FL_CAPACITY_HEURISTICS; 483 f |= US_FL_CAPACITY_HEURISTICS;
476 break; 484 break;
@@ -483,6 +491,9 @@ static void adjust_quirks(struct us_data *us)
483 case 'm': 491 case 'm':
484 f |= US_FL_MAX_SECTORS_64; 492 f |= US_FL_MAX_SECTORS_64;
485 break; 493 break;
494 case 'n':
495 f |= US_FL_INITIAL_READ10;
496 break;
486 case 'o': 497 case 'o':
487 f |= US_FL_CAPACITY_OK; 498 f |= US_FL_CAPACITY_OK;
488 break; 499 break;
@@ -512,10 +523,10 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id,
512 523
513 /* Store the entries */ 524 /* Store the entries */
514 us->unusual_dev = unusual_dev; 525 us->unusual_dev = unusual_dev;
515 us->subclass = (unusual_dev->useProtocol == US_SC_DEVICE) ? 526 us->subclass = (unusual_dev->useProtocol == USB_SC_DEVICE) ?
516 idesc->bInterfaceSubClass : 527 idesc->bInterfaceSubClass :
517 unusual_dev->useProtocol; 528 unusual_dev->useProtocol;
518 us->protocol = (unusual_dev->useTransport == US_PR_DEVICE) ? 529 us->protocol = (unusual_dev->useTransport == USB_PR_DEVICE) ?
519 idesc->bInterfaceProtocol : 530 idesc->bInterfaceProtocol :
520 unusual_dev->useTransport; 531 unusual_dev->useTransport;
521 us->fflags = USB_US_ORIG_FLAGS(id->driver_info); 532 us->fflags = USB_US_ORIG_FLAGS(id->driver_info);
@@ -552,10 +563,10 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id,
552 struct usb_device_descriptor *ddesc = &dev->descriptor; 563 struct usb_device_descriptor *ddesc = &dev->descriptor;
553 int msg = -1; 564 int msg = -1;
554 565
555 if (unusual_dev->useProtocol != US_SC_DEVICE && 566 if (unusual_dev->useProtocol != USB_SC_DEVICE &&
556 us->subclass == idesc->bInterfaceSubClass) 567 us->subclass == idesc->bInterfaceSubClass)
557 msg += 1; 568 msg += 1;
558 if (unusual_dev->useTransport != US_PR_DEVICE && 569 if (unusual_dev->useTransport != USB_PR_DEVICE &&
559 us->protocol == idesc->bInterfaceProtocol) 570 us->protocol == idesc->bInterfaceProtocol)
560 msg += 2; 571 msg += 2;
561 if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE)) 572 if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE))
@@ -582,21 +593,21 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id,
582static void get_transport(struct us_data *us) 593static void get_transport(struct us_data *us)
583{ 594{
584 switch (us->protocol) { 595 switch (us->protocol) {
585 case US_PR_CB: 596 case USB_PR_CB:
586 us->transport_name = "Control/Bulk"; 597 us->transport_name = "Control/Bulk";
587 us->transport = usb_stor_CB_transport; 598 us->transport = usb_stor_CB_transport;
588 us->transport_reset = usb_stor_CB_reset; 599 us->transport_reset = usb_stor_CB_reset;
589 us->max_lun = 7; 600 us->max_lun = 7;
590 break; 601 break;
591 602
592 case US_PR_CBI: 603 case USB_PR_CBI:
593 us->transport_name = "Control/Bulk/Interrupt"; 604 us->transport_name = "Control/Bulk/Interrupt";
594 us->transport = usb_stor_CB_transport; 605 us->transport = usb_stor_CB_transport;
595 us->transport_reset = usb_stor_CB_reset; 606 us->transport_reset = usb_stor_CB_reset;
596 us->max_lun = 7; 607 us->max_lun = 7;
597 break; 608 break;
598 609
599 case US_PR_BULK: 610 case USB_PR_BULK:
600 us->transport_name = "Bulk"; 611 us->transport_name = "Bulk";
601 us->transport = usb_stor_Bulk_transport; 612 us->transport = usb_stor_Bulk_transport;
602 us->transport_reset = usb_stor_Bulk_reset; 613 us->transport_reset = usb_stor_Bulk_reset;
@@ -608,35 +619,35 @@ static void get_transport(struct us_data *us)
608static void get_protocol(struct us_data *us) 619static void get_protocol(struct us_data *us)
609{ 620{
610 switch (us->subclass) { 621 switch (us->subclass) {
611 case US_SC_RBC: 622 case USB_SC_RBC:
612 us->protocol_name = "Reduced Block Commands (RBC)"; 623 us->protocol_name = "Reduced Block Commands (RBC)";
613 us->proto_handler = usb_stor_transparent_scsi_command; 624 us->proto_handler = usb_stor_transparent_scsi_command;
614 break; 625 break;
615 626
616 case US_SC_8020: 627 case USB_SC_8020:
617 us->protocol_name = "8020i"; 628 us->protocol_name = "8020i";
618 us->proto_handler = usb_stor_pad12_command; 629 us->proto_handler = usb_stor_pad12_command;
619 us->max_lun = 0; 630 us->max_lun = 0;
620 break; 631 break;
621 632
622 case US_SC_QIC: 633 case USB_SC_QIC:
623 us->protocol_name = "QIC-157"; 634 us->protocol_name = "QIC-157";
624 us->proto_handler = usb_stor_pad12_command; 635 us->proto_handler = usb_stor_pad12_command;
625 us->max_lun = 0; 636 us->max_lun = 0;
626 break; 637 break;
627 638
628 case US_SC_8070: 639 case USB_SC_8070:
629 us->protocol_name = "8070i"; 640 us->protocol_name = "8070i";
630 us->proto_handler = usb_stor_pad12_command; 641 us->proto_handler = usb_stor_pad12_command;
631 us->max_lun = 0; 642 us->max_lun = 0;
632 break; 643 break;
633 644
634 case US_SC_SCSI: 645 case USB_SC_SCSI:
635 us->protocol_name = "Transparent SCSI"; 646 us->protocol_name = "Transparent SCSI";
636 us->proto_handler = usb_stor_transparent_scsi_command; 647 us->proto_handler = usb_stor_transparent_scsi_command;
637 break; 648 break;
638 649
639 case US_SC_UFI: 650 case USB_SC_UFI:
640 us->protocol_name = "Uniform Floppy Interface (UFI)"; 651 us->protocol_name = "Uniform Floppy Interface (UFI)";
641 us->proto_handler = usb_stor_ufi_command; 652 us->proto_handler = usb_stor_ufi_command;
642 break; 653 break;
@@ -679,7 +690,7 @@ static int get_pipes(struct us_data *us)
679 } 690 }
680 } 691 }
681 692
682 if (!ep_in || !ep_out || (us->protocol == US_PR_CBI && !ep_int)) { 693 if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) {
683 US_DEBUGP("Endpoint sanity check failed! Rejecting dev.\n"); 694 US_DEBUGP("Endpoint sanity check failed! Rejecting dev.\n");
684 return -EIO; 695 return -EIO;
685 } 696 }
@@ -834,7 +845,7 @@ static int usb_stor_scan_thread(void * __us)
834 if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) { 845 if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) {
835 846
836 /* For bulk-only devices, determine the max LUN value */ 847 /* For bulk-only devices, determine the max LUN value */
837 if (us->protocol == US_PR_BULK && 848 if (us->protocol == USB_PR_BULK &&
838 !(us->fflags & US_FL_SINGLE_LUN)) { 849 !(us->fflags & US_FL_SINGLE_LUN)) {
839 mutex_lock(&us->dev_mutex); 850 mutex_lock(&us->dev_mutex);
840 us->max_lun = usb_stor_Bulk_max_lun(us); 851 us->max_lun = usb_stor_Bulk_max_lun(us);
@@ -946,6 +957,13 @@ int usb_stor_probe2(struct us_data *us)
946 if (result) 957 if (result)
947 goto BadDevice; 958 goto BadDevice;
948 959
960 /*
961 * If the device returns invalid data for the first READ(10)
962 * command, indicate the command should be retried.
963 */
964 if (us->fflags & US_FL_INITIAL_READ10)
965 set_bit(US_FLIDX_REDO_READ10, &us->dflags);
966
949 /* Acquire all the other resources and add the host */ 967 /* Acquire all the other resources and add the host */
950 result = usb_stor_acquire_resources(us); 968 result = usb_stor_acquire_resources(us);
951 if (result) 969 if (result)
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 89d3bfff98df..7b0f2113632e 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -73,6 +73,8 @@ struct us_unusual_dev {
73#define US_FLIDX_RESETTING 4 /* device reset in progress */ 73#define US_FLIDX_RESETTING 4 /* device reset in progress */
74#define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */ 74#define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
75#define US_FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */ 75#define US_FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */
76#define US_FLIDX_REDO_READ10 7 /* redo READ(10) command */
77#define US_FLIDX_READ10_WORKED 8 /* previous READ(10) succeeded */
76 78
77#define USB_STOR_STRING_LEN 32 79#define USB_STOR_STRING_LEN 32
78 80
diff --git a/drivers/usb/storage/usual-tables.c b/drivers/usb/storage/usual-tables.c
index 468bde7d1971..b96927914f89 100644
--- a/drivers/usb/storage/usual-tables.c
+++ b/drivers/usb/storage/usual-tables.c
@@ -80,11 +80,13 @@ static struct ignore_entry ignore_ids[] = {
80# include "unusual_alauda.h" 80# include "unusual_alauda.h"
81# include "unusual_cypress.h" 81# include "unusual_cypress.h"
82# include "unusual_datafab.h" 82# include "unusual_datafab.h"
83# include "unusual_ene_ub6250.h"
83# include "unusual_freecom.h" 84# include "unusual_freecom.h"
84# include "unusual_isd200.h" 85# include "unusual_isd200.h"
85# include "unusual_jumpshot.h" 86# include "unusual_jumpshot.h"
86# include "unusual_karma.h" 87# include "unusual_karma.h"
87# include "unusual_onetouch.h" 88# include "unusual_onetouch.h"
89# include "unusual_realtek.h"
88# include "unusual_sddr09.h" 90# include "unusual_sddr09.h"
89# include "unusual_sddr55.h" 91# include "unusual_sddr55.h"
90# include "unusual_usbat.h" 92# include "unusual_usbat.h"
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 552679b8dbd1..e24ce3123071 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -507,6 +507,7 @@ static const struct file_operations skel_fops = {
507 .open = skel_open, 507 .open = skel_open,
508 .release = skel_release, 508 .release = skel_release,
509 .flush = skel_flush, 509 .flush = skel_flush,
510 .llseek = noop_llseek,
510}; 511};
511 512
512/* 513/*
diff --git a/drivers/usb/wusbcore/Makefile b/drivers/usb/wusbcore/Makefile
index 75f1ade66258..b3bd313032b1 100644
--- a/drivers/usb/wusbcore/Makefile
+++ b/drivers/usb/wusbcore/Makefile
@@ -1,9 +1,11 @@
1ccflags-$(CONFIG_USB_WUSB_CBAF_DEBUG) := -DDEBUG
2
1obj-$(CONFIG_USB_WUSB) += wusbcore.o 3obj-$(CONFIG_USB_WUSB) += wusbcore.o
2obj-$(CONFIG_USB_HWA_HCD) += wusb-wa.o 4obj-$(CONFIG_USB_HWA_HCD) += wusb-wa.o
3obj-$(CONFIG_USB_WUSB_CBAF) += wusb-cbaf.o 5obj-$(CONFIG_USB_WUSB_CBAF) += wusb-cbaf.o
4 6
5 7
6wusbcore-objs := \ 8wusbcore-y := \
7 crypto.o \ 9 crypto.o \
8 devconnect.o \ 10 devconnect.o \
9 dev-sysfs.o \ 11 dev-sysfs.o \
@@ -14,13 +16,10 @@ wusbcore-objs := \
14 security.o \ 16 security.o \
15 wusbhc.o 17 wusbhc.o
16 18
17wusb-cbaf-objs := cbaf.o 19wusb-cbaf-y := cbaf.o
18
19wusb-wa-objs := wa-hc.o \
20 wa-nep.o \
21 wa-rpipe.o \
22 wa-xfer.o
23 20
24ifeq ($(CONFIG_USB_WUSB_CBAF_DEBUG),y) 21wusb-wa-y := \
25EXTRA_CFLAGS += -DDEBUG 22 wa-hc.o \
26endif 23 wa-nep.o \
24 wa-rpipe.o \
25 wa-xfer.o
diff --git a/drivers/usb/wusbcore/crypto.c b/drivers/usb/wusbcore/crypto.c
index 827c87f10cc5..7e4bf95f8f7b 100644
--- a/drivers/usb/wusbcore/crypto.c
+++ b/drivers/usb/wusbcore/crypto.c
@@ -180,7 +180,7 @@ static void bytewise_xor(void *_bo, const void *_bi1, const void *_bi2,
180 * using the 14 bytes of @a to fill up 180 * using the 14 bytes of @a to fill up
181 * b1.{mac_header,e0,security_reserved,padding}. 181 * b1.{mac_header,e0,security_reserved,padding}.
182 * 182 *
183 * NOTE: The definiton of l(a) in WUSB1.0[6.5] vs the definition of 183 * NOTE: The definition of l(a) in WUSB1.0[6.5] vs the definition of
184 * l(m) is orthogonal, they bear no relationship, so it is not 184 * l(m) is orthogonal, they bear no relationship, so it is not
185 * in conflict with the parameter's relation that 185 * in conflict with the parameter's relation that
186 * WUSB1.0[6.4.2]) defines. 186 * WUSB1.0[6.4.2]) defines.
@@ -272,7 +272,7 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc,
272 272
273 /* Now we crypt the MIC Tag (*iv) with Ax -- values per WUSB1.0[6.5] 273 /* Now we crypt the MIC Tag (*iv) with Ax -- values per WUSB1.0[6.5]
274 * The procedure is to AES crypt the A0 block and XOR the MIC 274 * The procedure is to AES crypt the A0 block and XOR the MIC
275 * Tag agains it; we only do the first 8 bytes and place it 275 * Tag against it; we only do the first 8 bytes and place it
276 * directly in the destination buffer. 276 * directly in the destination buffer.
277 * 277 *
278 * POS Crypto API: size is assumed to be AES's block size. 278 * POS Crypto API: size is assumed to be AES's block size.
diff --git a/drivers/usb/wusbcore/reservation.c b/drivers/usb/wusbcore/reservation.c
index 4ed97360c046..6f4fafdc2401 100644
--- a/drivers/usb/wusbcore/reservation.c
+++ b/drivers/usb/wusbcore/reservation.c
@@ -71,7 +71,7 @@ static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv)
71 71
72/** 72/**
73 * wusbhc_rsv_establish - establish a reservation for the cluster 73 * wusbhc_rsv_establish - establish a reservation for the cluster
74 * @wusbhc: the WUSB HC requesting a bandwith reservation 74 * @wusbhc: the WUSB HC requesting a bandwidth reservation
75 */ 75 */
76int wusbhc_rsv_establish(struct wusbhc *wusbhc) 76int wusbhc_rsv_establish(struct wusbhc *wusbhc)
77{ 77{
diff --git a/drivers/usb/wusbcore/rh.c b/drivers/usb/wusbcore/rh.c
index a68ad7aa0b59..39de3900ad20 100644
--- a/drivers/usb/wusbcore/rh.c
+++ b/drivers/usb/wusbcore/rh.c
@@ -133,7 +133,7 @@ static int wusbhc_rh_port_reset(struct wusbhc *wusbhc, u8 port_idx)
133 * big of a problem [and we can't make it an spinlock 133 * big of a problem [and we can't make it an spinlock
134 * because other parts need to take it and sleep] . 134 * because other parts need to take it and sleep] .
135 * 135 *
136 * @usb_hcd is refcounted, so it won't dissapear under us 136 * @usb_hcd is refcounted, so it won't disappear under us
137 * and before killing a host, the polling of the root hub 137 * and before killing a host, the polling of the root hub
138 * would be stopped anyway. 138 * would be stopped anyway.
139 */ 139 */
@@ -156,7 +156,7 @@ int wusbhc_rh_status_data(struct usb_hcd *usb_hcd, char *_buf)
156EXPORT_SYMBOL_GPL(wusbhc_rh_status_data); 156EXPORT_SYMBOL_GPL(wusbhc_rh_status_data);
157 157
158/* 158/*
159 * Return the hub's desciptor 159 * Return the hub's descriptor
160 * 160 *
161 * NOTE: almost cut and paste from ehci-hub.c 161 * NOTE: almost cut and paste from ehci-hub.c
162 * 162 *
@@ -184,8 +184,8 @@ static int wusbhc_rh_get_hub_descr(struct wusbhc *wusbhc, u16 wValue,
184 descr->bPwrOn2PwrGood = 0; 184 descr->bPwrOn2PwrGood = 0;
185 descr->bHubContrCurrent = 0; 185 descr->bHubContrCurrent = 0;
186 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 186 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
187 memset(&descr->bitmap[0], 0, temp); 187 memset(&descr->u.hs.DeviceRemovable[0], 0, temp);
188 memset(&descr->bitmap[temp], 0xff, temp); 188 memset(&descr->u.hs.DeviceRemovable[temp], 0xff, temp);
189 return 0; 189 return 0;
190} 190}
191 191
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c
index c7b1d8108de9..ca80171f42c6 100644
--- a/drivers/usb/wusbcore/wa-rpipe.c
+++ b/drivers/usb/wusbcore/wa-rpipe.c
@@ -24,7 +24,7 @@
24 * 24 *
25 * RPIPE 25 * RPIPE
26 * 26 *
27 * Targetted at different downstream endpoints 27 * Targeted at different downstream endpoints
28 * 28 *
29 * Descriptor: use to config the remote pipe. 29 * Descriptor: use to config the remote pipe.
30 * 30 *
@@ -49,7 +49,7 @@
49 * 49 *
50 * USB Stack port number 4 (1 based) 50 * USB Stack port number 4 (1 based)
51 * WUSB code port index 3 (0 based) 51 * WUSB code port index 3 (0 based)
52 * USB Addresss 5 (2 based -- 0 is for default, 1 for root hub) 52 * USB Address 5 (2 based -- 0 is for default, 1 for root hub)
53 * 53 *
54 * Now, because we don't use the concept as default address exactly 54 * Now, because we don't use the concept as default address exactly
55 * like the (wired) USB code does, we need to kind of skip it. So we 55 * like the (wired) USB code does, we need to kind of skip it. So we
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 84b744c428a4..6ccd93a9b909 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -61,7 +61,7 @@
61 * 61 *
62 * Two methods it could be done: 62 * Two methods it could be done:
63 * 63 *
64 * (a) set up a timer everytime an rpipe's use count drops to 1 64 * (a) set up a timer every time an rpipe's use count drops to 1
65 * (which means unused) or when a transfer ends. Reset the 65 * (which means unused) or when a transfer ends. Reset the
66 * timer when a xfer is queued. If the timer expires, release 66 * timer when a xfer is queued. If the timer expires, release
67 * the rpipe [see rpipe_ep_disable()]. 67 * the rpipe [see rpipe_ep_disable()].
@@ -140,7 +140,7 @@ struct wa_xfer {
140 140
141 struct wahc *wa; /* Wire adapter we are plugged to */ 141 struct wahc *wa; /* Wire adapter we are plugged to */
142 struct usb_host_endpoint *ep; 142 struct usb_host_endpoint *ep;
143 struct urb *urb; /* URB we are transfering for */ 143 struct urb *urb; /* URB we are transferring for */
144 struct wa_seg **seg; /* transfer segments */ 144 struct wa_seg **seg; /* transfer segments */
145 u8 segs, segs_submitted, segs_done; 145 u8 segs, segs_submitted, segs_done;
146 unsigned is_inbound:1; 146 unsigned is_inbound:1;
@@ -161,7 +161,7 @@ static inline void wa_xfer_init(struct wa_xfer *xfer)
161} 161}
162 162
163/* 163/*
164 * Destory a transfer structure 164 * Destroy a transfer structure
165 * 165 *
166 * Note that the xfer->seg[index] thingies follow the URB life cycle, 166 * Note that the xfer->seg[index] thingies follow the URB life cycle,
167 * so we need to put them, not free them. 167 * so we need to put them, not free them.
@@ -494,7 +494,7 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
494 * function does almost the same thing and they work closely 494 * function does almost the same thing and they work closely
495 * together. 495 * together.
496 * 496 *
497 * If the seg request has failed but this DTO phase has suceeded, 497 * If the seg request has failed but this DTO phase has succeeded,
498 * wa_seg_cb() has already failed the segment and moved the 498 * wa_seg_cb() has already failed the segment and moved the
499 * status to WA_SEG_ERROR, so this will go through 'case 0' and 499 * status to WA_SEG_ERROR, so this will go through 'case 0' and
500 * effectively do nothing. 500 * effectively do nothing.
diff --git a/drivers/usb/wusbcore/wusbhc.c b/drivers/usb/wusbcore/wusbhc.c
index 2054d4ee9774..0faca16df765 100644
--- a/drivers/usb/wusbcore/wusbhc.c
+++ b/drivers/usb/wusbcore/wusbhc.c
@@ -320,7 +320,7 @@ u8 wusb_cluster_id_get(void)
320 u8 id; 320 u8 id;
321 spin_lock(&wusb_cluster_ids_lock); 321 spin_lock(&wusb_cluster_ids_lock);
322 id = find_first_zero_bit(wusb_cluster_id_table, CLUSTER_IDS); 322 id = find_first_zero_bit(wusb_cluster_id_table, CLUSTER_IDS);
323 if (id > CLUSTER_IDS) { 323 if (id >= CLUSTER_IDS) {
324 id = 0; 324 id = 0;
325 goto out; 325 goto out;
326 } 326 }
diff --git a/drivers/usb/wusbcore/wusbhc.h b/drivers/usb/wusbcore/wusbhc.h
index 3d94c4247f46..3a2d09162e70 100644
--- a/drivers/usb/wusbcore/wusbhc.h
+++ b/drivers/usb/wusbcore/wusbhc.h
@@ -132,7 +132,7 @@ static inline void wusb_dev_put(struct wusb_dev *wusb_dev)
132} 132}
133 133
134/** 134/**
135 * Wireless USB Host Controlller root hub "fake" ports 135 * Wireless USB Host Controller root hub "fake" ports
136 * (state and device information) 136 * (state and device information)
137 * 137 *
138 * Wireless USB is wireless, so there are no ports; but we 138 * Wireless USB is wireless, so there are no ports; but we
@@ -231,7 +231,7 @@ struct wusb_port {
231 * 231 *
232 * Most of the times when you need to use it, it will be non-NULL, 232 * Most of the times when you need to use it, it will be non-NULL,
233 * so there is no real need to check for it (wusb_dev will 233 * so there is no real need to check for it (wusb_dev will
234 * dissapear before usb_dev). 234 * disappear before usb_dev).
235 * 235 *
236 * - The following fields need to be filled out before calling 236 * - The following fields need to be filled out before calling
237 * wusbhc_create(): ports_max, mmcies_max, mmcie_{add,rm}. 237 * wusbhc_create(): ports_max, mmcies_max, mmcie_{add,rm}.