aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/atm/usbatm.h14
-rw-r--r--drivers/usb/c67x00/c67x00-sched.c2
-rw-r--r--drivers/usb/chipidea/Kconfig2
-rw-r--r--drivers/usb/chipidea/bits.h1
-rw-r--r--drivers/usb/chipidea/ci_hdrc_imx.c21
-rw-r--r--drivers/usb/chipidea/ci_hdrc_pci.c7
-rw-r--r--drivers/usb/chipidea/core.c124
-rw-r--r--drivers/usb/chipidea/host.c12
-rw-r--r--drivers/usb/chipidea/udc.c60
-rw-r--r--drivers/usb/class/cdc-wdm.c42
-rw-r--r--drivers/usb/core/devio.c54
-rw-r--r--drivers/usb/core/driver.c7
-rw-r--r--drivers/usb/core/file.c24
-rw-r--r--drivers/usb/core/hcd-pci.c3
-rw-r--r--drivers/usb/core/hcd.c122
-rw-r--r--drivers/usb/core/hub.c185
-rw-r--r--drivers/usb/core/message.c4
-rw-r--r--drivers/usb/core/quirks.c43
-rw-r--r--drivers/usb/core/sysfs.c64
-rw-r--r--drivers/usb/core/urb.c44
-rw-r--r--drivers/usb/core/usb.c2
-rw-r--r--drivers/usb/core/usb.h1
-rw-r--r--drivers/usb/dwc3/Kconfig3
-rw-r--r--drivers/usb/dwc3/core.c3
-rw-r--r--drivers/usb/dwc3/dwc3-exynos.c7
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c6
-rw-r--r--drivers/usb/dwc3/ep0.c6
-rw-r--r--drivers/usb/dwc3/gadget.c6
-rw-r--r--drivers/usb/early/ehci-dbgp.c4
-rw-r--r--drivers/usb/gadget/Kconfig38
-rw-r--r--drivers/usb/gadget/Makefile5
-rw-r--r--drivers/usb/gadget/acm_ms.c125
-rw-r--r--drivers/usb/gadget/amd5536udc.c2
-rw-r--r--drivers/usb/gadget/cdc2.c19
-rw-r--r--drivers/usb/gadget/composite.c2
-rw-r--r--drivers/usb/gadget/configfs.c10
-rw-r--r--drivers/usb/gadget/configfs.h6
-rw-r--r--drivers/usb/gadget/dummy_hcd.c13
-rw-r--r--drivers/usb/gadget/f_ecm.c2
-rw-r--r--drivers/usb/gadget/f_eem.c2
-rw-r--r--drivers/usb/gadget/f_fs.c64
-rw-r--r--drivers/usb/gadget/f_mass_storage.c1256
-rw-r--r--drivers/usb/gadget/f_mass_storage.h166
-rw-r--r--drivers/usb/gadget/fotg210-udc.c2
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c1
-rw-r--r--drivers/usb/gadget/fusb300_udc.c2
-rw-r--r--drivers/usb/gadget/g_ffs.c2
-rw-r--r--drivers/usb/gadget/goku_udc.c3
-rw-r--r--drivers/usb/gadget/inode.c9
-rw-r--r--drivers/usb/gadget/lpc32xx_udc.c4
-rw-r--r--drivers/usb/gadget/mass_storage.c125
-rw-r--r--drivers/usb/gadget/multi.c255
-rw-r--r--drivers/usb/gadget/mv_u3d_core.c7
-rw-r--r--drivers/usb/gadget/net2280.c5
-rw-r--r--drivers/usb/gadget/pch_udc.c1
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c9
-rw-r--r--drivers/usb/gadget/rndis.c2
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c182
-rw-r--r--drivers/usb/gadget/storage_common.c430
-rw-r--r--drivers/usb/gadget/storage_common.h229
-rw-r--r--drivers/usb/gadget/tcm_usb_gadget.c4
-rw-r--r--drivers/usb/gadget/udc-core.c3
-rw-r--r--drivers/usb/gadget/zero.c25
-rw-r--r--drivers/usb/host/Kconfig60
-rw-r--r--drivers/usb/host/Makefile11
-rw-r--r--drivers/usb/host/bcma-hcd.c3
-rw-r--r--drivers/usb/host/ehci-atmel.c23
-rw-r--r--drivers/usb/host/ehci-dbg.c113
-rw-r--r--drivers/usb/host/ehci-exynos.c (renamed from drivers/usb/host/ehci-s5p.c)171
-rw-r--r--drivers/usb/host/ehci-fsl.c19
-rw-r--r--drivers/usb/host/ehci-hcd.c40
-rw-r--r--drivers/usb/host/ehci-mem.c4
-rw-r--r--drivers/usb/host/ehci-msm.c20
-rw-r--r--drivers/usb/host/ehci-octeon.c4
-rw-r--r--drivers/usb/host/ehci-omap.c10
-rw-r--r--drivers/usb/host/ehci-orion.c7
-rw-r--r--drivers/usb/host/ehci-pci.c26
-rw-r--r--drivers/usb/host/ehci-platform.c10
-rw-r--r--drivers/usb/host/ehci-ppc-of.c2
-rw-r--r--drivers/usb/host/ehci-q.c59
-rw-r--r--drivers/usb/host/ehci-sched.c1033
-rw-r--r--drivers/usb/host/ehci-spear.c7
-rw-r--r--drivers/usb/host/ehci-sysfs.c15
-rw-r--r--drivers/usb/host/ehci-tegra.c11
-rw-r--r--drivers/usb/host/ehci-w90x900.c89
-rw-r--r--drivers/usb/host/ehci.h81
-rw-r--r--drivers/usb/host/fhci-hcd.c2
-rw-r--r--drivers/usb/host/fotg210-hcd.c2
-rw-r--r--drivers/usb/host/fsl-mph-dr-of.c22
-rw-r--r--drivers/usb/host/fusbh200-hcd.c2
-rw-r--r--drivers/usb/host/hwa-hc.c33
-rw-r--r--drivers/usb/host/imx21-hcd.c8
-rw-r--r--drivers/usb/host/isp1362-hcd.c2
-rw-r--r--drivers/usb/host/ohci-at91.c165
-rw-r--r--drivers/usb/host/ohci-dbg.c2
-rw-r--r--drivers/usb/host/ohci-ep93xx.c184
-rw-r--r--drivers/usb/host/ohci-exynos.c193
-rw-r--r--drivers/usb/host/ohci-hcd.c181
-rw-r--r--drivers/usb/host/ohci-hub.c9
-rw-r--r--drivers/usb/host/ohci-nxp.c128
-rw-r--r--drivers/usb/host/ohci-octeon.c5
-rw-r--r--drivers/usb/host/ohci-omap.c169
-rw-r--r--drivers/usb/host/ohci-omap3.c128
-rw-r--r--drivers/usb/host/ohci-pci.c15
-rw-r--r--drivers/usb/host/ohci-platform.c11
-rw-r--r--drivers/usb/host/ohci-ppc-of.c2
-rw-r--r--drivers/usb/host/ohci-pxa27x.c257
-rw-r--r--drivers/usb/host/ohci-q.c26
-rw-r--r--drivers/usb/host/ohci-s3c2410.c136
-rw-r--r--drivers/usb/host/ohci-sa1111.c6
-rw-r--r--drivers/usb/host/ohci-sm501.c11
-rw-r--r--drivers/usb/host/ohci-spear.c147
-rw-r--r--drivers/usb/host/pci-quirks.c141
-rw-r--r--drivers/usb/host/pci-quirks.h2
-rw-r--r--drivers/usb/host/sl811-hcd.c4
-rw-r--r--drivers/usb/host/ssb-hcd.c3
-rw-r--r--drivers/usb/host/uhci-debug.c16
-rw-r--r--drivers/usb/host/uhci-hub.c40
-rw-r--r--drivers/usb/host/uhci-pci.c21
-rw-r--r--drivers/usb/host/uhci-platform.c10
-rw-r--r--drivers/usb/host/uhci-q.c12
-rw-r--r--drivers/usb/host/whci/hcd.c4
-rw-r--r--drivers/usb/host/xhci-hub.c78
-rw-r--r--drivers/usb/host/xhci-mem.c12
-rw-r--r--drivers/usb/host/xhci-pci.c27
-rw-r--r--drivers/usb/host/xhci-ring.c361
-rw-r--r--drivers/usb/host/xhci.c221
-rw-r--r--drivers/usb/host/xhci.h16
-rw-r--r--drivers/usb/misc/Kconfig2
-rw-r--r--drivers/usb/misc/usbtest.c172
-rw-r--r--drivers/usb/musb/Kconfig6
-rw-r--r--drivers/usb/musb/am35x.c63
-rw-r--r--drivers/usb/musb/blackfin.c13
-rw-r--r--drivers/usb/musb/da8xx.c49
-rw-r--r--drivers/usb/musb/davinci.c59
-rw-r--r--drivers/usb/musb/musb_am335x.c2
-rw-r--r--drivers/usb/musb/musb_core.c65
-rw-r--r--drivers/usb/musb/musb_core.h3
-rw-r--r--drivers/usb/musb/musb_cppi41.c8
-rw-r--r--drivers/usb/musb/musb_dsps.c99
-rw-r--r--drivers/usb/musb/musb_gadget.c8
-rw-r--r--drivers/usb/musb/musb_host.c2
-rw-r--r--drivers/usb/musb/musb_virthub.c65
-rw-r--r--drivers/usb/musb/omap2430.c54
-rw-r--r--drivers/usb/musb/tusb6010.c49
-rw-r--r--drivers/usb/musb/ux500.c15
-rw-r--r--drivers/usb/phy/Kconfig35
-rw-r--r--drivers/usb/phy/Makefile3
-rw-r--r--drivers/usb/phy/phy-am335x-control.c44
-rw-r--r--drivers/usb/phy/phy-am335x.c44
-rw-r--r--drivers/usb/phy/phy-fsl-usb.c96
-rw-r--r--drivers/usb/phy/phy-fsl-usb.h4
-rw-r--r--drivers/usb/phy/phy-fsm-usb.c72
-rw-r--r--drivers/usb/phy/phy-fsm-usb.h179
-rw-r--r--drivers/usb/phy/phy-generic.c108
-rw-r--r--drivers/usb/phy/phy-generic.h7
-rw-r--r--drivers/usb/phy/phy-gpio-vbus-usb.c11
-rw-r--r--drivers/usb/phy/phy-omap-control.c208
-rw-r--r--drivers/usb/phy/phy-omap-usb2.c272
-rw-r--r--drivers/usb/phy/phy-omap-usb3.c34
-rw-r--r--drivers/usb/phy/phy-rcar-gen2-usb.c248
-rw-r--r--drivers/usb/phy/phy-samsung-usb2.c3
-rw-r--r--drivers/usb/phy/phy-samsung-usb3.c3
-rw-r--r--drivers/usb/phy/phy-tegra-usb.c2
-rw-r--r--drivers/usb/phy/phy-twl4030-usb.c794
-rw-r--r--drivers/usb/phy/phy-twl6030-usb.c1
-rw-r--r--drivers/usb/phy/phy-ulpi-viewport.c2
-rw-r--r--drivers/usb/phy/phy.c2
-rw-r--r--drivers/usb/renesas_usbhs/Kconfig2
-rw-r--r--drivers/usb/serial/Kconfig2
-rw-r--r--drivers/usb/serial/cyberjack.c2
-rw-r--r--drivers/usb/serial/ftdi_sio.c11
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h6
-rw-r--r--drivers/usb/serial/generic.c82
-rw-r--r--drivers/usb/serial/mos7720.c2
-rw-r--r--drivers/usb/serial/mos7840.c4
-rw-r--r--drivers/usb/serial/option.c245
-rw-r--r--drivers/usb/serial/pl2303.c253
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c1
-rw-r--r--drivers/usb/storage/scsiglue.c5
-rw-r--r--drivers/usb/storage/unusual_devs.h7
-rw-r--r--drivers/usb/wusbcore/cbaf.c7
-rw-r--r--drivers/usb/wusbcore/devconnect.c2
-rw-r--r--drivers/usb/wusbcore/wa-hc.c18
-rw-r--r--drivers/usb/wusbcore/wa-hc.h42
-rw-r--r--drivers/usb/wusbcore/wa-rpipe.c22
-rw-r--r--drivers/usb/wusbcore/wa-xfer.c1261
187 files changed, 7613 insertions, 5782 deletions
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h
index 5651231a7437..f3eecd967a8a 100644
--- a/drivers/usb/atm/usbatm.h
+++ b/drivers/usb/atm/usbatm.h
@@ -34,6 +34,7 @@
34#include <linux/stringify.h> 34#include <linux/stringify.h>
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/ratelimit.h>
37 38
38/* 39/*
39#define VERBOSE_DEBUG 40#define VERBOSE_DEBUG
@@ -59,13 +60,12 @@
59 atm_printk(KERN_INFO, instance , format , ## arg) 60 atm_printk(KERN_INFO, instance , format , ## arg)
60#define atm_warn(instance, format, arg...) \ 61#define atm_warn(instance, format, arg...) \
61 atm_printk(KERN_WARNING, instance , format , ## arg) 62 atm_printk(KERN_WARNING, instance , format , ## arg)
62#define atm_dbg(instance, format, arg...) \ 63#define atm_dbg(instance, format, ...) \
63 dynamic_pr_debug("ATM dev %d: " format , \ 64 pr_debug("ATM dev %d: " format, \
64 (instance)->atm_dev->number , ## arg) 65 (instance)->atm_dev->number, ##__VA_ARGS__)
65#define atm_rldbg(instance, format, arg...) \ 66#define atm_rldbg(instance, format, ...) \
66 if (printk_ratelimit()) \ 67 pr_debug_ratelimited("ATM dev %d: " format, \
67 atm_dbg(instance , format , ## arg) 68 (instance)->atm_dev->number, ##__VA_ARGS__)
68
69 69
70/* flags, set by mini-driver in bind() */ 70/* flags, set by mini-driver in bind() */
71 71
diff --git a/drivers/usb/c67x00/c67x00-sched.c b/drivers/usb/c67x00/c67x00-sched.c
index aa491627a45b..892cc96466eb 100644
--- a/drivers/usb/c67x00/c67x00-sched.c
+++ b/drivers/usb/c67x00/c67x00-sched.c
@@ -344,7 +344,7 @@ void c67x00_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
344 /* it could happen that we reinitialize this completion, while 344 /* it could happen that we reinitialize this completion, while
345 * somebody was waiting for that completion. The timeout and 345 * somebody was waiting for that completion. The timeout and
346 * while loop handle such cases, but this might be improved */ 346 * while loop handle such cases, but this might be improved */
347 INIT_COMPLETION(c67x00->endpoint_disable); 347 reinit_completion(&c67x00->endpoint_disable);
348 c67x00_sched_kick(c67x00); 348 c67x00_sched_kick(c67x00);
349 wait_for_completion_timeout(&c67x00->endpoint_disable, 1 * HZ); 349 wait_for_completion_timeout(&c67x00->endpoint_disable, 1 * HZ);
350 350
diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig
index 4a851e15e58c..77b47d82c9a6 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_EHCI_HCD && USB_GADGET) || (USB_EHCI_HCD && !USB_GADGET) || (!USB_EHCI_HCD && USB_GADGET) 3 depends on ((USB_EHCI_HCD && USB_GADGET) || (USB_EHCI_HCD && !USB_GADGET) || (!USB_EHCI_HCD && USB_GADGET)) && HAS_DMA
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
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 464584c6ccae..a85713165688 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -48,6 +48,7 @@
48#define PORTSC_SUSP BIT(7) 48#define PORTSC_SUSP BIT(7)
49#define PORTSC_HSP BIT(9) 49#define PORTSC_HSP BIT(9)
50#define PORTSC_PTC (0x0FUL << 16) 50#define PORTSC_PTC (0x0FUL << 16)
51#define PORTSC_PHCD(d) ((d) ? BIT(22) : BIT(23))
51/* PTS and PTW for non lpm version only */ 52/* PTS and PTW for non lpm version only */
52#define PORTSC_PTS(d) \ 53#define PORTSC_PTS(d) \
53 (u32)((((d) & 0x3) << 30) | (((d) & 0x4) ? BIT(25) : 0)) 54 (u32)((((d) & 0x3) << 30) | (((d) & 0x4) ? BIT(25) : 0))
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index 74d998d9b45b..bb5d976e5b81 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -108,23 +108,16 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
108 } 108 }
109 109
110 data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0); 110 data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0);
111 if (!IS_ERR(data->phy)) { 111 if (IS_ERR(data->phy)) {
112 ret = usb_phy_init(data->phy); 112 ret = PTR_ERR(data->phy);
113 if (ret) {
114 dev_err(&pdev->dev, "unable to init phy: %d\n", ret);
115 goto err_clk;
116 }
117 } else if (PTR_ERR(data->phy) == -EPROBE_DEFER) {
118 ret = -EPROBE_DEFER;
119 goto err_clk; 113 goto err_clk;
120 } 114 }
121 115
122 pdata.phy = data->phy; 116 pdata.phy = data->phy;
123 117
124 if (!pdev->dev.dma_mask) 118 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
125 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 119 if (ret)
126 if (!pdev->dev.coherent_dma_mask) 120 goto err_clk;
127 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
128 121
129 if (data->usbmisc_data) { 122 if (data->usbmisc_data) {
130 ret = imx_usbmisc_init(data->usbmisc_data); 123 ret = imx_usbmisc_init(data->usbmisc_data);
@@ -175,10 +168,6 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
175 168
176 pm_runtime_disable(&pdev->dev); 169 pm_runtime_disable(&pdev->dev);
177 ci_hdrc_remove_device(data->ci_pdev); 170 ci_hdrc_remove_device(data->ci_pdev);
178
179 if (data->phy)
180 usb_phy_shutdown(data->phy);
181
182 clk_disable_unprepare(data->clk); 171 clk_disable_unprepare(data->clk);
183 172
184 return 0; 173 return 0;
diff --git a/drivers/usb/chipidea/ci_hdrc_pci.c b/drivers/usb/chipidea/ci_hdrc_pci.c
index 042320a6c6c7..d514332ac081 100644
--- a/drivers/usb/chipidea/ci_hdrc_pci.c
+++ b/drivers/usb/chipidea/ci_hdrc_pci.c
@@ -129,7 +129,12 @@ static DEFINE_PCI_DEVICE_TABLE(ci_hdrc_pci_id_table) = {
129 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829), 129 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
130 .driver_data = (kernel_ulong_t)&penwell_pci_platdata, 130 .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
131 }, 131 },
132 { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ } 132 {
133 /* Intel Clovertrail */
134 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xe006),
135 .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
136 },
137 { 0 } /* end: all zeroes */
133}; 138};
134MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table); 139MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table);
135 140
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 94626409559a..5d8981c5235e 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -172,6 +172,27 @@ u8 hw_port_test_get(struct ci_hdrc *ci)
172 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC); 172 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC);
173} 173}
174 174
175/* The PHY enters/leaves low power mode */
176static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable)
177{
178 enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC;
179 bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm)));
180
181 if (enable && !lpm) {
182 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
183 PORTSC_PHCD(ci->hw_bank.lpm));
184 } else if (!enable && lpm) {
185 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
186 0);
187 /*
188 * The controller needs at least 1ms to reflect
189 * PHY's status, the PHY also needs some time (less
190 * than 1ms) to leave low power mode.
191 */
192 usleep_range(1500, 2000);
193 }
194}
195
175static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) 196static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
176{ 197{
177 u32 reg; 198 u32 reg;
@@ -199,6 +220,8 @@ static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
199 if (ci->hw_ep_max > ENDPT_MAX) 220 if (ci->hw_ep_max > ENDPT_MAX)
200 return -ENODEV; 221 return -ENODEV;
201 222
223 ci_hdrc_enter_lpm(ci, false);
224
202 /* Disable all interrupts bits */ 225 /* Disable all interrupts bits */
203 hw_write(ci, OP_USBINTR, 0xffffffff, 0); 226 hw_write(ci, OP_USBINTR, 0xffffffff, 0);
204 227
@@ -369,16 +392,28 @@ static irqreturn_t ci_irq(int irq, void *data)
369static int ci_get_platdata(struct device *dev, 392static int ci_get_platdata(struct device *dev,
370 struct ci_hdrc_platform_data *platdata) 393 struct ci_hdrc_platform_data *platdata)
371{ 394{
372 /* Get the vbus regulator */ 395 if (!platdata->phy_mode)
373 platdata->reg_vbus = devm_regulator_get(dev, "vbus"); 396 platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);
374 if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) { 397
375 return -EPROBE_DEFER; 398 if (!platdata->dr_mode)
376 } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) { 399 platdata->dr_mode = of_usb_get_dr_mode(dev->of_node);
377 platdata->reg_vbus = NULL; /* no vbus regualator is needed */ 400
378 } else if (IS_ERR(platdata->reg_vbus)) { 401 if (platdata->dr_mode == USB_DR_MODE_UNKNOWN)
379 dev_err(dev, "Getting regulator error: %ld\n", 402 platdata->dr_mode = USB_DR_MODE_OTG;
380 PTR_ERR(platdata->reg_vbus)); 403
381 return PTR_ERR(platdata->reg_vbus); 404 if (platdata->dr_mode != USB_DR_MODE_PERIPHERAL) {
405 /* Get the vbus regulator */
406 platdata->reg_vbus = devm_regulator_get(dev, "vbus");
407 if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
408 return -EPROBE_DEFER;
409 } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
410 /* no vbus regualator is needed */
411 platdata->reg_vbus = NULL;
412 } else if (IS_ERR(platdata->reg_vbus)) {
413 dev_err(dev, "Getting regulator error: %ld\n",
414 PTR_ERR(platdata->reg_vbus));
415 return PTR_ERR(platdata->reg_vbus);
416 }
382 } 417 }
383 418
384 return 0; 419 return 0;
@@ -465,6 +500,33 @@ static void ci_get_otg_capable(struct ci_hdrc *ci)
465 } 500 }
466} 501}
467 502
503static int ci_usb_phy_init(struct ci_hdrc *ci)
504{
505 if (ci->platdata->phy) {
506 ci->transceiver = ci->platdata->phy;
507 return usb_phy_init(ci->transceiver);
508 } else {
509 ci->global_phy = true;
510 ci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
511 if (IS_ERR(ci->transceiver))
512 ci->transceiver = NULL;
513
514 return 0;
515 }
516}
517
518static void ci_usb_phy_destroy(struct ci_hdrc *ci)
519{
520 if (!ci->transceiver)
521 return;
522
523 otg_set_peripheral(ci->transceiver->otg, NULL);
524 if (ci->global_phy)
525 usb_put_phy(ci->transceiver);
526 else
527 usb_phy_shutdown(ci->transceiver);
528}
529
468static int ci_hdrc_probe(struct platform_device *pdev) 530static int ci_hdrc_probe(struct platform_device *pdev)
469{ 531{
470 struct device *dev = &pdev->dev; 532 struct device *dev = &pdev->dev;
@@ -473,7 +535,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
473 void __iomem *base; 535 void __iomem *base;
474 int ret; 536 int ret;
475 enum usb_dr_mode dr_mode; 537 enum usb_dr_mode dr_mode;
476 struct device_node *of_node = dev->of_node ?: dev->parent->of_node;
477 538
478 if (!dev->platform_data) { 539 if (!dev->platform_data) {
479 dev_err(dev, "platform data missing\n"); 540 dev_err(dev, "platform data missing\n");
@@ -493,10 +554,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
493 554
494 ci->dev = dev; 555 ci->dev = dev;
495 ci->platdata = dev->platform_data; 556 ci->platdata = dev->platform_data;
496 if (ci->platdata->phy)
497 ci->transceiver = ci->platdata->phy;
498 else
499 ci->global_phy = true;
500 557
501 ret = hw_device_init(ci, base); 558 ret = hw_device_init(ci, base);
502 if (ret < 0) { 559 if (ret < 0) {
@@ -504,27 +561,25 @@ static int ci_hdrc_probe(struct platform_device *pdev)
504 return -ENODEV; 561 return -ENODEV;
505 } 562 }
506 563
564 ret = ci_usb_phy_init(ci);
565 if (ret) {
566 dev_err(dev, "unable to init phy: %d\n", ret);
567 return ret;
568 }
569
507 ci->hw_bank.phys = res->start; 570 ci->hw_bank.phys = res->start;
508 571
509 ci->irq = platform_get_irq(pdev, 0); 572 ci->irq = platform_get_irq(pdev, 0);
510 if (ci->irq < 0) { 573 if (ci->irq < 0) {
511 dev_err(dev, "missing IRQ\n"); 574 dev_err(dev, "missing IRQ\n");
512 return -ENODEV; 575 ret = -ENODEV;
576 goto destroy_phy;
513 } 577 }
514 578
515 ci_get_otg_capable(ci); 579 ci_get_otg_capable(ci);
516 580
517 if (!ci->platdata->phy_mode)
518 ci->platdata->phy_mode = of_usb_get_phy_mode(of_node);
519
520 hw_phymode_configure(ci); 581 hw_phymode_configure(ci);
521 582
522 if (!ci->platdata->dr_mode)
523 ci->platdata->dr_mode = of_usb_get_dr_mode(of_node);
524
525 if (ci->platdata->dr_mode == USB_DR_MODE_UNKNOWN)
526 ci->platdata->dr_mode = USB_DR_MODE_OTG;
527
528 dr_mode = ci->platdata->dr_mode; 583 dr_mode = ci->platdata->dr_mode;
529 /* initialize role(s) before the interrupt is requested */ 584 /* initialize role(s) before the interrupt is requested */
530 if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { 585 if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
@@ -537,11 +592,23 @@ static int ci_hdrc_probe(struct platform_device *pdev)
537 ret = ci_hdrc_gadget_init(ci); 592 ret = ci_hdrc_gadget_init(ci);
538 if (ret) 593 if (ret)
539 dev_info(dev, "doesn't support gadget\n"); 594 dev_info(dev, "doesn't support gadget\n");
595 if (!ret && ci->transceiver) {
596 ret = otg_set_peripheral(ci->transceiver->otg,
597 &ci->gadget);
598 /*
599 * If we implement all USB functions using chipidea drivers,
600 * it doesn't need to call above API, meanwhile, if we only
601 * use gadget function, calling above API is useless.
602 */
603 if (ret && ret != -ENOTSUPP)
604 goto destroy_phy;
605 }
540 } 606 }
541 607
542 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { 608 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
543 dev_err(dev, "no supported roles\n"); 609 dev_err(dev, "no supported roles\n");
544 return -ENODEV; 610 ret = -ENODEV;
611 goto destroy_phy;
545 } 612 }
546 613
547 if (ci->is_otg) { 614 if (ci->is_otg) {
@@ -594,6 +661,8 @@ static int ci_hdrc_probe(struct platform_device *pdev)
594 free_irq(ci->irq, ci); 661 free_irq(ci->irq, ci);
595stop: 662stop:
596 ci_role_destroy(ci); 663 ci_role_destroy(ci);
664destroy_phy:
665 ci_usb_phy_destroy(ci);
597 666
598 return ret; 667 return ret;
599} 668}
@@ -605,6 +674,9 @@ static int ci_hdrc_remove(struct platform_device *pdev)
605 dbg_remove_files(ci); 674 dbg_remove_files(ci);
606 free_irq(ci->irq, ci); 675 free_irq(ci->irq, ci);
607 ci_role_destroy(ci); 676 ci_role_destroy(ci);
677 ci_hdrc_enter_lpm(ci, true);
678 ci_usb_phy_destroy(ci);
679 kfree(ci->hw_bank.regmap);
608 680
609 return 0; 681 return 0;
610} 682}
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 6f96795dd20c..59e6020ea753 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -100,16 +100,18 @@ static void host_stop(struct ci_hdrc *ci)
100{ 100{
101 struct usb_hcd *hcd = ci->hcd; 101 struct usb_hcd *hcd = ci->hcd;
102 102
103 usb_remove_hcd(hcd); 103 if (hcd) {
104 usb_put_hcd(hcd); 104 usb_remove_hcd(hcd);
105 if (ci->platdata->reg_vbus) 105 usb_put_hcd(hcd);
106 regulator_disable(ci->platdata->reg_vbus); 106 if (ci->platdata->reg_vbus)
107 regulator_disable(ci->platdata->reg_vbus);
108 }
107} 109}
108 110
109 111
110void ci_hdrc_host_destroy(struct ci_hdrc *ci) 112void ci_hdrc_host_destroy(struct ci_hdrc *ci)
111{ 113{
112 if (ci->role == CI_ROLE_HOST) 114 if (ci->role == CI_ROLE_HOST && ci->hcd)
113 host_stop(ci); 115 host_stop(ci);
114} 116}
115 117
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 6b4c2f2eb946..b34c81969cba 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -20,7 +20,6 @@
20#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
21#include <linux/usb/ch9.h> 21#include <linux/usb/ch9.h>
22#include <linux/usb/gadget.h> 22#include <linux/usb/gadget.h>
23#include <linux/usb/otg.h>
24#include <linux/usb/chipidea.h> 23#include <linux/usb/chipidea.h>
25 24
26#include "ci.h" 25#include "ci.h"
@@ -686,9 +685,6 @@ static int _gadget_stop_activity(struct usb_gadget *gadget)
686 usb_ep_fifo_flush(&ci->ep0out->ep); 685 usb_ep_fifo_flush(&ci->ep0out->ep);
687 usb_ep_fifo_flush(&ci->ep0in->ep); 686 usb_ep_fifo_flush(&ci->ep0in->ep);
688 687
689 if (ci->driver)
690 ci->driver->disconnect(gadget);
691
692 /* make sure to disable all endpoints */ 688 /* make sure to disable all endpoints */
693 gadget_for_each_ep(ep, gadget) { 689 gadget_for_each_ep(ep, gadget) {
694 usb_ep_disable(ep); 690 usb_ep_disable(ep);
@@ -718,6 +714,11 @@ __acquires(ci->lock)
718 int retval; 714 int retval;
719 715
720 spin_unlock(&ci->lock); 716 spin_unlock(&ci->lock);
717 if (ci->gadget.speed != USB_SPEED_UNKNOWN) {
718 if (ci->driver)
719 ci->driver->disconnect(&ci->gadget);
720 }
721
721 retval = _gadget_stop_activity(&ci->gadget); 722 retval = _gadget_stop_activity(&ci->gadget);
722 if (retval) 723 if (retval)
723 goto done; 724 goto done;
@@ -1461,6 +1462,8 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
1461 hw_device_state(ci, ci->ep0out->qh.dma); 1462 hw_device_state(ci, ci->ep0out->qh.dma);
1462 dev_dbg(ci->dev, "Connected to host\n"); 1463 dev_dbg(ci->dev, "Connected to host\n");
1463 } else { 1464 } else {
1465 if (ci->driver)
1466 ci->driver->disconnect(&ci->gadget);
1464 hw_device_state(ci, 0); 1467 hw_device_state(ci, 0);
1465 if (ci->platdata->notify_event) 1468 if (ci->platdata->notify_event)
1466 ci->platdata->notify_event(ci, 1469 ci->platdata->notify_event(ci,
@@ -1600,6 +1603,8 @@ static void destroy_eps(struct ci_hdrc *ci)
1600 for (i = 0; i < ci->hw_ep_max; i++) { 1603 for (i = 0; i < ci->hw_ep_max; i++) {
1601 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; 1604 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i];
1602 1605
1606 if (hwep->pending_td)
1607 free_pending_td(hwep);
1603 dma_pool_free(ci->qh_pool, hwep->qh.ptr, hwep->qh.dma); 1608 dma_pool_free(ci->qh_pool, hwep->qh.ptr, hwep->qh.dma);
1604 } 1609 }
1605} 1610}
@@ -1631,23 +1636,22 @@ static int ci_udc_start(struct usb_gadget *gadget,
1631 retval = usb_ep_enable(&ci->ep0in->ep); 1636 retval = usb_ep_enable(&ci->ep0in->ep);
1632 if (retval) 1637 if (retval)
1633 return retval; 1638 return retval;
1634 spin_lock_irqsave(&ci->lock, flags);
1635 1639
1636 ci->driver = driver; 1640 ci->driver = driver;
1637 pm_runtime_get_sync(&ci->gadget.dev); 1641 pm_runtime_get_sync(&ci->gadget.dev);
1638 if (ci->vbus_active) { 1642 if (ci->vbus_active) {
1643 spin_lock_irqsave(&ci->lock, flags);
1639 hw_device_reset(ci, USBMODE_CM_DC); 1644 hw_device_reset(ci, USBMODE_CM_DC);
1640 } else { 1645 } else {
1641 pm_runtime_put_sync(&ci->gadget.dev); 1646 pm_runtime_put_sync(&ci->gadget.dev);
1642 goto done; 1647 return retval;
1643 } 1648 }
1644 1649
1645 retval = hw_device_state(ci, ci->ep0out->qh.dma); 1650 retval = hw_device_state(ci, ci->ep0out->qh.dma);
1651 spin_unlock_irqrestore(&ci->lock, flags);
1646 if (retval) 1652 if (retval)
1647 pm_runtime_put_sync(&ci->gadget.dev); 1653 pm_runtime_put_sync(&ci->gadget.dev);
1648 1654
1649 done:
1650 spin_unlock_irqrestore(&ci->lock, flags);
1651 return retval; 1655 return retval;
1652} 1656}
1653 1657
@@ -1667,13 +1671,13 @@ static int ci_udc_stop(struct usb_gadget *gadget,
1667 if (ci->platdata->notify_event) 1671 if (ci->platdata->notify_event)
1668 ci->platdata->notify_event(ci, 1672 ci->platdata->notify_event(ci,
1669 CI_HDRC_CONTROLLER_STOPPED_EVENT); 1673 CI_HDRC_CONTROLLER_STOPPED_EVENT);
1670 ci->driver = NULL;
1671 spin_unlock_irqrestore(&ci->lock, flags); 1674 spin_unlock_irqrestore(&ci->lock, flags);
1672 _gadget_stop_activity(&ci->gadget); 1675 _gadget_stop_activity(&ci->gadget);
1673 spin_lock_irqsave(&ci->lock, flags); 1676 spin_lock_irqsave(&ci->lock, flags);
1674 pm_runtime_put(&ci->gadget.dev); 1677 pm_runtime_put(&ci->gadget.dev);
1675 } 1678 }
1676 1679
1680 ci->driver = NULL;
1677 spin_unlock_irqrestore(&ci->lock, flags); 1681 spin_unlock_irqrestore(&ci->lock, flags);
1678 1682
1679 return 0; 1683 return 0;
@@ -1784,34 +1788,9 @@ static int udc_start(struct ci_hdrc *ci)
1784 1788
1785 ci->gadget.ep0 = &ci->ep0in->ep; 1789 ci->gadget.ep0 = &ci->ep0in->ep;
1786 1790
1787 if (ci->global_phy) {
1788 ci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
1789 if (IS_ERR(ci->transceiver))
1790 ci->transceiver = NULL;
1791 }
1792
1793 if (ci->platdata->flags & CI_HDRC_REQUIRE_TRANSCEIVER) {
1794 if (ci->transceiver == NULL) {
1795 retval = -ENODEV;
1796 goto destroy_eps;
1797 }
1798 }
1799
1800 if (ci->transceiver) {
1801 retval = otg_set_peripheral(ci->transceiver->otg,
1802 &ci->gadget);
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;
1810 }
1811
1812 retval = usb_add_gadget_udc(dev, &ci->gadget); 1791 retval = usb_add_gadget_udc(dev, &ci->gadget);
1813 if (retval) 1792 if (retval)
1814 goto remove_trans; 1793 goto destroy_eps;
1815 1794
1816 pm_runtime_no_callbacks(&ci->gadget.dev); 1795 pm_runtime_no_callbacks(&ci->gadget.dev);
1817 pm_runtime_enable(&ci->gadget.dev); 1796 pm_runtime_enable(&ci->gadget.dev);
@@ -1821,17 +1800,6 @@ static int udc_start(struct ci_hdrc *ci)
1821 1800
1822 return retval; 1801 return retval;
1823 1802
1824remove_trans:
1825 if (ci->transceiver) {
1826 otg_set_peripheral(ci->transceiver->otg, NULL);
1827 if (ci->global_phy)
1828 usb_put_phy(ci->transceiver);
1829 }
1830
1831 dev_err(dev, "error = %i\n", retval);
1832put_transceiver:
1833 if (ci->transceiver && ci->global_phy)
1834 usb_put_phy(ci->transceiver);
1835destroy_eps: 1803destroy_eps:
1836 destroy_eps(ci); 1804 destroy_eps(ci);
1837free_pools: 1805free_pools:
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index d3318a0df8ee..4d387596f3f0 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -101,6 +101,7 @@ struct wdm_device {
101 struct work_struct rxwork; 101 struct work_struct rxwork;
102 int werr; 102 int werr;
103 int rerr; 103 int rerr;
104 int resp_count;
104 105
105 struct list_head device_list; 106 struct list_head device_list;
106 int (*manage_power)(struct usb_interface *, int); 107 int (*manage_power)(struct usb_interface *, int);
@@ -253,6 +254,10 @@ static void wdm_int_callback(struct urb *urb)
253 "NOTIFY_NETWORK_CONNECTION %s network", 254 "NOTIFY_NETWORK_CONNECTION %s network",
254 dr->wValue ? "connected to" : "disconnected from"); 255 dr->wValue ? "connected to" : "disconnected from");
255 goto exit; 256 goto exit;
257 case USB_CDC_NOTIFY_SPEED_CHANGE:
258 dev_dbg(&desc->intf->dev, "SPEED_CHANGE received (len %u)",
259 urb->actual_length);
260 goto exit;
256 default: 261 default:
257 clear_bit(WDM_POLL_RUNNING, &desc->flags); 262 clear_bit(WDM_POLL_RUNNING, &desc->flags);
258 dev_err(&desc->intf->dev, 263 dev_err(&desc->intf->dev,
@@ -262,9 +267,9 @@ static void wdm_int_callback(struct urb *urb)
262 } 267 }
263 268
264 spin_lock(&desc->iuspin); 269 spin_lock(&desc->iuspin);
265 clear_bit(WDM_READ, &desc->flags);
266 responding = test_and_set_bit(WDM_RESPONDING, &desc->flags); 270 responding = test_and_set_bit(WDM_RESPONDING, &desc->flags);
267 if (!responding && !test_bit(WDM_DISCONNECTING, &desc->flags) 271 if (!desc->resp_count++ && !responding
272 && !test_bit(WDM_DISCONNECTING, &desc->flags)
268 && !test_bit(WDM_SUSPENDING, &desc->flags)) { 273 && !test_bit(WDM_SUSPENDING, &desc->flags)) {
269 rv = usb_submit_urb(desc->response, GFP_ATOMIC); 274 rv = usb_submit_urb(desc->response, GFP_ATOMIC);
270 dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", 275 dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d",
@@ -521,10 +526,36 @@ retry:
521 526
522 desc->length -= cntr; 527 desc->length -= cntr;
523 /* in case we had outstanding data */ 528 /* in case we had outstanding data */
524 if (!desc->length) 529 if (!desc->length) {
525 clear_bit(WDM_READ, &desc->flags); 530 clear_bit(WDM_READ, &desc->flags);
526 531
527 spin_unlock_irq(&desc->iuspin); 532 if (--desc->resp_count) {
533 set_bit(WDM_RESPONDING, &desc->flags);
534 spin_unlock_irq(&desc->iuspin);
535
536 rv = usb_submit_urb(desc->response, GFP_KERNEL);
537 if (rv) {
538 dev_err(&desc->intf->dev,
539 "%s: usb_submit_urb failed with result %d\n",
540 __func__, rv);
541 spin_lock_irq(&desc->iuspin);
542 clear_bit(WDM_RESPONDING, &desc->flags);
543 spin_unlock_irq(&desc->iuspin);
544
545 if (rv == -ENOMEM) {
546 rv = schedule_work(&desc->rxwork);
547 if (rv)
548 dev_err(&desc->intf->dev, "Cannot schedule work\n");
549 } else {
550 spin_lock_irq(&desc->iuspin);
551 desc->resp_count = 0;
552 spin_unlock_irq(&desc->iuspin);
553 }
554 }
555 } else
556 spin_unlock_irq(&desc->iuspin);
557 } else
558 spin_unlock_irq(&desc->iuspin);
528 559
529 rv = cntr; 560 rv = cntr;
530 561
@@ -635,6 +666,9 @@ static int wdm_release(struct inode *inode, struct file *file)
635 if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { 666 if (!test_bit(WDM_DISCONNECTING, &desc->flags)) {
636 dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); 667 dev_dbg(&desc->intf->dev, "wdm_release: cleanup");
637 kill_urbs(desc); 668 kill_urbs(desc);
669 spin_lock_irq(&desc->iuspin);
670 desc->resp_count = 0;
671 spin_unlock_irq(&desc->iuspin);
638 desc->manage_power(desc->intf, 0); 672 desc->manage_power(desc->intf, 0);
639 } else { 673 } else {
640 /* must avoid dev_printk here as desc->intf is invalid */ 674 /* must avoid dev_printk here as desc->intf is invalid */
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 737e3c19967b..967152a63bd3 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -742,6 +742,22 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype,
742 if ((index & ~USB_DIR_IN) == 0) 742 if ((index & ~USB_DIR_IN) == 0)
743 return 0; 743 return 0;
744 ret = findintfep(ps->dev, index); 744 ret = findintfep(ps->dev, index);
745 if (ret < 0) {
746 /*
747 * Some not fully compliant Win apps seem to get
748 * index wrong and have the endpoint number here
749 * rather than the endpoint address (with the
750 * correct direction). Win does let this through,
751 * so we'll not reject it here but leave it to
752 * the device to not break KVM. But we warn.
753 */
754 ret = findintfep(ps->dev, index ^ 0x80);
755 if (ret >= 0)
756 dev_info(&ps->dev->dev,
757 "%s: process %i (%s) requesting ep %02x but needs %02x\n",
758 __func__, task_pid_nr(current),
759 current->comm, index, index ^ 0x80);
760 }
745 if (ret >= 0) 761 if (ret >= 0)
746 ret = checkintf(ps, ret); 762 ret = checkintf(ps, ret);
747 break; 763 break;
@@ -898,10 +914,8 @@ static int proc_control(struct dev_state *ps, void __user *arg)
898 snoop(&dev->dev, "control urb: bRequestType=%02x " 914 snoop(&dev->dev, "control urb: bRequestType=%02x "
899 "bRequest=%02x wValue=%04x " 915 "bRequest=%02x wValue=%04x "
900 "wIndex=%04x wLength=%04x\n", 916 "wIndex=%04x wLength=%04x\n",
901 ctrl.bRequestType, ctrl.bRequest, 917 ctrl.bRequestType, ctrl.bRequest, ctrl.wValue,
902 __le16_to_cpup(&ctrl.wValue), 918 ctrl.wIndex, ctrl.wLength);
903 __le16_to_cpup(&ctrl.wIndex),
904 __le16_to_cpup(&ctrl.wLength));
905 if (ctrl.bRequestType & 0x80) { 919 if (ctrl.bRequestType & 0x80) {
906 if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, 920 if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data,
907 ctrl.wLength)) { 921 ctrl.wLength)) {
@@ -1620,32 +1634,32 @@ static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg)
1620static int proc_control_compat(struct dev_state *ps, 1634static int proc_control_compat(struct dev_state *ps,
1621 struct usbdevfs_ctrltransfer32 __user *p32) 1635 struct usbdevfs_ctrltransfer32 __user *p32)
1622{ 1636{
1623 struct usbdevfs_ctrltransfer __user *p; 1637 struct usbdevfs_ctrltransfer __user *p;
1624 __u32 udata; 1638 __u32 udata;
1625 p = compat_alloc_user_space(sizeof(*p)); 1639 p = compat_alloc_user_space(sizeof(*p));
1626 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) || 1640 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
1627 get_user(udata, &p32->data) || 1641 get_user(udata, &p32->data) ||
1628 put_user(compat_ptr(udata), &p->data)) 1642 put_user(compat_ptr(udata), &p->data))
1629 return -EFAULT; 1643 return -EFAULT;
1630 return proc_control(ps, p); 1644 return proc_control(ps, p);
1631} 1645}
1632 1646
1633static int proc_bulk_compat(struct dev_state *ps, 1647static int proc_bulk_compat(struct dev_state *ps,
1634 struct usbdevfs_bulktransfer32 __user *p32) 1648 struct usbdevfs_bulktransfer32 __user *p32)
1635{ 1649{
1636 struct usbdevfs_bulktransfer __user *p; 1650 struct usbdevfs_bulktransfer __user *p;
1637 compat_uint_t n; 1651 compat_uint_t n;
1638 compat_caddr_t addr; 1652 compat_caddr_t addr;
1639 1653
1640 p = compat_alloc_user_space(sizeof(*p)); 1654 p = compat_alloc_user_space(sizeof(*p));
1641 1655
1642 if (get_user(n, &p32->ep) || put_user(n, &p->ep) || 1656 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
1643 get_user(n, &p32->len) || put_user(n, &p->len) || 1657 get_user(n, &p32->len) || put_user(n, &p->len) ||
1644 get_user(n, &p32->timeout) || put_user(n, &p->timeout) || 1658 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
1645 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data)) 1659 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
1646 return -EFAULT; 1660 return -EFAULT;
1647 1661
1648 return proc_bulk(ps, p); 1662 return proc_bulk(ps, p);
1649} 1663}
1650static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg) 1664static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg)
1651{ 1665{
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index f7841d44feda..47aade2a5e74 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1179,8 +1179,8 @@ static int usb_resume_interface(struct usb_device *udev,
1179 "reset_resume", status); 1179 "reset_resume", status);
1180 } else { 1180 } else {
1181 intf->needs_binding = 1; 1181 intf->needs_binding = 1;
1182 dev_warn(&intf->dev, "no %s for driver %s?\n", 1182 dev_dbg(&intf->dev, "no reset_resume for driver %s?\n",
1183 "reset_resume", driver->name); 1183 driver->name);
1184 } 1184 }
1185 } else { 1185 } else {
1186 status = driver->resume(intf); 1186 status = driver->resume(intf);
@@ -1790,6 +1790,9 @@ int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
1790 struct usb_hcd *hcd = bus_to_hcd(udev->bus); 1790 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1791 int ret = -EPERM; 1791 int ret = -EPERM;
1792 1792
1793 if (enable && !udev->usb2_hw_lpm_allowed)
1794 return 0;
1795
1793 if (hcd->driver->set_usb2_hw_lpm) { 1796 if (hcd->driver->set_usb2_hw_lpm) {
1794 ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable); 1797 ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable);
1795 if (!ret) 1798 if (!ret)
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 7421888087a3..ea337a718cc1 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -8,7 +8,7 @@
8 * (C) Copyright Deti Fliegl 1999 (new USB architecture) 8 * (C) Copyright Deti Fliegl 1999 (new USB architecture)
9 * (C) Copyright Randy Dunlap 2000 9 * (C) Copyright Randy Dunlap 2000
10 * (C) Copyright David Brownell 2000-2001 (kernel hotplug, usb_device_id, 10 * (C) Copyright David Brownell 2000-2001 (kernel hotplug, usb_device_id,
11 more docs, etc) 11 * more docs, etc)
12 * (C) Copyright Yggdrasil Computing, Inc. 2000 12 * (C) Copyright Yggdrasil Computing, Inc. 2000
13 * (usb_device_id matching changes by Adam J. Richter) 13 * (usb_device_id matching changes by Adam J. Richter)
14 * (C) Copyright Greg Kroah-Hartman 2002-2003 14 * (C) Copyright Greg Kroah-Hartman 2002-2003
@@ -27,29 +27,21 @@
27static const struct file_operations *usb_minors[MAX_USB_MINORS]; 27static const struct file_operations *usb_minors[MAX_USB_MINORS];
28static DECLARE_RWSEM(minor_rwsem); 28static DECLARE_RWSEM(minor_rwsem);
29 29
30static int usb_open(struct inode * inode, struct file * file) 30static int usb_open(struct inode *inode, struct file *file)
31{ 31{
32 int minor = iminor(inode);
33 const struct file_operations *c;
34 int err = -ENODEV; 32 int err = -ENODEV;
35 const struct file_operations *old_fops, *new_fops = NULL; 33 const struct file_operations *new_fops;
36 34
37 down_read(&minor_rwsem); 35 down_read(&minor_rwsem);
38 c = usb_minors[minor]; 36 new_fops = fops_get(usb_minors[iminor(inode)]);
39 37
40 if (!c || !(new_fops = fops_get(c))) 38 if (!new_fops)
41 goto done; 39 goto done;
42 40
43 old_fops = file->f_op; 41 replace_fops(file, new_fops);
44 file->f_op = new_fops;
45 /* Curiouser and curiouser... NULL ->open() as "no device" ? */ 42 /* Curiouser and curiouser... NULL ->open() as "no device" ? */
46 if (file->f_op->open) 43 if (file->f_op->open)
47 err = file->f_op->open(inode,file); 44 err = file->f_op->open(inode, file);
48 if (err) {
49 fops_put(file->f_op);
50 file->f_op = fops_get(old_fops);
51 }
52 fops_put(old_fops);
53 done: 45 done:
54 up_read(&minor_rwsem); 46 up_read(&minor_rwsem);
55 return err; 47 return err;
@@ -166,7 +158,7 @@ int usb_register_dev(struct usb_interface *intf,
166 char *temp; 158 char *temp;
167 159
168#ifdef CONFIG_USB_DYNAMIC_MINORS 160#ifdef CONFIG_USB_DYNAMIC_MINORS
169 /* 161 /*
170 * We don't care what the device tries to start at, we want to start 162 * We don't care what the device tries to start at, we want to start
171 * at zero to pack the devices into the smallest available space with 163 * at zero to pack the devices into the smallest available space with
172 * no holes in the minor range. 164 * no holes in the minor range.
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index b9d3c43e3859..dfe9d0f22978 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -215,6 +215,9 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
215 goto disable_pci; 215 goto disable_pci;
216 } 216 }
217 217
218 hcd->amd_resume_bug = (usb_hcd_amd_remote_wakeup_quirk(dev) &&
219 driver->flags & (HCD_USB11 | HCD_USB3)) ? 1 : 0;
220
218 if (driver->flags & HCD_MEMORY) { 221 if (driver->flags & HCD_MEMORY) {
219 /* EHCI, OHCI */ 222 /* EHCI, OHCI */
220 hcd->rsrc_start = pci_resource_start(dev, 0); 223 hcd->rsrc_start = pci_resource_start(dev, 0);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d6a8d23f047b..6bffb8c87bc9 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -6,7 +6,7 @@
6 * (C) Copyright Deti Fliegl 1999 6 * (C) Copyright Deti Fliegl 1999
7 * (C) Copyright Randy Dunlap 2000 7 * (C) Copyright Randy Dunlap 2000
8 * (C) Copyright David Brownell 2000-2002 8 * (C) Copyright David Brownell 2000-2002
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the 11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your 12 * Free Software Foundation; either version 2 of the License, or (at your
@@ -40,6 +40,7 @@
40#include <linux/platform_device.h> 40#include <linux/platform_device.h>
41#include <linux/workqueue.h> 41#include <linux/workqueue.h>
42#include <linux/pm_runtime.h> 42#include <linux/pm_runtime.h>
43#include <linux/types.h>
43 44
44#include <linux/usb.h> 45#include <linux/usb.h>
45#include <linux/usb/hcd.h> 46#include <linux/usb/hcd.h>
@@ -92,10 +93,7 @@ EXPORT_SYMBOL_GPL (usb_bus_list);
92 93
93/* used when allocating bus numbers */ 94/* used when allocating bus numbers */
94#define USB_MAXBUS 64 95#define USB_MAXBUS 64
95struct usb_busmap { 96static DECLARE_BITMAP(busmap, USB_MAXBUS);
96 unsigned long busmap [USB_MAXBUS / (8*sizeof (unsigned long))];
97};
98static struct usb_busmap busmap;
99 97
100/* used when updating list of hcds */ 98/* used when updating list of hcds */
101DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */ 99DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */
@@ -171,7 +169,7 @@ static const u8 usb25_rh_dev_descriptor[18] = {
171}; 169};
172 170
173/* usb 2.0 root hub device descriptor */ 171/* usb 2.0 root hub device descriptor */
174static const u8 usb2_rh_dev_descriptor [18] = { 172static const u8 usb2_rh_dev_descriptor[18] = {
175 0x12, /* __u8 bLength; */ 173 0x12, /* __u8 bLength; */
176 0x01, /* __u8 bDescriptorType; Device */ 174 0x01, /* __u8 bDescriptorType; Device */
177 0x00, 0x02, /* __le16 bcdUSB; v2.0 */ 175 0x00, 0x02, /* __le16 bcdUSB; v2.0 */
@@ -194,7 +192,7 @@ static const u8 usb2_rh_dev_descriptor [18] = {
194/* no usb 2.0 root hub "device qualifier" descriptor: one speed only */ 192/* no usb 2.0 root hub "device qualifier" descriptor: one speed only */
195 193
196/* usb 1.1 root hub device descriptor */ 194/* usb 1.1 root hub device descriptor */
197static const u8 usb11_rh_dev_descriptor [18] = { 195static const u8 usb11_rh_dev_descriptor[18] = {
198 0x12, /* __u8 bLength; */ 196 0x12, /* __u8 bLength; */
199 0x01, /* __u8 bDescriptorType; Device */ 197 0x01, /* __u8 bDescriptorType; Device */
200 0x10, 0x01, /* __le16 bcdUSB; v1.1 */ 198 0x10, 0x01, /* __le16 bcdUSB; v1.1 */
@@ -219,7 +217,7 @@ static const u8 usb11_rh_dev_descriptor [18] = {
219 217
220/* Configuration descriptors for our root hubs */ 218/* Configuration descriptors for our root hubs */
221 219
222static const u8 fs_rh_config_descriptor [] = { 220static const u8 fs_rh_config_descriptor[] = {
223 221
224 /* one configuration */ 222 /* one configuration */
225 0x09, /* __u8 bLength; */ 223 0x09, /* __u8 bLength; */
@@ -228,13 +226,13 @@ static const u8 fs_rh_config_descriptor [] = {
228 0x01, /* __u8 bNumInterfaces; (1) */ 226 0x01, /* __u8 bNumInterfaces; (1) */
229 0x01, /* __u8 bConfigurationValue; */ 227 0x01, /* __u8 bConfigurationValue; */
230 0x00, /* __u8 iConfiguration; */ 228 0x00, /* __u8 iConfiguration; */
231 0xc0, /* __u8 bmAttributes; 229 0xc0, /* __u8 bmAttributes;
232 Bit 7: must be set, 230 Bit 7: must be set,
233 6: Self-powered, 231 6: Self-powered,
234 5: Remote wakeup, 232 5: Remote wakeup,
235 4..0: resvd */ 233 4..0: resvd */
236 0x00, /* __u8 MaxPower; */ 234 0x00, /* __u8 MaxPower; */
237 235
238 /* USB 1.1: 236 /* USB 1.1:
239 * USB 2.0, single TT organization (mandatory): 237 * USB 2.0, single TT organization (mandatory):
240 * one interface, protocol 0 238 * one interface, protocol 0
@@ -256,17 +254,17 @@ static const u8 fs_rh_config_descriptor [] = {
256 0x00, /* __u8 if_bInterfaceSubClass; */ 254 0x00, /* __u8 if_bInterfaceSubClass; */
257 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ 255 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
258 0x00, /* __u8 if_iInterface; */ 256 0x00, /* __u8 if_iInterface; */
259 257
260 /* one endpoint (status change endpoint) */ 258 /* one endpoint (status change endpoint) */
261 0x07, /* __u8 ep_bLength; */ 259 0x07, /* __u8 ep_bLength; */
262 0x05, /* __u8 ep_bDescriptorType; Endpoint */ 260 0x05, /* __u8 ep_bDescriptorType; Endpoint */
263 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ 261 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
264 0x03, /* __u8 ep_bmAttributes; Interrupt */ 262 0x03, /* __u8 ep_bmAttributes; Interrupt */
265 0x02, 0x00, /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */ 263 0x02, 0x00, /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
266 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */ 264 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */
267}; 265};
268 266
269static const u8 hs_rh_config_descriptor [] = { 267static const u8 hs_rh_config_descriptor[] = {
270 268
271 /* one configuration */ 269 /* one configuration */
272 0x09, /* __u8 bLength; */ 270 0x09, /* __u8 bLength; */
@@ -275,13 +273,13 @@ static const u8 hs_rh_config_descriptor [] = {
275 0x01, /* __u8 bNumInterfaces; (1) */ 273 0x01, /* __u8 bNumInterfaces; (1) */
276 0x01, /* __u8 bConfigurationValue; */ 274 0x01, /* __u8 bConfigurationValue; */
277 0x00, /* __u8 iConfiguration; */ 275 0x00, /* __u8 iConfiguration; */
278 0xc0, /* __u8 bmAttributes; 276 0xc0, /* __u8 bmAttributes;
279 Bit 7: must be set, 277 Bit 7: must be set,
280 6: Self-powered, 278 6: Self-powered,
281 5: Remote wakeup, 279 5: Remote wakeup,
282 4..0: resvd */ 280 4..0: resvd */
283 0x00, /* __u8 MaxPower; */ 281 0x00, /* __u8 MaxPower; */
284 282
285 /* USB 1.1: 283 /* USB 1.1:
286 * USB 2.0, single TT organization (mandatory): 284 * USB 2.0, single TT organization (mandatory):
287 * one interface, protocol 0 285 * one interface, protocol 0
@@ -303,12 +301,12 @@ static const u8 hs_rh_config_descriptor [] = {
303 0x00, /* __u8 if_bInterfaceSubClass; */ 301 0x00, /* __u8 if_bInterfaceSubClass; */
304 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ 302 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
305 0x00, /* __u8 if_iInterface; */ 303 0x00, /* __u8 if_iInterface; */
306 304
307 /* one endpoint (status change endpoint) */ 305 /* one endpoint (status change endpoint) */
308 0x07, /* __u8 ep_bLength; */ 306 0x07, /* __u8 ep_bLength; */
309 0x05, /* __u8 ep_bDescriptorType; Endpoint */ 307 0x05, /* __u8 ep_bDescriptorType; Endpoint */
310 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ 308 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
311 0x03, /* __u8 ep_bmAttributes; Interrupt */ 309 0x03, /* __u8 ep_bmAttributes; Interrupt */
312 /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) 310 /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8)
313 * see hub.c:hub_configure() for details. */ 311 * see hub.c:hub_configure() for details. */
314 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, 312 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
@@ -428,7 +426,7 @@ rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len)
428 char const *s; 426 char const *s;
429 static char const langids[4] = {4, USB_DT_STRING, 0x09, 0x04}; 427 static char const langids[4] = {4, USB_DT_STRING, 0x09, 0x04};
430 428
431 // language ids 429 /* language ids */
432 switch (id) { 430 switch (id) {
433 case 0: 431 case 0:
434 /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */ 432 /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */
@@ -464,7 +462,7 @@ rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len)
464static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) 462static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
465{ 463{
466 struct usb_ctrlrequest *cmd; 464 struct usb_ctrlrequest *cmd;
467 u16 typeReq, wValue, wIndex, wLength; 465 u16 typeReq, wValue, wIndex, wLength;
468 u8 *ubuf = urb->transfer_buffer; 466 u8 *ubuf = urb->transfer_buffer;
469 unsigned len = 0; 467 unsigned len = 0;
470 int status; 468 int status;
@@ -526,10 +524,10 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
526 */ 524 */
527 525
528 case DeviceRequest | USB_REQ_GET_STATUS: 526 case DeviceRequest | USB_REQ_GET_STATUS:
529 tbuf [0] = (device_may_wakeup(&hcd->self.root_hub->dev) 527 tbuf[0] = (device_may_wakeup(&hcd->self.root_hub->dev)
530 << USB_DEVICE_REMOTE_WAKEUP) 528 << USB_DEVICE_REMOTE_WAKEUP)
531 | (1 << USB_DEVICE_SELF_POWERED); 529 | (1 << USB_DEVICE_SELF_POWERED);
532 tbuf [1] = 0; 530 tbuf[1] = 0;
533 len = 2; 531 len = 2;
534 break; 532 break;
535 case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: 533 case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
@@ -546,7 +544,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
546 goto error; 544 goto error;
547 break; 545 break;
548 case DeviceRequest | USB_REQ_GET_CONFIGURATION: 546 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
549 tbuf [0] = 1; 547 tbuf[0] = 1;
550 len = 1; 548 len = 1;
551 /* FALLTHROUGH */ 549 /* FALLTHROUGH */
552 case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: 550 case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
@@ -609,13 +607,13 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
609 } 607 }
610 break; 608 break;
611 case DeviceRequest | USB_REQ_GET_INTERFACE: 609 case DeviceRequest | USB_REQ_GET_INTERFACE:
612 tbuf [0] = 0; 610 tbuf[0] = 0;
613 len = 1; 611 len = 1;
614 /* FALLTHROUGH */ 612 /* FALLTHROUGH */
615 case DeviceOutRequest | USB_REQ_SET_INTERFACE: 613 case DeviceOutRequest | USB_REQ_SET_INTERFACE:
616 break; 614 break;
617 case DeviceOutRequest | USB_REQ_SET_ADDRESS: 615 case DeviceOutRequest | USB_REQ_SET_ADDRESS:
618 // wValue == urb->dev->devaddr 616 /* wValue == urb->dev->devaddr */
619 dev_dbg (hcd->self.controller, "root hub device address %d\n", 617 dev_dbg (hcd->self.controller, "root hub device address %d\n",
620 wValue); 618 wValue);
621 break; 619 break;
@@ -625,9 +623,9 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
625 /* ENDPOINT REQUESTS */ 623 /* ENDPOINT REQUESTS */
626 624
627 case EndpointRequest | USB_REQ_GET_STATUS: 625 case EndpointRequest | USB_REQ_GET_STATUS:
628 // ENDPOINT_HALT flag 626 /* ENDPOINT_HALT flag */
629 tbuf [0] = 0; 627 tbuf[0] = 0;
630 tbuf [1] = 0; 628 tbuf[1] = 0;
631 len = 2; 629 len = 2;
632 /* FALLTHROUGH */ 630 /* FALLTHROUGH */
633 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE: 631 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
@@ -683,7 +681,7 @@ error:
683 if (urb->transfer_buffer_length < len) 681 if (urb->transfer_buffer_length < len)
684 len = urb->transfer_buffer_length; 682 len = urb->transfer_buffer_length;
685 urb->actual_length = len; 683 urb->actual_length = len;
686 // always USB_DIR_IN, toward host 684 /* always USB_DIR_IN, toward host */
687 memcpy (ubuf, bufp, len); 685 memcpy (ubuf, bufp, len);
688 686
689 /* report whether RH hardware supports remote wakeup */ 687 /* report whether RH hardware supports remote wakeup */
@@ -877,11 +875,11 @@ static ssize_t authorized_default_store(struct device *dev,
877 usb_hcd = bus_to_hcd(usb_bus); 875 usb_hcd = bus_to_hcd(usb_bus);
878 result = sscanf(buf, "%u\n", &val); 876 result = sscanf(buf, "%u\n", &val);
879 if (result == 1) { 877 if (result == 1) {
880 usb_hcd->authorized_default = val? 1 : 0; 878 usb_hcd->authorized_default = val ? 1 : 0;
881 result = size; 879 result = size;
882 } 880 } else {
883 else
884 result = -EINVAL; 881 result = -EINVAL;
882 }
885 return result; 883 return result;
886} 884}
887static DEVICE_ATTR_RW(authorized_default); 885static DEVICE_ATTR_RW(authorized_default);
@@ -941,12 +939,12 @@ static int usb_register_bus(struct usb_bus *bus)
941 int busnum; 939 int busnum;
942 940
943 mutex_lock(&usb_bus_list_lock); 941 mutex_lock(&usb_bus_list_lock);
944 busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); 942 busnum = find_next_zero_bit(busmap, USB_MAXBUS, 1);
945 if (busnum >= USB_MAXBUS) { 943 if (busnum >= USB_MAXBUS) {
946 printk (KERN_ERR "%s: too many buses\n", usbcore_name); 944 printk (KERN_ERR "%s: too many buses\n", usbcore_name);
947 goto error_find_busnum; 945 goto error_find_busnum;
948 } 946 }
949 set_bit (busnum, busmap.busmap); 947 set_bit(busnum, busmap);
950 bus->busnum = busnum; 948 bus->busnum = busnum;
951 949
952 /* Add it to the local list of buses */ 950 /* Add it to the local list of buses */
@@ -987,7 +985,7 @@ static void usb_deregister_bus (struct usb_bus *bus)
987 985
988 usb_notify_remove_bus(bus); 986 usb_notify_remove_bus(bus);
989 987
990 clear_bit (bus->busnum, busmap.busmap); 988 clear_bit(bus->busnum, busmap);
991} 989}
992 990
993/** 991/**
@@ -1033,6 +1031,7 @@ static int register_root_hub(struct usb_hcd *hcd)
1033 dev_name(&usb_dev->dev), retval); 1031 dev_name(&usb_dev->dev), retval);
1034 return retval; 1032 return retval;
1035 } 1033 }
1034 usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev);
1036 } 1035 }
1037 1036
1038 retval = usb_new_device (usb_dev); 1037 retval = usb_new_device (usb_dev);
@@ -1120,21 +1119,21 @@ long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount)
1120 case USB_SPEED_LOW: /* INTR only */ 1119 case USB_SPEED_LOW: /* INTR only */
1121 if (is_input) { 1120 if (is_input) {
1122 tmp = (67667L * (31L + 10L * BitTime (bytecount))) / 1000L; 1121 tmp = (67667L * (31L + 10L * BitTime (bytecount))) / 1000L;
1123 return (64060L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp); 1122 return 64060L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp;
1124 } else { 1123 } else {
1125 tmp = (66700L * (31L + 10L * BitTime (bytecount))) / 1000L; 1124 tmp = (66700L * (31L + 10L * BitTime (bytecount))) / 1000L;
1126 return (64107L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp); 1125 return 64107L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp;
1127 } 1126 }
1128 case USB_SPEED_FULL: /* ISOC or INTR */ 1127 case USB_SPEED_FULL: /* ISOC or INTR */
1129 if (isoc) { 1128 if (isoc) {
1130 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L; 1129 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
1131 return (((is_input) ? 7268L : 6265L) + BW_HOST_DELAY + tmp); 1130 return ((is_input) ? 7268L : 6265L) + BW_HOST_DELAY + tmp;
1132 } else { 1131 } else {
1133 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L; 1132 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
1134 return (9107L + BW_HOST_DELAY + tmp); 1133 return 9107L + BW_HOST_DELAY + tmp;
1135 } 1134 }
1136 case USB_SPEED_HIGH: /* ISOC or INTR */ 1135 case USB_SPEED_HIGH: /* ISOC or INTR */
1137 // FIXME adjust for input vs output 1136 /* FIXME adjust for input vs output */
1138 if (isoc) 1137 if (isoc)
1139 tmp = HS_NSECS_ISO (bytecount); 1138 tmp = HS_NSECS_ISO (bytecount);
1140 else 1139 else
@@ -1651,6 +1650,7 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1651static void __usb_hcd_giveback_urb(struct urb *urb) 1650static void __usb_hcd_giveback_urb(struct urb *urb)
1652{ 1651{
1653 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); 1652 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus);
1653 struct usb_anchor *anchor = urb->anchor;
1654 int status = urb->unlinked; 1654 int status = urb->unlinked;
1655 unsigned long flags; 1655 unsigned long flags;
1656 1656
@@ -1662,6 +1662,7 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
1662 1662
1663 unmap_urb_for_dma(hcd, urb); 1663 unmap_urb_for_dma(hcd, urb);
1664 usbmon_urb_complete(&hcd->self, urb, status); 1664 usbmon_urb_complete(&hcd->self, urb, status);
1665 usb_anchor_suspend_wakeups(anchor);
1665 usb_unanchor_urb(urb); 1666 usb_unanchor_urb(urb);
1666 1667
1667 /* pass ownership to the completion handler */ 1668 /* pass ownership to the completion handler */
@@ -1681,6 +1682,7 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
1681 urb->complete(urb); 1682 urb->complete(urb);
1682 local_irq_restore(flags); 1683 local_irq_restore(flags);
1683 1684
1685 usb_anchor_resume_wakeups(anchor);
1684 atomic_dec(&urb->use_count); 1686 atomic_dec(&urb->use_count);
1685 if (unlikely(atomic_read(&urb->reject))) 1687 if (unlikely(atomic_read(&urb->reject)))
1686 wake_up(&usb_kill_urb_queue); 1688 wake_up(&usb_kill_urb_queue);
@@ -1703,7 +1705,9 @@ static void usb_giveback_urb_bh(unsigned long param)
1703 1705
1704 urb = list_entry(local_list.next, struct urb, urb_list); 1706 urb = list_entry(local_list.next, struct urb, urb_list);
1705 list_del_init(&urb->urb_list); 1707 list_del_init(&urb->urb_list);
1708 bh->completing_ep = urb->ep;
1706 __usb_hcd_giveback_urb(urb); 1709 __usb_hcd_giveback_urb(urb);
1710 bh->completing_ep = NULL;
1707 } 1711 }
1708 1712
1709 /* check if there are new URBs to giveback */ 1713 /* check if there are new URBs to giveback */
@@ -1812,7 +1816,7 @@ rescan:
1812 case USB_ENDPOINT_XFER_INT: 1816 case USB_ENDPOINT_XFER_INT:
1813 s = "-intr"; break; 1817 s = "-intr"; break;
1814 default: 1818 default:
1815 s = "-iso"; break; 1819 s = "-iso"; break;
1816 }; 1820 };
1817 s; 1821 s;
1818 })); 1822 }));
@@ -2073,8 +2077,11 @@ EXPORT_SYMBOL_GPL(usb_alloc_streams);
2073 * 2077 *
2074 * Reverts a group of bulk endpoints back to not using stream IDs. 2078 * Reverts a group of bulk endpoints back to not using stream IDs.
2075 * Can fail if we are given bad arguments, or HCD is broken. 2079 * Can fail if we are given bad arguments, or HCD is broken.
2080 *
2081 * Return: On success, the number of allocated streams. On failure, a negative
2082 * error code.
2076 */ 2083 */
2077void usb_free_streams(struct usb_interface *interface, 2084int usb_free_streams(struct usb_interface *interface,
2078 struct usb_host_endpoint **eps, unsigned int num_eps, 2085 struct usb_host_endpoint **eps, unsigned int num_eps,
2079 gfp_t mem_flags) 2086 gfp_t mem_flags)
2080{ 2087{
@@ -2085,14 +2092,14 @@ void usb_free_streams(struct usb_interface *interface,
2085 dev = interface_to_usbdev(interface); 2092 dev = interface_to_usbdev(interface);
2086 hcd = bus_to_hcd(dev->bus); 2093 hcd = bus_to_hcd(dev->bus);
2087 if (dev->speed != USB_SPEED_SUPER) 2094 if (dev->speed != USB_SPEED_SUPER)
2088 return; 2095 return -EINVAL;
2089 2096
2090 /* Streams only apply to bulk endpoints. */ 2097 /* Streams only apply to bulk endpoints. */
2091 for (i = 0; i < num_eps; i++) 2098 for (i = 0; i < num_eps; i++)
2092 if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->desc)) 2099 if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->desc))
2093 return; 2100 return -EINVAL;
2094 2101
2095 hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); 2102 return hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags);
2096} 2103}
2097EXPORT_SYMBOL_GPL(usb_free_streams); 2104EXPORT_SYMBOL_GPL(usb_free_streams);
2098 2105
@@ -2245,7 +2252,7 @@ static void hcd_resume_work(struct work_struct *work)
2245} 2252}
2246 2253
2247/** 2254/**
2248 * usb_hcd_resume_root_hub - called by HCD to resume its root hub 2255 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
2249 * @hcd: host controller for this root hub 2256 * @hcd: host controller for this root hub
2250 * 2257 *
2251 * The USB host controller calls this function when its root hub is 2258 * The USB host controller calls this function when its root hub is
@@ -2324,15 +2331,8 @@ EXPORT_SYMBOL_GPL(usb_bus_start_enum);
2324irqreturn_t usb_hcd_irq (int irq, void *__hcd) 2331irqreturn_t usb_hcd_irq (int irq, void *__hcd)
2325{ 2332{
2326 struct usb_hcd *hcd = __hcd; 2333 struct usb_hcd *hcd = __hcd;
2327 unsigned long flags;
2328 irqreturn_t rc; 2334 irqreturn_t rc;
2329 2335
2330 /* IRQF_DISABLED doesn't work correctly with shared IRQs
2331 * when the first handler doesn't use it. So let's just
2332 * assume it's never used.
2333 */
2334 local_irq_save(flags);
2335
2336 if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) 2336 if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd)))
2337 rc = IRQ_NONE; 2337 rc = IRQ_NONE;
2338 else if (hcd->driver->irq(hcd) == IRQ_NONE) 2338 else if (hcd->driver->irq(hcd) == IRQ_NONE)
@@ -2340,7 +2340,6 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd)
2340 else 2340 else
2341 rc = IRQ_HANDLED; 2341 rc = IRQ_HANDLED;
2342 2342
2343 local_irq_restore(flags);
2344 return rc; 2343 return rc;
2345} 2344}
2346EXPORT_SYMBOL_GPL(usb_hcd_irq); 2345EXPORT_SYMBOL_GPL(usb_hcd_irq);
@@ -2547,13 +2546,6 @@ static int usb_hcd_request_irqs(struct usb_hcd *hcd,
2547 2546
2548 if (hcd->driver->irq) { 2547 if (hcd->driver->irq) {
2549 2548
2550 /* IRQF_DISABLED doesn't work as advertised when used together
2551 * with IRQF_SHARED. As usb_hcd_irq() will always disable
2552 * interrupts we can remove it here.
2553 */
2554 if (irqflags & IRQF_SHARED)
2555 irqflags &= ~IRQF_DISABLED;
2556
2557 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", 2549 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
2558 hcd->driver->description, hcd->self.busnum); 2550 hcd->driver->description, hcd->self.busnum);
2559 retval = request_irq(irqnum, &usb_hcd_irq, irqflags, 2551 retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
@@ -2600,7 +2592,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2600 2592
2601 /* Keep old behaviour if authorized_default is not in [0, 1]. */ 2593 /* Keep old behaviour if authorized_default is not in [0, 1]. */
2602 if (authorized_default < 0 || authorized_default > 1) 2594 if (authorized_default < 0 || authorized_default > 1)
2603 hcd->authorized_default = hcd->wireless? 0 : 1; 2595 hcd->authorized_default = hcd->wireless ? 0 : 1;
2604 else 2596 else
2605 hcd->authorized_default = authorized_default; 2597 hcd->authorized_default = authorized_default;
2606 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 2598 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
@@ -2743,7 +2735,7 @@ err_allocate_root_hub:
2743err_register_bus: 2735err_register_bus:
2744 hcd_buffer_destroy(hcd); 2736 hcd_buffer_destroy(hcd);
2745 return retval; 2737 return retval;
2746} 2738}
2747EXPORT_SYMBOL_GPL(usb_add_hcd); 2739EXPORT_SYMBOL_GPL(usb_add_hcd);
2748 2740
2749/** 2741/**
@@ -2818,7 +2810,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2818EXPORT_SYMBOL_GPL(usb_remove_hcd); 2810EXPORT_SYMBOL_GPL(usb_remove_hcd);
2819 2811
2820void 2812void
2821usb_hcd_platform_shutdown(struct platform_device* dev) 2813usb_hcd_platform_shutdown(struct platform_device *dev)
2822{ 2814{
2823 struct usb_hcd *hcd = platform_get_drvdata(dev); 2815 struct usb_hcd *hcd = platform_get_drvdata(dev);
2824 2816
@@ -2840,7 +2832,7 @@ struct usb_mon_operations *mon_ops;
2840 * Notice that the code is minimally error-proof. Because usbmon needs 2832 * Notice that the code is minimally error-proof. Because usbmon needs
2841 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first. 2833 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
2842 */ 2834 */
2843 2835
2844int usb_mon_register (struct usb_mon_operations *ops) 2836int usb_mon_register (struct usb_mon_operations *ops)
2845{ 2837{
2846 2838
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index dde4c83516a1..06cec635e703 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -120,7 +120,7 @@ static inline char *portspeed(struct usb_hub *hub, int portstatus)
120 if (hub_is_superspeed(hub->hdev)) 120 if (hub_is_superspeed(hub->hdev))
121 return "5.0 Gb/s"; 121 return "5.0 Gb/s";
122 if (portstatus & USB_PORT_STAT_HIGH_SPEED) 122 if (portstatus & USB_PORT_STAT_HIGH_SPEED)
123 return "480 Mb/s"; 123 return "480 Mb/s";
124 else if (portstatus & USB_PORT_STAT_LOW_SPEED) 124 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
125 return "1.5 Mb/s"; 125 return "1.5 Mb/s";
126 else 126 else
@@ -135,7 +135,7 @@ struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev)
135 return usb_get_intfdata(hdev->actconfig->interface[0]); 135 return usb_get_intfdata(hdev->actconfig->interface[0]);
136} 136}
137 137
138static int usb_device_supports_lpm(struct usb_device *udev) 138int usb_device_supports_lpm(struct usb_device *udev)
139{ 139{
140 /* USB 2.1 (and greater) devices indicate LPM support through 140 /* USB 2.1 (and greater) devices indicate LPM support through
141 * their USB 2.0 Extended Capabilities BOS descriptor. 141 * their USB 2.0 Extended Capabilities BOS descriptor.
@@ -156,6 +156,11 @@ static int usb_device_supports_lpm(struct usb_device *udev)
156 "Power management will be impacted.\n"); 156 "Power management will be impacted.\n");
157 return 0; 157 return 0;
158 } 158 }
159
160 /* udev is root hub */
161 if (!udev->parent)
162 return 1;
163
159 if (udev->parent->lpm_capable) 164 if (udev->parent->lpm_capable)
160 return 1; 165 return 1;
161 166
@@ -310,9 +315,9 @@ static void usb_set_lpm_parameters(struct usb_device *udev)
310 return; 315 return;
311 316
312 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; 317 udev_u1_del = udev->bos->ss_cap->bU1devExitLat;
313 udev_u2_del = udev->bos->ss_cap->bU2DevExitLat; 318 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat);
314 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; 319 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat;
315 hub_u2_del = udev->parent->bos->ss_cap->bU2DevExitLat; 320 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat);
316 321
317 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, 322 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del,
318 hub, &udev->parent->u1_params, hub_u1_del); 323 hub, &udev->parent->u1_params, hub_u1_del);
@@ -433,7 +438,7 @@ static void set_port_led(
433 case HUB_LED_OFF: s = "off"; break; 438 case HUB_LED_OFF: s = "off"; break;
434 case HUB_LED_AUTO: s = "auto"; break; 439 case HUB_LED_AUTO: s = "auto"; break;
435 default: s = "??"; break; 440 default: s = "??"; break;
436 }; s; }), 441 } s; }),
437 status); 442 status);
438} 443}
439 444
@@ -857,7 +862,7 @@ static int hub_hub_status(struct usb_hub *hub,
857 "%s failed (err = %d)\n", __func__, ret); 862 "%s failed (err = %d)\n", __func__, ret);
858 } else { 863 } else {
859 *status = le16_to_cpu(hub->status->hub.wHubStatus); 864 *status = le16_to_cpu(hub->status->hub.wHubStatus);
860 *change = le16_to_cpu(hub->status->hub.wHubChange); 865 *change = le16_to_cpu(hub->status->hub.wHubChange);
861 ret = 0; 866 ret = 0;
862 } 867 }
863 mutex_unlock(&hub->status_mutex); 868 mutex_unlock(&hub->status_mutex);
@@ -956,7 +961,7 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
956 */ 961 */
957 962
958 set_bit(port1, hub->change_bits); 963 set_bit(port1, hub->change_bits);
959 kick_khubd(hub); 964 kick_khubd(hub);
960} 965}
961 966
962/** 967/**
@@ -1107,16 +1112,13 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1107 /* 1112 /*
1108 * USB3 protocol ports will automatically transition 1113 * USB3 protocol ports will automatically transition
1109 * to Enabled state when detect an USB3.0 device attach. 1114 * to Enabled state when detect an USB3.0 device attach.
1110 * Do not disable USB3 protocol ports. 1115 * Do not disable USB3 protocol ports, just pretend
1116 * power was lost
1111 */ 1117 */
1112 if (!hub_is_superspeed(hdev)) { 1118 portstatus &= ~USB_PORT_STAT_ENABLE;
1119 if (!hub_is_superspeed(hdev))
1113 usb_clear_port_feature(hdev, port1, 1120 usb_clear_port_feature(hdev, port1,
1114 USB_PORT_FEAT_ENABLE); 1121 USB_PORT_FEAT_ENABLE);
1115 portstatus &= ~USB_PORT_STAT_ENABLE;
1116 } else {
1117 /* Pretend that power was lost for USB3 devs */
1118 portstatus &= ~USB_PORT_STAT_ENABLE;
1119 }
1120 } 1122 }
1121 1123
1122 /* Clear status-change flags; we'll debounce later */ 1124 /* Clear status-change flags; we'll debounce later */
@@ -1130,6 +1132,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1130 usb_clear_port_feature(hub->hdev, port1, 1132 usb_clear_port_feature(hub->hdev, port1,
1131 USB_PORT_FEAT_C_ENABLE); 1133 USB_PORT_FEAT_C_ENABLE);
1132 } 1134 }
1135 if (portchange & USB_PORT_STAT_C_RESET) {
1136 need_debounce_delay = true;
1137 usb_clear_port_feature(hub->hdev, port1,
1138 USB_PORT_FEAT_C_RESET);
1139 }
1133 if ((portchange & USB_PORT_STAT_C_BH_RESET) && 1140 if ((portchange & USB_PORT_STAT_C_BH_RESET) &&
1134 hub_is_superspeed(hub->hdev)) { 1141 hub_is_superspeed(hub->hdev)) {
1135 need_debounce_delay = true; 1142 need_debounce_delay = true;
@@ -1361,7 +1368,7 @@ static int hub_configure(struct usb_hub *hub,
1361 if ((wHubCharacteristics & HUB_CHAR_COMPOUND) && 1368 if ((wHubCharacteristics & HUB_CHAR_COMPOUND) &&
1362 !(hub_is_superspeed(hdev))) { 1369 !(hub_is_superspeed(hdev))) {
1363 int i; 1370 int i;
1364 char portstr [USB_MAXCHILDREN + 1]; 1371 char portstr[USB_MAXCHILDREN + 1];
1365 1372
1366 for (i = 0; i < hdev->maxchild; i++) 1373 for (i = 0; i < hdev->maxchild; i++)
1367 portstr[i] = hub->descriptor->u.hs.DeviceRemovable 1374 portstr[i] = hub->descriptor->u.hs.DeviceRemovable
@@ -1429,32 +1436,32 @@ static int hub_configure(struct usb_hub *hub,
1429 1436
1430 /* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */ 1437 /* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */
1431 switch (wHubCharacteristics & HUB_CHAR_TTTT) { 1438 switch (wHubCharacteristics & HUB_CHAR_TTTT) {
1432 case HUB_TTTT_8_BITS: 1439 case HUB_TTTT_8_BITS:
1433 if (hdev->descriptor.bDeviceProtocol != 0) { 1440 if (hdev->descriptor.bDeviceProtocol != 0) {
1434 hub->tt.think_time = 666; 1441 hub->tt.think_time = 666;
1435 dev_dbg(hub_dev, "TT requires at most %d "
1436 "FS bit times (%d ns)\n",
1437 8, hub->tt.think_time);
1438 }
1439 break;
1440 case HUB_TTTT_16_BITS:
1441 hub->tt.think_time = 666 * 2;
1442 dev_dbg(hub_dev, "TT requires at most %d " 1442 dev_dbg(hub_dev, "TT requires at most %d "
1443 "FS bit times (%d ns)\n", 1443 "FS bit times (%d ns)\n",
1444 16, hub->tt.think_time); 1444 8, hub->tt.think_time);
1445 break; 1445 }
1446 case HUB_TTTT_24_BITS: 1446 break;
1447 hub->tt.think_time = 666 * 3; 1447 case HUB_TTTT_16_BITS:
1448 dev_dbg(hub_dev, "TT requires at most %d " 1448 hub->tt.think_time = 666 * 2;
1449 "FS bit times (%d ns)\n", 1449 dev_dbg(hub_dev, "TT requires at most %d "
1450 24, hub->tt.think_time); 1450 "FS bit times (%d ns)\n",
1451 break; 1451 16, hub->tt.think_time);
1452 case HUB_TTTT_32_BITS: 1452 break;
1453 hub->tt.think_time = 666 * 4; 1453 case HUB_TTTT_24_BITS:
1454 dev_dbg(hub_dev, "TT requires at most %d " 1454 hub->tt.think_time = 666 * 3;
1455 "FS bit times (%d ns)\n", 1455 dev_dbg(hub_dev, "TT requires at most %d "
1456 32, hub->tt.think_time); 1456 "FS bit times (%d ns)\n",
1457 break; 1457 24, hub->tt.think_time);
1458 break;
1459 case HUB_TTTT_32_BITS:
1460 hub->tt.think_time = 666 * 4;
1461 dev_dbg(hub_dev, "TT requires at most %d "
1462 "FS bit times (%d ns)\n",
1463 32, hub->tt.think_time);
1464 break;
1458 } 1465 }
1459 1466
1460 /* probe() zeroes hub->indicator[] */ 1467 /* probe() zeroes hub->indicator[] */
@@ -1560,7 +1567,7 @@ static int hub_configure(struct usb_hub *hub,
1560 1567
1561 /* maybe cycle the hub leds */ 1568 /* maybe cycle the hub leds */
1562 if (hub->has_indicators && blinkenlights) 1569 if (hub->has_indicators && blinkenlights)
1563 hub->indicator [0] = INDICATOR_CYCLE; 1570 hub->indicator[0] = INDICATOR_CYCLE;
1564 1571
1565 for (i = 0; i < hdev->maxchild; i++) { 1572 for (i = 0; i < hdev->maxchild; i++) {
1566 ret = usb_hub_create_port_device(hub, i + 1); 1573 ret = usb_hub_create_port_device(hub, i + 1);
@@ -1978,7 +1985,7 @@ static void choose_devnum(struct usb_device *udev)
1978 if (devnum >= 128) 1985 if (devnum >= 128)
1979 devnum = find_next_zero_bit(bus->devmap.devicemap, 1986 devnum = find_next_zero_bit(bus->devmap.devicemap,
1980 128, 1); 1987 128, 1);
1981 bus->devnum_next = ( devnum >= 127 ? 1 : devnum + 1); 1988 bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1);
1982 } 1989 }
1983 if (devnum < 128) { 1990 if (devnum < 128) {
1984 set_bit(devnum, bus->devmap.devicemap); 1991 set_bit(devnum, bus->devmap.devicemap);
@@ -2018,8 +2025,8 @@ static void hub_free_dev(struct usb_device *udev)
2018 * Something got disconnected. Get rid of it and all of its children. 2025 * Something got disconnected. Get rid of it and all of its children.
2019 * 2026 *
2020 * If *pdev is a normal device then the parent hub must already be locked. 2027 * If *pdev is a normal device then the parent hub must already be locked.
2021 * If *pdev is a root hub then this routine will acquire the 2028 * If *pdev is a root hub then the caller must hold the usb_bus_list_lock,
2022 * usb_bus_list_lock on behalf of the caller. 2029 * which protects the set of root hubs as well as the list of buses.
2023 * 2030 *
2024 * Only hub drivers (including virtual root hub drivers for host 2031 * Only hub drivers (including virtual root hub drivers for host
2025 * controllers) should ever call this. 2032 * controllers) should ever call this.
@@ -2232,8 +2239,7 @@ static int usb_enumerate_device(struct usb_device *udev)
2232 udev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL); 2239 udev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL);
2233 udev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL); 2240 udev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL);
2234 udev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL); 2241 udev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL);
2235 } 2242 } else {
2236 else {
2237 /* read the standard strings and cache them if present */ 2243 /* read the standard strings and cache them if present */
2238 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); 2244 udev->product = usb_cache_string(udev, udev->descriptor.iProduct);
2239 udev->manufacturer = usb_cache_string(udev, 2245 udev->manufacturer = usb_cache_string(udev,
@@ -2489,7 +2495,7 @@ error_device_descriptor:
2489 usb_autosuspend_device(usb_dev); 2495 usb_autosuspend_device(usb_dev);
2490error_autoresume: 2496error_autoresume:
2491out_authorized: 2497out_authorized:
2492 usb_unlock_device(usb_dev); // complements locktree 2498 usb_unlock_device(usb_dev); /* complements locktree */
2493 return result; 2499 return result;
2494} 2500}
2495 2501
@@ -3108,8 +3114,8 @@ static int finish_port_resume(struct usb_device *udev)
3108 retry_reset_resume: 3114 retry_reset_resume:
3109 status = usb_reset_and_verify_device(udev); 3115 status = usb_reset_and_verify_device(udev);
3110 3116
3111 /* 10.5.4.5 says be sure devices in the tree are still there. 3117 /* 10.5.4.5 says be sure devices in the tree are still there.
3112 * For now let's assume the device didn't go crazy on resume, 3118 * For now let's assume the device didn't go crazy on resume,
3113 * and device drivers will know about any resume quirks. 3119 * and device drivers will know about any resume quirks.
3114 */ 3120 */
3115 if (status == 0) { 3121 if (status == 0) {
@@ -3211,7 +3217,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
3211 if (status == 0 && !port_is_suspended(hub, portstatus)) 3217 if (status == 0 && !port_is_suspended(hub, portstatus))
3212 goto SuspendCleared; 3218 goto SuspendCleared;
3213 3219
3214 // dev_dbg(hub->intfdev, "resume port %d\n", port1); 3220 /* dev_dbg(hub->intfdev, "resume port %d\n", port1); */
3215 3221
3216 set_bit(port1, hub->busy_bits); 3222 set_bit(port1, hub->busy_bits);
3217 3223
@@ -3426,6 +3432,9 @@ static int usb_req_set_sel(struct usb_device *udev, enum usb3_link_state state)
3426 unsigned long long u2_pel; 3432 unsigned long long u2_pel;
3427 int ret; 3433 int ret;
3428 3434
3435 if (udev->state != USB_STATE_CONFIGURED)
3436 return 0;
3437
3429 /* Convert SEL and PEL stored in ns to us */ 3438 /* Convert SEL and PEL stored in ns to us */
3430 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); 3439 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000);
3431 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); 3440 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000);
@@ -3852,7 +3861,7 @@ EXPORT_SYMBOL_GPL(usb_enable_ltm);
3852 * Between connect detection and reset signaling there must be a delay 3861 * Between connect detection and reset signaling there must be a delay
3853 * of 100ms at least for debounce and power-settling. The corresponding 3862 * of 100ms at least for debounce and power-settling. The corresponding
3854 * timer shall restart whenever the downstream port detects a disconnect. 3863 * timer shall restart whenever the downstream port detects a disconnect.
3855 * 3864 *
3856 * Apparently there are some bluetooth and irda-dongles and a number of 3865 * Apparently there are some bluetooth and irda-dongles and a number of
3857 * low-speed devices for which this debounce period may last over a second. 3866 * low-speed devices for which this debounce period may last over a second.
3858 * Not covered by the spec - but easy to deal with. 3867 * Not covered by the spec - but easy to deal with.
@@ -3946,6 +3955,32 @@ static int hub_set_address(struct usb_device *udev, int devnum)
3946 return retval; 3955 return retval;
3947} 3956}
3948 3957
3958/*
3959 * There are reports of USB 3.0 devices that say they support USB 2.0 Link PM
3960 * when they're plugged into a USB 2.0 port, but they don't work when LPM is
3961 * enabled.
3962 *
3963 * Only enable USB 2.0 Link PM if the port is internal (hardwired), or the
3964 * device says it supports the new USB 2.0 Link PM errata by setting the BESL
3965 * support bit in the BOS descriptor.
3966 */
3967static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev)
3968{
3969 int connect_type;
3970
3971 if (!udev->usb2_hw_lpm_capable)
3972 return;
3973
3974 connect_type = usb_get_hub_port_connect_type(udev->parent,
3975 udev->portnum);
3976
3977 if ((udev->bos->ext_cap->bmAttributes & USB_BESL_SUPPORT) ||
3978 connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) {
3979 udev->usb2_hw_lpm_allowed = 1;
3980 usb_set_usb2_hardware_lpm(udev, 1);
3981 }
3982}
3983
3949/* Reset device, (re)assign address, get device descriptor. 3984/* Reset device, (re)assign address, get device descriptor.
3950 * Device connection must be stable, no more debouncing needed. 3985 * Device connection must be stable, no more debouncing needed.
3951 * Returns device in USB_STATE_ADDRESS, except on error. 3986 * Returns device in USB_STATE_ADDRESS, except on error.
@@ -4052,7 +4087,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4052 udev->tt = &hub->tt; 4087 udev->tt = &hub->tt;
4053 udev->ttport = port1; 4088 udev->ttport = port1;
4054 } 4089 }
4055 4090
4056 /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way? 4091 /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way?
4057 * Because device hardware and firmware is sometimes buggy in 4092 * Because device hardware and firmware is sometimes buggy in
4058 * this area, and this is how Linux has done it for ages. 4093 * this area, and this is how Linux has done it for ages.
@@ -4127,11 +4162,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4127#undef GET_DESCRIPTOR_BUFSIZE 4162#undef GET_DESCRIPTOR_BUFSIZE
4128 } 4163 }
4129 4164
4130 /* 4165 /*
4131 * If device is WUSB, we already assigned an 4166 * If device is WUSB, we already assigned an
4132 * unauthorized address in the Connect Ack sequence; 4167 * unauthorized address in the Connect Ack sequence;
4133 * authorization will assign the final address. 4168 * authorization will assign the final address.
4134 */ 4169 */
4135 if (udev->wusb == 0) { 4170 if (udev->wusb == 0) {
4136 for (j = 0; j < SET_ADDRESS_TRIES; ++j) { 4171 for (j = 0; j < SET_ADDRESS_TRIES; ++j) {
4137 retval = hub_set_address(udev, devnum); 4172 retval = hub_set_address(udev, devnum);
@@ -4160,7 +4195,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4160 msleep(10); 4195 msleep(10);
4161 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) 4196 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3))
4162 break; 4197 break;
4163 } 4198 }
4164 4199
4165 retval = usb_get_device_descriptor(udev, 8); 4200 retval = usb_get_device_descriptor(udev, 8);
4166 if (retval < 8) { 4201 if (retval < 8) {
@@ -4216,7 +4251,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4216 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); 4251 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i);
4217 usb_ep0_reinit(udev); 4252 usb_ep0_reinit(udev);
4218 } 4253 }
4219 4254
4220 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); 4255 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE);
4221 if (retval < (signed)sizeof(udev->descriptor)) { 4256 if (retval < (signed)sizeof(udev->descriptor)) {
4222 if (retval != -ENODEV) 4257 if (retval != -ENODEV)
@@ -4239,6 +4274,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4239 /* notify HCD that we have a device connected and addressed */ 4274 /* notify HCD that we have a device connected and addressed */
4240 if (hcd->driver->update_device) 4275 if (hcd->driver->update_device)
4241 hcd->driver->update_device(hcd, udev); 4276 hcd->driver->update_device(hcd, udev);
4277 hub_set_initial_usb2_lpm_policy(udev);
4242fail: 4278fail:
4243 if (retval) { 4279 if (retval) {
4244 hub_port_disable(hub, port1, 0); 4280 hub_port_disable(hub, port1, 0);
@@ -4313,7 +4349,7 @@ hub_power_remaining (struct usb_hub *hub)
4313 } 4349 }
4314 if (remaining < 0) { 4350 if (remaining < 0) {
4315 dev_warn(hub->intfdev, "%dmA over power budget!\n", 4351 dev_warn(hub->intfdev, "%dmA over power budget!\n",
4316 - remaining); 4352 -remaining);
4317 remaining = 0; 4353 remaining = 0;
4318 } 4354 }
4319 return remaining; 4355 return remaining;
@@ -4424,7 +4460,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4424 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); 4460 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
4425 4461
4426 if (portstatus & USB_PORT_STAT_ENABLE) 4462 if (portstatus & USB_PORT_STAT_ENABLE)
4427 goto done; 4463 goto done;
4428 return; 4464 return;
4429 } 4465 }
4430 if (hub_is_superspeed(hub->hdev)) 4466 if (hub_is_superspeed(hub->hdev))
@@ -4447,7 +4483,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4447 } 4483 }
4448 4484
4449 usb_set_device_state(udev, USB_STATE_POWERED); 4485 usb_set_device_state(udev, USB_STATE_POWERED);
4450 udev->bus_mA = hub->mA_per_port; 4486 udev->bus_mA = hub->mA_per_port;
4451 udev->level = hdev->level + 1; 4487 udev->level = hdev->level + 1;
4452 udev->wusb = hub_is_wusb(hub); 4488 udev->wusb = hub_is_wusb(hub);
4453 4489
@@ -4501,7 +4537,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4501 goto loop_disable; 4537 goto loop_disable;
4502 } 4538 }
4503 } 4539 }
4504 4540
4505 /* check for devices running slower than they could */ 4541 /* check for devices running slower than they could */
4506 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 4542 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200
4507 && udev->speed == USB_SPEED_FULL 4543 && udev->speed == USB_SPEED_FULL
@@ -4561,7 +4597,7 @@ loop:
4561 dev_err(hub_dev, "unable to enumerate USB device on port %d\n", 4597 dev_err(hub_dev, "unable to enumerate USB device on port %d\n",
4562 port1); 4598 port1);
4563 } 4599 }
4564 4600
4565done: 4601done:
4566 hub_port_disable(hub, port1, 1); 4602 hub_port_disable(hub, port1, 1);
4567 if (hcd->driver->relinquish_port && !hub->hdev->parent) 4603 if (hcd->driver->relinquish_port && !hub->hdev->parent)
@@ -4726,7 +4762,7 @@ static void hub_events(void)
4726 * EM interference sometimes causes badly 4762 * EM interference sometimes causes badly
4727 * shielded USB devices to be shutdown by 4763 * shielded USB devices to be shutdown by
4728 * the hub, this hack enables them again. 4764 * the hub, this hack enables them again.
4729 * Works at least with mouse driver. 4765 * Works at least with mouse driver.
4730 */ 4766 */
4731 if (!(portstatus & USB_PORT_STAT_ENABLE) 4767 if (!(portstatus & USB_PORT_STAT_ENABLE)
4732 && !connect_change 4768 && !connect_change
@@ -4838,7 +4874,7 @@ static void hub_events(void)
4838 dev_dbg(hub_dev, "over-current change\n"); 4874 dev_dbg(hub_dev, "over-current change\n");
4839 clear_hub_feature(hdev, C_HUB_OVER_CURRENT); 4875 clear_hub_feature(hdev, C_HUB_OVER_CURRENT);
4840 msleep(500); /* Cool down */ 4876 msleep(500); /* Cool down */
4841 hub_power_on(hub, true); 4877 hub_power_on(hub, true);
4842 hub_hub_status(hub, &status, &unused); 4878 hub_hub_status(hub, &status, &unused);
4843 if (status & HUB_STATUS_OVERCURRENT) 4879 if (status & HUB_STATUS_OVERCURRENT)
4844 dev_err(hub_dev, "over-current " 4880 dev_err(hub_dev, "over-current "
@@ -4858,7 +4894,7 @@ static void hub_events(void)
4858 usb_unlock_device(hdev); 4894 usb_unlock_device(hdev);
4859 kref_put(&hub->kref, hub_release); 4895 kref_put(&hub->kref, hub_release);
4860 4896
4861 } /* end while (1) */ 4897 } /* end while (1) */
4862} 4898}
4863 4899
4864static int hub_thread(void *__unused) 4900static int hub_thread(void *__unused)
@@ -4883,7 +4919,7 @@ static int hub_thread(void *__unused)
4883 4919
4884static const struct usb_device_id hub_id_table[] = { 4920static const struct usb_device_id hub_id_table[] = {
4885 { .match_flags = USB_DEVICE_ID_MATCH_VENDOR 4921 { .match_flags = USB_DEVICE_ID_MATCH_VENDOR
4886 | USB_DEVICE_ID_MATCH_INT_CLASS, 4922 | USB_DEVICE_ID_MATCH_INT_CLASS,
4887 .idVendor = USB_VENDOR_GENESYS_LOGIC, 4923 .idVendor = USB_VENDOR_GENESYS_LOGIC,
4888 .bInterfaceClass = USB_CLASS_HUB, 4924 .bInterfaceClass = USB_CLASS_HUB,
4889 .driver_info = HUB_QUIRK_CHECK_PORT_AUTOSUSPEND}, 4925 .driver_info = HUB_QUIRK_CHECK_PORT_AUTOSUSPEND},
@@ -5083,6 +5119,12 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
5083 } 5119 }
5084 parent_hub = usb_hub_to_struct_hub(parent_hdev); 5120 parent_hub = usb_hub_to_struct_hub(parent_hdev);
5085 5121
5122 /* Disable USB2 hardware LPM.
5123 * It will be re-enabled by the enumeration process.
5124 */
5125 if (udev->usb2_hw_lpm_enabled == 1)
5126 usb_set_usb2_hardware_lpm(udev, 0);
5127
5086 bos = udev->bos; 5128 bos = udev->bos;
5087 udev->bos = NULL; 5129 udev->bos = NULL;
5088 5130
@@ -5117,13 +5159,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
5117 5159
5118 if (ret < 0) 5160 if (ret < 0)
5119 goto re_enumerate; 5161 goto re_enumerate;
5120 5162
5121 /* Device might have changed firmware (DFU or similar) */ 5163 /* Device might have changed firmware (DFU or similar) */
5122 if (descriptors_changed(udev, &descriptor, bos)) { 5164 if (descriptors_changed(udev, &descriptor, bos)) {
5123 dev_info(&udev->dev, "device firmware changed\n"); 5165 dev_info(&udev->dev, "device firmware changed\n");
5124 udev->descriptor = descriptor; /* for disconnect() calls */ 5166 udev->descriptor = descriptor; /* for disconnect() calls */
5125 goto re_enumerate; 5167 goto re_enumerate;
5126 } 5168 }
5127 5169
5128 /* Restore the device's previous configuration */ 5170 /* Restore the device's previous configuration */
5129 if (!udev->actconfig) 5171 if (!udev->actconfig)
@@ -5148,7 +5190,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
5148 udev->actconfig->desc.bConfigurationValue, ret); 5190 udev->actconfig->desc.bConfigurationValue, ret);
5149 mutex_unlock(hcd->bandwidth_mutex); 5191 mutex_unlock(hcd->bandwidth_mutex);
5150 goto re_enumerate; 5192 goto re_enumerate;
5151 } 5193 }
5152 mutex_unlock(hcd->bandwidth_mutex); 5194 mutex_unlock(hcd->bandwidth_mutex);
5153 usb_set_device_state(udev, USB_STATE_CONFIGURED); 5195 usb_set_device_state(udev, USB_STATE_CONFIGURED);
5154 5196
@@ -5190,12 +5232,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
5190 5232
5191done: 5233done:
5192 /* Now that the alt settings are re-installed, enable LTM and LPM. */ 5234 /* Now that the alt settings are re-installed, enable LTM and LPM. */
5235 usb_set_usb2_hardware_lpm(udev, 1);
5193 usb_unlocked_enable_lpm(udev); 5236 usb_unlocked_enable_lpm(udev);
5194 usb_enable_ltm(udev); 5237 usb_enable_ltm(udev);
5195 usb_release_bos_descriptor(udev); 5238 usb_release_bos_descriptor(udev);
5196 udev->bos = bos; 5239 udev->bos = bos;
5197 return 0; 5240 return 0;
5198 5241
5199re_enumerate: 5242re_enumerate:
5200 /* LPM state doesn't matter when we're about to destroy the device. */ 5243 /* LPM state doesn't matter when we're about to destroy the device. */
5201 hub_port_logical_disconnect(parent_hub, port1); 5244 hub_port_logical_disconnect(parent_hub, port1);
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 82927e1ed27d..bb315970e475 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1182,8 +1182,12 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1182 put_device(&dev->actconfig->interface[i]->dev); 1182 put_device(&dev->actconfig->interface[i]->dev);
1183 dev->actconfig->interface[i] = NULL; 1183 dev->actconfig->interface[i] = NULL;
1184 } 1184 }
1185
1186 if (dev->usb2_hw_lpm_enabled == 1)
1187 usb_set_usb2_hardware_lpm(dev, 0);
1185 usb_unlocked_disable_lpm(dev); 1188 usb_unlocked_disable_lpm(dev);
1186 usb_disable_ltm(dev); 1189 usb_disable_ltm(dev);
1190
1187 dev->actconfig = NULL; 1191 dev->actconfig = NULL;
1188 if (dev->state == USB_STATE_CONFIGURED) 1192 if (dev->state == USB_STATE_CONFIGURED)
1189 usb_set_device_state(dev, USB_STATE_ADDRESS); 1193 usb_set_device_state(dev, USB_STATE_ADDRESS);
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 5b44cd47da5b..12924dbfdc2c 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/usb.h> 14#include <linux/usb.h>
15#include <linux/usb/quirks.h> 15#include <linux/usb/quirks.h>
16#include <linux/usb/hcd.h>
16#include "usb.h" 17#include "usb.h"
17 18
18/* Lists of quirky USB devices, split in device quirks and interface quirks. 19/* Lists of quirky USB devices, split in device quirks and interface quirks.
@@ -97,6 +98,9 @@ static const struct usb_device_id usb_quirk_list[] = {
97 /* Alcor Micro Corp. Hub */ 98 /* Alcor Micro Corp. Hub */
98 { USB_DEVICE(0x058f, 0x9254), .driver_info = USB_QUIRK_RESET_RESUME }, 99 { USB_DEVICE(0x058f, 0x9254), .driver_info = USB_QUIRK_RESET_RESUME },
99 100
101 /* MicroTouch Systems touchscreen */
102 { USB_DEVICE(0x0596, 0x051e), .driver_info = USB_QUIRK_RESET_RESUME },
103
100 /* appletouch */ 104 /* appletouch */
101 { USB_DEVICE(0x05ac, 0x021a), .driver_info = USB_QUIRK_RESET_RESUME }, 105 { USB_DEVICE(0x05ac, 0x021a), .driver_info = USB_QUIRK_RESET_RESUME },
102 106
@@ -130,6 +134,9 @@ static const struct usb_device_id usb_quirk_list[] = {
130 /* Broadcom BCM92035DGROM BT dongle */ 134 /* Broadcom BCM92035DGROM BT dongle */
131 { USB_DEVICE(0x0a5c, 0x2021), .driver_info = USB_QUIRK_RESET_RESUME }, 135 { USB_DEVICE(0x0a5c, 0x2021), .driver_info = USB_QUIRK_RESET_RESUME },
132 136
137 /* MAYA44USB sound device */
138 { USB_DEVICE(0x0a92, 0x0091), .driver_info = USB_QUIRK_RESET_RESUME },
139
133 /* Action Semiconductor flash disk */ 140 /* Action Semiconductor flash disk */
134 { USB_DEVICE(0x10d6, 0x2200), .driver_info = 141 { USB_DEVICE(0x10d6, 0x2200), .driver_info =
135 USB_QUIRK_STRING_FETCH_255 }, 142 USB_QUIRK_STRING_FETCH_255 },
@@ -155,6 +162,21 @@ static const struct usb_device_id usb_interface_quirk_list[] = {
155 { } /* terminating entry must be last */ 162 { } /* terminating entry must be last */
156}; 163};
157 164
165static const struct usb_device_id usb_amd_resume_quirk_list[] = {
166 /* Lenovo Mouse with Pixart controller */
167 { USB_DEVICE(0x17ef, 0x602e), .driver_info = USB_QUIRK_RESET_RESUME },
168
169 /* Pixart Mouse */
170 { USB_DEVICE(0x093a, 0x2500), .driver_info = USB_QUIRK_RESET_RESUME },
171 { USB_DEVICE(0x093a, 0x2510), .driver_info = USB_QUIRK_RESET_RESUME },
172 { USB_DEVICE(0x093a, 0x2521), .driver_info = USB_QUIRK_RESET_RESUME },
173
174 /* Logitech Optical Mouse M90/M100 */
175 { USB_DEVICE(0x046d, 0xc05a), .driver_info = USB_QUIRK_RESET_RESUME },
176
177 { } /* terminating entry must be last */
178};
179
158static bool usb_match_any_interface(struct usb_device *udev, 180static bool usb_match_any_interface(struct usb_device *udev,
159 const struct usb_device_id *id) 181 const struct usb_device_id *id)
160{ 182{
@@ -181,6 +203,18 @@ static bool usb_match_any_interface(struct usb_device *udev,
181 return false; 203 return false;
182} 204}
183 205
206static int usb_amd_resume_quirk(struct usb_device *udev)
207{
208 struct usb_hcd *hcd;
209
210 hcd = bus_to_hcd(udev->bus);
211 /* The device should be attached directly to root hub */
212 if (udev->level == 1 && hcd->amd_resume_bug == 1)
213 return 1;
214
215 return 0;
216}
217
184static u32 __usb_detect_quirks(struct usb_device *udev, 218static u32 __usb_detect_quirks(struct usb_device *udev,
185 const struct usb_device_id *id) 219 const struct usb_device_id *id)
186{ 220{
@@ -206,6 +240,15 @@ static u32 __usb_detect_quirks(struct usb_device *udev,
206void usb_detect_quirks(struct usb_device *udev) 240void usb_detect_quirks(struct usb_device *udev)
207{ 241{
208 udev->quirks = __usb_detect_quirks(udev, usb_quirk_list); 242 udev->quirks = __usb_detect_quirks(udev, usb_quirk_list);
243
244 /*
245 * Pixart-based mice would trigger remote wakeup issue on AMD
246 * Yangtze chipset, so set them as RESET_RESUME flag.
247 */
248 if (usb_amd_resume_quirk(udev))
249 udev->quirks |= __usb_detect_quirks(udev,
250 usb_amd_resume_quirk_list);
251
209 if (udev->quirks) 252 if (udev->quirks)
210 dev_dbg(&udev->dev, "USB quirks for this device: %x\n", 253 dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
211 udev->quirks); 254 udev->quirks);
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 6d2c8edb1ffe..52a97adf02a0 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -23,14 +23,16 @@ static ssize_t field##_show(struct device *dev, \
23{ \ 23{ \
24 struct usb_device *udev; \ 24 struct usb_device *udev; \
25 struct usb_host_config *actconfig; \ 25 struct usb_host_config *actconfig; \
26 ssize_t rc = 0; \
26 \ 27 \
27 udev = to_usb_device(dev); \ 28 udev = to_usb_device(dev); \
29 usb_lock_device(udev); \
28 actconfig = udev->actconfig; \ 30 actconfig = udev->actconfig; \
29 if (actconfig) \ 31 if (actconfig) \
30 return sprintf(buf, format_string, \ 32 rc = sprintf(buf, format_string, \
31 actconfig->desc.field); \ 33 actconfig->desc.field); \
32 else \ 34 usb_unlock_device(udev); \
33 return 0; \ 35 return rc; \
34} \ 36} \
35 37
36#define usb_actconfig_attr(field, format_string) \ 38#define usb_actconfig_attr(field, format_string) \
@@ -45,12 +47,15 @@ static ssize_t bMaxPower_show(struct device *dev,
45{ 47{
46 struct usb_device *udev; 48 struct usb_device *udev;
47 struct usb_host_config *actconfig; 49 struct usb_host_config *actconfig;
50 ssize_t rc = 0;
48 51
49 udev = to_usb_device(dev); 52 udev = to_usb_device(dev);
53 usb_lock_device(udev);
50 actconfig = udev->actconfig; 54 actconfig = udev->actconfig;
51 if (!actconfig) 55 if (actconfig)
52 return 0; 56 rc = sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig));
53 return sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); 57 usb_unlock_device(udev);
58 return rc;
54} 59}
55static DEVICE_ATTR_RO(bMaxPower); 60static DEVICE_ATTR_RO(bMaxPower);
56 61
@@ -59,12 +64,15 @@ static ssize_t configuration_show(struct device *dev,
59{ 64{
60 struct usb_device *udev; 65 struct usb_device *udev;
61 struct usb_host_config *actconfig; 66 struct usb_host_config *actconfig;
67 ssize_t rc = 0;
62 68
63 udev = to_usb_device(dev); 69 udev = to_usb_device(dev);
70 usb_lock_device(udev);
64 actconfig = udev->actconfig; 71 actconfig = udev->actconfig;
65 if ((!actconfig) || (!actconfig->string)) 72 if (actconfig && actconfig->string)
66 return 0; 73 rc = sprintf(buf, "%s\n", actconfig->string);
67 return sprintf(buf, "%s\n", actconfig->string); 74 usb_unlock_device(udev);
75 return rc;
68} 76}
69static DEVICE_ATTR_RO(configuration); 77static DEVICE_ATTR_RO(configuration);
70 78
@@ -390,7 +398,8 @@ static DEVICE_ATTR_RW(autosuspend);
390static const char on_string[] = "on"; 398static const char on_string[] = "on";
391static const char auto_string[] = "auto"; 399static const char auto_string[] = "auto";
392 400
393static void warn_level(void) { 401static void warn_level(void)
402{
394 static int level_warned; 403 static int level_warned;
395 404
396 if (!level_warned) { 405 if (!level_warned) {
@@ -449,7 +458,7 @@ static ssize_t usb2_hardware_lpm_show(struct device *dev,
449 struct usb_device *udev = to_usb_device(dev); 458 struct usb_device *udev = to_usb_device(dev);
450 const char *p; 459 const char *p;
451 460
452 if (udev->usb2_hw_lpm_enabled == 1) 461 if (udev->usb2_hw_lpm_allowed == 1)
453 p = "enabled"; 462 p = "enabled";
454 else 463 else
455 p = "disabled"; 464 p = "disabled";
@@ -469,8 +478,10 @@ static ssize_t usb2_hardware_lpm_store(struct device *dev,
469 478
470 ret = strtobool(buf, &value); 479 ret = strtobool(buf, &value);
471 480
472 if (!ret) 481 if (!ret) {
482 udev->usb2_hw_lpm_allowed = value;
473 ret = usb_set_usb2_hardware_lpm(udev, value); 483 ret = usb_set_usb2_hardware_lpm(udev, value);
484 }
474 485
475 usb_unlock_device(udev); 486 usb_unlock_device(udev);
476 487
@@ -644,7 +655,7 @@ static ssize_t authorized_store(struct device *dev,
644 result = usb_deauthorize_device(usb_dev); 655 result = usb_deauthorize_device(usb_dev);
645 else 656 else
646 result = usb_authorize_device(usb_dev); 657 result = usb_authorize_device(usb_dev);
647 return result < 0? result : size; 658 return result < 0 ? result : size;
648} 659}
649static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR, 660static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR,
650 authorized_show, authorized_store); 661 authorized_show, authorized_store);
@@ -764,6 +775,7 @@ read_descriptors(struct file *filp, struct kobject *kobj,
764 * Following that are the raw descriptor entries for all the 775 * Following that are the raw descriptor entries for all the
765 * configurations (config plus subsidiary descriptors). 776 * configurations (config plus subsidiary descriptors).
766 */ 777 */
778 usb_lock_device(udev);
767 for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations && 779 for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations &&
768 nleft > 0; ++cfgno) { 780 nleft > 0; ++cfgno) {
769 if (cfgno < 0) { 781 if (cfgno < 0) {
@@ -784,6 +796,7 @@ read_descriptors(struct file *filp, struct kobject *kobj,
784 off -= srclen; 796 off -= srclen;
785 } 797 }
786 } 798 }
799 usb_unlock_device(udev);
787 return count - nleft; 800 return count - nleft;
788} 801}
789 802
@@ -870,9 +883,7 @@ static ssize_t interface_show(struct device *dev, struct device_attribute *attr,
870 char *string; 883 char *string;
871 884
872 intf = to_usb_interface(dev); 885 intf = to_usb_interface(dev);
873 string = intf->cur_altsetting->string; 886 string = ACCESS_ONCE(intf->cur_altsetting->string);
874 barrier(); /* The altsetting might change! */
875
876 if (!string) 887 if (!string)
877 return 0; 888 return 0;
878 return sprintf(buf, "%s\n", string); 889 return sprintf(buf, "%s\n", string);
@@ -888,7 +899,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
888 899
889 intf = to_usb_interface(dev); 900 intf = to_usb_interface(dev);
890 udev = interface_to_usbdev(intf); 901 udev = interface_to_usbdev(intf);
891 alt = intf->cur_altsetting; 902 alt = ACCESS_ONCE(intf->cur_altsetting);
892 903
893 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X" 904 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
894 "ic%02Xisc%02Xip%02Xin%02X\n", 905 "ic%02Xisc%02Xip%02Xin%02X\n",
@@ -909,23 +920,14 @@ static ssize_t supports_autosuspend_show(struct device *dev,
909 struct device_attribute *attr, 920 struct device_attribute *attr,
910 char *buf) 921 char *buf)
911{ 922{
912 struct usb_interface *intf; 923 int s;
913 struct usb_device *udev;
914 int ret;
915 924
916 intf = to_usb_interface(dev); 925 device_lock(dev);
917 udev = interface_to_usbdev(intf);
918
919 usb_lock_device(udev);
920 /* Devices will be autosuspended even when an interface isn't claimed */ 926 /* Devices will be autosuspended even when an interface isn't claimed */
921 if (!intf->dev.driver || 927 s = (!dev->driver || to_usb_driver(dev->driver)->supports_autosuspend);
922 to_usb_driver(intf->dev.driver)->supports_autosuspend) 928 device_unlock(dev);
923 ret = sprintf(buf, "%u\n", 1);
924 else
925 ret = sprintf(buf, "%u\n", 0);
926 usb_unlock_device(udev);
927 929
928 return ret; 930 return sprintf(buf, "%u\n", s);
929} 931}
930static DEVICE_ATTR_RO(supports_autosuspend); 932static DEVICE_ATTR_RO(supports_autosuspend);
931 933
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index c12bc790a6a7..e62208356c89 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -138,13 +138,19 @@ void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor)
138} 138}
139EXPORT_SYMBOL_GPL(usb_anchor_urb); 139EXPORT_SYMBOL_GPL(usb_anchor_urb);
140 140
141static int usb_anchor_check_wakeup(struct usb_anchor *anchor)
142{
143 return atomic_read(&anchor->suspend_wakeups) == 0 &&
144 list_empty(&anchor->urb_list);
145}
146
141/* Callers must hold anchor->lock */ 147/* Callers must hold anchor->lock */
142static void __usb_unanchor_urb(struct urb *urb, struct usb_anchor *anchor) 148static void __usb_unanchor_urb(struct urb *urb, struct usb_anchor *anchor)
143{ 149{
144 urb->anchor = NULL; 150 urb->anchor = NULL;
145 list_del(&urb->anchor_list); 151 list_del(&urb->anchor_list);
146 usb_put_urb(urb); 152 usb_put_urb(urb);
147 if (list_empty(&anchor->urb_list)) 153 if (usb_anchor_check_wakeup(anchor))
148 wake_up(&anchor->wait); 154 wake_up(&anchor->wait);
149} 155}
150 156
@@ -846,6 +852,39 @@ void usb_unlink_anchored_urbs(struct usb_anchor *anchor)
846EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs); 852EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs);
847 853
848/** 854/**
855 * usb_anchor_suspend_wakeups
856 * @anchor: the anchor you want to suspend wakeups on
857 *
858 * Call this to stop the last urb being unanchored from waking up any
859 * usb_wait_anchor_empty_timeout waiters. This is used in the hcd urb give-
860 * back path to delay waking up until after the completion handler has run.
861 */
862void usb_anchor_suspend_wakeups(struct usb_anchor *anchor)
863{
864 if (anchor)
865 atomic_inc(&anchor->suspend_wakeups);
866}
867EXPORT_SYMBOL_GPL(usb_anchor_suspend_wakeups);
868
869/**
870 * usb_anchor_resume_wakeups
871 * @anchor: the anchor you want to resume wakeups on
872 *
873 * Allow usb_wait_anchor_empty_timeout waiters to be woken up again, and
874 * wake up any current waiters if the anchor is empty.
875 */
876void usb_anchor_resume_wakeups(struct usb_anchor *anchor)
877{
878 if (!anchor)
879 return;
880
881 atomic_dec(&anchor->suspend_wakeups);
882 if (usb_anchor_check_wakeup(anchor))
883 wake_up(&anchor->wait);
884}
885EXPORT_SYMBOL_GPL(usb_anchor_resume_wakeups);
886
887/**
849 * usb_wait_anchor_empty_timeout - wait for an anchor to be unused 888 * usb_wait_anchor_empty_timeout - wait for an anchor to be unused
850 * @anchor: the anchor you want to become unused 889 * @anchor: the anchor you want to become unused
851 * @timeout: how long you are willing to wait in milliseconds 890 * @timeout: how long you are willing to wait in milliseconds
@@ -858,7 +897,8 @@ EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs);
858int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, 897int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor,
859 unsigned int timeout) 898 unsigned int timeout)
860{ 899{
861 return wait_event_timeout(anchor->wait, list_empty(&anchor->urb_list), 900 return wait_event_timeout(anchor->wait,
901 usb_anchor_check_wakeup(anchor),
862 msecs_to_jiffies(timeout)); 902 msecs_to_jiffies(timeout));
863} 903}
864EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout); 904EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 0a6ee2e70b25..4d1144990d4c 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -497,7 +497,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
497 dev->authorized = 1; 497 dev->authorized = 1;
498 else { 498 else {
499 dev->authorized = usb_hcd->authorized_default; 499 dev->authorized = usb_hcd->authorized_default;
500 dev->wusb = usb_bus_is_wusb(bus)? 1 : 0; 500 dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0;
501 } 501 }
502 return dev; 502 return dev;
503} 503}
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 823857767a16..c49383669cd8 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -35,6 +35,7 @@ extern int usb_get_device_descriptor(struct usb_device *dev,
35 unsigned int size); 35 unsigned int size);
36extern int usb_get_bos_descriptor(struct usb_device *dev); 36extern int usb_get_bos_descriptor(struct usb_device *dev);
37extern void usb_release_bos_descriptor(struct usb_device *dev); 37extern void usb_release_bos_descriptor(struct usb_device *dev);
38extern int usb_device_supports_lpm(struct usb_device *udev);
38extern char *usb_cache_string(struct usb_device *udev, int index); 39extern char *usb_cache_string(struct usb_device *udev, int index);
39extern int usb_set_configuration(struct usb_device *dev, int configuration); 40extern int usb_set_configuration(struct usb_device *dev, int configuration);
40extern int usb_choose_configuration(struct usb_device *udev); 41extern int usb_choose_configuration(struct usb_device *udev);
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index f969ea266acb..70fc43027a5c 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -1,7 +1,6 @@
1config USB_DWC3 1config USB_DWC3
2 tristate "DesignWare USB3 DRD Core Support" 2 tristate "DesignWare USB3 DRD Core Support"
3 depends on (USB || USB_GADGET) && GENERIC_HARDIRQS && HAS_DMA 3 depends on (USB || USB_GADGET) && HAS_DMA
4 depends on EXTCON
5 select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD 4 select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD
6 help 5 help
7 Say Y or M here if your system has a Dual Role SuperSpeed 6 Say Y or M here if your system has a Dual Role SuperSpeed
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 474162e9d01d..74f9cf02da07 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -584,7 +584,7 @@ static int dwc3_remove(struct platform_device *pdev)
584 usb_phy_set_suspend(dwc->usb2_phy, 1); 584 usb_phy_set_suspend(dwc->usb2_phy, 1);
585 usb_phy_set_suspend(dwc->usb3_phy, 1); 585 usb_phy_set_suspend(dwc->usb3_phy, 1);
586 586
587 pm_runtime_put(&pdev->dev); 587 pm_runtime_put_sync(&pdev->dev);
588 pm_runtime_disable(&pdev->dev); 588 pm_runtime_disable(&pdev->dev);
589 589
590 dwc3_debugfs_exit(dwc); 590 dwc3_debugfs_exit(dwc);
@@ -691,7 +691,6 @@ static int dwc3_resume(struct device *dev)
691 691
692 usb_phy_init(dwc->usb3_phy); 692 usb_phy_init(dwc->usb3_phy);
693 usb_phy_init(dwc->usb2_phy); 693 usb_phy_init(dwc->usb2_phy);
694 msleep(100);
695 694
696 spin_lock_irqsave(&dwc->lock, flags); 695 spin_lock_irqsave(&dwc->lock, flags);
697 696
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index 2f2e88a3a11a..8b20c70d91e7 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -119,10 +119,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
119 * Since shared usb code relies on it, set it here for now. 119 * Since shared usb code relies on it, set it here for now.
120 * Once we move to full device tree support this will vanish off. 120 * Once we move to full device tree support this will vanish off.
121 */ 121 */
122 if (!dev->dma_mask) 122 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
123 dev->dma_mask = &dev->coherent_dma_mask; 123 if (ret)
124 if (!dev->coherent_dma_mask) 124 goto err1;
125 dev->coherent_dma_mask = DMA_BIT_MASK(32);
126 125
127 platform_set_drvdata(pdev, exynos); 126 platform_set_drvdata(pdev, exynos);
128 127
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 9b138129e856..31443aeedcdb 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -28,6 +28,8 @@
28/* FIXME define these in <linux/pci_ids.h> */ 28/* FIXME define these in <linux/pci_ids.h> */
29#define PCI_VENDOR_ID_SYNOPSYS 0x16c3 29#define PCI_VENDOR_ID_SYNOPSYS 0x16c3
30#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 30#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
31#define PCI_DEVICE_ID_INTEL_BYT 0x0f37
32#define PCI_DEVICE_ID_INTEL_MRFLD 0x119e
31 33
32struct dwc3_pci { 34struct dwc3_pci {
33 struct device *dev; 35 struct device *dev;
@@ -163,7 +165,6 @@ static int dwc3_pci_probe(struct pci_dev *pci,
163 return 0; 165 return 0;
164 166
165err3: 167err3:
166 pci_set_drvdata(pci, NULL);
167 platform_device_put(dwc3); 168 platform_device_put(dwc3);
168err1: 169err1:
169 pci_disable_device(pci); 170 pci_disable_device(pci);
@@ -178,7 +179,6 @@ static void dwc3_pci_remove(struct pci_dev *pci)
178 platform_device_unregister(glue->dwc3); 179 platform_device_unregister(glue->dwc3);
179 platform_device_unregister(glue->usb2_phy); 180 platform_device_unregister(glue->usb2_phy);
180 platform_device_unregister(glue->usb3_phy); 181 platform_device_unregister(glue->usb3_phy);
181 pci_set_drvdata(pci, NULL);
182 pci_disable_device(pci); 182 pci_disable_device(pci);
183} 183}
184 184
@@ -187,6 +187,8 @@ static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = {
187 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 187 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
188 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3), 188 PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
189 }, 189 },
190 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
191 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
190 { } /* Terminating Entry */ 192 { } /* Terminating Entry */
191}; 193};
192MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); 194MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 7fa93f4bc507..95f7649c71a7 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -352,7 +352,7 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc,
352 break; 352 break;
353 default: 353 default:
354 return -EINVAL; 354 return -EINVAL;
355 }; 355 }
356 356
357 response_pkt = (__le16 *) dwc->setup_buf; 357 response_pkt = (__le16 *) dwc->setup_buf;
358 *response_pkt = cpu_to_le16(usb_status); 358 *response_pkt = cpu_to_le16(usb_status);
@@ -470,7 +470,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
470 470
471 default: 471 default:
472 return -EINVAL; 472 return -EINVAL;
473 }; 473 }
474 474
475 return 0; 475 return 0;
476} 476}
@@ -709,7 +709,7 @@ static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
709 dev_vdbg(dwc->dev, "Forwarding to gadget driver\n"); 709 dev_vdbg(dwc->dev, "Forwarding to gadget driver\n");
710 ret = dwc3_ep0_delegate_req(dwc, ctrl); 710 ret = dwc3_ep0_delegate_req(dwc, ctrl);
711 break; 711 break;
712 }; 712 }
713 713
714 return ret; 714 return ret;
715} 715}
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index f168eaebdef8..5452c0fce360 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2611,15 +2611,13 @@ int dwc3_gadget_init(struct dwc3 *dwc)
2611 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); 2611 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget);
2612 if (ret) { 2612 if (ret) {
2613 dev_err(dwc->dev, "failed to register udc\n"); 2613 dev_err(dwc->dev, "failed to register udc\n");
2614 goto err5; 2614 goto err4;
2615 } 2615 }
2616 2616
2617 return 0; 2617 return 0;
2618 2618
2619err5:
2620 dwc3_gadget_free_endpoints(dwc);
2621
2622err4: 2619err4:
2620 dwc3_gadget_free_endpoints(dwc);
2623 dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE, 2621 dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
2624 dwc->ep0_bounce, dwc->ep0_bounce_addr); 2622 dwc->ep0_bounce, dwc->ep0_bounce_addr);
2625 2623
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
index 5e29ddeb4d33..8cfc3191be50 100644
--- a/drivers/usb/early/ehci-dbgp.c
+++ b/drivers/usb/early/ehci-dbgp.c
@@ -568,10 +568,6 @@ try_again:
568 dbgp_printk("Could not find attached debug device\n"); 568 dbgp_printk("Could not find attached debug device\n");
569 goto err; 569 goto err;
570 } 570 }
571 if (ret < 0) {
572 dbgp_printk("Attached device is not a debug device\n");
573 goto err;
574 }
575 dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint; 571 dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint;
576 dbgp_endpoint_in = dbgp_desc.bDebugInEndpoint; 572 dbgp_endpoint_in = dbgp_desc.bDebugInEndpoint;
577 573
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 30e2dd8a1f2c..a91e6422f930 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -58,6 +58,20 @@ config USB_GADGET_DEBUG
58 trying to track down. Never enable these messages for a 58 trying to track down. Never enable these messages for a
59 production build. 59 production build.
60 60
61config USB_GADGET_VERBOSE
62 bool "Verbose debugging Messages (DEVELOPMENT)"
63 depends on USB_GADGET_DEBUG
64 help
65 Many controller and gadget drivers will print verbose debugging
66 messages if you use this option to ask for those messages.
67
68 Avoid enabling these messages, even if you're actively
69 debugging such a driver. Many drivers will emit so many
70 messages that the driver timings are affected, which will
71 either create new failure modes or remove the one you're
72 trying to track down. Never enable these messages for a
73 production build.
74
61config USB_GADGET_DEBUG_FILES 75config USB_GADGET_DEBUG_FILES
62 boolean "Debugging information files (DEVELOPMENT)" 76 boolean "Debugging information files (DEVELOPMENT)"
63 depends on PROC_FS 77 depends on PROC_FS
@@ -313,7 +327,7 @@ config USB_S3C_HSUDC
313 327
314config USB_MV_UDC 328config USB_MV_UDC
315 tristate "Marvell USB2.0 Device Controller" 329 tristate "Marvell USB2.0 Device Controller"
316 depends on GENERIC_HARDIRQS && HAS_DMA 330 depends on HAS_DMA
317 help 331 help
318 Marvell Socs (including PXA and MMP series) include a high speed 332 Marvell Socs (including PXA and MMP series) include a high speed
319 USB2.0 OTG controller, which can be configured as high speed or 333 USB2.0 OTG controller, which can be configured as high speed or
@@ -425,7 +439,7 @@ config USB_GOKU
425 439
426config USB_EG20T 440config USB_EG20T
427 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC" 441 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC"
428 depends on PCI && GENERIC_HARDIRQS 442 depends on PCI
429 help 443 help
430 This is a USB device driver for EG20T PCH. 444 This is a USB device driver for EG20T PCH.
431 EG20T PCH is the platform controller hub that is used in Intel's 445 EG20T PCH is the platform controller hub that is used in Intel's
@@ -525,6 +539,9 @@ config USB_F_SUBSET
525config USB_F_RNDIS 539config USB_F_RNDIS
526 tristate 540 tristate
527 541
542config USB_F_MASS_STORAGE
543 tristate
544
528choice 545choice
529 tristate "USB Gadget Drivers" 546 tristate "USB Gadget Drivers"
530 default USB_ETH 547 default USB_ETH
@@ -662,6 +679,16 @@ config USB_CONFIGFS_PHONET
662 help 679 help
663 The Phonet protocol implementation for USB device. 680 The Phonet protocol implementation for USB device.
664 681
682config USB_CONFIGFS_MASS_STORAGE
683 boolean "Mass storage"
684 depends on USB_CONFIGFS
685 select USB_F_MASS_STORAGE
686 help
687 The Mass Storage Gadget acts as a USB Mass Storage disk drive.
688 As its storage repository it can use a regular file or a block
689 device (in much the same way as the "loop" device driver),
690 specified as a module parameter or sysfs option.
691
665config USB_ZERO 692config USB_ZERO
666 tristate "Gadget Zero (DEVELOPMENT)" 693 tristate "Gadget Zero (DEVELOPMENT)"
667 select USB_LIBCOMPOSITE 694 select USB_LIBCOMPOSITE
@@ -878,6 +905,7 @@ config USB_MASS_STORAGE
878 tristate "Mass Storage Gadget" 905 tristate "Mass Storage Gadget"
879 depends on BLOCK 906 depends on BLOCK
880 select USB_LIBCOMPOSITE 907 select USB_LIBCOMPOSITE
908 select USB_F_MASS_STORAGE
881 help 909 help
882 The Mass Storage Gadget acts as a USB Mass Storage disk drive. 910 The Mass Storage Gadget acts as a USB Mass Storage disk drive.
883 As its storage repository it can use a regular file or a block 911 As its storage repository it can use a regular file or a block
@@ -1001,6 +1029,7 @@ config USB_G_ACM_MS
1001 select USB_LIBCOMPOSITE 1029 select USB_LIBCOMPOSITE
1002 select USB_U_SERIAL 1030 select USB_U_SERIAL
1003 select USB_F_ACM 1031 select USB_F_ACM
1032 select USB_F_MASS_STORAGE
1004 help 1033 help
1005 This driver provides two functions in one configuration: 1034 This driver provides two functions in one configuration:
1006 a mass storage, and a CDC ACM (serial port) link. 1035 a mass storage, and a CDC ACM (serial port) link.
@@ -1015,8 +1044,8 @@ config USB_G_MULTI
1015 select USB_LIBCOMPOSITE 1044 select USB_LIBCOMPOSITE
1016 select USB_U_SERIAL 1045 select USB_U_SERIAL
1017 select USB_U_ETHER 1046 select USB_U_ETHER
1018 select USB_U_RNDIS
1019 select USB_F_ACM 1047 select USB_F_ACM
1048 select USB_F_MASS_STORAGE
1020 help 1049 help
1021 The Multifunction Composite Gadget provides Ethernet (RNDIS 1050 The Multifunction Composite Gadget provides Ethernet (RNDIS
1022 and/or CDC Ethernet), mass storage and ACM serial link 1051 and/or CDC Ethernet), mass storage and ACM serial link
@@ -1035,6 +1064,8 @@ config USB_G_MULTI
1035config USB_G_MULTI_RNDIS 1064config USB_G_MULTI_RNDIS
1036 bool "RNDIS + CDC Serial + Storage configuration" 1065 bool "RNDIS + CDC Serial + Storage configuration"
1037 depends on USB_G_MULTI 1066 depends on USB_G_MULTI
1067 select USB_U_RNDIS
1068 select USB_F_RNDIS
1038 default y 1069 default y
1039 help 1070 help
1040 This option enables a configuration with RNDIS, CDC Serial and 1071 This option enables a configuration with RNDIS, CDC Serial and
@@ -1048,6 +1079,7 @@ config USB_G_MULTI_CDC
1048 bool "CDC Ethernet + CDC Serial + Storage configuration" 1079 bool "CDC Ethernet + CDC Serial + Storage configuration"
1049 depends on USB_G_MULTI 1080 depends on USB_G_MULTI
1050 default n 1081 default n
1082 select USB_F_ECM
1051 help 1083 help
1052 This option enables a configuration with CDC Ethernet (ECM), CDC 1084 This option enables a configuration with CDC Ethernet (ECM), CDC
1053 Serial and Mass Storage functions available in the Multifunction 1085 Serial and Mass Storage functions available in the Multifunction
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 386db9daf1d9..f1af39603d4d 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -1,7 +1,8 @@
1# 1#
2# USB peripheral controller drivers 2# USB peripheral controller drivers
3# 3#
4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG 4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
5ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG
5 6
6obj-$(CONFIG_USB_GADGET) += udc-core.o 7obj-$(CONFIG_USB_GADGET) += udc-core.o
7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 8obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
@@ -60,6 +61,8 @@ usb_f_ecm_subset-y := f_subset.o
60obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o 61obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o
61usb_f_rndis-y := f_rndis.o 62usb_f_rndis-y := f_rndis.o
62obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o 63obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o
64usb_f_mass_storage-y := f_mass_storage.o storage_common.o
65obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
63 66
64# 67#
65# USB gadget drivers 68# USB gadget drivers
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 4b947bb50f62..7bfa134fe0e3 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -31,16 +31,7 @@
31#define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */ 31#define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */
32#define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/ 32#define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/
33 33
34/*-------------------------------------------------------------------------*/ 34#include "f_mass_storage.h"
35
36/*
37 * Kbuild is not very cooperative with respect to linking separately
38 * compiled library objects into one module. So for now we won't use
39 * separate compilation ... ensuring init/exit sections work to shrink
40 * the runtime footprint, and giving us at least some parts of what
41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
42 */
43#include "f_mass_storage.c"
44 35
45/*-------------------------------------------------------------------------*/ 36/*-------------------------------------------------------------------------*/
46USB_GADGET_COMPOSITE_OPTIONS(); 37USB_GADGET_COMPOSITE_OPTIONS();
@@ -104,18 +95,35 @@ static struct usb_gadget_strings *dev_strings[] = {
104/****************************** Configurations ******************************/ 95/****************************** Configurations ******************************/
105 96
106static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; 97static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
107FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); 98#ifdef CONFIG_USB_GADGET_DEBUG_FILES
108 99
109static struct fsg_common fsg_common; 100static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
101
102#else
103
104/*
105 * Number of buffers we will use.
106 * 2 is usually enough for good buffering pipeline
107 */
108#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
109
110#endif /* CONFIG_USB_DEBUG */
111
112FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
110 113
111/*-------------------------------------------------------------------------*/ 114/*-------------------------------------------------------------------------*/
112static struct usb_function *f_acm; 115static struct usb_function *f_acm;
113static struct usb_function_instance *f_acm_inst; 116static struct usb_function_instance *f_acm_inst;
117
118static struct usb_function_instance *fi_msg;
119static struct usb_function *f_msg;
120
114/* 121/*
115 * We _always_ have both ACM and mass storage functions. 122 * We _always_ have both ACM and mass storage functions.
116 */ 123 */
117static int __init acm_ms_do_config(struct usb_configuration *c) 124static int __init acm_ms_do_config(struct usb_configuration *c)
118{ 125{
126 struct fsg_opts *opts;
119 int status; 127 int status;
120 128
121 if (gadget_is_otg(c->cdev->gadget)) { 129 if (gadget_is_otg(c->cdev->gadget)) {
@@ -123,31 +131,37 @@ static int __init acm_ms_do_config(struct usb_configuration *c)
123 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 131 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
124 } 132 }
125 133
126 f_acm_inst = usb_get_function_instance("acm"); 134 opts = fsg_opts_from_func_inst(fi_msg);
127 if (IS_ERR(f_acm_inst))
128 return PTR_ERR(f_acm_inst);
129 135
130 f_acm = usb_get_function(f_acm_inst); 136 f_acm = usb_get_function(f_acm_inst);
131 if (IS_ERR(f_acm)) { 137 if (IS_ERR(f_acm))
132 status = PTR_ERR(f_acm); 138 return PTR_ERR(f_acm);
133 goto err_func; 139
140 f_msg = usb_get_function(fi_msg);
141 if (IS_ERR(f_msg)) {
142 status = PTR_ERR(f_msg);
143 goto put_acm;
134 } 144 }
135 145
136 status = usb_add_function(c, f_acm); 146 status = usb_add_function(c, f_acm);
137 if (status < 0) 147 if (status < 0)
138 goto err_conf; 148 goto put_msg;
139 149
140 status = fsg_bind_config(c->cdev, c, &fsg_common); 150 status = fsg_common_run_thread(opts->common);
141 if (status < 0) 151 if (status)
142 goto err_fsg; 152 goto remove_acm;
153
154 status = usb_add_function(c, f_msg);
155 if (status)
156 goto remove_acm;
143 157
144 return 0; 158 return 0;
145err_fsg: 159remove_acm:
146 usb_remove_function(c, f_acm); 160 usb_remove_function(c, f_acm);
147err_conf: 161put_msg:
162 usb_put_function(f_msg);
163put_acm:
148 usb_put_function(f_acm); 164 usb_put_function(f_acm);
149err_func:
150 usb_put_function_instance(f_acm_inst);
151 return status; 165 return status;
152} 166}
153 167
@@ -163,45 +177,82 @@ static struct usb_configuration acm_ms_config_driver = {
163static int __init acm_ms_bind(struct usb_composite_dev *cdev) 177static int __init acm_ms_bind(struct usb_composite_dev *cdev)
164{ 178{
165 struct usb_gadget *gadget = cdev->gadget; 179 struct usb_gadget *gadget = cdev->gadget;
180 struct fsg_opts *opts;
181 struct fsg_config config;
166 int status; 182 int status;
167 void *retp;
168 183
169 /* set up mass storage function */ 184 f_acm_inst = usb_get_function_instance("acm");
170 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 185 if (IS_ERR(f_acm_inst))
171 if (IS_ERR(retp)) { 186 return PTR_ERR(f_acm_inst);
172 status = PTR_ERR(retp); 187
173 return PTR_ERR(retp); 188 fi_msg = usb_get_function_instance("mass_storage");
189 if (IS_ERR(fi_msg)) {
190 status = PTR_ERR(fi_msg);
191 goto fail_get_msg;
174 } 192 }
175 193
194 /* set up mass storage function */
195 fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers);
196 opts = fsg_opts_from_func_inst(fi_msg);
197
198 opts->no_configfs = true;
199 status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers);
200 if (status)
201 goto fail;
202
203 status = fsg_common_set_nluns(opts->common, config.nluns);
204 if (status)
205 goto fail_set_nluns;
206
207 status = fsg_common_set_cdev(opts->common, cdev, config.can_stall);
208 if (status)
209 goto fail_set_cdev;
210
211 fsg_common_set_sysfs(opts->common, true);
212 status = fsg_common_create_luns(opts->common, &config);
213 if (status)
214 goto fail_set_cdev;
215
216 fsg_common_set_inquiry_string(opts->common, config.vendor_name,
217 config.product_name);
176 /* 218 /*
177 * Allocate string descriptor numbers ... note that string 219 * Allocate string descriptor numbers ... note that string
178 * contents can be overridden by the composite_dev glue. 220 * contents can be overridden by the composite_dev glue.
179 */ 221 */
180 status = usb_string_ids_tab(cdev, strings_dev); 222 status = usb_string_ids_tab(cdev, strings_dev);
181 if (status < 0) 223 if (status < 0)
182 goto fail1; 224 goto fail_string_ids;
183 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; 225 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
184 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 226 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
185 227
186 /* register our configuration */ 228 /* register our configuration */
187 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); 229 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config);
188 if (status < 0) 230 if (status < 0)
189 goto fail1; 231 goto fail_string_ids;
190 232
191 usb_composite_overwrite_options(cdev, &coverwrite); 233 usb_composite_overwrite_options(cdev, &coverwrite);
192 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 234 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
193 DRIVER_DESC); 235 DRIVER_DESC);
194 fsg_common_put(&fsg_common);
195 return 0; 236 return 0;
196 237
197 /* error recovery */ 238 /* error recovery */
198fail1: 239fail_string_ids:
199 fsg_common_put(&fsg_common); 240 fsg_common_remove_luns(opts->common);
241fail_set_cdev:
242 fsg_common_free_luns(opts->common);
243fail_set_nluns:
244 fsg_common_free_buffers(opts->common);
245fail:
246 usb_put_function_instance(fi_msg);
247fail_get_msg:
248 usb_put_function_instance(f_acm_inst);
200 return status; 249 return status;
201} 250}
202 251
203static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) 252static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
204{ 253{
254 usb_put_function(f_msg);
255 usb_put_function_instance(fi_msg);
205 usb_put_function(f_acm); 256 usb_put_function(f_acm);
206 usb_put_function_instance(f_acm_inst); 257 usb_put_function_instance(f_acm_inst);
207 return 0; 258 return 0;
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index a9a4346c83aa..54a1e2954cea 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -3078,8 +3078,6 @@ static void udc_pci_remove(struct pci_dev *pdev)
3078 if (dev->active) 3078 if (dev->active)
3079 pci_disable_device(pdev); 3079 pci_disable_device(pdev);
3080 3080
3081 pci_set_drvdata(pdev, NULL);
3082
3083 udc_remove(dev); 3081 udc_remove(dev);
3084} 3082}
3085 3083
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 5a5acf22c694..e126b6b248e6 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -113,12 +113,6 @@ static int __init cdc_do_config(struct usb_configuration *c)
113 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 113 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
114 } 114 }
115 115
116 fi_ecm = usb_get_function_instance("ecm");
117 if (IS_ERR(fi_ecm)) {
118 status = PTR_ERR(fi_ecm);
119 goto err_func_ecm;
120 }
121
122 f_ecm = usb_get_function(fi_ecm); 116 f_ecm = usb_get_function(fi_ecm);
123 if (IS_ERR(f_ecm)) { 117 if (IS_ERR(f_ecm)) {
124 status = PTR_ERR(f_ecm); 118 status = PTR_ERR(f_ecm);
@@ -129,35 +123,24 @@ static int __init cdc_do_config(struct usb_configuration *c)
129 if (status) 123 if (status)
130 goto err_add_ecm; 124 goto err_add_ecm;
131 125
132 fi_serial = usb_get_function_instance("acm");
133 if (IS_ERR(fi_serial)) {
134 status = PTR_ERR(fi_serial);
135 goto err_get_acm;
136 }
137
138 f_acm = usb_get_function(fi_serial); 126 f_acm = usb_get_function(fi_serial);
139 if (IS_ERR(f_acm)) { 127 if (IS_ERR(f_acm)) {
140 status = PTR_ERR(f_acm); 128 status = PTR_ERR(f_acm);
141 goto err_func_acm; 129 goto err_get_acm;
142 } 130 }
143 131
144 status = usb_add_function(c, f_acm); 132 status = usb_add_function(c, f_acm);
145 if (status) 133 if (status)
146 goto err_add_acm; 134 goto err_add_acm;
147
148 return 0; 135 return 0;
149 136
150err_add_acm: 137err_add_acm:
151 usb_put_function(f_acm); 138 usb_put_function(f_acm);
152err_func_acm:
153 usb_put_function_instance(fi_serial);
154err_get_acm: 139err_get_acm:
155 usb_remove_function(c, f_ecm); 140 usb_remove_function(c, f_ecm);
156err_add_ecm: 141err_add_ecm:
157 usb_put_function(f_ecm); 142 usb_put_function(f_ecm);
158err_get_ecm: 143err_get_ecm:
159 usb_put_function_instance(fi_ecm);
160err_func_ecm:
161 return status; 144 return status;
162} 145}
163 146
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index d4f0f3305759..3e7ae707f691 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -354,7 +354,7 @@ static u8 encode_bMaxPower(enum usb_device_speed speed,
354 return DIV_ROUND_UP(val, 8); 354 return DIV_ROUND_UP(val, 8);
355 default: 355 default:
356 return DIV_ROUND_UP(val, 2); 356 return DIV_ROUND_UP(val, 2);
357 }; 357 }
358} 358}
359 359
360static int config_buf(struct usb_configuration *config, 360static int config_buf(struct usb_configuration *config,
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 8f0d6141e5e6..25885112fa35 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -557,7 +557,7 @@ static struct config_group *function_make(
557 557
558 fi = usb_get_function_instance(func_name); 558 fi = usb_get_function_instance(func_name);
559 if (IS_ERR(fi)) 559 if (IS_ERR(fi))
560 return ERR_PTR(PTR_ERR(fi)); 560 return ERR_CAST(fi);
561 561
562 ret = config_item_set_name(&fi->group.cg_item, name); 562 ret = config_item_set_name(&fi->group.cg_item, name);
563 if (ret) { 563 if (ret) {
@@ -991,6 +991,14 @@ static struct configfs_subsystem gadget_subsys = {
991 .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex), 991 .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex),
992}; 992};
993 993
994void unregister_gadget_item(struct config_item *item)
995{
996 struct gadget_info *gi = to_gadget_info(item);
997
998 unregister_gadget(gi);
999}
1000EXPORT_SYMBOL(unregister_gadget_item);
1001
994static int __init gadget_cfs_init(void) 1002static int __init gadget_cfs_init(void)
995{ 1003{
996 int ret; 1004 int ret;
diff --git a/drivers/usb/gadget/configfs.h b/drivers/usb/gadget/configfs.h
new file mode 100644
index 000000000000..a7b564a913d1
--- /dev/null
+++ b/drivers/usb/gadget/configfs.h
@@ -0,0 +1,6 @@
1#ifndef USB__GADGET__CONFIGFS__H
2#define USB__GADGET__CONFIGFS__H
3
4void unregister_gadget_item(struct config_item *item);
5
6#endif /* USB__GADGET__CONFIGFS__H */
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 06ecd08fd57a..8f4dae310923 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -544,7 +544,7 @@ static int dummy_enable(struct usb_ep *_ep,
544 default: 544 default:
545 val = "ctrl"; 545 val = "ctrl";
546 break; 546 break;
547 }; val; }), 547 } val; }),
548 max, ep->stream_en ? "enabled" : "disabled"); 548 max, ep->stream_en ? "enabled" : "disabled");
549 549
550 /* at this point real hardware should be NAKing transfers 550 /* at this point real hardware should be NAKing transfers
@@ -923,8 +923,9 @@ static int dummy_udc_stop(struct usb_gadget *g,
923 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g); 923 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
924 struct dummy *dum = dum_hcd->dum; 924 struct dummy *dum = dum_hcd->dum;
925 925
926 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n", 926 if (driver)
927 driver->driver.name); 927 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n",
928 driver->driver.name);
928 929
929 dum->driver = NULL; 930 dum->driver = NULL;
930 931
@@ -1000,8 +1001,8 @@ static int dummy_udc_remove(struct platform_device *pdev)
1000{ 1001{
1001 struct dummy *dum = platform_get_drvdata(pdev); 1002 struct dummy *dum = platform_get_drvdata(pdev);
1002 1003
1003 usb_del_gadget_udc(&dum->gadget);
1004 device_remove_file(&dum->gadget.dev, &dev_attr_function); 1004 device_remove_file(&dum->gadget.dev, &dev_attr_function);
1005 usb_del_gadget_udc(&dum->gadget);
1005 return 0; 1006 return 0;
1006} 1007}
1007 1008
@@ -2270,7 +2271,7 @@ static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb)
2270 default: 2271 default:
2271 s = "?"; 2272 s = "?";
2272 break; 2273 break;
2273 }; s; }), 2274 } s; }),
2274 ep, ep ? (usb_pipein(urb->pipe) ? "in" : "out") : "", 2275 ep, ep ? (usb_pipein(urb->pipe) ? "in" : "out") : "",
2275 ({ char *s; \ 2276 ({ char *s; \
2276 switch (usb_pipetype(urb->pipe)) { \ 2277 switch (usb_pipetype(urb->pipe)) { \
@@ -2286,7 +2287,7 @@ static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb)
2286 default: \ 2287 default: \
2287 s = "-iso"; \ 2288 s = "-iso"; \
2288 break; \ 2289 break; \
2289 }; s; }), 2290 } s; }),
2290 urb->actual_length, urb->transfer_buffer_length); 2291 urb->actual_length, urb->transfer_buffer_length);
2291} 2292}
2292 2293
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index edab45da3741..8d9e6f7e8f1a 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -995,7 +995,7 @@ static void ecm_unbind(struct usb_configuration *c, struct usb_function *f)
995 usb_ep_free_request(ecm->notify, ecm->notify_req); 995 usb_ep_free_request(ecm->notify, ecm->notify_req);
996} 996}
997 997
998struct usb_function *ecm_alloc(struct usb_function_instance *fi) 998static struct usb_function *ecm_alloc(struct usb_function_instance *fi)
999{ 999{
1000 struct f_ecm *ecm; 1000 struct f_ecm *ecm;
1001 struct f_ecm_opts *opts; 1001 struct f_ecm_opts *opts;
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index d00392d879db..d61c11d765d0 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -624,7 +624,7 @@ static void eem_unbind(struct usb_configuration *c, struct usb_function *f)
624 usb_free_all_descriptors(f); 624 usb_free_all_descriptors(f);
625} 625}
626 626
627struct usb_function *eem_alloc(struct usb_function_instance *fi) 627static struct usb_function *eem_alloc(struct usb_function_instance *fi)
628{ 628{
629 struct f_eem *eem; 629 struct f_eem *eem;
630 struct f_eem_opts *opts; 630 struct f_eem_opts *opts;
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 1a66c5baa0d1..774e8b89cdb5 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -373,7 +373,7 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
373 if (req->buf == NULL) 373 if (req->buf == NULL)
374 req->buf = (void *)0xDEADBABE; 374 req->buf = (void *)0xDEADBABE;
375 375
376 INIT_COMPLETION(ffs->ep0req_completion); 376 reinit_completion(&ffs->ep0req_completion);
377 377
378 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); 378 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC);
379 if (unlikely(ret < 0)) 379 if (unlikely(ret < 0))
@@ -1034,37 +1034,19 @@ struct ffs_sb_fill_data {
1034 struct ffs_file_perms perms; 1034 struct ffs_file_perms perms;
1035 umode_t root_mode; 1035 umode_t root_mode;
1036 const char *dev_name; 1036 const char *dev_name;
1037 union { 1037 struct ffs_data *ffs_data;
1038 /* set by ffs_fs_mount(), read by ffs_sb_fill() */
1039 void *private_data;
1040 /* set by ffs_sb_fill(), read by ffs_fs_mount */
1041 struct ffs_data *ffs_data;
1042 };
1043}; 1038};
1044 1039
1045static int ffs_sb_fill(struct super_block *sb, void *_data, int silent) 1040static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
1046{ 1041{
1047 struct ffs_sb_fill_data *data = _data; 1042 struct ffs_sb_fill_data *data = _data;
1048 struct inode *inode; 1043 struct inode *inode;
1049 struct ffs_data *ffs; 1044 struct ffs_data *ffs = data->ffs_data;
1050 1045
1051 ENTER(); 1046 ENTER();
1052 1047
1053 /* Initialise data */
1054 ffs = ffs_data_new();
1055 if (unlikely(!ffs))
1056 goto Enomem;
1057
1058 ffs->sb = sb; 1048 ffs->sb = sb;
1059 ffs->dev_name = kstrdup(data->dev_name, GFP_KERNEL); 1049 data->ffs_data = NULL;
1060 if (unlikely(!ffs->dev_name))
1061 goto Enomem;
1062 ffs->file_perms = data->perms;
1063 ffs->private_data = data->private_data;
1064
1065 /* used by the caller of this function */
1066 data->ffs_data = ffs;
1067
1068 sb->s_fs_info = ffs; 1050 sb->s_fs_info = ffs;
1069 sb->s_blocksize = PAGE_CACHE_SIZE; 1051 sb->s_blocksize = PAGE_CACHE_SIZE;
1070 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; 1052 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
@@ -1080,17 +1062,14 @@ static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
1080 &data->perms); 1062 &data->perms);
1081 sb->s_root = d_make_root(inode); 1063 sb->s_root = d_make_root(inode);
1082 if (unlikely(!sb->s_root)) 1064 if (unlikely(!sb->s_root))
1083 goto Enomem; 1065 return -ENOMEM;
1084 1066
1085 /* EP0 file */ 1067 /* EP0 file */
1086 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs, 1068 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs,
1087 &ffs_ep0_operations, NULL))) 1069 &ffs_ep0_operations, NULL)))
1088 goto Enomem; 1070 return -ENOMEM;
1089 1071
1090 return 0; 1072 return 0;
1091
1092Enomem:
1093 return -ENOMEM;
1094} 1073}
1095 1074
1096static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts) 1075static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
@@ -1193,6 +1172,7 @@ ffs_fs_mount(struct file_system_type *t, int flags,
1193 struct dentry *rv; 1172 struct dentry *rv;
1194 int ret; 1173 int ret;
1195 void *ffs_dev; 1174 void *ffs_dev;
1175 struct ffs_data *ffs;
1196 1176
1197 ENTER(); 1177 ENTER();
1198 1178
@@ -1200,18 +1180,30 @@ ffs_fs_mount(struct file_system_type *t, int flags,
1200 if (unlikely(ret < 0)) 1180 if (unlikely(ret < 0))
1201 return ERR_PTR(ret); 1181 return ERR_PTR(ret);
1202 1182
1183 ffs = ffs_data_new();
1184 if (unlikely(!ffs))
1185 return ERR_PTR(-ENOMEM);
1186 ffs->file_perms = data.perms;
1187
1188 ffs->dev_name = kstrdup(dev_name, GFP_KERNEL);
1189 if (unlikely(!ffs->dev_name)) {
1190 ffs_data_put(ffs);
1191 return ERR_PTR(-ENOMEM);
1192 }
1193
1203 ffs_dev = functionfs_acquire_dev_callback(dev_name); 1194 ffs_dev = functionfs_acquire_dev_callback(dev_name);
1204 if (IS_ERR(ffs_dev)) 1195 if (IS_ERR(ffs_dev)) {
1205 return ffs_dev; 1196 ffs_data_put(ffs);
1197 return ERR_CAST(ffs_dev);
1198 }
1199 ffs->private_data = ffs_dev;
1200 data.ffs_data = ffs;
1206 1201
1207 data.dev_name = dev_name;
1208 data.private_data = ffs_dev;
1209 rv = mount_nodev(t, flags, &data, ffs_sb_fill); 1202 rv = mount_nodev(t, flags, &data, ffs_sb_fill);
1210 1203 if (IS_ERR(rv) && data.ffs_data) {
1211 /* data.ffs_data is set by ffs_sb_fill */
1212 if (IS_ERR(rv))
1213 functionfs_release_dev_callback(data.ffs_data); 1204 functionfs_release_dev_callback(data.ffs_data);
1214 1205 ffs_data_put(data.ffs_data);
1206 }
1215 return rv; 1207 return rv;
1216} 1208}
1217 1209
@@ -2264,6 +2256,8 @@ static int ffs_func_bind(struct usb_configuration *c,
2264 data->raw_descs + ret, 2256 data->raw_descs + ret,
2265 (sizeof data->raw_descs) - ret, 2257 (sizeof data->raw_descs) - ret,
2266 __ffs_func_bind_do_descs, func); 2258 __ffs_func_bind_do_descs, func);
2259 if (unlikely(ret < 0))
2260 goto error;
2267 } 2261 }
2268 2262
2269 /* 2263 /*
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 313b835eedfd..a03ba2c83589 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -213,12 +213,14 @@
213#include <linux/spinlock.h> 213#include <linux/spinlock.h>
214#include <linux/string.h> 214#include <linux/string.h>
215#include <linux/freezer.h> 215#include <linux/freezer.h>
216#include <linux/module.h>
216 217
217#include <linux/usb/ch9.h> 218#include <linux/usb/ch9.h>
218#include <linux/usb/gadget.h> 219#include <linux/usb/gadget.h>
219#include <linux/usb/composite.h> 220#include <linux/usb/composite.h>
220 221
221#include "gadget_chips.h" 222#include "gadget_chips.h"
223#include "configfs.h"
222 224
223 225
224/*------------------------------------------------------------------------*/ 226/*------------------------------------------------------------------------*/
@@ -228,26 +230,30 @@
228 230
229static const char fsg_string_interface[] = "Mass Storage"; 231static const char fsg_string_interface[] = "Mass Storage";
230 232
231#include "storage_common.c" 233#include "storage_common.h"
234#include "f_mass_storage.h"
232 235
236/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
237static struct usb_string fsg_strings[] = {
238 {FSG_STRING_INTERFACE, fsg_string_interface},
239 {}
240};
241
242static struct usb_gadget_strings fsg_stringtab = {
243 .language = 0x0409, /* en-us */
244 .strings = fsg_strings,
245};
246
247static struct usb_gadget_strings *fsg_strings_array[] = {
248 &fsg_stringtab,
249 NULL,
250};
233 251
234/*-------------------------------------------------------------------------*/ 252/*-------------------------------------------------------------------------*/
235 253
236struct fsg_dev; 254struct fsg_dev;
237struct fsg_common; 255struct fsg_common;
238 256
239/* FSF callback functions */
240struct fsg_operations {
241 /*
242 * Callback function to call when thread exits. If no
243 * callback is set or it returns value lower then zero MSF
244 * will force eject all LUNs it operates on (including those
245 * marked as non-removable or with prevent_medium_removal flag
246 * set).
247 */
248 int (*thread_exits)(struct fsg_common *common);
249};
250
251/* Data shared by all the FSG instances. */ 257/* Data shared by all the FSG instances. */
252struct fsg_common { 258struct fsg_common {
253 struct usb_gadget *gadget; 259 struct usb_gadget *gadget;
@@ -268,13 +274,14 @@ struct fsg_common {
268 struct fsg_buffhd *next_buffhd_to_fill; 274 struct fsg_buffhd *next_buffhd_to_fill;
269 struct fsg_buffhd *next_buffhd_to_drain; 275 struct fsg_buffhd *next_buffhd_to_drain;
270 struct fsg_buffhd *buffhds; 276 struct fsg_buffhd *buffhds;
277 unsigned int fsg_num_buffers;
271 278
272 int cmnd_size; 279 int cmnd_size;
273 u8 cmnd[MAX_COMMAND_SIZE]; 280 u8 cmnd[MAX_COMMAND_SIZE];
274 281
275 unsigned int nluns; 282 unsigned int nluns;
276 unsigned int lun; 283 unsigned int lun;
277 struct fsg_lun *luns; 284 struct fsg_lun **luns;
278 struct fsg_lun *curlun; 285 struct fsg_lun *curlun;
279 286
280 unsigned int bulk_out_maxpacket; 287 unsigned int bulk_out_maxpacket;
@@ -294,6 +301,7 @@ struct fsg_common {
294 unsigned int short_packet_received:1; 301 unsigned int short_packet_received:1;
295 unsigned int bad_lun_okay:1; 302 unsigned int bad_lun_okay:1;
296 unsigned int running:1; 303 unsigned int running:1;
304 unsigned int sysfs:1;
297 305
298 int thread_wakeup_needed; 306 int thread_wakeup_needed;
299 struct completion thread_notifier; 307 struct completion thread_notifier;
@@ -313,27 +321,6 @@ struct fsg_common {
313 struct kref ref; 321 struct kref ref;
314}; 322};
315 323
316struct fsg_config {
317 unsigned nluns;
318 struct fsg_lun_config {
319 const char *filename;
320 char ro;
321 char removable;
322 char cdrom;
323 char nofua;
324 } luns[FSG_MAX_LUNS];
325
326 /* Callback functions. */
327 const struct fsg_operations *ops;
328 /* Gadget's private data. */
329 void *private_data;
330
331 const char *vendor_name; /* 8 characters or less */
332 const char *product_name; /* 16 characters or less */
333
334 char can_stall;
335};
336
337struct fsg_dev { 324struct fsg_dev {
338 struct usb_function function; 325 struct usb_function function;
339 struct usb_gadget *gadget; /* Copy of cdev->gadget */ 326 struct usb_gadget *gadget; /* Copy of cdev->gadget */
@@ -2172,7 +2159,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2172 common->data_dir = DATA_DIR_NONE; 2159 common->data_dir = DATA_DIR_NONE;
2173 common->lun = cbw->Lun; 2160 common->lun = cbw->Lun;
2174 if (common->lun < common->nluns) 2161 if (common->lun < common->nluns)
2175 common->curlun = &common->luns[common->lun]; 2162 common->curlun = common->luns[common->lun];
2176 else 2163 else
2177 common->curlun = NULL; 2164 common->curlun = NULL;
2178 common->tag = cbw->Tag; 2165 common->tag = cbw->Tag;
@@ -2244,7 +2231,7 @@ reset:
2244 if (common->fsg) { 2231 if (common->fsg) {
2245 fsg = common->fsg; 2232 fsg = common->fsg;
2246 2233
2247 for (i = 0; i < fsg_num_buffers; ++i) { 2234 for (i = 0; i < common->fsg_num_buffers; ++i) {
2248 struct fsg_buffhd *bh = &common->buffhds[i]; 2235 struct fsg_buffhd *bh = &common->buffhds[i];
2249 2236
2250 if (bh->inreq) { 2237 if (bh->inreq) {
@@ -2260,10 +2247,12 @@ reset:
2260 /* Disable the endpoints */ 2247 /* Disable the endpoints */
2261 if (fsg->bulk_in_enabled) { 2248 if (fsg->bulk_in_enabled) {
2262 usb_ep_disable(fsg->bulk_in); 2249 usb_ep_disable(fsg->bulk_in);
2250 fsg->bulk_in->driver_data = NULL;
2263 fsg->bulk_in_enabled = 0; 2251 fsg->bulk_in_enabled = 0;
2264 } 2252 }
2265 if (fsg->bulk_out_enabled) { 2253 if (fsg->bulk_out_enabled) {
2266 usb_ep_disable(fsg->bulk_out); 2254 usb_ep_disable(fsg->bulk_out);
2255 fsg->bulk_out->driver_data = NULL;
2267 fsg->bulk_out_enabled = 0; 2256 fsg->bulk_out_enabled = 0;
2268 } 2257 }
2269 2258
@@ -2301,7 +2290,7 @@ reset:
2301 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2290 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2302 2291
2303 /* Allocate the requests */ 2292 /* Allocate the requests */
2304 for (i = 0; i < fsg_num_buffers; ++i) { 2293 for (i = 0; i < common->fsg_num_buffers; ++i) {
2305 struct fsg_buffhd *bh = &common->buffhds[i]; 2294 struct fsg_buffhd *bh = &common->buffhds[i];
2306 2295
2307 rc = alloc_request(common, fsg->bulk_in, &bh->inreq); 2296 rc = alloc_request(common, fsg->bulk_in, &bh->inreq);
@@ -2318,7 +2307,9 @@ reset:
2318 2307
2319 common->running = 1; 2308 common->running = 1;
2320 for (i = 0; i < common->nluns; ++i) 2309 for (i = 0; i < common->nluns; ++i)
2321 common->luns[i].unit_attention_data = SS_RESET_OCCURRED; 2310 if (common->luns[i])
2311 common->luns[i]->unit_attention_data =
2312 SS_RESET_OCCURRED;
2322 return rc; 2313 return rc;
2323} 2314}
2324 2315
@@ -2370,7 +2361,7 @@ static void handle_exception(struct fsg_common *common)
2370 2361
2371 /* Cancel all the pending transfers */ 2362 /* Cancel all the pending transfers */
2372 if (likely(common->fsg)) { 2363 if (likely(common->fsg)) {
2373 for (i = 0; i < fsg_num_buffers; ++i) { 2364 for (i = 0; i < common->fsg_num_buffers; ++i) {
2374 bh = &common->buffhds[i]; 2365 bh = &common->buffhds[i];
2375 if (bh->inreq_busy) 2366 if (bh->inreq_busy)
2376 usb_ep_dequeue(common->fsg->bulk_in, bh->inreq); 2367 usb_ep_dequeue(common->fsg->bulk_in, bh->inreq);
@@ -2382,7 +2373,7 @@ static void handle_exception(struct fsg_common *common)
2382 /* Wait until everything is idle */ 2373 /* Wait until everything is idle */
2383 for (;;) { 2374 for (;;) {
2384 int num_active = 0; 2375 int num_active = 0;
2385 for (i = 0; i < fsg_num_buffers; ++i) { 2376 for (i = 0; i < common->fsg_num_buffers; ++i) {
2386 bh = &common->buffhds[i]; 2377 bh = &common->buffhds[i];
2387 num_active += bh->inreq_busy + bh->outreq_busy; 2378 num_active += bh->inreq_busy + bh->outreq_busy;
2388 } 2379 }
@@ -2405,7 +2396,7 @@ static void handle_exception(struct fsg_common *common)
2405 */ 2396 */
2406 spin_lock_irq(&common->lock); 2397 spin_lock_irq(&common->lock);
2407 2398
2408 for (i = 0; i < fsg_num_buffers; ++i) { 2399 for (i = 0; i < common->fsg_num_buffers; ++i) {
2409 bh = &common->buffhds[i]; 2400 bh = &common->buffhds[i];
2410 bh->state = BUF_STATE_EMPTY; 2401 bh->state = BUF_STATE_EMPTY;
2411 } 2402 }
@@ -2418,7 +2409,9 @@ static void handle_exception(struct fsg_common *common)
2418 common->state = FSG_STATE_STATUS_PHASE; 2409 common->state = FSG_STATE_STATUS_PHASE;
2419 else { 2410 else {
2420 for (i = 0; i < common->nluns; ++i) { 2411 for (i = 0; i < common->nluns; ++i) {
2421 curlun = &common->luns[i]; 2412 curlun = common->luns[i];
2413 if (!curlun)
2414 continue;
2422 curlun->prevent_medium_removal = 0; 2415 curlun->prevent_medium_removal = 0;
2423 curlun->sense_data = SS_NO_SENSE; 2416 curlun->sense_data = SS_NO_SENSE;
2424 curlun->unit_attention_data = SS_NO_SENSE; 2417 curlun->unit_attention_data = SS_NO_SENSE;
@@ -2460,8 +2453,9 @@ static void handle_exception(struct fsg_common *common)
2460 * CONFIG_CHANGE cases. 2453 * CONFIG_CHANGE cases.
2461 */ 2454 */
2462 /* for (i = 0; i < common->nluns; ++i) */ 2455 /* for (i = 0; i < common->nluns; ++i) */
2463 /* common->luns[i].unit_attention_data = */ 2456 /* if (common->luns[i]) */
2464 /* SS_RESET_OCCURRED; */ 2457 /* common->luns[i]->unit_attention_data = */
2458 /* SS_RESET_OCCURRED; */
2465 break; 2459 break;
2466 2460
2467 case FSG_STATE_CONFIG_CHANGE: 2461 case FSG_STATE_CONFIG_CHANGE:
@@ -2557,12 +2551,13 @@ static int fsg_main_thread(void *common_)
2557 2551
2558 if (!common->ops || !common->ops->thread_exits 2552 if (!common->ops || !common->ops->thread_exits
2559 || common->ops->thread_exits(common) < 0) { 2553 || common->ops->thread_exits(common) < 0) {
2560 struct fsg_lun *curlun = common->luns; 2554 struct fsg_lun **curlun_it = common->luns;
2561 unsigned i = common->nluns; 2555 unsigned i = common->nluns;
2562 2556
2563 down_write(&common->filesem); 2557 down_write(&common->filesem);
2564 for (; i--; ++curlun) { 2558 for (; i--; ++curlun_it) {
2565 if (!fsg_lun_is_open(curlun)) 2559 struct fsg_lun *curlun = *curlun_it;
2560 if (!curlun || !fsg_lun_is_open(curlun))
2566 continue; 2561 continue;
2567 2562
2568 fsg_lun_close(curlun); 2563 fsg_lun_close(curlun);
@@ -2578,6 +2573,56 @@ static int fsg_main_thread(void *common_)
2578 2573
2579/*************************** DEVICE ATTRIBUTES ***************************/ 2574/*************************** DEVICE ATTRIBUTES ***************************/
2580 2575
2576static ssize_t ro_show(struct device *dev, struct device_attribute *attr, char *buf)
2577{
2578 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2579
2580 return fsg_show_ro(curlun, buf);
2581}
2582
2583static ssize_t nofua_show(struct device *dev, struct device_attribute *attr,
2584 char *buf)
2585{
2586 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2587
2588 return fsg_show_nofua(curlun, buf);
2589}
2590
2591static ssize_t file_show(struct device *dev, struct device_attribute *attr,
2592 char *buf)
2593{
2594 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2595 struct rw_semaphore *filesem = dev_get_drvdata(dev);
2596
2597 return fsg_show_file(curlun, filesem, buf);
2598}
2599
2600static ssize_t ro_store(struct device *dev, struct device_attribute *attr,
2601 const char *buf, size_t count)
2602{
2603 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2604 struct rw_semaphore *filesem = dev_get_drvdata(dev);
2605
2606 return fsg_store_ro(curlun, filesem, buf, count);
2607}
2608
2609static ssize_t nofua_store(struct device *dev, struct device_attribute *attr,
2610 const char *buf, size_t count)
2611{
2612 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2613
2614 return fsg_store_nofua(curlun, buf, count);
2615}
2616
2617static ssize_t file_store(struct device *dev, struct device_attribute *attr,
2618 const char *buf, size_t count)
2619{
2620 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2621 struct rw_semaphore *filesem = dev_get_drvdata(dev);
2622
2623 return fsg_store_file(curlun, filesem, buf, count);
2624}
2625
2581static DEVICE_ATTR_RW(ro); 2626static DEVICE_ATTR_RW(ro);
2582static DEVICE_ATTR_RW(nofua); 2627static DEVICE_ATTR_RW(nofua);
2583static DEVICE_ATTR_RW(file); 2628static DEVICE_ATTR_RW(file);
@@ -2595,221 +2640,422 @@ static void fsg_lun_release(struct device *dev)
2595 /* Nothing needs to be done */ 2640 /* Nothing needs to be done */
2596} 2641}
2597 2642
2598static inline void fsg_common_get(struct fsg_common *common) 2643void fsg_common_get(struct fsg_common *common)
2599{ 2644{
2600 kref_get(&common->ref); 2645 kref_get(&common->ref);
2601} 2646}
2647EXPORT_SYMBOL_GPL(fsg_common_get);
2602 2648
2603static inline void fsg_common_put(struct fsg_common *common) 2649void fsg_common_put(struct fsg_common *common)
2604{ 2650{
2605 kref_put(&common->ref, fsg_common_release); 2651 kref_put(&common->ref, fsg_common_release);
2606} 2652}
2653EXPORT_SYMBOL_GPL(fsg_common_put);
2607 2654
2608static struct fsg_common *fsg_common_init(struct fsg_common *common, 2655/* check if fsg_num_buffers is within a valid range */
2609 struct usb_composite_dev *cdev, 2656static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
2610 struct fsg_config *cfg)
2611{ 2657{
2612 struct usb_gadget *gadget = cdev->gadget; 2658 if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4)
2613 struct fsg_buffhd *bh; 2659 return 0;
2614 struct fsg_lun *curlun; 2660 pr_err("fsg_num_buffers %u is out of range (%d to %d)\n",
2615 struct fsg_lun_config *lcfg; 2661 fsg_num_buffers, 2, 4);
2616 int nluns, i, rc; 2662 return -EINVAL;
2617 char *pathbuf; 2663}
2618
2619 rc = fsg_num_buffers_validate();
2620 if (rc != 0)
2621 return ERR_PTR(rc);
2622
2623 /* Find out how many LUNs there should be */
2624 nluns = cfg->nluns;
2625 if (nluns < 1 || nluns > FSG_MAX_LUNS) {
2626 dev_err(&gadget->dev, "invalid number of LUNs: %u\n", nluns);
2627 return ERR_PTR(-EINVAL);
2628 }
2629 2664
2630 /* Allocate? */ 2665static struct fsg_common *fsg_common_setup(struct fsg_common *common)
2666{
2631 if (!common) { 2667 if (!common) {
2632 common = kzalloc(sizeof *common, GFP_KERNEL); 2668 common = kzalloc(sizeof(*common), GFP_KERNEL);
2633 if (!common) 2669 if (!common)
2634 return ERR_PTR(-ENOMEM); 2670 return ERR_PTR(-ENOMEM);
2635 common->free_storage_on_release = 1; 2671 common->free_storage_on_release = 1;
2636 } else { 2672 } else {
2637 memset(common, 0, sizeof *common);
2638 common->free_storage_on_release = 0; 2673 common->free_storage_on_release = 0;
2639 } 2674 }
2675 init_rwsem(&common->filesem);
2676 spin_lock_init(&common->lock);
2677 kref_init(&common->ref);
2678 init_completion(&common->thread_notifier);
2679 init_waitqueue_head(&common->fsg_wait);
2680 common->state = FSG_STATE_TERMINATED;
2640 2681
2641 common->buffhds = kcalloc(fsg_num_buffers, 2682 return common;
2642 sizeof *(common->buffhds), GFP_KERNEL); 2683}
2643 if (!common->buffhds) { 2684
2644 if (common->free_storage_on_release) 2685void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs)
2645 kfree(common); 2686{
2646 return ERR_PTR(-ENOMEM); 2687 common->sysfs = sysfs;
2688}
2689EXPORT_SYMBOL_GPL(fsg_common_set_sysfs);
2690
2691static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
2692{
2693 if (buffhds) {
2694 struct fsg_buffhd *bh = buffhds;
2695 while (n--) {
2696 kfree(bh->buf);
2697 ++bh;
2698 }
2699 kfree(buffhds);
2647 } 2700 }
2701}
2648 2702
2649 common->ops = cfg->ops; 2703int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
2650 common->private_data = cfg->private_data; 2704{
2705 struct fsg_buffhd *bh, *buffhds;
2706 int i, rc;
2651 2707
2652 common->gadget = gadget; 2708 rc = fsg_num_buffers_validate(n);
2653 common->ep0 = gadget->ep0; 2709 if (rc != 0)
2654 common->ep0req = cdev->req; 2710 return rc;
2655 common->cdev = cdev; 2711
2712 buffhds = kcalloc(n, sizeof(*buffhds), GFP_KERNEL);
2713 if (!buffhds)
2714 return -ENOMEM;
2656 2715
2657 /* Maybe allocate device-global string IDs, and patch descriptors */ 2716 /* Data buffers cyclic list */
2658 if (fsg_strings[FSG_STRING_INTERFACE].id == 0) { 2717 bh = buffhds;
2659 rc = usb_string_id(cdev); 2718 i = n;
2660 if (unlikely(rc < 0)) 2719 goto buffhds_first_it;
2720 do {
2721 bh->next = bh + 1;
2722 ++bh;
2723buffhds_first_it:
2724 bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
2725 if (unlikely(!bh->buf))
2661 goto error_release; 2726 goto error_release;
2662 fsg_strings[FSG_STRING_INTERFACE].id = rc; 2727 } while (--i);
2663 fsg_intf_desc.iInterface = rc; 2728 bh->next = buffhds;
2664 }
2665 2729
2730 _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
2731 common->fsg_num_buffers = n;
2732 common->buffhds = buffhds;
2733
2734 return 0;
2735
2736error_release:
2666 /* 2737 /*
2667 * Create the LUNs, open their backing files, and register the 2738 * "buf"s pointed to by heads after n - i are NULL
2668 * LUN devices in sysfs. 2739 * so releasing them won't hurt
2669 */ 2740 */
2670 curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL); 2741 _fsg_common_free_buffers(buffhds, n);
2671 if (unlikely(!curlun)) { 2742
2672 rc = -ENOMEM; 2743 return -ENOMEM;
2673 goto error_release; 2744}
2745EXPORT_SYMBOL_GPL(fsg_common_set_num_buffers);
2746
2747static inline void fsg_common_remove_sysfs(struct fsg_lun *lun)
2748{
2749 device_remove_file(&lun->dev, &dev_attr_nofua);
2750 /*
2751 * device_remove_file() =>
2752 *
2753 * here the attr (e.g. dev_attr_ro) is only used to be passed to:
2754 *
2755 * sysfs_remove_file() =>
2756 *
2757 * here e.g. both dev_attr_ro_cdrom and dev_attr_ro are in
2758 * the same namespace and
2759 * from here only attr->name is passed to:
2760 *
2761 * sysfs_hash_and_remove()
2762 *
2763 * attr->name is the same for dev_attr_ro_cdrom and
2764 * dev_attr_ro
2765 * attr->name is the same for dev_attr_file and
2766 * dev_attr_file_nonremovable
2767 *
2768 * so we don't differentiate between removing e.g. dev_attr_ro_cdrom
2769 * and dev_attr_ro
2770 */
2771 device_remove_file(&lun->dev, &dev_attr_ro);
2772 device_remove_file(&lun->dev, &dev_attr_file);
2773}
2774
2775void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs)
2776{
2777 if (sysfs) {
2778 fsg_common_remove_sysfs(lun);
2779 device_unregister(&lun->dev);
2674 } 2780 }
2675 common->luns = curlun; 2781 fsg_lun_close(lun);
2782 kfree(lun);
2783}
2784EXPORT_SYMBOL_GPL(fsg_common_remove_lun);
2676 2785
2677 init_rwsem(&common->filesem); 2786static void _fsg_common_remove_luns(struct fsg_common *common, int n)
2787{
2788 int i;
2678 2789
2679 for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun, ++lcfg) { 2790 for (i = 0; i < n; ++i)
2680 curlun->cdrom = !!lcfg->cdrom; 2791 if (common->luns[i]) {
2681 curlun->ro = lcfg->cdrom || lcfg->ro; 2792 fsg_common_remove_lun(common->luns[i], common->sysfs);
2682 curlun->initially_ro = curlun->ro; 2793 common->luns[i] = NULL;
2683 curlun->removable = lcfg->removable;
2684 curlun->dev.release = fsg_lun_release;
2685 curlun->dev.parent = &gadget->dev;
2686 /* curlun->dev.driver = &fsg_driver.driver; XXX */
2687 dev_set_drvdata(&curlun->dev, &common->filesem);
2688 dev_set_name(&curlun->dev, "lun%d", i);
2689
2690 rc = device_register(&curlun->dev);
2691 if (rc) {
2692 INFO(common, "failed to register LUN%d: %d\n", i, rc);
2693 common->nluns = i;
2694 put_device(&curlun->dev);
2695 goto error_release;
2696 } 2794 }
2795}
2796EXPORT_SYMBOL_GPL(fsg_common_remove_luns);
2697 2797
2698 rc = device_create_file(&curlun->dev, 2798void fsg_common_remove_luns(struct fsg_common *common)
2699 curlun->cdrom 2799{
2700 ? &dev_attr_ro_cdrom 2800 _fsg_common_remove_luns(common, common->nluns);
2701 : &dev_attr_ro); 2801}
2702 if (rc)
2703 goto error_luns;
2704 rc = device_create_file(&curlun->dev,
2705 curlun->removable
2706 ? &dev_attr_file
2707 : &dev_attr_file_nonremovable);
2708 if (rc)
2709 goto error_luns;
2710 rc = device_create_file(&curlun->dev, &dev_attr_nofua);
2711 if (rc)
2712 goto error_luns;
2713 2802
2714 if (lcfg->filename) { 2803void fsg_common_free_luns(struct fsg_common *common)
2715 rc = fsg_lun_open(curlun, lcfg->filename); 2804{
2716 if (rc) 2805 fsg_common_remove_luns(common);
2717 goto error_luns; 2806 kfree(common->luns);
2718 } else if (!curlun->removable) { 2807 common->luns = NULL;
2719 ERROR(common, "no file given for LUN%d\n", i); 2808}
2720 rc = -EINVAL; 2809EXPORT_SYMBOL_GPL(fsg_common_free_luns);
2721 goto error_luns; 2810
2722 } 2811int fsg_common_set_nluns(struct fsg_common *common, int nluns)
2812{
2813 struct fsg_lun **curlun;
2814
2815 /* Find out how many LUNs there should be */
2816 if (nluns < 1 || nluns > FSG_MAX_LUNS) {
2817 pr_err("invalid number of LUNs: %u\n", nluns);
2818 return -EINVAL;
2723 } 2819 }
2820
2821 curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL);
2822 if (unlikely(!curlun))
2823 return -ENOMEM;
2824
2825 if (common->luns)
2826 fsg_common_free_luns(common);
2827
2828 common->luns = curlun;
2724 common->nluns = nluns; 2829 common->nluns = nluns;
2725 2830
2726 /* Data buffers cyclic list */ 2831 pr_info("Number of LUNs=%d\n", common->nluns);
2727 bh = common->buffhds;
2728 i = fsg_num_buffers;
2729 goto buffhds_first_it;
2730 do {
2731 bh->next = bh + 1;
2732 ++bh;
2733buffhds_first_it:
2734 bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
2735 if (unlikely(!bh->buf)) {
2736 rc = -ENOMEM;
2737 goto error_release;
2738 }
2739 } while (--i);
2740 bh->next = common->buffhds;
2741 2832
2742 /* Prepare inquiryString */ 2833 return 0;
2743 i = get_default_bcdDevice(); 2834}
2744 snprintf(common->inquiry_string, sizeof common->inquiry_string, 2835EXPORT_SYMBOL_GPL(fsg_common_set_nluns);
2745 "%-8s%-16s%04x", cfg->vendor_name ?: "Linux", 2836
2746 /* Assume product name dependent on the first LUN */ 2837void fsg_common_set_ops(struct fsg_common *common,
2747 cfg->product_name ?: (common->luns->cdrom 2838 const struct fsg_operations *ops)
2748 ? "File-CD Gadget" 2839{
2749 : "File-Stor Gadget"), 2840 common->ops = ops;
2750 i); 2841}
2842EXPORT_SYMBOL_GPL(fsg_common_set_ops);
2843
2844void fsg_common_free_buffers(struct fsg_common *common)
2845{
2846 _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
2847 common->buffhds = NULL;
2848}
2849EXPORT_SYMBOL_GPL(fsg_common_free_buffers);
2850
2851int fsg_common_set_cdev(struct fsg_common *common,
2852 struct usb_composite_dev *cdev, bool can_stall)
2853{
2854 struct usb_string *us;
2855
2856 common->gadget = cdev->gadget;
2857 common->ep0 = cdev->gadget->ep0;
2858 common->ep0req = cdev->req;
2859 common->cdev = cdev;
2860
2861 us = usb_gstrings_attach(cdev, fsg_strings_array,
2862 ARRAY_SIZE(fsg_strings));
2863 if (IS_ERR(us))
2864 return PTR_ERR(us);
2865
2866 fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id;
2751 2867
2752 /* 2868 /*
2753 * Some peripheral controllers are known not to be able to 2869 * Some peripheral controllers are known not to be able to
2754 * halt bulk endpoints correctly. If one of them is present, 2870 * halt bulk endpoints correctly. If one of them is present,
2755 * disable stalls. 2871 * disable stalls.
2756 */ 2872 */
2757 common->can_stall = cfg->can_stall && 2873 common->can_stall = can_stall && !(gadget_is_at91(common->gadget));
2758 !(gadget_is_at91(common->gadget));
2759 2874
2760 spin_lock_init(&common->lock); 2875 return 0;
2761 kref_init(&common->ref); 2876}
2877EXPORT_SYMBOL_GPL(fsg_common_set_cdev);
2762 2878
2763 /* Tell the thread to start working */ 2879static inline int fsg_common_add_sysfs(struct fsg_common *common,
2764 common->thread_task = 2880 struct fsg_lun *lun)
2765 kthread_create(fsg_main_thread, common, "file-storage"); 2881{
2766 if (IS_ERR(common->thread_task)) { 2882 int rc;
2767 rc = PTR_ERR(common->thread_task); 2883
2768 goto error_release; 2884 rc = device_register(&lun->dev);
2885 if (rc) {
2886 put_device(&lun->dev);
2887 return rc;
2769 } 2888 }
2770 init_completion(&common->thread_notifier);
2771 init_waitqueue_head(&common->fsg_wait);
2772 2889
2773 /* Information */ 2890 rc = device_create_file(&lun->dev,
2774 INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); 2891 lun->cdrom
2775 INFO(common, "Number of LUNs=%d\n", common->nluns); 2892 ? &dev_attr_ro_cdrom
2893 : &dev_attr_ro);
2894 if (rc)
2895 goto error;
2896 rc = device_create_file(&lun->dev,
2897 lun->removable
2898 ? &dev_attr_file
2899 : &dev_attr_file_nonremovable);
2900 if (rc)
2901 goto error;
2902 rc = device_create_file(&lun->dev, &dev_attr_nofua);
2903 if (rc)
2904 goto error;
2905
2906 return 0;
2907
2908error:
2909 /* removing nonexistent files is a no-op */
2910 fsg_common_remove_sysfs(lun);
2911 device_unregister(&lun->dev);
2912 return rc;
2913}
2914
2915int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
2916 unsigned int id, const char *name,
2917 const char **name_pfx)
2918{
2919 struct fsg_lun *lun;
2920 char *pathbuf, *p;
2921 int rc = -ENOMEM;
2922
2923 if (!common->nluns || !common->luns)
2924 return -ENODEV;
2925
2926 if (common->luns[id])
2927 return -EBUSY;
2928
2929 if (!cfg->filename && !cfg->removable) {
2930 pr_err("no file given for LUN%d\n", id);
2931 return -EINVAL;
2932 }
2933
2934 lun = kzalloc(sizeof(*lun), GFP_KERNEL);
2935 if (!lun)
2936 return -ENOMEM;
2937
2938 lun->name_pfx = name_pfx;
2939
2940 lun->cdrom = !!cfg->cdrom;
2941 lun->ro = cfg->cdrom || cfg->ro;
2942 lun->initially_ro = lun->ro;
2943 lun->removable = !!cfg->removable;
2944
2945 if (!common->sysfs) {
2946 /* we DON'T own the name!*/
2947 lun->name = name;
2948 } else {
2949 lun->dev.release = fsg_lun_release;
2950 lun->dev.parent = &common->gadget->dev;
2951 dev_set_drvdata(&lun->dev, &common->filesem);
2952 dev_set_name(&lun->dev, "%s", name);
2953 lun->name = dev_name(&lun->dev);
2954
2955 rc = fsg_common_add_sysfs(common, lun);
2956 if (rc) {
2957 pr_info("failed to register LUN%d: %d\n", id, rc);
2958 goto error_sysfs;
2959 }
2960 }
2961
2962 common->luns[id] = lun;
2963
2964 if (cfg->filename) {
2965 rc = fsg_lun_open(lun, cfg->filename);
2966 if (rc)
2967 goto error_lun;
2968 }
2776 2969
2777 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); 2970 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
2778 for (i = 0, nluns = common->nluns, curlun = common->luns; 2971 p = "(no medium)";
2779 i < nluns; 2972 if (fsg_lun_is_open(lun)) {
2780 ++curlun, ++i) { 2973 p = "(error)";
2781 char *p = "(no medium)"; 2974 if (pathbuf) {
2782 if (fsg_lun_is_open(curlun)) { 2975 p = d_path(&lun->filp->f_path, pathbuf, PATH_MAX);
2783 p = "(error)"; 2976 if (IS_ERR(p))
2784 if (pathbuf) { 2977 p = "(error)";
2785 p = d_path(&curlun->filp->f_path,
2786 pathbuf, PATH_MAX);
2787 if (IS_ERR(p))
2788 p = "(error)";
2789 }
2790 } 2978 }
2791 LINFO(curlun, "LUN: %s%s%sfile: %s\n",
2792 curlun->removable ? "removable " : "",
2793 curlun->ro ? "read only " : "",
2794 curlun->cdrom ? "CD-ROM " : "",
2795 p);
2796 } 2979 }
2980 pr_info("LUN: %s%s%sfile: %s\n",
2981 lun->removable ? "removable " : "",
2982 lun->ro ? "read only " : "",
2983 lun->cdrom ? "CD-ROM " : "",
2984 p);
2797 kfree(pathbuf); 2985 kfree(pathbuf);
2798 2986
2987 return 0;
2988
2989error_lun:
2990 if (common->sysfs) {
2991 fsg_common_remove_sysfs(lun);
2992 device_unregister(&lun->dev);
2993 }
2994 fsg_lun_close(lun);
2995 common->luns[id] = NULL;
2996error_sysfs:
2997 kfree(lun);
2998 return rc;
2999}
3000EXPORT_SYMBOL_GPL(fsg_common_create_lun);
3001
3002int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg)
3003{
3004 char buf[8]; /* enough for 100000000 different numbers, decimal */
3005 int i, rc;
3006
3007 for (i = 0; i < common->nluns; ++i) {
3008 snprintf(buf, sizeof(buf), "lun%d", i);
3009 rc = fsg_common_create_lun(common, &cfg->luns[i], i, buf, NULL);
3010 if (rc)
3011 goto fail;
3012 }
3013
3014 pr_info("Number of LUNs=%d\n", common->nluns);
3015
3016 return 0;
3017
3018fail:
3019 _fsg_common_remove_luns(common, i);
3020 return rc;
3021}
3022EXPORT_SYMBOL_GPL(fsg_common_create_luns);
3023
3024void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
3025 const char *pn)
3026{
3027 int i;
3028
3029 /* Prepare inquiryString */
3030 i = get_default_bcdDevice();
3031 snprintf(common->inquiry_string, sizeof(common->inquiry_string),
3032 "%-8s%-16s%04x", vn ?: "Linux",
3033 /* Assume product name dependent on the first LUN */
3034 pn ?: ((*common->luns)->cdrom
3035 ? "File-CD Gadget"
3036 : "File-Stor Gadget"),
3037 i);
3038}
3039EXPORT_SYMBOL_GPL(fsg_common_set_inquiry_string);
3040
3041int fsg_common_run_thread(struct fsg_common *common)
3042{
3043 common->state = FSG_STATE_IDLE;
3044 /* Tell the thread to start working */
3045 common->thread_task =
3046 kthread_create(fsg_main_thread, common, "file-storage");
3047 if (IS_ERR(common->thread_task)) {
3048 common->state = FSG_STATE_TERMINATED;
3049 return PTR_ERR(common->thread_task);
3050 }
3051
2799 DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task)); 3052 DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task));
2800 3053
2801 wake_up_process(common->thread_task); 3054 wake_up_process(common->thread_task);
2802 3055
2803 return common; 3056 return 0;
2804
2805error_luns:
2806 common->nluns = i + 1;
2807error_release:
2808 common->state = FSG_STATE_TERMINATED; /* The thread is dead */
2809 /* Call fsg_common_release() directly, ref might be not initialised. */
2810 fsg_common_release(&common->ref);
2811 return ERR_PTR(rc);
2812} 3057}
3058EXPORT_SYMBOL_GPL(fsg_common_run_thread);
2813 3059
2814static void fsg_common_release(struct kref *ref) 3060static void fsg_common_release(struct kref *ref)
2815{ 3061{
@@ -2822,36 +3068,26 @@ static void fsg_common_release(struct kref *ref)
2822 } 3068 }
2823 3069
2824 if (likely(common->luns)) { 3070 if (likely(common->luns)) {
2825 struct fsg_lun *lun = common->luns; 3071 struct fsg_lun **lun_it = common->luns;
2826 unsigned i = common->nluns; 3072 unsigned i = common->nluns;
2827 3073
2828 /* In error recovery common->nluns may be zero. */ 3074 /* In error recovery common->nluns may be zero. */
2829 for (; i; --i, ++lun) { 3075 for (; i; --i, ++lun_it) {
2830 device_remove_file(&lun->dev, &dev_attr_nofua); 3076 struct fsg_lun *lun = *lun_it;
2831 device_remove_file(&lun->dev, 3077 if (!lun)
2832 lun->cdrom 3078 continue;
2833 ? &dev_attr_ro_cdrom 3079 if (common->sysfs)
2834 : &dev_attr_ro); 3080 fsg_common_remove_sysfs(lun);
2835 device_remove_file(&lun->dev,
2836 lun->removable
2837 ? &dev_attr_file
2838 : &dev_attr_file_nonremovable);
2839 fsg_lun_close(lun); 3081 fsg_lun_close(lun);
2840 device_unregister(&lun->dev); 3082 if (common->sysfs)
3083 device_unregister(&lun->dev);
3084 kfree(lun);
2841 } 3085 }
2842 3086
2843 kfree(common->luns); 3087 kfree(common->luns);
2844 } 3088 }
2845 3089
2846 { 3090 _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
2847 struct fsg_buffhd *bh = common->buffhds;
2848 unsigned i = fsg_num_buffers;
2849 do {
2850 kfree(bh->buf);
2851 } while (++bh, --i);
2852 }
2853
2854 kfree(common->buffhds);
2855 if (common->free_storage_on_release) 3091 if (common->free_storage_on_release)
2856 kfree(common); 3092 kfree(common);
2857} 3093}
@@ -2859,24 +3095,6 @@ static void fsg_common_release(struct kref *ref)
2859 3095
2860/*-------------------------------------------------------------------------*/ 3096/*-------------------------------------------------------------------------*/
2861 3097
2862static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
2863{
2864 struct fsg_dev *fsg = fsg_from_func(f);
2865 struct fsg_common *common = fsg->common;
2866
2867 DBG(fsg, "unbind\n");
2868 if (fsg->common->fsg == fsg) {
2869 fsg->common->new_fsg = NULL;
2870 raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
2871 /* FIXME: make interruptible or killable somehow? */
2872 wait_event(common->fsg_wait, common->fsg != fsg);
2873 }
2874
2875 fsg_common_put(common);
2876 usb_free_all_descriptors(&fsg->function);
2877 kfree(fsg);
2878}
2879
2880static int fsg_bind(struct usb_configuration *c, struct usb_function *f) 3098static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
2881{ 3099{
2882 struct fsg_dev *fsg = fsg_from_func(f); 3100 struct fsg_dev *fsg = fsg_from_func(f);
@@ -2885,6 +3103,19 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
2885 struct usb_ep *ep; 3103 struct usb_ep *ep;
2886 unsigned max_burst; 3104 unsigned max_burst;
2887 int ret; 3105 int ret;
3106 struct fsg_opts *opts;
3107
3108 opts = fsg_opts_from_func_inst(f->fi);
3109 if (!opts->no_configfs) {
3110 ret = fsg_common_set_cdev(fsg->common, c->cdev,
3111 fsg->common->can_stall);
3112 if (ret)
3113 return ret;
3114 fsg_common_set_inquiry_string(fsg->common, 0, 0);
3115 ret = fsg_common_run_thread(fsg->common);
3116 if (ret)
3117 return ret;
3118 }
2888 3119
2889 fsg->gadget = gadget; 3120 fsg->gadget = gadget;
2890 3121
@@ -2937,95 +3168,472 @@ autoconf_fail:
2937 return -ENOTSUPP; 3168 return -ENOTSUPP;
2938} 3169}
2939 3170
2940/****************************** ADD FUNCTION ******************************/ 3171/****************************** ALLOCATE FUNCTION *************************/
2941 3172
2942static struct usb_gadget_strings *fsg_strings_array[] = { 3173static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
2943 &fsg_stringtab, 3174{
3175 struct fsg_dev *fsg = fsg_from_func(f);
3176 struct fsg_common *common = fsg->common;
3177
3178 DBG(fsg, "unbind\n");
3179 if (fsg->common->fsg == fsg) {
3180 fsg->common->new_fsg = NULL;
3181 raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
3182 /* FIXME: make interruptible or killable somehow? */
3183 wait_event(common->fsg_wait, common->fsg != fsg);
3184 }
3185
3186 usb_free_all_descriptors(&fsg->function);
3187}
3188
3189static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item)
3190{
3191 return container_of(to_config_group(item), struct fsg_lun_opts, group);
3192}
3193
3194static inline struct fsg_opts *to_fsg_opts(struct config_item *item)
3195{
3196 return container_of(to_config_group(item), struct fsg_opts,
3197 func_inst.group);
3198}
3199
3200CONFIGFS_ATTR_STRUCT(fsg_lun_opts);
3201CONFIGFS_ATTR_OPS(fsg_lun_opts);
3202
3203static void fsg_lun_attr_release(struct config_item *item)
3204{
3205 struct fsg_lun_opts *lun_opts;
3206
3207 lun_opts = to_fsg_lun_opts(item);
3208 kfree(lun_opts);
3209}
3210
3211static struct configfs_item_operations fsg_lun_item_ops = {
3212 .release = fsg_lun_attr_release,
3213 .show_attribute = fsg_lun_opts_attr_show,
3214 .store_attribute = fsg_lun_opts_attr_store,
3215};
3216
3217static ssize_t fsg_lun_opts_file_show(struct fsg_lun_opts *opts, char *page)
3218{
3219 struct fsg_opts *fsg_opts;
3220
3221 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3222
3223 return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page);
3224}
3225
3226static ssize_t fsg_lun_opts_file_store(struct fsg_lun_opts *opts,
3227 const char *page, size_t len)
3228{
3229 struct fsg_opts *fsg_opts;
3230
3231 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3232
3233 return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len);
3234}
3235
3236static struct fsg_lun_opts_attribute fsg_lun_opts_file =
3237 __CONFIGFS_ATTR(file, S_IRUGO | S_IWUSR, fsg_lun_opts_file_show,
3238 fsg_lun_opts_file_store);
3239
3240static ssize_t fsg_lun_opts_ro_show(struct fsg_lun_opts *opts, char *page)
3241{
3242 return fsg_show_ro(opts->lun, page);
3243}
3244
3245static ssize_t fsg_lun_opts_ro_store(struct fsg_lun_opts *opts,
3246 const char *page, size_t len)
3247{
3248 struct fsg_opts *fsg_opts;
3249
3250 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3251
3252 return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len);
3253}
3254
3255static struct fsg_lun_opts_attribute fsg_lun_opts_ro =
3256 __CONFIGFS_ATTR(ro, S_IRUGO | S_IWUSR, fsg_lun_opts_ro_show,
3257 fsg_lun_opts_ro_store);
3258
3259static ssize_t fsg_lun_opts_removable_show(struct fsg_lun_opts *opts,
3260 char *page)
3261{
3262 return fsg_show_removable(opts->lun, page);
3263}
3264
3265static ssize_t fsg_lun_opts_removable_store(struct fsg_lun_opts *opts,
3266 const char *page, size_t len)
3267{
3268 return fsg_store_removable(opts->lun, page, len);
3269}
3270
3271static struct fsg_lun_opts_attribute fsg_lun_opts_removable =
3272 __CONFIGFS_ATTR(removable, S_IRUGO | S_IWUSR,
3273 fsg_lun_opts_removable_show,
3274 fsg_lun_opts_removable_store);
3275
3276static ssize_t fsg_lun_opts_cdrom_show(struct fsg_lun_opts *opts, char *page)
3277{
3278 return fsg_show_cdrom(opts->lun, page);
3279}
3280
3281static ssize_t fsg_lun_opts_cdrom_store(struct fsg_lun_opts *opts,
3282 const char *page, size_t len)
3283{
3284 struct fsg_opts *fsg_opts;
3285
3286 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3287
3288 return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page,
3289 len);
3290}
3291
3292static struct fsg_lun_opts_attribute fsg_lun_opts_cdrom =
3293 __CONFIGFS_ATTR(cdrom, S_IRUGO | S_IWUSR, fsg_lun_opts_cdrom_show,
3294 fsg_lun_opts_cdrom_store);
3295
3296static ssize_t fsg_lun_opts_nofua_show(struct fsg_lun_opts *opts, char *page)
3297{
3298 return fsg_show_nofua(opts->lun, page);
3299}
3300
3301static ssize_t fsg_lun_opts_nofua_store(struct fsg_lun_opts *opts,
3302 const char *page, size_t len)
3303{
3304 return fsg_store_nofua(opts->lun, page, len);
3305}
3306
3307static struct fsg_lun_opts_attribute fsg_lun_opts_nofua =
3308 __CONFIGFS_ATTR(nofua, S_IRUGO | S_IWUSR, fsg_lun_opts_nofua_show,
3309 fsg_lun_opts_nofua_store);
3310
3311static struct configfs_attribute *fsg_lun_attrs[] = {
3312 &fsg_lun_opts_file.attr,
3313 &fsg_lun_opts_ro.attr,
3314 &fsg_lun_opts_removable.attr,
3315 &fsg_lun_opts_cdrom.attr,
3316 &fsg_lun_opts_nofua.attr,
2944 NULL, 3317 NULL,
2945}; 3318};
2946 3319
2947static int fsg_bind_config(struct usb_composite_dev *cdev, 3320static struct config_item_type fsg_lun_type = {
2948 struct usb_configuration *c, 3321 .ct_item_ops = &fsg_lun_item_ops,
2949 struct fsg_common *common) 3322 .ct_attrs = fsg_lun_attrs,
3323 .ct_owner = THIS_MODULE,
3324};
3325
3326static struct config_group *fsg_lun_make(struct config_group *group,
3327 const char *name)
2950{ 3328{
2951 struct fsg_dev *fsg; 3329 struct fsg_lun_opts *opts;
3330 struct fsg_opts *fsg_opts;
3331 struct fsg_lun_config config;
3332 char *num_str;
3333 u8 num;
3334 int ret;
3335
3336 num_str = strchr(name, '.');
3337 if (!num_str) {
3338 pr_err("Unable to locate . in LUN.NUMBER\n");
3339 return ERR_PTR(-EINVAL);
3340 }
3341 num_str++;
3342
3343 ret = kstrtou8(num_str, 0, &num);
3344 if (ret)
3345 return ERR_PTR(ret);
3346
3347 fsg_opts = to_fsg_opts(&group->cg_item);
3348 if (num >= FSG_MAX_LUNS)
3349 return ERR_PTR(-ERANGE);
3350
3351 mutex_lock(&fsg_opts->lock);
3352 if (fsg_opts->refcnt || fsg_opts->common->luns[num]) {
3353 ret = -EBUSY;
3354 goto out;
3355 }
3356
3357 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
3358 if (!opts) {
3359 ret = -ENOMEM;
3360 goto out;
3361 }
3362
3363 memset(&config, 0, sizeof(config));
3364 config.removable = true;
3365
3366 ret = fsg_common_create_lun(fsg_opts->common, &config, num, name,
3367 (const char **)&group->cg_item.ci_name);
3368 if (ret) {
3369 kfree(opts);
3370 goto out;
3371 }
3372 opts->lun = fsg_opts->common->luns[num];
3373 opts->lun_id = num;
3374 mutex_unlock(&fsg_opts->lock);
3375
3376 config_group_init_type_name(&opts->group, name, &fsg_lun_type);
3377
3378 return &opts->group;
3379out:
3380 mutex_unlock(&fsg_opts->lock);
3381 return ERR_PTR(ret);
3382}
3383
3384static void fsg_lun_drop(struct config_group *group, struct config_item *item)
3385{
3386 struct fsg_lun_opts *lun_opts;
3387 struct fsg_opts *fsg_opts;
3388
3389 lun_opts = to_fsg_lun_opts(item);
3390 fsg_opts = to_fsg_opts(&group->cg_item);
3391
3392 mutex_lock(&fsg_opts->lock);
3393 if (fsg_opts->refcnt) {
3394 struct config_item *gadget;
3395
3396 gadget = group->cg_item.ci_parent->ci_parent;
3397 unregister_gadget_item(gadget);
3398 }
3399
3400 fsg_common_remove_lun(lun_opts->lun, fsg_opts->common->sysfs);
3401 fsg_opts->common->luns[lun_opts->lun_id] = NULL;
3402 lun_opts->lun_id = 0;
3403 mutex_unlock(&fsg_opts->lock);
3404
3405 config_item_put(item);
3406}
3407
3408CONFIGFS_ATTR_STRUCT(fsg_opts);
3409CONFIGFS_ATTR_OPS(fsg_opts);
3410
3411static void fsg_attr_release(struct config_item *item)
3412{
3413 struct fsg_opts *opts = to_fsg_opts(item);
3414
3415 usb_put_function_instance(&opts->func_inst);
3416}
3417
3418static struct configfs_item_operations fsg_item_ops = {
3419 .release = fsg_attr_release,
3420 .show_attribute = fsg_opts_attr_show,
3421 .store_attribute = fsg_opts_attr_store,
3422};
3423
3424static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page)
3425{
3426 int result;
3427
3428 mutex_lock(&opts->lock);
3429 result = sprintf(page, "%d", opts->common->can_stall);
3430 mutex_unlock(&opts->lock);
3431
3432 return result;
3433}
3434
3435static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page,
3436 size_t len)
3437{
3438 int ret;
3439 bool stall;
3440
3441 mutex_lock(&opts->lock);
3442
3443 if (opts->refcnt) {
3444 mutex_unlock(&opts->lock);
3445 return -EBUSY;
3446 }
3447
3448 ret = strtobool(page, &stall);
3449 if (!ret) {
3450 opts->common->can_stall = stall;
3451 ret = len;
3452 }
3453
3454 mutex_unlock(&opts->lock);
3455
3456 return ret;
3457}
3458
3459static struct fsg_opts_attribute fsg_opts_stall =
3460 __CONFIGFS_ATTR(stall, S_IRUGO | S_IWUSR, fsg_opts_stall_show,
3461 fsg_opts_stall_store);
3462
3463#ifdef CONFIG_USB_GADGET_DEBUG_FILES
3464static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page)
3465{
3466 int result;
3467
3468 mutex_lock(&opts->lock);
3469 result = sprintf(page, "%d", opts->common->fsg_num_buffers);
3470 mutex_unlock(&opts->lock);
3471
3472 return result;
3473}
3474
3475static ssize_t fsg_opts_num_buffers_store(struct fsg_opts *opts,
3476 const char *page, size_t len)
3477{
3478 int ret;
3479 u8 num;
3480
3481 mutex_lock(&opts->lock);
3482 if (opts->refcnt) {
3483 ret = -EBUSY;
3484 goto end;
3485 }
3486 ret = kstrtou8(page, 0, &num);
3487 if (ret)
3488 goto end;
3489
3490 ret = fsg_num_buffers_validate(num);
3491 if (ret)
3492 goto end;
3493
3494 fsg_common_set_num_buffers(opts->common, num);
3495 ret = len;
3496
3497end:
3498 mutex_unlock(&opts->lock);
3499 return ret;
3500}
3501
3502static struct fsg_opts_attribute fsg_opts_num_buffers =
3503 __CONFIGFS_ATTR(num_buffers, S_IRUGO | S_IWUSR,
3504 fsg_opts_num_buffers_show,
3505 fsg_opts_num_buffers_store);
3506
3507#endif
3508
3509static struct configfs_attribute *fsg_attrs[] = {
3510 &fsg_opts_stall.attr,
3511#ifdef CONFIG_USB_GADGET_DEBUG_FILES
3512 &fsg_opts_num_buffers.attr,
3513#endif
3514 NULL,
3515};
3516
3517static struct configfs_group_operations fsg_group_ops = {
3518 .make_group = fsg_lun_make,
3519 .drop_item = fsg_lun_drop,
3520};
3521
3522static struct config_item_type fsg_func_type = {
3523 .ct_item_ops = &fsg_item_ops,
3524 .ct_group_ops = &fsg_group_ops,
3525 .ct_attrs = fsg_attrs,
3526 .ct_owner = THIS_MODULE,
3527};
3528
3529static void fsg_free_inst(struct usb_function_instance *fi)
3530{
3531 struct fsg_opts *opts;
3532
3533 opts = fsg_opts_from_func_inst(fi);
3534 fsg_common_put(opts->common);
3535 kfree(opts);
3536}
3537
3538static struct usb_function_instance *fsg_alloc_inst(void)
3539{
3540 struct fsg_opts *opts;
3541 struct fsg_lun_config config;
2952 int rc; 3542 int rc;
2953 3543
2954 fsg = kzalloc(sizeof *fsg, GFP_KERNEL); 3544 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
3545 if (!opts)
3546 return ERR_PTR(-ENOMEM);
3547 mutex_init(&opts->lock);
3548 opts->func_inst.free_func_inst = fsg_free_inst;
3549 opts->common = fsg_common_setup(opts->common);
3550 if (IS_ERR(opts->common)) {
3551 rc = PTR_ERR(opts->common);
3552 goto release_opts;
3553 }
3554 rc = fsg_common_set_nluns(opts->common, FSG_MAX_LUNS);
3555 if (rc)
3556 goto release_opts;
3557
3558 rc = fsg_common_set_num_buffers(opts->common,
3559 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS);
3560 if (rc)
3561 goto release_luns;
3562
3563 pr_info(FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
3564
3565 memset(&config, 0, sizeof(config));
3566 config.removable = true;
3567 rc = fsg_common_create_lun(opts->common, &config, 0, "lun.0",
3568 (const char **)&opts->func_inst.group.cg_item.ci_name);
3569 opts->lun0.lun = opts->common->luns[0];
3570 opts->lun0.lun_id = 0;
3571 config_group_init_type_name(&opts->lun0.group, "lun.0", &fsg_lun_type);
3572 opts->default_groups[0] = &opts->lun0.group;
3573 opts->func_inst.group.default_groups = opts->default_groups;
3574
3575 config_group_init_type_name(&opts->func_inst.group, "", &fsg_func_type);
3576
3577 return &opts->func_inst;
3578
3579release_luns:
3580 kfree(opts->common->luns);
3581release_opts:
3582 kfree(opts);
3583 return ERR_PTR(rc);
3584}
3585
3586static void fsg_free(struct usb_function *f)
3587{
3588 struct fsg_dev *fsg;
3589 struct fsg_opts *opts;
3590
3591 fsg = container_of(f, struct fsg_dev, function);
3592 opts = container_of(f->fi, struct fsg_opts, func_inst);
3593
3594 mutex_lock(&opts->lock);
3595 opts->refcnt--;
3596 mutex_unlock(&opts->lock);
3597
3598 kfree(fsg);
3599}
3600
3601static struct usb_function *fsg_alloc(struct usb_function_instance *fi)
3602{
3603 struct fsg_opts *opts = fsg_opts_from_func_inst(fi);
3604 struct fsg_common *common = opts->common;
3605 struct fsg_dev *fsg;
3606
3607 fsg = kzalloc(sizeof(*fsg), GFP_KERNEL);
2955 if (unlikely(!fsg)) 3608 if (unlikely(!fsg))
2956 return -ENOMEM; 3609 return ERR_PTR(-ENOMEM);
2957 3610
2958 fsg->function.name = FSG_DRIVER_DESC; 3611 mutex_lock(&opts->lock);
2959 fsg->function.strings = fsg_strings_array; 3612 opts->refcnt++;
2960 fsg->function.bind = fsg_bind; 3613 mutex_unlock(&opts->lock);
2961 fsg->function.unbind = fsg_unbind; 3614 fsg->function.name = FSG_DRIVER_DESC;
2962 fsg->function.setup = fsg_setup; 3615 fsg->function.bind = fsg_bind;
2963 fsg->function.set_alt = fsg_set_alt; 3616 fsg->function.unbind = fsg_unbind;
2964 fsg->function.disable = fsg_disable; 3617 fsg->function.setup = fsg_setup;
3618 fsg->function.set_alt = fsg_set_alt;
3619 fsg->function.disable = fsg_disable;
3620 fsg->function.free_func = fsg_free;
2965 3621
2966 fsg->common = common; 3622 fsg->common = common;
2967 /*
2968 * Our caller holds a reference to common structure so we
2969 * don't have to be worry about it being freed until we return
2970 * from this function. So instead of incrementing counter now
2971 * and decrement in error recovery we increment it only when
2972 * call to usb_add_function() was successful.
2973 */
2974 3623
2975 rc = usb_add_function(c, &fsg->function); 3624 return &fsg->function;
2976 if (unlikely(rc))
2977 kfree(fsg);
2978 else
2979 fsg_common_get(fsg->common);
2980 return rc;
2981} 3625}
2982 3626
3627DECLARE_USB_FUNCTION_INIT(mass_storage, fsg_alloc_inst, fsg_alloc);
3628MODULE_LICENSE("GPL");
3629MODULE_AUTHOR("Michal Nazarewicz");
2983 3630
2984/************************* Module parameters *************************/ 3631/************************* Module parameters *************************/
2985 3632
2986struct fsg_module_parameters {
2987 char *file[FSG_MAX_LUNS];
2988 bool ro[FSG_MAX_LUNS];
2989 bool removable[FSG_MAX_LUNS];
2990 bool cdrom[FSG_MAX_LUNS];
2991 bool nofua[FSG_MAX_LUNS];
2992
2993 unsigned int file_count, ro_count, removable_count, cdrom_count;
2994 unsigned int nofua_count;
2995 unsigned int luns; /* nluns */
2996 bool stall; /* can_stall */
2997};
2998 3633
2999#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \ 3634void fsg_config_from_params(struct fsg_config *cfg,
3000 module_param_array_named(prefix ## name, params.name, type, \ 3635 const struct fsg_module_parameters *params,
3001 &prefix ## params.name ## _count, \ 3636 unsigned int fsg_num_buffers)
3002 S_IRUGO); \
3003 MODULE_PARM_DESC(prefix ## name, desc)
3004
3005#define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \
3006 module_param_named(prefix ## name, params.name, type, \
3007 S_IRUGO); \
3008 MODULE_PARM_DESC(prefix ## name, desc)
3009
3010#define FSG_MODULE_PARAMETERS(prefix, params) \
3011 _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \
3012 "names of backing files or devices"); \
3013 _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \
3014 "true to force read-only"); \
3015 _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \
3016 "true to simulate removable media"); \
3017 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
3018 "true to simulate CD-ROM instead of disk"); \
3019 _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
3020 "true to ignore SCSI WRITE(10,12) FUA bit"); \
3021 _FSG_MODULE_PARAM(prefix, params, luns, uint, \
3022 "number of LUNs"); \
3023 _FSG_MODULE_PARAM(prefix, params, stall, bool, \
3024 "false to prevent bulk stalls")
3025
3026static void
3027fsg_config_from_params(struct fsg_config *cfg,
3028 const struct fsg_module_parameters *params)
3029{ 3637{
3030 struct fsg_lun_config *lun; 3638 struct fsg_lun_config *lun;
3031 unsigned i; 3639 unsigned i;
@@ -3053,19 +3661,7 @@ fsg_config_from_params(struct fsg_config *cfg,
3053 3661
3054 /* Finalise */ 3662 /* Finalise */
3055 cfg->can_stall = params->stall; 3663 cfg->can_stall = params->stall;
3664 cfg->fsg_num_buffers = fsg_num_buffers;
3056} 3665}
3666EXPORT_SYMBOL_GPL(fsg_config_from_params);
3057 3667
3058static inline struct fsg_common *
3059fsg_common_from_params(struct fsg_common *common,
3060 struct usb_composite_dev *cdev,
3061 const struct fsg_module_parameters *params)
3062 __attribute__((unused));
3063static inline struct fsg_common *
3064fsg_common_from_params(struct fsg_common *common,
3065 struct usb_composite_dev *cdev,
3066 const struct fsg_module_parameters *params)
3067{
3068 struct fsg_config cfg;
3069 fsg_config_from_params(&cfg, params);
3070 return fsg_common_init(common, cdev, &cfg);
3071}
diff --git a/drivers/usb/gadget/f_mass_storage.h b/drivers/usb/gadget/f_mass_storage.h
new file mode 100644
index 000000000000..b4866fcef30b
--- /dev/null
+++ b/drivers/usb/gadget/f_mass_storage.h
@@ -0,0 +1,166 @@
1#ifndef USB_F_MASS_STORAGE_H
2#define USB_F_MASS_STORAGE_H
3
4#include <linux/usb/composite.h>
5#include "storage_common.h"
6
7struct fsg_module_parameters {
8 char *file[FSG_MAX_LUNS];
9 bool ro[FSG_MAX_LUNS];
10 bool removable[FSG_MAX_LUNS];
11 bool cdrom[FSG_MAX_LUNS];
12 bool nofua[FSG_MAX_LUNS];
13
14 unsigned int file_count, ro_count, removable_count, cdrom_count;
15 unsigned int nofua_count;
16 unsigned int luns; /* nluns */
17 bool stall; /* can_stall */
18};
19
20#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \
21 module_param_array_named(prefix ## name, params.name, type, \
22 &prefix ## params.name ## _count, \
23 S_IRUGO); \
24 MODULE_PARM_DESC(prefix ## name, desc)
25
26#define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \
27 module_param_named(prefix ## name, params.name, type, \
28 S_IRUGO); \
29 MODULE_PARM_DESC(prefix ## name, desc)
30
31#define __FSG_MODULE_PARAMETERS(prefix, params) \
32 _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \
33 "names of backing files or devices"); \
34 _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \
35 "true to force read-only"); \
36 _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \
37 "true to simulate removable media"); \
38 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
39 "true to simulate CD-ROM instead of disk"); \
40 _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
41 "true to ignore SCSI WRITE(10,12) FUA bit"); \
42 _FSG_MODULE_PARAM(prefix, params, luns, uint, \
43 "number of LUNs"); \
44 _FSG_MODULE_PARAM(prefix, params, stall, bool, \
45 "false to prevent bulk stalls")
46
47#ifdef CONFIG_USB_GADGET_DEBUG_FILES
48
49#define FSG_MODULE_PARAMETERS(prefix, params) \
50 __FSG_MODULE_PARAMETERS(prefix, params); \
51 module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\
52 MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers")
53#else
54
55#define FSG_MODULE_PARAMETERS(prefix, params) \
56 __FSG_MODULE_PARAMETERS(prefix, params)
57
58#endif
59
60struct fsg_common;
61
62/* FSF callback functions */
63struct fsg_operations {
64 /*
65 * Callback function to call when thread exits. If no
66 * callback is set or it returns value lower then zero MSF
67 * will force eject all LUNs it operates on (including those
68 * marked as non-removable or with prevent_medium_removal flag
69 * set).
70 */
71 int (*thread_exits)(struct fsg_common *common);
72};
73
74struct fsg_lun_opts {
75 struct config_group group;
76 struct fsg_lun *lun;
77 int lun_id;
78};
79
80struct fsg_opts {
81 struct fsg_common *common;
82 struct usb_function_instance func_inst;
83 struct fsg_lun_opts lun0;
84 struct config_group *default_groups[2];
85 bool no_configfs; /* for legacy gadgets */
86
87 /*
88 * Read/write access to configfs attributes is handled by configfs.
89 *
90 * This is to protect the data from concurrent access by read/write
91 * and create symlink/remove symlink.
92 */
93 struct mutex lock;
94 int refcnt;
95};
96
97struct fsg_lun_config {
98 const char *filename;
99 char ro;
100 char removable;
101 char cdrom;
102 char nofua;
103};
104
105struct fsg_config {
106 unsigned nluns;
107 struct fsg_lun_config luns[FSG_MAX_LUNS];
108
109 /* Callback functions. */
110 const struct fsg_operations *ops;
111 /* Gadget's private data. */
112 void *private_data;
113
114 const char *vendor_name; /* 8 characters or less */
115 const char *product_name; /* 16 characters or less */
116
117 char can_stall;
118 unsigned int fsg_num_buffers;
119};
120
121static inline struct fsg_opts *
122fsg_opts_from_func_inst(const struct usb_function_instance *fi)
123{
124 return container_of(fi, struct fsg_opts, func_inst);
125}
126
127void fsg_common_get(struct fsg_common *common);
128
129void fsg_common_put(struct fsg_common *common);
130
131void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
132
133int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
134
135void fsg_common_free_buffers(struct fsg_common *common);
136
137int fsg_common_set_cdev(struct fsg_common *common,
138 struct usb_composite_dev *cdev, bool can_stall);
139
140void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs);
141
142void fsg_common_remove_luns(struct fsg_common *common);
143
144void fsg_common_free_luns(struct fsg_common *common);
145
146int fsg_common_set_nluns(struct fsg_common *common, int nluns);
147
148void fsg_common_set_ops(struct fsg_common *common,
149 const struct fsg_operations *ops);
150
151int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
152 unsigned int id, const char *name,
153 const char **name_pfx);
154
155int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg);
156
157void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
158 const char *pn);
159
160int fsg_common_run_thread(struct fsg_common *common);
161
162void fsg_config_from_params(struct fsg_config *cfg,
163 const struct fsg_module_parameters *params,
164 unsigned int fsg_num_buffers);
165
166#endif /* USB_F_MASS_STORAGE_H */
diff --git a/drivers/usb/gadget/fotg210-udc.c b/drivers/usb/gadget/fotg210-udc.c
index 32db2eee2d87..bbbfd1948778 100644
--- a/drivers/usb/gadget/fotg210-udc.c
+++ b/drivers/usb/gadget/fotg210-udc.c
@@ -1214,6 +1214,6 @@ static struct platform_driver fotg210_driver = {
1214 1214
1215module_platform_driver(fotg210_driver); 1215module_platform_driver(fotg210_driver);
1216 1216
1217MODULE_AUTHOR("Yuan-Hsin Chen <yhchen@faraday-tech.com>"); 1217MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang <john453@faraday-tech.com>");
1218MODULE_LICENSE("GPL"); 1218MODULE_LICENSE("GPL");
1219MODULE_DESCRIPTION(DRIVER_DESC); 1219MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index f3bb363f1d4a..807127d56fa3 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -33,6 +33,7 @@
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
35#include <linux/of_address.h> 35#include <linux/of_address.h>
36#include <linux/of_irq.h>
36#include <linux/of_platform.h> 37#include <linux/of_platform.h>
37#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
38#include <linux/usb/ch9.h> 39#include <linux/usb/ch9.h>
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index f1dd6daabe21..b278abe52453 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -22,7 +22,7 @@
22 22
23MODULE_DESCRIPTION("FUSB300 USB gadget driver"); 23MODULE_DESCRIPTION("FUSB300 USB gadget driver");
24MODULE_LICENSE("GPL"); 24MODULE_LICENSE("GPL");
25MODULE_AUTHOR("Yuan Hsin Chen <yhchen@faraday-tech.com>"); 25MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang <john453@faraday-tech.com>");
26MODULE_ALIAS("platform:fusb300_udc"); 26MODULE_ALIAS("platform:fusb300_udc");
27 27
28#define DRIVER_VERSION "20 October 2010" 28#define DRIVER_VERSION "20 October 2010"
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 5327c82472ed..2344efe4f4ce 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -76,7 +76,9 @@ struct gfs_ffs_obj {
76 76
77USB_GADGET_COMPOSITE_OPTIONS(); 77USB_GADGET_COMPOSITE_OPTIONS();
78 78
79#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
79USB_ETHERNET_MODULE_PARAMETERS(); 80USB_ETHERNET_MODULE_PARAMETERS();
81#endif
80 82
81static struct usb_device_descriptor gfs_dev_desc = { 83static struct usb_device_descriptor gfs_dev_desc = {
82 .bLength = sizeof gfs_dev_desc, 84 .bLength = sizeof gfs_dev_desc,
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index c64deb9e3d62..f82768015715 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1165,7 +1165,7 @@ static int udc_proc_read(struct seq_file *m, void *v)
1165 s = "invalid"; break; 1165 s = "invalid"; break;
1166 default: 1166 default:
1167 s = "?"; break; 1167 s = "?"; break;
1168 }; s; }), 1168 } s; }),
1169 (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0", 1169 (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0",
1170 (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "", 1170 (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "",
1171 (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "", 1171 (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "",
@@ -1701,7 +1701,6 @@ static void goku_remove(struct pci_dev *pdev)
1701 if (dev->enabled) 1701 if (dev->enabled)
1702 pci_disable_device(pdev); 1702 pci_disable_device(pdev);
1703 1703
1704 pci_set_drvdata(pdev, NULL);
1705 dev->regs = NULL; 1704 dev->regs = NULL;
1706 1705
1707 INFO(dev, "unbind\n"); 1706 INFO(dev, "unbind\n");
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 465ef8e2cc91..b94c049ab0d0 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -524,7 +524,7 @@ struct kiocb_priv {
524 unsigned actual; 524 unsigned actual;
525}; 525};
526 526
527static int ep_aio_cancel(struct kiocb *iocb, struct io_event *e) 527static int ep_aio_cancel(struct kiocb *iocb)
528{ 528{
529 struct kiocb_priv *priv = iocb->private; 529 struct kiocb_priv *priv = iocb->private;
530 struct ep_data *epdata; 530 struct ep_data *epdata;
@@ -540,7 +540,6 @@ static int ep_aio_cancel(struct kiocb *iocb, struct io_event *e)
540 // spin_unlock(&epdata->dev->lock); 540 // spin_unlock(&epdata->dev->lock);
541 local_irq_enable(); 541 local_irq_enable();
542 542
543 aio_put_req(iocb);
544 return value; 543 return value;
545} 544}
546 545
@@ -709,11 +708,11 @@ ep_aio_read(struct kiocb *iocb, const struct iovec *iov,
709 if (unlikely(usb_endpoint_dir_in(&epdata->desc))) 708 if (unlikely(usb_endpoint_dir_in(&epdata->desc)))
710 return -EINVAL; 709 return -EINVAL;
711 710
712 buf = kmalloc(iocb->ki_left, GFP_KERNEL); 711 buf = kmalloc(iocb->ki_nbytes, GFP_KERNEL);
713 if (unlikely(!buf)) 712 if (unlikely(!buf))
714 return -ENOMEM; 713 return -ENOMEM;
715 714
716 return ep_aio_rwtail(iocb, buf, iocb->ki_left, epdata, iov, nr_segs); 715 return ep_aio_rwtail(iocb, buf, iocb->ki_nbytes, epdata, iov, nr_segs);
717} 716}
718 717
719static ssize_t 718static ssize_t
@@ -728,7 +727,7 @@ ep_aio_write(struct kiocb *iocb, const struct iovec *iov,
728 if (unlikely(!usb_endpoint_dir_in(&epdata->desc))) 727 if (unlikely(!usb_endpoint_dir_in(&epdata->desc)))
729 return -EINVAL; 728 return -EINVAL;
730 729
731 buf = kmalloc(iocb->ki_left, GFP_KERNEL); 730 buf = kmalloc(iocb->ki_nbytes, GFP_KERNEL);
732 if (unlikely(!buf)) 731 if (unlikely(!buf))
733 return -ENOMEM; 732 return -ENOMEM;
734 733
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c
index 67128be1e1b7..6a2a65aa0057 100644
--- a/drivers/usb/gadget/lpc32xx_udc.c
+++ b/drivers/usb/gadget/lpc32xx_udc.c
@@ -3078,7 +3078,9 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3078 udc->isp1301_i2c_client->addr); 3078 udc->isp1301_i2c_client->addr);
3079 3079
3080 pdev->dev.dma_mask = &lpc32xx_usbd_dmamask; 3080 pdev->dev.dma_mask = &lpc32xx_usbd_dmamask;
3081 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 3081 retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
3082 if (retval)
3083 goto resource_fail;
3082 3084
3083 udc->board = &lpc32xx_usbddata; 3085 udc->board = &lpc32xx_usbddata;
3084 3086
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
index 080e577773d5..8e27a8c96444 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -37,16 +37,16 @@
37#define DRIVER_DESC "Mass Storage Gadget" 37#define DRIVER_DESC "Mass Storage Gadget"
38#define DRIVER_VERSION "2009/09/11" 38#define DRIVER_VERSION "2009/09/11"
39 39
40/*-------------------------------------------------------------------------*/
41
42/* 40/*
43 * kbuild is not very cooperative with respect to linking separately 41 * Thanks to NetChip Technologies for donating this product ID.
44 * compiled library objects into one module. So for now we won't use 42 *
45 * separate compilation ... ensuring init/exit sections work to shrink 43 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
46 * the runtime footprint, and giving us at least some parts of what 44 * Instead: allocate your own, using normal USB-IF procedures.
47 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
48 */ 45 */
49#include "f_mass_storage.c" 46#define FSG_VENDOR_ID 0x0525 /* NetChip */
47#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
48
49#include "f_mass_storage.h"
50 50
51/*-------------------------------------------------------------------------*/ 51/*-------------------------------------------------------------------------*/
52USB_GADGET_COMPOSITE_OPTIONS(); 52USB_GADGET_COMPOSITE_OPTIONS();
@@ -97,11 +97,28 @@ static struct usb_gadget_strings *dev_strings[] = {
97 NULL, 97 NULL,
98}; 98};
99 99
100static struct usb_function_instance *fi_msg;
101static struct usb_function *f_msg;
102
100/****************************** Configurations ******************************/ 103/****************************** Configurations ******************************/
101 104
102static struct fsg_module_parameters mod_data = { 105static struct fsg_module_parameters mod_data = {
103 .stall = 1 106 .stall = 1
104}; 107};
108#ifdef CONFIG_USB_GADGET_DEBUG_FILES
109
110static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
111
112#else
113
114/*
115 * Number of buffers we will use.
116 * 2 is usually enough for good buffering pipeline
117 */
118#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
119
120#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
121
105FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); 122FSG_MODULE_PARAMETERS(/* no prefix */, mod_data);
106 123
107static unsigned long msg_registered; 124static unsigned long msg_registered;
@@ -115,13 +132,7 @@ static int msg_thread_exits(struct fsg_common *common)
115 132
116static int __init msg_do_config(struct usb_configuration *c) 133static int __init msg_do_config(struct usb_configuration *c)
117{ 134{
118 static const struct fsg_operations ops = { 135 struct fsg_opts *opts;
119 .thread_exits = msg_thread_exits,
120 };
121 static struct fsg_common common;
122
123 struct fsg_common *retp;
124 struct fsg_config config;
125 int ret; 136 int ret;
126 137
127 if (gadget_is_otg(c->cdev->gadget)) { 138 if (gadget_is_otg(c->cdev->gadget)) {
@@ -129,15 +140,24 @@ static int __init msg_do_config(struct usb_configuration *c)
129 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 140 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
130 } 141 }
131 142
132 fsg_config_from_params(&config, &mod_data); 143 opts = fsg_opts_from_func_inst(fi_msg);
133 config.ops = &ops; 144
145 f_msg = usb_get_function(fi_msg);
146 if (IS_ERR(f_msg))
147 return PTR_ERR(f_msg);
148
149 ret = fsg_common_run_thread(opts->common);
150 if (ret)
151 goto put_func;
152
153 ret = usb_add_function(c, f_msg);
154 if (ret)
155 goto put_func;
134 156
135 retp = fsg_common_init(&common, c->cdev, &config); 157 return 0;
136 if (IS_ERR(retp))
137 return PTR_ERR(retp);
138 158
139 ret = fsg_bind_config(c->cdev, c, &common); 159put_func:
140 fsg_common_put(&common); 160 usb_put_function(f_msg);
141 return ret; 161 return ret;
142} 162}
143 163
@@ -152,23 +172,79 @@ static struct usb_configuration msg_config_driver = {
152 172
153static int __init msg_bind(struct usb_composite_dev *cdev) 173static int __init msg_bind(struct usb_composite_dev *cdev)
154{ 174{
175 static const struct fsg_operations ops = {
176 .thread_exits = msg_thread_exits,
177 };
178 struct fsg_opts *opts;
179 struct fsg_config config;
155 int status; 180 int status;
156 181
182 fi_msg = usb_get_function_instance("mass_storage");
183 if (IS_ERR(fi_msg))
184 return PTR_ERR(fi_msg);
185
186 fsg_config_from_params(&config, &mod_data, fsg_num_buffers);
187 opts = fsg_opts_from_func_inst(fi_msg);
188
189 opts->no_configfs = true;
190 status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers);
191 if (status)
192 goto fail;
193
194 status = fsg_common_set_nluns(opts->common, config.nluns);
195 if (status)
196 goto fail_set_nluns;
197
198 fsg_common_set_ops(opts->common, &ops);
199
200 status = fsg_common_set_cdev(opts->common, cdev, config.can_stall);
201 if (status)
202 goto fail_set_cdev;
203
204 fsg_common_set_sysfs(opts->common, true);
205 status = fsg_common_create_luns(opts->common, &config);
206 if (status)
207 goto fail_set_cdev;
208
209 fsg_common_set_inquiry_string(opts->common, config.vendor_name,
210 config.product_name);
211
157 status = usb_string_ids_tab(cdev, strings_dev); 212 status = usb_string_ids_tab(cdev, strings_dev);
158 if (status < 0) 213 if (status < 0)
159 return status; 214 goto fail_string_ids;
160 msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 215 msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
161 216
162 status = usb_add_config(cdev, &msg_config_driver, msg_do_config); 217 status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
163 if (status < 0) 218 if (status < 0)
164 return status; 219 goto fail_string_ids;
220
165 usb_composite_overwrite_options(cdev, &coverwrite); 221 usb_composite_overwrite_options(cdev, &coverwrite);
166 dev_info(&cdev->gadget->dev, 222 dev_info(&cdev->gadget->dev,
167 DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 223 DRIVER_DESC ", version: " DRIVER_VERSION "\n");
168 set_bit(0, &msg_registered); 224 set_bit(0, &msg_registered);
169 return 0; 225 return 0;
226
227fail_string_ids:
228 fsg_common_remove_luns(opts->common);
229fail_set_cdev:
230 fsg_common_free_luns(opts->common);
231fail_set_nluns:
232 fsg_common_free_buffers(opts->common);
233fail:
234 usb_put_function_instance(fi_msg);
235 return status;
170} 236}
171 237
238static int msg_unbind(struct usb_composite_dev *cdev)
239{
240 if (!IS_ERR(f_msg))
241 usb_put_function(f_msg);
242
243 if (!IS_ERR(fi_msg))
244 usb_put_function_instance(fi_msg);
245
246 return 0;
247}
172 248
173/****************************** Some noise ******************************/ 249/****************************** Some noise ******************************/
174 250
@@ -179,6 +255,7 @@ static __refdata struct usb_composite_driver msg_driver = {
179 .needs_serial = 1, 255 .needs_serial = 1,
180 .strings = dev_strings, 256 .strings = dev_strings,
181 .bind = msg_bind, 257 .bind = msg_bind,
258 .unbind = msg_unbind,
182}; 259};
183 260
184MODULE_DESCRIPTION(DRIVER_DESC); 261MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 2a1ebefd8f9e..4fdaa54a2a2a 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -15,6 +15,7 @@
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/netdevice.h>
18 19
19#include "u_serial.h" 20#include "u_serial.h"
20#if defined USB_ETH_RNDIS 21#if defined USB_ETH_RNDIS
@@ -32,22 +33,11 @@ MODULE_AUTHOR("Michal Nazarewicz");
32MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
33 34
34 35
35/***************************** All the files... *****************************/ 36#include "f_mass_storage.h"
36 37
37/* 38#include "u_ecm.h"
38 * kbuild is not very cooperative with respect to linking separately
39 * compiled library objects into one module. So for now we won't use
40 * separate compilation ... ensuring init/exit sections work to shrink
41 * the runtime footprint, and giving us at least some parts of what
42 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
43 */
44#include "f_mass_storage.c"
45
46#define USBF_ECM_INCLUDED
47#include "f_ecm.c"
48#ifdef USB_ETH_RNDIS 39#ifdef USB_ETH_RNDIS
49# define USB_FRNDIS_INCLUDED 40# include "u_rndis.h"
50# include "f_rndis.c"
51# include "rndis.h" 41# include "rndis.h"
52#endif 42#endif
53#include "u_ether.h" 43#include "u_ether.h"
@@ -132,22 +122,36 @@ static struct usb_gadget_strings *dev_strings[] = {
132/****************************** Configurations ******************************/ 122/****************************** Configurations ******************************/
133 123
134static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; 124static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
135FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); 125#ifdef CONFIG_USB_GADGET_DEBUG_FILES
126
127static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
136 128
137static struct fsg_common fsg_common; 129#else
130
131/*
132 * Number of buffers we will use.
133 * 2 is usually enough for good buffering pipeline
134 */
135#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
138 136
139static u8 host_mac[ETH_ALEN]; 137#endif /* CONFIG_USB_DEBUG */
138
139FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
140 140
141static struct usb_function_instance *fi_acm; 141static struct usb_function_instance *fi_acm;
142static struct eth_dev *the_dev; 142static struct usb_function_instance *fi_msg;
143 143
144/********** RNDIS **********/ 144/********** RNDIS **********/
145 145
146#ifdef USB_ETH_RNDIS 146#ifdef USB_ETH_RNDIS
147static struct usb_function_instance *fi_rndis;
147static struct usb_function *f_acm_rndis; 148static struct usb_function *f_acm_rndis;
149static struct usb_function *f_rndis;
150static struct usb_function *f_msg_rndis;
148 151
149static __init int rndis_do_config(struct usb_configuration *c) 152static __init int rndis_do_config(struct usb_configuration *c)
150{ 153{
154 struct fsg_opts *fsg_opts;
151 int ret; 155 int ret;
152 156
153 if (gadget_is_otg(c->cdev->gadget)) { 157 if (gadget_is_otg(c->cdev->gadget)) {
@@ -155,31 +159,54 @@ static __init int rndis_do_config(struct usb_configuration *c)
155 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 159 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
156 } 160 }
157 161
158 ret = rndis_bind_config(c, host_mac, the_dev); 162 f_rndis = usb_get_function(fi_rndis);
163 if (IS_ERR(f_rndis))
164 return PTR_ERR(f_rndis);
165
166 ret = usb_add_function(c, f_rndis);
159 if (ret < 0) 167 if (ret < 0)
160 return ret; 168 goto err_func_rndis;
161 169
162 f_acm_rndis = usb_get_function(fi_acm); 170 f_acm_rndis = usb_get_function(fi_acm);
163 if (IS_ERR(f_acm_rndis)) 171 if (IS_ERR(f_acm_rndis)) {
164 return PTR_ERR(f_acm_rndis); 172 ret = PTR_ERR(f_acm_rndis);
173 goto err_func_acm;
174 }
165 175
166 ret = usb_add_function(c, f_acm_rndis); 176 ret = usb_add_function(c, f_acm_rndis);
167 if (ret) 177 if (ret)
168 goto err_conf; 178 goto err_conf;
169 179
170 ret = fsg_bind_config(c->cdev, c, &fsg_common); 180 f_msg_rndis = usb_get_function(fi_msg);
171 if (ret < 0) 181 if (IS_ERR(f_msg_rndis)) {
182 ret = PTR_ERR(f_msg_rndis);
172 goto err_fsg; 183 goto err_fsg;
184 }
185
186 fsg_opts = fsg_opts_from_func_inst(fi_msg);
187 ret = fsg_common_run_thread(fsg_opts->common);
188 if (ret)
189 goto err_run;
190
191 ret = usb_add_function(c, f_msg_rndis);
192 if (ret)
193 goto err_run;
173 194
174 return 0; 195 return 0;
196err_run:
197 usb_put_function(f_msg_rndis);
175err_fsg: 198err_fsg:
176 usb_remove_function(c, f_acm_rndis); 199 usb_remove_function(c, f_acm_rndis);
177err_conf: 200err_conf:
178 usb_put_function(f_acm_rndis); 201 usb_put_function(f_acm_rndis);
202err_func_acm:
203 usb_remove_function(c, f_rndis);
204err_func_rndis:
205 usb_put_function(f_rndis);
179 return ret; 206 return ret;
180} 207}
181 208
182static int rndis_config_register(struct usb_composite_dev *cdev) 209static __ref int rndis_config_register(struct usb_composite_dev *cdev)
183{ 210{
184 static struct usb_configuration config = { 211 static struct usb_configuration config = {
185 .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM, 212 .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM,
@@ -194,7 +221,7 @@ static int rndis_config_register(struct usb_composite_dev *cdev)
194 221
195#else 222#else
196 223
197static int rndis_config_register(struct usb_composite_dev *cdev) 224static __ref int rndis_config_register(struct usb_composite_dev *cdev)
198{ 225{
199 return 0; 226 return 0;
200} 227}
@@ -205,10 +232,14 @@ static int rndis_config_register(struct usb_composite_dev *cdev)
205/********** CDC ECM **********/ 232/********** CDC ECM **********/
206 233
207#ifdef CONFIG_USB_G_MULTI_CDC 234#ifdef CONFIG_USB_G_MULTI_CDC
235static struct usb_function_instance *fi_ecm;
208static struct usb_function *f_acm_multi; 236static struct usb_function *f_acm_multi;
237static struct usb_function *f_ecm;
238static struct usb_function *f_msg_multi;
209 239
210static __init int cdc_do_config(struct usb_configuration *c) 240static __init int cdc_do_config(struct usb_configuration *c)
211{ 241{
242 struct fsg_opts *fsg_opts;
212 int ret; 243 int ret;
213 244
214 if (gadget_is_otg(c->cdev->gadget)) { 245 if (gadget_is_otg(c->cdev->gadget)) {
@@ -216,32 +247,55 @@ static __init int cdc_do_config(struct usb_configuration *c)
216 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 247 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
217 } 248 }
218 249
219 ret = ecm_bind_config(c, host_mac, the_dev); 250 f_ecm = usb_get_function(fi_ecm);
251 if (IS_ERR(f_ecm))
252 return PTR_ERR(f_ecm);
253
254 ret = usb_add_function(c, f_ecm);
220 if (ret < 0) 255 if (ret < 0)
221 return ret; 256 goto err_func_ecm;
222 257
223 /* implicit port_num is zero */ 258 /* implicit port_num is zero */
224 f_acm_multi = usb_get_function(fi_acm); 259 f_acm_multi = usb_get_function(fi_acm);
225 if (IS_ERR(f_acm_multi)) 260 if (IS_ERR(f_acm_multi)) {
226 return PTR_ERR(f_acm_multi); 261 ret = PTR_ERR(f_acm_multi);
262 goto err_func_acm;
263 }
227 264
228 ret = usb_add_function(c, f_acm_multi); 265 ret = usb_add_function(c, f_acm_multi);
229 if (ret) 266 if (ret)
230 goto err_conf; 267 goto err_conf;
231 268
232 ret = fsg_bind_config(c->cdev, c, &fsg_common); 269 f_msg_multi = usb_get_function(fi_msg);
233 if (ret < 0) 270 if (IS_ERR(f_msg_multi)) {
271 ret = PTR_ERR(f_msg_multi);
234 goto err_fsg; 272 goto err_fsg;
273 }
274
275 fsg_opts = fsg_opts_from_func_inst(fi_msg);
276 ret = fsg_common_run_thread(fsg_opts->common);
277 if (ret)
278 goto err_run;
279
280 ret = usb_add_function(c, f_msg_multi);
281 if (ret)
282 goto err_run;
235 283
236 return 0; 284 return 0;
285err_run:
286 usb_put_function(f_msg_multi);
237err_fsg: 287err_fsg:
238 usb_remove_function(c, f_acm_multi); 288 usb_remove_function(c, f_acm_multi);
239err_conf: 289err_conf:
240 usb_put_function(f_acm_multi); 290 usb_put_function(f_acm_multi);
291err_func_acm:
292 usb_remove_function(c, f_ecm);
293err_func_ecm:
294 usb_put_function(f_ecm);
241 return ret; 295 return ret;
242} 296}
243 297
244static int cdc_config_register(struct usb_composite_dev *cdev) 298static __ref int cdc_config_register(struct usb_composite_dev *cdev)
245{ 299{
246 static struct usb_configuration config = { 300 static struct usb_configuration config = {
247 .bConfigurationValue = MULTI_CDC_CONFIG_NUM, 301 .bConfigurationValue = MULTI_CDC_CONFIG_NUM,
@@ -256,7 +310,7 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
256 310
257#else 311#else
258 312
259static int cdc_config_register(struct usb_composite_dev *cdev) 313static __ref int cdc_config_register(struct usb_composite_dev *cdev)
260{ 314{
261 return 0; 315 return 0;
262} 316}
@@ -270,19 +324,67 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
270static int __ref multi_bind(struct usb_composite_dev *cdev) 324static int __ref multi_bind(struct usb_composite_dev *cdev)
271{ 325{
272 struct usb_gadget *gadget = cdev->gadget; 326 struct usb_gadget *gadget = cdev->gadget;
327#ifdef CONFIG_USB_G_MULTI_CDC
328 struct f_ecm_opts *ecm_opts;
329#endif
330#ifdef USB_ETH_RNDIS
331 struct f_rndis_opts *rndis_opts;
332#endif
333 struct fsg_opts *fsg_opts;
334 struct fsg_config config;
273 int status; 335 int status;
274 336
275 if (!can_support_ecm(cdev->gadget)) { 337 if (!can_support_ecm(cdev->gadget)) {
276 dev_err(&gadget->dev, "controller '%s' not usable\n", 338 dev_err(&gadget->dev, "controller '%s' not usable\n",
277 gadget->name); 339 gadget->name);
278 return -EINVAL; 340 return -EINVAL;
279 } 341 }
280 342
281 /* set up network link layer */ 343#ifdef CONFIG_USB_G_MULTI_CDC
282 the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac, 344 fi_ecm = usb_get_function_instance("ecm");
283 qmult); 345 if (IS_ERR(fi_ecm))
284 if (IS_ERR(the_dev)) 346 return PTR_ERR(fi_ecm);
285 return PTR_ERR(the_dev); 347
348 ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
349
350 gether_set_qmult(ecm_opts->net, qmult);
351 if (!gether_set_host_addr(ecm_opts->net, host_addr))
352 pr_info("using host ethernet address: %s", host_addr);
353 if (!gether_set_dev_addr(ecm_opts->net, dev_addr))
354 pr_info("using self ethernet address: %s", dev_addr);
355#endif
356
357#ifdef USB_ETH_RNDIS
358 fi_rndis = usb_get_function_instance("rndis");
359 if (IS_ERR(fi_rndis)) {
360 status = PTR_ERR(fi_rndis);
361 goto fail;
362 }
363
364 rndis_opts = container_of(fi_rndis, struct f_rndis_opts, func_inst);
365
366 gether_set_qmult(rndis_opts->net, qmult);
367 if (!gether_set_host_addr(rndis_opts->net, host_addr))
368 pr_info("using host ethernet address: %s", host_addr);
369 if (!gether_set_dev_addr(rndis_opts->net, dev_addr))
370 pr_info("using self ethernet address: %s", dev_addr);
371#endif
372
373#if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS)
374 /*
375 * If both ecm and rndis are selected then:
376 * 1) rndis borrows the net interface from ecm
377 * 2) since the interface is shared it must not be bound
378 * twice - in ecm's _and_ rndis' binds, so do it here.
379 */
380 gether_set_gadget(ecm_opts->net, cdev->gadget);
381 status = gether_register_netdev(ecm_opts->net);
382 if (status)
383 goto fail0;
384
385 rndis_borrow_net(fi_rndis, ecm_opts->net);
386 ecm_opts->bound = true;
387#endif
286 388
287 /* set up serial link layer */ 389 /* set up serial link layer */
288 fi_acm = usb_get_function_instance("acm"); 390 fi_acm = usb_get_function_instance("acm");
@@ -292,57 +394,102 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
292 } 394 }
293 395
294 /* set up mass storage function */ 396 /* set up mass storage function */
295 { 397 fi_msg = usb_get_function_instance("mass_storage");
296 void *retp; 398 if (IS_ERR(fi_msg)) {
297 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 399 status = PTR_ERR(fi_msg);
298 if (IS_ERR(retp)) { 400 goto fail1;
299 status = PTR_ERR(retp);
300 goto fail1;
301 }
302 } 401 }
402 fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers);
403 fsg_opts = fsg_opts_from_func_inst(fi_msg);
404
405 fsg_opts->no_configfs = true;
406 status = fsg_common_set_num_buffers(fsg_opts->common, fsg_num_buffers);
407 if (status)
408 goto fail2;
409
410 status = fsg_common_set_nluns(fsg_opts->common, config.nluns);
411 if (status)
412 goto fail_set_nluns;
413
414 status = fsg_common_set_cdev(fsg_opts->common, cdev, config.can_stall);
415 if (status)
416 goto fail_set_cdev;
417
418 fsg_common_set_sysfs(fsg_opts->common, true);
419 status = fsg_common_create_luns(fsg_opts->common, &config);
420 if (status)
421 goto fail_set_cdev;
422
423 fsg_common_set_inquiry_string(fsg_opts->common, config.vendor_name,
424 config.product_name);
303 425
304 /* allocate string IDs */ 426 /* allocate string IDs */
305 status = usb_string_ids_tab(cdev, strings_dev); 427 status = usb_string_ids_tab(cdev, strings_dev);
306 if (unlikely(status < 0)) 428 if (unlikely(status < 0))
307 goto fail2; 429 goto fail_string_ids;
308 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 430 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
309 431
310 /* register configurations */ 432 /* register configurations */
311 status = rndis_config_register(cdev); 433 status = rndis_config_register(cdev);
312 if (unlikely(status < 0)) 434 if (unlikely(status < 0))
313 goto fail2; 435 goto fail_string_ids;
314 436
315 status = cdc_config_register(cdev); 437 status = cdc_config_register(cdev);
316 if (unlikely(status < 0)) 438 if (unlikely(status < 0))
317 goto fail2; 439 goto fail_string_ids;
318 usb_composite_overwrite_options(cdev, &coverwrite); 440 usb_composite_overwrite_options(cdev, &coverwrite);
319 441
320 /* we're done */ 442 /* we're done */
321 dev_info(&gadget->dev, DRIVER_DESC "\n"); 443 dev_info(&gadget->dev, DRIVER_DESC "\n");
322 fsg_common_put(&fsg_common);
323 return 0; 444 return 0;
324 445
325 446
326 /* error recovery */ 447 /* error recovery */
448fail_string_ids:
449 fsg_common_remove_luns(fsg_opts->common);
450fail_set_cdev:
451 fsg_common_free_luns(fsg_opts->common);
452fail_set_nluns:
453 fsg_common_free_buffers(fsg_opts->common);
327fail2: 454fail2:
328 fsg_common_put(&fsg_common); 455 usb_put_function_instance(fi_msg);
329fail1: 456fail1:
330 usb_put_function_instance(fi_acm); 457 usb_put_function_instance(fi_acm);
331fail0: 458fail0:
332 gether_cleanup(the_dev); 459#ifdef USB_ETH_RNDIS
460 usb_put_function_instance(fi_rndis);
461fail:
462#endif
463#ifdef CONFIG_USB_G_MULTI_CDC
464 usb_put_function_instance(fi_ecm);
465#endif
333 return status; 466 return status;
334} 467}
335 468
336static int __exit multi_unbind(struct usb_composite_dev *cdev) 469static int __exit multi_unbind(struct usb_composite_dev *cdev)
337{ 470{
338#ifdef CONFIG_USB_G_MULTI_CDC 471#ifdef CONFIG_USB_G_MULTI_CDC
472 usb_put_function(f_msg_multi);
473#endif
474#ifdef USB_ETH_RNDIS
475 usb_put_function(f_msg_rndis);
476#endif
477 usb_put_function_instance(fi_msg);
478#ifdef CONFIG_USB_G_MULTI_CDC
339 usb_put_function(f_acm_multi); 479 usb_put_function(f_acm_multi);
340#endif 480#endif
341#ifdef USB_ETH_RNDIS 481#ifdef USB_ETH_RNDIS
342 usb_put_function(f_acm_rndis); 482 usb_put_function(f_acm_rndis);
343#endif 483#endif
344 usb_put_function_instance(fi_acm); 484 usb_put_function_instance(fi_acm);
345 gether_cleanup(the_dev); 485#ifdef USB_ETH_RNDIS
486 usb_put_function(f_rndis);
487 usb_put_function_instance(fi_rndis);
488#endif
489#ifdef CONFIG_USB_G_MULTI_CDC
490 usb_put_function(f_ecm);
491 usb_put_function_instance(fi_ecm);
492#endif
346 return 0; 493 return 0;
347} 494}
348 495
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c
index bbb6e98c4384..234711eabea1 100644
--- a/drivers/usb/gadget/mv_u3d_core.c
+++ b/drivers/usb/gadget/mv_u3d_core.c
@@ -310,6 +310,7 @@ static struct mv_u3d_trb *mv_u3d_build_trb_one(struct mv_u3d_req *req,
310 */ 310 */
311 trb_hw = dma_pool_alloc(u3d->trb_pool, GFP_ATOMIC, dma); 311 trb_hw = dma_pool_alloc(u3d->trb_pool, GFP_ATOMIC, dma);
312 if (!trb_hw) { 312 if (!trb_hw) {
313 kfree(trb);
313 dev_err(u3d->dev, 314 dev_err(u3d->dev,
314 "%s, dma_pool_alloc fail\n", __func__); 315 "%s, dma_pool_alloc fail\n", __func__);
315 return NULL; 316 return NULL;
@@ -454,6 +455,7 @@ static int mv_u3d_req_to_trb(struct mv_u3d_req *req)
454 455
455 trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC); 456 trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC);
456 if (!trb_hw) { 457 if (!trb_hw) {
458 kfree(trb);
457 dev_err(u3d->dev, 459 dev_err(u3d->dev,
458 "%s, trb_hw alloc fail\n", __func__); 460 "%s, trb_hw alloc fail\n", __func__);
459 return -ENOMEM; 461 return -ENOMEM;
@@ -645,6 +647,7 @@ static int mv_u3d_ep_disable(struct usb_ep *_ep)
645 struct mv_u3d_ep *ep; 647 struct mv_u3d_ep *ep;
646 struct mv_u3d_ep_context *ep_context; 648 struct mv_u3d_ep_context *ep_context;
647 u32 epxcr, direction; 649 u32 epxcr, direction;
650 unsigned long flags;
648 651
649 if (!_ep) 652 if (!_ep)
650 return -EINVAL; 653 return -EINVAL;
@@ -661,7 +664,9 @@ static int mv_u3d_ep_disable(struct usb_ep *_ep)
661 direction = mv_u3d_ep_dir(ep); 664 direction = mv_u3d_ep_dir(ep);
662 665
663 /* nuke all pending requests (does flush) */ 666 /* nuke all pending requests (does flush) */
667 spin_lock_irqsave(&u3d->lock, flags);
664 mv_u3d_nuke(ep, -ESHUTDOWN); 668 mv_u3d_nuke(ep, -ESHUTDOWN);
669 spin_unlock_irqrestore(&u3d->lock, flags);
665 670
666 /* Disable the endpoint for Rx or Tx and reset the endpoint type */ 671 /* Disable the endpoint for Rx or Tx and reset the endpoint type */
667 if (direction == MV_U3D_EP_DIR_OUT) { 672 if (direction == MV_U3D_EP_DIR_OUT) {
@@ -1933,7 +1938,7 @@ static int mv_u3d_probe(struct platform_device *dev)
1933 } 1938 }
1934 u3d->irq = r->start; 1939 u3d->irq = r->start;
1935 if (request_irq(u3d->irq, mv_u3d_irq, 1940 if (request_irq(u3d->irq, mv_u3d_irq,
1936 IRQF_DISABLED | IRQF_SHARED, driver_name, u3d)) { 1941 IRQF_SHARED, driver_name, u3d)) {
1937 u3d->irq = 0; 1942 u3d->irq = 0;
1938 dev_err(&dev->dev, "Request irq %d for u3d failed\n", 1943 dev_err(&dev->dev, "Request irq %d for u3d failed\n",
1939 u3d->irq); 1944 u3d->irq);
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 0781bff70015..fc852177c087 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -129,7 +129,7 @@ static char *type_string (u8 bmAttributes)
129 case USB_ENDPOINT_XFER_BULK: return "bulk"; 129 case USB_ENDPOINT_XFER_BULK: return "bulk";
130 case USB_ENDPOINT_XFER_ISOC: return "iso"; 130 case USB_ENDPOINT_XFER_ISOC: return "iso";
131 case USB_ENDPOINT_XFER_INT: return "intr"; 131 case USB_ENDPOINT_XFER_INT: return "intr";
132 }; 132 }
133 return "control"; 133 return "control";
134} 134}
135#endif 135#endif
@@ -1630,7 +1630,7 @@ static ssize_t queues_show(struct device *_dev, struct device_attribute *attr,
1630 val = "intr"; break; 1630 val = "intr"; break;
1631 default: 1631 default:
1632 val = "iso"; break; 1632 val = "iso"; break;
1633 }; val; }), 1633 } val; }),
1634 usb_endpoint_maxp (d) & 0x1fff, 1634 usb_endpoint_maxp (d) & 0x1fff,
1635 ep->dma ? "dma" : "pio", ep->fifo_size 1635 ep->dma ? "dma" : "pio", ep->fifo_size
1636 ); 1636 );
@@ -2680,7 +2680,6 @@ static void net2280_remove (struct pci_dev *pdev)
2680 if (dev->enabled) 2680 if (dev->enabled)
2681 pci_disable_device (pdev); 2681 pci_disable_device (pdev);
2682 device_remove_file (&pdev->dev, &dev_attr_registers); 2682 device_remove_file (&pdev->dev, &dev_attr_registers);
2683 pci_set_drvdata (pdev, NULL);
2684 2683
2685 INFO (dev, "unbind\n"); 2684 INFO (dev, "unbind\n");
2686} 2685}
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index 24174e1d1564..32d5e923750b 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -3080,7 +3080,6 @@ static void pch_udc_remove(struct pci_dev *pdev)
3080 if (dev->active) 3080 if (dev->active)
3081 pci_disable_device(pdev); 3081 pci_disable_device(pdev);
3082 kfree(dev); 3082 kfree(dev);
3083 pci_set_drvdata(pdev, NULL);
3084} 3083}
3085 3084
3086#ifdef CONFIG_PM 3085#ifdef CONFIG_PM
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index cc9207473dbc..0ac6064aa3b8 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -2054,7 +2054,7 @@ static struct pxa25x_udc memory = {
2054/* 2054/*
2055 * probe - binds to the platform device 2055 * probe - binds to the platform device
2056 */ 2056 */
2057static int __init pxa25x_udc_probe(struct platform_device *pdev) 2057static int pxa25x_udc_probe(struct platform_device *pdev)
2058{ 2058{
2059 struct pxa25x_udc *dev = &memory; 2059 struct pxa25x_udc *dev = &memory;
2060 int retval, irq; 2060 int retval, irq;
@@ -2203,7 +2203,7 @@ static void pxa25x_udc_shutdown(struct platform_device *_dev)
2203 pullup_off(); 2203 pullup_off();
2204} 2204}
2205 2205
2206static int __exit pxa25x_udc_remove(struct platform_device *pdev) 2206static int pxa25x_udc_remove(struct platform_device *pdev)
2207{ 2207{
2208 struct pxa25x_udc *dev = platform_get_drvdata(pdev); 2208 struct pxa25x_udc *dev = platform_get_drvdata(pdev);
2209 2209
@@ -2294,7 +2294,8 @@ static int pxa25x_udc_resume(struct platform_device *dev)
2294 2294
2295static struct platform_driver udc_driver = { 2295static struct platform_driver udc_driver = {
2296 .shutdown = pxa25x_udc_shutdown, 2296 .shutdown = pxa25x_udc_shutdown,
2297 .remove = __exit_p(pxa25x_udc_remove), 2297 .probe = pxa25x_udc_probe,
2298 .remove = pxa25x_udc_remove,
2298 .suspend = pxa25x_udc_suspend, 2299 .suspend = pxa25x_udc_suspend,
2299 .resume = pxa25x_udc_resume, 2300 .resume = pxa25x_udc_resume,
2300 .driver = { 2301 .driver = {
@@ -2303,7 +2304,7 @@ static struct platform_driver udc_driver = {
2303 }, 2304 },
2304}; 2305};
2305 2306
2306module_platform_driver_probe(udc_driver, pxa25x_udc_probe); 2307module_platform_driver(udc_driver);
2307 2308
2308MODULE_DESCRIPTION(DRIVER_DESC); 2309MODULE_DESCRIPTION(DRIVER_DESC);
2309MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell"); 2310MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 9575085ded81..a3ad732bc812 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -1068,7 +1068,7 @@ static int rndis_proc_show(struct seq_file *m, void *v)
1068 s = "RNDIS_INITIALIZED"; break; 1068 s = "RNDIS_INITIALIZED"; break;
1069 case RNDIS_DATA_INITIALIZED: 1069 case RNDIS_DATA_INITIALIZED:
1070 s = "RNDIS_DATA_INITIALIZED"; break; 1070 s = "RNDIS_DATA_INITIALIZED"; break;
1071 }; s; }), 1071 } s; }),
1072 param->medium, 1072 param->medium,
1073 (param->media_state) ? 0 : param->speed*100, 1073 (param->media_state) ? 0 : param->speed*100,
1074 (param->media_state) ? "disconnected" : "connected", 1074 (param->media_state) ? "disconnected" : "connected",
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index d69b36a99dbc..9875d9c0823f 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -83,9 +83,12 @@ struct s3c_hsotg_req;
83 * @dir_in: Set to true if this endpoint is of the IN direction, which 83 * @dir_in: Set to true if this endpoint is of the IN direction, which
84 * means that it is sending data to the Host. 84 * means that it is sending data to the Host.
85 * @index: The index for the endpoint registers. 85 * @index: The index for the endpoint registers.
86 * @mc: Multi Count - number of transactions per microframe
87 * @interval - Interval for periodic endpoints
86 * @name: The name array passed to the USB core. 88 * @name: The name array passed to the USB core.
87 * @halted: Set if the endpoint has been halted. 89 * @halted: Set if the endpoint has been halted.
88 * @periodic: Set if this is a periodic ep, such as Interrupt 90 * @periodic: Set if this is a periodic ep, such as Interrupt
91 * @isochronous: Set if this is a isochronous ep
89 * @sent_zlp: Set if we've sent a zero-length packet. 92 * @sent_zlp: Set if we've sent a zero-length packet.
90 * @total_data: The total number of data bytes done. 93 * @total_data: The total number of data bytes done.
91 * @fifo_size: The size of the FIFO (for periodic IN endpoints) 94 * @fifo_size: The size of the FIFO (for periodic IN endpoints)
@@ -121,9 +124,12 @@ struct s3c_hsotg_ep {
121 124
122 unsigned char dir_in; 125 unsigned char dir_in;
123 unsigned char index; 126 unsigned char index;
127 unsigned char mc;
128 unsigned char interval;
124 129
125 unsigned int halted:1; 130 unsigned int halted:1;
126 unsigned int periodic:1; 131 unsigned int periodic:1;
132 unsigned int isochronous:1;
127 unsigned int sent_zlp:1; 133 unsigned int sent_zlp:1;
128 134
129 char name[10]; 135 char name[10];
@@ -468,6 +474,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
468 void *data; 474 void *data;
469 int can_write; 475 int can_write;
470 int pkt_round; 476 int pkt_round;
477 int max_transfer;
471 478
472 to_write -= (buf_pos - hs_ep->last_load); 479 to_write -= (buf_pos - hs_ep->last_load);
473 480
@@ -535,15 +542,17 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
535 can_write *= 4; /* fifo size is in 32bit quantities. */ 542 can_write *= 4; /* fifo size is in 32bit quantities. */
536 } 543 }
537 544
538 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", 545 max_transfer = hs_ep->ep.maxpacket * hs_ep->mc;
539 __func__, gnptxsts, can_write, to_write, hs_ep->ep.maxpacket); 546
547 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n",
548 __func__, gnptxsts, can_write, to_write, max_transfer);
540 549
541 /* 550 /*
542 * limit to 512 bytes of data, it seems at least on the non-periodic 551 * limit to 512 bytes of data, it seems at least on the non-periodic
543 * FIFO, requests of >512 cause the endpoint to get stuck with a 552 * FIFO, requests of >512 cause the endpoint to get stuck with a
544 * fragment of the end of the transfer in it. 553 * fragment of the end of the transfer in it.
545 */ 554 */
546 if (can_write > 512) 555 if (can_write > 512 && !periodic)
547 can_write = 512; 556 can_write = 512;
548 557
549 /* 558 /*
@@ -551,19 +560,21 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
551 * the transfer to return that it did not run out of fifo space 560 * the transfer to return that it did not run out of fifo space
552 * doing it. 561 * doing it.
553 */ 562 */
554 if (to_write > hs_ep->ep.maxpacket) { 563 if (to_write > max_transfer) {
555 to_write = hs_ep->ep.maxpacket; 564 to_write = max_transfer;
556 565
557 s3c_hsotg_en_gsint(hsotg, 566 /* it's needed only when we do not use dedicated fifos */
558 periodic ? GINTSTS_PTxFEmp : 567 if (!hsotg->dedicated_fifos)
559 GINTSTS_NPTxFEmp); 568 s3c_hsotg_en_gsint(hsotg,
569 periodic ? GINTSTS_PTxFEmp :
570 GINTSTS_NPTxFEmp);
560 } 571 }
561 572
562 /* see if we can write data */ 573 /* see if we can write data */
563 574
564 if (to_write > can_write) { 575 if (to_write > can_write) {
565 to_write = can_write; 576 to_write = can_write;
566 pkt_round = to_write % hs_ep->ep.maxpacket; 577 pkt_round = to_write % max_transfer;
567 578
568 /* 579 /*
569 * Round the write down to an 580 * Round the write down to an
@@ -581,9 +592,11 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
581 * is more room left. 592 * is more room left.
582 */ 593 */
583 594
584 s3c_hsotg_en_gsint(hsotg, 595 /* it's needed only when we do not use dedicated fifos */
585 periodic ? GINTSTS_PTxFEmp : 596 if (!hsotg->dedicated_fifos)
586 GINTSTS_NPTxFEmp); 597 s3c_hsotg_en_gsint(hsotg,
598 periodic ? GINTSTS_PTxFEmp :
599 GINTSTS_NPTxFEmp);
587 } 600 }
588 601
589 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", 602 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n",
@@ -727,8 +740,16 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
727 else 740 else
728 packets = 1; /* send one packet if length is zero. */ 741 packets = 1; /* send one packet if length is zero. */
729 742
743 if (hs_ep->isochronous && length > (hs_ep->mc * hs_ep->ep.maxpacket)) {
744 dev_err(hsotg->dev, "req length > maxpacket*mc\n");
745 return;
746 }
747
730 if (dir_in && index != 0) 748 if (dir_in && index != 0)
731 epsize = DxEPTSIZ_MC(1); 749 if (hs_ep->isochronous)
750 epsize = DxEPTSIZ_MC(packets);
751 else
752 epsize = DxEPTSIZ_MC(1);
732 else 753 else
733 epsize = 0; 754 epsize = 0;
734 755
@@ -820,6 +841,9 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
820 841
821 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", 842 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n",
822 __func__, readl(hsotg->regs + epctrl_reg)); 843 __func__, readl(hsotg->regs + epctrl_reg));
844
845 /* enable ep interrupts */
846 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1);
823} 847}
824 848
825/** 849/**
@@ -1091,6 +1115,7 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1091 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); 1115 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE);
1092 struct s3c_hsotg_ep *ep; 1116 struct s3c_hsotg_ep *ep;
1093 int ret; 1117 int ret;
1118 bool halted;
1094 1119
1095 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", 1120 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n",
1096 __func__, set ? "SET" : "CLEAR"); 1121 __func__, set ? "SET" : "CLEAR");
@@ -1105,6 +1130,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1105 1130
1106 switch (le16_to_cpu(ctrl->wValue)) { 1131 switch (le16_to_cpu(ctrl->wValue)) {
1107 case USB_ENDPOINT_HALT: 1132 case USB_ENDPOINT_HALT:
1133 halted = ep->halted;
1134
1108 s3c_hsotg_ep_sethalt(&ep->ep, set); 1135 s3c_hsotg_ep_sethalt(&ep->ep, set);
1109 1136
1110 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); 1137 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0);
@@ -1114,7 +1141,12 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1114 return ret; 1141 return ret;
1115 } 1142 }
1116 1143
1117 if (!set) { 1144 /*
1145 * we have to complete all requests for ep if it was
1146 * halted, and the halt was cleared by CLEAR_FEATURE
1147 */
1148
1149 if (!set && halted) {
1118 /* 1150 /*
1119 * If we have request in progress, 1151 * If we have request in progress,
1120 * then complete it 1152 * then complete it
@@ -1147,6 +1179,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1147 return 1; 1179 return 1;
1148} 1180}
1149 1181
1182static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg);
1183
1150/** 1184/**
1151 * s3c_hsotg_process_control - process a control request 1185 * s3c_hsotg_process_control - process a control request
1152 * @hsotg: The device state 1186 * @hsotg: The device state
@@ -1246,11 +1280,15 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,
1246 * don't believe we need to anything more to get the EP 1280 * don't believe we need to anything more to get the EP
1247 * to reply with a STALL packet 1281 * to reply with a STALL packet
1248 */ 1282 */
1283
1284 /*
1285 * complete won't be called, so we enqueue
1286 * setup request here
1287 */
1288 s3c_hsotg_enqueue_setup(hsotg);
1249 } 1289 }
1250} 1290}
1251 1291
1252static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg);
1253
1254/** 1292/**
1255 * s3c_hsotg_complete_setup - completion of a setup transfer 1293 * s3c_hsotg_complete_setup - completion of a setup transfer
1256 * @ep: The endpoint the request was on. 1294 * @ep: The endpoint the request was on.
@@ -1698,6 +1736,7 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg,
1698 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; 1736 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep];
1699 void __iomem *regs = hsotg->regs; 1737 void __iomem *regs = hsotg->regs;
1700 u32 mpsval; 1738 u32 mpsval;
1739 u32 mcval;
1701 u32 reg; 1740 u32 reg;
1702 1741
1703 if (ep == 0) { 1742 if (ep == 0) {
@@ -1705,15 +1744,19 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg,
1705 mpsval = s3c_hsotg_ep0_mps(mps); 1744 mpsval = s3c_hsotg_ep0_mps(mps);
1706 if (mpsval > 3) 1745 if (mpsval > 3)
1707 goto bad_mps; 1746 goto bad_mps;
1747 hs_ep->ep.maxpacket = mps;
1748 hs_ep->mc = 1;
1708 } else { 1749 } else {
1709 if (mps >= DxEPCTL_MPS_LIMIT+1) 1750 mpsval = mps & DxEPCTL_MPS_MASK;
1751 if (mpsval > 1024)
1710 goto bad_mps; 1752 goto bad_mps;
1711 1753 mcval = ((mps >> 11) & 0x3) + 1;
1712 mpsval = mps; 1754 hs_ep->mc = mcval;
1755 if (mcval > 3)
1756 goto bad_mps;
1757 hs_ep->ep.maxpacket = mpsval;
1713 } 1758 }
1714 1759
1715 hs_ep->ep.maxpacket = mps;
1716
1717 /* 1760 /*
1718 * update both the in and out endpoint controldir_ registers, even 1761 * update both the in and out endpoint controldir_ registers, even
1719 * if one of the directions may not be in use. 1762 * if one of the directions may not be in use.
@@ -1782,8 +1825,16 @@ static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg,
1782{ 1825{
1783 struct s3c_hsotg_req *hs_req = hs_ep->req; 1826 struct s3c_hsotg_req *hs_req = hs_ep->req;
1784 1827
1785 if (!hs_ep->dir_in || !hs_req) 1828 if (!hs_ep->dir_in || !hs_req) {
1829 /**
1830 * if request is not enqueued, we disable interrupts
1831 * for endpoints, excepting ep0
1832 */
1833 if (hs_ep->index != 0)
1834 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index,
1835 hs_ep->dir_in, 0);
1786 return 0; 1836 return 0;
1837 }
1787 1838
1788 if (hs_req->req.actual < hs_req->req.length) { 1839 if (hs_req->req.actual < hs_req->req.length) {
1789 dev_dbg(hsotg->dev, "trying to write more for ep%d\n", 1840 dev_dbg(hsotg->dev, "trying to write more for ep%d\n",
@@ -1887,8 +1938,10 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1887 u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); 1938 u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx);
1888 u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx); 1939 u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx);
1889 u32 ints; 1940 u32 ints;
1941 u32 ctrl;
1890 1942
1891 ints = readl(hsotg->regs + epint_reg); 1943 ints = readl(hsotg->regs + epint_reg);
1944 ctrl = readl(hsotg->regs + epctl_reg);
1892 1945
1893 /* Clear endpoint interrupts */ 1946 /* Clear endpoint interrupts */
1894 writel(ints, hsotg->regs + epint_reg); 1947 writel(ints, hsotg->regs + epint_reg);
@@ -1897,6 +1950,14 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1897 __func__, idx, dir_in ? "in" : "out", ints); 1950 __func__, idx, dir_in ? "in" : "out", ints);
1898 1951
1899 if (ints & DxEPINT_XferCompl) { 1952 if (ints & DxEPINT_XferCompl) {
1953 if (hs_ep->isochronous && hs_ep->interval == 1) {
1954 if (ctrl & DxEPCTL_EOFrNum)
1955 ctrl |= DxEPCTL_SetEvenFr;
1956 else
1957 ctrl |= DxEPCTL_SetOddFr;
1958 writel(ctrl, hsotg->regs + epctl_reg);
1959 }
1960
1900 dev_dbg(hsotg->dev, 1961 dev_dbg(hsotg->dev,
1901 "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n", 1962 "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n",
1902 __func__, readl(hsotg->regs + epctl_reg), 1963 __func__, readl(hsotg->regs + epctl_reg),
@@ -1963,7 +2024,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1963 if (ints & DxEPINT_Back2BackSetup) 2024 if (ints & DxEPINT_Back2BackSetup)
1964 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); 2025 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__);
1965 2026
1966 if (dir_in) { 2027 if (dir_in && !hs_ep->isochronous) {
1967 /* not sure if this is important, but we'll clear it anyway */ 2028 /* not sure if this is important, but we'll clear it anyway */
1968 if (ints & DIEPMSK_INTknTXFEmpMsk) { 2029 if (ints & DIEPMSK_INTknTXFEmpMsk) {
1969 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", 2030 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n",
@@ -2092,12 +2153,14 @@ static void kill_all_requests(struct s3c_hsotg *hsotg,
2092} 2153}
2093 2154
2094#define call_gadget(_hs, _entry) \ 2155#define call_gadget(_hs, _entry) \
2156do { \
2095 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ 2157 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
2096 (_hs)->driver && (_hs)->driver->_entry) { \ 2158 (_hs)->driver && (_hs)->driver->_entry) { \
2097 spin_unlock(&_hs->lock); \ 2159 spin_unlock(&_hs->lock); \
2098 (_hs)->driver->_entry(&(_hs)->gadget); \ 2160 (_hs)->driver->_entry(&(_hs)->gadget); \
2099 spin_lock(&_hs->lock); \ 2161 spin_lock(&_hs->lock); \
2100 } 2162 } \
2163} while (0)
2101 2164
2102/** 2165/**
2103 * s3c_hsotg_disconnect - disconnect service 2166 * s3c_hsotg_disconnect - disconnect service
@@ -2241,15 +2304,19 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
2241 GAHBCFG_HBstLen_Incr4, 2304 GAHBCFG_HBstLen_Incr4,
2242 hsotg->regs + GAHBCFG); 2305 hsotg->regs + GAHBCFG);
2243 else 2306 else
2244 writel(GAHBCFG_GlblIntrEn, hsotg->regs + GAHBCFG); 2307 writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NPTxFEmpLvl |
2308 GAHBCFG_PTxFEmpLvl) : 0) |
2309 GAHBCFG_GlblIntrEn,
2310 hsotg->regs + GAHBCFG);
2245 2311
2246 /* 2312 /*
2247 * Enabling INTknTXFEmpMsk here seems to be a big mistake, we end 2313 * If INTknTXFEmpMsk is enabled, it's important to disable ep interrupts
2248 * up being flooded with interrupts if the host is polling the 2314 * when we have no data to transfer. Otherwise we get being flooded by
2249 * endpoint to try and read data. 2315 * interrupts.
2250 */ 2316 */
2251 2317
2252 writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty : 0) | 2318 writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty |
2319 DIEPMSK_INTknTXFEmpMsk : 0) |
2253 DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk | 2320 DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk |
2254 DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk | 2321 DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk |
2255 DIEPMSK_INTknEPMisMsk, 2322 DIEPMSK_INTknEPMisMsk,
@@ -2378,10 +2445,14 @@ irq_retry:
2378 2445
2379 if (gintsts & (GINTSTS_OEPInt | GINTSTS_IEPInt)) { 2446 if (gintsts & (GINTSTS_OEPInt | GINTSTS_IEPInt)) {
2380 u32 daint = readl(hsotg->regs + DAINT); 2447 u32 daint = readl(hsotg->regs + DAINT);
2381 u32 daint_out = daint >> DAINT_OutEP_SHIFT; 2448 u32 daintmsk = readl(hsotg->regs + DAINTMSK);
2382 u32 daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT); 2449 u32 daint_out, daint_in;
2383 int ep; 2450 int ep;
2384 2451
2452 daint &= daintmsk;
2453 daint_out = daint >> DAINT_OutEP_SHIFT;
2454 daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT);
2455
2385 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); 2456 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint);
2386 2457
2387 for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) { 2458 for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) {
@@ -2475,8 +2546,6 @@ irq_retry:
2475 if (gintsts & GINTSTS_ErlySusp) { 2546 if (gintsts & GINTSTS_ErlySusp) {
2476 dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); 2547 dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n");
2477 writel(GINTSTS_ErlySusp, hsotg->regs + GINTSTS); 2548 writel(GINTSTS_ErlySusp, hsotg->regs + GINTSTS);
2478
2479 s3c_hsotg_disconnect(hsotg);
2480 } 2549 }
2481 2550
2482 /* 2551 /*
@@ -2579,16 +2648,25 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2579 epctrl |= DxEPCTL_SNAK; 2648 epctrl |= DxEPCTL_SNAK;
2580 2649
2581 /* update the endpoint state */ 2650 /* update the endpoint state */
2582 hs_ep->ep.maxpacket = mps; 2651 s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps);
2583 2652
2584 /* default, set to non-periodic */ 2653 /* default, set to non-periodic */
2654 hs_ep->isochronous = 0;
2585 hs_ep->periodic = 0; 2655 hs_ep->periodic = 0;
2656 hs_ep->halted = 0;
2657 hs_ep->interval = desc->bInterval;
2658
2659 if (hs_ep->interval > 1 && hs_ep->mc > 1)
2660 dev_err(hsotg->dev, "MC > 1 when interval is not 1\n");
2586 2661
2587 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 2662 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
2588 case USB_ENDPOINT_XFER_ISOC: 2663 case USB_ENDPOINT_XFER_ISOC:
2589 dev_err(hsotg->dev, "no current ISOC support\n"); 2664 epctrl |= DxEPCTL_EPType_Iso;
2590 ret = -EINVAL; 2665 epctrl |= DxEPCTL_SetEvenFr;
2591 goto out; 2666 hs_ep->isochronous = 1;
2667 if (dir_in)
2668 hs_ep->periodic = 1;
2669 break;
2592 2670
2593 case USB_ENDPOINT_XFER_BULK: 2671 case USB_ENDPOINT_XFER_BULK:
2594 epctrl |= DxEPCTL_EPType_Bulk; 2672 epctrl |= DxEPCTL_EPType_Bulk;
@@ -2636,7 +2714,6 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2636 /* enable the endpoint interrupt */ 2714 /* enable the endpoint interrupt */
2637 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); 2715 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
2638 2716
2639out:
2640 spin_unlock_irqrestore(&hsotg->lock, flags); 2717 spin_unlock_irqrestore(&hsotg->lock, flags);
2641 return ret; 2718 return ret;
2642} 2719}
@@ -2778,6 +2855,8 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value)
2778 2855
2779 writel(epctl, hs->regs + epreg); 2856 writel(epctl, hs->regs + epreg);
2780 2857
2858 hs_ep->halted = value;
2859
2781 return 0; 2860 return 0;
2782} 2861}
2783 2862
@@ -2905,7 +2984,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
2905 int ret; 2984 int ret;
2906 2985
2907 if (!hsotg) { 2986 if (!hsotg) {
2908 printk(KERN_ERR "%s: called with no device\n", __func__); 2987 pr_err("%s: called with no device\n", __func__);
2909 return -ENODEV; 2988 return -ENODEV;
2910 } 2989 }
2911 2990
@@ -2962,9 +3041,6 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
2962 if (!hsotg) 3041 if (!hsotg)
2963 return -ENODEV; 3042 return -ENODEV;
2964 3043
2965 if (!driver || driver != hsotg->driver || !driver->unbind)
2966 return -EINVAL;
2967
2968 /* all endpoints should be shutdown */ 3044 /* all endpoints should be shutdown */
2969 for (ep = 0; ep < hsotg->num_of_eps; ep++) 3045 for (ep = 0; ep < hsotg->num_of_eps; ep++)
2970 s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); 3046 s3c_hsotg_ep_disable(&hsotg->eps[ep].ep);
@@ -2972,15 +3048,15 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
2972 spin_lock_irqsave(&hsotg->lock, flags); 3048 spin_lock_irqsave(&hsotg->lock, flags);
2973 3049
2974 s3c_hsotg_phy_disable(hsotg); 3050 s3c_hsotg_phy_disable(hsotg);
2975 regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
2976 3051
2977 hsotg->driver = NULL; 3052 if (!driver)
3053 hsotg->driver = NULL;
3054
2978 hsotg->gadget.speed = USB_SPEED_UNKNOWN; 3055 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
2979 3056
2980 spin_unlock_irqrestore(&hsotg->lock, flags); 3057 spin_unlock_irqrestore(&hsotg->lock, flags);
2981 3058
2982 dev_info(hsotg->dev, "unregistered gadget driver '%s'\n", 3059 regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
2983 driver->driver.name);
2984 3060
2985 return 0; 3061 return 0;
2986} 3062}
@@ -3071,7 +3147,7 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg,
3071 3147
3072 hs_ep->parent = hsotg; 3148 hs_ep->parent = hsotg;
3073 hs_ep->ep.name = hs_ep->name; 3149 hs_ep->ep.name = hs_ep->name;
3074 hs_ep->ep.maxpacket = epnum ? 512 : EP0_MPS_LIMIT; 3150 hs_ep->ep.maxpacket = epnum ? 1024 : EP0_MPS_LIMIT;
3075 hs_ep->ep.ops = &s3c_hsotg_ep_ops; 3151 hs_ep->ep.ops = &s3c_hsotg_ep_ops;
3076 3152
3077 /* 3153 /*
@@ -3205,7 +3281,7 @@ static int state_show(struct seq_file *seq, void *v)
3205 readl(regs + GNPTXSTS), 3281 readl(regs + GNPTXSTS),
3206 readl(regs + GRXSTSR)); 3282 readl(regs + GRXSTSR));
3207 3283
3208 seq_printf(seq, "\nEndpoint status:\n"); 3284 seq_puts(seq, "\nEndpoint status:\n");
3209 3285
3210 for (idx = 0; idx < 15; idx++) { 3286 for (idx = 0; idx < 15; idx++) {
3211 u32 in, out; 3287 u32 in, out;
@@ -3222,7 +3298,7 @@ static int state_show(struct seq_file *seq, void *v)
3222 seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", 3298 seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x",
3223 in, out); 3299 in, out);
3224 3300
3225 seq_printf(seq, "\n"); 3301 seq_puts(seq, "\n");
3226 } 3302 }
3227 3303
3228 return 0; 3304 return 0;
@@ -3256,7 +3332,7 @@ static int fifo_show(struct seq_file *seq, void *v)
3256 u32 val; 3332 u32 val;
3257 int idx; 3333 int idx;
3258 3334
3259 seq_printf(seq, "Non-periodic FIFOs:\n"); 3335 seq_puts(seq, "Non-periodic FIFOs:\n");
3260 seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); 3336 seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ));
3261 3337
3262 val = readl(regs + GNPTXFSIZ); 3338 val = readl(regs + GNPTXFSIZ);
@@ -3264,7 +3340,7 @@ static int fifo_show(struct seq_file *seq, void *v)
3264 val >> GNPTXFSIZ_NPTxFDep_SHIFT, 3340 val >> GNPTXFSIZ_NPTxFDep_SHIFT,
3265 val & GNPTXFSIZ_NPTxFStAddr_MASK); 3341 val & GNPTXFSIZ_NPTxFStAddr_MASK);
3266 3342
3267 seq_printf(seq, "\nPeriodic TXFIFOs:\n"); 3343 seq_puts(seq, "\nPeriodic TXFIFOs:\n");
3268 3344
3269 for (idx = 1; idx <= 15; idx++) { 3345 for (idx = 1; idx <= 15; idx++) {
3270 val = readl(regs + DPTXFSIZn(idx)); 3346 val = readl(regs + DPTXFSIZn(idx));
@@ -3335,7 +3411,7 @@ static int ep_show(struct seq_file *seq, void *v)
3335 readl(regs + DIEPTSIZ(index)), 3411 readl(regs + DIEPTSIZ(index)),
3336 readl(regs + DOEPTSIZ(index))); 3412 readl(regs + DOEPTSIZ(index)));
3337 3413
3338 seq_printf(seq, "\n"); 3414 seq_puts(seq, "\n");
3339 seq_printf(seq, "mps %d\n", ep->ep.maxpacket); 3415 seq_printf(seq, "mps %d\n", ep->ep.maxpacket);
3340 seq_printf(seq, "total_data=%ld\n", ep->total_data); 3416 seq_printf(seq, "total_data=%ld\n", ep->total_data);
3341 3417
@@ -3346,7 +3422,7 @@ static int ep_show(struct seq_file *seq, void *v)
3346 3422
3347 list_for_each_entry(req, &ep->queue, queue) { 3423 list_for_each_entry(req, &ep->queue, queue) {
3348 if (--show_limit < 0) { 3424 if (--show_limit < 0) {
3349 seq_printf(seq, "not showing more requests...\n"); 3425 seq_puts(seq, "not showing more requests...\n");
3350 break; 3426 break;
3351 } 3427 }
3352 3428
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 08a1a3210a21..ec20a1f50c2d 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -23,242 +23,17 @@
23 * The valid range of num_buffers is: num >= 2 && num <= 4. 23 * The valid range of num_buffers is: num >= 2 && num <= 4.
24 */ 24 */
25 25
26#include <linux/module.h>
27#include <linux/blkdev.h>
28#include <linux/file.h>
29#include <linux/fs.h>
30#include <linux/usb/composite.h>
26 31
27#include <linux/usb/storage.h> 32#include "storage_common.h"
28#include <scsi/scsi.h>
29#include <asm/unaligned.h>
30
31
32/*
33 * Thanks to NetChip Technologies for donating this product ID.
34 *
35 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
36 * Instead: allocate your own, using normal USB-IF procedures.
37 */
38#define FSG_VENDOR_ID 0x0525 /* NetChip */
39#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
40
41
42/*-------------------------------------------------------------------------*/
43
44
45#ifndef DEBUG
46#undef VERBOSE_DEBUG
47#undef DUMP_MSGS
48#endif /* !DEBUG */
49
50#ifdef VERBOSE_DEBUG
51#define VLDBG LDBG
52#else
53#define VLDBG(lun, fmt, args...) do { } while (0)
54#endif /* VERBOSE_DEBUG */
55
56#define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args)
57#define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args)
58#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args)
59#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args)
60
61
62#ifdef DUMP_MSGS
63
64# define dump_msg(fsg, /* const char * */ label, \
65 /* const u8 * */ buf, /* unsigned */ length) do { \
66 if (length < 512) { \
67 DBG(fsg, "%s, length %u:\n", label, length); \
68 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
69 16, 1, buf, length, 0); \
70 } \
71} while (0)
72
73# define dump_cdb(fsg) do { } while (0)
74
75#else
76
77# define dump_msg(fsg, /* const char * */ label, \
78 /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
79
80# ifdef VERBOSE_DEBUG
81
82# define dump_cdb(fsg) \
83 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
84 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
85
86# else
87
88# define dump_cdb(fsg) do { } while (0)
89
90# endif /* VERBOSE_DEBUG */
91
92#endif /* DUMP_MSGS */
93
94/*-------------------------------------------------------------------------*/
95
96/* Length of a SCSI Command Data Block */
97#define MAX_COMMAND_SIZE 16
98
99/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
100#define SS_NO_SENSE 0
101#define SS_COMMUNICATION_FAILURE 0x040800
102#define SS_INVALID_COMMAND 0x052000
103#define SS_INVALID_FIELD_IN_CDB 0x052400
104#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
105#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
106#define SS_MEDIUM_NOT_PRESENT 0x023a00
107#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
108#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
109#define SS_RESET_OCCURRED 0x062900
110#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
111#define SS_UNRECOVERED_READ_ERROR 0x031100
112#define SS_WRITE_ERROR 0x030c02
113#define SS_WRITE_PROTECTED 0x072700
114
115#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
116#define ASC(x) ((u8) ((x) >> 8))
117#define ASCQ(x) ((u8) (x))
118
119
120/*-------------------------------------------------------------------------*/
121
122
123struct fsg_lun {
124 struct file *filp;
125 loff_t file_length;
126 loff_t num_sectors;
127
128 unsigned int initially_ro:1;
129 unsigned int ro:1;
130 unsigned int removable:1;
131 unsigned int cdrom:1;
132 unsigned int prevent_medium_removal:1;
133 unsigned int registered:1;
134 unsigned int info_valid:1;
135 unsigned int nofua:1;
136
137 u32 sense_data;
138 u32 sense_data_info;
139 u32 unit_attention_data;
140
141 unsigned int blkbits; /* Bits of logical block size of bound block device */
142 unsigned int blksize; /* logical block size of bound block device */
143 struct device dev;
144};
145
146static inline bool fsg_lun_is_open(struct fsg_lun *curlun)
147{
148 return curlun->filp != NULL;
149}
150
151static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
152{
153 return container_of(dev, struct fsg_lun, dev);
154}
155
156
157/* Big enough to hold our biggest descriptor */
158#define EP0_BUFSIZE 256
159#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */
160
161#ifdef CONFIG_USB_GADGET_DEBUG_FILES
162
163static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
164module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);
165MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers");
166
167#else
168
169/*
170 * Number of buffers we will use.
171 * 2 is usually enough for good buffering pipeline
172 */
173#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
174
175#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
176
177/* check if fsg_num_buffers is within a valid range */
178static inline int fsg_num_buffers_validate(void)
179{
180 if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4)
181 return 0;
182 pr_err("fsg_num_buffers %u is out of range (%d to %d)\n",
183 fsg_num_buffers, 2 ,4);
184 return -EINVAL;
185}
186
187/* Default size of buffer length. */
188#define FSG_BUFLEN ((u32)16384)
189
190/* Maximal number of LUNs supported in mass storage function */
191#define FSG_MAX_LUNS 8
192
193enum fsg_buffer_state {
194 BUF_STATE_EMPTY = 0,
195 BUF_STATE_FULL,
196 BUF_STATE_BUSY
197};
198
199struct fsg_buffhd {
200 void *buf;
201 enum fsg_buffer_state state;
202 struct fsg_buffhd *next;
203
204 /*
205 * The NetChip 2280 is faster, and handles some protocol faults
206 * better, if we don't submit any short bulk-out read requests.
207 * So we will record the intended request length here.
208 */
209 unsigned int bulk_out_intended_length;
210
211 struct usb_request *inreq;
212 int inreq_busy;
213 struct usb_request *outreq;
214 int outreq_busy;
215};
216
217enum fsg_state {
218 /* This one isn't used anywhere */
219 FSG_STATE_COMMAND_PHASE = -10,
220 FSG_STATE_DATA_PHASE,
221 FSG_STATE_STATUS_PHASE,
222
223 FSG_STATE_IDLE = 0,
224 FSG_STATE_ABORT_BULK_OUT,
225 FSG_STATE_RESET,
226 FSG_STATE_INTERFACE_CHANGE,
227 FSG_STATE_CONFIG_CHANGE,
228 FSG_STATE_DISCONNECT,
229 FSG_STATE_EXIT,
230 FSG_STATE_TERMINATED
231};
232
233enum data_direction {
234 DATA_DIR_UNKNOWN = 0,
235 DATA_DIR_FROM_HOST,
236 DATA_DIR_TO_HOST,
237 DATA_DIR_NONE
238};
239
240
241/*-------------------------------------------------------------------------*/
242
243
244static inline u32 get_unaligned_be24(u8 *buf)
245{
246 return 0xffffff & (u32) get_unaligned_be32(buf - 1);
247}
248
249
250/*-------------------------------------------------------------------------*/
251
252
253enum {
254 FSG_STRING_INTERFACE
255};
256
257 33
258/* There is only one interface. */ 34/* There is only one interface. */
259 35
260static struct usb_interface_descriptor 36struct usb_interface_descriptor fsg_intf_desc = {
261fsg_intf_desc = {
262 .bLength = sizeof fsg_intf_desc, 37 .bLength = sizeof fsg_intf_desc,
263 .bDescriptorType = USB_DT_INTERFACE, 38 .bDescriptorType = USB_DT_INTERFACE,
264 39
@@ -268,14 +43,14 @@ fsg_intf_desc = {
268 .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ 43 .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */
269 .iInterface = FSG_STRING_INTERFACE, 44 .iInterface = FSG_STRING_INTERFACE,
270}; 45};
46EXPORT_SYMBOL(fsg_intf_desc);
271 47
272/* 48/*
273 * Three full-speed endpoint descriptors: bulk-in, bulk-out, and 49 * Three full-speed endpoint descriptors: bulk-in, bulk-out, and
274 * interrupt-in. 50 * interrupt-in.
275 */ 51 */
276 52
277static struct usb_endpoint_descriptor 53struct usb_endpoint_descriptor fsg_fs_bulk_in_desc = {
278fsg_fs_bulk_in_desc = {
279 .bLength = USB_DT_ENDPOINT_SIZE, 54 .bLength = USB_DT_ENDPOINT_SIZE,
280 .bDescriptorType = USB_DT_ENDPOINT, 55 .bDescriptorType = USB_DT_ENDPOINT,
281 56
@@ -283,9 +58,9 @@ fsg_fs_bulk_in_desc = {
283 .bmAttributes = USB_ENDPOINT_XFER_BULK, 58 .bmAttributes = USB_ENDPOINT_XFER_BULK,
284 /* wMaxPacketSize set by autoconfiguration */ 59 /* wMaxPacketSize set by autoconfiguration */
285}; 60};
61EXPORT_SYMBOL(fsg_fs_bulk_in_desc);
286 62
287static struct usb_endpoint_descriptor 63struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = {
288fsg_fs_bulk_out_desc = {
289 .bLength = USB_DT_ENDPOINT_SIZE, 64 .bLength = USB_DT_ENDPOINT_SIZE,
290 .bDescriptorType = USB_DT_ENDPOINT, 65 .bDescriptorType = USB_DT_ENDPOINT,
291 66
@@ -293,13 +68,15 @@ fsg_fs_bulk_out_desc = {
293 .bmAttributes = USB_ENDPOINT_XFER_BULK, 68 .bmAttributes = USB_ENDPOINT_XFER_BULK,
294 /* wMaxPacketSize set by autoconfiguration */ 69 /* wMaxPacketSize set by autoconfiguration */
295}; 70};
71EXPORT_SYMBOL(fsg_fs_bulk_out_desc);
296 72
297static struct usb_descriptor_header *fsg_fs_function[] = { 73struct usb_descriptor_header *fsg_fs_function[] = {
298 (struct usb_descriptor_header *) &fsg_intf_desc, 74 (struct usb_descriptor_header *) &fsg_intf_desc,
299 (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc, 75 (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
300 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, 76 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
301 NULL, 77 NULL,
302}; 78};
79EXPORT_SYMBOL(fsg_fs_function);
303 80
304 81
305/* 82/*
@@ -310,8 +87,7 @@ static struct usb_descriptor_header *fsg_fs_function[] = {
310 * and a "device qualifier" ... plus more construction options 87 * and a "device qualifier" ... plus more construction options
311 * for the configuration descriptor. 88 * for the configuration descriptor.
312 */ 89 */
313static struct usb_endpoint_descriptor 90struct usb_endpoint_descriptor fsg_hs_bulk_in_desc = {
314fsg_hs_bulk_in_desc = {
315 .bLength = USB_DT_ENDPOINT_SIZE, 91 .bLength = USB_DT_ENDPOINT_SIZE,
316 .bDescriptorType = USB_DT_ENDPOINT, 92 .bDescriptorType = USB_DT_ENDPOINT,
317 93
@@ -319,9 +95,9 @@ fsg_hs_bulk_in_desc = {
319 .bmAttributes = USB_ENDPOINT_XFER_BULK, 95 .bmAttributes = USB_ENDPOINT_XFER_BULK,
320 .wMaxPacketSize = cpu_to_le16(512), 96 .wMaxPacketSize = cpu_to_le16(512),
321}; 97};
98EXPORT_SYMBOL(fsg_hs_bulk_in_desc);
322 99
323static struct usb_endpoint_descriptor 100struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = {
324fsg_hs_bulk_out_desc = {
325 .bLength = USB_DT_ENDPOINT_SIZE, 101 .bLength = USB_DT_ENDPOINT_SIZE,
326 .bDescriptorType = USB_DT_ENDPOINT, 102 .bDescriptorType = USB_DT_ENDPOINT,
327 103
@@ -330,17 +106,18 @@ fsg_hs_bulk_out_desc = {
330 .wMaxPacketSize = cpu_to_le16(512), 106 .wMaxPacketSize = cpu_to_le16(512),
331 .bInterval = 1, /* NAK every 1 uframe */ 107 .bInterval = 1, /* NAK every 1 uframe */
332}; 108};
109EXPORT_SYMBOL(fsg_hs_bulk_out_desc);
333 110
334 111
335static struct usb_descriptor_header *fsg_hs_function[] = { 112struct usb_descriptor_header *fsg_hs_function[] = {
336 (struct usb_descriptor_header *) &fsg_intf_desc, 113 (struct usb_descriptor_header *) &fsg_intf_desc,
337 (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc, 114 (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
338 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, 115 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
339 NULL, 116 NULL,
340}; 117};
118EXPORT_SYMBOL(fsg_hs_function);
341 119
342static struct usb_endpoint_descriptor 120struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = {
343fsg_ss_bulk_in_desc = {
344 .bLength = USB_DT_ENDPOINT_SIZE, 121 .bLength = USB_DT_ENDPOINT_SIZE,
345 .bDescriptorType = USB_DT_ENDPOINT, 122 .bDescriptorType = USB_DT_ENDPOINT,
346 123
@@ -348,16 +125,17 @@ fsg_ss_bulk_in_desc = {
348 .bmAttributes = USB_ENDPOINT_XFER_BULK, 125 .bmAttributes = USB_ENDPOINT_XFER_BULK,
349 .wMaxPacketSize = cpu_to_le16(1024), 126 .wMaxPacketSize = cpu_to_le16(1024),
350}; 127};
128EXPORT_SYMBOL(fsg_ss_bulk_in_desc);
351 129
352static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { 130struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = {
353 .bLength = sizeof(fsg_ss_bulk_in_comp_desc), 131 .bLength = sizeof(fsg_ss_bulk_in_comp_desc),
354 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 132 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
355 133
356 /*.bMaxBurst = DYNAMIC, */ 134 /*.bMaxBurst = DYNAMIC, */
357}; 135};
136EXPORT_SYMBOL(fsg_ss_bulk_in_comp_desc);
358 137
359static struct usb_endpoint_descriptor 138struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = {
360fsg_ss_bulk_out_desc = {
361 .bLength = USB_DT_ENDPOINT_SIZE, 139 .bLength = USB_DT_ENDPOINT_SIZE,
362 .bDescriptorType = USB_DT_ENDPOINT, 140 .bDescriptorType = USB_DT_ENDPOINT,
363 141
@@ -365,15 +143,17 @@ fsg_ss_bulk_out_desc = {
365 .bmAttributes = USB_ENDPOINT_XFER_BULK, 143 .bmAttributes = USB_ENDPOINT_XFER_BULK,
366 .wMaxPacketSize = cpu_to_le16(1024), 144 .wMaxPacketSize = cpu_to_le16(1024),
367}; 145};
146EXPORT_SYMBOL(fsg_ss_bulk_out_desc);
368 147
369static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { 148struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = {
370 .bLength = sizeof(fsg_ss_bulk_in_comp_desc), 149 .bLength = sizeof(fsg_ss_bulk_in_comp_desc),
371 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 150 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
372 151
373 /*.bMaxBurst = DYNAMIC, */ 152 /*.bMaxBurst = DYNAMIC, */
374}; 153};
154EXPORT_SYMBOL(fsg_ss_bulk_out_comp_desc);
375 155
376static struct usb_descriptor_header *fsg_ss_function[] = { 156struct usb_descriptor_header *fsg_ss_function[] = {
377 (struct usb_descriptor_header *) &fsg_intf_desc, 157 (struct usb_descriptor_header *) &fsg_intf_desc,
378 (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, 158 (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc,
379 (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc, 159 (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc,
@@ -381,17 +161,7 @@ static struct usb_descriptor_header *fsg_ss_function[] = {
381 (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, 161 (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc,
382 NULL, 162 NULL,
383}; 163};
384 164EXPORT_SYMBOL(fsg_ss_function);
385/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
386static struct usb_string fsg_strings[] = {
387 {FSG_STRING_INTERFACE, fsg_string_interface},
388 {}
389};
390
391static struct usb_gadget_strings fsg_stringtab = {
392 .language = 0x0409, /* en-us */
393 .strings = fsg_strings,
394};
395 165
396 166
397 /*-------------------------------------------------------------------------*/ 167 /*-------------------------------------------------------------------------*/
@@ -401,7 +171,7 @@ static struct usb_gadget_strings fsg_stringtab = {
401 * the caller must own fsg->filesem for writing. 171 * the caller must own fsg->filesem for writing.
402 */ 172 */
403 173
404static void fsg_lun_close(struct fsg_lun *curlun) 174void fsg_lun_close(struct fsg_lun *curlun)
405{ 175{
406 if (curlun->filp) { 176 if (curlun->filp) {
407 LDBG(curlun, "close backing file\n"); 177 LDBG(curlun, "close backing file\n");
@@ -409,9 +179,9 @@ static void fsg_lun_close(struct fsg_lun *curlun)
409 curlun->filp = NULL; 179 curlun->filp = NULL;
410 } 180 }
411} 181}
182EXPORT_SYMBOL(fsg_lun_close);
412 183
413 184int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
414static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
415{ 185{
416 int ro; 186 int ro;
417 struct file *filp = NULL; 187 struct file *filp = NULL;
@@ -508,6 +278,7 @@ out:
508 fput(filp); 278 fput(filp);
509 return rc; 279 return rc;
510} 280}
281EXPORT_SYMBOL(fsg_lun_open);
511 282
512 283
513/*-------------------------------------------------------------------------*/ 284/*-------------------------------------------------------------------------*/
@@ -516,7 +287,7 @@ out:
516 * Sync the file data, don't bother with the metadata. 287 * Sync the file data, don't bother with the metadata.
517 * This code was copied from fs/buffer.c:sys_fdatasync(). 288 * This code was copied from fs/buffer.c:sys_fdatasync().
518 */ 289 */
519static int fsg_lun_fsync_sub(struct fsg_lun *curlun) 290int fsg_lun_fsync_sub(struct fsg_lun *curlun)
520{ 291{
521 struct file *filp = curlun->filp; 292 struct file *filp = curlun->filp;
522 293
@@ -524,8 +295,9 @@ static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
524 return 0; 295 return 0;
525 return vfs_fsync(filp, 1); 296 return vfs_fsync(filp, 1);
526} 297}
298EXPORT_SYMBOL(fsg_lun_fsync_sub);
527 299
528static void store_cdrom_address(u8 *dest, int msf, u32 addr) 300void store_cdrom_address(u8 *dest, int msf, u32 addr)
529{ 301{
530 if (msf) { 302 if (msf) {
531 /* Convert to Minutes-Seconds-Frames */ 303 /* Convert to Minutes-Seconds-Frames */
@@ -542,34 +314,28 @@ static void store_cdrom_address(u8 *dest, int msf, u32 addr)
542 put_unaligned_be32(addr, dest); 314 put_unaligned_be32(addr, dest);
543 } 315 }
544} 316}
545 317EXPORT_SYMBOL(store_cdrom_address);
546 318
547/*-------------------------------------------------------------------------*/ 319/*-------------------------------------------------------------------------*/
548 320
549 321
550static ssize_t ro_show(struct device *dev, struct device_attribute *attr, 322ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf)
551 char *buf)
552{ 323{
553 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
554
555 return sprintf(buf, "%d\n", fsg_lun_is_open(curlun) 324 return sprintf(buf, "%d\n", fsg_lun_is_open(curlun)
556 ? curlun->ro 325 ? curlun->ro
557 : curlun->initially_ro); 326 : curlun->initially_ro);
558} 327}
328EXPORT_SYMBOL(fsg_show_ro);
559 329
560static ssize_t nofua_show(struct device *dev, struct device_attribute *attr, 330ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf)
561 char *buf)
562{ 331{
563 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
564
565 return sprintf(buf, "%u\n", curlun->nofua); 332 return sprintf(buf, "%u\n", curlun->nofua);
566} 333}
334EXPORT_SYMBOL(fsg_show_nofua);
567 335
568static ssize_t file_show(struct device *dev, struct device_attribute *attr, 336ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
569 char *buf) 337 char *buf)
570{ 338{
571 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
572 struct rw_semaphore *filesem = dev_get_drvdata(dev);
573 char *p; 339 char *p;
574 ssize_t rc; 340 ssize_t rc;
575 341
@@ -591,17 +357,44 @@ static ssize_t file_show(struct device *dev, struct device_attribute *attr,
591 up_read(filesem); 357 up_read(filesem);
592 return rc; 358 return rc;
593} 359}
360EXPORT_SYMBOL(fsg_show_file);
594 361
362ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf)
363{
364 return sprintf(buf, "%u\n", curlun->cdrom);
365}
366EXPORT_SYMBOL(fsg_show_cdrom);
595 367
596static ssize_t ro_store(struct device *dev, struct device_attribute *attr, 368ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf)
597 const char *buf, size_t count) 369{
370 return sprintf(buf, "%u\n", curlun->removable);
371}
372EXPORT_SYMBOL(fsg_show_removable);
373
374/*
375 * The caller must hold fsg->filesem for reading when calling this function.
376 */
377static ssize_t _fsg_store_ro(struct fsg_lun *curlun, bool ro)
378{
379 if (fsg_lun_is_open(curlun)) {
380 LDBG(curlun, "read-only status change prevented\n");
381 return -EBUSY;
382 }
383
384 curlun->ro = ro;
385 curlun->initially_ro = ro;
386 LDBG(curlun, "read-only status set to %d\n", curlun->ro);
387
388 return 0;
389}
390
391ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
392 const char *buf, size_t count)
598{ 393{
599 ssize_t rc; 394 ssize_t rc;
600 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 395 bool ro;
601 struct rw_semaphore *filesem = dev_get_drvdata(dev);
602 unsigned ro;
603 396
604 rc = kstrtouint(buf, 2, &ro); 397 rc = strtobool(buf, &ro);
605 if (rc) 398 if (rc)
606 return rc; 399 return rc;
607 400
@@ -610,27 +403,21 @@ static ssize_t ro_store(struct device *dev, struct device_attribute *attr,
610 * backing file is closed. 403 * backing file is closed.
611 */ 404 */
612 down_read(filesem); 405 down_read(filesem);
613 if (fsg_lun_is_open(curlun)) { 406 rc = _fsg_store_ro(curlun, ro);
614 LDBG(curlun, "read-only status change prevented\n"); 407 if (!rc)
615 rc = -EBUSY;
616 } else {
617 curlun->ro = ro;
618 curlun->initially_ro = ro;
619 LDBG(curlun, "read-only status set to %d\n", curlun->ro);
620 rc = count; 408 rc = count;
621 }
622 up_read(filesem); 409 up_read(filesem);
410
623 return rc; 411 return rc;
624} 412}
413EXPORT_SYMBOL(fsg_store_ro);
625 414
626static ssize_t nofua_store(struct device *dev, struct device_attribute *attr, 415ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count)
627 const char *buf, size_t count)
628{ 416{
629 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 417 bool nofua;
630 unsigned nofua;
631 int ret; 418 int ret;
632 419
633 ret = kstrtouint(buf, 2, &nofua); 420 ret = strtobool(buf, &nofua);
634 if (ret) 421 if (ret)
635 return ret; 422 return ret;
636 423
@@ -642,12 +429,11 @@ static ssize_t nofua_store(struct device *dev, struct device_attribute *attr,
642 429
643 return count; 430 return count;
644} 431}
432EXPORT_SYMBOL(fsg_store_nofua);
645 433
646static ssize_t file_store(struct device *dev, struct device_attribute *attr, 434ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
647 const char *buf, size_t count) 435 const char *buf, size_t count)
648{ 436{
649 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
650 struct rw_semaphore *filesem = dev_get_drvdata(dev);
651 int rc = 0; 437 int rc = 0;
652 438
653 if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) { 439 if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) {
@@ -674,3 +460,45 @@ static ssize_t file_store(struct device *dev, struct device_attribute *attr,
674 up_write(filesem); 460 up_write(filesem);
675 return (rc < 0 ? rc : count); 461 return (rc < 0 ? rc : count);
676} 462}
463EXPORT_SYMBOL(fsg_store_file);
464
465ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem,
466 const char *buf, size_t count)
467{
468 bool cdrom;
469 int ret;
470
471 ret = strtobool(buf, &cdrom);
472 if (ret)
473 return ret;
474
475 down_read(filesem);
476 ret = cdrom ? _fsg_store_ro(curlun, true) : 0;
477
478 if (!ret) {
479 curlun->cdrom = cdrom;
480 ret = count;
481 }
482 up_read(filesem);
483
484 return ret;
485}
486EXPORT_SYMBOL(fsg_store_cdrom);
487
488ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf,
489 size_t count)
490{
491 bool removable;
492 int ret;
493
494 ret = strtobool(buf, &removable);
495 if (ret)
496 return ret;
497
498 curlun->removable = removable;
499
500 return count;
501}
502EXPORT_SYMBOL(fsg_store_removable);
503
504MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/storage_common.h b/drivers/usb/gadget/storage_common.h
new file mode 100644
index 000000000000..c74c2fdbd56e
--- /dev/null
+++ b/drivers/usb/gadget/storage_common.h
@@ -0,0 +1,229 @@
1#ifndef USB_STORAGE_COMMON_H
2#define USB_STORAGE_COMMON_H
3
4#include <linux/device.h>
5#include <linux/usb/storage.h>
6#include <scsi/scsi.h>
7#include <asm/unaligned.h>
8
9#ifndef DEBUG
10#undef VERBOSE_DEBUG
11#undef DUMP_MSGS
12#endif /* !DEBUG */
13
14#ifdef VERBOSE_DEBUG
15#define VLDBG LDBG
16#else
17#define VLDBG(lun, fmt, args...) do { } while (0)
18#endif /* VERBOSE_DEBUG */
19
20#define _LMSG(func, lun, fmt, args...) \
21 do { \
22 if ((lun)->name_pfx && *(lun)->name_pfx) \
23 func("%s/%s: " fmt, *(lun)->name_pfx, \
24 (lun)->name, ## args); \
25 else \
26 func("%s: " fmt, (lun)->name, ## args); \
27 } while (0)
28
29#define LDBG(lun, fmt, args...) _LMSG(pr_debug, lun, fmt, ## args)
30#define LERROR(lun, fmt, args...) _LMSG(pr_err, lun, fmt, ## args)
31#define LWARN(lun, fmt, args...) _LMSG(pr_warn, lun, fmt, ## args)
32#define LINFO(lun, fmt, args...) _LMSG(pr_info, lun, fmt, ## args)
33
34
35#ifdef DUMP_MSGS
36
37# define dump_msg(fsg, /* const char * */ label, \
38 /* const u8 * */ buf, /* unsigned */ length) \
39do { \
40 if (length < 512) { \
41 DBG(fsg, "%s, length %u:\n", label, length); \
42 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
43 16, 1, buf, length, 0); \
44 } \
45} while (0)
46
47# define dump_cdb(fsg) do { } while (0)
48
49#else
50
51# define dump_msg(fsg, /* const char * */ label, \
52 /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
53
54# ifdef VERBOSE_DEBUG
55
56# define dump_cdb(fsg) \
57 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
58 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
59
60# else
61
62# define dump_cdb(fsg) do { } while (0)
63
64# endif /* VERBOSE_DEBUG */
65
66#endif /* DUMP_MSGS */
67
68/* Length of a SCSI Command Data Block */
69#define MAX_COMMAND_SIZE 16
70
71/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
72#define SS_NO_SENSE 0
73#define SS_COMMUNICATION_FAILURE 0x040800
74#define SS_INVALID_COMMAND 0x052000
75#define SS_INVALID_FIELD_IN_CDB 0x052400
76#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
77#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
78#define SS_MEDIUM_NOT_PRESENT 0x023a00
79#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
80#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
81#define SS_RESET_OCCURRED 0x062900
82#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
83#define SS_UNRECOVERED_READ_ERROR 0x031100
84#define SS_WRITE_ERROR 0x030c02
85#define SS_WRITE_PROTECTED 0x072700
86
87#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
88#define ASC(x) ((u8) ((x) >> 8))
89#define ASCQ(x) ((u8) (x))
90
91struct fsg_lun {
92 struct file *filp;
93 loff_t file_length;
94 loff_t num_sectors;
95
96 unsigned int initially_ro:1;
97 unsigned int ro:1;
98 unsigned int removable:1;
99 unsigned int cdrom:1;
100 unsigned int prevent_medium_removal:1;
101 unsigned int registered:1;
102 unsigned int info_valid:1;
103 unsigned int nofua:1;
104
105 u32 sense_data;
106 u32 sense_data_info;
107 u32 unit_attention_data;
108
109 unsigned int blkbits; /* Bits of logical block size
110 of bound block device */
111 unsigned int blksize; /* logical block size of bound block device */
112 struct device dev;
113 const char *name; /* "lun.name" */
114 const char **name_pfx; /* "function.name" */
115};
116
117static inline bool fsg_lun_is_open(struct fsg_lun *curlun)
118{
119 return curlun->filp != NULL;
120}
121
122/* Big enough to hold our biggest descriptor */
123#define EP0_BUFSIZE 256
124#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */
125
126/* Default size of buffer length. */
127#define FSG_BUFLEN ((u32)16384)
128
129/* Maximal number of LUNs supported in mass storage function */
130#define FSG_MAX_LUNS 8
131
132enum fsg_buffer_state {
133 BUF_STATE_EMPTY = 0,
134 BUF_STATE_FULL,
135 BUF_STATE_BUSY
136};
137
138struct fsg_buffhd {
139 void *buf;
140 enum fsg_buffer_state state;
141 struct fsg_buffhd *next;
142
143 /*
144 * The NetChip 2280 is faster, and handles some protocol faults
145 * better, if we don't submit any short bulk-out read requests.
146 * So we will record the intended request length here.
147 */
148 unsigned int bulk_out_intended_length;
149
150 struct usb_request *inreq;
151 int inreq_busy;
152 struct usb_request *outreq;
153 int outreq_busy;
154};
155
156enum fsg_state {
157 /* This one isn't used anywhere */
158 FSG_STATE_COMMAND_PHASE = -10,
159 FSG_STATE_DATA_PHASE,
160 FSG_STATE_STATUS_PHASE,
161
162 FSG_STATE_IDLE = 0,
163 FSG_STATE_ABORT_BULK_OUT,
164 FSG_STATE_RESET,
165 FSG_STATE_INTERFACE_CHANGE,
166 FSG_STATE_CONFIG_CHANGE,
167 FSG_STATE_DISCONNECT,
168 FSG_STATE_EXIT,
169 FSG_STATE_TERMINATED
170};
171
172enum data_direction {
173 DATA_DIR_UNKNOWN = 0,
174 DATA_DIR_FROM_HOST,
175 DATA_DIR_TO_HOST,
176 DATA_DIR_NONE
177};
178
179static inline u32 get_unaligned_be24(u8 *buf)
180{
181 return 0xffffff & (u32) get_unaligned_be32(buf - 1);
182}
183
184static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
185{
186 return container_of(dev, struct fsg_lun, dev);
187}
188
189enum {
190 FSG_STRING_INTERFACE
191};
192
193extern struct usb_interface_descriptor fsg_intf_desc;
194
195extern struct usb_endpoint_descriptor fsg_fs_bulk_in_desc;
196extern struct usb_endpoint_descriptor fsg_fs_bulk_out_desc;
197extern struct usb_descriptor_header *fsg_fs_function[];
198
199extern struct usb_endpoint_descriptor fsg_hs_bulk_in_desc;
200extern struct usb_endpoint_descriptor fsg_hs_bulk_out_desc;
201extern struct usb_descriptor_header *fsg_hs_function[];
202
203extern struct usb_endpoint_descriptor fsg_ss_bulk_in_desc;
204extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc;
205extern struct usb_endpoint_descriptor fsg_ss_bulk_out_desc;
206extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc;
207extern struct usb_descriptor_header *fsg_ss_function[];
208
209void fsg_lun_close(struct fsg_lun *curlun);
210int fsg_lun_open(struct fsg_lun *curlun, const char *filename);
211int fsg_lun_fsync_sub(struct fsg_lun *curlun);
212void store_cdrom_address(u8 *dest, int msf, u32 addr);
213ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf);
214ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf);
215ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
216 char *buf);
217ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf);
218ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf);
219ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
220 const char *buf, size_t count);
221ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count);
222ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
223 const char *buf, size_t count);
224ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem,
225 const char *buf, size_t count);
226ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf,
227 size_t count);
228
229#endif /* USB_STORAGE_COMMON_H */
diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c
index 0ff33396eef3..eccea1df702d 100644
--- a/drivers/usb/gadget/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/tcm_usb_gadget.c
@@ -472,7 +472,7 @@ static int usbg_bot_setup(struct usb_function *f,
472 bot_enqueue_cmd_cbw(fu); 472 bot_enqueue_cmd_cbw(fu);
473 return 0; 473 return 0;
474 break; 474 break;
475 }; 475 }
476 return -ENOTSUPP; 476 return -ENOTSUPP;
477} 477}
478 478
@@ -617,7 +617,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req)
617 617
618 default: 618 default:
619 BUG(); 619 BUG();
620 }; 620 }
621 return; 621 return;
622 622
623cleanup: 623cleanup:
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 59891b1c48fc..27768a7d986a 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -356,7 +356,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
356 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 356 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
357 return 0; 357 return 0;
358err1: 358err1:
359 dev_err(&udc->dev, "failed to start %s: %d\n", 359 if (ret != -EISNAM)
360 dev_err(&udc->dev, "failed to start %s: %d\n",
360 udc->driver->function, ret); 361 udc->driver->function, ret);
361 udc->driver = NULL; 362 udc->driver = NULL;
362 udc->dev.driver = NULL; 363 udc->dev.driver = NULL;
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 0deb9d6cde26..0dd07ae1555d 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -95,6 +95,18 @@ unsigned autoresume = DEFAULT_AUTORESUME;
95module_param(autoresume, uint, S_IRUGO); 95module_param(autoresume, uint, S_IRUGO);
96MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup"); 96MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup");
97 97
98/* Maximum Autoresume time */
99unsigned max_autoresume;
100module_param(max_autoresume, uint, S_IRUGO);
101MODULE_PARM_DESC(max_autoresume, "maximum seconds before remote wakeup");
102
103/* Interval between two remote wakeups */
104unsigned autoresume_interval_ms;
105module_param(autoresume_interval_ms, uint, S_IRUGO);
106MODULE_PARM_DESC(autoresume_interval_ms,
107 "milliseconds to increase successive wakeup delays");
108
109static unsigned autoresume_step_ms;
98/*-------------------------------------------------------------------------*/ 110/*-------------------------------------------------------------------------*/
99 111
100static struct usb_device_descriptor device_desc = { 112static struct usb_device_descriptor device_desc = {
@@ -183,8 +195,16 @@ static void zero_suspend(struct usb_composite_dev *cdev)
183 return; 195 return;
184 196
185 if (autoresume) { 197 if (autoresume) {
186 mod_timer(&autoresume_timer, jiffies + (HZ * autoresume)); 198 if (max_autoresume &&
187 DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume); 199 (autoresume_step_ms > max_autoresume * 1000))
200 autoresume_step_ms = autoresume * 1000;
201
202 mod_timer(&autoresume_timer, jiffies +
203 msecs_to_jiffies(autoresume_step_ms));
204 DBG(cdev, "suspend, wakeup in %d milliseconds\n",
205 autoresume_step_ms);
206
207 autoresume_step_ms += autoresume_interval_ms;
188 } else 208 } else
189 DBG(cdev, "%s\n", __func__); 209 DBG(cdev, "%s\n", __func__);
190} 210}
@@ -316,6 +336,7 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
316 if (autoresume) { 336 if (autoresume) {
317 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 337 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
318 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 338 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
339 autoresume_step_ms = autoresume * 1000;
319 } 340 }
320 341
321 /* support OTG systems */ 342 /* support OTG systems */
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 5be0326aae38..a9707da7da0b 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -54,7 +54,7 @@ config USB_EHCI_HCD
54 54
55config USB_EHCI_ROOT_HUB_TT 55config USB_EHCI_ROOT_HUB_TT
56 bool "Root Hub Transaction Translators" 56 bool "Root Hub Transaction Translators"
57 depends on USB_EHCI_HCD || USB_CHIPIDEA_HOST 57 depends on USB_EHCI_HCD
58 ---help--- 58 ---help---
59 Some EHCI chips have vendor-specific extensions to integrate 59 Some EHCI chips have vendor-specific extensions to integrate
60 transaction translators, so that no OHCI or UHCI companion 60 transaction translators, so that no OHCI or UHCI companion
@@ -66,7 +66,7 @@ config USB_EHCI_ROOT_HUB_TT
66 66
67config USB_EHCI_TT_NEWSCHED 67config USB_EHCI_TT_NEWSCHED
68 bool "Improved Transaction Translator scheduling" 68 bool "Improved Transaction Translator scheduling"
69 depends on USB_EHCI_HCD || USB_CHIPIDEA_HOST 69 depends on USB_EHCI_HCD
70 default y 70 default y
71 ---help--- 71 ---help---
72 This changes the periodic scheduling code to fill more of the low 72 This changes the periodic scheduling code to fill more of the low
@@ -203,12 +203,11 @@ config USB_EHCI_SH
203 Enables support for the on-chip EHCI controller on the SuperH. 203 Enables support for the on-chip EHCI controller on the SuperH.
204 If you use the PCI EHCI controller, this option is not necessary. 204 If you use the PCI EHCI controller, this option is not necessary.
205 205
206config USB_EHCI_S5P 206config USB_EHCI_EXYNOS
207 tristate "EHCI support for Samsung S5P/EXYNOS SoC Series" 207 tristate "EHCI support for Samsung S5P/EXYNOS SoC Series"
208 depends on PLAT_S5P || ARCH_EXYNOS 208 depends on PLAT_S5P || ARCH_EXYNOS
209 help 209 help
210 Enable support for the Samsung S5Pxxxx and Exynos3/4/5 SOC's 210 Enable support for the Samsung Exynos SOC's on-chip EHCI controller.
211 on-chip EHCI controller.
212 211
213config USB_EHCI_MV 212config USB_EHCI_MV
214 bool "EHCI support for Marvell PXA/MMP USB controller" 213 bool "EHCI support for Marvell PXA/MMP USB controller"
@@ -224,7 +223,7 @@ config USB_EHCI_MV
224 on-chip EHCI USB controller" for those. 223 on-chip EHCI USB controller" for those.
225 224
226config USB_W90X900_EHCI 225config USB_W90X900_EHCI
227 bool "W90X900(W90P910) EHCI support" 226 tristate "W90X900(W90P910) EHCI support"
228 depends on ARCH_W90X900 227 depends on ARCH_W90X900
229 ---help--- 228 ---help---
230 Enables support for the W90X900 USB controller 229 Enables support for the W90X900 USB controller
@@ -278,7 +277,6 @@ endif # USB_EHCI_HCD
278 277
279config USB_OXU210HP_HCD 278config USB_OXU210HP_HCD
280 tristate "OXU210HP HCD support" 279 tristate "OXU210HP HCD support"
281 depends on GENERIC_HARDIRQS
282 ---help--- 280 ---help---
283 The OXU210HP is an USB host/OTG/device controller. Enable this 281 The OXU210HP is an USB host/OTG/device controller. Enable this
284 option if your board has this chip. If unsure, say N. 282 option if your board has this chip. If unsure, say N.
@@ -368,14 +366,54 @@ config USB_OHCI_HCD
368if USB_OHCI_HCD 366if USB_OHCI_HCD
369 367
370config USB_OHCI_HCD_OMAP1 368config USB_OHCI_HCD_OMAP1
371 bool "OHCI support for OMAP1/2 chips" 369 tristate "OHCI support for OMAP1/2 chips"
372 depends on ARCH_OMAP1 370 depends on ARCH_OMAP1
373 default y 371 default y
374 ---help--- 372 ---help---
375 Enables support for the OHCI controller on OMAP1/2 chips. 373 Enables support for the OHCI controller on OMAP1/2 chips.
376 374
375config USB_OHCI_HCD_SPEAR
376 tristate "Support for ST SPEAr on-chip OHCI USB controller"
377 depends on USB_OHCI_HCD && PLAT_SPEAR
378 default y
379 ---help---
380 Enables support for the on-chip OHCI controller on
381 ST SPEAr chips.
382
383config USB_OHCI_HCD_S3C2410
384 tristate "OHCI support for Samsung S3C24xx/S3C64xx SoC series"
385 depends on USB_OHCI_HCD && (ARCH_S3C24XX || ARCH_S3C64XX)
386 default y
387 ---help---
388 Enables support for the on-chip OHCI controller on
389 S3C24xx/S3C64xx chips.
390
391config USB_OHCI_HCD_LPC32XX
392 tristate "Support for LPC on-chip OHCI USB controller"
393 depends on USB_OHCI_HCD && ARCH_LPC32XX
394 default y
395 ---help---
396 Enables support for the on-chip OHCI controller on
397 NXP chips.
398
399config USB_OHCI_HCD_PXA27X
400 tristate "Support for PXA27X/PXA3XX on-chip OHCI USB controller"
401 depends on USB_OHCI_HCD && (PXA27x || PXA3xx)
402 default y
403 ---help---
404 Enables support for the on-chip OHCI controller on
405 PXA27x/PXA3xx chips.
406
407config USB_OHCI_HCD_AT91
408 tristate "Support for Atmel on-chip OHCI USB controller"
409 depends on USB_OHCI_HCD && ARCH_AT91
410 default y
411 ---help---
412 Enables support for the on-chip OHCI controller on
413 Atmel chips.
414
377config USB_OHCI_HCD_OMAP3 415config USB_OHCI_HCD_OMAP3
378 bool "OHCI support for OMAP3 and later chips" 416 tristate "OHCI support for OMAP3 and later chips"
379 depends on (ARCH_OMAP3 || ARCH_OMAP4) 417 depends on (ARCH_OMAP3 || ARCH_OMAP4)
380 default y 418 default y
381 ---help--- 419 ---help---
@@ -455,8 +493,8 @@ config USB_OHCI_SH
455 If you use the PCI OHCI controller, this option is not necessary. 493 If you use the PCI OHCI controller, this option is not necessary.
456 494
457config USB_OHCI_EXYNOS 495config USB_OHCI_EXYNOS
458 boolean "OHCI support for Samsung EXYNOS SoC Series" 496 tristate "OHCI support for Samsung S5P/EXYNOS SoC Series"
459 depends on ARCH_EXYNOS 497 depends on PLAT_S5P || ARCH_EXYNOS
460 help 498 help
461 Enable support for the Samsung Exynos SOC's on-chip OHCI controller. 499 Enable support for the Samsung Exynos SOC's on-chip OHCI controller.
462 500
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 50b0041c09a9..01e879ef3654 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -34,10 +34,11 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci-mxc.o
34obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o 34obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o
35obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o 35obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o
36obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o 36obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o
37obj-$(CONFIG_USB_EHCI_S5P) += ehci-s5p.o 37obj-$(CONFIG_USB_EHCI_EXYNOS) += ehci-exynos.o
38obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o 38obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o
39obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o 39obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o
40obj-$(CONFIG_USB_EHCI_TEGRA) += ehci-tegra.o 40obj-$(CONFIG_USB_EHCI_TEGRA) += ehci-tegra.o
41obj-$(CONFIG_USB_W90X900_EHCI) += ehci-w90x900.o
41 42
42obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o 43obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o
43obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o 44obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o
@@ -46,6 +47,14 @@ obj-$(CONFIG_USB_ISP1362_HCD) += isp1362-hcd.o
46obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o 47obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
47obj-$(CONFIG_USB_OHCI_HCD_PCI) += ohci-pci.o 48obj-$(CONFIG_USB_OHCI_HCD_PCI) += ohci-pci.o
48obj-$(CONFIG_USB_OHCI_HCD_PLATFORM) += ohci-platform.o 49obj-$(CONFIG_USB_OHCI_HCD_PLATFORM) += ohci-platform.o
50obj-$(CONFIG_USB_OHCI_EXYNOS) += ohci-exynos.o
51obj-$(CONFIG_USB_OHCI_HCD_OMAP1) += ohci-omap.o
52obj-$(CONFIG_USB_OHCI_HCD_OMAP3) += ohci-omap3.o
53obj-$(CONFIG_USB_OHCI_HCD_SPEAR) += ohci-spear.o
54obj-$(CONFIG_USB_OHCI_HCD_AT91) += ohci-at91.o
55obj-$(CONFIG_USB_OHCI_HCD_S3C2410) += ohci-s3c2410.o
56obj-$(CONFIG_USB_OHCI_HCD_LPC32XX) += ohci-nxp.o
57obj-$(CONFIG_USB_OHCI_HCD_PXA27X) += ohci-pxa27x.o
49 58
50obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o 59obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
51obj-$(CONFIG_USB_FHCI_HCD) += fhci.o 60obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/bcma-hcd.c b/drivers/usb/host/bcma-hcd.c
index df13d425e9c5..205f4a336583 100644
--- a/drivers/usb/host/bcma-hcd.c
+++ b/drivers/usb/host/bcma-hcd.c
@@ -227,8 +227,7 @@ static int bcma_hcd_probe(struct bcma_device *dev)
227 227
228 /* TODO: Probably need checks here; is the core connected? */ 228 /* TODO: Probably need checks here; is the core connected? */
229 229
230 if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) || 230 if (dma_set_mask_and_coherent(dev->dma_dev, DMA_BIT_MASK(32)))
231 dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
232 return -EOPNOTSUPP; 231 return -EOPNOTSUPP;
233 232
234 usb_dev = kzalloc(sizeof(struct bcma_hcd_device), GFP_KERNEL); 233 usb_dev = kzalloc(sizeof(struct bcma_hcd_device), GFP_KERNEL);
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index 3b645ff46f7b..284f8417eae5 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -30,13 +30,17 @@ static const char hcd_name[] = "ehci-atmel";
30static struct hc_driver __read_mostly ehci_atmel_hc_driver; 30static struct hc_driver __read_mostly ehci_atmel_hc_driver;
31 31
32/* interface and function clocks */ 32/* interface and function clocks */
33static struct clk *iclk, *fclk; 33static struct clk *iclk, *fclk, *uclk;
34static int clocked; 34static int clocked;
35 35
36/*-------------------------------------------------------------------------*/ 36/*-------------------------------------------------------------------------*/
37 37
38static void atmel_start_clock(void) 38static void atmel_start_clock(void)
39{ 39{
40 if (IS_ENABLED(CONFIG_COMMON_CLK)) {
41 clk_set_rate(uclk, 48000000);
42 clk_prepare_enable(uclk);
43 }
40 clk_prepare_enable(iclk); 44 clk_prepare_enable(iclk);
41 clk_prepare_enable(fclk); 45 clk_prepare_enable(fclk);
42 clocked = 1; 46 clocked = 1;
@@ -46,6 +50,8 @@ static void atmel_stop_clock(void)
46{ 50{
47 clk_disable_unprepare(fclk); 51 clk_disable_unprepare(fclk);
48 clk_disable_unprepare(iclk); 52 clk_disable_unprepare(iclk);
53 if (IS_ENABLED(CONFIG_COMMON_CLK))
54 clk_disable_unprepare(uclk);
49 clocked = 0; 55 clocked = 0;
50} 56}
51 57
@@ -90,10 +96,9 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev)
90 * Since shared usb code relies on it, set it here for now. 96 * Since shared usb code relies on it, set it here for now.
91 * Once we have dma capability bindings this can go away. 97 * Once we have dma capability bindings this can go away.
92 */ 98 */
93 if (!pdev->dev.dma_mask) 99 retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
94 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 100 if (retval)
95 if (!pdev->dev.coherent_dma_mask) 101 goto fail_create_hcd;
96 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
97 102
98 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); 103 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
99 if (!hcd) { 104 if (!hcd) {
@@ -130,6 +135,14 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev)
130 retval = -ENOENT; 135 retval = -ENOENT;
131 goto fail_request_resource; 136 goto fail_request_resource;
132 } 137 }
138 if (IS_ENABLED(CONFIG_COMMON_CLK)) {
139 uclk = devm_clk_get(&pdev->dev, "usb_clk");
140 if (IS_ERR(uclk)) {
141 dev_err(&pdev->dev, "failed to get uclk\n");
142 retval = PTR_ERR(uclk);
143 goto fail_request_resource;
144 }
145 }
133 146
134 ehci = hcd_to_ehci(hcd); 147 ehci = hcd_to_ehci(hcd);
135 /* registers start at offset 0x0 */ 148 /* registers start at offset 0x0 */
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index aa5b603f3933..4a9c2edbcb2b 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -334,6 +334,7 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { }
334/* troubleshooting help: expose state in debugfs */ 334/* troubleshooting help: expose state in debugfs */
335 335
336static int debug_async_open(struct inode *, struct file *); 336static int debug_async_open(struct inode *, struct file *);
337static int debug_bandwidth_open(struct inode *, struct file *);
337static int debug_periodic_open(struct inode *, struct file *); 338static int debug_periodic_open(struct inode *, struct file *);
338static int debug_registers_open(struct inode *, struct file *); 339static int debug_registers_open(struct inode *, struct file *);
339 340
@@ -347,6 +348,13 @@ static const struct file_operations debug_async_fops = {
347 .release = debug_close, 348 .release = debug_close,
348 .llseek = default_llseek, 349 .llseek = default_llseek,
349}; 350};
351static const struct file_operations debug_bandwidth_fops = {
352 .owner = THIS_MODULE,
353 .open = debug_bandwidth_open,
354 .read = debug_output,
355 .release = debug_close,
356 .llseek = default_llseek,
357};
350static const struct file_operations debug_periodic_fops = { 358static const struct file_operations debug_periodic_fops = {
351 .owner = THIS_MODULE, 359 .owner = THIS_MODULE,
352 .open = debug_periodic_open, 360 .open = debug_periodic_open,
@@ -379,7 +387,7 @@ struct debug_buffer {
379 case QH_LOW_SPEED: tmp = 'l'; break; \ 387 case QH_LOW_SPEED: tmp = 'l'; break; \
380 case QH_HIGH_SPEED: tmp = 'h'; break; \ 388 case QH_HIGH_SPEED: tmp = 'h'; break; \
381 default: tmp = '?'; break; \ 389 default: tmp = '?'; break; \
382 }; tmp; }) 390 } tmp; })
383 391
384static inline char token_mark(struct ehci_hcd *ehci, __hc32 token) 392static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
385{ 393{
@@ -525,6 +533,89 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf)
525 return strlen(buf->output_buf); 533 return strlen(buf->output_buf);
526} 534}
527 535
536static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf)
537{
538 struct ehci_hcd *ehci;
539 struct ehci_tt *tt;
540 struct ehci_per_sched *ps;
541 unsigned temp, size;
542 char *next;
543 unsigned i;
544 u8 *bw;
545 u16 *bf;
546 u8 budget[EHCI_BANDWIDTH_SIZE];
547
548 ehci = hcd_to_ehci(bus_to_hcd(buf->bus));
549 next = buf->output_buf;
550 size = buf->alloc_size;
551
552 *next = 0;
553
554 spin_lock_irq(&ehci->lock);
555
556 /* Dump the HS bandwidth table */
557 temp = scnprintf(next, size,
558 "HS bandwidth allocation (us per microframe)\n");
559 size -= temp;
560 next += temp;
561 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
562 bw = &ehci->bandwidth[i];
563 temp = scnprintf(next, size,
564 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
565 i, bw[0], bw[1], bw[2], bw[3],
566 bw[4], bw[5], bw[6], bw[7]);
567 size -= temp;
568 next += temp;
569 }
570
571 /* Dump all the FS/LS tables */
572 list_for_each_entry(tt, &ehci->tt_list, tt_list) {
573 temp = scnprintf(next, size,
574 "\nTT %s port %d FS/LS bandwidth allocation (us per frame)\n",
575 dev_name(&tt->usb_tt->hub->dev),
576 tt->tt_port + !!tt->usb_tt->multi);
577 size -= temp;
578 next += temp;
579
580 bf = tt->bandwidth;
581 temp = scnprintf(next, size,
582 " %5u%5u%5u%5u%5u%5u%5u%5u\n",
583 bf[0], bf[1], bf[2], bf[3],
584 bf[4], bf[5], bf[6], bf[7]);
585 size -= temp;
586 next += temp;
587
588 temp = scnprintf(next, size,
589 "FS/LS budget (us per microframe)\n");
590 size -= temp;
591 next += temp;
592 compute_tt_budget(budget, tt);
593 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
594 bw = &budget[i];
595 temp = scnprintf(next, size,
596 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
597 i, bw[0], bw[1], bw[2], bw[3],
598 bw[4], bw[5], bw[6], bw[7]);
599 size -= temp;
600 next += temp;
601 }
602 list_for_each_entry(ps, &tt->ps_list, ps_list) {
603 temp = scnprintf(next, size,
604 "%s ep %02x: %4u @ %2u.%u+%u mask %04x\n",
605 dev_name(&ps->udev->dev),
606 ps->ep->desc.bEndpointAddress,
607 ps->tt_usecs,
608 ps->bw_phase, ps->phase_uf,
609 ps->bw_period, ps->cs_mask);
610 size -= temp;
611 next += temp;
612 }
613 }
614 spin_unlock_irq(&ehci->lock);
615
616 return next - buf->output_buf;
617}
618
528#define DBG_SCHED_LIMIT 64 619#define DBG_SCHED_LIMIT 64
529static ssize_t fill_periodic_buffer(struct debug_buffer *buf) 620static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
530{ 621{
@@ -571,7 +662,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
571 case Q_TYPE_QH: 662 case Q_TYPE_QH:
572 hw = p.qh->hw; 663 hw = p.qh->hw;
573 temp = scnprintf (next, size, " qh%d-%04x/%p", 664 temp = scnprintf (next, size, " qh%d-%04x/%p",
574 p.qh->period, 665 p.qh->ps.period,
575 hc32_to_cpup(ehci, 666 hc32_to_cpup(ehci,
576 &hw->hw_info2) 667 &hw->hw_info2)
577 /* uframe masks */ 668 /* uframe masks */
@@ -618,7 +709,8 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
618 speed_char (scratch), 709 speed_char (scratch),
619 scratch & 0x007f, 710 scratch & 0x007f,
620 (scratch >> 8) & 0x000f, type, 711 (scratch >> 8) & 0x000f, type,
621 p.qh->usecs, p.qh->c_usecs, 712 p.qh->ps.usecs,
713 p.qh->ps.c_usecs,
622 temp, 714 temp,
623 0x7ff & (scratch >> 16)); 715 0x7ff & (scratch >> 16));
624 716
@@ -645,7 +737,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
645 case Q_TYPE_SITD: 737 case Q_TYPE_SITD:
646 temp = scnprintf (next, size, 738 temp = scnprintf (next, size,
647 " sitd%d-%04x/%p", 739 " sitd%d-%04x/%p",
648 p.sitd->stream->interval, 740 p.sitd->stream->ps.period,
649 hc32_to_cpup(ehci, &p.sitd->hw_uframe) 741 hc32_to_cpup(ehci, &p.sitd->hw_uframe)
650 & 0x0000ffff, 742 & 0x0000ffff,
651 p.sitd); 743 p.sitd);
@@ -918,6 +1010,7 @@ static int debug_close(struct inode *inode, struct file *file)
918 1010
919 return 0; 1011 return 0;
920} 1012}
1013
921static int debug_async_open(struct inode *inode, struct file *file) 1014static int debug_async_open(struct inode *inode, struct file *file)
922{ 1015{
923 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); 1016 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
@@ -925,6 +1018,14 @@ static int debug_async_open(struct inode *inode, struct file *file)
925 return file->private_data ? 0 : -ENOMEM; 1018 return file->private_data ? 0 : -ENOMEM;
926} 1019}
927 1020
1021static int debug_bandwidth_open(struct inode *inode, struct file *file)
1022{
1023 file->private_data = alloc_buffer(inode->i_private,
1024 fill_bandwidth_buffer);
1025
1026 return file->private_data ? 0 : -ENOMEM;
1027}
1028
928static int debug_periodic_open(struct inode *inode, struct file *file) 1029static int debug_periodic_open(struct inode *inode, struct file *file)
929{ 1030{
930 struct debug_buffer *buf; 1031 struct debug_buffer *buf;
@@ -957,6 +1058,10 @@ static inline void create_debug_files (struct ehci_hcd *ehci)
957 &debug_async_fops)) 1058 &debug_async_fops))
958 goto file_error; 1059 goto file_error;
959 1060
1061 if (!debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus,
1062 &debug_bandwidth_fops))
1063 goto file_error;
1064
960 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus, 1065 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
961 &debug_periodic_fops)) 1066 &debug_periodic_fops))
962 goto file_error; 1067 goto file_error;
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-exynos.c
index 7c3de95c7054..e97c198e052f 100644
--- a/drivers/usb/host/ehci-s5p.c
+++ b/drivers/usb/host/ehci-exynos.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * SAMSUNG S5P USB HOST EHCI Controller 2 * SAMSUNG EXYNOS USB HOST EHCI Controller
3 * 3 *
4 * Copyright (C) 2011 Samsung Electronics Co.Ltd 4 * Copyright (C) 2011 Samsung Electronics Co.Ltd
5 * Author: Jingoo Han <jg1.han@samsung.com> 5 * Author: Jingoo Han <jg1.han@samsung.com>
@@ -20,7 +20,6 @@
20#include <linux/of.h> 20#include <linux/of.h>
21#include <linux/of_gpio.h> 21#include <linux/of_gpio.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/platform_data/usb-ehci-s5p.h>
24#include <linux/usb/phy.h> 23#include <linux/usb/phy.h>
25#include <linux/usb/samsung_usb_phy.h> 24#include <linux/usb/samsung_usb_phy.h>
26#include <linux/usb.h> 25#include <linux/usb.h>
@@ -29,7 +28,7 @@
29 28
30#include "ehci.h" 29#include "ehci.h"
31 30
32#define DRIVER_DESC "EHCI s5p driver" 31#define DRIVER_DESC "EHCI EXYNOS driver"
33 32
34#define EHCI_INSNREG00(base) (base + 0x90) 33#define EHCI_INSNREG00(base) (base + 0x90)
35#define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25) 34#define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
@@ -40,21 +39,18 @@
40 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \ 39 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
41 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN) 40 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
42 41
43static const char hcd_name[] = "ehci-s5p"; 42static const char hcd_name[] = "ehci-exynos";
44static struct hc_driver __read_mostly s5p_ehci_hc_driver; 43static struct hc_driver __read_mostly exynos_ehci_hc_driver;
45 44
46struct s5p_ehci_hcd { 45struct exynos_ehci_hcd {
47 struct clk *clk; 46 struct clk *clk;
48 struct usb_phy *phy; 47 struct usb_phy *phy;
49 struct usb_otg *otg; 48 struct usb_otg *otg;
50 struct s5p_ehci_platdata *pdata;
51}; 49};
52 50
53static struct s5p_ehci_platdata empty_platdata; 51#define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv)
54 52
55#define to_s5p_ehci(hcd) (struct s5p_ehci_hcd *)(hcd_to_ehci(hcd)->priv) 53static void exynos_setup_vbus_gpio(struct platform_device *pdev)
56
57static void s5p_setup_vbus_gpio(struct platform_device *pdev)
58{ 54{
59 struct device *dev = &pdev->dev; 55 struct device *dev = &pdev->dev;
60 int err; 56 int err;
@@ -73,10 +69,9 @@ static void s5p_setup_vbus_gpio(struct platform_device *pdev)
73 dev_err(dev, "can't request ehci vbus gpio %d", gpio); 69 dev_err(dev, "can't request ehci vbus gpio %d", gpio);
74} 70}
75 71
76static int s5p_ehci_probe(struct platform_device *pdev) 72static int exynos_ehci_probe(struct platform_device *pdev)
77{ 73{
78 struct s5p_ehci_platdata *pdata = dev_get_platdata(&pdev->dev); 74 struct exynos_ehci_hcd *exynos_ehci;
79 struct s5p_ehci_hcd *s5p_ehci;
80 struct usb_hcd *hcd; 75 struct usb_hcd *hcd;
81 struct ehci_hcd *ehci; 76 struct ehci_hcd *ehci;
82 struct resource *res; 77 struct resource *res;
@@ -89,53 +84,45 @@ static int s5p_ehci_probe(struct platform_device *pdev)
89 * Since shared usb code relies on it, set it here for now. 84 * Since shared usb code relies on it, set it here for now.
90 * Once we move to full device tree support this will vanish off. 85 * Once we move to full device tree support this will vanish off.
91 */ 86 */
92 if (!pdev->dev.dma_mask) 87 err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
93 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 88 if (err)
94 if (!pdev->dev.coherent_dma_mask) 89 return err;
95 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
96 90
97 s5p_setup_vbus_gpio(pdev); 91 exynos_setup_vbus_gpio(pdev);
98 92
99 hcd = usb_create_hcd(&s5p_ehci_hc_driver, 93 hcd = usb_create_hcd(&exynos_ehci_hc_driver,
100 &pdev->dev, dev_name(&pdev->dev)); 94 &pdev->dev, dev_name(&pdev->dev));
101 if (!hcd) { 95 if (!hcd) {
102 dev_err(&pdev->dev, "Unable to create HCD\n"); 96 dev_err(&pdev->dev, "Unable to create HCD\n");
103 return -ENOMEM; 97 return -ENOMEM;
104 } 98 }
105 s5p_ehci = to_s5p_ehci(hcd); 99 exynos_ehci = to_exynos_ehci(hcd);
106 100
107 if (of_device_is_compatible(pdev->dev.of_node, 101 if (of_device_is_compatible(pdev->dev.of_node,
108 "samsung,exynos5440-ehci")) { 102 "samsung,exynos5440-ehci"))
109 s5p_ehci->pdata = &empty_platdata;
110 goto skip_phy; 103 goto skip_phy;
111 }
112 104
113 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 105 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
114 if (IS_ERR(phy)) { 106 if (IS_ERR(phy)) {
115 /* Fallback to pdata */ 107 usb_put_hcd(hcd);
116 if (!pdata) { 108 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
117 usb_put_hcd(hcd); 109 return -EPROBE_DEFER;
118 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
119 return -EPROBE_DEFER;
120 } else {
121 s5p_ehci->pdata = pdata;
122 }
123 } else { 110 } else {
124 s5p_ehci->phy = phy; 111 exynos_ehci->phy = phy;
125 s5p_ehci->otg = phy->otg; 112 exynos_ehci->otg = phy->otg;
126 } 113 }
127 114
128skip_phy: 115skip_phy:
129 116
130 s5p_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); 117 exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
131 118
132 if (IS_ERR(s5p_ehci->clk)) { 119 if (IS_ERR(exynos_ehci->clk)) {
133 dev_err(&pdev->dev, "Failed to get usbhost clock\n"); 120 dev_err(&pdev->dev, "Failed to get usbhost clock\n");
134 err = PTR_ERR(s5p_ehci->clk); 121 err = PTR_ERR(exynos_ehci->clk);
135 goto fail_clk; 122 goto fail_clk;
136 } 123 }
137 124
138 err = clk_prepare_enable(s5p_ehci->clk); 125 err = clk_prepare_enable(exynos_ehci->clk);
139 if (err) 126 if (err)
140 goto fail_clk; 127 goto fail_clk;
141 128
@@ -162,13 +149,11 @@ skip_phy:
162 goto fail_io; 149 goto fail_io;
163 } 150 }
164 151
165 if (s5p_ehci->otg) 152 if (exynos_ehci->otg)
166 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); 153 exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self);
167 154
168 if (s5p_ehci->phy) 155 if (exynos_ehci->phy)
169 usb_phy_init(s5p_ehci->phy); 156 usb_phy_init(exynos_ehci->phy);
170 else if (s5p_ehci->pdata->phy_init)
171 s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
172 157
173 ehci = hcd_to_ehci(hcd); 158 ehci = hcd_to_ehci(hcd);
174 ehci->caps = hcd->regs; 159 ehci->caps = hcd->regs;
@@ -187,33 +172,29 @@ skip_phy:
187 return 0; 172 return 0;
188 173
189fail_add_hcd: 174fail_add_hcd:
190 if (s5p_ehci->phy) 175 if (exynos_ehci->phy)
191 usb_phy_shutdown(s5p_ehci->phy); 176 usb_phy_shutdown(exynos_ehci->phy);
192 else if (s5p_ehci->pdata->phy_exit)
193 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
194fail_io: 177fail_io:
195 clk_disable_unprepare(s5p_ehci->clk); 178 clk_disable_unprepare(exynos_ehci->clk);
196fail_clk: 179fail_clk:
197 usb_put_hcd(hcd); 180 usb_put_hcd(hcd);
198 return err; 181 return err;
199} 182}
200 183
201static int s5p_ehci_remove(struct platform_device *pdev) 184static int exynos_ehci_remove(struct platform_device *pdev)
202{ 185{
203 struct usb_hcd *hcd = platform_get_drvdata(pdev); 186 struct usb_hcd *hcd = platform_get_drvdata(pdev);
204 struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); 187 struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
205 188
206 usb_remove_hcd(hcd); 189 usb_remove_hcd(hcd);
207 190
208 if (s5p_ehci->otg) 191 if (exynos_ehci->otg)
209 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); 192 exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self);
210 193
211 if (s5p_ehci->phy) 194 if (exynos_ehci->phy)
212 usb_phy_shutdown(s5p_ehci->phy); 195 usb_phy_shutdown(exynos_ehci->phy);
213 else if (s5p_ehci->pdata->phy_exit)
214 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
215 196
216 clk_disable_unprepare(s5p_ehci->clk); 197 clk_disable_unprepare(exynos_ehci->clk);
217 198
218 usb_put_hcd(hcd); 199 usb_put_hcd(hcd);
219 200
@@ -221,45 +202,39 @@ static int s5p_ehci_remove(struct platform_device *pdev)
221} 202}
222 203
223#ifdef CONFIG_PM 204#ifdef CONFIG_PM
224static int s5p_ehci_suspend(struct device *dev) 205static int exynos_ehci_suspend(struct device *dev)
225{ 206{
226 struct usb_hcd *hcd = dev_get_drvdata(dev); 207 struct usb_hcd *hcd = dev_get_drvdata(dev);
227 struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); 208 struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
228 struct platform_device *pdev = to_platform_device(dev);
229 209
230 bool do_wakeup = device_may_wakeup(dev); 210 bool do_wakeup = device_may_wakeup(dev);
231 int rc; 211 int rc;
232 212
233 rc = ehci_suspend(hcd, do_wakeup); 213 rc = ehci_suspend(hcd, do_wakeup);
234 214
235 if (s5p_ehci->otg) 215 if (exynos_ehci->otg)
236 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); 216 exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self);
237 217
238 if (s5p_ehci->phy) 218 if (exynos_ehci->phy)
239 usb_phy_shutdown(s5p_ehci->phy); 219 usb_phy_shutdown(exynos_ehci->phy);
240 else if (s5p_ehci->pdata->phy_exit)
241 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
242 220
243 clk_disable_unprepare(s5p_ehci->clk); 221 clk_disable_unprepare(exynos_ehci->clk);
244 222
245 return rc; 223 return rc;
246} 224}
247 225
248static int s5p_ehci_resume(struct device *dev) 226static int exynos_ehci_resume(struct device *dev)
249{ 227{
250 struct usb_hcd *hcd = dev_get_drvdata(dev); 228 struct usb_hcd *hcd = dev_get_drvdata(dev);
251 struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); 229 struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
252 struct platform_device *pdev = to_platform_device(dev);
253 230
254 clk_prepare_enable(s5p_ehci->clk); 231 clk_prepare_enable(exynos_ehci->clk);
255 232
256 if (s5p_ehci->otg) 233 if (exynos_ehci->otg)
257 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); 234 exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self);
258 235
259 if (s5p_ehci->phy) 236 if (exynos_ehci->phy)
260 usb_phy_init(s5p_ehci->phy); 237 usb_phy_init(exynos_ehci->phy);
261 else if (s5p_ehci->pdata->phy_init)
262 s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
263 238
264 /* DMA burst Enable */ 239 /* DMA burst Enable */
265 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); 240 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
@@ -268,13 +243,13 @@ static int s5p_ehci_resume(struct device *dev)
268 return 0; 243 return 0;
269} 244}
270#else 245#else
271#define s5p_ehci_suspend NULL 246#define exynos_ehci_suspend NULL
272#define s5p_ehci_resume NULL 247#define exynos_ehci_resume NULL
273#endif 248#endif
274 249
275static const struct dev_pm_ops s5p_ehci_pm_ops = { 250static const struct dev_pm_ops exynos_ehci_pm_ops = {
276 .suspend = s5p_ehci_suspend, 251 .suspend = exynos_ehci_suspend,
277 .resume = s5p_ehci_resume, 252 .resume = exynos_ehci_resume,
278}; 253};
279 254
280#ifdef CONFIG_OF 255#ifdef CONFIG_OF
@@ -286,40 +261,40 @@ static const struct of_device_id exynos_ehci_match[] = {
286MODULE_DEVICE_TABLE(of, exynos_ehci_match); 261MODULE_DEVICE_TABLE(of, exynos_ehci_match);
287#endif 262#endif
288 263
289static struct platform_driver s5p_ehci_driver = { 264static struct platform_driver exynos_ehci_driver = {
290 .probe = s5p_ehci_probe, 265 .probe = exynos_ehci_probe,
291 .remove = s5p_ehci_remove, 266 .remove = exynos_ehci_remove,
292 .shutdown = usb_hcd_platform_shutdown, 267 .shutdown = usb_hcd_platform_shutdown,
293 .driver = { 268 .driver = {
294 .name = "s5p-ehci", 269 .name = "exynos-ehci",
295 .owner = THIS_MODULE, 270 .owner = THIS_MODULE,
296 .pm = &s5p_ehci_pm_ops, 271 .pm = &exynos_ehci_pm_ops,
297 .of_match_table = of_match_ptr(exynos_ehci_match), 272 .of_match_table = of_match_ptr(exynos_ehci_match),
298 } 273 }
299}; 274};
300static const struct ehci_driver_overrides s5p_overrides __initdata = { 275static const struct ehci_driver_overrides exynos_overrides __initdata = {
301 .extra_priv_size = sizeof(struct s5p_ehci_hcd), 276 .extra_priv_size = sizeof(struct exynos_ehci_hcd),
302}; 277};
303 278
304static int __init ehci_s5p_init(void) 279static int __init ehci_exynos_init(void)
305{ 280{
306 if (usb_disabled()) 281 if (usb_disabled())
307 return -ENODEV; 282 return -ENODEV;
308 283
309 pr_info("%s: " DRIVER_DESC "\n", hcd_name); 284 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
310 ehci_init_driver(&s5p_ehci_hc_driver, &s5p_overrides); 285 ehci_init_driver(&exynos_ehci_hc_driver, &exynos_overrides);
311 return platform_driver_register(&s5p_ehci_driver); 286 return platform_driver_register(&exynos_ehci_driver);
312} 287}
313module_init(ehci_s5p_init); 288module_init(ehci_exynos_init);
314 289
315static void __exit ehci_s5p_cleanup(void) 290static void __exit ehci_exynos_cleanup(void)
316{ 291{
317 platform_driver_unregister(&s5p_ehci_driver); 292 platform_driver_unregister(&exynos_ehci_driver);
318} 293}
319module_exit(ehci_s5p_cleanup); 294module_exit(ehci_exynos_cleanup);
320 295
321MODULE_DESCRIPTION(DRIVER_DESC); 296MODULE_DESCRIPTION(DRIVER_DESC);
322MODULE_ALIAS("platform:s5p-ehci"); 297MODULE_ALIAS("platform:exynos-ehci");
323MODULE_AUTHOR("Jingoo Han"); 298MODULE_AUTHOR("Jingoo Han");
324MODULE_AUTHOR("Joonyoung Shim"); 299MODULE_AUTHOR("Joonyoung Shim");
325MODULE_LICENSE("GPL v2"); 300MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 947b009009f1..a06d5012201f 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 *)dev_get_platdata(&pdev->dev); 60 pdata = 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));
@@ -130,7 +130,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
130 } 130 }
131 131
132 /* Enable USB controller, 83xx or 8536 */ 132 /* Enable USB controller, 83xx or 8536 */
133 if (pdata->have_sysif_regs) 133 if (pdata->have_sysif_regs && pdata->controller_ver < FSL_USB_VER_1_6)
134 setbits32(hcd->regs + FSL_SOC_USB_CTRL, 0x4); 134 setbits32(hcd->regs + FSL_SOC_USB_CTRL, 0x4);
135 135
136 /* Don't need to set host mode here. It will be done by tdi_reset() */ 136 /* Don't need to set host mode here. It will be done by tdi_reset() */
@@ -232,15 +232,9 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
232 case FSL_USB2_PHY_ULPI: 232 case FSL_USB2_PHY_ULPI:
233 if (pdata->have_sysif_regs && pdata->controller_ver) { 233 if (pdata->have_sysif_regs && pdata->controller_ver) {
234 /* controller version 1.6 or above */ 234 /* controller version 1.6 or above */
235 clrbits32(non_ehci + FSL_SOC_USB_CTRL, UTMI_PHY_EN);
235 setbits32(non_ehci + FSL_SOC_USB_CTRL, 236 setbits32(non_ehci + FSL_SOC_USB_CTRL,
236 ULPI_PHY_CLK_SEL); 237 ULPI_PHY_CLK_SEL | USB_CTRL_USB_EN);
237 /*
238 * Due to controller issue of PHY_CLK_VALID in ULPI
239 * mode, we set USB_CTRL_USB_EN before checking
240 * PHY_CLK_VALID, otherwise PHY_CLK_VALID doesn't work.
241 */
242 clrsetbits_be32(non_ehci + FSL_SOC_USB_CTRL,
243 UTMI_PHY_EN, USB_CTRL_USB_EN);
244 } 238 }
245 portsc |= PORT_PTS_ULPI; 239 portsc |= PORT_PTS_ULPI;
246 break; 240 break;
@@ -270,8 +264,9 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
270 if (pdata->have_sysif_regs && pdata->controller_ver && 264 if (pdata->have_sysif_regs && pdata->controller_ver &&
271 (phy_mode == FSL_USB2_PHY_ULPI)) { 265 (phy_mode == FSL_USB2_PHY_ULPI)) {
272 /* check PHY_CLK_VALID to get phy clk valid */ 266 /* check PHY_CLK_VALID to get phy clk valid */
273 if (!spin_event_timeout(in_be32(non_ehci + FSL_SOC_USB_CTRL) & 267 if (!(spin_event_timeout(in_be32(non_ehci + FSL_SOC_USB_CTRL) &
274 PHY_CLK_VALID, FSL_USB_PHY_CLK_TIMEOUT, 0)) { 268 PHY_CLK_VALID, FSL_USB_PHY_CLK_TIMEOUT, 0) ||
269 in_be32(non_ehci + FSL_SOC_USB_PRICTRL))) {
275 printk(KERN_WARNING "fsl-ehci: USB PHY clock invalid\n"); 270 printk(KERN_WARNING "fsl-ehci: USB PHY clock invalid\n");
276 return -EINVAL; 271 return -EINVAL;
277 } 272 }
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 5d6022f30ebe..e8ba4c44223a 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -110,6 +110,9 @@ MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
110#include "ehci.h" 110#include "ehci.h"
111#include "pci-quirks.h" 111#include "pci-quirks.h"
112 112
113static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE],
114 struct ehci_tt *tt);
115
113/* 116/*
114 * The MosChip MCS9990 controller updates its microframe counter 117 * The MosChip MCS9990 controller updates its microframe counter
115 * a little before the frame counter, and occasionally we will read 118 * a little before the frame counter, and occasionally we will read
@@ -484,6 +487,7 @@ static int ehci_init(struct usb_hcd *hcd)
484 INIT_LIST_HEAD(&ehci->intr_qh_list); 487 INIT_LIST_HEAD(&ehci->intr_qh_list);
485 INIT_LIST_HEAD(&ehci->cached_itd_list); 488 INIT_LIST_HEAD(&ehci->cached_itd_list);
486 INIT_LIST_HEAD(&ehci->cached_sitd_list); 489 INIT_LIST_HEAD(&ehci->cached_sitd_list);
490 INIT_LIST_HEAD(&ehci->tt_list);
487 491
488 if (HCC_PGM_FRAMELISTLEN(hcc_params)) { 492 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
489 /* periodic schedule size can be smaller than default */ 493 /* periodic schedule size can be smaller than default */
@@ -956,6 +960,7 @@ rescan:
956 goto idle_timeout; 960 goto idle_timeout;
957 961
958 /* BUG_ON(!list_empty(&stream->free_list)); */ 962 /* BUG_ON(!list_empty(&stream->free_list)); */
963 reserve_release_iso_bandwidth(ehci, stream, -1);
959 kfree(stream); 964 kfree(stream);
960 goto done; 965 goto done;
961 } 966 }
@@ -982,6 +987,8 @@ idle_timeout:
982 if (qh->clearing_tt) 987 if (qh->clearing_tt)
983 goto idle_timeout; 988 goto idle_timeout;
984 if (list_empty (&qh->qtd_list)) { 989 if (list_empty (&qh->qtd_list)) {
990 if (qh->ps.bw_uperiod)
991 reserve_release_intr_bandwidth(ehci, qh, -1);
985 qh_destroy(ehci, qh); 992 qh_destroy(ehci, qh);
986 break; 993 break;
987 } 994 }
@@ -1022,7 +1029,6 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1022 * the toggle bit in the QH. 1029 * the toggle bit in the QH.
1023 */ 1030 */
1024 if (qh) { 1031 if (qh) {
1025 usb_settoggle(qh->dev, epnum, is_out, 0);
1026 if (!list_empty(&qh->qtd_list)) { 1032 if (!list_empty(&qh->qtd_list)) {
1027 WARN_ONCE(1, "clear_halt for a busy endpoint\n"); 1033 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
1028 } else { 1034 } else {
@@ -1030,6 +1036,7 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1030 * while the QH is active. Unlink it now; 1036 * while the QH is active. Unlink it now;
1031 * re-linking will call qh_refresh(). 1037 * re-linking will call qh_refresh().
1032 */ 1038 */
1039 usb_settoggle(qh->ps.udev, epnum, is_out, 0);
1033 qh->exception = 1; 1040 qh->exception = 1;
1034 if (eptype == USB_ENDPOINT_XFER_BULK) 1041 if (eptype == USB_ENDPOINT_XFER_BULK)
1035 start_unlink_async(ehci, qh); 1042 start_unlink_async(ehci, qh);
@@ -1048,6 +1055,19 @@ static int ehci_get_frame (struct usb_hcd *hcd)
1048 1055
1049/*-------------------------------------------------------------------------*/ 1056/*-------------------------------------------------------------------------*/
1050 1057
1058/* Device addition and removal */
1059
1060static void ehci_remove_device(struct usb_hcd *hcd, struct usb_device *udev)
1061{
1062 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1063
1064 spin_lock_irq(&ehci->lock);
1065 drop_tt(udev);
1066 spin_unlock_irq(&ehci->lock);
1067}
1068
1069/*-------------------------------------------------------------------------*/
1070
1051#ifdef CONFIG_PM 1071#ifdef CONFIG_PM
1052 1072
1053/* suspend/resume, section 4.3 */ 1073/* suspend/resume, section 4.3 */
@@ -1075,6 +1095,14 @@ int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
1075 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 1095 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1076 spin_unlock_irq(&ehci->lock); 1096 spin_unlock_irq(&ehci->lock);
1077 1097
1098 synchronize_irq(hcd->irq);
1099
1100 /* Check for race with a wakeup request */
1101 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
1102 ehci_resume(hcd, false);
1103 return -EBUSY;
1104 }
1105
1078 return 0; 1106 return 0;
1079} 1107}
1080EXPORT_SYMBOL_GPL(ehci_suspend); 1108EXPORT_SYMBOL_GPL(ehci_suspend);
@@ -1191,6 +1219,11 @@ static const struct hc_driver ehci_hc_driver = {
1191 .bus_resume = ehci_bus_resume, 1219 .bus_resume = ehci_bus_resume,
1192 .relinquish_port = ehci_relinquish_port, 1220 .relinquish_port = ehci_relinquish_port,
1193 .port_handed_over = ehci_port_handed_over, 1221 .port_handed_over = ehci_port_handed_over,
1222
1223 /*
1224 * device support
1225 */
1226 .free_dev = ehci_remove_device,
1194}; 1227};
1195 1228
1196void ehci_init_driver(struct hc_driver *drv, 1229void ehci_init_driver(struct hc_driver *drv,
@@ -1238,11 +1271,6 @@ MODULE_LICENSE ("GPL");
1238#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver 1271#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
1239#endif 1272#endif
1240 1273
1241#ifdef CONFIG_USB_W90X900_EHCI
1242#include "ehci-w90x900.c"
1243#define PLATFORM_DRIVER ehci_hcd_w90x900_driver
1244#endif
1245
1246#ifdef CONFIG_USB_OCTEON_EHCI 1274#ifdef CONFIG_USB_OCTEON_EHCI
1247#include "ehci-octeon.c" 1275#include "ehci-octeon.c"
1248#define PLATFORM_DRIVER ehci_octeon_driver 1276#define PLATFORM_DRIVER ehci_octeon_driver
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index 52a77734a225..c0fb6a8ae6a3 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -224,11 +224,11 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
224 hw->hw_next = EHCI_LIST_END(ehci); 224 hw->hw_next = EHCI_LIST_END(ehci);
225 hw->hw_qtd_next = EHCI_LIST_END(ehci); 225 hw->hw_qtd_next = EHCI_LIST_END(ehci);
226 hw->hw_alt_next = EHCI_LIST_END(ehci); 226 hw->hw_alt_next = EHCI_LIST_END(ehci);
227 hw->hw_token &= ~QTD_STS_ACTIVE;
228 ehci->dummy->hw = hw; 227 ehci->dummy->hw = hw;
229 228
230 for (i = 0; i < ehci->periodic_size; i++) 229 for (i = 0; i < ehci->periodic_size; i++)
231 ehci->periodic[i] = ehci->dummy->qh_dma; 230 ehci->periodic[i] = cpu_to_hc32(ehci,
231 ehci->dummy->qh_dma);
232 } else { 232 } else {
233 for (i = 0; i < ehci->periodic_size; i++) 233 for (i = 0; i < ehci->periodic_size; i++)
234 ehci->periodic[i] = EHCI_LIST_END(ehci); 234 ehci->periodic[i] = EHCI_LIST_END(ehci);
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 0f717dc688b7..f341651d6f6c 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -42,7 +42,6 @@
42 42
43static const char hcd_name[] = "ehci-msm"; 43static const char hcd_name[] = "ehci-msm";
44static struct hc_driver __read_mostly msm_hc_driver; 44static struct hc_driver __read_mostly msm_hc_driver;
45static struct usb_phy *phy;
46 45
47static int ehci_msm_reset(struct usb_hcd *hcd) 46static int ehci_msm_reset(struct usb_hcd *hcd)
48{ 47{
@@ -70,6 +69,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
70{ 69{
71 struct usb_hcd *hcd; 70 struct usb_hcd *hcd;
72 struct resource *res; 71 struct resource *res;
72 struct usb_phy *phy;
73 int ret; 73 int ret;
74 74
75 dev_dbg(&pdev->dev, "ehci_msm proble\n"); 75 dev_dbg(&pdev->dev, "ehci_msm proble\n");
@@ -108,10 +108,14 @@ static int ehci_msm_probe(struct platform_device *pdev)
108 * powering up VBUS, mapping of registers address space and power 108 * powering up VBUS, mapping of registers address space and power
109 * management. 109 * management.
110 */ 110 */
111 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 111 if (pdev->dev.of_node)
112 phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
113 else
114 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
115
112 if (IS_ERR(phy)) { 116 if (IS_ERR(phy)) {
113 dev_err(&pdev->dev, "unable to find transceiver\n"); 117 dev_err(&pdev->dev, "unable to find transceiver\n");
114 ret = -ENODEV; 118 ret = -EPROBE_DEFER;
115 goto put_hcd; 119 goto put_hcd;
116 } 120 }
117 121
@@ -121,6 +125,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
121 goto put_hcd; 125 goto put_hcd;
122 } 126 }
123 127
128 hcd->phy = phy;
124 device_init_wakeup(&pdev->dev, 1); 129 device_init_wakeup(&pdev->dev, 1);
125 /* 130 /*
126 * OTG device parent of HCD takes care of putting 131 * OTG device parent of HCD takes care of putting
@@ -147,7 +152,7 @@ static int ehci_msm_remove(struct platform_device *pdev)
147 pm_runtime_disable(&pdev->dev); 152 pm_runtime_disable(&pdev->dev);
148 pm_runtime_set_suspended(&pdev->dev); 153 pm_runtime_set_suspended(&pdev->dev);
149 154
150 otg_set_host(phy->otg, NULL); 155 otg_set_host(hcd->phy->otg, NULL);
151 156
152 /* FIXME: need to call usb_remove_hcd() here? */ 157 /* FIXME: need to call usb_remove_hcd() here? */
153 158
@@ -186,12 +191,19 @@ static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
186 .resume = ehci_msm_pm_resume, 191 .resume = ehci_msm_pm_resume,
187}; 192};
188 193
194static struct of_device_id msm_ehci_dt_match[] = {
195 { .compatible = "qcom,ehci-host", },
196 {}
197};
198MODULE_DEVICE_TABLE(of, msm_ehci_dt_match);
199
189static struct platform_driver ehci_msm_driver = { 200static struct platform_driver ehci_msm_driver = {
190 .probe = ehci_msm_probe, 201 .probe = ehci_msm_probe,
191 .remove = ehci_msm_remove, 202 .remove = ehci_msm_remove,
192 .driver = { 203 .driver = {
193 .name = "msm_hsusb_host", 204 .name = "msm_hsusb_host",
194 .pm = &ehci_msm_dev_pm_ops, 205 .pm = &ehci_msm_dev_pm_ops,
206 .of_match_table = msm_ehci_dt_match,
195 }, 207 },
196}; 208};
197 209
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c
index ab0397e4d8f3..4c528b2c033a 100644
--- a/drivers/usb/host/ehci-octeon.c
+++ b/drivers/usb/host/ehci-octeon.c
@@ -116,8 +116,10 @@ static int ehci_octeon_drv_probe(struct platform_device *pdev)
116 * We can DMA from anywhere. But the descriptors must be in 116 * We can DMA from anywhere. But the descriptors must be in
117 * the lower 4GB. 117 * the lower 4GB.
118 */ 118 */
119 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
120 pdev->dev.dma_mask = &ehci_octeon_dma_mask; 119 pdev->dev.dma_mask = &ehci_octeon_dma_mask;
120 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
121 if (ret)
122 return ret;
121 123
122 hcd = usb_create_hcd(&ehci_octeon_hc_driver, &pdev->dev, "octeon"); 124 hcd = usb_create_hcd(&ehci_octeon_hc_driver, &pdev->dev, "octeon");
123 if (!hcd) 125 if (!hcd)
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 78b01fa475bb..6fa82d6b7661 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -104,7 +104,7 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
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;
107 int ret = -ENODEV; 107 int ret;
108 int irq; 108 int irq;
109 int i; 109 int i;
110 struct omap_hcd *omap; 110 struct omap_hcd *omap;
@@ -144,11 +144,11 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
144 * Since shared usb code relies on it, set it here for now. 144 * Since shared usb code relies on it, set it here for now.
145 * Once we have dma capability bindings this can go away. 145 * Once we have dma capability bindings this can go away.
146 */ 146 */
147 if (!dev->dma_mask) 147 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
148 dev->dma_mask = &dev->coherent_dma_mask; 148 if (ret)
149 if (!dev->coherent_dma_mask) 149 return ret;
150 dev->coherent_dma_mask = DMA_BIT_MASK(32);
151 150
151 ret = -ENODEV;
152 hcd = usb_create_hcd(&ehci_omap_hc_driver, dev, 152 hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
153 dev_name(dev)); 153 dev_name(dev));
154 if (!hcd) { 154 if (!hcd) {
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index d1dfb9db5b42..2ba76730e650 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -180,10 +180,9 @@ static int ehci_orion_drv_probe(struct platform_device *pdev)
180 * set. Since shared usb code relies on it, set it here for 180 * set. Since shared usb code relies on it, set it here for
181 * now. Once we have dma capability bindings this can go away. 181 * now. Once we have dma capability bindings this can go away.
182 */ 182 */
183 if (!pdev->dev.dma_mask) 183 err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
184 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 184 if (err)
185 if (!pdev->dev.coherent_dma_mask) 185 goto err1;
186 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
187 186
188 if (!request_mem_region(res->start, resource_size(res), 187 if (!request_mem_region(res->start, resource_size(res),
189 ehci_orion_hc_driver.description)) { 188 ehci_orion_hc_driver.description)) {
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 6bd299e61f58..3e86bf4371b3 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -58,8 +58,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
58{ 58{
59 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 59 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
60 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 60 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
61 struct pci_dev *p_smbus;
62 u8 rev;
63 u32 temp; 61 u32 temp;
64 int retval; 62 int retval;
65 63
@@ -175,22 +173,12 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
175 /* SB600 and old version of SB700 have a bug in EHCI controller, 173 /* SB600 and old version of SB700 have a bug in EHCI controller,
176 * which causes usb devices lose response in some cases. 174 * which causes usb devices lose response in some cases.
177 */ 175 */
178 if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) { 176 if ((pdev->device == 0x4386 || pdev->device == 0x4396) &&
179 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI, 177 usb_amd_hang_symptom_quirk()) {
180 PCI_DEVICE_ID_ATI_SBX00_SMBUS, 178 u8 tmp;
181 NULL); 179 ehci_info(ehci, "applying AMD SB600/SB700 USB freeze workaround\n");
182 if (!p_smbus) 180 pci_read_config_byte(pdev, 0x53, &tmp);
183 break; 181 pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
184 rev = p_smbus->revision;
185 if ((pdev->device == 0x4386) || (rev == 0x3a)
186 || (rev == 0x3b)) {
187 u8 tmp;
188 ehci_info(ehci, "applying AMD SB600/SB700 USB "
189 "freeze workaround\n");
190 pci_read_config_byte(pdev, 0x53, &tmp);
191 pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
192 }
193 pci_dev_put(p_smbus);
194 } 182 }
195 break; 183 break;
196 case PCI_VENDOR_ID_NETMOS: 184 case PCI_VENDOR_ID_NETMOS:
@@ -361,7 +349,7 @@ static struct pci_driver ehci_pci_driver = {
361 .remove = usb_hcd_pci_remove, 349 .remove = usb_hcd_pci_remove,
362 .shutdown = usb_hcd_pci_shutdown, 350 .shutdown = usb_hcd_pci_shutdown,
363 351
364#ifdef CONFIG_PM_SLEEP 352#ifdef CONFIG_PM
365 .driver = { 353 .driver = {
366 .pm = &usb_hcd_pci_pm_ops 354 .pm = &usb_hcd_pci_pm_ops
367 }, 355 },
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index f6b790ca8cf2..7f30b7168d5a 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -78,7 +78,7 @@ static int ehci_platform_probe(struct platform_device *dev)
78 struct resource *res_mem; 78 struct resource *res_mem;
79 struct usb_ehci_pdata *pdata; 79 struct usb_ehci_pdata *pdata;
80 int irq; 80 int irq;
81 int err = -ENOMEM; 81 int err;
82 82
83 if (usb_disabled()) 83 if (usb_disabled())
84 return -ENODEV; 84 return -ENODEV;
@@ -89,10 +89,10 @@ static int ehci_platform_probe(struct platform_device *dev)
89 */ 89 */
90 if (!dev_get_platdata(&dev->dev)) 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
93 dev->dev.dma_mask = &dev->dev.coherent_dma_mask; 93 err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
94 if (!dev->dev.coherent_dma_mask) 94 if (err)
95 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 95 return err;
96 96
97 pdata = dev_get_platdata(&dev->dev); 97 pdata = dev_get_platdata(&dev->dev);
98 98
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 6cc5567bf9c8..875d2fcc9e0e 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -16,6 +16,8 @@
16#include <linux/signal.h> 16#include <linux/signal.h>
17 17
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/of_address.h>
20#include <linux/of_irq.h>
19#include <linux/of_platform.h> 21#include <linux/of_platform.h>
20 22
21 23
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index e321804c3475..db05bd8ee9d5 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -105,9 +105,9 @@ qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd)
105 105
106 is_out = qh->is_out; 106 is_out = qh->is_out;
107 epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f; 107 epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f;
108 if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) { 108 if (unlikely(!usb_gettoggle(qh->ps.udev, epnum, is_out))) {
109 hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE); 109 hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE);
110 usb_settoggle (qh->dev, epnum, is_out, 1); 110 usb_settoggle(qh->ps.udev, epnum, is_out, 1);
111 } 111 }
112 } 112 }
113 113
@@ -797,26 +797,35 @@ qh_make (
797 * For control/bulk requests, the HC or TT handles these. 797 * For control/bulk requests, the HC or TT handles these.
798 */ 798 */
799 if (type == PIPE_INTERRUPT) { 799 if (type == PIPE_INTERRUPT) {
800 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, 800 unsigned tmp;
801
802 qh->ps.usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
801 is_input, 0, 803 is_input, 0,
802 hb_mult(maxp) * max_packet(maxp))); 804 hb_mult(maxp) * max_packet(maxp)));
803 qh->start = NO_FRAME; 805 qh->ps.phase = NO_FRAME;
804 806
805 if (urb->dev->speed == USB_SPEED_HIGH) { 807 if (urb->dev->speed == USB_SPEED_HIGH) {
806 qh->c_usecs = 0; 808 qh->ps.c_usecs = 0;
807 qh->gap_uf = 0; 809 qh->gap_uf = 0;
808 810
809 qh->period = urb->interval >> 3; 811 if (urb->interval > 1 && urb->interval < 8) {
810 if (qh->period == 0 && urb->interval != 1) {
811 /* NOTE interval 2 or 4 uframes could work. 812 /* NOTE interval 2 or 4 uframes could work.
812 * But interval 1 scheduling is simpler, and 813 * But interval 1 scheduling is simpler, and
813 * includes high bandwidth. 814 * includes high bandwidth.
814 */ 815 */
815 urb->interval = 1; 816 urb->interval = 1;
816 } else if (qh->period > ehci->periodic_size) { 817 } else if (urb->interval > ehci->periodic_size << 3) {
817 qh->period = ehci->periodic_size; 818 urb->interval = ehci->periodic_size << 3;
818 urb->interval = qh->period << 3;
819 } 819 }
820 qh->ps.period = urb->interval >> 3;
821
822 /* period for bandwidth allocation */
823 tmp = min_t(unsigned, EHCI_BANDWIDTH_SIZE,
824 1 << (urb->ep->desc.bInterval - 1));
825
826 /* Allow urb->interval to override */
827 qh->ps.bw_uperiod = min_t(unsigned, tmp, urb->interval);
828 qh->ps.bw_period = qh->ps.bw_uperiod >> 3;
820 } else { 829 } else {
821 int think_time; 830 int think_time;
822 831
@@ -826,27 +835,35 @@ qh_make (
826 835
827 /* FIXME this just approximates SPLIT/CSPLIT times */ 836 /* FIXME this just approximates SPLIT/CSPLIT times */
828 if (is_input) { // SPLIT, gap, CSPLIT+DATA 837 if (is_input) { // SPLIT, gap, CSPLIT+DATA
829 qh->c_usecs = qh->usecs + HS_USECS (0); 838 qh->ps.c_usecs = qh->ps.usecs + HS_USECS(0);
830 qh->usecs = HS_USECS (1); 839 qh->ps.usecs = HS_USECS(1);
831 } else { // SPLIT+DATA, gap, CSPLIT 840 } else { // SPLIT+DATA, gap, CSPLIT
832 qh->usecs += HS_USECS (1); 841 qh->ps.usecs += HS_USECS(1);
833 qh->c_usecs = HS_USECS (0); 842 qh->ps.c_usecs = HS_USECS(0);
834 } 843 }
835 844
836 think_time = tt ? tt->think_time : 0; 845 think_time = tt ? tt->think_time : 0;
837 qh->tt_usecs = NS_TO_US (think_time + 846 qh->ps.tt_usecs = NS_TO_US(think_time +
838 usb_calc_bus_time (urb->dev->speed, 847 usb_calc_bus_time (urb->dev->speed,
839 is_input, 0, max_packet (maxp))); 848 is_input, 0, max_packet (maxp)));
840 qh->period = urb->interval; 849 if (urb->interval > ehci->periodic_size)
841 if (qh->period > ehci->periodic_size) { 850 urb->interval = ehci->periodic_size;
842 qh->period = ehci->periodic_size; 851 qh->ps.period = urb->interval;
843 urb->interval = qh->period; 852
844 } 853 /* period for bandwidth allocation */
854 tmp = min_t(unsigned, EHCI_BANDWIDTH_FRAMES,
855 urb->ep->desc.bInterval);
856 tmp = rounddown_pow_of_two(tmp);
857
858 /* Allow urb->interval to override */
859 qh->ps.bw_period = min_t(unsigned, tmp, urb->interval);
860 qh->ps.bw_uperiod = qh->ps.bw_period << 3;
845 } 861 }
846 } 862 }
847 863
848 /* support for tt scheduling, and access to toggles */ 864 /* support for tt scheduling, and access to toggles */
849 qh->dev = urb->dev; 865 qh->ps.udev = urb->dev;
866 qh->ps.ep = urb->ep;
850 867
851 /* using TT? */ 868 /* using TT? */
852 switch (urb->dev->speed) { 869 switch (urb->dev->speed) {
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 85dd24ed97a6..e113fd73aeae 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -103,83 +103,210 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr)
103 *hw_p = *shadow_next_periodic(ehci, &here, 103 *hw_p = *shadow_next_periodic(ehci, &here,
104 Q_NEXT_TYPE(ehci, *hw_p)); 104 Q_NEXT_TYPE(ehci, *hw_p));
105 else 105 else
106 *hw_p = ehci->dummy->qh_dma; 106 *hw_p = cpu_to_hc32(ehci, ehci->dummy->qh_dma);
107} 107}
108 108
109/* how many of the uframe's 125 usecs are allocated? */ 109/*-------------------------------------------------------------------------*/
110static unsigned short 110
111periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) 111/* Bandwidth and TT management */
112
113/* Find the TT data structure for this device; create it if necessary */
114static struct ehci_tt *find_tt(struct usb_device *udev)
112{ 115{
113 __hc32 *hw_p = &ehci->periodic [frame]; 116 struct usb_tt *utt = udev->tt;
114 union ehci_shadow *q = &ehci->pshadow [frame]; 117 struct ehci_tt *tt, **tt_index, **ptt;
115 unsigned usecs = 0; 118 unsigned port;
116 struct ehci_qh_hw *hw; 119 bool allocated_index = false;
117 120
118 while (q->ptr) { 121 if (!utt)
119 switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) { 122 return NULL; /* Not below a TT */
120 case Q_TYPE_QH: 123
121 hw = q->qh->hw; 124 /*
122 /* is it in the S-mask? */ 125 * Find/create our data structure.
123 if (hw->hw_info2 & cpu_to_hc32(ehci, 1 << uframe)) 126 * For hubs with a single TT, we get it directly.
124 usecs += q->qh->usecs; 127 * For hubs with multiple TTs, there's an extra level of pointers.
125 /* ... or C-mask? */ 128 */
126 if (hw->hw_info2 & cpu_to_hc32(ehci, 129 tt_index = NULL;
127 1 << (8 + uframe))) 130 if (utt->multi) {
128 usecs += q->qh->c_usecs; 131 tt_index = utt->hcpriv;
129 hw_p = &hw->hw_next; 132 if (!tt_index) { /* Create the index array */
130 q = &q->qh->qh_next; 133 tt_index = kzalloc(utt->hub->maxchild *
131 break; 134 sizeof(*tt_index), GFP_ATOMIC);
132 // case Q_TYPE_FSTN: 135 if (!tt_index)
133 default: 136 return ERR_PTR(-ENOMEM);
134 /* for "save place" FSTNs, count the relevant INTR 137 utt->hcpriv = tt_index;
135 * bandwidth from the previous frame 138 allocated_index = true;
136 */ 139 }
137 if (q->fstn->hw_prev != EHCI_LIST_END(ehci)) { 140 port = udev->ttport - 1;
138 ehci_dbg (ehci, "ignoring FSTN cost ...\n"); 141 ptt = &tt_index[port];
139 } 142 } else {
140 hw_p = &q->fstn->hw_next; 143 port = 0;
141 q = &q->fstn->fstn_next; 144 ptt = (struct ehci_tt **) &utt->hcpriv;
142 break; 145 }
143 case Q_TYPE_ITD: 146
144 if (q->itd->hw_transaction[uframe]) 147 tt = *ptt;
145 usecs += q->itd->stream->usecs; 148 if (!tt) { /* Create the ehci_tt */
146 hw_p = &q->itd->hw_next; 149 struct ehci_hcd *ehci =
147 q = &q->itd->itd_next; 150 hcd_to_ehci(bus_to_hcd(udev->bus));
148 break;
149 case Q_TYPE_SITD:
150 /* is it in the S-mask? (count SPLIT, DATA) */
151 if (q->sitd->hw_uframe & cpu_to_hc32(ehci,
152 1 << uframe)) {
153 if (q->sitd->hw_fullspeed_ep &
154 cpu_to_hc32(ehci, 1<<31))
155 usecs += q->sitd->stream->usecs;
156 else /* worst case for OUT start-split */
157 usecs += HS_USECS_ISO (188);
158 }
159 151
160 /* ... C-mask? (count CSPLIT, DATA) */ 152 tt = kzalloc(sizeof(*tt), GFP_ATOMIC);
161 if (q->sitd->hw_uframe & 153 if (!tt) {
162 cpu_to_hc32(ehci, 1 << (8 + uframe))) { 154 if (allocated_index) {
163 /* worst case for IN complete-split */ 155 utt->hcpriv = NULL;
164 usecs += q->sitd->stream->c_usecs; 156 kfree(tt_index);
165 } 157 }
158 return ERR_PTR(-ENOMEM);
159 }
160 list_add_tail(&tt->tt_list, &ehci->tt_list);
161 INIT_LIST_HEAD(&tt->ps_list);
162 tt->usb_tt = utt;
163 tt->tt_port = port;
164 *ptt = tt;
165 }
166 166
167 hw_p = &q->sitd->hw_next; 167 return tt;
168 q = &q->sitd->sitd_next; 168}
169 break; 169
170/* Release the TT above udev, if it's not in use */
171static void drop_tt(struct usb_device *udev)
172{
173 struct usb_tt *utt = udev->tt;
174 struct ehci_tt *tt, **tt_index, **ptt;
175 int cnt, i;
176
177 if (!utt || !utt->hcpriv)
178 return; /* Not below a TT, or never allocated */
179
180 cnt = 0;
181 if (utt->multi) {
182 tt_index = utt->hcpriv;
183 ptt = &tt_index[udev->ttport - 1];
184
185 /* How many entries are left in tt_index? */
186 for (i = 0; i < utt->hub->maxchild; ++i)
187 cnt += !!tt_index[i];
188 } else {
189 tt_index = NULL;
190 ptt = (struct ehci_tt **) &utt->hcpriv;
191 }
192
193 tt = *ptt;
194 if (!tt || !list_empty(&tt->ps_list))
195 return; /* never allocated, or still in use */
196
197 list_del(&tt->tt_list);
198 *ptt = NULL;
199 kfree(tt);
200 if (cnt == 1) {
201 utt->hcpriv = NULL;
202 kfree(tt_index);
203 }
204}
205
206static void bandwidth_dbg(struct ehci_hcd *ehci, int sign, char *type,
207 struct ehci_per_sched *ps)
208{
209 dev_dbg(&ps->udev->dev,
210 "ep %02x: %s %s @ %u+%u (%u.%u+%u) [%u/%u us] mask %04x\n",
211 ps->ep->desc.bEndpointAddress,
212 (sign >= 0 ? "reserve" : "release"), type,
213 (ps->bw_phase << 3) + ps->phase_uf, ps->bw_uperiod,
214 ps->phase, ps->phase_uf, ps->period,
215 ps->usecs, ps->c_usecs, ps->cs_mask);
216}
217
218static void reserve_release_intr_bandwidth(struct ehci_hcd *ehci,
219 struct ehci_qh *qh, int sign)
220{
221 unsigned start_uf;
222 unsigned i, j, m;
223 int usecs = qh->ps.usecs;
224 int c_usecs = qh->ps.c_usecs;
225 int tt_usecs = qh->ps.tt_usecs;
226 struct ehci_tt *tt;
227
228 if (qh->ps.phase == NO_FRAME) /* Bandwidth wasn't reserved */
229 return;
230 start_uf = qh->ps.bw_phase << 3;
231
232 bandwidth_dbg(ehci, sign, "intr", &qh->ps);
233
234 if (sign < 0) { /* Release bandwidth */
235 usecs = -usecs;
236 c_usecs = -c_usecs;
237 tt_usecs = -tt_usecs;
238 }
239
240 /* Entire transaction (high speed) or start-split (full/low speed) */
241 for (i = start_uf + qh->ps.phase_uf; i < EHCI_BANDWIDTH_SIZE;
242 i += qh->ps.bw_uperiod)
243 ehci->bandwidth[i] += usecs;
244
245 /* Complete-split (full/low speed) */
246 if (qh->ps.c_usecs) {
247 /* NOTE: adjustments needed for FSTN */
248 for (i = start_uf; i < EHCI_BANDWIDTH_SIZE;
249 i += qh->ps.bw_uperiod) {
250 for ((j = 2, m = 1 << (j+8)); j < 8; (++j, m <<= 1)) {
251 if (qh->ps.cs_mask & m)
252 ehci->bandwidth[i+j] += c_usecs;
253 }
170 } 254 }
171 } 255 }
172#if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) 256
173 if (usecs > ehci->uframe_periodic_max) 257 /* FS/LS bus bandwidth */
174 ehci_err (ehci, "uframe %d sched overrun: %d usecs\n", 258 if (tt_usecs) {
175 frame * 8 + uframe, usecs); 259 tt = find_tt(qh->ps.udev);
176#endif 260 if (sign > 0)
177 return usecs; 261 list_add_tail(&qh->ps.ps_list, &tt->ps_list);
262 else
263 list_del(&qh->ps.ps_list);
264
265 for (i = start_uf >> 3; i < EHCI_BANDWIDTH_FRAMES;
266 i += qh->ps.bw_period)
267 tt->bandwidth[i] += tt_usecs;
268 }
178} 269}
179 270
180/*-------------------------------------------------------------------------*/ 271/*-------------------------------------------------------------------------*/
181 272
182static int same_tt (struct usb_device *dev1, struct usb_device *dev2) 273static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE],
274 struct ehci_tt *tt)
275{
276 struct ehci_per_sched *ps;
277 unsigned uframe, uf, x;
278 u8 *budget_line;
279
280 if (!tt)
281 return;
282 memset(budget_table, 0, EHCI_BANDWIDTH_SIZE);
283
284 /* Add up the contributions from all the endpoints using this TT */
285 list_for_each_entry(ps, &tt->ps_list, ps_list) {
286 for (uframe = ps->bw_phase << 3; uframe < EHCI_BANDWIDTH_SIZE;
287 uframe += ps->bw_uperiod) {
288 budget_line = &budget_table[uframe];
289 x = ps->tt_usecs;
290
291 /* propagate the time forward */
292 for (uf = ps->phase_uf; uf < 8; ++uf) {
293 x += budget_line[uf];
294
295 /* Each microframe lasts 125 us */
296 if (x <= 125) {
297 budget_line[uf] = x;
298 break;
299 } else {
300 budget_line[uf] = 125;
301 x -= 125;
302 }
303 }
304 }
305 }
306}
307
308static int __maybe_unused same_tt(struct usb_device *dev1,
309 struct usb_device *dev2)
183{ 310{
184 if (!dev1->tt || !dev2->tt) 311 if (!dev1->tt || !dev2->tt)
185 return 0; 312 return 0;
@@ -227,68 +354,6 @@ static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
227 } 354 }
228} 355}
229 356
230/* How many of the tt's periodic downstream 1000 usecs are allocated?
231 *
232 * While this measures the bandwidth in terms of usecs/uframe,
233 * the low/fullspeed bus has no notion of uframes, so any particular
234 * low/fullspeed transfer can "carry over" from one uframe to the next,
235 * since the TT just performs downstream transfers in sequence.
236 *
237 * For example two separate 100 usec transfers can start in the same uframe,
238 * and the second one would "carry over" 75 usecs into the next uframe.
239 */
240static void
241periodic_tt_usecs (
242 struct ehci_hcd *ehci,
243 struct usb_device *dev,
244 unsigned frame,
245 unsigned short tt_usecs[8]
246)
247{
248 __hc32 *hw_p = &ehci->periodic [frame];
249 union ehci_shadow *q = &ehci->pshadow [frame];
250 unsigned char uf;
251
252 memset(tt_usecs, 0, 16);
253
254 while (q->ptr) {
255 switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) {
256 case Q_TYPE_ITD:
257 hw_p = &q->itd->hw_next;
258 q = &q->itd->itd_next;
259 continue;
260 case Q_TYPE_QH:
261 if (same_tt(dev, q->qh->dev)) {
262 uf = tt_start_uframe(ehci, q->qh->hw->hw_info2);
263 tt_usecs[uf] += q->qh->tt_usecs;
264 }
265 hw_p = &q->qh->hw->hw_next;
266 q = &q->qh->qh_next;
267 continue;
268 case Q_TYPE_SITD:
269 if (same_tt(dev, q->sitd->urb->dev)) {
270 uf = tt_start_uframe(ehci, q->sitd->hw_uframe);
271 tt_usecs[uf] += q->sitd->stream->tt_usecs;
272 }
273 hw_p = &q->sitd->hw_next;
274 q = &q->sitd->sitd_next;
275 continue;
276 // case Q_TYPE_FSTN:
277 default:
278 ehci_dbg(ehci, "ignoring periodic frame %d FSTN\n",
279 frame);
280 hw_p = &q->fstn->hw_next;
281 q = &q->fstn->fstn_next;
282 }
283 }
284
285 carryover_tt_bandwidth(tt_usecs);
286
287 if (max_tt_usecs[7] < tt_usecs[7])
288 ehci_err(ehci, "frame %d tt sched overrun: %d usecs\n",
289 frame, tt_usecs[7] - max_tt_usecs[7]);
290}
291
292/* 357/*
293 * Return true if the device's tt's downstream bus is available for a 358 * Return true if the device's tt's downstream bus is available for a
294 * periodic transfer of the specified length (usecs), starting at the 359 * periodic transfer of the specified length (usecs), starting at the
@@ -312,20 +377,29 @@ periodic_tt_usecs (
312 */ 377 */
313static int tt_available ( 378static int tt_available (
314 struct ehci_hcd *ehci, 379 struct ehci_hcd *ehci,
315 unsigned period, 380 struct ehci_per_sched *ps,
316 struct usb_device *dev, 381 struct ehci_tt *tt,
317 unsigned frame, 382 unsigned frame,
318 unsigned uframe, 383 unsigned uframe
319 u16 usecs
320) 384)
321{ 385{
386 unsigned period = ps->bw_period;
387 unsigned usecs = ps->tt_usecs;
388
322 if ((period == 0) || (uframe >= 7)) /* error */ 389 if ((period == 0) || (uframe >= 7)) /* error */
323 return 0; 390 return 0;
324 391
325 for (; frame < ehci->periodic_size; frame += period) { 392 for (frame &= period - 1; frame < EHCI_BANDWIDTH_FRAMES;
326 unsigned short tt_usecs[8]; 393 frame += period) {
394 unsigned i, uf;
395 unsigned short tt_usecs[8];
327 396
328 periodic_tt_usecs (ehci, dev, frame, tt_usecs); 397 if (tt->bandwidth[frame] + usecs > 900)
398 return 0;
399
400 uf = frame << 3;
401 for (i = 0; i < 8; (++i, ++uf))
402 tt_usecs[i] = ehci->tt_budget[uf];
329 403
330 if (max_tt_usecs[uframe] <= tt_usecs[uframe]) 404 if (max_tt_usecs[uframe] <= tt_usecs[uframe])
331 return 0; 405 return 0;
@@ -337,7 +411,7 @@ static int tt_available (
337 */ 411 */
338 if (125 < usecs) { 412 if (125 < usecs) {
339 int ufs = (usecs / 125); 413 int ufs = (usecs / 125);
340 int i; 414
341 for (i = uframe; i < (uframe + ufs) && i < 8; i++) 415 for (i = uframe; i < (uframe + ufs) && i < 8; i++)
342 if (0 < tt_usecs[i]) 416 if (0 < tt_usecs[i])
343 return 0; 417 return 0;
@@ -391,7 +465,7 @@ static int tt_no_collision (
391 continue; 465 continue;
392 case Q_TYPE_QH: 466 case Q_TYPE_QH:
393 hw = here.qh->hw; 467 hw = here.qh->hw;
394 if (same_tt (dev, here.qh->dev)) { 468 if (same_tt(dev, here.qh->ps.udev)) {
395 u32 mask; 469 u32 mask;
396 470
397 mask = hc32_to_cpu(ehci, 471 mask = hc32_to_cpu(ehci,
@@ -471,19 +545,19 @@ static void disable_periodic(struct ehci_hcd *ehci)
471static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) 545static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
472{ 546{
473 unsigned i; 547 unsigned i;
474 unsigned period = qh->period; 548 unsigned period = qh->ps.period;
475 549
476 dev_dbg (&qh->dev->dev, 550 dev_dbg(&qh->ps.udev->dev,
477 "link qh%d-%04x/%p start %d [%d/%d us]\n", 551 "link qh%d-%04x/%p start %d [%d/%d us]\n",
478 period, hc32_to_cpup(ehci, &qh->hw->hw_info2) 552 period, hc32_to_cpup(ehci, &qh->hw->hw_info2)
479 & (QH_CMASK | QH_SMASK), 553 & (QH_CMASK | QH_SMASK),
480 qh, qh->start, qh->usecs, qh->c_usecs); 554 qh, qh->ps.phase, qh->ps.usecs, qh->ps.c_usecs);
481 555
482 /* high bandwidth, or otherwise every microframe */ 556 /* high bandwidth, or otherwise every microframe */
483 if (period == 0) 557 if (period == 0)
484 period = 1; 558 period = 1;
485 559
486 for (i = qh->start; i < ehci->periodic_size; i += period) { 560 for (i = qh->ps.phase; i < ehci->periodic_size; i += period) {
487 union ehci_shadow *prev = &ehci->pshadow[i]; 561 union ehci_shadow *prev = &ehci->pshadow[i];
488 __hc32 *hw_p = &ehci->periodic[i]; 562 __hc32 *hw_p = &ehci->periodic[i];
489 union ehci_shadow here = *prev; 563 union ehci_shadow here = *prev;
@@ -503,7 +577,7 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
503 * enables sharing interior tree nodes 577 * enables sharing interior tree nodes
504 */ 578 */
505 while (here.ptr && qh != here.qh) { 579 while (here.ptr && qh != here.qh) {
506 if (qh->period > here.qh->period) 580 if (qh->ps.period > here.qh->ps.period)
507 break; 581 break;
508 prev = &here.qh->qh_next; 582 prev = &here.qh->qh_next;
509 hw_p = &here.qh->hw->hw_next; 583 hw_p = &here.qh->hw->hw_next;
@@ -523,10 +597,10 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
523 qh->xacterrs = 0; 597 qh->xacterrs = 0;
524 qh->exception = 0; 598 qh->exception = 0;
525 599
526 /* update per-qh bandwidth for usbfs */ 600 /* update per-qh bandwidth for debugfs */
527 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->period 601 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->ps.bw_period
528 ? ((qh->usecs + qh->c_usecs) / qh->period) 602 ? ((qh->ps.usecs + qh->ps.c_usecs) / qh->ps.bw_period)
529 : (qh->usecs * 8); 603 : (qh->ps.usecs * 8);
530 604
531 list_add(&qh->intr_node, &ehci->intr_qh_list); 605 list_add(&qh->intr_node, &ehci->intr_qh_list);
532 606
@@ -556,22 +630,21 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
556 */ 630 */
557 631
558 /* high bandwidth, or otherwise part of every microframe */ 632 /* high bandwidth, or otherwise part of every microframe */
559 if ((period = qh->period) == 0) 633 period = qh->ps.period ? : 1;
560 period = 1;
561 634
562 for (i = qh->start; i < ehci->periodic_size; i += period) 635 for (i = qh->ps.phase; i < ehci->periodic_size; i += period)
563 periodic_unlink (ehci, i, qh); 636 periodic_unlink (ehci, i, qh);
564 637
565 /* update per-qh bandwidth for usbfs */ 638 /* update per-qh bandwidth for debugfs */
566 ehci_to_hcd(ehci)->self.bandwidth_allocated -= qh->period 639 ehci_to_hcd(ehci)->self.bandwidth_allocated -= qh->ps.bw_period
567 ? ((qh->usecs + qh->c_usecs) / qh->period) 640 ? ((qh->ps.usecs + qh->ps.c_usecs) / qh->ps.bw_period)
568 : (qh->usecs * 8); 641 : (qh->ps.usecs * 8);
569 642
570 dev_dbg (&qh->dev->dev, 643 dev_dbg(&qh->ps.udev->dev,
571 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", 644 "unlink qh%d-%04x/%p start %d [%d/%d us]\n",
572 qh->period, 645 qh->ps.period,
573 hc32_to_cpup(ehci, &qh->hw->hw_info2) & (QH_CMASK | QH_SMASK), 646 hc32_to_cpup(ehci, &qh->hw->hw_info2) & (QH_CMASK | QH_SMASK),
574 qh, qh->start, qh->usecs, qh->c_usecs); 647 qh, qh->ps.phase, qh->ps.usecs, qh->ps.c_usecs);
575 648
576 /* qh->qh_next still "live" to HC */ 649 /* qh->qh_next still "live" to HC */
577 qh->qh_state = QH_STATE_UNLINK; 650 qh->qh_state = QH_STATE_UNLINK;
@@ -694,11 +767,9 @@ static int check_period (
694 struct ehci_hcd *ehci, 767 struct ehci_hcd *ehci,
695 unsigned frame, 768 unsigned frame,
696 unsigned uframe, 769 unsigned uframe,
697 unsigned period, 770 unsigned uperiod,
698 unsigned usecs 771 unsigned usecs
699) { 772) {
700 int claimed;
701
702 /* complete split running into next frame? 773 /* complete split running into next frame?
703 * given FSTN support, we could sometimes check... 774 * given FSTN support, we could sometimes check...
704 */ 775 */
@@ -708,25 +779,10 @@ static int check_period (
708 /* convert "usecs we need" to "max already claimed" */ 779 /* convert "usecs we need" to "max already claimed" */
709 usecs = ehci->uframe_periodic_max - usecs; 780 usecs = ehci->uframe_periodic_max - usecs;
710 781
711 /* we "know" 2 and 4 uframe intervals were rejected; so 782 for (uframe += frame << 3; uframe < EHCI_BANDWIDTH_SIZE;
712 * for period 0, check _every_ microframe in the schedule. 783 uframe += uperiod) {
713 */ 784 if (ehci->bandwidth[uframe] > usecs)
714 if (unlikely (period == 0)) { 785 return 0;
715 do {
716 for (uframe = 0; uframe < 7; uframe++) {
717 claimed = periodic_usecs (ehci, frame, uframe);
718 if (claimed > usecs)
719 return 0;
720 }
721 } while ((frame += 1) < ehci->periodic_size);
722
723 /* just check the specified uframe, at that period */
724 } else {
725 do {
726 claimed = periodic_usecs (ehci, frame, uframe);
727 if (claimed > usecs)
728 return 0;
729 } while ((frame += period) < ehci->periodic_size);
730 } 786 }
731 787
732 // success! 788 // success!
@@ -737,40 +793,40 @@ static int check_intr_schedule (
737 struct ehci_hcd *ehci, 793 struct ehci_hcd *ehci,
738 unsigned frame, 794 unsigned frame,
739 unsigned uframe, 795 unsigned uframe,
740 const struct ehci_qh *qh, 796 struct ehci_qh *qh,
741 __hc32 *c_maskp 797 unsigned *c_maskp,
798 struct ehci_tt *tt
742) 799)
743{ 800{
744 int retval = -ENOSPC; 801 int retval = -ENOSPC;
745 u8 mask = 0; 802 u8 mask = 0;
746 803
747 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ 804 if (qh->ps.c_usecs && uframe >= 6) /* FSTN territory? */
748 goto done; 805 goto done;
749 806
750 if (!check_period (ehci, frame, uframe, qh->period, qh->usecs)) 807 if (!check_period(ehci, frame, uframe, qh->ps.bw_uperiod, qh->ps.usecs))
751 goto done; 808 goto done;
752 if (!qh->c_usecs) { 809 if (!qh->ps.c_usecs) {
753 retval = 0; 810 retval = 0;
754 *c_maskp = 0; 811 *c_maskp = 0;
755 goto done; 812 goto done;
756 } 813 }
757 814
758#ifdef CONFIG_USB_EHCI_TT_NEWSCHED 815#ifdef CONFIG_USB_EHCI_TT_NEWSCHED
759 if (tt_available (ehci, qh->period, qh->dev, frame, uframe, 816 if (tt_available(ehci, &qh->ps, tt, frame, uframe)) {
760 qh->tt_usecs)) {
761 unsigned i; 817 unsigned i;
762 818
763 /* TODO : this may need FSTN for SSPLIT in uframe 5. */ 819 /* TODO : this may need FSTN for SSPLIT in uframe 5. */
764 for (i=uframe+1; i<8 && i<uframe+4; i++) 820 for (i = uframe+2; i < 8 && i <= uframe+4; i++)
765 if (!check_period (ehci, frame, i, 821 if (!check_period(ehci, frame, i,
766 qh->period, qh->c_usecs)) 822 qh->ps.bw_uperiod, qh->ps.c_usecs))
767 goto done; 823 goto done;
768 else 824 else
769 mask |= 1 << i; 825 mask |= 1 << i;
770 826
771 retval = 0; 827 retval = 0;
772 828
773 *c_maskp = cpu_to_hc32(ehci, mask << 8); 829 *c_maskp = mask;
774 } 830 }
775#else 831#else
776 /* Make sure this tt's buffer is also available for CSPLITs. 832 /* Make sure this tt's buffer is also available for CSPLITs.
@@ -781,15 +837,15 @@ static int check_intr_schedule (
781 * one smart pass... 837 * one smart pass...
782 */ 838 */
783 mask = 0x03 << (uframe + qh->gap_uf); 839 mask = 0x03 << (uframe + qh->gap_uf);
784 *c_maskp = cpu_to_hc32(ehci, mask << 8); 840 *c_maskp = mask;
785 841
786 mask |= 1 << uframe; 842 mask |= 1 << uframe;
787 if (tt_no_collision (ehci, qh->period, qh->dev, frame, mask)) { 843 if (tt_no_collision(ehci, qh->ps.bw_period, qh->ps.udev, frame, mask)) {
788 if (!check_period (ehci, frame, uframe + qh->gap_uf + 1, 844 if (!check_period(ehci, frame, uframe + qh->gap_uf + 1,
789 qh->period, qh->c_usecs)) 845 qh->ps.bw_uperiod, qh->ps.c_usecs))
790 goto done; 846 goto done;
791 if (!check_period (ehci, frame, uframe + qh->gap_uf, 847 if (!check_period(ehci, frame, uframe + qh->gap_uf,
792 qh->period, qh->c_usecs)) 848 qh->ps.bw_uperiod, qh->ps.c_usecs))
793 goto done; 849 goto done;
794 retval = 0; 850 retval = 0;
795 } 851 }
@@ -803,62 +859,67 @@ done:
803 */ 859 */
804static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh) 860static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)
805{ 861{
806 int status; 862 int status = 0;
807 unsigned uframe; 863 unsigned uframe;
808 __hc32 c_mask; 864 unsigned c_mask;
809 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
810 struct ehci_qh_hw *hw = qh->hw; 865 struct ehci_qh_hw *hw = qh->hw;
866 struct ehci_tt *tt;
811 867
812 hw->hw_next = EHCI_LIST_END(ehci); 868 hw->hw_next = EHCI_LIST_END(ehci);
813 frame = qh->start;
814 869
815 /* reuse the previous schedule slots, if we can */ 870 /* reuse the previous schedule slots, if we can */
816 if (frame < qh->period) { 871 if (qh->ps.phase != NO_FRAME) {
817 uframe = ffs(hc32_to_cpup(ehci, &hw->hw_info2) & QH_SMASK); 872 ehci_dbg(ehci, "reused qh %p schedule\n", qh);
818 status = check_intr_schedule (ehci, frame, --uframe, 873 return 0;
819 qh, &c_mask); 874 }
820 } else { 875
821 uframe = 0; 876 uframe = 0;
822 c_mask = 0; 877 c_mask = 0;
823 status = -ENOSPC; 878 tt = find_tt(qh->ps.udev);
879 if (IS_ERR(tt)) {
880 status = PTR_ERR(tt);
881 goto done;
824 } 882 }
883 compute_tt_budget(ehci->tt_budget, tt);
825 884
826 /* else scan the schedule to find a group of slots such that all 885 /* else scan the schedule to find a group of slots such that all
827 * uframes have enough periodic bandwidth available. 886 * uframes have enough periodic bandwidth available.
828 */ 887 */
829 if (status) { 888 /* "normal" case, uframing flexible except with splits */
830 /* "normal" case, uframing flexible except with splits */ 889 if (qh->ps.bw_period) {
831 if (qh->period) { 890 int i;
832 int i; 891 unsigned frame;
833 892
834 for (i = qh->period; status && i > 0; --i) { 893 for (i = qh->ps.bw_period; i > 0; --i) {
835 frame = ++ehci->random_frame % qh->period; 894 frame = ++ehci->random_frame & (qh->ps.bw_period - 1);
836 for (uframe = 0; uframe < 8; uframe++) { 895 for (uframe = 0; uframe < 8; uframe++) {
837 status = check_intr_schedule (ehci, 896 status = check_intr_schedule(ehci,
838 frame, uframe, qh, 897 frame, uframe, qh, &c_mask, tt);
839 &c_mask); 898 if (status == 0)
840 if (status == 0) 899 goto got_it;
841 break;
842 }
843 } 900 }
844
845 /* qh->period == 0 means every uframe */
846 } else {
847 frame = 0;
848 status = check_intr_schedule (ehci, 0, 0, qh, &c_mask);
849 } 901 }
850 if (status)
851 goto done;
852 qh->start = frame;
853 902
854 /* reset S-frame and (maybe) C-frame masks */ 903 /* qh->ps.bw_period == 0 means every uframe */
855 hw->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK)); 904 } else {
856 hw->hw_info2 |= qh->period 905 status = check_intr_schedule(ehci, 0, 0, qh, &c_mask, tt);
857 ? cpu_to_hc32(ehci, 1 << uframe) 906 }
858 : cpu_to_hc32(ehci, QH_SMASK); 907 if (status)
859 hw->hw_info2 |= c_mask; 908 goto done;
860 } else 909
861 ehci_dbg (ehci, "reused qh %p schedule\n", qh); 910 got_it:
911 qh->ps.phase = (qh->ps.period ? ehci->random_frame &
912 (qh->ps.period - 1) : 0);
913 qh->ps.bw_phase = qh->ps.phase & (qh->ps.bw_period - 1);
914 qh->ps.phase_uf = uframe;
915 qh->ps.cs_mask = qh->ps.period ?
916 (c_mask << 8) | (1 << uframe) :
917 QH_SMASK;
918
919 /* reset S-frame and (maybe) C-frame masks */
920 hw->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK));
921 hw->hw_info2 |= cpu_to_hc32(ehci, qh->ps.cs_mask);
922 reserve_release_intr_bandwidth(ehci, qh, 1);
862 923
863done: 924done:
864 return status; 925 return status;
@@ -969,7 +1030,8 @@ iso_stream_alloc (gfp_t mem_flags)
969 if (likely (stream != NULL)) { 1030 if (likely (stream != NULL)) {
970 INIT_LIST_HEAD(&stream->td_list); 1031 INIT_LIST_HEAD(&stream->td_list);
971 INIT_LIST_HEAD(&stream->free_list); 1032 INIT_LIST_HEAD(&stream->free_list);
972 stream->next_uframe = -1; 1033 stream->next_uframe = NO_FRAME;
1034 stream->ps.phase = NO_FRAME;
973 } 1035 }
974 return stream; 1036 return stream;
975} 1037}
@@ -978,25 +1040,24 @@ static void
978iso_stream_init ( 1040iso_stream_init (
979 struct ehci_hcd *ehci, 1041 struct ehci_hcd *ehci,
980 struct ehci_iso_stream *stream, 1042 struct ehci_iso_stream *stream,
981 struct usb_device *dev, 1043 struct urb *urb
982 int pipe,
983 unsigned interval
984) 1044)
985{ 1045{
986 static const u8 smask_out [] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f }; 1046 static const u8 smask_out [] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f };
987 1047
1048 struct usb_device *dev = urb->dev;
988 u32 buf1; 1049 u32 buf1;
989 unsigned epnum, maxp; 1050 unsigned epnum, maxp;
990 int is_input; 1051 int is_input;
991 long bandwidth; 1052 unsigned tmp;
992 1053
993 /* 1054 /*
994 * this might be a "high bandwidth" highspeed endpoint, 1055 * this might be a "high bandwidth" highspeed endpoint,
995 * as encoded in the ep descriptor's wMaxPacket field 1056 * as encoded in the ep descriptor's wMaxPacket field
996 */ 1057 */
997 epnum = usb_pipeendpoint (pipe); 1058 epnum = usb_pipeendpoint(urb->pipe);
998 is_input = usb_pipein (pipe) ? USB_DIR_IN : 0; 1059 is_input = usb_pipein(urb->pipe) ? USB_DIR_IN : 0;
999 maxp = usb_maxpacket(dev, pipe, !is_input); 1060 maxp = usb_endpoint_maxp(&urb->ep->desc);
1000 if (is_input) { 1061 if (is_input) {
1001 buf1 = (1 << 11); 1062 buf1 = (1 << 11);
1002 } else { 1063 } else {
@@ -1020,9 +1081,19 @@ iso_stream_init (
1020 /* usbfs wants to report the average usecs per frame tied up 1081 /* usbfs wants to report the average usecs per frame tied up
1021 * when transfers on this endpoint are scheduled ... 1082 * when transfers on this endpoint are scheduled ...
1022 */ 1083 */
1023 stream->usecs = HS_USECS_ISO (maxp); 1084 stream->ps.usecs = HS_USECS_ISO(maxp);
1024 bandwidth = stream->usecs * 8; 1085
1025 bandwidth /= interval; 1086 /* period for bandwidth allocation */
1087 tmp = min_t(unsigned, EHCI_BANDWIDTH_SIZE,
1088 1 << (urb->ep->desc.bInterval - 1));
1089
1090 /* Allow urb->interval to override */
1091 stream->ps.bw_uperiod = min_t(unsigned, tmp, urb->interval);
1092
1093 stream->uperiod = urb->interval;
1094 stream->ps.period = urb->interval >> 3;
1095 stream->bandwidth = stream->ps.usecs * 8 /
1096 stream->ps.bw_uperiod;
1026 1097
1027 } else { 1098 } else {
1028 u32 addr; 1099 u32 addr;
@@ -1036,36 +1107,46 @@ iso_stream_init (
1036 addr |= dev->tt->hub->devnum << 16; 1107 addr |= dev->tt->hub->devnum << 16;
1037 addr |= epnum << 8; 1108 addr |= epnum << 8;
1038 addr |= dev->devnum; 1109 addr |= dev->devnum;
1039 stream->usecs = HS_USECS_ISO (maxp); 1110 stream->ps.usecs = HS_USECS_ISO(maxp);
1040 think_time = dev->tt ? dev->tt->think_time : 0; 1111 think_time = dev->tt ? dev->tt->think_time : 0;
1041 stream->tt_usecs = NS_TO_US (think_time + usb_calc_bus_time ( 1112 stream->ps.tt_usecs = NS_TO_US(think_time + usb_calc_bus_time(
1042 dev->speed, is_input, 1, maxp)); 1113 dev->speed, is_input, 1, maxp));
1043 hs_transfers = max (1u, (maxp + 187) / 188); 1114 hs_transfers = max (1u, (maxp + 187) / 188);
1044 if (is_input) { 1115 if (is_input) {
1045 u32 tmp; 1116 u32 tmp;
1046 1117
1047 addr |= 1 << 31; 1118 addr |= 1 << 31;
1048 stream->c_usecs = stream->usecs; 1119 stream->ps.c_usecs = stream->ps.usecs;
1049 stream->usecs = HS_USECS_ISO (1); 1120 stream->ps.usecs = HS_USECS_ISO(1);
1050 stream->raw_mask = 1; 1121 stream->ps.cs_mask = 1;
1051 1122
1052 /* c-mask as specified in USB 2.0 11.18.4 3.c */ 1123 /* c-mask as specified in USB 2.0 11.18.4 3.c */
1053 tmp = (1 << (hs_transfers + 2)) - 1; 1124 tmp = (1 << (hs_transfers + 2)) - 1;
1054 stream->raw_mask |= tmp << (8 + 2); 1125 stream->ps.cs_mask |= tmp << (8 + 2);
1055 } else 1126 } else
1056 stream->raw_mask = smask_out [hs_transfers - 1]; 1127 stream->ps.cs_mask = smask_out[hs_transfers - 1];
1057 bandwidth = stream->usecs + stream->c_usecs; 1128
1058 bandwidth /= interval << 3; 1129 /* period for bandwidth allocation */
1130 tmp = min_t(unsigned, EHCI_BANDWIDTH_FRAMES,
1131 1 << (urb->ep->desc.bInterval - 1));
1132
1133 /* Allow urb->interval to override */
1134 stream->ps.bw_period = min_t(unsigned, tmp, urb->interval);
1135 stream->ps.bw_uperiod = stream->ps.bw_period << 3;
1059 1136
1060 /* stream->splits gets created from raw_mask later */ 1137 stream->ps.period = urb->interval;
1138 stream->uperiod = urb->interval << 3;
1139 stream->bandwidth = (stream->ps.usecs + stream->ps.c_usecs) /
1140 stream->ps.bw_period;
1141
1142 /* stream->splits gets created from cs_mask later */
1061 stream->address = cpu_to_hc32(ehci, addr); 1143 stream->address = cpu_to_hc32(ehci, addr);
1062 } 1144 }
1063 stream->bandwidth = bandwidth;
1064 1145
1065 stream->udev = dev; 1146 stream->ps.udev = dev;
1147 stream->ps.ep = urb->ep;
1066 1148
1067 stream->bEndpointAddress = is_input | epnum; 1149 stream->bEndpointAddress = is_input | epnum;
1068 stream->interval = interval;
1069 stream->maxp = maxp; 1150 stream->maxp = maxp;
1070} 1151}
1071 1152
@@ -1090,9 +1171,7 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
1090 stream = iso_stream_alloc(GFP_ATOMIC); 1171 stream = iso_stream_alloc(GFP_ATOMIC);
1091 if (likely (stream != NULL)) { 1172 if (likely (stream != NULL)) {
1092 ep->hcpriv = stream; 1173 ep->hcpriv = stream;
1093 stream->ep = ep; 1174 iso_stream_init(ehci, stream, urb);
1094 iso_stream_init(ehci, stream, urb->dev, urb->pipe,
1095 urb->interval);
1096 } 1175 }
1097 1176
1098 /* if dev->ep [epnum] is a QH, hw is set */ 1177 /* if dev->ep [epnum] is a QH, hw is set */
@@ -1137,7 +1216,7 @@ itd_sched_init(
1137 dma_addr_t dma = urb->transfer_dma; 1216 dma_addr_t dma = urb->transfer_dma;
1138 1217
1139 /* how many uframes are needed for these transfers */ 1218 /* how many uframes are needed for these transfers */
1140 iso_sched->span = urb->number_of_packets * stream->interval; 1219 iso_sched->span = urb->number_of_packets * stream->uperiod;
1141 1220
1142 /* figure out per-uframe itd fields that we'll need later 1221 /* figure out per-uframe itd fields that we'll need later
1143 * when we fit new itds into the schedule. 1222 * when we fit new itds into the schedule.
@@ -1236,7 +1315,7 @@ itd_urb_transaction (
1236 1315
1237 memset (itd, 0, sizeof *itd); 1316 memset (itd, 0, sizeof *itd);
1238 itd->itd_dma = itd_dma; 1317 itd->itd_dma = itd_dma;
1239 itd->frame = 9999; /* an invalid value */ 1318 itd->frame = NO_FRAME;
1240 list_add (&itd->itd_list, &sched->td_list); 1319 list_add (&itd->itd_list, &sched->td_list);
1241 } 1320 }
1242 spin_unlock_irqrestore (&ehci->lock, flags); 1321 spin_unlock_irqrestore (&ehci->lock, flags);
@@ -1249,49 +1328,106 @@ itd_urb_transaction (
1249 1328
1250/*-------------------------------------------------------------------------*/ 1329/*-------------------------------------------------------------------------*/
1251 1330
1331static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
1332 struct ehci_iso_stream *stream, int sign)
1333{
1334 unsigned uframe;
1335 unsigned i, j;
1336 unsigned s_mask, c_mask, m;
1337 int usecs = stream->ps.usecs;
1338 int c_usecs = stream->ps.c_usecs;
1339 int tt_usecs = stream->ps.tt_usecs;
1340 struct ehci_tt *tt;
1341
1342 if (stream->ps.phase == NO_FRAME) /* Bandwidth wasn't reserved */
1343 return;
1344 uframe = stream->ps.bw_phase << 3;
1345
1346 bandwidth_dbg(ehci, sign, "iso", &stream->ps);
1347
1348 if (sign < 0) { /* Release bandwidth */
1349 usecs = -usecs;
1350 c_usecs = -c_usecs;
1351 tt_usecs = -tt_usecs;
1352 }
1353
1354 if (!stream->splits) { /* High speed */
1355 for (i = uframe + stream->ps.phase_uf; i < EHCI_BANDWIDTH_SIZE;
1356 i += stream->ps.bw_uperiod)
1357 ehci->bandwidth[i] += usecs;
1358
1359 } else { /* Full speed */
1360 s_mask = stream->ps.cs_mask;
1361 c_mask = s_mask >> 8;
1362
1363 /* NOTE: adjustment needed for frame overflow */
1364 for (i = uframe; i < EHCI_BANDWIDTH_SIZE;
1365 i += stream->ps.bw_uperiod) {
1366 for ((j = stream->ps.phase_uf, m = 1 << j); j < 8;
1367 (++j, m <<= 1)) {
1368 if (s_mask & m)
1369 ehci->bandwidth[i+j] += usecs;
1370 else if (c_mask & m)
1371 ehci->bandwidth[i+j] += c_usecs;
1372 }
1373 }
1374
1375 tt = find_tt(stream->ps.udev);
1376 if (sign > 0)
1377 list_add_tail(&stream->ps.ps_list, &tt->ps_list);
1378 else
1379 list_del(&stream->ps.ps_list);
1380
1381 for (i = uframe >> 3; i < EHCI_BANDWIDTH_FRAMES;
1382 i += stream->ps.bw_period)
1383 tt->bandwidth[i] += tt_usecs;
1384 }
1385}
1386
1252static inline int 1387static inline int
1253itd_slot_ok ( 1388itd_slot_ok (
1254 struct ehci_hcd *ehci, 1389 struct ehci_hcd *ehci,
1255 u32 mod, 1390 struct ehci_iso_stream *stream,
1256 u32 uframe, 1391 unsigned uframe
1257 u8 usecs,
1258 u32 period
1259) 1392)
1260{ 1393{
1261 uframe %= period; 1394 unsigned usecs;
1262 do { 1395
1263 /* can't commit more than uframe_periodic_max usec */ 1396 /* convert "usecs we need" to "max already claimed" */
1264 if (periodic_usecs (ehci, uframe >> 3, uframe & 0x7) 1397 usecs = ehci->uframe_periodic_max - stream->ps.usecs;
1265 > (ehci->uframe_periodic_max - usecs))
1266 return 0;
1267 1398
1268 /* we know urb->interval is 2^N uframes */ 1399 for (uframe &= stream->ps.bw_uperiod - 1; uframe < EHCI_BANDWIDTH_SIZE;
1269 uframe += period; 1400 uframe += stream->ps.bw_uperiod) {
1270 } while (uframe < mod); 1401 if (ehci->bandwidth[uframe] > usecs)
1402 return 0;
1403 }
1271 return 1; 1404 return 1;
1272} 1405}
1273 1406
1274static inline int 1407static inline int
1275sitd_slot_ok ( 1408sitd_slot_ok (
1276 struct ehci_hcd *ehci, 1409 struct ehci_hcd *ehci,
1277 u32 mod,
1278 struct ehci_iso_stream *stream, 1410 struct ehci_iso_stream *stream,
1279 u32 uframe, 1411 unsigned uframe,
1280 struct ehci_iso_sched *sched, 1412 struct ehci_iso_sched *sched,
1281 u32 period_uframes 1413 struct ehci_tt *tt
1282) 1414)
1283{ 1415{
1284 u32 mask, tmp; 1416 unsigned mask, tmp;
1285 u32 frame, uf; 1417 unsigned frame, uf;
1418
1419 mask = stream->ps.cs_mask << (uframe & 7);
1286 1420
1287 mask = stream->raw_mask << (uframe & 7); 1421 /* for OUT, don't wrap SSPLIT into H-microframe 7 */
1422 if (((stream->ps.cs_mask & 0xff) << (uframe & 7)) >= (1 << 7))
1423 return 0;
1288 1424
1289 /* for IN, don't wrap CSPLIT into the next frame */ 1425 /* for IN, don't wrap CSPLIT into the next frame */
1290 if (mask & ~0xffff) 1426 if (mask & ~0xffff)
1291 return 0; 1427 return 0;
1292 1428
1293 /* check bandwidth */ 1429 /* check bandwidth */
1294 uframe %= period_uframes; 1430 uframe &= stream->ps.bw_uperiod - 1;
1295 frame = uframe >> 3; 1431 frame = uframe >> 3;
1296 1432
1297#ifdef CONFIG_USB_EHCI_TT_NEWSCHED 1433#ifdef CONFIG_USB_EHCI_TT_NEWSCHED
@@ -1299,54 +1435,48 @@ sitd_slot_ok (
1299 * tt_available scheduling guarantees 10+% for control/bulk. 1435 * tt_available scheduling guarantees 10+% for control/bulk.
1300 */ 1436 */
1301 uf = uframe & 7; 1437 uf = uframe & 7;
1302 if (!tt_available(ehci, period_uframes >> 3, 1438 if (!tt_available(ehci, &stream->ps, tt, frame, uf))
1303 stream->udev, frame, uf, stream->tt_usecs))
1304 return 0; 1439 return 0;
1305#else 1440#else
1306 /* tt must be idle for start(s), any gap, and csplit. 1441 /* tt must be idle for start(s), any gap, and csplit.
1307 * assume scheduling slop leaves 10+% for control/bulk. 1442 * assume scheduling slop leaves 10+% for control/bulk.
1308 */ 1443 */
1309 if (!tt_no_collision(ehci, period_uframes >> 3, 1444 if (!tt_no_collision(ehci, stream->ps.bw_period,
1310 stream->udev, frame, mask)) 1445 stream->ps.udev, frame, mask))
1311 return 0; 1446 return 0;
1312#endif 1447#endif
1313 1448
1314 /* this multi-pass logic is simple, but performance may
1315 * suffer when the schedule data isn't cached.
1316 */
1317 do { 1449 do {
1318 u32 max_used; 1450 unsigned max_used;
1319 1451 unsigned i;
1320 frame = uframe >> 3;
1321 uf = uframe & 7;
1322 1452
1323 /* check starts (OUT uses more than one) */ 1453 /* check starts (OUT uses more than one) */
1324 max_used = ehci->uframe_periodic_max - stream->usecs; 1454 uf = uframe;
1325 for (tmp = stream->raw_mask & 0xff; tmp; tmp >>= 1, uf++) { 1455 max_used = ehci->uframe_periodic_max - stream->ps.usecs;
1326 if (periodic_usecs (ehci, frame, uf) > max_used) 1456 for (tmp = stream->ps.cs_mask & 0xff; tmp; tmp >>= 1, uf++) {
1457 if (ehci->bandwidth[uf] > max_used)
1327 return 0; 1458 return 0;
1328 } 1459 }
1329 1460
1330 /* for IN, check CSPLIT */ 1461 /* for IN, check CSPLIT */
1331 if (stream->c_usecs) { 1462 if (stream->ps.c_usecs) {
1332 uf = uframe & 7; 1463 max_used = ehci->uframe_periodic_max -
1333 max_used = ehci->uframe_periodic_max - stream->c_usecs; 1464 stream->ps.c_usecs;
1334 do { 1465 uf = uframe & ~7;
1335 tmp = 1 << uf; 1466 tmp = 1 << (2+8);
1336 tmp <<= 8; 1467 for (i = (uframe & 7) + 2; i < 8; (++i, tmp <<= 1)) {
1337 if ((stream->raw_mask & tmp) == 0) 1468 if ((stream->ps.cs_mask & tmp) == 0)
1338 continue; 1469 continue;
1339 if (periodic_usecs (ehci, frame, uf) 1470 if (ehci->bandwidth[uf+i] > max_used)
1340 > max_used)
1341 return 0; 1471 return 0;
1342 } while (++uf < 8); 1472 }
1343 } 1473 }
1344 1474
1345 /* we know urb->interval is 2^N uframes */ 1475 uframe += stream->ps.bw_uperiod;
1346 uframe += period_uframes; 1476 } while (uframe < EHCI_BANDWIDTH_SIZE);
1347 } while (uframe < mod);
1348 1477
1349 stream->splits = cpu_to_hc32(ehci, stream->raw_mask << (uframe & 7)); 1478 stream->ps.cs_mask <<= uframe & 7;
1479 stream->splits = cpu_to_hc32(ehci, stream->ps.cs_mask);
1350 return 1; 1480 return 1;
1351} 1481}
1352 1482
@@ -1361,8 +1491,6 @@ sitd_slot_ok (
1361 * given EHCI_TUNE_FLS and the slop). Or, write a smarter scheduler! 1491 * given EHCI_TUNE_FLS and the slop). Or, write a smarter scheduler!
1362 */ 1492 */
1363 1493
1364#define SCHEDULING_DELAY 40 /* microframes */
1365
1366static int 1494static int
1367iso_stream_schedule ( 1495iso_stream_schedule (
1368 struct ehci_hcd *ehci, 1496 struct ehci_hcd *ehci,
@@ -1370,134 +1498,184 @@ iso_stream_schedule (
1370 struct ehci_iso_stream *stream 1498 struct ehci_iso_stream *stream
1371) 1499)
1372{ 1500{
1373 u32 now, base, next, start, period, span; 1501 u32 now, base, next, start, period, span, now2;
1374 int status; 1502 u32 wrap = 0, skip = 0;
1503 int status = 0;
1375 unsigned mod = ehci->periodic_size << 3; 1504 unsigned mod = ehci->periodic_size << 3;
1376 struct ehci_iso_sched *sched = urb->hcpriv; 1505 struct ehci_iso_sched *sched = urb->hcpriv;
1506 bool empty = list_empty(&stream->td_list);
1507 bool new_stream = false;
1377 1508
1378 period = urb->interval; 1509 period = stream->uperiod;
1379 span = sched->span; 1510 span = sched->span;
1380 if (!stream->highspeed) { 1511 if (!stream->highspeed)
1381 period <<= 3;
1382 span <<= 3; 1512 span <<= 3;
1383 }
1384 1513
1385 now = ehci_read_frame_index(ehci) & (mod - 1); 1514 /* Start a new isochronous stream? */
1515 if (unlikely(empty && !hcd_periodic_completion_in_progress(
1516 ehci_to_hcd(ehci), urb->ep))) {
1386 1517
1387 /* Typical case: reuse current schedule, stream is still active. 1518 /* Schedule the endpoint */
1388 * Hopefully there are no gaps from the host falling behind 1519 if (stream->ps.phase == NO_FRAME) {
1389 * (irq delays etc). If there are, the behavior depends on 1520 int done = 0;
1390 * whether URB_ISO_ASAP is set. 1521 struct ehci_tt *tt = find_tt(stream->ps.udev);
1391 */
1392 if (likely (!list_empty (&stream->td_list))) {
1393 1522
1394 /* Take the isochronous scheduling threshold into account */ 1523 if (IS_ERR(tt)) {
1395 if (ehci->i_thresh) 1524 status = PTR_ERR(tt);
1396 next = now + ehci->i_thresh; /* uframe cache */ 1525 goto fail;
1397 else 1526 }
1398 next = (now + 2 + 7) & ~0x07; /* full frame cache */ 1527 compute_tt_budget(ehci->tt_budget, tt);
1399
1400 /*
1401 * Use ehci->last_iso_frame as the base. There can't be any
1402 * TDs scheduled for earlier than that.
1403 */
1404 base = ehci->last_iso_frame << 3;
1405 next = (next - base) & (mod - 1);
1406 start = (stream->next_uframe - base) & (mod - 1);
1407
1408 /* Is the schedule already full? */
1409 if (unlikely(start < period)) {
1410 ehci_dbg(ehci, "iso sched full %p (%u-%u < %u mod %u)\n",
1411 urb, stream->next_uframe, base,
1412 period, mod);
1413 status = -ENOSPC;
1414 goto fail;
1415 }
1416
1417 /* Behind the scheduling threshold? */
1418 if (unlikely(start < next)) {
1419 unsigned now2 = (now - base) & (mod - 1);
1420 1528
1421 /* USB_ISO_ASAP: Round up to the first available slot */ 1529 start = ((-(++ehci->random_frame)) << 3) & (period - 1);
1422 if (urb->transfer_flags & URB_ISO_ASAP)
1423 start += (next - start + period - 1) & -period;
1424 1530
1425 /* 1531 /* find a uframe slot with enough bandwidth.
1426 * Not ASAP: Use the next slot in the stream, 1532 * Early uframes are more precious because full-speed
1427 * no matter what. 1533 * iso IN transfers can't use late uframes,
1534 * and therefore they should be allocated last.
1428 */ 1535 */
1429 else if (start + span - period < now2) { 1536 next = start;
1430 ehci_dbg(ehci, "iso underrun %p (%u+%u < %u)\n", 1537 start += period;
1431 urb, start + base, 1538 do {
1432 span - period, now2 + base); 1539 start--;
1540 /* check schedule: enough space? */
1541 if (stream->highspeed) {
1542 if (itd_slot_ok(ehci, stream, start))
1543 done = 1;
1544 } else {
1545 if ((start % 8) >= 6)
1546 continue;
1547 if (sitd_slot_ok(ehci, stream, start,
1548 sched, tt))
1549 done = 1;
1550 }
1551 } while (start > next && !done);
1552
1553 /* no room in the schedule */
1554 if (!done) {
1555 ehci_dbg(ehci, "iso sched full %p", urb);
1556 status = -ENOSPC;
1557 goto fail;
1433 } 1558 }
1559 stream->ps.phase = (start >> 3) &
1560 (stream->ps.period - 1);
1561 stream->ps.bw_phase = stream->ps.phase &
1562 (stream->ps.bw_period - 1);
1563 stream->ps.phase_uf = start & 7;
1564 reserve_release_iso_bandwidth(ehci, stream, 1);
1565 }
1566
1567 /* New stream is already scheduled; use the upcoming slot */
1568 else {
1569 start = (stream->ps.phase << 3) + stream->ps.phase_uf;
1434 } 1570 }
1435 1571
1436 start += base; 1572 stream->next_uframe = start;
1573 new_stream = true;
1437 } 1574 }
1438 1575
1439 /* need to schedule; when's the next (u)frame we could start? 1576 now = ehci_read_frame_index(ehci) & (mod - 1);
1440 * this is bigger than ehci->i_thresh allows; scheduling itself 1577
1441 * isn't free, the delay should handle reasonably slow cpus. it 1578 /* Take the isochronous scheduling threshold into account */
1442 * can also help high bandwidth if the dma and irq loads don't 1579 if (ehci->i_thresh)
1443 * jump until after the queue is primed. 1580 next = now + ehci->i_thresh; /* uframe cache */
1581 else
1582 next = (now + 2 + 7) & ~0x07; /* full frame cache */
1583
1584 /*
1585 * Use ehci->last_iso_frame as the base. There can't be any
1586 * TDs scheduled for earlier than that.
1444 */ 1587 */
1445 else { 1588 base = ehci->last_iso_frame << 3;
1446 int done = 0; 1589 next = (next - base) & (mod - 1);
1590 start = (stream->next_uframe - base) & (mod - 1);
1447 1591
1448 base = now & ~0x07; 1592 if (unlikely(new_stream))
1449 start = base + SCHEDULING_DELAY; 1593 goto do_ASAP;
1450 1594
1451 /* find a uframe slot with enough bandwidth. 1595 /*
1452 * Early uframes are more precious because full-speed 1596 * Typical case: reuse current schedule, stream may still be active.
1453 * iso IN transfers can't use late uframes, 1597 * Hopefully there are no gaps from the host falling behind
1454 * and therefore they should be allocated last. 1598 * (irq delays etc). If there are, the behavior depends on
1455 */ 1599 * whether URB_ISO_ASAP is set.
1456 next = start; 1600 */
1457 start += period; 1601 now2 = (now - base) & (mod - 1);
1458 do { 1602
1459 start--; 1603 /* Is the schedule already full? */
1460 /* check schedule: enough space? */ 1604 if (unlikely(!empty && start < period)) {
1461 if (stream->highspeed) { 1605 ehci_dbg(ehci, "iso sched full %p (%u-%u < %u mod %u)\n",
1462 if (itd_slot_ok(ehci, mod, start, 1606 urb, stream->next_uframe, base, period, mod);
1463 stream->usecs, period)) 1607 status = -ENOSPC;
1464 done = 1; 1608 goto fail;
1465 } else { 1609 }
1466 if ((start % 8) >= 6) 1610
1467 continue; 1611 /* Is the next packet scheduled after the base time? */
1468 if (sitd_slot_ok(ehci, mod, stream, 1612 if (likely(!empty || start <= now2 + period)) {
1469 start, sched, period)) 1613
1470 done = 1; 1614 /* URB_ISO_ASAP: make sure that start >= next */
1471 } 1615 if (unlikely(start < next &&
1472 } while (start > next && !done); 1616 (urb->transfer_flags & URB_ISO_ASAP)))
1617 goto do_ASAP;
1618
1619 /* Otherwise use start, if it's not in the past */
1620 if (likely(start >= now2))
1621 goto use_start;
1473 1622
1474 /* no room in the schedule */ 1623 /* Otherwise we got an underrun while the queue was empty */
1475 if (!done) { 1624 } else {
1476 ehci_dbg(ehci, "iso sched full %p", urb); 1625 if (urb->transfer_flags & URB_ISO_ASAP)
1477 status = -ENOSPC; 1626 goto do_ASAP;
1478 goto fail; 1627 wrap = mod;
1628 now2 += mod;
1629 }
1630
1631 /* How many uframes and packets do we need to skip? */
1632 skip = (now2 - start + period - 1) & -period;
1633 if (skip >= span) { /* Entirely in the past? */
1634 ehci_dbg(ehci, "iso underrun %p (%u+%u < %u) [%u]\n",
1635 urb, start + base, span - period, now2 + base,
1636 base);
1637
1638 /* Try to keep the last TD intact for scanning later */
1639 skip = span - period;
1640
1641 /* Will it come before the current scan position? */
1642 if (empty) {
1643 skip = span; /* Skip the entire URB */
1644 status = 1; /* and give it back immediately */
1645 iso_sched_free(stream, sched);
1646 sched = NULL;
1479 } 1647 }
1480 } 1648 }
1649 urb->error_count = skip / period;
1650 if (sched)
1651 sched->first_packet = urb->error_count;
1652 goto use_start;
1481 1653
1654 do_ASAP:
1655 /* Use the first slot after "next" */
1656 start = next + ((start - next) & (period - 1));
1657
1658 use_start:
1482 /* Tried to schedule too far into the future? */ 1659 /* Tried to schedule too far into the future? */
1483 if (unlikely(start - base + span - period >= mod)) { 1660 if (unlikely(start + span - period >= mod + wrap)) {
1484 ehci_dbg(ehci, "request %p would overflow (%u+%u >= %u)\n", 1661 ehci_dbg(ehci, "request %p would overflow (%u+%u >= %u)\n",
1485 urb, start - base, span - period, mod); 1662 urb, start, span - period, mod + wrap);
1486 status = -EFBIG; 1663 status = -EFBIG;
1487 goto fail; 1664 goto fail;
1488 } 1665 }
1489 1666
1490 stream->next_uframe = start & (mod - 1); 1667 start += base;
1668 stream->next_uframe = (start + skip) & (mod - 1);
1491 1669
1492 /* report high speed start in uframes; full speed, in frames */ 1670 /* report high speed start in uframes; full speed, in frames */
1493 urb->start_frame = stream->next_uframe; 1671 urb->start_frame = start & (mod - 1);
1494 if (!stream->highspeed) 1672 if (!stream->highspeed)
1495 urb->start_frame >>= 3; 1673 urb->start_frame >>= 3;
1496 1674
1497 /* Make sure scan_isoc() sees these */ 1675 /* Make sure scan_isoc() sees these */
1498 if (ehci->isoc_count == 0) 1676 if (ehci->isoc_count == 0)
1499 ehci->last_iso_frame = now >> 3; 1677 ehci->last_iso_frame = now >> 3;
1500 return 0; 1678 return status;
1501 1679
1502 fail: 1680 fail:
1503 iso_sched_free(stream, sched); 1681 iso_sched_free(stream, sched);
@@ -1610,7 +1788,8 @@ static void itd_link_urb(
1610 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 1788 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
1611 1789
1612 /* fill iTDs uframe by uframe */ 1790 /* fill iTDs uframe by uframe */
1613 for (packet = 0, itd = NULL; packet < urb->number_of_packets; ) { 1791 for (packet = iso_sched->first_packet, itd = NULL;
1792 packet < urb->number_of_packets;) {
1614 if (itd == NULL) { 1793 if (itd == NULL) {
1615 /* ASSERT: we have all necessary itds */ 1794 /* ASSERT: we have all necessary itds */
1616 // BUG_ON (list_empty (&iso_sched->td_list)); 1795 // BUG_ON (list_empty (&iso_sched->td_list));
@@ -1630,7 +1809,7 @@ static void itd_link_urb(
1630 1809
1631 itd_patch(ehci, itd, iso_sched, packet, uframe); 1810 itd_patch(ehci, itd, iso_sched, packet, uframe);
1632 1811
1633 next_uframe += stream->interval; 1812 next_uframe += stream->uperiod;
1634 next_uframe &= mod - 1; 1813 next_uframe &= mod - 1;
1635 packet++; 1814 packet++;
1636 1815
@@ -1770,9 +1949,9 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1770 ehci_dbg (ehci, "can't get iso stream\n"); 1949 ehci_dbg (ehci, "can't get iso stream\n");
1771 return -ENOMEM; 1950 return -ENOMEM;
1772 } 1951 }
1773 if (unlikely (urb->interval != stream->interval)) { 1952 if (unlikely(urb->interval != stream->uperiod)) {
1774 ehci_dbg (ehci, "can't change iso interval %d --> %d\n", 1953 ehci_dbg (ehci, "can't change iso interval %d --> %d\n",
1775 stream->interval, urb->interval); 1954 stream->uperiod, urb->interval);
1776 goto done; 1955 goto done;
1777 } 1956 }
1778 1957
@@ -1804,10 +1983,14 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1804 if (unlikely(status)) 1983 if (unlikely(status))
1805 goto done_not_linked; 1984 goto done_not_linked;
1806 status = iso_stream_schedule(ehci, urb, stream); 1985 status = iso_stream_schedule(ehci, urb, stream);
1807 if (likely (status == 0)) 1986 if (likely(status == 0)) {
1808 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 1987 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
1809 else 1988 } else if (status > 0) {
1989 status = 0;
1990 ehci_urb_done(ehci, urb, 0);
1991 } else {
1810 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); 1992 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
1993 }
1811 done_not_linked: 1994 done_not_linked:
1812 spin_unlock_irqrestore (&ehci->lock, flags); 1995 spin_unlock_irqrestore (&ehci->lock, flags);
1813 done: 1996 done:
@@ -1833,7 +2016,7 @@ sitd_sched_init(
1833 dma_addr_t dma = urb->transfer_dma; 2016 dma_addr_t dma = urb->transfer_dma;
1834 2017
1835 /* how many frames are needed for these transfers */ 2018 /* how many frames are needed for these transfers */
1836 iso_sched->span = urb->number_of_packets * stream->interval; 2019 iso_sched->span = urb->number_of_packets * stream->ps.period;
1837 2020
1838 /* figure out per-frame sitd fields that we'll need later 2021 /* figure out per-frame sitd fields that we'll need later
1839 * when we fit new sitds into the schedule. 2022 * when we fit new sitds into the schedule.
@@ -1925,7 +2108,7 @@ sitd_urb_transaction (
1925 2108
1926 memset (sitd, 0, sizeof *sitd); 2109 memset (sitd, 0, sizeof *sitd);
1927 sitd->sitd_dma = sitd_dma; 2110 sitd->sitd_dma = sitd_dma;
1928 sitd->frame = 9999; /* an invalid value */ 2111 sitd->frame = NO_FRAME;
1929 list_add (&sitd->sitd_list, &iso_sched->td_list); 2112 list_add (&sitd->sitd_list, &iso_sched->td_list);
1930 } 2113 }
1931 2114
@@ -2008,7 +2191,7 @@ static void sitd_link_urb(
2008 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 2191 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
2009 2192
2010 /* fill sITDs frame by frame */ 2193 /* fill sITDs frame by frame */
2011 for (packet = 0, sitd = NULL; 2194 for (packet = sched->first_packet, sitd = NULL;
2012 packet < urb->number_of_packets; 2195 packet < urb->number_of_packets;
2013 packet++) { 2196 packet++) {
2014 2197
@@ -2027,7 +2210,7 @@ static void sitd_link_urb(
2027 sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1), 2210 sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1),
2028 sitd); 2211 sitd);
2029 2212
2030 next_uframe += stream->interval << 3; 2213 next_uframe += stream->uperiod;
2031 } 2214 }
2032 stream->next_uframe = next_uframe & (mod - 1); 2215 stream->next_uframe = next_uframe & (mod - 1);
2033 2216
@@ -2146,9 +2329,9 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2146 ehci_dbg (ehci, "can't get iso stream\n"); 2329 ehci_dbg (ehci, "can't get iso stream\n");
2147 return -ENOMEM; 2330 return -ENOMEM;
2148 } 2331 }
2149 if (urb->interval != stream->interval) { 2332 if (urb->interval != stream->ps.period) {
2150 ehci_dbg (ehci, "can't change iso interval %d --> %d\n", 2333 ehci_dbg (ehci, "can't change iso interval %d --> %d\n",
2151 stream->interval, urb->interval); 2334 stream->ps.period, urb->interval);
2152 goto done; 2335 goto done;
2153 } 2336 }
2154 2337
@@ -2178,10 +2361,14 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2178 if (unlikely(status)) 2361 if (unlikely(status))
2179 goto done_not_linked; 2362 goto done_not_linked;
2180 status = iso_stream_schedule(ehci, urb, stream); 2363 status = iso_stream_schedule(ehci, urb, stream);
2181 if (status == 0) 2364 if (likely(status == 0)) {
2182 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 2365 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
2183 else 2366 } else if (status > 0) {
2367 status = 0;
2368 ehci_urb_done(ehci, urb, 0);
2369 } else {
2184 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); 2370 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
2371 }
2185 done_not_linked: 2372 done_not_linked:
2186 spin_unlock_irqrestore (&ehci->lock, flags); 2373 spin_unlock_irqrestore (&ehci->lock, flags);
2187 done: 2374 done:
@@ -2259,7 +2446,8 @@ restart:
2259 q.itd->hw_next != EHCI_LIST_END(ehci)) 2446 q.itd->hw_next != EHCI_LIST_END(ehci))
2260 *hw_p = q.itd->hw_next; 2447 *hw_p = q.itd->hw_next;
2261 else 2448 else
2262 *hw_p = ehci->dummy->qh_dma; 2449 *hw_p = cpu_to_hc32(ehci,
2450 ehci->dummy->qh_dma);
2263 type = Q_NEXT_TYPE(ehci, q.itd->hw_next); 2451 type = Q_NEXT_TYPE(ehci, q.itd->hw_next);
2264 wmb(); 2452 wmb();
2265 modified = itd_complete (ehci, q.itd); 2453 modified = itd_complete (ehci, q.itd);
@@ -2294,7 +2482,8 @@ restart:
2294 q.sitd->hw_next != EHCI_LIST_END(ehci)) 2482 q.sitd->hw_next != EHCI_LIST_END(ehci))
2295 *hw_p = q.sitd->hw_next; 2483 *hw_p = q.sitd->hw_next;
2296 else 2484 else
2297 *hw_p = ehci->dummy->qh_dma; 2485 *hw_p = cpu_to_hc32(ehci,
2486 ehci->dummy->qh_dma);
2298 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); 2487 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
2299 wmb(); 2488 wmb();
2300 modified = sitd_complete (ehci, q.sitd); 2489 modified = sitd_complete (ehci, q.sitd);
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c
index 1cf0adba3fc8..ee6f9ffaa0e7 100644
--- a/drivers/usb/host/ehci-spear.c
+++ b/drivers/usb/host/ehci-spear.c
@@ -81,10 +81,9 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
81 * Since shared usb code relies on it, set it here for now. 81 * Since shared usb code relies on it, set it here for now.
82 * Once we have dma capability bindings this can go away. 82 * Once we have dma capability bindings this can go away.
83 */ 83 */
84 if (!pdev->dev.dma_mask) 84 retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
85 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 85 if (retval)
86 if (!pdev->dev.coherent_dma_mask) 86 goto fail;
87 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
88 87
89 usbh_clk = devm_clk_get(&pdev->dev, NULL); 88 usbh_clk = devm_clk_get(&pdev->dev, NULL);
90 if (IS_ERR(usbh_clk)) { 89 if (IS_ERR(usbh_clk)) {
diff --git a/drivers/usb/host/ehci-sysfs.c b/drivers/usb/host/ehci-sysfs.c
index 14ced00ba220..f6459dfb6f54 100644
--- a/drivers/usb/host/ehci-sysfs.c
+++ b/drivers/usb/host/ehci-sysfs.c
@@ -97,8 +97,7 @@ static ssize_t store_uframe_periodic_max(struct device *dev,
97{ 97{
98 struct ehci_hcd *ehci; 98 struct ehci_hcd *ehci;
99 unsigned uframe_periodic_max; 99 unsigned uframe_periodic_max;
100 unsigned frame, uframe; 100 unsigned uframe;
101 unsigned short allocated_max;
102 unsigned long flags; 101 unsigned long flags;
103 ssize_t ret; 102 ssize_t ret;
104 103
@@ -122,16 +121,14 @@ static ssize_t store_uframe_periodic_max(struct device *dev,
122 121
123 /* 122 /*
124 * for request to decrease max periodic bandwidth, we have to check 123 * for request to decrease max periodic bandwidth, we have to check
125 * every microframe in the schedule to see whether the decrease is 124 * to see whether the decrease is possible.
126 * possible.
127 */ 125 */
128 if (uframe_periodic_max < ehci->uframe_periodic_max) { 126 if (uframe_periodic_max < ehci->uframe_periodic_max) {
129 allocated_max = 0; 127 u8 allocated_max = 0;
130 128
131 for (frame = 0; frame < ehci->periodic_size; ++frame) 129 for (uframe = 0; uframe < EHCI_BANDWIDTH_SIZE; ++uframe)
132 for (uframe = 0; uframe < 7; ++uframe) 130 allocated_max = max(allocated_max,
133 allocated_max = max(allocated_max, 131 ehci->bandwidth[uframe]);
134 periodic_usecs (ehci, frame, uframe));
135 132
136 if (allocated_max > uframe_periodic_max) { 133 if (allocated_max > uframe_periodic_max) {
137 ehci_info(ehci, 134 ehci_info(ehci,
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 78fa76da3324..b9fd0396011e 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -362,10 +362,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
362 * 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.
363 * Once we have dma capability bindings this can go away. 363 * Once we have dma capability bindings this can go away.
364 */ 364 */
365 if (!pdev->dev.dma_mask) 365 err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
366 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 366 if (err)
367 if (!pdev->dev.coherent_dma_mask) 367 return err;
368 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
369 368
370 hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev, 369 hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev,
371 dev_name(&pdev->dev)); 370 dev_name(&pdev->dev));
@@ -388,7 +387,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
388 387
389 err = clk_prepare_enable(tegra->clk); 388 err = clk_prepare_enable(tegra->clk);
390 if (err) 389 if (err)
391 goto cleanup_clk_get; 390 goto cleanup_hcd_create;
392 391
393 tegra_periph_reset_assert(tegra->clk); 392 tegra_periph_reset_assert(tegra->clk);
394 udelay(1); 393 udelay(1);
@@ -465,8 +464,6 @@ cleanup_phy:
465 usb_phy_shutdown(hcd->phy); 464 usb_phy_shutdown(hcd->phy);
466cleanup_clk_en: 465cleanup_clk_en:
467 clk_disable_unprepare(tegra->clk); 466 clk_disable_unprepare(tegra->clk);
468cleanup_clk_get:
469 clk_put(tegra->clk);
470cleanup_hcd_create: 467cleanup_hcd_create:
471 usb_put_hcd(hcd); 468 usb_put_hcd(hcd);
472 return err; 469 return err;
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c
index 1c370dfbee0d..cdad8438c02b 100644
--- a/drivers/usb/host/ehci-w90x900.c
+++ b/drivers/usb/host/ehci-w90x900.c
@@ -11,13 +11,28 @@
11 * 11 *
12 */ 12 */
13 13
14#include <linux/dma-mapping.h>
15#include <linux/io.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/of.h>
14#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/usb.h>
21#include <linux/usb/hcd.h>
22
23#include "ehci.h"
15 24
16/* enable phy0 and phy1 for w90p910 */ 25/* enable phy0 and phy1 for w90p910 */
17#define ENPHY (0x01<<8) 26#define ENPHY (0x01<<8)
18#define PHY0_CTR (0xA4) 27#define PHY0_CTR (0xA4)
19#define PHY1_CTR (0xA8) 28#define PHY1_CTR (0xA8)
20 29
30#define DRIVER_DESC "EHCI w90x900 driver"
31
32static const char hcd_name[] = "ehci-w90x900 ";
33
34static struct hc_driver __read_mostly ehci_w90x900_hc_driver;
35
21static int usb_w90x900_probe(const struct hc_driver *driver, 36static int usb_w90x900_probe(const struct hc_driver *driver,
22 struct platform_device *pdev) 37 struct platform_device *pdev)
23{ 38{
@@ -90,8 +105,8 @@ err1:
90 return retval; 105 return retval;
91} 106}
92 107
93static 108static void usb_w90x900_remove(struct usb_hcd *hcd,
94void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev) 109 struct platform_device *pdev)
95{ 110{
96 usb_remove_hcd(hcd); 111 usb_remove_hcd(hcd);
97 iounmap(hcd->regs); 112 iounmap(hcd->regs);
@@ -99,54 +114,6 @@ void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev)
99 usb_put_hcd(hcd); 114 usb_put_hcd(hcd);
100} 115}
101 116
102static const struct hc_driver ehci_w90x900_hc_driver = {
103 .description = hcd_name,
104 .product_desc = "Nuvoton w90x900 EHCI Host Controller",
105 .hcd_priv_size = sizeof(struct ehci_hcd),
106
107 /*
108 * generic hardware linkage
109 */
110 .irq = ehci_irq,
111 .flags = HCD_USB2|HCD_MEMORY|HCD_BH,
112
113 /*
114 * basic lifecycle operations
115 */
116 .reset = ehci_setup,
117 .start = ehci_run,
118
119 .stop = ehci_stop,
120 .shutdown = ehci_shutdown,
121
122 /*
123 * managing i/o requests and associated device resources
124 */
125 .urb_enqueue = ehci_urb_enqueue,
126 .urb_dequeue = ehci_urb_dequeue,
127 .endpoint_disable = ehci_endpoint_disable,
128 .endpoint_reset = ehci_endpoint_reset,
129
130 /*
131 * scheduling support
132 */
133 .get_frame_number = ehci_get_frame,
134
135 /*
136 * root hub support
137 */
138 .hub_status_data = ehci_hub_status_data,
139 .hub_control = ehci_hub_control,
140#ifdef CONFIG_PM
141 .bus_suspend = ehci_bus_suspend,
142 .bus_resume = ehci_bus_resume,
143#endif
144 .relinquish_port = ehci_relinquish_port,
145 .port_handed_over = ehci_port_handed_over,
146
147 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
148};
149
150static int ehci_w90x900_probe(struct platform_device *pdev) 117static int ehci_w90x900_probe(struct platform_device *pdev)
151{ 118{
152 if (usb_disabled()) 119 if (usb_disabled())
@@ -173,7 +140,25 @@ static struct platform_driver ehci_hcd_w90x900_driver = {
173 }, 140 },
174}; 141};
175 142
143static int __init ehci_w90X900_init(void)
144{
145 if (usb_disabled())
146 return -ENODEV;
147
148 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
149
150 ehci_init_driver(&ehci_w90x900_hc_driver, NULL);
151 return platform_driver_register(&ehci_hcd_w90x900_driver);
152}
153module_init(ehci_w90X900_init);
154
155static void __exit ehci_w90X900_cleanup(void)
156{
157 platform_driver_unregister(&ehci_hcd_w90x900_driver);
158}
159module_exit(ehci_w90X900_cleanup);
160
161MODULE_DESCRIPTION(DRIVER_DESC);
176MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); 162MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
177MODULE_DESCRIPTION("w90p910 usb ehci driver!");
178MODULE_LICENSE("GPL");
179MODULE_ALIAS("platform:w90p910-ehci"); 163MODULE_ALIAS("platform:w90p910-ehci");
164MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 291db7d09f22..e8f41c5e771b 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -54,6 +54,28 @@ struct ehci_stats {
54 unsigned long unlink; 54 unsigned long unlink;
55}; 55};
56 56
57/*
58 * Scheduling and budgeting information for periodic transfers, for both
59 * high-speed devices and full/low-speed devices lying behind a TT.
60 */
61struct ehci_per_sched {
62 struct usb_device *udev; /* access to the TT */
63 struct usb_host_endpoint *ep;
64 struct list_head ps_list; /* node on ehci_tt's ps_list */
65 u16 tt_usecs; /* time on the FS/LS bus */
66 u16 cs_mask; /* C-mask and S-mask bytes */
67 u16 period; /* actual period in frames */
68 u16 phase; /* actual phase, frame part */
69 u8 bw_phase; /* same, for bandwidth
70 reservation */
71 u8 phase_uf; /* uframe part of the phase */
72 u8 usecs, c_usecs; /* times on the HS bus */
73 u8 bw_uperiod; /* period in microframes, for
74 bandwidth reservation */
75 u8 bw_period; /* same, in frames */
76};
77#define NO_FRAME 29999 /* frame not assigned yet */
78
57/* ehci_hcd->lock guards shared data against other CPUs: 79/* ehci_hcd->lock guards shared data against other CPUs:
58 * ehci_hcd: async, unlink, periodic (and shadow), ... 80 * ehci_hcd: async, unlink, periodic (and shadow), ...
59 * usb_host_endpoint: hcpriv 81 * usb_host_endpoint: hcpriv
@@ -230,6 +252,15 @@ struct ehci_hcd { /* one per controller */
230 struct dentry *debug_dir; 252 struct dentry *debug_dir;
231#endif 253#endif
232 254
255 /* bandwidth usage */
256#define EHCI_BANDWIDTH_SIZE 64
257#define EHCI_BANDWIDTH_FRAMES (EHCI_BANDWIDTH_SIZE >> 3)
258 u8 bandwidth[EHCI_BANDWIDTH_SIZE];
259 /* us allocated per uframe */
260 u8 tt_budget[EHCI_BANDWIDTH_SIZE];
261 /* us budgeted per uframe */
262 struct list_head tt_list;
263
233 /* platform-specific data -- must come last */ 264 /* platform-specific data -- must come last */
234 unsigned long priv[0] __aligned(sizeof(s64)); 265 unsigned long priv[0] __aligned(sizeof(s64));
235}; 266};
@@ -385,6 +416,7 @@ struct ehci_qh {
385 struct list_head intr_node; /* list of intr QHs */ 416 struct list_head intr_node; /* list of intr QHs */
386 struct ehci_qtd *dummy; 417 struct ehci_qtd *dummy;
387 struct list_head unlink_node; 418 struct list_head unlink_node;
419 struct ehci_per_sched ps; /* scheduling info */
388 420
389 unsigned unlink_cycle; 421 unsigned unlink_cycle;
390 422
@@ -398,16 +430,8 @@ struct ehci_qh {
398 u8 xacterrs; /* XactErr retry counter */ 430 u8 xacterrs; /* XactErr retry counter */
399#define QH_XACTERR_MAX 32 /* XactErr retry limit */ 431#define QH_XACTERR_MAX 32 /* XactErr retry limit */
400 432
401 /* periodic schedule info */
402 u8 usecs; /* intr bandwidth */
403 u8 gap_uf; /* uframes split/csplit gap */ 433 u8 gap_uf; /* uframes split/csplit gap */
404 u8 c_usecs; /* ... split completion bw */
405 u16 tt_usecs; /* tt downstream bandwidth */
406 unsigned short period; /* polling interval */
407 unsigned short start; /* where polling starts */
408#define NO_FRAME ((unsigned short)~0) /* pick new start */
409 434
410 struct usb_device *dev; /* access to TT */
411 unsigned is_out:1; /* bulk or intr OUT */ 435 unsigned is_out:1; /* bulk or intr OUT */
412 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ 436 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
413 unsigned dequeue_during_giveback:1; 437 unsigned dequeue_during_giveback:1;
@@ -434,6 +458,7 @@ struct ehci_iso_packet {
434struct ehci_iso_sched { 458struct ehci_iso_sched {
435 struct list_head td_list; 459 struct list_head td_list;
436 unsigned span; 460 unsigned span;
461 unsigned first_packet;
437 struct ehci_iso_packet packet [0]; 462 struct ehci_iso_packet packet [0];
438}; 463};
439 464
@@ -449,22 +474,17 @@ struct ehci_iso_stream {
449 u8 highspeed; 474 u8 highspeed;
450 struct list_head td_list; /* queued itds/sitds */ 475 struct list_head td_list; /* queued itds/sitds */
451 struct list_head free_list; /* list of unused itds/sitds */ 476 struct list_head free_list; /* list of unused itds/sitds */
452 struct usb_device *udev;
453 struct usb_host_endpoint *ep;
454 477
455 /* output of (re)scheduling */ 478 /* output of (re)scheduling */
456 int next_uframe; 479 struct ehci_per_sched ps; /* scheduling info */
480 unsigned next_uframe;
457 __hc32 splits; 481 __hc32 splits;
458 482
459 /* the rest is derived from the endpoint descriptor, 483 /* the rest is derived from the endpoint descriptor,
460 * trusting urb->interval == f(epdesc->bInterval) and
461 * including the extra info for hw_bufp[0..2] 484 * including the extra info for hw_bufp[0..2]
462 */ 485 */
463 u8 usecs, c_usecs; 486 u16 uperiod; /* period in uframes */
464 u16 interval;
465 u16 tt_usecs;
466 u16 maxp; 487 u16 maxp;
467 u16 raw_mask;
468 unsigned bandwidth; 488 unsigned bandwidth;
469 489
470 /* This is used to initialize iTD's hw_bufp fields */ 490 /* This is used to initialize iTD's hw_bufp fields */
@@ -579,6 +599,35 @@ struct ehci_fstn {
579 599
580/*-------------------------------------------------------------------------*/ 600/*-------------------------------------------------------------------------*/
581 601
602/*
603 * USB-2.0 Specification Sections 11.14 and 11.18
604 * Scheduling and budgeting split transactions using TTs
605 *
606 * A hub can have a single TT for all its ports, or multiple TTs (one for each
607 * port). The bandwidth and budgeting information for the full/low-speed bus
608 * below each TT is self-contained and independent of the other TTs or the
609 * high-speed bus.
610 *
611 * "Bandwidth" refers to the number of microseconds on the FS/LS bus allocated
612 * to an interrupt or isochronous endpoint for each frame. "Budget" refers to
613 * the best-case estimate of the number of full-speed bytes allocated to an
614 * endpoint for each microframe within an allocated frame.
615 *
616 * Removal of an endpoint invalidates a TT's budget. Instead of trying to
617 * keep an up-to-date record, we recompute the budget when it is needed.
618 */
619
620struct ehci_tt {
621 u16 bandwidth[EHCI_BANDWIDTH_FRAMES];
622
623 struct list_head tt_list; /* List of all ehci_tt's */
624 struct list_head ps_list; /* Items using this TT */
625 struct usb_tt *usb_tt;
626 int tt_port; /* TT port number */
627};
628
629/*-------------------------------------------------------------------------*/
630
582/* Prepare the PORTSC wakeup flags during controller suspend/resume */ 631/* Prepare the PORTSC wakeup flags during controller suspend/resume */
583 632
584#define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \ 633#define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index 0b46542591ff..0551c0af0fd1 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -26,6 +26,8 @@
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/usb/hcd.h> 28#include <linux/usb/hcd.h>
29#include <linux/of_address.h>
30#include <linux/of_irq.h>
29#include <linux/of_platform.h> 31#include <linux/of_platform.h>
30#include <linux/of_gpio.h> 32#include <linux/of_gpio.h>
31#include <linux/slab.h> 33#include <linux/slab.h>
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
index fce13bcc4a3e..55486bd23cf1 100644
--- a/drivers/usb/host/fotg210-hcd.c
+++ b/drivers/usb/host/fotg210-hcd.c
@@ -412,7 +412,7 @@ struct debug_buffer {
412 tmp = 'h'; break; \ 412 tmp = 'h'; break; \
413 default: \ 413 default: \
414 tmp = '?'; break; \ 414 tmp = '?'; break; \
415 }; tmp; }) 415 } tmp; })
416 416
417static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token) 417static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token)
418{ 418{
diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
index cfbff7161828..abd5050a4899 100644
--- a/drivers/usb/host/fsl-mph-dr-of.c
+++ b/drivers/usb/host/fsl-mph-dr-of.c
@@ -24,7 +24,7 @@ struct fsl_usb2_dev_data {
24 enum fsl_usb2_operating_modes op_mode; /* operating mode */ 24 enum fsl_usb2_operating_modes op_mode; /* operating mode */
25}; 25};
26 26
27struct fsl_usb2_dev_data dr_mode_data[] = { 27static struct fsl_usb2_dev_data dr_mode_data[] = {
28 { 28 {
29 .dr_mode = "host", 29 .dr_mode = "host",
30 .drivers = { "fsl-ehci", NULL, NULL, }, 30 .drivers = { "fsl-ehci", NULL, NULL, },
@@ -42,7 +42,7 @@ struct fsl_usb2_dev_data dr_mode_data[] = {
42 }, 42 },
43}; 43};
44 44
45struct fsl_usb2_dev_data *get_dr_mode_data(struct device_node *np) 45static struct fsl_usb2_dev_data *get_dr_mode_data(struct device_node *np)
46{ 46{
47 const unsigned char *prop; 47 const unsigned char *prop;
48 int i; 48 int i;
@@ -75,7 +75,7 @@ static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
75 return FSL_USB2_PHY_NONE; 75 return FSL_USB2_PHY_NONE;
76} 76}
77 77
78struct platform_device *fsl_usb2_device_register( 78static struct platform_device *fsl_usb2_device_register(
79 struct platform_device *ofdev, 79 struct platform_device *ofdev,
80 struct fsl_usb2_platform_data *pdata, 80 struct fsl_usb2_platform_data *pdata,
81 const char *name, int id) 81 const char *name, int id)
@@ -260,6 +260,7 @@ int fsl_usb2_mpc5121_init(struct platform_device *pdev)
260{ 260{
261 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev); 261 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
262 struct clk *clk; 262 struct clk *clk;
263 int err;
263 char clk_name[10]; 264 char clk_name[10];
264 int base, clk_num; 265 int base, clk_num;
265 266
@@ -272,13 +273,16 @@ int fsl_usb2_mpc5121_init(struct platform_device *pdev)
272 return -ENODEV; 273 return -ENODEV;
273 274
274 snprintf(clk_name, sizeof(clk_name), "usb%d_clk", clk_num); 275 snprintf(clk_name, sizeof(clk_name), "usb%d_clk", clk_num);
275 clk = clk_get(&pdev->dev, clk_name); 276 clk = devm_clk_get(pdev->dev.parent, clk_name);
276 if (IS_ERR(clk)) { 277 if (IS_ERR(clk)) {
277 dev_err(&pdev->dev, "failed to get clk\n"); 278 dev_err(&pdev->dev, "failed to get clk\n");
278 return PTR_ERR(clk); 279 return PTR_ERR(clk);
279 } 280 }
280 281 err = clk_prepare_enable(clk);
281 clk_enable(clk); 282 if (err) {
283 dev_err(&pdev->dev, "failed to enable clk\n");
284 return err;
285 }
282 pdata->clk = clk; 286 pdata->clk = clk;
283 287
284 if (pdata->phy_mode == FSL_USB2_PHY_UTMI_WIDE) { 288 if (pdata->phy_mode == FSL_USB2_PHY_UTMI_WIDE) {
@@ -302,10 +306,8 @@ static void fsl_usb2_mpc5121_exit(struct platform_device *pdev)
302 306
303 pdata->regs = NULL; 307 pdata->regs = NULL;
304 308
305 if (pdata->clk) { 309 if (pdata->clk)
306 clk_disable(pdata->clk); 310 clk_disable_unprepare(pdata->clk);
307 clk_put(pdata->clk);
308 }
309} 311}
310 312
311static struct fsl_usb2_platform_data fsl_usb2_mpc5121_pd = { 313static struct fsl_usb2_platform_data fsl_usb2_mpc5121_pd = {
diff --git a/drivers/usb/host/fusbh200-hcd.c b/drivers/usb/host/fusbh200-hcd.c
index 299253c826c7..e1c6d850a7e1 100644
--- a/drivers/usb/host/fusbh200-hcd.c
+++ b/drivers/usb/host/fusbh200-hcd.c
@@ -402,7 +402,7 @@ struct debug_buffer {
402 case QH_LOW_SPEED: tmp = 'l'; break; \ 402 case QH_LOW_SPEED: tmp = 'l'; break; \
403 case QH_HIGH_SPEED: tmp = 'h'; break; \ 403 case QH_HIGH_SPEED: tmp = 'h'; break; \
404 default: tmp = '?'; break; \ 404 default: tmp = '?'; break; \
405 }; tmp; }) 405 } tmp; })
406 406
407static inline char token_mark(struct fusbh200_hcd *fusbh200, __hc32 token) 407static inline char token_mark(struct fusbh200_hcd *fusbh200, __hc32 token)
408{ 408{
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index 5b86ffb88f1c..ada0a52797b1 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -199,10 +199,14 @@ static int hwahc_op_get_frame_number(struct usb_hcd *usb_hcd)
199{ 199{
200 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); 200 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
201 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); 201 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
202 struct wahc *wa = &hwahc->wa;
202 203
203 dev_err(wusbhc->dev, "%s (%p [%p]) UNIMPLEMENTED\n", __func__, 204 /*
204 usb_hcd, hwahc); 205 * We cannot query the HWA for the WUSB time since that requires sending
205 return -ENOSYS; 206 * a synchronous URB and this function can be called in_interrupt.
207 * Instead, query the USB frame number for our parent and use that.
208 */
209 return usb_get_current_frame_number(wa->usb_dev);
206} 210}
207 211
208static int hwahc_op_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb, 212static int hwahc_op_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb,
@@ -566,14 +570,10 @@ found:
566 goto error; 570 goto error;
567 } 571 }
568 wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr; 572 wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr;
569 /* Make LE fields CPU order */ 573 if (le16_to_cpu(wa_descr->bcdWAVersion) > 0x0100)
570 wa_descr->bcdWAVersion = le16_to_cpu(wa_descr->bcdWAVersion);
571 wa_descr->wNumRPipes = le16_to_cpu(wa_descr->wNumRPipes);
572 wa_descr->wRPipeMaxBlock = le16_to_cpu(wa_descr->wRPipeMaxBlock);
573 if (wa_descr->bcdWAVersion > 0x0100)
574 dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n", 574 dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n",
575 wa_descr->bcdWAVersion & 0xff00 >> 8, 575 le16_to_cpu(wa_descr->bcdWAVersion) & 0xff00 >> 8,
576 wa_descr->bcdWAVersion & 0x00ff); 576 le16_to_cpu(wa_descr->bcdWAVersion) & 0x00ff);
577 result = 0; 577 result = 0;
578error: 578error:
579 return result; 579 return result;
@@ -679,7 +679,8 @@ static void hwahc_security_release(struct hwahc *hwahc)
679 /* nothing to do here so far... */ 679 /* nothing to do here so far... */
680} 680}
681 681
682static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface) 682static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface,
683 kernel_ulong_t quirks)
683{ 684{
684 int result; 685 int result;
685 struct device *dev = &iface->dev; 686 struct device *dev = &iface->dev;
@@ -724,7 +725,7 @@ static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface)
724 dev_err(dev, "Can't create WUSB HC structures: %d\n", result); 725 dev_err(dev, "Can't create WUSB HC structures: %d\n", result);
725 goto error_wusbhc_create; 726 goto error_wusbhc_create;
726 } 727 }
727 result = wa_create(&hwahc->wa, iface); 728 result = wa_create(&hwahc->wa, iface, quirks);
728 if (result < 0) 729 if (result < 0)
729 goto error_wa_create; 730 goto error_wa_create;
730 return 0; 731 return 0;
@@ -780,7 +781,7 @@ static int hwahc_probe(struct usb_interface *usb_iface,
780 wusbhc = usb_hcd_to_wusbhc(usb_hcd); 781 wusbhc = usb_hcd_to_wusbhc(usb_hcd);
781 hwahc = container_of(wusbhc, struct hwahc, wusbhc); 782 hwahc = container_of(wusbhc, struct hwahc, wusbhc);
782 hwahc_init(hwahc); 783 hwahc_init(hwahc);
783 result = hwahc_create(hwahc, usb_iface); 784 result = hwahc_create(hwahc, usb_iface, id->driver_info);
784 if (result < 0) { 785 if (result < 0) {
785 dev_err(dev, "Cannot initialize internals: %d\n", result); 786 dev_err(dev, "Cannot initialize internals: %d\n", result);
786 goto error_hwahc_create; 787 goto error_hwahc_create;
@@ -824,6 +825,12 @@ static void hwahc_disconnect(struct usb_interface *usb_iface)
824} 825}
825 826
826static struct usb_device_id hwahc_id_table[] = { 827static struct usb_device_id hwahc_id_table[] = {
828 /* Alereon 5310 */
829 { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5310, 0xe0, 0x02, 0x01),
830 .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC },
831 /* Alereon 5611 */
832 { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5611, 0xe0, 0x02, 0x01),
833 .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC },
827 /* FIXME: use class labels for this */ 834 /* FIXME: use class labels for this */
828 { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), }, 835 { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), },
829 {}, 836 {},
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index 60a5de505ca1..adb01d950a16 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -824,13 +824,13 @@ static int imx21_hc_urb_enqueue_isoc(struct usb_hcd *hcd,
824 i = DIV_ROUND_UP(wrap_frame( 824 i = DIV_ROUND_UP(wrap_frame(
825 cur_frame - urb->start_frame), 825 cur_frame - urb->start_frame),
826 urb->interval); 826 urb->interval);
827 if (urb->transfer_flags & URB_ISO_ASAP) { 827
828 /* Treat underruns as if URB_ISO_ASAP was set */
829 if ((urb->transfer_flags & URB_ISO_ASAP) ||
830 i >= urb->number_of_packets) {
828 urb->start_frame = wrap_frame(urb->start_frame 831 urb->start_frame = wrap_frame(urb->start_frame
829 + i * urb->interval); 832 + i * urb->interval);
830 i = 0; 833 i = 0;
831 } else if (i >= urb->number_of_packets) {
832 ret = -EXDEV;
833 goto alloc_dmem_failed;
834 } 834 }
835 } 835 }
836 } 836 }
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index 6f29abad6815..935a2dd367a8 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -2108,7 +2108,7 @@ static int isp1362_show(struct seq_file *s, void *unused)
2108 default: 2108 default:
2109 s = "?"; 2109 s = "?";
2110 break; 2110 break;
2111 }; 2111 }
2112 s;}), ep->maxpacket) ; 2112 s;}), ep->maxpacket) ;
2113 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) { 2113 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
2114 seq_printf(s, " urb%p, %d/%d\n", urb, 2114 seq_printf(s, " urb%p, %d/%d\n", urb,
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index caa3764a3407..418444ebb1b8 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -13,19 +13,24 @@
13 */ 13 */
14 14
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/platform_device.h> 16#include <linux/dma-mapping.h>
17#include <linux/of_platform.h> 17#include <linux/of_platform.h>
18#include <linux/of_gpio.h> 18#include <linux/of_gpio.h>
19#include <linux/platform_device.h>
19#include <linux/platform_data/atmel.h> 20#include <linux/platform_data/atmel.h>
21#include <linux/io.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/usb.h>
25#include <linux/usb/hcd.h>
20 26
21#include <mach/hardware.h> 27#include <mach/hardware.h>
22#include <asm/gpio.h> 28#include <asm/gpio.h>
23 29
24#include <mach/cpu.h> 30#include <mach/cpu.h>
25 31
26#ifndef CONFIG_ARCH_AT91 32
27#error "CONFIG_ARCH_AT91 must be defined." 33#include "ohci.h"
28#endif
29 34
30#define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS) 35#define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS)
31#define at91_for_each_port(index) \ 36#define at91_for_each_port(index) \
@@ -33,7 +38,17 @@
33 38
34/* interface, function and usb clocks; sometimes also an AHB clock */ 39/* interface, function and usb clocks; sometimes also an AHB clock */
35static struct clk *iclk, *fclk, *uclk, *hclk; 40static struct clk *iclk, *fclk, *uclk, *hclk;
41/* interface and function clocks; sometimes also an AHB clock */
42
43#define DRIVER_DESC "OHCI Atmel driver"
44
45static const char hcd_name[] = "ohci-atmel";
46
47static struct hc_driver __read_mostly ohci_at91_hc_driver;
36static int clocked; 48static int clocked;
49static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq,
50 u16 wValue, u16 wIndex, char *buf, u16 wLength);
51static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
37 52
38extern int usb_disabled(void); 53extern int usb_disabled(void);
39 54
@@ -117,6 +132,8 @@ static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
117static int usb_hcd_at91_probe(const struct hc_driver *driver, 132static int usb_hcd_at91_probe(const struct hc_driver *driver,
118 struct platform_device *pdev) 133 struct platform_device *pdev)
119{ 134{
135 struct at91_usbh_data *board;
136 struct ohci_hcd *ohci;
120 int retval; 137 int retval;
121 struct usb_hcd *hcd = NULL; 138 struct usb_hcd *hcd = NULL;
122 139
@@ -177,8 +194,10 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
177 } 194 }
178 } 195 }
179 196
197 board = hcd->self.controller->platform_data;
198 ohci = hcd_to_ohci(hcd);
199 ohci->num_ports = board->ports;
180 at91_start_hc(pdev); 200 at91_start_hc(pdev);
181 ohci_hcd_init(hcd_to_ohci(hcd));
182 201
183 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); 202 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
184 if (retval == 0) 203 if (retval == 0)
@@ -238,36 +257,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
238} 257}
239 258
240/*-------------------------------------------------------------------------*/ 259/*-------------------------------------------------------------------------*/
241
242static int
243ohci_at91_reset (struct usb_hcd *hcd)
244{
245 struct at91_usbh_data *board = dev_get_platdata(hcd->self.controller);
246 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
247 int ret;
248
249 if ((ret = ohci_init(ohci)) < 0)
250 return ret;
251
252 ohci->num_ports = board->ports;
253 return 0;
254}
255
256static int
257ohci_at91_start (struct usb_hcd *hcd)
258{
259 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
260 int ret;
261
262 if ((ret = ohci_run(ohci)) < 0) {
263 dev_err(hcd->self.controller, "can't start %s\n",
264 hcd->self.bus_name);
265 ohci_stop(hcd);
266 return ret;
267 }
268 return 0;
269}
270
271static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) 260static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
272{ 261{
273 if (!valid_port(port)) 262 if (!valid_port(port))
@@ -297,8 +286,8 @@ static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
297 */ 286 */
298static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) 287static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
299{ 288{
300 struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller); 289 struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
301 int length = ohci_hub_status_data(hcd, buf); 290 int length = orig_ohci_hub_status_data(hcd, buf);
302 int port; 291 int port;
303 292
304 at91_for_each_port(port) { 293 at91_for_each_port(port) {
@@ -376,7 +365,8 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
376 break; 365 break;
377 } 366 }
378 367
379 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength); 368 ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex + 1,
369 buf, wLength);
380 if (ret) 370 if (ret)
381 goto out; 371 goto out;
382 372
@@ -430,51 +420,6 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
430 420
431/*-------------------------------------------------------------------------*/ 421/*-------------------------------------------------------------------------*/
432 422
433static const struct hc_driver ohci_at91_hc_driver = {
434 .description = hcd_name,
435 .product_desc = "AT91 OHCI",
436 .hcd_priv_size = sizeof(struct ohci_hcd),
437
438 /*
439 * generic hardware linkage
440 */
441 .irq = ohci_irq,
442 .flags = HCD_USB11 | HCD_MEMORY,
443
444 /*
445 * basic lifecycle operations
446 */
447 .reset = ohci_at91_reset,
448 .start = ohci_at91_start,
449 .stop = ohci_stop,
450 .shutdown = ohci_shutdown,
451
452 /*
453 * managing i/o requests and associated device resources
454 */
455 .urb_enqueue = ohci_urb_enqueue,
456 .urb_dequeue = ohci_urb_dequeue,
457 .endpoint_disable = ohci_endpoint_disable,
458
459 /*
460 * scheduling support
461 */
462 .get_frame_number = ohci_get_frame,
463
464 /*
465 * root hub support
466 */
467 .hub_status_data = ohci_at91_hub_status_data,
468 .hub_control = ohci_at91_hub_control,
469#ifdef CONFIG_PM
470 .bus_suspend = ohci_bus_suspend,
471 .bus_resume = ohci_bus_resume,
472#endif
473 .start_port_reset = ohci_start_port_reset,
474};
475
476/*-------------------------------------------------------------------------*/
477
478static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) 423static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
479{ 424{
480 struct platform_device *pdev = data; 425 struct platform_device *pdev = data;
@@ -524,7 +469,7 @@ MODULE_DEVICE_TABLE(of, at91_ohci_dt_ids);
524static int ohci_at91_of_init(struct platform_device *pdev) 469static int ohci_at91_of_init(struct platform_device *pdev)
525{ 470{
526 struct device_node *np = pdev->dev.of_node; 471 struct device_node *np = pdev->dev.of_node;
527 int i, gpio; 472 int i, gpio, ret;
528 enum of_gpio_flags flags; 473 enum of_gpio_flags flags;
529 struct at91_usbh_data *pdata; 474 struct at91_usbh_data *pdata;
530 u32 ports; 475 u32 ports;
@@ -536,10 +481,9 @@ static int ohci_at91_of_init(struct platform_device *pdev)
536 * Since shared usb code relies on it, set it here for now. 481 * Since shared usb code relies on it, set it here for now.
537 * Once we have dma capability bindings this can go away. 482 * Once we have dma capability bindings this can go away.
538 */ 483 */
539 if (!pdev->dev.dma_mask) 484 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
540 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 485 if (ret)
541 if (!pdev->dev.coherent_dma_mask) 486 return ret;
542 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
543 487
544 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 488 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
545 if (!pdata) 489 if (!pdata)
@@ -703,7 +647,11 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
703 * REVISIT: some boards will be able to turn VBUS off... 647 * REVISIT: some boards will be able to turn VBUS off...
704 */ 648 */
705 if (at91_suspend_entering_slow_clock()) { 649 if (at91_suspend_entering_slow_clock()) {
706 ohci_usb_reset (ohci); 650 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
651 ohci->hc_control &= OHCI_CTRL_RWC;
652 ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
653 ohci->rh_state = OHCI_RH_HALTED;
654
707 /* flush the writes */ 655 /* flush the writes */
708 (void) ohci_readl (ohci, &ohci->regs->control); 656 (void) ohci_readl (ohci, &ohci->regs->control);
709 at91_stop_clock(); 657 at91_stop_clock();
@@ -730,8 +678,6 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
730#define ohci_hcd_at91_drv_resume NULL 678#define ohci_hcd_at91_drv_resume NULL
731#endif 679#endif
732 680
733MODULE_ALIAS("platform:at91_ohci");
734
735static struct platform_driver ohci_hcd_at91_driver = { 681static struct platform_driver ohci_hcd_at91_driver = {
736 .probe = ohci_hcd_at91_drv_probe, 682 .probe = ohci_hcd_at91_drv_probe,
737 .remove = ohci_hcd_at91_drv_remove, 683 .remove = ohci_hcd_at91_drv_remove,
@@ -744,3 +690,40 @@ static struct platform_driver ohci_hcd_at91_driver = {
744 .of_match_table = of_match_ptr(at91_ohci_dt_ids), 690 .of_match_table = of_match_ptr(at91_ohci_dt_ids),
745 }, 691 },
746}; 692};
693
694static int __init ohci_at91_init(void)
695{
696 if (usb_disabled())
697 return -ENODEV;
698
699 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
700 ohci_init_driver(&ohci_at91_hc_driver, NULL);
701
702 /*
703 * The Atmel HW has some unusual quirks, which require Atmel-specific
704 * workarounds. We override certain hc_driver functions here to
705 * achieve that. We explicitly do not enhance ohci_driver_overrides to
706 * allow this more easily, since this is an unusual case, and we don't
707 * want to encourage others to override these functions by making it
708 * too easy.
709 */
710
711 orig_ohci_hub_control = ohci_at91_hc_driver.hub_control;
712 orig_ohci_hub_status_data = ohci_at91_hc_driver.hub_status_data;
713
714 ohci_at91_hc_driver.hub_status_data = ohci_at91_hub_status_data;
715 ohci_at91_hc_driver.hub_control = ohci_at91_hub_control;
716
717 return platform_driver_register(&ohci_hcd_at91_driver);
718}
719module_init(ohci_at91_init);
720
721static void __exit ohci_at91_cleanup(void)
722{
723 platform_driver_unregister(&ohci_hcd_at91_driver);
724}
725module_exit(ohci_at91_cleanup);
726
727MODULE_DESCRIPTION(DRIVER_DESC);
728MODULE_LICENSE("GPL");
729MODULE_ALIAS("platform:at91_ohci");
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 31b81f9eacdc..3fca52ec02ac 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -17,7 +17,7 @@
17 case PIPE_BULK: temp = "bulk"; break; \ 17 case PIPE_BULK: temp = "bulk"; break; \
18 case PIPE_INTERRUPT: temp = "intr"; break; \ 18 case PIPE_INTERRUPT: temp = "intr"; break; \
19 default: temp = "isoc"; break; \ 19 default: temp = "isoc"; break; \
20 }; temp;}) 20 } temp;})
21#define pipestring(pipe) edstring(usb_pipetype(pipe)) 21#define pipestring(pipe) edstring(usb_pipetype(pipe))
22 22
23/* debug| print the main components of an URB 23/* debug| print the main components of an URB
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
deleted file mode 100644
index 84a20d5223b9..000000000000
--- a/drivers/usb/host/ohci-ep93xx.c
+++ /dev/null
@@ -1,184 +0,0 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
7 *
8 * Bus Glue for ep93xx.
9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
12 *
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
15 *
16 * Modified for pxa27x from ohci-lh7a404.c
17 * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
18 *
19 * Modified for ep93xx from ohci-pxa27x.c
20 * by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006
21 * Based on an earlier driver by Ray Lehtiniemi
22 *
23 * This file is licenced under the GPL.
24 */
25
26#include <linux/clk.h>
27#include <linux/device.h>
28#include <linux/signal.h>
29#include <linux/platform_device.h>
30
31static struct clk *usb_host_clock;
32
33static int ohci_ep93xx_start(struct usb_hcd *hcd)
34{
35 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
36 int ret;
37
38 if ((ret = ohci_init(ohci)) < 0)
39 return ret;
40
41 if ((ret = ohci_run(ohci)) < 0) {
42 dev_err(hcd->self.controller, "can't start %s\n",
43 hcd->self.bus_name);
44 ohci_stop(hcd);
45 return ret;
46 }
47
48 return 0;
49}
50
51static struct hc_driver ohci_ep93xx_hc_driver = {
52 .description = hcd_name,
53 .product_desc = "EP93xx OHCI",
54 .hcd_priv_size = sizeof(struct ohci_hcd),
55 .irq = ohci_irq,
56 .flags = HCD_USB11 | HCD_MEMORY,
57 .start = ohci_ep93xx_start,
58 .stop = ohci_stop,
59 .shutdown = ohci_shutdown,
60 .urb_enqueue = ohci_urb_enqueue,
61 .urb_dequeue = ohci_urb_dequeue,
62 .endpoint_disable = ohci_endpoint_disable,
63 .get_frame_number = ohci_get_frame,
64 .hub_status_data = ohci_hub_status_data,
65 .hub_control = ohci_hub_control,
66#ifdef CONFIG_PM
67 .bus_suspend = ohci_bus_suspend,
68 .bus_resume = ohci_bus_resume,
69#endif
70 .start_port_reset = ohci_start_port_reset,
71};
72
73static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
74{
75 struct usb_hcd *hcd;
76 struct resource *res;
77 int irq;
78 int ret;
79
80 if (usb_disabled())
81 return -ENODEV;
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);
124
125 return ret;
126}
127
128static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
129{
130 struct usb_hcd *hcd = platform_get_drvdata(pdev);
131
132 usb_remove_hcd(hcd);
133 clk_disable(usb_host_clock);
134 usb_put_hcd(hcd);
135
136 return 0;
137}
138
139#ifdef CONFIG_PM
140static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
141{
142 struct usb_hcd *hcd = platform_get_drvdata(pdev);
143 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
144
145 if (time_before(jiffies, ohci->next_statechange))
146 msleep(5);
147 ohci->next_statechange = jiffies;
148
149 clk_disable(usb_host_clock);
150 return 0;
151}
152
153static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
154{
155 struct usb_hcd *hcd = platform_get_drvdata(pdev);
156 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
157
158 if (time_before(jiffies, ohci->next_statechange))
159 msleep(5);
160 ohci->next_statechange = jiffies;
161
162 clk_enable(usb_host_clock);
163
164 ohci_resume(hcd, false);
165 return 0;
166}
167#endif
168
169
170static struct platform_driver ohci_hcd_ep93xx_driver = {
171 .probe = ohci_hcd_ep93xx_drv_probe,
172 .remove = ohci_hcd_ep93xx_drv_remove,
173 .shutdown = usb_hcd_platform_shutdown,
174#ifdef CONFIG_PM
175 .suspend = ohci_hcd_ep93xx_drv_suspend,
176 .resume = ohci_hcd_ep93xx_drv_resume,
177#endif
178 .driver = {
179 .name = "ep93xx-ohci",
180 .owner = THIS_MODULE,
181 },
182};
183
184MODULE_ALIAS("platform:ep93xx-ohci");
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index dc6ee9adacf5..91ec9b2cd378 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -12,98 +12,55 @@
12 */ 12 */
13 13
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/dma-mapping.h>
16#include <linux/io.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
15#include <linux/of.h> 19#include <linux/of.h>
16#include <linux/platform_device.h> 20#include <linux/platform_device.h>
17#include <linux/platform_data/usb-ohci-exynos.h>
18#include <linux/usb/phy.h> 21#include <linux/usb/phy.h>
19#include <linux/usb/samsung_usb_phy.h> 22#include <linux/usb/samsung_usb_phy.h>
23#include <linux/usb.h>
24#include <linux/usb/hcd.h>
25#include <linux/usb/otg.h>
26
27#include "ohci.h"
28
29#define DRIVER_DESC "OHCI EXYNOS driver"
30
31static const char hcd_name[] = "ohci-exynos";
32static struct hc_driver __read_mostly exynos_ohci_hc_driver;
33
34#define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)->priv)
20 35
21struct exynos_ohci_hcd { 36struct exynos_ohci_hcd {
22 struct device *dev;
23 struct usb_hcd *hcd;
24 struct clk *clk; 37 struct clk *clk;
25 struct usb_phy *phy; 38 struct usb_phy *phy;
26 struct usb_otg *otg; 39 struct usb_otg *otg;
27 struct exynos4_ohci_platdata *pdata;
28}; 40};
29 41
30static void exynos_ohci_phy_enable(struct exynos_ohci_hcd *exynos_ohci) 42static void exynos_ohci_phy_enable(struct platform_device *pdev)
31{ 43{
32 struct platform_device *pdev = to_platform_device(exynos_ohci->dev); 44 struct usb_hcd *hcd = platform_get_drvdata(pdev);
45 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
33 46
34 if (exynos_ohci->phy) 47 if (exynos_ohci->phy)
35 usb_phy_init(exynos_ohci->phy); 48 usb_phy_init(exynos_ohci->phy);
36 else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_init)
37 exynos_ohci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
38} 49}
39 50
40static void exynos_ohci_phy_disable(struct exynos_ohci_hcd *exynos_ohci) 51static void exynos_ohci_phy_disable(struct platform_device *pdev)
41{ 52{
42 struct platform_device *pdev = to_platform_device(exynos_ohci->dev); 53 struct usb_hcd *hcd = platform_get_drvdata(pdev);
54 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
43 55
44 if (exynos_ohci->phy) 56 if (exynos_ohci->phy)
45 usb_phy_shutdown(exynos_ohci->phy); 57 usb_phy_shutdown(exynos_ohci->phy);
46 else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_exit)
47 exynos_ohci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
48}
49
50static int ohci_exynos_reset(struct usb_hcd *hcd)
51{
52 return ohci_init(hcd_to_ohci(hcd));
53}
54
55static int ohci_exynos_start(struct usb_hcd *hcd)
56{
57 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
58 int ret;
59
60 ohci_dbg(ohci, "ohci_exynos_start, ohci:%p", ohci);
61
62 ret = ohci_run(ohci);
63 if (ret < 0) {
64 dev_err(hcd->self.controller, "can't start %s\n",
65 hcd->self.bus_name);
66 ohci_stop(hcd);
67 return ret;
68 }
69
70 return 0;
71} 58}
72 59
73static const struct hc_driver exynos_ohci_hc_driver = {
74 .description = hcd_name,
75 .product_desc = "EXYNOS OHCI Host Controller",
76 .hcd_priv_size = sizeof(struct ohci_hcd),
77
78 .irq = ohci_irq,
79 .flags = HCD_MEMORY|HCD_USB11,
80
81 .reset = ohci_exynos_reset,
82 .start = ohci_exynos_start,
83 .stop = ohci_stop,
84 .shutdown = ohci_shutdown,
85
86 .get_frame_number = ohci_get_frame,
87
88 .urb_enqueue = ohci_urb_enqueue,
89 .urb_dequeue = ohci_urb_dequeue,
90 .endpoint_disable = ohci_endpoint_disable,
91
92 .hub_status_data = ohci_hub_status_data,
93 .hub_control = ohci_hub_control,
94#ifdef CONFIG_PM
95 .bus_suspend = ohci_bus_suspend,
96 .bus_resume = ohci_bus_resume,
97#endif
98 .start_port_reset = ohci_start_port_reset,
99};
100
101static int exynos_ohci_probe(struct platform_device *pdev) 60static int exynos_ohci_probe(struct platform_device *pdev)
102{ 61{
103 struct exynos4_ohci_platdata *pdata = dev_get_platdata(&pdev->dev);
104 struct exynos_ohci_hcd *exynos_ohci; 62 struct exynos_ohci_hcd *exynos_ohci;
105 struct usb_hcd *hcd; 63 struct usb_hcd *hcd;
106 struct ohci_hcd *ohci;
107 struct resource *res; 64 struct resource *res;
108 struct usb_phy *phy; 65 struct usb_phy *phy;
109 int irq; 66 int irq;
@@ -114,15 +71,18 @@ static int exynos_ohci_probe(struct platform_device *pdev)
114 * Since shared usb code relies on it, set it here for now. 71 * Since shared usb code relies on it, set it here for now.
115 * Once we move to full device tree support this will vanish off. 72 * Once we move to full device tree support this will vanish off.
116 */ 73 */
117 if (!pdev->dev.dma_mask) 74 err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
118 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 75 if (err)
119 if (!pdev->dev.coherent_dma_mask) 76 return err;
120 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 77
121 78 hcd = usb_create_hcd(&exynos_ohci_hc_driver,
122 exynos_ohci = devm_kzalloc(&pdev->dev, sizeof(struct exynos_ohci_hcd), 79 &pdev->dev, dev_name(&pdev->dev));
123 GFP_KERNEL); 80 if (!hcd) {
124 if (!exynos_ohci) 81 dev_err(&pdev->dev, "Unable to create HCD\n");
125 return -ENOMEM; 82 return -ENOMEM;
83 }
84
85 exynos_ohci = to_exynos_ohci(hcd);
126 86
127 if (of_device_is_compatible(pdev->dev.of_node, 87 if (of_device_is_compatible(pdev->dev.of_node,
128 "samsung,exynos5440-ohci")) 88 "samsung,exynos5440-ohci"))
@@ -130,30 +90,15 @@ static int exynos_ohci_probe(struct platform_device *pdev)
130 90
131 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 91 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
132 if (IS_ERR(phy)) { 92 if (IS_ERR(phy)) {
133 /* Fallback to pdata */ 93 usb_put_hcd(hcd);
134 if (!pdata) { 94 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
135 dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); 95 return -EPROBE_DEFER;
136 return -EPROBE_DEFER;
137 } else {
138 exynos_ohci->pdata = pdata;
139 }
140 } else { 96 } else {
141 exynos_ohci->phy = phy; 97 exynos_ohci->phy = phy;
142 exynos_ohci->otg = phy->otg; 98 exynos_ohci->otg = phy->otg;
143 } 99 }
144 100
145skip_phy: 101skip_phy:
146
147 exynos_ohci->dev = &pdev->dev;
148
149 hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev,
150 dev_name(&pdev->dev));
151 if (!hcd) {
152 dev_err(&pdev->dev, "Unable to create HCD\n");
153 return -ENOMEM;
154 }
155
156 exynos_ohci->hcd = hcd;
157 exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); 102 exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost");
158 103
159 if (IS_ERR(exynos_ohci->clk)) { 104 if (IS_ERR(exynos_ohci->clk)) {
@@ -190,26 +135,21 @@ skip_phy:
190 } 135 }
191 136
192 if (exynos_ohci->otg) 137 if (exynos_ohci->otg)
193 exynos_ohci->otg->set_host(exynos_ohci->otg, 138 exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
194 &exynos_ohci->hcd->self);
195 139
196 exynos_ohci_phy_enable(exynos_ohci); 140 platform_set_drvdata(pdev, hcd);
197 141
198 ohci = hcd_to_ohci(hcd); 142 exynos_ohci_phy_enable(pdev);
199 ohci_hcd_init(ohci);
200 143
201 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 144 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
202 if (err) { 145 if (err) {
203 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 146 dev_err(&pdev->dev, "Failed to add USB HCD\n");
204 goto fail_add_hcd; 147 goto fail_add_hcd;
205 } 148 }
206
207 platform_set_drvdata(pdev, exynos_ohci);
208
209 return 0; 149 return 0;
210 150
211fail_add_hcd: 151fail_add_hcd:
212 exynos_ohci_phy_disable(exynos_ohci); 152 exynos_ohci_phy_disable(pdev);
213fail_io: 153fail_io:
214 clk_disable_unprepare(exynos_ohci->clk); 154 clk_disable_unprepare(exynos_ohci->clk);
215fail_clk: 155fail_clk:
@@ -219,16 +159,15 @@ fail_clk:
219 159
220static int exynos_ohci_remove(struct platform_device *pdev) 160static int exynos_ohci_remove(struct platform_device *pdev)
221{ 161{
222 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev); 162 struct usb_hcd *hcd = platform_get_drvdata(pdev);
223 struct usb_hcd *hcd = exynos_ohci->hcd; 163 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
224 164
225 usb_remove_hcd(hcd); 165 usb_remove_hcd(hcd);
226 166
227 if (exynos_ohci->otg) 167 if (exynos_ohci->otg)
228 exynos_ohci->otg->set_host(exynos_ohci->otg, 168 exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
229 &exynos_ohci->hcd->self);
230 169
231 exynos_ohci_phy_disable(exynos_ohci); 170 exynos_ohci_phy_disable(pdev);
232 171
233 clk_disable_unprepare(exynos_ohci->clk); 172 clk_disable_unprepare(exynos_ohci->clk);
234 173
@@ -239,8 +178,7 @@ static int exynos_ohci_remove(struct platform_device *pdev)
239 178
240static void exynos_ohci_shutdown(struct platform_device *pdev) 179static void exynos_ohci_shutdown(struct platform_device *pdev)
241{ 180{
242 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev); 181 struct usb_hcd *hcd = platform_get_drvdata(pdev);
243 struct usb_hcd *hcd = exynos_ohci->hcd;
244 182
245 if (hcd->driver->shutdown) 183 if (hcd->driver->shutdown)
246 hcd->driver->shutdown(hcd); 184 hcd->driver->shutdown(hcd);
@@ -249,9 +187,10 @@ static void exynos_ohci_shutdown(struct platform_device *pdev)
249#ifdef CONFIG_PM 187#ifdef CONFIG_PM
250static int exynos_ohci_suspend(struct device *dev) 188static int exynos_ohci_suspend(struct device *dev)
251{ 189{
252 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev); 190 struct usb_hcd *hcd = dev_get_drvdata(dev);
253 struct usb_hcd *hcd = exynos_ohci->hcd; 191 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
254 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 192 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
193 struct platform_device *pdev = to_platform_device(dev);
255 unsigned long flags; 194 unsigned long flags;
256 int rc = 0; 195 int rc = 0;
257 196
@@ -271,10 +210,9 @@ static int exynos_ohci_suspend(struct device *dev)
271 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 210 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
272 211
273 if (exynos_ohci->otg) 212 if (exynos_ohci->otg)
274 exynos_ohci->otg->set_host(exynos_ohci->otg, 213 exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
275 &exynos_ohci->hcd->self);
276 214
277 exynos_ohci_phy_disable(exynos_ohci); 215 exynos_ohci_phy_disable(pdev);
278 216
279 clk_disable_unprepare(exynos_ohci->clk); 217 clk_disable_unprepare(exynos_ohci->clk);
280 218
@@ -286,16 +224,16 @@ fail:
286 224
287static int exynos_ohci_resume(struct device *dev) 225static int exynos_ohci_resume(struct device *dev)
288{ 226{
289 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev); 227 struct usb_hcd *hcd = dev_get_drvdata(dev);
290 struct usb_hcd *hcd = exynos_ohci->hcd; 228 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
229 struct platform_device *pdev = to_platform_device(dev);
291 230
292 clk_prepare_enable(exynos_ohci->clk); 231 clk_prepare_enable(exynos_ohci->clk);
293 232
294 if (exynos_ohci->otg) 233 if (exynos_ohci->otg)
295 exynos_ohci->otg->set_host(exynos_ohci->otg, 234 exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
296 &exynos_ohci->hcd->self);
297 235
298 exynos_ohci_phy_enable(exynos_ohci); 236 exynos_ohci_phy_enable(pdev);
299 237
300 ohci_resume(hcd, false); 238 ohci_resume(hcd, false);
301 239
@@ -306,6 +244,10 @@ static int exynos_ohci_resume(struct device *dev)
306#define exynos_ohci_resume NULL 244#define exynos_ohci_resume NULL
307#endif 245#endif
308 246
247static const struct ohci_driver_overrides exynos_overrides __initconst = {
248 .extra_priv_size = sizeof(struct exynos_ohci_hcd),
249};
250
309static const struct dev_pm_ops exynos_ohci_pm_ops = { 251static const struct dev_pm_ops exynos_ohci_pm_ops = {
310 .suspend = exynos_ohci_suspend, 252 .suspend = exynos_ohci_suspend,
311 .resume = exynos_ohci_resume, 253 .resume = exynos_ohci_resume,
@@ -331,6 +273,23 @@ static struct platform_driver exynos_ohci_driver = {
331 .of_match_table = of_match_ptr(exynos_ohci_match), 273 .of_match_table = of_match_ptr(exynos_ohci_match),
332 } 274 }
333}; 275};
276static int __init ohci_exynos_init(void)
277{
278 if (usb_disabled())
279 return -ENODEV;
280
281 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
282 ohci_init_driver(&exynos_ohci_hc_driver, &exynos_overrides);
283 return platform_driver_register(&exynos_ohci_driver);
284}
285module_init(ohci_exynos_init);
286
287static void __exit ohci_exynos_cleanup(void)
288{
289 platform_driver_unregister(&exynos_ohci_driver);
290}
291module_exit(ohci_exynos_cleanup);
334 292
335MODULE_ALIAS("platform:exynos-ohci"); 293MODULE_ALIAS("platform:exynos-ohci");
336MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); 294MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
295MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 8f6b695af6a4..8ada13f8dde2 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -216,31 +216,26 @@ static int ohci_urb_enqueue (
216 frame &= ~(ed->interval - 1); 216 frame &= ~(ed->interval - 1);
217 frame |= ed->branch; 217 frame |= ed->branch;
218 urb->start_frame = frame; 218 urb->start_frame = frame;
219 ed->last_iso = frame + ed->interval * (size - 1);
219 } 220 }
220 } else if (ed->type == PIPE_ISOCHRONOUS) { 221 } else if (ed->type == PIPE_ISOCHRONOUS) {
221 u16 next = ohci_frame_no(ohci) + 1; 222 u16 next = ohci_frame_no(ohci) + 1;
222 u16 frame = ed->last_iso + ed->interval; 223 u16 frame = ed->last_iso + ed->interval;
224 u16 length = ed->interval * (size - 1);
223 225
224 /* Behind the scheduling threshold? */ 226 /* Behind the scheduling threshold? */
225 if (unlikely(tick_before(frame, next))) { 227 if (unlikely(tick_before(frame, next))) {
226 228
227 /* USB_ISO_ASAP: Round up to the first available slot */ 229 /* URB_ISO_ASAP: Round up to the first available slot */
228 if (urb->transfer_flags & URB_ISO_ASAP) { 230 if (urb->transfer_flags & URB_ISO_ASAP) {
229 frame += (next - frame + ed->interval - 1) & 231 frame += (next - frame + ed->interval - 1) &
230 -ed->interval; 232 -ed->interval;
231 233
232 /* 234 /*
233 * Not ASAP: Use the next slot in the stream. If 235 * Not ASAP: Use the next slot in the stream,
234 * the entire URB falls before the threshold, fail. 236 * no matter what.
235 */ 237 */
236 } else { 238 } else {
237 if (tick_before(frame + ed->interval *
238 (urb->number_of_packets - 1), next)) {
239 retval = -EXDEV;
240 usb_hcd_unlink_urb_from_ep(hcd, urb);
241 goto fail;
242 }
243
244 /* 239 /*
245 * Some OHCI hardware doesn't handle late TDs 240 * Some OHCI hardware doesn't handle late TDs
246 * correctly. After retiring them it proceeds 241 * correctly. After retiring them it proceeds
@@ -251,9 +246,16 @@ static int ohci_urb_enqueue (
251 urb_priv->td_cnt = DIV_ROUND_UP( 246 urb_priv->td_cnt = DIV_ROUND_UP(
252 (u16) (next - frame), 247 (u16) (next - frame),
253 ed->interval); 248 ed->interval);
249 if (urb_priv->td_cnt >= urb_priv->length) {
250 ++urb_priv->td_cnt; /* Mark it */
251 ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n",
252 urb, frame, length,
253 next);
254 }
254 } 255 }
255 } 256 }
256 urb->start_frame = frame; 257 urb->start_frame = frame;
258 ed->last_iso = frame + length;
257 } 259 }
258 260
259 /* fill the TDs and link them to the ed; and 261 /* fill the TDs and link them to the ed; and
@@ -1159,10 +1161,12 @@ void ohci_init_driver(struct hc_driver *drv,
1159 /* Copy the generic table to drv and then apply the overrides */ 1161 /* Copy the generic table to drv and then apply the overrides */
1160 *drv = ohci_hc_driver; 1162 *drv = ohci_hc_driver;
1161 1163
1162 drv->product_desc = over->product_desc; 1164 if (over) {
1163 drv->hcd_priv_size += over->extra_priv_size; 1165 drv->product_desc = over->product_desc;
1164 if (over->reset) 1166 drv->hcd_priv_size += over->extra_priv_size;
1165 drv->reset = over->reset; 1167 if (over->reset)
1168 drv->reset = over->reset;
1169 }
1166} 1170}
1167EXPORT_SYMBOL_GPL(ohci_init_driver); 1171EXPORT_SYMBOL_GPL(ohci_init_driver);
1168 1172
@@ -1177,46 +1181,6 @@ MODULE_LICENSE ("GPL");
1177#define SA1111_DRIVER ohci_hcd_sa1111_driver 1181#define SA1111_DRIVER ohci_hcd_sa1111_driver
1178#endif 1182#endif
1179 1183
1180#if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX)
1181#include "ohci-s3c2410.c"
1182#define S3C2410_PLATFORM_DRIVER ohci_hcd_s3c2410_driver
1183#endif
1184
1185#ifdef CONFIG_USB_OHCI_EXYNOS
1186#include "ohci-exynos.c"
1187#define EXYNOS_PLATFORM_DRIVER exynos_ohci_driver
1188#endif
1189
1190#ifdef CONFIG_USB_OHCI_HCD_OMAP1
1191#include "ohci-omap.c"
1192#define OMAP1_PLATFORM_DRIVER ohci_hcd_omap_driver
1193#endif
1194
1195#ifdef CONFIG_USB_OHCI_HCD_OMAP3
1196#include "ohci-omap3.c"
1197#define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver
1198#endif
1199
1200#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
1201#include "ohci-pxa27x.c"
1202#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
1203#endif
1204
1205#ifdef CONFIG_ARCH_EP93XX
1206#include "ohci-ep93xx.c"
1207#define EP93XX_PLATFORM_DRIVER ohci_hcd_ep93xx_driver
1208#endif
1209
1210#ifdef CONFIG_ARCH_AT91
1211#include "ohci-at91.c"
1212#define AT91_PLATFORM_DRIVER ohci_hcd_at91_driver
1213#endif
1214
1215#ifdef CONFIG_ARCH_LPC32XX
1216#include "ohci-nxp.c"
1217#define NXP_PLATFORM_DRIVER usb_hcd_nxp_driver
1218#endif
1219
1220#ifdef CONFIG_ARCH_DAVINCI_DA8XX 1184#ifdef CONFIG_ARCH_DAVINCI_DA8XX
1221#include "ohci-da8xx.c" 1185#include "ohci-da8xx.c"
1222#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver 1186#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
@@ -1227,11 +1191,6 @@ MODULE_LICENSE ("GPL");
1227#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver 1191#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1228#endif 1192#endif
1229 1193
1230#ifdef CONFIG_PLAT_SPEAR
1231#include "ohci-spear.c"
1232#define SPEAR_PLATFORM_DRIVER spear_ohci_hcd_driver
1233#endif
1234
1235#ifdef CONFIG_PPC_PS3 1194#ifdef CONFIG_PPC_PS3
1236#include "ohci-ps3.c" 1195#include "ohci-ps3.c"
1237#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver 1196#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
@@ -1294,18 +1253,6 @@ static int __init ohci_hcd_mod_init(void)
1294 goto error_platform; 1253 goto error_platform;
1295#endif 1254#endif
1296 1255
1297#ifdef OMAP1_PLATFORM_DRIVER
1298 retval = platform_driver_register(&OMAP1_PLATFORM_DRIVER);
1299 if (retval < 0)
1300 goto error_omap1_platform;
1301#endif
1302
1303#ifdef OMAP3_PLATFORM_DRIVER
1304 retval = platform_driver_register(&OMAP3_PLATFORM_DRIVER);
1305 if (retval < 0)
1306 goto error_omap3_platform;
1307#endif
1308
1309#ifdef OF_PLATFORM_DRIVER 1256#ifdef OF_PLATFORM_DRIVER
1310 retval = platform_driver_register(&OF_PLATFORM_DRIVER); 1257 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1311 if (retval < 0) 1258 if (retval < 0)
@@ -1330,79 +1277,19 @@ static int __init ohci_hcd_mod_init(void)
1330 goto error_tmio; 1277 goto error_tmio;
1331#endif 1278#endif
1332 1279
1333#ifdef S3C2410_PLATFORM_DRIVER
1334 retval = platform_driver_register(&S3C2410_PLATFORM_DRIVER);
1335 if (retval < 0)
1336 goto error_s3c2410;
1337#endif
1338
1339#ifdef EXYNOS_PLATFORM_DRIVER
1340 retval = platform_driver_register(&EXYNOS_PLATFORM_DRIVER);
1341 if (retval < 0)
1342 goto error_exynos;
1343#endif
1344
1345#ifdef EP93XX_PLATFORM_DRIVER
1346 retval = platform_driver_register(&EP93XX_PLATFORM_DRIVER);
1347 if (retval < 0)
1348 goto error_ep93xx;
1349#endif
1350
1351#ifdef AT91_PLATFORM_DRIVER
1352 retval = platform_driver_register(&AT91_PLATFORM_DRIVER);
1353 if (retval < 0)
1354 goto error_at91;
1355#endif
1356
1357#ifdef NXP_PLATFORM_DRIVER
1358 retval = platform_driver_register(&NXP_PLATFORM_DRIVER);
1359 if (retval < 0)
1360 goto error_nxp;
1361#endif
1362
1363#ifdef DAVINCI_PLATFORM_DRIVER 1280#ifdef DAVINCI_PLATFORM_DRIVER
1364 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER); 1281 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
1365 if (retval < 0) 1282 if (retval < 0)
1366 goto error_davinci; 1283 goto error_davinci;
1367#endif 1284#endif
1368 1285
1369#ifdef SPEAR_PLATFORM_DRIVER
1370 retval = platform_driver_register(&SPEAR_PLATFORM_DRIVER);
1371 if (retval < 0)
1372 goto error_spear;
1373#endif
1374
1375 return retval; 1286 return retval;
1376 1287
1377 /* Error path */ 1288 /* Error path */
1378#ifdef SPEAR_PLATFORM_DRIVER
1379 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1380 error_spear:
1381#endif
1382#ifdef DAVINCI_PLATFORM_DRIVER 1289#ifdef DAVINCI_PLATFORM_DRIVER
1383 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); 1290 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1384 error_davinci: 1291 error_davinci:
1385#endif 1292#endif
1386#ifdef NXP_PLATFORM_DRIVER
1387 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1388 error_nxp:
1389#endif
1390#ifdef AT91_PLATFORM_DRIVER
1391 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1392 error_at91:
1393#endif
1394#ifdef EP93XX_PLATFORM_DRIVER
1395 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1396 error_ep93xx:
1397#endif
1398#ifdef EXYNOS_PLATFORM_DRIVER
1399 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1400 error_exynos:
1401#endif
1402#ifdef S3C2410_PLATFORM_DRIVER
1403 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1404 error_s3c2410:
1405#endif
1406#ifdef TMIO_OHCI_DRIVER 1293#ifdef TMIO_OHCI_DRIVER
1407 platform_driver_unregister(&TMIO_OHCI_DRIVER); 1294 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1408 error_tmio: 1295 error_tmio:
@@ -1419,14 +1306,6 @@ static int __init ohci_hcd_mod_init(void)
1419 platform_driver_unregister(&OF_PLATFORM_DRIVER); 1306 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1420 error_of_platform: 1307 error_of_platform:
1421#endif 1308#endif
1422#ifdef OMAP3_PLATFORM_DRIVER
1423 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1424 error_omap3_platform:
1425#endif
1426#ifdef OMAP1_PLATFORM_DRIVER
1427 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1428 error_omap1_platform:
1429#endif
1430#ifdef PLATFORM_DRIVER 1309#ifdef PLATFORM_DRIVER
1431 platform_driver_unregister(&PLATFORM_DRIVER); 1310 platform_driver_unregister(&PLATFORM_DRIVER);
1432 error_platform: 1311 error_platform:
@@ -1448,27 +1327,9 @@ module_init(ohci_hcd_mod_init);
1448 1327
1449static void __exit ohci_hcd_mod_exit(void) 1328static void __exit ohci_hcd_mod_exit(void)
1450{ 1329{
1451#ifdef SPEAR_PLATFORM_DRIVER
1452 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1453#endif
1454#ifdef DAVINCI_PLATFORM_DRIVER 1330#ifdef DAVINCI_PLATFORM_DRIVER
1455 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); 1331 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1456#endif 1332#endif
1457#ifdef NXP_PLATFORM_DRIVER
1458 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1459#endif
1460#ifdef AT91_PLATFORM_DRIVER
1461 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1462#endif
1463#ifdef EP93XX_PLATFORM_DRIVER
1464 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1465#endif
1466#ifdef EXYNOS_PLATFORM_DRIVER
1467 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1468#endif
1469#ifdef S3C2410_PLATFORM_DRIVER
1470 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1471#endif
1472#ifdef TMIO_OHCI_DRIVER 1333#ifdef TMIO_OHCI_DRIVER
1473 platform_driver_unregister(&TMIO_OHCI_DRIVER); 1334 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1474#endif 1335#endif
@@ -1481,12 +1342,6 @@ static void __exit ohci_hcd_mod_exit(void)
1481#ifdef OF_PLATFORM_DRIVER 1342#ifdef OF_PLATFORM_DRIVER
1482 platform_driver_unregister(&OF_PLATFORM_DRIVER); 1343 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1483#endif 1344#endif
1484#ifdef OMAP3_PLATFORM_DRIVER
1485 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1486#endif
1487#ifdef OMAP1_PLATFORM_DRIVER
1488 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1489#endif
1490#ifdef PLATFORM_DRIVER 1345#ifdef PLATFORM_DRIVER
1491 platform_driver_unregister(&PLATFORM_DRIVER); 1346 platform_driver_unregister(&PLATFORM_DRIVER);
1492#endif 1347#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 2347ab83f046..61705a760e7d 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -212,10 +212,11 @@ __acquires(ohci->lock)
212 /* Sometimes PCI D3 suspend trashes frame timings ... */ 212 /* Sometimes PCI D3 suspend trashes frame timings ... */
213 periodic_reinit (ohci); 213 periodic_reinit (ohci);
214 214
215 /* the following code is executed with ohci->lock held and 215 /*
216 * irqs disabled if and only if autostopped is true 216 * The following code is executed with ohci->lock held and
217 * irqs disabled if and only if autostopped is true. This
218 * will cause sparse to warn about a "context imbalance".
217 */ 219 */
218
219skip_resume: 220skip_resume:
220 /* interrupts might have been disabled */ 221 /* interrupts might have been disabled */
221 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); 222 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable);
@@ -531,7 +532,7 @@ ohci_hub_descriptor (
531 temp |= 0x0010; 532 temp |= 0x0010;
532 else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */ 533 else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */
533 temp |= 0x0008; 534 temp |= 0x0008;
534 desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); 535 desc->wHubCharacteristics = cpu_to_le16(temp);
535 536
536 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 537 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
537 rh = roothub_b (ohci); 538 rh = roothub_b (ohci);
diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c
index 7d7d507d54e8..e99db8a6d55f 100644
--- a/drivers/usb/host/ohci-nxp.c
+++ b/drivers/usb/host/ohci-nxp.c
@@ -19,10 +19,19 @@
19 * or implied. 19 * or implied.
20 */ 20 */
21#include <linux/clk.h> 21#include <linux/clk.h>
22#include <linux/platform_device.h> 22#include <linux/dma-mapping.h>
23#include <linux/io.h>
23#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
24#include <linux/of.h> 27#include <linux/of.h>
28#include <linux/platform_device.h>
25#include <linux/usb/isp1301.h> 29#include <linux/usb/isp1301.h>
30#include <linux/usb.h>
31#include <linux/usb/hcd.h>
32
33#include "ohci.h"
34
26 35
27#include <mach/hardware.h> 36#include <mach/hardware.h>
28#include <asm/mach-types.h> 37#include <asm/mach-types.h>
@@ -57,6 +66,11 @@
57#define start_int_umask(irq) 66#define start_int_umask(irq)
58#endif 67#endif
59 68
69#define DRIVER_DESC "OHCI NXP driver"
70
71static const char hcd_name[] = "ohci-nxp";
72static struct hc_driver __read_mostly ohci_nxp_hc_driver;
73
60static struct i2c_client *isp1301_i2c_client; 74static struct i2c_client *isp1301_i2c_client;
61 75
62extern int usb_disabled(void); 76extern int usb_disabled(void);
@@ -132,14 +146,14 @@ static inline void isp1301_vbus_off(void)
132 OTG1_VBUS_DRV); 146 OTG1_VBUS_DRV);
133} 147}
134 148
135static void nxp_start_hc(void) 149static void ohci_nxp_start_hc(void)
136{ 150{
137 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN; 151 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
138 __raw_writel(tmp, USB_OTG_STAT_CONTROL); 152 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
139 isp1301_vbus_on(); 153 isp1301_vbus_on();
140} 154}
141 155
142static void nxp_stop_hc(void) 156static void ohci_nxp_stop_hc(void)
143{ 157{
144 unsigned long tmp; 158 unsigned long tmp;
145 isp1301_vbus_off(); 159 isp1301_vbus_off();
@@ -147,68 +161,9 @@ static void nxp_stop_hc(void)
147 __raw_writel(tmp, USB_OTG_STAT_CONTROL); 161 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
148} 162}
149 163
150static int ohci_nxp_start(struct usb_hcd *hcd) 164static int ohci_hcd_nxp_probe(struct platform_device *pdev)
151{
152 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
153 int ret;
154
155 if ((ret = ohci_init(ohci)) < 0)
156 return ret;
157
158 if ((ret = ohci_run(ohci)) < 0) {
159 dev_err(hcd->self.controller, "can't start\n");
160 ohci_stop(hcd);
161 return ret;
162 }
163 return 0;
164}
165
166static const struct hc_driver ohci_nxp_hc_driver = {
167 .description = hcd_name,
168 .product_desc = "nxp OHCI",
169
170 /*
171 * generic hardware linkage
172 */
173 .irq = ohci_irq,
174 .flags = HCD_USB11 | HCD_MEMORY,
175
176 .hcd_priv_size = sizeof(struct ohci_hcd),
177 /*
178 * basic lifecycle operations
179 */
180 .start = ohci_nxp_start,
181 .stop = ohci_stop,
182 .shutdown = ohci_shutdown,
183
184 /*
185 * managing i/o requests and associated device resources
186 */
187 .urb_enqueue = ohci_urb_enqueue,
188 .urb_dequeue = ohci_urb_dequeue,
189 .endpoint_disable = ohci_endpoint_disable,
190
191 /*
192 * scheduling support
193 */
194 .get_frame_number = ohci_get_frame,
195
196 /*
197 * root hub support
198 */
199 .hub_status_data = ohci_hub_status_data,
200 .hub_control = ohci_hub_control,
201#ifdef CONFIG_PM
202 .bus_suspend = ohci_bus_suspend,
203 .bus_resume = ohci_bus_resume,
204#endif
205 .start_port_reset = ohci_start_port_reset,
206};
207
208static int usb_hcd_nxp_probe(struct platform_device *pdev)
209{ 165{
210 struct usb_hcd *hcd = 0; 166 struct usb_hcd *hcd = 0;
211 struct ohci_hcd *ohci;
212 const struct hc_driver *driver = &ohci_nxp_hc_driver; 167 const struct hc_driver *driver = &ohci_nxp_hc_driver;
213 struct resource *res; 168 struct resource *res;
214 int ret = 0, irq; 169 int ret = 0, irq;
@@ -226,8 +181,9 @@ static int usb_hcd_nxp_probe(struct platform_device *pdev)
226 return -EPROBE_DEFER; 181 return -EPROBE_DEFER;
227 } 182 }
228 183
229 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 184 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
230 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 185 if (ret)
186 goto fail_disable;
231 187
232 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name); 188 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
233 if (usb_disabled()) { 189 if (usb_disabled()) {
@@ -313,17 +269,15 @@ static int usb_hcd_nxp_probe(struct platform_device *pdev)
313 goto fail_resource; 269 goto fail_resource;
314 } 270 }
315 271
316 nxp_start_hc(); 272 ohci_nxp_start_hc();
317 platform_set_drvdata(pdev, hcd); 273 platform_set_drvdata(pdev, hcd);
318 ohci = hcd_to_ohci(hcd);
319 ohci_hcd_init(ohci);
320 274
321 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq); 275 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
322 ret = usb_add_hcd(hcd, irq, 0); 276 ret = usb_add_hcd(hcd, irq, 0);
323 if (ret == 0) 277 if (ret == 0)
324 return ret; 278 return ret;
325 279
326 nxp_stop_hc(); 280 ohci_nxp_stop_hc();
327fail_resource: 281fail_resource:
328 usb_put_hcd(hcd); 282 usb_put_hcd(hcd);
329fail_hcd: 283fail_hcd:
@@ -345,12 +299,12 @@ fail_disable:
345 return ret; 299 return ret;
346} 300}
347 301
348static int usb_hcd_nxp_remove(struct platform_device *pdev) 302static int ohci_hcd_nxp_remove(struct platform_device *pdev)
349{ 303{
350 struct usb_hcd *hcd = platform_get_drvdata(pdev); 304 struct usb_hcd *hcd = platform_get_drvdata(pdev);
351 305
352 usb_remove_hcd(hcd); 306 usb_remove_hcd(hcd);
353 nxp_stop_hc(); 307 ohci_nxp_stop_hc();
354 usb_put_hcd(hcd); 308 usb_put_hcd(hcd);
355 clk_disable(usb_pll_clk); 309 clk_disable(usb_pll_clk);
356 clk_put(usb_pll_clk); 310 clk_put(usb_pll_clk);
@@ -366,20 +320,40 @@ static int usb_hcd_nxp_remove(struct platform_device *pdev)
366MODULE_ALIAS("platform:usb-ohci"); 320MODULE_ALIAS("platform:usb-ohci");
367 321
368#ifdef CONFIG_OF 322#ifdef CONFIG_OF
369static const struct of_device_id usb_hcd_nxp_match[] = { 323static const struct of_device_id ohci_hcd_nxp_match[] = {
370 { .compatible = "nxp,ohci-nxp" }, 324 { .compatible = "nxp,ohci-nxp" },
371 {}, 325 {},
372}; 326};
373MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match); 327MODULE_DEVICE_TABLE(of, ohci_hcd_nxp_match);
374#endif 328#endif
375 329
376static struct platform_driver usb_hcd_nxp_driver = { 330static struct platform_driver ohci_hcd_nxp_driver = {
377 .driver = { 331 .driver = {
378 .name = "usb-ohci", 332 .name = "usb-ohci",
379 .owner = THIS_MODULE, 333 .owner = THIS_MODULE,
380 .of_match_table = of_match_ptr(usb_hcd_nxp_match), 334 .of_match_table = of_match_ptr(ohci_hcd_nxp_match),
381 }, 335 },
382 .probe = usb_hcd_nxp_probe, 336 .probe = ohci_hcd_nxp_probe,
383 .remove = usb_hcd_nxp_remove, 337 .remove = ohci_hcd_nxp_remove,
384}; 338};
385 339
340static int __init ohci_nxp_init(void)
341{
342 if (usb_disabled())
343 return -ENODEV;
344
345 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
346
347 ohci_init_driver(&ohci_nxp_hc_driver, NULL);
348 return platform_driver_register(&ohci_hcd_nxp_driver);
349}
350module_init(ohci_nxp_init);
351
352static void __exit ohci_nxp_cleanup(void)
353{
354 platform_driver_unregister(&ohci_hcd_nxp_driver);
355}
356module_exit(ohci_nxp_cleanup);
357
358MODULE_DESCRIPTION(DRIVER_DESC);
359MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ohci-octeon.c b/drivers/usb/host/ohci-octeon.c
index 342dc7e543b8..6c16dcef15c6 100644
--- a/drivers/usb/host/ohci-octeon.c
+++ b/drivers/usb/host/ohci-octeon.c
@@ -127,8 +127,9 @@ static int ohci_octeon_drv_probe(struct platform_device *pdev)
127 } 127 }
128 128
129 /* Ohci is a 32-bit device. */ 129 /* Ohci is a 32-bit device. */
130 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 130 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
131 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 131 if (ret)
132 return ret;
132 133
133 hcd = usb_create_hcd(&ohci_octeon_hc_driver, &pdev->dev, "octeon"); 134 hcd = usb_create_hcd(&ohci_octeon_hc_driver, &pdev->dev, "octeon");
134 if (!hcd) 135 if (!hcd)
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 31d3a12eb486..f253214741ba 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -14,12 +14,21 @@
14 * This file is licenced under the GPL. 14 * This file is licenced under the GPL.
15 */ 15 */
16 16
17#include <linux/signal.h>
18#include <linux/jiffies.h>
19#include <linux/platform_device.h>
20#include <linux/clk.h> 17#include <linux/clk.h>
18#include <linux/dma-mapping.h>
21#include <linux/err.h> 19#include <linux/err.h>
22#include <linux/gpio.h> 20#include <linux/gpio.h>
21#include <linux/io.h>
22#include <linux/jiffies.h>
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/usb/otg.h>
26#include <linux/platform_device.h>
27#include <linux/signal.h>
28#include <linux/usb.h>
29#include <linux/usb/hcd.h>
30
31#include "ohci.h"
23 32
24#include <asm/io.h> 33#include <asm/io.h>
25#include <asm/mach-types.h> 34#include <asm/mach-types.h>
@@ -42,10 +51,7 @@
42#define OMAP1510_LB_MMU_RAM_H 0xfffec234 51#define OMAP1510_LB_MMU_RAM_H 0xfffec234
43#define OMAP1510_LB_MMU_RAM_L 0xfffec238 52#define OMAP1510_LB_MMU_RAM_L 0xfffec238
44 53
45 54#define DRIVER_DESC "OHCI OMAP driver"
46#ifndef CONFIG_ARCH_OMAP
47#error "This file is OMAP bus glue. CONFIG_OMAP must be defined."
48#endif
49 55
50#ifdef CONFIG_TPS65010 56#ifdef CONFIG_TPS65010
51#include <linux/i2c/tps65010.h> 57#include <linux/i2c/tps65010.h>
@@ -68,8 +74,9 @@ extern int ocpi_enable(void);
68 74
69static struct clk *usb_host_ck; 75static struct clk *usb_host_ck;
70static struct clk *usb_dc_ck; 76static struct clk *usb_dc_ck;
71static int host_enabled; 77
72static int host_initialized; 78static const char hcd_name[] = "ohci-omap";
79static struct hc_driver __read_mostly ohci_omap_hc_driver;
73 80
74static void omap_ohci_clock_power(int on) 81static void omap_ohci_clock_power(int on)
75{ 82{
@@ -188,7 +195,7 @@ static void start_hnp(struct ohci_hcd *ohci)
188 195
189/*-------------------------------------------------------------------------*/ 196/*-------------------------------------------------------------------------*/
190 197
191static int ohci_omap_init(struct usb_hcd *hcd) 198static int ohci_omap_reset(struct usb_hcd *hcd)
192{ 199{
193 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 200 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
194 struct omap_usb_config *config = dev_get_platdata(hcd->self.controller); 201 struct omap_usb_config *config = dev_get_platdata(hcd->self.controller);
@@ -198,9 +205,9 @@ static int ohci_omap_init(struct usb_hcd *hcd)
198 dev_dbg(hcd->self.controller, "starting USB Controller\n"); 205 dev_dbg(hcd->self.controller, "starting USB Controller\n");
199 206
200 if (config->otg) { 207 if (config->otg) {
201 ohci_to_hcd(ohci)->self.otg_port = config->otg; 208 hcd->self.otg_port = config->otg;
202 /* default/minimum OTG power budget: 8 mA */ 209 /* default/minimum OTG power budget: 8 mA */
203 ohci_to_hcd(ohci)->power_budget = 8; 210 hcd->power_budget = 8;
204 } 211 }
205 212
206 /* boards can use OTG transceivers in non-OTG modes */ 213 /* boards can use OTG transceivers in non-OTG modes */
@@ -238,9 +245,15 @@ static int ohci_omap_init(struct usb_hcd *hcd)
238 omap_1510_local_bus_init(); 245 omap_1510_local_bus_init();
239 } 246 }
240 247
241 if ((ret = ohci_init(ohci)) < 0) 248 ret = ohci_setup(hcd);
249 if (ret < 0)
242 return ret; 250 return ret;
243 251
252 if (config->otg || config->rwc) {
253 ohci->hc_control = OHCI_CTRL_RWC;
254 writel(OHCI_CTRL_RWC, &ohci->regs->control);
255 }
256
244 /* board-specific power switching and overcurrent support */ 257 /* board-specific power switching and overcurrent support */
245 if (machine_is_omap_osk() || machine_is_omap_innovator()) { 258 if (machine_is_omap_osk() || machine_is_omap_innovator()) {
246 u32 rh = roothub_a (ohci); 259 u32 rh = roothub_a (ohci);
@@ -281,14 +294,6 @@ static int ohci_omap_init(struct usb_hcd *hcd)
281 return 0; 294 return 0;
282} 295}
283 296
284static void ohci_omap_stop(struct usb_hcd *hcd)
285{
286 dev_dbg(hcd->self.controller, "stopping USB Controller\n");
287 ohci_stop(hcd);
288 omap_ohci_clock_power(0);
289}
290
291
292/*-------------------------------------------------------------------------*/ 297/*-------------------------------------------------------------------------*/
293 298
294/** 299/**
@@ -304,7 +309,6 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
304{ 309{
305 int retval, irq; 310 int retval, irq;
306 struct usb_hcd *hcd = 0; 311 struct usb_hcd *hcd = 0;
307 struct ohci_hcd *ohci;
308 312
309 if (pdev->num_resources != 2) { 313 if (pdev->num_resources != 2) {
310 printk(KERN_ERR "hcd probe: invalid num_resources: %i\n", 314 printk(KERN_ERR "hcd probe: invalid num_resources: %i\n",
@@ -354,12 +358,6 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
354 goto err2; 358 goto err2;
355 } 359 }
356 360
357 ohci = hcd_to_ohci(hcd);
358 ohci_hcd_init(ohci);
359
360 host_initialized = 0;
361 host_enabled = 1;
362
363 irq = platform_get_irq(pdev, 0); 361 irq = platform_get_irq(pdev, 0);
364 if (irq < 0) { 362 if (irq < 0) {
365 retval = -ENXIO; 363 retval = -ENXIO;
@@ -369,11 +367,6 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
369 if (retval) 367 if (retval)
370 goto err3; 368 goto err3;
371 369
372 host_initialized = 1;
373
374 if (!host_enabled)
375 omap_ohci_clock_power(0);
376
377 return 0; 370 return 0;
378err3: 371err3:
379 iounmap(hcd->regs); 372 iounmap(hcd->regs);
@@ -402,7 +395,9 @@ err0:
402static inline void 395static inline void
403usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev) 396usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
404{ 397{
398 dev_dbg(hcd->self.controller, "stopping USB Controller\n");
405 usb_remove_hcd(hcd); 399 usb_remove_hcd(hcd);
400 omap_ohci_clock_power(0);
406 if (!IS_ERR_OR_NULL(hcd->phy)) { 401 if (!IS_ERR_OR_NULL(hcd->phy)) {
407 (void) otg_set_host(hcd->phy->otg, 0); 402 (void) otg_set_host(hcd->phy->otg, 0);
408 usb_put_phy(hcd->phy); 403 usb_put_phy(hcd->phy);
@@ -418,76 +413,6 @@ usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
418 413
419/*-------------------------------------------------------------------------*/ 414/*-------------------------------------------------------------------------*/
420 415
421static int
422ohci_omap_start (struct usb_hcd *hcd)
423{
424 struct omap_usb_config *config;
425 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
426 int ret;
427
428 if (!host_enabled)
429 return 0;
430 config = dev_get_platdata(hcd->self.controller);
431 if (config->otg || config->rwc) {
432 ohci->hc_control = OHCI_CTRL_RWC;
433 writel(OHCI_CTRL_RWC, &ohci->regs->control);
434 }
435
436 if ((ret = ohci_run (ohci)) < 0) {
437 dev_err(hcd->self.controller, "can't start\n");
438 ohci_stop (hcd);
439 return ret;
440 }
441 return 0;
442}
443
444/*-------------------------------------------------------------------------*/
445
446static const struct hc_driver ohci_omap_hc_driver = {
447 .description = hcd_name,
448 .product_desc = "OMAP OHCI",
449 .hcd_priv_size = sizeof(struct ohci_hcd),
450
451 /*
452 * generic hardware linkage
453 */
454 .irq = ohci_irq,
455 .flags = HCD_USB11 | HCD_MEMORY,
456
457 /*
458 * basic lifecycle operations
459 */
460 .reset = ohci_omap_init,
461 .start = ohci_omap_start,
462 .stop = ohci_omap_stop,
463 .shutdown = ohci_shutdown,
464
465 /*
466 * managing i/o requests and associated device resources
467 */
468 .urb_enqueue = ohci_urb_enqueue,
469 .urb_dequeue = ohci_urb_dequeue,
470 .endpoint_disable = ohci_endpoint_disable,
471
472 /*
473 * scheduling support
474 */
475 .get_frame_number = ohci_get_frame,
476
477 /*
478 * root hub support
479 */
480 .hub_status_data = ohci_hub_status_data,
481 .hub_control = ohci_hub_control,
482#ifdef CONFIG_PM
483 .bus_suspend = ohci_bus_suspend,
484 .bus_resume = ohci_bus_resume,
485#endif
486 .start_port_reset = ohci_start_port_reset,
487};
488
489/*-------------------------------------------------------------------------*/
490
491static int ohci_hcd_omap_drv_probe(struct platform_device *dev) 416static int ohci_hcd_omap_drv_probe(struct platform_device *dev)
492{ 417{
493 return usb_hcd_omap_probe(&ohci_omap_hc_driver, dev); 418 return usb_hcd_omap_probe(&ohci_omap_hc_driver, dev);
@@ -506,16 +431,23 @@ static int ohci_hcd_omap_drv_remove(struct platform_device *dev)
506 431
507#ifdef CONFIG_PM 432#ifdef CONFIG_PM
508 433
509static int ohci_omap_suspend(struct platform_device *dev, pm_message_t message) 434static int ohci_omap_suspend(struct platform_device *pdev, pm_message_t message)
510{ 435{
511 struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(dev)); 436 struct usb_hcd *hcd = platform_get_drvdata(pdev);
437 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
438 bool do_wakeup = device_may_wakeup(&pdev->dev);
439 int ret;
512 440
513 if (time_before(jiffies, ohci->next_statechange)) 441 if (time_before(jiffies, ohci->next_statechange))
514 msleep(5); 442 msleep(5);
515 ohci->next_statechange = jiffies; 443 ohci->next_statechange = jiffies;
516 444
445 ret = ohci_suspend(hcd, do_wakeup);
446 if (ret)
447 return ret;
448
517 omap_ohci_clock_power(0); 449 omap_ohci_clock_power(0);
518 return 0; 450 return ret;
519} 451}
520 452
521static int ohci_omap_resume(struct platform_device *dev) 453static int ohci_omap_resume(struct platform_device *dev)
@@ -553,4 +485,29 @@ static struct platform_driver ohci_hcd_omap_driver = {
553 }, 485 },
554}; 486};
555 487
488static const struct ohci_driver_overrides omap_overrides __initconst = {
489 .product_desc = "OMAP OHCI",
490 .reset = ohci_omap_reset
491};
492
493static int __init ohci_omap_init(void)
494{
495 if (usb_disabled())
496 return -ENODEV;
497
498 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
499
500 ohci_init_driver(&ohci_omap_hc_driver, &omap_overrides);
501 return platform_driver_register(&ohci_hcd_omap_driver);
502}
503module_init(ohci_omap_init);
504
505static void __exit ohci_omap_cleanup(void)
506{
507 platform_driver_unregister(&ohci_hcd_omap_driver);
508}
509module_exit(ohci_omap_cleanup);
510
511MODULE_DESCRIPTION(DRIVER_DESC);
556MODULE_ALIAS("platform:ohci"); 512MODULE_ALIAS("platform:ohci");
513MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c
index a09af26f69ed..21457417a856 100644
--- a/drivers/usb/host/ohci-omap3.c
+++ b/drivers/usb/host/ohci-omap3.c
@@ -29,90 +29,22 @@
29 * - add kernel-doc 29 * - add kernel-doc
30 */ 30 */
31 31
32#include <linux/dma-mapping.h>
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/of.h>
36#include <linux/usb/otg.h>
32#include <linux/platform_device.h> 37#include <linux/platform_device.h>
33#include <linux/pm_runtime.h> 38#include <linux/pm_runtime.h>
34#include <linux/of.h> 39#include <linux/usb.h>
35#include <linux/dma-mapping.h> 40#include <linux/usb/hcd.h>
36
37/*-------------------------------------------------------------------------*/
38
39static int ohci_omap3_init(struct usb_hcd *hcd)
40{
41 dev_dbg(hcd->self.controller, "starting OHCI controller\n");
42
43 return ohci_init(hcd_to_ohci(hcd));
44}
45
46/*-------------------------------------------------------------------------*/
47
48static int ohci_omap3_start(struct usb_hcd *hcd)
49{
50 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
51 int ret;
52
53 /*
54 * RemoteWakeupConnected has to be set explicitly before
55 * calling ohci_run. The reset value of RWC is 0.
56 */
57 ohci->hc_control = OHCI_CTRL_RWC;
58 writel(OHCI_CTRL_RWC, &ohci->regs->control);
59
60 ret = ohci_run(ohci);
61
62 if (ret < 0) {
63 dev_err(hcd->self.controller, "can't start\n");
64 ohci_stop(hcd);
65 }
66
67 return ret;
68}
69
70/*-------------------------------------------------------------------------*/
71
72static const struct hc_driver ohci_omap3_hc_driver = {
73 .description = hcd_name,
74 .product_desc = "OMAP3 OHCI Host Controller",
75 .hcd_priv_size = sizeof(struct ohci_hcd),
76
77 /*
78 * generic hardware linkage
79 */
80 .irq = ohci_irq,
81 .flags = HCD_USB11 | HCD_MEMORY,
82
83 /*
84 * basic lifecycle operations
85 */
86 .reset = ohci_omap3_init,
87 .start = ohci_omap3_start,
88 .stop = ohci_stop,
89 .shutdown = ohci_shutdown,
90
91 /*
92 * managing i/o requests and associated device resources
93 */
94 .urb_enqueue = ohci_urb_enqueue,
95 .urb_dequeue = ohci_urb_dequeue,
96 .endpoint_disable = ohci_endpoint_disable,
97 41
98 /* 42#include "ohci.h"
99 * scheduling support
100 */
101 .get_frame_number = ohci_get_frame,
102 43
103 /* 44#define DRIVER_DESC "OHCI OMAP3 driver"
104 * root hub support
105 */
106 .hub_status_data = ohci_hub_status_data,
107 .hub_control = ohci_hub_control,
108#ifdef CONFIG_PM
109 .bus_suspend = ohci_bus_suspend,
110 .bus_resume = ohci_bus_resume,
111#endif
112 .start_port_reset = ohci_start_port_reset,
113};
114 45
115/*-------------------------------------------------------------------------*/ 46static const char hcd_name[] = "ohci-omap3";
47static struct hc_driver __read_mostly ohci_omap3_hc_driver;
116 48
117/* 49/*
118 * configure so an HC device and id are always provided 50 * configure so an HC device and id are always provided
@@ -129,10 +61,11 @@ static const struct hc_driver ohci_omap3_hc_driver = {
129static int ohci_hcd_omap3_probe(struct platform_device *pdev) 61static int ohci_hcd_omap3_probe(struct platform_device *pdev)
130{ 62{
131 struct device *dev = &pdev->dev; 63 struct device *dev = &pdev->dev;
64 struct ohci_hcd *ohci;
132 struct usb_hcd *hcd = NULL; 65 struct usb_hcd *hcd = NULL;
133 void __iomem *regs = NULL; 66 void __iomem *regs = NULL;
134 struct resource *res; 67 struct resource *res;
135 int ret = -ENODEV; 68 int ret;
136 int irq; 69 int irq;
137 70
138 if (usb_disabled()) 71 if (usb_disabled())
@@ -166,11 +99,11 @@ static int ohci_hcd_omap3_probe(struct platform_device *pdev)
166 * Since shared usb code relies on it, set it here for now. 99 * Since shared usb code relies on it, set it here for now.
167 * Once we have dma capability bindings this can go away. 100 * Once we have dma capability bindings this can go away.
168 */ 101 */
169 if (!dev->dma_mask) 102 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
170 dev->dma_mask = &dev->coherent_dma_mask; 103 if (ret)
171 if (!dev->coherent_dma_mask) 104 goto err_io;
172 dev->coherent_dma_mask = DMA_BIT_MASK(32);
173 105
106 ret = -ENODEV;
174 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev, 107 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
175 dev_name(dev)); 108 dev_name(dev));
176 if (!hcd) { 109 if (!hcd) {
@@ -185,7 +118,12 @@ static int ohci_hcd_omap3_probe(struct platform_device *pdev)
185 pm_runtime_enable(dev); 118 pm_runtime_enable(dev);
186 pm_runtime_get_sync(dev); 119 pm_runtime_get_sync(dev);
187 120
188 ohci_hcd_init(hcd_to_ohci(hcd)); 121 ohci = hcd_to_ohci(hcd);
122 /*
123 * RemoteWakeupConnected has to be set explicitly before
124 * calling ohci_run. The reset value of RWC is 0.
125 */
126 ohci->hc_control = OHCI_CTRL_RWC;
189 127
190 ret = usb_add_hcd(hcd, irq, 0); 128 ret = usb_add_hcd(hcd, irq, 0);
191 if (ret) { 129 if (ret) {
@@ -248,5 +186,25 @@ static struct platform_driver ohci_hcd_omap3_driver = {
248 }, 186 },
249}; 187};
250 188
189static int __init ohci_omap3_init(void)
190{
191 if (usb_disabled())
192 return -ENODEV;
193
194 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
195
196 ohci_init_driver(&ohci_omap3_hc_driver, NULL);
197 return platform_driver_register(&ohci_hcd_omap3_driver);
198}
199module_init(ohci_omap3_init);
200
201static void __exit ohci_omap3_cleanup(void)
202{
203 platform_driver_unregister(&ohci_hcd_omap3_driver);
204}
205module_exit(ohci_omap3_cleanup);
206
207MODULE_DESCRIPTION(DRIVER_DESC);
251MODULE_ALIAS("platform:ohci-omap3"); 208MODULE_ALIAS("platform:ohci-omap3");
252MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>"); 209MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");
210MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index ec337c2bd5e0..90879e9ccbec 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -150,28 +150,16 @@ static int ohci_quirk_nec(struct usb_hcd *hcd)
150static int ohci_quirk_amd700(struct usb_hcd *hcd) 150static int ohci_quirk_amd700(struct usb_hcd *hcd)
151{ 151{
152 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 152 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
153 struct pci_dev *amd_smbus_dev;
154 u8 rev;
155 153
156 if (usb_amd_find_chipset_info()) 154 if (usb_amd_find_chipset_info())
157 ohci->flags |= OHCI_QUIRK_AMD_PLL; 155 ohci->flags |= OHCI_QUIRK_AMD_PLL;
158 156
159 amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI,
160 PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL);
161 if (!amd_smbus_dev)
162 return 0;
163
164 rev = amd_smbus_dev->revision;
165
166 /* SB800 needs pre-fetch fix */ 157 /* SB800 needs pre-fetch fix */
167 if ((rev >= 0x40) && (rev <= 0x4f)) { 158 if (usb_amd_prefetch_quirk()) {
168 ohci->flags |= OHCI_QUIRK_AMD_PREFETCH; 159 ohci->flags |= OHCI_QUIRK_AMD_PREFETCH;
169 ohci_dbg(ohci, "enabled AMD prefetch quirk\n"); 160 ohci_dbg(ohci, "enabled AMD prefetch quirk\n");
170 } 161 }
171 162
172 pci_dev_put(amd_smbus_dev);
173 amd_smbus_dev = NULL;
174
175 return 0; 163 return 0;
176} 164}
177 165
@@ -323,3 +311,4 @@ module_exit(ohci_pci_cleanup);
323 311
324MODULE_DESCRIPTION(DRIVER_DESC); 312MODULE_DESCRIPTION(DRIVER_DESC);
325MODULE_LICENSE("GPL"); 313MODULE_LICENSE("GPL");
314MODULE_SOFTDEP("pre: ehci_pci");
diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
index a4c6410f0ed4..f351ff5b171f 100644
--- a/drivers/usb/host/ohci-platform.c
+++ b/drivers/usb/host/ohci-platform.c
@@ -139,14 +139,21 @@ 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_get_platdata(dev); 142 struct usb_hcd *hcd = dev_get_drvdata(dev);
143 struct usb_ohci_pdata *pdata = dev->platform_data;
143 struct platform_device *pdev = 144 struct platform_device *pdev =
144 container_of(dev, struct platform_device, dev); 145 container_of(dev, struct platform_device, dev);
146 bool do_wakeup = device_may_wakeup(dev);
147 int ret;
148
149 ret = ohci_suspend(hcd, do_wakeup);
150 if (ret)
151 return ret;
145 152
146 if (pdata->power_suspend) 153 if (pdata->power_suspend)
147 pdata->power_suspend(pdev); 154 pdata->power_suspend(pdev);
148 155
149 return 0; 156 return ret;
150} 157}
151 158
152static int ohci_platform_resume(struct device *dev) 159static int ohci_platform_resume(struct device *dev)
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index 75f5a1e2f01e..81f3eba215c1 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -14,6 +14,8 @@
14 */ 14 */
15 15
16#include <linux/signal.h> 16#include <linux/signal.h>
17#include <linux/of_address.h>
18#include <linux/of_irq.h>
17#include <linux/of_platform.h> 19#include <linux/of_platform.h>
18 20
19#include <asm/prom.h> 21#include <asm/prom.h>
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index 93371a235e82..e89ac4d4b87e 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -19,15 +19,26 @@
19 * This file is licenced under the GPL. 19 * This file is licenced under the GPL.
20 */ 20 */
21 21
22#include <linux/device.h>
23#include <linux/signal.h>
24#include <linux/platform_device.h>
25#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/device.h>
24#include <linux/io.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
26#include <linux/of_platform.h> 27#include <linux/of_platform.h>
27#include <linux/of_gpio.h> 28#include <linux/of_gpio.h>
28#include <mach/hardware.h>
29#include <linux/platform_data/usb-ohci-pxa27x.h> 29#include <linux/platform_data/usb-ohci-pxa27x.h>
30#include <linux/platform_data/usb-pxa3xx-ulpi.h> 30#include <linux/platform_data/usb-pxa3xx-ulpi.h>
31#include <linux/platform_device.h>
32#include <linux/signal.h>
33#include <linux/usb.h>
34#include <linux/usb/hcd.h>
35#include <linux/usb/otg.h>
36
37#include <mach/hardware.h>
38
39#include "ohci.h"
40
41#define DRIVER_DESC "OHCI PXA27x/PXA3x driver"
31 42
32/* 43/*
33 * UHC: USB Host Controller (OHCI-like) register definitions 44 * UHC: USB Host Controller (OHCI-like) register definitions
@@ -101,16 +112,16 @@
101 112
102#define PXA_UHC_MAX_PORTNUM 3 113#define PXA_UHC_MAX_PORTNUM 3
103 114
104struct pxa27x_ohci { 115static const char hcd_name[] = "ohci-pxa27x";
105 /* must be 1st member here for hcd_to_ohci() to work */
106 struct ohci_hcd ohci;
107 116
108 struct device *dev; 117static struct hc_driver __read_mostly ohci_pxa27x_hc_driver;
118
119struct pxa27x_ohci {
109 struct clk *clk; 120 struct clk *clk;
110 void __iomem *mmio_base; 121 void __iomem *mmio_base;
111}; 122};
112 123
113#define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)hcd_to_ohci(hcd) 124#define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)(hcd_to_ohci(hcd)->priv)
114 125
115/* 126/*
116 PMM_NPS_MODE -- PMM Non-power switching mode 127 PMM_NPS_MODE -- PMM Non-power switching mode
@@ -122,10 +133,10 @@ struct pxa27x_ohci {
122 PMM_PERPORT_MODE -- PMM per port switching mode 133 PMM_PERPORT_MODE -- PMM per port switching mode
123 Ports are powered individually. 134 Ports are powered individually.
124 */ 135 */
125static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *ohci, int mode) 136static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *pxa_ohci, int mode)
126{ 137{
127 uint32_t uhcrhda = __raw_readl(ohci->mmio_base + UHCRHDA); 138 uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA);
128 uint32_t uhcrhdb = __raw_readl(ohci->mmio_base + UHCRHDB); 139 uint32_t uhcrhdb = __raw_readl(pxa_ohci->mmio_base + UHCRHDB);
129 140
130 switch (mode) { 141 switch (mode) {
131 case PMM_NPS_MODE: 142 case PMM_NPS_MODE:
@@ -149,20 +160,18 @@ static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *ohci, int mode)
149 uhcrhda |= RH_A_NPS; 160 uhcrhda |= RH_A_NPS;
150 } 161 }
151 162
152 __raw_writel(uhcrhda, ohci->mmio_base + UHCRHDA); 163 __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA);
153 __raw_writel(uhcrhdb, ohci->mmio_base + UHCRHDB); 164 __raw_writel(uhcrhdb, pxa_ohci->mmio_base + UHCRHDB);
154 return 0; 165 return 0;
155} 166}
156 167
157extern int usb_disabled(void);
158
159/*-------------------------------------------------------------------------*/ 168/*-------------------------------------------------------------------------*/
160 169
161static inline void pxa27x_setup_hc(struct pxa27x_ohci *ohci, 170static inline void pxa27x_setup_hc(struct pxa27x_ohci *pxa_ohci,
162 struct pxaohci_platform_data *inf) 171 struct pxaohci_platform_data *inf)
163{ 172{
164 uint32_t uhchr = __raw_readl(ohci->mmio_base + UHCHR); 173 uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR);
165 uint32_t uhcrhda = __raw_readl(ohci->mmio_base + UHCRHDA); 174 uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA);
166 175
167 if (inf->flags & ENABLE_PORT1) 176 if (inf->flags & ENABLE_PORT1)
168 uhchr &= ~UHCHR_SSEP1; 177 uhchr &= ~UHCHR_SSEP1;
@@ -194,17 +203,17 @@ static inline void pxa27x_setup_hc(struct pxa27x_ohci *ohci,
194 uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2); 203 uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2);
195 } 204 }
196 205
197 __raw_writel(uhchr, ohci->mmio_base + UHCHR); 206 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR);
198 __raw_writel(uhcrhda, ohci->mmio_base + UHCRHDA); 207 __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA);
199} 208}
200 209
201static inline void pxa27x_reset_hc(struct pxa27x_ohci *ohci) 210static inline void pxa27x_reset_hc(struct pxa27x_ohci *pxa_ohci)
202{ 211{
203 uint32_t uhchr = __raw_readl(ohci->mmio_base + UHCHR); 212 uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR);
204 213
205 __raw_writel(uhchr | UHCHR_FHR, ohci->mmio_base + UHCHR); 214 __raw_writel(uhchr | UHCHR_FHR, pxa_ohci->mmio_base + UHCHR);
206 udelay(11); 215 udelay(11);
207 __raw_writel(uhchr & ~UHCHR_FHR, ohci->mmio_base + UHCHR); 216 __raw_writel(uhchr & ~UHCHR_FHR, pxa_ohci->mmio_base + UHCHR);
208} 217}
209 218
210#ifdef CONFIG_PXA27x 219#ifdef CONFIG_PXA27x
@@ -213,25 +222,26 @@ extern void pxa27x_clear_otgph(void);
213#define pxa27x_clear_otgph() do {} while (0) 222#define pxa27x_clear_otgph() do {} while (0)
214#endif 223#endif
215 224
216static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev) 225static int pxa27x_start_hc(struct pxa27x_ohci *pxa_ohci, struct device *dev)
217{ 226{
218 int retval = 0; 227 int retval = 0;
219 struct pxaohci_platform_data *inf; 228 struct pxaohci_platform_data *inf;
220 uint32_t uhchr; 229 uint32_t uhchr;
230 struct usb_hcd *hcd = dev_get_drvdata(dev);
221 231
222 inf = dev_get_platdata(dev); 232 inf = dev_get_platdata(dev);
223 233
224 clk_prepare_enable(ohci->clk); 234 clk_prepare_enable(pxa_ohci->clk);
225 235
226 pxa27x_reset_hc(ohci); 236 pxa27x_reset_hc(pxa_ohci);
227 237
228 uhchr = __raw_readl(ohci->mmio_base + UHCHR) | UHCHR_FSBIR; 238 uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) | UHCHR_FSBIR;
229 __raw_writel(uhchr, ohci->mmio_base + UHCHR); 239 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR);
230 240
231 while (__raw_readl(ohci->mmio_base + UHCHR) & UHCHR_FSBIR) 241 while (__raw_readl(pxa_ohci->mmio_base + UHCHR) & UHCHR_FSBIR)
232 cpu_relax(); 242 cpu_relax();
233 243
234 pxa27x_setup_hc(ohci, inf); 244 pxa27x_setup_hc(pxa_ohci, inf);
235 245
236 if (inf->init) 246 if (inf->init)
237 retval = inf->init(dev); 247 retval = inf->init(dev);
@@ -240,38 +250,39 @@ static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev)
240 return retval; 250 return retval;
241 251
242 if (cpu_is_pxa3xx()) 252 if (cpu_is_pxa3xx())
243 pxa3xx_u2d_start_hc(&ohci_to_hcd(&ohci->ohci)->self); 253 pxa3xx_u2d_start_hc(&hcd->self);
244 254
245 uhchr = __raw_readl(ohci->mmio_base + UHCHR) & ~UHCHR_SSE; 255 uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) & ~UHCHR_SSE;
246 __raw_writel(uhchr, ohci->mmio_base + UHCHR); 256 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR);
247 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, ohci->mmio_base + UHCHIE); 257 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, pxa_ohci->mmio_base + UHCHIE);
248 258
249 /* Clear any OTG Pin Hold */ 259 /* Clear any OTG Pin Hold */
250 pxa27x_clear_otgph(); 260 pxa27x_clear_otgph();
251 return 0; 261 return 0;
252} 262}
253 263
254static void pxa27x_stop_hc(struct pxa27x_ohci *ohci, struct device *dev) 264static void pxa27x_stop_hc(struct pxa27x_ohci *pxa_ohci, struct device *dev)
255{ 265{
256 struct pxaohci_platform_data *inf; 266 struct pxaohci_platform_data *inf;
267 struct usb_hcd *hcd = dev_get_drvdata(dev);
257 uint32_t uhccoms; 268 uint32_t uhccoms;
258 269
259 inf = dev_get_platdata(dev); 270 inf = dev_get_platdata(dev);
260 271
261 if (cpu_is_pxa3xx()) 272 if (cpu_is_pxa3xx())
262 pxa3xx_u2d_stop_hc(&ohci_to_hcd(&ohci->ohci)->self); 273 pxa3xx_u2d_stop_hc(&hcd->self);
263 274
264 if (inf->exit) 275 if (inf->exit)
265 inf->exit(dev); 276 inf->exit(dev);
266 277
267 pxa27x_reset_hc(ohci); 278 pxa27x_reset_hc(pxa_ohci);
268 279
269 /* Host Controller Reset */ 280 /* Host Controller Reset */
270 uhccoms = __raw_readl(ohci->mmio_base + UHCCOMS) | 0x01; 281 uhccoms = __raw_readl(pxa_ohci->mmio_base + UHCCOMS) | 0x01;
271 __raw_writel(uhccoms, ohci->mmio_base + UHCCOMS); 282 __raw_writel(uhccoms, pxa_ohci->mmio_base + UHCCOMS);
272 udelay(10); 283 udelay(10);
273 284
274 clk_disable_unprepare(ohci->clk); 285 clk_disable_unprepare(pxa_ohci->clk);
275} 286}
276 287
277#ifdef CONFIG_OF 288#ifdef CONFIG_OF
@@ -287,6 +298,7 @@ static int ohci_pxa_of_init(struct platform_device *pdev)
287 struct device_node *np = pdev->dev.of_node; 298 struct device_node *np = pdev->dev.of_node;
288 struct pxaohci_platform_data *pdata; 299 struct pxaohci_platform_data *pdata;
289 u32 tmp; 300 u32 tmp;
301 int ret;
290 302
291 if (!np) 303 if (!np)
292 return 0; 304 return 0;
@@ -295,10 +307,9 @@ static int ohci_pxa_of_init(struct platform_device *pdev)
295 * Since shared usb code relies on it, set it here for now. 307 * Since shared usb code relies on it, set it here for now.
296 * Once we have dma capability bindings this can go away. 308 * Once we have dma capability bindings this can go away.
297 */ 309 */
298 if (!pdev->dev.dma_mask) 310 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
299 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 311 if (ret)
300 if (!pdev->dev.coherent_dma_mask) 312 return ret;
301 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
302 313
303 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 314 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
304 if (!pdata) 315 if (!pdata)
@@ -356,7 +367,8 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
356 int retval, irq; 367 int retval, irq;
357 struct usb_hcd *hcd; 368 struct usb_hcd *hcd;
358 struct pxaohci_platform_data *inf; 369 struct pxaohci_platform_data *inf;
359 struct pxa27x_ohci *ohci; 370 struct pxa27x_ohci *pxa_ohci;
371 struct ohci_hcd *ohci;
360 struct resource *r; 372 struct resource *r;
361 struct clk *usb_clk; 373 struct clk *usb_clk;
362 374
@@ -409,29 +421,31 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
409 } 421 }
410 422
411 /* initialize "struct pxa27x_ohci" */ 423 /* initialize "struct pxa27x_ohci" */
412 ohci = (struct pxa27x_ohci *)hcd_to_ohci(hcd); 424 pxa_ohci = to_pxa27x_ohci(hcd);
413 ohci->dev = &pdev->dev; 425 pxa_ohci->clk = usb_clk;
414 ohci->clk = usb_clk; 426 pxa_ohci->mmio_base = (void __iomem *)hcd->regs;
415 ohci->mmio_base = (void __iomem *)hcd->regs;
416 427
417 if ((retval = pxa27x_start_hc(ohci, &pdev->dev)) < 0) { 428 retval = pxa27x_start_hc(pxa_ohci, &pdev->dev);
429 if (retval < 0) {
418 pr_debug("pxa27x_start_hc failed"); 430 pr_debug("pxa27x_start_hc failed");
419 goto err3; 431 goto err3;
420 } 432 }
421 433
422 /* Select Power Management Mode */ 434 /* Select Power Management Mode */
423 pxa27x_ohci_select_pmm(ohci, inf->port_mode); 435 pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode);
424 436
425 if (inf->power_budget) 437 if (inf->power_budget)
426 hcd->power_budget = inf->power_budget; 438 hcd->power_budget = inf->power_budget;
427 439
428 ohci_hcd_init(hcd_to_ohci(hcd)); 440 /* The value of NDP in roothub_a is incorrect on this hardware */
441 ohci = hcd_to_ohci(hcd);
442 ohci->num_ports = 3;
429 443
430 retval = usb_add_hcd(hcd, irq, 0); 444 retval = usb_add_hcd(hcd, irq, 0);
431 if (retval == 0) 445 if (retval == 0)
432 return retval; 446 return retval;
433 447
434 pxa27x_stop_hc(ohci, &pdev->dev); 448 pxa27x_stop_hc(pxa_ohci, &pdev->dev);
435 err3: 449 err3:
436 iounmap(hcd->regs); 450 iounmap(hcd->regs);
437 err2: 451 err2:
@@ -459,88 +473,18 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
459 */ 473 */
460void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev) 474void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
461{ 475{
462 struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); 476 struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd);
463 477
464 usb_remove_hcd(hcd); 478 usb_remove_hcd(hcd);
465 pxa27x_stop_hc(ohci, &pdev->dev); 479 pxa27x_stop_hc(pxa_ohci, &pdev->dev);
466 iounmap(hcd->regs); 480 iounmap(hcd->regs);
467 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 481 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
482 clk_put(pxa_ohci->clk);
468 usb_put_hcd(hcd); 483 usb_put_hcd(hcd);
469 clk_put(ohci->clk);
470} 484}
471 485
472/*-------------------------------------------------------------------------*/ 486/*-------------------------------------------------------------------------*/
473 487
474static int
475ohci_pxa27x_start (struct usb_hcd *hcd)
476{
477 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
478 int ret;
479
480 ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
481
482 /* The value of NDP in roothub_a is incorrect on this hardware */
483 ohci->num_ports = 3;
484
485 if ((ret = ohci_init(ohci)) < 0)
486 return ret;
487
488 if ((ret = ohci_run (ohci)) < 0) {
489 dev_err(hcd->self.controller, "can't start %s",
490 hcd->self.bus_name);
491 ohci_stop (hcd);
492 return ret;
493 }
494
495 return 0;
496}
497
498/*-------------------------------------------------------------------------*/
499
500static const struct hc_driver ohci_pxa27x_hc_driver = {
501 .description = hcd_name,
502 .product_desc = "PXA27x OHCI",
503 .hcd_priv_size = sizeof(struct pxa27x_ohci),
504
505 /*
506 * generic hardware linkage
507 */
508 .irq = ohci_irq,
509 .flags = HCD_USB11 | HCD_MEMORY,
510
511 /*
512 * basic lifecycle operations
513 */
514 .start = ohci_pxa27x_start,
515 .stop = ohci_stop,
516 .shutdown = ohci_shutdown,
517
518 /*
519 * managing i/o requests and associated device resources
520 */
521 .urb_enqueue = ohci_urb_enqueue,
522 .urb_dequeue = ohci_urb_dequeue,
523 .endpoint_disable = ohci_endpoint_disable,
524
525 /*
526 * scheduling support
527 */
528 .get_frame_number = ohci_get_frame,
529
530 /*
531 * root hub support
532 */
533 .hub_status_data = ohci_hub_status_data,
534 .hub_control = ohci_hub_control,
535#ifdef CONFIG_PM
536 .bus_suspend = ohci_bus_suspend,
537 .bus_resume = ohci_bus_resume,
538#endif
539 .start_port_reset = ohci_start_port_reset,
540};
541
542/*-------------------------------------------------------------------------*/
543
544static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev) 488static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
545{ 489{
546 pr_debug ("In ohci_hcd_pxa27x_drv_probe"); 490 pr_debug ("In ohci_hcd_pxa27x_drv_probe");
@@ -563,32 +507,42 @@ static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
563static int ohci_hcd_pxa27x_drv_suspend(struct device *dev) 507static int ohci_hcd_pxa27x_drv_suspend(struct device *dev)
564{ 508{
565 struct usb_hcd *hcd = dev_get_drvdata(dev); 509 struct usb_hcd *hcd = dev_get_drvdata(dev);
566 struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); 510 struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd);
511 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
512 bool do_wakeup = device_may_wakeup(dev);
513 int ret;
514
567 515
568 if (time_before(jiffies, ohci->ohci.next_statechange)) 516 if (time_before(jiffies, ohci->next_statechange))
569 msleep(5); 517 msleep(5);
570 ohci->ohci.next_statechange = jiffies; 518 ohci->next_statechange = jiffies;
571 519
572 pxa27x_stop_hc(ohci, dev); 520 ret = ohci_suspend(hcd, do_wakeup);
573 return 0; 521 if (ret)
522 return ret;
523
524 pxa27x_stop_hc(pxa_ohci, dev);
525 return ret;
574} 526}
575 527
576static int ohci_hcd_pxa27x_drv_resume(struct device *dev) 528static int ohci_hcd_pxa27x_drv_resume(struct device *dev)
577{ 529{
578 struct usb_hcd *hcd = dev_get_drvdata(dev); 530 struct usb_hcd *hcd = dev_get_drvdata(dev);
579 struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); 531 struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd);
580 struct pxaohci_platform_data *inf = dev_get_platdata(dev); 532 struct pxaohci_platform_data *inf = dev_get_platdata(dev);
533 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
581 int status; 534 int status;
582 535
583 if (time_before(jiffies, ohci->ohci.next_statechange)) 536 if (time_before(jiffies, ohci->next_statechange))
584 msleep(5); 537 msleep(5);
585 ohci->ohci.next_statechange = jiffies; 538 ohci->next_statechange = jiffies;
586 539
587 if ((status = pxa27x_start_hc(ohci, dev)) < 0) 540 status = pxa27x_start_hc(pxa_ohci, dev);
541 if (status < 0)
588 return status; 542 return status;
589 543
590 /* Select Power Management Mode */ 544 /* Select Power Management Mode */
591 pxa27x_ohci_select_pmm(ohci, inf->port_mode); 545 pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode);
592 546
593 ohci_resume(hcd, false); 547 ohci_resume(hcd, false);
594 return 0; 548 return 0;
@@ -600,9 +554,6 @@ static const struct dev_pm_ops ohci_hcd_pxa27x_pm_ops = {
600}; 554};
601#endif 555#endif
602 556
603/* work with hotplug and coldplug */
604MODULE_ALIAS("platform:pxa27x-ohci");
605
606static struct platform_driver ohci_hcd_pxa27x_driver = { 557static struct platform_driver ohci_hcd_pxa27x_driver = {
607 .probe = ohci_hcd_pxa27x_drv_probe, 558 .probe = ohci_hcd_pxa27x_drv_probe,
608 .remove = ohci_hcd_pxa27x_drv_remove, 559 .remove = ohci_hcd_pxa27x_drv_remove,
@@ -617,3 +568,27 @@ static struct platform_driver ohci_hcd_pxa27x_driver = {
617 }, 568 },
618}; 569};
619 570
571static const struct ohci_driver_overrides pxa27x_overrides __initconst = {
572 .extra_priv_size = sizeof(struct pxa27x_ohci),
573};
574
575static int __init ohci_pxa27x_init(void)
576{
577 if (usb_disabled())
578 return -ENODEV;
579
580 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
581 ohci_init_driver(&ohci_pxa27x_hc_driver, &pxa27x_overrides);
582 return platform_driver_register(&ohci_hcd_pxa27x_driver);
583}
584module_init(ohci_pxa27x_init);
585
586static void __exit ohci_pxa27x_cleanup(void)
587{
588 platform_driver_unregister(&ohci_hcd_pxa27x_driver);
589}
590module_exit(ohci_pxa27x_cleanup);
591
592MODULE_DESCRIPTION(DRIVER_DESC);
593MODULE_LICENSE("GPL");
594MODULE_ALIAS("platform:pxa27x-ohci");
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index df4a6707322d..e7f577e63624 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -41,9 +41,13 @@ finish_urb(struct ohci_hcd *ohci, struct urb *urb, int status)
41__releases(ohci->lock) 41__releases(ohci->lock)
42__acquires(ohci->lock) 42__acquires(ohci->lock)
43{ 43{
44 struct device *dev = ohci_to_hcd(ohci)->self.controller; 44 struct device *dev = ohci_to_hcd(ohci)->self.controller;
45 struct usb_host_endpoint *ep = urb->ep;
46 struct urb_priv *urb_priv;
47
45 // ASSERT (urb->hcpriv != 0); 48 // ASSERT (urb->hcpriv != 0);
46 49
50 restart:
47 urb_free_priv (ohci, urb->hcpriv); 51 urb_free_priv (ohci, urb->hcpriv);
48 urb->hcpriv = NULL; 52 urb->hcpriv = NULL;
49 if (likely(status == -EINPROGRESS)) 53 if (likely(status == -EINPROGRESS))
@@ -80,6 +84,21 @@ __acquires(ohci->lock)
80 ohci->hc_control &= ~(OHCI_CTRL_PLE|OHCI_CTRL_IE); 84 ohci->hc_control &= ~(OHCI_CTRL_PLE|OHCI_CTRL_IE);
81 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 85 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
82 } 86 }
87
88 /*
89 * An isochronous URB that is sumitted too late won't have any TDs
90 * (marked by the fact that the td_cnt value is larger than the
91 * actual number of TDs). If the next URB on this endpoint is like
92 * that, give it back now.
93 */
94 if (!list_empty(&ep->urb_list)) {
95 urb = list_first_entry(&ep->urb_list, struct urb, urb_list);
96 urb_priv = urb->hcpriv;
97 if (urb_priv->td_cnt > urb_priv->length) {
98 status = 0;
99 goto restart;
100 }
101 }
83} 102}
84 103
85 104
@@ -546,7 +565,6 @@ td_fill (struct ohci_hcd *ohci, u32 info,
546 td->hwCBP = cpu_to_hc32 (ohci, data & 0xFFFFF000); 565 td->hwCBP = cpu_to_hc32 (ohci, data & 0xFFFFF000);
547 *ohci_hwPSWp(ohci, td, 0) = cpu_to_hc16 (ohci, 566 *ohci_hwPSWp(ohci, td, 0) = cpu_to_hc16 (ohci,
548 (data & 0x0FFF) | 0xE000); 567 (data & 0x0FFF) | 0xE000);
549 td->ed->last_iso = info & 0xffff;
550 } else { 568 } else {
551 td->hwCBP = cpu_to_hc32 (ohci, data); 569 td->hwCBP = cpu_to_hc32 (ohci, data);
552 } 570 }
@@ -996,7 +1014,7 @@ rescan_this:
996 urb_priv->td_cnt++; 1014 urb_priv->td_cnt++;
997 1015
998 /* if URB is done, clean up */ 1016 /* if URB is done, clean up */
999 if (urb_priv->td_cnt == urb_priv->length) { 1017 if (urb_priv->td_cnt >= urb_priv->length) {
1000 modified = completed = 1; 1018 modified = completed = 1;
1001 finish_urb(ohci, urb, 0); 1019 finish_urb(ohci, urb, 0);
1002 } 1020 }
@@ -1086,7 +1104,7 @@ static void takeback_td(struct ohci_hcd *ohci, struct td *td)
1086 urb_priv->td_cnt++; 1104 urb_priv->td_cnt++;
1087 1105
1088 /* If all this urb's TDs are done, call complete() */ 1106 /* If all this urb's TDs are done, call complete() */
1089 if (urb_priv->td_cnt == urb_priv->length) 1107 if (urb_priv->td_cnt >= urb_priv->length)
1090 finish_urb(ohci, urb, status); 1108 finish_urb(ohci, urb, status);
1091 1109
1092 /* clean schedule: unlink EDs that are no longer busy */ 1110 /* clean schedule: unlink EDs that are no longer busy */
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index 4919afa4125e..f90101b9cdb9 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -19,19 +19,36 @@
19 * This file is licenced under the GPL. 19 * This file is licenced under the GPL.
20*/ 20*/
21 21
22#include <linux/platform_device.h>
23#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/io.h>
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
24#include <linux/platform_data/usb-ohci-s3c2410.h> 27#include <linux/platform_data/usb-ohci-s3c2410.h>
28#include <linux/usb.h>
29#include <linux/usb/hcd.h>
30
31#include "ohci.h"
32
25 33
26#define valid_port(idx) ((idx) == 1 || (idx) == 2) 34#define valid_port(idx) ((idx) == 1 || (idx) == 2)
27 35
28/* clock device associated with the hcd */ 36/* clock device associated with the hcd */
29 37
38
39#define DRIVER_DESC "OHCI S3C2410 driver"
40
41static const char hcd_name[] = "ohci-s3c2410";
42
30static struct clk *clk; 43static struct clk *clk;
31static struct clk *usb_clk; 44static struct clk *usb_clk;
32 45
33/* forward definitions */ 46/* forward definitions */
34 47
48static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq,
49 u16 wValue, u16 wIndex, char *buf, u16 wLength);
50static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
51
35static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc); 52static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
36 53
37/* conversion functions */ 54/* conversion functions */
@@ -47,10 +64,10 @@ static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
47 64
48 dev_dbg(&dev->dev, "s3c2410_start_hc:\n"); 65 dev_dbg(&dev->dev, "s3c2410_start_hc:\n");
49 66
50 clk_enable(usb_clk); 67 clk_prepare_enable(usb_clk);
51 mdelay(2); /* let the bus clock stabilise */ 68 mdelay(2); /* let the bus clock stabilise */
52 69
53 clk_enable(clk); 70 clk_prepare_enable(clk);
54 71
55 if (info != NULL) { 72 if (info != NULL) {
56 info->hcd = hcd; 73 info->hcd = hcd;
@@ -75,8 +92,8 @@ static void s3c2410_stop_hc(struct platform_device *dev)
75 (info->enable_oc)(info, 0); 92 (info->enable_oc)(info, 0);
76 } 93 }
77 94
78 clk_disable(clk); 95 clk_disable_unprepare(clk);
79 clk_disable(usb_clk); 96 clk_disable_unprepare(usb_clk);
80} 97}
81 98
82/* ohci_s3c2410_hub_status_data 99/* ohci_s3c2410_hub_status_data
@@ -93,7 +110,7 @@ ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf)
93 int orig; 110 int orig;
94 int portno; 111 int portno;
95 112
96 orig = ohci_hub_status_data(hcd, buf); 113 orig = orig_ohci_hub_status_data(hcd, buf);
97 114
98 if (info == NULL) 115 if (info == NULL)
99 return orig; 116 return orig;
@@ -164,7 +181,7 @@ static int ohci_s3c2410_hub_control(
164 * process the request straight away and exit */ 181 * process the request straight away and exit */
165 182
166 if (info == NULL) { 183 if (info == NULL) {
167 ret = ohci_hub_control(hcd, typeReq, wValue, 184 ret = orig_ohci_hub_control(hcd, typeReq, wValue,
168 wIndex, buf, wLength); 185 wIndex, buf, wLength);
169 goto out; 186 goto out;
170 } 187 }
@@ -214,7 +231,7 @@ static int ohci_s3c2410_hub_control(
214 break; 231 break;
215 } 232 }
216 233
217 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); 234 ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
218 if (ret) 235 if (ret)
219 goto out; 236 goto out;
220 237
@@ -374,8 +391,6 @@ static int usb_hcd_s3c2410_probe(const struct hc_driver *driver,
374 391
375 s3c2410_start_hc(dev, hcd); 392 s3c2410_start_hc(dev, hcd);
376 393
377 ohci_hcd_init(hcd_to_ohci(hcd));
378
379 retval = usb_add_hcd(hcd, dev->resource[1].start, 0); 394 retval = usb_add_hcd(hcd, dev->resource[1].start, 0);
380 if (retval != 0) 395 if (retval != 0)
381 goto err_ioremap; 396 goto err_ioremap;
@@ -392,71 +407,7 @@ static int usb_hcd_s3c2410_probe(const struct hc_driver *driver,
392 407
393/*-------------------------------------------------------------------------*/ 408/*-------------------------------------------------------------------------*/
394 409
395static int 410static struct hc_driver __read_mostly ohci_s3c2410_hc_driver;
396ohci_s3c2410_start(struct usb_hcd *hcd)
397{
398 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
399 int ret;
400
401 ret = ohci_init(ohci);
402 if (ret < 0)
403 return ret;
404
405 ret = ohci_run(ohci);
406 if (ret < 0) {
407 dev_err(hcd->self.controller, "can't start %s\n",
408 hcd->self.bus_name);
409 ohci_stop(hcd);
410 return ret;
411 }
412
413 return 0;
414}
415
416
417static const struct hc_driver ohci_s3c2410_hc_driver = {
418 .description = hcd_name,
419 .product_desc = "S3C24XX OHCI",
420 .hcd_priv_size = sizeof(struct ohci_hcd),
421
422 /*
423 * generic hardware linkage
424 */
425 .irq = ohci_irq,
426 .flags = HCD_USB11 | HCD_MEMORY,
427
428 /*
429 * basic lifecycle operations
430 */
431 .start = ohci_s3c2410_start,
432 .stop = ohci_stop,
433 .shutdown = ohci_shutdown,
434
435 /*
436 * managing i/o requests and associated device resources
437 */
438 .urb_enqueue = ohci_urb_enqueue,
439 .urb_dequeue = ohci_urb_dequeue,
440 .endpoint_disable = ohci_endpoint_disable,
441
442 /*
443 * scheduling support
444 */
445 .get_frame_number = ohci_get_frame,
446
447 /*
448 * root hub support
449 */
450 .hub_status_data = ohci_s3c2410_hub_status_data,
451 .hub_control = ohci_s3c2410_hub_control,
452#ifdef CONFIG_PM
453 .bus_suspend = ohci_bus_suspend,
454 .bus_resume = ohci_bus_resume,
455#endif
456 .start_port_reset = ohci_start_port_reset,
457};
458
459/* device driver */
460 411
461static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev) 412static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev)
462{ 413{
@@ -533,4 +484,39 @@ static struct platform_driver ohci_hcd_s3c2410_driver = {
533 }, 484 },
534}; 485};
535 486
487static int __init ohci_s3c2410_init(void)
488{
489 if (usb_disabled())
490 return -ENODEV;
491
492 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
493 ohci_init_driver(&ohci_s3c2410_hc_driver, NULL);
494
495 /*
496 * The Samsung HW has some unusual quirks, which require
497 * Sumsung-specific workarounds. We override certain hc_driver
498 * functions here to achieve that. We explicitly do not enhance
499 * ohci_driver_overrides to allow this more easily, since this
500 * is an unusual case, and we don't want to encourage others to
501 * override these functions by making it too easy.
502 */
503
504 orig_ohci_hub_control = ohci_s3c2410_hc_driver.hub_control;
505 orig_ohci_hub_status_data = ohci_s3c2410_hc_driver.hub_status_data;
506
507 ohci_s3c2410_hc_driver.hub_status_data = ohci_s3c2410_hub_status_data;
508 ohci_s3c2410_hc_driver.hub_control = ohci_s3c2410_hub_control;
509
510 return platform_driver_register(&ohci_hcd_s3c2410_driver);
511}
512module_init(ohci_s3c2410_init);
513
514static void __exit ohci_s3c2410_cleanup(void)
515{
516 platform_driver_unregister(&ohci_hcd_s3c2410_driver);
517}
518module_exit(ohci_s3c2410_cleanup);
519
520MODULE_DESCRIPTION(DRIVER_DESC);
521MODULE_LICENSE("GPL");
536MODULE_ALIAS("platform:s3c2410-ohci"); 522MODULE_ALIAS("platform:s3c2410-ohci");
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c
index 17b2a7dad77b..aa9e127bbe71 100644
--- a/drivers/usb/host/ohci-sa1111.c
+++ b/drivers/usb/host/ohci-sa1111.c
@@ -185,6 +185,12 @@ static int ohci_hcd_sa1111_probe(struct sa1111_dev *dev)
185 if (usb_disabled()) 185 if (usb_disabled())
186 return -ENODEV; 186 return -ENODEV;
187 187
188 /*
189 * We don't call dma_set_mask_and_coherent() here because the
190 * DMA mask has already been appropraitely setup by the core
191 * SA-1111 bus code (which includes bug workarounds.)
192 */
193
188 hcd = usb_create_hcd(&ohci_sa1111_hc_driver, &dev->dev, "sa1111"); 194 hcd = usb_create_hcd(&ohci_sa1111_hc_driver, &dev->dev, "sa1111");
189 if (!hcd) 195 if (!hcd)
190 return -ENOMEM; 196 return -ENOMEM;
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c
index d479d5ddab88..2a5de5fecd8f 100644
--- a/drivers/usb/host/ohci-sm501.c
+++ b/drivers/usb/host/ohci-sm501.c
@@ -216,14 +216,21 @@ static int ohci_hcd_sm501_drv_remove(struct platform_device *pdev)
216static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg) 216static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg)
217{ 217{
218 struct device *dev = &pdev->dev; 218 struct device *dev = &pdev->dev;
219 struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev)); 219 struct usb_hcd *hcd = platform_get_drvdata(pdev);
220 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
221 bool do_wakeup = device_may_wakeup(dev);
222 int ret;
220 223
221 if (time_before(jiffies, ohci->next_statechange)) 224 if (time_before(jiffies, ohci->next_statechange))
222 msleep(5); 225 msleep(5);
223 ohci->next_statechange = jiffies; 226 ohci->next_statechange = jiffies;
224 227
228 ret = ohci_suspend(hcd, do_wakeup);
229 if (ret)
230 return ret;
231
225 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0); 232 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0);
226 return 0; 233 return ret;
227} 234}
228 235
229static int ohci_sm501_resume(struct platform_device *pdev) 236static int ohci_sm501_resume(struct platform_device *pdev)
diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c
index cc9dd9e4f05e..6b02107d281d 100644
--- a/drivers/usb/host/ohci-spear.c
+++ b/drivers/usb/host/ohci-spear.c
@@ -11,92 +11,37 @@
11* warranty of any kind, whether express or implied. 11* warranty of any kind, whether express or implied.
12*/ 12*/
13 13
14#include <linux/signal.h>
15#include <linux/platform_device.h>
16#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/dma-mapping.h>
16#include <linux/io.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
17#include <linux/of.h> 19#include <linux/of.h>
20#include <linux/platform_device.h>
21#include <linux/signal.h>
22#include <linux/usb.h>
23#include <linux/usb/hcd.h>
24
25#include "ohci.h"
18 26
27#define DRIVER_DESC "OHCI SPEAr driver"
28
29static const char hcd_name[] = "SPEAr-ohci";
19struct spear_ohci { 30struct spear_ohci {
20 struct ohci_hcd ohci;
21 struct clk *clk; 31 struct clk *clk;
22}; 32};
23 33
24#define to_spear_ohci(hcd) (struct spear_ohci *)hcd_to_ohci(hcd) 34#define to_spear_ohci(hcd) (struct spear_ohci *)(hcd_to_ohci(hcd)->priv)
25
26static void spear_start_ohci(struct spear_ohci *ohci)
27{
28 clk_prepare_enable(ohci->clk);
29}
30
31static void spear_stop_ohci(struct spear_ohci *ohci)
32{
33 clk_disable_unprepare(ohci->clk);
34}
35
36static int ohci_spear_start(struct usb_hcd *hcd)
37{
38 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
39 int ret;
40
41 ret = ohci_init(ohci);
42 if (ret < 0)
43 return ret;
44 ohci->regs = hcd->regs;
45
46 ret = ohci_run(ohci);
47 if (ret < 0) {
48 dev_err(hcd->self.controller, "can't start\n");
49 ohci_stop(hcd);
50 return ret;
51 }
52 35
53 create_debug_files(ohci); 36static struct hc_driver __read_mostly ohci_spear_hc_driver;
54
55#ifdef DEBUG
56 ohci_dump(ohci, 1);
57#endif
58 return 0;
59}
60
61static const struct hc_driver ohci_spear_hc_driver = {
62 .description = hcd_name,
63 .product_desc = "SPEAr OHCI",
64 .hcd_priv_size = sizeof(struct spear_ohci),
65
66 /* generic hardware linkage */
67 .irq = ohci_irq,
68 .flags = HCD_USB11 | HCD_MEMORY,
69
70 /* basic lifecycle operations */
71 .start = ohci_spear_start,
72 .stop = ohci_stop,
73 .shutdown = ohci_shutdown,
74#ifdef CONFIG_PM
75 .bus_suspend = ohci_bus_suspend,
76 .bus_resume = ohci_bus_resume,
77#endif
78
79 /* managing i/o requests and associated device resources */
80 .urb_enqueue = ohci_urb_enqueue,
81 .urb_dequeue = ohci_urb_dequeue,
82 .endpoint_disable = ohci_endpoint_disable,
83
84 /* scheduling support */
85 .get_frame_number = ohci_get_frame,
86
87 /* root hub support */
88 .hub_status_data = ohci_hub_status_data,
89 .hub_control = ohci_hub_control,
90
91 .start_port_reset = ohci_start_port_reset,
92};
93 37
94static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) 38static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
95{ 39{
96 const struct hc_driver *driver = &ohci_spear_hc_driver; 40 const struct hc_driver *driver = &ohci_spear_hc_driver;
41 struct ohci_hcd *ohci;
97 struct usb_hcd *hcd = NULL; 42 struct usb_hcd *hcd = NULL;
98 struct clk *usbh_clk; 43 struct clk *usbh_clk;
99 struct spear_ohci *ohci_p; 44 struct spear_ohci *sohci_p;
100 struct resource *res; 45 struct resource *res;
101 int retval, irq; 46 int retval, irq;
102 47
@@ -111,10 +56,9 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
111 * Since shared usb code relies on it, set it here for now. 56 * Since shared usb code relies on it, set it here for now.
112 * Once we have dma capability bindings this can go away. 57 * Once we have dma capability bindings this can go away.
113 */ 58 */
114 if (!pdev->dev.dma_mask) 59 retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
115 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 60 if (retval)
116 if (!pdev->dev.coherent_dma_mask) 61 goto fail;
117 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
118 62
119 usbh_clk = devm_clk_get(&pdev->dev, NULL); 63 usbh_clk = devm_clk_get(&pdev->dev, NULL);
120 if (IS_ERR(usbh_clk)) { 64 if (IS_ERR(usbh_clk)) {
@@ -151,16 +95,18 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
151 goto err_put_hcd; 95 goto err_put_hcd;
152 } 96 }
153 97
154 ohci_p = (struct spear_ohci *)hcd_to_ohci(hcd); 98 sohci_p = to_spear_ohci(hcd);
155 ohci_p->clk = usbh_clk; 99 sohci_p->clk = usbh_clk;
156 spear_start_ohci(ohci_p); 100
157 ohci_hcd_init(hcd_to_ohci(hcd)); 101 clk_prepare_enable(sohci_p->clk);
102
103 ohci = hcd_to_ohci(hcd);
158 104
159 retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); 105 retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0);
160 if (retval == 0) 106 if (retval == 0)
161 return retval; 107 return retval;
162 108
163 spear_stop_ohci(ohci_p); 109 clk_disable_unprepare(sohci_p->clk);
164err_put_hcd: 110err_put_hcd:
165 usb_put_hcd(hcd); 111 usb_put_hcd(hcd);
166fail: 112fail:
@@ -172,11 +118,11 @@ fail:
172static int spear_ohci_hcd_drv_remove(struct platform_device *pdev) 118static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)
173{ 119{
174 struct usb_hcd *hcd = platform_get_drvdata(pdev); 120 struct usb_hcd *hcd = platform_get_drvdata(pdev);
175 struct spear_ohci *ohci_p = to_spear_ohci(hcd); 121 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
176 122
177 usb_remove_hcd(hcd); 123 usb_remove_hcd(hcd);
178 if (ohci_p->clk) 124 if (sohci_p->clk)
179 spear_stop_ohci(ohci_p); 125 clk_disable_unprepare(sohci_p->clk);
180 126
181 usb_put_hcd(hcd); 127 usb_put_hcd(hcd);
182 return 0; 128 return 0;
@@ -188,13 +134,14 @@ static int spear_ohci_hcd_drv_suspend(struct platform_device *dev,
188{ 134{
189 struct usb_hcd *hcd = platform_get_drvdata(dev); 135 struct usb_hcd *hcd = platform_get_drvdata(dev);
190 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 136 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
191 struct spear_ohci *ohci_p = to_spear_ohci(hcd); 137 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
192 138
193 if (time_before(jiffies, ohci->next_statechange)) 139 if (time_before(jiffies, ohci->next_statechange))
194 msleep(5); 140 msleep(5);
195 ohci->next_statechange = jiffies; 141 ohci->next_statechange = jiffies;
196 142
197 spear_stop_ohci(ohci_p); 143 clk_disable_unprepare(sohci_p->clk);
144
198 return 0; 145 return 0;
199} 146}
200 147
@@ -202,13 +149,13 @@ static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
202{ 149{
203 struct usb_hcd *hcd = platform_get_drvdata(dev); 150 struct usb_hcd *hcd = platform_get_drvdata(dev);
204 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 151 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
205 struct spear_ohci *ohci_p = to_spear_ohci(hcd); 152 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
206 153
207 if (time_before(jiffies, ohci->next_statechange)) 154 if (time_before(jiffies, ohci->next_statechange))
208 msleep(5); 155 msleep(5);
209 ohci->next_statechange = jiffies; 156 ohci->next_statechange = jiffies;
210 157
211 spear_start_ohci(ohci_p); 158 clk_prepare_enable(sohci_p->clk);
212 ohci_resume(hcd, false); 159 ohci_resume(hcd, false);
213 return 0; 160 return 0;
214} 161}
@@ -234,4 +181,28 @@ static struct platform_driver spear_ohci_hcd_driver = {
234 }, 181 },
235}; 182};
236 183
184static const struct ohci_driver_overrides spear_overrides __initconst = {
185 .extra_priv_size = sizeof(struct spear_ohci),
186};
187static int __init ohci_spear_init(void)
188{
189 if (usb_disabled())
190 return -ENODEV;
191
192 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
193
194 ohci_init_driver(&ohci_spear_hc_driver, &spear_overrides);
195 return platform_driver_register(&spear_ohci_hcd_driver);
196}
197module_init(ohci_spear_init);
198
199static void __exit ohci_spear_cleanup(void)
200{
201 platform_driver_unregister(&spear_ohci_hcd_driver);
202}
203module_exit(ohci_spear_cleanup);
204
205MODULE_DESCRIPTION(DRIVER_DESC);
206MODULE_AUTHOR("Deepak Sikri");
207MODULE_LICENSE("GPL v2");
237MODULE_ALIAS("platform:spear-ohci"); 208MODULE_ALIAS("platform:spear-ohci");
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 2c76ef1320ea..dfbdd3aefe98 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -79,11 +79,30 @@
79#define USB_INTEL_USB3_PSSEN 0xD8 79#define USB_INTEL_USB3_PSSEN 0xD8
80#define USB_INTEL_USB3PRM 0xDC 80#define USB_INTEL_USB3PRM 0xDC
81 81
82/*
83 * amd_chipset_gen values represent AMD different chipset generations
84 */
85enum amd_chipset_gen {
86 NOT_AMD_CHIPSET = 0,
87 AMD_CHIPSET_SB600,
88 AMD_CHIPSET_SB700,
89 AMD_CHIPSET_SB800,
90 AMD_CHIPSET_HUDSON2,
91 AMD_CHIPSET_BOLTON,
92 AMD_CHIPSET_YANGTZE,
93 AMD_CHIPSET_UNKNOWN,
94};
95
96struct amd_chipset_type {
97 enum amd_chipset_gen gen;
98 u8 rev;
99};
100
82static struct amd_chipset_info { 101static struct amd_chipset_info {
83 struct pci_dev *nb_dev; 102 struct pci_dev *nb_dev;
84 struct pci_dev *smbus_dev; 103 struct pci_dev *smbus_dev;
85 int nb_type; 104 int nb_type;
86 int sb_type; 105 struct amd_chipset_type sb_type;
87 int isoc_reqs; 106 int isoc_reqs;
88 int probe_count; 107 int probe_count;
89 int probe_result; 108 int probe_result;
@@ -91,6 +110,51 @@ static struct amd_chipset_info {
91 110
92static DEFINE_SPINLOCK(amd_lock); 111static DEFINE_SPINLOCK(amd_lock);
93 112
113/*
114 * amd_chipset_sb_type_init - initialize amd chipset southbridge type
115 *
116 * AMD FCH/SB generation and revision is identified by SMBus controller
117 * vendor, device and revision IDs.
118 *
119 * Returns: 1 if it is an AMD chipset, 0 otherwise.
120 */
121static int amd_chipset_sb_type_init(struct amd_chipset_info *pinfo)
122{
123 u8 rev = 0;
124 pinfo->sb_type.gen = AMD_CHIPSET_UNKNOWN;
125
126 pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI,
127 PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL);
128 if (pinfo->smbus_dev) {
129 rev = pinfo->smbus_dev->revision;
130 if (rev >= 0x10 && rev <= 0x1f)
131 pinfo->sb_type.gen = AMD_CHIPSET_SB600;
132 else if (rev >= 0x30 && rev <= 0x3f)
133 pinfo->sb_type.gen = AMD_CHIPSET_SB700;
134 else if (rev >= 0x40 && rev <= 0x4f)
135 pinfo->sb_type.gen = AMD_CHIPSET_SB800;
136 } else {
137 pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
138 PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL);
139
140 if (!pinfo->smbus_dev) {
141 pinfo->sb_type.gen = NOT_AMD_CHIPSET;
142 return 0;
143 }
144
145 rev = pinfo->smbus_dev->revision;
146 if (rev >= 0x11 && rev <= 0x14)
147 pinfo->sb_type.gen = AMD_CHIPSET_HUDSON2;
148 else if (rev >= 0x15 && rev <= 0x18)
149 pinfo->sb_type.gen = AMD_CHIPSET_BOLTON;
150 else if (rev >= 0x39 && rev <= 0x3a)
151 pinfo->sb_type.gen = AMD_CHIPSET_YANGTZE;
152 }
153
154 pinfo->sb_type.rev = rev;
155 return 1;
156}
157
94void sb800_prefetch(struct device *dev, int on) 158void sb800_prefetch(struct device *dev, int on)
95{ 159{
96 u16 misc; 160 u16 misc;
@@ -106,7 +170,6 @@ EXPORT_SYMBOL_GPL(sb800_prefetch);
106 170
107int usb_amd_find_chipset_info(void) 171int usb_amd_find_chipset_info(void)
108{ 172{
109 u8 rev = 0;
110 unsigned long flags; 173 unsigned long flags;
111 struct amd_chipset_info info; 174 struct amd_chipset_info info;
112 int ret; 175 int ret;
@@ -122,27 +185,17 @@ int usb_amd_find_chipset_info(void)
122 memset(&info, 0, sizeof(info)); 185 memset(&info, 0, sizeof(info));
123 spin_unlock_irqrestore(&amd_lock, flags); 186 spin_unlock_irqrestore(&amd_lock, flags);
124 187
125 info.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL); 188 if (!amd_chipset_sb_type_init(&info)) {
126 if (info.smbus_dev) { 189 ret = 0;
127 rev = info.smbus_dev->revision; 190 goto commit;
128 if (rev >= 0x40)
129 info.sb_type = 1;
130 else if (rev >= 0x30 && rev <= 0x3b)
131 info.sb_type = 3;
132 } else {
133 info.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
134 0x780b, NULL);
135 if (!info.smbus_dev) {
136 ret = 0;
137 goto commit;
138 }
139
140 rev = info.smbus_dev->revision;
141 if (rev >= 0x11 && rev <= 0x18)
142 info.sb_type = 2;
143 } 191 }
144 192
145 if (info.sb_type == 0) { 193 /* Below chipset generations needn't enable AMD PLL quirk */
194 if (info.sb_type.gen == AMD_CHIPSET_UNKNOWN ||
195 info.sb_type.gen == AMD_CHIPSET_SB600 ||
196 info.sb_type.gen == AMD_CHIPSET_YANGTZE ||
197 (info.sb_type.gen == AMD_CHIPSET_SB700 &&
198 info.sb_type.rev > 0x3b)) {
146 if (info.smbus_dev) { 199 if (info.smbus_dev) {
147 pci_dev_put(info.smbus_dev); 200 pci_dev_put(info.smbus_dev);
148 info.smbus_dev = NULL; 201 info.smbus_dev = NULL;
@@ -197,6 +250,39 @@ commit:
197} 250}
198EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info); 251EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info);
199 252
253int usb_hcd_amd_remote_wakeup_quirk(struct pci_dev *pdev)
254{
255 /* Make sure amd chipset type has already been initialized */
256 usb_amd_find_chipset_info();
257 if (amd_chipset.sb_type.gen != AMD_CHIPSET_YANGTZE)
258 return 0;
259
260 dev_dbg(&pdev->dev, "QUIRK: Enable AMD remote wakeup fix\n");
261 return 1;
262}
263EXPORT_SYMBOL_GPL(usb_hcd_amd_remote_wakeup_quirk);
264
265bool usb_amd_hang_symptom_quirk(void)
266{
267 u8 rev;
268
269 usb_amd_find_chipset_info();
270 rev = amd_chipset.sb_type.rev;
271 /* SB600 and old version of SB700 have hang symptom bug */
272 return amd_chipset.sb_type.gen == AMD_CHIPSET_SB600 ||
273 (amd_chipset.sb_type.gen == AMD_CHIPSET_SB700 &&
274 rev >= 0x3a && rev <= 0x3b);
275}
276EXPORT_SYMBOL_GPL(usb_amd_hang_symptom_quirk);
277
278bool usb_amd_prefetch_quirk(void)
279{
280 usb_amd_find_chipset_info();
281 /* SB800 needs pre-fetch fix */
282 return amd_chipset.sb_type.gen == AMD_CHIPSET_SB800;
283}
284EXPORT_SYMBOL_GPL(usb_amd_prefetch_quirk);
285
200/* 286/*
201 * The hardware normally enables the A-link power management feature, which 287 * The hardware normally enables the A-link power management feature, which
202 * lets the system lower the power consumption in idle states. 288 * lets the system lower the power consumption in idle states.
@@ -229,7 +315,9 @@ static void usb_amd_quirk_pll(int disable)
229 } 315 }
230 } 316 }
231 317
232 if (amd_chipset.sb_type == 1 || amd_chipset.sb_type == 2) { 318 if (amd_chipset.sb_type.gen == AMD_CHIPSET_SB800 ||
319 amd_chipset.sb_type.gen == AMD_CHIPSET_HUDSON2 ||
320 amd_chipset.sb_type.gen == AMD_CHIPSET_BOLTON) {
233 outb_p(AB_REG_BAR_LOW, 0xcd6); 321 outb_p(AB_REG_BAR_LOW, 0xcd6);
234 addr_low = inb_p(0xcd7); 322 addr_low = inb_p(0xcd7);
235 outb_p(AB_REG_BAR_HIGH, 0xcd6); 323 outb_p(AB_REG_BAR_HIGH, 0xcd6);
@@ -240,7 +328,8 @@ static void usb_amd_quirk_pll(int disable)
240 outl_p(0x40, AB_DATA(addr)); 328 outl_p(0x40, AB_DATA(addr));
241 outl_p(0x34, AB_INDX(addr)); 329 outl_p(0x34, AB_INDX(addr));
242 val = inl_p(AB_DATA(addr)); 330 val = inl_p(AB_DATA(addr));
243 } else if (amd_chipset.sb_type == 3) { 331 } else if (amd_chipset.sb_type.gen == AMD_CHIPSET_SB700 &&
332 amd_chipset.sb_type.rev <= 0x3b) {
244 pci_read_config_dword(amd_chipset.smbus_dev, 333 pci_read_config_dword(amd_chipset.smbus_dev,
245 AB_REG_BAR_SB700, &addr); 334 AB_REG_BAR_SB700, &addr);
246 outl(AX_INDXC, AB_INDX(addr)); 335 outl(AX_INDXC, AB_INDX(addr));
@@ -353,7 +442,7 @@ void usb_amd_dev_put(void)
353 amd_chipset.nb_dev = NULL; 442 amd_chipset.nb_dev = NULL;
354 amd_chipset.smbus_dev = NULL; 443 amd_chipset.smbus_dev = NULL;
355 amd_chipset.nb_type = 0; 444 amd_chipset.nb_type = 0;
356 amd_chipset.sb_type = 0; 445 memset(&amd_chipset.sb_type, 0, sizeof(amd_chipset.sb_type));
357 amd_chipset.isoc_reqs = 0; 446 amd_chipset.isoc_reqs = 0;
358 amd_chipset.probe_result = 0; 447 amd_chipset.probe_result = 0;
359 448
@@ -799,7 +888,7 @@ void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev)
799 * switchable ports. 888 * switchable ports.
800 */ 889 */
801 pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN, 890 pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
802 cpu_to_le32(ports_available)); 891 ports_available);
803 892
804 pci_read_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN, 893 pci_read_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
805 &ports_available); 894 &ports_available);
@@ -821,7 +910,7 @@ void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev)
821 * host. 910 * host.
822 */ 911 */
823 pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, 912 pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
824 cpu_to_le32(ports_available)); 913 ports_available);
825 914
826 pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, 915 pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
827 &ports_available); 916 &ports_available);
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h
index ed6700d00fe6..638e88f7a28b 100644
--- a/drivers/usb/host/pci-quirks.h
+++ b/drivers/usb/host/pci-quirks.h
@@ -5,6 +5,8 @@
5void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); 5void uhci_reset_hc(struct pci_dev *pdev, unsigned long base);
6int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base); 6int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base);
7int usb_amd_find_chipset_info(void); 7int usb_amd_find_chipset_info(void);
8bool usb_amd_hang_symptom_quirk(void);
9bool usb_amd_prefetch_quirk(void);
8void usb_amd_dev_put(void); 10void usb_amd_dev_put(void);
9void usb_amd_quirk_pll_disable(void); 11void usb_amd_quirk_pll_disable(void);
10void usb_amd_quirk_pll_enable(void); 12void usb_amd_quirk_pll_enable(void);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 5477bf5df218..79620c39217e 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1413,7 +1413,7 @@ static int sl811h_show(struct seq_file *s, void *unused)
1413 case SL11H_CTL1MASK_SE0: s = " se0/reset"; break; 1413 case SL11H_CTL1MASK_SE0: s = " se0/reset"; break;
1414 case SL11H_CTL1MASK_K: s = " k/resume"; break; 1414 case SL11H_CTL1MASK_K: s = " k/resume"; break;
1415 default: s = "j"; break; 1415 default: s = "j"; break;
1416 }; s; }), 1416 } s; }),
1417 (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "", 1417 (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "",
1418 (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : ""); 1418 (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : "");
1419 1419
@@ -1446,7 +1446,7 @@ static int sl811h_show(struct seq_file *s, void *unused)
1446 case USB_PID_SETUP: s = "setup"; break; 1446 case USB_PID_SETUP: s = "setup"; break;
1447 case USB_PID_ACK: s = "status"; break; 1447 case USB_PID_ACK: s = "status"; break;
1448 default: s = "?"; break; 1448 default: s = "?"; break;
1449 }; s;}), 1449 } s;}),
1450 ep->maxpacket, 1450 ep->maxpacket,
1451 ep->nak_count, ep->error_count); 1451 ep->nak_count, ep->error_count);
1452 list_for_each_entry (urb, &ep->hep->urb_list, urb_list) { 1452 list_for_each_entry (urb, &ep->hep->urb_list, urb_list) {
diff --git a/drivers/usb/host/ssb-hcd.c b/drivers/usb/host/ssb-hcd.c
index 74af2c6287d2..0196f766df73 100644
--- a/drivers/usb/host/ssb-hcd.c
+++ b/drivers/usb/host/ssb-hcd.c
@@ -163,8 +163,7 @@ static int ssb_hcd_probe(struct ssb_device *dev,
163 163
164 /* TODO: Probably need checks here; is the core connected? */ 164 /* TODO: Probably need checks here; is the core connected? */
165 165
166 if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) || 166 if (dma_set_mask_and_coherent(dev->dma_dev, DMA_BIT_MASK(32)))
167 dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
168 return -EOPNOTSUPP; 167 return -EOPNOTSUPP;
169 168
170 usb_dev = kzalloc(sizeof(struct ssb_hcd_device), GFP_KERNEL); 169 usb_dev = kzalloc(sizeof(struct ssb_hcd_device), GFP_KERNEL);
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 455737546525..8e239cdd95d5 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -310,14 +310,14 @@ static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
310 unsigned short portsc1, portsc2; 310 unsigned short portsc1, portsc2;
311 311
312 312
313 usbcmd = uhci_readw(uhci, 0); 313 usbcmd = uhci_readw(uhci, USBCMD);
314 usbstat = uhci_readw(uhci, 2); 314 usbstat = uhci_readw(uhci, USBSTS);
315 usbint = uhci_readw(uhci, 4); 315 usbint = uhci_readw(uhci, USBINTR);
316 usbfrnum = uhci_readw(uhci, 6); 316 usbfrnum = uhci_readw(uhci, USBFRNUM);
317 flbaseadd = uhci_readl(uhci, 8); 317 flbaseadd = uhci_readl(uhci, USBFLBASEADD);
318 sof = uhci_readb(uhci, 12); 318 sof = uhci_readb(uhci, USBSOF);
319 portsc1 = uhci_readw(uhci, 16); 319 portsc1 = uhci_readw(uhci, USBPORTSC1);
320 portsc2 = uhci_readw(uhci, 18); 320 portsc2 = uhci_readw(uhci, USBPORTSC2);
321 321
322 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n", 322 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
323 usbcmd, 323 usbcmd,
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 9189bc984c98..93e17b12fb33 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -75,8 +75,6 @@ static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
75 return !!*buf; 75 return !!*buf;
76} 76}
77 77
78#define OK(x) len = (x); break
79
80#define CLR_RH_PORTSTAT(x) \ 78#define CLR_RH_PORTSTAT(x) \
81 status = uhci_readw(uhci, port_addr); \ 79 status = uhci_readw(uhci, port_addr); \
82 status &= ~(RWC_BITS|WZ_BITS); \ 80 status &= ~(RWC_BITS|WZ_BITS); \
@@ -244,7 +242,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
244 u16 wIndex, char *buf, u16 wLength) 242 u16 wIndex, char *buf, u16 wLength)
245{ 243{
246 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 244 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
247 int status, lstatus, retval = 0, len = 0; 245 int status, lstatus, retval = 0;
248 unsigned int port = wIndex - 1; 246 unsigned int port = wIndex - 1;
249 unsigned long port_addr = USBPORTSC1 + 2 * port; 247 unsigned long port_addr = USBPORTSC1 + 2 * port;
250 u16 wPortChange, wPortStatus; 248 u16 wPortChange, wPortStatus;
@@ -258,7 +256,8 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
258 256
259 case GetHubStatus: 257 case GetHubStatus:
260 *(__le32 *)buf = cpu_to_le32(0); 258 *(__le32 *)buf = cpu_to_le32(0);
261 OK(4); /* hub power */ 259 retval = 4; /* hub power */
260 break;
262 case GetPortStatus: 261 case GetPortStatus:
263 if (port >= uhci->rh_numports) 262 if (port >= uhci->rh_numports)
264 goto err; 263 goto err;
@@ -311,13 +310,14 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
311 310
312 *(__le16 *)buf = cpu_to_le16(wPortStatus); 311 *(__le16 *)buf = cpu_to_le16(wPortStatus);
313 *(__le16 *)(buf + 2) = cpu_to_le16(wPortChange); 312 *(__le16 *)(buf + 2) = cpu_to_le16(wPortChange);
314 OK(4); 313 retval = 4;
314 break;
315 case SetHubFeature: /* We don't implement these */ 315 case SetHubFeature: /* We don't implement these */
316 case ClearHubFeature: 316 case ClearHubFeature:
317 switch (wValue) { 317 switch (wValue) {
318 case C_HUB_OVER_CURRENT: 318 case C_HUB_OVER_CURRENT:
319 case C_HUB_LOCAL_POWER: 319 case C_HUB_LOCAL_POWER:
320 OK(0); 320 break;
321 default: 321 default:
322 goto err; 322 goto err;
323 } 323 }
@@ -329,7 +329,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
329 switch (wValue) { 329 switch (wValue) {
330 case USB_PORT_FEAT_SUSPEND: 330 case USB_PORT_FEAT_SUSPEND:
331 SET_RH_PORTSTAT(USBPORTSC_SUSP); 331 SET_RH_PORTSTAT(USBPORTSC_SUSP);
332 OK(0); 332 break;
333 case USB_PORT_FEAT_RESET: 333 case USB_PORT_FEAT_RESET:
334 SET_RH_PORTSTAT(USBPORTSC_PR); 334 SET_RH_PORTSTAT(USBPORTSC_PR);
335 335
@@ -338,10 +338,10 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
338 338
339 /* USB v2.0 7.1.7.5 */ 339 /* USB v2.0 7.1.7.5 */
340 uhci->ports_timeout = jiffies + msecs_to_jiffies(50); 340 uhci->ports_timeout = jiffies + msecs_to_jiffies(50);
341 OK(0); 341 break;
342 case USB_PORT_FEAT_POWER: 342 case USB_PORT_FEAT_POWER:
343 /* UHCI has no power switching */ 343 /* UHCI has no power switching */
344 OK(0); 344 break;
345 default: 345 default:
346 goto err; 346 goto err;
347 } 347 }
@@ -356,10 +356,10 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
356 356
357 /* Disable terminates Resume signalling */ 357 /* Disable terminates Resume signalling */
358 uhci_finish_suspend(uhci, port, port_addr); 358 uhci_finish_suspend(uhci, port, port_addr);
359 OK(0); 359 break;
360 case USB_PORT_FEAT_C_ENABLE: 360 case USB_PORT_FEAT_C_ENABLE:
361 CLR_RH_PORTSTAT(USBPORTSC_PEC); 361 CLR_RH_PORTSTAT(USBPORTSC_PEC);
362 OK(0); 362 break;
363 case USB_PORT_FEAT_SUSPEND: 363 case USB_PORT_FEAT_SUSPEND:
364 if (!(uhci_readw(uhci, port_addr) & USBPORTSC_SUSP)) { 364 if (!(uhci_readw(uhci, port_addr) & USBPORTSC_SUSP)) {
365 365
@@ -382,32 +382,32 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
382 uhci->ports_timeout = jiffies + 382 uhci->ports_timeout = jiffies +
383 msecs_to_jiffies(20); 383 msecs_to_jiffies(20);
384 } 384 }
385 OK(0); 385 break;
386 case USB_PORT_FEAT_C_SUSPEND: 386 case USB_PORT_FEAT_C_SUSPEND:
387 clear_bit(port, &uhci->port_c_suspend); 387 clear_bit(port, &uhci->port_c_suspend);
388 OK(0); 388 break;
389 case USB_PORT_FEAT_POWER: 389 case USB_PORT_FEAT_POWER:
390 /* UHCI has no power switching */ 390 /* UHCI has no power switching */
391 goto err; 391 goto err;
392 case USB_PORT_FEAT_C_CONNECTION: 392 case USB_PORT_FEAT_C_CONNECTION:
393 CLR_RH_PORTSTAT(USBPORTSC_CSC); 393 CLR_RH_PORTSTAT(USBPORTSC_CSC);
394 OK(0); 394 break;
395 case USB_PORT_FEAT_C_OVER_CURRENT: 395 case USB_PORT_FEAT_C_OVER_CURRENT:
396 CLR_RH_PORTSTAT(USBPORTSC_OCC); 396 CLR_RH_PORTSTAT(USBPORTSC_OCC);
397 OK(0); 397 break;
398 case USB_PORT_FEAT_C_RESET: 398 case USB_PORT_FEAT_C_RESET:
399 /* this driver won't report these */ 399 /* this driver won't report these */
400 OK(0); 400 break;
401 default: 401 default:
402 goto err; 402 goto err;
403 } 403 }
404 break; 404 break;
405 case GetHubDescriptor: 405 case GetHubDescriptor:
406 len = min_t(unsigned int, sizeof(root_hub_hub_des), wLength); 406 retval = min_t(unsigned int, sizeof(root_hub_hub_des), wLength);
407 memcpy(buf, root_hub_hub_des, len); 407 memcpy(buf, root_hub_hub_des, retval);
408 if (len > 2) 408 if (retval > 2)
409 buf[2] = uhci->rh_numports; 409 buf[2] = uhci->rh_numports;
410 OK(len); 410 break;
411 default: 411 default:
412err: 412err:
413 retval = -EPIPE; 413 retval = -EPIPE;
diff --git a/drivers/usb/host/uhci-pci.c b/drivers/usb/host/uhci-pci.c
index c300bd2f7d1c..4cd79888804b 100644
--- a/drivers/usb/host/uhci-pci.c
+++ b/drivers/usb/host/uhci-pci.c
@@ -162,6 +162,8 @@ static void uhci_shutdown(struct pci_dev *pdev)
162 162
163#ifdef CONFIG_PM 163#ifdef CONFIG_PM
164 164
165static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated);
166
165static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) 167static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
166{ 168{
167 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 169 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
@@ -174,12 +176,6 @@ static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
174 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead) 176 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
175 goto done_okay; /* Already suspended or dead */ 177 goto done_okay; /* Already suspended or dead */
176 178
177 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
178 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
179 rc = -EBUSY;
180 goto done;
181 };
182
183 /* All PCI host controllers are required to disable IRQ generation 179 /* All PCI host controllers are required to disable IRQ generation
184 * at the source, so we must turn off PIRQ. 180 * at the source, so we must turn off PIRQ.
185 */ 181 */
@@ -195,8 +191,15 @@ static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
195 191
196done_okay: 192done_okay:
197 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 193 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
198done:
199 spin_unlock_irq(&uhci->lock); 194 spin_unlock_irq(&uhci->lock);
195
196 synchronize_irq(hcd->irq);
197
198 /* Check for race with a wakeup request */
199 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
200 uhci_pci_resume(hcd, false);
201 rc = -EBUSY;
202 }
200 return rc; 203 return rc;
201} 204}
202 205
@@ -293,9 +296,11 @@ static struct pci_driver uhci_pci_driver = {
293 .remove = usb_hcd_pci_remove, 296 .remove = usb_hcd_pci_remove,
294 .shutdown = uhci_shutdown, 297 .shutdown = uhci_shutdown,
295 298
296#ifdef CONFIG_PM_SLEEP 299#ifdef CONFIG_PM
297 .driver = { 300 .driver = {
298 .pm = &usb_hcd_pci_pm_ops 301 .pm = &usb_hcd_pci_pm_ops
299 }, 302 },
300#endif 303#endif
301}; 304};
305
306MODULE_SOFTDEP("pre: ehci_pci");
diff --git a/drivers/usb/host/uhci-platform.c b/drivers/usb/host/uhci-platform.c
index d033a0ec7f0d..3003fefaa964 100644
--- a/drivers/usb/host/uhci-platform.c
+++ b/drivers/usb/host/uhci-platform.c
@@ -75,10 +75,9 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
75 * Since shared usb code relies on it, set it here for now. 75 * Since shared usb code relies on it, set it here for now.
76 * Once we have dma capability bindings this can go away. 76 * Once we have dma capability bindings this can go away.
77 */ 77 */
78 if (!pdev->dev.dma_mask) 78 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
79 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 79 if (ret)
80 if (!pdev->dev.coherent_dma_mask) 80 return ret;
81 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
82 81
83 hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev, 82 hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev,
84 pdev->name); 83 pdev->name);
@@ -105,8 +104,7 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
105 104
106 uhci->regs = hcd->regs; 105 uhci->regs = hcd->regs;
107 106
108 ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED | 107 ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
109 IRQF_SHARED);
110 if (ret) 108 if (ret)
111 goto err_uhci; 109 goto err_uhci;
112 110
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 041c6ddb695c..da6f56d996ce 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -1303,7 +1303,7 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb,
1303 } 1303 }
1304 1304
1305 /* Fell behind? */ 1305 /* Fell behind? */
1306 if (uhci_frame_before_eq(frame, next)) { 1306 if (!uhci_frame_before_eq(next, frame)) {
1307 1307
1308 /* USB_ISO_ASAP: Round up to the first available slot */ 1308 /* USB_ISO_ASAP: Round up to the first available slot */
1309 if (urb->transfer_flags & URB_ISO_ASAP) 1309 if (urb->transfer_flags & URB_ISO_ASAP)
@@ -1311,13 +1311,17 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb,
1311 -qh->period; 1311 -qh->period;
1312 1312
1313 /* 1313 /*
1314 * Not ASAP: Use the next slot in the stream. If 1314 * Not ASAP: Use the next slot in the stream,
1315 * the entire URB falls before the threshold, fail. 1315 * no matter what.
1316 */ 1316 */
1317 else if (!uhci_frame_before_eq(next, 1317 else if (!uhci_frame_before_eq(next,
1318 frame + (urb->number_of_packets - 1) * 1318 frame + (urb->number_of_packets - 1) *
1319 qh->period)) 1319 qh->period))
1320 return -EXDEV; 1320 dev_dbg(uhci_dev(uhci), "iso underrun %p (%u+%u < %u)\n",
1321 urb, frame,
1322 (urb->number_of_packets - 1) *
1323 qh->period,
1324 next);
1321 } 1325 }
1322 } 1326 }
1323 1327
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index ecc88db804e0..1b0888f8da9a 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -134,7 +134,7 @@ static int whc_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb,
134 default: 134 default:
135 ret = asl_urb_enqueue(whc, urb, mem_flags); 135 ret = asl_urb_enqueue(whc, urb, mem_flags);
136 break; 136 break;
137 }; 137 }
138 138
139 return ret; 139 return ret;
140} 140}
@@ -160,7 +160,7 @@ static int whc_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb, int status)
160 default: 160 default:
161 ret = asl_urb_dequeue(whc, urb, status); 161 ret = asl_urb_dequeue(whc, urb, status);
162 break; 162 break;
163 }; 163 }
164 164
165 return ret; 165 return ret;
166} 166}
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index fae697ed0b70..805f2348eeba 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -287,7 +287,7 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
287 if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) 287 if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue)
288 xhci_queue_stop_endpoint(xhci, slot_id, i, suspend); 288 xhci_queue_stop_endpoint(xhci, slot_id, i, suspend);
289 } 289 }
290 cmd->command_trb = xhci->cmd_ring->enqueue; 290 cmd->command_trb = xhci_find_next_enqueue(xhci->cmd_ring);
291 list_add_tail(&cmd->cmd_list, &virt_dev->cmd_list); 291 list_add_tail(&cmd->cmd_list, &virt_dev->cmd_list);
292 xhci_queue_stop_endpoint(xhci, slot_id, 0, suspend); 292 xhci_queue_stop_endpoint(xhci, slot_id, 0, suspend);
293 xhci_ring_cmd_db(xhci); 293 xhci_ring_cmd_db(xhci);
@@ -296,7 +296,7 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
296 /* Wait for last stop endpoint command to finish */ 296 /* Wait for last stop endpoint command to finish */
297 timeleft = wait_for_completion_interruptible_timeout( 297 timeleft = wait_for_completion_interruptible_timeout(
298 cmd->completion, 298 cmd->completion,
299 USB_CTRL_SET_TIMEOUT); 299 XHCI_CMD_DEFAULT_TIMEOUT);
300 if (timeleft <= 0) { 300 if (timeleft <= 0) {
301 xhci_warn(xhci, "%s while waiting for stop endpoint command\n", 301 xhci_warn(xhci, "%s while waiting for stop endpoint command\n",
302 timeleft == 0 ? "Timeout" : "Signal"); 302 timeleft == 0 ? "Timeout" : "Signal");
@@ -524,7 +524,8 @@ static void xhci_hub_report_usb3_link_state(u32 *status, u32 status_reg)
524 * the compliance mode timer is deleted. A port won't enter 524 * the compliance mode timer is deleted. A port won't enter
525 * compliance mode if it has previously entered U0. 525 * compliance mode if it has previously entered U0.
526 */ 526 */
527void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status, u16 wIndex) 527static void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status,
528 u16 wIndex)
528{ 529{
529 u32 all_ports_seen_u0 = ((1 << xhci->num_usb3_ports)-1); 530 u32 all_ports_seen_u0 = ((1 << xhci->num_usb3_ports)-1);
530 bool port_in_u0 = ((status & PORT_PLS_MASK) == XDEV_U0); 531 bool port_in_u0 = ((status & PORT_PLS_MASK) == XDEV_U0);
@@ -552,11 +553,15 @@ void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status, u16 wIndex)
552 * - Mark a port as being done with device resume, 553 * - Mark a port as being done with device resume,
553 * and ring the endpoint doorbells. 554 * and ring the endpoint doorbells.
554 * - Stop the Synopsys redriver Compliance Mode polling. 555 * - Stop the Synopsys redriver Compliance Mode polling.
556 * - Drop and reacquire the xHCI lock, in order to wait for port resume.
555 */ 557 */
556static u32 xhci_get_port_status(struct usb_hcd *hcd, 558static u32 xhci_get_port_status(struct usb_hcd *hcd,
557 struct xhci_bus_state *bus_state, 559 struct xhci_bus_state *bus_state,
558 __le32 __iomem **port_array, 560 __le32 __iomem **port_array,
559 u16 wIndex, u32 raw_port_status) 561 u16 wIndex, u32 raw_port_status,
562 unsigned long flags)
563 __releases(&xhci->lock)
564 __acquires(&xhci->lock)
560{ 565{
561 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 566 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
562 u32 status = 0; 567 u32 status = 0;
@@ -591,21 +596,42 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
591 return 0xffffffff; 596 return 0xffffffff;
592 if (time_after_eq(jiffies, 597 if (time_after_eq(jiffies,
593 bus_state->resume_done[wIndex])) { 598 bus_state->resume_done[wIndex])) {
599 int time_left;
600
594 xhci_dbg(xhci, "Resume USB2 port %d\n", 601 xhci_dbg(xhci, "Resume USB2 port %d\n",
595 wIndex + 1); 602 wIndex + 1);
596 bus_state->resume_done[wIndex] = 0; 603 bus_state->resume_done[wIndex] = 0;
597 clear_bit(wIndex, &bus_state->resuming_ports); 604 clear_bit(wIndex, &bus_state->resuming_ports);
605
606 set_bit(wIndex, &bus_state->rexit_ports);
598 xhci_set_link_state(xhci, port_array, wIndex, 607 xhci_set_link_state(xhci, port_array, wIndex,
599 XDEV_U0); 608 XDEV_U0);
600 xhci_dbg(xhci, "set port %d resume\n", 609
601 wIndex + 1); 610 spin_unlock_irqrestore(&xhci->lock, flags);
602 slot_id = xhci_find_slot_id_by_port(hcd, xhci, 611 time_left = wait_for_completion_timeout(
603 wIndex + 1); 612 &bus_state->rexit_done[wIndex],
604 if (!slot_id) { 613 msecs_to_jiffies(
605 xhci_dbg(xhci, "slot_id is zero\n"); 614 XHCI_MAX_REXIT_TIMEOUT));
606 return 0xffffffff; 615 spin_lock_irqsave(&xhci->lock, flags);
616
617 if (time_left) {
618 slot_id = xhci_find_slot_id_by_port(hcd,
619 xhci, wIndex + 1);
620 if (!slot_id) {
621 xhci_dbg(xhci, "slot_id is zero\n");
622 return 0xffffffff;
623 }
624 xhci_ring_device(xhci, slot_id);
625 } else {
626 int port_status = xhci_readl(xhci,
627 port_array[wIndex]);
628 xhci_warn(xhci, "Port resume took longer than %i msec, port status = 0x%x\n",
629 XHCI_MAX_REXIT_TIMEOUT,
630 port_status);
631 status |= USB_PORT_STAT_SUSPEND;
632 clear_bit(wIndex, &bus_state->rexit_ports);
607 } 633 }
608 xhci_ring_device(xhci, slot_id); 634
609 bus_state->port_c_suspend |= 1 << wIndex; 635 bus_state->port_c_suspend |= 1 << wIndex;
610 bus_state->suspended_ports &= ~(1 << wIndex); 636 bus_state->suspended_ports &= ~(1 << wIndex);
611 } else { 637 } else {
@@ -728,7 +754,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
728 break; 754 break;
729 } 755 }
730 status = xhci_get_port_status(hcd, bus_state, port_array, 756 status = xhci_get_port_status(hcd, bus_state, port_array,
731 wIndex, temp); 757 wIndex, temp, flags);
732 if (status == 0xffffffff) 758 if (status == 0xffffffff)
733 goto error; 759 goto error;
734 760
@@ -1132,18 +1158,6 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
1132 t1 = xhci_port_state_to_neutral(t1); 1158 t1 = xhci_port_state_to_neutral(t1);
1133 if (t1 != t2) 1159 if (t1 != t2)
1134 xhci_writel(xhci, t2, port_array[port_index]); 1160 xhci_writel(xhci, t2, port_array[port_index]);
1135
1136 if (hcd->speed != HCD_USB3) {
1137 /* enable remote wake up for USB 2.0 */
1138 __le32 __iomem *addr;
1139 u32 tmp;
1140
1141 /* Get the port power control register address. */
1142 addr = port_array[port_index] + PORTPMSC;
1143 tmp = xhci_readl(xhci, addr);
1144 tmp |= PORT_RWE;
1145 xhci_writel(xhci, tmp, addr);
1146 }
1147 } 1161 }
1148 hcd->state = HC_STATE_SUSPENDED; 1162 hcd->state = HC_STATE_SUSPENDED;
1149 bus_state->next_statechange = jiffies + msecs_to_jiffies(10); 1163 bus_state->next_statechange = jiffies + msecs_to_jiffies(10);
@@ -1222,20 +1236,6 @@ int xhci_bus_resume(struct usb_hcd *hcd)
1222 xhci_ring_device(xhci, slot_id); 1236 xhci_ring_device(xhci, slot_id);
1223 } else 1237 } else
1224 xhci_writel(xhci, temp, port_array[port_index]); 1238 xhci_writel(xhci, temp, port_array[port_index]);
1225
1226 if (hcd->speed != HCD_USB3) {
1227 /* disable remote wake up for USB 2.0 */
1228 __le32 __iomem *addr;
1229 u32 tmp;
1230
1231 /* Add one to the port status register address to get
1232 * the port power control register address.
1233 */
1234 addr = port_array[port_index] + PORTPMSC;
1235 tmp = xhci_readl(xhci, addr);
1236 tmp &= ~PORT_RWE;
1237 xhci_writel(xhci, tmp, addr);
1238 }
1239 } 1239 }
1240 1240
1241 (void) xhci_readl(xhci, &xhci->op_regs->command); 1241 (void) xhci_readl(xhci, &xhci->op_regs->command);
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 53b972c2a09f..49b8bd063fab 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1693,9 +1693,7 @@ void xhci_free_command(struct xhci_hcd *xhci,
1693void xhci_mem_cleanup(struct xhci_hcd *xhci) 1693void xhci_mem_cleanup(struct xhci_hcd *xhci)
1694{ 1694{
1695 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 1695 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
1696 struct dev_info *dev_info, *next;
1697 struct xhci_cd *cur_cd, *next_cd; 1696 struct xhci_cd *cur_cd, *next_cd;
1698 unsigned long flags;
1699 int size; 1697 int size;
1700 int i, j, num_ports; 1698 int i, j, num_ports;
1701 1699
@@ -1756,13 +1754,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1756 1754
1757 scratchpad_free(xhci); 1755 scratchpad_free(xhci);
1758 1756
1759 spin_lock_irqsave(&xhci->lock, flags);
1760 list_for_each_entry_safe(dev_info, next, &xhci->lpm_failed_devs, list) {
1761 list_del(&dev_info->list);
1762 kfree(dev_info);
1763 }
1764 spin_unlock_irqrestore(&xhci->lock, flags);
1765
1766 if (!xhci->rh_bw) 1757 if (!xhci->rh_bw)
1767 goto no_bw; 1758 goto no_bw;
1768 1759
@@ -2231,7 +2222,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2231 u32 page_size, temp; 2222 u32 page_size, temp;
2232 int i; 2223 int i;
2233 2224
2234 INIT_LIST_HEAD(&xhci->lpm_failed_devs);
2235 INIT_LIST_HEAD(&xhci->cancel_cmd_list); 2225 INIT_LIST_HEAD(&xhci->cancel_cmd_list);
2236 2226
2237 page_size = xhci_readl(xhci, &xhci->op_regs->page_size); 2227 page_size = xhci_readl(xhci, &xhci->op_regs->page_size);
@@ -2428,6 +2418,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2428 for (i = 0; i < USB_MAXCHILDREN; ++i) { 2418 for (i = 0; i < USB_MAXCHILDREN; ++i) {
2429 xhci->bus_state[0].resume_done[i] = 0; 2419 xhci->bus_state[0].resume_done[i] = 0;
2430 xhci->bus_state[1].resume_done[i] = 0; 2420 xhci->bus_state[1].resume_done[i] = 0;
2421 /* Only the USB 2.0 completions will ever be used. */
2422 init_completion(&xhci->bus_state[1].rexit_done[i]);
2431 } 2423 }
2432 2424
2433 if (scratchpad_alloc(xhci, flags)) 2425 if (scratchpad_alloc(xhci, flags))
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index c2d495057eb5..b8dffd59eb25 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -35,6 +35,9 @@
35#define PCI_VENDOR_ID_ETRON 0x1b6f 35#define PCI_VENDOR_ID_ETRON 0x1b6f
36#define PCI_DEVICE_ID_ASROCK_P67 0x7023 36#define PCI_DEVICE_ID_ASROCK_P67 0x7023
37 37
38#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31
39#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
40
38static const char hcd_name[] = "xhci_hcd"; 41static const char hcd_name[] = "xhci_hcd";
39 42
40/* called after powerup, by probe or system-pm "wakeup" */ 43/* called after powerup, by probe or system-pm "wakeup" */
@@ -69,6 +72,14 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
69 "QUIRK: Fresco Logic xHC needs configure" 72 "QUIRK: Fresco Logic xHC needs configure"
70 " endpoint cmd after reset endpoint"); 73 " endpoint cmd after reset endpoint");
71 } 74 }
75 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
76 pdev->revision == 0x4) {
77 xhci->quirks |= XHCI_SLOW_SUSPEND;
78 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
79 "QUIRK: Fresco Logic xHC revision %u"
80 "must be suspended extra slowly",
81 pdev->revision);
82 }
72 /* Fresco Logic confirms: all revisions of this chip do not 83 /* Fresco Logic confirms: all revisions of this chip do not
73 * support MSI, even though some of them claim to in their PCI 84 * support MSI, even though some of them claim to in their PCI
74 * capabilities. 85 * capabilities.
@@ -110,6 +121,15 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
110 xhci->quirks |= XHCI_SPURIOUS_REBOOT; 121 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
111 xhci->quirks |= XHCI_AVOID_BEI; 122 xhci->quirks |= XHCI_AVOID_BEI;
112 } 123 }
124 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
125 (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI ||
126 pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI)) {
127 /* Workaround for occasional spurious wakeups from S5 (or
128 * any other sleep) on Haswell machines with LPT and LPT-LP
129 * with the new Intel BIOS
130 */
131 xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
132 }
113 if (pdev->vendor == PCI_VENDOR_ID_ETRON && 133 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
114 pdev->device == PCI_DEVICE_ID_ASROCK_P67) { 134 pdev->device == PCI_DEVICE_ID_ASROCK_P67) {
115 xhci->quirks |= XHCI_RESET_ON_RESUME; 135 xhci->quirks |= XHCI_RESET_ON_RESUME;
@@ -217,6 +237,11 @@ static void xhci_pci_remove(struct pci_dev *dev)
217 usb_put_hcd(xhci->shared_hcd); 237 usb_put_hcd(xhci->shared_hcd);
218 } 238 }
219 usb_hcd_pci_remove(dev); 239 usb_hcd_pci_remove(dev);
240
241 /* Workaround for spurious wakeups at shutdown with HSW */
242 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
243 pci_set_power_state(dev, PCI_D3hot);
244
220 kfree(xhci); 245 kfree(xhci);
221} 246}
222 247
@@ -351,7 +376,7 @@ static struct pci_driver xhci_pci_driver = {
351 /* suspend and resume implemented later */ 376 /* suspend and resume implemented later */
352 377
353 .shutdown = usb_hcd_pci_shutdown, 378 .shutdown = usb_hcd_pci_shutdown,
354#ifdef CONFIG_PM_SLEEP 379#ifdef CONFIG_PM
355 .driver = { 380 .driver = {
356 .pm = &usb_hcd_pci_pm_ops 381 .pm = &usb_hcd_pci_pm_ops
357 }, 382 },
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 411da1fc7ae8..1e2f3f495843 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -123,6 +123,16 @@ static int enqueue_is_link_trb(struct xhci_ring *ring)
123 return TRB_TYPE_LINK_LE32(link->control); 123 return TRB_TYPE_LINK_LE32(link->control);
124} 124}
125 125
126union xhci_trb *xhci_find_next_enqueue(struct xhci_ring *ring)
127{
128 /* Enqueue pointer can be left pointing to the link TRB,
129 * we must handle that
130 */
131 if (TRB_TYPE_LINK_LE32(ring->enqueue->link.control))
132 return ring->enq_seg->next->trbs;
133 return ring->enqueue;
134}
135
126/* Updates trb to point to the next TRB in the ring, and updates seg if the next 136/* Updates trb to point to the next TRB in the ring, and updates seg if the next
127 * TRB is in a new segment. This does not skip over link TRBs, and it does not 137 * TRB is in a new segment. This does not skip over link TRBs, and it does not
128 * effect the ring dequeue or enqueue pointers. 138 * effect the ring dequeue or enqueue pointers.
@@ -168,7 +178,7 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring)
168 if (ring->type == TYPE_EVENT && 178 if (ring->type == TYPE_EVENT &&
169 last_trb_on_last_seg(xhci, ring, 179 last_trb_on_last_seg(xhci, ring,
170 ring->deq_seg, ring->dequeue)) { 180 ring->deq_seg, ring->dequeue)) {
171 ring->cycle_state = (ring->cycle_state ? 0 : 1); 181 ring->cycle_state ^= 1;
172 } 182 }
173 ring->deq_seg = ring->deq_seg->next; 183 ring->deq_seg = ring->deq_seg->next;
174 ring->dequeue = ring->deq_seg->trbs; 184 ring->dequeue = ring->deq_seg->trbs;
@@ -716,7 +726,7 @@ static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
716 726
717/* Must be called with xhci->lock held in interrupt context */ 727/* Must be called with xhci->lock held in interrupt context */
718static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, 728static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
719 struct xhci_td *cur_td, int status, char *adjective) 729 struct xhci_td *cur_td, int status)
720{ 730{
721 struct usb_hcd *hcd; 731 struct usb_hcd *hcd;
722 struct urb *urb; 732 struct urb *urb;
@@ -755,10 +765,9 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
755 * 2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the chain 765 * 2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the chain
756 * bit cleared) so that the HW will skip over them. 766 * bit cleared) so that the HW will skip over them.
757 */ 767 */
758static void handle_stopped_endpoint(struct xhci_hcd *xhci, 768static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,
759 union xhci_trb *trb, struct xhci_event_cmd *event) 769 union xhci_trb *trb, struct xhci_event_cmd *event)
760{ 770{
761 unsigned int slot_id;
762 unsigned int ep_index; 771 unsigned int ep_index;
763 struct xhci_virt_device *virt_dev; 772 struct xhci_virt_device *virt_dev;
764 struct xhci_ring *ep_ring; 773 struct xhci_ring *ep_ring;
@@ -769,10 +778,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
769 778
770 struct xhci_dequeue_state deq_state; 779 struct xhci_dequeue_state deq_state;
771 780
772 if (unlikely(TRB_TO_SUSPEND_PORT( 781 if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) {
773 le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])))) {
774 slot_id = TRB_TO_SLOT_ID(
775 le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3]));
776 virt_dev = xhci->devs[slot_id]; 782 virt_dev = xhci->devs[slot_id];
777 if (virt_dev) 783 if (virt_dev)
778 handle_cmd_in_cmd_wait_list(xhci, virt_dev, 784 handle_cmd_in_cmd_wait_list(xhci, virt_dev,
@@ -785,7 +791,6 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
785 } 791 }
786 792
787 memset(&deq_state, 0, sizeof(deq_state)); 793 memset(&deq_state, 0, sizeof(deq_state));
788 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3]));
789 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); 794 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3]));
790 ep = &xhci->devs[slot_id]->eps[ep_index]; 795 ep = &xhci->devs[slot_id]->eps[ep_index];
791 796
@@ -859,8 +864,12 @@ remove_finished_td:
859 /* Otherwise ring the doorbell(s) to restart queued transfers */ 864 /* Otherwise ring the doorbell(s) to restart queued transfers */
860 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); 865 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
861 } 866 }
862 ep->stopped_td = NULL; 867
863 ep->stopped_trb = NULL; 868 /* Clear stopped_td and stopped_trb if endpoint is not halted */
869 if (!(ep->ep_state & EP_HALTED)) {
870 ep->stopped_td = NULL;
871 ep->stopped_trb = NULL;
872 }
864 873
865 /* 874 /*
866 * Drop the lock and complete the URBs in the cancelled TD list. 875 * Drop the lock and complete the URBs in the cancelled TD list.
@@ -877,7 +886,7 @@ remove_finished_td:
877 /* Doesn't matter what we pass for status, since the core will 886 /* Doesn't matter what we pass for status, since the core will
878 * just overwrite it (because the URB has been unlinked). 887 * just overwrite it (because the URB has been unlinked).
879 */ 888 */
880 xhci_giveback_urb_in_irq(xhci, cur_td, 0, "cancelled"); 889 xhci_giveback_urb_in_irq(xhci, cur_td, 0);
881 890
882 /* Stop processing the cancelled list if the watchdog timer is 891 /* Stop processing the cancelled list if the watchdog timer is
883 * running. 892 * running.
@@ -987,7 +996,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
987 if (!list_empty(&cur_td->cancelled_td_list)) 996 if (!list_empty(&cur_td->cancelled_td_list))
988 list_del_init(&cur_td->cancelled_td_list); 997 list_del_init(&cur_td->cancelled_td_list);
989 xhci_giveback_urb_in_irq(xhci, cur_td, 998 xhci_giveback_urb_in_irq(xhci, cur_td,
990 -ESHUTDOWN, "killed"); 999 -ESHUTDOWN);
991 } 1000 }
992 while (!list_empty(&temp_ep->cancelled_td_list)) { 1001 while (!list_empty(&temp_ep->cancelled_td_list)) {
993 cur_td = list_first_entry( 1002 cur_td = list_first_entry(
@@ -996,7 +1005,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
996 cancelled_td_list); 1005 cancelled_td_list);
997 list_del_init(&cur_td->cancelled_td_list); 1006 list_del_init(&cur_td->cancelled_td_list);
998 xhci_giveback_urb_in_irq(xhci, cur_td, 1007 xhci_giveback_urb_in_irq(xhci, cur_td,
999 -ESHUTDOWN, "killed"); 1008 -ESHUTDOWN);
1000 } 1009 }
1001 } 1010 }
1002 } 1011 }
@@ -1063,11 +1072,9 @@ static void update_ring_for_set_deq_completion(struct xhci_hcd *xhci,
1063 * endpoint doorbell to restart the ring, but only if there aren't more 1072 * endpoint doorbell to restart the ring, but only if there aren't more
1064 * cancellations pending. 1073 * cancellations pending.
1065 */ 1074 */
1066static void handle_set_deq_completion(struct xhci_hcd *xhci, 1075static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id,
1067 struct xhci_event_cmd *event, 1076 union xhci_trb *trb, u32 cmd_comp_code)
1068 union xhci_trb *trb)
1069{ 1077{
1070 unsigned int slot_id;
1071 unsigned int ep_index; 1078 unsigned int ep_index;
1072 unsigned int stream_id; 1079 unsigned int stream_id;
1073 struct xhci_ring *ep_ring; 1080 struct xhci_ring *ep_ring;
@@ -1075,7 +1082,6 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1075 struct xhci_ep_ctx *ep_ctx; 1082 struct xhci_ep_ctx *ep_ctx;
1076 struct xhci_slot_ctx *slot_ctx; 1083 struct xhci_slot_ctx *slot_ctx;
1077 1084
1078 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3]));
1079 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); 1085 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3]));
1080 stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2])); 1086 stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2]));
1081 dev = xhci->devs[slot_id]; 1087 dev = xhci->devs[slot_id];
@@ -1093,11 +1099,11 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1093 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); 1099 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
1094 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); 1100 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
1095 1101
1096 if (GET_COMP_CODE(le32_to_cpu(event->status)) != COMP_SUCCESS) { 1102 if (cmd_comp_code != COMP_SUCCESS) {
1097 unsigned int ep_state; 1103 unsigned int ep_state;
1098 unsigned int slot_state; 1104 unsigned int slot_state;
1099 1105
1100 switch (GET_COMP_CODE(le32_to_cpu(event->status))) { 1106 switch (cmd_comp_code) {
1101 case COMP_TRB_ERR: 1107 case COMP_TRB_ERR:
1102 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because " 1108 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because "
1103 "of stream ID configuration\n"); 1109 "of stream ID configuration\n");
@@ -1120,7 +1126,7 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1120 default: 1126 default:
1121 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown " 1127 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown "
1122 "completion code of %u.\n", 1128 "completion code of %u.\n",
1123 GET_COMP_CODE(le32_to_cpu(event->status))); 1129 cmd_comp_code);
1124 break; 1130 break;
1125 } 1131 }
1126 /* OK what do we do now? The endpoint state is hosed, and we 1132 /* OK what do we do now? The endpoint state is hosed, and we
@@ -1157,21 +1163,17 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1157 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); 1163 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1158} 1164}
1159 1165
1160static void handle_reset_ep_completion(struct xhci_hcd *xhci, 1166static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id,
1161 struct xhci_event_cmd *event, 1167 union xhci_trb *trb, u32 cmd_comp_code)
1162 union xhci_trb *trb)
1163{ 1168{
1164 int slot_id;
1165 unsigned int ep_index; 1169 unsigned int ep_index;
1166 1170
1167 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3]));
1168 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); 1171 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3]));
1169 /* This command will only fail if the endpoint wasn't halted, 1172 /* This command will only fail if the endpoint wasn't halted,
1170 * but we don't care. 1173 * but we don't care.
1171 */ 1174 */
1172 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, 1175 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
1173 "Ignoring reset ep completion code of %u", 1176 "Ignoring reset ep completion code of %u", cmd_comp_code);
1174 GET_COMP_CODE(le32_to_cpu(event->status)));
1175 1177
1176 /* HW with the reset endpoint quirk needs to have a configure endpoint 1178 /* HW with the reset endpoint quirk needs to have a configure endpoint
1177 * command complete before the endpoint can be used. Queue that here 1179 * command complete before the endpoint can be used. Queue that here
@@ -1372,21 +1374,149 @@ static int handle_stopped_cmd_ring(struct xhci_hcd *xhci,
1372 return cur_trb_is_good; 1374 return cur_trb_is_good;
1373} 1375}
1374 1376
1377static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id,
1378 u32 cmd_comp_code)
1379{
1380 if (cmd_comp_code == COMP_SUCCESS)
1381 xhci->slot_id = slot_id;
1382 else
1383 xhci->slot_id = 0;
1384 complete(&xhci->addr_dev);
1385}
1386
1387static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id)
1388{
1389 struct xhci_virt_device *virt_dev;
1390
1391 virt_dev = xhci->devs[slot_id];
1392 if (!virt_dev)
1393 return;
1394 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK)
1395 /* Delete default control endpoint resources */
1396 xhci_free_device_endpoint_resources(xhci, virt_dev, true);
1397 xhci_free_virt_device(xhci, slot_id);
1398}
1399
1400static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id,
1401 struct xhci_event_cmd *event, u32 cmd_comp_code)
1402{
1403 struct xhci_virt_device *virt_dev;
1404 struct xhci_input_control_ctx *ctrl_ctx;
1405 unsigned int ep_index;
1406 unsigned int ep_state;
1407 u32 add_flags, drop_flags;
1408
1409 virt_dev = xhci->devs[slot_id];
1410 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1411 return;
1412 /*
1413 * Configure endpoint commands can come from the USB core
1414 * configuration or alt setting changes, or because the HW
1415 * needed an extra configure endpoint command after a reset
1416 * endpoint command or streams were being configured.
1417 * If the command was for a halted endpoint, the xHCI driver
1418 * is not waiting on the configure endpoint command.
1419 */
1420 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
1421 if (!ctrl_ctx) {
1422 xhci_warn(xhci, "Could not get input context, bad type.\n");
1423 return;
1424 }
1425
1426 add_flags = le32_to_cpu(ctrl_ctx->add_flags);
1427 drop_flags = le32_to_cpu(ctrl_ctx->drop_flags);
1428 /* Input ctx add_flags are the endpoint index plus one */
1429 ep_index = xhci_last_valid_endpoint(add_flags) - 1;
1430
1431 /* A usb_set_interface() call directly after clearing a halted
1432 * condition may race on this quirky hardware. Not worth
1433 * worrying about, since this is prototype hardware. Not sure
1434 * if this will work for streams, but streams support was
1435 * untested on this prototype.
1436 */
1437 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
1438 ep_index != (unsigned int) -1 &&
1439 add_flags - SLOT_FLAG == drop_flags) {
1440 ep_state = virt_dev->eps[ep_index].ep_state;
1441 if (!(ep_state & EP_HALTED))
1442 goto bandwidth_change;
1443 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1444 "Completed config ep cmd - "
1445 "last ep index = %d, state = %d",
1446 ep_index, ep_state);
1447 /* Clear internal halted state and restart ring(s) */
1448 virt_dev->eps[ep_index].ep_state &= ~EP_HALTED;
1449 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1450 return;
1451 }
1452bandwidth_change:
1453 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1454 "Completed config ep cmd");
1455 virt_dev->cmd_status = cmd_comp_code;
1456 complete(&virt_dev->cmd_completion);
1457 return;
1458}
1459
1460static void xhci_handle_cmd_eval_ctx(struct xhci_hcd *xhci, int slot_id,
1461 struct xhci_event_cmd *event, u32 cmd_comp_code)
1462{
1463 struct xhci_virt_device *virt_dev;
1464
1465 virt_dev = xhci->devs[slot_id];
1466 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1467 return;
1468 virt_dev->cmd_status = cmd_comp_code;
1469 complete(&virt_dev->cmd_completion);
1470}
1471
1472static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id,
1473 u32 cmd_comp_code)
1474{
1475 xhci->devs[slot_id]->cmd_status = cmd_comp_code;
1476 complete(&xhci->addr_dev);
1477}
1478
1479static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id,
1480 struct xhci_event_cmd *event)
1481{
1482 struct xhci_virt_device *virt_dev;
1483
1484 xhci_dbg(xhci, "Completed reset device command.\n");
1485 virt_dev = xhci->devs[slot_id];
1486 if (virt_dev)
1487 handle_cmd_in_cmd_wait_list(xhci, virt_dev, event);
1488 else
1489 xhci_warn(xhci, "Reset device command completion "
1490 "for disabled slot %u\n", slot_id);
1491}
1492
1493static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci,
1494 struct xhci_event_cmd *event)
1495{
1496 if (!(xhci->quirks & XHCI_NEC_HOST)) {
1497 xhci->error_bitmask |= 1 << 6;
1498 return;
1499 }
1500 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1501 "NEC firmware version %2x.%02x",
1502 NEC_FW_MAJOR(le32_to_cpu(event->status)),
1503 NEC_FW_MINOR(le32_to_cpu(event->status)));
1504}
1505
1375static void handle_cmd_completion(struct xhci_hcd *xhci, 1506static void handle_cmd_completion(struct xhci_hcd *xhci,
1376 struct xhci_event_cmd *event) 1507 struct xhci_event_cmd *event)
1377{ 1508{
1378 int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); 1509 int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
1379 u64 cmd_dma; 1510 u64 cmd_dma;
1380 dma_addr_t cmd_dequeue_dma; 1511 dma_addr_t cmd_dequeue_dma;
1381 struct xhci_input_control_ctx *ctrl_ctx; 1512 u32 cmd_comp_code;
1382 struct xhci_virt_device *virt_dev; 1513 union xhci_trb *cmd_trb;
1383 unsigned int ep_index; 1514 u32 cmd_type;
1384 struct xhci_ring *ep_ring;
1385 unsigned int ep_state;
1386 1515
1387 cmd_dma = le64_to_cpu(event->cmd_trb); 1516 cmd_dma = le64_to_cpu(event->cmd_trb);
1517 cmd_trb = xhci->cmd_ring->dequeue;
1388 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, 1518 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
1389 xhci->cmd_ring->dequeue); 1519 cmd_trb);
1390 /* Is the command ring deq ptr out of sync with the deq seg ptr? */ 1520 /* Is the command ring deq ptr out of sync with the deq seg ptr? */
1391 if (cmd_dequeue_dma == 0) { 1521 if (cmd_dequeue_dma == 0) {
1392 xhci->error_bitmask |= 1 << 4; 1522 xhci->error_bitmask |= 1 << 4;
@@ -1398,135 +1528,69 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1398 return; 1528 return;
1399 } 1529 }
1400 1530
1401 trace_xhci_cmd_completion(&xhci->cmd_ring->dequeue->generic, 1531 trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event);
1402 (struct xhci_generic_trb *) event);
1403 1532
1404 if ((GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_ABORT) || 1533 cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status));
1405 (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_STOP)) { 1534 if (cmd_comp_code == COMP_CMD_ABORT || cmd_comp_code == COMP_CMD_STOP) {
1406 /* If the return value is 0, we think the trb pointed by 1535 /* If the return value is 0, we think the trb pointed by
1407 * command ring dequeue pointer is a good trb. The good 1536 * command ring dequeue pointer is a good trb. The good
1408 * trb means we don't want to cancel the trb, but it have 1537 * trb means we don't want to cancel the trb, but it have
1409 * been stopped by host. So we should handle it normally. 1538 * been stopped by host. So we should handle it normally.
1410 * Otherwise, driver should invoke inc_deq() and return. 1539 * Otherwise, driver should invoke inc_deq() and return.
1411 */ 1540 */
1412 if (handle_stopped_cmd_ring(xhci, 1541 if (handle_stopped_cmd_ring(xhci, cmd_comp_code)) {
1413 GET_COMP_CODE(le32_to_cpu(event->status)))) {
1414 inc_deq(xhci, xhci->cmd_ring); 1542 inc_deq(xhci, xhci->cmd_ring);
1415 return; 1543 return;
1416 } 1544 }
1545 /* There is no command to handle if we get a stop event when the
1546 * command ring is empty, event->cmd_trb points to the next
1547 * unset command
1548 */
1549 if (xhci->cmd_ring->dequeue == xhci->cmd_ring->enqueue)
1550 return;
1417 } 1551 }
1418 1552
1419 switch (le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3]) 1553 cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3]));
1420 & TRB_TYPE_BITMASK) { 1554 switch (cmd_type) {
1421 case TRB_TYPE(TRB_ENABLE_SLOT): 1555 case TRB_ENABLE_SLOT:
1422 if (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_SUCCESS) 1556 xhci_handle_cmd_enable_slot(xhci, slot_id, cmd_comp_code);
1423 xhci->slot_id = slot_id;
1424 else
1425 xhci->slot_id = 0;
1426 complete(&xhci->addr_dev);
1427 break; 1557 break;
1428 case TRB_TYPE(TRB_DISABLE_SLOT): 1558 case TRB_DISABLE_SLOT:
1429 if (xhci->devs[slot_id]) { 1559 xhci_handle_cmd_disable_slot(xhci, slot_id);
1430 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK)
1431 /* Delete default control endpoint resources */
1432 xhci_free_device_endpoint_resources(xhci,
1433 xhci->devs[slot_id], true);
1434 xhci_free_virt_device(xhci, slot_id);
1435 }
1436 break; 1560 break;
1437 case TRB_TYPE(TRB_CONFIG_EP): 1561 case TRB_CONFIG_EP:
1438 virt_dev = xhci->devs[slot_id]; 1562 xhci_handle_cmd_config_ep(xhci, slot_id, event, cmd_comp_code);
1439 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1440 break;
1441 /*
1442 * Configure endpoint commands can come from the USB core
1443 * configuration or alt setting changes, or because the HW
1444 * needed an extra configure endpoint command after a reset
1445 * endpoint command or streams were being configured.
1446 * If the command was for a halted endpoint, the xHCI driver
1447 * is not waiting on the configure endpoint command.
1448 */
1449 ctrl_ctx = xhci_get_input_control_ctx(xhci,
1450 virt_dev->in_ctx);
1451 if (!ctrl_ctx) {
1452 xhci_warn(xhci, "Could not get input context, bad type.\n");
1453 break;
1454 }
1455 /* Input ctx add_flags are the endpoint index plus one */
1456 ep_index = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags)) - 1;
1457 /* A usb_set_interface() call directly after clearing a halted
1458 * condition may race on this quirky hardware. Not worth
1459 * worrying about, since this is prototype hardware. Not sure
1460 * if this will work for streams, but streams support was
1461 * untested on this prototype.
1462 */
1463 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
1464 ep_index != (unsigned int) -1 &&
1465 le32_to_cpu(ctrl_ctx->add_flags) - SLOT_FLAG ==
1466 le32_to_cpu(ctrl_ctx->drop_flags)) {
1467 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
1468 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
1469 if (!(ep_state & EP_HALTED))
1470 goto bandwidth_change;
1471 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1472 "Completed config ep cmd - "
1473 "last ep index = %d, state = %d",
1474 ep_index, ep_state);
1475 /* Clear internal halted state and restart ring(s) */
1476 xhci->devs[slot_id]->eps[ep_index].ep_state &=
1477 ~EP_HALTED;
1478 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1479 break;
1480 }
1481bandwidth_change:
1482 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1483 "Completed config ep cmd");
1484 xhci->devs[slot_id]->cmd_status =
1485 GET_COMP_CODE(le32_to_cpu(event->status));
1486 complete(&xhci->devs[slot_id]->cmd_completion);
1487 break; 1563 break;
1488 case TRB_TYPE(TRB_EVAL_CONTEXT): 1564 case TRB_EVAL_CONTEXT:
1489 virt_dev = xhci->devs[slot_id]; 1565 xhci_handle_cmd_eval_ctx(xhci, slot_id, event, cmd_comp_code);
1490 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1491 break;
1492 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(le32_to_cpu(event->status));
1493 complete(&xhci->devs[slot_id]->cmd_completion);
1494 break; 1566 break;
1495 case TRB_TYPE(TRB_ADDR_DEV): 1567 case TRB_ADDR_DEV:
1496 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(le32_to_cpu(event->status)); 1568 xhci_handle_cmd_addr_dev(xhci, slot_id, cmd_comp_code);
1497 complete(&xhci->addr_dev);
1498 break; 1569 break;
1499 case TRB_TYPE(TRB_STOP_RING): 1570 case TRB_STOP_RING:
1500 handle_stopped_endpoint(xhci, xhci->cmd_ring->dequeue, event); 1571 WARN_ON(slot_id != TRB_TO_SLOT_ID(
1572 le32_to_cpu(cmd_trb->generic.field[3])));
1573 xhci_handle_cmd_stop_ep(xhci, slot_id, cmd_trb, event);
1501 break; 1574 break;
1502 case TRB_TYPE(TRB_SET_DEQ): 1575 case TRB_SET_DEQ:
1503 handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue); 1576 WARN_ON(slot_id != TRB_TO_SLOT_ID(
1577 le32_to_cpu(cmd_trb->generic.field[3])));
1578 xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code);
1504 break; 1579 break;
1505 case TRB_TYPE(TRB_CMD_NOOP): 1580 case TRB_CMD_NOOP:
1506 break; 1581 break;
1507 case TRB_TYPE(TRB_RESET_EP): 1582 case TRB_RESET_EP:
1508 handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); 1583 WARN_ON(slot_id != TRB_TO_SLOT_ID(
1584 le32_to_cpu(cmd_trb->generic.field[3])));
1585 xhci_handle_cmd_reset_ep(xhci, slot_id, cmd_trb, cmd_comp_code);
1509 break; 1586 break;
1510 case TRB_TYPE(TRB_RESET_DEV): 1587 case TRB_RESET_DEV:
1511 xhci_dbg(xhci, "Completed reset device command.\n"); 1588 WARN_ON(slot_id != TRB_TO_SLOT_ID(
1512 slot_id = TRB_TO_SLOT_ID( 1589 le32_to_cpu(cmd_trb->generic.field[3])));
1513 le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])); 1590 xhci_handle_cmd_reset_dev(xhci, slot_id, event);
1514 virt_dev = xhci->devs[slot_id];
1515 if (virt_dev)
1516 handle_cmd_in_cmd_wait_list(xhci, virt_dev, event);
1517 else
1518 xhci_warn(xhci, "Reset device command completion "
1519 "for disabled slot %u\n", slot_id);
1520 break; 1591 break;
1521 case TRB_TYPE(TRB_NEC_GET_FW): 1592 case TRB_NEC_GET_FW:
1522 if (!(xhci->quirks & XHCI_NEC_HOST)) { 1593 xhci_handle_cmd_nec_get_fw(xhci, event);
1523 xhci->error_bitmask |= 1 << 6;
1524 break;
1525 }
1526 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1527 "NEC firmware version %2x.%02x",
1528 NEC_FW_MAJOR(le32_to_cpu(event->status)),
1529 NEC_FW_MINOR(le32_to_cpu(event->status)));
1530 break; 1594 break;
1531 default: 1595 default:
1532 /* Skip over unknown commands on the event ring */ 1596 /* Skip over unknown commands on the event ring */
@@ -1743,6 +1807,19 @@ static void handle_port_status(struct xhci_hcd *xhci,
1743 } 1807 }
1744 } 1808 }
1745 1809
1810 /*
1811 * Check to see if xhci-hub.c is waiting on RExit to U0 transition (or
1812 * RExit to a disconnect state). If so, let the the driver know it's
1813 * out of the RExit state.
1814 */
1815 if (!DEV_SUPERSPEED(temp) &&
1816 test_and_clear_bit(faked_port_index,
1817 &bus_state->rexit_ports)) {
1818 complete(&bus_state->rexit_done[faked_port_index]);
1819 bogus_port_status = true;
1820 goto cleanup;
1821 }
1822
1746 if (hcd->speed != HCD_USB3) 1823 if (hcd->speed != HCD_USB3)
1747 xhci_test_and_clear_bit(xhci, port_array, faked_port_index, 1824 xhci_test_and_clear_bit(xhci, port_array, faked_port_index,
1748 PORT_PLC); 1825 PORT_PLC);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 49b6edb84a79..4265b48856f6 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -730,6 +730,9 @@ void xhci_shutdown(struct usb_hcd *hcd)
730 730
731 spin_lock_irq(&xhci->lock); 731 spin_lock_irq(&xhci->lock);
732 xhci_halt(xhci); 732 xhci_halt(xhci);
733 /* Workaround for spurious wakeups at shutdown with HSW */
734 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
735 xhci_reset(xhci);
733 spin_unlock_irq(&xhci->lock); 736 spin_unlock_irq(&xhci->lock);
734 737
735 xhci_cleanup_msix(xhci); 738 xhci_cleanup_msix(xhci);
@@ -737,6 +740,10 @@ void xhci_shutdown(struct usb_hcd *hcd)
737 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 740 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
738 "xhci_shutdown completed - status = %x", 741 "xhci_shutdown completed - status = %x",
739 xhci_readl(xhci, &xhci->op_regs->status)); 742 xhci_readl(xhci, &xhci->op_regs->status));
743
744 /* Yet another workaround for spurious wakeups at shutdown with HSW */
745 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
746 pci_set_power_state(to_pci_dev(hcd->self.controller), PCI_D3hot);
740} 747}
741 748
742#ifdef CONFIG_PM 749#ifdef CONFIG_PM
@@ -839,6 +846,7 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
839int xhci_suspend(struct xhci_hcd *xhci) 846int xhci_suspend(struct xhci_hcd *xhci)
840{ 847{
841 int rc = 0; 848 int rc = 0;
849 unsigned int delay = XHCI_MAX_HALT_USEC;
842 struct usb_hcd *hcd = xhci_to_hcd(xhci); 850 struct usb_hcd *hcd = xhci_to_hcd(xhci);
843 u32 command; 851 u32 command;
844 852
@@ -861,8 +869,12 @@ int xhci_suspend(struct xhci_hcd *xhci)
861 command = xhci_readl(xhci, &xhci->op_regs->command); 869 command = xhci_readl(xhci, &xhci->op_regs->command);
862 command &= ~CMD_RUN; 870 command &= ~CMD_RUN;
863 xhci_writel(xhci, command, &xhci->op_regs->command); 871 xhci_writel(xhci, command, &xhci->op_regs->command);
872
873 /* Some chips from Fresco Logic need an extraordinary delay */
874 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1;
875
864 if (xhci_handshake(xhci, &xhci->op_regs->status, 876 if (xhci_handshake(xhci, &xhci->op_regs->status,
865 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC)) { 877 STS_HALT, STS_HALT, delay)) {
866 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n"); 878 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n");
867 spin_unlock_irq(&xhci->lock); 879 spin_unlock_irq(&xhci->lock);
868 return -ETIMEDOUT; 880 return -ETIMEDOUT;
@@ -2598,15 +2610,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2598 if (command) { 2610 if (command) {
2599 cmd_completion = command->completion; 2611 cmd_completion = command->completion;
2600 cmd_status = &command->status; 2612 cmd_status = &command->status;
2601 command->command_trb = xhci->cmd_ring->enqueue; 2613 command->command_trb = xhci_find_next_enqueue(xhci->cmd_ring);
2602
2603 /* Enqueue pointer can be left pointing to the link TRB,
2604 * we must handle that
2605 */
2606 if (TRB_TYPE_LINK_LE32(command->command_trb->link.control))
2607 command->command_trb =
2608 xhci->cmd_ring->enq_seg->next->trbs;
2609
2610 list_add_tail(&command->cmd_list, &virt_dev->cmd_list); 2614 list_add_tail(&command->cmd_list, &virt_dev->cmd_list);
2611 } else { 2615 } else {
2612 cmd_completion = &virt_dev->cmd_completion; 2616 cmd_completion = &virt_dev->cmd_completion;
@@ -2614,7 +2618,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2614 } 2618 }
2615 init_completion(cmd_completion); 2619 init_completion(cmd_completion);
2616 2620
2617 cmd_trb = xhci->cmd_ring->dequeue; 2621 cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring);
2618 if (!ctx_change) 2622 if (!ctx_change)
2619 ret = xhci_queue_configure_endpoint(xhci, in_ctx->dma, 2623 ret = xhci_queue_configure_endpoint(xhci, in_ctx->dma,
2620 udev->slot_id, must_succeed); 2624 udev->slot_id, must_succeed);
@@ -3439,14 +3443,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
3439 3443
3440 /* Attempt to submit the Reset Device command to the command ring */ 3444 /* Attempt to submit the Reset Device command to the command ring */
3441 spin_lock_irqsave(&xhci->lock, flags); 3445 spin_lock_irqsave(&xhci->lock, flags);
3442 reset_device_cmd->command_trb = xhci->cmd_ring->enqueue; 3446 reset_device_cmd->command_trb = xhci_find_next_enqueue(xhci->cmd_ring);
3443
3444 /* Enqueue pointer can be left pointing to the link TRB,
3445 * we must handle that
3446 */
3447 if (TRB_TYPE_LINK_LE32(reset_device_cmd->command_trb->link.control))
3448 reset_device_cmd->command_trb =
3449 xhci->cmd_ring->enq_seg->next->trbs;
3450 3447
3451 list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list); 3448 list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list);
3452 ret = xhci_queue_reset_device(xhci, slot_id); 3449 ret = xhci_queue_reset_device(xhci, slot_id);
@@ -3462,7 +3459,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
3462 /* Wait for the Reset Device command to finish */ 3459 /* Wait for the Reset Device command to finish */
3463 timeleft = wait_for_completion_interruptible_timeout( 3460 timeleft = wait_for_completion_interruptible_timeout(
3464 reset_device_cmd->completion, 3461 reset_device_cmd->completion,
3465 USB_CTRL_SET_TIMEOUT); 3462 XHCI_CMD_DEFAULT_TIMEOUT);
3466 if (timeleft <= 0) { 3463 if (timeleft <= 0) {
3467 xhci_warn(xhci, "%s while waiting for reset device command\n", 3464 xhci_warn(xhci, "%s while waiting for reset device command\n",
3468 timeleft == 0 ? "Timeout" : "Signal"); 3465 timeleft == 0 ? "Timeout" : "Signal");
@@ -3586,11 +3583,6 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
3586 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); 3583 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer);
3587 } 3584 }
3588 3585
3589 if (udev->usb2_hw_lpm_enabled) {
3590 xhci_set_usb2_hardware_lpm(hcd, udev, 0);
3591 udev->usb2_hw_lpm_enabled = 0;
3592 }
3593
3594 spin_lock_irqsave(&xhci->lock, flags); 3586 spin_lock_irqsave(&xhci->lock, flags);
3595 /* Don't disable the slot if the host controller is dead. */ 3587 /* Don't disable the slot if the host controller is dead. */
3596 state = xhci_readl(xhci, &xhci->op_regs->status); 3588 state = xhci_readl(xhci, &xhci->op_regs->status);
@@ -3650,7 +3642,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
3650 union xhci_trb *cmd_trb; 3642 union xhci_trb *cmd_trb;
3651 3643
3652 spin_lock_irqsave(&xhci->lock, flags); 3644 spin_lock_irqsave(&xhci->lock, flags);
3653 cmd_trb = xhci->cmd_ring->dequeue; 3645 cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring);
3654 ret = xhci_queue_slot_control(xhci, TRB_ENABLE_SLOT, 0); 3646 ret = xhci_queue_slot_control(xhci, TRB_ENABLE_SLOT, 0);
3655 if (ret) { 3647 if (ret) {
3656 spin_unlock_irqrestore(&xhci->lock, flags); 3648 spin_unlock_irqrestore(&xhci->lock, flags);
@@ -3724,9 +3716,6 @@ disable_slot:
3724 * the device). 3716 * the device).
3725 * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so 3717 * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so
3726 * we should only issue and wait on one address command at the same time. 3718 * we should only issue and wait on one address command at the same time.
3727 *
3728 * We add one to the device address issued by the hardware because the USB core
3729 * uses address 1 for the root hubs (even though they're not really devices).
3730 */ 3719 */
3731int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) 3720int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3732{ 3721{
@@ -3785,7 +3774,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3785 slot_ctx->dev_info >> 27); 3774 slot_ctx->dev_info >> 27);
3786 3775
3787 spin_lock_irqsave(&xhci->lock, flags); 3776 spin_lock_irqsave(&xhci->lock, flags);
3788 cmd_trb = xhci->cmd_ring->dequeue; 3777 cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring);
3789 ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma, 3778 ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma,
3790 udev->slot_id); 3779 udev->slot_id);
3791 if (ret) { 3780 if (ret) {
@@ -3871,16 +3860,13 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3871 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); 3860 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx);
3872 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 3861 trace_xhci_address_ctx(xhci, virt_dev->out_ctx,
3873 slot_ctx->dev_info >> 27); 3862 slot_ctx->dev_info >> 27);
3874 /* Use kernel assigned address for devices; store xHC assigned
3875 * address locally. */
3876 virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK)
3877 + 1;
3878 /* Zero the input context control for later use */ 3863 /* Zero the input context control for later use */
3879 ctrl_ctx->add_flags = 0; 3864 ctrl_ctx->add_flags = 0;
3880 ctrl_ctx->drop_flags = 0; 3865 ctrl_ctx->drop_flags = 0;
3881 3866
3882 xhci_dbg_trace(xhci, trace_xhci_dbg_address, 3867 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3883 "Internal device address = %d", virt_dev->address); 3868 "Internal device address = %d",
3869 le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK);
3884 3870
3885 return 0; 3871 return 0;
3886} 3872}
@@ -4028,133 +4014,6 @@ static int xhci_calculate_usb2_hw_lpm_params(struct usb_device *udev)
4028 return PORT_BESLD(besld) | PORT_L1_TIMEOUT(l1) | PORT_HIRDM(hirdm); 4014 return PORT_BESLD(besld) | PORT_L1_TIMEOUT(l1) | PORT_HIRDM(hirdm);
4029} 4015}
4030 4016
4031static int xhci_usb2_software_lpm_test(struct usb_hcd *hcd,
4032 struct usb_device *udev)
4033{
4034 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
4035 struct dev_info *dev_info;
4036 __le32 __iomem **port_array;
4037 __le32 __iomem *addr, *pm_addr;
4038 u32 temp, dev_id;
4039 unsigned int port_num;
4040 unsigned long flags;
4041 int hird;
4042 int ret;
4043
4044 if (hcd->speed == HCD_USB3 || !xhci->sw_lpm_support ||
4045 !udev->lpm_capable)
4046 return -EINVAL;
4047
4048 /* we only support lpm for non-hub device connected to root hub yet */
4049 if (!udev->parent || udev->parent->parent ||
4050 udev->descriptor.bDeviceClass == USB_CLASS_HUB)
4051 return -EINVAL;
4052
4053 spin_lock_irqsave(&xhci->lock, flags);
4054
4055 /* Look for devices in lpm_failed_devs list */
4056 dev_id = le16_to_cpu(udev->descriptor.idVendor) << 16 |
4057 le16_to_cpu(udev->descriptor.idProduct);
4058 list_for_each_entry(dev_info, &xhci->lpm_failed_devs, list) {
4059 if (dev_info->dev_id == dev_id) {
4060 ret = -EINVAL;
4061 goto finish;
4062 }
4063 }
4064
4065 port_array = xhci->usb2_ports;
4066 port_num = udev->portnum - 1;
4067
4068 if (port_num > HCS_MAX_PORTS(xhci->hcs_params1)) {
4069 xhci_dbg(xhci, "invalid port number %d\n", udev->portnum);
4070 ret = -EINVAL;
4071 goto finish;
4072 }
4073
4074 /*
4075 * Test USB 2.0 software LPM.
4076 * FIXME: some xHCI 1.0 hosts may implement a new register to set up
4077 * hardware-controlled USB 2.0 LPM. See section 5.4.11 and 4.23.5.1.1.1
4078 * in the June 2011 errata release.
4079 */
4080 xhci_dbg(xhci, "test port %d software LPM\n", port_num);
4081 /*
4082 * Set L1 Device Slot and HIRD/BESL.
4083 * Check device's USB 2.0 extension descriptor to determine whether
4084 * HIRD or BESL shoule be used. See USB2.0 LPM errata.
4085 */
4086 pm_addr = port_array[port_num] + PORTPMSC;
4087 hird = xhci_calculate_hird_besl(xhci, udev);
4088 temp = PORT_L1DS(udev->slot_id) | PORT_HIRD(hird);
4089 xhci_writel(xhci, temp, pm_addr);
4090
4091 /* Set port link state to U2(L1) */
4092 addr = port_array[port_num];
4093 xhci_set_link_state(xhci, port_array, port_num, XDEV_U2);
4094
4095 /* wait for ACK */
4096 spin_unlock_irqrestore(&xhci->lock, flags);
4097 msleep(10);
4098 spin_lock_irqsave(&xhci->lock, flags);
4099
4100 /* Check L1 Status */
4101 ret = xhci_handshake(xhci, pm_addr,
4102 PORT_L1S_MASK, PORT_L1S_SUCCESS, 125);
4103 if (ret != -ETIMEDOUT) {
4104 /* enter L1 successfully */
4105 temp = xhci_readl(xhci, addr);
4106 xhci_dbg(xhci, "port %d entered L1 state, port status 0x%x\n",
4107 port_num, temp);
4108 ret = 0;
4109 } else {
4110 temp = xhci_readl(xhci, pm_addr);
4111 xhci_dbg(xhci, "port %d software lpm failed, L1 status %d\n",
4112 port_num, temp & PORT_L1S_MASK);
4113 ret = -EINVAL;
4114 }
4115
4116 /* Resume the port */
4117 xhci_set_link_state(xhci, port_array, port_num, XDEV_U0);
4118
4119 spin_unlock_irqrestore(&xhci->lock, flags);
4120 msleep(10);
4121 spin_lock_irqsave(&xhci->lock, flags);
4122
4123 /* Clear PLC */
4124 xhci_test_and_clear_bit(xhci, port_array, port_num, PORT_PLC);
4125
4126 /* Check PORTSC to make sure the device is in the right state */
4127 if (!ret) {
4128 temp = xhci_readl(xhci, addr);
4129 xhci_dbg(xhci, "resumed port %d status 0x%x\n", port_num, temp);
4130 if (!(temp & PORT_CONNECT) || !(temp & PORT_PE) ||
4131 (temp & PORT_PLS_MASK) != XDEV_U0) {
4132 xhci_dbg(xhci, "port L1 resume fail\n");
4133 ret = -EINVAL;
4134 }
4135 }
4136
4137 if (ret) {
4138 /* Insert dev to lpm_failed_devs list */
4139 xhci_warn(xhci, "device LPM test failed, may disconnect and "
4140 "re-enumerate\n");
4141 dev_info = kzalloc(sizeof(struct dev_info), GFP_ATOMIC);
4142 if (!dev_info) {
4143 ret = -ENOMEM;
4144 goto finish;
4145 }
4146 dev_info->dev_id = dev_id;
4147 INIT_LIST_HEAD(&dev_info->list);
4148 list_add(&dev_info->list, &xhci->lpm_failed_devs);
4149 } else {
4150 xhci_ring_device(xhci, udev->slot_id);
4151 }
4152
4153finish:
4154 spin_unlock_irqrestore(&xhci->lock, flags);
4155 return ret;
4156}
4157
4158int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, 4017int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
4159 struct usb_device *udev, int enable) 4018 struct usb_device *udev, int enable)
4160{ 4019{
@@ -4231,7 +4090,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
4231 } 4090 }
4232 4091
4233 pm_val &= ~PORT_HIRD_MASK; 4092 pm_val &= ~PORT_HIRD_MASK;
4234 pm_val |= PORT_HIRD(hird) | PORT_RWE; 4093 pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id);
4235 xhci_writel(xhci, pm_val, pm_addr); 4094 xhci_writel(xhci, pm_val, pm_addr);
4236 pm_val = xhci_readl(xhci, pm_addr); 4095 pm_val = xhci_readl(xhci, pm_addr);
4237 pm_val |= PORT_HLE; 4096 pm_val |= PORT_HLE;
@@ -4239,7 +4098,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
4239 /* flush write */ 4098 /* flush write */
4240 xhci_readl(xhci, pm_addr); 4099 xhci_readl(xhci, pm_addr);
4241 } else { 4100 } else {
4242 pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK); 4101 pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK | PORT_L1DS_MASK);
4243 xhci_writel(xhci, pm_val, pm_addr); 4102 xhci_writel(xhci, pm_val, pm_addr);
4244 /* flush write */ 4103 /* flush write */
4245 xhci_readl(xhci, pm_addr); 4104 xhci_readl(xhci, pm_addr);
@@ -4282,24 +4141,26 @@ static int xhci_check_usb2_port_capability(struct xhci_hcd *xhci, int port,
4282int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) 4141int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
4283{ 4142{
4284 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 4143 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
4285 int ret;
4286 int portnum = udev->portnum - 1; 4144 int portnum = udev->portnum - 1;
4287 4145
4288 ret = xhci_usb2_software_lpm_test(hcd, udev); 4146 if (hcd->speed == HCD_USB3 || !xhci->sw_lpm_support ||
4289 if (!ret) { 4147 !udev->lpm_capable)
4290 xhci_dbg(xhci, "software LPM test succeed\n"); 4148 return 0;
4291 if (xhci->hw_lpm_support == 1 && 4149
4292 xhci_check_usb2_port_capability(xhci, portnum, XHCI_HLC)) { 4150 /* we only support lpm for non-hub device connected to root hub yet */
4293 udev->usb2_hw_lpm_capable = 1; 4151 if (!udev->parent || udev->parent->parent ||
4294 udev->l1_params.timeout = XHCI_L1_TIMEOUT; 4152 udev->descriptor.bDeviceClass == USB_CLASS_HUB)
4295 udev->l1_params.besl = XHCI_DEFAULT_BESL; 4153 return 0;
4296 if (xhci_check_usb2_port_capability(xhci, portnum, 4154
4297 XHCI_BLC)) 4155 if (xhci->hw_lpm_support == 1 &&
4298 udev->usb2_hw_lpm_besl_capable = 1; 4156 xhci_check_usb2_port_capability(
4299 ret = xhci_set_usb2_hardware_lpm(hcd, udev, 1); 4157 xhci, portnum, XHCI_HLC)) {
4300 if (!ret) 4158 udev->usb2_hw_lpm_capable = 1;
4301 udev->usb2_hw_lpm_enabled = 1; 4159 udev->l1_params.timeout = XHCI_L1_TIMEOUT;
4302 } 4160 udev->l1_params.besl = XHCI_DEFAULT_BESL;
4161 if (xhci_check_usb2_port_capability(xhci, portnum,
4162 XHCI_BLC))
4163 udev->usb2_hw_lpm_besl_capable = 1;
4303 } 4164 }
4304 4165
4305 return 0; 4166 return 0;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 46aa14894148..03c74b7965f8 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -383,6 +383,7 @@ struct xhci_op_regs {
383#define PORT_RWE (1 << 3) 383#define PORT_RWE (1 << 3)
384#define PORT_HIRD(p) (((p) & 0xf) << 4) 384#define PORT_HIRD(p) (((p) & 0xf) << 4)
385#define PORT_HIRD_MASK (0xf << 4) 385#define PORT_HIRD_MASK (0xf << 4)
386#define PORT_L1DS_MASK (0xff << 8)
386#define PORT_L1DS(p) (((p) & 0xff) << 8) 387#define PORT_L1DS(p) (((p) & 0xff) << 8)
387#define PORT_HLE (1 << 16) 388#define PORT_HLE (1 << 16)
388 389
@@ -934,8 +935,6 @@ struct xhci_virt_device {
934 /* Rings saved to ensure old alt settings can be re-instated */ 935 /* Rings saved to ensure old alt settings can be re-instated */
935 struct xhci_ring **ring_cache; 936 struct xhci_ring **ring_cache;
936 int num_rings_cached; 937 int num_rings_cached;
937 /* Store xHC assigned device address */
938 int address;
939#define XHCI_MAX_RINGS_CACHED 31 938#define XHCI_MAX_RINGS_CACHED 31
940 struct xhci_virt_ep eps[31]; 939 struct xhci_virt_ep eps[31];
941 struct completion cmd_completion; 940 struct completion cmd_completion;
@@ -1412,8 +1411,18 @@ struct xhci_bus_state {
1412 unsigned long resume_done[USB_MAXCHILDREN]; 1411 unsigned long resume_done[USB_MAXCHILDREN];
1413 /* which ports have started to resume */ 1412 /* which ports have started to resume */
1414 unsigned long resuming_ports; 1413 unsigned long resuming_ports;
1414 /* Which ports are waiting on RExit to U0 transition. */
1415 unsigned long rexit_ports;
1416 struct completion rexit_done[USB_MAXCHILDREN];
1415}; 1417};
1416 1418
1419
1420/*
1421 * It can take up to 20 ms to transition from RExit to U0 on the
1422 * Intel Lynx Point LP xHCI host.
1423 */
1424#define XHCI_MAX_REXIT_TIMEOUT (20 * 1000)
1425
1417static inline unsigned int hcd_index(struct usb_hcd *hcd) 1426static inline unsigned int hcd_index(struct usb_hcd *hcd)
1418{ 1427{
1419 if (hcd->speed == HCD_USB3) 1428 if (hcd->speed == HCD_USB3)
@@ -1538,6 +1547,8 @@ struct xhci_hcd {
1538#define XHCI_COMP_MODE_QUIRK (1 << 14) 1547#define XHCI_COMP_MODE_QUIRK (1 << 14)
1539#define XHCI_AVOID_BEI (1 << 15) 1548#define XHCI_AVOID_BEI (1 << 15)
1540#define XHCI_PLAT (1 << 16) 1549#define XHCI_PLAT (1 << 16)
1550#define XHCI_SLOW_SUSPEND (1 << 17)
1551#define XHCI_SPURIOUS_WAKEUP (1 << 18)
1541 unsigned int num_active_eps; 1552 unsigned int num_active_eps;
1542 unsigned int limit_active_eps; 1553 unsigned int limit_active_eps;
1543 /* There are two roothubs to keep track of bus suspend info for */ 1554 /* There are two roothubs to keep track of bus suspend info for */
@@ -1840,6 +1851,7 @@ int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command,
1840 union xhci_trb *cmd_trb); 1851 union xhci_trb *cmd_trb);
1841void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, 1852void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
1842 unsigned int ep_index, unsigned int stream_id); 1853 unsigned int ep_index, unsigned int stream_id);
1854union xhci_trb *xhci_find_next_enqueue(struct xhci_ring *ring);
1843 1855
1844/* xHCI roothub code */ 1856/* xHCI roothub code */
1845void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array, 1857void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index e2b21c1d9c40..ba5f70f92888 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -246,6 +246,6 @@ config USB_EZUSB_FX2
246config USB_HSIC_USB3503 246config USB_HSIC_USB3503
247 tristate "USB3503 HSIC to USB20 Driver" 247 tristate "USB3503 HSIC to USB20 Driver"
248 depends on I2C 248 depends on I2C
249 select REGMAP 249 select REGMAP_I2C
250 help 250 help
251 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/usbtest.c b/drivers/usb/misc/usbtest.c
index aa28ac8c7607..b4152820d655 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -120,7 +120,7 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
120 struct usb_host_endpoint *e; 120 struct usb_host_endpoint *e;
121 121
122 e = alt->endpoint + ep; 122 e = alt->endpoint + ep;
123 switch (e->desc.bmAttributes) { 123 switch (usb_endpoint_type(&e->desc)) {
124 case USB_ENDPOINT_XFER_BULK: 124 case USB_ENDPOINT_XFER_BULK:
125 break; 125 break;
126 case USB_ENDPOINT_XFER_ISOC: 126 case USB_ENDPOINT_XFER_ISOC:
@@ -437,7 +437,7 @@ alloc_sglist(int nents, int max, int vary)
437 if (max == 0) 437 if (max == 0)
438 return NULL; 438 return NULL;
439 439
440 sg = kmalloc_array(nents, sizeof *sg, GFP_KERNEL); 440 sg = kmalloc_array(nents, sizeof(*sg), GFP_KERNEL);
441 if (!sg) 441 if (!sg)
442 return NULL; 442 return NULL;
443 sg_init_table(sg, nents); 443 sg_init_table(sg, nents);
@@ -573,7 +573,7 @@ static int is_good_config(struct usbtest_dev *tdev, int len)
573{ 573{
574 struct usb_config_descriptor *config; 574 struct usb_config_descriptor *config;
575 575
576 if (len < sizeof *config) 576 if (len < sizeof(*config))
577 return 0; 577 return 0;
578 config = (struct usb_config_descriptor *) tdev->buf; 578 config = (struct usb_config_descriptor *) tdev->buf;
579 579
@@ -606,6 +606,76 @@ static int is_good_config(struct usbtest_dev *tdev, int len)
606 return 0; 606 return 0;
607} 607}
608 608
609static int is_good_ext(struct usbtest_dev *tdev, u8 *buf)
610{
611 struct usb_ext_cap_descriptor *ext;
612 u32 attr;
613
614 ext = (struct usb_ext_cap_descriptor *) buf;
615
616 if (ext->bLength != USB_DT_USB_EXT_CAP_SIZE) {
617 ERROR(tdev, "bogus usb 2.0 extension descriptor length\n");
618 return 0;
619 }
620
621 attr = le32_to_cpu(ext->bmAttributes);
622 /* bits[1:4] is used and others are reserved */
623 if (attr & ~0x1e) { /* reserved == 0 */
624 ERROR(tdev, "reserved bits set\n");
625 return 0;
626 }
627
628 return 1;
629}
630
631static int is_good_ss_cap(struct usbtest_dev *tdev, u8 *buf)
632{
633 struct usb_ss_cap_descriptor *ss;
634
635 ss = (struct usb_ss_cap_descriptor *) buf;
636
637 if (ss->bLength != USB_DT_USB_SS_CAP_SIZE) {
638 ERROR(tdev, "bogus superspeed device capability descriptor length\n");
639 return 0;
640 }
641
642 /*
643 * only bit[1] of bmAttributes is used for LTM and others are
644 * reserved
645 */
646 if (ss->bmAttributes & ~0x02) { /* reserved == 0 */
647 ERROR(tdev, "reserved bits set in bmAttributes\n");
648 return 0;
649 }
650
651 /* bits[0:3] of wSpeedSupported is used and others are reserved */
652 if (le16_to_cpu(ss->wSpeedSupported) & ~0x0f) { /* reserved == 0 */
653 ERROR(tdev, "reserved bits set in wSpeedSupported\n");
654 return 0;
655 }
656
657 return 1;
658}
659
660static int is_good_con_id(struct usbtest_dev *tdev, u8 *buf)
661{
662 struct usb_ss_container_id_descriptor *con_id;
663
664 con_id = (struct usb_ss_container_id_descriptor *) buf;
665
666 if (con_id->bLength != USB_DT_USB_SS_CONTN_ID_SIZE) {
667 ERROR(tdev, "bogus container id descriptor length\n");
668 return 0;
669 }
670
671 if (con_id->bReserved) { /* reserved == 0 */
672 ERROR(tdev, "reserved bits set\n");
673 return 0;
674 }
675
676 return 1;
677}
678
609/* sanity test for standard requests working with usb_control_mesg() and some 679/* sanity test for standard requests working with usb_control_mesg() and some
610 * of the utility functions which use it. 680 * of the utility functions which use it.
611 * 681 *
@@ -683,12 +753,96 @@ static int ch9_postconfig(struct usbtest_dev *dev)
683 753
684 /* there's always [9.4.3] a device descriptor [9.6.1] */ 754 /* there's always [9.4.3] a device descriptor [9.6.1] */
685 retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0, 755 retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0,
686 dev->buf, sizeof udev->descriptor); 756 dev->buf, sizeof(udev->descriptor));
687 if (retval != sizeof udev->descriptor) { 757 if (retval != sizeof(udev->descriptor)) {
688 dev_err(&iface->dev, "dev descriptor --> %d\n", retval); 758 dev_err(&iface->dev, "dev descriptor --> %d\n", retval);
689 return (retval < 0) ? retval : -EDOM; 759 return (retval < 0) ? retval : -EDOM;
690 } 760 }
691 761
762 /*
763 * there's always [9.4.3] a bos device descriptor [9.6.2] in USB
764 * 3.0 spec
765 */
766 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0300) {
767 struct usb_bos_descriptor *bos = NULL;
768 struct usb_dev_cap_header *header = NULL;
769 unsigned total, num, length;
770 u8 *buf;
771
772 retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf,
773 sizeof(*udev->bos->desc));
774 if (retval != sizeof(*udev->bos->desc)) {
775 dev_err(&iface->dev, "bos descriptor --> %d\n", retval);
776 return (retval < 0) ? retval : -EDOM;
777 }
778
779 bos = (struct usb_bos_descriptor *)dev->buf;
780 total = le16_to_cpu(bos->wTotalLength);
781 num = bos->bNumDeviceCaps;
782
783 if (total > TBUF_SIZE)
784 total = TBUF_SIZE;
785
786 /*
787 * get generic device-level capability descriptors [9.6.2]
788 * in USB 3.0 spec
789 */
790 retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf,
791 total);
792 if (retval != total) {
793 dev_err(&iface->dev, "bos descriptor set --> %d\n",
794 retval);
795 return (retval < 0) ? retval : -EDOM;
796 }
797
798 length = sizeof(*udev->bos->desc);
799 buf = dev->buf;
800 for (i = 0; i < num; i++) {
801 buf += length;
802 if (buf + sizeof(struct usb_dev_cap_header) >
803 dev->buf + total)
804 break;
805
806 header = (struct usb_dev_cap_header *)buf;
807 length = header->bLength;
808
809 if (header->bDescriptorType !=
810 USB_DT_DEVICE_CAPABILITY) {
811 dev_warn(&udev->dev, "not device capability descriptor, skip\n");
812 continue;
813 }
814
815 switch (header->bDevCapabilityType) {
816 case USB_CAP_TYPE_EXT:
817 if (buf + USB_DT_USB_EXT_CAP_SIZE >
818 dev->buf + total ||
819 !is_good_ext(dev, buf)) {
820 dev_err(&iface->dev, "bogus usb 2.0 extension descriptor\n");
821 return -EDOM;
822 }
823 break;
824 case USB_SS_CAP_TYPE:
825 if (buf + USB_DT_USB_SS_CAP_SIZE >
826 dev->buf + total ||
827 !is_good_ss_cap(dev, buf)) {
828 dev_err(&iface->dev, "bogus superspeed device capability descriptor\n");
829 return -EDOM;
830 }
831 break;
832 case CONTAINER_ID_TYPE:
833 if (buf + USB_DT_USB_SS_CONTN_ID_SIZE >
834 dev->buf + total ||
835 !is_good_con_id(dev, buf)) {
836 dev_err(&iface->dev, "bogus container id descriptor\n");
837 return -EDOM;
838 }
839 break;
840 default:
841 break;
842 }
843 }
844 }
845
692 /* there's always [9.4.3] at least one config descriptor [9.6.3] */ 846 /* there's always [9.4.3] at least one config descriptor [9.6.3] */
693 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { 847 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) {
694 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i, 848 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i,
@@ -954,7 +1108,7 @@ test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
954 * device, but some are chosen to trigger protocol stalls 1108 * device, but some are chosen to trigger protocol stalls
955 * or short reads. 1109 * or short reads.
956 */ 1110 */
957 memset(&req, 0, sizeof req); 1111 memset(&req, 0, sizeof(req));
958 req.bRequest = USB_REQ_GET_DESCRIPTOR; 1112 req.bRequest = USB_REQ_GET_DESCRIPTOR;
959 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 1113 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
960 1114
@@ -1074,7 +1228,7 @@ test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
1074 if (!u) 1228 if (!u)
1075 goto cleanup; 1229 goto cleanup;
1076 1230
1077 reqp = kmalloc(sizeof *reqp, GFP_KERNEL); 1231 reqp = kmalloc(sizeof(*reqp), GFP_KERNEL);
1078 if (!reqp) 1232 if (!reqp)
1079 goto cleanup; 1233 goto cleanup;
1080 reqp->setup = req; 1234 reqp->setup = req;
@@ -1667,13 +1821,13 @@ test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
1667 if (param->sglen > 10) 1821 if (param->sglen > 10)
1668 return -EDOM; 1822 return -EDOM;
1669 1823
1670 memset(&context, 0, sizeof context); 1824 memset(&context, 0, sizeof(context));
1671 context.count = param->iterations * param->sglen; 1825 context.count = param->iterations * param->sglen;
1672 context.dev = dev; 1826 context.dev = dev;
1673 init_completion(&context.done); 1827 init_completion(&context.done);
1674 spin_lock_init(&context.lock); 1828 spin_lock_init(&context.lock);
1675 1829
1676 memset(urbs, 0, sizeof urbs); 1830 memset(urbs, 0, sizeof(urbs));
1677 udev = testdev_to_usbdev(dev); 1831 udev = testdev_to_usbdev(dev);
1678 dev_info(&dev->intf->dev, 1832 dev_info(&dev->intf->dev,
1679 "... iso period %d %sframes, wMaxPacket %04x\n", 1833 "... iso period %d %sframes, wMaxPacket %04x\n",
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index c64ee09a7c0e..57dfc0cedb00 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -71,11 +71,11 @@ config USB_MUSB_DA8XX
71 71
72config USB_MUSB_TUSB6010 72config USB_MUSB_TUSB6010
73 tristate "TUSB6010" 73 tristate "TUSB6010"
74 depends on GENERIC_HARDIRQS
75 74
76config USB_MUSB_OMAP2PLUS 75config USB_MUSB_OMAP2PLUS
77 tristate "OMAP2430 and onwards" 76 tristate "OMAP2430 and onwards"
78 depends on ARCH_OMAP2PLUS 77 depends on ARCH_OMAP2PLUS
78 select GENERIC_PHY
79 79
80config USB_MUSB_AM35X 80config USB_MUSB_AM35X
81 tristate "AM35x" 81 tristate "AM35x"
@@ -91,7 +91,7 @@ config USB_MUSB_BLACKFIN
91 depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523) 91 depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523)
92 92
93config USB_MUSB_UX500 93config USB_MUSB_UX500
94 tristate "U8500 and U5500" 94 tristate "Ux500 platforms"
95 95
96endchoice 96endchoice
97 97
@@ -113,7 +113,7 @@ choice
113 allow using DMA on multiplatform kernels. 113 allow using DMA on multiplatform kernels.
114 114
115config USB_UX500_DMA 115config USB_UX500_DMA
116 bool 'ST Ericsson U8500 and U5500' 116 bool 'ST Ericsson Ux500'
117 depends on USB_MUSB_UX500 117 depends on USB_MUSB_UX500
118 help 118 help
119 Enable DMA transfers on UX500 platforms. 119 Enable DMA transfers on UX500 platforms.
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 5c310c664218..ca45b39db5b9 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -89,7 +89,6 @@ struct am35x_glue {
89 struct clk *phy_clk; 89 struct clk *phy_clk;
90 struct clk *clk; 90 struct clk *clk;
91}; 91};
92#define glue_to_musb(g) platform_get_drvdata(g->musb)
93 92
94/* 93/*
95 * am35x_musb_enable - enable interrupts 94 * am35x_musb_enable - enable interrupts
@@ -452,14 +451,18 @@ static const struct musb_platform_ops am35x_ops = {
452 .set_vbus = am35x_musb_set_vbus, 451 .set_vbus = am35x_musb_set_vbus,
453}; 452};
454 453
455static u64 am35x_dmamask = DMA_BIT_MASK(32); 454static const struct platform_device_info am35x_dev_info = {
455 .name = "musb-hdrc",
456 .id = PLATFORM_DEVID_AUTO,
457 .dma_mask = DMA_BIT_MASK(32),
458};
456 459
457static int am35x_probe(struct platform_device *pdev) 460static int am35x_probe(struct platform_device *pdev)
458{ 461{
459 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 462 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
460 struct platform_device *musb; 463 struct platform_device *musb;
461 struct am35x_glue *glue; 464 struct am35x_glue *glue;
462 465 struct platform_device_info pinfo;
463 struct clk *phy_clk; 466 struct clk *phy_clk;
464 struct clk *clk; 467 struct clk *clk;
465 468
@@ -471,12 +474,6 @@ static int am35x_probe(struct platform_device *pdev)
471 goto err0; 474 goto err0;
472 } 475 }
473 476
474 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
475 if (!musb) {
476 dev_err(&pdev->dev, "failed to allocate musb device\n");
477 goto err1;
478 }
479
480 phy_clk = clk_get(&pdev->dev, "fck"); 477 phy_clk = clk_get(&pdev->dev, "fck");
481 if (IS_ERR(phy_clk)) { 478 if (IS_ERR(phy_clk)) {
482 dev_err(&pdev->dev, "failed to get PHY clock\n"); 479 dev_err(&pdev->dev, "failed to get PHY clock\n");
@@ -503,12 +500,7 @@ static int am35x_probe(struct platform_device *pdev)
503 goto err6; 500 goto err6;
504 } 501 }
505 502
506 musb->dev.parent = &pdev->dev;
507 musb->dev.dma_mask = &am35x_dmamask;
508 musb->dev.coherent_dma_mask = am35x_dmamask;
509
510 glue->dev = &pdev->dev; 503 glue->dev = &pdev->dev;
511 glue->musb = musb;
512 glue->phy_clk = phy_clk; 504 glue->phy_clk = phy_clk;
513 glue->clk = clk; 505 glue->clk = clk;
514 506
@@ -516,22 +508,17 @@ static int am35x_probe(struct platform_device *pdev)
516 508
517 platform_set_drvdata(pdev, glue); 509 platform_set_drvdata(pdev, glue);
518 510
519 ret = platform_device_add_resources(musb, pdev->resource, 511 pinfo = am35x_dev_info;
520 pdev->num_resources); 512 pinfo.parent = &pdev->dev;
521 if (ret) { 513 pinfo.res = pdev->resource;
522 dev_err(&pdev->dev, "failed to add resources\n"); 514 pinfo.num_res = pdev->num_resources;
523 goto err7; 515 pinfo.data = pdata;
524 } 516 pinfo.size_data = sizeof(*pdata);
525 517
526 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 518 glue->musb = musb = platform_device_register_full(&pinfo);
527 if (ret) { 519 if (IS_ERR(musb)) {
528 dev_err(&pdev->dev, "failed to add platform_data\n"); 520 ret = PTR_ERR(musb);
529 goto err7; 521 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
530 }
531
532 ret = platform_device_add(musb);
533 if (ret) {
534 dev_err(&pdev->dev, "failed to register musb device\n");
535 goto err7; 522 goto err7;
536 } 523 }
537 524
@@ -550,9 +537,6 @@ err4:
550 clk_put(phy_clk); 537 clk_put(phy_clk);
551 538
552err3: 539err3:
553 platform_device_put(musb);
554
555err1:
556 kfree(glue); 540 kfree(glue);
557 541
558err0: 542err0:
@@ -615,23 +599,16 @@ static int am35x_resume(struct device *dev)
615 599
616 return 0; 600 return 0;
617} 601}
618
619static struct dev_pm_ops am35x_pm_ops = {
620 .suspend = am35x_suspend,
621 .resume = am35x_resume,
622};
623
624#define DEV_PM_OPS &am35x_pm_ops
625#else
626#define DEV_PM_OPS NULL
627#endif 602#endif
628 603
604static SIMPLE_DEV_PM_OPS(am35x_pm_ops, am35x_suspend, am35x_resume);
605
629static struct platform_driver am35x_driver = { 606static struct platform_driver am35x_driver = {
630 .probe = am35x_probe, 607 .probe = am35x_probe,
631 .remove = am35x_remove, 608 .remove = am35x_remove,
632 .driver = { 609 .driver = {
633 .name = "musb-am35x", 610 .name = "musb-am35x",
634 .pm = DEV_PM_OPS, 611 .pm = &am35x_pm_ops,
635 }, 612 },
636}; 613};
637 614
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index 72e2056b6082..d9692f78e227 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -561,23 +561,16 @@ static int bfin_resume(struct device *dev)
561 561
562 return 0; 562 return 0;
563} 563}
564
565static struct dev_pm_ops bfin_pm_ops = {
566 .suspend = bfin_suspend,
567 .resume = bfin_resume,
568};
569
570#define DEV_PM_OPS &bfin_pm_ops
571#else
572#define DEV_PM_OPS NULL
573#endif 564#endif
574 565
566static SIMPLE_DEV_PM_OPS(bfin_pm_ops, bfin_suspend, bfin_resume);
567
575static struct platform_driver bfin_driver = { 568static struct platform_driver bfin_driver = {
576 .probe = bfin_probe, 569 .probe = bfin_probe,
577 .remove = __exit_p(bfin_remove), 570 .remove = __exit_p(bfin_remove),
578 .driver = { 571 .driver = {
579 .name = "musb-blackfin", 572 .name = "musb-blackfin",
580 .pm = DEV_PM_OPS, 573 .pm = &bfin_pm_ops,
581 }, 574 },
582}; 575};
583 576
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index d9ddf4122f37..2f2c1cb36421 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -472,7 +472,11 @@ static const struct musb_platform_ops da8xx_ops = {
472 .set_vbus = da8xx_musb_set_vbus, 472 .set_vbus = da8xx_musb_set_vbus,
473}; 473};
474 474
475static u64 da8xx_dmamask = DMA_BIT_MASK(32); 475static const struct platform_device_info da8xx_dev_info = {
476 .name = "musb-hdrc",
477 .id = PLATFORM_DEVID_AUTO,
478 .dma_mask = DMA_BIT_MASK(32),
479};
476 480
477static int da8xx_probe(struct platform_device *pdev) 481static int da8xx_probe(struct platform_device *pdev)
478{ 482{
@@ -480,7 +484,7 @@ static int da8xx_probe(struct platform_device *pdev)
480 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 484 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
481 struct platform_device *musb; 485 struct platform_device *musb;
482 struct da8xx_glue *glue; 486 struct da8xx_glue *glue;
483 487 struct platform_device_info pinfo;
484 struct clk *clk; 488 struct clk *clk;
485 489
486 int ret = -ENOMEM; 490 int ret = -ENOMEM;
@@ -491,12 +495,6 @@ static int da8xx_probe(struct platform_device *pdev)
491 goto err0; 495 goto err0;
492 } 496 }
493 497
494 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
495 if (!musb) {
496 dev_err(&pdev->dev, "failed to allocate musb device\n");
497 goto err1;
498 }
499
500 clk = clk_get(&pdev->dev, "usb20"); 498 clk = clk_get(&pdev->dev, "usb20");
501 if (IS_ERR(clk)) { 499 if (IS_ERR(clk)) {
502 dev_err(&pdev->dev, "failed to get clock\n"); 500 dev_err(&pdev->dev, "failed to get clock\n");
@@ -510,12 +508,7 @@ static int da8xx_probe(struct platform_device *pdev)
510 goto err4; 508 goto err4;
511 } 509 }
512 510
513 musb->dev.parent = &pdev->dev;
514 musb->dev.dma_mask = &da8xx_dmamask;
515 musb->dev.coherent_dma_mask = da8xx_dmamask;
516
517 glue->dev = &pdev->dev; 511 glue->dev = &pdev->dev;
518 glue->musb = musb;
519 glue->clk = clk; 512 glue->clk = clk;
520 513
521 pdata->platform_ops = &da8xx_ops; 514 pdata->platform_ops = &da8xx_ops;
@@ -535,22 +528,17 @@ static int da8xx_probe(struct platform_device *pdev)
535 musb_resources[1].end = pdev->resource[1].end; 528 musb_resources[1].end = pdev->resource[1].end;
536 musb_resources[1].flags = pdev->resource[1].flags; 529 musb_resources[1].flags = pdev->resource[1].flags;
537 530
538 ret = platform_device_add_resources(musb, musb_resources, 531 pinfo = da8xx_dev_info;
539 ARRAY_SIZE(musb_resources)); 532 pinfo.parent = &pdev->dev;
540 if (ret) { 533 pinfo.res = musb_resources;
541 dev_err(&pdev->dev, "failed to add resources\n"); 534 pinfo.num_res = ARRAY_SIZE(musb_resources);
542 goto err5; 535 pinfo.data = pdata;
543 } 536 pinfo.size_data = sizeof(*pdata);
544 537
545 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 538 glue->musb = musb = platform_device_register_full(&pinfo);
546 if (ret) { 539 if (IS_ERR(musb)) {
547 dev_err(&pdev->dev, "failed to add platform_data\n"); 540 ret = PTR_ERR(musb);
548 goto err5; 541 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
549 }
550
551 ret = platform_device_add(musb);
552 if (ret) {
553 dev_err(&pdev->dev, "failed to register musb device\n");
554 goto err5; 542 goto err5;
555 } 543 }
556 544
@@ -563,9 +551,6 @@ err4:
563 clk_put(clk); 551 clk_put(clk);
564 552
565err3: 553err3:
566 platform_device_put(musb);
567
568err1:
569 kfree(glue); 554 kfree(glue);
570 555
571err0: 556err0:
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index ed0834e2b72e..1121fd741bf8 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -505,14 +505,19 @@ static const struct musb_platform_ops davinci_ops = {
505 .set_vbus = davinci_musb_set_vbus, 505 .set_vbus = davinci_musb_set_vbus,
506}; 506};
507 507
508static u64 davinci_dmamask = DMA_BIT_MASK(32); 508static const struct platform_device_info davinci_dev_info = {
509 .name = "musb-hdrc",
510 .id = PLATFORM_DEVID_AUTO,
511 .dma_mask = DMA_BIT_MASK(32),
512};
509 513
510static int davinci_probe(struct platform_device *pdev) 514static int davinci_probe(struct platform_device *pdev)
511{ 515{
512 struct resource musb_resources[2]; 516 struct resource musb_resources[3];
513 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 517 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
514 struct platform_device *musb; 518 struct platform_device *musb;
515 struct davinci_glue *glue; 519 struct davinci_glue *glue;
520 struct platform_device_info pinfo;
516 struct clk *clk; 521 struct clk *clk;
517 522
518 int ret = -ENOMEM; 523 int ret = -ENOMEM;
@@ -523,12 +528,6 @@ static int davinci_probe(struct platform_device *pdev)
523 goto err0; 528 goto err0;
524 } 529 }
525 530
526 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
527 if (!musb) {
528 dev_err(&pdev->dev, "failed to allocate musb device\n");
529 goto err1;
530 }
531
532 clk = clk_get(&pdev->dev, "usb"); 531 clk = clk_get(&pdev->dev, "usb");
533 if (IS_ERR(clk)) { 532 if (IS_ERR(clk)) {
534 dev_err(&pdev->dev, "failed to get clock\n"); 533 dev_err(&pdev->dev, "failed to get clock\n");
@@ -542,12 +541,7 @@ static int davinci_probe(struct platform_device *pdev)
542 goto err4; 541 goto err4;
543 } 542 }
544 543
545 musb->dev.parent = &pdev->dev;
546 musb->dev.dma_mask = &davinci_dmamask;
547 musb->dev.coherent_dma_mask = davinci_dmamask;
548
549 glue->dev = &pdev->dev; 544 glue->dev = &pdev->dev;
550 glue->musb = musb;
551 glue->clk = clk; 545 glue->clk = clk;
552 546
553 pdata->platform_ops = &davinci_ops; 547 pdata->platform_ops = &davinci_ops;
@@ -567,22 +561,26 @@ static int davinci_probe(struct platform_device *pdev)
567 musb_resources[1].end = pdev->resource[1].end; 561 musb_resources[1].end = pdev->resource[1].end;
568 musb_resources[1].flags = pdev->resource[1].flags; 562 musb_resources[1].flags = pdev->resource[1].flags;
569 563
570 ret = platform_device_add_resources(musb, musb_resources, 564 /*
571 ARRAY_SIZE(musb_resources)); 565 * For DM6467 3 resources are passed. A placeholder for the 3rd
572 if (ret) { 566 * resource is always there, so it's safe to always copy it...
573 dev_err(&pdev->dev, "failed to add resources\n"); 567 */
574 goto err5; 568 musb_resources[2].name = pdev->resource[2].name;
575 } 569 musb_resources[2].start = pdev->resource[2].start;
576 570 musb_resources[2].end = pdev->resource[2].end;
577 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 571 musb_resources[2].flags = pdev->resource[2].flags;
578 if (ret) { 572
579 dev_err(&pdev->dev, "failed to add platform_data\n"); 573 pinfo = davinci_dev_info;
580 goto err5; 574 pinfo.parent = &pdev->dev;
581 } 575 pinfo.res = musb_resources;
582 576 pinfo.num_res = ARRAY_SIZE(musb_resources);
583 ret = platform_device_add(musb); 577 pinfo.data = pdata;
584 if (ret) { 578 pinfo.size_data = sizeof(*pdata);
585 dev_err(&pdev->dev, "failed to register musb device\n"); 579
580 glue->musb = musb = platform_device_register_full(&pinfo);
581 if (IS_ERR(musb)) {
582 ret = PTR_ERR(musb);
583 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
586 goto err5; 584 goto err5;
587 } 585 }
588 586
@@ -595,9 +593,6 @@ err4:
595 clk_put(clk); 593 clk_put(clk);
596 594
597err3: 595err3:
598 platform_device_put(musb);
599
600err1:
601 kfree(glue); 596 kfree(glue);
602 597
603err0: 598err0:
diff --git a/drivers/usb/musb/musb_am335x.c b/drivers/usb/musb/musb_am335x.c
index 41ac5b5b57ce..8be9b02c3cc2 100644
--- a/drivers/usb/musb/musb_am335x.c
+++ b/drivers/usb/musb/musb_am335x.c
@@ -46,7 +46,7 @@ static struct platform_driver am335x_child_driver = {
46 .remove = am335x_child_remove, 46 .remove = am335x_child_remove,
47 .driver = { 47 .driver = {
48 .name = "am335x-usb-childs", 48 .name = "am335x-usb-childs",
49 .of_match_table = of_match_ptr(am335x_child_of_match), 49 .of_match_table = am335x_child_of_match,
50 }, 50 },
51}; 51};
52 52
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 18e877ffe7b7..0a43329569d1 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -617,7 +617,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
617 /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */ 617 /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */
618 default: 618 default:
619 s = "VALID"; break; 619 s = "VALID"; break;
620 }; s; }), 620 } s; }),
621 VBUSERR_RETRY_COUNT - musb->vbuserr_retry, 621 VBUSERR_RETRY_COUNT - musb->vbuserr_retry,
622 musb->port1_status); 622 musb->port1_status);
623 623
@@ -922,6 +922,52 @@ static void musb_generic_disable(struct musb *musb)
922} 922}
923 923
924/* 924/*
925 * Program the HDRC to start (enable interrupts, dma, etc.).
926 */
927void musb_start(struct musb *musb)
928{
929 void __iomem *regs = musb->mregs;
930 u8 devctl = musb_readb(regs, MUSB_DEVCTL);
931
932 dev_dbg(musb->controller, "<== devctl %02x\n", devctl);
933
934 /* Set INT enable registers, enable interrupts */
935 musb->intrtxe = musb->epmask;
936 musb_writew(regs, MUSB_INTRTXE, musb->intrtxe);
937 musb->intrrxe = musb->epmask & 0xfffe;
938 musb_writew(regs, MUSB_INTRRXE, musb->intrrxe);
939 musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
940
941 musb_writeb(regs, MUSB_TESTMODE, 0);
942
943 /* put into basic highspeed mode and start session */
944 musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
945 | MUSB_POWER_HSENAB
946 /* ENSUSPEND wedges tusb */
947 /* | MUSB_POWER_ENSUSPEND */
948 );
949
950 musb->is_active = 0;
951 devctl = musb_readb(regs, MUSB_DEVCTL);
952 devctl &= ~MUSB_DEVCTL_SESSION;
953
954 /* session started after:
955 * (a) ID-grounded irq, host mode;
956 * (b) vbus present/connect IRQ, peripheral mode;
957 * (c) peripheral initiates, using SRP
958 */
959 if (musb->port_mode != MUSB_PORT_MODE_HOST &&
960 (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
961 musb->is_active = 1;
962 } else {
963 devctl |= MUSB_DEVCTL_SESSION;
964 }
965
966 musb_platform_enable(musb);
967 musb_writeb(regs, MUSB_DEVCTL, devctl);
968}
969
970/*
925 * Make the HDRC stop (disable interrupts, etc.); 971 * Make the HDRC stop (disable interrupts, etc.);
926 * reversible by musb_start 972 * reversible by musb_start
927 * called on gadget driver unregister 973 * called on gadget driver unregister
@@ -1763,8 +1809,7 @@ static void musb_free(struct musb *musb)
1763 disable_irq_wake(musb->nIrq); 1809 disable_irq_wake(musb->nIrq);
1764 free_irq(musb->nIrq, musb); 1810 free_irq(musb->nIrq, musb);
1765 } 1811 }
1766 if (musb->dma_controller) 1812 cancel_work_sync(&musb->irq_work);
1767 dma_controller_destroy(musb->dma_controller);
1768 1813
1769 musb_host_free(musb); 1814 musb_host_free(musb);
1770} 1815}
@@ -1839,8 +1884,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1839 1884
1840 pm_runtime_get_sync(musb->controller); 1885 pm_runtime_get_sync(musb->controller);
1841 1886
1842 if (use_dma && dev->dma_mask) 1887 if (use_dma && dev->dma_mask) {
1843 musb->dma_controller = dma_controller_create(musb, musb->mregs); 1888 musb->dma_controller = dma_controller_create(musb, musb->mregs);
1889 if (IS_ERR(musb->dma_controller)) {
1890 status = PTR_ERR(musb->dma_controller);
1891 goto fail2_5;
1892 }
1893 }
1844 1894
1845 /* be sure interrupts are disabled before connecting ISR */ 1895 /* be sure interrupts are disabled before connecting ISR */
1846 musb_platform_disable(musb); 1896 musb_platform_disable(musb);
@@ -1900,6 +1950,8 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1900 if (status < 0) 1950 if (status < 0)
1901 goto fail3; 1951 goto fail3;
1902 status = musb_gadget_setup(musb); 1952 status = musb_gadget_setup(musb);
1953 if (status)
1954 musb_host_cleanup(musb);
1903 break; 1955 break;
1904 default: 1956 default:
1905 dev_err(dev, "unsupported port mode %d\n", musb->port_mode); 1957 dev_err(dev, "unsupported port mode %d\n", musb->port_mode);
@@ -1926,10 +1978,12 @@ fail5:
1926 1978
1927fail4: 1979fail4:
1928 musb_gadget_cleanup(musb); 1980 musb_gadget_cleanup(musb);
1981 musb_host_cleanup(musb);
1929 1982
1930fail3: 1983fail3:
1931 if (musb->dma_controller) 1984 if (musb->dma_controller)
1932 dma_controller_destroy(musb->dma_controller); 1985 dma_controller_destroy(musb->dma_controller);
1986fail2_5:
1933 pm_runtime_put_sync(musb->controller); 1987 pm_runtime_put_sync(musb->controller);
1934 1988
1935fail2: 1989fail2:
@@ -1986,6 +2040,9 @@ static int musb_remove(struct platform_device *pdev)
1986 musb_exit_debugfs(musb); 2040 musb_exit_debugfs(musb);
1987 musb_shutdown(pdev); 2041 musb_shutdown(pdev);
1988 2042
2043 if (musb->dma_controller)
2044 dma_controller_destroy(musb->dma_controller);
2045
1989 musb_free(musb); 2046 musb_free(musb);
1990 device_init_wakeup(dev, 0); 2047 device_init_wakeup(dev, 0);
1991 return 0; 2048 return 0;
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 65f3917b4fc5..29f7cd7c7964 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -46,6 +46,7 @@
46#include <linux/usb.h> 46#include <linux/usb.h>
47#include <linux/usb/otg.h> 47#include <linux/usb/otg.h>
48#include <linux/usb/musb.h> 48#include <linux/usb/musb.h>
49#include <linux/phy/phy.h>
49 50
50struct musb; 51struct musb;
51struct musb_hw_ep; 52struct musb_hw_ep;
@@ -341,6 +342,7 @@ struct musb {
341 u16 int_tx; 342 u16 int_tx;
342 343
343 struct usb_phy *xceiv; 344 struct usb_phy *xceiv;
345 struct phy *phy;
344 346
345 int nIrq; 347 int nIrq;
346 unsigned irq_wake:1; 348 unsigned irq_wake:1;
@@ -503,6 +505,7 @@ static inline void musb_configure_ep0(struct musb *musb)
503extern const char musb_driver_name[]; 505extern const char musb_driver_name[];
504 506
505extern void musb_stop(struct musb *musb); 507extern void musb_stop(struct musb *musb);
508extern void musb_start(struct musb *musb);
506 509
507extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src); 510extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
508extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst); 511extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst);
diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c
index ae959746f77f..ff9d6de2b746 100644
--- a/drivers/usb/musb/musb_cppi41.c
+++ b/drivers/usb/musb/musb_cppi41.c
@@ -484,6 +484,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller)
484 if (ret) 484 if (ret)
485 goto err; 485 goto err;
486 486
487 ret = -EINVAL;
487 if (port > MUSB_DMA_NUM_CHANNELS || !port) 488 if (port > MUSB_DMA_NUM_CHANNELS || !port)
488 goto err; 489 goto err;
489 if (is_tx) 490 if (is_tx)
@@ -503,6 +504,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller)
503 dc = dma_request_slave_channel(dev, str); 504 dc = dma_request_slave_channel(dev, str);
504 if (!dc) { 505 if (!dc) {
505 dev_err(dev, "Falied to request %s.\n", str); 506 dev_err(dev, "Falied to request %s.\n", str);
507 ret = -EPROBE_DEFER;
506 goto err; 508 goto err;
507 } 509 }
508 cppi41_channel->dc = dc; 510 cppi41_channel->dc = dc;
@@ -510,7 +512,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller)
510 return 0; 512 return 0;
511err: 513err:
512 cppi41_release_all_dma_chans(controller); 514 cppi41_release_all_dma_chans(controller);
513 return -EINVAL; 515 return ret;
514} 516}
515 517
516void dma_controller_destroy(struct dma_controller *c) 518void dma_controller_destroy(struct dma_controller *c)
@@ -526,7 +528,7 @@ struct dma_controller *dma_controller_create(struct musb *musb,
526 void __iomem *base) 528 void __iomem *base)
527{ 529{
528 struct cppi41_dma_controller *controller; 530 struct cppi41_dma_controller *controller;
529 int ret; 531 int ret = 0;
530 532
531 if (!musb->controller->of_node) { 533 if (!musb->controller->of_node) {
532 dev_err(musb->controller, "Need DT for the DMA engine.\n"); 534 dev_err(musb->controller, "Need DT for the DMA engine.\n");
@@ -553,5 +555,7 @@ struct dma_controller *dma_controller_create(struct musb *musb,
553plat_get_fail: 555plat_get_fail:
554 kfree(controller); 556 kfree(controller);
555kzalloc_fail: 557kzalloc_fail:
558 if (ret == -EPROBE_DEFER)
559 return ERR_PTR(ret);
556 return NULL; 560 return NULL;
557} 561}
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 4047cbb91bac..1901f6fe5807 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -121,6 +121,43 @@ struct dsps_glue {
121 unsigned long last_timer; /* last timer data for each instance */ 121 unsigned long last_timer; /* last timer data for each instance */
122}; 122};
123 123
124static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
125{
126 struct device *dev = musb->controller;
127 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
128
129 if (timeout == 0)
130 timeout = jiffies + msecs_to_jiffies(3);
131
132 /* Never idle if active, or when VBUS timeout is not set as host */
133 if (musb->is_active || (musb->a_wait_bcon == 0 &&
134 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
135 dev_dbg(musb->controller, "%s active, deleting timer\n",
136 usb_otg_state_string(musb->xceiv->state));
137 del_timer(&glue->timer);
138 glue->last_timer = jiffies;
139 return;
140 }
141 if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE)
142 return;
143
144 if (!musb->g.dev.driver)
145 return;
146
147 if (time_after(glue->last_timer, timeout) &&
148 timer_pending(&glue->timer)) {
149 dev_dbg(musb->controller,
150 "Longer idle timer already pending, ignoring...\n");
151 return;
152 }
153 glue->last_timer = timeout;
154
155 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
156 usb_otg_state_string(musb->xceiv->state),
157 jiffies_to_msecs(timeout - jiffies));
158 mod_timer(&glue->timer, timeout);
159}
160
124/** 161/**
125 * dsps_musb_enable - enable interrupts 162 * dsps_musb_enable - enable interrupts
126 */ 163 */
@@ -143,6 +180,7 @@ static void dsps_musb_enable(struct musb *musb)
143 /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 180 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
144 dsps_writel(reg_base, wrp->coreintr_set, 181 dsps_writel(reg_base, wrp->coreintr_set,
145 (1 << wrp->drvvbus) << wrp->usb_shift); 182 (1 << wrp->drvvbus) << wrp->usb_shift);
183 dsps_musb_try_idle(musb, 0);
146} 184}
147 185
148/** 186/**
@@ -171,6 +209,7 @@ static void otg_timer(unsigned long _musb)
171 const struct dsps_musb_wrapper *wrp = glue->wrp; 209 const struct dsps_musb_wrapper *wrp = glue->wrp;
172 u8 devctl; 210 u8 devctl;
173 unsigned long flags; 211 unsigned long flags;
212 int skip_session = 0;
174 213
175 /* 214 /*
176 * We poll because DSPS IP's won't expose several OTG-critical 215 * We poll because DSPS IP's won't expose several OTG-critical
@@ -183,10 +222,12 @@ static void otg_timer(unsigned long _musb)
183 spin_lock_irqsave(&musb->lock, flags); 222 spin_lock_irqsave(&musb->lock, flags);
184 switch (musb->xceiv->state) { 223 switch (musb->xceiv->state) {
185 case OTG_STATE_A_WAIT_BCON: 224 case OTG_STATE_A_WAIT_BCON:
186 devctl &= ~MUSB_DEVCTL_SESSION; 225 dsps_writeb(musb->mregs, MUSB_DEVCTL, 0);
187 dsps_writeb(musb->mregs, MUSB_DEVCTL, devctl); 226 skip_session = 1;
227 /* fall */
188 228
189 devctl = dsps_readb(musb->mregs, MUSB_DEVCTL); 229 case OTG_STATE_A_IDLE:
230 case OTG_STATE_B_IDLE:
190 if (devctl & MUSB_DEVCTL_BDEVICE) { 231 if (devctl & MUSB_DEVCTL_BDEVICE) {
191 musb->xceiv->state = OTG_STATE_B_IDLE; 232 musb->xceiv->state = OTG_STATE_B_IDLE;
192 MUSB_DEV_MODE(musb); 233 MUSB_DEV_MODE(musb);
@@ -194,60 +235,21 @@ static void otg_timer(unsigned long _musb)
194 musb->xceiv->state = OTG_STATE_A_IDLE; 235 musb->xceiv->state = OTG_STATE_A_IDLE;
195 MUSB_HST_MODE(musb); 236 MUSB_HST_MODE(musb);
196 } 237 }
238 if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session)
239 dsps_writeb(mregs, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
240 mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ);
197 break; 241 break;
198 case OTG_STATE_A_WAIT_VFALL: 242 case OTG_STATE_A_WAIT_VFALL:
199 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 243 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
200 dsps_writel(musb->ctrl_base, wrp->coreintr_set, 244 dsps_writel(musb->ctrl_base, wrp->coreintr_set,
201 MUSB_INTR_VBUSERROR << wrp->usb_shift); 245 MUSB_INTR_VBUSERROR << wrp->usb_shift);
202 break; 246 break;
203 case OTG_STATE_B_IDLE:
204 devctl = dsps_readb(mregs, MUSB_DEVCTL);
205 if (devctl & MUSB_DEVCTL_BDEVICE)
206 mod_timer(&glue->timer,
207 jiffies + wrp->poll_seconds * HZ);
208 else
209 musb->xceiv->state = OTG_STATE_A_IDLE;
210 break;
211 default: 247 default:
212 break; 248 break;
213 } 249 }
214 spin_unlock_irqrestore(&musb->lock, flags); 250 spin_unlock_irqrestore(&musb->lock, flags);
215} 251}
216 252
217static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
218{
219 struct device *dev = musb->controller;
220 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
221
222 if (timeout == 0)
223 timeout = jiffies + msecs_to_jiffies(3);
224
225 /* Never idle if active, or when VBUS timeout is not set as host */
226 if (musb->is_active || (musb->a_wait_bcon == 0 &&
227 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
228 dev_dbg(musb->controller, "%s active, deleting timer\n",
229 usb_otg_state_string(musb->xceiv->state));
230 del_timer(&glue->timer);
231 glue->last_timer = jiffies;
232 return;
233 }
234 if (musb->port_mode == MUSB_PORT_MODE_HOST)
235 return;
236
237 if (time_after(glue->last_timer, timeout) &&
238 timer_pending(&glue->timer)) {
239 dev_dbg(musb->controller,
240 "Longer idle timer already pending, ignoring...\n");
241 return;
242 }
243 glue->last_timer = timeout;
244
245 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
246 usb_otg_state_string(musb->xceiv->state),
247 jiffies_to_msecs(timeout - jiffies));
248 mod_timer(&glue->timer, timeout);
249}
250
251static irqreturn_t dsps_interrupt(int irq, void *hci) 253static irqreturn_t dsps_interrupt(int irq, void *hci)
252{ 254{
253 struct musb *musb = hci; 255 struct musb *musb = hci;
@@ -443,7 +445,7 @@ static int get_musb_port_mode(struct device *dev)
443 case USB_DR_MODE_OTG: 445 case USB_DR_MODE_OTG:
444 default: 446 default:
445 return MUSB_PORT_MODE_DUAL_ROLE; 447 return MUSB_PORT_MODE_DUAL_ROLE;
446 }; 448 }
447} 449}
448 450
449static int dsps_create_musb_pdev(struct dsps_glue *glue, 451static int dsps_create_musb_pdev(struct dsps_glue *glue,
@@ -535,6 +537,9 @@ static int dsps_probe(struct platform_device *pdev)
535 struct dsps_glue *glue; 537 struct dsps_glue *glue;
536 int ret; 538 int ret;
537 539
540 if (!strcmp(pdev->name, "musb-hdrc"))
541 return -ENODEV;
542
538 match = of_match_node(musb_dsps_of_match, pdev->dev.of_node); 543 match = of_match_node(musb_dsps_of_match, pdev->dev.of_node);
539 if (!match) { 544 if (!match) {
540 dev_err(&pdev->dev, "fail to get matching of_match struct\n"); 545 dev_err(&pdev->dev, "fail to get matching of_match struct\n");
@@ -628,7 +633,7 @@ static struct platform_driver dsps_usbss_driver = {
628 .remove = dsps_remove, 633 .remove = dsps_remove,
629 .driver = { 634 .driver = {
630 .name = "musb-dsps", 635 .name = "musb-dsps",
631 .of_match_table = of_match_ptr(musb_dsps_of_match), 636 .of_match_table = musb_dsps_of_match,
632 }, 637 },
633}; 638};
634 639
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 9a08679d204d..d2d3a173b315 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1121,7 +1121,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
1121 case USB_ENDPOINT_XFER_BULK: s = "bulk"; break; 1121 case USB_ENDPOINT_XFER_BULK: s = "bulk"; break;
1122 case USB_ENDPOINT_XFER_INT: s = "int"; break; 1122 case USB_ENDPOINT_XFER_INT: s = "int"; break;
1123 default: s = "iso"; break; 1123 default: s = "iso"; break;
1124 }; s; }), 1124 } s; }),
1125 musb_ep->is_in ? "IN" : "OUT", 1125 musb_ep->is_in ? "IN" : "OUT",
1126 musb_ep->dma ? "dma, " : "", 1126 musb_ep->dma ? "dma, " : "",
1127 musb_ep->packet_sz); 1127 musb_ep->packet_sz);
@@ -1790,6 +1790,10 @@ int musb_gadget_setup(struct musb *musb)
1790 musb->g.max_speed = USB_SPEED_HIGH; 1790 musb->g.max_speed = USB_SPEED_HIGH;
1791 musb->g.speed = USB_SPEED_UNKNOWN; 1791 musb->g.speed = USB_SPEED_UNKNOWN;
1792 1792
1793 MUSB_DEV_MODE(musb);
1794 musb->xceiv->otg->default_a = 0;
1795 musb->xceiv->state = OTG_STATE_B_IDLE;
1796
1793 /* this "gadget" abstracts/virtualizes the controller */ 1797 /* this "gadget" abstracts/virtualizes the controller */
1794 musb->g.name = musb_driver_name; 1798 musb->g.name = musb_driver_name;
1795 musb->g.is_otg = 1; 1799 musb->g.is_otg = 1;
@@ -1855,6 +1859,8 @@ static int musb_gadget_start(struct usb_gadget *g,
1855 musb->xceiv->state = OTG_STATE_B_IDLE; 1859 musb->xceiv->state = OTG_STATE_B_IDLE;
1856 spin_unlock_irqrestore(&musb->lock, flags); 1860 spin_unlock_irqrestore(&musb->lock, flags);
1857 1861
1862 musb_start(musb);
1863
1858 /* REVISIT: funcall to other code, which also 1864 /* REVISIT: funcall to other code, which also
1859 * handles power budgeting ... this way also 1865 * handles power budgeting ... this way also
1860 * ensures HdrcStart is indirectly called. 1866 * ensures HdrcStart is indirectly called.
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 9a2b8c85f19a..6582a20bec05 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -253,7 +253,7 @@ musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh)
253 case USB_ENDPOINT_XFER_BULK: s = "-bulk"; break; 253 case USB_ENDPOINT_XFER_BULK: s = "-bulk"; break;
254 case USB_ENDPOINT_XFER_ISOC: s = "-iso"; break; 254 case USB_ENDPOINT_XFER_ISOC: s = "-iso"; break;
255 default: s = "-intr"; break; 255 default: s = "-intr"; break;
256 }; s; }), 256 } s; }),
257 epnum, buf + offset, len); 257 epnum, buf + offset, len);
258 258
259 /* Configure endpoint */ 259 /* Configure endpoint */
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index a523950c2b32..9af6bba5eac9 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -44,52 +44,6 @@
44 44
45#include "musb_core.h" 45#include "musb_core.h"
46 46
47/*
48* Program the HDRC to start (enable interrupts, dma, etc.).
49*/
50static void musb_start(struct musb *musb)
51{
52 void __iomem *regs = musb->mregs;
53 u8 devctl = musb_readb(regs, MUSB_DEVCTL);
54
55 dev_dbg(musb->controller, "<== devctl %02x\n", devctl);
56
57 /* Set INT enable registers, enable interrupts */
58 musb->intrtxe = musb->epmask;
59 musb_writew(regs, MUSB_INTRTXE, musb->intrtxe);
60 musb->intrrxe = musb->epmask & 0xfffe;
61 musb_writew(regs, MUSB_INTRRXE, musb->intrrxe);
62 musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
63
64 musb_writeb(regs, MUSB_TESTMODE, 0);
65
66 /* put into basic highspeed mode and start session */
67 musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
68 | MUSB_POWER_HSENAB
69 /* ENSUSPEND wedges tusb */
70 /* | MUSB_POWER_ENSUSPEND */
71 );
72
73 musb->is_active = 0;
74 devctl = musb_readb(regs, MUSB_DEVCTL);
75 devctl &= ~MUSB_DEVCTL_SESSION;
76
77 /* session started after:
78 * (a) ID-grounded irq, host mode;
79 * (b) vbus present/connect IRQ, peripheral mode;
80 * (c) peripheral initiates, using SRP
81 */
82 if (musb->port_mode != MUSB_PORT_MODE_HOST &&
83 (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
84 musb->is_active = 1;
85 } else {
86 devctl |= MUSB_DEVCTL_SESSION;
87 }
88
89 musb_platform_enable(musb);
90 musb_writeb(regs, MUSB_DEVCTL, devctl);
91}
92
93static void musb_port_suspend(struct musb *musb, bool do_suspend) 47static void musb_port_suspend(struct musb *musb, bool do_suspend)
94{ 48{
95 struct usb_otg *otg = musb->xceiv->otg; 49 struct usb_otg *otg = musb->xceiv->otg;
@@ -266,6 +220,23 @@ int musb_hub_status_data(struct usb_hcd *hcd, char *buf)
266 return retval; 220 return retval;
267} 221}
268 222
223static int musb_has_gadget(struct musb *musb)
224{
225 /*
226 * In host-only mode we start a connection right away. In OTG mode
227 * we have to wait until we loaded a gadget. We don't really need a
228 * gadget if we operate as a host but we should not start a session
229 * as a device without a gadget or else we explode.
230 */
231#ifdef CONFIG_USB_MUSB_HOST
232 return 1;
233#else
234 if (musb->port_mode == MUSB_PORT_MODE_HOST)
235 return 1;
236 return musb->g.dev.driver != NULL;
237#endif
238}
239
269int musb_hub_control( 240int musb_hub_control(
270 struct usb_hcd *hcd, 241 struct usb_hcd *hcd,
271 u16 typeReq, 242 u16 typeReq,
@@ -408,7 +379,7 @@ int musb_hub_control(
408 * initialization logic, e.g. for OTG, or change any 379 * initialization logic, e.g. for OTG, or change any
409 * logic relating to VBUS power-up. 380 * logic relating to VBUS power-up.
410 */ 381 */
411 if (!hcd->self.is_b_host) 382 if (!hcd->self.is_b_host && musb_has_gadget(musb))
412 musb_start(musb); 383 musb_start(musb);
413 break; 384 break;
414 case USB_PORT_FEAT_RESET: 385 case USB_PORT_FEAT_RESET:
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 59d2245db1c8..2a408cdaf7b2 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -38,6 +38,7 @@
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/usb/musb-omap.h> 39#include <linux/usb/musb-omap.h>
40#include <linux/usb/omap_control_usb.h> 40#include <linux/usb/omap_control_usb.h>
41#include <linux/of_platform.h>
41 42
42#include "musb_core.h" 43#include "musb_core.h"
43#include "omap2430.h" 44#include "omap2430.h"
@@ -305,6 +306,9 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
305 default: 306 default:
306 dev_dbg(dev, "ID float\n"); 307 dev_dbg(dev, "ID float\n");
307 } 308 }
309
310 atomic_notifier_call_chain(&musb->xceiv->notifier,
311 musb->xceiv->last_event, NULL);
308} 312}
309 313
310 314
@@ -348,11 +352,21 @@ static int omap2430_musb_init(struct musb *musb)
348 * up through ULPI. TWL4030-family PMICs include one, 352 * up through ULPI. TWL4030-family PMICs include one,
349 * which needs a driver, drivers aren't always needed. 353 * which needs a driver, drivers aren't always needed.
350 */ 354 */
351 if (dev->parent->of_node) 355 if (dev->parent->of_node) {
356 musb->phy = devm_phy_get(dev->parent, "usb2-phy");
357
358 /* We can't totally remove musb->xceiv as of now because
359 * musb core uses xceiv.state and xceiv.otg. Once we have
360 * a separate state machine to handle otg, these can be moved
361 * out of xceiv and then we can start using the generic PHY
362 * framework
363 */
352 musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, 364 musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
353 "usb-phy", 0); 365 "usb-phy", 0);
354 else 366 } else {
355 musb->xceiv = devm_usb_get_phy_dev(dev, 0); 367 musb->xceiv = devm_usb_get_phy_dev(dev, 0);
368 musb->phy = devm_phy_get(dev, "usb");
369 }
356 370
357 if (IS_ERR(musb->xceiv)) { 371 if (IS_ERR(musb->xceiv)) {
358 status = PTR_ERR(musb->xceiv); 372 status = PTR_ERR(musb->xceiv);
@@ -364,6 +378,10 @@ static int omap2430_musb_init(struct musb *musb)
364 return -EPROBE_DEFER; 378 return -EPROBE_DEFER;
365 } 379 }
366 380
381 if (IS_ERR(musb->phy)) {
382 pr_err("HS USB OTG: no PHY configured\n");
383 return PTR_ERR(musb->phy);
384 }
367 musb->isr = omap2430_musb_interrupt; 385 musb->isr = omap2430_musb_interrupt;
368 386
369 status = pm_runtime_get_sync(dev); 387 status = pm_runtime_get_sync(dev);
@@ -397,7 +415,7 @@ static int omap2430_musb_init(struct musb *musb)
397 if (glue->status != OMAP_MUSB_UNKNOWN) 415 if (glue->status != OMAP_MUSB_UNKNOWN)
398 omap_musb_set_mailbox(glue); 416 omap_musb_set_mailbox(glue);
399 417
400 usb_phy_init(musb->xceiv); 418 phy_init(musb->phy);
401 419
402 pm_runtime_put_noidle(musb->controller); 420 pm_runtime_put_noidle(musb->controller);
403 return 0; 421 return 0;
@@ -460,6 +478,7 @@ static int omap2430_musb_exit(struct musb *musb)
460 del_timer_sync(&musb_idle_timer); 478 del_timer_sync(&musb_idle_timer);
461 479
462 omap2430_low_level_exit(musb); 480 omap2430_low_level_exit(musb);
481 phy_exit(musb->phy);
463 482
464 return 0; 483 return 0;
465} 484}
@@ -509,8 +528,12 @@ static int omap2430_probe(struct platform_device *pdev)
509 glue->dev = &pdev->dev; 528 glue->dev = &pdev->dev;
510 glue->musb = musb; 529 glue->musb = musb;
511 glue->status = OMAP_MUSB_UNKNOWN; 530 glue->status = OMAP_MUSB_UNKNOWN;
531 glue->control_otghs = ERR_PTR(-ENODEV);
512 532
513 if (np) { 533 if (np) {
534 struct device_node *control_node;
535 struct platform_device *control_pdev;
536
514 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 537 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
515 if (!pdata) { 538 if (!pdata) {
516 dev_err(&pdev->dev, 539 dev_err(&pdev->dev,
@@ -539,22 +562,20 @@ static int omap2430_probe(struct platform_device *pdev)
539 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); 562 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
540 of_property_read_u32(np, "power", (u32 *)&pdata->power); 563 of_property_read_u32(np, "power", (u32 *)&pdata->power);
541 config->multipoint = of_property_read_bool(np, "multipoint"); 564 config->multipoint = of_property_read_bool(np, "multipoint");
542 pdata->has_mailbox = of_property_read_bool(np,
543 "ti,has-mailbox");
544 565
545 pdata->board_data = data; 566 pdata->board_data = data;
546 pdata->config = config; 567 pdata->config = config;
547 }
548 568
549 if (pdata->has_mailbox) { 569 control_node = of_parse_phandle(np, "ctrl-module", 0);
550 glue->control_otghs = omap_get_control_dev(); 570 if (control_node) {
551 if (IS_ERR(glue->control_otghs)) { 571 control_pdev = of_find_device_by_node(control_node);
552 dev_vdbg(&pdev->dev, "Failed to get control device\n"); 572 if (!control_pdev) {
553 ret = PTR_ERR(glue->control_otghs); 573 dev_err(&pdev->dev, "Failed to get control device\n");
554 goto err2; 574 ret = -EINVAL;
575 goto err2;
576 }
577 glue->control_otghs = &control_pdev->dev;
555 } 578 }
556 } else {
557 glue->control_otghs = ERR_PTR(-ENODEV);
558 } 579 }
559 pdata->platform_ops = &omap2430_ops; 580 pdata->platform_ops = &omap2430_ops;
560 581
@@ -638,7 +659,7 @@ static int omap2430_runtime_suspend(struct device *dev)
638 OTG_INTERFSEL); 659 OTG_INTERFSEL);
639 660
640 omap2430_low_level_exit(musb); 661 omap2430_low_level_exit(musb);
641 usb_phy_set_suspend(musb->xceiv, 1); 662 phy_power_off(musb->phy);
642 } 663 }
643 664
644 return 0; 665 return 0;
@@ -653,8 +674,7 @@ static int omap2430_runtime_resume(struct device *dev)
653 omap2430_low_level_init(musb); 674 omap2430_low_level_init(musb);
654 musb_writel(musb->mregs, OTG_INTERFSEL, 675 musb_writel(musb->mregs, OTG_INTERFSEL,
655 musb->context.otg_interfsel); 676 musb->context.otg_interfsel);
656 677 phy_power_on(musb->phy);
657 usb_phy_set_suspend(musb->xceiv, 0);
658 } 678 }
659 679
660 return 0; 680 return 0;
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index b3b3ed723882..4432314d70ee 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -1152,7 +1152,11 @@ static const struct musb_platform_ops tusb_ops = {
1152 .set_vbus = tusb_musb_set_vbus, 1152 .set_vbus = tusb_musb_set_vbus,
1153}; 1153};
1154 1154
1155static u64 tusb_dmamask = DMA_BIT_MASK(32); 1155static const struct platform_device_info tusb_dev_info = {
1156 .name = "musb-hdrc",
1157 .id = PLATFORM_DEVID_AUTO,
1158 .dma_mask = DMA_BIT_MASK(32),
1159};
1156 1160
1157static int tusb_probe(struct platform_device *pdev) 1161static int tusb_probe(struct platform_device *pdev)
1158{ 1162{
@@ -1160,7 +1164,7 @@ static int tusb_probe(struct platform_device *pdev)
1160 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 1164 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
1161 struct platform_device *musb; 1165 struct platform_device *musb;
1162 struct tusb6010_glue *glue; 1166 struct tusb6010_glue *glue;
1163 1167 struct platform_device_info pinfo;
1164 int ret = -ENOMEM; 1168 int ret = -ENOMEM;
1165 1169
1166 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 1170 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
@@ -1169,18 +1173,7 @@ static int tusb_probe(struct platform_device *pdev)
1169 goto err0; 1173 goto err0;
1170 } 1174 }
1171 1175
1172 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
1173 if (!musb) {
1174 dev_err(&pdev->dev, "failed to allocate musb device\n");
1175 goto err1;
1176 }
1177
1178 musb->dev.parent = &pdev->dev;
1179 musb->dev.dma_mask = &tusb_dmamask;
1180 musb->dev.coherent_dma_mask = tusb_dmamask;
1181
1182 glue->dev = &pdev->dev; 1176 glue->dev = &pdev->dev;
1183 glue->musb = musb;
1184 1177
1185 pdata->platform_ops = &tusb_ops; 1178 pdata->platform_ops = &tusb_ops;
1186 1179
@@ -1204,31 +1197,23 @@ static int tusb_probe(struct platform_device *pdev)
1204 musb_resources[2].end = pdev->resource[2].end; 1197 musb_resources[2].end = pdev->resource[2].end;
1205 musb_resources[2].flags = pdev->resource[2].flags; 1198 musb_resources[2].flags = pdev->resource[2].flags;
1206 1199
1207 ret = platform_device_add_resources(musb, musb_resources, 1200 pinfo = tusb_dev_info;
1208 ARRAY_SIZE(musb_resources)); 1201 pinfo.parent = &pdev->dev;
1209 if (ret) { 1202 pinfo.res = musb_resources;
1210 dev_err(&pdev->dev, "failed to add resources\n"); 1203 pinfo.num_res = ARRAY_SIZE(musb_resources);
1211 goto err3; 1204 pinfo.data = pdata;
1212 } 1205 pinfo.size_data = sizeof(*pdata);
1213 1206
1214 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 1207 glue->musb = musb = platform_device_register_full(&pinfo);
1215 if (ret) { 1208 if (IS_ERR(musb)) {
1216 dev_err(&pdev->dev, "failed to add platform_data\n"); 1209 ret = PTR_ERR(musb);
1217 goto err3; 1210 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
1218 }
1219
1220 ret = platform_device_add(musb);
1221 if (ret) {
1222 dev_err(&pdev->dev, "failed to register musb device\n");
1223 goto err3; 1211 goto err3;
1224 } 1212 }
1225 1213
1226 return 0; 1214 return 0;
1227 1215
1228err3: 1216err3:
1229 platform_device_put(musb);
1230
1231err1:
1232 kfree(glue); 1217 kfree(glue);
1233 1218
1234err0: 1219err0:
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index 59256b12f746..122446bf1664 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -259,7 +259,7 @@ static int ux500_probe(struct platform_device *pdev)
259 goto err1; 259 goto err1;
260 } 260 }
261 261
262 clk = clk_get(&pdev->dev, "usb"); 262 clk = clk_get(&pdev->dev, NULL);
263 if (IS_ERR(clk)) { 263 if (IS_ERR(clk)) {
264 dev_err(&pdev->dev, "failed to get clock\n"); 264 dev_err(&pdev->dev, "failed to get clock\n");
265 ret = PTR_ERR(clk); 265 ret = PTR_ERR(clk);
@@ -376,17 +376,10 @@ static int ux500_resume(struct device *dev)
376 376
377 return 0; 377 return 0;
378} 378}
379
380static const struct dev_pm_ops ux500_pm_ops = {
381 .suspend = ux500_suspend,
382 .resume = ux500_resume,
383};
384
385#define DEV_PM_OPS (&ux500_pm_ops)
386#else
387#define DEV_PM_OPS NULL
388#endif 379#endif
389 380
381static SIMPLE_DEV_PM_OPS(ux500_pm_ops, ux500_suspend, ux500_resume);
382
390static const struct of_device_id ux500_match[] = { 383static const struct of_device_id ux500_match[] = {
391 { .compatible = "stericsson,db8500-musb", }, 384 { .compatible = "stericsson,db8500-musb", },
392 {} 385 {}
@@ -397,7 +390,7 @@ static struct platform_driver ux500_driver = {
397 .remove = ux500_remove, 390 .remove = ux500_remove,
398 .driver = { 391 .driver = {
399 .name = "musb-ux500", 392 .name = "musb-ux500",
400 .pm = DEV_PM_OPS, 393 .pm = &ux500_pm_ops,
401 .of_match_table = ux500_match, 394 .of_match_table = ux500_match,
402 }, 395 },
403}; 396};
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9c60a9..08e2f39027ec 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -66,17 +66,6 @@ config OMAP_CONTROL_USB
66 power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an 66 power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an
67 additional register to power on USB3 PHY. 67 additional register to power on USB3 PHY.
68 68
69config OMAP_USB2
70 tristate "OMAP USB2 PHY Driver"
71 depends on ARCH_OMAP2PLUS
72 select OMAP_CONTROL_USB
73 select USB_PHY
74 help
75 Enable this to support the transceiver that is part of SOC. This
76 driver takes care of all the PHY functionality apart from comparator.
77 The USB OTG controller communicates with the comparator using this
78 driver.
79
80config OMAP_USB3 69config OMAP_USB3
81 tristate "OMAP USB3 PHY Driver" 70 tristate "OMAP USB3 PHY Driver"
82 depends on ARCH_OMAP2PLUS || COMPILE_TEST 71 depends on ARCH_OMAP2PLUS || COMPILE_TEST
@@ -93,6 +82,7 @@ config AM335X_CONTROL_USB
93 82
94config AM335X_PHY_USB 83config AM335X_PHY_USB
95 tristate "AM335x USB PHY Driver" 84 tristate "AM335x USB PHY Driver"
85 depends on ARM || COMPILE_TEST
96 select USB_PHY 86 select USB_PHY
97 select AM335X_CONTROL_USB 87 select AM335X_CONTROL_USB
98 select NOP_USB_XCEIV 88 select NOP_USB_XCEIV
@@ -123,16 +113,6 @@ config SAMSUNG_USB3PHY
123 Enable this to support Samsung USB 3.0 (Super Speed) phy controller 113 Enable this to support Samsung USB 3.0 (Super Speed) phy controller
124 for samsung SoCs. 114 for samsung SoCs.
125 115
126config TWL4030_USB
127 tristate "TWL4030 USB Transceiver Driver"
128 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
129 select USB_PHY
130 help
131 Enable this to support the USB OTG transceiver on TWL4030
132 family chips (including the TWL5030 and TPS659x0 devices).
133 This transceiver supports high and full speed devices plus,
134 in host mode, low speed.
135
136config TWL6030_USB 116config TWL6030_USB
137 tristate "TWL6030 USB Transceiver Driver" 117 tristate "TWL6030 USB Transceiver Driver"
138 depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS 118 depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS
@@ -214,6 +194,19 @@ config USB_RCAR_PHY
214 To compile this driver as a module, choose M here: the 194 To compile this driver as a module, choose M here: the
215 module will be called phy-rcar-usb. 195 module will be called phy-rcar-usb.
216 196
197config USB_RCAR_GEN2_PHY
198 tristate "Renesas R-Car Gen2 USB PHY support"
199 depends on ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST
200 select USB_PHY
201 help
202 Say Y here to add support for the Renesas R-Car Gen2 USB PHY driver.
203 It is typically used to control internal USB PHY for USBHS,
204 and to configure shared USB channels 0 and 2.
205 This driver supports R8A7790 and R8A7791.
206
207 To compile this driver as a module, choose M here: the
208 module will be called phy-rcar-gen2-usb.
209
217config USB_ULPI 210config USB_ULPI
218 bool "Generic ULPI Transceiver Driver" 211 bool "Generic ULPI Transceiver Driver"
219 depends on ARM 212 depends on ARM
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 2135e85f46ed..022c1da7fb78 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -15,12 +15,10 @@ obj-$(CONFIG_NOP_USB_XCEIV) += phy-generic.o
15obj-$(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 16obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o
17obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o 17obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o
18obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
19obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o 18obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o
20obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o 19obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o
21obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o 20obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o
22obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o 21obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o
23obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o
24obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o 22obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o
25obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o 23obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o
26obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o 24obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o
@@ -29,5 +27,6 @@ obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
29obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o 27obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o
30obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o 28obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o
31obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o 29obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o
30obj-$(CONFIG_USB_RCAR_GEN2_PHY) += phy-rcar-gen2-usb.o
32obj-$(CONFIG_USB_ULPI) += phy-ulpi.o 31obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
33obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o 32obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o
diff --git a/drivers/usb/phy/phy-am335x-control.c b/drivers/usb/phy/phy-am335x-control.c
index 22cf07d62e4c..634f49acd20e 100644
--- a/drivers/usb/phy/phy-am335x-control.c
+++ b/drivers/usb/phy/phy-am335x-control.c
@@ -26,6 +26,41 @@ struct am335x_control_usb {
26#define USBPHY_OTGVDET_EN (1 << 19) 26#define USBPHY_OTGVDET_EN (1 << 19)
27#define USBPHY_OTGSESSEND_EN (1 << 20) 27#define USBPHY_OTGSESSEND_EN (1 << 20)
28 28
29#define AM335X_PHY0_WK_EN (1 << 0)
30#define AM335X_PHY1_WK_EN (1 << 8)
31
32static void am335x_phy_wkup(struct phy_control *phy_ctrl, u32 id, bool on)
33{
34 struct am335x_control_usb *usb_ctrl;
35 u32 val;
36 u32 reg;
37
38 usb_ctrl = container_of(phy_ctrl, struct am335x_control_usb, phy_ctrl);
39
40 switch (id) {
41 case 0:
42 reg = AM335X_PHY0_WK_EN;
43 break;
44 case 1:
45 reg = AM335X_PHY1_WK_EN;
46 break;
47 default:
48 WARN_ON(1);
49 return;
50 }
51
52 spin_lock(&usb_ctrl->lock);
53 val = readl(usb_ctrl->wkup);
54
55 if (on)
56 val |= reg;
57 else
58 val &= ~reg;
59
60 writel(val, usb_ctrl->wkup);
61 spin_unlock(&usb_ctrl->lock);
62}
63
29static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on) 64static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on)
30{ 65{
31 struct am335x_control_usb *usb_ctrl; 66 struct am335x_control_usb *usb_ctrl;
@@ -59,6 +94,7 @@ static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on)
59 94
60static const struct phy_control ctrl_am335x = { 95static const struct phy_control ctrl_am335x = {
61 .phy_power = am335x_phy_power, 96 .phy_power = am335x_phy_power,
97 .phy_wkup = am335x_phy_wkup,
62}; 98};
63 99
64static const struct of_device_id omap_control_usb_id_table[] = { 100static const struct of_device_id omap_control_usb_id_table[] = {
@@ -117,6 +153,12 @@ static int am335x_control_usb_probe(struct platform_device *pdev)
117 ctrl_usb->phy_reg = devm_ioremap_resource(&pdev->dev, res); 153 ctrl_usb->phy_reg = devm_ioremap_resource(&pdev->dev, res);
118 if (IS_ERR(ctrl_usb->phy_reg)) 154 if (IS_ERR(ctrl_usb->phy_reg))
119 return PTR_ERR(ctrl_usb->phy_reg); 155 return PTR_ERR(ctrl_usb->phy_reg);
156
157 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wakeup");
158 ctrl_usb->wkup = devm_ioremap_resource(&pdev->dev, res);
159 if (IS_ERR(ctrl_usb->wkup))
160 return PTR_ERR(ctrl_usb->wkup);
161
120 spin_lock_init(&ctrl_usb->lock); 162 spin_lock_init(&ctrl_usb->lock);
121 ctrl_usb->phy_ctrl = *phy_ctrl; 163 ctrl_usb->phy_ctrl = *phy_ctrl;
122 164
@@ -129,7 +171,7 @@ static struct platform_driver am335x_control_driver = {
129 .driver = { 171 .driver = {
130 .name = "am335x-control-usb", 172 .name = "am335x-control-usb",
131 .owner = THIS_MODULE, 173 .owner = THIS_MODULE,
132 .of_match_table = of_match_ptr(omap_control_usb_id_table), 174 .of_match_table = omap_control_usb_id_table,
133 }, 175 },
134}; 176};
135 177
diff --git a/drivers/usb/phy/phy-am335x.c b/drivers/usb/phy/phy-am335x.c
index c4d614d1f173..6370e50649d7 100644
--- a/drivers/usb/phy/phy-am335x.c
+++ b/drivers/usb/phy/phy-am335x.c
@@ -53,21 +53,20 @@ static int am335x_phy_probe(struct platform_device *pdev)
53 } 53 }
54 54
55 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, 55 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen,
56 USB_PHY_TYPE_USB2, 0, false, false); 56 USB_PHY_TYPE_USB2, 0, false);
57 if (ret) 57 if (ret)
58 return ret; 58 return ret;
59 59
60 ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy); 60 ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy);
61 if (ret) 61 if (ret)
62 goto err_add; 62 return ret;
63 am_phy->usb_phy_gen.phy.init = am335x_init; 63 am_phy->usb_phy_gen.phy.init = am335x_init;
64 am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; 64 am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown;
65 65
66 platform_set_drvdata(pdev, am_phy); 66 platform_set_drvdata(pdev, am_phy);
67
67 return 0; 68 return 0;
68 69
69err_add:
70 usb_phy_gen_cleanup_phy(&am_phy->usb_phy_gen);
71 return ret; 70 return ret;
72} 71}
73 72
@@ -79,6 +78,40 @@ static int am335x_phy_remove(struct platform_device *pdev)
79 return 0; 78 return 0;
80} 79}
81 80
81#ifdef CONFIG_PM_RUNTIME
82
83static int am335x_phy_runtime_suspend(struct device *dev)
84{
85 struct platform_device *pdev = to_platform_device(dev);
86 struct am335x_phy *am_phy = platform_get_drvdata(pdev);
87
88 if (device_may_wakeup(dev))
89 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true);
90 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
91 return 0;
92}
93
94static int am335x_phy_runtime_resume(struct device *dev)
95{
96 struct platform_device *pdev = to_platform_device(dev);
97 struct am335x_phy *am_phy = platform_get_drvdata(pdev);
98
99 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true);
100 if (device_may_wakeup(dev))
101 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
102 return 0;
103}
104
105static const struct dev_pm_ops am335x_pm_ops = {
106 SET_RUNTIME_PM_OPS(am335x_phy_runtime_suspend,
107 am335x_phy_runtime_resume, NULL)
108};
109
110#define DEV_PM_OPS (&am335x_pm_ops)
111#else
112#define DEV_PM_OPS NULL
113#endif
114
82static const struct of_device_id am335x_phy_ids[] = { 115static const struct of_device_id am335x_phy_ids[] = {
83 { .compatible = "ti,am335x-usb-phy" }, 116 { .compatible = "ti,am335x-usb-phy" },
84 { } 117 { }
@@ -91,7 +124,8 @@ static struct platform_driver am335x_phy_driver = {
91 .driver = { 124 .driver = {
92 .name = "am335x-phy-driver", 125 .name = "am335x-phy-driver",
93 .owner = THIS_MODULE, 126 .owner = THIS_MODULE,
94 .of_match_table = of_match_ptr(am335x_phy_ids), 127 .pm = DEV_PM_OPS,
128 .of_match_table = am335x_phy_ids,
95 }, 129 },
96}; 130};
97 131
diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c
index fa7c9f9628b5..7f3c73b967ce 100644
--- a/drivers/usb/phy/phy-fsl-usb.c
+++ b/drivers/usb/phy/phy-fsl-usb.c
@@ -134,7 +134,7 @@ int write_ulpi(u8 addr, u8 data)
134/* Operations that will be called from OTG Finite State Machine */ 134/* Operations that will be called from OTG Finite State Machine */
135 135
136/* Charge vbus for vbus pulsing in SRP */ 136/* Charge vbus for vbus pulsing in SRP */
137void fsl_otg_chrg_vbus(int on) 137void fsl_otg_chrg_vbus(struct otg_fsm *fsm, int on)
138{ 138{
139 u32 tmp; 139 u32 tmp;
140 140
@@ -170,7 +170,7 @@ void fsl_otg_dischrg_vbus(int on)
170} 170}
171 171
172/* A-device driver vbus, controlled through PP bit in PORTSC */ 172/* A-device driver vbus, controlled through PP bit in PORTSC */
173void fsl_otg_drv_vbus(int on) 173void fsl_otg_drv_vbus(struct otg_fsm *fsm, int on)
174{ 174{
175 u32 tmp; 175 u32 tmp;
176 176
@@ -188,7 +188,7 @@ void fsl_otg_drv_vbus(int on)
188 * Pull-up D+, signalling connect by periperal. Also used in 188 * Pull-up D+, signalling connect by periperal. Also used in
189 * data-line pulsing in SRP 189 * data-line pulsing in SRP
190 */ 190 */
191void fsl_otg_loc_conn(int on) 191void fsl_otg_loc_conn(struct otg_fsm *fsm, int on)
192{ 192{
193 u32 tmp; 193 u32 tmp;
194 194
@@ -207,7 +207,7 @@ void fsl_otg_loc_conn(int on)
207 * port. In host mode, controller will automatically send SOF. 207 * port. In host mode, controller will automatically send SOF.
208 * Suspend will block the data on the port. 208 * Suspend will block the data on the port.
209 */ 209 */
210void fsl_otg_loc_sof(int on) 210void fsl_otg_loc_sof(struct otg_fsm *fsm, int on)
211{ 211{
212 u32 tmp; 212 u32 tmp;
213 213
@@ -222,7 +222,7 @@ void fsl_otg_loc_sof(int on)
222} 222}
223 223
224/* Start SRP pulsing by data-line pulsing, followed with v-bus pulsing. */ 224/* Start SRP pulsing by data-line pulsing, followed with v-bus pulsing. */
225void fsl_otg_start_pulse(void) 225void fsl_otg_start_pulse(struct otg_fsm *fsm)
226{ 226{
227 u32 tmp; 227 u32 tmp;
228 228
@@ -235,7 +235,7 @@ void fsl_otg_start_pulse(void)
235 fsl_otg_loc_conn(1); 235 fsl_otg_loc_conn(1);
236#endif 236#endif
237 237
238 fsl_otg_add_timer(b_data_pulse_tmr); 238 fsl_otg_add_timer(fsm, b_data_pulse_tmr);
239} 239}
240 240
241void b_data_pulse_end(unsigned long foo) 241void b_data_pulse_end(unsigned long foo)
@@ -252,14 +252,14 @@ void b_data_pulse_end(unsigned long foo)
252void fsl_otg_pulse_vbus(void) 252void fsl_otg_pulse_vbus(void)
253{ 253{
254 srp_wait_done = 0; 254 srp_wait_done = 0;
255 fsl_otg_chrg_vbus(1); 255 fsl_otg_chrg_vbus(&fsl_otg_dev->fsm, 1);
256 /* start the timer to end vbus charge */ 256 /* start the timer to end vbus charge */
257 fsl_otg_add_timer(b_vbus_pulse_tmr); 257 fsl_otg_add_timer(&fsl_otg_dev->fsm, b_vbus_pulse_tmr);
258} 258}
259 259
260void b_vbus_pulse_end(unsigned long foo) 260void b_vbus_pulse_end(unsigned long foo)
261{ 261{
262 fsl_otg_chrg_vbus(0); 262 fsl_otg_chrg_vbus(&fsl_otg_dev->fsm, 0);
263 263
264 /* 264 /*
265 * As USB3300 using the same a_sess_vld and b_sess_vld voltage 265 * As USB3300 using the same a_sess_vld and b_sess_vld voltage
@@ -267,7 +267,7 @@ void b_vbus_pulse_end(unsigned long foo)
267 * residual voltage of vbus pulsing and A device pull up 267 * residual voltage of vbus pulsing and A device pull up
268 */ 268 */
269 fsl_otg_dischrg_vbus(1); 269 fsl_otg_dischrg_vbus(1);
270 fsl_otg_add_timer(b_srp_wait_tmr); 270 fsl_otg_add_timer(&fsl_otg_dev->fsm, b_srp_wait_tmr);
271} 271}
272 272
273void b_srp_end(unsigned long foo) 273void b_srp_end(unsigned long foo)
@@ -289,7 +289,7 @@ void a_wait_enum(unsigned long foo)
289{ 289{
290 VDBG("a_wait_enum timeout\n"); 290 VDBG("a_wait_enum timeout\n");
291 if (!fsl_otg_dev->phy.otg->host->b_hnp_enable) 291 if (!fsl_otg_dev->phy.otg->host->b_hnp_enable)
292 fsl_otg_add_timer(a_wait_enum_tmr); 292 fsl_otg_add_timer(&fsl_otg_dev->fsm, a_wait_enum_tmr);
293 else 293 else
294 otg_statemachine(&fsl_otg_dev->fsm); 294 otg_statemachine(&fsl_otg_dev->fsm);
295} 295}
@@ -375,8 +375,42 @@ void fsl_otg_uninit_timers(void)
375 kfree(b_vbus_pulse_tmr); 375 kfree(b_vbus_pulse_tmr);
376} 376}
377 377
378static struct fsl_otg_timer *fsl_otg_get_timer(enum otg_fsm_timer t)
379{
380 struct fsl_otg_timer *timer;
381
382 /* REVISIT: use array of pointers to timers instead */
383 switch (t) {
384 case A_WAIT_VRISE:
385 timer = a_wait_vrise_tmr;
386 break;
387 case A_WAIT_BCON:
388 timer = a_wait_vrise_tmr;
389 break;
390 case A_AIDL_BDIS:
391 timer = a_wait_vrise_tmr;
392 break;
393 case B_ASE0_BRST:
394 timer = a_wait_vrise_tmr;
395 break;
396 case B_SE0_SRP:
397 timer = a_wait_vrise_tmr;
398 break;
399 case B_SRP_FAIL:
400 timer = a_wait_vrise_tmr;
401 break;
402 case A_WAIT_ENUM:
403 timer = a_wait_vrise_tmr;
404 break;
405 default:
406 timer = NULL;
407 }
408
409 return timer;
410}
411
378/* Add timer to timer list */ 412/* Add timer to timer list */
379void fsl_otg_add_timer(void *gtimer) 413void fsl_otg_add_timer(struct otg_fsm *fsm, void *gtimer)
380{ 414{
381 struct fsl_otg_timer *timer = gtimer; 415 struct fsl_otg_timer *timer = gtimer;
382 struct fsl_otg_timer *tmp_timer; 416 struct fsl_otg_timer *tmp_timer;
@@ -394,8 +428,19 @@ void fsl_otg_add_timer(void *gtimer)
394 list_add_tail(&timer->list, &active_timers); 428 list_add_tail(&timer->list, &active_timers);
395} 429}
396 430
431static void fsl_otg_fsm_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer t)
432{
433 struct fsl_otg_timer *timer;
434
435 timer = fsl_otg_get_timer(t);
436 if (!timer)
437 return;
438
439 fsl_otg_add_timer(fsm, timer);
440}
441
397/* Remove timer from the timer list; clear timeout status */ 442/* Remove timer from the timer list; clear timeout status */
398void fsl_otg_del_timer(void *gtimer) 443void fsl_otg_del_timer(struct otg_fsm *fsm, void *gtimer)
399{ 444{
400 struct fsl_otg_timer *timer = gtimer; 445 struct fsl_otg_timer *timer = gtimer;
401 struct fsl_otg_timer *tmp_timer, *del_tmp; 446 struct fsl_otg_timer *tmp_timer, *del_tmp;
@@ -405,6 +450,17 @@ void fsl_otg_del_timer(void *gtimer)
405 list_del(&timer->list); 450 list_del(&timer->list);
406} 451}
407 452
453static void fsl_otg_fsm_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer t)
454{
455 struct fsl_otg_timer *timer;
456
457 timer = fsl_otg_get_timer(t);
458 if (!timer)
459 return;
460
461 fsl_otg_del_timer(fsm, timer);
462}
463
408/* 464/*
409 * Reduce timer count by 1, and find timeout conditions. 465 * Reduce timer count by 1, and find timeout conditions.
410 * Called by fsl_otg 1ms timer interrupt 466 * Called by fsl_otg 1ms timer interrupt
@@ -468,7 +524,7 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on)
468 retval = dev->driver->pm->resume(dev); 524 retval = dev->driver->pm->resume(dev);
469 if (fsm->id) { 525 if (fsm->id) {
470 /* default-b */ 526 /* default-b */
471 fsl_otg_drv_vbus(1); 527 fsl_otg_drv_vbus(fsm, 1);
472 /* 528 /*
473 * Workaround: b_host can't driver 529 * Workaround: b_host can't driver
474 * vbus, but PP in PORTSC needs to 530 * vbus, but PP in PORTSC needs to
@@ -493,7 +549,7 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on)
493 retval = dev->driver->pm->suspend(dev); 549 retval = dev->driver->pm->suspend(dev);
494 if (fsm->id) 550 if (fsm->id)
495 /* default-b */ 551 /* default-b */
496 fsl_otg_drv_vbus(0); 552 fsl_otg_drv_vbus(fsm, 0);
497 } 553 }
498 otg_dev->host_working = 0; 554 otg_dev->host_working = 0;
499 } 555 }
@@ -757,8 +813,8 @@ static struct otg_fsm_ops fsl_otg_ops = {
757 .loc_sof = fsl_otg_loc_sof, 813 .loc_sof = fsl_otg_loc_sof,
758 .start_pulse = fsl_otg_start_pulse, 814 .start_pulse = fsl_otg_start_pulse,
759 815
760 .add_timer = fsl_otg_add_timer, 816 .add_timer = fsl_otg_fsm_add_timer,
761 .del_timer = fsl_otg_del_timer, 817 .del_timer = fsl_otg_fsm_del_timer,
762 818
763 .start_host = fsl_otg_start_host, 819 .start_host = fsl_otg_start_host,
764 .start_gadget = fsl_otg_start_gadget, 820 .start_gadget = fsl_otg_start_gadget,
@@ -1011,7 +1067,7 @@ static int show_fsl_usb2_otg_state(struct device *dev,
1011 "b_bus_suspend: %d\n" 1067 "b_bus_suspend: %d\n"
1012 "b_conn: %d\n" 1068 "b_conn: %d\n"
1013 "b_se0_srp: %d\n" 1069 "b_se0_srp: %d\n"
1014 "b_sess_end: %d\n" 1070 "b_ssend_srp: %d\n"
1015 "b_sess_vld: %d\n" 1071 "b_sess_vld: %d\n"
1016 "id: %d\n", 1072 "id: %d\n",
1017 fsm->a_bus_req, 1073 fsm->a_bus_req,
@@ -1026,7 +1082,7 @@ static int show_fsl_usb2_otg_state(struct device *dev,
1026 fsm->b_bus_suspend, 1082 fsm->b_bus_suspend,
1027 fsm->b_conn, 1083 fsm->b_conn,
1028 fsm->b_se0_srp, 1084 fsm->b_se0_srp,
1029 fsm->b_sess_end, 1085 fsm->b_ssend_srp,
1030 fsm->b_sess_vld, 1086 fsm->b_sess_vld,
1031 fsm->id); 1087 fsm->id);
1032 size -= t; 1088 size -= t;
@@ -1057,7 +1113,7 @@ static long fsl_otg_ioctl(struct file *file, unsigned int cmd,
1057 break; 1113 break;
1058 1114
1059 case SET_A_SUSPEND_REQ: 1115 case SET_A_SUSPEND_REQ:
1060 fsl_otg_dev->fsm.a_suspend_req = arg; 1116 fsl_otg_dev->fsm.a_suspend_req_inf = arg;
1061 break; 1117 break;
1062 1118
1063 case SET_A_BUS_DROP: 1119 case SET_A_BUS_DROP:
diff --git a/drivers/usb/phy/phy-fsl-usb.h b/drivers/usb/phy/phy-fsl-usb.h
index e1859b8ef567..7365170a2f23 100644
--- a/drivers/usb/phy/phy-fsl-usb.h
+++ b/drivers/usb/phy/phy-fsl-usb.h
@@ -401,6 +401,6 @@ struct fsl_otg_config {
401#define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int) 401#define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int)
402#define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int) 402#define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int)
403 403
404void fsl_otg_add_timer(void *timer); 404void fsl_otg_add_timer(struct otg_fsm *fsm, void *timer);
405void fsl_otg_del_timer(void *timer); 405void fsl_otg_del_timer(struct otg_fsm *fsm, void *timer);
406void fsl_otg_pulse_vbus(void); 406void fsl_otg_pulse_vbus(void);
diff --git a/drivers/usb/phy/phy-fsm-usb.c b/drivers/usb/phy/phy-fsm-usb.c
index 7f4596606e18..329c2d2f8595 100644
--- a/drivers/usb/phy/phy-fsm-usb.c
+++ b/drivers/usb/phy/phy-fsm-usb.c
@@ -41,17 +41,17 @@ static int otg_set_protocol(struct otg_fsm *fsm, int protocol)
41 fsm->protocol, protocol); 41 fsm->protocol, protocol);
42 /* stop old protocol */ 42 /* stop old protocol */
43 if (fsm->protocol == PROTO_HOST) 43 if (fsm->protocol == PROTO_HOST)
44 ret = fsm->ops->start_host(fsm, 0); 44 ret = otg_start_host(fsm, 0);
45 else if (fsm->protocol == PROTO_GADGET) 45 else if (fsm->protocol == PROTO_GADGET)
46 ret = fsm->ops->start_gadget(fsm, 0); 46 ret = otg_start_gadget(fsm, 0);
47 if (ret) 47 if (ret)
48 return ret; 48 return ret;
49 49
50 /* start new protocol */ 50 /* start new protocol */
51 if (protocol == PROTO_HOST) 51 if (protocol == PROTO_HOST)
52 ret = fsm->ops->start_host(fsm, 1); 52 ret = otg_start_host(fsm, 1);
53 else if (protocol == PROTO_GADGET) 53 else if (protocol == PROTO_GADGET)
54 ret = fsm->ops->start_gadget(fsm, 1); 54 ret = otg_start_gadget(fsm, 1);
55 if (ret) 55 if (ret)
56 return ret; 56 return ret;
57 57
@@ -69,42 +69,50 @@ void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state)
69{ 69{
70 switch (old_state) { 70 switch (old_state) {
71 case OTG_STATE_B_IDLE: 71 case OTG_STATE_B_IDLE:
72 otg_del_timer(fsm, b_se0_srp_tmr); 72 otg_del_timer(fsm, B_SE0_SRP);
73 fsm->b_se0_srp = 0; 73 fsm->b_se0_srp = 0;
74 fsm->adp_sns = 0;
75 fsm->adp_prb = 0;
74 break; 76 break;
75 case OTG_STATE_B_SRP_INIT: 77 case OTG_STATE_B_SRP_INIT:
78 fsm->data_pulse = 0;
76 fsm->b_srp_done = 0; 79 fsm->b_srp_done = 0;
77 break; 80 break;
78 case OTG_STATE_B_PERIPHERAL: 81 case OTG_STATE_B_PERIPHERAL:
79 break; 82 break;
80 case OTG_STATE_B_WAIT_ACON: 83 case OTG_STATE_B_WAIT_ACON:
81 otg_del_timer(fsm, b_ase0_brst_tmr); 84 otg_del_timer(fsm, B_ASE0_BRST);
82 fsm->b_ase0_brst_tmout = 0; 85 fsm->b_ase0_brst_tmout = 0;
83 break; 86 break;
84 case OTG_STATE_B_HOST: 87 case OTG_STATE_B_HOST:
85 break; 88 break;
86 case OTG_STATE_A_IDLE: 89 case OTG_STATE_A_IDLE:
90 fsm->adp_prb = 0;
87 break; 91 break;
88 case OTG_STATE_A_WAIT_VRISE: 92 case OTG_STATE_A_WAIT_VRISE:
89 otg_del_timer(fsm, a_wait_vrise_tmr); 93 otg_del_timer(fsm, A_WAIT_VRISE);
90 fsm->a_wait_vrise_tmout = 0; 94 fsm->a_wait_vrise_tmout = 0;
91 break; 95 break;
92 case OTG_STATE_A_WAIT_BCON: 96 case OTG_STATE_A_WAIT_BCON:
93 otg_del_timer(fsm, a_wait_bcon_tmr); 97 otg_del_timer(fsm, A_WAIT_BCON);
94 fsm->a_wait_bcon_tmout = 0; 98 fsm->a_wait_bcon_tmout = 0;
95 break; 99 break;
96 case OTG_STATE_A_HOST: 100 case OTG_STATE_A_HOST:
97 otg_del_timer(fsm, a_wait_enum_tmr); 101 otg_del_timer(fsm, A_WAIT_ENUM);
98 break; 102 break;
99 case OTG_STATE_A_SUSPEND: 103 case OTG_STATE_A_SUSPEND:
100 otg_del_timer(fsm, a_aidl_bdis_tmr); 104 otg_del_timer(fsm, A_AIDL_BDIS);
101 fsm->a_aidl_bdis_tmout = 0; 105 fsm->a_aidl_bdis_tmout = 0;
102 fsm->a_suspend_req = 0; 106 fsm->a_suspend_req_inf = 0;
103 break; 107 break;
104 case OTG_STATE_A_PERIPHERAL: 108 case OTG_STATE_A_PERIPHERAL:
109 otg_del_timer(fsm, A_BIDL_ADIS);
110 fsm->a_bidl_adis_tmout = 0;
105 break; 111 break;
106 case OTG_STATE_A_WAIT_VFALL: 112 case OTG_STATE_A_WAIT_VFALL:
107 otg_del_timer(fsm, a_wait_vrise_tmr); 113 otg_del_timer(fsm, A_WAIT_VFALL);
114 fsm->a_wait_vfall_tmout = 0;
115 otg_del_timer(fsm, A_WAIT_VRISE);
108 break; 116 break;
109 case OTG_STATE_A_VBUS_ERR: 117 case OTG_STATE_A_VBUS_ERR:
110 break; 118 break;
@@ -127,14 +135,19 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
127 otg_chrg_vbus(fsm, 0); 135 otg_chrg_vbus(fsm, 0);
128 otg_loc_conn(fsm, 0); 136 otg_loc_conn(fsm, 0);
129 otg_loc_sof(fsm, 0); 137 otg_loc_sof(fsm, 0);
138 /*
139 * Driver is responsible for starting ADP probing
140 * if ADP sensing times out.
141 */
142 otg_start_adp_sns(fsm);
130 otg_set_protocol(fsm, PROTO_UNDEF); 143 otg_set_protocol(fsm, PROTO_UNDEF);
131 otg_add_timer(fsm, b_se0_srp_tmr); 144 otg_add_timer(fsm, B_SE0_SRP);
132 break; 145 break;
133 case OTG_STATE_B_SRP_INIT: 146 case OTG_STATE_B_SRP_INIT:
134 otg_start_pulse(fsm); 147 otg_start_pulse(fsm);
135 otg_loc_sof(fsm, 0); 148 otg_loc_sof(fsm, 0);
136 otg_set_protocol(fsm, PROTO_UNDEF); 149 otg_set_protocol(fsm, PROTO_UNDEF);
137 otg_add_timer(fsm, b_srp_fail_tmr); 150 otg_add_timer(fsm, B_SRP_FAIL);
138 break; 151 break;
139 case OTG_STATE_B_PERIPHERAL: 152 case OTG_STATE_B_PERIPHERAL:
140 otg_chrg_vbus(fsm, 0); 153 otg_chrg_vbus(fsm, 0);
@@ -147,7 +160,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
147 otg_loc_conn(fsm, 0); 160 otg_loc_conn(fsm, 0);
148 otg_loc_sof(fsm, 0); 161 otg_loc_sof(fsm, 0);
149 otg_set_protocol(fsm, PROTO_HOST); 162 otg_set_protocol(fsm, PROTO_HOST);
150 otg_add_timer(fsm, b_ase0_brst_tmr); 163 otg_add_timer(fsm, B_ASE0_BRST);
151 fsm->a_bus_suspend = 0; 164 fsm->a_bus_suspend = 0;
152 break; 165 break;
153 case OTG_STATE_B_HOST: 166 case OTG_STATE_B_HOST:
@@ -163,6 +176,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
163 otg_chrg_vbus(fsm, 0); 176 otg_chrg_vbus(fsm, 0);
164 otg_loc_conn(fsm, 0); 177 otg_loc_conn(fsm, 0);
165 otg_loc_sof(fsm, 0); 178 otg_loc_sof(fsm, 0);
179 otg_start_adp_prb(fsm);
166 otg_set_protocol(fsm, PROTO_HOST); 180 otg_set_protocol(fsm, PROTO_HOST);
167 break; 181 break;
168 case OTG_STATE_A_WAIT_VRISE: 182 case OTG_STATE_A_WAIT_VRISE:
@@ -170,14 +184,14 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
170 otg_loc_conn(fsm, 0); 184 otg_loc_conn(fsm, 0);
171 otg_loc_sof(fsm, 0); 185 otg_loc_sof(fsm, 0);
172 otg_set_protocol(fsm, PROTO_HOST); 186 otg_set_protocol(fsm, PROTO_HOST);
173 otg_add_timer(fsm, a_wait_vrise_tmr); 187 otg_add_timer(fsm, A_WAIT_VRISE);
174 break; 188 break;
175 case OTG_STATE_A_WAIT_BCON: 189 case OTG_STATE_A_WAIT_BCON:
176 otg_drv_vbus(fsm, 1); 190 otg_drv_vbus(fsm, 1);
177 otg_loc_conn(fsm, 0); 191 otg_loc_conn(fsm, 0);
178 otg_loc_sof(fsm, 0); 192 otg_loc_sof(fsm, 0);
179 otg_set_protocol(fsm, PROTO_HOST); 193 otg_set_protocol(fsm, PROTO_HOST);
180 otg_add_timer(fsm, a_wait_bcon_tmr); 194 otg_add_timer(fsm, A_WAIT_BCON);
181 break; 195 break;
182 case OTG_STATE_A_HOST: 196 case OTG_STATE_A_HOST:
183 otg_drv_vbus(fsm, 1); 197 otg_drv_vbus(fsm, 1);
@@ -188,15 +202,15 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
188 * When HNP is triggered while a_bus_req = 0, a_host will 202 * When HNP is triggered while a_bus_req = 0, a_host will
189 * suspend too fast to complete a_set_b_hnp_en 203 * suspend too fast to complete a_set_b_hnp_en
190 */ 204 */
191 if (!fsm->a_bus_req || fsm->a_suspend_req) 205 if (!fsm->a_bus_req || fsm->a_suspend_req_inf)
192 otg_add_timer(fsm, a_wait_enum_tmr); 206 otg_add_timer(fsm, A_WAIT_ENUM);
193 break; 207 break;
194 case OTG_STATE_A_SUSPEND: 208 case OTG_STATE_A_SUSPEND:
195 otg_drv_vbus(fsm, 1); 209 otg_drv_vbus(fsm, 1);
196 otg_loc_conn(fsm, 0); 210 otg_loc_conn(fsm, 0);
197 otg_loc_sof(fsm, 0); 211 otg_loc_sof(fsm, 0);
198 otg_set_protocol(fsm, PROTO_HOST); 212 otg_set_protocol(fsm, PROTO_HOST);
199 otg_add_timer(fsm, a_aidl_bdis_tmr); 213 otg_add_timer(fsm, A_AIDL_BDIS);
200 214
201 break; 215 break;
202 case OTG_STATE_A_PERIPHERAL: 216 case OTG_STATE_A_PERIPHERAL:
@@ -204,12 +218,14 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
204 otg_loc_sof(fsm, 0); 218 otg_loc_sof(fsm, 0);
205 otg_set_protocol(fsm, PROTO_GADGET); 219 otg_set_protocol(fsm, PROTO_GADGET);
206 otg_drv_vbus(fsm, 1); 220 otg_drv_vbus(fsm, 1);
221 otg_add_timer(fsm, A_BIDL_ADIS);
207 break; 222 break;
208 case OTG_STATE_A_WAIT_VFALL: 223 case OTG_STATE_A_WAIT_VFALL:
209 otg_drv_vbus(fsm, 0); 224 otg_drv_vbus(fsm, 0);
210 otg_loc_conn(fsm, 0); 225 otg_loc_conn(fsm, 0);
211 otg_loc_sof(fsm, 0); 226 otg_loc_sof(fsm, 0);
212 otg_set_protocol(fsm, PROTO_HOST); 227 otg_set_protocol(fsm, PROTO_HOST);
228 otg_add_timer(fsm, A_WAIT_VFALL);
213 break; 229 break;
214 case OTG_STATE_A_VBUS_ERR: 230 case OTG_STATE_A_VBUS_ERR:
215 otg_drv_vbus(fsm, 0); 231 otg_drv_vbus(fsm, 0);
@@ -250,7 +266,8 @@ int otg_statemachine(struct otg_fsm *fsm)
250 otg_set_state(fsm, OTG_STATE_A_IDLE); 266 otg_set_state(fsm, OTG_STATE_A_IDLE);
251 else if (fsm->b_sess_vld && fsm->otg->gadget) 267 else if (fsm->b_sess_vld && fsm->otg->gadget)
252 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); 268 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
253 else if (fsm->b_bus_req && fsm->b_sess_end && fsm->b_se0_srp) 269 else if ((fsm->b_bus_req || fsm->adp_change || fsm->power_up) &&
270 fsm->b_ssend_srp && fsm->b_se0_srp)
254 otg_set_state(fsm, OTG_STATE_B_SRP_INIT); 271 otg_set_state(fsm, OTG_STATE_B_SRP_INIT);
255 break; 272 break;
256 case OTG_STATE_B_SRP_INIT: 273 case OTG_STATE_B_SRP_INIT:
@@ -277,13 +294,14 @@ int otg_statemachine(struct otg_fsm *fsm)
277 case OTG_STATE_B_HOST: 294 case OTG_STATE_B_HOST:
278 if (!fsm->id || !fsm->b_sess_vld) 295 if (!fsm->id || !fsm->b_sess_vld)
279 otg_set_state(fsm, OTG_STATE_B_IDLE); 296 otg_set_state(fsm, OTG_STATE_B_IDLE);
280 else if (!fsm->b_bus_req || !fsm->a_conn) 297 else if (!fsm->b_bus_req || !fsm->a_conn || fsm->test_device)
281 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); 298 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
282 break; 299 break;
283 case OTG_STATE_A_IDLE: 300 case OTG_STATE_A_IDLE:
284 if (fsm->id) 301 if (fsm->id)
285 otg_set_state(fsm, OTG_STATE_B_IDLE); 302 otg_set_state(fsm, OTG_STATE_B_IDLE);
286 else if (!fsm->a_bus_drop && (fsm->a_bus_req || fsm->a_srp_det)) 303 else if (!fsm->a_bus_drop && (fsm->a_bus_req ||
304 fsm->a_srp_det || fsm->adp_change || fsm->power_up))
287 otg_set_state(fsm, OTG_STATE_A_WAIT_VRISE); 305 otg_set_state(fsm, OTG_STATE_A_WAIT_VRISE);
288 break; 306 break;
289 case OTG_STATE_A_WAIT_VRISE: 307 case OTG_STATE_A_WAIT_VRISE:
@@ -301,7 +319,7 @@ int otg_statemachine(struct otg_fsm *fsm)
301 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); 319 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
302 break; 320 break;
303 case OTG_STATE_A_HOST: 321 case OTG_STATE_A_HOST:
304 if ((!fsm->a_bus_req || fsm->a_suspend_req) && 322 if ((!fsm->a_bus_req || fsm->a_suspend_req_inf) &&
305 fsm->otg->host->b_hnp_enable) 323 fsm->otg->host->b_hnp_enable)
306 otg_set_state(fsm, OTG_STATE_A_SUSPEND); 324 otg_set_state(fsm, OTG_STATE_A_SUSPEND);
307 else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop) 325 else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop)
@@ -324,14 +342,14 @@ int otg_statemachine(struct otg_fsm *fsm)
324 case OTG_STATE_A_PERIPHERAL: 342 case OTG_STATE_A_PERIPHERAL:
325 if (fsm->id || fsm->a_bus_drop) 343 if (fsm->id || fsm->a_bus_drop)
326 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); 344 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
327 else if (fsm->b_bus_suspend) 345 else if (fsm->a_bidl_adis_tmout || fsm->b_bus_suspend)
328 otg_set_state(fsm, OTG_STATE_A_WAIT_BCON); 346 otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
329 else if (!fsm->a_vbus_vld) 347 else if (!fsm->a_vbus_vld)
330 otg_set_state(fsm, OTG_STATE_A_VBUS_ERR); 348 otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
331 break; 349 break;
332 case OTG_STATE_A_WAIT_VFALL: 350 case OTG_STATE_A_WAIT_VFALL:
333 if (fsm->id || fsm->a_bus_req || (!fsm->a_sess_vld && 351 if (fsm->a_wait_vfall_tmout || fsm->id || fsm->a_bus_req ||
334 !fsm->b_conn)) 352 (!fsm->a_sess_vld && !fsm->b_conn))
335 otg_set_state(fsm, OTG_STATE_A_IDLE); 353 otg_set_state(fsm, OTG_STATE_A_IDLE);
336 break; 354 break;
337 case OTG_STATE_A_VBUS_ERR: 355 case OTG_STATE_A_VBUS_ERR:
diff --git a/drivers/usb/phy/phy-fsm-usb.h b/drivers/usb/phy/phy-fsm-usb.h
index fbe586206f33..7441b46a27f1 100644
--- a/drivers/usb/phy/phy-fsm-usb.h
+++ b/drivers/usb/phy/phy-fsm-usb.h
@@ -34,45 +34,76 @@
34#define PROTO_HOST (1) 34#define PROTO_HOST (1)
35#define PROTO_GADGET (2) 35#define PROTO_GADGET (2)
36 36
37enum otg_fsm_timer {
38 /* Standard OTG timers */
39 A_WAIT_VRISE,
40 A_WAIT_VFALL,
41 A_WAIT_BCON,
42 A_AIDL_BDIS,
43 B_ASE0_BRST,
44 A_BIDL_ADIS,
45
46 /* Auxiliary timers */
47 B_SE0_SRP,
48 B_SRP_FAIL,
49 A_WAIT_ENUM,
50
51 NUM_OTG_FSM_TIMERS,
52};
53
37/* OTG state machine according to the OTG spec */ 54/* OTG state machine according to the OTG spec */
38struct otg_fsm { 55struct otg_fsm {
39 /* Input */ 56 /* Input */
57 int id;
58 int adp_change;
59 int power_up;
60 int test_device;
61 int a_bus_drop;
62 int a_bus_req;
63 int a_srp_det;
64 int a_vbus_vld;
65 int b_conn;
40 int a_bus_resume; 66 int a_bus_resume;
41 int a_bus_suspend; 67 int a_bus_suspend;
42 int a_conn; 68 int a_conn;
69 int b_bus_req;
70 int b_se0_srp;
71 int b_ssend_srp;
72 int b_sess_vld;
73 /* Auxilary inputs */
43 int a_sess_vld; 74 int a_sess_vld;
44 int a_srp_det;
45 int a_vbus_vld;
46 int b_bus_resume; 75 int b_bus_resume;
47 int b_bus_suspend; 76 int b_bus_suspend;
48 int b_conn; 77
49 int b_se0_srp; 78 /* Output */
50 int b_sess_end; 79 int data_pulse;
51 int b_sess_vld; 80 int drv_vbus;
52 int id; 81 int loc_conn;
82 int loc_sof;
83 int adp_prb;
84 int adp_sns;
53 85
54 /* Internal variables */ 86 /* Internal variables */
55 int a_set_b_hnp_en; 87 int a_set_b_hnp_en;
56 int b_srp_done; 88 int b_srp_done;
57 int b_hnp_enable; 89 int b_hnp_enable;
90 int a_clr_err;
91
92 /* Informative variables */
93 int a_bus_drop_inf;
94 int a_bus_req_inf;
95 int a_clr_err_inf;
96 int b_bus_req_inf;
97 /* Auxilary informative variables */
98 int a_suspend_req_inf;
58 99
59 /* Timeout indicator for timers */ 100 /* Timeout indicator for timers */
60 int a_wait_vrise_tmout; 101 int a_wait_vrise_tmout;
102 int a_wait_vfall_tmout;
61 int a_wait_bcon_tmout; 103 int a_wait_bcon_tmout;
62 int a_aidl_bdis_tmout; 104 int a_aidl_bdis_tmout;
63 int b_ase0_brst_tmout; 105 int b_ase0_brst_tmout;
64 106 int a_bidl_adis_tmout;
65 /* Informative variables */
66 int a_bus_drop;
67 int a_bus_req;
68 int a_clr_err;
69 int a_suspend_req;
70 int b_bus_req;
71
72 /* Output */
73 int drv_vbus;
74 int loc_conn;
75 int loc_sof;
76 107
77 struct otg_fsm_ops *ops; 108 struct otg_fsm_ops *ops;
78 struct usb_otg *otg; 109 struct usb_otg *otg;
@@ -83,65 +114,123 @@ struct otg_fsm {
83}; 114};
84 115
85struct otg_fsm_ops { 116struct otg_fsm_ops {
86 void (*chrg_vbus)(int on); 117 void (*chrg_vbus)(struct otg_fsm *fsm, int on);
87 void (*drv_vbus)(int on); 118 void (*drv_vbus)(struct otg_fsm *fsm, int on);
88 void (*loc_conn)(int on); 119 void (*loc_conn)(struct otg_fsm *fsm, int on);
89 void (*loc_sof)(int on); 120 void (*loc_sof)(struct otg_fsm *fsm, int on);
90 void (*start_pulse)(void); 121 void (*start_pulse)(struct otg_fsm *fsm);
91 void (*add_timer)(void *timer); 122 void (*start_adp_prb)(struct otg_fsm *fsm);
92 void (*del_timer)(void *timer); 123 void (*start_adp_sns)(struct otg_fsm *fsm);
124 void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
125 void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
93 int (*start_host)(struct otg_fsm *fsm, int on); 126 int (*start_host)(struct otg_fsm *fsm, int on);
94 int (*start_gadget)(struct otg_fsm *fsm, int on); 127 int (*start_gadget)(struct otg_fsm *fsm, int on);
95}; 128};
96 129
97 130
98static inline void otg_chrg_vbus(struct otg_fsm *fsm, int on) 131static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on)
99{ 132{
100 fsm->ops->chrg_vbus(on); 133 if (!fsm->ops->chrg_vbus)
134 return -EOPNOTSUPP;
135 fsm->ops->chrg_vbus(fsm, on);
136 return 0;
101} 137}
102 138
103static inline void otg_drv_vbus(struct otg_fsm *fsm, int on) 139static inline int otg_drv_vbus(struct otg_fsm *fsm, int on)
104{ 140{
141 if (!fsm->ops->drv_vbus)
142 return -EOPNOTSUPP;
105 if (fsm->drv_vbus != on) { 143 if (fsm->drv_vbus != on) {
106 fsm->drv_vbus = on; 144 fsm->drv_vbus = on;
107 fsm->ops->drv_vbus(on); 145 fsm->ops->drv_vbus(fsm, on);
108 } 146 }
147 return 0;
109} 148}
110 149
111static inline void otg_loc_conn(struct otg_fsm *fsm, int on) 150static inline int otg_loc_conn(struct otg_fsm *fsm, int on)
112{ 151{
152 if (!fsm->ops->loc_conn)
153 return -EOPNOTSUPP;
113 if (fsm->loc_conn != on) { 154 if (fsm->loc_conn != on) {
114 fsm->loc_conn = on; 155 fsm->loc_conn = on;
115 fsm->ops->loc_conn(on); 156 fsm->ops->loc_conn(fsm, on);
116 } 157 }
158 return 0;
117} 159}
118 160
119static inline void otg_loc_sof(struct otg_fsm *fsm, int on) 161static inline int otg_loc_sof(struct otg_fsm *fsm, int on)
120{ 162{
163 if (!fsm->ops->loc_sof)
164 return -EOPNOTSUPP;
121 if (fsm->loc_sof != on) { 165 if (fsm->loc_sof != on) {
122 fsm->loc_sof = on; 166 fsm->loc_sof = on;
123 fsm->ops->loc_sof(on); 167 fsm->ops->loc_sof(fsm, on);
168 }
169 return 0;
170}
171
172static inline int otg_start_pulse(struct otg_fsm *fsm)
173{
174 if (!fsm->ops->start_pulse)
175 return -EOPNOTSUPP;
176 if (!fsm->data_pulse) {
177 fsm->data_pulse = 1;
178 fsm->ops->start_pulse(fsm);
124 } 179 }
180 return 0;
125} 181}
126 182
127static inline void otg_start_pulse(struct otg_fsm *fsm) 183static inline int otg_start_adp_prb(struct otg_fsm *fsm)
128{ 184{
129 fsm->ops->start_pulse(); 185 if (!fsm->ops->start_adp_prb)
186 return -EOPNOTSUPP;
187 if (!fsm->adp_prb) {
188 fsm->adp_sns = 0;
189 fsm->adp_prb = 1;
190 fsm->ops->start_adp_prb(fsm);
191 }
192 return 0;
130} 193}
131 194
132static inline void otg_add_timer(struct otg_fsm *fsm, void *timer) 195static inline int otg_start_adp_sns(struct otg_fsm *fsm)
133{ 196{
134 fsm->ops->add_timer(timer); 197 if (!fsm->ops->start_adp_sns)
198 return -EOPNOTSUPP;
199 if (!fsm->adp_sns) {
200 fsm->adp_sns = 1;
201 fsm->ops->start_adp_sns(fsm);
202 }
203 return 0;
135} 204}
136 205
137static inline void otg_del_timer(struct otg_fsm *fsm, void *timer) 206static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
138{ 207{
139 fsm->ops->del_timer(timer); 208 if (!fsm->ops->add_timer)
209 return -EOPNOTSUPP;
210 fsm->ops->add_timer(fsm, timer);
211 return 0;
140} 212}
141 213
142int otg_statemachine(struct otg_fsm *fsm); 214static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
215{
216 if (!fsm->ops->del_timer)
217 return -EOPNOTSUPP;
218 fsm->ops->del_timer(fsm, timer);
219 return 0;
220}
143 221
144/* Defined by device specific driver, for different timer implementation */ 222static inline int otg_start_host(struct otg_fsm *fsm, int on)
145extern struct fsl_otg_timer *a_wait_vrise_tmr, *a_wait_bcon_tmr, 223{
146 *a_aidl_bdis_tmr, *b_ase0_brst_tmr, *b_se0_srp_tmr, *b_srp_fail_tmr, 224 if (!fsm->ops->start_host)
147 *a_wait_enum_tmr; 225 return -EOPNOTSUPP;
226 return fsm->ops->start_host(fsm, on);
227}
228
229static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
230{
231 if (!fsm->ops->start_gadget)
232 return -EOPNOTSUPP;
233 return fsm->ops->start_gadget(fsm, on);
234}
235
236int otg_statemachine(struct otg_fsm *fsm);
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index efe59f3f7fda..fce3a9e9bb5d 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -35,6 +35,9 @@
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#include <linux/of_gpio.h>
39#include <linux/gpio.h>
40#include <linux/delay.h>
38 41
39#include "phy-generic.h" 42#include "phy-generic.h"
40 43
@@ -64,6 +67,23 @@ static int nop_set_suspend(struct usb_phy *x, int suspend)
64 return 0; 67 return 0;
65} 68}
66 69
70static void nop_reset_set(struct usb_phy_gen_xceiv *nop, int asserted)
71{
72 int value;
73
74 if (!gpio_is_valid(nop->gpio_reset))
75 return;
76
77 value = asserted;
78 if (nop->reset_active_low)
79 value = !value;
80
81 gpio_set_value_cansleep(nop->gpio_reset, value);
82
83 if (!asserted)
84 usleep_range(10000, 20000);
85}
86
67int usb_gen_phy_init(struct usb_phy *phy) 87int usb_gen_phy_init(struct usb_phy *phy)
68{ 88{
69 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); 89 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
@@ -74,13 +94,10 @@ int usb_gen_phy_init(struct usb_phy *phy)
74 } 94 }
75 95
76 if (!IS_ERR(nop->clk)) 96 if (!IS_ERR(nop->clk))
77 clk_enable(nop->clk); 97 clk_prepare_enable(nop->clk);
78 98
79 if (!IS_ERR(nop->reset)) { 99 /* De-assert RESET */
80 /* De-assert RESET */ 100 nop_reset_set(nop, 0);
81 if (regulator_enable(nop->reset))
82 dev_err(phy->dev, "Failed to de-assert reset\n");
83 }
84 101
85 return 0; 102 return 0;
86} 103}
@@ -90,14 +107,11 @@ void usb_gen_phy_shutdown(struct usb_phy *phy)
90{ 107{
91 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); 108 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
92 109
93 if (!IS_ERR(nop->reset)) { 110 /* Assert RESET */
94 /* Assert RESET */ 111 nop_reset_set(nop, 1);
95 if (regulator_disable(nop->reset))
96 dev_err(phy->dev, "Failed to assert reset\n");
97 }
98 112
99 if (!IS_ERR(nop->clk)) 113 if (!IS_ERR(nop->clk))
100 clk_disable(nop->clk); 114 clk_disable_unprepare(nop->clk);
101 115
102 if (!IS_ERR(nop->vcc)) { 116 if (!IS_ERR(nop->vcc)) {
103 if (regulator_disable(nop->vcc)) 117 if (regulator_disable(nop->vcc))
@@ -136,8 +150,7 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
136} 150}
137 151
138int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, 152int 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, 153 enum usb_phy_type type, u32 clk_rate, bool needs_vcc)
140 bool needs_reset)
141{ 154{
142 int err; 155 int err;
143 156
@@ -160,14 +173,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
160 } 173 }
161 } 174 }
162 175
163 if (!IS_ERR(nop->clk)) {
164 err = clk_prepare(nop->clk);
165 if (err) {
166 dev_err(dev, "Error preparing clock\n");
167 return err;
168 }
169 }
170
171 nop->vcc = devm_regulator_get(dev, "vcc"); 176 nop->vcc = devm_regulator_get(dev, "vcc");
172 if (IS_ERR(nop->vcc)) { 177 if (IS_ERR(nop->vcc)) {
173 dev_dbg(dev, "Error getting vcc regulator: %ld\n", 178 dev_dbg(dev, "Error getting vcc regulator: %ld\n",
@@ -176,12 +181,22 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
176 return -EPROBE_DEFER; 181 return -EPROBE_DEFER;
177 } 182 }
178 183
179 nop->reset = devm_regulator_get(dev, "reset"); 184 if (gpio_is_valid(nop->gpio_reset)) {
180 if (IS_ERR(nop->reset)) { 185 unsigned long gpio_flags;
181 dev_dbg(dev, "Error getting reset regulator: %ld\n", 186
182 PTR_ERR(nop->reset)); 187 /* Assert RESET */
183 if (needs_reset) 188 if (nop->reset_active_low)
184 return -EPROBE_DEFER; 189 gpio_flags = GPIOF_OUT_INIT_LOW;
190 else
191 gpio_flags = GPIOF_OUT_INIT_HIGH;
192
193 err = devm_gpio_request_one(dev, nop->gpio_reset,
194 gpio_flags, dev_name(dev));
195 if (err) {
196 dev_err(dev, "Error requesting RESET GPIO %d\n",
197 nop->gpio_reset);
198 return err;
199 }
185 } 200 }
186 201
187 nop->dev = dev; 202 nop->dev = dev;
@@ -200,13 +215,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
200} 215}
201EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); 216EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy);
202 217
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) 218static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
211{ 219{
212 struct device *dev = &pdev->dev; 220 struct device *dev = &pdev->dev;
@@ -217,31 +225,36 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
217 int err; 225 int err;
218 u32 clk_rate = 0; 226 u32 clk_rate = 0;
219 bool needs_vcc = false; 227 bool needs_vcc = false;
220 bool needs_reset = false; 228
229 nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL);
230 if (!nop)
231 return -ENOMEM;
232
233 nop->reset_active_low = true; /* default behaviour */
221 234
222 if (dev->of_node) { 235 if (dev->of_node) {
223 struct device_node *node = dev->of_node; 236 struct device_node *node = dev->of_node;
237 enum of_gpio_flags flags;
224 238
225 if (of_property_read_u32(node, "clock-frequency", &clk_rate)) 239 if (of_property_read_u32(node, "clock-frequency", &clk_rate))
226 clk_rate = 0; 240 clk_rate = 0;
227 241
228 needs_vcc = of_property_read_bool(node, "vcc-supply"); 242 needs_vcc = of_property_read_bool(node, "vcc-supply");
229 needs_reset = of_property_read_bool(node, "reset-supply"); 243 nop->gpio_reset = of_get_named_gpio_flags(node, "reset-gpios",
244 0, &flags);
245 if (nop->gpio_reset == -EPROBE_DEFER)
246 return -EPROBE_DEFER;
247
248 nop->reset_active_low = flags & OF_GPIO_ACTIVE_LOW;
230 249
231 } else if (pdata) { 250 } else if (pdata) {
232 type = pdata->type; 251 type = pdata->type;
233 clk_rate = pdata->clk_rate; 252 clk_rate = pdata->clk_rate;
234 needs_vcc = pdata->needs_vcc; 253 needs_vcc = pdata->needs_vcc;
235 needs_reset = pdata->needs_reset; 254 nop->gpio_reset = pdata->gpio_reset;
236 } 255 }
237 256
238 nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); 257 err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc);
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) 258 if (err)
246 return err; 259 return err;
247 260
@@ -252,15 +265,13 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
252 if (err) { 265 if (err) {
253 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 266 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
254 err); 267 err);
255 goto err_add; 268 return err;
256 } 269 }
257 270
258 platform_set_drvdata(pdev, nop); 271 platform_set_drvdata(pdev, nop);
259 272
260 return 0; 273 return 0;
261 274
262err_add:
263 usb_phy_gen_cleanup_phy(nop);
264 return err; 275 return err;
265} 276}
266 277
@@ -268,7 +279,6 @@ static int usb_phy_gen_xceiv_remove(struct platform_device *pdev)
268{ 279{
269 struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev); 280 struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev);
270 281
271 usb_phy_gen_cleanup_phy(nop);
272 usb_remove_phy(&nop->phy); 282 usb_remove_phy(&nop->phy);
273 283
274 return 0; 284 return 0;
diff --git a/drivers/usb/phy/phy-generic.h b/drivers/usb/phy/phy-generic.h
index 61687d5a965b..d2a220d81734 100644
--- a/drivers/usb/phy/phy-generic.h
+++ b/drivers/usb/phy/phy-generic.h
@@ -6,15 +6,14 @@ struct usb_phy_gen_xceiv {
6 struct device *dev; 6 struct device *dev;
7 struct clk *clk; 7 struct clk *clk;
8 struct regulator *vcc; 8 struct regulator *vcc;
9 struct regulator *reset; 9 int gpio_reset;
10 bool reset_active_low;
10}; 11};
11 12
12int usb_gen_phy_init(struct usb_phy *phy); 13int usb_gen_phy_init(struct usb_phy *phy);
13void usb_gen_phy_shutdown(struct usb_phy *phy); 14void usb_gen_phy_shutdown(struct usb_phy *phy);
14 15
15int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, 16int 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 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 18
20#endif 19#endif
diff --git a/drivers/usb/phy/phy-gpio-vbus-usb.c b/drivers/usb/phy/phy-gpio-vbus-usb.c
index b2f29c9aebbf..02799a5efcd4 100644
--- a/drivers/usb/phy/phy-gpio-vbus-usb.c
+++ b/drivers/usb/phy/phy-gpio-vbus-usb.c
@@ -241,7 +241,7 @@ static int gpio_vbus_set_suspend(struct usb_phy *phy, int suspend)
241 241
242/* platform driver interface */ 242/* platform driver interface */
243 243
244static int __init gpio_vbus_probe(struct platform_device *pdev) 244static int gpio_vbus_probe(struct platform_device *pdev)
245{ 245{
246 struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev); 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;
@@ -349,7 +349,7 @@ err_gpio:
349 return err; 349 return err;
350} 350}
351 351
352static int __exit gpio_vbus_remove(struct platform_device *pdev) 352static int 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 = dev_get_platdata(&pdev->dev); 355 struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev);
@@ -398,8 +398,6 @@ static const struct dev_pm_ops gpio_vbus_dev_pm_ops = {
398}; 398};
399#endif 399#endif
400 400
401/* NOTE: the gpio-vbus device may *NOT* be hotplugged */
402
403MODULE_ALIAS("platform:gpio-vbus"); 401MODULE_ALIAS("platform:gpio-vbus");
404 402
405static struct platform_driver gpio_vbus_driver = { 403static struct platform_driver gpio_vbus_driver = {
@@ -410,10 +408,11 @@ static struct platform_driver gpio_vbus_driver = {
410 .pm = &gpio_vbus_dev_pm_ops, 408 .pm = &gpio_vbus_dev_pm_ops,
411#endif 409#endif
412 }, 410 },
413 .remove = __exit_p(gpio_vbus_remove), 411 .probe = gpio_vbus_probe,
412 .remove = gpio_vbus_remove,
414}; 413};
415 414
416module_platform_driver_probe(gpio_vbus_driver, gpio_vbus_probe); 415module_platform_driver(gpio_vbus_driver);
417 416
418MODULE_DESCRIPTION("simple GPIO controlled OTG transceiver driver"); 417MODULE_DESCRIPTION("simple GPIO controlled OTG transceiver driver");
419MODULE_AUTHOR("Philipp Zabel"); 418MODULE_AUTHOR("Philipp Zabel");
diff --git a/drivers/usb/phy/phy-omap-control.c b/drivers/usb/phy/phy-omap-control.c
index a4dda8e12562..09c5ace1edd8 100644
--- a/drivers/usb/phy/phy-omap-control.c
+++ b/drivers/usb/phy/phy-omap-control.c
@@ -20,87 +20,77 @@
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/of.h> 22#include <linux/of.h>
23#include <linux/of_device.h>
23#include <linux/err.h> 24#include <linux/err.h>
24#include <linux/io.h> 25#include <linux/io.h>
25#include <linux/clk.h> 26#include <linux/clk.h>
26#include <linux/usb/omap_control_usb.h> 27#include <linux/usb/omap_control_usb.h>
27 28
28static struct omap_control_usb *control_usb;
29
30/**
31 * omap_get_control_dev - returns the device pointer for this control device
32 *
33 * This API should be called to get the device pointer for this control
34 * module device. This device pointer should be used for called other
35 * exported API's in this driver.
36 *
37 * To be used by PHY driver and glue driver.
38 */
39struct device *omap_get_control_dev(void)
40{
41 if (!control_usb)
42 return ERR_PTR(-ENODEV);
43
44 return control_usb->dev;
45}
46EXPORT_SYMBOL_GPL(omap_get_control_dev);
47
48/** 29/**
49 * omap_control_usb3_phy_power - power on/off the serializer using control 30 * omap_control_usb_phy_power - power on/off the phy using control module reg
50 * module
51 * @dev: the control module device 31 * @dev: the control module device
52 * @on: 0 to off and 1 to on based on powering on or off the PHY 32 * @on: 0 or 1, based on powering on or off the PHY
53 *
54 * usb3 PHY driver should call this API to power on or off the PHY.
55 */ 33 */
56void omap_control_usb3_phy_power(struct device *dev, bool on) 34void omap_control_usb_phy_power(struct device *dev, int on)
57{ 35{
58 u32 val; 36 u32 val;
59 unsigned long rate; 37 unsigned long rate;
60 struct omap_control_usb *control_usb = dev_get_drvdata(dev); 38 struct omap_control_usb *control_usb;
61 39
62 if (control_usb->type != OMAP_CTRL_DEV_TYPE2) 40 if (IS_ERR(dev) || !dev) {
41 pr_err("%s: invalid device\n", __func__);
63 return; 42 return;
43 }
64 44
65 rate = clk_get_rate(control_usb->sys_clk); 45 control_usb = dev_get_drvdata(dev);
66 rate = rate/1000000; 46 if (!control_usb) {
67 47 dev_err(dev, "%s: invalid control usb device\n", __func__);
68 val = readl(control_usb->phy_power); 48 return;
69
70 if (on) {
71 val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK |
72 OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK);
73 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON <<
74 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
75 val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT;
76 } else {
77 val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK;
78 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF <<
79 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
80 } 49 }
81 50
82 writel(val, control_usb->phy_power); 51 if (control_usb->type == OMAP_CTRL_TYPE_OTGHS)
83} 52 return;
84EXPORT_SYMBOL_GPL(omap_control_usb3_phy_power);
85 53
86/** 54 val = readl(control_usb->power);
87 * omap_control_usb_phy_power - power on/off the phy using control module reg
88 * @dev: the control module device
89 * @on: 0 or 1, based on powering on or off the PHY
90 */
91void omap_control_usb_phy_power(struct device *dev, int on)
92{
93 u32 val;
94 struct omap_control_usb *control_usb = dev_get_drvdata(dev);
95 55
96 val = readl(control_usb->dev_conf); 56 switch (control_usb->type) {
57 case OMAP_CTRL_TYPE_USB2:
58 if (on)
59 val &= ~OMAP_CTRL_DEV_PHY_PD;
60 else
61 val |= OMAP_CTRL_DEV_PHY_PD;
62 break;
97 63
98 if (on) 64 case OMAP_CTRL_TYPE_PIPE3:
99 val &= ~OMAP_CTRL_DEV_PHY_PD; 65 rate = clk_get_rate(control_usb->sys_clk);
100 else 66 rate = rate/1000000;
101 val |= OMAP_CTRL_DEV_PHY_PD; 67
68 if (on) {
69 val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK |
70 OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK);
71 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON <<
72 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
73 val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT;
74 } else {
75 val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK;
76 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF <<
77 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
78 }
79 break;
102 80
103 writel(val, control_usb->dev_conf); 81 case OMAP_CTRL_TYPE_DRA7USB2:
82 if (on)
83 val &= ~OMAP_CTRL_USB2_PHY_PD;
84 else
85 val |= OMAP_CTRL_USB2_PHY_PD;
86 break;
87 default:
88 dev_err(dev, "%s: type %d not recognized\n",
89 __func__, control_usb->type);
90 break;
91 }
92
93 writel(val, control_usb->power);
104} 94}
105EXPORT_SYMBOL_GPL(omap_control_usb_phy_power); 95EXPORT_SYMBOL_GPL(omap_control_usb_phy_power);
106 96
@@ -172,11 +162,19 @@ void omap_control_usb_set_mode(struct device *dev,
172{ 162{
173 struct omap_control_usb *ctrl_usb; 163 struct omap_control_usb *ctrl_usb;
174 164
175 if (IS_ERR(dev) || control_usb->type != OMAP_CTRL_DEV_TYPE1) 165 if (IS_ERR(dev) || !dev)
176 return; 166 return;
177 167
178 ctrl_usb = dev_get_drvdata(dev); 168 ctrl_usb = dev_get_drvdata(dev);
179 169
170 if (!ctrl_usb) {
171 dev_err(dev, "Invalid control usb device\n");
172 return;
173 }
174
175 if (ctrl_usb->type != OMAP_CTRL_TYPE_OTGHS)
176 return;
177
180 switch (mode) { 178 switch (mode) {
181 case USB_MODE_HOST: 179 case USB_MODE_HOST:
182 omap_control_usb_host_mode(ctrl_usb); 180 omap_control_usb_host_mode(ctrl_usb);
@@ -193,12 +191,46 @@ void omap_control_usb_set_mode(struct device *dev,
193} 191}
194EXPORT_SYMBOL_GPL(omap_control_usb_set_mode); 192EXPORT_SYMBOL_GPL(omap_control_usb_set_mode);
195 193
194#ifdef CONFIG_OF
195
196static const enum omap_control_usb_type otghs_data = OMAP_CTRL_TYPE_OTGHS;
197static const enum omap_control_usb_type usb2_data = OMAP_CTRL_TYPE_USB2;
198static const enum omap_control_usb_type pipe3_data = OMAP_CTRL_TYPE_PIPE3;
199static const enum omap_control_usb_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2;
200
201static const struct of_device_id omap_control_usb_id_table[] = {
202 {
203 .compatible = "ti,control-phy-otghs",
204 .data = &otghs_data,
205 },
206 {
207 .compatible = "ti,control-phy-usb2",
208 .data = &usb2_data,
209 },
210 {
211 .compatible = "ti,control-phy-pipe3",
212 .data = &pipe3_data,
213 },
214 {
215 .compatible = "ti,control-phy-dra7usb2",
216 .data = &dra7usb2_data,
217 },
218 {},
219};
220MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
221#endif
222
223
196static int omap_control_usb_probe(struct platform_device *pdev) 224static int omap_control_usb_probe(struct platform_device *pdev)
197{ 225{
198 struct resource *res; 226 struct resource *res;
199 struct device_node *np = pdev->dev.of_node; 227 const struct of_device_id *of_id;
200 struct omap_control_usb_platform_data *pdata = 228 struct omap_control_usb *control_usb;
201 dev_get_platdata(&pdev->dev); 229
230 of_id = of_match_device(of_match_ptr(omap_control_usb_id_table),
231 &pdev->dev);
232 if (!of_id)
233 return -EINVAL;
202 234
203 control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb), 235 control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),
204 GFP_KERNEL); 236 GFP_KERNEL);
@@ -207,40 +239,27 @@ static int omap_control_usb_probe(struct platform_device *pdev)
207 return -ENOMEM; 239 return -ENOMEM;
208 } 240 }
209 241
210 if (np) { 242 control_usb->dev = &pdev->dev;
211 of_property_read_u32(np, "ti,type", &control_usb->type); 243 control_usb->type = *(enum omap_control_usb_type *)of_id->data;
212 } else if (pdata) {
213 control_usb->type = pdata->type;
214 } else {
215 dev_err(&pdev->dev, "no pdata present\n");
216 return -EINVAL;
217 }
218
219 control_usb->dev = &pdev->dev;
220
221 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
222 "control_dev_conf");
223 control_usb->dev_conf = devm_ioremap_resource(&pdev->dev, res);
224 if (IS_ERR(control_usb->dev_conf))
225 return PTR_ERR(control_usb->dev_conf);
226 244
227 if (control_usb->type == OMAP_CTRL_DEV_TYPE1) { 245 if (control_usb->type == OMAP_CTRL_TYPE_OTGHS) {
228 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 246 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
229 "otghs_control"); 247 "otghs_control");
230 control_usb->otghs_control = devm_ioremap_resource( 248 control_usb->otghs_control = devm_ioremap_resource(
231 &pdev->dev, res); 249 &pdev->dev, res);
232 if (IS_ERR(control_usb->otghs_control)) 250 if (IS_ERR(control_usb->otghs_control))
233 return PTR_ERR(control_usb->otghs_control); 251 return PTR_ERR(control_usb->otghs_control);
234 } 252 } else {
235
236 if (control_usb->type == OMAP_CTRL_DEV_TYPE2) {
237 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 253 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
238 "phy_power_usb"); 254 "power");
239 control_usb->phy_power = devm_ioremap_resource( 255 control_usb->power = devm_ioremap_resource(&pdev->dev, res);
240 &pdev->dev, res); 256 if (IS_ERR(control_usb->power)) {
241 if (IS_ERR(control_usb->phy_power)) 257 dev_err(&pdev->dev, "Couldn't get power register\n");
242 return PTR_ERR(control_usb->phy_power); 258 return PTR_ERR(control_usb->power);
259 }
260 }
243 261
262 if (control_usb->type == OMAP_CTRL_TYPE_PIPE3) {
244 control_usb->sys_clk = devm_clk_get(control_usb->dev, 263 control_usb->sys_clk = devm_clk_get(control_usb->dev,
245 "sys_clkin"); 264 "sys_clkin");
246 if (IS_ERR(control_usb->sys_clk)) { 265 if (IS_ERR(control_usb->sys_clk)) {
@@ -249,20 +268,11 @@ static int omap_control_usb_probe(struct platform_device *pdev)
249 } 268 }
250 } 269 }
251 270
252
253 dev_set_drvdata(control_usb->dev, control_usb); 271 dev_set_drvdata(control_usb->dev, control_usb);
254 272
255 return 0; 273 return 0;
256} 274}
257 275
258#ifdef CONFIG_OF
259static const struct of_device_id omap_control_usb_id_table[] = {
260 { .compatible = "ti,omap-control-usb" },
261 {}
262};
263MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
264#endif
265
266static struct platform_driver omap_control_usb_driver = { 276static struct platform_driver omap_control_usb_driver = {
267 .probe = omap_control_usb_probe, 277 .probe = omap_control_usb_probe,
268 .driver = { 278 .driver = {
diff --git a/drivers/usb/phy/phy-omap-usb2.c b/drivers/usb/phy/phy-omap-usb2.c
deleted file mode 100644
index d266861d24f7..000000000000
--- a/drivers/usb/phy/phy-omap-usb2.c
+++ /dev/null
@@ -1,272 +0,0 @@
1/*
2 * omap-usb2.c - USB PHY, talking to musb controller in OMAP.
3 *
4 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * Author: Kishon Vijay Abraham I <kishon@ti.com>
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/slab.h>
22#include <linux/of.h>
23#include <linux/io.h>
24#include <linux/usb/omap_usb.h>
25#include <linux/usb/phy_companion.h>
26#include <linux/clk.h>
27#include <linux/err.h>
28#include <linux/pm_runtime.h>
29#include <linux/delay.h>
30#include <linux/usb/omap_control_usb.h>
31
32/**
33 * omap_usb2_set_comparator - links the comparator present in the sytem with
34 * this phy
35 * @comparator - the companion phy(comparator) for this phy
36 *
37 * The phy companion driver should call this API passing the phy_companion
38 * filled with set_vbus and start_srp to be used by usb phy.
39 *
40 * For use by phy companion driver
41 */
42int omap_usb2_set_comparator(struct phy_companion *comparator)
43{
44 struct omap_usb *phy;
45 struct usb_phy *x = usb_get_phy(USB_PHY_TYPE_USB2);
46
47 if (IS_ERR(x))
48 return -ENODEV;
49
50 phy = phy_to_omapusb(x);
51 phy->comparator = comparator;
52 return 0;
53}
54EXPORT_SYMBOL_GPL(omap_usb2_set_comparator);
55
56static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled)
57{
58 struct omap_usb *phy = phy_to_omapusb(otg->phy);
59
60 if (!phy->comparator)
61 return -ENODEV;
62
63 return phy->comparator->set_vbus(phy->comparator, enabled);
64}
65
66static int omap_usb_start_srp(struct usb_otg *otg)
67{
68 struct omap_usb *phy = phy_to_omapusb(otg->phy);
69
70 if (!phy->comparator)
71 return -ENODEV;
72
73 return phy->comparator->start_srp(phy->comparator);
74}
75
76static int omap_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
77{
78 struct usb_phy *phy = otg->phy;
79
80 otg->host = host;
81 if (!host)
82 phy->state = OTG_STATE_UNDEFINED;
83
84 return 0;
85}
86
87static int omap_usb_set_peripheral(struct usb_otg *otg,
88 struct usb_gadget *gadget)
89{
90 struct usb_phy *phy = otg->phy;
91
92 otg->gadget = gadget;
93 if (!gadget)
94 phy->state = OTG_STATE_UNDEFINED;
95
96 return 0;
97}
98
99static int omap_usb2_suspend(struct usb_phy *x, int suspend)
100{
101 struct omap_usb *phy = phy_to_omapusb(x);
102 int ret;
103
104 if (suspend && !phy->is_suspended) {
105 omap_control_usb_phy_power(phy->control_dev, 0);
106 pm_runtime_put_sync(phy->dev);
107 phy->is_suspended = 1;
108 } else if (!suspend && phy->is_suspended) {
109 ret = pm_runtime_get_sync(phy->dev);
110 if (ret < 0) {
111 dev_err(phy->dev, "get_sync failed with err %d\n", ret);
112 return ret;
113 }
114 omap_control_usb_phy_power(phy->control_dev, 1);
115 phy->is_suspended = 0;
116 }
117
118 return 0;
119}
120
121static int omap_usb2_probe(struct platform_device *pdev)
122{
123 struct omap_usb *phy;
124 struct usb_otg *otg;
125
126 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
127 if (!phy) {
128 dev_err(&pdev->dev, "unable to allocate memory for USB2 PHY\n");
129 return -ENOMEM;
130 }
131
132 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
133 if (!otg) {
134 dev_err(&pdev->dev, "unable to allocate memory for USB OTG\n");
135 return -ENOMEM;
136 }
137
138 phy->dev = &pdev->dev;
139
140 phy->phy.dev = phy->dev;
141 phy->phy.label = "omap-usb2";
142 phy->phy.set_suspend = omap_usb2_suspend;
143 phy->phy.otg = otg;
144 phy->phy.type = USB_PHY_TYPE_USB2;
145
146 phy->control_dev = omap_get_control_dev();
147 if (IS_ERR(phy->control_dev)) {
148 dev_dbg(&pdev->dev, "Failed to get control device\n");
149 return -ENODEV;
150 }
151
152 phy->is_suspended = 1;
153 omap_control_usb_phy_power(phy->control_dev, 0);
154
155 otg->set_host = omap_usb_set_host;
156 otg->set_peripheral = omap_usb_set_peripheral;
157 otg->set_vbus = omap_usb_set_vbus;
158 otg->start_srp = omap_usb_start_srp;
159 otg->phy = &phy->phy;
160
161 phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k");
162 if (IS_ERR(phy->wkupclk)) {
163 dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n");
164 return PTR_ERR(phy->wkupclk);
165 }
166 clk_prepare(phy->wkupclk);
167
168 phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
169 if (IS_ERR(phy->optclk))
170 dev_vdbg(&pdev->dev, "unable to get refclk960m\n");
171 else
172 clk_prepare(phy->optclk);
173
174 usb_add_phy_dev(&phy->phy);
175
176 platform_set_drvdata(pdev, phy);
177
178 pm_runtime_enable(phy->dev);
179
180 return 0;
181}
182
183static int omap_usb2_remove(struct platform_device *pdev)
184{
185 struct omap_usb *phy = platform_get_drvdata(pdev);
186
187 clk_unprepare(phy->wkupclk);
188 if (!IS_ERR(phy->optclk))
189 clk_unprepare(phy->optclk);
190 usb_remove_phy(&phy->phy);
191
192 return 0;
193}
194
195#ifdef CONFIG_PM_RUNTIME
196
197static int omap_usb2_runtime_suspend(struct device *dev)
198{
199 struct platform_device *pdev = to_platform_device(dev);
200 struct omap_usb *phy = platform_get_drvdata(pdev);
201
202 clk_disable(phy->wkupclk);
203 if (!IS_ERR(phy->optclk))
204 clk_disable(phy->optclk);
205
206 return 0;
207}
208
209static int omap_usb2_runtime_resume(struct device *dev)
210{
211 struct platform_device *pdev = to_platform_device(dev);
212 struct omap_usb *phy = platform_get_drvdata(pdev);
213 int ret;
214
215 ret = clk_enable(phy->wkupclk);
216 if (ret < 0) {
217 dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret);
218 goto err0;
219 }
220
221 if (!IS_ERR(phy->optclk)) {
222 ret = clk_enable(phy->optclk);
223 if (ret < 0) {
224 dev_err(phy->dev, "Failed to enable optclk %d\n", ret);
225 goto err1;
226 }
227 }
228
229 return 0;
230
231err1:
232 clk_disable(phy->wkupclk);
233
234err0:
235 return ret;
236}
237
238static const struct dev_pm_ops omap_usb2_pm_ops = {
239 SET_RUNTIME_PM_OPS(omap_usb2_runtime_suspend, omap_usb2_runtime_resume,
240 NULL)
241};
242
243#define DEV_PM_OPS (&omap_usb2_pm_ops)
244#else
245#define DEV_PM_OPS NULL
246#endif
247
248#ifdef CONFIG_OF
249static const struct of_device_id omap_usb2_id_table[] = {
250 { .compatible = "ti,omap-usb2" },
251 {}
252};
253MODULE_DEVICE_TABLE(of, omap_usb2_id_table);
254#endif
255
256static struct platform_driver omap_usb2_driver = {
257 .probe = omap_usb2_probe,
258 .remove = omap_usb2_remove,
259 .driver = {
260 .name = "omap-usb2",
261 .owner = THIS_MODULE,
262 .pm = DEV_PM_OPS,
263 .of_match_table = of_match_ptr(omap_usb2_id_table),
264 },
265};
266
267module_platform_driver(omap_usb2_driver);
268
269MODULE_ALIAS("platform: omap_usb2");
270MODULE_AUTHOR("Texas Instruments Inc.");
271MODULE_DESCRIPTION("OMAP USB2 phy driver");
272MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/phy/phy-omap-usb3.c b/drivers/usb/phy/phy-omap-usb3.c
index fc15694d3031..0c6ba29bdddd 100644
--- a/drivers/usb/phy/phy-omap-usb3.c
+++ b/drivers/usb/phy/phy-omap-usb3.c
@@ -26,6 +26,7 @@
26#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
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#include <linux/of_platform.h>
29 30
30#define PLL_STATUS 0x00000004 31#define PLL_STATUS 0x00000004
31#define PLL_GO 0x00000008 32#define PLL_GO 0x00000008
@@ -79,7 +80,7 @@ static struct usb_dpll_params *omap_usb3_get_dpll_params(unsigned long rate)
79 return &dpll_map[i].params; 80 return &dpll_map[i].params;
80 } 81 }
81 82
82 return 0; 83 return NULL;
83} 84}
84 85
85static int omap_usb3_suspend(struct usb_phy *x, int suspend) 86static int omap_usb3_suspend(struct usb_phy *x, int suspend)
@@ -100,7 +101,7 @@ static int omap_usb3_suspend(struct usb_phy *x, int suspend)
100 udelay(1); 101 udelay(1);
101 } while (--timeout); 102 } while (--timeout);
102 103
103 omap_control_usb3_phy_power(phy->control_dev, 0); 104 omap_control_usb_phy_power(phy->control_dev, 0);
104 105
105 phy->is_suspended = 1; 106 phy->is_suspended = 1;
106 } else if (!suspend && phy->is_suspended) { 107 } else if (!suspend && phy->is_suspended) {
@@ -189,15 +190,21 @@ static int omap_usb3_init(struct usb_phy *x)
189 if (ret) 190 if (ret)
190 return ret; 191 return ret;
191 192
192 omap_control_usb3_phy_power(phy->control_dev, 1); 193 omap_control_usb_phy_power(phy->control_dev, 1);
193 194
194 return 0; 195 return 0;
195} 196}
196 197
197static int omap_usb3_probe(struct platform_device *pdev) 198static int omap_usb3_probe(struct platform_device *pdev)
198{ 199{
199 struct omap_usb *phy; 200 struct omap_usb *phy;
200 struct resource *res; 201 struct resource *res;
202 struct device_node *node = pdev->dev.of_node;
203 struct device_node *control_node;
204 struct platform_device *control_pdev;
205
206 if (!node)
207 return -EINVAL;
201 208
202 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); 209 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
203 if (!phy) { 210 if (!phy) {
@@ -239,13 +246,20 @@ static int omap_usb3_probe(struct platform_device *pdev)
239 return -EINVAL; 246 return -EINVAL;
240 } 247 }
241 248
242 phy->control_dev = omap_get_control_dev(); 249 control_node = of_parse_phandle(node, "ctrl-module", 0);
243 if (IS_ERR(phy->control_dev)) { 250 if (!control_node) {
244 dev_dbg(&pdev->dev, "Failed to get control device\n"); 251 dev_err(&pdev->dev, "Failed to get control device phandle\n");
245 return -ENODEV; 252 return -EINVAL;
246 } 253 }
254 control_pdev = of_find_device_by_node(control_node);
255 if (!control_pdev) {
256 dev_err(&pdev->dev, "Failed to get control device\n");
257 return -EINVAL;
258 }
259
260 phy->control_dev = &control_pdev->dev;
247 261
248 omap_control_usb3_phy_power(phy->control_dev, 0); 262 omap_control_usb_phy_power(phy->control_dev, 0);
249 usb_add_phy_dev(&phy->phy); 263 usb_add_phy_dev(&phy->phy);
250 264
251 platform_set_drvdata(pdev, phy); 265 platform_set_drvdata(pdev, phy);
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c b/drivers/usb/phy/phy-rcar-gen2-usb.c
new file mode 100644
index 000000000000..a99a6953f11c
--- /dev/null
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -0,0 +1,248 @@
1/*
2 * Renesas R-Car Gen2 USB phy driver
3 *
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Cogent Embedded, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/clk.h>
13#include <linux/delay.h>
14#include <linux/io.h>
15#include <linux/module.h>
16#include <linux/platform_data/usb-rcar-gen2-phy.h>
17#include <linux/platform_device.h>
18#include <linux/spinlock.h>
19#include <linux/usb/otg.h>
20
21struct rcar_gen2_usb_phy_priv {
22 struct usb_phy phy;
23 void __iomem *base;
24 struct clk *clk;
25 spinlock_t lock;
26 int usecount;
27 u32 ugctrl2;
28};
29
30#define usb_phy_to_priv(p) container_of(p, struct rcar_gen2_usb_phy_priv, phy)
31
32/* Low Power Status register */
33#define USBHS_LPSTS_REG 0x02
34#define USBHS_LPSTS_SUSPM (1 << 14)
35
36/* USB General control register */
37#define USBHS_UGCTRL_REG 0x80
38#define USBHS_UGCTRL_CONNECT (1 << 2)
39#define USBHS_UGCTRL_PLLRESET (1 << 0)
40
41/* USB General control register 2 */
42#define USBHS_UGCTRL2_REG 0x84
43#define USBHS_UGCTRL2_USB0_PCI (1 << 4)
44#define USBHS_UGCTRL2_USB0_HS (3 << 4)
45#define USBHS_UGCTRL2_USB2_PCI (0 << 31)
46#define USBHS_UGCTRL2_USB2_SS (1 << 31)
47
48/* USB General status register */
49#define USBHS_UGSTS_REG 0x88
50#define USBHS_UGSTS_LOCK (3 << 8)
51
52/* Enable USBHS internal phy */
53static int __rcar_gen2_usbhs_phy_enable(void __iomem *base)
54{
55 u32 val;
56 int i;
57
58 /* USBHS PHY power on */
59 val = ioread32(base + USBHS_UGCTRL_REG);
60 val &= ~USBHS_UGCTRL_PLLRESET;
61 iowrite32(val, base + USBHS_UGCTRL_REG);
62
63 val = ioread16(base + USBHS_LPSTS_REG);
64 val |= USBHS_LPSTS_SUSPM;
65 iowrite16(val, base + USBHS_LPSTS_REG);
66
67 for (i = 0; i < 20; i++) {
68 val = ioread32(base + USBHS_UGSTS_REG);
69 if ((val & USBHS_UGSTS_LOCK) == USBHS_UGSTS_LOCK) {
70 val = ioread32(base + USBHS_UGCTRL_REG);
71 val |= USBHS_UGCTRL_CONNECT;
72 iowrite32(val, base + USBHS_UGCTRL_REG);
73 return 0;
74 }
75 udelay(1);
76 }
77
78 /* Timed out waiting for the PLL lock */
79 return -ETIMEDOUT;
80}
81
82/* Disable USBHS internal phy */
83static int __rcar_gen2_usbhs_phy_disable(void __iomem *base)
84{
85 u32 val;
86
87 /* USBHS PHY power off */
88 val = ioread32(base + USBHS_UGCTRL_REG);
89 val &= ~USBHS_UGCTRL_CONNECT;
90 iowrite32(val, base + USBHS_UGCTRL_REG);
91
92 val = ioread16(base + USBHS_LPSTS_REG);
93 val &= ~USBHS_LPSTS_SUSPM;
94 iowrite16(val, base + USBHS_LPSTS_REG);
95
96 val = ioread32(base + USBHS_UGCTRL_REG);
97 val |= USBHS_UGCTRL_PLLRESET;
98 iowrite32(val, base + USBHS_UGCTRL_REG);
99 return 0;
100}
101
102/* Setup USB channels */
103static void __rcar_gen2_usb_phy_init(struct rcar_gen2_usb_phy_priv *priv)
104{
105 u32 val;
106
107 clk_prepare_enable(priv->clk);
108
109 /* Set USB channels in the USBHS UGCTRL2 register */
110 val = ioread32(priv->base);
111 val &= ~(USBHS_UGCTRL2_USB0_HS | USBHS_UGCTRL2_USB2_SS);
112 val |= priv->ugctrl2;
113 iowrite32(val, priv->base);
114}
115
116/* Shutdown USB channels */
117static void __rcar_gen2_usb_phy_shutdown(struct rcar_gen2_usb_phy_priv *priv)
118{
119 __rcar_gen2_usbhs_phy_disable(priv->base);
120 clk_disable_unprepare(priv->clk);
121}
122
123static int rcar_gen2_usb_phy_set_suspend(struct usb_phy *phy, int suspend)
124{
125 struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy);
126 unsigned long flags;
127 int retval;
128
129 spin_lock_irqsave(&priv->lock, flags);
130 retval = suspend ? __rcar_gen2_usbhs_phy_disable(priv->base) :
131 __rcar_gen2_usbhs_phy_enable(priv->base);
132 spin_unlock_irqrestore(&priv->lock, flags);
133 return retval;
134}
135
136static int rcar_gen2_usb_phy_init(struct usb_phy *phy)
137{
138 struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy);
139 unsigned long flags;
140
141 spin_lock_irqsave(&priv->lock, flags);
142 /*
143 * Enable the clock and setup USB channels
144 * if it's the first user
145 */
146 if (!priv->usecount++)
147 __rcar_gen2_usb_phy_init(priv);
148 spin_unlock_irqrestore(&priv->lock, flags);
149 return 0;
150}
151
152static void rcar_gen2_usb_phy_shutdown(struct usb_phy *phy)
153{
154 struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy);
155 unsigned long flags;
156
157 spin_lock_irqsave(&priv->lock, flags);
158 if (!priv->usecount) {
159 dev_warn(phy->dev, "Trying to disable phy with 0 usecount\n");
160 goto out;
161 }
162
163 /* Disable everything if it's the last user */
164 if (!--priv->usecount)
165 __rcar_gen2_usb_phy_shutdown(priv);
166out:
167 spin_unlock_irqrestore(&priv->lock, flags);
168}
169
170static int rcar_gen2_usb_phy_probe(struct platform_device *pdev)
171{
172 struct device *dev = &pdev->dev;
173 struct rcar_gen2_phy_platform_data *pdata;
174 struct rcar_gen2_usb_phy_priv *priv;
175 struct resource *res;
176 void __iomem *base;
177 struct clk *clk;
178 int retval;
179
180 pdata = dev_get_platdata(&pdev->dev);
181 if (!pdata) {
182 dev_err(dev, "No platform data\n");
183 return -EINVAL;
184 }
185
186 clk = devm_clk_get(&pdev->dev, "usbhs");
187 if (IS_ERR(clk)) {
188 dev_err(&pdev->dev, "Can't get the clock\n");
189 return PTR_ERR(clk);
190 }
191
192 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
193 base = devm_ioremap_resource(dev, res);
194 if (IS_ERR(base))
195 return PTR_ERR(base);
196
197 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
198 if (!priv) {
199 dev_err(dev, "Memory allocation failed\n");
200 return -ENOMEM;
201 }
202
203 spin_lock_init(&priv->lock);
204 priv->clk = clk;
205 priv->base = base;
206 priv->ugctrl2 = pdata->chan0_pci ?
207 USBHS_UGCTRL2_USB0_PCI : USBHS_UGCTRL2_USB0_HS;
208 priv->ugctrl2 |= pdata->chan2_pci ?
209 USBHS_UGCTRL2_USB2_PCI : USBHS_UGCTRL2_USB2_SS;
210 priv->phy.dev = dev;
211 priv->phy.label = dev_name(dev);
212 priv->phy.init = rcar_gen2_usb_phy_init;
213 priv->phy.shutdown = rcar_gen2_usb_phy_shutdown;
214 priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend;
215
216 retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2);
217 if (retval < 0) {
218 dev_err(dev, "Failed to add USB phy\n");
219 return retval;
220 }
221
222 platform_set_drvdata(pdev, priv);
223
224 return retval;
225}
226
227static int rcar_gen2_usb_phy_remove(struct platform_device *pdev)
228{
229 struct rcar_gen2_usb_phy_priv *priv = platform_get_drvdata(pdev);
230
231 usb_remove_phy(&priv->phy);
232
233 return 0;
234}
235
236static struct platform_driver rcar_gen2_usb_phy_driver = {
237 .driver = {
238 .name = "usb_phy_rcar_gen2",
239 },
240 .probe = rcar_gen2_usb_phy_probe,
241 .remove = rcar_gen2_usb_phy_remove,
242};
243
244module_platform_driver(rcar_gen2_usb_phy_driver);
245
246MODULE_LICENSE("GPL v2");
247MODULE_DESCRIPTION("Renesas R-Car Gen2 USB phy");
248MODULE_AUTHOR("Valentine Barshak <valentine.barshak@cogentembedded.com>");
diff --git a/drivers/usb/phy/phy-samsung-usb2.c b/drivers/usb/phy/phy-samsung-usb2.c
index ff70e4b19b97..b3ba86627b72 100644
--- a/drivers/usb/phy/phy-samsung-usb2.c
+++ b/drivers/usb/phy/phy-samsung-usb2.c
@@ -411,6 +411,7 @@ static int samsung_usb2phy_probe(struct platform_device *pdev)
411 sphy->drv_data = drv_data; 411 sphy->drv_data = drv_data;
412 sphy->phy.dev = sphy->dev; 412 sphy->phy.dev = sphy->dev;
413 sphy->phy.label = "samsung-usb2phy"; 413 sphy->phy.label = "samsung-usb2phy";
414 sphy->phy.type = USB_PHY_TYPE_USB2;
414 sphy->phy.init = samsung_usb2phy_init; 415 sphy->phy.init = samsung_usb2phy_init;
415 sphy->phy.shutdown = samsung_usb2phy_shutdown; 416 sphy->phy.shutdown = samsung_usb2phy_shutdown;
416 417
@@ -426,7 +427,7 @@ static int samsung_usb2phy_probe(struct platform_device *pdev)
426 427
427 platform_set_drvdata(pdev, sphy); 428 platform_set_drvdata(pdev, sphy);
428 429
429 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2); 430 return usb_add_phy_dev(&sphy->phy);
430} 431}
431 432
432static int samsung_usb2phy_remove(struct platform_device *pdev) 433static int samsung_usb2phy_remove(struct platform_device *pdev)
diff --git a/drivers/usb/phy/phy-samsung-usb3.c b/drivers/usb/phy/phy-samsung-usb3.c
index c6eb22213de6..cc0819248acf 100644
--- a/drivers/usb/phy/phy-samsung-usb3.c
+++ b/drivers/usb/phy/phy-samsung-usb3.c
@@ -271,6 +271,7 @@ static int samsung_usb3phy_probe(struct platform_device *pdev)
271 sphy->clk = clk; 271 sphy->clk = clk;
272 sphy->phy.dev = sphy->dev; 272 sphy->phy.dev = sphy->dev;
273 sphy->phy.label = "samsung-usb3phy"; 273 sphy->phy.label = "samsung-usb3phy";
274 sphy->phy.type = USB_PHY_TYPE_USB3;
274 sphy->phy.init = samsung_usb3phy_init; 275 sphy->phy.init = samsung_usb3phy_init;
275 sphy->phy.shutdown = samsung_usb3phy_shutdown; 276 sphy->phy.shutdown = samsung_usb3phy_shutdown;
276 sphy->drv_data = samsung_usbphy_get_driver_data(pdev); 277 sphy->drv_data = samsung_usbphy_get_driver_data(pdev);
@@ -283,7 +284,7 @@ static int samsung_usb3phy_probe(struct platform_device *pdev)
283 284
284 platform_set_drvdata(pdev, sphy); 285 platform_set_drvdata(pdev, sphy);
285 286
286 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB3); 287 return usb_add_phy_dev(&sphy->phy);
287} 288}
288 289
289static int samsung_usb3phy_remove(struct platform_device *pdev) 290static int samsung_usb3phy_remove(struct platform_device *pdev)
diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
index e9cb1cb8abc7..82232acf1ab6 100644
--- a/drivers/usb/phy/phy-tegra-usb.c
+++ b/drivers/usb/phy/phy-tegra-usb.c
@@ -1090,7 +1090,7 @@ static struct platform_driver tegra_usb_phy_driver = {
1090 .driver = { 1090 .driver = {
1091 .name = "tegra-phy", 1091 .name = "tegra-phy",
1092 .owner = THIS_MODULE, 1092 .owner = THIS_MODULE,
1093 .of_match_table = of_match_ptr(tegra_usb_phy_id_table), 1093 .of_match_table = tegra_usb_phy_id_table,
1094 }, 1094 },
1095}; 1095};
1096module_platform_driver(tegra_usb_phy_driver); 1096module_platform_driver(tegra_usb_phy_driver);
diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
deleted file mode 100644
index 90730c8762b8..000000000000
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ /dev/null
@@ -1,794 +0,0 @@
1/*
2 * twl4030_usb - TWL4030 USB transceiver, talking to OMAP OTG controller
3 *
4 * Copyright (C) 2004-2007 Texas Instruments
5 * Copyright (C) 2008 Nokia Corporation
6 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * Current status:
23 * - HS USB ULPI mode works.
24 * - 3-pin mode support may be added in future.
25 */
26
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/interrupt.h>
30#include <linux/platform_device.h>
31#include <linux/spinlock.h>
32#include <linux/workqueue.h>
33#include <linux/io.h>
34#include <linux/delay.h>
35#include <linux/usb/otg.h>
36#include <linux/usb/musb-omap.h>
37#include <linux/usb/ulpi.h>
38#include <linux/i2c/twl.h>
39#include <linux/regulator/consumer.h>
40#include <linux/err.h>
41#include <linux/slab.h>
42
43/* Register defines */
44
45#define MCPC_CTRL 0x30
46#define MCPC_CTRL_RTSOL (1 << 7)
47#define MCPC_CTRL_EXTSWR (1 << 6)
48#define MCPC_CTRL_EXTSWC (1 << 5)
49#define MCPC_CTRL_VOICESW (1 << 4)
50#define MCPC_CTRL_OUT64K (1 << 3)
51#define MCPC_CTRL_RTSCTSSW (1 << 2)
52#define MCPC_CTRL_HS_UART (1 << 0)
53
54#define MCPC_IO_CTRL 0x33
55#define MCPC_IO_CTRL_MICBIASEN (1 << 5)
56#define MCPC_IO_CTRL_CTS_NPU (1 << 4)
57#define MCPC_IO_CTRL_RXD_PU (1 << 3)
58#define MCPC_IO_CTRL_TXDTYP (1 << 2)
59#define MCPC_IO_CTRL_CTSTYP (1 << 1)
60#define MCPC_IO_CTRL_RTSTYP (1 << 0)
61
62#define MCPC_CTRL2 0x36
63#define MCPC_CTRL2_MCPC_CK_EN (1 << 0)
64
65#define OTHER_FUNC_CTRL 0x80
66#define OTHER_FUNC_CTRL_BDIS_ACON_EN (1 << 4)
67#define OTHER_FUNC_CTRL_FIVEWIRE_MODE (1 << 2)
68
69#define OTHER_IFC_CTRL 0x83
70#define OTHER_IFC_CTRL_OE_INT_EN (1 << 6)
71#define OTHER_IFC_CTRL_CEA2011_MODE (1 << 5)
72#define OTHER_IFC_CTRL_FSLSSERIALMODE_4PIN (1 << 4)
73#define OTHER_IFC_CTRL_HIZ_ULPI_60MHZ_OUT (1 << 3)
74#define OTHER_IFC_CTRL_HIZ_ULPI (1 << 2)
75#define OTHER_IFC_CTRL_ALT_INT_REROUTE (1 << 0)
76
77#define OTHER_INT_EN_RISE 0x86
78#define OTHER_INT_EN_FALL 0x89
79#define OTHER_INT_STS 0x8C
80#define OTHER_INT_LATCH 0x8D
81#define OTHER_INT_VB_SESS_VLD (1 << 7)
82#define OTHER_INT_DM_HI (1 << 6) /* not valid for "latch" reg */
83#define OTHER_INT_DP_HI (1 << 5) /* not valid for "latch" reg */
84#define OTHER_INT_BDIS_ACON (1 << 3) /* not valid for "fall" regs */
85#define OTHER_INT_MANU (1 << 1)
86#define OTHER_INT_ABNORMAL_STRESS (1 << 0)
87
88#define ID_STATUS 0x96
89#define ID_RES_FLOAT (1 << 4)
90#define ID_RES_440K (1 << 3)
91#define ID_RES_200K (1 << 2)
92#define ID_RES_102K (1 << 1)
93#define ID_RES_GND (1 << 0)
94
95#define POWER_CTRL 0xAC
96#define POWER_CTRL_OTG_ENAB (1 << 5)
97
98#define OTHER_IFC_CTRL2 0xAF
99#define OTHER_IFC_CTRL2_ULPI_STP_LOW (1 << 4)
100#define OTHER_IFC_CTRL2_ULPI_TXEN_POL (1 << 3)
101#define OTHER_IFC_CTRL2_ULPI_4PIN_2430 (1 << 2)
102#define OTHER_IFC_CTRL2_USB_INT_OUTSEL_MASK (3 << 0) /* bits 0 and 1 */
103#define OTHER_IFC_CTRL2_USB_INT_OUTSEL_INT1N (0 << 0)
104#define OTHER_IFC_CTRL2_USB_INT_OUTSEL_INT2N (1 << 0)
105
106#define REG_CTRL_EN 0xB2
107#define REG_CTRL_ERROR 0xB5
108#define ULPI_I2C_CONFLICT_INTEN (1 << 0)
109
110#define OTHER_FUNC_CTRL2 0xB8
111#define OTHER_FUNC_CTRL2_VBAT_TIMER_EN (1 << 0)
112
113/* following registers do not have separate _clr and _set registers */
114#define VBUS_DEBOUNCE 0xC0
115#define ID_DEBOUNCE 0xC1
116#define VBAT_TIMER 0xD3
117#define PHY_PWR_CTRL 0xFD
118#define PHY_PWR_PHYPWD (1 << 0)
119#define PHY_CLK_CTRL 0xFE
120#define PHY_CLK_CTRL_CLOCKGATING_EN (1 << 2)
121#define PHY_CLK_CTRL_CLK32K_EN (1 << 1)
122#define REQ_PHY_DPLL_CLK (1 << 0)
123#define PHY_CLK_CTRL_STS 0xFF
124#define PHY_DPLL_CLK (1 << 0)
125
126/* In module TWL_MODULE_PM_MASTER */
127#define STS_HW_CONDITIONS 0x0F
128
129/* In module TWL_MODULE_PM_RECEIVER */
130#define VUSB_DEDICATED1 0x7D
131#define VUSB_DEDICATED2 0x7E
132#define VUSB1V5_DEV_GRP 0x71
133#define VUSB1V5_TYPE 0x72
134#define VUSB1V5_REMAP 0x73
135#define VUSB1V8_DEV_GRP 0x74
136#define VUSB1V8_TYPE 0x75
137#define VUSB1V8_REMAP 0x76
138#define VUSB3V1_DEV_GRP 0x77
139#define VUSB3V1_TYPE 0x78
140#define VUSB3V1_REMAP 0x79
141
142/* In module TWL4030_MODULE_INTBR */
143#define PMBR1 0x0D
144#define GPIO_USB_4PIN_ULPI_2430C (3 << 0)
145
146struct twl4030_usb {
147 struct usb_phy phy;
148 struct device *dev;
149
150 /* TWL4030 internal USB regulator supplies */
151 struct regulator *usb1v5;
152 struct regulator *usb1v8;
153 struct regulator *usb3v1;
154
155 /* for vbus reporting with irqs disabled */
156 spinlock_t lock;
157
158 /* pin configuration */
159 enum twl4030_usb_mode usb_mode;
160
161 int irq;
162 enum omap_musb_vbus_id_status linkstat;
163 bool vbus_supplied;
164 u8 asleep;
165 bool irq_enabled;
166
167 struct delayed_work id_workaround_work;
168};
169
170/* internal define on top of container_of */
171#define phy_to_twl(x) container_of((x), struct twl4030_usb, phy)
172
173/*-------------------------------------------------------------------------*/
174
175static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl,
176 u8 module, u8 data, u8 address)
177{
178 u8 check;
179
180 if ((twl_i2c_write_u8(module, data, address) >= 0) &&
181 (twl_i2c_read_u8(module, &check, address) >= 0) &&
182 (check == data))
183 return 0;
184 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n",
185 1, module, address, check, data);
186
187 /* Failed once: Try again */
188 if ((twl_i2c_write_u8(module, data, address) >= 0) &&
189 (twl_i2c_read_u8(module, &check, address) >= 0) &&
190 (check == data))
191 return 0;
192 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n",
193 2, module, address, check, data);
194
195 /* Failed again: Return error */
196 return -EBUSY;
197}
198
199#define twl4030_usb_write_verify(twl, address, data) \
200 twl4030_i2c_write_u8_verify(twl, TWL_MODULE_USB, (data), (address))
201
202static inline int twl4030_usb_write(struct twl4030_usb *twl,
203 u8 address, u8 data)
204{
205 int ret = 0;
206
207 ret = twl_i2c_write_u8(TWL_MODULE_USB, data, address);
208 if (ret < 0)
209 dev_dbg(twl->dev,
210 "TWL4030:USB:Write[0x%x] Error %d\n", address, ret);
211 return ret;
212}
213
214static inline int twl4030_readb(struct twl4030_usb *twl, u8 module, u8 address)
215{
216 u8 data;
217 int ret = 0;
218
219 ret = twl_i2c_read_u8(module, &data, address);
220 if (ret >= 0)
221 ret = data;
222 else
223 dev_dbg(twl->dev,
224 "TWL4030:readb[0x%x,0x%x] Error %d\n",
225 module, address, ret);
226
227 return ret;
228}
229
230static inline int twl4030_usb_read(struct twl4030_usb *twl, u8 address)
231{
232 return twl4030_readb(twl, TWL_MODULE_USB, address);
233}
234
235/*-------------------------------------------------------------------------*/
236
237static inline int
238twl4030_usb_set_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
239{
240 return twl4030_usb_write(twl, ULPI_SET(reg), bits);
241}
242
243static inline int
244twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
245{
246 return twl4030_usb_write(twl, ULPI_CLR(reg), bits);
247}
248
249/*-------------------------------------------------------------------------*/
250
251static bool twl4030_is_driving_vbus(struct twl4030_usb *twl)
252{
253 int ret;
254
255 ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS);
256 if (ret < 0 || !(ret & PHY_DPLL_CLK))
257 /*
258 * if clocks are off, registers are not updated,
259 * but we can assume we don't drive VBUS in this case
260 */
261 return false;
262
263 ret = twl4030_usb_read(twl, ULPI_OTG_CTRL);
264 if (ret < 0)
265 return false;
266
267 return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false;
268}
269
270static enum omap_musb_vbus_id_status
271 twl4030_usb_linkstat(struct twl4030_usb *twl)
272{
273 int status;
274 enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN;
275
276 twl->vbus_supplied = false;
277
278 /*
279 * For ID/VBUS sensing, see manual section 15.4.8 ...
280 * except when using only battery backup power, two
281 * comparators produce VBUS_PRES and ID_PRES signals,
282 * which don't match docs elsewhere. But ... BIT(7)
283 * and BIT(2) of STS_HW_CONDITIONS, respectively, do
284 * seem to match up. If either is true the USB_PRES
285 * signal is active, the OTG module is activated, and
286 * its interrupt may be raised (may wake the system).
287 */
288 status = twl4030_readb(twl, TWL_MODULE_PM_MASTER, STS_HW_CONDITIONS);
289 if (status < 0)
290 dev_err(twl->dev, "USB link status err %d\n", status);
291 else if (status & (BIT(7) | BIT(2))) {
292 if (status & BIT(7)) {
293 if (twl4030_is_driving_vbus(twl))
294 status &= ~BIT(7);
295 else
296 twl->vbus_supplied = true;
297 }
298
299 if (status & BIT(2))
300 linkstat = OMAP_MUSB_ID_GROUND;
301 else if (status & BIT(7))
302 linkstat = OMAP_MUSB_VBUS_VALID;
303 else
304 linkstat = OMAP_MUSB_VBUS_OFF;
305 } else {
306 if (twl->linkstat != OMAP_MUSB_UNKNOWN)
307 linkstat = OMAP_MUSB_VBUS_OFF;
308 }
309
310 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
311 status, status, linkstat);
312
313 /* REVISIT this assumes host and peripheral controllers
314 * are registered, and that both are active...
315 */
316
317 return linkstat;
318}
319
320static void twl4030_usb_set_mode(struct twl4030_usb *twl, int mode)
321{
322 twl->usb_mode = mode;
323
324 switch (mode) {
325 case T2_USB_MODE_ULPI:
326 twl4030_usb_clear_bits(twl, ULPI_IFC_CTRL,
327 ULPI_IFC_CTRL_CARKITMODE);
328 twl4030_usb_set_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB);
329 twl4030_usb_clear_bits(twl, ULPI_FUNC_CTRL,
330 ULPI_FUNC_CTRL_XCVRSEL_MASK |
331 ULPI_FUNC_CTRL_OPMODE_MASK);
332 break;
333 case -1:
334 /* FIXME: power on defaults */
335 break;
336 default:
337 dev_err(twl->dev, "unsupported T2 transceiver mode %d\n",
338 mode);
339 break;
340 };
341}
342
343static void twl4030_i2c_access(struct twl4030_usb *twl, int on)
344{
345 unsigned long timeout;
346 int val = twl4030_usb_read(twl, PHY_CLK_CTRL);
347
348 if (val >= 0) {
349 if (on) {
350 /* enable DPLL to access PHY registers over I2C */
351 val |= REQ_PHY_DPLL_CLK;
352 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL,
353 (u8)val) < 0);
354
355 timeout = jiffies + HZ;
356 while (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) &
357 PHY_DPLL_CLK)
358 && time_before(jiffies, timeout))
359 udelay(10);
360 if (!(twl4030_usb_read(twl, PHY_CLK_CTRL_STS) &
361 PHY_DPLL_CLK))
362 dev_err(twl->dev, "Timeout setting T2 HSUSB "
363 "PHY DPLL clock\n");
364 } else {
365 /* let ULPI control the DPLL clock */
366 val &= ~REQ_PHY_DPLL_CLK;
367 WARN_ON(twl4030_usb_write_verify(twl, PHY_CLK_CTRL,
368 (u8)val) < 0);
369 }
370 }
371}
372
373static void __twl4030_phy_power(struct twl4030_usb *twl, int on)
374{
375 u8 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL);
376
377 if (on)
378 pwr &= ~PHY_PWR_PHYPWD;
379 else
380 pwr |= PHY_PWR_PHYPWD;
381
382 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0);
383}
384
385static void twl4030_phy_power(struct twl4030_usb *twl, int on)
386{
387 int ret;
388
389 if (on) {
390 ret = regulator_enable(twl->usb3v1);
391 if (ret)
392 dev_err(twl->dev, "Failed to enable usb3v1\n");
393
394 ret = regulator_enable(twl->usb1v8);
395 if (ret)
396 dev_err(twl->dev, "Failed to enable usb1v8\n");
397
398 /*
399 * Disabling usb3v1 regulator (= writing 0 to VUSB3V1_DEV_GRP
400 * in twl4030) resets the VUSB_DEDICATED2 register. This reset
401 * enables VUSB3V1_SLEEP bit that remaps usb3v1 ACTIVE state to
402 * SLEEP. We work around this by clearing the bit after usv3v1
403 * is re-activated. This ensures that VUSB3V1 is really active.
404 */
405 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2);
406
407 ret = regulator_enable(twl->usb1v5);
408 if (ret)
409 dev_err(twl->dev, "Failed to enable usb1v5\n");
410
411 __twl4030_phy_power(twl, 1);
412 twl4030_usb_write(twl, PHY_CLK_CTRL,
413 twl4030_usb_read(twl, PHY_CLK_CTRL) |
414 (PHY_CLK_CTRL_CLOCKGATING_EN |
415 PHY_CLK_CTRL_CLK32K_EN));
416 } else {
417 __twl4030_phy_power(twl, 0);
418 regulator_disable(twl->usb1v5);
419 regulator_disable(twl->usb1v8);
420 regulator_disable(twl->usb3v1);
421 }
422}
423
424static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off)
425{
426 if (twl->asleep)
427 return;
428
429 twl4030_phy_power(twl, 0);
430 twl->asleep = 1;
431 dev_dbg(twl->dev, "%s\n", __func__);
432}
433
434static void __twl4030_phy_resume(struct twl4030_usb *twl)
435{
436 twl4030_phy_power(twl, 1);
437 twl4030_i2c_access(twl, 1);
438 twl4030_usb_set_mode(twl, twl->usb_mode);
439 if (twl->usb_mode == T2_USB_MODE_ULPI)
440 twl4030_i2c_access(twl, 0);
441}
442
443static void twl4030_phy_resume(struct twl4030_usb *twl)
444{
445 if (!twl->asleep)
446 return;
447 __twl4030_phy_resume(twl);
448 twl->asleep = 0;
449 dev_dbg(twl->dev, "%s\n", __func__);
450
451 /*
452 * XXX When VBUS gets driven after musb goes to A mode,
453 * ID_PRES related interrupts no longer arrive, why?
454 * Register itself is updated fine though, so we must poll.
455 */
456 if (twl->linkstat == OMAP_MUSB_ID_GROUND) {
457 cancel_delayed_work(&twl->id_workaround_work);
458 schedule_delayed_work(&twl->id_workaround_work, HZ);
459 }
460}
461
462static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
463{
464 /* Enable writing to power configuration registers */
465 twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1,
466 TWL4030_PM_MASTER_PROTECT_KEY);
467
468 twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG2,
469 TWL4030_PM_MASTER_PROTECT_KEY);
470
471 /* Keep VUSB3V1 LDO in sleep state until VBUS/ID change detected*/
472 /*twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2);*/
473
474 /* input to VUSB3V1 LDO is from VBAT, not VBUS */
475 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0x14, VUSB_DEDICATED1);
476
477 /* Initialize 3.1V regulator */
478 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP);
479
480 twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1");
481 if (IS_ERR(twl->usb3v1))
482 return -ENODEV;
483
484 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB3V1_TYPE);
485
486 /* Initialize 1.5V regulator */
487 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP);
488
489 twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5");
490 if (IS_ERR(twl->usb1v5))
491 return -ENODEV;
492
493 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE);
494
495 /* Initialize 1.8V regulator */
496 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP);
497
498 twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8");
499 if (IS_ERR(twl->usb1v8))
500 return -ENODEV;
501
502 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE);
503
504 /* disable access to power configuration registers */
505 twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0,
506 TWL4030_PM_MASTER_PROTECT_KEY);
507
508 return 0;
509}
510
511static ssize_t twl4030_usb_vbus_show(struct device *dev,
512 struct device_attribute *attr, char *buf)
513{
514 struct twl4030_usb *twl = dev_get_drvdata(dev);
515 unsigned long flags;
516 int ret = -EINVAL;
517
518 spin_lock_irqsave(&twl->lock, flags);
519 ret = sprintf(buf, "%s\n",
520 twl->vbus_supplied ? "on" : "off");
521 spin_unlock_irqrestore(&twl->lock, flags);
522
523 return ret;
524}
525static DEVICE_ATTR(vbus, 0444, twl4030_usb_vbus_show, NULL);
526
527static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
528{
529 struct twl4030_usb *twl = _twl;
530 enum omap_musb_vbus_id_status status;
531 bool status_changed = false;
532
533 status = twl4030_usb_linkstat(twl);
534
535 spin_lock_irq(&twl->lock);
536 if (status >= 0 && status != twl->linkstat) {
537 twl->linkstat = status;
538 status_changed = true;
539 }
540 spin_unlock_irq(&twl->lock);
541
542 if (status_changed) {
543 /* FIXME add a set_power() method so that B-devices can
544 * configure the charger appropriately. It's not always
545 * correct to consume VBUS power, and how much current to
546 * consume is a function of the USB configuration chosen
547 * by the host.
548 *
549 * REVISIT usb_gadget_vbus_connect(...) as needed, ditto
550 * its disconnect() sibling, when changing to/from the
551 * USB_LINK_VBUS state. musb_hdrc won't care until it
552 * starts to handle softconnect right.
553 */
554 omap_musb_mailbox(status);
555 }
556 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
557
558 return IRQ_HANDLED;
559}
560
561static void twl4030_id_workaround_work(struct work_struct *work)
562{
563 struct twl4030_usb *twl = container_of(work, struct twl4030_usb,
564 id_workaround_work.work);
565 enum omap_musb_vbus_id_status status;
566 bool status_changed = false;
567
568 status = twl4030_usb_linkstat(twl);
569
570 spin_lock_irq(&twl->lock);
571 if (status >= 0 && status != twl->linkstat) {
572 twl->linkstat = status;
573 status_changed = true;
574 }
575 spin_unlock_irq(&twl->lock);
576
577 if (status_changed) {
578 dev_dbg(twl->dev, "handle missing status change to %d\n",
579 status);
580 omap_musb_mailbox(status);
581 }
582
583 /* don't schedule during sleep - irq works right then */
584 if (status == OMAP_MUSB_ID_GROUND && !twl->asleep) {
585 cancel_delayed_work(&twl->id_workaround_work);
586 schedule_delayed_work(&twl->id_workaround_work, HZ);
587 }
588}
589
590static int twl4030_usb_phy_init(struct usb_phy *phy)
591{
592 struct twl4030_usb *twl = phy_to_twl(phy);
593 enum omap_musb_vbus_id_status status;
594
595 /*
596 * Start in sleep state, we'll get called through set_suspend()
597 * callback when musb is runtime resumed and it's time to start.
598 */
599 __twl4030_phy_power(twl, 0);
600 twl->asleep = 1;
601
602 status = twl4030_usb_linkstat(twl);
603 twl->linkstat = status;
604
605 if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
606 omap_musb_mailbox(twl->linkstat);
607
608 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
609 return 0;
610}
611
612static int twl4030_set_suspend(struct usb_phy *x, int suspend)
613{
614 struct twl4030_usb *twl = phy_to_twl(x);
615
616 if (suspend)
617 twl4030_phy_suspend(twl, 1);
618 else
619 twl4030_phy_resume(twl);
620
621 return 0;
622}
623
624static int twl4030_set_peripheral(struct usb_otg *otg,
625 struct usb_gadget *gadget)
626{
627 if (!otg)
628 return -ENODEV;
629
630 otg->gadget = gadget;
631 if (!gadget)
632 otg->phy->state = OTG_STATE_UNDEFINED;
633
634 return 0;
635}
636
637static int twl4030_set_host(struct usb_otg *otg, struct usb_bus *host)
638{
639 if (!otg)
640 return -ENODEV;
641
642 otg->host = host;
643 if (!host)
644 otg->phy->state = OTG_STATE_UNDEFINED;
645
646 return 0;
647}
648
649static int twl4030_usb_probe(struct platform_device *pdev)
650{
651 struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev);
652 struct twl4030_usb *twl;
653 int status, err;
654 struct usb_otg *otg;
655 struct device_node *np = pdev->dev.of_node;
656
657 twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL);
658 if (!twl)
659 return -ENOMEM;
660
661 if (np)
662 of_property_read_u32(np, "usb_mode",
663 (enum twl4030_usb_mode *)&twl->usb_mode);
664 else if (pdata)
665 twl->usb_mode = pdata->usb_mode;
666 else {
667 dev_err(&pdev->dev, "twl4030 initialized without pdata\n");
668 return -EINVAL;
669 }
670
671 otg = devm_kzalloc(&pdev->dev, sizeof *otg, GFP_KERNEL);
672 if (!otg)
673 return -ENOMEM;
674
675 twl->dev = &pdev->dev;
676 twl->irq = platform_get_irq(pdev, 0);
677 twl->vbus_supplied = false;
678 twl->asleep = 1;
679 twl->linkstat = OMAP_MUSB_UNKNOWN;
680
681 twl->phy.dev = twl->dev;
682 twl->phy.label = "twl4030";
683 twl->phy.otg = otg;
684 twl->phy.type = USB_PHY_TYPE_USB2;
685 twl->phy.set_suspend = twl4030_set_suspend;
686 twl->phy.init = twl4030_usb_phy_init;
687
688 otg->phy = &twl->phy;
689 otg->set_host = twl4030_set_host;
690 otg->set_peripheral = twl4030_set_peripheral;
691
692 /* init spinlock for workqueue */
693 spin_lock_init(&twl->lock);
694
695 INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work);
696
697 err = twl4030_usb_ldo_init(twl);
698 if (err) {
699 dev_err(&pdev->dev, "ldo init failed\n");
700 return err;
701 }
702 usb_add_phy_dev(&twl->phy);
703
704 platform_set_drvdata(pdev, twl);
705 if (device_create_file(&pdev->dev, &dev_attr_vbus))
706 dev_warn(&pdev->dev, "could not create sysfs file\n");
707
708 /* Our job is to use irqs and status from the power module
709 * to keep the transceiver disabled when nothing's connected.
710 *
711 * FIXME we actually shouldn't start enabling it until the
712 * USB controller drivers have said they're ready, by calling
713 * set_host() and/or set_peripheral() ... OTG_capable boards
714 * need both handles, otherwise just one suffices.
715 */
716 twl->irq_enabled = true;
717 status = devm_request_threaded_irq(twl->dev, twl->irq, NULL,
718 twl4030_usb_irq, IRQF_TRIGGER_FALLING |
719 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl);
720 if (status < 0) {
721 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n",
722 twl->irq, status);
723 return status;
724 }
725
726 dev_info(&pdev->dev, "Initialized TWL4030 USB module\n");
727 return 0;
728}
729
730static int twl4030_usb_remove(struct platform_device *pdev)
731{
732 struct twl4030_usb *twl = platform_get_drvdata(pdev);
733 int val;
734
735 cancel_delayed_work(&twl->id_workaround_work);
736 device_remove_file(twl->dev, &dev_attr_vbus);
737
738 /* set transceiver mode to power on defaults */
739 twl4030_usb_set_mode(twl, -1);
740
741 /* autogate 60MHz ULPI clock,
742 * clear dpll clock request for i2c access,
743 * disable 32KHz
744 */
745 val = twl4030_usb_read(twl, PHY_CLK_CTRL);
746 if (val >= 0) {
747 val |= PHY_CLK_CTRL_CLOCKGATING_EN;
748 val &= ~(PHY_CLK_CTRL_CLK32K_EN | REQ_PHY_DPLL_CLK);
749 twl4030_usb_write(twl, PHY_CLK_CTRL, (u8)val);
750 }
751
752 /* disable complete OTG block */
753 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB);
754
755 if (!twl->asleep)
756 twl4030_phy_power(twl, 0);
757
758 return 0;
759}
760
761#ifdef CONFIG_OF
762static const struct of_device_id twl4030_usb_id_table[] = {
763 { .compatible = "ti,twl4030-usb" },
764 {}
765};
766MODULE_DEVICE_TABLE(of, twl4030_usb_id_table);
767#endif
768
769static struct platform_driver twl4030_usb_driver = {
770 .probe = twl4030_usb_probe,
771 .remove = twl4030_usb_remove,
772 .driver = {
773 .name = "twl4030_usb",
774 .owner = THIS_MODULE,
775 .of_match_table = of_match_ptr(twl4030_usb_id_table),
776 },
777};
778
779static int __init twl4030_usb_init(void)
780{
781 return platform_driver_register(&twl4030_usb_driver);
782}
783subsys_initcall(twl4030_usb_init);
784
785static void __exit twl4030_usb_exit(void)
786{
787 platform_driver_unregister(&twl4030_usb_driver);
788}
789module_exit(twl4030_usb_exit);
790
791MODULE_ALIAS("platform:twl4030_usb");
792MODULE_AUTHOR("Texas Instruments, Inc, Nokia Corporation");
793MODULE_DESCRIPTION("TWL4030 USB transceiver driver");
794MODULE_LICENSE("GPL");
diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c
index 16dbc9382678..30e8a61552d4 100644
--- a/drivers/usb/phy/phy-twl6030-usb.c
+++ b/drivers/usb/phy/phy-twl6030-usb.c
@@ -33,6 +33,7 @@
33#include <linux/err.h> 33#include <linux/err.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/of.h>
36 37
37/* usb register definitions */ 38/* usb register definitions */
38#define USB_VENDOR_ID_LSB 0x00 39#define USB_VENDOR_ID_LSB 0x00
diff --git a/drivers/usb/phy/phy-ulpi-viewport.c b/drivers/usb/phy/phy-ulpi-viewport.c
index 7c22a5390fc3..18bb8264b5a0 100644
--- a/drivers/usb/phy/phy-ulpi-viewport.c
+++ b/drivers/usb/phy/phy-ulpi-viewport.c
@@ -36,7 +36,7 @@ static int ulpi_viewport_wait(void __iomem *view, u32 mask)
36 return 0; 36 return 0;
37 37
38 udelay(1); 38 udelay(1);
39 }; 39 }
40 40
41 return -ETIMEDOUT; 41 return -ETIMEDOUT;
42} 42}
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c
index a9984c700d2c..1b74523e1fee 100644
--- a/drivers/usb/phy/phy.c
+++ b/drivers/usb/phy/phy.c
@@ -98,7 +98,7 @@ struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
98 98
99 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL); 99 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
100 if (!ptr) 100 if (!ptr)
101 return NULL; 101 return ERR_PTR(-ENOMEM);
102 102
103 phy = usb_get_phy(type); 103 phy = usb_get_phy(type);
104 if (!IS_ERR(phy)) { 104 if (!IS_ERR(phy)) {
diff --git a/drivers/usb/renesas_usbhs/Kconfig b/drivers/usb/renesas_usbhs/Kconfig
index 019bf7e49ee6..1c4195abc108 100644
--- a/drivers/usb/renesas_usbhs/Kconfig
+++ b/drivers/usb/renesas_usbhs/Kconfig
@@ -4,7 +4,7 @@
4 4
5config USB_RENESAS_USBHS 5config USB_RENESAS_USBHS
6 tristate 'Renesas USBHS controller' 6 tristate 'Renesas USBHS controller'
7 depends on USB_GADGET && GENERIC_HARDIRQS 7 depends on USB_GADGET
8 default n 8 default n
9 help 9 help
10 Renesas USBHS is a discrete USB host and peripheral controller chip 10 Renesas USBHS is a discrete USB host and peripheral controller chip
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index c454bfa22a10..ddb9c51f2c99 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -60,7 +60,7 @@ config USB_SERIAL_SIMPLE
60 - Suunto ANT+ USB device. 60 - Suunto ANT+ USB device.
61 - Fundamental Software dongle. 61 - Fundamental Software dongle.
62 - HP4x calculators 62 - HP4x calculators
63 - a number of Motoroloa phones 63 - a number of Motorola phones
64 - Siemens USB/MPI adapter. 64 - Siemens USB/MPI adapter.
65 - ViVOtech ViVOpay USB device. 65 - ViVOtech ViVOpay USB device.
66 - Infineon Modem Flashloader USB interface 66 - Infineon Modem Flashloader USB interface
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 781426230d69..6e1b69d0f5f5 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -279,7 +279,7 @@ static void cyberjack_read_int_callback(struct urb *urb)
279 279
280 old_rdtodo = priv->rdtodo; 280 old_rdtodo = priv->rdtodo;
281 281
282 if (old_rdtodo + size < old_rdtodo) { 282 if (old_rdtodo > SHRT_MAX - size) {
283 dev_dbg(dev, "To many bulk_in urbs to do.\n"); 283 dev_dbg(dev, "To many bulk_in urbs to do.\n");
284 spin_unlock(&priv->lock); 284 spin_unlock(&priv->lock);
285 goto resubmit; 285 goto resubmit;
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index c45f9c0a1b34..9ced8937a8f3 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -904,6 +904,7 @@ static struct usb_device_id id_table_combined [] = {
904 { USB_DEVICE(FTDI_VID, FTDI_LUMEL_PD12_PID) }, 904 { USB_DEVICE(FTDI_VID, FTDI_LUMEL_PD12_PID) },
905 /* Crucible Devices */ 905 /* Crucible Devices */
906 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) }, 906 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) },
907 { USB_DEVICE(FTDI_VID, FTDI_Z3X_PID) },
907 { } /* Terminating entry */ 908 { } /* Terminating entry */
908}; 909};
909 910
@@ -1966,8 +1967,16 @@ static int ftdi_process_packet(struct usb_serial_port *port,
1966 port->icount.dsr++; 1967 port->icount.dsr++;
1967 if (diff_status & FTDI_RS0_RI) 1968 if (diff_status & FTDI_RS0_RI)
1968 port->icount.rng++; 1969 port->icount.rng++;
1969 if (diff_status & FTDI_RS0_RLSD) 1970 if (diff_status & FTDI_RS0_RLSD) {
1971 struct tty_struct *tty;
1972
1970 port->icount.dcd++; 1973 port->icount.dcd++;
1974 tty = tty_port_tty_get(&port->port);
1975 if (tty)
1976 usb_serial_handle_dcd_change(port, tty,
1977 status & FTDI_RS0_RLSD);
1978 tty_kref_put(tty);
1979 }
1971 1980
1972 wake_up_interruptible(&port->port.delta_msr_wait); 1981 wake_up_interruptible(&port->port.delta_msr_wait);
1973 priv->prev_status = status; 1982 priv->prev_status = status;
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 1b8af461b522..a7019d1e3058 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -1307,3 +1307,9 @@
1307 * Manufacturer: Crucible Technologies 1307 * Manufacturer: Crucible Technologies
1308 */ 1308 */
1309#define FTDI_CT_COMET_PID 0x8e08 1309#define FTDI_CT_COMET_PID 0x8e08
1310
1311/*
1312 * Product: Z3X Box
1313 * Manufacturer: Smart GSM Team
1314 */
1315#define FTDI_Z3X_PID 0x0011
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 1f31e6b4c251..2b01ec8651c2 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -7,7 +7,6 @@
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation. 9 * 2 as published by the Free Software Foundation.
10 *
11 */ 10 */
12 11
13#include <linux/kernel.h> 12#include <linux/kernel.h>
@@ -37,7 +36,6 @@ MODULE_PARM_DESC(product, "User specified USB idProduct");
37 36
38static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */ 37static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */
39 38
40/* All of the device info needed for the Generic Serial Converter */
41struct usb_serial_driver usb_serial_generic_device = { 39struct usb_serial_driver usb_serial_generic_device = {
42 .driver = { 40 .driver = {
43 .owner = THIS_MODULE, 41 .owner = THIS_MODULE,
@@ -66,7 +64,6 @@ int usb_serial_generic_register(void)
66 generic_device_ids[0].match_flags = 64 generic_device_ids[0].match_flags =
67 USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; 65 USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
68 66
69 /* register our generic driver with ourselves */
70 retval = usb_serial_register_drivers(serial_drivers, 67 retval = usb_serial_register_drivers(serial_drivers,
71 "usbserial_generic", generic_device_ids); 68 "usbserial_generic", generic_device_ids);
72#endif 69#endif
@@ -76,7 +73,6 @@ int usb_serial_generic_register(void)
76void usb_serial_generic_deregister(void) 73void usb_serial_generic_deregister(void)
77{ 74{
78#ifdef CONFIG_USB_SERIAL_GENERIC 75#ifdef CONFIG_USB_SERIAL_GENERIC
79 /* remove our generic driver */
80 usb_serial_deregister_drivers(serial_drivers); 76 usb_serial_deregister_drivers(serial_drivers);
81#endif 77#endif
82} 78}
@@ -86,13 +82,11 @@ int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port
86 int result = 0; 82 int result = 0;
87 unsigned long flags; 83 unsigned long flags;
88 84
89 /* clear the throttle flags */
90 spin_lock_irqsave(&port->lock, flags); 85 spin_lock_irqsave(&port->lock, flags);
91 port->throttled = 0; 86 port->throttled = 0;
92 port->throttle_req = 0; 87 port->throttle_req = 0;
93 spin_unlock_irqrestore(&port->lock, flags); 88 spin_unlock_irqrestore(&port->lock, flags);
94 89
95 /* if we have a bulk endpoint, start reading from it */
96 if (port->bulk_in_size) 90 if (port->bulk_in_size)
97 result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL); 91 result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
98 92
@@ -127,12 +121,16 @@ int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
127} 121}
128 122
129/** 123/**
130 * usb_serial_generic_write_start - kick off an URB write 124 * usb_serial_generic_write_start - start writing buffered data
131 * @port: Pointer to the &struct usb_serial_port data 125 * @port: usb-serial port
126 * @mem_flags: flags to use for memory allocations
127 *
128 * Serialised using USB_SERIAL_WRITE_BUSY flag.
132 * 129 *
133 * Returns zero on success, or a negative errno value 130 * Return: Zero on success or if busy, otherwise a negative errno value.
134 */ 131 */
135static int usb_serial_generic_write_start(struct usb_serial_port *port) 132int usb_serial_generic_write_start(struct usb_serial_port *port,
133 gfp_t mem_flags)
136{ 134{
137 struct urb *urb; 135 struct urb *urb;
138 int count, result; 136 int count, result;
@@ -163,7 +161,7 @@ retry:
163 spin_unlock_irqrestore(&port->lock, flags); 161 spin_unlock_irqrestore(&port->lock, flags);
164 162
165 clear_bit(i, &port->write_urbs_free); 163 clear_bit(i, &port->write_urbs_free);
166 result = usb_submit_urb(urb, GFP_ATOMIC); 164 result = usb_submit_urb(urb, mem_flags);
167 if (result) { 165 if (result) {
168 dev_err_console(port, "%s - error submitting urb: %d\n", 166 dev_err_console(port, "%s - error submitting urb: %d\n",
169 __func__, result); 167 __func__, result);
@@ -175,34 +173,34 @@ retry:
175 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); 173 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
176 return result; 174 return result;
177 } 175 }
178 176 /*
179 /* Try sending off another urb, unless in irq context (in which case 177 * Try sending off another urb, unless called from completion handler
180 * there will be no free urb). */ 178 * (in which case there will be no free urb or no data).
181 if (!in_irq()) 179 */
180 if (mem_flags != GFP_ATOMIC)
182 goto retry; 181 goto retry;
183 182
184 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); 183 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
185 184
186 return 0; 185 return 0;
187} 186}
187EXPORT_SYMBOL_GPL(usb_serial_generic_write_start);
188 188
189/** 189/**
190 * usb_serial_generic_write - generic write function for serial USB devices 190 * usb_serial_generic_write - generic write function
191 * @tty: Pointer to &struct tty_struct for the device 191 * @tty: tty for the port
192 * @port: Pointer to the &usb_serial_port structure for the device 192 * @port: usb-serial port
193 * @buf: Pointer to the data to write 193 * @buf: data to write
194 * @count: Number of bytes to write 194 * @count: number of bytes to write
195 * 195 *
196 * Returns the number of characters actually written, which may be anything 196 * Return: The number of characters buffered, which may be anything from
197 * from zero to @count. If an error occurs, it returns the negative errno 197 * zero to @count, or a negative errno value.
198 * value.
199 */ 198 */
200int usb_serial_generic_write(struct tty_struct *tty, 199int usb_serial_generic_write(struct tty_struct *tty,
201 struct usb_serial_port *port, const unsigned char *buf, int count) 200 struct usb_serial_port *port, const unsigned char *buf, int count)
202{ 201{
203 int result; 202 int result;
204 203
205 /* only do something if we have a bulk out endpoint */
206 if (!port->bulk_out_size) 204 if (!port->bulk_out_size)
207 return -ENODEV; 205 return -ENODEV;
208 206
@@ -210,7 +208,7 @@ int usb_serial_generic_write(struct tty_struct *tty,
210 return 0; 208 return 0;
211 209
212 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); 210 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock);
213 result = usb_serial_generic_write_start(port); 211 result = usb_serial_generic_write_start(port, GFP_KERNEL);
214 if (result) 212 if (result)
215 return result; 213 return result;
216 214
@@ -337,10 +335,11 @@ void usb_serial_generic_process_read_urb(struct urb *urb)
337 335
338 if (!urb->actual_length) 336 if (!urb->actual_length)
339 return; 337 return;
340 338 /*
341 /* The per character mucking around with sysrq path it too slow for 339 * The per character mucking around with sysrq path it too slow for
342 stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases 340 * stuff like 3G modems, so shortcircuit it in the 99.9999999% of
343 where the USB serial is not a console anyway */ 341 * cases where the USB serial is not a console anyway.
342 */
344 if (!port->port.console || !port->sysrq) 343 if (!port->port.console || !port->sysrq)
345 tty_insert_flip_string(&port->port, ch, urb->actual_length); 344 tty_insert_flip_string(&port->port, ch, urb->actual_length);
346 else { 345 else {
@@ -413,7 +412,7 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb)
413 kfifo_reset_out(&port->write_fifo); 412 kfifo_reset_out(&port->write_fifo);
414 spin_unlock_irqrestore(&port->lock, flags); 413 spin_unlock_irqrestore(&port->lock, flags);
415 } else { 414 } else {
416 usb_serial_generic_write_start(port); 415 usb_serial_generic_write_start(port, GFP_ATOMIC);
417 } 416 }
418 417
419 usb_serial_port_softint(port); 418 usb_serial_port_softint(port);
@@ -425,8 +424,6 @@ void usb_serial_generic_throttle(struct tty_struct *tty)
425 struct usb_serial_port *port = tty->driver_data; 424 struct usb_serial_port *port = tty->driver_data;
426 unsigned long flags; 425 unsigned long flags;
427 426
428 /* Set the throttle request flag. It will be picked up
429 * by usb_serial_generic_read_bulk_callback(). */
430 spin_lock_irqsave(&port->lock, flags); 427 spin_lock_irqsave(&port->lock, flags);
431 port->throttle_req = 1; 428 port->throttle_req = 1;
432 spin_unlock_irqrestore(&port->lock, flags); 429 spin_unlock_irqrestore(&port->lock, flags);
@@ -438,7 +435,6 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty)
438 struct usb_serial_port *port = tty->driver_data; 435 struct usb_serial_port *port = tty->driver_data;
439 int was_throttled; 436 int was_throttled;
440 437
441 /* Clear the throttle flags */
442 spin_lock_irq(&port->lock); 438 spin_lock_irq(&port->lock);
443 was_throttled = port->throttled; 439 was_throttled = port->throttled;
444 port->throttled = port->throttle_req = 0; 440 port->throttled = port->throttle_req = 0;
@@ -558,10 +554,10 @@ int usb_serial_handle_break(struct usb_serial_port *port)
558EXPORT_SYMBOL_GPL(usb_serial_handle_break); 554EXPORT_SYMBOL_GPL(usb_serial_handle_break);
559 555
560/** 556/**
561 * usb_serial_handle_dcd_change - handle a change of carrier detect state 557 * usb_serial_handle_dcd_change - handle a change of carrier detect state
562 * @port: usb_serial_port structure for the open port 558 * @port: usb-serial port
563 * @tty: tty_struct structure for the port 559 * @tty: tty for the port
564 * @status: new carrier detect status, nonzero if active 560 * @status: new carrier detect status, nonzero if active
565 */ 561 */
566void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port, 562void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
567 struct tty_struct *tty, unsigned int status) 563 struct tty_struct *tty, unsigned int status)
@@ -570,6 +566,16 @@ void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
570 566
571 dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status); 567 dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status);
572 568
569 if (tty) {
570 struct tty_ldisc *ld = tty_ldisc_ref(tty);
571
572 if (ld) {
573 if (ld->ops->dcd_change)
574 ld->ops->dcd_change(tty, status);
575 tty_ldisc_deref(ld);
576 }
577 }
578
573 if (status) 579 if (status)
574 wake_up_interruptible(&port->open_wait); 580 wake_up_interruptible(&port->open_wait);
575 else if (tty && !C_CLOCAL(tty)) 581 else if (tty && !C_CLOCAL(tty))
@@ -595,7 +601,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
595 } 601 }
596 602
597 if (port->bulk_out_size) { 603 if (port->bulk_out_size) {
598 r = usb_serial_generic_write_start(port); 604 r = usb_serial_generic_write_start(port, GFP_NOIO);
599 if (r < 0) 605 if (r < 0)
600 c++; 606 c++;
601 } 607 }
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 84657e07dc5d..439c951f261b 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -455,7 +455,7 @@ static int parport_prologue(struct parport *pp)
455 return -1; 455 return -1;
456 } 456 }
457 mos_parport->msg_pending = true; /* synch usb call pending */ 457 mos_parport->msg_pending = true; /* synch usb call pending */
458 INIT_COMPLETION(mos_parport->syncmsg_compl); 458 reinit_completion(&mos_parport->syncmsg_compl);
459 spin_unlock(&release_lock); 459 spin_unlock(&release_lock);
460 460
461 mutex_lock(&mos_parport->serial->disc_mutex); 461 mutex_lock(&mos_parport->serial->disc_mutex);
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index fdf953539c62..e5bdd987b9e8 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1532,7 +1532,11 @@ static int mos7840_tiocmget(struct tty_struct *tty)
1532 return -ENODEV; 1532 return -ENODEV;
1533 1533
1534 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); 1534 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1535 if (status != 1)
1536 return -EIO;
1535 status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr); 1537 status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1538 if (status != 1)
1539 return -EIO;
1536 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) 1540 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1537 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) 1541 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1538 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0) 1542 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 1cf6f125f5f0..c3d94853b4ab 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -81,6 +81,7 @@ static void option_instat_callback(struct urb *urb);
81 81
82#define HUAWEI_VENDOR_ID 0x12D1 82#define HUAWEI_VENDOR_ID 0x12D1
83#define HUAWEI_PRODUCT_E173 0x140C 83#define HUAWEI_PRODUCT_E173 0x140C
84#define HUAWEI_PRODUCT_E1750 0x1406
84#define HUAWEI_PRODUCT_K4505 0x1464 85#define HUAWEI_PRODUCT_K4505 0x1464
85#define HUAWEI_PRODUCT_K3765 0x1465 86#define HUAWEI_PRODUCT_K3765 0x1465
86#define HUAWEI_PRODUCT_K4605 0x14C6 87#define HUAWEI_PRODUCT_K4605 0x14C6
@@ -450,6 +451,10 @@ static void option_instat_callback(struct urb *urb);
450#define CHANGHONG_VENDOR_ID 0x2077 451#define CHANGHONG_VENDOR_ID 0x2077
451#define CHANGHONG_PRODUCT_CH690 0x7001 452#define CHANGHONG_PRODUCT_CH690 0x7001
452 453
454/* Inovia */
455#define INOVIA_VENDOR_ID 0x20a6
456#define INOVIA_SEW858 0x1105
457
453/* some devices interfaces need special handling due to a number of reasons */ 458/* some devices interfaces need special handling due to a number of reasons */
454enum option_blacklist_reason { 459enum option_blacklist_reason {
455 OPTION_BLACKLIST_NONE = 0, 460 OPTION_BLACKLIST_NONE = 0,
@@ -567,6 +572,8 @@ static const struct usb_device_id option_ids[] = {
567 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1c23, USB_CLASS_COMM, 0x02, 0xff) }, 572 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1c23, USB_CLASS_COMM, 0x02, 0xff) },
568 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E173, 0xff, 0xff, 0xff), 573 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E173, 0xff, 0xff, 0xff),
569 .driver_info = (kernel_ulong_t) &net_intf1_blacklist }, 574 .driver_info = (kernel_ulong_t) &net_intf1_blacklist },
575 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E1750, 0xff, 0xff, 0xff),
576 .driver_info = (kernel_ulong_t) &net_intf2_blacklist },
570 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1441, USB_CLASS_COMM, 0x02, 0xff) }, 577 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1441, USB_CLASS_COMM, 0x02, 0xff) },
571 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1442, USB_CLASS_COMM, 0x02, 0xff) }, 578 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1442, USB_CLASS_COMM, 0x02, 0xff) },
572 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff), 579 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff),
@@ -686,6 +693,222 @@ static const struct usb_device_id option_ids[] = {
686 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7A) }, 693 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7A) },
687 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7B) }, 694 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7B) },
688 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7C) }, 695 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x02, 0x7C) },
696 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x01) },
697 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x02) },
698 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x03) },
699 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x04) },
700 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x05) },
701 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x06) },
702 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0A) },
703 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0B) },
704 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0D) },
705 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0E) },
706 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x0F) },
707 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x10) },
708 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x12) },
709 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x13) },
710 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x14) },
711 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x15) },
712 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x17) },
713 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x18) },
714 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x19) },
715 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x1A) },
716 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x1B) },
717 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x1C) },
718 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x31) },
719 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x32) },
720 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x33) },
721 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x34) },
722 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x35) },
723 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x36) },
724 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3A) },
725 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3B) },
726 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3D) },
727 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3E) },
728 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x3F) },
729 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x48) },
730 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x49) },
731 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x4A) },
732 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x4B) },
733 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x4C) },
734 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x61) },
735 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x62) },
736 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x63) },
737 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x64) },
738 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x65) },
739 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x66) },
740 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6A) },
741 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6B) },
742 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6D) },
743 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6E) },
744 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x6F) },
745 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x78) },
746 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x79) },
747 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x7A) },
748 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x7B) },
749 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x03, 0x7C) },
750 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x01) },
751 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x02) },
752 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x03) },
753 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x04) },
754 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x05) },
755 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x06) },
756 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0A) },
757 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0B) },
758 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0D) },
759 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0E) },
760 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x0F) },
761 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x10) },
762 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x12) },
763 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x13) },
764 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x14) },
765 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x15) },
766 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x17) },
767 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x18) },
768 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x19) },
769 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x1A) },
770 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x1B) },
771 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x1C) },
772 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x31) },
773 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x32) },
774 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x33) },
775 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x34) },
776 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x35) },
777 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x36) },
778 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3A) },
779 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3B) },
780 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3D) },
781 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3E) },
782 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x3F) },
783 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x48) },
784 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x49) },
785 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x4A) },
786 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x4B) },
787 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x4C) },
788 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x61) },
789 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x62) },
790 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x63) },
791 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x64) },
792 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x65) },
793 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x66) },
794 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6A) },
795 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6B) },
796 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6D) },
797 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6E) },
798 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x6F) },
799 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x78) },
800 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x79) },
801 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x7A) },
802 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x7B) },
803 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x04, 0x7C) },
804 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x01) },
805 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x02) },
806 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x03) },
807 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x04) },
808 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x05) },
809 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x06) },
810 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0A) },
811 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0B) },
812 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0D) },
813 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0E) },
814 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x0F) },
815 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x10) },
816 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x12) },
817 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x13) },
818 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x14) },
819 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x15) },
820 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x17) },
821 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x18) },
822 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x19) },
823 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x1A) },
824 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x1B) },
825 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x1C) },
826 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x31) },
827 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x32) },
828 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x33) },
829 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x34) },
830 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x35) },
831 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x36) },
832 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3A) },
833 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3B) },
834 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3D) },
835 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3E) },
836 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x3F) },
837 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x48) },
838 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x49) },
839 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x4A) },
840 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x4B) },
841 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x4C) },
842 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x61) },
843 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x62) },
844 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x63) },
845 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x64) },
846 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x65) },
847 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x66) },
848 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6A) },
849 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6B) },
850 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6D) },
851 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6E) },
852 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x6F) },
853 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x78) },
854 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x79) },
855 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x7A) },
856 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x7B) },
857 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x05, 0x7C) },
858 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x01) },
859 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x02) },
860 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x03) },
861 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x04) },
862 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x05) },
863 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x06) },
864 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0A) },
865 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0B) },
866 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0D) },
867 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0E) },
868 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x0F) },
869 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x10) },
870 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x12) },
871 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x13) },
872 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x14) },
873 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x15) },
874 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x17) },
875 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x18) },
876 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x19) },
877 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x1A) },
878 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x1B) },
879 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x1C) },
880 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x31) },
881 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x32) },
882 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x33) },
883 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x34) },
884 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x35) },
885 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x36) },
886 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3A) },
887 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3B) },
888 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3D) },
889 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3E) },
890 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x3F) },
891 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x48) },
892 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x49) },
893 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x4A) },
894 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x4B) },
895 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x4C) },
896 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x61) },
897 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x62) },
898 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x63) },
899 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x64) },
900 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x65) },
901 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x66) },
902 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6A) },
903 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6B) },
904 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6D) },
905 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6E) },
906 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x6F) },
907 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x78) },
908 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x79) },
909 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x7A) },
910 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x7B) },
911 { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x7C) },
689 912
690 913
691 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, 914 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) },
@@ -1153,6 +1376,23 @@ static const struct usb_device_id option_ids[] = {
1153 .driver_info = (kernel_ulong_t)&net_intf2_blacklist }, 1376 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1154 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1426, 0xff, 0xff, 0xff), /* ZTE MF91 */ 1377 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1426, 0xff, 0xff, 0xff), /* ZTE MF91 */
1155 .driver_info = (kernel_ulong_t)&net_intf2_blacklist }, 1378 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1379 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1533, 0xff, 0xff, 0xff) },
1380 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1534, 0xff, 0xff, 0xff) },
1381 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1535, 0xff, 0xff, 0xff) },
1382 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1545, 0xff, 0xff, 0xff) },
1383 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1546, 0xff, 0xff, 0xff) },
1384 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1547, 0xff, 0xff, 0xff) },
1385 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1565, 0xff, 0xff, 0xff) },
1386 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1566, 0xff, 0xff, 0xff) },
1387 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1567, 0xff, 0xff, 0xff) },
1388 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1589, 0xff, 0xff, 0xff) },
1389 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1590, 0xff, 0xff, 0xff) },
1390 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1591, 0xff, 0xff, 0xff) },
1391 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1592, 0xff, 0xff, 0xff) },
1392 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1594, 0xff, 0xff, 0xff) },
1393 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1596, 0xff, 0xff, 0xff) },
1394 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1598, 0xff, 0xff, 0xff) },
1395 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1600, 0xff, 0xff, 0xff) },
1156 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff, 1396 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff,
1157 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist }, 1397 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist },
1158 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) }, 1398 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) },
@@ -1254,7 +1494,9 @@ static const struct usb_device_id option_ids[] = {
1254 1494
1255 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) }, 1495 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) },
1256 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD145) }, 1496 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD145) },
1257 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD200) }, 1497 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD200),
1498 .driver_info = (kernel_ulong_t)&net_intf6_blacklist
1499 },
1258 { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */ 1500 { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */
1259 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_GT_B3730, USB_CLASS_CDC_DATA, 0x00, 0x00) }, /* Samsung GT-B3730 LTE USB modem.*/ 1501 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_GT_B3730, USB_CLASS_CDC_DATA, 0x00, 0x00) }, /* Samsung GT-B3730 LTE USB modem.*/
1260 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM600) }, 1502 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM600) },
@@ -1342,6 +1584,7 @@ static const struct usb_device_id option_ids[] = {
1342 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d03, 0xff, 0x00, 0x00) }, 1584 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d03, 0xff, 0x00, 0x00) },
1343 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e01, 0xff, 0xff, 0xff) }, /* D-Link DWM-152/C1 */ 1585 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e01, 0xff, 0xff, 0xff) }, /* D-Link DWM-152/C1 */
1344 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e02, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/C1 */ 1586 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e02, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/C1 */
1587 { USB_DEVICE(INOVIA_VENDOR_ID, INOVIA_SEW858) },
1345 { } /* Terminating entry */ 1588 { } /* Terminating entry */
1346}; 1589};
1347MODULE_DEVICE_TABLE(usb, option_ids); 1590MODULE_DEVICE_TABLE(usb, option_ids);
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index e7a84f0f5179..1e6de4cd079d 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -4,11 +4,6 @@
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 *
12 * Original driver for 2.2.x by anonymous 7 * Original driver for 2.2.x by anonymous
13 * 8 *
14 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
@@ -134,17 +129,10 @@ MODULE_DEVICE_TABLE(usb, id_table);
134 129
135 130
136enum pl2303_type { 131enum pl2303_type {
137 type_0, /* H version ? */ 132 type_0, /* don't know the difference between type 0 and */
138 type_1, /* H version ? */ 133 type_1, /* type 1, until someone from prolific tells us... */
139 HX_TA, /* HX(A) / X(A) / TA version */ /* TODO: improve */ 134 HX, /* HX version of the pl2303 chip */
140 HXD_EA_RA_SA, /* HXD / EA / RA / SA version */ /* TODO: improve */
141 TB, /* TB version */
142}; 135};
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 */
148 136
149struct pl2303_serial_private { 137struct pl2303_serial_private {
150 enum pl2303_type type; 138 enum pl2303_type type;
@@ -184,7 +172,6 @@ static int pl2303_startup(struct usb_serial *serial)
184{ 172{
185 struct pl2303_serial_private *spriv; 173 struct pl2303_serial_private *spriv;
186 enum pl2303_type type = type_0; 174 enum pl2303_type type = type_0;
187 char *type_str = "unknown (treating as type_0)";
188 unsigned char *buf; 175 unsigned char *buf;
189 176
190 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 177 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
@@ -197,38 +184,15 @@ static int pl2303_startup(struct usb_serial *serial)
197 return -ENOMEM; 184 return -ENOMEM;
198 } 185 }
199 186
200 if (serial->dev->descriptor.bDeviceClass == 0x02) { 187 if (serial->dev->descriptor.bDeviceClass == 0x02)
201 type = type_0; 188 type = type_0;
202 type_str = "type_0"; 189 else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40)
203 } else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) { 190 type = HX;
204 /* 191 else if (serial->dev->descriptor.bDeviceClass == 0x00)
205 * NOTE: The bcdDevice version is the only difference between
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) {
228 type = type_1; 192 type = type_1;
229 type_str = "type_1"; 193 else if (serial->dev->descriptor.bDeviceClass == 0xFF)
230 } 194 type = type_1;
231 dev_dbg(&serial->interface->dev, "device type: %s\n", type_str); 195 dev_dbg(&serial->interface->dev, "device type: %d\n", type);
232 196
233 spriv->type = type; 197 spriv->type = type;
234 usb_set_serial_data(serial, spriv); 198 usb_set_serial_data(serial, spriv);
@@ -243,10 +207,10 @@ static int pl2303_startup(struct usb_serial *serial)
243 pl2303_vendor_read(0x8383, 0, serial, buf); 207 pl2303_vendor_read(0x8383, 0, serial, buf);
244 pl2303_vendor_write(0, 1, serial); 208 pl2303_vendor_write(0, 1, serial);
245 pl2303_vendor_write(1, 0, serial); 209 pl2303_vendor_write(1, 0, serial);
246 if (type == type_0 || type == type_1) 210 if (type == HX)
247 pl2303_vendor_write(2, 0x24, serial);
248 else
249 pl2303_vendor_write(2, 0x44, serial); 211 pl2303_vendor_write(2, 0x44, serial);
212 else
213 pl2303_vendor_write(2, 0x24, serial);
250 214
251 kfree(buf); 215 kfree(buf);
252 return 0; 216 return 0;
@@ -300,170 +264,65 @@ static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value)
300 return retval; 264 return retval;
301} 265}
302 266
303static int pl2303_baudrate_encode_direct(int baud, enum pl2303_type type, 267static void pl2303_encode_baudrate(struct tty_struct *tty,
304 u8 buf[4]) 268 struct usb_serial_port *port,
269 u8 buf[4])
305{ 270{
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, 271 const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600,
312 4800, 7200, 9600, 14400, 19200, 28800, 38400, 272 4800, 7200, 9600, 14400, 19200, 28800, 38400,
313 57600, 115200, 230400, 460800, 614400, 921600, 273 57600, 115200, 230400, 460800, 500000, 614400,
314 1228800, 2457600, 3000000, 6000000, 12000000 }; 274 921600, 1228800, 2457600, 3000000, 6000000 };
275
276 struct usb_serial *serial = port->serial;
277 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
278 int baud;
279 int i;
280
315 /* 281 /*
316 * NOTE: With the exception of type_0/1 devices, the following 282 * NOTE: Only the values defined in baud_sup are supported!
317 * additional baud rates are supported (tested with HX rev. 3A only): 283 * => if unsupported values are set, the PL2303 seems to use
318 * 110*, 56000*, 128000, 134400, 161280, 201600, 256000*, 268800, 284 * 9600 baud (at least my PL2303X always does)
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 */ 285 */
328 int i; 286 baud = tty_get_baud_rate(tty);
287 dev_dbg(&port->dev, "baud requested = %d\n", baud);
288 if (!baud)
289 return;
329 290
330 /* Set baudrate to nearest supported value */ 291 /* Set baudrate to nearest supported value */
331 for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) { 292 for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) {
332 if (baud_sup[i] > baud) 293 if (baud_sup[i] > baud)
333 break; 294 break;
334 } 295 }
296
335 if (i == ARRAY_SIZE(baud_sup)) 297 if (i == ARRAY_SIZE(baud_sup))
336 baud = baud_sup[i - 1]; 298 baud = baud_sup[i - 1];
337 else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1])) 299 else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1]))
338 baud = baud_sup[i - 1]; 300 baud = baud_sup[i - 1];
339 else 301 else
340 baud = baud_sup[i]; 302 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 303
353 return baud; 304 /* type_0, type_1 only support up to 1228800 baud */
354} 305 if (spriv->type != HX)
355 306 baud = min_t(int, baud, 1228800);
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 307
377 /* 308 if (baud <= 115200) {
378 * NOTE: The Windows driver allows maximum baud rates of 110% of the 309 put_unaligned_le32(baud, buf);
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 { 310 } 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 /* 311 /*
420 * NOTE: With the current algorithm this happens 312 * Apparently the formula for higher speeds is:
421 * only for A=0 and means that the min. divisor 313 * baudrate = 12M * 32 / (2^buf[1]) / buf[0]
422 * (respectively: the max. baudrate) is reached.
423 */ 314 */
424 B = 16; /* => 24 MBaud */ 315 unsigned tmp = 12000000 * 32 / baud;
425 /* Encode the baud rate */ 316 buf[3] = 0x80;
426 buf[3] = 0x80; /* Select divisor encoding method */ 317 buf[2] = 0;
427 buf[2] = 0; 318 buf[1] = (tmp >= 256);
428 buf[1] = (A & 0x0e); /* A */ 319 while (tmp >= 256) {
429 buf[1] |= ((B & 0x100) >> 8); /* MSB of B */ 320 tmp >>= 2;
430 buf[0] = B & 0xff; /* 8 LSBs of B */ 321 buf[1] <<= 1;
431 /* Calculate the actual/resulting baud rate */ 322 }
432 if (B <= 8) 323 buf[0] = tmp;
433 B = 512; 324 }
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 325
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 */ 326 /* Save resulting baud rate */
468 tty_encode_baud_rate(tty, baud, baud); 327 tty_encode_baud_rate(tty, baud, baud);
469 dev_dbg(&port->dev, "baud set = %d\n", baud); 328 dev_dbg(&port->dev, "baud set = %d\n", baud);
@@ -520,8 +379,8 @@ static void pl2303_set_termios(struct tty_struct *tty,
520 dev_dbg(&port->dev, "data bits = %d\n", buf[6]); 379 dev_dbg(&port->dev, "data bits = %d\n", buf[6]);
521 } 380 }
522 381
523 /* For reference: buf[0]:buf[3] baud rate value */ 382 /* For reference buf[0]:buf[3] baud rate value */
524 pl2303_encode_baudrate(tty, port, spriv->type, buf); 383 pl2303_encode_baudrate(tty, port, &buf[0]);
525 384
526 /* For reference buf[4]=0 is 1 stop bits */ 385 /* For reference buf[4]=0 is 1 stop bits */
527 /* For reference buf[4]=1 is 1.5 stop bits */ 386 /* For reference buf[4]=1 is 1.5 stop bits */
@@ -598,10 +457,10 @@ static void pl2303_set_termios(struct tty_struct *tty,
598 dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); 457 dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf);
599 458
600 if (C_CRTSCTS(tty)) { 459 if (C_CRTSCTS(tty)) {
601 if (spriv->type == type_0 || spriv->type == type_1) 460 if (spriv->type == HX)
602 pl2303_vendor_write(0x0, 0x41, serial);
603 else
604 pl2303_vendor_write(0x0, 0x61, serial); 461 pl2303_vendor_write(0x0, 0x61, serial);
462 else
463 pl2303_vendor_write(0x0, 0x41, serial);
605 } else { 464 } else {
606 pl2303_vendor_write(0x0, 0x0, serial); 465 pl2303_vendor_write(0x0, 0x0, serial);
607 } 466 }
@@ -638,7 +497,7 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
638 struct pl2303_serial_private *spriv = usb_get_serial_data(serial); 497 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
639 int result; 498 int result;
640 499
641 if (spriv->type == type_0 || spriv->type == type_1) { 500 if (spriv->type != HX) {
642 usb_clear_halt(serial->dev, port->write_urb->pipe); 501 usb_clear_halt(serial->dev, port->write_urb->pipe);
643 usb_clear_halt(serial->dev, port->read_urb->pipe); 502 usb_clear_halt(serial->dev, port->read_urb->pipe);
644 } else { 503 } else {
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 760b78560f67..c9a35697ebe9 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -190,6 +190,7 @@ static struct usb_device_id ti_id_table_combined[] = {
190 { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) }, 190 { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) },
191 { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) }, 191 { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) },
192 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) }, 192 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) },
193 { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_STRIP_PORT_ID) },
193 { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) }, 194 { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) },
194 { } /* terminator */ 195 { } /* terminator */
195}; 196};
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 94d75edef77f..18509e6c21ab 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -211,8 +211,11 @@ static int slave_configure(struct scsi_device *sdev)
211 /* 211 /*
212 * Many devices do not respond properly to READ_CAPACITY_16. 212 * Many devices do not respond properly to READ_CAPACITY_16.
213 * Tell the SCSI layer to try READ_CAPACITY_10 first. 213 * Tell the SCSI layer to try READ_CAPACITY_10 first.
214 * However some USB 3.0 drive enclosures return capacity
215 * modulo 2TB. Those must use READ_CAPACITY_16
214 */ 216 */
215 sdev->try_rc_10_first = 1; 217 if (!(us->fflags & US_FL_NEEDS_CAP16))
218 sdev->try_rc_10_first = 1;
216 219
217 /* assume SPC3 or latter devices support sense size > 18 */ 220 /* assume SPC3 or latter devices support sense size > 18 */
218 if (sdev->scsi_level > SCSI_SPC_2) 221 if (sdev->scsi_level > SCSI_SPC_2)
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index c015f2c16729..de32cfa5bfa6 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1925,6 +1925,13 @@ UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1925 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 1925 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1926 US_FL_IGNORE_RESIDUE ), 1926 US_FL_IGNORE_RESIDUE ),
1927 1927
1928/* Reported by Oliver Neukum <oneukum@suse.com> */
1929UNUSUAL_DEV( 0x174c, 0x55aa, 0x0100, 0x0100,
1930 "ASMedia",
1931 "AS2105",
1932 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1933 US_FL_NEEDS_CAP16),
1934
1928/* Reported by Jesse Feddema <jdfeddema@gmail.com> */ 1935/* Reported by Jesse Feddema <jdfeddema@gmail.com> */
1929UNUSUAL_DEV( 0x177f, 0x0400, 0x0000, 0x0000, 1936UNUSUAL_DEV( 0x177f, 0x0400, 0x0000, 0x0000,
1930 "Yarvik", 1937 "Yarvik",
diff --git a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c
index 7f78f300f8fb..f06ed82e63d1 100644
--- a/drivers/usb/wusbcore/cbaf.c
+++ b/drivers/usb/wusbcore/cbaf.c
@@ -208,9 +208,9 @@ static int cbaf_check(struct cbaf *cbaf)
208 ar_name = "ASSOCIATE"; 208 ar_name = "ASSOCIATE";
209 ar_assoc = 1; 209 ar_assoc = 1;
210 break; 210 break;
211 }; 211 }
212 break; 212 break;
213 }; 213 }
214 214
215 dev_dbg(dev, "Association request #%02u: 0x%04x/%04x " 215 dev_dbg(dev, "Association request #%02u: 0x%04x/%04x "
216 "(%zu bytes): %s\n", 216 "(%zu bytes): %s\n",
@@ -623,6 +623,8 @@ static int cbaf_probe(struct usb_interface *iface,
623 623
624error_create_group: 624error_create_group:
625error_check: 625error_check:
626 usb_put_intf(iface);
627 usb_put_dev(cbaf->usb_dev);
626 kfree(cbaf->buffer); 628 kfree(cbaf->buffer);
627error_kmalloc_buffer: 629error_kmalloc_buffer:
628 kfree(cbaf); 630 kfree(cbaf);
@@ -637,6 +639,7 @@ static void cbaf_disconnect(struct usb_interface *iface)
637 sysfs_remove_group(&dev->kobj, &cbaf_dev_attr_group); 639 sysfs_remove_group(&dev->kobj, &cbaf_dev_attr_group);
638 usb_set_intfdata(iface, NULL); 640 usb_set_intfdata(iface, NULL);
639 usb_put_intf(iface); 641 usb_put_intf(iface);
642 usb_put_dev(cbaf->usb_dev);
640 kfree(cbaf->buffer); 643 kfree(cbaf->buffer);
641 /* paranoia: clean up crypto keys */ 644 /* paranoia: clean up crypto keys */
642 kzfree(cbaf); 645 kzfree(cbaf);
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c
index 33a12788f9ca..e538b72c4e3a 100644
--- a/drivers/usb/wusbcore/devconnect.c
+++ b/drivers/usb/wusbcore/devconnect.c
@@ -973,7 +973,7 @@ int wusb_usb_ncb(struct notifier_block *nb, unsigned long val,
973 default: 973 default:
974 WARN_ON(1); 974 WARN_ON(1);
975 result = NOTIFY_BAD; 975 result = NOTIFY_BAD;
976 }; 976 }
977 return result; 977 return result;
978} 978}
979 979
diff --git a/drivers/usb/wusbcore/wa-hc.c b/drivers/usb/wusbcore/wa-hc.c
index a09b65ebd9bb..368360f9a93a 100644
--- a/drivers/usb/wusbcore/wa-hc.c
+++ b/drivers/usb/wusbcore/wa-hc.c
@@ -33,7 +33,8 @@
33 * wa->usb_dev and wa->usb_iface initialized and refcounted, 33 * wa->usb_dev and wa->usb_iface initialized and refcounted,
34 * wa->wa_descr initialized. 34 * wa->wa_descr initialized.
35 */ 35 */
36int wa_create(struct wahc *wa, struct usb_interface *iface) 36int wa_create(struct wahc *wa, struct usb_interface *iface,
37 kernel_ulong_t quirks)
37{ 38{
38 int result; 39 int result;
39 struct device *dev = &iface->dev; 40 struct device *dev = &iface->dev;
@@ -41,14 +42,15 @@ int wa_create(struct wahc *wa, struct usb_interface *iface)
41 result = wa_rpipes_create(wa); 42 result = wa_rpipes_create(wa);
42 if (result < 0) 43 if (result < 0)
43 goto error_rpipes_create; 44 goto error_rpipes_create;
45 wa->quirks = quirks;
44 /* Fill up Data Transfer EP pointers */ 46 /* Fill up Data Transfer EP pointers */
45 wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc; 47 wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc;
46 wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc; 48 wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc;
47 wa->xfer_result_size = usb_endpoint_maxp(wa->dti_epd); 49 wa->dti_buf_size = usb_endpoint_maxp(wa->dti_epd);
48 wa->xfer_result = kmalloc(wa->xfer_result_size, GFP_KERNEL); 50 wa->dti_buf = kmalloc(wa->dti_buf_size, GFP_KERNEL);
49 if (wa->xfer_result == NULL) { 51 if (wa->dti_buf == NULL) {
50 result = -ENOMEM; 52 result = -ENOMEM;
51 goto error_xfer_result_alloc; 53 goto error_dti_buf_alloc;
52 } 54 }
53 result = wa_nep_create(wa, iface); 55 result = wa_nep_create(wa, iface);
54 if (result < 0) { 56 if (result < 0) {
@@ -59,8 +61,8 @@ int wa_create(struct wahc *wa, struct usb_interface *iface)
59 return 0; 61 return 0;
60 62
61error_nep_create: 63error_nep_create:
62 kfree(wa->xfer_result); 64 kfree(wa->dti_buf);
63error_xfer_result_alloc: 65error_dti_buf_alloc:
64 wa_rpipes_destroy(wa); 66 wa_rpipes_destroy(wa);
65error_rpipes_create: 67error_rpipes_create:
66 return result; 68 return result;
@@ -76,7 +78,7 @@ void __wa_destroy(struct wahc *wa)
76 usb_kill_urb(wa->buf_in_urb); 78 usb_kill_urb(wa->buf_in_urb);
77 usb_put_urb(wa->buf_in_urb); 79 usb_put_urb(wa->buf_in_urb);
78 } 80 }
79 kfree(wa->xfer_result); 81 kfree(wa->dti_buf);
80 wa_nep_destroy(wa); 82 wa_nep_destroy(wa);
81 wa_rpipes_destroy(wa); 83 wa_rpipes_destroy(wa);
82} 84}
diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
index cf250c21e946..e614f02f0cf2 100644
--- a/drivers/usb/wusbcore/wa-hc.h
+++ b/drivers/usb/wusbcore/wa-hc.h
@@ -117,11 +117,25 @@ struct wa_rpipe {
117 struct wahc *wa; 117 struct wahc *wa;
118 spinlock_t seg_lock; 118 spinlock_t seg_lock;
119 struct list_head seg_list; 119 struct list_head seg_list;
120 struct list_head list_node;
120 atomic_t segs_available; 121 atomic_t segs_available;
121 u8 buffer[1]; /* For reads/writes on USB */ 122 u8 buffer[1]; /* For reads/writes on USB */
122}; 123};
123 124
124 125
126enum wa_dti_state {
127 WA_DTI_TRANSFER_RESULT_PENDING,
128 WA_DTI_ISOC_PACKET_STATUS_PENDING
129};
130
131enum wa_quirks {
132 /*
133 * The Alereon HWA expects the data frames in isochronous transfer
134 * requests to be concatenated and not sent as separate packets.
135 */
136 WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC = 0x01,
137};
138
125/** 139/**
126 * Instance of a HWA Host Controller 140 * Instance of a HWA Host Controller
127 * 141 *
@@ -178,14 +192,26 @@ struct wahc {
178 192
179 u16 rpipes; 193 u16 rpipes;
180 unsigned long *rpipe_bm; /* rpipe usage bitmap */ 194 unsigned long *rpipe_bm; /* rpipe usage bitmap */
181 spinlock_t rpipe_bm_lock; /* protect rpipe_bm */ 195 struct list_head rpipe_delayed_list; /* delayed RPIPES. */
196 spinlock_t rpipe_lock; /* protect rpipe_bm and delayed list */
182 struct mutex rpipe_mutex; /* assigning resources to endpoints */ 197 struct mutex rpipe_mutex; /* assigning resources to endpoints */
183 198
199 /*
200 * dti_state is used to track the state of the dti_urb. When dti_state
201 * is WA_DTI_ISOC_PACKET_STATUS_PENDING, dti_isoc_xfer_in_progress and
202 * dti_isoc_xfer_seg identify which xfer the incoming isoc packet status
203 * refers to.
204 */
205 enum wa_dti_state dti_state;
206 u32 dti_isoc_xfer_in_progress;
207 u8 dti_isoc_xfer_seg;
184 struct urb *dti_urb; /* URB for reading xfer results */ 208 struct urb *dti_urb; /* URB for reading xfer results */
185 struct urb *buf_in_urb; /* URB for reading data in */ 209 struct urb *buf_in_urb; /* URB for reading data in */
186 struct edc dti_edc; /* DTI error density counter */ 210 struct edc dti_edc; /* DTI error density counter */
187 struct wa_xfer_result *xfer_result; /* real size = dti_ep maxpktsize */ 211 void *dti_buf;
188 size_t xfer_result_size; 212 size_t dti_buf_size;
213
214 unsigned long dto_in_use; /* protect dto endoint serialization. */
189 215
190 s32 status; /* For reading status */ 216 s32 status; /* For reading status */
191 217
@@ -200,10 +226,13 @@ struct wahc {
200 struct work_struct xfer_enqueue_work; 226 struct work_struct xfer_enqueue_work;
201 struct work_struct xfer_error_work; 227 struct work_struct xfer_error_work;
202 atomic_t xfer_id_count; 228 atomic_t xfer_id_count;
229
230 kernel_ulong_t quirks;
203}; 231};
204 232
205 233
206extern int wa_create(struct wahc *wa, struct usb_interface *iface); 234extern int wa_create(struct wahc *wa, struct usb_interface *iface,
235 kernel_ulong_t);
207extern void __wa_destroy(struct wahc *wa); 236extern void __wa_destroy(struct wahc *wa);
208void wa_reset_all(struct wahc *wa); 237void wa_reset_all(struct wahc *wa);
209 238
@@ -239,7 +268,8 @@ static inline void wa_nep_disarm(struct wahc *wa)
239/* RPipes */ 268/* RPipes */
240static inline void wa_rpipe_init(struct wahc *wa) 269static inline void wa_rpipe_init(struct wahc *wa)
241{ 270{
242 spin_lock_init(&wa->rpipe_bm_lock); 271 INIT_LIST_HEAD(&wa->rpipe_delayed_list);
272 spin_lock_init(&wa->rpipe_lock);
243 mutex_init(&wa->rpipe_mutex); 273 mutex_init(&wa->rpipe_mutex);
244} 274}
245 275
@@ -247,6 +277,7 @@ static inline void wa_init(struct wahc *wa)
247{ 277{
248 edc_init(&wa->nep_edc); 278 edc_init(&wa->nep_edc);
249 atomic_set(&wa->notifs_queued, 0); 279 atomic_set(&wa->notifs_queued, 0);
280 wa->dti_state = WA_DTI_TRANSFER_RESULT_PENDING;
250 wa_rpipe_init(wa); 281 wa_rpipe_init(wa);
251 edc_init(&wa->dti_edc); 282 edc_init(&wa->dti_edc);
252 INIT_LIST_HEAD(&wa->xfer_list); 283 INIT_LIST_HEAD(&wa->xfer_list);
@@ -255,6 +286,7 @@ static inline void wa_init(struct wahc *wa)
255 spin_lock_init(&wa->xfer_list_lock); 286 spin_lock_init(&wa->xfer_list_lock);
256 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run); 287 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
257 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run); 288 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
289 wa->dto_in_use = 0;
258 atomic_set(&wa->xfer_id_count, 1); 290 atomic_set(&wa->xfer_id_count, 1);
259} 291}
260 292
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c
index fd4f1ce6256a..b48e74cc54d7 100644
--- a/drivers/usb/wusbcore/wa-rpipe.c
+++ b/drivers/usb/wusbcore/wa-rpipe.c
@@ -143,17 +143,18 @@ static void rpipe_init(struct wa_rpipe *rpipe)
143 kref_init(&rpipe->refcnt); 143 kref_init(&rpipe->refcnt);
144 spin_lock_init(&rpipe->seg_lock); 144 spin_lock_init(&rpipe->seg_lock);
145 INIT_LIST_HEAD(&rpipe->seg_list); 145 INIT_LIST_HEAD(&rpipe->seg_list);
146 INIT_LIST_HEAD(&rpipe->list_node);
146} 147}
147 148
148static unsigned rpipe_get_idx(struct wahc *wa, unsigned rpipe_idx) 149static unsigned rpipe_get_idx(struct wahc *wa, unsigned rpipe_idx)
149{ 150{
150 unsigned long flags; 151 unsigned long flags;
151 152
152 spin_lock_irqsave(&wa->rpipe_bm_lock, flags); 153 spin_lock_irqsave(&wa->rpipe_lock, flags);
153 rpipe_idx = find_next_zero_bit(wa->rpipe_bm, wa->rpipes, rpipe_idx); 154 rpipe_idx = find_next_zero_bit(wa->rpipe_bm, wa->rpipes, rpipe_idx);
154 if (rpipe_idx < wa->rpipes) 155 if (rpipe_idx < wa->rpipes)
155 set_bit(rpipe_idx, wa->rpipe_bm); 156 set_bit(rpipe_idx, wa->rpipe_bm);
156 spin_unlock_irqrestore(&wa->rpipe_bm_lock, flags); 157 spin_unlock_irqrestore(&wa->rpipe_lock, flags);
157 158
158 return rpipe_idx; 159 return rpipe_idx;
159} 160}
@@ -162,9 +163,9 @@ static void rpipe_put_idx(struct wahc *wa, unsigned rpipe_idx)
162{ 163{
163 unsigned long flags; 164 unsigned long flags;
164 165
165 spin_lock_irqsave(&wa->rpipe_bm_lock, flags); 166 spin_lock_irqsave(&wa->rpipe_lock, flags);
166 clear_bit(rpipe_idx, wa->rpipe_bm); 167 clear_bit(rpipe_idx, wa->rpipe_bm);
167 spin_unlock_irqrestore(&wa->rpipe_bm_lock, flags); 168 spin_unlock_irqrestore(&wa->rpipe_lock, flags);
168} 169}
169 170
170void rpipe_destroy(struct kref *_rpipe) 171void rpipe_destroy(struct kref *_rpipe)
@@ -333,7 +334,10 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa,
333 /* FIXME: compute so seg_size > ep->maxpktsize */ 334 /* FIXME: compute so seg_size > ep->maxpktsize */
334 rpipe->descr.wBlocks = cpu_to_le16(16); /* given */ 335 rpipe->descr.wBlocks = cpu_to_le16(16); /* given */
335 /* ep0 maxpktsize is 0x200 (WUSB1.0[4.8.1]) */ 336 /* ep0 maxpktsize is 0x200 (WUSB1.0[4.8.1]) */
336 rpipe->descr.wMaxPacketSize = cpu_to_le16(ep->desc.wMaxPacketSize); 337 if (usb_endpoint_xfer_isoc(&ep->desc))
338 rpipe->descr.wMaxPacketSize = epcd->wOverTheAirPacketSize;
339 else
340 rpipe->descr.wMaxPacketSize = ep->desc.wMaxPacketSize;
337 341
338 rpipe->descr.hwa_bMaxBurst = max(min_t(unsigned int, 342 rpipe->descr.hwa_bMaxBurst = max(min_t(unsigned int,
339 epcd->bMaxBurst, 16U), 1U); 343 epcd->bMaxBurst, 16U), 1U);
@@ -361,8 +365,10 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa,
361 epcd->bMaxSequence, 32U), 2U); 365 epcd->bMaxSequence, 32U), 2U);
362 rpipe->descr.bMaxDataSequence = epcd_max_sequence - 1; 366 rpipe->descr.bMaxDataSequence = epcd_max_sequence - 1;
363 rpipe->descr.bInterval = ep->desc.bInterval; 367 rpipe->descr.bInterval = ep->desc.bInterval;
364 /* FIXME: bOverTheAirInterval */ 368 if (usb_endpoint_xfer_isoc(&ep->desc))
365 rpipe->descr.bOverTheAirInterval = 0; /* 0 if not isoc */ 369 rpipe->descr.bOverTheAirInterval = epcd->bOverTheAirInterval;
370 else
371 rpipe->descr.bOverTheAirInterval = 0; /* 0 if not isoc */
366 /* FIXME: xmit power & preamble blah blah */ 372 /* FIXME: xmit power & preamble blah blah */
367 rpipe->descr.bmAttribute = (ep->desc.bmAttributes & 373 rpipe->descr.bmAttribute = (ep->desc.bmAttributes &
368 USB_ENDPOINT_XFERTYPE_MASK); 374 USB_ENDPOINT_XFERTYPE_MASK);
@@ -477,7 +483,7 @@ error:
477 */ 483 */
478int wa_rpipes_create(struct wahc *wa) 484int wa_rpipes_create(struct wahc *wa)
479{ 485{
480 wa->rpipes = wa->wa_descr->wNumRPipes; 486 wa->rpipes = le16_to_cpu(wa->wa_descr->wNumRPipes);
481 wa->rpipe_bm = kzalloc(BITS_TO_LONGS(wa->rpipes)*sizeof(unsigned long), 487 wa->rpipe_bm = kzalloc(BITS_TO_LONGS(wa->rpipes)*sizeof(unsigned long),
482 GFP_KERNEL); 488 GFP_KERNEL);
483 if (wa->rpipe_bm == NULL) 489 if (wa->rpipe_bm == NULL)
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 6ad02f57c366..ed5abe87b049 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -91,7 +91,8 @@
91#include "wusbhc.h" 91#include "wusbhc.h"
92 92
93enum { 93enum {
94 WA_SEGS_MAX = 255, 94 /* [WUSB] section 8.3.3 allocates 7 bits for the segment index. */
95 WA_SEGS_MAX = 128,
95}; 96};
96 97
97enum wa_seg_status { 98enum wa_seg_status {
@@ -107,6 +108,7 @@ enum wa_seg_status {
107}; 108};
108 109
109static void wa_xfer_delayed_run(struct wa_rpipe *); 110static void wa_xfer_delayed_run(struct wa_rpipe *);
111static int __wa_xfer_delayed_run(struct wa_rpipe *rpipe, int *dto_waiting);
110 112
111/* 113/*
112 * Life cycle governed by 'struct urb' (the refcount of the struct is 114 * Life cycle governed by 'struct urb' (the refcount of the struct is
@@ -114,24 +116,27 @@ static void wa_xfer_delayed_run(struct wa_rpipe *);
114 * struct). 116 * struct).
115 */ 117 */
116struct wa_seg { 118struct wa_seg {
117 struct urb urb; 119 struct urb tr_urb; /* transfer request urb. */
118 struct urb *dto_urb; /* for data output? */ 120 struct urb *isoc_pack_desc_urb; /* for isoc packet descriptor. */
121 struct urb *dto_urb; /* for data output. */
119 struct list_head list_node; /* for rpipe->req_list */ 122 struct list_head list_node; /* for rpipe->req_list */
120 struct wa_xfer *xfer; /* out xfer */ 123 struct wa_xfer *xfer; /* out xfer */
121 u8 index; /* which segment we are */ 124 u8 index; /* which segment we are */
125 int isoc_frame_count; /* number of isoc frames in this segment. */
126 int isoc_frame_offset; /* starting frame offset in the xfer URB. */
127 int isoc_size; /* size of all isoc frames sent by this seg. */
122 enum wa_seg_status status; 128 enum wa_seg_status status;
123 ssize_t result; /* bytes xfered or error */ 129 ssize_t result; /* bytes xfered or error */
124 struct wa_xfer_hdr xfer_hdr; 130 struct wa_xfer_hdr xfer_hdr;
125 u8 xfer_extra[]; /* xtra space for xfer_hdr_ctl */
126}; 131};
127 132
128static inline void wa_seg_init(struct wa_seg *seg) 133static inline void wa_seg_init(struct wa_seg *seg)
129{ 134{
130 usb_init_urb(&seg->urb); 135 usb_init_urb(&seg->tr_urb);
131 136
132 /* set the remaining memory to 0. */ 137 /* set the remaining memory to 0. */
133 memset(((void *)seg) + sizeof(seg->urb), 0, 138 memset(((void *)seg) + sizeof(seg->tr_urb), 0,
134 sizeof(*seg) - sizeof(seg->urb)); 139 sizeof(*seg) - sizeof(seg->tr_urb));
135} 140}
136 141
137/* 142/*
@@ -153,12 +158,17 @@ struct wa_xfer {
153 unsigned is_dma:1; 158 unsigned is_dma:1;
154 size_t seg_size; 159 size_t seg_size;
155 int result; 160 int result;
161 /* Isoc frame that the current transfer buffer corresponds to. */
162 int dto_isoc_frame_index;
156 163
157 gfp_t gfp; /* allocation mask */ 164 gfp_t gfp; /* allocation mask */
158 165
159 struct wusb_dev *wusb_dev; /* for activity timestamps */ 166 struct wusb_dev *wusb_dev; /* for activity timestamps */
160}; 167};
161 168
169static void __wa_populate_dto_urb_isoc(struct wa_xfer *xfer,
170 struct wa_seg *seg, int curr_iso_frame);
171
162static inline void wa_xfer_init(struct wa_xfer *xfer) 172static inline void wa_xfer_init(struct wa_xfer *xfer)
163{ 173{
164 kref_init(&xfer->refcnt); 174 kref_init(&xfer->refcnt);
@@ -169,7 +179,7 @@ static inline void wa_xfer_init(struct wa_xfer *xfer)
169/* 179/*
170 * Destroy a transfer structure 180 * Destroy a transfer structure
171 * 181 *
172 * Note that freeing xfer->seg[cnt]->urb will free the containing 182 * Note that freeing xfer->seg[cnt]->tr_urb will free the containing
173 * xfer->seg[cnt] memory that was allocated by __wa_xfer_setup_segs. 183 * xfer->seg[cnt] memory that was allocated by __wa_xfer_setup_segs.
174 */ 184 */
175static void wa_xfer_destroy(struct kref *_xfer) 185static void wa_xfer_destroy(struct kref *_xfer)
@@ -178,9 +188,17 @@ static void wa_xfer_destroy(struct kref *_xfer)
178 if (xfer->seg) { 188 if (xfer->seg) {
179 unsigned cnt; 189 unsigned cnt;
180 for (cnt = 0; cnt < xfer->segs; cnt++) { 190 for (cnt = 0; cnt < xfer->segs; cnt++) {
181 usb_free_urb(xfer->seg[cnt]->dto_urb); 191 struct wa_seg *seg = xfer->seg[cnt];
182 usb_free_urb(&xfer->seg[cnt]->urb); 192 if (seg) {
193 usb_free_urb(seg->isoc_pack_desc_urb);
194 if (seg->dto_urb) {
195 kfree(seg->dto_urb->sg);
196 usb_free_urb(seg->dto_urb);
197 }
198 usb_free_urb(&seg->tr_urb);
199 }
183 } 200 }
201 kfree(xfer->seg);
184 } 202 }
185 kfree(xfer); 203 kfree(xfer);
186} 204}
@@ -196,6 +214,59 @@ static void wa_xfer_put(struct wa_xfer *xfer)
196} 214}
197 215
198/* 216/*
217 * Try to get exclusive access to the DTO endpoint resource. Return true
218 * if successful.
219 */
220static inline int __wa_dto_try_get(struct wahc *wa)
221{
222 return (test_and_set_bit(0, &wa->dto_in_use) == 0);
223}
224
225/* Release the DTO endpoint resource. */
226static inline void __wa_dto_put(struct wahc *wa)
227{
228 clear_bit_unlock(0, &wa->dto_in_use);
229}
230
231/* Service RPIPEs that are waiting on the DTO resource. */
232static void wa_check_for_delayed_rpipes(struct wahc *wa)
233{
234 unsigned long flags;
235 int dto_waiting = 0;
236 struct wa_rpipe *rpipe;
237
238 spin_lock_irqsave(&wa->rpipe_lock, flags);
239 while (!list_empty(&wa->rpipe_delayed_list) && !dto_waiting) {
240 rpipe = list_first_entry(&wa->rpipe_delayed_list,
241 struct wa_rpipe, list_node);
242 __wa_xfer_delayed_run(rpipe, &dto_waiting);
243 /* remove this RPIPE from the list if it is not waiting. */
244 if (!dto_waiting) {
245 pr_debug("%s: RPIPE %d serviced and removed from delayed list.\n",
246 __func__,
247 le16_to_cpu(rpipe->descr.wRPipeIndex));
248 list_del_init(&rpipe->list_node);
249 }
250 }
251 spin_unlock_irqrestore(&wa->rpipe_lock, flags);
252}
253
254/* add this RPIPE to the end of the delayed RPIPE list. */
255static void wa_add_delayed_rpipe(struct wahc *wa, struct wa_rpipe *rpipe)
256{
257 unsigned long flags;
258
259 spin_lock_irqsave(&wa->rpipe_lock, flags);
260 /* add rpipe to the list if it is not already on it. */
261 if (list_empty(&rpipe->list_node)) {
262 pr_debug("%s: adding RPIPE %d to the delayed list.\n",
263 __func__, le16_to_cpu(rpipe->descr.wRPipeIndex));
264 list_add_tail(&rpipe->list_node, &wa->rpipe_delayed_list);
265 }
266 spin_unlock_irqrestore(&wa->rpipe_lock, flags);
267}
268
269/*
199 * xfer is referenced 270 * xfer is referenced
200 * 271 *
201 * xfer->lock has to be unlocked 272 * xfer->lock has to be unlocked
@@ -232,6 +303,31 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
232} 303}
233 304
234/* 305/*
306 * Initialize a transfer's ID
307 *
308 * We need to use a sequential number; if we use the pointer or the
309 * hash of the pointer, it can repeat over sequential transfers and
310 * then it will confuse the HWA....wonder why in hell they put a 32
311 * bit handle in there then.
312 */
313static void wa_xfer_id_init(struct wa_xfer *xfer)
314{
315 xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
316}
317
318/* Return the xfer's ID. */
319static inline u32 wa_xfer_id(struct wa_xfer *xfer)
320{
321 return xfer->id;
322}
323
324/* Return the xfer's ID in transport format (little endian). */
325static inline __le32 wa_xfer_id_le32(struct wa_xfer *xfer)
326{
327 return cpu_to_le32(xfer->id);
328}
329
330/*
235 * If transfer is done, wrap it up and return true 331 * If transfer is done, wrap it up and return true
236 * 332 *
237 * xfer->lock has to be locked 333 * xfer->lock has to be locked
@@ -253,33 +349,37 @@ static unsigned __wa_xfer_is_done(struct wa_xfer *xfer)
253 switch (seg->status) { 349 switch (seg->status) {
254 case WA_SEG_DONE: 350 case WA_SEG_DONE:
255 if (found_short && seg->result > 0) { 351 if (found_short && seg->result > 0) {
256 dev_dbg(dev, "xfer %p#%u: bad short segments (%zu)\n", 352 dev_dbg(dev, "xfer %p ID %08X#%u: bad short segments (%zu)\n",
257 xfer, cnt, seg->result); 353 xfer, wa_xfer_id(xfer), cnt,
354 seg->result);
258 urb->status = -EINVAL; 355 urb->status = -EINVAL;
259 goto out; 356 goto out;
260 } 357 }
261 urb->actual_length += seg->result; 358 urb->actual_length += seg->result;
262 if (seg->result < xfer->seg_size 359 if (!(usb_pipeisoc(xfer->urb->pipe))
360 && seg->result < xfer->seg_size
263 && cnt != xfer->segs-1) 361 && cnt != xfer->segs-1)
264 found_short = 1; 362 found_short = 1;
265 dev_dbg(dev, "xfer %p#%u: DONE short %d " 363 dev_dbg(dev, "xfer %p ID %08X#%u: DONE short %d "
266 "result %zu urb->actual_length %d\n", 364 "result %zu urb->actual_length %d\n",
267 xfer, seg->index, found_short, seg->result, 365 xfer, wa_xfer_id(xfer), seg->index, found_short,
268 urb->actual_length); 366 seg->result, urb->actual_length);
269 break; 367 break;
270 case WA_SEG_ERROR: 368 case WA_SEG_ERROR:
271 xfer->result = seg->result; 369 xfer->result = seg->result;
272 dev_dbg(dev, "xfer %p#%u: ERROR result %zu\n", 370 dev_dbg(dev, "xfer %p ID %08X#%u: ERROR result %zu(0x%08zX)\n",
273 xfer, seg->index, seg->result); 371 xfer, wa_xfer_id(xfer), seg->index, seg->result,
372 seg->result);
274 goto out; 373 goto out;
275 case WA_SEG_ABORTED: 374 case WA_SEG_ABORTED:
276 dev_dbg(dev, "xfer %p#%u ABORTED: result %d\n", 375 dev_dbg(dev, "xfer %p ID %08X#%u ABORTED: result %d\n",
277 xfer, seg->index, urb->status); 376 xfer, wa_xfer_id(xfer), seg->index,
377 urb->status);
278 xfer->result = urb->status; 378 xfer->result = urb->status;
279 goto out; 379 goto out;
280 default: 380 default:
281 dev_warn(dev, "xfer %p#%u: is_done bad state %d\n", 381 dev_warn(dev, "xfer %p ID %08X#%u: is_done bad state %d\n",
282 xfer, cnt, seg->status); 382 xfer, wa_xfer_id(xfer), cnt, seg->status);
283 xfer->result = -EINVAL; 383 xfer->result = -EINVAL;
284 goto out; 384 goto out;
285 } 385 }
@@ -290,29 +390,6 @@ out:
290} 390}
291 391
292/* 392/*
293 * Initialize a transfer's ID
294 *
295 * We need to use a sequential number; if we use the pointer or the
296 * hash of the pointer, it can repeat over sequential transfers and
297 * then it will confuse the HWA....wonder why in hell they put a 32
298 * bit handle in there then.
299 */
300static void wa_xfer_id_init(struct wa_xfer *xfer)
301{
302 xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
303}
304
305/*
306 * Return the xfer's ID associated with xfer
307 *
308 * Need to generate a
309 */
310static u32 wa_xfer_id(struct wa_xfer *xfer)
311{
312 return xfer->id;
313}
314
315/*
316 * Search for a transfer list ID on the HCD's URB list 393 * Search for a transfer list ID on the HCD's URB list
317 * 394 *
318 * For 32 bit architectures, we use the pointer itself; for 64 bits, a 395 * For 32 bit architectures, we use the pointer itself; for 64 bits, a
@@ -356,15 +433,11 @@ static void __wa_xfer_abort_cb(struct urb *urb)
356 * 433 *
357 * The callback (see above) does nothing but freeing up the data by 434 * The callback (see above) does nothing but freeing up the data by
358 * putting the URB. Because the URB is allocated at the head of the 435 * putting the URB. Because the URB is allocated at the head of the
359 * struct, the whole space we allocated is kfreed. 436 * struct, the whole space we allocated is kfreed. *
360 *
361 * We'll get an 'aborted transaction' xfer result on DTI, that'll
362 * politely ignore because at this point the transaction has been
363 * marked as aborted already.
364 */ 437 */
365static void __wa_xfer_abort(struct wa_xfer *xfer) 438static int __wa_xfer_abort(struct wa_xfer *xfer)
366{ 439{
367 int result; 440 int result = -ENOMEM;
368 struct device *dev = &xfer->wa->usb_iface->dev; 441 struct device *dev = &xfer->wa->usb_iface->dev;
369 struct wa_xfer_abort_buffer *b; 442 struct wa_xfer_abort_buffer *b;
370 struct wa_rpipe *rpipe = xfer->ep->hcpriv; 443 struct wa_rpipe *rpipe = xfer->ep->hcpriv;
@@ -375,7 +448,7 @@ static void __wa_xfer_abort(struct wa_xfer *xfer)
375 b->cmd.bLength = sizeof(b->cmd); 448 b->cmd.bLength = sizeof(b->cmd);
376 b->cmd.bRequestType = WA_XFER_ABORT; 449 b->cmd.bRequestType = WA_XFER_ABORT;
377 b->cmd.wRPipe = rpipe->descr.wRPipeIndex; 450 b->cmd.wRPipe = rpipe->descr.wRPipeIndex;
378 b->cmd.dwTransferID = wa_xfer_id(xfer); 451 b->cmd.dwTransferID = wa_xfer_id_le32(xfer);
379 452
380 usb_init_urb(&b->urb); 453 usb_init_urb(&b->urb);
381 usb_fill_bulk_urb(&b->urb, xfer->wa->usb_dev, 454 usb_fill_bulk_urb(&b->urb, xfer->wa->usb_dev,
@@ -385,7 +458,7 @@ static void __wa_xfer_abort(struct wa_xfer *xfer)
385 result = usb_submit_urb(&b->urb, GFP_ATOMIC); 458 result = usb_submit_urb(&b->urb, GFP_ATOMIC);
386 if (result < 0) 459 if (result < 0)
387 goto error_submit; 460 goto error_submit;
388 return; /* callback frees! */ 461 return result; /* callback frees! */
389 462
390 463
391error_submit: 464error_submit:
@@ -394,11 +467,52 @@ error_submit:
394 xfer, result); 467 xfer, result);
395 kfree(b); 468 kfree(b);
396error_kmalloc: 469error_kmalloc:
397 return; 470 return result;
398 471
399} 472}
400 473
401/* 474/*
475 * Calculate the number of isoc frames starting from isoc_frame_offset
476 * that will fit a in transfer segment.
477 */
478static int __wa_seg_calculate_isoc_frame_count(struct wa_xfer *xfer,
479 int isoc_frame_offset, int *total_size)
480{
481 int segment_size = 0, frame_count = 0;
482 int index = isoc_frame_offset;
483 struct usb_iso_packet_descriptor *iso_frame_desc =
484 xfer->urb->iso_frame_desc;
485
486 while ((index < xfer->urb->number_of_packets)
487 && ((segment_size + iso_frame_desc[index].length)
488 <= xfer->seg_size)) {
489 /*
490 * For Alereon HWA devices, only include an isoc frame in a
491 * segment if it is physically contiguous with the previous
492 * frame. This is required because those devices expect
493 * the isoc frames to be sent as a single USB transaction as
494 * opposed to one transaction per frame with standard HWA.
495 */
496 if ((xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC)
497 && (index > isoc_frame_offset)
498 && ((iso_frame_desc[index - 1].offset +
499 iso_frame_desc[index - 1].length) !=
500 iso_frame_desc[index].offset))
501 break;
502
503 /* this frame fits. count it. */
504 ++frame_count;
505 segment_size += iso_frame_desc[index].length;
506
507 /* move to the next isoc frame. */
508 ++index;
509 }
510
511 *total_size = segment_size;
512 return frame_count;
513}
514
515/*
402 * 516 *
403 * @returns < 0 on error, transfer segment request size if ok 517 * @returns < 0 on error, transfer segment request size if ok
404 */ 518 */
@@ -422,43 +536,92 @@ static ssize_t __wa_xfer_setup_sizes(struct wa_xfer *xfer,
422 result = sizeof(struct wa_xfer_bi); 536 result = sizeof(struct wa_xfer_bi);
423 break; 537 break;
424 case USB_ENDPOINT_XFER_ISOC: 538 case USB_ENDPOINT_XFER_ISOC:
425 dev_err(dev, "FIXME: ISOC not implemented\n"); 539 if (usb_pipeout(urb->pipe)) {
426 result = -ENOSYS; 540 *pxfer_type = WA_XFER_TYPE_ISO;
427 goto error; 541 result = sizeof(struct wa_xfer_hwaiso);
542 } else {
543 dev_err(dev, "FIXME: ISOC IN not implemented\n");
544 result = -ENOSYS;
545 goto error;
546 }
547 break;
428 default: 548 default:
429 /* never happens */ 549 /* never happens */
430 BUG(); 550 BUG();
431 result = -EINVAL; /* shut gcc up */ 551 result = -EINVAL; /* shut gcc up */
432 }; 552 }
433 xfer->is_inbound = urb->pipe & USB_DIR_IN ? 1 : 0; 553 xfer->is_inbound = urb->pipe & USB_DIR_IN ? 1 : 0;
434 xfer->is_dma = urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? 1 : 0; 554 xfer->is_dma = urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? 1 : 0;
435 xfer->seg_size = le16_to_cpu(rpipe->descr.wBlocks) 555
436 * 1 << (xfer->wa->wa_descr->bRPipeBlockSize - 1);
437 /* Compute the segment size and make sure it is a multiple of
438 * the maxpktsize (WUSB1.0[8.3.3.1])...not really too much of
439 * a check (FIXME) */
440 maxpktsize = le16_to_cpu(rpipe->descr.wMaxPacketSize); 556 maxpktsize = le16_to_cpu(rpipe->descr.wMaxPacketSize);
441 if (xfer->seg_size < maxpktsize) { 557 if ((rpipe->descr.bmAttribute & 0x3) == USB_ENDPOINT_XFER_ISOC) {
442 dev_err(dev, "HW BUG? seg_size %zu smaller than maxpktsize " 558 int index = 0;
443 "%zu\n", xfer->seg_size, maxpktsize); 559
444 result = -EINVAL; 560 xfer->seg_size = maxpktsize;
445 goto error; 561 xfer->segs = 0;
562 /*
563 * loop over urb->number_of_packets to determine how many
564 * xfer segments will be needed to send the isoc frames.
565 */
566 while (index < urb->number_of_packets) {
567 int seg_size; /* don't care. */
568 index += __wa_seg_calculate_isoc_frame_count(xfer,
569 index, &seg_size);
570 ++xfer->segs;
571 }
572 } else {
573 xfer->seg_size = le16_to_cpu(rpipe->descr.wBlocks)
574 * 1 << (xfer->wa->wa_descr->bRPipeBlockSize - 1);
575 /* Compute the segment size and make sure it is a multiple of
576 * the maxpktsize (WUSB1.0[8.3.3.1])...not really too much of
577 * a check (FIXME) */
578 if (xfer->seg_size < maxpktsize) {
579 dev_err(dev,
580 "HW BUG? seg_size %zu smaller than maxpktsize %zu\n",
581 xfer->seg_size, maxpktsize);
582 result = -EINVAL;
583 goto error;
584 }
585 xfer->seg_size = (xfer->seg_size / maxpktsize) * maxpktsize;
586 xfer->segs = DIV_ROUND_UP(urb->transfer_buffer_length,
587 xfer->seg_size);
588 if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL)
589 xfer->segs = 1;
446 } 590 }
447 xfer->seg_size = (xfer->seg_size / maxpktsize) * maxpktsize; 591
448 xfer->segs = DIV_ROUND_UP(urb->transfer_buffer_length, xfer->seg_size); 592 if (xfer->segs > WA_SEGS_MAX) {
449 if (xfer->segs >= WA_SEGS_MAX) { 593 dev_err(dev, "BUG? oops, number of segments %zu bigger than %d\n",
450 dev_err(dev, "BUG? ops, number of segments %d bigger than %d\n", 594 (urb->transfer_buffer_length/xfer->seg_size),
451 (int)(urb->transfer_buffer_length / xfer->seg_size),
452 WA_SEGS_MAX); 595 WA_SEGS_MAX);
453 result = -EINVAL; 596 result = -EINVAL;
454 goto error; 597 goto error;
455 } 598 }
456 if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL)
457 xfer->segs = 1;
458error: 599error:
459 return result; 600 return result;
460} 601}
461 602
603static void __wa_setup_isoc_packet_descr(
604 struct wa_xfer_packet_info_hwaiso *packet_desc,
605 struct wa_xfer *xfer,
606 struct wa_seg *seg) {
607 struct usb_iso_packet_descriptor *iso_frame_desc =
608 xfer->urb->iso_frame_desc;
609 int frame_index;
610
611 /* populate isoc packet descriptor. */
612 packet_desc->bPacketType = WA_XFER_ISO_PACKET_INFO;
613 packet_desc->wLength = cpu_to_le16(sizeof(*packet_desc) +
614 (sizeof(packet_desc->PacketLength[0]) *
615 seg->isoc_frame_count));
616 for (frame_index = 0; frame_index < seg->isoc_frame_count;
617 ++frame_index) {
618 int offset_index = frame_index + seg->isoc_frame_offset;
619 packet_desc->PacketLength[frame_index] =
620 cpu_to_le16(iso_frame_desc[offset_index].length);
621 }
622}
623
624
462/* Fill in the common request header and xfer-type specific data. */ 625/* Fill in the common request header and xfer-type specific data. */
463static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer, 626static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
464 struct wa_xfer_hdr *xfer_hdr0, 627 struct wa_xfer_hdr *xfer_hdr0,
@@ -466,12 +629,13 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
466 size_t xfer_hdr_size) 629 size_t xfer_hdr_size)
467{ 630{
468 struct wa_rpipe *rpipe = xfer->ep->hcpriv; 631 struct wa_rpipe *rpipe = xfer->ep->hcpriv;
632 struct wa_seg *seg = xfer->seg[0];
469 633
470 xfer_hdr0 = &xfer->seg[0]->xfer_hdr; 634 xfer_hdr0 = &seg->xfer_hdr;
471 xfer_hdr0->bLength = xfer_hdr_size; 635 xfer_hdr0->bLength = xfer_hdr_size;
472 xfer_hdr0->bRequestType = xfer_type; 636 xfer_hdr0->bRequestType = xfer_type;
473 xfer_hdr0->wRPipe = rpipe->descr.wRPipeIndex; 637 xfer_hdr0->wRPipe = rpipe->descr.wRPipeIndex;
474 xfer_hdr0->dwTransferID = wa_xfer_id(xfer); 638 xfer_hdr0->dwTransferID = wa_xfer_id_le32(xfer);
475 xfer_hdr0->bTransferSegment = 0; 639 xfer_hdr0->bTransferSegment = 0;
476 switch (xfer_type) { 640 switch (xfer_type) {
477 case WA_XFER_TYPE_CTL: { 641 case WA_XFER_TYPE_CTL: {
@@ -484,8 +648,18 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
484 } 648 }
485 case WA_XFER_TYPE_BI: 649 case WA_XFER_TYPE_BI:
486 break; 650 break;
487 case WA_XFER_TYPE_ISO: 651 case WA_XFER_TYPE_ISO: {
488 printk(KERN_ERR "FIXME: ISOC not implemented\n"); 652 struct wa_xfer_hwaiso *xfer_iso =
653 container_of(xfer_hdr0, struct wa_xfer_hwaiso, hdr);
654 struct wa_xfer_packet_info_hwaiso *packet_desc =
655 ((void *)xfer_iso) + xfer_hdr_size;
656
657 /* populate the isoc section of the transfer request. */
658 xfer_iso->dwNumOfPackets = cpu_to_le32(seg->isoc_frame_count);
659 /* populate isoc packet descriptor. */
660 __wa_setup_isoc_packet_descr(packet_desc, xfer, seg);
661 break;
662 }
489 default: 663 default:
490 BUG(); 664 BUG();
491 }; 665 };
@@ -494,12 +668,12 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
494/* 668/*
495 * Callback for the OUT data phase of the segment request 669 * Callback for the OUT data phase of the segment request
496 * 670 *
497 * Check wa_seg_cb(); most comments also apply here because this 671 * Check wa_seg_tr_cb(); most comments also apply here because this
498 * function does almost the same thing and they work closely 672 * function does almost the same thing and they work closely
499 * together. 673 * together.
500 * 674 *
501 * If the seg request has failed but this DTO phase has succeeded, 675 * If the seg request has failed but this DTO phase has succeeded,
502 * wa_seg_cb() has already failed the segment and moved the 676 * wa_seg_tr_cb() has already failed the segment and moved the
503 * status to WA_SEG_ERROR, so this will go through 'case 0' and 677 * status to WA_SEG_ERROR, so this will go through 'case 0' and
504 * effectively do nothing. 678 * effectively do nothing.
505 */ 679 */
@@ -512,6 +686,139 @@ static void wa_seg_dto_cb(struct urb *urb)
512 struct wa_rpipe *rpipe; 686 struct wa_rpipe *rpipe;
513 unsigned long flags; 687 unsigned long flags;
514 unsigned rpipe_ready = 0; 688 unsigned rpipe_ready = 0;
689 int data_send_done = 1, release_dto = 0, holding_dto = 0;
690 u8 done = 0;
691 int result;
692
693 /* free the sg if it was used. */
694 kfree(urb->sg);
695 urb->sg = NULL;
696
697 spin_lock_irqsave(&xfer->lock, flags);
698 wa = xfer->wa;
699 dev = &wa->usb_iface->dev;
700 if (usb_pipeisoc(xfer->urb->pipe)) {
701 /* Alereon HWA sends all isoc frames in a single transfer. */
702 if (wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC)
703 xfer->dto_isoc_frame_index += seg->isoc_frame_count;
704 else
705 xfer->dto_isoc_frame_index += 1;
706 if (xfer->dto_isoc_frame_index < seg->isoc_frame_count) {
707 data_send_done = 0;
708 holding_dto = 1; /* checked in error cases. */
709 /*
710 * if this is the last isoc frame of the segment, we
711 * can release DTO after sending this frame.
712 */
713 if ((xfer->dto_isoc_frame_index + 1) >=
714 seg->isoc_frame_count)
715 release_dto = 1;
716 }
717 dev_dbg(dev, "xfer 0x%08X#%u: isoc frame = %d, holding_dto = %d, release_dto = %d.\n",
718 wa_xfer_id(xfer), seg->index,
719 xfer->dto_isoc_frame_index, holding_dto, release_dto);
720 }
721 spin_unlock_irqrestore(&xfer->lock, flags);
722
723 switch (urb->status) {
724 case 0:
725 spin_lock_irqsave(&xfer->lock, flags);
726 seg->result += urb->actual_length;
727 if (data_send_done) {
728 dev_dbg(dev, "xfer 0x%08X#%u: data out done (%zu bytes)\n",
729 wa_xfer_id(xfer), seg->index, seg->result);
730 if (seg->status < WA_SEG_PENDING)
731 seg->status = WA_SEG_PENDING;
732 } else {
733 /* should only hit this for isoc xfers. */
734 /*
735 * Populate the dto URB with the next isoc frame buffer,
736 * send the URB and release DTO if we no longer need it.
737 */
738 __wa_populate_dto_urb_isoc(xfer, seg,
739 seg->isoc_frame_offset +
740 xfer->dto_isoc_frame_index);
741
742 /* resubmit the URB with the next isoc frame. */
743 result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC);
744 if (result < 0) {
745 dev_err(dev, "xfer 0x%08X#%u: DTO submit failed: %d\n",
746 wa_xfer_id(xfer), seg->index, result);
747 spin_unlock_irqrestore(&xfer->lock, flags);
748 goto error_dto_submit;
749 }
750 }
751 spin_unlock_irqrestore(&xfer->lock, flags);
752 if (release_dto) {
753 __wa_dto_put(wa);
754 wa_check_for_delayed_rpipes(wa);
755 }
756 break;
757 case -ECONNRESET: /* URB unlinked; no need to do anything */
758 case -ENOENT: /* as it was done by the who unlinked us */
759 if (holding_dto) {
760 __wa_dto_put(wa);
761 wa_check_for_delayed_rpipes(wa);
762 }
763 break;
764 default: /* Other errors ... */
765 dev_err(dev, "xfer 0x%08X#%u: data out error %d\n",
766 wa_xfer_id(xfer), seg->index, urb->status);
767 goto error_default;
768 }
769
770 return;
771
772error_dto_submit:
773error_default:
774 spin_lock_irqsave(&xfer->lock, flags);
775 rpipe = xfer->ep->hcpriv;
776 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS,
777 EDC_ERROR_TIMEFRAME)){
778 dev_err(dev, "DTO: URB max acceptable errors exceeded, resetting device\n");
779 wa_reset_all(wa);
780 }
781 if (seg->status != WA_SEG_ERROR) {
782 seg->status = WA_SEG_ERROR;
783 seg->result = urb->status;
784 xfer->segs_done++;
785 __wa_xfer_abort(xfer);
786 rpipe_ready = rpipe_avail_inc(rpipe);
787 done = __wa_xfer_is_done(xfer);
788 }
789 spin_unlock_irqrestore(&xfer->lock, flags);
790 if (holding_dto) {
791 __wa_dto_put(wa);
792 wa_check_for_delayed_rpipes(wa);
793 }
794 if (done)
795 wa_xfer_completion(xfer);
796 if (rpipe_ready)
797 wa_xfer_delayed_run(rpipe);
798
799}
800
801/*
802 * Callback for the isoc packet descriptor phase of the segment request
803 *
804 * Check wa_seg_tr_cb(); most comments also apply here because this
805 * function does almost the same thing and they work closely
806 * together.
807 *
808 * If the seg request has failed but this phase has succeeded,
809 * wa_seg_tr_cb() has already failed the segment and moved the
810 * status to WA_SEG_ERROR, so this will go through 'case 0' and
811 * effectively do nothing.
812 */
813static void wa_seg_iso_pack_desc_cb(struct urb *urb)
814{
815 struct wa_seg *seg = urb->context;
816 struct wa_xfer *xfer = seg->xfer;
817 struct wahc *wa;
818 struct device *dev;
819 struct wa_rpipe *rpipe;
820 unsigned long flags;
821 unsigned rpipe_ready = 0;
515 u8 done = 0; 822 u8 done = 0;
516 823
517 switch (urb->status) { 824 switch (urb->status) {
@@ -519,11 +826,10 @@ static void wa_seg_dto_cb(struct urb *urb)
519 spin_lock_irqsave(&xfer->lock, flags); 826 spin_lock_irqsave(&xfer->lock, flags);
520 wa = xfer->wa; 827 wa = xfer->wa;
521 dev = &wa->usb_iface->dev; 828 dev = &wa->usb_iface->dev;
522 dev_dbg(dev, "xfer %p#%u: data out done (%d bytes)\n", 829 dev_dbg(dev, "iso xfer %08X#%u: packet descriptor done\n",
523 xfer, seg->index, urb->actual_length); 830 wa_xfer_id(xfer), seg->index);
524 if (seg->status < WA_SEG_PENDING) 831 if (xfer->is_inbound && seg->status < WA_SEG_PENDING)
525 seg->status = WA_SEG_PENDING; 832 seg->status = WA_SEG_PENDING;
526 seg->result = urb->actual_length;
527 spin_unlock_irqrestore(&xfer->lock, flags); 833 spin_unlock_irqrestore(&xfer->lock, flags);
528 break; 834 break;
529 case -ECONNRESET: /* URB unlinked; no need to do anything */ 835 case -ECONNRESET: /* URB unlinked; no need to do anything */
@@ -534,15 +840,15 @@ static void wa_seg_dto_cb(struct urb *urb)
534 wa = xfer->wa; 840 wa = xfer->wa;
535 dev = &wa->usb_iface->dev; 841 dev = &wa->usb_iface->dev;
536 rpipe = xfer->ep->hcpriv; 842 rpipe = xfer->ep->hcpriv;
537 dev_dbg(dev, "xfer %p#%u: data out error %d\n", 843 pr_err_ratelimited("iso xfer %08X#%u: packet descriptor error %d\n",
538 xfer, seg->index, urb->status); 844 wa_xfer_id(xfer), seg->index, urb->status);
539 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, 845 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS,
540 EDC_ERROR_TIMEFRAME)){ 846 EDC_ERROR_TIMEFRAME)){
541 dev_err(dev, "DTO: URB max acceptable errors " 847 dev_err(dev, "DTO: URB max acceptable errors exceeded, resetting device\n");
542 "exceeded, resetting device\n");
543 wa_reset_all(wa); 848 wa_reset_all(wa);
544 } 849 }
545 if (seg->status != WA_SEG_ERROR) { 850 if (seg->status != WA_SEG_ERROR) {
851 usb_unlink_urb(seg->dto_urb);
546 seg->status = WA_SEG_ERROR; 852 seg->status = WA_SEG_ERROR;
547 seg->result = urb->status; 853 seg->result = urb->status;
548 xfer->segs_done++; 854 xfer->segs_done++;
@@ -572,11 +878,11 @@ static void wa_seg_dto_cb(struct urb *urb)
572 * We have to check before setting the status to WA_SEG_PENDING 878 * We have to check before setting the status to WA_SEG_PENDING
573 * because sometimes the xfer result callback arrives before this 879 * because sometimes the xfer result callback arrives before this
574 * callback (geeeeeeze), so it might happen that we are already in 880 * callback (geeeeeeze), so it might happen that we are already in
575 * another state. As well, we don't set it if the transfer is inbound, 881 * another state. As well, we don't set it if the transfer is not inbound,
576 * as in that case, wa_seg_dto_cb will do it when the OUT data phase 882 * as in that case, wa_seg_dto_cb will do it when the OUT data phase
577 * finishes. 883 * finishes.
578 */ 884 */
579static void wa_seg_cb(struct urb *urb) 885static void wa_seg_tr_cb(struct urb *urb)
580{ 886{
581 struct wa_seg *seg = urb->context; 887 struct wa_seg *seg = urb->context;
582 struct wa_xfer *xfer = seg->xfer; 888 struct wa_xfer *xfer = seg->xfer;
@@ -592,8 +898,11 @@ static void wa_seg_cb(struct urb *urb)
592 spin_lock_irqsave(&xfer->lock, flags); 898 spin_lock_irqsave(&xfer->lock, flags);
593 wa = xfer->wa; 899 wa = xfer->wa;
594 dev = &wa->usb_iface->dev; 900 dev = &wa->usb_iface->dev;
595 dev_dbg(dev, "xfer %p#%u: request done\n", xfer, seg->index); 901 dev_dbg(dev, "xfer %p ID 0x%08X#%u: request done\n",
596 if (xfer->is_inbound && seg->status < WA_SEG_PENDING) 902 xfer, wa_xfer_id(xfer), seg->index);
903 if (xfer->is_inbound &&
904 seg->status < WA_SEG_PENDING &&
905 !(usb_pipeisoc(xfer->urb->pipe)))
597 seg->status = WA_SEG_PENDING; 906 seg->status = WA_SEG_PENDING;
598 spin_unlock_irqrestore(&xfer->lock, flags); 907 spin_unlock_irqrestore(&xfer->lock, flags);
599 break; 908 break;
@@ -606,14 +915,16 @@ static void wa_seg_cb(struct urb *urb)
606 dev = &wa->usb_iface->dev; 915 dev = &wa->usb_iface->dev;
607 rpipe = xfer->ep->hcpriv; 916 rpipe = xfer->ep->hcpriv;
608 if (printk_ratelimit()) 917 if (printk_ratelimit())
609 dev_err(dev, "xfer %p#%u: request error %d\n", 918 dev_err(dev, "xfer %p ID 0x%08X#%u: request error %d\n",
610 xfer, seg->index, urb->status); 919 xfer, wa_xfer_id(xfer), seg->index,
920 urb->status);
611 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, 921 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS,
612 EDC_ERROR_TIMEFRAME)){ 922 EDC_ERROR_TIMEFRAME)){
613 dev_err(dev, "DTO: URB max acceptable errors " 923 dev_err(dev, "DTO: URB max acceptable errors "
614 "exceeded, resetting device\n"); 924 "exceeded, resetting device\n");
615 wa_reset_all(wa); 925 wa_reset_all(wa);
616 } 926 }
927 usb_unlink_urb(seg->isoc_pack_desc_urb);
617 usb_unlink_urb(seg->dto_urb); 928 usb_unlink_urb(seg->dto_urb);
618 seg->status = WA_SEG_ERROR; 929 seg->status = WA_SEG_ERROR;
619 seg->result = urb->status; 930 seg->result = urb->status;
@@ -629,9 +940,11 @@ static void wa_seg_cb(struct urb *urb)
629 } 940 }
630} 941}
631 942
632/* allocate an SG list to store bytes_to_transfer bytes and copy the 943/*
944 * Allocate an SG list to store bytes_to_transfer bytes and copy the
633 * subset of the in_sg that matches the buffer subset 945 * subset of the in_sg that matches the buffer subset
634 * we are about to transfer. */ 946 * we are about to transfer.
947 */
635static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg, 948static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg,
636 const unsigned int bytes_transferred, 949 const unsigned int bytes_transferred,
637 const unsigned int bytes_to_transfer, unsigned int *out_num_sgs) 950 const unsigned int bytes_to_transfer, unsigned int *out_num_sgs)
@@ -710,6 +1023,75 @@ static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg,
710} 1023}
711 1024
712/* 1025/*
1026 * Populate DMA buffer info for the isoc dto urb.
1027 */
1028static void __wa_populate_dto_urb_isoc(struct wa_xfer *xfer,
1029 struct wa_seg *seg, int curr_iso_frame)
1030{
1031 seg->dto_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1032 seg->dto_urb->sg = NULL;
1033 seg->dto_urb->num_sgs = 0;
1034 /* dto urb buffer address pulled from iso_frame_desc. */
1035 seg->dto_urb->transfer_dma = xfer->urb->transfer_dma +
1036 xfer->urb->iso_frame_desc[curr_iso_frame].offset;
1037 /* The Alereon HWA sends a single URB with all isoc segs. */
1038 if (xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC)
1039 seg->dto_urb->transfer_buffer_length = seg->isoc_size;
1040 else
1041 seg->dto_urb->transfer_buffer_length =
1042 xfer->urb->iso_frame_desc[curr_iso_frame].length;
1043}
1044
1045/*
1046 * Populate buffer ptr and size, DMA buffer or SG list for the dto urb.
1047 */
1048static int __wa_populate_dto_urb(struct wa_xfer *xfer,
1049 struct wa_seg *seg, size_t buf_itr_offset, size_t buf_itr_size)
1050{
1051 int result = 0;
1052
1053 if (xfer->is_dma) {
1054 seg->dto_urb->transfer_dma =
1055 xfer->urb->transfer_dma + buf_itr_offset;
1056 seg->dto_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1057 seg->dto_urb->sg = NULL;
1058 seg->dto_urb->num_sgs = 0;
1059 } else {
1060 /* do buffer or SG processing. */
1061 seg->dto_urb->transfer_flags &=
1062 ~URB_NO_TRANSFER_DMA_MAP;
1063 /* this should always be 0 before a resubmit. */
1064 seg->dto_urb->num_mapped_sgs = 0;
1065
1066 if (xfer->urb->transfer_buffer) {
1067 seg->dto_urb->transfer_buffer =
1068 xfer->urb->transfer_buffer +
1069 buf_itr_offset;
1070 seg->dto_urb->sg = NULL;
1071 seg->dto_urb->num_sgs = 0;
1072 } else {
1073 seg->dto_urb->transfer_buffer = NULL;
1074
1075 /*
1076 * allocate an SG list to store seg_size bytes
1077 * and copy the subset of the xfer->urb->sg that
1078 * matches the buffer subset we are about to
1079 * read.
1080 */
1081 seg->dto_urb->sg = wa_xfer_create_subset_sg(
1082 xfer->urb->sg,
1083 buf_itr_offset, buf_itr_size,
1084 &(seg->dto_urb->num_sgs));
1085 if (!(seg->dto_urb->sg))
1086 result = -ENOMEM;
1087 }
1088 }
1089 seg->dto_urb->transfer_buffer_length = buf_itr_size;
1090
1091 return result;
1092}
1093
1094/*
713 * Allocate the segs array and initialize each of them 1095 * Allocate the segs array and initialize each of them
714 * 1096 *
715 * The segments are freed by wa_xfer_destroy() when the xfer use count 1097 * The segments are freed by wa_xfer_destroy() when the xfer use count
@@ -719,13 +1101,14 @@ static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg,
719 */ 1101 */
720static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) 1102static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size)
721{ 1103{
722 int result, cnt; 1104 int result, cnt, iso_frame_offset;
723 size_t alloc_size = sizeof(*xfer->seg[0]) 1105 size_t alloc_size = sizeof(*xfer->seg[0])
724 - sizeof(xfer->seg[0]->xfer_hdr) + xfer_hdr_size; 1106 - sizeof(xfer->seg[0]->xfer_hdr) + xfer_hdr_size;
725 struct usb_device *usb_dev = xfer->wa->usb_dev; 1107 struct usb_device *usb_dev = xfer->wa->usb_dev;
726 const struct usb_endpoint_descriptor *dto_epd = xfer->wa->dto_epd; 1108 const struct usb_endpoint_descriptor *dto_epd = xfer->wa->dto_epd;
727 struct wa_seg *seg; 1109 struct wa_seg *seg;
728 size_t buf_itr, buf_size, buf_itr_size; 1110 size_t buf_itr, buf_size, buf_itr_size;
1111 int xfer_isoc_frame_offset = 0;
729 1112
730 result = -ENOMEM; 1113 result = -ENOMEM;
731 xfer->seg = kcalloc(xfer->segs, sizeof(xfer->seg[0]), GFP_ATOMIC); 1114 xfer->seg = kcalloc(xfer->segs, sizeof(xfer->seg[0]), GFP_ATOMIC);
@@ -733,18 +1116,35 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size)
733 goto error_segs_kzalloc; 1116 goto error_segs_kzalloc;
734 buf_itr = 0; 1117 buf_itr = 0;
735 buf_size = xfer->urb->transfer_buffer_length; 1118 buf_size = xfer->urb->transfer_buffer_length;
1119 iso_frame_offset = 0;
736 for (cnt = 0; cnt < xfer->segs; cnt++) { 1120 for (cnt = 0; cnt < xfer->segs; cnt++) {
737 seg = xfer->seg[cnt] = kmalloc(alloc_size, GFP_ATOMIC); 1121 size_t iso_pkt_descr_size = 0;
1122 int seg_isoc_frame_count = 0, seg_isoc_size = 0;
1123
1124 if (usb_pipeisoc(xfer->urb->pipe)) {
1125 seg_isoc_frame_count =
1126 __wa_seg_calculate_isoc_frame_count(xfer,
1127 xfer_isoc_frame_offset, &seg_isoc_size);
1128
1129 iso_pkt_descr_size =
1130 sizeof(struct wa_xfer_packet_info_hwaiso) +
1131 (seg_isoc_frame_count * sizeof(__le16));
1132 }
1133 seg = xfer->seg[cnt] = kmalloc(alloc_size + iso_pkt_descr_size,
1134 GFP_ATOMIC);
738 if (seg == NULL) 1135 if (seg == NULL)
739 goto error_seg_kmalloc; 1136 goto error_seg_kmalloc;
740 wa_seg_init(seg); 1137 wa_seg_init(seg);
741 seg->xfer = xfer; 1138 seg->xfer = xfer;
742 seg->index = cnt; 1139 seg->index = cnt;
743 usb_fill_bulk_urb(&seg->urb, usb_dev, 1140 seg->isoc_frame_count = seg_isoc_frame_count;
1141 seg->isoc_frame_offset = xfer_isoc_frame_offset;
1142 seg->isoc_size = seg_isoc_size;
1143 usb_fill_bulk_urb(&seg->tr_urb, usb_dev,
744 usb_sndbulkpipe(usb_dev, 1144 usb_sndbulkpipe(usb_dev,
745 dto_epd->bEndpointAddress), 1145 dto_epd->bEndpointAddress),
746 &seg->xfer_hdr, xfer_hdr_size, 1146 &seg->xfer_hdr, xfer_hdr_size,
747 wa_seg_cb, seg); 1147 wa_seg_tr_cb, seg);
748 buf_itr_size = min(buf_size, xfer->seg_size); 1148 buf_itr_size = min(buf_size, xfer->seg_size);
749 if (xfer->is_inbound == 0 && buf_size > 0) { 1149 if (xfer->is_inbound == 0 && buf_size > 0) {
750 /* outbound data. */ 1150 /* outbound data. */
@@ -756,69 +1156,64 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size)
756 usb_sndbulkpipe(usb_dev, 1156 usb_sndbulkpipe(usb_dev,
757 dto_epd->bEndpointAddress), 1157 dto_epd->bEndpointAddress),
758 NULL, 0, wa_seg_dto_cb, seg); 1158 NULL, 0, wa_seg_dto_cb, seg);
759 if (xfer->is_dma) { 1159
760 seg->dto_urb->transfer_dma = 1160 if (usb_pipeisoc(xfer->urb->pipe)) {
761 xfer->urb->transfer_dma + buf_itr; 1161 /* iso packet descriptor. */
762 seg->dto_urb->transfer_flags |= 1162 seg->isoc_pack_desc_urb =
763 URB_NO_TRANSFER_DMA_MAP; 1163 usb_alloc_urb(0, GFP_ATOMIC);
764 seg->dto_urb->transfer_buffer = NULL; 1164 if (seg->isoc_pack_desc_urb == NULL)
765 seg->dto_urb->sg = NULL; 1165 goto error_iso_pack_desc_alloc;
766 seg->dto_urb->num_sgs = 0; 1166 /*
1167 * The buffer for the isoc packet descriptor
1168 * after the transfer request header in the
1169 * segment object memory buffer.
1170 */
1171 usb_fill_bulk_urb(
1172 seg->isoc_pack_desc_urb, usb_dev,
1173 usb_sndbulkpipe(usb_dev,
1174 dto_epd->bEndpointAddress),
1175 (void *)(&seg->xfer_hdr) +
1176 xfer_hdr_size,
1177 iso_pkt_descr_size,
1178 wa_seg_iso_pack_desc_cb, seg);
1179
1180 /*
1181 * Fill in the xfer buffer information for the
1182 * first isoc frame. Subsequent frames in this
1183 * segment will be filled in and sent from the
1184 * DTO completion routine, if needed.
1185 */
1186 __wa_populate_dto_urb_isoc(xfer, seg,
1187 xfer_isoc_frame_offset);
1188 /* adjust starting frame offset for next seg. */
1189 xfer_isoc_frame_offset += seg_isoc_frame_count;
767 } else { 1190 } else {
768 /* do buffer or SG processing. */ 1191 /* fill in the xfer buffer information. */
769 seg->dto_urb->transfer_flags &= 1192 result = __wa_populate_dto_urb(xfer, seg,
770 ~URB_NO_TRANSFER_DMA_MAP; 1193 buf_itr, buf_itr_size);
771 /* this should always be 0 before a resubmit. */ 1194 if (result < 0)
772 seg->dto_urb->num_mapped_sgs = 0; 1195 goto error_seg_outbound_populate;
773 1196
774 if (xfer->urb->transfer_buffer) { 1197 buf_itr += buf_itr_size;
775 seg->dto_urb->transfer_buffer = 1198 buf_size -= buf_itr_size;
776 xfer->urb->transfer_buffer +
777 buf_itr;
778 seg->dto_urb->sg = NULL;
779 seg->dto_urb->num_sgs = 0;
780 } else {
781 /* allocate an SG list to store seg_size
782 bytes and copy the subset of the
783 xfer->urb->sg that matches the
784 buffer subset we are about to read.
785 */
786 seg->dto_urb->sg =
787 wa_xfer_create_subset_sg(
788 xfer->urb->sg,
789 buf_itr, buf_itr_size,
790 &(seg->dto_urb->num_sgs));
791
792 if (!(seg->dto_urb->sg)) {
793 seg->dto_urb->num_sgs = 0;
794 goto error_sg_alloc;
795 }
796
797 seg->dto_urb->transfer_buffer = NULL;
798 }
799 } 1199 }
800 seg->dto_urb->transfer_buffer_length = buf_itr_size;
801 } 1200 }
802 seg->status = WA_SEG_READY; 1201 seg->status = WA_SEG_READY;
803 buf_itr += buf_itr_size;
804 buf_size -= buf_itr_size;
805 } 1202 }
806 return 0; 1203 return 0;
807 1204
808error_sg_alloc: 1205 /*
1206 * Free the memory for the current segment which failed to init.
1207 * Use the fact that cnt is left at were it failed. The remaining
1208 * segments will be cleaned up by wa_xfer_destroy.
1209 */
1210error_iso_pack_desc_alloc:
1211error_seg_outbound_populate:
809 usb_free_urb(xfer->seg[cnt]->dto_urb); 1212 usb_free_urb(xfer->seg[cnt]->dto_urb);
810error_dto_alloc: 1213error_dto_alloc:
811 kfree(xfer->seg[cnt]); 1214 kfree(xfer->seg[cnt]);
812 cnt--; 1215 xfer->seg[cnt] = NULL;
813error_seg_kmalloc: 1216error_seg_kmalloc:
814 /* use the fact that cnt is left at were it failed */
815 for (; cnt >= 0; cnt--) {
816 if (xfer->seg[cnt] && xfer->is_inbound == 0) {
817 usb_free_urb(xfer->seg[cnt]->dto_urb);
818 kfree(xfer->seg[cnt]->dto_urb->sg);
819 }
820 kfree(xfer->seg[cnt]);
821 }
822error_segs_kzalloc: 1217error_segs_kzalloc:
823 return result; 1218 return result;
824} 1219}
@@ -856,21 +1251,45 @@ static int __wa_xfer_setup(struct wa_xfer *xfer, struct urb *urb)
856 wa_xfer_id_init(xfer); 1251 wa_xfer_id_init(xfer);
857 __wa_xfer_setup_hdr0(xfer, xfer_hdr0, xfer_type, xfer_hdr_size); 1252 __wa_xfer_setup_hdr0(xfer, xfer_hdr0, xfer_type, xfer_hdr_size);
858 1253
859 /* Fill remainig headers */ 1254 /* Fill remaining headers */
860 xfer_hdr = xfer_hdr0; 1255 xfer_hdr = xfer_hdr0;
861 transfer_size = urb->transfer_buffer_length; 1256 if (xfer_type == WA_XFER_TYPE_ISO) {
862 xfer_hdr0->dwTransferLength = transfer_size > xfer->seg_size ? 1257 xfer_hdr0->dwTransferLength =
863 xfer->seg_size : transfer_size; 1258 cpu_to_le32(xfer->seg[0]->isoc_size);
864 transfer_size -= xfer->seg_size; 1259 for (cnt = 1; cnt < xfer->segs; cnt++) {
865 for (cnt = 1; cnt < xfer->segs; cnt++) { 1260 struct wa_xfer_packet_info_hwaiso *packet_desc;
866 xfer_hdr = &xfer->seg[cnt]->xfer_hdr; 1261 struct wa_seg *seg = xfer->seg[cnt];
867 memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size); 1262
868 xfer_hdr->bTransferSegment = cnt; 1263 xfer_hdr = &seg->xfer_hdr;
869 xfer_hdr->dwTransferLength = transfer_size > xfer->seg_size ? 1264 packet_desc = ((void *)xfer_hdr) + xfer_hdr_size;
870 cpu_to_le32(xfer->seg_size) 1265 /*
871 : cpu_to_le32(transfer_size); 1266 * Copy values from the 0th header. Segment specific
872 xfer->seg[cnt]->status = WA_SEG_READY; 1267 * values are set below.
1268 */
1269 memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size);
1270 xfer_hdr->bTransferSegment = cnt;
1271 xfer_hdr->dwTransferLength =
1272 cpu_to_le32(seg->isoc_size);
1273 __wa_setup_isoc_packet_descr(packet_desc, xfer, seg);
1274 seg->status = WA_SEG_READY;
1275 }
1276 } else {
1277 transfer_size = urb->transfer_buffer_length;
1278 xfer_hdr0->dwTransferLength = transfer_size > xfer->seg_size ?
1279 cpu_to_le32(xfer->seg_size) :
1280 cpu_to_le32(transfer_size);
873 transfer_size -= xfer->seg_size; 1281 transfer_size -= xfer->seg_size;
1282 for (cnt = 1; cnt < xfer->segs; cnt++) {
1283 xfer_hdr = &xfer->seg[cnt]->xfer_hdr;
1284 memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size);
1285 xfer_hdr->bTransferSegment = cnt;
1286 xfer_hdr->dwTransferLength =
1287 transfer_size > xfer->seg_size ?
1288 cpu_to_le32(xfer->seg_size)
1289 : cpu_to_le32(transfer_size);
1290 xfer->seg[cnt]->status = WA_SEG_READY;
1291 transfer_size -= xfer->seg_size;
1292 }
874 } 1293 }
875 xfer_hdr->bTransferSegment |= 0x80; /* this is the last segment */ 1294 xfer_hdr->bTransferSegment |= 0x80; /* this is the last segment */
876 result = 0; 1295 result = 0;
@@ -885,20 +1304,46 @@ error_setup_sizes:
885 * rpipe->seg_lock is held! 1304 * rpipe->seg_lock is held!
886 */ 1305 */
887static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer, 1306static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer,
888 struct wa_seg *seg) 1307 struct wa_seg *seg, int *dto_done)
889{ 1308{
890 int result; 1309 int result;
891 result = usb_submit_urb(&seg->urb, GFP_ATOMIC); 1310
1311 /* default to done unless we encounter a multi-frame isoc segment. */
1312 *dto_done = 1;
1313
1314 /* submit the transfer request. */
1315 result = usb_submit_urb(&seg->tr_urb, GFP_ATOMIC);
892 if (result < 0) { 1316 if (result < 0) {
893 printk(KERN_ERR "xfer %p#%u: REQ submit failed: %d\n", 1317 pr_err("%s: xfer %p#%u: REQ submit failed: %d\n",
894 xfer, seg->index, result); 1318 __func__, xfer, seg->index, result);
895 goto error_seg_submit; 1319 goto error_seg_submit;
896 } 1320 }
1321 /* submit the isoc packet descriptor if present. */
1322 if (seg->isoc_pack_desc_urb) {
1323 struct wahc *wa = xfer->wa;
1324
1325 result = usb_submit_urb(seg->isoc_pack_desc_urb, GFP_ATOMIC);
1326 if (result < 0) {
1327 pr_err("%s: xfer %p#%u: ISO packet descriptor submit failed: %d\n",
1328 __func__, xfer, seg->index, result);
1329 goto error_iso_pack_desc_submit;
1330 }
1331 xfer->dto_isoc_frame_index = 0;
1332 /*
1333 * If this segment contains more than one isoc frame, hold
1334 * onto the dto resource until we send all frames.
1335 * Only applies to non-Alereon devices.
1336 */
1337 if (((wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) == 0)
1338 && (seg->isoc_frame_count > 1))
1339 *dto_done = 0;
1340 }
1341 /* submit the out data if this is an out request. */
897 if (seg->dto_urb) { 1342 if (seg->dto_urb) {
898 result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); 1343 result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC);
899 if (result < 0) { 1344 if (result < 0) {
900 printk(KERN_ERR "xfer %p#%u: DTO submit failed: %d\n", 1345 pr_err("%s: xfer %p#%u: DTO submit failed: %d\n",
901 xfer, seg->index, result); 1346 __func__, xfer, seg->index, result);
902 goto error_dto_submit; 1347 goto error_dto_submit;
903 } 1348 }
904 } 1349 }
@@ -907,38 +1352,48 @@ static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer,
907 return 0; 1352 return 0;
908 1353
909error_dto_submit: 1354error_dto_submit:
910 usb_unlink_urb(&seg->urb); 1355 usb_unlink_urb(seg->isoc_pack_desc_urb);
1356error_iso_pack_desc_submit:
1357 usb_unlink_urb(&seg->tr_urb);
911error_seg_submit: 1358error_seg_submit:
912 seg->status = WA_SEG_ERROR; 1359 seg->status = WA_SEG_ERROR;
913 seg->result = result; 1360 seg->result = result;
1361 *dto_done = 1;
914 return result; 1362 return result;
915} 1363}
916 1364
917/* 1365/*
918 * Execute more queued request segments until the maximum concurrent allowed 1366 * Execute more queued request segments until the maximum concurrent allowed.
1367 * Return true if the DTO resource was acquired and released.
919 * 1368 *
920 * The ugly unlock/lock sequence on the error path is needed as the 1369 * The ugly unlock/lock sequence on the error path is needed as the
921 * xfer->lock normally nests the seg_lock and not viceversa. 1370 * xfer->lock normally nests the seg_lock and not viceversa.
922 *
923 */ 1371 */
924static void wa_xfer_delayed_run(struct wa_rpipe *rpipe) 1372static int __wa_xfer_delayed_run(struct wa_rpipe *rpipe, int *dto_waiting)
925{ 1373{
926 int result; 1374 int result, dto_acquired = 0, dto_done = 0;
927 struct device *dev = &rpipe->wa->usb_iface->dev; 1375 struct device *dev = &rpipe->wa->usb_iface->dev;
928 struct wa_seg *seg; 1376 struct wa_seg *seg;
929 struct wa_xfer *xfer; 1377 struct wa_xfer *xfer;
930 unsigned long flags; 1378 unsigned long flags;
931 1379
1380 *dto_waiting = 0;
1381
932 spin_lock_irqsave(&rpipe->seg_lock, flags); 1382 spin_lock_irqsave(&rpipe->seg_lock, flags);
933 while (atomic_read(&rpipe->segs_available) > 0 1383 while (atomic_read(&rpipe->segs_available) > 0
934 && !list_empty(&rpipe->seg_list)) { 1384 && !list_empty(&rpipe->seg_list)
1385 && (dto_acquired = __wa_dto_try_get(rpipe->wa))) {
935 seg = list_first_entry(&(rpipe->seg_list), struct wa_seg, 1386 seg = list_first_entry(&(rpipe->seg_list), struct wa_seg,
936 list_node); 1387 list_node);
937 list_del(&seg->list_node); 1388 list_del(&seg->list_node);
938 xfer = seg->xfer; 1389 xfer = seg->xfer;
939 result = __wa_seg_submit(rpipe, xfer, seg); 1390 result = __wa_seg_submit(rpipe, xfer, seg, &dto_done);
940 dev_dbg(dev, "xfer %p#%u submitted from delayed [%d segments available] %d\n", 1391 /* release the dto resource if this RPIPE is done with it. */
941 xfer, seg->index, atomic_read(&rpipe->segs_available), result); 1392 if (dto_done)
1393 __wa_dto_put(rpipe->wa);
1394 dev_dbg(dev, "xfer %p ID %08X#%u submitted from delayed [%d segments available] %d\n",
1395 xfer, wa_xfer_id(xfer), seg->index,
1396 atomic_read(&rpipe->segs_available), result);
942 if (unlikely(result < 0)) { 1397 if (unlikely(result < 0)) {
943 spin_unlock_irqrestore(&rpipe->seg_lock, flags); 1398 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
944 spin_lock_irqsave(&xfer->lock, flags); 1399 spin_lock_irqsave(&xfer->lock, flags);
@@ -948,7 +1403,37 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
948 spin_lock_irqsave(&rpipe->seg_lock, flags); 1403 spin_lock_irqsave(&rpipe->seg_lock, flags);
949 } 1404 }
950 } 1405 }
1406 /*
1407 * Mark this RPIPE as waiting if dto was not acquired, there are
1408 * delayed segs and no active transfers to wake us up later.
1409 */
1410 if (!dto_acquired && !list_empty(&rpipe->seg_list)
1411 && (atomic_read(&rpipe->segs_available) ==
1412 le16_to_cpu(rpipe->descr.wRequests)))
1413 *dto_waiting = 1;
1414
951 spin_unlock_irqrestore(&rpipe->seg_lock, flags); 1415 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
1416
1417 return dto_done;
1418}
1419
1420static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
1421{
1422 int dto_waiting;
1423 int dto_done = __wa_xfer_delayed_run(rpipe, &dto_waiting);
1424
1425 /*
1426 * If this RPIPE is waiting on the DTO resource, add it to the tail of
1427 * the waiting list.
1428 * Otherwise, if the WA DTO resource was acquired and released by
1429 * __wa_xfer_delayed_run, another RPIPE may have attempted to acquire
1430 * DTO and failed during that time. Check the delayed list and process
1431 * any waiters. Start searching from the next RPIPE index.
1432 */
1433 if (dto_waiting)
1434 wa_add_delayed_rpipe(rpipe->wa, rpipe);
1435 else if (dto_done)
1436 wa_check_for_delayed_rpipes(rpipe->wa);
952} 1437}
953 1438
954/* 1439/*
@@ -960,7 +1445,7 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
960 */ 1445 */
961static int __wa_xfer_submit(struct wa_xfer *xfer) 1446static int __wa_xfer_submit(struct wa_xfer *xfer)
962{ 1447{
963 int result; 1448 int result, dto_acquired = 0, dto_done = 0, dto_waiting = 0;
964 struct wahc *wa = xfer->wa; 1449 struct wahc *wa = xfer->wa;
965 struct device *dev = &wa->usb_iface->dev; 1450 struct device *dev = &wa->usb_iface->dev;
966 unsigned cnt; 1451 unsigned cnt;
@@ -979,27 +1464,58 @@ static int __wa_xfer_submit(struct wa_xfer *xfer)
979 result = 0; 1464 result = 0;
980 spin_lock_irqsave(&rpipe->seg_lock, flags); 1465 spin_lock_irqsave(&rpipe->seg_lock, flags);
981 for (cnt = 0; cnt < xfer->segs; cnt++) { 1466 for (cnt = 0; cnt < xfer->segs; cnt++) {
1467 int delay_seg = 1;
1468
982 available = atomic_read(&rpipe->segs_available); 1469 available = atomic_read(&rpipe->segs_available);
983 empty = list_empty(&rpipe->seg_list); 1470 empty = list_empty(&rpipe->seg_list);
984 seg = xfer->seg[cnt]; 1471 seg = xfer->seg[cnt];
985 dev_dbg(dev, "xfer %p#%u: available %u empty %u (%s)\n", 1472 if (available && empty) {
986 xfer, cnt, available, empty, 1473 /*
987 available == 0 || !empty ? "delayed" : "submitted"); 1474 * Only attempt to acquire DTO if we have a segment
988 if (available == 0 || !empty) { 1475 * to send.
989 dev_dbg(dev, "xfer %p#%u: delayed\n", xfer, cnt); 1476 */
1477 dto_acquired = __wa_dto_try_get(rpipe->wa);
1478 if (dto_acquired) {
1479 delay_seg = 0;
1480 result = __wa_seg_submit(rpipe, xfer, seg,
1481 &dto_done);
1482 dev_dbg(dev, "xfer %p ID 0x%08X#%u: available %u empty %u submitted\n",
1483 xfer, wa_xfer_id(xfer), cnt, available,
1484 empty);
1485 if (dto_done)
1486 __wa_dto_put(rpipe->wa);
1487
1488 if (result < 0) {
1489 __wa_xfer_abort(xfer);
1490 goto error_seg_submit;
1491 }
1492 }
1493 }
1494
1495 if (delay_seg) {
1496 dev_dbg(dev, "xfer %p ID 0x%08X#%u: available %u empty %u delayed\n",
1497 xfer, wa_xfer_id(xfer), cnt, available, empty);
990 seg->status = WA_SEG_DELAYED; 1498 seg->status = WA_SEG_DELAYED;
991 list_add_tail(&seg->list_node, &rpipe->seg_list); 1499 list_add_tail(&seg->list_node, &rpipe->seg_list);
992 } else {
993 result = __wa_seg_submit(rpipe, xfer, seg);
994 if (result < 0) {
995 __wa_xfer_abort(xfer);
996 goto error_seg_submit;
997 }
998 } 1500 }
999 xfer->segs_submitted++; 1501 xfer->segs_submitted++;
1000 } 1502 }
1001error_seg_submit: 1503error_seg_submit:
1504 /*
1505 * Mark this RPIPE as waiting if dto was not acquired, there are
1506 * delayed segs and no active transfers to wake us up later.
1507 */
1508 if (!dto_acquired && !list_empty(&rpipe->seg_list)
1509 && (atomic_read(&rpipe->segs_available) ==
1510 le16_to_cpu(rpipe->descr.wRequests)))
1511 dto_waiting = 1;
1002 spin_unlock_irqrestore(&rpipe->seg_lock, flags); 1512 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
1513
1514 if (dto_waiting)
1515 wa_add_delayed_rpipe(rpipe->wa, rpipe);
1516 else if (dto_done)
1517 wa_check_for_delayed_rpipes(rpipe->wa);
1518
1003 return result; 1519 return result;
1004} 1520}
1005 1521
@@ -1025,7 +1541,7 @@ error_seg_submit:
1025 * result never kicks in, the xfer will timeout from the USB code and 1541 * result never kicks in, the xfer will timeout from the USB code and
1026 * dequeue() will be called. 1542 * dequeue() will be called.
1027 */ 1543 */
1028static void wa_urb_enqueue_b(struct wa_xfer *xfer) 1544static int wa_urb_enqueue_b(struct wa_xfer *xfer)
1029{ 1545{
1030 int result; 1546 int result;
1031 unsigned long flags; 1547 unsigned long flags;
@@ -1036,18 +1552,22 @@ static void wa_urb_enqueue_b(struct wa_xfer *xfer)
1036 unsigned done; 1552 unsigned done;
1037 1553
1038 result = rpipe_get_by_ep(wa, xfer->ep, urb, xfer->gfp); 1554 result = rpipe_get_by_ep(wa, xfer->ep, urb, xfer->gfp);
1039 if (result < 0) 1555 if (result < 0) {
1556 pr_err("%s: error_rpipe_get\n", __func__);
1040 goto error_rpipe_get; 1557 goto error_rpipe_get;
1558 }
1041 result = -ENODEV; 1559 result = -ENODEV;
1042 /* FIXME: segmentation broken -- kills DWA */ 1560 /* FIXME: segmentation broken -- kills DWA */
1043 mutex_lock(&wusbhc->mutex); /* get a WUSB dev */ 1561 mutex_lock(&wusbhc->mutex); /* get a WUSB dev */
1044 if (urb->dev == NULL) { 1562 if (urb->dev == NULL) {
1045 mutex_unlock(&wusbhc->mutex); 1563 mutex_unlock(&wusbhc->mutex);
1564 pr_err("%s: error usb dev gone\n", __func__);
1046 goto error_dev_gone; 1565 goto error_dev_gone;
1047 } 1566 }
1048 wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev); 1567 wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev);
1049 if (wusb_dev == NULL) { 1568 if (wusb_dev == NULL) {
1050 mutex_unlock(&wusbhc->mutex); 1569 mutex_unlock(&wusbhc->mutex);
1570 pr_err("%s: error wusb dev gone\n", __func__);
1051 goto error_dev_gone; 1571 goto error_dev_gone;
1052 } 1572 }
1053 mutex_unlock(&wusbhc->mutex); 1573 mutex_unlock(&wusbhc->mutex);
@@ -1055,21 +1575,28 @@ static void wa_urb_enqueue_b(struct wa_xfer *xfer)
1055 spin_lock_irqsave(&xfer->lock, flags); 1575 spin_lock_irqsave(&xfer->lock, flags);
1056 xfer->wusb_dev = wusb_dev; 1576 xfer->wusb_dev = wusb_dev;
1057 result = urb->status; 1577 result = urb->status;
1058 if (urb->status != -EINPROGRESS) 1578 if (urb->status != -EINPROGRESS) {
1579 pr_err("%s: error_dequeued\n", __func__);
1059 goto error_dequeued; 1580 goto error_dequeued;
1581 }
1060 1582
1061 result = __wa_xfer_setup(xfer, urb); 1583 result = __wa_xfer_setup(xfer, urb);
1062 if (result < 0) 1584 if (result < 0) {
1585 pr_err("%s: error_xfer_setup\n", __func__);
1063 goto error_xfer_setup; 1586 goto error_xfer_setup;
1587 }
1064 result = __wa_xfer_submit(xfer); 1588 result = __wa_xfer_submit(xfer);
1065 if (result < 0) 1589 if (result < 0) {
1590 pr_err("%s: error_xfer_submit\n", __func__);
1066 goto error_xfer_submit; 1591 goto error_xfer_submit;
1592 }
1067 spin_unlock_irqrestore(&xfer->lock, flags); 1593 spin_unlock_irqrestore(&xfer->lock, flags);
1068 return; 1594 return 0;
1069 1595
1070 /* this is basically wa_xfer_completion() broken up wa_xfer_giveback() 1596 /*
1071 * does a wa_xfer_put() that will call wa_xfer_destroy() and clean 1597 * this is basically wa_xfer_completion() broken up wa_xfer_giveback()
1072 * upundo setup(). 1598 * does a wa_xfer_put() that will call wa_xfer_destroy() and undo
1599 * setup().
1073 */ 1600 */
1074error_xfer_setup: 1601error_xfer_setup:
1075error_dequeued: 1602error_dequeued:
@@ -1081,8 +1608,7 @@ error_dev_gone:
1081 rpipe_put(xfer->ep->hcpriv); 1608 rpipe_put(xfer->ep->hcpriv);
1082error_rpipe_get: 1609error_rpipe_get:
1083 xfer->result = result; 1610 xfer->result = result;
1084 wa_xfer_giveback(xfer); 1611 return result;
1085 return;
1086 1612
1087error_xfer_submit: 1613error_xfer_submit:
1088 done = __wa_xfer_is_done(xfer); 1614 done = __wa_xfer_is_done(xfer);
@@ -1090,6 +1616,8 @@ error_xfer_submit:
1090 spin_unlock_irqrestore(&xfer->lock, flags); 1616 spin_unlock_irqrestore(&xfer->lock, flags);
1091 if (done) 1617 if (done)
1092 wa_xfer_completion(xfer); 1618 wa_xfer_completion(xfer);
1619 /* return success since the completion routine will run. */
1620 return 0;
1093} 1621}
1094 1622
1095/* 1623/*
@@ -1123,7 +1651,8 @@ void wa_urb_enqueue_run(struct work_struct *ws)
1123 list_del_init(&xfer->list_node); 1651 list_del_init(&xfer->list_node);
1124 1652
1125 urb = xfer->urb; 1653 urb = xfer->urb;
1126 wa_urb_enqueue_b(xfer); 1654 if (wa_urb_enqueue_b(xfer) < 0)
1655 wa_xfer_giveback(xfer);
1127 usb_put_urb(urb); /* taken when queuing */ 1656 usb_put_urb(urb); /* taken when queuing */
1128 } 1657 }
1129} 1658}
@@ -1229,7 +1758,19 @@ int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep,
1229 spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); 1758 spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags);
1230 queue_work(wusbd, &wa->xfer_enqueue_work); 1759 queue_work(wusbd, &wa->xfer_enqueue_work);
1231 } else { 1760 } else {
1232 wa_urb_enqueue_b(xfer); 1761 result = wa_urb_enqueue_b(xfer);
1762 if (result < 0) {
1763 /*
1764 * URB submit/enqueue failed. Clean up, return an
1765 * error and do not run the callback. This avoids
1766 * an infinite submit/complete loop.
1767 */
1768 dev_err(dev, "%s: URB enqueue failed: %d\n",
1769 __func__, result);
1770 wa_put(xfer->wa);
1771 wa_xfer_put(xfer);
1772 return result;
1773 }
1233 } 1774 }
1234 return 0; 1775 return 0;
1235 1776
@@ -1264,7 +1805,7 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1264 struct wa_xfer *xfer; 1805 struct wa_xfer *xfer;
1265 struct wa_seg *seg; 1806 struct wa_seg *seg;
1266 struct wa_rpipe *rpipe; 1807 struct wa_rpipe *rpipe;
1267 unsigned cnt; 1808 unsigned cnt, done = 0, xfer_abort_pending;
1268 unsigned rpipe_ready = 0; 1809 unsigned rpipe_ready = 0;
1269 1810
1270 xfer = urb->hcpriv; 1811 xfer = urb->hcpriv;
@@ -1278,6 +1819,7 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1278 goto out; 1819 goto out;
1279 } 1820 }
1280 spin_lock_irqsave(&xfer->lock, flags); 1821 spin_lock_irqsave(&xfer->lock, flags);
1822 pr_debug("%s: DEQUEUE xfer id 0x%08X\n", __func__, wa_xfer_id(xfer));
1281 rpipe = xfer->ep->hcpriv; 1823 rpipe = xfer->ep->hcpriv;
1282 if (rpipe == NULL) { 1824 if (rpipe == NULL) {
1283 pr_debug("%s: xfer id 0x%08X has no RPIPE. %s", 1825 pr_debug("%s: xfer id 0x%08X has no RPIPE. %s",
@@ -1293,9 +1835,11 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1293 if (xfer->seg == NULL) /* still hasn't reached */ 1835 if (xfer->seg == NULL) /* still hasn't reached */
1294 goto out_unlock; /* setup(), enqueue_b() completes */ 1836 goto out_unlock; /* setup(), enqueue_b() completes */
1295 /* Ok, the xfer is in flight already, it's been setup and submitted.*/ 1837 /* Ok, the xfer is in flight already, it's been setup and submitted.*/
1296 __wa_xfer_abort(xfer); 1838 xfer_abort_pending = __wa_xfer_abort(xfer) >= 0;
1297 for (cnt = 0; cnt < xfer->segs; cnt++) { 1839 for (cnt = 0; cnt < xfer->segs; cnt++) {
1298 seg = xfer->seg[cnt]; 1840 seg = xfer->seg[cnt];
1841 pr_debug("%s: xfer id 0x%08X#%d status = %d\n",
1842 __func__, wa_xfer_id(xfer), cnt, seg->status);
1299 switch (seg->status) { 1843 switch (seg->status) {
1300 case WA_SEG_NOTREADY: 1844 case WA_SEG_NOTREADY:
1301 case WA_SEG_READY: 1845 case WA_SEG_READY:
@@ -1304,42 +1848,50 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1304 WARN_ON(1); 1848 WARN_ON(1);
1305 break; 1849 break;
1306 case WA_SEG_DELAYED: 1850 case WA_SEG_DELAYED:
1851 /*
1852 * delete from rpipe delayed list. If no segments on
1853 * this xfer have been submitted, __wa_xfer_is_done will
1854 * trigger a giveback below. Otherwise, the submitted
1855 * segments will be completed in the DTI interrupt.
1856 */
1307 seg->status = WA_SEG_ABORTED; 1857 seg->status = WA_SEG_ABORTED;
1308 spin_lock_irqsave(&rpipe->seg_lock, flags2); 1858 spin_lock_irqsave(&rpipe->seg_lock, flags2);
1309 list_del(&seg->list_node); 1859 list_del(&seg->list_node);
1310 xfer->segs_done++; 1860 xfer->segs_done++;
1311 rpipe_ready = rpipe_avail_inc(rpipe);
1312 spin_unlock_irqrestore(&rpipe->seg_lock, flags2); 1861 spin_unlock_irqrestore(&rpipe->seg_lock, flags2);
1313 break; 1862 break;
1314 case WA_SEG_SUBMITTED:
1315 seg->status = WA_SEG_ABORTED;
1316 usb_unlink_urb(&seg->urb);
1317 if (xfer->is_inbound == 0)
1318 usb_unlink_urb(seg->dto_urb);
1319 xfer->segs_done++;
1320 rpipe_ready = rpipe_avail_inc(rpipe);
1321 break;
1322 case WA_SEG_PENDING:
1323 seg->status = WA_SEG_ABORTED;
1324 xfer->segs_done++;
1325 rpipe_ready = rpipe_avail_inc(rpipe);
1326 break;
1327 case WA_SEG_DTI_PENDING:
1328 usb_unlink_urb(wa->dti_urb);
1329 seg->status = WA_SEG_ABORTED;
1330 xfer->segs_done++;
1331 rpipe_ready = rpipe_avail_inc(rpipe);
1332 break;
1333 case WA_SEG_DONE: 1863 case WA_SEG_DONE:
1334 case WA_SEG_ERROR: 1864 case WA_SEG_ERROR:
1335 case WA_SEG_ABORTED: 1865 case WA_SEG_ABORTED:
1336 break; 1866 break;
1867 /*
1868 * In the states below, the HWA device already knows
1869 * about the transfer. If an abort request was sent,
1870 * allow the HWA to process it and wait for the
1871 * results. Otherwise, the DTI state and seg completed
1872 * counts can get out of sync.
1873 */
1874 case WA_SEG_SUBMITTED:
1875 case WA_SEG_PENDING:
1876 case WA_SEG_DTI_PENDING:
1877 /*
1878 * Check if the abort was successfully sent. This could
1879 * be false if the HWA has been removed but we haven't
1880 * gotten the disconnect notification yet.
1881 */
1882 if (!xfer_abort_pending) {
1883 seg->status = WA_SEG_ABORTED;
1884 rpipe_ready = rpipe_avail_inc(rpipe);
1885 xfer->segs_done++;
1886 }
1887 break;
1337 } 1888 }
1338 } 1889 }
1339 xfer->result = urb->status; /* -ENOENT or -ECONNRESET */ 1890 xfer->result = urb->status; /* -ENOENT or -ECONNRESET */
1340 __wa_xfer_is_done(xfer); 1891 done = __wa_xfer_is_done(xfer);
1341 spin_unlock_irqrestore(&xfer->lock, flags); 1892 spin_unlock_irqrestore(&xfer->lock, flags);
1342 wa_xfer_completion(xfer); 1893 if (done)
1894 wa_xfer_completion(xfer);
1343 if (rpipe_ready) 1895 if (rpipe_ready)
1344 wa_xfer_delayed_run(rpipe); 1896 wa_xfer_delayed_run(rpipe);
1345 return 0; 1897 return 0;
@@ -1410,13 +1962,56 @@ static int wa_xfer_status_to_errno(u8 status)
1410} 1962}
1411 1963
1412/* 1964/*
1965 * If a last segment flag and/or a transfer result error is encountered,
1966 * no other segment transfer results will be returned from the device.
1967 * Mark the remaining submitted or pending xfers as completed so that
1968 * the xfer will complete cleanly.
1969 */
1970static void wa_complete_remaining_xfer_segs(struct wa_xfer *xfer,
1971 struct wa_seg *incoming_seg)
1972{
1973 int index;
1974 struct wa_rpipe *rpipe = xfer->ep->hcpriv;
1975
1976 for (index = incoming_seg->index + 1; index < xfer->segs_submitted;
1977 index++) {
1978 struct wa_seg *current_seg = xfer->seg[index];
1979
1980 BUG_ON(current_seg == NULL);
1981
1982 switch (current_seg->status) {
1983 case WA_SEG_SUBMITTED:
1984 case WA_SEG_PENDING:
1985 case WA_SEG_DTI_PENDING:
1986 rpipe_avail_inc(rpipe);
1987 /*
1988 * do not increment RPIPE avail for the WA_SEG_DELAYED case
1989 * since it has not been submitted to the RPIPE.
1990 */
1991 case WA_SEG_DELAYED:
1992 xfer->segs_done++;
1993 current_seg->status = incoming_seg->status;
1994 break;
1995 case WA_SEG_ABORTED:
1996 break;
1997 default:
1998 WARN(1, "%s: xfer 0x%08X#%d. bad seg status = %d\n",
1999 __func__, wa_xfer_id(xfer), index,
2000 current_seg->status);
2001 break;
2002 }
2003 }
2004}
2005
2006/*
1413 * Process a xfer result completion message 2007 * Process a xfer result completion message
1414 * 2008 *
1415 * inbound transfers: need to schedule a DTI read 2009 * inbound transfers: need to schedule a buf_in_urb read
1416 * 2010 *
1417 * FIXME: this function needs to be broken up in parts 2011 * FIXME: this function needs to be broken up in parts
1418 */ 2012 */
1419static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer) 2013static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer,
2014 struct wa_xfer_result *xfer_result)
1420{ 2015{
1421 int result; 2016 int result;
1422 struct device *dev = &wa->usb_iface->dev; 2017 struct device *dev = &wa->usb_iface->dev;
@@ -1424,8 +2019,7 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
1424 u8 seg_idx; 2019 u8 seg_idx;
1425 struct wa_seg *seg; 2020 struct wa_seg *seg;
1426 struct wa_rpipe *rpipe; 2021 struct wa_rpipe *rpipe;
1427 struct wa_xfer_result *xfer_result = wa->xfer_result; 2022 unsigned done = 0;
1428 u8 done = 0;
1429 u8 usb_status; 2023 u8 usb_status;
1430 unsigned rpipe_ready = 0; 2024 unsigned rpipe_ready = 0;
1431 2025
@@ -1436,8 +2030,8 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
1436 seg = xfer->seg[seg_idx]; 2030 seg = xfer->seg[seg_idx];
1437 rpipe = xfer->ep->hcpriv; 2031 rpipe = xfer->ep->hcpriv;
1438 usb_status = xfer_result->bTransferStatus; 2032 usb_status = xfer_result->bTransferStatus;
1439 dev_dbg(dev, "xfer %p#%u: bTransferStatus 0x%02x (seg status %u)\n", 2033 dev_dbg(dev, "xfer %p ID 0x%08X#%u: bTransferStatus 0x%02x (seg status %u)\n",
1440 xfer, seg_idx, usb_status, seg->status); 2034 xfer, wa_xfer_id(xfer), seg_idx, usb_status, seg->status);
1441 if (seg->status == WA_SEG_ABORTED 2035 if (seg->status == WA_SEG_ABORTED
1442 || seg->status == WA_SEG_ERROR) /* already handled */ 2036 || seg->status == WA_SEG_ERROR) /* already handled */
1443 goto segment_aborted; 2037 goto segment_aborted;
@@ -1453,12 +2047,19 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
1453 seg->result = wa_xfer_status_to_errno(usb_status); 2047 seg->result = wa_xfer_status_to_errno(usb_status);
1454 dev_err(dev, "DTI: xfer %p#:%08X:%u failed (0x%02x)\n", 2048 dev_err(dev, "DTI: xfer %p#:%08X:%u failed (0x%02x)\n",
1455 xfer, xfer->id, seg->index, usb_status); 2049 xfer, xfer->id, seg->index, usb_status);
2050 seg->status = ((usb_status & 0x7F) == WA_XFER_STATUS_ABORTED) ?
2051 WA_SEG_ABORTED : WA_SEG_ERROR;
1456 goto error_complete; 2052 goto error_complete;
1457 } 2053 }
1458 /* FIXME: we ignore warnings, tally them for stats */ 2054 /* FIXME: we ignore warnings, tally them for stats */
1459 if (usb_status & 0x40) /* Warning?... */ 2055 if (usb_status & 0x40) /* Warning?... */
1460 usb_status = 0; /* ... pass */ 2056 usb_status = 0; /* ... pass */
1461 if (xfer->is_inbound) { /* IN data phase: read to buffer */ 2057 if (usb_pipeisoc(xfer->urb->pipe)) {
2058 /* set up WA state to read the isoc packet status next. */
2059 wa->dti_isoc_xfer_in_progress = wa_xfer_id(xfer);
2060 wa->dti_isoc_xfer_seg = seg_idx;
2061 wa->dti_state = WA_DTI_ISOC_PACKET_STATUS_PENDING;
2062 } else if (xfer->is_inbound) { /* IN data phase: read to buffer */
1462 seg->status = WA_SEG_DTI_PENDING; 2063 seg->status = WA_SEG_DTI_PENDING;
1463 BUG_ON(wa->buf_in_urb->status == -EINPROGRESS); 2064 BUG_ON(wa->buf_in_urb->status == -EINPROGRESS);
1464 /* this should always be 0 before a resubmit. */ 2065 /* this should always be 0 before a resubmit. */
@@ -1535,12 +2136,14 @@ error_submit_buf_in:
1535 xfer, seg_idx, result); 2136 xfer, seg_idx, result);
1536 seg->result = result; 2137 seg->result = result;
1537 kfree(wa->buf_in_urb->sg); 2138 kfree(wa->buf_in_urb->sg);
2139 wa->buf_in_urb->sg = NULL;
1538error_sg_alloc: 2140error_sg_alloc:
1539 __wa_xfer_abort(xfer); 2141 __wa_xfer_abort(xfer);
1540error_complete:
1541 seg->status = WA_SEG_ERROR; 2142 seg->status = WA_SEG_ERROR;
2143error_complete:
1542 xfer->segs_done++; 2144 xfer->segs_done++;
1543 rpipe_ready = rpipe_avail_inc(rpipe); 2145 rpipe_ready = rpipe_avail_inc(rpipe);
2146 wa_complete_remaining_xfer_segs(xfer, seg);
1544 done = __wa_xfer_is_done(xfer); 2147 done = __wa_xfer_is_done(xfer);
1545 /* 2148 /*
1546 * queue work item to clear STALL for control endpoints. 2149 * queue work item to clear STALL for control endpoints.
@@ -1552,10 +2155,8 @@ error_complete:
1552 2155
1553 dev_info(dev, "Control EP stall. Queue delayed work.\n"); 2156 dev_info(dev, "Control EP stall. Queue delayed work.\n");
1554 spin_lock_irq(&wa->xfer_list_lock); 2157 spin_lock_irq(&wa->xfer_list_lock);
1555 /* remove xfer from xfer_list. */ 2158 /* move xfer from xfer_list to xfer_errored_list. */
1556 list_del(&xfer->list_node); 2159 list_move_tail(&xfer->list_node, &wa->xfer_errored_list);
1557 /* add xfer to xfer_errored_list. */
1558 list_add_tail(&xfer->list_node, &wa->xfer_errored_list);
1559 spin_unlock_irq(&wa->xfer_list_lock); 2160 spin_unlock_irq(&wa->xfer_list_lock);
1560 spin_unlock_irqrestore(&xfer->lock, flags); 2161 spin_unlock_irqrestore(&xfer->lock, flags);
1561 queue_work(wusbd, &wa->xfer_error_work); 2162 queue_work(wusbd, &wa->xfer_error_work);
@@ -1587,6 +2188,90 @@ segment_aborted:
1587} 2188}
1588 2189
1589/* 2190/*
2191 * Process a isochronous packet status message
2192 *
2193 * inbound transfers: need to schedule a buf_in_urb read
2194 */
2195static void wa_process_iso_packet_status(struct wahc *wa, struct urb *urb)
2196{
2197 struct device *dev = &wa->usb_iface->dev;
2198 struct wa_xfer_packet_status_hwaiso *packet_status;
2199 struct wa_xfer_packet_status_len_hwaiso *status_array;
2200 struct wa_xfer *xfer;
2201 unsigned long flags;
2202 struct wa_seg *seg;
2203 struct wa_rpipe *rpipe;
2204 unsigned done = 0;
2205 unsigned rpipe_ready = 0, seg_index;
2206 int expected_size;
2207
2208 /* We have a xfer result buffer; check it */
2209 dev_dbg(dev, "DTI: isoc packet status %d bytes at %p\n",
2210 urb->actual_length, urb->transfer_buffer);
2211 packet_status = (struct wa_xfer_packet_status_hwaiso *)(wa->dti_buf);
2212 if (packet_status->bPacketType != WA_XFER_ISO_PACKET_STATUS) {
2213 dev_err(dev, "DTI Error: isoc packet status--bad type 0x%02x\n",
2214 packet_status->bPacketType);
2215 goto error_parse_buffer;
2216 }
2217 xfer = wa_xfer_get_by_id(wa, wa->dti_isoc_xfer_in_progress);
2218 if (xfer == NULL) {
2219 dev_err(dev, "DTI Error: isoc packet status--unknown xfer 0x%08x\n",
2220 wa->dti_isoc_xfer_in_progress);
2221 goto error_parse_buffer;
2222 }
2223 spin_lock_irqsave(&xfer->lock, flags);
2224 if (unlikely(wa->dti_isoc_xfer_seg >= xfer->segs))
2225 goto error_bad_seg;
2226 seg = xfer->seg[wa->dti_isoc_xfer_seg];
2227 rpipe = xfer->ep->hcpriv;
2228 expected_size = sizeof(*packet_status) +
2229 (sizeof(packet_status->PacketStatus[0]) *
2230 seg->isoc_frame_count);
2231 if (urb->actual_length != expected_size) {
2232 dev_err(dev, "DTI Error: isoc packet status--bad urb length (%d bytes vs %d needed)\n",
2233 urb->actual_length, expected_size);
2234 goto error_bad_seg;
2235 }
2236 if (le16_to_cpu(packet_status->wLength) != expected_size) {
2237 dev_err(dev, "DTI Error: isoc packet status--bad length %u\n",
2238 le16_to_cpu(packet_status->wLength));
2239 goto error_bad_seg;
2240 }
2241 /* isoc packet status and lengths back xfer urb. */
2242 status_array = packet_status->PacketStatus;
2243 for (seg_index = 0; seg_index < seg->isoc_frame_count; ++seg_index) {
2244 xfer->urb->iso_frame_desc[seg->index].status =
2245 wa_xfer_status_to_errno(
2246 le16_to_cpu(status_array[seg_index].PacketStatus));
2247 xfer->urb->iso_frame_desc[seg->index].actual_length =
2248 le16_to_cpu(status_array[seg_index].PacketLength);
2249 }
2250
2251 if (!xfer->is_inbound) {
2252 /* OUT transfer, complete it -- */
2253 seg->status = WA_SEG_DONE;
2254 xfer->segs_done++;
2255 rpipe_ready = rpipe_avail_inc(rpipe);
2256 done = __wa_xfer_is_done(xfer);
2257 }
2258 spin_unlock_irqrestore(&xfer->lock, flags);
2259 wa->dti_state = WA_DTI_TRANSFER_RESULT_PENDING;
2260 if (done)
2261 wa_xfer_completion(xfer);
2262 if (rpipe_ready)
2263 wa_xfer_delayed_run(rpipe);
2264 wa_xfer_put(xfer);
2265 return;
2266
2267error_bad_seg:
2268 spin_unlock_irqrestore(&xfer->lock, flags);
2269 wa_xfer_put(xfer);
2270error_parse_buffer:
2271 return;
2272}
2273
2274/*
1590 * Callback for the IN data phase 2275 * Callback for the IN data phase
1591 * 2276 *
1592 * If successful transition state; otherwise, take a note of the 2277 * If successful transition state; otherwise, take a note of the
@@ -1687,56 +2372,61 @@ static void wa_buf_in_cb(struct urb *urb)
1687 * We go back to OFF when we detect a ENOENT or ESHUTDOWN (or too many 2372 * We go back to OFF when we detect a ENOENT or ESHUTDOWN (or too many
1688 * errors) in the URBs. 2373 * errors) in the URBs.
1689 */ 2374 */
1690static void wa_xfer_result_cb(struct urb *urb) 2375static void wa_dti_cb(struct urb *urb)
1691{ 2376{
1692 int result; 2377 int result;
1693 struct wahc *wa = urb->context; 2378 struct wahc *wa = urb->context;
1694 struct device *dev = &wa->usb_iface->dev; 2379 struct device *dev = &wa->usb_iface->dev;
1695 struct wa_xfer_result *xfer_result;
1696 u32 xfer_id; 2380 u32 xfer_id;
1697 struct wa_xfer *xfer;
1698 u8 usb_status; 2381 u8 usb_status;
1699 2382
1700 BUG_ON(wa->dti_urb != urb); 2383 BUG_ON(wa->dti_urb != urb);
1701 switch (wa->dti_urb->status) { 2384 switch (wa->dti_urb->status) {
1702 case 0: 2385 case 0:
1703 /* We have a xfer result buffer; check it */ 2386 if (wa->dti_state == WA_DTI_TRANSFER_RESULT_PENDING) {
1704 dev_dbg(dev, "DTI: xfer result %d bytes at %p\n", 2387 struct wa_xfer_result *xfer_result;
1705 urb->actual_length, urb->transfer_buffer); 2388 struct wa_xfer *xfer;
1706 if (wa->dti_urb->actual_length != sizeof(*xfer_result)) { 2389
1707 dev_err(dev, "DTI Error: xfer result--bad size " 2390 /* We have a xfer result buffer; check it */
1708 "xfer result (%d bytes vs %zu needed)\n", 2391 dev_dbg(dev, "DTI: xfer result %d bytes at %p\n",
1709 urb->actual_length, sizeof(*xfer_result)); 2392 urb->actual_length, urb->transfer_buffer);
1710 break; 2393 if (urb->actual_length != sizeof(*xfer_result)) {
1711 } 2394 dev_err(dev, "DTI Error: xfer result--bad size xfer result (%d bytes vs %zu needed)\n",
1712 xfer_result = wa->xfer_result; 2395 urb->actual_length,
1713 if (xfer_result->hdr.bLength != sizeof(*xfer_result)) { 2396 sizeof(*xfer_result));
1714 dev_err(dev, "DTI Error: xfer result--" 2397 break;
1715 "bad header length %u\n", 2398 }
1716 xfer_result->hdr.bLength); 2399 xfer_result = (struct wa_xfer_result *)(wa->dti_buf);
1717 break; 2400 if (xfer_result->hdr.bLength != sizeof(*xfer_result)) {
1718 } 2401 dev_err(dev, "DTI Error: xfer result--bad header length %u\n",
1719 if (xfer_result->hdr.bNotifyType != WA_XFER_RESULT) { 2402 xfer_result->hdr.bLength);
1720 dev_err(dev, "DTI Error: xfer result--" 2403 break;
1721 "bad header type 0x%02x\n", 2404 }
1722 xfer_result->hdr.bNotifyType); 2405 if (xfer_result->hdr.bNotifyType != WA_XFER_RESULT) {
1723 break; 2406 dev_err(dev, "DTI Error: xfer result--bad header type 0x%02x\n",
1724 } 2407 xfer_result->hdr.bNotifyType);
1725 usb_status = xfer_result->bTransferStatus & 0x3f; 2408 break;
1726 if (usb_status == WA_XFER_STATUS_NOT_FOUND) 2409 }
1727 /* taken care of already */ 2410 usb_status = xfer_result->bTransferStatus & 0x3f;
1728 break; 2411 if (usb_status == WA_XFER_STATUS_NOT_FOUND)
1729 xfer_id = xfer_result->dwTransferID; 2412 /* taken care of already */
1730 xfer = wa_xfer_get_by_id(wa, xfer_id); 2413 break;
1731 if (xfer == NULL) { 2414 xfer_id = le32_to_cpu(xfer_result->dwTransferID);
1732 /* FIXME: transaction might have been cancelled */ 2415 xfer = wa_xfer_get_by_id(wa, xfer_id);
1733 dev_err(dev, "DTI Error: xfer result--" 2416 if (xfer == NULL) {
1734 "unknown xfer 0x%08x (status 0x%02x)\n", 2417 /* FIXME: transaction not found. */
1735 xfer_id, usb_status); 2418 dev_err(dev, "DTI Error: xfer result--unknown xfer 0x%08x (status 0x%02x)\n",
1736 break; 2419 xfer_id, usb_status);
2420 break;
2421 }
2422 wa_xfer_result_chew(wa, xfer, xfer_result);
2423 wa_xfer_put(xfer);
2424 } else if (wa->dti_state == WA_DTI_ISOC_PACKET_STATUS_PENDING) {
2425 wa_process_iso_packet_status(wa, urb);
2426 } else {
2427 dev_err(dev, "DTI Error: unexpected EP state = %d\n",
2428 wa->dti_state);
1737 } 2429 }
1738 wa_xfer_result_chew(wa, xfer);
1739 wa_xfer_put(xfer);
1740 break; 2430 break;
1741 case -ENOENT: /* (we killed the URB)...so, no broadcast */ 2431 case -ENOENT: /* (we killed the URB)...so, no broadcast */
1742 case -ESHUTDOWN: /* going away! */ 2432 case -ESHUTDOWN: /* going away! */
@@ -1777,7 +2467,7 @@ out:
1777 * don't really set it up and start it until the first xfer complete 2467 * don't really set it up and start it until the first xfer complete
1778 * notification arrives, which is what we do here. 2468 * notification arrives, which is what we do here.
1779 * 2469 *
1780 * Follow up in wa_xfer_result_cb(), as that's where the whole state 2470 * Follow up in wa_dti_cb(), as that's where the whole state
1781 * machine starts. 2471 * machine starts.
1782 * 2472 *
1783 * So here we just initialize the DTI URB for reading transfer result 2473 * So here we just initialize the DTI URB for reading transfer result
@@ -1813,8 +2503,8 @@ void wa_handle_notif_xfer(struct wahc *wa, struct wa_notif_hdr *notif_hdr)
1813 usb_fill_bulk_urb( 2503 usb_fill_bulk_urb(
1814 wa->dti_urb, wa->usb_dev, 2504 wa->dti_urb, wa->usb_dev,
1815 usb_rcvbulkpipe(wa->usb_dev, 0x80 | notif_xfer->bEndpoint), 2505 usb_rcvbulkpipe(wa->usb_dev, 0x80 | notif_xfer->bEndpoint),
1816 wa->xfer_result, wa->xfer_result_size, 2506 wa->dti_buf, wa->dti_buf_size,
1817 wa_xfer_result_cb, wa); 2507 wa_dti_cb, wa);
1818 2508
1819 wa->buf_in_urb = usb_alloc_urb(0, GFP_KERNEL); 2509 wa->buf_in_urb = usb_alloc_urb(0, GFP_KERNEL);
1820 if (wa->buf_in_urb == NULL) { 2510 if (wa->buf_in_urb == NULL) {
@@ -1836,6 +2526,7 @@ out:
1836 2526
1837error_dti_urb_submit: 2527error_dti_urb_submit:
1838 usb_put_urb(wa->buf_in_urb); 2528 usb_put_urb(wa->buf_in_urb);
2529 wa->buf_in_urb = NULL;
1839error_buf_in_urb_alloc: 2530error_buf_in_urb_alloc:
1840 usb_put_urb(wa->dti_urb); 2531 usb_put_urb(wa->dti_urb);
1841 wa->dti_urb = NULL; 2532 wa->dti_urb = NULL;