aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/dma/Kconfig8
-rw-r--r--drivers/dma/Makefile1
-rw-r--r--drivers/dma/cppi41.c1048
-rw-r--r--drivers/net/usb/ax88179_178a.c8
-rw-r--r--drivers/net/usb/usbnet.c45
-rw-r--r--drivers/usb/Kconfig17
-rw-r--r--drivers/usb/Makefile3
-rw-r--r--drivers/usb/atm/Makefile3
-rw-r--r--drivers/usb/atm/speedtch.c2
-rw-r--r--drivers/usb/atm/usbatm.c49
-rw-r--r--drivers/usb/atm/usbatm.h35
-rw-r--r--drivers/usb/c67x00/c67x00-drv.c4
-rw-r--r--drivers/usb/chipidea/Kconfig7
-rw-r--r--drivers/usb/chipidea/Makefile2
-rw-r--r--drivers/usb/chipidea/bits.h10
-rw-r--r--drivers/usb/chipidea/ci.h8
-rw-r--r--drivers/usb/chipidea/ci_hdrc_imx.c110
-rw-r--r--drivers/usb/chipidea/ci_hdrc_imx.h17
-rw-r--r--drivers/usb/chipidea/ci_hdrc_msm.c1
-rw-r--r--drivers/usb/chipidea/core.c197
-rw-r--r--drivers/usb/chipidea/host.c31
-rw-r--r--drivers/usb/chipidea/host.h6
-rw-r--r--drivers/usb/chipidea/otg.c120
-rw-r--r--drivers/usb/chipidea/otg.h35
-rw-r--r--drivers/usb/chipidea/udc.c78
-rw-r--r--drivers/usb/chipidea/udc.h6
-rw-r--r--drivers/usb/chipidea/usbmisc_imx.c95
-rw-r--r--drivers/usb/class/cdc-acm.c2
-rw-r--r--drivers/usb/class/cdc-wdm.c13
-rw-r--r--drivers/usb/class/usbtmc.c46
-rw-r--r--drivers/usb/core/buffer.c5
-rw-r--r--drivers/usb/core/config.c3
-rw-r--r--drivers/usb/core/devio.c6
-rw-r--r--drivers/usb/core/driver.c22
-rw-r--r--drivers/usb/core/endpoint.c1
-rw-r--r--drivers/usb/core/file.c2
-rw-r--r--drivers/usb/core/hcd-pci.c2
-rw-r--r--drivers/usb/core/hcd.c210
-rw-r--r--drivers/usb/core/hub.c152
-rw-r--r--drivers/usb/core/message.c62
-rw-r--r--drivers/usb/core/urb.c43
-rw-r--r--drivers/usb/core/usb.c60
-rw-r--r--drivers/usb/dwc3/Kconfig32
-rw-r--r--drivers/usb/dwc3/Makefile13
-rw-r--r--drivers/usb/dwc3/core.c196
-rw-r--r--drivers/usb/dwc3/core.h53
-rw-r--r--drivers/usb/dwc3/debug.h34
-rw-r--r--drivers/usb/dwc3/debugfs.c34
-rw-r--r--drivers/usb/dwc3/dwc3-exynos.c22
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c44
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c54
-rw-r--r--drivers/usb/dwc3/ep0.c49
-rw-r--r--drivers/usb/dwc3/gadget.c257
-rw-r--r--drivers/usb/dwc3/gadget.h34
-rw-r--r--drivers/usb/dwc3/host.c34
-rw-r--r--drivers/usb/dwc3/io.h34
-rw-r--r--drivers/usb/dwc3/platform_data.h27
-rw-r--r--drivers/usb/gadget/Kconfig17
-rw-r--r--drivers/usb/gadget/Makefile1
-rw-r--r--drivers/usb/gadget/amd5536udc.c4
-rw-r--r--drivers/usb/gadget/at91_udc.c25
-rw-r--r--drivers/usb/gadget/at91_udc.h2
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c30
-rw-r--r--drivers/usb/gadget/bcm63xx_udc.c2
-rw-r--r--drivers/usb/gadget/f_mass_storage.c6
-rw-r--r--drivers/usb/gadget/f_uac1.c4
-rw-r--r--drivers/usb/gadget/fsl_mxc_udc.c4
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c6
-rw-r--r--drivers/usb/gadget/fusb300_udc.c2
-rw-r--r--drivers/usb/gadget/goku_udc.c2
-rw-r--r--drivers/usb/gadget/hid.c2
-rw-r--r--drivers/usb/gadget/imx_udc.c1544
-rw-r--r--drivers/usb/gadget/imx_udc.h351
-rw-r--r--drivers/usb/gadget/m66592-udc.c4
-rw-r--r--drivers/usb/gadget/mv_u3d_core.c12
-rw-r--r--drivers/usb/gadget/mv_udc_core.c4
-rw-r--r--drivers/usb/gadget/omap_udc.c2
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c2
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c2
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c2
-rw-r--r--drivers/usb/gadget/rndis.c4
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c14
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c4
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c2
-rw-r--r--drivers/usb/gadget/storage_common.c2
-rw-r--r--drivers/usb/gadget/u_uac1.c2
-rw-r--r--drivers/usb/gadget/udc-core.c12
-rw-r--r--drivers/usb/gadget/uvc_queue.c6
-rw-r--r--drivers/usb/host/Kconfig63
-rw-r--r--drivers/usb/host/Makefile5
-rw-r--r--drivers/usb/host/ehci-fsl.c16
-rw-r--r--drivers/usb/host/ehci-grlib.c13
-rw-r--r--drivers/usb/host/ehci-hcd.c19
-rw-r--r--drivers/usb/host/ehci-hub.c226
-rw-r--r--drivers/usb/host/ehci-mem.c1
-rw-r--r--drivers/usb/host/ehci-mv.c4
-rw-r--r--drivers/usb/host/ehci-mxc.c14
-rw-r--r--drivers/usb/host/ehci-octeon.c2
-rw-r--r--drivers/usb/host/ehci-omap.c14
-rw-r--r--drivers/usb/host/ehci-orion.c2
-rw-r--r--drivers/usb/host/ehci-pci.c42
-rw-r--r--drivers/usb/host/ehci-platform.c12
-rw-r--r--drivers/usb/host/ehci-pmcmsp.c2
-rw-r--r--drivers/usb/host/ehci-ppc-of.c13
-rw-r--r--drivers/usb/host/ehci-ps3.c2
-rw-r--r--drivers/usb/host/ehci-q.c108
-rw-r--r--drivers/usb/host/ehci-s5p.c12
-rw-r--r--drivers/usb/host/ehci-sched.c47
-rw-r--r--drivers/usb/host/ehci-sead3.c2
-rw-r--r--drivers/usb/host/ehci-sh.c4
-rw-r--r--drivers/usb/host/ehci-tegra.c95
-rw-r--r--drivers/usb/host/ehci-tilegx.c6
-rw-r--r--drivers/usb/host/ehci-timer.c34
-rw-r--r--drivers/usb/host/ehci-w90x900.c2
-rw-r--r--drivers/usb/host/ehci-xilinx-of.c19
-rw-r--r--drivers/usb/host/ehci.h4
-rw-r--r--drivers/usb/host/fotg210-hcd.c6049
-rw-r--r--drivers/usb/host/fotg210.h750
-rw-r--r--drivers/usb/host/fsl-mph-dr-of.c4
-rw-r--r--drivers/usb/host/hwa-hc.c7
-rw-r--r--drivers/usb/host/imx21-hcd.c2
-rw-r--r--drivers/usb/host/isp116x-hcd.c2
-rw-r--r--drivers/usb/host/isp116x.h13
-rw-r--r--drivers/usb/host/isp1362-hcd.c85
-rw-r--r--drivers/usb/host/isp1362.h53
-rw-r--r--drivers/usb/host/isp1760-if.c2
-rw-r--r--drivers/usb/host/ohci-at91.c35
-rw-r--r--drivers/usb/host/ohci-da8xx.c8
-rw-r--r--drivers/usb/host/ohci-ep93xx.c137
-rw-r--r--drivers/usb/host/ohci-exynos.c2
-rw-r--r--drivers/usb/host/ohci-hcd.c2
-rw-r--r--drivers/usb/host/ohci-omap.c4
-rw-r--r--drivers/usb/host/ohci-omap3.c10
-rw-r--r--drivers/usb/host/ohci-platform.c10
-rw-r--r--drivers/usb/host/ohci-ppc-of.c11
-rw-r--r--drivers/usb/host/ohci-pxa27x.c8
-rw-r--r--drivers/usb/host/ohci-s3c2410.c11
-rw-r--r--drivers/usb/host/ohci-tilegx.c4
-rw-r--r--drivers/usb/host/pci-quirks.c48
-rw-r--r--drivers/usb/host/pci-quirks.h3
-rw-r--r--drivers/usb/host/r8a66597-hcd.c2
-rw-r--r--drivers/usb/host/sl811-hcd.c109
-rw-r--r--drivers/usb/host/sl811.h21
-rw-r--r--drivers/usb/host/u132-hcd.c6
-rw-r--r--drivers/usb/host/xhci-dbg.c14
-rw-r--r--drivers/usb/host/xhci-hub.c228
-rw-r--r--drivers/usb/host/xhci-mem.c187
-rw-r--r--drivers/usb/host/xhci-pci.c28
-rw-r--r--drivers/usb/host/xhci-plat.c46
-rw-r--r--drivers/usb/host/xhci-ring.c89
-rw-r--r--drivers/usb/host/xhci-trace.c15
-rw-r--r--drivers/usb/host/xhci-trace.h151
-rw-r--r--drivers/usb/host/xhci.c351
-rw-r--r--drivers/usb/host/xhci.h17
-rw-r--r--drivers/usb/misc/Kconfig14
-rw-r--r--drivers/usb/misc/Makefile4
-rw-r--r--drivers/usb/misc/adutux.c200
-rw-r--r--drivers/usb/misc/ehset.c152
-rw-r--r--drivers/usb/misc/ldusb.c31
-rw-r--r--drivers/usb/misc/legousbtower.c124
-rw-r--r--drivers/usb/misc/usb3503.c284
-rw-r--r--drivers/usb/misc/usbtest.c9
-rw-r--r--drivers/usb/misc/uss720.c24
-rw-r--r--drivers/usb/musb/Kconfig9
-rw-r--r--drivers/usb/musb/Makefile4
-rw-r--r--drivers/usb/musb/am35x.c16
-rw-r--r--drivers/usb/musb/blackfin.c4
-rw-r--r--drivers/usb/musb/cppi_dma.c18
-rw-r--r--drivers/usb/musb/da8xx.c4
-rw-r--r--drivers/usb/musb/davinci.c4
-rw-r--r--drivers/usb/musb/musb_am335x.c55
-rw-r--r--drivers/usb/musb/musb_core.c31
-rw-r--r--drivers/usb/musb/musb_core.h8
-rw-r--r--drivers/usb/musb/musb_cppi41.c555
-rw-r--r--drivers/usb/musb/musb_dma.h21
-rw-r--r--drivers/usb/musb/musb_dsps.c382
-rw-r--r--drivers/usb/musb/musb_gadget.c87
-rw-r--r--drivers/usb/musb/musbhsdma.c17
-rw-r--r--drivers/usb/musb/omap2430.c8
-rw-r--r--drivers/usb/musb/tusb6010.c4
-rw-r--r--drivers/usb/musb/tusb6010_omap.c24
-rw-r--r--drivers/usb/musb/ux500.c2
-rw-r--r--drivers/usb/musb/ux500_dma.c21
-rw-r--r--drivers/usb/phy/Kconfig50
-rw-r--r--drivers/usb/phy/Makefile7
-rw-r--r--drivers/usb/phy/am35x-phy-control.h21
-rw-r--r--drivers/usb/phy/phy-am335x-control.c137
-rw-r--r--drivers/usb/phy/phy-am335x.c99
-rw-r--r--drivers/usb/phy/phy-fsl-usb.c12
-rw-r--r--drivers/usb/phy/phy-fsm-usb.h11
-rw-r--r--drivers/usb/phy/phy-generic.c (renamed from drivers/usb/phy/phy-nop.c)167
-rw-r--r--drivers/usb/phy/phy-generic.h20
-rw-r--r--drivers/usb/phy/phy-gpio-vbus-usb.c10
-rw-r--r--drivers/usb/phy/phy-isp1301-omap.c6
-rw-r--r--drivers/usb/phy/phy-msm-usb.c4
-rw-r--r--drivers/usb/phy/phy-mv-u3d-usb.c4
-rw-r--r--drivers/usb/phy/phy-mv-usb.c6
-rw-r--r--drivers/usb/phy/phy-mxs-usb.c13
-rw-r--r--drivers/usb/phy/phy-omap-control.c3
-rw-r--r--drivers/usb/phy/phy-omap-usb3.c87
-rw-r--r--drivers/usb/phy/phy-rcar-usb.c9
-rw-r--r--drivers/usb/phy/phy-samsung-usb2.c2
-rw-r--r--drivers/usb/phy/phy-samsung-usb3.c2
-rw-r--r--drivers/usb/phy/phy-tegra-usb.c460
-rw-r--r--drivers/usb/phy/phy-twl4030-usb.c2
-rw-r--r--drivers/usb/phy/phy-twl6030-usb.c2
-rw-r--r--drivers/usb/renesas_usbhs/common.c4
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c6
-rw-r--r--drivers/usb/renesas_usbhs/mod_host.c6
-rw-r--r--drivers/usb/renesas_usbhs/pipe.h6
-rw-r--r--drivers/usb/serial/Kconfig84
-rw-r--r--drivers/usb/serial/Makefile9
-rw-r--r--drivers/usb/serial/console.c27
-rw-r--r--drivers/usb/serial/cp210x.c3
-rw-r--r--drivers/usb/serial/cypress_m8.c4
-rw-r--r--drivers/usb/serial/f81232.c3
-rw-r--r--drivers/usb/serial/flashloader.c39
-rw-r--r--drivers/usb/serial/ftdi_sio.c52
-rw-r--r--drivers/usb/serial/funsoft.c40
-rw-r--r--drivers/usb/serial/generic.c13
-rw-r--r--drivers/usb/serial/hp4x.c51
-rw-r--r--drivers/usb/serial/io_edgeport.c2
-rw-r--r--drivers/usb/serial/io_ti.c71
-rw-r--r--drivers/usb/serial/keyspan.c104
-rw-r--r--drivers/usb/serial/mos7840.c48
-rw-r--r--drivers/usb/serial/moto_modem.c48
-rw-r--r--drivers/usb/serial/oti6858.c10
-rw-r--r--drivers/usb/serial/pl2303.c352
-rw-r--r--drivers/usb/serial/quatech2.c35
-rw-r--r--drivers/usb/serial/safe_serial.c51
-rw-r--r--drivers/usb/serial/siemens_mpi.c47
-rw-r--r--drivers/usb/serial/spcp8x5.c4
-rw-r--r--drivers/usb/serial/suunto.c41
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c103
-rw-r--r--drivers/usb/serial/usb-serial-simple.c110
-rw-r--r--drivers/usb/serial/usb-serial.c14
-rw-r--r--drivers/usb/serial/vivopay-serial.c43
-rw-r--r--drivers/usb/serial/zio.c39
-rw-r--r--drivers/usb/usb-common.c49
-rw-r--r--drivers/usb/usb-skeleton.c3
-rw-r--r--drivers/usb/wusbcore/rh.c28
-rw-r--r--drivers/usb/wusbcore/wa-xfer.c25
-rw-r--r--drivers/uwb/hwa-rc.c16
-rw-r--r--drivers/uwb/pal.c40
244 files changed, 13506 insertions, 6249 deletions
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index 6825957c97fb..77bc480117b7 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -287,6 +287,14 @@ config DMA_OMAP
287 select DMA_ENGINE 287 select DMA_ENGINE
288 select DMA_VIRTUAL_CHANNELS 288 select DMA_VIRTUAL_CHANNELS
289 289
290config TI_CPPI41
291 tristate "AM33xx CPPI41 DMA support"
292 depends on ARCH_OMAP
293 select DMA_ENGINE
294 help
295 The Communications Port Programming Interface (CPPI) 4.1 DMA engine
296 is currently used by the USB driver on AM335x platforms.
297
290config MMP_PDMA 298config MMP_PDMA
291 bool "MMP PDMA support" 299 bool "MMP PDMA support"
292 depends on (ARCH_MMP || ARCH_PXA) 300 depends on (ARCH_MMP || ARCH_PXA)
diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
index 5e0f2ef85614..6d62ec30c4bc 100644
--- a/drivers/dma/Makefile
+++ b/drivers/dma/Makefile
@@ -39,3 +39,4 @@ obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
39obj-$(CONFIG_DMA_OMAP) += omap-dma.o 39obj-$(CONFIG_DMA_OMAP) += omap-dma.o
40obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o 40obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
41obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o 41obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
42obj-$(CONFIG_TI_CPPI41) += cppi41.o
diff --git a/drivers/dma/cppi41.c b/drivers/dma/cppi41.c
new file mode 100644
index 000000000000..5dcebca37760
--- /dev/null
+++ b/drivers/dma/cppi41.c
@@ -0,0 +1,1048 @@
1#include <linux/dmaengine.h>
2#include <linux/dma-mapping.h>
3#include <linux/platform_device.h>
4#include <linux/module.h>
5#include <linux/of.h>
6#include <linux/slab.h>
7#include <linux/of_dma.h>
8#include <linux/of_irq.h>
9#include <linux/dmapool.h>
10#include <linux/interrupt.h>
11#include <linux/of_address.h>
12#include "dmaengine.h"
13
14#define DESC_TYPE 27
15#define DESC_TYPE_HOST 0x10
16#define DESC_TYPE_TEARD 0x13
17
18#define TD_DESC_IS_RX (1 << 16)
19#define TD_DESC_DMA_NUM 10
20
21#define DESC_LENGTH_BITS_NUM 21
22
23#define DESC_TYPE_USB (5 << 26)
24#define DESC_PD_COMPLETE (1 << 31)
25
26/* DMA engine */
27#define DMA_TDFDQ 4
28#define DMA_TXGCR(x) (0x800 + (x) * 0x20)
29#define DMA_RXGCR(x) (0x808 + (x) * 0x20)
30#define RXHPCRA0 4
31
32#define GCR_CHAN_ENABLE (1 << 31)
33#define GCR_TEARDOWN (1 << 30)
34#define GCR_STARV_RETRY (1 << 24)
35#define GCR_DESC_TYPE_HOST (1 << 14)
36
37/* DMA scheduler */
38#define DMA_SCHED_CTRL 0
39#define DMA_SCHED_CTRL_EN (1 << 31)
40#define DMA_SCHED_WORD(x) ((x) * 4 + 0x800)
41
42#define SCHED_ENTRY0_CHAN(x) ((x) << 0)
43#define SCHED_ENTRY0_IS_RX (1 << 7)
44
45#define SCHED_ENTRY1_CHAN(x) ((x) << 8)
46#define SCHED_ENTRY1_IS_RX (1 << 15)
47
48#define SCHED_ENTRY2_CHAN(x) ((x) << 16)
49#define SCHED_ENTRY2_IS_RX (1 << 23)
50
51#define SCHED_ENTRY3_CHAN(x) ((x) << 24)
52#define SCHED_ENTRY3_IS_RX (1 << 31)
53
54/* Queue manager */
55/* 4 KiB of memory for descriptors, 2 for each endpoint */
56#define ALLOC_DECS_NUM 128
57#define DESCS_AREAS 1
58#define TOTAL_DESCS_NUM (ALLOC_DECS_NUM * DESCS_AREAS)
59#define QMGR_SCRATCH_SIZE (TOTAL_DESCS_NUM * 4)
60
61#define QMGR_LRAM0_BASE 0x80
62#define QMGR_LRAM_SIZE 0x84
63#define QMGR_LRAM1_BASE 0x88
64#define QMGR_MEMBASE(x) (0x1000 + (x) * 0x10)
65#define QMGR_MEMCTRL(x) (0x1004 + (x) * 0x10)
66#define QMGR_MEMCTRL_IDX_SH 16
67#define QMGR_MEMCTRL_DESC_SH 8
68
69#define QMGR_NUM_PEND 5
70#define QMGR_PEND(x) (0x90 + (x) * 4)
71
72#define QMGR_PENDING_SLOT_Q(x) (x / 32)
73#define QMGR_PENDING_BIT_Q(x) (x % 32)
74
75#define QMGR_QUEUE_A(n) (0x2000 + (n) * 0x10)
76#define QMGR_QUEUE_B(n) (0x2004 + (n) * 0x10)
77#define QMGR_QUEUE_C(n) (0x2008 + (n) * 0x10)
78#define QMGR_QUEUE_D(n) (0x200c + (n) * 0x10)
79
80/* Glue layer specific */
81/* USBSS / USB AM335x */
82#define USBSS_IRQ_STATUS 0x28
83#define USBSS_IRQ_ENABLER 0x2c
84#define USBSS_IRQ_CLEARR 0x30
85
86#define USBSS_IRQ_PD_COMP (1 << 2)
87
88struct cppi41_channel {
89 struct dma_chan chan;
90 struct dma_async_tx_descriptor txd;
91 struct cppi41_dd *cdd;
92 struct cppi41_desc *desc;
93 dma_addr_t desc_phys;
94 void __iomem *gcr_reg;
95 int is_tx;
96 u32 residue;
97
98 unsigned int q_num;
99 unsigned int q_comp_num;
100 unsigned int port_num;
101
102 unsigned td_retry;
103 unsigned td_queued:1;
104 unsigned td_seen:1;
105 unsigned td_desc_seen:1;
106};
107
108struct cppi41_desc {
109 u32 pd0;
110 u32 pd1;
111 u32 pd2;
112 u32 pd3;
113 u32 pd4;
114 u32 pd5;
115 u32 pd6;
116 u32 pd7;
117} __aligned(32);
118
119struct chan_queues {
120 u16 submit;
121 u16 complete;
122};
123
124struct cppi41_dd {
125 struct dma_device ddev;
126
127 void *qmgr_scratch;
128 dma_addr_t scratch_phys;
129
130 struct cppi41_desc *cd;
131 dma_addr_t descs_phys;
132 u32 first_td_desc;
133 struct cppi41_channel *chan_busy[ALLOC_DECS_NUM];
134
135 void __iomem *usbss_mem;
136 void __iomem *ctrl_mem;
137 void __iomem *sched_mem;
138 void __iomem *qmgr_mem;
139 unsigned int irq;
140 const struct chan_queues *queues_rx;
141 const struct chan_queues *queues_tx;
142 struct chan_queues td_queue;
143};
144
145#define FIST_COMPLETION_QUEUE 93
146static struct chan_queues usb_queues_tx[] = {
147 /* USB0 ENDP 1 */
148 [ 0] = { .submit = 32, .complete = 93},
149 [ 1] = { .submit = 34, .complete = 94},
150 [ 2] = { .submit = 36, .complete = 95},
151 [ 3] = { .submit = 38, .complete = 96},
152 [ 4] = { .submit = 40, .complete = 97},
153 [ 5] = { .submit = 42, .complete = 98},
154 [ 6] = { .submit = 44, .complete = 99},
155 [ 7] = { .submit = 46, .complete = 100},
156 [ 8] = { .submit = 48, .complete = 101},
157 [ 9] = { .submit = 50, .complete = 102},
158 [10] = { .submit = 52, .complete = 103},
159 [11] = { .submit = 54, .complete = 104},
160 [12] = { .submit = 56, .complete = 105},
161 [13] = { .submit = 58, .complete = 106},
162 [14] = { .submit = 60, .complete = 107},
163
164 /* USB1 ENDP1 */
165 [15] = { .submit = 62, .complete = 125},
166 [16] = { .submit = 64, .complete = 126},
167 [17] = { .submit = 66, .complete = 127},
168 [18] = { .submit = 68, .complete = 128},
169 [19] = { .submit = 70, .complete = 129},
170 [20] = { .submit = 72, .complete = 130},
171 [21] = { .submit = 74, .complete = 131},
172 [22] = { .submit = 76, .complete = 132},
173 [23] = { .submit = 78, .complete = 133},
174 [24] = { .submit = 80, .complete = 134},
175 [25] = { .submit = 82, .complete = 135},
176 [26] = { .submit = 84, .complete = 136},
177 [27] = { .submit = 86, .complete = 137},
178 [28] = { .submit = 88, .complete = 138},
179 [29] = { .submit = 90, .complete = 139},
180};
181
182static const struct chan_queues usb_queues_rx[] = {
183 /* USB0 ENDP 1 */
184 [ 0] = { .submit = 1, .complete = 109},
185 [ 1] = { .submit = 2, .complete = 110},
186 [ 2] = { .submit = 3, .complete = 111},
187 [ 3] = { .submit = 4, .complete = 112},
188 [ 4] = { .submit = 5, .complete = 113},
189 [ 5] = { .submit = 6, .complete = 114},
190 [ 6] = { .submit = 7, .complete = 115},
191 [ 7] = { .submit = 8, .complete = 116},
192 [ 8] = { .submit = 9, .complete = 117},
193 [ 9] = { .submit = 10, .complete = 118},
194 [10] = { .submit = 11, .complete = 119},
195 [11] = { .submit = 12, .complete = 120},
196 [12] = { .submit = 13, .complete = 121},
197 [13] = { .submit = 14, .complete = 122},
198 [14] = { .submit = 15, .complete = 123},
199
200 /* USB1 ENDP 1 */
201 [15] = { .submit = 16, .complete = 141},
202 [16] = { .submit = 17, .complete = 142},
203 [17] = { .submit = 18, .complete = 143},
204 [18] = { .submit = 19, .complete = 144},
205 [19] = { .submit = 20, .complete = 145},
206 [20] = { .submit = 21, .complete = 146},
207 [21] = { .submit = 22, .complete = 147},
208 [22] = { .submit = 23, .complete = 148},
209 [23] = { .submit = 24, .complete = 149},
210 [24] = { .submit = 25, .complete = 150},
211 [25] = { .submit = 26, .complete = 151},
212 [26] = { .submit = 27, .complete = 152},
213 [27] = { .submit = 28, .complete = 153},
214 [28] = { .submit = 29, .complete = 154},
215 [29] = { .submit = 30, .complete = 155},
216};
217
218struct cppi_glue_infos {
219 irqreturn_t (*isr)(int irq, void *data);
220 const struct chan_queues *queues_rx;
221 const struct chan_queues *queues_tx;
222 struct chan_queues td_queue;
223};
224
225static struct cppi41_channel *to_cpp41_chan(struct dma_chan *c)
226{
227 return container_of(c, struct cppi41_channel, chan);
228}
229
230static struct cppi41_channel *desc_to_chan(struct cppi41_dd *cdd, u32 desc)
231{
232 struct cppi41_channel *c;
233 u32 descs_size;
234 u32 desc_num;
235
236 descs_size = sizeof(struct cppi41_desc) * ALLOC_DECS_NUM;
237
238 if (!((desc >= cdd->descs_phys) &&
239 (desc < (cdd->descs_phys + descs_size)))) {
240 return NULL;
241 }
242
243 desc_num = (desc - cdd->descs_phys) / sizeof(struct cppi41_desc);
244 BUG_ON(desc_num > ALLOC_DECS_NUM);
245 c = cdd->chan_busy[desc_num];
246 cdd->chan_busy[desc_num] = NULL;
247 return c;
248}
249
250static void cppi_writel(u32 val, void *__iomem *mem)
251{
252 __raw_writel(val, mem);
253}
254
255static u32 cppi_readl(void *__iomem *mem)
256{
257 return __raw_readl(mem);
258}
259
260static u32 pd_trans_len(u32 val)
261{
262 return val & ((1 << (DESC_LENGTH_BITS_NUM + 1)) - 1);
263}
264
265static irqreturn_t cppi41_irq(int irq, void *data)
266{
267 struct cppi41_dd *cdd = data;
268 struct cppi41_channel *c;
269 u32 status;
270 int i;
271
272 status = cppi_readl(cdd->usbss_mem + USBSS_IRQ_STATUS);
273 if (!(status & USBSS_IRQ_PD_COMP))
274 return IRQ_NONE;
275 cppi_writel(status, cdd->usbss_mem + USBSS_IRQ_STATUS);
276
277 for (i = QMGR_PENDING_SLOT_Q(FIST_COMPLETION_QUEUE); i < QMGR_NUM_PEND;
278 i++) {
279 u32 val;
280 u32 q_num;
281
282 val = cppi_readl(cdd->qmgr_mem + QMGR_PEND(i));
283 if (i == QMGR_PENDING_SLOT_Q(FIST_COMPLETION_QUEUE) && val) {
284 u32 mask;
285 /* set corresponding bit for completetion Q 93 */
286 mask = 1 << QMGR_PENDING_BIT_Q(FIST_COMPLETION_QUEUE);
287 /* not set all bits for queues less than Q 93 */
288 mask--;
289 /* now invert and keep only Q 93+ set */
290 val &= ~mask;
291 }
292
293 if (val)
294 __iormb();
295
296 while (val) {
297 u32 desc;
298
299 q_num = __fls(val);
300 val &= ~(1 << q_num);
301 q_num += 32 * i;
302 desc = cppi_readl(cdd->qmgr_mem + QMGR_QUEUE_D(q_num));
303 desc &= ~0x1f;
304 c = desc_to_chan(cdd, desc);
305 if (WARN_ON(!c)) {
306 pr_err("%s() q %d desc %08x\n", __func__,
307 q_num, desc);
308 continue;
309 }
310 c->residue = pd_trans_len(c->desc->pd6) -
311 pd_trans_len(c->desc->pd0);
312
313 dma_cookie_complete(&c->txd);
314 c->txd.callback(c->txd.callback_param);
315 }
316 }
317 return IRQ_HANDLED;
318}
319
320static dma_cookie_t cppi41_tx_submit(struct dma_async_tx_descriptor *tx)
321{
322 dma_cookie_t cookie;
323
324 cookie = dma_cookie_assign(tx);
325
326 return cookie;
327}
328
329static int cppi41_dma_alloc_chan_resources(struct dma_chan *chan)
330{
331 struct cppi41_channel *c = to_cpp41_chan(chan);
332
333 dma_cookie_init(chan);
334 dma_async_tx_descriptor_init(&c->txd, chan);
335 c->txd.tx_submit = cppi41_tx_submit;
336
337 if (!c->is_tx)
338 cppi_writel(c->q_num, c->gcr_reg + RXHPCRA0);
339
340 return 0;
341}
342
343static void cppi41_dma_free_chan_resources(struct dma_chan *chan)
344{
345}
346
347static enum dma_status cppi41_dma_tx_status(struct dma_chan *chan,
348 dma_cookie_t cookie, struct dma_tx_state *txstate)
349{
350 struct cppi41_channel *c = to_cpp41_chan(chan);
351 enum dma_status ret;
352
353 /* lock */
354 ret = dma_cookie_status(chan, cookie, txstate);
355 if (txstate && ret == DMA_SUCCESS)
356 txstate->residue = c->residue;
357 /* unlock */
358
359 return ret;
360}
361
362static void push_desc_queue(struct cppi41_channel *c)
363{
364 struct cppi41_dd *cdd = c->cdd;
365 u32 desc_num;
366 u32 desc_phys;
367 u32 reg;
368
369 desc_phys = lower_32_bits(c->desc_phys);
370 desc_num = (desc_phys - cdd->descs_phys) / sizeof(struct cppi41_desc);
371 WARN_ON(cdd->chan_busy[desc_num]);
372 cdd->chan_busy[desc_num] = c;
373
374 reg = (sizeof(struct cppi41_desc) - 24) / 4;
375 reg |= desc_phys;
376 cppi_writel(reg, cdd->qmgr_mem + QMGR_QUEUE_D(c->q_num));
377}
378
379static void cppi41_dma_issue_pending(struct dma_chan *chan)
380{
381 struct cppi41_channel *c = to_cpp41_chan(chan);
382 u32 reg;
383
384 c->residue = 0;
385
386 reg = GCR_CHAN_ENABLE;
387 if (!c->is_tx) {
388 reg |= GCR_STARV_RETRY;
389 reg |= GCR_DESC_TYPE_HOST;
390 reg |= c->q_comp_num;
391 }
392
393 cppi_writel(reg, c->gcr_reg);
394
395 /*
396 * We don't use writel() but __raw_writel() so we have to make sure
397 * that the DMA descriptor in coherent memory made to the main memory
398 * before starting the dma engine.
399 */
400 __iowmb();
401 push_desc_queue(c);
402}
403
404static u32 get_host_pd0(u32 length)
405{
406 u32 reg;
407
408 reg = DESC_TYPE_HOST << DESC_TYPE;
409 reg |= length;
410
411 return reg;
412}
413
414static u32 get_host_pd1(struct cppi41_channel *c)
415{
416 u32 reg;
417
418 reg = 0;
419
420 return reg;
421}
422
423static u32 get_host_pd2(struct cppi41_channel *c)
424{
425 u32 reg;
426
427 reg = DESC_TYPE_USB;
428 reg |= c->q_comp_num;
429
430 return reg;
431}
432
433static u32 get_host_pd3(u32 length)
434{
435 u32 reg;
436
437 /* PD3 = packet size */
438 reg = length;
439
440 return reg;
441}
442
443static u32 get_host_pd6(u32 length)
444{
445 u32 reg;
446
447 /* PD6 buffer size */
448 reg = DESC_PD_COMPLETE;
449 reg |= length;
450
451 return reg;
452}
453
454static u32 get_host_pd4_or_7(u32 addr)
455{
456 u32 reg;
457
458 reg = addr;
459
460 return reg;
461}
462
463static u32 get_host_pd5(void)
464{
465 u32 reg;
466
467 reg = 0;
468
469 return reg;
470}
471
472static struct dma_async_tx_descriptor *cppi41_dma_prep_slave_sg(
473 struct dma_chan *chan, struct scatterlist *sgl, unsigned sg_len,
474 enum dma_transfer_direction dir, unsigned long tx_flags, void *context)
475{
476 struct cppi41_channel *c = to_cpp41_chan(chan);
477 struct cppi41_desc *d;
478 struct scatterlist *sg;
479 unsigned int i;
480 unsigned int num;
481
482 num = 0;
483 d = c->desc;
484 for_each_sg(sgl, sg, sg_len, i) {
485 u32 addr;
486 u32 len;
487
488 /* We need to use more than one desc once musb supports sg */
489 BUG_ON(num > 0);
490 addr = lower_32_bits(sg_dma_address(sg));
491 len = sg_dma_len(sg);
492
493 d->pd0 = get_host_pd0(len);
494 d->pd1 = get_host_pd1(c);
495 d->pd2 = get_host_pd2(c);
496 d->pd3 = get_host_pd3(len);
497 d->pd4 = get_host_pd4_or_7(addr);
498 d->pd5 = get_host_pd5();
499 d->pd6 = get_host_pd6(len);
500 d->pd7 = get_host_pd4_or_7(addr);
501
502 d++;
503 }
504
505 return &c->txd;
506}
507
508static int cpp41_cfg_chan(struct cppi41_channel *c,
509 struct dma_slave_config *cfg)
510{
511 return 0;
512}
513
514static void cppi41_compute_td_desc(struct cppi41_desc *d)
515{
516 d->pd0 = DESC_TYPE_TEARD << DESC_TYPE;
517}
518
519static u32 cppi41_pop_desc(struct cppi41_dd *cdd, unsigned queue_num)
520{
521 u32 desc;
522
523 desc = cppi_readl(cdd->qmgr_mem + QMGR_QUEUE_D(queue_num));
524 desc &= ~0x1f;
525 return desc;
526}
527
528static int cppi41_tear_down_chan(struct cppi41_channel *c)
529{
530 struct cppi41_dd *cdd = c->cdd;
531 struct cppi41_desc *td;
532 u32 reg;
533 u32 desc_phys;
534 u32 td_desc_phys;
535
536 td = cdd->cd;
537 td += cdd->first_td_desc;
538
539 td_desc_phys = cdd->descs_phys;
540 td_desc_phys += cdd->first_td_desc * sizeof(struct cppi41_desc);
541
542 if (!c->td_queued) {
543 cppi41_compute_td_desc(td);
544 __iowmb();
545
546 reg = (sizeof(struct cppi41_desc) - 24) / 4;
547 reg |= td_desc_phys;
548 cppi_writel(reg, cdd->qmgr_mem +
549 QMGR_QUEUE_D(cdd->td_queue.submit));
550
551 reg = GCR_CHAN_ENABLE;
552 if (!c->is_tx) {
553 reg |= GCR_STARV_RETRY;
554 reg |= GCR_DESC_TYPE_HOST;
555 reg |= c->q_comp_num;
556 }
557 reg |= GCR_TEARDOWN;
558 cppi_writel(reg, c->gcr_reg);
559 c->td_queued = 1;
560 c->td_retry = 100;
561 }
562
563 if (!c->td_seen) {
564 unsigned td_comp_queue;
565
566 if (c->is_tx)
567 td_comp_queue = cdd->td_queue.complete;
568 else
569 td_comp_queue = c->q_comp_num;
570
571 desc_phys = cppi41_pop_desc(cdd, td_comp_queue);
572 if (desc_phys) {
573 __iormb();
574
575 if (desc_phys == td_desc_phys) {
576 u32 pd0;
577 pd0 = td->pd0;
578 WARN_ON((pd0 >> DESC_TYPE) != DESC_TYPE_TEARD);
579 WARN_ON(!c->is_tx && !(pd0 & TD_DESC_IS_RX));
580 WARN_ON((pd0 & 0x1f) != c->port_num);
581 } else {
582 __WARN();
583 }
584 c->td_seen = 1;
585 }
586 }
587 if (!c->td_desc_seen) {
588 desc_phys = cppi41_pop_desc(cdd, c->q_comp_num);
589 if (desc_phys) {
590 __iormb();
591 WARN_ON(c->desc_phys != desc_phys);
592 c->td_desc_seen = 1;
593 }
594 }
595 c->td_retry--;
596 /*
597 * If the TX descriptor / channel is in use, the caller needs to poke
598 * his TD bit multiple times. After that he hardware releases the
599 * transfer descriptor followed by TD descriptor. Waiting seems not to
600 * cause any difference.
601 * RX seems to be thrown out right away. However once the TearDown
602 * descriptor gets through we are done. If we have seens the transfer
603 * descriptor before the TD we fetch it from enqueue, it has to be
604 * there waiting for us.
605 */
606 if (!c->td_seen && c->td_retry)
607 return -EAGAIN;
608
609 WARN_ON(!c->td_retry);
610 if (!c->td_desc_seen) {
611 desc_phys = cppi_readl(cdd->qmgr_mem + QMGR_QUEUE_D(c->q_num));
612 WARN_ON(!desc_phys);
613 }
614
615 c->td_queued = 0;
616 c->td_seen = 0;
617 c->td_desc_seen = 0;
618 cppi_writel(0, c->gcr_reg);
619 return 0;
620}
621
622static int cppi41_stop_chan(struct dma_chan *chan)
623{
624 struct cppi41_channel *c = to_cpp41_chan(chan);
625 struct cppi41_dd *cdd = c->cdd;
626 u32 desc_num;
627 u32 desc_phys;
628 int ret;
629
630 ret = cppi41_tear_down_chan(c);
631 if (ret)
632 return ret;
633
634 desc_phys = lower_32_bits(c->desc_phys);
635 desc_num = (desc_phys - cdd->descs_phys) / sizeof(struct cppi41_desc);
636 WARN_ON(!cdd->chan_busy[desc_num]);
637 cdd->chan_busy[desc_num] = NULL;
638
639 return 0;
640}
641
642static int cppi41_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
643 unsigned long arg)
644{
645 struct cppi41_channel *c = to_cpp41_chan(chan);
646 int ret;
647
648 switch (cmd) {
649 case DMA_SLAVE_CONFIG:
650 ret = cpp41_cfg_chan(c, (struct dma_slave_config *) arg);
651 break;
652
653 case DMA_TERMINATE_ALL:
654 ret = cppi41_stop_chan(chan);
655 break;
656
657 default:
658 ret = -ENXIO;
659 break;
660 }
661 return ret;
662}
663
664static void cleanup_chans(struct cppi41_dd *cdd)
665{
666 while (!list_empty(&cdd->ddev.channels)) {
667 struct cppi41_channel *cchan;
668
669 cchan = list_first_entry(&cdd->ddev.channels,
670 struct cppi41_channel, chan.device_node);
671 list_del(&cchan->chan.device_node);
672 kfree(cchan);
673 }
674}
675
676static int cppi41_add_chans(struct platform_device *pdev, struct cppi41_dd *cdd)
677{
678 struct cppi41_channel *cchan;
679 int i;
680 int ret;
681 u32 n_chans;
682
683 ret = of_property_read_u32(pdev->dev.of_node, "#dma-channels",
684 &n_chans);
685 if (ret)
686 return ret;
687 /*
688 * The channels can only be used as TX or as RX. So we add twice
689 * that much dma channels because USB can only do RX or TX.
690 */
691 n_chans *= 2;
692
693 for (i = 0; i < n_chans; i++) {
694 cchan = kzalloc(sizeof(*cchan), GFP_KERNEL);
695 if (!cchan)
696 goto err;
697
698 cchan->cdd = cdd;
699 if (i & 1) {
700 cchan->gcr_reg = cdd->ctrl_mem + DMA_TXGCR(i >> 1);
701 cchan->is_tx = 1;
702 } else {
703 cchan->gcr_reg = cdd->ctrl_mem + DMA_RXGCR(i >> 1);
704 cchan->is_tx = 0;
705 }
706 cchan->port_num = i >> 1;
707 cchan->desc = &cdd->cd[i];
708 cchan->desc_phys = cdd->descs_phys;
709 cchan->desc_phys += i * sizeof(struct cppi41_desc);
710 cchan->chan.device = &cdd->ddev;
711 list_add_tail(&cchan->chan.device_node, &cdd->ddev.channels);
712 }
713 cdd->first_td_desc = n_chans;
714
715 return 0;
716err:
717 cleanup_chans(cdd);
718 return -ENOMEM;
719}
720
721static void purge_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
722{
723 unsigned int mem_decs;
724 int i;
725
726 mem_decs = ALLOC_DECS_NUM * sizeof(struct cppi41_desc);
727
728 for (i = 0; i < DESCS_AREAS; i++) {
729
730 cppi_writel(0, cdd->qmgr_mem + QMGR_MEMBASE(i));
731 cppi_writel(0, cdd->qmgr_mem + QMGR_MEMCTRL(i));
732
733 dma_free_coherent(&pdev->dev, mem_decs, cdd->cd,
734 cdd->descs_phys);
735 }
736}
737
738static void disable_sched(struct cppi41_dd *cdd)
739{
740 cppi_writel(0, cdd->sched_mem + DMA_SCHED_CTRL);
741}
742
743static void deinit_cpii41(struct platform_device *pdev, struct cppi41_dd *cdd)
744{
745 disable_sched(cdd);
746
747 purge_descs(pdev, cdd);
748
749 cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM0_BASE);
750 cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM0_BASE);
751 dma_free_coherent(&pdev->dev, QMGR_SCRATCH_SIZE, cdd->qmgr_scratch,
752 cdd->scratch_phys);
753}
754
755static int init_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
756{
757 unsigned int desc_size;
758 unsigned int mem_decs;
759 int i;
760 u32 reg;
761 u32 idx;
762
763 BUILD_BUG_ON(sizeof(struct cppi41_desc) &
764 (sizeof(struct cppi41_desc) - 1));
765 BUILD_BUG_ON(sizeof(struct cppi41_desc) < 32);
766 BUILD_BUG_ON(ALLOC_DECS_NUM < 32);
767
768 desc_size = sizeof(struct cppi41_desc);
769 mem_decs = ALLOC_DECS_NUM * desc_size;
770
771 idx = 0;
772 for (i = 0; i < DESCS_AREAS; i++) {
773
774 reg = idx << QMGR_MEMCTRL_IDX_SH;
775 reg |= (ilog2(desc_size) - 5) << QMGR_MEMCTRL_DESC_SH;
776 reg |= ilog2(ALLOC_DECS_NUM) - 5;
777
778 BUILD_BUG_ON(DESCS_AREAS != 1);
779 cdd->cd = dma_alloc_coherent(&pdev->dev, mem_decs,
780 &cdd->descs_phys, GFP_KERNEL);
781 if (!cdd->cd)
782 return -ENOMEM;
783
784 cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
785 cppi_writel(reg, cdd->qmgr_mem + QMGR_MEMCTRL(i));
786
787 idx += ALLOC_DECS_NUM;
788 }
789 return 0;
790}
791
792static void init_sched(struct cppi41_dd *cdd)
793{
794 unsigned ch;
795 unsigned word;
796 u32 reg;
797
798 word = 0;
799 cppi_writel(0, cdd->sched_mem + DMA_SCHED_CTRL);
800 for (ch = 0; ch < 15 * 2; ch += 2) {
801
802 reg = SCHED_ENTRY0_CHAN(ch);
803 reg |= SCHED_ENTRY1_CHAN(ch) | SCHED_ENTRY1_IS_RX;
804
805 reg |= SCHED_ENTRY2_CHAN(ch + 1);
806 reg |= SCHED_ENTRY3_CHAN(ch + 1) | SCHED_ENTRY3_IS_RX;
807 cppi_writel(reg, cdd->sched_mem + DMA_SCHED_WORD(word));
808 word++;
809 }
810 reg = 15 * 2 * 2 - 1;
811 reg |= DMA_SCHED_CTRL_EN;
812 cppi_writel(reg, cdd->sched_mem + DMA_SCHED_CTRL);
813}
814
815static int init_cppi41(struct platform_device *pdev, struct cppi41_dd *cdd)
816{
817 int ret;
818
819 BUILD_BUG_ON(QMGR_SCRATCH_SIZE > ((1 << 14) - 1));
820 cdd->qmgr_scratch = dma_alloc_coherent(&pdev->dev, QMGR_SCRATCH_SIZE,
821 &cdd->scratch_phys, GFP_KERNEL);
822 if (!cdd->qmgr_scratch)
823 return -ENOMEM;
824
825 cppi_writel(cdd->scratch_phys, cdd->qmgr_mem + QMGR_LRAM0_BASE);
826 cppi_writel(QMGR_SCRATCH_SIZE, cdd->qmgr_mem + QMGR_LRAM_SIZE);
827 cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM1_BASE);
828
829 ret = init_descs(pdev, cdd);
830 if (ret)
831 goto err_td;
832
833 cppi_writel(cdd->td_queue.submit, cdd->ctrl_mem + DMA_TDFDQ);
834 init_sched(cdd);
835 return 0;
836err_td:
837 deinit_cpii41(pdev, cdd);
838 return ret;
839}
840
841static struct platform_driver cpp41_dma_driver;
842/*
843 * The param format is:
844 * X Y
845 * X: Port
846 * Y: 0 = RX else TX
847 */
848#define INFO_PORT 0
849#define INFO_IS_TX 1
850
851static bool cpp41_dma_filter_fn(struct dma_chan *chan, void *param)
852{
853 struct cppi41_channel *cchan;
854 struct cppi41_dd *cdd;
855 const struct chan_queues *queues;
856 u32 *num = param;
857
858 if (chan->device->dev->driver != &cpp41_dma_driver.driver)
859 return false;
860
861 cchan = to_cpp41_chan(chan);
862
863 if (cchan->port_num != num[INFO_PORT])
864 return false;
865
866 if (cchan->is_tx && !num[INFO_IS_TX])
867 return false;
868 cdd = cchan->cdd;
869 if (cchan->is_tx)
870 queues = cdd->queues_tx;
871 else
872 queues = cdd->queues_rx;
873
874 BUILD_BUG_ON(ARRAY_SIZE(usb_queues_rx) != ARRAY_SIZE(usb_queues_tx));
875 if (WARN_ON(cchan->port_num > ARRAY_SIZE(usb_queues_rx)))
876 return false;
877
878 cchan->q_num = queues[cchan->port_num].submit;
879 cchan->q_comp_num = queues[cchan->port_num].complete;
880 return true;
881}
882
883static struct of_dma_filter_info cpp41_dma_info = {
884 .filter_fn = cpp41_dma_filter_fn,
885};
886
887static struct dma_chan *cppi41_dma_xlate(struct of_phandle_args *dma_spec,
888 struct of_dma *ofdma)
889{
890 int count = dma_spec->args_count;
891 struct of_dma_filter_info *info = ofdma->of_dma_data;
892
893 if (!info || !info->filter_fn)
894 return NULL;
895
896 if (count != 2)
897 return NULL;
898
899 return dma_request_channel(info->dma_cap, info->filter_fn,
900 &dma_spec->args[0]);
901}
902
903static const struct cppi_glue_infos usb_infos = {
904 .isr = cppi41_irq,
905 .queues_rx = usb_queues_rx,
906 .queues_tx = usb_queues_tx,
907 .td_queue = { .submit = 31, .complete = 0 },
908};
909
910static const struct of_device_id cppi41_dma_ids[] = {
911 { .compatible = "ti,am3359-cppi41", .data = &usb_infos},
912 {},
913};
914MODULE_DEVICE_TABLE(of, cppi41_dma_ids);
915
916static const struct cppi_glue_infos *get_glue_info(struct platform_device *pdev)
917{
918 const struct of_device_id *of_id;
919
920 of_id = of_match_node(cppi41_dma_ids, pdev->dev.of_node);
921 if (!of_id)
922 return NULL;
923 return of_id->data;
924}
925
926static int cppi41_dma_probe(struct platform_device *pdev)
927{
928 struct cppi41_dd *cdd;
929 const struct cppi_glue_infos *glue_info;
930 int irq;
931 int ret;
932
933 glue_info = get_glue_info(pdev);
934 if (!glue_info)
935 return -EINVAL;
936
937 cdd = kzalloc(sizeof(*cdd), GFP_KERNEL);
938 if (!cdd)
939 return -ENOMEM;
940
941 dma_cap_set(DMA_SLAVE, cdd->ddev.cap_mask);
942 cdd->ddev.device_alloc_chan_resources = cppi41_dma_alloc_chan_resources;
943 cdd->ddev.device_free_chan_resources = cppi41_dma_free_chan_resources;
944 cdd->ddev.device_tx_status = cppi41_dma_tx_status;
945 cdd->ddev.device_issue_pending = cppi41_dma_issue_pending;
946 cdd->ddev.device_prep_slave_sg = cppi41_dma_prep_slave_sg;
947 cdd->ddev.device_control = cppi41_dma_control;
948 cdd->ddev.dev = &pdev->dev;
949 INIT_LIST_HEAD(&cdd->ddev.channels);
950 cpp41_dma_info.dma_cap = cdd->ddev.cap_mask;
951
952 cdd->usbss_mem = of_iomap(pdev->dev.of_node, 0);
953 cdd->ctrl_mem = of_iomap(pdev->dev.of_node, 1);
954 cdd->sched_mem = of_iomap(pdev->dev.of_node, 2);
955 cdd->qmgr_mem = of_iomap(pdev->dev.of_node, 3);
956
957 if (!cdd->usbss_mem || !cdd->ctrl_mem || !cdd->sched_mem ||
958 !cdd->qmgr_mem) {
959 ret = -ENXIO;
960 goto err_remap;
961 }
962
963 cdd->queues_rx = glue_info->queues_rx;
964 cdd->queues_tx = glue_info->queues_tx;
965 cdd->td_queue = glue_info->td_queue;
966
967 ret = init_cppi41(pdev, cdd);
968 if (ret)
969 goto err_init_cppi;
970
971 ret = cppi41_add_chans(pdev, cdd);
972 if (ret)
973 goto err_chans;
974
975 irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
976 if (!irq)
977 goto err_irq;
978
979 cppi_writel(USBSS_IRQ_PD_COMP, cdd->usbss_mem + USBSS_IRQ_ENABLER);
980
981 ret = request_irq(irq, glue_info->isr, IRQF_SHARED,
982 dev_name(&pdev->dev), cdd);
983 if (ret)
984 goto err_irq;
985 cdd->irq = irq;
986
987 ret = dma_async_device_register(&cdd->ddev);
988 if (ret)
989 goto err_dma_reg;
990
991 ret = of_dma_controller_register(pdev->dev.of_node,
992 cppi41_dma_xlate, &cpp41_dma_info);
993 if (ret)
994 goto err_of;
995
996 platform_set_drvdata(pdev, cdd);
997 return 0;
998err_of:
999 dma_async_device_unregister(&cdd->ddev);
1000err_dma_reg:
1001 free_irq(irq, cdd);
1002err_irq:
1003 cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
1004 cleanup_chans(cdd);
1005err_chans:
1006 deinit_cpii41(pdev, cdd);
1007err_init_cppi:
1008 iounmap(cdd->usbss_mem);
1009 iounmap(cdd->ctrl_mem);
1010 iounmap(cdd->sched_mem);
1011 iounmap(cdd->qmgr_mem);
1012err_remap:
1013 kfree(cdd);
1014 return ret;
1015}
1016
1017static int cppi41_dma_remove(struct platform_device *pdev)
1018{
1019 struct cppi41_dd *cdd = platform_get_drvdata(pdev);
1020
1021 of_dma_controller_free(pdev->dev.of_node);
1022 dma_async_device_unregister(&cdd->ddev);
1023
1024 cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
1025 free_irq(cdd->irq, cdd);
1026 cleanup_chans(cdd);
1027 deinit_cpii41(pdev, cdd);
1028 iounmap(cdd->usbss_mem);
1029 iounmap(cdd->ctrl_mem);
1030 iounmap(cdd->sched_mem);
1031 iounmap(cdd->qmgr_mem);
1032 kfree(cdd);
1033 return 0;
1034}
1035
1036static struct platform_driver cpp41_dma_driver = {
1037 .probe = cppi41_dma_probe,
1038 .remove = cppi41_dma_remove,
1039 .driver = {
1040 .name = "cppi41-dma-engine",
1041 .owner = THIS_MODULE,
1042 .of_match_table = of_match_ptr(cppi41_dma_ids),
1043 },
1044};
1045
1046module_platform_driver(cpp41_dma_driver);
1047MODULE_LICENSE("GPL");
1048MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");
diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
index 2bc87e3a8141..4233c05a3e32 100644
--- a/drivers/net/usb/ax88179_178a.c
+++ b/drivers/net/usb/ax88179_178a.c
@@ -1028,12 +1028,20 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
1028 dev->mii.phy_id = 0x03; 1028 dev->mii.phy_id = 0x03;
1029 dev->mii.supports_gmii = 1; 1029 dev->mii.supports_gmii = 1;
1030 1030
1031 if (usb_device_no_sg_constraint(dev->udev))
1032 dev->can_dma_sg = 1;
1033
1031 dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 1034 dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1032 NETIF_F_RXCSUM; 1035 NETIF_F_RXCSUM;
1033 1036
1034 dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 1037 dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1035 NETIF_F_RXCSUM; 1038 NETIF_F_RXCSUM;
1036 1039
1040 if (dev->can_dma_sg) {
1041 dev->net->features |= NETIF_F_SG | NETIF_F_TSO;
1042 dev->net->hw_features |= NETIF_F_SG | NETIF_F_TSO;
1043 }
1044
1037 /* Enable checksum offload */ 1045 /* Enable checksum offload */
1038 *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 1046 *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
1039 AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 1047 AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 06ee82f557d4..27a00b006033 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1197,6 +1197,37 @@ EXPORT_SYMBOL_GPL(usbnet_tx_timeout);
1197 1197
1198/*-------------------------------------------------------------------------*/ 1198/*-------------------------------------------------------------------------*/
1199 1199
1200static int build_dma_sg(const struct sk_buff *skb, struct urb *urb)
1201{
1202 unsigned num_sgs, total_len = 0;
1203 int i, s = 0;
1204
1205 num_sgs = skb_shinfo(skb)->nr_frags + 1;
1206 if (num_sgs == 1)
1207 return 0;
1208
1209 urb->sg = kmalloc(num_sgs * sizeof(struct scatterlist), GFP_ATOMIC);
1210 if (!urb->sg)
1211 return -ENOMEM;
1212
1213 urb->num_sgs = num_sgs;
1214 sg_init_table(urb->sg, urb->num_sgs);
1215
1216 sg_set_buf(&urb->sg[s++], skb->data, skb_headlen(skb));
1217 total_len += skb_headlen(skb);
1218
1219 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1220 struct skb_frag_struct *f = &skb_shinfo(skb)->frags[i];
1221
1222 total_len += skb_frag_size(f);
1223 sg_set_page(&urb->sg[i + s], f->page.p, f->size,
1224 f->page_offset);
1225 }
1226 urb->transfer_buffer_length = total_len;
1227
1228 return 1;
1229}
1230
1200netdev_tx_t usbnet_start_xmit (struct sk_buff *skb, 1231netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
1201 struct net_device *net) 1232 struct net_device *net)
1202{ 1233{
@@ -1223,7 +1254,6 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
1223 goto drop; 1254 goto drop;
1224 } 1255 }
1225 } 1256 }
1226 length = skb->len;
1227 1257
1228 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) { 1258 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
1229 netif_dbg(dev, tx_err, dev->net, "no urb\n"); 1259 netif_dbg(dev, tx_err, dev->net, "no urb\n");
@@ -1233,10 +1263,14 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
1233 entry = (struct skb_data *) skb->cb; 1263 entry = (struct skb_data *) skb->cb;
1234 entry->urb = urb; 1264 entry->urb = urb;
1235 entry->dev = dev; 1265 entry->dev = dev;
1236 entry->length = length;
1237 1266
1238 usb_fill_bulk_urb (urb, dev->udev, dev->out, 1267 usb_fill_bulk_urb (urb, dev->udev, dev->out,
1239 skb->data, skb->len, tx_complete, skb); 1268 skb->data, skb->len, tx_complete, skb);
1269 if (dev->can_dma_sg) {
1270 if (build_dma_sg(skb, urb) < 0)
1271 goto drop;
1272 }
1273 entry->length = length = urb->transfer_buffer_length;
1240 1274
1241 /* don't assume the hardware handles USB_ZERO_PACKET 1275 /* don't assume the hardware handles USB_ZERO_PACKET
1242 * NOTE: strictly conforming cdc-ether devices should expect 1276 * NOTE: strictly conforming cdc-ether devices should expect
@@ -1305,7 +1339,10 @@ drop:
1305not_drop: 1339not_drop:
1306 if (skb) 1340 if (skb)
1307 dev_kfree_skb_any (skb); 1341 dev_kfree_skb_any (skb);
1308 usb_free_urb (urb); 1342 if (urb) {
1343 kfree(urb->sg);
1344 usb_free_urb(urb);
1345 }
1309 } else 1346 } else
1310 netif_dbg(dev, tx_queued, dev->net, 1347 netif_dbg(dev, tx_queued, dev->net,
1311 "> tx, len %d, type 0x%x\n", length, skb->protocol); 1348 "> tx, len %d, type 0x%x\n", length, skb->protocol);
@@ -1356,6 +1393,7 @@ static void usbnet_bh (unsigned long param)
1356 rx_process (dev, skb); 1393 rx_process (dev, skb);
1357 continue; 1394 continue;
1358 case tx_done: 1395 case tx_done:
1396 kfree(entry->urb->sg);
1359 case rx_cleanup: 1397 case rx_cleanup:
1360 usb_free_urb (entry->urb); 1398 usb_free_urb (entry->urb);
1361 dev_kfree_skb (skb); 1399 dev_kfree_skb (skb);
@@ -1689,6 +1727,7 @@ int usbnet_resume (struct usb_interface *intf)
1689 retval = usb_submit_urb(res, GFP_ATOMIC); 1727 retval = usb_submit_urb(res, GFP_ATOMIC);
1690 if (retval < 0) { 1728 if (retval < 0) {
1691 dev_kfree_skb_any(skb); 1729 dev_kfree_skb_any(skb);
1730 kfree(res->sg);
1692 usb_free_urb(res); 1731 usb_free_urb(res);
1693 usb_autopm_put_interface_async(dev->intf); 1732 usb_autopm_put_interface_async(dev->intf);
1694 } else { 1733 } else {
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 73f62caa8609..2642b8a11e05 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -6,9 +6,26 @@
6config USB_ARCH_HAS_OHCI 6config USB_ARCH_HAS_OHCI
7 bool 7 bool
8 8
9config USB_OHCI_BIG_ENDIAN_DESC
10 bool
11
12config USB_OHCI_BIG_ENDIAN_MMIO
13 bool
14
15config USB_OHCI_LITTLE_ENDIAN
16 bool
17 default n if STB03xxx || PPC_MPC52xx
18 default y
19
9config USB_ARCH_HAS_EHCI 20config USB_ARCH_HAS_EHCI
10 bool 21 bool
11 22
23config USB_EHCI_BIG_ENDIAN_MMIO
24 bool
25
26config USB_EHCI_BIG_ENDIAN_DESC
27 bool
28
12config USB_ARCH_HAS_XHCI 29config USB_ARCH_HAS_XHCI
13 bool 30 bool
14 31
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 238c5d47cadb..70d7c5b92c3c 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_USB_ISP1760_HCD) += host/
26obj-$(CONFIG_USB_IMX21_HCD) += host/ 26obj-$(CONFIG_USB_IMX21_HCD) += host/
27obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/ 27obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
28obj-$(CONFIG_USB_FUSBH200_HCD) += host/ 28obj-$(CONFIG_USB_FUSBH200_HCD) += host/
29obj-$(CONFIG_USB_FOTG210_HCD) += host/
29 30
30obj-$(CONFIG_USB_C67X00_HCD) += c67x00/ 31obj-$(CONFIG_USB_C67X00_HCD) += c67x00/
31 32
@@ -45,7 +46,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/
45obj-$(CONFIG_USB_SERIAL) += serial/ 46obj-$(CONFIG_USB_SERIAL) += serial/
46 47
47obj-$(CONFIG_USB) += misc/ 48obj-$(CONFIG_USB) += misc/
48obj-$(CONFIG_USB_PHY) += phy/ 49obj-$(CONFIG_USB_SUPPORT) += phy/
49obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/ 50obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/
50 51
51obj-$(CONFIG_USB_ATM) += atm/ 52obj-$(CONFIG_USB_ATM) += atm/
diff --git a/drivers/usb/atm/Makefile b/drivers/usb/atm/Makefile
index a5d792ec3ad5..ac278946b06c 100644
--- a/drivers/usb/atm/Makefile
+++ b/drivers/usb/atm/Makefile
@@ -1,9 +1,6 @@
1# 1#
2# Makefile for USB ATM/xDSL drivers 2# Makefile for USB ATM/xDSL drivers
3# 3#
4
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6
7obj-$(CONFIG_USB_CXACRU) += cxacru.o 4obj-$(CONFIG_USB_CXACRU) += cxacru.o
8obj-$(CONFIG_USB_SPEEDTOUCH) += speedtch.o 5obj-$(CONFIG_USB_SPEEDTOUCH) += speedtch.o
9obj-$(CONFIG_USB_UEAGLEATM) += ueagle-atm.o 6obj-$(CONFIG_USB_UEAGLEATM) += ueagle-atm.o
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 807627b36cc8..69461d653972 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -888,7 +888,7 @@ static int speedtch_bind(struct usbatm_data *usbatm,
888 usb_fill_int_urb(instance->int_urb, usb_dev, 888 usb_fill_int_urb(instance->int_urb, usb_dev,
889 usb_rcvintpipe(usb_dev, ENDPOINT_INT), 889 usb_rcvintpipe(usb_dev, ENDPOINT_INT),
890 instance->int_data, sizeof(instance->int_data), 890 instance->int_data, sizeof(instance->int_data),
891 speedtch_handle_int, instance, 50); 891 speedtch_handle_int, instance, 16);
892 else 892 else
893 usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__); 893 usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__);
894 894
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 5e0d33a7da58..25a7bfcf666c 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -311,8 +311,6 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
311 int vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4); 311 int vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
312 u8 pti = ((source[3] & 0xe) >> 1); 312 u8 pti = ((source[3] & 0xe) >> 1);
313 313
314 vdbg(&instance->usb_intf->dev, "%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti);
315
316 if ((vci != instance->cached_vci) || (vpi != instance->cached_vpi)) { 314 if ((vci != instance->cached_vci) || (vpi != instance->cached_vpi)) {
317 instance->cached_vpi = vpi; 315 instance->cached_vpi = vpi;
318 instance->cached_vci = vci; 316 instance->cached_vci = vci;
@@ -344,7 +342,6 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
344 __func__, sarb->len, vcc); 342 __func__, sarb->len, vcc);
345 /* discard cells already received */ 343 /* discard cells already received */
346 skb_trim(sarb, 0); 344 skb_trim(sarb, 0);
347 UDSL_ASSERT(instance, sarb->tail + ATM_CELL_PAYLOAD <= sarb->end);
348 } 345 }
349 346
350 memcpy(skb_tail_pointer(sarb), source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD); 347 memcpy(skb_tail_pointer(sarb), source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
@@ -437,8 +434,6 @@ static void usbatm_extract_cells(struct usbatm_data *instance,
437 unsigned char *cell_buf = instance->cell_buf; 434 unsigned char *cell_buf = instance->cell_buf;
438 unsigned int space_left = stride - buf_usage; 435 unsigned int space_left = stride - buf_usage;
439 436
440 UDSL_ASSERT(instance, buf_usage <= stride);
441
442 if (avail_data >= space_left) { 437 if (avail_data >= space_left) {
443 /* add new data and process cell */ 438 /* add new data and process cell */
444 memcpy(cell_buf + buf_usage, source, space_left); 439 memcpy(cell_buf + buf_usage, source, space_left);
@@ -479,10 +474,6 @@ static unsigned int usbatm_write_cells(struct usbatm_data *instance,
479 unsigned int bytes_written; 474 unsigned int bytes_written;
480 unsigned int stride = instance->tx_channel.stride; 475 unsigned int stride = instance->tx_channel.stride;
481 476
482 vdbg(&instance->usb_intf->dev, "%s: skb->len=%d, avail_space=%u",
483 __func__, skb->len, avail_space);
484 UDSL_ASSERT(instance, !(avail_space % stride));
485
486 for (bytes_written = 0; bytes_written < avail_space && ctrl->len; 477 for (bytes_written = 0; bytes_written < avail_space && ctrl->len;
487 bytes_written += stride, target += stride) { 478 bytes_written += stride, target += stride) {
488 unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD); 479 unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD);
@@ -553,8 +544,6 @@ static void usbatm_rx_process(unsigned long data)
553 if (!urb->iso_frame_desc[i].status) { 544 if (!urb->iso_frame_desc[i].status) {
554 unsigned int actual_length = urb->iso_frame_desc[i].actual_length; 545 unsigned int actual_length = urb->iso_frame_desc[i].actual_length;
555 546
556 UDSL_ASSERT(instance, actual_length <= packet_size);
557
558 if (!merge_length) 547 if (!merge_length)
559 merge_start = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset; 548 merge_start = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
560 merge_length += actual_length; 549 merge_length += actual_length;
@@ -645,7 +634,6 @@ static void usbatm_cancel_send(struct usbatm_data *instance,
645{ 634{
646 struct sk_buff *skb, *n; 635 struct sk_buff *skb, *n;
647 636
648 atm_dbg(instance, "%s entered\n", __func__);
649 spin_lock_irq(&instance->sndqueue.lock); 637 spin_lock_irq(&instance->sndqueue.lock);
650 skb_queue_walk_safe(&instance->sndqueue, skb, n) { 638 skb_queue_walk_safe(&instance->sndqueue, skb, n) {
651 if (UDSL_SKB(skb)->atm.vcc == vcc) { 639 if (UDSL_SKB(skb)->atm.vcc == vcc) {
@@ -663,7 +651,6 @@ static void usbatm_cancel_send(struct usbatm_data *instance,
663 usbatm_pop(vcc, skb); 651 usbatm_pop(vcc, skb);
664 } 652 }
665 tasklet_enable(&instance->tx_channel.tasklet); 653 tasklet_enable(&instance->tx_channel.tasklet);
666 atm_dbg(instance, "%s done\n", __func__);
667} 654}
668 655
669static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb) 656static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
@@ -674,16 +661,13 @@ static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
674 661
675 /* racy disconnection check - fine */ 662 /* racy disconnection check - fine */
676 if (!instance || instance->disconnected) { 663 if (!instance || instance->disconnected) {
677#ifdef DEBUG 664#ifdef VERBOSE_DEBUG
678 printk_ratelimited(KERN_DEBUG "%s: %s!\n", __func__, instance ? "disconnected" : "NULL instance"); 665 printk_ratelimited(KERN_DEBUG "%s: %s!\n", __func__, instance ? "disconnected" : "NULL instance");
679#endif 666#endif
680 err = -ENODEV; 667 err = -ENODEV;
681 goto fail; 668 goto fail;
682 } 669 }
683 670
684 vdbg(&instance->usb_intf->dev, "%s called (skb 0x%p, len %u)", __func__,
685 skb, skb->len);
686
687 if (vcc->qos.aal != ATM_AAL5) { 671 if (vcc->qos.aal != ATM_AAL5) {
688 atm_rldbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 672 atm_rldbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
689 err = -EINVAL; 673 err = -EINVAL;
@@ -723,8 +707,6 @@ static void usbatm_destroy_instance(struct kref *kref)
723{ 707{
724 struct usbatm_data *instance = container_of(kref, struct usbatm_data, refcount); 708 struct usbatm_data *instance = container_of(kref, struct usbatm_data, refcount);
725 709
726 usb_dbg(instance, "%s\n", __func__);
727
728 tasklet_kill(&instance->rx_channel.tasklet); 710 tasklet_kill(&instance->rx_channel.tasklet);
729 tasklet_kill(&instance->tx_channel.tasklet); 711 tasklet_kill(&instance->tx_channel.tasklet);
730 usb_put_dev(instance->usb_dev); 712 usb_put_dev(instance->usb_dev);
@@ -733,15 +715,11 @@ static void usbatm_destroy_instance(struct kref *kref)
733 715
734static void usbatm_get_instance(struct usbatm_data *instance) 716static void usbatm_get_instance(struct usbatm_data *instance)
735{ 717{
736 usb_dbg(instance, "%s\n", __func__);
737
738 kref_get(&instance->refcount); 718 kref_get(&instance->refcount);
739} 719}
740 720
741static void usbatm_put_instance(struct usbatm_data *instance) 721static void usbatm_put_instance(struct usbatm_data *instance)
742{ 722{
743 usb_dbg(instance, "%s\n", __func__);
744
745 kref_put(&instance->refcount, usbatm_destroy_instance); 723 kref_put(&instance->refcount, usbatm_destroy_instance);
746} 724}
747 725
@@ -757,7 +735,6 @@ static void usbatm_atm_dev_close(struct atm_dev *atm_dev)
757 if (!instance) 735 if (!instance)
758 return; 736 return;
759 737
760 usb_dbg(instance, "%s\n", __func__);
761 atm_dev->dev_data = NULL; /* catch bugs */ 738 atm_dev->dev_data = NULL; /* catch bugs */
762 usbatm_put_instance(instance); /* taken in usbatm_atm_init */ 739 usbatm_put_instance(instance); /* taken in usbatm_atm_init */
763} 740}
@@ -813,8 +790,6 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
813 if (!instance) 790 if (!instance)
814 return -ENODEV; 791 return -ENODEV;
815 792
816 atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci);
817
818 /* only support AAL5 */ 793 /* only support AAL5 */
819 if ((vcc->qos.aal != ATM_AAL5)) { 794 if ((vcc->qos.aal != ATM_AAL5)) {
820 atm_warn(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 795 atm_warn(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
@@ -891,11 +866,6 @@ static void usbatm_atm_close(struct atm_vcc *vcc)
891 if (!instance || !vcc_data) 866 if (!instance || !vcc_data)
892 return; 867 return;
893 868
894 atm_dbg(instance, "%s entered\n", __func__);
895
896 atm_dbg(instance, "%s: deallocating vcc 0x%p with vpi %d vci %d\n",
897 __func__, vcc_data, vcc_data->vpi, vcc_data->vci);
898
899 usbatm_cancel_send(instance, vcc); 869 usbatm_cancel_send(instance, vcc);
900 870
901 mutex_lock(&instance->serialize); /* vs self, usbatm_atm_open, usbatm_usb_disconnect */ 871 mutex_lock(&instance->serialize); /* vs self, usbatm_atm_open, usbatm_usb_disconnect */
@@ -922,8 +892,6 @@ static void usbatm_atm_close(struct atm_vcc *vcc)
922 clear_bit(ATM_VF_ADDR, &vcc->flags); 892 clear_bit(ATM_VF_ADDR, &vcc->flags);
923 893
924 mutex_unlock(&instance->serialize); 894 mutex_unlock(&instance->serialize);
925
926 atm_dbg(instance, "%s successful\n", __func__);
927} 895}
928 896
929static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, 897static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd,
@@ -1060,12 +1028,6 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1060 int i, length; 1028 int i, length;
1061 unsigned int maxpacket, num_packets; 1029 unsigned int maxpacket, num_packets;
1062 1030
1063 dev_dbg(dev, "%s: trying driver %s with vendor=%04x, product=%04x, ifnum %2d\n",
1064 __func__, driver->driver_name,
1065 le16_to_cpu(usb_dev->descriptor.idVendor),
1066 le16_to_cpu(usb_dev->descriptor.idProduct),
1067 intf->altsetting->desc.bInterfaceNumber);
1068
1069 /* instance init */ 1031 /* instance init */
1070 instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL); 1032 instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL);
1071 if (!instance) { 1033 if (!instance) {
@@ -1158,14 +1120,13 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1158 instance->rx_channel.buf_size = num_packets * maxpacket; 1120 instance->rx_channel.buf_size = num_packets * maxpacket;
1159 instance->rx_channel.packet_size = maxpacket; 1121 instance->rx_channel.packet_size = maxpacket;
1160 1122
1161#ifdef DEBUG
1162 for (i = 0; i < 2; i++) { 1123 for (i = 0; i < 2; i++) {
1163 struct usbatm_channel *channel = i ? 1124 struct usbatm_channel *channel = i ?
1164 &instance->tx_channel : &instance->rx_channel; 1125 &instance->tx_channel : &instance->rx_channel;
1165 1126
1166 dev_dbg(dev, "%s: using %d byte buffer for %s channel 0x%p\n", __func__, channel->buf_size, i ? "tx" : "rx", channel); 1127 dev_dbg(dev, "%s: using %d byte buffer for %s channel 0x%p\n",
1128 __func__, channel->buf_size, i ? "tx" : "rx", channel);
1167 } 1129 }
1168#endif
1169 1130
1170 /* initialize urbs */ 1131 /* initialize urbs */
1171 1132
@@ -1176,8 +1137,6 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1176 struct urb *urb; 1137 struct urb *urb;
1177 unsigned int iso_packets = usb_pipeisoc(channel->endpoint) ? channel->buf_size / channel->packet_size : 0; 1138 unsigned int iso_packets = usb_pipeisoc(channel->endpoint) ? channel->buf_size / channel->packet_size : 0;
1178 1139
1179 UDSL_ASSERT(instance, !usb_pipeisoc(channel->endpoint) || usb_pipein(channel->endpoint));
1180
1181 urb = usb_alloc_urb(iso_packets, GFP_KERNEL); 1140 urb = usb_alloc_urb(iso_packets, GFP_KERNEL);
1182 if (!urb) { 1141 if (!urb) {
1183 dev_err(dev, "%s: no memory for urb %d!\n", __func__, i); 1142 dev_err(dev, "%s: no memory for urb %d!\n", __func__, i);
@@ -1266,8 +1225,6 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
1266 struct usbatm_vcc_data *vcc_data; 1225 struct usbatm_vcc_data *vcc_data;
1267 int i; 1226 int i;
1268 1227
1269 dev_dbg(dev, "%s entered\n", __func__);
1270
1271 if (!instance) { 1228 if (!instance) {
1272 dev_dbg(dev, "%s: NULL instance!\n", __func__); 1229 dev_dbg(dev, "%s: NULL instance!\n", __func__);
1273 return; 1230 return;
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h
index 5fc489405217..5651231a7437 100644
--- a/drivers/usb/atm/usbatm.h
+++ b/drivers/usb/atm/usbatm.h
@@ -39,31 +39,14 @@
39#define VERBOSE_DEBUG 39#define VERBOSE_DEBUG
40*/ 40*/
41 41
42#ifdef DEBUG
43#define UDSL_ASSERT(instance, x) BUG_ON(!(x))
44#else
45#define UDSL_ASSERT(instance, x) \
46 do { \
47 if (!(x)) \
48 dev_warn(&(instance)->usb_intf->dev, \
49 "failed assertion '%s' at line %d", \
50 __stringify(x), __LINE__); \
51 } while (0)
52#endif
53
54#define usb_err(instance, format, arg...) \ 42#define usb_err(instance, format, arg...) \
55 dev_err(&(instance)->usb_intf->dev , format , ## arg) 43 dev_err(&(instance)->usb_intf->dev , format , ## arg)
56#define usb_info(instance, format, arg...) \ 44#define usb_info(instance, format, arg...) \
57 dev_info(&(instance)->usb_intf->dev , format , ## arg) 45 dev_info(&(instance)->usb_intf->dev , format , ## arg)
58#define usb_warn(instance, format, arg...) \ 46#define usb_warn(instance, format, arg...) \
59 dev_warn(&(instance)->usb_intf->dev , format , ## arg) 47 dev_warn(&(instance)->usb_intf->dev , format , ## arg)
60#ifdef DEBUG
61#define usb_dbg(instance, format, arg...) \
62 dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg)
63#else
64#define usb_dbg(instance, format, arg...) \ 48#define usb_dbg(instance, format, arg...) \
65 do {} while (0) 49 dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
66#endif
67 50
68/* FIXME: move to dev_* once ATM is driver model aware */ 51/* FIXME: move to dev_* once ATM is driver model aware */
69#define atm_printk(level, instance, format, arg...) \ 52#define atm_printk(level, instance, format, arg...) \
@@ -76,18 +59,12 @@
76 atm_printk(KERN_INFO, instance , format , ## arg) 59 atm_printk(KERN_INFO, instance , format , ## arg)
77#define atm_warn(instance, format, arg...) \ 60#define atm_warn(instance, format, arg...) \
78 atm_printk(KERN_WARNING, instance , format , ## arg) 61 atm_printk(KERN_WARNING, instance , format , ## arg)
79#ifdef DEBUG 62#define atm_dbg(instance, format, arg...) \
80#define atm_dbg(instance, format, arg...) \ 63 dynamic_pr_debug("ATM dev %d: " format , \
81 atm_printk(KERN_DEBUG, instance , format , ## arg) 64 (instance)->atm_dev->number , ## arg)
82#define atm_rldbg(instance, format, arg...) \ 65#define atm_rldbg(instance, format, arg...) \
83 if (printk_ratelimit()) \ 66 if (printk_ratelimit()) \
84 atm_printk(KERN_DEBUG, instance , format , ## arg) 67 atm_dbg(instance , format , ## arg)
85#else
86#define atm_dbg(instance, format, arg...) \
87 do {} while (0)
88#define atm_rldbg(instance, format, arg...) \
89 do {} while (0)
90#endif
91 68
92 69
93/* flags, set by mini-driver in bind() */ 70/* flags, set by mini-driver in bind() */
diff --git a/drivers/usb/c67x00/c67x00-drv.c b/drivers/usb/c67x00/c67x00-drv.c
index fe815ecd557e..8db3380c3329 100644
--- a/drivers/usb/c67x00/c67x00-drv.c
+++ b/drivers/usb/c67x00/c67x00-drv.c
@@ -131,7 +131,7 @@ static int c67x00_drv_probe(struct platform_device *pdev)
131 if (!res2) 131 if (!res2)
132 return -ENODEV; 132 return -ENODEV;
133 133
134 pdata = pdev->dev.platform_data; 134 pdata = dev_get_platdata(&pdev->dev);
135 if (!pdata) 135 if (!pdata)
136 return -ENODEV; 136 return -ENODEV;
137 137
@@ -154,7 +154,7 @@ static int c67x00_drv_probe(struct platform_device *pdev)
154 154
155 spin_lock_init(&c67x00->hpi.lock); 155 spin_lock_init(&c67x00->hpi.lock);
156 c67x00->hpi.regstep = pdata->hpi_regstep; 156 c67x00->hpi.regstep = pdata->hpi_regstep;
157 c67x00->pdata = pdev->dev.platform_data; 157 c67x00->pdata = dev_get_platdata(&pdev->dev);
158 c67x00->pdev = pdev; 158 c67x00->pdev = pdev;
159 159
160 c67x00_ll_init(c67x00); 160 c67x00_ll_init(c67x00);
diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig
index d1bd8ef1f9c1..4a851e15e58c 100644
--- a/drivers/usb/chipidea/Kconfig
+++ b/drivers/usb/chipidea/Kconfig
@@ -1,6 +1,6 @@
1config USB_CHIPIDEA 1config USB_CHIPIDEA
2 tristate "ChipIdea Highspeed Dual Role Controller" 2 tristate "ChipIdea Highspeed Dual Role Controller"
3 depends on USB || USB_GADGET 3 depends on (USB_EHCI_HCD && USB_GADGET) || (USB_EHCI_HCD && !USB_GADGET) || (!USB_EHCI_HCD && USB_GADGET)
4 help 4 help
5 Say Y here if your system has a dual role high speed USB 5 Say Y here if your system has a dual role high speed USB
6 controller based on ChipIdea silicon IP. Currently, only the 6 controller based on ChipIdea silicon IP. Currently, only the
@@ -12,15 +12,14 @@ if USB_CHIPIDEA
12 12
13config USB_CHIPIDEA_UDC 13config USB_CHIPIDEA_UDC
14 bool "ChipIdea device controller" 14 bool "ChipIdea device controller"
15 depends on USB_GADGET=y || (USB_CHIPIDEA=m && USB_GADGET=m) 15 depends on USB_GADGET
16 help 16 help
17 Say Y here to enable device controller functionality of the 17 Say Y here to enable device controller functionality of the
18 ChipIdea driver. 18 ChipIdea driver.
19 19
20config USB_CHIPIDEA_HOST 20config USB_CHIPIDEA_HOST
21 bool "ChipIdea host controller" 21 bool "ChipIdea host controller"
22 depends on USB=y 22 depends on USB_EHCI_HCD
23 depends on USB_EHCI_HCD=y || (USB_CHIPIDEA=m && USB_EHCI_HCD=m)
24 select USB_EHCI_ROOT_HUB_TT 23 select USB_EHCI_ROOT_HUB_TT
25 help 24 help
26 Say Y here to enable host controller functionality of the 25 Say Y here to enable host controller functionality of the
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index 6cf5f68dedd8..a99d980454a6 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -2,7 +2,7 @@ ccflags-$(CONFIG_USB_CHIPIDEA_DEBUG) := -DDEBUG
2 2
3obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc.o 3obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc.o
4 4
5ci_hdrc-y := core.o 5ci_hdrc-y := core.o otg.o
6ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o 6ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o
7ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o 7ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o
8ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o 8ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 1b23e354f9fb..464584c6ccae 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -79,11 +79,21 @@
79#define OTGSC_ASVIS BIT(18) 79#define OTGSC_ASVIS BIT(18)
80#define OTGSC_BSVIS BIT(19) 80#define OTGSC_BSVIS BIT(19)
81#define OTGSC_BSEIS BIT(20) 81#define OTGSC_BSEIS BIT(20)
82#define OTGSC_1MSIS BIT(21)
83#define OTGSC_DPIS BIT(22)
82#define OTGSC_IDIE BIT(24) 84#define OTGSC_IDIE BIT(24)
83#define OTGSC_AVVIE BIT(25) 85#define OTGSC_AVVIE BIT(25)
84#define OTGSC_ASVIE BIT(26) 86#define OTGSC_ASVIE BIT(26)
85#define OTGSC_BSVIE BIT(27) 87#define OTGSC_BSVIE BIT(27)
86#define OTGSC_BSEIE BIT(28) 88#define OTGSC_BSEIE BIT(28)
89#define OTGSC_1MSIE BIT(29)
90#define OTGSC_DPIE BIT(30)
91#define OTGSC_INT_EN_BITS (OTGSC_IDIE | OTGSC_AVVIE | OTGSC_ASVIE \
92 | OTGSC_BSVIE | OTGSC_BSEIE | OTGSC_1MSIE \
93 | OTGSC_DPIE)
94#define OTGSC_INT_STATUS_BITS (OTGSC_IDIS | OTGSC_AVVIS | OTGSC_ASVIS \
95 | OTGSC_BSVIS | OTGSC_BSEIS | OTGSC_1MSIS \
96 | OTGSC_DPIS)
87 97
88/* USBMODE */ 98/* USBMODE */
89#define USBMODE_CM (0x03UL << 0) 99#define USBMODE_CM (0x03UL << 0)
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index 33cb29f36e06..1c94fc5257f4 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -132,6 +132,9 @@ struct hw_bank {
132 * @transceiver: pointer to USB PHY, if any 132 * @transceiver: pointer to USB PHY, if any
133 * @hcd: pointer to usb_hcd for ehci host driver 133 * @hcd: pointer to usb_hcd for ehci host driver
134 * @debugfs: root dentry for this controller in debugfs 134 * @debugfs: root dentry for this controller in debugfs
135 * @id_event: indicates there is an id event, and handled at ci_otg_work
136 * @b_sess_valid_event: indicates there is a vbus event, and handled
137 * at ci_otg_work
135 */ 138 */
136struct ci_hdrc { 139struct ci_hdrc {
137 struct device *dev; 140 struct device *dev;
@@ -168,6 +171,8 @@ struct ci_hdrc {
168 struct usb_phy *transceiver; 171 struct usb_phy *transceiver;
169 struct usb_hcd *hcd; 172 struct usb_hcd *hcd;
170 struct dentry *debugfs; 173 struct dentry *debugfs;
174 bool id_event;
175 bool b_sess_valid_event;
171}; 176};
172 177
173static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) 178static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci)
@@ -303,4 +308,7 @@ int hw_port_test_set(struct ci_hdrc *ci, u8 mode);
303 308
304u8 hw_port_test_get(struct ci_hdrc *ci); 309u8 hw_port_test_get(struct ci_hdrc *ci);
305 310
311int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask,
312 u32 value, unsigned int timeout_ms);
313
306#endif /* __DRIVERS_USB_CHIPIDEA_CI_H */ 314#endif /* __DRIVERS_USB_CHIPIDEA_CI_H */
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index 14362c00db3f..74d998d9b45b 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -19,70 +19,56 @@
19#include <linux/dma-mapping.h> 19#include <linux/dma-mapping.h>
20#include <linux/usb/chipidea.h> 20#include <linux/usb/chipidea.h>
21#include <linux/clk.h> 21#include <linux/clk.h>
22#include <linux/regulator/consumer.h>
23 22
24#include "ci.h" 23#include "ci.h"
25#include "ci_hdrc_imx.h" 24#include "ci_hdrc_imx.h"
26 25
27#define pdev_to_phy(pdev) \
28 ((struct usb_phy *)platform_get_drvdata(pdev))
29
30struct ci_hdrc_imx_data { 26struct ci_hdrc_imx_data {
31 struct usb_phy *phy; 27 struct usb_phy *phy;
32 struct platform_device *ci_pdev; 28 struct platform_device *ci_pdev;
33 struct clk *clk; 29 struct clk *clk;
34 struct regulator *reg_vbus; 30 struct imx_usbmisc_data *usbmisc_data;
35}; 31};
36 32
37static const struct usbmisc_ops *usbmisc_ops;
38
39/* Common functions shared by usbmisc drivers */ 33/* Common functions shared by usbmisc drivers */
40 34
41int usbmisc_set_ops(const struct usbmisc_ops *ops) 35static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev)
42{
43 if (usbmisc_ops)
44 return -EBUSY;
45
46 usbmisc_ops = ops;
47
48 return 0;
49}
50EXPORT_SYMBOL_GPL(usbmisc_set_ops);
51
52void usbmisc_unset_ops(const struct usbmisc_ops *ops)
53{
54 usbmisc_ops = NULL;
55}
56EXPORT_SYMBOL_GPL(usbmisc_unset_ops);
57
58int usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device *usbdev)
59{ 36{
60 struct device_node *np = dev->of_node; 37 struct device_node *np = dev->of_node;
61 struct of_phandle_args args; 38 struct of_phandle_args args;
39 struct imx_usbmisc_data *data;
62 int ret; 40 int ret;
63 41
64 usbdev->dev = dev; 42 /*
43 * In case the fsl,usbmisc property is not present this device doesn't
44 * need usbmisc. Return NULL (which is no error here)
45 */
46 if (!of_get_property(np, "fsl,usbmisc", NULL))
47 return NULL;
48
49 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
50 if (!data)
51 return ERR_PTR(-ENOMEM);
65 52
66 ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells", 53 ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells",
67 0, &args); 54 0, &args);
68 if (ret) { 55 if (ret) {
69 dev_err(dev, "Failed to parse property fsl,usbmisc, errno %d\n", 56 dev_err(dev, "Failed to parse property fsl,usbmisc, errno %d\n",
70 ret); 57 ret);
71 memset(usbdev, 0, sizeof(*usbdev)); 58 return ERR_PTR(ret);
72 return ret;
73 } 59 }
74 usbdev->index = args.args[0]; 60
61 data->index = args.args[0];
75 of_node_put(args.np); 62 of_node_put(args.np);
76 63
77 if (of_find_property(np, "disable-over-current", NULL)) 64 if (of_find_property(np, "disable-over-current", NULL))
78 usbdev->disable_oc = 1; 65 data->disable_oc = 1;
79 66
80 if (of_find_property(np, "external-vbus-divider", NULL)) 67 if (of_find_property(np, "external-vbus-divider", NULL))
81 usbdev->evdo = 1; 68 data->evdo = 1;
82 69
83 return 0; 70 return data;
84} 71}
85EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
86 72
87/* End of common functions shared by usbmisc drivers*/ 73/* End of common functions shared by usbmisc drivers*/
88 74
@@ -93,27 +79,19 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
93 .name = "ci_hdrc_imx", 79 .name = "ci_hdrc_imx",
94 .capoffset = DEF_CAPOFFSET, 80 .capoffset = DEF_CAPOFFSET,
95 .flags = CI_HDRC_REQUIRE_TRANSCEIVER | 81 .flags = CI_HDRC_REQUIRE_TRANSCEIVER |
96 CI_HDRC_PULLUP_ON_VBUS |
97 CI_HDRC_DISABLE_STREAMING, 82 CI_HDRC_DISABLE_STREAMING,
98 }; 83 };
99 struct resource *res;
100 int ret; 84 int ret;
101 85
102 if (of_find_property(pdev->dev.of_node, "fsl,usbmisc", NULL)
103 && !usbmisc_ops)
104 return -EPROBE_DEFER;
105
106 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 86 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
107 if (!data) { 87 if (!data) {
108 dev_err(&pdev->dev, "Failed to allocate ci_hdrc-imx data!\n"); 88 dev_err(&pdev->dev, "Failed to allocate ci_hdrc-imx data!\n");
109 return -ENOMEM; 89 return -ENOMEM;
110 } 90 }
111 91
112 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 92 data->usbmisc_data = usbmisc_get_init_data(&pdev->dev);
113 if (!res) { 93 if (IS_ERR(data->usbmisc_data))
114 dev_err(&pdev->dev, "Can't get device resources!\n"); 94 return PTR_ERR(data->usbmisc_data);
115 return -ENOENT;
116 }
117 95
118 data->clk = devm_clk_get(&pdev->dev, NULL); 96 data->clk = devm_clk_get(&pdev->dev, NULL);
119 if (IS_ERR(data->clk)) { 97 if (IS_ERR(data->clk)) {
@@ -141,20 +119,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
141 goto err_clk; 119 goto err_clk;
142 } 120 }
143 121
144 /* we only support host now, so enable vbus here */
145 data->reg_vbus = devm_regulator_get(&pdev->dev, "vbus");
146 if (!IS_ERR(data->reg_vbus)) {
147 ret = regulator_enable(data->reg_vbus);
148 if (ret) {
149 dev_err(&pdev->dev,
150 "Failed to enable vbus regulator, err=%d\n",
151 ret);
152 goto err_clk;
153 }
154 } else {
155 data->reg_vbus = NULL;
156 }
157
158 pdata.phy = data->phy; 122 pdata.phy = data->phy;
159 123
160 if (!pdev->dev.dma_mask) 124 if (!pdev->dev.dma_mask)
@@ -162,12 +126,12 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
162 if (!pdev->dev.coherent_dma_mask) 126 if (!pdev->dev.coherent_dma_mask)
163 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 127 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
164 128
165 if (usbmisc_ops && usbmisc_ops->init) { 129 if (data->usbmisc_data) {
166 ret = usbmisc_ops->init(&pdev->dev); 130 ret = imx_usbmisc_init(data->usbmisc_data);
167 if (ret) { 131 if (ret) {
168 dev_err(&pdev->dev, 132 dev_err(&pdev->dev, "usbmisc init failed, ret=%d\n",
169 "usbmisc init failed, ret=%d\n", ret); 133 ret);
170 goto err; 134 goto err_clk;
171 } 135 }
172 } 136 }
173 137
@@ -179,14 +143,14 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
179 dev_err(&pdev->dev, 143 dev_err(&pdev->dev,
180 "Can't register ci_hdrc platform device, err=%d\n", 144 "Can't register ci_hdrc platform device, err=%d\n",
181 ret); 145 ret);
182 goto err; 146 goto err_clk;
183 } 147 }
184 148
185 if (usbmisc_ops && usbmisc_ops->post) { 149 if (data->usbmisc_data) {
186 ret = usbmisc_ops->post(&pdev->dev); 150 ret = imx_usbmisc_init_post(data->usbmisc_data);
187 if (ret) { 151 if (ret) {
188 dev_err(&pdev->dev, 152 dev_err(&pdev->dev, "usbmisc post failed, ret=%d\n",
189 "usbmisc post failed, ret=%d\n", ret); 153 ret);
190 goto disable_device; 154 goto disable_device;
191 } 155 }
192 } 156 }
@@ -200,9 +164,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
200 164
201disable_device: 165disable_device:
202 ci_hdrc_remove_device(data->ci_pdev); 166 ci_hdrc_remove_device(data->ci_pdev);
203err:
204 if (data->reg_vbus)
205 regulator_disable(data->reg_vbus);
206err_clk: 167err_clk:
207 clk_disable_unprepare(data->clk); 168 clk_disable_unprepare(data->clk);
208 return ret; 169 return ret;
@@ -215,13 +176,8 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
215 pm_runtime_disable(&pdev->dev); 176 pm_runtime_disable(&pdev->dev);
216 ci_hdrc_remove_device(data->ci_pdev); 177 ci_hdrc_remove_device(data->ci_pdev);
217 178
218 if (data->reg_vbus) 179 if (data->phy)
219 regulator_disable(data->reg_vbus);
220
221 if (data->phy) {
222 usb_phy_shutdown(data->phy); 180 usb_phy_shutdown(data->phy);
223 module_put(data->phy->dev->driver->owner);
224 }
225 181
226 clk_disable_unprepare(data->clk); 182 clk_disable_unprepare(data->clk);
227 183
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.h b/drivers/usb/chipidea/ci_hdrc_imx.h
index 550bfa457620..c7271590dd0a 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.h
+++ b/drivers/usb/chipidea/ci_hdrc_imx.h
@@ -9,23 +9,12 @@
9 * http://www.gnu.org/copyleft/gpl.html 9 * http://www.gnu.org/copyleft/gpl.html
10 */ 10 */
11 11
12/* Used to set SoC specific callbacks */ 12struct imx_usbmisc_data {
13struct usbmisc_ops {
14 /* It's called once when probe a usb device */
15 int (*init)(struct device *dev);
16 /* It's called once after adding a usb device */
17 int (*post)(struct device *dev);
18};
19
20struct usbmisc_usb_device {
21 struct device *dev; /* usb controller device */
22 int index; 13 int index;
23 14
24 unsigned int disable_oc:1; /* over current detect disabled */ 15 unsigned int disable_oc:1; /* over current detect disabled */
25 unsigned int evdo:1; /* set external vbus divider option */ 16 unsigned int evdo:1; /* set external vbus divider option */
26}; 17};
27 18
28int usbmisc_set_ops(const struct usbmisc_ops *ops); 19int imx_usbmisc_init(struct imx_usbmisc_data *);
29void usbmisc_unset_ops(const struct usbmisc_ops *ops); 20int imx_usbmisc_init_post(struct imx_usbmisc_data *);
30int
31usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device *usbdev);
diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c
index fb657ef50a9c..2d51d852b474 100644
--- a/drivers/usb/chipidea/ci_hdrc_msm.c
+++ b/drivers/usb/chipidea/ci_hdrc_msm.c
@@ -49,7 +49,6 @@ static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = {
49 .name = "ci_hdrc_msm", 49 .name = "ci_hdrc_msm",
50 .flags = CI_HDRC_REGS_SHARED | 50 .flags = CI_HDRC_REGS_SHARED |
51 CI_HDRC_REQUIRE_TRANSCEIVER | 51 CI_HDRC_REQUIRE_TRANSCEIVER |
52 CI_HDRC_PULLUP_ON_VBUS |
53 CI_HDRC_DISABLE_STREAMING, 52 CI_HDRC_DISABLE_STREAMING,
54 53
55 .notify_event = ci_hdrc_msm_notify_event, 54 .notify_event = ci_hdrc_msm_notify_event,
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index a5df24c578fc..94626409559a 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -65,12 +65,14 @@
65#include <linux/usb/chipidea.h> 65#include <linux/usb/chipidea.h>
66#include <linux/usb/of.h> 66#include <linux/usb/of.h>
67#include <linux/phy.h> 67#include <linux/phy.h>
68#include <linux/regulator/consumer.h>
68 69
69#include "ci.h" 70#include "ci.h"
70#include "udc.h" 71#include "udc.h"
71#include "bits.h" 72#include "bits.h"
72#include "host.h" 73#include "host.h"
73#include "debug.h" 74#include "debug.h"
75#include "otg.h"
74 76
75/* Controller register map */ 77/* Controller register map */
76static uintptr_t ci_regs_nolpm[] = { 78static uintptr_t ci_regs_nolpm[] = {
@@ -197,6 +199,12 @@ static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
197 if (ci->hw_ep_max > ENDPT_MAX) 199 if (ci->hw_ep_max > ENDPT_MAX)
198 return -ENODEV; 200 return -ENODEV;
199 201
202 /* Disable all interrupts bits */
203 hw_write(ci, OP_USBINTR, 0xffffffff, 0);
204
205 /* Clear all interrupts status bits*/
206 hw_write(ci, OP_USBSTS, 0xffffffff, 0xffffffff);
207
200 dev_dbg(ci->dev, "ChipIdea HDRC found, lpm: %d; cap: %p op: %p\n", 208 dev_dbg(ci->dev, "ChipIdea HDRC found, lpm: %d; cap: %p op: %p\n",
201 ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op); 209 ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op);
202 210
@@ -264,8 +272,6 @@ int hw_device_reset(struct ci_hdrc *ci, u32 mode)
264 while (hw_read(ci, OP_USBCMD, USBCMD_RST)) 272 while (hw_read(ci, OP_USBCMD, USBCMD_RST))
265 udelay(10); /* not RTOS friendly */ 273 udelay(10); /* not RTOS friendly */
266 274
267 hw_phymode_configure(ci);
268
269 if (ci->platdata->notify_event) 275 if (ci->platdata->notify_event)
270 ci->platdata->notify_event(ci, 276 ci->platdata->notify_event(ci,
271 CI_HDRC_CONTROLLER_RESET_EVENT); 277 CI_HDRC_CONTROLLER_RESET_EVENT);
@@ -289,37 +295,35 @@ int hw_device_reset(struct ci_hdrc *ci, u32 mode)
289} 295}
290 296
291/** 297/**
292 * ci_otg_role - pick role based on ID pin state 298 * hw_wait_reg: wait the register value
299 *
300 * Sometimes, it needs to wait register value before going on.
301 * Eg, when switch to device mode, the vbus value should be lower
302 * than OTGSC_BSV before connects to host.
303 *
293 * @ci: the controller 304 * @ci: the controller
305 * @reg: register index
306 * @mask: mast bit
307 * @value: the bit value to wait
308 * @timeout_ms: timeout in millisecond
309 *
310 * This function returns an error code if timeout
294 */ 311 */
295static enum ci_role ci_otg_role(struct ci_hdrc *ci) 312int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask,
296{ 313 u32 value, unsigned int timeout_ms)
297 u32 sts = hw_read(ci, OP_OTGSC, ~0);
298 enum ci_role role = sts & OTGSC_ID
299 ? CI_ROLE_GADGET
300 : CI_ROLE_HOST;
301
302 return role;
303}
304
305/**
306 * ci_role_work - perform role changing based on ID pin
307 * @work: work struct
308 */
309static void ci_role_work(struct work_struct *work)
310{ 314{
311 struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work); 315 unsigned long elapse = jiffies + msecs_to_jiffies(timeout_ms);
312 enum ci_role role = ci_otg_role(ci); 316
313 317 while (hw_read(ci, reg, mask) != value) {
314 if (role != ci->role) { 318 if (time_after(jiffies, elapse)) {
315 dev_dbg(ci->dev, "switching from %s to %s\n", 319 dev_err(ci->dev, "timeout waiting for %08x in %d\n",
316 ci_role(ci)->name, ci->roles[role]->name); 320 mask, reg);
317 321 return -ETIMEDOUT;
318 ci_role_stop(ci); 322 }
319 ci_role_start(ci, role); 323 msleep(20);
320 } 324 }
321 325
322 enable_irq(ci->irq); 326 return 0;
323} 327}
324 328
325static irqreturn_t ci_irq(int irq, void *data) 329static irqreturn_t ci_irq(int irq, void *data)
@@ -331,19 +335,55 @@ static irqreturn_t ci_irq(int irq, void *data)
331 if (ci->is_otg) 335 if (ci->is_otg)
332 otgsc = hw_read(ci, OP_OTGSC, ~0); 336 otgsc = hw_read(ci, OP_OTGSC, ~0);
333 337
334 if (ci->role != CI_ROLE_END) 338 /*
335 ret = ci_role(ci)->irq(ci); 339 * Handle id change interrupt, it indicates device/host function
340 * switch.
341 */
342 if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) {
343 ci->id_event = true;
344 ci_clear_otg_interrupt(ci, OTGSC_IDIS);
345 disable_irq_nosync(ci->irq);
346 queue_work(ci->wq, &ci->work);
347 return IRQ_HANDLED;
348 }
336 349
337 if (ci->is_otg && (otgsc & OTGSC_IDIS)) { 350 /*
338 hw_write(ci, OP_OTGSC, OTGSC_IDIS, OTGSC_IDIS); 351 * Handle vbus change interrupt, it indicates device connection
352 * and disconnection events.
353 */
354 if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) {
355 ci->b_sess_valid_event = true;
356 ci_clear_otg_interrupt(ci, OTGSC_BSVIS);
339 disable_irq_nosync(ci->irq); 357 disable_irq_nosync(ci->irq);
340 queue_work(ci->wq, &ci->work); 358 queue_work(ci->wq, &ci->work);
341 ret = IRQ_HANDLED; 359 return IRQ_HANDLED;
342 } 360 }
343 361
362 /* Handle device/host interrupt */
363 if (ci->role != CI_ROLE_END)
364 ret = ci_role(ci)->irq(ci);
365
344 return ret; 366 return ret;
345} 367}
346 368
369static int ci_get_platdata(struct device *dev,
370 struct ci_hdrc_platform_data *platdata)
371{
372 /* Get the vbus regulator */
373 platdata->reg_vbus = devm_regulator_get(dev, "vbus");
374 if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
375 return -EPROBE_DEFER;
376 } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
377 platdata->reg_vbus = NULL; /* no vbus regualator is needed */
378 } else if (IS_ERR(platdata->reg_vbus)) {
379 dev_err(dev, "Getting regulator error: %ld\n",
380 PTR_ERR(platdata->reg_vbus));
381 return PTR_ERR(platdata->reg_vbus);
382 }
383
384 return 0;
385}
386
347static DEFINE_IDA(ci_ida); 387static DEFINE_IDA(ci_ida);
348 388
349struct platform_device *ci_hdrc_add_device(struct device *dev, 389struct platform_device *ci_hdrc_add_device(struct device *dev,
@@ -353,6 +393,10 @@ struct platform_device *ci_hdrc_add_device(struct device *dev,
353 struct platform_device *pdev; 393 struct platform_device *pdev;
354 int id, ret; 394 int id, ret;
355 395
396 ret = ci_get_platdata(dev, platdata);
397 if (ret)
398 return ERR_PTR(ret);
399
356 id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL); 400 id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
357 if (id < 0) 401 if (id < 0)
358 return ERR_PTR(id); 402 return ERR_PTR(id);
@@ -398,6 +442,29 @@ void ci_hdrc_remove_device(struct platform_device *pdev)
398} 442}
399EXPORT_SYMBOL_GPL(ci_hdrc_remove_device); 443EXPORT_SYMBOL_GPL(ci_hdrc_remove_device);
400 444
445static inline void ci_role_destroy(struct ci_hdrc *ci)
446{
447 ci_hdrc_gadget_destroy(ci);
448 ci_hdrc_host_destroy(ci);
449 if (ci->is_otg)
450 ci_hdrc_otg_destroy(ci);
451}
452
453static void ci_get_otg_capable(struct ci_hdrc *ci)
454{
455 if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG)
456 ci->is_otg = false;
457 else
458 ci->is_otg = (hw_read(ci, CAP_DCCPARAMS,
459 DCCPARAMS_DC | DCCPARAMS_HC)
460 == (DCCPARAMS_DC | DCCPARAMS_HC));
461 if (ci->is_otg) {
462 dev_dbg(ci->dev, "It is OTG capable controller\n");
463 ci_disable_otg_interrupt(ci, OTGSC_INT_EN_BITS);
464 ci_clear_otg_interrupt(ci, OTGSC_INT_STATUS_BITS);
465 }
466}
467
401static int ci_hdrc_probe(struct platform_device *pdev) 468static int ci_hdrc_probe(struct platform_device *pdev)
402{ 469{
403 struct device *dev = &pdev->dev; 470 struct device *dev = &pdev->dev;
@@ -406,15 +473,13 @@ static int ci_hdrc_probe(struct platform_device *pdev)
406 void __iomem *base; 473 void __iomem *base;
407 int ret; 474 int ret;
408 enum usb_dr_mode dr_mode; 475 enum usb_dr_mode dr_mode;
476 struct device_node *of_node = dev->of_node ?: dev->parent->of_node;
409 477
410 if (!dev->platform_data) { 478 if (!dev->platform_data) {
411 dev_err(dev, "platform data missing\n"); 479 dev_err(dev, "platform data missing\n");
412 return -ENODEV; 480 return -ENODEV;
413 } 481 }
414 482
415 if (!dev->of_node && dev->parent)
416 dev->of_node = dev->parent->of_node;
417
418 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 483 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
419 base = devm_ioremap_resource(dev, res); 484 base = devm_ioremap_resource(dev, res);
420 if (IS_ERR(base)) 485 if (IS_ERR(base))
@@ -447,18 +512,15 @@ static int ci_hdrc_probe(struct platform_device *pdev)
447 return -ENODEV; 512 return -ENODEV;
448 } 513 }
449 514
450 INIT_WORK(&ci->work, ci_role_work); 515 ci_get_otg_capable(ci);
451 ci->wq = create_singlethread_workqueue("ci_otg");
452 if (!ci->wq) {
453 dev_err(dev, "can't create workqueue\n");
454 return -ENODEV;
455 }
456 516
457 if (!ci->platdata->phy_mode) 517 if (!ci->platdata->phy_mode)
458 ci->platdata->phy_mode = of_usb_get_phy_mode(dev->of_node); 518 ci->platdata->phy_mode = of_usb_get_phy_mode(of_node);
519
520 hw_phymode_configure(ci);
459 521
460 if (!ci->platdata->dr_mode) 522 if (!ci->platdata->dr_mode)
461 ci->platdata->dr_mode = of_usb_get_dr_mode(dev->of_node); 523 ci->platdata->dr_mode = of_usb_get_dr_mode(of_node);
462 524
463 if (ci->platdata->dr_mode == USB_DR_MODE_UNKNOWN) 525 if (ci->platdata->dr_mode == USB_DR_MODE_UNKNOWN)
464 ci->platdata->dr_mode = USB_DR_MODE_OTG; 526 ci->platdata->dr_mode = USB_DR_MODE_OTG;
@@ -479,15 +541,34 @@ static int ci_hdrc_probe(struct platform_device *pdev)
479 541
480 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { 542 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
481 dev_err(dev, "no supported roles\n"); 543 dev_err(dev, "no supported roles\n");
482 ret = -ENODEV; 544 return -ENODEV;
483 goto rm_wq; 545 }
546
547 if (ci->is_otg) {
548 ret = ci_hdrc_otg_init(ci);
549 if (ret) {
550 dev_err(dev, "init otg fails, ret = %d\n", ret);
551 goto stop;
552 }
484 } 553 }
485 554
486 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { 555 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {
487 ci->is_otg = true; 556 if (ci->is_otg) {
488 /* ID pin needs 1ms debouce time, we delay 2ms for safe */ 557 /*
489 mdelay(2); 558 * ID pin needs 1ms debouce time,
490 ci->role = ci_otg_role(ci); 559 * we delay 2ms for safe.
560 */
561 mdelay(2);
562 ci->role = ci_otg_role(ci);
563 ci_enable_otg_interrupt(ci, OTGSC_IDIE);
564 } else {
565 /*
566 * If the controller is not OTG capable, but support
567 * role switch, the defalt role is gadget, and the
568 * user can switch it through debugfs.
569 */
570 ci->role = CI_ROLE_GADGET;
571 }
491 } else { 572 } else {
492 ci->role = ci->roles[CI_ROLE_HOST] 573 ci->role = ci->roles[CI_ROLE_HOST]
493 ? CI_ROLE_HOST 574 ? CI_ROLE_HOST
@@ -497,8 +578,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
497 ret = ci_role_start(ci, ci->role); 578 ret = ci_role_start(ci, ci->role);
498 if (ret) { 579 if (ret) {
499 dev_err(dev, "can't start %s role\n", ci_role(ci)->name); 580 dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
500 ret = -ENODEV; 581 goto stop;
501 goto rm_wq;
502 } 582 }
503 583
504 platform_set_drvdata(pdev, ci); 584 platform_set_drvdata(pdev, ci);
@@ -507,19 +587,13 @@ static int ci_hdrc_probe(struct platform_device *pdev)
507 if (ret) 587 if (ret)
508 goto stop; 588 goto stop;
509 589
510 if (ci->is_otg)
511 hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE);
512
513 ret = dbg_create_files(ci); 590 ret = dbg_create_files(ci);
514 if (!ret) 591 if (!ret)
515 return 0; 592 return 0;
516 593
517 free_irq(ci->irq, ci); 594 free_irq(ci->irq, ci);
518stop: 595stop:
519 ci_role_stop(ci); 596 ci_role_destroy(ci);
520rm_wq:
521 flush_workqueue(ci->wq);
522 destroy_workqueue(ci->wq);
523 597
524 return ret; 598 return ret;
525} 599}
@@ -529,10 +603,8 @@ static int ci_hdrc_remove(struct platform_device *pdev)
529 struct ci_hdrc *ci = platform_get_drvdata(pdev); 603 struct ci_hdrc *ci = platform_get_drvdata(pdev);
530 604
531 dbg_remove_files(ci); 605 dbg_remove_files(ci);
532 flush_workqueue(ci->wq);
533 destroy_workqueue(ci->wq);
534 free_irq(ci->irq, ci); 606 free_irq(ci->irq, ci);
535 ci_role_stop(ci); 607 ci_role_destroy(ci);
536 608
537 return 0; 609 return 0;
538} 610}
@@ -548,7 +620,6 @@ static struct platform_driver ci_hdrc_driver = {
548module_platform_driver(ci_hdrc_driver); 620module_platform_driver(ci_hdrc_driver);
549 621
550MODULE_ALIAS("platform:ci_hdrc"); 622MODULE_ALIAS("platform:ci_hdrc");
551MODULE_ALIAS("platform:ci13xxx");
552MODULE_LICENSE("GPL v2"); 623MODULE_LICENSE("GPL v2");
553MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>"); 624MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>");
554MODULE_DESCRIPTION("ChipIdea HDRC Driver"); 625MODULE_DESCRIPTION("ChipIdea HDRC Driver");
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 40d0fda4f66c..6f96795dd20c 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -24,6 +24,7 @@
24#include <linux/usb.h> 24#include <linux/usb.h>
25#include <linux/usb/hcd.h> 25#include <linux/usb/hcd.h>
26#include <linux/usb/chipidea.h> 26#include <linux/usb/chipidea.h>
27#include <linux/regulator/consumer.h>
27 28
28#include "../host/ehci.h" 29#include "../host/ehci.h"
29 30
@@ -63,10 +64,21 @@ static int host_start(struct ci_hdrc *ci)
63 ehci = hcd_to_ehci(hcd); 64 ehci = hcd_to_ehci(hcd);
64 ehci->caps = ci->hw_bank.cap; 65 ehci->caps = ci->hw_bank.cap;
65 ehci->has_hostpc = ci->hw_bank.lpm; 66 ehci->has_hostpc = ci->hw_bank.lpm;
67 ehci->has_tdi_phy_lpm = ci->hw_bank.lpm;
68
69 if (ci->platdata->reg_vbus) {
70 ret = regulator_enable(ci->platdata->reg_vbus);
71 if (ret) {
72 dev_err(ci->dev,
73 "Failed to enable vbus regulator, ret=%d\n",
74 ret);
75 goto put_hcd;
76 }
77 }
66 78
67 ret = usb_add_hcd(hcd, 0, 0); 79 ret = usb_add_hcd(hcd, 0, 0);
68 if (ret) 80 if (ret)
69 usb_put_hcd(hcd); 81 goto disable_reg;
70 else 82 else
71 ci->hcd = hcd; 83 ci->hcd = hcd;
72 84
@@ -74,6 +86,14 @@ static int host_start(struct ci_hdrc *ci)
74 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS); 86 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
75 87
76 return ret; 88 return ret;
89
90disable_reg:
91 regulator_disable(ci->platdata->reg_vbus);
92
93put_hcd:
94 usb_put_hcd(hcd);
95
96 return ret;
77} 97}
78 98
79static void host_stop(struct ci_hdrc *ci) 99static void host_stop(struct ci_hdrc *ci)
@@ -82,6 +102,15 @@ static void host_stop(struct ci_hdrc *ci)
82 102
83 usb_remove_hcd(hcd); 103 usb_remove_hcd(hcd);
84 usb_put_hcd(hcd); 104 usb_put_hcd(hcd);
105 if (ci->platdata->reg_vbus)
106 regulator_disable(ci->platdata->reg_vbus);
107}
108
109
110void ci_hdrc_host_destroy(struct ci_hdrc *ci)
111{
112 if (ci->role == CI_ROLE_HOST)
113 host_stop(ci);
85} 114}
86 115
87int ci_hdrc_host_init(struct ci_hdrc *ci) 116int ci_hdrc_host_init(struct ci_hdrc *ci)
diff --git a/drivers/usb/chipidea/host.h b/drivers/usb/chipidea/host.h
index 058875c15333..5707bf379bfb 100644
--- a/drivers/usb/chipidea/host.h
+++ b/drivers/usb/chipidea/host.h
@@ -4,6 +4,7 @@
4#ifdef CONFIG_USB_CHIPIDEA_HOST 4#ifdef CONFIG_USB_CHIPIDEA_HOST
5 5
6int ci_hdrc_host_init(struct ci_hdrc *ci); 6int ci_hdrc_host_init(struct ci_hdrc *ci);
7void ci_hdrc_host_destroy(struct ci_hdrc *ci);
7 8
8#else 9#else
9 10
@@ -12,6 +13,11 @@ static inline int ci_hdrc_host_init(struct ci_hdrc *ci)
12 return -ENXIO; 13 return -ENXIO;
13} 14}
14 15
16static inline void ci_hdrc_host_destroy(struct ci_hdrc *ci)
17{
18
19}
20
15#endif 21#endif
16 22
17#endif /* __DRIVERS_USB_CHIPIDEA_HOST_H */ 23#endif /* __DRIVERS_USB_CHIPIDEA_HOST_H */
diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
new file mode 100644
index 000000000000..39bd7ec8bf75
--- /dev/null
+++ b/drivers/usb/chipidea/otg.c
@@ -0,0 +1,120 @@
1/*
2 * otg.c - ChipIdea USB IP core OTG driver
3 *
4 * Copyright (C) 2013 Freescale Semiconductor, Inc.
5 *
6 * Author: Peter Chen
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/*
14 * This file mainly handles otgsc register, it may include OTG operation
15 * in the future.
16 */
17
18#include <linux/usb/otg.h>
19#include <linux/usb/gadget.h>
20#include <linux/usb/chipidea.h>
21
22#include "ci.h"
23#include "bits.h"
24#include "otg.h"
25
26/**
27 * ci_otg_role - pick role based on ID pin state
28 * @ci: the controller
29 */
30enum ci_role ci_otg_role(struct ci_hdrc *ci)
31{
32 u32 sts = hw_read(ci, OP_OTGSC, ~0);
33 enum ci_role role = sts & OTGSC_ID
34 ? CI_ROLE_GADGET
35 : CI_ROLE_HOST;
36
37 return role;
38}
39
40void ci_handle_vbus_change(struct ci_hdrc *ci)
41{
42 u32 otgsc;
43
44 if (!ci->is_otg)
45 return;
46
47 otgsc = hw_read(ci, OP_OTGSC, ~0);
48
49 if (otgsc & OTGSC_BSV)
50 usb_gadget_vbus_connect(&ci->gadget);
51 else
52 usb_gadget_vbus_disconnect(&ci->gadget);
53}
54
55#define CI_VBUS_STABLE_TIMEOUT_MS 5000
56static void ci_handle_id_switch(struct ci_hdrc *ci)
57{
58 enum ci_role role = ci_otg_role(ci);
59
60 if (role != ci->role) {
61 dev_dbg(ci->dev, "switching from %s to %s\n",
62 ci_role(ci)->name, ci->roles[role]->name);
63
64 ci_role_stop(ci);
65 /* wait vbus lower than OTGSC_BSV */
66 hw_wait_reg(ci, OP_OTGSC, OTGSC_BSV, 0,
67 CI_VBUS_STABLE_TIMEOUT_MS);
68 ci_role_start(ci, role);
69 }
70}
71/**
72 * ci_otg_work - perform otg (vbus/id) event handle
73 * @work: work struct
74 */
75static void ci_otg_work(struct work_struct *work)
76{
77 struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work);
78
79 if (ci->id_event) {
80 ci->id_event = false;
81 ci_handle_id_switch(ci);
82 } else if (ci->b_sess_valid_event) {
83 ci->b_sess_valid_event = false;
84 ci_handle_vbus_change(ci);
85 } else
86 dev_err(ci->dev, "unexpected event occurs at %s\n", __func__);
87
88 enable_irq(ci->irq);
89}
90
91
92/**
93 * ci_hdrc_otg_init - initialize otg struct
94 * ci: the controller
95 */
96int ci_hdrc_otg_init(struct ci_hdrc *ci)
97{
98 INIT_WORK(&ci->work, ci_otg_work);
99 ci->wq = create_singlethread_workqueue("ci_otg");
100 if (!ci->wq) {
101 dev_err(ci->dev, "can't create workqueue\n");
102 return -ENODEV;
103 }
104
105 return 0;
106}
107
108/**
109 * ci_hdrc_otg_destroy - destroy otg struct
110 * ci: the controller
111 */
112void ci_hdrc_otg_destroy(struct ci_hdrc *ci)
113{
114 if (ci->wq) {
115 flush_workqueue(ci->wq);
116 destroy_workqueue(ci->wq);
117 }
118 ci_disable_otg_interrupt(ci, OTGSC_INT_EN_BITS);
119 ci_clear_otg_interrupt(ci, OTGSC_INT_STATUS_BITS);
120}
diff --git a/drivers/usb/chipidea/otg.h b/drivers/usb/chipidea/otg.h
new file mode 100644
index 000000000000..2d9f090733bc
--- /dev/null
+++ b/drivers/usb/chipidea/otg.h
@@ -0,0 +1,35 @@
1/*
2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
3 *
4 * Author: Peter Chen
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef __DRIVERS_USB_CHIPIDEA_OTG_H
12#define __DRIVERS_USB_CHIPIDEA_OTG_H
13
14static inline void ci_clear_otg_interrupt(struct ci_hdrc *ci, u32 bits)
15{
16 /* Only clear request bits */
17 hw_write(ci, OP_OTGSC, OTGSC_INT_STATUS_BITS, bits);
18}
19
20static inline void ci_enable_otg_interrupt(struct ci_hdrc *ci, u32 bits)
21{
22 hw_write(ci, OP_OTGSC, bits, bits);
23}
24
25static inline void ci_disable_otg_interrupt(struct ci_hdrc *ci, u32 bits)
26{
27 hw_write(ci, OP_OTGSC, bits, 0);
28}
29
30int ci_hdrc_otg_init(struct ci_hdrc *ci);
31void ci_hdrc_otg_destroy(struct ci_hdrc *ci);
32enum ci_role ci_otg_role(struct ci_hdrc *ci);
33void ci_handle_vbus_change(struct ci_hdrc *ci);
34
35#endif /* __DRIVERS_USB_CHIPIDEA_OTG_H */
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index e475fcda1d68..6b4c2f2eb946 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -27,6 +27,7 @@
27#include "udc.h" 27#include "udc.h"
28#include "bits.h" 28#include "bits.h"
29#include "debug.h" 29#include "debug.h"
30#include "otg.h"
30 31
31/* control endpoint description */ 32/* control endpoint description */
32static const struct usb_endpoint_descriptor 33static const struct usb_endpoint_descriptor
@@ -84,8 +85,10 @@ static int hw_device_state(struct ci_hdrc *ci, u32 dma)
84 /* interrupt, error, port change, reset, sleep/suspend */ 85 /* interrupt, error, port change, reset, sleep/suspend */
85 hw_write(ci, OP_USBINTR, ~0, 86 hw_write(ci, OP_USBINTR, ~0,
86 USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); 87 USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI);
88 hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS);
87 } else { 89 } else {
88 hw_write(ci, OP_USBINTR, ~0, 0); 90 hw_write(ci, OP_USBINTR, ~0, 0);
91 hw_write(ci, OP_USBCMD, USBCMD_RS, 0);
89 } 92 }
90 return 0; 93 return 0;
91} 94}
@@ -1445,9 +1448,6 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
1445 unsigned long flags; 1448 unsigned long flags;
1446 int gadget_ready = 0; 1449 int gadget_ready = 0;
1447 1450
1448 if (!(ci->platdata->flags & CI_HDRC_PULLUP_ON_VBUS))
1449 return -EOPNOTSUPP;
1450
1451 spin_lock_irqsave(&ci->lock, flags); 1451 spin_lock_irqsave(&ci->lock, flags);
1452 ci->vbus_active = is_active; 1452 ci->vbus_active = is_active;
1453 if (ci->driver) 1453 if (ci->driver)
@@ -1459,6 +1459,7 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
1459 pm_runtime_get_sync(&_gadget->dev); 1459 pm_runtime_get_sync(&_gadget->dev);
1460 hw_device_reset(ci, USBMODE_CM_DC); 1460 hw_device_reset(ci, USBMODE_CM_DC);
1461 hw_device_state(ci, ci->ep0out->qh.dma); 1461 hw_device_state(ci, ci->ep0out->qh.dma);
1462 dev_dbg(ci->dev, "Connected to host\n");
1462 } else { 1463 } else {
1463 hw_device_state(ci, 0); 1464 hw_device_state(ci, 0);
1464 if (ci->platdata->notify_event) 1465 if (ci->platdata->notify_event)
@@ -1466,6 +1467,7 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
1466 CI_HDRC_CONTROLLER_STOPPED_EVENT); 1467 CI_HDRC_CONTROLLER_STOPPED_EVENT);
1467 _gadget_stop_activity(&ci->gadget); 1468 _gadget_stop_activity(&ci->gadget);
1468 pm_runtime_put_sync(&_gadget->dev); 1469 pm_runtime_put_sync(&_gadget->dev);
1470 dev_dbg(ci->dev, "Disconnected from host\n");
1469 } 1471 }
1470 } 1472 }
1471 1473
@@ -1509,6 +1511,9 @@ static int ci_udc_pullup(struct usb_gadget *_gadget, int is_on)
1509{ 1511{
1510 struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); 1512 struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
1511 1513
1514 if (!ci->vbus_active)
1515 return -EOPNOTSUPP;
1516
1512 if (is_on) 1517 if (is_on)
1513 hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); 1518 hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS);
1514 else 1519 else
@@ -1630,14 +1635,11 @@ static int ci_udc_start(struct usb_gadget *gadget,
1630 1635
1631 ci->driver = driver; 1636 ci->driver = driver;
1632 pm_runtime_get_sync(&ci->gadget.dev); 1637 pm_runtime_get_sync(&ci->gadget.dev);
1633 if (ci->platdata->flags & CI_HDRC_PULLUP_ON_VBUS) { 1638 if (ci->vbus_active) {
1634 if (ci->vbus_active) { 1639 hw_device_reset(ci, USBMODE_CM_DC);
1635 if (ci->platdata->flags & CI_HDRC_REGS_SHARED) 1640 } else {
1636 hw_device_reset(ci, USBMODE_CM_DC); 1641 pm_runtime_put_sync(&ci->gadget.dev);
1637 } else { 1642 goto done;
1638 pm_runtime_put_sync(&ci->gadget.dev);
1639 goto done;
1640 }
1641 } 1643 }
1642 1644
1643 retval = hw_device_state(ci, ci->ep0out->qh.dma); 1645 retval = hw_device_state(ci, ci->ep0out->qh.dma);
@@ -1660,8 +1662,7 @@ static int ci_udc_stop(struct usb_gadget *gadget,
1660 1662
1661 spin_lock_irqsave(&ci->lock, flags); 1663 spin_lock_irqsave(&ci->lock, flags);
1662 1664
1663 if (!(ci->platdata->flags & CI_HDRC_PULLUP_ON_VBUS) || 1665 if (ci->vbus_active) {
1664 ci->vbus_active) {
1665 hw_device_state(ci, 0); 1666 hw_device_state(ci, 0);
1666 if (ci->platdata->notify_event) 1667 if (ci->platdata->notify_event)
1667 ci->platdata->notify_event(ci, 1668 ci->platdata->notify_event(ci,
@@ -1796,16 +1797,15 @@ static int udc_start(struct ci_hdrc *ci)
1796 } 1797 }
1797 } 1798 }
1798 1799
1799 if (!(ci->platdata->flags & CI_HDRC_REGS_SHARED)) {
1800 retval = hw_device_reset(ci, USBMODE_CM_DC);
1801 if (retval)
1802 goto put_transceiver;
1803 }
1804
1805 if (ci->transceiver) { 1800 if (ci->transceiver) {
1806 retval = otg_set_peripheral(ci->transceiver->otg, 1801 retval = otg_set_peripheral(ci->transceiver->otg,
1807 &ci->gadget); 1802 &ci->gadget);
1808 if (retval) 1803 /*
1804 * If we implement all USB functions using chipidea drivers,
1805 * it doesn't need to call above API, meanwhile, if we only
1806 * use gadget function, calling above API is useless.
1807 */
1808 if (retval && retval != -ENOTSUPP)
1809 goto put_transceiver; 1809 goto put_transceiver;
1810 } 1810 }
1811 1811
@@ -1816,6 +1816,9 @@ static int udc_start(struct ci_hdrc *ci)
1816 pm_runtime_no_callbacks(&ci->gadget.dev); 1816 pm_runtime_no_callbacks(&ci->gadget.dev);
1817 pm_runtime_enable(&ci->gadget.dev); 1817 pm_runtime_enable(&ci->gadget.dev);
1818 1818
1819 /* Update ci->vbus_active */
1820 ci_handle_vbus_change(ci);
1821
1819 return retval; 1822 return retval;
1820 1823
1821remove_trans: 1824remove_trans:
@@ -1839,13 +1842,13 @@ free_qh_pool:
1839} 1842}
1840 1843
1841/** 1844/**
1842 * udc_remove: parent remove must call this to remove UDC 1845 * ci_hdrc_gadget_destroy: parent remove must call this to remove UDC
1843 * 1846 *
1844 * No interrupts active, the IRQ has been released 1847 * No interrupts active, the IRQ has been released
1845 */ 1848 */
1846static void udc_stop(struct ci_hdrc *ci) 1849void ci_hdrc_gadget_destroy(struct ci_hdrc *ci)
1847{ 1850{
1848 if (ci == NULL) 1851 if (!ci->roles[CI_ROLE_GADGET])
1849 return; 1852 return;
1850 1853
1851 usb_del_gadget_udc(&ci->gadget); 1854 usb_del_gadget_udc(&ci->gadget);
@@ -1860,15 +1863,32 @@ static void udc_stop(struct ci_hdrc *ci)
1860 if (ci->global_phy) 1863 if (ci->global_phy)
1861 usb_put_phy(ci->transceiver); 1864 usb_put_phy(ci->transceiver);
1862 } 1865 }
1863 /* my kobject is dynamic, I swear! */ 1866}
1864 memset(&ci->gadget, 0, sizeof(ci->gadget)); 1867
1868static int udc_id_switch_for_device(struct ci_hdrc *ci)
1869{
1870 if (ci->is_otg) {
1871 ci_clear_otg_interrupt(ci, OTGSC_BSVIS);
1872 ci_enable_otg_interrupt(ci, OTGSC_BSVIE);
1873 }
1874
1875 return 0;
1876}
1877
1878static void udc_id_switch_for_host(struct ci_hdrc *ci)
1879{
1880 if (ci->is_otg) {
1881 /* host doesn't care B_SESSION_VALID event */
1882 ci_clear_otg_interrupt(ci, OTGSC_BSVIS);
1883 ci_disable_otg_interrupt(ci, OTGSC_BSVIE);
1884 }
1865} 1885}
1866 1886
1867/** 1887/**
1868 * ci_hdrc_gadget_init - initialize device related bits 1888 * ci_hdrc_gadget_init - initialize device related bits
1869 * ci: the controller 1889 * ci: the controller
1870 * 1890 *
1871 * This function enables the gadget role, if the device is "device capable". 1891 * This function initializes the gadget, if the device is "device capable".
1872 */ 1892 */
1873int ci_hdrc_gadget_init(struct ci_hdrc *ci) 1893int ci_hdrc_gadget_init(struct ci_hdrc *ci)
1874{ 1894{
@@ -1881,11 +1901,11 @@ int ci_hdrc_gadget_init(struct ci_hdrc *ci)
1881 if (!rdrv) 1901 if (!rdrv)
1882 return -ENOMEM; 1902 return -ENOMEM;
1883 1903
1884 rdrv->start = udc_start; 1904 rdrv->start = udc_id_switch_for_device;
1885 rdrv->stop = udc_stop; 1905 rdrv->stop = udc_id_switch_for_host;
1886 rdrv->irq = udc_irq; 1906 rdrv->irq = udc_irq;
1887 rdrv->name = "gadget"; 1907 rdrv->name = "gadget";
1888 ci->roles[CI_ROLE_GADGET] = rdrv; 1908 ci->roles[CI_ROLE_GADGET] = rdrv;
1889 1909
1890 return 0; 1910 return udc_start(ci);
1891} 1911}
diff --git a/drivers/usb/chipidea/udc.h b/drivers/usb/chipidea/udc.h
index 455ac2169226..e66df0020bd4 100644
--- a/drivers/usb/chipidea/udc.h
+++ b/drivers/usb/chipidea/udc.h
@@ -84,6 +84,7 @@ struct ci_hw_req {
84#ifdef CONFIG_USB_CHIPIDEA_UDC 84#ifdef CONFIG_USB_CHIPIDEA_UDC
85 85
86int ci_hdrc_gadget_init(struct ci_hdrc *ci); 86int ci_hdrc_gadget_init(struct ci_hdrc *ci);
87void ci_hdrc_gadget_destroy(struct ci_hdrc *ci);
87 88
88#else 89#else
89 90
@@ -92,6 +93,11 @@ static inline int ci_hdrc_gadget_init(struct ci_hdrc *ci)
92 return -ENXIO; 93 return -ENXIO;
93} 94}
94 95
96static inline void ci_hdrc_gadget_destroy(struct ci_hdrc *ci)
97{
98
99}
100
95#endif 101#endif
96 102
97#endif /* __DRIVERS_USB_CHIPIDEA_UDC_H */ 103#endif /* __DRIVERS_USB_CHIPIDEA_UDC_H */
diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
index ac5a46155200..8a1094b1182f 100644
--- a/drivers/usb/chipidea/usbmisc_imx.c
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -18,8 +18,6 @@
18 18
19#include "ci_hdrc_imx.h" 19#include "ci_hdrc_imx.h"
20 20
21#define USB_DEV_MAX 4
22
23#define MX25_USB_PHY_CTRL_OFFSET 0x08 21#define MX25_USB_PHY_CTRL_OFFSET 0x08
24#define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23) 22#define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23)
25 23
@@ -32,51 +30,34 @@
32 30
33#define MX6_BM_OVER_CUR_DIS BIT(7) 31#define MX6_BM_OVER_CUR_DIS BIT(7)
34 32
33struct usbmisc_ops {
34 /* It's called once when probe a usb device */
35 int (*init)(struct imx_usbmisc_data *data);
36 /* It's called once after adding a usb device */
37 int (*post)(struct imx_usbmisc_data *data);
38};
39
35struct imx_usbmisc { 40struct imx_usbmisc {
36 void __iomem *base; 41 void __iomem *base;
37 spinlock_t lock; 42 spinlock_t lock;
38 struct clk *clk; 43 struct clk *clk;
39 struct usbmisc_usb_device usbdev[USB_DEV_MAX];
40 const struct usbmisc_ops *ops; 44 const struct usbmisc_ops *ops;
41}; 45};
42 46
43static struct imx_usbmisc *usbmisc; 47static struct imx_usbmisc *usbmisc;
44 48
45static struct usbmisc_usb_device *get_usbdev(struct device *dev) 49static int usbmisc_imx25_post(struct imx_usbmisc_data *data)
46{
47 int i, ret;
48
49 for (i = 0; i < USB_DEV_MAX; i++) {
50 if (usbmisc->usbdev[i].dev == dev)
51 return &usbmisc->usbdev[i];
52 else if (!usbmisc->usbdev[i].dev)
53 break;
54 }
55
56 if (i >= USB_DEV_MAX)
57 return ERR_PTR(-EBUSY);
58
59 ret = usbmisc_get_init_data(dev, &usbmisc->usbdev[i]);
60 if (ret)
61 return ERR_PTR(ret);
62
63 return &usbmisc->usbdev[i];
64}
65
66static int usbmisc_imx25_post(struct device *dev)
67{ 50{
68 struct usbmisc_usb_device *usbdev;
69 void __iomem *reg; 51 void __iomem *reg;
70 unsigned long flags; 52 unsigned long flags;
71 u32 val; 53 u32 val;
72 54
73 usbdev = get_usbdev(dev); 55 if (data->index > 2)
74 if (IS_ERR(usbdev)) 56 return -EINVAL;
75 return PTR_ERR(usbdev);
76 57
77 reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET; 58 reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET;
78 59
79 if (usbdev->evdo) { 60 if (data->evdo) {
80 spin_lock_irqsave(&usbmisc->lock, flags); 61 spin_lock_irqsave(&usbmisc->lock, flags);
81 val = readl(reg); 62 val = readl(reg);
82 writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg); 63 writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg);
@@ -87,20 +68,18 @@ static int usbmisc_imx25_post(struct device *dev)
87 return 0; 68 return 0;
88} 69}
89 70
90static int usbmisc_imx53_init(struct device *dev) 71static int usbmisc_imx53_init(struct imx_usbmisc_data *data)
91{ 72{
92 struct usbmisc_usb_device *usbdev;
93 void __iomem *reg = NULL; 73 void __iomem *reg = NULL;
94 unsigned long flags; 74 unsigned long flags;
95 u32 val = 0; 75 u32 val = 0;
96 76
97 usbdev = get_usbdev(dev); 77 if (data->index > 3)
98 if (IS_ERR(usbdev)) 78 return -EINVAL;
99 return PTR_ERR(usbdev);
100 79
101 if (usbdev->disable_oc) { 80 if (data->disable_oc) {
102 spin_lock_irqsave(&usbmisc->lock, flags); 81 spin_lock_irqsave(&usbmisc->lock, flags);
103 switch (usbdev->index) { 82 switch (data->index) {
104 case 0: 83 case 0:
105 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET; 84 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET;
106 val = readl(reg) | MX53_BM_OVER_CUR_DIS_OTG; 85 val = readl(reg) | MX53_BM_OVER_CUR_DIS_OTG;
@@ -126,22 +105,19 @@ static int usbmisc_imx53_init(struct device *dev)
126 return 0; 105 return 0;
127} 106}
128 107
129static int usbmisc_imx6q_init(struct device *dev) 108static int usbmisc_imx6q_init(struct imx_usbmisc_data *data)
130{ 109{
131
132 struct usbmisc_usb_device *usbdev;
133 unsigned long flags; 110 unsigned long flags;
134 u32 reg; 111 u32 reg;
135 112
136 usbdev = get_usbdev(dev); 113 if (data->index > 3)
137 if (IS_ERR(usbdev)) 114 return -EINVAL;
138 return PTR_ERR(usbdev);
139 115
140 if (usbdev->disable_oc) { 116 if (data->disable_oc) {
141 spin_lock_irqsave(&usbmisc->lock, flags); 117 spin_lock_irqsave(&usbmisc->lock, flags);
142 reg = readl(usbmisc->base + usbdev->index * 4); 118 reg = readl(usbmisc->base + data->index * 4);
143 writel(reg | MX6_BM_OVER_CUR_DIS, 119 writel(reg | MX6_BM_OVER_CUR_DIS,
144 usbmisc->base + usbdev->index * 4); 120 usbmisc->base + data->index * 4);
145 spin_unlock_irqrestore(&usbmisc->lock, flags); 121 spin_unlock_irqrestore(&usbmisc->lock, flags);
146 } 122 }
147 123
@@ -160,6 +136,26 @@ static const struct usbmisc_ops imx6q_usbmisc_ops = {
160 .init = usbmisc_imx6q_init, 136 .init = usbmisc_imx6q_init,
161}; 137};
162 138
139int imx_usbmisc_init(struct imx_usbmisc_data *data)
140{
141 if (!usbmisc)
142 return -EPROBE_DEFER;
143 if (!usbmisc->ops->init)
144 return 0;
145 return usbmisc->ops->init(data);
146}
147EXPORT_SYMBOL_GPL(imx_usbmisc_init);
148
149int imx_usbmisc_init_post(struct imx_usbmisc_data *data)
150{
151 if (!usbmisc)
152 return -EPROBE_DEFER;
153 if (!usbmisc->ops->post)
154 return 0;
155 return usbmisc->ops->post(data);
156}
157EXPORT_SYMBOL_GPL(imx_usbmisc_init_post);
158
163static const struct of_device_id usbmisc_imx_dt_ids[] = { 159static const struct of_device_id usbmisc_imx_dt_ids[] = {
164 { 160 {
165 .compatible = "fsl,imx25-usbmisc", 161 .compatible = "fsl,imx25-usbmisc",
@@ -216,19 +212,12 @@ static int usbmisc_imx_probe(struct platform_device *pdev)
216 of_match_device(usbmisc_imx_dt_ids, &pdev->dev); 212 of_match_device(usbmisc_imx_dt_ids, &pdev->dev);
217 data->ops = (const struct usbmisc_ops *)tmp_dev->data; 213 data->ops = (const struct usbmisc_ops *)tmp_dev->data;
218 usbmisc = data; 214 usbmisc = data;
219 ret = usbmisc_set_ops(data->ops);
220 if (ret) {
221 usbmisc = NULL;
222 clk_disable_unprepare(data->clk);
223 return ret;
224 }
225 215
226 return 0; 216 return 0;
227} 217}
228 218
229static int usbmisc_imx_remove(struct platform_device *pdev) 219static int usbmisc_imx_remove(struct platform_device *pdev)
230{ 220{
231 usbmisc_unset_ops(usbmisc->ops);
232 clk_disable_unprepare(usbmisc->clk); 221 clk_disable_unprepare(usbmisc->clk);
233 usbmisc = NULL; 222 usbmisc = NULL;
234 return 0; 223 return 0;
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 9f49bfe4c6f4..3e7560f004f8 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1295,7 +1295,7 @@ skip_countries:
1295 usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), 1295 usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),
1296 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, 1296 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm,
1297 /* works around buggy devices */ 1297 /* works around buggy devices */
1298 epctrl->bInterval ? epctrl->bInterval : 0xff); 1298 epctrl->bInterval ? epctrl->bInterval : 16);
1299 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1299 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1300 acm->ctrlurb->transfer_dma = acm->ctrl_dma; 1300 acm->ctrlurb->transfer_dma = acm->ctrl_dma;
1301 1301
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 8a230f0ef77c..d3318a0df8ee 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -209,6 +209,7 @@ skip_error:
209static void wdm_int_callback(struct urb *urb) 209static void wdm_int_callback(struct urb *urb)
210{ 210{
211 int rv = 0; 211 int rv = 0;
212 int responding;
212 int status = urb->status; 213 int status = urb->status;
213 struct wdm_device *desc; 214 struct wdm_device *desc;
214 struct usb_cdc_notification *dr; 215 struct usb_cdc_notification *dr;
@@ -262,8 +263,8 @@ static void wdm_int_callback(struct urb *urb)
262 263
263 spin_lock(&desc->iuspin); 264 spin_lock(&desc->iuspin);
264 clear_bit(WDM_READ, &desc->flags); 265 clear_bit(WDM_READ, &desc->flags);
265 set_bit(WDM_RESPONDING, &desc->flags); 266 responding = test_and_set_bit(WDM_RESPONDING, &desc->flags);
266 if (!test_bit(WDM_DISCONNECTING, &desc->flags) 267 if (!responding && !test_bit(WDM_DISCONNECTING, &desc->flags)
267 && !test_bit(WDM_SUSPENDING, &desc->flags)) { 268 && !test_bit(WDM_SUSPENDING, &desc->flags)) {
268 rv = usb_submit_urb(desc->response, GFP_ATOMIC); 269 rv = usb_submit_urb(desc->response, GFP_ATOMIC);
269 dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", 270 dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d",
@@ -685,16 +686,20 @@ static void wdm_rxwork(struct work_struct *work)
685{ 686{
686 struct wdm_device *desc = container_of(work, struct wdm_device, rxwork); 687 struct wdm_device *desc = container_of(work, struct wdm_device, rxwork);
687 unsigned long flags; 688 unsigned long flags;
688 int rv; 689 int rv = 0;
690 int responding;
689 691
690 spin_lock_irqsave(&desc->iuspin, flags); 692 spin_lock_irqsave(&desc->iuspin, flags);
691 if (test_bit(WDM_DISCONNECTING, &desc->flags)) { 693 if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
692 spin_unlock_irqrestore(&desc->iuspin, flags); 694 spin_unlock_irqrestore(&desc->iuspin, flags);
693 } else { 695 } else {
696 responding = test_and_set_bit(WDM_RESPONDING, &desc->flags);
694 spin_unlock_irqrestore(&desc->iuspin, flags); 697 spin_unlock_irqrestore(&desc->iuspin, flags);
695 rv = usb_submit_urb(desc->response, GFP_KERNEL); 698 if (!responding)
699 rv = usb_submit_urb(desc->response, GFP_KERNEL);
696 if (rv < 0 && rv != -EPERM) { 700 if (rv < 0 && rv != -EPERM) {
697 spin_lock_irqsave(&desc->iuspin, flags); 701 spin_lock_irqsave(&desc->iuspin, flags);
702 clear_bit(WDM_RESPONDING, &desc->flags);
698 if (!test_bit(WDM_DISCONNECTING, &desc->flags)) 703 if (!test_bit(WDM_DISCONNECTING, &desc->flags))
699 schedule_work(&desc->rxwork); 704 schedule_work(&desc->rxwork);
700 spin_unlock_irqrestore(&desc->iuspin, flags); 705 spin_unlock_irqrestore(&desc->iuspin, flags);
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 83b4ef4dfcf8..66c4001306f0 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -19,6 +19,8 @@
19 * http://www.gnu.org/copyleft/gpl.html. 19 * http://www.gnu.org/copyleft/gpl.html.
20 */ 20 */
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
22#include <linux/init.h> 24#include <linux/init.h>
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/kernel.h> 26#include <linux/kernel.h>
@@ -119,7 +121,6 @@ static void usbtmc_delete(struct kref *kref)
119 struct usbtmc_device_data *data = to_usbtmc_data(kref); 121 struct usbtmc_device_data *data = to_usbtmc_data(kref);
120 122
121 usb_put_dev(data->usb_dev); 123 usb_put_dev(data->usb_dev);
122 kfree(data);
123} 124}
124 125
125static int usbtmc_open(struct inode *inode, struct file *filp) 126static int usbtmc_open(struct inode *inode, struct file *filp)
@@ -130,10 +131,8 @@ static int usbtmc_open(struct inode *inode, struct file *filp)
130 131
131 intf = usb_find_interface(&usbtmc_driver, iminor(inode)); 132 intf = usb_find_interface(&usbtmc_driver, iminor(inode));
132 if (!intf) { 133 if (!intf) {
133 printk(KERN_ERR KBUILD_MODNAME 134 pr_err("can not find device for minor %d", iminor(inode));
134 ": can not find device for minor %d", iminor(inode)); 135 return -ENODEV;
135 retval = -ENODEV;
136 goto exit;
137 } 136 }
138 137
139 data = usb_get_intfdata(intf); 138 data = usb_get_intfdata(intf);
@@ -142,7 +141,6 @@ static int usbtmc_open(struct inode *inode, struct file *filp)
142 /* Store pointer in file structure's private data field */ 141 /* Store pointer in file structure's private data field */
143 filp->private_data = data; 142 filp->private_data = data;
144 143
145exit:
146 return retval; 144 return retval;
147} 145}
148 146
@@ -394,12 +392,12 @@ static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t t
394 */ 392 */
395 buffer[0] = 2; 393 buffer[0] = 2;
396 buffer[1] = data->bTag; 394 buffer[1] = data->bTag;
397 buffer[2] = ~(data->bTag); 395 buffer[2] = ~data->bTag;
398 buffer[3] = 0; /* Reserved */ 396 buffer[3] = 0; /* Reserved */
399 buffer[4] = (transfer_size) & 255; 397 buffer[4] = transfer_size >> 0;
400 buffer[5] = ((transfer_size) >> 8) & 255; 398 buffer[5] = transfer_size >> 8;
401 buffer[6] = ((transfer_size) >> 16) & 255; 399 buffer[6] = transfer_size >> 16;
402 buffer[7] = ((transfer_size) >> 24) & 255; 400 buffer[7] = transfer_size >> 24;
403 buffer[8] = data->TermCharEnabled * 2; 401 buffer[8] = data->TermCharEnabled * 2;
404 /* Use term character? */ 402 /* Use term character? */
405 buffer[9] = data->TermChar; 403 buffer[9] = data->TermChar;
@@ -418,7 +416,7 @@ static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t t
418 /* Increment bTag -- and increment again if zero */ 416 /* Increment bTag -- and increment again if zero */
419 data->bTag++; 417 data->bTag++;
420 if (!data->bTag) 418 if (!data->bTag)
421 (data->bTag)++; 419 data->bTag++;
422 420
423 if (retval < 0) { 421 if (retval < 0) {
424 dev_err(&data->intf->dev, "usb_bulk_msg in send_request_dev_dep_msg_in() returned %d\n", retval); 422 dev_err(&data->intf->dev, "usb_bulk_msg in send_request_dev_dep_msg_in() returned %d\n", retval);
@@ -473,7 +471,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
473 done = 0; 471 done = 0;
474 472
475 while (remaining > 0) { 473 while (remaining > 0) {
476 if (!(data->rigol_quirk)) { 474 if (!data->rigol_quirk) {
477 dev_dbg(dev, "usb_bulk_msg_in: remaining(%zu), count(%zu)\n", remaining, count); 475 dev_dbg(dev, "usb_bulk_msg_in: remaining(%zu), count(%zu)\n", remaining, count);
478 476
479 if (remaining > USBTMC_SIZE_IOBUFFER - USBTMC_HEADER_SIZE - 3) 477 if (remaining > USBTMC_SIZE_IOBUFFER - USBTMC_HEADER_SIZE - 3)
@@ -510,7 +508,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
510 } 508 }
511 509
512 /* Parse header in first packet */ 510 /* Parse header in first packet */
513 if ((done == 0) || (!(data->rigol_quirk))) { 511 if ((done == 0) || !data->rigol_quirk) {
514 /* Sanity checks for the header */ 512 /* Sanity checks for the header */
515 if (actual < USBTMC_HEADER_SIZE) { 513 if (actual < USBTMC_HEADER_SIZE) {
516 dev_err(dev, "Device sent too small first packet: %u < %u\n", actual, USBTMC_HEADER_SIZE); 514 dev_err(dev, "Device sent too small first packet: %u < %u\n", actual, USBTMC_HEADER_SIZE);
@@ -554,14 +552,14 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
554 if (remaining > n_characters) 552 if (remaining > n_characters)
555 remaining = n_characters; 553 remaining = n_characters;
556 /* Remove padding if it exists */ 554 /* Remove padding if it exists */
557 if (actual > remaining) 555 if (actual > remaining)
558 actual = remaining; 556 actual = remaining;
559 } 557 }
560 else { 558 else {
561 if (this_part > n_characters) 559 if (this_part > n_characters)
562 this_part = n_characters; 560 this_part = n_characters;
563 /* Remove padding if it exists */ 561 /* Remove padding if it exists */
564 if (actual > this_part) 562 if (actual > this_part)
565 actual = this_part; 563 actual = this_part;
566 } 564 }
567 565
@@ -570,7 +568,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
570 remaining -= actual; 568 remaining -= actual;
571 569
572 /* Terminate if end-of-message bit received from device */ 570 /* Terminate if end-of-message bit received from device */
573 if ((buffer[8] & 0x01) && (actual >= n_characters)) 571 if ((buffer[8] & 0x01) && (actual >= n_characters))
574 remaining = 0; 572 remaining = 0;
575 573
576 dev_dbg(dev, "Bulk-IN header: remaining(%zu), buf(%p), buffer(%p) done(%zu)\n", remaining,buf,buffer,done); 574 dev_dbg(dev, "Bulk-IN header: remaining(%zu), buf(%p), buffer(%p) done(%zu)\n", remaining,buf,buffer,done);
@@ -585,7 +583,7 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
585 done += actual; 583 done += actual;
586 } 584 }
587 else { 585 else {
588 if (actual > remaining) 586 if (actual > remaining)
589 actual = remaining; 587 actual = remaining;
590 588
591 remaining -= actual; 589 remaining -= actual;
@@ -651,12 +649,12 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
651 /* Setup IO buffer for DEV_DEP_MSG_OUT message */ 649 /* Setup IO buffer for DEV_DEP_MSG_OUT message */
652 buffer[0] = 1; 650 buffer[0] = 1;
653 buffer[1] = data->bTag; 651 buffer[1] = data->bTag;
654 buffer[2] = ~(data->bTag); 652 buffer[2] = ~data->bTag;
655 buffer[3] = 0; /* Reserved */ 653 buffer[3] = 0; /* Reserved */
656 buffer[4] = this_part & 255; 654 buffer[4] = this_part >> 0;
657 buffer[5] = (this_part >> 8) & 255; 655 buffer[5] = this_part >> 8;
658 buffer[6] = (this_part >> 16) & 255; 656 buffer[6] = this_part >> 16;
659 buffer[7] = (this_part >> 24) & 255; 657 buffer[7] = this_part >> 24;
660 /* buffer[8] is set above... */ 658 /* buffer[8] is set above... */
661 buffer[9] = 0; /* Reserved */ 659 buffer[9] = 0; /* Reserved */
662 buffer[10] = 0; /* Reserved */ 660 buffer[10] = 0; /* Reserved */
@@ -1102,7 +1100,7 @@ static int usbtmc_probe(struct usb_interface *intf,
1102 1100
1103 dev_dbg(&intf->dev, "%s called\n", __func__); 1101 dev_dbg(&intf->dev, "%s called\n", __func__);
1104 1102
1105 data = kmalloc(sizeof(struct usbtmc_device_data), GFP_KERNEL); 1103 data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
1106 if (!data) { 1104 if (!data) {
1107 dev_err(&intf->dev, "Unable to allocate kernel memory\n"); 1105 dev_err(&intf->dev, "Unable to allocate kernel memory\n");
1108 return -ENOMEM; 1106 return -ENOMEM;
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index b0585e623ba9..23559746be92 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -43,10 +43,11 @@ static const size_t pool_max[HCD_BUFFER_POOLS] = {
43 * 43 *
44 * Call this as part of initializing a host controller that uses the dma 44 * Call this as part of initializing a host controller that uses the dma
45 * memory allocators. It initializes some pools of dma-coherent memory that 45 * memory allocators. It initializes some pools of dma-coherent memory that
46 * will be shared by all drivers using that controller, or returns a negative 46 * will be shared by all drivers using that controller.
47 * errno value on error.
48 * 47 *
49 * Call hcd_buffer_destroy() to clean up after using those pools. 48 * Call hcd_buffer_destroy() to clean up after using those pools.
49 *
50 * Return: 0 if successful. A negative errno value otherwise.
50 */ 51 */
51int hcd_buffer_create(struct usb_hcd *hcd) 52int hcd_buffer_create(struct usb_hcd *hcd)
52{ 53{
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 7199adccf444..a6b2cabe7930 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -424,7 +424,8 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
424 424
425 memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE); 425 memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE);
426 if (config->desc.bDescriptorType != USB_DT_CONFIG || 426 if (config->desc.bDescriptorType != USB_DT_CONFIG ||
427 config->desc.bLength < USB_DT_CONFIG_SIZE) { 427 config->desc.bLength < USB_DT_CONFIG_SIZE ||
428 config->desc.bLength > size) {
428 dev_err(ddev, "invalid descriptor for config index %d: " 429 dev_err(ddev, "invalid descriptor for config index %d: "
429 "type = 0x%X, length = %d\n", cfgidx, 430 "type = 0x%X, length = %d\n", cfgidx,
430 config->desc.bDescriptorType, config->desc.bLength); 431 config->desc.bDescriptorType, config->desc.bLength);
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 05986507b585..737e3c19967b 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -725,15 +725,15 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype,
725 725
726 /* 726 /*
727 * check for the special corner case 'get_device_id' in the printer 727 * check for the special corner case 'get_device_id' in the printer
728 * class specification, where wIndex is (interface << 8 | altsetting) 728 * class specification, which we always want to allow as it is used
729 * instead of just interface 729 * to query things like ink level, etc.
730 */ 730 */
731 if (requesttype == 0xa1 && request == 0) { 731 if (requesttype == 0xa1 && request == 0) {
732 alt_setting = usb_find_alt_setting(ps->dev->actconfig, 732 alt_setting = usb_find_alt_setting(ps->dev->actconfig,
733 index >> 8, index & 0xff); 733 index >> 8, index & 0xff);
734 if (alt_setting 734 if (alt_setting
735 && alt_setting->desc.bInterfaceClass == USB_CLASS_PRINTER) 735 && alt_setting->desc.bInterfaceClass == USB_CLASS_PRINTER)
736 index >>= 8; 736 return 0;
737 } 737 }
738 738
739 index &= 0xff; 739 index &= 0xff;
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 7609ac4aed1c..124bcc50b0b7 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -117,6 +117,8 @@ static DRIVER_ATTR(new_id, S_IRUGO | S_IWUSR, show_dynids, store_new_id);
117 * @count: input size 117 * @count: input size
118 * 118 *
119 * Removes a dynamic usb device ID from this driver. 119 * Removes a dynamic usb device ID from this driver.
120 *
121 * Return: @count on success. A negative error code otherwise.
120 */ 122 */
121static ssize_t 123static ssize_t
122store_remove_id(struct device_driver *driver, const char *buf, size_t count) 124store_remove_id(struct device_driver *driver, const char *buf, size_t count)
@@ -457,6 +459,8 @@ static int usb_unbind_interface(struct device *dev)
457 * Callers must own the device lock, so driver probe() entries don't need 459 * Callers must own the device lock, so driver probe() entries don't need
458 * extra locking, but other call contexts may need to explicitly claim that 460 * extra locking, but other call contexts may need to explicitly claim that
459 * lock. 461 * lock.
462 *
463 * Return: 0 on success.
460 */ 464 */
461int usb_driver_claim_interface(struct usb_driver *driver, 465int usb_driver_claim_interface(struct usb_driver *driver,
462 struct usb_interface *iface, void *priv) 466 struct usb_interface *iface, void *priv)
@@ -658,6 +662,8 @@ EXPORT_SYMBOL_GPL(usb_match_one_id);
658 * These device tables are exported with MODULE_DEVICE_TABLE, through 662 * These device tables are exported with MODULE_DEVICE_TABLE, through
659 * modutils, to support the driver loading functionality of USB hotplugging. 663 * modutils, to support the driver loading functionality of USB hotplugging.
660 * 664 *
665 * Return: The first matching usb_device_id, or %NULL.
666 *
661 * What Matches: 667 * What Matches:
662 * 668 *
663 * The "match_flags" element in a usb_device_id controls which 669 * The "match_flags" element in a usb_device_id controls which
@@ -823,7 +829,8 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
823 * Registers a USB device driver with the USB core. The list of 829 * Registers a USB device driver with the USB core. The list of
824 * unattached devices will be rescanned whenever a new driver is 830 * unattached devices will be rescanned whenever a new driver is
825 * added, allowing the new driver to attach to any recognized devices. 831 * added, allowing the new driver to attach to any recognized devices.
826 * Returns a negative error code on failure and 0 on success. 832 *
833 * Return: A negative error code on failure and 0 on success.
827 */ 834 */
828int usb_register_device_driver(struct usb_device_driver *new_udriver, 835int usb_register_device_driver(struct usb_device_driver *new_udriver,
829 struct module *owner) 836 struct module *owner)
@@ -879,7 +886,8 @@ EXPORT_SYMBOL_GPL(usb_deregister_device_driver);
879 * Registers a USB interface driver with the USB core. The list of 886 * Registers a USB interface driver with the USB core. The list of
880 * unattached interfaces will be rescanned whenever a new driver is 887 * unattached interfaces will be rescanned whenever a new driver is
881 * added, allowing the new driver to attach to any recognized interfaces. 888 * added, allowing the new driver to attach to any recognized interfaces.
882 * Returns a negative error code on failure and 0 on success. 889 *
890 * Return: A negative error code on failure and 0 on success.
883 * 891 *
884 * NOTE: if you want your driver to use the USB major number, you must call 892 * NOTE: if you want your driver to use the USB major number, you must call
885 * usb_register_dev() to enable that functionality. This function no longer 893 * usb_register_dev() to enable that functionality. This function no longer
@@ -1213,6 +1221,8 @@ done:
1213 * unpredictable times. 1221 * unpredictable times.
1214 * 1222 *
1215 * This routine can run only in process context. 1223 * This routine can run only in process context.
1224 *
1225 * Return: 0 if the suspend succeeded.
1216 */ 1226 */
1217static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) 1227static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1218{ 1228{
@@ -1294,6 +1304,8 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1294 * unpredictable times. 1304 * unpredictable times.
1295 * 1305 *
1296 * This routine can run only in process context. 1306 * This routine can run only in process context.
1307 *
1308 * Return: 0 on success.
1297 */ 1309 */
1298static int usb_resume_both(struct usb_device *udev, pm_message_t msg) 1310static int usb_resume_both(struct usb_device *udev, pm_message_t msg)
1299{ 1311{
@@ -1491,6 +1503,8 @@ void usb_autosuspend_device(struct usb_device *udev)
1491 * The caller must hold @udev's device lock. 1503 * The caller must hold @udev's device lock.
1492 * 1504 *
1493 * This routine can run only in process context. 1505 * This routine can run only in process context.
1506 *
1507 * Return: 0 on success. A negative error code otherwise.
1494 */ 1508 */
1495int usb_autoresume_device(struct usb_device *udev) 1509int usb_autoresume_device(struct usb_device *udev)
1496{ 1510{
@@ -1600,6 +1614,8 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface_no_suspend);
1600 * However if the autoresume fails then the counter is re-decremented. 1614 * However if the autoresume fails then the counter is re-decremented.
1601 * 1615 *
1602 * This routine can run only in process context. 1616 * This routine can run only in process context.
1617 *
1618 * Return: 0 on success.
1603 */ 1619 */
1604int usb_autopm_get_interface(struct usb_interface *intf) 1620int usb_autopm_get_interface(struct usb_interface *intf)
1605{ 1621{
@@ -1633,6 +1649,8 @@ EXPORT_SYMBOL_GPL(usb_autopm_get_interface);
1633 * resumed. 1649 * resumed.
1634 * 1650 *
1635 * This routine can run in atomic context. 1651 * This routine can run in atomic context.
1652 *
1653 * Return: 0 on success. A negative error code otherwise.
1636 */ 1654 */
1637int usb_autopm_get_interface_async(struct usb_interface *intf) 1655int usb_autopm_get_interface_async(struct usb_interface *intf)
1638{ 1656{
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 68cc6532e749..f13a289a0743 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -12,7 +12,6 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/spinlock.h> 13#include <linux/spinlock.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/idr.h>
16#include <linux/usb.h> 15#include <linux/usb.h>
17#include "usb.h" 16#include "usb.h"
18 17
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 6a4c40766f0f..7421888087a3 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -153,7 +153,7 @@ void usb_major_cleanup(void)
153 * usb_deregister_dev() must be called when the driver is done with 153 * usb_deregister_dev() must be called when the driver is done with
154 * the minor numbers given out by this function. 154 * the minor numbers given out by this function.
155 * 155 *
156 * Returns -EINVAL if something bad happens with trying to register a 156 * Return: -EINVAL if something bad happens with trying to register a
157 * device, and 0 on success. 157 * device, and 0 on success.
158 */ 158 */
159int usb_register_dev(struct usb_interface *intf, 159int usb_register_dev(struct usb_interface *intf,
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index caeb8d6d39fb..b9d3c43e3859 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -171,6 +171,8 @@ static void ehci_wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd,
171 * through the hotplug entry's driver_data. 171 * through the hotplug entry's driver_data.
172 * 172 *
173 * Store this function in the HCD's struct pci_driver as probe(). 173 * Store this function in the HCD's struct pci_driver as probe().
174 *
175 * Return: 0 if successful.
174 */ 176 */
175int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 177int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
176{ 178{
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 014dc996b4f6..19ad3d2f8a24 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -378,9 +378,10 @@ MODULE_PARM_DESC(authorized_default,
378 * @buf: Buffer for USB string descriptor (header + UTF-16LE) 378 * @buf: Buffer for USB string descriptor (header + UTF-16LE)
379 * @len: Length (in bytes; may be odd) of descriptor buffer. 379 * @len: Length (in bytes; may be odd) of descriptor buffer.
380 * 380 *
381 * The return value is the number of bytes filled in: 2 + 2*strlen(s) or 381 * Return: The number of bytes filled in: 2 + 2*strlen(s) or @len,
382 * buflen, whichever is less. 382 * whichever is less.
383 * 383 *
384 * Note:
384 * USB String descriptors can contain at most 126 characters; input 385 * USB String descriptors can contain at most 126 characters; input
385 * strings longer than that are truncated. 386 * strings longer than that are truncated.
386 */ 387 */
@@ -416,7 +417,8 @@ ascii2desc(char const *s, u8 *buf, unsigned len)
416 * 417 *
417 * Produces either a manufacturer, product or serial number string for the 418 * Produces either a manufacturer, product or serial number string for the
418 * virtual root hub device. 419 * virtual root hub device.
419 * Returns the number of bytes filled in: the length of the descriptor or 420 *
421 * Return: The number of bytes filled in: the length of the descriptor or
420 * of the provided buffer, whichever is less. 422 * of the provided buffer, whichever is less.
421 */ 423 */
422static unsigned 424static unsigned
@@ -464,17 +466,13 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
464 struct usb_ctrlrequest *cmd; 466 struct usb_ctrlrequest *cmd;
465 u16 typeReq, wValue, wIndex, wLength; 467 u16 typeReq, wValue, wIndex, wLength;
466 u8 *ubuf = urb->transfer_buffer; 468 u8 *ubuf = urb->transfer_buffer;
467 /*
468 * tbuf should be as big as the BOS descriptor and
469 * the USB hub descriptor.
470 */
471 u8 tbuf[USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE]
472 __attribute__((aligned(4)));
473 const u8 *bufp = tbuf;
474 unsigned len = 0; 469 unsigned len = 0;
475 int status; 470 int status;
476 u8 patch_wakeup = 0; 471 u8 patch_wakeup = 0;
477 u8 patch_protocol = 0; 472 u8 patch_protocol = 0;
473 u16 tbuf_size;
474 u8 *tbuf = NULL;
475 const u8 *bufp;
478 476
479 might_sleep(); 477 might_sleep();
480 478
@@ -494,6 +492,18 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
494 if (wLength > urb->transfer_buffer_length) 492 if (wLength > urb->transfer_buffer_length)
495 goto error; 493 goto error;
496 494
495 /*
496 * tbuf should be at least as big as the
497 * USB hub descriptor.
498 */
499 tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength);
500 tbuf = kzalloc(tbuf_size, GFP_KERNEL);
501 if (!tbuf)
502 return -ENOMEM;
503
504 bufp = tbuf;
505
506
497 urb->actual_length = 0; 507 urb->actual_length = 0;
498 switch (typeReq) { 508 switch (typeReq) {
499 509
@@ -691,18 +701,12 @@ error:
691 bDeviceProtocol = USB_HUB_PR_HS_SINGLE_TT; 701 bDeviceProtocol = USB_HUB_PR_HS_SINGLE_TT;
692 } 702 }
693 703
704 kfree(tbuf);
705
694 /* any errors get returned through the urb completion */ 706 /* any errors get returned through the urb completion */
695 spin_lock_irq(&hcd_root_hub_lock); 707 spin_lock_irq(&hcd_root_hub_lock);
696 usb_hcd_unlink_urb_from_ep(hcd, urb); 708 usb_hcd_unlink_urb_from_ep(hcd, urb);
697
698 /* This peculiar use of spinlocks echoes what real HC drivers do.
699 * Avoiding calls to local_irq_disable/enable makes the code
700 * RT-friendly.
701 */
702 spin_unlock(&hcd_root_hub_lock);
703 usb_hcd_giveback_urb(hcd, urb, status); 709 usb_hcd_giveback_urb(hcd, urb, status);
704 spin_lock(&hcd_root_hub_lock);
705
706 spin_unlock_irq(&hcd_root_hub_lock); 710 spin_unlock_irq(&hcd_root_hub_lock);
707 return 0; 711 return 0;
708} 712}
@@ -742,9 +746,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
742 memcpy(urb->transfer_buffer, buffer, length); 746 memcpy(urb->transfer_buffer, buffer, length);
743 747
744 usb_hcd_unlink_urb_from_ep(hcd, urb); 748 usb_hcd_unlink_urb_from_ep(hcd, urb);
745 spin_unlock(&hcd_root_hub_lock);
746 usb_hcd_giveback_urb(hcd, urb, 0); 749 usb_hcd_giveback_urb(hcd, urb, 0);
747 spin_lock(&hcd_root_hub_lock);
748 } else { 750 } else {
749 length = 0; 751 length = 0;
750 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); 752 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags);
@@ -834,10 +836,7 @@ static int usb_rh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
834 if (urb == hcd->status_urb) { 836 if (urb == hcd->status_urb) {
835 hcd->status_urb = NULL; 837 hcd->status_urb = NULL;
836 usb_hcd_unlink_urb_from_ep(hcd, urb); 838 usb_hcd_unlink_urb_from_ep(hcd, urb);
837
838 spin_unlock(&hcd_root_hub_lock);
839 usb_hcd_giveback_urb(hcd, urb, status); 839 usb_hcd_giveback_urb(hcd, urb, status);
840 spin_lock(&hcd_root_hub_lock);
841 } 840 }
842 } 841 }
843 done: 842 done:
@@ -938,6 +937,8 @@ static void usb_bus_init (struct usb_bus *bus)
938 * 937 *
939 * Assigns a bus number, and links the controller into usbcore data 938 * Assigns a bus number, and links the controller into usbcore data
940 * structures so that it can be seen by scanning the bus list. 939 * structures so that it can be seen by scanning the bus list.
940 *
941 * Return: 0 if successful. A negative error code otherwise.
941 */ 942 */
942static int usb_register_bus(struct usb_bus *bus) 943static int usb_register_bus(struct usb_bus *bus)
943{ 944{
@@ -1002,6 +1003,8 @@ static void usb_deregister_bus (struct usb_bus *bus)
1002 * the device properly in the device tree and then calls usb_new_device() 1003 * the device properly in the device tree and then calls usb_new_device()
1003 * to register the usb device. It also assigns the root hub's USB address 1004 * to register the usb device. It also assigns the root hub's USB address
1004 * (always 1). 1005 * (always 1).
1006 *
1007 * Return: 0 if successful. A negative error code otherwise.
1005 */ 1008 */
1006static int register_root_hub(struct usb_hcd *hcd) 1009static int register_root_hub(struct usb_hcd *hcd)
1007{ 1010{
@@ -1108,7 +1111,9 @@ EXPORT_SYMBOL_GPL(usb_hcd_end_port_resume);
1108 * @isoc: true for isochronous transactions, false for interrupt ones 1111 * @isoc: true for isochronous transactions, false for interrupt ones
1109 * @bytecount: how many bytes in the transaction. 1112 * @bytecount: how many bytes in the transaction.
1110 * 1113 *
1111 * Returns approximate bus time in nanoseconds for a periodic transaction. 1114 * Return: Approximate bus time in nanoseconds for a periodic transaction.
1115 *
1116 * Note:
1112 * See USB 2.0 spec section 5.11.3; only periodic transfers need to be 1117 * See USB 2.0 spec section 5.11.3; only periodic transfers need to be
1113 * scheduled in software, this function is only used for such scheduling. 1118 * scheduled in software, this function is only used for such scheduling.
1114 */ 1119 */
@@ -1166,7 +1171,7 @@ EXPORT_SYMBOL_GPL(usb_calc_bus_time);
1166 * be disabled. The actions carried out here are required for URB 1171 * be disabled. The actions carried out here are required for URB
1167 * submission, as well as for endpoint shutdown and for usb_kill_urb. 1172 * submission, as well as for endpoint shutdown and for usb_kill_urb.
1168 * 1173 *
1169 * Returns 0 for no error, otherwise a negative error code (in which case 1174 * Return: 0 for no error, otherwise a negative error code (in which case
1170 * the enqueue() method must fail). If no error occurs but enqueue() fails 1175 * the enqueue() method must fail). If no error occurs but enqueue() fails
1171 * anyway, it must call usb_hcd_unlink_urb_from_ep() before releasing 1176 * anyway, it must call usb_hcd_unlink_urb_from_ep() before releasing
1172 * the private spinlock and returning. 1177 * the private spinlock and returning.
@@ -1221,7 +1226,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_link_urb_to_ep);
1221 * be disabled. The actions carried out here are required for making 1226 * be disabled. The actions carried out here are required for making
1222 * sure than an unlink is valid. 1227 * sure than an unlink is valid.
1223 * 1228 *
1224 * Returns 0 for no error, otherwise a negative error code (in which case 1229 * Return: 0 for no error, otherwise a negative error code (in which case
1225 * the dequeue() method must fail). The possible error codes are: 1230 * the dequeue() method must fail). The possible error codes are:
1226 * 1231 *
1227 * -EIDRM: @urb was not submitted or has already completed. 1232 * -EIDRM: @urb was not submitted or has already completed.
@@ -1648,6 +1653,72 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1648 1653
1649/*-------------------------------------------------------------------------*/ 1654/*-------------------------------------------------------------------------*/
1650 1655
1656static void __usb_hcd_giveback_urb(struct urb *urb)
1657{
1658 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus);
1659 int status = urb->unlinked;
1660 unsigned long flags;
1661
1662 urb->hcpriv = NULL;
1663 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) &&
1664 urb->actual_length < urb->transfer_buffer_length &&
1665 !status))
1666 status = -EREMOTEIO;
1667
1668 unmap_urb_for_dma(hcd, urb);
1669 usbmon_urb_complete(&hcd->self, urb, status);
1670 usb_unanchor_urb(urb);
1671
1672 /* pass ownership to the completion handler */
1673 urb->status = status;
1674
1675 /*
1676 * We disable local IRQs here avoid possible deadlock because
1677 * drivers may call spin_lock() to hold lock which might be
1678 * acquired in one hard interrupt handler.
1679 *
1680 * The local_irq_save()/local_irq_restore() around complete()
1681 * will be removed if current USB drivers have been cleaned up
1682 * and no one may trigger the above deadlock situation when
1683 * running complete() in tasklet.
1684 */
1685 local_irq_save(flags);
1686 urb->complete(urb);
1687 local_irq_restore(flags);
1688
1689 atomic_dec(&urb->use_count);
1690 if (unlikely(atomic_read(&urb->reject)))
1691 wake_up(&usb_kill_urb_queue);
1692 usb_put_urb(urb);
1693}
1694
1695static void usb_giveback_urb_bh(unsigned long param)
1696{
1697 struct giveback_urb_bh *bh = (struct giveback_urb_bh *)param;
1698 struct list_head local_list;
1699
1700 spin_lock_irq(&bh->lock);
1701 bh->running = true;
1702 restart:
1703 list_replace_init(&bh->head, &local_list);
1704 spin_unlock_irq(&bh->lock);
1705
1706 while (!list_empty(&local_list)) {
1707 struct urb *urb;
1708
1709 urb = list_entry(local_list.next, struct urb, urb_list);
1710 list_del_init(&urb->urb_list);
1711 __usb_hcd_giveback_urb(urb);
1712 }
1713
1714 /* check if there are new URBs to giveback */
1715 spin_lock_irq(&bh->lock);
1716 if (!list_empty(&bh->head))
1717 goto restart;
1718 bh->running = false;
1719 spin_unlock_irq(&bh->lock);
1720}
1721
1651/** 1722/**
1652 * usb_hcd_giveback_urb - return URB from HCD to device driver 1723 * usb_hcd_giveback_urb - return URB from HCD to device driver
1653 * @hcd: host controller returning the URB 1724 * @hcd: host controller returning the URB
@@ -1667,25 +1738,37 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1667 */ 1738 */
1668void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status) 1739void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
1669{ 1740{
1670 urb->hcpriv = NULL; 1741 struct giveback_urb_bh *bh;
1671 if (unlikely(urb->unlinked)) 1742 bool running, high_prio_bh;
1672 status = urb->unlinked;
1673 else if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) &&
1674 urb->actual_length < urb->transfer_buffer_length &&
1675 !status))
1676 status = -EREMOTEIO;
1677 1743
1678 unmap_urb_for_dma(hcd, urb); 1744 /* pass status to tasklet via unlinked */
1679 usbmon_urb_complete(&hcd->self, urb, status); 1745 if (likely(!urb->unlinked))
1680 usb_unanchor_urb(urb); 1746 urb->unlinked = status;
1681 1747
1682 /* pass ownership to the completion handler */ 1748 if (!hcd_giveback_urb_in_bh(hcd) && !is_root_hub(urb->dev)) {
1683 urb->status = status; 1749 __usb_hcd_giveback_urb(urb);
1684 urb->complete (urb); 1750 return;
1685 atomic_dec (&urb->use_count); 1751 }
1686 if (unlikely(atomic_read(&urb->reject))) 1752
1687 wake_up (&usb_kill_urb_queue); 1753 if (usb_pipeisoc(urb->pipe) || usb_pipeint(urb->pipe)) {
1688 usb_put_urb (urb); 1754 bh = &hcd->high_prio_bh;
1755 high_prio_bh = true;
1756 } else {
1757 bh = &hcd->low_prio_bh;
1758 high_prio_bh = false;
1759 }
1760
1761 spin_lock(&bh->lock);
1762 list_add_tail(&urb->urb_list, &bh->head);
1763 running = bh->running;
1764 spin_unlock(&bh->lock);
1765
1766 if (running)
1767 ;
1768 else if (high_prio_bh)
1769 tasklet_hi_schedule(&bh->bh);
1770 else
1771 tasklet_schedule(&bh->bh);
1689} 1772}
1690EXPORT_SYMBOL_GPL(usb_hcd_giveback_urb); 1773EXPORT_SYMBOL_GPL(usb_hcd_giveback_urb);
1691 1774
@@ -1784,7 +1867,7 @@ rescan:
1784 * pass in the current alternate interface setting in cur_alt, 1867 * pass in the current alternate interface setting in cur_alt,
1785 * and pass in the new alternate interface setting in new_alt. 1868 * and pass in the new alternate interface setting in new_alt.
1786 * 1869 *
1787 * Returns an error if the requested bandwidth change exceeds the 1870 * Return: An error if the requested bandwidth change exceeds the
1788 * bus bandwidth or host controller internal resources. 1871 * bus bandwidth or host controller internal resources.
1789 */ 1872 */
1790int usb_hcd_alloc_bandwidth(struct usb_device *udev, 1873int usb_hcd_alloc_bandwidth(struct usb_device *udev,
@@ -1954,9 +2037,12 @@ void usb_hcd_reset_endpoint(struct usb_device *udev,
1954 * @num_streams: number of streams to allocate. 2037 * @num_streams: number of streams to allocate.
1955 * @mem_flags: flags hcd should use to allocate memory. 2038 * @mem_flags: flags hcd should use to allocate memory.
1956 * 2039 *
1957 * Sets up a group of bulk endpoints to have num_streams stream IDs available. 2040 * Sets up a group of bulk endpoints to have @num_streams stream IDs available.
1958 * Drivers may queue multiple transfers to different stream IDs, which may 2041 * Drivers may queue multiple transfers to different stream IDs, which may
1959 * complete in a different order than they were queued. 2042 * complete in a different order than they were queued.
2043 *
2044 * Return: On success, the number of allocated streams. On failure, a negative
2045 * error code.
1960 */ 2046 */
1961int usb_alloc_streams(struct usb_interface *interface, 2047int usb_alloc_streams(struct usb_interface *interface,
1962 struct usb_host_endpoint **eps, unsigned int num_eps, 2048 struct usb_host_endpoint **eps, unsigned int num_eps,
@@ -2201,6 +2287,8 @@ EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub);
2201 * khubd identifying and possibly configuring the device. 2287 * khubd identifying and possibly configuring the device.
2202 * This is needed by OTG controller drivers, where it helps meet 2288 * This is needed by OTG controller drivers, where it helps meet
2203 * HNP protocol timing requirements for starting a port reset. 2289 * HNP protocol timing requirements for starting a port reset.
2290 *
2291 * Return: 0 if successful.
2204 */ 2292 */
2205int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num) 2293int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num)
2206{ 2294{
@@ -2235,6 +2323,8 @@ EXPORT_SYMBOL_GPL(usb_bus_start_enum);
2235 * 2323 *
2236 * If the controller isn't HALTed, calls the driver's irq handler. 2324 * If the controller isn't HALTed, calls the driver's irq handler.
2237 * Checks whether the controller is now dead. 2325 * Checks whether the controller is now dead.
2326 *
2327 * Return: %IRQ_HANDLED if the IRQ was handled. %IRQ_NONE otherwise.
2238 */ 2328 */
2239irqreturn_t usb_hcd_irq (int irq, void *__hcd) 2329irqreturn_t usb_hcd_irq (int irq, void *__hcd)
2240{ 2330{
@@ -2307,6 +2397,14 @@ EXPORT_SYMBOL_GPL (usb_hc_died);
2307 2397
2308/*-------------------------------------------------------------------------*/ 2398/*-------------------------------------------------------------------------*/
2309 2399
2400static void init_giveback_urb_bh(struct giveback_urb_bh *bh)
2401{
2402
2403 spin_lock_init(&bh->lock);
2404 INIT_LIST_HEAD(&bh->head);
2405 tasklet_init(&bh->bh, usb_giveback_urb_bh, (unsigned long)bh);
2406}
2407
2310/** 2408/**
2311 * usb_create_shared_hcd - create and initialize an HCD structure 2409 * usb_create_shared_hcd - create and initialize an HCD structure
2312 * @driver: HC driver that will use this hcd 2410 * @driver: HC driver that will use this hcd
@@ -2320,7 +2418,8 @@ EXPORT_SYMBOL_GPL (usb_hc_died);
2320 * HC driver's private data. Initialize the generic members of the 2418 * HC driver's private data. Initialize the generic members of the
2321 * hcd structure. 2419 * hcd structure.
2322 * 2420 *
2323 * If memory is unavailable, returns NULL. 2421 * Return: On success, a pointer to the created and initialized HCD structure.
2422 * On failure (e.g. if memory is unavailable), %NULL.
2324 */ 2423 */
2325struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver, 2424struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
2326 struct device *dev, const char *bus_name, 2425 struct device *dev, const char *bus_name,
@@ -2384,7 +2483,8 @@ EXPORT_SYMBOL_GPL(usb_create_shared_hcd);
2384 * HC driver's private data. Initialize the generic members of the 2483 * HC driver's private data. Initialize the generic members of the
2385 * hcd structure. 2484 * hcd structure.
2386 * 2485 *
2387 * If memory is unavailable, returns NULL. 2486 * Return: On success, a pointer to the created and initialized HCD
2487 * structure. On failure (e.g. if memory is unavailable), %NULL.
2388 */ 2488 */
2389struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, 2489struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
2390 struct device *dev, const char *bus_name) 2490 struct device *dev, const char *bus_name)
@@ -2563,7 +2663,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2563 * should already have been reset (and boot firmware kicked off etc). 2663 * should already have been reset (and boot firmware kicked off etc).
2564 */ 2664 */
2565 if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) { 2665 if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) {
2566 dev_err(hcd->self.controller, "can't setup\n"); 2666 dev_err(hcd->self.controller, "can't setup: %d\n", retval);
2567 goto err_hcd_driver_setup; 2667 goto err_hcd_driver_setup;
2568 } 2668 }
2569 hcd->rh_pollable = 1; 2669 hcd->rh_pollable = 1;
@@ -2573,6 +2673,10 @@ int usb_add_hcd(struct usb_hcd *hcd,
2573 && device_can_wakeup(&hcd->self.root_hub->dev)) 2673 && device_can_wakeup(&hcd->self.root_hub->dev))
2574 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); 2674 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
2575 2675
2676 /* initialize tasklets */
2677 init_giveback_urb_bh(&hcd->high_prio_bh);
2678 init_giveback_urb_bh(&hcd->low_prio_bh);
2679
2576 /* enable irqs just before we start the controller, 2680 /* enable irqs just before we start the controller,
2577 * if the BIOS provides legacy PCI irqs. 2681 * if the BIOS provides legacy PCI irqs.
2578 */ 2682 */
@@ -2681,6 +2785,16 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2681 usb_disconnect(&rhdev); /* Sets rhdev to NULL */ 2785 usb_disconnect(&rhdev); /* Sets rhdev to NULL */
2682 mutex_unlock(&usb_bus_list_lock); 2786 mutex_unlock(&usb_bus_list_lock);
2683 2787
2788 /*
2789 * tasklet_kill() isn't needed here because:
2790 * - driver's disconnect() called from usb_disconnect() should
2791 * make sure its URBs are completed during the disconnect()
2792 * callback
2793 *
2794 * - it is too late to run complete() here since driver may have
2795 * been removed already now
2796 */
2797
2684 /* Prevent any more root-hub status calls from the timer. 2798 /* Prevent any more root-hub status calls from the timer.
2685 * The HCD might still restart the timer (if a port status change 2799 * The HCD might still restart the timer (if a port status change
2686 * interrupt occurs), but usb_hcd_poll_rh_status() won't invoke 2800 * interrupt occurs), but usb_hcd_poll_rh_status() won't invoke
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 17c3785241a4..175179eb17ee 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -734,6 +734,8 @@ static void hub_tt_work(struct work_struct *work)
734 * 734 *
735 * call this function to control port's power via setting or 735 * call this function to control port's power via setting or
736 * clearing the port's PORT_POWER feature. 736 * clearing the port's PORT_POWER feature.
737 *
738 * Return: 0 if successful. A negative error code otherwise.
737 */ 739 */
738int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, 740int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
739 int port1, bool set) 741 int port1, bool set)
@@ -762,6 +764,8 @@ int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
762 * 764 *
763 * It may not be possible for that hub to handle additional full (or low) 765 * It may not be possible for that hub to handle additional full (or low)
764 * speed transactions until that state is fully cleared out. 766 * speed transactions until that state is fully cleared out.
767 *
768 * Return: 0 if successful. A negative error code otherwise.
765 */ 769 */
766int usb_hub_clear_tt_buffer(struct urb *urb) 770int usb_hub_clear_tt_buffer(struct urb *urb)
767{ 771{
@@ -964,6 +968,8 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
964 * see that the device has been disconnected. When the device is 968 * see that the device has been disconnected. When the device is
965 * physically unplugged and something is plugged in, the events will 969 * physically unplugged and something is plugged in, the events will
966 * be received and processed normally. 970 * be received and processed normally.
971 *
972 * Return: 0 if successful. A negative error code otherwise.
967 */ 973 */
968int usb_remove_device(struct usb_device *udev) 974int usb_remove_device(struct usb_device *udev)
969{ 975{
@@ -1464,11 +1470,10 @@ static int hub_configure(struct usb_hub *hub,
1464 * and battery-powered root hubs (may provide just 8 mA). 1470 * and battery-powered root hubs (may provide just 8 mA).
1465 */ 1471 */
1466 ret = usb_get_status(hdev, USB_RECIP_DEVICE, 0, &hubstatus); 1472 ret = usb_get_status(hdev, USB_RECIP_DEVICE, 0, &hubstatus);
1467 if (ret < 2) { 1473 if (ret) {
1468 message = "can't get hub status"; 1474 message = "can't get hub status";
1469 goto fail; 1475 goto fail;
1470 } 1476 }
1471 le16_to_cpus(&hubstatus);
1472 hcd = bus_to_hcd(hdev->bus); 1477 hcd = bus_to_hcd(hdev->bus);
1473 if (hdev == hdev->bus->root_hub) { 1478 if (hdev == hdev->bus->root_hub) {
1474 if (hcd->power_budget > 0) 1479 if (hcd->power_budget > 0)
@@ -2116,6 +2121,8 @@ static inline void announce_device(struct usb_device *udev) { }
2116 * @udev: newly addressed device (in ADDRESS state) 2121 * @udev: newly addressed device (in ADDRESS state)
2117 * 2122 *
2118 * Finish enumeration for On-The-Go devices 2123 * Finish enumeration for On-The-Go devices
2124 *
2125 * Return: 0 if successful. A negative error code otherwise.
2119 */ 2126 */
2120static int usb_enumerate_device_otg(struct usb_device *udev) 2127static int usb_enumerate_device_otg(struct usb_device *udev)
2121{ 2128{
@@ -2198,6 +2205,8 @@ fail:
2198 * If the device is WUSB and not authorized, we don't attempt to read 2205 * If the device is WUSB and not authorized, we don't attempt to read
2199 * the string descriptors, as they will be errored out by the device 2206 * the string descriptors, as they will be errored out by the device
2200 * until it has been authorized. 2207 * until it has been authorized.
2208 *
2209 * Return: 0 if successful. A negative error code otherwise.
2201 */ 2210 */
2202static int usb_enumerate_device(struct usb_device *udev) 2211static int usb_enumerate_device(struct usb_device *udev)
2203{ 2212{
@@ -2278,13 +2287,14 @@ static void set_usb_port_removable(struct usb_device *udev)
2278 * udev has already been installed, but udev is not yet visible through 2287 * udev has already been installed, but udev is not yet visible through
2279 * sysfs or other filesystem code. 2288 * sysfs or other filesystem code.
2280 * 2289 *
2281 * It will return if the device is configured properly or not. Zero if
2282 * the interface was registered with the driver core; else a negative
2283 * errno value.
2284 *
2285 * This call is synchronous, and may not be used in an interrupt context. 2290 * This call is synchronous, and may not be used in an interrupt context.
2286 * 2291 *
2287 * Only the hub driver or root-hub registrar should ever call this. 2292 * Only the hub driver or root-hub registrar should ever call this.
2293 *
2294 * Return: Whether the device is configured properly or not. Zero if the
2295 * interface was registered with the driver core; else a negative errno
2296 * value.
2297 *
2288 */ 2298 */
2289int usb_new_device(struct usb_device *udev) 2299int usb_new_device(struct usb_device *udev)
2290{ 2300{
@@ -2392,6 +2402,8 @@ fail:
2392 * 2402 *
2393 * We share a lock (that we have) with device_del(), so we need to 2403 * We share a lock (that we have) with device_del(), so we need to
2394 * defer its call. 2404 * defer its call.
2405 *
2406 * Return: 0.
2395 */ 2407 */
2396int usb_deauthorize_device(struct usb_device *usb_dev) 2408int usb_deauthorize_device(struct usb_device *usb_dev)
2397{ 2409{
@@ -2838,20 +2850,51 @@ void usb_enable_ltm(struct usb_device *udev)
2838} 2850}
2839EXPORT_SYMBOL_GPL(usb_enable_ltm); 2851EXPORT_SYMBOL_GPL(usb_enable_ltm);
2840 2852
2841#ifdef CONFIG_PM
2842/* 2853/*
2843 * usb_disable_function_remotewakeup - disable usb3.0 2854 * usb_enable_remote_wakeup - enable remote wakeup for a device
2844 * device's function remote wakeup
2845 * @udev: target device 2855 * @udev: target device
2846 * 2856 *
2847 * Assume there's only one function on the USB 3.0 2857 * For USB-2 devices: Set the device's remote wakeup feature.
2848 * device and disable remote wake for the first 2858 *
2849 * interface. FIXME if the interface association 2859 * For USB-3 devices: Assume there's only one function on the device and
2850 * descriptor shows there's more than one function. 2860 * enable remote wake for the first interface. FIXME if the interface
2861 * association descriptor shows there's more than one function.
2851 */ 2862 */
2852static int usb_disable_function_remotewakeup(struct usb_device *udev) 2863static int usb_enable_remote_wakeup(struct usb_device *udev)
2853{ 2864{
2854 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 2865 if (udev->speed < USB_SPEED_SUPER)
2866 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2867 USB_REQ_SET_FEATURE, USB_RECIP_DEVICE,
2868 USB_DEVICE_REMOTE_WAKEUP, 0, NULL, 0,
2869 USB_CTRL_SET_TIMEOUT);
2870 else
2871 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2872 USB_REQ_SET_FEATURE, USB_RECIP_INTERFACE,
2873 USB_INTRF_FUNC_SUSPEND,
2874 USB_INTRF_FUNC_SUSPEND_RW |
2875 USB_INTRF_FUNC_SUSPEND_LP,
2876 NULL, 0, USB_CTRL_SET_TIMEOUT);
2877}
2878
2879/*
2880 * usb_disable_remote_wakeup - disable remote wakeup for a device
2881 * @udev: target device
2882 *
2883 * For USB-2 devices: Clear the device's remote wakeup feature.
2884 *
2885 * For USB-3 devices: Assume there's only one function on the device and
2886 * disable remote wake for the first interface. FIXME if the interface
2887 * association descriptor shows there's more than one function.
2888 */
2889static int usb_disable_remote_wakeup(struct usb_device *udev)
2890{
2891 if (udev->speed < USB_SPEED_SUPER)
2892 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2893 USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE,
2894 USB_DEVICE_REMOTE_WAKEUP, 0, NULL, 0,
2895 USB_CTRL_SET_TIMEOUT);
2896 else
2897 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2855 USB_REQ_CLEAR_FEATURE, USB_RECIP_INTERFACE, 2898 USB_REQ_CLEAR_FEATURE, USB_RECIP_INTERFACE,
2856 USB_INTRF_FUNC_SUSPEND, 0, NULL, 0, 2899 USB_INTRF_FUNC_SUSPEND, 0, NULL, 0,
2857 USB_CTRL_SET_TIMEOUT); 2900 USB_CTRL_SET_TIMEOUT);
@@ -2929,27 +2972,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2929 * we don't explicitly enable it here. 2972 * we don't explicitly enable it here.
2930 */ 2973 */
2931 if (udev->do_remote_wakeup) { 2974 if (udev->do_remote_wakeup) {
2932 if (!hub_is_superspeed(hub->hdev)) { 2975 status = usb_enable_remote_wakeup(udev);
2933 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2934 USB_REQ_SET_FEATURE, USB_RECIP_DEVICE,
2935 USB_DEVICE_REMOTE_WAKEUP, 0,
2936 NULL, 0,
2937 USB_CTRL_SET_TIMEOUT);
2938 } else {
2939 /* Assume there's only one function on the USB 3.0
2940 * device and enable remote wake for the first
2941 * interface. FIXME if the interface association
2942 * descriptor shows there's more than one function.
2943 */
2944 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2945 USB_REQ_SET_FEATURE,
2946 USB_RECIP_INTERFACE,
2947 USB_INTRF_FUNC_SUSPEND,
2948 USB_INTRF_FUNC_SUSPEND_RW |
2949 USB_INTRF_FUNC_SUSPEND_LP,
2950 NULL, 0,
2951 USB_CTRL_SET_TIMEOUT);
2952 }
2953 if (status) { 2976 if (status) {
2954 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", 2977 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n",
2955 status); 2978 status);
@@ -3011,20 +3034,8 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
3011 if (udev->usb2_hw_lpm_capable == 1) 3034 if (udev->usb2_hw_lpm_capable == 1)
3012 usb_set_usb2_hardware_lpm(udev, 1); 3035 usb_set_usb2_hardware_lpm(udev, 1);
3013 3036
3014 if (udev->do_remote_wakeup) { 3037 if (udev->do_remote_wakeup)
3015 if (udev->speed < USB_SPEED_SUPER) 3038 (void) usb_disable_remote_wakeup(udev);
3016 usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3017 USB_REQ_CLEAR_FEATURE,
3018 USB_RECIP_DEVICE,
3019 USB_DEVICE_REMOTE_WAKEUP, 0,
3020 NULL, 0, USB_CTRL_SET_TIMEOUT);
3021 else
3022 usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3023 USB_REQ_CLEAR_FEATURE,
3024 USB_RECIP_INTERFACE,
3025 USB_INTRF_FUNC_SUSPEND, 0,
3026 NULL, 0, USB_CTRL_SET_TIMEOUT);
3027 }
3028 err_wakeup: 3039 err_wakeup:
3029 3040
3030 /* System sleep transitions should never fail */ 3041 /* System sleep transitions should never fail */
@@ -3097,8 +3108,6 @@ static int finish_port_resume(struct usb_device *udev)
3097 if (status == 0) { 3108 if (status == 0) {
3098 devstatus = 0; 3109 devstatus = 0;
3099 status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus); 3110 status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus);
3100 if (status >= 0)
3101 status = (status > 0 ? 0 : -ENODEV);
3102 3111
3103 /* If a normal resume failed, try doing a reset-resume */ 3112 /* If a normal resume failed, try doing a reset-resume */
3104 if (status && !udev->reset_resume && udev->persist_enabled) { 3113 if (status && !udev->reset_resume && udev->persist_enabled) {
@@ -3118,24 +3127,15 @@ static int finish_port_resume(struct usb_device *udev)
3118 * udev->reset_resume 3127 * udev->reset_resume
3119 */ 3128 */
3120 } else if (udev->actconfig && !udev->reset_resume) { 3129 } else if (udev->actconfig && !udev->reset_resume) {
3121 if (!hub_is_superspeed(udev->parent)) { 3130 if (udev->speed < USB_SPEED_SUPER) {
3122 le16_to_cpus(&devstatus);
3123 if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) 3131 if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP))
3124 status = usb_control_msg(udev, 3132 status = usb_disable_remote_wakeup(udev);
3125 usb_sndctrlpipe(udev, 0),
3126 USB_REQ_CLEAR_FEATURE,
3127 USB_RECIP_DEVICE,
3128 USB_DEVICE_REMOTE_WAKEUP, 0,
3129 NULL, 0,
3130 USB_CTRL_SET_TIMEOUT);
3131 } else { 3133 } else {
3132 status = usb_get_status(udev, USB_RECIP_INTERFACE, 0, 3134 status = usb_get_status(udev, USB_RECIP_INTERFACE, 0,
3133 &devstatus); 3135 &devstatus);
3134 le16_to_cpus(&devstatus);
3135 if (!status && devstatus & (USB_INTRF_STAT_FUNC_RW_CAP 3136 if (!status && devstatus & (USB_INTRF_STAT_FUNC_RW_CAP
3136 | USB_INTRF_STAT_FUNC_RW)) 3137 | USB_INTRF_STAT_FUNC_RW))
3137 status = 3138 status = usb_disable_remote_wakeup(udev);
3138 usb_disable_function_remotewakeup(udev);
3139 } 3139 }
3140 3140
3141 if (status) 3141 if (status)
@@ -3269,8 +3269,6 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
3269 return status; 3269 return status;
3270} 3270}
3271 3271
3272#endif /* CONFIG_PM */
3273
3274#ifdef CONFIG_PM_RUNTIME 3272#ifdef CONFIG_PM_RUNTIME
3275 3273
3276/* caller has locked udev */ 3274/* caller has locked udev */
@@ -3838,7 +3836,8 @@ EXPORT_SYMBOL_GPL(usb_disable_ltm);
3838 3836
3839void usb_enable_ltm(struct usb_device *udev) { } 3837void usb_enable_ltm(struct usb_device *udev) { }
3840EXPORT_SYMBOL_GPL(usb_enable_ltm); 3838EXPORT_SYMBOL_GPL(usb_enable_ltm);
3841#endif 3839
3840#endif /* CONFIG_PM */
3842 3841
3843 3842
3844/* USB 2.0 spec, 7.1.7.3 / fig 7-29: 3843/* USB 2.0 spec, 7.1.7.3 / fig 7-29:
@@ -4478,11 +4477,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4478 4477
4479 status = usb_get_status(udev, USB_RECIP_DEVICE, 0, 4478 status = usb_get_status(udev, USB_RECIP_DEVICE, 0,
4480 &devstat); 4479 &devstat);
4481 if (status < 2) { 4480 if (status) {
4482 dev_dbg(&udev->dev, "get status %d ?\n", status); 4481 dev_dbg(&udev->dev, "get status %d ?\n", status);
4483 goto loop_disable; 4482 goto loop_disable;
4484 } 4483 }
4485 le16_to_cpus(&devstat);
4486 if ((devstat & (1 << USB_DEVICE_SELF_POWERED)) == 0) { 4484 if ((devstat & (1 << USB_DEVICE_SELF_POWERED)) == 0) {
4487 dev_err(&udev->dev, 4485 dev_err(&udev->dev,
4488 "can't connect bus-powered hub " 4486 "can't connect bus-powered hub "
@@ -5030,10 +5028,11 @@ static int descriptors_changed(struct usb_device *udev,
5030 * re-connected. All drivers will be unbound, and the device will be 5028 * re-connected. All drivers will be unbound, and the device will be
5031 * re-enumerated and probed all over again. 5029 * re-enumerated and probed all over again.
5032 * 5030 *
5033 * Returns 0 if the reset succeeded, -ENODEV if the device has been 5031 * Return: 0 if the reset succeeded, -ENODEV if the device has been
5034 * flagged for logical disconnection, or some other negative error code 5032 * flagged for logical disconnection, or some other negative error code
5035 * if the reset wasn't even attempted. 5033 * if the reset wasn't even attempted.
5036 * 5034 *
5035 * Note:
5037 * The caller must own the device lock. For example, it's safe to use 5036 * The caller must own the device lock. For example, it's safe to use
5038 * this from a driver probe() routine after downloading new firmware. 5037 * this from a driver probe() routine after downloading new firmware.
5039 * For calls that might not occur during probe(), drivers should lock 5038 * For calls that might not occur during probe(), drivers should lock
@@ -5189,8 +5188,9 @@ re_enumerate:
5189 * method), performs the port reset, and then lets the drivers know that 5188 * method), performs the port reset, and then lets the drivers know that
5190 * the reset is over (using their post_reset method). 5189 * the reset is over (using their post_reset method).
5191 * 5190 *
5192 * Return value is the same as for usb_reset_and_verify_device(). 5191 * Return: The same as for usb_reset_and_verify_device().
5193 * 5192 *
5193 * Note:
5194 * The caller must own the device lock. For example, it's safe to use 5194 * The caller must own the device lock. For example, it's safe to use
5195 * this from a driver probe() routine after downloading new firmware. 5195 * this from a driver probe() routine after downloading new firmware.
5196 * For calls that might not occur during probe(), drivers should lock 5196 * For calls that might not occur during probe(), drivers should lock
@@ -5328,7 +5328,7 @@ EXPORT_SYMBOL_GPL(usb_queue_reset_device);
5328 * USB drivers call this function to get hub's child device 5328 * USB drivers call this function to get hub's child device
5329 * pointer. 5329 * pointer.
5330 * 5330 *
5331 * Return NULL if input param is invalid and 5331 * Return: %NULL if input param is invalid and
5332 * child's usb_device pointer if non-NULL. 5332 * child's usb_device pointer if non-NULL.
5333 */ 5333 */
5334struct usb_device *usb_hub_find_child(struct usb_device *hdev, 5334struct usb_device *usb_hub_find_child(struct usb_device *hdev,
@@ -5362,8 +5362,8 @@ void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1,
5362 * @hdev: USB device belonging to the usb hub 5362 * @hdev: USB device belonging to the usb hub
5363 * @port1: port num of the port 5363 * @port1: port num of the port
5364 * 5364 *
5365 * Return connect type of the port and if input params are 5365 * Return: The connect type of the port if successful. Or
5366 * invalid, return USB_PORT_CONNECT_TYPE_UNKNOWN. 5366 * USB_PORT_CONNECT_TYPE_UNKNOWN if input params are invalid.
5367 */ 5367 */
5368enum usb_port_connect_type 5368enum usb_port_connect_type
5369usb_get_hub_port_connect_type(struct usb_device *hdev, int port1) 5369usb_get_hub_port_connect_type(struct usb_device *hdev, int port1)
@@ -5423,8 +5423,8 @@ void usb_hub_adjust_deviceremovable(struct usb_device *hdev,
5423 * @hdev: USB device belonging to the usb hub 5423 * @hdev: USB device belonging to the usb hub
5424 * @port1: port num of the port 5424 * @port1: port num of the port
5425 * 5425 *
5426 * Return port's acpi handle if successful, NULL if params are 5426 * Return: Port's acpi handle if successful, %NULL if params are
5427 * invaild. 5427 * invalid.
5428 */ 5428 */
5429acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev, 5429acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev,
5430 int port1) 5430 int port1)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index e7ee1e451660..82927e1ed27d 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -119,15 +119,15 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
119 * This function sends a simple control message to a specified endpoint and 119 * This function sends a simple control message to a specified endpoint and
120 * waits for the message to complete, or timeout. 120 * waits for the message to complete, or timeout.
121 * 121 *
122 * If successful, it returns the number of bytes transferred, otherwise a
123 * negative error number.
124 *
125 * Don't use this function from within an interrupt context, like a bottom half 122 * Don't use this function from within an interrupt context, like a bottom half
126 * handler. If you need an asynchronous message, or need to send a message 123 * handler. If you need an asynchronous message, or need to send a message
127 * from within interrupt context, use usb_submit_urb(). 124 * from within interrupt context, use usb_submit_urb().
128 * If a thread in your driver uses this call, make sure your disconnect() 125 * If a thread in your driver uses this call, make sure your disconnect()
129 * method can wait for it to complete. Since you don't have a handle on the 126 * method can wait for it to complete. Since you don't have a handle on the
130 * URB used, you can't cancel the request. 127 * URB used, you can't cancel the request.
128 *
129 * Return: If successful, the number of bytes transferred. Otherwise, a negative
130 * error number.
131 */ 131 */
132int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, 132int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
133 __u8 requesttype, __u16 value, __u16 index, void *data, 133 __u8 requesttype, __u16 value, __u16 index, void *data,
@@ -170,15 +170,16 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
170 * This function sends a simple interrupt message to a specified endpoint and 170 * This function sends a simple interrupt message to a specified endpoint and
171 * waits for the message to complete, or timeout. 171 * waits for the message to complete, or timeout.
172 * 172 *
173 * If successful, it returns 0, otherwise a negative error number. The number
174 * of actual bytes transferred will be stored in the actual_length paramater.
175 *
176 * Don't use this function from within an interrupt context, like a bottom half 173 * Don't use this function from within an interrupt context, like a bottom half
177 * handler. If you need an asynchronous message, or need to send a message 174 * handler. If you need an asynchronous message, or need to send a message
178 * from within interrupt context, use usb_submit_urb() If a thread in your 175 * from within interrupt context, use usb_submit_urb() If a thread in your
179 * driver uses this call, make sure your disconnect() method can wait for it to 176 * driver uses this call, make sure your disconnect() method can wait for it to
180 * complete. Since you don't have a handle on the URB used, you can't cancel 177 * complete. Since you don't have a handle on the URB used, you can't cancel
181 * the request. 178 * the request.
179 *
180 * Return:
181 * If successful, 0. Otherwise a negative error number. The number of actual
182 * bytes transferred will be stored in the @actual_length paramater.
182 */ 183 */
183int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe, 184int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
184 void *data, int len, int *actual_length, int timeout) 185 void *data, int len, int *actual_length, int timeout)
@@ -203,9 +204,6 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
203 * This function sends a simple bulk message to a specified endpoint 204 * This function sends a simple bulk message to a specified endpoint
204 * and waits for the message to complete, or timeout. 205 * and waits for the message to complete, or timeout.
205 * 206 *
206 * If successful, it returns 0, otherwise a negative error number. The number
207 * of actual bytes transferred will be stored in the actual_length paramater.
208 *
209 * Don't use this function from within an interrupt context, like a bottom half 207 * Don't use this function from within an interrupt context, like a bottom half
210 * handler. If you need an asynchronous message, or need to send a message 208 * handler. If you need an asynchronous message, or need to send a message
211 * from within interrupt context, use usb_submit_urb() If a thread in your 209 * from within interrupt context, use usb_submit_urb() If a thread in your
@@ -217,6 +215,11 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
217 * users are forced to abuse this routine by using it to submit URBs for 215 * users are forced to abuse this routine by using it to submit URBs for
218 * interrupt endpoints. We will take the liberty of creating an interrupt URB 216 * interrupt endpoints. We will take the liberty of creating an interrupt URB
219 * (with the default interval) if the target is an interrupt endpoint. 217 * (with the default interval) if the target is an interrupt endpoint.
218 *
219 * Return:
220 * If successful, 0. Otherwise a negative error number. The number of actual
221 * bytes transferred will be stored in the @actual_length paramater.
222 *
220 */ 223 */
221int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, 224int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
222 void *data, int len, int *actual_length, int timeout) 225 void *data, int len, int *actual_length, int timeout)
@@ -341,9 +344,9 @@ static void sg_complete(struct urb *urb)
341 * send every byte identified in the list. 344 * send every byte identified in the list.
342 * @mem_flags: SLAB_* flags affecting memory allocations in this call 345 * @mem_flags: SLAB_* flags affecting memory allocations in this call
343 * 346 *
344 * Returns zero for success, else a negative errno value. This initializes a 347 * This initializes a scatter/gather request, allocating resources such as
345 * scatter/gather request, allocating resources such as I/O mappings and urb 348 * I/O mappings and urb memory (except maybe memory used by USB controller
346 * memory (except maybe memory used by USB controller drivers). 349 * drivers).
347 * 350 *
348 * The request must be issued using usb_sg_wait(), which waits for the I/O to 351 * The request must be issued using usb_sg_wait(), which waits for the I/O to
349 * complete (or to be canceled) and then cleans up all resources allocated by 352 * complete (or to be canceled) and then cleans up all resources allocated by
@@ -351,6 +354,8 @@ static void sg_complete(struct urb *urb)
351 * 354 *
352 * The request may be canceled with usb_sg_cancel(), either before or after 355 * The request may be canceled with usb_sg_cancel(), either before or after
353 * usb_sg_wait() is called. 356 * usb_sg_wait() is called.
357 *
358 * Return: Zero for success, else a negative errno value.
354 */ 359 */
355int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, 360int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
356 unsigned pipe, unsigned period, struct scatterlist *sg, 361 unsigned pipe, unsigned period, struct scatterlist *sg,
@@ -623,7 +628,7 @@ EXPORT_SYMBOL_GPL(usb_sg_cancel);
623 * 628 *
624 * This call is synchronous, and may not be used in an interrupt context. 629 * This call is synchronous, and may not be used in an interrupt context.
625 * 630 *
626 * Returns the number of bytes received on success, or else the status code 631 * Return: The number of bytes received on success, or else the status code
627 * returned by the underlying usb_control_msg() call. 632 * returned by the underlying usb_control_msg() call.
628 */ 633 */
629int usb_get_descriptor(struct usb_device *dev, unsigned char type, 634int usb_get_descriptor(struct usb_device *dev, unsigned char type,
@@ -671,7 +676,7 @@ EXPORT_SYMBOL_GPL(usb_get_descriptor);
671 * 676 *
672 * This call is synchronous, and may not be used in an interrupt context. 677 * This call is synchronous, and may not be used in an interrupt context.
673 * 678 *
674 * Returns the number of bytes received on success, or else the status code 679 * Return: The number of bytes received on success, or else the status code
675 * returned by the underlying usb_control_msg() call. 680 * returned by the underlying usb_control_msg() call.
676 */ 681 */
677static int usb_get_string(struct usb_device *dev, unsigned short langid, 682static int usb_get_string(struct usb_device *dev, unsigned short langid,
@@ -805,7 +810,7 @@ static int usb_get_langid(struct usb_device *dev, unsigned char *tbuf)
805 * 810 *
806 * This call is synchronous, and may not be used in an interrupt context. 811 * This call is synchronous, and may not be used in an interrupt context.
807 * 812 *
808 * Returns length of the string (>= 0) or usb_control_msg status (< 0). 813 * Return: length of the string (>= 0) or usb_control_msg status (< 0).
809 */ 814 */
810int usb_string(struct usb_device *dev, int index, char *buf, size_t size) 815int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
811{ 816{
@@ -853,8 +858,8 @@ EXPORT_SYMBOL_GPL(usb_string);
853 * @udev: the device whose string descriptor is being read 858 * @udev: the device whose string descriptor is being read
854 * @index: the descriptor index 859 * @index: the descriptor index
855 * 860 *
856 * Returns a pointer to a kmalloc'ed buffer containing the descriptor string, 861 * Return: A pointer to a kmalloc'ed buffer containing the descriptor string,
857 * or NULL if the index is 0 or the string could not be read. 862 * or %NULL if the index is 0 or the string could not be read.
858 */ 863 */
859char *usb_cache_string(struct usb_device *udev, int index) 864char *usb_cache_string(struct usb_device *udev, int index)
860{ 865{
@@ -894,7 +899,7 @@ char *usb_cache_string(struct usb_device *udev, int index)
894 * 899 *
895 * This call is synchronous, and may not be used in an interrupt context. 900 * This call is synchronous, and may not be used in an interrupt context.
896 * 901 *
897 * Returns the number of bytes received on success, or else the status code 902 * Return: The number of bytes received on success, or else the status code
898 * returned by the underlying usb_control_msg() call. 903 * returned by the underlying usb_control_msg() call.
899 */ 904 */
900int usb_get_device_descriptor(struct usb_device *dev, unsigned int size) 905int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
@@ -934,13 +939,13 @@ int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
934 * 939 *
935 * This call is synchronous, and may not be used in an interrupt context. 940 * This call is synchronous, and may not be used in an interrupt context.
936 * 941 *
937 * Returns the number of bytes received on success, or else the status code 942 * Returns 0 and the status value in *@data (in host byte order) on success,
938 * returned by the underlying usb_control_msg() call. 943 * or else the status code from the underlying usb_control_msg() call.
939 */ 944 */
940int usb_get_status(struct usb_device *dev, int type, int target, void *data) 945int usb_get_status(struct usb_device *dev, int type, int target, void *data)
941{ 946{
942 int ret; 947 int ret;
943 u16 *status = kmalloc(sizeof(*status), GFP_KERNEL); 948 __le16 *status = kmalloc(sizeof(*status), GFP_KERNEL);
944 949
945 if (!status) 950 if (!status)
946 return -ENOMEM; 951 return -ENOMEM;
@@ -949,7 +954,12 @@ int usb_get_status(struct usb_device *dev, int type, int target, void *data)
949 USB_REQ_GET_STATUS, USB_DIR_IN | type, 0, target, status, 954 USB_REQ_GET_STATUS, USB_DIR_IN | type, 0, target, status,
950 sizeof(*status), USB_CTRL_GET_TIMEOUT); 955 sizeof(*status), USB_CTRL_GET_TIMEOUT);
951 956
952 *(u16 *)data = *status; 957 if (ret == 2) {
958 *(u16 *) data = le16_to_cpu(*status);
959 ret = 0;
960 } else if (ret >= 0) {
961 ret = -EIO;
962 }
953 kfree(status); 963 kfree(status);
954 return ret; 964 return ret;
955} 965}
@@ -975,7 +985,7 @@ EXPORT_SYMBOL_GPL(usb_get_status);
975 * 985 *
976 * This call is synchronous, and may not be used in an interrupt context. 986 * This call is synchronous, and may not be used in an interrupt context.
977 * 987 *
978 * Returns zero on success, or else the status code returned by the 988 * Return: Zero on success, or else the status code returned by the
979 * underlying usb_control_msg() call. 989 * underlying usb_control_msg() call.
980 */ 990 */
981int usb_clear_halt(struct usb_device *dev, int pipe) 991int usb_clear_halt(struct usb_device *dev, int pipe)
@@ -1272,7 +1282,7 @@ void usb_enable_interface(struct usb_device *dev,
1272 * endpoints in that interface; all such urbs must first be completed 1282 * endpoints in that interface; all such urbs must first be completed
1273 * (perhaps forced by unlinking). 1283 * (perhaps forced by unlinking).
1274 * 1284 *
1275 * Returns zero on success, or else the status code returned by the 1285 * Return: Zero on success, or else the status code returned by the
1276 * underlying usb_control_msg() call. 1286 * underlying usb_control_msg() call.
1277 */ 1287 */
1278int usb_set_interface(struct usb_device *dev, int interface, int alternate) 1288int usb_set_interface(struct usb_device *dev, int interface, int alternate)
@@ -1426,7 +1436,7 @@ EXPORT_SYMBOL_GPL(usb_set_interface);
1426 * 1436 *
1427 * The caller must own the device lock. 1437 * The caller must own the device lock.
1428 * 1438 *
1429 * Returns zero on success, else a negative error code. 1439 * Return: Zero on success, else a negative error code.
1430 */ 1440 */
1431int usb_reset_configuration(struct usb_device *dev) 1441int usb_reset_configuration(struct usb_device *dev)
1432{ 1442{
@@ -1968,7 +1978,7 @@ static void cancel_async_set_config(struct usb_device *udev)
1968 * routine gets around the normal restrictions by using a work thread to 1978 * routine gets around the normal restrictions by using a work thread to
1969 * submit the change-config request. 1979 * submit the change-config request.
1970 * 1980 *
1971 * Returns 0 if the request was successfully queued, error code otherwise. 1981 * Return: 0 if the request was successfully queued, error code otherwise.
1972 * The caller has no way to know whether the queued request will eventually 1982 * The caller has no way to know whether the queued request will eventually
1973 * succeed. 1983 * succeed.
1974 */ 1984 */
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 16927fa88fbd..c12bc790a6a7 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -7,6 +7,7 @@
7#include <linux/usb.h> 7#include <linux/usb.h>
8#include <linux/wait.h> 8#include <linux/wait.h>
9#include <linux/usb/hcd.h> 9#include <linux/usb/hcd.h>
10#include <linux/scatterlist.h>
10 11
11#define to_urb(d) container_of(d, struct urb, kref) 12#define to_urb(d) container_of(d, struct urb, kref)
12 13
@@ -54,12 +55,12 @@ EXPORT_SYMBOL_GPL(usb_init_urb);
54 * Creates an urb for the USB driver to use, initializes a few internal 55 * Creates an urb for the USB driver to use, initializes a few internal
55 * structures, incrementes the usage counter, and returns a pointer to it. 56 * structures, incrementes the usage counter, and returns a pointer to it.
56 * 57 *
57 * If no memory is available, NULL is returned.
58 *
59 * If the driver want to use this urb for interrupt, control, or bulk 58 * If the driver want to use this urb for interrupt, control, or bulk
60 * endpoints, pass '0' as the number of iso packets. 59 * endpoints, pass '0' as the number of iso packets.
61 * 60 *
62 * The driver must call usb_free_urb() when it is finished with the urb. 61 * The driver must call usb_free_urb() when it is finished with the urb.
62 *
63 * Return: A pointer to the new urb, or %NULL if no memory is available.
63 */ 64 */
64struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags) 65struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags)
65{ 66{
@@ -102,7 +103,7 @@ EXPORT_SYMBOL_GPL(usb_free_urb);
102 * host controller driver. This allows proper reference counting to happen 103 * host controller driver. This allows proper reference counting to happen
103 * for urbs. 104 * for urbs.
104 * 105 *
105 * A pointer to the urb with the incremented reference counter is returned. 106 * Return: A pointer to the urb with the incremented reference counter.
106 */ 107 */
107struct urb *usb_get_urb(struct urb *urb) 108struct urb *usb_get_urb(struct urb *urb)
108{ 109{
@@ -199,13 +200,12 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb);
199 * the particular kind of transfer, although they will not initialize 200 * the particular kind of transfer, although they will not initialize
200 * any transfer flags. 201 * any transfer flags.
201 * 202 *
202 * Successful submissions return 0; otherwise this routine returns a 203 * If the submission is successful, the complete() callback from the URB
203 * negative error number. If the submission is successful, the complete() 204 * will be called exactly once, when the USB core and Host Controller Driver
204 * callback from the URB will be called exactly once, when the USB core and 205 * (HCD) are finished with the URB. When the completion function is called,
205 * Host Controller Driver (HCD) are finished with the URB. When the completion 206 * control of the URB is returned to the device driver which issued the
206 * function is called, control of the URB is returned to the device 207 * request. The completion handler may then immediately free or reuse that
207 * driver which issued the request. The completion handler may then 208 * URB.
208 * immediately free or reuse that URB.
209 * 209 *
210 * With few exceptions, USB device drivers should never access URB fields 210 * With few exceptions, USB device drivers should never access URB fields
211 * provided by usbcore or the HCD until its complete() is called. 211 * provided by usbcore or the HCD until its complete() is called.
@@ -240,6 +240,9 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb);
240 * that are standardized in the USB 2.0 specification. For bulk 240 * that are standardized in the USB 2.0 specification. For bulk
241 * endpoints, a synchronous usb_bulk_msg() call is available. 241 * endpoints, a synchronous usb_bulk_msg() call is available.
242 * 242 *
243 * Return:
244 * 0 on successful submissions. A negative error number otherwise.
245 *
243 * Request Queuing: 246 * Request Queuing:
244 * 247 *
245 * URBs may be submitted to endpoints before previous ones complete, to 248 * URBs may be submitted to endpoints before previous ones complete, to
@@ -413,6 +416,14 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
413 urb->iso_frame_desc[n].status = -EXDEV; 416 urb->iso_frame_desc[n].status = -EXDEV;
414 urb->iso_frame_desc[n].actual_length = 0; 417 urb->iso_frame_desc[n].actual_length = 0;
415 } 418 }
419 } else if (urb->num_sgs && !urb->dev->bus->no_sg_constraint &&
420 dev->speed != USB_SPEED_WIRELESS) {
421 struct scatterlist *sg;
422 int i;
423
424 for_each_sg(urb->sg, sg, urb->num_sgs - 1, i)
425 if (sg->length % max)
426 return -EINVAL;
416 } 427 }
417 428
418 /* the I/O buffer must be mapped/unmapped, except when length=0 */ 429 /* the I/O buffer must be mapped/unmapped, except when length=0 */
@@ -564,6 +575,9 @@ EXPORT_SYMBOL_GPL(usb_submit_urb);
564 * particular, when a driver calls this routine, it must insure that the 575 * particular, when a driver calls this routine, it must insure that the
565 * completion handler cannot deallocate the URB. 576 * completion handler cannot deallocate the URB.
566 * 577 *
578 * Return: -EINPROGRESS on success. See description for other values on
579 * failure.
580 *
567 * Unlinking and Endpoint Queues: 581 * Unlinking and Endpoint Queues:
568 * 582 *
569 * [The behaviors and guarantees described below do not apply to virtual 583 * [The behaviors and guarantees described below do not apply to virtual
@@ -838,6 +852,8 @@ EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs);
838 * 852 *
839 * Call this is you want to be sure all an anchor's 853 * Call this is you want to be sure all an anchor's
840 * URBs have finished 854 * URBs have finished
855 *
856 * Return: Non-zero if the anchor became unused. Zero on timeout.
841 */ 857 */
842int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, 858int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor,
843 unsigned int timeout) 859 unsigned int timeout)
@@ -851,8 +867,11 @@ EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout);
851 * usb_get_from_anchor - get an anchor's oldest urb 867 * usb_get_from_anchor - get an anchor's oldest urb
852 * @anchor: the anchor whose urb you want 868 * @anchor: the anchor whose urb you want
853 * 869 *
854 * this will take the oldest urb from an anchor, 870 * This will take the oldest urb from an anchor,
855 * unanchor and return it 871 * unanchor and return it
872 *
873 * Return: The oldest urb from @anchor, or %NULL if @anchor has no
874 * urbs associated with it.
856 */ 875 */
857struct urb *usb_get_from_anchor(struct usb_anchor *anchor) 876struct urb *usb_get_from_anchor(struct usb_anchor *anchor)
858{ 877{
@@ -901,7 +920,7 @@ EXPORT_SYMBOL_GPL(usb_scuttle_anchored_urbs);
901 * usb_anchor_empty - is an anchor empty 920 * usb_anchor_empty - is an anchor empty
902 * @anchor: the anchor you want to query 921 * @anchor: the anchor you want to query
903 * 922 *
904 * returns 1 if the anchor has no urbs associated with it 923 * Return: 1 if the anchor has no urbs associated with it.
905 */ 924 */
906int usb_anchor_empty(struct usb_anchor *anchor) 925int usb_anchor_empty(struct usb_anchor *anchor)
907{ 926{
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 7dad603dde43..0a6ee2e70b25 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -68,6 +68,8 @@ MODULE_PARM_DESC(autosuspend, "default autosuspend delay");
68 * @alt_num: alternate interface setting number to search for. 68 * @alt_num: alternate interface setting number to search for.
69 * 69 *
70 * Search the configuration's interface cache for the given alt setting. 70 * Search the configuration's interface cache for the given alt setting.
71 *
72 * Return: The alternate setting, if found. %NULL otherwise.
71 */ 73 */
72struct usb_host_interface *usb_find_alt_setting( 74struct usb_host_interface *usb_find_alt_setting(
73 struct usb_host_config *config, 75 struct usb_host_config *config,
@@ -103,8 +105,7 @@ EXPORT_SYMBOL_GPL(usb_find_alt_setting);
103 * @ifnum: the desired interface 105 * @ifnum: the desired interface
104 * 106 *
105 * This walks the device descriptor for the currently active configuration 107 * This walks the device descriptor for the currently active configuration
106 * and returns a pointer to the interface with that particular interface 108 * to find the interface object with the particular interface number.
107 * number, or null.
108 * 109 *
109 * Note that configuration descriptors are not required to assign interface 110 * Note that configuration descriptors are not required to assign interface
110 * numbers sequentially, so that it would be incorrect to assume that 111 * numbers sequentially, so that it would be incorrect to assume that
@@ -115,6 +116,9 @@ EXPORT_SYMBOL_GPL(usb_find_alt_setting);
115 * 116 *
116 * Don't call this function unless you are bound to one of the interfaces 117 * Don't call this function unless you are bound to one of the interfaces
117 * on this device or you have locked the device! 118 * on this device or you have locked the device!
119 *
120 * Return: A pointer to the interface that has @ifnum as interface number,
121 * if found. %NULL otherwise.
118 */ 122 */
119struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev, 123struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev,
120 unsigned ifnum) 124 unsigned ifnum)
@@ -139,8 +143,7 @@ EXPORT_SYMBOL_GPL(usb_ifnum_to_if);
139 * @altnum: the desired alternate setting number 143 * @altnum: the desired alternate setting number
140 * 144 *
141 * This searches the altsetting array of the specified interface for 145 * This searches the altsetting array of the specified interface for
142 * an entry with the correct bAlternateSetting value and returns a pointer 146 * an entry with the correct bAlternateSetting value.
143 * to that entry, or null.
144 * 147 *
145 * Note that altsettings need not be stored sequentially by number, so 148 * Note that altsettings need not be stored sequentially by number, so
146 * it would be incorrect to assume that the first altsetting entry in 149 * it would be incorrect to assume that the first altsetting entry in
@@ -149,6 +152,9 @@ EXPORT_SYMBOL_GPL(usb_ifnum_to_if);
149 * 152 *
150 * Don't call this function unless you are bound to the intf interface 153 * Don't call this function unless you are bound to the intf interface
151 * or you have locked the device! 154 * or you have locked the device!
155 *
156 * Return: A pointer to the entry of the altsetting array of @intf that
157 * has @altnum as the alternate setting number. %NULL if not found.
152 */ 158 */
153struct usb_host_interface *usb_altnum_to_altsetting( 159struct usb_host_interface *usb_altnum_to_altsetting(
154 const struct usb_interface *intf, 160 const struct usb_interface *intf,
@@ -191,6 +197,8 @@ static int __find_interface(struct device *dev, void *data)
191 * This walks the bus device list and returns a pointer to the interface 197 * This walks the bus device list and returns a pointer to the interface
192 * with the matching minor and driver. Note, this only works for devices 198 * with the matching minor and driver. Note, this only works for devices
193 * that share the USB major number. 199 * that share the USB major number.
200 *
201 * Return: A pointer to the interface with the matching major and @minor.
194 */ 202 */
195struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) 203struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
196{ 204{
@@ -390,6 +398,9 @@ static unsigned usb_bus_is_wusb(struct usb_bus *bus)
390 * controllers) should ever call this. 398 * controllers) should ever call this.
391 * 399 *
392 * This call may not be used in a non-sleeping context. 400 * This call may not be used in a non-sleeping context.
401 *
402 * Return: On success, a pointer to the allocated usb device. %NULL on
403 * failure.
393 */ 404 */
394struct usb_device *usb_alloc_dev(struct usb_device *parent, 405struct usb_device *usb_alloc_dev(struct usb_device *parent,
395 struct usb_bus *bus, unsigned port1) 406 struct usb_bus *bus, unsigned port1)
@@ -501,7 +512,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
501 * their probe() methods, when they bind to an interface, and release 512 * their probe() methods, when they bind to an interface, and release
502 * them by calling usb_put_dev(), in their disconnect() methods. 513 * them by calling usb_put_dev(), in their disconnect() methods.
503 * 514 *
504 * A pointer to the device with the incremented reference counter is returned. 515 * Return: A pointer to the device with the incremented reference counter.
505 */ 516 */
506struct usb_device *usb_get_dev(struct usb_device *dev) 517struct usb_device *usb_get_dev(struct usb_device *dev)
507{ 518{
@@ -535,8 +546,7 @@ EXPORT_SYMBOL_GPL(usb_put_dev);
535 * their probe() methods, when they bind to an interface, and release 546 * their probe() methods, when they bind to an interface, and release
536 * them by calling usb_put_intf(), in their disconnect() methods. 547 * them by calling usb_put_intf(), in their disconnect() methods.
537 * 548 *
538 * A pointer to the interface with the incremented reference counter is 549 * Return: A pointer to the interface with the incremented reference counter.
539 * returned.
540 */ 550 */
541struct usb_interface *usb_get_intf(struct usb_interface *intf) 551struct usb_interface *usb_get_intf(struct usb_interface *intf)
542{ 552{
@@ -589,7 +599,7 @@ EXPORT_SYMBOL_GPL(usb_put_intf);
589 * disconnect; in some drivers (such as usb-storage) the disconnect() 599 * disconnect; in some drivers (such as usb-storage) the disconnect()
590 * or suspend() method will block waiting for a device reset to complete. 600 * or suspend() method will block waiting for a device reset to complete.
591 * 601 *
592 * Returns a negative error code for failure, otherwise 0. 602 * Return: A negative error code for failure, otherwise 0.
593 */ 603 */
594int usb_lock_device_for_reset(struct usb_device *udev, 604int usb_lock_device_for_reset(struct usb_device *udev,
595 const struct usb_interface *iface) 605 const struct usb_interface *iface)
@@ -628,14 +638,15 @@ EXPORT_SYMBOL_GPL(usb_lock_device_for_reset);
628 * usb_get_current_frame_number - return current bus frame number 638 * usb_get_current_frame_number - return current bus frame number
629 * @dev: the device whose bus is being queried 639 * @dev: the device whose bus is being queried
630 * 640 *
631 * Returns the current frame number for the USB host controller 641 * Return: The current frame number for the USB host controller used
632 * used with the given USB device. This can be used when scheduling 642 * with the given USB device. This can be used when scheduling
633 * isochronous requests. 643 * isochronous requests.
634 * 644 *
635 * Note that different kinds of host controller have different 645 * Note: Different kinds of host controller have different "scheduling
636 * "scheduling horizons". While one type might support scheduling only 646 * horizons". While one type might support scheduling only 32 frames
637 * 32 frames into the future, others could support scheduling up to 647 * into the future, others could support scheduling up to 1024 frames
638 * 1024 frames into the future. 648 * into the future.
649 *
639 */ 650 */
640int usb_get_current_frame_number(struct usb_device *dev) 651int usb_get_current_frame_number(struct usb_device *dev)
641{ 652{
@@ -685,11 +696,12 @@ EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor);
685 * @mem_flags: affect whether allocation may block 696 * @mem_flags: affect whether allocation may block
686 * @dma: used to return DMA address of buffer 697 * @dma: used to return DMA address of buffer
687 * 698 *
688 * Return value is either null (indicating no buffer could be allocated), or 699 * Return: Either null (indicating no buffer could be allocated), or the
689 * the cpu-space pointer to a buffer that may be used to perform DMA to the 700 * cpu-space pointer to a buffer that may be used to perform DMA to the
690 * specified device. Such cpu-space buffers are returned along with the DMA 701 * specified device. Such cpu-space buffers are returned along with the DMA
691 * address (through the pointer provided). 702 * address (through the pointer provided).
692 * 703 *
704 * Note:
693 * These buffers are used with URB_NO_xxx_DMA_MAP set in urb->transfer_flags 705 * These buffers are used with URB_NO_xxx_DMA_MAP set in urb->transfer_flags
694 * to avoid behaviors like using "DMA bounce buffers", or thrashing IOMMU 706 * to avoid behaviors like using "DMA bounce buffers", or thrashing IOMMU
695 * hardware during URB completion/resubmit. The implementation varies between 707 * hardware during URB completion/resubmit. The implementation varies between
@@ -735,17 +747,18 @@ EXPORT_SYMBOL_GPL(usb_free_coherent);
735 * usb_buffer_map - create DMA mapping(s) for an urb 747 * usb_buffer_map - create DMA mapping(s) for an urb
736 * @urb: urb whose transfer_buffer/setup_packet will be mapped 748 * @urb: urb whose transfer_buffer/setup_packet will be mapped
737 * 749 *
738 * Return value is either null (indicating no buffer could be mapped), or 750 * URB_NO_TRANSFER_DMA_MAP is added to urb->transfer_flags if the operation
739 * the parameter. URB_NO_TRANSFER_DMA_MAP is 751 * succeeds. If the device is connected to this system through a non-DMA
740 * added to urb->transfer_flags if the operation succeeds. If the device 752 * controller, this operation always succeeds.
741 * is connected to this system through a non-DMA controller, this operation
742 * always succeeds.
743 * 753 *
744 * This call would normally be used for an urb which is reused, perhaps 754 * This call would normally be used for an urb which is reused, perhaps
745 * as the target of a large periodic transfer, with usb_buffer_dmasync() 755 * as the target of a large periodic transfer, with usb_buffer_dmasync()
746 * calls to synchronize memory and dma state. 756 * calls to synchronize memory and dma state.
747 * 757 *
748 * Reverse the effect of this call with usb_buffer_unmap(). 758 * Reverse the effect of this call with usb_buffer_unmap().
759 *
760 * Return: Either %NULL (indicating no buffer could be mapped), or @urb.
761 *
749 */ 762 */
750#if 0 763#if 0
751struct urb *usb_buffer_map(struct urb *urb) 764struct urb *usb_buffer_map(struct urb *urb)
@@ -850,9 +863,10 @@ EXPORT_SYMBOL_GPL(usb_buffer_unmap);
850 * @sg: the scatterlist to map 863 * @sg: the scatterlist to map
851 * @nents: the number of entries in the scatterlist 864 * @nents: the number of entries in the scatterlist
852 * 865 *
853 * Return value is either < 0 (indicating no buffers could be mapped), or 866 * Return: Either < 0 (indicating no buffers could be mapped), or the
854 * the number of DMA mapping array entries in the scatterlist. 867 * number of DMA mapping array entries in the scatterlist.
855 * 868 *
869 * Note:
856 * The caller is responsible for placing the resulting DMA addresses from 870 * The caller is responsible for placing the resulting DMA addresses from
857 * the scatterlist into URB transfer buffer pointers, and for setting the 871 * the scatterlist into URB transfer buffer pointers, and for setting the
858 * URB_NO_TRANSFER_DMA_MAP transfer flag in each of those URBs. 872 * URB_NO_TRANSFER_DMA_MAP transfer flag in each of those URBs.
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 2378958ea63e..3e225d5846f6 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -40,6 +40,38 @@ config USB_DWC3_DUAL_ROLE
40 40
41endchoice 41endchoice
42 42
43comment "Platform Glue Driver Support"
44
45config USB_DWC3_OMAP
46 tristate "Texas Instruments OMAP5 and similar Platforms"
47 depends on EXTCON
48 default USB_DWC3
49 help
50 Some platforms from Texas Instruments like OMAP5, DRA7xxx and
51 AM437x use this IP for USB2/3 functionality.
52
53 Say 'Y' or 'M' here if you have one such device
54
55config USB_DWC3_EXYNOS
56 tristate "Samsung Exynos Platform"
57 default USB_DWC3
58 help
59 Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside,
60 say 'Y' or 'M' if you have one such device.
61
62config USB_DWC3_PCI
63 tristate "PCIe-based Platforms"
64 depends on PCI
65 default USB_DWC3
66 help
67 If you're using the DesignWare Core IP with a PCIe, please say
68 'Y' or 'M' here.
69
70 One such PCIe-based platform is Synopsys' PCIe HAPS model of
71 this IP.
72
73comment "Debugging features"
74
43config USB_DWC3_DEBUG 75config USB_DWC3_DEBUG
44 bool "Enable Debugging Messages" 76 bool "Enable Debugging Messages"
45 help 77 help
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 0c7ac92582be..dd1760145c46 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -27,15 +27,8 @@ endif
27# the entire driver (with all its glue layers) on several architectures 27# the entire driver (with all its glue layers) on several architectures
28# and make sure it compiles fine. This will also help with allmodconfig 28# and make sure it compiles fine. This will also help with allmodconfig
29# and allyesconfig builds. 29# and allyesconfig builds.
30#
31# The only exception is the PCI glue layer, but that's only because
32# PCI doesn't provide nops if CONFIG_PCI isn't enabled.
33## 30##
34 31
35obj-$(CONFIG_USB_DWC3) += dwc3-omap.o 32obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o
36obj-$(CONFIG_USB_DWC3) += dwc3-exynos.o 33obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o
37 34obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o
38ifneq ($(CONFIG_PCI),)
39 obj-$(CONFIG_USB_DWC3) += dwc3-pci.o
40endif
41
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 358375e0b291..577af1b237f2 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -6,34 +6,17 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
25 * 17 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 18 * You should have received a copy of the GNU General Public License
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 20 */
38 21
39#include <linux/module.h> 22#include <linux/module.h>
@@ -53,17 +36,16 @@
53#include <linux/usb/otg.h> 36#include <linux/usb/otg.h>
54#include <linux/usb/ch9.h> 37#include <linux/usb/ch9.h>
55#include <linux/usb/gadget.h> 38#include <linux/usb/gadget.h>
39#include <linux/usb/of.h>
40#include <linux/usb/otg.h>
56 41
42#include "platform_data.h"
57#include "core.h" 43#include "core.h"
58#include "gadget.h" 44#include "gadget.h"
59#include "io.h" 45#include "io.h"
60 46
61#include "debug.h" 47#include "debug.h"
62 48
63static char *maximum_speed = "super";
64module_param(maximum_speed, charp, 0);
65MODULE_PARM_DESC(maximum_speed, "Maximum supported speed.");
66
67/* -------------------------------------------------------------------------- */ 49/* -------------------------------------------------------------------------- */
68 50
69void dwc3_set_mode(struct dwc3 *dwc, u32 mode) 51void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
@@ -236,7 +218,7 @@ static int dwc3_event_buffers_setup(struct dwc3 *dwc)
236 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 218 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
237 upper_32_bits(evt->dma)); 219 upper_32_bits(evt->dma));
238 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), 220 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
239 evt->length & 0xffff); 221 DWC3_GEVNTSIZ_SIZE(evt->length));
240 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0); 222 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
241 } 223 }
242 224
@@ -255,7 +237,8 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
255 237
256 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0); 238 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
257 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0); 239 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
258 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), 0); 240 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), DWC3_GEVNTSIZ_INTMASK
241 | DWC3_GEVNTSIZ_SIZE(0));
259 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0); 242 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
260 } 243 }
261} 244}
@@ -367,18 +350,17 @@ static void dwc3_core_exit(struct dwc3 *dwc)
367 350
368static int dwc3_probe(struct platform_device *pdev) 351static int dwc3_probe(struct platform_device *pdev)
369{ 352{
370 struct device_node *node = pdev->dev.of_node; 353 struct device *dev = &pdev->dev;
354 struct dwc3_platform_data *pdata = dev_get_platdata(dev);
355 struct device_node *node = dev->of_node;
371 struct resource *res; 356 struct resource *res;
372 struct dwc3 *dwc; 357 struct dwc3 *dwc;
373 struct device *dev = &pdev->dev;
374 358
375 int ret = -ENOMEM; 359 int ret = -ENOMEM;
376 360
377 void __iomem *regs; 361 void __iomem *regs;
378 void *mem; 362 void *mem;
379 363
380 u8 mode;
381
382 mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); 364 mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
383 if (!mem) { 365 if (!mem) {
384 dev_err(dev, "not enough memory\n"); 366 dev_err(dev, "not enough memory\n");
@@ -402,38 +384,32 @@ static int dwc3_probe(struct platform_device *pdev)
402 dev_err(dev, "missing memory resource\n"); 384 dev_err(dev, "missing memory resource\n");
403 return -ENODEV; 385 return -ENODEV;
404 } 386 }
405 dwc->xhci_resources[0].start = res->start;
406 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
407 DWC3_XHCI_REGS_END;
408 dwc->xhci_resources[0].flags = res->flags;
409 dwc->xhci_resources[0].name = res->name;
410
411 /*
412 * Request memory region but exclude xHCI regs,
413 * since it will be requested by the xhci-plat driver.
414 */
415 res = devm_request_mem_region(dev, res->start + DWC3_GLOBALS_REGS_START,
416 resource_size(res) - DWC3_GLOBALS_REGS_START,
417 dev_name(dev));
418 if (!res) {
419 dev_err(dev, "can't request mem region\n");
420 return -ENOMEM;
421 }
422
423 regs = devm_ioremap_nocache(dev, res->start, resource_size(res));
424 if (!regs) {
425 dev_err(dev, "ioremap failed\n");
426 return -ENOMEM;
427 }
428 387
429 if (node) { 388 if (node) {
389 dwc->maximum_speed = of_usb_get_maximum_speed(node);
390
430 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); 391 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
431 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); 392 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
393
394 dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
395 dwc->dr_mode = of_usb_get_dr_mode(node);
396 } else if (pdata) {
397 dwc->maximum_speed = pdata->maximum_speed;
398
399 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
400 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
401
402 dwc->needs_fifo_resize = pdata->tx_fifo_resize;
403 dwc->dr_mode = pdata->dr_mode;
432 } else { 404 } else {
433 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 405 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
434 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); 406 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
435 } 407 }
436 408
409 /* default to superspeed if no maximum_speed passed */
410 if (dwc->maximum_speed == USB_SPEED_UNKNOWN)
411 dwc->maximum_speed = USB_SPEED_SUPER;
412
437 if (IS_ERR(dwc->usb2_phy)) { 413 if (IS_ERR(dwc->usb2_phy)) {
438 ret = PTR_ERR(dwc->usb2_phy); 414 ret = PTR_ERR(dwc->usb2_phy);
439 415
@@ -464,6 +440,22 @@ static int dwc3_probe(struct platform_device *pdev)
464 return -EPROBE_DEFER; 440 return -EPROBE_DEFER;
465 } 441 }
466 442
443 dwc->xhci_resources[0].start = res->start;
444 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
445 DWC3_XHCI_REGS_END;
446 dwc->xhci_resources[0].flags = res->flags;
447 dwc->xhci_resources[0].name = res->name;
448
449 res->start += DWC3_GLOBALS_REGS_START;
450
451 /*
452 * Request memory region but exclude xHCI regs,
453 * since it will be requested by the xhci-plat driver.
454 */
455 regs = devm_ioremap_resource(dev, res);
456 if (IS_ERR(regs))
457 return PTR_ERR(regs);
458
467 usb_phy_set_suspend(dwc->usb2_phy, 0); 459 usb_phy_set_suspend(dwc->usb2_phy, 0);
468 usb_phy_set_suspend(dwc->usb3_phy, 0); 460 usb_phy_set_suspend(dwc->usb3_phy, 0);
469 461
@@ -478,19 +470,6 @@ static int dwc3_probe(struct platform_device *pdev)
478 dev->dma_parms = dev->parent->dma_parms; 470 dev->dma_parms = dev->parent->dma_parms;
479 dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); 471 dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
480 472
481 if (!strncmp("super", maximum_speed, 5))
482 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
483 else if (!strncmp("high", maximum_speed, 4))
484 dwc->maximum_speed = DWC3_DCFG_HIGHSPEED;
485 else if (!strncmp("full", maximum_speed, 4))
486 dwc->maximum_speed = DWC3_DCFG_FULLSPEED1;
487 else if (!strncmp("low", maximum_speed, 3))
488 dwc->maximum_speed = DWC3_DCFG_LOWSPEED;
489 else
490 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
491
492 dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
493
494 pm_runtime_enable(dev); 473 pm_runtime_enable(dev);
495 pm_runtime_get_sync(dev); 474 pm_runtime_get_sync(dev);
496 pm_runtime_forbid(dev); 475 pm_runtime_forbid(dev);
@@ -517,14 +496,15 @@ static int dwc3_probe(struct platform_device *pdev)
517 } 496 }
518 497
519 if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) 498 if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
520 mode = DWC3_MODE_HOST; 499 dwc->dr_mode = USB_DR_MODE_HOST;
521 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) 500 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
522 mode = DWC3_MODE_DEVICE; 501 dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
523 else 502
524 mode = DWC3_MODE_DRD; 503 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
504 dwc->dr_mode = USB_DR_MODE_OTG;
525 505
526 switch (mode) { 506 switch (dwc->dr_mode) {
527 case DWC3_MODE_DEVICE: 507 case USB_DR_MODE_PERIPHERAL:
528 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); 508 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
529 ret = dwc3_gadget_init(dwc); 509 ret = dwc3_gadget_init(dwc);
530 if (ret) { 510 if (ret) {
@@ -532,7 +512,7 @@ static int dwc3_probe(struct platform_device *pdev)
532 goto err2; 512 goto err2;
533 } 513 }
534 break; 514 break;
535 case DWC3_MODE_HOST: 515 case USB_DR_MODE_HOST:
536 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); 516 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
537 ret = dwc3_host_init(dwc); 517 ret = dwc3_host_init(dwc);
538 if (ret) { 518 if (ret) {
@@ -540,7 +520,7 @@ static int dwc3_probe(struct platform_device *pdev)
540 goto err2; 520 goto err2;
541 } 521 }
542 break; 522 break;
543 case DWC3_MODE_DRD: 523 case USB_DR_MODE_OTG:
544 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); 524 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
545 ret = dwc3_host_init(dwc); 525 ret = dwc3_host_init(dwc);
546 if (ret) { 526 if (ret) {
@@ -555,10 +535,9 @@ static int dwc3_probe(struct platform_device *pdev)
555 } 535 }
556 break; 536 break;
557 default: 537 default:
558 dev_err(dev, "Unsupported mode of operation %d\n", mode); 538 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
559 goto err2; 539 goto err2;
560 } 540 }
561 dwc->mode = mode;
562 541
563 ret = dwc3_debugfs_init(dwc); 542 ret = dwc3_debugfs_init(dwc);
564 if (ret) { 543 if (ret) {
@@ -571,14 +550,14 @@ static int dwc3_probe(struct platform_device *pdev)
571 return 0; 550 return 0;
572 551
573err3: 552err3:
574 switch (mode) { 553 switch (dwc->dr_mode) {
575 case DWC3_MODE_DEVICE: 554 case USB_DR_MODE_PERIPHERAL:
576 dwc3_gadget_exit(dwc); 555 dwc3_gadget_exit(dwc);
577 break; 556 break;
578 case DWC3_MODE_HOST: 557 case USB_DR_MODE_HOST:
579 dwc3_host_exit(dwc); 558 dwc3_host_exit(dwc);
580 break; 559 break;
581 case DWC3_MODE_DRD: 560 case USB_DR_MODE_OTG:
582 dwc3_host_exit(dwc); 561 dwc3_host_exit(dwc);
583 dwc3_gadget_exit(dwc); 562 dwc3_gadget_exit(dwc);
584 break; 563 break;
@@ -611,14 +590,14 @@ static int dwc3_remove(struct platform_device *pdev)
611 590
612 dwc3_debugfs_exit(dwc); 591 dwc3_debugfs_exit(dwc);
613 592
614 switch (dwc->mode) { 593 switch (dwc->dr_mode) {
615 case DWC3_MODE_DEVICE: 594 case USB_DR_MODE_PERIPHERAL:
616 dwc3_gadget_exit(dwc); 595 dwc3_gadget_exit(dwc);
617 break; 596 break;
618 case DWC3_MODE_HOST: 597 case USB_DR_MODE_HOST:
619 dwc3_host_exit(dwc); 598 dwc3_host_exit(dwc);
620 break; 599 break;
621 case DWC3_MODE_DRD: 600 case USB_DR_MODE_OTG:
622 dwc3_host_exit(dwc); 601 dwc3_host_exit(dwc);
623 dwc3_gadget_exit(dwc); 602 dwc3_gadget_exit(dwc);
624 break; 603 break;
@@ -642,12 +621,12 @@ static int dwc3_prepare(struct device *dev)
642 621
643 spin_lock_irqsave(&dwc->lock, flags); 622 spin_lock_irqsave(&dwc->lock, flags);
644 623
645 switch (dwc->mode) { 624 switch (dwc->dr_mode) {
646 case DWC3_MODE_DEVICE: 625 case USB_DR_MODE_PERIPHERAL:
647 case DWC3_MODE_DRD: 626 case USB_DR_MODE_OTG:
648 dwc3_gadget_prepare(dwc); 627 dwc3_gadget_prepare(dwc);
649 /* FALLTHROUGH */ 628 /* FALLTHROUGH */
650 case DWC3_MODE_HOST: 629 case USB_DR_MODE_HOST:
651 default: 630 default:
652 dwc3_event_buffers_cleanup(dwc); 631 dwc3_event_buffers_cleanup(dwc);
653 break; 632 break;
@@ -665,12 +644,12 @@ static void dwc3_complete(struct device *dev)
665 644
666 spin_lock_irqsave(&dwc->lock, flags); 645 spin_lock_irqsave(&dwc->lock, flags);
667 646
668 switch (dwc->mode) { 647 switch (dwc->dr_mode) {
669 case DWC3_MODE_DEVICE: 648 case USB_DR_MODE_PERIPHERAL:
670 case DWC3_MODE_DRD: 649 case USB_DR_MODE_OTG:
671 dwc3_gadget_complete(dwc); 650 dwc3_gadget_complete(dwc);
672 /* FALLTHROUGH */ 651 /* FALLTHROUGH */
673 case DWC3_MODE_HOST: 652 case USB_DR_MODE_HOST:
674 default: 653 default:
675 dwc3_event_buffers_setup(dwc); 654 dwc3_event_buffers_setup(dwc);
676 break; 655 break;
@@ -686,12 +665,12 @@ static int dwc3_suspend(struct device *dev)
686 665
687 spin_lock_irqsave(&dwc->lock, flags); 666 spin_lock_irqsave(&dwc->lock, flags);
688 667
689 switch (dwc->mode) { 668 switch (dwc->dr_mode) {
690 case DWC3_MODE_DEVICE: 669 case USB_DR_MODE_PERIPHERAL:
691 case DWC3_MODE_DRD: 670 case USB_DR_MODE_OTG:
692 dwc3_gadget_suspend(dwc); 671 dwc3_gadget_suspend(dwc);
693 /* FALLTHROUGH */ 672 /* FALLTHROUGH */
694 case DWC3_MODE_HOST: 673 case USB_DR_MODE_HOST:
695 default: 674 default:
696 /* do nothing */ 675 /* do nothing */
697 break; 676 break;
@@ -719,12 +698,12 @@ static int dwc3_resume(struct device *dev)
719 698
720 dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl); 699 dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
721 700
722 switch (dwc->mode) { 701 switch (dwc->dr_mode) {
723 case DWC3_MODE_DEVICE: 702 case USB_DR_MODE_PERIPHERAL:
724 case DWC3_MODE_DRD: 703 case USB_DR_MODE_OTG:
725 dwc3_gadget_resume(dwc); 704 dwc3_gadget_resume(dwc);
726 /* FALLTHROUGH */ 705 /* FALLTHROUGH */
727 case DWC3_MODE_HOST: 706 case USB_DR_MODE_HOST:
728 default: 707 default:
729 /* do nothing */ 708 /* do nothing */
730 break; 709 break;
@@ -754,6 +733,9 @@ static const struct dev_pm_ops dwc3_dev_pm_ops = {
754#ifdef CONFIG_OF 733#ifdef CONFIG_OF
755static const struct of_device_id of_dwc3_match[] = { 734static const struct of_device_id of_dwc3_match[] = {
756 { 735 {
736 .compatible = "snps,dwc3"
737 },
738 {
757 .compatible = "synopsys,dwc3" 739 .compatible = "synopsys,dwc3"
758 }, 740 },
759 { }, 741 { },
@@ -775,5 +757,5 @@ module_platform_driver(dwc3_driver);
775 757
776MODULE_ALIAS("platform:dwc3"); 758MODULE_ALIAS("platform:dwc3");
777MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 759MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
778MODULE_LICENSE("Dual BSD/GPL"); 760MODULE_LICENSE("GPL v2");
779MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); 761MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 27dad993b007..f8af8d44af85 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -6,34 +6,14 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * 16 * GNU General Public License for more details.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 17 */
38 18
39#ifndef __DRIVERS_USB_DWC3_CORE_H 19#ifndef __DRIVERS_USB_DWC3_CORE_H
@@ -49,6 +29,7 @@
49 29
50#include <linux/usb/ch9.h> 30#include <linux/usb/ch9.h>
51#include <linux/usb/gadget.h> 31#include <linux/usb/gadget.h>
32#include <linux/usb/otg.h>
52 33
53/* Global constants */ 34/* Global constants */
54#define DWC3_EP0_BOUNCE_SIZE 512 35#define DWC3_EP0_BOUNCE_SIZE 512
@@ -194,6 +175,10 @@
194#define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff) 175#define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff)
195#define DWC3_GTXFIFOSIZ_TXFSTADDR(n) ((n) & 0xffff0000) 176#define DWC3_GTXFIFOSIZ_TXFSTADDR(n) ((n) & 0xffff0000)
196 177
178/* Global Event Size Registers */
179#define DWC3_GEVNTSIZ_INTMASK (1 << 31)
180#define DWC3_GEVNTSIZ_SIZE(n) ((n) & 0xffff)
181
197/* Global HWPARAMS1 Register */ 182/* Global HWPARAMS1 Register */
198#define DWC3_GHWPARAMS1_EN_PWROPT(n) (((n) & (3 << 24)) >> 24) 183#define DWC3_GHWPARAMS1_EN_PWROPT(n) (((n) & (3 << 24)) >> 24)
199#define DWC3_GHWPARAMS1_EN_PWROPT_NO 0 184#define DWC3_GHWPARAMS1_EN_PWROPT_NO 0
@@ -207,7 +192,6 @@
207#define DWC3_MAX_HIBER_SCRATCHBUFS 15 192#define DWC3_MAX_HIBER_SCRATCHBUFS 15
208 193
209/* Device Configuration Register */ 194/* Device Configuration Register */
210#define DWC3_DCFG_LPM_CAP (1 << 22)
211#define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) 195#define DWC3_DCFG_DEVADDR(addr) ((addr) << 3)
212#define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f) 196#define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f)
213 197
@@ -367,7 +351,6 @@ struct dwc3_trb;
367 351
368/** 352/**
369 * struct dwc3_event_buffer - Software event buffer representation 353 * struct dwc3_event_buffer - Software event buffer representation
370 * @list: a list of event buffers
371 * @buf: _THE_ buffer 354 * @buf: _THE_ buffer
372 * @length: size of this buffer 355 * @length: size of this buffer
373 * @lpos: event offset 356 * @lpos: event offset
@@ -415,7 +398,7 @@ struct dwc3_event_buffer {
415 * @number: endpoint number (1 - 15) 398 * @number: endpoint number (1 - 15)
416 * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK 399 * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
417 * @resource_index: Resource transfer index 400 * @resource_index: Resource transfer index
418 * @interval: the intervall on which the ISOC transfer is started 401 * @interval: the interval on which the ISOC transfer is started
419 * @name: a human readable name e.g. ep1out-bulk 402 * @name: a human readable name e.g. ep1out-bulk
420 * @direction: true for TX, false for RX 403 * @direction: true for TX, false for RX
421 * @stream_capable: true when streams are enabled 404 * @stream_capable: true when streams are enabled
@@ -566,11 +549,6 @@ struct dwc3_hwparams {
566/* HWPARAMS0 */ 549/* HWPARAMS0 */
567#define DWC3_MODE(n) ((n) & 0x7) 550#define DWC3_MODE(n) ((n) & 0x7)
568 551
569#define DWC3_MODE_DEVICE 0
570#define DWC3_MODE_HOST 1
571#define DWC3_MODE_DRD 2
572#define DWC3_MODE_HUB 3
573
574#define DWC3_MDWIDTH(n) (((n) & 0xff00) >> 8) 552#define DWC3_MDWIDTH(n) (((n) & 0xff00) >> 8)
575 553
576/* HWPARAMS1 */ 554/* HWPARAMS1 */
@@ -632,7 +610,7 @@ struct dwc3_scratchpad_array {
632 * @u1u2: only used on revisions <1.83a for workaround 610 * @u1u2: only used on revisions <1.83a for workaround
633 * @maximum_speed: maximum speed requested (mainly for testing purposes) 611 * @maximum_speed: maximum speed requested (mainly for testing purposes)
634 * @revision: revision register contents 612 * @revision: revision register contents
635 * @mode: mode of operation 613 * @dr_mode: requested mode of operation
636 * @usb2_phy: pointer to USB2 PHY 614 * @usb2_phy: pointer to USB2 PHY
637 * @usb3_phy: pointer to USB3 PHY 615 * @usb3_phy: pointer to USB3 PHY
638 * @dcfg: saved contents of DCFG register 616 * @dcfg: saved contents of DCFG register
@@ -690,6 +668,8 @@ struct dwc3 {
690 void __iomem *regs; 668 void __iomem *regs;
691 size_t regs_size; 669 size_t regs_size;
692 670
671 enum usb_dr_mode dr_mode;
672
693 /* used for suspend/resume */ 673 /* used for suspend/resume */
694 u32 dcfg; 674 u32 dcfg;
695 u32 gctl; 675 u32 gctl;
@@ -698,7 +678,6 @@ struct dwc3 {
698 u32 u1u2; 678 u32 u1u2;
699 u32 maximum_speed; 679 u32 maximum_speed;
700 u32 revision; 680 u32 revision;
701 u32 mode;
702 681
703#define DWC3_REVISION_173A 0x5533173a 682#define DWC3_REVISION_173A 0x5533173a
704#define DWC3_REVISION_175A 0x5533175a 683#define DWC3_REVISION_175A 0x5533175a
diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index 5894ee8222af..fceb39dc4bba 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -6,34 +6,14 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * 16 * GNU General Public License for more details.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 17 */
38 18
39#include "core.h" 19#include "core.h"
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 9e9f122162f2..9ac37fe1b6a7 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -6,34 +6,14 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * 16 * GNU General Public License for more details.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 17 */
38 18
39#include <linux/kernel.h> 19#include <linux/kernel.h>
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index 8ce9d7fd6cfc..2f2e88a3a11a 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -6,10 +6,14 @@
6 * 6 *
7 * Author: Anton Tikhomirov <av.tikhomirov@samsung.com> 7 * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
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
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License version 2 of
11 * the Free Software Foundation; either version 2 of the License, or 11 * the License as published by the Free Software Foundation.
12 * (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.
13 */ 17 */
14 18
15#include <linux/module.h> 19#include <linux/module.h>
@@ -20,7 +24,7 @@
20#include <linux/dma-mapping.h> 24#include <linux/dma-mapping.h>
21#include <linux/clk.h> 25#include <linux/clk.h>
22#include <linux/usb/otg.h> 26#include <linux/usb/otg.h>
23#include <linux/usb/nop-usb-xceiv.h> 27#include <linux/usb/usb_phy_gen_xceiv.h>
24#include <linux/of.h> 28#include <linux/of.h>
25#include <linux/of_platform.h> 29#include <linux/of_platform.h>
26 30
@@ -34,13 +38,13 @@ struct dwc3_exynos {
34 38
35static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos) 39static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
36{ 40{
37 struct nop_usb_xceiv_platform_data pdata; 41 struct usb_phy_gen_xceiv_platform_data pdata;
38 struct platform_device *pdev; 42 struct platform_device *pdev;
39 int ret; 43 int ret;
40 44
41 memset(&pdata, 0x00, sizeof(pdata)); 45 memset(&pdata, 0x00, sizeof(pdata));
42 46
43 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); 47 pdev = platform_device_alloc("usb_phy_gen_xceiv", PLATFORM_DEVID_AUTO);
44 if (!pdev) 48 if (!pdev)
45 return -ENOMEM; 49 return -ENOMEM;
46 50
@@ -51,7 +55,7 @@ static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
51 if (ret) 55 if (ret)
52 goto err1; 56 goto err1;
53 57
54 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); 58 pdev = platform_device_alloc("usb_phy_gen_xceiv", PLATFORM_DEVID_AUTO);
55 if (!pdev) { 59 if (!pdev) {
56 ret = -ENOMEM; 60 ret = -ENOMEM;
57 goto err1; 61 goto err1;
@@ -228,5 +232,5 @@ module_platform_driver(dwc3_exynos_driver);
228 232
229MODULE_ALIAS("platform:exynos-dwc3"); 233MODULE_ALIAS("platform:exynos-dwc3");
230MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>"); 234MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
231MODULE_LICENSE("GPL"); 235MODULE_LICENSE("GPL v2");
232MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer"); 236MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 077f110bd746..ecd99451ee90 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -6,34 +6,14 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * 16 * GNU General Public License for more details.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 17 */
38 18
39#include <linux/module.h> 19#include <linux/module.h>
@@ -409,11 +389,9 @@ static int dwc3_omap_probe(struct platform_device *pdev)
409 return -EINVAL; 389 return -EINVAL;
410 } 390 }
411 391
412 base = devm_ioremap_nocache(dev, res->start, resource_size(res)); 392 base = devm_ioremap_resource(dev, res);
413 if (!base) { 393 if (IS_ERR(base))
414 dev_err(dev, "ioremap failed\n"); 394 return PTR_ERR(base);
415 return -ENOMEM;
416 }
417 395
418 spin_lock_init(&omap->lock); 396 spin_lock_init(&omap->lock);
419 397
@@ -610,5 +588,5 @@ module_platform_driver(dwc3_omap_driver);
610 588
611MODULE_ALIAS("platform:omap-dwc3"); 589MODULE_ALIAS("platform:omap-dwc3");
612MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 590MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
613MODULE_LICENSE("Dual BSD/GPL"); 591MODULE_LICENSE("GPL v2");
614MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer"); 592MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer");
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index ed07ec04a962..9b138129e856 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -6,34 +6,14 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * 16 * GNU General Public License for more details.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 17 */
38 18
39#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -43,7 +23,7 @@
43#include <linux/platform_device.h> 23#include <linux/platform_device.h>
44 24
45#include <linux/usb/otg.h> 25#include <linux/usb/otg.h>
46#include <linux/usb/nop-usb-xceiv.h> 26#include <linux/usb/usb_phy_gen_xceiv.h>
47 27
48/* FIXME define these in <linux/pci_ids.h> */ 28/* FIXME define these in <linux/pci_ids.h> */
49#define PCI_VENDOR_ID_SYNOPSYS 0x16c3 29#define PCI_VENDOR_ID_SYNOPSYS 0x16c3
@@ -58,13 +38,13 @@ struct dwc3_pci {
58 38
59static int dwc3_pci_register_phys(struct dwc3_pci *glue) 39static int dwc3_pci_register_phys(struct dwc3_pci *glue)
60{ 40{
61 struct nop_usb_xceiv_platform_data pdata; 41 struct usb_phy_gen_xceiv_platform_data pdata;
62 struct platform_device *pdev; 42 struct platform_device *pdev;
63 int ret; 43 int ret;
64 44
65 memset(&pdata, 0x00, sizeof(pdata)); 45 memset(&pdata, 0x00, sizeof(pdata));
66 46
67 pdev = platform_device_alloc("nop_usb_xceiv", 0); 47 pdev = platform_device_alloc("usb_phy_gen_xceiv", 0);
68 if (!pdev) 48 if (!pdev)
69 return -ENOMEM; 49 return -ENOMEM;
70 50
@@ -75,7 +55,7 @@ static int dwc3_pci_register_phys(struct dwc3_pci *glue)
75 if (ret) 55 if (ret)
76 goto err1; 56 goto err1;
77 57
78 pdev = platform_device_alloc("nop_usb_xceiv", 1); 58 pdev = platform_device_alloc("usb_phy_gen_xceiv", 1);
79 if (!pdev) { 59 if (!pdev) {
80 ret = -ENOMEM; 60 ret = -ENOMEM;
81 goto err1; 61 goto err1;
@@ -211,7 +191,7 @@ static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = {
211}; 191};
212MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); 192MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
213 193
214#ifdef CONFIG_PM 194#ifdef CONFIG_PM_SLEEP
215static int dwc3_pci_suspend(struct device *dev) 195static int dwc3_pci_suspend(struct device *dev)
216{ 196{
217 struct pci_dev *pci = to_pci_dev(dev); 197 struct pci_dev *pci = to_pci_dev(dev);
@@ -236,28 +216,24 @@ static int dwc3_pci_resume(struct device *dev)
236 216
237 return 0; 217 return 0;
238} 218}
219#endif /* CONFIG_PM_SLEEP */
239 220
240static const struct dev_pm_ops dwc3_pci_dev_pm_ops = { 221static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
241 SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume) 222 SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
242}; 223};
243 224
244#define DEV_PM_OPS (&dwc3_pci_dev_pm_ops)
245#else
246#define DEV_PM_OPS NULL
247#endif /* CONFIG_PM */
248
249static struct pci_driver dwc3_pci_driver = { 225static struct pci_driver dwc3_pci_driver = {
250 .name = "dwc3-pci", 226 .name = "dwc3-pci",
251 .id_table = dwc3_pci_id_table, 227 .id_table = dwc3_pci_id_table,
252 .probe = dwc3_pci_probe, 228 .probe = dwc3_pci_probe,
253 .remove = dwc3_pci_remove, 229 .remove = dwc3_pci_remove,
254 .driver = { 230 .driver = {
255 .pm = DEV_PM_OPS, 231 .pm = &dwc3_pci_dev_pm_ops,
256 }, 232 },
257}; 233};
258 234
259MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 235MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
260MODULE_LICENSE("Dual BSD/GPL"); 236MODULE_LICENSE("GPL v2");
261MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer"); 237MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
262 238
263module_pci_driver(dwc3_pci_driver); 239module_pci_driver(dwc3_pci_driver);
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 5acbb948b704..7fa93f4bc507 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -6,34 +6,14 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * 16 * GNU General Public License for more details.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 17 */
38 18
39#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -168,6 +148,7 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
168 148
169 direction = !dwc->ep0_expect_in; 149 direction = !dwc->ep0_expect_in;
170 dwc->delayed_status = false; 150 dwc->delayed_status = false;
151 usb_gadget_set_state(&dwc->gadget, USB_STATE_CONFIGURED);
171 152
172 if (dwc->ep0state == EP0_STATUS_PHASE) 153 if (dwc->ep0state == EP0_STATUS_PHASE)
173 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); 154 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]);
@@ -553,8 +534,16 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
553 ret = dwc3_ep0_delegate_req(dwc, ctrl); 534 ret = dwc3_ep0_delegate_req(dwc, ctrl);
554 /* if the cfg matches and the cfg is non zero */ 535 /* if the cfg matches and the cfg is non zero */
555 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { 536 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) {
556 usb_gadget_set_state(&dwc->gadget, 537
557 USB_STATE_CONFIGURED); 538 /*
539 * only change state if set_config has already
540 * been processed. If gadget driver returns
541 * USB_GADGET_DELAYED_STATUS, we will wait
542 * to change the state on the next usb_ep_queue()
543 */
544 if (ret == 0)
545 usb_gadget_set_state(&dwc->gadget,
546 USB_STATE_CONFIGURED);
558 547
559 /* 548 /*
560 * Enable transition to U1/U2 state when 549 * Enable transition to U1/U2 state when
@@ -571,7 +560,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
571 560
572 case USB_STATE_CONFIGURED: 561 case USB_STATE_CONFIGURED:
573 ret = dwc3_ep0_delegate_req(dwc, ctrl); 562 ret = dwc3_ep0_delegate_req(dwc, ctrl);
574 if (!cfg) 563 if (!cfg && !ret)
575 usb_gadget_set_state(&dwc->gadget, 564 usb_gadget_set_state(&dwc->gadget,
576 USB_STATE_ADDRESS); 565 USB_STATE_ADDRESS);
577 break; 566 break;
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index f77083fedc68..f168eaebdef8 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -6,34 +6,14 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * 16 * GNU General Public License for more details.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 17 */
38 18
39#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -520,6 +500,8 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
520 u32 reg; 500 u32 reg;
521 int ret = -ENOMEM; 501 int ret = -ENOMEM;
522 502
503 dev_vdbg(dwc->dev, "Enabling %s\n", dep->name);
504
523 if (!(dep->flags & DWC3_EP_ENABLED)) { 505 if (!(dep->flags & DWC3_EP_ENABLED)) {
524 ret = dwc3_gadget_start_config(dwc, dep); 506 ret = dwc3_gadget_start_config(dwc, dep);
525 if (ret) 507 if (ret)
@@ -676,8 +658,6 @@ static int dwc3_gadget_ep_enable(struct usb_ep *ep,
676 dev_err(dwc->dev, "invalid endpoint transfer type\n"); 658 dev_err(dwc->dev, "invalid endpoint transfer type\n");
677 } 659 }
678 660
679 dev_vdbg(dwc->dev, "Enabling %s\n", dep->name);
680
681 spin_lock_irqsave(&dwc->lock, flags); 661 spin_lock_irqsave(&dwc->lock, flags);
682 ret = __dwc3_gadget_ep_enable(dep, desc, ep->comp_desc, false); 662 ret = __dwc3_gadget_ep_enable(dep, desc, ep->comp_desc, false);
683 spin_unlock_irqrestore(&dwc->lock, flags); 663 spin_unlock_irqrestore(&dwc->lock, flags);
@@ -1508,6 +1488,15 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1508 int irq; 1488 int irq;
1509 u32 reg; 1489 u32 reg;
1510 1490
1491 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
1492 ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
1493 IRQF_SHARED, "dwc3", dwc);
1494 if (ret) {
1495 dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
1496 irq, ret);
1497 goto err0;
1498 }
1499
1511 spin_lock_irqsave(&dwc->lock, flags); 1500 spin_lock_irqsave(&dwc->lock, flags);
1512 1501
1513 if (dwc->gadget_driver) { 1502 if (dwc->gadget_driver) {
@@ -1515,7 +1504,7 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1515 dwc->gadget.name, 1504 dwc->gadget.name,
1516 dwc->gadget_driver->driver.name); 1505 dwc->gadget_driver->driver.name);
1517 ret = -EBUSY; 1506 ret = -EBUSY;
1518 goto err0; 1507 goto err1;
1519 } 1508 }
1520 1509
1521 dwc->gadget_driver = driver; 1510 dwc->gadget_driver = driver;
@@ -1536,10 +1525,25 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1536 * STAR#9000525659: Clock Domain Crossing on DCTL in 1525 * STAR#9000525659: Clock Domain Crossing on DCTL in
1537 * USB 2.0 Mode 1526 * USB 2.0 Mode
1538 */ 1527 */
1539 if (dwc->revision < DWC3_REVISION_220A) 1528 if (dwc->revision < DWC3_REVISION_220A) {
1540 reg |= DWC3_DCFG_SUPERSPEED; 1529 reg |= DWC3_DCFG_SUPERSPEED;
1541 else 1530 } else {
1542 reg |= dwc->maximum_speed; 1531 switch (dwc->maximum_speed) {
1532 case USB_SPEED_LOW:
1533 reg |= DWC3_DSTS_LOWSPEED;
1534 break;
1535 case USB_SPEED_FULL:
1536 reg |= DWC3_DSTS_FULLSPEED1;
1537 break;
1538 case USB_SPEED_HIGH:
1539 reg |= DWC3_DSTS_HIGHSPEED;
1540 break;
1541 case USB_SPEED_SUPER: /* FALLTHROUGH */
1542 case USB_SPEED_UNKNOWN: /* FALTHROUGH */
1543 default:
1544 reg |= DWC3_DSTS_SUPERSPEED;
1545 }
1546 }
1543 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 1547 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
1544 1548
1545 dwc->start_config_issued = false; 1549 dwc->start_config_issued = false;
@@ -1551,42 +1555,38 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1551 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false); 1555 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false);
1552 if (ret) { 1556 if (ret) {
1553 dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1557 dev_err(dwc->dev, "failed to enable %s\n", dep->name);
1554 goto err0; 1558 goto err2;
1555 } 1559 }
1556 1560
1557 dep = dwc->eps[1]; 1561 dep = dwc->eps[1];
1558 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false); 1562 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false);
1559 if (ret) { 1563 if (ret) {
1560 dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1564 dev_err(dwc->dev, "failed to enable %s\n", dep->name);
1561 goto err1; 1565 goto err3;
1562 } 1566 }
1563 1567
1564 /* begin to receive SETUP packets */ 1568 /* begin to receive SETUP packets */
1565 dwc->ep0state = EP0_SETUP_PHASE; 1569 dwc->ep0state = EP0_SETUP_PHASE;
1566 dwc3_ep0_out_start(dwc); 1570 dwc3_ep0_out_start(dwc);
1567 1571
1568 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
1569 ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
1570 IRQF_SHARED | IRQF_ONESHOT, "dwc3", dwc);
1571 if (ret) {
1572 dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
1573 irq, ret);
1574 goto err1;
1575 }
1576
1577 dwc3_gadget_enable_irq(dwc); 1572 dwc3_gadget_enable_irq(dwc);
1578 1573
1579 spin_unlock_irqrestore(&dwc->lock, flags); 1574 spin_unlock_irqrestore(&dwc->lock, flags);
1580 1575
1581 return 0; 1576 return 0;
1582 1577
1583err1: 1578err3:
1584 __dwc3_gadget_ep_disable(dwc->eps[0]); 1579 __dwc3_gadget_ep_disable(dwc->eps[0]);
1585 1580
1586err0: 1581err2:
1587 dwc->gadget_driver = NULL; 1582 dwc->gadget_driver = NULL;
1583
1584err1:
1588 spin_unlock_irqrestore(&dwc->lock, flags); 1585 spin_unlock_irqrestore(&dwc->lock, flags);
1589 1586
1587 free_irq(irq, dwc);
1588
1589err0:
1590 return ret; 1590 return ret;
1591} 1591}
1592 1592
@@ -1600,9 +1600,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g,
1600 spin_lock_irqsave(&dwc->lock, flags); 1600 spin_lock_irqsave(&dwc->lock, flags);
1601 1601
1602 dwc3_gadget_disable_irq(dwc); 1602 dwc3_gadget_disable_irq(dwc);
1603 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
1604 free_irq(irq, dwc);
1605
1606 __dwc3_gadget_ep_disable(dwc->eps[0]); 1603 __dwc3_gadget_ep_disable(dwc->eps[0]);
1607 __dwc3_gadget_ep_disable(dwc->eps[1]); 1604 __dwc3_gadget_ep_disable(dwc->eps[1]);
1608 1605
@@ -1610,6 +1607,9 @@ static int dwc3_gadget_stop(struct usb_gadget *g,
1610 1607
1611 spin_unlock_irqrestore(&dwc->lock, flags); 1608 spin_unlock_irqrestore(&dwc->lock, flags);
1612 1609
1610 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
1611 free_irq(irq, dwc);
1612
1613 return 0; 1613 return 0;
1614} 1614}
1615 1615
@@ -1642,13 +1642,15 @@ static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc,
1642 1642
1643 dep->dwc = dwc; 1643 dep->dwc = dwc;
1644 dep->number = epnum; 1644 dep->number = epnum;
1645 dep->direction = !!direction;
1645 dwc->eps[epnum] = dep; 1646 dwc->eps[epnum] = dep;
1646 1647
1647 snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1, 1648 snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1,
1648 (epnum & 1) ? "in" : "out"); 1649 (epnum & 1) ? "in" : "out");
1649 1650
1650 dep->endpoint.name = dep->name; 1651 dep->endpoint.name = dep->name;
1651 dep->direction = (epnum & 1); 1652
1653 dev_vdbg(dwc->dev, "initializing %s\n", dep->name);
1652 1654
1653 if (epnum == 0 || epnum == 1) { 1655 if (epnum == 0 || epnum == 1) {
1654 dep->endpoint.maxpacket = 512; 1656 dep->endpoint.maxpacket = 512;
@@ -2105,34 +2107,6 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
2105 dwc->setup_packet_pending = false; 2107 dwc->setup_packet_pending = false;
2106} 2108}
2107 2109
2108static void dwc3_gadget_usb3_phy_suspend(struct dwc3 *dwc, int suspend)
2109{
2110 u32 reg;
2111
2112 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
2113
2114 if (suspend)
2115 reg |= DWC3_GUSB3PIPECTL_SUSPHY;
2116 else
2117 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
2118
2119 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
2120}
2121
2122static void dwc3_gadget_usb2_phy_suspend(struct dwc3 *dwc, int suspend)
2123{
2124 u32 reg;
2125
2126 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
2127
2128 if (suspend)
2129 reg |= DWC3_GUSB2PHYCFG_SUSPHY;
2130 else
2131 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
2132
2133 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
2134}
2135
2136static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) 2110static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
2137{ 2111{
2138 u32 reg; 2112 u32 reg;
@@ -2173,13 +2147,6 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
2173 /* after reset -> Default State */ 2147 /* after reset -> Default State */
2174 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); 2148 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
2175 2149
2176 /* Recent versions support automatic phy suspend and don't need this */
2177 if (dwc->revision < DWC3_REVISION_194A) {
2178 /* Resume PHYs */
2179 dwc3_gadget_usb2_phy_suspend(dwc, false);
2180 dwc3_gadget_usb3_phy_suspend(dwc, false);
2181 }
2182
2183 if (dwc->gadget.speed != USB_SPEED_UNKNOWN) 2150 if (dwc->gadget.speed != USB_SPEED_UNKNOWN)
2184 dwc3_disconnect_gadget(dwc); 2151 dwc3_disconnect_gadget(dwc);
2185 2152
@@ -2223,20 +2190,6 @@ static void dwc3_update_ram_clk_sel(struct dwc3 *dwc, u32 speed)
2223 dwc3_writel(dwc->regs, DWC3_GCTL, reg); 2190 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
2224} 2191}
2225 2192
2226static void dwc3_gadget_phy_suspend(struct dwc3 *dwc, u8 speed)
2227{
2228 switch (speed) {
2229 case USB_SPEED_SUPER:
2230 dwc3_gadget_usb2_phy_suspend(dwc, true);
2231 break;
2232 case USB_SPEED_HIGH:
2233 case USB_SPEED_FULL:
2234 case USB_SPEED_LOW:
2235 dwc3_gadget_usb3_phy_suspend(dwc, true);
2236 break;
2237 }
2238}
2239
2240static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) 2193static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
2241{ 2194{
2242 struct dwc3_ep *dep; 2195 struct dwc3_ep *dep;
@@ -2312,12 +2265,6 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
2312 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 2265 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
2313 } 2266 }
2314 2267
2315 /* Recent versions support automatic phy suspend and don't need this */
2316 if (dwc->revision < DWC3_REVISION_194A) {
2317 /* Suspend unneeded PHY */
2318 dwc3_gadget_phy_suspend(dwc, dwc->gadget.speed);
2319 }
2320
2321 dep = dwc->eps[0]; 2268 dep = dwc->eps[0];
2322 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, true); 2269 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, true);
2323 if (ret) { 2270 if (ret) {
@@ -2495,61 +2442,75 @@ static void dwc3_process_event_entry(struct dwc3 *dwc,
2495 } 2442 }
2496} 2443}
2497 2444
2498static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc) 2445static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf)
2499{ 2446{
2500 struct dwc3 *dwc = _dwc; 2447 struct dwc3_event_buffer *evt;
2501 unsigned long flags;
2502 irqreturn_t ret = IRQ_NONE; 2448 irqreturn_t ret = IRQ_NONE;
2503 int i; 2449 int left;
2450 u32 reg;
2504 2451
2505 spin_lock_irqsave(&dwc->lock, flags); 2452 evt = dwc->ev_buffs[buf];
2453 left = evt->count;
2506 2454
2507 for (i = 0; i < dwc->num_event_buffers; i++) { 2455 if (!(evt->flags & DWC3_EVENT_PENDING))
2508 struct dwc3_event_buffer *evt; 2456 return IRQ_NONE;
2509 int left;
2510 2457
2511 evt = dwc->ev_buffs[i]; 2458 while (left > 0) {
2512 left = evt->count; 2459 union dwc3_event event;
2513 2460
2514 if (!(evt->flags & DWC3_EVENT_PENDING)) 2461 event.raw = *(u32 *) (evt->buf + evt->lpos);
2515 continue;
2516 2462
2517 while (left > 0) { 2463 dwc3_process_event_entry(dwc, &event);
2518 union dwc3_event event;
2519 2464
2520 event.raw = *(u32 *) (evt->buf + evt->lpos); 2465 /*
2466 * FIXME we wrap around correctly to the next entry as
2467 * almost all entries are 4 bytes in size. There is one
2468 * entry which has 12 bytes which is a regular entry
2469 * followed by 8 bytes data. ATM I don't know how
2470 * things are organized if we get next to the a
2471 * boundary so I worry about that once we try to handle
2472 * that.
2473 */
2474 evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
2475 left -= 4;
2521 2476
2522 dwc3_process_event_entry(dwc, &event); 2477 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(buf), 4);
2478 }
2523 2479
2524 /* 2480 evt->count = 0;
2525 * FIXME we wrap around correctly to the next entry as 2481 evt->flags &= ~DWC3_EVENT_PENDING;
2526 * almost all entries are 4 bytes in size. There is one 2482 ret = IRQ_HANDLED;
2527 * entry which has 12 bytes which is a regular entry
2528 * followed by 8 bytes data. ATM I don't know how
2529 * things are organized if we get next to the a
2530 * boundary so I worry about that once we try to handle
2531 * that.
2532 */
2533 evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
2534 left -= 4;
2535 2483
2536 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(i), 4); 2484 /* Unmask interrupt */
2537 } 2485 reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(buf));
2486 reg &= ~DWC3_GEVNTSIZ_INTMASK;
2487 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(buf), reg);
2538 2488
2539 evt->count = 0; 2489 return ret;
2540 evt->flags &= ~DWC3_EVENT_PENDING; 2490}
2541 ret = IRQ_HANDLED; 2491
2542 } 2492static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc)
2493{
2494 struct dwc3 *dwc = _dwc;
2495 unsigned long flags;
2496 irqreturn_t ret = IRQ_NONE;
2497 int i;
2498
2499 spin_lock_irqsave(&dwc->lock, flags);
2500
2501 for (i = 0; i < dwc->num_event_buffers; i++)
2502 ret |= dwc3_process_event_buf(dwc, i);
2543 2503
2544 spin_unlock_irqrestore(&dwc->lock, flags); 2504 spin_unlock_irqrestore(&dwc->lock, flags);
2545 2505
2546 return ret; 2506 return ret;
2547} 2507}
2548 2508
2549static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf) 2509static irqreturn_t dwc3_check_event_buf(struct dwc3 *dwc, u32 buf)
2550{ 2510{
2551 struct dwc3_event_buffer *evt; 2511 struct dwc3_event_buffer *evt;
2552 u32 count; 2512 u32 count;
2513 u32 reg;
2553 2514
2554 evt = dwc->ev_buffs[buf]; 2515 evt = dwc->ev_buffs[buf];
2555 2516
@@ -2561,6 +2522,11 @@ static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf)
2561 evt->count = count; 2522 evt->count = count;
2562 evt->flags |= DWC3_EVENT_PENDING; 2523 evt->flags |= DWC3_EVENT_PENDING;
2563 2524
2525 /* Mask interrupt */
2526 reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(buf));
2527 reg |= DWC3_GEVNTSIZ_INTMASK;
2528 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(buf), reg);
2529
2564 return IRQ_WAKE_THREAD; 2530 return IRQ_WAKE_THREAD;
2565} 2531}
2566 2532
@@ -2575,7 +2541,7 @@ static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
2575 for (i = 0; i < dwc->num_event_buffers; i++) { 2541 for (i = 0; i < dwc->num_event_buffers; i++) {
2576 irqreturn_t status; 2542 irqreturn_t status;
2577 2543
2578 status = dwc3_process_event_buf(dwc, i); 2544 status = dwc3_check_event_buf(dwc, i);
2579 if (status == IRQ_WAKE_THREAD) 2545 if (status == IRQ_WAKE_THREAD)
2580 ret = status; 2546 ret = status;
2581 } 2547 }
@@ -2593,7 +2559,6 @@ static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
2593 */ 2559 */
2594int dwc3_gadget_init(struct dwc3 *dwc) 2560int dwc3_gadget_init(struct dwc3 *dwc)
2595{ 2561{
2596 u32 reg;
2597 int ret; 2562 int ret;
2598 2563
2599 dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 2564 dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
@@ -2643,16 +2608,6 @@ int dwc3_gadget_init(struct dwc3 *dwc)
2643 if (ret) 2608 if (ret)
2644 goto err4; 2609 goto err4;
2645 2610
2646 reg = dwc3_readl(dwc->regs, DWC3_DCFG);
2647 reg |= DWC3_DCFG_LPM_CAP;
2648 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
2649
2650 /* Enable USB2 LPM and automatic phy suspend only on recent versions */
2651 if (dwc->revision >= DWC3_REVISION_194A) {
2652 dwc3_gadget_usb2_phy_suspend(dwc, false);
2653 dwc3_gadget_usb3_phy_suspend(dwc, false);
2654 }
2655
2656 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); 2611 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget);
2657 if (ret) { 2612 if (ret) {
2658 dev_err(dwc->dev, "failed to register udc\n"); 2613 dev_err(dwc->dev, "failed to register udc\n");
diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
index 99e6d7248820..febe1aa7b714 100644
--- a/drivers/usb/dwc3/gadget.h
+++ b/drivers/usb/dwc3/gadget.h
@@ -6,34 +6,14 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * 16 * GNU General Public License for more details.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 17 */
38 18
39#ifndef __DRIVERS_USB_DWC3_GADGET_H 19#ifndef __DRIVERS_USB_DWC3_GADGET_H
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index 0fa1846eda4c..32db328cc769 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -5,34 +5,14 @@
5 * 5 *
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * This program is free software: you can redistribute it and/or modify
9 * modification, are permitted provided that the following conditions 9 * it under the terms of the GNU General Public License version 2 of
10 * are met: 10 * the License as published by the Free Software Foundation.
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The names of the above-listed copyright holders may not be used
18 * to endorse or promote products derived from this software without
19 * specific prior written permission.
20 * 11 *
21 * ALTERNATIVELY, this software may be distributed under the terms of the 12 * This program is distributed in the hope that it will be useful,
22 * GNU General Public License ("GPL") version 2, as published by the Free 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * Software Foundation. 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * 15 * GNU General Public License for more details.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */ 16 */
37 17
38#include <linux/platform_device.h> 18#include <linux/platform_device.h>
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
index a50f76b9d19b..d94441c14d8c 100644
--- a/drivers/usb/dwc3/io.h
+++ b/drivers/usb/dwc3/io.h
@@ -6,34 +6,14 @@
6 * Authors: Felipe Balbi <balbi@ti.com>, 6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * This program is free software: you can redistribute it and/or modify
10 * modification, are permitted provided that the following conditions 10 * it under the terms of the GNU General Public License version 2 of
11 * are met: 11 * the License as published by the Free Software Foundation.
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 * 12 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the 13 * This program is distributed in the hope that it will be useful,
23 * GNU General Public License ("GPL") version 2, as published by the Free 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * Software Foundation. 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * 16 * GNU General Public License for more details.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */ 17 */
38 18
39#ifndef __DRIVERS_USB_DWC3_IO_H 19#ifndef __DRIVERS_USB_DWC3_IO_H
diff --git a/drivers/usb/dwc3/platform_data.h b/drivers/usb/dwc3/platform_data.h
new file mode 100644
index 000000000000..7db34f00b89a
--- /dev/null
+++ b/drivers/usb/dwc3/platform_data.h
@@ -0,0 +1,27 @@
1/**
2 * platform_data.h - USB DWC3 Platform Data Support
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5 * Author: Felipe Balbi <balbi@ti.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 of
9 * the License as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/usb/ch9.h>
21#include <linux/usb/otg.h>
22
23struct dwc3_platform_data {
24 enum usb_device_speed maximum_speed;
25 enum usb_dr_mode dr_mode;
26 bool tx_fifo_resize;
27};
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 8e9368330b10..1e3f52574367 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -144,7 +144,6 @@ config USB_AT91
144config USB_LPC32XX 144config USB_LPC32XX
145 tristate "LPC32XX USB Peripheral Controller" 145 tristate "LPC32XX USB Peripheral Controller"
146 depends on ARCH_LPC32XX 146 depends on ARCH_LPC32XX
147 depends on USB_PHY
148 select USB_ISP1301 147 select USB_ISP1301
149 help 148 help
150 This option selects the USB device controller in the LPC32xx SoC. 149 This option selects the USB device controller in the LPC32xx SoC.
@@ -206,7 +205,6 @@ config USB_FOTG210_UDC
206config USB_OMAP 205config USB_OMAP
207 tristate "OMAP USB Device Controller" 206 tristate "OMAP USB Device Controller"
208 depends on ARCH_OMAP1 207 depends on ARCH_OMAP1
209 depends on USB_PHY
210 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG 208 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG
211 help 209 help
212 Many Texas Instruments OMAP processors have flexible full 210 Many Texas Instruments OMAP processors have flexible full
@@ -287,21 +285,6 @@ config USB_S3C_HSOTG
287 The Samsung S3C64XX USB2.0 high-speed gadget controller 285 The Samsung S3C64XX USB2.0 high-speed gadget controller
288 integrated into the S3C64XX series SoC. 286 integrated into the S3C64XX series SoC.
289 287
290config USB_IMX
291 tristate "Freescale i.MX1 USB Peripheral Controller"
292 depends on ARCH_MXC
293 depends on BROKEN
294 help
295 Freescale's i.MX1 includes an integrated full speed
296 USB 1.1 device controller.
297
298 It has Six fixed-function endpoints, as well as endpoint
299 zero (for control transfers).
300
301 Say "y" to link the driver statically, or "m" to build a
302 dynamically linked module called "imx_udc" and force all
303 gadget drivers to also be dynamically linked.
304
305config USB_S3C2410 288config USB_S3C2410
306 tristate "S3C2410 USB Device Controller" 289 tristate "S3C2410 USB Device Controller"
307 depends on ARCH_S3C24XX 290 depends on ARCH_S3C24XX
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index bad08e66f369..386db9daf1d9 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -13,7 +13,6 @@ obj-$(CONFIG_USB_NET2280) += net2280.o
13obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o 13obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o
14obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o 14obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o
15obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o 15obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o
16obj-$(CONFIG_USB_IMX) += imx_udc.o
17obj-$(CONFIG_USB_GOKU) += goku_udc.o 16obj-$(CONFIG_USB_GOKU) += goku_udc.o
18obj-$(CONFIG_USB_OMAP) += omap_udc.o 17obj-$(CONFIG_USB_OMAP) += omap_udc.o
19obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o 18obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index f52dcfe8f545..a9a4346c83aa 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1122,7 +1122,7 @@ udc_queue(struct usb_ep *usbep, struct usb_request *usbreq, gfp_t gfp)
1122 goto finished; 1122 goto finished;
1123 } 1123 }
1124 if (ep->dma) { 1124 if (ep->dma) {
1125 retval = prep_dma(ep, req, gfp); 1125 retval = prep_dma(ep, req, GFP_ATOMIC);
1126 if (retval != 0) 1126 if (retval != 0)
1127 goto finished; 1127 goto finished;
1128 /* write desc pointer to enable DMA */ 1128 /* write desc pointer to enable DMA */
@@ -1190,7 +1190,7 @@ udc_queue(struct usb_ep *usbep, struct usb_request *usbreq, gfp_t gfp)
1190 * for PPB modes, because of chain creation reasons 1190 * for PPB modes, because of chain creation reasons
1191 */ 1191 */
1192 if (ep->in) { 1192 if (ep->in) {
1193 retval = prep_dma(ep, req, gfp); 1193 retval = prep_dma(ep, req, GFP_ATOMIC);
1194 if (retval != 0) 1194 if (retval != 0)
1195 goto finished; 1195 goto finished;
1196 } 1196 }
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index d9a6add0c852..4cc4fd6d1473 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -870,6 +870,11 @@ static void clk_on(struct at91_udc *udc)
870 if (udc->clocked) 870 if (udc->clocked)
871 return; 871 return;
872 udc->clocked = 1; 872 udc->clocked = 1;
873
874 if (IS_ENABLED(CONFIG_COMMON_CLK)) {
875 clk_set_rate(udc->uclk, 48000000);
876 clk_prepare_enable(udc->uclk);
877 }
873 clk_prepare_enable(udc->iclk); 878 clk_prepare_enable(udc->iclk);
874 clk_prepare_enable(udc->fclk); 879 clk_prepare_enable(udc->fclk);
875} 880}
@@ -882,6 +887,8 @@ static void clk_off(struct at91_udc *udc)
882 udc->gadget.speed = USB_SPEED_UNKNOWN; 887 udc->gadget.speed = USB_SPEED_UNKNOWN;
883 clk_disable_unprepare(udc->fclk); 888 clk_disable_unprepare(udc->fclk);
884 clk_disable_unprepare(udc->iclk); 889 clk_disable_unprepare(udc->iclk);
890 if (IS_ENABLED(CONFIG_COMMON_CLK))
891 clk_disable_unprepare(udc->uclk);
885} 892}
886 893
887/* 894/*
@@ -1697,7 +1704,7 @@ static int at91udc_probe(struct platform_device *pdev)
1697 int retval; 1704 int retval;
1698 struct resource *res; 1705 struct resource *res;
1699 1706
1700 if (!dev->platform_data && !pdev->dev.of_node) { 1707 if (!dev_get_platdata(dev) && !pdev->dev.of_node) {
1701 /* small (so we copy it) but critical! */ 1708 /* small (so we copy it) but critical! */
1702 DBG("missing platform_data\n"); 1709 DBG("missing platform_data\n");
1703 return -ENODEV; 1710 return -ENODEV;
@@ -1728,7 +1735,7 @@ static int at91udc_probe(struct platform_device *pdev)
1728 if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) 1735 if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
1729 at91udc_of_init(udc, pdev->dev.of_node); 1736 at91udc_of_init(udc, pdev->dev.of_node);
1730 else 1737 else
1731 memcpy(&udc->board, dev->platform_data, 1738 memcpy(&udc->board, dev_get_platdata(dev),
1732 sizeof(struct at91_udc_data)); 1739 sizeof(struct at91_udc_data));
1733 udc->pdev = pdev; 1740 udc->pdev = pdev;
1734 udc->enabled = 0; 1741 udc->enabled = 0;
@@ -1774,10 +1781,12 @@ static int at91udc_probe(struct platform_device *pdev)
1774 /* get interface and function clocks */ 1781 /* get interface and function clocks */
1775 udc->iclk = clk_get(dev, "udc_clk"); 1782 udc->iclk = clk_get(dev, "udc_clk");
1776 udc->fclk = clk_get(dev, "udpck"); 1783 udc->fclk = clk_get(dev, "udpck");
1777 if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) { 1784 if (IS_ENABLED(CONFIG_COMMON_CLK))
1785 udc->uclk = clk_get(dev, "usb_clk");
1786 if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk) ||
1787 (IS_ENABLED(CONFIG_COMMON_CLK) && IS_ERR(udc->uclk))) {
1778 DBG("clocks missing\n"); 1788 DBG("clocks missing\n");
1779 retval = -ENODEV; 1789 retval = -ENODEV;
1780 /* NOTE: we "know" here that refcounts on these are NOPs */
1781 goto fail1; 1790 goto fail1;
1782 } 1791 }
1783 1792
@@ -1851,6 +1860,12 @@ fail3:
1851fail2: 1860fail2:
1852 free_irq(udc->udp_irq, udc); 1861 free_irq(udc->udp_irq, udc);
1853fail1: 1862fail1:
1863 if (IS_ENABLED(CONFIG_COMMON_CLK) && !IS_ERR(udc->uclk))
1864 clk_put(udc->uclk);
1865 if (!IS_ERR(udc->fclk))
1866 clk_put(udc->fclk);
1867 if (!IS_ERR(udc->iclk))
1868 clk_put(udc->iclk);
1854 iounmap(udc->udp_baseaddr); 1869 iounmap(udc->udp_baseaddr);
1855fail0a: 1870fail0a:
1856 if (cpu_is_at91rm9200()) 1871 if (cpu_is_at91rm9200())
@@ -1894,6 +1909,8 @@ static int __exit at91udc_remove(struct platform_device *pdev)
1894 1909
1895 clk_put(udc->iclk); 1910 clk_put(udc->iclk);
1896 clk_put(udc->fclk); 1911 clk_put(udc->fclk);
1912 if (IS_ENABLED(CONFIG_COMMON_CLK))
1913 clk_put(udc->uclk);
1897 1914
1898 return 0; 1915 return 0;
1899} 1916}
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index e647d1c2ada4..017524663381 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -126,7 +126,7 @@ struct at91_udc {
126 unsigned active_suspend:1; 126 unsigned active_suspend:1;
127 u8 addr; 127 u8 addr;
128 struct at91_udc_data board; 128 struct at91_udc_data board;
129 struct clk *iclk, *fclk; 129 struct clk *iclk, *fclk, *uclk;
130 struct platform_device *pdev; 130 struct platform_device *pdev;
131 struct proc_dir_entry *pde; 131 struct proc_dir_entry *pde;
132 void __iomem *udp_baseaddr; 132 void __iomem *udp_baseaddr;
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index 1d9722203ca6..40d23384b716 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1772,6 +1772,7 @@ out:
1772static int atmel_usba_start(struct usb_gadget *gadget, 1772static int atmel_usba_start(struct usb_gadget *gadget,
1773 struct usb_gadget_driver *driver) 1773 struct usb_gadget_driver *driver)
1774{ 1774{
1775 int ret = 0;
1775 struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); 1776 struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget);
1776 unsigned long flags; 1777 unsigned long flags;
1777 1778
@@ -1781,8 +1782,14 @@ static int atmel_usba_start(struct usb_gadget *gadget,
1781 udc->driver = driver; 1782 udc->driver = driver;
1782 spin_unlock_irqrestore(&udc->lock, flags); 1783 spin_unlock_irqrestore(&udc->lock, flags);
1783 1784
1784 clk_enable(udc->pclk); 1785 ret = clk_prepare_enable(udc->pclk);
1785 clk_enable(udc->hclk); 1786 if (ret)
1787 goto out;
1788 ret = clk_prepare_enable(udc->hclk);
1789 if (ret) {
1790 clk_disable_unprepare(udc->pclk);
1791 goto out;
1792 }
1786 1793
1787 DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name); 1794 DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name);
1788 1795
@@ -1797,9 +1804,11 @@ static int atmel_usba_start(struct usb_gadget *gadget,
1797 usba_writel(udc, CTRL, USBA_ENABLE_MASK); 1804 usba_writel(udc, CTRL, USBA_ENABLE_MASK);
1798 usba_writel(udc, INT_ENB, USBA_END_OF_RESET); 1805 usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
1799 } 1806 }
1807
1808out:
1800 spin_unlock_irqrestore(&udc->lock, flags); 1809 spin_unlock_irqrestore(&udc->lock, flags);
1801 1810
1802 return 0; 1811 return ret;
1803} 1812}
1804 1813
1805static int atmel_usba_stop(struct usb_gadget *gadget, 1814static int atmel_usba_stop(struct usb_gadget *gadget,
@@ -1822,8 +1831,8 @@ static int atmel_usba_stop(struct usb_gadget *gadget,
1822 1831
1823 udc->driver = NULL; 1832 udc->driver = NULL;
1824 1833
1825 clk_disable(udc->hclk); 1834 clk_disable_unprepare(udc->hclk);
1826 clk_disable(udc->pclk); 1835 clk_disable_unprepare(udc->pclk);
1827 1836
1828 DBG(DBG_GADGET, "unregistered driver `%s'\n", driver->driver.name); 1837 DBG(DBG_GADGET, "unregistered driver `%s'\n", driver->driver.name);
1829 1838
@@ -1922,7 +1931,7 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
1922static struct usba_ep * usba_udc_pdata(struct platform_device *pdev, 1931static struct usba_ep * usba_udc_pdata(struct platform_device *pdev,
1923 struct usba_udc *udc) 1932 struct usba_udc *udc)
1924{ 1933{
1925 struct usba_platform_data *pdata = pdev->dev.platform_data; 1934 struct usba_platform_data *pdata = dev_get_platdata(&pdev->dev);
1926 struct usba_ep *eps; 1935 struct usba_ep *eps;
1927 int i; 1936 int i;
1928 1937
@@ -2022,10 +2031,14 @@ static int __init usba_udc_probe(struct platform_device *pdev)
2022 platform_set_drvdata(pdev, udc); 2031 platform_set_drvdata(pdev, udc);
2023 2032
2024 /* Make sure we start from a clean slate */ 2033 /* Make sure we start from a clean slate */
2025 clk_enable(pclk); 2034 ret = clk_prepare_enable(pclk);
2035 if (ret) {
2036 dev_err(&pdev->dev, "Unable to enable pclk, aborting.\n");
2037 goto err_clk_enable;
2038 }
2026 toggle_bias(0); 2039 toggle_bias(0);
2027 usba_writel(udc, CTRL, USBA_DISABLE_MASK); 2040 usba_writel(udc, CTRL, USBA_DISABLE_MASK);
2028 clk_disable(pclk); 2041 clk_disable_unprepare(pclk);
2029 2042
2030 if (pdev->dev.of_node) 2043 if (pdev->dev.of_node)
2031 udc->usba_ep = atmel_udc_of_init(pdev, udc); 2044 udc->usba_ep = atmel_udc_of_init(pdev, udc);
@@ -2081,6 +2094,7 @@ err_add_udc:
2081 free_irq(irq, udc); 2094 free_irq(irq, udc);
2082err_request_irq: 2095err_request_irq:
2083err_alloc_ep: 2096err_alloc_ep:
2097err_clk_enable:
2084 iounmap(udc->fifo); 2098 iounmap(udc->fifo);
2085err_map_fifo: 2099err_map_fifo:
2086 iounmap(udc->regs); 2100 iounmap(udc->regs);
diff --git a/drivers/usb/gadget/bcm63xx_udc.c b/drivers/usb/gadget/bcm63xx_udc.c
index fd24cb4540a4..c58fcf1ebe41 100644
--- a/drivers/usb/gadget/bcm63xx_udc.c
+++ b/drivers/usb/gadget/bcm63xx_udc.c
@@ -2313,7 +2313,7 @@ static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc)
2313static int bcm63xx_udc_probe(struct platform_device *pdev) 2313static int bcm63xx_udc_probe(struct platform_device *pdev)
2314{ 2314{
2315 struct device *dev = &pdev->dev; 2315 struct device *dev = &pdev->dev;
2316 struct bcm63xx_usbd_platform_data *pd = dev->platform_data; 2316 struct bcm63xx_usbd_platform_data *pd = dev_get_platdata(dev);
2317 struct bcm63xx_udc *udc; 2317 struct bcm63xx_udc *udc;
2318 struct resource *res; 2318 struct resource *res;
2319 int rc = -ENOMEM, i, irq; 2319 int rc = -ENOMEM, i, irq;
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 56f1fd1cba25..4d4e96a5d2e9 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3043,12 +3043,12 @@ fsg_config_from_params(struct fsg_config *cfg,
3043 lun->filename = 3043 lun->filename =
3044 params->file_count > i && params->file[i][0] 3044 params->file_count > i && params->file[i][0]
3045 ? params->file[i] 3045 ? params->file[i]
3046 : 0; 3046 : NULL;
3047 } 3047 }
3048 3048
3049 /* Let MSF use defaults */ 3049 /* Let MSF use defaults */
3050 cfg->vendor_name = 0; 3050 cfg->vendor_name = NULL;
3051 cfg->product_name = 0; 3051 cfg->product_name = NULL;
3052 3052
3053 cfg->ops = NULL; 3053 cfg->ops = NULL;
3054 cfg->private_data = NULL; 3054 cfg->private_data = NULL;
diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
index fa8ea4ea00c1..2b4c82d84bfc 100644
--- a/drivers/usb/gadget/f_uac1.c
+++ b/drivers/usb/gadget/f_uac1.c
@@ -695,7 +695,7 @@ static int generic_get_cmd(struct usb_audio_control *con, u8 cmd)
695} 695}
696 696
697/* Todo: add more control selecotor dynamically */ 697/* Todo: add more control selecotor dynamically */
698int __init control_selector_init(struct f_audio *audio) 698static int __init control_selector_init(struct f_audio *audio)
699{ 699{
700 INIT_LIST_HEAD(&audio->cs); 700 INIT_LIST_HEAD(&audio->cs);
701 list_add(&feature_unit.list, &audio->cs); 701 list_add(&feature_unit.list, &audio->cs);
@@ -719,7 +719,7 @@ int __init control_selector_init(struct f_audio *audio)
719 * 719 *
720 * Returns zero on success, else negative errno. 720 * Returns zero on success, else negative errno.
721 */ 721 */
722int __init audio_bind_config(struct usb_configuration *c) 722static int __init audio_bind_config(struct usb_configuration *c)
723{ 723{
724 struct f_audio *audio; 724 struct f_audio *audio;
725 int status; 725 int status;
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c
index d3bd7b095ba3..9b140fc4d3bc 100644
--- a/drivers/usb/gadget/fsl_mxc_udc.c
+++ b/drivers/usb/gadget/fsl_mxc_udc.c
@@ -33,7 +33,7 @@ int fsl_udc_clk_init(struct platform_device *pdev)
33 unsigned long freq; 33 unsigned long freq;
34 int ret; 34 int ret;
35 35
36 pdata = pdev->dev.platform_data; 36 pdata = dev_get_platdata(&pdev->dev);
37 37
38 mxc_ipg_clk = devm_clk_get(&pdev->dev, "ipg"); 38 mxc_ipg_clk = devm_clk_get(&pdev->dev, "ipg");
39 if (IS_ERR(mxc_ipg_clk)) { 39 if (IS_ERR(mxc_ipg_clk)) {
@@ -80,7 +80,7 @@ eclkrate:
80 80
81int fsl_udc_clk_finalize(struct platform_device *pdev) 81int fsl_udc_clk_finalize(struct platform_device *pdev)
82{ 82{
83 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 83 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
84 int ret = 0; 84 int ret = 0;
85 85
86 /* workaround ENGcm09152 for i.MX35 */ 86 /* workaround ENGcm09152 for i.MX35 */
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index a766a4ca1cb7..36ac7cfba91d 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -2248,7 +2248,7 @@ static int __init struct_udc_setup(struct fsl_udc *udc,
2248 struct fsl_usb2_platform_data *pdata; 2248 struct fsl_usb2_platform_data *pdata;
2249 size_t size; 2249 size_t size;
2250 2250
2251 pdata = pdev->dev.platform_data; 2251 pdata = dev_get_platdata(&pdev->dev);
2252 udc->phy_mode = pdata->phy_mode; 2252 udc->phy_mode = pdata->phy_mode;
2253 2253
2254 udc->eps = kzalloc(sizeof(struct fsl_ep) * udc->max_ep, GFP_KERNEL); 2254 udc->eps = kzalloc(sizeof(struct fsl_ep) * udc->max_ep, GFP_KERNEL);
@@ -2343,7 +2343,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2343 return -ENOMEM; 2343 return -ENOMEM;
2344 } 2344 }
2345 2345
2346 pdata = pdev->dev.platform_data; 2346 pdata = dev_get_platdata(&pdev->dev);
2347 udc_controller->pdata = pdata; 2347 udc_controller->pdata = pdata;
2348 spin_lock_init(&udc_controller->lock); 2348 spin_lock_init(&udc_controller->lock);
2349 udc_controller->stopped = 1; 2349 udc_controller->stopped = 1;
@@ -2524,7 +2524,7 @@ err_kfree:
2524static int __exit fsl_udc_remove(struct platform_device *pdev) 2524static int __exit fsl_udc_remove(struct platform_device *pdev)
2525{ 2525{
2526 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2526 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2527 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 2527 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
2528 2528
2529 DECLARE_COMPLETION(done); 2529 DECLARE_COMPLETION(done);
2530 2530
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index c83f3e165325..f1dd6daabe21 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -557,7 +557,7 @@ static void fusb300_set_cxdone(struct fusb300 *fusb300)
557} 557}
558 558
559/* read data from cx fifo */ 559/* read data from cx fifo */
560void fusb300_rdcxf(struct fusb300 *fusb300, 560static void fusb300_rdcxf(struct fusb300 *fusb300,
561 u8 *buffer, u32 length) 561 u8 *buffer, u32 length)
562{ 562{
563 int i = 0; 563 int i = 0;
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 52dd6cc6c0aa..c64deb9e3d62 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -772,7 +772,7 @@ goku_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
772 772
773 } /* else pio or dma irq handler advances the queue. */ 773 } /* else pio or dma irq handler advances the queue. */
774 774
775 if (likely(req != 0)) 775 if (likely(req != NULL))
776 list_add_tail(&req->queue, &ep->queue); 776 list_add_tail(&req->queue, &ep->queue);
777 777
778 if (likely(!list_empty(&ep->queue)) 778 if (likely(!list_empty(&ep->queue))
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index c36260ea8bf2..778613eb37af 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -185,7 +185,7 @@ static int __exit hid_unbind(struct usb_composite_dev *cdev)
185 185
186static int __init hidg_plat_driver_probe(struct platform_device *pdev) 186static int __init hidg_plat_driver_probe(struct platform_device *pdev)
187{ 187{
188 struct hidg_func_descriptor *func = pdev->dev.platform_data; 188 struct hidg_func_descriptor *func = dev_get_platdata(&pdev->dev);
189 struct hidg_func_node *entry; 189 struct hidg_func_node *entry;
190 190
191 if (!func) { 191 if (!func) {
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
deleted file mode 100644
index 9b2d24e4c95f..000000000000
--- a/drivers/usb/gadget/imx_udc.c
+++ /dev/null
@@ -1,1544 +0,0 @@
1/*
2 * driver/usb/gadget/imx_udc.c
3 *
4 * Copyright (C) 2005 Mike Lee <eemike@gmail.com>
5 * Copyright (C) 2008 Darius Augulis <augulis.darius@gmail.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
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/platform_device.h>
21#include <linux/module.h>
22#include <linux/errno.h>
23#include <linux/list.h>
24#include <linux/interrupt.h>
25#include <linux/io.h>
26#include <linux/irq.h>
27#include <linux/device.h>
28#include <linux/dma-mapping.h>
29#include <linux/clk.h>
30#include <linux/delay.h>
31#include <linux/timer.h>
32#include <linux/slab.h>
33#include <linux/prefetch.h>
34
35#include <linux/usb/ch9.h>
36#include <linux/usb/gadget.h>
37
38#include <linux/platform_data/usb-imx_udc.h>
39#include <mach/hardware.h>
40
41#include "imx_udc.h"
42
43static const char driver_name[] = "imx_udc";
44static const char ep0name[] = "ep0";
45
46void ep0_chg_stat(const char *label, struct imx_udc_struct *imx_usb,
47 enum ep0_state stat);
48
49/*******************************************************************************
50 * IMX UDC hardware related functions
51 *******************************************************************************
52 */
53
54void imx_udc_enable(struct imx_udc_struct *imx_usb)
55{
56 int temp = __raw_readl(imx_usb->base + USB_CTRL);
57 __raw_writel(temp | CTRL_FE_ENA | CTRL_AFE_ENA,
58 imx_usb->base + USB_CTRL);
59 imx_usb->gadget.speed = USB_SPEED_FULL;
60}
61
62void imx_udc_disable(struct imx_udc_struct *imx_usb)
63{
64 int temp = __raw_readl(imx_usb->base + USB_CTRL);
65
66 __raw_writel(temp & ~(CTRL_FE_ENA | CTRL_AFE_ENA),
67 imx_usb->base + USB_CTRL);
68
69 ep0_chg_stat(__func__, imx_usb, EP0_IDLE);
70 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
71}
72
73void imx_udc_reset(struct imx_udc_struct *imx_usb)
74{
75 int temp = __raw_readl(imx_usb->base + USB_ENAB);
76
77 /* set RST bit */
78 __raw_writel(temp | ENAB_RST, imx_usb->base + USB_ENAB);
79
80 /* wait RST bit to clear */
81 do {} while (__raw_readl(imx_usb->base + USB_ENAB) & ENAB_RST);
82
83 /* wait CFG bit to assert */
84 do {} while (!(__raw_readl(imx_usb->base + USB_DADR) & DADR_CFG));
85
86 /* udc module is now ready */
87}
88
89void imx_udc_config(struct imx_udc_struct *imx_usb)
90{
91 u8 ep_conf[5];
92 u8 i, j, cfg;
93 struct imx_ep_struct *imx_ep;
94
95 /* wait CFG bit to assert */
96 do {} while (!(__raw_readl(imx_usb->base + USB_DADR) & DADR_CFG));
97
98 /* Download the endpoint buffer for endpoint 0. */
99 for (j = 0; j < 5; j++) {
100 i = (j == 2 ? imx_usb->imx_ep[0].fifosize : 0x00);
101 __raw_writeb(i, imx_usb->base + USB_DDAT);
102 do {} while (__raw_readl(imx_usb->base + USB_DADR) & DADR_BSY);
103 }
104
105 /* Download the endpoint buffers for endpoints 1-5.
106 * We specify two configurations, one interface
107 */
108 for (cfg = 1; cfg < 3; cfg++) {
109 for (i = 1; i < IMX_USB_NB_EP; i++) {
110 imx_ep = &imx_usb->imx_ep[i];
111 /* EP no | Config no */
112 ep_conf[0] = (i << 4) | (cfg << 2);
113 /* Type | Direction */
114 ep_conf[1] = (imx_ep->bmAttributes << 3) |
115 (EP_DIR(imx_ep) << 2);
116 /* Max packet size */
117 ep_conf[2] = imx_ep->fifosize;
118 /* TRXTYP */
119 ep_conf[3] = 0xC0;
120 /* FIFO no */
121 ep_conf[4] = i;
122
123 D_INI(imx_usb->dev,
124 "<%s> ep%d_conf[%d]:"
125 "[%02x-%02x-%02x-%02x-%02x]\n",
126 __func__, i, cfg,
127 ep_conf[0], ep_conf[1], ep_conf[2],
128 ep_conf[3], ep_conf[4]);
129
130 for (j = 0; j < 5; j++) {
131 __raw_writeb(ep_conf[j],
132 imx_usb->base + USB_DDAT);
133 do {} while (__raw_readl(imx_usb->base
134 + USB_DADR)
135 & DADR_BSY);
136 }
137 }
138 }
139
140 /* wait CFG bit to clear */
141 do {} while (__raw_readl(imx_usb->base + USB_DADR) & DADR_CFG);
142}
143
144void imx_udc_init_irq(struct imx_udc_struct *imx_usb)
145{
146 int i;
147
148 /* Mask and clear all irqs */
149 __raw_writel(0xFFFFFFFF, imx_usb->base + USB_MASK);
150 __raw_writel(0xFFFFFFFF, imx_usb->base + USB_INTR);
151 for (i = 0; i < IMX_USB_NB_EP; i++) {
152 __raw_writel(0x1FF, imx_usb->base + USB_EP_MASK(i));
153 __raw_writel(0x1FF, imx_usb->base + USB_EP_INTR(i));
154 }
155
156 /* Enable USB irqs */
157 __raw_writel(INTR_MSOF | INTR_FRAME_MATCH, imx_usb->base + USB_MASK);
158
159 /* Enable EP0 irqs */
160 __raw_writel(0x1FF & ~(EPINTR_DEVREQ | EPINTR_MDEVREQ | EPINTR_EOT
161 | EPINTR_EOF | EPINTR_FIFO_EMPTY | EPINTR_FIFO_FULL),
162 imx_usb->base + USB_EP_MASK(0));
163}
164
165void imx_udc_init_ep(struct imx_udc_struct *imx_usb)
166{
167 int i, max, temp;
168 struct imx_ep_struct *imx_ep;
169 for (i = 0; i < IMX_USB_NB_EP; i++) {
170 imx_ep = &imx_usb->imx_ep[i];
171 switch (imx_ep->fifosize) {
172 case 8:
173 max = 0;
174 break;
175 case 16:
176 max = 1;
177 break;
178 case 32:
179 max = 2;
180 break;
181 case 64:
182 max = 3;
183 break;
184 default:
185 max = 1;
186 break;
187 }
188 temp = (EP_DIR(imx_ep) << 7) | (max << 5)
189 | (imx_ep->bmAttributes << 3);
190 __raw_writel(temp, imx_usb->base + USB_EP_STAT(i));
191 __raw_writel(temp | EPSTAT_FLUSH,
192 imx_usb->base + USB_EP_STAT(i));
193 D_INI(imx_usb->dev, "<%s> ep%d_stat %08x\n", __func__, i,
194 __raw_readl(imx_usb->base + USB_EP_STAT(i)));
195 }
196}
197
198void imx_udc_init_fifo(struct imx_udc_struct *imx_usb)
199{
200 int i, temp;
201 struct imx_ep_struct *imx_ep;
202 for (i = 0; i < IMX_USB_NB_EP; i++) {
203 imx_ep = &imx_usb->imx_ep[i];
204
205 /* Fifo control */
206 temp = EP_DIR(imx_ep) ? 0x0B000000 : 0x0F000000;
207 __raw_writel(temp, imx_usb->base + USB_EP_FCTRL(i));
208 D_INI(imx_usb->dev, "<%s> ep%d_fctrl %08x\n", __func__, i,
209 __raw_readl(imx_usb->base + USB_EP_FCTRL(i)));
210
211 /* Fifo alarm */
212 temp = (i ? imx_ep->fifosize / 2 : 0);
213 __raw_writel(temp, imx_usb->base + USB_EP_FALRM(i));
214 D_INI(imx_usb->dev, "<%s> ep%d_falrm %08x\n", __func__, i,
215 __raw_readl(imx_usb->base + USB_EP_FALRM(i)));
216 }
217}
218
219static void imx_udc_init(struct imx_udc_struct *imx_usb)
220{
221 /* Reset UDC */
222 imx_udc_reset(imx_usb);
223
224 /* Download config to enpoint buffer */
225 imx_udc_config(imx_usb);
226
227 /* Setup interrups */
228 imx_udc_init_irq(imx_usb);
229
230 /* Setup endpoints */
231 imx_udc_init_ep(imx_usb);
232
233 /* Setup fifos */
234 imx_udc_init_fifo(imx_usb);
235}
236
237void imx_ep_irq_enable(struct imx_ep_struct *imx_ep)
238{
239
240 int i = EP_NO(imx_ep);
241
242 __raw_writel(0x1FF, imx_ep->imx_usb->base + USB_EP_MASK(i));
243 __raw_writel(0x1FF, imx_ep->imx_usb->base + USB_EP_INTR(i));
244 __raw_writel(0x1FF & ~(EPINTR_EOT | EPINTR_EOF),
245 imx_ep->imx_usb->base + USB_EP_MASK(i));
246}
247
248void imx_ep_irq_disable(struct imx_ep_struct *imx_ep)
249{
250
251 int i = EP_NO(imx_ep);
252
253 __raw_writel(0x1FF, imx_ep->imx_usb->base + USB_EP_MASK(i));
254 __raw_writel(0x1FF, imx_ep->imx_usb->base + USB_EP_INTR(i));
255}
256
257int imx_ep_empty(struct imx_ep_struct *imx_ep)
258{
259 struct imx_udc_struct *imx_usb = imx_ep->imx_usb;
260
261 return __raw_readl(imx_usb->base + USB_EP_FSTAT(EP_NO(imx_ep)))
262 & FSTAT_EMPTY;
263}
264
265unsigned imx_fifo_bcount(struct imx_ep_struct *imx_ep)
266{
267 struct imx_udc_struct *imx_usb = imx_ep->imx_usb;
268
269 return (__raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep)))
270 & EPSTAT_BCOUNT) >> 16;
271}
272
273void imx_flush(struct imx_ep_struct *imx_ep)
274{
275 struct imx_udc_struct *imx_usb = imx_ep->imx_usb;
276
277 int temp = __raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep)));
278 __raw_writel(temp | EPSTAT_FLUSH,
279 imx_usb->base + USB_EP_STAT(EP_NO(imx_ep)));
280}
281
282void imx_ep_stall(struct imx_ep_struct *imx_ep)
283{
284 struct imx_udc_struct *imx_usb = imx_ep->imx_usb;
285 int temp, i;
286
287 D_ERR(imx_usb->dev,
288 "<%s> Forced stall on %s\n", __func__, imx_ep->ep.name);
289
290 imx_flush(imx_ep);
291
292 /* Special care for ep0 */
293 if (!EP_NO(imx_ep)) {
294 temp = __raw_readl(imx_usb->base + USB_CTRL);
295 __raw_writel(temp | CTRL_CMDOVER | CTRL_CMDERROR,
296 imx_usb->base + USB_CTRL);
297 do { } while (__raw_readl(imx_usb->base + USB_CTRL)
298 & CTRL_CMDOVER);
299 temp = __raw_readl(imx_usb->base + USB_CTRL);
300 __raw_writel(temp & ~CTRL_CMDERROR, imx_usb->base + USB_CTRL);
301 }
302 else {
303 temp = __raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep)));
304 __raw_writel(temp | EPSTAT_STALL,
305 imx_usb->base + USB_EP_STAT(EP_NO(imx_ep)));
306
307 for (i = 0; i < 100; i ++) {
308 temp = __raw_readl(imx_usb->base
309 + USB_EP_STAT(EP_NO(imx_ep)));
310 if (!(temp & EPSTAT_STALL))
311 break;
312 udelay(20);
313 }
314 if (i == 100)
315 D_ERR(imx_usb->dev, "<%s> Non finished stall on %s\n",
316 __func__, imx_ep->ep.name);
317 }
318}
319
320static int imx_udc_get_frame(struct usb_gadget *_gadget)
321{
322 struct imx_udc_struct *imx_usb = container_of(_gadget,
323 struct imx_udc_struct, gadget);
324
325 return __raw_readl(imx_usb->base + USB_FRAME) & 0x7FF;
326}
327
328static int imx_udc_wakeup(struct usb_gadget *_gadget)
329{
330 return 0;
331}
332
333/*******************************************************************************
334 * USB request control functions
335 *******************************************************************************
336 */
337
338static void ep_add_request(struct imx_ep_struct *imx_ep,
339 struct imx_request *req)
340{
341 if (unlikely(!req))
342 return;
343
344 req->in_use = 1;
345 list_add_tail(&req->queue, &imx_ep->queue);
346}
347
348static void ep_del_request(struct imx_ep_struct *imx_ep,
349 struct imx_request *req)
350{
351 if (unlikely(!req))
352 return;
353
354 list_del_init(&req->queue);
355 req->in_use = 0;
356}
357
358static void done(struct imx_ep_struct *imx_ep,
359 struct imx_request *req, int status)
360{
361 ep_del_request(imx_ep, req);
362
363 if (likely(req->req.status == -EINPROGRESS))
364 req->req.status = status;
365 else
366 status = req->req.status;
367
368 if (status && status != -ESHUTDOWN)
369 D_ERR(imx_ep->imx_usb->dev,
370 "<%s> complete %s req %p stat %d len %u/%u\n", __func__,
371 imx_ep->ep.name, &req->req, status,
372 req->req.actual, req->req.length);
373
374 req->req.complete(&imx_ep->ep, &req->req);
375}
376
377static void nuke(struct imx_ep_struct *imx_ep, int status)
378{
379 struct imx_request *req;
380
381 while (!list_empty(&imx_ep->queue)) {
382 req = list_entry(imx_ep->queue.next, struct imx_request, queue);
383 done(imx_ep, req, status);
384 }
385}
386
387/*******************************************************************************
388 * Data tansfer over USB functions
389 *******************************************************************************
390 */
391static int read_packet(struct imx_ep_struct *imx_ep, struct imx_request *req)
392{
393 u8 *buf;
394 int bytes_ep, bufferspace, count, i;
395
396 bytes_ep = imx_fifo_bcount(imx_ep);
397 bufferspace = req->req.length - req->req.actual;
398
399 buf = req->req.buf + req->req.actual;
400 prefetchw(buf);
401
402 if (unlikely(imx_ep_empty(imx_ep)))
403 count = 0; /* zlp */
404 else
405 count = min(bytes_ep, bufferspace);
406
407 for (i = count; i > 0; i--)
408 *buf++ = __raw_readb(imx_ep->imx_usb->base
409 + USB_EP_FDAT0(EP_NO(imx_ep)));
410 req->req.actual += count;
411
412 return count;
413}
414
415static int write_packet(struct imx_ep_struct *imx_ep, struct imx_request *req)
416{
417 u8 *buf;
418 int length, count, temp;
419
420 if (unlikely(__raw_readl(imx_ep->imx_usb->base +
421 USB_EP_STAT(EP_NO(imx_ep))) & EPSTAT_ZLPS)) {
422 D_TRX(imx_ep->imx_usb->dev, "<%s> zlp still queued in EP %s\n",
423 __func__, imx_ep->ep.name);
424 return -1;
425 }
426
427 buf = req->req.buf + req->req.actual;
428 prefetch(buf);
429
430 length = min(req->req.length - req->req.actual, (u32)imx_ep->fifosize);
431
432 if (imx_fifo_bcount(imx_ep) + length > imx_ep->fifosize) {
433 D_TRX(imx_ep->imx_usb->dev, "<%s> packet overfill %s fifo\n",
434 __func__, imx_ep->ep.name);
435 return -1;
436 }
437
438 req->req.actual += length;
439 count = length;
440
441 if (!count && req->req.zero) { /* zlp */
442 temp = __raw_readl(imx_ep->imx_usb->base
443 + USB_EP_STAT(EP_NO(imx_ep)));
444 __raw_writel(temp | EPSTAT_ZLPS, imx_ep->imx_usb->base
445 + USB_EP_STAT(EP_NO(imx_ep)));
446 D_TRX(imx_ep->imx_usb->dev, "<%s> zero packet\n", __func__);
447 return 0;
448 }
449
450 while (count--) {
451 if (count == 0) { /* last byte */
452 temp = __raw_readl(imx_ep->imx_usb->base
453 + USB_EP_FCTRL(EP_NO(imx_ep)));
454 __raw_writel(temp | FCTRL_WFR, imx_ep->imx_usb->base
455 + USB_EP_FCTRL(EP_NO(imx_ep)));
456 }
457 __raw_writeb(*buf++,
458 imx_ep->imx_usb->base + USB_EP_FDAT0(EP_NO(imx_ep)));
459 }
460
461 return length;
462}
463
464static int read_fifo(struct imx_ep_struct *imx_ep, struct imx_request *req)
465{
466 int bytes = 0,
467 count,
468 completed = 0;
469
470 while (__raw_readl(imx_ep->imx_usb->base + USB_EP_FSTAT(EP_NO(imx_ep)))
471 & FSTAT_FR) {
472 count = read_packet(imx_ep, req);
473 bytes += count;
474
475 completed = (count != imx_ep->fifosize);
476 if (completed || req->req.actual == req->req.length) {
477 completed = 1;
478 break;
479 }
480 }
481
482 if (completed || !req->req.length) {
483 done(imx_ep, req, 0);
484 D_REQ(imx_ep->imx_usb->dev, "<%s> %s req<%p> %s\n",
485 __func__, imx_ep->ep.name, req,
486 completed ? "completed" : "not completed");
487 if (!EP_NO(imx_ep))
488 ep0_chg_stat(__func__, imx_ep->imx_usb, EP0_IDLE);
489 }
490
491 D_TRX(imx_ep->imx_usb->dev, "<%s> bytes read: %d\n", __func__, bytes);
492
493 return completed;
494}
495
496static int write_fifo(struct imx_ep_struct *imx_ep, struct imx_request *req)
497{
498 int bytes = 0,
499 count,
500 completed = 0;
501
502 while (!completed) {
503 count = write_packet(imx_ep, req);
504 if (count < 0)
505 break; /* busy */
506 bytes += count;
507
508 /* last packet "must be" short (or a zlp) */
509 completed = (count != imx_ep->fifosize);
510
511 if (unlikely(completed)) {
512 done(imx_ep, req, 0);
513 D_REQ(imx_ep->imx_usb->dev, "<%s> %s req<%p> %s\n",
514 __func__, imx_ep->ep.name, req,
515 completed ? "completed" : "not completed");
516 if (!EP_NO(imx_ep))
517 ep0_chg_stat(__func__,
518 imx_ep->imx_usb, EP0_IDLE);
519 }
520 }
521
522 D_TRX(imx_ep->imx_usb->dev, "<%s> bytes sent: %d\n", __func__, bytes);
523
524 return completed;
525}
526
527/*******************************************************************************
528 * Endpoint handlers
529 *******************************************************************************
530 */
531static int handle_ep(struct imx_ep_struct *imx_ep)
532{
533 struct imx_request *req;
534 int completed = 0;
535
536 do {
537 if (!list_empty(&imx_ep->queue))
538 req = list_entry(imx_ep->queue.next,
539 struct imx_request, queue);
540 else {
541 D_REQ(imx_ep->imx_usb->dev, "<%s> no request on %s\n",
542 __func__, imx_ep->ep.name);
543 return 0;
544 }
545
546 if (EP_DIR(imx_ep)) /* to host */
547 completed = write_fifo(imx_ep, req);
548 else /* to device */
549 completed = read_fifo(imx_ep, req);
550
551 dump_ep_stat(__func__, imx_ep);
552
553 } while (completed);
554
555 return 0;
556}
557
558static int handle_ep0(struct imx_ep_struct *imx_ep)
559{
560 struct imx_request *req = NULL;
561 int ret = 0;
562
563 if (!list_empty(&imx_ep->queue)) {
564 req = list_entry(imx_ep->queue.next, struct imx_request, queue);
565
566 switch (imx_ep->imx_usb->ep0state) {
567
568 case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR */
569 write_fifo(imx_ep, req);
570 break;
571 case EP0_OUT_DATA_PHASE: /* SET_DESCRIPTOR */
572 read_fifo(imx_ep, req);
573 break;
574 default:
575 D_EP0(imx_ep->imx_usb->dev,
576 "<%s> ep0 i/o, odd state %d\n",
577 __func__, imx_ep->imx_usb->ep0state);
578 ep_del_request(imx_ep, req);
579 ret = -EL2HLT;
580 break;
581 }
582 }
583
584 else
585 D_ERR(imx_ep->imx_usb->dev, "<%s> no request on %s\n",
586 __func__, imx_ep->ep.name);
587
588 return ret;
589}
590
591static void handle_ep0_devreq(struct imx_udc_struct *imx_usb)
592{
593 struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[0];
594 union {
595 struct usb_ctrlrequest r;
596 u8 raw[8];
597 u32 word[2];
598 } u;
599 int temp, i;
600
601 nuke(imx_ep, -EPROTO);
602
603 /* read SETUP packet */
604 for (i = 0; i < 2; i++) {
605 if (imx_ep_empty(imx_ep)) {
606 D_ERR(imx_usb->dev,
607 "<%s> no setup packet received\n", __func__);
608 goto stall;
609 }
610 u.word[i] = __raw_readl(imx_usb->base
611 + USB_EP_FDAT(EP_NO(imx_ep)));
612 }
613
614 temp = imx_ep_empty(imx_ep);
615 while (!imx_ep_empty(imx_ep)) {
616 i = __raw_readl(imx_usb->base + USB_EP_FDAT(EP_NO(imx_ep)));
617 D_ERR(imx_usb->dev,
618 "<%s> wrong to have extra bytes for setup : 0x%08x\n",
619 __func__, i);
620 }
621 if (!temp)
622 goto stall;
623
624 le16_to_cpus(&u.r.wValue);
625 le16_to_cpus(&u.r.wIndex);
626 le16_to_cpus(&u.r.wLength);
627
628 D_REQ(imx_usb->dev, "<%s> SETUP %02x.%02x v%04x i%04x l%04x\n",
629 __func__, u.r.bRequestType, u.r.bRequest,
630 u.r.wValue, u.r.wIndex, u.r.wLength);
631
632 if (imx_usb->set_config) {
633 /* NACK the host by using CMDOVER */
634 temp = __raw_readl(imx_usb->base + USB_CTRL);
635 __raw_writel(temp | CTRL_CMDOVER, imx_usb->base + USB_CTRL);
636
637 D_ERR(imx_usb->dev,
638 "<%s> set config req is pending, NACK the host\n",
639 __func__);
640 return;
641 }
642
643 if (u.r.bRequestType & USB_DIR_IN)
644 ep0_chg_stat(__func__, imx_usb, EP0_IN_DATA_PHASE);
645 else
646 ep0_chg_stat(__func__, imx_usb, EP0_OUT_DATA_PHASE);
647
648 i = imx_usb->driver->setup(&imx_usb->gadget, &u.r);
649 if (i < 0) {
650 D_ERR(imx_usb->dev, "<%s> device setup error %d\n",
651 __func__, i);
652 goto stall;
653 }
654
655 return;
656stall:
657 D_ERR(imx_usb->dev, "<%s> protocol STALL\n", __func__);
658 imx_ep_stall(imx_ep);
659 ep0_chg_stat(__func__, imx_usb, EP0_STALL);
660 return;
661}
662
663/*******************************************************************************
664 * USB gadget callback functions
665 *******************************************************************************
666 */
667
668static int imx_ep_enable(struct usb_ep *usb_ep,
669 const struct usb_endpoint_descriptor *desc)
670{
671 struct imx_ep_struct *imx_ep = container_of(usb_ep,
672 struct imx_ep_struct, ep);
673 struct imx_udc_struct *imx_usb = imx_ep->imx_usb;
674 unsigned long flags;
675
676 if (!usb_ep
677 || !desc
678 || !EP_NO(imx_ep)
679 || desc->bDescriptorType != USB_DT_ENDPOINT
680 || imx_ep->bEndpointAddress != desc->bEndpointAddress) {
681 D_ERR(imx_usb->dev,
682 "<%s> bad ep or descriptor\n", __func__);
683 return -EINVAL;
684 }
685
686 if (imx_ep->bmAttributes != desc->bmAttributes) {
687 D_ERR(imx_usb->dev,
688 "<%s> %s type mismatch\n", __func__, usb_ep->name);
689 return -EINVAL;
690 }
691
692 if (imx_ep->fifosize < usb_endpoint_maxp(desc)) {
693 D_ERR(imx_usb->dev,
694 "<%s> bad %s maxpacket\n", __func__, usb_ep->name);
695 return -ERANGE;
696 }
697
698 if (!imx_usb->driver || imx_usb->gadget.speed == USB_SPEED_UNKNOWN) {
699 D_ERR(imx_usb->dev, "<%s> bogus device state\n", __func__);
700 return -ESHUTDOWN;
701 }
702
703 local_irq_save(flags);
704
705 imx_ep->stopped = 0;
706 imx_flush(imx_ep);
707 imx_ep_irq_enable(imx_ep);
708
709 local_irq_restore(flags);
710
711 D_EPX(imx_usb->dev, "<%s> ENABLED %s\n", __func__, usb_ep->name);
712 return 0;
713}
714
715static int imx_ep_disable(struct usb_ep *usb_ep)
716{
717 struct imx_ep_struct *imx_ep = container_of(usb_ep,
718 struct imx_ep_struct, ep);
719 unsigned long flags;
720
721 if (!usb_ep || !EP_NO(imx_ep) || !list_empty(&imx_ep->queue)) {
722 D_ERR(imx_ep->imx_usb->dev, "<%s> %s can not be disabled\n",
723 __func__, usb_ep ? imx_ep->ep.name : NULL);
724 return -EINVAL;
725 }
726
727 local_irq_save(flags);
728
729 imx_ep->stopped = 1;
730 nuke(imx_ep, -ESHUTDOWN);
731 imx_flush(imx_ep);
732 imx_ep_irq_disable(imx_ep);
733
734 local_irq_restore(flags);
735
736 D_EPX(imx_ep->imx_usb->dev,
737 "<%s> DISABLED %s\n", __func__, usb_ep->name);
738 return 0;
739}
740
741static struct usb_request *imx_ep_alloc_request
742 (struct usb_ep *usb_ep, gfp_t gfp_flags)
743{
744 struct imx_request *req;
745
746 if (!usb_ep)
747 return NULL;
748
749 req = kzalloc(sizeof *req, gfp_flags);
750 if (!req)
751 return NULL;
752
753 INIT_LIST_HEAD(&req->queue);
754 req->in_use = 0;
755
756 return &req->req;
757}
758
759static void imx_ep_free_request
760 (struct usb_ep *usb_ep, struct usb_request *usb_req)
761{
762 struct imx_request *req;
763
764 req = container_of(usb_req, struct imx_request, req);
765 WARN_ON(!list_empty(&req->queue));
766 kfree(req);
767}
768
769static int imx_ep_queue
770 (struct usb_ep *usb_ep, struct usb_request *usb_req, gfp_t gfp_flags)
771{
772 struct imx_ep_struct *imx_ep;
773 struct imx_udc_struct *imx_usb;
774 struct imx_request *req;
775 unsigned long flags;
776 int ret = 0;
777
778 imx_ep = container_of(usb_ep, struct imx_ep_struct, ep);
779 imx_usb = imx_ep->imx_usb;
780 req = container_of(usb_req, struct imx_request, req);
781
782 /*
783 Special care on IMX udc.
784 Ignore enqueue when after set configuration from the
785 host. This assume all gadget drivers reply set
786 configuration with the next ep0 req enqueue.
787 */
788 if (imx_usb->set_config && !EP_NO(imx_ep)) {
789 imx_usb->set_config = 0;
790 D_ERR(imx_usb->dev,
791 "<%s> gadget reply set config\n", __func__);
792 return 0;
793 }
794
795 if (unlikely(!usb_req || !req || !usb_req->complete || !usb_req->buf)) {
796 D_ERR(imx_usb->dev, "<%s> bad params\n", __func__);
797 return -EINVAL;
798 }
799
800 if (unlikely(!usb_ep || !imx_ep)) {
801 D_ERR(imx_usb->dev, "<%s> bad ep\n", __func__);
802 return -EINVAL;
803 }
804
805 if (!imx_usb->driver || imx_usb->gadget.speed == USB_SPEED_UNKNOWN) {
806 D_ERR(imx_usb->dev, "<%s> bogus device state\n", __func__);
807 return -ESHUTDOWN;
808 }
809
810 /* Debug */
811 D_REQ(imx_usb->dev, "<%s> ep%d %s request for [%d] bytes\n",
812 __func__, EP_NO(imx_ep),
813 ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state
814 == EP0_IN_DATA_PHASE)
815 || (EP_NO(imx_ep) && EP_DIR(imx_ep)))
816 ? "IN" : "OUT", usb_req->length);
817 dump_req(__func__, imx_ep, usb_req);
818
819 if (imx_ep->stopped) {
820 usb_req->status = -ESHUTDOWN;
821 return -ESHUTDOWN;
822 }
823
824 if (req->in_use) {
825 D_ERR(imx_usb->dev,
826 "<%s> refusing to queue req %p (already queued)\n",
827 __func__, req);
828 return 0;
829 }
830
831 local_irq_save(flags);
832
833 usb_req->status = -EINPROGRESS;
834 usb_req->actual = 0;
835
836 ep_add_request(imx_ep, req);
837
838 if (!EP_NO(imx_ep))
839 ret = handle_ep0(imx_ep);
840 else
841 ret = handle_ep(imx_ep);
842
843 local_irq_restore(flags);
844 return ret;
845}
846
847static int imx_ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
848{
849
850 struct imx_ep_struct *imx_ep = container_of
851 (usb_ep, struct imx_ep_struct, ep);
852 struct imx_request *req;
853 unsigned long flags;
854
855 if (unlikely(!usb_ep || !EP_NO(imx_ep))) {
856 D_ERR(imx_ep->imx_usb->dev, "<%s> bad ep\n", __func__);
857 return -EINVAL;
858 }
859
860 local_irq_save(flags);
861
862 /* make sure it's actually queued on this endpoint */
863 list_for_each_entry(req, &imx_ep->queue, queue) {
864 if (&req->req == usb_req)
865 break;
866 }
867 if (&req->req != usb_req) {
868 local_irq_restore(flags);
869 return -EINVAL;
870 }
871
872 done(imx_ep, req, -ECONNRESET);
873
874 local_irq_restore(flags);
875 return 0;
876}
877
878static int imx_ep_set_halt(struct usb_ep *usb_ep, int value)
879{
880 struct imx_ep_struct *imx_ep = container_of
881 (usb_ep, struct imx_ep_struct, ep);
882 unsigned long flags;
883
884 if (unlikely(!usb_ep || !EP_NO(imx_ep))) {
885 D_ERR(imx_ep->imx_usb->dev, "<%s> bad ep\n", __func__);
886 return -EINVAL;
887 }
888
889 local_irq_save(flags);
890
891 if ((imx_ep->bEndpointAddress & USB_DIR_IN)
892 && !list_empty(&imx_ep->queue)) {
893 local_irq_restore(flags);
894 return -EAGAIN;
895 }
896
897 imx_ep_stall(imx_ep);
898
899 local_irq_restore(flags);
900
901 D_EPX(imx_ep->imx_usb->dev, "<%s> %s halt\n", __func__, usb_ep->name);
902 return 0;
903}
904
905static int imx_ep_fifo_status(struct usb_ep *usb_ep)
906{
907 struct imx_ep_struct *imx_ep = container_of
908 (usb_ep, struct imx_ep_struct, ep);
909
910 if (!usb_ep) {
911 D_ERR(imx_ep->imx_usb->dev, "<%s> bad ep\n", __func__);
912 return -ENODEV;
913 }
914
915 if (imx_ep->imx_usb->gadget.speed == USB_SPEED_UNKNOWN)
916 return 0;
917 else
918 return imx_fifo_bcount(imx_ep);
919}
920
921static void imx_ep_fifo_flush(struct usb_ep *usb_ep)
922{
923 struct imx_ep_struct *imx_ep = container_of
924 (usb_ep, struct imx_ep_struct, ep);
925 unsigned long flags;
926
927 local_irq_save(flags);
928
929 if (!usb_ep || !EP_NO(imx_ep) || !list_empty(&imx_ep->queue)) {
930 D_ERR(imx_ep->imx_usb->dev, "<%s> bad ep\n", __func__);
931 local_irq_restore(flags);
932 return;
933 }
934
935 /* toggle and halt bits stay unchanged */
936 imx_flush(imx_ep);
937
938 local_irq_restore(flags);
939}
940
941static struct usb_ep_ops imx_ep_ops = {
942 .enable = imx_ep_enable,
943 .disable = imx_ep_disable,
944
945 .alloc_request = imx_ep_alloc_request,
946 .free_request = imx_ep_free_request,
947
948 .queue = imx_ep_queue,
949 .dequeue = imx_ep_dequeue,
950
951 .set_halt = imx_ep_set_halt,
952 .fifo_status = imx_ep_fifo_status,
953 .fifo_flush = imx_ep_fifo_flush,
954};
955
956/*******************************************************************************
957 * USB endpoint control functions
958 *******************************************************************************
959 */
960
961void ep0_chg_stat(const char *label,
962 struct imx_udc_struct *imx_usb, enum ep0_state stat)
963{
964 D_EP0(imx_usb->dev, "<%s> from %15s to %15s\n",
965 label, state_name[imx_usb->ep0state], state_name[stat]);
966
967 if (imx_usb->ep0state == stat)
968 return;
969
970 imx_usb->ep0state = stat;
971}
972
973static void usb_init_data(struct imx_udc_struct *imx_usb)
974{
975 struct imx_ep_struct *imx_ep;
976 u8 i;
977
978 /* device/ep0 records init */
979 INIT_LIST_HEAD(&imx_usb->gadget.ep_list);
980 INIT_LIST_HEAD(&imx_usb->gadget.ep0->ep_list);
981 ep0_chg_stat(__func__, imx_usb, EP0_IDLE);
982
983 /* basic endpoint records init */
984 for (i = 0; i < IMX_USB_NB_EP; i++) {
985 imx_ep = &imx_usb->imx_ep[i];
986
987 if (i) {
988 list_add_tail(&imx_ep->ep.ep_list,
989 &imx_usb->gadget.ep_list);
990 imx_ep->stopped = 1;
991 } else
992 imx_ep->stopped = 0;
993
994 INIT_LIST_HEAD(&imx_ep->queue);
995 }
996}
997
998static void udc_stop_activity(struct imx_udc_struct *imx_usb,
999 struct usb_gadget_driver *driver)
1000{
1001 struct imx_ep_struct *imx_ep;
1002 int i;
1003
1004 if (imx_usb->gadget.speed == USB_SPEED_UNKNOWN)
1005 driver = NULL;
1006
1007 /* prevent new request submissions, kill any outstanding requests */
1008 for (i = 1; i < IMX_USB_NB_EP; i++) {
1009 imx_ep = &imx_usb->imx_ep[i];
1010 imx_flush(imx_ep);
1011 imx_ep->stopped = 1;
1012 imx_ep_irq_disable(imx_ep);
1013 nuke(imx_ep, -ESHUTDOWN);
1014 }
1015
1016 imx_usb->cfg = 0;
1017 imx_usb->intf = 0;
1018 imx_usb->alt = 0;
1019
1020 if (driver)
1021 driver->disconnect(&imx_usb->gadget);
1022}
1023
1024/*******************************************************************************
1025 * Interrupt handlers
1026 *******************************************************************************
1027 */
1028
1029/*
1030 * Called when timer expires.
1031 * Timer is started when CFG_CHG is received.
1032 */
1033static void handle_config(unsigned long data)
1034{
1035 struct imx_udc_struct *imx_usb = (void *)data;
1036 struct usb_ctrlrequest u;
1037 int temp, cfg, intf, alt;
1038
1039 local_irq_disable();
1040
1041 temp = __raw_readl(imx_usb->base + USB_STAT);
1042 cfg = (temp & STAT_CFG) >> 5;
1043 intf = (temp & STAT_INTF) >> 3;
1044 alt = temp & STAT_ALTSET;
1045
1046 D_REQ(imx_usb->dev,
1047 "<%s> orig config C=%d, I=%d, A=%d / "
1048 "req config C=%d, I=%d, A=%d\n",
1049 __func__, imx_usb->cfg, imx_usb->intf, imx_usb->alt,
1050 cfg, intf, alt);
1051
1052 if (cfg == 1 || cfg == 2) {
1053
1054 if (imx_usb->cfg != cfg) {
1055 u.bRequest = USB_REQ_SET_CONFIGURATION;
1056 u.bRequestType = USB_DIR_OUT |
1057 USB_TYPE_STANDARD |
1058 USB_RECIP_DEVICE;
1059 u.wValue = cfg;
1060 u.wIndex = 0;
1061 u.wLength = 0;
1062 imx_usb->cfg = cfg;
1063 imx_usb->driver->setup(&imx_usb->gadget, &u);
1064
1065 }
1066 if (imx_usb->intf != intf || imx_usb->alt != alt) {
1067 u.bRequest = USB_REQ_SET_INTERFACE;
1068 u.bRequestType = USB_DIR_OUT |
1069 USB_TYPE_STANDARD |
1070 USB_RECIP_INTERFACE;
1071 u.wValue = alt;
1072 u.wIndex = intf;
1073 u.wLength = 0;
1074 imx_usb->intf = intf;
1075 imx_usb->alt = alt;
1076 imx_usb->driver->setup(&imx_usb->gadget, &u);
1077 }
1078 }
1079
1080 imx_usb->set_config = 0;
1081
1082 local_irq_enable();
1083}
1084
1085static irqreturn_t imx_udc_irq(int irq, void *dev)
1086{
1087 struct imx_udc_struct *imx_usb = dev;
1088 int intr = __raw_readl(imx_usb->base + USB_INTR);
1089 int temp;
1090
1091 if (intr & (INTR_WAKEUP | INTR_SUSPEND | INTR_RESUME | INTR_RESET_START
1092 | INTR_RESET_STOP | INTR_CFG_CHG)) {
1093 dump_intr(__func__, intr, imx_usb->dev);
1094 dump_usb_stat(__func__, imx_usb);
1095 }
1096
1097 if (!imx_usb->driver)
1098 goto end_irq;
1099
1100 if (intr & INTR_SOF) {
1101 /* Copy from Freescale BSP.
1102 We must enable SOF intr and set CMDOVER.
1103 Datasheet don't specifiy this action, but it
1104 is done in Freescale BSP, so just copy it.
1105 */
1106 if (imx_usb->ep0state == EP0_IDLE) {
1107 temp = __raw_readl(imx_usb->base + USB_CTRL);
1108 __raw_writel(temp | CTRL_CMDOVER,
1109 imx_usb->base + USB_CTRL);
1110 }
1111 }
1112
1113 if (intr & INTR_CFG_CHG) {
1114 /* A workaround of serious IMX UDC bug.
1115 Handling of CFG_CHG should be delayed for some time, because
1116 IMX does not NACK the host when CFG_CHG interrupt is pending.
1117 There is no time to handle current CFG_CHG
1118 if next CFG_CHG or SETUP packed is send immediately.
1119 We have to clear CFG_CHG, start the timer and
1120 NACK the host by setting CTRL_CMDOVER
1121 if it sends any SETUP packet.
1122 When timer expires, handler is called to handle configuration
1123 changes. While CFG_CHG is not handled (set_config=1),
1124 we must NACK the host to every SETUP packed.
1125 This delay prevents from going out of sync with host.
1126 */
1127 __raw_writel(INTR_CFG_CHG, imx_usb->base + USB_INTR);
1128 imx_usb->set_config = 1;
1129 mod_timer(&imx_usb->timer, jiffies + 5);
1130 goto end_irq;
1131 }
1132
1133 if (intr & INTR_WAKEUP) {
1134 if (imx_usb->gadget.speed == USB_SPEED_UNKNOWN
1135 && imx_usb->driver && imx_usb->driver->resume)
1136 imx_usb->driver->resume(&imx_usb->gadget);
1137 imx_usb->set_config = 0;
1138 del_timer(&imx_usb->timer);
1139 imx_usb->gadget.speed = USB_SPEED_FULL;
1140 }
1141
1142 if (intr & INTR_SUSPEND) {
1143 if (imx_usb->gadget.speed != USB_SPEED_UNKNOWN
1144 && imx_usb->driver && imx_usb->driver->suspend)
1145 imx_usb->driver->suspend(&imx_usb->gadget);
1146 imx_usb->set_config = 0;
1147 del_timer(&imx_usb->timer);
1148 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1149 }
1150
1151 if (intr & INTR_RESET_START) {
1152 __raw_writel(intr, imx_usb->base + USB_INTR);
1153 udc_stop_activity(imx_usb, imx_usb->driver);
1154 imx_usb->set_config = 0;
1155 del_timer(&imx_usb->timer);
1156 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1157 }
1158
1159 if (intr & INTR_RESET_STOP)
1160 imx_usb->gadget.speed = USB_SPEED_FULL;
1161
1162end_irq:
1163 __raw_writel(intr, imx_usb->base + USB_INTR);
1164 return IRQ_HANDLED;
1165}
1166
1167static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev)
1168{
1169 struct imx_udc_struct *imx_usb = dev;
1170 struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[0];
1171 int intr = __raw_readl(imx_usb->base + USB_EP_INTR(0));
1172
1173 dump_ep_intr(__func__, 0, intr, imx_usb->dev);
1174
1175 if (!imx_usb->driver) {
1176 __raw_writel(intr, imx_usb->base + USB_EP_INTR(0));
1177 return IRQ_HANDLED;
1178 }
1179
1180 /* DEVREQ has highest priority */
1181 if (intr & (EPINTR_DEVREQ | EPINTR_MDEVREQ))
1182 handle_ep0_devreq(imx_usb);
1183 /* Seem i.MX is missing EOF interrupt sometimes.
1184 * Therefore we don't monitor EOF.
1185 * We call handle_ep0() only if a request is queued for ep0.
1186 */
1187 else if (!list_empty(&imx_ep->queue))
1188 handle_ep0(imx_ep);
1189
1190 __raw_writel(intr, imx_usb->base + USB_EP_INTR(0));
1191
1192 return IRQ_HANDLED;
1193}
1194
1195#ifndef MX1_INT_USBD0
1196#define MX1_INT_USBD0 MX1_USBD_INT0
1197#endif
1198
1199static irqreturn_t imx_udc_bulk_irq(int irq, void *dev)
1200{
1201 struct imx_udc_struct *imx_usb = dev;
1202 struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[irq - MX1_INT_USBD0];
1203 int intr = __raw_readl(imx_usb->base + USB_EP_INTR(EP_NO(imx_ep)));
1204
1205 dump_ep_intr(__func__, irq - MX1_INT_USBD0, intr, imx_usb->dev);
1206
1207 if (!imx_usb->driver) {
1208 __raw_writel(intr, imx_usb->base + USB_EP_INTR(EP_NO(imx_ep)));
1209 return IRQ_HANDLED;
1210 }
1211
1212 handle_ep(imx_ep);
1213
1214 __raw_writel(intr, imx_usb->base + USB_EP_INTR(EP_NO(imx_ep)));
1215
1216 return IRQ_HANDLED;
1217}
1218
1219irq_handler_t intr_handler(int i)
1220{
1221 switch (i) {
1222 case 0:
1223 return imx_udc_ctrl_irq;
1224 case 1:
1225 case 2:
1226 case 3:
1227 case 4:
1228 case 5:
1229 return imx_udc_bulk_irq;
1230 default:
1231 return imx_udc_irq;
1232 }
1233}
1234
1235/*******************************************************************************
1236 * Static defined IMX UDC structure
1237 *******************************************************************************
1238 */
1239
1240static int imx_udc_start(struct usb_gadget *gadget,
1241 struct usb_gadget_driver *driver);
1242static int imx_udc_stop(struct usb_gadget *gadget,
1243 struct usb_gadget_driver *driver);
1244static const struct usb_gadget_ops imx_udc_ops = {
1245 .get_frame = imx_udc_get_frame,
1246 .wakeup = imx_udc_wakeup,
1247 .udc_start = imx_udc_start,
1248 .udc_stop = imx_udc_stop,
1249};
1250
1251static struct imx_udc_struct controller = {
1252 .gadget = {
1253 .ops = &imx_udc_ops,
1254 .ep0 = &controller.imx_ep[0].ep,
1255 .name = driver_name,
1256 .dev = {
1257 .init_name = "gadget",
1258 },
1259 },
1260
1261 .imx_ep[0] = {
1262 .ep = {
1263 .name = ep0name,
1264 .ops = &imx_ep_ops,
1265 .maxpacket = 32,
1266 },
1267 .imx_usb = &controller,
1268 .fifosize = 32,
1269 .bEndpointAddress = 0,
1270 .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
1271 },
1272 .imx_ep[1] = {
1273 .ep = {
1274 .name = "ep1in-bulk",
1275 .ops = &imx_ep_ops,
1276 .maxpacket = 64,
1277 },
1278 .imx_usb = &controller,
1279 .fifosize = 64,
1280 .bEndpointAddress = USB_DIR_IN | 1,
1281 .bmAttributes = USB_ENDPOINT_XFER_BULK,
1282 },
1283 .imx_ep[2] = {
1284 .ep = {
1285 .name = "ep2out-bulk",
1286 .ops = &imx_ep_ops,
1287 .maxpacket = 64,
1288 },
1289 .imx_usb = &controller,
1290 .fifosize = 64,
1291 .bEndpointAddress = USB_DIR_OUT | 2,
1292 .bmAttributes = USB_ENDPOINT_XFER_BULK,
1293 },
1294 .imx_ep[3] = {
1295 .ep = {
1296 .name = "ep3out-bulk",
1297 .ops = &imx_ep_ops,
1298 .maxpacket = 32,
1299 },
1300 .imx_usb = &controller,
1301 .fifosize = 32,
1302 .bEndpointAddress = USB_DIR_OUT | 3,
1303 .bmAttributes = USB_ENDPOINT_XFER_BULK,
1304 },
1305 .imx_ep[4] = {
1306 .ep = {
1307 .name = "ep4in-int",
1308 .ops = &imx_ep_ops,
1309 .maxpacket = 32,
1310 },
1311 .imx_usb = &controller,
1312 .fifosize = 32,
1313 .bEndpointAddress = USB_DIR_IN | 4,
1314 .bmAttributes = USB_ENDPOINT_XFER_INT,
1315 },
1316 .imx_ep[5] = {
1317 .ep = {
1318 .name = "ep5out-int",
1319 .ops = &imx_ep_ops,
1320 .maxpacket = 32,
1321 },
1322 .imx_usb = &controller,
1323 .fifosize = 32,
1324 .bEndpointAddress = USB_DIR_OUT | 5,
1325 .bmAttributes = USB_ENDPOINT_XFER_INT,
1326 },
1327};
1328
1329/*******************************************************************************
1330 * USB gadget driver functions
1331 *******************************************************************************
1332 */
1333static int imx_udc_start(struct usb_gadget *gadget,
1334 struct usb_gadget_driver *driver)
1335{
1336 struct imx_udc_struct *imx_usb;
1337
1338 imx_usb = container_of(gadget, struct imx_udc_struct, gadget);
1339 /* first hook up the driver ... */
1340 imx_usb->driver = driver;
1341
1342 D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n",
1343 __func__, driver->driver.name);
1344
1345 imx_udc_enable(imx_usb);
1346
1347 return 0;
1348}
1349
1350static int imx_udc_stop(struct usb_gadget *gadget,
1351 struct usb_gadget_driver *driver)
1352{
1353 struct imx_udc_struct *imx_usb = container_of(gadget,
1354 struct imx_udc_struct, gadget);
1355
1356 udc_stop_activity(imx_usb, driver);
1357 imx_udc_disable(imx_usb);
1358 del_timer(&imx_usb->timer);
1359
1360 imx_usb->driver = NULL;
1361
1362 D_INI(imx_usb->dev, "<%s> unregistered gadget driver '%s'\n",
1363 __func__, driver->driver.name);
1364
1365 return 0;
1366}
1367
1368/*******************************************************************************
1369 * Module functions
1370 *******************************************************************************
1371 */
1372
1373static int __init imx_udc_probe(struct platform_device *pdev)
1374{
1375 struct imx_udc_struct *imx_usb = &controller;
1376 struct resource *res;
1377 struct imxusb_platform_data *pdata;
1378 struct clk *clk;
1379 void __iomem *base;
1380 int ret = 0;
1381 int i;
1382 resource_size_t res_size;
1383
1384 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1385 if (!res) {
1386 dev_err(&pdev->dev, "can't get device resources\n");
1387 return -ENODEV;
1388 }
1389
1390 pdata = pdev->dev.platform_data;
1391 if (!pdata) {
1392 dev_err(&pdev->dev, "driver needs platform data\n");
1393 return -ENODEV;
1394 }
1395
1396 res_size = resource_size(res);
1397 if (!request_mem_region(res->start, res_size, res->name)) {
1398 dev_err(&pdev->dev, "can't allocate %d bytes at %d address\n",
1399 res_size, res->start);
1400 return -ENOMEM;
1401 }
1402
1403 if (pdata->init) {
1404 ret = pdata->init(&pdev->dev);
1405 if (ret)
1406 goto fail0;
1407 }
1408
1409 base = ioremap(res->start, res_size);
1410 if (!base) {
1411 dev_err(&pdev->dev, "ioremap failed\n");
1412 ret = -EIO;
1413 goto fail1;
1414 }
1415
1416 clk = clk_get(NULL, "usbd_clk");
1417 if (IS_ERR(clk)) {
1418 ret = PTR_ERR(clk);
1419 dev_err(&pdev->dev, "can't get USB clock\n");
1420 goto fail2;
1421 }
1422 clk_prepare_enable(clk);
1423
1424 if (clk_get_rate(clk) != 48000000) {
1425 D_INI(&pdev->dev,
1426 "Bad USB clock (%d Hz), changing to 48000000 Hz\n",
1427 (int)clk_get_rate(clk));
1428 if (clk_set_rate(clk, 48000000)) {
1429 dev_err(&pdev->dev,
1430 "Unable to set correct USB clock (48MHz)\n");
1431 ret = -EIO;
1432 goto fail3;
1433 }
1434 }
1435
1436 for (i = 0; i < IMX_USB_NB_EP + 1; i++) {
1437 imx_usb->usbd_int[i] = platform_get_irq(pdev, i);
1438 if (imx_usb->usbd_int[i] < 0) {
1439 dev_err(&pdev->dev, "can't get irq number\n");
1440 ret = -ENODEV;
1441 goto fail3;
1442 }
1443 }
1444
1445 for (i = 0; i < IMX_USB_NB_EP + 1; i++) {
1446 ret = request_irq(imx_usb->usbd_int[i], intr_handler(i),
1447 0, driver_name, imx_usb);
1448 if (ret) {
1449 dev_err(&pdev->dev, "can't get irq %i, err %d\n",
1450 imx_usb->usbd_int[i], ret);
1451 for (--i; i >= 0; i--)
1452 free_irq(imx_usb->usbd_int[i], imx_usb);
1453 goto fail3;
1454 }
1455 }
1456
1457 imx_usb->res = res;
1458 imx_usb->base = base;
1459 imx_usb->clk = clk;
1460 imx_usb->dev = &pdev->dev;
1461
1462 platform_set_drvdata(pdev, imx_usb);
1463
1464 usb_init_data(imx_usb);
1465 imx_udc_init(imx_usb);
1466
1467 init_timer(&imx_usb->timer);
1468 imx_usb->timer.function = handle_config;
1469 imx_usb->timer.data = (unsigned long)imx_usb;
1470
1471 ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget);
1472 if (ret)
1473 goto fail4;
1474
1475 return 0;
1476fail4:
1477 for (i = 0; i < IMX_USB_NB_EP + 1; i++)
1478 free_irq(imx_usb->usbd_int[i], imx_usb);
1479fail3:
1480 clk_put(clk);
1481 clk_disable_unprepare(clk);
1482fail2:
1483 iounmap(base);
1484fail1:
1485 if (pdata->exit)
1486 pdata->exit(&pdev->dev);
1487fail0:
1488 release_mem_region(res->start, res_size);
1489 return ret;
1490}
1491
1492static int __exit imx_udc_remove(struct platform_device *pdev)
1493{
1494 struct imx_udc_struct *imx_usb = platform_get_drvdata(pdev);
1495 struct imxusb_platform_data *pdata = pdev->dev.platform_data;
1496 int i;
1497
1498 usb_del_gadget_udc(&imx_usb->gadget);
1499 imx_udc_disable(imx_usb);
1500 del_timer(&imx_usb->timer);
1501
1502 for (i = 0; i < IMX_USB_NB_EP + 1; i++)
1503 free_irq(imx_usb->usbd_int[i], imx_usb);
1504
1505 clk_put(imx_usb->clk);
1506 clk_disable_unprepare(imx_usb->clk);
1507 iounmap(imx_usb->base);
1508
1509 release_mem_region(imx_usb->res->start, resource_size(imx_usb->res));
1510
1511 if (pdata->exit)
1512 pdata->exit(&pdev->dev);
1513
1514 return 0;
1515}
1516
1517/*----------------------------------------------------------------------------*/
1518
1519#ifdef CONFIG_PM
1520#define imx_udc_suspend NULL
1521#define imx_udc_resume NULL
1522#else
1523#define imx_udc_suspend NULL
1524#define imx_udc_resume NULL
1525#endif
1526
1527/*----------------------------------------------------------------------------*/
1528
1529static struct platform_driver udc_driver = {
1530 .driver = {
1531 .name = driver_name,
1532 .owner = THIS_MODULE,
1533 },
1534 .remove = __exit_p(imx_udc_remove),
1535 .suspend = imx_udc_suspend,
1536 .resume = imx_udc_resume,
1537};
1538
1539module_platform_driver_probe(udc_driver, imx_udc_probe);
1540
1541MODULE_DESCRIPTION("IMX USB Device Controller driver");
1542MODULE_AUTHOR("Darius Augulis <augulis.darius@gmail.com>");
1543MODULE_LICENSE("GPL");
1544MODULE_ALIAS("platform:imx_udc");
diff --git a/drivers/usb/gadget/imx_udc.h b/drivers/usb/gadget/imx_udc.h
deleted file mode 100644
index d118fb777840..000000000000
--- a/drivers/usb/gadget/imx_udc.h
+++ /dev/null
@@ -1,351 +0,0 @@
1/*
2 * Copyright (C) 2005 Mike Lee(eemike@gmail.com)
3 *
4 * This udc driver is now under testing and code is based on pxa2xx_udc.h
5 * Please use it with your own risk!
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#ifndef __LINUX_USB_GADGET_IMX_H
14#define __LINUX_USB_GADGET_IMX_H
15
16#include <linux/types.h>
17
18/* Helper macros */
19#define EP_NO(ep) ((ep->bEndpointAddress) & ~USB_DIR_IN) /* IN:1, OUT:0 */
20#define EP_DIR(ep) ((ep->bEndpointAddress) & USB_DIR_IN ? 1 : 0)
21#define IMX_USB_NB_EP 6
22
23/* Driver structures */
24struct imx_request {
25 struct usb_request req;
26 struct list_head queue;
27 unsigned int in_use;
28};
29
30enum ep0_state {
31 EP0_IDLE,
32 EP0_IN_DATA_PHASE,
33 EP0_OUT_DATA_PHASE,
34 EP0_CONFIG,
35 EP0_STALL,
36};
37
38struct imx_ep_struct {
39 struct usb_ep ep;
40 struct imx_udc_struct *imx_usb;
41 struct list_head queue;
42 unsigned char stopped;
43 unsigned char fifosize;
44 unsigned char bEndpointAddress;
45 unsigned char bmAttributes;
46};
47
48struct imx_udc_struct {
49 struct usb_gadget gadget;
50 struct usb_gadget_driver *driver;
51 struct device *dev;
52 struct imx_ep_struct imx_ep[IMX_USB_NB_EP];
53 struct clk *clk;
54 struct timer_list timer;
55 enum ep0_state ep0state;
56 struct resource *res;
57 void __iomem *base;
58 unsigned char set_config;
59 int cfg,
60 intf,
61 alt,
62 usbd_int[7];
63};
64
65/* USB registers */
66#define USB_FRAME (0x00) /* USB frame */
67#define USB_SPEC (0x04) /* USB Spec */
68#define USB_STAT (0x08) /* USB Status */
69#define USB_CTRL (0x0C) /* USB Control */
70#define USB_DADR (0x10) /* USB Desc RAM addr */
71#define USB_DDAT (0x14) /* USB Desc RAM/EP buffer data */
72#define USB_INTR (0x18) /* USB interrupt */
73#define USB_MASK (0x1C) /* USB Mask */
74#define USB_ENAB (0x24) /* USB Enable */
75#define USB_EP_STAT(x) (0x30 + (x*0x30)) /* USB status/control */
76#define USB_EP_INTR(x) (0x34 + (x*0x30)) /* USB interrupt */
77#define USB_EP_MASK(x) (0x38 + (x*0x30)) /* USB mask */
78#define USB_EP_FDAT(x) (0x3C + (x*0x30)) /* USB FIFO data */
79#define USB_EP_FDAT0(x) (0x3C + (x*0x30)) /* USB FIFO data */
80#define USB_EP_FDAT1(x) (0x3D + (x*0x30)) /* USB FIFO data */
81#define USB_EP_FDAT2(x) (0x3E + (x*0x30)) /* USB FIFO data */
82#define USB_EP_FDAT3(x) (0x3F + (x*0x30)) /* USB FIFO data */
83#define USB_EP_FSTAT(x) (0x40 + (x*0x30)) /* USB FIFO status */
84#define USB_EP_FCTRL(x) (0x44 + (x*0x30)) /* USB FIFO control */
85#define USB_EP_LRFP(x) (0x48 + (x*0x30)) /* USB last rd f. pointer */
86#define USB_EP_LWFP(x) (0x4C + (x*0x30)) /* USB last wr f. pointer */
87#define USB_EP_FALRM(x) (0x50 + (x*0x30)) /* USB FIFO alarm */
88#define USB_EP_FRDP(x) (0x54 + (x*0x30)) /* USB FIFO read pointer */
89#define USB_EP_FWRP(x) (0x58 + (x*0x30)) /* USB FIFO write pointer */
90/* USB Control Register Bit Fields.*/
91#define CTRL_CMDOVER (1<<6) /* UDC status */
92#define CTRL_CMDERROR (1<<5) /* UDC status */
93#define CTRL_FE_ENA (1<<3) /* Enable Font End logic */
94#define CTRL_UDC_RST (1<<2) /* UDC reset */
95#define CTRL_AFE_ENA (1<<1) /* Analog Font end enable */
96#define CTRL_RESUME (1<<0) /* UDC resume */
97/* USB Status Register Bit Fields.*/
98#define STAT_RST (1<<8)
99#define STAT_SUSP (1<<7)
100#define STAT_CFG (3<<5)
101#define STAT_INTF (3<<3)
102#define STAT_ALTSET (7<<0)
103/* USB Interrupt Status/Mask Registers Bit fields */
104#define INTR_WAKEUP (1<<31) /* Wake up Interrupt */
105#define INTR_MSOF (1<<7) /* Missed Start of Frame */
106#define INTR_SOF (1<<6) /* Start of Frame */
107#define INTR_RESET_STOP (1<<5) /* Reset Signaling stop */
108#define INTR_RESET_START (1<<4) /* Reset Signaling start */
109#define INTR_RESUME (1<<3) /* Suspend to resume */
110#define INTR_SUSPEND (1<<2) /* Active to suspend */
111#define INTR_FRAME_MATCH (1<<1) /* Frame matched */
112#define INTR_CFG_CHG (1<<0) /* Configuration change occurred */
113/* USB Enable Register Bit Fields.*/
114#define ENAB_RST (1<<31) /* Reset USB modules */
115#define ENAB_ENAB (1<<30) /* Enable USB modules*/
116#define ENAB_SUSPEND (1<<29) /* Suspend USB modules */
117#define ENAB_ENDIAN (1<<28) /* Endian of USB modules */
118#define ENAB_PWRMD (1<<0) /* Power mode of USB modules */
119/* USB Descriptor Ram Address Register bit fields */
120#define DADR_CFG (1<<31) /* Configuration */
121#define DADR_BSY (1<<30) /* Busy status */
122#define DADR_DADR (0x1FF) /* Descriptor Ram Address */
123/* USB Descriptor RAM/Endpoint Buffer Data Register bit fields */
124#define DDAT_DDAT (0xFF) /* Descriptor Endpoint Buffer */
125/* USB Endpoint Status Register bit fields */
126#define EPSTAT_BCOUNT (0x7F<<16) /* Endpoint FIFO byte count */
127#define EPSTAT_SIP (1<<8) /* Endpoint setup in progress */
128#define EPSTAT_DIR (1<<7) /* Endpoint transfer direction */
129#define EPSTAT_MAX (3<<5) /* Endpoint Max packet size */
130#define EPSTAT_TYP (3<<3) /* Endpoint type */
131#define EPSTAT_ZLPS (1<<2) /* Send zero length packet */
132#define EPSTAT_FLUSH (1<<1) /* Endpoint FIFO Flush */
133#define EPSTAT_STALL (1<<0) /* Force stall */
134/* USB Endpoint FIFO Status Register bit fields */
135#define FSTAT_FRAME_STAT (0xF<<24) /* Frame status bit [0-3] */
136#define FSTAT_ERR (1<<22) /* FIFO error */
137#define FSTAT_UF (1<<21) /* FIFO underflow */
138#define FSTAT_OF (1<<20) /* FIFO overflow */
139#define FSTAT_FR (1<<19) /* FIFO frame ready */
140#define FSTAT_FULL (1<<18) /* FIFO full */
141#define FSTAT_ALRM (1<<17) /* FIFO alarm */
142#define FSTAT_EMPTY (1<<16) /* FIFO empty */
143/* USB Endpoint FIFO Control Register bit fields */
144#define FCTRL_WFR (1<<29) /* Write frame end */
145/* USB Endpoint Interrupt Status Regsiter bit fields */
146#define EPINTR_FIFO_FULL (1<<8) /* fifo full */
147#define EPINTR_FIFO_EMPTY (1<<7) /* fifo empty */
148#define EPINTR_FIFO_ERROR (1<<6) /* fifo error */
149#define EPINTR_FIFO_HIGH (1<<5) /* fifo high */
150#define EPINTR_FIFO_LOW (1<<4) /* fifo low */
151#define EPINTR_MDEVREQ (1<<3) /* multi Device request */
152#define EPINTR_EOT (1<<2) /* fifo end of transfer */
153#define EPINTR_DEVREQ (1<<1) /* Device request */
154#define EPINTR_EOF (1<<0) /* fifo end of frame */
155
156/* Debug macros */
157#ifdef DEBUG
158
159/* #define DEBUG_REQ */
160/* #define DEBUG_TRX */
161/* #define DEBUG_INIT */
162/* #define DEBUG_EP0 */
163/* #define DEBUG_EPX */
164/* #define DEBUG_IRQ */
165/* #define DEBUG_EPIRQ */
166/* #define DEBUG_DUMP */
167/* #define DEBUG_ERR */
168
169#ifdef DEBUG_REQ
170 #define D_REQ(dev, args...) dev_dbg(dev, ## args)
171#else
172 #define D_REQ(dev, args...) do {} while (0)
173#endif /* DEBUG_REQ */
174
175#ifdef DEBUG_TRX
176 #define D_TRX(dev, args...) dev_dbg(dev, ## args)
177#else
178 #define D_TRX(dev, args...) do {} while (0)
179#endif /* DEBUG_TRX */
180
181#ifdef DEBUG_INIT
182 #define D_INI(dev, args...) dev_dbg(dev, ## args)
183#else
184 #define D_INI(dev, args...) do {} while (0)
185#endif /* DEBUG_INIT */
186
187#ifdef DEBUG_EP0
188 static const char *state_name[] = {
189 "EP0_IDLE",
190 "EP0_IN_DATA_PHASE",
191 "EP0_OUT_DATA_PHASE",
192 "EP0_CONFIG",
193 "EP0_STALL"
194 };
195 #define D_EP0(dev, args...) dev_dbg(dev, ## args)
196#else
197 #define D_EP0(dev, args...) do {} while (0)
198#endif /* DEBUG_EP0 */
199
200#ifdef DEBUG_EPX
201 #define D_EPX(dev, args...) dev_dbg(dev, ## args)
202#else
203 #define D_EPX(dev, args...) do {} while (0)
204#endif /* DEBUG_EP0 */
205
206#ifdef DEBUG_IRQ
207 static void dump_intr(const char *label, int irqreg, struct device *dev)
208 {
209 dev_dbg(dev, "<%s> USB_INTR=[%s%s%s%s%s%s%s%s%s]\n", label,
210 (irqreg & INTR_WAKEUP) ? " wake" : "",
211 (irqreg & INTR_MSOF) ? " msof" : "",
212 (irqreg & INTR_SOF) ? " sof" : "",
213 (irqreg & INTR_RESUME) ? " resume" : "",
214 (irqreg & INTR_SUSPEND) ? " suspend" : "",
215 (irqreg & INTR_RESET_STOP) ? " noreset" : "",
216 (irqreg & INTR_RESET_START) ? " reset" : "",
217 (irqreg & INTR_FRAME_MATCH) ? " fmatch" : "",
218 (irqreg & INTR_CFG_CHG) ? " config" : "");
219 }
220#else
221 #define dump_intr(x, y, z) do {} while (0)
222#endif /* DEBUG_IRQ */
223
224#ifdef DEBUG_EPIRQ
225 static void dump_ep_intr(const char *label, int nr, int irqreg,
226 struct device *dev)
227 {
228 dev_dbg(dev, "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, nr,
229 (irqreg & EPINTR_FIFO_FULL) ? " full" : "",
230 (irqreg & EPINTR_FIFO_EMPTY) ? " fempty" : "",
231 (irqreg & EPINTR_FIFO_ERROR) ? " ferr" : "",
232 (irqreg & EPINTR_FIFO_HIGH) ? " fhigh" : "",
233 (irqreg & EPINTR_FIFO_LOW) ? " flow" : "",
234 (irqreg & EPINTR_MDEVREQ) ? " mreq" : "",
235 (irqreg & EPINTR_EOF) ? " eof" : "",
236 (irqreg & EPINTR_DEVREQ) ? " devreq" : "",
237 (irqreg & EPINTR_EOT) ? " eot" : "");
238 }
239#else
240 #define dump_ep_intr(x, y, z, i) do {} while (0)
241#endif /* DEBUG_IRQ */
242
243#ifdef DEBUG_DUMP
244 static void dump_usb_stat(const char *label,
245 struct imx_udc_struct *imx_usb)
246 {
247 int temp = __raw_readl(imx_usb->base + USB_STAT);
248
249 dev_dbg(imx_usb->dev,
250 "<%s> USB_STAT=[%s%s CFG=%d, INTF=%d, ALTR=%d]\n", label,
251 (temp & STAT_RST) ? " reset" : "",
252 (temp & STAT_SUSP) ? " suspend" : "",
253 (temp & STAT_CFG) >> 5,
254 (temp & STAT_INTF) >> 3,
255 (temp & STAT_ALTSET));
256 }
257
258 static void dump_ep_stat(const char *label,
259 struct imx_ep_struct *imx_ep)
260 {
261 int temp = __raw_readl(imx_ep->imx_usb->base
262 + USB_EP_INTR(EP_NO(imx_ep)));
263
264 dev_dbg(imx_ep->imx_usb->dev,
265 "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n",
266 label, EP_NO(imx_ep),
267 (temp & EPINTR_FIFO_FULL) ? " full" : "",
268 (temp & EPINTR_FIFO_EMPTY) ? " fempty" : "",
269 (temp & EPINTR_FIFO_ERROR) ? " ferr" : "",
270 (temp & EPINTR_FIFO_HIGH) ? " fhigh" : "",
271 (temp & EPINTR_FIFO_LOW) ? " flow" : "",
272 (temp & EPINTR_MDEVREQ) ? " mreq" : "",
273 (temp & EPINTR_EOF) ? " eof" : "",
274 (temp & EPINTR_DEVREQ) ? " devreq" : "",
275 (temp & EPINTR_EOT) ? " eot" : "");
276
277 temp = __raw_readl(imx_ep->imx_usb->base
278 + USB_EP_STAT(EP_NO(imx_ep)));
279
280 dev_dbg(imx_ep->imx_usb->dev,
281 "<%s> EP%d_STAT=[%s%s bcount=%d]\n",
282 label, EP_NO(imx_ep),
283 (temp & EPSTAT_SIP) ? " sip" : "",
284 (temp & EPSTAT_STALL) ? " stall" : "",
285 (temp & EPSTAT_BCOUNT) >> 16);
286
287 temp = __raw_readl(imx_ep->imx_usb->base
288 + USB_EP_FSTAT(EP_NO(imx_ep)));
289
290 dev_dbg(imx_ep->imx_usb->dev,
291 "<%s> EP%d_FSTAT=[%s%s%s%s%s%s%s]\n",
292 label, EP_NO(imx_ep),
293 (temp & FSTAT_ERR) ? " ferr" : "",
294 (temp & FSTAT_UF) ? " funder" : "",
295 (temp & FSTAT_OF) ? " fover" : "",
296 (temp & FSTAT_FR) ? " fready" : "",
297 (temp & FSTAT_FULL) ? " ffull" : "",
298 (temp & FSTAT_ALRM) ? " falarm" : "",
299 (temp & FSTAT_EMPTY) ? " fempty" : "");
300 }
301
302 static void dump_req(const char *label, struct imx_ep_struct *imx_ep,
303 struct usb_request *req)
304 {
305 int i;
306
307 if (!req || !req->buf) {
308 dev_dbg(imx_ep->imx_usb->dev,
309 "<%s> req or req buf is free\n", label);
310 return;
311 }
312
313 if ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state
314 == EP0_IN_DATA_PHASE)
315 || (EP_NO(imx_ep) && EP_DIR(imx_ep))) {
316
317 dev_dbg(imx_ep->imx_usb->dev,
318 "<%s> request dump <", label);
319 for (i = 0; i < req->length; i++)
320 printk("%02x-", *((u8 *)req->buf + i));
321 printk(">\n");
322 }
323 }
324
325#else
326 #define dump_ep_stat(x, y) do {} while (0)
327 #define dump_usb_stat(x, y) do {} while (0)
328 #define dump_req(x, y, z) do {} while (0)
329#endif /* DEBUG_DUMP */
330
331#ifdef DEBUG_ERR
332 #define D_ERR(dev, args...) dev_dbg(dev, ## args)
333#else
334 #define D_ERR(dev, args...) do {} while (0)
335#endif
336
337#else
338 #define D_REQ(dev, args...) do {} while (0)
339 #define D_TRX(dev, args...) do {} while (0)
340 #define D_INI(dev, args...) do {} while (0)
341 #define D_EP0(dev, args...) do {} while (0)
342 #define D_EPX(dev, args...) do {} while (0)
343 #define dump_ep_intr(x, y, z, i) do {} while (0)
344 #define dump_intr(x, y, z) do {} while (0)
345 #define dump_ep_stat(x, y) do {} while (0)
346 #define dump_usb_stat(x, y) do {} while (0)
347 #define dump_req(x, y, z) do {} while (0)
348 #define D_ERR(dev, args...) do {} while (0)
349#endif /* DEBUG */
350
351#endif /* __LINUX_USB_GADGET_IMX_H */
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index 46ba9838c3a0..d5f050d30edf 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1584,7 +1584,7 @@ static int __init m66592_probe(struct platform_device *pdev)
1584 goto clean_up; 1584 goto clean_up;
1585 } 1585 }
1586 1586
1587 if (pdev->dev.platform_data == NULL) { 1587 if (dev_get_platdata(&pdev->dev) == NULL) {
1588 dev_err(&pdev->dev, "no platform data\n"); 1588 dev_err(&pdev->dev, "no platform data\n");
1589 ret = -ENODEV; 1589 ret = -ENODEV;
1590 goto clean_up; 1590 goto clean_up;
@@ -1598,7 +1598,7 @@ static int __init m66592_probe(struct platform_device *pdev)
1598 goto clean_up; 1598 goto clean_up;
1599 } 1599 }
1600 1600
1601 m66592->pdata = pdev->dev.platform_data; 1601 m66592->pdata = dev_get_platdata(&pdev->dev);
1602 m66592->irq_trigger = ires->flags & IRQF_TRIGGER_MASK; 1602 m66592->irq_trigger = ires->flags & IRQF_TRIGGER_MASK;
1603 1603
1604 spin_lock_init(&m66592->lock); 1604 spin_lock_init(&m66592->lock);
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c
index ec6a2d290398..bbb6e98c4384 100644
--- a/drivers/usb/gadget/mv_u3d_core.c
+++ b/drivers/usb/gadget/mv_u3d_core.c
@@ -1109,7 +1109,7 @@ static int mv_u3d_controller_reset(struct mv_u3d *u3d)
1109 1109
1110static int mv_u3d_enable(struct mv_u3d *u3d) 1110static int mv_u3d_enable(struct mv_u3d *u3d)
1111{ 1111{
1112 struct mv_usb_platform_data *pdata = u3d->dev->platform_data; 1112 struct mv_usb_platform_data *pdata = dev_get_platdata(u3d->dev);
1113 int retval; 1113 int retval;
1114 1114
1115 if (u3d->active) 1115 if (u3d->active)
@@ -1138,7 +1138,7 @@ static int mv_u3d_enable(struct mv_u3d *u3d)
1138 1138
1139static void mv_u3d_disable(struct mv_u3d *u3d) 1139static void mv_u3d_disable(struct mv_u3d *u3d)
1140{ 1140{
1141 struct mv_usb_platform_data *pdata = u3d->dev->platform_data; 1141 struct mv_usb_platform_data *pdata = dev_get_platdata(u3d->dev);
1142 if (u3d->clock_gating && u3d->active) { 1142 if (u3d->clock_gating && u3d->active) {
1143 dev_dbg(u3d->dev, "disable u3d\n"); 1143 dev_dbg(u3d->dev, "disable u3d\n");
1144 if (pdata->phy_deinit) 1144 if (pdata->phy_deinit)
@@ -1246,7 +1246,7 @@ static int mv_u3d_start(struct usb_gadget *g,
1246 struct usb_gadget_driver *driver) 1246 struct usb_gadget_driver *driver)
1247{ 1247{
1248 struct mv_u3d *u3d = container_of(g, struct mv_u3d, gadget); 1248 struct mv_u3d *u3d = container_of(g, struct mv_u3d, gadget);
1249 struct mv_usb_platform_data *pdata = u3d->dev->platform_data; 1249 struct mv_usb_platform_data *pdata = dev_get_platdata(u3d->dev);
1250 unsigned long flags; 1250 unsigned long flags;
1251 1251
1252 if (u3d->driver) 1252 if (u3d->driver)
@@ -1277,7 +1277,7 @@ static int mv_u3d_stop(struct usb_gadget *g,
1277 struct usb_gadget_driver *driver) 1277 struct usb_gadget_driver *driver)
1278{ 1278{
1279 struct mv_u3d *u3d = container_of(g, struct mv_u3d, gadget); 1279 struct mv_u3d *u3d = container_of(g, struct mv_u3d, gadget);
1280 struct mv_usb_platform_data *pdata = u3d->dev->platform_data; 1280 struct mv_usb_platform_data *pdata = dev_get_platdata(u3d->dev);
1281 unsigned long flags; 1281 unsigned long flags;
1282 1282
1283 u3d->vbus_valid_detect = 0; 1283 u3d->vbus_valid_detect = 0;
@@ -1794,12 +1794,12 @@ static int mv_u3d_remove(struct platform_device *dev)
1794static int mv_u3d_probe(struct platform_device *dev) 1794static int mv_u3d_probe(struct platform_device *dev)
1795{ 1795{
1796 struct mv_u3d *u3d = NULL; 1796 struct mv_u3d *u3d = NULL;
1797 struct mv_usb_platform_data *pdata = dev->dev.platform_data; 1797 struct mv_usb_platform_data *pdata = dev_get_platdata(&dev->dev);
1798 int retval = 0; 1798 int retval = 0;
1799 struct resource *r; 1799 struct resource *r;
1800 size_t size; 1800 size_t size;
1801 1801
1802 if (!dev->dev.platform_data) { 1802 if (!dev_get_platdata(&dev->dev)) {
1803 dev_err(&dev->dev, "missing platform_data\n"); 1803 dev_err(&dev->dev, "missing platform_data\n");
1804 retval = -ENODEV; 1804 retval = -ENODEV;
1805 goto err_pdata; 1805 goto err_pdata;
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index c2a57023e467..104cdbea635a 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -2100,7 +2100,7 @@ static int mv_udc_remove(struct platform_device *pdev)
2100 2100
2101static int mv_udc_probe(struct platform_device *pdev) 2101static int mv_udc_probe(struct platform_device *pdev)
2102{ 2102{
2103 struct mv_usb_platform_data *pdata = pdev->dev.platform_data; 2103 struct mv_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
2104 struct mv_udc *udc; 2104 struct mv_udc *udc;
2105 int retval = 0; 2105 int retval = 0;
2106 struct resource *r; 2106 struct resource *r;
@@ -2118,7 +2118,7 @@ static int mv_udc_probe(struct platform_device *pdev)
2118 } 2118 }
2119 2119
2120 udc->done = &release_done; 2120 udc->done = &release_done;
2121 udc->pdata = pdev->dev.platform_data; 2121 udc->pdata = dev_get_platdata(&pdev->dev);
2122 spin_lock_init(&udc->lock); 2122 spin_lock_init(&udc->lock);
2123 2123
2124 udc->dev = pdev; 2124 udc->dev = pdev;
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index b8ed74a823cb..83957cc225d9 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -2734,7 +2734,7 @@ static int omap_udc_probe(struct platform_device *pdev)
2734 int hmc; 2734 int hmc;
2735 struct usb_phy *xceiv = NULL; 2735 struct usb_phy *xceiv = NULL;
2736 const char *type = NULL; 2736 const char *type = NULL;
2737 struct omap_usb_config *config = pdev->dev.platform_data; 2737 struct omap_usb_config *config = dev_get_platdata(&pdev->dev);
2738 struct clk *dc_clk = NULL; 2738 struct clk *dc_clk = NULL;
2739 struct clk *hhc_clk = NULL; 2739 struct clk *hhc_clk = NULL;
2740 2740
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index 95c531d5aa4f..cc9207473dbc 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -2117,7 +2117,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2117 2117
2118 /* other non-static parts of init */ 2118 /* other non-static parts of init */
2119 dev->dev = &pdev->dev; 2119 dev->dev = &pdev->dev;
2120 dev->mach = pdev->dev.platform_data; 2120 dev->mach = dev_get_platdata(&pdev->dev);
2121 2121
2122 dev->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 2122 dev->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2123 2123
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 41cea9566ac8..3c97da7760da 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -2422,7 +2422,7 @@ static int pxa_udc_probe(struct platform_device *pdev)
2422 return udc->irq; 2422 return udc->irq;
2423 2423
2424 udc->dev = &pdev->dev; 2424 udc->dev = &pdev->dev;
2425 udc->mach = pdev->dev.platform_data; 2425 udc->mach = dev_get_platdata(&pdev->dev);
2426 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 2426 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2427 2427
2428 gpio = udc->mach->gpio_pullup; 2428 gpio = udc->mach->gpio_pullup;
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index c6af649f3240..68be48d33404 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -1910,7 +1910,7 @@ static int __init r8a66597_probe(struct platform_device *pdev)
1910 1910
1911 spin_lock_init(&r8a66597->lock); 1911 spin_lock_init(&r8a66597->lock);
1912 platform_set_drvdata(pdev, r8a66597); 1912 platform_set_drvdata(pdev, r8a66597);
1913 r8a66597->pdata = pdev->dev.platform_data; 1913 r8a66597->pdata = dev_get_platdata(&pdev->dev);
1914 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; 1914 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
1915 1915
1916 r8a66597->gadget.ops = &r8a66597_gadget_ops; 1916 r8a66597->gadget.ops = &r8a66597_gadget_ops;
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 3e3ea7203030..9575085ded81 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -1142,7 +1142,7 @@ static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1142#endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1142#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1143 1143
1144 1144
1145int rndis_init(void) 1145static int rndis_init(void)
1146{ 1146{
1147 u8 i; 1147 u8 i;
1148 1148
@@ -1176,7 +1176,7 @@ int rndis_init(void)
1176} 1176}
1177module_init(rndis_init); 1177module_init(rndis_init);
1178 1178
1179void rndis_exit(void) 1179static void rndis_exit(void)
1180{ 1180{
1181#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1181#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1182 u8 i; 1182 u8 i;
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index af22f24046b2..d69b36a99dbc 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -29,6 +29,7 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/clk.h> 30#include <linux/clk.h>
31#include <linux/regulator/consumer.h> 31#include <linux/regulator/consumer.h>
32#include <linux/of_platform.h>
32 33
33#include <linux/usb/ch9.h> 34#include <linux/usb/ch9.h>
34#include <linux/usb/gadget.h> 35#include <linux/usb/gadget.h>
@@ -3450,7 +3451,7 @@ static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg)
3450 3451
3451static int s3c_hsotg_probe(struct platform_device *pdev) 3452static int s3c_hsotg_probe(struct platform_device *pdev)
3452{ 3453{
3453 struct s3c_hsotg_plat *plat = pdev->dev.platform_data; 3454 struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev);
3454 struct usb_phy *phy; 3455 struct usb_phy *phy;
3455 struct device *dev = &pdev->dev; 3456 struct device *dev = &pdev->dev;
3456 struct s3c_hsotg_ep *eps; 3457 struct s3c_hsotg_ep *eps;
@@ -3469,7 +3470,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
3469 phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 3470 phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
3470 if (IS_ERR(phy)) { 3471 if (IS_ERR(phy)) {
3471 /* Fallback for pdata */ 3472 /* Fallback for pdata */
3472 plat = pdev->dev.platform_data; 3473 plat = dev_get_platdata(&pdev->dev);
3473 if (!plat) { 3474 if (!plat) {
3474 dev_err(&pdev->dev, "no platform data or transceiver defined\n"); 3475 dev_err(&pdev->dev, "no platform data or transceiver defined\n");
3475 return -EPROBE_DEFER; 3476 return -EPROBE_DEFER;
@@ -3648,10 +3649,19 @@ static int s3c_hsotg_remove(struct platform_device *pdev)
3648#define s3c_hsotg_resume NULL 3649#define s3c_hsotg_resume NULL
3649#endif 3650#endif
3650 3651
3652#ifdef CONFIG_OF
3653static const struct of_device_id s3c_hsotg_of_ids[] = {
3654 { .compatible = "samsung,s3c6400-hsotg", },
3655 { /* sentinel */ }
3656};
3657MODULE_DEVICE_TABLE(of, s3c_hsotg_of_ids);
3658#endif
3659
3651static struct platform_driver s3c_hsotg_driver = { 3660static struct platform_driver s3c_hsotg_driver = {
3652 .driver = { 3661 .driver = {
3653 .name = "s3c-hsotg", 3662 .name = "s3c-hsotg",
3654 .owner = THIS_MODULE, 3663 .owner = THIS_MODULE,
3664 .of_match_table = of_match_ptr(s3c_hsotg_of_ids),
3655 }, 3665 },
3656 .probe = s3c_hsotg_probe, 3666 .probe = s3c_hsotg_probe,
3657 .remove = s3c_hsotg_remove, 3667 .remove = s3c_hsotg_remove,
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index b1f0771fbd3d..1a1a41498db2 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -1262,7 +1262,7 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1262 struct device *dev = &pdev->dev; 1262 struct device *dev = &pdev->dev;
1263 struct resource *res; 1263 struct resource *res;
1264 struct s3c_hsudc *hsudc; 1264 struct s3c_hsudc *hsudc;
1265 struct s3c24xx_hsudc_platdata *pd = pdev->dev.platform_data; 1265 struct s3c24xx_hsudc_platdata *pd = dev_get_platdata(&pdev->dev);
1266 int ret, i; 1266 int ret, i;
1267 1267
1268 hsudc = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsudc) + 1268 hsudc = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsudc) +
@@ -1275,7 +1275,7 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1275 1275
1276 platform_set_drvdata(pdev, dev); 1276 platform_set_drvdata(pdev, dev);
1277 hsudc->dev = dev; 1277 hsudc->dev = dev;
1278 hsudc->pd = pdev->dev.platform_data; 1278 hsudc->pd = dev_get_platdata(&pdev->dev);
1279 1279
1280 hsudc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 1280 hsudc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
1281 1281
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index 09c4f70c93c4..c72d810e6b36 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -1809,7 +1809,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1809 } 1809 }
1810 1810
1811 spin_lock_init(&udc->lock); 1811 spin_lock_init(&udc->lock);
1812 udc_info = pdev->dev.platform_data; 1812 udc_info = dev_get_platdata(&pdev->dev);
1813 1813
1814 rsrc_start = S3C2410_PA_USBDEV; 1814 rsrc_start = S3C2410_PA_USBDEV;
1815 rsrc_len = S3C24XX_SZ_USBDEV; 1815 rsrc_len = S3C24XX_SZ_USBDEV;
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index dbce3a9074e6..8c71212a8c52 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -172,7 +172,7 @@ MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers");
172 */ 172 */
173#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS 173#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
174 174
175#endif /* CONFIG_USB_DEBUG */ 175#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
176 176
177/* check if fsg_num_buffers is within a valid range */ 177/* check if fsg_num_buffers is within a valid range */
178static inline int fsg_num_buffers_validate(void) 178static inline int fsg_num_buffers_validate(void)
diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
index c7d460f43390..7a55fea43430 100644
--- a/drivers/usb/gadget/u_uac1.c
+++ b/drivers/usb/gadget/u_uac1.c
@@ -191,7 +191,7 @@ try_again:
191 frames = bytes_to_frames(runtime, count); 191 frames = bytes_to_frames(runtime, count);
192 old_fs = get_fs(); 192 old_fs = get_fs();
193 set_fs(KERNEL_DS); 193 set_fs(KERNEL_DS);
194 result = snd_pcm_lib_write(snd->substream, buf, frames); 194 result = snd_pcm_lib_write(snd->substream, (void __user *)buf, frames);
195 if (result != frames) { 195 if (result != frames) {
196 ERROR(card, "Playback error: %d\n", (int)result); 196 ERROR(card, "Playback error: %d\n", (int)result);
197 set_fs(old_fs); 197 set_fs(old_fs);
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 13e25f80fc20..546bfda3059a 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -23,6 +23,7 @@
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/dma-mapping.h> 25#include <linux/dma-mapping.h>
26#include <linux/workqueue.h>
26 27
27#include <linux/usb/ch9.h> 28#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h> 29#include <linux/usb/gadget.h>
@@ -105,11 +106,18 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
105 106
106/* ------------------------------------------------------------------------- */ 107/* ------------------------------------------------------------------------- */
107 108
109static void usb_gadget_state_work(struct work_struct *work)
110{
111 struct usb_gadget *gadget = work_to_gadget(work);
112
113 sysfs_notify(&gadget->dev.kobj, NULL, "state");
114}
115
108void usb_gadget_set_state(struct usb_gadget *gadget, 116void usb_gadget_set_state(struct usb_gadget *gadget,
109 enum usb_device_state state) 117 enum usb_device_state state)
110{ 118{
111 gadget->state = state; 119 gadget->state = state;
112 sysfs_notify(&gadget->dev.kobj, NULL, "state"); 120 schedule_work(&gadget->work);
113} 121}
114EXPORT_SYMBOL_GPL(usb_gadget_set_state); 122EXPORT_SYMBOL_GPL(usb_gadget_set_state);
115 123
@@ -196,6 +204,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
196 goto err1; 204 goto err1;
197 205
198 dev_set_name(&gadget->dev, "gadget"); 206 dev_set_name(&gadget->dev, "gadget");
207 INIT_WORK(&gadget->work, usb_gadget_state_work);
199 gadget->dev.parent = parent; 208 gadget->dev.parent = parent;
200 209
201#ifdef CONFIG_HAS_DMA 210#ifdef CONFIG_HAS_DMA
@@ -315,6 +324,7 @@ found:
315 usb_gadget_remove_driver(udc); 324 usb_gadget_remove_driver(udc);
316 325
317 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); 326 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
327 flush_work(&gadget->work);
318 device_unregister(&udc->dev); 328 device_unregister(&udc->dev);
319 device_unregister(&gadget->dev); 329 device_unregister(&gadget->dev);
320} 330}
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c
index e6170478ea9f..0bb5d50075de 100644
--- a/drivers/usb/gadget/uvc_queue.c
+++ b/drivers/usb/gadget/uvc_queue.c
@@ -193,12 +193,16 @@ static int uvc_queue_buffer(struct uvc_video_queue *queue,
193 193
194 mutex_lock(&queue->mutex); 194 mutex_lock(&queue->mutex);
195 ret = vb2_qbuf(&queue->queue, buf); 195 ret = vb2_qbuf(&queue->queue, buf);
196 if (ret < 0)
197 goto done;
198
196 spin_lock_irqsave(&queue->irqlock, flags); 199 spin_lock_irqsave(&queue->irqlock, flags);
197 ret = (queue->flags & UVC_QUEUE_PAUSED) != 0; 200 ret = (queue->flags & UVC_QUEUE_PAUSED) != 0;
198 queue->flags &= ~UVC_QUEUE_PAUSED; 201 queue->flags &= ~UVC_QUEUE_PAUSED;
199 spin_unlock_irqrestore(&queue->irqlock, flags); 202 spin_unlock_irqrestore(&queue->irqlock, flags);
200 mutex_unlock(&queue->mutex);
201 203
204done:
205 mutex_unlock(&queue->mutex);
202 return ret; 206 return ret;
203} 207}
204 208
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 4263d011392c..5be0326aae38 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -29,15 +29,6 @@ if USB_XHCI_HCD
29config USB_XHCI_PLATFORM 29config USB_XHCI_PLATFORM
30 tristate 30 tristate
31 31
32config USB_XHCI_HCD_DEBUGGING
33 bool "Debugging for the xHCI host controller"
34 ---help---
35 Say 'Y' to turn on debugging for the xHCI host controller driver.
36 This will spew debugging output, even in interrupt context.
37 This should only be used for debugging xHCI driver bugs.
38
39 If unsure, say N.
40
41endif # USB_XHCI_HCD 32endif # USB_XHCI_HCD
42 33
43config USB_EHCI_HCD 34config USB_EHCI_HCD
@@ -113,12 +104,6 @@ config USB_EHCI_HCD_PMC_MSP
113 Enables support for the onchip USB controller on the PMC_MSP7100 Family SoC's. 104 Enables support for the onchip USB controller on the PMC_MSP7100 Family SoC's.
114 If unsure, say N. 105 If unsure, say N.
115 106
116config USB_EHCI_BIG_ENDIAN_MMIO
117 bool
118
119config USB_EHCI_BIG_ENDIAN_DESC
120 bool
121
122config XPS_USB_HCD_XILINX 107config XPS_USB_HCD_XILINX
123 bool "Use Xilinx usb host EHCI controller core" 108 bool "Use Xilinx usb host EHCI controller core"
124 depends on (PPC32 || MICROBLAZE) 109 depends on (PPC32 || MICROBLAZE)
@@ -148,13 +133,11 @@ config USB_EHCI_MXC
148config USB_EHCI_HCD_OMAP 133config USB_EHCI_HCD_OMAP
149 tristate "EHCI support for OMAP3 and later chips" 134 tristate "EHCI support for OMAP3 and later chips"
150 depends on ARCH_OMAP 135 depends on ARCH_OMAP
136 select NOP_USB_XCEIV
151 default y 137 default y
152 ---help--- 138 ---help---
153 Enables support for the on-chip EHCI controller on 139 Enables support for the on-chip EHCI controller on
154 OMAP3 and later chips. 140 OMAP3 and later chips.
155 If your system uses a PHY on the USB port, you will need to
156 enable USB_PHY and the appropriate PHY driver as well. Most
157 boards need the NOP_USB_XCEIV PHY driver.
158 141
159config USB_EHCI_HCD_ORION 142config USB_EHCI_HCD_ORION
160 tristate "Support for Marvell EBU on-chip EHCI USB controller" 143 tristate "Support for Marvell EBU on-chip EHCI USB controller"
@@ -186,7 +169,6 @@ config USB_EHCI_HCD_AT91
186config USB_EHCI_MSM 169config USB_EHCI_MSM
187 tristate "Support for Qualcomm QSD/MSM on-chip EHCI USB controller" 170 tristate "Support for Qualcomm QSD/MSM on-chip EHCI USB controller"
188 depends on ARCH_MSM 171 depends on ARCH_MSM
189 depends on USB_PHY
190 select USB_EHCI_ROOT_HUB_TT 172 select USB_EHCI_ROOT_HUB_TT
191 select USB_MSM_OTG 173 select USB_MSM_OTG
192 ---help--- 174 ---help---
@@ -354,6 +336,18 @@ config USB_FUSBH200_HCD
354 To compile this driver as a module, choose M here: the 336 To compile this driver as a module, choose M here: the
355 module will be called fusbh200-hcd. 337 module will be called fusbh200-hcd.
356 338
339config USB_FOTG210_HCD
340 tristate "FOTG210 HCD support"
341 depends on USB
342 default N
343 ---help---
344 Faraday FOTG210 is an OTG controller which can be configured as
345 an USB2.0 host. It is designed to meet USB2.0 EHCI specification
346 with minor modification.
347
348 To compile this driver as a module, choose M here: the
349 module will be called fotg210-hcd.
350
357config USB_OHCI_HCD 351config USB_OHCI_HCD
358 tristate "OHCI HCD (USB 1.1) support" 352 tristate "OHCI HCD (USB 1.1) support"
359 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 353 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3
@@ -497,20 +491,6 @@ config USB_OCTEON_OHCI
497 controller. It is needed for low-speed USB 1.0 device 491 controller. It is needed for low-speed USB 1.0 device
498 support. All CN6XXX based chips with USB are supported. 492 support. All CN6XXX based chips with USB are supported.
499 493
500
501config USB_OHCI_BIG_ENDIAN_DESC
502 bool
503 default n
504
505config USB_OHCI_BIG_ENDIAN_MMIO
506 bool
507 default n
508
509config USB_OHCI_LITTLE_ENDIAN
510 bool
511 default n if STB03xxx || PPC_MPC52xx
512 default y
513
514endif # USB_OHCI_HCD 494endif # USB_OHCI_HCD
515 495
516config USB_UHCI_HCD 496config USB_UHCI_HCD
@@ -710,3 +690,20 @@ config USB_HCD_SSB
710 for ehci and ohci. 690 for ehci and ohci.
711 691
712 If unsure, say N. 692 If unsure, say N.
693
694config USB_HCD_TEST_MODE
695 bool "HCD test mode support"
696 ---help---
697 Say 'Y' to enable additional software test modes that may be
698 supported by the host controller drivers.
699
700 One such test mode is the Embedded High-speed Host Electrical Test
701 (EHSET) for EHCI host controller hardware, specifically the "Single
702 Step Set Feature" test. Typically this will be enabled for On-the-Go
703 or embedded hosts that need to undergo USB-IF compliance testing with
704 the aid of special testing hardware. In the future, this may expand
705 to include other tests that require support from a HCD driver.
706
707 This option is of interest only to developers who need to validate
708 their USB hardware designs. It is not needed for normal use. If
709 unsure, say N.
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index bea71127b15f..50b0041c09a9 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -4,6 +4,9 @@
4 4
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG 5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6 6
7# tell define_trace.h where to find the xhci trace header
8CFLAGS_xhci-trace.o := -I$(src)
9
7isp1760-y := isp1760-hcd.o isp1760-if.o 10isp1760-y := isp1760-hcd.o isp1760-if.o
8 11
9fhci-y := fhci-hcd.o fhci-hub.o fhci-q.o 12fhci-y := fhci-hcd.o fhci-hub.o fhci-q.o
@@ -13,6 +16,7 @@ fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o
13 16
14xhci-hcd-y := xhci.o xhci-mem.o 17xhci-hcd-y := xhci.o xhci-mem.o
15xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o 18xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o
19xhci-hcd-y += xhci-trace.o
16xhci-hcd-$(CONFIG_PCI) += xhci-pci.o 20xhci-hcd-$(CONFIG_PCI) += xhci-pci.o
17 21
18ifneq ($(CONFIG_USB_XHCI_PLATFORM), ) 22ifneq ($(CONFIG_USB_XHCI_PLATFORM), )
@@ -58,3 +62,4 @@ obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
58obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o 62obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o
59obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o 63obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o
60obj-$(CONFIG_USB_FUSBH200_HCD) += fusbh200-hcd.o 64obj-$(CONFIG_USB_FUSBH200_HCD) += fusbh200-hcd.o
65obj-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index bd831ec06dcd..e44f442e2fb7 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -57,7 +57,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
57 pr_debug("initializing FSL-SOC USB Controller\n"); 57 pr_debug("initializing FSL-SOC USB Controller\n");
58 58
59 /* Need platform data for setup */ 59 /* Need platform data for setup */
60 pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data; 60 pdata = (struct fsl_usb2_platform_data *)dev_get_platdata(&pdev->dev);
61 if (!pdata) { 61 if (!pdata) {
62 dev_err(&pdev->dev, 62 dev_err(&pdev->dev,
63 "No platform data for %s.\n", dev_name(&pdev->dev)); 63 "No platform data for %s.\n", dev_name(&pdev->dev));
@@ -190,7 +190,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
190static void usb_hcd_fsl_remove(struct usb_hcd *hcd, 190static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
191 struct platform_device *pdev) 191 struct platform_device *pdev)
192{ 192{
193 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 193 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
194 194
195 if (!IS_ERR_OR_NULL(hcd->phy)) { 195 if (!IS_ERR_OR_NULL(hcd->phy)) {
196 otg_set_host(hcd->phy->otg, NULL); 196 otg_set_host(hcd->phy->otg, NULL);
@@ -218,7 +218,7 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
218 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 218 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
219 void __iomem *non_ehci = hcd->regs; 219 void __iomem *non_ehci = hcd->regs;
220 struct device *dev = hcd->self.controller; 220 struct device *dev = hcd->self.controller;
221 struct fsl_usb2_platform_data *pdata = dev->platform_data; 221 struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
222 222
223 if (pdata->controller_ver < 0) { 223 if (pdata->controller_ver < 0) {
224 dev_warn(hcd->self.controller, "Could not get controller version\n"); 224 dev_warn(hcd->self.controller, "Could not get controller version\n");
@@ -291,7 +291,7 @@ static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)
291 struct fsl_usb2_platform_data *pdata; 291 struct fsl_usb2_platform_data *pdata;
292 void __iomem *non_ehci = hcd->regs; 292 void __iomem *non_ehci = hcd->regs;
293 293
294 pdata = hcd->self.controller->platform_data; 294 pdata = dev_get_platdata(hcd->self.controller);
295 295
296 if (pdata->have_sysif_regs) { 296 if (pdata->have_sysif_regs) {
297 /* 297 /*
@@ -363,7 +363,7 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
363 struct device *dev; 363 struct device *dev;
364 364
365 dev = hcd->self.controller; 365 dev = hcd->self.controller;
366 pdata = hcd->self.controller->platform_data; 366 pdata = dev_get_platdata(hcd->self.controller);
367 ehci->big_endian_desc = pdata->big_endian_desc; 367 ehci->big_endian_desc = pdata->big_endian_desc;
368 ehci->big_endian_mmio = pdata->big_endian_mmio; 368 ehci->big_endian_mmio = pdata->big_endian_mmio;
369 369
@@ -415,7 +415,7 @@ static int ehci_fsl_mpc512x_drv_suspend(struct device *dev)
415{ 415{
416 struct usb_hcd *hcd = dev_get_drvdata(dev); 416 struct usb_hcd *hcd = dev_get_drvdata(dev);
417 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 417 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
418 struct fsl_usb2_platform_data *pdata = dev->platform_data; 418 struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
419 u32 tmp; 419 u32 tmp;
420 420
421#ifdef DEBUG 421#ifdef DEBUG
@@ -484,7 +484,7 @@ static int ehci_fsl_mpc512x_drv_resume(struct device *dev)
484{ 484{
485 struct usb_hcd *hcd = dev_get_drvdata(dev); 485 struct usb_hcd *hcd = dev_get_drvdata(dev);
486 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 486 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
487 struct fsl_usb2_platform_data *pdata = dev->platform_data; 487 struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
488 u32 tmp; 488 u32 tmp;
489 489
490 dev_dbg(dev, "suspend=%d already_suspended=%d\n", 490 dev_dbg(dev, "suspend=%d already_suspended=%d\n",
@@ -669,7 +669,7 @@ static const struct hc_driver ehci_fsl_hc_driver = {
669 * generic hardware linkage 669 * generic hardware linkage
670 */ 670 */
671 .irq = ehci_irq, 671 .irq = ehci_irq,
672 .flags = HCD_USB2 | HCD_MEMORY, 672 .flags = HCD_USB2 | HCD_MEMORY | HCD_BH,
673 673
674 /* 674 /*
675 * basic lifecycle operations 675 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-grlib.c b/drivers/usb/host/ehci-grlib.c
index a77bd8dc33f4..b52a66ce92e8 100644
--- a/drivers/usb/host/ehci-grlib.c
+++ b/drivers/usb/host/ehci-grlib.c
@@ -43,7 +43,7 @@ static const struct hc_driver ehci_grlib_hc_driver = {
43 * generic hardware linkage 43 * generic hardware linkage
44 */ 44 */
45 .irq = ehci_irq, 45 .irq = ehci_irq,
46 .flags = HCD_MEMORY | HCD_USB2, 46 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
47 47
48 /* 48 /*
49 * basic lifecycle operations 49 * basic lifecycle operations
@@ -167,15 +167,6 @@ static int ehci_hcd_grlib_remove(struct platform_device *op)
167} 167}
168 168
169 169
170static void ehci_hcd_grlib_shutdown(struct platform_device *op)
171{
172 struct usb_hcd *hcd = platform_get_drvdata(op);
173
174 if (hcd->driver->shutdown)
175 hcd->driver->shutdown(hcd);
176}
177
178
179static const struct of_device_id ehci_hcd_grlib_of_match[] = { 170static const struct of_device_id ehci_hcd_grlib_of_match[] = {
180 { 171 {
181 .name = "GAISLER_EHCI", 172 .name = "GAISLER_EHCI",
@@ -191,7 +182,7 @@ MODULE_DEVICE_TABLE(of, ehci_hcd_grlib_of_match);
191static struct platform_driver ehci_grlib_driver = { 182static struct platform_driver ehci_grlib_driver = {
192 .probe = ehci_hcd_grlib_probe, 183 .probe = ehci_hcd_grlib_probe,
193 .remove = ehci_hcd_grlib_remove, 184 .remove = ehci_hcd_grlib_remove,
194 .shutdown = ehci_hcd_grlib_shutdown, 185 .shutdown = usb_hcd_platform_shutdown,
195 .driver = { 186 .driver = {
196 .name = "grlib-ehci", 187 .name = "grlib-ehci",
197 .owner = THIS_MODULE, 188 .owner = THIS_MODULE,
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 7abf1ce3a670..73c72997cd4f 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -487,6 +487,7 @@ static int ehci_init(struct usb_hcd *hcd)
487 ehci->periodic_size = DEFAULT_I_TDPS; 487 ehci->periodic_size = DEFAULT_I_TDPS;
488 INIT_LIST_HEAD(&ehci->async_unlink); 488 INIT_LIST_HEAD(&ehci->async_unlink);
489 INIT_LIST_HEAD(&ehci->async_idle); 489 INIT_LIST_HEAD(&ehci->async_idle);
490 INIT_LIST_HEAD(&ehci->intr_unlink_wait);
490 INIT_LIST_HEAD(&ehci->intr_unlink); 491 INIT_LIST_HEAD(&ehci->intr_unlink);
491 INIT_LIST_HEAD(&ehci->intr_qh_list); 492 INIT_LIST_HEAD(&ehci->intr_qh_list);
492 INIT_LIST_HEAD(&ehci->cached_itd_list); 493 INIT_LIST_HEAD(&ehci->cached_itd_list);
@@ -942,7 +943,7 @@ ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
942{ 943{
943 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 944 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
944 unsigned long flags; 945 unsigned long flags;
945 struct ehci_qh *qh, *tmp; 946 struct ehci_qh *qh;
946 947
947 /* ASSERT: any requests/urbs are being unlinked */ 948 /* ASSERT: any requests/urbs are being unlinked */
948 /* ASSERT: nobody can be submitting urbs for this any more */ 949 /* ASSERT: nobody can be submitting urbs for this any more */
@@ -972,17 +973,13 @@ rescan:
972 qh->qh_state = QH_STATE_IDLE; 973 qh->qh_state = QH_STATE_IDLE;
973 switch (qh->qh_state) { 974 switch (qh->qh_state) {
974 case QH_STATE_LINKED: 975 case QH_STATE_LINKED:
975 case QH_STATE_COMPLETING: 976 WARN_ON(!list_empty(&qh->qtd_list));
976 for (tmp = ehci->async->qh_next.qh; 977 if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_INT)
977 tmp && tmp != qh;
978 tmp = tmp->qh_next.qh)
979 continue;
980 /* periodic qh self-unlinks on empty, and a COMPLETING qh
981 * may already be unlinked.
982 */
983 if (tmp)
984 start_unlink_async(ehci, qh); 978 start_unlink_async(ehci, qh);
979 else
980 start_unlink_intr(ehci, qh);
985 /* FALL THROUGH */ 981 /* FALL THROUGH */
982 case QH_STATE_COMPLETING: /* already in unlinking */
986 case QH_STATE_UNLINK: /* wait for hw to finish? */ 983 case QH_STATE_UNLINK: /* wait for hw to finish? */
987 case QH_STATE_UNLINK_WAIT: 984 case QH_STATE_UNLINK_WAIT:
988idle_timeout: 985idle_timeout:
@@ -1169,7 +1166,7 @@ static const struct hc_driver ehci_hc_driver = {
1169 * generic hardware linkage 1166 * generic hardware linkage
1170 */ 1167 */
1171 .irq = ehci_irq, 1168 .irq = ehci_irq,
1172 .flags = HCD_MEMORY | HCD_USB2, 1169 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
1173 1170
1174 /* 1171 /*
1175 * basic lifecycle operations 1172 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 6dce37555c4f..3bf9f482710c 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -183,7 +183,7 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
183 spin_lock_irq(&ehci->lock); 183 spin_lock_irq(&ehci->lock);
184 184
185 /* clear phy low-power mode before changing wakeup flags */ 185 /* clear phy low-power mode before changing wakeup flags */
186 if (ehci->has_hostpc) { 186 if (ehci->has_tdi_phy_lpm) {
187 port = HCS_N_PORTS(ehci->hcs_params); 187 port = HCS_N_PORTS(ehci->hcs_params);
188 while (port--) { 188 while (port--) {
189 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port]; 189 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
@@ -217,7 +217,7 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
217 } 217 }
218 218
219 /* enter phy low-power mode again */ 219 /* enter phy low-power mode again */
220 if (ehci->has_hostpc) { 220 if (ehci->has_tdi_phy_lpm) {
221 port = HCS_N_PORTS(ehci->hcs_params); 221 port = HCS_N_PORTS(ehci->hcs_params);
222 while (port--) { 222 while (port--) {
223 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port]; 223 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
@@ -309,7 +309,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
309 } 309 }
310 } 310 }
311 311
312 if (changed && ehci->has_hostpc) { 312 if (changed && ehci->has_tdi_phy_lpm) {
313 spin_unlock_irq(&ehci->lock); 313 spin_unlock_irq(&ehci->lock);
314 msleep(5); /* 5 ms for HCD to enter low-power mode */ 314 msleep(5); /* 5 ms for HCD to enter low-power mode */
315 spin_lock_irq(&ehci->lock); 315 spin_lock_irq(&ehci->lock);
@@ -345,6 +345,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
345 345
346 end_unlink_async(ehci); 346 end_unlink_async(ehci);
347 unlink_empty_async_suspended(ehci); 347 unlink_empty_async_suspended(ehci);
348 ehci_handle_start_intr_unlinks(ehci);
348 ehci_handle_intr_unlinks(ehci); 349 ehci_handle_intr_unlinks(ehci);
349 end_free_itds(ehci); 350 end_free_itds(ehci);
350 351
@@ -435,7 +436,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
435 goto shutdown; 436 goto shutdown;
436 437
437 /* clear phy low-power mode before resume */ 438 /* clear phy low-power mode before resume */
438 if (ehci->bus_suspended && ehci->has_hostpc) { 439 if (ehci->bus_suspended && ehci->has_tdi_phy_lpm) {
439 i = HCS_N_PORTS(ehci->hcs_params); 440 i = HCS_N_PORTS(ehci->hcs_params);
440 while (i--) { 441 while (i--) {
441 if (test_bit(i, &ehci->bus_suspended)) { 442 if (test_bit(i, &ehci->bus_suspended)) {
@@ -711,6 +712,145 @@ ehci_hub_descriptor (
711} 712}
712 713
713/*-------------------------------------------------------------------------*/ 714/*-------------------------------------------------------------------------*/
715#ifdef CONFIG_USB_HCD_TEST_MODE
716
717#define EHSET_TEST_SINGLE_STEP_SET_FEATURE 0x06
718
719static void usb_ehset_completion(struct urb *urb)
720{
721 struct completion *done = urb->context;
722
723 complete(done);
724}
725static int submit_single_step_set_feature(
726 struct usb_hcd *hcd,
727 struct urb *urb,
728 int is_setup
729);
730
731/*
732 * Allocate and initialize a control URB. This request will be used by the
733 * EHSET SINGLE_STEP_SET_FEATURE test in which the DATA and STATUS stages
734 * of the GetDescriptor request are sent 15 seconds after the SETUP stage.
735 * Return NULL if failed.
736 */
737static struct urb *request_single_step_set_feature_urb(
738 struct usb_device *udev,
739 void *dr,
740 void *buf,
741 struct completion *done
742) {
743 struct urb *urb;
744 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
745 struct usb_host_endpoint *ep;
746
747 urb = usb_alloc_urb(0, GFP_KERNEL);
748 if (!urb)
749 return NULL;
750
751 urb->pipe = usb_rcvctrlpipe(udev, 0);
752 ep = (usb_pipein(urb->pipe) ? udev->ep_in : udev->ep_out)
753 [usb_pipeendpoint(urb->pipe)];
754 if (!ep) {
755 usb_free_urb(urb);
756 return NULL;
757 }
758
759 urb->ep = ep;
760 urb->dev = udev;
761 urb->setup_packet = (void *)dr;
762 urb->transfer_buffer = buf;
763 urb->transfer_buffer_length = USB_DT_DEVICE_SIZE;
764 urb->complete = usb_ehset_completion;
765 urb->status = -EINPROGRESS;
766 urb->actual_length = 0;
767 urb->transfer_flags = URB_DIR_IN;
768 usb_get_urb(urb);
769 atomic_inc(&urb->use_count);
770 atomic_inc(&urb->dev->urbnum);
771 urb->setup_dma = dma_map_single(
772 hcd->self.controller,
773 urb->setup_packet,
774 sizeof(struct usb_ctrlrequest),
775 DMA_TO_DEVICE);
776 urb->transfer_dma = dma_map_single(
777 hcd->self.controller,
778 urb->transfer_buffer,
779 urb->transfer_buffer_length,
780 DMA_FROM_DEVICE);
781 urb->context = done;
782 return urb;
783}
784
785static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
786{
787 int retval = -ENOMEM;
788 struct usb_ctrlrequest *dr;
789 struct urb *urb;
790 struct usb_device *udev;
791 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
792 struct usb_device_descriptor *buf;
793 DECLARE_COMPLETION_ONSTACK(done);
794
795 /* Obtain udev of the rhub's child port */
796 udev = usb_hub_find_child(hcd->self.root_hub, port);
797 if (!udev) {
798 ehci_err(ehci, "No device attached to the RootHub\n");
799 return -ENODEV;
800 }
801 buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);
802 if (!buf)
803 return -ENOMEM;
804
805 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
806 if (!dr) {
807 kfree(buf);
808 return -ENOMEM;
809 }
810
811 /* Fill Setup packet for GetDescriptor */
812 dr->bRequestType = USB_DIR_IN;
813 dr->bRequest = USB_REQ_GET_DESCRIPTOR;
814 dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8);
815 dr->wIndex = 0;
816 dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE);
817 urb = request_single_step_set_feature_urb(udev, dr, buf, &done);
818 if (!urb)
819 goto cleanup;
820
821 /* Submit just the SETUP stage */
822 retval = submit_single_step_set_feature(hcd, urb, 1);
823 if (retval)
824 goto out1;
825 if (!wait_for_completion_timeout(&done, msecs_to_jiffies(2000))) {
826 usb_kill_urb(urb);
827 retval = -ETIMEDOUT;
828 ehci_err(ehci, "%s SETUP stage timed out on ep0\n", __func__);
829 goto out1;
830 }
831 msleep(15 * 1000);
832
833 /* Complete remaining DATA and STATUS stages using the same URB */
834 urb->status = -EINPROGRESS;
835 usb_get_urb(urb);
836 atomic_inc(&urb->use_count);
837 atomic_inc(&urb->dev->urbnum);
838 retval = submit_single_step_set_feature(hcd, urb, 0);
839 if (!retval && !wait_for_completion_timeout(&done,
840 msecs_to_jiffies(2000))) {
841 usb_kill_urb(urb);
842 retval = -ETIMEDOUT;
843 ehci_err(ehci, "%s IN stage timed out on ep0\n", __func__);
844 }
845out1:
846 usb_free_urb(urb);
847cleanup:
848 kfree(dr);
849 kfree(buf);
850 return retval;
851}
852#endif /* CONFIG_USB_HCD_TEST_MODE */
853/*-------------------------------------------------------------------------*/
714 854
715static int ehci_hub_control ( 855static int ehci_hub_control (
716 struct usb_hcd *hcd, 856 struct usb_hcd *hcd,
@@ -788,7 +928,7 @@ static int ehci_hub_control (
788 goto error; 928 goto error;
789 929
790 /* clear phy low-power mode before resume */ 930 /* clear phy low-power mode before resume */
791 if (ehci->has_hostpc) { 931 if (ehci->has_tdi_phy_lpm) {
792 temp1 = ehci_readl(ehci, hostpc_reg); 932 temp1 = ehci_readl(ehci, hostpc_reg);
793 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD, 933 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
794 hostpc_reg); 934 hostpc_reg);
@@ -801,6 +941,8 @@ static int ehci_hub_control (
801 ehci_writel(ehci, temp | PORT_RESUME, status_reg); 941 ehci_writel(ehci, temp | PORT_RESUME, status_reg);
802 ehci->reset_done[wIndex] = jiffies 942 ehci->reset_done[wIndex] = jiffies
803 + msecs_to_jiffies(20); 943 + msecs_to_jiffies(20);
944 set_bit(wIndex, &ehci->resuming_ports);
945 usb_hcd_start_port_resume(&hcd->self, wIndex);
804 break; 946 break;
805 case USB_PORT_FEAT_C_SUSPEND: 947 case USB_PORT_FEAT_C_SUSPEND:
806 clear_bit(wIndex, &ehci->port_c_suspend); 948 clear_bit(wIndex, &ehci->port_c_suspend);
@@ -865,11 +1007,11 @@ static int ehci_hub_control (
865 } 1007 }
866 } 1008 }
867 1009
868 /* whoever resumes must GetPortStatus to complete it!! */ 1010 /* no reset or resume pending */
869 if (temp & PORT_RESUME) { 1011 if (!ehci->reset_done[wIndex]) {
870 1012
871 /* Remote Wakeup received? */ 1013 /* Remote Wakeup received? */
872 if (!ehci->reset_done[wIndex]) { 1014 if (temp & PORT_RESUME) {
873 /* resume signaling for 20 msec */ 1015 /* resume signaling for 20 msec */
874 ehci->reset_done[wIndex] = jiffies 1016 ehci->reset_done[wIndex] = jiffies
875 + msecs_to_jiffies(20); 1017 + msecs_to_jiffies(20);
@@ -880,38 +1022,34 @@ static int ehci_hub_control (
880 ehci->reset_done[wIndex]); 1022 ehci->reset_done[wIndex]);
881 } 1023 }
882 1024
883 /* resume completed? */ 1025 /* reset or resume not yet complete */
884 else if (time_after_eq(jiffies, 1026 } else if (!time_after_eq(jiffies, ehci->reset_done[wIndex])) {
885 ehci->reset_done[wIndex])) { 1027 ; /* wait until it is complete */
886 clear_bit(wIndex, &ehci->suspended_ports); 1028
887 set_bit(wIndex, &ehci->port_c_suspend); 1029 /* resume completed */
888 ehci->reset_done[wIndex] = 0; 1030 } else if (test_bit(wIndex, &ehci->resuming_ports)) {
889 usb_hcd_end_port_resume(&hcd->self, wIndex); 1031 clear_bit(wIndex, &ehci->suspended_ports);
890 1032 set_bit(wIndex, &ehci->port_c_suspend);
891 /* stop resume signaling */ 1033 ehci->reset_done[wIndex] = 0;
892 temp &= ~(PORT_RWC_BITS | 1034 usb_hcd_end_port_resume(&hcd->self, wIndex);
893 PORT_SUSPEND | PORT_RESUME); 1035
894 ehci_writel(ehci, temp, status_reg); 1036 /* stop resume signaling */
895 clear_bit(wIndex, &ehci->resuming_ports); 1037 temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
896 retval = ehci_handshake(ehci, status_reg, 1038 ehci_writel(ehci, temp, status_reg);
897 PORT_RESUME, 0, 2000 /* 2msec */); 1039 clear_bit(wIndex, &ehci->resuming_ports);
898 if (retval != 0) { 1040 retval = ehci_handshake(ehci, status_reg,
899 ehci_err(ehci, 1041 PORT_RESUME, 0, 2000 /* 2msec */);
900 "port %d resume error %d\n", 1042 if (retval != 0) {
1043 ehci_err(ehci, "port %d resume error %d\n",
901 wIndex + 1, retval); 1044 wIndex + 1, retval);
902 goto error; 1045 goto error;
903 }
904 temp = ehci_readl(ehci, status_reg);
905 } 1046 }
906 } 1047 temp = ehci_readl(ehci, status_reg);
907 1048
908 /* whoever resets must GetPortStatus to complete it!! */ 1049 /* whoever resets must GetPortStatus to complete it!! */
909 if ((temp & PORT_RESET) 1050 } else {
910 && time_after_eq(jiffies,
911 ehci->reset_done[wIndex])) {
912 status |= USB_PORT_STAT_C_RESET << 16; 1051 status |= USB_PORT_STAT_C_RESET << 16;
913 ehci->reset_done [wIndex] = 0; 1052 ehci->reset_done [wIndex] = 0;
914 clear_bit(wIndex, &ehci->resuming_ports);
915 1053
916 /* force reset to complete */ 1054 /* force reset to complete */
917 ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET), 1055 ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
@@ -932,11 +1070,6 @@ static int ehci_hub_control (
932 ehci_readl(ehci, status_reg)); 1070 ehci_readl(ehci, status_reg));
933 } 1071 }
934 1072
935 if (!(temp & (PORT_RESUME|PORT_RESET))) {
936 ehci->reset_done[wIndex] = 0;
937 clear_bit(wIndex, &ehci->resuming_ports);
938 }
939
940 /* transfer dedicated ports to the companion hc */ 1073 /* transfer dedicated ports to the companion hc */
941 if ((temp & PORT_CONNECT) && 1074 if ((temp & PORT_CONNECT) &&
942 test_bit(wIndex, &ehci->companion_ports)) { 1075 test_bit(wIndex, &ehci->companion_ports)) {
@@ -1032,12 +1165,12 @@ static int ehci_hub_control (
1032 1165
1033 /* After above check the port must be connected. 1166 /* After above check the port must be connected.
1034 * Set appropriate bit thus could put phy into low power 1167 * Set appropriate bit thus could put phy into low power
1035 * mode if we have hostpc feature 1168 * mode if we have tdi_phy_lpm feature
1036 */ 1169 */
1037 temp &= ~PORT_WKCONN_E; 1170 temp &= ~PORT_WKCONN_E;
1038 temp |= PORT_WKDISC_E | PORT_WKOC_E; 1171 temp |= PORT_WKDISC_E | PORT_WKOC_E;
1039 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); 1172 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
1040 if (ehci->has_hostpc) { 1173 if (ehci->has_tdi_phy_lpm) {
1041 spin_unlock_irqrestore(&ehci->lock, flags); 1174 spin_unlock_irqrestore(&ehci->lock, flags);
1042 msleep(5);/* 5ms for HCD enter low pwr mode */ 1175 msleep(5);/* 5ms for HCD enter low pwr mode */
1043 spin_lock_irqsave(&ehci->lock, flags); 1176 spin_lock_irqsave(&ehci->lock, flags);
@@ -1057,7 +1190,7 @@ static int ehci_hub_control (
1057 status_reg); 1190 status_reg);
1058 break; 1191 break;
1059 case USB_PORT_FEAT_RESET: 1192 case USB_PORT_FEAT_RESET:
1060 if (temp & PORT_RESUME) 1193 if (temp & (PORT_SUSPEND|PORT_RESUME))
1061 goto error; 1194 goto error;
1062 /* line status bits may report this as low speed, 1195 /* line status bits may report this as low speed,
1063 * which can be fine if this root hub has a 1196 * which can be fine if this root hub has a
@@ -1092,6 +1225,15 @@ static int ehci_hub_control (
1092 * about the EHCI-specific stuff. 1225 * about the EHCI-specific stuff.
1093 */ 1226 */
1094 case USB_PORT_FEAT_TEST: 1227 case USB_PORT_FEAT_TEST:
1228#ifdef CONFIG_USB_HCD_TEST_MODE
1229 if (selector == EHSET_TEST_SINGLE_STEP_SET_FEATURE) {
1230 spin_unlock_irqrestore(&ehci->lock, flags);
1231 retval = ehset_single_step_set_feature(hcd,
1232 wIndex);
1233 spin_lock_irqsave(&ehci->lock, flags);
1234 break;
1235 }
1236#endif
1095 if (!selector || selector > 5) 1237 if (!selector || selector > 5)
1096 goto error; 1238 goto error;
1097 spin_unlock_irqrestore(&ehci->lock, flags); 1239 spin_unlock_irqrestore(&ehci->lock, flags);
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index ef2c3a1eca4b..52a77734a225 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -93,6 +93,7 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags)
93 qh->qh_dma = dma; 93 qh->qh_dma = dma;
94 // INIT_LIST_HEAD (&qh->qh_list); 94 // INIT_LIST_HEAD (&qh->qh_list);
95 INIT_LIST_HEAD (&qh->qtd_list); 95 INIT_LIST_HEAD (&qh->qtd_list);
96 INIT_LIST_HEAD(&qh->unlink_node);
96 97
97 /* dummy td enables safe urb queuing */ 98 /* dummy td enables safe urb queuing */
98 qh->dummy = ehci_qtd_alloc (ehci, flags); 99 qh->dummy = ehci_qtd_alloc (ehci, flags);
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index 915c2db96dce..417c10da9450 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -96,7 +96,7 @@ static const struct hc_driver mv_ehci_hc_driver = {
96 * generic hardware linkage 96 * generic hardware linkage
97 */ 97 */
98 .irq = ehci_irq, 98 .irq = ehci_irq,
99 .flags = HCD_MEMORY | HCD_USB2, 99 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
100 100
101 /* 101 /*
102 * basic lifecycle operations 102 * basic lifecycle operations
@@ -131,7 +131,7 @@ static const struct hc_driver mv_ehci_hc_driver = {
131 131
132static int mv_ehci_probe(struct platform_device *pdev) 132static int mv_ehci_probe(struct platform_device *pdev)
133{ 133{
134 struct mv_usb_platform_data *pdata = pdev->dev.platform_data; 134 struct mv_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
135 struct usb_hcd *hcd; 135 struct usb_hcd *hcd;
136 struct ehci_hcd *ehci; 136 struct ehci_hcd *ehci;
137 struct ehci_hcd_mv *ehci_mv; 137 struct ehci_hcd_mv *ehci_mv;
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
index e4c34ac386c0..5899ad6626c7 100644
--- a/drivers/usb/host/ehci-mxc.c
+++ b/drivers/usb/host/ehci-mxc.c
@@ -49,7 +49,7 @@ static const struct ehci_driver_overrides ehci_mxc_overrides __initconst = {
49 49
50static int ehci_mxc_drv_probe(struct platform_device *pdev) 50static int ehci_mxc_drv_probe(struct platform_device *pdev)
51{ 51{
52 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; 52 struct mxc_usbh_platform_data *pdata = dev_get_platdata(&pdev->dev);
53 struct usb_hcd *hcd; 53 struct usb_hcd *hcd;
54 struct resource *res; 54 struct resource *res;
55 int irq, ret; 55 int irq, ret;
@@ -174,7 +174,7 @@ err_alloc:
174 174
175static int ehci_mxc_drv_remove(struct platform_device *pdev) 175static int ehci_mxc_drv_remove(struct platform_device *pdev)
176{ 176{
177 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; 177 struct mxc_usbh_platform_data *pdata = dev_get_platdata(&pdev->dev);
178 struct usb_hcd *hcd = platform_get_drvdata(pdev); 178 struct usb_hcd *hcd = platform_get_drvdata(pdev);
179 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 179 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
180 struct ehci_mxc_priv *priv = (struct ehci_mxc_priv *) ehci->priv; 180 struct ehci_mxc_priv *priv = (struct ehci_mxc_priv *) ehci->priv;
@@ -197,20 +197,12 @@ static int ehci_mxc_drv_remove(struct platform_device *pdev)
197 return 0; 197 return 0;
198} 198}
199 199
200static void ehci_mxc_drv_shutdown(struct platform_device *pdev)
201{
202 struct usb_hcd *hcd = platform_get_drvdata(pdev);
203
204 if (hcd->driver->shutdown)
205 hcd->driver->shutdown(hcd);
206}
207
208MODULE_ALIAS("platform:mxc-ehci"); 200MODULE_ALIAS("platform:mxc-ehci");
209 201
210static struct platform_driver ehci_mxc_driver = { 202static struct platform_driver ehci_mxc_driver = {
211 .probe = ehci_mxc_drv_probe, 203 .probe = ehci_mxc_drv_probe,
212 .remove = ehci_mxc_drv_remove, 204 .remove = ehci_mxc_drv_remove,
213 .shutdown = ehci_mxc_drv_shutdown, 205 .shutdown = usb_hcd_platform_shutdown,
214 .driver = { 206 .driver = {
215 .name = "mxc-ehci", 207 .name = "mxc-ehci",
216 }, 208 },
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c
index 45cc00158412..ab0397e4d8f3 100644
--- a/drivers/usb/host/ehci-octeon.c
+++ b/drivers/usb/host/ehci-octeon.c
@@ -51,7 +51,7 @@ static const struct hc_driver ehci_octeon_hc_driver = {
51 * generic hardware linkage 51 * generic hardware linkage
52 */ 52 */
53 .irq = ehci_irq, 53 .irq = ehci_irq,
54 .flags = HCD_MEMORY | HCD_USB2, 54 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
55 55
56 /* 56 /*
57 * basic lifecycle operations 57 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 9bd7dfe3315b..78b01fa475bb 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -100,7 +100,7 @@ static const struct ehci_driver_overrides ehci_omap_overrides __initdata = {
100static int ehci_hcd_omap_probe(struct platform_device *pdev) 100static int ehci_hcd_omap_probe(struct platform_device *pdev)
101{ 101{
102 struct device *dev = &pdev->dev; 102 struct device *dev = &pdev->dev;
103 struct usbhs_omap_platform_data *pdata = dev->platform_data; 103 struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev);
104 struct resource *res; 104 struct resource *res;
105 struct usb_hcd *hcd; 105 struct usb_hcd *hcd;
106 void __iomem *regs; 106 void __iomem *regs;
@@ -119,7 +119,7 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
119 119
120 /* For DT boot, get platform data from parent. i.e. usbhshost */ 120 /* For DT boot, get platform data from parent. i.e. usbhshost */
121 if (dev->of_node) { 121 if (dev->of_node) {
122 pdata = dev->parent->platform_data; 122 pdata = dev_get_platdata(dev->parent);
123 dev->platform_data = pdata; 123 dev->platform_data = pdata;
124 } 124 }
125 125
@@ -278,14 +278,6 @@ static int ehci_hcd_omap_remove(struct platform_device *pdev)
278 return 0; 278 return 0;
279} 279}
280 280
281static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
282{
283 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
284
285 if (hcd->driver->shutdown)
286 hcd->driver->shutdown(hcd);
287}
288
289static const struct of_device_id omap_ehci_dt_ids[] = { 281static const struct of_device_id omap_ehci_dt_ids[] = {
290 { .compatible = "ti,ehci-omap" }, 282 { .compatible = "ti,ehci-omap" },
291 { } 283 { }
@@ -296,7 +288,7 @@ MODULE_DEVICE_TABLE(of, omap_ehci_dt_ids);
296static struct platform_driver ehci_hcd_omap_driver = { 288static struct platform_driver ehci_hcd_omap_driver = {
297 .probe = ehci_hcd_omap_probe, 289 .probe = ehci_hcd_omap_probe,
298 .remove = ehci_hcd_omap_remove, 290 .remove = ehci_hcd_omap_remove,
299 .shutdown = ehci_hcd_omap_shutdown, 291 .shutdown = usb_hcd_platform_shutdown,
300 /*.suspend = ehci_hcd_omap_suspend, */ 292 /*.suspend = ehci_hcd_omap_suspend, */
301 /*.resume = ehci_hcd_omap_resume, */ 293 /*.resume = ehci_hcd_omap_resume, */
302 .driver = { 294 .driver = {
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 1a450aa13ebf..d1dfb9db5b42 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -139,7 +139,7 @@ ehci_orion_conf_mbus_windows(struct usb_hcd *hcd,
139 139
140static int ehci_orion_drv_probe(struct platform_device *pdev) 140static int ehci_orion_drv_probe(struct platform_device *pdev)
141{ 141{
142 struct orion_ehci_data *pd = pdev->dev.platform_data; 142 struct orion_ehci_data *pd = dev_get_platdata(&pdev->dev);
143 const struct mbus_dram_target_info *dram; 143 const struct mbus_dram_target_info *dram;
144 struct resource *res; 144 struct resource *res;
145 struct usb_hcd *hcd; 145 struct usb_hcd *hcd;
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 595d210655b6..6bd299e61f58 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -315,53 +315,11 @@ done:
315 * Also they depend on separate root hub suspend/resume. 315 * Also they depend on separate root hub suspend/resume.
316 */ 316 */
317 317
318static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
319{
320 return pdev->class == PCI_CLASS_SERIAL_USB_EHCI &&
321 pdev->vendor == PCI_VENDOR_ID_INTEL &&
322 (pdev->device == 0x1E26 ||
323 pdev->device == 0x8C2D ||
324 pdev->device == 0x8C26 ||
325 pdev->device == 0x9C26);
326}
327
328static void ehci_enable_xhci_companion(void)
329{
330 struct pci_dev *companion = NULL;
331
332 /* The xHCI and EHCI controllers are not on the same PCI slot */
333 for_each_pci_dev(companion) {
334 if (!usb_is_intel_switchable_xhci(companion))
335 continue;
336 usb_enable_xhci_ports(companion);
337 return;
338 }
339}
340
341static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated) 318static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
342{ 319{
343 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 320 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
344 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 321 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
345 322
346 /* The BIOS on systems with the Intel Panther Point chipset may or may
347 * not support xHCI natively. That means that during system resume, it
348 * may switch the ports back to EHCI so that users can use their
349 * keyboard to select a kernel from GRUB after resume from hibernate.
350 *
351 * The BIOS is supposed to remember whether the OS had xHCI ports
352 * enabled before resume, and switch the ports back to xHCI when the
353 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
354 * writers.
355 *
356 * Unconditionally switch the ports back to xHCI after a system resume.
357 * We can't tell whether the EHCI or xHCI controller will be resumed
358 * first, so we have to do the port switchover in both drivers. Writing
359 * a '1' to the port switchover registers should have no effect if the
360 * port was already switched over.
361 */
362 if (usb_is_intel_switchable_ehci(pdev))
363 ehci_enable_xhci_companion();
364
365 if (ehci_resume(hcd, hibernated) != 0) 323 if (ehci_resume(hcd, hibernated) != 0)
366 (void) ehci_pci_reinit(ehci, pdev); 324 (void) ehci_pci_reinit(ehci, pdev);
367 return 0; 325 return 0;
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index 5196d728517d..f6b790ca8cf2 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -39,7 +39,7 @@ static const char hcd_name[] = "ehci-platform";
39static int ehci_platform_reset(struct usb_hcd *hcd) 39static int ehci_platform_reset(struct usb_hcd *hcd)
40{ 40{
41 struct platform_device *pdev = to_platform_device(hcd->self.controller); 41 struct platform_device *pdev = to_platform_device(hcd->self.controller);
42 struct usb_ehci_pdata *pdata = pdev->dev.platform_data; 42 struct usb_ehci_pdata *pdata = dev_get_platdata(&pdev->dev);
43 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 43 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
44 int retval; 44 int retval;
45 45
@@ -87,14 +87,14 @@ static int ehci_platform_probe(struct platform_device *dev)
87 * use reasonable defaults so platforms don't have to provide these. 87 * use reasonable defaults so platforms don't have to provide these.
88 * with DT probing on ARM, none of these are set. 88 * with DT probing on ARM, none of these are set.
89 */ 89 */
90 if (!dev->dev.platform_data) 90 if (!dev_get_platdata(&dev->dev))
91 dev->dev.platform_data = &ehci_platform_defaults; 91 dev->dev.platform_data = &ehci_platform_defaults;
92 if (!dev->dev.dma_mask) 92 if (!dev->dev.dma_mask)
93 dev->dev.dma_mask = &dev->dev.coherent_dma_mask; 93 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
94 if (!dev->dev.coherent_dma_mask) 94 if (!dev->dev.coherent_dma_mask)
95 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 95 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
96 96
97 pdata = dev->dev.platform_data; 97 pdata = dev_get_platdata(&dev->dev);
98 98
99 irq = platform_get_irq(dev, 0); 99 irq = platform_get_irq(dev, 0);
100 if (irq < 0) { 100 if (irq < 0) {
@@ -148,7 +148,7 @@ err_power:
148static int ehci_platform_remove(struct platform_device *dev) 148static int ehci_platform_remove(struct platform_device *dev)
149{ 149{
150 struct usb_hcd *hcd = platform_get_drvdata(dev); 150 struct usb_hcd *hcd = platform_get_drvdata(dev);
151 struct usb_ehci_pdata *pdata = dev->dev.platform_data; 151 struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
152 152
153 usb_remove_hcd(hcd); 153 usb_remove_hcd(hcd);
154 usb_put_hcd(hcd); 154 usb_put_hcd(hcd);
@@ -167,7 +167,7 @@ static int ehci_platform_remove(struct platform_device *dev)
167static int ehci_platform_suspend(struct device *dev) 167static int ehci_platform_suspend(struct device *dev)
168{ 168{
169 struct usb_hcd *hcd = dev_get_drvdata(dev); 169 struct usb_hcd *hcd = dev_get_drvdata(dev);
170 struct usb_ehci_pdata *pdata = dev->platform_data; 170 struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
171 struct platform_device *pdev = 171 struct platform_device *pdev =
172 container_of(dev, struct platform_device, dev); 172 container_of(dev, struct platform_device, dev);
173 bool do_wakeup = device_may_wakeup(dev); 173 bool do_wakeup = device_may_wakeup(dev);
@@ -184,7 +184,7 @@ static int ehci_platform_suspend(struct device *dev)
184static int ehci_platform_resume(struct device *dev) 184static int ehci_platform_resume(struct device *dev)
185{ 185{
186 struct usb_hcd *hcd = dev_get_drvdata(dev); 186 struct usb_hcd *hcd = dev_get_drvdata(dev);
187 struct usb_ehci_pdata *pdata = dev->platform_data; 187 struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
188 struct platform_device *pdev = 188 struct platform_device *pdev =
189 container_of(dev, struct platform_device, dev); 189 container_of(dev, struct platform_device, dev);
190 190
diff --git a/drivers/usb/host/ehci-pmcmsp.c b/drivers/usb/host/ehci-pmcmsp.c
index 601e208bd782..893b707f0000 100644
--- a/drivers/usb/host/ehci-pmcmsp.c
+++ b/drivers/usb/host/ehci-pmcmsp.c
@@ -286,7 +286,7 @@ static const struct hc_driver ehci_msp_hc_driver = {
286#else 286#else
287 .irq = ehci_irq, 287 .irq = ehci_irq,
288#endif 288#endif
289 .flags = HCD_MEMORY | HCD_USB2, 289 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
290 290
291 /* 291 /*
292 * basic lifecycle operations 292 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 86da09c0f8d0..6cc5567bf9c8 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -28,7 +28,7 @@ static const struct hc_driver ehci_ppc_of_hc_driver = {
28 * generic hardware linkage 28 * generic hardware linkage
29 */ 29 */
30 .irq = ehci_irq, 30 .irq = ehci_irq,
31 .flags = HCD_MEMORY | HCD_USB2, 31 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
32 32
33 /* 33 /*
34 * basic lifecycle operations 34 * basic lifecycle operations
@@ -215,15 +215,6 @@ static int ehci_hcd_ppc_of_remove(struct platform_device *op)
215} 215}
216 216
217 217
218static void ehci_hcd_ppc_of_shutdown(struct platform_device *op)
219{
220 struct usb_hcd *hcd = platform_get_drvdata(op);
221
222 if (hcd->driver->shutdown)
223 hcd->driver->shutdown(hcd);
224}
225
226
227static const struct of_device_id ehci_hcd_ppc_of_match[] = { 218static const struct of_device_id ehci_hcd_ppc_of_match[] = {
228 { 219 {
229 .compatible = "usb-ehci", 220 .compatible = "usb-ehci",
@@ -236,7 +227,7 @@ MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match);
236static struct platform_driver ehci_hcd_ppc_of_driver = { 227static struct platform_driver ehci_hcd_ppc_of_driver = {
237 .probe = ehci_hcd_ppc_of_probe, 228 .probe = ehci_hcd_ppc_of_probe,
238 .remove = ehci_hcd_ppc_of_remove, 229 .remove = ehci_hcd_ppc_of_remove,
239 .shutdown = ehci_hcd_ppc_of_shutdown, 230 .shutdown = usb_hcd_platform_shutdown,
240 .driver = { 231 .driver = {
241 .name = "ppc-of-ehci", 232 .name = "ppc-of-ehci",
242 .owner = THIS_MODULE, 233 .owner = THIS_MODULE,
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index fd983771b025..8188542ba17e 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -71,7 +71,7 @@ static const struct hc_driver ps3_ehci_hc_driver = {
71 .product_desc = "PS3 EHCI Host Controller", 71 .product_desc = "PS3 EHCI Host Controller",
72 .hcd_priv_size = sizeof(struct ehci_hcd), 72 .hcd_priv_size = sizeof(struct ehci_hcd),
73 .irq = ehci_irq, 73 .irq = ehci_irq,
74 .flags = HCD_MEMORY | HCD_USB2, 74 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
75 .reset = ps3_ehci_hc_reset, 75 .reset = ps3_ehci_hc_reset,
76 .start = ehci_run, 76 .start = ehci_run,
77 .stop = ehci_stop, 77 .stop = ehci_stop,
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index d34b399b78e2..33336874c47b 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -254,8 +254,6 @@ static int qtd_copy_status (
254 254
255static void 255static void
256ehci_urb_done(struct ehci_hcd *ehci, struct urb *urb, int status) 256ehci_urb_done(struct ehci_hcd *ehci, struct urb *urb, int status)
257__releases(ehci->lock)
258__acquires(ehci->lock)
259{ 257{
260 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { 258 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
261 /* ... update hc-wide periodic stats */ 259 /* ... update hc-wide periodic stats */
@@ -281,11 +279,8 @@ __acquires(ehci->lock)
281 urb->actual_length, urb->transfer_buffer_length); 279 urb->actual_length, urb->transfer_buffer_length);
282#endif 280#endif
283 281
284 /* complete() can reenter this HCD */
285 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); 282 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
286 spin_unlock (&ehci->lock);
287 usb_hcd_giveback_urb(ehci_to_hcd(ehci), urb, status); 283 usb_hcd_giveback_urb(ehci_to_hcd(ehci), urb, status);
288 spin_lock (&ehci->lock);
289} 284}
290 285
291static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); 286static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh);
@@ -1144,6 +1139,109 @@ submit_async (
1144} 1139}
1145 1140
1146/*-------------------------------------------------------------------------*/ 1141/*-------------------------------------------------------------------------*/
1142#ifdef CONFIG_USB_HCD_TEST_MODE
1143/*
1144 * This function creates the qtds and submits them for the
1145 * SINGLE_STEP_SET_FEATURE Test.
1146 * This is done in two parts: first SETUP req for GetDesc is sent then
1147 * 15 seconds later, the IN stage for GetDesc starts to req data from dev
1148 *
1149 * is_setup : i/p arguement decides which of the two stage needs to be
1150 * performed; TRUE - SETUP and FALSE - IN+STATUS
1151 * Returns 0 if success
1152 */
1153static int submit_single_step_set_feature(
1154 struct usb_hcd *hcd,
1155 struct urb *urb,
1156 int is_setup
1157) {
1158 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1159 struct list_head qtd_list;
1160 struct list_head *head;
1161
1162 struct ehci_qtd *qtd, *qtd_prev;
1163 dma_addr_t buf;
1164 int len, maxpacket;
1165 u32 token;
1166
1167 INIT_LIST_HEAD(&qtd_list);
1168 head = &qtd_list;
1169
1170 /* URBs map to sequences of QTDs: one logical transaction */
1171 qtd = ehci_qtd_alloc(ehci, GFP_KERNEL);
1172 if (unlikely(!qtd))
1173 return -1;
1174 list_add_tail(&qtd->qtd_list, head);
1175 qtd->urb = urb;
1176
1177 token = QTD_STS_ACTIVE;
1178 token |= (EHCI_TUNE_CERR << 10);
1179
1180 len = urb->transfer_buffer_length;
1181 /*
1182 * Check if the request is to perform just the SETUP stage (getDesc)
1183 * as in SINGLE_STEP_SET_FEATURE test, DATA stage (IN) happens
1184 * 15 secs after the setup
1185 */
1186 if (is_setup) {
1187 /* SETUP pid */
1188 qtd_fill(ehci, qtd, urb->setup_dma,
1189 sizeof(struct usb_ctrlrequest),
1190 token | (2 /* "setup" */ << 8), 8);
1191
1192 submit_async(ehci, urb, &qtd_list, GFP_ATOMIC);
1193 return 0; /*Return now; we shall come back after 15 seconds*/
1194 }
1195
1196 /*
1197 * IN: data transfer stage: buffer setup : start the IN txn phase for
1198 * the get_Desc SETUP which was sent 15seconds back
1199 */
1200 token ^= QTD_TOGGLE; /*We need to start IN with DATA-1 Pid-sequence*/
1201 buf = urb->transfer_dma;
1202
1203 token |= (1 /* "in" */ << 8); /*This is IN stage*/
1204
1205 maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, 0));
1206
1207 qtd_fill(ehci, qtd, buf, len, token, maxpacket);
1208
1209 /*
1210 * Our IN phase shall always be a short read; so keep the queue running
1211 * and let it advance to the next qtd which zero length OUT status
1212 */
1213 qtd->hw_alt_next = EHCI_LIST_END(ehci);
1214
1215 /* STATUS stage for GetDesc control request */
1216 token ^= 0x0100; /* "in" <--> "out" */
1217 token |= QTD_TOGGLE; /* force DATA1 */
1218
1219 qtd_prev = qtd;
1220 qtd = ehci_qtd_alloc(ehci, GFP_ATOMIC);
1221 if (unlikely(!qtd))
1222 goto cleanup;
1223 qtd->urb = urb;
1224 qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma);
1225 list_add_tail(&qtd->qtd_list, head);
1226
1227 /* dont fill any data in such packets */
1228 qtd_fill(ehci, qtd, 0, 0, token, 0);
1229
1230 /* by default, enable interrupt on urb completion */
1231 if (likely(!(urb->transfer_flags & URB_NO_INTERRUPT)))
1232 qtd->hw_token |= cpu_to_hc32(ehci, QTD_IOC);
1233
1234 submit_async(ehci, urb, &qtd_list, GFP_KERNEL);
1235
1236 return 0;
1237
1238cleanup:
1239 qtd_list_free(ehci, urb, head);
1240 return -1;
1241}
1242#endif /* CONFIG_USB_HCD_TEST_MODE */
1243
1244/*-------------------------------------------------------------------------*/
1147 1245
1148static void single_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh) 1246static void single_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1149{ 1247{
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c
index 7cc26e621aa7..7c3de95c7054 100644
--- a/drivers/usb/host/ehci-s5p.c
+++ b/drivers/usb/host/ehci-s5p.c
@@ -75,7 +75,7 @@ static void s5p_setup_vbus_gpio(struct platform_device *pdev)
75 75
76static int s5p_ehci_probe(struct platform_device *pdev) 76static int s5p_ehci_probe(struct platform_device *pdev)
77{ 77{
78 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 78 struct s5p_ehci_platdata *pdata = dev_get_platdata(&pdev->dev);
79 struct s5p_ehci_hcd *s5p_ehci; 79 struct s5p_ehci_hcd *s5p_ehci;
80 struct usb_hcd *hcd; 80 struct usb_hcd *hcd;
81 struct ehci_hcd *ehci; 81 struct ehci_hcd *ehci;
@@ -220,14 +220,6 @@ static int s5p_ehci_remove(struct platform_device *pdev)
220 return 0; 220 return 0;
221} 221}
222 222
223static void s5p_ehci_shutdown(struct platform_device *pdev)
224{
225 struct usb_hcd *hcd = platform_get_drvdata(pdev);
226
227 if (hcd->driver->shutdown)
228 hcd->driver->shutdown(hcd);
229}
230
231#ifdef CONFIG_PM 223#ifdef CONFIG_PM
232static int s5p_ehci_suspend(struct device *dev) 224static int s5p_ehci_suspend(struct device *dev)
233{ 225{
@@ -297,7 +289,7 @@ MODULE_DEVICE_TABLE(of, exynos_ehci_match);
297static struct platform_driver s5p_ehci_driver = { 289static struct platform_driver s5p_ehci_driver = {
298 .probe = s5p_ehci_probe, 290 .probe = s5p_ehci_probe,
299 .remove = s5p_ehci_remove, 291 .remove = s5p_ehci_remove,
300 .shutdown = s5p_ehci_shutdown, 292 .shutdown = usb_hcd_platform_shutdown,
301 .driver = { 293 .driver = {
302 .name = "s5p-ehci", 294 .name = "s5p-ehci",
303 .owner = THIS_MODULE, 295 .owner = THIS_MODULE,
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 8e3c878f38cf..66310894ad97 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -601,12 +601,29 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
601 list_del(&qh->intr_node); 601 list_del(&qh->intr_node);
602} 602}
603 603
604static void cancel_unlink_wait_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
605{
606 if (qh->qh_state != QH_STATE_LINKED ||
607 list_empty(&qh->unlink_node))
608 return;
609
610 list_del_init(&qh->unlink_node);
611
612 /*
613 * TODO: disable the event of EHCI_HRTIMER_START_UNLINK_INTR for
614 * avoiding unnecessary CPU wakeup
615 */
616}
617
604static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh) 618static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
605{ 619{
606 /* If the QH isn't linked then there's nothing we can do. */ 620 /* If the QH isn't linked then there's nothing we can do. */
607 if (qh->qh_state != QH_STATE_LINKED) 621 if (qh->qh_state != QH_STATE_LINKED)
608 return; 622 return;
609 623
624 /* if the qh is waiting for unlink, cancel it now */
625 cancel_unlink_wait_intr(ehci, qh);
626
610 qh_unlink_periodic (ehci, qh); 627 qh_unlink_periodic (ehci, qh);
611 628
612 /* Make sure the unlinks are visible before starting the timer */ 629 /* Make sure the unlinks are visible before starting the timer */
@@ -632,6 +649,27 @@ static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
632 } 649 }
633} 650}
634 651
652/*
653 * It is common only one intr URB is scheduled on one qh, and
654 * given complete() is run in tasklet context, introduce a bit
655 * delay to avoid unlink qh too early.
656 */
657static void start_unlink_intr_wait(struct ehci_hcd *ehci,
658 struct ehci_qh *qh)
659{
660 qh->unlink_cycle = ehci->intr_unlink_wait_cycle;
661
662 /* New entries go at the end of the intr_unlink_wait list */
663 list_add_tail(&qh->unlink_node, &ehci->intr_unlink_wait);
664
665 if (ehci->rh_state < EHCI_RH_RUNNING)
666 ehci_handle_start_intr_unlinks(ehci);
667 else if (ehci->intr_unlink_wait.next == &qh->unlink_node) {
668 ehci_enable_event(ehci, EHCI_HRTIMER_START_UNLINK_INTR, true);
669 ++ehci->intr_unlink_wait_cycle;
670 }
671}
672
635static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh) 673static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
636{ 674{
637 struct ehci_qh_hw *hw = qh->hw; 675 struct ehci_qh_hw *hw = qh->hw;
@@ -889,6 +927,9 @@ static int intr_submit (
889 if (qh->qh_state == QH_STATE_IDLE) { 927 if (qh->qh_state == QH_STATE_IDLE) {
890 qh_refresh(ehci, qh); 928 qh_refresh(ehci, qh);
891 qh_link_periodic(ehci, qh); 929 qh_link_periodic(ehci, qh);
930 } else {
931 /* cancel unlink wait for the qh */
932 cancel_unlink_wait_intr(ehci, qh);
892 } 933 }
893 934
894 /* ... update usbfs periodic stats */ 935 /* ... update usbfs periodic stats */
@@ -924,9 +965,11 @@ static void scan_intr(struct ehci_hcd *ehci)
924 * in qh_unlink_periodic(). 965 * in qh_unlink_periodic().
925 */ 966 */
926 temp = qh_completions(ehci, qh); 967 temp = qh_completions(ehci, qh);
927 if (unlikely(temp || (list_empty(&qh->qtd_list) && 968 if (unlikely(temp))
928 qh->qh_state == QH_STATE_LINKED)))
929 start_unlink_intr(ehci, qh); 969 start_unlink_intr(ehci, qh);
970 else if (unlikely(list_empty(&qh->qtd_list) &&
971 qh->qh_state == QH_STATE_LINKED))
972 start_unlink_intr_wait(ehci, qh);
930 } 973 }
931 } 974 }
932} 975}
diff --git a/drivers/usb/host/ehci-sead3.c b/drivers/usb/host/ehci-sead3.c
index b2de52d39614..8a734498079b 100644
--- a/drivers/usb/host/ehci-sead3.c
+++ b/drivers/usb/host/ehci-sead3.c
@@ -55,7 +55,7 @@ const struct hc_driver ehci_sead3_hc_driver = {
55 * generic hardware linkage 55 * generic hardware linkage
56 */ 56 */
57 .irq = ehci_irq, 57 .irq = ehci_irq,
58 .flags = HCD_MEMORY | HCD_USB2, 58 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
59 59
60 /* 60 /*
61 * basic lifecycle operations 61 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
index c4c0ee92a397..dc899eb2b861 100644
--- a/drivers/usb/host/ehci-sh.c
+++ b/drivers/usb/host/ehci-sh.c
@@ -36,7 +36,7 @@ static const struct hc_driver ehci_sh_hc_driver = {
36 * generic hardware linkage 36 * generic hardware linkage
37 */ 37 */
38 .irq = ehci_irq, 38 .irq = ehci_irq,
39 .flags = HCD_USB2 | HCD_MEMORY, 39 .flags = HCD_USB2 | HCD_MEMORY | HCD_BH,
40 40
41 /* 41 /*
42 * basic lifecycle operations 42 * basic lifecycle operations
@@ -104,7 +104,7 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev)
104 goto fail_create_hcd; 104 goto fail_create_hcd;
105 } 105 }
106 106
107 pdata = pdev->dev.platform_data; 107 pdata = dev_get_platdata(&pdev->dev);
108 108
109 /* initialize hcd */ 109 /* initialize hcd */
110 hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev, 110 hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 6ee7ef79b4f8..78fa76da3324 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -25,9 +25,9 @@
25#include <linux/irq.h> 25#include <linux/irq.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/of.h> 27#include <linux/of.h>
28#include <linux/of_device.h>
28#include <linux/of_gpio.h> 29#include <linux/of_gpio.h>
29#include <linux/platform_device.h> 30#include <linux/platform_device.h>
30#include <linux/platform_data/tegra_usb.h>
31#include <linux/pm_runtime.h> 31#include <linux/pm_runtime.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/usb/ehci_def.h> 33#include <linux/usb/ehci_def.h>
@@ -51,6 +51,10 @@
51 51
52static struct hc_driver __read_mostly tegra_ehci_hc_driver; 52static struct hc_driver __read_mostly tegra_ehci_hc_driver;
53 53
54struct tegra_ehci_soc_config {
55 bool has_hostpc;
56};
57
54static int (*orig_hub_control)(struct usb_hcd *hcd, 58static int (*orig_hub_control)(struct usb_hcd *hcd,
55 u16 typeReq, u16 wValue, u16 wIndex, 59 u16 typeReq, u16 wValue, u16 wIndex,
56 char *buf, u16 wLength); 60 char *buf, u16 wLength);
@@ -58,7 +62,6 @@ static int (*orig_hub_control)(struct usb_hcd *hcd,
58struct tegra_ehci_hcd { 62struct tegra_ehci_hcd {
59 struct tegra_usb_phy *phy; 63 struct tegra_usb_phy *phy;
60 struct clk *clk; 64 struct clk *clk;
61 struct usb_phy *transceiver;
62 int port_resuming; 65 int port_resuming;
63 bool needs_double_reset; 66 bool needs_double_reset;
64 enum tegra_usb_phy_port_speed port_speed; 67 enum tegra_usb_phy_port_speed port_speed;
@@ -322,50 +325,38 @@ static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
322 free_dma_aligned_buffer(urb); 325 free_dma_aligned_buffer(urb);
323} 326}
324 327
325static int setup_vbus_gpio(struct platform_device *pdev, 328static const struct tegra_ehci_soc_config tegra30_soc_config = {
326 struct tegra_ehci_platform_data *pdata) 329 .has_hostpc = true,
327{ 330};
328 int err = 0;
329 int gpio;
330
331 gpio = pdata->vbus_gpio;
332 if (!gpio_is_valid(gpio))
333 gpio = of_get_named_gpio(pdev->dev.of_node,
334 "nvidia,vbus-gpio", 0);
335 if (!gpio_is_valid(gpio))
336 return 0;
337 331
338 err = gpio_request(gpio, "vbus_gpio"); 332static const struct tegra_ehci_soc_config tegra20_soc_config = {
339 if (err) { 333 .has_hostpc = false,
340 dev_err(&pdev->dev, "can't request vbus gpio %d", gpio); 334};
341 return err;
342 }
343 err = gpio_direction_output(gpio, 1);
344 if (err) {
345 dev_err(&pdev->dev, "can't enable vbus\n");
346 return err;
347 }
348 335
349 return err; 336static struct of_device_id tegra_ehci_of_match[] = {
350} 337 { .compatible = "nvidia,tegra30-ehci", .data = &tegra30_soc_config },
338 { .compatible = "nvidia,tegra20-ehci", .data = &tegra20_soc_config },
339 { },
340};
351 341
352static int tegra_ehci_probe(struct platform_device *pdev) 342static int tegra_ehci_probe(struct platform_device *pdev)
353{ 343{
344 const struct of_device_id *match;
345 const struct tegra_ehci_soc_config *soc_config;
354 struct resource *res; 346 struct resource *res;
355 struct usb_hcd *hcd; 347 struct usb_hcd *hcd;
356 struct ehci_hcd *ehci; 348 struct ehci_hcd *ehci;
357 struct tegra_ehci_hcd *tegra; 349 struct tegra_ehci_hcd *tegra;
358 struct tegra_ehci_platform_data *pdata;
359 int err = 0; 350 int err = 0;
360 int irq; 351 int irq;
361 struct device_node *np_phy;
362 struct usb_phy *u_phy; 352 struct usb_phy *u_phy;
363 353
364 pdata = pdev->dev.platform_data; 354 match = of_match_device(tegra_ehci_of_match, &pdev->dev);
365 if (!pdata) { 355 if (!match) {
366 dev_err(&pdev->dev, "Platform data missing\n"); 356 dev_err(&pdev->dev, "Error: No device match found\n");
367 return -EINVAL; 357 return -ENODEV;
368 } 358 }
359 soc_config = match->data;
369 360
370 /* Right now device-tree probed devices don't get dma_mask set. 361 /* Right now device-tree probed devices don't get dma_mask set.
371 * Since shared usb code relies on it, set it here for now. 362 * Since shared usb code relies on it, set it here for now.
@@ -376,14 +367,11 @@ static int tegra_ehci_probe(struct platform_device *pdev)
376 if (!pdev->dev.coherent_dma_mask) 367 if (!pdev->dev.coherent_dma_mask)
377 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 368 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
378 369
379 setup_vbus_gpio(pdev, pdata);
380
381 hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev, 370 hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev,
382 dev_name(&pdev->dev)); 371 dev_name(&pdev->dev));
383 if (!hcd) { 372 if (!hcd) {
384 dev_err(&pdev->dev, "Unable to create HCD\n"); 373 dev_err(&pdev->dev, "Unable to create HCD\n");
385 err = -ENOMEM; 374 return -ENOMEM;
386 goto cleanup_vbus_gpio;
387 } 375 }
388 platform_set_drvdata(pdev, hcd); 376 platform_set_drvdata(pdev, hcd);
389 ehci = hcd_to_ehci(hcd); 377 ehci = hcd_to_ehci(hcd);
@@ -406,13 +394,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
406 udelay(1); 394 udelay(1);
407 tegra_periph_reset_deassert(tegra->clk); 395 tegra_periph_reset_deassert(tegra->clk);
408 396
409 np_phy = of_parse_phandle(pdev->dev.of_node, "nvidia,phy", 0); 397 u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
410 if (!np_phy) {
411 err = -ENODEV;
412 goto cleanup_clk_en;
413 }
414
415 u_phy = tegra_usb_get_phy(np_phy);
416 if (IS_ERR(u_phy)) { 398 if (IS_ERR(u_phy)) {
417 err = PTR_ERR(u_phy); 399 err = PTR_ERR(u_phy);
418 goto cleanup_clk_en; 400 goto cleanup_clk_en;
@@ -437,6 +419,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
437 goto cleanup_clk_en; 419 goto cleanup_clk_en;
438 } 420 }
439 ehci->caps = hcd->regs + 0x100; 421 ehci->caps = hcd->regs + 0x100;
422 ehci->has_hostpc = soc_config->has_hostpc;
440 423
441 err = usb_phy_init(hcd->phy); 424 err = usb_phy_init(hcd->phy);
442 if (err) { 425 if (err) {
@@ -466,26 +449,18 @@ static int tegra_ehci_probe(struct platform_device *pdev)
466 goto cleanup_phy; 449 goto cleanup_phy;
467 } 450 }
468 451
469 if (pdata->operating_mode == TEGRA_USB_OTG) { 452 otg_set_host(u_phy->otg, &hcd->self);
470 tegra->transceiver =
471 devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
472 if (!IS_ERR(tegra->transceiver))
473 otg_set_host(tegra->transceiver->otg, &hcd->self);
474 } else {
475 tegra->transceiver = ERR_PTR(-ENODEV);
476 }
477 453
478 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 454 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
479 if (err) { 455 if (err) {
480 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 456 dev_err(&pdev->dev, "Failed to add USB HCD\n");
481 goto cleanup_transceiver; 457 goto cleanup_otg_set_host;
482 } 458 }
483 459
484 return err; 460 return err;
485 461
486cleanup_transceiver: 462cleanup_otg_set_host:
487 if (!IS_ERR(tegra->transceiver)) 463 otg_set_host(u_phy->otg, NULL);
488 otg_set_host(tegra->transceiver->otg, NULL);
489cleanup_phy: 464cleanup_phy:
490 usb_phy_shutdown(hcd->phy); 465 usb_phy_shutdown(hcd->phy);
491cleanup_clk_en: 466cleanup_clk_en:
@@ -494,8 +469,6 @@ cleanup_clk_get:
494 clk_put(tegra->clk); 469 clk_put(tegra->clk);
495cleanup_hcd_create: 470cleanup_hcd_create:
496 usb_put_hcd(hcd); 471 usb_put_hcd(hcd);
497cleanup_vbus_gpio:
498 /* FIXME: Undo setup_vbus_gpio() here */
499 return err; 472 return err;
500} 473}
501 474
@@ -505,8 +478,7 @@ static int tegra_ehci_remove(struct platform_device *pdev)
505 struct tegra_ehci_hcd *tegra = 478 struct tegra_ehci_hcd *tegra =
506 (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv; 479 (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv;
507 480
508 if (!IS_ERR(tegra->transceiver)) 481 otg_set_host(hcd->phy->otg, NULL);
509 otg_set_host(tegra->transceiver->otg, NULL);
510 482
511 usb_phy_shutdown(hcd->phy); 483 usb_phy_shutdown(hcd->phy);
512 usb_remove_hcd(hcd); 484 usb_remove_hcd(hcd);
@@ -525,11 +497,6 @@ static void tegra_ehci_hcd_shutdown(struct platform_device *pdev)
525 hcd->driver->shutdown(hcd); 497 hcd->driver->shutdown(hcd);
526} 498}
527 499
528static struct of_device_id tegra_ehci_of_match[] = {
529 { .compatible = "nvidia,tegra20-ehci", },
530 { },
531};
532
533static struct platform_driver tegra_ehci_driver = { 500static struct platform_driver tegra_ehci_driver = {
534 .probe = tegra_ehci_probe, 501 .probe = tegra_ehci_probe,
535 .remove = tegra_ehci_remove, 502 .remove = tegra_ehci_remove,
diff --git a/drivers/usb/host/ehci-tilegx.c b/drivers/usb/host/ehci-tilegx.c
index d72b2929c03d..67026ffbf9a8 100644
--- a/drivers/usb/host/ehci-tilegx.c
+++ b/drivers/usb/host/ehci-tilegx.c
@@ -61,7 +61,7 @@ static const struct hc_driver ehci_tilegx_hc_driver = {
61 * Generic hardware linkage. 61 * Generic hardware linkage.
62 */ 62 */
63 .irq = ehci_irq, 63 .irq = ehci_irq,
64 .flags = HCD_MEMORY | HCD_USB2, 64 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
65 65
66 /* 66 /*
67 * Basic lifecycle operations. 67 * Basic lifecycle operations.
@@ -101,7 +101,7 @@ static int ehci_hcd_tilegx_drv_probe(struct platform_device *pdev)
101{ 101{
102 struct usb_hcd *hcd; 102 struct usb_hcd *hcd;
103 struct ehci_hcd *ehci; 103 struct ehci_hcd *ehci;
104 struct tilegx_usb_platform_data *pdata = pdev->dev.platform_data; 104 struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
105 pte_t pte = { 0 }; 105 pte_t pte = { 0 };
106 int my_cpu = smp_processor_id(); 106 int my_cpu = smp_processor_id();
107 int ret; 107 int ret;
@@ -186,7 +186,7 @@ err_hcd:
186static int ehci_hcd_tilegx_drv_remove(struct platform_device *pdev) 186static int ehci_hcd_tilegx_drv_remove(struct platform_device *pdev)
187{ 187{
188 struct usb_hcd *hcd = platform_get_drvdata(pdev); 188 struct usb_hcd *hcd = platform_get_drvdata(pdev);
189 struct tilegx_usb_platform_data *pdata = pdev->dev.platform_data; 189 struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
190 190
191 usb_remove_hcd(hcd); 191 usb_remove_hcd(hcd);
192 usb_put_hcd(hcd); 192 usb_put_hcd(hcd);
diff --git a/drivers/usb/host/ehci-timer.c b/drivers/usb/host/ehci-timer.c
index 11e5b32f73e9..424ac5d83714 100644
--- a/drivers/usb/host/ehci-timer.c
+++ b/drivers/usb/host/ehci-timer.c
@@ -72,6 +72,7 @@ static unsigned event_delays_ns[] = {
72 1 * NSEC_PER_MSEC, /* EHCI_HRTIMER_POLL_DEAD */ 72 1 * NSEC_PER_MSEC, /* EHCI_HRTIMER_POLL_DEAD */
73 1125 * NSEC_PER_USEC, /* EHCI_HRTIMER_UNLINK_INTR */ 73 1125 * NSEC_PER_USEC, /* EHCI_HRTIMER_UNLINK_INTR */
74 2 * NSEC_PER_MSEC, /* EHCI_HRTIMER_FREE_ITDS */ 74 2 * NSEC_PER_MSEC, /* EHCI_HRTIMER_FREE_ITDS */
75 5 * NSEC_PER_MSEC, /* EHCI_HRTIMER_START_UNLINK_INTR */
75 6 * NSEC_PER_MSEC, /* EHCI_HRTIMER_ASYNC_UNLINKS */ 76 6 * NSEC_PER_MSEC, /* EHCI_HRTIMER_ASYNC_UNLINKS */
76 10 * NSEC_PER_MSEC, /* EHCI_HRTIMER_IAA_WATCHDOG */ 77 10 * NSEC_PER_MSEC, /* EHCI_HRTIMER_IAA_WATCHDOG */
77 10 * NSEC_PER_MSEC, /* EHCI_HRTIMER_DISABLE_PERIODIC */ 78 10 * NSEC_PER_MSEC, /* EHCI_HRTIMER_DISABLE_PERIODIC */
@@ -215,6 +216,36 @@ static void ehci_handle_controller_death(struct ehci_hcd *ehci)
215 /* Not in process context, so don't try to reset the controller */ 216 /* Not in process context, so don't try to reset the controller */
216} 217}
217 218
219/* start to unlink interrupt QHs */
220static void ehci_handle_start_intr_unlinks(struct ehci_hcd *ehci)
221{
222 bool stopped = (ehci->rh_state < EHCI_RH_RUNNING);
223
224 /*
225 * Process all the QHs on the intr_unlink list that were added
226 * before the current unlink cycle began. The list is in
227 * temporal order, so stop when we reach the first entry in the
228 * current cycle. But if the root hub isn't running then
229 * process all the QHs on the list.
230 */
231 while (!list_empty(&ehci->intr_unlink_wait)) {
232 struct ehci_qh *qh;
233
234 qh = list_first_entry(&ehci->intr_unlink_wait,
235 struct ehci_qh, unlink_node);
236 if (!stopped && (qh->unlink_cycle ==
237 ehci->intr_unlink_wait_cycle))
238 break;
239 list_del_init(&qh->unlink_node);
240 start_unlink_intr(ehci, qh);
241 }
242
243 /* Handle remaining entries later */
244 if (!list_empty(&ehci->intr_unlink_wait)) {
245 ehci_enable_event(ehci, EHCI_HRTIMER_START_UNLINK_INTR, true);
246 ++ehci->intr_unlink_wait_cycle;
247 }
248}
218 249
219/* Handle unlinked interrupt QHs once they are gone from the hardware */ 250/* Handle unlinked interrupt QHs once they are gone from the hardware */
220static void ehci_handle_intr_unlinks(struct ehci_hcd *ehci) 251static void ehci_handle_intr_unlinks(struct ehci_hcd *ehci)
@@ -236,7 +267,7 @@ static void ehci_handle_intr_unlinks(struct ehci_hcd *ehci)
236 unlink_node); 267 unlink_node);
237 if (!stopped && qh->unlink_cycle == ehci->intr_unlink_cycle) 268 if (!stopped && qh->unlink_cycle == ehci->intr_unlink_cycle)
238 break; 269 break;
239 list_del(&qh->unlink_node); 270 list_del_init(&qh->unlink_node);
240 end_unlink_intr(ehci, qh); 271 end_unlink_intr(ehci, qh);
241 } 272 }
242 273
@@ -363,6 +394,7 @@ static void (*event_handlers[])(struct ehci_hcd *) = {
363 ehci_handle_controller_death, /* EHCI_HRTIMER_POLL_DEAD */ 394 ehci_handle_controller_death, /* EHCI_HRTIMER_POLL_DEAD */
364 ehci_handle_intr_unlinks, /* EHCI_HRTIMER_UNLINK_INTR */ 395 ehci_handle_intr_unlinks, /* EHCI_HRTIMER_UNLINK_INTR */
365 end_free_itds, /* EHCI_HRTIMER_FREE_ITDS */ 396 end_free_itds, /* EHCI_HRTIMER_FREE_ITDS */
397 ehci_handle_start_intr_unlinks, /* EHCI_HRTIMER_START_UNLINK_INTR */
366 unlink_empty_async, /* EHCI_HRTIMER_ASYNC_UNLINKS */ 398 unlink_empty_async, /* EHCI_HRTIMER_ASYNC_UNLINKS */
367 ehci_iaa_watchdog, /* EHCI_HRTIMER_IAA_WATCHDOG */ 399 ehci_iaa_watchdog, /* EHCI_HRTIMER_IAA_WATCHDOG */
368 ehci_disable_PSE, /* EHCI_HRTIMER_DISABLE_PERIODIC */ 400 ehci_disable_PSE, /* EHCI_HRTIMER_DISABLE_PERIODIC */
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c
index 59e0e24c753f..1c370dfbee0d 100644
--- a/drivers/usb/host/ehci-w90x900.c
+++ b/drivers/usb/host/ehci-w90x900.c
@@ -108,7 +108,7 @@ static const struct hc_driver ehci_w90x900_hc_driver = {
108 * generic hardware linkage 108 * generic hardware linkage
109 */ 109 */
110 .irq = ehci_irq, 110 .irq = ehci_irq,
111 .flags = HCD_USB2|HCD_MEMORY, 111 .flags = HCD_USB2|HCD_MEMORY|HCD_BH,
112 112
113 /* 113 /*
114 * basic lifecycle operations 114 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c
index 35c7f90384a6..95979f9f4381 100644
--- a/drivers/usb/host/ehci-xilinx-of.c
+++ b/drivers/usb/host/ehci-xilinx-of.c
@@ -79,7 +79,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
79 * generic hardware linkage 79 * generic hardware linkage
80 */ 80 */
81 .irq = ehci_irq, 81 .irq = ehci_irq,
82 .flags = HCD_MEMORY | HCD_USB2, 82 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
83 83
84 /* 84 /*
85 * basic lifecycle operations 85 * basic lifecycle operations
@@ -220,21 +220,6 @@ static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
220 return 0; 220 return 0;
221} 221}
222 222
223/**
224 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
225 * @op: pointer to platform_device structure that is to be removed
226 *
227 * Properly shutdown the hcd, call driver's shutdown routine.
228 */
229static void ehci_hcd_xilinx_of_shutdown(struct platform_device *op)
230{
231 struct usb_hcd *hcd = platform_get_drvdata(op);
232
233 if (hcd->driver->shutdown)
234 hcd->driver->shutdown(hcd);
235}
236
237
238static const struct of_device_id ehci_hcd_xilinx_of_match[] = { 223static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
239 {.compatible = "xlnx,xps-usb-host-1.00.a",}, 224 {.compatible = "xlnx,xps-usb-host-1.00.a",},
240 {}, 225 {},
@@ -244,7 +229,7 @@ MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
244static struct platform_driver ehci_hcd_xilinx_of_driver = { 229static struct platform_driver ehci_hcd_xilinx_of_driver = {
245 .probe = ehci_hcd_xilinx_of_probe, 230 .probe = ehci_hcd_xilinx_of_probe,
246 .remove = ehci_hcd_xilinx_of_remove, 231 .remove = ehci_hcd_xilinx_of_remove,
247 .shutdown = ehci_hcd_xilinx_of_shutdown, 232 .shutdown = usb_hcd_platform_shutdown,
248 .driver = { 233 .driver = {
249 .name = "xilinx-of-ehci", 234 .name = "xilinx-of-ehci",
250 .owner = THIS_MODULE, 235 .owner = THIS_MODULE,
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 64f9a08e959c..2822e79e1fbc 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -88,6 +88,7 @@ enum ehci_hrtimer_event {
88 EHCI_HRTIMER_POLL_DEAD, /* Wait for dead controller to stop */ 88 EHCI_HRTIMER_POLL_DEAD, /* Wait for dead controller to stop */
89 EHCI_HRTIMER_UNLINK_INTR, /* Wait for interrupt QH unlink */ 89 EHCI_HRTIMER_UNLINK_INTR, /* Wait for interrupt QH unlink */
90 EHCI_HRTIMER_FREE_ITDS, /* Wait for unused iTDs and siTDs */ 90 EHCI_HRTIMER_FREE_ITDS, /* Wait for unused iTDs and siTDs */
91 EHCI_HRTIMER_START_UNLINK_INTR, /* Unlink empty interrupt QHs */
91 EHCI_HRTIMER_ASYNC_UNLINKS, /* Unlink empty async QHs */ 92 EHCI_HRTIMER_ASYNC_UNLINKS, /* Unlink empty async QHs */
92 EHCI_HRTIMER_IAA_WATCHDOG, /* Handle lost IAA interrupts */ 93 EHCI_HRTIMER_IAA_WATCHDOG, /* Handle lost IAA interrupts */
93 EHCI_HRTIMER_DISABLE_PERIODIC, /* Wait to disable periodic sched */ 94 EHCI_HRTIMER_DISABLE_PERIODIC, /* Wait to disable periodic sched */
@@ -143,7 +144,9 @@ struct ehci_hcd { /* one per controller */
143 unsigned i_thresh; /* uframes HC might cache */ 144 unsigned i_thresh; /* uframes HC might cache */
144 145
145 union ehci_shadow *pshadow; /* mirror hw periodic table */ 146 union ehci_shadow *pshadow; /* mirror hw periodic table */
147 struct list_head intr_unlink_wait;
146 struct list_head intr_unlink; 148 struct list_head intr_unlink;
149 unsigned intr_unlink_wait_cycle;
147 unsigned intr_unlink_cycle; 150 unsigned intr_unlink_cycle;
148 unsigned now_frame; /* frame from HC hardware */ 151 unsigned now_frame; /* frame from HC hardware */
149 unsigned last_iso_frame; /* last frame scanned for iso */ 152 unsigned last_iso_frame; /* last frame scanned for iso */
@@ -210,6 +213,7 @@ struct ehci_hcd { /* one per controller */
210 #define OHCI_HCCTRL_LEN 0x4 213 #define OHCI_HCCTRL_LEN 0x4
211 __hc32 *ohci_hcctrl_reg; 214 __hc32 *ohci_hcctrl_reg;
212 unsigned has_hostpc:1; 215 unsigned has_hostpc:1;
216 unsigned has_tdi_phy_lpm:1;
213 unsigned has_ppcd:1; /* support per-port change bits */ 217 unsigned has_ppcd:1; /* support per-port change bits */
214 u8 sbrn; /* packed release number */ 218 u8 sbrn; /* packed release number */
215 219
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
new file mode 100644
index 000000000000..fce13bcc4a3e
--- /dev/null
+++ b/drivers/usb/host/fotg210-hcd.c
@@ -0,0 +1,6049 @@
1/*
2 * Faraday FOTG210 EHCI-like driver
3 *
4 * Copyright (c) 2013 Faraday Technology Corporation
5 *
6 * Author: Yuan-Hsin Chen <yhchen@faraday-tech.com>
7 * Feng-Hsin Chiang <john453@faraday-tech.com>
8 * Po-Yu Chuang <ratbert.chuang@gmail.com>
9 *
10 * Most of code borrowed from the Linux-3.7 EHCI driver
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26#include <linux/module.h>
27#include <linux/device.h>
28#include <linux/dmapool.h>
29#include <linux/kernel.h>
30#include <linux/delay.h>
31#include <linux/ioport.h>
32#include <linux/sched.h>
33#include <linux/vmalloc.h>
34#include <linux/errno.h>
35#include <linux/init.h>
36#include <linux/hrtimer.h>
37#include <linux/list.h>
38#include <linux/interrupt.h>
39#include <linux/usb.h>
40#include <linux/usb/hcd.h>
41#include <linux/moduleparam.h>
42#include <linux/dma-mapping.h>
43#include <linux/debugfs.h>
44#include <linux/slab.h>
45#include <linux/uaccess.h>
46#include <linux/platform_device.h>
47#include <linux/io.h>
48
49#include <asm/byteorder.h>
50#include <asm/irq.h>
51#include <asm/unaligned.h>
52
53/*-------------------------------------------------------------------------*/
54#define DRIVER_AUTHOR "Yuan-Hsin Chen"
55#define DRIVER_DESC "FOTG210 Host Controller (EHCI) Driver"
56
57static const char hcd_name[] = "fotg210_hcd";
58
59#undef VERBOSE_DEBUG
60#undef FOTG210_URB_TRACE
61
62#ifdef DEBUG
63#define FOTG210_STATS
64#endif
65
66/* magic numbers that can affect system performance */
67#define FOTG210_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
68#define FOTG210_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
69#define FOTG210_TUNE_RL_TT 0
70#define FOTG210_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
71#define FOTG210_TUNE_MULT_TT 1
72/*
73 * Some drivers think it's safe to schedule isochronous transfers more than
74 * 256 ms into the future (partly as a result of an old bug in the scheduling
75 * code). In an attempt to avoid trouble, we will use a minimum scheduling
76 * length of 512 frames instead of 256.
77 */
78#define FOTG210_TUNE_FLS 1 /* (medium) 512-frame schedule */
79
80/* Initial IRQ latency: faster than hw default */
81static int log2_irq_thresh; /* 0 to 6 */
82module_param(log2_irq_thresh, int, S_IRUGO);
83MODULE_PARM_DESC(log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
84
85/* initial park setting: slower than hw default */
86static unsigned park;
87module_param(park, uint, S_IRUGO);
88MODULE_PARM_DESC(park, "park setting; 1-3 back-to-back async packets");
89
90/* for link power management(LPM) feature */
91static unsigned int hird;
92module_param(hird, int, S_IRUGO);
93MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us");
94
95#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
96
97#include "fotg210.h"
98
99/*-------------------------------------------------------------------------*/
100
101#define fotg210_dbg(fotg210, fmt, args...) \
102 dev_dbg(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args)
103#define fotg210_err(fotg210, fmt, args...) \
104 dev_err(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args)
105#define fotg210_info(fotg210, fmt, args...) \
106 dev_info(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args)
107#define fotg210_warn(fotg210, fmt, args...) \
108 dev_warn(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args)
109
110#ifdef VERBOSE_DEBUG
111# define fotg210_vdbg fotg210_dbg
112#else
113 static inline void fotg210_vdbg(struct fotg210_hcd *fotg210, ...) {}
114#endif
115
116#ifdef DEBUG
117
118/* check the values in the HCSPARAMS register
119 * (host controller _Structural_ parameters)
120 * see EHCI spec, Table 2-4 for each value
121 */
122static void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label)
123{
124 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params);
125
126 fotg210_dbg(fotg210,
127 "%s hcs_params 0x%x ports=%d\n",
128 label, params,
129 HCS_N_PORTS(params)
130 );
131}
132#else
133
134static inline void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label) {}
135
136#endif
137
138#ifdef DEBUG
139
140/* check the values in the HCCPARAMS register
141 * (host controller _Capability_ parameters)
142 * see EHCI Spec, Table 2-5 for each value
143 * */
144static void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label)
145{
146 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
147
148 fotg210_dbg(fotg210,
149 "%s hcc_params %04x uframes %s%s\n",
150 label,
151 params,
152 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
153 HCC_CANPARK(params) ? " park" : "");
154}
155#else
156
157static inline void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label) {}
158
159#endif
160
161#ifdef DEBUG
162
163static void __maybe_unused
164dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd)
165{
166 fotg210_dbg(fotg210, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
167 hc32_to_cpup(fotg210, &qtd->hw_next),
168 hc32_to_cpup(fotg210, &qtd->hw_alt_next),
169 hc32_to_cpup(fotg210, &qtd->hw_token),
170 hc32_to_cpup(fotg210, &qtd->hw_buf[0]));
171 if (qtd->hw_buf[1])
172 fotg210_dbg(fotg210, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
173 hc32_to_cpup(fotg210, &qtd->hw_buf[1]),
174 hc32_to_cpup(fotg210, &qtd->hw_buf[2]),
175 hc32_to_cpup(fotg210, &qtd->hw_buf[3]),
176 hc32_to_cpup(fotg210, &qtd->hw_buf[4]));
177}
178
179static void __maybe_unused
180dbg_qh(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
181{
182 struct fotg210_qh_hw *hw = qh->hw;
183
184 fotg210_dbg(fotg210, "%s qh %p n%08x info %x %x qtd %x\n", label,
185 qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
186 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next);
187}
188
189static void __maybe_unused
190dbg_itd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
191{
192 fotg210_dbg(fotg210, "%s[%d] itd %p, next %08x, urb %p\n",
193 label, itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next),
194 itd->urb);
195 fotg210_dbg(fotg210,
196 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
197 hc32_to_cpu(fotg210, itd->hw_transaction[0]),
198 hc32_to_cpu(fotg210, itd->hw_transaction[1]),
199 hc32_to_cpu(fotg210, itd->hw_transaction[2]),
200 hc32_to_cpu(fotg210, itd->hw_transaction[3]),
201 hc32_to_cpu(fotg210, itd->hw_transaction[4]),
202 hc32_to_cpu(fotg210, itd->hw_transaction[5]),
203 hc32_to_cpu(fotg210, itd->hw_transaction[6]),
204 hc32_to_cpu(fotg210, itd->hw_transaction[7]));
205 fotg210_dbg(fotg210,
206 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
207 hc32_to_cpu(fotg210, itd->hw_bufp[0]),
208 hc32_to_cpu(fotg210, itd->hw_bufp[1]),
209 hc32_to_cpu(fotg210, itd->hw_bufp[2]),
210 hc32_to_cpu(fotg210, itd->hw_bufp[3]),
211 hc32_to_cpu(fotg210, itd->hw_bufp[4]),
212 hc32_to_cpu(fotg210, itd->hw_bufp[5]),
213 hc32_to_cpu(fotg210, itd->hw_bufp[6]));
214 fotg210_dbg(fotg210, " index: %d %d %d %d %d %d %d %d\n",
215 itd->index[0], itd->index[1], itd->index[2],
216 itd->index[3], itd->index[4], itd->index[5],
217 itd->index[6], itd->index[7]);
218}
219
220static int __maybe_unused
221dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
222{
223 return scnprintf(buf, len,
224 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s",
225 label, label[0] ? " " : "", status,
226 (status & STS_ASS) ? " Async" : "",
227 (status & STS_PSS) ? " Periodic" : "",
228 (status & STS_RECL) ? " Recl" : "",
229 (status & STS_HALT) ? " Halt" : "",
230 (status & STS_IAA) ? " IAA" : "",
231 (status & STS_FATAL) ? " FATAL" : "",
232 (status & STS_FLR) ? " FLR" : "",
233 (status & STS_PCD) ? " PCD" : "",
234 (status & STS_ERR) ? " ERR" : "",
235 (status & STS_INT) ? " INT" : ""
236 );
237}
238
239static int __maybe_unused
240dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
241{
242 return scnprintf(buf, len,
243 "%s%sintrenable %02x%s%s%s%s%s%s",
244 label, label[0] ? " " : "", enable,
245 (enable & STS_IAA) ? " IAA" : "",
246 (enable & STS_FATAL) ? " FATAL" : "",
247 (enable & STS_FLR) ? " FLR" : "",
248 (enable & STS_PCD) ? " PCD" : "",
249 (enable & STS_ERR) ? " ERR" : "",
250 (enable & STS_INT) ? " INT" : ""
251 );
252}
253
254static const char *const fls_strings[] = { "1024", "512", "256", "??" };
255
256static int
257dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
258{
259 return scnprintf(buf, len,
260 "%s%scommand %07x %s=%d ithresh=%d%s%s%s "
261 "period=%s%s %s",
262 label, label[0] ? " " : "", command,
263 (command & CMD_PARK) ? " park" : "(park)",
264 CMD_PARK_CNT(command),
265 (command >> 16) & 0x3f,
266 (command & CMD_IAAD) ? " IAAD" : "",
267 (command & CMD_ASE) ? " Async" : "",
268 (command & CMD_PSE) ? " Periodic" : "",
269 fls_strings[(command >> 2) & 0x3],
270 (command & CMD_RESET) ? " Reset" : "",
271 (command & CMD_RUN) ? "RUN" : "HALT"
272 );
273}
274
275static int
276dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
277{
278 char *sig;
279
280 /* signaling state */
281 switch (status & (3 << 10)) {
282 case 0 << 10:
283 sig = "se0";
284 break;
285 case 1 << 10:
286 sig = "k";
287 break; /* low speed */
288 case 2 << 10:
289 sig = "j";
290 break;
291 default:
292 sig = "?";
293 break;
294 }
295
296 return scnprintf(buf, len,
297 "%s%sport:%d status %06x %d "
298 "sig=%s%s%s%s%s%s%s%s",
299 label, label[0] ? " " : "", port, status,
300 status>>25,/*device address */
301 sig,
302 (status & PORT_RESET) ? " RESET" : "",
303 (status & PORT_SUSPEND) ? " SUSPEND" : "",
304 (status & PORT_RESUME) ? " RESUME" : "",
305 (status & PORT_PEC) ? " PEC" : "",
306 (status & PORT_PE) ? " PE" : "",
307 (status & PORT_CSC) ? " CSC" : "",
308 (status & PORT_CONNECT) ? " CONNECT" : "");
309}
310
311#else
312static inline void __maybe_unused
313dbg_qh(char *label, struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
314{}
315
316static inline int __maybe_unused
317dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
318{ return 0; }
319
320static inline int __maybe_unused
321dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
322{ return 0; }
323
324static inline int __maybe_unused
325dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
326{ return 0; }
327
328static inline int __maybe_unused
329dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
330{ return 0; }
331
332#endif /* DEBUG */
333
334/* functions have the "wrong" filename when they're output... */
335#define dbg_status(fotg210, label, status) { \
336 char _buf[80]; \
337 dbg_status_buf(_buf, sizeof(_buf), label, status); \
338 fotg210_dbg(fotg210, "%s\n", _buf); \
339}
340
341#define dbg_cmd(fotg210, label, command) { \
342 char _buf[80]; \
343 dbg_command_buf(_buf, sizeof(_buf), label, command); \
344 fotg210_dbg(fotg210, "%s\n", _buf); \
345}
346
347#define dbg_port(fotg210, label, port, status) { \
348 char _buf[80]; \
349 dbg_port_buf(_buf, sizeof(_buf), label, port, status); \
350 fotg210_dbg(fotg210, "%s\n", _buf); \
351}
352
353/*-------------------------------------------------------------------------*/
354
355#ifdef STUB_DEBUG_FILES
356
357static inline void create_debug_files(struct fotg210_hcd *bus) { }
358static inline void remove_debug_files(struct fotg210_hcd *bus) { }
359
360#else
361
362/* troubleshooting help: expose state in debugfs */
363
364static int debug_async_open(struct inode *, struct file *);
365static int debug_periodic_open(struct inode *, struct file *);
366static int debug_registers_open(struct inode *, struct file *);
367static int debug_async_open(struct inode *, struct file *);
368
369static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
370static int debug_close(struct inode *, struct file *);
371
372static const struct file_operations debug_async_fops = {
373 .owner = THIS_MODULE,
374 .open = debug_async_open,
375 .read = debug_output,
376 .release = debug_close,
377 .llseek = default_llseek,
378};
379static const struct file_operations debug_periodic_fops = {
380 .owner = THIS_MODULE,
381 .open = debug_periodic_open,
382 .read = debug_output,
383 .release = debug_close,
384 .llseek = default_llseek,
385};
386static const struct file_operations debug_registers_fops = {
387 .owner = THIS_MODULE,
388 .open = debug_registers_open,
389 .read = debug_output,
390 .release = debug_close,
391 .llseek = default_llseek,
392};
393
394static struct dentry *fotg210_debug_root;
395
396struct debug_buffer {
397 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
398 struct usb_bus *bus;
399 struct mutex mutex; /* protect filling of buffer */
400 size_t count; /* number of characters filled into buffer */
401 char *output_buf;
402 size_t alloc_size;
403};
404
405#define speed_char(info1)({ char tmp; \
406 switch (info1 & (3 << 12)) { \
407 case QH_FULL_SPEED: \
408 tmp = 'f'; break; \
409 case QH_LOW_SPEED: \
410 tmp = 'l'; break; \
411 case QH_HIGH_SPEED: \
412 tmp = 'h'; break; \
413 default: \
414 tmp = '?'; break; \
415 }; tmp; })
416
417static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token)
418{
419 __u32 v = hc32_to_cpu(fotg210, token);
420
421 if (v & QTD_STS_ACTIVE)
422 return '*';
423 if (v & QTD_STS_HALT)
424 return '-';
425 if (!IS_SHORT_READ(v))
426 return ' ';
427 /* tries to advance through hw_alt_next */
428 return '/';
429}
430
431static void qh_lines(
432 struct fotg210_hcd *fotg210,
433 struct fotg210_qh *qh,
434 char **nextp,
435 unsigned *sizep
436)
437{
438 u32 scratch;
439 u32 hw_curr;
440 struct fotg210_qtd *td;
441 unsigned temp;
442 unsigned size = *sizep;
443 char *next = *nextp;
444 char mark;
445 __le32 list_end = FOTG210_LIST_END(fotg210);
446 struct fotg210_qh_hw *hw = qh->hw;
447
448 if (hw->hw_qtd_next == list_end) /* NEC does this */
449 mark = '@';
450 else
451 mark = token_mark(fotg210, hw->hw_token);
452 if (mark == '/') { /* qh_alt_next controls qh advance? */
453 if ((hw->hw_alt_next & QTD_MASK(fotg210))
454 == fotg210->async->hw->hw_alt_next)
455 mark = '#'; /* blocked */
456 else if (hw->hw_alt_next == list_end)
457 mark = '.'; /* use hw_qtd_next */
458 /* else alt_next points to some other qtd */
459 }
460 scratch = hc32_to_cpup(fotg210, &hw->hw_info1);
461 hw_curr = (mark == '*') ? hc32_to_cpup(fotg210, &hw->hw_current) : 0;
462 temp = scnprintf(next, size,
463 "qh/%p dev%d %cs ep%d %08x %08x(%08x%c %s nak%d)",
464 qh, scratch & 0x007f,
465 speed_char(scratch),
466 (scratch >> 8) & 0x000f,
467 scratch, hc32_to_cpup(fotg210, &hw->hw_info2),
468 hc32_to_cpup(fotg210, &hw->hw_token), mark,
469 (cpu_to_hc32(fotg210, QTD_TOGGLE) & hw->hw_token)
470 ? "data1" : "data0",
471 (hc32_to_cpup(fotg210, &hw->hw_alt_next) >> 1) & 0x0f);
472 size -= temp;
473 next += temp;
474
475 /* hc may be modifying the list as we read it ... */
476 list_for_each_entry(td, &qh->qtd_list, qtd_list) {
477 scratch = hc32_to_cpup(fotg210, &td->hw_token);
478 mark = ' ';
479 if (hw_curr == td->qtd_dma)
480 mark = '*';
481 else if (hw->hw_qtd_next == cpu_to_hc32(fotg210, td->qtd_dma))
482 mark = '+';
483 else if (QTD_LENGTH(scratch)) {
484 if (td->hw_alt_next == fotg210->async->hw->hw_alt_next)
485 mark = '#';
486 else if (td->hw_alt_next != list_end)
487 mark = '/';
488 }
489 temp = snprintf(next, size,
490 "\n\t%p%c%s len=%d %08x urb %p",
491 td, mark, ({ char *tmp;
492 switch ((scratch>>8)&0x03) {
493 case 0:
494 tmp = "out";
495 break;
496 case 1:
497 tmp = "in";
498 break;
499 case 2:
500 tmp = "setup";
501 break;
502 default:
503 tmp = "?";
504 break;
505 } tmp; }),
506 (scratch >> 16) & 0x7fff,
507 scratch,
508 td->urb);
509 if (size < temp)
510 temp = size;
511 size -= temp;
512 next += temp;
513 if (temp == size)
514 goto done;
515 }
516
517 temp = snprintf(next, size, "\n");
518 if (size < temp)
519 temp = size;
520 size -= temp;
521 next += temp;
522
523done:
524 *sizep = size;
525 *nextp = next;
526}
527
528static ssize_t fill_async_buffer(struct debug_buffer *buf)
529{
530 struct usb_hcd *hcd;
531 struct fotg210_hcd *fotg210;
532 unsigned long flags;
533 unsigned temp, size;
534 char *next;
535 struct fotg210_qh *qh;
536
537 hcd = bus_to_hcd(buf->bus);
538 fotg210 = hcd_to_fotg210(hcd);
539 next = buf->output_buf;
540 size = buf->alloc_size;
541
542 *next = 0;
543
544 /* dumps a snapshot of the async schedule.
545 * usually empty except for long-term bulk reads, or head.
546 * one QH per line, and TDs we know about
547 */
548 spin_lock_irqsave(&fotg210->lock, flags);
549 for (qh = fotg210->async->qh_next.qh; size > 0 && qh;
550 qh = qh->qh_next.qh)
551 qh_lines(fotg210, qh, &next, &size);
552 if (fotg210->async_unlink && size > 0) {
553 temp = scnprintf(next, size, "\nunlink =\n");
554 size -= temp;
555 next += temp;
556
557 for (qh = fotg210->async_unlink; size > 0 && qh;
558 qh = qh->unlink_next)
559 qh_lines(fotg210, qh, &next, &size);
560 }
561 spin_unlock_irqrestore(&fotg210->lock, flags);
562
563 return strlen(buf->output_buf);
564}
565
566#define DBG_SCHED_LIMIT 64
567static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
568{
569 struct usb_hcd *hcd;
570 struct fotg210_hcd *fotg210;
571 unsigned long flags;
572 union fotg210_shadow p, *seen;
573 unsigned temp, size, seen_count;
574 char *next;
575 unsigned i;
576 __hc32 tag;
577
578 seen = kmalloc(DBG_SCHED_LIMIT * sizeof(*seen), GFP_ATOMIC);
579 if (!seen)
580 return 0;
581 seen_count = 0;
582
583 hcd = bus_to_hcd(buf->bus);
584 fotg210 = hcd_to_fotg210(hcd);
585 next = buf->output_buf;
586 size = buf->alloc_size;
587
588 temp = scnprintf(next, size, "size = %d\n", fotg210->periodic_size);
589 size -= temp;
590 next += temp;
591
592 /* dump a snapshot of the periodic schedule.
593 * iso changes, interrupt usually doesn't.
594 */
595 spin_lock_irqsave(&fotg210->lock, flags);
596 for (i = 0; i < fotg210->periodic_size; i++) {
597 p = fotg210->pshadow[i];
598 if (likely(!p.ptr))
599 continue;
600 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]);
601
602 temp = scnprintf(next, size, "%4d: ", i);
603 size -= temp;
604 next += temp;
605
606 do {
607 struct fotg210_qh_hw *hw;
608
609 switch (hc32_to_cpu(fotg210, tag)) {
610 case Q_TYPE_QH:
611 hw = p.qh->hw;
612 temp = scnprintf(next, size, " qh%d-%04x/%p",
613 p.qh->period,
614 hc32_to_cpup(fotg210,
615 &hw->hw_info2)
616 /* uframe masks */
617 & (QH_CMASK | QH_SMASK),
618 p.qh);
619 size -= temp;
620 next += temp;
621 /* don't repeat what follows this qh */
622 for (temp = 0; temp < seen_count; temp++) {
623 if (seen[temp].ptr != p.ptr)
624 continue;
625 if (p.qh->qh_next.ptr) {
626 temp = scnprintf(next, size,
627 " ...");
628 size -= temp;
629 next += temp;
630 }
631 break;
632 }
633 /* show more info the first time around */
634 if (temp == seen_count) {
635 u32 scratch = hc32_to_cpup(fotg210,
636 &hw->hw_info1);
637 struct fotg210_qtd *qtd;
638 char *type = "";
639
640 /* count tds, get ep direction */
641 temp = 0;
642 list_for_each_entry(qtd,
643 &p.qh->qtd_list,
644 qtd_list) {
645 temp++;
646 switch (0x03 & (hc32_to_cpu(
647 fotg210,
648 qtd->hw_token) >> 8)) {
649 case 0:
650 type = "out";
651 continue;
652 case 1:
653 type = "in";
654 continue;
655 }
656 }
657
658 temp = scnprintf(next, size,
659 "(%c%d ep%d%s "
660 "[%d/%d] q%d p%d)",
661 speed_char(scratch),
662 scratch & 0x007f,
663 (scratch >> 8) & 0x000f, type,
664 p.qh->usecs, p.qh->c_usecs,
665 temp,
666 0x7ff & (scratch >> 16));
667
668 if (seen_count < DBG_SCHED_LIMIT)
669 seen[seen_count++].qh = p.qh;
670 } else
671 temp = 0;
672 tag = Q_NEXT_TYPE(fotg210, hw->hw_next);
673 p = p.qh->qh_next;
674 break;
675 case Q_TYPE_FSTN:
676 temp = scnprintf(next, size,
677 " fstn-%8x/%p", p.fstn->hw_prev,
678 p.fstn);
679 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next);
680 p = p.fstn->fstn_next;
681 break;
682 case Q_TYPE_ITD:
683 temp = scnprintf(next, size,
684 " itd/%p", p.itd);
685 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next);
686 p = p.itd->itd_next;
687 break;
688 }
689 size -= temp;
690 next += temp;
691 } while (p.ptr);
692
693 temp = scnprintf(next, size, "\n");
694 size -= temp;
695 next += temp;
696 }
697 spin_unlock_irqrestore(&fotg210->lock, flags);
698 kfree(seen);
699
700 return buf->alloc_size - size;
701}
702#undef DBG_SCHED_LIMIT
703
704static const char *rh_state_string(struct fotg210_hcd *fotg210)
705{
706 switch (fotg210->rh_state) {
707 case FOTG210_RH_HALTED:
708 return "halted";
709 case FOTG210_RH_SUSPENDED:
710 return "suspended";
711 case FOTG210_RH_RUNNING:
712 return "running";
713 case FOTG210_RH_STOPPING:
714 return "stopping";
715 }
716 return "?";
717}
718
719static ssize_t fill_registers_buffer(struct debug_buffer *buf)
720{
721 struct usb_hcd *hcd;
722 struct fotg210_hcd *fotg210;
723 unsigned long flags;
724 unsigned temp, size, i;
725 char *next, scratch[80];
726 static const char fmt[] = "%*s\n";
727 static const char label[] = "";
728
729 hcd = bus_to_hcd(buf->bus);
730 fotg210 = hcd_to_fotg210(hcd);
731 next = buf->output_buf;
732 size = buf->alloc_size;
733
734 spin_lock_irqsave(&fotg210->lock, flags);
735
736 if (!HCD_HW_ACCESSIBLE(hcd)) {
737 size = scnprintf(next, size,
738 "bus %s, device %s\n"
739 "%s\n"
740 "SUSPENDED(no register access)\n",
741 hcd->self.controller->bus->name,
742 dev_name(hcd->self.controller),
743 hcd->product_desc);
744 goto done;
745 }
746
747 /* Capability Registers */
748 i = HC_VERSION(fotg210, fotg210_readl(fotg210,
749 &fotg210->caps->hc_capbase));
750 temp = scnprintf(next, size,
751 "bus %s, device %s\n"
752 "%s\n"
753 "EHCI %x.%02x, rh state %s\n",
754 hcd->self.controller->bus->name,
755 dev_name(hcd->self.controller),
756 hcd->product_desc,
757 i >> 8, i & 0x0ff, rh_state_string(fotg210));
758 size -= temp;
759 next += temp;
760
761 /* FIXME interpret both types of params */
762 i = fotg210_readl(fotg210, &fotg210->caps->hcs_params);
763 temp = scnprintf(next, size, "structural params 0x%08x\n", i);
764 size -= temp;
765 next += temp;
766
767 i = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
768 temp = scnprintf(next, size, "capability params 0x%08x\n", i);
769 size -= temp;
770 next += temp;
771
772 /* Operational Registers */
773 temp = dbg_status_buf(scratch, sizeof(scratch), label,
774 fotg210_readl(fotg210, &fotg210->regs->status));
775 temp = scnprintf(next, size, fmt, temp, scratch);
776 size -= temp;
777 next += temp;
778
779 temp = dbg_command_buf(scratch, sizeof(scratch), label,
780 fotg210_readl(fotg210, &fotg210->regs->command));
781 temp = scnprintf(next, size, fmt, temp, scratch);
782 size -= temp;
783 next += temp;
784
785 temp = dbg_intr_buf(scratch, sizeof(scratch), label,
786 fotg210_readl(fotg210, &fotg210->regs->intr_enable));
787 temp = scnprintf(next, size, fmt, temp, scratch);
788 size -= temp;
789 next += temp;
790
791 temp = scnprintf(next, size, "uframe %04x\n",
792 fotg210_read_frame_index(fotg210));
793 size -= temp;
794 next += temp;
795
796 if (fotg210->async_unlink) {
797 temp = scnprintf(next, size, "async unlink qh %p\n",
798 fotg210->async_unlink);
799 size -= temp;
800 next += temp;
801 }
802
803#ifdef FOTG210_STATS
804 temp = scnprintf(next, size,
805 "irq normal %ld err %ld iaa %ld(lost %ld)\n",
806 fotg210->stats.normal, fotg210->stats.error, fotg210->stats.iaa,
807 fotg210->stats.lost_iaa);
808 size -= temp;
809 next += temp;
810
811 temp = scnprintf(next, size, "complete %ld unlink %ld\n",
812 fotg210->stats.complete, fotg210->stats.unlink);
813 size -= temp;
814 next += temp;
815#endif
816
817done:
818 spin_unlock_irqrestore(&fotg210->lock, flags);
819
820 return buf->alloc_size - size;
821}
822
823static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
824 ssize_t (*fill_func)(struct debug_buffer *))
825{
826 struct debug_buffer *buf;
827
828 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
829
830 if (buf) {
831 buf->bus = bus;
832 buf->fill_func = fill_func;
833 mutex_init(&buf->mutex);
834 buf->alloc_size = PAGE_SIZE;
835 }
836
837 return buf;
838}
839
840static int fill_buffer(struct debug_buffer *buf)
841{
842 int ret = 0;
843
844 if (!buf->output_buf)
845 buf->output_buf = vmalloc(buf->alloc_size);
846
847 if (!buf->output_buf) {
848 ret = -ENOMEM;
849 goto out;
850 }
851
852 ret = buf->fill_func(buf);
853
854 if (ret >= 0) {
855 buf->count = ret;
856 ret = 0;
857 }
858
859out:
860 return ret;
861}
862
863static ssize_t debug_output(struct file *file, char __user *user_buf,
864 size_t len, loff_t *offset)
865{
866 struct debug_buffer *buf = file->private_data;
867 int ret = 0;
868
869 mutex_lock(&buf->mutex);
870 if (buf->count == 0) {
871 ret = fill_buffer(buf);
872 if (ret != 0) {
873 mutex_unlock(&buf->mutex);
874 goto out;
875 }
876 }
877 mutex_unlock(&buf->mutex);
878
879 ret = simple_read_from_buffer(user_buf, len, offset,
880 buf->output_buf, buf->count);
881
882out:
883 return ret;
884
885}
886
887static int debug_close(struct inode *inode, struct file *file)
888{
889 struct debug_buffer *buf = file->private_data;
890
891 if (buf) {
892 vfree(buf->output_buf);
893 kfree(buf);
894 }
895
896 return 0;
897}
898static int debug_async_open(struct inode *inode, struct file *file)
899{
900 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
901
902 return file->private_data ? 0 : -ENOMEM;
903}
904
905static int debug_periodic_open(struct inode *inode, struct file *file)
906{
907 struct debug_buffer *buf;
908 buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
909 if (!buf)
910 return -ENOMEM;
911
912 buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE;
913 file->private_data = buf;
914 return 0;
915}
916
917static int debug_registers_open(struct inode *inode, struct file *file)
918{
919 file->private_data = alloc_buffer(inode->i_private,
920 fill_registers_buffer);
921
922 return file->private_data ? 0 : -ENOMEM;
923}
924
925static inline void create_debug_files(struct fotg210_hcd *fotg210)
926{
927 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self;
928
929 fotg210->debug_dir = debugfs_create_dir(bus->bus_name,
930 fotg210_debug_root);
931 if (!fotg210->debug_dir)
932 return;
933
934 if (!debugfs_create_file("async", S_IRUGO, fotg210->debug_dir, bus,
935 &debug_async_fops))
936 goto file_error;
937
938 if (!debugfs_create_file("periodic", S_IRUGO, fotg210->debug_dir, bus,
939 &debug_periodic_fops))
940 goto file_error;
941
942 if (!debugfs_create_file("registers", S_IRUGO, fotg210->debug_dir, bus,
943 &debug_registers_fops))
944 goto file_error;
945
946 return;
947
948file_error:
949 debugfs_remove_recursive(fotg210->debug_dir);
950}
951
952static inline void remove_debug_files(struct fotg210_hcd *fotg210)
953{
954 debugfs_remove_recursive(fotg210->debug_dir);
955}
956
957#endif /* STUB_DEBUG_FILES */
958/*-------------------------------------------------------------------------*/
959
960/*
961 * handshake - spin reading hc until handshake completes or fails
962 * @ptr: address of hc register to be read
963 * @mask: bits to look at in result of read
964 * @done: value of those bits when handshake succeeds
965 * @usec: timeout in microseconds
966 *
967 * Returns negative errno, or zero on success
968 *
969 * Success happens when the "mask" bits have the specified value (hardware
970 * handshake done). There are two failure modes: "usec" have passed (major
971 * hardware flakeout), or the register reads as all-ones (hardware removed).
972 *
973 * That last failure should_only happen in cases like physical cardbus eject
974 * before driver shutdown. But it also seems to be caused by bugs in cardbus
975 * bridge shutdown: shutting down the bridge before the devices using it.
976 */
977static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr,
978 u32 mask, u32 done, int usec)
979{
980 u32 result;
981
982 do {
983 result = fotg210_readl(fotg210, ptr);
984 if (result == ~(u32)0) /* card removed */
985 return -ENODEV;
986 result &= mask;
987 if (result == done)
988 return 0;
989 udelay(1);
990 usec--;
991 } while (usec > 0);
992 return -ETIMEDOUT;
993}
994
995/*
996 * Force HC to halt state from unknown (EHCI spec section 2.3).
997 * Must be called with interrupts enabled and the lock not held.
998 */
999static int fotg210_halt(struct fotg210_hcd *fotg210)
1000{
1001 u32 temp;
1002
1003 spin_lock_irq(&fotg210->lock);
1004
1005 /* disable any irqs left enabled by previous code */
1006 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
1007
1008 /*
1009 * This routine gets called during probe before fotg210->command
1010 * has been initialized, so we can't rely on its value.
1011 */
1012 fotg210->command &= ~CMD_RUN;
1013 temp = fotg210_readl(fotg210, &fotg210->regs->command);
1014 temp &= ~(CMD_RUN | CMD_IAAD);
1015 fotg210_writel(fotg210, temp, &fotg210->regs->command);
1016
1017 spin_unlock_irq(&fotg210->lock);
1018 synchronize_irq(fotg210_to_hcd(fotg210)->irq);
1019
1020 return handshake(fotg210, &fotg210->regs->status,
1021 STS_HALT, STS_HALT, 16 * 125);
1022}
1023
1024/*
1025 * Reset a non-running (STS_HALT == 1) controller.
1026 * Must be called with interrupts enabled and the lock not held.
1027 */
1028static int fotg210_reset(struct fotg210_hcd *fotg210)
1029{
1030 int retval;
1031 u32 command = fotg210_readl(fotg210, &fotg210->regs->command);
1032
1033 /* If the EHCI debug controller is active, special care must be
1034 * taken before and after a host controller reset */
1035 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210)))
1036 fotg210->debug = NULL;
1037
1038 command |= CMD_RESET;
1039 dbg_cmd(fotg210, "reset", command);
1040 fotg210_writel(fotg210, command, &fotg210->regs->command);
1041 fotg210->rh_state = FOTG210_RH_HALTED;
1042 fotg210->next_statechange = jiffies;
1043 retval = handshake(fotg210, &fotg210->regs->command,
1044 CMD_RESET, 0, 250 * 1000);
1045
1046 if (retval)
1047 return retval;
1048
1049 if (fotg210->debug)
1050 dbgp_external_startup(fotg210_to_hcd(fotg210));
1051
1052 fotg210->port_c_suspend = fotg210->suspended_ports =
1053 fotg210->resuming_ports = 0;
1054 return retval;
1055}
1056
1057/*
1058 * Idle the controller (turn off the schedules).
1059 * Must be called with interrupts enabled and the lock not held.
1060 */
1061static void fotg210_quiesce(struct fotg210_hcd *fotg210)
1062{
1063 u32 temp;
1064
1065 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1066 return;
1067
1068 /* wait for any schedule enables/disables to take effect */
1069 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS);
1070 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp,
1071 16 * 125);
1072
1073 /* then disable anything that's still active */
1074 spin_lock_irq(&fotg210->lock);
1075 fotg210->command &= ~(CMD_ASE | CMD_PSE);
1076 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
1077 spin_unlock_irq(&fotg210->lock);
1078
1079 /* hardware can take 16 microframes to turn off ... */
1080 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0,
1081 16 * 125);
1082}
1083
1084/*-------------------------------------------------------------------------*/
1085
1086static void end_unlink_async(struct fotg210_hcd *fotg210);
1087static void unlink_empty_async(struct fotg210_hcd *fotg210);
1088static void fotg210_work(struct fotg210_hcd *fotg210);
1089static void start_unlink_intr(struct fotg210_hcd *fotg210,
1090 struct fotg210_qh *qh);
1091static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
1092
1093/*-------------------------------------------------------------------------*/
1094
1095/* Set a bit in the USBCMD register */
1096static void fotg210_set_command_bit(struct fotg210_hcd *fotg210, u32 bit)
1097{
1098 fotg210->command |= bit;
1099 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
1100
1101 /* unblock posted write */
1102 fotg210_readl(fotg210, &fotg210->regs->command);
1103}
1104
1105/* Clear a bit in the USBCMD register */
1106static void fotg210_clear_command_bit(struct fotg210_hcd *fotg210, u32 bit)
1107{
1108 fotg210->command &= ~bit;
1109 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
1110
1111 /* unblock posted write */
1112 fotg210_readl(fotg210, &fotg210->regs->command);
1113}
1114
1115/*-------------------------------------------------------------------------*/
1116
1117/*
1118 * EHCI timer support... Now using hrtimers.
1119 *
1120 * Lots of different events are triggered from fotg210->hrtimer. Whenever
1121 * the timer routine runs, it checks each possible event; events that are
1122 * currently enabled and whose expiration time has passed get handled.
1123 * The set of enabled events is stored as a collection of bitflags in
1124 * fotg210->enabled_hrtimer_events, and they are numbered in order of
1125 * increasing delay values (ranging between 1 ms and 100 ms).
1126 *
1127 * Rather than implementing a sorted list or tree of all pending events,
1128 * we keep track only of the lowest-numbered pending event, in
1129 * fotg210->next_hrtimer_event. Whenever fotg210->hrtimer gets restarted, its
1130 * expiration time is set to the timeout value for this event.
1131 *
1132 * As a result, events might not get handled right away; the actual delay
1133 * could be anywhere up to twice the requested delay. This doesn't
1134 * matter, because none of the events are especially time-critical. The
1135 * ones that matter most all have a delay of 1 ms, so they will be
1136 * handled after 2 ms at most, which is okay. In addition to this, we
1137 * allow for an expiration range of 1 ms.
1138 */
1139
1140/*
1141 * Delay lengths for the hrtimer event types.
1142 * Keep this list sorted by delay length, in the same order as
1143 * the event types indexed by enum fotg210_hrtimer_event in fotg210.h.
1144 */
1145static unsigned event_delays_ns[] = {
1146 1 * NSEC_PER_MSEC, /* FOTG210_HRTIMER_POLL_ASS */
1147 1 * NSEC_PER_MSEC, /* FOTG210_HRTIMER_POLL_PSS */
1148 1 * NSEC_PER_MSEC, /* FOTG210_HRTIMER_POLL_DEAD */
1149 1125 * NSEC_PER_USEC, /* FOTG210_HRTIMER_UNLINK_INTR */
1150 2 * NSEC_PER_MSEC, /* FOTG210_HRTIMER_FREE_ITDS */
1151 6 * NSEC_PER_MSEC, /* FOTG210_HRTIMER_ASYNC_UNLINKS */
1152 10 * NSEC_PER_MSEC, /* FOTG210_HRTIMER_IAA_WATCHDOG */
1153 10 * NSEC_PER_MSEC, /* FOTG210_HRTIMER_DISABLE_PERIODIC */
1154 15 * NSEC_PER_MSEC, /* FOTG210_HRTIMER_DISABLE_ASYNC */
1155 100 * NSEC_PER_MSEC, /* FOTG210_HRTIMER_IO_WATCHDOG */
1156};
1157
1158/* Enable a pending hrtimer event */
1159static void fotg210_enable_event(struct fotg210_hcd *fotg210, unsigned event,
1160 bool resched)
1161{
1162 ktime_t *timeout = &fotg210->hr_timeouts[event];
1163
1164 if (resched)
1165 *timeout = ktime_add(ktime_get(),
1166 ktime_set(0, event_delays_ns[event]));
1167 fotg210->enabled_hrtimer_events |= (1 << event);
1168
1169 /* Track only the lowest-numbered pending event */
1170 if (event < fotg210->next_hrtimer_event) {
1171 fotg210->next_hrtimer_event = event;
1172 hrtimer_start_range_ns(&fotg210->hrtimer, *timeout,
1173 NSEC_PER_MSEC, HRTIMER_MODE_ABS);
1174 }
1175}
1176
1177
1178/* Poll the STS_ASS status bit; see when it agrees with CMD_ASE */
1179static void fotg210_poll_ASS(struct fotg210_hcd *fotg210)
1180{
1181 unsigned actual, want;
1182
1183 /* Don't enable anything if the controller isn't running (e.g., died) */
1184 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1185 return;
1186
1187 want = (fotg210->command & CMD_ASE) ? STS_ASS : 0;
1188 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_ASS;
1189
1190 if (want != actual) {
1191
1192 /* Poll again later, but give up after about 20 ms */
1193 if (fotg210->ASS_poll_count++ < 20) {
1194 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_ASS,
1195 true);
1196 return;
1197 }
1198 fotg210_dbg(fotg210, "Waited too long for the async schedule status (%x/%x), giving up\n",
1199 want, actual);
1200 }
1201 fotg210->ASS_poll_count = 0;
1202
1203 /* The status is up-to-date; restart or stop the schedule as needed */
1204 if (want == 0) { /* Stopped */
1205 if (fotg210->async_count > 0)
1206 fotg210_set_command_bit(fotg210, CMD_ASE);
1207
1208 } else { /* Running */
1209 if (fotg210->async_count == 0) {
1210
1211 /* Turn off the schedule after a while */
1212 fotg210_enable_event(fotg210,
1213 FOTG210_HRTIMER_DISABLE_ASYNC,
1214 true);
1215 }
1216 }
1217}
1218
1219/* Turn off the async schedule after a brief delay */
1220static void fotg210_disable_ASE(struct fotg210_hcd *fotg210)
1221{
1222 fotg210_clear_command_bit(fotg210, CMD_ASE);
1223}
1224
1225
1226/* Poll the STS_PSS status bit; see when it agrees with CMD_PSE */
1227static void fotg210_poll_PSS(struct fotg210_hcd *fotg210)
1228{
1229 unsigned actual, want;
1230
1231 /* Don't do anything if the controller isn't running (e.g., died) */
1232 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1233 return;
1234
1235 want = (fotg210->command & CMD_PSE) ? STS_PSS : 0;
1236 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_PSS;
1237
1238 if (want != actual) {
1239
1240 /* Poll again later, but give up after about 20 ms */
1241 if (fotg210->PSS_poll_count++ < 20) {
1242 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_PSS,
1243 true);
1244 return;
1245 }
1246 fotg210_dbg(fotg210, "Waited too long for the periodic schedule status (%x/%x), giving up\n",
1247 want, actual);
1248 }
1249 fotg210->PSS_poll_count = 0;
1250
1251 /* The status is up-to-date; restart or stop the schedule as needed */
1252 if (want == 0) { /* Stopped */
1253 if (fotg210->periodic_count > 0)
1254 fotg210_set_command_bit(fotg210, CMD_PSE);
1255
1256 } else { /* Running */
1257 if (fotg210->periodic_count == 0) {
1258
1259 /* Turn off the schedule after a while */
1260 fotg210_enable_event(fotg210,
1261 FOTG210_HRTIMER_DISABLE_PERIODIC,
1262 true);
1263 }
1264 }
1265}
1266
1267/* Turn off the periodic schedule after a brief delay */
1268static void fotg210_disable_PSE(struct fotg210_hcd *fotg210)
1269{
1270 fotg210_clear_command_bit(fotg210, CMD_PSE);
1271}
1272
1273
1274/* Poll the STS_HALT status bit; see when a dead controller stops */
1275static void fotg210_handle_controller_death(struct fotg210_hcd *fotg210)
1276{
1277 if (!(fotg210_readl(fotg210, &fotg210->regs->status) & STS_HALT)) {
1278
1279 /* Give up after a few milliseconds */
1280 if (fotg210->died_poll_count++ < 5) {
1281 /* Try again later */
1282 fotg210_enable_event(fotg210,
1283 FOTG210_HRTIMER_POLL_DEAD, true);
1284 return;
1285 }
1286 fotg210_warn(fotg210, "Waited too long for the controller to stop, giving up\n");
1287 }
1288
1289 /* Clean up the mess */
1290 fotg210->rh_state = FOTG210_RH_HALTED;
1291 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
1292 fotg210_work(fotg210);
1293 end_unlink_async(fotg210);
1294
1295 /* Not in process context, so don't try to reset the controller */
1296}
1297
1298
1299/* Handle unlinked interrupt QHs once they are gone from the hardware */
1300static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210)
1301{
1302 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING);
1303
1304 /*
1305 * Process all the QHs on the intr_unlink list that were added
1306 * before the current unlink cycle began. The list is in
1307 * temporal order, so stop when we reach the first entry in the
1308 * current cycle. But if the root hub isn't running then
1309 * process all the QHs on the list.
1310 */
1311 fotg210->intr_unlinking = true;
1312 while (fotg210->intr_unlink) {
1313 struct fotg210_qh *qh = fotg210->intr_unlink;
1314
1315 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle)
1316 break;
1317 fotg210->intr_unlink = qh->unlink_next;
1318 qh->unlink_next = NULL;
1319 end_unlink_intr(fotg210, qh);
1320 }
1321
1322 /* Handle remaining entries later */
1323 if (fotg210->intr_unlink) {
1324 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR,
1325 true);
1326 ++fotg210->intr_unlink_cycle;
1327 }
1328 fotg210->intr_unlinking = false;
1329}
1330
1331
1332/* Start another free-iTDs/siTDs cycle */
1333static void start_free_itds(struct fotg210_hcd *fotg210)
1334{
1335 if (!(fotg210->enabled_hrtimer_events &
1336 BIT(FOTG210_HRTIMER_FREE_ITDS))) {
1337 fotg210->last_itd_to_free = list_entry(
1338 fotg210->cached_itd_list.prev,
1339 struct fotg210_itd, itd_list);
1340 fotg210_enable_event(fotg210, FOTG210_HRTIMER_FREE_ITDS, true);
1341 }
1342}
1343
1344/* Wait for controller to stop using old iTDs and siTDs */
1345static void end_free_itds(struct fotg210_hcd *fotg210)
1346{
1347 struct fotg210_itd *itd, *n;
1348
1349 if (fotg210->rh_state < FOTG210_RH_RUNNING)
1350 fotg210->last_itd_to_free = NULL;
1351
1352 list_for_each_entry_safe(itd, n, &fotg210->cached_itd_list, itd_list) {
1353 list_del(&itd->itd_list);
1354 dma_pool_free(fotg210->itd_pool, itd, itd->itd_dma);
1355 if (itd == fotg210->last_itd_to_free)
1356 break;
1357 }
1358
1359 if (!list_empty(&fotg210->cached_itd_list))
1360 start_free_itds(fotg210);
1361}
1362
1363
1364/* Handle lost (or very late) IAA interrupts */
1365static void fotg210_iaa_watchdog(struct fotg210_hcd *fotg210)
1366{
1367 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1368 return;
1369
1370 /*
1371 * Lost IAA irqs wedge things badly; seen first with a vt8235.
1372 * So we need this watchdog, but must protect it against both
1373 * (a) SMP races against real IAA firing and retriggering, and
1374 * (b) clean HC shutdown, when IAA watchdog was pending.
1375 */
1376 if (fotg210->async_iaa) {
1377 u32 cmd, status;
1378
1379 /* If we get here, IAA is *REALLY* late. It's barely
1380 * conceivable that the system is so busy that CMD_IAAD
1381 * is still legitimately set, so let's be sure it's
1382 * clear before we read STS_IAA. (The HC should clear
1383 * CMD_IAAD when it sets STS_IAA.)
1384 */
1385 cmd = fotg210_readl(fotg210, &fotg210->regs->command);
1386
1387 /*
1388 * If IAA is set here it either legitimately triggered
1389 * after the watchdog timer expired (_way_ late, so we'll
1390 * still count it as lost) ... or a silicon erratum:
1391 * - VIA seems to set IAA without triggering the IRQ;
1392 * - IAAD potentially cleared without setting IAA.
1393 */
1394 status = fotg210_readl(fotg210, &fotg210->regs->status);
1395 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
1396 COUNT(fotg210->stats.lost_iaa);
1397 fotg210_writel(fotg210, STS_IAA,
1398 &fotg210->regs->status);
1399 }
1400
1401 fotg210_vdbg(fotg210, "IAA watchdog: status %x cmd %x\n",
1402 status, cmd);
1403 end_unlink_async(fotg210);
1404 }
1405}
1406
1407
1408/* Enable the I/O watchdog, if appropriate */
1409static void turn_on_io_watchdog(struct fotg210_hcd *fotg210)
1410{
1411 /* Not needed if the controller isn't running or it's already enabled */
1412 if (fotg210->rh_state != FOTG210_RH_RUNNING ||
1413 (fotg210->enabled_hrtimer_events &
1414 BIT(FOTG210_HRTIMER_IO_WATCHDOG)))
1415 return;
1416
1417 /*
1418 * Isochronous transfers always need the watchdog.
1419 * For other sorts we use it only if the flag is set.
1420 */
1421 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog &&
1422 fotg210->async_count + fotg210->intr_count > 0))
1423 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IO_WATCHDOG,
1424 true);
1425}
1426
1427
1428/*
1429 * Handler functions for the hrtimer event types.
1430 * Keep this array in the same order as the event types indexed by
1431 * enum fotg210_hrtimer_event in fotg210.h.
1432 */
1433static void (*event_handlers[])(struct fotg210_hcd *) = {
1434 fotg210_poll_ASS, /* FOTG210_HRTIMER_POLL_ASS */
1435 fotg210_poll_PSS, /* FOTG210_HRTIMER_POLL_PSS */
1436 fotg210_handle_controller_death, /* FOTG210_HRTIMER_POLL_DEAD */
1437 fotg210_handle_intr_unlinks, /* FOTG210_HRTIMER_UNLINK_INTR */
1438 end_free_itds, /* FOTG210_HRTIMER_FREE_ITDS */
1439 unlink_empty_async, /* FOTG210_HRTIMER_ASYNC_UNLINKS */
1440 fotg210_iaa_watchdog, /* FOTG210_HRTIMER_IAA_WATCHDOG */
1441 fotg210_disable_PSE, /* FOTG210_HRTIMER_DISABLE_PERIODIC */
1442 fotg210_disable_ASE, /* FOTG210_HRTIMER_DISABLE_ASYNC */
1443 fotg210_work, /* FOTG210_HRTIMER_IO_WATCHDOG */
1444};
1445
1446static enum hrtimer_restart fotg210_hrtimer_func(struct hrtimer *t)
1447{
1448 struct fotg210_hcd *fotg210 =
1449 container_of(t, struct fotg210_hcd, hrtimer);
1450 ktime_t now;
1451 unsigned long events;
1452 unsigned long flags;
1453 unsigned e;
1454
1455 spin_lock_irqsave(&fotg210->lock, flags);
1456
1457 events = fotg210->enabled_hrtimer_events;
1458 fotg210->enabled_hrtimer_events = 0;
1459 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT;
1460
1461 /*
1462 * Check each pending event. If its time has expired, handle
1463 * the event; otherwise re-enable it.
1464 */
1465 now = ktime_get();
1466 for_each_set_bit(e, &events, FOTG210_HRTIMER_NUM_EVENTS) {
1467 if (now.tv64 >= fotg210->hr_timeouts[e].tv64)
1468 event_handlers[e](fotg210);
1469 else
1470 fotg210_enable_event(fotg210, e, false);
1471 }
1472
1473 spin_unlock_irqrestore(&fotg210->lock, flags);
1474 return HRTIMER_NORESTART;
1475}
1476
1477/*-------------------------------------------------------------------------*/
1478
1479#define fotg210_bus_suspend NULL
1480#define fotg210_bus_resume NULL
1481
1482/*-------------------------------------------------------------------------*/
1483
1484static int check_reset_complete(
1485 struct fotg210_hcd *fotg210,
1486 int index,
1487 u32 __iomem *status_reg,
1488 int port_status
1489) {
1490 if (!(port_status & PORT_CONNECT))
1491 return port_status;
1492
1493 /* if reset finished and it's still not enabled -- handoff */
1494 if (!(port_status & PORT_PE)) {
1495 /* with integrated TT, there's nobody to hand it to! */
1496 fotg210_dbg(fotg210,
1497 "Failed to enable port %d on root hub TT\n",
1498 index+1);
1499 return port_status;
1500 } else {
1501 fotg210_dbg(fotg210, "port %d reset complete, port enabled\n",
1502 index + 1);
1503 }
1504
1505 return port_status;
1506}
1507
1508/*-------------------------------------------------------------------------*/
1509
1510
1511/* build "status change" packet (one or two bytes) from HC registers */
1512
1513static int
1514fotg210_hub_status_data(struct usb_hcd *hcd, char *buf)
1515{
1516 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
1517 u32 temp, status;
1518 u32 mask;
1519 int retval = 1;
1520 unsigned long flags;
1521
1522 /* init status to no-changes */
1523 buf[0] = 0;
1524
1525 /* Inform the core about resumes-in-progress by returning
1526 * a non-zero value even if there are no status changes.
1527 */
1528 status = fotg210->resuming_ports;
1529
1530 mask = PORT_CSC | PORT_PEC;
1531 /* PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND */
1532
1533 /* no hub change reports (bit 0) for now (power, ...) */
1534
1535 /* port N changes (bit N)? */
1536 spin_lock_irqsave(&fotg210->lock, flags);
1537
1538 temp = fotg210_readl(fotg210, &fotg210->regs->port_status);
1539
1540 /*
1541 * Return status information even for ports with OWNER set.
1542 * Otherwise khubd wouldn't see the disconnect event when a
1543 * high-speed device is switched over to the companion
1544 * controller by the user.
1545 */
1546
1547 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend)
1548 || (fotg210->reset_done[0] && time_after_eq(
1549 jiffies, fotg210->reset_done[0]))) {
1550 buf[0] |= 1 << 1;
1551 status = STS_PCD;
1552 }
1553 /* FIXME autosuspend idle root hubs */
1554 spin_unlock_irqrestore(&fotg210->lock, flags);
1555 return status ? retval : 0;
1556}
1557
1558/*-------------------------------------------------------------------------*/
1559
1560static void
1561fotg210_hub_descriptor(
1562 struct fotg210_hcd *fotg210,
1563 struct usb_hub_descriptor *desc
1564) {
1565 int ports = HCS_N_PORTS(fotg210->hcs_params);
1566 u16 temp;
1567
1568 desc->bDescriptorType = 0x29;
1569 desc->bPwrOn2PwrGood = 10; /* fotg210 1.0, 2.3.9 says 20ms max */
1570 desc->bHubContrCurrent = 0;
1571
1572 desc->bNbrPorts = ports;
1573 temp = 1 + (ports / 8);
1574 desc->bDescLength = 7 + 2 * temp;
1575
1576 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
1577 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
1578 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
1579
1580 temp = 0x0008; /* per-port overcurrent reporting */
1581 temp |= 0x0002; /* no power switching */
1582 desc->wHubCharacteristics = cpu_to_le16(temp);
1583}
1584
1585/*-------------------------------------------------------------------------*/
1586
1587static int fotg210_hub_control(
1588 struct usb_hcd *hcd,
1589 u16 typeReq,
1590 u16 wValue,
1591 u16 wIndex,
1592 char *buf,
1593 u16 wLength
1594) {
1595 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
1596 int ports = HCS_N_PORTS(fotg210->hcs_params);
1597 u32 __iomem *status_reg = &fotg210->regs->port_status;
1598 u32 temp, temp1, status;
1599 unsigned long flags;
1600 int retval = 0;
1601 unsigned selector;
1602
1603 /*
1604 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
1605 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
1606 * (track current state ourselves) ... blink for diagnostics,
1607 * power, "this is the one", etc. EHCI spec supports this.
1608 */
1609
1610 spin_lock_irqsave(&fotg210->lock, flags);
1611 switch (typeReq) {
1612 case ClearHubFeature:
1613 switch (wValue) {
1614 case C_HUB_LOCAL_POWER:
1615 case C_HUB_OVER_CURRENT:
1616 /* no hub-wide feature/status flags */
1617 break;
1618 default:
1619 goto error;
1620 }
1621 break;
1622 case ClearPortFeature:
1623 if (!wIndex || wIndex > ports)
1624 goto error;
1625 wIndex--;
1626 temp = fotg210_readl(fotg210, status_reg);
1627 temp &= ~PORT_RWC_BITS;
1628
1629 /*
1630 * Even if OWNER is set, so the port is owned by the
1631 * companion controller, khubd needs to be able to clear
1632 * the port-change status bits (especially
1633 * USB_PORT_STAT_C_CONNECTION).
1634 */
1635
1636 switch (wValue) {
1637 case USB_PORT_FEAT_ENABLE:
1638 fotg210_writel(fotg210, temp & ~PORT_PE, status_reg);
1639 break;
1640 case USB_PORT_FEAT_C_ENABLE:
1641 fotg210_writel(fotg210, temp | PORT_PEC, status_reg);
1642 break;
1643 case USB_PORT_FEAT_SUSPEND:
1644 if (temp & PORT_RESET)
1645 goto error;
1646 if (!(temp & PORT_SUSPEND))
1647 break;
1648 if ((temp & PORT_PE) == 0)
1649 goto error;
1650
1651 /* resume signaling for 20 msec */
1652 fotg210_writel(fotg210, temp | PORT_RESUME, status_reg);
1653 fotg210->reset_done[wIndex] = jiffies
1654 + msecs_to_jiffies(20);
1655 break;
1656 case USB_PORT_FEAT_C_SUSPEND:
1657 clear_bit(wIndex, &fotg210->port_c_suspend);
1658 break;
1659 case USB_PORT_FEAT_C_CONNECTION:
1660 fotg210_writel(fotg210, temp | PORT_CSC, status_reg);
1661 break;
1662 case USB_PORT_FEAT_C_OVER_CURRENT:
1663 fotg210_writel(fotg210, temp | OTGISR_OVC,
1664 &fotg210->regs->otgisr);
1665 break;
1666 case USB_PORT_FEAT_C_RESET:
1667 /* GetPortStatus clears reset */
1668 break;
1669 default:
1670 goto error;
1671 }
1672 fotg210_readl(fotg210, &fotg210->regs->command);
1673 break;
1674 case GetHubDescriptor:
1675 fotg210_hub_descriptor(fotg210, (struct usb_hub_descriptor *)
1676 buf);
1677 break;
1678 case GetHubStatus:
1679 /* no hub-wide feature/status flags */
1680 memset(buf, 0, 4);
1681 /*cpu_to_le32s ((u32 *) buf); */
1682 break;
1683 case GetPortStatus:
1684 if (!wIndex || wIndex > ports)
1685 goto error;
1686 wIndex--;
1687 status = 0;
1688 temp = fotg210_readl(fotg210, status_reg);
1689
1690 /* wPortChange bits */
1691 if (temp & PORT_CSC)
1692 status |= USB_PORT_STAT_C_CONNECTION << 16;
1693 if (temp & PORT_PEC)
1694 status |= USB_PORT_STAT_C_ENABLE << 16;
1695
1696 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr);
1697 if (temp1 & OTGISR_OVC)
1698 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
1699
1700 /* whoever resumes must GetPortStatus to complete it!! */
1701 if (temp & PORT_RESUME) {
1702
1703 /* Remote Wakeup received? */
1704 if (!fotg210->reset_done[wIndex]) {
1705 /* resume signaling for 20 msec */
1706 fotg210->reset_done[wIndex] = jiffies
1707 + msecs_to_jiffies(20);
1708 /* check the port again */
1709 mod_timer(&fotg210_to_hcd(fotg210)->rh_timer,
1710 fotg210->reset_done[wIndex]);
1711 }
1712
1713 /* resume completed? */
1714 else if (time_after_eq(jiffies,
1715 fotg210->reset_done[wIndex])) {
1716 clear_bit(wIndex, &fotg210->suspended_ports);
1717 set_bit(wIndex, &fotg210->port_c_suspend);
1718 fotg210->reset_done[wIndex] = 0;
1719
1720 /* stop resume signaling */
1721 temp = fotg210_readl(fotg210, status_reg);
1722 fotg210_writel(fotg210,
1723 temp & ~(PORT_RWC_BITS | PORT_RESUME),
1724 status_reg);
1725 clear_bit(wIndex, &fotg210->resuming_ports);
1726 retval = handshake(fotg210, status_reg,
1727 PORT_RESUME, 0, 2000 /* 2msec */);
1728 if (retval != 0) {
1729 fotg210_err(fotg210,
1730 "port %d resume error %d\n",
1731 wIndex + 1, retval);
1732 goto error;
1733 }
1734 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
1735 }
1736 }
1737
1738 /* whoever resets must GetPortStatus to complete it!! */
1739 if ((temp & PORT_RESET)
1740 && time_after_eq(jiffies,
1741 fotg210->reset_done[wIndex])) {
1742 status |= USB_PORT_STAT_C_RESET << 16;
1743 fotg210->reset_done[wIndex] = 0;
1744 clear_bit(wIndex, &fotg210->resuming_ports);
1745
1746 /* force reset to complete */
1747 fotg210_writel(fotg210,
1748 temp & ~(PORT_RWC_BITS | PORT_RESET),
1749 status_reg);
1750 /* REVISIT: some hardware needs 550+ usec to clear
1751 * this bit; seems too long to spin routinely...
1752 */
1753 retval = handshake(fotg210, status_reg,
1754 PORT_RESET, 0, 1000);
1755 if (retval != 0) {
1756 fotg210_err(fotg210, "port %d reset error %d\n",
1757 wIndex + 1, retval);
1758 goto error;
1759 }
1760
1761 /* see what we found out */
1762 temp = check_reset_complete(fotg210, wIndex, status_reg,
1763 fotg210_readl(fotg210, status_reg));
1764 }
1765
1766 if (!(temp & (PORT_RESUME|PORT_RESET))) {
1767 fotg210->reset_done[wIndex] = 0;
1768 clear_bit(wIndex, &fotg210->resuming_ports);
1769 }
1770
1771 /* transfer dedicated ports to the companion hc */
1772 if ((temp & PORT_CONNECT) &&
1773 test_bit(wIndex, &fotg210->companion_ports)) {
1774 temp &= ~PORT_RWC_BITS;
1775 fotg210_writel(fotg210, temp, status_reg);
1776 fotg210_dbg(fotg210, "port %d --> companion\n",
1777 wIndex + 1);
1778 temp = fotg210_readl(fotg210, status_reg);
1779 }
1780
1781 /*
1782 * Even if OWNER is set, there's no harm letting khubd
1783 * see the wPortStatus values (they should all be 0 except
1784 * for PORT_POWER anyway).
1785 */
1786
1787 if (temp & PORT_CONNECT) {
1788 status |= USB_PORT_STAT_CONNECTION;
1789 status |= fotg210_port_speed(fotg210, temp);
1790 }
1791 if (temp & PORT_PE)
1792 status |= USB_PORT_STAT_ENABLE;
1793
1794 /* maybe the port was unsuspended without our knowledge */
1795 if (temp & (PORT_SUSPEND|PORT_RESUME)) {
1796 status |= USB_PORT_STAT_SUSPEND;
1797 } else if (test_bit(wIndex, &fotg210->suspended_ports)) {
1798 clear_bit(wIndex, &fotg210->suspended_ports);
1799 clear_bit(wIndex, &fotg210->resuming_ports);
1800 fotg210->reset_done[wIndex] = 0;
1801 if (temp & PORT_PE)
1802 set_bit(wIndex, &fotg210->port_c_suspend);
1803 }
1804
1805 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr);
1806 if (temp1 & OTGISR_OVC)
1807 status |= USB_PORT_STAT_OVERCURRENT;
1808 if (temp & PORT_RESET)
1809 status |= USB_PORT_STAT_RESET;
1810 if (test_bit(wIndex, &fotg210->port_c_suspend))
1811 status |= USB_PORT_STAT_C_SUSPEND << 16;
1812
1813#ifndef VERBOSE_DEBUG
1814 if (status & ~0xffff) /* only if wPortChange is interesting */
1815#endif
1816 dbg_port(fotg210, "GetStatus", wIndex + 1, temp);
1817 put_unaligned_le32(status, buf);
1818 break;
1819 case SetHubFeature:
1820 switch (wValue) {
1821 case C_HUB_LOCAL_POWER:
1822 case C_HUB_OVER_CURRENT:
1823 /* no hub-wide feature/status flags */
1824 break;
1825 default:
1826 goto error;
1827 }
1828 break;
1829 case SetPortFeature:
1830 selector = wIndex >> 8;
1831 wIndex &= 0xff;
1832
1833 if (!wIndex || wIndex > ports)
1834 goto error;
1835 wIndex--;
1836 temp = fotg210_readl(fotg210, status_reg);
1837 temp &= ~PORT_RWC_BITS;
1838 switch (wValue) {
1839 case USB_PORT_FEAT_SUSPEND:
1840 if ((temp & PORT_PE) == 0
1841 || (temp & PORT_RESET) != 0)
1842 goto error;
1843
1844 /* After above check the port must be connected.
1845 * Set appropriate bit thus could put phy into low power
1846 * mode if we have hostpc feature
1847 */
1848 fotg210_writel(fotg210, temp | PORT_SUSPEND,
1849 status_reg);
1850 set_bit(wIndex, &fotg210->suspended_ports);
1851 break;
1852 case USB_PORT_FEAT_RESET:
1853 if (temp & PORT_RESUME)
1854 goto error;
1855 /* line status bits may report this as low speed,
1856 * which can be fine if this root hub has a
1857 * transaction translator built in.
1858 */
1859 fotg210_vdbg(fotg210, "port %d reset\n", wIndex + 1);
1860 temp |= PORT_RESET;
1861 temp &= ~PORT_PE;
1862
1863 /*
1864 * caller must wait, then call GetPortStatus
1865 * usb 2.0 spec says 50 ms resets on root
1866 */
1867 fotg210->reset_done[wIndex] = jiffies
1868 + msecs_to_jiffies(50);
1869 fotg210_writel(fotg210, temp, status_reg);
1870 break;
1871
1872 /* For downstream facing ports (these): one hub port is put
1873 * into test mode according to USB2 11.24.2.13, then the hub
1874 * must be reset (which for root hub now means rmmod+modprobe,
1875 * or else system reboot). See EHCI 2.3.9 and 4.14 for info
1876 * about the EHCI-specific stuff.
1877 */
1878 case USB_PORT_FEAT_TEST:
1879 if (!selector || selector > 5)
1880 goto error;
1881 spin_unlock_irqrestore(&fotg210->lock, flags);
1882 fotg210_quiesce(fotg210);
1883 spin_lock_irqsave(&fotg210->lock, flags);
1884
1885 /* Put all enabled ports into suspend */
1886 temp = fotg210_readl(fotg210, status_reg) &
1887 ~PORT_RWC_BITS;
1888 if (temp & PORT_PE)
1889 fotg210_writel(fotg210, temp | PORT_SUSPEND,
1890 status_reg);
1891
1892 spin_unlock_irqrestore(&fotg210->lock, flags);
1893 fotg210_halt(fotg210);
1894 spin_lock_irqsave(&fotg210->lock, flags);
1895
1896 temp = fotg210_readl(fotg210, status_reg);
1897 temp |= selector << 16;
1898 fotg210_writel(fotg210, temp, status_reg);
1899 break;
1900
1901 default:
1902 goto error;
1903 }
1904 fotg210_readl(fotg210, &fotg210->regs->command);
1905 break;
1906
1907 default:
1908error:
1909 /* "stall" on error */
1910 retval = -EPIPE;
1911 }
1912 spin_unlock_irqrestore(&fotg210->lock, flags);
1913 return retval;
1914}
1915
1916static void __maybe_unused fotg210_relinquish_port(struct usb_hcd *hcd,
1917 int portnum)
1918{
1919 return;
1920}
1921
1922static int __maybe_unused fotg210_port_handed_over(struct usb_hcd *hcd,
1923 int portnum)
1924{
1925 return 0;
1926}
1927/*-------------------------------------------------------------------------*/
1928/*
1929 * There's basically three types of memory:
1930 * - data used only by the HCD ... kmalloc is fine
1931 * - async and periodic schedules, shared by HC and HCD ... these
1932 * need to use dma_pool or dma_alloc_coherent
1933 * - driver buffers, read/written by HC ... single shot DMA mapped
1934 *
1935 * There's also "register" data (e.g. PCI or SOC), which is memory mapped.
1936 * No memory seen by this driver is pageable.
1937 */
1938
1939/*-------------------------------------------------------------------------*/
1940
1941/* Allocate the key transfer structures from the previously allocated pool */
1942
1943static inline void fotg210_qtd_init(struct fotg210_hcd *fotg210,
1944 struct fotg210_qtd *qtd, dma_addr_t dma)
1945{
1946 memset(qtd, 0, sizeof(*qtd));
1947 qtd->qtd_dma = dma;
1948 qtd->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT);
1949 qtd->hw_next = FOTG210_LIST_END(fotg210);
1950 qtd->hw_alt_next = FOTG210_LIST_END(fotg210);
1951 INIT_LIST_HEAD(&qtd->qtd_list);
1952}
1953
1954static struct fotg210_qtd *fotg210_qtd_alloc(struct fotg210_hcd *fotg210,
1955 gfp_t flags)
1956{
1957 struct fotg210_qtd *qtd;
1958 dma_addr_t dma;
1959
1960 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma);
1961 if (qtd != NULL)
1962 fotg210_qtd_init(fotg210, qtd, dma);
1963
1964 return qtd;
1965}
1966
1967static inline void fotg210_qtd_free(struct fotg210_hcd *fotg210,
1968 struct fotg210_qtd *qtd)
1969{
1970 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma);
1971}
1972
1973
1974static void qh_destroy(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
1975{
1976 /* clean qtds first, and know this is not linked */
1977 if (!list_empty(&qh->qtd_list) || qh->qh_next.ptr) {
1978 fotg210_dbg(fotg210, "unused qh not empty!\n");
1979 BUG();
1980 }
1981 if (qh->dummy)
1982 fotg210_qtd_free(fotg210, qh->dummy);
1983 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma);
1984 kfree(qh);
1985}
1986
1987static struct fotg210_qh *fotg210_qh_alloc(struct fotg210_hcd *fotg210,
1988 gfp_t flags)
1989{
1990 struct fotg210_qh *qh;
1991 dma_addr_t dma;
1992
1993 qh = kzalloc(sizeof(*qh), GFP_ATOMIC);
1994 if (!qh)
1995 goto done;
1996 qh->hw = (struct fotg210_qh_hw *)
1997 dma_pool_alloc(fotg210->qh_pool, flags, &dma);
1998 if (!qh->hw)
1999 goto fail;
2000 memset(qh->hw, 0, sizeof(*qh->hw));
2001 qh->qh_dma = dma;
2002 INIT_LIST_HEAD(&qh->qtd_list);
2003
2004 /* dummy td enables safe urb queuing */
2005 qh->dummy = fotg210_qtd_alloc(fotg210, flags);
2006 if (qh->dummy == NULL) {
2007 fotg210_dbg(fotg210, "no dummy td\n");
2008 goto fail1;
2009 }
2010done:
2011 return qh;
2012fail1:
2013 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma);
2014fail:
2015 kfree(qh);
2016 return NULL;
2017}
2018
2019/*-------------------------------------------------------------------------*/
2020
2021/* The queue heads and transfer descriptors are managed from pools tied
2022 * to each of the "per device" structures.
2023 * This is the initialisation and cleanup code.
2024 */
2025
2026static void fotg210_mem_cleanup(struct fotg210_hcd *fotg210)
2027{
2028 if (fotg210->async)
2029 qh_destroy(fotg210, fotg210->async);
2030 fotg210->async = NULL;
2031
2032 if (fotg210->dummy)
2033 qh_destroy(fotg210, fotg210->dummy);
2034 fotg210->dummy = NULL;
2035
2036 /* DMA consistent memory and pools */
2037 if (fotg210->qtd_pool)
2038 dma_pool_destroy(fotg210->qtd_pool);
2039 fotg210->qtd_pool = NULL;
2040
2041 if (fotg210->qh_pool) {
2042 dma_pool_destroy(fotg210->qh_pool);
2043 fotg210->qh_pool = NULL;
2044 }
2045
2046 if (fotg210->itd_pool)
2047 dma_pool_destroy(fotg210->itd_pool);
2048 fotg210->itd_pool = NULL;
2049
2050 if (fotg210->periodic)
2051 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller,
2052 fotg210->periodic_size * sizeof(u32),
2053 fotg210->periodic, fotg210->periodic_dma);
2054 fotg210->periodic = NULL;
2055
2056 /* shadow periodic table */
2057 kfree(fotg210->pshadow);
2058 fotg210->pshadow = NULL;
2059}
2060
2061/* remember to add cleanup code (above) if you add anything here */
2062static int fotg210_mem_init(struct fotg210_hcd *fotg210, gfp_t flags)
2063{
2064 int i;
2065
2066 /* QTDs for control/bulk/intr transfers */
2067 fotg210->qtd_pool = dma_pool_create("fotg210_qtd",
2068 fotg210_to_hcd(fotg210)->self.controller,
2069 sizeof(struct fotg210_qtd),
2070 32 /* byte alignment (for hw parts) */,
2071 4096 /* can't cross 4K */);
2072 if (!fotg210->qtd_pool)
2073 goto fail;
2074
2075 /* QHs for control/bulk/intr transfers */
2076 fotg210->qh_pool = dma_pool_create("fotg210_qh",
2077 fotg210_to_hcd(fotg210)->self.controller,
2078 sizeof(struct fotg210_qh_hw),
2079 32 /* byte alignment (for hw parts) */,
2080 4096 /* can't cross 4K */);
2081 if (!fotg210->qh_pool)
2082 goto fail;
2083
2084 fotg210->async = fotg210_qh_alloc(fotg210, flags);
2085 if (!fotg210->async)
2086 goto fail;
2087
2088 /* ITD for high speed ISO transfers */
2089 fotg210->itd_pool = dma_pool_create("fotg210_itd",
2090 fotg210_to_hcd(fotg210)->self.controller,
2091 sizeof(struct fotg210_itd),
2092 64 /* byte alignment (for hw parts) */,
2093 4096 /* can't cross 4K */);
2094 if (!fotg210->itd_pool)
2095 goto fail;
2096
2097 /* Hardware periodic table */
2098 fotg210->periodic = (__le32 *)
2099 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller,
2100 fotg210->periodic_size * sizeof(__le32),
2101 &fotg210->periodic_dma, 0);
2102 if (fotg210->periodic == NULL)
2103 goto fail;
2104
2105 for (i = 0; i < fotg210->periodic_size; i++)
2106 fotg210->periodic[i] = FOTG210_LIST_END(fotg210);
2107
2108 /* software shadow of hardware table */
2109 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *),
2110 flags);
2111 if (fotg210->pshadow != NULL)
2112 return 0;
2113
2114fail:
2115 fotg210_dbg(fotg210, "couldn't init memory\n");
2116 fotg210_mem_cleanup(fotg210);
2117 return -ENOMEM;
2118}
2119/*-------------------------------------------------------------------------*/
2120/*
2121 * EHCI hardware queue manipulation ... the core. QH/QTD manipulation.
2122 *
2123 * Control, bulk, and interrupt traffic all use "qh" lists. They list "qtd"
2124 * entries describing USB transactions, max 16-20kB/entry (with 4kB-aligned
2125 * buffers needed for the larger number). We use one QH per endpoint, queue
2126 * multiple urbs (all three types) per endpoint. URBs may need several qtds.
2127 *
2128 * ISO traffic uses "ISO TD" (itd) records, and (along with
2129 * interrupts) needs careful scheduling. Performance improvements can be
2130 * an ongoing challenge. That's in "ehci-sched.c".
2131 *
2132 * USB 1.1 devices are handled (a) by "companion" OHCI or UHCI root hubs,
2133 * or otherwise through transaction translators (TTs) in USB 2.0 hubs using
2134 * (b) special fields in qh entries or (c) split iso entries. TTs will
2135 * buffer low/full speed data so the host collects it at high speed.
2136 */
2137
2138/*-------------------------------------------------------------------------*/
2139
2140/* fill a qtd, returning how much of the buffer we were able to queue up */
2141
2142static int
2143qtd_fill(struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd, dma_addr_t buf,
2144 size_t len, int token, int maxpacket)
2145{
2146 int i, count;
2147 u64 addr = buf;
2148
2149 /* one buffer entry per 4K ... first might be short or unaligned */
2150 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr);
2151 qtd->hw_buf_hi[0] = cpu_to_hc32(fotg210, (u32)(addr >> 32));
2152 count = 0x1000 - (buf & 0x0fff); /* rest of that page */
2153 if (likely(len < count)) /* ... iff needed */
2154 count = len;
2155 else {
2156 buf += 0x1000;
2157 buf &= ~0x0fff;
2158
2159 /* per-qtd limit: from 16K to 20K (best alignment) */
2160 for (i = 1; count < len && i < 5; i++) {
2161 addr = buf;
2162 qtd->hw_buf[i] = cpu_to_hc32(fotg210, (u32)addr);
2163 qtd->hw_buf_hi[i] = cpu_to_hc32(fotg210,
2164 (u32)(addr >> 32));
2165 buf += 0x1000;
2166 if ((count + 0x1000) < len)
2167 count += 0x1000;
2168 else
2169 count = len;
2170 }
2171
2172 /* short packets may only terminate transfers */
2173 if (count != len)
2174 count -= (count % maxpacket);
2175 }
2176 qtd->hw_token = cpu_to_hc32(fotg210, (count << 16) | token);
2177 qtd->length = count;
2178
2179 return count;
2180}
2181
2182/*-------------------------------------------------------------------------*/
2183
2184static inline void
2185qh_update(struct fotg210_hcd *fotg210, struct fotg210_qh *qh,
2186 struct fotg210_qtd *qtd)
2187{
2188 struct fotg210_qh_hw *hw = qh->hw;
2189
2190 /* writes to an active overlay are unsafe */
2191 BUG_ON(qh->qh_state != QH_STATE_IDLE);
2192
2193 hw->hw_qtd_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2194 hw->hw_alt_next = FOTG210_LIST_END(fotg210);
2195
2196 /* Except for control endpoints, we make hardware maintain data
2197 * toggle (like OHCI) ... here (re)initialize the toggle in the QH,
2198 * and set the pseudo-toggle in udev. Only usb_clear_halt() will
2199 * ever clear it.
2200 */
2201 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) {
2202 unsigned is_out, epnum;
2203
2204 is_out = qh->is_out;
2205 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f;
2206 if (unlikely(!usb_gettoggle(qh->dev, epnum, is_out))) {
2207 hw->hw_token &= ~cpu_to_hc32(fotg210, QTD_TOGGLE);
2208 usb_settoggle(qh->dev, epnum, is_out, 1);
2209 }
2210 }
2211
2212 hw->hw_token &= cpu_to_hc32(fotg210, QTD_TOGGLE | QTD_STS_PING);
2213}
2214
2215/* if it weren't for a common silicon quirk (writing the dummy into the qh
2216 * overlay, so qh->hw_token wrongly becomes inactive/halted), only fault
2217 * recovery (including urb dequeue) would need software changes to a QH...
2218 */
2219static void
2220qh_refresh(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2221{
2222 struct fotg210_qtd *qtd;
2223
2224 if (list_empty(&qh->qtd_list))
2225 qtd = qh->dummy;
2226 else {
2227 qtd = list_entry(qh->qtd_list.next,
2228 struct fotg210_qtd, qtd_list);
2229 /*
2230 * first qtd may already be partially processed.
2231 * If we come here during unlink, the QH overlay region
2232 * might have reference to the just unlinked qtd. The
2233 * qtd is updated in qh_completions(). Update the QH
2234 * overlay here.
2235 */
2236 if (cpu_to_hc32(fotg210, qtd->qtd_dma) == qh->hw->hw_current) {
2237 qh->hw->hw_qtd_next = qtd->hw_next;
2238 qtd = NULL;
2239 }
2240 }
2241
2242 if (qtd)
2243 qh_update(fotg210, qh, qtd);
2244}
2245
2246/*-------------------------------------------------------------------------*/
2247
2248static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2249
2250static void fotg210_clear_tt_buffer_complete(struct usb_hcd *hcd,
2251 struct usb_host_endpoint *ep)
2252{
2253 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
2254 struct fotg210_qh *qh = ep->hcpriv;
2255 unsigned long flags;
2256
2257 spin_lock_irqsave(&fotg210->lock, flags);
2258 qh->clearing_tt = 0;
2259 if (qh->qh_state == QH_STATE_IDLE && !list_empty(&qh->qtd_list)
2260 && fotg210->rh_state == FOTG210_RH_RUNNING)
2261 qh_link_async(fotg210, qh);
2262 spin_unlock_irqrestore(&fotg210->lock, flags);
2263}
2264
2265static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210,
2266 struct fotg210_qh *qh,
2267 struct urb *urb, u32 token)
2268{
2269
2270 /* If an async split transaction gets an error or is unlinked,
2271 * the TT buffer may be left in an indeterminate state. We
2272 * have to clear the TT buffer.
2273 *
2274 * Note: this routine is never called for Isochronous transfers.
2275 */
2276 if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) {
2277#ifdef DEBUG
2278 struct usb_device *tt = urb->dev->tt->hub;
2279 dev_dbg(&tt->dev,
2280 "clear tt buffer port %d, a%d ep%d t%08x\n",
2281 urb->dev->ttport, urb->dev->devnum,
2282 usb_pipeendpoint(urb->pipe), token);
2283#endif /* DEBUG */
2284 if (urb->dev->tt->hub !=
2285 fotg210_to_hcd(fotg210)->self.root_hub) {
2286 if (usb_hub_clear_tt_buffer(urb) == 0)
2287 qh->clearing_tt = 1;
2288 }
2289 }
2290}
2291
2292static int qtd_copy_status(
2293 struct fotg210_hcd *fotg210,
2294 struct urb *urb,
2295 size_t length,
2296 u32 token
2297)
2298{
2299 int status = -EINPROGRESS;
2300
2301 /* count IN/OUT bytes, not SETUP (even short packets) */
2302 if (likely(QTD_PID(token) != 2))
2303 urb->actual_length += length - QTD_LENGTH(token);
2304
2305 /* don't modify error codes */
2306 if (unlikely(urb->unlinked))
2307 return status;
2308
2309 /* force cleanup after short read; not always an error */
2310 if (unlikely(IS_SHORT_READ(token)))
2311 status = -EREMOTEIO;
2312
2313 /* serious "can't proceed" faults reported by the hardware */
2314 if (token & QTD_STS_HALT) {
2315 if (token & QTD_STS_BABBLE) {
2316 /* FIXME "must" disable babbling device's port too */
2317 status = -EOVERFLOW;
2318 /* CERR nonzero + halt --> stall */
2319 } else if (QTD_CERR(token)) {
2320 status = -EPIPE;
2321
2322 /* In theory, more than one of the following bits can be set
2323 * since they are sticky and the transaction is retried.
2324 * Which to test first is rather arbitrary.
2325 */
2326 } else if (token & QTD_STS_MMF) {
2327 /* fs/ls interrupt xfer missed the complete-split */
2328 status = -EPROTO;
2329 } else if (token & QTD_STS_DBE) {
2330 status = (QTD_PID(token) == 1) /* IN ? */
2331 ? -ENOSR /* hc couldn't read data */
2332 : -ECOMM; /* hc couldn't write data */
2333 } else if (token & QTD_STS_XACT) {
2334 /* timeout, bad CRC, wrong PID, etc */
2335 fotg210_dbg(fotg210, "devpath %s ep%d%s 3strikes\n",
2336 urb->dev->devpath,
2337 usb_pipeendpoint(urb->pipe),
2338 usb_pipein(urb->pipe) ? "in" : "out");
2339 status = -EPROTO;
2340 } else { /* unknown */
2341 status = -EPROTO;
2342 }
2343
2344 fotg210_vdbg(fotg210,
2345 "dev%d ep%d%s qtd token %08x --> status %d\n",
2346 usb_pipedevice(urb->pipe),
2347 usb_pipeendpoint(urb->pipe),
2348 usb_pipein(urb->pipe) ? "in" : "out",
2349 token, status);
2350 }
2351
2352 return status;
2353}
2354
2355static void
2356fotg210_urb_done(struct fotg210_hcd *fotg210, struct urb *urb, int status)
2357__releases(fotg210->lock)
2358__acquires(fotg210->lock)
2359{
2360 if (likely(urb->hcpriv != NULL)) {
2361 struct fotg210_qh *qh = (struct fotg210_qh *) urb->hcpriv;
2362
2363 /* S-mask in a QH means it's an interrupt urb */
2364 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) {
2365
2366 /* ... update hc-wide periodic stats (for usbfs) */
2367 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs--;
2368 }
2369 }
2370
2371 if (unlikely(urb->unlinked)) {
2372 COUNT(fotg210->stats.unlink);
2373 } else {
2374 /* report non-error and short read status as zero */
2375 if (status == -EINPROGRESS || status == -EREMOTEIO)
2376 status = 0;
2377 COUNT(fotg210->stats.complete);
2378 }
2379
2380#ifdef FOTG210_URB_TRACE
2381 fotg210_dbg(fotg210,
2382 "%s %s urb %p ep%d%s status %d len %d/%d\n",
2383 __func__, urb->dev->devpath, urb,
2384 usb_pipeendpoint(urb->pipe),
2385 usb_pipein(urb->pipe) ? "in" : "out",
2386 status,
2387 urb->actual_length, urb->transfer_buffer_length);
2388#endif
2389
2390 /* complete() can reenter this HCD */
2391 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
2392 spin_unlock(&fotg210->lock);
2393 usb_hcd_giveback_urb(fotg210_to_hcd(fotg210), urb, status);
2394 spin_lock(&fotg210->lock);
2395}
2396
2397static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2398
2399/*
2400 * Process and free completed qtds for a qh, returning URBs to drivers.
2401 * Chases up to qh->hw_current. Returns number of completions called,
2402 * indicating how much "real" work we did.
2403 */
2404static unsigned
2405qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2406{
2407 struct fotg210_qtd *last, *end = qh->dummy;
2408 struct list_head *entry, *tmp;
2409 int last_status;
2410 int stopped;
2411 unsigned count = 0;
2412 u8 state;
2413 struct fotg210_qh_hw *hw = qh->hw;
2414
2415 if (unlikely(list_empty(&qh->qtd_list)))
2416 return count;
2417
2418 /* completions (or tasks on other cpus) must never clobber HALT
2419 * till we've gone through and cleaned everything up, even when
2420 * they add urbs to this qh's queue or mark them for unlinking.
2421 *
2422 * NOTE: unlinking expects to be done in queue order.
2423 *
2424 * It's a bug for qh->qh_state to be anything other than
2425 * QH_STATE_IDLE, unless our caller is scan_async() or
2426 * scan_intr().
2427 */
2428 state = qh->qh_state;
2429 qh->qh_state = QH_STATE_COMPLETING;
2430 stopped = (state == QH_STATE_IDLE);
2431
2432 rescan:
2433 last = NULL;
2434 last_status = -EINPROGRESS;
2435 qh->needs_rescan = 0;
2436
2437 /* remove de-activated QTDs from front of queue.
2438 * after faults (including short reads), cleanup this urb
2439 * then let the queue advance.
2440 * if queue is stopped, handles unlinks.
2441 */
2442 list_for_each_safe(entry, tmp, &qh->qtd_list) {
2443 struct fotg210_qtd *qtd;
2444 struct urb *urb;
2445 u32 token = 0;
2446
2447 qtd = list_entry(entry, struct fotg210_qtd, qtd_list);
2448 urb = qtd->urb;
2449
2450 /* clean up any state from previous QTD ...*/
2451 if (last) {
2452 if (likely(last->urb != urb)) {
2453 fotg210_urb_done(fotg210, last->urb,
2454 last_status);
2455 count++;
2456 last_status = -EINPROGRESS;
2457 }
2458 fotg210_qtd_free(fotg210, last);
2459 last = NULL;
2460 }
2461
2462 /* ignore urbs submitted during completions we reported */
2463 if (qtd == end)
2464 break;
2465
2466 /* hardware copies qtd out of qh overlay */
2467 rmb();
2468 token = hc32_to_cpu(fotg210, qtd->hw_token);
2469
2470 /* always clean up qtds the hc de-activated */
2471 retry_xacterr:
2472 if ((token & QTD_STS_ACTIVE) == 0) {
2473
2474 /* Report Data Buffer Error: non-fatal but useful */
2475 if (token & QTD_STS_DBE)
2476 fotg210_dbg(fotg210,
2477 "detected DataBufferErr for urb %p ep%d%s len %d, qtd %p [qh %p]\n",
2478 urb,
2479 usb_endpoint_num(&urb->ep->desc),
2480 usb_endpoint_dir_in(&urb->ep->desc)
2481 ? "in" : "out",
2482 urb->transfer_buffer_length,
2483 qtd,
2484 qh);
2485
2486 /* on STALL, error, and short reads this urb must
2487 * complete and all its qtds must be recycled.
2488 */
2489 if ((token & QTD_STS_HALT) != 0) {
2490
2491 /* retry transaction errors until we
2492 * reach the software xacterr limit
2493 */
2494 if ((token & QTD_STS_XACT) &&
2495 QTD_CERR(token) == 0 &&
2496 ++qh->xacterrs < QH_XACTERR_MAX &&
2497 !urb->unlinked) {
2498 fotg210_dbg(fotg210,
2499 "detected XactErr len %zu/%zu retry %d\n",
2500 qtd->length - QTD_LENGTH(token), qtd->length, qh->xacterrs);
2501
2502 /* reset the token in the qtd and the
2503 * qh overlay (which still contains
2504 * the qtd) so that we pick up from
2505 * where we left off
2506 */
2507 token &= ~QTD_STS_HALT;
2508 token |= QTD_STS_ACTIVE |
2509 (FOTG210_TUNE_CERR << 10);
2510 qtd->hw_token = cpu_to_hc32(fotg210,
2511 token);
2512 wmb();
2513 hw->hw_token = cpu_to_hc32(fotg210,
2514 token);
2515 goto retry_xacterr;
2516 }
2517 stopped = 1;
2518
2519 /* magic dummy for some short reads; qh won't advance.
2520 * that silicon quirk can kick in with this dummy too.
2521 *
2522 * other short reads won't stop the queue, including
2523 * control transfers (status stage handles that) or
2524 * most other single-qtd reads ... the queue stops if
2525 * URB_SHORT_NOT_OK was set so the driver submitting
2526 * the urbs could clean it up.
2527 */
2528 } else if (IS_SHORT_READ(token)
2529 && !(qtd->hw_alt_next
2530 & FOTG210_LIST_END(fotg210))) {
2531 stopped = 1;
2532 }
2533
2534 /* stop scanning when we reach qtds the hc is using */
2535 } else if (likely(!stopped
2536 && fotg210->rh_state >= FOTG210_RH_RUNNING)) {
2537 break;
2538
2539 /* scan the whole queue for unlinks whenever it stops */
2540 } else {
2541 stopped = 1;
2542
2543 /* cancel everything if we halt, suspend, etc */
2544 if (fotg210->rh_state < FOTG210_RH_RUNNING)
2545 last_status = -ESHUTDOWN;
2546
2547 /* this qtd is active; skip it unless a previous qtd
2548 * for its urb faulted, or its urb was canceled.
2549 */
2550 else if (last_status == -EINPROGRESS && !urb->unlinked)
2551 continue;
2552
2553 /* qh unlinked; token in overlay may be most current */
2554 if (state == QH_STATE_IDLE
2555 && cpu_to_hc32(fotg210, qtd->qtd_dma)
2556 == hw->hw_current) {
2557 token = hc32_to_cpu(fotg210, hw->hw_token);
2558
2559 /* An unlink may leave an incomplete
2560 * async transaction in the TT buffer.
2561 * We have to clear it.
2562 */
2563 fotg210_clear_tt_buffer(fotg210, qh, urb,
2564 token);
2565 }
2566 }
2567
2568 /* unless we already know the urb's status, collect qtd status
2569 * and update count of bytes transferred. in common short read
2570 * cases with only one data qtd (including control transfers),
2571 * queue processing won't halt. but with two or more qtds (for
2572 * example, with a 32 KB transfer), when the first qtd gets a
2573 * short read the second must be removed by hand.
2574 */
2575 if (last_status == -EINPROGRESS) {
2576 last_status = qtd_copy_status(fotg210, urb,
2577 qtd->length, token);
2578 if (last_status == -EREMOTEIO
2579 && (qtd->hw_alt_next
2580 & FOTG210_LIST_END(fotg210)))
2581 last_status = -EINPROGRESS;
2582
2583 /* As part of low/full-speed endpoint-halt processing
2584 * we must clear the TT buffer (11.17.5).
2585 */
2586 if (unlikely(last_status != -EINPROGRESS &&
2587 last_status != -EREMOTEIO)) {
2588 /* The TT's in some hubs malfunction when they
2589 * receive this request following a STALL (they
2590 * stop sending isochronous packets). Since a
2591 * STALL can't leave the TT buffer in a busy
2592 * state (if you believe Figures 11-48 - 11-51
2593 * in the USB 2.0 spec), we won't clear the TT
2594 * buffer in this case. Strictly speaking this
2595 * is a violation of the spec.
2596 */
2597 if (last_status != -EPIPE)
2598 fotg210_clear_tt_buffer(fotg210, qh,
2599 urb, token);
2600 }
2601 }
2602
2603 /* if we're removing something not at the queue head,
2604 * patch the hardware queue pointer.
2605 */
2606 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) {
2607 last = list_entry(qtd->qtd_list.prev,
2608 struct fotg210_qtd, qtd_list);
2609 last->hw_next = qtd->hw_next;
2610 }
2611
2612 /* remove qtd; it's recycled after possible urb completion */
2613 list_del(&qtd->qtd_list);
2614 last = qtd;
2615
2616 /* reinit the xacterr counter for the next qtd */
2617 qh->xacterrs = 0;
2618 }
2619
2620 /* last urb's completion might still need calling */
2621 if (likely(last != NULL)) {
2622 fotg210_urb_done(fotg210, last->urb, last_status);
2623 count++;
2624 fotg210_qtd_free(fotg210, last);
2625 }
2626
2627 /* Do we need to rescan for URBs dequeued during a giveback? */
2628 if (unlikely(qh->needs_rescan)) {
2629 /* If the QH is already unlinked, do the rescan now. */
2630 if (state == QH_STATE_IDLE)
2631 goto rescan;
2632
2633 /* Otherwise we have to wait until the QH is fully unlinked.
2634 * Our caller will start an unlink if qh->needs_rescan is
2635 * set. But if an unlink has already started, nothing needs
2636 * to be done.
2637 */
2638 if (state != QH_STATE_LINKED)
2639 qh->needs_rescan = 0;
2640 }
2641
2642 /* restore original state; caller must unlink or relink */
2643 qh->qh_state = state;
2644
2645 /* be sure the hardware's done with the qh before refreshing
2646 * it after fault cleanup, or recovering from silicon wrongly
2647 * overlaying the dummy qtd (which reduces DMA chatter).
2648 */
2649 if (stopped != 0 || hw->hw_qtd_next == FOTG210_LIST_END(fotg210)) {
2650 switch (state) {
2651 case QH_STATE_IDLE:
2652 qh_refresh(fotg210, qh);
2653 break;
2654 case QH_STATE_LINKED:
2655 /* We won't refresh a QH that's linked (after the HC
2656 * stopped the queue). That avoids a race:
2657 * - HC reads first part of QH;
2658 * - CPU updates that first part and the token;
2659 * - HC reads rest of that QH, including token
2660 * Result: HC gets an inconsistent image, and then
2661 * DMAs to/from the wrong memory (corrupting it).
2662 *
2663 * That should be rare for interrupt transfers,
2664 * except maybe high bandwidth ...
2665 */
2666
2667 /* Tell the caller to start an unlink */
2668 qh->needs_rescan = 1;
2669 break;
2670 /* otherwise, unlink already started */
2671 }
2672 }
2673
2674 return count;
2675}
2676
2677/*-------------------------------------------------------------------------*/
2678
2679/* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
2680#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
2681/* ... and packet size, for any kind of endpoint descriptor */
2682#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
2683
2684/*
2685 * reverse of qh_urb_transaction: free a list of TDs.
2686 * used for cleanup after errors, before HC sees an URB's TDs.
2687 */
2688static void qtd_list_free(
2689 struct fotg210_hcd *fotg210,
2690 struct urb *urb,
2691 struct list_head *qtd_list
2692) {
2693 struct list_head *entry, *temp;
2694
2695 list_for_each_safe(entry, temp, qtd_list) {
2696 struct fotg210_qtd *qtd;
2697
2698 qtd = list_entry(entry, struct fotg210_qtd, qtd_list);
2699 list_del(&qtd->qtd_list);
2700 fotg210_qtd_free(fotg210, qtd);
2701 }
2702}
2703
2704/*
2705 * create a list of filled qtds for this URB; won't link into qh.
2706 */
2707static struct list_head *
2708qh_urb_transaction(
2709 struct fotg210_hcd *fotg210,
2710 struct urb *urb,
2711 struct list_head *head,
2712 gfp_t flags
2713) {
2714 struct fotg210_qtd *qtd, *qtd_prev;
2715 dma_addr_t buf;
2716 int len, this_sg_len, maxpacket;
2717 int is_input;
2718 u32 token;
2719 int i;
2720 struct scatterlist *sg;
2721
2722 /*
2723 * URBs map to sequences of QTDs: one logical transaction
2724 */
2725 qtd = fotg210_qtd_alloc(fotg210, flags);
2726 if (unlikely(!qtd))
2727 return NULL;
2728 list_add_tail(&qtd->qtd_list, head);
2729 qtd->urb = urb;
2730
2731 token = QTD_STS_ACTIVE;
2732 token |= (FOTG210_TUNE_CERR << 10);
2733 /* for split transactions, SplitXState initialized to zero */
2734
2735 len = urb->transfer_buffer_length;
2736 is_input = usb_pipein(urb->pipe);
2737 if (usb_pipecontrol(urb->pipe)) {
2738 /* SETUP pid */
2739 qtd_fill(fotg210, qtd, urb->setup_dma,
2740 sizeof(struct usb_ctrlrequest),
2741 token | (2 /* "setup" */ << 8), 8);
2742
2743 /* ... and always at least one more pid */
2744 token ^= QTD_TOGGLE;
2745 qtd_prev = qtd;
2746 qtd = fotg210_qtd_alloc(fotg210, flags);
2747 if (unlikely(!qtd))
2748 goto cleanup;
2749 qtd->urb = urb;
2750 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2751 list_add_tail(&qtd->qtd_list, head);
2752
2753 /* for zero length DATA stages, STATUS is always IN */
2754 if (len == 0)
2755 token |= (1 /* "in" */ << 8);
2756 }
2757
2758 /*
2759 * data transfer stage: buffer setup
2760 */
2761 i = urb->num_mapped_sgs;
2762 if (len > 0 && i > 0) {
2763 sg = urb->sg;
2764 buf = sg_dma_address(sg);
2765
2766 /* urb->transfer_buffer_length may be smaller than the
2767 * size of the scatterlist (or vice versa)
2768 */
2769 this_sg_len = min_t(int, sg_dma_len(sg), len);
2770 } else {
2771 sg = NULL;
2772 buf = urb->transfer_dma;
2773 this_sg_len = len;
2774 }
2775
2776 if (is_input)
2777 token |= (1 /* "in" */ << 8);
2778 /* else it's already initted to "out" pid (0 << 8) */
2779
2780 maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input));
2781
2782 /*
2783 * buffer gets wrapped in one or more qtds;
2784 * last one may be "short" (including zero len)
2785 * and may serve as a control status ack
2786 */
2787 for (;;) {
2788 int this_qtd_len;
2789
2790 this_qtd_len = qtd_fill(fotg210, qtd, buf, this_sg_len, token,
2791 maxpacket);
2792 this_sg_len -= this_qtd_len;
2793 len -= this_qtd_len;
2794 buf += this_qtd_len;
2795
2796 /*
2797 * short reads advance to a "magic" dummy instead of the next
2798 * qtd ... that forces the queue to stop, for manual cleanup.
2799 * (this will usually be overridden later.)
2800 */
2801 if (is_input)
2802 qtd->hw_alt_next = fotg210->async->hw->hw_alt_next;
2803
2804 /* qh makes control packets use qtd toggle; maybe switch it */
2805 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
2806 token ^= QTD_TOGGLE;
2807
2808 if (likely(this_sg_len <= 0)) {
2809 if (--i <= 0 || len <= 0)
2810 break;
2811 sg = sg_next(sg);
2812 buf = sg_dma_address(sg);
2813 this_sg_len = min_t(int, sg_dma_len(sg), len);
2814 }
2815
2816 qtd_prev = qtd;
2817 qtd = fotg210_qtd_alloc(fotg210, flags);
2818 if (unlikely(!qtd))
2819 goto cleanup;
2820 qtd->urb = urb;
2821 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2822 list_add_tail(&qtd->qtd_list, head);
2823 }
2824
2825 /*
2826 * unless the caller requires manual cleanup after short reads,
2827 * have the alt_next mechanism keep the queue running after the
2828 * last data qtd (the only one, for control and most other cases).
2829 */
2830 if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0
2831 || usb_pipecontrol(urb->pipe)))
2832 qtd->hw_alt_next = FOTG210_LIST_END(fotg210);
2833
2834 /*
2835 * control requests may need a terminating data "status" ack;
2836 * other OUT ones may need a terminating short packet
2837 * (zero length).
2838 */
2839 if (likely(urb->transfer_buffer_length != 0)) {
2840 int one_more = 0;
2841
2842 if (usb_pipecontrol(urb->pipe)) {
2843 one_more = 1;
2844 token ^= 0x0100; /* "in" <--> "out" */
2845 token |= QTD_TOGGLE; /* force DATA1 */
2846 } else if (usb_pipeout(urb->pipe)
2847 && (urb->transfer_flags & URB_ZERO_PACKET)
2848 && !(urb->transfer_buffer_length % maxpacket)) {
2849 one_more = 1;
2850 }
2851 if (one_more) {
2852 qtd_prev = qtd;
2853 qtd = fotg210_qtd_alloc(fotg210, flags);
2854 if (unlikely(!qtd))
2855 goto cleanup;
2856 qtd->urb = urb;
2857 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2858 list_add_tail(&qtd->qtd_list, head);
2859
2860 /* never any data in such packets */
2861 qtd_fill(fotg210, qtd, 0, 0, token, 0);
2862 }
2863 }
2864
2865 /* by default, enable interrupt on urb completion */
2866 if (likely(!(urb->transfer_flags & URB_NO_INTERRUPT)))
2867 qtd->hw_token |= cpu_to_hc32(fotg210, QTD_IOC);
2868 return head;
2869
2870cleanup:
2871 qtd_list_free(fotg210, urb, head);
2872 return NULL;
2873}
2874
2875/*-------------------------------------------------------------------------*/
2876/*
2877 * Would be best to create all qh's from config descriptors,
2878 * when each interface/altsetting is established. Unlink
2879 * any previous qh and cancel its urbs first; endpoints are
2880 * implicitly reset then (data toggle too).
2881 * That'd mean updating how usbcore talks to HCDs. (2.7?)
2882*/
2883
2884
2885/*
2886 * Each QH holds a qtd list; a QH is used for everything except iso.
2887 *
2888 * For interrupt urbs, the scheduler must set the microframe scheduling
2889 * mask(s) each time the QH gets scheduled. For highspeed, that's
2890 * just one microframe in the s-mask. For split interrupt transactions
2891 * there are additional complications: c-mask, maybe FSTNs.
2892 */
2893static struct fotg210_qh *
2894qh_make(
2895 struct fotg210_hcd *fotg210,
2896 struct urb *urb,
2897 gfp_t flags
2898) {
2899 struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags);
2900 u32 info1 = 0, info2 = 0;
2901 int is_input, type;
2902 int maxp = 0;
2903 struct usb_tt *tt = urb->dev->tt;
2904 struct fotg210_qh_hw *hw;
2905
2906 if (!qh)
2907 return qh;
2908
2909 /*
2910 * init endpoint/device data for this QH
2911 */
2912 info1 |= usb_pipeendpoint(urb->pipe) << 8;
2913 info1 |= usb_pipedevice(urb->pipe) << 0;
2914
2915 is_input = usb_pipein(urb->pipe);
2916 type = usb_pipetype(urb->pipe);
2917 maxp = usb_maxpacket(urb->dev, urb->pipe, !is_input);
2918
2919 /* 1024 byte maxpacket is a hardware ceiling. High bandwidth
2920 * acts like up to 3KB, but is built from smaller packets.
2921 */
2922 if (max_packet(maxp) > 1024) {
2923 fotg210_dbg(fotg210, "bogus qh maxpacket %d\n",
2924 max_packet(maxp));
2925 goto done;
2926 }
2927
2928 /* Compute interrupt scheduling parameters just once, and save.
2929 * - allowing for high bandwidth, how many nsec/uframe are used?
2930 * - split transactions need a second CSPLIT uframe; same question
2931 * - splits also need a schedule gap (for full/low speed I/O)
2932 * - qh has a polling interval
2933 *
2934 * For control/bulk requests, the HC or TT handles these.
2935 */
2936 if (type == PIPE_INTERRUPT) {
2937 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
2938 is_input, 0,
2939 hb_mult(maxp) * max_packet(maxp)));
2940 qh->start = NO_FRAME;
2941
2942 if (urb->dev->speed == USB_SPEED_HIGH) {
2943 qh->c_usecs = 0;
2944 qh->gap_uf = 0;
2945
2946 qh->period = urb->interval >> 3;
2947 if (qh->period == 0 && urb->interval != 1) {
2948 /* NOTE interval 2 or 4 uframes could work.
2949 * But interval 1 scheduling is simpler, and
2950 * includes high bandwidth.
2951 */
2952 urb->interval = 1;
2953 } else if (qh->period > fotg210->periodic_size) {
2954 qh->period = fotg210->periodic_size;
2955 urb->interval = qh->period << 3;
2956 }
2957 } else {
2958 int think_time;
2959
2960 /* gap is f(FS/LS transfer times) */
2961 qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed,
2962 is_input, 0, maxp) / (125 * 1000);
2963
2964 /* FIXME this just approximates SPLIT/CSPLIT times */
2965 if (is_input) { /* SPLIT, gap, CSPLIT+DATA */
2966 qh->c_usecs = qh->usecs + HS_USECS(0);
2967 qh->usecs = HS_USECS(1);
2968 } else { /* SPLIT+DATA, gap, CSPLIT */
2969 qh->usecs += HS_USECS(1);
2970 qh->c_usecs = HS_USECS(0);
2971 }
2972
2973 think_time = tt ? tt->think_time : 0;
2974 qh->tt_usecs = NS_TO_US(think_time +
2975 usb_calc_bus_time(urb->dev->speed,
2976 is_input, 0, max_packet(maxp)));
2977 qh->period = urb->interval;
2978 if (qh->period > fotg210->periodic_size) {
2979 qh->period = fotg210->periodic_size;
2980 urb->interval = qh->period;
2981 }
2982 }
2983 }
2984
2985 /* support for tt scheduling, and access to toggles */
2986 qh->dev = urb->dev;
2987
2988 /* using TT? */
2989 switch (urb->dev->speed) {
2990 case USB_SPEED_LOW:
2991 info1 |= QH_LOW_SPEED;
2992 /* FALL THROUGH */
2993
2994 case USB_SPEED_FULL:
2995 /* EPS 0 means "full" */
2996 if (type != PIPE_INTERRUPT)
2997 info1 |= (FOTG210_TUNE_RL_TT << 28);
2998 if (type == PIPE_CONTROL) {
2999 info1 |= QH_CONTROL_EP; /* for TT */
3000 info1 |= QH_TOGGLE_CTL; /* toggle from qtd */
3001 }
3002 info1 |= maxp << 16;
3003
3004 info2 |= (FOTG210_TUNE_MULT_TT << 30);
3005
3006 /* Some Freescale processors have an erratum in which the
3007 * port number in the queue head was 0..N-1 instead of 1..N.
3008 */
3009 if (fotg210_has_fsl_portno_bug(fotg210))
3010 info2 |= (urb->dev->ttport-1) << 23;
3011 else
3012 info2 |= urb->dev->ttport << 23;
3013
3014 /* set the address of the TT; for TDI's integrated
3015 * root hub tt, leave it zeroed.
3016 */
3017 if (tt && tt->hub != fotg210_to_hcd(fotg210)->self.root_hub)
3018 info2 |= tt->hub->devnum << 16;
3019
3020 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */
3021
3022 break;
3023
3024 case USB_SPEED_HIGH: /* no TT involved */
3025 info1 |= QH_HIGH_SPEED;
3026 if (type == PIPE_CONTROL) {
3027 info1 |= (FOTG210_TUNE_RL_HS << 28);
3028 info1 |= 64 << 16; /* usb2 fixed maxpacket */
3029 info1 |= QH_TOGGLE_CTL; /* toggle from qtd */
3030 info2 |= (FOTG210_TUNE_MULT_HS << 30);
3031 } else if (type == PIPE_BULK) {
3032 info1 |= (FOTG210_TUNE_RL_HS << 28);
3033 /* The USB spec says that high speed bulk endpoints
3034 * always use 512 byte maxpacket. But some device
3035 * vendors decided to ignore that, and MSFT is happy
3036 * to help them do so. So now people expect to use
3037 * such nonconformant devices with Linux too; sigh.
3038 */
3039 info1 |= max_packet(maxp) << 16;
3040 info2 |= (FOTG210_TUNE_MULT_HS << 30);
3041 } else { /* PIPE_INTERRUPT */
3042 info1 |= max_packet(maxp) << 16;
3043 info2 |= hb_mult(maxp) << 30;
3044 }
3045 break;
3046 default:
3047 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev,
3048 urb->dev->speed);
3049done:
3050 qh_destroy(fotg210, qh);
3051 return NULL;
3052 }
3053
3054 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */
3055
3056 /* init as live, toggle clear, advance to dummy */
3057 qh->qh_state = QH_STATE_IDLE;
3058 hw = qh->hw;
3059 hw->hw_info1 = cpu_to_hc32(fotg210, info1);
3060 hw->hw_info2 = cpu_to_hc32(fotg210, info2);
3061 qh->is_out = !is_input;
3062 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1);
3063 qh_refresh(fotg210, qh);
3064 return qh;
3065}
3066
3067/*-------------------------------------------------------------------------*/
3068
3069static void enable_async(struct fotg210_hcd *fotg210)
3070{
3071 if (fotg210->async_count++)
3072 return;
3073
3074 /* Stop waiting to turn off the async schedule */
3075 fotg210->enabled_hrtimer_events &= ~BIT(FOTG210_HRTIMER_DISABLE_ASYNC);
3076
3077 /* Don't start the schedule until ASS is 0 */
3078 fotg210_poll_ASS(fotg210);
3079 turn_on_io_watchdog(fotg210);
3080}
3081
3082static void disable_async(struct fotg210_hcd *fotg210)
3083{
3084 if (--fotg210->async_count)
3085 return;
3086
3087 /* The async schedule and async_unlink list are supposed to be empty */
3088 WARN_ON(fotg210->async->qh_next.qh || fotg210->async_unlink);
3089
3090 /* Don't turn off the schedule until ASS is 1 */
3091 fotg210_poll_ASS(fotg210);
3092}
3093
3094/* move qh (and its qtds) onto async queue; maybe enable queue. */
3095
3096static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3097{
3098 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma);
3099 struct fotg210_qh *head;
3100
3101 /* Don't link a QH if there's a Clear-TT-Buffer pending */
3102 if (unlikely(qh->clearing_tt))
3103 return;
3104
3105 WARN_ON(qh->qh_state != QH_STATE_IDLE);
3106
3107 /* clear halt and/or toggle; and maybe recover from silicon quirk */
3108 qh_refresh(fotg210, qh);
3109
3110 /* splice right after start */
3111 head = fotg210->async;
3112 qh->qh_next = head->qh_next;
3113 qh->hw->hw_next = head->hw->hw_next;
3114 wmb();
3115
3116 head->qh_next.qh = qh;
3117 head->hw->hw_next = dma;
3118
3119 qh->xacterrs = 0;
3120 qh->qh_state = QH_STATE_LINKED;
3121 /* qtd completions reported later by interrupt */
3122
3123 enable_async(fotg210);
3124}
3125
3126/*-------------------------------------------------------------------------*/
3127
3128/*
3129 * For control/bulk/interrupt, return QH with these TDs appended.
3130 * Allocates and initializes the QH if necessary.
3131 * Returns null if it can't allocate a QH it needs to.
3132 * If the QH has TDs (urbs) already, that's great.
3133 */
3134static struct fotg210_qh *qh_append_tds(
3135 struct fotg210_hcd *fotg210,
3136 struct urb *urb,
3137 struct list_head *qtd_list,
3138 int epnum,
3139 void **ptr
3140)
3141{
3142 struct fotg210_qh *qh = NULL;
3143 __hc32 qh_addr_mask = cpu_to_hc32(fotg210, 0x7f);
3144
3145 qh = (struct fotg210_qh *) *ptr;
3146 if (unlikely(qh == NULL)) {
3147 /* can't sleep here, we have fotg210->lock... */
3148 qh = qh_make(fotg210, urb, GFP_ATOMIC);
3149 *ptr = qh;
3150 }
3151 if (likely(qh != NULL)) {
3152 struct fotg210_qtd *qtd;
3153
3154 if (unlikely(list_empty(qtd_list)))
3155 qtd = NULL;
3156 else
3157 qtd = list_entry(qtd_list->next, struct fotg210_qtd,
3158 qtd_list);
3159
3160 /* control qh may need patching ... */
3161 if (unlikely(epnum == 0)) {
3162 /* usb_reset_device() briefly reverts to address 0 */
3163 if (usb_pipedevice(urb->pipe) == 0)
3164 qh->hw->hw_info1 &= ~qh_addr_mask;
3165 }
3166
3167 /* just one way to queue requests: swap with the dummy qtd.
3168 * only hc or qh_refresh() ever modify the overlay.
3169 */
3170 if (likely(qtd != NULL)) {
3171 struct fotg210_qtd *dummy;
3172 dma_addr_t dma;
3173 __hc32 token;
3174
3175 /* to avoid racing the HC, use the dummy td instead of
3176 * the first td of our list (becomes new dummy). both
3177 * tds stay deactivated until we're done, when the
3178 * HC is allowed to fetch the old dummy (4.10.2).
3179 */
3180 token = qtd->hw_token;
3181 qtd->hw_token = HALT_BIT(fotg210);
3182
3183 dummy = qh->dummy;
3184
3185 dma = dummy->qtd_dma;
3186 *dummy = *qtd;
3187 dummy->qtd_dma = dma;
3188
3189 list_del(&qtd->qtd_list);
3190 list_add(&dummy->qtd_list, qtd_list);
3191 list_splice_tail(qtd_list, &qh->qtd_list);
3192
3193 fotg210_qtd_init(fotg210, qtd, qtd->qtd_dma);
3194 qh->dummy = qtd;
3195
3196 /* hc must see the new dummy at list end */
3197 dma = qtd->qtd_dma;
3198 qtd = list_entry(qh->qtd_list.prev,
3199 struct fotg210_qtd, qtd_list);
3200 qtd->hw_next = QTD_NEXT(fotg210, dma);
3201
3202 /* let the hc process these next qtds */
3203 wmb();
3204 dummy->hw_token = token;
3205
3206 urb->hcpriv = qh;
3207 }
3208 }
3209 return qh;
3210}
3211
3212/*-------------------------------------------------------------------------*/
3213
3214static int
3215submit_async(
3216 struct fotg210_hcd *fotg210,
3217 struct urb *urb,
3218 struct list_head *qtd_list,
3219 gfp_t mem_flags
3220) {
3221 int epnum;
3222 unsigned long flags;
3223 struct fotg210_qh *qh = NULL;
3224 int rc;
3225
3226 epnum = urb->ep->desc.bEndpointAddress;
3227
3228#ifdef FOTG210_URB_TRACE
3229 {
3230 struct fotg210_qtd *qtd;
3231 qtd = list_entry(qtd_list->next, struct fotg210_qtd, qtd_list);
3232 fotg210_dbg(fotg210,
3233 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
3234 __func__, urb->dev->devpath, urb,
3235 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out",
3236 urb->transfer_buffer_length,
3237 qtd, urb->ep->hcpriv);
3238 }
3239#endif
3240
3241 spin_lock_irqsave(&fotg210->lock, flags);
3242 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) {
3243 rc = -ESHUTDOWN;
3244 goto done;
3245 }
3246 rc = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb);
3247 if (unlikely(rc))
3248 goto done;
3249
3250 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv);
3251 if (unlikely(qh == NULL)) {
3252 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
3253 rc = -ENOMEM;
3254 goto done;
3255 }
3256
3257 /* Control/bulk operations through TTs don't need scheduling,
3258 * the HC and TT handle it when the TT has a buffer ready.
3259 */
3260 if (likely(qh->qh_state == QH_STATE_IDLE))
3261 qh_link_async(fotg210, qh);
3262 done:
3263 spin_unlock_irqrestore(&fotg210->lock, flags);
3264 if (unlikely(qh == NULL))
3265 qtd_list_free(fotg210, urb, qtd_list);
3266 return rc;
3267}
3268
3269/*-------------------------------------------------------------------------*/
3270
3271static void single_unlink_async(struct fotg210_hcd *fotg210,
3272 struct fotg210_qh *qh)
3273{
3274 struct fotg210_qh *prev;
3275
3276 /* Add to the end of the list of QHs waiting for the next IAAD */
3277 qh->qh_state = QH_STATE_UNLINK;
3278 if (fotg210->async_unlink)
3279 fotg210->async_unlink_last->unlink_next = qh;
3280 else
3281 fotg210->async_unlink = qh;
3282 fotg210->async_unlink_last = qh;
3283
3284 /* Unlink it from the schedule */
3285 prev = fotg210->async;
3286 while (prev->qh_next.qh != qh)
3287 prev = prev->qh_next.qh;
3288
3289 prev->hw->hw_next = qh->hw->hw_next;
3290 prev->qh_next = qh->qh_next;
3291 if (fotg210->qh_scan_next == qh)
3292 fotg210->qh_scan_next = qh->qh_next.qh;
3293}
3294
3295static void start_iaa_cycle(struct fotg210_hcd *fotg210, bool nested)
3296{
3297 /*
3298 * Do nothing if an IAA cycle is already running or
3299 * if one will be started shortly.
3300 */
3301 if (fotg210->async_iaa || fotg210->async_unlinking)
3302 return;
3303
3304 /* Do all the waiting QHs at once */
3305 fotg210->async_iaa = fotg210->async_unlink;
3306 fotg210->async_unlink = NULL;
3307
3308 /* If the controller isn't running, we don't have to wait for it */
3309 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) {
3310 if (!nested) /* Avoid recursion */
3311 end_unlink_async(fotg210);
3312
3313 /* Otherwise start a new IAA cycle */
3314 } else if (likely(fotg210->rh_state == FOTG210_RH_RUNNING)) {
3315 /* Make sure the unlinks are all visible to the hardware */
3316 wmb();
3317
3318 fotg210_writel(fotg210, fotg210->command | CMD_IAAD,
3319 &fotg210->regs->command);
3320 fotg210_readl(fotg210, &fotg210->regs->command);
3321 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IAA_WATCHDOG,
3322 true);
3323 }
3324}
3325
3326/* the async qh for the qtds being unlinked are now gone from the HC */
3327
3328static void end_unlink_async(struct fotg210_hcd *fotg210)
3329{
3330 struct fotg210_qh *qh;
3331
3332 /* Process the idle QHs */
3333 restart:
3334 fotg210->async_unlinking = true;
3335 while (fotg210->async_iaa) {
3336 qh = fotg210->async_iaa;
3337 fotg210->async_iaa = qh->unlink_next;
3338 qh->unlink_next = NULL;
3339
3340 qh->qh_state = QH_STATE_IDLE;
3341 qh->qh_next.qh = NULL;
3342
3343 qh_completions(fotg210, qh);
3344 if (!list_empty(&qh->qtd_list) &&
3345 fotg210->rh_state == FOTG210_RH_RUNNING)
3346 qh_link_async(fotg210, qh);
3347 disable_async(fotg210);
3348 }
3349 fotg210->async_unlinking = false;
3350
3351 /* Start a new IAA cycle if any QHs are waiting for it */
3352 if (fotg210->async_unlink) {
3353 start_iaa_cycle(fotg210, true);
3354 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING))
3355 goto restart;
3356 }
3357}
3358
3359static void unlink_empty_async(struct fotg210_hcd *fotg210)
3360{
3361 struct fotg210_qh *qh, *next;
3362 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING);
3363 bool check_unlinks_later = false;
3364
3365 /* Unlink all the async QHs that have been empty for a timer cycle */
3366 next = fotg210->async->qh_next.qh;
3367 while (next) {
3368 qh = next;
3369 next = qh->qh_next.qh;
3370
3371 if (list_empty(&qh->qtd_list) &&
3372 qh->qh_state == QH_STATE_LINKED) {
3373 if (!stopped && qh->unlink_cycle ==
3374 fotg210->async_unlink_cycle)
3375 check_unlinks_later = true;
3376 else
3377 single_unlink_async(fotg210, qh);
3378 }
3379 }
3380
3381 /* Start a new IAA cycle if any QHs are waiting for it */
3382 if (fotg210->async_unlink)
3383 start_iaa_cycle(fotg210, false);
3384
3385 /* QHs that haven't been empty for long enough will be handled later */
3386 if (check_unlinks_later) {
3387 fotg210_enable_event(fotg210, FOTG210_HRTIMER_ASYNC_UNLINKS,
3388 true);
3389 ++fotg210->async_unlink_cycle;
3390 }
3391}
3392
3393/* makes sure the async qh will become idle */
3394/* caller must own fotg210->lock */
3395
3396static void start_unlink_async(struct fotg210_hcd *fotg210,
3397 struct fotg210_qh *qh)
3398{
3399 /*
3400 * If the QH isn't linked then there's nothing we can do
3401 * unless we were called during a giveback, in which case
3402 * qh_completions() has to deal with it.
3403 */
3404 if (qh->qh_state != QH_STATE_LINKED) {
3405 if (qh->qh_state == QH_STATE_COMPLETING)
3406 qh->needs_rescan = 1;
3407 return;
3408 }
3409
3410 single_unlink_async(fotg210, qh);
3411 start_iaa_cycle(fotg210, false);
3412}
3413
3414/*-------------------------------------------------------------------------*/
3415
3416static void scan_async(struct fotg210_hcd *fotg210)
3417{
3418 struct fotg210_qh *qh;
3419 bool check_unlinks_later = false;
3420
3421 fotg210->qh_scan_next = fotg210->async->qh_next.qh;
3422 while (fotg210->qh_scan_next) {
3423 qh = fotg210->qh_scan_next;
3424 fotg210->qh_scan_next = qh->qh_next.qh;
3425 rescan:
3426 /* clean any finished work for this qh */
3427 if (!list_empty(&qh->qtd_list)) {
3428 int temp;
3429
3430 /*
3431 * Unlinks could happen here; completion reporting
3432 * drops the lock. That's why fotg210->qh_scan_next
3433 * always holds the next qh to scan; if the next qh
3434 * gets unlinked then fotg210->qh_scan_next is adjusted
3435 * in single_unlink_async().
3436 */
3437 temp = qh_completions(fotg210, qh);
3438 if (qh->needs_rescan) {
3439 start_unlink_async(fotg210, qh);
3440 } else if (list_empty(&qh->qtd_list)
3441 && qh->qh_state == QH_STATE_LINKED) {
3442 qh->unlink_cycle = fotg210->async_unlink_cycle;
3443 check_unlinks_later = true;
3444 } else if (temp != 0)
3445 goto rescan;
3446 }
3447 }
3448
3449 /*
3450 * Unlink empty entries, reducing DMA usage as well
3451 * as HCD schedule-scanning costs. Delay for any qh
3452 * we just scanned, there's a not-unusual case that it
3453 * doesn't stay idle for long.
3454 */
3455 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING &&
3456 !(fotg210->enabled_hrtimer_events &
3457 BIT(FOTG210_HRTIMER_ASYNC_UNLINKS))) {
3458 fotg210_enable_event(fotg210,
3459 FOTG210_HRTIMER_ASYNC_UNLINKS, true);
3460 ++fotg210->async_unlink_cycle;
3461 }
3462}
3463/*-------------------------------------------------------------------------*/
3464/*
3465 * EHCI scheduled transaction support: interrupt, iso, split iso
3466 * These are called "periodic" transactions in the EHCI spec.
3467 *
3468 * Note that for interrupt transfers, the QH/QTD manipulation is shared
3469 * with the "asynchronous" transaction support (control/bulk transfers).
3470 * The only real difference is in how interrupt transfers are scheduled.
3471 *
3472 * For ISO, we make an "iso_stream" head to serve the same role as a QH.
3473 * It keeps track of every ITD (or SITD) that's linked, and holds enough
3474 * pre-calculated schedule data to make appending to the queue be quick.
3475 */
3476
3477static int fotg210_get_frame(struct usb_hcd *hcd);
3478
3479/*-------------------------------------------------------------------------*/
3480
3481/*
3482 * periodic_next_shadow - return "next" pointer on shadow list
3483 * @periodic: host pointer to qh/itd
3484 * @tag: hardware tag for type of this record
3485 */
3486static union fotg210_shadow *
3487periodic_next_shadow(struct fotg210_hcd *fotg210,
3488 union fotg210_shadow *periodic, __hc32 tag)
3489{
3490 switch (hc32_to_cpu(fotg210, tag)) {
3491 case Q_TYPE_QH:
3492 return &periodic->qh->qh_next;
3493 case Q_TYPE_FSTN:
3494 return &periodic->fstn->fstn_next;
3495 default:
3496 return &periodic->itd->itd_next;
3497 }
3498}
3499
3500static __hc32 *
3501shadow_next_periodic(struct fotg210_hcd *fotg210,
3502 union fotg210_shadow *periodic, __hc32 tag)
3503{
3504 switch (hc32_to_cpu(fotg210, tag)) {
3505 /* our fotg210_shadow.qh is actually software part */
3506 case Q_TYPE_QH:
3507 return &periodic->qh->hw->hw_next;
3508 /* others are hw parts */
3509 default:
3510 return periodic->hw_next;
3511 }
3512}
3513
3514/* caller must hold fotg210->lock */
3515static void periodic_unlink(struct fotg210_hcd *fotg210, unsigned frame,
3516 void *ptr)
3517{
3518 union fotg210_shadow *prev_p = &fotg210->pshadow[frame];
3519 __hc32 *hw_p = &fotg210->periodic[frame];
3520 union fotg210_shadow here = *prev_p;
3521
3522 /* find predecessor of "ptr"; hw and shadow lists are in sync */
3523 while (here.ptr && here.ptr != ptr) {
3524 prev_p = periodic_next_shadow(fotg210, prev_p,
3525 Q_NEXT_TYPE(fotg210, *hw_p));
3526 hw_p = shadow_next_periodic(fotg210, &here,
3527 Q_NEXT_TYPE(fotg210, *hw_p));
3528 here = *prev_p;
3529 }
3530 /* an interrupt entry (at list end) could have been shared */
3531 if (!here.ptr)
3532 return;
3533
3534 /* update shadow and hardware lists ... the old "next" pointers
3535 * from ptr may still be in use, the caller updates them.
3536 */
3537 *prev_p = *periodic_next_shadow(fotg210, &here,
3538 Q_NEXT_TYPE(fotg210, *hw_p));
3539
3540 *hw_p = *shadow_next_periodic(fotg210, &here,
3541 Q_NEXT_TYPE(fotg210, *hw_p));
3542}
3543
3544/* how many of the uframe's 125 usecs are allocated? */
3545static unsigned short
3546periodic_usecs(struct fotg210_hcd *fotg210, unsigned frame, unsigned uframe)
3547{
3548 __hc32 *hw_p = &fotg210->periodic[frame];
3549 union fotg210_shadow *q = &fotg210->pshadow[frame];
3550 unsigned usecs = 0;
3551 struct fotg210_qh_hw *hw;
3552
3553 while (q->ptr) {
3554 switch (hc32_to_cpu(fotg210, Q_NEXT_TYPE(fotg210, *hw_p))) {
3555 case Q_TYPE_QH:
3556 hw = q->qh->hw;
3557 /* is it in the S-mask? */
3558 if (hw->hw_info2 & cpu_to_hc32(fotg210, 1 << uframe))
3559 usecs += q->qh->usecs;
3560 /* ... or C-mask? */
3561 if (hw->hw_info2 & cpu_to_hc32(fotg210,
3562 1 << (8 + uframe)))
3563 usecs += q->qh->c_usecs;
3564 hw_p = &hw->hw_next;
3565 q = &q->qh->qh_next;
3566 break;
3567 /* case Q_TYPE_FSTN: */
3568 default:
3569 /* for "save place" FSTNs, count the relevant INTR
3570 * bandwidth from the previous frame
3571 */
3572 if (q->fstn->hw_prev != FOTG210_LIST_END(fotg210))
3573 fotg210_dbg(fotg210, "ignoring FSTN cost ...\n");
3574
3575 hw_p = &q->fstn->hw_next;
3576 q = &q->fstn->fstn_next;
3577 break;
3578 case Q_TYPE_ITD:
3579 if (q->itd->hw_transaction[uframe])
3580 usecs += q->itd->stream->usecs;
3581 hw_p = &q->itd->hw_next;
3582 q = &q->itd->itd_next;
3583 break;
3584 }
3585 }
3586#ifdef DEBUG
3587 if (usecs > fotg210->uframe_periodic_max)
3588 fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n",
3589 frame * 8 + uframe, usecs);
3590#endif
3591 return usecs;
3592}
3593
3594/*-------------------------------------------------------------------------*/
3595
3596static int same_tt(struct usb_device *dev1, struct usb_device *dev2)
3597{
3598 if (!dev1->tt || !dev2->tt)
3599 return 0;
3600 if (dev1->tt != dev2->tt)
3601 return 0;
3602 if (dev1->tt->multi)
3603 return dev1->ttport == dev2->ttport;
3604 else
3605 return 1;
3606}
3607
3608/* return true iff the device's transaction translator is available
3609 * for a periodic transfer starting at the specified frame, using
3610 * all the uframes in the mask.
3611 */
3612static int tt_no_collision(
3613 struct fotg210_hcd *fotg210,
3614 unsigned period,
3615 struct usb_device *dev,
3616 unsigned frame,
3617 u32 uf_mask
3618)
3619{
3620 if (period == 0) /* error */
3621 return 0;
3622
3623 /* note bandwidth wastage: split never follows csplit
3624 * (different dev or endpoint) until the next uframe.
3625 * calling convention doesn't make that distinction.
3626 */
3627 for (; frame < fotg210->periodic_size; frame += period) {
3628 union fotg210_shadow here;
3629 __hc32 type;
3630 struct fotg210_qh_hw *hw;
3631
3632 here = fotg210->pshadow[frame];
3633 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]);
3634 while (here.ptr) {
3635 switch (hc32_to_cpu(fotg210, type)) {
3636 case Q_TYPE_ITD:
3637 type = Q_NEXT_TYPE(fotg210, here.itd->hw_next);
3638 here = here.itd->itd_next;
3639 continue;
3640 case Q_TYPE_QH:
3641 hw = here.qh->hw;
3642 if (same_tt(dev, here.qh->dev)) {
3643 u32 mask;
3644
3645 mask = hc32_to_cpu(fotg210,
3646 hw->hw_info2);
3647 /* "knows" no gap is needed */
3648 mask |= mask >> 8;
3649 if (mask & uf_mask)
3650 break;
3651 }
3652 type = Q_NEXT_TYPE(fotg210, hw->hw_next);
3653 here = here.qh->qh_next;
3654 continue;
3655 /* case Q_TYPE_FSTN: */
3656 default:
3657 fotg210_dbg(fotg210,
3658 "periodic frame %d bogus type %d\n",
3659 frame, type);
3660 }
3661
3662 /* collision or error */
3663 return 0;
3664 }
3665 }
3666
3667 /* no collision */
3668 return 1;
3669}
3670
3671/*-------------------------------------------------------------------------*/
3672
3673static void enable_periodic(struct fotg210_hcd *fotg210)
3674{
3675 if (fotg210->periodic_count++)
3676 return;
3677
3678 /* Stop waiting to turn off the periodic schedule */
3679 fotg210->enabled_hrtimer_events &=
3680 ~BIT(FOTG210_HRTIMER_DISABLE_PERIODIC);
3681
3682 /* Don't start the schedule until PSS is 0 */
3683 fotg210_poll_PSS(fotg210);
3684 turn_on_io_watchdog(fotg210);
3685}
3686
3687static void disable_periodic(struct fotg210_hcd *fotg210)
3688{
3689 if (--fotg210->periodic_count)
3690 return;
3691
3692 /* Don't turn off the schedule until PSS is 1 */
3693 fotg210_poll_PSS(fotg210);
3694}
3695
3696/*-------------------------------------------------------------------------*/
3697
3698/* periodic schedule slots have iso tds (normal or split) first, then a
3699 * sparse tree for active interrupt transfers.
3700 *
3701 * this just links in a qh; caller guarantees uframe masks are set right.
3702 * no FSTN support (yet; fotg210 0.96+)
3703 */
3704static void qh_link_periodic(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3705{
3706 unsigned i;
3707 unsigned period = qh->period;
3708
3709 dev_dbg(&qh->dev->dev,
3710 "link qh%d-%04x/%p start %d [%d/%d us]\n",
3711 period, hc32_to_cpup(fotg210, &qh->hw->hw_info2)
3712 & (QH_CMASK | QH_SMASK),
3713 qh, qh->start, qh->usecs, qh->c_usecs);
3714
3715 /* high bandwidth, or otherwise every microframe */
3716 if (period == 0)
3717 period = 1;
3718
3719 for (i = qh->start; i < fotg210->periodic_size; i += period) {
3720 union fotg210_shadow *prev = &fotg210->pshadow[i];
3721 __hc32 *hw_p = &fotg210->periodic[i];
3722 union fotg210_shadow here = *prev;
3723 __hc32 type = 0;
3724
3725 /* skip the iso nodes at list head */
3726 while (here.ptr) {
3727 type = Q_NEXT_TYPE(fotg210, *hw_p);
3728 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH))
3729 break;
3730 prev = periodic_next_shadow(fotg210, prev, type);
3731 hw_p = shadow_next_periodic(fotg210, &here, type);
3732 here = *prev;
3733 }
3734
3735 /* sorting each branch by period (slow-->fast)
3736 * enables sharing interior tree nodes
3737 */
3738 while (here.ptr && qh != here.qh) {
3739 if (qh->period > here.qh->period)
3740 break;
3741 prev = &here.qh->qh_next;
3742 hw_p = &here.qh->hw->hw_next;
3743 here = *prev;
3744 }
3745 /* link in this qh, unless some earlier pass did that */
3746 if (qh != here.qh) {
3747 qh->qh_next = here;
3748 if (here.qh)
3749 qh->hw->hw_next = *hw_p;
3750 wmb();
3751 prev->qh = qh;
3752 *hw_p = QH_NEXT(fotg210, qh->qh_dma);
3753 }
3754 }
3755 qh->qh_state = QH_STATE_LINKED;
3756 qh->xacterrs = 0;
3757
3758 /* update per-qh bandwidth for usbfs */
3759 fotg210_to_hcd(fotg210)->self.bandwidth_allocated += qh->period
3760 ? ((qh->usecs + qh->c_usecs) / qh->period)
3761 : (qh->usecs * 8);
3762
3763 list_add(&qh->intr_node, &fotg210->intr_qh_list);
3764
3765 /* maybe enable periodic schedule processing */
3766 ++fotg210->intr_count;
3767 enable_periodic(fotg210);
3768}
3769
3770static void qh_unlink_periodic(struct fotg210_hcd *fotg210,
3771 struct fotg210_qh *qh)
3772{
3773 unsigned i;
3774 unsigned period;
3775
3776 /*
3777 * If qh is for a low/full-speed device, simply unlinking it
3778 * could interfere with an ongoing split transaction. To unlink
3779 * it safely would require setting the QH_INACTIVATE bit and
3780 * waiting at least one frame, as described in EHCI 4.12.2.5.
3781 *
3782 * We won't bother with any of this. Instead, we assume that the
3783 * only reason for unlinking an interrupt QH while the current URB
3784 * is still active is to dequeue all the URBs (flush the whole
3785 * endpoint queue).
3786 *
3787 * If rebalancing the periodic schedule is ever implemented, this
3788 * approach will no longer be valid.
3789 */
3790
3791 /* high bandwidth, or otherwise part of every microframe */
3792 period = qh->period;
3793 if (!period)
3794 period = 1;
3795
3796 for (i = qh->start; i < fotg210->periodic_size; i += period)
3797 periodic_unlink(fotg210, i, qh);
3798
3799 /* update per-qh bandwidth for usbfs */
3800 fotg210_to_hcd(fotg210)->self.bandwidth_allocated -= qh->period
3801 ? ((qh->usecs + qh->c_usecs) / qh->period)
3802 : (qh->usecs * 8);
3803
3804 dev_dbg(&qh->dev->dev,
3805 "unlink qh%d-%04x/%p start %d [%d/%d us]\n",
3806 qh->period,
3807 hc32_to_cpup(fotg210, &qh->hw->hw_info2) &
3808 (QH_CMASK | QH_SMASK), qh, qh->start, qh->usecs, qh->c_usecs);
3809
3810 /* qh->qh_next still "live" to HC */
3811 qh->qh_state = QH_STATE_UNLINK;
3812 qh->qh_next.ptr = NULL;
3813
3814 if (fotg210->qh_scan_next == qh)
3815 fotg210->qh_scan_next = list_entry(qh->intr_node.next,
3816 struct fotg210_qh, intr_node);
3817 list_del(&qh->intr_node);
3818}
3819
3820static void start_unlink_intr(struct fotg210_hcd *fotg210,
3821 struct fotg210_qh *qh)
3822{
3823 /* If the QH isn't linked then there's nothing we can do
3824 * unless we were called during a giveback, in which case
3825 * qh_completions() has to deal with it.
3826 */
3827 if (qh->qh_state != QH_STATE_LINKED) {
3828 if (qh->qh_state == QH_STATE_COMPLETING)
3829 qh->needs_rescan = 1;
3830 return;
3831 }
3832
3833 qh_unlink_periodic(fotg210, qh);
3834
3835 /* Make sure the unlinks are visible before starting the timer */
3836 wmb();
3837
3838 /*
3839 * The EHCI spec doesn't say how long it takes the controller to
3840 * stop accessing an unlinked interrupt QH. The timer delay is
3841 * 9 uframes; presumably that will be long enough.
3842 */
3843 qh->unlink_cycle = fotg210->intr_unlink_cycle;
3844
3845 /* New entries go at the end of the intr_unlink list */
3846 if (fotg210->intr_unlink)
3847 fotg210->intr_unlink_last->unlink_next = qh;
3848 else
3849 fotg210->intr_unlink = qh;
3850 fotg210->intr_unlink_last = qh;
3851
3852 if (fotg210->intr_unlinking)
3853 ; /* Avoid recursive calls */
3854 else if (fotg210->rh_state < FOTG210_RH_RUNNING)
3855 fotg210_handle_intr_unlinks(fotg210);
3856 else if (fotg210->intr_unlink == qh) {
3857 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR,
3858 true);
3859 ++fotg210->intr_unlink_cycle;
3860 }
3861}
3862
3863static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3864{
3865 struct fotg210_qh_hw *hw = qh->hw;
3866 int rc;
3867
3868 qh->qh_state = QH_STATE_IDLE;
3869 hw->hw_next = FOTG210_LIST_END(fotg210);
3870
3871 qh_completions(fotg210, qh);
3872
3873 /* reschedule QH iff another request is queued */
3874 if (!list_empty(&qh->qtd_list) &&
3875 fotg210->rh_state == FOTG210_RH_RUNNING) {
3876 rc = qh_schedule(fotg210, qh);
3877
3878 /* An error here likely indicates handshake failure
3879 * or no space left in the schedule. Neither fault
3880 * should happen often ...
3881 *
3882 * FIXME kill the now-dysfunctional queued urbs
3883 */
3884 if (rc != 0)
3885 fotg210_err(fotg210, "can't reschedule qh %p, err %d\n",
3886 qh, rc);
3887 }
3888
3889 /* maybe turn off periodic schedule */
3890 --fotg210->intr_count;
3891 disable_periodic(fotg210);
3892}
3893
3894/*-------------------------------------------------------------------------*/
3895
3896static int check_period(
3897 struct fotg210_hcd *fotg210,
3898 unsigned frame,
3899 unsigned uframe,
3900 unsigned period,
3901 unsigned usecs
3902) {
3903 int claimed;
3904
3905 /* complete split running into next frame?
3906 * given FSTN support, we could sometimes check...
3907 */
3908 if (uframe >= 8)
3909 return 0;
3910
3911 /* convert "usecs we need" to "max already claimed" */
3912 usecs = fotg210->uframe_periodic_max - usecs;
3913
3914 /* we "know" 2 and 4 uframe intervals were rejected; so
3915 * for period 0, check _every_ microframe in the schedule.
3916 */
3917 if (unlikely(period == 0)) {
3918 do {
3919 for (uframe = 0; uframe < 7; uframe++) {
3920 claimed = periodic_usecs(fotg210, frame,
3921 uframe);
3922 if (claimed > usecs)
3923 return 0;
3924 }
3925 } while ((frame += 1) < fotg210->periodic_size);
3926
3927 /* just check the specified uframe, at that period */
3928 } else {
3929 do {
3930 claimed = periodic_usecs(fotg210, frame, uframe);
3931 if (claimed > usecs)
3932 return 0;
3933 } while ((frame += period) < fotg210->periodic_size);
3934 }
3935
3936 /* success! */
3937 return 1;
3938}
3939
3940static int check_intr_schedule(
3941 struct fotg210_hcd *fotg210,
3942 unsigned frame,
3943 unsigned uframe,
3944 const struct fotg210_qh *qh,
3945 __hc32 *c_maskp
3946)
3947{
3948 int retval = -ENOSPC;
3949 u8 mask = 0;
3950
3951 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */
3952 goto done;
3953
3954 if (!check_period(fotg210, frame, uframe, qh->period, qh->usecs))
3955 goto done;
3956 if (!qh->c_usecs) {
3957 retval = 0;
3958 *c_maskp = 0;
3959 goto done;
3960 }
3961
3962 /* Make sure this tt's buffer is also available for CSPLITs.
3963 * We pessimize a bit; probably the typical full speed case
3964 * doesn't need the second CSPLIT.
3965 *
3966 * NOTE: both SPLIT and CSPLIT could be checked in just
3967 * one smart pass...
3968 */
3969 mask = 0x03 << (uframe + qh->gap_uf);
3970 *c_maskp = cpu_to_hc32(fotg210, mask << 8);
3971
3972 mask |= 1 << uframe;
3973 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) {
3974 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1,
3975 qh->period, qh->c_usecs))
3976 goto done;
3977 if (!check_period(fotg210, frame, uframe + qh->gap_uf,
3978 qh->period, qh->c_usecs))
3979 goto done;
3980 retval = 0;
3981 }
3982done:
3983 return retval;
3984}
3985
3986/* "first fit" scheduling policy used the first time through,
3987 * or when the previous schedule slot can't be re-used.
3988 */
3989static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3990{
3991 int status;
3992 unsigned uframe;
3993 __hc32 c_mask;
3994 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
3995 struct fotg210_qh_hw *hw = qh->hw;
3996
3997 qh_refresh(fotg210, qh);
3998 hw->hw_next = FOTG210_LIST_END(fotg210);
3999 frame = qh->start;
4000
4001 /* reuse the previous schedule slots, if we can */
4002 if (frame < qh->period) {
4003 uframe = ffs(hc32_to_cpup(fotg210, &hw->hw_info2) & QH_SMASK);
4004 status = check_intr_schedule(fotg210, frame, --uframe,
4005 qh, &c_mask);
4006 } else {
4007 uframe = 0;
4008 c_mask = 0;
4009 status = -ENOSPC;
4010 }
4011
4012 /* else scan the schedule to find a group of slots such that all
4013 * uframes have enough periodic bandwidth available.
4014 */
4015 if (status) {
4016 /* "normal" case, uframing flexible except with splits */
4017 if (qh->period) {
4018 int i;
4019
4020 for (i = qh->period; status && i > 0; --i) {
4021 frame = ++fotg210->random_frame % qh->period;
4022 for (uframe = 0; uframe < 8; uframe++) {
4023 status = check_intr_schedule(fotg210,
4024 frame, uframe, qh,
4025 &c_mask);
4026 if (status == 0)
4027 break;
4028 }
4029 }
4030
4031 /* qh->period == 0 means every uframe */
4032 } else {
4033 frame = 0;
4034 status = check_intr_schedule(fotg210, 0, 0, qh,
4035 &c_mask);
4036 }
4037 if (status)
4038 goto done;
4039 qh->start = frame;
4040
4041 /* reset S-frame and (maybe) C-frame masks */
4042 hw->hw_info2 &= cpu_to_hc32(fotg210, ~(QH_CMASK | QH_SMASK));
4043 hw->hw_info2 |= qh->period
4044 ? cpu_to_hc32(fotg210, 1 << uframe)
4045 : cpu_to_hc32(fotg210, QH_SMASK);
4046 hw->hw_info2 |= c_mask;
4047 } else
4048 fotg210_dbg(fotg210, "reused qh %p schedule\n", qh);
4049
4050 /* stuff into the periodic schedule */
4051 qh_link_periodic(fotg210, qh);
4052done:
4053 return status;
4054}
4055
4056static int intr_submit(
4057 struct fotg210_hcd *fotg210,
4058 struct urb *urb,
4059 struct list_head *qtd_list,
4060 gfp_t mem_flags
4061) {
4062 unsigned epnum;
4063 unsigned long flags;
4064 struct fotg210_qh *qh;
4065 int status;
4066 struct list_head empty;
4067
4068 /* get endpoint and transfer/schedule data */
4069 epnum = urb->ep->desc.bEndpointAddress;
4070
4071 spin_lock_irqsave(&fotg210->lock, flags);
4072
4073 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) {
4074 status = -ESHUTDOWN;
4075 goto done_not_linked;
4076 }
4077 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb);
4078 if (unlikely(status))
4079 goto done_not_linked;
4080
4081 /* get qh and force any scheduling errors */
4082 INIT_LIST_HEAD(&empty);
4083 qh = qh_append_tds(fotg210, urb, &empty, epnum, &urb->ep->hcpriv);
4084 if (qh == NULL) {
4085 status = -ENOMEM;
4086 goto done;
4087 }
4088 if (qh->qh_state == QH_STATE_IDLE) {
4089 status = qh_schedule(fotg210, qh);
4090 if (status)
4091 goto done;
4092 }
4093
4094 /* then queue the urb's tds to the qh */
4095 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv);
4096 BUG_ON(qh == NULL);
4097
4098 /* ... update usbfs periodic stats */
4099 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs++;
4100
4101done:
4102 if (unlikely(status))
4103 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
4104done_not_linked:
4105 spin_unlock_irqrestore(&fotg210->lock, flags);
4106 if (status)
4107 qtd_list_free(fotg210, urb, qtd_list);
4108
4109 return status;
4110}
4111
4112static void scan_intr(struct fotg210_hcd *fotg210)
4113{
4114 struct fotg210_qh *qh;
4115
4116 list_for_each_entry_safe(qh, fotg210->qh_scan_next,
4117 &fotg210->intr_qh_list, intr_node) {
4118 rescan:
4119 /* clean any finished work for this qh */
4120 if (!list_empty(&qh->qtd_list)) {
4121 int temp;
4122
4123 /*
4124 * Unlinks could happen here; completion reporting
4125 * drops the lock. That's why fotg210->qh_scan_next
4126 * always holds the next qh to scan; if the next qh
4127 * gets unlinked then fotg210->qh_scan_next is adjusted
4128 * in qh_unlink_periodic().
4129 */
4130 temp = qh_completions(fotg210, qh);
4131 if (unlikely(qh->needs_rescan ||
4132 (list_empty(&qh->qtd_list) &&
4133 qh->qh_state == QH_STATE_LINKED)))
4134 start_unlink_intr(fotg210, qh);
4135 else if (temp != 0)
4136 goto rescan;
4137 }
4138 }
4139}
4140
4141/*-------------------------------------------------------------------------*/
4142
4143/* fotg210_iso_stream ops work with both ITD and SITD */
4144
4145static struct fotg210_iso_stream *
4146iso_stream_alloc(gfp_t mem_flags)
4147{
4148 struct fotg210_iso_stream *stream;
4149
4150 stream = kzalloc(sizeof(*stream), mem_flags);
4151 if (likely(stream != NULL)) {
4152 INIT_LIST_HEAD(&stream->td_list);
4153 INIT_LIST_HEAD(&stream->free_list);
4154 stream->next_uframe = -1;
4155 }
4156 return stream;
4157}
4158
4159static void
4160iso_stream_init(
4161 struct fotg210_hcd *fotg210,
4162 struct fotg210_iso_stream *stream,
4163 struct usb_device *dev,
4164 int pipe,
4165 unsigned interval
4166)
4167{
4168 u32 buf1;
4169 unsigned epnum, maxp;
4170 int is_input;
4171 long bandwidth;
4172 unsigned multi;
4173
4174 /*
4175 * this might be a "high bandwidth" highspeed endpoint,
4176 * as encoded in the ep descriptor's wMaxPacket field
4177 */
4178 epnum = usb_pipeendpoint(pipe);
4179 is_input = usb_pipein(pipe) ? USB_DIR_IN : 0;
4180 maxp = usb_maxpacket(dev, pipe, !is_input);
4181 if (is_input)
4182 buf1 = (1 << 11);
4183 else
4184 buf1 = 0;
4185
4186 maxp = max_packet(maxp);
4187 multi = hb_mult(maxp);
4188 buf1 |= maxp;
4189 maxp *= multi;
4190
4191 stream->buf0 = cpu_to_hc32(fotg210, (epnum << 8) | dev->devnum);
4192 stream->buf1 = cpu_to_hc32(fotg210, buf1);
4193 stream->buf2 = cpu_to_hc32(fotg210, multi);
4194
4195 /* usbfs wants to report the average usecs per frame tied up
4196 * when transfers on this endpoint are scheduled ...
4197 */
4198 if (dev->speed == USB_SPEED_FULL) {
4199 interval <<= 3;
4200 stream->usecs = NS_TO_US(usb_calc_bus_time(dev->speed,
4201 is_input, 1, maxp));
4202 stream->usecs /= 8;
4203 } else {
4204 stream->highspeed = 1;
4205 stream->usecs = HS_USECS_ISO(maxp);
4206 }
4207 bandwidth = stream->usecs * 8;
4208 bandwidth /= interval;
4209
4210 stream->bandwidth = bandwidth;
4211 stream->udev = dev;
4212 stream->bEndpointAddress = is_input | epnum;
4213 stream->interval = interval;
4214 stream->maxp = maxp;
4215}
4216
4217static struct fotg210_iso_stream *
4218iso_stream_find(struct fotg210_hcd *fotg210, struct urb *urb)
4219{
4220 unsigned epnum;
4221 struct fotg210_iso_stream *stream;
4222 struct usb_host_endpoint *ep;
4223 unsigned long flags;
4224
4225 epnum = usb_pipeendpoint(urb->pipe);
4226 if (usb_pipein(urb->pipe))
4227 ep = urb->dev->ep_in[epnum];
4228 else
4229 ep = urb->dev->ep_out[epnum];
4230
4231 spin_lock_irqsave(&fotg210->lock, flags);
4232 stream = ep->hcpriv;
4233
4234 if (unlikely(stream == NULL)) {
4235 stream = iso_stream_alloc(GFP_ATOMIC);
4236 if (likely(stream != NULL)) {
4237 ep->hcpriv = stream;
4238 stream->ep = ep;
4239 iso_stream_init(fotg210, stream, urb->dev, urb->pipe,
4240 urb->interval);
4241 }
4242
4243 /* if dev->ep[epnum] is a QH, hw is set */
4244 } else if (unlikely(stream->hw != NULL)) {
4245 fotg210_dbg(fotg210, "dev %s ep%d%s, not iso??\n",
4246 urb->dev->devpath, epnum,
4247 usb_pipein(urb->pipe) ? "in" : "out");
4248 stream = NULL;
4249 }
4250
4251 spin_unlock_irqrestore(&fotg210->lock, flags);
4252 return stream;
4253}
4254
4255/*-------------------------------------------------------------------------*/
4256
4257/* fotg210_iso_sched ops can be ITD-only or SITD-only */
4258
4259static struct fotg210_iso_sched *
4260iso_sched_alloc(unsigned packets, gfp_t mem_flags)
4261{
4262 struct fotg210_iso_sched *iso_sched;
4263 int size = sizeof(*iso_sched);
4264
4265 size += packets * sizeof(struct fotg210_iso_packet);
4266 iso_sched = kzalloc(size, mem_flags);
4267 if (likely(iso_sched != NULL))
4268 INIT_LIST_HEAD(&iso_sched->td_list);
4269
4270 return iso_sched;
4271}
4272
4273static inline void
4274itd_sched_init(
4275 struct fotg210_hcd *fotg210,
4276 struct fotg210_iso_sched *iso_sched,
4277 struct fotg210_iso_stream *stream,
4278 struct urb *urb
4279)
4280{
4281 unsigned i;
4282 dma_addr_t dma = urb->transfer_dma;
4283
4284 /* how many uframes are needed for these transfers */
4285 iso_sched->span = urb->number_of_packets * stream->interval;
4286
4287 /* figure out per-uframe itd fields that we'll need later
4288 * when we fit new itds into the schedule.
4289 */
4290 for (i = 0; i < urb->number_of_packets; i++) {
4291 struct fotg210_iso_packet *uframe = &iso_sched->packet[i];
4292 unsigned length;
4293 dma_addr_t buf;
4294 u32 trans;
4295
4296 length = urb->iso_frame_desc[i].length;
4297 buf = dma + urb->iso_frame_desc[i].offset;
4298
4299 trans = FOTG210_ISOC_ACTIVE;
4300 trans |= buf & 0x0fff;
4301 if (unlikely(((i + 1) == urb->number_of_packets))
4302 && !(urb->transfer_flags & URB_NO_INTERRUPT))
4303 trans |= FOTG210_ITD_IOC;
4304 trans |= length << 16;
4305 uframe->transaction = cpu_to_hc32(fotg210, trans);
4306
4307 /* might need to cross a buffer page within a uframe */
4308 uframe->bufp = (buf & ~(u64)0x0fff);
4309 buf += length;
4310 if (unlikely((uframe->bufp != (buf & ~(u64)0x0fff))))
4311 uframe->cross = 1;
4312 }
4313}
4314
4315static void
4316iso_sched_free(
4317 struct fotg210_iso_stream *stream,
4318 struct fotg210_iso_sched *iso_sched
4319)
4320{
4321 if (!iso_sched)
4322 return;
4323 /* caller must hold fotg210->lock!*/
4324 list_splice(&iso_sched->td_list, &stream->free_list);
4325 kfree(iso_sched);
4326}
4327
4328static int
4329itd_urb_transaction(
4330 struct fotg210_iso_stream *stream,
4331 struct fotg210_hcd *fotg210,
4332 struct urb *urb,
4333 gfp_t mem_flags
4334)
4335{
4336 struct fotg210_itd *itd;
4337 dma_addr_t itd_dma;
4338 int i;
4339 unsigned num_itds;
4340 struct fotg210_iso_sched *sched;
4341 unsigned long flags;
4342
4343 sched = iso_sched_alloc(urb->number_of_packets, mem_flags);
4344 if (unlikely(sched == NULL))
4345 return -ENOMEM;
4346
4347 itd_sched_init(fotg210, sched, stream, urb);
4348
4349 if (urb->interval < 8)
4350 num_itds = 1 + (sched->span + 7) / 8;
4351 else
4352 num_itds = urb->number_of_packets;
4353
4354 /* allocate/init ITDs */
4355 spin_lock_irqsave(&fotg210->lock, flags);
4356 for (i = 0; i < num_itds; i++) {
4357
4358 /*
4359 * Use iTDs from the free list, but not iTDs that may
4360 * still be in use by the hardware.
4361 */
4362 if (likely(!list_empty(&stream->free_list))) {
4363 itd = list_first_entry(&stream->free_list,
4364 struct fotg210_itd, itd_list);
4365 if (itd->frame == fotg210->now_frame)
4366 goto alloc_itd;
4367 list_del(&itd->itd_list);
4368 itd_dma = itd->itd_dma;
4369 } else {
4370 alloc_itd:
4371 spin_unlock_irqrestore(&fotg210->lock, flags);
4372 itd = dma_pool_alloc(fotg210->itd_pool, mem_flags,
4373 &itd_dma);
4374 spin_lock_irqsave(&fotg210->lock, flags);
4375 if (!itd) {
4376 iso_sched_free(stream, sched);
4377 spin_unlock_irqrestore(&fotg210->lock, flags);
4378 return -ENOMEM;
4379 }
4380 }
4381
4382 memset(itd, 0, sizeof(*itd));
4383 itd->itd_dma = itd_dma;
4384 list_add(&itd->itd_list, &sched->td_list);
4385 }
4386 spin_unlock_irqrestore(&fotg210->lock, flags);
4387
4388 /* temporarily store schedule info in hcpriv */
4389 urb->hcpriv = sched;
4390 urb->error_count = 0;
4391 return 0;
4392}
4393
4394/*-------------------------------------------------------------------------*/
4395
4396static inline int
4397itd_slot_ok(
4398 struct fotg210_hcd *fotg210,
4399 u32 mod,
4400 u32 uframe,
4401 u8 usecs,
4402 u32 period
4403)
4404{
4405 uframe %= period;
4406 do {
4407 /* can't commit more than uframe_periodic_max usec */
4408 if (periodic_usecs(fotg210, uframe >> 3, uframe & 0x7)
4409 > (fotg210->uframe_periodic_max - usecs))
4410 return 0;
4411
4412 /* we know urb->interval is 2^N uframes */
4413 uframe += period;
4414 } while (uframe < mod);
4415 return 1;
4416}
4417
4418/*
4419 * This scheduler plans almost as far into the future as it has actual
4420 * periodic schedule slots. (Affected by TUNE_FLS, which defaults to
4421 * "as small as possible" to be cache-friendlier.) That limits the size
4422 * transfers you can stream reliably; avoid more than 64 msec per urb.
4423 * Also avoid queue depths of less than fotg210's worst irq latency (affected
4424 * by the per-urb URB_NO_INTERRUPT hint, the log2_irq_thresh module parameter,
4425 * and other factors); or more than about 230 msec total (for portability,
4426 * given FOTG210_TUNE_FLS and the slop). Or, write a smarter scheduler!
4427 */
4428
4429#define SCHEDULE_SLOP 80 /* microframes */
4430
4431static int
4432iso_stream_schedule(
4433 struct fotg210_hcd *fotg210,
4434 struct urb *urb,
4435 struct fotg210_iso_stream *stream
4436)
4437{
4438 u32 now, next, start, period, span;
4439 int status;
4440 unsigned mod = fotg210->periodic_size << 3;
4441 struct fotg210_iso_sched *sched = urb->hcpriv;
4442
4443 period = urb->interval;
4444 span = sched->span;
4445
4446 if (span > mod - SCHEDULE_SLOP) {
4447 fotg210_dbg(fotg210, "iso request %p too long\n", urb);
4448 status = -EFBIG;
4449 goto fail;
4450 }
4451
4452 now = fotg210_read_frame_index(fotg210) & (mod - 1);
4453
4454 /* Typical case: reuse current schedule, stream is still active.
4455 * Hopefully there are no gaps from the host falling behind
4456 * (irq delays etc), but if there are we'll take the next
4457 * slot in the schedule, implicitly assuming URB_ISO_ASAP.
4458 */
4459 if (likely(!list_empty(&stream->td_list))) {
4460 u32 excess;
4461
4462 /* For high speed devices, allow scheduling within the
4463 * isochronous scheduling threshold. For full speed devices
4464 * and Intel PCI-based controllers, don't (work around for
4465 * Intel ICH9 bug).
4466 */
4467 if (!stream->highspeed && fotg210->fs_i_thresh)
4468 next = now + fotg210->i_thresh;
4469 else
4470 next = now;
4471
4472 /* Fell behind (by up to twice the slop amount)?
4473 * We decide based on the time of the last currently-scheduled
4474 * slot, not the time of the next available slot.
4475 */
4476 excess = (stream->next_uframe - period - next) & (mod - 1);
4477 if (excess >= mod - 2 * SCHEDULE_SLOP)
4478 start = next + excess - mod + period *
4479 DIV_ROUND_UP(mod - excess, period);
4480 else
4481 start = next + excess + period;
4482 if (start - now >= mod) {
4483 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n",
4484 urb, start - now - period, period,
4485 mod);
4486 status = -EFBIG;
4487 goto fail;
4488 }
4489 }
4490
4491 /* need to schedule; when's the next (u)frame we could start?
4492 * this is bigger than fotg210->i_thresh allows; scheduling itself
4493 * isn't free, the slop should handle reasonably slow cpus. it
4494 * can also help high bandwidth if the dma and irq loads don't
4495 * jump until after the queue is primed.
4496 */
4497 else {
4498 int done = 0;
4499 start = SCHEDULE_SLOP + (now & ~0x07);
4500
4501 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */
4502
4503 /* find a uframe slot with enough bandwidth.
4504 * Early uframes are more precious because full-speed
4505 * iso IN transfers can't use late uframes,
4506 * and therefore they should be allocated last.
4507 */
4508 next = start;
4509 start += period;
4510 do {
4511 start--;
4512 /* check schedule: enough space? */
4513 if (itd_slot_ok(fotg210, mod, start,
4514 stream->usecs, period))
4515 done = 1;
4516 } while (start > next && !done);
4517
4518 /* no room in the schedule */
4519 if (!done) {
4520 fotg210_dbg(fotg210, "iso resched full %p (now %d max %d)\n",
4521 urb, now, now + mod);
4522 status = -ENOSPC;
4523 goto fail;
4524 }
4525 }
4526
4527 /* Tried to schedule too far into the future? */
4528 if (unlikely(start - now + span - period
4529 >= mod - 2 * SCHEDULE_SLOP)) {
4530 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n",
4531 urb, start - now, span - period,
4532 mod - 2 * SCHEDULE_SLOP);
4533 status = -EFBIG;
4534 goto fail;
4535 }
4536
4537 stream->next_uframe = start & (mod - 1);
4538
4539 /* report high speed start in uframes; full speed, in frames */
4540 urb->start_frame = stream->next_uframe;
4541 if (!stream->highspeed)
4542 urb->start_frame >>= 3;
4543
4544 /* Make sure scan_isoc() sees these */
4545 if (fotg210->isoc_count == 0)
4546 fotg210->next_frame = now >> 3;
4547 return 0;
4548
4549 fail:
4550 iso_sched_free(stream, sched);
4551 urb->hcpriv = NULL;
4552 return status;
4553}
4554
4555/*-------------------------------------------------------------------------*/
4556
4557static inline void
4558itd_init(struct fotg210_hcd *fotg210, struct fotg210_iso_stream *stream,
4559 struct fotg210_itd *itd)
4560{
4561 int i;
4562
4563 /* it's been recently zeroed */
4564 itd->hw_next = FOTG210_LIST_END(fotg210);
4565 itd->hw_bufp[0] = stream->buf0;
4566 itd->hw_bufp[1] = stream->buf1;
4567 itd->hw_bufp[2] = stream->buf2;
4568
4569 for (i = 0; i < 8; i++)
4570 itd->index[i] = -1;
4571
4572 /* All other fields are filled when scheduling */
4573}
4574
4575static inline void
4576itd_patch(
4577 struct fotg210_hcd *fotg210,
4578 struct fotg210_itd *itd,
4579 struct fotg210_iso_sched *iso_sched,
4580 unsigned index,
4581 u16 uframe
4582)
4583{
4584 struct fotg210_iso_packet *uf = &iso_sched->packet[index];
4585 unsigned pg = itd->pg;
4586
4587 uframe &= 0x07;
4588 itd->index[uframe] = index;
4589
4590 itd->hw_transaction[uframe] = uf->transaction;
4591 itd->hw_transaction[uframe] |= cpu_to_hc32(fotg210, pg << 12);
4592 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, uf->bufp & ~(u32)0);
4593 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(uf->bufp >> 32));
4594
4595 /* iso_frame_desc[].offset must be strictly increasing */
4596 if (unlikely(uf->cross)) {
4597 u64 bufp = uf->bufp + 4096;
4598
4599 itd->pg = ++pg;
4600 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0);
4601 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(bufp >> 32));
4602 }
4603}
4604
4605static inline void
4606itd_link(struct fotg210_hcd *fotg210, unsigned frame, struct fotg210_itd *itd)
4607{
4608 union fotg210_shadow *prev = &fotg210->pshadow[frame];
4609 __hc32 *hw_p = &fotg210->periodic[frame];
4610 union fotg210_shadow here = *prev;
4611 __hc32 type = 0;
4612
4613 /* skip any iso nodes which might belong to previous microframes */
4614 while (here.ptr) {
4615 type = Q_NEXT_TYPE(fotg210, *hw_p);
4616 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH))
4617 break;
4618 prev = periodic_next_shadow(fotg210, prev, type);
4619 hw_p = shadow_next_periodic(fotg210, &here, type);
4620 here = *prev;
4621 }
4622
4623 itd->itd_next = here;
4624 itd->hw_next = *hw_p;
4625 prev->itd = itd;
4626 itd->frame = frame;
4627 wmb();
4628 *hw_p = cpu_to_hc32(fotg210, itd->itd_dma | Q_TYPE_ITD);
4629}
4630
4631/* fit urb's itds into the selected schedule slot; activate as needed */
4632static void itd_link_urb(
4633 struct fotg210_hcd *fotg210,
4634 struct urb *urb,
4635 unsigned mod,
4636 struct fotg210_iso_stream *stream
4637)
4638{
4639 int packet;
4640 unsigned next_uframe, uframe, frame;
4641 struct fotg210_iso_sched *iso_sched = urb->hcpriv;
4642 struct fotg210_itd *itd;
4643
4644 next_uframe = stream->next_uframe & (mod - 1);
4645
4646 if (unlikely(list_empty(&stream->td_list))) {
4647 fotg210_to_hcd(fotg210)->self.bandwidth_allocated
4648 += stream->bandwidth;
4649 fotg210_vdbg(fotg210,
4650 "schedule devp %s ep%d%s-iso period %d start %d.%d\n",
4651 urb->dev->devpath, stream->bEndpointAddress & 0x0f,
4652 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
4653 urb->interval,
4654 next_uframe >> 3, next_uframe & 0x7);
4655 }
4656
4657 /* fill iTDs uframe by uframe */
4658 for (packet = 0, itd = NULL; packet < urb->number_of_packets;) {
4659 if (itd == NULL) {
4660 /* ASSERT: we have all necessary itds */
4661
4662 /* ASSERT: no itds for this endpoint in this uframe */
4663
4664 itd = list_entry(iso_sched->td_list.next,
4665 struct fotg210_itd, itd_list);
4666 list_move_tail(&itd->itd_list, &stream->td_list);
4667 itd->stream = stream;
4668 itd->urb = urb;
4669 itd_init(fotg210, stream, itd);
4670 }
4671
4672 uframe = next_uframe & 0x07;
4673 frame = next_uframe >> 3;
4674
4675 itd_patch(fotg210, itd, iso_sched, packet, uframe);
4676
4677 next_uframe += stream->interval;
4678 next_uframe &= mod - 1;
4679 packet++;
4680
4681 /* link completed itds into the schedule */
4682 if (((next_uframe >> 3) != frame)
4683 || packet == urb->number_of_packets) {
4684 itd_link(fotg210, frame & (fotg210->periodic_size - 1),
4685 itd);
4686 itd = NULL;
4687 }
4688 }
4689 stream->next_uframe = next_uframe;
4690
4691 /* don't need that schedule data any more */
4692 iso_sched_free(stream, iso_sched);
4693 urb->hcpriv = NULL;
4694
4695 ++fotg210->isoc_count;
4696 enable_periodic(fotg210);
4697}
4698
4699#define ISO_ERRS (FOTG210_ISOC_BUF_ERR | FOTG210_ISOC_BABBLE |\
4700 FOTG210_ISOC_XACTERR)
4701
4702/* Process and recycle a completed ITD. Return true iff its urb completed,
4703 * and hence its completion callback probably added things to the hardware
4704 * schedule.
4705 *
4706 * Note that we carefully avoid recycling this descriptor until after any
4707 * completion callback runs, so that it won't be reused quickly. That is,
4708 * assuming (a) no more than two urbs per frame on this endpoint, and also
4709 * (b) only this endpoint's completions submit URBs. It seems some silicon
4710 * corrupts things if you reuse completed descriptors very quickly...
4711 */
4712static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
4713{
4714 struct urb *urb = itd->urb;
4715 struct usb_iso_packet_descriptor *desc;
4716 u32 t;
4717 unsigned uframe;
4718 int urb_index = -1;
4719 struct fotg210_iso_stream *stream = itd->stream;
4720 struct usb_device *dev;
4721 bool retval = false;
4722
4723 /* for each uframe with a packet */
4724 for (uframe = 0; uframe < 8; uframe++) {
4725 if (likely(itd->index[uframe] == -1))
4726 continue;
4727 urb_index = itd->index[uframe];
4728 desc = &urb->iso_frame_desc[urb_index];
4729
4730 t = hc32_to_cpup(fotg210, &itd->hw_transaction[uframe]);
4731 itd->hw_transaction[uframe] = 0;
4732
4733 /* report transfer status */
4734 if (unlikely(t & ISO_ERRS)) {
4735 urb->error_count++;
4736 if (t & FOTG210_ISOC_BUF_ERR)
4737 desc->status = usb_pipein(urb->pipe)
4738 ? -ENOSR /* hc couldn't read */
4739 : -ECOMM; /* hc couldn't write */
4740 else if (t & FOTG210_ISOC_BABBLE)
4741 desc->status = -EOVERFLOW;
4742 else /* (t & FOTG210_ISOC_XACTERR) */
4743 desc->status = -EPROTO;
4744
4745 /* HC need not update length with this error */
4746 if (!(t & FOTG210_ISOC_BABBLE)) {
4747 desc->actual_length =
4748 fotg210_itdlen(urb, desc, t);
4749 urb->actual_length += desc->actual_length;
4750 }
4751 } else if (likely((t & FOTG210_ISOC_ACTIVE) == 0)) {
4752 desc->status = 0;
4753 desc->actual_length = fotg210_itdlen(urb, desc, t);
4754 urb->actual_length += desc->actual_length;
4755 } else {
4756 /* URB was too late */
4757 desc->status = -EXDEV;
4758 }
4759 }
4760
4761 /* handle completion now? */
4762 if (likely((urb_index + 1) != urb->number_of_packets))
4763 goto done;
4764
4765 /* ASSERT: it's really the last itd for this urb
4766 list_for_each_entry (itd, &stream->td_list, itd_list)
4767 BUG_ON (itd->urb == urb);
4768 */
4769
4770 /* give urb back to the driver; completion often (re)submits */
4771 dev = urb->dev;
4772 fotg210_urb_done(fotg210, urb, 0);
4773 retval = true;
4774 urb = NULL;
4775
4776 --fotg210->isoc_count;
4777 disable_periodic(fotg210);
4778
4779 if (unlikely(list_is_singular(&stream->td_list))) {
4780 fotg210_to_hcd(fotg210)->self.bandwidth_allocated
4781 -= stream->bandwidth;
4782 fotg210_vdbg(fotg210,
4783 "deschedule devp %s ep%d%s-iso\n",
4784 dev->devpath, stream->bEndpointAddress & 0x0f,
4785 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
4786 }
4787
4788done:
4789 itd->urb = NULL;
4790
4791 /* Add to the end of the free list for later reuse */
4792 list_move_tail(&itd->itd_list, &stream->free_list);
4793
4794 /* Recycle the iTDs when the pipeline is empty (ep no longer in use) */
4795 if (list_empty(&stream->td_list)) {
4796 list_splice_tail_init(&stream->free_list,
4797 &fotg210->cached_itd_list);
4798 start_free_itds(fotg210);
4799 }
4800
4801 return retval;
4802}
4803
4804/*-------------------------------------------------------------------------*/
4805
4806static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb,
4807 gfp_t mem_flags)
4808{
4809 int status = -EINVAL;
4810 unsigned long flags;
4811 struct fotg210_iso_stream *stream;
4812
4813 /* Get iso_stream head */
4814 stream = iso_stream_find(fotg210, urb);
4815 if (unlikely(stream == NULL)) {
4816 fotg210_dbg(fotg210, "can't get iso stream\n");
4817 return -ENOMEM;
4818 }
4819 if (unlikely(urb->interval != stream->interval &&
4820 fotg210_port_speed(fotg210, 0) ==
4821 USB_PORT_STAT_HIGH_SPEED)) {
4822 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n",
4823 stream->interval, urb->interval);
4824 goto done;
4825 }
4826
4827#ifdef FOTG210_URB_TRACE
4828 fotg210_dbg(fotg210,
4829 "%s %s urb %p ep%d%s len %d, %d pkts %d uframes[%p]\n",
4830 __func__, urb->dev->devpath, urb,
4831 usb_pipeendpoint(urb->pipe),
4832 usb_pipein(urb->pipe) ? "in" : "out",
4833 urb->transfer_buffer_length,
4834 urb->number_of_packets, urb->interval,
4835 stream);
4836#endif
4837
4838 /* allocate ITDs w/o locking anything */
4839 status = itd_urb_transaction(stream, fotg210, urb, mem_flags);
4840 if (unlikely(status < 0)) {
4841 fotg210_dbg(fotg210, "can't init itds\n");
4842 goto done;
4843 }
4844
4845 /* schedule ... need to lock */
4846 spin_lock_irqsave(&fotg210->lock, flags);
4847 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) {
4848 status = -ESHUTDOWN;
4849 goto done_not_linked;
4850 }
4851 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb);
4852 if (unlikely(status))
4853 goto done_not_linked;
4854 status = iso_stream_schedule(fotg210, urb, stream);
4855 if (likely(status == 0))
4856 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream);
4857 else
4858 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
4859 done_not_linked:
4860 spin_unlock_irqrestore(&fotg210->lock, flags);
4861 done:
4862 return status;
4863}
4864
4865/*-------------------------------------------------------------------------*/
4866
4867static void scan_isoc(struct fotg210_hcd *fotg210)
4868{
4869 unsigned uf, now_frame, frame;
4870 unsigned fmask = fotg210->periodic_size - 1;
4871 bool modified, live;
4872
4873 /*
4874 * When running, scan from last scan point up to "now"
4875 * else clean up by scanning everything that's left.
4876 * Touches as few pages as possible: cache-friendly.
4877 */
4878 if (fotg210->rh_state >= FOTG210_RH_RUNNING) {
4879 uf = fotg210_read_frame_index(fotg210);
4880 now_frame = (uf >> 3) & fmask;
4881 live = true;
4882 } else {
4883 now_frame = (fotg210->next_frame - 1) & fmask;
4884 live = false;
4885 }
4886 fotg210->now_frame = now_frame;
4887
4888 frame = fotg210->next_frame;
4889 for (;;) {
4890 union fotg210_shadow q, *q_p;
4891 __hc32 type, *hw_p;
4892
4893restart:
4894 /* scan each element in frame's queue for completions */
4895 q_p = &fotg210->pshadow[frame];
4896 hw_p = &fotg210->periodic[frame];
4897 q.ptr = q_p->ptr;
4898 type = Q_NEXT_TYPE(fotg210, *hw_p);
4899 modified = false;
4900
4901 while (q.ptr != NULL) {
4902 switch (hc32_to_cpu(fotg210, type)) {
4903 case Q_TYPE_ITD:
4904 /* If this ITD is still active, leave it for
4905 * later processing ... check the next entry.
4906 * No need to check for activity unless the
4907 * frame is current.
4908 */
4909 if (frame == now_frame && live) {
4910 rmb();
4911 for (uf = 0; uf < 8; uf++) {
4912 if (q.itd->hw_transaction[uf] &
4913 ITD_ACTIVE(fotg210))
4914 break;
4915 }
4916 if (uf < 8) {
4917 q_p = &q.itd->itd_next;
4918 hw_p = &q.itd->hw_next;
4919 type = Q_NEXT_TYPE(fotg210,
4920 q.itd->hw_next);
4921 q = *q_p;
4922 break;
4923 }
4924 }
4925
4926 /* Take finished ITDs out of the schedule
4927 * and process them: recycle, maybe report
4928 * URB completion. HC won't cache the
4929 * pointer for much longer, if at all.
4930 */
4931 *q_p = q.itd->itd_next;
4932 *hw_p = q.itd->hw_next;
4933 type = Q_NEXT_TYPE(fotg210, q.itd->hw_next);
4934 wmb();
4935 modified = itd_complete(fotg210, q.itd);
4936 q = *q_p;
4937 break;
4938 default:
4939 fotg210_dbg(fotg210, "corrupt type %d frame %d shadow %p\n",
4940 type, frame, q.ptr);
4941 /* FALL THROUGH */
4942 case Q_TYPE_QH:
4943 case Q_TYPE_FSTN:
4944 /* End of the iTDs and siTDs */
4945 q.ptr = NULL;
4946 break;
4947 }
4948
4949 /* assume completion callbacks modify the queue */
4950 if (unlikely(modified && fotg210->isoc_count > 0))
4951 goto restart;
4952 }
4953
4954 /* Stop when we have reached the current frame */
4955 if (frame == now_frame)
4956 break;
4957 frame = (frame + 1) & fmask;
4958 }
4959 fotg210->next_frame = now_frame;
4960}
4961/*-------------------------------------------------------------------------*/
4962/*
4963 * Display / Set uframe_periodic_max
4964 */
4965static ssize_t show_uframe_periodic_max(struct device *dev,
4966 struct device_attribute *attr,
4967 char *buf)
4968{
4969 struct fotg210_hcd *fotg210;
4970 int n;
4971
4972 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev)));
4973 n = scnprintf(buf, PAGE_SIZE, "%d\n", fotg210->uframe_periodic_max);
4974 return n;
4975}
4976
4977
4978static ssize_t store_uframe_periodic_max(struct device *dev,
4979 struct device_attribute *attr,
4980 const char *buf, size_t count)
4981{
4982 struct fotg210_hcd *fotg210;
4983 unsigned uframe_periodic_max;
4984 unsigned frame, uframe;
4985 unsigned short allocated_max;
4986 unsigned long flags;
4987 ssize_t ret;
4988
4989 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev)));
4990 if (kstrtouint(buf, 0, &uframe_periodic_max) < 0)
4991 return -EINVAL;
4992
4993 if (uframe_periodic_max < 100 || uframe_periodic_max >= 125) {
4994 fotg210_info(fotg210, "rejecting invalid request for uframe_periodic_max=%u\n",
4995 uframe_periodic_max);
4996 return -EINVAL;
4997 }
4998
4999 ret = -EINVAL;
5000
5001 /*
5002 * lock, so that our checking does not race with possible periodic
5003 * bandwidth allocation through submitting new urbs.
5004 */
5005 spin_lock_irqsave(&fotg210->lock, flags);
5006
5007 /*
5008 * for request to decrease max periodic bandwidth, we have to check
5009 * every microframe in the schedule to see whether the decrease is
5010 * possible.
5011 */
5012 if (uframe_periodic_max < fotg210->uframe_periodic_max) {
5013 allocated_max = 0;
5014
5015 for (frame = 0; frame < fotg210->periodic_size; ++frame)
5016 for (uframe = 0; uframe < 7; ++uframe)
5017 allocated_max = max(allocated_max,
5018 periodic_usecs(fotg210, frame, uframe));
5019
5020 if (allocated_max > uframe_periodic_max) {
5021 fotg210_info(fotg210,
5022 "cannot decrease uframe_periodic_max becase "
5023 "periodic bandwidth is already allocated "
5024 "(%u > %u)\n",
5025 allocated_max, uframe_periodic_max);
5026 goto out_unlock;
5027 }
5028 }
5029
5030 /* increasing is always ok */
5031
5032 fotg210_info(fotg210, "setting max periodic bandwidth to %u%% (== %u usec/uframe)\n",
5033 100 * uframe_periodic_max/125, uframe_periodic_max);
5034
5035 if (uframe_periodic_max != 100)
5036 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n");
5037
5038 fotg210->uframe_periodic_max = uframe_periodic_max;
5039 ret = count;
5040
5041out_unlock:
5042 spin_unlock_irqrestore(&fotg210->lock, flags);
5043 return ret;
5044}
5045
5046static DEVICE_ATTR(uframe_periodic_max, 0644, show_uframe_periodic_max,
5047 store_uframe_periodic_max);
5048
5049static inline int create_sysfs_files(struct fotg210_hcd *fotg210)
5050{
5051 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
5052 int i = 0;
5053
5054 if (i)
5055 goto out;
5056
5057 i = device_create_file(controller, &dev_attr_uframe_periodic_max);
5058out:
5059 return i;
5060}
5061
5062static inline void remove_sysfs_files(struct fotg210_hcd *fotg210)
5063{
5064 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
5065
5066 device_remove_file(controller, &dev_attr_uframe_periodic_max);
5067}
5068/*-------------------------------------------------------------------------*/
5069
5070/* On some systems, leaving remote wakeup enabled prevents system shutdown.
5071 * The firmware seems to think that powering off is a wakeup event!
5072 * This routine turns off remote wakeup and everything else, on all ports.
5073 */
5074static void fotg210_turn_off_all_ports(struct fotg210_hcd *fotg210)
5075{
5076 u32 __iomem *status_reg = &fotg210->regs->port_status;
5077
5078 fotg210_writel(fotg210, PORT_RWC_BITS, status_reg);
5079}
5080
5081/*
5082 * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
5083 * Must be called with interrupts enabled and the lock not held.
5084 */
5085static void fotg210_silence_controller(struct fotg210_hcd *fotg210)
5086{
5087 fotg210_halt(fotg210);
5088
5089 spin_lock_irq(&fotg210->lock);
5090 fotg210->rh_state = FOTG210_RH_HALTED;
5091 fotg210_turn_off_all_ports(fotg210);
5092 spin_unlock_irq(&fotg210->lock);
5093}
5094
5095/* fotg210_shutdown kick in for silicon on any bus (not just pci, etc).
5096 * This forcibly disables dma and IRQs, helping kexec and other cases
5097 * where the next system software may expect clean state.
5098 */
5099static void fotg210_shutdown(struct usb_hcd *hcd)
5100{
5101 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5102
5103 spin_lock_irq(&fotg210->lock);
5104 fotg210->shutdown = true;
5105 fotg210->rh_state = FOTG210_RH_STOPPING;
5106 fotg210->enabled_hrtimer_events = 0;
5107 spin_unlock_irq(&fotg210->lock);
5108
5109 fotg210_silence_controller(fotg210);
5110
5111 hrtimer_cancel(&fotg210->hrtimer);
5112}
5113
5114/*-------------------------------------------------------------------------*/
5115
5116/*
5117 * fotg210_work is called from some interrupts, timers, and so on.
5118 * it calls driver completion functions, after dropping fotg210->lock.
5119 */
5120static void fotg210_work(struct fotg210_hcd *fotg210)
5121{
5122 /* another CPU may drop fotg210->lock during a schedule scan while
5123 * it reports urb completions. this flag guards against bogus
5124 * attempts at re-entrant schedule scanning.
5125 */
5126 if (fotg210->scanning) {
5127 fotg210->need_rescan = true;
5128 return;
5129 }
5130 fotg210->scanning = true;
5131
5132 rescan:
5133 fotg210->need_rescan = false;
5134 if (fotg210->async_count)
5135 scan_async(fotg210);
5136 if (fotg210->intr_count > 0)
5137 scan_intr(fotg210);
5138 if (fotg210->isoc_count > 0)
5139 scan_isoc(fotg210);
5140 if (fotg210->need_rescan)
5141 goto rescan;
5142 fotg210->scanning = false;
5143
5144 /* the IO watchdog guards against hardware or driver bugs that
5145 * misplace IRQs, and should let us run completely without IRQs.
5146 * such lossage has been observed on both VT6202 and VT8235.
5147 */
5148 turn_on_io_watchdog(fotg210);
5149}
5150
5151/*
5152 * Called when the fotg210_hcd module is removed.
5153 */
5154static void fotg210_stop(struct usb_hcd *hcd)
5155{
5156 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5157
5158 fotg210_dbg(fotg210, "stop\n");
5159
5160 /* no more interrupts ... */
5161
5162 spin_lock_irq(&fotg210->lock);
5163 fotg210->enabled_hrtimer_events = 0;
5164 spin_unlock_irq(&fotg210->lock);
5165
5166 fotg210_quiesce(fotg210);
5167 fotg210_silence_controller(fotg210);
5168 fotg210_reset(fotg210);
5169
5170 hrtimer_cancel(&fotg210->hrtimer);
5171 remove_sysfs_files(fotg210);
5172 remove_debug_files(fotg210);
5173
5174 /* root hub is shut down separately (first, when possible) */
5175 spin_lock_irq(&fotg210->lock);
5176 end_free_itds(fotg210);
5177 spin_unlock_irq(&fotg210->lock);
5178 fotg210_mem_cleanup(fotg210);
5179
5180#ifdef FOTG210_STATS
5181 fotg210_dbg(fotg210, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
5182 fotg210->stats.normal, fotg210->stats.error, fotg210->stats.iaa,
5183 fotg210->stats.lost_iaa);
5184 fotg210_dbg(fotg210, "complete %ld unlink %ld\n",
5185 fotg210->stats.complete, fotg210->stats.unlink);
5186#endif
5187
5188 dbg_status(fotg210, "fotg210_stop completed",
5189 fotg210_readl(fotg210, &fotg210->regs->status));
5190}
5191
5192/* one-time init, only for memory state */
5193static int hcd_fotg210_init(struct usb_hcd *hcd)
5194{
5195 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5196 u32 temp;
5197 int retval;
5198 u32 hcc_params;
5199 struct fotg210_qh_hw *hw;
5200
5201 spin_lock_init(&fotg210->lock);
5202
5203 /*
5204 * keep io watchdog by default, those good HCDs could turn off it later
5205 */
5206 fotg210->need_io_watchdog = 1;
5207
5208 hrtimer_init(&fotg210->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
5209 fotg210->hrtimer.function = fotg210_hrtimer_func;
5210 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT;
5211
5212 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
5213
5214 /*
5215 * by default set standard 80% (== 100 usec/uframe) max periodic
5216 * bandwidth as required by USB 2.0
5217 */
5218 fotg210->uframe_periodic_max = 100;
5219
5220 /*
5221 * hw default: 1K periodic list heads, one per frame.
5222 * periodic_size can shrink by USBCMD update if hcc_params allows.
5223 */
5224 fotg210->periodic_size = DEFAULT_I_TDPS;
5225 INIT_LIST_HEAD(&fotg210->intr_qh_list);
5226 INIT_LIST_HEAD(&fotg210->cached_itd_list);
5227
5228 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
5229 /* periodic schedule size can be smaller than default */
5230 switch (FOTG210_TUNE_FLS) {
5231 case 0:
5232 fotg210->periodic_size = 1024;
5233 break;
5234 case 1:
5235 fotg210->periodic_size = 512;
5236 break;
5237 case 2:
5238 fotg210->periodic_size = 256;
5239 break;
5240 default:
5241 BUG();
5242 }
5243 }
5244 retval = fotg210_mem_init(fotg210, GFP_KERNEL);
5245 if (retval < 0)
5246 return retval;
5247
5248 /* controllers may cache some of the periodic schedule ... */
5249 fotg210->i_thresh = 2;
5250
5251 /*
5252 * dedicate a qh for the async ring head, since we couldn't unlink
5253 * a 'real' qh without stopping the async schedule [4.8]. use it
5254 * as the 'reclamation list head' too.
5255 * its dummy is used in hw_alt_next of many tds, to prevent the qh
5256 * from automatically advancing to the next td after short reads.
5257 */
5258 fotg210->async->qh_next.qh = NULL;
5259 hw = fotg210->async->hw;
5260 hw->hw_next = QH_NEXT(fotg210, fotg210->async->qh_dma);
5261 hw->hw_info1 = cpu_to_hc32(fotg210, QH_HEAD);
5262 hw->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT);
5263 hw->hw_qtd_next = FOTG210_LIST_END(fotg210);
5264 fotg210->async->qh_state = QH_STATE_LINKED;
5265 hw->hw_alt_next = QTD_NEXT(fotg210, fotg210->async->dummy->qtd_dma);
5266
5267 /* clear interrupt enables, set irq latency */
5268 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
5269 log2_irq_thresh = 0;
5270 temp = 1 << (16 + log2_irq_thresh);
5271 if (HCC_CANPARK(hcc_params)) {
5272 /* HW default park == 3, on hardware that supports it (like
5273 * NVidia and ALI silicon), maximizes throughput on the async
5274 * schedule by avoiding QH fetches between transfers.
5275 *
5276 * With fast usb storage devices and NForce2, "park" seems to
5277 * make problems: throughput reduction (!), data errors...
5278 */
5279 if (park) {
5280 park = min_t(unsigned, park, 3);
5281 temp |= CMD_PARK;
5282 temp |= park << 8;
5283 }
5284 fotg210_dbg(fotg210, "park %d\n", park);
5285 }
5286 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
5287 /* periodic schedule size can be smaller than default */
5288 temp &= ~(3 << 2);
5289 temp |= (FOTG210_TUNE_FLS << 2);
5290 }
5291 fotg210->command = temp;
5292
5293 /* Accept arbitrarily long scatter-gather lists */
5294 if (!(hcd->driver->flags & HCD_LOCAL_MEM))
5295 hcd->self.sg_tablesize = ~0;
5296 return 0;
5297}
5298
5299/* start HC running; it's halted, hcd_fotg210_init() has been run (once) */
5300static int fotg210_run(struct usb_hcd *hcd)
5301{
5302 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5303 u32 temp;
5304 u32 hcc_params;
5305
5306 hcd->uses_new_polling = 1;
5307
5308 /* EHCI spec section 4.1 */
5309
5310 fotg210_writel(fotg210, fotg210->periodic_dma,
5311 &fotg210->regs->frame_list);
5312 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma,
5313 &fotg210->regs->async_next);
5314
5315 /*
5316 * hcc_params controls whether fotg210->regs->segment must (!!!)
5317 * be used; it constrains QH/ITD/SITD and QTD locations.
5318 * pci_pool consistent memory always uses segment zero.
5319 * streaming mappings for I/O buffers, like pci_map_single(),
5320 * can return segments above 4GB, if the device allows.
5321 *
5322 * NOTE: the dma mask is visible through dma_supported(), so
5323 * drivers can pass this info along ... like NETIF_F_HIGHDMA,
5324 * Scsi_Host.highmem_io, and so forth. It's readonly to all
5325 * host side drivers though.
5326 */
5327 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
5328
5329 /*
5330 * Philips, Intel, and maybe others need CMD_RUN before the
5331 * root hub will detect new devices (why?); NEC doesn't
5332 */
5333 fotg210->command &= ~(CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
5334 fotg210->command |= CMD_RUN;
5335 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
5336 dbg_cmd(fotg210, "init", fotg210->command);
5337
5338 /*
5339 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
5340 * are explicitly handed to companion controller(s), so no TT is
5341 * involved with the root hub. (Except where one is integrated,
5342 * and there's no companion controller unless maybe for USB OTG.)
5343 *
5344 * Turning on the CF flag will transfer ownership of all ports
5345 * from the companions to the EHCI controller. If any of the
5346 * companions are in the middle of a port reset at the time, it
5347 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
5348 * guarantees that no resets are in progress. After we set CF,
5349 * a short delay lets the hardware catch up; new resets shouldn't
5350 * be started before the port switching actions could complete.
5351 */
5352 down_write(&ehci_cf_port_reset_rwsem);
5353 fotg210->rh_state = FOTG210_RH_RUNNING;
5354 /* unblock posted writes */
5355 fotg210_readl(fotg210, &fotg210->regs->command);
5356 msleep(5);
5357 up_write(&ehci_cf_port_reset_rwsem);
5358 fotg210->last_periodic_enable = ktime_get_real();
5359
5360 temp = HC_VERSION(fotg210,
5361 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5362 fotg210_info(fotg210,
5363 "USB %x.%x started, EHCI %x.%02x\n",
5364 ((fotg210->sbrn & 0xf0)>>4), (fotg210->sbrn & 0x0f),
5365 temp >> 8, temp & 0xff);
5366
5367 fotg210_writel(fotg210, INTR_MASK,
5368 &fotg210->regs->intr_enable); /* Turn On Interrupts */
5369
5370 /* GRR this is run-once init(), being done every time the HC starts.
5371 * So long as they're part of class devices, we can't do it init()
5372 * since the class device isn't created that early.
5373 */
5374 create_debug_files(fotg210);
5375 create_sysfs_files(fotg210);
5376
5377 return 0;
5378}
5379
5380static int fotg210_setup(struct usb_hcd *hcd)
5381{
5382 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5383 int retval;
5384
5385 fotg210->regs = (void __iomem *)fotg210->caps +
5386 HC_LENGTH(fotg210,
5387 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5388 dbg_hcs_params(fotg210, "reset");
5389 dbg_hcc_params(fotg210, "reset");
5390
5391 /* cache this readonly data; minimize chip reads */
5392 fotg210->hcs_params = fotg210_readl(fotg210,
5393 &fotg210->caps->hcs_params);
5394
5395 fotg210->sbrn = HCD_USB2;
5396
5397 /* data structure init */
5398 retval = hcd_fotg210_init(hcd);
5399 if (retval)
5400 return retval;
5401
5402 retval = fotg210_halt(fotg210);
5403 if (retval)
5404 return retval;
5405
5406 fotg210_reset(fotg210);
5407
5408 return 0;
5409}
5410
5411/*-------------------------------------------------------------------------*/
5412
5413static irqreturn_t fotg210_irq(struct usb_hcd *hcd)
5414{
5415 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5416 u32 status, masked_status, pcd_status = 0, cmd;
5417 int bh;
5418
5419 spin_lock(&fotg210->lock);
5420
5421 status = fotg210_readl(fotg210, &fotg210->regs->status);
5422
5423 /* e.g. cardbus physical eject */
5424 if (status == ~(u32) 0) {
5425 fotg210_dbg(fotg210, "device removed\n");
5426 goto dead;
5427 }
5428
5429 /*
5430 * We don't use STS_FLR, but some controllers don't like it to
5431 * remain on, so mask it out along with the other status bits.
5432 */
5433 masked_status = status & (INTR_MASK | STS_FLR);
5434
5435 /* Shared IRQ? */
5436 if (!masked_status ||
5437 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) {
5438 spin_unlock(&fotg210->lock);
5439 return IRQ_NONE;
5440 }
5441
5442 /* clear (just) interrupts */
5443 fotg210_writel(fotg210, masked_status, &fotg210->regs->status);
5444 cmd = fotg210_readl(fotg210, &fotg210->regs->command);
5445 bh = 0;
5446
5447#ifdef VERBOSE_DEBUG
5448 /* unrequested/ignored: Frame List Rollover */
5449 dbg_status(fotg210, "irq", status);
5450#endif
5451
5452 /* INT, ERR, and IAA interrupt rates can be throttled */
5453
5454 /* normal [4.15.1.2] or error [4.15.1.1] completion */
5455 if (likely((status & (STS_INT|STS_ERR)) != 0)) {
5456 if (likely((status & STS_ERR) == 0))
5457 COUNT(fotg210->stats.normal);
5458 else
5459 COUNT(fotg210->stats.error);
5460 bh = 1;
5461 }
5462
5463 /* complete the unlinking of some qh [4.15.2.3] */
5464 if (status & STS_IAA) {
5465
5466 /* Turn off the IAA watchdog */
5467 fotg210->enabled_hrtimer_events &=
5468 ~BIT(FOTG210_HRTIMER_IAA_WATCHDOG);
5469
5470 /*
5471 * Mild optimization: Allow another IAAD to reset the
5472 * hrtimer, if one occurs before the next expiration.
5473 * In theory we could always cancel the hrtimer, but
5474 * tests show that about half the time it will be reset
5475 * for some other event anyway.
5476 */
5477 if (fotg210->next_hrtimer_event == FOTG210_HRTIMER_IAA_WATCHDOG)
5478 ++fotg210->next_hrtimer_event;
5479
5480 /* guard against (alleged) silicon errata */
5481 if (cmd & CMD_IAAD)
5482 fotg210_dbg(fotg210, "IAA with IAAD still set?\n");
5483 if (fotg210->async_iaa) {
5484 COUNT(fotg210->stats.iaa);
5485 end_unlink_async(fotg210);
5486 } else
5487 fotg210_dbg(fotg210, "IAA with nothing unlinked?\n");
5488 }
5489
5490 /* remote wakeup [4.3.1] */
5491 if (status & STS_PCD) {
5492 int pstatus;
5493 u32 __iomem *status_reg = &fotg210->regs->port_status;
5494
5495 /* kick root hub later */
5496 pcd_status = status;
5497
5498 /* resume root hub? */
5499 if (fotg210->rh_state == FOTG210_RH_SUSPENDED)
5500 usb_hcd_resume_root_hub(hcd);
5501
5502 pstatus = fotg210_readl(fotg210, status_reg);
5503
5504 if (test_bit(0, &fotg210->suspended_ports) &&
5505 ((pstatus & PORT_RESUME) ||
5506 !(pstatus & PORT_SUSPEND)) &&
5507 (pstatus & PORT_PE) &&
5508 fotg210->reset_done[0] == 0) {
5509
5510 /* start 20 msec resume signaling from this port,
5511 * and make khubd collect PORT_STAT_C_SUSPEND to
5512 * stop that signaling. Use 5 ms extra for safety,
5513 * like usb_port_resume() does.
5514 */
5515 fotg210->reset_done[0] = jiffies + msecs_to_jiffies(25);
5516 set_bit(0, &fotg210->resuming_ports);
5517 fotg210_dbg(fotg210, "port 1 remote wakeup\n");
5518 mod_timer(&hcd->rh_timer, fotg210->reset_done[0]);
5519 }
5520 }
5521
5522 /* PCI errors [4.15.2.4] */
5523 if (unlikely((status & STS_FATAL) != 0)) {
5524 fotg210_err(fotg210, "fatal error\n");
5525 dbg_cmd(fotg210, "fatal", cmd);
5526 dbg_status(fotg210, "fatal", status);
5527dead:
5528 usb_hc_died(hcd);
5529
5530 /* Don't let the controller do anything more */
5531 fotg210->shutdown = true;
5532 fotg210->rh_state = FOTG210_RH_STOPPING;
5533 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
5534 fotg210_writel(fotg210, fotg210->command,
5535 &fotg210->regs->command);
5536 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
5537 fotg210_handle_controller_death(fotg210);
5538
5539 /* Handle completions when the controller stops */
5540 bh = 0;
5541 }
5542
5543 if (bh)
5544 fotg210_work(fotg210);
5545 spin_unlock(&fotg210->lock);
5546 if (pcd_status)
5547 usb_hcd_poll_rh_status(hcd);
5548 return IRQ_HANDLED;
5549}
5550
5551/*-------------------------------------------------------------------------*/
5552
5553/*
5554 * non-error returns are a promise to giveback() the urb later
5555 * we drop ownership so next owner (or urb unlink) can get it
5556 *
5557 * urb + dev is in hcd.self.controller.urb_list
5558 * we're queueing TDs onto software and hardware lists
5559 *
5560 * hcd-specific init for hcpriv hasn't been done yet
5561 *
5562 * NOTE: control, bulk, and interrupt share the same code to append TDs
5563 * to a (possibly active) QH, and the same QH scanning code.
5564 */
5565static int fotg210_urb_enqueue(
5566 struct usb_hcd *hcd,
5567 struct urb *urb,
5568 gfp_t mem_flags
5569) {
5570 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5571 struct list_head qtd_list;
5572
5573 INIT_LIST_HEAD(&qtd_list);
5574
5575 switch (usb_pipetype(urb->pipe)) {
5576 case PIPE_CONTROL:
5577 /* qh_completions() code doesn't handle all the fault cases
5578 * in multi-TD control transfers. Even 1KB is rare anyway.
5579 */
5580 if (urb->transfer_buffer_length > (16 * 1024))
5581 return -EMSGSIZE;
5582 /* FALLTHROUGH */
5583 /* case PIPE_BULK: */
5584 default:
5585 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags))
5586 return -ENOMEM;
5587 return submit_async(fotg210, urb, &qtd_list, mem_flags);
5588
5589 case PIPE_INTERRUPT:
5590 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags))
5591 return -ENOMEM;
5592 return intr_submit(fotg210, urb, &qtd_list, mem_flags);
5593
5594 case PIPE_ISOCHRONOUS:
5595 return itd_submit(fotg210, urb, mem_flags);
5596 }
5597}
5598
5599/* remove from hardware lists
5600 * completions normally happen asynchronously
5601 */
5602
5603static int fotg210_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
5604{
5605 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5606 struct fotg210_qh *qh;
5607 unsigned long flags;
5608 int rc;
5609
5610 spin_lock_irqsave(&fotg210->lock, flags);
5611 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
5612 if (rc)
5613 goto done;
5614
5615 switch (usb_pipetype(urb->pipe)) {
5616 /* case PIPE_CONTROL: */
5617 /* case PIPE_BULK:*/
5618 default:
5619 qh = (struct fotg210_qh *) urb->hcpriv;
5620 if (!qh)
5621 break;
5622 switch (qh->qh_state) {
5623 case QH_STATE_LINKED:
5624 case QH_STATE_COMPLETING:
5625 start_unlink_async(fotg210, qh);
5626 break;
5627 case QH_STATE_UNLINK:
5628 case QH_STATE_UNLINK_WAIT:
5629 /* already started */
5630 break;
5631 case QH_STATE_IDLE:
5632 /* QH might be waiting for a Clear-TT-Buffer */
5633 qh_completions(fotg210, qh);
5634 break;
5635 }
5636 break;
5637
5638 case PIPE_INTERRUPT:
5639 qh = (struct fotg210_qh *) urb->hcpriv;
5640 if (!qh)
5641 break;
5642 switch (qh->qh_state) {
5643 case QH_STATE_LINKED:
5644 case QH_STATE_COMPLETING:
5645 start_unlink_intr(fotg210, qh);
5646 break;
5647 case QH_STATE_IDLE:
5648 qh_completions(fotg210, qh);
5649 break;
5650 default:
5651 fotg210_dbg(fotg210, "bogus qh %p state %d\n",
5652 qh, qh->qh_state);
5653 goto done;
5654 }
5655 break;
5656
5657 case PIPE_ISOCHRONOUS:
5658 /* itd... */
5659
5660 /* wait till next completion, do it then. */
5661 /* completion irqs can wait up to 1024 msec, */
5662 break;
5663 }
5664done:
5665 spin_unlock_irqrestore(&fotg210->lock, flags);
5666 return rc;
5667}
5668
5669/*-------------------------------------------------------------------------*/
5670
5671/* bulk qh holds the data toggle */
5672
5673static void
5674fotg210_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
5675{
5676 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5677 unsigned long flags;
5678 struct fotg210_qh *qh, *tmp;
5679
5680 /* ASSERT: any requests/urbs are being unlinked */
5681 /* ASSERT: nobody can be submitting urbs for this any more */
5682
5683rescan:
5684 spin_lock_irqsave(&fotg210->lock, flags);
5685 qh = ep->hcpriv;
5686 if (!qh)
5687 goto done;
5688
5689 /* endpoints can be iso streams. for now, we don't
5690 * accelerate iso completions ... so spin a while.
5691 */
5692 if (qh->hw == NULL) {
5693 struct fotg210_iso_stream *stream = ep->hcpriv;
5694
5695 if (!list_empty(&stream->td_list))
5696 goto idle_timeout;
5697
5698 /* BUG_ON(!list_empty(&stream->free_list)); */
5699 kfree(stream);
5700 goto done;
5701 }
5702
5703 if (fotg210->rh_state < FOTG210_RH_RUNNING)
5704 qh->qh_state = QH_STATE_IDLE;
5705 switch (qh->qh_state) {
5706 case QH_STATE_LINKED:
5707 case QH_STATE_COMPLETING:
5708 for (tmp = fotg210->async->qh_next.qh;
5709 tmp && tmp != qh;
5710 tmp = tmp->qh_next.qh)
5711 continue;
5712 /* periodic qh self-unlinks on empty, and a COMPLETING qh
5713 * may already be unlinked.
5714 */
5715 if (tmp)
5716 start_unlink_async(fotg210, qh);
5717 /* FALL THROUGH */
5718 case QH_STATE_UNLINK: /* wait for hw to finish? */
5719 case QH_STATE_UNLINK_WAIT:
5720idle_timeout:
5721 spin_unlock_irqrestore(&fotg210->lock, flags);
5722 schedule_timeout_uninterruptible(1);
5723 goto rescan;
5724 case QH_STATE_IDLE: /* fully unlinked */
5725 if (qh->clearing_tt)
5726 goto idle_timeout;
5727 if (list_empty(&qh->qtd_list)) {
5728 qh_destroy(fotg210, qh);
5729 break;
5730 }
5731 /* else FALL THROUGH */
5732 default:
5733 /* caller was supposed to have unlinked any requests;
5734 * that's not our job. just leak this memory.
5735 */
5736 fotg210_err(fotg210, "qh %p (#%02x) state %d%s\n",
5737 qh, ep->desc.bEndpointAddress, qh->qh_state,
5738 list_empty(&qh->qtd_list) ? "" : "(has tds)");
5739 break;
5740 }
5741 done:
5742 ep->hcpriv = NULL;
5743 spin_unlock_irqrestore(&fotg210->lock, flags);
5744}
5745
5746static void
5747fotg210_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
5748{
5749 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5750 struct fotg210_qh *qh;
5751 int eptype = usb_endpoint_type(&ep->desc);
5752 int epnum = usb_endpoint_num(&ep->desc);
5753 int is_out = usb_endpoint_dir_out(&ep->desc);
5754 unsigned long flags;
5755
5756 if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
5757 return;
5758
5759 spin_lock_irqsave(&fotg210->lock, flags);
5760 qh = ep->hcpriv;
5761
5762 /* For Bulk and Interrupt endpoints we maintain the toggle state
5763 * in the hardware; the toggle bits in udev aren't used at all.
5764 * When an endpoint is reset by usb_clear_halt() we must reset
5765 * the toggle bit in the QH.
5766 */
5767 if (qh) {
5768 usb_settoggle(qh->dev, epnum, is_out, 0);
5769 if (!list_empty(&qh->qtd_list)) {
5770 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
5771 } else if (qh->qh_state == QH_STATE_LINKED ||
5772 qh->qh_state == QH_STATE_COMPLETING) {
5773
5774 /* The toggle value in the QH can't be updated
5775 * while the QH is active. Unlink it now;
5776 * re-linking will call qh_refresh().
5777 */
5778 if (eptype == USB_ENDPOINT_XFER_BULK)
5779 start_unlink_async(fotg210, qh);
5780 else
5781 start_unlink_intr(fotg210, qh);
5782 }
5783 }
5784 spin_unlock_irqrestore(&fotg210->lock, flags);
5785}
5786
5787static int fotg210_get_frame(struct usb_hcd *hcd)
5788{
5789 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5790 return (fotg210_read_frame_index(fotg210) >> 3) %
5791 fotg210->periodic_size;
5792}
5793
5794/*-------------------------------------------------------------------------*/
5795
5796/*
5797 * The EHCI in ChipIdea HDRC cannot be a separate module or device,
5798 * because its registers (and irq) are shared between host/gadget/otg
5799 * functions and in order to facilitate role switching we cannot
5800 * give the fotg210 driver exclusive access to those.
5801 */
5802MODULE_DESCRIPTION(DRIVER_DESC);
5803MODULE_AUTHOR(DRIVER_AUTHOR);
5804MODULE_LICENSE("GPL");
5805
5806static const struct hc_driver fotg210_fotg210_hc_driver = {
5807 .description = hcd_name,
5808 .product_desc = "Faraday USB2.0 Host Controller",
5809 .hcd_priv_size = sizeof(struct fotg210_hcd),
5810
5811 /*
5812 * generic hardware linkage
5813 */
5814 .irq = fotg210_irq,
5815 .flags = HCD_MEMORY | HCD_USB2,
5816
5817 /*
5818 * basic lifecycle operations
5819 */
5820 .reset = hcd_fotg210_init,
5821 .start = fotg210_run,
5822 .stop = fotg210_stop,
5823 .shutdown = fotg210_shutdown,
5824
5825 /*
5826 * managing i/o requests and associated device resources
5827 */
5828 .urb_enqueue = fotg210_urb_enqueue,
5829 .urb_dequeue = fotg210_urb_dequeue,
5830 .endpoint_disable = fotg210_endpoint_disable,
5831 .endpoint_reset = fotg210_endpoint_reset,
5832
5833 /*
5834 * scheduling support
5835 */
5836 .get_frame_number = fotg210_get_frame,
5837
5838 /*
5839 * root hub support
5840 */
5841 .hub_status_data = fotg210_hub_status_data,
5842 .hub_control = fotg210_hub_control,
5843 .bus_suspend = fotg210_bus_suspend,
5844 .bus_resume = fotg210_bus_resume,
5845
5846 .relinquish_port = fotg210_relinquish_port,
5847 .port_handed_over = fotg210_port_handed_over,
5848
5849 .clear_tt_buffer_complete = fotg210_clear_tt_buffer_complete,
5850};
5851
5852static void fotg210_init(struct fotg210_hcd *fotg210)
5853{
5854 u32 value;
5855
5856 iowrite32(GMIR_MDEV_INT | GMIR_MOTG_INT | GMIR_INT_POLARITY,
5857 &fotg210->regs->gmir);
5858
5859 value = ioread32(&fotg210->regs->otgcsr);
5860 value &= ~OTGCSR_A_BUS_DROP;
5861 value |= OTGCSR_A_BUS_REQ;
5862 iowrite32(value, &fotg210->regs->otgcsr);
5863}
5864
5865/**
5866 * fotg210_hcd_probe - initialize faraday FOTG210 HCDs
5867 *
5868 * Allocates basic resources for this USB host controller, and
5869 * then invokes the start() method for the HCD associated with it
5870 * through the hotplug entry's driver_data.
5871 */
5872static int fotg210_hcd_probe(struct platform_device *pdev)
5873{
5874 struct device *dev = &pdev->dev;
5875 struct usb_hcd *hcd;
5876 struct resource *res;
5877 int irq;
5878 int retval = -ENODEV;
5879 struct fotg210_hcd *fotg210;
5880
5881 if (usb_disabled())
5882 return -ENODEV;
5883
5884 pdev->dev.power.power_state = PMSG_ON;
5885
5886 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
5887 if (!res) {
5888 dev_err(dev,
5889 "Found HC with no IRQ. Check %s setup!\n",
5890 dev_name(dev));
5891 return -ENODEV;
5892 }
5893
5894 irq = res->start;
5895
5896 hcd = usb_create_hcd(&fotg210_fotg210_hc_driver, dev,
5897 dev_name(dev));
5898 if (!hcd) {
5899 dev_err(dev, "failed to create hcd with err %d\n", retval);
5900 retval = -ENOMEM;
5901 goto fail_create_hcd;
5902 }
5903
5904 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5905 if (!res) {
5906 dev_err(dev,
5907 "Found HC with no register addr. Check %s setup!\n",
5908 dev_name(dev));
5909 retval = -ENODEV;
5910 goto fail_request_resource;
5911 }
5912
5913 hcd->rsrc_start = res->start;
5914 hcd->rsrc_len = resource_size(res);
5915 hcd->has_tt = 1;
5916
5917 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
5918 fotg210_fotg210_hc_driver.description)) {
5919 dev_dbg(dev, "controller already in use\n");
5920 retval = -EBUSY;
5921 goto fail_request_resource;
5922 }
5923
5924 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
5925 if (!res) {
5926 dev_err(dev,
5927 "Found HC with no register addr. Check %s setup!\n",
5928 dev_name(dev));
5929 retval = -ENODEV;
5930 goto fail_request_resource;
5931 }
5932
5933 hcd->regs = ioremap_nocache(res->start, resource_size(res));
5934 if (hcd->regs == NULL) {
5935 dev_dbg(dev, "error mapping memory\n");
5936 retval = -EFAULT;
5937 goto fail_ioremap;
5938 }
5939
5940 fotg210 = hcd_to_fotg210(hcd);
5941
5942 fotg210->caps = hcd->regs;
5943
5944 retval = fotg210_setup(hcd);
5945 if (retval)
5946 goto fail_add_hcd;
5947
5948 fotg210_init(fotg210);
5949
5950 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
5951 if (retval) {
5952 dev_err(dev, "failed to add hcd with err %d\n", retval);
5953 goto fail_add_hcd;
5954 }
5955
5956 return retval;
5957
5958fail_add_hcd:
5959 iounmap(hcd->regs);
5960fail_ioremap:
5961 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
5962fail_request_resource:
5963 usb_put_hcd(hcd);
5964fail_create_hcd:
5965 dev_err(dev, "init %s fail, %d\n", dev_name(dev), retval);
5966 return retval;
5967}
5968
5969/**
5970 * fotg210_hcd_remove - shutdown processing for EHCI HCDs
5971 * @dev: USB Host Controller being removed
5972 *
5973 */
5974static int fotg210_hcd_remove(struct platform_device *pdev)
5975{
5976 struct device *dev = &pdev->dev;
5977 struct usb_hcd *hcd = dev_get_drvdata(dev);
5978
5979 if (!hcd)
5980 return 0;
5981
5982 usb_remove_hcd(hcd);
5983 iounmap(hcd->regs);
5984 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
5985 usb_put_hcd(hcd);
5986
5987 return 0;
5988}
5989
5990static struct platform_driver fotg210_hcd_driver = {
5991 .driver = {
5992 .name = "fotg210-hcd",
5993 },
5994 .probe = fotg210_hcd_probe,
5995 .remove = fotg210_hcd_remove,
5996};
5997
5998static int __init fotg210_hcd_init(void)
5999{
6000 int retval = 0;
6001
6002 if (usb_disabled())
6003 return -ENODEV;
6004
6005 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
6006 set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
6007 if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||
6008 test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))
6009 pr_warn(KERN_WARNING "Warning! fotg210_hcd should always be loaded before uhci_hcd and ohci_hcd, not after\n");
6010
6011 pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd\n",
6012 hcd_name,
6013 sizeof(struct fotg210_qh), sizeof(struct fotg210_qtd),
6014 sizeof(struct fotg210_itd));
6015
6016#ifdef DEBUG
6017 fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root);
6018 if (!fotg210_debug_root) {
6019 retval = -ENOENT;
6020 goto err_debug;
6021 }
6022#endif
6023
6024 retval = platform_driver_register(&fotg210_hcd_driver);
6025 if (retval < 0)
6026 goto clean;
6027 return retval;
6028
6029 platform_driver_unregister(&fotg210_hcd_driver);
6030clean:
6031#ifdef DEBUG
6032 debugfs_remove(fotg210_debug_root);
6033 fotg210_debug_root = NULL;
6034err_debug:
6035#endif
6036 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
6037 return retval;
6038}
6039module_init(fotg210_hcd_init);
6040
6041static void __exit fotg210_hcd_cleanup(void)
6042{
6043 platform_driver_unregister(&fotg210_hcd_driver);
6044#ifdef DEBUG
6045 debugfs_remove(fotg210_debug_root);
6046#endif
6047 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
6048}
6049module_exit(fotg210_hcd_cleanup);
diff --git a/drivers/usb/host/fotg210.h b/drivers/usb/host/fotg210.h
new file mode 100644
index 000000000000..8920f9d32564
--- /dev/null
+++ b/drivers/usb/host/fotg210.h
@@ -0,0 +1,750 @@
1#ifndef __LINUX_FOTG210_H
2#define __LINUX_FOTG210_H
3
4/* definitions used for the EHCI driver */
5
6/*
7 * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to
8 * __leXX (normally) or __beXX (given FOTG210_BIG_ENDIAN_DESC), depending on
9 * the host controller implementation.
10 *
11 * To facilitate the strongest possible byte-order checking from "sparse"
12 * and so on, we use __leXX unless that's not practical.
13 */
14#define __hc32 __le32
15#define __hc16 __le16
16
17/* statistics can be kept for tuning/monitoring */
18struct fotg210_stats {
19 /* irq usage */
20 unsigned long normal;
21 unsigned long error;
22 unsigned long iaa;
23 unsigned long lost_iaa;
24
25 /* termination of urbs from core */
26 unsigned long complete;
27 unsigned long unlink;
28};
29
30/* fotg210_hcd->lock guards shared data against other CPUs:
31 * fotg210_hcd: async, unlink, periodic (and shadow), ...
32 * usb_host_endpoint: hcpriv
33 * fotg210_qh: qh_next, qtd_list
34 * fotg210_qtd: qtd_list
35 *
36 * Also, hold this lock when talking to HC registers or
37 * when updating hw_* fields in shared qh/qtd/... structures.
38 */
39
40#define FOTG210_MAX_ROOT_PORTS 1 /* see HCS_N_PORTS */
41
42/*
43 * fotg210_rh_state values of FOTG210_RH_RUNNING or above mean that the
44 * controller may be doing DMA. Lower values mean there's no DMA.
45 */
46enum fotg210_rh_state {
47 FOTG210_RH_HALTED,
48 FOTG210_RH_SUSPENDED,
49 FOTG210_RH_RUNNING,
50 FOTG210_RH_STOPPING
51};
52
53/*
54 * Timer events, ordered by increasing delay length.
55 * Always update event_delays_ns[] and event_handlers[] (defined in
56 * ehci-timer.c) in parallel with this list.
57 */
58enum fotg210_hrtimer_event {
59 FOTG210_HRTIMER_POLL_ASS, /* Poll for async schedule off */
60 FOTG210_HRTIMER_POLL_PSS, /* Poll for periodic schedule off */
61 FOTG210_HRTIMER_POLL_DEAD, /* Wait for dead controller to stop */
62 FOTG210_HRTIMER_UNLINK_INTR, /* Wait for interrupt QH unlink */
63 FOTG210_HRTIMER_FREE_ITDS, /* Wait for unused iTDs and siTDs */
64 FOTG210_HRTIMER_ASYNC_UNLINKS, /* Unlink empty async QHs */
65 FOTG210_HRTIMER_IAA_WATCHDOG, /* Handle lost IAA interrupts */
66 FOTG210_HRTIMER_DISABLE_PERIODIC, /* Wait to disable periodic sched */
67 FOTG210_HRTIMER_DISABLE_ASYNC, /* Wait to disable async sched */
68 FOTG210_HRTIMER_IO_WATCHDOG, /* Check for missing IRQs */
69 FOTG210_HRTIMER_NUM_EVENTS /* Must come last */
70};
71#define FOTG210_HRTIMER_NO_EVENT 99
72
73struct fotg210_hcd { /* one per controller */
74 /* timing support */
75 enum fotg210_hrtimer_event next_hrtimer_event;
76 unsigned enabled_hrtimer_events;
77 ktime_t hr_timeouts[FOTG210_HRTIMER_NUM_EVENTS];
78 struct hrtimer hrtimer;
79
80 int PSS_poll_count;
81 int ASS_poll_count;
82 int died_poll_count;
83
84 /* glue to PCI and HCD framework */
85 struct fotg210_caps __iomem *caps;
86 struct fotg210_regs __iomem *regs;
87 struct fotg210_dbg_port __iomem *debug;
88
89 __u32 hcs_params; /* cached register copy */
90 spinlock_t lock;
91 enum fotg210_rh_state rh_state;
92
93 /* general schedule support */
94 bool scanning:1;
95 bool need_rescan:1;
96 bool intr_unlinking:1;
97 bool async_unlinking:1;
98 bool shutdown:1;
99 struct fotg210_qh *qh_scan_next;
100
101 /* async schedule support */
102 struct fotg210_qh *async;
103 struct fotg210_qh *dummy; /* For AMD quirk use */
104 struct fotg210_qh *async_unlink;
105 struct fotg210_qh *async_unlink_last;
106 struct fotg210_qh *async_iaa;
107 unsigned async_unlink_cycle;
108 unsigned async_count; /* async activity count */
109
110 /* periodic schedule support */
111#define DEFAULT_I_TDPS 1024 /* some HCs can do less */
112 unsigned periodic_size;
113 __hc32 *periodic; /* hw periodic table */
114 dma_addr_t periodic_dma;
115 struct list_head intr_qh_list;
116 unsigned i_thresh; /* uframes HC might cache */
117
118 union fotg210_shadow *pshadow; /* mirror hw periodic table */
119 struct fotg210_qh *intr_unlink;
120 struct fotg210_qh *intr_unlink_last;
121 unsigned intr_unlink_cycle;
122 unsigned now_frame; /* frame from HC hardware */
123 unsigned next_frame; /* scan periodic, start here */
124 unsigned intr_count; /* intr activity count */
125 unsigned isoc_count; /* isoc activity count */
126 unsigned periodic_count; /* periodic activity count */
127 /* max periodic time per uframe */
128 unsigned uframe_periodic_max;
129
130
131 /* list of itds completed while now_frame was still active */
132 struct list_head cached_itd_list;
133 struct fotg210_itd *last_itd_to_free;
134
135 /* per root hub port */
136 unsigned long reset_done[FOTG210_MAX_ROOT_PORTS];
137
138 /* bit vectors (one bit per port) */
139 unsigned long bus_suspended; /* which ports were
140 already suspended at the start of a bus suspend */
141 unsigned long companion_ports; /* which ports are
142 dedicated to the companion controller */
143 unsigned long owned_ports; /* which ports are
144 owned by the companion during a bus suspend */
145 unsigned long port_c_suspend; /* which ports have
146 the change-suspend feature turned on */
147 unsigned long suspended_ports; /* which ports are
148 suspended */
149 unsigned long resuming_ports; /* which ports have
150 started to resume */
151
152 /* per-HC memory pools (could be per-bus, but ...) */
153 struct dma_pool *qh_pool; /* qh per active urb */
154 struct dma_pool *qtd_pool; /* one or more per qh */
155 struct dma_pool *itd_pool; /* itd per iso urb */
156
157 unsigned random_frame;
158 unsigned long next_statechange;
159 ktime_t last_periodic_enable;
160 u32 command;
161
162 /* SILICON QUIRKS */
163 unsigned need_io_watchdog:1;
164 unsigned fs_i_thresh:1; /* Intel iso scheduling */
165
166 u8 sbrn; /* packed release number */
167
168 /* irq statistics */
169#ifdef FOTG210_STATS
170 struct fotg210_stats stats;
171# define COUNT(x) ((x)++)
172#else
173# define COUNT(x)
174#endif
175
176 /* debug files */
177#ifdef DEBUG
178 struct dentry *debug_dir;
179#endif
180};
181
182/* convert between an HCD pointer and the corresponding FOTG210_HCD */
183static inline struct fotg210_hcd *hcd_to_fotg210(struct usb_hcd *hcd)
184{
185 return (struct fotg210_hcd *)(hcd->hcd_priv);
186}
187static inline struct usb_hcd *fotg210_to_hcd(struct fotg210_hcd *fotg210)
188{
189 return container_of((void *) fotg210, struct usb_hcd, hcd_priv);
190}
191
192/*-------------------------------------------------------------------------*/
193
194/* EHCI register interface, corresponds to EHCI Revision 0.95 specification */
195
196/* Section 2.2 Host Controller Capability Registers */
197struct fotg210_caps {
198 /* these fields are specified as 8 and 16 bit registers,
199 * but some hosts can't perform 8 or 16 bit PCI accesses.
200 * some hosts treat caplength and hciversion as parts of a 32-bit
201 * register, others treat them as two separate registers, this
202 * affects the memory map for big endian controllers.
203 */
204 u32 hc_capbase;
205#define HC_LENGTH(fotg210, p) (0x00ff&((p) >> /* bits 7:0 / offset 00h */ \
206 (fotg210_big_endian_capbase(fotg210) ? 24 : 0)))
207#define HC_VERSION(fotg210, p) (0xffff&((p) >> /* bits 31:16 / offset 02h */ \
208 (fotg210_big_endian_capbase(fotg210) ? 0 : 16)))
209 u32 hcs_params; /* HCSPARAMS - offset 0x4 */
210#define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */
211
212 u32 hcc_params; /* HCCPARAMS - offset 0x8 */
213#define HCC_CANPARK(p) ((p)&(1 << 2)) /* true: can park on async qh */
214#define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1)) /* true: periodic_size changes*/
215 u8 portroute[8]; /* nibbles for routing - offset 0xC */
216};
217
218
219/* Section 2.3 Host Controller Operational Registers */
220struct fotg210_regs {
221
222 /* USBCMD: offset 0x00 */
223 u32 command;
224
225/* EHCI 1.1 addendum */
226/* 23:16 is r/w intr rate, in microframes; default "8" == 1/msec */
227#define CMD_PARK (1<<11) /* enable "park" on async qh */
228#define CMD_PARK_CNT(c) (((c)>>8)&3) /* how many transfers to park for */
229#define CMD_IAAD (1<<6) /* "doorbell" interrupt async advance */
230#define CMD_ASE (1<<5) /* async schedule enable */
231#define CMD_PSE (1<<4) /* periodic schedule enable */
232/* 3:2 is periodic frame list size */
233#define CMD_RESET (1<<1) /* reset HC not bus */
234#define CMD_RUN (1<<0) /* start/stop HC */
235
236 /* USBSTS: offset 0x04 */
237 u32 status;
238#define STS_ASS (1<<15) /* Async Schedule Status */
239#define STS_PSS (1<<14) /* Periodic Schedule Status */
240#define STS_RECL (1<<13) /* Reclamation */
241#define STS_HALT (1<<12) /* Not running (any reason) */
242/* some bits reserved */
243 /* these STS_* flags are also intr_enable bits (USBINTR) */
244#define STS_IAA (1<<5) /* Interrupted on async advance */
245#define STS_FATAL (1<<4) /* such as some PCI access errors */
246#define STS_FLR (1<<3) /* frame list rolled over */
247#define STS_PCD (1<<2) /* port change detect */
248#define STS_ERR (1<<1) /* "error" completion (overflow, ...) */
249#define STS_INT (1<<0) /* "normal" completion (short, ...) */
250
251 /* USBINTR: offset 0x08 */
252 u32 intr_enable;
253
254 /* FRINDEX: offset 0x0C */
255 u32 frame_index; /* current microframe number */
256 /* CTRLDSSEGMENT: offset 0x10 */
257 u32 segment; /* address bits 63:32 if needed */
258 /* PERIODICLISTBASE: offset 0x14 */
259 u32 frame_list; /* points to periodic list */
260 /* ASYNCLISTADDR: offset 0x18 */
261 u32 async_next; /* address of next async queue head */
262
263 u32 reserved1;
264 /* PORTSC: offset 0x20 */
265 u32 port_status;
266/* 31:23 reserved */
267#define PORT_USB11(x) (((x)&(3<<10)) == (1<<10)) /* USB 1.1 device */
268#define PORT_RESET (1<<8) /* reset port */
269#define PORT_SUSPEND (1<<7) /* suspend port */
270#define PORT_RESUME (1<<6) /* resume it */
271#define PORT_PEC (1<<3) /* port enable change */
272#define PORT_PE (1<<2) /* port enable */
273#define PORT_CSC (1<<1) /* connect status change */
274#define PORT_CONNECT (1<<0) /* device connected */
275#define PORT_RWC_BITS (PORT_CSC | PORT_PEC)
276 u32 reserved2[19];
277
278 /* OTGCSR: offet 0x70 */
279 u32 otgcsr;
280#define OTGCSR_HOST_SPD_TYP (3 << 22)
281#define OTGCSR_A_BUS_DROP (1 << 5)
282#define OTGCSR_A_BUS_REQ (1 << 4)
283
284 /* OTGISR: offset 0x74 */
285 u32 otgisr;
286#define OTGISR_OVC (1 << 10)
287
288 u32 reserved3[15];
289
290 /* GMIR: offset 0xB4 */
291 u32 gmir;
292#define GMIR_INT_POLARITY (1 << 3) /*Active High*/
293#define GMIR_MHC_INT (1 << 2)
294#define GMIR_MOTG_INT (1 << 1)
295#define GMIR_MDEV_INT (1 << 0)
296};
297
298/* Appendix C, Debug port ... intended for use with special "debug devices"
299 * that can help if there's no serial console. (nonstandard enumeration.)
300 */
301struct fotg210_dbg_port {
302 u32 control;
303#define DBGP_OWNER (1<<30)
304#define DBGP_ENABLED (1<<28)
305#define DBGP_DONE (1<<16)
306#define DBGP_INUSE (1<<10)
307#define DBGP_ERRCODE(x) (((x)>>7)&0x07)
308# define DBGP_ERR_BAD 1
309# define DBGP_ERR_SIGNAL 2
310#define DBGP_ERROR (1<<6)
311#define DBGP_GO (1<<5)
312#define DBGP_OUT (1<<4)
313#define DBGP_LEN(x) (((x)>>0)&0x0f)
314 u32 pids;
315#define DBGP_PID_GET(x) (((x)>>16)&0xff)
316#define DBGP_PID_SET(data, tok) (((data)<<8)|(tok))
317 u32 data03;
318 u32 data47;
319 u32 address;
320#define DBGP_EPADDR(dev, ep) (((dev)<<8)|(ep))
321};
322
323#ifdef CONFIG_EARLY_PRINTK_DBGP
324#include <linux/init.h>
325extern int __init early_dbgp_init(char *s);
326extern struct console early_dbgp_console;
327#endif /* CONFIG_EARLY_PRINTK_DBGP */
328
329struct usb_hcd;
330
331static inline int xen_dbgp_reset_prep(struct usb_hcd *hcd)
332{
333 return 1; /* Shouldn't this be 0? */
334}
335
336static inline int xen_dbgp_external_startup(struct usb_hcd *hcd)
337{
338 return -1;
339}
340
341#ifdef CONFIG_EARLY_PRINTK_DBGP
342/* Call backs from fotg210 host driver to fotg210 debug driver */
343extern int dbgp_external_startup(struct usb_hcd *);
344extern int dbgp_reset_prep(struct usb_hcd *hcd);
345#else
346static inline int dbgp_reset_prep(struct usb_hcd *hcd)
347{
348 return xen_dbgp_reset_prep(hcd);
349}
350static inline int dbgp_external_startup(struct usb_hcd *hcd)
351{
352 return xen_dbgp_external_startup(hcd);
353}
354#endif
355
356/*-------------------------------------------------------------------------*/
357
358#define QTD_NEXT(fotg210, dma) cpu_to_hc32(fotg210, (u32)dma)
359
360/*
361 * EHCI Specification 0.95 Section 3.5
362 * QTD: describe data transfer components (buffer, direction, ...)
363 * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
364 *
365 * These are associated only with "QH" (Queue Head) structures,
366 * used with control, bulk, and interrupt transfers.
367 */
368struct fotg210_qtd {
369 /* first part defined by EHCI spec */
370 __hc32 hw_next; /* see EHCI 3.5.1 */
371 __hc32 hw_alt_next; /* see EHCI 3.5.2 */
372 __hc32 hw_token; /* see EHCI 3.5.3 */
373#define QTD_TOGGLE (1 << 31) /* data toggle */
374#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
375#define QTD_IOC (1 << 15) /* interrupt on complete */
376#define QTD_CERR(tok) (((tok)>>10) & 0x3)
377#define QTD_PID(tok) (((tok)>>8) & 0x3)
378#define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */
379#define QTD_STS_HALT (1 << 6) /* halted on error */
380#define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */
381#define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */
382#define QTD_STS_XACT (1 << 3) /* device gave illegal response */
383#define QTD_STS_MMF (1 << 2) /* incomplete split transaction */
384#define QTD_STS_STS (1 << 1) /* split transaction state */
385#define QTD_STS_PING (1 << 0) /* issue PING? */
386
387#define ACTIVE_BIT(fotg210) cpu_to_hc32(fotg210, QTD_STS_ACTIVE)
388#define HALT_BIT(fotg210) cpu_to_hc32(fotg210, QTD_STS_HALT)
389#define STATUS_BIT(fotg210) cpu_to_hc32(fotg210, QTD_STS_STS)
390
391 __hc32 hw_buf[5]; /* see EHCI 3.5.4 */
392 __hc32 hw_buf_hi[5]; /* Appendix B */
393
394 /* the rest is HCD-private */
395 dma_addr_t qtd_dma; /* qtd address */
396 struct list_head qtd_list; /* sw qtd list */
397 struct urb *urb; /* qtd's urb */
398 size_t length; /* length of buffer */
399} __aligned(32);
400
401/* mask NakCnt+T in qh->hw_alt_next */
402#define QTD_MASK(fotg210) cpu_to_hc32(fotg210, ~0x1f)
403
404#define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1)
405
406/*-------------------------------------------------------------------------*/
407
408/* type tag from {qh,itd,fstn}->hw_next */
409#define Q_NEXT_TYPE(fotg210, dma) ((dma) & cpu_to_hc32(fotg210, 3 << 1))
410
411/*
412 * Now the following defines are not converted using the
413 * cpu_to_le32() macro anymore, since we have to support
414 * "dynamic" switching between be and le support, so that the driver
415 * can be used on one system with SoC EHCI controller using big-endian
416 * descriptors as well as a normal little-endian PCI EHCI controller.
417 */
418/* values for that type tag */
419#define Q_TYPE_ITD (0 << 1)
420#define Q_TYPE_QH (1 << 1)
421#define Q_TYPE_SITD (2 << 1)
422#define Q_TYPE_FSTN (3 << 1)
423
424/* next async queue entry, or pointer to interrupt/periodic QH */
425#define QH_NEXT(fotg210, dma) \
426 (cpu_to_hc32(fotg210, (((u32)dma)&~0x01f)|Q_TYPE_QH))
427
428/* for periodic/async schedules and qtd lists, mark end of list */
429#define FOTG210_LIST_END(fotg210) \
430 cpu_to_hc32(fotg210, 1) /* "null pointer" to hw */
431
432/*
433 * Entries in periodic shadow table are pointers to one of four kinds
434 * of data structure. That's dictated by the hardware; a type tag is
435 * encoded in the low bits of the hardware's periodic schedule. Use
436 * Q_NEXT_TYPE to get the tag.
437 *
438 * For entries in the async schedule, the type tag always says "qh".
439 */
440union fotg210_shadow {
441 struct fotg210_qh *qh; /* Q_TYPE_QH */
442 struct fotg210_itd *itd; /* Q_TYPE_ITD */
443 struct fotg210_fstn *fstn; /* Q_TYPE_FSTN */
444 __hc32 *hw_next; /* (all types) */
445 void *ptr;
446};
447
448/*-------------------------------------------------------------------------*/
449
450/*
451 * EHCI Specification 0.95 Section 3.6
452 * QH: describes control/bulk/interrupt endpoints
453 * See Fig 3-7 "Queue Head Structure Layout".
454 *
455 * These appear in both the async and (for interrupt) periodic schedules.
456 */
457
458/* first part defined by EHCI spec */
459struct fotg210_qh_hw {
460 __hc32 hw_next; /* see EHCI 3.6.1 */
461 __hc32 hw_info1; /* see EHCI 3.6.2 */
462#define QH_CONTROL_EP (1 << 27) /* FS/LS control endpoint */
463#define QH_HEAD (1 << 15) /* Head of async reclamation list */
464#define QH_TOGGLE_CTL (1 << 14) /* Data toggle control */
465#define QH_HIGH_SPEED (2 << 12) /* Endpoint speed */
466#define QH_LOW_SPEED (1 << 12)
467#define QH_FULL_SPEED (0 << 12)
468#define QH_INACTIVATE (1 << 7) /* Inactivate on next transaction */
469 __hc32 hw_info2; /* see EHCI 3.6.2 */
470#define QH_SMASK 0x000000ff
471#define QH_CMASK 0x0000ff00
472#define QH_HUBADDR 0x007f0000
473#define QH_HUBPORT 0x3f800000
474#define QH_MULT 0xc0000000
475 __hc32 hw_current; /* qtd list - see EHCI 3.6.4 */
476
477 /* qtd overlay (hardware parts of a struct fotg210_qtd) */
478 __hc32 hw_qtd_next;
479 __hc32 hw_alt_next;
480 __hc32 hw_token;
481 __hc32 hw_buf[5];
482 __hc32 hw_buf_hi[5];
483} __aligned(32);
484
485struct fotg210_qh {
486 struct fotg210_qh_hw *hw; /* Must come first */
487 /* the rest is HCD-private */
488 dma_addr_t qh_dma; /* address of qh */
489 union fotg210_shadow qh_next; /* ptr to qh; or periodic */
490 struct list_head qtd_list; /* sw qtd list */
491 struct list_head intr_node; /* list of intr QHs */
492 struct fotg210_qtd *dummy;
493 struct fotg210_qh *unlink_next; /* next on unlink list */
494
495 unsigned unlink_cycle;
496
497 u8 needs_rescan; /* Dequeue during giveback */
498 u8 qh_state;
499#define QH_STATE_LINKED 1 /* HC sees this */
500#define QH_STATE_UNLINK 2 /* HC may still see this */
501#define QH_STATE_IDLE 3 /* HC doesn't see this */
502#define QH_STATE_UNLINK_WAIT 4 /* LINKED and on unlink q */
503#define QH_STATE_COMPLETING 5 /* don't touch token.HALT */
504
505 u8 xacterrs; /* XactErr retry counter */
506#define QH_XACTERR_MAX 32 /* XactErr retry limit */
507
508 /* periodic schedule info */
509 u8 usecs; /* intr bandwidth */
510 u8 gap_uf; /* uframes split/csplit gap */
511 u8 c_usecs; /* ... split completion bw */
512 u16 tt_usecs; /* tt downstream bandwidth */
513 unsigned short period; /* polling interval */
514 unsigned short start; /* where polling starts */
515#define NO_FRAME ((unsigned short)~0) /* pick new start */
516
517 struct usb_device *dev; /* access to TT */
518 unsigned is_out:1; /* bulk or intr OUT */
519 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
520};
521
522/*-------------------------------------------------------------------------*/
523
524/* description of one iso transaction (up to 3 KB data if highspeed) */
525struct fotg210_iso_packet {
526 /* These will be copied to iTD when scheduling */
527 u64 bufp; /* itd->hw_bufp{,_hi}[pg] |= */
528 __hc32 transaction; /* itd->hw_transaction[i] |= */
529 u8 cross; /* buf crosses pages */
530 /* for full speed OUT splits */
531 u32 buf1;
532};
533
534/* temporary schedule data for packets from iso urbs (both speeds)
535 * each packet is one logical usb transaction to the device (not TT),
536 * beginning at stream->next_uframe
537 */
538struct fotg210_iso_sched {
539 struct list_head td_list;
540 unsigned span;
541 struct fotg210_iso_packet packet[0];
542};
543
544/*
545 * fotg210_iso_stream - groups all (s)itds for this endpoint.
546 * acts like a qh would, if EHCI had them for ISO.
547 */
548struct fotg210_iso_stream {
549 /* first field matches fotg210_hq, but is NULL */
550 struct fotg210_qh_hw *hw;
551
552 u8 bEndpointAddress;
553 u8 highspeed;
554 struct list_head td_list; /* queued itds */
555 struct list_head free_list; /* list of unused itds */
556 struct usb_device *udev;
557 struct usb_host_endpoint *ep;
558
559 /* output of (re)scheduling */
560 int next_uframe;
561 __hc32 splits;
562
563 /* the rest is derived from the endpoint descriptor,
564 * trusting urb->interval == f(epdesc->bInterval) and
565 * including the extra info for hw_bufp[0..2]
566 */
567 u8 usecs, c_usecs;
568 u16 interval;
569 u16 tt_usecs;
570 u16 maxp;
571 u16 raw_mask;
572 unsigned bandwidth;
573
574 /* This is used to initialize iTD's hw_bufp fields */
575 __hc32 buf0;
576 __hc32 buf1;
577 __hc32 buf2;
578
579 /* this is used to initialize sITD's tt info */
580 __hc32 address;
581};
582
583/*-------------------------------------------------------------------------*/
584
585/*
586 * EHCI Specification 0.95 Section 3.3
587 * Fig 3-4 "Isochronous Transaction Descriptor (iTD)"
588 *
589 * Schedule records for high speed iso xfers
590 */
591struct fotg210_itd {
592 /* first part defined by EHCI spec */
593 __hc32 hw_next; /* see EHCI 3.3.1 */
594 __hc32 hw_transaction[8]; /* see EHCI 3.3.2 */
595#define FOTG210_ISOC_ACTIVE (1<<31) /* activate transfer this slot */
596#define FOTG210_ISOC_BUF_ERR (1<<30) /* Data buffer error */
597#define FOTG210_ISOC_BABBLE (1<<29) /* babble detected */
598#define FOTG210_ISOC_XACTERR (1<<28) /* XactErr - transaction error */
599#define FOTG210_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff)
600#define FOTG210_ITD_IOC (1 << 15) /* interrupt on complete */
601
602#define ITD_ACTIVE(fotg210) cpu_to_hc32(fotg210, FOTG210_ISOC_ACTIVE)
603
604 __hc32 hw_bufp[7]; /* see EHCI 3.3.3 */
605 __hc32 hw_bufp_hi[7]; /* Appendix B */
606
607 /* the rest is HCD-private */
608 dma_addr_t itd_dma; /* for this itd */
609 union fotg210_shadow itd_next; /* ptr to periodic q entry */
610
611 struct urb *urb;
612 struct fotg210_iso_stream *stream; /* endpoint's queue */
613 struct list_head itd_list; /* list of stream's itds */
614
615 /* any/all hw_transactions here may be used by that urb */
616 unsigned frame; /* where scheduled */
617 unsigned pg;
618 unsigned index[8]; /* in urb->iso_frame_desc */
619} __aligned(32);
620
621/*-------------------------------------------------------------------------*/
622
623/*
624 * EHCI Specification 0.96 Section 3.7
625 * Periodic Frame Span Traversal Node (FSTN)
626 *
627 * Manages split interrupt transactions (using TT) that span frame boundaries
628 * into uframes 0/1; see 4.12.2.2. In those uframes, a "save place" FSTN
629 * makes the HC jump (back) to a QH to scan for fs/ls QH completions until
630 * it hits a "restore" FSTN; then it returns to finish other uframe 0/1 work.
631 */
632struct fotg210_fstn {
633 __hc32 hw_next; /* any periodic q entry */
634 __hc32 hw_prev; /* qh or FOTG210_LIST_END */
635
636 /* the rest is HCD-private */
637 dma_addr_t fstn_dma;
638 union fotg210_shadow fstn_next; /* ptr to periodic q entry */
639} __aligned(32);
640
641/*-------------------------------------------------------------------------*/
642
643/* Prepare the PORTSC wakeup flags during controller suspend/resume */
644
645#define fotg210_prepare_ports_for_controller_suspend(fotg210, do_wakeup) \
646 fotg210_adjust_port_wakeup_flags(fotg210, true, do_wakeup);
647
648#define fotg210_prepare_ports_for_controller_resume(fotg210) \
649 fotg210_adjust_port_wakeup_flags(fotg210, false, false);
650
651/*-------------------------------------------------------------------------*/
652
653/*
654 * Some EHCI controllers have a Transaction Translator built into the
655 * root hub. This is a non-standard feature. Each controller will need
656 * to add code to the following inline functions, and call them as
657 * needed (mostly in root hub code).
658 */
659
660static inline unsigned int
661fotg210_get_speed(struct fotg210_hcd *fotg210, unsigned int portsc)
662{
663 return (readl(&fotg210->regs->otgcsr)
664 & OTGCSR_HOST_SPD_TYP) >> 22;
665}
666
667/* Returns the speed of a device attached to a port on the root hub. */
668static inline unsigned int
669fotg210_port_speed(struct fotg210_hcd *fotg210, unsigned int portsc)
670{
671 switch (fotg210_get_speed(fotg210, portsc)) {
672 case 0:
673 return 0;
674 case 1:
675 return USB_PORT_STAT_LOW_SPEED;
676 case 2:
677 default:
678 return USB_PORT_STAT_HIGH_SPEED;
679 }
680}
681
682/*-------------------------------------------------------------------------*/
683
684#define fotg210_has_fsl_portno_bug(e) (0)
685
686/*
687 * While most USB host controllers implement their registers in
688 * little-endian format, a minority (celleb companion chip) implement
689 * them in big endian format.
690 *
691 * This attempts to support either format at compile time without a
692 * runtime penalty, or both formats with the additional overhead
693 * of checking a flag bit.
694 *
695 */
696
697#define fotg210_big_endian_mmio(e) 0
698#define fotg210_big_endian_capbase(e) 0
699
700static inline unsigned int fotg210_readl(const struct fotg210_hcd *fotg210,
701 __u32 __iomem *regs)
702{
703 return readl(regs);
704}
705
706static inline void fotg210_writel(const struct fotg210_hcd *fotg210,
707 const unsigned int val, __u32 __iomem *regs)
708{
709 writel(val, regs);
710}
711
712/* cpu to fotg210 */
713static inline __hc32 cpu_to_hc32(const struct fotg210_hcd *fotg210, const u32 x)
714{
715 return cpu_to_le32(x);
716}
717
718/* fotg210 to cpu */
719static inline u32 hc32_to_cpu(const struct fotg210_hcd *fotg210, const __hc32 x)
720{
721 return le32_to_cpu(x);
722}
723
724static inline u32 hc32_to_cpup(const struct fotg210_hcd *fotg210,
725 const __hc32 *x)
726{
727 return le32_to_cpup(x);
728}
729
730/*-------------------------------------------------------------------------*/
731
732static inline unsigned fotg210_read_frame_index(struct fotg210_hcd *fotg210)
733{
734 return fotg210_readl(fotg210, &fotg210->regs->frame_index);
735}
736
737#define fotg210_itdlen(urb, desc, t) ({ \
738 usb_pipein((urb)->pipe) ? \
739 (desc)->length - FOTG210_ITD_LENGTH(t) : \
740 FOTG210_ITD_LENGTH(t); \
741})
742/*-------------------------------------------------------------------------*/
743
744#ifndef DEBUG
745#define STUB_DEBUG_FILES
746#endif /* DEBUG */
747
748/*-------------------------------------------------------------------------*/
749
750#endif /* __LINUX_FOTG210_H */
diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
index 11e0b79ff9d5..cfbff7161828 100644
--- a/drivers/usb/host/fsl-mph-dr-of.c
+++ b/drivers/usb/host/fsl-mph-dr-of.c
@@ -258,7 +258,7 @@ static int fsl_usb2_mph_dr_of_remove(struct platform_device *ofdev)
258 258
259int fsl_usb2_mpc5121_init(struct platform_device *pdev) 259int fsl_usb2_mpc5121_init(struct platform_device *pdev)
260{ 260{
261 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 261 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
262 struct clk *clk; 262 struct clk *clk;
263 char clk_name[10]; 263 char clk_name[10];
264 int base, clk_num; 264 int base, clk_num;
@@ -298,7 +298,7 @@ int fsl_usb2_mpc5121_init(struct platform_device *pdev)
298 298
299static void fsl_usb2_mpc5121_exit(struct platform_device *pdev) 299static void fsl_usb2_mpc5121_exit(struct platform_device *pdev)
300{ 300{
301 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 301 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
302 302
303 pdata->regs = NULL; 303 pdata->regs = NULL;
304 304
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index 483990c716aa..5b86ffb88f1c 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -161,6 +161,13 @@ static int hwahc_op_start(struct usb_hcd *usb_hcd)
161 usb_hcd->uses_new_polling = 1; 161 usb_hcd->uses_new_polling = 1;
162 set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags); 162 set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags);
163 usb_hcd->state = HC_STATE_RUNNING; 163 usb_hcd->state = HC_STATE_RUNNING;
164
165 /*
166 * prevent USB core from suspending the root hub since
167 * bus_suspend and bus_resume are not yet supported.
168 */
169 pm_runtime_get_noresume(&usb_hcd->self.root_hub->dev);
170
164 result = 0; 171 result = 0;
165out: 172out:
166 mutex_unlock(&wusbhc->mutex); 173 mutex_unlock(&wusbhc->mutex);
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index 03dc4d9cbeca..60a5de505ca1 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -1860,7 +1860,7 @@ static int imx21_probe(struct platform_device *pdev)
1860 imx21 = hcd_to_imx21(hcd); 1860 imx21 = hcd_to_imx21(hcd);
1861 imx21->hcd = hcd; 1861 imx21->hcd = hcd;
1862 imx21->dev = &pdev->dev; 1862 imx21->dev = &pdev->dev;
1863 imx21->pdata = pdev->dev.platform_data; 1863 imx21->pdata = dev_get_platdata(&pdev->dev);
1864 if (!imx21->pdata) 1864 if (!imx21->pdata)
1865 imx21->pdata = &default_pdata; 1865 imx21->pdata = &default_pdata;
1866 1866
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index b64e661618bb..c7d0f8f231be 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -1626,7 +1626,7 @@ static int isp116x_probe(struct platform_device *pdev)
1626 isp116x->addr_reg = addr_reg; 1626 isp116x->addr_reg = addr_reg;
1627 spin_lock_init(&isp116x->lock); 1627 spin_lock_init(&isp116x->lock);
1628 INIT_LIST_HEAD(&isp116x->async); 1628 INIT_LIST_HEAD(&isp116x->async);
1629 isp116x->board = pdev->dev.platform_data; 1629 isp116x->board = dev_get_platdata(&pdev->dev);
1630 1630
1631 if (!isp116x->board) { 1631 if (!isp116x->board) {
1632 ERR("Platform data structure not initialized\n"); 1632 ERR("Platform data structure not initialized\n");
diff --git a/drivers/usb/host/isp116x.h b/drivers/usb/host/isp116x.h
index 9a2c400e6090..dd34b7a33965 100644
--- a/drivers/usb/host/isp116x.h
+++ b/drivers/usb/host/isp116x.h
@@ -325,11 +325,7 @@ struct isp116x_ep {
325 325
326/*-------------------------------------------------------------------------*/ 326/*-------------------------------------------------------------------------*/
327 327
328#ifdef DEBUG 328#define DBG(stuff...) pr_debug("116x: " stuff)
329#define DBG(stuff...) printk(KERN_DEBUG "116x: " stuff)
330#else
331#define DBG(stuff...) do{}while(0)
332#endif
333 329
334#ifdef VERBOSE 330#ifdef VERBOSE
335# define VDBG DBG 331# define VDBG DBG
@@ -358,15 +354,8 @@ struct isp116x_ep {
358#define isp116x_check_platform_delay(h) 0 354#define isp116x_check_platform_delay(h) 0
359#endif 355#endif
360 356
361#if defined(DEBUG)
362#define IRQ_TEST() BUG_ON(!irqs_disabled())
363#else
364#define IRQ_TEST() do{}while(0)
365#endif
366
367static inline void isp116x_write_addr(struct isp116x *isp116x, unsigned reg) 357static inline void isp116x_write_addr(struct isp116x *isp116x, unsigned reg)
368{ 358{
369 IRQ_TEST();
370 writew(reg & 0xff, isp116x->addr_reg); 359 writew(reg & 0xff, isp116x->addr_reg);
371 isp116x_delay(isp116x, 300); 360 isp116x_delay(isp116x, 300);
372} 361}
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index b04e8ece4d35..6f29abad6815 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -37,11 +37,7 @@
37 * recovery time (MSCx = 0x7f8c) with a memory clock of 99.53 MHz. 37 * recovery time (MSCx = 0x7f8c) with a memory clock of 99.53 MHz.
38 */ 38 */
39 39
40#ifdef CONFIG_USB_DEBUG 40#undef ISP1362_DEBUG
41# define ISP1362_DEBUG
42#else
43# undef ISP1362_DEBUG
44#endif
45 41
46/* 42/*
47 * The PXA255 UDC apparently doesn't handle GET_STATUS, GET_CONFIG and 43 * The PXA255 UDC apparently doesn't handle GET_STATUS, GET_CONFIG and
@@ -82,6 +78,8 @@
82#include <linux/io.h> 78#include <linux/io.h>
83#include <linux/bitmap.h> 79#include <linux/bitmap.h>
84#include <linux/prefetch.h> 80#include <linux/prefetch.h>
81#include <linux/debugfs.h>
82#include <linux/seq_file.h>
85 83
86#include <asm/irq.h> 84#include <asm/irq.h>
87#include <asm/byteorder.h> 85#include <asm/byteorder.h>
@@ -92,7 +90,6 @@ static int dbg_level;
92module_param(dbg_level, int, 0644); 90module_param(dbg_level, int, 0644);
93#else 91#else
94module_param(dbg_level, int, 0); 92module_param(dbg_level, int, 0);
95#define STUB_DEBUG_FILE
96#endif 93#endif
97 94
98#include "../core/usb.h" 95#include "../core/usb.h"
@@ -350,8 +347,6 @@ static void isp1362_write_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep
350 struct ptd *ptd = &ep->ptd; 347 struct ptd *ptd = &ep->ptd;
351 int len = PTD_GET_DIR(ptd) == PTD_DIR_IN ? 0 : ep->length; 348 int len = PTD_GET_DIR(ptd) == PTD_DIR_IN ? 0 : ep->length;
352 349
353 _BUG_ON(ep->ptd_offset < 0);
354
355 prefetch(ptd); 350 prefetch(ptd);
356 isp1362_write_buffer(isp1362_hcd, ptd, ep->ptd_offset, PTD_HEADER_SIZE); 351 isp1362_write_buffer(isp1362_hcd, ptd, ep->ptd_offset, PTD_HEADER_SIZE);
357 if (len) 352 if (len)
@@ -1575,12 +1570,12 @@ static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1575 DBG(0, "ClearHubFeature: "); 1570 DBG(0, "ClearHubFeature: ");
1576 switch (wValue) { 1571 switch (wValue) {
1577 case C_HUB_OVER_CURRENT: 1572 case C_HUB_OVER_CURRENT:
1578 _DBG(0, "C_HUB_OVER_CURRENT\n"); 1573 DBG(0, "C_HUB_OVER_CURRENT\n");
1579 spin_lock_irqsave(&isp1362_hcd->lock, flags); 1574 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1580 isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_OCIC); 1575 isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_OCIC);
1581 spin_unlock_irqrestore(&isp1362_hcd->lock, flags); 1576 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1582 case C_HUB_LOCAL_POWER: 1577 case C_HUB_LOCAL_POWER:
1583 _DBG(0, "C_HUB_LOCAL_POWER\n"); 1578 DBG(0, "C_HUB_LOCAL_POWER\n");
1584 break; 1579 break;
1585 default: 1580 default:
1586 goto error; 1581 goto error;
@@ -1591,7 +1586,7 @@ static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1591 switch (wValue) { 1586 switch (wValue) {
1592 case C_HUB_OVER_CURRENT: 1587 case C_HUB_OVER_CURRENT:
1593 case C_HUB_LOCAL_POWER: 1588 case C_HUB_LOCAL_POWER:
1594 _DBG(0, "C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n"); 1589 DBG(0, "C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1595 break; 1590 break;
1596 default: 1591 default:
1597 goto error; 1592 goto error;
@@ -1622,36 +1617,36 @@ static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1622 1617
1623 switch (wValue) { 1618 switch (wValue) {
1624 case USB_PORT_FEAT_ENABLE: 1619 case USB_PORT_FEAT_ENABLE:
1625 _DBG(0, "USB_PORT_FEAT_ENABLE\n"); 1620 DBG(0, "USB_PORT_FEAT_ENABLE\n");
1626 tmp = RH_PS_CCS; 1621 tmp = RH_PS_CCS;
1627 break; 1622 break;
1628 case USB_PORT_FEAT_C_ENABLE: 1623 case USB_PORT_FEAT_C_ENABLE:
1629 _DBG(0, "USB_PORT_FEAT_C_ENABLE\n"); 1624 DBG(0, "USB_PORT_FEAT_C_ENABLE\n");
1630 tmp = RH_PS_PESC; 1625 tmp = RH_PS_PESC;
1631 break; 1626 break;
1632 case USB_PORT_FEAT_SUSPEND: 1627 case USB_PORT_FEAT_SUSPEND:
1633 _DBG(0, "USB_PORT_FEAT_SUSPEND\n"); 1628 DBG(0, "USB_PORT_FEAT_SUSPEND\n");
1634 tmp = RH_PS_POCI; 1629 tmp = RH_PS_POCI;
1635 break; 1630 break;
1636 case USB_PORT_FEAT_C_SUSPEND: 1631 case USB_PORT_FEAT_C_SUSPEND:
1637 _DBG(0, "USB_PORT_FEAT_C_SUSPEND\n"); 1632 DBG(0, "USB_PORT_FEAT_C_SUSPEND\n");
1638 tmp = RH_PS_PSSC; 1633 tmp = RH_PS_PSSC;
1639 break; 1634 break;
1640 case USB_PORT_FEAT_POWER: 1635 case USB_PORT_FEAT_POWER:
1641 _DBG(0, "USB_PORT_FEAT_POWER\n"); 1636 DBG(0, "USB_PORT_FEAT_POWER\n");
1642 tmp = RH_PS_LSDA; 1637 tmp = RH_PS_LSDA;
1643 1638
1644 break; 1639 break;
1645 case USB_PORT_FEAT_C_CONNECTION: 1640 case USB_PORT_FEAT_C_CONNECTION:
1646 _DBG(0, "USB_PORT_FEAT_C_CONNECTION\n"); 1641 DBG(0, "USB_PORT_FEAT_C_CONNECTION\n");
1647 tmp = RH_PS_CSC; 1642 tmp = RH_PS_CSC;
1648 break; 1643 break;
1649 case USB_PORT_FEAT_C_OVER_CURRENT: 1644 case USB_PORT_FEAT_C_OVER_CURRENT:
1650 _DBG(0, "USB_PORT_FEAT_C_OVER_CURRENT\n"); 1645 DBG(0, "USB_PORT_FEAT_C_OVER_CURRENT\n");
1651 tmp = RH_PS_OCIC; 1646 tmp = RH_PS_OCIC;
1652 break; 1647 break;
1653 case USB_PORT_FEAT_C_RESET: 1648 case USB_PORT_FEAT_C_RESET:
1654 _DBG(0, "USB_PORT_FEAT_C_RESET\n"); 1649 DBG(0, "USB_PORT_FEAT_C_RESET\n");
1655 tmp = RH_PS_PRSC; 1650 tmp = RH_PS_PRSC;
1656 break; 1651 break;
1657 default: 1652 default:
@@ -1671,7 +1666,7 @@ static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1671 wIndex--; 1666 wIndex--;
1672 switch (wValue) { 1667 switch (wValue) {
1673 case USB_PORT_FEAT_SUSPEND: 1668 case USB_PORT_FEAT_SUSPEND:
1674 _DBG(0, "USB_PORT_FEAT_SUSPEND\n"); 1669 DBG(0, "USB_PORT_FEAT_SUSPEND\n");
1675 spin_lock_irqsave(&isp1362_hcd->lock, flags); 1670 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1676 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PSS); 1671 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PSS);
1677 isp1362_hcd->rhport[wIndex] = 1672 isp1362_hcd->rhport[wIndex] =
@@ -1679,7 +1674,7 @@ static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1679 spin_unlock_irqrestore(&isp1362_hcd->lock, flags); 1674 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1680 break; 1675 break;
1681 case USB_PORT_FEAT_POWER: 1676 case USB_PORT_FEAT_POWER:
1682 _DBG(0, "USB_PORT_FEAT_POWER\n"); 1677 DBG(0, "USB_PORT_FEAT_POWER\n");
1683 spin_lock_irqsave(&isp1362_hcd->lock, flags); 1678 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1684 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PPS); 1679 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PPS);
1685 isp1362_hcd->rhport[wIndex] = 1680 isp1362_hcd->rhport[wIndex] =
@@ -1687,7 +1682,7 @@ static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1687 spin_unlock_irqrestore(&isp1362_hcd->lock, flags); 1682 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1688 break; 1683 break;
1689 case USB_PORT_FEAT_RESET: 1684 case USB_PORT_FEAT_RESET:
1690 _DBG(0, "USB_PORT_FEAT_RESET\n"); 1685 DBG(0, "USB_PORT_FEAT_RESET\n");
1691 spin_lock_irqsave(&isp1362_hcd->lock, flags); 1686 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1692 1687
1693 t1 = jiffies + msecs_to_jiffies(USB_RESET_WIDTH); 1688 t1 = jiffies + msecs_to_jiffies(USB_RESET_WIDTH);
@@ -1721,7 +1716,7 @@ static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1721 default: 1716 default:
1722 error: 1717 error:
1723 /* "protocol stall" on error */ 1718 /* "protocol stall" on error */
1724 _DBG(0, "PROTOCOL STALL\n"); 1719 DBG(0, "PROTOCOL STALL\n");
1725 retval = -EPIPE; 1720 retval = -EPIPE;
1726 } 1721 }
1727 1722
@@ -1913,20 +1908,6 @@ static int isp1362_bus_resume(struct usb_hcd *hcd)
1913 1908
1914/*-------------------------------------------------------------------------*/ 1909/*-------------------------------------------------------------------------*/
1915 1910
1916#ifdef STUB_DEBUG_FILE
1917
1918static inline void create_debug_file(struct isp1362_hcd *isp1362_hcd)
1919{
1920}
1921static inline void remove_debug_file(struct isp1362_hcd *isp1362_hcd)
1922{
1923}
1924
1925#else
1926
1927#include <linux/proc_fs.h>
1928#include <linux/seq_file.h>
1929
1930static void dump_irq(struct seq_file *s, char *label, u16 mask) 1911static void dump_irq(struct seq_file *s, char *label, u16 mask)
1931{ 1912{
1932 seq_printf(s, "%-15s %04x%s%s%s%s%s%s\n", label, mask, 1913 seq_printf(s, "%-15s %04x%s%s%s%s%s%s\n", label, mask,
@@ -2069,7 +2050,7 @@ static void dump_regs(struct seq_file *s, struct isp1362_hcd *isp1362_hcd)
2069 isp1362_read_reg16(isp1362_hcd, HCATLDTCTO)); 2050 isp1362_read_reg16(isp1362_hcd, HCATLDTCTO));
2070} 2051}
2071 2052
2072static int proc_isp1362_show(struct seq_file *s, void *unused) 2053static int isp1362_show(struct seq_file *s, void *unused)
2073{ 2054{
2074 struct isp1362_hcd *isp1362_hcd = s->private; 2055 struct isp1362_hcd *isp1362_hcd = s->private;
2075 struct isp1362_ep *ep; 2056 struct isp1362_ep *ep;
@@ -2173,41 +2154,31 @@ static int proc_isp1362_show(struct seq_file *s, void *unused)
2173 return 0; 2154 return 0;
2174} 2155}
2175 2156
2176static int proc_isp1362_open(struct inode *inode, struct file *file) 2157static int isp1362_open(struct inode *inode, struct file *file)
2177{ 2158{
2178 return single_open(file, proc_isp1362_show, PDE_DATA(inode)); 2159 return single_open(file, isp1362_show, inode);
2179} 2160}
2180 2161
2181static const struct file_operations proc_ops = { 2162static const struct file_operations debug_ops = {
2182 .open = proc_isp1362_open, 2163 .open = isp1362_open,
2183 .read = seq_read, 2164 .read = seq_read,
2184 .llseek = seq_lseek, 2165 .llseek = seq_lseek,
2185 .release = single_release, 2166 .release = single_release,
2186}; 2167};
2187 2168
2188/* expect just one isp1362_hcd per system */ 2169/* expect just one isp1362_hcd per system */
2189static const char proc_filename[] = "driver/isp1362";
2190
2191static void create_debug_file(struct isp1362_hcd *isp1362_hcd) 2170static void create_debug_file(struct isp1362_hcd *isp1362_hcd)
2192{ 2171{
2193 struct proc_dir_entry *pde; 2172 isp1362_hcd->debug_file = debugfs_create_file("isp1362", S_IRUGO,
2194 2173 usb_debug_root,
2195 pde = proc_create_data(proc_filename, 0, NULL, &proc_ops, isp1362_hcd); 2174 isp1362_hcd, &debug_ops);
2196 if (pde == NULL) {
2197 pr_warning("%s: Failed to create debug file '%s'\n", __func__, proc_filename);
2198 return;
2199 }
2200 isp1362_hcd->pde = pde;
2201} 2175}
2202 2176
2203static void remove_debug_file(struct isp1362_hcd *isp1362_hcd) 2177static void remove_debug_file(struct isp1362_hcd *isp1362_hcd)
2204{ 2178{
2205 if (isp1362_hcd->pde) 2179 debugfs_remove(isp1362_hcd->debug_file);
2206 remove_proc_entry(proc_filename, NULL);
2207} 2180}
2208 2181
2209#endif
2210
2211/*-------------------------------------------------------------------------*/ 2182/*-------------------------------------------------------------------------*/
2212 2183
2213static void __isp1362_sw_reset(struct isp1362_hcd *isp1362_hcd) 2184static void __isp1362_sw_reset(struct isp1362_hcd *isp1362_hcd)
@@ -2754,7 +2725,7 @@ static int isp1362_probe(struct platform_device *pdev)
2754 INIT_LIST_HEAD(&isp1362_hcd->periodic); 2725 INIT_LIST_HEAD(&isp1362_hcd->periodic);
2755 INIT_LIST_HEAD(&isp1362_hcd->isoc); 2726 INIT_LIST_HEAD(&isp1362_hcd->isoc);
2756 INIT_LIST_HEAD(&isp1362_hcd->remove_list); 2727 INIT_LIST_HEAD(&isp1362_hcd->remove_list);
2757 isp1362_hcd->board = pdev->dev.platform_data; 2728 isp1362_hcd->board = dev_get_platdata(&pdev->dev);
2758#if USE_PLATFORM_DELAY 2729#if USE_PLATFORM_DELAY
2759 if (!isp1362_hcd->board->delay) { 2730 if (!isp1362_hcd->board->delay) {
2760 dev_err(hcd->self.controller, "No platform delay function given\n"); 2731 dev_err(hcd->self.controller, "No platform delay function given\n");
diff --git a/drivers/usb/host/isp1362.h b/drivers/usb/host/isp1362.h
index 0f97820e65be..3b0b4847c3a9 100644
--- a/drivers/usb/host/isp1362.h
+++ b/drivers/usb/host/isp1362.h
@@ -76,14 +76,14 @@ static inline void delayed_insw(unsigned int addr, void *buf, int len)
76 76
77#define ISP1362_REG_WRITE_OFFSET 0x80 77#define ISP1362_REG_WRITE_OFFSET 0x80
78 78
79#ifdef ISP1362_DEBUG
80typedef const unsigned int isp1362_reg_t;
81
82#define REG_WIDTH_16 0x000 79#define REG_WIDTH_16 0x000
83#define REG_WIDTH_32 0x100 80#define REG_WIDTH_32 0x100
84#define REG_WIDTH_MASK 0x100 81#define REG_WIDTH_MASK 0x100
85#define REG_NO_MASK 0x0ff 82#define REG_NO_MASK 0x0ff
86 83
84#ifdef ISP1362_DEBUG
85typedef const unsigned int isp1362_reg_t;
86
87#define REG_ACCESS_R 0x200 87#define REG_ACCESS_R 0x200
88#define REG_ACCESS_W 0x400 88#define REG_ACCESS_W 0x400
89#define REG_ACCESS_RW 0x600 89#define REG_ACCESS_RW 0x600
@@ -91,9 +91,6 @@ typedef const unsigned int isp1362_reg_t;
91 91
92#define ISP1362_REG_NO(r) ((r) & REG_NO_MASK) 92#define ISP1362_REG_NO(r) ((r) & REG_NO_MASK)
93 93
94#define _BUG_ON(x) BUG_ON(x)
95#define _WARN_ON(x) WARN_ON(x)
96
97#define ISP1362_REG(name, addr, width, rw) \ 94#define ISP1362_REG(name, addr, width, rw) \
98static isp1362_reg_t ISP1362_REG_##name = ((addr) | (width) | (rw)) 95static isp1362_reg_t ISP1362_REG_##name = ((addr) | (width) | (rw))
99 96
@@ -102,8 +99,6 @@ static isp1362_reg_t ISP1362_REG_##name = ((addr) | (width) | (rw))
102#else 99#else
103typedef const unsigned char isp1362_reg_t; 100typedef const unsigned char isp1362_reg_t;
104#define ISP1362_REG_NO(r) (r) 101#define ISP1362_REG_NO(r) (r)
105#define _BUG_ON(x) do {} while (0)
106#define _WARN_ON(x) do {} while (0)
107 102
108#define ISP1362_REG(name, addr, width, rw) \ 103#define ISP1362_REG(name, addr, width, rw) \
109static isp1362_reg_t ISP1362_REG_##name = addr 104static isp1362_reg_t ISP1362_REG_##name = addr
@@ -485,7 +480,7 @@ struct isp1362_hcd {
485 480
486 struct isp1362_platform_data *board; 481 struct isp1362_platform_data *board;
487 482
488 struct proc_dir_entry *pde; 483 struct dentry *debug_file;
489 unsigned long stat1, stat2, stat4, stat8, stat16; 484 unsigned long stat1, stat2, stat4, stat8, stat16;
490 485
491 /* HC registers */ 486 /* HC registers */
@@ -587,21 +582,11 @@ static inline struct usb_hcd *isp1362_hcd_to_hcd(struct isp1362_hcd *isp1362_hcd
587 * ISP1362 HW Interface 582 * ISP1362 HW Interface
588 */ 583 */
589 584
590#ifdef ISP1362_DEBUG
591#define DBG(level, fmt...) \ 585#define DBG(level, fmt...) \
592 do { \ 586 do { \
593 if (dbg_level > level) \ 587 if (dbg_level > level) \
594 pr_debug(fmt); \ 588 pr_debug(fmt); \
595 } while (0) 589 } while (0)
596#define _DBG(level, fmt...) \
597 do { \
598 if (dbg_level > level) \
599 printk(fmt); \
600 } while (0)
601#else
602#define DBG(fmt...) do {} while (0)
603#define _DBG DBG
604#endif
605 590
606#ifdef VERBOSE 591#ifdef VERBOSE
607# define VDBG(fmt...) DBG(3, fmt) 592# define VDBG(fmt...) DBG(3, fmt)
@@ -645,9 +630,7 @@ static inline struct usb_hcd *isp1362_hcd_to_hcd(struct isp1362_hcd *isp1362_hcd
645 */ 630 */
646static void isp1362_write_addr(struct isp1362_hcd *isp1362_hcd, isp1362_reg_t reg) 631static void isp1362_write_addr(struct isp1362_hcd *isp1362_hcd, isp1362_reg_t reg)
647{ 632{
648 /*_BUG_ON((reg & ISP1362_REG_WRITE_OFFSET) && !(reg & REG_ACCESS_W));*/
649 REG_ACCESS_TEST(reg); 633 REG_ACCESS_TEST(reg);
650 _BUG_ON(!irqs_disabled());
651 DUMMY_DELAY_ACCESS; 634 DUMMY_DELAY_ACCESS;
652 writew(ISP1362_REG_NO(reg), isp1362_hcd->addr_reg); 635 writew(ISP1362_REG_NO(reg), isp1362_hcd->addr_reg);
653 DUMMY_DELAY_ACCESS; 636 DUMMY_DELAY_ACCESS;
@@ -656,7 +639,6 @@ static void isp1362_write_addr(struct isp1362_hcd *isp1362_hcd, isp1362_reg_t re
656 639
657static void isp1362_write_data16(struct isp1362_hcd *isp1362_hcd, u16 val) 640static void isp1362_write_data16(struct isp1362_hcd *isp1362_hcd, u16 val)
658{ 641{
659 _BUG_ON(!irqs_disabled());
660 DUMMY_DELAY_ACCESS; 642 DUMMY_DELAY_ACCESS;
661 writew(val, isp1362_hcd->data_reg); 643 writew(val, isp1362_hcd->data_reg);
662} 644}
@@ -665,7 +647,6 @@ static u16 isp1362_read_data16(struct isp1362_hcd *isp1362_hcd)
665{ 647{
666 u16 val; 648 u16 val;
667 649
668 _BUG_ON(!irqs_disabled());
669 DUMMY_DELAY_ACCESS; 650 DUMMY_DELAY_ACCESS;
670 val = readw(isp1362_hcd->data_reg); 651 val = readw(isp1362_hcd->data_reg);
671 652
@@ -674,7 +655,6 @@ static u16 isp1362_read_data16(struct isp1362_hcd *isp1362_hcd)
674 655
675static void isp1362_write_data32(struct isp1362_hcd *isp1362_hcd, u32 val) 656static void isp1362_write_data32(struct isp1362_hcd *isp1362_hcd, u32 val)
676{ 657{
677 _BUG_ON(!irqs_disabled());
678#if USE_32BIT 658#if USE_32BIT
679 DUMMY_DELAY_ACCESS; 659 DUMMY_DELAY_ACCESS;
680 writel(val, isp1362_hcd->data_reg); 660 writel(val, isp1362_hcd->data_reg);
@@ -690,7 +670,6 @@ static u32 isp1362_read_data32(struct isp1362_hcd *isp1362_hcd)
690{ 670{
691 u32 val; 671 u32 val;
692 672
693 _BUG_ON(!irqs_disabled());
694#if USE_32BIT 673#if USE_32BIT
695 DUMMY_DELAY_ACCESS; 674 DUMMY_DELAY_ACCESS;
696 val = readl(isp1362_hcd->data_reg); 675 val = readl(isp1362_hcd->data_reg);
@@ -713,8 +692,6 @@ static void isp1362_read_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 le
713 if (!len) 692 if (!len)
714 return; 693 return;
715 694
716 _BUG_ON(!irqs_disabled());
717
718 RDBG("%s: Reading %d byte from fifo to mem @ %p\n", __func__, len, buf); 695 RDBG("%s: Reading %d byte from fifo to mem @ %p\n", __func__, len, buf);
719#if USE_32BIT 696#if USE_32BIT
720 if (len >= 4) { 697 if (len >= 4) {
@@ -760,8 +737,6 @@ static void isp1362_write_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 l
760 return; 737 return;
761 } 738 }
762 739
763 _BUG_ON(!irqs_disabled());
764
765 RDBG("%s: Writing %d byte to fifo from memory @%p\n", __func__, len, buf); 740 RDBG("%s: Writing %d byte to fifo from memory @%p\n", __func__, len, buf);
766#if USE_32BIT 741#if USE_32BIT
767 if (len >= 4) { 742 if (len >= 4) {
@@ -854,7 +829,6 @@ static void isp1362_write_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 l
854 isp1362_write_reg32(d, r, __v & ~m); \ 829 isp1362_write_reg32(d, r, __v & ~m); \
855} 830}
856 831
857#ifdef ISP1362_DEBUG
858#define isp1362_show_reg(d, r) { \ 832#define isp1362_show_reg(d, r) { \
859 if ((ISP1362_REG_##r & REG_WIDTH_MASK) == REG_WIDTH_32) \ 833 if ((ISP1362_REG_##r & REG_WIDTH_MASK) == REG_WIDTH_32) \
860 DBG(0, "%-12s[%02x]: %08x\n", #r, \ 834 DBG(0, "%-12s[%02x]: %08x\n", #r, \
@@ -863,9 +837,6 @@ static void isp1362_write_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 l
863 DBG(0, "%-12s[%02x]: %04x\n", #r, \ 837 DBG(0, "%-12s[%02x]: %04x\n", #r, \
864 ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg16(d, r)); \ 838 ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg16(d, r)); \
865} 839}
866#else
867#define isp1362_show_reg(d, r) do {} while (0)
868#endif
869 840
870static void __attribute__((__unused__)) isp1362_show_regs(struct isp1362_hcd *isp1362_hcd) 841static void __attribute__((__unused__)) isp1362_show_regs(struct isp1362_hcd *isp1362_hcd)
871{ 842{
@@ -923,10 +894,6 @@ static void __attribute__((__unused__)) isp1362_show_regs(struct isp1362_hcd *is
923 894
924static void isp1362_write_diraddr(struct isp1362_hcd *isp1362_hcd, u16 offset, u16 len) 895static void isp1362_write_diraddr(struct isp1362_hcd *isp1362_hcd, u16 offset, u16 len)
925{ 896{
926 _BUG_ON(offset & 1);
927 _BUG_ON(offset >= ISP1362_BUF_SIZE);
928 _BUG_ON(len > ISP1362_BUF_SIZE);
929 _BUG_ON(offset + len > ISP1362_BUF_SIZE);
930 len = (len + 1) & ~1; 897 len = (len + 1) & ~1;
931 898
932 isp1362_clr_mask16(isp1362_hcd, HCDMACFG, HCDMACFG_CTR_ENABLE); 899 isp1362_clr_mask16(isp1362_hcd, HCDMACFG, HCDMACFG_CTR_ENABLE);
@@ -936,42 +903,32 @@ static void isp1362_write_diraddr(struct isp1362_hcd *isp1362_hcd, u16 offset, u
936 903
937static void isp1362_read_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len) 904static void isp1362_read_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len)
938{ 905{
939 _BUG_ON(offset & 1);
940
941 isp1362_write_diraddr(isp1362_hcd, offset, len); 906 isp1362_write_diraddr(isp1362_hcd, offset, len);
942 907
943 DBG(3, "%s: Reading %d byte from buffer @%04x to memory @ %p\n", 908 DBG(3, "%s: Reading %d byte from buffer @%04x to memory @ %p\n",
944 __func__, len, offset, buf); 909 __func__, len, offset, buf);
945 910
946 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT); 911 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
947 _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
948 912
949 isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA); 913 isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA);
950 914
951 isp1362_read_fifo(isp1362_hcd, buf, len); 915 isp1362_read_fifo(isp1362_hcd, buf, len);
952 _WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
953 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT); 916 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
954 _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
955} 917}
956 918
957static void isp1362_write_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len) 919static void isp1362_write_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len)
958{ 920{
959 _BUG_ON(offset & 1);
960
961 isp1362_write_diraddr(isp1362_hcd, offset, len); 921 isp1362_write_diraddr(isp1362_hcd, offset, len);
962 922
963 DBG(3, "%s: Writing %d byte to buffer @%04x from memory @ %p\n", 923 DBG(3, "%s: Writing %d byte to buffer @%04x from memory @ %p\n",
964 __func__, len, offset, buf); 924 __func__, len, offset, buf);
965 925
966 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT); 926 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
967 _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
968 927
969 isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA | ISP1362_REG_WRITE_OFFSET); 928 isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA | ISP1362_REG_WRITE_OFFSET);
970 isp1362_write_fifo(isp1362_hcd, buf, len); 929 isp1362_write_fifo(isp1362_hcd, buf, len);
971 930
972 _WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
973 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT); 931 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
974 _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
975} 932}
976 933
977static void __attribute__((unused)) dump_data(char *buf, int len) 934static void __attribute__((unused)) dump_data(char *buf, int len)
@@ -1002,7 +959,7 @@ static void __attribute__((unused)) dump_data(char *buf, int len)
1002 } 959 }
1003} 960}
1004 961
1005#if defined(ISP1362_DEBUG) && defined(PTD_TRACE) 962#if defined(PTD_TRACE)
1006 963
1007static void dump_ptd(struct ptd *ptd) 964static void dump_ptd(struct ptd *ptd)
1008{ 965{
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index 3df49b169b53..df931e9ba5b5 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -351,7 +351,7 @@ static int isp1760_plat_probe(struct platform_device *pdev)
351 struct resource *mem_res; 351 struct resource *mem_res;
352 struct resource *irq_res; 352 struct resource *irq_res;
353 resource_size_t mem_size; 353 resource_size_t mem_size;
354 struct isp1760_platform_data *priv = pdev->dev.platform_data; 354 struct isp1760_platform_data *priv = dev_get_platdata(&pdev->dev);
355 unsigned int devflags = 0; 355 unsigned int devflags = 0;
356 unsigned long irqflags = IRQF_SHARED; 356 unsigned long irqflags = IRQF_SHARED;
357 357
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 9677f6831209..b3cdd1467521 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -31,8 +31,8 @@
31#define at91_for_each_port(index) \ 31#define at91_for_each_port(index) \
32 for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++) 32 for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
33 33
34/* interface and function clocks; sometimes also an AHB clock */ 34/* interface, function and usb clocks; sometimes also an AHB clock */
35static struct clk *iclk, *fclk, *hclk; 35static struct clk *iclk, *fclk, *uclk, *hclk;
36static int clocked; 36static int clocked;
37 37
38extern int usb_disabled(void); 38extern int usb_disabled(void);
@@ -41,6 +41,10 @@ extern int usb_disabled(void);
41 41
42static void at91_start_clock(void) 42static void at91_start_clock(void)
43{ 43{
44 if (IS_ENABLED(CONFIG_COMMON_CLK)) {
45 clk_set_rate(uclk, 48000000);
46 clk_prepare_enable(uclk);
47 }
44 clk_prepare_enable(hclk); 48 clk_prepare_enable(hclk);
45 clk_prepare_enable(iclk); 49 clk_prepare_enable(iclk);
46 clk_prepare_enable(fclk); 50 clk_prepare_enable(fclk);
@@ -52,6 +56,8 @@ static void at91_stop_clock(void)
52 clk_disable_unprepare(fclk); 56 clk_disable_unprepare(fclk);
53 clk_disable_unprepare(iclk); 57 clk_disable_unprepare(iclk);
54 clk_disable_unprepare(hclk); 58 clk_disable_unprepare(hclk);
59 if (IS_ENABLED(CONFIG_COMMON_CLK))
60 clk_disable_unprepare(uclk);
55 clocked = 0; 61 clocked = 0;
56} 62}
57 63
@@ -162,6 +168,14 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
162 retval = PTR_ERR(hclk); 168 retval = PTR_ERR(hclk);
163 goto err5; 169 goto err5;
164 } 170 }
171 if (IS_ENABLED(CONFIG_COMMON_CLK)) {
172 uclk = clk_get(&pdev->dev, "usb_clk");
173 if (IS_ERR(uclk)) {
174 dev_err(&pdev->dev, "failed to get uclk\n");
175 retval = PTR_ERR(uclk);
176 goto err6;
177 }
178 }
165 179
166 at91_start_hc(pdev); 180 at91_start_hc(pdev);
167 ohci_hcd_init(hcd_to_ohci(hcd)); 181 ohci_hcd_init(hcd_to_ohci(hcd));
@@ -173,6 +187,9 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
173 /* Error handling */ 187 /* Error handling */
174 at91_stop_hc(pdev); 188 at91_stop_hc(pdev);
175 189
190 if (IS_ENABLED(CONFIG_COMMON_CLK))
191 clk_put(uclk);
192 err6:
176 clk_put(hclk); 193 clk_put(hclk);
177 err5: 194 err5:
178 clk_put(fclk); 195 clk_put(fclk);
@@ -212,6 +229,8 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
212 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 229 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
213 usb_put_hcd(hcd); 230 usb_put_hcd(hcd);
214 231
232 if (IS_ENABLED(CONFIG_COMMON_CLK))
233 clk_put(uclk);
215 clk_put(hclk); 234 clk_put(hclk);
216 clk_put(fclk); 235 clk_put(fclk);
217 clk_put(iclk); 236 clk_put(iclk);
@@ -225,7 +244,7 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
225static int 244static int
226ohci_at91_reset (struct usb_hcd *hcd) 245ohci_at91_reset (struct usb_hcd *hcd)
227{ 246{
228 struct at91_usbh_data *board = hcd->self.controller->platform_data; 247 struct at91_usbh_data *board = dev_get_platdata(hcd->self.controller);
229 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 248 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
230 int ret; 249 int ret;
231 250
@@ -280,7 +299,7 @@ static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
280 */ 299 */
281static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) 300static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
282{ 301{
283 struct at91_usbh_data *pdata = hcd->self.controller->platform_data; 302 struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
284 int length = ohci_hub_status_data(hcd, buf); 303 int length = ohci_hub_status_data(hcd, buf);
285 int port; 304 int port;
286 305
@@ -301,7 +320,7 @@ static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
301static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 320static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
302 u16 wIndex, char *buf, u16 wLength) 321 u16 wIndex, char *buf, u16 wLength)
303{ 322{
304 struct at91_usbh_data *pdata = hcd->self.controller->platform_data; 323 struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
305 struct usb_hub_descriptor *desc; 324 struct usb_hub_descriptor *desc;
306 int ret = -EINVAL; 325 int ret = -EINVAL;
307 u32 *data = (u32 *)buf; 326 u32 *data = (u32 *)buf;
@@ -461,7 +480,7 @@ static const struct hc_driver ohci_at91_hc_driver = {
461static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) 480static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
462{ 481{
463 struct platform_device *pdev = data; 482 struct platform_device *pdev = data;
464 struct at91_usbh_data *pdata = pdev->dev.platform_data; 483 struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
465 int val, gpio, port; 484 int val, gpio, port;
466 485
467 /* From the GPIO notifying the over-current situation, find 486 /* From the GPIO notifying the over-current situation, find
@@ -567,7 +586,7 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
567 if (ret) 586 if (ret)
568 return ret; 587 return ret;
569 588
570 pdata = pdev->dev.platform_data; 589 pdata = dev_get_platdata(&pdev->dev);
571 590
572 if (pdata) { 591 if (pdata) {
573 at91_for_each_port(i) { 592 at91_for_each_port(i) {
@@ -643,7 +662,7 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
643 662
644static int ohci_hcd_at91_drv_remove(struct platform_device *pdev) 663static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
645{ 664{
646 struct at91_usbh_data *pdata = pdev->dev.platform_data; 665 struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
647 int i; 666 int i;
648 667
649 if (pdata) { 668 if (pdata) {
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index 6aaa9c9c8eb0..9be59f11e051 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -85,7 +85,7 @@ static void ohci_da8xx_ocic_handler(struct da8xx_ohci_root_hub *hub,
85static int ohci_da8xx_init(struct usb_hcd *hcd) 85static int ohci_da8xx_init(struct usb_hcd *hcd)
86{ 86{
87 struct device *dev = hcd->self.controller; 87 struct device *dev = hcd->self.controller;
88 struct da8xx_ohci_root_hub *hub = dev->platform_data; 88 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
89 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 89 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
90 int result; 90 int result;
91 u32 rh_a; 91 u32 rh_a;
@@ -171,7 +171,7 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
171 u16 wIndex, char *buf, u16 wLength) 171 u16 wIndex, char *buf, u16 wLength)
172{ 172{
173 struct device *dev = hcd->self.controller; 173 struct device *dev = hcd->self.controller;
174 struct da8xx_ohci_root_hub *hub = dev->platform_data; 174 struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
175 int temp; 175 int temp;
176 176
177 switch (typeReq) { 177 switch (typeReq) {
@@ -292,7 +292,7 @@ static const struct hc_driver ohci_da8xx_hc_driver = {
292static int usb_hcd_da8xx_probe(const struct hc_driver *driver, 292static int usb_hcd_da8xx_probe(const struct hc_driver *driver,
293 struct platform_device *pdev) 293 struct platform_device *pdev)
294{ 294{
295 struct da8xx_ohci_root_hub *hub = pdev->dev.platform_data; 295 struct da8xx_ohci_root_hub *hub = dev_get_platdata(&pdev->dev);
296 struct usb_hcd *hcd; 296 struct usb_hcd *hcd;
297 struct resource *mem; 297 struct resource *mem;
298 int error, irq; 298 int error, irq;
@@ -380,7 +380,7 @@ err0:
380static inline void 380static inline void
381usb_hcd_da8xx_remove(struct usb_hcd *hcd, struct platform_device *pdev) 381usb_hcd_da8xx_remove(struct usb_hcd *hcd, struct platform_device *pdev)
382{ 382{
383 struct da8xx_ohci_root_hub *hub = pdev->dev.platform_data; 383 struct da8xx_ohci_root_hub *hub = dev_get_platdata(&pdev->dev);
384 384
385 hub->ocic_notify(NULL); 385 hub->ocic_notify(NULL);
386 usb_remove_hcd(hcd); 386 usb_remove_hcd(hcd);
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
index 8704e9fa5a80..84a20d5223b9 100644
--- a/drivers/usb/host/ohci-ep93xx.c
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -30,83 +30,6 @@
30 30
31static struct clk *usb_host_clock; 31static struct clk *usb_host_clock;
32 32
33static void ep93xx_start_hc(struct device *dev)
34{
35 clk_enable(usb_host_clock);
36}
37
38static void ep93xx_stop_hc(struct device *dev)
39{
40 clk_disable(usb_host_clock);
41}
42
43static int usb_hcd_ep93xx_probe(const struct hc_driver *driver,
44 struct platform_device *pdev)
45{
46 int retval;
47 struct usb_hcd *hcd;
48
49 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
50 dev_dbg(&pdev->dev, "resource[1] is not IORESOURCE_IRQ\n");
51 return -ENOMEM;
52 }
53
54 hcd = usb_create_hcd(driver, &pdev->dev, "ep93xx");
55 if (hcd == NULL)
56 return -ENOMEM;
57
58 hcd->rsrc_start = pdev->resource[0].start;
59 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
60 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
61 usb_put_hcd(hcd);
62 retval = -EBUSY;
63 goto err1;
64 }
65
66 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
67 if (hcd->regs == NULL) {
68 dev_dbg(&pdev->dev, "ioremap failed\n");
69 retval = -ENOMEM;
70 goto err2;
71 }
72
73 usb_host_clock = clk_get(&pdev->dev, NULL);
74 if (IS_ERR(usb_host_clock)) {
75 dev_dbg(&pdev->dev, "clk_get failed\n");
76 retval = PTR_ERR(usb_host_clock);
77 goto err3;
78 }
79
80 ep93xx_start_hc(&pdev->dev);
81
82 ohci_hcd_init(hcd_to_ohci(hcd));
83
84 retval = usb_add_hcd(hcd, pdev->resource[1].start, 0);
85 if (retval == 0)
86 return retval;
87
88 ep93xx_stop_hc(&pdev->dev);
89err3:
90 iounmap(hcd->regs);
91err2:
92 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
93err1:
94 usb_put_hcd(hcd);
95
96 return retval;
97}
98
99static void usb_hcd_ep93xx_remove(struct usb_hcd *hcd,
100 struct platform_device *pdev)
101{
102 usb_remove_hcd(hcd);
103 ep93xx_stop_hc(&pdev->dev);
104 clk_put(usb_host_clock);
105 iounmap(hcd->regs);
106 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
107 usb_put_hcd(hcd);
108}
109
110static int ohci_ep93xx_start(struct usb_hcd *hcd) 33static int ohci_ep93xx_start(struct usb_hcd *hcd)
111{ 34{
112 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 35 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
@@ -147,15 +70,57 @@ static struct hc_driver ohci_ep93xx_hc_driver = {
147 .start_port_reset = ohci_start_port_reset, 70 .start_port_reset = ohci_start_port_reset,
148}; 71};
149 72
150extern int usb_disabled(void);
151
152static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev) 73static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
153{ 74{
75 struct usb_hcd *hcd;
76 struct resource *res;
77 int irq;
154 int ret; 78 int ret;
155 79
156 ret = -ENODEV; 80 if (usb_disabled())
157 if (!usb_disabled()) 81 return -ENODEV;
158 ret = usb_hcd_ep93xx_probe(&ohci_ep93xx_hc_driver, pdev); 82
83 irq = platform_get_irq(pdev, 0);
84 if (irq < 0)
85 return irq;
86
87 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 if (!res)
89 return -ENXIO;
90
91 hcd = usb_create_hcd(&ohci_ep93xx_hc_driver, &pdev->dev, "ep93xx");
92 if (!hcd)
93 return -ENOMEM;
94
95 hcd->rsrc_start = res->start;
96 hcd->rsrc_len = resource_size(res);
97
98 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
99 if (IS_ERR(hcd->regs)) {
100 ret = PTR_ERR(hcd->regs);
101 goto err_put_hcd;
102 }
103
104 usb_host_clock = devm_clk_get(&pdev->dev, NULL);
105 if (IS_ERR(usb_host_clock)) {
106 ret = PTR_ERR(usb_host_clock);
107 goto err_put_hcd;
108 }
109
110 clk_enable(usb_host_clock);
111
112 ohci_hcd_init(hcd_to_ohci(hcd));
113
114 ret = usb_add_hcd(hcd, irq, 0);
115 if (ret)
116 goto err_clk_disable;
117
118 return 0;
119
120err_clk_disable:
121 clk_disable(usb_host_clock);
122err_put_hcd:
123 usb_put_hcd(hcd);
159 124
160 return ret; 125 return ret;
161} 126}
@@ -164,7 +129,9 @@ static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
164{ 129{
165 struct usb_hcd *hcd = platform_get_drvdata(pdev); 130 struct usb_hcd *hcd = platform_get_drvdata(pdev);
166 131
167 usb_hcd_ep93xx_remove(hcd, pdev); 132 usb_remove_hcd(hcd);
133 clk_disable(usb_host_clock);
134 usb_put_hcd(hcd);
168 135
169 return 0; 136 return 0;
170} 137}
@@ -179,7 +146,7 @@ static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_
179 msleep(5); 146 msleep(5);
180 ohci->next_statechange = jiffies; 147 ohci->next_statechange = jiffies;
181 148
182 ep93xx_stop_hc(&pdev->dev); 149 clk_disable(usb_host_clock);
183 return 0; 150 return 0;
184} 151}
185 152
@@ -192,7 +159,7 @@ static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
192 msleep(5); 159 msleep(5);
193 ohci->next_statechange = jiffies; 160 ohci->next_statechange = jiffies;
194 161
195 ep93xx_start_hc(&pdev->dev); 162 clk_enable(usb_host_clock);
196 163
197 ohci_resume(hcd, false); 164 ohci_resume(hcd, false);
198 return 0; 165 return 0;
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index b0b542c14e31..dc6ee9adacf5 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -100,7 +100,7 @@ static const struct hc_driver exynos_ohci_hc_driver = {
100 100
101static int exynos_ohci_probe(struct platform_device *pdev) 101static int exynos_ohci_probe(struct platform_device *pdev)
102{ 102{
103 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data; 103 struct exynos4_ohci_platdata *pdata = dev_get_platdata(&pdev->dev);
104 struct exynos_ohci_hcd *exynos_ohci; 104 struct exynos_ohci_hcd *exynos_ohci;
105 struct usb_hcd *hcd; 105 struct usb_hcd *hcd;
106 struct ohci_hcd *ohci; 106 struct ohci_hcd *ohci;
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index a9d3437da220..8f6b695af6a4 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -938,8 +938,8 @@ static void ohci_stop (struct usb_hcd *hcd)
938 if (quirk_nec(ohci)) 938 if (quirk_nec(ohci))
939 flush_work(&ohci->nec_work); 939 flush_work(&ohci->nec_work);
940 940
941 ohci_usb_reset (ohci);
942 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 941 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
942 ohci_usb_reset(ohci);
943 free_irq(hcd->irq, hcd); 943 free_irq(hcd->irq, hcd);
944 hcd->irq = 0; 944 hcd->irq = 0;
945 945
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 8747fa6a51b7..31d3a12eb486 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -191,7 +191,7 @@ static void start_hnp(struct ohci_hcd *ohci)
191static int ohci_omap_init(struct usb_hcd *hcd) 191static int ohci_omap_init(struct usb_hcd *hcd)
192{ 192{
193 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 193 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
194 struct omap_usb_config *config = hcd->self.controller->platform_data; 194 struct omap_usb_config *config = dev_get_platdata(hcd->self.controller);
195 int need_transceiver = (config->otg != 0); 195 int need_transceiver = (config->otg != 0);
196 int ret; 196 int ret;
197 197
@@ -427,7 +427,7 @@ ohci_omap_start (struct usb_hcd *hcd)
427 427
428 if (!host_enabled) 428 if (!host_enabled)
429 return 0; 429 return 0;
430 config = hcd->self.controller->platform_data; 430 config = dev_get_platdata(hcd->self.controller);
431 if (config->otg || config->rwc) { 431 if (config->otg || config->rwc) {
432 ohci->hc_control = OHCI_CTRL_RWC; 432 ohci->hc_control = OHCI_CTRL_RWC;
433 writel(OHCI_CTRL_RWC, &ohci->regs->control); 433 writel(OHCI_CTRL_RWC, &ohci->regs->control);
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c
index 8f713571a0b7..a09af26f69ed 100644
--- a/drivers/usb/host/ohci-omap3.c
+++ b/drivers/usb/host/ohci-omap3.c
@@ -231,14 +231,6 @@ static int ohci_hcd_omap3_remove(struct platform_device *pdev)
231 return 0; 231 return 0;
232} 232}
233 233
234static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
235{
236 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
237
238 if (hcd->driver->shutdown)
239 hcd->driver->shutdown(hcd);
240}
241
242static const struct of_device_id omap_ohci_dt_ids[] = { 234static const struct of_device_id omap_ohci_dt_ids[] = {
243 { .compatible = "ti,ohci-omap3" }, 235 { .compatible = "ti,ohci-omap3" },
244 { } 236 { }
@@ -249,7 +241,7 @@ MODULE_DEVICE_TABLE(of, omap_ohci_dt_ids);
249static struct platform_driver ohci_hcd_omap3_driver = { 241static struct platform_driver ohci_hcd_omap3_driver = {
250 .probe = ohci_hcd_omap3_probe, 242 .probe = ohci_hcd_omap3_probe,
251 .remove = ohci_hcd_omap3_remove, 243 .remove = ohci_hcd_omap3_remove,
252 .shutdown = ohci_hcd_omap3_shutdown, 244 .shutdown = usb_hcd_platform_shutdown,
253 .driver = { 245 .driver = {
254 .name = "ohci-omap3", 246 .name = "ohci-omap3",
255 .of_match_table = omap_ohci_dt_ids, 247 .of_match_table = omap_ohci_dt_ids,
diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
index bc30475c3a23..a4c6410f0ed4 100644
--- a/drivers/usb/host/ohci-platform.c
+++ b/drivers/usb/host/ohci-platform.c
@@ -33,7 +33,7 @@ static const char hcd_name[] = "ohci-platform";
33static int ohci_platform_reset(struct usb_hcd *hcd) 33static int ohci_platform_reset(struct usb_hcd *hcd)
34{ 34{
35 struct platform_device *pdev = to_platform_device(hcd->self.controller); 35 struct platform_device *pdev = to_platform_device(hcd->self.controller);
36 struct usb_ohci_pdata *pdata = pdev->dev.platform_data; 36 struct usb_ohci_pdata *pdata = dev_get_platdata(&pdev->dev);
37 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 37 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
38 38
39 if (pdata->big_endian_desc) 39 if (pdata->big_endian_desc)
@@ -59,7 +59,7 @@ static int ohci_platform_probe(struct platform_device *dev)
59{ 59{
60 struct usb_hcd *hcd; 60 struct usb_hcd *hcd;
61 struct resource *res_mem; 61 struct resource *res_mem;
62 struct usb_ohci_pdata *pdata = dev->dev.platform_data; 62 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
63 int irq; 63 int irq;
64 int err = -ENOMEM; 64 int err = -ENOMEM;
65 65
@@ -124,7 +124,7 @@ err_power:
124static int ohci_platform_remove(struct platform_device *dev) 124static int ohci_platform_remove(struct platform_device *dev)
125{ 125{
126 struct usb_hcd *hcd = platform_get_drvdata(dev); 126 struct usb_hcd *hcd = platform_get_drvdata(dev);
127 struct usb_ohci_pdata *pdata = dev->dev.platform_data; 127 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
128 128
129 usb_remove_hcd(hcd); 129 usb_remove_hcd(hcd);
130 usb_put_hcd(hcd); 130 usb_put_hcd(hcd);
@@ -139,7 +139,7 @@ static int ohci_platform_remove(struct platform_device *dev)
139 139
140static int ohci_platform_suspend(struct device *dev) 140static int ohci_platform_suspend(struct device *dev)
141{ 141{
142 struct usb_ohci_pdata *pdata = dev->platform_data; 142 struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
143 struct platform_device *pdev = 143 struct platform_device *pdev =
144 container_of(dev, struct platform_device, dev); 144 container_of(dev, struct platform_device, dev);
145 145
@@ -152,7 +152,7 @@ static int ohci_platform_suspend(struct device *dev)
152static int ohci_platform_resume(struct device *dev) 152static int ohci_platform_resume(struct device *dev)
153{ 153{
154 struct usb_hcd *hcd = dev_get_drvdata(dev); 154 struct usb_hcd *hcd = dev_get_drvdata(dev);
155 struct usb_ohci_pdata *pdata = dev->platform_data; 155 struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
156 struct platform_device *pdev = 156 struct platform_device *pdev =
157 container_of(dev, struct platform_device, dev); 157 container_of(dev, struct platform_device, dev);
158 158
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index 8294e2fcc2f6..75f5a1e2f01e 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -200,15 +200,6 @@ static int ohci_hcd_ppc_of_remove(struct platform_device *op)
200 return 0; 200 return 0;
201} 201}
202 202
203static void ohci_hcd_ppc_of_shutdown(struct platform_device *op)
204{
205 struct usb_hcd *hcd = platform_get_drvdata(op);
206
207 if (hcd->driver->shutdown)
208 hcd->driver->shutdown(hcd);
209}
210
211
212static const struct of_device_id ohci_hcd_ppc_of_match[] = { 203static const struct of_device_id ohci_hcd_ppc_of_match[] = {
213#ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE 204#ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE
214 { 205 {
@@ -243,7 +234,7 @@ MODULE_DEVICE_TABLE(of, ohci_hcd_ppc_of_match);
243static struct platform_driver ohci_hcd_ppc_of_driver = { 234static struct platform_driver ohci_hcd_ppc_of_driver = {
244 .probe = ohci_hcd_ppc_of_probe, 235 .probe = ohci_hcd_ppc_of_probe,
245 .remove = ohci_hcd_ppc_of_remove, 236 .remove = ohci_hcd_ppc_of_remove,
246 .shutdown = ohci_hcd_ppc_of_shutdown, 237 .shutdown = usb_hcd_platform_shutdown,
247 .driver = { 238 .driver = {
248 .name = "ppc-of-ohci", 239 .name = "ppc-of-ohci",
249 .owner = THIS_MODULE, 240 .owner = THIS_MODULE,
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index 3a9c01d8b79c..93371a235e82 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -219,7 +219,7 @@ static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev)
219 struct pxaohci_platform_data *inf; 219 struct pxaohci_platform_data *inf;
220 uint32_t uhchr; 220 uint32_t uhchr;
221 221
222 inf = dev->platform_data; 222 inf = dev_get_platdata(dev);
223 223
224 clk_prepare_enable(ohci->clk); 224 clk_prepare_enable(ohci->clk);
225 225
@@ -256,7 +256,7 @@ static void pxa27x_stop_hc(struct pxa27x_ohci *ohci, struct device *dev)
256 struct pxaohci_platform_data *inf; 256 struct pxaohci_platform_data *inf;
257 uint32_t uhccoms; 257 uint32_t uhccoms;
258 258
259 inf = dev->platform_data; 259 inf = dev_get_platdata(dev);
260 260
261 if (cpu_is_pxa3xx()) 261 if (cpu_is_pxa3xx())
262 pxa3xx_u2d_stop_hc(&ohci_to_hcd(&ohci->ohci)->self); 262 pxa3xx_u2d_stop_hc(&ohci_to_hcd(&ohci->ohci)->self);
@@ -364,7 +364,7 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
364 if (retval) 364 if (retval)
365 return retval; 365 return retval;
366 366
367 inf = pdev->dev.platform_data; 367 inf = dev_get_platdata(&pdev->dev);
368 368
369 if (!inf) 369 if (!inf)
370 return -ENODEV; 370 return -ENODEV;
@@ -577,7 +577,7 @@ static int ohci_hcd_pxa27x_drv_resume(struct device *dev)
577{ 577{
578 struct usb_hcd *hcd = dev_get_drvdata(dev); 578 struct usb_hcd *hcd = dev_get_drvdata(dev);
579 struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); 579 struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd);
580 struct pxaohci_platform_data *inf = dev->platform_data; 580 struct pxaohci_platform_data *inf = dev_get_platdata(dev);
581 int status; 581 int status;
582 582
583 if (time_before(jiffies, ohci->ohci.next_statechange)) 583 if (time_before(jiffies, ohci->ohci.next_statechange))
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index e125770b893c..4919afa4125e 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -38,12 +38,12 @@ static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
38 38
39static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd) 39static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd)
40{ 40{
41 return hcd->self.controller->platform_data; 41 return dev_get_platdata(hcd->self.controller);
42} 42}
43 43
44static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd) 44static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
45{ 45{
46 struct s3c2410_hcd_info *info = dev->dev.platform_data; 46 struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev);
47 47
48 dev_dbg(&dev->dev, "s3c2410_start_hc:\n"); 48 dev_dbg(&dev->dev, "s3c2410_start_hc:\n");
49 49
@@ -63,7 +63,7 @@ static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
63 63
64static void s3c2410_stop_hc(struct platform_device *dev) 64static void s3c2410_stop_hc(struct platform_device *dev)
65{ 65{
66 struct s3c2410_hcd_info *info = dev->dev.platform_data; 66 struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev);
67 67
68 dev_dbg(&dev->dev, "s3c2410_stop_hc:\n"); 68 dev_dbg(&dev->dev, "s3c2410_stop_hc:\n");
69 69
@@ -339,10 +339,11 @@ static int usb_hcd_s3c2410_probe(const struct hc_driver *driver,
339 struct platform_device *dev) 339 struct platform_device *dev)
340{ 340{
341 struct usb_hcd *hcd = NULL; 341 struct usb_hcd *hcd = NULL;
342 struct s3c2410_hcd_info *info = dev_get_platdata(&dev->dev);
342 int retval; 343 int retval;
343 344
344 s3c2410_usb_set_power(dev->dev.platform_data, 1, 1); 345 s3c2410_usb_set_power(info, 1, 1);
345 s3c2410_usb_set_power(dev->dev.platform_data, 2, 1); 346 s3c2410_usb_set_power(info, 2, 1);
346 347
347 hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx"); 348 hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx");
348 if (hcd == NULL) 349 if (hcd == NULL)
diff --git a/drivers/usb/host/ohci-tilegx.c b/drivers/usb/host/ohci-tilegx.c
index 197d514fe0d1..22540ab71f55 100644
--- a/drivers/usb/host/ohci-tilegx.c
+++ b/drivers/usb/host/ohci-tilegx.c
@@ -95,7 +95,7 @@ static const struct hc_driver ohci_tilegx_hc_driver = {
95static int ohci_hcd_tilegx_drv_probe(struct platform_device *pdev) 95static int ohci_hcd_tilegx_drv_probe(struct platform_device *pdev)
96{ 96{
97 struct usb_hcd *hcd; 97 struct usb_hcd *hcd;
98 struct tilegx_usb_platform_data *pdata = pdev->dev.platform_data; 98 struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
99 pte_t pte = { 0 }; 99 pte_t pte = { 0 };
100 int my_cpu = smp_processor_id(); 100 int my_cpu = smp_processor_id();
101 int ret; 101 int ret;
@@ -175,7 +175,7 @@ err_hcd:
175static int ohci_hcd_tilegx_drv_remove(struct platform_device *pdev) 175static int ohci_hcd_tilegx_drv_remove(struct platform_device *pdev)
176{ 176{
177 struct usb_hcd *hcd = platform_get_drvdata(pdev); 177 struct usb_hcd *hcd = platform_get_drvdata(pdev);
178 struct tilegx_usb_platform_data* pdata = pdev->dev.platform_data; 178 struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
179 179
180 usb_remove_hcd(hcd); 180 usb_remove_hcd(hcd);
181 usb_put_hcd(hcd); 181 usb_put_hcd(hcd);
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index b9848e4d3d44..2c76ef1320ea 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -735,32 +735,6 @@ static int handshake(void __iomem *ptr, u32 mask, u32 done,
735 return -ETIMEDOUT; 735 return -ETIMEDOUT;
736} 736}
737 737
738#define PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI 0x8C31
739#define PCI_DEVICE_ID_INTEL_LYNX_POINT_LP_XHCI 0x9C31
740
741bool usb_is_intel_ppt_switchable_xhci(struct pci_dev *pdev)
742{
743 return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
744 pdev->vendor == PCI_VENDOR_ID_INTEL &&
745 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI;
746}
747
748/* The Intel Lynx Point chipset also has switchable ports. */
749bool usb_is_intel_lpt_switchable_xhci(struct pci_dev *pdev)
750{
751 return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
752 pdev->vendor == PCI_VENDOR_ID_INTEL &&
753 (pdev->device == PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI ||
754 pdev->device == PCI_DEVICE_ID_INTEL_LYNX_POINT_LP_XHCI);
755}
756
757bool usb_is_intel_switchable_xhci(struct pci_dev *pdev)
758{
759 return usb_is_intel_ppt_switchable_xhci(pdev) ||
760 usb_is_intel_lpt_switchable_xhci(pdev);
761}
762EXPORT_SYMBOL_GPL(usb_is_intel_switchable_xhci);
763
764/* 738/*
765 * Intel's Panther Point chipset has two host controllers (EHCI and xHCI) that 739 * Intel's Panther Point chipset has two host controllers (EHCI and xHCI) that
766 * share some number of ports. These ports can be switched between either 740 * share some number of ports. These ports can be switched between either
@@ -779,9 +753,23 @@ EXPORT_SYMBOL_GPL(usb_is_intel_switchable_xhci);
779 * terminations before switching the USB 2.0 wires over, so that USB 3.0 753 * terminations before switching the USB 2.0 wires over, so that USB 3.0
780 * devices connect at SuperSpeed, rather than at USB 2.0 speeds. 754 * devices connect at SuperSpeed, rather than at USB 2.0 speeds.
781 */ 755 */
782void usb_enable_xhci_ports(struct pci_dev *xhci_pdev) 756void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev)
783{ 757{
784 u32 ports_available; 758 u32 ports_available;
759 bool ehci_found = false;
760 struct pci_dev *companion = NULL;
761
762 /* make sure an intel EHCI controller exists */
763 for_each_pci_dev(companion) {
764 if (companion->class == PCI_CLASS_SERIAL_USB_EHCI &&
765 companion->vendor == PCI_VENDOR_ID_INTEL) {
766 ehci_found = true;
767 break;
768 }
769 }
770
771 if (!ehci_found)
772 return;
785 773
786 /* Don't switchover the ports if the user hasn't compiled the xHCI 774 /* Don't switchover the ports if the user hasn't compiled the xHCI
787 * driver. Otherwise they will see "dead" USB ports that don't power 775 * driver. Otherwise they will see "dead" USB ports that don't power
@@ -840,7 +828,7 @@ void usb_enable_xhci_ports(struct pci_dev *xhci_pdev)
840 dev_dbg(&xhci_pdev->dev, "USB 2.0 ports that are now switched over " 828 dev_dbg(&xhci_pdev->dev, "USB 2.0 ports that are now switched over "
841 "to xHCI: 0x%x\n", ports_available); 829 "to xHCI: 0x%x\n", ports_available);
842} 830}
843EXPORT_SYMBOL_GPL(usb_enable_xhci_ports); 831EXPORT_SYMBOL_GPL(usb_enable_intel_xhci_ports);
844 832
845void usb_disable_xhci_ports(struct pci_dev *xhci_pdev) 833void usb_disable_xhci_ports(struct pci_dev *xhci_pdev)
846{ 834{
@@ -921,8 +909,8 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
921 writel(val, base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET); 909 writel(val, base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET);
922 910
923hc_init: 911hc_init:
924 if (usb_is_intel_switchable_xhci(pdev)) 912 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
925 usb_enable_xhci_ports(pdev); 913 usb_enable_intel_xhci_ports(pdev);
926 914
927 op_reg_base = base + XHCI_HC_LENGTH(readl(base)); 915 op_reg_base = base + XHCI_HC_LENGTH(readl(base));
928 916
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h
index 978c849f9c9a..ed6700d00fe6 100644
--- a/drivers/usb/host/pci-quirks.h
+++ b/drivers/usb/host/pci-quirks.h
@@ -8,8 +8,7 @@ int usb_amd_find_chipset_info(void);
8void usb_amd_dev_put(void); 8void usb_amd_dev_put(void);
9void usb_amd_quirk_pll_disable(void); 9void usb_amd_quirk_pll_disable(void);
10void usb_amd_quirk_pll_enable(void); 10void usb_amd_quirk_pll_enable(void);
11bool usb_is_intel_switchable_xhci(struct pci_dev *pdev); 11void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev);
12void usb_enable_xhci_ports(struct pci_dev *xhci_pdev);
13void usb_disable_xhci_ports(struct pci_dev *xhci_pdev); 12void usb_disable_xhci_ports(struct pci_dev *xhci_pdev);
14void sb800_prefetch(struct device *dev, int on); 13void sb800_prefetch(struct device *dev, int on);
15#else 14#else
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index a6fd8f5371df..a9eef6822a24 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -2467,7 +2467,7 @@ static int r8a66597_probe(struct platform_device *pdev)
2467 r8a66597 = hcd_to_r8a66597(hcd); 2467 r8a66597 = hcd_to_r8a66597(hcd);
2468 memset(r8a66597, 0, sizeof(struct r8a66597)); 2468 memset(r8a66597, 0, sizeof(struct r8a66597));
2469 dev_set_drvdata(&pdev->dev, r8a66597); 2469 dev_set_drvdata(&pdev->dev, r8a66597);
2470 r8a66597->pdata = pdev->dev.platform_data; 2470 r8a66597->pdata = dev_get_platdata(&pdev->dev);
2471 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; 2471 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
2472 2472
2473 if (r8a66597->pdata->on_chip) { 2473 if (r8a66597->pdata->on_chip) {
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index b2ec7fe758dd..5477bf5df218 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -48,6 +48,8 @@
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#include <linux/prefetch.h>
51#include <linux/debugfs.h>
52#include <linux/seq_file.h>
51 53
52#include <asm/io.h> 54#include <asm/io.h>
53#include <asm/irq.h> 55#include <asm/irq.h>
@@ -63,11 +65,6 @@ MODULE_ALIAS("platform:sl811-hcd");
63 65
64#define DRIVER_VERSION "19 May 2005" 66#define DRIVER_VERSION "19 May 2005"
65 67
66
67#ifndef DEBUG
68# define STUB_DEBUG_FILE
69#endif
70
71/* for now, use only one transfer register bank */ 68/* for now, use only one transfer register bank */
72#undef USE_B 69#undef USE_B
73 70
@@ -100,7 +97,8 @@ static void port_power(struct sl811 *sl811, int is_on)
100 97
101 if (sl811->board && sl811->board->port_power) { 98 if (sl811->board && sl811->board->port_power) {
102 /* switch VBUS, at 500mA unless hub power budget gets set */ 99 /* switch VBUS, at 500mA unless hub power budget gets set */
103 DBG("power %s\n", is_on ? "on" : "off"); 100 dev_dbg(hcd->self.controller, "power %s\n",
101 is_on ? "on" : "off");
104 sl811->board->port_power(hcd->self.controller, is_on); 102 sl811->board->port_power(hcd->self.controller, is_on);
105 } 103 }
106 104
@@ -282,7 +280,7 @@ static inline void sofirq_on(struct sl811 *sl811)
282{ 280{
283 if (sl811->irq_enable & SL11H_INTMASK_SOFINTR) 281 if (sl811->irq_enable & SL11H_INTMASK_SOFINTR)
284 return; 282 return;
285 VDBG("sof irq on\n"); 283 dev_dbg(sl811_to_hcd(sl811)->self.controller, "sof irq on\n");
286 sl811->irq_enable |= SL11H_INTMASK_SOFINTR; 284 sl811->irq_enable |= SL11H_INTMASK_SOFINTR;
287} 285}
288 286
@@ -290,7 +288,7 @@ static inline void sofirq_off(struct sl811 *sl811)
290{ 288{
291 if (!(sl811->irq_enable & SL11H_INTMASK_SOFINTR)) 289 if (!(sl811->irq_enable & SL11H_INTMASK_SOFINTR))
292 return; 290 return;
293 VDBG("sof irq off\n"); 291 dev_dbg(sl811_to_hcd(sl811)->self.controller, "sof irq off\n");
294 sl811->irq_enable &= ~SL11H_INTMASK_SOFINTR; 292 sl811->irq_enable &= ~SL11H_INTMASK_SOFINTR;
295} 293}
296 294
@@ -338,7 +336,8 @@ static struct sl811h_ep *start(struct sl811 *sl811, u8 bank)
338 } 336 }
339 337
340 if (unlikely(list_empty(&ep->hep->urb_list))) { 338 if (unlikely(list_empty(&ep->hep->urb_list))) {
341 DBG("empty %p queue?\n", ep); 339 dev_dbg(sl811_to_hcd(sl811)->self.controller,
340 "empty %p queue?\n", ep);
342 return NULL; 341 return NULL;
343 } 342 }
344 343
@@ -391,7 +390,8 @@ static struct sl811h_ep *start(struct sl811 *sl811, u8 bank)
391 status_packet(sl811, ep, urb, bank, control); 390 status_packet(sl811, ep, urb, bank, control);
392 break; 391 break;
393 default: 392 default:
394 DBG("bad ep%p pid %02x\n", ep, ep->nextpid); 393 dev_dbg(sl811_to_hcd(sl811)->self.controller,
394 "bad ep%p pid %02x\n", ep, ep->nextpid);
395 ep = NULL; 395 ep = NULL;
396 } 396 }
397 return ep; 397 return ep;
@@ -447,7 +447,8 @@ static void finish_request(
447 } 447 }
448 448
449 /* periodic deschedule */ 449 /* periodic deschedule */
450 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch); 450 dev_dbg(sl811_to_hcd(sl811)->self.controller,
451 "deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
451 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) { 452 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
452 struct sl811h_ep *temp; 453 struct sl811h_ep *temp;
453 struct sl811h_ep **prev = &sl811->periodic[i]; 454 struct sl811h_ep **prev = &sl811->periodic[i];
@@ -593,7 +594,8 @@ static inline u8 checkdone(struct sl811 *sl811)
593 ctl = sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG)); 594 ctl = sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG));
594 if (ctl & SL11H_HCTLMASK_ARM) 595 if (ctl & SL11H_HCTLMASK_ARM)
595 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0); 596 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0);
596 DBG("%s DONE_A: ctrl %02x sts %02x\n", 597 dev_dbg(sl811_to_hcd(sl811)->self.controller,
598 "%s DONE_A: ctrl %02x sts %02x\n",
597 (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost", 599 (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
598 ctl, 600 ctl,
599 sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG))); 601 sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
@@ -604,7 +606,8 @@ static inline u8 checkdone(struct sl811 *sl811)
604 ctl = sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG)); 606 ctl = sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG));
605 if (ctl & SL11H_HCTLMASK_ARM) 607 if (ctl & SL11H_HCTLMASK_ARM)
606 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0); 608 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0);
607 DBG("%s DONE_B: ctrl %02x sts %02x\n", 609 dev_dbg(sl811_to_hcd(sl811)->self.controller,
610 "%s DONE_B: ctrl %02x sts %02x\n",
608 (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost", 611 (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
609 ctl, 612 ctl,
610 sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG))); 613 sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
@@ -665,7 +668,7 @@ retry:
665 * this one has nothing scheduled. 668 * this one has nothing scheduled.
666 */ 669 */
667 if (sl811->next_periodic) { 670 if (sl811->next_periodic) {
668 // ERR("overrun to slot %d\n", index); 671 // dev_err(hcd->self.controller, "overrun to slot %d\n", index);
669 sl811->stat_overrun++; 672 sl811->stat_overrun++;
670 } 673 }
671 if (sl811->periodic[index]) 674 if (sl811->periodic[index])
@@ -723,7 +726,7 @@ retry:
723 726
724 } else if (irqstat & SL11H_INTMASK_RD) { 727 } else if (irqstat & SL11H_INTMASK_RD) {
725 if (sl811->port1 & USB_PORT_STAT_SUSPEND) { 728 if (sl811->port1 & USB_PORT_STAT_SUSPEND) {
726 DBG("wakeup\n"); 729 dev_dbg(hcd->self.controller, "wakeup\n");
727 sl811->port1 |= USB_PORT_STAT_C_SUSPEND << 16; 730 sl811->port1 |= USB_PORT_STAT_C_SUSPEND << 16;
728 sl811->stat_wake++; 731 sl811->stat_wake++;
729 } else 732 } else
@@ -852,8 +855,9 @@ static int sl811h_urb_enqueue(
852 855
853 if (ep->maxpacket > H_MAXPACKET) { 856 if (ep->maxpacket > H_MAXPACKET) {
854 /* iso packets up to 240 bytes could work... */ 857 /* iso packets up to 240 bytes could work... */
855 DBG("dev %d ep%d maxpacket %d\n", 858 dev_dbg(hcd->self.controller,
856 udev->devnum, epnum, ep->maxpacket); 859 "dev %d ep%d maxpacket %d\n", udev->devnum,
860 epnum, ep->maxpacket);
857 retval = -EINVAL; 861 retval = -EINVAL;
858 kfree(ep); 862 kfree(ep);
859 goto fail; 863 goto fail;
@@ -917,7 +921,8 @@ static int sl811h_urb_enqueue(
917 * to share the faster parts of the tree without needing 921 * to share the faster parts of the tree without needing
918 * dummy/placeholder nodes 922 * dummy/placeholder nodes
919 */ 923 */
920 DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch); 924 dev_dbg(hcd->self.controller, "schedule qh%d/%p branch %d\n",
925 ep->period, ep, ep->branch);
921 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) { 926 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
922 struct sl811h_ep **prev = &sl811->periodic[i]; 927 struct sl811h_ep **prev = &sl811->periodic[i];
923 struct sl811h_ep *here = *prev; 928 struct sl811h_ep *here = *prev;
@@ -976,7 +981,8 @@ static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
976 } else if (sl811->active_a == ep) { 981 } else if (sl811->active_a == ep) {
977 if (time_before_eq(sl811->jiffies_a, jiffies)) { 982 if (time_before_eq(sl811->jiffies_a, jiffies)) {
978 /* happens a lot with lowspeed?? */ 983 /* happens a lot with lowspeed?? */
979 DBG("giveup on DONE_A: ctrl %02x sts %02x\n", 984 dev_dbg(hcd->self.controller,
985 "giveup on DONE_A: ctrl %02x sts %02x\n",
980 sl811_read(sl811, 986 sl811_read(sl811,
981 SL811_EP_A(SL11H_HOSTCTLREG)), 987 SL811_EP_A(SL11H_HOSTCTLREG)),
982 sl811_read(sl811, 988 sl811_read(sl811,
@@ -990,7 +996,8 @@ static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
990 } else if (sl811->active_b == ep) { 996 } else if (sl811->active_b == ep) {
991 if (time_before_eq(sl811->jiffies_a, jiffies)) { 997 if (time_before_eq(sl811->jiffies_a, jiffies)) {
992 /* happens a lot with lowspeed?? */ 998 /* happens a lot with lowspeed?? */
993 DBG("giveup on DONE_B: ctrl %02x sts %02x\n", 999 dev_dbg(hcd->self.controller,
1000 "giveup on DONE_B: ctrl %02x sts %02x\n",
994 sl811_read(sl811, 1001 sl811_read(sl811,
995 SL811_EP_B(SL11H_HOSTCTLREG)), 1002 SL811_EP_B(SL11H_HOSTCTLREG)),
996 sl811_read(sl811, 1003 sl811_read(sl811,
@@ -1008,7 +1015,8 @@ static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1008 if (urb) 1015 if (urb)
1009 finish_request(sl811, ep, urb, 0); 1016 finish_request(sl811, ep, urb, 0);
1010 else 1017 else
1011 VDBG("dequeue, urb %p active %s; wait4irq\n", urb, 1018 dev_dbg(sl811_to_hcd(sl811)->self.controller,
1019 "dequeue, urb %p active %s; wait4irq\n", urb,
1012 (sl811->active_a == ep) ? "A" : "B"); 1020 (sl811->active_a == ep) ? "A" : "B");
1013 } else 1021 } else
1014 retval = -EINVAL; 1022 retval = -EINVAL;
@@ -1029,7 +1037,7 @@ sl811h_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
1029 if (!list_empty(&hep->urb_list)) 1037 if (!list_empty(&hep->urb_list))
1030 msleep(3); 1038 msleep(3);
1031 if (!list_empty(&hep->urb_list)) 1039 if (!list_empty(&hep->urb_list))
1032 WARNING("ep %p not empty?\n", ep); 1040 dev_warn(hcd->self.controller, "ep %p not empty?\n", ep);
1033 1041
1034 kfree(ep); 1042 kfree(ep);
1035 hep->hcpriv = NULL; 1043 hep->hcpriv = NULL;
@@ -1132,7 +1140,7 @@ sl811h_timer(unsigned long _sl811)
1132 1140
1133 switch (signaling) { 1141 switch (signaling) {
1134 case SL11H_CTL1MASK_SE0: 1142 case SL11H_CTL1MASK_SE0:
1135 DBG("end reset\n"); 1143 dev_dbg(sl811_to_hcd(sl811)->self.controller, "end reset\n");
1136 sl811->port1 = (USB_PORT_STAT_C_RESET << 16) 1144 sl811->port1 = (USB_PORT_STAT_C_RESET << 16)
1137 | USB_PORT_STAT_POWER; 1145 | USB_PORT_STAT_POWER;
1138 sl811->ctrl1 = 0; 1146 sl811->ctrl1 = 0;
@@ -1141,11 +1149,12 @@ sl811h_timer(unsigned long _sl811)
1141 irqstat &= ~SL11H_INTMASK_RD; 1149 irqstat &= ~SL11H_INTMASK_RD;
1142 break; 1150 break;
1143 case SL11H_CTL1MASK_K: 1151 case SL11H_CTL1MASK_K:
1144 DBG("end resume\n"); 1152 dev_dbg(sl811_to_hcd(sl811)->self.controller, "end resume\n");
1145 sl811->port1 &= ~USB_PORT_STAT_SUSPEND; 1153 sl811->port1 &= ~USB_PORT_STAT_SUSPEND;
1146 break; 1154 break;
1147 default: 1155 default:
1148 DBG("odd timer signaling: %02x\n", signaling); 1156 dev_dbg(sl811_to_hcd(sl811)->self.controller,
1157 "odd timer signaling: %02x\n", signaling);
1149 break; 1158 break;
1150 } 1159 }
1151 sl811_write(sl811, SL11H_IRQ_STATUS, irqstat); 1160 sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
@@ -1243,7 +1252,7 @@ sl811h_hub_control(
1243 break; 1252 break;
1244 1253
1245 /* 20 msec of resume/K signaling, other irqs blocked */ 1254 /* 20 msec of resume/K signaling, other irqs blocked */
1246 DBG("start resume...\n"); 1255 dev_dbg(hcd->self.controller, "start resume...\n");
1247 sl811->irq_enable = 0; 1256 sl811->irq_enable = 0;
1248 sl811_write(sl811, SL11H_IRQ_ENABLE, 1257 sl811_write(sl811, SL11H_IRQ_ENABLE,
1249 sl811->irq_enable); 1258 sl811->irq_enable);
@@ -1281,7 +1290,8 @@ sl811h_hub_control(
1281#ifndef VERBOSE 1290#ifndef VERBOSE
1282 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */ 1291 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
1283#endif 1292#endif
1284 DBG("GetPortStatus %08x\n", sl811->port1); 1293 dev_dbg(hcd->self.controller, "GetPortStatus %08x\n",
1294 sl811->port1);
1285 break; 1295 break;
1286 case SetPortFeature: 1296 case SetPortFeature:
1287 if (wIndex != 1 || wLength != 0) 1297 if (wIndex != 1 || wLength != 0)
@@ -1293,7 +1303,7 @@ sl811h_hub_control(
1293 if (!(sl811->port1 & USB_PORT_STAT_ENABLE)) 1303 if (!(sl811->port1 & USB_PORT_STAT_ENABLE))
1294 goto error; 1304 goto error;
1295 1305
1296 DBG("suspend...\n"); 1306 dev_dbg(hcd->self.controller,"suspend...\n");
1297 sl811->ctrl1 &= ~SL11H_CTL1MASK_SOF_ENA; 1307 sl811->ctrl1 &= ~SL11H_CTL1MASK_SOF_ENA;
1298 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1); 1308 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1299 break; 1309 break;
@@ -1338,7 +1348,7 @@ static int
1338sl811h_bus_suspend(struct usb_hcd *hcd) 1348sl811h_bus_suspend(struct usb_hcd *hcd)
1339{ 1349{
1340 // SOFs off 1350 // SOFs off
1341 DBG("%s\n", __func__); 1351 dev_dbg(hcd->self.controller, "%s\n", __func__);
1342 return 0; 1352 return 0;
1343} 1353}
1344 1354
@@ -1346,7 +1356,7 @@ static int
1346sl811h_bus_resume(struct usb_hcd *hcd) 1356sl811h_bus_resume(struct usb_hcd *hcd)
1347{ 1357{
1348 // SOFs on 1358 // SOFs on
1349 DBG("%s\n", __func__); 1359 dev_dbg(hcd->self.controller, "%s\n", __func__);
1350 return 0; 1360 return 0;
1351} 1361}
1352 1362
@@ -1360,16 +1370,6 @@ sl811h_bus_resume(struct usb_hcd *hcd)
1360 1370
1361/*-------------------------------------------------------------------------*/ 1371/*-------------------------------------------------------------------------*/
1362 1372
1363#ifdef STUB_DEBUG_FILE
1364
1365static inline void create_debug_file(struct sl811 *sl811) { }
1366static inline void remove_debug_file(struct sl811 *sl811) { }
1367
1368#else
1369
1370#include <linux/proc_fs.h>
1371#include <linux/seq_file.h>
1372
1373static void dump_irq(struct seq_file *s, char *label, u8 mask) 1373static void dump_irq(struct seq_file *s, char *label, u8 mask)
1374{ 1374{
1375 seq_printf(s, "%s %02x%s%s%s%s%s%s\n", label, mask, 1375 seq_printf(s, "%s %02x%s%s%s%s%s%s\n", label, mask,
@@ -1381,7 +1381,7 @@ static void dump_irq(struct seq_file *s, char *label, u8 mask)
1381 (mask & SL11H_INTMASK_DP) ? " dp" : ""); 1381 (mask & SL11H_INTMASK_DP) ? " dp" : "");
1382} 1382}
1383 1383
1384static int proc_sl811h_show(struct seq_file *s, void *unused) 1384static int sl811h_show(struct seq_file *s, void *unused)
1385{ 1385{
1386 struct sl811 *sl811 = s->private; 1386 struct sl811 *sl811 = s->private;
1387 struct sl811h_ep *ep; 1387 struct sl811h_ep *ep;
@@ -1492,34 +1492,31 @@ static int proc_sl811h_show(struct seq_file *s, void *unused)
1492 return 0; 1492 return 0;
1493} 1493}
1494 1494
1495static int proc_sl811h_open(struct inode *inode, struct file *file) 1495static int sl811h_open(struct inode *inode, struct file *file)
1496{ 1496{
1497 return single_open(file, proc_sl811h_show, PDE_DATA(inode)); 1497 return single_open(file, sl811h_show, inode->i_private);
1498} 1498}
1499 1499
1500static const struct file_operations proc_ops = { 1500static const struct file_operations debug_ops = {
1501 .open = proc_sl811h_open, 1501 .open = sl811h_open,
1502 .read = seq_read, 1502 .read = seq_read,
1503 .llseek = seq_lseek, 1503 .llseek = seq_lseek,
1504 .release = single_release, 1504 .release = single_release,
1505}; 1505};
1506 1506
1507/* expect just one sl811 per system */ 1507/* expect just one sl811 per system */
1508static const char proc_filename[] = "driver/sl811h";
1509
1510static void create_debug_file(struct sl811 *sl811) 1508static void create_debug_file(struct sl811 *sl811)
1511{ 1509{
1512 sl811->pde = proc_create_data(proc_filename, 0, NULL, &proc_ops, sl811); 1510 sl811->debug_file = debugfs_create_file("sl811h", S_IRUGO,
1511 usb_debug_root, sl811,
1512 &debug_ops);
1513} 1513}
1514 1514
1515static void remove_debug_file(struct sl811 *sl811) 1515static void remove_debug_file(struct sl811 *sl811)
1516{ 1516{
1517 if (sl811->pde) 1517 debugfs_remove(sl811->debug_file);
1518 remove_proc_entry(proc_filename, NULL);
1519} 1518}
1520 1519
1521#endif
1522
1523/*-------------------------------------------------------------------------*/ 1520/*-------------------------------------------------------------------------*/
1524 1521
1525static void 1522static void
@@ -1648,7 +1645,7 @@ sl811h_probe(struct platform_device *dev)
1648 1645
1649 /* refuse to confuse usbcore */ 1646 /* refuse to confuse usbcore */
1650 if (dev->dev.dma_mask) { 1647 if (dev->dev.dma_mask) {
1651 DBG("no we won't dma\n"); 1648 dev_dbg(&dev->dev, "no we won't dma\n");
1652 return -EINVAL; 1649 return -EINVAL;
1653 } 1650 }
1654 1651
@@ -1694,7 +1691,7 @@ sl811h_probe(struct platform_device *dev)
1694 1691
1695 spin_lock_init(&sl811->lock); 1692 spin_lock_init(&sl811->lock);
1696 INIT_LIST_HEAD(&sl811->async); 1693 INIT_LIST_HEAD(&sl811->async);
1697 sl811->board = dev->dev.platform_data; 1694 sl811->board = dev_get_platdata(&dev->dev);
1698 init_timer(&sl811->timer); 1695 init_timer(&sl811->timer);
1699 sl811->timer.function = sl811h_timer; 1696 sl811->timer.function = sl811h_timer;
1700 sl811->timer.data = (unsigned long) sl811; 1697 sl811->timer.data = (unsigned long) sl811;
@@ -1716,7 +1713,7 @@ sl811h_probe(struct platform_device *dev)
1716 break; 1713 break;
1717 default: 1714 default:
1718 /* reject case 0, SL11S is less functional */ 1715 /* reject case 0, SL11S is less functional */
1719 DBG("chiprev %02x\n", tmp); 1716 dev_dbg(&dev->dev, "chiprev %02x\n", tmp);
1720 retval = -ENXIO; 1717 retval = -ENXIO;
1721 goto err6; 1718 goto err6;
1722 } 1719 }
@@ -1747,7 +1744,7 @@ sl811h_probe(struct platform_device *dev)
1747 if (!ioaddr) 1744 if (!ioaddr)
1748 iounmap(addr_reg); 1745 iounmap(addr_reg);
1749 err2: 1746 err2:
1750 DBG("init error, %d\n", retval); 1747 dev_dbg(&dev->dev, "init error, %d\n", retval);
1751 return retval; 1748 return retval;
1752} 1749}
1753 1750
diff --git a/drivers/usb/host/sl811.h b/drivers/usb/host/sl811.h
index b6b8c1f233dd..1e23ef49bec1 100644
--- a/drivers/usb/host/sl811.h
+++ b/drivers/usb/host/sl811.h
@@ -122,7 +122,7 @@ struct sl811 {
122 void __iomem *addr_reg; 122 void __iomem *addr_reg;
123 void __iomem *data_reg; 123 void __iomem *data_reg;
124 struct sl811_platform_data *board; 124 struct sl811_platform_data *board;
125 struct proc_dir_entry *pde; 125 struct dentry *debug_file;
126 126
127 unsigned long stat_insrmv; 127 unsigned long stat_insrmv;
128 unsigned long stat_wake; 128 unsigned long stat_wake;
@@ -242,25 +242,8 @@ sl811_read_buf(struct sl811 *sl811, int addr, void *buf, size_t count)
242 242
243/*-------------------------------------------------------------------------*/ 243/*-------------------------------------------------------------------------*/
244 244
245#ifdef DEBUG
246#define DBG(stuff...) printk(KERN_DEBUG "sl811: " stuff)
247#else
248#define DBG(stuff...) do{}while(0)
249#endif
250
251#ifdef VERBOSE
252# define VDBG DBG
253#else
254# define VDBG(stuff...) do{}while(0)
255#endif
256
257#ifdef PACKET_TRACE 245#ifdef PACKET_TRACE
258# define PACKET VDBG 246# define PACKET pr_debug("sl811: "stuff)
259#else 247#else
260# define PACKET(stuff...) do{}while(0) 248# define PACKET(stuff...) do{}while(0)
261#endif 249#endif
262
263#define ERR(stuff...) printk(KERN_ERR "sl811: " stuff)
264#define WARNING(stuff...) printk(KERN_WARNING "sl811: " stuff)
265#define INFO(stuff...) printk(KERN_INFO "sl811: " stuff)
266
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 5c124bf5d018..e402beb5a069 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -1809,9 +1809,9 @@ static int u132_hcd_start(struct usb_hcd *hcd)
1809 struct platform_device *pdev = 1809 struct platform_device *pdev =
1810 to_platform_device(hcd->self.controller); 1810 to_platform_device(hcd->self.controller);
1811 u16 vendor = ((struct u132_platform_data *) 1811 u16 vendor = ((struct u132_platform_data *)
1812 (pdev->dev.platform_data))->vendor; 1812 dev_get_platdata(&pdev->dev))->vendor;
1813 u16 device = ((struct u132_platform_data *) 1813 u16 device = ((struct u132_platform_data *)
1814 (pdev->dev.platform_data))->device; 1814 dev_get_platdata(&pdev->dev))->device;
1815 mutex_lock(&u132->sw_lock); 1815 mutex_lock(&u132->sw_lock);
1816 msleep(10); 1816 msleep(10);
1817 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) { 1817 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
@@ -3034,7 +3034,7 @@ static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3034 int addrs = MAX_U132_ADDRS; 3034 int addrs = MAX_U132_ADDRS;
3035 int udevs = MAX_U132_UDEVS; 3035 int udevs = MAX_U132_UDEVS;
3036 int endps = MAX_U132_ENDPS; 3036 int endps = MAX_U132_ENDPS;
3037 u132->board = pdev->dev.platform_data; 3037 u132->board = dev_get_platdata(&pdev->dev);
3038 u132->platform_dev = pdev; 3038 u132->platform_dev = pdev;
3039 u132->power = 0; 3039 u132->power = 0;
3040 u132->reset = 0; 3040 u132->reset = 0;
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index 5d5e58fdeccc..73503a81ee81 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -580,3 +580,17 @@ void xhci_dbg_ctx(struct xhci_hcd *xhci,
580 xhci_dbg_slot_ctx(xhci, ctx); 580 xhci_dbg_slot_ctx(xhci, ctx);
581 xhci_dbg_ep_ctx(xhci, ctx, last_ep); 581 xhci_dbg_ep_ctx(xhci, ctx, last_ep);
582} 582}
583
584void xhci_dbg_trace(struct xhci_hcd *xhci, void (*trace)(struct va_format *),
585 const char *fmt, ...)
586{
587 struct va_format vaf;
588 va_list args;
589
590 va_start(args, fmt);
591 vaf.fmt = fmt;
592 vaf.va = &args;
593 xhci_dbg(xhci, "%pV\n", &vaf);
594 trace(&vaf);
595 va_end(args);
596}
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 1d3545943c50..fae697ed0b70 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -24,6 +24,7 @@
24#include <asm/unaligned.h> 24#include <asm/unaligned.h>
25 25
26#include "xhci.h" 26#include "xhci.h"
27#include "xhci-trace.h"
27 28
28#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E) 29#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E)
29#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ 30#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
@@ -461,8 +462,15 @@ void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array,
461 } 462 }
462} 463}
463 464
465/* Updates Link Status for USB 2.1 port */
466static void xhci_hub_report_usb2_link_state(u32 *status, u32 status_reg)
467{
468 if ((status_reg & PORT_PLS_MASK) == XDEV_U2)
469 *status |= USB_PORT_STAT_L1;
470}
471
464/* Updates Link Status for super Speed port */ 472/* Updates Link Status for super Speed port */
465static void xhci_hub_report_link_state(u32 *status, u32 status_reg) 473static void xhci_hub_report_usb3_link_state(u32 *status, u32 status_reg)
466{ 474{
467 u32 pls = status_reg & PORT_PLS_MASK; 475 u32 pls = status_reg & PORT_PLS_MASK;
468 476
@@ -528,12 +536,128 @@ void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status, u16 wIndex)
528 xhci->port_status_u0 |= 1 << wIndex; 536 xhci->port_status_u0 |= 1 << wIndex;
529 if (xhci->port_status_u0 == all_ports_seen_u0) { 537 if (xhci->port_status_u0 == all_ports_seen_u0) {
530 del_timer_sync(&xhci->comp_mode_recovery_timer); 538 del_timer_sync(&xhci->comp_mode_recovery_timer);
531 xhci_dbg(xhci, "All USB3 ports have entered U0 already!\n"); 539 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
532 xhci_dbg(xhci, "Compliance Mode Recovery Timer Deleted.\n"); 540 "All USB3 ports have entered U0 already!");
541 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
542 "Compliance Mode Recovery Timer Deleted.");
533 } 543 }
534 } 544 }
535} 545}
536 546
547/*
548 * Converts a raw xHCI port status into the format that external USB 2.0 or USB
549 * 3.0 hubs use.
550 *
551 * Possible side effects:
552 * - Mark a port as being done with device resume,
553 * and ring the endpoint doorbells.
554 * - Stop the Synopsys redriver Compliance Mode polling.
555 */
556static u32 xhci_get_port_status(struct usb_hcd *hcd,
557 struct xhci_bus_state *bus_state,
558 __le32 __iomem **port_array,
559 u16 wIndex, u32 raw_port_status)
560{
561 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
562 u32 status = 0;
563 int slot_id;
564
565 /* wPortChange bits */
566 if (raw_port_status & PORT_CSC)
567 status |= USB_PORT_STAT_C_CONNECTION << 16;
568 if (raw_port_status & PORT_PEC)
569 status |= USB_PORT_STAT_C_ENABLE << 16;
570 if ((raw_port_status & PORT_OCC))
571 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
572 if ((raw_port_status & PORT_RC))
573 status |= USB_PORT_STAT_C_RESET << 16;
574 /* USB3.0 only */
575 if (hcd->speed == HCD_USB3) {
576 if ((raw_port_status & PORT_PLC))
577 status |= USB_PORT_STAT_C_LINK_STATE << 16;
578 if ((raw_port_status & PORT_WRC))
579 status |= USB_PORT_STAT_C_BH_RESET << 16;
580 }
581
582 if (hcd->speed != HCD_USB3) {
583 if ((raw_port_status & PORT_PLS_MASK) == XDEV_U3
584 && (raw_port_status & PORT_POWER))
585 status |= USB_PORT_STAT_SUSPEND;
586 }
587 if ((raw_port_status & PORT_PLS_MASK) == XDEV_RESUME &&
588 !DEV_SUPERSPEED(raw_port_status)) {
589 if ((raw_port_status & PORT_RESET) ||
590 !(raw_port_status & PORT_PE))
591 return 0xffffffff;
592 if (time_after_eq(jiffies,
593 bus_state->resume_done[wIndex])) {
594 xhci_dbg(xhci, "Resume USB2 port %d\n",
595 wIndex + 1);
596 bus_state->resume_done[wIndex] = 0;
597 clear_bit(wIndex, &bus_state->resuming_ports);
598 xhci_set_link_state(xhci, port_array, wIndex,
599 XDEV_U0);
600 xhci_dbg(xhci, "set port %d resume\n",
601 wIndex + 1);
602 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
603 wIndex + 1);
604 if (!slot_id) {
605 xhci_dbg(xhci, "slot_id is zero\n");
606 return 0xffffffff;
607 }
608 xhci_ring_device(xhci, slot_id);
609 bus_state->port_c_suspend |= 1 << wIndex;
610 bus_state->suspended_ports &= ~(1 << wIndex);
611 } else {
612 /*
613 * The resume has been signaling for less than
614 * 20ms. Report the port status as SUSPEND,
615 * let the usbcore check port status again
616 * and clear resume signaling later.
617 */
618 status |= USB_PORT_STAT_SUSPEND;
619 }
620 }
621 if ((raw_port_status & PORT_PLS_MASK) == XDEV_U0
622 && (raw_port_status & PORT_POWER)
623 && (bus_state->suspended_ports & (1 << wIndex))) {
624 bus_state->suspended_ports &= ~(1 << wIndex);
625 if (hcd->speed != HCD_USB3)
626 bus_state->port_c_suspend |= 1 << wIndex;
627 }
628 if (raw_port_status & PORT_CONNECT) {
629 status |= USB_PORT_STAT_CONNECTION;
630 status |= xhci_port_speed(raw_port_status);
631 }
632 if (raw_port_status & PORT_PE)
633 status |= USB_PORT_STAT_ENABLE;
634 if (raw_port_status & PORT_OC)
635 status |= USB_PORT_STAT_OVERCURRENT;
636 if (raw_port_status & PORT_RESET)
637 status |= USB_PORT_STAT_RESET;
638 if (raw_port_status & PORT_POWER) {
639 if (hcd->speed == HCD_USB3)
640 status |= USB_SS_PORT_STAT_POWER;
641 else
642 status |= USB_PORT_STAT_POWER;
643 }
644 /* Update Port Link State */
645 if (hcd->speed == HCD_USB3) {
646 xhci_hub_report_usb3_link_state(&status, raw_port_status);
647 /*
648 * Verify if all USB3 Ports Have entered U0 already.
649 * Delete Compliance Mode Timer if so.
650 */
651 xhci_del_comp_mod_timer(xhci, raw_port_status, wIndex);
652 } else {
653 xhci_hub_report_usb2_link_state(&status, raw_port_status);
654 }
655 if (bus_state->port_c_suspend & (1 << wIndex))
656 status |= 1 << USB_PORT_FEAT_C_SUSPEND;
657
658 return status;
659}
660
537int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 661int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
538 u16 wIndex, char *buf, u16 wLength) 662 u16 wIndex, char *buf, u16 wLength)
539{ 663{
@@ -598,104 +722,20 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
598 if (!wIndex || wIndex > max_ports) 722 if (!wIndex || wIndex > max_ports)
599 goto error; 723 goto error;
600 wIndex--; 724 wIndex--;
601 status = 0;
602 temp = xhci_readl(xhci, port_array[wIndex]); 725 temp = xhci_readl(xhci, port_array[wIndex]);
603 if (temp == 0xffffffff) { 726 if (temp == 0xffffffff) {
604 retval = -ENODEV; 727 retval = -ENODEV;
605 break; 728 break;
606 } 729 }
607 xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n", wIndex, temp); 730 status = xhci_get_port_status(hcd, bus_state, port_array,
608 731 wIndex, temp);
609 /* wPortChange bits */ 732 if (status == 0xffffffff)
610 if (temp & PORT_CSC) 733 goto error;
611 status |= USB_PORT_STAT_C_CONNECTION << 16;
612 if (temp & PORT_PEC)
613 status |= USB_PORT_STAT_C_ENABLE << 16;
614 if ((temp & PORT_OCC))
615 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
616 if ((temp & PORT_RC))
617 status |= USB_PORT_STAT_C_RESET << 16;
618 /* USB3.0 only */
619 if (hcd->speed == HCD_USB3) {
620 if ((temp & PORT_PLC))
621 status |= USB_PORT_STAT_C_LINK_STATE << 16;
622 if ((temp & PORT_WRC))
623 status |= USB_PORT_STAT_C_BH_RESET << 16;
624 }
625 734
626 if (hcd->speed != HCD_USB3) { 735 xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n",
627 if ((temp & PORT_PLS_MASK) == XDEV_U3 736 wIndex, temp);
628 && (temp & PORT_POWER))
629 status |= USB_PORT_STAT_SUSPEND;
630 }
631 if ((temp & PORT_PLS_MASK) == XDEV_RESUME &&
632 !DEV_SUPERSPEED(temp)) {
633 if ((temp & PORT_RESET) || !(temp & PORT_PE))
634 goto error;
635 if (time_after_eq(jiffies,
636 bus_state->resume_done[wIndex])) {
637 xhci_dbg(xhci, "Resume USB2 port %d\n",
638 wIndex + 1);
639 bus_state->resume_done[wIndex] = 0;
640 clear_bit(wIndex, &bus_state->resuming_ports);
641 xhci_set_link_state(xhci, port_array, wIndex,
642 XDEV_U0);
643 xhci_dbg(xhci, "set port %d resume\n",
644 wIndex + 1);
645 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
646 wIndex + 1);
647 if (!slot_id) {
648 xhci_dbg(xhci, "slot_id is zero\n");
649 goto error;
650 }
651 xhci_ring_device(xhci, slot_id);
652 bus_state->port_c_suspend |= 1 << wIndex;
653 bus_state->suspended_ports &= ~(1 << wIndex);
654 } else {
655 /*
656 * The resume has been signaling for less than
657 * 20ms. Report the port status as SUSPEND,
658 * let the usbcore check port status again
659 * and clear resume signaling later.
660 */
661 status |= USB_PORT_STAT_SUSPEND;
662 }
663 }
664 if ((temp & PORT_PLS_MASK) == XDEV_U0
665 && (temp & PORT_POWER)
666 && (bus_state->suspended_ports & (1 << wIndex))) {
667 bus_state->suspended_ports &= ~(1 << wIndex);
668 if (hcd->speed != HCD_USB3)
669 bus_state->port_c_suspend |= 1 << wIndex;
670 }
671 if (temp & PORT_CONNECT) {
672 status |= USB_PORT_STAT_CONNECTION;
673 status |= xhci_port_speed(temp);
674 }
675 if (temp & PORT_PE)
676 status |= USB_PORT_STAT_ENABLE;
677 if (temp & PORT_OC)
678 status |= USB_PORT_STAT_OVERCURRENT;
679 if (temp & PORT_RESET)
680 status |= USB_PORT_STAT_RESET;
681 if (temp & PORT_POWER) {
682 if (hcd->speed == HCD_USB3)
683 status |= USB_SS_PORT_STAT_POWER;
684 else
685 status |= USB_PORT_STAT_POWER;
686 }
687 /* Update Port Link State for super speed ports*/
688 if (hcd->speed == HCD_USB3) {
689 xhci_hub_report_link_state(&status, temp);
690 /*
691 * Verify if all USB3 Ports Have entered U0 already.
692 * Delete Compliance Mode Timer if so.
693 */
694 xhci_del_comp_mod_timer(xhci, temp, wIndex);
695 }
696 if (bus_state->port_c_suspend & (1 << wIndex))
697 status |= 1 << USB_PORT_FEAT_C_SUSPEND;
698 xhci_dbg(xhci, "Get port status returned 0x%x\n", status); 737 xhci_dbg(xhci, "Get port status returned 0x%x\n", status);
738
699 put_unaligned(cpu_to_le32(status), (__le32 *) buf); 739 put_unaligned(cpu_to_le32(status), (__le32 *) buf);
700 break; 740 break;
701 case SetPortFeature: 741 case SetPortFeature:
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 6f8c2fd47675..53b972c2a09f 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -27,6 +27,7 @@
27#include <linux/dma-mapping.h> 27#include <linux/dma-mapping.h>
28 28
29#include "xhci.h" 29#include "xhci.h"
30#include "xhci-trace.h"
30 31
31/* 32/*
32 * Allocates a generic ring segment from the ring pool, sets the dma address, 33 * Allocates a generic ring segment from the ring pool, sets the dma address,
@@ -348,7 +349,8 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
348 return -ENOMEM; 349 return -ENOMEM;
349 350
350 xhci_link_rings(xhci, ring, first, last, num_segs); 351 xhci_link_rings(xhci, ring, first, last, num_segs);
351 xhci_dbg(xhci, "ring expansion succeed, now has %d segments\n", 352 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion,
353 "ring expansion succeed, now has %d segments",
352 ring->num_segs); 354 ring->num_segs);
353 355
354 return 0; 356 return 0;
@@ -482,17 +484,6 @@ struct xhci_ring *xhci_dma_to_transfer_ring(
482 return ep->ring; 484 return ep->ring;
483} 485}
484 486
485/* Only use this when you know stream_info is valid */
486#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
487static struct xhci_ring *dma_to_stream_ring(
488 struct xhci_stream_info *stream_info,
489 u64 address)
490{
491 return radix_tree_lookup(&stream_info->trb_address_map,
492 address >> TRB_SEGMENT_SHIFT);
493}
494#endif /* CONFIG_USB_XHCI_HCD_DEBUGGING */
495
496struct xhci_ring *xhci_stream_id_to_ring( 487struct xhci_ring *xhci_stream_id_to_ring(
497 struct xhci_virt_device *dev, 488 struct xhci_virt_device *dev,
498 unsigned int ep_index, 489 unsigned int ep_index,
@@ -510,58 +501,6 @@ struct xhci_ring *xhci_stream_id_to_ring(
510 return ep->stream_info->stream_rings[stream_id]; 501 return ep->stream_info->stream_rings[stream_id];
511} 502}
512 503
513#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
514static int xhci_test_radix_tree(struct xhci_hcd *xhci,
515 unsigned int num_streams,
516 struct xhci_stream_info *stream_info)
517{
518 u32 cur_stream;
519 struct xhci_ring *cur_ring;
520 u64 addr;
521
522 for (cur_stream = 1; cur_stream < num_streams; cur_stream++) {
523 struct xhci_ring *mapped_ring;
524 int trb_size = sizeof(union xhci_trb);
525
526 cur_ring = stream_info->stream_rings[cur_stream];
527 for (addr = cur_ring->first_seg->dma;
528 addr < cur_ring->first_seg->dma + TRB_SEGMENT_SIZE;
529 addr += trb_size) {
530 mapped_ring = dma_to_stream_ring(stream_info, addr);
531 if (cur_ring != mapped_ring) {
532 xhci_warn(xhci, "WARN: DMA address 0x%08llx "
533 "didn't map to stream ID %u; "
534 "mapped to ring %p\n",
535 (unsigned long long) addr,
536 cur_stream,
537 mapped_ring);
538 return -EINVAL;
539 }
540 }
541 /* One TRB after the end of the ring segment shouldn't return a
542 * pointer to the current ring (although it may be a part of a
543 * different ring).
544 */
545 mapped_ring = dma_to_stream_ring(stream_info, addr);
546 if (mapped_ring != cur_ring) {
547 /* One TRB before should also fail */
548 addr = cur_ring->first_seg->dma - trb_size;
549 mapped_ring = dma_to_stream_ring(stream_info, addr);
550 }
551 if (mapped_ring == cur_ring) {
552 xhci_warn(xhci, "WARN: Bad DMA address 0x%08llx "
553 "mapped to valid stream ID %u; "
554 "mapped ring = %p\n",
555 (unsigned long long) addr,
556 cur_stream,
557 mapped_ring);
558 return -EINVAL;
559 }
560 }
561 return 0;
562}
563#endif /* CONFIG_USB_XHCI_HCD_DEBUGGING */
564
565/* 504/*
566 * Change an endpoint's internal structure so it supports stream IDs. The 505 * Change an endpoint's internal structure so it supports stream IDs. The
567 * number of requested streams includes stream 0, which cannot be used by device 506 * number of requested streams includes stream 0, which cannot be used by device
@@ -688,13 +627,6 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
688 * was any other way, the host controller would assume the ring is 627 * was any other way, the host controller would assume the ring is
689 * "empty" and wait forever for data to be queued to that stream ID). 628 * "empty" and wait forever for data to be queued to that stream ID).
690 */ 629 */
691#if XHCI_DEBUG
692 /* Do a little test on the radix tree to make sure it returns the
693 * correct values.
694 */
695 if (xhci_test_radix_tree(xhci, num_streams, stream_info))
696 goto cleanup_rings;
697#endif
698 630
699 return stream_info; 631 return stream_info;
700 632
@@ -732,7 +664,8 @@ void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
732 * fls(0) = 0, fls(0x1) = 1, fls(0x10) = 2, fls(0x100) = 3, etc. 664 * fls(0) = 0, fls(0x1) = 1, fls(0x10) = 2, fls(0x100) = 3, etc.
733 */ 665 */
734 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2; 666 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2;
735 xhci_dbg(xhci, "Setting number of stream ctx array entries to %u\n", 667 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
668 "Setting number of stream ctx array entries to %u",
736 1 << (max_primary_streams + 1)); 669 1 << (max_primary_streams + 1));
737 ep_ctx->ep_info &= cpu_to_le32(~EP_MAXPSTREAMS_MASK); 670 ep_ctx->ep_info &= cpu_to_le32(~EP_MAXPSTREAMS_MASK);
738 ep_ctx->ep_info |= cpu_to_le32(EP_MAXPSTREAMS(max_primary_streams) 671 ep_ctx->ep_info |= cpu_to_le32(EP_MAXPSTREAMS(max_primary_streams)
@@ -1614,7 +1547,8 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
1614 struct device *dev = xhci_to_hcd(xhci)->self.controller; 1547 struct device *dev = xhci_to_hcd(xhci)->self.controller;
1615 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); 1548 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
1616 1549
1617 xhci_dbg(xhci, "Allocating %d scratchpad buffers\n", num_sp); 1550 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1551 "Allocating %d scratchpad buffers", num_sp);
1618 1552
1619 if (!num_sp) 1553 if (!num_sp)
1620 return 0; 1554 return 0;
@@ -1771,11 +1705,11 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1771 dma_free_coherent(&pdev->dev, size, 1705 dma_free_coherent(&pdev->dev, size,
1772 xhci->erst.entries, xhci->erst.erst_dma_addr); 1706 xhci->erst.entries, xhci->erst.erst_dma_addr);
1773 xhci->erst.entries = NULL; 1707 xhci->erst.entries = NULL;
1774 xhci_dbg(xhci, "Freed ERST\n"); 1708 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed ERST");
1775 if (xhci->event_ring) 1709 if (xhci->event_ring)
1776 xhci_ring_free(xhci, xhci->event_ring); 1710 xhci_ring_free(xhci, xhci->event_ring);
1777 xhci->event_ring = NULL; 1711 xhci->event_ring = NULL;
1778 xhci_dbg(xhci, "Freed event ring\n"); 1712 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed event ring");
1779 1713
1780 if (xhci->lpm_command) 1714 if (xhci->lpm_command)
1781 xhci_free_command(xhci, xhci->lpm_command); 1715 xhci_free_command(xhci, xhci->lpm_command);
@@ -1783,7 +1717,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1783 if (xhci->cmd_ring) 1717 if (xhci->cmd_ring)
1784 xhci_ring_free(xhci, xhci->cmd_ring); 1718 xhci_ring_free(xhci, xhci->cmd_ring);
1785 xhci->cmd_ring = NULL; 1719 xhci->cmd_ring = NULL;
1786 xhci_dbg(xhci, "Freed command ring\n"); 1720 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed command ring");
1787 list_for_each_entry_safe(cur_cd, next_cd, 1721 list_for_each_entry_safe(cur_cd, next_cd,
1788 &xhci->cancel_cmd_list, cancel_cmd_list) { 1722 &xhci->cancel_cmd_list, cancel_cmd_list) {
1789 list_del(&cur_cd->cancel_cmd_list); 1723 list_del(&cur_cd->cancel_cmd_list);
@@ -1796,22 +1730,24 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1796 if (xhci->segment_pool) 1730 if (xhci->segment_pool)
1797 dma_pool_destroy(xhci->segment_pool); 1731 dma_pool_destroy(xhci->segment_pool);
1798 xhci->segment_pool = NULL; 1732 xhci->segment_pool = NULL;
1799 xhci_dbg(xhci, "Freed segment pool\n"); 1733 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed segment pool");
1800 1734
1801 if (xhci->device_pool) 1735 if (xhci->device_pool)
1802 dma_pool_destroy(xhci->device_pool); 1736 dma_pool_destroy(xhci->device_pool);
1803 xhci->device_pool = NULL; 1737 xhci->device_pool = NULL;
1804 xhci_dbg(xhci, "Freed device context pool\n"); 1738 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed device context pool");
1805 1739
1806 if (xhci->small_streams_pool) 1740 if (xhci->small_streams_pool)
1807 dma_pool_destroy(xhci->small_streams_pool); 1741 dma_pool_destroy(xhci->small_streams_pool);
1808 xhci->small_streams_pool = NULL; 1742 xhci->small_streams_pool = NULL;
1809 xhci_dbg(xhci, "Freed small stream array pool\n"); 1743 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1744 "Freed small stream array pool");
1810 1745
1811 if (xhci->medium_streams_pool) 1746 if (xhci->medium_streams_pool)
1812 dma_pool_destroy(xhci->medium_streams_pool); 1747 dma_pool_destroy(xhci->medium_streams_pool);
1813 xhci->medium_streams_pool = NULL; 1748 xhci->medium_streams_pool = NULL;
1814 xhci_dbg(xhci, "Freed medium stream array pool\n"); 1749 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1750 "Freed medium stream array pool");
1815 1751
1816 if (xhci->dcbaa) 1752 if (xhci->dcbaa)
1817 dma_free_coherent(&pdev->dev, sizeof(*xhci->dcbaa), 1753 dma_free_coherent(&pdev->dev, sizeof(*xhci->dcbaa),
@@ -2037,8 +1973,9 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
2037 * there might be more events to service. 1973 * there might be more events to service.
2038 */ 1974 */
2039 temp &= ~ERST_EHB; 1975 temp &= ~ERST_EHB;
2040 xhci_dbg(xhci, "// Write event ring dequeue pointer, " 1976 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2041 "preserving EHB bit\n"); 1977 "// Write event ring dequeue pointer, "
1978 "preserving EHB bit");
2042 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp, 1979 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
2043 &xhci->ir_set->erst_dequeue); 1980 &xhci->ir_set->erst_dequeue);
2044} 1981}
@@ -2061,8 +1998,9 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
2061 temp = xhci_readl(xhci, addr + 2); 1998 temp = xhci_readl(xhci, addr + 2);
2062 port_offset = XHCI_EXT_PORT_OFF(temp); 1999 port_offset = XHCI_EXT_PORT_OFF(temp);
2063 port_count = XHCI_EXT_PORT_COUNT(temp); 2000 port_count = XHCI_EXT_PORT_COUNT(temp);
2064 xhci_dbg(xhci, "Ext Cap %p, port offset = %u, " 2001 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2065 "count = %u, revision = 0x%x\n", 2002 "Ext Cap %p, port offset = %u, "
2003 "count = %u, revision = 0x%x",
2066 addr, port_offset, port_count, major_revision); 2004 addr, port_offset, port_count, major_revision);
2067 /* Port count includes the current port offset */ 2005 /* Port count includes the current port offset */
2068 if (port_offset == 0 || (port_offset + port_count - 1) > num_ports) 2006 if (port_offset == 0 || (port_offset + port_count - 1) > num_ports)
@@ -2076,15 +2014,18 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
2076 /* Check the host's USB2 LPM capability */ 2014 /* Check the host's USB2 LPM capability */
2077 if ((xhci->hci_version == 0x96) && (major_revision != 0x03) && 2015 if ((xhci->hci_version == 0x96) && (major_revision != 0x03) &&
2078 (temp & XHCI_L1C)) { 2016 (temp & XHCI_L1C)) {
2079 xhci_dbg(xhci, "xHCI 0.96: support USB2 software lpm\n"); 2017 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2018 "xHCI 0.96: support USB2 software lpm");
2080 xhci->sw_lpm_support = 1; 2019 xhci->sw_lpm_support = 1;
2081 } 2020 }
2082 2021
2083 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03)) { 2022 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03)) {
2084 xhci_dbg(xhci, "xHCI 1.0: support USB2 software lpm\n"); 2023 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2024 "xHCI 1.0: support USB2 software lpm");
2085 xhci->sw_lpm_support = 1; 2025 xhci->sw_lpm_support = 1;
2086 if (temp & XHCI_HLC) { 2026 if (temp & XHCI_HLC) {
2087 xhci_dbg(xhci, "xHCI 1.0: support USB2 hardware lpm\n"); 2027 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2028 "xHCI 1.0: support USB2 hardware lpm");
2088 xhci->hw_lpm_support = 1; 2029 xhci->hw_lpm_support = 1;
2089 } 2030 }
2090 } 2031 }
@@ -2208,18 +2149,21 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
2208 xhci_warn(xhci, "No ports on the roothubs?\n"); 2149 xhci_warn(xhci, "No ports on the roothubs?\n");
2209 return -ENODEV; 2150 return -ENODEV;
2210 } 2151 }
2211 xhci_dbg(xhci, "Found %u USB 2.0 ports and %u USB 3.0 ports.\n", 2152 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2153 "Found %u USB 2.0 ports and %u USB 3.0 ports.",
2212 xhci->num_usb2_ports, xhci->num_usb3_ports); 2154 xhci->num_usb2_ports, xhci->num_usb3_ports);
2213 2155
2214 /* Place limits on the number of roothub ports so that the hub 2156 /* Place limits on the number of roothub ports so that the hub
2215 * descriptors aren't longer than the USB core will allocate. 2157 * descriptors aren't longer than the USB core will allocate.
2216 */ 2158 */
2217 if (xhci->num_usb3_ports > 15) { 2159 if (xhci->num_usb3_ports > 15) {
2218 xhci_dbg(xhci, "Limiting USB 3.0 roothub ports to 15.\n"); 2160 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2161 "Limiting USB 3.0 roothub ports to 15.");
2219 xhci->num_usb3_ports = 15; 2162 xhci->num_usb3_ports = 15;
2220 } 2163 }
2221 if (xhci->num_usb2_ports > USB_MAXCHILDREN) { 2164 if (xhci->num_usb2_ports > USB_MAXCHILDREN) {
2222 xhci_dbg(xhci, "Limiting USB 2.0 roothub ports to %u.\n", 2165 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2166 "Limiting USB 2.0 roothub ports to %u.",
2223 USB_MAXCHILDREN); 2167 USB_MAXCHILDREN);
2224 xhci->num_usb2_ports = USB_MAXCHILDREN; 2168 xhci->num_usb2_ports = USB_MAXCHILDREN;
2225 } 2169 }
@@ -2244,8 +2188,9 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
2244 xhci->usb2_ports[port_index] = 2188 xhci->usb2_ports[port_index] =
2245 &xhci->op_regs->port_status_base + 2189 &xhci->op_regs->port_status_base +
2246 NUM_PORT_REGS*i; 2190 NUM_PORT_REGS*i;
2247 xhci_dbg(xhci, "USB 2.0 port at index %u, " 2191 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2248 "addr = %p\n", i, 2192 "USB 2.0 port at index %u, "
2193 "addr = %p", i,
2249 xhci->usb2_ports[port_index]); 2194 xhci->usb2_ports[port_index]);
2250 port_index++; 2195 port_index++;
2251 if (port_index == xhci->num_usb2_ports) 2196 if (port_index == xhci->num_usb2_ports)
@@ -2264,8 +2209,9 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
2264 xhci->usb3_ports[port_index] = 2209 xhci->usb3_ports[port_index] =
2265 &xhci->op_regs->port_status_base + 2210 &xhci->op_regs->port_status_base +
2266 NUM_PORT_REGS*i; 2211 NUM_PORT_REGS*i;
2267 xhci_dbg(xhci, "USB 3.0 port at index %u, " 2212 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2268 "addr = %p\n", i, 2213 "USB 3.0 port at index %u, "
2214 "addr = %p", i,
2269 xhci->usb3_ports[port_index]); 2215 xhci->usb3_ports[port_index]);
2270 port_index++; 2216 port_index++;
2271 if (port_index == xhci->num_usb3_ports) 2217 if (port_index == xhci->num_usb3_ports)
@@ -2289,32 +2235,35 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2289 INIT_LIST_HEAD(&xhci->cancel_cmd_list); 2235 INIT_LIST_HEAD(&xhci->cancel_cmd_list);
2290 2236
2291 page_size = xhci_readl(xhci, &xhci->op_regs->page_size); 2237 page_size = xhci_readl(xhci, &xhci->op_regs->page_size);
2292 xhci_dbg(xhci, "Supported page size register = 0x%x\n", page_size); 2238 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2239 "Supported page size register = 0x%x", page_size);
2293 for (i = 0; i < 16; i++) { 2240 for (i = 0; i < 16; i++) {
2294 if ((0x1 & page_size) != 0) 2241 if ((0x1 & page_size) != 0)
2295 break; 2242 break;
2296 page_size = page_size >> 1; 2243 page_size = page_size >> 1;
2297 } 2244 }
2298 if (i < 16) 2245 if (i < 16)
2299 xhci_dbg(xhci, "Supported page size of %iK\n", (1 << (i+12)) / 1024); 2246 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2247 "Supported page size of %iK", (1 << (i+12)) / 1024);
2300 else 2248 else
2301 xhci_warn(xhci, "WARN: no supported page size\n"); 2249 xhci_warn(xhci, "WARN: no supported page size\n");
2302 /* Use 4K pages, since that's common and the minimum the HC supports */ 2250 /* Use 4K pages, since that's common and the minimum the HC supports */
2303 xhci->page_shift = 12; 2251 xhci->page_shift = 12;
2304 xhci->page_size = 1 << xhci->page_shift; 2252 xhci->page_size = 1 << xhci->page_shift;
2305 xhci_dbg(xhci, "HCD page size set to %iK\n", xhci->page_size / 1024); 2253 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2254 "HCD page size set to %iK", xhci->page_size / 1024);
2306 2255
2307 /* 2256 /*
2308 * Program the Number of Device Slots Enabled field in the CONFIG 2257 * Program the Number of Device Slots Enabled field in the CONFIG
2309 * register with the max value of slots the HC can handle. 2258 * register with the max value of slots the HC can handle.
2310 */ 2259 */
2311 val = HCS_MAX_SLOTS(xhci_readl(xhci, &xhci->cap_regs->hcs_params1)); 2260 val = HCS_MAX_SLOTS(xhci_readl(xhci, &xhci->cap_regs->hcs_params1));
2312 xhci_dbg(xhci, "// xHC can handle at most %d device slots.\n", 2261 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2313 (unsigned int) val); 2262 "// xHC can handle at most %d device slots.", val);
2314 val2 = xhci_readl(xhci, &xhci->op_regs->config_reg); 2263 val2 = xhci_readl(xhci, &xhci->op_regs->config_reg);
2315 val |= (val2 & ~HCS_SLOTS_MASK); 2264 val |= (val2 & ~HCS_SLOTS_MASK);
2316 xhci_dbg(xhci, "// Setting Max device slots reg = 0x%x.\n", 2265 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2317 (unsigned int) val); 2266 "// Setting Max device slots reg = 0x%x.", val);
2318 xhci_writel(xhci, val, &xhci->op_regs->config_reg); 2267 xhci_writel(xhci, val, &xhci->op_regs->config_reg);
2319 2268
2320 /* 2269 /*
@@ -2327,7 +2276,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2327 goto fail; 2276 goto fail;
2328 memset(xhci->dcbaa, 0, sizeof *(xhci->dcbaa)); 2277 memset(xhci->dcbaa, 0, sizeof *(xhci->dcbaa));
2329 xhci->dcbaa->dma = dma; 2278 xhci->dcbaa->dma = dma;
2330 xhci_dbg(xhci, "// Device context base array address = 0x%llx (DMA), %p (virt)\n", 2279 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2280 "// Device context base array address = 0x%llx (DMA), %p (virt)",
2331 (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa); 2281 (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa);
2332 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr); 2282 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr);
2333 2283
@@ -2366,8 +2316,9 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2366 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, flags); 2316 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, flags);
2367 if (!xhci->cmd_ring) 2317 if (!xhci->cmd_ring)
2368 goto fail; 2318 goto fail;
2369 xhci_dbg(xhci, "Allocated command ring at %p\n", xhci->cmd_ring); 2319 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2370 xhci_dbg(xhci, "First segment DMA is 0x%llx\n", 2320 "Allocated command ring at %p", xhci->cmd_ring);
2321 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%llx",
2371 (unsigned long long)xhci->cmd_ring->first_seg->dma); 2322 (unsigned long long)xhci->cmd_ring->first_seg->dma);
2372 2323
2373 /* Set the address in the Command Ring Control register */ 2324 /* Set the address in the Command Ring Control register */
@@ -2375,7 +2326,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2375 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | 2326 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
2376 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | 2327 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) |
2377 xhci->cmd_ring->cycle_state; 2328 xhci->cmd_ring->cycle_state;
2378 xhci_dbg(xhci, "// Setting command ring address to 0x%x\n", val); 2329 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2330 "// Setting command ring address to 0x%x", val);
2379 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); 2331 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
2380 xhci_dbg_cmd_ptrs(xhci); 2332 xhci_dbg_cmd_ptrs(xhci);
2381 2333
@@ -2391,8 +2343,9 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2391 2343
2392 val = xhci_readl(xhci, &xhci->cap_regs->db_off); 2344 val = xhci_readl(xhci, &xhci->cap_regs->db_off);
2393 val &= DBOFF_MASK; 2345 val &= DBOFF_MASK;
2394 xhci_dbg(xhci, "// Doorbell array is located at offset 0x%x" 2346 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2395 " from cap regs base addr\n", val); 2347 "// Doorbell array is located at offset 0x%x"
2348 " from cap regs base addr", val);
2396 xhci->dba = (void __iomem *) xhci->cap_regs + val; 2349 xhci->dba = (void __iomem *) xhci->cap_regs + val;
2397 xhci_dbg_regs(xhci); 2350 xhci_dbg_regs(xhci);
2398 xhci_print_run_regs(xhci); 2351 xhci_print_run_regs(xhci);
@@ -2403,7 +2356,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2403 * Event ring setup: Allocate a normal ring, but also setup 2356 * Event ring setup: Allocate a normal ring, but also setup
2404 * the event ring segment table (ERST). Section 4.9.3. 2357 * the event ring segment table (ERST). Section 4.9.3.
2405 */ 2358 */
2406 xhci_dbg(xhci, "// Allocating event ring\n"); 2359 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Allocating event ring");
2407 xhci->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, 1, TYPE_EVENT, 2360 xhci->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, 1, TYPE_EVENT,
2408 flags); 2361 flags);
2409 if (!xhci->event_ring) 2362 if (!xhci->event_ring)
@@ -2416,13 +2369,15 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2416 GFP_KERNEL); 2369 GFP_KERNEL);
2417 if (!xhci->erst.entries) 2370 if (!xhci->erst.entries)
2418 goto fail; 2371 goto fail;
2419 xhci_dbg(xhci, "// Allocated event ring segment table at 0x%llx\n", 2372 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2373 "// Allocated event ring segment table at 0x%llx",
2420 (unsigned long long)dma); 2374 (unsigned long long)dma);
2421 2375
2422 memset(xhci->erst.entries, 0, sizeof(struct xhci_erst_entry)*ERST_NUM_SEGS); 2376 memset(xhci->erst.entries, 0, sizeof(struct xhci_erst_entry)*ERST_NUM_SEGS);
2423 xhci->erst.num_entries = ERST_NUM_SEGS; 2377 xhci->erst.num_entries = ERST_NUM_SEGS;
2424 xhci->erst.erst_dma_addr = dma; 2378 xhci->erst.erst_dma_addr = dma;
2425 xhci_dbg(xhci, "Set ERST to 0; private num segs = %i, virt addr = %p, dma addr = 0x%llx\n", 2379 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2380 "Set ERST to 0; private num segs = %i, virt addr = %p, dma addr = 0x%llx",
2426 xhci->erst.num_entries, 2381 xhci->erst.num_entries,
2427 xhci->erst.entries, 2382 xhci->erst.entries,
2428 (unsigned long long)xhci->erst.erst_dma_addr); 2383 (unsigned long long)xhci->erst.erst_dma_addr);
@@ -2440,13 +2395,16 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2440 val = xhci_readl(xhci, &xhci->ir_set->erst_size); 2395 val = xhci_readl(xhci, &xhci->ir_set->erst_size);
2441 val &= ERST_SIZE_MASK; 2396 val &= ERST_SIZE_MASK;
2442 val |= ERST_NUM_SEGS; 2397 val |= ERST_NUM_SEGS;
2443 xhci_dbg(xhci, "// Write ERST size = %i to ir_set 0 (some bits preserved)\n", 2398 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2399 "// Write ERST size = %i to ir_set 0 (some bits preserved)",
2444 val); 2400 val);
2445 xhci_writel(xhci, val, &xhci->ir_set->erst_size); 2401 xhci_writel(xhci, val, &xhci->ir_set->erst_size);
2446 2402
2447 xhci_dbg(xhci, "// Set ERST entries to point to event ring.\n"); 2403 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2404 "// Set ERST entries to point to event ring.");
2448 /* set the segment table base address */ 2405 /* set the segment table base address */
2449 xhci_dbg(xhci, "// Set ERST base address for ir_set 0 = 0x%llx\n", 2406 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2407 "// Set ERST base address for ir_set 0 = 0x%llx",
2450 (unsigned long long)xhci->erst.erst_dma_addr); 2408 (unsigned long long)xhci->erst.erst_dma_addr);
2451 val_64 = xhci_read_64(xhci, &xhci->ir_set->erst_base); 2409 val_64 = xhci_read_64(xhci, &xhci->ir_set->erst_base);
2452 val_64 &= ERST_PTR_MASK; 2410 val_64 &= ERST_PTR_MASK;
@@ -2455,7 +2413,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2455 2413
2456 /* Set the event ring dequeue address */ 2414 /* Set the event ring dequeue address */
2457 xhci_set_hc_event_deq(xhci); 2415 xhci_set_hc_event_deq(xhci);
2458 xhci_dbg(xhci, "Wrote ERST address to ir_set 0.\n"); 2416 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2417 "Wrote ERST address to ir_set 0.");
2459 xhci_print_ir_set(xhci, 0); 2418 xhci_print_ir_set(xhci, 0);
2460 2419
2461 /* 2420 /*
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index f00cb203faea..c2d495057eb5 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26 26
27#include "xhci.h" 27#include "xhci.h"
28#include "xhci-trace.h"
28 29
29/* Device for a quirk */ 30/* Device for a quirk */
30#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73 31#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
@@ -64,16 +65,18 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
64 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK && 65 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
65 pdev->revision == 0x0) { 66 pdev->revision == 0x0) {
66 xhci->quirks |= XHCI_RESET_EP_QUIRK; 67 xhci->quirks |= XHCI_RESET_EP_QUIRK;
67 xhci_dbg(xhci, "QUIRK: Fresco Logic xHC needs configure" 68 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
68 " endpoint cmd after reset endpoint\n"); 69 "QUIRK: Fresco Logic xHC needs configure"
70 " endpoint cmd after reset endpoint");
69 } 71 }
70 /* Fresco Logic confirms: all revisions of this chip do not 72 /* Fresco Logic confirms: all revisions of this chip do not
71 * support MSI, even though some of them claim to in their PCI 73 * support MSI, even though some of them claim to in their PCI
72 * capabilities. 74 * capabilities.
73 */ 75 */
74 xhci->quirks |= XHCI_BROKEN_MSI; 76 xhci->quirks |= XHCI_BROKEN_MSI;
75 xhci_dbg(xhci, "QUIRK: Fresco Logic revision %u " 77 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
76 "has broken MSI implementation\n", 78 "QUIRK: Fresco Logic revision %u "
79 "has broken MSI implementation",
77 pdev->revision); 80 pdev->revision);
78 xhci->quirks |= XHCI_TRUST_TX_LENGTH; 81 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
79 } 82 }
@@ -110,7 +113,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
110 if (pdev->vendor == PCI_VENDOR_ID_ETRON && 113 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
111 pdev->device == PCI_DEVICE_ID_ASROCK_P67) { 114 pdev->device == PCI_DEVICE_ID_ASROCK_P67) {
112 xhci->quirks |= XHCI_RESET_ON_RESUME; 115 xhci->quirks |= XHCI_RESET_ON_RESUME;
113 xhci_dbg(xhci, "QUIRK: Resetting on resume\n"); 116 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
117 "QUIRK: Resetting on resume");
114 xhci->quirks |= XHCI_TRUST_TX_LENGTH; 118 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
115 } 119 }
116 if (pdev->vendor == PCI_VENDOR_ID_VIA) 120 if (pdev->vendor == PCI_VENDOR_ID_VIA)
@@ -249,13 +253,15 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
249 * writers. 253 * writers.
250 * 254 *
251 * Unconditionally switch the ports back to xHCI after a system resume. 255 * Unconditionally switch the ports back to xHCI after a system resume.
252 * We can't tell whether the EHCI or xHCI controller will be resumed 256 * It should not matter whether the EHCI or xHCI controller is
253 * first, so we have to do the port switchover in both drivers. Writing 257 * resumed first. It's enough to do the switchover in xHCI because
254 * a '1' to the port switchover registers should have no effect if the 258 * USB core won't notice anything as the hub driver doesn't start
255 * port was already switched over. 259 * running again until after all the devices (including both EHCI and
260 * xHCI host controllers) have been resumed.
256 */ 261 */
257 if (usb_is_intel_switchable_xhci(pdev)) 262
258 usb_enable_xhci_ports(pdev); 263 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
264 usb_enable_intel_xhci_ports(pdev);
259 265
260 retval = xhci_resume(xhci, hibernated); 266 retval = xhci_resume(xhci, hibernated);
261 return retval; 267 return retval;
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 6eca5a536c0a..d9c169f470d3 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -14,6 +14,8 @@
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/of.h>
18#include <linux/dma-mapping.h>
17 19
18#include "xhci.h" 20#include "xhci.h"
19 21
@@ -104,6 +106,15 @@ static int xhci_plat_probe(struct platform_device *pdev)
104 if (!res) 106 if (!res)
105 return -ENODEV; 107 return -ENODEV;
106 108
109 /* Initialize dma_mask and coherent_dma_mask to 32-bits */
110 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
111 if (ret)
112 return ret;
113 if (!pdev->dev.dma_mask)
114 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
115 else
116 dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
117
107 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); 118 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
108 if (!hcd) 119 if (!hcd)
109 return -ENOMEM; 120 return -ENOMEM;
@@ -186,11 +197,46 @@ static int xhci_plat_remove(struct platform_device *dev)
186 return 0; 197 return 0;
187} 198}
188 199
200#ifdef CONFIG_PM
201static int xhci_plat_suspend(struct device *dev)
202{
203 struct usb_hcd *hcd = dev_get_drvdata(dev);
204 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
205
206 return xhci_suspend(xhci);
207}
208
209static int xhci_plat_resume(struct device *dev)
210{
211 struct usb_hcd *hcd = dev_get_drvdata(dev);
212 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
213
214 return xhci_resume(xhci, 0);
215}
216
217static const struct dev_pm_ops xhci_plat_pm_ops = {
218 SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
219};
220#define DEV_PM_OPS (&xhci_plat_pm_ops)
221#else
222#define DEV_PM_OPS NULL
223#endif /* CONFIG_PM */
224
225#ifdef CONFIG_OF
226static const struct of_device_id usb_xhci_of_match[] = {
227 { .compatible = "xhci-platform" },
228 { },
229};
230MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
231#endif
232
189static struct platform_driver usb_xhci_driver = { 233static struct platform_driver usb_xhci_driver = {
190 .probe = xhci_plat_probe, 234 .probe = xhci_plat_probe,
191 .remove = xhci_plat_remove, 235 .remove = xhci_plat_remove,
192 .driver = { 236 .driver = {
193 .name = "xhci-hcd", 237 .name = "xhci-hcd",
238 .pm = DEV_PM_OPS,
239 .of_match_table = of_match_ptr(usb_xhci_of_match),
194 }, 240 },
195}; 241};
196MODULE_ALIAS("platform:xhci-hcd"); 242MODULE_ALIAS("platform:xhci-hcd");
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 5b08cd85f8e7..7b35af167e55 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -67,6 +67,7 @@
67#include <linux/scatterlist.h> 67#include <linux/scatterlist.h>
68#include <linux/slab.h> 68#include <linux/slab.h>
69#include "xhci.h" 69#include "xhci.h"
70#include "xhci-trace.h"
70 71
71static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci, 72static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci,
72 struct xhci_virt_device *virt_dev, 73 struct xhci_virt_device *virt_dev,
@@ -555,7 +556,8 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
555 return; 556 return;
556 } 557 }
557 state->new_cycle_state = 0; 558 state->new_cycle_state = 0;
558 xhci_dbg(xhci, "Finding segment containing stopped TRB.\n"); 559 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
560 "Finding segment containing stopped TRB.");
559 state->new_deq_seg = find_trb_seg(cur_td->start_seg, 561 state->new_deq_seg = find_trb_seg(cur_td->start_seg,
560 dev->eps[ep_index].stopped_trb, 562 dev->eps[ep_index].stopped_trb,
561 &state->new_cycle_state); 563 &state->new_cycle_state);
@@ -565,12 +567,14 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
565 } 567 }
566 568
567 /* Dig out the cycle state saved by the xHC during the stop ep cmd */ 569 /* Dig out the cycle state saved by the xHC during the stop ep cmd */
568 xhci_dbg(xhci, "Finding endpoint context\n"); 570 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
571 "Finding endpoint context");
569 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); 572 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
570 state->new_cycle_state = 0x1 & le64_to_cpu(ep_ctx->deq); 573 state->new_cycle_state = 0x1 & le64_to_cpu(ep_ctx->deq);
571 574
572 state->new_deq_ptr = cur_td->last_trb; 575 state->new_deq_ptr = cur_td->last_trb;
573 xhci_dbg(xhci, "Finding segment containing last TRB in TD.\n"); 576 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
577 "Finding segment containing last TRB in TD.");
574 state->new_deq_seg = find_trb_seg(state->new_deq_seg, 578 state->new_deq_seg = find_trb_seg(state->new_deq_seg,
575 state->new_deq_ptr, 579 state->new_deq_ptr,
576 &state->new_cycle_state); 580 &state->new_cycle_state);
@@ -597,13 +601,16 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
597 if (ep_ring->first_seg == ep_ring->first_seg->next && 601 if (ep_ring->first_seg == ep_ring->first_seg->next &&
598 state->new_deq_ptr < dev->eps[ep_index].stopped_trb) 602 state->new_deq_ptr < dev->eps[ep_index].stopped_trb)
599 state->new_cycle_state ^= 0x1; 603 state->new_cycle_state ^= 0x1;
600 xhci_dbg(xhci, "Cycle state = 0x%x\n", state->new_cycle_state); 604 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
605 "Cycle state = 0x%x", state->new_cycle_state);
601 606
602 /* Don't update the ring cycle state for the producer (us). */ 607 /* Don't update the ring cycle state for the producer (us). */
603 xhci_dbg(xhci, "New dequeue segment = %p (virtual)\n", 608 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
609 "New dequeue segment = %p (virtual)",
604 state->new_deq_seg); 610 state->new_deq_seg);
605 addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr); 611 addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr);
606 xhci_dbg(xhci, "New dequeue pointer = 0x%llx (DMA)\n", 612 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
613 "New dequeue pointer = 0x%llx (DMA)",
607 (unsigned long long) addr); 614 (unsigned long long) addr);
608} 615}
609 616
@@ -631,9 +638,11 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
631 if (flip_cycle) 638 if (flip_cycle)
632 cur_trb->generic.field[3] ^= 639 cur_trb->generic.field[3] ^=
633 cpu_to_le32(TRB_CYCLE); 640 cpu_to_le32(TRB_CYCLE);
634 xhci_dbg(xhci, "Cancel (unchain) link TRB\n"); 641 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
635 xhci_dbg(xhci, "Address = %p (0x%llx dma); " 642 "Cancel (unchain) link TRB");
636 "in seg %p (0x%llx dma)\n", 643 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
644 "Address = %p (0x%llx dma); "
645 "in seg %p (0x%llx dma)",
637 cur_trb, 646 cur_trb,
638 (unsigned long long)xhci_trb_virt_to_dma(cur_seg, cur_trb), 647 (unsigned long long)xhci_trb_virt_to_dma(cur_seg, cur_trb),
639 cur_seg, 648 cur_seg,
@@ -651,7 +660,8 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
651 cpu_to_le32(TRB_CYCLE); 660 cpu_to_le32(TRB_CYCLE);
652 cur_trb->generic.field[3] |= cpu_to_le32( 661 cur_trb->generic.field[3] |= cpu_to_le32(
653 TRB_TYPE(TRB_TR_NOOP)); 662 TRB_TYPE(TRB_TR_NOOP));
654 xhci_dbg(xhci, "TRB to noop at offset 0x%llx\n", 663 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
664 "TRB to noop at offset 0x%llx",
655 (unsigned long long) 665 (unsigned long long)
656 xhci_trb_virt_to_dma(cur_seg, cur_trb)); 666 xhci_trb_virt_to_dma(cur_seg, cur_trb));
657 } 667 }
@@ -672,8 +682,9 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
672{ 682{
673 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; 683 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index];
674 684
675 xhci_dbg(xhci, "Set TR Deq Ptr cmd, new deq seg = %p (0x%llx dma), " 685 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
676 "new deq ptr = %p (0x%llx dma), new cycle = %u\n", 686 "Set TR Deq Ptr cmd, new deq seg = %p (0x%llx dma), "
687 "new deq ptr = %p (0x%llx dma), new cycle = %u",
677 deq_state->new_deq_seg, 688 deq_state->new_deq_seg,
678 (unsigned long long)deq_state->new_deq_seg->dma, 689 (unsigned long long)deq_state->new_deq_seg->dma,
679 deq_state->new_deq_ptr, 690 deq_state->new_deq_ptr,
@@ -793,7 +804,8 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
793 */ 804 */
794 list_for_each(entry, &ep->cancelled_td_list) { 805 list_for_each(entry, &ep->cancelled_td_list) {
795 cur_td = list_entry(entry, struct xhci_td, cancelled_td_list); 806 cur_td = list_entry(entry, struct xhci_td, cancelled_td_list);
796 xhci_dbg(xhci, "Removing canceled TD starting at 0x%llx (dma).\n", 807 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
808 "Removing canceled TD starting at 0x%llx (dma).",
797 (unsigned long long)xhci_trb_virt_to_dma( 809 (unsigned long long)xhci_trb_virt_to_dma(
798 cur_td->start_seg, cur_td->first_trb)); 810 cur_td->start_seg, cur_td->first_trb));
799 ep_ring = xhci_urb_to_transfer_ring(xhci, cur_td->urb); 811 ep_ring = xhci_urb_to_transfer_ring(xhci, cur_td->urb);
@@ -913,14 +925,16 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
913 925
914 ep->stop_cmds_pending--; 926 ep->stop_cmds_pending--;
915 if (xhci->xhc_state & XHCI_STATE_DYING) { 927 if (xhci->xhc_state & XHCI_STATE_DYING) {
916 xhci_dbg(xhci, "Stop EP timer ran, but another timer marked " 928 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
917 "xHCI as DYING, exiting.\n"); 929 "Stop EP timer ran, but another timer marked "
930 "xHCI as DYING, exiting.");
918 spin_unlock_irqrestore(&xhci->lock, flags); 931 spin_unlock_irqrestore(&xhci->lock, flags);
919 return; 932 return;
920 } 933 }
921 if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) { 934 if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) {
922 xhci_dbg(xhci, "Stop EP timer ran, but no command pending, " 935 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
923 "exiting.\n"); 936 "Stop EP timer ran, but no command pending, "
937 "exiting.");
924 spin_unlock_irqrestore(&xhci->lock, flags); 938 spin_unlock_irqrestore(&xhci->lock, flags);
925 return; 939 return;
926 } 940 }
@@ -962,8 +976,9 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
962 ring = temp_ep->ring; 976 ring = temp_ep->ring;
963 if (!ring) 977 if (!ring)
964 continue; 978 continue;
965 xhci_dbg(xhci, "Killing URBs for slot ID %u, " 979 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
966 "ep index %u\n", i, j); 980 "Killing URBs for slot ID %u, "
981 "ep index %u", i, j);
967 while (!list_empty(&ring->td_list)) { 982 while (!list_empty(&ring->td_list)) {
968 cur_td = list_first_entry(&ring->td_list, 983 cur_td = list_first_entry(&ring->td_list,
969 struct xhci_td, 984 struct xhci_td,
@@ -986,9 +1001,11 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
986 } 1001 }
987 } 1002 }
988 spin_unlock_irqrestore(&xhci->lock, flags); 1003 spin_unlock_irqrestore(&xhci->lock, flags);
989 xhci_dbg(xhci, "Calling usb_hc_died()\n"); 1004 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
1005 "Calling usb_hc_died()");
990 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); 1006 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd);
991 xhci_dbg(xhci, "xHCI host controller is dead.\n"); 1007 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
1008 "xHCI host controller is dead.");
992} 1009}
993 1010
994 1011
@@ -1092,7 +1109,8 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1092 ep_state &= EP_STATE_MASK; 1109 ep_state &= EP_STATE_MASK;
1093 slot_state = le32_to_cpu(slot_ctx->dev_state); 1110 slot_state = le32_to_cpu(slot_ctx->dev_state);
1094 slot_state = GET_SLOT_STATE(slot_state); 1111 slot_state = GET_SLOT_STATE(slot_state);
1095 xhci_dbg(xhci, "Slot state = %u, EP state = %u\n", 1112 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
1113 "Slot state = %u, EP state = %u",
1096 slot_state, ep_state); 1114 slot_state, ep_state);
1097 break; 1115 break;
1098 case COMP_EBADSLT: 1116 case COMP_EBADSLT:
@@ -1112,7 +1130,8 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1112 * cancelling URBs, which might not be an error... 1130 * cancelling URBs, which might not be an error...
1113 */ 1131 */
1114 } else { 1132 } else {
1115 xhci_dbg(xhci, "Successful Set TR Deq Ptr cmd, deq = @%08llx\n", 1133 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
1134 "Successful Set TR Deq Ptr cmd, deq = @%08llx",
1116 le64_to_cpu(ep_ctx->deq)); 1135 le64_to_cpu(ep_ctx->deq));
1117 if (xhci_trb_virt_to_dma(dev->eps[ep_index].queued_deq_seg, 1136 if (xhci_trb_virt_to_dma(dev->eps[ep_index].queued_deq_seg,
1118 dev->eps[ep_index].queued_deq_ptr) == 1137 dev->eps[ep_index].queued_deq_ptr) ==
@@ -1150,7 +1169,8 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
1150 /* This command will only fail if the endpoint wasn't halted, 1169 /* This command will only fail if the endpoint wasn't halted,
1151 * but we don't care. 1170 * but we don't care.
1152 */ 1171 */
1153 xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n", 1172 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
1173 "Ignoring reset ep completion code of %u",
1154 GET_COMP_CODE(le32_to_cpu(event->status))); 1174 GET_COMP_CODE(le32_to_cpu(event->status)));
1155 1175
1156 /* HW with the reset endpoint quirk needs to have a configure endpoint 1176 /* HW with the reset endpoint quirk needs to have a configure endpoint
@@ -1158,7 +1178,8 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
1158 * because the HW can't handle two commands being queued in a row. 1178 * because the HW can't handle two commands being queued in a row.
1159 */ 1179 */
1160 if (xhci->quirks & XHCI_RESET_EP_QUIRK) { 1180 if (xhci->quirks & XHCI_RESET_EP_QUIRK) {
1161 xhci_dbg(xhci, "Queueing configure endpoint command\n"); 1181 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1182 "Queueing configure endpoint command");
1162 xhci_queue_configure_endpoint(xhci, 1183 xhci_queue_configure_endpoint(xhci,
1163 xhci->devs[slot_id]->in_ctx->dma, slot_id, 1184 xhci->devs[slot_id]->in_ctx->dma, slot_id,
1164 false); 1185 false);
@@ -1377,6 +1398,9 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1377 return; 1398 return;
1378 } 1399 }
1379 1400
1401 trace_xhci_cmd_completion(&xhci->cmd_ring->dequeue->generic,
1402 (struct xhci_generic_trb *) event);
1403
1380 if ((GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_ABORT) || 1404 if ((GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_ABORT) ||
1381 (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_STOP)) { 1405 (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_STOP)) {
1382 /* If the return value is 0, we think the trb pointed by 1406 /* If the return value is 0, we think the trb pointed by
@@ -1444,8 +1468,9 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1444 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; 1468 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
1445 if (!(ep_state & EP_HALTED)) 1469 if (!(ep_state & EP_HALTED))
1446 goto bandwidth_change; 1470 goto bandwidth_change;
1447 xhci_dbg(xhci, "Completed config ep cmd - " 1471 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1448 "last ep index = %d, state = %d\n", 1472 "Completed config ep cmd - "
1473 "last ep index = %d, state = %d",
1449 ep_index, ep_state); 1474 ep_index, ep_state);
1450 /* Clear internal halted state and restart ring(s) */ 1475 /* Clear internal halted state and restart ring(s) */
1451 xhci->devs[slot_id]->eps[ep_index].ep_state &= 1476 xhci->devs[slot_id]->eps[ep_index].ep_state &=
@@ -1454,7 +1479,8 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1454 break; 1479 break;
1455 } 1480 }
1456bandwidth_change: 1481bandwidth_change:
1457 xhci_dbg(xhci, "Completed config ep cmd\n"); 1482 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1483 "Completed config ep cmd");
1458 xhci->devs[slot_id]->cmd_status = 1484 xhci->devs[slot_id]->cmd_status =
1459 GET_COMP_CODE(le32_to_cpu(event->status)); 1485 GET_COMP_CODE(le32_to_cpu(event->status));
1460 complete(&xhci->devs[slot_id]->cmd_completion); 1486 complete(&xhci->devs[slot_id]->cmd_completion);
@@ -1497,7 +1523,8 @@ bandwidth_change:
1497 xhci->error_bitmask |= 1 << 6; 1523 xhci->error_bitmask |= 1 << 6;
1498 break; 1524 break;
1499 } 1525 }
1500 xhci_dbg(xhci, "NEC firmware version %2x.%02x\n", 1526 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1527 "NEC firmware version %2x.%02x",
1501 NEC_FW_MAJOR(le32_to_cpu(event->status)), 1528 NEC_FW_MAJOR(le32_to_cpu(event->status)),
1502 NEC_FW_MINOR(le32_to_cpu(event->status))); 1529 NEC_FW_MINOR(le32_to_cpu(event->status)));
1503 break; 1530 break;
@@ -2877,8 +2904,8 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
2877 return -ENOMEM; 2904 return -ENOMEM;
2878 } 2905 }
2879 2906
2880 xhci_dbg(xhci, "ERROR no room on ep ring, " 2907 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion,
2881 "try ring expansion\n"); 2908 "ERROR no room on ep ring, try ring expansion");
2882 num_trbs_needed = num_trbs - ep_ring->num_trbs_free; 2909 num_trbs_needed = num_trbs - ep_ring->num_trbs_free;
2883 if (xhci_ring_expansion(xhci, ep_ring, num_trbs_needed, 2910 if (xhci_ring_expansion(xhci, ep_ring, num_trbs_needed,
2884 mem_flags)) { 2911 mem_flags)) {
diff --git a/drivers/usb/host/xhci-trace.c b/drivers/usb/host/xhci-trace.c
new file mode 100644
index 000000000000..7cf30c83dcf3
--- /dev/null
+++ b/drivers/usb/host/xhci-trace.c
@@ -0,0 +1,15 @@
1/*
2 * xHCI host controller driver
3 *
4 * Copyright (C) 2013 Xenia Ragiadakou
5 *
6 * Author: Xenia Ragiadakou
7 * Email : burzalodowa@gmail.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 version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#define CREATE_TRACE_POINTS
15#include "xhci-trace.h"
diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h
new file mode 100644
index 000000000000..20364cc8d2fb
--- /dev/null
+++ b/drivers/usb/host/xhci-trace.h
@@ -0,0 +1,151 @@
1/*
2 * xHCI host controller driver
3 *
4 * Copyright (C) 2013 Xenia Ragiadakou
5 *
6 * Author: Xenia Ragiadakou
7 * Email : burzalodowa@gmail.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 version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#undef TRACE_SYSTEM
15#define TRACE_SYSTEM xhci-hcd
16
17#if !defined(__XHCI_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
18#define __XHCI_TRACE_H
19
20#include <linux/tracepoint.h>
21#include "xhci.h"
22
23#define XHCI_MSG_MAX 500
24
25DECLARE_EVENT_CLASS(xhci_log_msg,
26 TP_PROTO(struct va_format *vaf),
27 TP_ARGS(vaf),
28 TP_STRUCT__entry(__dynamic_array(char, msg, XHCI_MSG_MAX)),
29 TP_fast_assign(
30 vsnprintf(__get_str(msg), XHCI_MSG_MAX, vaf->fmt, *vaf->va);
31 ),
32 TP_printk("%s", __get_str(msg))
33);
34
35DEFINE_EVENT(xhci_log_msg, xhci_dbg_address,
36 TP_PROTO(struct va_format *vaf),
37 TP_ARGS(vaf)
38);
39
40DEFINE_EVENT(xhci_log_msg, xhci_dbg_context_change,
41 TP_PROTO(struct va_format *vaf),
42 TP_ARGS(vaf)
43);
44
45DEFINE_EVENT(xhci_log_msg, xhci_dbg_quirks,
46 TP_PROTO(struct va_format *vaf),
47 TP_ARGS(vaf)
48);
49
50DEFINE_EVENT(xhci_log_msg, xhci_dbg_reset_ep,
51 TP_PROTO(struct va_format *vaf),
52 TP_ARGS(vaf)
53);
54
55DEFINE_EVENT(xhci_log_msg, xhci_dbg_cancel_urb,
56 TP_PROTO(struct va_format *vaf),
57 TP_ARGS(vaf)
58);
59
60DEFINE_EVENT(xhci_log_msg, xhci_dbg_init,
61 TP_PROTO(struct va_format *vaf),
62 TP_ARGS(vaf)
63);
64
65DEFINE_EVENT(xhci_log_msg, xhci_dbg_ring_expansion,
66 TP_PROTO(struct va_format *vaf),
67 TP_ARGS(vaf)
68);
69
70DECLARE_EVENT_CLASS(xhci_log_ctx,
71 TP_PROTO(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
72 unsigned int ep_num),
73 TP_ARGS(xhci, ctx, ep_num),
74 TP_STRUCT__entry(
75 __field(int, ctx_64)
76 __field(unsigned, ctx_type)
77 __field(dma_addr_t, ctx_dma)
78 __field(u8 *, ctx_va)
79 __field(unsigned, ctx_ep_num)
80 __field(int, slot_id)
81 __dynamic_array(u32, ctx_data,
82 ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 8) *
83 ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1))
84 ),
85 TP_fast_assign(
86 struct usb_device *udev;
87
88 udev = to_usb_device(xhci_to_hcd(xhci)->self.controller);
89 __entry->ctx_64 = HCC_64BYTE_CONTEXT(xhci->hcc_params);
90 __entry->ctx_type = ctx->type;
91 __entry->ctx_dma = ctx->dma;
92 __entry->ctx_va = ctx->bytes;
93 __entry->slot_id = udev->slot_id;
94 __entry->ctx_ep_num = ep_num;
95 memcpy(__get_dynamic_array(ctx_data), ctx->bytes,
96 ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 32) *
97 ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1));
98 ),
99 TP_printk("\nctx_64=%d, ctx_type=%u, ctx_dma=@%llx, ctx_va=@%p",
100 __entry->ctx_64, __entry->ctx_type,
101 (unsigned long long) __entry->ctx_dma, __entry->ctx_va
102 )
103);
104
105DEFINE_EVENT(xhci_log_ctx, xhci_address_ctx,
106 TP_PROTO(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
107 unsigned int ep_num),
108 TP_ARGS(xhci, ctx, ep_num)
109);
110
111DECLARE_EVENT_CLASS(xhci_log_event,
112 TP_PROTO(void *trb_va, struct xhci_generic_trb *ev),
113 TP_ARGS(trb_va, ev),
114 TP_STRUCT__entry(
115 __field(void *, va)
116 __field(u64, dma)
117 __field(u32, status)
118 __field(u32, flags)
119 __dynamic_array(__le32, trb, 4)
120 ),
121 TP_fast_assign(
122 __entry->va = trb_va;
123 __entry->dma = le64_to_cpu(((u64)ev->field[1]) << 32 |
124 ev->field[0]);
125 __entry->status = le32_to_cpu(ev->field[2]);
126 __entry->flags = le32_to_cpu(ev->field[3]);
127 memcpy(__get_dynamic_array(trb), trb_va,
128 sizeof(struct xhci_generic_trb));
129 ),
130 TP_printk("\ntrb_dma=@%llx, trb_va=@%p, status=%08x, flags=%08x",
131 (unsigned long long) __entry->dma, __entry->va,
132 __entry->status, __entry->flags
133 )
134);
135
136DEFINE_EVENT(xhci_log_event, xhci_cmd_completion,
137 TP_PROTO(void *trb_va, struct xhci_generic_trb *ev),
138 TP_ARGS(trb_va, ev)
139);
140
141#endif /* __XHCI_TRACE_H */
142
143/* this part must be outside header guard */
144
145#undef TRACE_INCLUDE_PATH
146#define TRACE_INCLUDE_PATH .
147
148#undef TRACE_INCLUDE_FILE
149#define TRACE_INCLUDE_FILE xhci-trace
150
151#include <trace/define_trace.h>
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ead3555d6dba..ba0ec0a96481 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -30,6 +30,7 @@
30#include <linux/dma-mapping.h> 30#include <linux/dma-mapping.h>
31 31
32#include "xhci.h" 32#include "xhci.h"
33#include "xhci-trace.h"
33 34
34#define DRIVER_AUTHOR "Sarah Sharp" 35#define DRIVER_AUTHOR "Sarah Sharp"
35#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver" 36#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
@@ -101,7 +102,7 @@ void xhci_quiesce(struct xhci_hcd *xhci)
101int xhci_halt(struct xhci_hcd *xhci) 102int xhci_halt(struct xhci_hcd *xhci)
102{ 103{
103 int ret; 104 int ret;
104 xhci_dbg(xhci, "// Halt the HC\n"); 105 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Halt the HC");
105 xhci_quiesce(xhci); 106 xhci_quiesce(xhci);
106 107
107 ret = xhci_handshake(xhci, &xhci->op_regs->status, 108 ret = xhci_handshake(xhci, &xhci->op_regs->status,
@@ -125,7 +126,7 @@ static int xhci_start(struct xhci_hcd *xhci)
125 126
126 temp = xhci_readl(xhci, &xhci->op_regs->command); 127 temp = xhci_readl(xhci, &xhci->op_regs->command);
127 temp |= (CMD_RUN); 128 temp |= (CMD_RUN);
128 xhci_dbg(xhci, "// Turn on HC, cmd = 0x%x.\n", 129 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Turn on HC, cmd = 0x%x.",
129 temp); 130 temp);
130 xhci_writel(xhci, temp, &xhci->op_regs->command); 131 xhci_writel(xhci, temp, &xhci->op_regs->command);
131 132
@@ -163,7 +164,7 @@ int xhci_reset(struct xhci_hcd *xhci)
163 return 0; 164 return 0;
164 } 165 }
165 166
166 xhci_dbg(xhci, "// Reset the HC\n"); 167 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC");
167 command = xhci_readl(xhci, &xhci->op_regs->command); 168 command = xhci_readl(xhci, &xhci->op_regs->command);
168 command |= CMD_RESET; 169 command |= CMD_RESET;
169 xhci_writel(xhci, command, &xhci->op_regs->command); 170 xhci_writel(xhci, command, &xhci->op_regs->command);
@@ -173,7 +174,8 @@ int xhci_reset(struct xhci_hcd *xhci)
173 if (ret) 174 if (ret)
174 return ret; 175 return ret;
175 176
176 xhci_dbg(xhci, "Wait for controller to be ready for doorbell rings\n"); 177 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
178 "Wait for controller to be ready for doorbell rings");
177 /* 179 /*
178 * xHCI cannot write to any doorbells or operational registers other 180 * xHCI cannot write to any doorbells or operational registers other
179 * than status until the "Controller Not Ready" flag is cleared. 181 * than status until the "Controller Not Ready" flag is cleared.
@@ -215,14 +217,16 @@ static int xhci_setup_msi(struct xhci_hcd *xhci)
215 217
216 ret = pci_enable_msi(pdev); 218 ret = pci_enable_msi(pdev);
217 if (ret) { 219 if (ret) {
218 xhci_dbg(xhci, "failed to allocate MSI entry\n"); 220 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
221 "failed to allocate MSI entry");
219 return ret; 222 return ret;
220 } 223 }
221 224
222 ret = request_irq(pdev->irq, xhci_msi_irq, 225 ret = request_irq(pdev->irq, xhci_msi_irq,
223 0, "xhci_hcd", xhci_to_hcd(xhci)); 226 0, "xhci_hcd", xhci_to_hcd(xhci));
224 if (ret) { 227 if (ret) {
225 xhci_dbg(xhci, "disable MSI interrupt\n"); 228 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
229 "disable MSI interrupt");
226 pci_disable_msi(pdev); 230 pci_disable_msi(pdev);
227 } 231 }
228 232
@@ -285,7 +289,8 @@ static int xhci_setup_msix(struct xhci_hcd *xhci)
285 289
286 ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count); 290 ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count);
287 if (ret) { 291 if (ret) {
288 xhci_dbg(xhci, "Failed to enable MSI-X\n"); 292 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
293 "Failed to enable MSI-X");
289 goto free_entries; 294 goto free_entries;
290 } 295 }
291 296
@@ -301,7 +306,7 @@ static int xhci_setup_msix(struct xhci_hcd *xhci)
301 return ret; 306 return ret;
302 307
303disable_msix: 308disable_msix:
304 xhci_dbg(xhci, "disable MSI-X interrupt\n"); 309 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI-X interrupt");
305 xhci_free_irq(xhci); 310 xhci_free_irq(xhci);
306 pci_disable_msix(pdev); 311 pci_disable_msix(pdev);
307free_entries: 312free_entries:
@@ -423,9 +428,11 @@ static void compliance_mode_recovery(unsigned long arg)
423 * Compliance Mode Detected. Letting USB Core 428 * Compliance Mode Detected. Letting USB Core
424 * handle the Warm Reset 429 * handle the Warm Reset
425 */ 430 */
426 xhci_dbg(xhci, "Compliance mode detected->port %d\n", 431 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
432 "Compliance mode detected->port %d",
427 i + 1); 433 i + 1);
428 xhci_dbg(xhci, "Attempting compliance mode recovery\n"); 434 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
435 "Attempting compliance mode recovery");
429 hcd = xhci->shared_hcd; 436 hcd = xhci->shared_hcd;
430 437
431 if (hcd->state == HC_STATE_SUSPENDED) 438 if (hcd->state == HC_STATE_SUSPENDED)
@@ -463,7 +470,8 @@ static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci)
463 set_timer_slack(&xhci->comp_mode_recovery_timer, 470 set_timer_slack(&xhci->comp_mode_recovery_timer,
464 msecs_to_jiffies(COMP_MODE_RCVRY_MSECS)); 471 msecs_to_jiffies(COMP_MODE_RCVRY_MSECS));
465 add_timer(&xhci->comp_mode_recovery_timer); 472 add_timer(&xhci->comp_mode_recovery_timer);
466 xhci_dbg(xhci, "Compliance mode recovery timer initialized\n"); 473 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
474 "Compliance mode recovery timer initialized");
467} 475}
468 476
469/* 477/*
@@ -511,16 +519,18 @@ int xhci_init(struct usb_hcd *hcd)
511 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 519 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
512 int retval = 0; 520 int retval = 0;
513 521
514 xhci_dbg(xhci, "xhci_init\n"); 522 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init");
515 spin_lock_init(&xhci->lock); 523 spin_lock_init(&xhci->lock);
516 if (xhci->hci_version == 0x95 && link_quirk) { 524 if (xhci->hci_version == 0x95 && link_quirk) {
517 xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits.\n"); 525 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
526 "QUIRK: Not clearing Link TRB chain bits.");
518 xhci->quirks |= XHCI_LINK_TRB_QUIRK; 527 xhci->quirks |= XHCI_LINK_TRB_QUIRK;
519 } else { 528 } else {
520 xhci_dbg(xhci, "xHCI doesn't need link TRB QUIRK\n"); 529 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
530 "xHCI doesn't need link TRB QUIRK");
521 } 531 }
522 retval = xhci_mem_init(xhci, GFP_KERNEL); 532 retval = xhci_mem_init(xhci, GFP_KERNEL);
523 xhci_dbg(xhci, "Finished xhci_init\n"); 533 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_init");
524 534
525 /* Initializing Compliance Mode Recovery Data If Needed */ 535 /* Initializing Compliance Mode Recovery Data If Needed */
526 if (xhci_compliance_mode_recovery_timer_quirk_check()) { 536 if (xhci_compliance_mode_recovery_timer_quirk_check()) {
@@ -534,57 +544,6 @@ int xhci_init(struct usb_hcd *hcd)
534/*-------------------------------------------------------------------------*/ 544/*-------------------------------------------------------------------------*/
535 545
536 546
537#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
538static void xhci_event_ring_work(unsigned long arg)
539{
540 unsigned long flags;
541 int temp;
542 u64 temp_64;
543 struct xhci_hcd *xhci = (struct xhci_hcd *) arg;
544 int i, j;
545
546 xhci_dbg(xhci, "Poll event ring: %lu\n", jiffies);
547
548 spin_lock_irqsave(&xhci->lock, flags);
549 temp = xhci_readl(xhci, &xhci->op_regs->status);
550 xhci_dbg(xhci, "op reg status = 0x%x\n", temp);
551 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) ||
552 (xhci->xhc_state & XHCI_STATE_HALTED)) {
553 xhci_dbg(xhci, "HW died, polling stopped.\n");
554 spin_unlock_irqrestore(&xhci->lock, flags);
555 return;
556 }
557
558 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
559 xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp);
560 xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask);
561 xhci->error_bitmask = 0;
562 xhci_dbg(xhci, "Event ring:\n");
563 xhci_debug_segment(xhci, xhci->event_ring->deq_seg);
564 xhci_dbg_ring_ptrs(xhci, xhci->event_ring);
565 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
566 temp_64 &= ~ERST_PTR_MASK;
567 xhci_dbg(xhci, "ERST deq = 64'h%0lx\n", (long unsigned int) temp_64);
568 xhci_dbg(xhci, "Command ring:\n");
569 xhci_debug_segment(xhci, xhci->cmd_ring->deq_seg);
570 xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring);
571 xhci_dbg_cmd_ptrs(xhci);
572 for (i = 0; i < MAX_HC_SLOTS; ++i) {
573 if (!xhci->devs[i])
574 continue;
575 for (j = 0; j < 31; ++j) {
576 xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]);
577 }
578 }
579 spin_unlock_irqrestore(&xhci->lock, flags);
580
581 if (!xhci->zombie)
582 mod_timer(&xhci->event_ring_timer, jiffies + POLL_TIMEOUT * HZ);
583 else
584 xhci_dbg(xhci, "Quit polling the event ring.\n");
585}
586#endif
587
588static int xhci_run_finished(struct xhci_hcd *xhci) 547static int xhci_run_finished(struct xhci_hcd *xhci)
589{ 548{
590 if (xhci_start(xhci)) { 549 if (xhci_start(xhci)) {
@@ -597,7 +556,8 @@ static int xhci_run_finished(struct xhci_hcd *xhci)
597 if (xhci->quirks & XHCI_NEC_HOST) 556 if (xhci->quirks & XHCI_NEC_HOST)
598 xhci_ring_cmd_db(xhci); 557 xhci_ring_cmd_db(xhci);
599 558
600 xhci_dbg(xhci, "Finished xhci_run for USB3 roothub\n"); 559 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
560 "Finished xhci_run for USB3 roothub");
601 return 0; 561 return 0;
602} 562}
603 563
@@ -628,23 +588,12 @@ int xhci_run(struct usb_hcd *hcd)
628 if (!usb_hcd_is_primary_hcd(hcd)) 588 if (!usb_hcd_is_primary_hcd(hcd))
629 return xhci_run_finished(xhci); 589 return xhci_run_finished(xhci);
630 590
631 xhci_dbg(xhci, "xhci_run\n"); 591 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_run");
632 592
633 ret = xhci_try_enable_msi(hcd); 593 ret = xhci_try_enable_msi(hcd);
634 if (ret) 594 if (ret)
635 return ret; 595 return ret;
636 596
637#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
638 init_timer(&xhci->event_ring_timer);
639 xhci->event_ring_timer.data = (unsigned long) xhci;
640 xhci->event_ring_timer.function = xhci_event_ring_work;
641 /* Poll the event ring */
642 xhci->event_ring_timer.expires = jiffies + POLL_TIMEOUT * HZ;
643 xhci->zombie = 0;
644 xhci_dbg(xhci, "Setting event ring polling timer\n");
645 add_timer(&xhci->event_ring_timer);
646#endif
647
648 xhci_dbg(xhci, "Command ring memory map follows:\n"); 597 xhci_dbg(xhci, "Command ring memory map follows:\n");
649 xhci_debug_ring(xhci, xhci->cmd_ring); 598 xhci_debug_ring(xhci, xhci->cmd_ring);
650 xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring); 599 xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring);
@@ -657,9 +606,11 @@ int xhci_run(struct usb_hcd *hcd)
657 xhci_dbg_ring_ptrs(xhci, xhci->event_ring); 606 xhci_dbg_ring_ptrs(xhci, xhci->event_ring);
658 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 607 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
659 temp_64 &= ~ERST_PTR_MASK; 608 temp_64 &= ~ERST_PTR_MASK;
660 xhci_dbg(xhci, "ERST deq = 64'h%0lx\n", (long unsigned int) temp_64); 609 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
610 "ERST deq = 64'h%0lx", (long unsigned int) temp_64);
661 611
662 xhci_dbg(xhci, "// Set the interrupt modulation register\n"); 612 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
613 "// Set the interrupt modulation register");
663 temp = xhci_readl(xhci, &xhci->ir_set->irq_control); 614 temp = xhci_readl(xhci, &xhci->ir_set->irq_control);
664 temp &= ~ER_IRQ_INTERVAL_MASK; 615 temp &= ~ER_IRQ_INTERVAL_MASK;
665 temp |= (u32) 160; 616 temp |= (u32) 160;
@@ -668,12 +619,13 @@ int xhci_run(struct usb_hcd *hcd)
668 /* Set the HCD state before we enable the irqs */ 619 /* Set the HCD state before we enable the irqs */
669 temp = xhci_readl(xhci, &xhci->op_regs->command); 620 temp = xhci_readl(xhci, &xhci->op_regs->command);
670 temp |= (CMD_EIE); 621 temp |= (CMD_EIE);
671 xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n", 622 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
672 temp); 623 "// Enable interrupts, cmd = 0x%x.", temp);
673 xhci_writel(xhci, temp, &xhci->op_regs->command); 624 xhci_writel(xhci, temp, &xhci->op_regs->command);
674 625
675 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); 626 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
676 xhci_dbg(xhci, "// Enabling event ring interrupter %p by writing 0x%x to irq_pending\n", 627 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
628 "// Enabling event ring interrupter %p by writing 0x%x to irq_pending",
677 xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp)); 629 xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp));
678 xhci_writel(xhci, ER_IRQ_ENABLE(temp), 630 xhci_writel(xhci, ER_IRQ_ENABLE(temp),
679 &xhci->ir_set->irq_pending); 631 &xhci->ir_set->irq_pending);
@@ -683,7 +635,8 @@ int xhci_run(struct usb_hcd *hcd)
683 xhci_queue_vendor_command(xhci, 0, 0, 0, 635 xhci_queue_vendor_command(xhci, 0, 0, 0,
684 TRB_TYPE(TRB_NEC_GET_FW)); 636 TRB_TYPE(TRB_NEC_GET_FW));
685 637
686 xhci_dbg(xhci, "Finished xhci_run for USB2 roothub\n"); 638 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
639 "Finished xhci_run for USB2 roothub");
687 return 0; 640 return 0;
688} 641}
689 642
@@ -731,24 +684,20 @@ void xhci_stop(struct usb_hcd *hcd)
731 684
732 xhci_cleanup_msix(xhci); 685 xhci_cleanup_msix(xhci);
733 686
734#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
735 /* Tell the event ring poll function not to reschedule */
736 xhci->zombie = 1;
737 del_timer_sync(&xhci->event_ring_timer);
738#endif
739
740 /* Deleting Compliance Mode Recovery Timer */ 687 /* Deleting Compliance Mode Recovery Timer */
741 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && 688 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
742 (!(xhci_all_ports_seen_u0(xhci)))) { 689 (!(xhci_all_ports_seen_u0(xhci)))) {
743 del_timer_sync(&xhci->comp_mode_recovery_timer); 690 del_timer_sync(&xhci->comp_mode_recovery_timer);
744 xhci_dbg(xhci, "%s: compliance mode recovery timer deleted\n", 691 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
692 "%s: compliance mode recovery timer deleted",
745 __func__); 693 __func__);
746 } 694 }
747 695
748 if (xhci->quirks & XHCI_AMD_PLL_FIX) 696 if (xhci->quirks & XHCI_AMD_PLL_FIX)
749 usb_amd_dev_put(); 697 usb_amd_dev_put();
750 698
751 xhci_dbg(xhci, "// Disabling event ring interrupts\n"); 699 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
700 "// Disabling event ring interrupts");
752 temp = xhci_readl(xhci, &xhci->op_regs->status); 701 temp = xhci_readl(xhci, &xhci->op_regs->status);
753 xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status); 702 xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status);
754 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); 703 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
@@ -756,10 +705,11 @@ void xhci_stop(struct usb_hcd *hcd)
756 &xhci->ir_set->irq_pending); 705 &xhci->ir_set->irq_pending);
757 xhci_print_ir_set(xhci, 0); 706 xhci_print_ir_set(xhci, 0);
758 707
759 xhci_dbg(xhci, "cleaning up memory\n"); 708 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory");
760 xhci_mem_cleanup(xhci); 709 xhci_mem_cleanup(xhci);
761 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", 710 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
762 xhci_readl(xhci, &xhci->op_regs->status)); 711 "xhci_stop completed - status = %x",
712 xhci_readl(xhci, &xhci->op_regs->status));
763} 713}
764 714
765/* 715/*
@@ -784,8 +734,9 @@ void xhci_shutdown(struct usb_hcd *hcd)
784 734
785 xhci_cleanup_msix(xhci); 735 xhci_cleanup_msix(xhci);
786 736
787 xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n", 737 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
788 xhci_readl(xhci, &xhci->op_regs->status)); 738 "xhci_shutdown completed - status = %x",
739 xhci_readl(xhci, &xhci->op_regs->status));
789} 740}
790 741
791#ifdef CONFIG_PM 742#ifdef CONFIG_PM
@@ -826,7 +777,8 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
826 xhci->cmd_ring->dequeue) & 777 xhci->cmd_ring->dequeue) &
827 (u64) ~CMD_RING_RSVD_BITS) | 778 (u64) ~CMD_RING_RSVD_BITS) |
828 xhci->cmd_ring->cycle_state; 779 xhci->cmd_ring->cycle_state;
829 xhci_dbg(xhci, "// Setting command ring address to 0x%llx\n", 780 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
781 "// Setting command ring address to 0x%llx",
830 (long unsigned long) val_64); 782 (long unsigned long) val_64);
831 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); 783 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
832} 784}
@@ -939,7 +891,8 @@ int xhci_suspend(struct xhci_hcd *xhci)
939 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && 891 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
940 (!(xhci_all_ports_seen_u0(xhci)))) { 892 (!(xhci_all_ports_seen_u0(xhci)))) {
941 del_timer_sync(&xhci->comp_mode_recovery_timer); 893 del_timer_sync(&xhci->comp_mode_recovery_timer);
942 xhci_dbg(xhci, "%s: compliance mode recovery timer deleted\n", 894 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
895 "%s: compliance mode recovery timer deleted",
943 __func__); 896 __func__);
944 } 897 }
945 898
@@ -1004,7 +957,8 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
1004 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && 957 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
1005 !(xhci_all_ports_seen_u0(xhci))) { 958 !(xhci_all_ports_seen_u0(xhci))) {
1006 del_timer_sync(&xhci->comp_mode_recovery_timer); 959 del_timer_sync(&xhci->comp_mode_recovery_timer);
1007 xhci_dbg(xhci, "Compliance Mode Recovery Timer deleted!\n"); 960 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
961 "Compliance Mode Recovery Timer deleted!");
1008 } 962 }
1009 963
1010 /* Let the USB core know _both_ roothubs lost power. */ 964 /* Let the USB core know _both_ roothubs lost power. */
@@ -1017,12 +971,6 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
1017 spin_unlock_irq(&xhci->lock); 971 spin_unlock_irq(&xhci->lock);
1018 xhci_cleanup_msix(xhci); 972 xhci_cleanup_msix(xhci);
1019 973
1020#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
1021 /* Tell the event ring poll function not to reschedule */
1022 xhci->zombie = 1;
1023 del_timer_sync(&xhci->event_ring_timer);
1024#endif
1025
1026 xhci_dbg(xhci, "// Disabling event ring interrupts\n"); 974 xhci_dbg(xhci, "// Disabling event ring interrupts\n");
1027 temp = xhci_readl(xhci, &xhci->op_regs->status); 975 temp = xhci_readl(xhci, &xhci->op_regs->status);
1028 xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status); 976 xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status);
@@ -1176,27 +1124,25 @@ static int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev,
1176 struct xhci_virt_device *virt_dev; 1124 struct xhci_virt_device *virt_dev;
1177 1125
1178 if (!hcd || (check_ep && !ep) || !udev) { 1126 if (!hcd || (check_ep && !ep) || !udev) {
1179 printk(KERN_DEBUG "xHCI %s called with invalid args\n", 1127 pr_debug("xHCI %s called with invalid args\n", func);
1180 func);
1181 return -EINVAL; 1128 return -EINVAL;
1182 } 1129 }
1183 if (!udev->parent) { 1130 if (!udev->parent) {
1184 printk(KERN_DEBUG "xHCI %s called for root hub\n", 1131 pr_debug("xHCI %s called for root hub\n", func);
1185 func);
1186 return 0; 1132 return 0;
1187 } 1133 }
1188 1134
1189 xhci = hcd_to_xhci(hcd); 1135 xhci = hcd_to_xhci(hcd);
1190 if (check_virt_dev) { 1136 if (check_virt_dev) {
1191 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { 1137 if (!udev->slot_id || !xhci->devs[udev->slot_id]) {
1192 printk(KERN_DEBUG "xHCI %s called with unaddressed " 1138 xhci_dbg(xhci, "xHCI %s called with unaddressed device\n",
1193 "device\n", func); 1139 func);
1194 return -EINVAL; 1140 return -EINVAL;
1195 } 1141 }
1196 1142
1197 virt_dev = xhci->devs[udev->slot_id]; 1143 virt_dev = xhci->devs[udev->slot_id];
1198 if (virt_dev->udev != udev) { 1144 if (virt_dev->udev != udev) {
1199 printk(KERN_DEBUG "xHCI %s called with udev and " 1145 xhci_dbg(xhci, "xHCI %s called with udev and "
1200 "virt_dev does not match\n", func); 1146 "virt_dev does not match\n", func);
1201 return -EINVAL; 1147 return -EINVAL;
1202 } 1148 }
@@ -1234,12 +1180,16 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
1234 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); 1180 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2));
1235 max_packet_size = usb_endpoint_maxp(&urb->dev->ep0.desc); 1181 max_packet_size = usb_endpoint_maxp(&urb->dev->ep0.desc);
1236 if (hw_max_packet_size != max_packet_size) { 1182 if (hw_max_packet_size != max_packet_size) {
1237 xhci_dbg(xhci, "Max Packet Size for ep 0 changed.\n"); 1183 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1238 xhci_dbg(xhci, "Max packet size in usb_device = %d\n", 1184 "Max Packet Size for ep 0 changed.");
1185 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1186 "Max packet size in usb_device = %d",
1239 max_packet_size); 1187 max_packet_size);
1240 xhci_dbg(xhci, "Max packet size in xHCI HW = %d\n", 1188 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1189 "Max packet size in xHCI HW = %d",
1241 hw_max_packet_size); 1190 hw_max_packet_size);
1242 xhci_dbg(xhci, "Issuing evaluate context command.\n"); 1191 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1192 "Issuing evaluate context command.");
1243 1193
1244 /* Set up the input context flags for the command */ 1194 /* Set up the input context flags for the command */
1245 /* FIXME: This won't work if a non-default control endpoint 1195 /* FIXME: This won't work if a non-default control endpoint
@@ -1504,7 +1454,8 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1504 goto done; 1454 goto done;
1505 temp = xhci_readl(xhci, &xhci->op_regs->status); 1455 temp = xhci_readl(xhci, &xhci->op_regs->status);
1506 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) { 1456 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) {
1507 xhci_dbg(xhci, "HW died, freeing TD.\n"); 1457 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
1458 "HW died, freeing TD.");
1508 urb_priv = urb->hcpriv; 1459 urb_priv = urb->hcpriv;
1509 for (i = urb_priv->td_cnt; i < urb_priv->length; i++) { 1460 for (i = urb_priv->td_cnt; i < urb_priv->length; i++) {
1510 td = urb_priv->td[i]; 1461 td = urb_priv->td[i];
@@ -1522,8 +1473,9 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1522 } 1473 }
1523 if ((xhci->xhc_state & XHCI_STATE_DYING) || 1474 if ((xhci->xhc_state & XHCI_STATE_DYING) ||
1524 (xhci->xhc_state & XHCI_STATE_HALTED)) { 1475 (xhci->xhc_state & XHCI_STATE_HALTED)) {
1525 xhci_dbg(xhci, "Ep 0x%x: URB %p to be canceled on " 1476 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
1526 "non-responsive xHCI host.\n", 1477 "Ep 0x%x: URB %p to be canceled on "
1478 "non-responsive xHCI host.",
1527 urb->ep->desc.bEndpointAddress, urb); 1479 urb->ep->desc.bEndpointAddress, urb);
1528 /* Let the stop endpoint command watchdog timer (which set this 1480 /* Let the stop endpoint command watchdog timer (which set this
1529 * state) finish cleaning up the endpoint TD lists. We must 1481 * state) finish cleaning up the endpoint TD lists. We must
@@ -1544,8 +1496,9 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1544 urb_priv = urb->hcpriv; 1496 urb_priv = urb->hcpriv;
1545 i = urb_priv->td_cnt; 1497 i = urb_priv->td_cnt;
1546 if (i < urb_priv->length) 1498 if (i < urb_priv->length)
1547 xhci_dbg(xhci, "Cancel URB %p, dev %s, ep 0x%x, " 1499 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
1548 "starting at offset 0x%llx\n", 1500 "Cancel URB %p, dev %s, ep 0x%x, "
1501 "starting at offset 0x%llx",
1549 urb, urb->dev->devpath, 1502 urb, urb->dev->devpath,
1550 urb->ep->desc.bEndpointAddress, 1503 urb->ep->desc.bEndpointAddress,
1551 (unsigned long long) xhci_trb_virt_to_dma( 1504 (unsigned long long) xhci_trb_virt_to_dma(
@@ -1857,7 +1810,8 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
1857 ret = -ENODEV; 1810 ret = -ENODEV;
1858 break; 1811 break;
1859 case COMP_SUCCESS: 1812 case COMP_SUCCESS:
1860 dev_dbg(&udev->dev, "Successful Endpoint Configure command\n"); 1813 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1814 "Successful Endpoint Configure command");
1861 ret = 0; 1815 ret = 0;
1862 break; 1816 break;
1863 default: 1817 default:
@@ -1903,7 +1857,8 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci,
1903 ret = -EINVAL; 1857 ret = -EINVAL;
1904 break; 1858 break;
1905 case COMP_SUCCESS: 1859 case COMP_SUCCESS:
1906 dev_dbg(&udev->dev, "Successful evaluate context command\n"); 1860 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1861 "Successful evaluate context command");
1907 ret = 0; 1862 ret = 0;
1908 break; 1863 break;
1909 default: 1864 default:
@@ -1969,14 +1924,16 @@ static int xhci_reserve_host_resources(struct xhci_hcd *xhci,
1969 1924
1970 added_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); 1925 added_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx);
1971 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { 1926 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) {
1972 xhci_dbg(xhci, "Not enough ep ctxs: " 1927 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1973 "%u active, need to add %u, limit is %u.\n", 1928 "Not enough ep ctxs: "
1929 "%u active, need to add %u, limit is %u.",
1974 xhci->num_active_eps, added_eps, 1930 xhci->num_active_eps, added_eps,
1975 xhci->limit_active_eps); 1931 xhci->limit_active_eps);
1976 return -ENOMEM; 1932 return -ENOMEM;
1977 } 1933 }
1978 xhci->num_active_eps += added_eps; 1934 xhci->num_active_eps += added_eps;
1979 xhci_dbg(xhci, "Adding %u ep ctxs, %u now active.\n", added_eps, 1935 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1936 "Adding %u ep ctxs, %u now active.", added_eps,
1980 xhci->num_active_eps); 1937 xhci->num_active_eps);
1981 return 0; 1938 return 0;
1982} 1939}
@@ -1994,7 +1951,8 @@ static void xhci_free_host_resources(struct xhci_hcd *xhci,
1994 1951
1995 num_failed_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); 1952 num_failed_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx);
1996 xhci->num_active_eps -= num_failed_eps; 1953 xhci->num_active_eps -= num_failed_eps;
1997 xhci_dbg(xhci, "Removing %u failed ep ctxs, %u now active.\n", 1954 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1955 "Removing %u failed ep ctxs, %u now active.",
1998 num_failed_eps, 1956 num_failed_eps,
1999 xhci->num_active_eps); 1957 xhci->num_active_eps);
2000} 1958}
@@ -2013,7 +1971,8 @@ static void xhci_finish_resource_reservation(struct xhci_hcd *xhci,
2013 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, ctrl_ctx); 1971 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, ctrl_ctx);
2014 xhci->num_active_eps -= num_dropped_eps; 1972 xhci->num_active_eps -= num_dropped_eps;
2015 if (num_dropped_eps) 1973 if (num_dropped_eps)
2016 xhci_dbg(xhci, "Removing %u dropped ep ctxs, %u now active.\n", 1974 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1975 "Removing %u dropped ep ctxs, %u now active.",
2017 num_dropped_eps, 1976 num_dropped_eps,
2018 xhci->num_active_eps); 1977 xhci->num_active_eps);
2019} 1978}
@@ -2174,18 +2133,21 @@ static int xhci_check_bw_table(struct xhci_hcd *xhci,
2174 * that the HS bus has enough bandwidth if we are activing a new TT. 2133 * that the HS bus has enough bandwidth if we are activing a new TT.
2175 */ 2134 */
2176 if (virt_dev->tt_info) { 2135 if (virt_dev->tt_info) {
2177 xhci_dbg(xhci, "Recalculating BW for rootport %u\n", 2136 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
2137 "Recalculating BW for rootport %u",
2178 virt_dev->real_port); 2138 virt_dev->real_port);
2179 if (xhci_check_tt_bw_table(xhci, virt_dev, old_active_eps)) { 2139 if (xhci_check_tt_bw_table(xhci, virt_dev, old_active_eps)) {
2180 xhci_warn(xhci, "Not enough bandwidth on HS bus for " 2140 xhci_warn(xhci, "Not enough bandwidth on HS bus for "
2181 "newly activated TT.\n"); 2141 "newly activated TT.\n");
2182 return -ENOMEM; 2142 return -ENOMEM;
2183 } 2143 }
2184 xhci_dbg(xhci, "Recalculating BW for TT slot %u port %u\n", 2144 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
2145 "Recalculating BW for TT slot %u port %u",
2185 virt_dev->tt_info->slot_id, 2146 virt_dev->tt_info->slot_id,
2186 virt_dev->tt_info->ttport); 2147 virt_dev->tt_info->ttport);
2187 } else { 2148 } else {
2188 xhci_dbg(xhci, "Recalculating BW for rootport %u\n", 2149 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
2150 "Recalculating BW for rootport %u",
2189 virt_dev->real_port); 2151 virt_dev->real_port);
2190 } 2152 }
2191 2153
@@ -2293,8 +2255,9 @@ static int xhci_check_bw_table(struct xhci_hcd *xhci,
2293 xhci->rh_bw[port_index].num_active_tts; 2255 xhci->rh_bw[port_index].num_active_tts;
2294 } 2256 }
2295 2257
2296 xhci_dbg(xhci, "Final bandwidth: %u, Limit: %u, Reserved: %u, " 2258 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
2297 "Available: %u " "percent\n", 2259 "Final bandwidth: %u, Limit: %u, Reserved: %u, "
2260 "Available: %u " "percent",
2298 bw_used, max_bandwidth, bw_reserved, 2261 bw_used, max_bandwidth, bw_reserved,
2299 (max_bandwidth - bw_used - bw_reserved) * 100 / 2262 (max_bandwidth - bw_used - bw_reserved) * 100 /
2300 max_bandwidth); 2263 max_bandwidth);
@@ -2664,7 +2627,8 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2664 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) 2627 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK))
2665 xhci_free_host_resources(xhci, ctrl_ctx); 2628 xhci_free_host_resources(xhci, ctrl_ctx);
2666 spin_unlock_irqrestore(&xhci->lock, flags); 2629 spin_unlock_irqrestore(&xhci->lock, flags);
2667 xhci_dbg(xhci, "FIXME allocate a new ring segment\n"); 2630 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
2631 "FIXME allocate a new ring segment");
2668 return -ENOMEM; 2632 return -ENOMEM;
2669 } 2633 }
2670 xhci_ring_cmd_db(xhci); 2634 xhci_ring_cmd_db(xhci);
@@ -2877,7 +2841,8 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
2877 struct xhci_dequeue_state deq_state; 2841 struct xhci_dequeue_state deq_state;
2878 struct xhci_virt_ep *ep; 2842 struct xhci_virt_ep *ep;
2879 2843
2880 xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n"); 2844 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2845 "Cleaning up stalled endpoint ring");
2881 ep = &xhci->devs[udev->slot_id]->eps[ep_index]; 2846 ep = &xhci->devs[udev->slot_id]->eps[ep_index];
2882 /* We need to move the HW's dequeue pointer past this TD, 2847 /* We need to move the HW's dequeue pointer past this TD,
2883 * or it will attempt to resend it on the next doorbell ring. 2848 * or it will attempt to resend it on the next doorbell ring.
@@ -2890,7 +2855,8 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
2890 * issue a configure endpoint command later. 2855 * issue a configure endpoint command later.
2891 */ 2856 */
2892 if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) { 2857 if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) {
2893 xhci_dbg(xhci, "Queueing new dequeue state\n"); 2858 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2859 "Queueing new dequeue state");
2894 xhci_queue_new_dequeue_state(xhci, udev->slot_id, 2860 xhci_queue_new_dequeue_state(xhci, udev->slot_id,
2895 ep_index, ep->stopped_stream, &deq_state); 2861 ep_index, ep->stopped_stream, &deq_state);
2896 } else { 2862 } else {
@@ -2899,8 +2865,9 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
2899 * XXX: No idea how this hardware will react when stream rings 2865 * XXX: No idea how this hardware will react when stream rings
2900 * are enabled. 2866 * are enabled.
2901 */ 2867 */
2902 xhci_dbg(xhci, "Setting up input context for " 2868 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
2903 "configure endpoint command\n"); 2869 "Setting up input context for "
2870 "configure endpoint command");
2904 xhci_setup_input_ctx_for_quirk(xhci, udev->slot_id, 2871 xhci_setup_input_ctx_for_quirk(xhci, udev->slot_id,
2905 ep_index, &deq_state); 2872 ep_index, &deq_state);
2906 } 2873 }
@@ -2932,16 +2899,19 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
2932 ep_index = xhci_get_endpoint_index(&ep->desc); 2899 ep_index = xhci_get_endpoint_index(&ep->desc);
2933 virt_ep = &xhci->devs[udev->slot_id]->eps[ep_index]; 2900 virt_ep = &xhci->devs[udev->slot_id]->eps[ep_index];
2934 if (!virt_ep->stopped_td) { 2901 if (!virt_ep->stopped_td) {
2935 xhci_dbg(xhci, "Endpoint 0x%x not halted, refusing to reset.\n", 2902 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2936 ep->desc.bEndpointAddress); 2903 "Endpoint 0x%x not halted, refusing to reset.",
2904 ep->desc.bEndpointAddress);
2937 return; 2905 return;
2938 } 2906 }
2939 if (usb_endpoint_xfer_control(&ep->desc)) { 2907 if (usb_endpoint_xfer_control(&ep->desc)) {
2940 xhci_dbg(xhci, "Control endpoint stall already handled.\n"); 2908 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2909 "Control endpoint stall already handled.");
2941 return; 2910 return;
2942 } 2911 }
2943 2912
2944 xhci_dbg(xhci, "Queueing reset endpoint command\n"); 2913 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2914 "Queueing reset endpoint command");
2945 spin_lock_irqsave(&xhci->lock, flags); 2915 spin_lock_irqsave(&xhci->lock, flags);
2946 ret = xhci_queue_reset_ep(xhci, udev->slot_id, ep_index); 2916 ret = xhci_queue_reset_ep(xhci, udev->slot_id, ep_index);
2947 /* 2917 /*
@@ -3081,8 +3051,8 @@ static u32 xhci_calculate_no_streams_bitmask(struct xhci_hcd *xhci,
3081 /* Are streams already being freed for the endpoint? */ 3051 /* Are streams already being freed for the endpoint? */
3082 if (ep_state & EP_GETTING_NO_STREAMS) { 3052 if (ep_state & EP_GETTING_NO_STREAMS) {
3083 xhci_warn(xhci, "WARN Can't disable streams for " 3053 xhci_warn(xhci, "WARN Can't disable streams for "
3084 "endpoint 0x%x\n, " 3054 "endpoint 0x%x, "
3085 "streams are being disabled already.", 3055 "streams are being disabled already\n",
3086 eps[i]->desc.bEndpointAddress); 3056 eps[i]->desc.bEndpointAddress);
3087 return 0; 3057 return 0;
3088 } 3058 }
@@ -3090,8 +3060,8 @@ static u32 xhci_calculate_no_streams_bitmask(struct xhci_hcd *xhci,
3090 if (!(ep_state & EP_HAS_STREAMS) && 3060 if (!(ep_state & EP_HAS_STREAMS) &&
3091 !(ep_state & EP_GETTING_STREAMS)) { 3061 !(ep_state & EP_GETTING_STREAMS)) {
3092 xhci_warn(xhci, "WARN Can't disable streams for " 3062 xhci_warn(xhci, "WARN Can't disable streams for "
3093 "endpoint 0x%x\n, " 3063 "endpoint 0x%x, "
3094 "streams are already disabled!", 3064 "streams are already disabled!\n",
3095 eps[i]->desc.bEndpointAddress); 3065 eps[i]->desc.bEndpointAddress);
3096 xhci_warn(xhci, "WARN xhci_free_streams() called " 3066 xhci_warn(xhci, "WARN xhci_free_streams() called "
3097 "with non-streams endpoint\n"); 3067 "with non-streams endpoint\n");
@@ -3379,8 +3349,9 @@ void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci,
3379 } 3349 }
3380 xhci->num_active_eps -= num_dropped_eps; 3350 xhci->num_active_eps -= num_dropped_eps;
3381 if (num_dropped_eps) 3351 if (num_dropped_eps)
3382 xhci_dbg(xhci, "Dropped %u ep ctxs, flags = 0x%x, " 3352 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
3383 "%u now active.\n", 3353 "Dropped %u ep ctxs, flags = 0x%x, "
3354 "%u now active.",
3384 num_dropped_eps, drop_flags, 3355 num_dropped_eps, drop_flags,
3385 xhci->num_active_eps); 3356 xhci->num_active_eps);
3386} 3357}
@@ -3514,10 +3485,10 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
3514 switch (ret) { 3485 switch (ret) {
3515 case COMP_EBADSLT: /* 0.95 completion code for bad slot ID */ 3486 case COMP_EBADSLT: /* 0.95 completion code for bad slot ID */
3516 case COMP_CTX_STATE: /* 0.96 completion code for same thing */ 3487 case COMP_CTX_STATE: /* 0.96 completion code for same thing */
3517 xhci_info(xhci, "Can't reset device (slot ID %u) in %s state\n", 3488 xhci_dbg(xhci, "Can't reset device (slot ID %u) in %s state\n",
3518 slot_id, 3489 slot_id,
3519 xhci_get_slot_state(xhci, virt_dev->out_ctx)); 3490 xhci_get_slot_state(xhci, virt_dev->out_ctx));
3520 xhci_info(xhci, "Not freeing device rings.\n"); 3491 xhci_dbg(xhci, "Not freeing device rings.\n");
3521 /* Don't treat this as an error. May change my mind later. */ 3492 /* Don't treat this as an error. May change my mind later. */
3522 ret = 0; 3493 ret = 0;
3523 goto command_cleanup; 3494 goto command_cleanup;
@@ -3642,13 +3613,15 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
3642static int xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci) 3613static int xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci)
3643{ 3614{
3644 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { 3615 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) {
3645 xhci_dbg(xhci, "Not enough ep ctxs: " 3616 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
3646 "%u active, need to add 1, limit is %u.\n", 3617 "Not enough ep ctxs: "
3618 "%u active, need to add 1, limit is %u.",
3647 xhci->num_active_eps, xhci->limit_active_eps); 3619 xhci->num_active_eps, xhci->limit_active_eps);
3648 return -ENOMEM; 3620 return -ENOMEM;
3649 } 3621 }
3650 xhci->num_active_eps += 1; 3622 xhci->num_active_eps += 1;
3651 xhci_dbg(xhci, "Adding 1 ep ctx, %u now active.\n", 3623 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
3624 "Adding 1 ep ctx, %u now active.",
3652 xhci->num_active_eps); 3625 xhci->num_active_eps);
3653 return 0; 3626 return 0;
3654} 3627}
@@ -3748,7 +3721,8 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3748 union xhci_trb *cmd_trb; 3721 union xhci_trb *cmd_trb;
3749 3722
3750 if (!udev->slot_id) { 3723 if (!udev->slot_id) {
3751 xhci_dbg(xhci, "Bad Slot ID %d\n", udev->slot_id); 3724 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3725 "Bad Slot ID %d", udev->slot_id);
3752 return -EINVAL; 3726 return -EINVAL;
3753 } 3727 }
3754 3728
@@ -3787,6 +3761,8 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3787 3761
3788 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); 3762 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id);
3789 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); 3763 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2);
3764 trace_xhci_address_ctx(xhci, virt_dev->in_ctx,
3765 slot_ctx->dev_info >> 27);
3790 3766
3791 spin_lock_irqsave(&xhci->lock, flags); 3767 spin_lock_irqsave(&xhci->lock, flags);
3792 cmd_trb = xhci->cmd_ring->dequeue; 3768 cmd_trb = xhci->cmd_ring->dequeue;
@@ -3794,7 +3770,8 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3794 udev->slot_id); 3770 udev->slot_id);
3795 if (ret) { 3771 if (ret) {
3796 spin_unlock_irqrestore(&xhci->lock, flags); 3772 spin_unlock_irqrestore(&xhci->lock, flags);
3797 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); 3773 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3774 "FIXME: allocate a command ring segment");
3798 return ret; 3775 return ret;
3799 } 3776 }
3800 xhci_ring_cmd_db(xhci); 3777 xhci_ring_cmd_db(xhci);
@@ -3834,13 +3811,15 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3834 ret = -ENODEV; 3811 ret = -ENODEV;
3835 break; 3812 break;
3836 case COMP_SUCCESS: 3813 case COMP_SUCCESS:
3837 xhci_dbg(xhci, "Successful Address Device command\n"); 3814 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3815 "Successful Address Device command");
3838 break; 3816 break;
3839 default: 3817 default:
3840 xhci_err(xhci, "ERROR: unexpected command completion " 3818 xhci_err(xhci, "ERROR: unexpected command completion "
3841 "code 0x%x.\n", virt_dev->cmd_status); 3819 "code 0x%x.\n", virt_dev->cmd_status);
3842 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); 3820 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id);
3843 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); 3821 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2);
3822 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1);
3844 ret = -EINVAL; 3823 ret = -EINVAL;
3845 break; 3824 break;
3846 } 3825 }
@@ -3848,16 +3827,21 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3848 return ret; 3827 return ret;
3849 } 3828 }
3850 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); 3829 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
3851 xhci_dbg(xhci, "Op regs DCBAA ptr = %#016llx\n", temp_64); 3830 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3852 xhci_dbg(xhci, "Slot ID %d dcbaa entry @%p = %#016llx\n", 3831 "Op regs DCBAA ptr = %#016llx", temp_64);
3853 udev->slot_id, 3832 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3854 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], 3833 "Slot ID %d dcbaa entry @%p = %#016llx",
3855 (unsigned long long) 3834 udev->slot_id,
3856 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); 3835 &xhci->dcbaa->dev_context_ptrs[udev->slot_id],
3857 xhci_dbg(xhci, "Output Context DMA address = %#08llx\n", 3836 (unsigned long long)
3837 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id]));
3838 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3839 "Output Context DMA address = %#08llx",
3858 (unsigned long long)virt_dev->out_ctx->dma); 3840 (unsigned long long)virt_dev->out_ctx->dma);
3859 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); 3841 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id);
3860 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); 3842 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2);
3843 trace_xhci_address_ctx(xhci, virt_dev->in_ctx,
3844 slot_ctx->dev_info >> 27);
3861 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); 3845 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id);
3862 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); 3846 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2);
3863 /* 3847 /*
@@ -3865,6 +3849,8 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3865 * address given back to us by the HC. 3849 * address given back to us by the HC.
3866 */ 3850 */
3867 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); 3851 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx);
3852 trace_xhci_address_ctx(xhci, virt_dev->out_ctx,
3853 slot_ctx->dev_info >> 27);
3868 /* Use kernel assigned address for devices; store xHC assigned 3854 /* Use kernel assigned address for devices; store xHC assigned
3869 * address locally. */ 3855 * address locally. */
3870 virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK) 3856 virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK)
@@ -3873,7 +3859,8 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3873 ctrl_ctx->add_flags = 0; 3859 ctrl_ctx->add_flags = 0;
3874 ctrl_ctx->drop_flags = 0; 3860 ctrl_ctx->drop_flags = 0;
3875 3861
3876 xhci_dbg(xhci, "Internal device address = %d\n", virt_dev->address); 3862 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3863 "Internal device address = %d", virt_dev->address);
3877 3864
3878 return 0; 3865 return 0;
3879} 3866}
@@ -3939,7 +3926,8 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci,
3939 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT)); 3926 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT));
3940 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency); 3927 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency);
3941 3928
3942 xhci_dbg(xhci, "Set up evaluate context for LPM MEL change.\n"); 3929 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
3930 "Set up evaluate context for LPM MEL change.");
3943 xhci_dbg(xhci, "Slot %u Input Context:\n", udev->slot_id); 3931 xhci_dbg(xhci, "Slot %u Input Context:\n", udev->slot_id);
3944 xhci_dbg_ctx(xhci, command->in_ctx, 0); 3932 xhci_dbg_ctx(xhci, command->in_ctx, 0);
3945 3933
@@ -4359,7 +4347,7 @@ static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev,
4359 state_name, sel); 4347 state_name, sel);
4360 else 4348 else
4361 dev_dbg(&udev->dev, "Device-initiated %s disabled " 4349 dev_dbg(&udev->dev, "Device-initiated %s disabled "
4362 "due to long PEL %llu\n ms", 4350 "due to long PEL %llu ms\n",
4363 state_name, pel); 4351 state_name, pel);
4364 return USB3_LPM_DISABLED; 4352 return USB3_LPM_DISABLED;
4365} 4353}
@@ -4843,10 +4831,13 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4843 struct xhci_hcd *xhci; 4831 struct xhci_hcd *xhci;
4844 struct device *dev = hcd->self.controller; 4832 struct device *dev = hcd->self.controller;
4845 int retval; 4833 int retval;
4846 u32 temp;
4847 4834
4848 /* Accept arbitrarily long scatter-gather lists */ 4835 /* Accept arbitrarily long scatter-gather lists */
4849 hcd->self.sg_tablesize = ~0; 4836 hcd->self.sg_tablesize = ~0;
4837
4838 /* support to build packet from discontinuous buffers */
4839 hcd->self.no_sg_constraint = 1;
4840
4850 /* XHCI controllers don't stop the ep queue on short packets :| */ 4841 /* XHCI controllers don't stop the ep queue on short packets :| */
4851 hcd->self.no_stop_on_short = 1; 4842 hcd->self.no_stop_on_short = 1;
4852 4843
@@ -4871,14 +4862,6 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4871 /* xHCI private pointer was set in xhci_pci_probe for the second 4862 /* xHCI private pointer was set in xhci_pci_probe for the second
4872 * registered roothub. 4863 * registered roothub.
4873 */ 4864 */
4874 xhci = hcd_to_xhci(hcd);
4875 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
4876 if (HCC_64BIT_ADDR(temp)) {
4877 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
4878 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64));
4879 } else {
4880 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32));
4881 }
4882 return 0; 4865 return 0;
4883 } 4866 }
4884 4867
@@ -4917,12 +4900,12 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4917 goto error; 4900 goto error;
4918 xhci_dbg(xhci, "Reset complete\n"); 4901 xhci_dbg(xhci, "Reset complete\n");
4919 4902
4920 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); 4903 /* Set dma_mask and coherent_dma_mask to 64-bits,
4921 if (HCC_64BIT_ADDR(temp)) { 4904 * if xHC supports 64-bit addressing */
4905 if (HCC_64BIT_ADDR(xhci->hcc_params) &&
4906 !dma_set_mask(dev, DMA_BIT_MASK(64))) {
4922 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); 4907 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
4923 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)); 4908 dma_set_coherent_mask(dev, DMA_BIT_MASK(64));
4924 } else {
4925 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32));
4926 } 4909 }
4927 4910
4928 xhci_dbg(xhci, "Calling HCD init\n"); 4911 xhci_dbg(xhci, "Calling HCD init\n");
@@ -4947,12 +4930,12 @@ static int __init xhci_hcd_init(void)
4947 4930
4948 retval = xhci_register_pci(); 4931 retval = xhci_register_pci();
4949 if (retval < 0) { 4932 if (retval < 0) {
4950 printk(KERN_DEBUG "Problem registering PCI driver."); 4933 pr_debug("Problem registering PCI driver.\n");
4951 return retval; 4934 return retval;
4952 } 4935 }
4953 retval = xhci_register_plat(); 4936 retval = xhci_register_plat();
4954 if (retval < 0) { 4937 if (retval < 0) {
4955 printk(KERN_DEBUG "Problem registering platform driver."); 4938 pr_debug("Problem registering platform driver.\n");
4956 goto unreg_pci; 4939 goto unreg_pci;
4957 } 4940 }
4958 /* 4941 /*
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 6ab1e600dc18..46aa14894148 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1490,11 +1490,6 @@ struct xhci_hcd {
1490 struct dma_pool *small_streams_pool; 1490 struct dma_pool *small_streams_pool;
1491 struct dma_pool *medium_streams_pool; 1491 struct dma_pool *medium_streams_pool;
1492 1492
1493#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
1494 /* Poll the rings - for debugging */
1495 struct timer_list event_ring_timer;
1496 int zombie;
1497#endif
1498 /* Host controller watchdog timer structures */ 1493 /* Host controller watchdog timer structures */
1499 unsigned int xhc_state; 1494 unsigned int xhc_state;
1500 1495
@@ -1580,16 +1575,8 @@ static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1580 return xhci->main_hcd; 1575 return xhci->main_hcd;
1581} 1576}
1582 1577
1583#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
1584#define XHCI_DEBUG 1
1585#else
1586#define XHCI_DEBUG 0
1587#endif
1588
1589#define xhci_dbg(xhci, fmt, args...) \ 1578#define xhci_dbg(xhci, fmt, args...) \
1590 do { if (XHCI_DEBUG) dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0) 1579 dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1591#define xhci_info(xhci, fmt, args...) \
1592 do { if (XHCI_DEBUG) dev_info(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0)
1593#define xhci_err(xhci, fmt, args...) \ 1580#define xhci_err(xhci, fmt, args...) \
1594 dev_err(xhci_to_hcd(xhci)->self.controller , fmt , ## args) 1581 dev_err(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1595#define xhci_warn(xhci, fmt, args...) \ 1582#define xhci_warn(xhci, fmt, args...) \
@@ -1661,6 +1648,8 @@ char *xhci_get_slot_state(struct xhci_hcd *xhci,
1661void xhci_dbg_ep_rings(struct xhci_hcd *xhci, 1648void xhci_dbg_ep_rings(struct xhci_hcd *xhci,
1662 unsigned int slot_id, unsigned int ep_index, 1649 unsigned int slot_id, unsigned int ep_index,
1663 struct xhci_virt_ep *ep); 1650 struct xhci_virt_ep *ep);
1651void xhci_dbg_trace(struct xhci_hcd *xhci, void (*trace)(struct va_format *),
1652 const char *fmt, ...);
1664 1653
1665/* xHCI memory management */ 1654/* xHCI memory management */
1666void xhci_mem_cleanup(struct xhci_hcd *xhci); 1655void xhci_mem_cleanup(struct xhci_hcd *xhci);
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index a51e7d6afda9..e2b21c1d9c40 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -200,6 +200,19 @@ config USB_TEST
200 See <http://www.linux-usb.org/usbtest/> for more information, 200 See <http://www.linux-usb.org/usbtest/> for more information,
201 including sample test device firmware and "how to use it". 201 including sample test device firmware and "how to use it".
202 202
203config USB_EHSET_TEST_FIXTURE
204 tristate "USB EHSET Test Fixture driver"
205 help
206 Say Y here if you want to support the special test fixture device
207 used for the USB-IF Embedded Host High-Speed Electrical Test procedure.
208
209 When the test fixture is connected, it can enumerate as one of several
210 VID/PID pairs. This driver then initiates a corresponding test mode on
211 the downstream port to which the test fixture is attached.
212
213 See <http://www.usb.org/developers/onthego/EHSET_v1.01.pdf> for more
214 information.
215
203config USB_ISIGHTFW 216config USB_ISIGHTFW
204 tristate "iSight firmware loading support" 217 tristate "iSight firmware loading support"
205 select FW_LOADER 218 select FW_LOADER
@@ -233,5 +246,6 @@ config USB_EZUSB_FX2
233config USB_HSIC_USB3503 246config USB_HSIC_USB3503
234 tristate "USB3503 HSIC to USB20 Driver" 247 tristate "USB3503 HSIC to USB20 Driver"
235 depends on I2C 248 depends on I2C
249 select REGMAP
236 help 250 help
237 This option enables support for SMSC USB3503 HSIC to USB 2.0 Driver. 251 This option enables support for SMSC USB3503 HSIC to USB 2.0 Driver.
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 3e1bd70b06ea..e748fd5dbe94 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -2,9 +2,6 @@
2# Makefile for the rest of the USB drivers 2# Makefile for the rest of the USB drivers
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
6ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
7
8obj-$(CONFIG_USB_ADUTUX) += adutux.o 5obj-$(CONFIG_USB_ADUTUX) += adutux.o
9obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o 6obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o
10obj-$(CONFIG_USB_CYPRESS_CY7C63) += cypress_cy7c63.o 7obj-$(CONFIG_USB_CYPRESS_CY7C63) += cypress_cy7c63.o
@@ -22,6 +19,7 @@ obj-$(CONFIG_USB_LED) += usbled.o
22obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o 19obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
23obj-$(CONFIG_USB_RIO500) += rio500.o 20obj-$(CONFIG_USB_RIO500) += rio500.o
24obj-$(CONFIG_USB_TEST) += usbtest.o 21obj-$(CONFIG_USB_TEST) += usbtest.o
22obj-$(CONFIG_USB_EHSET_TEST_FIXTURE) += ehset.o
25obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o 23obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
26obj-$(CONFIG_USB_USS720) += uss720.o 24obj-$(CONFIG_USB_USS720) += uss720.o
27obj-$(CONFIG_USB_SEVSEG) += usbsevseg.o 25obj-$(CONFIG_USB_SEVSEG) += usbsevseg.o
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index eeb27208c0d1..3eaa83f05086 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -18,6 +18,8 @@
18 * 18 *
19 */ 19 */
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
21#include <linux/kernel.h> 23#include <linux/kernel.h>
22#include <linux/errno.h> 24#include <linux/errno.h>
23#include <linux/init.h> 25#include <linux/init.h>
@@ -27,30 +29,11 @@
27#include <linux/mutex.h> 29#include <linux/mutex.h>
28#include <linux/uaccess.h> 30#include <linux/uaccess.h>
29 31
30#ifdef CONFIG_USB_DEBUG
31static int debug = 5;
32#else
33static int debug = 1;
34#endif
35
36/* Use our own dbg macro */
37#undef dbg
38#define dbg(lvl, format, arg...) \
39do { \
40 if (debug >= lvl) \
41 printk(KERN_DEBUG "%s: " format "\n", __FILE__, ##arg); \
42} while (0)
43
44
45/* Version Information */ 32/* Version Information */
46#define DRIVER_VERSION "v0.0.13" 33#define DRIVER_VERSION "v0.0.13"
47#define DRIVER_AUTHOR "John Homppi" 34#define DRIVER_AUTHOR "John Homppi"
48#define DRIVER_DESC "adutux (see www.ontrak.net)" 35#define DRIVER_DESC "adutux (see www.ontrak.net)"
49 36
50/* Module parameters */
51module_param(debug, int, S_IRUGO | S_IWUSR);
52MODULE_PARM_DESC(debug, "Debug enabled or not");
53
54/* Define these values to match your device */ 37/* Define these values to match your device */
55#define ADU_VENDOR_ID 0x0a07 38#define ADU_VENDOR_ID 0x0a07
56#define ADU_PRODUCT_ID 0x0064 39#define ADU_PRODUCT_ID 0x0064
@@ -124,19 +107,11 @@ static DEFINE_MUTEX(adutux_mutex);
124 107
125static struct usb_driver adu_driver; 108static struct usb_driver adu_driver;
126 109
127static void adu_debug_data(int level, const char *function, int size, 110static inline void adu_debug_data(struct device *dev, const char *function,
128 const unsigned char *data) 111 int size, const unsigned char *data)
129{ 112{
130 int i; 113 dev_dbg(dev, "%s - length = %d, data = %*ph\n",
131 114 function, size, size, data);
132 if (debug < level)
133 return;
134
135 printk(KERN_DEBUG "%s: %s - length = %d, data = ",
136 __FILE__, function, size);
137 for (i = 0; i < size; ++i)
138 printk("%.2x ", data[i]);
139 printk("\n");
140} 115}
141 116
142/** 117/**
@@ -147,12 +122,8 @@ static void adu_abort_transfers(struct adu_device *dev)
147{ 122{
148 unsigned long flags; 123 unsigned long flags;
149 124
150 dbg(2, " %s : enter", __func__); 125 if (dev->udev == NULL)
151 126 return;
152 if (dev->udev == NULL) {
153 dbg(1, " %s : udev is null", __func__);
154 goto exit;
155 }
156 127
157 /* shutdown transfer */ 128 /* shutdown transfer */
158 129
@@ -170,15 +141,10 @@ static void adu_abort_transfers(struct adu_device *dev)
170 usb_kill_urb(dev->interrupt_out_urb); 141 usb_kill_urb(dev->interrupt_out_urb);
171 } else 142 } else
172 spin_unlock_irqrestore(&dev->buflock, flags); 143 spin_unlock_irqrestore(&dev->buflock, flags);
173
174exit:
175 dbg(2, " %s : leave", __func__);
176} 144}
177 145
178static void adu_delete(struct adu_device *dev) 146static void adu_delete(struct adu_device *dev)
179{ 147{
180 dbg(2, "%s enter", __func__);
181
182 /* free data structures */ 148 /* free data structures */
183 usb_free_urb(dev->interrupt_in_urb); 149 usb_free_urb(dev->interrupt_in_urb);
184 usb_free_urb(dev->interrupt_out_urb); 150 usb_free_urb(dev->interrupt_out_urb);
@@ -187,8 +153,6 @@ static void adu_delete(struct adu_device *dev)
187 kfree(dev->interrupt_in_buffer); 153 kfree(dev->interrupt_in_buffer);
188 kfree(dev->interrupt_out_buffer); 154 kfree(dev->interrupt_out_buffer);
189 kfree(dev); 155 kfree(dev);
190
191 dbg(2, "%s : leave", __func__);
192} 156}
193 157
194static void adu_interrupt_in_callback(struct urb *urb) 158static void adu_interrupt_in_callback(struct urb *urb)
@@ -196,17 +160,17 @@ static void adu_interrupt_in_callback(struct urb *urb)
196 struct adu_device *dev = urb->context; 160 struct adu_device *dev = urb->context;
197 int status = urb->status; 161 int status = urb->status;
198 162
199 dbg(4, " %s : enter, status %d", __func__, status); 163 adu_debug_data(&dev->udev->dev, __func__,
200 adu_debug_data(5, __func__, urb->actual_length, 164 urb->actual_length, urb->transfer_buffer);
201 urb->transfer_buffer);
202 165
203 spin_lock(&dev->buflock); 166 spin_lock(&dev->buflock);
204 167
205 if (status != 0) { 168 if (status != 0) {
206 if ((status != -ENOENT) && (status != -ECONNRESET) && 169 if ((status != -ENOENT) && (status != -ECONNRESET) &&
207 (status != -ESHUTDOWN)) { 170 (status != -ESHUTDOWN)) {
208 dbg(1, " %s : nonzero status received: %d", 171 dev_dbg(&dev->udev->dev,
209 __func__, status); 172 "%s : nonzero status received: %d\n",
173 __func__, status);
210 } 174 }
211 goto exit; 175 goto exit;
212 } 176 }
@@ -220,10 +184,11 @@ static void adu_interrupt_in_callback(struct urb *urb)
220 dev->interrupt_in_buffer, urb->actual_length); 184 dev->interrupt_in_buffer, urb->actual_length);
221 185
222 dev->read_buffer_length += urb->actual_length; 186 dev->read_buffer_length += urb->actual_length;
223 dbg(2, " %s reading %d ", __func__, 187 dev_dbg(&dev->udev->dev,"%s reading %d\n", __func__,
224 urb->actual_length); 188 urb->actual_length);
225 } else { 189 } else {
226 dbg(1, " %s : read_buffer overflow", __func__); 190 dev_dbg(&dev->udev->dev,"%s : read_buffer overflow\n",
191 __func__);
227 } 192 }
228 } 193 }
229 194
@@ -232,9 +197,6 @@ exit:
232 spin_unlock(&dev->buflock); 197 spin_unlock(&dev->buflock);
233 /* always wake up so we recover from errors */ 198 /* always wake up so we recover from errors */
234 wake_up_interruptible(&dev->read_wait); 199 wake_up_interruptible(&dev->read_wait);
235 adu_debug_data(5, __func__, urb->actual_length,
236 urb->transfer_buffer);
237 dbg(4, " %s : leave, status %d", __func__, status);
238} 200}
239 201
240static void adu_interrupt_out_callback(struct urb *urb) 202static void adu_interrupt_out_callback(struct urb *urb)
@@ -242,27 +204,23 @@ static void adu_interrupt_out_callback(struct urb *urb)
242 struct adu_device *dev = urb->context; 204 struct adu_device *dev = urb->context;
243 int status = urb->status; 205 int status = urb->status;
244 206
245 dbg(4, " %s : enter, status %d", __func__, status); 207 adu_debug_data(&dev->udev->dev, __func__,
246 adu_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer); 208 urb->actual_length, urb->transfer_buffer);
247 209
248 if (status != 0) { 210 if (status != 0) {
249 if ((status != -ENOENT) && 211 if ((status != -ENOENT) &&
250 (status != -ECONNRESET)) { 212 (status != -ECONNRESET)) {
251 dbg(1, " %s :nonzero status received: %d", 213 dev_dbg(&dev->udev->dev,
252 __func__, status); 214 "%s :nonzero status received: %d\n", __func__,
215 status);
253 } 216 }
254 goto exit; 217 return;
255 } 218 }
256 219
257 spin_lock(&dev->buflock); 220 spin_lock(&dev->buflock);
258 dev->out_urb_finished = 1; 221 dev->out_urb_finished = 1;
259 wake_up(&dev->write_wait); 222 wake_up(&dev->write_wait);
260 spin_unlock(&dev->buflock); 223 spin_unlock(&dev->buflock);
261exit:
262
263 adu_debug_data(5, __func__, urb->actual_length,
264 urb->transfer_buffer);
265 dbg(4, " %s : leave, status %d", __func__, status);
266} 224}
267 225
268static int adu_open(struct inode *inode, struct file *file) 226static int adu_open(struct inode *inode, struct file *file)
@@ -272,20 +230,16 @@ static int adu_open(struct inode *inode, struct file *file)
272 int subminor; 230 int subminor;
273 int retval; 231 int retval;
274 232
275 dbg(2, "%s : enter", __func__);
276
277 subminor = iminor(inode); 233 subminor = iminor(inode);
278 234
279 retval = mutex_lock_interruptible(&adutux_mutex); 235 retval = mutex_lock_interruptible(&adutux_mutex);
280 if (retval) { 236 if (retval)
281 dbg(2, "%s : mutex lock failed", __func__);
282 goto exit_no_lock; 237 goto exit_no_lock;
283 }
284 238
285 interface = usb_find_interface(&adu_driver, subminor); 239 interface = usb_find_interface(&adu_driver, subminor);
286 if (!interface) { 240 if (!interface) {
287 printk(KERN_ERR "adutux: %s - error, can't find device for " 241 pr_err("%s - error, can't find device for minor %d\n",
288 "minor %d\n", __func__, subminor); 242 __func__, subminor);
289 retval = -ENODEV; 243 retval = -ENODEV;
290 goto exit_no_device; 244 goto exit_no_device;
291 } 245 }
@@ -303,7 +257,8 @@ static int adu_open(struct inode *inode, struct file *file)
303 } 257 }
304 258
305 ++dev->open_count; 259 ++dev->open_count;
306 dbg(2, "%s : open count %d", __func__, dev->open_count); 260 dev_dbg(&dev->udev->dev, "%s: open count %d\n", __func__,
261 dev->open_count);
307 262
308 /* save device in the file's private structure */ 263 /* save device in the file's private structure */
309 file->private_data = dev; 264 file->private_data = dev;
@@ -333,23 +288,19 @@ static int adu_open(struct inode *inode, struct file *file)
333exit_no_device: 288exit_no_device:
334 mutex_unlock(&adutux_mutex); 289 mutex_unlock(&adutux_mutex);
335exit_no_lock: 290exit_no_lock:
336 dbg(2, "%s : leave, return value %d ", __func__, retval);
337 return retval; 291 return retval;
338} 292}
339 293
340static void adu_release_internal(struct adu_device *dev) 294static void adu_release_internal(struct adu_device *dev)
341{ 295{
342 dbg(2, " %s : enter", __func__);
343
344 /* decrement our usage count for the device */ 296 /* decrement our usage count for the device */
345 --dev->open_count; 297 --dev->open_count;
346 dbg(2, " %s : open count %d", __func__, dev->open_count); 298 dev_dbg(&dev->udev->dev, "%s : open count %d\n", __func__,
299 dev->open_count);
347 if (dev->open_count <= 0) { 300 if (dev->open_count <= 0) {
348 adu_abort_transfers(dev); 301 adu_abort_transfers(dev);
349 dev->open_count = 0; 302 dev->open_count = 0;
350 } 303 }
351
352 dbg(2, " %s : leave", __func__);
353} 304}
354 305
355static int adu_release(struct inode *inode, struct file *file) 306static int adu_release(struct inode *inode, struct file *file)
@@ -357,17 +308,13 @@ static int adu_release(struct inode *inode, struct file *file)
357 struct adu_device *dev; 308 struct adu_device *dev;
358 int retval = 0; 309 int retval = 0;
359 310
360 dbg(2, " %s : enter", __func__);
361
362 if (file == NULL) { 311 if (file == NULL) {
363 dbg(1, " %s : file is NULL", __func__);
364 retval = -ENODEV; 312 retval = -ENODEV;
365 goto exit; 313 goto exit;
366 } 314 }
367 315
368 dev = file->private_data; 316 dev = file->private_data;
369 if (dev == NULL) { 317 if (dev == NULL) {
370 dbg(1, " %s : object is NULL", __func__);
371 retval = -ENODEV; 318 retval = -ENODEV;
372 goto exit; 319 goto exit;
373 } 320 }
@@ -375,7 +322,7 @@ static int adu_release(struct inode *inode, struct file *file)
375 mutex_lock(&adutux_mutex); /* not interruptible */ 322 mutex_lock(&adutux_mutex); /* not interruptible */
376 323
377 if (dev->open_count <= 0) { 324 if (dev->open_count <= 0) {
378 dbg(1, " %s : device not opened", __func__); 325 dev_dbg(&dev->udev->dev, "%s : device not opened\n", __func__);
379 retval = -ENODEV; 326 retval = -ENODEV;
380 goto unlock; 327 goto unlock;
381 } 328 }
@@ -389,7 +336,6 @@ static int adu_release(struct inode *inode, struct file *file)
389unlock: 336unlock:
390 mutex_unlock(&adutux_mutex); 337 mutex_unlock(&adutux_mutex);
391exit: 338exit:
392 dbg(2, " %s : leave, return value %d", __func__, retval);
393 return retval; 339 return retval;
394} 340}
395 341
@@ -406,35 +352,32 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
406 unsigned long flags; 352 unsigned long flags;
407 DECLARE_WAITQUEUE(wait, current); 353 DECLARE_WAITQUEUE(wait, current);
408 354
409 dbg(2, " %s : enter, count = %Zd, file=%p", __func__, count, file);
410
411 dev = file->private_data; 355 dev = file->private_data;
412 dbg(2, " %s : dev=%p", __func__, dev);
413
414 if (mutex_lock_interruptible(&dev->mtx)) 356 if (mutex_lock_interruptible(&dev->mtx))
415 return -ERESTARTSYS; 357 return -ERESTARTSYS;
416 358
417 /* verify that the device wasn't unplugged */ 359 /* verify that the device wasn't unplugged */
418 if (dev->udev == NULL) { 360 if (dev->udev == NULL) {
419 retval = -ENODEV; 361 retval = -ENODEV;
420 printk(KERN_ERR "adutux: No device or device unplugged %d\n", 362 pr_err("No device or device unplugged %d\n", retval);
421 retval);
422 goto exit; 363 goto exit;
423 } 364 }
424 365
425 /* verify that some data was requested */ 366 /* verify that some data was requested */
426 if (count == 0) { 367 if (count == 0) {
427 dbg(1, " %s : read request of 0 bytes", __func__); 368 dev_dbg(&dev->udev->dev, "%s : read request of 0 bytes\n",
369 __func__);
428 goto exit; 370 goto exit;
429 } 371 }
430 372
431 timeout = COMMAND_TIMEOUT; 373 timeout = COMMAND_TIMEOUT;
432 dbg(2, " %s : about to start looping", __func__); 374 dev_dbg(&dev->udev->dev, "%s : about to start looping\n", __func__);
433 while (bytes_to_read) { 375 while (bytes_to_read) {
434 int data_in_secondary = dev->secondary_tail - dev->secondary_head; 376 int data_in_secondary = dev->secondary_tail - dev->secondary_head;
435 dbg(2, " %s : while, data_in_secondary=%d, status=%d", 377 dev_dbg(&dev->udev->dev,
436 __func__, data_in_secondary, 378 "%s : while, data_in_secondary=%d, status=%d\n",
437 dev->interrupt_in_urb->status); 379 __func__, data_in_secondary,
380 dev->interrupt_in_urb->status);
438 381
439 if (data_in_secondary) { 382 if (data_in_secondary) {
440 /* drain secondary buffer */ 383 /* drain secondary buffer */
@@ -457,8 +400,9 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
457 if (dev->read_buffer_length) { 400 if (dev->read_buffer_length) {
458 /* we secure access to the primary */ 401 /* we secure access to the primary */
459 char *tmp; 402 char *tmp;
460 dbg(2, " %s : swap, read_buffer_length = %d", 403 dev_dbg(&dev->udev->dev,
461 __func__, dev->read_buffer_length); 404 "%s : swap, read_buffer_length = %d\n",
405 __func__, dev->read_buffer_length);
462 tmp = dev->read_buffer_secondary; 406 tmp = dev->read_buffer_secondary;
463 dev->read_buffer_secondary = dev->read_buffer_primary; 407 dev->read_buffer_secondary = dev->read_buffer_primary;
464 dev->read_buffer_primary = tmp; 408 dev->read_buffer_primary = tmp;
@@ -473,10 +417,14 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
473 if (!dev->read_urb_finished) { 417 if (!dev->read_urb_finished) {
474 /* somebody is doing IO */ 418 /* somebody is doing IO */
475 spin_unlock_irqrestore(&dev->buflock, flags); 419 spin_unlock_irqrestore(&dev->buflock, flags);
476 dbg(2, " %s : submitted already", __func__); 420 dev_dbg(&dev->udev->dev,
421 "%s : submitted already\n",
422 __func__);
477 } else { 423 } else {
478 /* we must initiate input */ 424 /* we must initiate input */
479 dbg(2, " %s : initiate input", __func__); 425 dev_dbg(&dev->udev->dev,
426 "%s : initiate input\n",
427 __func__);
480 dev->read_urb_finished = 0; 428 dev->read_urb_finished = 0;
481 spin_unlock_irqrestore(&dev->buflock, flags); 429 spin_unlock_irqrestore(&dev->buflock, flags);
482 430
@@ -494,7 +442,9 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
494 if (retval == -ENOMEM) { 442 if (retval == -ENOMEM) {
495 retval = bytes_read ? bytes_read : -ENOMEM; 443 retval = bytes_read ? bytes_read : -ENOMEM;
496 } 444 }
497 dbg(2, " %s : submit failed", __func__); 445 dev_dbg(&dev->udev->dev,
446 "%s : submit failed\n",
447 __func__);
498 goto exit; 448 goto exit;
499 } 449 }
500 } 450 }
@@ -513,13 +463,16 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
513 remove_wait_queue(&dev->read_wait, &wait); 463 remove_wait_queue(&dev->read_wait, &wait);
514 464
515 if (timeout <= 0) { 465 if (timeout <= 0) {
516 dbg(2, " %s : timeout", __func__); 466 dev_dbg(&dev->udev->dev,
467 "%s : timeout\n", __func__);
517 retval = bytes_read ? bytes_read : -ETIMEDOUT; 468 retval = bytes_read ? bytes_read : -ETIMEDOUT;
518 goto exit; 469 goto exit;
519 } 470 }
520 471
521 if (signal_pending(current)) { 472 if (signal_pending(current)) {
522 dbg(2, " %s : signal pending", __func__); 473 dev_dbg(&dev->udev->dev,
474 "%s : signal pending\n",
475 __func__);
523 retval = bytes_read ? bytes_read : -EINTR; 476 retval = bytes_read ? bytes_read : -EINTR;
524 goto exit; 477 goto exit;
525 } 478 }
@@ -552,7 +505,6 @@ exit:
552 /* unlock the device */ 505 /* unlock the device */
553 mutex_unlock(&dev->mtx); 506 mutex_unlock(&dev->mtx);
554 507
555 dbg(2, " %s : leave, return value %d", __func__, retval);
556 return retval; 508 return retval;
557} 509}
558 510
@@ -567,8 +519,6 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
567 unsigned long flags; 519 unsigned long flags;
568 int retval; 520 int retval;
569 521
570 dbg(2, " %s : enter, count = %Zd", __func__, count);
571
572 dev = file->private_data; 522 dev = file->private_data;
573 523
574 retval = mutex_lock_interruptible(&dev->mtx); 524 retval = mutex_lock_interruptible(&dev->mtx);
@@ -578,14 +528,14 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
578 /* verify that the device wasn't unplugged */ 528 /* verify that the device wasn't unplugged */
579 if (dev->udev == NULL) { 529 if (dev->udev == NULL) {
580 retval = -ENODEV; 530 retval = -ENODEV;
581 printk(KERN_ERR "adutux: No device or device unplugged %d\n", 531 pr_err("No device or device unplugged %d\n", retval);
582 retval);
583 goto exit; 532 goto exit;
584 } 533 }
585 534
586 /* verify that we actually have some data to write */ 535 /* verify that we actually have some data to write */
587 if (count == 0) { 536 if (count == 0) {
588 dbg(1, " %s : write request of 0 bytes", __func__); 537 dev_dbg(&dev->udev->dev, "%s : write request of 0 bytes\n",
538 __func__);
589 goto exit; 539 goto exit;
590 } 540 }
591 541
@@ -598,13 +548,15 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
598 548
599 mutex_unlock(&dev->mtx); 549 mutex_unlock(&dev->mtx);
600 if (signal_pending(current)) { 550 if (signal_pending(current)) {
601 dbg(1, " %s : interrupted", __func__); 551 dev_dbg(&dev->udev->dev, "%s : interrupted\n",
552 __func__);
602 set_current_state(TASK_RUNNING); 553 set_current_state(TASK_RUNNING);
603 retval = -EINTR; 554 retval = -EINTR;
604 goto exit_onqueue; 555 goto exit_onqueue;
605 } 556 }
606 if (schedule_timeout(COMMAND_TIMEOUT) == 0) { 557 if (schedule_timeout(COMMAND_TIMEOUT) == 0) {
607 dbg(1, "%s - command timed out.", __func__); 558 dev_dbg(&dev->udev->dev,
559 "%s - command timed out.\n", __func__);
608 retval = -ETIMEDOUT; 560 retval = -ETIMEDOUT;
609 goto exit_onqueue; 561 goto exit_onqueue;
610 } 562 }
@@ -615,18 +567,22 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
615 goto exit_nolock; 567 goto exit_nolock;
616 } 568 }
617 569
618 dbg(4, " %s : in progress, count = %Zd", __func__, count); 570 dev_dbg(&dev->udev->dev,
571 "%s : in progress, count = %Zd\n",
572 __func__, count);
619 } else { 573 } else {
620 spin_unlock_irqrestore(&dev->buflock, flags); 574 spin_unlock_irqrestore(&dev->buflock, flags);
621 set_current_state(TASK_RUNNING); 575 set_current_state(TASK_RUNNING);
622 remove_wait_queue(&dev->write_wait, &waita); 576 remove_wait_queue(&dev->write_wait, &waita);
623 dbg(4, " %s : sending, count = %Zd", __func__, count); 577 dev_dbg(&dev->udev->dev, "%s : sending, count = %Zd\n",
578 __func__, count);
624 579
625 /* write the data into interrupt_out_buffer from userspace */ 580 /* write the data into interrupt_out_buffer from userspace */
626 buffer_size = usb_endpoint_maxp(dev->interrupt_out_endpoint); 581 buffer_size = usb_endpoint_maxp(dev->interrupt_out_endpoint);
627 bytes_to_write = count > buffer_size ? buffer_size : count; 582 bytes_to_write = count > buffer_size ? buffer_size : count;
628 dbg(4, " %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd", 583 dev_dbg(&dev->udev->dev,
629 __func__, buffer_size, count, bytes_to_write); 584 "%s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd\n",
585 __func__, buffer_size, count, bytes_to_write);
630 586
631 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) { 587 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) {
632 retval = -EFAULT; 588 retval = -EFAULT;
@@ -665,7 +621,6 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
665exit: 621exit:
666 mutex_unlock(&dev->mtx); 622 mutex_unlock(&dev->mtx);
667exit_nolock: 623exit_nolock:
668 dbg(2, " %s : leave, return value %d", __func__, retval);
669 return retval; 624 return retval;
670 625
671exit_onqueue: 626exit_onqueue:
@@ -711,8 +666,6 @@ static int adu_probe(struct usb_interface *interface,
711 int out_end_size; 666 int out_end_size;
712 int i; 667 int i;
713 668
714 dbg(2, " %s : enter", __func__);
715
716 if (udev == NULL) { 669 if (udev == NULL) {
717 dev_err(&interface->dev, "udev is NULL.\n"); 670 dev_err(&interface->dev, "udev is NULL.\n");
718 goto exit; 671 goto exit;
@@ -812,7 +765,7 @@ static int adu_probe(struct usb_interface *interface,
812 dev_err(&interface->dev, "Could not retrieve serial number\n"); 765 dev_err(&interface->dev, "Could not retrieve serial number\n");
813 goto error; 766 goto error;
814 } 767 }
815 dbg(2, " %s : serial_number=%s", __func__, dev->serial_number); 768 dev_dbg(&interface->dev,"serial_number=%s", dev->serial_number);
816 769
817 /* we can register the device now, as it is ready */ 770 /* we can register the device now, as it is ready */
818 usb_set_intfdata(interface, dev); 771 usb_set_intfdata(interface, dev);
@@ -833,8 +786,6 @@ static int adu_probe(struct usb_interface *interface,
833 le16_to_cpu(udev->descriptor.idProduct), dev->serial_number, 786 le16_to_cpu(udev->descriptor.idProduct), dev->serial_number,
834 (dev->minor - ADU_MINOR_BASE)); 787 (dev->minor - ADU_MINOR_BASE));
835exit: 788exit:
836 dbg(2, " %s : leave, return value %p (dev)", __func__, dev);
837
838 return retval; 789 return retval;
839 790
840error: 791error:
@@ -852,8 +803,6 @@ static void adu_disconnect(struct usb_interface *interface)
852 struct adu_device *dev; 803 struct adu_device *dev;
853 int minor; 804 int minor;
854 805
855 dbg(2, " %s : enter", __func__);
856
857 dev = usb_get_intfdata(interface); 806 dev = usb_get_intfdata(interface);
858 807
859 mutex_lock(&dev->mtx); /* not interruptible */ 808 mutex_lock(&dev->mtx); /* not interruptible */
@@ -866,7 +815,8 @@ static void adu_disconnect(struct usb_interface *interface)
866 usb_set_intfdata(interface, NULL); 815 usb_set_intfdata(interface, NULL);
867 816
868 /* if the device is not opened, then we clean up right now */ 817 /* if the device is not opened, then we clean up right now */
869 dbg(2, " %s : open count %d", __func__, dev->open_count); 818 dev_dbg(&dev->udev->dev, "%s : open count %d\n",
819 __func__, dev->open_count);
870 if (!dev->open_count) 820 if (!dev->open_count)
871 adu_delete(dev); 821 adu_delete(dev);
872 822
@@ -874,8 +824,6 @@ static void adu_disconnect(struct usb_interface *interface)
874 824
875 dev_info(&interface->dev, "ADU device adutux%d now disconnected\n", 825 dev_info(&interface->dev, "ADU device adutux%d now disconnected\n",
876 (minor - ADU_MINOR_BASE)); 826 (minor - ADU_MINOR_BASE));
877
878 dbg(2, " %s : leave", __func__);
879} 827}
880 828
881/* usb specific object needed to register this driver with the usb subsystem */ 829/* usb specific object needed to register this driver with the usb subsystem */
diff --git a/drivers/usb/misc/ehset.c b/drivers/usb/misc/ehset.c
new file mode 100644
index 000000000000..c31b4a33e6bb
--- /dev/null
+++ b/drivers/usb/misc/ehset.c
@@ -0,0 +1,152 @@
1/*
2 * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
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 version 2 and
6 * only version 2 as published by the Free Software Foundation.
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#include <linux/kernel.h>
15#include <linux/errno.h>
16#include <linux/module.h>
17#include <linux/slab.h>
18#include <linux/usb.h>
19#include <linux/usb/ch11.h>
20
21#define TEST_SE0_NAK_PID 0x0101
22#define TEST_J_PID 0x0102
23#define TEST_K_PID 0x0103
24#define TEST_PACKET_PID 0x0104
25#define TEST_HS_HOST_PORT_SUSPEND_RESUME 0x0106
26#define TEST_SINGLE_STEP_GET_DEV_DESC 0x0107
27#define TEST_SINGLE_STEP_SET_FEATURE 0x0108
28
29static int ehset_probe(struct usb_interface *intf,
30 const struct usb_device_id *id)
31{
32 int ret = -EINVAL;
33 struct usb_device *dev = interface_to_usbdev(intf);
34 struct usb_device *hub_udev = dev->parent;
35 struct usb_device_descriptor *buf;
36 u8 portnum = dev->portnum;
37 u16 test_pid = le16_to_cpu(dev->descriptor.idProduct);
38
39 switch (test_pid) {
40 case TEST_SE0_NAK_PID:
41 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
42 USB_REQ_SET_FEATURE, USB_RT_PORT,
43 USB_PORT_FEAT_TEST,
44 (TEST_SE0_NAK << 8) | portnum,
45 NULL, 0, 1000);
46 break;
47 case TEST_J_PID:
48 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
49 USB_REQ_SET_FEATURE, USB_RT_PORT,
50 USB_PORT_FEAT_TEST,
51 (TEST_J << 8) | portnum,
52 NULL, 0, 1000);
53 break;
54 case TEST_K_PID:
55 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
56 USB_REQ_SET_FEATURE, USB_RT_PORT,
57 USB_PORT_FEAT_TEST,
58 (TEST_K << 8) | portnum,
59 NULL, 0, 1000);
60 break;
61 case TEST_PACKET_PID:
62 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
63 USB_REQ_SET_FEATURE, USB_RT_PORT,
64 USB_PORT_FEAT_TEST,
65 (TEST_PACKET << 8) | portnum,
66 NULL, 0, 1000);
67 break;
68 case TEST_HS_HOST_PORT_SUSPEND_RESUME:
69 /* Test: wait for 15secs -> suspend -> 15secs delay -> resume */
70 msleep(15 * 1000);
71 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
72 USB_REQ_SET_FEATURE, USB_RT_PORT,
73 USB_PORT_FEAT_SUSPEND, portnum,
74 NULL, 0, 1000);
75 if (ret < 0)
76 break;
77
78 msleep(15 * 1000);
79 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
80 USB_REQ_CLEAR_FEATURE, USB_RT_PORT,
81 USB_PORT_FEAT_SUSPEND, portnum,
82 NULL, 0, 1000);
83 break;
84 case TEST_SINGLE_STEP_GET_DEV_DESC:
85 /* Test: wait for 15secs -> GetDescriptor request */
86 msleep(15 * 1000);
87 buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);
88 if (!buf)
89 return -ENOMEM;
90
91 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
92 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
93 USB_DT_DEVICE << 8, 0,
94 buf, USB_DT_DEVICE_SIZE,
95 USB_CTRL_GET_TIMEOUT);
96 kfree(buf);
97 break;
98 case TEST_SINGLE_STEP_SET_FEATURE:
99 /*
100 * GetDescriptor SETUP request -> 15secs delay -> IN & STATUS
101 *
102 * Note, this test is only supported on root hubs since the
103 * SetPortFeature handling can only be done inside the HCD's
104 * hub_control callback function.
105 */
106 if (hub_udev != dev->bus->root_hub) {
107 dev_err(&intf->dev, "SINGLE_STEP_SET_FEATURE test only supported on root hub\n");
108 break;
109 }
110
111 ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0),
112 USB_REQ_SET_FEATURE, USB_RT_PORT,
113 USB_PORT_FEAT_TEST,
114 (6 << 8) | portnum,
115 NULL, 0, 60 * 1000);
116
117 break;
118 default:
119 dev_err(&intf->dev, "%s: unsupported PID: 0x%x\n",
120 __func__, test_pid);
121 }
122
123 return (ret < 0) ? ret : 0;
124}
125
126static void ehset_disconnect(struct usb_interface *intf)
127{
128}
129
130static const struct usb_device_id ehset_id_table[] = {
131 { USB_DEVICE(0x1a0a, TEST_SE0_NAK_PID) },
132 { USB_DEVICE(0x1a0a, TEST_J_PID) },
133 { USB_DEVICE(0x1a0a, TEST_K_PID) },
134 { USB_DEVICE(0x1a0a, TEST_PACKET_PID) },
135 { USB_DEVICE(0x1a0a, TEST_HS_HOST_PORT_SUSPEND_RESUME) },
136 { USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_GET_DEV_DESC) },
137 { USB_DEVICE(0x1a0a, TEST_SINGLE_STEP_SET_FEATURE) },
138 { } /* Terminating entry */
139};
140MODULE_DEVICE_TABLE(usb, ehset_id_table);
141
142static struct usb_driver ehset_driver = {
143 .name = "usb_ehset_test",
144 .probe = ehset_probe,
145 .disconnect = ehset_disconnect,
146 .id_table = ehset_id_table,
147};
148
149module_usb_driver(ehset_driver);
150
151MODULE_DESCRIPTION("USB Driver for EHSET Test Fixture");
152MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index ac762299eaa8..b1d59532ac22 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -129,19 +129,6 @@ MODULE_DESCRIPTION("LD USB Driver");
129MODULE_LICENSE("GPL"); 129MODULE_LICENSE("GPL");
130MODULE_SUPPORTED_DEVICE("LD USB Devices"); 130MODULE_SUPPORTED_DEVICE("LD USB Devices");
131 131
132#ifdef CONFIG_USB_DEBUG
133 static int debug = 1;
134#else
135 static int debug = 0;
136#endif
137
138/* Use our own dbg macro */
139#define dbg_info(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
140
141/* Module parameters */
142module_param(debug, int, S_IRUGO | S_IWUSR);
143MODULE_PARM_DESC(debug, "Debug enabled or not");
144
145/* All interrupt in transfers are collected in a ring buffer to 132/* All interrupt in transfers are collected in a ring buffer to
146 * avoid racing conditions and get better performance of the driver. 133 * avoid racing conditions and get better performance of the driver.
147 */ 134 */
@@ -256,8 +243,9 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
256 status == -ESHUTDOWN) { 243 status == -ESHUTDOWN) {
257 goto exit; 244 goto exit;
258 } else { 245 } else {
259 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n", 246 dev_dbg(&dev->intf->dev,
260 __func__, status); 247 "%s: nonzero status received: %d\n", __func__,
248 status);
261 spin_lock(&dev->rbsl); 249 spin_lock(&dev->rbsl);
262 goto resubmit; /* maybe we can recover */ 250 goto resubmit; /* maybe we can recover */
263 } 251 }
@@ -272,8 +260,8 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
272 *actual_buffer = urb->actual_length; 260 *actual_buffer = urb->actual_length;
273 memcpy(actual_buffer+1, dev->interrupt_in_buffer, urb->actual_length); 261 memcpy(actual_buffer+1, dev->interrupt_in_buffer, urb->actual_length);
274 dev->ring_head = next_ring_head; 262 dev->ring_head = next_ring_head;
275 dbg_info(&dev->intf->dev, "%s: received %d bytes\n", 263 dev_dbg(&dev->intf->dev, "%s: received %d bytes\n",
276 __func__, urb->actual_length); 264 __func__, urb->actual_length);
277 } else { 265 } else {
278 dev_warn(&dev->intf->dev, 266 dev_warn(&dev->intf->dev,
279 "Ring buffer overflow, %d bytes dropped\n", 267 "Ring buffer overflow, %d bytes dropped\n",
@@ -310,9 +298,9 @@ static void ld_usb_interrupt_out_callback(struct urb *urb)
310 if (status && !(status == -ENOENT || 298 if (status && !(status == -ENOENT ||
311 status == -ECONNRESET || 299 status == -ECONNRESET ||
312 status == -ESHUTDOWN)) 300 status == -ESHUTDOWN))
313 dbg_info(&dev->intf->dev, 301 dev_dbg(&dev->intf->dev,
314 "%s - nonzero write interrupt status received: %d\n", 302 "%s - nonzero write interrupt status received: %d\n",
315 __func__, status); 303 __func__, status);
316 304
317 dev->interrupt_out_busy = 0; 305 dev->interrupt_out_busy = 0;
318 wake_up_interruptible(&dev->write_wait); 306 wake_up_interruptible(&dev->write_wait);
@@ -585,7 +573,8 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
585 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size); 573 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size);
586 if (bytes_to_write < count) 574 if (bytes_to_write < count)
587 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write); 575 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write);
588 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n", __func__, count, bytes_to_write); 576 dev_dbg(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n",
577 __func__, count, bytes_to_write);
589 578
590 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) { 579 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
591 retval = -EFAULT; 580 retval = -EFAULT;
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 80894791c020..eb37c9542052 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -75,6 +75,8 @@
75 * - move reset into open to clean out spurious data 75 * - move reset into open to clean out spurious data
76 */ 76 */
77 77
78#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
79
78#include <linux/kernel.h> 80#include <linux/kernel.h>
79#include <linux/errno.h> 81#include <linux/errno.h>
80#include <linux/init.h> 82#include <linux/init.h>
@@ -87,28 +89,11 @@
87#include <linux/poll.h> 89#include <linux/poll.h>
88 90
89 91
90#ifdef CONFIG_USB_DEBUG
91 static int debug = 4;
92#else
93 static int debug = 0;
94#endif
95
96/* Use our own dbg macro */
97#undef dbg
98#define dbg(lvl, format, arg...) \
99do { \
100 if (debug >= lvl) \
101 printk(KERN_DEBUG "%s: " format "\n", __FILE__, ##arg); \
102} while (0)
103
104/* Version Information */ 92/* Version Information */
105#define DRIVER_VERSION "v0.96" 93#define DRIVER_VERSION "v0.96"
106#define DRIVER_AUTHOR "Juergen Stuber <starblue@sourceforge.net>" 94#define DRIVER_AUTHOR "Juergen Stuber <starblue@sourceforge.net>"
107#define DRIVER_DESC "LEGO USB Tower Driver" 95#define DRIVER_DESC "LEGO USB Tower Driver"
108 96
109/* Module parameters */
110module_param(debug, int, S_IRUGO | S_IWUSR);
111MODULE_PARM_DESC(debug, "Debug enabled or not");
112 97
113/* The defaults are chosen to work with the latest versions of leJOS and NQC. 98/* The defaults are chosen to work with the latest versions of leJOS and NQC.
114 */ 99 */
@@ -298,18 +283,12 @@ static struct usb_driver tower_driver = {
298/** 283/**
299 * lego_usb_tower_debug_data 284 * lego_usb_tower_debug_data
300 */ 285 */
301static inline void lego_usb_tower_debug_data (int level, const char *function, int size, const unsigned char *data) 286static inline void lego_usb_tower_debug_data(struct device *dev,
287 const char *function, int size,
288 const unsigned char *data)
302{ 289{
303 int i; 290 dev_dbg(dev, "%s - length = %d, data = %*ph\n",
304 291 function, size, size, data);
305 if (debug < level)
306 return;
307
308 printk (KERN_DEBUG "%s: %s - length = %d, data = ", __FILE__, function, size);
309 for (i = 0; i < size; ++i) {
310 printk ("%.2x ", data[i]);
311 }
312 printk ("\n");
313} 292}
314 293
315 294
@@ -318,8 +297,6 @@ static inline void lego_usb_tower_debug_data (int level, const char *function, i
318 */ 297 */
319static inline void tower_delete (struct lego_usb_tower *dev) 298static inline void tower_delete (struct lego_usb_tower *dev)
320{ 299{
321 dbg(2, "%s: enter", __func__);
322
323 tower_abort_transfers (dev); 300 tower_abort_transfers (dev);
324 301
325 /* free data structures */ 302 /* free data structures */
@@ -329,8 +306,6 @@ static inline void tower_delete (struct lego_usb_tower *dev)
329 kfree (dev->interrupt_in_buffer); 306 kfree (dev->interrupt_in_buffer);
330 kfree (dev->interrupt_out_buffer); 307 kfree (dev->interrupt_out_buffer);
331 kfree (dev); 308 kfree (dev);
332
333 dbg(2, "%s: leave", __func__);
334} 309}
335 310
336 311
@@ -346,16 +321,13 @@ static int tower_open (struct inode *inode, struct file *file)
346 struct tower_reset_reply reset_reply; 321 struct tower_reset_reply reset_reply;
347 int result; 322 int result;
348 323
349 dbg(2, "%s: enter", __func__);
350
351 nonseekable_open(inode, file); 324 nonseekable_open(inode, file);
352 subminor = iminor(inode); 325 subminor = iminor(inode);
353 326
354 interface = usb_find_interface (&tower_driver, subminor); 327 interface = usb_find_interface (&tower_driver, subminor);
355 328
356 if (!interface) { 329 if (!interface) {
357 printk(KERN_ERR "%s - error, can't find device for minor %d\n", 330 pr_err("error, can't find device for minor %d\n", subminor);
358 __func__, subminor);
359 retval = -ENODEV; 331 retval = -ENODEV;
360 goto exit; 332 goto exit;
361 } 333 }
@@ -435,8 +407,6 @@ unlock_exit:
435 mutex_unlock(&dev->lock); 407 mutex_unlock(&dev->lock);
436 408
437exit: 409exit:
438 dbg(2, "%s: leave, return value %d ", __func__, retval);
439
440 return retval; 410 return retval;
441} 411}
442 412
@@ -448,12 +418,9 @@ static int tower_release (struct inode *inode, struct file *file)
448 struct lego_usb_tower *dev; 418 struct lego_usb_tower *dev;
449 int retval = 0; 419 int retval = 0;
450 420
451 dbg(2, "%s: enter", __func__);
452
453 dev = file->private_data; 421 dev = file->private_data;
454 422
455 if (dev == NULL) { 423 if (dev == NULL) {
456 dbg(1, "%s: object is NULL", __func__);
457 retval = -ENODEV; 424 retval = -ENODEV;
458 goto exit_nolock; 425 goto exit_nolock;
459 } 426 }
@@ -465,7 +432,8 @@ static int tower_release (struct inode *inode, struct file *file)
465 } 432 }
466 433
467 if (dev->open_count != 1) { 434 if (dev->open_count != 1) {
468 dbg(1, "%s: device not opened exactly once", __func__); 435 dev_dbg(&dev->udev->dev, "%s: device not opened exactly once\n",
436 __func__);
469 retval = -ENODEV; 437 retval = -ENODEV;
470 goto unlock_exit; 438 goto unlock_exit;
471 } 439 }
@@ -491,7 +459,6 @@ unlock_exit:
491exit: 459exit:
492 mutex_unlock(&open_disc_mutex); 460 mutex_unlock(&open_disc_mutex);
493exit_nolock: 461exit_nolock:
494 dbg(2, "%s: leave, return value %d", __func__, retval);
495 return retval; 462 return retval;
496} 463}
497 464
@@ -502,12 +469,8 @@ exit_nolock:
502 */ 469 */
503static void tower_abort_transfers (struct lego_usb_tower *dev) 470static void tower_abort_transfers (struct lego_usb_tower *dev)
504{ 471{
505 dbg(2, "%s: enter", __func__); 472 if (dev == NULL)
506 473 return;
507 if (dev == NULL) {
508 dbg(1, "%s: dev is null", __func__);
509 goto exit;
510 }
511 474
512 /* shutdown transfer */ 475 /* shutdown transfer */
513 if (dev->interrupt_in_running) { 476 if (dev->interrupt_in_running) {
@@ -518,9 +481,6 @@ static void tower_abort_transfers (struct lego_usb_tower *dev)
518 } 481 }
519 if (dev->interrupt_out_busy && dev->udev) 482 if (dev->interrupt_out_busy && dev->udev)
520 usb_kill_urb(dev->interrupt_out_urb); 483 usb_kill_urb(dev->interrupt_out_urb);
521
522exit:
523 dbg(2, "%s: leave", __func__);
524} 484}
525 485
526 486
@@ -553,8 +513,6 @@ static unsigned int tower_poll (struct file *file, poll_table *wait)
553 struct lego_usb_tower *dev; 513 struct lego_usb_tower *dev;
554 unsigned int mask = 0; 514 unsigned int mask = 0;
555 515
556 dbg(2, "%s: enter", __func__);
557
558 dev = file->private_data; 516 dev = file->private_data;
559 517
560 if (!dev->udev) 518 if (!dev->udev)
@@ -571,8 +529,6 @@ static unsigned int tower_poll (struct file *file, poll_table *wait)
571 mask |= POLLOUT | POLLWRNORM; 529 mask |= POLLOUT | POLLWRNORM;
572 } 530 }
573 531
574 dbg(2, "%s: leave, mask = %d", __func__, mask);
575
576 return mask; 532 return mask;
577} 533}
578 534
@@ -597,8 +553,6 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
597 int retval = 0; 553 int retval = 0;
598 unsigned long timeout = 0; 554 unsigned long timeout = 0;
599 555
600 dbg(2, "%s: enter, count = %Zd", __func__, count);
601
602 dev = file->private_data; 556 dev = file->private_data;
603 557
604 /* lock this object */ 558 /* lock this object */
@@ -610,13 +564,13 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
610 /* verify that the device wasn't unplugged */ 564 /* verify that the device wasn't unplugged */
611 if (dev->udev == NULL) { 565 if (dev->udev == NULL) {
612 retval = -ENODEV; 566 retval = -ENODEV;
613 printk(KERN_ERR "legousbtower: No device or device unplugged %d\n", retval); 567 pr_err("No device or device unplugged %d\n", retval);
614 goto unlock_exit; 568 goto unlock_exit;
615 } 569 }
616 570
617 /* verify that we actually have some data to read */ 571 /* verify that we actually have some data to read */
618 if (count == 0) { 572 if (count == 0) {
619 dbg(1, "%s: read request of 0 bytes", __func__); 573 dev_dbg(&dev->udev->dev, "read request of 0 bytes\n");
620 goto unlock_exit; 574 goto unlock_exit;
621 } 575 }
622 576
@@ -672,7 +626,6 @@ unlock_exit:
672 mutex_unlock(&dev->lock); 626 mutex_unlock(&dev->lock);
673 627
674exit: 628exit:
675 dbg(2, "%s: leave, return value %d", __func__, retval);
676 return retval; 629 return retval;
677} 630}
678 631
@@ -686,8 +639,6 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
686 size_t bytes_to_write; 639 size_t bytes_to_write;
687 int retval = 0; 640 int retval = 0;
688 641
689 dbg(2, "%s: enter, count = %Zd", __func__, count);
690
691 dev = file->private_data; 642 dev = file->private_data;
692 643
693 /* lock this object */ 644 /* lock this object */
@@ -699,13 +650,13 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
699 /* verify that the device wasn't unplugged */ 650 /* verify that the device wasn't unplugged */
700 if (dev->udev == NULL) { 651 if (dev->udev == NULL) {
701 retval = -ENODEV; 652 retval = -ENODEV;
702 printk(KERN_ERR "legousbtower: No device or device unplugged %d\n", retval); 653 pr_err("No device or device unplugged %d\n", retval);
703 goto unlock_exit; 654 goto unlock_exit;
704 } 655 }
705 656
706 /* verify that we actually have some data to write */ 657 /* verify that we actually have some data to write */
707 if (count == 0) { 658 if (count == 0) {
708 dbg(1, "%s: write request of 0 bytes", __func__); 659 dev_dbg(&dev->udev->dev, "write request of 0 bytes\n");
709 goto unlock_exit; 660 goto unlock_exit;
710 } 661 }
711 662
@@ -723,7 +674,8 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
723 674
724 /* write the data into interrupt_out_buffer from userspace */ 675 /* write the data into interrupt_out_buffer from userspace */
725 bytes_to_write = min_t(int, count, write_buffer_size); 676 bytes_to_write = min_t(int, count, write_buffer_size);
726 dbg(4, "%s: count = %Zd, bytes_to_write = %Zd", __func__, count, bytes_to_write); 677 dev_dbg(&dev->udev->dev, "%s: count = %Zd, bytes_to_write = %Zd\n",
678 __func__, count, bytes_to_write);
727 679
728 if (copy_from_user (dev->interrupt_out_buffer, buffer, bytes_to_write)) { 680 if (copy_from_user (dev->interrupt_out_buffer, buffer, bytes_to_write)) {
729 retval = -EFAULT; 681 retval = -EFAULT;
@@ -757,8 +709,6 @@ unlock_exit:
757 mutex_unlock(&dev->lock); 709 mutex_unlock(&dev->lock);
758 710
759exit: 711exit:
760 dbg(2, "%s: leave, return value %d", __func__, retval);
761
762 return retval; 712 return retval;
763} 713}
764 714
@@ -772,9 +722,8 @@ static void tower_interrupt_in_callback (struct urb *urb)
772 int status = urb->status; 722 int status = urb->status;
773 int retval; 723 int retval;
774 724
775 dbg(4, "%s: enter, status %d", __func__, status); 725 lego_usb_tower_debug_data(&dev->udev->dev, __func__,
776 726 urb->actual_length, urb->transfer_buffer);
777 lego_usb_tower_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer);
778 727
779 if (status) { 728 if (status) {
780 if (status == -ENOENT || 729 if (status == -ENOENT ||
@@ -782,7 +731,9 @@ static void tower_interrupt_in_callback (struct urb *urb)
782 status == -ESHUTDOWN) { 731 status == -ESHUTDOWN) {
783 goto exit; 732 goto exit;
784 } else { 733 } else {
785 dbg(1, "%s: nonzero status received: %d", __func__, status); 734 dev_dbg(&dev->udev->dev,
735 "%s: nonzero status received: %d\n", __func__,
736 status);
786 goto resubmit; /* maybe we can recover */ 737 goto resubmit; /* maybe we can recover */
787 } 738 }
788 } 739 }
@@ -795,9 +746,11 @@ static void tower_interrupt_in_callback (struct urb *urb)
795 urb->actual_length); 746 urb->actual_length);
796 dev->read_buffer_length += urb->actual_length; 747 dev->read_buffer_length += urb->actual_length;
797 dev->read_last_arrival = jiffies; 748 dev->read_last_arrival = jiffies;
798 dbg(3, "%s: received %d bytes", __func__, urb->actual_length); 749 dev_dbg(&dev->udev->dev, "%s: received %d bytes\n",
750 __func__, urb->actual_length);
799 } else { 751 } else {
800 printk(KERN_WARNING "%s: read_buffer overflow, %d bytes dropped", __func__, urb->actual_length); 752 pr_warn("read_buffer overflow, %d bytes dropped\n",
753 urb->actual_length);
801 } 754 }
802 spin_unlock (&dev->read_buffer_lock); 755 spin_unlock (&dev->read_buffer_lock);
803 } 756 }
@@ -815,9 +768,6 @@ resubmit:
815exit: 768exit:
816 dev->interrupt_in_done = 1; 769 dev->interrupt_in_done = 1;
817 wake_up_interruptible (&dev->read_wait); 770 wake_up_interruptible (&dev->read_wait);
818
819 lego_usb_tower_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer);
820 dbg(4, "%s: leave, status %d", __func__, status);
821} 771}
822 772
823 773
@@ -829,22 +779,20 @@ static void tower_interrupt_out_callback (struct urb *urb)
829 struct lego_usb_tower *dev = urb->context; 779 struct lego_usb_tower *dev = urb->context;
830 int status = urb->status; 780 int status = urb->status;
831 781
832 dbg(4, "%s: enter, status %d", __func__, status); 782 lego_usb_tower_debug_data(&dev->udev->dev, __func__,
833 lego_usb_tower_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer); 783 urb->actual_length, urb->transfer_buffer);
834 784
835 /* sync/async unlink faults aren't errors */ 785 /* sync/async unlink faults aren't errors */
836 if (status && !(status == -ENOENT || 786 if (status && !(status == -ENOENT ||
837 status == -ECONNRESET || 787 status == -ECONNRESET ||
838 status == -ESHUTDOWN)) { 788 status == -ESHUTDOWN)) {
839 dbg(1, "%s - nonzero write bulk status received: %d", 789 dev_dbg(&dev->udev->dev,
840 __func__, status); 790 "%s: nonzero write bulk status received: %d\n", __func__,
791 status);
841 } 792 }
842 793
843 dev->interrupt_out_busy = 0; 794 dev->interrupt_out_busy = 0;
844 wake_up_interruptible(&dev->write_wait); 795 wake_up_interruptible(&dev->write_wait);
845
846 lego_usb_tower_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer);
847 dbg(4, "%s: leave, status %d", __func__, status);
848} 796}
849 797
850 798
@@ -866,8 +814,6 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
866 int retval = -ENOMEM; 814 int retval = -ENOMEM;
867 int result; 815 int result;
868 816
869 dbg(2, "%s: enter", __func__);
870
871 /* allocate memory for our device state and initialize it */ 817 /* allocate memory for our device state and initialize it */
872 818
873 dev = kmalloc (sizeof(struct lego_usb_tower), GFP_KERNEL); 819 dev = kmalloc (sizeof(struct lego_usb_tower), GFP_KERNEL);
@@ -993,8 +939,6 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
993 939
994 940
995exit: 941exit:
996 dbg(2, "%s: leave, return value 0x%.8lx (dev)", __func__, (long) dev);
997
998 return retval; 942 return retval;
999 943
1000error: 944error:
@@ -1013,8 +957,6 @@ static void tower_disconnect (struct usb_interface *interface)
1013 struct lego_usb_tower *dev; 957 struct lego_usb_tower *dev;
1014 int minor; 958 int minor;
1015 959
1016 dbg(2, "%s: enter", __func__);
1017
1018 dev = usb_get_intfdata (interface); 960 dev = usb_get_intfdata (interface);
1019 mutex_lock(&open_disc_mutex); 961 mutex_lock(&open_disc_mutex);
1020 usb_set_intfdata (interface, NULL); 962 usb_set_intfdata (interface, NULL);
@@ -1041,8 +983,6 @@ static void tower_disconnect (struct usb_interface *interface)
1041 983
1042 dev_info(&interface->dev, "LEGO USB Tower #%d now disconnected\n", 984 dev_info(&interface->dev, "LEGO USB Tower #%d now disconnected\n",
1043 (minor - LEGO_USB_TOWER_MINOR_BASE)); 985 (minor - LEGO_USB_TOWER_MINOR_BASE));
1044
1045 dbg(2, "%s: leave", __func__);
1046} 986}
1047 987
1048module_usb_driver(tower_driver); 988module_usb_driver(tower_driver);
diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c
index c3578393ddef..a31641e18d19 100644
--- a/drivers/usb/misc/usb3503.c
+++ b/drivers/usb/misc/usb3503.c
@@ -26,6 +26,7 @@
26#include <linux/of_gpio.h> 26#include <linux/of_gpio.h>
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/platform_data/usb3503.h> 28#include <linux/platform_data/usb3503.h>
29#include <linux/regmap.h>
29 30
30#define USB3503_VIDL 0x00 31#define USB3503_VIDL 0x00
31#define USB3503_VIDM 0x01 32#define USB3503_VIDM 0x01
@@ -50,60 +51,25 @@
50#define USB3503_CFGP 0xee 51#define USB3503_CFGP 0xee
51#define USB3503_CLKSUSP (1 << 7) 52#define USB3503_CLKSUSP (1 << 7)
52 53
54#define USB3503_RESET 0xff
55
53struct usb3503 { 56struct usb3503 {
54 enum usb3503_mode mode; 57 enum usb3503_mode mode;
55 struct i2c_client *client; 58 struct regmap *regmap;
59 struct device *dev;
56 u8 port_off_mask; 60 u8 port_off_mask;
57 int gpio_intn; 61 int gpio_intn;
58 int gpio_reset; 62 int gpio_reset;
59 int gpio_connect; 63 int gpio_connect;
60}; 64};
61 65
62static int usb3503_write_register(struct i2c_client *client, 66static int usb3503_reset(struct usb3503 *hub, int state)
63 char reg, char data)
64{
65 return i2c_smbus_write_byte_data(client, reg, data);
66}
67
68static int usb3503_read_register(struct i2c_client *client, char reg)
69{
70 return i2c_smbus_read_byte_data(client, reg);
71}
72
73static int usb3503_set_bits(struct i2c_client *client, char reg, char req)
74{ 67{
75 int err; 68 if (!state && gpio_is_valid(hub->gpio_connect))
76 69 gpio_set_value_cansleep(hub->gpio_connect, 0);
77 err = usb3503_read_register(client, reg);
78 if (err < 0)
79 return err;
80
81 err = usb3503_write_register(client, reg, err | req);
82 if (err < 0)
83 return err;
84
85 return 0;
86}
87
88static int usb3503_clear_bits(struct i2c_client *client, char reg, char req)
89{
90 int err;
91
92 err = usb3503_read_register(client, reg);
93 if (err < 0)
94 return err;
95
96 err = usb3503_write_register(client, reg, err & ~req);
97 if (err < 0)
98 return err;
99
100 return 0;
101}
102 70
103static int usb3503_reset(int gpio_reset, int state) 71 if (gpio_is_valid(hub->gpio_reset))
104{ 72 gpio_set_value_cansleep(hub->gpio_reset, state);
105 if (gpio_is_valid(gpio_reset))
106 gpio_set_value(gpio_reset, state);
107 73
108 /* Wait T_HUBINIT == 4ms for hub logic to stabilize */ 74 /* Wait T_HUBINIT == 4ms for hub logic to stabilize */
109 if (state) 75 if (state)
@@ -112,90 +78,105 @@ static int usb3503_reset(int gpio_reset, int state)
112 return 0; 78 return 0;
113} 79}
114 80
115static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode) 81static int usb3503_connect(struct usb3503 *hub)
116{ 82{
117 struct i2c_client *i2c = hub->client; 83 struct device *dev = hub->dev;
118 int err = 0; 84 int err;
119 85
120 switch (mode) { 86 usb3503_reset(hub, 1);
121 case USB3503_MODE_HUB:
122 usb3503_reset(hub->gpio_reset, 1);
123 87
88 if (hub->regmap) {
124 /* SP_ILOCK: set connect_n, config_n for config */ 89 /* SP_ILOCK: set connect_n, config_n for config */
125 err = usb3503_write_register(i2c, USB3503_SP_ILOCK, 90 err = regmap_write(hub->regmap, USB3503_SP_ILOCK,
126 (USB3503_SPILOCK_CONNECT 91 (USB3503_SPILOCK_CONNECT
127 | USB3503_SPILOCK_CONFIG)); 92 | USB3503_SPILOCK_CONFIG));
128 if (err < 0) { 93 if (err < 0) {
129 dev_err(&i2c->dev, "SP_ILOCK failed (%d)\n", err); 94 dev_err(dev, "SP_ILOCK failed (%d)\n", err);
130 goto err_hubmode; 95 return err;
131 } 96 }
132 97
133 /* PDS : Disable For Self Powered Operation */ 98 /* PDS : Disable For Self Powered Operation */
134 if (hub->port_off_mask) { 99 if (hub->port_off_mask) {
135 err = usb3503_set_bits(i2c, USB3503_PDS, 100 err = regmap_update_bits(hub->regmap, USB3503_PDS,
101 hub->port_off_mask,
136 hub->port_off_mask); 102 hub->port_off_mask);
137 if (err < 0) { 103 if (err < 0) {
138 dev_err(&i2c->dev, "PDS failed (%d)\n", err); 104 dev_err(dev, "PDS failed (%d)\n", err);
139 goto err_hubmode; 105 return err;
140 } 106 }
141 } 107 }
142 108
143 /* CFG1 : SELF_BUS_PWR -> Self-Powerd operation */ 109 /* CFG1 : SELF_BUS_PWR -> Self-Powerd operation */
144 err = usb3503_set_bits(i2c, USB3503_CFG1, USB3503_SELF_BUS_PWR); 110 err = regmap_update_bits(hub->regmap, USB3503_CFG1,
111 USB3503_SELF_BUS_PWR,
112 USB3503_SELF_BUS_PWR);
145 if (err < 0) { 113 if (err < 0) {
146 dev_err(&i2c->dev, "CFG1 failed (%d)\n", err); 114 dev_err(dev, "CFG1 failed (%d)\n", err);
147 goto err_hubmode; 115 return err;
148 } 116 }
149 117
150 /* SP_LOCK: clear connect_n, config_n for hub connect */ 118 /* SP_LOCK: clear connect_n, config_n for hub connect */
151 err = usb3503_clear_bits(i2c, USB3503_SP_ILOCK, 119 err = regmap_update_bits(hub->regmap, USB3503_SP_ILOCK,
152 (USB3503_SPILOCK_CONNECT 120 (USB3503_SPILOCK_CONNECT
153 | USB3503_SPILOCK_CONFIG)); 121 | USB3503_SPILOCK_CONFIG), 0);
154 if (err < 0) { 122 if (err < 0) {
155 dev_err(&i2c->dev, "SP_ILOCK failed (%d)\n", err); 123 dev_err(dev, "SP_ILOCK failed (%d)\n", err);
156 goto err_hubmode; 124 return err;
157 } 125 }
126 }
158 127
159 hub->mode = mode; 128 if (gpio_is_valid(hub->gpio_connect))
160 dev_info(&i2c->dev, "switched to HUB mode\n"); 129 gpio_set_value_cansleep(hub->gpio_connect, 1);
130
131 hub->mode = USB3503_MODE_HUB;
132 dev_info(dev, "switched to HUB mode\n");
133
134 return 0;
135}
136
137static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode)
138{
139 struct device *dev = hub->dev;
140 int err = 0;
141
142 switch (mode) {
143 case USB3503_MODE_HUB:
144 err = usb3503_connect(hub);
161 break; 145 break;
162 146
163 case USB3503_MODE_STANDBY: 147 case USB3503_MODE_STANDBY:
164 usb3503_reset(hub->gpio_reset, 0); 148 usb3503_reset(hub, 0);
165 149
166 hub->mode = mode; 150 hub->mode = mode;
167 dev_info(&i2c->dev, "switched to STANDBY mode\n"); 151 dev_info(dev, "switched to STANDBY mode\n");
168 break; 152 break;
169 153
170 default: 154 default:
171 dev_err(&i2c->dev, "unknown mode is request\n"); 155 dev_err(dev, "unknown mode is requested\n");
172 err = -EINVAL; 156 err = -EINVAL;
173 break; 157 break;
174 } 158 }
175 159
176err_hubmode:
177 return err; 160 return err;
178} 161}
179 162
180static int usb3503_probe(struct i2c_client *i2c, const struct i2c_device_id *id) 163static const struct regmap_config usb3503_regmap_config = {
164 .reg_bits = 8,
165 .val_bits = 8,
166
167 .max_register = USB3503_RESET,
168};
169
170static int usb3503_probe(struct usb3503 *hub)
181{ 171{
182 struct usb3503_platform_data *pdata = i2c->dev.platform_data; 172 struct device *dev = hub->dev;
183 struct device_node *np = i2c->dev.of_node; 173 struct usb3503_platform_data *pdata = dev_get_platdata(dev);
184 struct usb3503 *hub; 174 struct device_node *np = dev->of_node;
185 int err = -ENOMEM; 175 int err;
186 u32 mode = USB3503_MODE_UNKNOWN; 176 u32 mode = USB3503_MODE_HUB;
187 const u32 *property; 177 const u32 *property;
188 int len; 178 int len;
189 179
190 hub = kzalloc(sizeof(struct usb3503), GFP_KERNEL);
191 if (!hub) {
192 dev_err(&i2c->dev, "private data alloc fail\n");
193 return err;
194 }
195
196 i2c_set_clientdata(i2c, hub);
197 hub->client = i2c;
198
199 if (pdata) { 180 if (pdata) {
200 hub->port_off_mask = pdata->port_off_mask; 181 hub->port_off_mask = pdata->port_off_mask;
201 hub->gpio_intn = pdata->gpio_intn; 182 hub->gpio_intn = pdata->gpio_intn;
@@ -215,10 +196,10 @@ static int usb3503_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
215 } 196 }
216 } 197 }
217 198
218 hub->gpio_intn = of_get_named_gpio(np, "connect-gpios", 0); 199 hub->gpio_intn = of_get_named_gpio(np, "intn-gpios", 0);
219 if (hub->gpio_intn == -EPROBE_DEFER) 200 if (hub->gpio_intn == -EPROBE_DEFER)
220 return -EPROBE_DEFER; 201 return -EPROBE_DEFER;
221 hub->gpio_connect = of_get_named_gpio(np, "intn-gpios", 0); 202 hub->gpio_connect = of_get_named_gpio(np, "connect-gpios", 0);
222 if (hub->gpio_connect == -EPROBE_DEFER) 203 if (hub->gpio_connect == -EPROBE_DEFER)
223 return -EPROBE_DEFER; 204 return -EPROBE_DEFER;
224 hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0); 205 hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0);
@@ -228,72 +209,86 @@ static int usb3503_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
228 hub->mode = mode; 209 hub->mode = mode;
229 } 210 }
230 211
212 if (hub->port_off_mask && !hub->regmap)
213 dev_err(dev, "Ports disabled with no control interface\n");
214
231 if (gpio_is_valid(hub->gpio_intn)) { 215 if (gpio_is_valid(hub->gpio_intn)) {
232 err = gpio_request_one(hub->gpio_intn, 216 err = devm_gpio_request_one(dev, hub->gpio_intn,
233 GPIOF_OUT_INIT_HIGH, "usb3503 intn"); 217 GPIOF_OUT_INIT_HIGH, "usb3503 intn");
234 if (err) { 218 if (err) {
235 dev_err(&i2c->dev, 219 dev_err(dev,
236 "unable to request GPIO %d as connect pin (%d)\n", 220 "unable to request GPIO %d as connect pin (%d)\n",
237 hub->gpio_intn, err); 221 hub->gpio_intn, err);
238 goto err_out; 222 return err;
239 } 223 }
240 } 224 }
241 225
242 if (gpio_is_valid(hub->gpio_connect)) { 226 if (gpio_is_valid(hub->gpio_connect)) {
243 err = gpio_request_one(hub->gpio_connect, 227 err = devm_gpio_request_one(dev, hub->gpio_connect,
244 GPIOF_OUT_INIT_HIGH, "usb3503 connect"); 228 GPIOF_OUT_INIT_LOW, "usb3503 connect");
245 if (err) { 229 if (err) {
246 dev_err(&i2c->dev, 230 dev_err(dev,
247 "unable to request GPIO %d as connect pin (%d)\n", 231 "unable to request GPIO %d as connect pin (%d)\n",
248 hub->gpio_connect, err); 232 hub->gpio_connect, err);
249 goto err_gpio_connect; 233 return err;
250 } 234 }
251 } 235 }
252 236
253 if (gpio_is_valid(hub->gpio_reset)) { 237 if (gpio_is_valid(hub->gpio_reset)) {
254 err = gpio_request_one(hub->gpio_reset, 238 err = devm_gpio_request_one(dev, hub->gpio_reset,
255 GPIOF_OUT_INIT_LOW, "usb3503 reset"); 239 GPIOF_OUT_INIT_LOW, "usb3503 reset");
256 if (err) { 240 if (err) {
257 dev_err(&i2c->dev, 241 dev_err(dev,
258 "unable to request GPIO %d as reset pin (%d)\n", 242 "unable to request GPIO %d as reset pin (%d)\n",
259 hub->gpio_reset, err); 243 hub->gpio_reset, err);
260 goto err_gpio_reset; 244 return err;
261 } 245 }
262 } 246 }
263 247
264 usb3503_switch_mode(hub, hub->mode); 248 usb3503_switch_mode(hub, hub->mode);
265 249
266 dev_info(&i2c->dev, "%s: probed on %s mode\n", __func__, 250 dev_info(dev, "%s: probed in %s mode\n", __func__,
267 (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby"); 251 (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby");
268 252
269 return 0; 253 return 0;
254}
270 255
271err_gpio_reset: 256static int usb3503_i2c_probe(struct i2c_client *i2c,
272 if (gpio_is_valid(hub->gpio_connect)) 257 const struct i2c_device_id *id)
273 gpio_free(hub->gpio_connect); 258{
274err_gpio_connect: 259 struct usb3503 *hub;
275 if (gpio_is_valid(hub->gpio_intn)) 260 int err;
276 gpio_free(hub->gpio_intn);
277err_out:
278 kfree(hub);
279 261
280 return err; 262 hub = devm_kzalloc(&i2c->dev, sizeof(struct usb3503), GFP_KERNEL);
263 if (!hub) {
264 dev_err(&i2c->dev, "private data alloc fail\n");
265 return -ENOMEM;
266 }
267
268 i2c_set_clientdata(i2c, hub);
269 hub->regmap = devm_regmap_init_i2c(i2c, &usb3503_regmap_config);
270 if (IS_ERR(hub->regmap)) {
271 err = PTR_ERR(hub->regmap);
272 dev_err(&i2c->dev, "Failed to initialise regmap: %d\n", err);
273 return err;
274 }
275 hub->dev = &i2c->dev;
276
277 return usb3503_probe(hub);
281} 278}
282 279
283static int usb3503_remove(struct i2c_client *i2c) 280static int usb3503_platform_probe(struct platform_device *pdev)
284{ 281{
285 struct usb3503 *hub = i2c_get_clientdata(i2c); 282 struct usb3503 *hub;
286
287 if (gpio_is_valid(hub->gpio_intn))
288 gpio_free(hub->gpio_intn);
289 if (gpio_is_valid(hub->gpio_connect))
290 gpio_free(hub->gpio_connect);
291 if (gpio_is_valid(hub->gpio_reset))
292 gpio_free(hub->gpio_reset);
293 283
294 kfree(hub); 284 hub = devm_kzalloc(&pdev->dev, sizeof(struct usb3503), GFP_KERNEL);
285 if (!hub) {
286 dev_err(&pdev->dev, "private data alloc fail\n");
287 return -ENOMEM;
288 }
289 hub->dev = &pdev->dev;
295 290
296 return 0; 291 return usb3503_probe(hub);
297} 292}
298 293
299static const struct i2c_device_id usb3503_id[] = { 294static const struct i2c_device_id usb3503_id[] = {
@@ -305,22 +300,53 @@ MODULE_DEVICE_TABLE(i2c, usb3503_id);
305#ifdef CONFIG_OF 300#ifdef CONFIG_OF
306static const struct of_device_id usb3503_of_match[] = { 301static const struct of_device_id usb3503_of_match[] = {
307 { .compatible = "smsc,usb3503", }, 302 { .compatible = "smsc,usb3503", },
303 { .compatible = "smsc,usb3503a", },
308 {}, 304 {},
309}; 305};
310MODULE_DEVICE_TABLE(of, usb3503_of_match); 306MODULE_DEVICE_TABLE(of, usb3503_of_match);
311#endif 307#endif
312 308
313static struct i2c_driver usb3503_driver = { 309static struct i2c_driver usb3503_i2c_driver = {
314 .driver = { 310 .driver = {
315 .name = USB3503_I2C_NAME, 311 .name = USB3503_I2C_NAME,
316 .of_match_table = of_match_ptr(usb3503_of_match), 312 .of_match_table = of_match_ptr(usb3503_of_match),
317 }, 313 },
318 .probe = usb3503_probe, 314 .probe = usb3503_i2c_probe,
319 .remove = usb3503_remove,
320 .id_table = usb3503_id, 315 .id_table = usb3503_id,
321}; 316};
322 317
323module_i2c_driver(usb3503_driver); 318static struct platform_driver usb3503_platform_driver = {
319 .driver = {
320 .name = USB3503_I2C_NAME,
321 .of_match_table = of_match_ptr(usb3503_of_match),
322 .owner = THIS_MODULE,
323 },
324 .probe = usb3503_platform_probe,
325};
326
327static int __init usb3503_init(void)
328{
329 int err;
330
331 err = i2c_register_driver(THIS_MODULE, &usb3503_i2c_driver);
332 if (err != 0)
333 pr_err("usb3503: Failed to register I2C driver: %d\n", err);
334
335 err = platform_driver_register(&usb3503_platform_driver);
336 if (err != 0)
337 pr_err("usb3503: Failed to register platform driver: %d\n",
338 err);
339
340 return 0;
341}
342module_init(usb3503_init);
343
344static void __exit usb3503_exit(void)
345{
346 platform_driver_unregister(&usb3503_platform_driver);
347 i2c_del_driver(&usb3503_i2c_driver);
348}
349module_exit(usb3503_exit);
324 350
325MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>"); 351MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>");
326MODULE_DESCRIPTION("USB3503 USB HUB driver"); 352MODULE_DESCRIPTION("USB3503 USB HUB driver");
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 8b4ca1cb450a..aa28ac8c7607 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -747,9 +747,9 @@ static int ch9_postconfig(struct usbtest_dev *dev)
747 747
748 /* [9.4.5] get_status always works */ 748 /* [9.4.5] get_status always works */
749 retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf); 749 retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf);
750 if (retval != 2) { 750 if (retval) {
751 dev_err(&iface->dev, "get dev status --> %d\n", retval); 751 dev_err(&iface->dev, "get dev status --> %d\n", retval);
752 return (retval < 0) ? retval : -EDOM; 752 return retval;
753 } 753 }
754 754
755 /* FIXME configuration.bmAttributes says if we could try to set/clear 755 /* FIXME configuration.bmAttributes says if we could try to set/clear
@@ -758,9 +758,9 @@ static int ch9_postconfig(struct usbtest_dev *dev)
758 758
759 retval = usb_get_status(udev, USB_RECIP_INTERFACE, 759 retval = usb_get_status(udev, USB_RECIP_INTERFACE,
760 iface->altsetting[0].desc.bInterfaceNumber, dev->buf); 760 iface->altsetting[0].desc.bInterfaceNumber, dev->buf);
761 if (retval != 2) { 761 if (retval) {
762 dev_err(&iface->dev, "get interface status --> %d\n", retval); 762 dev_err(&iface->dev, "get interface status --> %d\n", retval);
763 return (retval < 0) ? retval : -EDOM; 763 return retval;
764 } 764 }
765 /* FIXME get status for each endpoint in the interface */ 765 /* FIXME get status for each endpoint in the interface */
766 766
@@ -1351,7 +1351,6 @@ static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
1351 ep, retval); 1351 ep, retval);
1352 return retval; 1352 return retval;
1353 } 1353 }
1354 le16_to_cpus(&status);
1355 if (status != 1) { 1354 if (status != 1) {
1356 ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status); 1355 ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status);
1357 return -EINVAL; 1356 return -EINVAL;
diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
index e129cf661223..40ef40affe83 100644
--- a/drivers/usb/misc/uss720.c
+++ b/drivers/usb/misc/uss720.c
@@ -75,7 +75,7 @@ struct uss720_async_request {
75 struct list_head asynclist; 75 struct list_head asynclist;
76 struct completion compl; 76 struct completion compl;
77 struct urb *urb; 77 struct urb *urb;
78 struct usb_ctrlrequest dr; 78 struct usb_ctrlrequest *dr;
79 __u8 reg[7]; 79 __u8 reg[7];
80}; 80};
81 81
@@ -98,6 +98,7 @@ static void destroy_async(struct kref *kref)
98 98
99 if (likely(rq->urb)) 99 if (likely(rq->urb))
100 usb_free_urb(rq->urb); 100 usb_free_urb(rq->urb);
101 kfree(rq->dr);
101 spin_lock_irqsave(&priv->asynclock, flags); 102 spin_lock_irqsave(&priv->asynclock, flags);
102 list_del_init(&rq->asynclist); 103 list_del_init(&rq->asynclist);
103 spin_unlock_irqrestore(&priv->asynclock, flags); 104 spin_unlock_irqrestore(&priv->asynclock, flags);
@@ -120,7 +121,7 @@ static void async_complete(struct urb *urb)
120 if (status) { 121 if (status) {
121 dev_err(&urb->dev->dev, "async_complete: urb error %d\n", 122 dev_err(&urb->dev->dev, "async_complete: urb error %d\n",
122 status); 123 status);
123 } else if (rq->dr.bRequest == 3) { 124 } else if (rq->dr->bRequest == 3) {
124 memcpy(priv->reg, rq->reg, sizeof(priv->reg)); 125 memcpy(priv->reg, rq->reg, sizeof(priv->reg));
125#if 0 126#if 0
126 dev_dbg(&priv->usbdev->dev, 127 dev_dbg(&priv->usbdev->dev,
@@ -152,7 +153,7 @@ static struct uss720_async_request *submit_async_request(struct parport_uss720_p
152 usbdev = priv->usbdev; 153 usbdev = priv->usbdev;
153 if (!usbdev) 154 if (!usbdev)
154 return NULL; 155 return NULL;
155 rq = kmalloc(sizeof(struct uss720_async_request), mem_flags); 156 rq = kzalloc(sizeof(struct uss720_async_request), mem_flags);
156 if (!rq) { 157 if (!rq) {
157 dev_err(&usbdev->dev, "submit_async_request out of memory\n"); 158 dev_err(&usbdev->dev, "submit_async_request out of memory\n");
158 return NULL; 159 return NULL;
@@ -168,13 +169,18 @@ static struct uss720_async_request *submit_async_request(struct parport_uss720_p
168 dev_err(&usbdev->dev, "submit_async_request out of memory\n"); 169 dev_err(&usbdev->dev, "submit_async_request out of memory\n");
169 return NULL; 170 return NULL;
170 } 171 }
171 rq->dr.bRequestType = requesttype; 172 rq->dr = kmalloc(sizeof(*rq->dr), mem_flags);
172 rq->dr.bRequest = request; 173 if (!rq->dr) {
173 rq->dr.wValue = cpu_to_le16(value); 174 kref_put(&rq->ref_count, destroy_async);
174 rq->dr.wIndex = cpu_to_le16(index); 175 return NULL;
175 rq->dr.wLength = cpu_to_le16((request == 3) ? sizeof(rq->reg) : 0); 176 }
177 rq->dr->bRequestType = requesttype;
178 rq->dr->bRequest = request;
179 rq->dr->wValue = cpu_to_le16(value);
180 rq->dr->wIndex = cpu_to_le16(index);
181 rq->dr->wLength = cpu_to_le16((request == 3) ? sizeof(rq->reg) : 0);
176 usb_fill_control_urb(rq->urb, usbdev, (requesttype & 0x80) ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0), 182 usb_fill_control_urb(rq->urb, usbdev, (requesttype & 0x80) ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0),
177 (unsigned char *)&rq->dr, 183 (unsigned char *)rq->dr,
178 (request == 3) ? rq->reg : NULL, (request == 3) ? sizeof(rq->reg) : 0, async_complete, rq); 184 (request == 3) ? rq->reg : NULL, (request == 3) ? sizeof(rq->reg) : 0, async_complete, rq);
179 /* rq->urb->transfer_flags |= URB_ASYNC_UNLINK; */ 185 /* rq->urb->transfer_flags |= URB_ASYNC_UNLINK; */
180 spin_lock_irqsave(&priv->asynclock, flags); 186 spin_lock_irqsave(&priv->asynclock, flags);
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 797e3fd45510..c64ee09a7c0e 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -83,6 +83,8 @@ config USB_MUSB_AM35X
83 83
84config USB_MUSB_DSPS 84config USB_MUSB_DSPS
85 tristate "TI DSPS platforms" 85 tristate "TI DSPS platforms"
86 select USB_MUSB_AM335X_CHILD
87 depends on OF_IRQ
86 88
87config USB_MUSB_BLACKFIN 89config USB_MUSB_BLACKFIN
88 tristate "Blackfin" 90 tristate "Blackfin"
@@ -93,6 +95,9 @@ config USB_MUSB_UX500
93 95
94endchoice 96endchoice
95 97
98config USB_MUSB_AM335X_CHILD
99 tristate
100
96choice 101choice
97 prompt 'MUSB DMA mode' 102 prompt 'MUSB DMA mode'
98 default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM 103 default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM
@@ -125,6 +130,10 @@ config USB_TI_CPPI_DMA
125 help 130 help
126 Enable DMA transfers when TI CPPI DMA is available. 131 Enable DMA transfers when TI CPPI DMA is available.
127 132
133config USB_TI_CPPI41_DMA
134 bool 'TI CPPI 4.1 (AM335x)'
135 depends on ARCH_OMAP
136
128config USB_TUSB_OMAP_DMA 137config USB_TUSB_OMAP_DMA
129 bool 'TUSB 6010' 138 bool 'TUSB 6010'
130 depends on USB_MUSB_TUSB6010 139 depends on USB_MUSB_TUSB6010
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index 2b82ed7c85ca..c5ea5c6dc169 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -20,6 +20,9 @@ obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o
20obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o 20obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o
21obj-$(CONFIG_USB_MUSB_UX500) += ux500.o 21obj-$(CONFIG_USB_MUSB_UX500) += ux500.o
22 22
23
24obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o
25
23# the kconfig must guarantee that only one of the 26# the kconfig must guarantee that only one of the
24# possible I/O schemes will be enabled at a time ... 27# possible I/O schemes will be enabled at a time ...
25# PIO only, or DMA (several potential schemes). 28# PIO only, or DMA (several potential schemes).
@@ -29,3 +32,4 @@ musb_hdrc-$(CONFIG_USB_INVENTRA_DMA) += musbhsdma.o
29musb_hdrc-$(CONFIG_USB_TI_CPPI_DMA) += cppi_dma.o 32musb_hdrc-$(CONFIG_USB_TI_CPPI_DMA) += cppi_dma.o
30musb_hdrc-$(CONFIG_USB_TUSB_OMAP_DMA) += tusb6010_omap.o 33musb_hdrc-$(CONFIG_USB_TUSB_OMAP_DMA) += tusb6010_omap.o
31musb_hdrc-$(CONFIG_USB_UX500_DMA) += ux500_dma.o 34musb_hdrc-$(CONFIG_USB_UX500_DMA) += ux500_dma.o
35musb_hdrc-$(CONFIG_USB_TI_CPPI41_DMA) += musb_cppi41.o
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 2231850c0625..5c310c664218 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -33,7 +33,7 @@
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
36#include <linux/usb/nop-usb-xceiv.h> 36#include <linux/usb/usb_phy_gen_xceiv.h>
37#include <linux/platform_data/usb-omap.h> 37#include <linux/platform_data/usb-omap.h>
38 38
39#include "musb_core.h" 39#include "musb_core.h"
@@ -218,7 +218,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
218 struct musb *musb = hci; 218 struct musb *musb = hci;
219 void __iomem *reg_base = musb->ctrl_base; 219 void __iomem *reg_base = musb->ctrl_base;
220 struct device *dev = musb->controller; 220 struct device *dev = musb->controller;
221 struct musb_hdrc_platform_data *plat = dev->platform_data; 221 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
222 struct omap_musb_board_data *data = plat->board_data; 222 struct omap_musb_board_data *data = plat->board_data;
223 struct usb_otg *otg = musb->xceiv->otg; 223 struct usb_otg *otg = musb->xceiv->otg;
224 unsigned long flags; 224 unsigned long flags;
@@ -335,7 +335,7 @@ eoi:
335static int am35x_musb_set_mode(struct musb *musb, u8 musb_mode) 335static int am35x_musb_set_mode(struct musb *musb, u8 musb_mode)
336{ 336{
337 struct device *dev = musb->controller; 337 struct device *dev = musb->controller;
338 struct musb_hdrc_platform_data *plat = dev->platform_data; 338 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
339 struct omap_musb_board_data *data = plat->board_data; 339 struct omap_musb_board_data *data = plat->board_data;
340 int retval = 0; 340 int retval = 0;
341 341
@@ -350,7 +350,7 @@ static int am35x_musb_set_mode(struct musb *musb, u8 musb_mode)
350static int am35x_musb_init(struct musb *musb) 350static int am35x_musb_init(struct musb *musb)
351{ 351{
352 struct device *dev = musb->controller; 352 struct device *dev = musb->controller;
353 struct musb_hdrc_platform_data *plat = dev->platform_data; 353 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
354 struct omap_musb_board_data *data = plat->board_data; 354 struct omap_musb_board_data *data = plat->board_data;
355 void __iomem *reg_base = musb->ctrl_base; 355 void __iomem *reg_base = musb->ctrl_base;
356 u32 rev; 356 u32 rev;
@@ -394,7 +394,7 @@ static int am35x_musb_init(struct musb *musb)
394static int am35x_musb_exit(struct musb *musb) 394static int am35x_musb_exit(struct musb *musb)
395{ 395{
396 struct device *dev = musb->controller; 396 struct device *dev = musb->controller;
397 struct musb_hdrc_platform_data *plat = dev->platform_data; 397 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
398 struct omap_musb_board_data *data = plat->board_data; 398 struct omap_musb_board_data *data = plat->board_data;
399 399
400 del_timer_sync(&otg_workaround); 400 del_timer_sync(&otg_workaround);
@@ -456,7 +456,7 @@ static u64 am35x_dmamask = DMA_BIT_MASK(32);
456 456
457static int am35x_probe(struct platform_device *pdev) 457static int am35x_probe(struct platform_device *pdev)
458{ 458{
459 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 459 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
460 struct platform_device *musb; 460 struct platform_device *musb;
461 struct am35x_glue *glue; 461 struct am35x_glue *glue;
462 462
@@ -577,7 +577,7 @@ static int am35x_remove(struct platform_device *pdev)
577static int am35x_suspend(struct device *dev) 577static int am35x_suspend(struct device *dev)
578{ 578{
579 struct am35x_glue *glue = dev_get_drvdata(dev); 579 struct am35x_glue *glue = dev_get_drvdata(dev);
580 struct musb_hdrc_platform_data *plat = dev->platform_data; 580 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
581 struct omap_musb_board_data *data = plat->board_data; 581 struct omap_musb_board_data *data = plat->board_data;
582 582
583 /* Shutdown the on-chip PHY and its PLL. */ 583 /* Shutdown the on-chip PHY and its PLL. */
@@ -593,7 +593,7 @@ static int am35x_suspend(struct device *dev)
593static int am35x_resume(struct device *dev) 593static int am35x_resume(struct device *dev)
594{ 594{
595 struct am35x_glue *glue = dev_get_drvdata(dev); 595 struct am35x_glue *glue = dev_get_drvdata(dev);
596 struct musb_hdrc_platform_data *plat = dev->platform_data; 596 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
597 struct omap_musb_board_data *data = plat->board_data; 597 struct omap_musb_board_data *data = plat->board_data;
598 int ret; 598 int ret;
599 599
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index 6ba8439bd5a6..72e2056b6082 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -19,7 +19,7 @@
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
21#include <linux/prefetch.h> 21#include <linux/prefetch.h>
22#include <linux/usb/nop-usb-xceiv.h> 22#include <linux/usb/usb_phy_gen_xceiv.h>
23 23
24#include <asm/cacheflush.h> 24#include <asm/cacheflush.h>
25 25
@@ -451,7 +451,7 @@ static u64 bfin_dmamask = DMA_BIT_MASK(32);
451static int bfin_probe(struct platform_device *pdev) 451static int bfin_probe(struct platform_device *pdev)
452{ 452{
453 struct resource musb_resources[2]; 453 struct resource musb_resources[2];
454 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 454 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
455 struct platform_device *musb; 455 struct platform_device *musb;
456 struct bfin_glue *glue; 456 struct bfin_glue *glue;
457 457
diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index 9db211ee15b5..904fb85d85a6 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -150,14 +150,11 @@ static void cppi_pool_free(struct cppi_channel *c)
150 c->last_processed = NULL; 150 c->last_processed = NULL;
151} 151}
152 152
153static int cppi_controller_start(struct dma_controller *c) 153static void cppi_controller_start(struct cppi *controller)
154{ 154{
155 struct cppi *controller;
156 void __iomem *tibase; 155 void __iomem *tibase;
157 int i; 156 int i;
158 157
159 controller = container_of(c, struct cppi, controller);
160
161 /* do whatever is necessary to start controller */ 158 /* do whatever is necessary to start controller */
162 for (i = 0; i < ARRAY_SIZE(controller->tx); i++) { 159 for (i = 0; i < ARRAY_SIZE(controller->tx); i++) {
163 controller->tx[i].transmit = true; 160 controller->tx[i].transmit = true;
@@ -212,8 +209,6 @@ static int cppi_controller_start(struct dma_controller *c)
212 /* disable RNDIS mode, also host rx RNDIS autorequest */ 209 /* disable RNDIS mode, also host rx RNDIS autorequest */
213 musb_writel(tibase, DAVINCI_RNDIS_REG, 0); 210 musb_writel(tibase, DAVINCI_RNDIS_REG, 0);
214 musb_writel(tibase, DAVINCI_AUTOREQ_REG, 0); 211 musb_writel(tibase, DAVINCI_AUTOREQ_REG, 0);
215
216 return 0;
217} 212}
218 213
219/* 214/*
@@ -222,14 +217,12 @@ static int cppi_controller_start(struct dma_controller *c)
222 * De-Init the DMA controller as necessary. 217 * De-Init the DMA controller as necessary.
223 */ 218 */
224 219
225static int cppi_controller_stop(struct dma_controller *c) 220static void cppi_controller_stop(struct cppi *controller)
226{ 221{
227 struct cppi *controller;
228 void __iomem *tibase; 222 void __iomem *tibase;
229 int i; 223 int i;
230 struct musb *musb; 224 struct musb *musb;
231 225
232 controller = container_of(c, struct cppi, controller);
233 musb = controller->musb; 226 musb = controller->musb;
234 227
235 tibase = controller->tibase; 228 tibase = controller->tibase;
@@ -255,8 +248,6 @@ static int cppi_controller_stop(struct dma_controller *c)
255 /*disable tx/rx cppi */ 248 /*disable tx/rx cppi */
256 musb_writel(tibase, DAVINCI_TXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_DISABLE); 249 musb_writel(tibase, DAVINCI_TXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_DISABLE);
257 musb_writel(tibase, DAVINCI_RXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_DISABLE); 250 musb_writel(tibase, DAVINCI_RXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_DISABLE);
258
259 return 0;
260} 251}
261 252
262/* While dma channel is allocated, we only want the core irqs active 253/* While dma channel is allocated, we only want the core irqs active
@@ -1321,8 +1312,6 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *mr
1321 controller->tibase = mregs - DAVINCI_BASE_OFFSET; 1312 controller->tibase = mregs - DAVINCI_BASE_OFFSET;
1322 1313
1323 controller->musb = musb; 1314 controller->musb = musb;
1324 controller->controller.start = cppi_controller_start;
1325 controller->controller.stop = cppi_controller_stop;
1326 controller->controller.channel_alloc = cppi_channel_allocate; 1315 controller->controller.channel_alloc = cppi_channel_allocate;
1327 controller->controller.channel_release = cppi_channel_release; 1316 controller->controller.channel_release = cppi_channel_release;
1328 controller->controller.channel_program = cppi_channel_program; 1317 controller->controller.channel_program = cppi_channel_program;
@@ -1351,6 +1340,7 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *mr
1351 controller->irq = irq; 1340 controller->irq = irq;
1352 } 1341 }
1353 1342
1343 cppi_controller_start(controller);
1354 return &controller->controller; 1344 return &controller->controller;
1355} 1345}
1356 1346
@@ -1363,6 +1353,8 @@ void dma_controller_destroy(struct dma_controller *c)
1363 1353
1364 cppi = container_of(c, struct cppi, controller); 1354 cppi = container_of(c, struct cppi, controller);
1365 1355
1356 cppi_controller_stop(cppi);
1357
1366 if (cppi->irq) 1358 if (cppi->irq)
1367 free_irq(cppi->irq, cppi->musb); 1359 free_irq(cppi->irq, cppi->musb);
1368 1360
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 0da6f648a9fe..d9ddf4122f37 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -33,7 +33,7 @@
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
36#include <linux/usb/nop-usb-xceiv.h> 36#include <linux/usb/usb_phy_gen_xceiv.h>
37 37
38#include <mach/da8xx.h> 38#include <mach/da8xx.h>
39#include <linux/platform_data/usb-davinci.h> 39#include <linux/platform_data/usb-davinci.h>
@@ -477,7 +477,7 @@ static u64 da8xx_dmamask = DMA_BIT_MASK(32);
477static int da8xx_probe(struct platform_device *pdev) 477static int da8xx_probe(struct platform_device *pdev)
478{ 478{
479 struct resource musb_resources[2]; 479 struct resource musb_resources[2];
480 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 480 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
481 struct platform_device *musb; 481 struct platform_device *musb;
482 struct da8xx_glue *glue; 482 struct da8xx_glue *glue;
483 483
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index f8aeaf2e2cd1..ed0834e2b72e 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -33,7 +33,7 @@
33#include <linux/gpio.h> 33#include <linux/gpio.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
36#include <linux/usb/nop-usb-xceiv.h> 36#include <linux/usb/usb_phy_gen_xceiv.h>
37 37
38#include <mach/cputype.h> 38#include <mach/cputype.h>
39#include <mach/hardware.h> 39#include <mach/hardware.h>
@@ -510,7 +510,7 @@ static u64 davinci_dmamask = DMA_BIT_MASK(32);
510static int davinci_probe(struct platform_device *pdev) 510static int davinci_probe(struct platform_device *pdev)
511{ 511{
512 struct resource musb_resources[2]; 512 struct resource musb_resources[2];
513 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 513 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
514 struct platform_device *musb; 514 struct platform_device *musb;
515 struct davinci_glue *glue; 515 struct davinci_glue *glue;
516 struct clk *clk; 516 struct clk *clk;
diff --git a/drivers/usb/musb/musb_am335x.c b/drivers/usb/musb/musb_am335x.c
new file mode 100644
index 000000000000..41ac5b5b57ce
--- /dev/null
+++ b/drivers/usb/musb/musb_am335x.c
@@ -0,0 +1,55 @@
1#include <linux/init.h>
2#include <linux/platform_device.h>
3#include <linux/pm_runtime.h>
4#include <linux/module.h>
5#include <linux/of_platform.h>
6
7static int am335x_child_probe(struct platform_device *pdev)
8{
9 int ret;
10
11 pm_runtime_enable(&pdev->dev);
12
13 ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
14 if (ret)
15 goto err;
16
17 return 0;
18err:
19 pm_runtime_disable(&pdev->dev);
20 return ret;
21}
22
23static int of_remove_populated_child(struct device *dev, void *d)
24{
25 struct platform_device *pdev = to_platform_device(dev);
26
27 of_device_unregister(pdev);
28 return 0;
29}
30
31static int am335x_child_remove(struct platform_device *pdev)
32{
33 device_for_each_child(&pdev->dev, NULL, of_remove_populated_child);
34 pm_runtime_disable(&pdev->dev);
35 return 0;
36}
37
38static const struct of_device_id am335x_child_of_match[] = {
39 { .compatible = "ti,am33xx-usb" },
40 { },
41};
42MODULE_DEVICE_TABLE(of, am335x_child_of_match);
43
44static struct platform_driver am335x_child_driver = {
45 .probe = am335x_child_probe,
46 .remove = am335x_child_remove,
47 .driver = {
48 .name = "am335x-usb-childs",
49 .of_match_table = of_match_ptr(am335x_child_of_match),
50 },
51};
52
53module_platform_driver(am335x_child_driver);
54MODULE_DESCRIPTION("AM33xx child devices");
55MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 29a24ced6748..18e877ffe7b7 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -99,7 +99,6 @@
99#include <linux/prefetch.h> 99#include <linux/prefetch.h>
100#include <linux/platform_device.h> 100#include <linux/platform_device.h>
101#include <linux/io.h> 101#include <linux/io.h>
102#include <linux/idr.h>
103#include <linux/dma-mapping.h> 102#include <linux/dma-mapping.h>
104 103
105#include "musb_core.h" 104#include "musb_core.h"
@@ -1764,12 +1763,8 @@ static void musb_free(struct musb *musb)
1764 disable_irq_wake(musb->nIrq); 1763 disable_irq_wake(musb->nIrq);
1765 free_irq(musb->nIrq, musb); 1764 free_irq(musb->nIrq, musb);
1766 } 1765 }
1767 if (is_dma_capable() && musb->dma_controller) { 1766 if (musb->dma_controller)
1768 struct dma_controller *c = musb->dma_controller; 1767 dma_controller_destroy(musb->dma_controller);
1769
1770 (void) c->stop(c);
1771 dma_controller_destroy(c);
1772 }
1773 1768
1774 musb_host_free(musb); 1769 musb_host_free(musb);
1775} 1770}
@@ -1787,7 +1782,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1787{ 1782{
1788 int status; 1783 int status;
1789 struct musb *musb; 1784 struct musb *musb;
1790 struct musb_hdrc_platform_data *plat = dev->platform_data; 1785 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
1791 1786
1792 /* The driver might handle more features than the board; OK. 1787 /* The driver might handle more features than the board; OK.
1793 * Fail when the board needs a feature that's not enabled. 1788 * Fail when the board needs a feature that's not enabled.
@@ -1844,19 +1839,8 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1844 1839
1845 pm_runtime_get_sync(musb->controller); 1840 pm_runtime_get_sync(musb->controller);
1846 1841
1847#ifndef CONFIG_MUSB_PIO_ONLY 1842 if (use_dma && dev->dma_mask)
1848 if (use_dma && dev->dma_mask) { 1843 musb->dma_controller = dma_controller_create(musb, musb->mregs);
1849 struct dma_controller *c;
1850
1851 c = dma_controller_create(musb, musb->mregs);
1852 musb->dma_controller = c;
1853 if (c)
1854 (void) c->start(c);
1855 }
1856#endif
1857 /* ideally this would be abstracted in platform setup */
1858 if (!is_dma_capable() || !musb->dma_controller)
1859 dev->dma_mask = NULL;
1860 1844
1861 /* be sure interrupts are disabled before connecting ISR */ 1845 /* be sure interrupts are disabled before connecting ISR */
1862 musb_platform_disable(musb); 1846 musb_platform_disable(musb);
@@ -1944,6 +1928,8 @@ fail4:
1944 musb_gadget_cleanup(musb); 1928 musb_gadget_cleanup(musb);
1945 1929
1946fail3: 1930fail3:
1931 if (musb->dma_controller)
1932 dma_controller_destroy(musb->dma_controller);
1947 pm_runtime_put_sync(musb->controller); 1933 pm_runtime_put_sync(musb->controller);
1948 1934
1949fail2: 1935fail2:
@@ -2002,9 +1988,6 @@ static int musb_remove(struct platform_device *pdev)
2002 1988
2003 musb_free(musb); 1989 musb_free(musb);
2004 device_init_wakeup(dev, 0); 1990 device_init_wakeup(dev, 0);
2005#ifndef CONFIG_MUSB_PIO_ONLY
2006 dma_set_mask(dev, *dev->parent->dma_mask);
2007#endif
2008 return 0; 1991 return 0;
2009} 1992}
2010 1993
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 7d341c387eab..65f3917b4fc5 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -83,11 +83,6 @@ enum {
83 MUSB_PORT_MODE_DUAL_ROLE, 83 MUSB_PORT_MODE_DUAL_ROLE,
84}; 84};
85 85
86#ifdef CONFIG_PROC_FS
87#include <linux/fs.h>
88#define MUSB_CONFIG_PROC_FS
89#endif
90
91/****************************** CONSTANTS ********************************/ 86/****************************** CONSTANTS ********************************/
92 87
93#ifndef MUSB_C_NUM_EPS 88#ifndef MUSB_C_NUM_EPS
@@ -425,9 +420,6 @@ struct musb {
425 420
426 struct musb_hdrc_config *config; 421 struct musb_hdrc_config *config;
427 422
428#ifdef MUSB_CONFIG_PROC_FS
429 struct proc_dir_entry *proc_entry;
430#endif
431 int xceiv_old_state; 423 int xceiv_old_state;
432#ifdef CONFIG_DEBUG_FS 424#ifdef CONFIG_DEBUG_FS
433 struct dentry *debugfs_root; 425 struct dentry *debugfs_root;
diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c
new file mode 100644
index 000000000000..e64701d15401
--- /dev/null
+++ b/drivers/usb/musb/musb_cppi41.c
@@ -0,0 +1,555 @@
1#include <linux/device.h>
2#include <linux/dma-mapping.h>
3#include <linux/dmaengine.h>
4#include <linux/sizes.h>
5#include <linux/platform_device.h>
6#include <linux/of.h>
7
8#include "musb_core.h"
9
10#define RNDIS_REG(x) (0x80 + ((x - 1) * 4))
11
12#define EP_MODE_AUTOREG_NONE 0
13#define EP_MODE_AUTOREG_ALL_NEOP 1
14#define EP_MODE_AUTOREG_ALWAYS 3
15
16#define EP_MODE_DMA_TRANSPARENT 0
17#define EP_MODE_DMA_RNDIS 1
18#define EP_MODE_DMA_GEN_RNDIS 3
19
20#define USB_CTRL_TX_MODE 0x70
21#define USB_CTRL_RX_MODE 0x74
22#define USB_CTRL_AUTOREQ 0xd0
23#define USB_TDOWN 0xd8
24
25struct cppi41_dma_channel {
26 struct dma_channel channel;
27 struct cppi41_dma_controller *controller;
28 struct musb_hw_ep *hw_ep;
29 struct dma_chan *dc;
30 dma_cookie_t cookie;
31 u8 port_num;
32 u8 is_tx;
33 u8 is_allocated;
34 u8 usb_toggle;
35
36 dma_addr_t buf_addr;
37 u32 total_len;
38 u32 prog_len;
39 u32 transferred;
40 u32 packet_sz;
41};
42
43#define MUSB_DMA_NUM_CHANNELS 15
44
45struct cppi41_dma_controller {
46 struct dma_controller controller;
47 struct cppi41_dma_channel rx_channel[MUSB_DMA_NUM_CHANNELS];
48 struct cppi41_dma_channel tx_channel[MUSB_DMA_NUM_CHANNELS];
49 struct musb *musb;
50 u32 rx_mode;
51 u32 tx_mode;
52 u32 auto_req;
53};
54
55static void save_rx_toggle(struct cppi41_dma_channel *cppi41_channel)
56{
57 u16 csr;
58 u8 toggle;
59
60 if (cppi41_channel->is_tx)
61 return;
62 if (!is_host_active(cppi41_channel->controller->musb))
63 return;
64
65 csr = musb_readw(cppi41_channel->hw_ep->regs, MUSB_RXCSR);
66 toggle = csr & MUSB_RXCSR_H_DATATOGGLE ? 1 : 0;
67
68 cppi41_channel->usb_toggle = toggle;
69}
70
71static void update_rx_toggle(struct cppi41_dma_channel *cppi41_channel)
72{
73 u16 csr;
74 u8 toggle;
75
76 if (cppi41_channel->is_tx)
77 return;
78 if (!is_host_active(cppi41_channel->controller->musb))
79 return;
80
81 csr = musb_readw(cppi41_channel->hw_ep->regs, MUSB_RXCSR);
82 toggle = csr & MUSB_RXCSR_H_DATATOGGLE ? 1 : 0;
83
84 /*
85 * AM335x Advisory 1.0.13: Due to internal synchronisation error the
86 * data toggle may reset from DATA1 to DATA0 during receiving data from
87 * more than one endpoint.
88 */
89 if (!toggle && toggle == cppi41_channel->usb_toggle) {
90 csr |= MUSB_RXCSR_H_DATATOGGLE | MUSB_RXCSR_H_WR_DATATOGGLE;
91 musb_writew(cppi41_channel->hw_ep->regs, MUSB_RXCSR, csr);
92 dev_dbg(cppi41_channel->controller->musb->controller,
93 "Restoring DATA1 toggle.\n");
94 }
95
96 cppi41_channel->usb_toggle = toggle;
97}
98
99static void cppi41_dma_callback(void *private_data)
100{
101 struct dma_channel *channel = private_data;
102 struct cppi41_dma_channel *cppi41_channel = channel->private_data;
103 struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep;
104 struct musb *musb = hw_ep->musb;
105 unsigned long flags;
106 struct dma_tx_state txstate;
107 u32 transferred;
108
109 spin_lock_irqsave(&musb->lock, flags);
110
111 dmaengine_tx_status(cppi41_channel->dc, cppi41_channel->cookie,
112 &txstate);
113 transferred = cppi41_channel->prog_len - txstate.residue;
114 cppi41_channel->transferred += transferred;
115
116 dev_dbg(musb->controller, "DMA transfer done on hw_ep=%d bytes=%d/%d\n",
117 hw_ep->epnum, cppi41_channel->transferred,
118 cppi41_channel->total_len);
119
120 update_rx_toggle(cppi41_channel);
121
122 if (cppi41_channel->transferred == cppi41_channel->total_len ||
123 transferred < cppi41_channel->packet_sz) {
124
125 /* done, complete */
126 cppi41_channel->channel.actual_len =
127 cppi41_channel->transferred;
128 cppi41_channel->channel.status = MUSB_DMA_STATUS_FREE;
129 musb_dma_completion(musb, hw_ep->epnum, cppi41_channel->is_tx);
130 } else {
131 /* next iteration, reload */
132 struct dma_chan *dc = cppi41_channel->dc;
133 struct dma_async_tx_descriptor *dma_desc;
134 enum dma_transfer_direction direction;
135 u16 csr;
136 u32 remain_bytes;
137 void __iomem *epio = cppi41_channel->hw_ep->regs;
138
139 cppi41_channel->buf_addr += cppi41_channel->packet_sz;
140
141 remain_bytes = cppi41_channel->total_len;
142 remain_bytes -= cppi41_channel->transferred;
143 remain_bytes = min(remain_bytes, cppi41_channel->packet_sz);
144 cppi41_channel->prog_len = remain_bytes;
145
146 direction = cppi41_channel->is_tx ? DMA_MEM_TO_DEV
147 : DMA_DEV_TO_MEM;
148 dma_desc = dmaengine_prep_slave_single(dc,
149 cppi41_channel->buf_addr,
150 remain_bytes,
151 direction,
152 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
153 if (WARN_ON(!dma_desc))
154 return;
155
156 dma_desc->callback = cppi41_dma_callback;
157 dma_desc->callback_param = channel;
158 cppi41_channel->cookie = dma_desc->tx_submit(dma_desc);
159 dma_async_issue_pending(dc);
160
161 if (!cppi41_channel->is_tx) {
162 csr = musb_readw(epio, MUSB_RXCSR);
163 csr |= MUSB_RXCSR_H_REQPKT;
164 musb_writew(epio, MUSB_RXCSR, csr);
165 }
166 }
167 spin_unlock_irqrestore(&musb->lock, flags);
168}
169
170static u32 update_ep_mode(unsigned ep, unsigned mode, u32 old)
171{
172 unsigned shift;
173
174 shift = (ep - 1) * 2;
175 old &= ~(3 << shift);
176 old |= mode << shift;
177 return old;
178}
179
180static void cppi41_set_dma_mode(struct cppi41_dma_channel *cppi41_channel,
181 unsigned mode)
182{
183 struct cppi41_dma_controller *controller = cppi41_channel->controller;
184 u32 port;
185 u32 new_mode;
186 u32 old_mode;
187
188 if (cppi41_channel->is_tx)
189 old_mode = controller->tx_mode;
190 else
191 old_mode = controller->rx_mode;
192 port = cppi41_channel->port_num;
193 new_mode = update_ep_mode(port, mode, old_mode);
194
195 if (new_mode == old_mode)
196 return;
197 if (cppi41_channel->is_tx) {
198 controller->tx_mode = new_mode;
199 musb_writel(controller->musb->ctrl_base, USB_CTRL_TX_MODE,
200 new_mode);
201 } else {
202 controller->rx_mode = new_mode;
203 musb_writel(controller->musb->ctrl_base, USB_CTRL_RX_MODE,
204 new_mode);
205 }
206}
207
208static void cppi41_set_autoreq_mode(struct cppi41_dma_channel *cppi41_channel,
209 unsigned mode)
210{
211 struct cppi41_dma_controller *controller = cppi41_channel->controller;
212 u32 port;
213 u32 new_mode;
214 u32 old_mode;
215
216 old_mode = controller->auto_req;
217 port = cppi41_channel->port_num;
218 new_mode = update_ep_mode(port, mode, old_mode);
219
220 if (new_mode == old_mode)
221 return;
222 controller->auto_req = new_mode;
223 musb_writel(controller->musb->ctrl_base, USB_CTRL_AUTOREQ, new_mode);
224}
225
226static bool cppi41_configure_channel(struct dma_channel *channel,
227 u16 packet_sz, u8 mode,
228 dma_addr_t dma_addr, u32 len)
229{
230 struct cppi41_dma_channel *cppi41_channel = channel->private_data;
231 struct dma_chan *dc = cppi41_channel->dc;
232 struct dma_async_tx_descriptor *dma_desc;
233 enum dma_transfer_direction direction;
234 struct musb *musb = cppi41_channel->controller->musb;
235 unsigned use_gen_rndis = 0;
236
237 dev_dbg(musb->controller,
238 "configure ep%d/%x packet_sz=%d, mode=%d, dma_addr=0x%llx, len=%d is_tx=%d\n",
239 cppi41_channel->port_num, RNDIS_REG(cppi41_channel->port_num),
240 packet_sz, mode, (unsigned long long) dma_addr,
241 len, cppi41_channel->is_tx);
242
243 cppi41_channel->buf_addr = dma_addr;
244 cppi41_channel->total_len = len;
245 cppi41_channel->transferred = 0;
246 cppi41_channel->packet_sz = packet_sz;
247
248 /*
249 * Due to AM335x' Advisory 1.0.13 we are not allowed to transfer more
250 * than max packet size at a time.
251 */
252 if (cppi41_channel->is_tx)
253 use_gen_rndis = 1;
254
255 if (use_gen_rndis) {
256 /* RNDIS mode */
257 if (len > packet_sz) {
258 musb_writel(musb->ctrl_base,
259 RNDIS_REG(cppi41_channel->port_num), len);
260 /* gen rndis */
261 cppi41_set_dma_mode(cppi41_channel,
262 EP_MODE_DMA_GEN_RNDIS);
263
264 /* auto req */
265 cppi41_set_autoreq_mode(cppi41_channel,
266 EP_MODE_AUTOREG_ALL_NEOP);
267 } else {
268 musb_writel(musb->ctrl_base,
269 RNDIS_REG(cppi41_channel->port_num), 0);
270 cppi41_set_dma_mode(cppi41_channel,
271 EP_MODE_DMA_TRANSPARENT);
272 cppi41_set_autoreq_mode(cppi41_channel,
273 EP_MODE_AUTOREG_NONE);
274 }
275 } else {
276 /* fallback mode */
277 cppi41_set_dma_mode(cppi41_channel, EP_MODE_DMA_TRANSPARENT);
278 cppi41_set_autoreq_mode(cppi41_channel, EP_MODE_AUTOREG_NONE);
279 len = min_t(u32, packet_sz, len);
280 }
281 cppi41_channel->prog_len = len;
282 direction = cppi41_channel->is_tx ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
283 dma_desc = dmaengine_prep_slave_single(dc, dma_addr, len, direction,
284 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
285 if (!dma_desc)
286 return false;
287
288 dma_desc->callback = cppi41_dma_callback;
289 dma_desc->callback_param = channel;
290 cppi41_channel->cookie = dma_desc->tx_submit(dma_desc);
291
292 save_rx_toggle(cppi41_channel);
293 dma_async_issue_pending(dc);
294 return true;
295}
296
297static struct dma_channel *cppi41_dma_channel_allocate(struct dma_controller *c,
298 struct musb_hw_ep *hw_ep, u8 is_tx)
299{
300 struct cppi41_dma_controller *controller = container_of(c,
301 struct cppi41_dma_controller, controller);
302 struct cppi41_dma_channel *cppi41_channel = NULL;
303 u8 ch_num = hw_ep->epnum - 1;
304
305 if (ch_num >= MUSB_DMA_NUM_CHANNELS)
306 return NULL;
307
308 if (is_tx)
309 cppi41_channel = &controller->tx_channel[ch_num];
310 else
311 cppi41_channel = &controller->rx_channel[ch_num];
312
313 if (!cppi41_channel->dc)
314 return NULL;
315
316 if (cppi41_channel->is_allocated)
317 return NULL;
318
319 cppi41_channel->hw_ep = hw_ep;
320 cppi41_channel->is_allocated = 1;
321
322 return &cppi41_channel->channel;
323}
324
325static void cppi41_dma_channel_release(struct dma_channel *channel)
326{
327 struct cppi41_dma_channel *cppi41_channel = channel->private_data;
328
329 if (cppi41_channel->is_allocated) {
330 cppi41_channel->is_allocated = 0;
331 channel->status = MUSB_DMA_STATUS_FREE;
332 channel->actual_len = 0;
333 }
334}
335
336static int cppi41_dma_channel_program(struct dma_channel *channel,
337 u16 packet_sz, u8 mode,
338 dma_addr_t dma_addr, u32 len)
339{
340 int ret;
341
342 BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN ||
343 channel->status == MUSB_DMA_STATUS_BUSY);
344
345 channel->status = MUSB_DMA_STATUS_BUSY;
346 channel->actual_len = 0;
347 ret = cppi41_configure_channel(channel, packet_sz, mode, dma_addr, len);
348 if (!ret)
349 channel->status = MUSB_DMA_STATUS_FREE;
350
351 return ret;
352}
353
354static int cppi41_is_compatible(struct dma_channel *channel, u16 maxpacket,
355 void *buf, u32 length)
356{
357 struct cppi41_dma_channel *cppi41_channel = channel->private_data;
358 struct cppi41_dma_controller *controller = cppi41_channel->controller;
359 struct musb *musb = controller->musb;
360
361 if (is_host_active(musb)) {
362 WARN_ON(1);
363 return 1;
364 }
365 if (cppi41_channel->is_tx)
366 return 1;
367 /* AM335x Advisory 1.0.13. No workaround for device RX mode */
368 return 0;
369}
370
371static int cppi41_dma_channel_abort(struct dma_channel *channel)
372{
373 struct cppi41_dma_channel *cppi41_channel = channel->private_data;
374 struct cppi41_dma_controller *controller = cppi41_channel->controller;
375 struct musb *musb = controller->musb;
376 void __iomem *epio = cppi41_channel->hw_ep->regs;
377 int tdbit;
378 int ret;
379 unsigned is_tx;
380 u16 csr;
381
382 is_tx = cppi41_channel->is_tx;
383 dev_dbg(musb->controller, "abort channel=%d, is_tx=%d\n",
384 cppi41_channel->port_num, is_tx);
385
386 if (cppi41_channel->channel.status == MUSB_DMA_STATUS_FREE)
387 return 0;
388
389 if (is_tx) {
390 csr = musb_readw(epio, MUSB_TXCSR);
391 csr &= ~MUSB_TXCSR_DMAENAB;
392 musb_writew(epio, MUSB_TXCSR, csr);
393 } else {
394 csr = musb_readw(epio, MUSB_RXCSR);
395 csr &= ~(MUSB_RXCSR_H_REQPKT | MUSB_RXCSR_DMAENAB);
396 musb_writew(epio, MUSB_RXCSR, csr);
397
398 csr = musb_readw(epio, MUSB_RXCSR);
399 if (csr & MUSB_RXCSR_RXPKTRDY) {
400 csr |= MUSB_RXCSR_FLUSHFIFO;
401 musb_writew(epio, MUSB_RXCSR, csr);
402 musb_writew(epio, MUSB_RXCSR, csr);
403 }
404 }
405
406 tdbit = 1 << cppi41_channel->port_num;
407 if (is_tx)
408 tdbit <<= 16;
409
410 do {
411 musb_writel(musb->ctrl_base, USB_TDOWN, tdbit);
412 ret = dmaengine_terminate_all(cppi41_channel->dc);
413 } while (ret == -EAGAIN);
414
415 musb_writel(musb->ctrl_base, USB_TDOWN, tdbit);
416
417 if (is_tx) {
418 csr = musb_readw(epio, MUSB_TXCSR);
419 if (csr & MUSB_TXCSR_TXPKTRDY) {
420 csr |= MUSB_TXCSR_FLUSHFIFO;
421 musb_writew(epio, MUSB_TXCSR, csr);
422 }
423 }
424
425 cppi41_channel->channel.status = MUSB_DMA_STATUS_FREE;
426 return 0;
427}
428
429static void cppi41_release_all_dma_chans(struct cppi41_dma_controller *ctrl)
430{
431 struct dma_chan *dc;
432 int i;
433
434 for (i = 0; i < MUSB_DMA_NUM_CHANNELS; i++) {
435 dc = ctrl->tx_channel[i].dc;
436 if (dc)
437 dma_release_channel(dc);
438 dc = ctrl->rx_channel[i].dc;
439 if (dc)
440 dma_release_channel(dc);
441 }
442}
443
444static void cppi41_dma_controller_stop(struct cppi41_dma_controller *controller)
445{
446 cppi41_release_all_dma_chans(controller);
447}
448
449static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller)
450{
451 struct musb *musb = controller->musb;
452 struct device *dev = musb->controller;
453 struct device_node *np = dev->of_node;
454 struct cppi41_dma_channel *cppi41_channel;
455 int count;
456 int i;
457 int ret;
458
459 count = of_property_count_strings(np, "dma-names");
460 if (count < 0)
461 return count;
462
463 for (i = 0; i < count; i++) {
464 struct dma_chan *dc;
465 struct dma_channel *musb_dma;
466 const char *str;
467 unsigned is_tx;
468 unsigned int port;
469
470 ret = of_property_read_string_index(np, "dma-names", i, &str);
471 if (ret)
472 goto err;
473 if (!strncmp(str, "tx", 2))
474 is_tx = 1;
475 else if (!strncmp(str, "rx", 2))
476 is_tx = 0;
477 else {
478 dev_err(dev, "Wrong dmatype %s\n", str);
479 goto err;
480 }
481 ret = kstrtouint(str + 2, 0, &port);
482 if (ret)
483 goto err;
484
485 if (port > MUSB_DMA_NUM_CHANNELS || !port)
486 goto err;
487 if (is_tx)
488 cppi41_channel = &controller->tx_channel[port - 1];
489 else
490 cppi41_channel = &controller->rx_channel[port - 1];
491
492 cppi41_channel->controller = controller;
493 cppi41_channel->port_num = port;
494 cppi41_channel->is_tx = is_tx;
495
496 musb_dma = &cppi41_channel->channel;
497 musb_dma->private_data = cppi41_channel;
498 musb_dma->status = MUSB_DMA_STATUS_FREE;
499 musb_dma->max_len = SZ_4M;
500
501 dc = dma_request_slave_channel(dev, str);
502 if (!dc) {
503 dev_err(dev, "Falied to request %s.\n", str);
504 goto err;
505 }
506 cppi41_channel->dc = dc;
507 }
508 return 0;
509err:
510 cppi41_release_all_dma_chans(controller);
511 return -EINVAL;
512}
513
514void dma_controller_destroy(struct dma_controller *c)
515{
516 struct cppi41_dma_controller *controller = container_of(c,
517 struct cppi41_dma_controller, controller);
518
519 cppi41_dma_controller_stop(controller);
520 kfree(controller);
521}
522
523struct dma_controller *dma_controller_create(struct musb *musb,
524 void __iomem *base)
525{
526 struct cppi41_dma_controller *controller;
527 int ret;
528
529 if (!musb->controller->of_node) {
530 dev_err(musb->controller, "Need DT for the DMA engine.\n");
531 return NULL;
532 }
533
534 controller = kzalloc(sizeof(*controller), GFP_KERNEL);
535 if (!controller)
536 goto kzalloc_fail;
537
538 controller->musb = musb;
539
540 controller->controller.channel_alloc = cppi41_dma_channel_allocate;
541 controller->controller.channel_release = cppi41_dma_channel_release;
542 controller->controller.channel_program = cppi41_dma_channel_program;
543 controller->controller.channel_abort = cppi41_dma_channel_abort;
544 controller->controller.is_compatible = cppi41_is_compatible;
545
546 ret = cppi41_dma_controller_start(controller);
547 if (ret)
548 goto plat_get_fail;
549 return &controller->controller;
550
551plat_get_fail:
552 kfree(controller);
553kzalloc_fail:
554 return NULL;
555}
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 1b6b827b769f..1345a4ff041a 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -62,13 +62,13 @@ struct musb_hw_ep;
62 62
63#define DMA_ADDR_INVALID (~(dma_addr_t)0) 63#define DMA_ADDR_INVALID (~(dma_addr_t)0)
64 64
65#ifndef CONFIG_MUSB_PIO_ONLY 65#ifdef CONFIG_MUSB_PIO_ONLY
66#define is_dma_capable() (1)
67#else
68#define is_dma_capable() (0) 66#define is_dma_capable() (0)
67#else
68#define is_dma_capable() (1)
69#endif 69#endif
70 70
71#ifdef CONFIG_USB_TI_CPPI_DMA 71#if defined(CONFIG_USB_TI_CPPI_DMA) || defined(CONFIG_USB_TI_CPPI41_DMA)
72#define is_cppi_enabled() 1 72#define is_cppi_enabled() 1
73#else 73#else
74#define is_cppi_enabled() 0 74#define is_cppi_enabled() 0
@@ -159,8 +159,6 @@ dma_channel_status(struct dma_channel *c)
159 * Controllers manage dma channels. 159 * Controllers manage dma channels.
160 */ 160 */
161struct dma_controller { 161struct dma_controller {
162 int (*start)(struct dma_controller *);
163 int (*stop)(struct dma_controller *);
164 struct dma_channel *(*channel_alloc)(struct dma_controller *, 162 struct dma_channel *(*channel_alloc)(struct dma_controller *,
165 struct musb_hw_ep *, u8 is_tx); 163 struct musb_hw_ep *, u8 is_tx);
166 void (*channel_release)(struct dma_channel *); 164 void (*channel_release)(struct dma_channel *);
@@ -177,9 +175,20 @@ struct dma_controller {
177/* called after channel_program(), may indicate a fault */ 175/* called after channel_program(), may indicate a fault */
178extern void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit); 176extern void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit);
179 177
178#ifdef CONFIG_MUSB_PIO_ONLY
179static inline struct dma_controller *dma_controller_create(struct musb *m,
180 void __iomem *io)
181{
182 return NULL;
183}
184
185static inline void dma_controller_destroy(struct dma_controller *d) { }
186
187#else
180 188
181extern struct dma_controller *dma_controller_create(struct musb *, void __iomem *); 189extern struct dma_controller *dma_controller_create(struct musb *, void __iomem *);
182 190
183extern void dma_controller_destroy(struct dma_controller *); 191extern void dma_controller_destroy(struct dma_controller *);
192#endif
184 193
185#endif /* __MUSB_DMA_H__ */ 194#endif /* __MUSB_DMA_H__ */
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 5233804d66b1..4ffbaace7913 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -36,19 +36,18 @@
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/pm_runtime.h> 37#include <linux/pm_runtime.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/usb/nop-usb-xceiv.h> 39#include <linux/usb/usb_phy_gen_xceiv.h>
40#include <linux/platform_data/usb-omap.h> 40#include <linux/platform_data/usb-omap.h>
41#include <linux/sizes.h> 41#include <linux/sizes.h>
42 42
43#include <linux/of.h> 43#include <linux/of.h>
44#include <linux/of_device.h> 44#include <linux/of_device.h>
45#include <linux/of_address.h> 45#include <linux/of_address.h>
46#include <linux/of_irq.h>
46 47
47#include "musb_core.h" 48#include "musb_core.h"
48 49
49#ifdef CONFIG_OF
50static const struct of_device_id musb_dsps_of_match[]; 50static const struct of_device_id musb_dsps_of_match[];
51#endif
52 51
53/** 52/**
54 * avoid using musb_readx()/musb_writex() as glue layer should not be 53 * avoid using musb_readx()/musb_writex() as glue layer should not be
@@ -75,7 +74,6 @@ struct dsps_musb_wrapper {
75 u16 revision; 74 u16 revision;
76 u16 control; 75 u16 control;
77 u16 status; 76 u16 status;
78 u16 eoi;
79 u16 epintr_set; 77 u16 epintr_set;
80 u16 epintr_clear; 78 u16 epintr_clear;
81 u16 epintr_status; 79 u16 epintr_status;
@@ -108,10 +106,7 @@ struct dsps_musb_wrapper {
108 /* bit positions for mode */ 106 /* bit positions for mode */
109 unsigned iddig:5; 107 unsigned iddig:5;
110 /* miscellaneous stuff */ 108 /* miscellaneous stuff */
111 u32 musb_core_offset;
112 u8 poll_seconds; 109 u8 poll_seconds;
113 /* number of musb instances */
114 u8 instances;
115}; 110};
116 111
117/** 112/**
@@ -119,53 +114,12 @@ struct dsps_musb_wrapper {
119 */ 114 */
120struct dsps_glue { 115struct dsps_glue {
121 struct device *dev; 116 struct device *dev;
122 struct platform_device *musb[2]; /* child musb pdev */ 117 struct platform_device *musb; /* child musb pdev */
123 const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */ 118 const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */
124 struct timer_list timer[2]; /* otg_workaround timer */ 119 struct timer_list timer; /* otg_workaround timer */
125 unsigned long last_timer[2]; /* last timer data for each instance */ 120 unsigned long last_timer; /* last timer data for each instance */
126 u32 __iomem *usb_ctrl[2];
127}; 121};
128 122
129#define DSPS_AM33XX_CONTROL_MODULE_PHYS_0 0x44e10620
130#define DSPS_AM33XX_CONTROL_MODULE_PHYS_1 0x44e10628
131
132static const resource_size_t dsps_control_module_phys[] = {
133 DSPS_AM33XX_CONTROL_MODULE_PHYS_0,
134 DSPS_AM33XX_CONTROL_MODULE_PHYS_1,
135};
136
137#define USBPHY_CM_PWRDN (1 << 0)
138#define USBPHY_OTG_PWRDN (1 << 1)
139#define USBPHY_OTGVDET_EN (1 << 19)
140#define USBPHY_OTGSESSEND_EN (1 << 20)
141
142/**
143 * musb_dsps_phy_control - phy on/off
144 * @glue: struct dsps_glue *
145 * @id: musb instance
146 * @on: flag for phy to be switched on or off
147 *
148 * This is to enable the PHY using usb_ctrl register in system control
149 * module space.
150 *
151 * XXX: This function will be removed once we have a seperate driver for
152 * control module
153 */
154static void musb_dsps_phy_control(struct dsps_glue *glue, u8 id, u8 on)
155{
156 u32 usbphycfg;
157
158 usbphycfg = readl(glue->usb_ctrl[id]);
159
160 if (on) {
161 usbphycfg &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN);
162 usbphycfg |= USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN;
163 } else {
164 usbphycfg |= USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN;
165 }
166
167 writel(usbphycfg, glue->usb_ctrl[id]);
168}
169/** 123/**
170 * dsps_musb_enable - enable interrupts 124 * dsps_musb_enable - enable interrupts
171 */ 125 */
@@ -205,7 +159,6 @@ static void dsps_musb_disable(struct musb *musb)
205 dsps_writel(reg_base, wrp->epintr_clear, 159 dsps_writel(reg_base, wrp->epintr_clear,
206 wrp->txep_bitmap | wrp->rxep_bitmap); 160 wrp->txep_bitmap | wrp->rxep_bitmap);
207 dsps_writeb(musb->mregs, MUSB_DEVCTL, 0); 161 dsps_writeb(musb->mregs, MUSB_DEVCTL, 0);
208 dsps_writel(reg_base, wrp->eoi, 0);
209} 162}
210 163
211static void otg_timer(unsigned long _musb) 164static void otg_timer(unsigned long _musb)
@@ -213,7 +166,6 @@ static void otg_timer(unsigned long _musb)
213 struct musb *musb = (void *)_musb; 166 struct musb *musb = (void *)_musb;
214 void __iomem *mregs = musb->mregs; 167 void __iomem *mregs = musb->mregs;
215 struct device *dev = musb->controller; 168 struct device *dev = musb->controller;
216 struct platform_device *pdev = to_platform_device(dev);
217 struct dsps_glue *glue = dev_get_drvdata(dev->parent); 169 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
218 const struct dsps_musb_wrapper *wrp = glue->wrp; 170 const struct dsps_musb_wrapper *wrp = glue->wrp;
219 u8 devctl; 171 u8 devctl;
@@ -250,7 +202,7 @@ static void otg_timer(unsigned long _musb)
250 case OTG_STATE_B_IDLE: 202 case OTG_STATE_B_IDLE:
251 devctl = dsps_readb(mregs, MUSB_DEVCTL); 203 devctl = dsps_readb(mregs, MUSB_DEVCTL);
252 if (devctl & MUSB_DEVCTL_BDEVICE) 204 if (devctl & MUSB_DEVCTL_BDEVICE)
253 mod_timer(&glue->timer[pdev->id], 205 mod_timer(&glue->timer,
254 jiffies + wrp->poll_seconds * HZ); 206 jiffies + wrp->poll_seconds * HZ);
255 else 207 else
256 musb->xceiv->state = OTG_STATE_A_IDLE; 208 musb->xceiv->state = OTG_STATE_A_IDLE;
@@ -264,7 +216,6 @@ static void otg_timer(unsigned long _musb)
264static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) 216static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
265{ 217{
266 struct device *dev = musb->controller; 218 struct device *dev = musb->controller;
267 struct platform_device *pdev = to_platform_device(dev);
268 struct dsps_glue *glue = dev_get_drvdata(dev->parent); 219 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
269 220
270 if (timeout == 0) 221 if (timeout == 0)
@@ -275,23 +226,23 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
275 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 226 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
276 dev_dbg(musb->controller, "%s active, deleting timer\n", 227 dev_dbg(musb->controller, "%s active, deleting timer\n",
277 usb_otg_state_string(musb->xceiv->state)); 228 usb_otg_state_string(musb->xceiv->state));
278 del_timer(&glue->timer[pdev->id]); 229 del_timer(&glue->timer);
279 glue->last_timer[pdev->id] = jiffies; 230 glue->last_timer = jiffies;
280 return; 231 return;
281 } 232 }
282 233
283 if (time_after(glue->last_timer[pdev->id], timeout) && 234 if (time_after(glue->last_timer, timeout) &&
284 timer_pending(&glue->timer[pdev->id])) { 235 timer_pending(&glue->timer)) {
285 dev_dbg(musb->controller, 236 dev_dbg(musb->controller,
286 "Longer idle timer already pending, ignoring...\n"); 237 "Longer idle timer already pending, ignoring...\n");
287 return; 238 return;
288 } 239 }
289 glue->last_timer[pdev->id] = timeout; 240 glue->last_timer = timeout;
290 241
291 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 242 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
292 usb_otg_state_string(musb->xceiv->state), 243 usb_otg_state_string(musb->xceiv->state),
293 jiffies_to_msecs(timeout - jiffies)); 244 jiffies_to_msecs(timeout - jiffies));
294 mod_timer(&glue->timer[pdev->id], timeout); 245 mod_timer(&glue->timer, timeout);
295} 246}
296 247
297static irqreturn_t dsps_interrupt(int irq, void *hci) 248static irqreturn_t dsps_interrupt(int irq, void *hci)
@@ -299,7 +250,6 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
299 struct musb *musb = hci; 250 struct musb *musb = hci;
300 void __iomem *reg_base = musb->ctrl_base; 251 void __iomem *reg_base = musb->ctrl_base;
301 struct device *dev = musb->controller; 252 struct device *dev = musb->controller;
302 struct platform_device *pdev = to_platform_device(dev);
303 struct dsps_glue *glue = dev_get_drvdata(dev->parent); 253 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
304 const struct dsps_musb_wrapper *wrp = glue->wrp; 254 const struct dsps_musb_wrapper *wrp = glue->wrp;
305 unsigned long flags; 255 unsigned long flags;
@@ -319,7 +269,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
319 /* Get usb core interrupts */ 269 /* Get usb core interrupts */
320 usbintr = dsps_readl(reg_base, wrp->coreintr_status); 270 usbintr = dsps_readl(reg_base, wrp->coreintr_status);
321 if (!usbintr && !epintr) 271 if (!usbintr && !epintr)
322 goto eoi; 272 goto out;
323 273
324 musb->int_usb = (usbintr & wrp->usb_bitmap) >> wrp->usb_shift; 274 musb->int_usb = (usbintr & wrp->usb_bitmap) >> wrp->usb_shift;
325 if (usbintr) 275 if (usbintr)
@@ -359,7 +309,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
359 */ 309 */
360 musb->int_usb &= ~MUSB_INTR_VBUSERROR; 310 musb->int_usb &= ~MUSB_INTR_VBUSERROR;
361 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 311 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
362 mod_timer(&glue->timer[pdev->id], 312 mod_timer(&glue->timer,
363 jiffies + wrp->poll_seconds * HZ); 313 jiffies + wrp->poll_seconds * HZ);
364 WARNING("VBUS error workaround (delay coming)\n"); 314 WARNING("VBUS error workaround (delay coming)\n");
365 } else if (drvvbus) { 315 } else if (drvvbus) {
@@ -367,7 +317,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
367 MUSB_HST_MODE(musb); 317 MUSB_HST_MODE(musb);
368 musb->xceiv->otg->default_a = 1; 318 musb->xceiv->otg->default_a = 1;
369 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 319 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
370 del_timer(&glue->timer[pdev->id]); 320 del_timer(&glue->timer);
371 } else { 321 } else {
372 musb->is_active = 0; 322 musb->is_active = 0;
373 MUSB_DEV_MODE(musb); 323 MUSB_DEV_MODE(musb);
@@ -387,16 +337,10 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
387 if (musb->int_tx || musb->int_rx || musb->int_usb) 337 if (musb->int_tx || musb->int_rx || musb->int_usb)
388 ret |= musb_interrupt(musb); 338 ret |= musb_interrupt(musb);
389 339
390 eoi:
391 /* EOI needs to be written for the IRQ to be re-asserted. */
392 if (ret == IRQ_HANDLED || epintr || usbintr)
393 dsps_writel(reg_base, wrp->eoi, 1);
394
395 /* Poll for ID change */ 340 /* Poll for ID change */
396 if (musb->xceiv->state == OTG_STATE_B_IDLE) 341 if (musb->xceiv->state == OTG_STATE_B_IDLE)
397 mod_timer(&glue->timer[pdev->id], 342 mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ);
398 jiffies + wrp->poll_seconds * HZ); 343out:
399
400 spin_unlock_irqrestore(&musb->lock, flags); 344 spin_unlock_irqrestore(&musb->lock, flags);
401 345
402 return ret; 346 return ret;
@@ -405,37 +349,38 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
405static int dsps_musb_init(struct musb *musb) 349static int dsps_musb_init(struct musb *musb)
406{ 350{
407 struct device *dev = musb->controller; 351 struct device *dev = musb->controller;
408 struct platform_device *pdev = to_platform_device(dev);
409 struct dsps_glue *glue = dev_get_drvdata(dev->parent); 352 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
353 struct platform_device *parent = to_platform_device(dev->parent);
410 const struct dsps_musb_wrapper *wrp = glue->wrp; 354 const struct dsps_musb_wrapper *wrp = glue->wrp;
411 void __iomem *reg_base = musb->ctrl_base; 355 void __iomem *reg_base;
356 struct resource *r;
412 u32 rev, val; 357 u32 rev, val;
413 int status;
414 358
415 /* mentor core register starts at offset of 0x400 from musb base */ 359 r = platform_get_resource_byname(parent, IORESOURCE_MEM, "control");
416 musb->mregs += wrp->musb_core_offset; 360 if (!r)
361 return -EINVAL;
362
363 reg_base = devm_ioremap_resource(dev, r);
364 if (!musb->ctrl_base)
365 return -EINVAL;
366 musb->ctrl_base = reg_base;
417 367
418 /* NOP driver needs change if supporting dual instance */ 368 /* NOP driver needs change if supporting dual instance */
419 usb_nop_xceiv_register(); 369 musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0);
420 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 370 if (IS_ERR(musb->xceiv))
421 if (IS_ERR_OR_NULL(musb->xceiv)) 371 return PTR_ERR(musb->xceiv);
422 return -EPROBE_DEFER;
423 372
424 /* Returns zero if e.g. not clocked */ 373 /* Returns zero if e.g. not clocked */
425 rev = dsps_readl(reg_base, wrp->revision); 374 rev = dsps_readl(reg_base, wrp->revision);
426 if (!rev) { 375 if (!rev)
427 status = -ENODEV; 376 return -ENODEV;
428 goto err0;
429 }
430 377
431 setup_timer(&glue->timer[pdev->id], otg_timer, (unsigned long) musb); 378 usb_phy_init(musb->xceiv);
379 setup_timer(&glue->timer, otg_timer, (unsigned long) musb);
432 380
433 /* Reset the musb */ 381 /* Reset the musb */
434 dsps_writel(reg_base, wrp->control, (1 << wrp->reset)); 382 dsps_writel(reg_base, wrp->control, (1 << wrp->reset));
435 383
436 /* Start the on-chip PHY and its PLL. */
437 musb_dsps_phy_control(glue, pdev->id, 1);
438
439 musb->isr = dsps_interrupt; 384 musb->isr = dsps_interrupt;
440 385
441 /* reset the otgdisable bit, needed for host mode to work */ 386 /* reset the otgdisable bit, needed for host mode to work */
@@ -443,31 +388,17 @@ static int dsps_musb_init(struct musb *musb)
443 val &= ~(1 << wrp->otg_disable); 388 val &= ~(1 << wrp->otg_disable);
444 dsps_writel(musb->ctrl_base, wrp->phy_utmi, val); 389 dsps_writel(musb->ctrl_base, wrp->phy_utmi, val);
445 390
446 /* clear level interrupt */
447 dsps_writel(reg_base, wrp->eoi, 0);
448
449 return 0; 391 return 0;
450err0:
451 usb_put_phy(musb->xceiv);
452 usb_nop_xceiv_unregister();
453 return status;
454} 392}
455 393
456static int dsps_musb_exit(struct musb *musb) 394static int dsps_musb_exit(struct musb *musb)
457{ 395{
458 struct device *dev = musb->controller; 396 struct device *dev = musb->controller;
459 struct platform_device *pdev = to_platform_device(dev);
460 struct dsps_glue *glue = dev_get_drvdata(dev->parent); 397 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
461 398
462 del_timer_sync(&glue->timer[pdev->id]); 399 del_timer_sync(&glue->timer);
463
464 /* Shutdown the on-chip PHY and its PLL. */
465 musb_dsps_phy_control(glue, pdev->id, 0);
466
467 /* NOP driver needs change if supporting dual instance */
468 usb_put_phy(musb->xceiv);
469 usb_nop_xceiv_unregister();
470 400
401 usb_phy_shutdown(musb->xceiv);
471 return 0; 402 return 0;
472} 403}
473 404
@@ -483,116 +414,98 @@ static struct musb_platform_ops dsps_ops = {
483 414
484static u64 musb_dmamask = DMA_BIT_MASK(32); 415static u64 musb_dmamask = DMA_BIT_MASK(32);
485 416
486static int dsps_create_musb_pdev(struct dsps_glue *glue, u8 id) 417static int get_int_prop(struct device_node *dn, const char *s)
487{ 418{
488 struct device *dev = glue->dev; 419 int ret;
489 struct platform_device *pdev = to_platform_device(dev); 420 u32 val;
490 struct musb_hdrc_platform_data *pdata = dev->platform_data; 421
491 struct device_node *np = pdev->dev.of_node; 422 ret = of_property_read_u32(dn, s, &val);
492 struct musb_hdrc_config *config; 423 if (ret)
493 struct platform_device *musb; 424 return 0;
494 struct resource *res; 425 return val;
426}
427
428static int dsps_create_musb_pdev(struct dsps_glue *glue,
429 struct platform_device *parent)
430{
431 struct musb_hdrc_platform_data pdata;
495 struct resource resources[2]; 432 struct resource resources[2];
496 char res_name[11]; 433 struct device *dev = &parent->dev;
434 struct musb_hdrc_config *config;
435 struct platform_device *musb;
436 struct device_node *dn = parent->dev.of_node;
437 struct device_node *child_node;
497 int ret; 438 int ret;
498 439
499 resources[0].start = dsps_control_module_phys[id]; 440 child_node = of_get_child_by_name(dn, "usb");
500 resources[0].end = resources[0].start + SZ_4 - 1; 441 if (!child_node)
501 resources[0].flags = IORESOURCE_MEM; 442 return -EINVAL;
502 443
503 glue->usb_ctrl[id] = devm_ioremap_resource(&pdev->dev, resources); 444 memset(resources, 0, sizeof(resources));
504 if (IS_ERR(glue->usb_ctrl[id])) { 445 ret = of_address_to_resource(child_node, 0, &resources[0]);
505 ret = PTR_ERR(glue->usb_ctrl[id]); 446 if (ret) {
506 goto err0; 447 dev_err(dev, "failed to get memory.\n");
448 return ret;
507 } 449 }
508 450
509 /* first resource is for usbss, so start index from 1 */ 451 ret = of_irq_to_resource(child_node, 0, &resources[1]);
510 res = platform_get_resource(pdev, IORESOURCE_MEM, id + 1); 452 if (ret == 0) {
511 if (!res) { 453 dev_err(dev, "failed to get irq.\n");
512 dev_err(dev, "failed to get memory for instance %d\n", id); 454 ret = -EINVAL;
513 ret = -ENODEV; 455 return ret;
514 goto err0;
515 }
516 res->parent = NULL;
517 resources[0] = *res;
518
519 /* first resource is for usbss, so start index from 1 */
520 res = platform_get_resource(pdev, IORESOURCE_IRQ, id + 1);
521 if (!res) {
522 dev_err(dev, "failed to get irq for instance %d\n", id);
523 ret = -ENODEV;
524 goto err0;
525 } 456 }
526 res->parent = NULL;
527 resources[1] = *res;
528 resources[1].name = "mc";
529 457
530 /* allocate the child platform device */ 458 /* allocate the child platform device */
531 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 459 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
532 if (!musb) { 460 if (!musb) {
533 dev_err(dev, "failed to allocate musb device\n"); 461 dev_err(dev, "failed to allocate musb device\n");
534 ret = -ENOMEM; 462 return -ENOMEM;
535 goto err0;
536 } 463 }
537 464
538 musb->dev.parent = dev; 465 musb->dev.parent = dev;
539 musb->dev.dma_mask = &musb_dmamask; 466 musb->dev.dma_mask = &musb_dmamask;
540 musb->dev.coherent_dma_mask = musb_dmamask; 467 musb->dev.coherent_dma_mask = musb_dmamask;
468 musb->dev.of_node = of_node_get(child_node);
541 469
542 glue->musb[id] = musb; 470 glue->musb = musb;
543 471
544 ret = platform_device_add_resources(musb, resources, 2); 472 ret = platform_device_add_resources(musb, resources,
473 ARRAY_SIZE(resources));
545 if (ret) { 474 if (ret) {
546 dev_err(dev, "failed to add resources\n"); 475 dev_err(dev, "failed to add resources\n");
547 goto err2; 476 goto err;
548 } 477 }
549 478
550 if (np) { 479 config = devm_kzalloc(&parent->dev, sizeof(*config), GFP_KERNEL);
551 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 480 if (!config) {
552 if (!pdata) { 481 dev_err(dev, "failed to allocate musb hdrc config\n");
553 dev_err(&pdev->dev, 482 ret = -ENOMEM;
554 "failed to allocate musb platform data\n"); 483 goto err;
555 ret = -ENOMEM;
556 goto err2;
557 }
558
559 config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
560 if (!config) {
561 dev_err(&pdev->dev,
562 "failed to allocate musb hdrc config\n");
563 ret = -ENOMEM;
564 goto err2;
565 }
566
567 of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps);
568 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
569 snprintf(res_name, sizeof(res_name), "port%d-mode", id);
570 of_property_read_u32(np, res_name, (u32 *)&pdata->mode);
571 of_property_read_u32(np, "power", (u32 *)&pdata->power);
572 config->multipoint = of_property_read_bool(np, "multipoint");
573
574 pdata->config = config;
575 } 484 }
485 pdata.config = config;
486 pdata.platform_ops = &dsps_ops;
576 487
577 pdata->platform_ops = &dsps_ops; 488 config->num_eps = get_int_prop(child_node, "num-eps");
489 config->ram_bits = get_int_prop(child_node, "ram-bits");
490 pdata.mode = get_int_prop(child_node, "port-mode");
491 pdata.power = get_int_prop(child_node, "power");
492 config->multipoint = of_property_read_bool(child_node, "multipoint");
578 493
579 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 494 ret = platform_device_add_data(musb, &pdata, sizeof(pdata));
580 if (ret) { 495 if (ret) {
581 dev_err(dev, "failed to add platform_data\n"); 496 dev_err(dev, "failed to add platform_data\n");
582 goto err2; 497 goto err;
583 } 498 }
584 499
585 ret = platform_device_add(musb); 500 ret = platform_device_add(musb);
586 if (ret) { 501 if (ret) {
587 dev_err(dev, "failed to register musb device\n"); 502 dev_err(dev, "failed to register musb device\n");
588 goto err2; 503 goto err;
589 } 504 }
590
591 return 0; 505 return 0;
592 506
593err2: 507err:
594 platform_device_put(musb); 508 platform_device_put(musb);
595err0:
596 return ret; 509 return ret;
597} 510}
598 511
@@ -601,14 +514,12 @@ static int dsps_probe(struct platform_device *pdev)
601 const struct of_device_id *match; 514 const struct of_device_id *match;
602 const struct dsps_musb_wrapper *wrp; 515 const struct dsps_musb_wrapper *wrp;
603 struct dsps_glue *glue; 516 struct dsps_glue *glue;
604 struct resource *iomem; 517 int ret;
605 int ret, i;
606 518
607 match = of_match_node(musb_dsps_of_match, pdev->dev.of_node); 519 match = of_match_node(musb_dsps_of_match, pdev->dev.of_node);
608 if (!match) { 520 if (!match) {
609 dev_err(&pdev->dev, "fail to get matching of_match struct\n"); 521 dev_err(&pdev->dev, "fail to get matching of_match struct\n");
610 ret = -EINVAL; 522 return -EINVAL;
611 goto err0;
612 } 523 }
613 wrp = match->data; 524 wrp = match->data;
614 525
@@ -616,29 +527,13 @@ static int dsps_probe(struct platform_device *pdev)
616 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 527 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
617 if (!glue) { 528 if (!glue) {
618 dev_err(&pdev->dev, "unable to allocate glue memory\n"); 529 dev_err(&pdev->dev, "unable to allocate glue memory\n");
619 ret = -ENOMEM; 530 return -ENOMEM;
620 goto err0;
621 }
622
623 /* get memory resource */
624 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
625 if (!iomem) {
626 dev_err(&pdev->dev, "failed to get usbss mem resourse\n");
627 ret = -ENODEV;
628 goto err1;
629 } 531 }
630 532
631 glue->dev = &pdev->dev; 533 glue->dev = &pdev->dev;
534 glue->wrp = wrp;
632 535
633 glue->wrp = kmemdup(wrp, sizeof(*wrp), GFP_KERNEL);
634 if (!glue->wrp) {
635 dev_err(&pdev->dev, "failed to duplicate wrapper struct memory\n");
636 ret = -ENOMEM;
637 goto err1;
638 }
639 platform_set_drvdata(pdev, glue); 536 platform_set_drvdata(pdev, glue);
640
641 /* enable the usbss clocks */
642 pm_runtime_enable(&pdev->dev); 537 pm_runtime_enable(&pdev->dev);
643 538
644 ret = pm_runtime_get_sync(&pdev->dev); 539 ret = pm_runtime_get_sync(&pdev->dev);
@@ -647,17 +542,9 @@ static int dsps_probe(struct platform_device *pdev)
647 goto err2; 542 goto err2;
648 } 543 }
649 544
650 /* create the child platform device for all instances of musb */ 545 ret = dsps_create_musb_pdev(glue, pdev);
651 for (i = 0; i < wrp->instances ; i++) { 546 if (ret)
652 ret = dsps_create_musb_pdev(glue, i); 547 goto err3;
653 if (ret != 0) {
654 dev_err(&pdev->dev, "failed to create child pdev\n");
655 /* release resources of previously created instances */
656 for (i--; i >= 0 ; i--)
657 platform_device_unregister(glue->musb[i]);
658 goto err3;
659 }
660 }
661 548
662 return 0; 549 return 0;
663 550
@@ -665,65 +552,27 @@ err3:
665 pm_runtime_put(&pdev->dev); 552 pm_runtime_put(&pdev->dev);
666err2: 553err2:
667 pm_runtime_disable(&pdev->dev); 554 pm_runtime_disable(&pdev->dev);
668 kfree(glue->wrp);
669err1:
670 kfree(glue); 555 kfree(glue);
671err0:
672 return ret; 556 return ret;
673} 557}
558
674static int dsps_remove(struct platform_device *pdev) 559static int dsps_remove(struct platform_device *pdev)
675{ 560{
676 struct dsps_glue *glue = platform_get_drvdata(pdev); 561 struct dsps_glue *glue = platform_get_drvdata(pdev);
677 const struct dsps_musb_wrapper *wrp = glue->wrp;
678 int i;
679 562
680 /* delete the child platform device */ 563 platform_device_unregister(glue->musb);
681 for (i = 0; i < wrp->instances ; i++)
682 platform_device_unregister(glue->musb[i]);
683 564
684 /* disable usbss clocks */ 565 /* disable usbss clocks */
685 pm_runtime_put(&pdev->dev); 566 pm_runtime_put(&pdev->dev);
686 pm_runtime_disable(&pdev->dev); 567 pm_runtime_disable(&pdev->dev);
687 kfree(glue->wrp);
688 kfree(glue); 568 kfree(glue);
689 return 0; 569 return 0;
690} 570}
691 571
692#ifdef CONFIG_PM_SLEEP 572static const struct dsps_musb_wrapper am33xx_driver_data = {
693static int dsps_suspend(struct device *dev)
694{
695 struct platform_device *pdev = to_platform_device(dev->parent);
696 struct dsps_glue *glue = platform_get_drvdata(pdev);
697 const struct dsps_musb_wrapper *wrp = glue->wrp;
698 int i;
699
700 for (i = 0; i < wrp->instances; i++)
701 musb_dsps_phy_control(glue, i, 0);
702
703 return 0;
704}
705
706static int dsps_resume(struct device *dev)
707{
708 struct platform_device *pdev = to_platform_device(dev->parent);
709 struct dsps_glue *glue = platform_get_drvdata(pdev);
710 const struct dsps_musb_wrapper *wrp = glue->wrp;
711 int i;
712
713 for (i = 0; i < wrp->instances; i++)
714 musb_dsps_phy_control(glue, i, 1);
715
716 return 0;
717}
718#endif
719
720static SIMPLE_DEV_PM_OPS(dsps_pm_ops, dsps_suspend, dsps_resume);
721
722static const struct dsps_musb_wrapper ti81xx_driver_data = {
723 .revision = 0x00, 573 .revision = 0x00,
724 .control = 0x14, 574 .control = 0x14,
725 .status = 0x18, 575 .status = 0x18,
726 .eoi = 0x24,
727 .epintr_set = 0x38, 576 .epintr_set = 0x38,
728 .epintr_clear = 0x40, 577 .epintr_clear = 0x40,
729 .epintr_status = 0x30, 578 .epintr_status = 0x30,
@@ -745,38 +594,23 @@ static const struct dsps_musb_wrapper ti81xx_driver_data = {
745 .rxep_shift = 16, 594 .rxep_shift = 16,
746 .rxep_mask = 0xfffe, 595 .rxep_mask = 0xfffe,
747 .rxep_bitmap = (0xfffe << 16), 596 .rxep_bitmap = (0xfffe << 16),
748 .musb_core_offset = 0x400,
749 .poll_seconds = 2, 597 .poll_seconds = 2,
750 .instances = 1,
751};
752
753static const struct platform_device_id musb_dsps_id_table[] = {
754 {
755 .name = "musb-ti81xx",
756 .driver_data = (kernel_ulong_t) &ti81xx_driver_data,
757 },
758 { }, /* Terminating Entry */
759}; 598};
760MODULE_DEVICE_TABLE(platform, musb_dsps_id_table);
761 599
762#ifdef CONFIG_OF
763static const struct of_device_id musb_dsps_of_match[] = { 600static const struct of_device_id musb_dsps_of_match[] = {
764 { .compatible = "ti,musb-am33xx", 601 { .compatible = "ti,musb-am33xx",
765 .data = (void *) &ti81xx_driver_data, }, 602 .data = (void *) &am33xx_driver_data, },
766 { }, 603 { },
767}; 604};
768MODULE_DEVICE_TABLE(of, musb_dsps_of_match); 605MODULE_DEVICE_TABLE(of, musb_dsps_of_match);
769#endif
770 606
771static struct platform_driver dsps_usbss_driver = { 607static struct platform_driver dsps_usbss_driver = {
772 .probe = dsps_probe, 608 .probe = dsps_probe,
773 .remove = dsps_remove, 609 .remove = dsps_remove,
774 .driver = { 610 .driver = {
775 .name = "musb-dsps", 611 .name = "musb-dsps",
776 .pm = &dsps_pm_ops,
777 .of_match_table = of_match_ptr(musb_dsps_of_match), 612 .of_match_table = of_match_ptr(musb_dsps_of_match),
778 }, 613 },
779 .id_table = musb_dsps_id_table,
780}; 614};
781 615
782MODULE_DESCRIPTION("TI DSPS MUSB Glue Layer"); 616MODULE_DESCRIPTION("TI DSPS MUSB Glue Layer");
@@ -784,14 +618,4 @@ MODULE_AUTHOR("Ravi B <ravibabu@ti.com>");
784MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>"); 618MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>");
785MODULE_LICENSE("GPL v2"); 619MODULE_LICENSE("GPL v2");
786 620
787static int __init dsps_init(void) 621module_platform_driver(dsps_usbss_driver);
788{
789 return platform_driver_register(&dsps_usbss_driver);
790}
791subsys_initcall(dsps_init);
792
793static void __exit dsps_exit(void)
794{
795 platform_driver_unregister(&dsps_usbss_driver);
796}
797module_exit(dsps_exit);
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 0414bc19d009..4376f51f5ef1 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -357,47 +357,49 @@ static void txstate(struct musb *musb, struct musb_request *req)
357 } 357 }
358 } 358 }
359 359
360#elif defined(CONFIG_USB_TI_CPPI_DMA)
361 /* program endpoint CSR first, then setup DMA */
362 csr &= ~(MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY);
363 csr |= MUSB_TXCSR_DMAENAB | MUSB_TXCSR_DMAMODE |
364 MUSB_TXCSR_MODE;
365 musb_writew(epio, MUSB_TXCSR,
366 (MUSB_TXCSR_P_WZC_BITS & ~MUSB_TXCSR_P_UNDERRUN)
367 | csr);
368
369 /* ensure writebuffer is empty */
370 csr = musb_readw(epio, MUSB_TXCSR);
371
372 /* NOTE host side sets DMAENAB later than this; both are
373 * OK since the transfer dma glue (between CPPI and Mentor
374 * fifos) just tells CPPI it could start. Data only moves
375 * to the USB TX fifo when both fifos are ready.
376 */
377
378 /* "mode" is irrelevant here; handle terminating ZLPs like
379 * PIO does, since the hardware RNDIS mode seems unreliable
380 * except for the last-packet-is-already-short case.
381 */
382 use_dma = use_dma && c->channel_program(
383 musb_ep->dma, musb_ep->packet_sz,
384 0,
385 request->dma + request->actual,
386 request_size);
387 if (!use_dma) {
388 c->channel_release(musb_ep->dma);
389 musb_ep->dma = NULL;
390 csr &= ~MUSB_TXCSR_DMAENAB;
391 musb_writew(epio, MUSB_TXCSR, csr);
392 /* invariant: prequest->buf is non-null */
393 }
394#elif defined(CONFIG_USB_TUSB_OMAP_DMA)
395 use_dma = use_dma && c->channel_program(
396 musb_ep->dma, musb_ep->packet_sz,
397 request->zero,
398 request->dma + request->actual,
399 request_size);
400#endif 360#endif
361 if (is_cppi_enabled()) {
362 /* program endpoint CSR first, then setup DMA */
363 csr &= ~(MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY);
364 csr |= MUSB_TXCSR_DMAENAB | MUSB_TXCSR_DMAMODE |
365 MUSB_TXCSR_MODE;
366 musb_writew(epio, MUSB_TXCSR, (MUSB_TXCSR_P_WZC_BITS &
367 ~MUSB_TXCSR_P_UNDERRUN) | csr);
368
369 /* ensure writebuffer is empty */
370 csr = musb_readw(epio, MUSB_TXCSR);
371
372 /*
373 * NOTE host side sets DMAENAB later than this; both are
374 * OK since the transfer dma glue (between CPPI and
375 * Mentor fifos) just tells CPPI it could start. Data
376 * only moves to the USB TX fifo when both fifos are
377 * ready.
378 */
379 /*
380 * "mode" is irrelevant here; handle terminating ZLPs
381 * like PIO does, since the hardware RNDIS mode seems
382 * unreliable except for the
383 * last-packet-is-already-short case.
384 */
385 use_dma = use_dma && c->channel_program(
386 musb_ep->dma, musb_ep->packet_sz,
387 0,
388 request->dma + request->actual,
389 request_size);
390 if (!use_dma) {
391 c->channel_release(musb_ep->dma);
392 musb_ep->dma = NULL;
393 csr &= ~MUSB_TXCSR_DMAENAB;
394 musb_writew(epio, MUSB_TXCSR, csr);
395 /* invariant: prequest->buf is non-null */
396 }
397 } else if (tusb_dma_omap())
398 use_dma = use_dma && c->channel_program(
399 musb_ep->dma, musb_ep->packet_sz,
400 request->zero,
401 request->dma + request->actual,
402 request_size);
401 } 403 }
402#endif 404#endif
403 405
@@ -1266,7 +1268,8 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1266 dev_dbg(musb->controller, "req %p queued to %s while ep %s\n", 1268 dev_dbg(musb->controller, "req %p queued to %s while ep %s\n",
1267 req, ep->name, "disabled"); 1269 req, ep->name, "disabled");
1268 status = -ESHUTDOWN; 1270 status = -ESHUTDOWN;
1269 goto cleanup; 1271 unmap_dma_buffer(request, musb);
1272 goto unlock;
1270 } 1273 }
1271 1274
1272 /* add request to the list */ 1275 /* add request to the list */
@@ -1276,7 +1279,7 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1276 if (!musb_ep->busy && &request->list == musb_ep->req_list.next) 1279 if (!musb_ep->busy && &request->list == musb_ep->req_list.next)
1277 musb_ep_restart(musb, request); 1280 musb_ep_restart(musb, request);
1278 1281
1279cleanup: 1282unlock:
1280 spin_unlock_irqrestore(&musb->lock, lockflags); 1283 spin_unlock_irqrestore(&musb->lock, lockflags);
1281 return status; 1284 return status;
1282} 1285}
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index 3d1fd52a15a9..e8e9f9aab203 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -37,18 +37,10 @@
37#include "musb_core.h" 37#include "musb_core.h"
38#include "musbhsdma.h" 38#include "musbhsdma.h"
39 39
40static int dma_controller_start(struct dma_controller *c)
41{
42 /* nothing to do */
43 return 0;
44}
45
46static void dma_channel_release(struct dma_channel *channel); 40static void dma_channel_release(struct dma_channel *channel);
47 41
48static int dma_controller_stop(struct dma_controller *c) 42static void dma_controller_stop(struct musb_dma_controller *controller)
49{ 43{
50 struct musb_dma_controller *controller = container_of(c,
51 struct musb_dma_controller, controller);
52 struct musb *musb = controller->private_data; 44 struct musb *musb = controller->private_data;
53 struct dma_channel *channel; 45 struct dma_channel *channel;
54 u8 bit; 46 u8 bit;
@@ -67,8 +59,6 @@ static int dma_controller_stop(struct dma_controller *c)
67 } 59 }
68 } 60 }
69 } 61 }
70
71 return 0;
72} 62}
73 63
74static struct dma_channel *dma_channel_allocate(struct dma_controller *c, 64static struct dma_channel *dma_channel_allocate(struct dma_controller *c,
@@ -371,8 +361,7 @@ void dma_controller_destroy(struct dma_controller *c)
371 struct musb_dma_controller *controller = container_of(c, 361 struct musb_dma_controller *controller = container_of(c,
372 struct musb_dma_controller, controller); 362 struct musb_dma_controller, controller);
373 363
374 if (!controller) 364 dma_controller_stop(controller);
375 return;
376 365
377 if (controller->irq) 366 if (controller->irq)
378 free_irq(controller->irq, c); 367 free_irq(controller->irq, c);
@@ -400,8 +389,6 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba
400 controller->private_data = musb; 389 controller->private_data = musb;
401 controller->base = base; 390 controller->base = base;
402 391
403 controller->controller.start = dma_controller_start;
404 controller->controller.stop = dma_controller_stop;
405 controller->controller.channel_alloc = dma_channel_allocate; 392 controller->controller.channel_alloc = dma_channel_allocate;
406 controller->controller.channel_release = dma_channel_release; 393 controller->controller.channel_release = dma_channel_release;
407 controller->controller.channel_program = dma_channel_program; 394 controller->controller.channel_program = dma_channel_program;
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index f44e8b5e00c9..59d2245db1c8 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -255,7 +255,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
255{ 255{
256 struct musb *musb = glue_to_musb(glue); 256 struct musb *musb = glue_to_musb(glue);
257 struct device *dev = musb->controller; 257 struct device *dev = musb->controller;
258 struct musb_hdrc_platform_data *pdata = dev->platform_data; 258 struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
259 struct omap_musb_board_data *data = pdata->board_data; 259 struct omap_musb_board_data *data = pdata->board_data;
260 struct usb_otg *otg = musb->xceiv->otg; 260 struct usb_otg *otg = musb->xceiv->otg;
261 261
@@ -341,7 +341,7 @@ static int omap2430_musb_init(struct musb *musb)
341 int status = 0; 341 int status = 0;
342 struct device *dev = musb->controller; 342 struct device *dev = musb->controller;
343 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 343 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
344 struct musb_hdrc_platform_data *plat = dev->platform_data; 344 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
345 struct omap_musb_board_data *data = plat->board_data; 345 struct omap_musb_board_data *data = plat->board_data;
346 346
347 /* We require some kind of external transceiver, hooked 347 /* We require some kind of external transceiver, hooked
@@ -412,7 +412,7 @@ static void omap2430_musb_enable(struct musb *musb)
412 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 412 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
413 struct device *dev = musb->controller; 413 struct device *dev = musb->controller;
414 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 414 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
415 struct musb_hdrc_platform_data *pdata = dev->platform_data; 415 struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
416 struct omap_musb_board_data *data = pdata->board_data; 416 struct omap_musb_board_data *data = pdata->board_data;
417 417
418 switch (glue->status) { 418 switch (glue->status) {
@@ -482,7 +482,7 @@ static u64 omap2430_dmamask = DMA_BIT_MASK(32);
482static int omap2430_probe(struct platform_device *pdev) 482static int omap2430_probe(struct platform_device *pdev)
483{ 483{
484 struct resource musb_resources[3]; 484 struct resource musb_resources[3];
485 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 485 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
486 struct omap_musb_board_data *data; 486 struct omap_musb_board_data *data;
487 struct platform_device *musb; 487 struct platform_device *musb;
488 struct omap2430_glue *glue; 488 struct omap2430_glue *glue;
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 6f8a9ca96ae7..b3b3ed723882 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -25,7 +25,7 @@
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/dma-mapping.h> 27#include <linux/dma-mapping.h>
28#include <linux/usb/nop-usb-xceiv.h> 28#include <linux/usb/usb_phy_gen_xceiv.h>
29 29
30#include "musb_core.h" 30#include "musb_core.h"
31 31
@@ -1157,7 +1157,7 @@ static u64 tusb_dmamask = DMA_BIT_MASK(32);
1157static int tusb_probe(struct platform_device *pdev) 1157static int tusb_probe(struct platform_device *pdev)
1158{ 1158{
1159 struct resource musb_resources[3]; 1159 struct resource musb_resources[3];
1160 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 1160 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
1161 struct platform_device *musb; 1161 struct platform_device *musb;
1162 struct tusb6010_glue *glue; 1162 struct tusb6010_glue *glue;
1163 1163
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c
index 98df17c984a8..b8794eb81e9c 100644
--- a/drivers/usb/musb/tusb6010_omap.c
+++ b/drivers/usb/musb/tusb6010_omap.c
@@ -66,28 +66,6 @@ struct tusb_omap_dma {
66 unsigned multichannel:1; 66 unsigned multichannel:1;
67}; 67};
68 68
69static int tusb_omap_dma_start(struct dma_controller *c)
70{
71 struct tusb_omap_dma *tusb_dma;
72
73 tusb_dma = container_of(c, struct tusb_omap_dma, controller);
74
75 /* dev_dbg(musb->controller, "ep%i ch: %i\n", chdat->epnum, chdat->ch); */
76
77 return 0;
78}
79
80static int tusb_omap_dma_stop(struct dma_controller *c)
81{
82 struct tusb_omap_dma *tusb_dma;
83
84 tusb_dma = container_of(c, struct tusb_omap_dma, controller);
85
86 /* dev_dbg(musb->controller, "ep%i ch: %i\n", chdat->epnum, chdat->ch); */
87
88 return 0;
89}
90
91/* 69/*
92 * Allocate dmareq0 to the current channel unless it's already taken 70 * Allocate dmareq0 to the current channel unless it's already taken
93 */ 71 */
@@ -695,8 +673,6 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba
695 tusb_dma->dmareq = -1; 673 tusb_dma->dmareq = -1;
696 tusb_dma->sync_dev = -1; 674 tusb_dma->sync_dev = -1;
697 675
698 tusb_dma->controller.start = tusb_omap_dma_start;
699 tusb_dma->controller.stop = tusb_omap_dma_stop;
700 tusb_dma->controller.channel_alloc = tusb_omap_dma_allocate; 676 tusb_dma->controller.channel_alloc = tusb_omap_dma_allocate;
701 tusb_dma->controller.channel_release = tusb_omap_dma_release; 677 tusb_dma->controller.channel_release = tusb_omap_dma_release;
702 tusb_dma->controller.channel_program = tusb_omap_dma_program; 678 tusb_dma->controller.channel_program = tusb_omap_dma_program;
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index fce71b605936..59256b12f746 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -227,7 +227,7 @@ ux500_of_probe(struct platform_device *pdev, struct device_node *np)
227static int ux500_probe(struct platform_device *pdev) 227static int ux500_probe(struct platform_device *pdev)
228{ 228{
229 struct resource musb_resources[2]; 229 struct resource musb_resources[2];
230 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 230 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
231 struct device_node *np = pdev->dev.of_node; 231 struct device_node *np = pdev->dev.of_node;
232 struct platform_device *musb; 232 struct platform_device *musb;
233 struct ux500_glue *glue; 233 struct ux500_glue *glue;
diff --git a/drivers/usb/musb/ux500_dma.c b/drivers/usb/musb/ux500_dma.c
index bfb7a65d83cc..e51dd9b88e71 100644
--- a/drivers/usb/musb/ux500_dma.c
+++ b/drivers/usb/musb/ux500_dma.c
@@ -254,10 +254,8 @@ static int ux500_dma_channel_abort(struct dma_channel *channel)
254 return 0; 254 return 0;
255} 255}
256 256
257static int ux500_dma_controller_stop(struct dma_controller *c) 257static void ux500_dma_controller_stop(struct ux500_dma_controller *controller)
258{ 258{
259 struct ux500_dma_controller *controller = container_of(c,
260 struct ux500_dma_controller, controller);
261 struct ux500_dma_channel *ux500_channel; 259 struct ux500_dma_channel *ux500_channel;
262 struct dma_channel *channel; 260 struct dma_channel *channel;
263 u8 ch_num; 261 u8 ch_num;
@@ -281,18 +279,14 @@ static int ux500_dma_controller_stop(struct dma_controller *c)
281 if (ux500_channel->dma_chan) 279 if (ux500_channel->dma_chan)
282 dma_release_channel(ux500_channel->dma_chan); 280 dma_release_channel(ux500_channel->dma_chan);
283 } 281 }
284
285 return 0;
286} 282}
287 283
288static int ux500_dma_controller_start(struct dma_controller *c) 284static int ux500_dma_controller_start(struct ux500_dma_controller *controller)
289{ 285{
290 struct ux500_dma_controller *controller = container_of(c,
291 struct ux500_dma_controller, controller);
292 struct ux500_dma_channel *ux500_channel = NULL; 286 struct ux500_dma_channel *ux500_channel = NULL;
293 struct musb *musb = controller->private_data; 287 struct musb *musb = controller->private_data;
294 struct device *dev = musb->controller; 288 struct device *dev = musb->controller;
295 struct musb_hdrc_platform_data *plat = dev->platform_data; 289 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
296 struct ux500_musb_board_data *data; 290 struct ux500_musb_board_data *data;
297 struct dma_channel *dma_channel = NULL; 291 struct dma_channel *dma_channel = NULL;
298 char **chan_names; 292 char **chan_names;
@@ -347,7 +341,7 @@ static int ux500_dma_controller_start(struct dma_controller *c)
347 dir, ch_num); 341 dir, ch_num);
348 342
349 /* Release already allocated channels */ 343 /* Release already allocated channels */
350 ux500_dma_controller_stop(c); 344 ux500_dma_controller_stop(controller);
351 345
352 return -EBUSY; 346 return -EBUSY;
353 } 347 }
@@ -369,6 +363,7 @@ void dma_controller_destroy(struct dma_controller *c)
369 struct ux500_dma_controller *controller = container_of(c, 363 struct ux500_dma_controller *controller = container_of(c,
370 struct ux500_dma_controller, controller); 364 struct ux500_dma_controller, controller);
371 365
366 ux500_dma_controller_stop(controller);
372 kfree(controller); 367 kfree(controller);
373} 368}
374 369
@@ -378,6 +373,7 @@ struct dma_controller *dma_controller_create(struct musb *musb,
378 struct ux500_dma_controller *controller; 373 struct ux500_dma_controller *controller;
379 struct platform_device *pdev = to_platform_device(musb->controller); 374 struct platform_device *pdev = to_platform_device(musb->controller);
380 struct resource *iomem; 375 struct resource *iomem;
376 int ret;
381 377
382 controller = kzalloc(sizeof(*controller), GFP_KERNEL); 378 controller = kzalloc(sizeof(*controller), GFP_KERNEL);
383 if (!controller) 379 if (!controller)
@@ -394,14 +390,15 @@ struct dma_controller *dma_controller_create(struct musb *musb,
394 390
395 controller->phy_base = (dma_addr_t) iomem->start; 391 controller->phy_base = (dma_addr_t) iomem->start;
396 392
397 controller->controller.start = ux500_dma_controller_start;
398 controller->controller.stop = ux500_dma_controller_stop;
399 controller->controller.channel_alloc = ux500_dma_channel_allocate; 393 controller->controller.channel_alloc = ux500_dma_channel_allocate;
400 controller->controller.channel_release = ux500_dma_channel_release; 394 controller->controller.channel_release = ux500_dma_channel_release;
401 controller->controller.channel_program = ux500_dma_channel_program; 395 controller->controller.channel_program = ux500_dma_channel_program;
402 controller->controller.channel_abort = ux500_dma_channel_abort; 396 controller->controller.channel_abort = ux500_dma_channel_abort;
403 controller->controller.is_compatible = ux500_dma_is_compatible; 397 controller->controller.is_compatible = ux500_dma_is_compatible;
404 398
399 ret = ux500_dma_controller_start(controller);
400 if (ret)
401 goto plat_get_fail;
405 return &controller->controller; 402 return &controller->controller;
406 403
407plat_get_fail: 404plat_get_fail:
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 3622fff8b798..d5589f9c60a9 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -1,22 +1,10 @@
1# 1#
2# Physical Layer USB driver configuration 2# Physical Layer USB driver configuration
3# 3#
4menuconfig USB_PHY 4menu "USB Physical Layer drivers"
5 bool "USB Physical Layer drivers"
6 help
7 Most USB controllers have the physical layer signalling part
8 (commonly called a PHY) built in. However, dual-role devices
9 (a.k.a. USB on-the-go) which support being USB master or slave
10 with the same connector often use an external PHY.
11
12 The drivers in this submenu add support for such PHY devices.
13 They are not needed for standard master-only (or the vast
14 majority of slave-only) USB interfaces.
15 5
16 If you're not sure if this applies to you, it probably doesn't; 6config USB_PHY
17 say N here. 7 def_bool n
18
19if USB_PHY
20 8
21# 9#
22# USB Transceiver Drivers 10# USB Transceiver Drivers
@@ -24,6 +12,7 @@ if USB_PHY
24config AB8500_USB 12config AB8500_USB
25 tristate "AB8500 USB Transceiver Driver" 13 tristate "AB8500 USB Transceiver Driver"
26 depends on AB8500_CORE 14 depends on AB8500_CORE
15 select USB_PHY
27 help 16 help
28 Enable this to support the USB OTG transceiver in AB8500 chip. 17 Enable this to support the USB OTG transceiver in AB8500 chip.
29 This transceiver supports high and full speed devices plus, 18 This transceiver supports high and full speed devices plus,
@@ -33,12 +22,14 @@ config FSL_USB2_OTG
33 bool "Freescale USB OTG Transceiver Driver" 22 bool "Freescale USB OTG Transceiver Driver"
34 depends on USB_EHCI_FSL && USB_FSL_USB2 && PM_RUNTIME 23 depends on USB_EHCI_FSL && USB_FSL_USB2 && PM_RUNTIME
35 select USB_OTG 24 select USB_OTG
25 select USB_PHY
36 help 26 help
37 Enable this to support Freescale USB OTG transceiver. 27 Enable this to support Freescale USB OTG transceiver.
38 28
39config ISP1301_OMAP 29config ISP1301_OMAP
40 tristate "Philips ISP1301 with OMAP OTG" 30 tristate "Philips ISP1301 with OMAP OTG"
41 depends on I2C && ARCH_OMAP_OTG 31 depends on I2C && ARCH_OMAP_OTG
32 select USB_PHY
42 help 33 help
43 If you say yes here you get support for the Philips ISP1301 34 If you say yes here you get support for the Philips ISP1301
44 USB-On-The-Go transceiver working with the OMAP OTG controller. 35 USB-On-The-Go transceiver working with the OMAP OTG controller.
@@ -52,12 +43,14 @@ config ISP1301_OMAP
52config MV_U3D_PHY 43config MV_U3D_PHY
53 bool "Marvell USB 3.0 PHY controller Driver" 44 bool "Marvell USB 3.0 PHY controller Driver"
54 depends on CPU_MMP3 45 depends on CPU_MMP3
46 select USB_PHY
55 help 47 help
56 Enable this to support Marvell USB 3.0 phy controller for Marvell 48 Enable this to support Marvell USB 3.0 phy controller for Marvell
57 SoC. 49 SoC.
58 50
59config NOP_USB_XCEIV 51config NOP_USB_XCEIV
60 tristate "NOP USB Transceiver Driver" 52 tristate "NOP USB Transceiver Driver"
53 select USB_PHY
61 help 54 help
62 This driver is to be used by all the usb transceiver which are either 55 This driver is to be used by all the usb transceiver which are either
63 built-in with usb ip or which are autonomous and doesn't require any 56 built-in with usb ip or which are autonomous and doesn't require any
@@ -65,6 +58,7 @@ config NOP_USB_XCEIV
65 58
66config OMAP_CONTROL_USB 59config OMAP_CONTROL_USB
67 tristate "OMAP CONTROL USB Driver" 60 tristate "OMAP CONTROL USB Driver"
61 depends on ARCH_OMAP2PLUS || COMPILE_TEST
68 help 62 help
69 Enable this to add support for the USB part present in the control 63 Enable this to add support for the USB part present in the control
70 module. This driver has API to power on the USB2 PHY and to write to 64 module. This driver has API to power on the USB2 PHY and to write to
@@ -76,6 +70,7 @@ config OMAP_USB2
76 tristate "OMAP USB2 PHY Driver" 70 tristate "OMAP USB2 PHY Driver"
77 depends on ARCH_OMAP2PLUS 71 depends on ARCH_OMAP2PLUS
78 select OMAP_CONTROL_USB 72 select OMAP_CONTROL_USB
73 select USB_PHY
79 help 74 help
80 Enable this to support the transceiver that is part of SOC. This 75 Enable this to support the transceiver that is part of SOC. This
81 driver takes care of all the PHY functionality apart from comparator. 76 driver takes care of all the PHY functionality apart from comparator.
@@ -84,13 +79,27 @@ config OMAP_USB2
84 79
85config OMAP_USB3 80config OMAP_USB3
86 tristate "OMAP USB3 PHY Driver" 81 tristate "OMAP USB3 PHY Driver"
82 depends on ARCH_OMAP2PLUS || COMPILE_TEST
87 select OMAP_CONTROL_USB 83 select OMAP_CONTROL_USB
84 select USB_PHY
88 help 85 help
89 Enable this to support the USB3 PHY that is part of SOC. This 86 Enable this to support the USB3 PHY that is part of SOC. This
90 driver takes care of all the PHY functionality apart from comparator. 87 driver takes care of all the PHY functionality apart from comparator.
91 This driver interacts with the "OMAP Control USB Driver" to power 88 This driver interacts with the "OMAP Control USB Driver" to power
92 on/off the PHY. 89 on/off the PHY.
93 90
91config AM335X_CONTROL_USB
92 tristate
93
94config AM335X_PHY_USB
95 tristate "AM335x USB PHY Driver"
96 select USB_PHY
97 select AM335X_CONTROL_USB
98 select NOP_USB_XCEIV
99 help
100 This driver provides PHY support for that phy which part for the
101 AM335x SoC.
102
94config SAMSUNG_USBPHY 103config SAMSUNG_USBPHY
95 tristate 104 tristate
96 help 105 help
@@ -101,6 +110,7 @@ config SAMSUNG_USBPHY
101config SAMSUNG_USB2PHY 110config SAMSUNG_USB2PHY
102 tristate "Samsung USB 2.0 PHY controller Driver" 111 tristate "Samsung USB 2.0 PHY controller Driver"
103 select SAMSUNG_USBPHY 112 select SAMSUNG_USBPHY
113 select USB_PHY
104 help 114 help
105 Enable this to support Samsung USB 2.0 (High Speed) PHY controller 115 Enable this to support Samsung USB 2.0 (High Speed) PHY controller
106 driver for Samsung SoCs. 116 driver for Samsung SoCs.
@@ -108,6 +118,7 @@ config SAMSUNG_USB2PHY
108config SAMSUNG_USB3PHY 118config SAMSUNG_USB3PHY
109 tristate "Samsung USB 3.0 PHY controller Driver" 119 tristate "Samsung USB 3.0 PHY controller Driver"
110 select SAMSUNG_USBPHY 120 select SAMSUNG_USBPHY
121 select USB_PHY
111 help 122 help
112 Enable this to support Samsung USB 3.0 (Super Speed) phy controller 123 Enable this to support Samsung USB 3.0 (Super Speed) phy controller
113 for samsung SoCs. 124 for samsung SoCs.
@@ -115,6 +126,7 @@ config SAMSUNG_USB3PHY
115config TWL4030_USB 126config TWL4030_USB
116 tristate "TWL4030 USB Transceiver Driver" 127 tristate "TWL4030 USB Transceiver Driver"
117 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS 128 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
129 select USB_PHY
118 help 130 help
119 Enable this to support the USB OTG transceiver on TWL4030 131 Enable this to support the USB OTG transceiver on TWL4030
120 family chips (including the TWL5030 and TPS659x0 devices). 132 family chips (including the TWL5030 and TPS659x0 devices).
@@ -135,6 +147,7 @@ config TWL6030_USB
135config USB_GPIO_VBUS 147config USB_GPIO_VBUS
136 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'" 148 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'"
137 depends on GPIOLIB 149 depends on GPIOLIB
150 select USB_PHY
138 help 151 help
139 Provides simple GPIO VBUS sensing for controllers with an 152 Provides simple GPIO VBUS sensing for controllers with an
140 internal transceiver via the usb_phy interface, and 153 internal transceiver via the usb_phy interface, and
@@ -145,6 +158,7 @@ config USB_ISP1301
145 tristate "NXP ISP1301 USB transceiver support" 158 tristate "NXP ISP1301 USB transceiver support"
146 depends on USB || USB_GADGET 159 depends on USB || USB_GADGET
147 depends on I2C 160 depends on I2C
161 select USB_PHY
148 help 162 help
149 Say Y here to add support for the NXP ISP1301 USB transceiver driver. 163 Say Y here to add support for the NXP ISP1301 USB transceiver driver.
150 This chip is typically used as USB transceiver for USB host, gadget 164 This chip is typically used as USB transceiver for USB host, gadget
@@ -156,6 +170,7 @@ config USB_ISP1301
156config USB_MSM_OTG 170config USB_MSM_OTG
157 tristate "OTG support for Qualcomm on-chip USB controller" 171 tristate "OTG support for Qualcomm on-chip USB controller"
158 depends on (USB || USB_GADGET) && ARCH_MSM 172 depends on (USB || USB_GADGET) && ARCH_MSM
173 select USB_PHY
159 help 174 help
160 Enable this to support the USB OTG transceiver on MSM chips. It 175 Enable this to support the USB OTG transceiver on MSM chips. It
161 handles PHY initialization, clock management, and workarounds 176 handles PHY initialization, clock management, and workarounds
@@ -169,6 +184,7 @@ config USB_MV_OTG
169 tristate "Marvell USB OTG support" 184 tristate "Marvell USB OTG support"
170 depends on USB_EHCI_MV && USB_MV_UDC && PM_RUNTIME 185 depends on USB_EHCI_MV && USB_MV_UDC && PM_RUNTIME
171 select USB_OTG 186 select USB_OTG
187 select USB_PHY
172 help 188 help
173 Say Y here if you want to build Marvell USB OTG transciever 189 Say Y here if you want to build Marvell USB OTG transciever
174 driver in kernel (including PXA and MMP series). This driver 190 driver in kernel (including PXA and MMP series). This driver
@@ -180,6 +196,7 @@ config USB_MXS_PHY
180 tristate "Freescale MXS USB PHY support" 196 tristate "Freescale MXS USB PHY support"
181 depends on ARCH_MXC || ARCH_MXS 197 depends on ARCH_MXC || ARCH_MXS
182 select STMP_DEVICE 198 select STMP_DEVICE
199 select USB_PHY
183 help 200 help
184 Enable this to support the Freescale MXS USB PHY. 201 Enable this to support the Freescale MXS USB PHY.
185 202
@@ -188,6 +205,7 @@ config USB_MXS_PHY
188config USB_RCAR_PHY 205config USB_RCAR_PHY
189 tristate "Renesas R-Car USB PHY support" 206 tristate "Renesas R-Car USB PHY support"
190 depends on USB || USB_GADGET 207 depends on USB || USB_GADGET
208 select USB_PHY
191 help 209 help
192 Say Y here to add support for the Renesas R-Car USB common PHY driver. 210 Say Y here to add support for the Renesas R-Car USB common PHY driver.
193 This chip is typically used as USB PHY for USB host, gadget. 211 This chip is typically used as USB PHY for USB host, gadget.
@@ -210,4 +228,4 @@ config USB_ULPI_VIEWPORT
210 Provides read/write operations to the ULPI phy register set for 228 Provides read/write operations to the ULPI phy register set for
211 controllers with a viewport register (e.g. Chipidea/ARC controllers). 229 controllers with a viewport register (e.g. Chipidea/ARC controllers).
212 230
213endif # USB_PHY 231endmenu
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 070eca3af18b..2135e85f46ed 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -1,9 +1,6 @@
1# 1#
2# Makefile for physical layer USB drivers 2# Makefile for physical layer USB drivers
3# 3#
4
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6
7obj-$(CONFIG_USB_PHY) += phy.o 4obj-$(CONFIG_USB_PHY) += phy.o
8obj-$(CONFIG_OF) += of.o 5obj-$(CONFIG_OF) += of.o
9 6
@@ -14,8 +11,10 @@ phy-fsl-usb2-objs := phy-fsl-usb.o phy-fsm-usb.o
14obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb2.o 11obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb2.o
15obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301-omap.o 12obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301-omap.o
16obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o 13obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o
17obj-$(CONFIG_NOP_USB_XCEIV) += phy-nop.o 14obj-$(CONFIG_NOP_USB_XCEIV) += phy-generic.o
18obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o 15obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o
16obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o
17obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o
19obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o 18obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
20obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o 19obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o
21obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o 20obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o
diff --git a/drivers/usb/phy/am35x-phy-control.h b/drivers/usb/phy/am35x-phy-control.h
new file mode 100644
index 000000000000..b96594d1962c
--- /dev/null
+++ b/drivers/usb/phy/am35x-phy-control.h
@@ -0,0 +1,21 @@
1#ifndef _AM335x_PHY_CONTROL_H_
2#define _AM335x_PHY_CONTROL_H_
3
4struct phy_control {
5 void (*phy_power)(struct phy_control *phy_ctrl, u32 id, bool on);
6 void (*phy_wkup)(struct phy_control *phy_ctrl, u32 id, bool on);
7};
8
9static inline void phy_ctrl_power(struct phy_control *phy_ctrl, u32 id, bool on)
10{
11 phy_ctrl->phy_power(phy_ctrl, id, on);
12}
13
14static inline void phy_ctrl_wkup(struct phy_control *phy_ctrl, u32 id, bool on)
15{
16 phy_ctrl->phy_wkup(phy_ctrl, id, on);
17}
18
19struct phy_control *am335x_get_phy_control(struct device *dev);
20
21#endif
diff --git a/drivers/usb/phy/phy-am335x-control.c b/drivers/usb/phy/phy-am335x-control.c
new file mode 100644
index 000000000000..759754521426
--- /dev/null
+++ b/drivers/usb/phy/phy-am335x-control.c
@@ -0,0 +1,137 @@
1#include <linux/module.h>
2#include <linux/platform_device.h>
3#include <linux/err.h>
4#include <linux/of.h>
5#include <linux/io.h>
6
7struct phy_control {
8 void (*phy_power)(struct phy_control *phy_ctrl, u32 id, bool on);
9 void (*phy_wkup)(struct phy_control *phy_ctrl, u32 id, bool on);
10};
11
12struct am335x_control_usb {
13 struct device *dev;
14 void __iomem *phy_reg;
15 void __iomem *wkup;
16 spinlock_t lock;
17 struct phy_control phy_ctrl;
18};
19
20#define AM335X_USB0_CTRL 0x0
21#define AM335X_USB1_CTRL 0x8
22#define AM335x_USB_WKUP 0x0
23
24#define USBPHY_CM_PWRDN (1 << 0)
25#define USBPHY_OTG_PWRDN (1 << 1)
26#define USBPHY_OTGVDET_EN (1 << 19)
27#define USBPHY_OTGSESSEND_EN (1 << 20)
28
29static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on)
30{
31 struct am335x_control_usb *usb_ctrl;
32 u32 val;
33 u32 reg;
34
35 usb_ctrl = container_of(phy_ctrl, struct am335x_control_usb, phy_ctrl);
36
37 switch (id) {
38 case 0:
39 reg = AM335X_USB0_CTRL;
40 break;
41 case 1:
42 reg = AM335X_USB1_CTRL;
43 break;
44 default:
45 __WARN();
46 return;
47 }
48
49 val = readl(usb_ctrl->phy_reg + reg);
50 if (on) {
51 val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN);
52 val |= USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN;
53 } else {
54 val |= USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN;
55 }
56
57 writel(val, usb_ctrl->phy_reg + reg);
58}
59
60static const struct phy_control ctrl_am335x = {
61 .phy_power = am335x_phy_power,
62};
63
64static const struct of_device_id omap_control_usb_id_table[] = {
65 { .compatible = "ti,am335x-usb-ctrl-module", .data = &ctrl_am335x },
66 {}
67};
68MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
69
70static struct platform_driver am335x_control_driver;
71static int match(struct device *dev, void *data)
72{
73 struct device_node *node = (struct device_node *)data;
74 return dev->of_node == node &&
75 dev->driver == &am335x_control_driver.driver;
76}
77
78struct phy_control *am335x_get_phy_control(struct device *dev)
79{
80 struct device_node *node;
81 struct am335x_control_usb *ctrl_usb;
82
83 node = of_parse_phandle(dev->of_node, "ti,ctrl_mod", 0);
84 if (!node)
85 return NULL;
86
87 dev = bus_find_device(&platform_bus_type, NULL, node, match);
88 ctrl_usb = dev_get_drvdata(dev);
89 if (!ctrl_usb)
90 return NULL;
91 return &ctrl_usb->phy_ctrl;
92}
93EXPORT_SYMBOL_GPL(am335x_get_phy_control);
94
95static int am335x_control_usb_probe(struct platform_device *pdev)
96{
97 struct resource *res;
98 struct am335x_control_usb *ctrl_usb;
99 const struct of_device_id *of_id;
100 const struct phy_control *phy_ctrl;
101
102 of_id = of_match_node(omap_control_usb_id_table, pdev->dev.of_node);
103 if (!of_id)
104 return -EINVAL;
105
106 phy_ctrl = of_id->data;
107
108 ctrl_usb = devm_kzalloc(&pdev->dev, sizeof(*ctrl_usb), GFP_KERNEL);
109 if (!ctrl_usb) {
110 dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
111 return -ENOMEM;
112 }
113
114 ctrl_usb->dev = &pdev->dev;
115
116 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl");
117 ctrl_usb->phy_reg = devm_ioremap_resource(&pdev->dev, res);
118 if (IS_ERR(ctrl_usb->phy_reg))
119 return PTR_ERR(ctrl_usb->phy_reg);
120 spin_lock_init(&ctrl_usb->lock);
121 ctrl_usb->phy_ctrl = *phy_ctrl;
122
123 dev_set_drvdata(ctrl_usb->dev, ctrl_usb);
124 return 0;
125}
126
127static struct platform_driver am335x_control_driver = {
128 .probe = am335x_control_usb_probe,
129 .driver = {
130 .name = "am335x-control-usb",
131 .owner = THIS_MODULE,
132 .of_match_table = of_match_ptr(omap_control_usb_id_table),
133 },
134};
135
136module_platform_driver(am335x_control_driver);
137MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/phy/phy-am335x.c b/drivers/usb/phy/phy-am335x.c
new file mode 100644
index 000000000000..c4d614d1f173
--- /dev/null
+++ b/drivers/usb/phy/phy-am335x.c
@@ -0,0 +1,99 @@
1#include <linux/module.h>
2#include <linux/platform_device.h>
3#include <linux/dma-mapping.h>
4#include <linux/usb/otg.h>
5#include <linux/usb/usb_phy_gen_xceiv.h>
6#include <linux/slab.h>
7#include <linux/clk.h>
8#include <linux/regulator/consumer.h>
9#include <linux/of.h>
10#include <linux/of_address.h>
11
12#include "am35x-phy-control.h"
13#include "phy-generic.h"
14
15struct am335x_phy {
16 struct usb_phy_gen_xceiv usb_phy_gen;
17 struct phy_control *phy_ctrl;
18 int id;
19};
20
21static int am335x_init(struct usb_phy *phy)
22{
23 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
24
25 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true);
26 return 0;
27}
28
29static void am335x_shutdown(struct usb_phy *phy)
30{
31 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
32
33 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
34}
35
36static int am335x_phy_probe(struct platform_device *pdev)
37{
38 struct am335x_phy *am_phy;
39 struct device *dev = &pdev->dev;
40 int ret;
41
42 am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL);
43 if (!am_phy)
44 return -ENOMEM;
45
46 am_phy->phy_ctrl = am335x_get_phy_control(dev);
47 if (!am_phy->phy_ctrl)
48 return -EPROBE_DEFER;
49 am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy");
50 if (am_phy->id < 0) {
51 dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id);
52 return am_phy->id;
53 }
54
55 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen,
56 USB_PHY_TYPE_USB2, 0, false, false);
57 if (ret)
58 return ret;
59
60 ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy);
61 if (ret)
62 goto err_add;
63 am_phy->usb_phy_gen.phy.init = am335x_init;
64 am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown;
65
66 platform_set_drvdata(pdev, am_phy);
67 return 0;
68
69err_add:
70 usb_phy_gen_cleanup_phy(&am_phy->usb_phy_gen);
71 return ret;
72}
73
74static int am335x_phy_remove(struct platform_device *pdev)
75{
76 struct am335x_phy *am_phy = platform_get_drvdata(pdev);
77
78 usb_remove_phy(&am_phy->usb_phy_gen.phy);
79 return 0;
80}
81
82static const struct of_device_id am335x_phy_ids[] = {
83 { .compatible = "ti,am335x-usb-phy" },
84 { }
85};
86MODULE_DEVICE_TABLE(of, am335x_phy_ids);
87
88static struct platform_driver am335x_phy_driver = {
89 .probe = am335x_phy_probe,
90 .remove = am335x_phy_remove,
91 .driver = {
92 .name = "am335x-phy-driver",
93 .owner = THIS_MODULE,
94 .of_match_table = of_match_ptr(am335x_phy_ids),
95 },
96};
97
98module_platform_driver(am335x_phy_driver);
99MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c
index e771bafb9f1d..fa7c9f9628b5 100644
--- a/drivers/usb/phy/phy-fsl-usb.c
+++ b/drivers/usb/phy/phy-fsl-usb.c
@@ -611,7 +611,7 @@ static int fsl_otg_set_peripheral(struct usb_otg *otg,
611 otg_dev->fsm.b_bus_req = 1; 611 otg_dev->fsm.b_bus_req = 1;
612 612
613 /* start the gadget right away if the ID pin says Mini-B */ 613 /* start the gadget right away if the ID pin says Mini-B */
614 DBG("ID pin=%d\n", otg_dev->fsm.id); 614 pr_debug("ID pin=%d\n", otg_dev->fsm.id);
615 if (otg_dev->fsm.id == 1) { 615 if (otg_dev->fsm.id == 1) {
616 fsl_otg_start_host(&otg_dev->fsm, 0); 616 fsl_otg_start_host(&otg_dev->fsm, 0);
617 otg_drv_vbus(&otg_dev->fsm, 0); 617 otg_drv_vbus(&otg_dev->fsm, 0);
@@ -684,7 +684,7 @@ static int fsl_otg_start_hnp(struct usb_otg *otg)
684 if (otg_dev != fsl_otg_dev) 684 if (otg_dev != fsl_otg_dev)
685 return -ENODEV; 685 return -ENODEV;
686 686
687 DBG("start_hnp...n"); 687 pr_debug("start_hnp...\n");
688 688
689 /* clear a_bus_req to enter a_suspend state */ 689 /* clear a_bus_req to enter a_suspend state */
690 otg_dev->fsm.a_bus_req = 0; 690 otg_dev->fsm.a_bus_req = 0;
@@ -834,7 +834,7 @@ int usb_otg_start(struct platform_device *pdev)
834 int status; 834 int status;
835 struct resource *res; 835 struct resource *res;
836 u32 temp; 836 u32 temp;
837 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 837 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
838 838
839 p_otg = container_of(otg_trans, struct fsl_otg, phy); 839 p_otg = container_of(otg_trans, struct fsl_otg, phy);
840 fsm = &p_otg->fsm; 840 fsm = &p_otg->fsm;
@@ -941,7 +941,7 @@ int usb_otg_start(struct platform_device *pdev)
941 p_otg->fsm.id = 0; 941 p_otg->fsm.id = 0;
942 } 942 }
943 943
944 DBG("initial ID pin=%d\n", p_otg->fsm.id); 944 pr_debug("initial ID pin=%d\n", p_otg->fsm.id);
945 945
946 /* enable OTG ID pin interrupt */ 946 /* enable OTG ID pin interrupt */
947 temp = fsl_readl(&p_otg->dr_mem_map->otgsc); 947 temp = fsl_readl(&p_otg->dr_mem_map->otgsc);
@@ -1105,7 +1105,7 @@ static int fsl_otg_probe(struct platform_device *pdev)
1105{ 1105{
1106 int ret; 1106 int ret;
1107 1107
1108 if (!pdev->dev.platform_data) 1108 if (!dev_get_platdata(&pdev->dev))
1109 return -ENODEV; 1109 return -ENODEV;
1110 1110
1111 /* configure the OTG */ 1111 /* configure the OTG */
@@ -1137,7 +1137,7 @@ static int fsl_otg_probe(struct platform_device *pdev)
1137 1137
1138static int fsl_otg_remove(struct platform_device *pdev) 1138static int fsl_otg_remove(struct platform_device *pdev)
1139{ 1139{
1140 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 1140 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
1141 1141
1142 usb_remove_phy(&fsl_otg_dev->phy); 1142 usb_remove_phy(&fsl_otg_dev->phy);
1143 free_irq(fsl_otg_dev->irq, fsl_otg_dev); 1143 free_irq(fsl_otg_dev->irq, fsl_otg_dev);
diff --git a/drivers/usb/phy/phy-fsm-usb.h b/drivers/usb/phy/phy-fsm-usb.h
index c30a2e1d9e46..fbe586206f33 100644
--- a/drivers/usb/phy/phy-fsm-usb.h
+++ b/drivers/usb/phy/phy-fsm-usb.h
@@ -15,18 +15,11 @@
15 * 675 Mass Ave, Cambridge, MA 02139, USA. 15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */ 16 */
17 17
18#undef DEBUG
19#undef VERBOSE 18#undef VERBOSE
20 19
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 20#ifdef VERBOSE
29#define VDBG DBG 21#define VDBG(fmt, args...) pr_debug("[%s] " fmt , \
22 __func__, ## args)
30#else 23#else
31#define VDBG(stuff...) do {} while (0) 24#define VDBG(stuff...) do {} while (0)
32#endif 25#endif
diff --git a/drivers/usb/phy/phy-nop.c b/drivers/usb/phy/phy-generic.c
index 55445e5d72e5..efe59f3f7fda 100644
--- a/drivers/usb/phy/phy-nop.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -30,19 +30,13 @@
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/dma-mapping.h> 31#include <linux/dma-mapping.h>
32#include <linux/usb/otg.h> 32#include <linux/usb/otg.h>
33#include <linux/usb/nop-usb-xceiv.h> 33#include <linux/usb/usb_phy_gen_xceiv.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/regulator/consumer.h> 36#include <linux/regulator/consumer.h>
37#include <linux/of.h> 37#include <linux/of.h>
38 38
39struct nop_usb_xceiv { 39#include "phy-generic.h"
40 struct usb_phy phy;
41 struct device *dev;
42 struct clk *clk;
43 struct regulator *vcc;
44 struct regulator *reset;
45};
46 40
47static struct platform_device *pd; 41static struct platform_device *pd;
48 42
@@ -50,9 +44,9 @@ void usb_nop_xceiv_register(void)
50{ 44{
51 if (pd) 45 if (pd)
52 return; 46 return;
53 pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0); 47 pd = platform_device_register_simple("usb_phy_gen_xceiv", -1, NULL, 0);
54 if (!pd) { 48 if (!pd) {
55 printk(KERN_ERR "Unable to register usb nop transceiver\n"); 49 pr_err("Unable to register generic usb transceiver\n");
56 return; 50 return;
57 } 51 }
58} 52}
@@ -70,9 +64,9 @@ static int nop_set_suspend(struct usb_phy *x, int suspend)
70 return 0; 64 return 0;
71} 65}
72 66
73static int nop_init(struct usb_phy *phy) 67int usb_gen_phy_init(struct usb_phy *phy)
74{ 68{
75 struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev); 69 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
76 70
77 if (!IS_ERR(nop->vcc)) { 71 if (!IS_ERR(nop->vcc)) {
78 if (regulator_enable(nop->vcc)) 72 if (regulator_enable(nop->vcc))
@@ -90,10 +84,11 @@ static int nop_init(struct usb_phy *phy)
90 84
91 return 0; 85 return 0;
92} 86}
87EXPORT_SYMBOL_GPL(usb_gen_phy_init);
93 88
94static void nop_shutdown(struct usb_phy *phy) 89void usb_gen_phy_shutdown(struct usb_phy *phy)
95{ 90{
96 struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev); 91 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
97 92
98 if (!IS_ERR(nop->reset)) { 93 if (!IS_ERR(nop->reset)) {
99 /* Assert RESET */ 94 /* Assert RESET */
@@ -109,6 +104,7 @@ static void nop_shutdown(struct usb_phy *phy)
109 dev_err(phy->dev, "Failed to disable power\n"); 104 dev_err(phy->dev, "Failed to disable power\n");
110 } 105 }
111} 106}
107EXPORT_SYMBOL_GPL(usb_gen_phy_shutdown);
112 108
113static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) 109static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
114{ 110{
@@ -139,52 +135,27 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
139 return 0; 135 return 0;
140} 136}
141 137
142static int nop_usb_xceiv_probe(struct platform_device *pdev) 138int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
139 enum usb_phy_type type, u32 clk_rate, bool needs_vcc,
140 bool needs_reset)
143{ 141{
144 struct device *dev = &pdev->dev;
145 struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data;
146 struct nop_usb_xceiv *nop;
147 enum usb_phy_type type = USB_PHY_TYPE_USB2;
148 int err; 142 int err;
149 u32 clk_rate = 0;
150 bool needs_vcc = false;
151 bool needs_reset = false;
152
153 nop = devm_kzalloc(&pdev->dev, sizeof(*nop), GFP_KERNEL);
154 if (!nop)
155 return -ENOMEM;
156 143
157 nop->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*nop->phy.otg), 144 nop->phy.otg = devm_kzalloc(dev, sizeof(*nop->phy.otg),
158 GFP_KERNEL); 145 GFP_KERNEL);
159 if (!nop->phy.otg) 146 if (!nop->phy.otg)
160 return -ENOMEM; 147 return -ENOMEM;
161 148
162 if (dev->of_node) { 149 nop->clk = devm_clk_get(dev, "main_clk");
163 struct device_node *node = dev->of_node;
164
165 if (of_property_read_u32(node, "clock-frequency", &clk_rate))
166 clk_rate = 0;
167
168 needs_vcc = of_property_read_bool(node, "vcc-supply");
169 needs_reset = of_property_read_bool(node, "reset-supply");
170
171 } else if (pdata) {
172 type = pdata->type;
173 clk_rate = pdata->clk_rate;
174 needs_vcc = pdata->needs_vcc;
175 needs_reset = pdata->needs_reset;
176 }
177
178 nop->clk = devm_clk_get(&pdev->dev, "main_clk");
179 if (IS_ERR(nop->clk)) { 150 if (IS_ERR(nop->clk)) {
180 dev_dbg(&pdev->dev, "Can't get phy clock: %ld\n", 151 dev_dbg(dev, "Can't get phy clock: %ld\n",
181 PTR_ERR(nop->clk)); 152 PTR_ERR(nop->clk));
182 } 153 }
183 154
184 if (!IS_ERR(nop->clk) && clk_rate) { 155 if (!IS_ERR(nop->clk) && clk_rate) {
185 err = clk_set_rate(nop->clk, clk_rate); 156 err = clk_set_rate(nop->clk, clk_rate);
186 if (err) { 157 if (err) {
187 dev_err(&pdev->dev, "Error setting clock rate\n"); 158 dev_err(dev, "Error setting clock rate\n");
188 return err; 159 return err;
189 } 160 }
190 } 161 }
@@ -192,33 +163,31 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
192 if (!IS_ERR(nop->clk)) { 163 if (!IS_ERR(nop->clk)) {
193 err = clk_prepare(nop->clk); 164 err = clk_prepare(nop->clk);
194 if (err) { 165 if (err) {
195 dev_err(&pdev->dev, "Error preparing clock\n"); 166 dev_err(dev, "Error preparing clock\n");
196 return err; 167 return err;
197 } 168 }
198 } 169 }
199 170
200 nop->vcc = devm_regulator_get(&pdev->dev, "vcc"); 171 nop->vcc = devm_regulator_get(dev, "vcc");
201 if (IS_ERR(nop->vcc)) { 172 if (IS_ERR(nop->vcc)) {
202 dev_dbg(&pdev->dev, "Error getting vcc regulator: %ld\n", 173 dev_dbg(dev, "Error getting vcc regulator: %ld\n",
203 PTR_ERR(nop->vcc)); 174 PTR_ERR(nop->vcc));
204 if (needs_vcc) 175 if (needs_vcc)
205 return -EPROBE_DEFER; 176 return -EPROBE_DEFER;
206 } 177 }
207 178
208 nop->reset = devm_regulator_get(&pdev->dev, "reset"); 179 nop->reset = devm_regulator_get(dev, "reset");
209 if (IS_ERR(nop->reset)) { 180 if (IS_ERR(nop->reset)) {
210 dev_dbg(&pdev->dev, "Error getting reset regulator: %ld\n", 181 dev_dbg(dev, "Error getting reset regulator: %ld\n",
211 PTR_ERR(nop->reset)); 182 PTR_ERR(nop->reset));
212 if (needs_reset) 183 if (needs_reset)
213 return -EPROBE_DEFER; 184 return -EPROBE_DEFER;
214 } 185 }
215 186
216 nop->dev = &pdev->dev; 187 nop->dev = dev;
217 nop->phy.dev = nop->dev; 188 nop->phy.dev = nop->dev;
218 nop->phy.label = "nop-xceiv"; 189 nop->phy.label = "nop-xceiv";
219 nop->phy.set_suspend = nop_set_suspend; 190 nop->phy.set_suspend = nop_set_suspend;
220 nop->phy.init = nop_init;
221 nop->phy.shutdown = nop_shutdown;
222 nop->phy.state = OTG_STATE_UNDEFINED; 191 nop->phy.state = OTG_STATE_UNDEFINED;
223 nop->phy.type = type; 192 nop->phy.type = type;
224 193
@@ -226,6 +195,59 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
226 nop->phy.otg->set_host = nop_set_host; 195 nop->phy.otg->set_host = nop_set_host;
227 nop->phy.otg->set_peripheral = nop_set_peripheral; 196 nop->phy.otg->set_peripheral = nop_set_peripheral;
228 197
198 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
199 return 0;
200}
201EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy);
202
203void usb_phy_gen_cleanup_phy(struct usb_phy_gen_xceiv *nop)
204{
205 if (!IS_ERR(nop->clk))
206 clk_unprepare(nop->clk);
207}
208EXPORT_SYMBOL_GPL(usb_phy_gen_cleanup_phy);
209
210static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
211{
212 struct device *dev = &pdev->dev;
213 struct usb_phy_gen_xceiv_platform_data *pdata =
214 dev_get_platdata(&pdev->dev);
215 struct usb_phy_gen_xceiv *nop;
216 enum usb_phy_type type = USB_PHY_TYPE_USB2;
217 int err;
218 u32 clk_rate = 0;
219 bool needs_vcc = false;
220 bool needs_reset = false;
221
222 if (dev->of_node) {
223 struct device_node *node = dev->of_node;
224
225 if (of_property_read_u32(node, "clock-frequency", &clk_rate))
226 clk_rate = 0;
227
228 needs_vcc = of_property_read_bool(node, "vcc-supply");
229 needs_reset = of_property_read_bool(node, "reset-supply");
230
231 } else if (pdata) {
232 type = pdata->type;
233 clk_rate = pdata->clk_rate;
234 needs_vcc = pdata->needs_vcc;
235 needs_reset = pdata->needs_reset;
236 }
237
238 nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL);
239 if (!nop)
240 return -ENOMEM;
241
242
243 err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc,
244 needs_reset);
245 if (err)
246 return err;
247
248 nop->phy.init = usb_gen_phy_init;
249 nop->phy.shutdown = usb_gen_phy_shutdown;
250
229 err = usb_add_phy_dev(&nop->phy); 251 err = usb_add_phy_dev(&nop->phy);
230 if (err) { 252 if (err) {
231 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 253 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
@@ -235,23 +257,18 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
235 257
236 platform_set_drvdata(pdev, nop); 258 platform_set_drvdata(pdev, nop);
237 259
238 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
239
240 return 0; 260 return 0;
241 261
242err_add: 262err_add:
243 if (!IS_ERR(nop->clk)) 263 usb_phy_gen_cleanup_phy(nop);
244 clk_unprepare(nop->clk);
245 return err; 264 return err;
246} 265}
247 266
248static int nop_usb_xceiv_remove(struct platform_device *pdev) 267static int usb_phy_gen_xceiv_remove(struct platform_device *pdev)
249{ 268{
250 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev); 269 struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev);
251
252 if (!IS_ERR(nop->clk))
253 clk_unprepare(nop->clk);
254 270
271 usb_phy_gen_cleanup_phy(nop);
255 usb_remove_phy(&nop->phy); 272 usb_remove_phy(&nop->phy);
256 273
257 return 0; 274 return 0;
@@ -264,29 +281,29 @@ static const struct of_device_id nop_xceiv_dt_ids[] = {
264 281
265MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids); 282MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids);
266 283
267static struct platform_driver nop_usb_xceiv_driver = { 284static struct platform_driver usb_phy_gen_xceiv_driver = {
268 .probe = nop_usb_xceiv_probe, 285 .probe = usb_phy_gen_xceiv_probe,
269 .remove = nop_usb_xceiv_remove, 286 .remove = usb_phy_gen_xceiv_remove,
270 .driver = { 287 .driver = {
271 .name = "nop_usb_xceiv", 288 .name = "usb_phy_gen_xceiv",
272 .owner = THIS_MODULE, 289 .owner = THIS_MODULE,
273 .of_match_table = nop_xceiv_dt_ids, 290 .of_match_table = nop_xceiv_dt_ids,
274 }, 291 },
275}; 292};
276 293
277static int __init nop_usb_xceiv_init(void) 294static int __init usb_phy_gen_xceiv_init(void)
278{ 295{
279 return platform_driver_register(&nop_usb_xceiv_driver); 296 return platform_driver_register(&usb_phy_gen_xceiv_driver);
280} 297}
281subsys_initcall(nop_usb_xceiv_init); 298subsys_initcall(usb_phy_gen_xceiv_init);
282 299
283static void __exit nop_usb_xceiv_exit(void) 300static void __exit usb_phy_gen_xceiv_exit(void)
284{ 301{
285 platform_driver_unregister(&nop_usb_xceiv_driver); 302 platform_driver_unregister(&usb_phy_gen_xceiv_driver);
286} 303}
287module_exit(nop_usb_xceiv_exit); 304module_exit(usb_phy_gen_xceiv_exit);
288 305
289MODULE_ALIAS("platform:nop_usb_xceiv"); 306MODULE_ALIAS("platform:usb_phy_gen_xceiv");
290MODULE_AUTHOR("Texas Instruments Inc"); 307MODULE_AUTHOR("Texas Instruments Inc");
291MODULE_DESCRIPTION("NOP USB Transceiver driver"); 308MODULE_DESCRIPTION("NOP USB Transceiver driver");
292MODULE_LICENSE("GPL"); 309MODULE_LICENSE("GPL");
diff --git a/drivers/usb/phy/phy-generic.h b/drivers/usb/phy/phy-generic.h
new file mode 100644
index 000000000000..61687d5a965b
--- /dev/null
+++ b/drivers/usb/phy/phy-generic.h
@@ -0,0 +1,20 @@
1#ifndef _PHY_GENERIC_H_
2#define _PHY_GENERIC_H_
3
4struct usb_phy_gen_xceiv {
5 struct usb_phy phy;
6 struct device *dev;
7 struct clk *clk;
8 struct regulator *vcc;
9 struct regulator *reset;
10};
11
12int usb_gen_phy_init(struct usb_phy *phy);
13void usb_gen_phy_shutdown(struct usb_phy *phy);
14
15int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
16 enum usb_phy_type type, u32 clk_rate, bool needs_vcc,
17 bool needs_reset);
18void usb_phy_gen_cleanup_phy(struct usb_phy_gen_xceiv *nop);
19
20#endif
diff --git a/drivers/usb/phy/phy-gpio-vbus-usb.c b/drivers/usb/phy/phy-gpio-vbus-usb.c
index 8443335c2ea0..b2f29c9aebbf 100644
--- a/drivers/usb/phy/phy-gpio-vbus-usb.c
+++ b/drivers/usb/phy/phy-gpio-vbus-usb.c
@@ -101,7 +101,7 @@ static void gpio_vbus_work(struct work_struct *work)
101{ 101{
102 struct gpio_vbus_data *gpio_vbus = 102 struct gpio_vbus_data *gpio_vbus =
103 container_of(work, struct gpio_vbus_data, work.work); 103 container_of(work, struct gpio_vbus_data, work.work);
104 struct gpio_vbus_mach_info *pdata = gpio_vbus->dev->platform_data; 104 struct gpio_vbus_mach_info *pdata = dev_get_platdata(gpio_vbus->dev);
105 int gpio, status, vbus; 105 int gpio, status, vbus;
106 106
107 if (!gpio_vbus->phy.otg->gadget) 107 if (!gpio_vbus->phy.otg->gadget)
@@ -155,7 +155,7 @@ static void gpio_vbus_work(struct work_struct *work)
155static irqreturn_t gpio_vbus_irq(int irq, void *data) 155static irqreturn_t gpio_vbus_irq(int irq, void *data)
156{ 156{
157 struct platform_device *pdev = data; 157 struct platform_device *pdev = data;
158 struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; 158 struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev);
159 struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); 159 struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev);
160 struct usb_otg *otg = gpio_vbus->phy.otg; 160 struct usb_otg *otg = gpio_vbus->phy.otg;
161 161
@@ -182,7 +182,7 @@ static int gpio_vbus_set_peripheral(struct usb_otg *otg,
182 182
183 gpio_vbus = container_of(otg->phy, struct gpio_vbus_data, phy); 183 gpio_vbus = container_of(otg->phy, struct gpio_vbus_data, phy);
184 pdev = to_platform_device(gpio_vbus->dev); 184 pdev = to_platform_device(gpio_vbus->dev);
185 pdata = gpio_vbus->dev->platform_data; 185 pdata = dev_get_platdata(gpio_vbus->dev);
186 gpio = pdata->gpio_pullup; 186 gpio = pdata->gpio_pullup;
187 187
188 if (!gadget) { 188 if (!gadget) {
@@ -243,7 +243,7 @@ static int gpio_vbus_set_suspend(struct usb_phy *phy, int suspend)
243 243
244static int __init gpio_vbus_probe(struct platform_device *pdev) 244static int __init gpio_vbus_probe(struct platform_device *pdev)
245{ 245{
246 struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; 246 struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev);
247 struct gpio_vbus_data *gpio_vbus; 247 struct gpio_vbus_data *gpio_vbus;
248 struct resource *res; 248 struct resource *res;
249 int err, gpio, irq; 249 int err, gpio, irq;
@@ -352,7 +352,7 @@ err_gpio:
352static int __exit gpio_vbus_remove(struct platform_device *pdev) 352static int __exit gpio_vbus_remove(struct platform_device *pdev)
353{ 353{
354 struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); 354 struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev);
355 struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; 355 struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev);
356 int gpio = pdata->gpio_vbus; 356 int gpio = pdata->gpio_vbus;
357 357
358 device_init_wakeup(&pdev->dev, 0); 358 device_init_wakeup(&pdev->dev, 0);
diff --git a/drivers/usb/phy/phy-isp1301-omap.c b/drivers/usb/phy/phy-isp1301-omap.c
index ae481afcb3ec..d3a5160e4cc7 100644
--- a/drivers/usb/phy/phy-isp1301-omap.c
+++ b/drivers/usb/phy/phy-isp1301-omap.c
@@ -40,9 +40,7 @@
40 40
41#include <mach/usb.h> 41#include <mach/usb.h>
42 42
43#ifndef DEBUG 43#undef VERBOSE
44#undef VERBOSE
45#endif
46 44
47 45
48#define DRIVER_VERSION "24 August 2004" 46#define DRIVER_VERSION "24 August 2004"
@@ -387,7 +385,6 @@ static void b_idle(struct isp1301 *isp, const char *tag)
387static void 385static void
388dump_regs(struct isp1301 *isp, const char *label) 386dump_regs(struct isp1301 *isp, const char *label)
389{ 387{
390#ifdef DEBUG
391 u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1); 388 u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1);
392 u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS); 389 u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
393 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE); 390 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
@@ -396,7 +393,6 @@ dump_regs(struct isp1301 *isp, const char *label)
396 omap_readl(OTG_CTRL), label, state_name(isp), 393 omap_readl(OTG_CTRL), label, state_name(isp),
397 ctrl, status, src); 394 ctrl, status, src);
398 /* mode control and irq enables don't change much */ 395 /* mode control and irq enables don't change much */
399#endif
400} 396}
401 397
402/*-------------------------------------------------------------------------*/ 398/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index d08f33435e96..e9d4cd960ecd 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1419,7 +1419,7 @@ static int __init msm_otg_probe(struct platform_device *pdev)
1419 struct usb_phy *phy; 1419 struct usb_phy *phy;
1420 1420
1421 dev_info(&pdev->dev, "msm_otg probe\n"); 1421 dev_info(&pdev->dev, "msm_otg probe\n");
1422 if (!pdev->dev.platform_data) { 1422 if (!dev_get_platdata(&pdev->dev)) {
1423 dev_err(&pdev->dev, "No platform data given. Bailing out\n"); 1423 dev_err(&pdev->dev, "No platform data given. Bailing out\n");
1424 return -ENODEV; 1424 return -ENODEV;
1425 } 1425 }
@@ -1436,7 +1436,7 @@ static int __init msm_otg_probe(struct platform_device *pdev)
1436 return -ENOMEM; 1436 return -ENOMEM;
1437 } 1437 }
1438 1438
1439 motg->pdata = pdev->dev.platform_data; 1439 motg->pdata = dev_get_platdata(&pdev->dev);
1440 phy = &motg->phy; 1440 phy = &motg->phy;
1441 phy->dev = &pdev->dev; 1441 phy->dev = &pdev->dev;
1442 1442
diff --git a/drivers/usb/phy/phy-mv-u3d-usb.c b/drivers/usb/phy/phy-mv-u3d-usb.c
index 1568ea63e338..d317903022bf 100644
--- a/drivers/usb/phy/phy-mv-u3d-usb.c
+++ b/drivers/usb/phy/phy-mv-u3d-usb.c
@@ -82,7 +82,7 @@ static void mv_u3d_phy_write(void __iomem *base, u32 reg, u32 value)
82 writel_relaxed(value, data); 82 writel_relaxed(value, data);
83} 83}
84 84
85void mv_u3d_phy_shutdown(struct usb_phy *phy) 85static void mv_u3d_phy_shutdown(struct usb_phy *phy)
86{ 86{
87 struct mv_u3d_phy *mv_u3d_phy; 87 struct mv_u3d_phy *mv_u3d_phy;
88 void __iomem *base; 88 void __iomem *base;
@@ -271,7 +271,7 @@ static int mv_u3d_phy_probe(struct platform_device *pdev)
271 void __iomem *phy_base; 271 void __iomem *phy_base;
272 int ret; 272 int ret;
273 273
274 pdata = pdev->dev.platform_data; 274 pdata = dev_get_platdata(&pdev->dev);
275 if (!pdata) { 275 if (!pdata) {
276 dev_err(&pdev->dev, "%s: no platform data defined\n", __func__); 276 dev_err(&pdev->dev, "%s: no platform data defined\n", __func__);
277 return -EINVAL; 277 return -EINVAL;
diff --git a/drivers/usb/phy/phy-mv-usb.c b/drivers/usb/phy/phy-mv-usb.c
index 4a6b03c73876..98f6ac6a78ea 100644
--- a/drivers/usb/phy/phy-mv-usb.c
+++ b/drivers/usb/phy/phy-mv-usb.c
@@ -653,7 +653,7 @@ static struct attribute_group inputs_attr_group = {
653 .attrs = inputs_attrs, 653 .attrs = inputs_attrs,
654}; 654};
655 655
656int mv_otg_remove(struct platform_device *pdev) 656static int mv_otg_remove(struct platform_device *pdev)
657{ 657{
658 struct mv_otg *mvotg = platform_get_drvdata(pdev); 658 struct mv_otg *mvotg = platform_get_drvdata(pdev);
659 659
@@ -673,7 +673,7 @@ int mv_otg_remove(struct platform_device *pdev)
673 673
674static int mv_otg_probe(struct platform_device *pdev) 674static int mv_otg_probe(struct platform_device *pdev)
675{ 675{
676 struct mv_usb_platform_data *pdata = pdev->dev.platform_data; 676 struct mv_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
677 struct mv_otg *mvotg; 677 struct mv_otg *mvotg;
678 struct usb_otg *otg; 678 struct usb_otg *otg;
679 struct resource *r; 679 struct resource *r;
@@ -893,7 +893,7 @@ static int mv_otg_resume(struct platform_device *pdev)
893 893
894static struct platform_driver mv_otg_driver = { 894static struct platform_driver mv_otg_driver = {
895 .probe = mv_otg_probe, 895 .probe = mv_otg_probe,
896 .remove = __exit_p(mv_otg_remove), 896 .remove = mv_otg_remove,
897 .driver = { 897 .driver = {
898 .owner = THIS_MODULE, 898 .owner = THIS_MODULE,
899 .name = driver_name, 899 .name = driver_name,
diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c
index bd601c537c8d..fdd33b44dbd3 100644
--- a/drivers/usb/phy/phy-mxs-usb.c
+++ b/drivers/usb/phy/phy-mxs-usb.c
@@ -41,11 +41,14 @@ struct mxs_phy {
41 41
42#define to_mxs_phy(p) container_of((p), struct mxs_phy, phy) 42#define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
43 43
44static void mxs_phy_hw_init(struct mxs_phy *mxs_phy) 44static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
45{ 45{
46 int ret;
46 void __iomem *base = mxs_phy->phy.io_priv; 47 void __iomem *base = mxs_phy->phy.io_priv;
47 48
48 stmp_reset_block(base + HW_USBPHY_CTRL); 49 ret = stmp_reset_block(base + HW_USBPHY_CTRL);
50 if (ret)
51 return ret;
49 52
50 /* Power up the PHY */ 53 /* Power up the PHY */
51 writel(0, base + HW_USBPHY_PWD); 54 writel(0, base + HW_USBPHY_PWD);
@@ -54,6 +57,8 @@ static void mxs_phy_hw_init(struct mxs_phy *mxs_phy)
54 writel(BM_USBPHY_CTRL_ENUTMILEVEL2 | 57 writel(BM_USBPHY_CTRL_ENUTMILEVEL2 |
55 BM_USBPHY_CTRL_ENUTMILEVEL3, 58 BM_USBPHY_CTRL_ENUTMILEVEL3,
56 base + HW_USBPHY_CTRL_SET); 59 base + HW_USBPHY_CTRL_SET);
60
61 return 0;
57} 62}
58 63
59static int mxs_phy_init(struct usb_phy *phy) 64static int mxs_phy_init(struct usb_phy *phy)
@@ -61,9 +66,7 @@ static int mxs_phy_init(struct usb_phy *phy)
61 struct mxs_phy *mxs_phy = to_mxs_phy(phy); 66 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
62 67
63 clk_prepare_enable(mxs_phy->clk); 68 clk_prepare_enable(mxs_phy->clk);
64 mxs_phy_hw_init(mxs_phy); 69 return mxs_phy_hw_init(mxs_phy);
65
66 return 0;
67} 70}
68 71
69static void mxs_phy_shutdown(struct usb_phy *phy) 72static void mxs_phy_shutdown(struct usb_phy *phy)
diff --git a/drivers/usb/phy/phy-omap-control.c b/drivers/usb/phy/phy-omap-control.c
index 1419ceda9759..a4dda8e12562 100644
--- a/drivers/usb/phy/phy-omap-control.c
+++ b/drivers/usb/phy/phy-omap-control.c
@@ -197,7 +197,8 @@ static int omap_control_usb_probe(struct platform_device *pdev)
197{ 197{
198 struct resource *res; 198 struct resource *res;
199 struct device_node *np = pdev->dev.of_node; 199 struct device_node *np = pdev->dev.of_node;
200 struct omap_control_usb_platform_data *pdata = pdev->dev.platform_data; 200 struct omap_control_usb_platform_data *pdata =
201 dev_get_platdata(&pdev->dev);
201 202
202 control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb), 203 control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),
203 GFP_KERNEL); 204 GFP_KERNEL);
diff --git a/drivers/usb/phy/phy-omap-usb3.c b/drivers/usb/phy/phy-omap-usb3.c
index a2fb30bbb971..fc15694d3031 100644
--- a/drivers/usb/phy/phy-omap-usb3.c
+++ b/drivers/usb/phy/phy-omap-usb3.c
@@ -27,7 +27,6 @@
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/usb/omap_control_usb.h> 28#include <linux/usb/omap_control_usb.h>
29 29
30#define NUM_SYS_CLKS 6
31#define PLL_STATUS 0x00000004 30#define PLL_STATUS 0x00000004
32#define PLL_GO 0x00000008 31#define PLL_GO 0x00000008
33#define PLL_CONFIGURATION1 0x0000000C 32#define PLL_CONFIGURATION1 0x0000000C
@@ -57,26 +56,32 @@
57 */ 56 */
58# define PLL_IDLE_TIME 100; 57# define PLL_IDLE_TIME 100;
59 58
60enum sys_clk_rate { 59struct usb_dpll_map {
61 CLK_RATE_UNDEFINED = -1, 60 unsigned long rate;
62 CLK_RATE_12MHZ, 61 struct usb_dpll_params params;
63 CLK_RATE_16MHZ,
64 CLK_RATE_19MHZ,
65 CLK_RATE_20MHZ,
66 CLK_RATE_26MHZ,
67 CLK_RATE_38MHZ
68}; 62};
69 63
70static struct usb_dpll_params omap_usb3_dpll_params[NUM_SYS_CLKS] = { 64static struct usb_dpll_map dpll_map[] = {
71 {1250, 5, 4, 20, 0}, /* 12 MHz */ 65 {12000000, {1250, 5, 4, 20, 0} }, /* 12 MHz */
72 {3125, 20, 4, 20, 0}, /* 16.8 MHz */ 66 {16800000, {3125, 20, 4, 20, 0} }, /* 16.8 MHz */
73 {1172, 8, 4, 20, 65537}, /* 19.2 MHz */ 67 {19200000, {1172, 8, 4, 20, 65537} }, /* 19.2 MHz */
74 {1000, 7, 4, 10, 0}, /* 20 MHz */ 68 {20000000, {1000, 7, 4, 10, 0} }, /* 20 MHz */
75 {1250, 12, 4, 20, 0}, /* 26 MHz */ 69 {26000000, {1250, 12, 4, 20, 0} }, /* 26 MHz */
76 {3125, 47, 4, 20, 92843}, /* 38.4 MHz */ 70 {38400000, {3125, 47, 4, 20, 92843} }, /* 38.4 MHz */
77
78}; 71};
79 72
73static struct usb_dpll_params *omap_usb3_get_dpll_params(unsigned long rate)
74{
75 int i;
76
77 for (i = 0; i < ARRAY_SIZE(dpll_map); i++) {
78 if (rate == dpll_map[i].rate)
79 return &dpll_map[i].params;
80 }
81
82 return 0;
83}
84
80static int omap_usb3_suspend(struct usb_phy *x, int suspend) 85static int omap_usb3_suspend(struct usb_phy *x, int suspend)
81{ 86{
82 struct omap_usb *phy = phy_to_omapusb(x); 87 struct omap_usb *phy = phy_to_omapusb(x);
@@ -116,26 +121,6 @@ static int omap_usb3_suspend(struct usb_phy *x, int suspend)
116 return 0; 121 return 0;
117} 122}
118 123
119static inline enum sys_clk_rate __get_sys_clk_index(unsigned long rate)
120{
121 switch (rate) {
122 case 12000000:
123 return CLK_RATE_12MHZ;
124 case 16800000:
125 return CLK_RATE_16MHZ;
126 case 19200000:
127 return CLK_RATE_19MHZ;
128 case 20000000:
129 return CLK_RATE_20MHZ;
130 case 26000000:
131 return CLK_RATE_26MHZ;
132 case 38400000:
133 return CLK_RATE_38MHZ;
134 default:
135 return CLK_RATE_UNDEFINED;
136 }
137}
138
139static void omap_usb_dpll_relock(struct omap_usb *phy) 124static void omap_usb_dpll_relock(struct omap_usb *phy)
140{ 125{
141 u32 val; 126 u32 val;
@@ -155,39 +140,39 @@ static int omap_usb_dpll_lock(struct omap_usb *phy)
155{ 140{
156 u32 val; 141 u32 val;
157 unsigned long rate; 142 unsigned long rate;
158 enum sys_clk_rate clk_index; 143 struct usb_dpll_params *dpll_params;
159
160 rate = clk_get_rate(phy->sys_clk);
161 clk_index = __get_sys_clk_index(rate);
162 144
163 if (clk_index == CLK_RATE_UNDEFINED) { 145 rate = clk_get_rate(phy->sys_clk);
164 pr_err("dpll cannot be locked for sys clk freq:%luHz\n", rate); 146 dpll_params = omap_usb3_get_dpll_params(rate);
147 if (!dpll_params) {
148 dev_err(phy->dev,
149 "No DPLL configuration for %lu Hz SYS CLK\n", rate);
165 return -EINVAL; 150 return -EINVAL;
166 } 151 }
167 152
168 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1); 153 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1);
169 val &= ~PLL_REGN_MASK; 154 val &= ~PLL_REGN_MASK;
170 val |= omap_usb3_dpll_params[clk_index].n << PLL_REGN_SHIFT; 155 val |= dpll_params->n << PLL_REGN_SHIFT;
171 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val); 156 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val);
172 157
173 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2); 158 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2);
174 val &= ~PLL_SELFREQDCO_MASK; 159 val &= ~PLL_SELFREQDCO_MASK;
175 val |= omap_usb3_dpll_params[clk_index].freq << PLL_SELFREQDCO_SHIFT; 160 val |= dpll_params->freq << PLL_SELFREQDCO_SHIFT;
176 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val); 161 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val);
177 162
178 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1); 163 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1);
179 val &= ~PLL_REGM_MASK; 164 val &= ~PLL_REGM_MASK;
180 val |= omap_usb3_dpll_params[clk_index].m << PLL_REGM_SHIFT; 165 val |= dpll_params->m << PLL_REGM_SHIFT;
181 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val); 166 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val);
182 167
183 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION4); 168 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION4);
184 val &= ~PLL_REGM_F_MASK; 169 val &= ~PLL_REGM_F_MASK;
185 val |= omap_usb3_dpll_params[clk_index].mf << PLL_REGM_F_SHIFT; 170 val |= dpll_params->mf << PLL_REGM_F_SHIFT;
186 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION4, val); 171 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION4, val);
187 172
188 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION3); 173 val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION3);
189 val &= ~PLL_SD_MASK; 174 val &= ~PLL_SD_MASK;
190 val |= omap_usb3_dpll_params[clk_index].sd << PLL_SD_SHIFT; 175 val |= dpll_params->sd << PLL_SD_SHIFT;
191 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION3, val); 176 omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION3, val);
192 177
193 omap_usb_dpll_relock(phy); 178 omap_usb_dpll_relock(phy);
@@ -198,8 +183,12 @@ static int omap_usb_dpll_lock(struct omap_usb *phy)
198static int omap_usb3_init(struct usb_phy *x) 183static int omap_usb3_init(struct usb_phy *x)
199{ 184{
200 struct omap_usb *phy = phy_to_omapusb(x); 185 struct omap_usb *phy = phy_to_omapusb(x);
186 int ret;
187
188 ret = omap_usb_dpll_lock(phy);
189 if (ret)
190 return ret;
201 191
202 omap_usb_dpll_lock(phy);
203 omap_control_usb3_phy_power(phy->control_dev, 1); 192 omap_control_usb3_phy_power(phy->control_dev, 1);
204 193
205 return 0; 194 return 0;
diff --git a/drivers/usb/phy/phy-rcar-usb.c b/drivers/usb/phy/phy-rcar-usb.c
index ae909408958d..33265a5b2cdf 100644
--- a/drivers/usb/phy/phy-rcar-usb.c
+++ b/drivers/usb/phy/phy-rcar-usb.c
@@ -83,7 +83,7 @@ static int rcar_usb_phy_init(struct usb_phy *phy)
83{ 83{
84 struct rcar_usb_phy_priv *priv = usb_phy_to_priv(phy); 84 struct rcar_usb_phy_priv *priv = usb_phy_to_priv(phy);
85 struct device *dev = phy->dev; 85 struct device *dev = phy->dev;
86 struct rcar_phy_platform_data *pdata = dev->platform_data; 86 struct rcar_phy_platform_data *pdata = dev_get_platdata(dev);
87 void __iomem *reg0 = priv->reg0; 87 void __iomem *reg0 = priv->reg0;
88 void __iomem *reg1 = priv->reg1; 88 void __iomem *reg1 = priv->reg1;
89 static const u8 ovcn_act[] = { OVC0_ACT, OVC1_ACT, OVC2_ACT }; 89 static const u8 ovcn_act[] = { OVC0_ACT, OVC1_ACT, OVC2_ACT };
@@ -184,17 +184,12 @@ static int rcar_usb_phy_probe(struct platform_device *pdev)
184 void __iomem *reg0, *reg1 = NULL; 184 void __iomem *reg0, *reg1 = NULL;
185 int ret; 185 int ret;
186 186
187 if (!pdev->dev.platform_data) { 187 if (!dev_get_platdata(&pdev->dev)) {
188 dev_err(dev, "No platform data\n"); 188 dev_err(dev, "No platform data\n");
189 return -EINVAL; 189 return -EINVAL;
190 } 190 }
191 191
192 res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0); 192 res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
193 if (!res0) {
194 dev_err(dev, "Not enough platform resources\n");
195 return -EINVAL;
196 }
197
198 reg0 = devm_ioremap_resource(dev, res0); 193 reg0 = devm_ioremap_resource(dev, res0);
199 if (IS_ERR(reg0)) 194 if (IS_ERR(reg0))
200 return PTR_ERR(reg0); 195 return PTR_ERR(reg0);
diff --git a/drivers/usb/phy/phy-samsung-usb2.c b/drivers/usb/phy/phy-samsung-usb2.c
index 758b86d0fcb3..ff70e4b19b97 100644
--- a/drivers/usb/phy/phy-samsung-usb2.c
+++ b/drivers/usb/phy/phy-samsung-usb2.c
@@ -359,7 +359,7 @@ static int samsung_usb2phy_probe(struct platform_device *pdev)
359{ 359{
360 struct samsung_usbphy *sphy; 360 struct samsung_usbphy *sphy;
361 struct usb_otg *otg; 361 struct usb_otg *otg;
362 struct samsung_usbphy_data *pdata = pdev->dev.platform_data; 362 struct samsung_usbphy_data *pdata = dev_get_platdata(&pdev->dev);
363 const struct samsung_usbphy_drvdata *drv_data; 363 const struct samsung_usbphy_drvdata *drv_data;
364 struct device *dev = &pdev->dev; 364 struct device *dev = &pdev->dev;
365 struct resource *phy_mem; 365 struct resource *phy_mem;
diff --git a/drivers/usb/phy/phy-samsung-usb3.c b/drivers/usb/phy/phy-samsung-usb3.c
index 300e0cf5e31f..c6eb22213de6 100644
--- a/drivers/usb/phy/phy-samsung-usb3.c
+++ b/drivers/usb/phy/phy-samsung-usb3.c
@@ -231,7 +231,7 @@ static void samsung_usb3phy_shutdown(struct usb_phy *phy)
231static int samsung_usb3phy_probe(struct platform_device *pdev) 231static int samsung_usb3phy_probe(struct platform_device *pdev)
232{ 232{
233 struct samsung_usbphy *sphy; 233 struct samsung_usbphy *sphy;
234 struct samsung_usbphy_data *pdata = pdev->dev.platform_data; 234 struct samsung_usbphy_data *pdata = dev_get_platdata(&pdev->dev);
235 struct device *dev = &pdev->dev; 235 struct device *dev = &pdev->dev;
236 struct resource *phy_mem; 236 struct resource *phy_mem;
237 void __iomem *phy_base; 237 void __iomem *phy_base;
diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
index cec0855ed248..3bfb3d1957c1 100644
--- a/drivers/usb/phy/phy-tegra-usb.c
+++ b/drivers/usb/phy/phy-tegra-usb.c
@@ -28,20 +28,28 @@
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/gpio.h> 29#include <linux/gpio.h>
30#include <linux/of.h> 30#include <linux/of.h>
31#include <linux/of_device.h>
31#include <linux/of_gpio.h> 32#include <linux/of_gpio.h>
32#include <linux/usb/otg.h> 33#include <linux/usb/otg.h>
33#include <linux/usb/ulpi.h> 34#include <linux/usb/ulpi.h>
35#include <linux/usb/of.h>
34#include <asm/mach-types.h> 36#include <asm/mach-types.h>
35#include <linux/usb/ehci_def.h> 37#include <linux/usb/ehci_def.h>
36#include <linux/usb/tegra_usb_phy.h> 38#include <linux/usb/tegra_usb_phy.h>
39#include <linux/regulator/consumer.h>
37 40
38#define ULPI_VIEWPORT 0x170 41#define ULPI_VIEWPORT 0x170
39 42
40/* PORTSC registers */ 43/* PORTSC PTS/PHCD bits, Tegra20 only */
41#define TEGRA_USB_PORTSC1 0x184 44#define TEGRA_USB_PORTSC1 0x184
42#define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30) 45#define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30)
43#define TEGRA_USB_PORTSC1_PHCD (1 << 23) 46#define TEGRA_USB_PORTSC1_PHCD (1 << 23)
44 47
48/* HOSTPC1 PTS/PHCD bits, Tegra30 and above */
49#define TEGRA_USB_HOSTPC1_DEVLC 0x1b4
50#define TEGRA_USB_HOSTPC1_DEVLC_PTS(x) (((x) & 0x7) << 29)
51#define TEGRA_USB_HOSTPC1_DEVLC_PHCD (1 << 22)
52
45/* Bits of PORTSC1, which will get cleared by writing 1 into them */ 53/* Bits of PORTSC1, which will get cleared by writing 1 into them */
46#define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) 54#define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC)
47 55
@@ -84,16 +92,22 @@
84 92
85#define UTMIP_XCVR_CFG0 0x808 93#define UTMIP_XCVR_CFG0 0x808
86#define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0) 94#define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0)
95#define UTMIP_XCVR_SETUP_MSB(x) ((((x) & 0x70) >> 4) << 22)
87#define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8) 96#define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8)
88#define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10) 97#define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10)
89#define UTMIP_FORCE_PD_POWERDOWN (1 << 14) 98#define UTMIP_FORCE_PD_POWERDOWN (1 << 14)
90#define UTMIP_FORCE_PD2_POWERDOWN (1 << 16) 99#define UTMIP_FORCE_PD2_POWERDOWN (1 << 16)
91#define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18) 100#define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18)
92#define UTMIP_XCVR_HSSLEW_MSB(x) (((x) & 0x7f) << 25) 101#define UTMIP_XCVR_LSBIAS_SEL (1 << 21)
102#define UTMIP_XCVR_HSSLEW(x) (((x) & 0x3) << 4)
103#define UTMIP_XCVR_HSSLEW_MSB(x) ((((x) & 0x1fc) >> 2) << 25)
93 104
94#define UTMIP_BIAS_CFG0 0x80c 105#define UTMIP_BIAS_CFG0 0x80c
95#define UTMIP_OTGPD (1 << 11) 106#define UTMIP_OTGPD (1 << 11)
96#define UTMIP_BIASPD (1 << 10) 107#define UTMIP_BIASPD (1 << 10)
108#define UTMIP_HSSQUELCH_LEVEL(x) (((x) & 0x3) << 0)
109#define UTMIP_HSDISCON_LEVEL(x) (((x) & 0x3) << 2)
110#define UTMIP_HSDISCON_LEVEL_MSB(x) ((((x) & 0x4) >> 2) << 24)
97 111
98#define UTMIP_HSRX_CFG0 0x810 112#define UTMIP_HSRX_CFG0 0x810
99#define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10) 113#define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10)
@@ -137,6 +151,12 @@
137#define UTMIP_BIAS_CFG1 0x83c 151#define UTMIP_BIAS_CFG1 0x83c
138#define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3) 152#define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3)
139 153
154/* For Tegra30 and above only, the address is different in Tegra20 */
155#define USB_USBMODE 0x1f8
156#define USB_USBMODE_MASK (3 << 0)
157#define USB_USBMODE_HOST (3 << 0)
158#define USB_USBMODE_DEVICE (2 << 0)
159
140static DEFINE_SPINLOCK(utmip_pad_lock); 160static DEFINE_SPINLOCK(utmip_pad_lock);
141static int utmip_pad_count; 161static int utmip_pad_count;
142 162
@@ -184,36 +204,22 @@ static const struct tegra_xtal_freq tegra_freq_table[] = {
184 }, 204 },
185}; 205};
186 206
187static struct tegra_utmip_config utmip_default[] = {
188 [0] = {
189 .hssync_start_delay = 9,
190 .idle_wait_delay = 17,
191 .elastic_limit = 16,
192 .term_range_adj = 6,
193 .xcvr_setup = 9,
194 .xcvr_lsfslew = 1,
195 .xcvr_lsrslew = 1,
196 },
197 [2] = {
198 .hssync_start_delay = 9,
199 .idle_wait_delay = 17,
200 .elastic_limit = 16,
201 .term_range_adj = 6,
202 .xcvr_setup = 9,
203 .xcvr_lsfslew = 2,
204 .xcvr_lsrslew = 2,
205 },
206};
207
208static void set_pts(struct tegra_usb_phy *phy, u8 pts_val) 207static void set_pts(struct tegra_usb_phy *phy, u8 pts_val)
209{ 208{
210 void __iomem *base = phy->regs; 209 void __iomem *base = phy->regs;
211 unsigned long val; 210 unsigned long val;
212 211
213 val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS; 212 if (phy->soc_config->has_hostpc) {
214 val &= ~TEGRA_USB_PORTSC1_PTS(3); 213 val = readl(base + TEGRA_USB_HOSTPC1_DEVLC);
215 val |= TEGRA_USB_PORTSC1_PTS(pts_val & 3); 214 val &= ~TEGRA_USB_HOSTPC1_DEVLC_PTS(~0);
216 writel(val, base + TEGRA_USB_PORTSC1); 215 val |= TEGRA_USB_HOSTPC1_DEVLC_PTS(pts_val);
216 writel(val, base + TEGRA_USB_HOSTPC1_DEVLC);
217 } else {
218 val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS;
219 val &= ~TEGRA_USB_PORTSC1_PTS(~0);
220 val |= TEGRA_USB_PORTSC1_PTS(pts_val);
221 writel(val, base + TEGRA_USB_PORTSC1);
222 }
217} 223}
218 224
219static void set_phcd(struct tegra_usb_phy *phy, bool enable) 225static void set_phcd(struct tegra_usb_phy *phy, bool enable)
@@ -221,17 +227,26 @@ static void set_phcd(struct tegra_usb_phy *phy, bool enable)
221 void __iomem *base = phy->regs; 227 void __iomem *base = phy->regs;
222 unsigned long val; 228 unsigned long val;
223 229
224 val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS; 230 if (phy->soc_config->has_hostpc) {
225 if (enable) 231 val = readl(base + TEGRA_USB_HOSTPC1_DEVLC);
226 val |= TEGRA_USB_PORTSC1_PHCD; 232 if (enable)
227 else 233 val |= TEGRA_USB_HOSTPC1_DEVLC_PHCD;
228 val &= ~TEGRA_USB_PORTSC1_PHCD; 234 else
229 writel(val, base + TEGRA_USB_PORTSC1); 235 val &= ~TEGRA_USB_HOSTPC1_DEVLC_PHCD;
236 writel(val, base + TEGRA_USB_HOSTPC1_DEVLC);
237 } else {
238 val = readl(base + TEGRA_USB_PORTSC1) & ~PORT_RWC_BITS;
239 if (enable)
240 val |= TEGRA_USB_PORTSC1_PHCD;
241 else
242 val &= ~TEGRA_USB_PORTSC1_PHCD;
243 writel(val, base + TEGRA_USB_PORTSC1);
244 }
230} 245}
231 246
232static int utmip_pad_open(struct tegra_usb_phy *phy) 247static int utmip_pad_open(struct tegra_usb_phy *phy)
233{ 248{
234 phy->pad_clk = devm_clk_get(phy->dev, "utmi-pads"); 249 phy->pad_clk = devm_clk_get(phy->u_phy.dev, "utmi-pads");
235 if (IS_ERR(phy->pad_clk)) { 250 if (IS_ERR(phy->pad_clk)) {
236 pr_err("%s: can't get utmip pad clock\n", __func__); 251 pr_err("%s: can't get utmip pad clock\n", __func__);
237 return PTR_ERR(phy->pad_clk); 252 return PTR_ERR(phy->pad_clk);
@@ -244,6 +259,7 @@ static void utmip_pad_power_on(struct tegra_usb_phy *phy)
244{ 259{
245 unsigned long val, flags; 260 unsigned long val, flags;
246 void __iomem *base = phy->pad_regs; 261 void __iomem *base = phy->pad_regs;
262 struct tegra_utmip_config *config = phy->config;
247 263
248 clk_prepare_enable(phy->pad_clk); 264 clk_prepare_enable(phy->pad_clk);
249 265
@@ -252,6 +268,16 @@ static void utmip_pad_power_on(struct tegra_usb_phy *phy)
252 if (utmip_pad_count++ == 0) { 268 if (utmip_pad_count++ == 0) {
253 val = readl(base + UTMIP_BIAS_CFG0); 269 val = readl(base + UTMIP_BIAS_CFG0);
254 val &= ~(UTMIP_OTGPD | UTMIP_BIASPD); 270 val &= ~(UTMIP_OTGPD | UTMIP_BIASPD);
271
272 if (phy->soc_config->requires_extra_tuning_parameters) {
273 val &= ~(UTMIP_HSSQUELCH_LEVEL(~0) |
274 UTMIP_HSDISCON_LEVEL(~0) |
275 UTMIP_HSDISCON_LEVEL_MSB(~0));
276
277 val |= UTMIP_HSSQUELCH_LEVEL(config->hssquelch_level);
278 val |= UTMIP_HSDISCON_LEVEL(config->hsdiscon_level);
279 val |= UTMIP_HSDISCON_LEVEL_MSB(config->hsdiscon_level);
280 }
255 writel(val, base + UTMIP_BIAS_CFG0); 281 writel(val, base + UTMIP_BIAS_CFG0);
256 } 282 }
257 283
@@ -361,7 +387,7 @@ static int utmi_phy_power_on(struct tegra_usb_phy *phy)
361 } 387 }
362 388
363 val = readl(base + UTMIP_TX_CFG0); 389 val = readl(base + UTMIP_TX_CFG0);
364 val &= ~UTMIP_FS_PREABMLE_J; 390 val |= UTMIP_FS_PREABMLE_J;
365 writel(val, base + UTMIP_TX_CFG0); 391 writel(val, base + UTMIP_TX_CFG0);
366 392
367 val = readl(base + UTMIP_HSRX_CFG0); 393 val = readl(base + UTMIP_HSRX_CFG0);
@@ -384,34 +410,56 @@ static int utmi_phy_power_on(struct tegra_usb_phy *phy)
384 val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE; 410 val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE;
385 writel(val, base + UTMIP_MISC_CFG0); 411 writel(val, base + UTMIP_MISC_CFG0);
386 412
387 val = readl(base + UTMIP_MISC_CFG1); 413 if (!phy->soc_config->utmi_pll_config_in_car_module) {
388 val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | UTMIP_PLLU_STABLE_COUNT(~0)); 414 val = readl(base + UTMIP_MISC_CFG1);
389 val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) | 415 val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) |
390 UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count); 416 UTMIP_PLLU_STABLE_COUNT(~0));
391 writel(val, base + UTMIP_MISC_CFG1); 417 val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) |
392 418 UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count);
393 val = readl(base + UTMIP_PLL_CFG1); 419 writel(val, base + UTMIP_MISC_CFG1);
394 val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | UTMIP_PLLU_ENABLE_DLY_COUNT(~0)); 420
395 val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) | 421 val = readl(base + UTMIP_PLL_CFG1);
396 UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay); 422 val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) |
397 writel(val, base + UTMIP_PLL_CFG1); 423 UTMIP_PLLU_ENABLE_DLY_COUNT(~0));
424 val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) |
425 UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay);
426 writel(val, base + UTMIP_PLL_CFG1);
427 }
398 428
399 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) { 429 if (phy->mode == USB_DR_MODE_PERIPHERAL) {
400 val = readl(base + USB_SUSP_CTRL); 430 val = readl(base + USB_SUSP_CTRL);
401 val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV); 431 val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV);
402 writel(val, base + USB_SUSP_CTRL); 432 writel(val, base + USB_SUSP_CTRL);
433
434 val = readl(base + UTMIP_BAT_CHRG_CFG0);
435 val &= ~UTMIP_PD_CHRG;
436 writel(val, base + UTMIP_BAT_CHRG_CFG0);
437 } else {
438 val = readl(base + UTMIP_BAT_CHRG_CFG0);
439 val |= UTMIP_PD_CHRG;
440 writel(val, base + UTMIP_BAT_CHRG_CFG0);
403 } 441 }
404 442
405 utmip_pad_power_on(phy); 443 utmip_pad_power_on(phy);
406 444
407 val = readl(base + UTMIP_XCVR_CFG0); 445 val = readl(base + UTMIP_XCVR_CFG0);
408 val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | 446 val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
409 UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_SETUP(~0) | 447 UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_LSBIAS_SEL |
410 UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0) | 448 UTMIP_XCVR_SETUP(~0) | UTMIP_XCVR_SETUP_MSB(~0) |
411 UTMIP_XCVR_HSSLEW_MSB(~0)); 449 UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0));
412 val |= UTMIP_XCVR_SETUP(config->xcvr_setup); 450
451 if (!config->xcvr_setup_use_fuses) {
452 val |= UTMIP_XCVR_SETUP(config->xcvr_setup);
453 val |= UTMIP_XCVR_SETUP_MSB(config->xcvr_setup);
454 }
413 val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew); 455 val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew);
414 val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew); 456 val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew);
457
458 if (phy->soc_config->requires_extra_tuning_parameters) {
459 val &= ~(UTMIP_XCVR_HSSLEW(~0) | UTMIP_XCVR_HSSLEW_MSB(~0));
460 val |= UTMIP_XCVR_HSSLEW(config->xcvr_hsslew);
461 val |= UTMIP_XCVR_HSSLEW_MSB(config->xcvr_hsslew);
462 }
415 writel(val, base + UTMIP_XCVR_CFG0); 463 writel(val, base + UTMIP_XCVR_CFG0);
416 464
417 val = readl(base + UTMIP_XCVR_CFG1); 465 val = readl(base + UTMIP_XCVR_CFG1);
@@ -420,23 +468,19 @@ static int utmi_phy_power_on(struct tegra_usb_phy *phy)
420 val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj); 468 val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj);
421 writel(val, base + UTMIP_XCVR_CFG1); 469 writel(val, base + UTMIP_XCVR_CFG1);
422 470
423 val = readl(base + UTMIP_BAT_CHRG_CFG0);
424 val &= ~UTMIP_PD_CHRG;
425 writel(val, base + UTMIP_BAT_CHRG_CFG0);
426
427 val = readl(base + UTMIP_BIAS_CFG1); 471 val = readl(base + UTMIP_BIAS_CFG1);
428 val &= ~UTMIP_BIAS_PDTRK_COUNT(~0); 472 val &= ~UTMIP_BIAS_PDTRK_COUNT(~0);
429 val |= UTMIP_BIAS_PDTRK_COUNT(0x5); 473 val |= UTMIP_BIAS_PDTRK_COUNT(0x5);
430 writel(val, base + UTMIP_BIAS_CFG1); 474 writel(val, base + UTMIP_BIAS_CFG1);
431 475
432 if (phy->is_legacy_phy) { 476 val = readl(base + UTMIP_SPARE_CFG0);
433 val = readl(base + UTMIP_SPARE_CFG0); 477 if (config->xcvr_setup_use_fuses)
434 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) 478 val |= FUSE_SETUP_SEL;
435 val &= ~FUSE_SETUP_SEL; 479 else
436 else 480 val &= ~FUSE_SETUP_SEL;
437 val |= FUSE_SETUP_SEL; 481 writel(val, base + UTMIP_SPARE_CFG0);
438 writel(val, base + UTMIP_SPARE_CFG0); 482
439 } else { 483 if (!phy->is_legacy_phy) {
440 val = readl(base + USB_SUSP_CTRL); 484 val = readl(base + USB_SUSP_CTRL);
441 val |= UTMIP_PHY_ENABLE; 485 val |= UTMIP_PHY_ENABLE;
442 writel(val, base + USB_SUSP_CTRL); 486 writel(val, base + USB_SUSP_CTRL);
@@ -459,6 +503,16 @@ static int utmi_phy_power_on(struct tegra_usb_phy *phy)
459 503
460 utmi_phy_clk_enable(phy); 504 utmi_phy_clk_enable(phy);
461 505
506 if (phy->soc_config->requires_usbmode_setup) {
507 val = readl(base + USB_USBMODE);
508 val &= ~USB_USBMODE_MASK;
509 if (phy->mode == USB_DR_MODE_HOST)
510 val |= USB_USBMODE_HOST;
511 else
512 val |= USB_USBMODE_DEVICE;
513 writel(val, base + USB_USBMODE);
514 }
515
462 if (!phy->is_legacy_phy) 516 if (!phy->is_legacy_phy)
463 set_pts(phy, 0); 517 set_pts(phy, 0);
464 518
@@ -472,7 +526,7 @@ static int utmi_phy_power_off(struct tegra_usb_phy *phy)
472 526
473 utmi_phy_clk_disable(phy); 527 utmi_phy_clk_disable(phy);
474 528
475 if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) { 529 if (phy->mode == USB_DR_MODE_PERIPHERAL) {
476 val = readl(base + USB_SUSP_CTRL); 530 val = readl(base + USB_SUSP_CTRL);
477 val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0); 531 val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0);
478 val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5); 532 val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5);
@@ -560,13 +614,15 @@ static int ulpi_phy_power_on(struct tegra_usb_phy *phy)
560 614
561 ret = gpio_direction_output(phy->reset_gpio, 0); 615 ret = gpio_direction_output(phy->reset_gpio, 0);
562 if (ret < 0) { 616 if (ret < 0) {
563 dev_err(phy->dev, "gpio %d not set to 0\n", phy->reset_gpio); 617 dev_err(phy->u_phy.dev, "gpio %d not set to 0\n",
618 phy->reset_gpio);
564 return ret; 619 return ret;
565 } 620 }
566 msleep(5); 621 msleep(5);
567 ret = gpio_direction_output(phy->reset_gpio, 1); 622 ret = gpio_direction_output(phy->reset_gpio, 1);
568 if (ret < 0) { 623 if (ret < 0) {
569 dev_err(phy->dev, "gpio %d not set to 1\n", phy->reset_gpio); 624 dev_err(phy->u_phy.dev, "gpio %d not set to 1\n",
625 phy->reset_gpio);
570 return ret; 626 return ret;
571 } 627 }
572 628
@@ -634,6 +690,9 @@ static void tegra_usb_phy_close(struct usb_phy *x)
634{ 690{
635 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); 691 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
636 692
693 if (!IS_ERR(phy->vbus))
694 regulator_disable(phy->vbus);
695
637 clk_disable_unprepare(phy->pll_u); 696 clk_disable_unprepare(phy->pll_u);
638} 697}
639 698
@@ -666,29 +725,30 @@ static int ulpi_open(struct tegra_usb_phy *phy)
666{ 725{
667 int err; 726 int err;
668 727
669 phy->clk = devm_clk_get(phy->dev, "ulpi-link"); 728 phy->clk = devm_clk_get(phy->u_phy.dev, "ulpi-link");
670 if (IS_ERR(phy->clk)) { 729 if (IS_ERR(phy->clk)) {
671 pr_err("%s: can't get ulpi clock\n", __func__); 730 pr_err("%s: can't get ulpi clock\n", __func__);
672 return PTR_ERR(phy->clk); 731 return PTR_ERR(phy->clk);
673 } 732 }
674 733
675 err = devm_gpio_request(phy->dev, phy->reset_gpio, "ulpi_phy_reset_b"); 734 err = devm_gpio_request(phy->u_phy.dev, phy->reset_gpio,
735 "ulpi_phy_reset_b");
676 if (err < 0) { 736 if (err < 0) {
677 dev_err(phy->dev, "request failed for gpio: %d\n", 737 dev_err(phy->u_phy.dev, "request failed for gpio: %d\n",
678 phy->reset_gpio); 738 phy->reset_gpio);
679 return err; 739 return err;
680 } 740 }
681 741
682 err = gpio_direction_output(phy->reset_gpio, 0); 742 err = gpio_direction_output(phy->reset_gpio, 0);
683 if (err < 0) { 743 if (err < 0) {
684 dev_err(phy->dev, "gpio %d direction not set to output\n", 744 dev_err(phy->u_phy.dev, "gpio %d direction not set to output\n",
685 phy->reset_gpio); 745 phy->reset_gpio);
686 return err; 746 return err;
687 } 747 }
688 748
689 phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0); 749 phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0);
690 if (!phy->ulpi) { 750 if (!phy->ulpi) {
691 dev_err(phy->dev, "otg_ulpi_create returned NULL\n"); 751 dev_err(phy->u_phy.dev, "otg_ulpi_create returned NULL\n");
692 err = -ENOMEM; 752 err = -ENOMEM;
693 return err; 753 return err;
694 } 754 }
@@ -703,14 +763,7 @@ static int tegra_usb_phy_init(struct tegra_usb_phy *phy)
703 int i; 763 int i;
704 int err; 764 int err;
705 765
706 if (!phy->is_ulpi_phy) { 766 phy->pll_u = devm_clk_get(phy->u_phy.dev, "pll_u");
707 if (phy->is_legacy_phy)
708 phy->config = &utmip_default[0];
709 else
710 phy->config = &utmip_default[2];
711 }
712
713 phy->pll_u = devm_clk_get(phy->dev, "pll_u");
714 if (IS_ERR(phy->pll_u)) { 767 if (IS_ERR(phy->pll_u)) {
715 pr_err("Can't get pll_u clock\n"); 768 pr_err("Can't get pll_u clock\n");
716 return PTR_ERR(phy->pll_u); 769 return PTR_ERR(phy->pll_u);
@@ -733,6 +786,16 @@ static int tegra_usb_phy_init(struct tegra_usb_phy *phy)
733 goto fail; 786 goto fail;
734 } 787 }
735 788
789 if (!IS_ERR(phy->vbus)) {
790 err = regulator_enable(phy->vbus);
791 if (err) {
792 dev_err(phy->u_phy.dev,
793 "failed to enable usb vbus regulator: %d\n",
794 err);
795 goto fail;
796 }
797 }
798
736 if (phy->is_ulpi_phy) 799 if (phy->is_ulpi_phy)
737 err = ulpi_open(phy); 800 err = ulpi_open(phy);
738 else 801 else
@@ -784,11 +847,138 @@ void tegra_ehci_phy_restore_end(struct usb_phy *x)
784} 847}
785EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end); 848EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end);
786 849
850static int read_utmi_param(struct platform_device *pdev, const char *param,
851 u8 *dest)
852{
853 u32 value;
854 int err = of_property_read_u32(pdev->dev.of_node, param, &value);
855 *dest = (u8)value;
856 if (err < 0)
857 dev_err(&pdev->dev, "Failed to read USB UTMI parameter %s: %d\n",
858 param, err);
859 return err;
860}
861
862static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy,
863 struct platform_device *pdev)
864{
865 struct resource *res;
866 int err;
867 struct tegra_utmip_config *config;
868
869 tegra_phy->is_ulpi_phy = false;
870
871 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
872 if (!res) {
873 dev_err(&pdev->dev, "Failed to get UTMI Pad regs\n");
874 return -ENXIO;
875 }
876
877 tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start,
878 resource_size(res));
879 if (!tegra_phy->regs) {
880 dev_err(&pdev->dev, "Failed to remap UTMI Pad regs\n");
881 return -ENOMEM;
882 }
883
884 tegra_phy->config = devm_kzalloc(&pdev->dev,
885 sizeof(*tegra_phy->config), GFP_KERNEL);
886 if (!tegra_phy->config) {
887 dev_err(&pdev->dev,
888 "unable to allocate memory for USB UTMIP config\n");
889 return -ENOMEM;
890 }
891
892 config = tegra_phy->config;
893
894 err = read_utmi_param(pdev, "nvidia,hssync-start-delay",
895 &config->hssync_start_delay);
896 if (err < 0)
897 return err;
898
899 err = read_utmi_param(pdev, "nvidia,elastic-limit",
900 &config->elastic_limit);
901 if (err < 0)
902 return err;
903
904 err = read_utmi_param(pdev, "nvidia,idle-wait-delay",
905 &config->idle_wait_delay);
906 if (err < 0)
907 return err;
908
909 err = read_utmi_param(pdev, "nvidia,term-range-adj",
910 &config->term_range_adj);
911 if (err < 0)
912 return err;
913
914 err = read_utmi_param(pdev, "nvidia,xcvr-lsfslew",
915 &config->xcvr_lsfslew);
916 if (err < 0)
917 return err;
918
919 err = read_utmi_param(pdev, "nvidia,xcvr-lsrslew",
920 &config->xcvr_lsrslew);
921 if (err < 0)
922 return err;
923
924 if (tegra_phy->soc_config->requires_extra_tuning_parameters) {
925 err = read_utmi_param(pdev, "nvidia,xcvr-hsslew",
926 &config->xcvr_hsslew);
927 if (err < 0)
928 return err;
929
930 err = read_utmi_param(pdev, "nvidia,hssquelch-level",
931 &config->hssquelch_level);
932 if (err < 0)
933 return err;
934
935 err = read_utmi_param(pdev, "nvidia,hsdiscon-level",
936 &config->hsdiscon_level);
937 if (err < 0)
938 return err;
939 }
940
941 config->xcvr_setup_use_fuses = of_property_read_bool(
942 pdev->dev.of_node, "nvidia,xcvr-setup-use-fuses");
943
944 if (!config->xcvr_setup_use_fuses) {
945 err = read_utmi_param(pdev, "nvidia,xcvr-setup",
946 &config->xcvr_setup);
947 if (err < 0)
948 return err;
949 }
950
951 return 0;
952}
953
954static const struct tegra_phy_soc_config tegra20_soc_config = {
955 .utmi_pll_config_in_car_module = false,
956 .has_hostpc = false,
957 .requires_usbmode_setup = false,
958 .requires_extra_tuning_parameters = false,
959};
960
961static const struct tegra_phy_soc_config tegra30_soc_config = {
962 .utmi_pll_config_in_car_module = true,
963 .has_hostpc = true,
964 .requires_usbmode_setup = true,
965 .requires_extra_tuning_parameters = true,
966};
967
968static struct of_device_id tegra_usb_phy_id_table[] = {
969 { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config },
970 { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config },
971 { },
972};
973MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table);
974
787static int tegra_usb_phy_probe(struct platform_device *pdev) 975static int tegra_usb_phy_probe(struct platform_device *pdev)
788{ 976{
977 const struct of_device_id *match;
789 struct resource *res; 978 struct resource *res;
790 struct tegra_usb_phy *tegra_phy = NULL; 979 struct tegra_usb_phy *tegra_phy = NULL;
791 struct device_node *np = pdev->dev.of_node; 980 struct device_node *np = pdev->dev.of_node;
981 enum usb_phy_interface phy_type;
792 int err; 982 int err;
793 983
794 tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL); 984 tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL);
@@ -797,6 +987,13 @@ static int tegra_usb_phy_probe(struct platform_device *pdev)
797 return -ENOMEM; 987 return -ENOMEM;
798 } 988 }
799 989
990 match = of_match_device(tegra_usb_phy_id_table, &pdev->dev);
991 if (!match) {
992 dev_err(&pdev->dev, "Error: No device match found\n");
993 return -ENODEV;
994 }
995 tegra_phy->soc_config = match->data;
996
800 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 997 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
801 if (!res) { 998 if (!res) {
802 dev_err(&pdev->dev, "Failed to get I/O memory\n"); 999 dev_err(&pdev->dev, "Failed to get I/O memory\n");
@@ -813,23 +1010,15 @@ static int tegra_usb_phy_probe(struct platform_device *pdev)
813 tegra_phy->is_legacy_phy = 1010 tegra_phy->is_legacy_phy =
814 of_property_read_bool(np, "nvidia,has-legacy-mode"); 1011 of_property_read_bool(np, "nvidia,has-legacy-mode");
815 1012
816 err = of_property_match_string(np, "phy_type", "ulpi"); 1013 phy_type = of_usb_get_phy_mode(np);
817 if (err < 0) { 1014 switch (phy_type) {
818 tegra_phy->is_ulpi_phy = false; 1015 case USBPHY_INTERFACE_MODE_UTMI:
819 1016 err = utmi_phy_probe(tegra_phy, pdev);
820 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1017 if (err < 0)
821 if (!res) { 1018 return err;
822 dev_err(&pdev->dev, "Failed to get UTMI Pad regs\n"); 1019 break;
823 return -ENXIO;
824 }
825 1020
826 tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start, 1021 case USBPHY_INTERFACE_MODE_ULPI:
827 resource_size(res));
828 if (!tegra_phy->regs) {
829 dev_err(&pdev->dev, "Failed to remap UTMI Pad regs\n");
830 return -ENOMEM;
831 }
832 } else {
833 tegra_phy->is_ulpi_phy = true; 1022 tegra_phy->is_ulpi_phy = true;
834 1023
835 tegra_phy->reset_gpio = 1024 tegra_phy->reset_gpio =
@@ -839,19 +1028,35 @@ static int tegra_usb_phy_probe(struct platform_device *pdev)
839 tegra_phy->reset_gpio); 1028 tegra_phy->reset_gpio);
840 return tegra_phy->reset_gpio; 1029 return tegra_phy->reset_gpio;
841 } 1030 }
1031 tegra_phy->config = NULL;
1032 break;
1033
1034 default:
1035 dev_err(&pdev->dev, "phy_type is invalid or unsupported\n");
1036 return -EINVAL;
842 } 1037 }
843 1038
844 err = of_property_match_string(np, "dr_mode", "otg"); 1039 if (of_find_property(np, "dr_mode", NULL))
845 if (err < 0) { 1040 tegra_phy->mode = of_usb_get_dr_mode(np);
846 err = of_property_match_string(np, "dr_mode", "peripheral"); 1041 else
847 if (err < 0) 1042 tegra_phy->mode = USB_DR_MODE_HOST;
848 tegra_phy->mode = TEGRA_USB_PHY_MODE_HOST;
849 else
850 tegra_phy->mode = TEGRA_USB_PHY_MODE_DEVICE;
851 } else
852 tegra_phy->mode = TEGRA_USB_PHY_MODE_OTG;
853 1043
854 tegra_phy->dev = &pdev->dev; 1044 if (tegra_phy->mode == USB_DR_MODE_UNKNOWN) {
1045 dev_err(&pdev->dev, "dr_mode is invalid\n");
1046 return -EINVAL;
1047 }
1048
1049 /* On some boards, the VBUS regulator doesn't need to be controlled */
1050 if (of_find_property(np, "vbus-supply", NULL)) {
1051 tegra_phy->vbus = devm_regulator_get(&pdev->dev, "vbus");
1052 if (IS_ERR(tegra_phy->vbus))
1053 return PTR_ERR(tegra_phy->vbus);
1054 } else {
1055 dev_notice(&pdev->dev, "no vbus regulator");
1056 tegra_phy->vbus = ERR_PTR(-ENODEV);
1057 }
1058
1059 tegra_phy->u_phy.dev = &pdev->dev;
855 err = tegra_usb_phy_init(tegra_phy); 1060 err = tegra_usb_phy_init(tegra_phy);
856 if (err < 0) 1061 if (err < 0)
857 return err; 1062 return err;
@@ -860,17 +1065,28 @@ static int tegra_usb_phy_probe(struct platform_device *pdev)
860 tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend; 1065 tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend;
861 1066
862 dev_set_drvdata(&pdev->dev, tegra_phy); 1067 dev_set_drvdata(&pdev->dev, tegra_phy);
1068
1069 err = usb_add_phy_dev(&tegra_phy->u_phy);
1070 if (err < 0) {
1071 tegra_usb_phy_close(&tegra_phy->u_phy);
1072 return err;
1073 }
1074
863 return 0; 1075 return 0;
864} 1076}
865 1077
866static struct of_device_id tegra_usb_phy_id_table[] = { 1078static int tegra_usb_phy_remove(struct platform_device *pdev)
867 { .compatible = "nvidia,tegra20-usb-phy", }, 1079{
868 { }, 1080 struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev);
869}; 1081
870MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table); 1082 usb_remove_phy(&tegra_phy->u_phy);
1083
1084 return 0;
1085}
871 1086
872static struct platform_driver tegra_usb_phy_driver = { 1087static struct platform_driver tegra_usb_phy_driver = {
873 .probe = tegra_usb_phy_probe, 1088 .probe = tegra_usb_phy_probe,
1089 .remove = tegra_usb_phy_remove,
874 .driver = { 1090 .driver = {
875 .name = "tegra-phy", 1091 .name = "tegra-phy",
876 .owner = THIS_MODULE, 1092 .owner = THIS_MODULE,
@@ -879,29 +1095,5 @@ static struct platform_driver tegra_usb_phy_driver = {
879}; 1095};
880module_platform_driver(tegra_usb_phy_driver); 1096module_platform_driver(tegra_usb_phy_driver);
881 1097
882static int tegra_usb_phy_match(struct device *dev, void *data)
883{
884 struct tegra_usb_phy *tegra_phy = dev_get_drvdata(dev);
885 struct device_node *dn = data;
886
887 return (tegra_phy->dev->of_node == dn) ? 1 : 0;
888}
889
890struct usb_phy *tegra_usb_get_phy(struct device_node *dn)
891{
892 struct device *dev;
893 struct tegra_usb_phy *tegra_phy;
894
895 dev = driver_find_device(&tegra_usb_phy_driver.driver, NULL, dn,
896 tegra_usb_phy_match);
897 if (!dev)
898 return ERR_PTR(-EPROBE_DEFER);
899
900 tegra_phy = dev_get_drvdata(dev);
901
902 return &tegra_phy->u_phy;
903}
904EXPORT_SYMBOL_GPL(tegra_usb_get_phy);
905
906MODULE_DESCRIPTION("Tegra USB PHY driver"); 1098MODULE_DESCRIPTION("Tegra USB PHY driver");
907MODULE_LICENSE("GPL v2"); 1099MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
index 8f78d2d40722..90730c8762b8 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -648,7 +648,7 @@ static int twl4030_set_host(struct usb_otg *otg, struct usb_bus *host)
648 648
649static int twl4030_usb_probe(struct platform_device *pdev) 649static int twl4030_usb_probe(struct platform_device *pdev)
650{ 650{
651 struct twl4030_usb_data *pdata = pdev->dev.platform_data; 651 struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev);
652 struct twl4030_usb *twl; 652 struct twl4030_usb *twl;
653 int status, err; 653 int status, err;
654 struct usb_otg *otg; 654 struct usb_otg *otg;
diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c
index 1753bd367e0a..16dbc9382678 100644
--- a/drivers/usb/phy/phy-twl6030-usb.c
+++ b/drivers/usb/phy/phy-twl6030-usb.c
@@ -324,7 +324,7 @@ static int twl6030_usb_probe(struct platform_device *pdev)
324 int status, err; 324 int status, err;
325 struct device_node *np = pdev->dev.of_node; 325 struct device_node *np = pdev->dev.of_node;
326 struct device *dev = &pdev->dev; 326 struct device *dev = &pdev->dev;
327 struct twl4030_usb_data *pdata = dev->platform_data; 327 struct twl4030_usb_data *pdata = dev_get_platdata(dev);
328 328
329 twl = devm_kzalloc(dev, sizeof *twl, GFP_KERNEL); 329 twl = devm_kzalloc(dev, sizeof *twl, GFP_KERNEL);
330 if (!twl) 330 if (!twl)
diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
index cfd205036aba..3b39757c13bc 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -416,7 +416,7 @@ static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
416 */ 416 */
417static int usbhs_probe(struct platform_device *pdev) 417static int usbhs_probe(struct platform_device *pdev)
418{ 418{
419 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data; 419 struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev);
420 struct renesas_usbhs_driver_callback *dfunc; 420 struct renesas_usbhs_driver_callback *dfunc;
421 struct usbhs_priv *priv; 421 struct usbhs_priv *priv;
422 struct resource *res, *irq_res; 422 struct resource *res, *irq_res;
@@ -558,7 +558,7 @@ probe_end_pipe_exit:
558static int usbhs_remove(struct platform_device *pdev) 558static int usbhs_remove(struct platform_device *pdev)
559{ 559{
560 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); 560 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
561 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data; 561 struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev);
562 struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback; 562 struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback;
563 563
564 dev_dbg(&pdev->dev, "usb remove\n"); 564 dev_dbg(&pdev->dev, "usb remove\n");
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 805940c37353..3385aeb5a364 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -77,9 +77,9 @@ struct usbhsg_recip_handle {
77 struct usbhsg_gpriv, mod) 77 struct usbhsg_gpriv, mod)
78 78
79#define __usbhsg_for_each_uep(start, pos, g, i) \ 79#define __usbhsg_for_each_uep(start, pos, g, i) \
80 for (i = start, pos = (g)->uep + i; \ 80 for ((i) = start; \
81 i < (g)->uep_size; \ 81 ((i) < (g)->uep_size) && ((pos) = (g)->uep + (i)); \
82 i++, pos = (g)->uep + i) 82 (i)++)
83 83
84#define usbhsg_for_each_uep(pos, gpriv, i) \ 84#define usbhsg_for_each_uep(pos, gpriv, i) \
85 __usbhsg_for_each_uep(1, pos, gpriv, i) 85 __usbhsg_for_each_uep(1, pos, gpriv, i)
diff --git a/drivers/usb/renesas_usbhs/mod_host.c b/drivers/usb/renesas_usbhs/mod_host.c
index b86815421c8d..e40f565004d0 100644
--- a/drivers/usb/renesas_usbhs/mod_host.c
+++ b/drivers/usb/renesas_usbhs/mod_host.c
@@ -111,9 +111,9 @@ static const char usbhsh_hcd_name[] = "renesas_usbhs host";
111 container_of(usbhs_mod_get(priv, USBHS_HOST), struct usbhsh_hpriv, mod) 111 container_of(usbhs_mod_get(priv, USBHS_HOST), struct usbhsh_hpriv, mod)
112 112
113#define __usbhsh_for_each_udev(start, pos, h, i) \ 113#define __usbhsh_for_each_udev(start, pos, h, i) \
114 for (i = start, pos = (h)->udev + i; \ 114 for ((i) = start; \
115 i < USBHSH_DEVICE_MAX; \ 115 ((i) < USBHSH_DEVICE_MAX) && ((pos) = (h)->udev + (i)); \
116 i++, pos = (h)->udev + i) 116 (i)++)
117 117
118#define usbhsh_for_each_udev(pos, hpriv, i) \ 118#define usbhsh_for_each_udev(pos, hpriv, i) \
119 __usbhsh_for_each_udev(1, pos, hpriv, i) 119 __usbhsh_for_each_udev(1, pos, hpriv, i)
diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h
index b476fde955bf..3e5349879838 100644
--- a/drivers/usb/renesas_usbhs/pipe.h
+++ b/drivers/usb/renesas_usbhs/pipe.h
@@ -54,9 +54,9 @@ struct usbhs_pipe_info {
54 * pipe list 54 * pipe list
55 */ 55 */
56#define __usbhs_for_each_pipe(start, pos, info, i) \ 56#define __usbhs_for_each_pipe(start, pos, info, i) \
57 for (i = start, pos = (info)->pipe + i; \ 57 for ((i) = start; \
58 i < (info)->size; \ 58 ((i) < (info)->size) && ((pos) = (info)->pipe + (i)); \
59 i++, pos = (info)->pipe + i) 59 (i)++)
60 60
61#define usbhs_for_each_pipe(pos, priv, i) \ 61#define usbhs_for_each_pipe(pos, priv, i) \
62 __usbhs_for_each_pipe(1, pos, &((priv)->pipe_info), i) 62 __usbhs_for_each_pipe(1, pos, &((priv)->pipe_info), i)
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 7eef9b33fde6..c454bfa22a10 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -51,6 +51,24 @@ config USB_SERIAL_GENERIC
51 support" be compiled as a module for this driver to be used 51 support" be compiled as a module for this driver to be used
52 properly. 52 properly.
53 53
54config USB_SERIAL_SIMPLE
55 tristate "USB Serial Simple Driver"
56 help
57 Say Y here to use the USB serial "simple" driver. This driver
58 handles a wide range of very simple devices, all in one
59 driver. Specifically, it supports:
60 - Suunto ANT+ USB device.
61 - Fundamental Software dongle.
62 - HP4x calculators
63 - a number of Motoroloa phones
64 - Siemens USB/MPI adapter.
65 - ViVOtech ViVOpay USB device.
66 - Infineon Modem Flashloader USB interface
67 - ZIO Motherboard USB serial interface
68
69 To compile this driver as a module, choose M here: the module
70 will be called usb-serial-simple.
71
54config USB_SERIAL_AIRCABLE 72config USB_SERIAL_AIRCABLE
55 tristate "USB AIRcable Bluetooth Dongle Driver" 73 tristate "USB AIRcable Bluetooth Dongle Driver"
56 help 74 help
@@ -158,14 +176,6 @@ config USB_SERIAL_FTDI_SIO
158 To compile this driver as a module, choose M here: the 176 To compile this driver as a module, choose M here: the
159 module will be called ftdi_sio. 177 module will be called ftdi_sio.
160 178
161config USB_SERIAL_FUNSOFT
162 tristate "USB Fundamental Software Dongle Driver"
163 ---help---
164 Say Y here if you want to use the Fundamental Software dongle.
165
166 To compile this driver as a module, choose M here: the
167 module will be called funsoft.
168
169config USB_SERIAL_VISOR 179config USB_SERIAL_VISOR
170 tristate "USB Handspring Visor / Palm m50x / Sony Clie Driver" 180 tristate "USB Handspring Visor / Palm m50x / Sony Clie Driver"
171 help 181 help
@@ -462,15 +472,6 @@ config USB_SERIAL_MOS7840
462 To compile this driver as a module, choose M here: the 472 To compile this driver as a module, choose M here: the
463 module will be called mos7840. If unsure, choose N. 473 module will be called mos7840. If unsure, choose N.
464 474
465config USB_SERIAL_MOTOROLA
466 tristate "USB Motorola Phone modem driver"
467 ---help---
468 Say Y here if you want to use a Motorola phone with a USB
469 connector as a modem link.
470
471 To compile this driver as a module, choose M here: the
472 module will be called moto_modem. If unsure, choose N.
473
474config USB_SERIAL_NAVMAN 475config USB_SERIAL_NAVMAN
475 tristate "USB Navman GPS device" 476 tristate "USB Navman GPS device"
476 help 477 help
@@ -525,14 +526,6 @@ config USB_SERIAL_SPCP8X5
525 To compile this driver as a module, choose M here: the 526 To compile this driver as a module, choose M here: the
526 module will be called spcp8x5. 527 module will be called spcp8x5.
527 528
528config USB_SERIAL_HP4X
529 tristate "USB HP4x Calculators support"
530 help
531 Say Y here if you want to use an Hewlett-Packard 4x Calculator.
532
533 To compile this driver as a module, choose M here: the
534 module will be called hp4x.
535
536config USB_SERIAL_SAFE 529config USB_SERIAL_SAFE
537 tristate "USB Safe Serial (Encapsulated) Driver" 530 tristate "USB Safe Serial (Encapsulated) Driver"
538 531
@@ -540,14 +533,6 @@ config USB_SERIAL_SAFE_PADDED
540 bool "USB Secure Encapsulated Driver - Padded" 533 bool "USB Secure Encapsulated Driver - Padded"
541 depends on USB_SERIAL_SAFE 534 depends on USB_SERIAL_SAFE
542 535
543config USB_SERIAL_SIEMENS_MPI
544 tristate "USB Siemens MPI driver"
545 help
546 Say M here if you want to use a Siemens USB/MPI adapter.
547
548 To compile this driver as a module, choose M here: the
549 module will be called siemens_mpi.
550
551config USB_SERIAL_SIERRAWIRELESS 536config USB_SERIAL_SIERRAWIRELESS
552 tristate "USB Sierra Wireless Driver" 537 tristate "USB Sierra Wireless Driver"
553 help 538 help
@@ -639,14 +624,6 @@ config USB_SERIAL_OPTICON
639 To compile this driver as a module, choose M here: the 624 To compile this driver as a module, choose M here: the
640 module will be called opticon. 625 module will be called opticon.
641 626
642config USB_SERIAL_VIVOPAY_SERIAL
643 tristate "USB ViVOpay serial interface driver"
644 help
645 Say Y here if you want to use a ViVOtech ViVOpay USB device.
646
647 To compile this driver as a module, choose M here: the
648 module will be called vivopay-serial.
649
650config USB_SERIAL_XSENS_MT 627config USB_SERIAL_XSENS_MT
651 tristate "Xsens motion tracker serial interface driver" 628 tristate "Xsens motion tracker serial interface driver"
652 help 629 help
@@ -659,14 +636,6 @@ config USB_SERIAL_XSENS_MT
659 To compile this driver as a module, choose M here: the 636 To compile this driver as a module, choose M here: the
660 module will be called xsens_mt. 637 module will be called xsens_mt.
661 638
662config USB_SERIAL_ZIO
663 tristate "ZIO Motherboard USB serial interface driver"
664 help
665 Say Y here if you want to use ZIO Motherboard.
666
667 To compile this driver as a module, choose M here: the
668 module will be called zio.
669
670config USB_SERIAL_WISHBONE 639config USB_SERIAL_WISHBONE
671 tristate "USB-Wishbone adapter interface driver" 640 tristate "USB-Wishbone adapter interface driver"
672 help 641 help
@@ -710,23 +679,6 @@ config USB_SERIAL_QT2
710 To compile this driver as a module, choose M here: the 679 To compile this driver as a module, choose M here: the
711 module will be called quatech-serial. 680 module will be called quatech-serial.
712 681
713config USB_SERIAL_FLASHLOADER
714 tristate "Infineon Modem Flashloader USB interface driver"
715 help
716 Say Y here if you want to download Infineon Modem
717 via USB Flashloader serial driver.
718
719 To compile this driver as a module, choose M here: the
720 module will be called flashloader.
721
722config USB_SERIAL_SUUNTO
723 tristate "USB Suunto ANT+ driver"
724 help
725 Say Y here if you want to use the Suunto ANT+ USB device.
726
727 To compile this driver as a module, choose M here: the
728 module will be called suunto.
729
730config USB_SERIAL_DEBUG 682config USB_SERIAL_DEBUG
731 tristate "USB Debugging Device" 683 tristate "USB Debugging Device"
732 help 684 help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index a14a870d993f..42670f0b5bc0 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -24,9 +24,7 @@ obj-$(CONFIG_USB_SERIAL_EDGEPORT_TI) += io_ti.o
24obj-$(CONFIG_USB_SERIAL_EMPEG) += empeg.o 24obj-$(CONFIG_USB_SERIAL_EMPEG) += empeg.o
25obj-$(CONFIG_USB_SERIAL_F81232) += f81232.o 25obj-$(CONFIG_USB_SERIAL_F81232) += f81232.o
26obj-$(CONFIG_USB_SERIAL_FTDI_SIO) += ftdi_sio.o 26obj-$(CONFIG_USB_SERIAL_FTDI_SIO) += ftdi_sio.o
27obj-$(CONFIG_USB_SERIAL_FUNSOFT) += funsoft.o
28obj-$(CONFIG_USB_SERIAL_GARMIN) += garmin_gps.o 27obj-$(CONFIG_USB_SERIAL_GARMIN) += garmin_gps.o
29obj-$(CONFIG_USB_SERIAL_HP4X) += hp4x.o
30obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o 28obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o
31obj-$(CONFIG_USB_SERIAL_IPW) += ipw.o 29obj-$(CONFIG_USB_SERIAL_IPW) += ipw.o
32obj-$(CONFIG_USB_SERIAL_IR) += ir-usb.o 30obj-$(CONFIG_USB_SERIAL_IR) += ir-usb.o
@@ -39,7 +37,6 @@ obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o
39obj-$(CONFIG_USB_SERIAL_METRO) += metro-usb.o 37obj-$(CONFIG_USB_SERIAL_METRO) += metro-usb.o
40obj-$(CONFIG_USB_SERIAL_MOS7720) += mos7720.o 38obj-$(CONFIG_USB_SERIAL_MOS7720) += mos7720.o
41obj-$(CONFIG_USB_SERIAL_MOS7840) += mos7840.o 39obj-$(CONFIG_USB_SERIAL_MOS7840) += mos7840.o
42obj-$(CONFIG_USB_SERIAL_MOTOROLA) += moto_modem.o
43obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o 40obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o
44obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o 41obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o
45obj-$(CONFIG_USB_SERIAL_OPTICON) += opticon.o 42obj-$(CONFIG_USB_SERIAL_OPTICON) += opticon.o
@@ -50,11 +47,10 @@ obj-$(CONFIG_USB_SERIAL_QCAUX) += qcaux.o
50obj-$(CONFIG_USB_SERIAL_QUALCOMM) += qcserial.o 47obj-$(CONFIG_USB_SERIAL_QUALCOMM) += qcserial.o
51obj-$(CONFIG_USB_SERIAL_QT2) += quatech2.o 48obj-$(CONFIG_USB_SERIAL_QT2) += quatech2.o
52obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o 49obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o
53obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o
54obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o 50obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o
51obj-$(CONFIG_USB_SERIAL_SIMPLE) += usb-serial-simple.o
55obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o 52obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o
56obj-$(CONFIG_USB_SERIAL_SSU100) += ssu100.o 53obj-$(CONFIG_USB_SERIAL_SSU100) += ssu100.o
57obj-$(CONFIG_USB_SERIAL_SUUNTO) += suunto.o
58obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o 54obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o
59obj-$(CONFIG_USB_SERIAL_WWAN) += usb_wwan.o 55obj-$(CONFIG_USB_SERIAL_WWAN) += usb_wwan.o
60obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o 56obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
@@ -62,8 +58,5 @@ obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o
62obj-$(CONFIG_USB_SERIAL_WISHBONE) += wishbone-serial.o 58obj-$(CONFIG_USB_SERIAL_WISHBONE) += wishbone-serial.o
63obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 59obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
64obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o 60obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o
65obj-$(CONFIG_USB_SERIAL_VIVOPAY_SERIAL) += vivopay-serial.o
66obj-$(CONFIG_USB_SERIAL_XSENS_MT) += xsens_mt.o 61obj-$(CONFIG_USB_SERIAL_XSENS_MT) += xsens_mt.o
67obj-$(CONFIG_USB_SERIAL_ZIO) += zio.o
68obj-$(CONFIG_USB_SERIAL_ZTE) += zte_ev.o 62obj-$(CONFIG_USB_SERIAL_ZTE) += zte_ev.o
69obj-$(CONFIG_USB_SERIAL_FLASHLOADER) += flashloader.o
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index afb50eab2049..c69bb50d4663 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -151,11 +151,7 @@ static int usb_console_setup(struct console *co, char *options)
151 151
152 /* only call the device specific open if this 152 /* only call the device specific open if this
153 * is the first time the port is opened */ 153 * is the first time the port is opened */
154 if (serial->type->open) 154 retval = serial->type->open(NULL, port);
155 retval = serial->type->open(NULL, port);
156 else
157 retval = usb_serial_generic_open(NULL, port);
158
159 if (retval) { 155 if (retval) {
160 dev_err(&port->dev, "could not open USB console port\n"); 156 dev_err(&port->dev, "could not open USB console port\n");
161 goto fail; 157 goto fail;
@@ -210,10 +206,10 @@ static void usb_console_write(struct console *co,
210 if (count == 0) 206 if (count == 0)
211 return; 207 return;
212 208
213 pr_debug("%s - minor %d, %d byte(s)\n", __func__, port->minor, count); 209 dev_dbg(&port->dev, "%s - %d byte(s)\n", __func__, count);
214 210
215 if (!port->port.console) { 211 if (!port->port.console) {
216 pr_debug("%s - port not opened\n", __func__); 212 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
217 return; 213 return;
218 } 214 }
219 215
@@ -230,21 +226,14 @@ static void usb_console_write(struct console *co,
230 } 226 }
231 /* pass on to the driver specific version of this function if 227 /* pass on to the driver specific version of this function if
232 it is available */ 228 it is available */
233 if (serial->type->write) 229 retval = serial->type->write(NULL, port, buf, i);
234 retval = serial->type->write(NULL, port, buf, i); 230 dev_dbg(&port->dev, "%s - write: %d\n", __func__, retval);
235 else
236 retval = usb_serial_generic_write(NULL, port, buf, i);
237 pr_debug("%s - return value : %d\n", __func__, retval);
238 if (lf) { 231 if (lf) {
239 /* append CR after LF */ 232 /* append CR after LF */
240 unsigned char cr = 13; 233 unsigned char cr = 13;
241 if (serial->type->write) 234 retval = serial->type->write(NULL, port, &cr, 1);
242 retval = serial->type->write(NULL, 235 dev_dbg(&port->dev, "%s - write cr: %d\n",
243 port, &cr, 1); 236 __func__, retval);
244 else
245 retval = usb_serial_generic_write(NULL,
246 port, &cr, 1);
247 pr_debug("%s - return value : %d\n", __func__, retval);
248 } 237 }
249 buf += i; 238 buf += i;
250 count -= i; 239 count -= i;
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 0eae4ba3760e..6987b535aa98 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -670,9 +670,6 @@ static void cp210x_set_termios(struct tty_struct *tty,
670 unsigned int bits; 670 unsigned int bits;
671 unsigned int modem_ctl[4]; 671 unsigned int modem_ctl[4];
672 672
673 if (!tty)
674 return;
675
676 cflag = tty->termios.c_cflag; 673 cflag = tty->termios.c_cflag;
677 old_cflag = old_termios->c_cflag; 674 old_cflag = old_termios->c_cflag;
678 675
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index e948dc02795d..558605d646f3 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -495,6 +495,8 @@ static int cypress_generic_port_probe(struct usb_serial_port *port)
495 } 495 }
496 usb_set_serial_port_data(port, priv); 496 usb_set_serial_port_data(port, priv);
497 497
498 port->port.drain_delay = 256;
499
498 return 0; 500 return 0;
499} 501}
500 502
@@ -625,7 +627,7 @@ static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port)
625 __func__, result); 627 __func__, result);
626 cypress_set_dead(port); 628 cypress_set_dead(port);
627 } 629 }
628 port->port.drain_delay = 256; 630
629 return result; 631 return result;
630} /* cypress_open */ 632} /* cypress_open */
631 633
diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c
index 75e85cbf9e8b..639a18fb67e6 100644
--- a/drivers/usb/serial/f81232.c
+++ b/drivers/usb/serial/f81232.c
@@ -207,7 +207,6 @@ static int f81232_open(struct tty_struct *tty, struct usb_serial_port *port)
207 return result; 207 return result;
208 } 208 }
209 209
210 port->port.drain_delay = 256;
211 return 0; 210 return 0;
212} 211}
213 212
@@ -322,6 +321,8 @@ static int f81232_port_probe(struct usb_serial_port *port)
322 321
323 usb_set_serial_port_data(port, priv); 322 usb_set_serial_port_data(port, priv);
324 323
324 port->port.drain_delay = 256;
325
325 return 0; 326 return 0;
326} 327}
327 328
diff --git a/drivers/usb/serial/flashloader.c b/drivers/usb/serial/flashloader.c
deleted file mode 100644
index e6f5c10e891c..000000000000
--- a/drivers/usb/serial/flashloader.c
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 * Infineon Flashloader driver
3 *
4 * Copyright (C) 2013 Wei Shuai <cpuwolf@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 version
8 * 2 as published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/tty.h>
14#include <linux/module.h>
15#include <linux/usb.h>
16#include <linux/usb/serial.h>
17#include <linux/uaccess.h>
18
19static const struct usb_device_id id_table[] = {
20 { USB_DEVICE(0x8087, 0x0716) },
21 { },
22};
23MODULE_DEVICE_TABLE(usb, id_table);
24
25static struct usb_serial_driver flashloader_device = {
26 .driver = {
27 .owner = THIS_MODULE,
28 .name = "flashloader",
29 },
30 .id_table = id_table,
31 .num_ports = 1,
32};
33
34static struct usb_serial_driver * const serial_drivers[] = {
35 &flashloader_device, NULL
36};
37
38module_usb_serial_driver(serial_drivers, id_table);
39MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index b65e657c641d..dbf2f2818823 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -51,8 +51,6 @@
51#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>, Andreas Mohr, Johan Hovold <jhovold@gmail.com>" 51#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>, Andreas Mohr, Johan Hovold <jhovold@gmail.com>"
52#define DRIVER_DESC "USB FTDI Serial Converters Driver" 52#define DRIVER_DESC "USB FTDI Serial Converters Driver"
53 53
54static __u16 vendor = FTDI_VID;
55static __u16 product;
56 54
57struct ftdi_private { 55struct ftdi_private {
58 enum ftdi_chip_type chip_type; 56 enum ftdi_chip_type chip_type;
@@ -144,8 +142,8 @@ static struct ftdi_sio_quirk ftdi_8u2232c_quirk = {
144 142
145 143
146/* 144/*
147 * Device ID not listed? Test via module params product/vendor or 145 * Device ID not listed? Test it using
148 * /sys/bus/usb/ftdi_sio/new_id, then send patch/report! 146 * /sys/bus/usb-serial/drivers/ftdi_sio/new_id and send a patch or report.
149 */ 147 */
150static struct usb_device_id id_table_combined [] = { 148static struct usb_device_id id_table_combined [] = {
151 { USB_DEVICE(FTDI_VID, FTDI_ZEITCONTROL_TAGTRACE_MIFARE_PID) }, 149 { USB_DEVICE(FTDI_VID, FTDI_ZEITCONTROL_TAGTRACE_MIFARE_PID) },
@@ -906,7 +904,6 @@ static struct usb_device_id id_table_combined [] = {
906 { USB_DEVICE(FTDI_VID, FTDI_LUMEL_PD12_PID) }, 904 { USB_DEVICE(FTDI_VID, FTDI_LUMEL_PD12_PID) },
907 /* Crucible Devices */ 905 /* Crucible Devices */
908 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) }, 906 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) },
909 { }, /* Optional parameter entry */
910 { } /* Terminating entry */ 907 { } /* Terminating entry */
911}; 908};
912 909
@@ -930,9 +927,6 @@ static const char *ftdi_chip_name[] = {
930#define FTDI_STATUS_B1_MASK (FTDI_RS_BI) 927#define FTDI_STATUS_B1_MASK (FTDI_RS_BI)
931/* End TIOCMIWAIT */ 928/* End TIOCMIWAIT */
932 929
933#define FTDI_IMPL_ASYNC_FLAGS = (ASYNC_SPD_HI | ASYNC_SPD_VHI \
934 | ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP)
935
936/* function prototypes for a FTDI serial converter */ 930/* function prototypes for a FTDI serial converter */
937static int ftdi_sio_probe(struct usb_serial *serial, 931static int ftdi_sio_probe(struct usb_serial *serial,
938 const struct usb_device_id *id); 932 const struct usb_device_id *id);
@@ -999,10 +993,6 @@ static struct usb_serial_driver * const serial_drivers[] = {
999#define WDR_TIMEOUT 5000 /* default urb timeout */ 993#define WDR_TIMEOUT 5000 /* default urb timeout */
1000#define WDR_SHORT_TIMEOUT 1000 /* shorter urb timeout */ 994#define WDR_SHORT_TIMEOUT 1000 /* shorter urb timeout */
1001 995
1002/* High and low are for DTR, RTS etc etc */
1003#define HIGH 1
1004#define LOW 0
1005
1006/* 996/*
1007 * *************************************************************************** 997 * ***************************************************************************
1008 * Utility functions 998 * Utility functions
@@ -1867,7 +1857,6 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1867 1857
1868static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port) 1858static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1869{ 1859{
1870 struct ktermios dummy;
1871 struct usb_device *dev = port->serial->dev; 1860 struct usb_device *dev = port->serial->dev;
1872 struct ftdi_private *priv = usb_get_serial_port_data(port); 1861 struct ftdi_private *priv = usb_get_serial_port_data(port);
1873 1862
@@ -1883,10 +1872,8 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1883 This is same behaviour as serial.c/rs_open() - Kuba */ 1872 This is same behaviour as serial.c/rs_open() - Kuba */
1884 1873
1885 /* ftdi_set_termios will send usb control messages */ 1874 /* ftdi_set_termios will send usb control messages */
1886 if (tty) { 1875 if (tty)
1887 memset(&dummy, 0, sizeof(dummy)); 1876 ftdi_set_termios(tty, port, NULL);
1888 ftdi_set_termios(tty, port, &dummy);
1889 }
1890 1877
1891 return usb_serial_generic_open(tty, port); 1878 return usb_serial_generic_open(tty, port);
1892} 1879}
@@ -2215,7 +2202,7 @@ no_data_parity_stop_changes:
2215 dev_err(ddev, "%s urb failed to set baudrate\n", __func__); 2202 dev_err(ddev, "%s urb failed to set baudrate\n", __func__);
2216 mutex_unlock(&priv->cfg_lock); 2203 mutex_unlock(&priv->cfg_lock);
2217 /* Ensure RTS and DTR are raised when baudrate changed from 0 */ 2204 /* Ensure RTS and DTR are raised when baudrate changed from 0 */
2218 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) 2205 if (old_termios && (old_termios->c_cflag & CBAUD) == B0)
2219 set_mctrl(port, TIOCM_DTR | TIOCM_RTS); 2206 set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2220 } 2207 }
2221 2208
@@ -2405,38 +2392,11 @@ static int ftdi_ioctl(struct tty_struct *tty,
2405 return -ENOIOCTLCMD; 2392 return -ENOIOCTLCMD;
2406} 2393}
2407 2394
2408static int __init ftdi_init(void) 2395module_usb_serial_driver(serial_drivers, id_table_combined);
2409{
2410 if (vendor > 0 && product > 0) {
2411 /* Add user specified VID/PID to reserved element of table. */
2412 int i;
2413 for (i = 0; id_table_combined[i].idVendor; i++)
2414 ;
2415 id_table_combined[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
2416 id_table_combined[i].idVendor = vendor;
2417 id_table_combined[i].idProduct = product;
2418 }
2419 return usb_serial_register_drivers(serial_drivers, KBUILD_MODNAME, id_table_combined);
2420}
2421
2422static void __exit ftdi_exit(void)
2423{
2424 usb_serial_deregister_drivers(serial_drivers);
2425}
2426
2427
2428module_init(ftdi_init);
2429module_exit(ftdi_exit);
2430 2396
2431MODULE_AUTHOR(DRIVER_AUTHOR); 2397MODULE_AUTHOR(DRIVER_AUTHOR);
2432MODULE_DESCRIPTION(DRIVER_DESC); 2398MODULE_DESCRIPTION(DRIVER_DESC);
2433MODULE_LICENSE("GPL"); 2399MODULE_LICENSE("GPL");
2434 2400
2435module_param(vendor, ushort, 0);
2436MODULE_PARM_DESC(vendor, "User specified vendor ID (default="
2437 __MODULE_STRING(FTDI_VID)")");
2438module_param(product, ushort, 0);
2439MODULE_PARM_DESC(product, "User specified product ID");
2440
2441module_param(ndi_latency_timer, int, S_IRUGO | S_IWUSR); 2401module_param(ndi_latency_timer, int, S_IRUGO | S_IWUSR);
2442MODULE_PARM_DESC(ndi_latency_timer, "NDI device latency timer override"); 2402MODULE_PARM_DESC(ndi_latency_timer, "NDI device latency timer override");
diff --git a/drivers/usb/serial/funsoft.c b/drivers/usb/serial/funsoft.c
deleted file mode 100644
index 9362f8fd2385..000000000000
--- a/drivers/usb/serial/funsoft.c
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * Funsoft Serial USB driver
3 *
4 * Copyright (C) 2006 Greg Kroah-Hartman <gregkh@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/tty.h>
14#include <linux/module.h>
15#include <linux/usb.h>
16#include <linux/usb/serial.h>
17#include <linux/uaccess.h>
18
19static const struct usb_device_id id_table[] = {
20 { USB_DEVICE(0x1404, 0xcddc) },
21 { },
22};
23MODULE_DEVICE_TABLE(usb, id_table);
24
25static struct usb_serial_driver funsoft_device = {
26 .driver = {
27 .owner = THIS_MODULE,
28 .name = "funsoft",
29 },
30 .id_table = id_table,
31 .num_ports = 1,
32};
33
34static struct usb_serial_driver * const serial_drivers[] = {
35 &funsoft_device, NULL
36};
37
38module_usb_serial_driver(serial_drivers, id_table);
39
40MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index ba45170c78e5..1f31e6b4c251 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -460,12 +460,7 @@ static bool usb_serial_generic_msr_changed(struct tty_struct *tty,
460 /* 460 /*
461 * Use tty-port initialised flag to detect all hangups including the 461 * Use tty-port initialised flag to detect all hangups including the
462 * one generated at USB-device disconnect. 462 * one generated at USB-device disconnect.
463 *
464 * FIXME: Remove hupping check once tty_port_hangup calls shutdown
465 * (which clears the initialised flag) before wake up.
466 */ 463 */
467 if (test_bit(TTY_HUPPING, &tty->flags))
468 return true;
469 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 464 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags))
470 return true; 465 return true;
471 466
@@ -496,12 +491,8 @@ int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg)
496 491
497 ret = wait_event_interruptible(port->port.delta_msr_wait, 492 ret = wait_event_interruptible(port->port.delta_msr_wait,
498 usb_serial_generic_msr_changed(tty, arg, &cnow)); 493 usb_serial_generic_msr_changed(tty, arg, &cnow));
499 if (!ret) { 494 if (!ret && !test_bit(ASYNCB_INITIALIZED, &port->port.flags))
500 if (test_bit(TTY_HUPPING, &tty->flags)) 495 ret = -EIO;
501 ret = -EIO;
502 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags))
503 ret = -EIO;
504 }
505 496
506 return ret; 497 return ret;
507} 498}
diff --git a/drivers/usb/serial/hp4x.c b/drivers/usb/serial/hp4x.c
deleted file mode 100644
index 2cba60d90c79..000000000000
--- a/drivers/usb/serial/hp4x.c
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 * HP4x Calculators Serial USB driver
3 *
4 * Copyright (C) 2005 Arthur Huillet (ahuillet@users.sf.net)
5 * Copyright (C) 2001-2005 Greg Kroah-Hartman (greg@kroah.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 * See Documentation/usb/usb-serial.txt for more information on using this
13 * driver
14 */
15
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/tty.h>
19#include <linux/module.h>
20#include <linux/usb.h>
21#include <linux/usb/serial.h>
22
23#define DRIVER_DESC "HP4x (48/49) Generic Serial driver"
24
25#define HP_VENDOR_ID 0x03f0
26#define HP49GP_PRODUCT_ID 0x0121
27
28static const struct usb_device_id id_table[] = {
29 { USB_DEVICE(HP_VENDOR_ID, HP49GP_PRODUCT_ID) },
30 { } /* Terminating entry */
31};
32
33MODULE_DEVICE_TABLE(usb, id_table);
34
35static struct usb_serial_driver hp49gp_device = {
36 .driver = {
37 .owner = THIS_MODULE,
38 .name = "hp4X",
39 },
40 .id_table = id_table,
41 .num_ports = 1,
42};
43
44static struct usb_serial_driver * const serial_drivers[] = {
45 &hp49gp_device, NULL
46};
47
48module_usb_serial_driver(serial_drivers, id_table);
49
50MODULE_DESCRIPTION(DRIVER_DESC);
51MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index dc2803b5eb09..c91481d74a14 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -56,9 +56,7 @@
56 56
57#define MAX_NAME_LEN 64 57#define MAX_NAME_LEN 64
58 58
59#define CHASE_TIMEOUT (5*HZ) /* 5 seconds */
60#define OPEN_TIMEOUT (5*HZ) /* 5 seconds */ 59#define OPEN_TIMEOUT (5*HZ) /* 5 seconds */
61#define COMMAND_TIMEOUT (5*HZ) /* 5 seconds */
62 60
63/* receive port state */ 61/* receive port state */
64enum RXSTATE { 62enum RXSTATE {
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 60054e72b75b..9c18f5985c8d 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -64,8 +64,6 @@
64 64
65#define EDGE_CLOSING_WAIT 4000 /* in .01 sec */ 65#define EDGE_CLOSING_WAIT 4000 /* in .01 sec */
66 66
67#define EDGE_OUT_BUF_SIZE 1024
68
69 67
70/* Product information read from the Edgeport */ 68/* Product information read from the Edgeport */
71struct product_info { 69struct product_info {
@@ -93,7 +91,6 @@ struct edgeport_port {
93 spinlock_t ep_lock; 91 spinlock_t ep_lock;
94 int ep_read_urb_state; 92 int ep_read_urb_state;
95 int ep_write_urb_in_use; 93 int ep_write_urb_in_use;
96 struct kfifo write_fifo;
97}; 94};
98 95
99struct edgeport_serial { 96struct edgeport_serial {
@@ -1732,22 +1729,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
1732 return -ENODEV; 1729 return -ENODEV;
1733 1730
1734 port_number = port->port_number; 1731 port_number = port->port_number;
1735 switch (port_number) {
1736 case 0:
1737 edge_port->uart_base = UMPMEM_BASE_UART1;
1738 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1739 break;
1740 case 1:
1741 edge_port->uart_base = UMPMEM_BASE_UART2;
1742 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1743 break;
1744 default:
1745 dev_err(&port->dev, "Unknown port number!!!\n");
1746 return -ENODEV;
1747 }
1748
1749 dev_dbg(&port->dev, "%s - port_number = %d, uart_base = %04x, dma_address = %04x\n",
1750 __func__, port_number, edge_port->uart_base, edge_port->dma_address);
1751 1732
1752 dev = port->serial->dev; 1733 dev = port->serial->dev;
1753 1734
@@ -1872,8 +1853,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
1872 1853
1873 ++edge_serial->num_ports_open; 1854 ++edge_serial->num_ports_open;
1874 1855
1875 port->port.drain_delay = 1;
1876
1877 goto release_es_lock; 1856 goto release_es_lock;
1878 1857
1879unlink_int_urb: 1858unlink_int_urb:
@@ -1905,7 +1884,7 @@ static void edge_close(struct usb_serial_port *port)
1905 usb_kill_urb(port->write_urb); 1884 usb_kill_urb(port->write_urb);
1906 edge_port->ep_write_urb_in_use = 0; 1885 edge_port->ep_write_urb_in_use = 0;
1907 spin_lock_irqsave(&edge_port->ep_lock, flags); 1886 spin_lock_irqsave(&edge_port->ep_lock, flags);
1908 kfifo_reset_out(&edge_port->write_fifo); 1887 kfifo_reset_out(&port->write_fifo);
1909 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1888 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1910 1889
1911 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__); 1890 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__);
@@ -1939,7 +1918,7 @@ static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
1939 if (edge_port->close_pending == 1) 1918 if (edge_port->close_pending == 1)
1940 return -ENODEV; 1919 return -ENODEV;
1941 1920
1942 count = kfifo_in_locked(&edge_port->write_fifo, data, count, 1921 count = kfifo_in_locked(&port->write_fifo, data, count,
1943 &edge_port->ep_lock); 1922 &edge_port->ep_lock);
1944 edge_send(port, tty); 1923 edge_send(port, tty);
1945 1924
@@ -1959,7 +1938,7 @@ static void edge_send(struct usb_serial_port *port, struct tty_struct *tty)
1959 return; 1938 return;
1960 } 1939 }
1961 1940
1962 count = kfifo_out(&edge_port->write_fifo, 1941 count = kfifo_out(&port->write_fifo,
1963 port->write_urb->transfer_buffer, 1942 port->write_urb->transfer_buffer,
1964 port->bulk_out_size); 1943 port->bulk_out_size);
1965 1944
@@ -2007,7 +1986,7 @@ static int edge_write_room(struct tty_struct *tty)
2007 return 0; 1986 return 0;
2008 1987
2009 spin_lock_irqsave(&edge_port->ep_lock, flags); 1988 spin_lock_irqsave(&edge_port->ep_lock, flags);
2010 room = kfifo_avail(&edge_port->write_fifo); 1989 room = kfifo_avail(&port->write_fifo);
2011 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1990 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2012 1991
2013 dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); 1992 dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
@@ -2024,7 +2003,7 @@ static int edge_chars_in_buffer(struct tty_struct *tty)
2024 return 0; 2003 return 0;
2025 2004
2026 spin_lock_irqsave(&edge_port->ep_lock, flags); 2005 spin_lock_irqsave(&edge_port->ep_lock, flags);
2027 chars = kfifo_len(&edge_port->write_fifo); 2006 chars = kfifo_len(&port->write_fifo);
2028 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2007 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2029 2008
2030 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); 2009 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
@@ -2451,30 +2430,45 @@ static int edge_port_probe(struct usb_serial_port *port)
2451 if (!edge_port) 2430 if (!edge_port)
2452 return -ENOMEM; 2431 return -ENOMEM;
2453 2432
2454 ret = kfifo_alloc(&edge_port->write_fifo, EDGE_OUT_BUF_SIZE,
2455 GFP_KERNEL);
2456 if (ret) {
2457 kfree(edge_port);
2458 return -ENOMEM;
2459 }
2460
2461 spin_lock_init(&edge_port->ep_lock); 2433 spin_lock_init(&edge_port->ep_lock);
2462 edge_port->port = port; 2434 edge_port->port = port;
2463 edge_port->edge_serial = usb_get_serial_data(port->serial); 2435 edge_port->edge_serial = usb_get_serial_data(port->serial);
2464 edge_port->bUartMode = default_uart_mode; 2436 edge_port->bUartMode = default_uart_mode;
2465 2437
2438 switch (port->port_number) {
2439 case 0:
2440 edge_port->uart_base = UMPMEM_BASE_UART1;
2441 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
2442 break;
2443 case 1:
2444 edge_port->uart_base = UMPMEM_BASE_UART2;
2445 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
2446 break;
2447 default:
2448 dev_err(&port->dev, "unknown port number\n");
2449 ret = -ENODEV;
2450 goto err;
2451 }
2452
2453 dev_dbg(&port->dev,
2454 "%s - port_number = %d, uart_base = %04x, dma_address = %04x\n",
2455 __func__, port->port_number, edge_port->uart_base,
2456 edge_port->dma_address);
2457
2466 usb_set_serial_port_data(port, edge_port); 2458 usb_set_serial_port_data(port, edge_port);
2467 2459
2468 ret = edge_create_sysfs_attrs(port); 2460 ret = edge_create_sysfs_attrs(port);
2469 if (ret) { 2461 if (ret)
2470 kfifo_free(&edge_port->write_fifo); 2462 goto err;
2471 kfree(edge_port);
2472 return ret;
2473 }
2474 2463
2475 port->port.closing_wait = msecs_to_jiffies(closing_wait * 10); 2464 port->port.closing_wait = msecs_to_jiffies(closing_wait * 10);
2465 port->port.drain_delay = 1;
2476 2466
2477 return 0; 2467 return 0;
2468err:
2469 kfree(edge_port);
2470
2471 return ret;
2478} 2472}
2479 2473
2480static int edge_port_remove(struct usb_serial_port *port) 2474static int edge_port_remove(struct usb_serial_port *port)
@@ -2483,7 +2477,6 @@ static int edge_port_remove(struct usb_serial_port *port)
2483 2477
2484 edge_port = usb_get_serial_port_data(port); 2478 edge_port = usb_get_serial_port_data(port);
2485 edge_remove_sysfs_attrs(port); 2479 edge_remove_sysfs_attrs(port);
2486 kfifo_free(&edge_port->write_fifo);
2487 kfree(edge_port); 2480 kfree(edge_port);
2488 2481
2489 return 0; 2482 return 0;
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 58c17fdc85eb..d6960aebe246 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -50,23 +50,27 @@
50#define INSTAT_BUFLEN 32 50#define INSTAT_BUFLEN 32
51#define GLOCONT_BUFLEN 64 51#define GLOCONT_BUFLEN 64
52#define INDAT49W_BUFLEN 512 52#define INDAT49W_BUFLEN 512
53#define IN_BUFLEN 64
54#define OUT_BUFLEN 64
55#define INACK_BUFLEN 1
56#define OUTCONT_BUFLEN 64
53 57
54 /* Per device and per port private data */ 58 /* Per device and per port private data */
55struct keyspan_serial_private { 59struct keyspan_serial_private {
56 const struct keyspan_device_details *device_details; 60 const struct keyspan_device_details *device_details;
57 61
58 struct urb *instat_urb; 62 struct urb *instat_urb;
59 char instat_buf[INSTAT_BUFLEN]; 63 char *instat_buf;
60 64
61 /* added to support 49wg, where data from all 4 ports comes in 65 /* added to support 49wg, where data from all 4 ports comes in
62 on 1 EP and high-speed supported */ 66 on 1 EP and high-speed supported */
63 struct urb *indat_urb; 67 struct urb *indat_urb;
64 char indat_buf[INDAT49W_BUFLEN]; 68 char *indat_buf;
65 69
66 /* XXX this one probably will need a lock */ 70 /* XXX this one probably will need a lock */
67 struct urb *glocont_urb; 71 struct urb *glocont_urb;
68 char glocont_buf[GLOCONT_BUFLEN]; 72 char *glocont_buf;
69 char ctrl_buf[8]; /* for EP0 control message */ 73 char *ctrl_buf; /* for EP0 control message */
70}; 74};
71 75
72struct keyspan_port_private { 76struct keyspan_port_private {
@@ -81,18 +85,18 @@ struct keyspan_port_private {
81 85
82 /* Input endpoints and buffer for this port */ 86 /* Input endpoints and buffer for this port */
83 struct urb *in_urbs[2]; 87 struct urb *in_urbs[2];
84 char in_buffer[2][64]; 88 char *in_buffer[2];
85 /* Output endpoints and buffer for this port */ 89 /* Output endpoints and buffer for this port */
86 struct urb *out_urbs[2]; 90 struct urb *out_urbs[2];
87 char out_buffer[2][64]; 91 char *out_buffer[2];
88 92
89 /* Input ack endpoint */ 93 /* Input ack endpoint */
90 struct urb *inack_urb; 94 struct urb *inack_urb;
91 char inack_buffer[1]; 95 char *inack_buffer;
92 96
93 /* Output control endpoint */ 97 /* Output control endpoint */
94 struct urb *outcont_urb; 98 struct urb *outcont_urb;
95 char outcont_buffer[64]; 99 char *outcont_buffer;
96 100
97 /* Settings for the port */ 101 /* Settings for the port */
98 int baud; 102 int baud;
@@ -2313,6 +2317,22 @@ static int keyspan_startup(struct usb_serial *serial)
2313 return -ENOMEM; 2317 return -ENOMEM;
2314 } 2318 }
2315 2319
2320 s_priv->instat_buf = kzalloc(INSTAT_BUFLEN, GFP_KERNEL);
2321 if (!s_priv->instat_buf)
2322 goto err_instat_buf;
2323
2324 s_priv->indat_buf = kzalloc(INDAT49W_BUFLEN, GFP_KERNEL);
2325 if (!s_priv->indat_buf)
2326 goto err_indat_buf;
2327
2328 s_priv->glocont_buf = kzalloc(GLOCONT_BUFLEN, GFP_KERNEL);
2329 if (!s_priv->glocont_buf)
2330 goto err_glocont_buf;
2331
2332 s_priv->ctrl_buf = kzalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
2333 if (!s_priv->ctrl_buf)
2334 goto err_ctrl_buf;
2335
2316 s_priv->device_details = d_details; 2336 s_priv->device_details = d_details;
2317 usb_set_serial_data(serial, s_priv); 2337 usb_set_serial_data(serial, s_priv);
2318 2338
@@ -2330,6 +2350,17 @@ static int keyspan_startup(struct usb_serial *serial)
2330 } 2350 }
2331 2351
2332 return 0; 2352 return 0;
2353
2354err_ctrl_buf:
2355 kfree(s_priv->glocont_buf);
2356err_glocont_buf:
2357 kfree(s_priv->indat_buf);
2358err_indat_buf:
2359 kfree(s_priv->instat_buf);
2360err_instat_buf:
2361 kfree(s_priv);
2362
2363 return -ENOMEM;
2333} 2364}
2334 2365
2335static void keyspan_disconnect(struct usb_serial *serial) 2366static void keyspan_disconnect(struct usb_serial *serial)
@@ -2353,6 +2384,11 @@ static void keyspan_release(struct usb_serial *serial)
2353 usb_free_urb(s_priv->indat_urb); 2384 usb_free_urb(s_priv->indat_urb);
2354 usb_free_urb(s_priv->glocont_urb); 2385 usb_free_urb(s_priv->glocont_urb);
2355 2386
2387 kfree(s_priv->ctrl_buf);
2388 kfree(s_priv->glocont_buf);
2389 kfree(s_priv->indat_buf);
2390 kfree(s_priv->instat_buf);
2391
2356 kfree(s_priv); 2392 kfree(s_priv);
2357} 2393}
2358 2394
@@ -2374,6 +2410,26 @@ static int keyspan_port_probe(struct usb_serial_port *port)
2374 if (!p_priv) 2410 if (!p_priv)
2375 return -ENOMEM; 2411 return -ENOMEM;
2376 2412
2413 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i) {
2414 p_priv->in_buffer[i] = kzalloc(IN_BUFLEN, GFP_KERNEL);
2415 if (!p_priv->in_buffer[i])
2416 goto err_in_buffer;
2417 }
2418
2419 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i) {
2420 p_priv->out_buffer[i] = kzalloc(OUT_BUFLEN, GFP_KERNEL);
2421 if (!p_priv->out_buffer[i])
2422 goto err_out_buffer;
2423 }
2424
2425 p_priv->inack_buffer = kzalloc(INACK_BUFLEN, GFP_KERNEL);
2426 if (!p_priv->inack_buffer)
2427 goto err_inack_buffer;
2428
2429 p_priv->outcont_buffer = kzalloc(OUTCONT_BUFLEN, GFP_KERNEL);
2430 if (!p_priv->outcont_buffer)
2431 goto err_outcont_buffer;
2432
2377 p_priv->device_details = d_details; 2433 p_priv->device_details = d_details;
2378 2434
2379 /* Setup values for the various callback routines */ 2435 /* Setup values for the various callback routines */
@@ -2386,7 +2442,8 @@ static int keyspan_port_probe(struct usb_serial_port *port)
2386 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) { 2442 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
2387 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp, 2443 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
2388 USB_DIR_IN, port, 2444 USB_DIR_IN, port,
2389 p_priv->in_buffer[i], 64, 2445 p_priv->in_buffer[i],
2446 IN_BUFLEN,
2390 cback->indat_callback); 2447 cback->indat_callback);
2391 } 2448 }
2392 /* outdat endpoints also have flip */ 2449 /* outdat endpoints also have flip */
@@ -2394,25 +2451,41 @@ static int keyspan_port_probe(struct usb_serial_port *port)
2394 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) { 2451 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
2395 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp, 2452 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
2396 USB_DIR_OUT, port, 2453 USB_DIR_OUT, port,
2397 p_priv->out_buffer[i], 64, 2454 p_priv->out_buffer[i],
2455 OUT_BUFLEN,
2398 cback->outdat_callback); 2456 cback->outdat_callback);
2399 } 2457 }
2400 /* inack endpoint */ 2458 /* inack endpoint */
2401 p_priv->inack_urb = keyspan_setup_urb(serial, 2459 p_priv->inack_urb = keyspan_setup_urb(serial,
2402 d_details->inack_endpoints[port_num], 2460 d_details->inack_endpoints[port_num],
2403 USB_DIR_IN, port, 2461 USB_DIR_IN, port,
2404 p_priv->inack_buffer, 1, 2462 p_priv->inack_buffer,
2463 INACK_BUFLEN,
2405 cback->inack_callback); 2464 cback->inack_callback);
2406 /* outcont endpoint */ 2465 /* outcont endpoint */
2407 p_priv->outcont_urb = keyspan_setup_urb(serial, 2466 p_priv->outcont_urb = keyspan_setup_urb(serial,
2408 d_details->outcont_endpoints[port_num], 2467 d_details->outcont_endpoints[port_num],
2409 USB_DIR_OUT, port, 2468 USB_DIR_OUT, port,
2410 p_priv->outcont_buffer, 64, 2469 p_priv->outcont_buffer,
2470 OUTCONT_BUFLEN,
2411 cback->outcont_callback); 2471 cback->outcont_callback);
2412 2472
2413 usb_set_serial_port_data(port, p_priv); 2473 usb_set_serial_port_data(port, p_priv);
2414 2474
2415 return 0; 2475 return 0;
2476
2477err_outcont_buffer:
2478 kfree(p_priv->inack_buffer);
2479err_inack_buffer:
2480 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
2481 kfree(p_priv->out_buffer[i]);
2482err_out_buffer:
2483 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
2484 kfree(p_priv->in_buffer[i]);
2485err_in_buffer:
2486 kfree(p_priv);
2487
2488 return -ENOMEM;
2416} 2489}
2417 2490
2418static int keyspan_port_remove(struct usb_serial_port *port) 2491static int keyspan_port_remove(struct usb_serial_port *port)
@@ -2436,6 +2509,13 @@ static int keyspan_port_remove(struct usb_serial_port *port)
2436 usb_free_urb(p_priv->out_urbs[i]); 2509 usb_free_urb(p_priv->out_urbs[i]);
2437 } 2510 }
2438 2511
2512 kfree(p_priv->outcont_buffer);
2513 kfree(p_priv->inack_buffer);
2514 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
2515 kfree(p_priv->out_buffer[i]);
2516 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
2517 kfree(p_priv->in_buffer[i]);
2518
2439 kfree(p_priv); 2519 kfree(p_priv);
2440 2520
2441 return 0; 2521 return 0;
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 3bac4693c038..fdf953539c62 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -221,7 +221,6 @@ struct moschip_port {
221 __u8 shadowMCR; /* last MCR value received */ 221 __u8 shadowMCR; /* last MCR value received */
222 char open; 222 char open;
223 char open_ports; 223 char open_ports;
224 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
225 struct usb_serial_port *port; /* loop back to the owner of this object */ 224 struct usb_serial_port *port; /* loop back to the owner of this object */
226 225
227 /* Offsets */ 226 /* Offsets */
@@ -1100,9 +1099,6 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
1100 mos7840_port->read_urb_busy = false; 1099 mos7840_port->read_urb_busy = false;
1101 } 1100 }
1102 1101
1103 /* initialize our wait queues */
1104 init_waitqueue_head(&mos7840_port->wait_chase);
1105
1106 /* initialize our port settings */ 1102 /* initialize our port settings */
1107 /* Must set to enable ints! */ 1103 /* Must set to enable ints! */
1108 mos7840_port->shadowMCR = MCR_MASTER_IE; 1104 mos7840_port->shadowMCR = MCR_MASTER_IE;
@@ -1228,47 +1224,6 @@ static void mos7840_close(struct usb_serial_port *port)
1228 mos7840_port->open = 0; 1224 mos7840_port->open = 0;
1229} 1225}
1230 1226
1231/************************************************************************
1232 *
1233 * mos7840_block_until_chase_response
1234 *
1235 * This function will block the close until one of the following:
1236 * 1. Response to our Chase comes from mos7840
1237 * 2. A timeout of 10 seconds without activity has expired
1238 * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty)
1239 *
1240 ************************************************************************/
1241
1242static void mos7840_block_until_chase_response(struct tty_struct *tty,
1243 struct moschip_port *mos7840_port)
1244{
1245 int timeout = msecs_to_jiffies(1000);
1246 int wait = 10;
1247 int count;
1248
1249 while (1) {
1250 count = mos7840_chars_in_buffer(tty);
1251
1252 /* Check for Buffer status */
1253 if (count <= 0)
1254 return;
1255
1256 /* Block the thread for a while */
1257 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
1258 timeout);
1259 /* No activity.. count down section */
1260 wait--;
1261 if (wait == 0) {
1262 dev_dbg(&mos7840_port->port->dev, "%s - TIMEOUT\n", __func__);
1263 return;
1264 } else {
1265 /* Reset timeout value back to seconds */
1266 wait = 10;
1267 }
1268 }
1269
1270}
1271
1272/***************************************************************************** 1227/*****************************************************************************
1273 * mos7840_break 1228 * mos7840_break
1274 * this function sends a break to the port 1229 * this function sends a break to the port
@@ -1292,9 +1247,6 @@ static void mos7840_break(struct tty_struct *tty, int break_state)
1292 if (mos7840_port == NULL) 1247 if (mos7840_port == NULL)
1293 return; 1248 return;
1294 1249
1295 /* flush and block until tx is empty */
1296 mos7840_block_until_chase_response(tty, mos7840_port);
1297
1298 if (break_state == -1) 1250 if (break_state == -1)
1299 data = mos7840_port->shadowLCR | LCR_SET_BREAK; 1251 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
1300 else 1252 else
diff --git a/drivers/usb/serial/moto_modem.c b/drivers/usb/serial/moto_modem.c
deleted file mode 100644
index c5ff6c7795a6..000000000000
--- a/drivers/usb/serial/moto_modem.c
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2 * Motorola USB Phone driver
3 *
4 * Copyright (C) 2008 Greg Kroah-Hartman <greg@kroah.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * {sigh}
11 * Motorola should be using the CDC ACM USB spec, but instead
12 * they try to just "do their own thing"... This driver should handle a
13 * few phones in which a basic "dumb serial connection" is needed to be
14 * able to get a connection through to them.
15 */
16
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/tty.h>
20#include <linux/module.h>
21#include <linux/usb.h>
22#include <linux/usb/serial.h>
23
24static const struct usb_device_id id_table[] = {
25 { USB_DEVICE(0x05c6, 0x3197) }, /* unknown Motorola phone */
26 { USB_DEVICE(0x0c44, 0x0022) }, /* unknown Mororola phone */
27 { USB_DEVICE(0x22b8, 0x2a64) }, /* Motorola KRZR K1m */
28 { USB_DEVICE(0x22b8, 0x2c84) }, /* Motorola VE240 phone */
29 { USB_DEVICE(0x22b8, 0x2c64) }, /* Motorola V950 phone */
30 { },
31};
32MODULE_DEVICE_TABLE(usb, id_table);
33
34static struct usb_serial_driver moto_device = {
35 .driver = {
36 .owner = THIS_MODULE,
37 .name = "moto-modem",
38 },
39 .id_table = id_table,
40 .num_ports = 1,
41};
42
43static struct usb_serial_driver * const serial_drivers[] = {
44 &moto_device, NULL
45};
46
47module_usb_serial_driver(serial_drivers, id_table);
48MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index 7e3e0782e51f..a2080ac7b7e5 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -343,6 +343,8 @@ static int oti6858_port_probe(struct usb_serial_port *port)
343 343
344 usb_set_serial_port_data(port, priv); 344 usb_set_serial_port_data(port, priv);
345 345
346 port->port.drain_delay = 256; /* FIXME: check the FIFO length */
347
346 return 0; 348 return 0;
347} 349}
348 350
@@ -411,9 +413,6 @@ static void oti6858_set_termios(struct tty_struct *tty,
411 __le16 divisor; 413 __le16 divisor;
412 int br; 414 int br;
413 415
414 if (!tty)
415 return;
416
417 cflag = tty->termios.c_cflag; 416 cflag = tty->termios.c_cflag;
418 417
419 spin_lock_irqsave(&priv->lock, flags); 418 spin_lock_irqsave(&priv->lock, flags);
@@ -509,7 +508,6 @@ static void oti6858_set_termios(struct tty_struct *tty,
509static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port) 508static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port)
510{ 509{
511 struct oti6858_private *priv = usb_get_serial_port_data(port); 510 struct oti6858_private *priv = usb_get_serial_port_data(port);
512 struct ktermios tmp_termios;
513 struct usb_serial *serial = port->serial; 511 struct usb_serial *serial = port->serial;
514 struct oti6858_control_pkt *buf; 512 struct oti6858_control_pkt *buf;
515 unsigned long flags; 513 unsigned long flags;
@@ -560,8 +558,8 @@ static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port)
560 558
561 /* setup termios */ 559 /* setup termios */
562 if (tty) 560 if (tty)
563 oti6858_set_termios(tty, port, &tmp_termios); 561 oti6858_set_termios(tty, port, NULL);
564 port->port.drain_delay = 256; /* FIXME: check the FIFO length */ 562
565 return 0; 563 return 0;
566} 564}
567 565
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index cb6bbed374f2..e7a84f0f5179 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -4,6 +4,11 @@
4 * Copyright (C) 2001-2007 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 2001-2007 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2003 IBM Corp. 5 * Copyright (C) 2003 IBM Corp.
6 * 6 *
7 * Copyright (C) 2009, 2013 Frank Schäfer <fschaefer.oss@googlemail.com>
8 * - fixes, improvements and documentation for the baud rate encoding methods
9 * Copyright (C) 2013 Reinhard Max <max@suse.de>
10 * - fixes and improvements for the divisor based baud rate encoding method
11 *
7 * Original driver for 2.2.x by anonymous 12 * Original driver for 2.2.x by anonymous
8 * 13 *
9 * This program is free software; you can redistribute it and/or 14 * This program is free software; you can redistribute it and/or
@@ -29,6 +34,7 @@
29#include <linux/uaccess.h> 34#include <linux/uaccess.h>
30#include <linux/usb.h> 35#include <linux/usb.h>
31#include <linux/usb/serial.h> 36#include <linux/usb/serial.h>
37#include <asm/unaligned.h>
32#include "pl2303.h" 38#include "pl2303.h"
33 39
34/* 40/*
@@ -128,10 +134,17 @@ MODULE_DEVICE_TABLE(usb, id_table);
128 134
129 135
130enum pl2303_type { 136enum pl2303_type {
131 type_0, /* don't know the difference between type 0 and */ 137 type_0, /* H version ? */
132 type_1, /* type 1, until someone from prolific tells us... */ 138 type_1, /* H version ? */
133 HX, /* HX version of the pl2303 chip */ 139 HX_TA, /* HX(A) / X(A) / TA version */ /* TODO: improve */
140 HXD_EA_RA_SA, /* HXD / EA / RA / SA version */ /* TODO: improve */
141 TB, /* TB version */
134}; 142};
143/*
144 * NOTE: don't know the difference between type 0 and type 1,
145 * until someone from Prolific tells us...
146 * TODO: distinguish between X/HX, TA and HXD, EA, RA, SA variants
147 */
135 148
136struct pl2303_serial_private { 149struct pl2303_serial_private {
137 enum pl2303_type type; 150 enum pl2303_type type;
@@ -171,6 +184,7 @@ static int pl2303_startup(struct usb_serial *serial)
171{ 184{
172 struct pl2303_serial_private *spriv; 185 struct pl2303_serial_private *spriv;
173 enum pl2303_type type = type_0; 186 enum pl2303_type type = type_0;
187 char *type_str = "unknown (treating as type_0)";
174 unsigned char *buf; 188 unsigned char *buf;
175 189
176 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 190 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
@@ -183,15 +197,38 @@ static int pl2303_startup(struct usb_serial *serial)
183 return -ENOMEM; 197 return -ENOMEM;
184 } 198 }
185 199
186 if (serial->dev->descriptor.bDeviceClass == 0x02) 200 if (serial->dev->descriptor.bDeviceClass == 0x02) {
187 type = type_0; 201 type = type_0;
188 else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) 202 type_str = "type_0";
189 type = HX; 203 } else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) {
190 else if (serial->dev->descriptor.bDeviceClass == 0x00) 204 /*
191 type = type_1; 205 * NOTE: The bcdDevice version is the only difference between
192 else if (serial->dev->descriptor.bDeviceClass == 0xFF) 206 * the device descriptors of the X/HX, HXD, EA, RA, SA, TA, TB
207 */
208 if (le16_to_cpu(serial->dev->descriptor.bcdDevice) == 0x300) {
209 type = HX_TA;
210 type_str = "X/HX/TA";
211 } else if (le16_to_cpu(serial->dev->descriptor.bcdDevice)
212 == 0x400) {
213 type = HXD_EA_RA_SA;
214 type_str = "HXD/EA/RA/SA";
215 } else if (le16_to_cpu(serial->dev->descriptor.bcdDevice)
216 == 0x500) {
217 type = TB;
218 type_str = "TB";
219 } else {
220 dev_info(&serial->interface->dev,
221 "unknown/unsupported device type\n");
222 kfree(spriv);
223 kfree(buf);
224 return -ENODEV;
225 }
226 } else if (serial->dev->descriptor.bDeviceClass == 0x00
227 || serial->dev->descriptor.bDeviceClass == 0xFF) {
193 type = type_1; 228 type = type_1;
194 dev_dbg(&serial->interface->dev, "device type: %d\n", type); 229 type_str = "type_1";
230 }
231 dev_dbg(&serial->interface->dev, "device type: %s\n", type_str);
195 232
196 spriv->type = type; 233 spriv->type = type;
197 usb_set_serial_data(serial, spriv); 234 usb_set_serial_data(serial, spriv);
@@ -206,10 +243,10 @@ static int pl2303_startup(struct usb_serial *serial)
206 pl2303_vendor_read(0x8383, 0, serial, buf); 243 pl2303_vendor_read(0x8383, 0, serial, buf);
207 pl2303_vendor_write(0, 1, serial); 244 pl2303_vendor_write(0, 1, serial);
208 pl2303_vendor_write(1, 0, serial); 245 pl2303_vendor_write(1, 0, serial);
209 if (type == HX) 246 if (type == type_0 || type == type_1)
210 pl2303_vendor_write(2, 0x44, serial);
211 else
212 pl2303_vendor_write(2, 0x24, serial); 247 pl2303_vendor_write(2, 0x24, serial);
248 else
249 pl2303_vendor_write(2, 0x44, serial);
213 250
214 kfree(buf); 251 kfree(buf);
215 return 0; 252 return 0;
@@ -235,6 +272,8 @@ static int pl2303_port_probe(struct usb_serial_port *port)
235 272
236 usb_set_serial_port_data(port, priv); 273 usb_set_serial_port_data(port, priv);
237 274
275 port->port.drain_delay = 256;
276
238 return 0; 277 return 0;
239} 278}
240 279
@@ -261,6 +300,175 @@ static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value)
261 return retval; 300 return retval;
262} 301}
263 302
303static int pl2303_baudrate_encode_direct(int baud, enum pl2303_type type,
304 u8 buf[4])
305{
306 /*
307 * NOTE: Only the values defined in baud_sup are supported !
308 * => if unsupported values are set, the PL2303 seems to
309 * use 9600 baud (at least my PL2303X always does)
310 */
311 const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600,
312 4800, 7200, 9600, 14400, 19200, 28800, 38400,
313 57600, 115200, 230400, 460800, 614400, 921600,
314 1228800, 2457600, 3000000, 6000000, 12000000 };
315 /*
316 * NOTE: With the exception of type_0/1 devices, the following
317 * additional baud rates are supported (tested with HX rev. 3A only):
318 * 110*, 56000*, 128000, 134400, 161280, 201600, 256000*, 268800,
319 * 403200, 806400. (*: not HX)
320 *
321 * Maximum values: HXD, TB: 12000000; HX, TA: 6000000;
322 * type_0+1: 1228800; RA: 921600; SA: 115200
323 *
324 * As long as we are not using this encoding method for anything else
325 * than the type_0+1 and HX chips, there is no point in complicating
326 * the code to support them.
327 */
328 int i;
329
330 /* Set baudrate to nearest supported value */
331 for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) {
332 if (baud_sup[i] > baud)
333 break;
334 }
335 if (i == ARRAY_SIZE(baud_sup))
336 baud = baud_sup[i - 1];
337 else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1]))
338 baud = baud_sup[i - 1];
339 else
340 baud = baud_sup[i];
341 /* Respect the chip type specific baud rate limits */
342 /*
343 * FIXME: as long as we don't know how to distinguish between the
344 * HXD, EA, RA, and SA chip variants, allow the max. value of 12M.
345 */
346 if (type == HX_TA)
347 baud = min_t(int, baud, 6000000);
348 else if (type == type_0 || type == type_1)
349 baud = min_t(int, baud, 1228800);
350 /* Direct (standard) baud rate encoding method */
351 put_unaligned_le32(baud, buf);
352
353 return baud;
354}
355
356static int pl2303_baudrate_encode_divisor(int baud, enum pl2303_type type,
357 u8 buf[4])
358{
359 /*
360 * Divisor based baud rate encoding method
361 *
362 * NOTE: it's not clear if the type_0/1 chips support this method
363 *
364 * divisor = 12MHz * 32 / baudrate = 2^A * B
365 *
366 * with
367 *
368 * A = buf[1] & 0x0e
369 * B = buf[0] + (buf[1] & 0x01) << 8
370 *
371 * Special cases:
372 * => 8 < B < 16: device seems to work not properly
373 * => B <= 8: device uses the max. value B = 512 instead
374 */
375 unsigned int A, B;
376
377 /*
378 * NOTE: The Windows driver allows maximum baud rates of 110% of the
379 * specified maximium value.
380 * Quick tests with early (2004) HX (rev. A) chips suggest, that even
381 * higher baud rates (up to the maximum of 24M baud !) are working fine,
382 * but that should really be tested carefully in "real life" scenarios
383 * before removing the upper limit completely.
384 * Baud rates smaller than the specified 75 baud are definitely working
385 * fine.
386 */
387 if (type == type_0 || type == type_1)
388 baud = min_t(int, baud, 1228800 * 1.1);
389 else if (type == HX_TA)
390 baud = min_t(int, baud, 6000000 * 1.1);
391 else if (type == HXD_EA_RA_SA)
392 /* HXD, EA: 12Mbps; RA: 1Mbps; SA: 115200 bps */
393 /*
394 * FIXME: as long as we don't know how to distinguish between
395 * these chip variants, allow the max. of these values
396 */
397 baud = min_t(int, baud, 12000000 * 1.1);
398 else if (type == TB)
399 baud = min_t(int, baud, 12000000 * 1.1);
400 /* Determine factors A and B */
401 A = 0;
402 B = 12000000 * 32 / baud; /* 12MHz */
403 B <<= 1; /* Add one bit for rounding */
404 while (B > (512 << 1) && A <= 14) {
405 A += 2;
406 B >>= 2;
407 }
408 if (A > 14) { /* max. divisor = min. baudrate reached */
409 A = 14;
410 B = 512;
411 /* => ~45.78 baud */
412 } else {
413 B = (B + 1) >> 1; /* Round the last bit */
414 }
415 /* Handle special cases */
416 if (B == 512)
417 B = 0; /* also: 1 to 8 */
418 else if (B < 16)
419 /*
420 * NOTE: With the current algorithm this happens
421 * only for A=0 and means that the min. divisor
422 * (respectively: the max. baudrate) is reached.
423 */
424 B = 16; /* => 24 MBaud */
425 /* Encode the baud rate */
426 buf[3] = 0x80; /* Select divisor encoding method */
427 buf[2] = 0;
428 buf[1] = (A & 0x0e); /* A */
429 buf[1] |= ((B & 0x100) >> 8); /* MSB of B */
430 buf[0] = B & 0xff; /* 8 LSBs of B */
431 /* Calculate the actual/resulting baud rate */
432 if (B <= 8)
433 B = 512;
434 baud = 12000000 * 32 / ((1 << A) * B);
435
436 return baud;
437}
438
439static void pl2303_encode_baudrate(struct tty_struct *tty,
440 struct usb_serial_port *port,
441 enum pl2303_type type,
442 u8 buf[4])
443{
444 int baud;
445
446 baud = tty_get_baud_rate(tty);
447 dev_dbg(&port->dev, "baud requested = %d\n", baud);
448 if (!baud)
449 return;
450 /*
451 * There are two methods for setting/encoding the baud rate
452 * 1) Direct method: encodes the baud rate value directly
453 * => supported by all chip types
454 * 2) Divisor based method: encodes a divisor to a base value (12MHz*32)
455 * => supported by HX chips (and likely not by type_0/1 chips)
456 *
457 * NOTE: Although the divisor based baud rate encoding method is much
458 * more flexible, some of the standard baud rate values can not be
459 * realized exactly. But the difference is very small (max. 0.2%) and
460 * the device likely uses the same baud rate generator for both methods
461 * so that there is likley no difference.
462 */
463 if (type == type_0 || type == type_1)
464 baud = pl2303_baudrate_encode_direct(baud, type, buf);
465 else
466 baud = pl2303_baudrate_encode_divisor(baud, type, buf);
467 /* Save resulting baud rate */
468 tty_encode_baud_rate(tty, baud, baud);
469 dev_dbg(&port->dev, "baud set = %d\n", baud);
470}
471
264static void pl2303_set_termios(struct tty_struct *tty, 472static void pl2303_set_termios(struct tty_struct *tty,
265 struct usb_serial_port *port, struct ktermios *old_termios) 473 struct usb_serial_port *port, struct ktermios *old_termios)
266{ 474{
@@ -268,27 +476,18 @@ static void pl2303_set_termios(struct tty_struct *tty,
268 struct pl2303_serial_private *spriv = usb_get_serial_data(serial); 476 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
269 struct pl2303_private *priv = usb_get_serial_port_data(port); 477 struct pl2303_private *priv = usb_get_serial_port_data(port);
270 unsigned long flags; 478 unsigned long flags;
271 unsigned int cflag;
272 unsigned char *buf; 479 unsigned char *buf;
273 int baud;
274 int i; 480 int i;
275 u8 control; 481 u8 control;
276 const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600,
277 4800, 7200, 9600, 14400, 19200, 28800, 38400,
278 57600, 115200, 230400, 460800, 500000, 614400,
279 921600, 1228800, 2457600, 3000000, 6000000 };
280 int baud_floor, baud_ceil;
281 int k;
282
283 /* The PL2303 is reported to lose bytes if you change
284 serial settings even to the same values as before. Thus
285 we actually need to filter in this specific case */
286 482
483 /*
484 * The PL2303 is reported to lose bytes if you change serial settings
485 * even to the same values as before. Thus we actually need to filter
486 * in this specific case.
487 */
287 if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) 488 if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios))
288 return; 489 return;
289 490
290 cflag = tty->termios.c_cflag;
291
292 buf = kzalloc(7, GFP_KERNEL); 491 buf = kzalloc(7, GFP_KERNEL);
293 if (!buf) { 492 if (!buf) {
294 dev_err(&port->dev, "%s - out of memory.\n", __func__); 493 dev_err(&port->dev, "%s - out of memory.\n", __func__);
@@ -303,8 +502,8 @@ static void pl2303_set_termios(struct tty_struct *tty,
303 0, 0, buf, 7, 100); 502 0, 0, buf, 7, 100);
304 dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); 503 dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf);
305 504
306 if (cflag & CSIZE) { 505 if (C_CSIZE(tty)) {
307 switch (cflag & CSIZE) { 506 switch (C_CSIZE(tty)) {
308 case CS5: 507 case CS5:
309 buf[6] = 5; 508 buf[6] = 5;
310 break; 509 break;
@@ -317,73 +516,22 @@ static void pl2303_set_termios(struct tty_struct *tty,
317 default: 516 default:
318 case CS8: 517 case CS8:
319 buf[6] = 8; 518 buf[6] = 8;
320 break;
321 } 519 }
322 dev_dbg(&port->dev, "data bits = %d\n", buf[6]); 520 dev_dbg(&port->dev, "data bits = %d\n", buf[6]);
323 } 521 }
324 522
325 /* For reference buf[0]:buf[3] baud rate value */ 523 /* For reference: buf[0]:buf[3] baud rate value */
326 /* NOTE: Only the values defined in baud_sup are supported ! 524 pl2303_encode_baudrate(tty, port, spriv->type, buf);
327 * => if unsupported values are set, the PL2303 seems to use
328 * 9600 baud (at least my PL2303X always does)
329 */
330 baud = tty_get_baud_rate(tty);
331 dev_dbg(&port->dev, "baud requested = %d\n", baud);
332 if (baud) {
333 /* Set baudrate to nearest supported value */
334 for (k=0; k<ARRAY_SIZE(baud_sup); k++) {
335 if (baud_sup[k] / baud) {
336 baud_ceil = baud_sup[k];
337 if (k==0) {
338 baud = baud_ceil;
339 } else {
340 baud_floor = baud_sup[k-1];
341 if ((baud_ceil % baud)
342 > (baud % baud_floor))
343 baud = baud_floor;
344 else
345 baud = baud_ceil;
346 }
347 break;
348 }
349 }
350 if (baud > 1228800) {
351 /* type_0, type_1 only support up to 1228800 baud */
352 if (spriv->type != HX)
353 baud = 1228800;
354 else if (baud > 6000000)
355 baud = 6000000;
356 }
357 dev_dbg(&port->dev, "baud set = %d\n", baud);
358 if (baud <= 115200) {
359 buf[0] = baud & 0xff;
360 buf[1] = (baud >> 8) & 0xff;
361 buf[2] = (baud >> 16) & 0xff;
362 buf[3] = (baud >> 24) & 0xff;
363 } else {
364 /* apparently the formula for higher speeds is:
365 * baudrate = 12M * 32 / (2^buf[1]) / buf[0]
366 */
367 unsigned tmp = 12*1000*1000*32 / baud;
368 buf[3] = 0x80;
369 buf[2] = 0;
370 buf[1] = (tmp >= 256);
371 while (tmp >= 256) {
372 tmp >>= 2;
373 buf[1] <<= 1;
374 }
375 buf[0] = tmp;
376 }
377 }
378 525
379 /* For reference buf[4]=0 is 1 stop bits */ 526 /* For reference buf[4]=0 is 1 stop bits */
380 /* For reference buf[4]=1 is 1.5 stop bits */ 527 /* For reference buf[4]=1 is 1.5 stop bits */
381 /* For reference buf[4]=2 is 2 stop bits */ 528 /* For reference buf[4]=2 is 2 stop bits */
382 if (cflag & CSTOPB) { 529 if (C_CSTOPB(tty)) {
383 /* NOTE: Comply with "real" UARTs / RS232: 530 /*
531 * NOTE: Comply with "real" UARTs / RS232:
384 * use 1.5 instead of 2 stop bits with 5 data bits 532 * use 1.5 instead of 2 stop bits with 5 data bits
385 */ 533 */
386 if ((cflag & CSIZE) == CS5) { 534 if (C_CSIZE(tty) == CS5) {
387 buf[4] = 1; 535 buf[4] = 1;
388 dev_dbg(&port->dev, "stop bits = 1.5\n"); 536 dev_dbg(&port->dev, "stop bits = 1.5\n");
389 } else { 537 } else {
@@ -395,14 +543,14 @@ static void pl2303_set_termios(struct tty_struct *tty,
395 dev_dbg(&port->dev, "stop bits = 1\n"); 543 dev_dbg(&port->dev, "stop bits = 1\n");
396 } 544 }
397 545
398 if (cflag & PARENB) { 546 if (C_PARENB(tty)) {
399 /* For reference buf[5]=0 is none parity */ 547 /* For reference buf[5]=0 is none parity */
400 /* For reference buf[5]=1 is odd parity */ 548 /* For reference buf[5]=1 is odd parity */
401 /* For reference buf[5]=2 is even parity */ 549 /* For reference buf[5]=2 is even parity */
402 /* For reference buf[5]=3 is mark parity */ 550 /* For reference buf[5]=3 is mark parity */
403 /* For reference buf[5]=4 is space parity */ 551 /* For reference buf[5]=4 is space parity */
404 if (cflag & PARODD) { 552 if (C_PARODD(tty)) {
405 if (cflag & CMSPAR) { 553 if (tty->termios.c_cflag & CMSPAR) {
406 buf[5] = 3; 554 buf[5] = 3;
407 dev_dbg(&port->dev, "parity = mark\n"); 555 dev_dbg(&port->dev, "parity = mark\n");
408 } else { 556 } else {
@@ -410,7 +558,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
410 dev_dbg(&port->dev, "parity = odd\n"); 558 dev_dbg(&port->dev, "parity = odd\n");
411 } 559 }
412 } else { 560 } else {
413 if (cflag & CMSPAR) { 561 if (tty->termios.c_cflag & CMSPAR) {
414 buf[5] = 4; 562 buf[5] = 4;
415 dev_dbg(&port->dev, "parity = space\n"); 563 dev_dbg(&port->dev, "parity = space\n");
416 } else { 564 } else {
@@ -431,7 +579,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
431 /* change control lines if we are switching to or from B0 */ 579 /* change control lines if we are switching to or from B0 */
432 spin_lock_irqsave(&priv->lock, flags); 580 spin_lock_irqsave(&priv->lock, flags);
433 control = priv->line_control; 581 control = priv->line_control;
434 if ((cflag & CBAUD) == B0) 582 if (C_BAUD(tty) == B0)
435 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); 583 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
436 else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) 584 else if (old_termios && (old_termios->c_cflag & CBAUD) == B0)
437 priv->line_control |= (CONTROL_DTR | CONTROL_RTS); 585 priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
@@ -443,26 +591,21 @@ static void pl2303_set_termios(struct tty_struct *tty,
443 spin_unlock_irqrestore(&priv->lock, flags); 591 spin_unlock_irqrestore(&priv->lock, flags);
444 } 592 }
445 593
446 buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0; 594 memset(buf, 0, 7);
447
448 i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 595 i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
449 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, 596 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
450 0, 0, buf, 7, 100); 597 0, 0, buf, 7, 100);
451 dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); 598 dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf);
452 599
453 if (cflag & CRTSCTS) { 600 if (C_CRTSCTS(tty)) {
454 if (spriv->type == HX) 601 if (spriv->type == type_0 || spriv->type == type_1)
455 pl2303_vendor_write(0x0, 0x61, serial);
456 else
457 pl2303_vendor_write(0x0, 0x41, serial); 602 pl2303_vendor_write(0x0, 0x41, serial);
603 else
604 pl2303_vendor_write(0x0, 0x61, serial);
458 } else { 605 } else {
459 pl2303_vendor_write(0x0, 0x0, serial); 606 pl2303_vendor_write(0x0, 0x0, serial);
460 } 607 }
461 608
462 /* Save resulting baud rate */
463 if (baud)
464 tty_encode_baud_rate(tty, baud, baud);
465
466 kfree(buf); 609 kfree(buf);
467} 610}
468 611
@@ -495,7 +638,7 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
495 struct pl2303_serial_private *spriv = usb_get_serial_data(serial); 638 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
496 int result; 639 int result;
497 640
498 if (spriv->type != HX) { 641 if (spriv->type == type_0 || spriv->type == type_1) {
499 usb_clear_halt(serial->dev, port->write_urb->pipe); 642 usb_clear_halt(serial->dev, port->write_urb->pipe);
500 usb_clear_halt(serial->dev, port->read_urb->pipe); 643 usb_clear_halt(serial->dev, port->read_urb->pipe);
501 } else { 644 } else {
@@ -521,7 +664,6 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
521 return result; 664 return result;
522 } 665 }
523 666
524 port->port.drain_delay = 256;
525 return 0; 667 return 0;
526} 668}
527 669
@@ -789,8 +931,10 @@ static void pl2303_process_read_urb(struct urb *urb)
789 tty_flag = TTY_PARITY; 931 tty_flag = TTY_PARITY;
790 else if (line_status & UART_FRAME_ERROR) 932 else if (line_status & UART_FRAME_ERROR)
791 tty_flag = TTY_FRAME; 933 tty_flag = TTY_FRAME;
792 dev_dbg(&port->dev, "%s - tty_flag = %d\n", __func__, tty_flag);
793 934
935 if (tty_flag != TTY_NORMAL)
936 dev_dbg(&port->dev, "%s - tty_flag = %d\n", __func__,
937 tty_flag);
794 /* overrun is special, not associated with a char */ 938 /* overrun is special, not associated with a char */
795 if (line_status & UART_OVERRUN_ERROR) 939 if (line_status & UART_OVERRUN_ERROR)
796 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); 940 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
index d99743290fc1..a24d59ae4032 100644
--- a/drivers/usb/serial/quatech2.c
+++ b/drivers/usb/serial/quatech2.c
@@ -62,6 +62,7 @@
62#define MAX_BAUD_RATE 921600 62#define MAX_BAUD_RATE 921600
63#define DEFAULT_BAUD_RATE 9600 63#define DEFAULT_BAUD_RATE 9600
64 64
65#define QT2_READ_BUFFER_SIZE 512 /* size of read buffer */
65#define QT2_WRITE_BUFFER_SIZE 512 /* size of write buffer */ 66#define QT2_WRITE_BUFFER_SIZE 512 /* size of write buffer */
66#define QT2_WRITE_CONTROL_SIZE 5 /* control bytes used for a write */ 67#define QT2_WRITE_CONTROL_SIZE 5 /* control bytes used for a write */
67 68
@@ -112,7 +113,7 @@ struct qt2_serial_private {
112 unsigned char current_port; /* current port for incoming data */ 113 unsigned char current_port; /* current port for incoming data */
113 114
114 struct urb *read_urb; /* shared among all ports */ 115 struct urb *read_urb; /* shared among all ports */
115 char read_buffer[512]; 116 char *read_buffer;
116}; 117};
117 118
118struct qt2_port_private { 119struct qt2_port_private {
@@ -121,7 +122,7 @@ struct qt2_port_private {
121 spinlock_t urb_lock; 122 spinlock_t urb_lock;
122 bool urb_in_use; 123 bool urb_in_use;
123 struct urb *write_urb; 124 struct urb *write_urb;
124 char write_buffer[QT2_WRITE_BUFFER_SIZE]; 125 char *write_buffer;
125 126
126 spinlock_t lock; 127 spinlock_t lock;
127 u8 shadowLSR; 128 u8 shadowLSR;
@@ -142,6 +143,7 @@ static void qt2_release(struct usb_serial *serial)
142 serial_priv = usb_get_serial_data(serial); 143 serial_priv = usb_get_serial_data(serial);
143 144
144 usb_free_urb(serial_priv->read_urb); 145 usb_free_urb(serial_priv->read_urb);
146 kfree(serial_priv->read_buffer);
145 kfree(serial_priv); 147 kfree(serial_priv);
146} 148}
147 149
@@ -683,7 +685,7 @@ static int qt2_setup_urbs(struct usb_serial *serial)
683 usb_rcvbulkpipe(serial->dev, 685 usb_rcvbulkpipe(serial->dev,
684 port0->bulk_in_endpointAddress), 686 port0->bulk_in_endpointAddress),
685 serial_priv->read_buffer, 687 serial_priv->read_buffer,
686 sizeof(serial_priv->read_buffer), 688 QT2_READ_BUFFER_SIZE,
687 qt2_read_bulk_callback, serial); 689 qt2_read_bulk_callback, serial);
688 690
689 status = usb_submit_urb(serial_priv->read_urb, GFP_KERNEL); 691 status = usb_submit_urb(serial_priv->read_urb, GFP_KERNEL);
@@ -718,6 +720,12 @@ static int qt2_attach(struct usb_serial *serial)
718 return -ENOMEM; 720 return -ENOMEM;
719 } 721 }
720 722
723 serial_priv->read_buffer = kmalloc(QT2_READ_BUFFER_SIZE, GFP_KERNEL);
724 if (!serial_priv->read_buffer) {
725 status = -ENOMEM;
726 goto err_buf;
727 }
728
721 usb_set_serial_data(serial, serial_priv); 729 usb_set_serial_data(serial, serial_priv);
722 730
723 status = qt2_setup_urbs(serial); 731 status = qt2_setup_urbs(serial);
@@ -727,6 +735,8 @@ static int qt2_attach(struct usb_serial *serial)
727 return 0; 735 return 0;
728 736
729attach_failed: 737attach_failed:
738 kfree(serial_priv->read_buffer);
739err_buf:
730 kfree(serial_priv); 740 kfree(serial_priv);
731 return status; 741 return status;
732} 742}
@@ -745,21 +755,29 @@ static int qt2_port_probe(struct usb_serial_port *port)
745 spin_lock_init(&port_priv->urb_lock); 755 spin_lock_init(&port_priv->urb_lock);
746 port_priv->port = port; 756 port_priv->port = port;
747 757
758 port_priv->write_buffer = kmalloc(QT2_WRITE_BUFFER_SIZE, GFP_KERNEL);
759 if (!port_priv->write_buffer)
760 goto err_buf;
761
748 port_priv->write_urb = usb_alloc_urb(0, GFP_KERNEL); 762 port_priv->write_urb = usb_alloc_urb(0, GFP_KERNEL);
749 if (!port_priv->write_urb) { 763 if (!port_priv->write_urb)
750 kfree(port_priv); 764 goto err_urb;
751 return -ENOMEM; 765
752 }
753 bEndpointAddress = serial->port[0]->bulk_out_endpointAddress; 766 bEndpointAddress = serial->port[0]->bulk_out_endpointAddress;
754 usb_fill_bulk_urb(port_priv->write_urb, serial->dev, 767 usb_fill_bulk_urb(port_priv->write_urb, serial->dev,
755 usb_sndbulkpipe(serial->dev, bEndpointAddress), 768 usb_sndbulkpipe(serial->dev, bEndpointAddress),
756 port_priv->write_buffer, 769 port_priv->write_buffer,
757 sizeof(port_priv->write_buffer), 770 QT2_WRITE_BUFFER_SIZE,
758 qt2_write_bulk_callback, port); 771 qt2_write_bulk_callback, port);
759 772
760 usb_set_serial_port_data(port, port_priv); 773 usb_set_serial_port_data(port, port_priv);
761 774
762 return 0; 775 return 0;
776err_urb:
777 kfree(port_priv->write_buffer);
778err_buf:
779 kfree(port_priv);
780 return -ENOMEM;
763} 781}
764 782
765static int qt2_port_remove(struct usb_serial_port *port) 783static int qt2_port_remove(struct usb_serial_port *port)
@@ -768,6 +786,7 @@ static int qt2_port_remove(struct usb_serial_port *port)
768 786
769 port_priv = usb_get_serial_port_data(port); 787 port_priv = usb_get_serial_port_data(port);
770 usb_free_urb(port_priv->write_urb); 788 usb_free_urb(port_priv->write_urb);
789 kfree(port_priv->write_buffer);
771 kfree(port_priv); 790 kfree(port_priv);
772 791
773 return 0; 792 return 0;
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 21cd7bf2a8cc..ba895989d8c4 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -92,13 +92,6 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
92MODULE_DESCRIPTION(DRIVER_DESC); 92MODULE_DESCRIPTION(DRIVER_DESC);
93MODULE_LICENSE("GPL"); 93MODULE_LICENSE("GPL");
94 94
95static __u16 vendor; /* no default */
96static __u16 product; /* no default */
97module_param(vendor, ushort, 0);
98MODULE_PARM_DESC(vendor, "User specified USB idVendor (required)");
99module_param(product, ushort, 0);
100MODULE_PARM_DESC(product, "User specified USB idProduct (required)");
101
102module_param(safe, bool, 0); 95module_param(safe, bool, 0);
103MODULE_PARM_DESC(safe, "Turn Safe Encapsulation On/Off"); 96MODULE_PARM_DESC(safe, "Turn Safe Encapsulation On/Off");
104 97
@@ -140,8 +133,6 @@ static struct usb_device_id id_table[] = {
140 {MY_USB_DEVICE(0x4dd, 0x8003, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */ 133 {MY_USB_DEVICE(0x4dd, 0x8003, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */
141 {MY_USB_DEVICE(0x4dd, 0x8004, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */ 134 {MY_USB_DEVICE(0x4dd, 0x8004, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Collie */
142 {MY_USB_DEVICE(0x5f9, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Sharp tmp */ 135 {MY_USB_DEVICE(0x5f9, 0xffff, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)}, /* Sharp tmp */
143 /* extra null entry for module vendor/produc parameters */
144 {MY_USB_DEVICE(0, 0, CDC_DEVICE_CLASS, LINEO_INTERFACE_CLASS, LINEO_INTERFACE_SUBCLASS_SAFESERIAL)},
145 {} /* terminating entry */ 136 {} /* terminating entry */
146}; 137};
147 138
@@ -272,7 +263,19 @@ static int safe_prepare_write_buffer(struct usb_serial_port *port,
272 263
273static int safe_startup(struct usb_serial *serial) 264static int safe_startup(struct usb_serial *serial)
274{ 265{
275 switch (serial->interface->cur_altsetting->desc.bInterfaceProtocol) { 266 struct usb_interface_descriptor *desc;
267
268 if (serial->dev->descriptor.bDeviceClass != CDC_DEVICE_CLASS)
269 return -ENODEV;
270
271 desc = &serial->interface->cur_altsetting->desc;
272
273 if (desc->bInterfaceClass != LINEO_INTERFACE_CLASS)
274 return -ENODEV;
275 if (desc->bInterfaceSubClass != LINEO_INTERFACE_SUBCLASS_SAFESERIAL)
276 return -ENODEV;
277
278 switch (desc->bInterfaceProtocol) {
276 case LINEO_SAFESERIAL_CRC: 279 case LINEO_SAFESERIAL_CRC:
277 break; 280 break;
278 case LINEO_SAFESERIAL_CRC_PADDED: 281 case LINEO_SAFESERIAL_CRC_PADDED:
@@ -300,30 +303,4 @@ static struct usb_serial_driver * const serial_drivers[] = {
300 &safe_device, NULL 303 &safe_device, NULL
301}; 304};
302 305
303static int __init safe_init(void) 306module_usb_serial_driver(serial_drivers, id_table);
304{
305 int i;
306
307 /* if we have vendor / product parameters patch them into id list */
308 if (vendor || product) {
309 pr_info("vendor: %x product: %x\n", vendor, product);
310
311 for (i = 0; i < ARRAY_SIZE(id_table); i++) {
312 if (!id_table[i].idVendor && !id_table[i].idProduct) {
313 id_table[i].idVendor = vendor;
314 id_table[i].idProduct = product;
315 break;
316 }
317 }
318 }
319
320 return usb_serial_register_drivers(serial_drivers, KBUILD_MODNAME, id_table);
321}
322
323static void __exit safe_exit(void)
324{
325 usb_serial_deregister_drivers(serial_drivers);
326}
327
328module_init(safe_init);
329module_exit(safe_exit);
diff --git a/drivers/usb/serial/siemens_mpi.c b/drivers/usb/serial/siemens_mpi.c
deleted file mode 100644
index a76b1ae54a2a..000000000000
--- a/drivers/usb/serial/siemens_mpi.c
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * Siemens USB-MPI Serial USB driver
3 *
4 * Copyright (C) 2005 Thomas Hergenhahn <thomas.hergenhahn@suse.de>
5 * Copyright (C) 2005,2008 Greg Kroah-Hartman <gregkh@suse.de>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/tty.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17#include <linux/usb/serial.h>
18
19#define DRIVER_AUTHOR "Thomas Hergenhahn@web.de http://libnodave.sf.net"
20#define DRIVER_DESC "Driver for Siemens USB/MPI adapter"
21
22
23static const struct usb_device_id id_table[] = {
24 /* Vendor and product id for 6ES7-972-0CB20-0XA0 */
25 { USB_DEVICE(0x908, 0x0004) },
26 { },
27};
28MODULE_DEVICE_TABLE(usb, id_table);
29
30static struct usb_serial_driver siemens_usb_mpi_device = {
31 .driver = {
32 .owner = THIS_MODULE,
33 .name = "siemens_mpi",
34 },
35 .id_table = id_table,
36 .num_ports = 1,
37};
38
39static struct usb_serial_driver * const serial_drivers[] = {
40 &siemens_usb_mpi_device, NULL
41};
42
43module_usb_serial_driver(serial_drivers, id_table);
44
45MODULE_AUTHOR(DRIVER_AUTHOR);
46MODULE_DESCRIPTION(DRIVER_DESC);
47MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index ddf6c47137dc..4abac28b5992 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -169,6 +169,8 @@ static int spcp8x5_port_probe(struct usb_serial_port *port)
169 169
170 usb_set_serial_port_data(port, priv); 170 usb_set_serial_port_data(port, priv);
171 171
172 port->port.drain_delay = 256;
173
172 return 0; 174 return 0;
173} 175}
174 176
@@ -411,8 +413,6 @@ static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
411 if (tty) 413 if (tty)
412 spcp8x5_set_termios(tty, port, NULL); 414 spcp8x5_set_termios(tty, port, NULL);
413 415
414 port->port.drain_delay = 256;
415
416 return usb_serial_generic_open(tty, port); 416 return usb_serial_generic_open(tty, port);
417} 417}
418 418
diff --git a/drivers/usb/serial/suunto.c b/drivers/usb/serial/suunto.c
deleted file mode 100644
index 2248e7a7d5ad..000000000000
--- a/drivers/usb/serial/suunto.c
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Suunto ANT+ USB Driver
3 *
4 * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
5 * Copyright (C) 2013 Linux Foundation
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 version 2 as published by
9 * the Free Software Foundation only.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/tty.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17#include <linux/usb/serial.h>
18#include <linux/uaccess.h>
19
20static const struct usb_device_id id_table[] = {
21 { USB_DEVICE(0x0fcf, 0x1008) },
22 { },
23};
24MODULE_DEVICE_TABLE(usb, id_table);
25
26static struct usb_serial_driver suunto_device = {
27 .driver = {
28 .owner = THIS_MODULE,
29 .name = KBUILD_MODNAME,
30 },
31 .id_table = id_table,
32 .num_ports = 1,
33};
34
35static struct usb_serial_driver * const serial_drivers[] = {
36 &suunto_device,
37 NULL,
38};
39
40module_usb_serial_driver(serial_drivers, id_table);
41MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 5c9f9b1d7736..760b78560f67 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -45,8 +45,6 @@
45 45
46#define TI_FIRMWARE_BUF_SIZE 16284 46#define TI_FIRMWARE_BUF_SIZE 16284
47 47
48#define TI_WRITE_BUF_SIZE 1024
49
50#define TI_TRANSFER_TIMEOUT 2 48#define TI_TRANSFER_TIMEOUT 2
51 49
52#define TI_DEFAULT_CLOSING_WAIT 4000 /* in .01 secs */ 50#define TI_DEFAULT_CLOSING_WAIT 4000 /* in .01 secs */
@@ -71,13 +69,11 @@ struct ti_port {
71 __u8 tp_uart_mode; /* 232 or 485 modes */ 69 __u8 tp_uart_mode; /* 232 or 485 modes */
72 unsigned int tp_uart_base_addr; 70 unsigned int tp_uart_base_addr;
73 int tp_flags; 71 int tp_flags;
74 wait_queue_head_t tp_write_wait;
75 struct ti_device *tp_tdev; 72 struct ti_device *tp_tdev;
76 struct usb_serial_port *tp_port; 73 struct usb_serial_port *tp_port;
77 spinlock_t tp_lock; 74 spinlock_t tp_lock;
78 int tp_read_urb_state; 75 int tp_read_urb_state;
79 int tp_write_urb_in_use; 76 int tp_write_urb_in_use;
80 struct kfifo write_fifo;
81}; 77};
82 78
83struct ti_device { 79struct ti_device {
@@ -145,20 +141,9 @@ static int ti_download_firmware(struct ti_device *tdev);
145 141
146/* module parameters */ 142/* module parameters */
147static int closing_wait = TI_DEFAULT_CLOSING_WAIT; 143static int closing_wait = TI_DEFAULT_CLOSING_WAIT;
148static ushort vendor_3410[TI_EXTRA_VID_PID_COUNT];
149static unsigned int vendor_3410_count;
150static ushort product_3410[TI_EXTRA_VID_PID_COUNT];
151static unsigned int product_3410_count;
152static ushort vendor_5052[TI_EXTRA_VID_PID_COUNT];
153static unsigned int vendor_5052_count;
154static ushort product_5052[TI_EXTRA_VID_PID_COUNT];
155static unsigned int product_5052_count;
156 144
157/* supported devices */ 145/* supported devices */
158/* the array dimension is the number of default entries plus */ 146static struct usb_device_id ti_id_table_3410[] = {
159/* TI_EXTRA_VID_PID_COUNT user defined entries plus 1 terminating */
160/* null entry */
161static struct usb_device_id ti_id_table_3410[15+TI_EXTRA_VID_PID_COUNT+1] = {
162 { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, 147 { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) },
163 { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, 148 { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) },
164 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, 149 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) },
@@ -175,16 +160,18 @@ static struct usb_device_id ti_id_table_3410[15+TI_EXTRA_VID_PID_COUNT+1] = {
175 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_STEREO_PLUG_ID) }, 160 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_STEREO_PLUG_ID) },
176 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_STRIP_PORT_ID) }, 161 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_STRIP_PORT_ID) },
177 { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) }, 162 { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) },
163 { } /* terminator */
178}; 164};
179 165
180static struct usb_device_id ti_id_table_5052[5+TI_EXTRA_VID_PID_COUNT+1] = { 166static struct usb_device_id ti_id_table_5052[] = {
181 { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) }, 167 { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) },
182 { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) }, 168 { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) },
183 { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) }, 169 { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) },
184 { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) }, 170 { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) },
171 { } /* terminator */
185}; 172};
186 173
187static struct usb_device_id ti_id_table_combined[19+2*TI_EXTRA_VID_PID_COUNT+1] = { 174static struct usb_device_id ti_id_table_combined[] = {
188 { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, 175 { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) },
189 { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, 176 { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) },
190 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, 177 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) },
@@ -204,7 +191,7 @@ static struct usb_device_id ti_id_table_combined[19+2*TI_EXTRA_VID_PID_COUNT+1]
204 { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) }, 191 { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) },
205 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) }, 192 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) },
206 { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) }, 193 { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) },
207 { } 194 { } /* terminator */
208}; 195};
209 196
210static struct usb_serial_driver ti_1port_device = { 197static struct usb_serial_driver ti_1port_device = {
@@ -293,61 +280,12 @@ module_param(closing_wait, int, S_IRUGO | S_IWUSR);
293MODULE_PARM_DESC(closing_wait, 280MODULE_PARM_DESC(closing_wait,
294 "Maximum wait for data to drain in close, in .01 secs, default is 4000"); 281 "Maximum wait for data to drain in close, in .01 secs, default is 4000");
295 282
296module_param_array(vendor_3410, ushort, &vendor_3410_count, S_IRUGO);
297MODULE_PARM_DESC(vendor_3410,
298 "Vendor ids for 3410 based devices, 1-5 short integers");
299module_param_array(product_3410, ushort, &product_3410_count, S_IRUGO);
300MODULE_PARM_DESC(product_3410,
301 "Product ids for 3410 based devices, 1-5 short integers");
302module_param_array(vendor_5052, ushort, &vendor_5052_count, S_IRUGO);
303MODULE_PARM_DESC(vendor_5052,
304 "Vendor ids for 5052 based devices, 1-5 short integers");
305module_param_array(product_5052, ushort, &product_5052_count, S_IRUGO);
306MODULE_PARM_DESC(product_5052,
307 "Product ids for 5052 based devices, 1-5 short integers");
308
309MODULE_DEVICE_TABLE(usb, ti_id_table_combined); 283MODULE_DEVICE_TABLE(usb, ti_id_table_combined);
310 284
285module_usb_serial_driver(serial_drivers, ti_id_table_combined);
311 286
312/* Functions */ 287/* Functions */
313 288
314static int __init ti_init(void)
315{
316 int i, j, c;
317
318 /* insert extra vendor and product ids */
319 c = ARRAY_SIZE(ti_id_table_combined) - 2 * TI_EXTRA_VID_PID_COUNT - 1;
320 j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1;
321 for (i = 0; i < min(vendor_3410_count, product_3410_count); i++, j++, c++) {
322 ti_id_table_3410[j].idVendor = vendor_3410[i];
323 ti_id_table_3410[j].idProduct = product_3410[i];
324 ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
325 ti_id_table_combined[c].idVendor = vendor_3410[i];
326 ti_id_table_combined[c].idProduct = product_3410[i];
327 ti_id_table_combined[c].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
328 }
329 j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1;
330 for (i = 0; i < min(vendor_5052_count, product_5052_count); i++, j++, c++) {
331 ti_id_table_5052[j].idVendor = vendor_5052[i];
332 ti_id_table_5052[j].idProduct = product_5052[i];
333 ti_id_table_5052[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
334 ti_id_table_combined[c].idVendor = vendor_5052[i];
335 ti_id_table_combined[c].idProduct = product_5052[i];
336 ti_id_table_combined[c].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
337 }
338
339 return usb_serial_register_drivers(serial_drivers, KBUILD_MODNAME, ti_id_table_combined);
340}
341
342static void __exit ti_exit(void)
343{
344 usb_serial_deregister_drivers(serial_drivers);
345}
346
347module_init(ti_init);
348module_exit(ti_exit);
349
350
351static int ti_startup(struct usb_serial *serial) 289static int ti_startup(struct usb_serial *serial)
352{ 290{
353 struct ti_device *tdev; 291 struct ti_device *tdev;
@@ -430,17 +368,14 @@ static int ti_port_probe(struct usb_serial_port *port)
430 else 368 else
431 tport->tp_uart_base_addr = TI_UART2_BASE_ADDR; 369 tport->tp_uart_base_addr = TI_UART2_BASE_ADDR;
432 port->port.closing_wait = msecs_to_jiffies(10 * closing_wait); 370 port->port.closing_wait = msecs_to_jiffies(10 * closing_wait);
433 init_waitqueue_head(&tport->tp_write_wait);
434 if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE, GFP_KERNEL)) {
435 kfree(tport);
436 return -ENOMEM;
437 }
438 tport->tp_port = port; 371 tport->tp_port = port;
439 tport->tp_tdev = usb_get_serial_data(port->serial); 372 tport->tp_tdev = usb_get_serial_data(port->serial);
440 tport->tp_uart_mode = 0; /* default is RS232 */ 373 tport->tp_uart_mode = 0; /* default is RS232 */
441 374
442 usb_set_serial_port_data(port, tport); 375 usb_set_serial_port_data(port, tport);
443 376
377 port->port.drain_delay = 3;
378
444 return 0; 379 return 0;
445} 380}
446 381
@@ -449,7 +384,6 @@ static int ti_port_remove(struct usb_serial_port *port)
449 struct ti_port *tport; 384 struct ti_port *tport;
450 385
451 tport = usb_get_serial_port_data(port); 386 tport = usb_get_serial_port_data(port);
452 kfifo_free(&tport->write_fifo);
453 kfree(tport); 387 kfree(tport);
454 388
455 return 0; 389 return 0;
@@ -582,8 +516,6 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
582 tport->tp_is_open = 1; 516 tport->tp_is_open = 1;
583 ++tdev->td_open_port_count; 517 ++tdev->td_open_port_count;
584 518
585 port->port.drain_delay = 3;
586
587 goto release_lock; 519 goto release_lock;
588 520
589unlink_int_urb: 521unlink_int_urb:
@@ -616,7 +548,7 @@ static void ti_close(struct usb_serial_port *port)
616 usb_kill_urb(port->write_urb); 548 usb_kill_urb(port->write_urb);
617 tport->tp_write_urb_in_use = 0; 549 tport->tp_write_urb_in_use = 0;
618 spin_lock_irqsave(&tport->tp_lock, flags); 550 spin_lock_irqsave(&tport->tp_lock, flags);
619 kfifo_reset_out(&tport->write_fifo); 551 kfifo_reset_out(&port->write_fifo);
620 spin_unlock_irqrestore(&tport->tp_lock, flags); 552 spin_unlock_irqrestore(&tport->tp_lock, flags);
621 553
622 port_number = port->port_number; 554 port_number = port->port_number;
@@ -655,7 +587,7 @@ static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
655 if (tport == NULL || !tport->tp_is_open) 587 if (tport == NULL || !tport->tp_is_open)
656 return -ENODEV; 588 return -ENODEV;
657 589
658 count = kfifo_in_locked(&tport->write_fifo, data, count, 590 count = kfifo_in_locked(&port->write_fifo, data, count,
659 &tport->tp_lock); 591 &tport->tp_lock);
660 ti_send(tport); 592 ti_send(tport);
661 593
@@ -674,7 +606,7 @@ static int ti_write_room(struct tty_struct *tty)
674 return 0; 606 return 0;
675 607
676 spin_lock_irqsave(&tport->tp_lock, flags); 608 spin_lock_irqsave(&tport->tp_lock, flags);
677 room = kfifo_avail(&tport->write_fifo); 609 room = kfifo_avail(&port->write_fifo);
678 spin_unlock_irqrestore(&tport->tp_lock, flags); 610 spin_unlock_irqrestore(&tport->tp_lock, flags);
679 611
680 dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); 612 dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
@@ -693,7 +625,7 @@ static int ti_chars_in_buffer(struct tty_struct *tty)
693 return 0; 625 return 0;
694 626
695 spin_lock_irqsave(&tport->tp_lock, flags); 627 spin_lock_irqsave(&tport->tp_lock, flags);
696 chars = kfifo_len(&tport->write_fifo); 628 chars = kfifo_len(&port->write_fifo);
697 spin_unlock_irqrestore(&tport->tp_lock, flags); 629 spin_unlock_irqrestore(&tport->tp_lock, flags);
698 630
699 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); 631 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
@@ -1090,13 +1022,11 @@ static void ti_bulk_in_callback(struct urb *urb)
1090 case -ESHUTDOWN: 1022 case -ESHUTDOWN:
1091 dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status); 1023 dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status);
1092 tport->tp_tdev->td_urb_error = 1; 1024 tport->tp_tdev->td_urb_error = 1;
1093 wake_up_interruptible(&tport->tp_write_wait);
1094 return; 1025 return;
1095 default: 1026 default:
1096 dev_err(dev, "%s - nonzero urb status, %d\n", 1027 dev_err(dev, "%s - nonzero urb status, %d\n",
1097 __func__, status); 1028 __func__, status);
1098 tport->tp_tdev->td_urb_error = 1; 1029 tport->tp_tdev->td_urb_error = 1;
1099 wake_up_interruptible(&tport->tp_write_wait);
1100 } 1030 }
1101 1031
1102 if (status == -EPIPE) 1032 if (status == -EPIPE)
@@ -1152,13 +1082,11 @@ static void ti_bulk_out_callback(struct urb *urb)
1152 case -ESHUTDOWN: 1082 case -ESHUTDOWN:
1153 dev_dbg(&port->dev, "%s - urb shutting down, %d\n", __func__, status); 1083 dev_dbg(&port->dev, "%s - urb shutting down, %d\n", __func__, status);
1154 tport->tp_tdev->td_urb_error = 1; 1084 tport->tp_tdev->td_urb_error = 1;
1155 wake_up_interruptible(&tport->tp_write_wait);
1156 return; 1085 return;
1157 default: 1086 default:
1158 dev_err_console(port, "%s - nonzero urb status, %d\n", 1087 dev_err_console(port, "%s - nonzero urb status, %d\n",
1159 __func__, status); 1088 __func__, status);
1160 tport->tp_tdev->td_urb_error = 1; 1089 tport->tp_tdev->td_urb_error = 1;
1161 wake_up_interruptible(&tport->tp_write_wait);
1162 } 1090 }
1163 1091
1164 /* send any buffered data */ 1092 /* send any buffered data */
@@ -1197,7 +1125,7 @@ static void ti_send(struct ti_port *tport)
1197 if (tport->tp_write_urb_in_use) 1125 if (tport->tp_write_urb_in_use)
1198 goto unlock; 1126 goto unlock;
1199 1127
1200 count = kfifo_out(&tport->write_fifo, 1128 count = kfifo_out(&port->write_fifo,
1201 port->write_urb->transfer_buffer, 1129 port->write_urb->transfer_buffer,
1202 port->bulk_out_size); 1130 port->bulk_out_size);
1203 1131
@@ -1232,7 +1160,6 @@ static void ti_send(struct ti_port *tport)
1232 /* more room in the buffer for new writes, wakeup */ 1160 /* more room in the buffer for new writes, wakeup */
1233 tty_port_tty_wakeup(&port->port); 1161 tty_port_tty_wakeup(&port->port);
1234 1162
1235 wake_up_interruptible(&tport->tp_write_wait);
1236 return; 1163 return;
1237unlock: 1164unlock:
1238 spin_unlock_irqrestore(&tport->tp_lock, flags); 1165 spin_unlock_irqrestore(&tport->tp_lock, flags);
@@ -1312,7 +1239,7 @@ static int ti_get_serial_info(struct ti_port *tport,
1312 ret_serial.line = port->minor; 1239 ret_serial.line = port->minor;
1313 ret_serial.port = port->port_number; 1240 ret_serial.port = port->port_number;
1314 ret_serial.flags = tport->tp_flags; 1241 ret_serial.flags = tport->tp_flags;
1315 ret_serial.xmit_fifo_size = TI_WRITE_BUF_SIZE; 1242 ret_serial.xmit_fifo_size = kfifo_size(&port->write_fifo);
1316 ret_serial.baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800; 1243 ret_serial.baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800;
1317 ret_serial.closing_wait = cwait; 1244 ret_serial.closing_wait = cwait;
1318 1245
diff --git a/drivers/usb/serial/usb-serial-simple.c b/drivers/usb/serial/usb-serial-simple.c
new file mode 100644
index 000000000000..6a06131f48f4
--- /dev/null
+++ b/drivers/usb/serial/usb-serial-simple.c
@@ -0,0 +1,110 @@
1/*
2 * USB Serial "Simple" driver
3 *
4 * Copyright (C) 2001-2006,2008,2013 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2005 Arthur Huillet (ahuillet@users.sf.net)
6 * Copyright (C) 2005 Thomas Hergenhahn <thomas.hergenhahn@suse.de>
7 * Copyright (C) 2009 Outpost Embedded, LLC
8 * Copyright (C) 2010 Zilogic Systems <code@zilogic.com>
9 * Copyright (C) 2013 Wei Shuai <cpuwolf@gmail.com>
10 * Copyright (C) 2013 Linux Foundation
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License version
14 * 2 as published by the Free Software Foundation.
15 */
16
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/tty.h>
20#include <linux/module.h>
21#include <linux/usb.h>
22#include <linux/usb/serial.h>
23
24#define DEVICE(vendor, IDS) \
25static const struct usb_device_id vendor##_id_table[] = { \
26 IDS(), \
27 { }, \
28}; \
29static struct usb_serial_driver vendor##_device = { \
30 .driver = { \
31 .owner = THIS_MODULE, \
32 .name = "stringify(vendor)", \
33 }, \
34 .id_table = vendor##_id_table, \
35 .num_ports = 1, \
36};
37
38
39/* ZIO Motherboard USB driver */
40#define ZIO_IDS() \
41 { USB_DEVICE(0x1CBE, 0x0103) }
42DEVICE(zio, ZIO_IDS);
43
44/* Funsoft Serial USB driver */
45#define FUNSOFT_IDS() \
46 { USB_DEVICE(0x1404, 0xcddc) }
47DEVICE(funsoft, FUNSOFT_IDS);
48
49/* Infineon Flashloader driver */
50#define FLASHLOADER_IDS() \
51 { USB_DEVICE(0x8087, 0x0716) }
52DEVICE(flashloader, FLASHLOADER_IDS);
53
54/* ViVOpay USB Serial Driver */
55#define VIVOPAY_IDS() \
56 { USB_DEVICE(0x1d5f, 0x1004) } /* ViVOpay 8800 */
57DEVICE(vivopay, VIVOPAY_IDS);
58
59/* Motorola USB Phone driver */
60#define MOTO_IDS() \
61 { USB_DEVICE(0x05c6, 0x3197) }, /* unknown Motorola phone */ \
62 { USB_DEVICE(0x0c44, 0x0022) }, /* unknown Mororola phone */ \
63 { USB_DEVICE(0x22b8, 0x2a64) }, /* Motorola KRZR K1m */ \
64 { USB_DEVICE(0x22b8, 0x2c84) }, /* Motorola VE240 phone */ \
65 { USB_DEVICE(0x22b8, 0x2c64) } /* Motorola V950 phone */
66DEVICE(moto_modem, MOTO_IDS);
67
68/* HP4x (48/49) Generic Serial driver */
69#define HP4X_IDS() \
70 { USB_DEVICE(0x03f0, 0x0121) }
71DEVICE(hp4x, HP4X_IDS);
72
73/* Suunto ANT+ USB Driver */
74#define SUUNTO_IDS() \
75 { USB_DEVICE(0x0fcf, 0x1008) }
76DEVICE(suunto, SUUNTO_IDS);
77
78/* Siemens USB/MPI adapter */
79#define SIEMENS_IDS() \
80 { USB_DEVICE(0x908, 0x0004) }
81DEVICE(siemens_mpi, SIEMENS_IDS);
82
83/* All of the above structures mushed into two lists */
84static struct usb_serial_driver * const serial_drivers[] = {
85 &zio_device,
86 &funsoft_device,
87 &flashloader_device,
88 &vivopay_device,
89 &moto_modem_device,
90 &hp4x_device,
91 &suunto_device,
92 &siemens_mpi_device,
93 NULL
94};
95
96static const struct usb_device_id id_table[] = {
97 ZIO_IDS(),
98 FUNSOFT_IDS(),
99 FLASHLOADER_IDS(),
100 VIVOPAY_IDS(),
101 MOTO_IDS(),
102 HP4X_IDS(),
103 SUUNTO_IDS(),
104 SIEMENS_IDS(),
105 { },
106};
107MODULE_DEVICE_TABLE(usb, id_table);
108
109module_usb_serial_driver(serial_drivers, id_table);
110MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index cb27fcb2fc90..6091bd5a1f4f 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -681,20 +681,10 @@ static int serial_port_carrier_raised(struct tty_port *port)
681static void serial_port_dtr_rts(struct tty_port *port, int on) 681static void serial_port_dtr_rts(struct tty_port *port, int on)
682{ 682{
683 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); 683 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port);
684 struct usb_serial *serial = p->serial; 684 struct usb_serial_driver *drv = p->serial->type;
685 struct usb_serial_driver *drv = serial->type;
686 685
687 if (!drv->dtr_rts) 686 if (drv->dtr_rts)
688 return;
689 /*
690 * Work-around bug in the tty-layer which can result in dtr_rts
691 * being called after a disconnect (and tty_unregister_device
692 * has returned). Remove once bug has been squashed.
693 */
694 mutex_lock(&serial->disc_mutex);
695 if (!serial->disconnected)
696 drv->dtr_rts(p, on); 687 drv->dtr_rts(p, on);
697 mutex_unlock(&serial->disc_mutex);
698} 688}
699 689
700static const struct tty_port_operations serial_port_ops = { 690static const struct tty_port_operations serial_port_ops = {
diff --git a/drivers/usb/serial/vivopay-serial.c b/drivers/usb/serial/vivopay-serial.c
deleted file mode 100644
index 6299526ff8c3..000000000000
--- a/drivers/usb/serial/vivopay-serial.c
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * Copyright (C) 2001-2005 Greg Kroah-Hartman (greg@kroah.com)
3 * Copyright (C) 2009 Outpost Embedded, LLC
4 */
5
6#include <linux/kernel.h>
7#include <linux/init.h>
8#include <linux/tty.h>
9#include <linux/module.h>
10#include <linux/usb.h>
11#include <linux/usb/serial.h>
12
13#define DRIVER_DESC "ViVOpay USB Serial Driver"
14
15#define VIVOPAY_VENDOR_ID 0x1d5f
16
17
18static struct usb_device_id id_table [] = {
19 /* ViVOpay 8800 */
20 { USB_DEVICE(VIVOPAY_VENDOR_ID, 0x1004) },
21 { },
22};
23
24MODULE_DEVICE_TABLE(usb, id_table);
25
26static struct usb_serial_driver vivopay_serial_device = {
27 .driver = {
28 .owner = THIS_MODULE,
29 .name = "vivopay-serial",
30 },
31 .id_table = id_table,
32 .num_ports = 1,
33};
34
35static struct usb_serial_driver * const serial_drivers[] = {
36 &vivopay_serial_device, NULL
37};
38
39module_usb_serial_driver(serial_drivers, id_table);
40
41MODULE_AUTHOR("Forest Bond <forest.bond@outpostembedded.com>");
42MODULE_DESCRIPTION(DRIVER_DESC);
43MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/zio.c b/drivers/usb/serial/zio.c
deleted file mode 100644
index c043aa84a0ba..000000000000
--- a/drivers/usb/serial/zio.c
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 * ZIO Motherboard USB driver
3 *
4 * Copyright (C) 2010 Zilogic Systems <code@zilogic.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/tty.h>
14#include <linux/module.h>
15#include <linux/usb.h>
16#include <linux/usb/serial.h>
17#include <linux/uaccess.h>
18
19static const struct usb_device_id id_table[] = {
20 { USB_DEVICE(0x1CBE, 0x0103) },
21 { },
22};
23MODULE_DEVICE_TABLE(usb, id_table);
24
25static struct usb_serial_driver zio_device = {
26 .driver = {
27 .owner = THIS_MODULE,
28 .name = "zio",
29 },
30 .id_table = id_table,
31 .num_ports = 1,
32};
33
34static struct usb_serial_driver * const serial_drivers[] = {
35 &zio_device, NULL
36};
37
38module_usb_serial_driver(serial_drivers, id_table);
39MODULE_LICENSE("GPL");
diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
index 675384dabfe9..d771870a819e 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -43,20 +43,20 @@ const char *usb_otg_state_string(enum usb_otg_state state)
43} 43}
44EXPORT_SYMBOL_GPL(usb_otg_state_string); 44EXPORT_SYMBOL_GPL(usb_otg_state_string);
45 45
46static const char *const speed_names[] = {
47 [USB_SPEED_UNKNOWN] = "UNKNOWN",
48 [USB_SPEED_LOW] = "low-speed",
49 [USB_SPEED_FULL] = "full-speed",
50 [USB_SPEED_HIGH] = "high-speed",
51 [USB_SPEED_WIRELESS] = "wireless",
52 [USB_SPEED_SUPER] = "super-speed",
53};
54
46const char *usb_speed_string(enum usb_device_speed speed) 55const char *usb_speed_string(enum usb_device_speed speed)
47{ 56{
48 static const char *const names[] = { 57 if (speed < 0 || speed >= ARRAY_SIZE(speed_names))
49 [USB_SPEED_UNKNOWN] = "UNKNOWN",
50 [USB_SPEED_LOW] = "low-speed",
51 [USB_SPEED_FULL] = "full-speed",
52 [USB_SPEED_HIGH] = "high-speed",
53 [USB_SPEED_WIRELESS] = "wireless",
54 [USB_SPEED_SUPER] = "super-speed",
55 };
56
57 if (speed < 0 || speed >= ARRAY_SIZE(names))
58 speed = USB_SPEED_UNKNOWN; 58 speed = USB_SPEED_UNKNOWN;
59 return names[speed]; 59 return speed_names[speed];
60} 60}
61EXPORT_SYMBOL_GPL(usb_speed_string); 61EXPORT_SYMBOL_GPL(usb_speed_string);
62 62
@@ -112,6 +112,33 @@ enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
112 return USB_DR_MODE_UNKNOWN; 112 return USB_DR_MODE_UNKNOWN;
113} 113}
114EXPORT_SYMBOL_GPL(of_usb_get_dr_mode); 114EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
115
116/**
117 * of_usb_get_maximum_speed - Get maximum requested speed for a given USB
118 * controller.
119 * @np: Pointer to the given device_node
120 *
121 * The function gets the maximum speed string from property "maximum-speed",
122 * and returns the corresponding enum usb_device_speed.
123 */
124enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np)
125{
126 const char *maximum_speed;
127 int err;
128 int i;
129
130 err = of_property_read_string(np, "maximum-speed", &maximum_speed);
131 if (err < 0)
132 return USB_SPEED_UNKNOWN;
133
134 for (i = 0; i < ARRAY_SIZE(speed_names); i++)
135 if (strcmp(maximum_speed, speed_names[i]) == 0)
136 return i;
137
138 return USB_SPEED_UNKNOWN;
139}
140EXPORT_SYMBOL_GPL(of_usb_get_maximum_speed);
141
115#endif 142#endif
116 143
117MODULE_LICENSE("GPL"); 144MODULE_LICENSE("GPL");
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 7ed3b039dbe8..ff97652343a3 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -325,9 +325,8 @@ retry:
325 rv = skel_do_read_io(dev, count); 325 rv = skel_do_read_io(dev, count);
326 if (rv < 0) 326 if (rv < 0)
327 goto exit; 327 goto exit;
328 else if (!(file->f_flags & O_NONBLOCK)) 328 else
329 goto retry; 329 goto retry;
330 rv = -EAGAIN;
331 } 330 }
332exit: 331exit:
333 mutex_unlock(&dev->io_mutex); 332 mutex_unlock(&dev->io_mutex);
diff --git a/drivers/usb/wusbcore/rh.c b/drivers/usb/wusbcore/rh.c
index bdb0cc3046b5..fe8bc777ab88 100644
--- a/drivers/usb/wusbcore/rh.c
+++ b/drivers/usb/wusbcore/rh.c
@@ -141,18 +141,26 @@ static int wusbhc_rh_port_reset(struct wusbhc *wusbhc, u8 port_idx)
141int wusbhc_rh_status_data(struct usb_hcd *usb_hcd, char *_buf) 141int wusbhc_rh_status_data(struct usb_hcd *usb_hcd, char *_buf)
142{ 142{
143 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); 143 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
144 size_t cnt, size; 144 size_t cnt, size, bits_set = 0;
145 unsigned long *buf = (unsigned long *) _buf;
146 145
147 /* WE DON'T LOCK, see comment */ 146 /* WE DON'T LOCK, see comment */
148 size = wusbhc->ports_max + 1 /* hub bit */; 147 /* round up to bytes. Hub bit is bit 0 so add 1. */
149 size = (size + 8 - 1) / 8; /* round to bytes */ 148 size = DIV_ROUND_UP(wusbhc->ports_max + 1, 8);
150 for (cnt = 0; cnt < wusbhc->ports_max; cnt++) 149
151 if (wusb_port_by_idx(wusbhc, cnt)->change) 150 /* clear the output buffer. */
152 set_bit(cnt + 1, buf); 151 memset(_buf, 0, size);
153 else 152 /* set the bit for each changed port. */
154 clear_bit(cnt + 1, buf); 153 for (cnt = 0; cnt < wusbhc->ports_max; cnt++) {
155 return size; 154
155 if (wusb_port_by_idx(wusbhc, cnt)->change) {
156 const int bitpos = cnt+1;
157
158 _buf[bitpos/8] |= (1 << (bitpos % 8));
159 bits_set++;
160 }
161 }
162
163 return bits_set ? size : 0;
156} 164}
157EXPORT_SYMBOL_GPL(wusbhc_rh_status_data); 165EXPORT_SYMBOL_GPL(wusbhc_rh_status_data);
158 166
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index d3493ca0525d..cef940f4de7c 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -928,7 +928,7 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
928 spin_lock_irqsave(&rpipe->seg_lock, flags); 928 spin_lock_irqsave(&rpipe->seg_lock, flags);
929 while (atomic_read(&rpipe->segs_available) > 0 929 while (atomic_read(&rpipe->segs_available) > 0
930 && !list_empty(&rpipe->seg_list)) { 930 && !list_empty(&rpipe->seg_list)) {
931 seg = list_entry(rpipe->seg_list.next, struct wa_seg, 931 seg = list_first_entry(&(rpipe->seg_list), struct wa_seg,
932 list_node); 932 list_node);
933 list_del(&seg->list_node); 933 list_del(&seg->list_node);
934 xfer = seg->xfer; 934 xfer = seg->xfer;
@@ -1093,30 +1093,35 @@ error_xfer_submit:
1093 * 1093 *
1094 * We need to be careful here, as dequeue() could be called in the 1094 * We need to be careful here, as dequeue() could be called in the
1095 * middle. That's why we do the whole thing under the 1095 * middle. That's why we do the whole thing under the
1096 * wa->xfer_list_lock. If dequeue() jumps in, it first locks urb->lock 1096 * wa->xfer_list_lock. If dequeue() jumps in, it first locks xfer->lock
1097 * and then checks the list -- so as we would be acquiring in inverse 1097 * and then checks the list -- so as we would be acquiring in inverse
1098 * order, we just drop the lock once we have the xfer and reacquire it 1098 * order, we move the delayed list to a separate list while locked and then
1099 * later. 1099 * submit them without the list lock held.
1100 */ 1100 */
1101void wa_urb_enqueue_run(struct work_struct *ws) 1101void wa_urb_enqueue_run(struct work_struct *ws)
1102{ 1102{
1103 struct wahc *wa = container_of(ws, struct wahc, xfer_work); 1103 struct wahc *wa = container_of(ws, struct wahc, xfer_work);
1104 struct wa_xfer *xfer, *next; 1104 struct wa_xfer *xfer, *next;
1105 struct urb *urb; 1105 struct urb *urb;
1106 LIST_HEAD(tmp_list);
1106 1107
1108 /* Create a copy of the wa->xfer_delayed_list while holding the lock */
1107 spin_lock_irq(&wa->xfer_list_lock); 1109 spin_lock_irq(&wa->xfer_list_lock);
1108 list_for_each_entry_safe(xfer, next, &wa->xfer_delayed_list, 1110 list_cut_position(&tmp_list, &wa->xfer_delayed_list,
1109 list_node) { 1111 wa->xfer_delayed_list.prev);
1112 spin_unlock_irq(&wa->xfer_list_lock);
1113
1114 /*
1115 * enqueue from temp list without list lock held since wa_urb_enqueue_b
1116 * can take xfer->lock as well as lock mutexes.
1117 */
1118 list_for_each_entry_safe(xfer, next, &tmp_list, list_node) {
1110 list_del_init(&xfer->list_node); 1119 list_del_init(&xfer->list_node);
1111 spin_unlock_irq(&wa->xfer_list_lock);
1112 1120
1113 urb = xfer->urb; 1121 urb = xfer->urb;
1114 wa_urb_enqueue_b(xfer); 1122 wa_urb_enqueue_b(xfer);
1115 usb_put_urb(urb); /* taken when queuing */ 1123 usb_put_urb(urb); /* taken when queuing */
1116
1117 spin_lock_irq(&wa->xfer_list_lock);
1118 } 1124 }
1119 spin_unlock_irq(&wa->xfer_list_lock);
1120} 1125}
1121EXPORT_SYMBOL_GPL(wa_urb_enqueue_run); 1126EXPORT_SYMBOL_GPL(wa_urb_enqueue_run);
1122 1127
diff --git a/drivers/uwb/hwa-rc.c b/drivers/uwb/hwa-rc.c
index 0621abef9b4a..0257f35cfb9d 100644
--- a/drivers/uwb/hwa-rc.c
+++ b/drivers/uwb/hwa-rc.c
@@ -611,7 +611,16 @@ static
611int hwarc_reset(struct uwb_rc *uwb_rc) 611int hwarc_reset(struct uwb_rc *uwb_rc)
612{ 612{
613 struct hwarc *hwarc = uwb_rc->priv; 613 struct hwarc *hwarc = uwb_rc->priv;
614 return usb_reset_device(hwarc->usb_dev); 614 int result;
615
616 /* device lock must be held when calling usb_reset_device. */
617 result = usb_lock_device_for_reset(hwarc->usb_dev, NULL);
618 if (result >= 0) {
619 result = usb_reset_device(hwarc->usb_dev);
620 usb_unlock_device(hwarc->usb_dev);
621 }
622
623 return result;
615} 624}
616 625
617/** 626/**
@@ -709,8 +718,10 @@ static int hwarc_neep_init(struct uwb_rc *rc)
709 718
710error_neep_submit: 719error_neep_submit:
711 usb_free_urb(hwarc->neep_urb); 720 usb_free_urb(hwarc->neep_urb);
721 hwarc->neep_urb = NULL;
712error_urb_alloc: 722error_urb_alloc:
713 free_page((unsigned long)hwarc->rd_buffer); 723 free_page((unsigned long)hwarc->rd_buffer);
724 hwarc->rd_buffer = NULL;
714error_rd_buffer: 725error_rd_buffer:
715 return -ENOMEM; 726 return -ENOMEM;
716} 727}
@@ -723,7 +734,10 @@ static void hwarc_neep_release(struct uwb_rc *rc)
723 734
724 usb_kill_urb(hwarc->neep_urb); 735 usb_kill_urb(hwarc->neep_urb);
725 usb_free_urb(hwarc->neep_urb); 736 usb_free_urb(hwarc->neep_urb);
737 hwarc->neep_urb = NULL;
738
726 free_page((unsigned long)hwarc->rd_buffer); 739 free_page((unsigned long)hwarc->rd_buffer);
740 hwarc->rd_buffer = NULL;
727} 741}
728 742
729/** 743/**
diff --git a/drivers/uwb/pal.c b/drivers/uwb/pal.c
index 690577d2a35b..c1304b8d4985 100644
--- a/drivers/uwb/pal.c
+++ b/drivers/uwb/pal.c
@@ -68,8 +68,40 @@ int uwb_pal_register(struct uwb_pal *pal)
68} 68}
69EXPORT_SYMBOL_GPL(uwb_pal_register); 69EXPORT_SYMBOL_GPL(uwb_pal_register);
70 70
71static int find_rc(struct device *dev, const void *data)
72{
73 const struct uwb_rc *target_rc = data;
74 struct uwb_rc *rc = dev_get_drvdata(dev);
75
76 if (rc == NULL) {
77 WARN_ON(1);
78 return 0;
79 }
80 if (rc == target_rc) {
81 if (rc->ready == 0)
82 return 0;
83 else
84 return 1;
85 }
86 return 0;
87}
88
89/**
90 * Given a radio controller descriptor see if it is registered.
91 *
92 * @returns false if the rc does not exist or is quiescing; true otherwise.
93 */
94static bool uwb_rc_class_device_exists(struct uwb_rc *target_rc)
95{
96 struct device *dev;
97
98 dev = class_find_device(&uwb_rc_class, NULL, target_rc, find_rc);
99
100 return (dev != NULL);
101}
102
71/** 103/**
72 * uwb_pal_register - unregister a UWB PAL 104 * uwb_pal_unregister - unregister a UWB PAL
73 * @pal: the PAL 105 * @pal: the PAL
74 */ 106 */
75void uwb_pal_unregister(struct uwb_pal *pal) 107void uwb_pal_unregister(struct uwb_pal *pal)
@@ -85,7 +117,11 @@ void uwb_pal_unregister(struct uwb_pal *pal)
85 debugfs_remove(pal->debugfs_dir); 117 debugfs_remove(pal->debugfs_dir);
86 118
87 if (pal->device) { 119 if (pal->device) {
88 sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name); 120 /* remove link to the PAL in the UWB device's directory. */
121 if (uwb_rc_class_device_exists(rc))
122 sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name);
123
124 /* remove link to uwb_rc in the PAL device's directory. */
89 sysfs_remove_link(&pal->device->kobj, "uwb_rc"); 125 sysfs_remove_link(&pal->device->kobj, "uwb_rc");
90 } 126 }
91} 127}