aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-16 16:16:09 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-16 16:16:09 -0400
commitb903bd69e3fa156598def8d6433dfe5352af8da3 (patch)
treea13380f31bab62acfd667910656525c09511cb8a /drivers/usb
parent84a1caf1453c3d44050bd22db958af4a7f99315c (diff)
parent1a49e2ac9651df7349867a5cf44e2c83de1046af (diff)
Merge 3.5-rc7 into usb-next
This resolves the merge issue with the drivers/usb/host/ehci-omap.c file. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/chipidea/Kconfig1
-rw-r--r--drivers/usb/chipidea/Makefile9
-rw-r--r--drivers/usb/chipidea/ci.h32
-rw-r--r--drivers/usb/chipidea/ci13xxx_imx.c198
-rw-r--r--drivers/usb/chipidea/ci13xxx_msm.c63
-rw-r--r--drivers/usb/chipidea/ci13xxx_pci.c52
-rw-r--r--drivers/usb/chipidea/core.c70
-rw-r--r--drivers/usb/chipidea/debug.c146
-rw-r--r--drivers/usb/chipidea/host.c3
-rw-r--r--drivers/usb/chipidea/udc.c635
-rw-r--r--drivers/usb/class/cdc-acm.c2
-rw-r--r--drivers/usb/class/cdc-wdm.c25
-rw-r--r--drivers/usb/core/devio.c169
-rw-r--r--drivers/usb/core/driver.c10
-rw-r--r--drivers/usb/core/file.c2
-rw-r--r--drivers/usb/core/hcd.c10
-rw-r--r--drivers/usb/core/hub.c21
-rw-r--r--drivers/usb/core/message.c5
-rw-r--r--drivers/usb/core/sysfs.c5
-rw-r--r--drivers/usb/core/usb.h9
-rw-r--r--drivers/usb/dwc3/core.c13
-rw-r--r--drivers/usb/dwc3/core.h107
-rw-r--r--drivers/usb/dwc3/dwc3-exynos.c1
-rw-r--r--drivers/usb/dwc3/ep0.c146
-rw-r--r--drivers/usb/dwc3/gadget.c365
-rw-r--r--drivers/usb/dwc3/gadget.h6
-rw-r--r--drivers/usb/early/ehci-dbgp.c2
-rw-r--r--drivers/usb/gadget/Kconfig9
-rw-r--r--drivers/usb/gadget/Makefile1
-rw-r--r--drivers/usb/gadget/acm_ms.c1
-rw-r--r--drivers/usb/gadget/at91_udc.c1
-rw-r--r--drivers/usb/gadget/composite.c7
-rw-r--r--drivers/usb/gadget/f_fs.c7
-rw-r--r--drivers/usb/gadget/f_hid.c208
-rw-r--r--drivers/usb/gadget/f_mass_storage.c133
-rw-r--r--drivers/usb/gadget/f_uvc.c287
-rw-r--r--drivers/usb/gadget/f_uvc.h8
-rw-r--r--drivers/usb/gadget/fsl_mxc_udc.c74
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c18
-rw-r--r--drivers/usb/gadget/imx_udc.c6
-rw-r--r--drivers/usb/gadget/lpc32xx_udc.c85
-rw-r--r--drivers/usb/gadget/mv_u3d.h320
-rw-r--r--drivers/usb/gadget/mv_u3d_core.c2098
-rw-r--r--drivers/usb/gadget/mv_udc_core.c15
-rw-r--r--drivers/usb/gadget/omap_udc.c434
-rw-r--r--drivers/usb/gadget/pch_udc.c2
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c17
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c15
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c215
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c13
-rw-r--r--drivers/usb/gadget/storage_common.c63
-rw-r--r--drivers/usb/gadget/u_ether.c12
-rw-r--r--drivers/usb/gadget/uvc.h4
-rw-r--r--drivers/usb/gadget/webcam.c29
-rw-r--r--drivers/usb/host/Kconfig4
-rw-r--r--drivers/usb/host/ehci-atmel.c19
-rw-r--r--drivers/usb/host/ehci-au1xxx.c87
-rw-r--r--drivers/usb/host/ehci-cns3xxx.c6
-rw-r--r--drivers/usb/host/ehci-fsl.c40
-rw-r--r--drivers/usb/host/ehci-grlib.c15
-rw-r--r--drivers/usb/host/ehci-hcd.c109
-rw-r--r--drivers/usb/host/ehci-hub.c32
-rw-r--r--drivers/usb/host/ehci-ixp4xx.c6
-rw-r--r--drivers/usb/host/ehci-msm.c27
-rw-r--r--drivers/usb/host/ehci-mv.c36
-rw-r--r--drivers/usb/host/ehci-mxc.c17
-rw-r--r--drivers/usb/host/ehci-octeon.c8
-rw-r--r--drivers/usb/host/ehci-omap.c108
-rw-r--r--drivers/usb/host/ehci-orion.c17
-rw-r--r--drivers/usb/host/ehci-pci.c234
-rw-r--r--drivers/usb/host/ehci-platform.c7
-rw-r--r--drivers/usb/host/ehci-pmcmsp.c17
-rw-r--r--drivers/usb/host/ehci-ppc-of.c25
-rw-r--r--drivers/usb/host/ehci-ps3.c18
-rw-r--r--drivers/usb/host/ehci-s5p.c92
-rw-r--r--drivers/usb/host/ehci-sead3.c74
-rw-r--r--drivers/usb/host/ehci-sh.c16
-rw-r--r--drivers/usb/host/ehci-spear.c71
-rw-r--r--drivers/usb/host/ehci-tegra.c31
-rw-r--r--drivers/usb/host/ehci-vt8500.c14
-rw-r--r--drivers/usb/host/ehci-w90x900.c9
-rw-r--r--drivers/usb/host/ehci-xilinx-of.c31
-rw-r--r--drivers/usb/host/ehci-xls.c21
-rw-r--r--drivers/usb/host/ehci.h4
-rw-r--r--drivers/usb/host/fhci-dbg.c12
-rw-r--r--drivers/usb/host/fhci-hcd.c32
-rw-r--r--drivers/usb/host/fhci-hub.c16
-rw-r--r--drivers/usb/host/fhci-sched.c30
-rw-r--r--drivers/usb/host/fhci-tds.c14
-rw-r--r--drivers/usb/host/fhci.h22
-rw-r--r--drivers/usb/host/imx21-hcd.c6
-rw-r--r--drivers/usb/host/ohci-exynos.c24
-rw-r--r--drivers/usb/host/ohci-nxp.c88
-rw-r--r--drivers/usb/host/ohci-omap.c28
-rw-r--r--drivers/usb/host/ohci.h5
-rw-r--r--drivers/usb/host/xhci.c2
-rw-r--r--drivers/usb/musb/am35x.c7
-rw-r--r--drivers/usb/musb/blackfin.c7
-rw-r--r--drivers/usb/musb/da8xx.c7
-rw-r--r--drivers/usb/musb/davinci.c9
-rw-r--r--drivers/usb/musb/musb_core.c2
-rw-r--r--drivers/usb/musb/musb_core.h2
-rw-r--r--drivers/usb/musb/musb_dsps.c9
-rw-r--r--drivers/usb/musb/musb_gadget.c14
-rw-r--r--drivers/usb/musb/musb_host.c6
-rw-r--r--drivers/usb/musb/omap2430.c124
-rw-r--r--drivers/usb/musb/tusb6010.c9
-rw-r--r--drivers/usb/musb/ux500.c7
-rw-r--r--drivers/usb/otg/Kconfig10
-rw-r--r--drivers/usb/otg/Makefile1
-rw-r--r--drivers/usb/otg/ab8500-usb.c4
-rw-r--r--drivers/usb/otg/fsl_otg.c6
-rw-r--r--drivers/usb/otg/gpio_vbus.c4
-rw-r--r--drivers/usb/otg/isp1301_omap.c19
-rw-r--r--drivers/usb/otg/msm_otg.c6
-rw-r--r--drivers/usb/otg/mv_otg.c6
-rw-r--r--drivers/usb/otg/mxs-phy.c186
-rw-r--r--drivers/usb/otg/nop-usb-xceiv.c4
-rw-r--r--drivers/usb/otg/otg.c181
-rw-r--r--drivers/usb/otg/twl4030-usb.c73
-rw-r--r--drivers/usb/otg/twl6030-usb.c71
-rw-r--r--drivers/usb/renesas_usbhs/fifo.c14
-rw-r--r--drivers/usb/serial/keyspan.c5
-rw-r--r--drivers/usb/serial/option.c88
-rw-r--r--drivers/usb/serial/quatech2.c4
-rw-r--r--drivers/usb/storage/protocol.c6
-rw-r--r--drivers/usb/storage/uas.c422
127 files changed, 5999 insertions, 2977 deletions
diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig
index fd36dc8b889b..8337fb5d988d 100644
--- a/drivers/usb/chipidea/Kconfig
+++ b/drivers/usb/chipidea/Kconfig
@@ -20,6 +20,7 @@ config USB_CHIPIDEA_UDC
20 20
21config USB_CHIPIDEA_HOST 21config USB_CHIPIDEA_HOST
22 bool "ChipIdea host controller" 22 bool "ChipIdea host controller"
23 select USB_EHCI_ROOT_HUB_TT
23 help 24 help
24 Say Y here to enable host controller functionality of the 25 Say Y here to enable host controller functionality of the
25 ChipIdea driver. 26 ChipIdea driver.
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index cc3493769724..5c66d9c330ca 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -5,10 +5,15 @@ ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o
5ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o 5ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o
6ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o 6ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o
7 7
8# Glue/Bridge layers go here
9
10obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_msm.o
11
12# PCI doesn't provide stubs, need to check
8ifneq ($(CONFIG_PCI),) 13ifneq ($(CONFIG_PCI),)
9 obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_pci.o 14 obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_pci.o
10endif 15endif
11 16
12ifneq ($(CONFIG_ARCH_MSM),) 17ifneq ($(CONFIG_OF_DEVICE),)
13 obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_msm.o 18 obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_imx.o
14endif 19endif
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index 50911f8490d4..d738603a2757 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -36,7 +36,7 @@
36 * @name: string description of the endpoint 36 * @name: string description of the endpoint
37 * @qh: queue head for this endpoint 37 * @qh: queue head for this endpoint
38 * @wedge: is the endpoint wedged 38 * @wedge: is the endpoint wedged
39 * @udc: pointer to the controller 39 * @ci: pointer to the controller
40 * @lock: pointer to controller's spinlock 40 * @lock: pointer to controller's spinlock
41 * @td_pool: pointer to controller's TD pool 41 * @td_pool: pointer to controller's TD pool
42 */ 42 */
@@ -54,7 +54,7 @@ struct ci13xxx_ep {
54 int wedge; 54 int wedge;
55 55
56 /* global resources */ 56 /* global resources */
57 struct ci13xxx *udc; 57 struct ci13xxx *ci;
58 spinlock_t *lock; 58 spinlock_t *lock;
59 struct dma_pool *td_pool; 59 struct dma_pool *td_pool;
60}; 60};
@@ -125,7 +125,7 @@ struct hw_bank {
125 * @remote_wakeup: host-enabled remote wakeup 125 * @remote_wakeup: host-enabled remote wakeup
126 * @suspended: suspended by host 126 * @suspended: suspended by host
127 * @test_mode: the selected test mode 127 * @test_mode: the selected test mode
128 * @udc_driver: platform specific information supplied by parent device 128 * @platdata: platform specific information supplied by parent device
129 * @vbus_active: is VBUS active 129 * @vbus_active: is VBUS active
130 * @transceiver: pointer to USB PHY, if any 130 * @transceiver: pointer to USB PHY, if any
131 * @hcd: pointer to usb_hcd for ehci host driver 131 * @hcd: pointer to usb_hcd for ehci host driver
@@ -158,8 +158,10 @@ struct ci13xxx {
158 u8 suspended; 158 u8 suspended;
159 u8 test_mode; 159 u8 test_mode;
160 160
161 struct ci13xxx_udc_driver *udc_driver; 161 struct ci13xxx_platform_data *platdata;
162 int vbus_active; 162 int vbus_active;
163 /* FIXME: some day, we'll not use global phy */
164 bool global_phy;
163 struct usb_phy *transceiver; 165 struct usb_phy *transceiver;
164 struct usb_hcd *hcd; 166 struct usb_hcd *hcd;
165}; 167};
@@ -250,9 +252,9 @@ static inline int ffs_nr(u32 x)
250 * 252 *
251 * This function returns register contents 253 * This function returns register contents
252 */ 254 */
253static inline u32 hw_read(struct ci13xxx *udc, enum ci13xxx_regs reg, u32 mask) 255static inline u32 hw_read(struct ci13xxx *ci, enum ci13xxx_regs reg, u32 mask)
254{ 256{
255 return ioread32(udc->hw_bank.regmap[reg]) & mask; 257 return ioread32(ci->hw_bank.regmap[reg]) & mask;
256} 258}
257 259
258/** 260/**
@@ -261,14 +263,14 @@ static inline u32 hw_read(struct ci13xxx *udc, enum ci13xxx_regs reg, u32 mask)
261 * @mask: bitfield mask 263 * @mask: bitfield mask
262 * @data: new value 264 * @data: new value
263 */ 265 */
264static inline void hw_write(struct ci13xxx *udc, enum ci13xxx_regs reg, 266static inline void hw_write(struct ci13xxx *ci, enum ci13xxx_regs reg,
265 u32 mask, u32 data) 267 u32 mask, u32 data)
266{ 268{
267 if (~mask) 269 if (~mask)
268 data = (ioread32(udc->hw_bank.regmap[reg]) & ~mask) 270 data = (ioread32(ci->hw_bank.regmap[reg]) & ~mask)
269 | (data & mask); 271 | (data & mask);
270 272
271 iowrite32(data, udc->hw_bank.regmap[reg]); 273 iowrite32(data, ci->hw_bank.regmap[reg]);
272} 274}
273 275
274/** 276/**
@@ -278,12 +280,12 @@ static inline void hw_write(struct ci13xxx *udc, enum ci13xxx_regs reg,
278 * 280 *
279 * This function returns register contents 281 * This function returns register contents
280 */ 282 */
281static inline u32 hw_test_and_clear(struct ci13xxx *udc, enum ci13xxx_regs reg, 283static inline u32 hw_test_and_clear(struct ci13xxx *ci, enum ci13xxx_regs reg,
282 u32 mask) 284 u32 mask)
283{ 285{
284 u32 val = ioread32(udc->hw_bank.regmap[reg]) & mask; 286 u32 val = ioread32(ci->hw_bank.regmap[reg]) & mask;
285 287
286 iowrite32(val, udc->hw_bank.regmap[reg]); 288 iowrite32(val, ci->hw_bank.regmap[reg]);
287 return val; 289 return val;
288} 290}
289 291
@@ -295,12 +297,12 @@ static inline u32 hw_test_and_clear(struct ci13xxx *udc, enum ci13xxx_regs reg,
295 * 297 *
296 * This function returns register contents 298 * This function returns register contents
297 */ 299 */
298static inline u32 hw_test_and_write(struct ci13xxx *udc, enum ci13xxx_regs reg, 300static inline u32 hw_test_and_write(struct ci13xxx *ci, enum ci13xxx_regs reg,
299 u32 mask, u32 data) 301 u32 mask, u32 data)
300{ 302{
301 u32 val = hw_read(udc, reg, ~0); 303 u32 val = hw_read(ci, reg, ~0);
302 304
303 hw_write(udc, reg, mask, data); 305 hw_write(ci, reg, mask, data);
304 return (val & mask) >> ffs_nr(mask); 306 return (val & mask) >> ffs_nr(mask);
305} 307}
306 308
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c
new file mode 100644
index 000000000000..ef60d06835d0
--- /dev/null
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -0,0 +1,198 @@
1/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Copyright (C) 2012 Marek Vasut <marex@denx.de>
4 * on behalf of DENX Software Engineering GmbH
5 *
6 * The code contained herein is licensed under the GNU General Public
7 * License. You may obtain a copy of the GNU General Public License
8 * Version 2 or later at the following locations:
9 *
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
12 */
13
14#include <linux/module.h>
15#include <linux/of_platform.h>
16#include <linux/of_gpio.h>
17#include <linux/platform_device.h>
18#include <linux/pm_runtime.h>
19#include <linux/dma-mapping.h>
20#include <linux/usb/chipidea.h>
21#include <linux/clk.h>
22#include <linux/regulator/consumer.h>
23
24#include "ci.h"
25
26#define pdev_to_phy(pdev) \
27 ((struct usb_phy *)platform_get_drvdata(pdev))
28
29struct ci13xxx_imx_data {
30 struct device_node *phy_np;
31 struct usb_phy *phy;
32 struct platform_device *ci_pdev;
33 struct clk *clk;
34 struct regulator *reg_vbus;
35};
36
37static struct ci13xxx_platform_data ci13xxx_imx_platdata __devinitdata = {
38 .name = "ci13xxx_imx",
39 .flags = CI13XXX_REQUIRE_TRANSCEIVER |
40 CI13XXX_PULLUP_ON_VBUS |
41 CI13XXX_DISABLE_STREAMING,
42 .capoffset = DEF_CAPOFFSET,
43};
44
45static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
46{
47 struct ci13xxx_imx_data *data;
48 struct platform_device *plat_ci, *phy_pdev;
49 struct device_node *phy_np;
50 struct resource *res;
51 struct regulator *reg_vbus;
52 int ret;
53
54 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
55 if (!data) {
56 dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
57 return -ENOMEM;
58 }
59
60 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
61 if (!res) {
62 dev_err(&pdev->dev, "Can't get device resources!\n");
63 return -ENOENT;
64 }
65
66 data->clk = devm_clk_get(&pdev->dev, NULL);
67 if (IS_ERR(data->clk)) {
68 dev_err(&pdev->dev,
69 "Failed to get clock, err=%ld\n", PTR_ERR(data->clk));
70 return PTR_ERR(data->clk);
71 }
72
73 ret = clk_prepare_enable(data->clk);
74 if (ret) {
75 dev_err(&pdev->dev,
76 "Failed to prepare or enable clock, err=%d\n", ret);
77 return ret;
78 }
79
80 phy_np = of_parse_phandle(pdev->dev.of_node, "fsl,usbphy", 0);
81 if (phy_np) {
82 data->phy_np = phy_np;
83 phy_pdev = of_find_device_by_node(phy_np);
84 if (phy_pdev) {
85 struct usb_phy *phy;
86 phy = pdev_to_phy(phy_pdev);
87 if (phy &&
88 try_module_get(phy_pdev->dev.driver->owner)) {
89 usb_phy_init(phy);
90 data->phy = phy;
91 }
92 }
93 }
94
95 /* we only support host now, so enable vbus here */
96 reg_vbus = devm_regulator_get(&pdev->dev, "vbus");
97 if (!IS_ERR(reg_vbus)) {
98 ret = regulator_enable(reg_vbus);
99 if (ret) {
100 dev_err(&pdev->dev,
101 "Failed to enable vbus regulator, err=%d\n",
102 ret);
103 goto put_np;
104 }
105 data->reg_vbus = reg_vbus;
106 } else {
107 reg_vbus = NULL;
108 }
109
110 ci13xxx_imx_platdata.phy = data->phy;
111
112 if (!pdev->dev.dma_mask) {
113 pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
114 sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
115 if (!pdev->dev.dma_mask) {
116 ret = -ENOMEM;
117 dev_err(&pdev->dev, "Failed to alloc dma_mask!\n");
118 goto err;
119 }
120 *pdev->dev.dma_mask = DMA_BIT_MASK(32);
121 dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask);
122 }
123 plat_ci = ci13xxx_add_device(&pdev->dev,
124 pdev->resource, pdev->num_resources,
125 &ci13xxx_imx_platdata);
126 if (IS_ERR(plat_ci)) {
127 ret = PTR_ERR(plat_ci);
128 dev_err(&pdev->dev,
129 "Can't register ci_hdrc platform device, err=%d\n",
130 ret);
131 goto err;
132 }
133
134 data->ci_pdev = plat_ci;
135 platform_set_drvdata(pdev, data);
136
137 pm_runtime_no_callbacks(&pdev->dev);
138 pm_runtime_enable(&pdev->dev);
139
140 return 0;
141
142err:
143 if (reg_vbus)
144 regulator_disable(reg_vbus);
145put_np:
146 if (phy_np)
147 of_node_put(phy_np);
148 clk_disable_unprepare(data->clk);
149 return ret;
150}
151
152static int __devexit ci13xxx_imx_remove(struct platform_device *pdev)
153{
154 struct ci13xxx_imx_data *data = platform_get_drvdata(pdev);
155
156 pm_runtime_disable(&pdev->dev);
157 ci13xxx_remove_device(data->ci_pdev);
158
159 if (data->reg_vbus)
160 regulator_disable(data->reg_vbus);
161
162 if (data->phy) {
163 usb_phy_shutdown(data->phy);
164 module_put(data->phy->dev->driver->owner);
165 }
166
167 of_node_put(data->phy_np);
168
169 clk_disable_unprepare(data->clk);
170
171 platform_set_drvdata(pdev, NULL);
172
173 return 0;
174}
175
176static const struct of_device_id ci13xxx_imx_dt_ids[] = {
177 { .compatible = "fsl,imx27-usb", },
178 { /* sentinel */ }
179};
180MODULE_DEVICE_TABLE(of, ci13xxx_imx_dt_ids);
181
182static struct platform_driver ci13xxx_imx_driver = {
183 .probe = ci13xxx_imx_probe,
184 .remove = __devexit_p(ci13xxx_imx_remove),
185 .driver = {
186 .name = "imx_usb",
187 .owner = THIS_MODULE,
188 .of_match_table = ci13xxx_imx_dt_ids,
189 },
190};
191
192module_platform_driver(ci13xxx_imx_driver);
193
194MODULE_ALIAS("platform:imx-usb");
195MODULE_LICENSE("GPL v2");
196MODULE_DESCRIPTION("CI13xxx i.MX USB binding");
197MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
198MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
diff --git a/drivers/usb/chipidea/ci13xxx_msm.c b/drivers/usb/chipidea/ci13xxx_msm.c
index 958069ef95e3..b01feb3be92e 100644
--- a/drivers/usb/chipidea/ci13xxx_msm.c
+++ b/drivers/usb/chipidea/ci13xxx_msm.c
@@ -15,11 +15,11 @@
15 15
16#include "ci.h" 16#include "ci.h"
17 17
18#define MSM_USB_BASE (udc->hw_bank.abs) 18#define MSM_USB_BASE (ci->hw_bank.abs)
19 19
20static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event) 20static void ci13xxx_msm_notify_event(struct ci13xxx *ci, unsigned event)
21{ 21{
22 struct device *dev = udc->gadget.dev.parent; 22 struct device *dev = ci->gadget.dev.parent;
23 int val; 23 int val;
24 24
25 switch (event) { 25 switch (event) {
@@ -34,18 +34,18 @@ static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event)
34 * Put the transceiver in non-driving mode. Otherwise host 34 * Put the transceiver in non-driving mode. Otherwise host
35 * may not detect soft-disconnection. 35 * may not detect soft-disconnection.
36 */ 36 */
37 val = usb_phy_io_read(udc->transceiver, ULPI_FUNC_CTRL); 37 val = usb_phy_io_read(ci->transceiver, ULPI_FUNC_CTRL);
38 val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; 38 val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
39 val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; 39 val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
40 usb_phy_io_write(udc->transceiver, val, ULPI_FUNC_CTRL); 40 usb_phy_io_write(ci->transceiver, val, ULPI_FUNC_CTRL);
41 break; 41 break;
42 default: 42 default:
43 dev_dbg(dev, "unknown ci13xxx_udc event\n"); 43 dev_dbg(dev, "unknown ci13xxx event\n");
44 break; 44 break;
45 } 45 }
46} 46}
47 47
48static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = { 48static struct ci13xxx_platform_data ci13xxx_msm_platdata = {
49 .name = "ci13xxx_msm", 49 .name = "ci13xxx_msm",
50 .flags = CI13XXX_REGS_SHARED | 50 .flags = CI13XXX_REGS_SHARED |
51 CI13XXX_REQUIRE_TRANSCEIVER | 51 CI13XXX_REQUIRE_TRANSCEIVER |
@@ -55,56 +55,45 @@ static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = {
55 .notify_event = ci13xxx_msm_notify_event, 55 .notify_event = ci13xxx_msm_notify_event,
56}; 56};
57 57
58static int ci13xxx_msm_probe(struct platform_device *pdev) 58static int __devinit ci13xxx_msm_probe(struct platform_device *pdev)
59{ 59{
60 struct platform_device *plat_ci; 60 struct platform_device *plat_ci;
61 int ret;
62 61
63 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n"); 62 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
64 63
65 plat_ci = platform_device_alloc("ci_hdrc", -1); 64 plat_ci = ci13xxx_add_device(&pdev->dev,
66 if (!plat_ci) { 65 pdev->resource, pdev->num_resources,
67 dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n"); 66 &ci13xxx_msm_platdata);
68 return -ENOMEM; 67 if (IS_ERR(plat_ci)) {
68 dev_err(&pdev->dev, "ci13xxx_add_device failed!\n");
69 return PTR_ERR(plat_ci);
69 } 70 }
70 71
71 ret = platform_device_add_resources(plat_ci, pdev->resource, 72 platform_set_drvdata(pdev, plat_ci);
72 pdev->num_resources);
73 if (ret) {
74 dev_err(&pdev->dev, "can't add resources to platform device\n");
75 goto put_platform;
76 }
77
78 ret = platform_device_add_data(plat_ci, &ci13xxx_msm_udc_driver,
79 sizeof(ci13xxx_msm_udc_driver));
80 if (ret)
81 goto put_platform;
82
83 ret = platform_device_add(plat_ci);
84 if (ret)
85 goto put_platform;
86 73
87 pm_runtime_no_callbacks(&pdev->dev); 74 pm_runtime_no_callbacks(&pdev->dev);
88 pm_runtime_enable(&pdev->dev); 75 pm_runtime_enable(&pdev->dev);
89 76
90 return 0; 77 return 0;
78}
79
80static int __devexit ci13xxx_msm_remove(struct platform_device *pdev)
81{
82 struct platform_device *plat_ci = platform_get_drvdata(pdev);
91 83
92put_platform: 84 pm_runtime_disable(&pdev->dev);
93 platform_device_put(plat_ci); 85 ci13xxx_remove_device(plat_ci);
94 86
95 return ret; 87 return 0;
96} 88}
97 89
98static struct platform_driver ci13xxx_msm_driver = { 90static struct platform_driver ci13xxx_msm_driver = {
99 .probe = ci13xxx_msm_probe, 91 .probe = ci13xxx_msm_probe,
92 .remove = __devexit_p(ci13xxx_msm_remove),
100 .driver = { .name = "msm_hsusb", }, 93 .driver = { .name = "msm_hsusb", },
101}; 94};
102MODULE_ALIAS("platform:msm_hsusb");
103 95
104static int __init ci13xxx_msm_init(void) 96module_platform_driver(ci13xxx_msm_driver);
105{
106 return platform_driver_register(&ci13xxx_msm_driver);
107}
108module_init(ci13xxx_msm_init);
109 97
98MODULE_ALIAS("platform:msm_hsusb");
110MODULE_LICENSE("GPL v2"); 99MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/chipidea/ci13xxx_pci.c b/drivers/usb/chipidea/ci13xxx_pci.c
index e3dab27f5c75..918e14971f2b 100644
--- a/drivers/usb/chipidea/ci13xxx_pci.c
+++ b/drivers/usb/chipidea/ci13xxx_pci.c
@@ -23,17 +23,17 @@
23/****************************************************************************** 23/******************************************************************************
24 * PCI block 24 * PCI block
25 *****************************************************************************/ 25 *****************************************************************************/
26struct ci13xxx_udc_driver pci_driver = { 26struct ci13xxx_platform_data pci_platdata = {
27 .name = UDC_DRIVER_NAME, 27 .name = UDC_DRIVER_NAME,
28 .capoffset = DEF_CAPOFFSET, 28 .capoffset = DEF_CAPOFFSET,
29}; 29};
30 30
31struct ci13xxx_udc_driver langwell_pci_driver = { 31struct ci13xxx_platform_data langwell_pci_platdata = {
32 .name = UDC_DRIVER_NAME, 32 .name = UDC_DRIVER_NAME,
33 .capoffset = 0, 33 .capoffset = 0,
34}; 34};
35 35
36struct ci13xxx_udc_driver penwell_pci_driver = { 36struct ci13xxx_platform_data penwell_pci_platdata = {
37 .name = UDC_DRIVER_NAME, 37 .name = UDC_DRIVER_NAME,
38 .capoffset = 0, 38 .capoffset = 0,
39 .power_budget = 200, 39 .power_budget = 200,
@@ -51,12 +51,12 @@ struct ci13xxx_udc_driver penwell_pci_driver = {
51static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev, 51static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
52 const struct pci_device_id *id) 52 const struct pci_device_id *id)
53{ 53{
54 struct ci13xxx_udc_driver *driver = (void *)id->driver_data; 54 struct ci13xxx_platform_data *platdata = (void *)id->driver_data;
55 struct platform_device *plat_ci; 55 struct platform_device *plat_ci;
56 struct resource res[3]; 56 struct resource res[3];
57 int retval = 0, nres = 2; 57 int retval = 0, nres = 2;
58 58
59 if (!driver) { 59 if (!platdata) {
60 dev_err(&pdev->dev, "device doesn't provide driver data\n"); 60 dev_err(&pdev->dev, "device doesn't provide driver data\n");
61 return -ENODEV; 61 return -ENODEV;
62 } 62 }
@@ -75,13 +75,6 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
75 pci_set_master(pdev); 75 pci_set_master(pdev);
76 pci_try_set_mwi(pdev); 76 pci_try_set_mwi(pdev);
77 77
78 plat_ci = platform_device_alloc("ci_hdrc", -1);
79 if (!plat_ci) {
80 dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n");
81 retval = -ENOMEM;
82 goto disable_device;
83 }
84
85 memset(res, 0, sizeof(res)); 78 memset(res, 0, sizeof(res));
86 res[0].start = pci_resource_start(pdev, 0); 79 res[0].start = pci_resource_start(pdev, 0);
87 res[0].end = pci_resource_end(pdev, 0); 80 res[0].end = pci_resource_end(pdev, 0);
@@ -89,32 +82,17 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
89 res[1].start = pdev->irq; 82 res[1].start = pdev->irq;
90 res[1].flags = IORESOURCE_IRQ; 83 res[1].flags = IORESOURCE_IRQ;
91 84
92 retval = platform_device_add_resources(plat_ci, res, nres); 85 plat_ci = ci13xxx_add_device(&pdev->dev, res, nres, platdata);
93 if (retval) { 86 if (IS_ERR(plat_ci)) {
94 dev_err(&pdev->dev, "can't add resources to platform device\n"); 87 dev_err(&pdev->dev, "ci13xxx_add_device failed!\n");
95 goto put_platform; 88 retval = PTR_ERR(plat_ci);
89 goto disable_device;
96 } 90 }
97 91
98 retval = platform_device_add_data(plat_ci, driver, sizeof(*driver));
99 if (retval)
100 goto put_platform;
101
102 dma_set_coherent_mask(&plat_ci->dev, pdev->dev.coherent_dma_mask);
103 plat_ci->dev.dma_mask = pdev->dev.dma_mask;
104 plat_ci->dev.dma_parms = pdev->dev.dma_parms;
105 plat_ci->dev.parent = &pdev->dev;
106
107 pci_set_drvdata(pdev, plat_ci); 92 pci_set_drvdata(pdev, plat_ci);
108 93
109 retval = platform_device_add(plat_ci);
110 if (retval)
111 goto put_platform;
112
113 return 0; 94 return 0;
114 95
115 put_platform:
116 pci_set_drvdata(pdev, NULL);
117 platform_device_put(plat_ci);
118 disable_device: 96 disable_device:
119 pci_disable_device(pdev); 97 pci_disable_device(pdev);
120 done: 98 done:
@@ -133,7 +111,7 @@ static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
133{ 111{
134 struct platform_device *plat_ci = pci_get_drvdata(pdev); 112 struct platform_device *plat_ci = pci_get_drvdata(pdev);
135 113
136 platform_device_unregister(plat_ci); 114 ci13xxx_remove_device(plat_ci);
137 pci_set_drvdata(pdev, NULL); 115 pci_set_drvdata(pdev, NULL);
138 pci_disable_device(pdev); 116 pci_disable_device(pdev);
139} 117}
@@ -147,19 +125,19 @@ static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
147static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = { 125static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = {
148 { 126 {
149 PCI_DEVICE(0x153F, 0x1004), 127 PCI_DEVICE(0x153F, 0x1004),
150 .driver_data = (kernel_ulong_t)&pci_driver, 128 .driver_data = (kernel_ulong_t)&pci_platdata,
151 }, 129 },
152 { 130 {
153 PCI_DEVICE(0x153F, 0x1006), 131 PCI_DEVICE(0x153F, 0x1006),
154 .driver_data = (kernel_ulong_t)&pci_driver, 132 .driver_data = (kernel_ulong_t)&pci_platdata,
155 }, 133 },
156 { 134 {
157 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811), 135 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811),
158 .driver_data = (kernel_ulong_t)&langwell_pci_driver, 136 .driver_data = (kernel_ulong_t)&langwell_pci_platdata,
159 }, 137 },
160 { 138 {
161 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829), 139 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
162 .driver_data = (kernel_ulong_t)&penwell_pci_driver, 140 .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
163 }, 141 },
164 { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ } 142 { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
165}; 143};
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 15e03b308f8a..1083585fad00 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -56,6 +56,7 @@
56#include <linux/init.h> 56#include <linux/init.h>
57#include <linux/platform_device.h> 57#include <linux/platform_device.h>
58#include <linux/module.h> 58#include <linux/module.h>
59#include <linux/idr.h>
59#include <linux/interrupt.h> 60#include <linux/interrupt.h>
60#include <linux/io.h> 61#include <linux/io.h>
61#include <linux/irq.h> 62#include <linux/irq.h>
@@ -179,7 +180,7 @@ static int hw_device_init(struct ci13xxx *ci, void __iomem *base)
179 ci->hw_bank.abs = base; 180 ci->hw_bank.abs = base;
180 181
181 ci->hw_bank.cap = ci->hw_bank.abs; 182 ci->hw_bank.cap = ci->hw_bank.abs;
182 ci->hw_bank.cap += ci->udc_driver->capoffset; 183 ci->hw_bank.cap += ci->platdata->capoffset;
183 ci->hw_bank.op = ci->hw_bank.cap + ioread8(ci->hw_bank.cap); 184 ci->hw_bank.op = ci->hw_bank.cap + ioread8(ci->hw_bank.cap);
184 185
185 hw_alloc_regmap(ci, false); 186 hw_alloc_regmap(ci, false);
@@ -227,11 +228,11 @@ int hw_device_reset(struct ci13xxx *ci, u32 mode)
227 udelay(10); /* not RTOS friendly */ 228 udelay(10); /* not RTOS friendly */
228 229
229 230
230 if (ci->udc_driver->notify_event) 231 if (ci->platdata->notify_event)
231 ci->udc_driver->notify_event(ci, 232 ci->platdata->notify_event(ci,
232 CI13XXX_CONTROLLER_RESET_EVENT); 233 CI13XXX_CONTROLLER_RESET_EVENT);
233 234
234 if (ci->udc_driver->flags & CI13XXX_DISABLE_STREAMING) 235 if (ci->platdata->flags & CI13XXX_DISABLE_STREAMING)
235 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS); 236 hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
236 237
237 /* USBMODE should be configured step by step */ 238 /* USBMODE should be configured step by step */
@@ -332,6 +333,59 @@ static irqreturn_t ci_irq(int irq, void *data)
332 return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci); 333 return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci);
333} 334}
334 335
336static DEFINE_IDA(ci_ida);
337
338struct platform_device *ci13xxx_add_device(struct device *dev,
339 struct resource *res, int nres,
340 struct ci13xxx_platform_data *platdata)
341{
342 struct platform_device *pdev;
343 int id, ret;
344
345 id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
346 if (id < 0)
347 return ERR_PTR(id);
348
349 pdev = platform_device_alloc("ci_hdrc", id);
350 if (!pdev) {
351 ret = -ENOMEM;
352 goto put_id;
353 }
354
355 pdev->dev.parent = dev;
356 pdev->dev.dma_mask = dev->dma_mask;
357 pdev->dev.dma_parms = dev->dma_parms;
358 dma_set_coherent_mask(&pdev->dev, dev->coherent_dma_mask);
359
360 ret = platform_device_add_resources(pdev, res, nres);
361 if (ret)
362 goto err;
363
364 ret = platform_device_add_data(pdev, platdata, sizeof(*platdata));
365 if (ret)
366 goto err;
367
368 ret = platform_device_add(pdev);
369 if (ret)
370 goto err;
371
372 return pdev;
373
374err:
375 platform_device_put(pdev);
376put_id:
377 ida_simple_remove(&ci_ida, id);
378 return ERR_PTR(ret);
379}
380EXPORT_SYMBOL_GPL(ci13xxx_add_device);
381
382void ci13xxx_remove_device(struct platform_device *pdev)
383{
384 platform_device_unregister(pdev);
385 ida_simple_remove(&ci_ida, pdev->id);
386}
387EXPORT_SYMBOL_GPL(ci13xxx_remove_device);
388
335static int __devinit ci_hdrc_probe(struct platform_device *pdev) 389static int __devinit ci_hdrc_probe(struct platform_device *pdev)
336{ 390{
337 struct device *dev = &pdev->dev; 391 struct device *dev = &pdev->dev;
@@ -364,7 +418,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
364 } 418 }
365 419
366 ci->dev = dev; 420 ci->dev = dev;
367 ci->udc_driver = dev->platform_data; 421 ci->platdata = dev->platform_data;
422 if (ci->platdata->phy)
423 ci->transceiver = ci->platdata->phy;
424 else
425 ci->global_phy = true;
368 426
369 ret = hw_device_init(ci, base); 427 ret = hw_device_init(ci, base);
370 if (ret < 0) { 428 if (ret < 0) {
@@ -419,7 +477,7 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
419 } 477 }
420 478
421 platform_set_drvdata(pdev, ci); 479 platform_set_drvdata(pdev, ci);
422 ret = request_irq(ci->irq, ci_irq, IRQF_SHARED, ci->udc_driver->name, 480 ret = request_irq(ci->irq, ci_irq, IRQF_SHARED, ci->platdata->name,
423 ci); 481 ci);
424 if (ret) 482 if (ret)
425 goto stop; 483 goto stop;
diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
index c4b3e15532db..c6f50a257565 100644
--- a/drivers/usb/chipidea/debug.c
+++ b/drivers/usb/chipidea/debug.c
@@ -68,15 +68,15 @@ void dbg_interrupt(u32 intmask)
68 * 68 *
69 * This function returns number of registers read 69 * This function returns number of registers read
70 */ 70 */
71static size_t hw_register_read(struct ci13xxx *udc, u32 *buf, size_t size) 71static size_t hw_register_read(struct ci13xxx *ci, u32 *buf, size_t size)
72{ 72{
73 unsigned i; 73 unsigned i;
74 74
75 if (size > udc->hw_bank.size) 75 if (size > ci->hw_bank.size)
76 size = udc->hw_bank.size; 76 size = ci->hw_bank.size;
77 77
78 for (i = 0; i < size; i++) 78 for (i = 0; i < size; i++)
79 buf[i] = hw_read(udc, i * sizeof(u32), ~0); 79 buf[i] = hw_read(ci, i * sizeof(u32), ~0);
80 80
81 return size; 81 return size;
82} 82}
@@ -88,18 +88,18 @@ static size_t hw_register_read(struct ci13xxx *udc, u32 *buf, size_t size)
88 * 88 *
89 * This function returns an error code 89 * This function returns an error code
90 */ 90 */
91static int hw_register_write(struct ci13xxx *udc, u16 addr, u32 data) 91static int hw_register_write(struct ci13xxx *ci, u16 addr, u32 data)
92{ 92{
93 /* align */ 93 /* align */
94 addr /= sizeof(u32); 94 addr /= sizeof(u32);
95 95
96 if (addr >= udc->hw_bank.size) 96 if (addr >= ci->hw_bank.size)
97 return -EINVAL; 97 return -EINVAL;
98 98
99 /* align */ 99 /* align */
100 addr *= sizeof(u32); 100 addr *= sizeof(u32);
101 101
102 hw_write(udc, addr, ~0, data); 102 hw_write(ci, addr, ~0, data);
103 return 0; 103 return 0;
104} 104}
105 105
@@ -110,13 +110,13 @@ static int hw_register_write(struct ci13xxx *udc, u16 addr, u32 data)
110 * 110 *
111 * This function returns an error code 111 * This function returns an error code
112 */ 112 */
113static int hw_intr_clear(struct ci13xxx *udc, int n) 113static int hw_intr_clear(struct ci13xxx *ci, int n)
114{ 114{
115 if (n >= REG_BITS) 115 if (n >= REG_BITS)
116 return -EINVAL; 116 return -EINVAL;
117 117
118 hw_write(udc, OP_USBINTR, BIT(n), 0); 118 hw_write(ci, OP_USBINTR, BIT(n), 0);
119 hw_write(udc, OP_USBSTS, BIT(n), BIT(n)); 119 hw_write(ci, OP_USBSTS, BIT(n), BIT(n));
120 return 0; 120 return 0;
121} 121}
122 122
@@ -127,15 +127,15 @@ static int hw_intr_clear(struct ci13xxx *udc, int n)
127 * 127 *
128 * This function returns an error code 128 * This function returns an error code
129 */ 129 */
130static int hw_intr_force(struct ci13xxx *udc, int n) 130static int hw_intr_force(struct ci13xxx *ci, int n)
131{ 131{
132 if (n >= REG_BITS) 132 if (n >= REG_BITS)
133 return -EINVAL; 133 return -EINVAL;
134 134
135 hw_write(udc, CAP_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE); 135 hw_write(ci, CAP_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE);
136 hw_write(udc, OP_USBINTR, BIT(n), BIT(n)); 136 hw_write(ci, OP_USBINTR, BIT(n), BIT(n));
137 hw_write(udc, OP_USBSTS, BIT(n), BIT(n)); 137 hw_write(ci, OP_USBSTS, BIT(n), BIT(n));
138 hw_write(udc, CAP_TESTMODE, TESTMODE_FORCE, 0); 138 hw_write(ci, CAP_TESTMODE, TESTMODE_FORCE, 0);
139 return 0; 139 return 0;
140} 140}
141 141
@@ -147,12 +147,12 @@ static int hw_intr_force(struct ci13xxx *udc, int n)
147static ssize_t show_device(struct device *dev, struct device_attribute *attr, 147static ssize_t show_device(struct device *dev, struct device_attribute *attr,
148 char *buf) 148 char *buf)
149{ 149{
150 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 150 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
151 struct usb_gadget *gadget = &udc->gadget; 151 struct usb_gadget *gadget = &ci->gadget;
152 int n = 0; 152 int n = 0;
153 153
154 if (attr == NULL || buf == NULL) { 154 if (attr == NULL || buf == NULL) {
155 dev_err(udc->dev, "[%s] EINVAL\n", __func__); 155 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
156 return 0; 156 return 0;
157 } 157 }
158 158
@@ -188,8 +188,8 @@ static DEVICE_ATTR(device, S_IRUSR, show_device, NULL);
188static ssize_t show_driver(struct device *dev, struct device_attribute *attr, 188static ssize_t show_driver(struct device *dev, struct device_attribute *attr,
189 char *buf) 189 char *buf)
190{ 190{
191 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 191 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
192 struct usb_gadget_driver *driver = udc->driver; 192 struct usb_gadget_driver *driver = ci->driver;
193 int n = 0; 193 int n = 0;
194 194
195 if (attr == NULL || buf == NULL) { 195 if (attr == NULL || buf == NULL) {
@@ -412,22 +412,22 @@ static DEVICE_ATTR(events, S_IRUSR | S_IWUSR, show_events, store_events);
412static ssize_t show_inters(struct device *dev, struct device_attribute *attr, 412static ssize_t show_inters(struct device *dev, struct device_attribute *attr,
413 char *buf) 413 char *buf)
414{ 414{
415 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 415 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
416 unsigned long flags; 416 unsigned long flags;
417 u32 intr; 417 u32 intr;
418 unsigned i, j, n = 0; 418 unsigned i, j, n = 0;
419 419
420 if (attr == NULL || buf == NULL) { 420 if (attr == NULL || buf == NULL) {
421 dev_err(udc->dev, "[%s] EINVAL\n", __func__); 421 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
422 return 0; 422 return 0;
423 } 423 }
424 424
425 spin_lock_irqsave(&udc->lock, flags); 425 spin_lock_irqsave(&ci->lock, flags);
426 426
427 /*n += scnprintf(buf + n, PAGE_SIZE - n, 427 /*n += scnprintf(buf + n, PAGE_SIZE - n,
428 "status = %08x\n", hw_read_intr_status(udc)); 428 "status = %08x\n", hw_read_intr_status(ci));
429 n += scnprintf(buf + n, PAGE_SIZE - n, 429 n += scnprintf(buf + n, PAGE_SIZE - n,
430 "enable = %08x\n", hw_read_intr_enable(udc));*/ 430 "enable = %08x\n", hw_read_intr_enable(ci));*/
431 431
432 n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n", 432 n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n",
433 isr_statistics.test); 433 isr_statistics.test);
@@ -471,7 +471,7 @@ static ssize_t show_inters(struct device *dev, struct device_attribute *attr,
471 n += scnprintf(buf + n, PAGE_SIZE - n, "\n"); 471 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
472 } 472 }
473 473
474 spin_unlock_irqrestore(&udc->lock, flags); 474 spin_unlock_irqrestore(&ci->lock, flags);
475 475
476 return n; 476 return n;
477} 477}
@@ -485,31 +485,31 @@ static ssize_t show_inters(struct device *dev, struct device_attribute *attr,
485static ssize_t store_inters(struct device *dev, struct device_attribute *attr, 485static ssize_t store_inters(struct device *dev, struct device_attribute *attr,
486 const char *buf, size_t count) 486 const char *buf, size_t count)
487{ 487{
488 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 488 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
489 unsigned long flags; 489 unsigned long flags;
490 unsigned en, bit; 490 unsigned en, bit;
491 491
492 if (attr == NULL || buf == NULL) { 492 if (attr == NULL || buf == NULL) {
493 dev_err(udc->dev, "EINVAL\n"); 493 dev_err(ci->dev, "EINVAL\n");
494 goto done; 494 goto done;
495 } 495 }
496 496
497 if (sscanf(buf, "%u %u", &en, &bit) != 2 || en > 1) { 497 if (sscanf(buf, "%u %u", &en, &bit) != 2 || en > 1) {
498 dev_err(udc->dev, "<1|0> <bit>: enable|disable interrupt\n"); 498 dev_err(ci->dev, "<1|0> <bit>: enable|disable interrupt\n");
499 goto done; 499 goto done;
500 } 500 }
501 501
502 spin_lock_irqsave(&udc->lock, flags); 502 spin_lock_irqsave(&ci->lock, flags);
503 if (en) { 503 if (en) {
504 if (hw_intr_force(udc, bit)) 504 if (hw_intr_force(ci, bit))
505 dev_err(dev, "invalid bit number\n"); 505 dev_err(dev, "invalid bit number\n");
506 else 506 else
507 isr_statistics.test++; 507 isr_statistics.test++;
508 } else { 508 } else {
509 if (hw_intr_clear(udc, bit)) 509 if (hw_intr_clear(ci, bit))
510 dev_err(dev, "invalid bit number\n"); 510 dev_err(dev, "invalid bit number\n");
511 } 511 }
512 spin_unlock_irqrestore(&udc->lock, flags); 512 spin_unlock_irqrestore(&ci->lock, flags);
513 513
514 done: 514 done:
515 return count; 515 return count;
@@ -524,18 +524,18 @@ static DEVICE_ATTR(inters, S_IRUSR | S_IWUSR, show_inters, store_inters);
524static ssize_t show_port_test(struct device *dev, 524static ssize_t show_port_test(struct device *dev,
525 struct device_attribute *attr, char *buf) 525 struct device_attribute *attr, char *buf)
526{ 526{
527 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 527 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
528 unsigned long flags; 528 unsigned long flags;
529 unsigned mode; 529 unsigned mode;
530 530
531 if (attr == NULL || buf == NULL) { 531 if (attr == NULL || buf == NULL) {
532 dev_err(udc->dev, "EINVAL\n"); 532 dev_err(ci->dev, "EINVAL\n");
533 return 0; 533 return 0;
534 } 534 }
535 535
536 spin_lock_irqsave(&udc->lock, flags); 536 spin_lock_irqsave(&ci->lock, flags);
537 mode = hw_port_test_get(udc); 537 mode = hw_port_test_get(ci);
538 spin_unlock_irqrestore(&udc->lock, flags); 538 spin_unlock_irqrestore(&ci->lock, flags);
539 539
540 return scnprintf(buf, PAGE_SIZE, "mode = %u\n", mode); 540 return scnprintf(buf, PAGE_SIZE, "mode = %u\n", mode);
541} 541}
@@ -549,24 +549,24 @@ static ssize_t store_port_test(struct device *dev,
549 struct device_attribute *attr, 549 struct device_attribute *attr,
550 const char *buf, size_t count) 550 const char *buf, size_t count)
551{ 551{
552 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 552 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
553 unsigned long flags; 553 unsigned long flags;
554 unsigned mode; 554 unsigned mode;
555 555
556 if (attr == NULL || buf == NULL) { 556 if (attr == NULL || buf == NULL) {
557 dev_err(udc->dev, "[%s] EINVAL\n", __func__); 557 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
558 goto done; 558 goto done;
559 } 559 }
560 560
561 if (sscanf(buf, "%u", &mode) != 1) { 561 if (sscanf(buf, "%u", &mode) != 1) {
562 dev_err(udc->dev, "<mode>: set port test mode"); 562 dev_err(ci->dev, "<mode>: set port test mode");
563 goto done; 563 goto done;
564 } 564 }
565 565
566 spin_lock_irqsave(&udc->lock, flags); 566 spin_lock_irqsave(&ci->lock, flags);
567 if (hw_port_test_set(udc, mode)) 567 if (hw_port_test_set(ci, mode))
568 dev_err(udc->dev, "invalid mode\n"); 568 dev_err(ci->dev, "invalid mode\n");
569 spin_unlock_irqrestore(&udc->lock, flags); 569 spin_unlock_irqrestore(&ci->lock, flags);
570 570
571 done: 571 done:
572 return count; 572 return count;
@@ -582,20 +582,20 @@ static DEVICE_ATTR(port_test, S_IRUSR | S_IWUSR,
582static ssize_t show_qheads(struct device *dev, struct device_attribute *attr, 582static ssize_t show_qheads(struct device *dev, struct device_attribute *attr,
583 char *buf) 583 char *buf)
584{ 584{
585 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 585 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
586 unsigned long flags; 586 unsigned long flags;
587 unsigned i, j, n = 0; 587 unsigned i, j, n = 0;
588 588
589 if (attr == NULL || buf == NULL) { 589 if (attr == NULL || buf == NULL) {
590 dev_err(udc->dev, "[%s] EINVAL\n", __func__); 590 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
591 return 0; 591 return 0;
592 } 592 }
593 593
594 spin_lock_irqsave(&udc->lock, flags); 594 spin_lock_irqsave(&ci->lock, flags);
595 for (i = 0; i < udc->hw_ep_max/2; i++) { 595 for (i = 0; i < ci->hw_ep_max/2; i++) {
596 struct ci13xxx_ep *mEpRx = &udc->ci13xxx_ep[i]; 596 struct ci13xxx_ep *mEpRx = &ci->ci13xxx_ep[i];
597 struct ci13xxx_ep *mEpTx = 597 struct ci13xxx_ep *mEpTx =
598 &udc->ci13xxx_ep[i + udc->hw_ep_max/2]; 598 &ci->ci13xxx_ep[i + ci->hw_ep_max/2];
599 n += scnprintf(buf + n, PAGE_SIZE - n, 599 n += scnprintf(buf + n, PAGE_SIZE - n,
600 "EP=%02i: RX=%08X TX=%08X\n", 600 "EP=%02i: RX=%08X TX=%08X\n",
601 i, (u32)mEpRx->qh.dma, (u32)mEpTx->qh.dma); 601 i, (u32)mEpRx->qh.dma, (u32)mEpTx->qh.dma);
@@ -606,7 +606,7 @@ static ssize_t show_qheads(struct device *dev, struct device_attribute *attr,
606 *((u32 *)mEpTx->qh.ptr + j)); 606 *((u32 *)mEpTx->qh.ptr + j));
607 } 607 }
608 } 608 }
609 spin_unlock_irqrestore(&udc->lock, flags); 609 spin_unlock_irqrestore(&ci->lock, flags);
610 610
611 return n; 611 return n;
612} 612}
@@ -621,25 +621,25 @@ static DEVICE_ATTR(qheads, S_IRUSR, show_qheads, NULL);
621static ssize_t show_registers(struct device *dev, 621static ssize_t show_registers(struct device *dev,
622 struct device_attribute *attr, char *buf) 622 struct device_attribute *attr, char *buf)
623{ 623{
624 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 624 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
625 unsigned long flags; 625 unsigned long flags;
626 u32 *dump; 626 u32 *dump;
627 unsigned i, k, n = 0; 627 unsigned i, k, n = 0;
628 628
629 if (attr == NULL || buf == NULL) { 629 if (attr == NULL || buf == NULL) {
630 dev_err(udc->dev, "[%s] EINVAL\n", __func__); 630 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
631 return 0; 631 return 0;
632 } 632 }
633 633
634 dump = kmalloc(sizeof(u32) * DUMP_ENTRIES, GFP_KERNEL); 634 dump = kmalloc(sizeof(u32) * DUMP_ENTRIES, GFP_KERNEL);
635 if (!dump) { 635 if (!dump) {
636 dev_err(udc->dev, "%s: out of memory\n", __func__); 636 dev_err(ci->dev, "%s: out of memory\n", __func__);
637 return 0; 637 return 0;
638 } 638 }
639 639
640 spin_lock_irqsave(&udc->lock, flags); 640 spin_lock_irqsave(&ci->lock, flags);
641 k = hw_register_read(udc, dump, DUMP_ENTRIES); 641 k = hw_register_read(ci, dump, DUMP_ENTRIES);
642 spin_unlock_irqrestore(&udc->lock, flags); 642 spin_unlock_irqrestore(&ci->lock, flags);
643 643
644 for (i = 0; i < k; i++) { 644 for (i = 0; i < k; i++) {
645 n += scnprintf(buf + n, PAGE_SIZE - n, 645 n += scnprintf(buf + n, PAGE_SIZE - n,
@@ -660,24 +660,24 @@ static ssize_t store_registers(struct device *dev,
660 struct device_attribute *attr, 660 struct device_attribute *attr,
661 const char *buf, size_t count) 661 const char *buf, size_t count)
662{ 662{
663 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 663 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
664 unsigned long addr, data, flags; 664 unsigned long addr, data, flags;
665 665
666 if (attr == NULL || buf == NULL) { 666 if (attr == NULL || buf == NULL) {
667 dev_err(udc->dev, "[%s] EINVAL\n", __func__); 667 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
668 goto done; 668 goto done;
669 } 669 }
670 670
671 if (sscanf(buf, "%li %li", &addr, &data) != 2) { 671 if (sscanf(buf, "%li %li", &addr, &data) != 2) {
672 dev_err(udc->dev, 672 dev_err(ci->dev,
673 "<addr> <data>: write data to register address\n"); 673 "<addr> <data>: write data to register address\n");
674 goto done; 674 goto done;
675 } 675 }
676 676
677 spin_lock_irqsave(&udc->lock, flags); 677 spin_lock_irqsave(&ci->lock, flags);
678 if (hw_register_write(udc, addr, data)) 678 if (hw_register_write(ci, addr, data))
679 dev_err(udc->dev, "invalid address range\n"); 679 dev_err(ci->dev, "invalid address range\n");
680 spin_unlock_irqrestore(&udc->lock, flags); 680 spin_unlock_irqrestore(&ci->lock, flags);
681 681
682 done: 682 done:
683 return count; 683 return count;
@@ -693,34 +693,34 @@ static DEVICE_ATTR(registers, S_IRUSR | S_IWUSR,
693static ssize_t show_requests(struct device *dev, struct device_attribute *attr, 693static ssize_t show_requests(struct device *dev, struct device_attribute *attr,
694 char *buf) 694 char *buf)
695{ 695{
696 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 696 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
697 unsigned long flags; 697 unsigned long flags;
698 struct list_head *ptr = NULL; 698 struct list_head *ptr = NULL;
699 struct ci13xxx_req *req = NULL; 699 struct ci13xxx_req *req = NULL;
700 unsigned i, j, n = 0, qSize = sizeof(struct ci13xxx_td)/sizeof(u32); 700 unsigned i, j, n = 0, qSize = sizeof(struct ci13xxx_td)/sizeof(u32);
701 701
702 if (attr == NULL || buf == NULL) { 702 if (attr == NULL || buf == NULL) {
703 dev_err(udc->dev, "[%s] EINVAL\n", __func__); 703 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
704 return 0; 704 return 0;
705 } 705 }
706 706
707 spin_lock_irqsave(&udc->lock, flags); 707 spin_lock_irqsave(&ci->lock, flags);
708 for (i = 0; i < udc->hw_ep_max; i++) 708 for (i = 0; i < ci->hw_ep_max; i++)
709 list_for_each(ptr, &udc->ci13xxx_ep[i].qh.queue) 709 list_for_each(ptr, &ci->ci13xxx_ep[i].qh.queue)
710 { 710 {
711 req = list_entry(ptr, struct ci13xxx_req, queue); 711 req = list_entry(ptr, struct ci13xxx_req, queue);
712 712
713 n += scnprintf(buf + n, PAGE_SIZE - n, 713 n += scnprintf(buf + n, PAGE_SIZE - n,
714 "EP=%02i: TD=%08X %s\n", 714 "EP=%02i: TD=%08X %s\n",
715 i % udc->hw_ep_max/2, (u32)req->dma, 715 i % ci->hw_ep_max/2, (u32)req->dma,
716 ((i < udc->hw_ep_max/2) ? "RX" : "TX")); 716 ((i < ci->hw_ep_max/2) ? "RX" : "TX"));
717 717
718 for (j = 0; j < qSize; j++) 718 for (j = 0; j < qSize; j++)
719 n += scnprintf(buf + n, PAGE_SIZE - n, 719 n += scnprintf(buf + n, PAGE_SIZE - n,
720 " %04X: %08X\n", j, 720 " %04X: %08X\n", j,
721 *((u32 *)req->ptr + j)); 721 *((u32 *)req->ptr + j));
722 } 722 }
723 spin_unlock_irqrestore(&udc->lock, flags); 723 spin_unlock_irqrestore(&ci->lock, flags);
724 724
725 return n; 725 return n;
726} 726}
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 9eacd21c0cd9..ebff9f4f56ec 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -116,7 +116,8 @@ static int host_start(struct ci13xxx *ci)
116 hcd->regs = ci->hw_bank.abs; 116 hcd->regs = ci->hw_bank.abs;
117 hcd->has_tt = 1; 117 hcd->has_tt = 1;
118 118
119 hcd->power_budget = ci->udc_driver->power_budget; 119 hcd->power_budget = ci->platdata->power_budget;
120 hcd->phy = ci->transceiver;
120 121
121 ehci = hcd_to_ehci(hcd); 122 ehci = hcd_to_ehci(hcd);
122 ehci->caps = ci->hw_bank.cap; 123 ehci->caps = ci->hw_bank.cap;
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 51f96942dc5e..c7a032a4f0c5 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -14,6 +14,7 @@
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/dmapool.h> 15#include <linux/dmapool.h>
16#include <linux/dma-mapping.h> 16#include <linux/dma-mapping.h>
17#include <linux/err.h>
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/platform_device.h> 19#include <linux/platform_device.h>
19#include <linux/module.h> 20#include <linux/module.h>
@@ -66,11 +67,11 @@ static inline int hw_ep_bit(int num, int dir)
66 return num + (dir ? 16 : 0); 67 return num + (dir ? 16 : 0);
67} 68}
68 69
69static inline int ep_to_bit(struct ci13xxx *udc, int n) 70static inline int ep_to_bit(struct ci13xxx *ci, int n)
70{ 71{
71 int fill = 16 - udc->hw_ep_max / 2; 72 int fill = 16 - ci->hw_ep_max / 2;
72 73
73 if (n >= udc->hw_ep_max / 2) 74 if (n >= ci->hw_ep_max / 2)
74 n += fill; 75 n += fill;
75 76
76 return n; 77 return n;
@@ -83,17 +84,17 @@ static inline int ep_to_bit(struct ci13xxx *udc, int n)
83 * 84 *
84 * This function returns an error code 85 * This function returns an error code
85 */ 86 */
86static int hw_device_state(struct ci13xxx *udc, u32 dma) 87static int hw_device_state(struct ci13xxx *ci, u32 dma)
87{ 88{
88 if (dma) { 89 if (dma) {
89 hw_write(udc, OP_ENDPTLISTADDR, ~0, dma); 90 hw_write(ci, OP_ENDPTLISTADDR, ~0, dma);
90 /* interrupt, error, port change, reset, sleep/suspend */ 91 /* interrupt, error, port change, reset, sleep/suspend */
91 hw_write(udc, OP_USBINTR, ~0, 92 hw_write(ci, OP_USBINTR, ~0,
92 USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); 93 USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI);
93 hw_write(udc, OP_USBCMD, USBCMD_RS, USBCMD_RS); 94 hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS);
94 } else { 95 } else {
95 hw_write(udc, OP_USBCMD, USBCMD_RS, 0); 96 hw_write(ci, OP_USBCMD, USBCMD_RS, 0);
96 hw_write(udc, OP_USBINTR, ~0, 0); 97 hw_write(ci, OP_USBINTR, ~0, 0);
97 } 98 }
98 return 0; 99 return 0;
99} 100}
@@ -105,16 +106,16 @@ static int hw_device_state(struct ci13xxx *udc, u32 dma)
105 * 106 *
106 * This function returns an error code 107 * This function returns an error code
107 */ 108 */
108static int hw_ep_flush(struct ci13xxx *udc, int num, int dir) 109static int hw_ep_flush(struct ci13xxx *ci, int num, int dir)
109{ 110{
110 int n = hw_ep_bit(num, dir); 111 int n = hw_ep_bit(num, dir);
111 112
112 do { 113 do {
113 /* flush any pending transfer */ 114 /* flush any pending transfer */
114 hw_write(udc, OP_ENDPTFLUSH, BIT(n), BIT(n)); 115 hw_write(ci, OP_ENDPTFLUSH, BIT(n), BIT(n));
115 while (hw_read(udc, OP_ENDPTFLUSH, BIT(n))) 116 while (hw_read(ci, OP_ENDPTFLUSH, BIT(n)))
116 cpu_relax(); 117 cpu_relax();
117 } while (hw_read(udc, OP_ENDPTSTAT, BIT(n))); 118 } while (hw_read(ci, OP_ENDPTSTAT, BIT(n)));
118 119
119 return 0; 120 return 0;
120} 121}
@@ -126,10 +127,10 @@ static int hw_ep_flush(struct ci13xxx *udc, int num, int dir)
126 * 127 *
127 * This function returns an error code 128 * This function returns an error code
128 */ 129 */
129static int hw_ep_disable(struct ci13xxx *udc, int num, int dir) 130static int hw_ep_disable(struct ci13xxx *ci, int num, int dir)
130{ 131{
131 hw_ep_flush(udc, num, dir); 132 hw_ep_flush(ci, num, dir);
132 hw_write(udc, OP_ENDPTCTRL + num, 133 hw_write(ci, OP_ENDPTCTRL + num,
133 dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0); 134 dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0);
134 return 0; 135 return 0;
135} 136}
@@ -142,7 +143,7 @@ static int hw_ep_disable(struct ci13xxx *udc, int num, int dir)
142 * 143 *
143 * This function returns an error code 144 * This function returns an error code
144 */ 145 */
145static int hw_ep_enable(struct ci13xxx *udc, int num, int dir, int type) 146static int hw_ep_enable(struct ci13xxx *ci, int num, int dir, int type)
146{ 147{
147 u32 mask, data; 148 u32 mask, data;
148 149
@@ -165,7 +166,7 @@ static int hw_ep_enable(struct ci13xxx *udc, int num, int dir, int type)
165 mask |= ENDPTCTRL_RXE; /* enable */ 166 mask |= ENDPTCTRL_RXE; /* enable */
166 data |= ENDPTCTRL_RXE; 167 data |= ENDPTCTRL_RXE;
167 } 168 }
168 hw_write(udc, OP_ENDPTCTRL + num, mask, data); 169 hw_write(ci, OP_ENDPTCTRL + num, mask, data);
169 return 0; 170 return 0;
170} 171}
171 172
@@ -176,11 +177,11 @@ static int hw_ep_enable(struct ci13xxx *udc, int num, int dir, int type)
176 * 177 *
177 * This function returns 1 if endpoint halted 178 * This function returns 1 if endpoint halted
178 */ 179 */
179static int hw_ep_get_halt(struct ci13xxx *udc, int num, int dir) 180static int hw_ep_get_halt(struct ci13xxx *ci, int num, int dir)
180{ 181{
181 u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; 182 u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
182 183
183 return hw_read(udc, OP_ENDPTCTRL + num, mask) ? 1 : 0; 184 return hw_read(ci, OP_ENDPTCTRL + num, mask) ? 1 : 0;
184} 185}
185 186
186/** 187/**
@@ -190,10 +191,10 @@ static int hw_ep_get_halt(struct ci13xxx *udc, int num, int dir)
190 * 191 *
191 * This function returns setup status 192 * This function returns setup status
192 */ 193 */
193static int hw_test_and_clear_setup_status(struct ci13xxx *udc, int n) 194static int hw_test_and_clear_setup_status(struct ci13xxx *ci, int n)
194{ 195{
195 n = ep_to_bit(udc, n); 196 n = ep_to_bit(ci, n);
196 return hw_test_and_clear(udc, OP_ENDPTSETUPSTAT, BIT(n)); 197 return hw_test_and_clear(ci, OP_ENDPTSETUPSTAT, BIT(n));
197} 198}
198 199
199/** 200/**
@@ -204,18 +205,18 @@ static int hw_test_and_clear_setup_status(struct ci13xxx *udc, int n)
204 * 205 *
205 * This function returns an error code 206 * This function returns an error code
206 */ 207 */
207static int hw_ep_prime(struct ci13xxx *udc, int num, int dir, int is_ctrl) 208static int hw_ep_prime(struct ci13xxx *ci, int num, int dir, int is_ctrl)
208{ 209{
209 int n = hw_ep_bit(num, dir); 210 int n = hw_ep_bit(num, dir);
210 211
211 if (is_ctrl && dir == RX && hw_read(udc, OP_ENDPTSETUPSTAT, BIT(num))) 212 if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num)))
212 return -EAGAIN; 213 return -EAGAIN;
213 214
214 hw_write(udc, OP_ENDPTPRIME, BIT(n), BIT(n)); 215 hw_write(ci, OP_ENDPTPRIME, BIT(n), BIT(n));
215 216
216 while (hw_read(udc, OP_ENDPTPRIME, BIT(n))) 217 while (hw_read(ci, OP_ENDPTPRIME, BIT(n)))
217 cpu_relax(); 218 cpu_relax();
218 if (is_ctrl && dir == RX && hw_read(udc, OP_ENDPTSETUPSTAT, BIT(num))) 219 if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num)))
219 return -EAGAIN; 220 return -EAGAIN;
220 221
221 /* status shoult be tested according with manual but it doesn't work */ 222 /* status shoult be tested according with manual but it doesn't work */
@@ -231,7 +232,7 @@ static int hw_ep_prime(struct ci13xxx *udc, int num, int dir, int is_ctrl)
231 * 232 *
232 * This function returns an error code 233 * This function returns an error code
233 */ 234 */
234static int hw_ep_set_halt(struct ci13xxx *udc, int num, int dir, int value) 235static int hw_ep_set_halt(struct ci13xxx *ci, int num, int dir, int value)
235{ 236{
236 if (value != 0 && value != 1) 237 if (value != 0 && value != 1)
237 return -EINVAL; 238 return -EINVAL;
@@ -242,9 +243,9 @@ static int hw_ep_set_halt(struct ci13xxx *udc, int num, int dir, int value)
242 u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR; 243 u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR;
243 244
244 /* data toggle - reserved for EP0 but it's in ESS */ 245 /* data toggle - reserved for EP0 but it's in ESS */
245 hw_write(udc, reg, mask_xs|mask_xr, 246 hw_write(ci, reg, mask_xs|mask_xr,
246 value ? mask_xs : mask_xr); 247 value ? mask_xs : mask_xr);
247 } while (value != hw_ep_get_halt(udc, num, dir)); 248 } while (value != hw_ep_get_halt(ci, num, dir));
248 249
249 return 0; 250 return 0;
250} 251}
@@ -254,10 +255,10 @@ static int hw_ep_set_halt(struct ci13xxx *udc, int num, int dir, int value)
254 * 255 *
255 * This function returns true if high speed port 256 * This function returns true if high speed port
256 */ 257 */
257static int hw_port_is_high_speed(struct ci13xxx *udc) 258static int hw_port_is_high_speed(struct ci13xxx *ci)
258{ 259{
259 return udc->hw_bank.lpm ? hw_read(udc, OP_DEVLC, DEVLC_PSPD) : 260 return ci->hw_bank.lpm ? hw_read(ci, OP_DEVLC, DEVLC_PSPD) :
260 hw_read(udc, OP_PORTSC, PORTSC_HSP); 261 hw_read(ci, OP_PORTSC, PORTSC_HSP);
261} 262}
262 263
263/** 264/**
@@ -265,9 +266,9 @@ static int hw_port_is_high_speed(struct ci13xxx *udc)
265 * 266 *
266 * This function returns register data 267 * This function returns register data
267 */ 268 */
268static u32 hw_read_intr_enable(struct ci13xxx *udc) 269static u32 hw_read_intr_enable(struct ci13xxx *ci)
269{ 270{
270 return hw_read(udc, OP_USBINTR, ~0); 271 return hw_read(ci, OP_USBINTR, ~0);
271} 272}
272 273
273/** 274/**
@@ -275,9 +276,9 @@ static u32 hw_read_intr_enable(struct ci13xxx *udc)
275 * 276 *
276 * This function returns register data 277 * This function returns register data
277 */ 278 */
278static u32 hw_read_intr_status(struct ci13xxx *udc) 279static u32 hw_read_intr_status(struct ci13xxx *ci)
279{ 280{
280 return hw_read(udc, OP_USBSTS, ~0); 281 return hw_read(ci, OP_USBSTS, ~0);
281} 282}
282 283
283/** 284/**
@@ -287,10 +288,10 @@ static u32 hw_read_intr_status(struct ci13xxx *udc)
287 * 288 *
288 * This function returns complete status 289 * This function returns complete status
289 */ 290 */
290static int hw_test_and_clear_complete(struct ci13xxx *udc, int n) 291static int hw_test_and_clear_complete(struct ci13xxx *ci, int n)
291{ 292{
292 n = ep_to_bit(udc, n); 293 n = ep_to_bit(ci, n);
293 return hw_test_and_clear(udc, OP_ENDPTCOMPLETE, BIT(n)); 294 return hw_test_and_clear(ci, OP_ENDPTCOMPLETE, BIT(n));
294} 295}
295 296
296/** 297/**
@@ -299,11 +300,11 @@ static int hw_test_and_clear_complete(struct ci13xxx *udc, int n)
299 * 300 *
300 * This function returns active interrutps 301 * This function returns active interrutps
301 */ 302 */
302static u32 hw_test_and_clear_intr_active(struct ci13xxx *udc) 303static u32 hw_test_and_clear_intr_active(struct ci13xxx *ci)
303{ 304{
304 u32 reg = hw_read_intr_status(udc) & hw_read_intr_enable(udc); 305 u32 reg = hw_read_intr_status(ci) & hw_read_intr_enable(ci);
305 306
306 hw_write(udc, OP_USBSTS, ~0, reg); 307 hw_write(ci, OP_USBSTS, ~0, reg);
307 return reg; 308 return reg;
308} 309}
309 310
@@ -313,9 +314,9 @@ static u32 hw_test_and_clear_intr_active(struct ci13xxx *udc)
313 * 314 *
314 * This function returns guard value 315 * This function returns guard value
315 */ 316 */
316static int hw_test_and_clear_setup_guard(struct ci13xxx *udc) 317static int hw_test_and_clear_setup_guard(struct ci13xxx *ci)
317{ 318{
318 return hw_test_and_write(udc, OP_USBCMD, USBCMD_SUTW, 0); 319 return hw_test_and_write(ci, OP_USBCMD, USBCMD_SUTW, 0);
319} 320}
320 321
321/** 322/**
@@ -324,9 +325,9 @@ static int hw_test_and_clear_setup_guard(struct ci13xxx *udc)
324 * 325 *
325 * This function returns guard value 326 * This function returns guard value
326 */ 327 */
327static int hw_test_and_set_setup_guard(struct ci13xxx *udc) 328static int hw_test_and_set_setup_guard(struct ci13xxx *ci)
328{ 329{
329 return hw_test_and_write(udc, OP_USBCMD, USBCMD_SUTW, USBCMD_SUTW); 330 return hw_test_and_write(ci, OP_USBCMD, USBCMD_SUTW, USBCMD_SUTW);
330} 331}
331 332
332/** 333/**
@@ -336,9 +337,9 @@ static int hw_test_and_set_setup_guard(struct ci13xxx *udc)
336 * This function explicitly sets the address, without the "USBADRA" (advance) 337 * This function explicitly sets the address, without the "USBADRA" (advance)
337 * feature, which is not supported by older versions of the controller. 338 * feature, which is not supported by older versions of the controller.
338 */ 339 */
339static void hw_usb_set_address(struct ci13xxx *udc, u8 value) 340static void hw_usb_set_address(struct ci13xxx *ci, u8 value)
340{ 341{
341 hw_write(udc, OP_DEVICEADDR, DEVICEADDR_USBADR, 342 hw_write(ci, OP_DEVICEADDR, DEVICEADDR_USBADR,
342 value << ffs_nr(DEVICEADDR_USBADR)); 343 value << ffs_nr(DEVICEADDR_USBADR));
343} 344}
344 345
@@ -348,21 +349,21 @@ static void hw_usb_set_address(struct ci13xxx *udc, u8 value)
348 * 349 *
349 * This function returns an error code 350 * This function returns an error code
350 */ 351 */
351static int hw_usb_reset(struct ci13xxx *udc) 352static int hw_usb_reset(struct ci13xxx *ci)
352{ 353{
353 hw_usb_set_address(udc, 0); 354 hw_usb_set_address(ci, 0);
354 355
355 /* ESS flushes only at end?!? */ 356 /* ESS flushes only at end?!? */
356 hw_write(udc, OP_ENDPTFLUSH, ~0, ~0); 357 hw_write(ci, OP_ENDPTFLUSH, ~0, ~0);
357 358
358 /* clear setup token semaphores */ 359 /* clear setup token semaphores */
359 hw_write(udc, OP_ENDPTSETUPSTAT, 0, 0); 360 hw_write(ci, OP_ENDPTSETUPSTAT, 0, 0);
360 361
361 /* clear complete status */ 362 /* clear complete status */
362 hw_write(udc, OP_ENDPTCOMPLETE, 0, 0); 363 hw_write(ci, OP_ENDPTCOMPLETE, 0, 0);
363 364
364 /* wait until all bits cleared */ 365 /* wait until all bits cleared */
365 while (hw_read(udc, OP_ENDPTPRIME, ~0)) 366 while (hw_read(ci, OP_ENDPTPRIME, ~0))
366 udelay(10); /* not RTOS friendly */ 367 udelay(10); /* not RTOS friendly */
367 368
368 /* reset all endpoints ? */ 369 /* reset all endpoints ? */
@@ -394,7 +395,7 @@ static inline u8 _usb_addr(struct ci13xxx_ep *ep)
394 */ 395 */
395static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) 396static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
396{ 397{
397 struct ci13xxx *udc = mEp->udc; 398 struct ci13xxx *ci = mEp->ci;
398 unsigned i; 399 unsigned i;
399 int ret = 0; 400 int ret = 0;
400 unsigned length = mReq->req.length; 401 unsigned length = mReq->req.length;
@@ -417,7 +418,7 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
417 if (!mReq->req.no_interrupt) 418 if (!mReq->req.no_interrupt)
418 mReq->zptr->token |= TD_IOC; 419 mReq->zptr->token |= TD_IOC;
419 } 420 }
420 ret = usb_gadget_map_request(&udc->gadget, &mReq->req, mEp->dir); 421 ret = usb_gadget_map_request(&ci->gadget, &mReq->req, mEp->dir);
421 if (ret) 422 if (ret)
422 return ret; 423 return ret;
423 424
@@ -453,13 +454,13 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
453 else 454 else
454 mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK; 455 mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK;
455 wmb(); 456 wmb();
456 if (hw_read(udc, OP_ENDPTPRIME, BIT(n))) 457 if (hw_read(ci, OP_ENDPTPRIME, BIT(n)))
457 goto done; 458 goto done;
458 do { 459 do {
459 hw_write(udc, OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW); 460 hw_write(ci, OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW);
460 tmp_stat = hw_read(udc, OP_ENDPTSTAT, BIT(n)); 461 tmp_stat = hw_read(ci, OP_ENDPTSTAT, BIT(n));
461 } while (!hw_read(udc, OP_USBCMD, USBCMD_ATDTW)); 462 } while (!hw_read(ci, OP_USBCMD, USBCMD_ATDTW));
462 hw_write(udc, OP_USBCMD, USBCMD_ATDTW, 0); 463 hw_write(ci, OP_USBCMD, USBCMD_ATDTW, 0);
463 if (tmp_stat) 464 if (tmp_stat)
464 goto done; 465 goto done;
465 } 466 }
@@ -471,7 +472,7 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
471 472
472 wmb(); /* synchronize before ep prime */ 473 wmb(); /* synchronize before ep prime */
473 474
474 ret = hw_ep_prime(udc, mEp->num, mEp->dir, 475 ret = hw_ep_prime(ci, mEp->num, mEp->dir,
475 mEp->type == USB_ENDPOINT_XFER_CONTROL); 476 mEp->type == USB_ENDPOINT_XFER_CONTROL);
476done: 477done:
477 return ret; 478 return ret;
@@ -501,7 +502,7 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
501 502
502 mReq->req.status = 0; 503 mReq->req.status = 0;
503 504
504 usb_gadget_unmap_request(&mEp->udc->gadget, &mReq->req, mEp->dir); 505 usb_gadget_unmap_request(&mEp->ci->gadget, &mReq->req, mEp->dir);
505 506
506 mReq->req.status = mReq->ptr->token & TD_STATUS; 507 mReq->req.status = mReq->ptr->token & TD_STATUS;
507 if ((TD_STATUS_HALTED & mReq->req.status) != 0) 508 if ((TD_STATUS_HALTED & mReq->req.status) != 0)
@@ -533,7 +534,7 @@ __acquires(mEp->lock)
533 if (mEp == NULL) 534 if (mEp == NULL)
534 return -EINVAL; 535 return -EINVAL;
535 536
536 hw_ep_flush(mEp->udc, mEp->num, mEp->dir); 537 hw_ep_flush(mEp->ci, mEp->num, mEp->dir);
537 538
538 while (!list_empty(&mEp->qh.queue)) { 539 while (!list_empty(&mEp->qh.queue)) {
539 540
@@ -562,33 +563,33 @@ __acquires(mEp->lock)
562static int _gadget_stop_activity(struct usb_gadget *gadget) 563static int _gadget_stop_activity(struct usb_gadget *gadget)
563{ 564{
564 struct usb_ep *ep; 565 struct usb_ep *ep;
565 struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); 566 struct ci13xxx *ci = container_of(gadget, struct ci13xxx, gadget);
566 unsigned long flags; 567 unsigned long flags;
567 568
568 spin_lock_irqsave(&udc->lock, flags); 569 spin_lock_irqsave(&ci->lock, flags);
569 udc->gadget.speed = USB_SPEED_UNKNOWN; 570 ci->gadget.speed = USB_SPEED_UNKNOWN;
570 udc->remote_wakeup = 0; 571 ci->remote_wakeup = 0;
571 udc->suspended = 0; 572 ci->suspended = 0;
572 spin_unlock_irqrestore(&udc->lock, flags); 573 spin_unlock_irqrestore(&ci->lock, flags);
573 574
574 /* flush all endpoints */ 575 /* flush all endpoints */
575 gadget_for_each_ep(ep, gadget) { 576 gadget_for_each_ep(ep, gadget) {
576 usb_ep_fifo_flush(ep); 577 usb_ep_fifo_flush(ep);
577 } 578 }
578 usb_ep_fifo_flush(&udc->ep0out->ep); 579 usb_ep_fifo_flush(&ci->ep0out->ep);
579 usb_ep_fifo_flush(&udc->ep0in->ep); 580 usb_ep_fifo_flush(&ci->ep0in->ep);
580 581
581 if (udc->driver) 582 if (ci->driver)
582 udc->driver->disconnect(gadget); 583 ci->driver->disconnect(gadget);
583 584
584 /* make sure to disable all endpoints */ 585 /* make sure to disable all endpoints */
585 gadget_for_each_ep(ep, gadget) { 586 gadget_for_each_ep(ep, gadget) {
586 usb_ep_disable(ep); 587 usb_ep_disable(ep);
587 } 588 }
588 589
589 if (udc->status != NULL) { 590 if (ci->status != NULL) {
590 usb_ep_free_request(&udc->ep0in->ep, udc->status); 591 usb_ep_free_request(&ci->ep0in->ep, ci->status);
591 udc->status = NULL; 592 ci->status = NULL;
592 } 593 }
593 594
594 return 0; 595 return 0;
@@ -599,36 +600,36 @@ static int _gadget_stop_activity(struct usb_gadget *gadget)
599 *****************************************************************************/ 600 *****************************************************************************/
600/** 601/**
601 * isr_reset_handler: USB reset interrupt handler 602 * isr_reset_handler: USB reset interrupt handler
602 * @udc: UDC device 603 * @ci: UDC device
603 * 604 *
604 * This function resets USB engine after a bus reset occurred 605 * This function resets USB engine after a bus reset occurred
605 */ 606 */
606static void isr_reset_handler(struct ci13xxx *udc) 607static void isr_reset_handler(struct ci13xxx *ci)
607__releases(udc->lock) 608__releases(ci->lock)
608__acquires(udc->lock) 609__acquires(ci->lock)
609{ 610{
610 int retval; 611 int retval;
611 612
612 dbg_event(0xFF, "BUS RST", 0); 613 dbg_event(0xFF, "BUS RST", 0);
613 614
614 spin_unlock(&udc->lock); 615 spin_unlock(&ci->lock);
615 retval = _gadget_stop_activity(&udc->gadget); 616 retval = _gadget_stop_activity(&ci->gadget);
616 if (retval) 617 if (retval)
617 goto done; 618 goto done;
618 619
619 retval = hw_usb_reset(udc); 620 retval = hw_usb_reset(ci);
620 if (retval) 621 if (retval)
621 goto done; 622 goto done;
622 623
623 udc->status = usb_ep_alloc_request(&udc->ep0in->ep, GFP_ATOMIC); 624 ci->status = usb_ep_alloc_request(&ci->ep0in->ep, GFP_ATOMIC);
624 if (udc->status == NULL) 625 if (ci->status == NULL)
625 retval = -ENOMEM; 626 retval = -ENOMEM;
626 627
627done: 628done:
628 spin_lock(&udc->lock); 629 spin_lock(&ci->lock);
629 630
630 if (retval) 631 if (retval)
631 dev_err(udc->dev, "error: %i\n", retval); 632 dev_err(ci->dev, "error: %i\n", retval);
632} 633}
633 634
634/** 635/**
@@ -649,17 +650,17 @@ static void isr_get_status_complete(struct usb_ep *ep, struct usb_request *req)
649 650
650/** 651/**
651 * isr_get_status_response: get_status request response 652 * isr_get_status_response: get_status request response
652 * @udc: udc struct 653 * @ci: ci struct
653 * @setup: setup request packet 654 * @setup: setup request packet
654 * 655 *
655 * This function returns an error code 656 * This function returns an error code
656 */ 657 */
657static int isr_get_status_response(struct ci13xxx *udc, 658static int isr_get_status_response(struct ci13xxx *ci,
658 struct usb_ctrlrequest *setup) 659 struct usb_ctrlrequest *setup)
659__releases(mEp->lock) 660__releases(mEp->lock)
660__acquires(mEp->lock) 661__acquires(mEp->lock)
661{ 662{
662 struct ci13xxx_ep *mEp = udc->ep0in; 663 struct ci13xxx_ep *mEp = ci->ep0in;
663 struct usb_request *req = NULL; 664 struct usb_request *req = NULL;
664 gfp_t gfp_flags = GFP_ATOMIC; 665 gfp_t gfp_flags = GFP_ATOMIC;
665 int dir, num, retval; 666 int dir, num, retval;
@@ -683,14 +684,14 @@ __acquires(mEp->lock)
683 684
684 if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { 685 if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) {
685 /* Assume that device is bus powered for now. */ 686 /* Assume that device is bus powered for now. */
686 *(u16 *)req->buf = udc->remote_wakeup << 1; 687 *(u16 *)req->buf = ci->remote_wakeup << 1;
687 retval = 0; 688 retval = 0;
688 } else if ((setup->bRequestType & USB_RECIP_MASK) \ 689 } else if ((setup->bRequestType & USB_RECIP_MASK) \
689 == USB_RECIP_ENDPOINT) { 690 == USB_RECIP_ENDPOINT) {
690 dir = (le16_to_cpu(setup->wIndex) & USB_ENDPOINT_DIR_MASK) ? 691 dir = (le16_to_cpu(setup->wIndex) & USB_ENDPOINT_DIR_MASK) ?
691 TX : RX; 692 TX : RX;
692 num = le16_to_cpu(setup->wIndex) & USB_ENDPOINT_NUMBER_MASK; 693 num = le16_to_cpu(setup->wIndex) & USB_ENDPOINT_NUMBER_MASK;
693 *(u16 *)req->buf = hw_ep_get_halt(udc, num, dir); 694 *(u16 *)req->buf = hw_ep_get_halt(ci, num, dir);
694 } 695 }
695 /* else do nothing; reserved for future use */ 696 /* else do nothing; reserved for future use */
696 697
@@ -722,39 +723,39 @@ __acquires(mEp->lock)
722static void 723static void
723isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req) 724isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req)
724{ 725{
725 struct ci13xxx *udc = req->context; 726 struct ci13xxx *ci = req->context;
726 unsigned long flags; 727 unsigned long flags;
727 728
728 if (udc->setaddr) { 729 if (ci->setaddr) {
729 hw_usb_set_address(udc, udc->address); 730 hw_usb_set_address(ci, ci->address);
730 udc->setaddr = false; 731 ci->setaddr = false;
731 } 732 }
732 733
733 spin_lock_irqsave(&udc->lock, flags); 734 spin_lock_irqsave(&ci->lock, flags);
734 if (udc->test_mode) 735 if (ci->test_mode)
735 hw_port_test_set(udc, udc->test_mode); 736 hw_port_test_set(ci, ci->test_mode);
736 spin_unlock_irqrestore(&udc->lock, flags); 737 spin_unlock_irqrestore(&ci->lock, flags);
737} 738}
738 739
739/** 740/**
740 * isr_setup_status_phase: queues the status phase of a setup transation 741 * isr_setup_status_phase: queues the status phase of a setup transation
741 * @udc: udc struct 742 * @ci: ci struct
742 * 743 *
743 * This function returns an error code 744 * This function returns an error code
744 */ 745 */
745static int isr_setup_status_phase(struct ci13xxx *udc) 746static int isr_setup_status_phase(struct ci13xxx *ci)
746__releases(mEp->lock) 747__releases(mEp->lock)
747__acquires(mEp->lock) 748__acquires(mEp->lock)
748{ 749{
749 int retval; 750 int retval;
750 struct ci13xxx_ep *mEp; 751 struct ci13xxx_ep *mEp;
751 752
752 mEp = (udc->ep0_dir == TX) ? udc->ep0out : udc->ep0in; 753 mEp = (ci->ep0_dir == TX) ? ci->ep0out : ci->ep0in;
753 udc->status->context = udc; 754 ci->status->context = ci;
754 udc->status->complete = isr_setup_status_complete; 755 ci->status->complete = isr_setup_status_complete;
755 756
756 spin_unlock(mEp->lock); 757 spin_unlock(mEp->lock);
757 retval = usb_ep_queue(&mEp->ep, udc->status, GFP_ATOMIC); 758 retval = usb_ep_queue(&mEp->ep, ci->status, GFP_ATOMIC);
758 spin_lock(mEp->lock); 759 spin_lock(mEp->lock);
759 760
760 return retval; 761 return retval;
@@ -789,7 +790,7 @@ __acquires(mEp->lock)
789 spin_unlock(mEp->lock); 790 spin_unlock(mEp->lock);
790 if ((mEp->type == USB_ENDPOINT_XFER_CONTROL) && 791 if ((mEp->type == USB_ENDPOINT_XFER_CONTROL) &&
791 mReq->req.length) 792 mReq->req.length)
792 mEpTemp = mEp->udc->ep0in; 793 mEpTemp = mEp->ci->ep0in;
793 mReq->req.complete(&mEpTemp->ep, &mReq->req); 794 mReq->req.complete(&mEpTemp->ep, &mReq->req);
794 spin_lock(mEp->lock); 795 spin_lock(mEp->lock);
795 } 796 }
@@ -805,48 +806,48 @@ __acquires(mEp->lock)
805 806
806/** 807/**
807 * isr_tr_complete_handler: transaction complete interrupt handler 808 * isr_tr_complete_handler: transaction complete interrupt handler
808 * @udc: UDC descriptor 809 * @ci: UDC descriptor
809 * 810 *
810 * This function handles traffic events 811 * This function handles traffic events
811 */ 812 */
812static void isr_tr_complete_handler(struct ci13xxx *udc) 813static void isr_tr_complete_handler(struct ci13xxx *ci)
813__releases(udc->lock) 814__releases(ci->lock)
814__acquires(udc->lock) 815__acquires(ci->lock)
815{ 816{
816 unsigned i; 817 unsigned i;
817 u8 tmode = 0; 818 u8 tmode = 0;
818 819
819 for (i = 0; i < udc->hw_ep_max; i++) { 820 for (i = 0; i < ci->hw_ep_max; i++) {
820 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; 821 struct ci13xxx_ep *mEp = &ci->ci13xxx_ep[i];
821 int type, num, dir, err = -EINVAL; 822 int type, num, dir, err = -EINVAL;
822 struct usb_ctrlrequest req; 823 struct usb_ctrlrequest req;
823 824
824 if (mEp->ep.desc == NULL) 825 if (mEp->ep.desc == NULL)
825 continue; /* not configured */ 826 continue; /* not configured */
826 827
827 if (hw_test_and_clear_complete(udc, i)) { 828 if (hw_test_and_clear_complete(ci, i)) {
828 err = isr_tr_complete_low(mEp); 829 err = isr_tr_complete_low(mEp);
829 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) { 830 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) {
830 if (err > 0) /* needs status phase */ 831 if (err > 0) /* needs status phase */
831 err = isr_setup_status_phase(udc); 832 err = isr_setup_status_phase(ci);
832 if (err < 0) { 833 if (err < 0) {
833 dbg_event(_usb_addr(mEp), 834 dbg_event(_usb_addr(mEp),
834 "ERROR", err); 835 "ERROR", err);
835 spin_unlock(&udc->lock); 836 spin_unlock(&ci->lock);
836 if (usb_ep_set_halt(&mEp->ep)) 837 if (usb_ep_set_halt(&mEp->ep))
837 dev_err(udc->dev, 838 dev_err(ci->dev,
838 "error: ep_set_halt\n"); 839 "error: ep_set_halt\n");
839 spin_lock(&udc->lock); 840 spin_lock(&ci->lock);
840 } 841 }
841 } 842 }
842 } 843 }
843 844
844 if (mEp->type != USB_ENDPOINT_XFER_CONTROL || 845 if (mEp->type != USB_ENDPOINT_XFER_CONTROL ||
845 !hw_test_and_clear_setup_status(udc, i)) 846 !hw_test_and_clear_setup_status(ci, i))
846 continue; 847 continue;
847 848
848 if (i != 0) { 849 if (i != 0) {
849 dev_warn(udc->dev, "ctrl traffic at endpoint %d\n", i); 850 dev_warn(ci->dev, "ctrl traffic at endpoint %d\n", i);
850 continue; 851 continue;
851 } 852 }
852 853
@@ -854,18 +855,18 @@ __acquires(udc->lock)
854 * Flush data and handshake transactions of previous 855 * Flush data and handshake transactions of previous
855 * setup packet. 856 * setup packet.
856 */ 857 */
857 _ep_nuke(udc->ep0out); 858 _ep_nuke(ci->ep0out);
858 _ep_nuke(udc->ep0in); 859 _ep_nuke(ci->ep0in);
859 860
860 /* read_setup_packet */ 861 /* read_setup_packet */
861 do { 862 do {
862 hw_test_and_set_setup_guard(udc); 863 hw_test_and_set_setup_guard(ci);
863 memcpy(&req, &mEp->qh.ptr->setup, sizeof(req)); 864 memcpy(&req, &mEp->qh.ptr->setup, sizeof(req));
864 } while (!hw_test_and_clear_setup_guard(udc)); 865 } while (!hw_test_and_clear_setup_guard(ci));
865 866
866 type = req.bRequestType; 867 type = req.bRequestType;
867 868
868 udc->ep0_dir = (type & USB_DIR_IN) ? TX : RX; 869 ci->ep0_dir = (type & USB_DIR_IN) ? TX : RX;
869 870
870 dbg_setup(_usb_addr(mEp), &req); 871 dbg_setup(_usb_addr(mEp), &req);
871 872
@@ -880,23 +881,23 @@ __acquires(udc->lock)
880 dir = num & USB_ENDPOINT_DIR_MASK; 881 dir = num & USB_ENDPOINT_DIR_MASK;
881 num &= USB_ENDPOINT_NUMBER_MASK; 882 num &= USB_ENDPOINT_NUMBER_MASK;
882 if (dir) /* TX */ 883 if (dir) /* TX */
883 num += udc->hw_ep_max/2; 884 num += ci->hw_ep_max/2;
884 if (!udc->ci13xxx_ep[num].wedge) { 885 if (!ci->ci13xxx_ep[num].wedge) {
885 spin_unlock(&udc->lock); 886 spin_unlock(&ci->lock);
886 err = usb_ep_clear_halt( 887 err = usb_ep_clear_halt(
887 &udc->ci13xxx_ep[num].ep); 888 &ci->ci13xxx_ep[num].ep);
888 spin_lock(&udc->lock); 889 spin_lock(&ci->lock);
889 if (err) 890 if (err)
890 break; 891 break;
891 } 892 }
892 err = isr_setup_status_phase(udc); 893 err = isr_setup_status_phase(ci);
893 } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE) && 894 } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE) &&
894 le16_to_cpu(req.wValue) == 895 le16_to_cpu(req.wValue) ==
895 USB_DEVICE_REMOTE_WAKEUP) { 896 USB_DEVICE_REMOTE_WAKEUP) {
896 if (req.wLength != 0) 897 if (req.wLength != 0)
897 break; 898 break;
898 udc->remote_wakeup = 0; 899 ci->remote_wakeup = 0;
899 err = isr_setup_status_phase(udc); 900 err = isr_setup_status_phase(ci);
900 } else { 901 } else {
901 goto delegate; 902 goto delegate;
902 } 903 }
@@ -909,7 +910,7 @@ __acquires(udc->lock)
909 if (le16_to_cpu(req.wLength) != 2 || 910 if (le16_to_cpu(req.wLength) != 2 ||
910 le16_to_cpu(req.wValue) != 0) 911 le16_to_cpu(req.wValue) != 0)
911 break; 912 break;
912 err = isr_get_status_response(udc, &req); 913 err = isr_get_status_response(ci, &req);
913 break; 914 break;
914 case USB_REQ_SET_ADDRESS: 915 case USB_REQ_SET_ADDRESS:
915 if (type != (USB_DIR_OUT|USB_RECIP_DEVICE)) 916 if (type != (USB_DIR_OUT|USB_RECIP_DEVICE))
@@ -917,9 +918,9 @@ __acquires(udc->lock)
917 if (le16_to_cpu(req.wLength) != 0 || 918 if (le16_to_cpu(req.wLength) != 0 ||
918 le16_to_cpu(req.wIndex) != 0) 919 le16_to_cpu(req.wIndex) != 0)
919 break; 920 break;
920 udc->address = (u8)le16_to_cpu(req.wValue); 921 ci->address = (u8)le16_to_cpu(req.wValue);
921 udc->setaddr = true; 922 ci->setaddr = true;
922 err = isr_setup_status_phase(udc); 923 err = isr_setup_status_phase(ci);
923 break; 924 break;
924 case USB_REQ_SET_FEATURE: 925 case USB_REQ_SET_FEATURE:
925 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) && 926 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) &&
@@ -931,20 +932,20 @@ __acquires(udc->lock)
931 dir = num & USB_ENDPOINT_DIR_MASK; 932 dir = num & USB_ENDPOINT_DIR_MASK;
932 num &= USB_ENDPOINT_NUMBER_MASK; 933 num &= USB_ENDPOINT_NUMBER_MASK;
933 if (dir) /* TX */ 934 if (dir) /* TX */
934 num += udc->hw_ep_max/2; 935 num += ci->hw_ep_max/2;
935 936
936 spin_unlock(&udc->lock); 937 spin_unlock(&ci->lock);
937 err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep); 938 err = usb_ep_set_halt(&ci->ci13xxx_ep[num].ep);
938 spin_lock(&udc->lock); 939 spin_lock(&ci->lock);
939 if (!err) 940 if (!err)
940 isr_setup_status_phase(udc); 941 isr_setup_status_phase(ci);
941 } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE)) { 942 } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE)) {
942 if (req.wLength != 0) 943 if (req.wLength != 0)
943 break; 944 break;
944 switch (le16_to_cpu(req.wValue)) { 945 switch (le16_to_cpu(req.wValue)) {
945 case USB_DEVICE_REMOTE_WAKEUP: 946 case USB_DEVICE_REMOTE_WAKEUP:
946 udc->remote_wakeup = 1; 947 ci->remote_wakeup = 1;
947 err = isr_setup_status_phase(udc); 948 err = isr_setup_status_phase(ci);
948 break; 949 break;
949 case USB_DEVICE_TEST_MODE: 950 case USB_DEVICE_TEST_MODE:
950 tmode = le16_to_cpu(req.wIndex) >> 8; 951 tmode = le16_to_cpu(req.wIndex) >> 8;
@@ -954,9 +955,9 @@ __acquires(udc->lock)
954 case TEST_SE0_NAK: 955 case TEST_SE0_NAK:
955 case TEST_PACKET: 956 case TEST_PACKET:
956 case TEST_FORCE_EN: 957 case TEST_FORCE_EN:
957 udc->test_mode = tmode; 958 ci->test_mode = tmode;
958 err = isr_setup_status_phase( 959 err = isr_setup_status_phase(
959 udc); 960 ci);
960 break; 961 break;
961 default: 962 default:
962 break; 963 break;
@@ -971,21 +972,21 @@ __acquires(udc->lock)
971 default: 972 default:
972delegate: 973delegate:
973 if (req.wLength == 0) /* no data phase */ 974 if (req.wLength == 0) /* no data phase */
974 udc->ep0_dir = TX; 975 ci->ep0_dir = TX;
975 976
976 spin_unlock(&udc->lock); 977 spin_unlock(&ci->lock);
977 err = udc->driver->setup(&udc->gadget, &req); 978 err = ci->driver->setup(&ci->gadget, &req);
978 spin_lock(&udc->lock); 979 spin_lock(&ci->lock);
979 break; 980 break;
980 } 981 }
981 982
982 if (err < 0) { 983 if (err < 0) {
983 dbg_event(_usb_addr(mEp), "ERROR", err); 984 dbg_event(_usb_addr(mEp), "ERROR", err);
984 985
985 spin_unlock(&udc->lock); 986 spin_unlock(&ci->lock);
986 if (usb_ep_set_halt(&mEp->ep)) 987 if (usb_ep_set_halt(&mEp->ep))
987 dev_err(udc->dev, "error: ep_set_halt\n"); 988 dev_err(ci->dev, "error: ep_set_halt\n");
988 spin_lock(&udc->lock); 989 spin_lock(&ci->lock);
989 } 990 }
990 } 991 }
991} 992}
@@ -1015,7 +1016,7 @@ static int ep_enable(struct usb_ep *ep,
1015 mEp->ep.desc = desc; 1016 mEp->ep.desc = desc;
1016 1017
1017 if (!list_empty(&mEp->qh.queue)) 1018 if (!list_empty(&mEp->qh.queue))
1018 dev_warn(mEp->udc->dev, "enabling a non-empty endpoint!\n"); 1019 dev_warn(mEp->ci->dev, "enabling a non-empty endpoint!\n");
1019 1020
1020 mEp->dir = usb_endpoint_dir_in(desc) ? TX : RX; 1021 mEp->dir = usb_endpoint_dir_in(desc) ? TX : RX;
1021 mEp->num = usb_endpoint_num(desc); 1022 mEp->num = usb_endpoint_num(desc);
@@ -1043,7 +1044,7 @@ static int ep_enable(struct usb_ep *ep,
1043 * is always enabled 1044 * is always enabled
1044 */ 1045 */
1045 if (mEp->num) 1046 if (mEp->num)
1046 retval |= hw_ep_enable(mEp->udc, mEp->num, mEp->dir, mEp->type); 1047 retval |= hw_ep_enable(mEp->ci, mEp->num, mEp->dir, mEp->type);
1047 1048
1048 spin_unlock_irqrestore(mEp->lock, flags); 1049 spin_unlock_irqrestore(mEp->lock, flags);
1049 return retval; 1050 return retval;
@@ -1074,7 +1075,7 @@ static int ep_disable(struct usb_ep *ep)
1074 dbg_event(_usb_addr(mEp), "DISABLE", 0); 1075 dbg_event(_usb_addr(mEp), "DISABLE", 0);
1075 1076
1076 retval |= _ep_nuke(mEp); 1077 retval |= _ep_nuke(mEp);
1077 retval |= hw_ep_disable(mEp->udc, mEp->num, mEp->dir); 1078 retval |= hw_ep_disable(mEp->ci, mEp->num, mEp->dir);
1078 1079
1079 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) 1080 if (mEp->type == USB_ENDPOINT_XFER_CONTROL)
1080 mEp->dir = (mEp->dir == TX) ? RX : TX; 1081 mEp->dir = (mEp->dir == TX) ? RX : TX;
@@ -1131,7 +1132,7 @@ static void ep_free_request(struct usb_ep *ep, struct usb_request *req)
1131 if (ep == NULL || req == NULL) { 1132 if (ep == NULL || req == NULL) {
1132 return; 1133 return;
1133 } else if (!list_empty(&mReq->queue)) { 1134 } else if (!list_empty(&mReq->queue)) {
1134 dev_err(mEp->udc->dev, "freeing queued request\n"); 1135 dev_err(mEp->ci->dev, "freeing queued request\n");
1135 return; 1136 return;
1136 } 1137 }
1137 1138
@@ -1156,7 +1157,7 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
1156{ 1157{
1157 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); 1158 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep);
1158 struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req); 1159 struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req);
1159 struct ci13xxx *udc = mEp->udc; 1160 struct ci13xxx *ci = mEp->ci;
1160 int retval = 0; 1161 int retval = 0;
1161 unsigned long flags; 1162 unsigned long flags;
1162 1163
@@ -1167,12 +1168,12 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
1167 1168
1168 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) { 1169 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) {
1169 if (req->length) 1170 if (req->length)
1170 mEp = (udc->ep0_dir == RX) ? 1171 mEp = (ci->ep0_dir == RX) ?
1171 udc->ep0out : udc->ep0in; 1172 ci->ep0out : ci->ep0in;
1172 if (!list_empty(&mEp->qh.queue)) { 1173 if (!list_empty(&mEp->qh.queue)) {
1173 _ep_nuke(mEp); 1174 _ep_nuke(mEp);
1174 retval = -EOVERFLOW; 1175 retval = -EOVERFLOW;
1175 dev_warn(mEp->udc->dev, "endpoint ctrl %X nuked\n", 1176 dev_warn(mEp->ci->dev, "endpoint ctrl %X nuked\n",
1176 _usb_addr(mEp)); 1177 _usb_addr(mEp));
1177 } 1178 }
1178 } 1179 }
@@ -1180,14 +1181,14 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
1180 /* first nuke then test link, e.g. previous status has not sent */ 1181 /* first nuke then test link, e.g. previous status has not sent */
1181 if (!list_empty(&mReq->queue)) { 1182 if (!list_empty(&mReq->queue)) {
1182 retval = -EBUSY; 1183 retval = -EBUSY;
1183 dev_err(mEp->udc->dev, "request already in queue\n"); 1184 dev_err(mEp->ci->dev, "request already in queue\n");
1184 goto done; 1185 goto done;
1185 } 1186 }
1186 1187
1187 if (req->length > 4 * CI13XXX_PAGE_SIZE) { 1188 if (req->length > 4 * CI13XXX_PAGE_SIZE) {
1188 req->length = 4 * CI13XXX_PAGE_SIZE; 1189 req->length = 4 * CI13XXX_PAGE_SIZE;
1189 retval = -EMSGSIZE; 1190 retval = -EMSGSIZE;
1190 dev_warn(mEp->udc->dev, "request length truncated\n"); 1191 dev_warn(mEp->ci->dev, "request length truncated\n");
1191 } 1192 }
1192 1193
1193 dbg_queue(_usb_addr(mEp), req, retval); 1194 dbg_queue(_usb_addr(mEp), req, retval);
@@ -1230,12 +1231,12 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req)
1230 1231
1231 dbg_event(_usb_addr(mEp), "DEQUEUE", 0); 1232 dbg_event(_usb_addr(mEp), "DEQUEUE", 0);
1232 1233
1233 hw_ep_flush(mEp->udc, mEp->num, mEp->dir); 1234 hw_ep_flush(mEp->ci, mEp->num, mEp->dir);
1234 1235
1235 /* pop request */ 1236 /* pop request */
1236 list_del_init(&mReq->queue); 1237 list_del_init(&mReq->queue);
1237 1238
1238 usb_gadget_unmap_request(&mEp->udc->gadget, req, mEp->dir); 1239 usb_gadget_unmap_request(&mEp->ci->gadget, req, mEp->dir);
1239 1240
1240 req->status = -ECONNRESET; 1241 req->status = -ECONNRESET;
1241 1242
@@ -1277,7 +1278,7 @@ static int ep_set_halt(struct usb_ep *ep, int value)
1277 direction = mEp->dir; 1278 direction = mEp->dir;
1278 do { 1279 do {
1279 dbg_event(_usb_addr(mEp), "HALT", value); 1280 dbg_event(_usb_addr(mEp), "HALT", value);
1280 retval |= hw_ep_set_halt(mEp->udc, mEp->num, mEp->dir, value); 1281 retval |= hw_ep_set_halt(mEp->ci, mEp->num, mEp->dir, value);
1281 1282
1282 if (!value) 1283 if (!value)
1283 mEp->wedge = 0; 1284 mEp->wedge = 0;
@@ -1325,14 +1326,14 @@ static void ep_fifo_flush(struct usb_ep *ep)
1325 unsigned long flags; 1326 unsigned long flags;
1326 1327
1327 if (ep == NULL) { 1328 if (ep == NULL) {
1328 dev_err(mEp->udc->dev, "%02X: -EINVAL\n", _usb_addr(mEp)); 1329 dev_err(mEp->ci->dev, "%02X: -EINVAL\n", _usb_addr(mEp));
1329 return; 1330 return;
1330 } 1331 }
1331 1332
1332 spin_lock_irqsave(mEp->lock, flags); 1333 spin_lock_irqsave(mEp->lock, flags);
1333 1334
1334 dbg_event(_usb_addr(mEp), "FFLUSH", 0); 1335 dbg_event(_usb_addr(mEp), "FFLUSH", 0);
1335 hw_ep_flush(mEp->udc, mEp->num, mEp->dir); 1336 hw_ep_flush(mEp->ci, mEp->num, mEp->dir);
1336 1337
1337 spin_unlock_irqrestore(mEp->lock, flags); 1338 spin_unlock_irqrestore(mEp->lock, flags);
1338} 1339}
@@ -1358,30 +1359,30 @@ static const struct usb_ep_ops usb_ep_ops = {
1358 *****************************************************************************/ 1359 *****************************************************************************/
1359static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active) 1360static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
1360{ 1361{
1361 struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget); 1362 struct ci13xxx *ci = container_of(_gadget, struct ci13xxx, gadget);
1362 unsigned long flags; 1363 unsigned long flags;
1363 int gadget_ready = 0; 1364 int gadget_ready = 0;
1364 1365
1365 if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS)) 1366 if (!(ci->platdata->flags & CI13XXX_PULLUP_ON_VBUS))
1366 return -EOPNOTSUPP; 1367 return -EOPNOTSUPP;
1367 1368
1368 spin_lock_irqsave(&udc->lock, flags); 1369 spin_lock_irqsave(&ci->lock, flags);
1369 udc->vbus_active = is_active; 1370 ci->vbus_active = is_active;
1370 if (udc->driver) 1371 if (ci->driver)
1371 gadget_ready = 1; 1372 gadget_ready = 1;
1372 spin_unlock_irqrestore(&udc->lock, flags); 1373 spin_unlock_irqrestore(&ci->lock, flags);
1373 1374
1374 if (gadget_ready) { 1375 if (gadget_ready) {
1375 if (is_active) { 1376 if (is_active) {
1376 pm_runtime_get_sync(&_gadget->dev); 1377 pm_runtime_get_sync(&_gadget->dev);
1377 hw_device_reset(udc, USBMODE_CM_DC); 1378 hw_device_reset(ci, USBMODE_CM_DC);
1378 hw_device_state(udc, udc->ep0out->qh.dma); 1379 hw_device_state(ci, ci->ep0out->qh.dma);
1379 } else { 1380 } else {
1380 hw_device_state(udc, 0); 1381 hw_device_state(ci, 0);
1381 if (udc->udc_driver->notify_event) 1382 if (ci->platdata->notify_event)
1382 udc->udc_driver->notify_event(udc, 1383 ci->platdata->notify_event(ci,
1383 CI13XXX_CONTROLLER_STOPPED_EVENT); 1384 CI13XXX_CONTROLLER_STOPPED_EVENT);
1384 _gadget_stop_activity(&udc->gadget); 1385 _gadget_stop_activity(&ci->gadget);
1385 pm_runtime_put_sync(&_gadget->dev); 1386 pm_runtime_put_sync(&_gadget->dev);
1386 } 1387 }
1387 } 1388 }
@@ -1391,31 +1392,31 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
1391 1392
1392static int ci13xxx_wakeup(struct usb_gadget *_gadget) 1393static int ci13xxx_wakeup(struct usb_gadget *_gadget)
1393{ 1394{
1394 struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget); 1395 struct ci13xxx *ci = container_of(_gadget, struct ci13xxx, gadget);
1395 unsigned long flags; 1396 unsigned long flags;
1396 int ret = 0; 1397 int ret = 0;
1397 1398
1398 spin_lock_irqsave(&udc->lock, flags); 1399 spin_lock_irqsave(&ci->lock, flags);
1399 if (!udc->remote_wakeup) { 1400 if (!ci->remote_wakeup) {
1400 ret = -EOPNOTSUPP; 1401 ret = -EOPNOTSUPP;
1401 goto out; 1402 goto out;
1402 } 1403 }
1403 if (!hw_read(udc, OP_PORTSC, PORTSC_SUSP)) { 1404 if (!hw_read(ci, OP_PORTSC, PORTSC_SUSP)) {
1404 ret = -EINVAL; 1405 ret = -EINVAL;
1405 goto out; 1406 goto out;
1406 } 1407 }
1407 hw_write(udc, OP_PORTSC, PORTSC_FPR, PORTSC_FPR); 1408 hw_write(ci, OP_PORTSC, PORTSC_FPR, PORTSC_FPR);
1408out: 1409out:
1409 spin_unlock_irqrestore(&udc->lock, flags); 1410 spin_unlock_irqrestore(&ci->lock, flags);
1410 return ret; 1411 return ret;
1411} 1412}
1412 1413
1413static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA) 1414static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1414{ 1415{
1415 struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget); 1416 struct ci13xxx *ci = container_of(_gadget, struct ci13xxx, gadget);
1416 1417
1417 if (udc->transceiver) 1418 if (ci->transceiver)
1418 return usb_phy_set_power(udc->transceiver, mA); 1419 return usb_phy_set_power(ci->transceiver, mA);
1419 return -ENOTSUPP; 1420 return -ENOTSUPP;
1420} 1421}
1421 1422
@@ -1436,28 +1437,28 @@ static const struct usb_gadget_ops usb_gadget_ops = {
1436 .udc_stop = ci13xxx_stop, 1437 .udc_stop = ci13xxx_stop,
1437}; 1438};
1438 1439
1439static int init_eps(struct ci13xxx *udc) 1440static int init_eps(struct ci13xxx *ci)
1440{ 1441{
1441 int retval = 0, i, j; 1442 int retval = 0, i, j;
1442 1443
1443 for (i = 0; i < udc->hw_ep_max/2; i++) 1444 for (i = 0; i < ci->hw_ep_max/2; i++)
1444 for (j = RX; j <= TX; j++) { 1445 for (j = RX; j <= TX; j++) {
1445 int k = i + j * udc->hw_ep_max/2; 1446 int k = i + j * ci->hw_ep_max/2;
1446 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[k]; 1447 struct ci13xxx_ep *mEp = &ci->ci13xxx_ep[k];
1447 1448
1448 scnprintf(mEp->name, sizeof(mEp->name), "ep%i%s", i, 1449 scnprintf(mEp->name, sizeof(mEp->name), "ep%i%s", i,
1449 (j == TX) ? "in" : "out"); 1450 (j == TX) ? "in" : "out");
1450 1451
1451 mEp->udc = udc; 1452 mEp->ci = ci;
1452 mEp->lock = &udc->lock; 1453 mEp->lock = &ci->lock;
1453 mEp->td_pool = udc->td_pool; 1454 mEp->td_pool = ci->td_pool;
1454 1455
1455 mEp->ep.name = mEp->name; 1456 mEp->ep.name = mEp->name;
1456 mEp->ep.ops = &usb_ep_ops; 1457 mEp->ep.ops = &usb_ep_ops;
1457 mEp->ep.maxpacket = CTRL_PAYLOAD_MAX; 1458 mEp->ep.maxpacket = CTRL_PAYLOAD_MAX;
1458 1459
1459 INIT_LIST_HEAD(&mEp->qh.queue); 1460 INIT_LIST_HEAD(&mEp->qh.queue);
1460 mEp->qh.ptr = dma_pool_alloc(udc->qh_pool, GFP_KERNEL, 1461 mEp->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL,
1461 &mEp->qh.dma); 1462 &mEp->qh.dma);
1462 if (mEp->qh.ptr == NULL) 1463 if (mEp->qh.ptr == NULL)
1463 retval = -ENOMEM; 1464 retval = -ENOMEM;
@@ -1470,14 +1471,14 @@ static int init_eps(struct ci13xxx *udc)
1470 */ 1471 */
1471 if (i == 0) { 1472 if (i == 0) {
1472 if (j == RX) 1473 if (j == RX)
1473 udc->ep0out = mEp; 1474 ci->ep0out = mEp;
1474 else 1475 else
1475 udc->ep0in = mEp; 1476 ci->ep0in = mEp;
1476 1477
1477 continue; 1478 continue;
1478 } 1479 }
1479 1480
1480 list_add_tail(&mEp->ep.ep_list, &udc->gadget.ep_list); 1481 list_add_tail(&mEp->ep.ep_list, &ci->gadget.ep_list);
1481 } 1482 }
1482 1483
1483 return retval; 1484 return retval;
@@ -1493,7 +1494,7 @@ static int init_eps(struct ci13xxx *udc)
1493static int ci13xxx_start(struct usb_gadget *gadget, 1494static int ci13xxx_start(struct usb_gadget *gadget,
1494 struct usb_gadget_driver *driver) 1495 struct usb_gadget_driver *driver)
1495{ 1496{
1496 struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); 1497 struct ci13xxx *ci = container_of(gadget, struct ci13xxx, gadget);
1497 unsigned long flags; 1498 unsigned long flags;
1498 int retval = -ENOMEM; 1499 int retval = -ENOMEM;
1499 1500
@@ -1501,35 +1502,35 @@ static int ci13xxx_start(struct usb_gadget *gadget,
1501 return -EINVAL; 1502 return -EINVAL;
1502 1503
1503 1504
1504 udc->ep0out->ep.desc = &ctrl_endpt_out_desc; 1505 ci->ep0out->ep.desc = &ctrl_endpt_out_desc;
1505 retval = usb_ep_enable(&udc->ep0out->ep); 1506 retval = usb_ep_enable(&ci->ep0out->ep);
1506 if (retval) 1507 if (retval)
1507 return retval; 1508 return retval;
1508 1509
1509 udc->ep0in->ep.desc = &ctrl_endpt_in_desc; 1510 ci->ep0in->ep.desc = &ctrl_endpt_in_desc;
1510 retval = usb_ep_enable(&udc->ep0in->ep); 1511 retval = usb_ep_enable(&ci->ep0in->ep);
1511 if (retval) 1512 if (retval)
1512 return retval; 1513 return retval;
1513 spin_lock_irqsave(&udc->lock, flags); 1514 spin_lock_irqsave(&ci->lock, flags);
1514 1515
1515 udc->driver = driver; 1516 ci->driver = driver;
1516 pm_runtime_get_sync(&udc->gadget.dev); 1517 pm_runtime_get_sync(&ci->gadget.dev);
1517 if (udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) { 1518 if (ci->platdata->flags & CI13XXX_PULLUP_ON_VBUS) {
1518 if (udc->vbus_active) { 1519 if (ci->vbus_active) {
1519 if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) 1520 if (ci->platdata->flags & CI13XXX_REGS_SHARED)
1520 hw_device_reset(udc, USBMODE_CM_DC); 1521 hw_device_reset(ci, USBMODE_CM_DC);
1521 } else { 1522 } else {
1522 pm_runtime_put_sync(&udc->gadget.dev); 1523 pm_runtime_put_sync(&ci->gadget.dev);
1523 goto done; 1524 goto done;
1524 } 1525 }
1525 } 1526 }
1526 1527
1527 retval = hw_device_state(udc, udc->ep0out->qh.dma); 1528 retval = hw_device_state(ci, ci->ep0out->qh.dma);
1528 if (retval) 1529 if (retval)
1529 pm_runtime_put_sync(&udc->gadget.dev); 1530 pm_runtime_put_sync(&ci->gadget.dev);
1530 1531
1531 done: 1532 done:
1532 spin_unlock_irqrestore(&udc->lock, flags); 1533 spin_unlock_irqrestore(&ci->lock, flags);
1533 return retval; 1534 return retval;
1534} 1535}
1535 1536
@@ -1539,25 +1540,25 @@ static int ci13xxx_start(struct usb_gadget *gadget,
1539static int ci13xxx_stop(struct usb_gadget *gadget, 1540static int ci13xxx_stop(struct usb_gadget *gadget,
1540 struct usb_gadget_driver *driver) 1541 struct usb_gadget_driver *driver)
1541{ 1542{
1542 struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); 1543 struct ci13xxx *ci = container_of(gadget, struct ci13xxx, gadget);
1543 unsigned long flags; 1544 unsigned long flags;
1544 1545
1545 spin_lock_irqsave(&udc->lock, flags); 1546 spin_lock_irqsave(&ci->lock, flags);
1546 1547
1547 if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) || 1548 if (!(ci->platdata->flags & CI13XXX_PULLUP_ON_VBUS) ||
1548 udc->vbus_active) { 1549 ci->vbus_active) {
1549 hw_device_state(udc, 0); 1550 hw_device_state(ci, 0);
1550 if (udc->udc_driver->notify_event) 1551 if (ci->platdata->notify_event)
1551 udc->udc_driver->notify_event(udc, 1552 ci->platdata->notify_event(ci,
1552 CI13XXX_CONTROLLER_STOPPED_EVENT); 1553 CI13XXX_CONTROLLER_STOPPED_EVENT);
1553 udc->driver = NULL; 1554 ci->driver = NULL;
1554 spin_unlock_irqrestore(&udc->lock, flags); 1555 spin_unlock_irqrestore(&ci->lock, flags);
1555 _gadget_stop_activity(&udc->gadget); 1556 _gadget_stop_activity(&ci->gadget);
1556 spin_lock_irqsave(&udc->lock, flags); 1557 spin_lock_irqsave(&ci->lock, flags);
1557 pm_runtime_put(&udc->gadget.dev); 1558 pm_runtime_put(&ci->gadget.dev);
1558 } 1559 }
1559 1560
1560 spin_unlock_irqrestore(&udc->lock, flags); 1561 spin_unlock_irqrestore(&ci->lock, flags);
1561 1562
1562 return 0; 1563 return 0;
1563} 1564}
@@ -1566,64 +1567,64 @@ static int ci13xxx_stop(struct usb_gadget *gadget,
1566 * BUS block 1567 * BUS block
1567 *****************************************************************************/ 1568 *****************************************************************************/
1568/** 1569/**
1569 * udc_irq: udc interrupt handler 1570 * udc_irq: ci interrupt handler
1570 * 1571 *
1571 * This function returns IRQ_HANDLED if the IRQ has been handled 1572 * This function returns IRQ_HANDLED if the IRQ has been handled
1572 * It locks access to registers 1573 * It locks access to registers
1573 */ 1574 */
1574static irqreturn_t udc_irq(struct ci13xxx *udc) 1575static irqreturn_t udc_irq(struct ci13xxx *ci)
1575{ 1576{
1576 irqreturn_t retval; 1577 irqreturn_t retval;
1577 u32 intr; 1578 u32 intr;
1578 1579
1579 if (udc == NULL) 1580 if (ci == NULL)
1580 return IRQ_HANDLED; 1581 return IRQ_HANDLED;
1581 1582
1582 spin_lock(&udc->lock); 1583 spin_lock(&ci->lock);
1583 1584
1584 if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) { 1585 if (ci->platdata->flags & CI13XXX_REGS_SHARED) {
1585 if (hw_read(udc, OP_USBMODE, USBMODE_CM) != 1586 if (hw_read(ci, OP_USBMODE, USBMODE_CM) !=
1586 USBMODE_CM_DC) { 1587 USBMODE_CM_DC) {
1587 spin_unlock(&udc->lock); 1588 spin_unlock(&ci->lock);
1588 return IRQ_NONE; 1589 return IRQ_NONE;
1589 } 1590 }
1590 } 1591 }
1591 intr = hw_test_and_clear_intr_active(udc); 1592 intr = hw_test_and_clear_intr_active(ci);
1592 dbg_interrupt(intr); 1593 dbg_interrupt(intr);
1593 1594
1594 if (intr) { 1595 if (intr) {
1595 /* order defines priority - do NOT change it */ 1596 /* order defines priority - do NOT change it */
1596 if (USBi_URI & intr) 1597 if (USBi_URI & intr)
1597 isr_reset_handler(udc); 1598 isr_reset_handler(ci);
1598 1599
1599 if (USBi_PCI & intr) { 1600 if (USBi_PCI & intr) {
1600 udc->gadget.speed = hw_port_is_high_speed(udc) ? 1601 ci->gadget.speed = hw_port_is_high_speed(ci) ?
1601 USB_SPEED_HIGH : USB_SPEED_FULL; 1602 USB_SPEED_HIGH : USB_SPEED_FULL;
1602 if (udc->suspended && udc->driver->resume) { 1603 if (ci->suspended && ci->driver->resume) {
1603 spin_unlock(&udc->lock); 1604 spin_unlock(&ci->lock);
1604 udc->driver->resume(&udc->gadget); 1605 ci->driver->resume(&ci->gadget);
1605 spin_lock(&udc->lock); 1606 spin_lock(&ci->lock);
1606 udc->suspended = 0; 1607 ci->suspended = 0;
1607 } 1608 }
1608 } 1609 }
1609 1610
1610 if (USBi_UI & intr) 1611 if (USBi_UI & intr)
1611 isr_tr_complete_handler(udc); 1612 isr_tr_complete_handler(ci);
1612 1613
1613 if (USBi_SLI & intr) { 1614 if (USBi_SLI & intr) {
1614 if (udc->gadget.speed != USB_SPEED_UNKNOWN && 1615 if (ci->gadget.speed != USB_SPEED_UNKNOWN &&
1615 udc->driver->suspend) { 1616 ci->driver->suspend) {
1616 udc->suspended = 1; 1617 ci->suspended = 1;
1617 spin_unlock(&udc->lock); 1618 spin_unlock(&ci->lock);
1618 udc->driver->suspend(&udc->gadget); 1619 ci->driver->suspend(&ci->gadget);
1619 spin_lock(&udc->lock); 1620 spin_lock(&ci->lock);
1620 } 1621 }
1621 } 1622 }
1622 retval = IRQ_HANDLED; 1623 retval = IRQ_HANDLED;
1623 } else { 1624 } else {
1624 retval = IRQ_NONE; 1625 retval = IRQ_NONE;
1625 } 1626 }
1626 spin_unlock(&udc->lock); 1627 spin_unlock(&ci->lock);
1627 1628
1628 return retval; 1629 return retval;
1629} 1630}
@@ -1640,112 +1641,111 @@ static void udc_release(struct device *dev)
1640 1641
1641/** 1642/**
1642 * udc_start: initialize gadget role 1643 * udc_start: initialize gadget role
1643 * @udc: chipidea controller 1644 * @ci: chipidea controller
1644 */ 1645 */
1645static int udc_start(struct ci13xxx *udc) 1646static int udc_start(struct ci13xxx *ci)
1646{ 1647{
1647 struct device *dev = udc->dev; 1648 struct device *dev = ci->dev;
1648 int retval = 0; 1649 int retval = 0;
1649 1650
1650 if (!udc) 1651 spin_lock_init(&ci->lock);
1651 return -EINVAL;
1652
1653 spin_lock_init(&udc->lock);
1654 1652
1655 udc->gadget.ops = &usb_gadget_ops; 1653 ci->gadget.ops = &usb_gadget_ops;
1656 udc->gadget.speed = USB_SPEED_UNKNOWN; 1654 ci->gadget.speed = USB_SPEED_UNKNOWN;
1657 udc->gadget.max_speed = USB_SPEED_HIGH; 1655 ci->gadget.max_speed = USB_SPEED_HIGH;
1658 udc->gadget.is_otg = 0; 1656 ci->gadget.is_otg = 0;
1659 udc->gadget.name = udc->udc_driver->name; 1657 ci->gadget.name = ci->platdata->name;
1660 1658
1661 INIT_LIST_HEAD(&udc->gadget.ep_list); 1659 INIT_LIST_HEAD(&ci->gadget.ep_list);
1662 1660
1663 dev_set_name(&udc->gadget.dev, "gadget"); 1661 dev_set_name(&ci->gadget.dev, "gadget");
1664 udc->gadget.dev.dma_mask = dev->dma_mask; 1662 ci->gadget.dev.dma_mask = dev->dma_mask;
1665 udc->gadget.dev.coherent_dma_mask = dev->coherent_dma_mask; 1663 ci->gadget.dev.coherent_dma_mask = dev->coherent_dma_mask;
1666 udc->gadget.dev.parent = dev; 1664 ci->gadget.dev.parent = dev;
1667 udc->gadget.dev.release = udc_release; 1665 ci->gadget.dev.release = udc_release;
1668 1666
1669 /* alloc resources */ 1667 /* alloc resources */
1670 udc->qh_pool = dma_pool_create("ci13xxx_qh", dev, 1668 ci->qh_pool = dma_pool_create("ci13xxx_qh", dev,
1671 sizeof(struct ci13xxx_qh), 1669 sizeof(struct ci13xxx_qh),
1672 64, CI13XXX_PAGE_SIZE); 1670 64, CI13XXX_PAGE_SIZE);
1673 if (udc->qh_pool == NULL) 1671 if (ci->qh_pool == NULL)
1674 return -ENOMEM; 1672 return -ENOMEM;
1675 1673
1676 udc->td_pool = dma_pool_create("ci13xxx_td", dev, 1674 ci->td_pool = dma_pool_create("ci13xxx_td", dev,
1677 sizeof(struct ci13xxx_td), 1675 sizeof(struct ci13xxx_td),
1678 64, CI13XXX_PAGE_SIZE); 1676 64, CI13XXX_PAGE_SIZE);
1679 if (udc->td_pool == NULL) { 1677 if (ci->td_pool == NULL) {
1680 retval = -ENOMEM; 1678 retval = -ENOMEM;
1681 goto free_qh_pool; 1679 goto free_qh_pool;
1682 } 1680 }
1683 1681
1684 retval = init_eps(udc); 1682 retval = init_eps(ci);
1685 if (retval) 1683 if (retval)
1686 goto free_pools; 1684 goto free_pools;
1687 1685
1688 udc->gadget.ep0 = &udc->ep0in->ep; 1686 ci->gadget.ep0 = &ci->ep0in->ep;
1689 1687
1690 udc->transceiver = usb_get_transceiver(); 1688 if (ci->global_phy)
1689 ci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
1691 1690
1692 if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) { 1691 if (ci->platdata->flags & CI13XXX_REQUIRE_TRANSCEIVER) {
1693 if (udc->transceiver == NULL) { 1692 if (ci->transceiver == NULL) {
1694 retval = -ENODEV; 1693 retval = -ENODEV;
1695 goto free_pools; 1694 goto free_pools;
1696 } 1695 }
1697 } 1696 }
1698 1697
1699 if (!(udc->udc_driver->flags & CI13XXX_REGS_SHARED)) { 1698 if (!(ci->platdata->flags & CI13XXX_REGS_SHARED)) {
1700 retval = hw_device_reset(udc, USBMODE_CM_DC); 1699 retval = hw_device_reset(ci, USBMODE_CM_DC);
1701 if (retval) 1700 if (retval)
1702 goto put_transceiver; 1701 goto put_transceiver;
1703 } 1702 }
1704 1703
1705 retval = device_register(&udc->gadget.dev); 1704 retval = device_register(&ci->gadget.dev);
1706 if (retval) { 1705 if (retval) {
1707 put_device(&udc->gadget.dev); 1706 put_device(&ci->gadget.dev);
1708 goto put_transceiver; 1707 goto put_transceiver;
1709 } 1708 }
1710 1709
1711 retval = dbg_create_files(&udc->gadget.dev); 1710 retval = dbg_create_files(&ci->gadget.dev);
1712 if (retval) 1711 if (retval)
1713 goto unreg_device; 1712 goto unreg_device;
1714 1713
1715 if (udc->transceiver) { 1714 if (!IS_ERR_OR_NULL(ci->transceiver)) {
1716 retval = otg_set_peripheral(udc->transceiver->otg, 1715 retval = otg_set_peripheral(ci->transceiver->otg,
1717 &udc->gadget); 1716 &ci->gadget);
1718 if (retval) 1717 if (retval)
1719 goto remove_dbg; 1718 goto remove_dbg;
1720 } 1719 }
1721 1720
1722 retval = usb_add_gadget_udc(dev, &udc->gadget); 1721 retval = usb_add_gadget_udc(dev, &ci->gadget);
1723 if (retval) 1722 if (retval)
1724 goto remove_trans; 1723 goto remove_trans;
1725 1724
1726 pm_runtime_no_callbacks(&udc->gadget.dev); 1725 pm_runtime_no_callbacks(&ci->gadget.dev);
1727 pm_runtime_enable(&udc->gadget.dev); 1726 pm_runtime_enable(&ci->gadget.dev);
1728 1727
1729 return retval; 1728 return retval;
1730 1729
1731remove_trans: 1730remove_trans:
1732 if (udc->transceiver) { 1731 if (!IS_ERR_OR_NULL(ci->transceiver)) {
1733 otg_set_peripheral(udc->transceiver->otg, &udc->gadget); 1732 otg_set_peripheral(ci->transceiver->otg, &ci->gadget);
1734 usb_put_transceiver(udc->transceiver); 1733 if (ci->global_phy)
1734 usb_put_phy(ci->transceiver);
1735 } 1735 }
1736 1736
1737 dev_err(dev, "error = %i\n", retval); 1737 dev_err(dev, "error = %i\n", retval);
1738remove_dbg: 1738remove_dbg:
1739 dbg_remove_files(&udc->gadget.dev); 1739 dbg_remove_files(&ci->gadget.dev);
1740unreg_device: 1740unreg_device:
1741 device_unregister(&udc->gadget.dev); 1741 device_unregister(&ci->gadget.dev);
1742put_transceiver: 1742put_transceiver:
1743 if (udc->transceiver) 1743 if (!IS_ERR_OR_NULL(ci->transceiver) && ci->global_phy)
1744 usb_put_transceiver(udc->transceiver); 1744 usb_put_phy(ci->transceiver);
1745free_pools: 1745free_pools:
1746 dma_pool_destroy(udc->td_pool); 1746 dma_pool_destroy(ci->td_pool);
1747free_qh_pool: 1747free_qh_pool:
1748 dma_pool_destroy(udc->qh_pool); 1748 dma_pool_destroy(ci->qh_pool);
1749 return retval; 1749 return retval;
1750} 1750}
1751 1751
@@ -1754,32 +1754,33 @@ free_qh_pool:
1754 * 1754 *
1755 * No interrupts active, the IRQ has been released 1755 * No interrupts active, the IRQ has been released
1756 */ 1756 */
1757static void udc_stop(struct ci13xxx *udc) 1757static void udc_stop(struct ci13xxx *ci)
1758{ 1758{
1759 int i; 1759 int i;
1760 1760
1761 if (udc == NULL) 1761 if (ci == NULL)
1762 return; 1762 return;
1763 1763
1764 usb_del_gadget_udc(&udc->gadget); 1764 usb_del_gadget_udc(&ci->gadget);
1765 1765
1766 for (i = 0; i < udc->hw_ep_max; i++) { 1766 for (i = 0; i < ci->hw_ep_max; i++) {
1767 struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; 1767 struct ci13xxx_ep *mEp = &ci->ci13xxx_ep[i];
1768 1768
1769 dma_pool_free(udc->qh_pool, mEp->qh.ptr, mEp->qh.dma); 1769 dma_pool_free(ci->qh_pool, mEp->qh.ptr, mEp->qh.dma);
1770 } 1770 }
1771 1771
1772 dma_pool_destroy(udc->td_pool); 1772 dma_pool_destroy(ci->td_pool);
1773 dma_pool_destroy(udc->qh_pool); 1773 dma_pool_destroy(ci->qh_pool);
1774 1774
1775 if (udc->transceiver) { 1775 if (!IS_ERR_OR_NULL(ci->transceiver)) {
1776 otg_set_peripheral(udc->transceiver->otg, NULL); 1776 otg_set_peripheral(ci->transceiver->otg, NULL);
1777 usb_put_transceiver(udc->transceiver); 1777 if (ci->global_phy)
1778 usb_put_phy(ci->transceiver);
1778 } 1779 }
1779 dbg_remove_files(&udc->gadget.dev); 1780 dbg_remove_files(&ci->gadget.dev);
1780 device_unregister(&udc->gadget.dev); 1781 device_unregister(&ci->gadget.dev);
1781 /* my kobject is dynamic, I swear! */ 1782 /* my kobject is dynamic, I swear! */
1782 memset(&udc->gadget, 0, sizeof(udc->gadget)); 1783 memset(&ci->gadget, 0, sizeof(ci->gadget));
1783} 1784}
1784 1785
1785/** 1786/**
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 36a2a0b7b82c..56d6bf668488 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -996,7 +996,7 @@ static int acm_probe(struct usb_interface *intf,
996 case USB_CDC_CALL_MANAGEMENT_TYPE: 996 case USB_CDC_CALL_MANAGEMENT_TYPE:
997 call_management_function = buffer[3]; 997 call_management_function = buffer[3];
998 call_interface_num = buffer[4]; 998 call_interface_num = buffer[4];
999 if ( (quirks & NOT_A_MODEM) == 0 && (call_management_function & 3) != 3) 999 if ((quirks & NOT_A_MODEM) == 0 && (call_management_function & 3) != 3)
1000 dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n"); 1000 dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n");
1001 break; 1001 break;
1002 default: 1002 default:
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index ee469274a3fe..65a55abb791f 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -32,8 +32,6 @@
32#define DRIVER_AUTHOR "Oliver Neukum" 32#define DRIVER_AUTHOR "Oliver Neukum"
33#define DRIVER_DESC "USB Abstract Control Model driver for USB WCM Device Management" 33#define DRIVER_DESC "USB Abstract Control Model driver for USB WCM Device Management"
34 34
35#define HUAWEI_VENDOR_ID 0x12D1
36
37static const struct usb_device_id wdm_ids[] = { 35static const struct usb_device_id wdm_ids[] = {
38 { 36 {
39 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS | 37 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
@@ -41,29 +39,6 @@ static const struct usb_device_id wdm_ids[] = {
41 .bInterfaceClass = USB_CLASS_COMM, 39 .bInterfaceClass = USB_CLASS_COMM,
42 .bInterfaceSubClass = USB_CDC_SUBCLASS_DMM 40 .bInterfaceSubClass = USB_CDC_SUBCLASS_DMM
43 }, 41 },
44 {
45 /*
46 * Huawei E392, E398 and possibly other Qualcomm based modems
47 * embed the Qualcomm QMI protocol inside CDC on CDC ECM like
48 * control interfaces. Userspace access to this is required
49 * to configure the accompanying data interface
50 */
51 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
52 USB_DEVICE_ID_MATCH_INT_INFO,
53 .idVendor = HUAWEI_VENDOR_ID,
54 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
55 .bInterfaceSubClass = 1,
56 .bInterfaceProtocol = 9, /* NOTE: CDC ECM control interface! */
57 },
58 {
59 /* Vodafone/Huawei K5005 (12d1:14c8) and similar modems */
60 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
61 USB_DEVICE_ID_MATCH_INT_INFO,
62 .idVendor = HUAWEI_VENDOR_ID,
63 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
64 .bInterfaceSubClass = 1,
65 .bInterfaceProtocol = 57, /* NOTE: CDC ECM control interface! */
66 },
67 { } 42 { }
68}; 43};
69 44
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index e0f107948eba..ebb8a9de8b5f 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -47,6 +47,7 @@
47#include <linux/notifier.h> 47#include <linux/notifier.h>
48#include <linux/security.h> 48#include <linux/security.h>
49#include <linux/user_namespace.h> 49#include <linux/user_namespace.h>
50#include <linux/scatterlist.h>
50#include <asm/uaccess.h> 51#include <asm/uaccess.h>
51#include <asm/byteorder.h> 52#include <asm/byteorder.h>
52#include <linux/moduleparam.h> 53#include <linux/moduleparam.h>
@@ -55,6 +56,7 @@
55 56
56#define USB_MAXBUS 64 57#define USB_MAXBUS 64
57#define USB_DEVICE_MAX USB_MAXBUS * 128 58#define USB_DEVICE_MAX USB_MAXBUS * 128
59#define USB_SG_SIZE 16384 /* split-size for large txs */
58 60
59/* Mutual exclusion for removal, open, and release */ 61/* Mutual exclusion for removal, open, and release */
60DEFINE_MUTEX(usbfs_mutex); 62DEFINE_MUTEX(usbfs_mutex);
@@ -285,9 +287,16 @@ static struct async *alloc_async(unsigned int numisoframes)
285 287
286static void free_async(struct async *as) 288static void free_async(struct async *as)
287{ 289{
290 int i;
291
288 put_pid(as->pid); 292 put_pid(as->pid);
289 if (as->cred) 293 if (as->cred)
290 put_cred(as->cred); 294 put_cred(as->cred);
295 for (i = 0; i < as->urb->num_sgs; i++) {
296 if (sg_page(&as->urb->sg[i]))
297 kfree(sg_virt(&as->urb->sg[i]));
298 }
299 kfree(as->urb->sg);
291 kfree(as->urb->transfer_buffer); 300 kfree(as->urb->transfer_buffer);
292 kfree(as->urb->setup_packet); 301 kfree(as->urb->setup_packet);
293 usb_free_urb(as->urb); 302 usb_free_urb(as->urb);
@@ -388,6 +397,53 @@ static void snoop_urb(struct usb_device *udev,
388 } 397 }
389} 398}
390 399
400static void snoop_urb_data(struct urb *urb, unsigned len)
401{
402 int i, size;
403
404 if (!usbfs_snoop)
405 return;
406
407 if (urb->num_sgs == 0) {
408 print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_NONE, 32, 1,
409 urb->transfer_buffer, len, 1);
410 return;
411 }
412
413 for (i = 0; i < urb->num_sgs && len; i++) {
414 size = (len > USB_SG_SIZE) ? USB_SG_SIZE : len;
415 print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_NONE, 32, 1,
416 sg_virt(&urb->sg[i]), size, 1);
417 len -= size;
418 }
419}
420
421static int copy_urb_data_to_user(u8 __user *userbuffer, struct urb *urb)
422{
423 unsigned i, len, size;
424
425 if (urb->number_of_packets > 0) /* Isochronous */
426 len = urb->transfer_buffer_length;
427 else /* Non-Isoc */
428 len = urb->actual_length;
429
430 if (urb->num_sgs == 0) {
431 if (copy_to_user(userbuffer, urb->transfer_buffer, len))
432 return -EFAULT;
433 return 0;
434 }
435
436 for (i = 0; i < urb->num_sgs && len; i++) {
437 size = (len > USB_SG_SIZE) ? USB_SG_SIZE : len;
438 if (copy_to_user(userbuffer, sg_virt(&urb->sg[i]), size))
439 return -EFAULT;
440 userbuffer += size;
441 len -= size;
442 }
443
444 return 0;
445}
446
391#define AS_CONTINUATION 1 447#define AS_CONTINUATION 1
392#define AS_UNLINK 2 448#define AS_UNLINK 2
393 449
@@ -454,9 +510,10 @@ static void async_completed(struct urb *urb)
454 } 510 }
455 snoop(&urb->dev->dev, "urb complete\n"); 511 snoop(&urb->dev->dev, "urb complete\n");
456 snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length, 512 snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length,
457 as->status, COMPLETE, 513 as->status, COMPLETE, NULL, 0);
458 ((urb->transfer_flags & URB_DIR_MASK) == USB_DIR_OUT) ? 514 if ((urb->transfer_flags & URB_DIR_MASK) == USB_DIR_IN)
459 NULL : urb->transfer_buffer, urb->actual_length); 515 snoop_urb_data(urb, urb->actual_length);
516
460 if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET && 517 if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET &&
461 as->status != -ENOENT) 518 as->status != -ENOENT)
462 cancel_bulk_urbs(ps, as->bulk_addr); 519 cancel_bulk_urbs(ps, as->bulk_addr);
@@ -1114,8 +1171,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1114 struct async *as = NULL; 1171 struct async *as = NULL;
1115 struct usb_ctrlrequest *dr = NULL; 1172 struct usb_ctrlrequest *dr = NULL;
1116 unsigned int u, totlen, isofrmlen; 1173 unsigned int u, totlen, isofrmlen;
1117 int ret, ifnum = -1; 1174 int i, ret, is_in, num_sgs = 0, ifnum = -1;
1118 int is_in; 1175 void *buf;
1119 1176
1120 if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP | 1177 if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP |
1121 USBDEVFS_URB_SHORT_NOT_OK | 1178 USBDEVFS_URB_SHORT_NOT_OK |
@@ -1199,6 +1256,9 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1199 goto interrupt_urb; 1256 goto interrupt_urb;
1200 } 1257 }
1201 uurb->number_of_packets = 0; 1258 uurb->number_of_packets = 0;
1259 num_sgs = DIV_ROUND_UP(uurb->buffer_length, USB_SG_SIZE);
1260 if (num_sgs == 1 || num_sgs > ps->dev->bus->sg_tablesize)
1261 num_sgs = 0;
1202 break; 1262 break;
1203 1263
1204 case USBDEVFS_URB_TYPE_INTERRUPT: 1264 case USBDEVFS_URB_TYPE_INTERRUPT:
@@ -1255,26 +1315,67 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1255 ret = -ENOMEM; 1315 ret = -ENOMEM;
1256 goto error; 1316 goto error;
1257 } 1317 }
1258 u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length; 1318
1319 u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
1320 num_sgs * sizeof(struct scatterlist);
1259 ret = usbfs_increase_memory_usage(u); 1321 ret = usbfs_increase_memory_usage(u);
1260 if (ret) 1322 if (ret)
1261 goto error; 1323 goto error;
1262 as->mem_usage = u; 1324 as->mem_usage = u;
1263 1325
1264 if (uurb->buffer_length > 0) { 1326 if (num_sgs) {
1327 as->urb->sg = kmalloc(num_sgs * sizeof(struct scatterlist),
1328 GFP_KERNEL);
1329 if (!as->urb->sg) {
1330 ret = -ENOMEM;
1331 goto error;
1332 }
1333 as->urb->num_sgs = num_sgs;
1334 sg_init_table(as->urb->sg, as->urb->num_sgs);
1335
1336 totlen = uurb->buffer_length;
1337 for (i = 0; i < as->urb->num_sgs; i++) {
1338 u = (totlen > USB_SG_SIZE) ? USB_SG_SIZE : totlen;
1339 buf = kmalloc(u, GFP_KERNEL);
1340 if (!buf) {
1341 ret = -ENOMEM;
1342 goto error;
1343 }
1344 sg_set_buf(&as->urb->sg[i], buf, u);
1345
1346 if (!is_in) {
1347 if (copy_from_user(buf, uurb->buffer, u)) {
1348 ret = -EFAULT;
1349 goto error;
1350 }
1351 }
1352 totlen -= u;
1353 }
1354 } else if (uurb->buffer_length > 0) {
1265 as->urb->transfer_buffer = kmalloc(uurb->buffer_length, 1355 as->urb->transfer_buffer = kmalloc(uurb->buffer_length,
1266 GFP_KERNEL); 1356 GFP_KERNEL);
1267 if (!as->urb->transfer_buffer) { 1357 if (!as->urb->transfer_buffer) {
1268 ret = -ENOMEM; 1358 ret = -ENOMEM;
1269 goto error; 1359 goto error;
1270 } 1360 }
1271 /* Isochronous input data may end up being discontiguous 1361
1272 * if some of the packets are short. Clear the buffer so 1362 if (!is_in) {
1273 * that the gaps don't leak kernel data to userspace. 1363 if (copy_from_user(as->urb->transfer_buffer,
1274 */ 1364 uurb->buffer,
1275 if (is_in && uurb->type == USBDEVFS_URB_TYPE_ISO) 1365 uurb->buffer_length)) {
1366 ret = -EFAULT;
1367 goto error;
1368 }
1369 } else if (uurb->type == USBDEVFS_URB_TYPE_ISO) {
1370 /*
1371 * Isochronous input data may end up being
1372 * discontiguous if some of the packets are short.
1373 * Clear the buffer so that the gaps don't leak
1374 * kernel data to userspace.
1375 */
1276 memset(as->urb->transfer_buffer, 0, 1376 memset(as->urb->transfer_buffer, 0,
1277 uurb->buffer_length); 1377 uurb->buffer_length);
1378 }
1278 } 1379 }
1279 as->urb->dev = ps->dev; 1380 as->urb->dev = ps->dev;
1280 as->urb->pipe = (uurb->type << 30) | 1381 as->urb->pipe = (uurb->type << 30) |
@@ -1328,17 +1429,12 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1328 as->pid = get_pid(task_pid(current)); 1429 as->pid = get_pid(task_pid(current));
1329 as->cred = get_current_cred(); 1430 as->cred = get_current_cred();
1330 security_task_getsecid(current, &as->secid); 1431 security_task_getsecid(current, &as->secid);
1331 if (!is_in && uurb->buffer_length > 0) {
1332 if (copy_from_user(as->urb->transfer_buffer, uurb->buffer,
1333 uurb->buffer_length)) {
1334 ret = -EFAULT;
1335 goto error;
1336 }
1337 }
1338 snoop_urb(ps->dev, as->userurb, as->urb->pipe, 1432 snoop_urb(ps->dev, as->userurb, as->urb->pipe,
1339 as->urb->transfer_buffer_length, 0, SUBMIT, 1433 as->urb->transfer_buffer_length, 0, SUBMIT,
1340 is_in ? NULL : as->urb->transfer_buffer, 1434 NULL, 0);
1341 uurb->buffer_length); 1435 if (!is_in)
1436 snoop_urb_data(as->urb, as->urb->transfer_buffer_length);
1437
1342 async_newpending(as); 1438 async_newpending(as);
1343 1439
1344 if (usb_endpoint_xfer_bulk(&ep->desc)) { 1440 if (usb_endpoint_xfer_bulk(&ep->desc)) {
@@ -1433,11 +1529,7 @@ static int processcompl(struct async *as, void __user * __user *arg)
1433 unsigned int i; 1529 unsigned int i;
1434 1530
1435 if (as->userbuffer && urb->actual_length) { 1531 if (as->userbuffer && urb->actual_length) {
1436 if (urb->number_of_packets > 0) /* Isochronous */ 1532 if (copy_urb_data_to_user(as->userbuffer, urb))
1437 i = urb->transfer_buffer_length;
1438 else /* Non-Isoc */
1439 i = urb->actual_length;
1440 if (copy_to_user(as->userbuffer, urb->transfer_buffer, i))
1441 goto err_out; 1533 goto err_out;
1442 } 1534 }
1443 if (put_user(as->status, &userurb->status)) 1535 if (put_user(as->status, &userurb->status))
@@ -1604,10 +1696,10 @@ static int processcompl_compat(struct async *as, void __user * __user *arg)
1604 void __user *addr = as->userurb; 1696 void __user *addr = as->userurb;
1605 unsigned int i; 1697 unsigned int i;
1606 1698
1607 if (as->userbuffer && urb->actual_length) 1699 if (as->userbuffer && urb->actual_length) {
1608 if (copy_to_user(as->userbuffer, urb->transfer_buffer, 1700 if (copy_urb_data_to_user(as->userbuffer, urb))
1609 urb->actual_length))
1610 return -EFAULT; 1701 return -EFAULT;
1702 }
1611 if (put_user(as->status, &userurb->status)) 1703 if (put_user(as->status, &userurb->status))
1612 return -EFAULT; 1704 return -EFAULT;
1613 if (put_user(urb->actual_length, &userurb->actual_length)) 1705 if (put_user(urb->actual_length, &userurb->actual_length))
@@ -1820,6 +1912,22 @@ static int proc_release_port(struct dev_state *ps, void __user *arg)
1820 return usb_hub_release_port(ps->dev, portnum, ps); 1912 return usb_hub_release_port(ps->dev, portnum, ps);
1821} 1913}
1822 1914
1915static int proc_get_capabilities(struct dev_state *ps, void __user *arg)
1916{
1917 __u32 caps;
1918
1919 caps = USBDEVFS_CAP_ZERO_PACKET | USBDEVFS_CAP_NO_PACKET_SIZE_LIM;
1920 if (!ps->dev->bus->no_stop_on_short)
1921 caps |= USBDEVFS_CAP_BULK_CONTINUATION;
1922 if (ps->dev->bus->sg_tablesize)
1923 caps |= USBDEVFS_CAP_BULK_SCATTER_GATHER;
1924
1925 if (put_user(caps, (__u32 __user *)arg))
1926 return -EFAULT;
1927
1928 return 0;
1929}
1930
1823/* 1931/*
1824 * NOTE: All requests here that have interface numbers as parameters 1932 * NOTE: All requests here that have interface numbers as parameters
1825 * are assuming that somehow the configuration has been prevented from 1933 * are assuming that somehow the configuration has been prevented from
@@ -1990,6 +2098,9 @@ static long usbdev_do_ioctl(struct file *file, unsigned int cmd,
1990 snoop(&dev->dev, "%s: RELEASE_PORT\n", __func__); 2098 snoop(&dev->dev, "%s: RELEASE_PORT\n", __func__);
1991 ret = proc_release_port(ps, p); 2099 ret = proc_release_port(ps, p);
1992 break; 2100 break;
2101 case USBDEVFS_GET_CAPABILITIES:
2102 ret = proc_get_capabilities(ps, p);
2103 break;
1993 } 2104 }
1994 usb_unlock_device(dev); 2105 usb_unlock_device(dev);
1995 if (ret >= 0) 2106 if (ret >= 0)
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index f536aebc958e..69781016a266 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -367,6 +367,7 @@ static int usb_probe_interface(struct device *dev)
367 return error; 367 return error;
368 368
369 err: 369 err:
370 usb_set_intfdata(intf, NULL);
370 intf->needs_remote_wakeup = 0; 371 intf->needs_remote_wakeup = 0;
371 intf->condition = USB_INTERFACE_UNBOUND; 372 intf->condition = USB_INTERFACE_UNBOUND;
372 usb_cancel_queued_reset(intf); 373 usb_cancel_queued_reset(intf);
@@ -622,14 +623,15 @@ int usb_match_one_id(struct usb_interface *interface,
622 if (!usb_match_device(dev, id)) 623 if (!usb_match_device(dev, id))
623 return 0; 624 return 0;
624 625
625 /* The interface class, subclass, and protocol should never be 626 /* The interface class, subclass, protocol and number should never be
626 * checked for a match if the device class is Vendor Specific, 627 * checked for a match if the device class is Vendor Specific,
627 * unless the match record specifies the Vendor ID. */ 628 * unless the match record specifies the Vendor ID. */
628 if (dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC && 629 if (dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC &&
629 !(id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && 630 !(id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
630 (id->match_flags & (USB_DEVICE_ID_MATCH_INT_CLASS | 631 (id->match_flags & (USB_DEVICE_ID_MATCH_INT_CLASS |
631 USB_DEVICE_ID_MATCH_INT_SUBCLASS | 632 USB_DEVICE_ID_MATCH_INT_SUBCLASS |
632 USB_DEVICE_ID_MATCH_INT_PROTOCOL))) 633 USB_DEVICE_ID_MATCH_INT_PROTOCOL |
634 USB_DEVICE_ID_MATCH_INT_NUMBER)))
633 return 0; 635 return 0;
634 636
635 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) && 637 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) &&
@@ -644,6 +646,10 @@ int usb_match_one_id(struct usb_interface *interface,
644 (id->bInterfaceProtocol != intf->desc.bInterfaceProtocol)) 646 (id->bInterfaceProtocol != intf->desc.bInterfaceProtocol))
645 return 0; 647 return 0;
646 648
649 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_NUMBER) &&
650 (id->bInterfaceNumber != intf->desc.bInterfaceNumber))
651 return 0;
652
647 return 1; 653 return 1;
648} 654}
649EXPORT_SYMBOL_GPL(usb_match_one_id); 655EXPORT_SYMBOL_GPL(usb_match_one_id);
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index e673b26e598f..e5387a47ef6f 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -92,7 +92,7 @@ static int init_usb_class(void)
92 } 92 }
93 93
94 kref_init(&usb_class->kref); 94 kref_init(&usb_class->kref);
95 usb_class->class = class_create(THIS_MODULE, "usb"); 95 usb_class->class = class_create(THIS_MODULE, "usbmisc");
96 if (IS_ERR(usb_class->class)) { 96 if (IS_ERR(usb_class->class)) {
97 result = IS_ERR(usb_class->class); 97 result = IS_ERR(usb_class->class);
98 printk(KERN_ERR "class_create failed for usb devices\n"); 98 printk(KERN_ERR "class_create failed for usb devices\n");
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 190b1ec7bdcb..bc84106ac057 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1398,7 +1398,15 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1398 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { 1398 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1399 if (hcd->self.uses_dma) { 1399 if (hcd->self.uses_dma) {
1400 if (urb->num_sgs) { 1400 if (urb->num_sgs) {
1401 int n = dma_map_sg( 1401 int n;
1402
1403 /* We don't support sg for isoc transfers ! */
1404 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) {
1405 WARN_ON(1);
1406 return -EINVAL;
1407 }
1408
1409 n = dma_map_sg(
1402 hcd->self.controller, 1410 hcd->self.controller,
1403 urb->sg, 1411 urb->sg,
1404 urb->num_sgs, 1412 urb->num_sgs,
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 8fb484984c86..9e900f9a2ef7 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -81,7 +81,7 @@ struct usb_hub {
81 u8 indicator[USB_MAXCHILDREN]; 81 u8 indicator[USB_MAXCHILDREN];
82 struct delayed_work leds; 82 struct delayed_work leds;
83 struct delayed_work init_work; 83 struct delayed_work init_work;
84 void **port_owners; 84 struct dev_state **port_owners;
85}; 85};
86 86
87static inline int hub_is_superspeed(struct usb_device *hdev) 87static inline int hub_is_superspeed(struct usb_device *hdev)
@@ -1271,7 +1271,8 @@ static int hub_configure(struct usb_hub *hub,
1271 1271
1272 hdev->children = kzalloc(hdev->maxchild * 1272 hdev->children = kzalloc(hdev->maxchild *
1273 sizeof(struct usb_device *), GFP_KERNEL); 1273 sizeof(struct usb_device *), GFP_KERNEL);
1274 hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL); 1274 hub->port_owners = kzalloc(hdev->maxchild * sizeof(struct dev_state *),
1275 GFP_KERNEL);
1275 if (!hdev->children || !hub->port_owners) { 1276 if (!hdev->children || !hub->port_owners) {
1276 ret = -ENOMEM; 1277 ret = -ENOMEM;
1277 goto fail; 1278 goto fail;
@@ -1649,7 +1650,7 @@ hub_ioctl(struct usb_interface *intf, unsigned int code, void *user_data)
1649 * to one of these "claimed" ports, the program will "own" the device. 1650 * to one of these "claimed" ports, the program will "own" the device.
1650 */ 1651 */
1651static int find_port_owner(struct usb_device *hdev, unsigned port1, 1652static int find_port_owner(struct usb_device *hdev, unsigned port1,
1652 void ***ppowner) 1653 struct dev_state ***ppowner)
1653{ 1654{
1654 if (hdev->state == USB_STATE_NOTATTACHED) 1655 if (hdev->state == USB_STATE_NOTATTACHED)
1655 return -ENODEV; 1656 return -ENODEV;
@@ -1664,10 +1665,11 @@ static int find_port_owner(struct usb_device *hdev, unsigned port1,
1664} 1665}
1665 1666
1666/* In the following three functions, the caller must hold hdev's lock */ 1667/* In the following three functions, the caller must hold hdev's lock */
1667int usb_hub_claim_port(struct usb_device *hdev, unsigned port1, void *owner) 1668int usb_hub_claim_port(struct usb_device *hdev, unsigned port1,
1669 struct dev_state *owner)
1668{ 1670{
1669 int rc; 1671 int rc;
1670 void **powner; 1672 struct dev_state **powner;
1671 1673
1672 rc = find_port_owner(hdev, port1, &powner); 1674 rc = find_port_owner(hdev, port1, &powner);
1673 if (rc) 1675 if (rc)
@@ -1678,10 +1680,11 @@ int usb_hub_claim_port(struct usb_device *hdev, unsigned port1, void *owner)
1678 return rc; 1680 return rc;
1679} 1681}
1680 1682
1681int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner) 1683int usb_hub_release_port(struct usb_device *hdev, unsigned port1,
1684 struct dev_state *owner)
1682{ 1685{
1683 int rc; 1686 int rc;
1684 void **powner; 1687 struct dev_state **powner;
1685 1688
1686 rc = find_port_owner(hdev, port1, &powner); 1689 rc = find_port_owner(hdev, port1, &powner);
1687 if (rc) 1690 if (rc)
@@ -1692,10 +1695,10 @@ int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner)
1692 return rc; 1695 return rc;
1693} 1696}
1694 1697
1695void usb_hub_release_all_ports(struct usb_device *hdev, void *owner) 1698void usb_hub_release_all_ports(struct usb_device *hdev, struct dev_state *owner)
1696{ 1699{
1697 int n; 1700 int n;
1698 void **powner; 1701 struct dev_state **powner;
1699 1702
1700 n = find_port_owner(hdev, 1, &powner); 1703 n = find_port_owner(hdev, 1, &powner);
1701 if (n == 0) { 1704 if (n == 0) {
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index bdd1c6749d88..8b9d669e3784 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1559,7 +1559,7 @@ static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
1559 1559
1560 if (add_uevent_var(env, 1560 if (add_uevent_var(env,
1561 "MODALIAS=usb:" 1561 "MODALIAS=usb:"
1562 "v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", 1562 "v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02Xin%02X",
1563 le16_to_cpu(usb_dev->descriptor.idVendor), 1563 le16_to_cpu(usb_dev->descriptor.idVendor),
1564 le16_to_cpu(usb_dev->descriptor.idProduct), 1564 le16_to_cpu(usb_dev->descriptor.idProduct),
1565 le16_to_cpu(usb_dev->descriptor.bcdDevice), 1565 le16_to_cpu(usb_dev->descriptor.bcdDevice),
@@ -1568,7 +1568,8 @@ static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
1568 usb_dev->descriptor.bDeviceProtocol, 1568 usb_dev->descriptor.bDeviceProtocol,
1569 alt->desc.bInterfaceClass, 1569 alt->desc.bInterfaceClass,
1570 alt->desc.bInterfaceSubClass, 1570 alt->desc.bInterfaceSubClass,
1571 alt->desc.bInterfaceProtocol)) 1571 alt->desc.bInterfaceProtocol,
1572 alt->desc.bInterfaceNumber))
1572 return -ENOMEM; 1573 return -ENOMEM;
1573 1574
1574 return 0; 1575 return 0;
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 9a56e3adf476..777f03c37725 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -840,7 +840,7 @@ static ssize_t show_modalias(struct device *dev,
840 alt = intf->cur_altsetting; 840 alt = intf->cur_altsetting;
841 841
842 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X" 842 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
843 "ic%02Xisc%02Xip%02X\n", 843 "ic%02Xisc%02Xip%02Xin%02X\n",
844 le16_to_cpu(udev->descriptor.idVendor), 844 le16_to_cpu(udev->descriptor.idVendor),
845 le16_to_cpu(udev->descriptor.idProduct), 845 le16_to_cpu(udev->descriptor.idProduct),
846 le16_to_cpu(udev->descriptor.bcdDevice), 846 le16_to_cpu(udev->descriptor.bcdDevice),
@@ -849,7 +849,8 @@ static ssize_t show_modalias(struct device *dev,
849 udev->descriptor.bDeviceProtocol, 849 udev->descriptor.bDeviceProtocol,
850 alt->desc.bInterfaceClass, 850 alt->desc.bInterfaceClass,
851 alt->desc.bInterfaceSubClass, 851 alt->desc.bInterfaceSubClass,
852 alt->desc.bInterfaceProtocol); 852 alt->desc.bInterfaceProtocol,
853 alt->desc.bInterfaceNumber);
853} 854}
854static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); 855static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
855 856
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 5c5c538ea73d..67875a89cfa1 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -1,5 +1,7 @@
1#include <linux/pm.h> 1#include <linux/pm.h>
2 2
3struct dev_state;
4
3/* Functions local to drivers/usb/core/ */ 5/* Functions local to drivers/usb/core/ */
4 6
5extern int usb_create_sysfs_dev_files(struct usb_device *dev); 7extern int usb_create_sysfs_dev_files(struct usb_device *dev);
@@ -41,10 +43,11 @@ extern void usb_forced_unbind_intf(struct usb_interface *intf);
41extern void usb_rebind_intf(struct usb_interface *intf); 43extern void usb_rebind_intf(struct usb_interface *intf);
42 44
43extern int usb_hub_claim_port(struct usb_device *hdev, unsigned port, 45extern int usb_hub_claim_port(struct usb_device *hdev, unsigned port,
44 void *owner); 46 struct dev_state *owner);
45extern int usb_hub_release_port(struct usb_device *hdev, unsigned port, 47extern int usb_hub_release_port(struct usb_device *hdev, unsigned port,
46 void *owner); 48 struct dev_state *owner);
47extern void usb_hub_release_all_ports(struct usb_device *hdev, void *owner); 49extern void usb_hub_release_all_ports(struct usb_device *hdev,
50 struct dev_state *owner);
48extern bool usb_device_is_owned(struct usb_device *udev); 51extern bool usb_device_is_owned(struct usb_device *udev);
49 52
50extern int usb_hub_init(void); 53extern int usb_hub_init(void);
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 1040bdb8dc88..c34452a7304f 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -148,6 +148,8 @@ static void dwc3_core_soft_reset(struct dwc3 *dwc)
148 reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST; 148 reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST;
149 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 149 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
150 150
151 mdelay(100);
152
151 /* After PHYs are stable we can take Core out of reset state */ 153 /* After PHYs are stable we can take Core out of reset state */
152 reg = dwc3_readl(dwc->regs, DWC3_GCTL); 154 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
153 reg &= ~DWC3_GCTL_CORESOFTRESET; 155 reg &= ~DWC3_GCTL_CORESOFTRESET;
@@ -255,7 +257,7 @@ static int __devinit dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
255 * 257 *
256 * Returns 0 on success otherwise negative errno. 258 * Returns 0 on success otherwise negative errno.
257 */ 259 */
258static int __devinit dwc3_event_buffers_setup(struct dwc3 *dwc) 260static int dwc3_event_buffers_setup(struct dwc3 *dwc)
259{ 261{
260 struct dwc3_event_buffer *evt; 262 struct dwc3_event_buffer *evt;
261 int n; 263 int n;
@@ -266,6 +268,8 @@ static int __devinit dwc3_event_buffers_setup(struct dwc3 *dwc)
266 evt->buf, (unsigned long long) evt->dma, 268 evt->buf, (unsigned long long) evt->dma,
267 evt->length); 269 evt->length);
268 270
271 evt->lpos = 0;
272
269 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 273 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
270 lower_32_bits(evt->dma)); 274 lower_32_bits(evt->dma));
271 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 275 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
@@ -285,6 +289,9 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
285 289
286 for (n = 0; n < dwc->num_event_buffers; n++) { 290 for (n = 0; n < dwc->num_event_buffers; n++) {
287 evt = dwc->ev_buffs[n]; 291 evt = dwc->ev_buffs[n];
292
293 evt->lpos = 0;
294
288 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0); 295 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
289 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0); 296 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
290 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), 0); 297 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), 0);
@@ -328,8 +335,6 @@ static int __devinit dwc3_core_init(struct dwc3 *dwc)
328 } 335 }
329 dwc->revision = reg; 336 dwc->revision = reg;
330 337
331 dwc3_core_soft_reset(dwc);
332
333 /* issue device SoftReset too */ 338 /* issue device SoftReset too */
334 timeout = jiffies + msecs_to_jiffies(500); 339 timeout = jiffies + msecs_to_jiffies(500);
335 dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); 340 dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
@@ -347,6 +352,8 @@ static int __devinit dwc3_core_init(struct dwc3 *dwc)
347 cpu_relax(); 352 cpu_relax();
348 } while (true); 353 } while (true);
349 354
355 dwc3_core_soft_reset(dwc);
356
350 dwc3_cache_hwparams(dwc); 357 dwc3_cache_hwparams(dwc);
351 358
352 reg = dwc3_readl(dwc->regs, DWC3_GCTL); 359 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index f69c877add09..151eca876dfd 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -67,6 +67,7 @@
67#define DWC3_DEVICE_EVENT_CONNECT_DONE 2 67#define DWC3_DEVICE_EVENT_CONNECT_DONE 2
68#define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE 3 68#define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE 3
69#define DWC3_DEVICE_EVENT_WAKEUP 4 69#define DWC3_DEVICE_EVENT_WAKEUP 4
70#define DWC3_DEVICE_EVENT_HIBER_REQ 5
70#define DWC3_DEVICE_EVENT_EOPF 6 71#define DWC3_DEVICE_EVENT_EOPF 6
71#define DWC3_DEVICE_EVENT_SOF 7 72#define DWC3_DEVICE_EVENT_SOF 7
72#define DWC3_DEVICE_EVENT_ERRATIC_ERROR 9 73#define DWC3_DEVICE_EVENT_ERRATIC_ERROR 9
@@ -171,28 +172,36 @@
171#define DWC3_GCTL_PRTCAP_DEVICE 2 172#define DWC3_GCTL_PRTCAP_DEVICE 2
172#define DWC3_GCTL_PRTCAP_OTG 3 173#define DWC3_GCTL_PRTCAP_OTG 3
173 174
174#define DWC3_GCTL_CORESOFTRESET (1 << 11) 175#define DWC3_GCTL_CORESOFTRESET (1 << 11)
175#define DWC3_GCTL_SCALEDOWN(n) ((n) << 4) 176#define DWC3_GCTL_SCALEDOWN(n) ((n) << 4)
176#define DWC3_GCTL_SCALEDOWN_MASK DWC3_GCTL_SCALEDOWN(3) 177#define DWC3_GCTL_SCALEDOWN_MASK DWC3_GCTL_SCALEDOWN(3)
177#define DWC3_GCTL_DISSCRAMBLE (1 << 3) 178#define DWC3_GCTL_DISSCRAMBLE (1 << 3)
178#define DWC3_GCTL_DSBLCLKGTNG (1 << 0) 179#define DWC3_GCTL_GBLHIBERNATIONEN (1 << 1)
180#define DWC3_GCTL_DSBLCLKGTNG (1 << 0)
179 181
180/* Global USB2 PHY Configuration Register */ 182/* Global USB2 PHY Configuration Register */
181#define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31) 183#define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31)
182#define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6) 184#define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6)
183 185
184/* Global USB3 PIPE Control Register */ 186/* Global USB3 PIPE Control Register */
185#define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31) 187#define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31)
186#define DWC3_GUSB3PIPECTL_SUSPHY (1 << 17) 188#define DWC3_GUSB3PIPECTL_SUSPHY (1 << 17)
187 189
188/* Global TX Fifo Size Register */ 190/* Global TX Fifo Size Register */
189#define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff) 191#define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff)
190#define DWC3_GTXFIFOSIZ_TXFSTADDR(n) ((n) & 0xffff0000) 192#define DWC3_GTXFIFOSIZ_TXFSTADDR(n) ((n) & 0xffff0000)
191 193
192/* Global HWPARAMS1 Register */ 194/* Global HWPARAMS1 Register */
193#define DWC3_GHWPARAMS1_EN_PWROPT(n) (((n) & (3 << 24)) >> 24) 195#define DWC3_GHWPARAMS1_EN_PWROPT(n) (((n) & (3 << 24)) >> 24)
194#define DWC3_GHWPARAMS1_EN_PWROPT_NO 0 196#define DWC3_GHWPARAMS1_EN_PWROPT_NO 0
195#define DWC3_GHWPARAMS1_EN_PWROPT_CLK 1 197#define DWC3_GHWPARAMS1_EN_PWROPT_CLK 1
198#define DWC3_GHWPARAMS1_EN_PWROPT_HIB 2
199#define DWC3_GHWPARAMS1_PWROPT(n) ((n) << 24)
200#define DWC3_GHWPARAMS1_PWROPT_MASK DWC3_GHWPARAMS1_PWROPT(3)
201
202/* Global HWPARAMS4 Register */
203#define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13)
204#define DWC3_MAX_HIBER_SCRATCHBUFS 15
196 205
197/* Device Configuration Register */ 206/* Device Configuration Register */
198#define DWC3_DCFG_LPM_CAP (1 << 22) 207#define DWC3_DCFG_LPM_CAP (1 << 22)
@@ -206,24 +215,32 @@
206#define DWC3_DCFG_LOWSPEED (2 << 0) 215#define DWC3_DCFG_LOWSPEED (2 << 0)
207#define DWC3_DCFG_FULLSPEED1 (3 << 0) 216#define DWC3_DCFG_FULLSPEED1 (3 << 0)
208 217
218#define DWC3_DCFG_LPM_CAP (1 << 22)
219
209/* Device Control Register */ 220/* Device Control Register */
210#define DWC3_DCTL_RUN_STOP (1 << 31) 221#define DWC3_DCTL_RUN_STOP (1 << 31)
211#define DWC3_DCTL_CSFTRST (1 << 30) 222#define DWC3_DCTL_CSFTRST (1 << 30)
212#define DWC3_DCTL_LSFTRST (1 << 29) 223#define DWC3_DCTL_LSFTRST (1 << 29)
213 224
214#define DWC3_DCTL_HIRD_THRES_MASK (0x1f << 24) 225#define DWC3_DCTL_HIRD_THRES_MASK (0x1f << 24)
215#define DWC3_DCTL_HIRD_THRES(n) (((n) & DWC3_DCTL_HIRD_THRES_MASK) >> 24) 226#define DWC3_DCTL_HIRD_THRES(n) ((n) << 24)
216 227
217#define DWC3_DCTL_APPL1RES (1 << 23) 228#define DWC3_DCTL_APPL1RES (1 << 23)
218 229
219#define DWC3_DCTL_TRGTULST_MASK (0x0f << 17) 230/* These apply for core versions 1.87a and earlier */
220#define DWC3_DCTL_TRGTULST(n) ((n) << 17) 231#define DWC3_DCTL_TRGTULST_MASK (0x0f << 17)
221 232#define DWC3_DCTL_TRGTULST(n) ((n) << 17)
222#define DWC3_DCTL_TRGTULST_U2 (DWC3_DCTL_TRGTULST(2)) 233#define DWC3_DCTL_TRGTULST_U2 (DWC3_DCTL_TRGTULST(2))
223#define DWC3_DCTL_TRGTULST_U3 (DWC3_DCTL_TRGTULST(3)) 234#define DWC3_DCTL_TRGTULST_U3 (DWC3_DCTL_TRGTULST(3))
224#define DWC3_DCTL_TRGTULST_SS_DIS (DWC3_DCTL_TRGTULST(4)) 235#define DWC3_DCTL_TRGTULST_SS_DIS (DWC3_DCTL_TRGTULST(4))
225#define DWC3_DCTL_TRGTULST_RX_DET (DWC3_DCTL_TRGTULST(5)) 236#define DWC3_DCTL_TRGTULST_RX_DET (DWC3_DCTL_TRGTULST(5))
226#define DWC3_DCTL_TRGTULST_SS_INACT (DWC3_DCTL_TRGTULST(6)) 237#define DWC3_DCTL_TRGTULST_SS_INACT (DWC3_DCTL_TRGTULST(6))
238
239/* These apply for core versions 1.94a and later */
240#define DWC3_DCTL_KEEP_CONNECT (1 << 19)
241#define DWC3_DCTL_L1_HIBER_EN (1 << 18)
242#define DWC3_DCTL_CRS (1 << 17)
243#define DWC3_DCTL_CSS (1 << 16)
227 244
228#define DWC3_DCTL_INITU2ENA (1 << 12) 245#define DWC3_DCTL_INITU2ENA (1 << 12)
229#define DWC3_DCTL_ACCEPTU2ENA (1 << 11) 246#define DWC3_DCTL_ACCEPTU2ENA (1 << 11)
@@ -249,6 +266,7 @@
249#define DWC3_DEVTEN_ERRTICERREN (1 << 9) 266#define DWC3_DEVTEN_ERRTICERREN (1 << 9)
250#define DWC3_DEVTEN_SOFEN (1 << 7) 267#define DWC3_DEVTEN_SOFEN (1 << 7)
251#define DWC3_DEVTEN_EOPFEN (1 << 6) 268#define DWC3_DEVTEN_EOPFEN (1 << 6)
269#define DWC3_DEVTEN_HIBERNATIONREQEVTEN (1 << 5)
252#define DWC3_DEVTEN_WKUPEVTEN (1 << 4) 270#define DWC3_DEVTEN_WKUPEVTEN (1 << 4)
253#define DWC3_DEVTEN_ULSTCNGEN (1 << 3) 271#define DWC3_DEVTEN_ULSTCNGEN (1 << 3)
254#define DWC3_DEVTEN_CONNECTDONEEN (1 << 2) 272#define DWC3_DEVTEN_CONNECTDONEEN (1 << 2)
@@ -256,7 +274,15 @@
256#define DWC3_DEVTEN_DISCONNEVTEN (1 << 0) 274#define DWC3_DEVTEN_DISCONNEVTEN (1 << 0)
257 275
258/* Device Status Register */ 276/* Device Status Register */
277#define DWC3_DSTS_DCNRD (1 << 29)
278
279/* This applies for core versions 1.87a and earlier */
259#define DWC3_DSTS_PWRUPREQ (1 << 24) 280#define DWC3_DSTS_PWRUPREQ (1 << 24)
281
282/* These apply for core versions 1.94a and later */
283#define DWC3_DSTS_RSS (1 << 25)
284#define DWC3_DSTS_SSS (1 << 24)
285
260#define DWC3_DSTS_COREIDLE (1 << 23) 286#define DWC3_DSTS_COREIDLE (1 << 23)
261#define DWC3_DSTS_DEVCTRLHLT (1 << 22) 287#define DWC3_DSTS_DEVCTRLHLT (1 << 22)
262 288
@@ -265,7 +291,7 @@
265 291
266#define DWC3_DSTS_RXFIFOEMPTY (1 << 17) 292#define DWC3_DSTS_RXFIFOEMPTY (1 << 17)
267 293
268#define DWC3_DSTS_SOFFN_MASK (0x3ff << 3) 294#define DWC3_DSTS_SOFFN_MASK (0x3fff << 3)
269#define DWC3_DSTS_SOFFN(n) (((n) & DWC3_DSTS_SOFFN_MASK) >> 3) 295#define DWC3_DSTS_SOFFN(n) (((n) & DWC3_DSTS_SOFFN_MASK) >> 3)
270 296
271#define DWC3_DSTS_CONNECTSPD (7 << 0) 297#define DWC3_DSTS_CONNECTSPD (7 << 0)
@@ -280,6 +306,11 @@
280#define DWC3_DGCMD_SET_LMP 0x01 306#define DWC3_DGCMD_SET_LMP 0x01
281#define DWC3_DGCMD_SET_PERIODIC_PAR 0x02 307#define DWC3_DGCMD_SET_PERIODIC_PAR 0x02
282#define DWC3_DGCMD_XMIT_FUNCTION 0x03 308#define DWC3_DGCMD_XMIT_FUNCTION 0x03
309
310/* These apply for core versions 1.94a and later */
311#define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO 0x04
312#define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI 0x05
313
283#define DWC3_DGCMD_SELECTED_FIFO_FLUSH 0x09 314#define DWC3_DGCMD_SELECTED_FIFO_FLUSH 0x09
284#define DWC3_DGCMD_ALL_FIFO_FLUSH 0x0a 315#define DWC3_DGCMD_ALL_FIFO_FLUSH 0x0a
285#define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c 316#define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c
@@ -287,6 +318,15 @@
287 318
288#define DWC3_DGCMD_STATUS(n) (((n) >> 15) & 1) 319#define DWC3_DGCMD_STATUS(n) (((n) >> 15) & 1)
289#define DWC3_DGCMD_CMDACT (1 << 10) 320#define DWC3_DGCMD_CMDACT (1 << 10)
321#define DWC3_DGCMD_CMDIOC (1 << 8)
322
323/* Device Generic Command Parameter Register */
324#define DWC3_DGCMDPAR_FORCE_LINKPM_ACCEPT (1 << 0)
325#define DWC3_DGCMDPAR_FIFO_NUM(n) ((n) << 0)
326#define DWC3_DGCMDPAR_RX_FIFO (0 << 5)
327#define DWC3_DGCMDPAR_TX_FIFO (1 << 5)
328#define DWC3_DGCMDPAR_LOOPBACK_DIS (0 << 0)
329#define DWC3_DGCMDPAR_LOOPBACK_ENA (1 << 0)
290 330
291/* Device Endpoint Command Register */ 331/* Device Endpoint Command Register */
292#define DWC3_DEPCMD_PARAM_SHIFT 16 332#define DWC3_DEPCMD_PARAM_SHIFT 16
@@ -303,7 +343,10 @@
303#define DWC3_DEPCMD_STARTTRANSFER (0x06 << 0) 343#define DWC3_DEPCMD_STARTTRANSFER (0x06 << 0)
304#define DWC3_DEPCMD_CLEARSTALL (0x05 << 0) 344#define DWC3_DEPCMD_CLEARSTALL (0x05 << 0)
305#define DWC3_DEPCMD_SETSTALL (0x04 << 0) 345#define DWC3_DEPCMD_SETSTALL (0x04 << 0)
346/* This applies for core versions 1.90a and earlier */
306#define DWC3_DEPCMD_GETSEQNUMBER (0x03 << 0) 347#define DWC3_DEPCMD_GETSEQNUMBER (0x03 << 0)
348/* This applies for core versions 1.94a and later */
349#define DWC3_DEPCMD_GETEPSTATE (0x03 << 0)
307#define DWC3_DEPCMD_SETTRANSFRESOURCE (0x02 << 0) 350#define DWC3_DEPCMD_SETTRANSFRESOURCE (0x02 << 0)
308#define DWC3_DEPCMD_SETEPCONFIG (0x01 << 0) 351#define DWC3_DEPCMD_SETEPCONFIG (0x01 << 0)
309 352
@@ -361,7 +404,8 @@ struct dwc3_event_buffer {
361 * @current_trb: index of current used trb 404 * @current_trb: index of current used trb
362 * @number: endpoint number (1 - 15) 405 * @number: endpoint number (1 - 15)
363 * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK 406 * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
364 * @res_trans_idx: Resource transfer index 407 * @resource_index: Resource transfer index
408 * @current_uf: Current uf received through last event parameter
365 * @interval: the intervall on which the ISOC transfer is started 409 * @interval: the intervall on which the ISOC transfer is started
366 * @name: a human readable name e.g. ep1out-bulk 410 * @name: a human readable name e.g. ep1out-bulk
367 * @direction: true for TX, false for RX 411 * @direction: true for TX, false for RX
@@ -385,6 +429,7 @@ struct dwc3_ep {
385#define DWC3_EP_WEDGE (1 << 2) 429#define DWC3_EP_WEDGE (1 << 2)
386#define DWC3_EP_BUSY (1 << 4) 430#define DWC3_EP_BUSY (1 << 4)
387#define DWC3_EP_PENDING_REQUEST (1 << 5) 431#define DWC3_EP_PENDING_REQUEST (1 << 5)
432#define DWC3_EP_MISSED_ISOC (1 << 6)
388 433
389 /* This last one is specific to EP0 */ 434 /* This last one is specific to EP0 */
390#define DWC3_EP0_DIR_IN (1 << 31) 435#define DWC3_EP0_DIR_IN (1 << 31)
@@ -393,7 +438,8 @@ struct dwc3_ep {
393 438
394 u8 number; 439 u8 number;
395 u8 type; 440 u8 type;
396 u8 res_trans_idx; 441 u8 resource_index;
442 u16 current_uf;
397 u32 interval; 443 u32 interval;
398 444
399 char name[20]; 445 char name[20];
@@ -437,6 +483,8 @@ enum dwc3_link_state {
437 DWC3_LINK_STATE_HRESET = 0x09, 483 DWC3_LINK_STATE_HRESET = 0x09,
438 DWC3_LINK_STATE_CMPLY = 0x0a, 484 DWC3_LINK_STATE_CMPLY = 0x0a,
439 DWC3_LINK_STATE_LPBK = 0x0b, 485 DWC3_LINK_STATE_LPBK = 0x0b,
486 DWC3_LINK_STATE_RESET = 0x0e,
487 DWC3_LINK_STATE_RESUME = 0x0f,
440 DWC3_LINK_STATE_MASK = 0x0f, 488 DWC3_LINK_STATE_MASK = 0x0f,
441}; 489};
442 490
@@ -450,11 +498,12 @@ enum dwc3_device_state {
450#define DWC3_TRB_SIZE_MASK (0x00ffffff) 498#define DWC3_TRB_SIZE_MASK (0x00ffffff)
451#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK) 499#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
452#define DWC3_TRB_SIZE_PCM1(n) (((n) & 0x03) << 24) 500#define DWC3_TRB_SIZE_PCM1(n) (((n) & 0x03) << 24)
453#define DWC3_TRB_SIZE_TRBSTS(n) (((n) & (0x0f << 28) >> 28)) 501#define DWC3_TRB_SIZE_TRBSTS(n) (((n) & (0x0f << 28)) >> 28)
454 502
455#define DWC3_TRBSTS_OK 0 503#define DWC3_TRBSTS_OK 0
456#define DWC3_TRBSTS_MISSED_ISOC 1 504#define DWC3_TRBSTS_MISSED_ISOC 1
457#define DWC3_TRBSTS_SETUP_PENDING 2 505#define DWC3_TRBSTS_SETUP_PENDING 2
506#define DWC3_TRB_STS_XFER_IN_PROG 4
458 507
459/* TRB Control */ 508/* TRB Control */
460#define DWC3_TRB_CTRL_HWO (1 << 0) 509#define DWC3_TRB_CTRL_HWO (1 << 0)
@@ -543,6 +592,14 @@ struct dwc3_request {
543 unsigned queued:1; 592 unsigned queued:1;
544}; 593};
545 594
595/*
596 * struct dwc3_scratchpad_array - hibernation scratchpad array
597 * (format defined by hw)
598 */
599struct dwc3_scratchpad_array {
600 __le64 dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS];
601};
602
546/** 603/**
547 * struct dwc3 - representation of our controller 604 * struct dwc3 - representation of our controller
548 * @ctrl_req: usb control request which is used for ep0 605 * @ctrl_req: usb control request which is used for ep0
@@ -624,8 +681,10 @@ struct dwc3 {
624#define DWC3_REVISION_180A 0x5533180a 681#define DWC3_REVISION_180A 0x5533180a
625#define DWC3_REVISION_183A 0x5533183a 682#define DWC3_REVISION_183A 0x5533183a
626#define DWC3_REVISION_185A 0x5533185a 683#define DWC3_REVISION_185A 0x5533185a
684#define DWC3_REVISION_187A 0x5533187a
627#define DWC3_REVISION_188A 0x5533188a 685#define DWC3_REVISION_188A 0x5533188a
628#define DWC3_REVISION_190A 0x5533190a 686#define DWC3_REVISION_190A 0x5533190a
687#define DWC3_REVISION_194A 0x5533194a
629#define DWC3_REVISION_200A 0x5533200a 688#define DWC3_REVISION_200A 0x5533200a
630#define DWC3_REVISION_202A 0x5533202a 689#define DWC3_REVISION_202A 0x5533202a
631#define DWC3_REVISION_210A 0x5533210a 690#define DWC3_REVISION_210A 0x5533210a
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index d19030198086..b8f00389fa34 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -18,7 +18,6 @@
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/platform_data/dwc3-exynos.h> 19#include <linux/platform_data/dwc3-exynos.h>
20#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
21#include <linux/module.h>
22#include <linux/clk.h> 21#include <linux/clk.h>
23 22
24#include "core.h" 23#include "core.h"
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 9e8a3dce69fd..9b94886b66e5 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -54,7 +54,9 @@
54#include "gadget.h" 54#include "gadget.h"
55#include "io.h" 55#include "io.h"
56 56
57static void dwc3_ep0_do_control_status(struct dwc3 *dwc, u32 epnum); 57static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep);
58static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
59 struct dwc3_ep *dep, struct dwc3_request *req);
58 60
59static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state) 61static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
60{ 62{
@@ -111,7 +113,7 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
111 } 113 }
112 114
113 dep->flags |= DWC3_EP_BUSY; 115 dep->flags |= DWC3_EP_BUSY;
114 dep->res_trans_idx = dwc3_gadget_ep_get_transfer_index(dwc, 116 dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc,
115 dep->number); 117 dep->number);
116 118
117 dwc->ep0_next_event = DWC3_EP0_COMPLETE; 119 dwc->ep0_next_event = DWC3_EP0_COMPLETE;
@@ -150,16 +152,15 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
150 return 0; 152 return 0;
151 } 153 }
152 154
153 ret = dwc3_ep0_start_trans(dwc, direction, 155 __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req);
154 req->request.dma, req->request.length, 156
155 DWC3_TRBCTL_CONTROL_DATA);
156 dep->flags &= ~(DWC3_EP_PENDING_REQUEST | 157 dep->flags &= ~(DWC3_EP_PENDING_REQUEST |
157 DWC3_EP0_DIR_IN); 158 DWC3_EP0_DIR_IN);
158 } else if (dwc->delayed_status) { 159 } else if (dwc->delayed_status) {
159 dwc->delayed_status = false; 160 dwc->delayed_status = false;
160 161
161 if (dwc->ep0state == EP0_STATUS_PHASE) 162 if (dwc->ep0state == EP0_STATUS_PHASE)
162 dwc3_ep0_do_control_status(dwc, 1); 163 __dwc3_ep0_do_control_status(dwc, dwc->eps[1]);
163 else 164 else
164 dev_dbg(dwc->dev, "too early for delayed status\n"); 165 dev_dbg(dwc->dev, "too early for delayed status\n");
165 } 166 }
@@ -224,6 +225,16 @@ static void dwc3_ep0_stall_and_restart(struct dwc3 *dwc)
224 dwc3_ep0_out_start(dwc); 225 dwc3_ep0_out_start(dwc);
225} 226}
226 227
228int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value)
229{
230 struct dwc3_ep *dep = to_dwc3_ep(ep);
231 struct dwc3 *dwc = dep->dwc;
232
233 dwc3_ep0_stall_and_restart(dwc);
234
235 return 0;
236}
237
227void dwc3_ep0_out_start(struct dwc3 *dwc) 238void dwc3_ep0_out_start(struct dwc3 *dwc)
228{ 239{
229 int ret; 240 int ret;
@@ -463,6 +474,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
463{ 474{
464 u32 cfg; 475 u32 cfg;
465 int ret; 476 int ret;
477 u32 reg;
466 478
467 dwc->start_config_issued = false; 479 dwc->start_config_issued = false;
468 cfg = le16_to_cpu(ctrl->wValue); 480 cfg = le16_to_cpu(ctrl->wValue);
@@ -477,6 +489,14 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
477 /* if the cfg matches and the cfg is non zero */ 489 /* if the cfg matches and the cfg is non zero */
478 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { 490 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) {
479 dwc->dev_state = DWC3_CONFIGURED_STATE; 491 dwc->dev_state = DWC3_CONFIGURED_STATE;
492 /*
493 * Enable transition to U1/U2 state when
494 * nothing is pending from application.
495 */
496 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
497 reg |= (DWC3_DCTL_ACCEPTU1ENA | DWC3_DCTL_ACCEPTU2ENA);
498 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
499
480 dwc->resize_fifos = true; 500 dwc->resize_fifos = true;
481 dev_dbg(dwc->dev, "resize fifos flag SET\n"); 501 dev_dbg(dwc->dev, "resize fifos flag SET\n");
482 } 502 }
@@ -514,8 +534,8 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req)
514 534
515 dwc->u1sel = timing.u1sel; 535 dwc->u1sel = timing.u1sel;
516 dwc->u1pel = timing.u1pel; 536 dwc->u1pel = timing.u1pel;
517 dwc->u2sel = timing.u2sel; 537 dwc->u2sel = le16_to_cpu(timing.u2sel);
518 dwc->u2pel = timing.u2pel; 538 dwc->u2pel = le16_to_cpu(timing.u2pel);
519 539
520 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 540 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
521 if (reg & DWC3_DCTL_INITU2ENA) 541 if (reg & DWC3_DCTL_INITU2ENA)
@@ -640,11 +660,11 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc,
640 const struct dwc3_event_depevt *event) 660 const struct dwc3_event_depevt *event)
641{ 661{
642 struct usb_ctrlrequest *ctrl = dwc->ctrl_req; 662 struct usb_ctrlrequest *ctrl = dwc->ctrl_req;
643 int ret; 663 int ret = -EINVAL;
644 u32 len; 664 u32 len;
645 665
646 if (!dwc->gadget_driver) 666 if (!dwc->gadget_driver)
647 goto err; 667 goto out;
648 668
649 len = le16_to_cpu(ctrl->wLength); 669 len = le16_to_cpu(ctrl->wLength);
650 if (!len) { 670 if (!len) {
@@ -665,11 +685,9 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc,
665 if (ret == USB_GADGET_DELAYED_STATUS) 685 if (ret == USB_GADGET_DELAYED_STATUS)
666 dwc->delayed_status = true; 686 dwc->delayed_status = true;
667 687
668 if (ret >= 0) 688out:
669 return; 689 if (ret < 0)
670 690 dwc3_ep0_stall_and_restart(dwc);
671err:
672 dwc3_ep0_stall_and_restart(dwc);
673} 691}
674 692
675static void dwc3_ep0_complete_data(struct dwc3 *dwc, 693static void dwc3_ep0_complete_data(struct dwc3 *dwc,
@@ -723,7 +741,7 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
723 } 741 }
724} 742}
725 743
726static void dwc3_ep0_complete_req(struct dwc3 *dwc, 744static void dwc3_ep0_complete_status(struct dwc3 *dwc,
727 const struct dwc3_event_depevt *event) 745 const struct dwc3_event_depevt *event)
728{ 746{
729 struct dwc3_request *r; 747 struct dwc3_request *r;
@@ -745,6 +763,7 @@ static void dwc3_ep0_complete_req(struct dwc3 *dwc,
745 dev_dbg(dwc->dev, "Invalid Test #%d\n", 763 dev_dbg(dwc->dev, "Invalid Test #%d\n",
746 dwc->test_mode_nr); 764 dwc->test_mode_nr);
747 dwc3_ep0_stall_and_restart(dwc); 765 dwc3_ep0_stall_and_restart(dwc);
766 return;
748 } 767 }
749 } 768 }
750 769
@@ -758,7 +777,7 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc,
758 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; 777 struct dwc3_ep *dep = dwc->eps[event->endpoint_number];
759 778
760 dep->flags &= ~DWC3_EP_BUSY; 779 dep->flags &= ~DWC3_EP_BUSY;
761 dep->res_trans_idx = 0; 780 dep->resource_index = 0;
762 dwc->setup_packet_pending = false; 781 dwc->setup_packet_pending = false;
763 782
764 switch (dwc->ep0state) { 783 switch (dwc->ep0state) {
@@ -774,7 +793,7 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc,
774 793
775 case EP0_STATUS_PHASE: 794 case EP0_STATUS_PHASE:
776 dev_vdbg(dwc->dev, "Status Phase\n"); 795 dev_vdbg(dwc->dev, "Status Phase\n");
777 dwc3_ep0_complete_req(dwc, event); 796 dwc3_ep0_complete_status(dwc, event);
778 break; 797 break;
779 default: 798 default:
780 WARN(true, "UNKNOWN ep0state %d\n", dwc->ep0state); 799 WARN(true, "UNKNOWN ep0state %d\n", dwc->ep0state);
@@ -787,68 +806,81 @@ static void dwc3_ep0_do_control_setup(struct dwc3 *dwc,
787 dwc3_ep0_out_start(dwc); 806 dwc3_ep0_out_start(dwc);
788} 807}
789 808
790static void dwc3_ep0_do_control_data(struct dwc3 *dwc, 809static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
791 const struct dwc3_event_depevt *event) 810 struct dwc3_ep *dep, struct dwc3_request *req)
792{ 811{
793 struct dwc3_ep *dep;
794 struct dwc3_request *req;
795 int ret; 812 int ret;
796 813
797 dep = dwc->eps[0]; 814 req->direction = !!dep->number;
798
799 if (list_empty(&dep->request_list)) {
800 dev_vdbg(dwc->dev, "pending request for EP0 Data phase\n");
801 dep->flags |= DWC3_EP_PENDING_REQUEST;
802
803 if (event->endpoint_number)
804 dep->flags |= DWC3_EP0_DIR_IN;
805 return;
806 }
807
808 req = next_request(&dep->request_list);
809 req->direction = !!event->endpoint_number;
810 815
811 if (req->request.length == 0) { 816 if (req->request.length == 0) {
812 ret = dwc3_ep0_start_trans(dwc, event->endpoint_number, 817 ret = dwc3_ep0_start_trans(dwc, dep->number,
813 dwc->ctrl_req_addr, 0, 818 dwc->ctrl_req_addr, 0,
814 DWC3_TRBCTL_CONTROL_DATA); 819 DWC3_TRBCTL_CONTROL_DATA);
815 } else if ((req->request.length % dep->endpoint.maxpacket) 820 } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket)
816 && (event->endpoint_number == 0)) { 821 && (dep->number == 0)) {
822 u32 transfer_size;
823
817 ret = usb_gadget_map_request(&dwc->gadget, &req->request, 824 ret = usb_gadget_map_request(&dwc->gadget, &req->request,
818 event->endpoint_number); 825 dep->number);
819 if (ret) { 826 if (ret) {
820 dev_dbg(dwc->dev, "failed to map request\n"); 827 dev_dbg(dwc->dev, "failed to map request\n");
821 return; 828 return;
822 } 829 }
823 830
824 WARN_ON(req->request.length > dep->endpoint.maxpacket); 831 WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE);
832
833 transfer_size = roundup(req->request.length,
834 (u32) dep->endpoint.maxpacket);
825 835
826 dwc->ep0_bounced = true; 836 dwc->ep0_bounced = true;
827 837
828 /* 838 /*
829 * REVISIT in case request length is bigger than EP0 839 * REVISIT in case request length is bigger than
830 * wMaxPacketSize, we will need two chained TRBs to handle 840 * DWC3_EP0_BOUNCE_SIZE we will need two chained
831 * the transfer. 841 * TRBs to handle the transfer.
832 */ 842 */
833 ret = dwc3_ep0_start_trans(dwc, event->endpoint_number, 843 ret = dwc3_ep0_start_trans(dwc, dep->number,
834 dwc->ep0_bounce_addr, dep->endpoint.maxpacket, 844 dwc->ep0_bounce_addr, transfer_size,
835 DWC3_TRBCTL_CONTROL_DATA); 845 DWC3_TRBCTL_CONTROL_DATA);
836 } else { 846 } else {
837 ret = usb_gadget_map_request(&dwc->gadget, &req->request, 847 ret = usb_gadget_map_request(&dwc->gadget, &req->request,
838 event->endpoint_number); 848 dep->number);
839 if (ret) { 849 if (ret) {
840 dev_dbg(dwc->dev, "failed to map request\n"); 850 dev_dbg(dwc->dev, "failed to map request\n");
841 return; 851 return;
842 } 852 }
843 853
844 ret = dwc3_ep0_start_trans(dwc, event->endpoint_number, 854 ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma,
845 req->request.dma, req->request.length, 855 req->request.length, DWC3_TRBCTL_CONTROL_DATA);
846 DWC3_TRBCTL_CONTROL_DATA);
847 } 856 }
848 857
849 WARN_ON(ret < 0); 858 WARN_ON(ret < 0);
850} 859}
851 860
861static void dwc3_ep0_do_control_data(struct dwc3 *dwc,
862 const struct dwc3_event_depevt *event)
863{
864 struct dwc3_ep *dep;
865 struct dwc3_request *req;
866
867 dep = dwc->eps[0];
868
869 if (list_empty(&dep->request_list)) {
870 dev_vdbg(dwc->dev, "pending request for EP0 Data phase\n");
871 dep->flags |= DWC3_EP_PENDING_REQUEST;
872
873 if (event->endpoint_number)
874 dep->flags |= DWC3_EP0_DIR_IN;
875 return;
876 }
877
878 req = next_request(&dep->request_list);
879 dep = dwc->eps[event->endpoint_number];
880
881 __dwc3_ep0_do_control_data(dwc, dep, req);
882}
883
852static int dwc3_ep0_start_control_status(struct dwc3_ep *dep) 884static int dwc3_ep0_start_control_status(struct dwc3_ep *dep)
853{ 885{
854 struct dwc3 *dwc = dep->dwc; 886 struct dwc3 *dwc = dep->dwc;
@@ -861,10 +893,8 @@ static int dwc3_ep0_start_control_status(struct dwc3_ep *dep)
861 dwc->ctrl_req_addr, 0, type); 893 dwc->ctrl_req_addr, 0, type);
862} 894}
863 895
864static void dwc3_ep0_do_control_status(struct dwc3 *dwc, u32 epnum) 896static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep)
865{ 897{
866 struct dwc3_ep *dep = dwc->eps[epnum];
867
868 if (dwc->resize_fifos) { 898 if (dwc->resize_fifos) {
869 dev_dbg(dwc->dev, "starting to resize fifos\n"); 899 dev_dbg(dwc->dev, "starting to resize fifos\n");
870 dwc3_gadget_resize_tx_fifos(dwc); 900 dwc3_gadget_resize_tx_fifos(dwc);
@@ -874,13 +904,21 @@ static void dwc3_ep0_do_control_status(struct dwc3 *dwc, u32 epnum)
874 WARN_ON(dwc3_ep0_start_control_status(dep)); 904 WARN_ON(dwc3_ep0_start_control_status(dep));
875} 905}
876 906
907static void dwc3_ep0_do_control_status(struct dwc3 *dwc,
908 const struct dwc3_event_depevt *event)
909{
910 struct dwc3_ep *dep = dwc->eps[event->endpoint_number];
911
912 __dwc3_ep0_do_control_status(dwc, dep);
913}
914
877static void dwc3_ep0_xfernotready(struct dwc3 *dwc, 915static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
878 const struct dwc3_event_depevt *event) 916 const struct dwc3_event_depevt *event)
879{ 917{
880 dwc->setup_packet_pending = true; 918 dwc->setup_packet_pending = true;
881 919
882 /* 920 /*
883 * This part is very tricky: If we has just handled 921 * This part is very tricky: If we have just handled
884 * XferNotReady(Setup) and we're now expecting a 922 * XferNotReady(Setup) and we're now expecting a
885 * XferComplete but, instead, we receive another 923 * XferComplete but, instead, we receive another
886 * XferNotReady(Setup), we should STALL and restart 924 * XferNotReady(Setup), we should STALL and restart
@@ -974,7 +1012,7 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
974 return; 1012 return;
975 } 1013 }
976 1014
977 dwc3_ep0_do_control_status(dwc, event->endpoint_number); 1015 dwc3_ep0_do_control_status(dwc, event);
978 } 1016 }
979} 1017}
980 1018
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index ec70df7aba17..58fdfad96b4d 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -100,6 +100,23 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state)
100 int retries = 10000; 100 int retries = 10000;
101 u32 reg; 101 u32 reg;
102 102
103 /*
104 * Wait until device controller is ready. Only applies to 1.94a and
105 * later RTL.
106 */
107 if (dwc->revision >= DWC3_REVISION_194A) {
108 while (--retries) {
109 reg = dwc3_readl(dwc->regs, DWC3_DSTS);
110 if (reg & DWC3_DSTS_DCNRD)
111 udelay(5);
112 else
113 break;
114 }
115
116 if (retries <= 0)
117 return -ETIMEDOUT;
118 }
119
103 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 120 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
104 reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; 121 reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK;
105 122
@@ -107,7 +124,15 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state)
107 reg |= DWC3_DCTL_ULSTCHNGREQ(state); 124 reg |= DWC3_DCTL_ULSTCHNGREQ(state);
108 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 125 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
109 126
127 /*
128 * The following code is racy when called from dwc3_gadget_wakeup,
129 * and is not needed, at least on newer versions
130 */
131 if (dwc->revision >= DWC3_REVISION_194A)
132 return 0;
133
110 /* wait for a change in DSTS */ 134 /* wait for a change in DSTS */
135 retries = 10000;
111 while (--retries) { 136 while (--retries) {
112 reg = dwc3_readl(dwc->regs, DWC3_DSTS); 137 reg = dwc3_readl(dwc->regs, DWC3_DSTS);
113 138
@@ -265,8 +290,8 @@ static const char *dwc3_gadget_ep_cmd_string(u8 cmd)
265 return "Clear Stall"; 290 return "Clear Stall";
266 case DWC3_DEPCMD_SETSTALL: 291 case DWC3_DEPCMD_SETSTALL:
267 return "Set Stall"; 292 return "Set Stall";
268 case DWC3_DEPCMD_GETSEQNUMBER: 293 case DWC3_DEPCMD_GETEPSTATE:
269 return "Get Data Sequence Number"; 294 return "Get Endpoint State";
270 case DWC3_DEPCMD_SETTRANSFRESOURCE: 295 case DWC3_DEPCMD_SETTRANSFRESOURCE:
271 return "Set Endpoint Transfer Resource"; 296 return "Set Endpoint Transfer Resource";
272 case DWC3_DEPCMD_SETEPCONFIG: 297 case DWC3_DEPCMD_SETEPCONFIG:
@@ -414,7 +439,7 @@ static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, struct dwc3_ep *dep,
414 439
415 params.param0 = DWC3_DEPCFG_EP_TYPE(usb_endpoint_type(desc)) 440 params.param0 = DWC3_DEPCFG_EP_TYPE(usb_endpoint_type(desc))
416 | DWC3_DEPCFG_MAX_PACKET_SIZE(usb_endpoint_maxp(desc)) 441 | DWC3_DEPCFG_MAX_PACKET_SIZE(usb_endpoint_maxp(desc))
417 | DWC3_DEPCFG_BURST_SIZE(dep->endpoint.maxburst); 442 | DWC3_DEPCFG_BURST_SIZE(dep->endpoint.maxburst - 1);
418 443
419 params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN 444 params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN
420 | DWC3_DEPCFG_XFER_NOT_READY_EN; 445 | DWC3_DEPCFG_XFER_NOT_READY_EN;
@@ -530,9 +555,37 @@ static void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep)
530{ 555{
531 struct dwc3_request *req; 556 struct dwc3_request *req;
532 557
533 if (!list_empty(&dep->req_queued)) 558 if (!list_empty(&dep->req_queued)) {
534 dwc3_stop_active_transfer(dwc, dep->number); 559 dwc3_stop_active_transfer(dwc, dep->number);
535 560
561 /*
562 * NOTICE: We are violating what the Databook says about the
563 * EndTransfer command. Ideally we would _always_ wait for the
564 * EndTransfer Command Completion IRQ, but that's causing too
565 * much trouble synchronizing between us and gadget driver.
566 *
567 * We have discussed this with the IP Provider and it was
568 * suggested to giveback all requests here, but give HW some
569 * extra time to synchronize with the interconnect. We're using
570 * an arbitraty 100us delay for that.
571 *
572 * Note also that a similar handling was tested by Synopsys
573 * (thanks a lot Paul) and nothing bad has come out of it.
574 * In short, what we're doing is:
575 *
576 * - Issue EndTransfer WITH CMDIOC bit set
577 * - Wait 100us
578 * - giveback all requests to gadget driver
579 */
580 udelay(100);
581
582 while (!list_empty(&dep->req_queued)) {
583 req = next_request(&dep->req_queued);
584
585 dwc3_gadget_giveback(dep, req, -ESHUTDOWN);
586 }
587 }
588
536 while (!list_empty(&dep->request_list)) { 589 while (!list_empty(&dep->request_list)) {
537 req = next_request(&dep->request_list); 590 req = next_request(&dep->request_list);
538 591
@@ -741,8 +794,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
741 case USB_ENDPOINT_XFER_ISOC: 794 case USB_ENDPOINT_XFER_ISOC:
742 trb->ctrl = DWC3_TRBCTL_ISOCHRONOUS_FIRST; 795 trb->ctrl = DWC3_TRBCTL_ISOCHRONOUS_FIRST;
743 796
744 /* IOC every DWC3_TRB_NUM / 4 so we can refill */ 797 if (!req->request.no_interrupt)
745 if (!(cur_slot % (DWC3_TRB_NUM / 4)))
746 trb->ctrl |= DWC3_TRB_CTRL_IOC; 798 trb->ctrl |= DWC3_TRB_CTRL_IOC;
747 break; 799 break;
748 800
@@ -958,14 +1010,42 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param,
958 dep->flags |= DWC3_EP_BUSY; 1010 dep->flags |= DWC3_EP_BUSY;
959 1011
960 if (start_new) { 1012 if (start_new) {
961 dep->res_trans_idx = dwc3_gadget_ep_get_transfer_index(dwc, 1013 dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc,
962 dep->number); 1014 dep->number);
963 WARN_ON_ONCE(!dep->res_trans_idx); 1015 WARN_ON_ONCE(!dep->resource_index);
964 } 1016 }
965 1017
966 return 0; 1018 return 0;
967} 1019}
968 1020
1021static void __dwc3_gadget_start_isoc(struct dwc3 *dwc,
1022 struct dwc3_ep *dep, u32 cur_uf)
1023{
1024 u32 uf;
1025
1026 if (list_empty(&dep->request_list)) {
1027 dev_vdbg(dwc->dev, "ISOC ep %s run out for requests.\n",
1028 dep->name);
1029 return;
1030 }
1031
1032 /* 4 micro frames in the future */
1033 uf = cur_uf + dep->interval * 4;
1034
1035 __dwc3_gadget_kick_transfer(dep, uf, 1);
1036}
1037
1038static void dwc3_gadget_start_isoc(struct dwc3 *dwc,
1039 struct dwc3_ep *dep, const struct dwc3_event_depevt *event)
1040{
1041 u32 cur_uf, mask;
1042
1043 mask = ~(dep->interval - 1);
1044 cur_uf = event->parameters & mask;
1045
1046 __dwc3_gadget_start_isoc(dwc, dep, cur_uf);
1047}
1048
969static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) 1049static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
970{ 1050{
971 struct dwc3 *dwc = dep->dwc; 1051 struct dwc3 *dwc = dep->dwc;
@@ -995,11 +1075,8 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
995 1075
996 list_add_tail(&req->list, &dep->request_list); 1076 list_add_tail(&req->list, &dep->request_list);
997 1077
998 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && (dep->flags & DWC3_EP_BUSY))
999 dep->flags |= DWC3_EP_PENDING_REQUEST;
1000
1001 /* 1078 /*
1002 * There are two special cases: 1079 * There are a few special cases:
1003 * 1080 *
1004 * 1. XferNotReady with empty list of requests. We need to kick the 1081 * 1. XferNotReady with empty list of requests. We need to kick the
1005 * transfer here in that situation, otherwise we will be NAKing 1082 * transfer here in that situation, otherwise we will be NAKing
@@ -1008,31 +1085,46 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
1008 * able to receive the data until the next request is queued. 1085 * able to receive the data until the next request is queued.
1009 * The following code is handling exactly that. 1086 * The following code is handling exactly that.
1010 * 1087 *
1011 * 2. XferInProgress on Isoc EP with an active transfer. We need to
1012 * kick the transfer here after queuing a request, otherwise the
1013 * core may not see the modified TRB(s).
1014 */ 1088 */
1015 if (dep->flags & DWC3_EP_PENDING_REQUEST) { 1089 if (dep->flags & DWC3_EP_PENDING_REQUEST) {
1016 int ret; 1090 int ret;
1017 int start_trans = 1;
1018 u8 trans_idx = dep->res_trans_idx;
1019 1091
1020 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1092 ret = __dwc3_gadget_kick_transfer(dep, 0, true);
1021 (dep->flags & DWC3_EP_BUSY)) { 1093 if (ret && ret != -EBUSY) {
1022 start_trans = 0; 1094 struct dwc3 *dwc = dep->dwc;
1023 WARN_ON_ONCE(!trans_idx); 1095
1024 } else { 1096 dev_dbg(dwc->dev, "%s: failed to kick transfers\n",
1025 trans_idx = 0; 1097 dep->name);
1026 } 1098 }
1099 }
1027 1100
1028 ret = __dwc3_gadget_kick_transfer(dep, trans_idx, start_trans); 1101 /*
1102 * 2. XferInProgress on Isoc EP with an active transfer. We need to
1103 * kick the transfer here after queuing a request, otherwise the
1104 * core may not see the modified TRB(s).
1105 */
1106 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
1107 (dep->flags & DWC3_EP_BUSY)) {
1108 WARN_ON_ONCE(!dep->resource_index);
1109 ret = __dwc3_gadget_kick_transfer(dep, dep->resource_index,
1110 false);
1029 if (ret && ret != -EBUSY) { 1111 if (ret && ret != -EBUSY) {
1030 struct dwc3 *dwc = dep->dwc; 1112 struct dwc3 *dwc = dep->dwc;
1031 1113
1032 dev_dbg(dwc->dev, "%s: failed to kick transfers\n", 1114 dev_dbg(dwc->dev, "%s: failed to kick transfers\n",
1033 dep->name); 1115 dep->name);
1034 } 1116 }
1035 }; 1117 }
1118
1119 /*
1120 * 3. Missed ISOC Handling. We need to start isoc transfer on the saved
1121 * uframe number.
1122 */
1123 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
1124 (dep->flags & DWC3_EP_MISSED_ISOC)) {
1125 __dwc3_gadget_start_isoc(dwc, dep, dep->current_uf);
1126 dep->flags &= ~DWC3_EP_MISSED_ISOC;
1127 }
1036 1128
1037 return 0; 1129 return 0;
1038} 1130}
@@ -1118,15 +1210,6 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value)
1118 memset(&params, 0x00, sizeof(params)); 1210 memset(&params, 0x00, sizeof(params));
1119 1211
1120 if (value) { 1212 if (value) {
1121 if (dep->number == 0 || dep->number == 1) {
1122 /*
1123 * Whenever EP0 is stalled, we will restart
1124 * the state machine, thus moving back to
1125 * Setup Phase
1126 */
1127 dwc->ep0state = EP0_SETUP_PHASE;
1128 }
1129
1130 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, 1213 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number,
1131 DWC3_DEPCMD_SETSTALL, &params); 1214 DWC3_DEPCMD_SETSTALL, &params);
1132 if (ret) 1215 if (ret)
@@ -1186,7 +1269,10 @@ static int dwc3_gadget_ep_set_wedge(struct usb_ep *ep)
1186 dep->flags |= DWC3_EP_WEDGE; 1269 dep->flags |= DWC3_EP_WEDGE;
1187 spin_unlock_irqrestore(&dwc->lock, flags); 1270 spin_unlock_irqrestore(&dwc->lock, flags);
1188 1271
1189 return dwc3_gadget_ep_set_halt(ep, 1); 1272 if (dep->number == 0 || dep->number == 1)
1273 return dwc3_gadget_ep0_set_halt(ep, 1);
1274 else
1275 return dwc3_gadget_ep_set_halt(ep, 1);
1190} 1276}
1191 1277
1192/* -------------------------------------------------------------------------- */ 1278/* -------------------------------------------------------------------------- */
@@ -1204,7 +1290,7 @@ static const struct usb_ep_ops dwc3_gadget_ep0_ops = {
1204 .free_request = dwc3_gadget_ep_free_request, 1290 .free_request = dwc3_gadget_ep_free_request,
1205 .queue = dwc3_gadget_ep0_queue, 1291 .queue = dwc3_gadget_ep0_queue,
1206 .dequeue = dwc3_gadget_ep_dequeue, 1292 .dequeue = dwc3_gadget_ep_dequeue,
1207 .set_halt = dwc3_gadget_ep_set_halt, 1293 .set_halt = dwc3_gadget_ep0_set_halt,
1208 .set_wedge = dwc3_gadget_ep_set_wedge, 1294 .set_wedge = dwc3_gadget_ep_set_wedge,
1209}; 1295};
1210 1296
@@ -1280,9 +1366,13 @@ static int dwc3_gadget_wakeup(struct usb_gadget *g)
1280 goto out; 1366 goto out;
1281 } 1367 }
1282 1368
1283 /* write zeroes to Link Change Request */ 1369 /* Recent versions do this automatically */
1284 reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; 1370 if (dwc->revision < DWC3_REVISION_194A) {
1285 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1371 /* write zeroes to Link Change Request */
1372 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
1373 reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK;
1374 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
1375 }
1286 1376
1287 /* poll until Link State changes to ON */ 1377 /* poll until Link State changes to ON */
1288 timeout = jiffies + msecs_to_jiffies(100); 1378 timeout = jiffies + msecs_to_jiffies(100);
@@ -1319,16 +1409,21 @@ static int dwc3_gadget_set_selfpowered(struct usb_gadget *g,
1319 return 0; 1409 return 0;
1320} 1410}
1321 1411
1322static void dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on) 1412static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
1323{ 1413{
1324 u32 reg; 1414 u32 reg;
1325 u32 timeout = 500; 1415 u32 timeout = 500;
1326 1416
1327 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 1417 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
1328 if (is_on) { 1418 if (is_on) {
1329 reg &= ~DWC3_DCTL_TRGTULST_MASK; 1419 if (dwc->revision <= DWC3_REVISION_187A) {
1330 reg |= (DWC3_DCTL_RUN_STOP 1420 reg &= ~DWC3_DCTL_TRGTULST_MASK;
1331 | DWC3_DCTL_TRGTULST_RX_DET); 1421 reg |= DWC3_DCTL_TRGTULST_RX_DET;
1422 }
1423
1424 if (dwc->revision >= DWC3_REVISION_194A)
1425 reg &= ~DWC3_DCTL_KEEP_CONNECT;
1426 reg |= DWC3_DCTL_RUN_STOP;
1332 } else { 1427 } else {
1333 reg &= ~DWC3_DCTL_RUN_STOP; 1428 reg &= ~DWC3_DCTL_RUN_STOP;
1334 } 1429 }
@@ -1346,7 +1441,7 @@ static void dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
1346 } 1441 }
1347 timeout--; 1442 timeout--;
1348 if (!timeout) 1443 if (!timeout)
1349 break; 1444 return -ETIMEDOUT;
1350 udelay(1); 1445 udelay(1);
1351 } while (1); 1446 } while (1);
1352 1447
@@ -1354,20 +1449,23 @@ static void dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
1354 dwc->gadget_driver 1449 dwc->gadget_driver
1355 ? dwc->gadget_driver->function : "no-function", 1450 ? dwc->gadget_driver->function : "no-function",
1356 is_on ? "connect" : "disconnect"); 1451 is_on ? "connect" : "disconnect");
1452
1453 return 0;
1357} 1454}
1358 1455
1359static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) 1456static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
1360{ 1457{
1361 struct dwc3 *dwc = gadget_to_dwc(g); 1458 struct dwc3 *dwc = gadget_to_dwc(g);
1362 unsigned long flags; 1459 unsigned long flags;
1460 int ret;
1363 1461
1364 is_on = !!is_on; 1462 is_on = !!is_on;
1365 1463
1366 spin_lock_irqsave(&dwc->lock, flags); 1464 spin_lock_irqsave(&dwc->lock, flags);
1367 dwc3_gadget_run_stop(dwc, is_on); 1465 ret = dwc3_gadget_run_stop(dwc, is_on);
1368 spin_unlock_irqrestore(&dwc->lock, flags); 1466 spin_unlock_irqrestore(&dwc->lock, flags);
1369 1467
1370 return 0; 1468 return ret;
1371} 1469}
1372 1470
1373static int dwc3_gadget_start(struct usb_gadget *g, 1471static int dwc3_gadget_start(struct usb_gadget *g,
@@ -1468,6 +1566,7 @@ static int dwc3_gadget_stop(struct usb_gadget *g,
1468 1566
1469 return 0; 1567 return 0;
1470} 1568}
1569
1471static const struct usb_gadget_ops dwc3_gadget_ops = { 1570static const struct usb_gadget_ops dwc3_gadget_ops = {
1472 .get_frame = dwc3_gadget_get_frame, 1571 .get_frame = dwc3_gadget_get_frame,
1473 .wakeup = dwc3_gadget_wakeup, 1572 .wakeup = dwc3_gadget_wakeup,
@@ -1558,6 +1657,7 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
1558 struct dwc3_trb *trb; 1657 struct dwc3_trb *trb;
1559 unsigned int count; 1658 unsigned int count;
1560 unsigned int s_pkt = 0; 1659 unsigned int s_pkt = 0;
1660 unsigned int trb_status;
1561 1661
1562 do { 1662 do {
1563 req = next_request(&dep->req_queued); 1663 req = next_request(&dep->req_queued);
@@ -1583,9 +1683,18 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
1583 1683
1584 if (dep->direction) { 1684 if (dep->direction) {
1585 if (count) { 1685 if (count) {
1586 dev_err(dwc->dev, "incomplete IN transfer %s\n", 1686 trb_status = DWC3_TRB_SIZE_TRBSTS(trb->size);
1587 dep->name); 1687 if (trb_status == DWC3_TRBSTS_MISSED_ISOC) {
1588 status = -ECONNRESET; 1688 dev_dbg(dwc->dev, "incomplete IN transfer %s\n",
1689 dep->name);
1690 dep->current_uf = event->parameters &
1691 ~(dep->interval - 1);
1692 dep->flags |= DWC3_EP_MISSED_ISOC;
1693 } else {
1694 dev_err(dwc->dev, "incomplete IN transfer %s\n",
1695 dep->name);
1696 status = -ECONNRESET;
1697 }
1589 } 1698 }
1590 } else { 1699 } else {
1591 if (count && (event->status & DEPEVT_STATUS_SHORT)) 1700 if (count && (event->status & DEPEVT_STATUS_SHORT))
@@ -1604,7 +1713,8 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
1604 if (s_pkt) 1713 if (s_pkt)
1605 break; 1714 break;
1606 if ((event->status & DEPEVT_STATUS_LST) && 1715 if ((event->status & DEPEVT_STATUS_LST) &&
1607 (trb->ctrl & DWC3_TRB_CTRL_LST)) 1716 (trb->ctrl & (DWC3_TRB_CTRL_LST |
1717 DWC3_TRB_CTRL_HWO)))
1608 break; 1718 break;
1609 if ((event->status & DEPEVT_STATUS_IOC) && 1719 if ((event->status & DEPEVT_STATUS_IOC) &&
1610 (trb->ctrl & DWC3_TRB_CTRL_IOC)) 1720 (trb->ctrl & DWC3_TRB_CTRL_IOC))
@@ -1657,65 +1767,6 @@ static void dwc3_endpoint_transfer_complete(struct dwc3 *dwc,
1657 } 1767 }
1658} 1768}
1659 1769
1660static void dwc3_gadget_start_isoc(struct dwc3 *dwc,
1661 struct dwc3_ep *dep, const struct dwc3_event_depevt *event)
1662{
1663 u32 uf, mask;
1664
1665 if (list_empty(&dep->request_list)) {
1666 dev_vdbg(dwc->dev, "ISOC ep %s run out for requests.\n",
1667 dep->name);
1668 return;
1669 }
1670
1671 mask = ~(dep->interval - 1);
1672 uf = event->parameters & mask;
1673 /* 4 micro frames in the future */
1674 uf += dep->interval * 4;
1675
1676 __dwc3_gadget_kick_transfer(dep, uf, 1);
1677}
1678
1679static void dwc3_process_ep_cmd_complete(struct dwc3_ep *dep,
1680 const struct dwc3_event_depevt *event)
1681{
1682 struct dwc3 *dwc = dep->dwc;
1683 struct dwc3_event_depevt mod_ev = *event;
1684
1685 /*
1686 * We were asked to remove one request. It is possible that this
1687 * request and a few others were started together and have the same
1688 * transfer index. Since we stopped the complete endpoint we don't
1689 * know how many requests were already completed (and not yet)
1690 * reported and how could be done (later). We purge them all until
1691 * the end of the list.
1692 */
1693 mod_ev.status = DEPEVT_STATUS_LST;
1694 dwc3_cleanup_done_reqs(dwc, dep, &mod_ev, -ESHUTDOWN);
1695 dep->flags &= ~DWC3_EP_BUSY;
1696 /* pending requests are ignored and are queued on XferNotReady */
1697}
1698
1699static void dwc3_ep_cmd_compl(struct dwc3_ep *dep,
1700 const struct dwc3_event_depevt *event)
1701{
1702 u32 param = event->parameters;
1703 u32 cmd_type = (param >> 8) & ((1 << 5) - 1);
1704
1705 switch (cmd_type) {
1706 case DWC3_DEPCMD_ENDTRANSFER:
1707 dwc3_process_ep_cmd_complete(dep, event);
1708 break;
1709 case DWC3_DEPCMD_STARTTRANSFER:
1710 dep->res_trans_idx = param & 0x7f;
1711 break;
1712 default:
1713 printk(KERN_ERR "%s() unknown /unexpected type: %d\n",
1714 __func__, cmd_type);
1715 break;
1716 };
1717}
1718
1719static void dwc3_endpoint_interrupt(struct dwc3 *dwc, 1770static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
1720 const struct dwc3_event_depevt *event) 1771 const struct dwc3_event_depevt *event)
1721{ 1772{
@@ -1724,6 +1775,9 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
1724 1775
1725 dep = dwc->eps[epnum]; 1776 dep = dwc->eps[epnum];
1726 1777
1778 if (!(dep->flags & DWC3_EP_ENABLED))
1779 return;
1780
1727 dev_vdbg(dwc->dev, "%s: %s\n", dep->name, 1781 dev_vdbg(dwc->dev, "%s: %s\n", dep->name,
1728 dwc3_ep_event_string(event->endpoint_event)); 1782 dwc3_ep_event_string(event->endpoint_event));
1729 1783
@@ -1734,7 +1788,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
1734 1788
1735 switch (event->endpoint_event) { 1789 switch (event->endpoint_event) {
1736 case DWC3_DEPEVT_XFERCOMPLETE: 1790 case DWC3_DEPEVT_XFERCOMPLETE:
1737 dep->res_trans_idx = 0; 1791 dep->resource_index = 0;
1738 1792
1739 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { 1793 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
1740 dev_dbg(dwc->dev, "%s is an Isochronous endpoint\n", 1794 dev_dbg(dwc->dev, "%s is an Isochronous endpoint\n",
@@ -1797,7 +1851,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
1797 dev_dbg(dwc->dev, "%s FIFO Overrun\n", dep->name); 1851 dev_dbg(dwc->dev, "%s FIFO Overrun\n", dep->name);
1798 break; 1852 break;
1799 case DWC3_DEPEVT_EPCMDCMPLT: 1853 case DWC3_DEPEVT_EPCMDCMPLT:
1800 dwc3_ep_cmd_compl(dep, event); 1854 dev_vdbg(dwc->dev, "Endpoint Command Complete\n");
1801 break; 1855 break;
1802 } 1856 }
1803} 1857}
@@ -1820,16 +1874,16 @@ static void dwc3_stop_active_transfer(struct dwc3 *dwc, u32 epnum)
1820 1874
1821 dep = dwc->eps[epnum]; 1875 dep = dwc->eps[epnum];
1822 1876
1823 WARN_ON(!dep->res_trans_idx); 1877 if (!dep->resource_index)
1824 if (dep->res_trans_idx) { 1878 return;
1825 cmd = DWC3_DEPCMD_ENDTRANSFER; 1879
1826 cmd |= DWC3_DEPCMD_HIPRI_FORCERM | DWC3_DEPCMD_CMDIOC; 1880 cmd = DWC3_DEPCMD_ENDTRANSFER;
1827 cmd |= DWC3_DEPCMD_PARAM(dep->res_trans_idx); 1881 cmd |= DWC3_DEPCMD_HIPRI_FORCERM | DWC3_DEPCMD_CMDIOC;
1828 memset(&params, 0, sizeof(params)); 1882 cmd |= DWC3_DEPCMD_PARAM(dep->resource_index);
1829 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 1883 memset(&params, 0, sizeof(params));
1830 WARN_ON_ONCE(ret); 1884 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params);
1831 dep->res_trans_idx = 0; 1885 WARN_ON_ONCE(ret);
1832 } 1886 dep->resource_index = 0;
1833} 1887}
1834 1888
1835static void dwc3_stop_active_transfers(struct dwc3 *dwc) 1889static void dwc3_stop_active_transfers(struct dwc3 *dwc)
@@ -1872,11 +1926,9 @@ static void dwc3_clear_stall_all_ep(struct dwc3 *dwc)
1872 1926
1873static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) 1927static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
1874{ 1928{
1929 int reg;
1930
1875 dev_vdbg(dwc->dev, "%s\n", __func__); 1931 dev_vdbg(dwc->dev, "%s\n", __func__);
1876#if 0
1877 XXX
1878 U1/U2 is powersave optimization. Skip it for now. Anyway we need to
1879 enable it before we can disable it.
1880 1932
1881 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 1933 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
1882 reg &= ~DWC3_DCTL_INITU1ENA; 1934 reg &= ~DWC3_DCTL_INITU1ENA;
@@ -1884,9 +1936,7 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
1884 1936
1885 reg &= ~DWC3_DCTL_INITU2ENA; 1937 reg &= ~DWC3_DCTL_INITU2ENA;
1886 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1938 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
1887#endif
1888 1939
1889 dwc3_stop_active_transfers(dwc);
1890 dwc3_disconnect_gadget(dwc); 1940 dwc3_disconnect_gadget(dwc);
1891 dwc->start_config_issued = false; 1941 dwc->start_config_issued = false;
1892 1942
@@ -1894,30 +1944,30 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
1894 dwc->setup_packet_pending = false; 1944 dwc->setup_packet_pending = false;
1895} 1945}
1896 1946
1897static void dwc3_gadget_usb3_phy_power(struct dwc3 *dwc, int on) 1947static void dwc3_gadget_usb3_phy_suspend(struct dwc3 *dwc, int suspend)
1898{ 1948{
1899 u32 reg; 1949 u32 reg;
1900 1950
1901 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); 1951 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
1902 1952
1903 if (on) 1953 if (suspend)
1904 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
1905 else
1906 reg |= DWC3_GUSB3PIPECTL_SUSPHY; 1954 reg |= DWC3_GUSB3PIPECTL_SUSPHY;
1955 else
1956 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
1907 1957
1908 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); 1958 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
1909} 1959}
1910 1960
1911static void dwc3_gadget_usb2_phy_power(struct dwc3 *dwc, int on) 1961static void dwc3_gadget_usb2_phy_suspend(struct dwc3 *dwc, int suspend)
1912{ 1962{
1913 u32 reg; 1963 u32 reg;
1914 1964
1915 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); 1965 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
1916 1966
1917 if (on) 1967 if (suspend)
1918 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
1919 else
1920 reg |= DWC3_GUSB2PHYCFG_SUSPHY; 1968 reg |= DWC3_GUSB2PHYCFG_SUSPHY;
1969 else
1970 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
1921 1971
1922 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 1972 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
1923} 1973}
@@ -1962,16 +2012,18 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
1962 /* after reset -> Default State */ 2012 /* after reset -> Default State */
1963 dwc->dev_state = DWC3_DEFAULT_STATE; 2013 dwc->dev_state = DWC3_DEFAULT_STATE;
1964 2014
1965 /* Enable PHYs */ 2015 /* Recent versions support automatic phy suspend and don't need this */
1966 dwc3_gadget_usb2_phy_power(dwc, true); 2016 if (dwc->revision < DWC3_REVISION_194A) {
1967 dwc3_gadget_usb3_phy_power(dwc, true); 2017 /* Resume PHYs */
2018 dwc3_gadget_usb2_phy_suspend(dwc, false);
2019 dwc3_gadget_usb3_phy_suspend(dwc, false);
2020 }
1968 2021
1969 if (dwc->gadget.speed != USB_SPEED_UNKNOWN) 2022 if (dwc->gadget.speed != USB_SPEED_UNKNOWN)
1970 dwc3_disconnect_gadget(dwc); 2023 dwc3_disconnect_gadget(dwc);
1971 2024
1972 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 2025 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
1973 reg &= ~DWC3_DCTL_TSTCTRL_MASK; 2026 reg &= ~DWC3_DCTL_TSTCTRL_MASK;
1974 reg &= ~(DWC3_DCTL_INITU1ENA | DWC3_DCTL_INITU2ENA);
1975 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 2027 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
1976 dwc->test_mode = false; 2028 dwc->test_mode = false;
1977 2029
@@ -2010,16 +2062,16 @@ static void dwc3_update_ram_clk_sel(struct dwc3 *dwc, u32 speed)
2010 dwc3_writel(dwc->regs, DWC3_GCTL, reg); 2062 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
2011} 2063}
2012 2064
2013static void dwc3_gadget_disable_phy(struct dwc3 *dwc, u8 speed) 2065static void dwc3_gadget_phy_suspend(struct dwc3 *dwc, u8 speed)
2014{ 2066{
2015 switch (speed) { 2067 switch (speed) {
2016 case USB_SPEED_SUPER: 2068 case USB_SPEED_SUPER:
2017 dwc3_gadget_usb2_phy_power(dwc, false); 2069 dwc3_gadget_usb2_phy_suspend(dwc, true);
2018 break; 2070 break;
2019 case USB_SPEED_HIGH: 2071 case USB_SPEED_HIGH:
2020 case USB_SPEED_FULL: 2072 case USB_SPEED_FULL:
2021 case USB_SPEED_LOW: 2073 case USB_SPEED_LOW:
2022 dwc3_gadget_usb3_phy_power(dwc, false); 2074 dwc3_gadget_usb3_phy_suspend(dwc, true);
2023 break; 2075 break;
2024 } 2076 }
2025} 2077}
@@ -2082,8 +2134,11 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
2082 break; 2134 break;
2083 } 2135 }
2084 2136
2085 /* Disable unneded PHY */ 2137 /* Recent versions support automatic phy suspend and don't need this */
2086 dwc3_gadget_disable_phy(dwc, dwc->gadget.speed); 2138 if (dwc->revision < DWC3_REVISION_194A) {
2139 /* Suspend unneeded PHY */
2140 dwc3_gadget_phy_suspend(dwc, dwc->gadget.speed);
2141 }
2087 2142
2088 dep = dwc->eps[0]; 2143 dep = dwc->eps[0];
2089 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL); 2144 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL);
@@ -2373,10 +2428,6 @@ int __devinit dwc3_gadget_init(struct dwc3 *dwc)
2373 reg |= DWC3_DCFG_LPM_CAP; 2428 reg |= DWC3_DCFG_LPM_CAP;
2374 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 2429 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
2375 2430
2376 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
2377 reg |= DWC3_DCTL_ACCEPTU1ENA | DWC3_DCTL_ACCEPTU2ENA;
2378 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
2379
2380 /* Enable all but Start and End of Frame IRQs */ 2431 /* Enable all but Start and End of Frame IRQs */
2381 reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN | 2432 reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN |
2382 DWC3_DEVTEN_EVNTOVERFLOWEN | 2433 DWC3_DEVTEN_EVNTOVERFLOWEN |
@@ -2389,6 +2440,24 @@ int __devinit dwc3_gadget_init(struct dwc3 *dwc)
2389 DWC3_DEVTEN_DISCONNEVTEN); 2440 DWC3_DEVTEN_DISCONNEVTEN);
2390 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); 2441 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg);
2391 2442
2443 /* Enable USB2 LPM and automatic phy suspend only on recent versions */
2444 if (dwc->revision >= DWC3_REVISION_194A) {
2445 reg = dwc3_readl(dwc->regs, DWC3_DCFG);
2446 reg |= DWC3_DCFG_LPM_CAP;
2447 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
2448
2449 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
2450 reg &= ~(DWC3_DCTL_HIRD_THRES_MASK | DWC3_DCTL_L1_HIBER_EN);
2451
2452 /* TODO: This should be configurable */
2453 reg |= DWC3_DCTL_HIRD_THRES(28);
2454
2455 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
2456
2457 dwc3_gadget_usb2_phy_suspend(dwc, false);
2458 dwc3_gadget_usb3_phy_suspend(dwc, false);
2459 }
2460
2392 ret = device_register(&dwc->gadget.dev); 2461 ret = device_register(&dwc->gadget.dev);
2393 if (ret) { 2462 if (ret) {
2394 dev_err(dwc->dev, "failed to register gadget device\n"); 2463 dev_err(dwc->dev, "failed to register gadget device\n");
diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
index 95ef6a2f7764..99e6d7248820 100644
--- a/drivers/usb/dwc3/gadget.h
+++ b/drivers/usb/dwc3/gadget.h
@@ -66,7 +66,12 @@ struct dwc3;
66#define DWC3_DEPCFG_FIFO_NUMBER(n) ((n) << 17) 66#define DWC3_DEPCFG_FIFO_NUMBER(n) ((n) << 17)
67#define DWC3_DEPCFG_BURST_SIZE(n) ((n) << 22) 67#define DWC3_DEPCFG_BURST_SIZE(n) ((n) << 22)
68#define DWC3_DEPCFG_DATA_SEQ_NUM(n) ((n) << 26) 68#define DWC3_DEPCFG_DATA_SEQ_NUM(n) ((n) << 26)
69/* This applies for core versions earlier than 1.94a */
69#define DWC3_DEPCFG_IGN_SEQ_NUM (1 << 31) 70#define DWC3_DEPCFG_IGN_SEQ_NUM (1 << 31)
71/* These apply for core versions 1.94a and later */
72#define DWC3_DEPCFG_ACTION_INIT (0 << 30)
73#define DWC3_DEPCFG_ACTION_RESTORE (1 << 30)
74#define DWC3_DEPCFG_ACTION_MODIFY (2 << 30)
70 75
71/* DEPXFERCFG parameter 0 */ 76/* DEPXFERCFG parameter 0 */
72#define DWC3_DEPXFERCFG_NUM_XFER_RES(n) ((n) & 0xffff) 77#define DWC3_DEPXFERCFG_NUM_XFER_RES(n) ((n) & 0xffff)
@@ -106,6 +111,7 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
106void dwc3_ep0_interrupt(struct dwc3 *dwc, 111void dwc3_ep0_interrupt(struct dwc3 *dwc,
107 const struct dwc3_event_depevt *event); 112 const struct dwc3_event_depevt *event);
108void dwc3_ep0_out_start(struct dwc3 *dwc); 113void dwc3_ep0_out_start(struct dwc3 *dwc);
114int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value);
109int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, 115int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
110 gfp_t gfp_flags); 116 gfp_t gfp_flags);
111int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value); 117int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value);
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
index 1fc8f1249806..ee0ebacf8227 100644
--- a/drivers/usb/early/ehci-dbgp.c
+++ b/drivers/usb/early/ehci-dbgp.c
@@ -334,7 +334,7 @@ static int dbgp_control_msg(unsigned devnum, int requesttype,
334 int ret; 334 int ret;
335 335
336 read = (requesttype & USB_DIR_IN) != 0; 336 read = (requesttype & USB_DIR_IN) != 0;
337 if (size > (read ? DBGP_MAX_PACKET:0)) 337 if (size > (read ? DBGP_MAX_PACKET : 0))
338 return -1; 338 return -1;
339 339
340 /* Compute the control message */ 340 /* Compute the control message */
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index bddc8fd9a7be..5e242c34088d 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -321,6 +321,15 @@ config USB_MV_UDC
321 USB2.0 OTG controller, which can be configured as high speed or 321 USB2.0 OTG controller, which can be configured as high speed or
322 full speed USB peripheral. 322 full speed USB peripheral.
323 323
324config USB_MV_U3D
325 tristate "MARVELL PXA2128 USB 3.0 controller"
326 depends on CPU_MMP3
327 select USB_GADGET_DUALSPEED
328 select USB_GADGET_SUPERSPEED
329 help
330 MARVELL PXA2128 Processor series include a super speed USB3.0 device
331 controller, which support super speed USB peripheral.
332
324# 333#
325# Controllers available in both integrated and discrete versions 334# Controllers available in both integrated and discrete versions
326# 335#
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 1811513f1c27..3fd8cd09d2c1 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_USB_EG20T) += pch_udc.o
29obj-$(CONFIG_USB_MV_UDC) += mv_udc.o 29obj-$(CONFIG_USB_MV_UDC) += mv_udc.o
30mv_udc-y := mv_udc_core.o 30mv_udc-y := mv_udc_core.o
31obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o 31obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
32obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o
32 33
33# 34#
34# USB gadget drivers 35# USB gadget drivers
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index fdb7aec3bd0c..75b8a691fd00 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -235,6 +235,7 @@ static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
235static struct usb_composite_driver acm_ms_driver = { 235static struct usb_composite_driver acm_ms_driver = {
236 .name = "g_acm_ms", 236 .name = "g_acm_ms",
237 .dev = &device_desc, 237 .dev = &device_desc,
238 .max_speed = USB_SPEED_SUPER,
238 .strings = dev_strings, 239 .strings = dev_strings,
239 .unbind = __exit_p(acm_ms_unbind), 240 .unbind = __exit_p(acm_ms_unbind),
240}; 241};
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 1a4430f315c3..c9e66dfb02e6 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1634,6 +1634,7 @@ static int at91_start(struct usb_gadget *gadget,
1634 udc = container_of(gadget, struct at91_udc, gadget); 1634 udc = container_of(gadget, struct at91_udc, gadget);
1635 udc->driver = driver; 1635 udc->driver = driver;
1636 udc->gadget.dev.driver = &driver->driver; 1636 udc->gadget.dev.driver = &driver->driver;
1637 udc->gadget.dev.of_node = udc->pdev->dev.of_node;
1637 dev_set_drvdata(&udc->gadget.dev, &driver->driver); 1638 dev_set_drvdata(&udc->gadget.dev, &driver->driver);
1638 udc->enabled = 1; 1639 udc->enabled = 1;
1639 udc->selfpowered = 1; 1640 udc->selfpowered = 1;
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 390749bbb0c3..3f72110da1b0 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -117,6 +117,7 @@ int config_ep_by_speed(struct usb_gadget *g,
117 struct usb_function *f, 117 struct usb_function *f,
118 struct usb_ep *_ep) 118 struct usb_ep *_ep)
119{ 119{
120 struct usb_composite_dev *cdev = get_gadget_data(g);
120 struct usb_endpoint_descriptor *chosen_desc = NULL; 121 struct usb_endpoint_descriptor *chosen_desc = NULL;
121 struct usb_descriptor_header **speed_desc = NULL; 122 struct usb_descriptor_header **speed_desc = NULL;
122 123
@@ -180,10 +181,12 @@ ep_found:
180 _ep->mult = comp_desc->bmAttributes & 0x3; 181 _ep->mult = comp_desc->bmAttributes & 0x3;
181 case USB_ENDPOINT_XFER_BULK: 182 case USB_ENDPOINT_XFER_BULK:
182 case USB_ENDPOINT_XFER_INT: 183 case USB_ENDPOINT_XFER_INT:
183 _ep->maxburst = comp_desc->bMaxBurst; 184 _ep->maxburst = comp_desc->bMaxBurst + 1;
184 break; 185 break;
185 default: 186 default:
186 /* Do nothing for control endpoints */ 187 if (comp_desc->bMaxBurst != 0)
188 ERROR(cdev, "ep0 bMaxBurst must be 0\n");
189 _ep->maxburst = 1;
187 break; 190 break;
188 } 191 }
189 } 192 }
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index dcd1c7fbb016..8adc79d1b402 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -21,6 +21,7 @@
21#include <linux/blkdev.h> 21#include <linux/blkdev.h>
22#include <linux/pagemap.h> 22#include <linux/pagemap.h>
23#include <linux/export.h> 23#include <linux/export.h>
24#include <linux/hid.h>
24#include <asm/unaligned.h> 25#include <asm/unaligned.h>
25 26
26#include <linux/usb/composite.h> 27#include <linux/usb/composite.h>
@@ -1671,6 +1672,12 @@ static int __must_check ffs_do_desc(char *data, unsigned len,
1671 } 1672 }
1672 break; 1673 break;
1673 1674
1675 case HID_DT_HID:
1676 pr_vdebug("hid descriptor\n");
1677 if (length != sizeof(struct hid_descriptor))
1678 goto inv_length;
1679 break;
1680
1674 case USB_DT_OTG: 1681 case USB_DT_OTG:
1675 if (length != sizeof(struct usb_otg_descriptor)) 1682 if (length != sizeof(struct usb_otg_descriptor))
1676 goto inv_length; 1683 goto inv_length;
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c
index 3b3932c55361..16a8b1c15c62 100644
--- a/drivers/usb/gadget/f_hid.c
+++ b/drivers/usb/gadget/f_hid.c
@@ -26,6 +26,12 @@ static struct class *hidg_class;
26/*-------------------------------------------------------------------------*/ 26/*-------------------------------------------------------------------------*/
27/* HID gadget struct */ 27/* HID gadget struct */
28 28
29struct f_hidg_req_list {
30 struct usb_request *req;
31 unsigned int pos;
32 struct list_head list;
33};
34
29struct f_hidg { 35struct f_hidg {
30 /* configuration */ 36 /* configuration */
31 unsigned char bInterfaceSubClass; 37 unsigned char bInterfaceSubClass;
@@ -35,10 +41,10 @@ struct f_hidg {
35 unsigned short report_length; 41 unsigned short report_length;
36 42
37 /* recv report */ 43 /* recv report */
38 char *set_report_buff; 44 struct list_head completed_out_req;
39 unsigned short set_report_length;
40 spinlock_t spinlock; 45 spinlock_t spinlock;
41 wait_queue_head_t read_queue; 46 wait_queue_head_t read_queue;
47 unsigned int qlen;
42 48
43 /* send report */ 49 /* send report */
44 struct mutex lock; 50 struct mutex lock;
@@ -49,7 +55,9 @@ struct f_hidg {
49 int minor; 55 int minor;
50 struct cdev cdev; 56 struct cdev cdev;
51 struct usb_function func; 57 struct usb_function func;
58
52 struct usb_ep *in_ep; 59 struct usb_ep *in_ep;
60 struct usb_ep *out_ep;
53}; 61};
54 62
55static inline struct f_hidg *func_to_hidg(struct usb_function *f) 63static inline struct f_hidg *func_to_hidg(struct usb_function *f)
@@ -65,7 +73,7 @@ static struct usb_interface_descriptor hidg_interface_desc = {
65 .bDescriptorType = USB_DT_INTERFACE, 73 .bDescriptorType = USB_DT_INTERFACE,
66 /* .bInterfaceNumber = DYNAMIC */ 74 /* .bInterfaceNumber = DYNAMIC */
67 .bAlternateSetting = 0, 75 .bAlternateSetting = 0,
68 .bNumEndpoints = 1, 76 .bNumEndpoints = 2,
69 .bInterfaceClass = USB_CLASS_HID, 77 .bInterfaceClass = USB_CLASS_HID,
70 /* .bInterfaceSubClass = DYNAMIC */ 78 /* .bInterfaceSubClass = DYNAMIC */
71 /* .bInterfaceProtocol = DYNAMIC */ 79 /* .bInterfaceProtocol = DYNAMIC */
@@ -96,10 +104,23 @@ static struct usb_endpoint_descriptor hidg_hs_in_ep_desc = {
96 */ 104 */
97}; 105};
98 106
107static struct usb_endpoint_descriptor hidg_hs_out_ep_desc = {
108 .bLength = USB_DT_ENDPOINT_SIZE,
109 .bDescriptorType = USB_DT_ENDPOINT,
110 .bEndpointAddress = USB_DIR_OUT,
111 .bmAttributes = USB_ENDPOINT_XFER_INT,
112 /*.wMaxPacketSize = DYNAMIC */
113 .bInterval = 4, /* FIXME: Add this field in the
114 * HID gadget configuration?
115 * (struct hidg_func_descriptor)
116 */
117};
118
99static struct usb_descriptor_header *hidg_hs_descriptors[] = { 119static struct usb_descriptor_header *hidg_hs_descriptors[] = {
100 (struct usb_descriptor_header *)&hidg_interface_desc, 120 (struct usb_descriptor_header *)&hidg_interface_desc,
101 (struct usb_descriptor_header *)&hidg_desc, 121 (struct usb_descriptor_header *)&hidg_desc,
102 (struct usb_descriptor_header *)&hidg_hs_in_ep_desc, 122 (struct usb_descriptor_header *)&hidg_hs_in_ep_desc,
123 (struct usb_descriptor_header *)&hidg_hs_out_ep_desc,
103 NULL, 124 NULL,
104}; 125};
105 126
@@ -117,10 +138,23 @@ static struct usb_endpoint_descriptor hidg_fs_in_ep_desc = {
117 */ 138 */
118}; 139};
119 140
141static struct usb_endpoint_descriptor hidg_fs_out_ep_desc = {
142 .bLength = USB_DT_ENDPOINT_SIZE,
143 .bDescriptorType = USB_DT_ENDPOINT,
144 .bEndpointAddress = USB_DIR_OUT,
145 .bmAttributes = USB_ENDPOINT_XFER_INT,
146 /*.wMaxPacketSize = DYNAMIC */
147 .bInterval = 10, /* FIXME: Add this field in the
148 * HID gadget configuration?
149 * (struct hidg_func_descriptor)
150 */
151};
152
120static struct usb_descriptor_header *hidg_fs_descriptors[] = { 153static struct usb_descriptor_header *hidg_fs_descriptors[] = {
121 (struct usb_descriptor_header *)&hidg_interface_desc, 154 (struct usb_descriptor_header *)&hidg_interface_desc,
122 (struct usb_descriptor_header *)&hidg_desc, 155 (struct usb_descriptor_header *)&hidg_desc,
123 (struct usb_descriptor_header *)&hidg_fs_in_ep_desc, 156 (struct usb_descriptor_header *)&hidg_fs_in_ep_desc,
157 (struct usb_descriptor_header *)&hidg_fs_out_ep_desc,
124 NULL, 158 NULL,
125}; 159};
126 160
@@ -130,9 +164,11 @@ static struct usb_descriptor_header *hidg_fs_descriptors[] = {
130static ssize_t f_hidg_read(struct file *file, char __user *buffer, 164static ssize_t f_hidg_read(struct file *file, char __user *buffer,
131 size_t count, loff_t *ptr) 165 size_t count, loff_t *ptr)
132{ 166{
133 struct f_hidg *hidg = file->private_data; 167 struct f_hidg *hidg = file->private_data;
134 char *tmp_buff = NULL; 168 struct f_hidg_req_list *list;
135 unsigned long flags; 169 struct usb_request *req;
170 unsigned long flags;
171 int ret;
136 172
137 if (!count) 173 if (!count)
138 return 0; 174 return 0;
@@ -142,8 +178,9 @@ static ssize_t f_hidg_read(struct file *file, char __user *buffer,
142 178
143 spin_lock_irqsave(&hidg->spinlock, flags); 179 spin_lock_irqsave(&hidg->spinlock, flags);
144 180
145#define READ_COND (hidg->set_report_buff != NULL) 181#define READ_COND (!list_empty(&hidg->completed_out_req))
146 182
183 /* wait for at least one buffer to complete */
147 while (!READ_COND) { 184 while (!READ_COND) {
148 spin_unlock_irqrestore(&hidg->spinlock, flags); 185 spin_unlock_irqrestore(&hidg->spinlock, flags);
149 if (file->f_flags & O_NONBLOCK) 186 if (file->f_flags & O_NONBLOCK)
@@ -155,19 +192,34 @@ static ssize_t f_hidg_read(struct file *file, char __user *buffer,
155 spin_lock_irqsave(&hidg->spinlock, flags); 192 spin_lock_irqsave(&hidg->spinlock, flags);
156 } 193 }
157 194
158 195 /* pick the first one */
159 count = min_t(unsigned, count, hidg->set_report_length); 196 list = list_first_entry(&hidg->completed_out_req,
160 tmp_buff = hidg->set_report_buff; 197 struct f_hidg_req_list, list);
161 hidg->set_report_buff = NULL; 198 req = list->req;
162 199 count = min_t(unsigned int, count, req->actual - list->pos);
163 spin_unlock_irqrestore(&hidg->spinlock, flags); 200 spin_unlock_irqrestore(&hidg->spinlock, flags);
164 201
165 if (tmp_buff != NULL) { 202 /* copy to user outside spinlock */
166 /* copy to user outside spinlock */ 203 count -= copy_to_user(buffer, req->buf + list->pos, count);
167 count -= copy_to_user(buffer, tmp_buff, count); 204 list->pos += count;
168 kfree(tmp_buff); 205
169 } else 206 /*
170 count = -ENOMEM; 207 * if this request is completely handled and transfered to
208 * userspace, remove its entry from the list and requeue it
209 * again. Otherwise, we will revisit it again upon the next
210 * call, taking into account its current read position.
211 */
212 if (list->pos == req->actual) {
213 spin_lock_irqsave(&hidg->spinlock, flags);
214 list_del(&list->list);
215 kfree(list);
216 spin_unlock_irqrestore(&hidg->spinlock, flags);
217
218 req->length = hidg->report_length;
219 ret = usb_ep_queue(hidg->out_ep, req, GFP_KERNEL);
220 if (ret < 0)
221 return ret;
222 }
171 223
172 return count; 224 return count;
173} 225}
@@ -282,28 +334,37 @@ static int f_hidg_open(struct inode *inode, struct file *fd)
282/*-------------------------------------------------------------------------*/ 334/*-------------------------------------------------------------------------*/
283/* usb_function */ 335/* usb_function */
284 336
285static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req) 337static struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep, unsigned length)
286{ 338{
287 struct f_hidg *hidg = (struct f_hidg *)req->context; 339 struct usb_request *req;
288 340
289 if (req->status != 0 || req->buf == NULL || req->actual == 0) { 341 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
290 ERROR(hidg->func.config->cdev, "%s FAILED\n", __func__); 342 if (req) {
291 return; 343 req->length = length;
344 req->buf = kmalloc(length, GFP_ATOMIC);
345 if (!req->buf) {
346 usb_ep_free_request(ep, req);
347 req = NULL;
348 }
292 } 349 }
350 return req;
351}
293 352
294 spin_lock(&hidg->spinlock); 353static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req)
295 354{
296 hidg->set_report_buff = krealloc(hidg->set_report_buff, 355 struct f_hidg *hidg = (struct f_hidg *) req->context;
297 req->actual, GFP_ATOMIC); 356 struct f_hidg_req_list *req_list;
357 unsigned long flags;
298 358
299 if (hidg->set_report_buff == NULL) { 359 req_list = kzalloc(sizeof(*req_list), GFP_ATOMIC);
300 spin_unlock(&hidg->spinlock); 360 if (!req_list)
301 return; 361 return;
302 }
303 hidg->set_report_length = req->actual;
304 memcpy(hidg->set_report_buff, req->buf, req->actual);
305 362
306 spin_unlock(&hidg->spinlock); 363 req_list->req = req;
364
365 spin_lock_irqsave(&hidg->spinlock, flags);
366 list_add_tail(&req_list->list, &hidg->completed_out_req);
367 spin_unlock_irqrestore(&hidg->spinlock, flags);
307 368
308 wake_up(&hidg->read_queue); 369 wake_up(&hidg->read_queue);
309} 370}
@@ -344,9 +405,7 @@ static int hidg_setup(struct usb_function *f,
344 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 405 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
345 | HID_REQ_SET_REPORT): 406 | HID_REQ_SET_REPORT):
346 VDBG(cdev, "set_report | wLenght=%d\n", ctrl->wLength); 407 VDBG(cdev, "set_report | wLenght=%d\n", ctrl->wLength);
347 req->context = hidg; 408 goto stall;
348 req->complete = hidg_set_report_complete;
349 goto respond;
350 break; 409 break;
351 410
352 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 411 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
@@ -403,16 +462,25 @@ respond:
403static void hidg_disable(struct usb_function *f) 462static void hidg_disable(struct usb_function *f)
404{ 463{
405 struct f_hidg *hidg = func_to_hidg(f); 464 struct f_hidg *hidg = func_to_hidg(f);
465 struct f_hidg_req_list *list, *next;
406 466
407 usb_ep_disable(hidg->in_ep); 467 usb_ep_disable(hidg->in_ep);
408 hidg->in_ep->driver_data = NULL; 468 hidg->in_ep->driver_data = NULL;
469
470 usb_ep_disable(hidg->out_ep);
471 hidg->out_ep->driver_data = NULL;
472
473 list_for_each_entry_safe(list, next, &hidg->completed_out_req, list) {
474 list_del(&list->list);
475 kfree(list);
476 }
409} 477}
410 478
411static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) 479static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
412{ 480{
413 struct usb_composite_dev *cdev = f->config->cdev; 481 struct usb_composite_dev *cdev = f->config->cdev;
414 struct f_hidg *hidg = func_to_hidg(f); 482 struct f_hidg *hidg = func_to_hidg(f);
415 int status = 0; 483 int i, status = 0;
416 484
417 VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt); 485 VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt);
418 486
@@ -429,11 +497,55 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
429 } 497 }
430 status = usb_ep_enable(hidg->in_ep); 498 status = usb_ep_enable(hidg->in_ep);
431 if (status < 0) { 499 if (status < 0) {
432 ERROR(cdev, "Enable endpoint FAILED!\n"); 500 ERROR(cdev, "Enable IN endpoint FAILED!\n");
433 goto fail; 501 goto fail;
434 } 502 }
435 hidg->in_ep->driver_data = hidg; 503 hidg->in_ep->driver_data = hidg;
436 } 504 }
505
506
507 if (hidg->out_ep != NULL) {
508 /* restart endpoint */
509 if (hidg->out_ep->driver_data != NULL)
510 usb_ep_disable(hidg->out_ep);
511
512 status = config_ep_by_speed(f->config->cdev->gadget, f,
513 hidg->out_ep);
514 if (status) {
515 ERROR(cdev, "config_ep_by_speed FAILED!\n");
516 goto fail;
517 }
518 status = usb_ep_enable(hidg->out_ep);
519 if (status < 0) {
520 ERROR(cdev, "Enable IN endpoint FAILED!\n");
521 goto fail;
522 }
523 hidg->out_ep->driver_data = hidg;
524
525 /*
526 * allocate a bunch of read buffers and queue them all at once.
527 */
528 for (i = 0; i < hidg->qlen && status == 0; i++) {
529 struct usb_request *req =
530 hidg_alloc_ep_req(hidg->out_ep,
531 hidg->report_length);
532 if (req) {
533 req->complete = hidg_set_report_complete;
534 req->context = hidg;
535 status = usb_ep_queue(hidg->out_ep, req,
536 GFP_ATOMIC);
537 if (status)
538 ERROR(cdev, "%s queue req --> %d\n",
539 hidg->out_ep->name, status);
540 } else {
541 usb_ep_disable(hidg->out_ep);
542 hidg->out_ep->driver_data = NULL;
543 status = -ENOMEM;
544 goto fail;
545 }
546 }
547 }
548
437fail: 549fail:
438 return status; 550 return status;
439} 551}
@@ -470,13 +582,18 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
470 ep->driver_data = c->cdev; /* claim */ 582 ep->driver_data = c->cdev; /* claim */
471 hidg->in_ep = ep; 583 hidg->in_ep = ep;
472 584
585 ep = usb_ep_autoconfig(c->cdev->gadget, &hidg_fs_out_ep_desc);
586 if (!ep)
587 goto fail;
588 ep->driver_data = c->cdev; /* claim */
589 hidg->out_ep = ep;
590
473 /* preallocate request and buffer */ 591 /* preallocate request and buffer */
474 status = -ENOMEM; 592 status = -ENOMEM;
475 hidg->req = usb_ep_alloc_request(hidg->in_ep, GFP_KERNEL); 593 hidg->req = usb_ep_alloc_request(hidg->in_ep, GFP_KERNEL);
476 if (!hidg->req) 594 if (!hidg->req)
477 goto fail; 595 goto fail;
478 596
479
480 hidg->req->buf = kmalloc(hidg->report_length, GFP_KERNEL); 597 hidg->req->buf = kmalloc(hidg->report_length, GFP_KERNEL);
481 if (!hidg->req->buf) 598 if (!hidg->req->buf)
482 goto fail; 599 goto fail;
@@ -486,12 +603,12 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
486 hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol; 603 hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol;
487 hidg_hs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); 604 hidg_hs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
488 hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); 605 hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
606 hidg_hs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
607 hidg_fs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
489 hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT; 608 hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT;
490 hidg_desc.desc[0].wDescriptorLength = 609 hidg_desc.desc[0].wDescriptorLength =
491 cpu_to_le16(hidg->report_desc_length); 610 cpu_to_le16(hidg->report_desc_length);
492 611
493 hidg->set_report_buff = NULL;
494
495 /* copy descriptors */ 612 /* copy descriptors */
496 f->descriptors = usb_copy_descriptors(hidg_fs_descriptors); 613 f->descriptors = usb_copy_descriptors(hidg_fs_descriptors);
497 if (!f->descriptors) 614 if (!f->descriptors)
@@ -500,6 +617,8 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
500 if (gadget_is_dualspeed(c->cdev->gadget)) { 617 if (gadget_is_dualspeed(c->cdev->gadget)) {
501 hidg_hs_in_ep_desc.bEndpointAddress = 618 hidg_hs_in_ep_desc.bEndpointAddress =
502 hidg_fs_in_ep_desc.bEndpointAddress; 619 hidg_fs_in_ep_desc.bEndpointAddress;
620 hidg_hs_out_ep_desc.bEndpointAddress =
621 hidg_fs_out_ep_desc.bEndpointAddress;
503 f->hs_descriptors = usb_copy_descriptors(hidg_hs_descriptors); 622 f->hs_descriptors = usb_copy_descriptors(hidg_hs_descriptors);
504 if (!f->hs_descriptors) 623 if (!f->hs_descriptors)
505 goto fail; 624 goto fail;
@@ -509,6 +628,7 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
509 spin_lock_init(&hidg->spinlock); 628 spin_lock_init(&hidg->spinlock);
510 init_waitqueue_head(&hidg->write_queue); 629 init_waitqueue_head(&hidg->write_queue);
511 init_waitqueue_head(&hidg->read_queue); 630 init_waitqueue_head(&hidg->read_queue);
631 INIT_LIST_HEAD(&hidg->completed_out_req);
512 632
513 /* create char device */ 633 /* create char device */
514 cdev_init(&hidg->cdev, &f_hidg_fops); 634 cdev_init(&hidg->cdev, &f_hidg_fops);
@@ -553,7 +673,6 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
553 usb_free_descriptors(f->descriptors); 673 usb_free_descriptors(f->descriptors);
554 674
555 kfree(hidg->report_desc); 675 kfree(hidg->report_desc);
556 kfree(hidg->set_report_buff);
557 kfree(hidg); 676 kfree(hidg);
558} 677}
559 678
@@ -624,6 +743,9 @@ int __init hidg_bind_config(struct usb_configuration *c,
624 hidg->func.disable = hidg_disable; 743 hidg->func.disable = hidg_disable;
625 hidg->func.setup = hidg_setup; 744 hidg->func.setup = hidg_setup;
626 745
746 /* this could me made configurable at some point */
747 hidg->qlen = 4;
748
627 status = usb_add_function(c, &hidg->func); 749 status = usb_add_function(c, &hidg->func);
628 if (status) 750 if (status)
629 kfree(hidg); 751 kfree(hidg);
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index f67b453740bd..4f1142efa6d1 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -44,12 +44,12 @@
44 * function for a USB device, it also illustrates a technique of 44 * function for a USB device, it also illustrates a technique of
45 * double-buffering for increased throughput. 45 * double-buffering for increased throughput.
46 * 46 *
47 * Function supports multiple logical units (LUNs). Backing storage 47 * For more information about MSF and in particular its module
48 * for each LUN is provided by a regular file or a block device. 48 * parameters and sysfs interface read the
49 * Access for each LUN can be limited to read-only. Moreover, the 49 * <Documentation/usb/mass-storage.txt> file.
50 * function can indicate that LUN is removable and/or CD-ROM. (The 50 */
51 * later implies read-only access.) 51
52 * 52/*
53 * MSF is configured by specifying a fsg_config structure. It has the 53 * MSF is configured by specifying a fsg_config structure. It has the
54 * following fields: 54 * following fields:
55 * 55 *
@@ -75,25 +75,6 @@
75 * ->nofua Flag specifying that FUA flag in SCSI WRITE(10,12) 75 * ->nofua Flag specifying that FUA flag in SCSI WRITE(10,12)
76 * commands for this LUN shall be ignored. 76 * commands for this LUN shall be ignored.
77 * 77 *
78 * lun_name_format A printf-like format for names of the LUN
79 * devices. This determines how the
80 * directory in sysfs will be named.
81 * Unless you are using several MSFs in
82 * a single gadget (as opposed to single
83 * MSF in many configurations) you may
84 * leave it as NULL (in which case
85 * "lun%d" will be used). In the format
86 * you can use "%d" to index LUNs for
87 * MSF's with more than one LUN. (Beware
88 * that there is only one integer given
89 * as an argument for the format and
90 * specifying invalid format may cause
91 * unspecified behaviour.)
92 * thread_name Name of the kernel thread process used by the
93 * MSF. You can safely set it to NULL
94 * (in which case default "file-storage"
95 * will be used).
96 *
97 * vendor_name 78 * vendor_name
98 * product_name 79 * product_name
99 * release Information used as a reply to INQUIRY 80 * release Information used as a reply to INQUIRY
@@ -114,62 +95,6 @@
114 * data track and no audio tracks; hence there need be only one 95 * data track and no audio tracks; hence there need be only one
115 * backing file per LUN. 96 * backing file per LUN.
116 * 97 *
117 *
118 * MSF includes support for module parameters. If gadget using it
119 * decides to use it, the following module parameters will be
120 * available:
121 *
122 * file=filename[,filename...]
123 * Names of the files or block devices used for
124 * backing storage.
125 * ro=b[,b...] Default false, boolean for read-only access.
126 * removable=b[,b...]
127 * Default true, boolean for removable media.
128 * cdrom=b[,b...] Default false, boolean for whether to emulate
129 * a CD-ROM drive.
130 * nofua=b[,b...] Default false, booleans for ignore FUA flag
131 * in SCSI WRITE(10,12) commands
132 * luns=N Default N = number of filenames, number of
133 * LUNs to support.
134 * stall Default determined according to the type of
135 * USB device controller (usually true),
136 * boolean to permit the driver to halt
137 * bulk endpoints.
138 *
139 * The module parameters may be prefixed with some string. You need
140 * to consult gadget's documentation or source to verify whether it is
141 * using those module parameters and if it does what are the prefixes
142 * (look for FSG_MODULE_PARAMETERS() macro usage, what's inside it is
143 * the prefix).
144 *
145 *
146 * Requirements are modest; only a bulk-in and a bulk-out endpoint are
147 * needed. The memory requirement amounts to two 16K buffers, size
148 * configurable by a parameter. Support is included for both
149 * full-speed and high-speed operation.
150 *
151 * Note that the driver is slightly non-portable in that it assumes a
152 * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
153 * interrupt-in endpoints. With most device controllers this isn't an
154 * issue, but there may be some with hardware restrictions that prevent
155 * a buffer from being used by more than one endpoint.
156 *
157 *
158 * The pathnames of the backing files and the ro settings are
159 * available in the attribute files "file" and "ro" in the lun<n> (or
160 * to be more precise in a directory which name comes from
161 * "lun_name_format" option!) subdirectory of the gadget's sysfs
162 * directory. If the "removable" option is set, writing to these
163 * files will simulate ejecting/loading the medium (writing an empty
164 * line means eject) and adjusting a write-enable tab. Changes to the
165 * ro setting are not allowed when the medium is loaded or if CD-ROM
166 * emulation is being used.
167 *
168 * When a LUN receive an "eject" SCSI request (Start/Stop Unit),
169 * if the LUN is removable, the backing file is released to simulate
170 * ejection.
171 *
172 *
173 * This function is heavily based on "File-backed Storage Gadget" by 98 * This function is heavily based on "File-backed Storage Gadget" by
174 * Alan Stern which in turn is heavily based on "Gadget Zero" by David 99 * Alan Stern which in turn is heavily based on "Gadget Zero" by David
175 * Brownell. The driver's SCSI command interface was based on the 100 * Brownell. The driver's SCSI command interface was based on the
@@ -211,7 +136,7 @@
211 * In normal operation the main thread is started during the gadget's 136 * In normal operation the main thread is started during the gadget's
212 * fsg_bind() callback and stopped during fsg_unbind(). But it can 137 * fsg_bind() callback and stopped during fsg_unbind(). But it can
213 * also exit when it receives a signal, and there's no point leaving 138 * also exit when it receives a signal, and there's no point leaving
214 * the gadget running when the thread is dead. At of this moment, MSF 139 * the gadget running when the thread is dead. As of this moment, MSF
215 * provides no way to deregister the gadget when thread dies -- maybe 140 * provides no way to deregister the gadget when thread dies -- maybe
216 * a callback functions is needed. 141 * a callback functions is needed.
217 * 142 *
@@ -417,9 +342,6 @@ struct fsg_config {
417 char nofua; 342 char nofua;
418 } luns[FSG_MAX_LUNS]; 343 } luns[FSG_MAX_LUNS];
419 344
420 const char *lun_name_format;
421 const char *thread_name;
422
423 /* Callback functions. */ 345 /* Callback functions. */
424 const struct fsg_operations *ops; 346 const struct fsg_operations *ops;
425 /* Gadget's private data. */ 347 /* Gadget's private data. */
@@ -2687,11 +2609,15 @@ static int fsg_main_thread(void *common_)
2687 2609
2688/*************************** DEVICE ATTRIBUTES ***************************/ 2610/*************************** DEVICE ATTRIBUTES ***************************/
2689 2611
2690/* Write permission is checked per LUN in store_*() functions. */
2691static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro); 2612static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
2692static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua); 2613static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua);
2693static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file); 2614static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
2694 2615
2616static struct device_attribute dev_attr_ro_cdrom =
2617 __ATTR(ro, 0444, fsg_show_ro, NULL);
2618static struct device_attribute dev_attr_file_nonremovable =
2619 __ATTR(file, 0444, fsg_show_file, NULL);
2620
2695 2621
2696/****************************** FSG COMMON ******************************/ 2622/****************************** FSG COMMON ******************************/
2697 2623
@@ -2792,11 +2718,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2792 curlun->dev.parent = &gadget->dev; 2718 curlun->dev.parent = &gadget->dev;
2793 /* curlun->dev.driver = &fsg_driver.driver; XXX */ 2719 /* curlun->dev.driver = &fsg_driver.driver; XXX */
2794 dev_set_drvdata(&curlun->dev, &common->filesem); 2720 dev_set_drvdata(&curlun->dev, &common->filesem);
2795 dev_set_name(&curlun->dev, 2721 dev_set_name(&curlun->dev, "lun%d", i);
2796 cfg->lun_name_format
2797 ? cfg->lun_name_format
2798 : "lun%d",
2799 i);
2800 2722
2801 rc = device_register(&curlun->dev); 2723 rc = device_register(&curlun->dev);
2802 if (rc) { 2724 if (rc) {
@@ -2806,10 +2728,16 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2806 goto error_release; 2728 goto error_release;
2807 } 2729 }
2808 2730
2809 rc = device_create_file(&curlun->dev, &dev_attr_ro); 2731 rc = device_create_file(&curlun->dev,
2732 curlun->cdrom
2733 ? &dev_attr_ro_cdrom
2734 : &dev_attr_ro);
2810 if (rc) 2735 if (rc)
2811 goto error_luns; 2736 goto error_luns;
2812 rc = device_create_file(&curlun->dev, &dev_attr_file); 2737 rc = device_create_file(&curlun->dev,
2738 curlun->removable
2739 ? &dev_attr_file
2740 : &dev_attr_file_nonremovable);
2813 if (rc) 2741 if (rc)
2814 goto error_luns; 2742 goto error_luns;
2815 rc = device_create_file(&curlun->dev, &dev_attr_nofua); 2743 rc = device_create_file(&curlun->dev, &dev_attr_nofua);
@@ -2878,8 +2806,7 @@ buffhds_first_it:
2878 2806
2879 /* Tell the thread to start working */ 2807 /* Tell the thread to start working */
2880 common->thread_task = 2808 common->thread_task =
2881 kthread_create(fsg_main_thread, common, 2809 kthread_create(fsg_main_thread, common, "file-storage");
2882 cfg->thread_name ?: "file-storage");
2883 if (IS_ERR(common->thread_task)) { 2810 if (IS_ERR(common->thread_task)) {
2884 rc = PTR_ERR(common->thread_task); 2811 rc = PTR_ERR(common->thread_task);
2885 goto error_release; 2812 goto error_release;
@@ -2945,8 +2872,14 @@ static void fsg_common_release(struct kref *ref)
2945 /* In error recovery common->nluns may be zero. */ 2872 /* In error recovery common->nluns may be zero. */
2946 for (; i; --i, ++lun) { 2873 for (; i; --i, ++lun) {
2947 device_remove_file(&lun->dev, &dev_attr_nofua); 2874 device_remove_file(&lun->dev, &dev_attr_nofua);
2948 device_remove_file(&lun->dev, &dev_attr_ro); 2875 device_remove_file(&lun->dev,
2949 device_remove_file(&lun->dev, &dev_attr_file); 2876 lun->cdrom
2877 ? &dev_attr_ro_cdrom
2878 : &dev_attr_ro);
2879 device_remove_file(&lun->dev,
2880 lun->removable
2881 ? &dev_attr_file
2882 : &dev_attr_file_nonremovable);
2950 fsg_lun_close(lun); 2883 fsg_lun_close(lun);
2951 device_unregister(&lun->dev); 2884 device_unregister(&lun->dev);
2952 } 2885 }
@@ -3167,8 +3100,7 @@ fsg_config_from_params(struct fsg_config *cfg,
3167 for (i = 0, lun = cfg->luns; i < cfg->nluns; ++i, ++lun) { 3100 for (i = 0, lun = cfg->luns; i < cfg->nluns; ++i, ++lun) {
3168 lun->ro = !!params->ro[i]; 3101 lun->ro = !!params->ro[i];
3169 lun->cdrom = !!params->cdrom[i]; 3102 lun->cdrom = !!params->cdrom[i];
3170 lun->removable = /* Removable by default */ 3103 lun->removable = !!params->removable[i];
3171 params->removable_count <= i || params->removable[i];
3172 lun->filename = 3104 lun->filename =
3173 params->file_count > i && params->file[i][0] 3105 params->file_count > i && params->file[i][0]
3174 ? params->file[i] 3106 ? params->file[i]
@@ -3176,8 +3108,6 @@ fsg_config_from_params(struct fsg_config *cfg,
3176 } 3108 }
3177 3109
3178 /* Let MSF use defaults */ 3110 /* Let MSF use defaults */
3179 cfg->lun_name_format = 0;
3180 cfg->thread_name = 0;
3181 cfg->vendor_name = 0; 3111 cfg->vendor_name = 0;
3182 cfg->product_name = 0; 3112 cfg->product_name = 0;
3183 cfg->release = 0xffff; 3113 cfg->release = 0xffff;
@@ -3203,4 +3133,3 @@ fsg_common_from_params(struct fsg_common *common,
3203 fsg_config_from_params(&cfg, params); 3133 fsg_config_from_params(&cfg, params);
3204 return fsg_common_init(common, cdev, &cfg); 3134 return fsg_common_init(common, cdev, &cfg);
3205} 3135}
3206
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
index 2022fe492148..2a8bf0655c60 100644
--- a/drivers/usb/gadget/f_uvc.c
+++ b/drivers/usb/gadget/f_uvc.c
@@ -29,6 +29,25 @@
29 29
30unsigned int uvc_gadget_trace_param; 30unsigned int uvc_gadget_trace_param;
31 31
32/*-------------------------------------------------------------------------*/
33
34/* module parameters specific to the Video streaming endpoint */
35static unsigned streaming_interval = 1;
36module_param(streaming_interval, uint, S_IRUGO|S_IWUSR);
37MODULE_PARM_DESC(streaming_interval, "1 - 16");
38
39static unsigned streaming_maxpacket = 1024;
40module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR);
41MODULE_PARM_DESC(streaming_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)");
42
43static unsigned streaming_mult;
44module_param(streaming_mult, uint, S_IRUGO|S_IWUSR);
45MODULE_PARM_DESC(streaming_mult, "0 - 2 (hs/ss only)");
46
47static unsigned streaming_maxburst;
48module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR);
49MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)");
50
32/* -------------------------------------------------------------------------- 51/* --------------------------------------------------------------------------
33 * Function descriptors 52 * Function descriptors
34 */ 53 */
@@ -59,6 +78,8 @@ static struct usb_gadget_strings *uvc_function_strings[] = {
59#define UVC_INTF_VIDEO_CONTROL 0 78#define UVC_INTF_VIDEO_CONTROL 0
60#define UVC_INTF_VIDEO_STREAMING 1 79#define UVC_INTF_VIDEO_STREAMING 1
61 80
81#define STATUS_BYTECOUNT 16 /* 16 bytes status */
82
62static struct usb_interface_assoc_descriptor uvc_iad __initdata = { 83static struct usb_interface_assoc_descriptor uvc_iad __initdata = {
63 .bLength = sizeof(uvc_iad), 84 .bLength = sizeof(uvc_iad),
64 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, 85 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
@@ -82,12 +103,12 @@ static struct usb_interface_descriptor uvc_control_intf __initdata = {
82 .iInterface = 0, 103 .iInterface = 0,
83}; 104};
84 105
85static struct usb_endpoint_descriptor uvc_control_ep __initdata = { 106static struct usb_endpoint_descriptor uvc_fs_control_ep __initdata = {
86 .bLength = USB_DT_ENDPOINT_SIZE, 107 .bLength = USB_DT_ENDPOINT_SIZE,
87 .bDescriptorType = USB_DT_ENDPOINT, 108 .bDescriptorType = USB_DT_ENDPOINT,
88 .bEndpointAddress = USB_DIR_IN, 109 .bEndpointAddress = USB_DIR_IN,
89 .bmAttributes = USB_ENDPOINT_XFER_INT, 110 .bmAttributes = USB_ENDPOINT_XFER_INT,
90 .wMaxPacketSize = cpu_to_le16(16), 111 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
91 .bInterval = 8, 112 .bInterval = 8,
92}; 113};
93 114
@@ -95,7 +116,7 @@ static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = {
95 .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE, 116 .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE,
96 .bDescriptorType = USB_DT_CS_ENDPOINT, 117 .bDescriptorType = USB_DT_CS_ENDPOINT,
97 .bDescriptorSubType = UVC_EP_INTERRUPT, 118 .bDescriptorSubType = UVC_EP_INTERRUPT,
98 .wMaxTransferSize = cpu_to_le16(16), 119 .wMaxTransferSize = cpu_to_le16(STATUS_BYTECOUNT),
99}; 120};
100 121
101static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = { 122static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = {
@@ -122,7 +143,7 @@ static struct usb_interface_descriptor uvc_streaming_intf_alt1 __initdata = {
122 .iInterface = 0, 143 .iInterface = 0,
123}; 144};
124 145
125static struct usb_endpoint_descriptor uvc_streaming_ep = { 146static struct usb_endpoint_descriptor uvc_fs_streaming_ep = {
126 .bLength = USB_DT_ENDPOINT_SIZE, 147 .bLength = USB_DT_ENDPOINT_SIZE,
127 .bDescriptorType = USB_DT_ENDPOINT, 148 .bDescriptorType = USB_DT_ENDPOINT,
128 .bEndpointAddress = USB_DIR_IN, 149 .bEndpointAddress = USB_DIR_IN,
@@ -131,15 +152,72 @@ static struct usb_endpoint_descriptor uvc_streaming_ep = {
131 .bInterval = 1, 152 .bInterval = 1,
132}; 153};
133 154
155static struct usb_endpoint_descriptor uvc_hs_streaming_ep = {
156 .bLength = USB_DT_ENDPOINT_SIZE,
157 .bDescriptorType = USB_DT_ENDPOINT,
158 .bEndpointAddress = USB_DIR_IN,
159 .bmAttributes = USB_ENDPOINT_XFER_ISOC,
160 .wMaxPacketSize = cpu_to_le16(1024),
161 .bInterval = 1,
162};
163
164/* super speed support */
165static struct usb_endpoint_descriptor uvc_ss_control_ep __initdata = {
166 .bLength = USB_DT_ENDPOINT_SIZE,
167 .bDescriptorType = USB_DT_ENDPOINT,
168
169 .bEndpointAddress = USB_DIR_IN,
170 .bmAttributes = USB_ENDPOINT_XFER_INT,
171 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
172 .bInterval = 8,
173};
174
175static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = {
176 .bLength = sizeof uvc_ss_control_comp,
177 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
178
179 /* the following 3 values can be tweaked if necessary */
180 /* .bMaxBurst = 0, */
181 /* .bmAttributes = 0, */
182 .wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT),
183};
184
185static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = {
186 .bLength = USB_DT_ENDPOINT_SIZE,
187 .bDescriptorType = USB_DT_ENDPOINT,
188
189 .bEndpointAddress = USB_DIR_IN,
190 .bmAttributes = USB_ENDPOINT_XFER_ISOC,
191 .wMaxPacketSize = cpu_to_le16(1024),
192 .bInterval = 4,
193};
194
195static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp = {
196 .bLength = sizeof uvc_ss_streaming_comp,
197 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
198
199 /* the following 3 values can be tweaked if necessary */
200 .bMaxBurst = 0,
201 .bmAttributes = 0,
202 .wBytesPerInterval = cpu_to_le16(1024),
203};
204
134static const struct usb_descriptor_header * const uvc_fs_streaming[] = { 205static const struct usb_descriptor_header * const uvc_fs_streaming[] = {
135 (struct usb_descriptor_header *) &uvc_streaming_intf_alt1, 206 (struct usb_descriptor_header *) &uvc_streaming_intf_alt1,
136 (struct usb_descriptor_header *) &uvc_streaming_ep, 207 (struct usb_descriptor_header *) &uvc_fs_streaming_ep,
137 NULL, 208 NULL,
138}; 209};
139 210
140static const struct usb_descriptor_header * const uvc_hs_streaming[] = { 211static const struct usb_descriptor_header * const uvc_hs_streaming[] = {
141 (struct usb_descriptor_header *) &uvc_streaming_intf_alt1, 212 (struct usb_descriptor_header *) &uvc_streaming_intf_alt1,
142 (struct usb_descriptor_header *) &uvc_streaming_ep, 213 (struct usb_descriptor_header *) &uvc_hs_streaming_ep,
214 NULL,
215};
216
217static const struct usb_descriptor_header * const uvc_ss_streaming[] = {
218 (struct usb_descriptor_header *) &uvc_streaming_intf_alt1,
219 (struct usb_descriptor_header *) &uvc_ss_streaming_ep,
220 (struct usb_descriptor_header *) &uvc_ss_streaming_comp,
143 NULL, 221 NULL,
144}; 222};
145 223
@@ -215,6 +293,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
215 struct uvc_device *uvc = to_uvc(f); 293 struct uvc_device *uvc = to_uvc(f);
216 struct v4l2_event v4l2_event; 294 struct v4l2_event v4l2_event;
217 struct uvc_event *uvc_event = (void *)&v4l2_event.u.data; 295 struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
296 int ret;
218 297
219 INFO(f->config->cdev, "uvc_function_set_alt(%u, %u)\n", interface, alt); 298 INFO(f->config->cdev, "uvc_function_set_alt(%u, %u)\n", interface, alt);
220 299
@@ -262,7 +341,10 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
262 return 0; 341 return 0;
263 342
264 if (uvc->video.ep) { 343 if (uvc->video.ep) {
265 uvc->video.ep->desc = &uvc_streaming_ep; 344 ret = config_ep_by_speed(f->config->cdev->gadget,
345 &(uvc->func), uvc->video.ep);
346 if (ret)
347 return ret;
266 usb_ep_enable(uvc->video.ep); 348 usb_ep_enable(uvc->video.ep);
267 } 349 }
268 350
@@ -368,9 +450,11 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
368{ 450{
369 struct uvc_input_header_descriptor *uvc_streaming_header; 451 struct uvc_input_header_descriptor *uvc_streaming_header;
370 struct uvc_header_descriptor *uvc_control_header; 452 struct uvc_header_descriptor *uvc_control_header;
453 const struct uvc_descriptor_header * const *uvc_control_desc;
371 const struct uvc_descriptor_header * const *uvc_streaming_cls; 454 const struct uvc_descriptor_header * const *uvc_streaming_cls;
372 const struct usb_descriptor_header * const *uvc_streaming_std; 455 const struct usb_descriptor_header * const *uvc_streaming_std;
373 const struct usb_descriptor_header * const *src; 456 const struct usb_descriptor_header * const *src;
457 static struct usb_endpoint_descriptor *uvc_control_ep;
374 struct usb_descriptor_header **dst; 458 struct usb_descriptor_header **dst;
375 struct usb_descriptor_header **hdr; 459 struct usb_descriptor_header **hdr;
376 unsigned int control_size; 460 unsigned int control_size;
@@ -379,10 +463,29 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
379 unsigned int bytes; 463 unsigned int bytes;
380 void *mem; 464 void *mem;
381 465
382 uvc_streaming_cls = (speed == USB_SPEED_FULL) 466 switch (speed) {
383 ? uvc->desc.fs_streaming : uvc->desc.hs_streaming; 467 case USB_SPEED_SUPER:
384 uvc_streaming_std = (speed == USB_SPEED_FULL) 468 uvc_control_desc = uvc->desc.ss_control;
385 ? uvc_fs_streaming : uvc_hs_streaming; 469 uvc_streaming_cls = uvc->desc.ss_streaming;
470 uvc_streaming_std = uvc_ss_streaming;
471 uvc_control_ep = &uvc_ss_control_ep;
472 break;
473
474 case USB_SPEED_HIGH:
475 uvc_control_desc = uvc->desc.fs_control;
476 uvc_streaming_cls = uvc->desc.hs_streaming;
477 uvc_streaming_std = uvc_hs_streaming;
478 uvc_control_ep = &uvc_fs_control_ep;
479 break;
480
481 case USB_SPEED_FULL:
482 default:
483 uvc_control_desc = uvc->desc.fs_control;
484 uvc_streaming_cls = uvc->desc.fs_streaming;
485 uvc_streaming_std = uvc_fs_streaming;
486 uvc_control_ep = &uvc_fs_control_ep;
487 break;
488 }
386 489
387 /* Descriptors layout 490 /* Descriptors layout
388 * 491 *
@@ -400,16 +503,24 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
400 control_size = 0; 503 control_size = 0;
401 streaming_size = 0; 504 streaming_size = 0;
402 bytes = uvc_iad.bLength + uvc_control_intf.bLength 505 bytes = uvc_iad.bLength + uvc_control_intf.bLength
403 + uvc_control_ep.bLength + uvc_control_cs_ep.bLength 506 + uvc_control_ep->bLength + uvc_control_cs_ep.bLength
404 + uvc_streaming_intf_alt0.bLength; 507 + uvc_streaming_intf_alt0.bLength;
405 n_desc = 5;
406 508
407 for (src = (const struct usb_descriptor_header**)uvc->desc.control; *src; ++src) { 509 if (speed == USB_SPEED_SUPER) {
510 bytes += uvc_ss_control_comp.bLength;
511 n_desc = 6;
512 } else {
513 n_desc = 5;
514 }
515
516 for (src = (const struct usb_descriptor_header **)uvc_control_desc;
517 *src; ++src) {
408 control_size += (*src)->bLength; 518 control_size += (*src)->bLength;
409 bytes += (*src)->bLength; 519 bytes += (*src)->bLength;
410 n_desc++; 520 n_desc++;
411 } 521 }
412 for (src = (const struct usb_descriptor_header**)uvc_streaming_cls; *src; ++src) { 522 for (src = (const struct usb_descriptor_header **)uvc_streaming_cls;
523 *src; ++src) {
413 streaming_size += (*src)->bLength; 524 streaming_size += (*src)->bLength;
414 bytes += (*src)->bLength; 525 bytes += (*src)->bLength;
415 n_desc++; 526 n_desc++;
@@ -433,12 +544,15 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
433 544
434 uvc_control_header = mem; 545 uvc_control_header = mem;
435 UVC_COPY_DESCRIPTORS(mem, dst, 546 UVC_COPY_DESCRIPTORS(mem, dst,
436 (const struct usb_descriptor_header**)uvc->desc.control); 547 (const struct usb_descriptor_header **)uvc_control_desc);
437 uvc_control_header->wTotalLength = cpu_to_le16(control_size); 548 uvc_control_header->wTotalLength = cpu_to_le16(control_size);
438 uvc_control_header->bInCollection = 1; 549 uvc_control_header->bInCollection = 1;
439 uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf; 550 uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf;
440 551
441 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_ep); 552 UVC_COPY_DESCRIPTOR(mem, dst, uvc_control_ep);
553 if (speed == USB_SPEED_SUPER)
554 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_ss_control_comp);
555
442 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_cs_ep); 556 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_cs_ep);
443 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_streaming_intf_alt0); 557 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_streaming_intf_alt0);
444 558
@@ -446,7 +560,8 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
446 UVC_COPY_DESCRIPTORS(mem, dst, 560 UVC_COPY_DESCRIPTORS(mem, dst,
447 (const struct usb_descriptor_header**)uvc_streaming_cls); 561 (const struct usb_descriptor_header**)uvc_streaming_cls);
448 uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size); 562 uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size);
449 uvc_streaming_header->bEndpointAddress = uvc_streaming_ep.bEndpointAddress; 563 uvc_streaming_header->bEndpointAddress =
564 uvc_fs_streaming_ep.bEndpointAddress;
450 565
451 UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std); 566 UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std);
452 567
@@ -482,6 +597,7 @@ uvc_function_unbind(struct usb_configuration *c, struct usb_function *f)
482 597
483 kfree(f->descriptors); 598 kfree(f->descriptors);
484 kfree(f->hs_descriptors); 599 kfree(f->hs_descriptors);
600 kfree(f->ss_descriptors);
485 601
486 kfree(uvc); 602 kfree(uvc);
487} 603}
@@ -496,8 +612,26 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
496 612
497 INFO(cdev, "uvc_function_bind\n"); 613 INFO(cdev, "uvc_function_bind\n");
498 614
615 /* sanity check the streaming endpoint module parameters */
616 if (streaming_interval < 1)
617 streaming_interval = 1;
618 if (streaming_interval > 16)
619 streaming_interval = 16;
620 if (streaming_mult > 2)
621 streaming_mult = 2;
622 if (streaming_maxburst > 15)
623 streaming_maxburst = 15;
624
625 /*
626 * fill in the FS video streaming specific descriptors from the
627 * module parameters
628 */
629 uvc_fs_streaming_ep.wMaxPacketSize = streaming_maxpacket > 1023 ?
630 1023 : streaming_maxpacket;
631 uvc_fs_streaming_ep.bInterval = streaming_interval;
632
499 /* Allocate endpoints. */ 633 /* Allocate endpoints. */
500 ep = usb_ep_autoconfig(cdev->gadget, &uvc_control_ep); 634 ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_control_ep);
501 if (!ep) { 635 if (!ep) {
502 INFO(cdev, "Unable to allocate control EP\n"); 636 INFO(cdev, "Unable to allocate control EP\n");
503 goto error; 637 goto error;
@@ -505,7 +639,7 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
505 uvc->control_ep = ep; 639 uvc->control_ep = ep;
506 ep->driver_data = uvc; 640 ep->driver_data = uvc;
507 641
508 ep = usb_ep_autoconfig(cdev->gadget, &uvc_streaming_ep); 642 ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep);
509 if (!ep) { 643 if (!ep) {
510 INFO(cdev, "Unable to allocate streaming EP\n"); 644 INFO(cdev, "Unable to allocate streaming EP\n");
511 goto error; 645 goto error;
@@ -526,9 +660,52 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
526 uvc_streaming_intf_alt1.bInterfaceNumber = ret; 660 uvc_streaming_intf_alt1.bInterfaceNumber = ret;
527 uvc->streaming_intf = ret; 661 uvc->streaming_intf = ret;
528 662
529 /* Copy descriptors. */ 663 /* sanity check the streaming endpoint module parameters */
664 if (streaming_maxpacket > 1024)
665 streaming_maxpacket = 1024;
666
667 /* Copy descriptors for FS. */
530 f->descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL); 668 f->descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL);
531 f->hs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_HIGH); 669
670 /* support high speed hardware */
671 if (gadget_is_dualspeed(cdev->gadget)) {
672 /*
673 * Fill in the HS descriptors from the module parameters for the
674 * Video Streaming endpoint.
675 * NOTE: We assume that the user knows what they are doing and
676 * won't give parameters that their UDC doesn't support.
677 */
678 uvc_hs_streaming_ep.wMaxPacketSize = streaming_maxpacket;
679 uvc_hs_streaming_ep.wMaxPacketSize |= streaming_mult << 11;
680 uvc_hs_streaming_ep.bInterval = streaming_interval;
681 uvc_hs_streaming_ep.bEndpointAddress =
682 uvc_fs_streaming_ep.bEndpointAddress;
683
684 /* Copy descriptors. */
685 f->hs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_HIGH);
686 }
687
688 /* support super speed hardware */
689 if (gadget_is_superspeed(c->cdev->gadget)) {
690 /*
691 * Fill in the SS descriptors from the module parameters for the
692 * Video Streaming endpoint.
693 * NOTE: We assume that the user knows what they are doing and
694 * won't give parameters that their UDC doesn't support.
695 */
696 uvc_ss_streaming_ep.wMaxPacketSize = streaming_maxpacket;
697 uvc_ss_streaming_ep.bInterval = streaming_interval;
698 uvc_ss_streaming_comp.bmAttributes = streaming_mult;
699 uvc_ss_streaming_comp.bMaxBurst = streaming_maxburst;
700 uvc_ss_streaming_comp.wBytesPerInterval =
701 streaming_maxpacket * (streaming_mult + 1) *
702 (streaming_maxburst + 1);
703 uvc_ss_streaming_ep.bEndpointAddress =
704 uvc_fs_streaming_ep.bEndpointAddress;
705
706 /* Copy descriptors. */
707 f->ss_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_SUPER);
708 }
532 709
533 /* Preallocate control endpoint request. */ 710 /* Preallocate control endpoint request. */
534 uvc->control_req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); 711 uvc->control_req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL);
@@ -583,9 +760,11 @@ error:
583 */ 760 */
584int __init 761int __init
585uvc_bind_config(struct usb_configuration *c, 762uvc_bind_config(struct usb_configuration *c,
586 const struct uvc_descriptor_header * const *control, 763 const struct uvc_descriptor_header * const *fs_control,
764 const struct uvc_descriptor_header * const *ss_control,
587 const struct uvc_descriptor_header * const *fs_streaming, 765 const struct uvc_descriptor_header * const *fs_streaming,
588 const struct uvc_descriptor_header * const *hs_streaming) 766 const struct uvc_descriptor_header * const *hs_streaming,
767 const struct uvc_descriptor_header * const *ss_streaming)
589{ 768{
590 struct uvc_device *uvc; 769 struct uvc_device *uvc;
591 int ret = 0; 770 int ret = 0;
@@ -603,38 +782,54 @@ uvc_bind_config(struct usb_configuration *c,
603 uvc->state = UVC_STATE_DISCONNECTED; 782 uvc->state = UVC_STATE_DISCONNECTED;
604 783
605 /* Validate the descriptors. */ 784 /* Validate the descriptors. */
606 if (control == NULL || control[0] == NULL || 785 if (fs_control == NULL || fs_control[0] == NULL ||
607 control[0]->bDescriptorSubType != UVC_VC_HEADER) 786 fs_control[0]->bDescriptorSubType != UVC_VC_HEADER)
608 goto error; 787 goto error;
609 788
610 if (fs_streaming == NULL || fs_streaming[0] == NULL || 789 if (ss_control == NULL || ss_control[0] == NULL ||
611 fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 790 ss_control[0]->bDescriptorSubType != UVC_VC_HEADER)
612 goto error; 791 goto error;
613 792
614 if (hs_streaming == NULL || hs_streaming[0] == NULL || 793 if (fs_streaming == NULL || fs_streaming[0] == NULL ||
615 hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 794 fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
616 goto error; 795 goto error;
617 796
618 uvc->desc.control = control; 797 if (hs_streaming == NULL || hs_streaming[0] == NULL ||
619 uvc->desc.fs_streaming = fs_streaming; 798 hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
620 uvc->desc.hs_streaming = hs_streaming;
621
622 /* Allocate string descriptor numbers. */
623 if ((ret = usb_string_id(c->cdev)) < 0)
624 goto error; 799 goto error;
625 uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id = ret;
626 uvc_iad.iFunction = ret;
627 800
628 if ((ret = usb_string_id(c->cdev)) < 0) 801 if (ss_streaming == NULL || ss_streaming[0] == NULL ||
802 ss_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
629 goto error; 803 goto error;
630 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id = ret;
631 uvc_control_intf.iInterface = ret;
632 804
633 if ((ret = usb_string_id(c->cdev)) < 0) 805 uvc->desc.fs_control = fs_control;
634 goto error; 806 uvc->desc.ss_control = ss_control;
635 uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id = ret; 807 uvc->desc.fs_streaming = fs_streaming;
636 uvc_streaming_intf_alt0.iInterface = ret; 808 uvc->desc.hs_streaming = hs_streaming;
637 uvc_streaming_intf_alt1.iInterface = ret; 809 uvc->desc.ss_streaming = ss_streaming;
810
811 /* maybe allocate device-global string IDs, and patch descriptors */
812 if (uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id == 0) {
813 /* Allocate string descriptor numbers. */
814 ret = usb_string_id(c->cdev);
815 if (ret < 0)
816 goto error;
817 uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id = ret;
818 uvc_iad.iFunction = ret;
819
820 ret = usb_string_id(c->cdev);
821 if (ret < 0)
822 goto error;
823 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id = ret;
824 uvc_control_intf.iInterface = ret;
825
826 ret = usb_string_id(c->cdev);
827 if (ret < 0)
828 goto error;
829 uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id = ret;
830 uvc_streaming_intf_alt0.iInterface = ret;
831 uvc_streaming_intf_alt1.iInterface = ret;
832 }
638 833
639 /* Register the function. */ 834 /* Register the function. */
640 uvc->func.name = "uvc"; 835 uvc->func.name = "uvc";
diff --git a/drivers/usb/gadget/f_uvc.h b/drivers/usb/gadget/f_uvc.h
index abf832935134..c3d258d30188 100644
--- a/drivers/usb/gadget/f_uvc.h
+++ b/drivers/usb/gadget/f_uvc.h
@@ -17,9 +17,11 @@
17#include <linux/usb/video.h> 17#include <linux/usb/video.h>
18 18
19extern int uvc_bind_config(struct usb_configuration *c, 19extern int uvc_bind_config(struct usb_configuration *c,
20 const struct uvc_descriptor_header * const *control, 20 const struct uvc_descriptor_header * const *fs_control,
21 const struct uvc_descriptor_header * const *fs_streaming, 21 const struct uvc_descriptor_header * const *hs_control,
22 const struct uvc_descriptor_header * const *hs_streaming); 22 const struct uvc_descriptor_header * const *fs_streaming,
23 const struct uvc_descriptor_header * const *hs_streaming,
24 const struct uvc_descriptor_header * const *ss_streaming);
23 25
24#endif /* _F_UVC_H_ */ 26#endif /* _F_UVC_H_ */
25 27
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c
index dcbc0a2e48dd..1b0f086426bd 100644
--- a/drivers/usb/gadget/fsl_mxc_udc.c
+++ b/drivers/usb/gadget/fsl_mxc_udc.c
@@ -21,7 +21,8 @@
21#include <mach/hardware.h> 21#include <mach/hardware.h>
22 22
23static struct clk *mxc_ahb_clk; 23static struct clk *mxc_ahb_clk;
24static struct clk *mxc_usb_clk; 24static struct clk *mxc_per_clk;
25static struct clk *mxc_ipg_clk;
25 26
26/* workaround ENGcm09152 for i.MX35 */ 27/* workaround ENGcm09152 for i.MX35 */
27#define USBPHYCTRL_OTGBASE_OFFSET 0x608 28#define USBPHYCTRL_OTGBASE_OFFSET 0x608
@@ -35,28 +36,31 @@ int fsl_udc_clk_init(struct platform_device *pdev)
35 36
36 pdata = pdev->dev.platform_data; 37 pdata = pdev->dev.platform_data;
37 38
38 if (!cpu_is_mx35() && !cpu_is_mx25()) { 39 mxc_ipg_clk = devm_clk_get(&pdev->dev, "ipg");
39 mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb"); 40 if (IS_ERR(mxc_ipg_clk)) {
40 if (IS_ERR(mxc_ahb_clk)) 41 dev_err(&pdev->dev, "clk_get(\"ipg\") failed\n");
41 return PTR_ERR(mxc_ahb_clk); 42 return PTR_ERR(mxc_ipg_clk);
43 }
42 44
43 ret = clk_enable(mxc_ahb_clk); 45 mxc_ahb_clk = devm_clk_get(&pdev->dev, "ahb");
44 if (ret < 0) { 46 if (IS_ERR(mxc_ahb_clk)) {
45 dev_err(&pdev->dev, "clk_enable(\"usb_ahb\") failed\n"); 47 dev_err(&pdev->dev, "clk_get(\"ahb\") failed\n");
46 goto eenahb; 48 return PTR_ERR(mxc_ahb_clk);
47 }
48 } 49 }
49 50
50 /* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */ 51 mxc_per_clk = devm_clk_get(&pdev->dev, "per");
51 mxc_usb_clk = clk_get(&pdev->dev, "usb"); 52 if (IS_ERR(mxc_per_clk)) {
52 if (IS_ERR(mxc_usb_clk)) { 53 dev_err(&pdev->dev, "clk_get(\"per\") failed\n");
53 dev_err(&pdev->dev, "clk_get(\"usb\") failed\n"); 54 return PTR_ERR(mxc_per_clk);
54 ret = PTR_ERR(mxc_usb_clk);
55 goto egusb;
56 } 55 }
57 56
57 clk_prepare_enable(mxc_ipg_clk);
58 clk_prepare_enable(mxc_ahb_clk);
59 clk_prepare_enable(mxc_per_clk);
60
61 /* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */
58 if (!cpu_is_mx51()) { 62 if (!cpu_is_mx51()) {
59 freq = clk_get_rate(mxc_usb_clk); 63 freq = clk_get_rate(mxc_per_clk);
60 if (pdata->phy_mode != FSL_USB2_PHY_ULPI && 64 if (pdata->phy_mode != FSL_USB2_PHY_ULPI &&
61 (freq < 59999000 || freq > 60001000)) { 65 (freq < 59999000 || freq > 60001000)) {
62 dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq); 66 dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq);
@@ -65,24 +69,13 @@ int fsl_udc_clk_init(struct platform_device *pdev)
65 } 69 }
66 } 70 }
67 71
68 ret = clk_enable(mxc_usb_clk);
69 if (ret < 0) {
70 dev_err(&pdev->dev, "clk_enable(\"usb_clk\") failed\n");
71 goto eenusb;
72 }
73
74 return 0; 72 return 0;
75 73
76eenusb:
77eclkrate: 74eclkrate:
78 clk_put(mxc_usb_clk); 75 clk_disable_unprepare(mxc_ipg_clk);
79 mxc_usb_clk = NULL; 76 clk_disable_unprepare(mxc_ahb_clk);
80egusb: 77 clk_disable_unprepare(mxc_per_clk);
81 if (!cpu_is_mx35()) 78 mxc_per_clk = NULL;
82 clk_disable(mxc_ahb_clk);
83eenahb:
84 if (!cpu_is_mx35())
85 clk_put(mxc_ahb_clk);
86 return ret; 79 return ret;
87} 80}
88 81
@@ -104,20 +97,15 @@ void fsl_udc_clk_finalize(struct platform_device *pdev)
104 97
105 /* ULPI transceivers don't need usbpll */ 98 /* ULPI transceivers don't need usbpll */
106 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) { 99 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
107 clk_disable(mxc_usb_clk); 100 clk_disable_unprepare(mxc_per_clk);
108 clk_put(mxc_usb_clk); 101 mxc_per_clk = NULL;
109 mxc_usb_clk = NULL;
110 } 102 }
111} 103}
112 104
113void fsl_udc_clk_release(void) 105void fsl_udc_clk_release(void)
114{ 106{
115 if (mxc_usb_clk) { 107 if (mxc_per_clk)
116 clk_disable(mxc_usb_clk); 108 clk_disable_unprepare(mxc_per_clk);
117 clk_put(mxc_usb_clk); 109 clk_disable_unprepare(mxc_ahb_clk);
118 } 110 clk_disable_unprepare(mxc_ipg_clk);
119 if (!cpu_is_mx35()) {
120 clk_disable(mxc_ahb_clk);
121 clk_put(mxc_ahb_clk);
122 }
123} 111}
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index bc6f9bb9994a..3def828f85e7 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -24,6 +24,7 @@
24#include <linux/ioport.h> 24#include <linux/ioport.h>
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/err.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28#include <linux/init.h> 29#include <linux/init.h>
29#include <linux/list.h> 30#include <linux/list.h>
@@ -1229,7 +1230,7 @@ static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1229 struct fsl_udc *udc; 1230 struct fsl_udc *udc;
1230 1231
1231 udc = container_of(gadget, struct fsl_udc, gadget); 1232 udc = container_of(gadget, struct fsl_udc, gadget);
1232 if (udc->transceiver) 1233 if (!IS_ERR_OR_NULL(udc->transceiver))
1233 return usb_phy_set_power(udc->transceiver, mA); 1234 return usb_phy_set_power(udc->transceiver, mA);
1234 return -ENOTSUPP; 1235 return -ENOTSUPP;
1235} 1236}
@@ -1983,13 +1984,13 @@ static int fsl_start(struct usb_gadget_driver *driver,
1983 goto out; 1984 goto out;
1984 } 1985 }
1985 1986
1986 if (udc_controller->transceiver) { 1987 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
1987 /* Suspend the controller until OTG enable it */ 1988 /* Suspend the controller until OTG enable it */
1988 udc_controller->stopped = 1; 1989 udc_controller->stopped = 1;
1989 printk(KERN_INFO "Suspend udc for OTG auto detect\n"); 1990 printk(KERN_INFO "Suspend udc for OTG auto detect\n");
1990 1991
1991 /* connect to bus through transceiver */ 1992 /* connect to bus through transceiver */
1992 if (udc_controller->transceiver) { 1993 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
1993 retval = otg_set_peripheral( 1994 retval = otg_set_peripheral(
1994 udc_controller->transceiver->otg, 1995 udc_controller->transceiver->otg,
1995 &udc_controller->gadget); 1996 &udc_controller->gadget);
@@ -2030,7 +2031,7 @@ static int fsl_stop(struct usb_gadget_driver *driver)
2030 if (!driver || driver != udc_controller->driver || !driver->unbind) 2031 if (!driver || driver != udc_controller->driver || !driver->unbind)
2031 return -EINVAL; 2032 return -EINVAL;
2032 2033
2033 if (udc_controller->transceiver) 2034 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
2034 otg_set_peripheral(udc_controller->transceiver->otg, NULL); 2035 otg_set_peripheral(udc_controller->transceiver->otg, NULL);
2035 2036
2036 /* stop DR, disable intr */ 2037 /* stop DR, disable intr */
@@ -2455,8 +2456,8 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2455 2456
2456#ifdef CONFIG_USB_OTG 2457#ifdef CONFIG_USB_OTG
2457 if (pdata->operating_mode == FSL_USB2_DR_OTG) { 2458 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
2458 udc_controller->transceiver = usb_get_transceiver(); 2459 udc_controller->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2459 if (!udc_controller->transceiver) { 2460 if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
2460 ERR("Can't find OTG driver!\n"); 2461 ERR("Can't find OTG driver!\n");
2461 ret = -ENODEV; 2462 ret = -ENODEV;
2462 goto err_kfree; 2463 goto err_kfree;
@@ -2540,7 +2541,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2540 goto err_free_irq; 2541 goto err_free_irq;
2541 } 2542 }
2542 2543
2543 if (!udc_controller->transceiver) { 2544 if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
2544 /* initialize usb hw reg except for regs for EP, 2545 /* initialize usb hw reg except for regs for EP,
2545 * leave usbintr reg untouched */ 2546 * leave usbintr reg untouched */
2546 dr_controller_setup(udc_controller); 2547 dr_controller_setup(udc_controller);
@@ -2560,11 +2561,12 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2560 dev_set_name(&udc_controller->gadget.dev, "gadget"); 2561 dev_set_name(&udc_controller->gadget.dev, "gadget");
2561 udc_controller->gadget.dev.release = fsl_udc_release; 2562 udc_controller->gadget.dev.release = fsl_udc_release;
2562 udc_controller->gadget.dev.parent = &pdev->dev; 2563 udc_controller->gadget.dev.parent = &pdev->dev;
2564 udc_controller->gadget.dev.of_node = pdev->dev.of_node;
2563 ret = device_register(&udc_controller->gadget.dev); 2565 ret = device_register(&udc_controller->gadget.dev);
2564 if (ret < 0) 2566 if (ret < 0)
2565 goto err_free_irq; 2567 goto err_free_irq;
2566 2568
2567 if (udc_controller->transceiver) 2569 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
2568 udc_controller->gadget.is_otg = 1; 2570 udc_controller->gadget.is_otg = 1;
2569 2571
2570 /* setup QH and epctrl for ep0 */ 2572 /* setup QH and epctrl for ep0 */
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index 54034f84f992..dc5334856afe 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -1432,7 +1432,7 @@ static int __init imx_udc_probe(struct platform_device *pdev)
1432 dev_err(&pdev->dev, "can't get USB clock\n"); 1432 dev_err(&pdev->dev, "can't get USB clock\n");
1433 goto fail2; 1433 goto fail2;
1434 } 1434 }
1435 clk_enable(clk); 1435 clk_prepare_enable(clk);
1436 1436
1437 if (clk_get_rate(clk) != 48000000) { 1437 if (clk_get_rate(clk) != 48000000) {
1438 D_INI(&pdev->dev, 1438 D_INI(&pdev->dev,
@@ -1496,7 +1496,7 @@ fail4:
1496 free_irq(imx_usb->usbd_int[i], imx_usb); 1496 free_irq(imx_usb->usbd_int[i], imx_usb);
1497fail3: 1497fail3:
1498 clk_put(clk); 1498 clk_put(clk);
1499 clk_disable(clk); 1499 clk_disable_unprepare(clk);
1500fail2: 1500fail2:
1501 iounmap(base); 1501 iounmap(base);
1502fail1: 1502fail1:
@@ -1521,7 +1521,7 @@ static int __exit imx_udc_remove(struct platform_device *pdev)
1521 free_irq(imx_usb->usbd_int[i], imx_usb); 1521 free_irq(imx_usb->usbd_int[i], imx_usb);
1522 1522
1523 clk_put(imx_usb->clk); 1523 clk_put(imx_usb->clk);
1524 clk_disable(imx_usb->clk); 1524 clk_disable_unprepare(imx_usb->clk);
1525 iounmap(imx_usb->base); 1525 iounmap(imx_usb->base);
1526 1526
1527 release_mem_region(imx_usb->res->start, resource_size(imx_usb->res)); 1527 release_mem_region(imx_usb->res->start, resource_size(imx_usb->res));
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c
index 2ab0388d93eb..f1ec99e69cb7 100644
--- a/drivers/usb/gadget/lpc32xx_udc.c
+++ b/drivers/usb/gadget/lpc32xx_udc.c
@@ -165,6 +165,7 @@ struct lpc32xx_udc {
165 int udp_irq[4]; 165 int udp_irq[4];
166 struct clk *usb_pll_clk; 166 struct clk *usb_pll_clk;
167 struct clk *usb_slv_clk; 167 struct clk *usb_slv_clk;
168 struct clk *usb_otg_clk;
168 169
169 /* DMA support */ 170 /* DMA support */
170 u32 *udca_v_base; 171 u32 *udca_v_base;
@@ -227,33 +228,15 @@ static inline struct lpc32xx_udc *to_udc(struct usb_gadget *g)
227#define UDCA_BUFF_SIZE (128) 228#define UDCA_BUFF_SIZE (128)
228 229
229/* TODO: When the clock framework is introduced in LPC32xx, IO_ADDRESS will 230/* TODO: When the clock framework is introduced in LPC32xx, IO_ADDRESS will
230 * be replaced with an inremap()ed pointer, see USB_OTG_CLK_CTRL() 231 * be replaced with an inremap()ed pointer
231 * */ 232 * */
232#define USB_CTRL IO_ADDRESS(LPC32XX_CLK_PM_BASE + 0x64) 233#define USB_CTRL IO_ADDRESS(LPC32XX_CLK_PM_BASE + 0x64)
233#define USB_CLOCK_MASK (AHB_M_CLOCK_ON | OTG_CLOCK_ON | \
234 DEV_CLOCK_ON | I2C_CLOCK_ON)
235 234
236/* USB_CTRL bit defines */ 235/* USB_CTRL bit defines */
237#define USB_SLAVE_HCLK_EN (1 << 24) 236#define USB_SLAVE_HCLK_EN (1 << 24)
238#define USB_HOST_NEED_CLK_EN (1 << 21) 237#define USB_HOST_NEED_CLK_EN (1 << 21)
239#define USB_DEV_NEED_CLK_EN (1 << 22) 238#define USB_DEV_NEED_CLK_EN (1 << 22)
240 239
241#define USB_OTG_CLK_CTRL(udc) ((udc)->udp_baseaddr + 0xFF4)
242#define USB_OTG_CLK_STAT(udc) ((udc)->udp_baseaddr + 0xFF8)
243
244/* USB_OTG_CLK_CTRL bit defines */
245#define AHB_M_CLOCK_ON (1 << 4)
246#define OTG_CLOCK_ON (1 << 3)
247#define I2C_CLOCK_ON (1 << 2)
248#define DEV_CLOCK_ON (1 << 1)
249#define HOST_CLOCK_ON (1 << 0)
250
251#define USB_OTG_STAT_CONTROL(udc) (udc->udp_baseaddr + 0x110)
252
253/* USB_OTG_STAT_CONTROL bit defines */
254#define TRANSPARENT_I2C_EN (1 << 7)
255#define HOST_EN (1 << 0)
256
257/********************************************************************** 240/**********************************************************************
258 * USB device controller register offsets 241 * USB device controller register offsets
259 **********************************************************************/ 242 **********************************************************************/
@@ -677,7 +660,7 @@ static void isp1301_udc_configure(struct lpc32xx_udc *udc)
677 ISP1301_I2C_INTERRUPT_RISING, INT_VBUS_VLD); 660 ISP1301_I2C_INTERRUPT_RISING, INT_VBUS_VLD);
678 661
679 /* Enable usb_need_clk clock after transceiver is initialized */ 662 /* Enable usb_need_clk clock after transceiver is initialized */
680 writel((readl(USB_CTRL) | (1 << 22)), USB_CTRL); 663 writel((readl(USB_CTRL) | USB_DEV_NEED_CLK_EN), USB_CTRL);
681 664
682 dev_info(udc->dev, "ISP1301 Vendor ID : 0x%04x\n", 665 dev_info(udc->dev, "ISP1301 Vendor ID : 0x%04x\n",
683 i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x00)); 666 i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x00));
@@ -1010,11 +993,8 @@ static void udc_dd_free(struct lpc32xx_udc *udc, struct lpc32xx_usbd_dd_gad *dd)
1010/* Enables or disables most of the USB system clocks when low power mode is 993/* Enables or disables most of the USB system clocks when low power mode is
1011 * needed. Clocks are typically started on a connection event, and disabled 994 * needed. Clocks are typically started on a connection event, and disabled
1012 * when a cable is disconnected */ 995 * when a cable is disconnected */
1013#define OTGOFF_CLK_MASK (AHB_M_CLOCK_ON | I2C_CLOCK_ON)
1014static void udc_clk_set(struct lpc32xx_udc *udc, int enable) 996static void udc_clk_set(struct lpc32xx_udc *udc, int enable)
1015{ 997{
1016 int to = 1000;
1017
1018 if (enable != 0) { 998 if (enable != 0) {
1019 if (udc->clocked) 999 if (udc->clocked)
1020 return; 1000 return;
@@ -1028,14 +1008,7 @@ static void udc_clk_set(struct lpc32xx_udc *udc, int enable)
1028 writel(readl(USB_CTRL) | USB_DEV_NEED_CLK_EN, 1008 writel(readl(USB_CTRL) | USB_DEV_NEED_CLK_EN,
1029 USB_CTRL); 1009 USB_CTRL);
1030 1010
1031 /* Set to enable all needed USB OTG clocks */ 1011 clk_enable(udc->usb_otg_clk);
1032 writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL(udc));
1033
1034 while (((readl(USB_OTG_CLK_STAT(udc)) & USB_CLOCK_MASK) !=
1035 USB_CLOCK_MASK) && (to > 0))
1036 to--;
1037 if (!to)
1038 dev_dbg(udc->dev, "Cannot enable USB OTG clocking\n");
1039 } else { 1012 } else {
1040 if (!udc->clocked) 1013 if (!udc->clocked)
1041 return; 1014 return;
@@ -1047,19 +1020,11 @@ static void udc_clk_set(struct lpc32xx_udc *udc, int enable)
1047 /* 48MHz PLL dpwn */ 1020 /* 48MHz PLL dpwn */
1048 clk_disable(udc->usb_pll_clk); 1021 clk_disable(udc->usb_pll_clk);
1049 1022
1050 /* Enable the USB device clock */ 1023 /* Disable the USB device clock */
1051 writel(readl(USB_CTRL) & ~USB_DEV_NEED_CLK_EN, 1024 writel(readl(USB_CTRL) & ~USB_DEV_NEED_CLK_EN,
1052 USB_CTRL); 1025 USB_CTRL);
1053 1026
1054 /* Set to enable all needed USB OTG clocks */ 1027 clk_disable(udc->usb_otg_clk);
1055 writel(OTGOFF_CLK_MASK, USB_OTG_CLK_CTRL(udc));
1056
1057 while (((readl(USB_OTG_CLK_STAT(udc)) &
1058 OTGOFF_CLK_MASK) !=
1059 OTGOFF_CLK_MASK) && (to > 0))
1060 to--;
1061 if (!to)
1062 dev_dbg(udc->dev, "Cannot disable USB OTG clocking\n");
1063 } 1028 }
1064} 1029}
1065 1030
@@ -3041,6 +3006,7 @@ static int lpc32xx_start(struct usb_gadget_driver *driver,
3041 3006
3042 udc->driver = driver; 3007 udc->driver = driver;
3043 udc->gadget.dev.driver = &driver->driver; 3008 udc->gadget.dev.driver = &driver->driver;
3009 udc->gadget.dev.of_node = udc->dev->of_node;
3044 udc->enabled = 1; 3010 udc->enabled = 1;
3045 udc->selfpowered = 1; 3011 udc->selfpowered = 1;
3046 udc->vbus = 0; 3012 udc->vbus = 0;
@@ -3239,6 +3205,12 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3239 retval = PTR_ERR(udc->usb_slv_clk); 3205 retval = PTR_ERR(udc->usb_slv_clk);
3240 goto usb_clk_get_fail; 3206 goto usb_clk_get_fail;
3241 } 3207 }
3208 udc->usb_otg_clk = clk_get(&pdev->dev, "ck_usb_otg");
3209 if (IS_ERR(udc->usb_otg_clk)) {
3210 dev_err(udc->dev, "failed to acquire USB otg clock\n");
3211 retval = PTR_ERR(udc->usb_slv_clk);
3212 goto usb_otg_clk_get_fail;
3213 }
3242 3214
3243 /* Setup PLL clock to 48MHz */ 3215 /* Setup PLL clock to 48MHz */
3244 retval = clk_enable(udc->usb_pll_clk); 3216 retval = clk_enable(udc->usb_pll_clk);
@@ -3262,15 +3234,12 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3262 goto usb_clk_enable_fail; 3234 goto usb_clk_enable_fail;
3263 } 3235 }
3264 3236
3265 /* Set to enable all needed USB OTG clocks */ 3237 /* Enable USB OTG clock */
3266 writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL(udc)); 3238 retval = clk_enable(udc->usb_otg_clk);
3267 3239 if (retval < 0) {
3268 i = 1000; 3240 dev_err(udc->dev, "failed to start USB otg clock\n");
3269 while (((readl(USB_OTG_CLK_STAT(udc)) & USB_CLOCK_MASK) != 3241 goto usb_otg_clk_enable_fail;
3270 USB_CLOCK_MASK) && (i > 0)) 3242 }
3271 i--;
3272 if (!i)
3273 dev_dbg(udc->dev, "USB OTG clocks not correctly enabled\n");
3274 3243
3275 /* Setup deferred workqueue data */ 3244 /* Setup deferred workqueue data */
3276 udc->poweron = udc->pullup = 0; 3245 udc->poweron = udc->pullup = 0;
@@ -3390,12 +3359,16 @@ dma_alloc_fail:
3390 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, 3359 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE,
3391 udc->udca_v_base, udc->udca_p_base); 3360 udc->udca_v_base, udc->udca_p_base);
3392i2c_fail: 3361i2c_fail:
3362 clk_disable(udc->usb_otg_clk);
3363usb_otg_clk_enable_fail:
3393 clk_disable(udc->usb_slv_clk); 3364 clk_disable(udc->usb_slv_clk);
3394usb_clk_enable_fail: 3365usb_clk_enable_fail:
3395pll_set_fail: 3366pll_set_fail:
3396 clk_disable(udc->usb_pll_clk); 3367 clk_disable(udc->usb_pll_clk);
3397pll_enable_fail: 3368pll_enable_fail:
3398 clk_put(udc->usb_slv_clk); 3369 clk_put(udc->usb_slv_clk);
3370usb_otg_clk_get_fail:
3371 clk_put(udc->usb_otg_clk);
3399usb_clk_get_fail: 3372usb_clk_get_fail:
3400 clk_put(udc->usb_pll_clk); 3373 clk_put(udc->usb_pll_clk);
3401pll_get_fail: 3374pll_get_fail:
@@ -3433,6 +3406,8 @@ static int __devexit lpc32xx_udc_remove(struct platform_device *pdev)
3433 3406
3434 device_unregister(&udc->gadget.dev); 3407 device_unregister(&udc->gadget.dev);
3435 3408
3409 clk_disable(udc->usb_otg_clk);
3410 clk_put(udc->usb_otg_clk);
3436 clk_disable(udc->usb_slv_clk); 3411 clk_disable(udc->usb_slv_clk);
3437 clk_put(udc->usb_slv_clk); 3412 clk_put(udc->usb_slv_clk);
3438 clk_disable(udc->usb_pll_clk); 3413 clk_disable(udc->usb_pll_clk);
@@ -3446,7 +3421,6 @@ static int __devexit lpc32xx_udc_remove(struct platform_device *pdev)
3446#ifdef CONFIG_PM 3421#ifdef CONFIG_PM
3447static int lpc32xx_udc_suspend(struct platform_device *pdev, pm_message_t mesg) 3422static int lpc32xx_udc_suspend(struct platform_device *pdev, pm_message_t mesg)
3448{ 3423{
3449 int to = 1000;
3450 struct lpc32xx_udc *udc = platform_get_drvdata(pdev); 3424 struct lpc32xx_udc *udc = platform_get_drvdata(pdev);
3451 3425
3452 if (udc->clocked) { 3426 if (udc->clocked) {
@@ -3461,15 +3435,6 @@ static int lpc32xx_udc_suspend(struct platform_device *pdev, pm_message_t mesg)
3461 on resume */ 3435 on resume */
3462 udc->clocked = 1; 3436 udc->clocked = 1;
3463 3437
3464 /* Kill OTG and I2C clocks */
3465 writel(0, USB_OTG_CLK_CTRL(udc));
3466 while (((readl(USB_OTG_CLK_STAT(udc)) & OTGOFF_CLK_MASK) !=
3467 OTGOFF_CLK_MASK) && (to > 0))
3468 to--;
3469 if (!to)
3470 dev_dbg(udc->dev,
3471 "USB OTG clocks not correctly enabled\n");
3472
3473 /* Kill global USB clock */ 3438 /* Kill global USB clock */
3474 clk_disable(udc->usb_slv_clk); 3439 clk_disable(udc->usb_slv_clk);
3475 } 3440 }
diff --git a/drivers/usb/gadget/mv_u3d.h b/drivers/usb/gadget/mv_u3d.h
new file mode 100644
index 000000000000..e32a787ac373
--- /dev/null
+++ b/drivers/usb/gadget/mv_u3d.h
@@ -0,0 +1,320 @@
1/*
2 * Copyright (C) 2011 Marvell International Ltd. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 */
8
9#ifndef __MV_U3D_H
10#define __MV_U3D_H
11
12#define MV_U3D_EP_CONTEXT_ALIGNMENT 32
13#define MV_U3D_TRB_ALIGNMENT 16
14#define MV_U3D_DMA_BOUNDARY 4096
15#define MV_U3D_EP0_MAX_PKT_SIZE 512
16
17/* ep0 transfer state */
18#define MV_U3D_WAIT_FOR_SETUP 0
19#define MV_U3D_DATA_STATE_XMIT 1
20#define MV_U3D_DATA_STATE_NEED_ZLP 2
21#define MV_U3D_WAIT_FOR_OUT_STATUS 3
22#define MV_U3D_DATA_STATE_RECV 4
23#define MV_U3D_STATUS_STAGE 5
24
25#define MV_U3D_EP_MAX_LENGTH_TRANSFER 0x10000
26
27/* USB3 Interrupt Status */
28#define MV_U3D_USBINT_SETUP 0x00000001
29#define MV_U3D_USBINT_RX_COMPLETE 0x00000002
30#define MV_U3D_USBINT_TX_COMPLETE 0x00000004
31#define MV_U3D_USBINT_UNDER_RUN 0x00000008
32#define MV_U3D_USBINT_RXDESC_ERR 0x00000010
33#define MV_U3D_USBINT_TXDESC_ERR 0x00000020
34#define MV_U3D_USBINT_RX_TRB_COMPLETE 0x00000040
35#define MV_U3D_USBINT_TX_TRB_COMPLETE 0x00000080
36#define MV_U3D_USBINT_VBUS_VALID 0x00010000
37#define MV_U3D_USBINT_STORAGE_CMD_FULL 0x00020000
38#define MV_U3D_USBINT_LINK_CHG 0x01000000
39
40/* USB3 Interrupt Enable */
41#define MV_U3D_INTR_ENABLE_SETUP 0x00000001
42#define MV_U3D_INTR_ENABLE_RX_COMPLETE 0x00000002
43#define MV_U3D_INTR_ENABLE_TX_COMPLETE 0x00000004
44#define MV_U3D_INTR_ENABLE_UNDER_RUN 0x00000008
45#define MV_U3D_INTR_ENABLE_RXDESC_ERR 0x00000010
46#define MV_U3D_INTR_ENABLE_TXDESC_ERR 0x00000020
47#define MV_U3D_INTR_ENABLE_RX_TRB_COMPLETE 0x00000040
48#define MV_U3D_INTR_ENABLE_TX_TRB_COMPLETE 0x00000080
49#define MV_U3D_INTR_ENABLE_RX_BUFFER_ERR 0x00000100
50#define MV_U3D_INTR_ENABLE_VBUS_VALID 0x00010000
51#define MV_U3D_INTR_ENABLE_STORAGE_CMD_FULL 0x00020000
52#define MV_U3D_INTR_ENABLE_LINK_CHG 0x01000000
53#define MV_U3D_INTR_ENABLE_PRIME_STATUS 0x02000000
54
55/* USB3 Link Change */
56#define MV_U3D_LINK_CHANGE_LINK_UP 0x00000001
57#define MV_U3D_LINK_CHANGE_SUSPEND 0x00000002
58#define MV_U3D_LINK_CHANGE_RESUME 0x00000004
59#define MV_U3D_LINK_CHANGE_WRESET 0x00000008
60#define MV_U3D_LINK_CHANGE_HRESET 0x00000010
61#define MV_U3D_LINK_CHANGE_VBUS_INVALID 0x00000020
62#define MV_U3D_LINK_CHANGE_INACT 0x00000040
63#define MV_U3D_LINK_CHANGE_DISABLE_AFTER_U0 0x00000080
64#define MV_U3D_LINK_CHANGE_U1 0x00000100
65#define MV_U3D_LINK_CHANGE_U2 0x00000200
66#define MV_U3D_LINK_CHANGE_U3 0x00000400
67
68/* bridge setting */
69#define MV_U3D_BRIDGE_SETTING_VBUS_VALID (1 << 16)
70
71/* Command Register Bit Masks */
72#define MV_U3D_CMD_RUN_STOP 0x00000001
73#define MV_U3D_CMD_CTRL_RESET 0x00000002
74
75/* ep control register */
76#define MV_U3D_EPXCR_EP_TYPE_CONTROL 0
77#define MV_U3D_EPXCR_EP_TYPE_ISOC 1
78#define MV_U3D_EPXCR_EP_TYPE_BULK 2
79#define MV_U3D_EPXCR_EP_TYPE_INT 3
80#define MV_U3D_EPXCR_EP_ENABLE_SHIFT 4
81#define MV_U3D_EPXCR_MAX_BURST_SIZE_SHIFT 12
82#define MV_U3D_EPXCR_MAX_PACKET_SIZE_SHIFT 16
83#define MV_U3D_USB_BULK_BURST_OUT 6
84#define MV_U3D_USB_BULK_BURST_IN 14
85
86#define MV_U3D_EPXCR_EP_FLUSH (1 << 7)
87#define MV_U3D_EPXCR_EP_HALT (1 << 1)
88#define MV_U3D_EPXCR_EP_INIT (1)
89
90/* TX/RX Status Register */
91#define MV_U3D_XFERSTATUS_COMPLETE_SHIFT 24
92#define MV_U3D_COMPLETE_INVALID 0
93#define MV_U3D_COMPLETE_SUCCESS 1
94#define MV_U3D_COMPLETE_BUFF_ERR 2
95#define MV_U3D_COMPLETE_SHORT_PACKET 3
96#define MV_U3D_COMPLETE_TRB_ERR 5
97#define MV_U3D_XFERSTATUS_TRB_LENGTH_MASK (0xFFFFFF)
98
99#define MV_U3D_USB_LINK_BYPASS_VBUS 0x8
100
101#define MV_U3D_LTSSM_PHY_INIT_DONE 0x80000000
102#define MV_U3D_LTSSM_NEVER_GO_COMPLIANCE 0x40000000
103
104#define MV_U3D_USB3_OP_REGS_OFFSET 0x100
105#define MV_U3D_USB3_PHY_OFFSET 0xB800
106
107#define DCS_ENABLE 0x1
108
109/* timeout */
110#define MV_U3D_RESET_TIMEOUT 10000
111#define MV_U3D_FLUSH_TIMEOUT 100000
112#define MV_U3D_OWN_TIMEOUT 10000
113#define LOOPS_USEC_SHIFT 4
114#define LOOPS_USEC (1 << LOOPS_USEC_SHIFT)
115#define LOOPS(timeout) ((timeout) >> LOOPS_USEC_SHIFT)
116
117/* ep direction */
118#define MV_U3D_EP_DIR_IN 1
119#define MV_U3D_EP_DIR_OUT 0
120#define mv_u3d_ep_dir(ep) (((ep)->ep_num == 0) ? \
121 ((ep)->u3d->ep0_dir) : ((ep)->direction))
122
123/* usb capability registers */
124struct mv_u3d_cap_regs {
125 u32 rsvd[5];
126 u32 dboff; /* doorbell register offset */
127 u32 rtsoff; /* runtime register offset */
128 u32 vuoff; /* vendor unique register offset */
129};
130
131/* operation registers */
132struct mv_u3d_op_regs {
133 u32 usbcmd; /* Command register */
134 u32 rsvd1[11];
135 u32 dcbaapl; /* Device Context Base Address low register */
136 u32 dcbaaph; /* Device Context Base Address high register */
137 u32 rsvd2[243];
138 u32 portsc; /* port status and control register*/
139 u32 portlinkinfo; /* port link info register*/
140 u32 rsvd3[9917];
141 u32 doorbell; /* doorbell register */
142};
143
144/* control enpoint enable registers */
145struct epxcr {
146 u32 epxoutcr0; /* ep out control 0 register */
147 u32 epxoutcr1; /* ep out control 1 register */
148 u32 epxincr0; /* ep in control 0 register */
149 u32 epxincr1; /* ep in control 1 register */
150};
151
152/* transfer status registers */
153struct xferstatus {
154 u32 curdeqlo; /* current TRB pointer low */
155 u32 curdeqhi; /* current TRB pointer high */
156 u32 statuslo; /* transfer status low */
157 u32 statushi; /* transfer status high */
158};
159
160/* vendor unique control registers */
161struct mv_u3d_vuc_regs {
162 u32 ctrlepenable; /* control endpoint enable register */
163 u32 setuplock; /* setup lock register */
164 u32 endcomplete; /* endpoint transfer complete register */
165 u32 intrcause; /* interrupt cause register */
166 u32 intrenable; /* interrupt enable register */
167 u32 trbcomplete; /* TRB complete register */
168 u32 linkchange; /* link change register */
169 u32 rsvd1[5];
170 u32 trbunderrun; /* TRB underrun register */
171 u32 rsvd2[43];
172 u32 bridgesetting; /* bridge setting register */
173 u32 rsvd3[7];
174 struct xferstatus txst[16]; /* TX status register */
175 struct xferstatus rxst[16]; /* RX status register */
176 u32 ltssm; /* LTSSM control register */
177 u32 pipe; /* PIPE control register */
178 u32 linkcr0; /* link control 0 register */
179 u32 linkcr1; /* link control 1 register */
180 u32 rsvd6[60];
181 u32 mib0; /* MIB0 counter register */
182 u32 usblink; /* usb link control register */
183 u32 ltssmstate; /* LTSSM state register */
184 u32 linkerrorcause; /* link error cause register */
185 u32 rsvd7[60];
186 u32 devaddrtiebrkr; /* device address and tie breaker */
187 u32 itpinfo0; /* ITP info 0 register */
188 u32 itpinfo1; /* ITP info 1 register */
189 u32 rsvd8[61];
190 struct epxcr epcr[16]; /* ep control register */
191 u32 rsvd9[64];
192 u32 phyaddr; /* PHY address register */
193 u32 phydata; /* PHY data register */
194};
195
196/* Endpoint context structure */
197struct mv_u3d_ep_context {
198 u32 rsvd0;
199 u32 rsvd1;
200 u32 trb_addr_lo; /* TRB address low 32 bit */
201 u32 trb_addr_hi; /* TRB address high 32 bit */
202 u32 rsvd2;
203 u32 rsvd3;
204 struct usb_ctrlrequest setup_buffer; /* setup data buffer */
205};
206
207/* TRB control data structure */
208struct mv_u3d_trb_ctrl {
209 u32 own:1; /* owner of TRB */
210 u32 rsvd1:3;
211 u32 chain:1; /* associate this TRB with the
212 next TRB on the Ring */
213 u32 ioc:1; /* interrupt on complete */
214 u32 rsvd2:4;
215 u32 type:6; /* TRB type */
216#define TYPE_NORMAL 1
217#define TYPE_DATA 3
218#define TYPE_LINK 6
219 u32 dir:1; /* Working at data stage of control endpoint
220 operation. 0 is OUT and 1 is IN. */
221 u32 rsvd3:15;
222};
223
224/* TRB data structure
225 * For multiple TRB, all the TRBs' physical address should be continuous.
226 */
227struct mv_u3d_trb_hw {
228 u32 buf_addr_lo; /* data buffer address low 32 bit */
229 u32 buf_addr_hi; /* data buffer address high 32 bit */
230 u32 trb_len; /* transfer length */
231 struct mv_u3d_trb_ctrl ctrl; /* TRB control data */
232};
233
234/* TRB structure */
235struct mv_u3d_trb {
236 struct mv_u3d_trb_hw *trb_hw; /* point to the trb_hw structure */
237 dma_addr_t trb_dma; /* dma address for this trb_hw */
238 struct list_head trb_list; /* trb list */
239};
240
241/* device data structure */
242struct mv_u3d {
243 struct usb_gadget gadget;
244 struct usb_gadget_driver *driver;
245 spinlock_t lock; /* device lock */
246 struct completion *done;
247 struct device *dev;
248 int irq;
249
250 /* usb controller registers */
251 struct mv_u3d_cap_regs __iomem *cap_regs;
252 struct mv_u3d_op_regs __iomem *op_regs;
253 struct mv_u3d_vuc_regs __iomem *vuc_regs;
254 void __iomem *phy_regs;
255
256 unsigned int max_eps;
257 struct mv_u3d_ep_context *ep_context;
258 size_t ep_context_size;
259 dma_addr_t ep_context_dma;
260
261 struct dma_pool *trb_pool; /* for TRB data structure */
262 struct mv_u3d_ep *eps;
263
264 struct mv_u3d_req *status_req; /* ep0 status request */
265 struct usb_ctrlrequest local_setup_buff; /* store setup data*/
266
267 unsigned int resume_state; /* USB state to resume */
268 unsigned int usb_state; /* USB current state */
269 unsigned int ep0_state; /* Endpoint zero state */
270 unsigned int ep0_dir;
271
272 unsigned int dev_addr; /* device address */
273
274 unsigned int errors;
275
276 unsigned softconnect:1;
277 unsigned vbus_active:1; /* vbus is active or not */
278 unsigned remote_wakeup:1; /* support remote wakeup */
279 unsigned clock_gating:1; /* clock gating or not */
280 unsigned active:1; /* udc is active or not */
281 unsigned vbus_valid_detect:1; /* udc vbus detection */
282
283 struct mv_usb_addon_irq *vbus;
284 unsigned int power;
285
286 struct clk *clk;
287};
288
289/* endpoint data structure */
290struct mv_u3d_ep {
291 struct usb_ep ep;
292 struct mv_u3d *u3d;
293 struct list_head queue; /* ep request queued hardware */
294 struct list_head req_list; /* list of ep request */
295 struct mv_u3d_ep_context *ep_context; /* ep context */
296 u32 direction;
297 char name[14];
298 u32 processing; /* there is ep request
299 queued on haredware */
300 spinlock_t req_lock; /* ep lock */
301 unsigned wedge:1;
302 unsigned enabled:1;
303 unsigned ep_type:2;
304 unsigned ep_num:8;
305};
306
307/* request data structure */
308struct mv_u3d_req {
309 struct usb_request req;
310 struct mv_u3d_ep *ep;
311 struct list_head queue; /* ep requst queued on hardware */
312 struct list_head list; /* ep request list */
313 struct list_head trb_list; /* trb list of a request */
314
315 struct mv_u3d_trb *trb_head; /* point to first trb of a request */
316 unsigned trb_count; /* TRB number in the chain */
317 unsigned chain; /* TRB chain or not */
318};
319
320#endif
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c
new file mode 100644
index 000000000000..8cfd5b028dbd
--- /dev/null
+++ b/drivers/usb/gadget/mv_u3d_core.c
@@ -0,0 +1,2098 @@
1/*
2 * Copyright (C) 2011 Marvell International Ltd. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 */
8
9#include <linux/module.h>
10#include <linux/dma-mapping.h>
11#include <linux/dmapool.h>
12#include <linux/kernel.h>
13#include <linux/delay.h>
14#include <linux/ioport.h>
15#include <linux/sched.h>
16#include <linux/slab.h>
17#include <linux/errno.h>
18#include <linux/init.h>
19#include <linux/timer.h>
20#include <linux/list.h>
21#include <linux/notifier.h>
22#include <linux/interrupt.h>
23#include <linux/moduleparam.h>
24#include <linux/device.h>
25#include <linux/usb/ch9.h>
26#include <linux/usb/gadget.h>
27#include <linux/pm.h>
28#include <linux/io.h>
29#include <linux/irq.h>
30#include <linux/platform_device.h>
31#include <linux/platform_data/mv_usb.h>
32#include <linux/clk.h>
33#include <asm/system.h>
34#include <asm/unaligned.h>
35#include <asm/byteorder.h>
36
37#include "mv_u3d.h"
38
39#define DRIVER_DESC "Marvell PXA USB3.0 Device Controller driver"
40
41static const char driver_name[] = "mv_u3d";
42static const char driver_desc[] = DRIVER_DESC;
43
44static void mv_u3d_nuke(struct mv_u3d_ep *ep, int status);
45static void mv_u3d_stop_activity(struct mv_u3d *u3d,
46 struct usb_gadget_driver *driver);
47
48/* for endpoint 0 operations */
49static const struct usb_endpoint_descriptor mv_u3d_ep0_desc = {
50 .bLength = USB_DT_ENDPOINT_SIZE,
51 .bDescriptorType = USB_DT_ENDPOINT,
52 .bEndpointAddress = 0,
53 .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
54 .wMaxPacketSize = MV_U3D_EP0_MAX_PKT_SIZE,
55};
56
57static void mv_u3d_ep0_reset(struct mv_u3d *u3d)
58{
59 struct mv_u3d_ep *ep;
60 u32 epxcr;
61 int i;
62
63 for (i = 0; i < 2; i++) {
64 ep = &u3d->eps[i];
65 ep->u3d = u3d;
66
67 /* ep0 ep context, ep0 in and out share the same ep context */
68 ep->ep_context = &u3d->ep_context[1];
69 }
70
71 /* reset ep state machine */
72 /* reset ep0 out */
73 epxcr = ioread32(&u3d->vuc_regs->epcr[0].epxoutcr0);
74 epxcr |= MV_U3D_EPXCR_EP_INIT;
75 iowrite32(epxcr, &u3d->vuc_regs->epcr[0].epxoutcr0);
76 udelay(5);
77 epxcr &= ~MV_U3D_EPXCR_EP_INIT;
78 iowrite32(epxcr, &u3d->vuc_regs->epcr[0].epxoutcr0);
79
80 epxcr = ((MV_U3D_EP0_MAX_PKT_SIZE
81 << MV_U3D_EPXCR_MAX_PACKET_SIZE_SHIFT)
82 | (1 << MV_U3D_EPXCR_MAX_BURST_SIZE_SHIFT)
83 | (1 << MV_U3D_EPXCR_EP_ENABLE_SHIFT)
84 | MV_U3D_EPXCR_EP_TYPE_CONTROL);
85 iowrite32(epxcr, &u3d->vuc_regs->epcr[0].epxoutcr1);
86
87 /* reset ep0 in */
88 epxcr = ioread32(&u3d->vuc_regs->epcr[0].epxincr0);
89 epxcr |= MV_U3D_EPXCR_EP_INIT;
90 iowrite32(epxcr, &u3d->vuc_regs->epcr[0].epxincr0);
91 udelay(5);
92 epxcr &= ~MV_U3D_EPXCR_EP_INIT;
93 iowrite32(epxcr, &u3d->vuc_regs->epcr[0].epxincr0);
94
95 epxcr = ((MV_U3D_EP0_MAX_PKT_SIZE
96 << MV_U3D_EPXCR_MAX_PACKET_SIZE_SHIFT)
97 | (1 << MV_U3D_EPXCR_MAX_BURST_SIZE_SHIFT)
98 | (1 << MV_U3D_EPXCR_EP_ENABLE_SHIFT)
99 | MV_U3D_EPXCR_EP_TYPE_CONTROL);
100 iowrite32(epxcr, &u3d->vuc_regs->epcr[0].epxincr1);
101}
102
103static void mv_u3d_ep0_stall(struct mv_u3d *u3d)
104{
105 u32 tmp;
106 dev_dbg(u3d->dev, "%s\n", __func__);
107
108 /* set TX and RX to stall */
109 tmp = ioread32(&u3d->vuc_regs->epcr[0].epxoutcr0);
110 tmp |= MV_U3D_EPXCR_EP_HALT;
111 iowrite32(tmp, &u3d->vuc_regs->epcr[0].epxoutcr0);
112
113 tmp = ioread32(&u3d->vuc_regs->epcr[0].epxincr0);
114 tmp |= MV_U3D_EPXCR_EP_HALT;
115 iowrite32(tmp, &u3d->vuc_regs->epcr[0].epxincr0);
116
117 /* update ep0 state */
118 u3d->ep0_state = MV_U3D_WAIT_FOR_SETUP;
119 u3d->ep0_dir = MV_U3D_EP_DIR_OUT;
120}
121
122static int mv_u3d_process_ep_req(struct mv_u3d *u3d, int index,
123 struct mv_u3d_req *curr_req)
124{
125 struct mv_u3d_trb *curr_trb;
126 dma_addr_t cur_deq_lo;
127 struct mv_u3d_ep_context *curr_ep_context;
128 int trb_complete, actual, remaining_length;
129 int direction, ep_num;
130 int retval = 0;
131 u32 tmp, status, length;
132
133 curr_ep_context = &u3d->ep_context[index];
134 direction = index % 2;
135 ep_num = index / 2;
136
137 trb_complete = 0;
138 actual = curr_req->req.length;
139
140 while (!list_empty(&curr_req->trb_list)) {
141 curr_trb = list_entry(curr_req->trb_list.next,
142 struct mv_u3d_trb, trb_list);
143 if (!curr_trb->trb_hw->ctrl.own) {
144 dev_err(u3d->dev, "%s, TRB own error!\n",
145 u3d->eps[index].name);
146 return 1;
147 }
148
149 curr_trb->trb_hw->ctrl.own = 0;
150 if (direction == MV_U3D_EP_DIR_OUT) {
151 tmp = ioread32(&u3d->vuc_regs->rxst[ep_num].statuslo);
152 cur_deq_lo =
153 ioread32(&u3d->vuc_regs->rxst[ep_num].curdeqlo);
154 } else {
155 tmp = ioread32(&u3d->vuc_regs->txst[ep_num].statuslo);
156 cur_deq_lo =
157 ioread32(&u3d->vuc_regs->txst[ep_num].curdeqlo);
158 }
159
160 status = tmp >> MV_U3D_XFERSTATUS_COMPLETE_SHIFT;
161 length = tmp & MV_U3D_XFERSTATUS_TRB_LENGTH_MASK;
162
163 if (status == MV_U3D_COMPLETE_SUCCESS ||
164 (status == MV_U3D_COMPLETE_SHORT_PACKET &&
165 direction == MV_U3D_EP_DIR_OUT)) {
166 remaining_length += length;
167 actual -= remaining_length;
168 } else {
169 dev_err(u3d->dev,
170 "complete_tr error: ep=%d %s: error = 0x%x\n",
171 index >> 1, direction ? "SEND" : "RECV",
172 status);
173 retval = -EPROTO;
174 }
175
176 list_del_init(&curr_trb->trb_list);
177 }
178 if (retval)
179 return retval;
180
181 curr_req->req.actual = actual;
182 return 0;
183}
184
185/*
186 * mv_u3d_done() - retire a request; caller blocked irqs
187 * @status : request status to be set, only works when
188 * request is still in progress.
189 */
190static
191void mv_u3d_done(struct mv_u3d_ep *ep, struct mv_u3d_req *req, int status)
192{
193 struct mv_u3d *u3d = (struct mv_u3d *)ep->u3d;
194
195 dev_dbg(u3d->dev, "mv_u3d_done: remove req->queue\n");
196 /* Removed the req from ep queue */
197 list_del_init(&req->queue);
198
199 /* req.status should be set as -EINPROGRESS in ep_queue() */
200 if (req->req.status == -EINPROGRESS)
201 req->req.status = status;
202 else
203 status = req->req.status;
204
205 /* Free trb for the request */
206 if (!req->chain)
207 dma_pool_free(u3d->trb_pool,
208 req->trb_head->trb_hw, req->trb_head->trb_dma);
209 else {
210 dma_unmap_single(ep->u3d->gadget.dev.parent,
211 (dma_addr_t)req->trb_head->trb_dma,
212 req->trb_count * sizeof(struct mv_u3d_trb_hw),
213 DMA_BIDIRECTIONAL);
214 kfree(req->trb_head->trb_hw);
215 }
216 kfree(req->trb_head);
217
218 usb_gadget_unmap_request(&u3d->gadget, &req->req, mv_u3d_ep_dir(ep));
219
220 if (status && (status != -ESHUTDOWN)) {
221 dev_dbg(u3d->dev, "complete %s req %p stat %d len %u/%u",
222 ep->ep.name, &req->req, status,
223 req->req.actual, req->req.length);
224 }
225
226 spin_unlock(&ep->u3d->lock);
227 /*
228 * complete() is from gadget layer,
229 * eg fsg->bulk_in_complete()
230 */
231 if (req->req.complete)
232 req->req.complete(&ep->ep, &req->req);
233
234 spin_lock(&ep->u3d->lock);
235}
236
237static int mv_u3d_queue_trb(struct mv_u3d_ep *ep, struct mv_u3d_req *req)
238{
239 u32 tmp, direction;
240 struct mv_u3d *u3d;
241 struct mv_u3d_ep_context *ep_context;
242 int retval = 0;
243
244 u3d = ep->u3d;
245 direction = mv_u3d_ep_dir(ep);
246
247 /* ep0 in and out share the same ep context slot 1*/
248 if (ep->ep_num == 0)
249 ep_context = &(u3d->ep_context[1]);
250 else
251 ep_context = &(u3d->ep_context[ep->ep_num * 2 + direction]);
252
253 /* check if the pipe is empty or not */
254 if (!list_empty(&ep->queue)) {
255 dev_err(u3d->dev, "add trb to non-empty queue!\n");
256 retval = -ENOMEM;
257 WARN_ON(1);
258 } else {
259 ep_context->rsvd0 = cpu_to_le32(1);
260 ep_context->rsvd1 = 0;
261
262 /* Configure the trb address and set the DCS bit.
263 * Both DCS bit and own bit in trb should be set.
264 */
265 ep_context->trb_addr_lo =
266 cpu_to_le32(req->trb_head->trb_dma | DCS_ENABLE);
267 ep_context->trb_addr_hi = 0;
268
269 /* Ensure that updates to the EP Context will
270 * occure before Ring Bell.
271 */
272 wmb();
273
274 /* ring bell the ep */
275 if (ep->ep_num == 0)
276 tmp = 0x1;
277 else
278 tmp = ep->ep_num * 2
279 + ((direction == MV_U3D_EP_DIR_OUT) ? 0 : 1);
280
281 iowrite32(tmp, &u3d->op_regs->doorbell);
282 }
283 return retval;
284}
285
286static struct mv_u3d_trb *mv_u3d_build_trb_one(struct mv_u3d_req *req,
287 unsigned *length, dma_addr_t *dma)
288{
289 u32 temp;
290 unsigned int direction;
291 struct mv_u3d_trb *trb;
292 struct mv_u3d_trb_hw *trb_hw;
293 struct mv_u3d *u3d;
294
295 /* how big will this transfer be? */
296 *length = req->req.length - req->req.actual;
297 BUG_ON(*length > (unsigned)MV_U3D_EP_MAX_LENGTH_TRANSFER);
298
299 u3d = req->ep->u3d;
300
301 trb = kzalloc(sizeof(*trb), GFP_ATOMIC);
302 if (!trb) {
303 dev_err(u3d->dev, "%s, trb alloc fail\n", __func__);
304 return NULL;
305 }
306
307 /*
308 * Be careful that no _GFP_HIGHMEM is set,
309 * or we can not use dma_to_virt
310 * cannot use GFP_KERNEL in spin lock
311 */
312 trb_hw = dma_pool_alloc(u3d->trb_pool, GFP_ATOMIC, dma);
313 if (!trb_hw) {
314 dev_err(u3d->dev,
315 "%s, dma_pool_alloc fail\n", __func__);
316 return NULL;
317 }
318 trb->trb_dma = *dma;
319 trb->trb_hw = trb_hw;
320
321 /* initialize buffer page pointers */
322 temp = (u32)(req->req.dma + req->req.actual);
323
324 trb_hw->buf_addr_lo = cpu_to_le32(temp);
325 trb_hw->buf_addr_hi = 0;
326 trb_hw->trb_len = cpu_to_le32(*length);
327 trb_hw->ctrl.own = 1;
328
329 if (req->ep->ep_num == 0)
330 trb_hw->ctrl.type = TYPE_DATA;
331 else
332 trb_hw->ctrl.type = TYPE_NORMAL;
333
334 req->req.actual += *length;
335
336 direction = mv_u3d_ep_dir(req->ep);
337 if (direction == MV_U3D_EP_DIR_IN)
338 trb_hw->ctrl.dir = 1;
339 else
340 trb_hw->ctrl.dir = 0;
341
342 /* Enable interrupt for the last trb of a request */
343 if (!req->req.no_interrupt)
344 trb_hw->ctrl.ioc = 1;
345
346 trb_hw->ctrl.chain = 0;
347
348 wmb();
349 return trb;
350}
351
352static int mv_u3d_build_trb_chain(struct mv_u3d_req *req, unsigned *length,
353 struct mv_u3d_trb *trb, int *is_last)
354{
355 u32 temp;
356 unsigned int direction;
357 struct mv_u3d *u3d;
358
359 /* how big will this transfer be? */
360 *length = min(req->req.length - req->req.actual,
361 (unsigned)MV_U3D_EP_MAX_LENGTH_TRANSFER);
362
363 u3d = req->ep->u3d;
364
365 trb->trb_dma = 0;
366
367 /* initialize buffer page pointers */
368 temp = (u32)(req->req.dma + req->req.actual);
369
370 trb->trb_hw->buf_addr_lo = cpu_to_le32(temp);
371 trb->trb_hw->buf_addr_hi = 0;
372 trb->trb_hw->trb_len = cpu_to_le32(*length);
373 trb->trb_hw->ctrl.own = 1;
374
375 if (req->ep->ep_num == 0)
376 trb->trb_hw->ctrl.type = TYPE_DATA;
377 else
378 trb->trb_hw->ctrl.type = TYPE_NORMAL;
379
380 req->req.actual += *length;
381
382 direction = mv_u3d_ep_dir(req->ep);
383 if (direction == MV_U3D_EP_DIR_IN)
384 trb->trb_hw->ctrl.dir = 1;
385 else
386 trb->trb_hw->ctrl.dir = 0;
387
388 /* zlp is needed if req->req.zero is set */
389 if (req->req.zero) {
390 if (*length == 0 || (*length % req->ep->ep.maxpacket) != 0)
391 *is_last = 1;
392 else
393 *is_last = 0;
394 } else if (req->req.length == req->req.actual)
395 *is_last = 1;
396 else
397 *is_last = 0;
398
399 /* Enable interrupt for the last trb of a request */
400 if (*is_last && !req->req.no_interrupt)
401 trb->trb_hw->ctrl.ioc = 1;
402
403 if (*is_last)
404 trb->trb_hw->ctrl.chain = 0;
405 else {
406 trb->trb_hw->ctrl.chain = 1;
407 dev_dbg(u3d->dev, "chain trb\n");
408 }
409
410 wmb();
411
412 return 0;
413}
414
415/* generate TRB linked list for a request
416 * usb controller only supports continous trb chain,
417 * that trb structure physical address should be continous.
418 */
419static int mv_u3d_req_to_trb(struct mv_u3d_req *req)
420{
421 unsigned count;
422 int is_last;
423 struct mv_u3d_trb *trb;
424 struct mv_u3d_trb_hw *trb_hw;
425 struct mv_u3d *u3d;
426 dma_addr_t dma;
427 unsigned length;
428 unsigned trb_num;
429
430 u3d = req->ep->u3d;
431
432 INIT_LIST_HEAD(&req->trb_list);
433
434 length = req->req.length - req->req.actual;
435 /* normally the request transfer length is less than 16KB.
436 * we use buil_trb_one() to optimize it.
437 */
438 if (length <= (unsigned)MV_U3D_EP_MAX_LENGTH_TRANSFER) {
439 trb = mv_u3d_build_trb_one(req, &count, &dma);
440 list_add_tail(&trb->trb_list, &req->trb_list);
441 req->trb_head = trb;
442 req->trb_count = 1;
443 req->chain = 0;
444 } else {
445 trb_num = length / MV_U3D_EP_MAX_LENGTH_TRANSFER;
446 if (length % MV_U3D_EP_MAX_LENGTH_TRANSFER)
447 trb_num++;
448
449 trb = kcalloc(trb_num, sizeof(*trb), GFP_ATOMIC);
450 if (!trb) {
451 dev_err(u3d->dev,
452 "%s, trb alloc fail\n", __func__);
453 return -ENOMEM;
454 }
455
456 trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC);
457 if (!trb_hw) {
458 dev_err(u3d->dev,
459 "%s, trb_hw alloc fail\n", __func__);
460 return -ENOMEM;
461 }
462
463 do {
464 trb->trb_hw = trb_hw;
465 if (mv_u3d_build_trb_chain(req, &count,
466 trb, &is_last)) {
467 dev_err(u3d->dev,
468 "%s, mv_u3d_build_trb_chain fail\n",
469 __func__);
470 return -EIO;
471 }
472
473 list_add_tail(&trb->trb_list, &req->trb_list);
474 req->trb_count++;
475 trb++;
476 trb_hw++;
477 } while (!is_last);
478
479 req->trb_head = list_entry(req->trb_list.next,
480 struct mv_u3d_trb, trb_list);
481 req->trb_head->trb_dma = dma_map_single(u3d->gadget.dev.parent,
482 req->trb_head->trb_hw,
483 trb_num * sizeof(*trb_hw),
484 DMA_BIDIRECTIONAL);
485
486 req->chain = 1;
487 }
488
489 return 0;
490}
491
492static int
493mv_u3d_start_queue(struct mv_u3d_ep *ep)
494{
495 struct mv_u3d *u3d = ep->u3d;
496 struct mv_u3d_req *req;
497 int ret;
498
499 if (!list_empty(&ep->req_list) && !ep->processing)
500 req = list_entry(ep->req_list.next, struct mv_u3d_req, list);
501 else
502 return 0;
503
504 ep->processing = 1;
505
506 /* set up dma mapping */
507 ret = usb_gadget_map_request(&u3d->gadget, &req->req,
508 mv_u3d_ep_dir(ep));
509 if (ret)
510 return ret;
511
512 req->req.status = -EINPROGRESS;
513 req->req.actual = 0;
514 req->trb_count = 0;
515
516 /* build trbs and push them to device queue */
517 if (!mv_u3d_req_to_trb(req)) {
518 ret = mv_u3d_queue_trb(ep, req);
519 if (ret) {
520 ep->processing = 0;
521 return ret;
522 }
523 } else {
524 ep->processing = 0;
525 dev_err(u3d->dev, "%s, mv_u3d_req_to_trb fail\n", __func__);
526 return -ENOMEM;
527 }
528
529 /* irq handler advances the queue */
530 if (req)
531 list_add_tail(&req->queue, &ep->queue);
532
533 return 0;
534}
535
536static int mv_u3d_ep_enable(struct usb_ep *_ep,
537 const struct usb_endpoint_descriptor *desc)
538{
539 struct mv_u3d *u3d;
540 struct mv_u3d_ep *ep;
541 struct mv_u3d_ep_context *ep_context;
542 u16 max = 0;
543 unsigned maxburst = 0;
544 u32 epxcr, direction;
545
546 if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT)
547 return -EINVAL;
548
549 ep = container_of(_ep, struct mv_u3d_ep, ep);
550 u3d = ep->u3d;
551
552 if (!u3d->driver || u3d->gadget.speed == USB_SPEED_UNKNOWN)
553 return -ESHUTDOWN;
554
555 direction = mv_u3d_ep_dir(ep);
556 max = le16_to_cpu(desc->wMaxPacketSize);
557
558 if (!_ep->maxburst)
559 _ep->maxburst = 1;
560 maxburst = _ep->maxburst;
561
562 /* Get the endpoint context address */
563 ep_context = (struct mv_u3d_ep_context *)ep->ep_context;
564
565 /* Set the max burst size */
566 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
567 case USB_ENDPOINT_XFER_BULK:
568 if (maxburst > 16) {
569 dev_dbg(u3d->dev,
570 "max burst should not be greater "
571 "than 16 on bulk ep\n");
572 maxburst = 1;
573 _ep->maxburst = maxburst;
574 }
575 dev_dbg(u3d->dev,
576 "maxburst: %d on bulk %s\n", maxburst, ep->name);
577 break;
578 case USB_ENDPOINT_XFER_CONTROL:
579 /* control transfer only supports maxburst as one */
580 maxburst = 1;
581 _ep->maxburst = maxburst;
582 break;
583 case USB_ENDPOINT_XFER_INT:
584 if (maxburst != 1) {
585 dev_dbg(u3d->dev,
586 "max burst should be 1 on int ep "
587 "if transfer size is not 1024\n");
588 maxburst = 1;
589 _ep->maxburst = maxburst;
590 }
591 break;
592 case USB_ENDPOINT_XFER_ISOC:
593 if (maxburst != 1) {
594 dev_dbg(u3d->dev,
595 "max burst should be 1 on isoc ep "
596 "if transfer size is not 1024\n");
597 maxburst = 1;
598 _ep->maxburst = maxburst;
599 }
600 break;
601 default:
602 goto en_done;
603 }
604
605 ep->ep.maxpacket = max;
606 ep->ep.desc = desc;
607 ep->enabled = 1;
608
609 /* Enable the endpoint for Rx or Tx and set the endpoint type */
610 if (direction == MV_U3D_EP_DIR_OUT) {
611 epxcr = ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxoutcr0);
612 epxcr |= MV_U3D_EPXCR_EP_INIT;
613 iowrite32(epxcr, &u3d->vuc_regs->epcr[ep->ep_num].epxoutcr0);
614 udelay(5);
615 epxcr &= ~MV_U3D_EPXCR_EP_INIT;
616 iowrite32(epxcr, &u3d->vuc_regs->epcr[ep->ep_num].epxoutcr0);
617
618 epxcr = ((max << MV_U3D_EPXCR_MAX_PACKET_SIZE_SHIFT)
619 | ((maxburst - 1) << MV_U3D_EPXCR_MAX_BURST_SIZE_SHIFT)
620 | (1 << MV_U3D_EPXCR_EP_ENABLE_SHIFT)
621 | (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK));
622 iowrite32(epxcr, &u3d->vuc_regs->epcr[ep->ep_num].epxoutcr1);
623 } else {
624 epxcr = ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxincr0);
625 epxcr |= MV_U3D_EPXCR_EP_INIT;
626 iowrite32(epxcr, &u3d->vuc_regs->epcr[ep->ep_num].epxincr0);
627 udelay(5);
628 epxcr &= ~MV_U3D_EPXCR_EP_INIT;
629 iowrite32(epxcr, &u3d->vuc_regs->epcr[ep->ep_num].epxincr0);
630
631 epxcr = ((max << MV_U3D_EPXCR_MAX_PACKET_SIZE_SHIFT)
632 | ((maxburst - 1) << MV_U3D_EPXCR_MAX_BURST_SIZE_SHIFT)
633 | (1 << MV_U3D_EPXCR_EP_ENABLE_SHIFT)
634 | (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK));
635 iowrite32(epxcr, &u3d->vuc_regs->epcr[ep->ep_num].epxincr1);
636 }
637
638 return 0;
639en_done:
640 return -EINVAL;
641}
642
643static int mv_u3d_ep_disable(struct usb_ep *_ep)
644{
645 struct mv_u3d *u3d;
646 struct mv_u3d_ep *ep;
647 struct mv_u3d_ep_context *ep_context;
648 u32 epxcr, direction;
649
650 if (!_ep)
651 return -EINVAL;
652
653 ep = container_of(_ep, struct mv_u3d_ep, ep);
654 if (!ep->ep.desc)
655 return -EINVAL;
656
657 u3d = ep->u3d;
658
659 /* Get the endpoint context address */
660 ep_context = ep->ep_context;
661
662 direction = mv_u3d_ep_dir(ep);
663
664 /* nuke all pending requests (does flush) */
665 mv_u3d_nuke(ep, -ESHUTDOWN);
666
667 /* Disable the endpoint for Rx or Tx and reset the endpoint type */
668 if (direction == MV_U3D_EP_DIR_OUT) {
669 epxcr = ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxoutcr1);
670 epxcr &= ~((1 << MV_U3D_EPXCR_EP_ENABLE_SHIFT)
671 | USB_ENDPOINT_XFERTYPE_MASK);
672 iowrite32(epxcr, &u3d->vuc_regs->epcr[ep->ep_num].epxoutcr1);
673 } else {
674 epxcr = ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxincr1);
675 epxcr &= ~((1 << MV_U3D_EPXCR_EP_ENABLE_SHIFT)
676 | USB_ENDPOINT_XFERTYPE_MASK);
677 iowrite32(epxcr, &u3d->vuc_regs->epcr[ep->ep_num].epxincr1);
678 }
679
680 ep->enabled = 0;
681
682 ep->ep.desc = NULL;
683 return 0;
684}
685
686static struct usb_request *
687mv_u3d_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
688{
689 struct mv_u3d_req *req = NULL;
690
691 req = kzalloc(sizeof *req, gfp_flags);
692 if (!req)
693 return NULL;
694
695 INIT_LIST_HEAD(&req->queue);
696
697 return &req->req;
698}
699
700static void mv_u3d_free_request(struct usb_ep *_ep, struct usb_request *_req)
701{
702 struct mv_u3d_req *req = container_of(_req, struct mv_u3d_req, req);
703
704 kfree(req);
705}
706
707static void mv_u3d_ep_fifo_flush(struct usb_ep *_ep)
708{
709 struct mv_u3d *u3d;
710 u32 direction;
711 struct mv_u3d_ep *ep = container_of(_ep, struct mv_u3d_ep, ep);
712 unsigned int loops;
713 u32 tmp;
714
715 /* if endpoint is not enabled, cannot flush endpoint */
716 if (!ep->enabled)
717 return;
718
719 u3d = ep->u3d;
720 direction = mv_u3d_ep_dir(ep);
721
722 /* ep0 need clear bit after flushing fifo. */
723 if (!ep->ep_num) {
724 if (direction == MV_U3D_EP_DIR_OUT) {
725 tmp = ioread32(&u3d->vuc_regs->epcr[0].epxoutcr0);
726 tmp |= MV_U3D_EPXCR_EP_FLUSH;
727 iowrite32(tmp, &u3d->vuc_regs->epcr[0].epxoutcr0);
728 udelay(10);
729 tmp &= ~MV_U3D_EPXCR_EP_FLUSH;
730 iowrite32(tmp, &u3d->vuc_regs->epcr[0].epxoutcr0);
731 } else {
732 tmp = ioread32(&u3d->vuc_regs->epcr[0].epxincr0);
733 tmp |= MV_U3D_EPXCR_EP_FLUSH;
734 iowrite32(tmp, &u3d->vuc_regs->epcr[0].epxincr0);
735 udelay(10);
736 tmp &= ~MV_U3D_EPXCR_EP_FLUSH;
737 iowrite32(tmp, &u3d->vuc_regs->epcr[0].epxincr0);
738 }
739 return;
740 }
741
742 if (direction == MV_U3D_EP_DIR_OUT) {
743 tmp = ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxoutcr0);
744 tmp |= MV_U3D_EPXCR_EP_FLUSH;
745 iowrite32(tmp, &u3d->vuc_regs->epcr[ep->ep_num].epxoutcr0);
746
747 /* Wait until flushing completed */
748 loops = LOOPS(MV_U3D_FLUSH_TIMEOUT);
749 while (ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxoutcr0) &
750 MV_U3D_EPXCR_EP_FLUSH) {
751 /*
752 * EP_FLUSH bit should be cleared to indicate this
753 * operation is complete
754 */
755 if (loops == 0) {
756 dev_dbg(u3d->dev,
757 "EP FLUSH TIMEOUT for ep%d%s\n", ep->ep_num,
758 direction ? "in" : "out");
759 return;
760 }
761 loops--;
762 udelay(LOOPS_USEC);
763 }
764 } else { /* EP_DIR_IN */
765 tmp = ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxincr0);
766 tmp |= MV_U3D_EPXCR_EP_FLUSH;
767 iowrite32(tmp, &u3d->vuc_regs->epcr[ep->ep_num].epxincr0);
768
769 /* Wait until flushing completed */
770 loops = LOOPS(MV_U3D_FLUSH_TIMEOUT);
771 while (ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxincr0) &
772 MV_U3D_EPXCR_EP_FLUSH) {
773 /*
774 * EP_FLUSH bit should be cleared to indicate this
775 * operation is complete
776 */
777 if (loops == 0) {
778 dev_dbg(u3d->dev,
779 "EP FLUSH TIMEOUT for ep%d%s\n", ep->ep_num,
780 direction ? "in" : "out");
781 return;
782 }
783 loops--;
784 udelay(LOOPS_USEC);
785 }
786 }
787}
788
789/* queues (submits) an I/O request to an endpoint */
790static int
791mv_u3d_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
792{
793 struct mv_u3d_ep *ep;
794 struct mv_u3d_req *req;
795 struct mv_u3d *u3d;
796 unsigned long flags;
797 int is_first_req = 0;
798
799 if (unlikely(!_ep || !_req))
800 return -EINVAL;
801
802 ep = container_of(_ep, struct mv_u3d_ep, ep);
803 u3d = ep->u3d;
804
805 req = container_of(_req, struct mv_u3d_req, req);
806
807 if (!ep->ep_num
808 && u3d->ep0_state == MV_U3D_STATUS_STAGE
809 && !_req->length) {
810 dev_dbg(u3d->dev, "ep0 status stage\n");
811 u3d->ep0_state = MV_U3D_WAIT_FOR_SETUP;
812 return 0;
813 }
814
815 dev_dbg(u3d->dev, "%s: %s, req: 0x%x\n",
816 __func__, _ep->name, (u32)req);
817
818 /* catch various bogus parameters */
819 if (!req->req.complete || !req->req.buf
820 || !list_empty(&req->queue)) {
821 dev_err(u3d->dev,
822 "%s, bad params, _req: 0x%x,"
823 "req->req.complete: 0x%x, req->req.buf: 0x%x,"
824 "list_empty: 0x%x\n",
825 __func__, (u32)_req,
826 (u32)req->req.complete, (u32)req->req.buf,
827 (u32)list_empty(&req->queue));
828 return -EINVAL;
829 }
830 if (unlikely(!ep->ep.desc)) {
831 dev_err(u3d->dev, "%s, bad ep\n", __func__);
832 return -EINVAL;
833 }
834 if (ep->ep.desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
835 if (req->req.length > ep->ep.maxpacket)
836 return -EMSGSIZE;
837 }
838
839 if (!u3d->driver || u3d->gadget.speed == USB_SPEED_UNKNOWN) {
840 dev_err(u3d->dev,
841 "bad params of driver/speed\n");
842 return -ESHUTDOWN;
843 }
844
845 req->ep = ep;
846
847 /* Software list handles usb request. */
848 spin_lock_irqsave(&ep->req_lock, flags);
849 is_first_req = list_empty(&ep->req_list);
850 list_add_tail(&req->list, &ep->req_list);
851 spin_unlock_irqrestore(&ep->req_lock, flags);
852 if (!is_first_req) {
853 dev_dbg(u3d->dev, "list is not empty\n");
854 return 0;
855 }
856
857 dev_dbg(u3d->dev, "call mv_u3d_start_queue from usb_ep_queue\n");
858 spin_lock_irqsave(&u3d->lock, flags);
859 mv_u3d_start_queue(ep);
860 spin_unlock_irqrestore(&u3d->lock, flags);
861 return 0;
862}
863
864/* dequeues (cancels, unlinks) an I/O request from an endpoint */
865static int mv_u3d_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
866{
867 struct mv_u3d_ep *ep;
868 struct mv_u3d_req *req;
869 struct mv_u3d *u3d;
870 struct mv_u3d_ep_context *ep_context;
871 struct mv_u3d_req *next_req;
872
873 unsigned long flags;
874 int ret = 0;
875
876 if (!_ep || !_req)
877 return -EINVAL;
878
879 ep = container_of(_ep, struct mv_u3d_ep, ep);
880 u3d = ep->u3d;
881
882 spin_lock_irqsave(&ep->u3d->lock, flags);
883
884 /* make sure it's actually queued on this endpoint */
885 list_for_each_entry(req, &ep->queue, queue) {
886 if (&req->req == _req)
887 break;
888 }
889 if (&req->req != _req) {
890 ret = -EINVAL;
891 goto out;
892 }
893
894 /* The request is in progress, or completed but not dequeued */
895 if (ep->queue.next == &req->queue) {
896 _req->status = -ECONNRESET;
897 mv_u3d_ep_fifo_flush(_ep);
898
899 /* The request isn't the last request in this ep queue */
900 if (req->queue.next != &ep->queue) {
901 dev_dbg(u3d->dev,
902 "it is the last request in this ep queue\n");
903 ep_context = ep->ep_context;
904 next_req = list_entry(req->queue.next,
905 struct mv_u3d_req, queue);
906
907 /* Point first TRB of next request to the EP context. */
908 iowrite32((u32) next_req->trb_head,
909 &ep_context->trb_addr_lo);
910 } else {
911 struct mv_u3d_ep_context *ep_context;
912 ep_context = ep->ep_context;
913 ep_context->trb_addr_lo = 0;
914 ep_context->trb_addr_hi = 0;
915 }
916
917 } else
918 WARN_ON(1);
919
920 mv_u3d_done(ep, req, -ECONNRESET);
921
922 /* remove the req from the ep req list */
923 if (!list_empty(&ep->req_list)) {
924 struct mv_u3d_req *curr_req;
925 curr_req = list_entry(ep->req_list.next,
926 struct mv_u3d_req, list);
927 if (curr_req == req) {
928 list_del_init(&req->list);
929 ep->processing = 0;
930 }
931 }
932
933out:
934 spin_unlock_irqrestore(&ep->u3d->lock, flags);
935 return ret;
936}
937
938static void
939mv_u3d_ep_set_stall(struct mv_u3d *u3d, u8 ep_num, u8 direction, int stall)
940{
941 u32 tmp;
942 struct mv_u3d_ep *ep = u3d->eps;
943
944 dev_dbg(u3d->dev, "%s\n", __func__);
945 if (direction == MV_U3D_EP_DIR_OUT) {
946 tmp = ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxoutcr0);
947 if (stall)
948 tmp |= MV_U3D_EPXCR_EP_HALT;
949 else
950 tmp &= ~MV_U3D_EPXCR_EP_HALT;
951 iowrite32(tmp, &u3d->vuc_regs->epcr[ep->ep_num].epxoutcr0);
952 } else {
953 tmp = ioread32(&u3d->vuc_regs->epcr[ep->ep_num].epxincr0);
954 if (stall)
955 tmp |= MV_U3D_EPXCR_EP_HALT;
956 else
957 tmp &= ~MV_U3D_EPXCR_EP_HALT;
958 iowrite32(tmp, &u3d->vuc_regs->epcr[ep->ep_num].epxincr0);
959 }
960}
961
962static int mv_u3d_ep_set_halt_wedge(struct usb_ep *_ep, int halt, int wedge)
963{
964 struct mv_u3d_ep *ep;
965 unsigned long flags = 0;
966 int status = 0;
967 struct mv_u3d *u3d;
968
969 ep = container_of(_ep, struct mv_u3d_ep, ep);
970 u3d = ep->u3d;
971 if (!ep->ep.desc) {
972 status = -EINVAL;
973 goto out;
974 }
975
976 if (ep->ep.desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
977 status = -EOPNOTSUPP;
978 goto out;
979 }
980
981 /*
982 * Attempt to halt IN ep will fail if any transfer requests
983 * are still queue
984 */
985 if (halt && (mv_u3d_ep_dir(ep) == MV_U3D_EP_DIR_IN)
986 && !list_empty(&ep->queue)) {
987 status = -EAGAIN;
988 goto out;
989 }
990
991 spin_lock_irqsave(&ep->u3d->lock, flags);
992 mv_u3d_ep_set_stall(u3d, ep->ep_num, mv_u3d_ep_dir(ep), halt);
993 if (halt && wedge)
994 ep->wedge = 1;
995 else if (!halt)
996 ep->wedge = 0;
997 spin_unlock_irqrestore(&ep->u3d->lock, flags);
998
999 if (ep->ep_num == 0)
1000 u3d->ep0_dir = MV_U3D_EP_DIR_OUT;
1001out:
1002 return status;
1003}
1004
1005static int mv_u3d_ep_set_halt(struct usb_ep *_ep, int halt)
1006{
1007 return mv_u3d_ep_set_halt_wedge(_ep, halt, 0);
1008}
1009
1010static int mv_u3d_ep_set_wedge(struct usb_ep *_ep)
1011{
1012 return mv_u3d_ep_set_halt_wedge(_ep, 1, 1);
1013}
1014
1015static struct usb_ep_ops mv_u3d_ep_ops = {
1016 .enable = mv_u3d_ep_enable,
1017 .disable = mv_u3d_ep_disable,
1018
1019 .alloc_request = mv_u3d_alloc_request,
1020 .free_request = mv_u3d_free_request,
1021
1022 .queue = mv_u3d_ep_queue,
1023 .dequeue = mv_u3d_ep_dequeue,
1024
1025 .set_wedge = mv_u3d_ep_set_wedge,
1026 .set_halt = mv_u3d_ep_set_halt,
1027 .fifo_flush = mv_u3d_ep_fifo_flush,
1028};
1029
1030static void mv_u3d_controller_stop(struct mv_u3d *u3d)
1031{
1032 u32 tmp;
1033
1034 if (!u3d->clock_gating && u3d->vbus_valid_detect)
1035 iowrite32(MV_U3D_INTR_ENABLE_VBUS_VALID,
1036 &u3d->vuc_regs->intrenable);
1037 else
1038 iowrite32(0, &u3d->vuc_regs->intrenable);
1039 iowrite32(~0x0, &u3d->vuc_regs->endcomplete);
1040 iowrite32(~0x0, &u3d->vuc_regs->trbunderrun);
1041 iowrite32(~0x0, &u3d->vuc_regs->trbcomplete);
1042 iowrite32(~0x0, &u3d->vuc_regs->linkchange);
1043 iowrite32(0x1, &u3d->vuc_regs->setuplock);
1044
1045 /* Reset the RUN bit in the command register to stop USB */
1046 tmp = ioread32(&u3d->op_regs->usbcmd);
1047 tmp &= ~MV_U3D_CMD_RUN_STOP;
1048 iowrite32(tmp, &u3d->op_regs->usbcmd);
1049 dev_dbg(u3d->dev, "after u3d_stop, USBCMD 0x%x\n",
1050 ioread32(&u3d->op_regs->usbcmd));
1051}
1052
1053static void mv_u3d_controller_start(struct mv_u3d *u3d)
1054{
1055 u32 usbintr;
1056 u32 temp;
1057
1058 /* enable link LTSSM state machine */
1059 temp = ioread32(&u3d->vuc_regs->ltssm);
1060 temp |= MV_U3D_LTSSM_PHY_INIT_DONE;
1061 iowrite32(temp, &u3d->vuc_regs->ltssm);
1062
1063 /* Enable interrupts */
1064 usbintr = MV_U3D_INTR_ENABLE_LINK_CHG | MV_U3D_INTR_ENABLE_TXDESC_ERR |
1065 MV_U3D_INTR_ENABLE_RXDESC_ERR | MV_U3D_INTR_ENABLE_TX_COMPLETE |
1066 MV_U3D_INTR_ENABLE_RX_COMPLETE | MV_U3D_INTR_ENABLE_SETUP |
1067 (u3d->vbus_valid_detect ? MV_U3D_INTR_ENABLE_VBUS_VALID : 0);
1068 iowrite32(usbintr, &u3d->vuc_regs->intrenable);
1069
1070 /* Enable ctrl ep */
1071 iowrite32(0x1, &u3d->vuc_regs->ctrlepenable);
1072
1073 /* Set the Run bit in the command register */
1074 iowrite32(MV_U3D_CMD_RUN_STOP, &u3d->op_regs->usbcmd);
1075 dev_dbg(u3d->dev, "after u3d_start, USBCMD 0x%x\n",
1076 ioread32(&u3d->op_regs->usbcmd));
1077}
1078
1079static int mv_u3d_controller_reset(struct mv_u3d *u3d)
1080{
1081 unsigned int loops;
1082 u32 tmp;
1083
1084 /* Stop the controller */
1085 tmp = ioread32(&u3d->op_regs->usbcmd);
1086 tmp &= ~MV_U3D_CMD_RUN_STOP;
1087 iowrite32(tmp, &u3d->op_regs->usbcmd);
1088
1089 /* Reset the controller to get default values */
1090 iowrite32(MV_U3D_CMD_CTRL_RESET, &u3d->op_regs->usbcmd);
1091
1092 /* wait for reset to complete */
1093 loops = LOOPS(MV_U3D_RESET_TIMEOUT);
1094 while (ioread32(&u3d->op_regs->usbcmd) & MV_U3D_CMD_CTRL_RESET) {
1095 if (loops == 0) {
1096 dev_err(u3d->dev,
1097 "Wait for RESET completed TIMEOUT\n");
1098 return -ETIMEDOUT;
1099 }
1100 loops--;
1101 udelay(LOOPS_USEC);
1102 }
1103
1104 /* Configure the Endpoint Context Address */
1105 iowrite32(u3d->ep_context_dma, &u3d->op_regs->dcbaapl);
1106 iowrite32(0, &u3d->op_regs->dcbaaph);
1107
1108 return 0;
1109}
1110
1111static int mv_u3d_enable(struct mv_u3d *u3d)
1112{
1113 struct mv_usb_platform_data *pdata = u3d->dev->platform_data;
1114 int retval;
1115
1116 if (u3d->active)
1117 return 0;
1118
1119 if (!u3d->clock_gating) {
1120 u3d->active = 1;
1121 return 0;
1122 }
1123
1124 dev_dbg(u3d->dev, "enable u3d\n");
1125 clk_enable(u3d->clk);
1126 if (pdata->phy_init) {
1127 retval = pdata->phy_init(u3d->phy_regs);
1128 if (retval) {
1129 dev_err(u3d->dev,
1130 "init phy error %d\n", retval);
1131 clk_disable(u3d->clk);
1132 return retval;
1133 }
1134 }
1135 u3d->active = 1;
1136
1137 return 0;
1138}
1139
1140static void mv_u3d_disable(struct mv_u3d *u3d)
1141{
1142 struct mv_usb_platform_data *pdata = u3d->dev->platform_data;
1143 if (u3d->clock_gating && u3d->active) {
1144 dev_dbg(u3d->dev, "disable u3d\n");
1145 if (pdata->phy_deinit)
1146 pdata->phy_deinit(u3d->phy_regs);
1147 clk_disable(u3d->clk);
1148 u3d->active = 0;
1149 }
1150}
1151
1152static int mv_u3d_vbus_session(struct usb_gadget *gadget, int is_active)
1153{
1154 struct mv_u3d *u3d;
1155 unsigned long flags;
1156 int retval = 0;
1157
1158 u3d = container_of(gadget, struct mv_u3d, gadget);
1159
1160 spin_lock_irqsave(&u3d->lock, flags);
1161
1162 u3d->vbus_active = (is_active != 0);
1163 dev_dbg(u3d->dev, "%s: softconnect %d, vbus_active %d\n",
1164 __func__, u3d->softconnect, u3d->vbus_active);
1165 /*
1166 * 1. external VBUS detect: we can disable/enable clock on demand.
1167 * 2. UDC VBUS detect: we have to enable clock all the time.
1168 * 3. No VBUS detect: we have to enable clock all the time.
1169 */
1170 if (u3d->driver && u3d->softconnect && u3d->vbus_active) {
1171 retval = mv_u3d_enable(u3d);
1172 if (retval == 0) {
1173 /*
1174 * after clock is disabled, we lost all the register
1175 * context. We have to re-init registers
1176 */
1177 mv_u3d_controller_reset(u3d);
1178 mv_u3d_ep0_reset(u3d);
1179 mv_u3d_controller_start(u3d);
1180 }
1181 } else if (u3d->driver && u3d->softconnect) {
1182 if (!u3d->active)
1183 goto out;
1184
1185 /* stop all the transfer in queue*/
1186 mv_u3d_stop_activity(u3d, u3d->driver);
1187 mv_u3d_controller_stop(u3d);
1188 mv_u3d_disable(u3d);
1189 }
1190
1191out:
1192 spin_unlock_irqrestore(&u3d->lock, flags);
1193 return retval;
1194}
1195
1196/* constrain controller's VBUS power usage
1197 * This call is used by gadget drivers during SET_CONFIGURATION calls,
1198 * reporting how much power the device may consume. For example, this
1199 * could affect how quickly batteries are recharged.
1200 *
1201 * Returns zero on success, else negative errno.
1202 */
1203static int mv_u3d_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1204{
1205 struct mv_u3d *u3d = container_of(gadget, struct mv_u3d, gadget);
1206
1207 u3d->power = mA;
1208
1209 return 0;
1210}
1211
1212static int mv_u3d_pullup(struct usb_gadget *gadget, int is_on)
1213{
1214 struct mv_u3d *u3d = container_of(gadget, struct mv_u3d, gadget);
1215 unsigned long flags;
1216 int retval = 0;
1217
1218 spin_lock_irqsave(&u3d->lock, flags);
1219
1220 dev_dbg(u3d->dev, "%s: softconnect %d, vbus_active %d\n",
1221 __func__, u3d->softconnect, u3d->vbus_active);
1222 u3d->softconnect = (is_on != 0);
1223 if (u3d->driver && u3d->softconnect && u3d->vbus_active) {
1224 retval = mv_u3d_enable(u3d);
1225 if (retval == 0) {
1226 /*
1227 * after clock is disabled, we lost all the register
1228 * context. We have to re-init registers
1229 */
1230 mv_u3d_controller_reset(u3d);
1231 mv_u3d_ep0_reset(u3d);
1232 mv_u3d_controller_start(u3d);
1233 }
1234 } else if (u3d->driver && u3d->vbus_active) {
1235 /* stop all the transfer in queue*/
1236 mv_u3d_stop_activity(u3d, u3d->driver);
1237 mv_u3d_controller_stop(u3d);
1238 mv_u3d_disable(u3d);
1239 }
1240
1241 spin_unlock_irqrestore(&u3d->lock, flags);
1242
1243 return retval;
1244}
1245
1246static int mv_u3d_start(struct usb_gadget *g,
1247 struct usb_gadget_driver *driver)
1248{
1249 struct mv_u3d *u3d = container_of(g, struct mv_u3d, gadget);
1250 struct mv_usb_platform_data *pdata = u3d->dev->platform_data;
1251 unsigned long flags;
1252
1253 if (u3d->driver)
1254 return -EBUSY;
1255
1256 spin_lock_irqsave(&u3d->lock, flags);
1257
1258 if (!u3d->clock_gating) {
1259 clk_enable(u3d->clk);
1260 if (pdata->phy_init)
1261 pdata->phy_init(u3d->phy_regs);
1262 }
1263
1264 /* hook up the driver ... */
1265 driver->driver.bus = NULL;
1266 u3d->driver = driver;
1267 u3d->gadget.dev.driver = &driver->driver;
1268
1269 u3d->ep0_dir = USB_DIR_OUT;
1270
1271 spin_unlock_irqrestore(&u3d->lock, flags);
1272
1273 u3d->vbus_valid_detect = 1;
1274
1275 return 0;
1276}
1277
1278static int mv_u3d_stop(struct usb_gadget *g,
1279 struct usb_gadget_driver *driver)
1280{
1281 struct mv_u3d *u3d = container_of(g, struct mv_u3d, gadget);
1282 struct mv_usb_platform_data *pdata = u3d->dev->platform_data;
1283 unsigned long flags;
1284
1285 u3d->vbus_valid_detect = 0;
1286 spin_lock_irqsave(&u3d->lock, flags);
1287
1288 /* enable clock to access controller register */
1289 clk_enable(u3d->clk);
1290 if (pdata->phy_init)
1291 pdata->phy_init(u3d->phy_regs);
1292
1293 mv_u3d_controller_stop(u3d);
1294 /* stop all usb activities */
1295 u3d->gadget.speed = USB_SPEED_UNKNOWN;
1296 mv_u3d_stop_activity(u3d, driver);
1297 mv_u3d_disable(u3d);
1298
1299 if (pdata->phy_deinit)
1300 pdata->phy_deinit(u3d->phy_regs);
1301 clk_disable(u3d->clk);
1302
1303 spin_unlock_irqrestore(&u3d->lock, flags);
1304
1305 u3d->gadget.dev.driver = NULL;
1306 u3d->driver = NULL;
1307
1308 return 0;
1309}
1310
1311/* device controller usb_gadget_ops structure */
1312static const struct usb_gadget_ops mv_u3d_ops = {
1313 /* notify controller that VBUS is powered or not */
1314 .vbus_session = mv_u3d_vbus_session,
1315
1316 /* constrain controller's VBUS power usage */
1317 .vbus_draw = mv_u3d_vbus_draw,
1318
1319 .pullup = mv_u3d_pullup,
1320 .udc_start = mv_u3d_start,
1321 .udc_stop = mv_u3d_stop,
1322};
1323
1324static int mv_u3d_eps_init(struct mv_u3d *u3d)
1325{
1326 struct mv_u3d_ep *ep;
1327 char name[14];
1328 int i;
1329
1330 /* initialize ep0, ep0 in/out use eps[1] */
1331 ep = &u3d->eps[1];
1332 ep->u3d = u3d;
1333 strncpy(ep->name, "ep0", sizeof(ep->name));
1334 ep->ep.name = ep->name;
1335 ep->ep.ops = &mv_u3d_ep_ops;
1336 ep->wedge = 0;
1337 ep->ep.maxpacket = MV_U3D_EP0_MAX_PKT_SIZE;
1338 ep->ep_num = 0;
1339 ep->ep.desc = &mv_u3d_ep0_desc;
1340 INIT_LIST_HEAD(&ep->queue);
1341 INIT_LIST_HEAD(&ep->req_list);
1342 ep->ep_type = USB_ENDPOINT_XFER_CONTROL;
1343
1344 /* add ep0 ep_context */
1345 ep->ep_context = &u3d->ep_context[1];
1346
1347 /* initialize other endpoints */
1348 for (i = 2; i < u3d->max_eps * 2; i++) {
1349 ep = &u3d->eps[i];
1350 if (i & 1) {
1351 snprintf(name, sizeof(name), "ep%din", i >> 1);
1352 ep->direction = MV_U3D_EP_DIR_IN;
1353 } else {
1354 snprintf(name, sizeof(name), "ep%dout", i >> 1);
1355 ep->direction = MV_U3D_EP_DIR_OUT;
1356 }
1357 ep->u3d = u3d;
1358 strncpy(ep->name, name, sizeof(ep->name));
1359 ep->ep.name = ep->name;
1360
1361 ep->ep.ops = &mv_u3d_ep_ops;
1362 ep->ep.maxpacket = (unsigned short) ~0;
1363 ep->ep_num = i / 2;
1364
1365 INIT_LIST_HEAD(&ep->queue);
1366 list_add_tail(&ep->ep.ep_list, &u3d->gadget.ep_list);
1367
1368 INIT_LIST_HEAD(&ep->req_list);
1369 spin_lock_init(&ep->req_lock);
1370 ep->ep_context = &u3d->ep_context[i];
1371 }
1372
1373 return 0;
1374}
1375
1376/* delete all endpoint requests, called with spinlock held */
1377static void mv_u3d_nuke(struct mv_u3d_ep *ep, int status)
1378{
1379 /* endpoint fifo flush */
1380 mv_u3d_ep_fifo_flush(&ep->ep);
1381
1382 while (!list_empty(&ep->queue)) {
1383 struct mv_u3d_req *req = NULL;
1384 req = list_entry(ep->queue.next, struct mv_u3d_req, queue);
1385 mv_u3d_done(ep, req, status);
1386 }
1387}
1388
1389/* stop all USB activities */
1390static
1391void mv_u3d_stop_activity(struct mv_u3d *u3d, struct usb_gadget_driver *driver)
1392{
1393 struct mv_u3d_ep *ep;
1394
1395 mv_u3d_nuke(&u3d->eps[1], -ESHUTDOWN);
1396
1397 list_for_each_entry(ep, &u3d->gadget.ep_list, ep.ep_list) {
1398 mv_u3d_nuke(ep, -ESHUTDOWN);
1399 }
1400
1401 /* report disconnect; the driver is already quiesced */
1402 if (driver) {
1403 spin_unlock(&u3d->lock);
1404 driver->disconnect(&u3d->gadget);
1405 spin_lock(&u3d->lock);
1406 }
1407}
1408
1409static void mv_u3d_irq_process_error(struct mv_u3d *u3d)
1410{
1411 /* Increment the error count */
1412 u3d->errors++;
1413 dev_err(u3d->dev, "%s\n", __func__);
1414}
1415
1416static void mv_u3d_irq_process_link_change(struct mv_u3d *u3d)
1417{
1418 u32 linkchange;
1419
1420 linkchange = ioread32(&u3d->vuc_regs->linkchange);
1421 iowrite32(linkchange, &u3d->vuc_regs->linkchange);
1422
1423 dev_dbg(u3d->dev, "linkchange: 0x%x\n", linkchange);
1424
1425 if (linkchange & MV_U3D_LINK_CHANGE_LINK_UP) {
1426 dev_dbg(u3d->dev, "link up: ltssm state: 0x%x\n",
1427 ioread32(&u3d->vuc_regs->ltssmstate));
1428
1429 u3d->usb_state = USB_STATE_DEFAULT;
1430 u3d->ep0_dir = MV_U3D_EP_DIR_OUT;
1431 u3d->ep0_state = MV_U3D_WAIT_FOR_SETUP;
1432
1433 /* set speed */
1434 u3d->gadget.speed = USB_SPEED_SUPER;
1435 }
1436
1437 if (linkchange & MV_U3D_LINK_CHANGE_SUSPEND) {
1438 dev_dbg(u3d->dev, "link suspend\n");
1439 u3d->resume_state = u3d->usb_state;
1440 u3d->usb_state = USB_STATE_SUSPENDED;
1441 }
1442
1443 if (linkchange & MV_U3D_LINK_CHANGE_RESUME) {
1444 dev_dbg(u3d->dev, "link resume\n");
1445 u3d->usb_state = u3d->resume_state;
1446 u3d->resume_state = 0;
1447 }
1448
1449 if (linkchange & MV_U3D_LINK_CHANGE_WRESET) {
1450 dev_dbg(u3d->dev, "warm reset\n");
1451 u3d->usb_state = USB_STATE_POWERED;
1452 }
1453
1454 if (linkchange & MV_U3D_LINK_CHANGE_HRESET) {
1455 dev_dbg(u3d->dev, "hot reset\n");
1456 u3d->usb_state = USB_STATE_DEFAULT;
1457 }
1458
1459 if (linkchange & MV_U3D_LINK_CHANGE_INACT)
1460 dev_dbg(u3d->dev, "inactive\n");
1461
1462 if (linkchange & MV_U3D_LINK_CHANGE_DISABLE_AFTER_U0)
1463 dev_dbg(u3d->dev, "ss.disabled\n");
1464
1465 if (linkchange & MV_U3D_LINK_CHANGE_VBUS_INVALID) {
1466 dev_dbg(u3d->dev, "vbus invalid\n");
1467 u3d->usb_state = USB_STATE_ATTACHED;
1468 u3d->vbus_valid_detect = 1;
1469 /* if external vbus detect is not supported,
1470 * we handle it here.
1471 */
1472 if (!u3d->vbus) {
1473 spin_unlock(&u3d->lock);
1474 mv_u3d_vbus_session(&u3d->gadget, 0);
1475 spin_lock(&u3d->lock);
1476 }
1477 }
1478}
1479
1480static void mv_u3d_ch9setaddress(struct mv_u3d *u3d,
1481 struct usb_ctrlrequest *setup)
1482{
1483 u32 tmp;
1484
1485 if (u3d->usb_state != USB_STATE_DEFAULT) {
1486 dev_err(u3d->dev,
1487 "%s, cannot setaddr in this state (%d)\n",
1488 __func__, u3d->usb_state);
1489 goto err;
1490 }
1491
1492 u3d->dev_addr = (u8)setup->wValue;
1493
1494 dev_dbg(u3d->dev, "%s: 0x%x\n", __func__, u3d->dev_addr);
1495
1496 if (u3d->dev_addr > 127) {
1497 dev_err(u3d->dev,
1498 "%s, u3d address is wrong (out of range)\n", __func__);
1499 u3d->dev_addr = 0;
1500 goto err;
1501 }
1502
1503 /* update usb state */
1504 u3d->usb_state = USB_STATE_ADDRESS;
1505
1506 /* set the new address */
1507 tmp = ioread32(&u3d->vuc_regs->devaddrtiebrkr);
1508 tmp &= ~0x7F;
1509 tmp |= (u32)u3d->dev_addr;
1510 iowrite32(tmp, &u3d->vuc_regs->devaddrtiebrkr);
1511
1512 return;
1513err:
1514 mv_u3d_ep0_stall(u3d);
1515}
1516
1517static int mv_u3d_is_set_configuration(struct usb_ctrlrequest *setup)
1518{
1519 if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD)
1520 if (setup->bRequest == USB_REQ_SET_CONFIGURATION)
1521 return 1;
1522
1523 return 0;
1524}
1525
1526static void mv_u3d_handle_setup_packet(struct mv_u3d *u3d, u8 ep_num,
1527 struct usb_ctrlrequest *setup)
1528{
1529 bool delegate = false;
1530
1531 mv_u3d_nuke(&u3d->eps[ep_num * 2 + MV_U3D_EP_DIR_IN], -ESHUTDOWN);
1532
1533 dev_dbg(u3d->dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1534 setup->bRequestType, setup->bRequest,
1535 setup->wValue, setup->wIndex, setup->wLength);
1536
1537 /* We process some stardard setup requests here */
1538 if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
1539 switch (setup->bRequest) {
1540 case USB_REQ_GET_STATUS:
1541 delegate = true;
1542 break;
1543
1544 case USB_REQ_SET_ADDRESS:
1545 mv_u3d_ch9setaddress(u3d, setup);
1546 break;
1547
1548 case USB_REQ_CLEAR_FEATURE:
1549 delegate = true;
1550 break;
1551
1552 case USB_REQ_SET_FEATURE:
1553 delegate = true;
1554 break;
1555
1556 default:
1557 delegate = true;
1558 }
1559 } else
1560 delegate = true;
1561
1562 /* delegate USB standard requests to the gadget driver */
1563 if (delegate == true) {
1564 /* USB requests handled by gadget */
1565 if (setup->wLength) {
1566 /* DATA phase from gadget, STATUS phase from u3d */
1567 u3d->ep0_dir = (setup->bRequestType & USB_DIR_IN)
1568 ? MV_U3D_EP_DIR_IN : MV_U3D_EP_DIR_OUT;
1569 spin_unlock(&u3d->lock);
1570 if (u3d->driver->setup(&u3d->gadget,
1571 &u3d->local_setup_buff) < 0) {
1572 dev_err(u3d->dev, "setup error!\n");
1573 mv_u3d_ep0_stall(u3d);
1574 }
1575 spin_lock(&u3d->lock);
1576 } else {
1577 /* no DATA phase, STATUS phase from gadget */
1578 u3d->ep0_dir = MV_U3D_EP_DIR_IN;
1579 u3d->ep0_state = MV_U3D_STATUS_STAGE;
1580 spin_unlock(&u3d->lock);
1581 if (u3d->driver->setup(&u3d->gadget,
1582 &u3d->local_setup_buff) < 0)
1583 mv_u3d_ep0_stall(u3d);
1584 spin_lock(&u3d->lock);
1585 }
1586
1587 if (mv_u3d_is_set_configuration(setup)) {
1588 dev_dbg(u3d->dev, "u3d configured\n");
1589 u3d->usb_state = USB_STATE_CONFIGURED;
1590 }
1591 }
1592}
1593
1594static void mv_u3d_get_setup_data(struct mv_u3d *u3d, u8 ep_num, u8 *buffer_ptr)
1595{
1596 struct mv_u3d_ep_context *epcontext;
1597
1598 epcontext = &u3d->ep_context[ep_num * 2 + MV_U3D_EP_DIR_IN];
1599
1600 /* Copy the setup packet to local buffer */
1601 memcpy(buffer_ptr, (u8 *) &epcontext->setup_buffer, 8);
1602}
1603
1604static void mv_u3d_irq_process_setup(struct mv_u3d *u3d)
1605{
1606 u32 tmp, i;
1607 /* Process all Setup packet received interrupts */
1608 tmp = ioread32(&u3d->vuc_regs->setuplock);
1609 if (tmp) {
1610 for (i = 0; i < u3d->max_eps; i++) {
1611 if (tmp & (1 << i)) {
1612 mv_u3d_get_setup_data(u3d, i,
1613 (u8 *)(&u3d->local_setup_buff));
1614 mv_u3d_handle_setup_packet(u3d, i,
1615 &u3d->local_setup_buff);
1616 }
1617 }
1618 }
1619
1620 iowrite32(tmp, &u3d->vuc_regs->setuplock);
1621}
1622
1623static void mv_u3d_irq_process_tr_complete(struct mv_u3d *u3d)
1624{
1625 u32 tmp, bit_pos;
1626 int i, ep_num = 0, direction = 0;
1627 struct mv_u3d_ep *curr_ep;
1628 struct mv_u3d_req *curr_req, *temp_req;
1629 int status;
1630
1631 tmp = ioread32(&u3d->vuc_regs->endcomplete);
1632
1633 dev_dbg(u3d->dev, "tr_complete: ep: 0x%x\n", tmp);
1634 if (!tmp)
1635 return;
1636 iowrite32(tmp, &u3d->vuc_regs->endcomplete);
1637
1638 for (i = 0; i < u3d->max_eps * 2; i++) {
1639 ep_num = i >> 1;
1640 direction = i % 2;
1641
1642 bit_pos = 1 << (ep_num + 16 * direction);
1643
1644 if (!(bit_pos & tmp))
1645 continue;
1646
1647 if (i == 0)
1648 curr_ep = &u3d->eps[1];
1649 else
1650 curr_ep = &u3d->eps[i];
1651
1652 /* remove req out of ep request list after completion */
1653 dev_dbg(u3d->dev, "tr comp: check req_list\n");
1654 spin_lock(&curr_ep->req_lock);
1655 if (!list_empty(&curr_ep->req_list)) {
1656 struct mv_u3d_req *req;
1657 req = list_entry(curr_ep->req_list.next,
1658 struct mv_u3d_req, list);
1659 list_del_init(&req->list);
1660 curr_ep->processing = 0;
1661 }
1662 spin_unlock(&curr_ep->req_lock);
1663
1664 /* process the req queue until an uncomplete request */
1665 list_for_each_entry_safe(curr_req, temp_req,
1666 &curr_ep->queue, queue) {
1667 status = mv_u3d_process_ep_req(u3d, i, curr_req);
1668 if (status)
1669 break;
1670 /* write back status to req */
1671 curr_req->req.status = status;
1672
1673 /* ep0 request completion */
1674 if (ep_num == 0) {
1675 mv_u3d_done(curr_ep, curr_req, 0);
1676 break;
1677 } else {
1678 mv_u3d_done(curr_ep, curr_req, status);
1679 }
1680 }
1681
1682 dev_dbg(u3d->dev, "call mv_u3d_start_queue from ep complete\n");
1683 mv_u3d_start_queue(curr_ep);
1684 }
1685}
1686
1687static irqreturn_t mv_u3d_irq(int irq, void *dev)
1688{
1689 struct mv_u3d *u3d = (struct mv_u3d *)dev;
1690 u32 status, intr;
1691 u32 bridgesetting;
1692 u32 trbunderrun;
1693
1694 spin_lock(&u3d->lock);
1695
1696 status = ioread32(&u3d->vuc_regs->intrcause);
1697 intr = ioread32(&u3d->vuc_regs->intrenable);
1698 status &= intr;
1699
1700 if (status == 0) {
1701 spin_unlock(&u3d->lock);
1702 dev_err(u3d->dev, "irq error!\n");
1703 return IRQ_NONE;
1704 }
1705
1706 if (status & MV_U3D_USBINT_VBUS_VALID) {
1707 bridgesetting = ioread32(&u3d->vuc_regs->bridgesetting);
1708 if (bridgesetting & MV_U3D_BRIDGE_SETTING_VBUS_VALID) {
1709 /* write vbus valid bit of bridge setting to clear */
1710 bridgesetting = MV_U3D_BRIDGE_SETTING_VBUS_VALID;
1711 iowrite32(bridgesetting, &u3d->vuc_regs->bridgesetting);
1712 dev_dbg(u3d->dev, "vbus valid\n");
1713
1714 u3d->usb_state = USB_STATE_POWERED;
1715 u3d->vbus_valid_detect = 0;
1716 /* if external vbus detect is not supported,
1717 * we handle it here.
1718 */
1719 if (!u3d->vbus) {
1720 spin_unlock(&u3d->lock);
1721 mv_u3d_vbus_session(&u3d->gadget, 1);
1722 spin_lock(&u3d->lock);
1723 }
1724 } else
1725 dev_err(u3d->dev, "vbus bit is not set\n");
1726 }
1727
1728 /* RX data is already in the 16KB FIFO.*/
1729 if (status & MV_U3D_USBINT_UNDER_RUN) {
1730 trbunderrun = ioread32(&u3d->vuc_regs->trbunderrun);
1731 dev_err(u3d->dev, "under run, ep%d\n", trbunderrun);
1732 iowrite32(trbunderrun, &u3d->vuc_regs->trbunderrun);
1733 mv_u3d_irq_process_error(u3d);
1734 }
1735
1736 if (status & (MV_U3D_USBINT_RXDESC_ERR | MV_U3D_USBINT_TXDESC_ERR)) {
1737 /* write one to clear */
1738 iowrite32(status & (MV_U3D_USBINT_RXDESC_ERR
1739 | MV_U3D_USBINT_TXDESC_ERR),
1740 &u3d->vuc_regs->intrcause);
1741 dev_err(u3d->dev, "desc err 0x%x\n", status);
1742 mv_u3d_irq_process_error(u3d);
1743 }
1744
1745 if (status & MV_U3D_USBINT_LINK_CHG)
1746 mv_u3d_irq_process_link_change(u3d);
1747
1748 if (status & MV_U3D_USBINT_TX_COMPLETE)
1749 mv_u3d_irq_process_tr_complete(u3d);
1750
1751 if (status & MV_U3D_USBINT_RX_COMPLETE)
1752 mv_u3d_irq_process_tr_complete(u3d);
1753
1754 if (status & MV_U3D_USBINT_SETUP)
1755 mv_u3d_irq_process_setup(u3d);
1756
1757 spin_unlock(&u3d->lock);
1758 return IRQ_HANDLED;
1759}
1760
1761static void mv_u3d_gadget_release(struct device *dev)
1762{
1763 dev_dbg(dev, "%s\n", __func__);
1764}
1765
1766static __devexit int mv_u3d_remove(struct platform_device *dev)
1767{
1768 struct mv_u3d *u3d = platform_get_drvdata(dev);
1769
1770 BUG_ON(u3d == NULL);
1771
1772 usb_del_gadget_udc(&u3d->gadget);
1773
1774 /* free memory allocated in probe */
1775 if (u3d->trb_pool)
1776 dma_pool_destroy(u3d->trb_pool);
1777
1778 if (u3d->ep_context)
1779 dma_free_coherent(&dev->dev, u3d->ep_context_size,
1780 u3d->ep_context, u3d->ep_context_dma);
1781
1782 kfree(u3d->eps);
1783
1784 if (u3d->irq)
1785 free_irq(u3d->irq, &dev->dev);
1786
1787 if (u3d->cap_regs)
1788 iounmap(u3d->cap_regs);
1789 u3d->cap_regs = NULL;
1790
1791 kfree(u3d->status_req);
1792
1793 clk_put(u3d->clk);
1794
1795 device_unregister(&u3d->gadget.dev);
1796
1797 platform_set_drvdata(dev, NULL);
1798
1799 kfree(u3d);
1800
1801 return 0;
1802}
1803
1804static int mv_u3d_probe(struct platform_device *dev)
1805{
1806 struct mv_u3d *u3d = NULL;
1807 struct mv_usb_platform_data *pdata = dev->dev.platform_data;
1808 int retval = 0;
1809 struct resource *r;
1810 size_t size;
1811
1812 if (!dev->dev.platform_data) {
1813 dev_err(&dev->dev, "missing platform_data\n");
1814 retval = -ENODEV;
1815 goto err_pdata;
1816 }
1817
1818 u3d = kzalloc(sizeof(*u3d), GFP_KERNEL);
1819 if (!u3d) {
1820 dev_err(&dev->dev, "failed to allocate memory for u3d\n");
1821 retval = -ENOMEM;
1822 goto err_alloc_private;
1823 }
1824
1825 spin_lock_init(&u3d->lock);
1826
1827 platform_set_drvdata(dev, u3d);
1828
1829 u3d->dev = &dev->dev;
1830 u3d->vbus = pdata->vbus;
1831
1832 u3d->clk = clk_get(&dev->dev, pdata->clkname[0]);
1833 if (IS_ERR(u3d->clk)) {
1834 retval = PTR_ERR(u3d->clk);
1835 goto err_get_clk;
1836 }
1837
1838 r = platform_get_resource_byname(dev, IORESOURCE_MEM, "capregs");
1839 if (!r) {
1840 dev_err(&dev->dev, "no I/O memory resource defined\n");
1841 retval = -ENODEV;
1842 goto err_get_cap_regs;
1843 }
1844
1845 u3d->cap_regs = (struct mv_u3d_cap_regs __iomem *)
1846 ioremap(r->start, resource_size(r));
1847 if (!u3d->cap_regs) {
1848 dev_err(&dev->dev, "failed to map I/O memory\n");
1849 retval = -EBUSY;
1850 goto err_map_cap_regs;
1851 } else {
1852 dev_dbg(&dev->dev, "cap_regs address: 0x%x/0x%x\n",
1853 (unsigned int)r->start, (unsigned int)u3d->cap_regs);
1854 }
1855
1856 /* we will access controller register, so enable the u3d controller */
1857 clk_enable(u3d->clk);
1858
1859 if (pdata->phy_init) {
1860 retval = pdata->phy_init(u3d->phy_regs);
1861 if (retval) {
1862 dev_err(&dev->dev, "init phy error %d\n", retval);
1863 goto err_u3d_enable;
1864 }
1865 }
1866
1867 u3d->op_regs = (struct mv_u3d_op_regs __iomem *)((u32)u3d->cap_regs
1868 + MV_U3D_USB3_OP_REGS_OFFSET);
1869
1870 u3d->vuc_regs = (struct mv_u3d_vuc_regs __iomem *)((u32)u3d->cap_regs
1871 + ioread32(&u3d->cap_regs->vuoff));
1872
1873 u3d->max_eps = 16;
1874
1875 /*
1876 * some platform will use usb to download image, it may not disconnect
1877 * usb gadget before loading kernel. So first stop u3d here.
1878 */
1879 mv_u3d_controller_stop(u3d);
1880 iowrite32(0xFFFFFFFF, &u3d->vuc_regs->intrcause);
1881
1882 if (pdata->phy_deinit)
1883 pdata->phy_deinit(u3d->phy_regs);
1884 clk_disable(u3d->clk);
1885
1886 size = u3d->max_eps * sizeof(struct mv_u3d_ep_context) * 2;
1887 size = (size + MV_U3D_EP_CONTEXT_ALIGNMENT - 1)
1888 & ~(MV_U3D_EP_CONTEXT_ALIGNMENT - 1);
1889 u3d->ep_context = dma_alloc_coherent(&dev->dev, size,
1890 &u3d->ep_context_dma, GFP_KERNEL);
1891 if (!u3d->ep_context) {
1892 dev_err(&dev->dev, "allocate ep context memory failed\n");
1893 retval = -ENOMEM;
1894 goto err_alloc_ep_context;
1895 }
1896 u3d->ep_context_size = size;
1897
1898 /* create TRB dma_pool resource */
1899 u3d->trb_pool = dma_pool_create("u3d_trb",
1900 &dev->dev,
1901 sizeof(struct mv_u3d_trb_hw),
1902 MV_U3D_TRB_ALIGNMENT,
1903 MV_U3D_DMA_BOUNDARY);
1904
1905 if (!u3d->trb_pool) {
1906 retval = -ENOMEM;
1907 goto err_alloc_trb_pool;
1908 }
1909
1910 size = u3d->max_eps * sizeof(struct mv_u3d_ep) * 2;
1911 u3d->eps = kzalloc(size, GFP_KERNEL);
1912 if (!u3d->eps) {
1913 dev_err(&dev->dev, "allocate ep memory failed\n");
1914 retval = -ENOMEM;
1915 goto err_alloc_eps;
1916 }
1917
1918 /* initialize ep0 status request structure */
1919 u3d->status_req = kzalloc(sizeof(struct mv_u3d_req) + 8, GFP_KERNEL);
1920 if (!u3d->status_req) {
1921 dev_err(&dev->dev, "allocate status_req memory failed\n");
1922 retval = -ENOMEM;
1923 goto err_alloc_status_req;
1924 }
1925 INIT_LIST_HEAD(&u3d->status_req->queue);
1926
1927 /* allocate a small amount of memory to get valid address */
1928 u3d->status_req->req.buf = (char *)u3d->status_req
1929 + sizeof(struct mv_u3d_req);
1930 u3d->status_req->req.dma = virt_to_phys(u3d->status_req->req.buf);
1931
1932 u3d->resume_state = USB_STATE_NOTATTACHED;
1933 u3d->usb_state = USB_STATE_ATTACHED;
1934 u3d->ep0_dir = MV_U3D_EP_DIR_OUT;
1935 u3d->remote_wakeup = 0;
1936
1937 r = platform_get_resource(dev, IORESOURCE_IRQ, 0);
1938 if (!r) {
1939 dev_err(&dev->dev, "no IRQ resource defined\n");
1940 retval = -ENODEV;
1941 goto err_get_irq;
1942 }
1943 u3d->irq = r->start;
1944 if (request_irq(u3d->irq, mv_u3d_irq,
1945 IRQF_DISABLED | IRQF_SHARED, driver_name, u3d)) {
1946 u3d->irq = 0;
1947 dev_err(&dev->dev, "Request irq %d for u3d failed\n",
1948 u3d->irq);
1949 retval = -ENODEV;
1950 goto err_request_irq;
1951 }
1952
1953 /* initialize gadget structure */
1954 u3d->gadget.ops = &mv_u3d_ops; /* usb_gadget_ops */
1955 u3d->gadget.ep0 = &u3d->eps[1].ep; /* gadget ep0 */
1956 INIT_LIST_HEAD(&u3d->gadget.ep_list); /* ep_list */
1957 u3d->gadget.speed = USB_SPEED_UNKNOWN; /* speed */
1958
1959 /* the "gadget" abstracts/virtualizes the controller */
1960 dev_set_name(&u3d->gadget.dev, "gadget");
1961 u3d->gadget.dev.parent = &dev->dev;
1962 u3d->gadget.dev.dma_mask = dev->dev.dma_mask;
1963 u3d->gadget.dev.release = mv_u3d_gadget_release;
1964 u3d->gadget.name = driver_name; /* gadget name */
1965
1966 retval = device_register(&u3d->gadget.dev);
1967 if (retval)
1968 goto err_register_gadget_device;
1969
1970 mv_u3d_eps_init(u3d);
1971
1972 /* external vbus detection */
1973 if (u3d->vbus) {
1974 u3d->clock_gating = 1;
1975 dev_err(&dev->dev, "external vbus detection\n");
1976 }
1977
1978 if (!u3d->clock_gating)
1979 u3d->vbus_active = 1;
1980
1981 /* enable usb3 controller vbus detection */
1982 u3d->vbus_valid_detect = 1;
1983
1984 retval = usb_add_gadget_udc(&dev->dev, &u3d->gadget);
1985 if (retval)
1986 goto err_unregister;
1987
1988 dev_dbg(&dev->dev, "successful probe usb3 device %s clock gating.\n",
1989 u3d->clock_gating ? "with" : "without");
1990
1991 return 0;
1992
1993err_unregister:
1994 device_unregister(&u3d->gadget.dev);
1995err_register_gadget_device:
1996 free_irq(u3d->irq, &dev->dev);
1997err_request_irq:
1998err_get_irq:
1999 kfree(u3d->status_req);
2000err_alloc_status_req:
2001 kfree(u3d->eps);
2002err_alloc_eps:
2003 dma_pool_destroy(u3d->trb_pool);
2004err_alloc_trb_pool:
2005 dma_free_coherent(&dev->dev, u3d->ep_context_size,
2006 u3d->ep_context, u3d->ep_context_dma);
2007err_alloc_ep_context:
2008 if (pdata->phy_deinit)
2009 pdata->phy_deinit(u3d->phy_regs);
2010 clk_disable(u3d->clk);
2011err_u3d_enable:
2012 iounmap(u3d->cap_regs);
2013err_map_cap_regs:
2014err_get_cap_regs:
2015err_get_clk:
2016 clk_put(u3d->clk);
2017 platform_set_drvdata(dev, NULL);
2018 kfree(u3d);
2019err_alloc_private:
2020err_pdata:
2021 return retval;
2022}
2023
2024#ifdef CONFIG_PM
2025static int mv_u3d_suspend(struct device *dev)
2026{
2027 struct mv_u3d *u3d = dev_get_drvdata(dev);
2028
2029 /*
2030 * only cable is unplugged, usb can suspend.
2031 * So do not care about clock_gating == 1, it is handled by
2032 * vbus session.
2033 */
2034 if (!u3d->clock_gating) {
2035 mv_u3d_controller_stop(u3d);
2036
2037 spin_lock_irq(&u3d->lock);
2038 /* stop all usb activities */
2039 mv_u3d_stop_activity(u3d, u3d->driver);
2040 spin_unlock_irq(&u3d->lock);
2041
2042 mv_u3d_disable(u3d);
2043 }
2044
2045 return 0;
2046}
2047
2048static int mv_u3d_resume(struct device *dev)
2049{
2050 struct mv_u3d *u3d = dev_get_drvdata(dev);
2051 int retval;
2052
2053 if (!u3d->clock_gating) {
2054 retval = mv_u3d_enable(u3d);
2055 if (retval)
2056 return retval;
2057
2058 if (u3d->driver && u3d->softconnect) {
2059 mv_u3d_controller_reset(u3d);
2060 mv_u3d_ep0_reset(u3d);
2061 mv_u3d_controller_start(u3d);
2062 }
2063 }
2064
2065 return 0;
2066}
2067
2068SIMPLE_DEV_PM_OPS(mv_u3d_pm_ops, mv_u3d_suspend, mv_u3d_resume);
2069#endif
2070
2071static void mv_u3d_shutdown(struct platform_device *dev)
2072{
2073 struct mv_u3d *u3d = dev_get_drvdata(&dev->dev);
2074 u32 tmp;
2075
2076 tmp = ioread32(&u3d->op_regs->usbcmd);
2077 tmp &= ~MV_U3D_CMD_RUN_STOP;
2078 iowrite32(tmp, &u3d->op_regs->usbcmd);
2079}
2080
2081static struct platform_driver mv_u3d_driver = {
2082 .probe = mv_u3d_probe,
2083 .remove = __exit_p(mv_u3d_remove),
2084 .shutdown = mv_u3d_shutdown,
2085 .driver = {
2086 .owner = THIS_MODULE,
2087 .name = "mv-u3d",
2088#ifdef CONFIG_PM
2089 .pm = &mv_u3d_pm_ops,
2090#endif
2091 },
2092};
2093
2094module_platform_driver(mv_u3d_driver);
2095MODULE_ALIAS("platform:mv-u3d");
2096MODULE_DESCRIPTION(DRIVER_DESC);
2097MODULE_AUTHOR("Yu Xu <yuxu@marvell.com>");
2098MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index 117a4bba1b8c..75db2c306cea 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -19,6 +19,7 @@
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/err.h>
22#include <linux/init.h> 23#include <linux/init.h>
23#include <linux/timer.h> 24#include <linux/timer.h>
24#include <linux/list.h> 25#include <linux/list.h>
@@ -1381,7 +1382,7 @@ static int mv_udc_start(struct usb_gadget_driver *driver,
1381 return retval; 1382 return retval;
1382 } 1383 }
1383 1384
1384 if (udc->transceiver) { 1385 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1385 retval = otg_set_peripheral(udc->transceiver->otg, 1386 retval = otg_set_peripheral(udc->transceiver->otg,
1386 &udc->gadget); 1387 &udc->gadget);
1387 if (retval) { 1388 if (retval) {
@@ -2107,7 +2108,7 @@ static int __devexit mv_udc_remove(struct platform_device *dev)
2107 * then vbus irq will not be requested in udc driver. 2108 * then vbus irq will not be requested in udc driver.
2108 */ 2109 */
2109 if (udc->pdata && udc->pdata->vbus 2110 if (udc->pdata && udc->pdata->vbus
2110 && udc->clock_gating && udc->transceiver == NULL) 2111 && udc->clock_gating && IS_ERR_OR_NULL(udc->transceiver))
2111 free_irq(udc->pdata->vbus->irq, &dev->dev); 2112 free_irq(udc->pdata->vbus->irq, &dev->dev);
2112 2113
2113 /* free memory allocated in probe */ 2114 /* free memory allocated in probe */
@@ -2180,7 +2181,7 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
2180 2181
2181#ifdef CONFIG_USB_OTG_UTILS 2182#ifdef CONFIG_USB_OTG_UTILS
2182 if (pdata->mode == MV_USB_MODE_OTG) 2183 if (pdata->mode == MV_USB_MODE_OTG)
2183 udc->transceiver = usb_get_transceiver(); 2184 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2184#endif 2185#endif
2185 2186
2186 udc->clknum = pdata->clknum; 2187 udc->clknum = pdata->clknum;
@@ -2325,7 +2326,7 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
2325 eps_init(udc); 2326 eps_init(udc);
2326 2327
2327 /* VBUS detect: we can disable/enable clock on demand.*/ 2328 /* VBUS detect: we can disable/enable clock on demand.*/
2328 if (udc->transceiver) 2329 if (!IS_ERR_OR_NULL(udc->transceiver))
2329 udc->clock_gating = 1; 2330 udc->clock_gating = 1;
2330 else if (pdata->vbus) { 2331 else if (pdata->vbus) {
2331 udc->clock_gating = 1; 2332 udc->clock_gating = 1;
@@ -2369,7 +2370,7 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
2369 2370
2370err_unregister: 2371err_unregister:
2371 if (udc->pdata && udc->pdata->vbus 2372 if (udc->pdata && udc->pdata->vbus
2372 && udc->clock_gating && udc->transceiver == NULL) 2373 && udc->clock_gating && IS_ERR_OR_NULL(udc->transceiver))
2373 free_irq(pdata->vbus->irq, &dev->dev); 2374 free_irq(pdata->vbus->irq, &dev->dev);
2374 device_unregister(&udc->gadget.dev); 2375 device_unregister(&udc->gadget.dev);
2375err_free_irq: 2376err_free_irq:
@@ -2404,7 +2405,7 @@ static int mv_udc_suspend(struct device *_dev)
2404 struct mv_udc *udc = the_controller; 2405 struct mv_udc *udc = the_controller;
2405 2406
2406 /* if OTG is enabled, the following will be done in OTG driver*/ 2407 /* if OTG is enabled, the following will be done in OTG driver*/
2407 if (udc->transceiver) 2408 if (!IS_ERR_OR_NULL(udc->transceiver))
2408 return 0; 2409 return 0;
2409 2410
2410 if (udc->pdata->vbus && udc->pdata->vbus->poll) 2411 if (udc->pdata->vbus && udc->pdata->vbus->poll)
@@ -2437,7 +2438,7 @@ static int mv_udc_resume(struct device *_dev)
2437 int retval; 2438 int retval;
2438 2439
2439 /* if OTG is enabled, the following will be done in OTG driver*/ 2440 /* if OTG is enabled, the following will be done in OTG driver*/
2440 if (udc->transceiver) 2441 if (!IS_ERR_OR_NULL(udc->transceiver))
2441 return 0; 2442 return 0;
2442 2443
2443 if (!udc->clock_gating) { 2444 if (!udc->clock_gating) {
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index a460e8c204f4..d7df89e72efe 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -35,10 +35,11 @@
35#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/clk.h> 37#include <linux/clk.h>
38#include <linux/err.h>
38#include <linux/prefetch.h> 39#include <linux/prefetch.h>
40#include <linux/io.h>
39 41
40#include <asm/byteorder.h> 42#include <asm/byteorder.h>
41#include <asm/io.h>
42#include <asm/irq.h> 43#include <asm/irq.h>
43#include <asm/unaligned.h> 44#include <asm/unaligned.h>
44#include <asm/mach-types.h> 45#include <asm/mach-types.h>
@@ -59,11 +60,6 @@
59#define DRIVER_DESC "OMAP UDC driver" 60#define DRIVER_DESC "OMAP UDC driver"
60#define DRIVER_VERSION "4 October 2004" 61#define DRIVER_VERSION "4 October 2004"
61 62
62#define DMA_ADDR_INVALID (~(dma_addr_t)0)
63
64#define OMAP2_DMA_CH(ch) (((ch) - 1) << 1)
65#define OMAP24XX_DMA(name, ch) (OMAP24XX_DMA_##name + OMAP2_DMA_CH(ch))
66
67/* 63/*
68 * The OMAP UDC needs _very_ early endpoint setup: before enabling the 64 * The OMAP UDC needs _very_ early endpoint setup: before enabling the
69 * D+ pullup to allow enumeration. That's too early for the gadget 65 * D+ pullup to allow enumeration. That's too early for the gadget
@@ -87,14 +83,14 @@
87#ifdef USE_ISO 83#ifdef USE_ISO
88static unsigned fifo_mode = 3; 84static unsigned fifo_mode = 3;
89#else 85#else
90static unsigned fifo_mode = 0; 86static unsigned fifo_mode;
91#endif 87#endif
92 88
93/* "modprobe omap_udc fifo_mode=42", or else as a kernel 89/* "modprobe omap_udc fifo_mode=42", or else as a kernel
94 * boot parameter "omap_udc:fifo_mode=42" 90 * boot parameter "omap_udc:fifo_mode=42"
95 */ 91 */
96module_param (fifo_mode, uint, 0); 92module_param(fifo_mode, uint, 0);
97MODULE_PARM_DESC (fifo_mode, "endpoint configuration"); 93MODULE_PARM_DESC(fifo_mode, "endpoint configuration");
98 94
99#ifdef USE_DMA 95#ifdef USE_DMA
100static bool use_dma = 1; 96static bool use_dma = 1;
@@ -102,8 +98,8 @@ static bool use_dma = 1;
102/* "modprobe omap_udc use_dma=y", or else as a kernel 98/* "modprobe omap_udc use_dma=y", or else as a kernel
103 * boot parameter "omap_udc:use_dma=y" 99 * boot parameter "omap_udc:use_dma=y"
104 */ 100 */
105module_param (use_dma, bool, 0); 101module_param(use_dma, bool, 0);
106MODULE_PARM_DESC (use_dma, "enable/disable DMA"); 102MODULE_PARM_DESC(use_dma, "enable/disable DMA");
107#else /* !USE_DMA */ 103#else /* !USE_DMA */
108 104
109/* save a bit of code */ 105/* save a bit of code */
@@ -111,8 +107,8 @@ MODULE_PARM_DESC (use_dma, "enable/disable DMA");
111#endif /* !USE_DMA */ 107#endif /* !USE_DMA */
112 108
113 109
114static const char driver_name [] = "omap_udc"; 110static const char driver_name[] = "omap_udc";
115static const char driver_desc [] = DRIVER_DESC; 111static const char driver_desc[] = DRIVER_DESC;
116 112
117/*-------------------------------------------------------------------------*/ 113/*-------------------------------------------------------------------------*/
118 114
@@ -250,7 +246,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
250 246
251 spin_lock_irqsave(&ep->udc->lock, flags); 247 spin_lock_irqsave(&ep->udc->lock, flags);
252 ep->ep.desc = NULL; 248 ep->ep.desc = NULL;
253 nuke (ep, -ESHUTDOWN); 249 nuke(ep, -ESHUTDOWN);
254 ep->ep.maxpacket = ep->maxpacket; 250 ep->ep.maxpacket = ep->maxpacket;
255 ep->has_dma = 0; 251 ep->has_dma = 0;
256 omap_writew(UDC_SET_HALT, UDC_CTRL); 252 omap_writew(UDC_SET_HALT, UDC_CTRL);
@@ -271,10 +267,11 @@ omap_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
271 struct omap_req *req; 267 struct omap_req *req;
272 268
273 req = kzalloc(sizeof(*req), gfp_flags); 269 req = kzalloc(sizeof(*req), gfp_flags);
274 if (req) { 270 if (!req)
275 req->req.dma = DMA_ADDR_INVALID; 271 return NULL;
276 INIT_LIST_HEAD (&req->queue); 272
277 } 273 INIT_LIST_HEAD(&req->queue);
274
278 return &req->req; 275 return &req->req;
279} 276}
280 277
@@ -283,8 +280,7 @@ omap_free_request(struct usb_ep *ep, struct usb_request *_req)
283{ 280{
284 struct omap_req *req = container_of(_req, struct omap_req, req); 281 struct omap_req *req = container_of(_req, struct omap_req, req);
285 282
286 if (_req) 283 kfree(req);
287 kfree (req);
288} 284}
289 285
290/*-------------------------------------------------------------------------*/ 286/*-------------------------------------------------------------------------*/
@@ -292,6 +288,7 @@ omap_free_request(struct usb_ep *ep, struct usb_request *_req)
292static void 288static void
293done(struct omap_ep *ep, struct omap_req *req, int status) 289done(struct omap_ep *ep, struct omap_req *req, int status)
294{ 290{
291 struct omap_udc *udc = ep->udc;
295 unsigned stopped = ep->stopped; 292 unsigned stopped = ep->stopped;
296 293
297 list_del_init(&req->queue); 294 list_del_init(&req->queue);
@@ -301,22 +298,9 @@ done(struct omap_ep *ep, struct omap_req *req, int status)
301 else 298 else
302 status = req->req.status; 299 status = req->req.status;
303 300
304 if (use_dma && ep->has_dma) { 301 if (use_dma && ep->has_dma)
305 if (req->mapped) { 302 usb_gadget_unmap_request(&udc->gadget, &req->req,
306 dma_unmap_single(ep->udc->gadget.dev.parent, 303 (ep->bEndpointAddress & USB_DIR_IN));
307 req->req.dma, req->req.length,
308 (ep->bEndpointAddress & USB_DIR_IN)
309 ? DMA_TO_DEVICE
310 : DMA_FROM_DEVICE);
311 req->req.dma = DMA_ADDR_INVALID;
312 req->mapped = 0;
313 } else
314 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
315 req->req.dma, req->req.length,
316 (ep->bEndpointAddress & USB_DIR_IN)
317 ? DMA_TO_DEVICE
318 : DMA_FROM_DEVICE);
319 }
320 304
321#ifndef USB_TRACE 305#ifndef USB_TRACE
322 if (status && status != -ESHUTDOWN) 306 if (status && status != -ESHUTDOWN)
@@ -364,10 +348,10 @@ write_packet(u8 *buf, struct omap_req *req, unsigned max)
364 return len; 348 return len;
365} 349}
366 350
367// FIXME change r/w fifo calling convention 351/* FIXME change r/w fifo calling convention */
368 352
369 353
370// return: 0 = still running, 1 = completed, negative = errno 354/* return: 0 = still running, 1 = completed, negative = errno */
371static int write_fifo(struct omap_ep *ep, struct omap_req *req) 355static int write_fifo(struct omap_ep *ep, struct omap_req *req)
372{ 356{
373 u8 *buf; 357 u8 *buf;
@@ -429,7 +413,7 @@ read_packet(u8 *buf, struct omap_req *req, unsigned avail)
429 return len; 413 return len;
430} 414}
431 415
432// return: 0 = still running, 1 = queue empty, negative = errno 416/* return: 0 = still running, 1 = queue empty, negative = errno */
433static int read_fifo(struct omap_ep *ep, struct omap_req *req) 417static int read_fifo(struct omap_ep *ep, struct omap_req *req)
434{ 418{
435 u8 *buf; 419 u8 *buf;
@@ -536,12 +520,8 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
536 : OMAP_DMA_SYNC_ELEMENT; 520 : OMAP_DMA_SYNC_ELEMENT;
537 int dma_trigger = 0; 521 int dma_trigger = 0;
538 522
539 if (cpu_is_omap24xx())
540 dma_trigger = OMAP24XX_DMA(USB_W2FC_TX0, ep->dma_channel);
541
542 /* measure length in either bytes or packets */ 523 /* measure length in either bytes or packets */
543 if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC) 524 if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC)
544 || (cpu_is_omap24xx() && length < ep->maxpacket)
545 || (cpu_is_omap15xx() && length < ep->maxpacket)) { 525 || (cpu_is_omap15xx() && length < ep->maxpacket)) {
546 txdma_ctrl = UDC_TXN_EOT | length; 526 txdma_ctrl = UDC_TXN_EOT | length;
547 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 527 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
@@ -600,28 +580,14 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
600 int dma_trigger = 0; 580 int dma_trigger = 0;
601 u16 w; 581 u16 w;
602 582
603 if (cpu_is_omap24xx()) 583 /* set up this DMA transfer, enable the fifo, start */
604 dma_trigger = OMAP24XX_DMA(USB_W2FC_RX0, ep->dma_channel); 584 packets /= ep->ep.maxpacket;
605 585 packets = min(packets, (unsigned)UDC_RXN_TC + 1);
606 /* NOTE: we filtered out "short reads" before, so we know 586 req->dma_bytes = packets * ep->ep.maxpacket;
607 * the buffer has only whole numbers of packets. 587 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
608 * except MODE SELECT(6) sent the 24 bytes data in OMAP24XX DMA mode 588 ep->ep.maxpacket >> 1, packets,
609 */ 589 OMAP_DMA_SYNC_ELEMENT,
610 if (cpu_is_omap24xx() && packets < ep->maxpacket) { 590 dma_trigger, 0);
611 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
612 packets, 1, OMAP_DMA_SYNC_ELEMENT,
613 dma_trigger, 0);
614 req->dma_bytes = packets;
615 } else {
616 /* set up this DMA transfer, enable the fifo, start */
617 packets /= ep->ep.maxpacket;
618 packets = min(packets, (unsigned)UDC_RXN_TC + 1);
619 req->dma_bytes = packets * ep->ep.maxpacket;
620 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
621 ep->ep.maxpacket >> 1, packets,
622 OMAP_DMA_SYNC_ELEMENT,
623 dma_trigger, 0);
624 }
625 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 591 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
626 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, 592 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual,
627 0, 0); 593 0, 0);
@@ -683,7 +649,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
683 } 649 }
684 omap_writew(UDC_TXN_DONE, UDC_IRQ_SRC); 650 omap_writew(UDC_TXN_DONE, UDC_IRQ_SRC);
685 651
686 if (!list_empty (&ep->queue)) { 652 if (!list_empty(&ep->queue)) {
687 req = container_of(ep->queue.next, 653 req = container_of(ep->queue.next,
688 struct omap_req, queue); 654 struct omap_req, queue);
689 next_in_dma(ep, req); 655 next_in_dma(ep, req);
@@ -702,7 +668,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
702 } 668 }
703 omap_writew(UDC_RXN_EOT, UDC_IRQ_SRC); 669 omap_writew(UDC_RXN_EOT, UDC_IRQ_SRC);
704 670
705 if (!list_empty (&ep->queue)) { 671 if (!list_empty(&ep->queue)) {
706 req = container_of(ep->queue.next, 672 req = container_of(ep->queue.next,
707 struct omap_req, queue); 673 struct omap_req, queue);
708 next_out_dma(ep, req); 674 next_out_dma(ep, req);
@@ -760,10 +726,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
760 ep->dma_channel = channel; 726 ep->dma_channel = channel;
761 727
762 if (is_in) { 728 if (is_in) {
763 if (cpu_is_omap24xx()) 729 dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel;
764 dma_channel = OMAP24XX_DMA(USB_W2FC_TX0, channel);
765 else
766 dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel;
767 status = omap_request_dma(dma_channel, 730 status = omap_request_dma(dma_channel,
768 ep->ep.name, dma_error, ep, &ep->lch); 731 ep->ep.name, dma_error, ep, &ep->lch);
769 if (status == 0) { 732 if (status == 0) {
@@ -780,11 +743,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
780 0, 0); 743 0, 0);
781 } 744 }
782 } else { 745 } else {
783 if (cpu_is_omap24xx()) 746 dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel;
784 dma_channel = OMAP24XX_DMA(USB_W2FC_RX0, channel);
785 else
786 dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel;
787
788 status = omap_request_dma(dma_channel, 747 status = omap_request_dma(dma_channel,
789 ep->ep.name, dma_error, ep, &ep->lch); 748 ep->ep.name, dma_error, ep, &ep->lch);
790 if (status == 0) { 749 if (status == 0) {
@@ -808,7 +767,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
808 omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ); 767 omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ);
809 768
810 /* channel type P: hw synch (fifo) */ 769 /* channel type P: hw synch (fifo) */
811 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) 770 if (!cpu_is_omap15xx())
812 omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P); 771 omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P);
813 } 772 }
814 773
@@ -928,13 +887,11 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
928 887
929 /* this isn't bogus, but OMAP DMA isn't the only hardware to 888 /* this isn't bogus, but OMAP DMA isn't the only hardware to
930 * have a hard time with partial packet reads... reject it. 889 * have a hard time with partial packet reads... reject it.
931 * Except OMAP2 can handle the small packets.
932 */ 890 */
933 if (use_dma 891 if (use_dma
934 && ep->has_dma 892 && ep->has_dma
935 && ep->bEndpointAddress != 0 893 && ep->bEndpointAddress != 0
936 && (ep->bEndpointAddress & USB_DIR_IN) == 0 894 && (ep->bEndpointAddress & USB_DIR_IN) == 0
937 && !cpu_class_is_omap2()
938 && (req->req.length % ep->ep.maxpacket) != 0) { 895 && (req->req.length % ep->ep.maxpacket) != 0) {
939 DBG("%s, no partial packet OUT reads\n", __func__); 896 DBG("%s, no partial packet OUT reads\n", __func__);
940 return -EMSGSIZE; 897 return -EMSGSIZE;
@@ -944,26 +901,9 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
944 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) 901 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN)
945 return -ESHUTDOWN; 902 return -ESHUTDOWN;
946 903
947 if (use_dma && ep->has_dma) { 904 if (use_dma && ep->has_dma)
948 if (req->req.dma == DMA_ADDR_INVALID) { 905 usb_gadget_map_request(&udc->gadget, &req->req,
949 req->req.dma = dma_map_single( 906 (ep->bEndpointAddress & USB_DIR_IN));
950 ep->udc->gadget.dev.parent,
951 req->req.buf,
952 req->req.length,
953 (ep->bEndpointAddress & USB_DIR_IN)
954 ? DMA_TO_DEVICE
955 : DMA_FROM_DEVICE);
956 req->mapped = 1;
957 } else {
958 dma_sync_single_for_device(
959 ep->udc->gadget.dev.parent,
960 req->req.dma, req->req.length,
961 (ep->bEndpointAddress & USB_DIR_IN)
962 ? DMA_TO_DEVICE
963 : DMA_FROM_DEVICE);
964 req->mapped = 0;
965 }
966 }
967 907
968 VDBG("%s queue req %p, len %d buf %p\n", 908 VDBG("%s queue req %p, len %d buf %p\n",
969 ep->ep.name, _req, _req->length, _req->buf); 909 ep->ep.name, _req, _req->length, _req->buf);
@@ -984,7 +924,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
984 int is_in; 924 int is_in;
985 925
986 if (ep->bEndpointAddress == 0) { 926 if (ep->bEndpointAddress == 0) {
987 if (!udc->ep0_pending || !list_empty (&ep->queue)) { 927 if (!udc->ep0_pending || !list_empty(&ep->queue)) {
988 spin_unlock_irqrestore(&udc->lock, flags); 928 spin_unlock_irqrestore(&udc->lock, flags);
989 return -EL2HLT; 929 return -EL2HLT;
990 } 930 }
@@ -1011,7 +951,8 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
1011 * always an IN ... even for IN transfers, 951 * always an IN ... even for IN transfers,
1012 * a weird case which seem to stall OMAP. 952 * a weird case which seem to stall OMAP.
1013 */ 953 */
1014 omap_writew(UDC_EP_SEL | UDC_EP_DIR, UDC_EP_NUM); 954 omap_writew(UDC_EP_SEL | UDC_EP_DIR,
955 UDC_EP_NUM);
1015 omap_writew(UDC_CLR_EP, UDC_CTRL); 956 omap_writew(UDC_CLR_EP, UDC_CTRL);
1016 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); 957 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1017 omap_writew(UDC_EP_DIR, UDC_EP_NUM); 958 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
@@ -1023,7 +964,8 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
1023 964
1024 /* non-empty DATA stage */ 965 /* non-empty DATA stage */
1025 } else if (is_in) { 966 } else if (is_in) {
1026 omap_writew(UDC_EP_SEL | UDC_EP_DIR, UDC_EP_NUM); 967 omap_writew(UDC_EP_SEL | UDC_EP_DIR,
968 UDC_EP_NUM);
1027 } else { 969 } else {
1028 if (udc->ep0_setup) 970 if (udc->ep0_setup)
1029 goto irq_wait; 971 goto irq_wait;
@@ -1071,7 +1013,7 @@ static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1071 spin_lock_irqsave(&ep->udc->lock, flags); 1013 spin_lock_irqsave(&ep->udc->lock, flags);
1072 1014
1073 /* make sure it's actually queued on this endpoint */ 1015 /* make sure it's actually queued on this endpoint */
1074 list_for_each_entry (req, &ep->queue, queue) { 1016 list_for_each_entry(req, &ep->queue, queue) {
1075 if (&req->req == _req) 1017 if (&req->req == _req)
1076 break; 1018 break;
1077 } 1019 }
@@ -1178,8 +1120,8 @@ static struct usb_ep_ops omap_ep_ops = {
1178 .dequeue = omap_ep_dequeue, 1120 .dequeue = omap_ep_dequeue,
1179 1121
1180 .set_halt = omap_ep_set_halt, 1122 .set_halt = omap_ep_set_halt,
1181 // fifo_status ... report bytes in fifo 1123 /* fifo_status ... report bytes in fifo */
1182 // fifo_flush ... flush fifo 1124 /* fifo_flush ... flush fifo */
1183}; 1125};
1184 1126
1185/*-------------------------------------------------------------------------*/ 1127/*-------------------------------------------------------------------------*/
@@ -1211,7 +1153,7 @@ static int omap_wakeup(struct usb_gadget *gadget)
1211 1153
1212 /* NOTE: non-OTG systems may use SRP TOO... */ 1154 /* NOTE: non-OTG systems may use SRP TOO... */
1213 } else if (!(udc->devstat & UDC_ATT)) { 1155 } else if (!(udc->devstat & UDC_ATT)) {
1214 if (udc->transceiver) 1156 if (!IS_ERR_OR_NULL(udc->transceiver))
1215 retval = otg_start_srp(udc->transceiver->otg); 1157 retval = otg_start_srp(udc->transceiver->otg);
1216 } 1158 }
1217 spin_unlock_irqrestore(&udc->lock, flags); 1159 spin_unlock_irqrestore(&udc->lock, flags);
@@ -1343,7 +1285,7 @@ static int omap_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1343 struct omap_udc *udc; 1285 struct omap_udc *udc;
1344 1286
1345 udc = container_of(gadget, struct omap_udc, gadget); 1287 udc = container_of(gadget, struct omap_udc, gadget);
1346 if (udc->transceiver) 1288 if (!IS_ERR_OR_NULL(udc->transceiver))
1347 return usb_phy_set_power(udc->transceiver, mA); 1289 return usb_phy_set_power(udc->transceiver, mA);
1348 return -EOPNOTSUPP; 1290 return -EOPNOTSUPP;
1349} 1291}
@@ -1409,7 +1351,7 @@ static void udc_quiesce(struct omap_udc *udc)
1409 1351
1410 udc->gadget.speed = USB_SPEED_UNKNOWN; 1352 udc->gadget.speed = USB_SPEED_UNKNOWN;
1411 nuke(&udc->ep[0], -ESHUTDOWN); 1353 nuke(&udc->ep[0], -ESHUTDOWN);
1412 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) 1354 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list)
1413 nuke(ep, -ESHUTDOWN); 1355 nuke(ep, -ESHUTDOWN);
1414} 1356}
1415 1357
@@ -1525,7 +1467,8 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1525 /* read next OUT packet of request, maybe 1467 /* read next OUT packet of request, maybe
1526 * reactiviting the fifo; stall on errors. 1468 * reactiviting the fifo; stall on errors.
1527 */ 1469 */
1528 if (!req || (stat = read_fifo(ep0, req)) < 0) { 1470 stat = read_fifo(ep0, req);
1471 if (!req || stat < 0) {
1529 omap_writew(UDC_STALL_CMD, UDC_SYSCON2); 1472 omap_writew(UDC_STALL_CMD, UDC_SYSCON2);
1530 udc->ep0_pending = 0; 1473 udc->ep0_pending = 0;
1531 stat = 0; 1474 stat = 0;
@@ -1658,7 +1601,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1658 /* this has rude side-effects (aborts) and 1601 /* this has rude side-effects (aborts) and
1659 * can't really work if DMA-IN is active 1602 * can't really work if DMA-IN is active
1660 */ 1603 */
1661 DBG("%s host set_halt, NYET \n", ep->name); 1604 DBG("%s host set_halt, NYET\n", ep->name);
1662 goto do_stall; 1605 goto do_stall;
1663 } 1606 }
1664 use_ep(ep, 0); 1607 use_ep(ep, 0);
@@ -1749,7 +1692,7 @@ delegate:
1749 */ 1692 */
1750 udc->ep0_setup = 1; 1693 udc->ep0_setup = 1;
1751 spin_unlock(&udc->lock); 1694 spin_unlock(&udc->lock);
1752 status = udc->driver->setup (&udc->gadget, &u.r); 1695 status = udc->driver->setup(&udc->gadget, &u.r);
1753 spin_lock(&udc->lock); 1696 spin_lock(&udc->lock);
1754 udc->ep0_setup = 0; 1697 udc->ep0_setup = 0;
1755 } 1698 }
@@ -1792,12 +1735,12 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1792 if (devstat & UDC_ATT) { 1735 if (devstat & UDC_ATT) {
1793 udc->gadget.speed = USB_SPEED_FULL; 1736 udc->gadget.speed = USB_SPEED_FULL;
1794 VDBG("connect\n"); 1737 VDBG("connect\n");
1795 if (!udc->transceiver) 1738 if (IS_ERR_OR_NULL(udc->transceiver))
1796 pullup_enable(udc); 1739 pullup_enable(udc);
1797 // if (driver->connect) call it 1740 /* if (driver->connect) call it */
1798 } else if (udc->gadget.speed != USB_SPEED_UNKNOWN) { 1741 } else if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
1799 udc->gadget.speed = USB_SPEED_UNKNOWN; 1742 udc->gadget.speed = USB_SPEED_UNKNOWN;
1800 if (!udc->transceiver) 1743 if (IS_ERR_OR_NULL(udc->transceiver))
1801 pullup_disable(udc); 1744 pullup_disable(udc);
1802 DBG("disconnect, gadget %s\n", 1745 DBG("disconnect, gadget %s\n",
1803 udc->driver->driver.name); 1746 udc->driver->driver.name);
@@ -1826,7 +1769,7 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1826 } 1769 }
1827 if (change & UDC_SUS) { 1770 if (change & UDC_SUS) {
1828 if (udc->gadget.speed != USB_SPEED_UNKNOWN) { 1771 if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
1829 // FIXME tell isp1301 to suspend/resume (?) 1772 /* FIXME tell isp1301 to suspend/resume (?) */
1830 if (devstat & UDC_SUS) { 1773 if (devstat & UDC_SUS) {
1831 VDBG("suspend\n"); 1774 VDBG("suspend\n");
1832 update_otg(udc); 1775 update_otg(udc);
@@ -1837,12 +1780,12 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1837 udc->driver->suspend(&udc->gadget); 1780 udc->driver->suspend(&udc->gadget);
1838 spin_lock(&udc->lock); 1781 spin_lock(&udc->lock);
1839 } 1782 }
1840 if (udc->transceiver) 1783 if (!IS_ERR_OR_NULL(udc->transceiver))
1841 usb_phy_set_suspend( 1784 usb_phy_set_suspend(
1842 udc->transceiver, 1); 1785 udc->transceiver, 1);
1843 } else { 1786 } else {
1844 VDBG("resume\n"); 1787 VDBG("resume\n");
1845 if (udc->transceiver) 1788 if (!IS_ERR_OR_NULL(udc->transceiver))
1846 usb_phy_set_suspend( 1789 usb_phy_set_suspend(
1847 udc->transceiver, 0); 1790 udc->transceiver, 0);
1848 if (udc->gadget.speed == USB_SPEED_FULL 1791 if (udc->gadget.speed == USB_SPEED_FULL
@@ -2029,7 +1972,7 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev)
2029 spin_lock_irqsave(&udc->lock, flags); 1972 spin_lock_irqsave(&udc->lock, flags);
2030 1973
2031 /* handle all non-DMA ISO transfers */ 1974 /* handle all non-DMA ISO transfers */
2032 list_for_each_entry (ep, &udc->iso, iso) { 1975 list_for_each_entry(ep, &udc->iso, iso) {
2033 u16 stat; 1976 u16 stat;
2034 struct omap_req *req; 1977 struct omap_req *req;
2035 1978
@@ -2088,15 +2031,11 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev)
2088 2031
2089static inline int machine_without_vbus_sense(void) 2032static inline int machine_without_vbus_sense(void)
2090{ 2033{
2091 return (machine_is_omap_innovator() 2034 return machine_is_omap_innovator()
2092 || machine_is_omap_osk() 2035 || machine_is_omap_osk()
2093 || machine_is_omap_apollon()
2094#ifndef CONFIG_MACH_OMAP_H4_OTG
2095 || machine_is_omap_h4()
2096#endif
2097 || machine_is_sx1() 2036 || machine_is_sx1()
2098 || cpu_is_omap7xx() /* No known omap7xx boards with vbus sense */ 2037 /* No known omap7xx boards with vbus sense */
2099 ); 2038 || cpu_is_omap7xx();
2100} 2039}
2101 2040
2102static int omap_udc_start(struct usb_gadget_driver *driver, 2041static int omap_udc_start(struct usb_gadget_driver *driver,
@@ -2110,7 +2049,7 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2110 if (!udc) 2049 if (!udc)
2111 return -ENODEV; 2050 return -ENODEV;
2112 if (!driver 2051 if (!driver
2113 // FIXME if otg, check: driver->is_otg 2052 /* FIXME if otg, check: driver->is_otg */
2114 || driver->max_speed < USB_SPEED_FULL 2053 || driver->max_speed < USB_SPEED_FULL
2115 || !bind || !driver->setup) 2054 || !bind || !driver->setup)
2116 return -EINVAL; 2055 return -EINVAL;
@@ -2122,7 +2061,7 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2122 } 2061 }
2123 2062
2124 /* reset state */ 2063 /* reset state */
2125 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { 2064 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
2126 ep->irqs = 0; 2065 ep->irqs = 0;
2127 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) 2066 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
2128 continue; 2067 continue;
@@ -2154,13 +2093,13 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2154 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC); 2093 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC);
2155 2094
2156 /* connect to bus through transceiver */ 2095 /* connect to bus through transceiver */
2157 if (udc->transceiver) { 2096 if (!IS_ERR_OR_NULL(udc->transceiver)) {
2158 status = otg_set_peripheral(udc->transceiver->otg, 2097 status = otg_set_peripheral(udc->transceiver->otg,
2159 &udc->gadget); 2098 &udc->gadget);
2160 if (status < 0) { 2099 if (status < 0) {
2161 ERR("can't bind to transceiver\n"); 2100 ERR("can't bind to transceiver\n");
2162 if (driver->unbind) { 2101 if (driver->unbind) {
2163 driver->unbind (&udc->gadget); 2102 driver->unbind(&udc->gadget);
2164 udc->gadget.dev.driver = NULL; 2103 udc->gadget.dev.driver = NULL;
2165 udc->driver = NULL; 2104 udc->driver = NULL;
2166 } 2105 }
@@ -2168,9 +2107,9 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2168 } 2107 }
2169 } else { 2108 } else {
2170 if (can_pullup(udc)) 2109 if (can_pullup(udc))
2171 pullup_enable (udc); 2110 pullup_enable(udc);
2172 else 2111 else
2173 pullup_disable (udc); 2112 pullup_disable(udc);
2174 } 2113 }
2175 2114
2176 /* boards that don't have VBUS sensing can't autogate 48MHz; 2115 /* boards that don't have VBUS sensing can't autogate 48MHz;
@@ -2201,7 +2140,7 @@ static int omap_udc_stop(struct usb_gadget_driver *driver)
2201 if (machine_without_vbus_sense()) 2140 if (machine_without_vbus_sense())
2202 omap_vbus_session(&udc->gadget, 0); 2141 omap_vbus_session(&udc->gadget, 0);
2203 2142
2204 if (udc->transceiver) 2143 if (!IS_ERR_OR_NULL(udc->transceiver))
2205 (void) otg_set_peripheral(udc->transceiver->otg, NULL); 2144 (void) otg_set_peripheral(udc->transceiver->otg, NULL);
2206 else 2145 else
2207 pullup_disable(udc); 2146 pullup_disable(udc);
@@ -2229,7 +2168,7 @@ static int omap_udc_stop(struct usb_gadget_driver *driver)
2229static const char proc_filename[] = "driver/udc"; 2168static const char proc_filename[] = "driver/udc";
2230 2169
2231#define FOURBITS "%s%s%s%s" 2170#define FOURBITS "%s%s%s%s"
2232#define EIGHTBITS FOURBITS FOURBITS 2171#define EIGHTBITS "%s%s%s%s%s%s%s%s"
2233 2172
2234static void proc_ep_show(struct seq_file *s, struct omap_ep *ep) 2173static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2235{ 2174{
@@ -2251,12 +2190,21 @@ static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2251 "\n%s %s%s%sirqs %ld stat %04x " EIGHTBITS FOURBITS "%s\n", 2190 "\n%s %s%s%sirqs %ld stat %04x " EIGHTBITS FOURBITS "%s\n",
2252 ep->name, buf, 2191 ep->name, buf,
2253 ep->double_buf ? "dbuf " : "", 2192 ep->double_buf ? "dbuf " : "",
2254 ({char *s; switch(ep->ackwait){ 2193 ({ char *s;
2255 case 0: s = ""; break; 2194 switch (ep->ackwait) {
2256 case 1: s = "(ackw) "; break; 2195 case 0:
2257 case 2: s = "(ackw2) "; break; 2196 s = "";
2258 default: s = "(?) "; break; 2197 break;
2259 } s;}), 2198 case 1:
2199 s = "(ackw) ";
2200 break;
2201 case 2:
2202 s = "(ackw2) ";
2203 break;
2204 default:
2205 s = "(?) ";
2206 break;
2207 } s; }),
2260 ep->irqs, stat_flg, 2208 ep->irqs, stat_flg,
2261 (stat_flg & UDC_NO_RXPACKET) ? "no_rxpacket " : "", 2209 (stat_flg & UDC_NO_RXPACKET) ? "no_rxpacket " : "",
2262 (stat_flg & UDC_MISS_IN) ? "miss_in " : "", 2210 (stat_flg & UDC_MISS_IN) ? "miss_in " : "",
@@ -2272,10 +2220,10 @@ static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2272 (stat_flg & UDC_NON_ISO_FIFO_EMPTY) ? "fifo_empty " : "", 2220 (stat_flg & UDC_NON_ISO_FIFO_EMPTY) ? "fifo_empty " : "",
2273 (stat_flg & UDC_NON_ISO_FIFO_FULL) ? "fifo_full " : ""); 2221 (stat_flg & UDC_NON_ISO_FIFO_FULL) ? "fifo_full " : "");
2274 2222
2275 if (list_empty (&ep->queue)) 2223 if (list_empty(&ep->queue))
2276 seq_printf(s, "\t(queue empty)\n"); 2224 seq_printf(s, "\t(queue empty)\n");
2277 else 2225 else
2278 list_for_each_entry (req, &ep->queue, queue) { 2226 list_for_each_entry(req, &ep->queue, queue) {
2279 unsigned length = req->req.actual; 2227 unsigned length = req->req.actual;
2280 2228
2281 if (use_dma && buf[0]) { 2229 if (use_dma && buf[0]) {
@@ -2293,11 +2241,16 @@ static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2293static char *trx_mode(unsigned m, int enabled) 2241static char *trx_mode(unsigned m, int enabled)
2294{ 2242{
2295 switch (m) { 2243 switch (m) {
2296 case 0: return enabled ? "*6wire" : "unused"; 2244 case 0:
2297 case 1: return "4wire"; 2245 return enabled ? "*6wire" : "unused";
2298 case 2: return "3wire"; 2246 case 1:
2299 case 3: return "6wire"; 2247 return "4wire";
2300 default: return "unknown"; 2248 case 2:
2249 return "3wire";
2250 case 3:
2251 return "6wire";
2252 default:
2253 return "unknown";
2301 } 2254 }
2302} 2255}
2303 2256
@@ -2307,12 +2260,9 @@ static int proc_otg_show(struct seq_file *s)
2307 u32 trans = 0; 2260 u32 trans = 0;
2308 char *ctrl_name = "(UNKNOWN)"; 2261 char *ctrl_name = "(UNKNOWN)";
2309 2262
2310 /* XXX This needs major revision for OMAP2+ */
2311 tmp = omap_readl(OTG_REV); 2263 tmp = omap_readl(OTG_REV);
2312 if (cpu_class_is_omap1()) { 2264 ctrl_name = "tranceiver_ctrl";
2313 ctrl_name = "tranceiver_ctrl"; 2265 trans = omap_readw(USB_TRANSCEIVER_CTRL);
2314 trans = omap_readw(USB_TRANSCEIVER_CTRL);
2315 }
2316 seq_printf(s, "\nOTG rev %d.%d, %s %05x\n", 2266 seq_printf(s, "\nOTG rev %d.%d, %s %05x\n",
2317 tmp >> 4, tmp & 0xf, ctrl_name, trans); 2267 tmp >> 4, tmp & 0xf, ctrl_name, trans);
2318 tmp = omap_readw(OTG_SYSCON_1); 2268 tmp = omap_readw(OTG_SYSCON_1);
@@ -2332,7 +2282,7 @@ static int proc_otg_show(struct seq_file *s)
2332 " b_ase_brst=%d hmc=%d\n", tmp, 2282 " b_ase_brst=%d hmc=%d\n", tmp,
2333 (tmp & OTG_EN) ? " otg_en" : "", 2283 (tmp & OTG_EN) ? " otg_en" : "",
2334 (tmp & USBX_SYNCHRO) ? " synchro" : "", 2284 (tmp & USBX_SYNCHRO) ? " synchro" : "",
2335 // much more SRP stuff 2285 /* much more SRP stuff */
2336 (tmp & SRP_DATA) ? " srp_data" : "", 2286 (tmp & SRP_DATA) ? " srp_data" : "",
2337 (tmp & SRP_VBUS) ? " srp_vbus" : "", 2287 (tmp & SRP_VBUS) ? " srp_vbus" : "",
2338 (tmp & OTG_PADEN) ? " otg_paden" : "", 2288 (tmp & OTG_PADEN) ? " otg_paden" : "",
@@ -2399,14 +2349,12 @@ static int proc_udc_show(struct seq_file *s, void *_)
2399 HMC, 2349 HMC,
2400 udc->transceiver 2350 udc->transceiver
2401 ? udc->transceiver->label 2351 ? udc->transceiver->label
2402 : ((cpu_is_omap1710() || cpu_is_omap24xx()) 2352 : (cpu_is_omap1710()
2403 ? "external" : "(none)")); 2353 ? "external" : "(none)"));
2404 if (cpu_class_is_omap1()) { 2354 seq_printf(s, "ULPD control %04x req %04x status %04x\n",
2405 seq_printf(s, "ULPD control %04x req %04x status %04x\n", 2355 omap_readw(ULPD_CLOCK_CTRL),
2406 omap_readw(ULPD_CLOCK_CTRL), 2356 omap_readw(ULPD_SOFT_REQ),
2407 omap_readw(ULPD_SOFT_REQ), 2357 omap_readw(ULPD_STATUS_REQ));
2408 omap_readw(ULPD_STATUS_REQ));
2409 }
2410 2358
2411 /* OTG controller registers */ 2359 /* OTG controller registers */
2412 if (!cpu_is_omap15xx()) 2360 if (!cpu_is_omap15xx())
@@ -2422,7 +2370,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2422 (tmp & UDC_SELF_PWR) ? " self_pwr" : "", 2370 (tmp & UDC_SELF_PWR) ? " self_pwr" : "",
2423 (tmp & UDC_SOFF_DIS) ? " soff_dis" : "", 2371 (tmp & UDC_SOFF_DIS) ? " soff_dis" : "",
2424 (tmp & UDC_PULLUP_EN) ? " PULLUP" : ""); 2372 (tmp & UDC_PULLUP_EN) ? " PULLUP" : "");
2425 // syscon2 is write-only 2373 /* syscon2 is write-only */
2426 2374
2427 /* UDC controller registers */ 2375 /* UDC controller registers */
2428 if (!(tmp & UDC_PULLUP_EN)) { 2376 if (!(tmp & UDC_PULLUP_EN)) {
@@ -2506,7 +2454,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2506 if (tmp & UDC_ATT) { 2454 if (tmp & UDC_ATT) {
2507 proc_ep_show(s, &udc->ep[0]); 2455 proc_ep_show(s, &udc->ep[0]);
2508 if (tmp & UDC_ADD) { 2456 if (tmp & UDC_ADD) {
2509 list_for_each_entry (ep, &udc->gadget.ep_list, 2457 list_for_each_entry(ep, &udc->gadget.ep_list,
2510 ep.ep_list) { 2458 ep.ep_list) {
2511 if (ep->ep.desc) 2459 if (ep->ep.desc)
2512 proc_ep_show(s, ep); 2460 proc_ep_show(s, ep);
@@ -2557,7 +2505,7 @@ static inline void remove_proc_file(void) {}
2557 * UDC_SYSCON_1.CFG_LOCK is set can now work. We won't use that 2505 * UDC_SYSCON_1.CFG_LOCK is set can now work. We won't use that
2558 * capability yet though. 2506 * capability yet though.
2559 */ 2507 */
2560static unsigned __init 2508static unsigned __devinit
2561omap_ep_setup(char *name, u8 addr, u8 type, 2509omap_ep_setup(char *name, u8 addr, u8 type,
2562 unsigned buf, unsigned maxp, int dbuf) 2510 unsigned buf, unsigned maxp, int dbuf)
2563{ 2511{
@@ -2575,14 +2523,29 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2575 /* chip setup ... bit values are same for IN, OUT */ 2523 /* chip setup ... bit values are same for IN, OUT */
2576 if (type == USB_ENDPOINT_XFER_ISOC) { 2524 if (type == USB_ENDPOINT_XFER_ISOC) {
2577 switch (maxp) { 2525 switch (maxp) {
2578 case 8: epn_rxtx = 0 << 12; break; 2526 case 8:
2579 case 16: epn_rxtx = 1 << 12; break; 2527 epn_rxtx = 0 << 12;
2580 case 32: epn_rxtx = 2 << 12; break; 2528 break;
2581 case 64: epn_rxtx = 3 << 12; break; 2529 case 16:
2582 case 128: epn_rxtx = 4 << 12; break; 2530 epn_rxtx = 1 << 12;
2583 case 256: epn_rxtx = 5 << 12; break; 2531 break;
2584 case 512: epn_rxtx = 6 << 12; break; 2532 case 32:
2585 default: BUG(); 2533 epn_rxtx = 2 << 12;
2534 break;
2535 case 64:
2536 epn_rxtx = 3 << 12;
2537 break;
2538 case 128:
2539 epn_rxtx = 4 << 12;
2540 break;
2541 case 256:
2542 epn_rxtx = 5 << 12;
2543 break;
2544 case 512:
2545 epn_rxtx = 6 << 12;
2546 break;
2547 default:
2548 BUG();
2586 } 2549 }
2587 epn_rxtx |= UDC_EPN_RX_ISO; 2550 epn_rxtx |= UDC_EPN_RX_ISO;
2588 dbuf = 1; 2551 dbuf = 1;
@@ -2591,15 +2554,24 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2591 * and ignored for PIO-IN on newer chips 2554 * and ignored for PIO-IN on newer chips
2592 * (for more reliable behavior) 2555 * (for more reliable behavior)
2593 */ 2556 */
2594 if (!use_dma || cpu_is_omap15xx() || cpu_is_omap24xx()) 2557 if (!use_dma || cpu_is_omap15xx())
2595 dbuf = 0; 2558 dbuf = 0;
2596 2559
2597 switch (maxp) { 2560 switch (maxp) {
2598 case 8: epn_rxtx = 0 << 12; break; 2561 case 8:
2599 case 16: epn_rxtx = 1 << 12; break; 2562 epn_rxtx = 0 << 12;
2600 case 32: epn_rxtx = 2 << 12; break; 2563 break;
2601 case 64: epn_rxtx = 3 << 12; break; 2564 case 16:
2602 default: BUG(); 2565 epn_rxtx = 1 << 12;
2566 break;
2567 case 32:
2568 epn_rxtx = 2 << 12;
2569 break;
2570 case 64:
2571 epn_rxtx = 3 << 12;
2572 break;
2573 default:
2574 BUG();
2603 } 2575 }
2604 if (dbuf && addr) 2576 if (dbuf && addr)
2605 epn_rxtx |= UDC_EPN_RX_DB; 2577 epn_rxtx |= UDC_EPN_RX_DB;
@@ -2639,7 +2611,7 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2639 ep->ep.name = ep->name; 2611 ep->ep.name = ep->name;
2640 ep->ep.ops = &omap_ep_ops; 2612 ep->ep.ops = &omap_ep_ops;
2641 ep->ep.maxpacket = ep->maxpacket = maxp; 2613 ep->ep.maxpacket = ep->maxpacket = maxp;
2642 list_add_tail (&ep->ep.ep_list, &udc->gadget.ep_list); 2614 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
2643 2615
2644 return buf; 2616 return buf;
2645} 2617}
@@ -2647,11 +2619,11 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2647static void omap_udc_release(struct device *dev) 2619static void omap_udc_release(struct device *dev)
2648{ 2620{
2649 complete(udc->done); 2621 complete(udc->done);
2650 kfree (udc); 2622 kfree(udc);
2651 udc = NULL; 2623 udc = NULL;
2652} 2624}
2653 2625
2654static int __init 2626static int __devinit
2655omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv) 2627omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2656{ 2628{
2657 unsigned tmp, buf; 2629 unsigned tmp, buf;
@@ -2665,13 +2637,13 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2665 omap_writew(0, UDC_TXDMA_CFG); 2637 omap_writew(0, UDC_TXDMA_CFG);
2666 2638
2667 /* UDC_PULLUP_EN gates the chip clock */ 2639 /* UDC_PULLUP_EN gates the chip clock */
2668 // OTG_SYSCON_1 |= DEV_IDLE_EN; 2640 /* OTG_SYSCON_1 |= DEV_IDLE_EN; */
2669 2641
2670 udc = kzalloc(sizeof(*udc), GFP_KERNEL); 2642 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
2671 if (!udc) 2643 if (!udc)
2672 return -ENOMEM; 2644 return -ENOMEM;
2673 2645
2674 spin_lock_init (&udc->lock); 2646 spin_lock_init(&udc->lock);
2675 2647
2676 udc->gadget.ops = &omap_gadget_ops; 2648 udc->gadget.ops = &omap_gadget_ops;
2677 udc->gadget.ep0 = &udc->ep[0].ep; 2649 udc->gadget.ep0 = &udc->ep[0].ep;
@@ -2701,13 +2673,13 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2701 omap_writew(0, UDC_EP_TX(tmp)); 2673 omap_writew(0, UDC_EP_TX(tmp));
2702 } 2674 }
2703 2675
2704#define OMAP_BULK_EP(name,addr) \ 2676#define OMAP_BULK_EP(name, addr) \
2705 buf = omap_ep_setup(name "-bulk", addr, \ 2677 buf = omap_ep_setup(name "-bulk", addr, \
2706 USB_ENDPOINT_XFER_BULK, buf, 64, 1); 2678 USB_ENDPOINT_XFER_BULK, buf, 64, 1);
2707#define OMAP_INT_EP(name,addr, maxp) \ 2679#define OMAP_INT_EP(name, addr, maxp) \
2708 buf = omap_ep_setup(name "-int", addr, \ 2680 buf = omap_ep_setup(name "-int", addr, \
2709 USB_ENDPOINT_XFER_INT, buf, maxp, 0); 2681 USB_ENDPOINT_XFER_INT, buf, maxp, 0);
2710#define OMAP_ISO_EP(name,addr, maxp) \ 2682#define OMAP_ISO_EP(name, addr, maxp) \
2711 buf = omap_ep_setup(name "-iso", addr, \ 2683 buf = omap_ep_setup(name "-iso", addr, \
2712 USB_ENDPOINT_XFER_ISOC, buf, maxp, 1); 2684 USB_ENDPOINT_XFER_ISOC, buf, maxp, 1);
2713 2685
@@ -2788,15 +2760,18 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2788 return 0; 2760 return 0;
2789} 2761}
2790 2762
2791static int __init omap_udc_probe(struct platform_device *pdev) 2763static int __devinit omap_udc_probe(struct platform_device *pdev)
2792{ 2764{
2793 int status = -ENODEV; 2765 int status = -ENODEV;
2794 int hmc; 2766 int hmc;
2795 struct usb_phy *xceiv = NULL; 2767 struct usb_phy *xceiv = NULL;
2796 const char *type = NULL; 2768 const char *type = NULL;
2797 struct omap_usb_config *config = pdev->dev.platform_data; 2769 struct omap_usb_config *config = pdev->dev.platform_data;
2798 struct clk *dc_clk; 2770 struct clk *dc_clk = NULL;
2799 struct clk *hhc_clk; 2771 struct clk *hhc_clk = NULL;
2772
2773 if (cpu_is_omap7xx())
2774 use_dma = 0;
2800 2775
2801 /* NOTE: "knows" the order of the resources! */ 2776 /* NOTE: "knows" the order of the resources! */
2802 if (!request_mem_region(pdev->resource[0].start, 2777 if (!request_mem_region(pdev->resource[0].start,
@@ -2816,16 +2791,6 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2816 udelay(100); 2791 udelay(100);
2817 } 2792 }
2818 2793
2819 if (cpu_is_omap24xx()) {
2820 dc_clk = clk_get(&pdev->dev, "usb_fck");
2821 hhc_clk = clk_get(&pdev->dev, "usb_l4_ick");
2822 BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk));
2823 /* can't use omap_udc_enable_clock yet */
2824 clk_enable(dc_clk);
2825 clk_enable(hhc_clk);
2826 udelay(100);
2827 }
2828
2829 if (cpu_is_omap7xx()) { 2794 if (cpu_is_omap7xx()) {
2830 dc_clk = clk_get(&pdev->dev, "usb_dc_ck"); 2795 dc_clk = clk_get(&pdev->dev, "usb_dc_ck");
2831 hhc_clk = clk_get(&pdev->dev, "l3_ocpi_ck"); 2796 hhc_clk = clk_get(&pdev->dev, "l3_ocpi_ck");
@@ -2865,8 +2830,8 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2865 * use it. Except for OTG, we don't _need_ to talk to one; 2830 * use it. Except for OTG, we don't _need_ to talk to one;
2866 * but not having one probably means no VBUS detection. 2831 * but not having one probably means no VBUS detection.
2867 */ 2832 */
2868 xceiv = usb_get_transceiver(); 2833 xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
2869 if (xceiv) 2834 if (!IS_ERR_OR_NULL(xceiv))
2870 type = xceiv->label; 2835 type = xceiv->label;
2871 else if (config->otg) { 2836 else if (config->otg) {
2872 DBG("OTG requires external transceiver!\n"); 2837 DBG("OTG requires external transceiver!\n");
@@ -2875,14 +2840,6 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2875 2840
2876 hmc = HMC_1610; 2841 hmc = HMC_1610;
2877 2842
2878 if (cpu_is_omap24xx()) {
2879 /* this could be transceiverless in one of the
2880 * "we don't need to know" modes.
2881 */
2882 type = "external";
2883 goto known;
2884 }
2885
2886 switch (hmc) { 2843 switch (hmc) {
2887 case 0: /* POWERUP DEFAULT == 0 */ 2844 case 0: /* POWERUP DEFAULT == 0 */
2888 case 4: 2845 case 4:
@@ -2898,7 +2855,7 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2898 case 16: 2855 case 16:
2899 case 19: 2856 case 19:
2900 case 25: 2857 case 25:
2901 if (!xceiv) { 2858 if (IS_ERR_OR_NULL(xceiv)) {
2902 DBG("external transceiver not registered!\n"); 2859 DBG("external transceiver not registered!\n");
2903 type = "unknown"; 2860 type = "unknown";
2904 } 2861 }
@@ -2921,16 +2878,16 @@ bad_on_1710:
2921 goto cleanup0; 2878 goto cleanup0;
2922 } 2879 }
2923 } 2880 }
2924known: 2881
2925 INFO("hmc mode %d, %s transceiver\n", hmc, type); 2882 INFO("hmc mode %d, %s transceiver\n", hmc, type);
2926 2883
2927 /* a "gadget" abstracts/virtualizes the controller */ 2884 /* a "gadget" abstracts/virtualizes the controller */
2928 status = omap_udc_setup(pdev, xceiv); 2885 status = omap_udc_setup(pdev, xceiv);
2929 if (status) { 2886 if (status)
2930 goto cleanup0; 2887 goto cleanup0;
2931 } 2888
2932 xceiv = NULL; 2889 xceiv = NULL;
2933 // "udc" is now valid 2890 /* "udc" is now valid */
2934 pullup_disable(udc); 2891 pullup_disable(udc);
2935#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) 2892#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
2936 udc->gadget.is_otg = (config->otg != 0); 2893 udc->gadget.is_otg = (config->otg != 0);
@@ -2944,7 +2901,7 @@ known:
2944 2901
2945 /* USB general purpose IRQ: ep0, state changes, dma, etc */ 2902 /* USB general purpose IRQ: ep0, state changes, dma, etc */
2946 status = request_irq(pdev->resource[1].start, omap_udc_irq, 2903 status = request_irq(pdev->resource[1].start, omap_udc_irq,
2947 IRQF_SAMPLE_RANDOM, driver_name, udc); 2904 0, driver_name, udc);
2948 if (status != 0) { 2905 if (status != 0) {
2949 ERR("can't get irq %d, err %d\n", 2906 ERR("can't get irq %d, err %d\n",
2950 (int) pdev->resource[1].start, status); 2907 (int) pdev->resource[1].start, status);
@@ -2953,7 +2910,7 @@ known:
2953 2910
2954 /* USB "non-iso" IRQ (PIO for all but ep0) */ 2911 /* USB "non-iso" IRQ (PIO for all but ep0) */
2955 status = request_irq(pdev->resource[2].start, omap_udc_pio_irq, 2912 status = request_irq(pdev->resource[2].start, omap_udc_pio_irq,
2956 IRQF_SAMPLE_RANDOM, "omap_udc pio", udc); 2913 0, "omap_udc pio", udc);
2957 if (status != 0) { 2914 if (status != 0) {
2958 ERR("can't get irq %d, err %d\n", 2915 ERR("can't get irq %d, err %d\n",
2959 (int) pdev->resource[2].start, status); 2916 (int) pdev->resource[2].start, status);
@@ -2975,16 +2932,6 @@ known:
2975 clk_disable(dc_clk); 2932 clk_disable(dc_clk);
2976 } 2933 }
2977 2934
2978 if (cpu_is_omap24xx()) {
2979 udc->dc_clk = dc_clk;
2980 udc->hhc_clk = hhc_clk;
2981 /* FIXME OMAP2 don't release hhc & dc clock */
2982#if 0
2983 clk_disable(hhc_clk);
2984 clk_disable(dc_clk);
2985#endif
2986 }
2987
2988 create_proc_file(); 2935 create_proc_file();
2989 status = device_add(&udc->gadget.dev); 2936 status = device_add(&udc->gadget.dev);
2990 if (status) 2937 if (status)
@@ -3006,14 +2953,14 @@ cleanup2:
3006 free_irq(pdev->resource[1].start, udc); 2953 free_irq(pdev->resource[1].start, udc);
3007 2954
3008cleanup1: 2955cleanup1:
3009 kfree (udc); 2956 kfree(udc);
3010 udc = NULL; 2957 udc = NULL;
3011 2958
3012cleanup0: 2959cleanup0:
3013 if (xceiv) 2960 if (!IS_ERR_OR_NULL(xceiv))
3014 usb_put_transceiver(xceiv); 2961 usb_put_phy(xceiv);
3015 2962
3016 if (cpu_is_omap16xx() || cpu_is_omap24xx() || cpu_is_omap7xx()) { 2963 if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
3017 clk_disable(hhc_clk); 2964 clk_disable(hhc_clk);
3018 clk_disable(dc_clk); 2965 clk_disable(dc_clk);
3019 clk_put(hhc_clk); 2966 clk_put(hhc_clk);
@@ -3026,7 +2973,7 @@ cleanup0:
3026 return status; 2973 return status;
3027} 2974}
3028 2975
3029static int __exit omap_udc_remove(struct platform_device *pdev) 2976static int __devexit omap_udc_remove(struct platform_device *pdev)
3030{ 2977{
3031 DECLARE_COMPLETION_ONSTACK(done); 2978 DECLARE_COMPLETION_ONSTACK(done);
3032 2979
@@ -3040,8 +2987,8 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
3040 udc->done = &done; 2987 udc->done = &done;
3041 2988
3042 pullup_disable(udc); 2989 pullup_disable(udc);
3043 if (udc->transceiver) { 2990 if (!IS_ERR_OR_NULL(udc->transceiver)) {
3044 usb_put_transceiver(udc->transceiver); 2991 usb_put_phy(udc->transceiver);
3045 udc->transceiver = NULL; 2992 udc->transceiver = NULL;
3046 } 2993 }
3047 omap_writew(0, UDC_SYSCON1); 2994 omap_writew(0, UDC_SYSCON1);
@@ -3111,7 +3058,8 @@ static int omap_udc_resume(struct platform_device *dev)
3111/*-------------------------------------------------------------------------*/ 3058/*-------------------------------------------------------------------------*/
3112 3059
3113static struct platform_driver udc_driver = { 3060static struct platform_driver udc_driver = {
3114 .remove = __exit_p(omap_udc_remove), 3061 .probe = omap_udc_probe,
3062 .remove = __devexit_p(omap_udc_remove),
3115 .suspend = omap_udc_suspend, 3063 .suspend = omap_udc_suspend,
3116 .resume = omap_udc_resume, 3064 .resume = omap_udc_resume,
3117 .driver = { 3065 .driver = {
@@ -3120,27 +3068,7 @@ static struct platform_driver udc_driver = {
3120 }, 3068 },
3121}; 3069};
3122 3070
3123static int __init udc_init(void) 3071module_platform_driver(udc_driver);
3124{
3125 /* Disable DMA for omap7xx -- it doesn't work right. */
3126 if (cpu_is_omap7xx())
3127 use_dma = 0;
3128
3129 INFO("%s, version: " DRIVER_VERSION
3130#ifdef USE_ISO
3131 " (iso)"
3132#endif
3133 "%s\n", driver_desc,
3134 use_dma ? " (dma)" : "");
3135 return platform_driver_probe(&udc_driver, omap_udc_probe);
3136}
3137module_init(udc_init);
3138
3139static void __exit udc_exit(void)
3140{
3141 platform_driver_unregister(&udc_driver);
3142}
3143module_exit(udc_exit);
3144 3072
3145MODULE_DESCRIPTION(DRIVER_DESC); 3073MODULE_DESCRIPTION(DRIVER_DESC);
3146MODULE_LICENSE("GPL"); 3074MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index 1cfcc9ecbfbc..f4fb71c9ae08 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -2208,7 +2208,7 @@ static void pch_udc_complete_receiver(struct pch_udc_ep *ep)
2208 return; 2208 return;
2209 } 2209 }
2210 if ((td->status & PCH_UDC_BUFF_STS) == PCH_UDC_BS_DMA_DONE) 2210 if ((td->status & PCH_UDC_BUFF_STS) == PCH_UDC_BS_DMA_DONE)
2211 if (td->status | PCH_UDC_DMA_LAST) { 2211 if (td->status & PCH_UDC_DMA_LAST) {
2212 count = td->status & PCH_UDC_RXTX_BYTES; 2212 count = td->status & PCH_UDC_RXTX_BYTES;
2213 break; 2213 break;
2214 } 2214 }
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index f7ff9e8e746a..53c093b941e5 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -21,6 +21,7 @@
21#include <linux/ioport.h> 21#include <linux/ioport.h>
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/errno.h> 23#include <linux/errno.h>
24#include <linux/err.h>
24#include <linux/delay.h> 25#include <linux/delay.h>
25#include <linux/slab.h> 26#include <linux/slab.h>
26#include <linux/init.h> 27#include <linux/init.h>
@@ -993,7 +994,7 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
993 994
994 udc = container_of(_gadget, struct pxa25x_udc, gadget); 995 udc = container_of(_gadget, struct pxa25x_udc, gadget);
995 996
996 if (udc->transceiver) 997 if (!IS_ERR_OR_NULL(udc->transceiver))
997 return usb_phy_set_power(udc->transceiver, mA); 998 return usb_phy_set_power(udc->transceiver, mA);
998 return -EOPNOTSUPP; 999 return -EOPNOTSUPP;
999} 1000}
@@ -1299,7 +1300,7 @@ fail:
1299 DMSG("registered gadget driver '%s'\n", driver->driver.name); 1300 DMSG("registered gadget driver '%s'\n", driver->driver.name);
1300 1301
1301 /* connect to bus through transceiver */ 1302 /* connect to bus through transceiver */
1302 if (dev->transceiver) { 1303 if (!IS_ERR_OR_NULL(dev->transceiver)) {
1303 retval = otg_set_peripheral(dev->transceiver->otg, 1304 retval = otg_set_peripheral(dev->transceiver->otg,
1304 &dev->gadget); 1305 &dev->gadget);
1305 if (retval) { 1306 if (retval) {
@@ -1359,7 +1360,7 @@ static int pxa25x_stop(struct usb_gadget_driver *driver)
1359 stop_activity(dev, driver); 1360 stop_activity(dev, driver);
1360 local_irq_enable(); 1361 local_irq_enable();
1361 1362
1362 if (dev->transceiver) 1363 if (!IS_ERR_OR_NULL(dev->transceiver))
1363 (void) otg_set_peripheral(dev->transceiver->otg, NULL); 1364 (void) otg_set_peripheral(dev->transceiver->otg, NULL);
1364 1365
1365 driver->unbind(&dev->gadget); 1366 driver->unbind(&dev->gadget);
@@ -2159,7 +2160,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2159 dev->dev = &pdev->dev; 2160 dev->dev = &pdev->dev;
2160 dev->mach = pdev->dev.platform_data; 2161 dev->mach = pdev->dev.platform_data;
2161 2162
2162 dev->transceiver = usb_get_transceiver(); 2163 dev->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2163 2164
2164 if (gpio_is_valid(dev->mach->gpio_pullup)) { 2165 if (gpio_is_valid(dev->mach->gpio_pullup)) {
2165 if ((retval = gpio_request(dev->mach->gpio_pullup, 2166 if ((retval = gpio_request(dev->mach->gpio_pullup,
@@ -2237,8 +2238,8 @@ lubbock_fail0:
2237 if (gpio_is_valid(dev->mach->gpio_pullup)) 2238 if (gpio_is_valid(dev->mach->gpio_pullup))
2238 gpio_free(dev->mach->gpio_pullup); 2239 gpio_free(dev->mach->gpio_pullup);
2239 err_gpio_pullup: 2240 err_gpio_pullup:
2240 if (dev->transceiver) { 2241 if (!IS_ERR_OR_NULL(dev->transceiver)) {
2241 usb_put_transceiver(dev->transceiver); 2242 usb_put_phy(dev->transceiver);
2242 dev->transceiver = NULL; 2243 dev->transceiver = NULL;
2243 } 2244 }
2244 clk_put(dev->clk); 2245 clk_put(dev->clk);
@@ -2279,8 +2280,8 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev)
2279 2280
2280 clk_put(dev->clk); 2281 clk_put(dev->clk);
2281 2282
2282 if (dev->transceiver) { 2283 if (!IS_ERR_OR_NULL(dev->transceiver)) {
2283 usb_put_transceiver(dev->transceiver); 2284 usb_put_phy(dev->transceiver);
2284 dev->transceiver = NULL; 2285 dev->transceiver = NULL;
2285 } 2286 }
2286 2287
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 98acb3ab9e17..644b4305cb99 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -13,6 +13,7 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/err.h>
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
17#include <linux/delay.h> 18#include <linux/delay.h>
18#include <linux/list.h> 19#include <linux/list.h>
@@ -1573,7 +1574,7 @@ static int should_enable_udc(struct pxa_udc *udc)
1573 int put_on; 1574 int put_on;
1574 1575
1575 put_on = ((udc->pullup_on) && (udc->driver)); 1576 put_on = ((udc->pullup_on) && (udc->driver));
1576 put_on &= ((udc->vbus_sensed) || (!udc->transceiver)); 1577 put_on &= ((udc->vbus_sensed) || (IS_ERR_OR_NULL(udc->transceiver)));
1577 return put_on; 1578 return put_on;
1578} 1579}
1579 1580
@@ -1594,7 +1595,7 @@ static int should_disable_udc(struct pxa_udc *udc)
1594 int put_off; 1595 int put_off;
1595 1596
1596 put_off = ((!udc->pullup_on) || (!udc->driver)); 1597 put_off = ((!udc->pullup_on) || (!udc->driver));
1597 put_off |= ((!udc->vbus_sensed) && (udc->transceiver)); 1598 put_off |= ((!udc->vbus_sensed) && (!IS_ERR_OR_NULL(udc->transceiver)));
1598 return put_off; 1599 return put_off;
1599} 1600}
1600 1601
@@ -1665,7 +1666,7 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1665 struct pxa_udc *udc; 1666 struct pxa_udc *udc;
1666 1667
1667 udc = to_gadget_udc(_gadget); 1668 udc = to_gadget_udc(_gadget);
1668 if (udc->transceiver) 1669 if (!IS_ERR_OR_NULL(udc->transceiver))
1669 return usb_phy_set_power(udc->transceiver, mA); 1670 return usb_phy_set_power(udc->transceiver, mA);
1670 return -EOPNOTSUPP; 1671 return -EOPNOTSUPP;
1671} 1672}
@@ -1834,7 +1835,7 @@ static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1834 dev_dbg(udc->dev, "registered gadget driver '%s'\n", 1835 dev_dbg(udc->dev, "registered gadget driver '%s'\n",
1835 driver->driver.name); 1836 driver->driver.name);
1836 1837
1837 if (udc->transceiver) { 1838 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1838 retval = otg_set_peripheral(udc->transceiver->otg, 1839 retval = otg_set_peripheral(udc->transceiver->otg,
1839 &udc->gadget); 1840 &udc->gadget);
1840 if (retval) { 1841 if (retval) {
@@ -1908,7 +1909,7 @@ static int pxa27x_udc_stop(struct usb_gadget_driver *driver)
1908 dev_info(udc->dev, "unregistered gadget driver '%s'\n", 1909 dev_info(udc->dev, "unregistered gadget driver '%s'\n",
1909 driver->driver.name); 1910 driver->driver.name);
1910 1911
1911 if (udc->transceiver) 1912 if (!IS_ERR_OR_NULL(udc->transceiver))
1912 return otg_set_peripheral(udc->transceiver->otg, NULL); 1913 return otg_set_peripheral(udc->transceiver->otg, NULL);
1913 return 0; 1914 return 0;
1914} 1915}
@@ -2464,7 +2465,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2464 2465
2465 udc->dev = &pdev->dev; 2466 udc->dev = &pdev->dev;
2466 udc->mach = pdev->dev.platform_data; 2467 udc->mach = pdev->dev.platform_data;
2467 udc->transceiver = usb_get_transceiver(); 2468 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2468 2469
2469 gpio = udc->mach->gpio_pullup; 2470 gpio = udc->mach->gpio_pullup;
2470 if (gpio_is_valid(gpio)) { 2471 if (gpio_is_valid(gpio)) {
@@ -2543,7 +2544,7 @@ static int __exit pxa_udc_remove(struct platform_device *_dev)
2543 if (gpio_is_valid(gpio)) 2544 if (gpio_is_valid(gpio))
2544 gpio_free(gpio); 2545 gpio_free(gpio);
2545 2546
2546 usb_put_transceiver(udc->transceiver); 2547 usb_put_phy(udc->transceiver);
2547 2548
2548 udc->transceiver = NULL; 2549 udc->transceiver = NULL;
2549 platform_set_drvdata(_dev, NULL); 2550 platform_set_drvdata(_dev, NULL);
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index f4abb0ed9872..b13e0bb5f5b8 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -112,7 +112,6 @@ struct s3c_hsotg_ep {
112 struct s3c_hsotg_req *req; 112 struct s3c_hsotg_req *req;
113 struct dentry *debugfs; 113 struct dentry *debugfs;
114 114
115 spinlock_t lock;
116 115
117 unsigned long total_data; 116 unsigned long total_data;
118 unsigned int size_loaded; 117 unsigned int size_loaded;
@@ -136,7 +135,6 @@ struct s3c_hsotg_ep {
136 * @driver: USB gadget driver 135 * @driver: USB gadget driver
137 * @plat: The platform specific configuration data. 136 * @plat: The platform specific configuration data.
138 * @regs: The memory area mapped for accessing registers. 137 * @regs: The memory area mapped for accessing registers.
139 * @regs_res: The resource that was allocated when claiming register space.
140 * @irq: The IRQ number we are using 138 * @irq: The IRQ number we are using
141 * @supplies: Definition of USB power supplies 139 * @supplies: Definition of USB power supplies
142 * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. 140 * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
@@ -157,8 +155,9 @@ struct s3c_hsotg {
157 struct usb_gadget_driver *driver; 155 struct usb_gadget_driver *driver;
158 struct s3c_hsotg_plat *plat; 156 struct s3c_hsotg_plat *plat;
159 157
158 spinlock_t lock;
159
160 void __iomem *regs; 160 void __iomem *regs;
161 struct resource *regs_res;
162 int irq; 161 int irq;
163 struct clk *clk; 162 struct clk *clk;
164 163
@@ -896,7 +895,6 @@ static int s3c_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req,
896 struct s3c_hsotg_req *hs_req = our_req(req); 895 struct s3c_hsotg_req *hs_req = our_req(req);
897 struct s3c_hsotg_ep *hs_ep = our_ep(ep); 896 struct s3c_hsotg_ep *hs_ep = our_ep(ep);
898 struct s3c_hsotg *hs = hs_ep->parent; 897 struct s3c_hsotg *hs = hs_ep->parent;
899 unsigned long irqflags;
900 bool first; 898 bool first;
901 899
902 dev_dbg(hs->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n", 900 dev_dbg(hs->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n",
@@ -915,19 +913,30 @@ static int s3c_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req,
915 return ret; 913 return ret;
916 } 914 }
917 915
918 spin_lock_irqsave(&hs_ep->lock, irqflags);
919
920 first = list_empty(&hs_ep->queue); 916 first = list_empty(&hs_ep->queue);
921 list_add_tail(&hs_req->queue, &hs_ep->queue); 917 list_add_tail(&hs_req->queue, &hs_ep->queue);
922 918
923 if (first) 919 if (first)
924 s3c_hsotg_start_req(hs, hs_ep, hs_req, false); 920 s3c_hsotg_start_req(hs, hs_ep, hs_req, false);
925 921
926 spin_unlock_irqrestore(&hs_ep->lock, irqflags);
927
928 return 0; 922 return 0;
929} 923}
930 924
925static int s3c_hsotg_ep_queue_lock(struct usb_ep *ep, struct usb_request *req,
926 gfp_t gfp_flags)
927{
928 struct s3c_hsotg_ep *hs_ep = our_ep(ep);
929 struct s3c_hsotg *hs = hs_ep->parent;
930 unsigned long flags = 0;
931 int ret = 0;
932
933 spin_lock_irqsave(&hs->lock, flags);
934 ret = s3c_hsotg_ep_queue(ep, req, gfp_flags);
935 spin_unlock_irqrestore(&hs->lock, flags);
936
937 return ret;
938}
939
931static void s3c_hsotg_ep_free_request(struct usb_ep *ep, 940static void s3c_hsotg_ep_free_request(struct usb_ep *ep,
932 struct usb_request *req) 941 struct usb_request *req)
933{ 942{
@@ -1383,9 +1392,9 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg,
1383 */ 1392 */
1384 1393
1385 if (hs_req->req.complete) { 1394 if (hs_req->req.complete) {
1386 spin_unlock(&hs_ep->lock); 1395 spin_unlock(&hsotg->lock);
1387 hs_req->req.complete(&hs_ep->ep, &hs_req->req); 1396 hs_req->req.complete(&hs_ep->ep, &hs_req->req);
1388 spin_lock(&hs_ep->lock); 1397 spin_lock(&hsotg->lock);
1389 } 1398 }
1390 1399
1391 /* 1400 /*
@@ -1404,28 +1413,6 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg,
1404} 1413}
1405 1414
1406/** 1415/**
1407 * s3c_hsotg_complete_request_lock - complete a request given to us (locked)
1408 * @hsotg: The device state.
1409 * @hs_ep: The endpoint the request was on.
1410 * @hs_req: The request to complete.
1411 * @result: The result code (0 => Ok, otherwise errno)
1412 *
1413 * See s3c_hsotg_complete_request(), but called with the endpoint's
1414 * lock held.
1415 */
1416static void s3c_hsotg_complete_request_lock(struct s3c_hsotg *hsotg,
1417 struct s3c_hsotg_ep *hs_ep,
1418 struct s3c_hsotg_req *hs_req,
1419 int result)
1420{
1421 unsigned long flags;
1422
1423 spin_lock_irqsave(&hs_ep->lock, flags);
1424 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, result);
1425 spin_unlock_irqrestore(&hs_ep->lock, flags);
1426}
1427
1428/**
1429 * s3c_hsotg_rx_data - receive data from the FIFO for an endpoint 1416 * s3c_hsotg_rx_data - receive data from the FIFO for an endpoint
1430 * @hsotg: The device state. 1417 * @hsotg: The device state.
1431 * @ep_idx: The endpoint index for the data 1418 * @ep_idx: The endpoint index for the data
@@ -1444,6 +1431,7 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size)
1444 int max_req; 1431 int max_req;
1445 int read_ptr; 1432 int read_ptr;
1446 1433
1434
1447 if (!hs_req) { 1435 if (!hs_req) {
1448 u32 epctl = readl(hsotg->regs + DOEPCTL(ep_idx)); 1436 u32 epctl = readl(hsotg->regs + DOEPCTL(ep_idx));
1449 int ptr; 1437 int ptr;
@@ -1459,8 +1447,6 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size)
1459 return; 1447 return;
1460 } 1448 }
1461 1449
1462 spin_lock(&hs_ep->lock);
1463
1464 to_read = size; 1450 to_read = size;
1465 read_ptr = hs_req->req.actual; 1451 read_ptr = hs_req->req.actual;
1466 max_req = hs_req->req.length - read_ptr; 1452 max_req = hs_req->req.length - read_ptr;
@@ -1487,8 +1473,6 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size)
1487 * alignment of the data. 1473 * alignment of the data.
1488 */ 1474 */
1489 readsl(fifo, hs_req->req.buf + read_ptr, to_read); 1475 readsl(fifo, hs_req->req.buf + read_ptr, to_read);
1490
1491 spin_unlock(&hs_ep->lock);
1492} 1476}
1493 1477
1494/** 1478/**
@@ -1609,7 +1593,7 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg,
1609 s3c_hsotg_send_zlp(hsotg, hs_req); 1593 s3c_hsotg_send_zlp(hsotg, hs_req);
1610 } 1594 }
1611 1595
1612 s3c_hsotg_complete_request_lock(hsotg, hs_ep, hs_req, result); 1596 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, result);
1613} 1597}
1614 1598
1615/** 1599/**
@@ -1864,7 +1848,7 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg,
1864 /* Finish ZLP handling for IN EP0 transactions */ 1848 /* Finish ZLP handling for IN EP0 transactions */
1865 if (hsotg->eps[0].sent_zlp) { 1849 if (hsotg->eps[0].sent_zlp) {
1866 dev_dbg(hsotg->dev, "zlp packet received\n"); 1850 dev_dbg(hsotg->dev, "zlp packet received\n");
1867 s3c_hsotg_complete_request_lock(hsotg, hs_ep, hs_req, 0); 1851 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0);
1868 return; 1852 return;
1869 } 1853 }
1870 1854
@@ -1915,7 +1899,7 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg,
1915 dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); 1899 dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__);
1916 s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); 1900 s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true);
1917 } else 1901 } else
1918 s3c_hsotg_complete_request_lock(hsotg, hs_ep, hs_req, 0); 1902 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0);
1919} 1903}
1920 1904
1921/** 1905/**
@@ -2123,9 +2107,6 @@ static void kill_all_requests(struct s3c_hsotg *hsotg,
2123 int result, bool force) 2107 int result, bool force)
2124{ 2108{
2125 struct s3c_hsotg_req *req, *treq; 2109 struct s3c_hsotg_req *req, *treq;
2126 unsigned long flags;
2127
2128 spin_lock_irqsave(&ep->lock, flags);
2129 2110
2130 list_for_each_entry_safe(req, treq, &ep->queue, queue) { 2111 list_for_each_entry_safe(req, treq, &ep->queue, queue) {
2131 /* 2112 /*
@@ -2139,14 +2120,15 @@ static void kill_all_requests(struct s3c_hsotg *hsotg,
2139 s3c_hsotg_complete_request(hsotg, ep, req, 2120 s3c_hsotg_complete_request(hsotg, ep, req,
2140 result); 2121 result);
2141 } 2122 }
2142
2143 spin_unlock_irqrestore(&ep->lock, flags);
2144} 2123}
2145 2124
2146#define call_gadget(_hs, _entry) \ 2125#define call_gadget(_hs, _entry) \
2147 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ 2126 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
2148 (_hs)->driver && (_hs)->driver->_entry) \ 2127 (_hs)->driver && (_hs)->driver->_entry) { \
2149 (_hs)->driver->_entry(&(_hs)->gadget); 2128 spin_unlock(&_hs->lock); \
2129 (_hs)->driver->_entry(&(_hs)->gadget); \
2130 spin_lock(&_hs->lock); \
2131 }
2150 2132
2151/** 2133/**
2152 * s3c_hsotg_disconnect - disconnect service 2134 * s3c_hsotg_disconnect - disconnect service
@@ -2388,6 +2370,7 @@ static irqreturn_t s3c_hsotg_irq(int irq, void *pw)
2388 u32 gintsts; 2370 u32 gintsts;
2389 u32 gintmsk; 2371 u32 gintmsk;
2390 2372
2373 spin_lock(&hsotg->lock);
2391irq_retry: 2374irq_retry:
2392 gintsts = readl(hsotg->regs + GINTSTS); 2375 gintsts = readl(hsotg->regs + GINTSTS);
2393 gintmsk = readl(hsotg->regs + GINTMSK); 2376 gintmsk = readl(hsotg->regs + GINTMSK);
@@ -2557,6 +2540,8 @@ irq_retry:
2557 if (gintsts & IRQ_RETRY_MASK && --retry_count > 0) 2540 if (gintsts & IRQ_RETRY_MASK && --retry_count > 0)
2558 goto irq_retry; 2541 goto irq_retry;
2559 2542
2543 spin_unlock(&hsotg->lock);
2544
2560 return IRQ_HANDLED; 2545 return IRQ_HANDLED;
2561} 2546}
2562 2547
@@ -2604,7 +2589,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2604 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", 2589 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n",
2605 __func__, epctrl, epctrl_reg); 2590 __func__, epctrl, epctrl_reg);
2606 2591
2607 spin_lock_irqsave(&hs_ep->lock, flags); 2592 spin_lock_irqsave(&hsotg->lock, flags);
2608 2593
2609 epctrl &= ~(DxEPCTL_EPType_MASK | DxEPCTL_MPS_MASK); 2594 epctrl &= ~(DxEPCTL_EPType_MASK | DxEPCTL_MPS_MASK);
2610 epctrl |= DxEPCTL_MPS(mps); 2595 epctrl |= DxEPCTL_MPS(mps);
@@ -2683,7 +2668,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2683 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); 2668 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
2684 2669
2685out: 2670out:
2686 spin_unlock_irqrestore(&hs_ep->lock, flags); 2671 spin_unlock_irqrestore(&hsotg->lock, flags);
2687 return ret; 2672 return ret;
2688} 2673}
2689 2674
@@ -2710,10 +2695,10 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep)
2710 2695
2711 epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); 2696 epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index);
2712 2697
2698 spin_lock_irqsave(&hsotg->lock, flags);
2713 /* terminate all requests with shutdown */ 2699 /* terminate all requests with shutdown */
2714 kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false); 2700 kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false);
2715 2701
2716 spin_lock_irqsave(&hs_ep->lock, flags);
2717 2702
2718 ctrl = readl(hsotg->regs + epctrl_reg); 2703 ctrl = readl(hsotg->regs + epctrl_reg);
2719 ctrl &= ~DxEPCTL_EPEna; 2704 ctrl &= ~DxEPCTL_EPEna;
@@ -2726,7 +2711,7 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep)
2726 /* disable endpoint interrupts */ 2711 /* disable endpoint interrupts */
2727 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0); 2712 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0);
2728 2713
2729 spin_unlock_irqrestore(&hs_ep->lock, flags); 2714 spin_unlock_irqrestore(&hsotg->lock, flags);
2730 return 0; 2715 return 0;
2731} 2716}
2732 2717
@@ -2761,15 +2746,15 @@ static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
2761 2746
2762 dev_info(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); 2747 dev_info(hs->dev, "ep_dequeue(%p,%p)\n", ep, req);
2763 2748
2764 spin_lock_irqsave(&hs_ep->lock, flags); 2749 spin_lock_irqsave(&hs->lock, flags);
2765 2750
2766 if (!on_list(hs_ep, hs_req)) { 2751 if (!on_list(hs_ep, hs_req)) {
2767 spin_unlock_irqrestore(&hs_ep->lock, flags); 2752 spin_unlock_irqrestore(&hs->lock, flags);
2768 return -EINVAL; 2753 return -EINVAL;
2769 } 2754 }
2770 2755
2771 s3c_hsotg_complete_request(hs, hs_ep, hs_req, -ECONNRESET); 2756 s3c_hsotg_complete_request(hs, hs_ep, hs_req, -ECONNRESET);
2772 spin_unlock_irqrestore(&hs_ep->lock, flags); 2757 spin_unlock_irqrestore(&hs->lock, flags);
2773 2758
2774 return 0; 2759 return 0;
2775} 2760}
@@ -2784,15 +2769,12 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value)
2784 struct s3c_hsotg_ep *hs_ep = our_ep(ep); 2769 struct s3c_hsotg_ep *hs_ep = our_ep(ep);
2785 struct s3c_hsotg *hs = hs_ep->parent; 2770 struct s3c_hsotg *hs = hs_ep->parent;
2786 int index = hs_ep->index; 2771 int index = hs_ep->index;
2787 unsigned long irqflags;
2788 u32 epreg; 2772 u32 epreg;
2789 u32 epctl; 2773 u32 epctl;
2790 u32 xfertype; 2774 u32 xfertype;
2791 2775
2792 dev_info(hs->dev, "%s(ep %p %s, %d)\n", __func__, ep, ep->name, value); 2776 dev_info(hs->dev, "%s(ep %p %s, %d)\n", __func__, ep, ep->name, value);
2793 2777
2794 spin_lock_irqsave(&hs_ep->lock, irqflags);
2795
2796 /* write both IN and OUT control registers */ 2778 /* write both IN and OUT control registers */
2797 2779
2798 epreg = DIEPCTL(index); 2780 epreg = DIEPCTL(index);
@@ -2827,19 +2809,36 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value)
2827 2809
2828 writel(epctl, hs->regs + epreg); 2810 writel(epctl, hs->regs + epreg);
2829 2811
2830 spin_unlock_irqrestore(&hs_ep->lock, irqflags);
2831
2832 return 0; 2812 return 0;
2833} 2813}
2834 2814
2815/**
2816 * s3c_hsotg_ep_sethalt_lock - set halt on a given endpoint with lock held
2817 * @ep: The endpoint to set halt.
2818 * @value: Set or unset the halt.
2819 */
2820static int s3c_hsotg_ep_sethalt_lock(struct usb_ep *ep, int value)
2821{
2822 struct s3c_hsotg_ep *hs_ep = our_ep(ep);
2823 struct s3c_hsotg *hs = hs_ep->parent;
2824 unsigned long flags = 0;
2825 int ret = 0;
2826
2827 spin_lock_irqsave(&hs->lock, flags);
2828 ret = s3c_hsotg_ep_sethalt(ep, value);
2829 spin_unlock_irqrestore(&hs->lock, flags);
2830
2831 return ret;
2832}
2833
2835static struct usb_ep_ops s3c_hsotg_ep_ops = { 2834static struct usb_ep_ops s3c_hsotg_ep_ops = {
2836 .enable = s3c_hsotg_ep_enable, 2835 .enable = s3c_hsotg_ep_enable,
2837 .disable = s3c_hsotg_ep_disable, 2836 .disable = s3c_hsotg_ep_disable,
2838 .alloc_request = s3c_hsotg_ep_alloc_request, 2837 .alloc_request = s3c_hsotg_ep_alloc_request,
2839 .free_request = s3c_hsotg_ep_free_request, 2838 .free_request = s3c_hsotg_ep_free_request,
2840 .queue = s3c_hsotg_ep_queue, 2839 .queue = s3c_hsotg_ep_queue_lock,
2841 .dequeue = s3c_hsotg_ep_dequeue, 2840 .dequeue = s3c_hsotg_ep_dequeue,
2842 .set_halt = s3c_hsotg_ep_sethalt, 2841 .set_halt = s3c_hsotg_ep_sethalt_lock,
2843 /* note, don't believe we have any call for the fifo routines */ 2842 /* note, don't believe we have any call for the fifo routines */
2844}; 2843};
2845 2844
@@ -2954,6 +2953,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
2954 driver->driver.bus = NULL; 2953 driver->driver.bus = NULL;
2955 hsotg->driver = driver; 2954 hsotg->driver = driver;
2956 hsotg->gadget.dev.driver = &driver->driver; 2955 hsotg->gadget.dev.driver = &driver->driver;
2956 hsotg->gadget.dev.of_node = hsotg->dev->of_node;
2957 hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask; 2957 hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask;
2958 hsotg->gadget.speed = USB_SPEED_UNKNOWN; 2958 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
2959 2959
@@ -2964,9 +2964,6 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
2964 goto err; 2964 goto err;
2965 } 2965 }
2966 2966
2967 s3c_hsotg_phy_enable(hsotg);
2968
2969 s3c_hsotg_core_init(hsotg);
2970 hsotg->last_rst = jiffies; 2967 hsotg->last_rst = jiffies;
2971 dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); 2968 dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name);
2972 return 0; 2969 return 0;
@@ -2988,6 +2985,7 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
2988 struct usb_gadget_driver *driver) 2985 struct usb_gadget_driver *driver)
2989{ 2986{
2990 struct s3c_hsotg *hsotg = to_hsotg(gadget); 2987 struct s3c_hsotg *hsotg = to_hsotg(gadget);
2988 unsigned long flags = 0;
2991 int ep; 2989 int ep;
2992 2990
2993 if (!hsotg) 2991 if (!hsotg)
@@ -3000,6 +2998,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
3000 for (ep = 0; ep < hsotg->num_of_eps; ep++) 2998 for (ep = 0; ep < hsotg->num_of_eps; ep++)
3001 s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); 2999 s3c_hsotg_ep_disable(&hsotg->eps[ep].ep);
3002 3000
3001 spin_lock_irqsave(&hsotg->lock, flags);
3002
3003 s3c_hsotg_phy_disable(hsotg); 3003 s3c_hsotg_phy_disable(hsotg);
3004 regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); 3004 regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
3005 3005
@@ -3007,6 +3007,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
3007 hsotg->gadget.speed = USB_SPEED_UNKNOWN; 3007 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
3008 hsotg->gadget.dev.driver = NULL; 3008 hsotg->gadget.dev.driver = NULL;
3009 3009
3010 spin_unlock_irqrestore(&hsotg->lock, flags);
3011
3010 dev_info(hsotg->dev, "unregistered gadget driver '%s'\n", 3012 dev_info(hsotg->dev, "unregistered gadget driver '%s'\n",
3011 driver->driver.name); 3013 driver->driver.name);
3012 3014
@@ -3024,10 +3026,40 @@ static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget)
3024 return s3c_hsotg_read_frameno(to_hsotg(gadget)); 3026 return s3c_hsotg_read_frameno(to_hsotg(gadget));
3025} 3027}
3026 3028
3029/**
3030 * s3c_hsotg_pullup - connect/disconnect the USB PHY
3031 * @gadget: The usb gadget state
3032 * @is_on: Current state of the USB PHY
3033 *
3034 * Connect/Disconnect the USB PHY pullup
3035 */
3036static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)
3037{
3038 struct s3c_hsotg *hsotg = to_hsotg(gadget);
3039 unsigned long flags = 0;
3040
3041 dev_dbg(hsotg->dev, "%s: is_in: %d\n", __func__, is_on);
3042
3043 spin_lock_irqsave(&hsotg->lock, flags);
3044 if (is_on) {
3045 s3c_hsotg_phy_enable(hsotg);
3046 s3c_hsotg_core_init(hsotg);
3047 } else {
3048 s3c_hsotg_disconnect(hsotg);
3049 s3c_hsotg_phy_disable(hsotg);
3050 }
3051
3052 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
3053 spin_unlock_irqrestore(&hsotg->lock, flags);
3054
3055 return 0;
3056}
3057
3027static struct usb_gadget_ops s3c_hsotg_gadget_ops = { 3058static struct usb_gadget_ops s3c_hsotg_gadget_ops = {
3028 .get_frame = s3c_hsotg_gadget_getframe, 3059 .get_frame = s3c_hsotg_gadget_getframe,
3029 .udc_start = s3c_hsotg_udc_start, 3060 .udc_start = s3c_hsotg_udc_start,
3030 .udc_stop = s3c_hsotg_udc_stop, 3061 .udc_stop = s3c_hsotg_udc_stop,
3062 .pullup = s3c_hsotg_pullup,
3031}; 3063};
3032 3064
3033/** 3065/**
@@ -3063,8 +3095,6 @@ static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg,
3063 INIT_LIST_HEAD(&hs_ep->queue); 3095 INIT_LIST_HEAD(&hs_ep->queue);
3064 INIT_LIST_HEAD(&hs_ep->ep.ep_list); 3096 INIT_LIST_HEAD(&hs_ep->ep.ep_list);
3065 3097
3066 spin_lock_init(&hs_ep->lock);
3067
3068 /* add to the list of endpoints known by the gadget driver */ 3098 /* add to the list of endpoints known by the gadget driver */
3069 if (epnum) 3099 if (epnum)
3070 list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list); 3100 list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list);
@@ -3342,7 +3372,7 @@ static int ep_show(struct seq_file *seq, void *v)
3342 seq_printf(seq, "request list (%p,%p):\n", 3372 seq_printf(seq, "request list (%p,%p):\n",
3343 ep->queue.next, ep->queue.prev); 3373 ep->queue.next, ep->queue.prev);
3344 3374
3345 spin_lock_irqsave(&ep->lock, flags); 3375 spin_lock_irqsave(&hsotg->lock, flags);
3346 3376
3347 list_for_each_entry(req, &ep->queue, queue) { 3377 list_for_each_entry(req, &ep->queue, queue) {
3348 if (--show_limit < 0) { 3378 if (--show_limit < 0) {
@@ -3357,7 +3387,7 @@ static int ep_show(struct seq_file *seq, void *v)
3357 req->req.actual, req->req.status); 3387 req->req.actual, req->req.status);
3358 } 3388 }
3359 3389
3360 spin_unlock_irqrestore(&ep->lock, flags); 3390 spin_unlock_irqrestore(&hsotg->lock, flags);
3361 3391
3362 return 0; 3392 return 0;
3363} 3393}
@@ -3477,7 +3507,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3477 return -EINVAL; 3507 return -EINVAL;
3478 } 3508 }
3479 3509
3480 hsotg = kzalloc(sizeof(struct s3c_hsotg), GFP_KERNEL); 3510 hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL);
3481 if (!hsotg) { 3511 if (!hsotg) {
3482 dev_err(dev, "cannot get memory\n"); 3512 dev_err(dev, "cannot get memory\n");
3483 return -ENOMEM; 3513 return -ENOMEM;
@@ -3489,46 +3519,35 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3489 hsotg->clk = clk_get(&pdev->dev, "otg"); 3519 hsotg->clk = clk_get(&pdev->dev, "otg");
3490 if (IS_ERR(hsotg->clk)) { 3520 if (IS_ERR(hsotg->clk)) {
3491 dev_err(dev, "cannot get otg clock\n"); 3521 dev_err(dev, "cannot get otg clock\n");
3492 ret = PTR_ERR(hsotg->clk); 3522 return PTR_ERR(hsotg->clk);
3493 goto err_mem;
3494 } 3523 }
3495 3524
3496 platform_set_drvdata(pdev, hsotg); 3525 platform_set_drvdata(pdev, hsotg);
3497 3526
3498 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 3527 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3499 if (!res) {
3500 dev_err(dev, "cannot find register resource 0\n");
3501 ret = -EINVAL;
3502 goto err_clk;
3503 }
3504
3505 hsotg->regs_res = request_mem_region(res->start, resource_size(res),
3506 dev_name(dev));
3507 if (!hsotg->regs_res) {
3508 dev_err(dev, "cannot reserve registers\n");
3509 ret = -ENOENT;
3510 goto err_clk;
3511 }
3512 3528
3513 hsotg->regs = ioremap(res->start, resource_size(res)); 3529 hsotg->regs = devm_request_and_ioremap(&pdev->dev, res);
3514 if (!hsotg->regs) { 3530 if (!hsotg->regs) {
3515 dev_err(dev, "cannot map registers\n"); 3531 dev_err(dev, "cannot map registers\n");
3516 ret = -ENXIO; 3532 ret = -ENXIO;
3517 goto err_regs_res; 3533 goto err_clk;
3518 } 3534 }
3519 3535
3520 ret = platform_get_irq(pdev, 0); 3536 ret = platform_get_irq(pdev, 0);
3521 if (ret < 0) { 3537 if (ret < 0) {
3522 dev_err(dev, "cannot find IRQ\n"); 3538 dev_err(dev, "cannot find IRQ\n");
3523 goto err_regs; 3539 goto err_clk;
3524 } 3540 }
3525 3541
3542 spin_lock_init(&hsotg->lock);
3543
3526 hsotg->irq = ret; 3544 hsotg->irq = ret;
3527 3545
3528 ret = request_irq(ret, s3c_hsotg_irq, 0, dev_name(dev), hsotg); 3546 ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0,
3547 dev_name(dev), hsotg);
3529 if (ret < 0) { 3548 if (ret < 0) {
3530 dev_err(dev, "cannot claim IRQ\n"); 3549 dev_err(dev, "cannot claim IRQ\n");
3531 goto err_regs; 3550 goto err_clk;
3532 } 3551 }
3533 3552
3534 dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq); 3553 dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq);
@@ -3558,7 +3577,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3558 hsotg->supplies); 3577 hsotg->supplies);
3559 if (ret) { 3578 if (ret) {
3560 dev_err(dev, "failed to request supplies: %d\n", ret); 3579 dev_err(dev, "failed to request supplies: %d\n", ret);
3561 goto err_irq; 3580 goto err_clk;
3562 } 3581 }
3563 3582
3564 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), 3583 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
@@ -3642,19 +3661,11 @@ err_ep_mem:
3642err_supplies: 3661err_supplies:
3643 s3c_hsotg_phy_disable(hsotg); 3662 s3c_hsotg_phy_disable(hsotg);
3644 regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); 3663 regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
3645err_irq: 3664
3646 free_irq(hsotg->irq, hsotg);
3647err_regs:
3648 iounmap(hsotg->regs);
3649
3650err_regs_res:
3651 release_resource(hsotg->regs_res);
3652 kfree(hsotg->regs_res);
3653err_clk: 3665err_clk:
3654 clk_disable_unprepare(hsotg->clk); 3666 clk_disable_unprepare(hsotg->clk);
3655 clk_put(hsotg->clk); 3667 clk_put(hsotg->clk);
3656err_mem: 3668
3657 kfree(hsotg);
3658 return ret; 3669 return ret;
3659} 3670}
3660 3671
@@ -3675,12 +3686,6 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev)
3675 usb_gadget_unregister_driver(hsotg->driver); 3686 usb_gadget_unregister_driver(hsotg->driver);
3676 } 3687 }
3677 3688
3678 free_irq(hsotg->irq, hsotg);
3679 iounmap(hsotg->regs);
3680
3681 release_resource(hsotg->regs_res);
3682 kfree(hsotg->regs_res);
3683
3684 s3c_hsotg_phy_disable(hsotg); 3689 s3c_hsotg_phy_disable(hsotg);
3685 regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); 3690 regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
3686 3691
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index 236b271871a0..e26a4e7ed2bf 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -24,6 +24,7 @@
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/clk.h> 26#include <linux/clk.h>
27#include <linux/err.h>
27#include <linux/usb/ch9.h> 28#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h> 29#include <linux/usb/gadget.h>
29#include <linux/usb/otg.h> 30#include <linux/usb/otg.h>
@@ -1165,7 +1166,7 @@ static int s3c_hsudc_start(struct usb_gadget *gadget,
1165 } 1166 }
1166 1167
1167 /* connect to bus through transceiver */ 1168 /* connect to bus through transceiver */
1168 if (hsudc->transceiver) { 1169 if (!IS_ERR_OR_NULL(hsudc->transceiver)) {
1169 ret = otg_set_peripheral(hsudc->transceiver->otg, 1170 ret = otg_set_peripheral(hsudc->transceiver->otg,
1170 &hsudc->gadget); 1171 &hsudc->gadget);
1171 if (ret) { 1172 if (ret) {
@@ -1220,7 +1221,7 @@ static int s3c_hsudc_stop(struct usb_gadget *gadget,
1220 s3c_hsudc_stop_activity(hsudc); 1221 s3c_hsudc_stop_activity(hsudc);
1221 spin_unlock_irqrestore(&hsudc->lock, flags); 1222 spin_unlock_irqrestore(&hsudc->lock, flags);
1222 1223
1223 if (hsudc->transceiver) 1224 if (!IS_ERR_OR_NULL(hsudc->transceiver))
1224 (void) otg_set_peripheral(hsudc->transceiver->otg, NULL); 1225 (void) otg_set_peripheral(hsudc->transceiver->otg, NULL);
1225 1226
1226 disable_irq(hsudc->irq); 1227 disable_irq(hsudc->irq);
@@ -1249,7 +1250,7 @@ static int s3c_hsudc_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1249 if (!hsudc) 1250 if (!hsudc)
1250 return -ENODEV; 1251 return -ENODEV;
1251 1252
1252 if (hsudc->transceiver) 1253 if (!IS_ERR_OR_NULL(hsudc->transceiver))
1253 return usb_phy_set_power(hsudc->transceiver, mA); 1254 return usb_phy_set_power(hsudc->transceiver, mA);
1254 1255
1255 return -EOPNOTSUPP; 1256 return -EOPNOTSUPP;
@@ -1282,7 +1283,7 @@ static int __devinit s3c_hsudc_probe(struct platform_device *pdev)
1282 hsudc->dev = dev; 1283 hsudc->dev = dev;
1283 hsudc->pd = pdev->dev.platform_data; 1284 hsudc->pd = pdev->dev.platform_data;
1284 1285
1285 hsudc->transceiver = usb_get_transceiver(); 1286 hsudc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
1286 1287
1287 for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++) 1288 for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++)
1288 hsudc->supplies[i].supply = s3c_hsudc_supply_names[i]; 1289 hsudc->supplies[i].supply = s3c_hsudc_supply_names[i];
@@ -1385,8 +1386,8 @@ err_irq:
1385err_remap: 1386err_remap:
1386 release_mem_region(res->start, resource_size(res)); 1387 release_mem_region(res->start, resource_size(res));
1387err_res: 1388err_res:
1388 if (hsudc->transceiver) 1389 if (!IS_ERR_OR_NULL(hsudc->transceiver))
1389 usb_put_transceiver(hsudc->transceiver); 1390 usb_put_phy(hsudc->transceiver);
1390 1391
1391 regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1392 regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies);
1392err_supplies: 1393err_supplies:
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 8081ca3a70a2..ae8b18869b8c 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -38,12 +38,6 @@
38 */ 38 */
39 39
40/* 40/*
41 * When FSG_BUFFHD_STATIC_BUFFER is defined when this file is included
42 * the fsg_buffhd structure's buf field will be an array of FSG_BUFLEN
43 * characters rather then a pointer to void.
44 */
45
46/*
47 * When USB_GADGET_DEBUG_FILES is defined the module param num_buffers 41 * When USB_GADGET_DEBUG_FILES is defined the module param num_buffers
48 * sets the number of pipeline buffers (length of the fsg_buffhd array). 42 * sets the number of pipeline buffers (length of the fsg_buffhd array).
49 * The valid range of num_buffers is: num >= 2 && num <= 4. 43 * The valid range of num_buffers is: num >= 2 && num <= 4.
@@ -260,11 +254,7 @@ enum fsg_buffer_state {
260}; 254};
261 255
262struct fsg_buffhd { 256struct fsg_buffhd {
263#ifdef FSG_BUFFHD_STATIC_BUFFER
264 char buf[FSG_BUFLEN];
265#else
266 void *buf; 257 void *buf;
267#endif
268 enum fsg_buffer_state state; 258 enum fsg_buffer_state state;
269 struct fsg_buffhd *next; 259 struct fsg_buffhd *next;
270 260
@@ -627,6 +617,16 @@ static struct usb_gadget_strings fsg_stringtab = {
627 * the caller must own fsg->filesem for writing. 617 * the caller must own fsg->filesem for writing.
628 */ 618 */
629 619
620static void fsg_lun_close(struct fsg_lun *curlun)
621{
622 if (curlun->filp) {
623 LDBG(curlun, "close backing file\n");
624 fput(curlun->filp);
625 curlun->filp = NULL;
626 }
627}
628
629
630static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) 630static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
631{ 631{
632 int ro; 632 int ro;
@@ -636,6 +636,8 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
636 loff_t size; 636 loff_t size;
637 loff_t num_sectors; 637 loff_t num_sectors;
638 loff_t min_sectors; 638 loff_t min_sectors;
639 unsigned int blkbits;
640 unsigned int blksize;
639 641
640 /* R/W if we can, R/O if we must */ 642 /* R/W if we can, R/O if we must */
641 ro = curlun->initially_ro; 643 ro = curlun->initially_ro;
@@ -680,17 +682,17 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
680 } 682 }
681 683
682 if (curlun->cdrom) { 684 if (curlun->cdrom) {
683 curlun->blksize = 2048; 685 blksize = 2048;
684 curlun->blkbits = 11; 686 blkbits = 11;
685 } else if (inode->i_bdev) { 687 } else if (inode->i_bdev) {
686 curlun->blksize = bdev_logical_block_size(inode->i_bdev); 688 blksize = bdev_logical_block_size(inode->i_bdev);
687 curlun->blkbits = blksize_bits(curlun->blksize); 689 blkbits = blksize_bits(blksize);
688 } else { 690 } else {
689 curlun->blksize = 512; 691 blksize = 512;
690 curlun->blkbits = 9; 692 blkbits = 9;
691 } 693 }
692 694
693 num_sectors = size >> curlun->blkbits; /* File size in logic-block-size blocks */ 695 num_sectors = size >> blkbits; /* File size in logic-block-size blocks */
694 min_sectors = 1; 696 min_sectors = 1;
695 if (curlun->cdrom) { 697 if (curlun->cdrom) {
696 min_sectors = 300; /* Smallest track is 300 frames */ 698 min_sectors = 300; /* Smallest track is 300 frames */
@@ -707,7 +709,12 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
707 goto out; 709 goto out;
708 } 710 }
709 711
712 if (fsg_lun_is_open(curlun))
713 fsg_lun_close(curlun);
714
710 get_file(filp); 715 get_file(filp);
716 curlun->blksize = blksize;
717 curlun->blkbits = blkbits;
711 curlun->ro = ro; 718 curlun->ro = ro;
712 curlun->filp = filp; 719 curlun->filp = filp;
713 curlun->file_length = size; 720 curlun->file_length = size;
@@ -721,16 +728,6 @@ out:
721} 728}
722 729
723 730
724static void fsg_lun_close(struct fsg_lun *curlun)
725{
726 if (curlun->filp) {
727 LDBG(curlun, "close backing file\n");
728 fput(curlun->filp);
729 curlun->filp = NULL;
730 }
731}
732
733
734/*-------------------------------------------------------------------------*/ 731/*-------------------------------------------------------------------------*/
735 732
736/* 733/*
@@ -881,19 +878,17 @@ static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
881 if (count > 0 && buf[count-1] == '\n') 878 if (count > 0 && buf[count-1] == '\n')
882 ((char *) buf)[count-1] = 0; /* Ugh! */ 879 ((char *) buf)[count-1] = 0; /* Ugh! */
883 880
884 /* Eject current medium */
885 down_write(filesem);
886 if (fsg_lun_is_open(curlun)) {
887 fsg_lun_close(curlun);
888 curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
889 }
890
891 /* Load new medium */ 881 /* Load new medium */
882 down_write(filesem);
892 if (count > 0 && buf[0]) { 883 if (count > 0 && buf[0]) {
884 /* fsg_lun_open() will close existing file if any. */
893 rc = fsg_lun_open(curlun, buf); 885 rc = fsg_lun_open(curlun, buf);
894 if (rc == 0) 886 if (rc == 0)
895 curlun->unit_attention_data = 887 curlun->unit_attention_data =
896 SS_NOT_READY_TO_READY_TRANSITION; 888 SS_NOT_READY_TO_READY_TRANSITION;
889 } else if (fsg_lun_is_open(curlun)) {
890 fsg_lun_close(curlun);
891 curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
897 } 892 }
898 up_write(filesem); 893 up_write(filesem);
899 return (rc < 0 ? rc : count); 894 return (rc < 0 ? rc : count);
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 47cf48b51c9d..5b46f022d0f0 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -798,12 +798,6 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
798 798
799 SET_ETHTOOL_OPS(net, &ops); 799 SET_ETHTOOL_OPS(net, &ops);
800 800
801 /* two kinds of host-initiated state changes:
802 * - iff DATA transfer is active, carrier is "on"
803 * - tx queueing enabled if open *and* carrier is "on"
804 */
805 netif_carrier_off(net);
806
807 dev->gadget = g; 801 dev->gadget = g;
808 SET_NETDEV_DEV(net, &g->dev); 802 SET_NETDEV_DEV(net, &g->dev);
809 SET_NETDEV_DEVTYPE(net, &gadget_type); 803 SET_NETDEV_DEVTYPE(net, &gadget_type);
@@ -817,6 +811,12 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
817 INFO(dev, "HOST MAC %pM\n", dev->host_mac); 811 INFO(dev, "HOST MAC %pM\n", dev->host_mac);
818 812
819 the_dev = dev; 813 the_dev = dev;
814
815 /* two kinds of host-initiated state changes:
816 * - iff DATA transfer is active, carrier is "on"
817 * - tx queueing enabled if open *and* carrier is "on"
818 */
819 netif_carrier_off(net);
820 } 820 }
821 821
822 return status; 822 return status;
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h
index ca4e03a1c73a..93b0c1191115 100644
--- a/drivers/usb/gadget/uvc.h
+++ b/drivers/usb/gadget/uvc.h
@@ -153,9 +153,11 @@ struct uvc_device
153 153
154 /* Descriptors */ 154 /* Descriptors */
155 struct { 155 struct {
156 const struct uvc_descriptor_header * const *control; 156 const struct uvc_descriptor_header * const *fs_control;
157 const struct uvc_descriptor_header * const *ss_control;
157 const struct uvc_descriptor_header * const *fs_streaming; 158 const struct uvc_descriptor_header * const *fs_streaming;
158 const struct uvc_descriptor_header * const *hs_streaming; 159 const struct uvc_descriptor_header * const *hs_streaming;
160 const struct uvc_descriptor_header * const *ss_streaming;
159 } desc; 161 } desc;
160 162
161 unsigned int control_intf; 163 unsigned int control_intf;
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index 668fe128f2ef..120e134e805e 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -272,7 +272,15 @@ static const struct uvc_color_matching_descriptor uvc_color_matching = {
272 .bMatrixCoefficients = 4, 272 .bMatrixCoefficients = 4,
273}; 273};
274 274
275static const struct uvc_descriptor_header * const uvc_control_cls[] = { 275static const struct uvc_descriptor_header * const uvc_fs_control_cls[] = {
276 (const struct uvc_descriptor_header *) &uvc_control_header,
277 (const struct uvc_descriptor_header *) &uvc_camera_terminal,
278 (const struct uvc_descriptor_header *) &uvc_processing,
279 (const struct uvc_descriptor_header *) &uvc_output_terminal,
280 NULL,
281};
282
283static const struct uvc_descriptor_header * const uvc_ss_control_cls[] = {
276 (const struct uvc_descriptor_header *) &uvc_control_header, 284 (const struct uvc_descriptor_header *) &uvc_control_header,
277 (const struct uvc_descriptor_header *) &uvc_camera_terminal, 285 (const struct uvc_descriptor_header *) &uvc_camera_terminal,
278 (const struct uvc_descriptor_header *) &uvc_processing, 286 (const struct uvc_descriptor_header *) &uvc_processing,
@@ -304,6 +312,18 @@ static const struct uvc_descriptor_header * const uvc_hs_streaming_cls[] = {
304 NULL, 312 NULL,
305}; 313};
306 314
315static const struct uvc_descriptor_header * const uvc_ss_streaming_cls[] = {
316 (const struct uvc_descriptor_header *) &uvc_input_header,
317 (const struct uvc_descriptor_header *) &uvc_format_yuv,
318 (const struct uvc_descriptor_header *) &uvc_frame_yuv_360p,
319 (const struct uvc_descriptor_header *) &uvc_frame_yuv_720p,
320 (const struct uvc_descriptor_header *) &uvc_format_mjpg,
321 (const struct uvc_descriptor_header *) &uvc_frame_mjpg_360p,
322 (const struct uvc_descriptor_header *) &uvc_frame_mjpg_720p,
323 (const struct uvc_descriptor_header *) &uvc_color_matching,
324 NULL,
325};
326
307/* -------------------------------------------------------------------------- 327/* --------------------------------------------------------------------------
308 * USB configuration 328 * USB configuration
309 */ 329 */
@@ -311,8 +331,9 @@ static const struct uvc_descriptor_header * const uvc_hs_streaming_cls[] = {
311static int __init 331static int __init
312webcam_config_bind(struct usb_configuration *c) 332webcam_config_bind(struct usb_configuration *c)
313{ 333{
314 return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls, 334 return uvc_bind_config(c, uvc_fs_control_cls, uvc_ss_control_cls,
315 uvc_hs_streaming_cls); 335 uvc_fs_streaming_cls, uvc_hs_streaming_cls,
336 uvc_ss_streaming_cls);
316} 337}
317 338
318static struct usb_configuration webcam_config_driver = { 339static struct usb_configuration webcam_config_driver = {
@@ -373,7 +394,7 @@ static struct usb_composite_driver webcam_driver = {
373 .name = "g_webcam", 394 .name = "g_webcam",
374 .dev = &webcam_device_descriptor, 395 .dev = &webcam_device_descriptor,
375 .strings = webcam_device_strings, 396 .strings = webcam_device_strings,
376 .max_speed = USB_SPEED_HIGH, 397 .max_speed = USB_SPEED_SUPER,
377 .unbind = webcam_unbind, 398 .unbind = webcam_unbind,
378}; 399};
379 400
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 83e58df29fe3..18ba33da34ec 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -652,7 +652,7 @@ config USB_HCD_BCMA
652 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD 652 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
653 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD 653 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD
654 help 654 help
655 Enbale support for the EHCI and OCHI host controller on an bcma bus. 655 Enable support for the EHCI and OCHI host controller on an bcma bus.
656 It converts the bcma driver into two platform device drivers 656 It converts the bcma driver into two platform device drivers
657 for ehci and ohci. 657 for ehci and ohci.
658 658
@@ -664,7 +664,7 @@ config USB_HCD_SSB
664 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD 664 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
665 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD 665 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD
666 help 666 help
667 Enbale support for the EHCI and OCHI host controller on an bcma bus. 667 Enable support for the EHCI and OCHI host controller on an bcma bus.
668 It converts the bcma driver into two platform device drivers 668 It converts the bcma driver into two platform device drivers
669 for ehci and ohci. 669 for ehci and ohci.
670 670
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index cf14c95a6700..a47e2cffaaf8 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -53,30 +53,15 @@ static void atmel_stop_ehci(struct platform_device *pdev)
53static int ehci_atmel_setup(struct usb_hcd *hcd) 53static int ehci_atmel_setup(struct usb_hcd *hcd)
54{ 54{
55 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 55 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
56 int retval = 0; 56 int retval;
57 57
58 /* registers start at offset 0x0 */ 58 /* registers start at offset 0x0 */
59 ehci->caps = hcd->regs; 59 ehci->caps = hcd->regs;
60 ehci->regs = hcd->regs +
61 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
62 dbg_hcs_params(ehci, "reset");
63 dbg_hcc_params(ehci, "reset");
64
65 /* cache this readonly data; minimize chip reads */
66 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
67
68 retval = ehci_halt(ehci);
69 if (retval)
70 return retval;
71 60
72 /* data structure init */ 61 retval = ehci_setup(hcd);
73 retval = ehci_init(hcd);
74 if (retval) 62 if (retval)
75 return retval; 63 return retval;
76 64
77 ehci->sbrn = 0x20;
78
79 ehci_reset(ehci);
80 ehci_port_power(ehci, 0); 65 ehci_port_power(ehci, 0);
81 66
82 return retval; 67 return retval;
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index bf7441afed16..cba10d625a5d 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -20,10 +20,12 @@ extern int usb_disabled(void);
20static int au1xxx_ehci_setup(struct usb_hcd *hcd) 20static int au1xxx_ehci_setup(struct usb_hcd *hcd)
21{ 21{
22 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 22 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
23 int ret = ehci_init(hcd); 23 int ret;
24
25 ehci->caps = hcd->regs;
26 ret = ehci_setup(hcd);
24 27
25 ehci->need_io_watchdog = 0; 28 ehci->need_io_watchdog = 0;
26 ehci_reset(ehci);
27 return ret; 29 return ret;
28} 30}
29 31
@@ -78,7 +80,6 @@ static const struct hc_driver ehci_au1xxx_hc_driver = {
78static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) 80static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
79{ 81{
80 struct usb_hcd *hcd; 82 struct usb_hcd *hcd;
81 struct ehci_hcd *ehci;
82 struct resource *res; 83 struct resource *res;
83 int ret; 84 int ret;
84 85
@@ -116,13 +117,6 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
116 goto err3; 117 goto err3;
117 } 118 }
118 119
119 ehci = hcd_to_ehci(hcd);
120 ehci->caps = hcd->regs;
121 ehci->regs = hcd->regs +
122 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
123 /* cache this readonly data; minimize chip reads */
124 ehci->hcs_params = readl(&ehci->caps->hcs_params);
125
126 ret = usb_add_hcd(hcd, pdev->resource[1].start, 120 ret = usb_add_hcd(hcd, pdev->resource[1].start,
127 IRQF_SHARED); 121 IRQF_SHARED);
128 if (ret == 0) { 122 if (ret == 0) {
@@ -158,28 +152,10 @@ static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
158static int ehci_hcd_au1xxx_drv_suspend(struct device *dev) 152static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
159{ 153{
160 struct usb_hcd *hcd = dev_get_drvdata(dev); 154 struct usb_hcd *hcd = dev_get_drvdata(dev);
161 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 155 bool do_wakeup = device_may_wakeup(dev);
162 unsigned long flags; 156 int rc;
163 int rc = 0;
164
165 if (time_before(jiffies, ehci->next_statechange))
166 msleep(10);
167
168 /* Root hub was already suspended. Disable irq emission and
169 * mark HW unaccessible. The PM and USB cores make sure that
170 * the root hub is either suspended or stopped.
171 */
172 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
173 spin_lock_irqsave(&ehci->lock, flags);
174 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
175 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
176
177 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
178 spin_unlock_irqrestore(&ehci->lock, flags);
179
180 // could save FLADJ in case of Vaux power loss
181 // ... we'd only use it to handle clock skew
182 157
158 rc = ehci_suspend(hcd, do_wakeup);
183 alchemy_usb_control(ALCHEMY_USB_EHCI0, 0); 159 alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
184 160
185 return rc; 161 return rc;
@@ -188,56 +164,9 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
188static int ehci_hcd_au1xxx_drv_resume(struct device *dev) 164static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
189{ 165{
190 struct usb_hcd *hcd = dev_get_drvdata(dev); 166 struct usb_hcd *hcd = dev_get_drvdata(dev);
191 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
192 167
193 alchemy_usb_control(ALCHEMY_USB_EHCI0, 1); 168 alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
194 169 ehci_resume(hcd, false);
195 // maybe restore FLADJ
196
197 if (time_before(jiffies, ehci->next_statechange))
198 msleep(100);
199
200 /* Mark hardware accessible again as we are out of D3 state by now */
201 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
202
203 /* If CF is still set, we maintained PCI Vaux power.
204 * Just undo the effect of ehci_pci_suspend().
205 */
206 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
207 int mask = INTR_MASK;
208
209 ehci_prepare_ports_for_controller_resume(ehci);
210 if (!hcd->self.root_hub->do_remote_wakeup)
211 mask &= ~STS_PCD;
212 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
213 ehci_readl(ehci, &ehci->regs->intr_enable);
214 return 0;
215 }
216
217 ehci_dbg(ehci, "lost power, restarting\n");
218 usb_root_hub_lost_power(hcd->self.root_hub);
219
220 /* Else reset, to cope with power loss or flush-to-storage
221 * style "resume" having let BIOS kick in during reboot.
222 */
223 (void) ehci_halt(ehci);
224 (void) ehci_reset(ehci);
225
226 /* emptying the schedule aborts any urbs */
227 spin_lock_irq(&ehci->lock);
228 if (ehci->reclaim)
229 end_unlink_async(ehci);
230 ehci_work(ehci);
231 spin_unlock_irq(&ehci->lock);
232
233 ehci_writel(ehci, ehci->command, &ehci->regs->command);
234 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
235 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
236
237 /* here we "know" root ports should always stay powered */
238 ehci_port_power(ehci, 1);
239
240 ehci->rh_state = EHCI_RH_SUSPENDED;
241 170
242 return 0; 171 return 0;
243} 172}
diff --git a/drivers/usb/host/ehci-cns3xxx.c b/drivers/usb/host/ehci-cns3xxx.c
index 6536abdea6e6..caaa3e5be334 100644
--- a/drivers/usb/host/ehci-cns3xxx.c
+++ b/drivers/usb/host/ehci-cns3xxx.c
@@ -33,14 +33,10 @@ static int cns3xxx_ehci_init(struct usb_hcd *hcd)
33 } 33 }
34 34
35 ehci->caps = hcd->regs; 35 ehci->caps = hcd->regs;
36 ehci->regs = hcd->regs
37 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
38 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
39 36
40 hcd->has_tt = 0; 37 hcd->has_tt = 0;
41 ehci_reset(ehci);
42 38
43 retval = ehci_init(hcd); 39 retval = ehci_setup(hcd);
44 if (retval) 40 if (retval)
45 return retval; 41 return retval;
46 42
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 43362577b54a..ab52db684b63 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -27,6 +27,7 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/pm.h> 29#include <linux/pm.h>
30#include <linux/err.h>
30#include <linux/platform_device.h> 31#include <linux/platform_device.h>
31#include <linux/fsl_devices.h> 32#include <linux/fsl_devices.h>
32 33
@@ -142,19 +143,19 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
142 if (pdata->operating_mode == FSL_USB2_DR_OTG) { 143 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
143 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 144 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
144 145
145 ehci->transceiver = usb_get_transceiver(); 146 hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2);
146 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, transceiver=0x%p\n", 147 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n",
147 hcd, ehci, ehci->transceiver); 148 hcd, ehci, hcd->phy);
148 149
149 if (ehci->transceiver) { 150 if (!IS_ERR_OR_NULL(hcd->phy)) {
150 retval = otg_set_host(ehci->transceiver->otg, 151 retval = otg_set_host(hcd->phy->otg,
151 &ehci_to_hcd(ehci)->self); 152 &ehci_to_hcd(ehci)->self);
152 if (retval) { 153 if (retval) {
153 usb_put_transceiver(ehci->transceiver); 154 usb_put_phy(hcd->phy);
154 goto err4; 155 goto err4;
155 } 156 }
156 } else { 157 } else {
157 dev_err(&pdev->dev, "can't find transceiver\n"); 158 dev_err(&pdev->dev, "can't find phy\n");
158 retval = -ENODEV; 159 retval = -ENODEV;
159 goto err4; 160 goto err4;
160 } 161 }
@@ -190,11 +191,10 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
190 struct platform_device *pdev) 191 struct platform_device *pdev)
191{ 192{
192 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 193 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
193 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
194 194
195 if (ehci->transceiver) { 195 if (!IS_ERR_OR_NULL(hcd->phy)) {
196 otg_set_host(ehci->transceiver->otg, NULL); 196 otg_set_host(hcd->phy->otg, NULL);
197 usb_put_transceiver(ehci->transceiver); 197 usb_put_phy(hcd->phy);
198 } 198 }
199 199
200 usb_remove_hcd(hcd); 200 usb_remove_hcd(hcd);
@@ -348,29 +348,13 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
348 348
349 /* EHCI registers start at offset 0x100 */ 349 /* EHCI registers start at offset 0x100 */
350 ehci->caps = hcd->regs + 0x100; 350 ehci->caps = hcd->regs + 0x100;
351 ehci->regs = hcd->regs + 0x100 +
352 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
353 dbg_hcs_params(ehci, "reset");
354 dbg_hcc_params(ehci, "reset");
355
356 /* cache this readonly data; minimize chip reads */
357 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
358 351
359 hcd->has_tt = 1; 352 hcd->has_tt = 1;
360 353
361 retval = ehci_halt(ehci); 354 retval = ehci_setup(hcd);
362 if (retval)
363 return retval;
364
365 /* data structure init */
366 retval = ehci_init(hcd);
367 if (retval) 355 if (retval)
368 return retval; 356 return retval;
369 357
370 ehci->sbrn = 0x20;
371
372 ehci_reset(ehci);
373
374 if (of_device_is_compatible(dev->parent->of_node, 358 if (of_device_is_compatible(dev->parent->of_node,
375 "fsl,mpc5121-usb2-dr")) { 359 "fsl,mpc5121-usb2-dr")) {
376 /* 360 /*
diff --git a/drivers/usb/host/ehci-grlib.c b/drivers/usb/host/ehci-grlib.c
index fdfd8c5b639b..22ca45c079a4 100644
--- a/drivers/usb/host/ehci-grlib.c
+++ b/drivers/usb/host/ehci-grlib.c
@@ -40,18 +40,13 @@ static int ehci_grlib_setup(struct usb_hcd *hcd)
40 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 40 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
41 int retval; 41 int retval;
42 42
43 retval = ehci_halt(ehci); 43 retval = ehci_setup(hcd);
44 if (retval) 44 if (retval)
45 return retval; 45 return retval;
46 46
47 retval = ehci_init(hcd);
48 if (retval)
49 return retval;
50
51 ehci->sbrn = 0x20;
52 ehci_port_power(ehci, 1); 47 ehci_port_power(ehci, 1);
53 48
54 return ehci_reset(ehci); 49 return retval;
55} 50}
56 51
57 52
@@ -164,12 +159,6 @@ static int __devinit ehci_hcd_grlib_probe(struct platform_device *op)
164 ehci->big_endian_capbase = 1; 159 ehci->big_endian_capbase = 1;
165 } 160 }
166 161
167 ehci->regs = hcd->regs +
168 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
169
170 /* cache this readonly data; minimize chip reads */
171 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
172
173 rv = usb_add_hcd(hcd, irq, 0); 162 rv = usb_add_hcd(hcd, irq, 0);
174 if (rv) 163 if (rv)
175 goto err_ehci; 164 goto err_ehci;
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 800be38c78b4..f9a783bfa1fe 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -203,11 +203,9 @@ static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
203/* check TDI/ARC silicon is in host mode */ 203/* check TDI/ARC silicon is in host mode */
204static int tdi_in_host_mode (struct ehci_hcd *ehci) 204static int tdi_in_host_mode (struct ehci_hcd *ehci)
205{ 205{
206 u32 __iomem *reg_ptr;
207 u32 tmp; 206 u32 tmp;
208 207
209 reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE); 208 tmp = ehci_readl(ehci, &ehci->regs->usbmode);
210 tmp = ehci_readl(ehci, reg_ptr);
211 return (tmp & 3) == USBMODE_CM_HC; 209 return (tmp & 3) == USBMODE_CM_HC;
212} 210}
213 211
@@ -303,11 +301,9 @@ static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr,
303/* put TDI/ARC silicon into EHCI mode */ 301/* put TDI/ARC silicon into EHCI mode */
304static void tdi_reset (struct ehci_hcd *ehci) 302static void tdi_reset (struct ehci_hcd *ehci)
305{ 303{
306 u32 __iomem *reg_ptr;
307 u32 tmp; 304 u32 tmp;
308 305
309 reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE); 306 tmp = ehci_readl(ehci, &ehci->regs->usbmode);
310 tmp = ehci_readl(ehci, reg_ptr);
311 tmp |= USBMODE_CM_HC; 307 tmp |= USBMODE_CM_HC;
312 /* The default byte access to MMR space is LE after 308 /* The default byte access to MMR space is LE after
313 * controller reset. Set the required endian mode 309 * controller reset. Set the required endian mode
@@ -315,7 +311,7 @@ static void tdi_reset (struct ehci_hcd *ehci)
315 */ 311 */
316 if (ehci_big_endian_mmio(ehci)) 312 if (ehci_big_endian_mmio(ehci))
317 tmp |= USBMODE_BE; 313 tmp |= USBMODE_BE;
318 ehci_writel(ehci, tmp, reg_ptr); 314 ehci_writel(ehci, tmp, &ehci->regs->usbmode);
319} 315}
320 316
321/* reset a non-running (STS_HALT == 1) controller */ 317/* reset a non-running (STS_HALT == 1) controller */
@@ -339,9 +335,8 @@ static int ehci_reset (struct ehci_hcd *ehci)
339 335
340 if (ehci->has_hostpc) { 336 if (ehci->has_hostpc) {
341 ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS, 337 ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
342 (u32 __iomem *)(((u8 *)ehci->regs) + USBMODE_EX)); 338 &ehci->regs->usbmode_ex);
343 ehci_writel(ehci, TXFIFO_DEFAULT, 339 ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning);
344 (u32 __iomem *)(((u8 *)ehci->regs) + TXFILLTUNING));
345 } 340 }
346 if (retval) 341 if (retval)
347 return retval; 342 return retval;
@@ -813,7 +808,7 @@ static int ehci_run (struct usb_hcd *hcd)
813 return 0; 808 return 0;
814} 809}
815 810
816static int __maybe_unused ehci_setup (struct usb_hcd *hcd) 811static int ehci_setup(struct usb_hcd *hcd)
817{ 812{
818 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 813 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
819 int retval; 814 int retval;
@@ -837,6 +832,9 @@ static int __maybe_unused ehci_setup (struct usb_hcd *hcd)
837 if (retval) 832 if (retval)
838 return retval; 833 return retval;
839 834
835 if (ehci_is_TDI(ehci))
836 tdi_reset(ehci);
837
840 ehci_reset(ehci); 838 ehci_reset(ehci);
841 839
842 return 0; 840 return 0;
@@ -1247,6 +1245,95 @@ static int ehci_get_frame (struct usb_hcd *hcd)
1247} 1245}
1248 1246
1249/*-------------------------------------------------------------------------*/ 1247/*-------------------------------------------------------------------------*/
1248
1249#ifdef CONFIG_PM
1250
1251/* suspend/resume, section 4.3 */
1252
1253/* These routines handle the generic parts of controller suspend/resume */
1254
1255static int __maybe_unused ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
1256{
1257 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1258
1259 if (time_before(jiffies, ehci->next_statechange))
1260 msleep(10);
1261
1262 /*
1263 * Root hub was already suspended. Disable IRQ emission and
1264 * mark HW unaccessible. The PM and USB cores make sure that
1265 * the root hub is either suspended or stopped.
1266 */
1267 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
1268
1269 spin_lock_irq(&ehci->lock);
1270 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
1271 (void) ehci_readl(ehci, &ehci->regs->intr_enable);
1272
1273 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1274 spin_unlock_irq(&ehci->lock);
1275
1276 return 0;
1277}
1278
1279/* Returns 0 if power was preserved, 1 if power was lost */
1280static int __maybe_unused ehci_resume(struct usb_hcd *hcd, bool hibernated)
1281{
1282 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1283
1284 if (time_before(jiffies, ehci->next_statechange))
1285 msleep(100);
1286
1287 /* Mark hardware accessible again as we are back to full power by now */
1288 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1289
1290 /*
1291 * If CF is still set and we aren't resuming from hibernation
1292 * then we maintained suspend power.
1293 * Just undo the effect of ehci_suspend().
1294 */
1295 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
1296 !hibernated) {
1297 int mask = INTR_MASK;
1298
1299 ehci_prepare_ports_for_controller_resume(ehci);
1300 if (!hcd->self.root_hub->do_remote_wakeup)
1301 mask &= ~STS_PCD;
1302 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
1303 ehci_readl(ehci, &ehci->regs->intr_enable);
1304 return 0;
1305 }
1306
1307 /*
1308 * Else reset, to cope with power loss or resume from hibernation
1309 * having let the firmware kick in during reboot.
1310 */
1311 usb_root_hub_lost_power(hcd->self.root_hub);
1312 (void) ehci_halt(ehci);
1313 (void) ehci_reset(ehci);
1314
1315 /* emptying the schedule aborts any urbs */
1316 spin_lock_irq(&ehci->lock);
1317 if (ehci->reclaim)
1318 end_unlink_async(ehci);
1319 ehci_work(ehci);
1320 spin_unlock_irq(&ehci->lock);
1321
1322 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1323 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
1324 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
1325
1326 /* here we "know" root ports should always stay powered */
1327 ehci_port_power(ehci, 1);
1328
1329 ehci->rh_state = EHCI_RH_SUSPENDED;
1330 return 1;
1331}
1332
1333#endif
1334
1335/*-------------------------------------------------------------------------*/
1336
1250/* 1337/*
1251 * The EHCI in ChipIdea HDRC cannot be a separate module or device, 1338 * The EHCI in ChipIdea HDRC cannot be a separate module or device,
1252 * because its registers (and irq) are shared between host/gadget/otg 1339 * because its registers (and irq) are shared between host/gadget/otg
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index fc9e7cc6ac9b..b3e2d66e95bb 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -107,7 +107,7 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
107 ehci->owned_ports = 0; 107 ehci->owned_ports = 0;
108} 108}
109 109
110static int __maybe_unused ehci_port_change(struct ehci_hcd *ehci) 110static int ehci_port_change(struct ehci_hcd *ehci)
111{ 111{
112 int i = HCS_N_PORTS(ehci->hcs_params); 112 int i = HCS_N_PORTS(ehci->hcs_params);
113 113
@@ -128,7 +128,7 @@ static int __maybe_unused ehci_port_change(struct ehci_hcd *ehci)
128 return 0; 128 return 0;
129} 129}
130 130
131static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 131static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
132 bool suspending, bool do_wakeup) 132 bool suspending, bool do_wakeup)
133{ 133{
134 int port; 134 int port;
@@ -149,10 +149,8 @@ static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
149 if (ehci->has_hostpc) { 149 if (ehci->has_hostpc) {
150 port = HCS_N_PORTS(ehci->hcs_params); 150 port = HCS_N_PORTS(ehci->hcs_params);
151 while (port--) { 151 while (port--) {
152 u32 __iomem *hostpc_reg; 152 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
153 153
154 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
155 + HOSTPC0 + 4 * port);
156 temp = ehci_readl(ehci, hostpc_reg); 154 temp = ehci_readl(ehci, hostpc_reg);
157 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg); 155 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
158 } 156 }
@@ -185,10 +183,8 @@ static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
185 if (ehci->has_hostpc) { 183 if (ehci->has_hostpc) {
186 port = HCS_N_PORTS(ehci->hcs_params); 184 port = HCS_N_PORTS(ehci->hcs_params);
187 while (port--) { 185 while (port--) {
188 u32 __iomem *hostpc_reg; 186 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
189 187
190 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
191 + HOSTPC0 + 4 * port);
192 temp = ehci_readl(ehci, hostpc_reg); 188 temp = ehci_readl(ehci, hostpc_reg);
193 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg); 189 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
194 } 190 }
@@ -285,11 +281,9 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
285 281
286 port = HCS_N_PORTS(ehci->hcs_params); 282 port = HCS_N_PORTS(ehci->hcs_params);
287 while (port--) { 283 while (port--) {
288 u32 __iomem *hostpc_reg; 284 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
289 u32 t3; 285 u32 t3;
290 286
291 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
292 + HOSTPC0 + 4 * port);
293 t3 = ehci_readl(ehci, hostpc_reg); 287 t3 = ehci_readl(ehci, hostpc_reg);
294 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg); 288 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
295 t3 = ehci_readl(ehci, hostpc_reg); 289 t3 = ehci_readl(ehci, hostpc_reg);
@@ -388,10 +382,9 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
388 i = HCS_N_PORTS(ehci->hcs_params); 382 i = HCS_N_PORTS(ehci->hcs_params);
389 while (i--) { 383 while (i--) {
390 if (test_bit(i, &ehci->bus_suspended)) { 384 if (test_bit(i, &ehci->bus_suspended)) {
391 u32 __iomem *hostpc_reg; 385 u32 __iomem *hostpc_reg =
386 &ehci->regs->hostpc[i];
392 387
393 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
394 + HOSTPC0 + 4 * i);
395 temp = ehci_readl(ehci, hostpc_reg); 388 temp = ehci_readl(ehci, hostpc_reg);
396 ehci_writel(ehci, temp & ~HOSTPC_PHCD, 389 ehci_writel(ehci, temp & ~HOSTPC_PHCD,
397 hostpc_reg); 390 hostpc_reg);
@@ -667,7 +660,7 @@ static int ehci_hub_control (
667 int ports = HCS_N_PORTS (ehci->hcs_params); 660 int ports = HCS_N_PORTS (ehci->hcs_params);
668 u32 __iomem *status_reg = &ehci->regs->port_status[ 661 u32 __iomem *status_reg = &ehci->regs->port_status[
669 (wIndex & 0xff) - 1]; 662 (wIndex & 0xff) - 1];
670 u32 __iomem *hostpc_reg = NULL; 663 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[(wIndex & 0xff) - 1];
671 u32 temp, temp1, status; 664 u32 temp, temp1, status;
672 unsigned long flags; 665 unsigned long flags;
673 int retval = 0; 666 int retval = 0;
@@ -680,9 +673,6 @@ static int ehci_hub_control (
680 * power, "this is the one", etc. EHCI spec supports this. 673 * power, "this is the one", etc. EHCI spec supports this.
681 */ 674 */
682 675
683 if (ehci->has_hostpc)
684 hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
685 + HOSTPC0 + 4 * ((wIndex & 0xff) - 1));
686 spin_lock_irqsave (&ehci->lock, flags); 676 spin_lock_irqsave (&ehci->lock, flags);
687 switch (typeReq) { 677 switch (typeReq) {
688 case ClearHubFeature: 678 case ClearHubFeature:
@@ -724,7 +714,7 @@ static int ehci_hub_control (
724#ifdef CONFIG_USB_OTG 714#ifdef CONFIG_USB_OTG
725 if ((hcd->self.otg_port == (wIndex + 1)) 715 if ((hcd->self.otg_port == (wIndex + 1))
726 && hcd->self.b_hnp_enable) { 716 && hcd->self.b_hnp_enable) {
727 otg_start_hnp(ehci->transceiver->otg); 717 otg_start_hnp(hcd->phy->otg);
728 break; 718 break;
729 } 719 }
730#endif 720#endif
@@ -734,7 +724,7 @@ static int ehci_hub_control (
734 goto error; 724 goto error;
735 725
736 /* clear phy low-power mode before resume */ 726 /* clear phy low-power mode before resume */
737 if (hostpc_reg) { 727 if (ehci->has_hostpc) {
738 temp1 = ehci_readl(ehci, hostpc_reg); 728 temp1 = ehci_readl(ehci, hostpc_reg);
739 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD, 729 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
740 hostpc_reg); 730 hostpc_reg);
@@ -984,7 +974,7 @@ static int ehci_hub_control (
984 temp &= ~PORT_WKCONN_E; 974 temp &= ~PORT_WKCONN_E;
985 temp |= PORT_WKDISC_E | PORT_WKOC_E; 975 temp |= PORT_WKDISC_E | PORT_WKOC_E;
986 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); 976 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
987 if (hostpc_reg) { 977 if (ehci->has_hostpc) {
988 spin_unlock_irqrestore(&ehci->lock, flags); 978 spin_unlock_irqrestore(&ehci->lock, flags);
989 msleep(5);/* 5ms for HCD enter low pwr mode */ 979 msleep(5);/* 5ms for HCD enter low pwr mode */
990 spin_lock_irqsave(&ehci->lock, flags); 980 spin_lock_irqsave(&ehci->lock, flags);
diff --git a/drivers/usb/host/ehci-ixp4xx.c b/drivers/usb/host/ehci-ixp4xx.c
index c4460f3d009f..488d401942e9 100644
--- a/drivers/usb/host/ehci-ixp4xx.c
+++ b/drivers/usb/host/ehci-ixp4xx.c
@@ -22,14 +22,10 @@ static int ixp4xx_ehci_init(struct usb_hcd *hcd)
22 ehci->big_endian_mmio = 1; 22 ehci->big_endian_mmio = 1;
23 23
24 ehci->caps = hcd->regs + 0x100; 24 ehci->caps = hcd->regs + 0x100;
25 ehci->regs = hcd->regs + 0x100
26 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
27 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
28 25
29 hcd->has_tt = 1; 26 hcd->has_tt = 1;
30 ehci_reset(ehci);
31 27
32 retval = ehci_init(hcd); 28 retval = ehci_setup(hcd);
33 if (retval) 29 if (retval)
34 return retval; 30 return retval;
35 31
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 9803a55fd5f4..17dd9e94001e 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -145,8 +145,8 @@ static int ehci_msm_probe(struct platform_device *pdev)
145 * powering up VBUS, mapping of registers address space and power 145 * powering up VBUS, mapping of registers address space and power
146 * management. 146 * management.
147 */ 147 */
148 phy = usb_get_transceiver(); 148 phy = usb_get_phy(USB_PHY_TYPE_USB2);
149 if (!phy) { 149 if (IS_ERR_OR_NULL(phy)) {
150 dev_err(&pdev->dev, "unable to find transceiver\n"); 150 dev_err(&pdev->dev, "unable to find transceiver\n");
151 ret = -ENODEV; 151 ret = -ENODEV;
152 goto unmap; 152 goto unmap;
@@ -169,7 +169,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
169 return 0; 169 return 0;
170 170
171put_transceiver: 171put_transceiver:
172 usb_put_transceiver(phy); 172 usb_put_phy(phy);
173unmap: 173unmap:
174 iounmap(hcd->regs); 174 iounmap(hcd->regs);
175put_hcd: 175put_hcd:
@@ -187,7 +187,7 @@ static int __devexit ehci_msm_remove(struct platform_device *pdev)
187 pm_runtime_set_suspended(&pdev->dev); 187 pm_runtime_set_suspended(&pdev->dev);
188 188
189 otg_set_host(phy->otg, NULL); 189 otg_set_host(phy->otg, NULL);
190 usb_put_transceiver(phy); 190 usb_put_phy(phy);
191 191
192 usb_put_hcd(hcd); 192 usb_put_hcd(hcd);
193 193
@@ -198,24 +198,11 @@ static int __devexit ehci_msm_remove(struct platform_device *pdev)
198static int ehci_msm_pm_suspend(struct device *dev) 198static int ehci_msm_pm_suspend(struct device *dev)
199{ 199{
200 struct usb_hcd *hcd = dev_get_drvdata(dev); 200 struct usb_hcd *hcd = dev_get_drvdata(dev);
201 bool wakeup = device_may_wakeup(dev); 201 bool do_wakeup = device_may_wakeup(dev);
202 202
203 dev_dbg(dev, "ehci-msm PM suspend\n"); 203 dev_dbg(dev, "ehci-msm PM suspend\n");
204 204
205 /* 205 return ehci_suspend(hcd, do_wakeup);
206 * EHCI helper function has also the same check before manipulating
207 * port wakeup flags. We do check here the same condition before
208 * calling the same helper function to avoid bringing hardware
209 * from Low power mode when there is no need for adjusting port
210 * wakeup flags.
211 */
212 if (hcd->self.root_hub->do_remote_wakeup && !wakeup) {
213 pm_runtime_resume(dev);
214 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
215 wakeup);
216 }
217
218 return 0;
219} 206}
220 207
221static int ehci_msm_pm_resume(struct device *dev) 208static int ehci_msm_pm_resume(struct device *dev)
@@ -223,7 +210,7 @@ static int ehci_msm_pm_resume(struct device *dev)
223 struct usb_hcd *hcd = dev_get_drvdata(dev); 210 struct usb_hcd *hcd = dev_get_drvdata(dev);
224 211
225 dev_dbg(dev, "ehci-msm PM resume\n"); 212 dev_dbg(dev, "ehci-msm PM resume\n");
226 ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd)); 213 ehci_resume(hcd, false);
227 214
228 return 0; 215 return 0;
229} 216}
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index a936bbcff8f4..f6df1ccc9617 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/err.h>
16#include <linux/usb/otg.h> 17#include <linux/usb/otg.h>
17#include <linux/platform_data/mv_usb.h> 18#include <linux/platform_data/mv_usb.h>
18 19
@@ -76,7 +77,6 @@ static void mv_ehci_disable(struct ehci_hcd_mv *ehci_mv)
76 77
77static int mv_ehci_reset(struct usb_hcd *hcd) 78static int mv_ehci_reset(struct usb_hcd *hcd)
78{ 79{
79 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
80 struct device *dev = hcd->self.controller; 80 struct device *dev = hcd->self.controller;
81 struct ehci_hcd_mv *ehci_mv = dev_get_drvdata(dev); 81 struct ehci_hcd_mv *ehci_mv = dev_get_drvdata(dev);
82 int retval; 82 int retval;
@@ -86,25 +86,13 @@ static int mv_ehci_reset(struct usb_hcd *hcd)
86 return -ENODEV; 86 return -ENODEV;
87 } 87 }
88 88
89 /*
90 * data structure init
91 */
92 retval = ehci_init(hcd);
93 if (retval) {
94 dev_err(dev, "ehci_init failed %d\n", retval);
95 return retval;
96 }
97
98 hcd->has_tt = 1; 89 hcd->has_tt = 1;
99 ehci->sbrn = 0x20;
100 90
101 retval = ehci_reset(ehci); 91 retval = ehci_setup(hcd);
102 if (retval) { 92 if (retval)
103 dev_err(dev, "ehci_reset failed %d\n", retval); 93 dev_err(dev, "ehci_setup failed %d\n", retval);
104 return retval;
105 }
106 94
107 return 0; 95 return retval;
108} 96}
109 97
110static const struct hc_driver mv_ehci_hc_driver = { 98static const struct hc_driver mv_ehci_hc_driver = {
@@ -247,14 +235,12 @@ static int mv_ehci_probe(struct platform_device *pdev)
247 235
248 ehci = hcd_to_ehci(hcd); 236 ehci = hcd_to_ehci(hcd);
249 ehci->caps = (struct ehci_caps *) ehci_mv->cap_regs; 237 ehci->caps = (struct ehci_caps *) ehci_mv->cap_regs;
250 ehci->regs = (struct ehci_regs *) ehci_mv->op_regs;
251 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
252 238
253 ehci_mv->mode = pdata->mode; 239 ehci_mv->mode = pdata->mode;
254 if (ehci_mv->mode == MV_USB_MODE_OTG) { 240 if (ehci_mv->mode == MV_USB_MODE_OTG) {
255#ifdef CONFIG_USB_OTG_UTILS 241#ifdef CONFIG_USB_OTG_UTILS
256 ehci_mv->otg = usb_get_transceiver(); 242 ehci_mv->otg = usb_get_phy(USB_PHY_TYPE_USB2);
257 if (!ehci_mv->otg) { 243 if (IS_ERR_OR_NULL(ehci_mv->otg)) {
258 dev_err(&pdev->dev, 244 dev_err(&pdev->dev,
259 "unable to find transceiver\n"); 245 "unable to find transceiver\n");
260 retval = -ENODEV; 246 retval = -ENODEV;
@@ -302,8 +288,8 @@ err_set_vbus:
302 pdata->set_vbus(0); 288 pdata->set_vbus(0);
303#ifdef CONFIG_USB_OTG_UTILS 289#ifdef CONFIG_USB_OTG_UTILS
304err_put_transceiver: 290err_put_transceiver:
305 if (ehci_mv->otg) 291 if (!IS_ERR_OR_NULL(ehci_mv->otg))
306 usb_put_transceiver(ehci_mv->otg); 292 usb_put_phy(ehci_mv->otg);
307#endif 293#endif
308err_disable_clk: 294err_disable_clk:
309 mv_ehci_disable(ehci_mv); 295 mv_ehci_disable(ehci_mv);
@@ -331,9 +317,9 @@ static int mv_ehci_remove(struct platform_device *pdev)
331 if (hcd->rh_registered) 317 if (hcd->rh_registered)
332 usb_remove_hcd(hcd); 318 usb_remove_hcd(hcd);
333 319
334 if (ehci_mv->otg) { 320 if (!IS_ERR_OR_NULL(ehci_mv->otg)) {
335 otg_set_host(ehci_mv->otg->otg, NULL); 321 otg_set_host(ehci_mv->otg->otg, NULL);
336 usb_put_transceiver(ehci_mv->otg); 322 usb_put_phy(ehci_mv->otg);
337 } 323 }
338 324
339 if (ehci_mv->mode == MV_USB_MODE_HOST) { 325 if (ehci_mv->mode == MV_USB_MODE_HOST) {
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
index c778ffe4e4e5..34201372c85f 100644
--- a/drivers/usb/host/ehci-mxc.c
+++ b/drivers/usb/host/ehci-mxc.c
@@ -42,27 +42,12 @@ static int ehci_mxc_setup(struct usb_hcd *hcd)
42 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 42 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
43 int retval; 43 int retval;
44 44
45 dbg_hcs_params(ehci, "reset");
46 dbg_hcc_params(ehci, "reset");
47
48 /* cache this readonly data; minimize chip reads */
49 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
50
51 hcd->has_tt = 1; 45 hcd->has_tt = 1;
52 46
53 retval = ehci_halt(ehci); 47 retval = ehci_setup(hcd);
54 if (retval) 48 if (retval)
55 return retval; 49 return retval;
56 50
57 /* data structure init */
58 retval = ehci_init(hcd);
59 if (retval)
60 return retval;
61
62 ehci->sbrn = 0x20;
63
64 ehci_reset(ehci);
65
66 ehci_port_power(ehci, 0); 51 ehci_port_power(ehci, 0);
67 return 0; 52 return 0;
68} 53}
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c
index c0104882c72d..ba26957abf46 100644
--- a/drivers/usb/host/ehci-octeon.c
+++ b/drivers/usb/host/ehci-octeon.c
@@ -56,7 +56,7 @@ static const struct hc_driver ehci_octeon_hc_driver = {
56 /* 56 /*
57 * basic lifecycle operations 57 * basic lifecycle operations
58 */ 58 */
59 .reset = ehci_init, 59 .reset = ehci_setup,
60 .start = ehci_run, 60 .start = ehci_run,
61 .stop = ehci_stop, 61 .stop = ehci_stop,
62 .shutdown = ehci_shutdown, 62 .shutdown = ehci_shutdown,
@@ -150,12 +150,6 @@ static int ehci_octeon_drv_probe(struct platform_device *pdev)
150#endif 150#endif
151 151
152 ehci->caps = hcd->regs; 152 ehci->caps = hcd->regs;
153 ehci->regs = hcd->regs +
154 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
155 /* cache this readonly data; minimize chip reads */
156 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
157
158 ehci_reset(ehci);
159 153
160 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 154 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
161 if (ret) { 155 if (ret) {
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index c30435499a02..6133d93808dc 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -145,6 +145,56 @@ static void omap_ehci_soft_phy_reset(struct platform_device *pdev, u8 port)
145 } 145 }
146} 146}
147 147
148static int omap_ehci_init(struct usb_hcd *hcd)
149{
150 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
151 int rc;
152 struct ehci_hcd_omap_platform_data *pdata;
153
154 pdata = hcd->self.controller->platform_data;
155 if (pdata->phy_reset) {
156 if (gpio_is_valid(pdata->reset_gpio_port[0]))
157 gpio_request_one(pdata->reset_gpio_port[0],
158 GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
159
160 if (gpio_is_valid(pdata->reset_gpio_port[1]))
161 gpio_request_one(pdata->reset_gpio_port[1],
162 GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
163
164 /* Hold the PHY in RESET for enough time till DIR is high */
165 udelay(10);
166 }
167
168 /* Soft reset the PHY using PHY reset command over ULPI */
169 if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY)
170 omap_ehci_soft_phy_reset(pdev, 0);
171 if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY)
172 omap_ehci_soft_phy_reset(pdev, 1);
173
174 /* we know this is the memory we want, no need to ioremap again */
175 ehci->caps = hcd->regs;
176
177 rc = ehci_setup(hcd);
178
179 if (pdata->phy_reset) {
180 /* Hold the PHY in RESET for enough time till
181 * PHY is settled and ready
182 */
183 udelay(10);
184
185 if (gpio_is_valid(pdata->reset_gpio_port[0]))
186 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 1);
187
188 if (gpio_is_valid(pdata->reset_gpio_port[1]))
189 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 1);
190 }
191
192 /* root ports should always stay powered */
193 ehci_port_power(ehci, 1);
194
195 return rc;
196}
197
148static int omap_ehci_hub_control( 198static int omap_ehci_hub_control(
149 struct usb_hcd *hcd, 199 struct usb_hcd *hcd,
150 u16 typeReq, 200 u16 typeReq,
@@ -219,7 +269,6 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
219 struct resource *res; 269 struct resource *res;
220 struct usb_hcd *hcd; 270 struct usb_hcd *hcd;
221 void __iomem *regs; 271 void __iomem *regs;
222 struct ehci_hcd *omap_ehci;
223 int ret = -ENODEV; 272 int ret = -ENODEV;
224 int irq; 273 int irq;
225 int i; 274 int i;
@@ -281,18 +330,6 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
281 } 330 }
282 } 331 }
283 332
284 /* Hold PHYs in reset while initializing EHCI controller */
285 if (pdata->phy_reset) {
286 if (gpio_is_valid(pdata->reset_gpio_port[0]))
287 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 0);
288
289 if (gpio_is_valid(pdata->reset_gpio_port[1]))
290 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 0);
291
292 /* Hold the PHY in RESET for enough time till DIR is high */
293 udelay(10);
294 }
295
296 pm_runtime_enable(dev); 333 pm_runtime_enable(dev);
297 pm_runtime_get_sync(dev); 334 pm_runtime_get_sync(dev);
298 335
@@ -308,49 +345,12 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
308 ehci_write(regs, EHCI_INSNREG04, 345 ehci_write(regs, EHCI_INSNREG04,
309 EHCI_INSNREG04_DISABLE_UNSUSPEND); 346 EHCI_INSNREG04_DISABLE_UNSUSPEND);
310 347
311 /* Soft reset the PHY using PHY reset command over ULPI */
312 if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY)
313 omap_ehci_soft_phy_reset(pdev, 0);
314 if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY)
315 omap_ehci_soft_phy_reset(pdev, 1);
316
317 omap_ehci = hcd_to_ehci(hcd);
318 omap_ehci->sbrn = 0x20;
319
320 /* we know this is the memory we want, no need to ioremap again */
321 omap_ehci->caps = hcd->regs;
322 omap_ehci->regs = hcd->regs
323 + HC_LENGTH(ehci, readl(&omap_ehci->caps->hc_capbase));
324
325 dbg_hcs_params(omap_ehci, "reset");
326 dbg_hcc_params(omap_ehci, "reset");
327
328 /* cache this readonly data; minimize chip reads */
329 omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params);
330
331 ehci_reset(omap_ehci);
332 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 348 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
333 if (ret) { 349 if (ret) {
334 dev_err(dev, "failed to add hcd with err %d\n", ret); 350 dev_err(dev, "failed to add hcd with err %d\n", ret);
335 goto err_add_hcd; 351 goto err_pm_runtime;
336 } 352 }
337 353
338 if (pdata->phy_reset) {
339 /* Hold the PHY in RESET for enough time till
340 * PHY is settled and ready
341 */
342 udelay(10);
343
344 if (gpio_is_valid(pdata->reset_gpio_port[0]))
345 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 1);
346
347 if (gpio_is_valid(pdata->reset_gpio_port[1]))
348 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 1);
349 }
350
351 /* root ports should always stay powered */
352 ehci_port_power(omap_ehci, 1);
353
354 /* get clocks */ 354 /* get clocks */
355 utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk"); 355 utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk");
356 if (IS_ERR(utmi_p1_fck)) { 356 if (IS_ERR(utmi_p1_fck)) {
@@ -422,8 +422,12 @@ err_utmi_p1_fck:
422 clk_put(utmi_p1_fck); 422 clk_put(utmi_p1_fck);
423 423
424err_add_hcd: 424err_add_hcd:
425 usb_remove_hcd(hcd);
426
427err_pm_runtime:
425 disable_put_regulator(pdata); 428 disable_put_regulator(pdata);
426 pm_runtime_put_sync(dev); 429 pm_runtime_put_sync(dev);
430 usb_put_hcd(hcd);
427 431
428err_io: 432err_io:
429 iounmap(regs); 433 iounmap(regs);
@@ -506,7 +510,7 @@ static const struct hc_driver ehci_omap_hc_driver = {
506 /* 510 /*
507 * basic lifecycle operations 511 * basic lifecycle operations
508 */ 512 */
509 .reset = ehci_init, 513 .reset = omap_ehci_init,
510 .start = ehci_run, 514 .start = ehci_run,
511 .stop = ehci_stop, 515 .stop = ehci_stop,
512 .shutdown = ehci_shutdown, 516 .shutdown = ehci_shutdown,
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 82de1073aa52..3e411230953b 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -106,21 +106,10 @@ static int ehci_orion_setup(struct usb_hcd *hcd)
106 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 106 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
107 int retval; 107 int retval;
108 108
109 hcd->has_tt = 1; 109 retval = ehci_setup(ehci);
110
111 retval = ehci_halt(ehci);
112 if (retval)
113 return retval;
114
115 /*
116 * data structure init
117 */
118 retval = ehci_init(hcd);
119 if (retval) 110 if (retval)
120 return retval; 111 return retval;
121 112
122 ehci_reset(ehci);
123
124 ehci_port_power(ehci, 0); 113 ehci_port_power(ehci, 0);
125 114
126 return retval; 115 return retval;
@@ -261,11 +250,7 @@ static int __devinit ehci_orion_drv_probe(struct platform_device *pdev)
261 250
262 ehci = hcd_to_ehci(hcd); 251 ehci = hcd_to_ehci(hcd);
263 ehci->caps = hcd->regs + 0x100; 252 ehci->caps = hcd->regs + 0x100;
264 ehci->regs = hcd->regs + 0x100 +
265 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
266 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
267 hcd->has_tt = 1; 253 hcd->has_tt = 1;
268 ehci->sbrn = 0x20;
269 254
270 /* 255 /*
271 * (Re-)program MBUS remapping windows if we are asked to. 256 * (Re-)program MBUS remapping windows if we are asked to.
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 123481793a47..21e5f963f331 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -54,6 +54,17 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
54 u32 temp; 54 u32 temp;
55 int retval; 55 int retval;
56 56
57 ehci->caps = hcd->regs;
58
59 /*
60 * ehci_init() causes memory for DMA transfers to be
61 * allocated. Thus, any vendor-specific workarounds based on
62 * limiting the type of memory used for DMA transfers must
63 * happen before ehci_setup() is called.
64 *
65 * Most other workarounds can be done either before or after
66 * init and reset; they are located here too.
67 */
57 switch (pdev->vendor) { 68 switch (pdev->vendor) {
58 case PCI_VENDOR_ID_TOSHIBA_2: 69 case PCI_VENDOR_ID_TOSHIBA_2:
59 /* celleb's companion chip */ 70 /* celleb's companion chip */
@@ -66,20 +77,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
66#endif 77#endif
67 } 78 }
68 break; 79 break;
69 }
70
71 ehci->caps = hcd->regs;
72 ehci->regs = hcd->regs +
73 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
74
75 dbg_hcs_params(ehci, "reset");
76 dbg_hcc_params(ehci, "reset");
77
78 /* ehci_init() causes memory for DMA transfers to be
79 * allocated. Thus, any vendor-specific workarounds based on
80 * limiting the type of memory used for DMA transfers must
81 * happen before ehci_init() is called. */
82 switch (pdev->vendor) {
83 case PCI_VENDOR_ID_NVIDIA: 80 case PCI_VENDOR_ID_NVIDIA:
84 /* NVidia reports that certain chips don't handle 81 /* NVidia reports that certain chips don't handle
85 * QH, ITD, or SITD addresses above 2GB. (But TD, 82 * QH, ITD, or SITD addresses above 2GB. (But TD,
@@ -95,61 +92,28 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
95 ehci_warn(ehci, "can't enable NVidia " 92 ehci_warn(ehci, "can't enable NVidia "
96 "workaround for >2GB RAM\n"); 93 "workaround for >2GB RAM\n");
97 break; 94 break;
98 }
99 break;
100 }
101
102 /* cache this readonly data; minimize chip reads */
103 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
104
105 retval = ehci_halt(ehci);
106 if (retval)
107 return retval;
108 95
109 if ((pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x7808) || 96 /* Some NForce2 chips have problems with selective suspend;
110 (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x4396)) { 97 * fixed in newer silicon.
111 /* EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
112 * read/write memory space which does not belong to it when
113 * there is NULL pointer with T-bit set to 1 in the frame list
114 * table. To avoid the issue, the frame list link pointer
115 * should always contain a valid pointer to a inactive qh.
116 */ 98 */
117 ehci->use_dummy_qh = 1; 99 case 0x0068:
118 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI " 100 if (pdev->revision < 0xa4)
119 "dummy qh workaround\n"); 101 ehci->no_selective_suspend = 1;
120 } 102 break;
121 103 }
122 /* data structure init */
123 retval = ehci_init(hcd);
124 if (retval)
125 return retval;
126
127 switch (pdev->vendor) {
128 case PCI_VENDOR_ID_NEC:
129 ehci->need_io_watchdog = 0;
130 break; 104 break;
131 case PCI_VENDOR_ID_INTEL: 105 case PCI_VENDOR_ID_INTEL:
132 ehci->need_io_watchdog = 0;
133 ehci->fs_i_thresh = 1; 106 ehci->fs_i_thresh = 1;
134 if (pdev->device == 0x27cc) { 107 if (pdev->device == 0x27cc) {
135 ehci->broken_periodic = 1; 108 ehci->broken_periodic = 1;
136 ehci_info(ehci, "using broken periodic workaround\n"); 109 ehci_info(ehci, "using broken periodic workaround\n");
137 } 110 }
138 if (pdev->device == 0x0806 || pdev->device == 0x0811 111 if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB)
139 || pdev->device == 0x0829) {
140 ehci_info(ehci, "disable lpm for langwell/penwell\n");
141 ehci->has_lpm = 0;
142 }
143 if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB) {
144 hcd->has_tt = 1; 112 hcd->has_tt = 1;
145 tdi_reset(ehci);
146 }
147 break; 113 break;
148 case PCI_VENDOR_ID_TDI: 114 case PCI_VENDOR_ID_TDI:
149 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 115 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI)
150 hcd->has_tt = 1; 116 hcd->has_tt = 1;
151 tdi_reset(ehci);
152 }
153 break; 117 break;
154 case PCI_VENDOR_ID_AMD: 118 case PCI_VENDOR_ID_AMD:
155 /* AMD PLL quirk */ 119 /* AMD PLL quirk */
@@ -161,28 +125,17 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
161 retval = -EIO; 125 retval = -EIO;
162 goto done; 126 goto done;
163 } 127 }
164 break;
165 case PCI_VENDOR_ID_NVIDIA:
166 switch (pdev->device) {
167 /* Some NForce2 chips have problems with selective suspend;
168 * fixed in newer silicon.
169 */
170 case 0x0068:
171 if (pdev->revision < 0xa4)
172 ehci->no_selective_suspend = 1;
173 break;
174 128
175 /* MCP89 chips on the MacBookAir3,1 give EPROTO when 129 /*
176 * fetching device descriptors unless LPM is disabled. 130 * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
177 * There are also intermittent problems enumerating 131 * read/write memory space which does not belong to it when
178 * devices with PPCD enabled. 132 * there is NULL pointer with T-bit set to 1 in the frame list
133 * table. To avoid the issue, the frame list link pointer
134 * should always contain a valid pointer to a inactive qh.
179 */ 135 */
180 case 0x0d9d: 136 if (pdev->device == 0x7808) {
181 ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89"); 137 ehci->use_dummy_qh = 1;
182 ehci->has_lpm = 0; 138 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
183 ehci->has_ppcd = 0;
184 ehci->command &= ~CMD_PPCEE;
185 break;
186 } 139 }
187 break; 140 break;
188 case PCI_VENDOR_ID_VIA: 141 case PCI_VENDOR_ID_VIA:
@@ -203,6 +156,18 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
203 /* AMD PLL quirk */ 156 /* AMD PLL quirk */
204 if (usb_amd_find_chipset_info()) 157 if (usb_amd_find_chipset_info())
205 ehci->amd_pll_fix = 1; 158 ehci->amd_pll_fix = 1;
159
160 /*
161 * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
162 * read/write memory space which does not belong to it when
163 * there is NULL pointer with T-bit set to 1 in the frame list
164 * table. To avoid the issue, the frame list link pointer
165 * should always contain a valid pointer to a inactive qh.
166 */
167 if (pdev->device == 0x4396) {
168 ehci->use_dummy_qh = 1;
169 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
170 }
206 /* SB600 and old version of SB700 have a bug in EHCI controller, 171 /* SB600 and old version of SB700 have a bug in EHCI controller,
207 * which causes usb devices lose response in some cases. 172 * which causes usb devices lose response in some cases.
208 */ 173 */
@@ -231,6 +196,40 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
231 break; 196 break;
232 } 197 }
233 198
199 retval = ehci_setup(hcd);
200 if (retval)
201 return retval;
202
203 /* These workarounds need to be applied after ehci_setup() */
204 switch (pdev->vendor) {
205 case PCI_VENDOR_ID_NEC:
206 ehci->need_io_watchdog = 0;
207 break;
208 case PCI_VENDOR_ID_INTEL:
209 ehci->need_io_watchdog = 0;
210 if (pdev->device == 0x0806 || pdev->device == 0x0811
211 || pdev->device == 0x0829) {
212 ehci_info(ehci, "disable lpm for langwell/penwell\n");
213 ehci->has_lpm = 0;
214 }
215 break;
216 case PCI_VENDOR_ID_NVIDIA:
217 switch (pdev->device) {
218 /* MCP89 chips on the MacBookAir3,1 give EPROTO when
219 * fetching device descriptors unless LPM is disabled.
220 * There are also intermittent problems enumerating
221 * devices with PPCD enabled.
222 */
223 case 0x0d9d:
224 ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89");
225 ehci->has_lpm = 0;
226 ehci->has_ppcd = 0;
227 ehci->command &= ~CMD_PPCEE;
228 break;
229 }
230 break;
231 }
232
234 /* optional debug port, normally in the first BAR */ 233 /* optional debug port, normally in the first BAR */
235 temp = pci_find_capability(pdev, 0x0a); 234 temp = pci_find_capability(pdev, 0x0a);
236 if (temp) { 235 if (temp) {
@@ -238,7 +237,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
238 temp >>= 16; 237 temp >>= 16;
239 if ((temp & (3 << 13)) == (1 << 13)) { 238 if ((temp & (3 << 13)) == (1 << 13)) {
240 temp &= 0x1fff; 239 temp &= 0x1fff;
241 ehci->debug = ehci_to_hcd(ehci)->regs + temp; 240 ehci->debug = hcd->regs + temp;
242 temp = ehci_readl(ehci, &ehci->debug->control); 241 temp = ehci_readl(ehci, &ehci->debug->control);
243 ehci_info(ehci, "debug port %d%s\n", 242 ehci_info(ehci, "debug port %d%s\n",
244 HCS_DEBUG_PORT(ehci->hcs_params), 243 HCS_DEBUG_PORT(ehci->hcs_params),
@@ -250,8 +249,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
250 } 249 }
251 } 250 }
252 251
253 ehci_reset(ehci);
254
255 /* at least the Genesys GL880S needs fixup here */ 252 /* at least the Genesys GL880S needs fixup here */
256 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params); 253 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
257 temp &= 0x0f; 254 temp &= 0x0f;
@@ -275,10 +272,11 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
275 } 272 }
276 273
277 /* Serial Bus Release Number is at PCI 0x60 offset */ 274 /* Serial Bus Release Number is at PCI 0x60 offset */
278 pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
279 if (pdev->vendor == PCI_VENDOR_ID_STMICRO 275 if (pdev->vendor == PCI_VENDOR_ID_STMICRO
280 && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST) 276 && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST)
281 ehci->sbrn = 0x20; /* ConneXT has no sbrn register */ 277 ; /* ConneXT has no sbrn register */
278 else
279 pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
282 280
283 /* Keep this around for a while just in case some EHCI 281 /* Keep this around for a while just in case some EHCI
284 * implementation uses legacy PCI PM support. This test 282 * implementation uses legacy PCI PM support. This test
@@ -331,29 +329,7 @@ done:
331 329
332static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) 330static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
333{ 331{
334 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 332 return ehci_suspend(hcd, do_wakeup);
335 unsigned long flags;
336 int rc = 0;
337
338 if (time_before(jiffies, ehci->next_statechange))
339 msleep(10);
340
341 /* Root hub was already suspended. Disable irq emission and
342 * mark HW unaccessible. The PM and USB cores make sure that
343 * the root hub is either suspended or stopped.
344 */
345 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
346 spin_lock_irqsave (&ehci->lock, flags);
347 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
348 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
349
350 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
351 spin_unlock_irqrestore (&ehci->lock, flags);
352
353 // could save FLADJ in case of Vaux power loss
354 // ... we'd only use it to handle clock skew
355
356 return rc;
357} 333}
358 334
359static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev) 335static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
@@ -402,54 +378,8 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
402 if (usb_is_intel_switchable_ehci(pdev)) 378 if (usb_is_intel_switchable_ehci(pdev))
403 ehci_enable_xhci_companion(); 379 ehci_enable_xhci_companion();
404 380
405 // maybe restore FLADJ 381 if (ehci_resume(hcd, hibernated) != 0)
406 382 (void) ehci_pci_reinit(ehci, pdev);
407 if (time_before(jiffies, ehci->next_statechange))
408 msleep(100);
409
410 /* Mark hardware accessible again as we are out of D3 state by now */
411 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
412
413 /* If CF is still set and we aren't resuming from hibernation
414 * then we maintained PCI Vaux power.
415 * Just undo the effect of ehci_pci_suspend().
416 */
417 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
418 !hibernated) {
419 int mask = INTR_MASK;
420
421 ehci_prepare_ports_for_controller_resume(ehci);
422 if (!hcd->self.root_hub->do_remote_wakeup)
423 mask &= ~STS_PCD;
424 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
425 ehci_readl(ehci, &ehci->regs->intr_enable);
426 return 0;
427 }
428
429 usb_root_hub_lost_power(hcd->self.root_hub);
430
431 /* Else reset, to cope with power loss or flush-to-storage
432 * style "resume" having let BIOS kick in during reboot.
433 */
434 (void) ehci_halt(ehci);
435 (void) ehci_reset(ehci);
436 (void) ehci_pci_reinit(ehci, pdev);
437
438 /* emptying the schedule aborts any urbs */
439 spin_lock_irq(&ehci->lock);
440 if (ehci->reclaim)
441 end_unlink_async(ehci);
442 ehci_work(ehci);
443 spin_unlock_irq(&ehci->lock);
444
445 ehci_writel(ehci, ehci->command, &ehci->regs->command);
446 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
447 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
448
449 /* here we "know" root ports should always stay powered */
450 ehci_port_power(ehci, 1);
451
452 ehci->rh_state = EHCI_RH_SUSPENDED;
453 return 0; 383 return 0;
454} 384}
455#endif 385#endif
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index dfe881a34ae2..4b1d896d5a22 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -153,17 +153,16 @@ static int __devexit ehci_platform_remove(struct platform_device *dev)
153static int ehci_platform_suspend(struct device *dev) 153static int ehci_platform_suspend(struct device *dev)
154{ 154{
155 struct usb_hcd *hcd = dev_get_drvdata(dev); 155 struct usb_hcd *hcd = dev_get_drvdata(dev);
156 bool wakeup = device_may_wakeup(dev); 156 bool do_wakeup = device_may_wakeup(dev);
157 157
158 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), wakeup); 158 return ehci_suspend(hcd, do_wakeup);
159 return 0;
160} 159}
161 160
162static int ehci_platform_resume(struct device *dev) 161static int ehci_platform_resume(struct device *dev)
163{ 162{
164 struct usb_hcd *hcd = dev_get_drvdata(dev); 163 struct usb_hcd *hcd = dev_get_drvdata(dev);
165 164
166 ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd)); 165 ehci_resume(hcd, false);
167 return 0; 166 return 0;
168} 167}
169 168
diff --git a/drivers/usb/host/ehci-pmcmsp.c b/drivers/usb/host/ehci-pmcmsp.c
index e8d54de44acc..087aee2a904f 100644
--- a/drivers/usb/host/ehci-pmcmsp.c
+++ b/drivers/usb/host/ehci-pmcmsp.c
@@ -78,27 +78,14 @@ static int ehci_msp_setup(struct usb_hcd *hcd)
78{ 78{
79 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 79 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
80 int retval; 80 int retval;
81
81 ehci->big_endian_mmio = 1; 82 ehci->big_endian_mmio = 1;
82 ehci->big_endian_desc = 1; 83 ehci->big_endian_desc = 1;
83 84
84 ehci->caps = hcd->regs; 85 ehci->caps = hcd->regs;
85 ehci->regs = hcd->regs +
86 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
87 dbg_hcs_params(ehci, "reset");
88 dbg_hcc_params(ehci, "reset");
89
90 /* cache this readonly data; minimize chip reads */
91 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
92 hcd->has_tt = 1; 86 hcd->has_tt = 1;
93 87
94 retval = ehci_halt(ehci); 88 retval = ehci_setup(hcd);
95 if (retval)
96 return retval;
97
98 ehci_reset(ehci);
99
100 /* data structure init */
101 retval = ehci_init(hcd);
102 if (retval) 89 if (retval)
103 return retval; 90 return retval;
104 91
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 41d11fe14252..bbbe89dfd886 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -17,24 +17,6 @@
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/of_platform.h> 18#include <linux/of_platform.h>
19 19
20/* called during probe() after chip reset completes */
21static int ehci_ppc_of_setup(struct usb_hcd *hcd)
22{
23 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
24 int retval;
25
26 retval = ehci_halt(ehci);
27 if (retval)
28 return retval;
29
30 retval = ehci_init(hcd);
31 if (retval)
32 return retval;
33
34 ehci->sbrn = 0x20;
35 return ehci_reset(ehci);
36}
37
38 20
39static const struct hc_driver ehci_ppc_of_hc_driver = { 21static const struct hc_driver ehci_ppc_of_hc_driver = {
40 .description = hcd_name, 22 .description = hcd_name,
@@ -50,7 +32,7 @@ static const struct hc_driver ehci_ppc_of_hc_driver = {
50 /* 32 /*
51 * basic lifecycle operations 33 * basic lifecycle operations
52 */ 34 */
53 .reset = ehci_ppc_of_setup, 35 .reset = ehci_setup,
54 .start = ehci_run, 36 .start = ehci_run,
55 .stop = ehci_stop, 37 .stop = ehci_stop,
56 .shutdown = ehci_shutdown, 38 .shutdown = ehci_shutdown,
@@ -178,11 +160,6 @@ static int __devinit ehci_hcd_ppc_of_probe(struct platform_device *op)
178 ehci->big_endian_desc = 1; 160 ehci->big_endian_desc = 1;
179 161
180 ehci->caps = hcd->regs; 162 ehci->caps = hcd->regs;
181 ehci->regs = hcd->regs +
182 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
183
184 /* cache this readonly data; minimize chip reads */
185 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
186 163
187 if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) { 164 if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) {
188 rv = ppc44x_enable_bmt(dn); 165 rv = ppc44x_enable_bmt(dn);
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index a20e496eb479..45a356e9f138 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -55,28 +55,12 @@ static int ps3_ehci_hc_reset(struct usb_hcd *hcd)
55 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 55 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
56 56
57 ehci->big_endian_mmio = 1; 57 ehci->big_endian_mmio = 1;
58
59 ehci->caps = hcd->regs; 58 ehci->caps = hcd->regs;
60 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
61 &ehci->caps->hc_capbase));
62
63 dbg_hcs_params(ehci, "reset");
64 dbg_hcc_params(ehci, "reset");
65
66 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
67
68 result = ehci_halt(ehci);
69 59
60 result = ehci_setup(hcd);
70 if (result) 61 if (result)
71 return result; 62 return result;
72 63
73 result = ehci_init(hcd);
74
75 if (result)
76 return result;
77
78 ehci_reset(ehci);
79
80 ps3_ehci_setup_insnreg(ehci); 64 ps3_ehci_setup_insnreg(ehci);
81 65
82 return result; 66 return result;
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c
index c474cec064e4..13c179fb2ee2 100644
--- a/drivers/usb/host/ehci-s5p.c
+++ b/drivers/usb/host/ehci-s5p.c
@@ -40,7 +40,7 @@ static const struct hc_driver s5p_ehci_hc_driver = {
40 .irq = ehci_irq, 40 .irq = ehci_irq,
41 .flags = HCD_MEMORY | HCD_USB2, 41 .flags = HCD_MEMORY | HCD_USB2,
42 42
43 .reset = ehci_init, 43 .reset = ehci_setup,
44 .start = ehci_run, 44 .start = ehci_run,
45 .stop = ehci_stop, 45 .stop = ehci_stop,
46 .shutdown = ehci_shutdown, 46 .shutdown = ehci_shutdown,
@@ -79,7 +79,8 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
79 return -EINVAL; 79 return -EINVAL;
80 } 80 }
81 81
82 s5p_ehci = kzalloc(sizeof(struct s5p_ehci_hcd), GFP_KERNEL); 82 s5p_ehci = devm_kzalloc(&pdev->dev, sizeof(struct s5p_ehci_hcd),
83 GFP_KERNEL);
83 if (!s5p_ehci) 84 if (!s5p_ehci)
84 return -ENOMEM; 85 return -ENOMEM;
85 86
@@ -89,8 +90,7 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
89 dev_name(&pdev->dev)); 90 dev_name(&pdev->dev));
90 if (!hcd) { 91 if (!hcd) {
91 dev_err(&pdev->dev, "Unable to create HCD\n"); 92 dev_err(&pdev->dev, "Unable to create HCD\n");
92 err = -ENOMEM; 93 return -ENOMEM;
93 goto fail_hcd;
94 } 94 }
95 95
96 s5p_ehci->hcd = hcd; 96 s5p_ehci->hcd = hcd;
@@ -115,7 +115,7 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
115 115
116 hcd->rsrc_start = res->start; 116 hcd->rsrc_start = res->start;
117 hcd->rsrc_len = resource_size(res); 117 hcd->rsrc_len = resource_size(res);
118 hcd->regs = ioremap(res->start, resource_size(res)); 118 hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
119 if (!hcd->regs) { 119 if (!hcd->regs) {
120 dev_err(&pdev->dev, "Failed to remap I/O memory\n"); 120 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
121 err = -ENOMEM; 121 err = -ENOMEM;
@@ -126,7 +126,7 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
126 if (!irq) { 126 if (!irq) {
127 dev_err(&pdev->dev, "Failed to get IRQ\n"); 127 dev_err(&pdev->dev, "Failed to get IRQ\n");
128 err = -ENODEV; 128 err = -ENODEV;
129 goto fail; 129 goto fail_io;
130 } 130 }
131 131
132 if (pdata->phy_init) 132 if (pdata->phy_init)
@@ -134,40 +134,26 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
134 134
135 ehci = hcd_to_ehci(hcd); 135 ehci = hcd_to_ehci(hcd);
136 ehci->caps = hcd->regs; 136 ehci->caps = hcd->regs;
137 ehci->regs = hcd->regs +
138 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
139 137
140 /* DMA burst Enable */ 138 /* DMA burst Enable */
141 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); 139 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
142 140
143 dbg_hcs_params(ehci, "reset");
144 dbg_hcc_params(ehci, "reset");
145
146 /* cache this readonly data; minimize chip reads */
147 ehci->hcs_params = readl(&ehci->caps->hcs_params);
148
149 ehci_reset(ehci);
150
151 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 141 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
152 if (err) { 142 if (err) {
153 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 143 dev_err(&pdev->dev, "Failed to add USB HCD\n");
154 goto fail; 144 goto fail_io;
155 } 145 }
156 146
157 platform_set_drvdata(pdev, s5p_ehci); 147 platform_set_drvdata(pdev, s5p_ehci);
158 148
159 return 0; 149 return 0;
160 150
161fail:
162 iounmap(hcd->regs);
163fail_io: 151fail_io:
164 clk_disable(s5p_ehci->clk); 152 clk_disable(s5p_ehci->clk);
165fail_clken: 153fail_clken:
166 clk_put(s5p_ehci->clk); 154 clk_put(s5p_ehci->clk);
167fail_clk: 155fail_clk:
168 usb_put_hcd(hcd); 156 usb_put_hcd(hcd);
169fail_hcd:
170 kfree(s5p_ehci);
171 return err; 157 return err;
172} 158}
173 159
@@ -182,13 +168,10 @@ static int __devexit s5p_ehci_remove(struct platform_device *pdev)
182 if (pdata && pdata->phy_exit) 168 if (pdata && pdata->phy_exit)
183 pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 169 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
184 170
185 iounmap(hcd->regs);
186
187 clk_disable(s5p_ehci->clk); 171 clk_disable(s5p_ehci->clk);
188 clk_put(s5p_ehci->clk); 172 clk_put(s5p_ehci->clk);
189 173
190 usb_put_hcd(hcd); 174 usb_put_hcd(hcd);
191 kfree(s5p_ehci);
192 175
193 return 0; 176 return 0;
194} 177}
@@ -207,27 +190,12 @@ static int s5p_ehci_suspend(struct device *dev)
207{ 190{
208 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); 191 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
209 struct usb_hcd *hcd = s5p_ehci->hcd; 192 struct usb_hcd *hcd = s5p_ehci->hcd;
210 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 193 bool do_wakeup = device_may_wakeup(dev);
211 struct platform_device *pdev = to_platform_device(dev); 194 struct platform_device *pdev = to_platform_device(dev);
212 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 195 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
213 unsigned long flags; 196 int rc;
214 int rc = 0;
215
216 if (time_before(jiffies, ehci->next_statechange))
217 msleep(20);
218 197
219 /* 198 rc = ehci_suspend(hcd, do_wakeup);
220 * Root hub was already suspended. Disable irq emission and
221 * mark HW unaccessible. The PM and USB cores make sure that
222 * the root hub is either suspended or stopped.
223 */
224 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
225 spin_lock_irqsave(&ehci->lock, flags);
226 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
227 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
228
229 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
230 spin_unlock_irqrestore(&ehci->lock, flags);
231 199
232 if (pdata && pdata->phy_exit) 200 if (pdata && pdata->phy_exit)
233 pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 201 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
@@ -241,7 +209,6 @@ static int s5p_ehci_resume(struct device *dev)
241{ 209{
242 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); 210 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
243 struct usb_hcd *hcd = s5p_ehci->hcd; 211 struct usb_hcd *hcd = s5p_ehci->hcd;
244 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
245 struct platform_device *pdev = to_platform_device(dev); 212 struct platform_device *pdev = to_platform_device(dev);
246 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 213 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
247 214
@@ -253,44 +220,7 @@ static int s5p_ehci_resume(struct device *dev)
253 /* DMA burst Enable */ 220 /* DMA burst Enable */
254 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); 221 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
255 222
256 if (time_before(jiffies, ehci->next_statechange)) 223 ehci_resume(hcd, false);
257 msleep(100);
258
259 /* Mark hardware accessible again as we are out of D3 state by now */
260 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
261
262 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
263 int mask = INTR_MASK;
264
265 ehci_prepare_ports_for_controller_resume(ehci);
266 if (!hcd->self.root_hub->do_remote_wakeup)
267 mask &= ~STS_PCD;
268 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
269 ehci_readl(ehci, &ehci->regs->intr_enable);
270 return 0;
271 }
272
273 usb_root_hub_lost_power(hcd->self.root_hub);
274
275 (void) ehci_halt(ehci);
276 (void) ehci_reset(ehci);
277
278 /* emptying the schedule aborts any urbs */
279 spin_lock_irq(&ehci->lock);
280 if (ehci->reclaim)
281 end_unlink_async(ehci);
282 ehci_work(ehci);
283 spin_unlock_irq(&ehci->lock);
284
285 ehci_writel(ehci, ehci->command, &ehci->regs->command);
286 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
287 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
288
289 /* here we "know" root ports should always stay powered */
290 ehci_port_power(ehci, 1);
291
292 ehci->rh_state = EHCI_RH_SUSPENDED;
293
294 return 0; 224 return 0;
295} 225}
296#else 226#else
diff --git a/drivers/usb/host/ehci-sead3.c b/drivers/usb/host/ehci-sead3.c
index cc199e87a7a9..58c96bd50d22 100644
--- a/drivers/usb/host/ehci-sead3.c
+++ b/drivers/usb/host/ehci-sead3.c
@@ -160,84 +160,16 @@ static int ehci_hcd_sead3_drv_remove(struct platform_device *pdev)
160static int ehci_hcd_sead3_drv_suspend(struct device *dev) 160static int ehci_hcd_sead3_drv_suspend(struct device *dev)
161{ 161{
162 struct usb_hcd *hcd = dev_get_drvdata(dev); 162 struct usb_hcd *hcd = dev_get_drvdata(dev);
163 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 163 bool do_wakeup = device_may_wakeup(dev);
164 unsigned long flags;
165 int rc = 0;
166
167 if (time_before(jiffies, ehci->next_statechange))
168 msleep(20);
169
170 /* Root hub was already suspended. Disable irq emission and
171 * mark HW unaccessible. The PM and USB cores make sure that
172 * the root hub is either suspended or stopped.
173 */
174 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
175 spin_lock_irqsave(&ehci->lock, flags);
176 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
177 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
178
179 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
180 spin_unlock_irqrestore(&ehci->lock, flags);
181 164
182 /* could save FLADJ in case of Vaux power loss 165 return ehci_suspend(hcd, do_wakeup);
183 * ... we'd only use it to handle clock skew
184 */
185
186 return rc;
187} 166}
188 167
189static int ehci_hcd_sead3_drv_resume(struct device *dev) 168static int ehci_hcd_sead3_drv_resume(struct device *dev)
190{ 169{
191 struct usb_hcd *hcd = dev_get_drvdata(dev); 170 struct usb_hcd *hcd = dev_get_drvdata(dev);
192 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
193
194 /* maybe restore FLADJ. */
195
196 if (time_before(jiffies, ehci->next_statechange))
197 msleep(100);
198
199 /* Mark hardware accessible again as we are out of D3 state by now */
200 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
201
202 /* If CF is still set, we maintained PCI Vaux power.
203 * Just undo the effect of ehci_pci_suspend().
204 */
205 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
206 int mask = INTR_MASK;
207
208 ehci_prepare_ports_for_controller_resume(ehci);
209 if (!hcd->self.root_hub->do_remote_wakeup)
210 mask &= ~STS_PCD;
211 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
212 ehci_readl(ehci, &ehci->regs->intr_enable);
213 return 0;
214 }
215
216 ehci_dbg(ehci, "lost power, restarting\n");
217 usb_root_hub_lost_power(hcd->self.root_hub);
218
219 /* Else reset, to cope with power loss or flush-to-storage
220 * style "resume" having let BIOS kick in during reboot.
221 */
222 (void) ehci_halt(ehci);
223 (void) ehci_reset(ehci);
224
225 /* emptying the schedule aborts any urbs */
226 spin_lock_irq(&ehci->lock);
227 if (ehci->reclaim)
228 end_unlink_async(ehci);
229 ehci_work(ehci);
230 spin_unlock_irq(&ehci->lock);
231
232 ehci_writel(ehci, ehci->command, &ehci->regs->command);
233 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
234 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
235
236 /* here we "know" root ports should always stay powered */
237 ehci_port_power(ehci, 1);
238
239 ehci->rh_state = EHCI_RH_SUSPENDED;
240 171
172 ehci_resume(hcd, false);
241 return 0; 173 return 0;
242} 174}
243 175
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
index e7cb3925abf8..b3f1e3650da0 100644
--- a/drivers/usb/host/ehci-sh.c
+++ b/drivers/usb/host/ehci-sh.c
@@ -24,25 +24,11 @@ static int ehci_sh_reset(struct usb_hcd *hcd)
24 int ret; 24 int ret;
25 25
26 ehci->caps = hcd->regs; 26 ehci->caps = hcd->regs;
27 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
28 &ehci->caps->hc_capbase));
29 27
30 dbg_hcs_params(ehci, "reset"); 28 ret = ehci_setup(hcd);
31 dbg_hcc_params(ehci, "reset");
32
33 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
34
35 ret = ehci_halt(ehci);
36 if (unlikely(ret))
37 return ret;
38
39 ret = ehci_init(hcd);
40 if (unlikely(ret)) 29 if (unlikely(ret))
41 return ret; 30 return ret;
42 31
43 ehci->sbrn = 0x20;
44
45 ehci_reset(ehci);
46 ehci_port_power(ehci, 0); 32 ehci_port_power(ehci, 0);
47 33
48 return ret; 34 return ret;
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c
index 37ba8c8d2fd0..c718a065e154 100644
--- a/drivers/usb/host/ehci-spear.c
+++ b/drivers/usb/host/ehci-spear.c
@@ -41,19 +41,11 @@ static int ehci_spear_setup(struct usb_hcd *hcd)
41 41
42 /* registers start at offset 0x0 */ 42 /* registers start at offset 0x0 */
43 ehci->caps = hcd->regs; 43 ehci->caps = hcd->regs;
44 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
45 &ehci->caps->hc_capbase));
46 /* cache this readonly data; minimize chip reads */
47 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
48 retval = ehci_halt(ehci);
49 if (retval)
50 return retval;
51 44
52 retval = ehci_init(hcd); 45 retval = ehci_setup(hcd);
53 if (retval) 46 if (retval)
54 return retval; 47 return retval;
55 48
56 ehci_reset(ehci);
57 ehci_port_power(ehci, 0); 49 ehci_port_power(ehci, 0);
58 50
59 return retval; 51 return retval;
@@ -97,71 +89,16 @@ static const struct hc_driver ehci_spear_hc_driver = {
97static int ehci_spear_drv_suspend(struct device *dev) 89static int ehci_spear_drv_suspend(struct device *dev)
98{ 90{
99 struct usb_hcd *hcd = dev_get_drvdata(dev); 91 struct usb_hcd *hcd = dev_get_drvdata(dev);
100 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 92 bool do_wakeup = device_may_wakeup(dev);
101 unsigned long flags;
102 int rc = 0;
103 93
104 if (time_before(jiffies, ehci->next_statechange)) 94 return ehci_suspend(hcd, do_wakeup);
105 msleep(10);
106
107 /*
108 * Root hub was already suspended. Disable irq emission and mark HW
109 * unaccessible. The PM and USB cores make sure that the root hub is
110 * either suspended or stopped.
111 */
112 spin_lock_irqsave(&ehci->lock, flags);
113 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
114 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
115 ehci_readl(ehci, &ehci->regs->intr_enable);
116 spin_unlock_irqrestore(&ehci->lock, flags);
117
118 return rc;
119} 95}
120 96
121static int ehci_spear_drv_resume(struct device *dev) 97static int ehci_spear_drv_resume(struct device *dev)
122{ 98{
123 struct usb_hcd *hcd = dev_get_drvdata(dev); 99 struct usb_hcd *hcd = dev_get_drvdata(dev);
124 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
125
126 if (time_before(jiffies, ehci->next_statechange))
127 msleep(100);
128
129 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
130 int mask = INTR_MASK;
131
132 ehci_prepare_ports_for_controller_resume(ehci);
133
134 if (!hcd->self.root_hub->do_remote_wakeup)
135 mask &= ~STS_PCD;
136
137 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
138 ehci_readl(ehci, &ehci->regs->intr_enable);
139 return 0;
140 }
141
142 usb_root_hub_lost_power(hcd->self.root_hub);
143
144 /*
145 * Else reset, to cope with power loss or flush-to-storage style
146 * "resume" having let BIOS kick in during reboot.
147 */
148 ehci_halt(ehci);
149 ehci_reset(ehci);
150
151 /* emptying the schedule aborts any urbs */
152 spin_lock_irq(&ehci->lock);
153 if (ehci->reclaim)
154 end_unlink_async(ehci);
155
156 ehci_work(ehci);
157 spin_unlock_irq(&ehci->lock);
158
159 ehci_writel(ehci, ehci->command, &ehci->regs->command);
160 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
161 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
162 100
163 /* here we "know" root ports should always stay powered */ 101 ehci_resume(hcd, false);
164 ehci_port_power(ehci, 1);
165 return 0; 102 return 0;
166} 103}
167#endif /* CONFIG_PM */ 104#endif /* CONFIG_PM */
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 68548236ec42..f7f3ce3275b8 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -17,6 +17,7 @@
17 */ 17 */
18 18
19#include <linux/clk.h> 19#include <linux/clk.h>
20#include <linux/err.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
21#include <linux/platform_data/tegra_usb.h> 22#include <linux/platform_data/tegra_usb.h>
22#include <linux/irq.h> 23#include <linux/irq.h>
@@ -280,30 +281,14 @@ static int tegra_ehci_setup(struct usb_hcd *hcd)
280 281
281 /* EHCI registers start at offset 0x100 */ 282 /* EHCI registers start at offset 0x100 */
282 ehci->caps = hcd->regs + 0x100; 283 ehci->caps = hcd->regs + 0x100;
283 ehci->regs = hcd->regs + 0x100 +
284 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
285
286 dbg_hcs_params(ehci, "reset");
287 dbg_hcc_params(ehci, "reset");
288
289 /* cache this readonly data; minimize chip reads */
290 ehci->hcs_params = readl(&ehci->caps->hcs_params);
291 284
292 /* switch to host mode */ 285 /* switch to host mode */
293 hcd->has_tt = 1; 286 hcd->has_tt = 1;
294 ehci_reset(ehci);
295 287
296 retval = ehci_halt(ehci); 288 retval = ehci_setup(ehci);
297 if (retval) 289 if (retval)
298 return retval; 290 return retval;
299 291
300 /* data structure init */
301 retval = ehci_init(hcd);
302 if (retval)
303 return retval;
304
305 ehci->sbrn = 0x20;
306
307 ehci_port_power(ehci, 1); 292 ehci_port_power(ehci, 1);
308 return retval; 293 return retval;
309} 294}
@@ -749,8 +734,8 @@ static int tegra_ehci_probe(struct platform_device *pdev)
749 734
750#ifdef CONFIG_USB_OTG_UTILS 735#ifdef CONFIG_USB_OTG_UTILS
751 if (pdata->operating_mode == TEGRA_USB_OTG) { 736 if (pdata->operating_mode == TEGRA_USB_OTG) {
752 tegra->transceiver = usb_get_transceiver(); 737 tegra->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
753 if (tegra->transceiver) 738 if (!IS_ERR_OR_NULL(tegra->transceiver))
754 otg_set_host(tegra->transceiver->otg, &hcd->self); 739 otg_set_host(tegra->transceiver->otg, &hcd->self);
755 } 740 }
756#endif 741#endif
@@ -773,9 +758,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
773 758
774fail: 759fail:
775#ifdef CONFIG_USB_OTG_UTILS 760#ifdef CONFIG_USB_OTG_UTILS
776 if (tegra->transceiver) { 761 if (!IS_ERR_OR_NULL(tegra->transceiver)) {
777 otg_set_host(tegra->transceiver->otg, NULL); 762 otg_set_host(tegra->transceiver->otg, NULL);
778 usb_put_transceiver(tegra->transceiver); 763 usb_put_phy(tegra->transceiver);
779 } 764 }
780#endif 765#endif
781 tegra_usb_phy_close(tegra->phy); 766 tegra_usb_phy_close(tegra->phy);
@@ -808,9 +793,9 @@ static int tegra_ehci_remove(struct platform_device *pdev)
808 pm_runtime_put_noidle(&pdev->dev); 793 pm_runtime_put_noidle(&pdev->dev);
809 794
810#ifdef CONFIG_USB_OTG_UTILS 795#ifdef CONFIG_USB_OTG_UTILS
811 if (tegra->transceiver) { 796 if (!IS_ERR_OR_NULL(tegra->transceiver)) {
812 otg_set_host(tegra->transceiver->otg, NULL); 797 otg_set_host(tegra->transceiver->otg, NULL);
813 usb_put_transceiver(tegra->transceiver); 798 usb_put_phy(tegra->transceiver);
814 } 799 }
815#endif 800#endif
816 801
diff --git a/drivers/usb/host/ehci-vt8500.c b/drivers/usb/host/ehci-vt8500.c
index c1eda73916cd..4d147c4e33f5 100644
--- a/drivers/usb/host/ehci-vt8500.c
+++ b/drivers/usb/host/ehci-vt8500.c
@@ -48,7 +48,7 @@ static const struct hc_driver vt8500_ehci_hc_driver = {
48 /* 48 /*
49 * basic lifecycle operations 49 * basic lifecycle operations
50 */ 50 */
51 .reset = ehci_init, 51 .reset = ehci_setup,
52 .start = ehci_run, 52 .start = ehci_run,
53 .stop = ehci_stop, 53 .stop = ehci_stop,
54 .shutdown = ehci_shutdown, 54 .shutdown = ehci_shutdown,
@@ -121,18 +121,6 @@ static int vt8500_ehci_drv_probe(struct platform_device *pdev)
121 121
122 ehci = hcd_to_ehci(hcd); 122 ehci = hcd_to_ehci(hcd);
123 ehci->caps = hcd->regs; 123 ehci->caps = hcd->regs;
124 ehci->regs = hcd->regs +
125 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
126
127 dbg_hcs_params(ehci, "reset");
128 dbg_hcc_params(ehci, "reset");
129
130 /* cache this readonly data; minimize chip reads */
131 ehci->hcs_params = readl(&ehci->caps->hcs_params);
132
133 ehci_port_power(ehci, 1);
134
135 ehci_reset(ehci);
136 124
137 ret = usb_add_hcd(hcd, pdev->resource[1].start, 125 ret = usb_add_hcd(hcd, pdev->resource[1].start,
138 IRQF_SHARED); 126 IRQF_SHARED);
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c
index 3d2e26cbb34c..ec598082c14b 100644
--- a/drivers/usb/host/ehci-w90x900.c
+++ b/drivers/usb/host/ehci-w90x900.c
@@ -71,21 +71,14 @@ static int __devinit usb_w90x900_probe(const struct hc_driver *driver,
71 val |= ENPHY; 71 val |= ENPHY;
72 __raw_writel(val, ehci->regs+PHY1_CTR); 72 __raw_writel(val, ehci->regs+PHY1_CTR);
73 73
74 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
75 ehci->sbrn = 0x20;
76
77 irq = platform_get_irq(pdev, 0); 74 irq = platform_get_irq(pdev, 0);
78 if (irq < 0) 75 if (irq < 0)
79 goto err4; 76 goto err4;
80 77
81 ehci_reset(ehci);
82
83 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 78 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
84 if (retval != 0) 79 if (retval != 0)
85 goto err4; 80 goto err4;
86 81
87 ehci_writel(ehci, 1, &ehci->regs->configured_flag);
88
89 return retval; 82 return retval;
90err4: 83err4:
91 iounmap(hcd->regs); 84 iounmap(hcd->regs);
@@ -120,7 +113,7 @@ static const struct hc_driver ehci_w90x900_hc_driver = {
120 /* 113 /*
121 * basic lifecycle operations 114 * basic lifecycle operations
122 */ 115 */
123 .reset = ehci_init, 116 .reset = ehci_setup,
124 .start = ehci_run, 117 .start = ehci_run,
125 118
126 .stop = ehci_stop, 119 .stop = ehci_stop,
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c
index e9713d589e30..39f24fa37ebe 100644
--- a/drivers/usb/host/ehci-xilinx-of.c
+++ b/drivers/usb/host/ehci-xilinx-of.c
@@ -32,30 +32,6 @@
32#include <linux/of_address.h> 32#include <linux/of_address.h>
33 33
34/** 34/**
35 * ehci_xilinx_of_setup - Initialize the device for ehci_reset()
36 * @hcd: Pointer to the usb_hcd device to which the host controller bound
37 *
38 * called during probe() after chip reset completes.
39 */
40static int ehci_xilinx_of_setup(struct usb_hcd *hcd)
41{
42 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
43 int retval;
44
45 retval = ehci_halt(ehci);
46 if (retval)
47 return retval;
48
49 retval = ehci_init(hcd);
50 if (retval)
51 return retval;
52
53 ehci->sbrn = 0x20;
54
55 return ehci_reset(ehci);
56}
57
58/**
59 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it 35 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
60 * @hcd: Pointer to the usb_hcd device to which the host controller bound 36 * @hcd: Pointer to the usb_hcd device to which the host controller bound
61 * @portnum:Port number to which the device is attached. 37 * @portnum:Port number to which the device is attached.
@@ -107,7 +83,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
107 /* 83 /*
108 * basic lifecycle operations 84 * basic lifecycle operations
109 */ 85 */
110 .reset = ehci_xilinx_of_setup, 86 .reset = ehci_setup,
111 .start = ehci_run, 87 .start = ehci_run,
112 .stop = ehci_stop, 88 .stop = ehci_stop,
113 .shutdown = ehci_shutdown, 89 .shutdown = ehci_shutdown,
@@ -219,11 +195,6 @@ static int __devinit ehci_hcd_xilinx_of_probe(struct platform_device *op)
219 /* Debug registers are at the first 0x100 region 195 /* Debug registers are at the first 0x100 region
220 */ 196 */
221 ehci->caps = hcd->regs + 0x100; 197 ehci->caps = hcd->regs + 0x100;
222 ehci->regs = hcd->regs + 0x100 +
223 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
224
225 /* cache this readonly data; minimize chip reads */
226 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
227 198
228 rv = usb_add_hcd(hcd, irq, 0); 199 rv = usb_add_hcd(hcd, irq, 0);
229 if (rv == 0) 200 if (rv == 0)
diff --git a/drivers/usb/host/ehci-xls.c b/drivers/usb/host/ehci-xls.c
index 72f08196f8cd..99c353a85ae4 100644
--- a/drivers/usb/host/ehci-xls.c
+++ b/drivers/usb/host/ehci-xls.c
@@ -14,30 +14,11 @@
14 14
15static int ehci_xls_setup(struct usb_hcd *hcd) 15static int ehci_xls_setup(struct usb_hcd *hcd)
16{ 16{
17 int retval;
18 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 17 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
19 18
20 ehci->caps = hcd->regs; 19 ehci->caps = hcd->regs;
21 ehci->regs = hcd->regs +
22 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
23 dbg_hcs_params(ehci, "reset");
24 dbg_hcc_params(ehci, "reset");
25 20
26 /* cache this readonly data; minimize chip reads */ 21 return ehci_setup(ehci);
27 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
28
29 retval = ehci_halt(ehci);
30 if (retval)
31 return retval;
32
33 /* data structure init */
34 retval = ehci_init(hcd);
35 if (retval)
36 return retval;
37
38 ehci_reset(ehci);
39
40 return retval;
41} 22}
42 23
43int ehci_xls_probe_internal(const struct hc_driver *driver, 24int ehci_xls_probe_internal(const struct hc_driver *driver,
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 2694ed6558d2..85c3572155d1 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -175,10 +175,6 @@ struct ehci_hcd { /* one per controller */
175#ifdef DEBUG 175#ifdef DEBUG
176 struct dentry *debug_dir; 176 struct dentry *debug_dir;
177#endif 177#endif
178 /*
179 * OTG controllers and transceivers need software interaction
180 */
181 struct usb_phy *transceiver;
182}; 178};
183 179
184/* convert between an HCD pointer and the corresponding EHCI_HCD */ 180/* convert between an HCD pointer and the corresponding EHCI_HCD */
diff --git a/drivers/usb/host/fhci-dbg.c b/drivers/usb/host/fhci-dbg.c
index 6fe550049119..f238cb37305c 100644
--- a/drivers/usb/host/fhci-dbg.c
+++ b/drivers/usb/host/fhci-dbg.c
@@ -41,7 +41,7 @@ void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er)
41static int fhci_dfs_regs_show(struct seq_file *s, void *v) 41static int fhci_dfs_regs_show(struct seq_file *s, void *v)
42{ 42{
43 struct fhci_hcd *fhci = s->private; 43 struct fhci_hcd *fhci = s->private;
44 struct fhci_regs __iomem *regs = fhci->regs; 44 struct qe_usb_ctlr __iomem *regs = fhci->regs;
45 45
46 seq_printf(s, 46 seq_printf(s,
47 "mode: 0x%x\n" "addr: 0x%x\n" 47 "mode: 0x%x\n" "addr: 0x%x\n"
@@ -50,11 +50,11 @@ static int fhci_dfs_regs_show(struct seq_file *s, void *v)
50 "status: 0x%x\n" "SOF timer: %d\n" 50 "status: 0x%x\n" "SOF timer: %d\n"
51 "frame number: %d\n" 51 "frame number: %d\n"
52 "lines status: 0x%x\n", 52 "lines status: 0x%x\n",
53 in_8(&regs->usb_mod), in_8(&regs->usb_addr), 53 in_8(&regs->usb_usmod), in_8(&regs->usb_usadr),
54 in_8(&regs->usb_comm), in_be16(&regs->usb_ep[0]), 54 in_8(&regs->usb_uscom), in_be16(&regs->usb_usep[0]),
55 in_be16(&regs->usb_event), in_be16(&regs->usb_mask), 55 in_be16(&regs->usb_usber), in_be16(&regs->usb_usbmr),
56 in_8(&regs->usb_status), in_be16(&regs->usb_sof_tmr), 56 in_8(&regs->usb_usbs), in_be16(&regs->usb_ussft),
57 in_be16(&regs->usb_frame_num), 57 in_be16(&regs->usb_usfrn),
58 fhci_ioports_check_bus_state(fhci)); 58 fhci_ioports_check_bus_state(fhci));
59 59
60 return 0; 60 return 0;
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index d2623747b489..7da1a26bed2e 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -40,8 +40,8 @@ void fhci_start_sof_timer(struct fhci_hcd *fhci)
40 /* clear frame_n */ 40 /* clear frame_n */
41 out_be16(&fhci->pram->frame_num, 0); 41 out_be16(&fhci->pram->frame_num, 0);
42 42
43 out_be16(&fhci->regs->usb_sof_tmr, 0); 43 out_be16(&fhci->regs->usb_ussft, 0);
44 setbits8(&fhci->regs->usb_mod, USB_MODE_SFTE); 44 setbits8(&fhci->regs->usb_usmod, USB_MODE_SFTE);
45 45
46 fhci_dbg(fhci, "<- %s\n", __func__); 46 fhci_dbg(fhci, "<- %s\n", __func__);
47} 47}
@@ -50,7 +50,7 @@ void fhci_stop_sof_timer(struct fhci_hcd *fhci)
50{ 50{
51 fhci_dbg(fhci, "-> %s\n", __func__); 51 fhci_dbg(fhci, "-> %s\n", __func__);
52 52
53 clrbits8(&fhci->regs->usb_mod, USB_MODE_SFTE); 53 clrbits8(&fhci->regs->usb_usmod, USB_MODE_SFTE);
54 gtm_stop_timer16(fhci->timer); 54 gtm_stop_timer16(fhci->timer);
55 55
56 fhci_dbg(fhci, "<- %s\n", __func__); 56 fhci_dbg(fhci, "<- %s\n", __func__);
@@ -58,7 +58,7 @@ void fhci_stop_sof_timer(struct fhci_hcd *fhci)
58 58
59u16 fhci_get_sof_timer_count(struct fhci_usb *usb) 59u16 fhci_get_sof_timer_count(struct fhci_usb *usb)
60{ 60{
61 return be16_to_cpu(in_be16(&usb->fhci->regs->usb_sof_tmr) / 12); 61 return be16_to_cpu(in_be16(&usb->fhci->regs->usb_ussft) / 12);
62} 62}
63 63
64/* initialize the endpoint zero */ 64/* initialize the endpoint zero */
@@ -88,8 +88,8 @@ void fhci_usb_enable_interrupt(struct fhci_usb *usb)
88 enable_irq(fhci_to_hcd(fhci)->irq); 88 enable_irq(fhci_to_hcd(fhci)->irq);
89 89
90 /* initialize the event register and mask register */ 90 /* initialize the event register and mask register */
91 out_be16(&usb->fhci->regs->usb_event, 0xffff); 91 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
92 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 92 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
93 93
94 /* enable the timer interrupts */ 94 /* enable the timer interrupts */
95 enable_irq(fhci->timer->irq); 95 enable_irq(fhci->timer->irq);
@@ -109,7 +109,7 @@ void fhci_usb_disable_interrupt(struct fhci_usb *usb)
109 109
110 /* disable the usb interrupt */ 110 /* disable the usb interrupt */
111 disable_irq_nosync(fhci_to_hcd(fhci)->irq); 111 disable_irq_nosync(fhci_to_hcd(fhci)->irq);
112 out_be16(&usb->fhci->regs->usb_mask, 0); 112 out_be16(&usb->fhci->regs->usb_usbmr, 0);
113 } 113 }
114 usb->intr_nesting_cnt++; 114 usb->intr_nesting_cnt++;
115} 115}
@@ -119,9 +119,9 @@ static u32 fhci_usb_enable(struct fhci_hcd *fhci)
119{ 119{
120 struct fhci_usb *usb = fhci->usb_lld; 120 struct fhci_usb *usb = fhci->usb_lld;
121 121
122 out_be16(&usb->fhci->regs->usb_event, 0xffff); 122 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
123 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 123 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
124 setbits8(&usb->fhci->regs->usb_mod, USB_MODE_EN); 124 setbits8(&usb->fhci->regs->usb_usmod, USB_MODE_EN);
125 125
126 mdelay(100); 126 mdelay(100);
127 127
@@ -141,7 +141,7 @@ static u32 fhci_usb_disable(struct fhci_hcd *fhci)
141 usb->port_status == FHCI_PORT_LOW) 141 usb->port_status == FHCI_PORT_LOW)
142 fhci_device_disconnected_interrupt(fhci); 142 fhci_device_disconnected_interrupt(fhci);
143 143
144 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_EN); 144 clrbits8(&usb->fhci->regs->usb_usmod, USB_MODE_EN);
145 145
146 return 0; 146 return 0;
147} 147}
@@ -285,13 +285,13 @@ static int fhci_usb_init(struct fhci_hcd *fhci)
285 USB_E_IDLE_MASK | 285 USB_E_IDLE_MASK |
286 USB_E_RESET_MASK | USB_E_SFT_MASK | USB_E_MSF_MASK); 286 USB_E_RESET_MASK | USB_E_SFT_MASK | USB_E_MSF_MASK);
287 287
288 out_8(&usb->fhci->regs->usb_mod, USB_MODE_HOST | USB_MODE_EN); 288 out_8(&usb->fhci->regs->usb_usmod, USB_MODE_HOST | USB_MODE_EN);
289 289
290 /* clearing the mask register */ 290 /* clearing the mask register */
291 out_be16(&usb->fhci->regs->usb_mask, 0); 291 out_be16(&usb->fhci->regs->usb_usbmr, 0);
292 292
293 /* initialing the event register */ 293 /* initialing the event register */
294 out_be16(&usb->fhci->regs->usb_event, 0xffff); 294 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
295 295
296 if (endpoint_zero_init(usb, DEFAULT_DATA_MEM, DEFAULT_RING_LEN) != 0) { 296 if (endpoint_zero_init(usb, DEFAULT_DATA_MEM, DEFAULT_RING_LEN) != 0) {
297 fhci_usb_free(usb); 297 fhci_usb_free(usb);
@@ -745,8 +745,8 @@ static int __devinit of_fhci_probe(struct platform_device *ofdev)
745 } 745 }
746 746
747 /* Clear and disable any pending interrupts. */ 747 /* Clear and disable any pending interrupts. */
748 out_be16(&fhci->regs->usb_event, 0xffff); 748 out_be16(&fhci->regs->usb_usber, 0xffff);
749 out_be16(&fhci->regs->usb_mask, 0); 749 out_be16(&fhci->regs->usb_usbmr, 0);
750 750
751 ret = usb_add_hcd(hcd, usb_irq, 0); 751 ret = usb_add_hcd(hcd, usb_irq, 0);
752 if (ret < 0) 752 if (ret < 0)
diff --git a/drivers/usb/host/fhci-hub.c b/drivers/usb/host/fhci-hub.c
index 348fe62e94f7..6af2512f8378 100644
--- a/drivers/usb/host/fhci-hub.c
+++ b/drivers/usb/host/fhci-hub.c
@@ -97,7 +97,7 @@ void fhci_port_disable(struct fhci_hcd *fhci)
97 97
98 /* Enable IDLE since we want to know if something comes along */ 98 /* Enable IDLE since we want to know if something comes along */
99 usb->saved_msk |= USB_E_IDLE_MASK; 99 usb->saved_msk |= USB_E_IDLE_MASK;
100 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 100 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
101 101
102 /* check if during the disconnection process attached new device */ 102 /* check if during the disconnection process attached new device */
103 if (port_status == FHCI_PORT_WAITING) 103 if (port_status == FHCI_PORT_WAITING)
@@ -158,21 +158,21 @@ void fhci_port_reset(void *lld)
158 158
159 fhci_stop_sof_timer(fhci); 159 fhci_stop_sof_timer(fhci);
160 /* disable the USB controller */ 160 /* disable the USB controller */
161 mode = in_8(&fhci->regs->usb_mod); 161 mode = in_8(&fhci->regs->usb_usmod);
162 out_8(&fhci->regs->usb_mod, mode & (~USB_MODE_EN)); 162 out_8(&fhci->regs->usb_usmod, mode & (~USB_MODE_EN));
163 163
164 /* disable idle interrupts */ 164 /* disable idle interrupts */
165 mask = in_be16(&fhci->regs->usb_mask); 165 mask = in_be16(&fhci->regs->usb_usbmr);
166 out_be16(&fhci->regs->usb_mask, mask & (~USB_E_IDLE_MASK)); 166 out_be16(&fhci->regs->usb_usbmr, mask & (~USB_E_IDLE_MASK));
167 167
168 fhci_io_port_generate_reset(fhci); 168 fhci_io_port_generate_reset(fhci);
169 169
170 /* enable interrupt on this endpoint */ 170 /* enable interrupt on this endpoint */
171 out_be16(&fhci->regs->usb_mask, mask); 171 out_be16(&fhci->regs->usb_usbmr, mask);
172 172
173 /* enable the USB controller */ 173 /* enable the USB controller */
174 mode = in_8(&fhci->regs->usb_mod); 174 mode = in_8(&fhci->regs->usb_usmod);
175 out_8(&fhci->regs->usb_mod, mode | USB_MODE_EN); 175 out_8(&fhci->regs->usb_usmod, mode | USB_MODE_EN);
176 fhci_start_sof_timer(fhci); 176 fhci_start_sof_timer(fhci);
177 177
178 fhci_dbg(fhci, "<- %s\n", __func__); 178 fhci_dbg(fhci, "<- %s\n", __func__);
diff --git a/drivers/usb/host/fhci-sched.c b/drivers/usb/host/fhci-sched.c
index 2df851b4bc7c..2dc8a40e39d7 100644
--- a/drivers/usb/host/fhci-sched.c
+++ b/drivers/usb/host/fhci-sched.c
@@ -132,8 +132,8 @@ void fhci_flush_all_transmissions(struct fhci_usb *usb)
132 u8 mode; 132 u8 mode;
133 struct td *td; 133 struct td *td;
134 134
135 mode = in_8(&usb->fhci->regs->usb_mod); 135 mode = in_8(&usb->fhci->regs->usb_usmod);
136 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_EN); 136 clrbits8(&usb->fhci->regs->usb_usmod, USB_MODE_EN);
137 137
138 fhci_flush_bds(usb); 138 fhci_flush_bds(usb);
139 139
@@ -147,9 +147,9 @@ void fhci_flush_all_transmissions(struct fhci_usb *usb)
147 usb->actual_frame->frame_status = FRAME_END_TRANSMISSION; 147 usb->actual_frame->frame_status = FRAME_END_TRANSMISSION;
148 148
149 /* reset the event register */ 149 /* reset the event register */
150 out_be16(&usb->fhci->regs->usb_event, 0xffff); 150 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
151 /* enable the USB controller */ 151 /* enable the USB controller */
152 out_8(&usb->fhci->regs->usb_mod, mode | USB_MODE_EN); 152 out_8(&usb->fhci->regs->usb_usmod, mode | USB_MODE_EN);
153} 153}
154 154
155/* 155/*
@@ -414,7 +414,7 @@ static void sof_interrupt(struct fhci_hcd *fhci)
414 usb->port_status = FHCI_PORT_FULL; 414 usb->port_status = FHCI_PORT_FULL;
415 /* Disable IDLE */ 415 /* Disable IDLE */
416 usb->saved_msk &= ~USB_E_IDLE_MASK; 416 usb->saved_msk &= ~USB_E_IDLE_MASK;
417 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 417 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
418 } 418 }
419 419
420 gtm_set_exact_timer16(fhci->timer, usb->max_frame_usage, false); 420 gtm_set_exact_timer16(fhci->timer, usb->max_frame_usage, false);
@@ -433,14 +433,14 @@ void fhci_device_disconnected_interrupt(struct fhci_hcd *fhci)
433 fhci_dbg(fhci, "-> %s\n", __func__); 433 fhci_dbg(fhci, "-> %s\n", __func__);
434 434
435 fhci_usb_disable_interrupt(usb); 435 fhci_usb_disable_interrupt(usb);
436 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_LSS); 436 clrbits8(&usb->fhci->regs->usb_usmod, USB_MODE_LSS);
437 usb->port_status = FHCI_PORT_DISABLED; 437 usb->port_status = FHCI_PORT_DISABLED;
438 438
439 fhci_stop_sof_timer(fhci); 439 fhci_stop_sof_timer(fhci);
440 440
441 /* Enable IDLE since we want to know if something comes along */ 441 /* Enable IDLE since we want to know if something comes along */
442 usb->saved_msk |= USB_E_IDLE_MASK; 442 usb->saved_msk |= USB_E_IDLE_MASK;
443 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 443 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
444 444
445 usb->vroot_hub->port.wPortStatus &= ~USB_PORT_STAT_CONNECTION; 445 usb->vroot_hub->port.wPortStatus &= ~USB_PORT_STAT_CONNECTION;
446 usb->vroot_hub->port.wPortChange |= USB_PORT_STAT_C_CONNECTION; 446 usb->vroot_hub->port.wPortChange |= USB_PORT_STAT_C_CONNECTION;
@@ -473,7 +473,7 @@ void fhci_device_connected_interrupt(struct fhci_hcd *fhci)
473 } 473 }
474 474
475 usb->port_status = FHCI_PORT_LOW; 475 usb->port_status = FHCI_PORT_LOW;
476 setbits8(&usb->fhci->regs->usb_mod, USB_MODE_LSS); 476 setbits8(&usb->fhci->regs->usb_usmod, USB_MODE_LSS);
477 usb->vroot_hub->port.wPortStatus |= 477 usb->vroot_hub->port.wPortStatus |=
478 (USB_PORT_STAT_LOW_SPEED | 478 (USB_PORT_STAT_LOW_SPEED |
479 USB_PORT_STAT_CONNECTION); 479 USB_PORT_STAT_CONNECTION);
@@ -491,7 +491,7 @@ void fhci_device_connected_interrupt(struct fhci_hcd *fhci)
491 } 491 }
492 492
493 usb->port_status = FHCI_PORT_FULL; 493 usb->port_status = FHCI_PORT_FULL;
494 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_LSS); 494 clrbits8(&usb->fhci->regs->usb_usmod, USB_MODE_LSS);
495 usb->vroot_hub->port.wPortStatus &= 495 usb->vroot_hub->port.wPortStatus &=
496 ~USB_PORT_STAT_LOW_SPEED; 496 ~USB_PORT_STAT_LOW_SPEED;
497 usb->vroot_hub->port.wPortStatus |= 497 usb->vroot_hub->port.wPortStatus |=
@@ -535,7 +535,7 @@ static void abort_transmission(struct fhci_usb *usb)
535 /* issue stop Tx command */ 535 /* issue stop Tx command */
536 qe_issue_cmd(QE_USB_STOP_TX, QE_CR_SUBBLOCK_USB, EP_ZERO, 0); 536 qe_issue_cmd(QE_USB_STOP_TX, QE_CR_SUBBLOCK_USB, EP_ZERO, 0);
537 /* flush Tx FIFOs */ 537 /* flush Tx FIFOs */
538 out_8(&usb->fhci->regs->usb_comm, USB_CMD_FLUSH_FIFO | EP_ZERO); 538 out_8(&usb->fhci->regs->usb_uscom, USB_CMD_FLUSH_FIFO | EP_ZERO);
539 udelay(1000); 539 udelay(1000);
540 /* reset Tx BDs */ 540 /* reset Tx BDs */
541 fhci_flush_bds(usb); 541 fhci_flush_bds(usb);
@@ -555,11 +555,11 @@ irqreturn_t fhci_irq(struct usb_hcd *hcd)
555 555
556 usb = fhci->usb_lld; 556 usb = fhci->usb_lld;
557 557
558 usb_er |= in_be16(&usb->fhci->regs->usb_event) & 558 usb_er |= in_be16(&usb->fhci->regs->usb_usber) &
559 in_be16(&usb->fhci->regs->usb_mask); 559 in_be16(&usb->fhci->regs->usb_usbmr);
560 560
561 /* clear event bits for next time */ 561 /* clear event bits for next time */
562 out_be16(&usb->fhci->regs->usb_event, usb_er); 562 out_be16(&usb->fhci->regs->usb_usber, usb_er);
563 563
564 fhci_dbg_isr(fhci, usb_er); 564 fhci_dbg_isr(fhci, usb_er);
565 565
@@ -573,7 +573,7 @@ irqreturn_t fhci_irq(struct usb_hcd *hcd)
573 573
574 /* Turn on IDLE since we want to disconnect */ 574 /* Turn on IDLE since we want to disconnect */
575 usb->saved_msk |= USB_E_IDLE_MASK; 575 usb->saved_msk |= USB_E_IDLE_MASK;
576 out_be16(&usb->fhci->regs->usb_event, 576 out_be16(&usb->fhci->regs->usb_usber,
577 usb->saved_msk); 577 usb->saved_msk);
578 } else if (usb->port_status == FHCI_PORT_DISABLED) { 578 } else if (usb->port_status == FHCI_PORT_DISABLED) {
579 if (fhci_ioports_check_bus_state(fhci) == 1) 579 if (fhci_ioports_check_bus_state(fhci) == 1)
@@ -611,7 +611,7 @@ irqreturn_t fhci_irq(struct usb_hcd *hcd)
611 /* XXX usb->port_status = FHCI_PORT_WAITING; */ 611 /* XXX usb->port_status = FHCI_PORT_WAITING; */
612 /* Disable IDLE */ 612 /* Disable IDLE */
613 usb->saved_msk &= ~USB_E_IDLE_MASK; 613 usb->saved_msk &= ~USB_E_IDLE_MASK;
614 out_be16(&usb->fhci->regs->usb_mask, 614 out_be16(&usb->fhci->regs->usb_usbmr,
615 usb->saved_msk); 615 usb->saved_msk);
616 } else { 616 } else {
617 fhci_dbg_isr(fhci, -1); 617 fhci_dbg_isr(fhci, -1);
diff --git a/drivers/usb/host/fhci-tds.c b/drivers/usb/host/fhci-tds.c
index c5ed88199292..1498061f0aea 100644
--- a/drivers/usb/host/fhci-tds.c
+++ b/drivers/usb/host/fhci-tds.c
@@ -249,7 +249,7 @@ void fhci_init_ep_registers(struct fhci_usb *usb, struct endpoint *ep,
249 u8 rt; 249 u8 rt;
250 250
251 /* set the endpoint registers according to the endpoint */ 251 /* set the endpoint registers according to the endpoint */
252 out_be16(&usb->fhci->regs->usb_ep[0], 252 out_be16(&usb->fhci->regs->usb_usep[0],
253 USB_TRANS_CTR | USB_EP_MF | USB_EP_RTE); 253 USB_TRANS_CTR | USB_EP_MF | USB_EP_RTE);
254 out_be16(&usb->fhci->pram->ep_ptr[0], 254 out_be16(&usb->fhci->pram->ep_ptr[0],
255 cpm_muram_offset(ep->ep_pram_ptr)); 255 cpm_muram_offset(ep->ep_pram_ptr));
@@ -463,7 +463,7 @@ u32 fhci_host_transaction(struct fhci_usb *usb,
463 cq_put(&ep->conf_frame_Q, pkt); 463 cq_put(&ep->conf_frame_Q, pkt);
464 464
465 if (cq_howmany(&ep->conf_frame_Q) == 1) 465 if (cq_howmany(&ep->conf_frame_Q) == 1)
466 out_8(&usb->fhci->regs->usb_comm, USB_CMD_STR_FIFO); 466 out_8(&usb->fhci->regs->usb_uscom, USB_CMD_STR_FIFO);
467 467
468 return 0; 468 return 0;
469} 469}
@@ -535,8 +535,8 @@ void fhci_flush_actual_frame(struct fhci_usb *usb)
535 struct endpoint *ep = usb->ep0; 535 struct endpoint *ep = usb->ep0;
536 536
537 /* disable the USB controller */ 537 /* disable the USB controller */
538 mode = in_8(&usb->fhci->regs->usb_mod); 538 mode = in_8(&usb->fhci->regs->usb_usmod);
539 out_8(&usb->fhci->regs->usb_mod, mode & ~USB_MODE_EN); 539 out_8(&usb->fhci->regs->usb_usmod, mode & ~USB_MODE_EN);
540 540
541 tb_ptr = in_be16(&ep->ep_pram_ptr->tx_bd_ptr); 541 tb_ptr = in_be16(&ep->ep_pram_ptr->tx_bd_ptr);
542 td = cpm_muram_addr(tb_ptr); 542 td = cpm_muram_addr(tb_ptr);
@@ -571,9 +571,9 @@ void fhci_flush_actual_frame(struct fhci_usb *usb)
571 usb->actual_frame->frame_status = FRAME_TIMER_END_TRANSMISSION; 571 usb->actual_frame->frame_status = FRAME_TIMER_END_TRANSMISSION;
572 572
573 /* reset the event register */ 573 /* reset the event register */
574 out_be16(&usb->fhci->regs->usb_event, 0xffff); 574 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
575 /* enable the USB controller */ 575 /* enable the USB controller */
576 out_8(&usb->fhci->regs->usb_mod, mode | USB_MODE_EN); 576 out_8(&usb->fhci->regs->usb_usmod, mode | USB_MODE_EN);
577} 577}
578 578
579/* handles Tx confirm and Tx error interrupt */ 579/* handles Tx confirm and Tx error interrupt */
@@ -613,7 +613,7 @@ void fhci_host_transmit_actual_frame(struct fhci_usb *usb)
613 613
614 /* start transmit only if we have something in the TDs */ 614 /* start transmit only if we have something in the TDs */
615 if (in_be16(&td->status) & TD_R) 615 if (in_be16(&td->status) & TD_R)
616 out_8(&usb->fhci->regs->usb_comm, USB_CMD_STR_FIFO); 616 out_8(&usb->fhci->regs->usb_uscom, USB_CMD_STR_FIFO);
617 617
618 if (in_be32(&ep->conf_td->buf_ptr) == DUMMY_BD_BUFFER) { 618 if (in_be32(&ep->conf_td->buf_ptr) == DUMMY_BD_BUFFER) {
619 out_be32(&old_td->buf_ptr, 0); 619 out_be32(&old_td->buf_ptr, 0);
diff --git a/drivers/usb/host/fhci.h b/drivers/usb/host/fhci.h
index dc6939a44a1a..7cc1c32dc36c 100644
--- a/drivers/usb/host/fhci.h
+++ b/drivers/usb/host/fhci.h
@@ -28,6 +28,7 @@
28#include <linux/usb.h> 28#include <linux/usb.h>
29#include <linux/usb/hcd.h> 29#include <linux/usb/hcd.h>
30#include <asm/qe.h> 30#include <asm/qe.h>
31#include <asm/immap_qe.h>
31 32
32#define USB_CLOCK 48000000 33#define USB_CLOCK 48000000
33 34
@@ -173,25 +174,6 @@
173#define USB_E_TXB_MASK 0x0002 174#define USB_E_TXB_MASK 0x0002
174#define USB_E_RXB_MASK 0x0001 175#define USB_E_RXB_MASK 0x0001
175 176
176/* Freescale USB Host controller registers */
177struct fhci_regs {
178 u8 usb_mod; /* mode register */
179 u8 usb_addr; /* address register */
180 u8 usb_comm; /* command register */
181 u8 reserved1[1];
182 __be16 usb_ep[4]; /* endpoint register */
183 u8 reserved2[4];
184 __be16 usb_event; /* event register */
185 u8 reserved3[2];
186 __be16 usb_mask; /* mask register */
187 u8 reserved4[1];
188 u8 usb_status; /* status register */
189 __be16 usb_sof_tmr; /* Start Of Frame timer */
190 u8 reserved5[2];
191 __be16 usb_frame_num; /* frame number register */
192 u8 reserved6[1];
193};
194
195/* Freescale USB HOST */ 177/* Freescale USB HOST */
196struct fhci_pram { 178struct fhci_pram {
197 __be16 ep_ptr[4]; /* Endpoint porter reg */ 179 __be16 ep_ptr[4]; /* Endpoint porter reg */
@@ -267,7 +249,7 @@ struct fhci_hcd {
267 int gpios[NUM_GPIOS]; 249 int gpios[NUM_GPIOS];
268 bool alow_gpios[NUM_GPIOS]; 250 bool alow_gpios[NUM_GPIOS];
269 251
270 struct fhci_regs __iomem *regs; /* I/O memory used to communicate */ 252 struct qe_usb_ctlr __iomem *regs; /* I/O memory used to communicate */
271 struct fhci_pram __iomem *pram; /* Parameter RAM */ 253 struct fhci_pram __iomem *pram; /* Parameter RAM */
272 struct gtm_timer *timer; 254 struct gtm_timer *timer;
273 255
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index ff471c1c165e..f19e2690c232 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -1811,7 +1811,7 @@ static int imx21_remove(struct platform_device *pdev)
1811 usb_remove_hcd(hcd); 1811 usb_remove_hcd(hcd);
1812 1812
1813 if (res != NULL) { 1813 if (res != NULL) {
1814 clk_disable(imx21->clk); 1814 clk_disable_unprepare(imx21->clk);
1815 clk_put(imx21->clk); 1815 clk_put(imx21->clk);
1816 iounmap(imx21->regs); 1816 iounmap(imx21->regs);
1817 release_mem_region(res->start, resource_size(res)); 1817 release_mem_region(res->start, resource_size(res));
@@ -1884,7 +1884,7 @@ static int imx21_probe(struct platform_device *pdev)
1884 ret = clk_set_rate(imx21->clk, clk_round_rate(imx21->clk, 48000000)); 1884 ret = clk_set_rate(imx21->clk, clk_round_rate(imx21->clk, 48000000));
1885 if (ret) 1885 if (ret)
1886 goto failed_clock_set; 1886 goto failed_clock_set;
1887 ret = clk_enable(imx21->clk); 1887 ret = clk_prepare_enable(imx21->clk);
1888 if (ret) 1888 if (ret)
1889 goto failed_clock_enable; 1889 goto failed_clock_enable;
1890 1890
@@ -1900,7 +1900,7 @@ static int imx21_probe(struct platform_device *pdev)
1900 return 0; 1900 return 0;
1901 1901
1902failed_add_hcd: 1902failed_add_hcd:
1903 clk_disable(imx21->clk); 1903 clk_disable_unprepare(imx21->clk);
1904failed_clock_enable: 1904failed_clock_enable:
1905failed_clock_set: 1905failed_clock_set:
1906 clk_put(imx21->clk); 1906 clk_put(imx21->clk);
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index 2909621ea196..8bcbdb5ade2d 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -87,7 +87,8 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
87 return -EINVAL; 87 return -EINVAL;
88 } 88 }
89 89
90 exynos_ohci = kzalloc(sizeof(struct exynos_ohci_hcd), GFP_KERNEL); 90 exynos_ohci = devm_kzalloc(&pdev->dev, sizeof(struct exynos_ohci_hcd),
91 GFP_KERNEL);
91 if (!exynos_ohci) 92 if (!exynos_ohci)
92 return -ENOMEM; 93 return -ENOMEM;
93 94
@@ -97,8 +98,7 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
97 dev_name(&pdev->dev)); 98 dev_name(&pdev->dev));
98 if (!hcd) { 99 if (!hcd) {
99 dev_err(&pdev->dev, "Unable to create HCD\n"); 100 dev_err(&pdev->dev, "Unable to create HCD\n");
100 err = -ENOMEM; 101 return -ENOMEM;
101 goto fail_hcd;
102 } 102 }
103 103
104 exynos_ohci->hcd = hcd; 104 exynos_ohci->hcd = hcd;
@@ -123,7 +123,7 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
123 123
124 hcd->rsrc_start = res->start; 124 hcd->rsrc_start = res->start;
125 hcd->rsrc_len = resource_size(res); 125 hcd->rsrc_len = resource_size(res);
126 hcd->regs = ioremap(res->start, resource_size(res)); 126 hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
127 if (!hcd->regs) { 127 if (!hcd->regs) {
128 dev_err(&pdev->dev, "Failed to remap I/O memory\n"); 128 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
129 err = -ENOMEM; 129 err = -ENOMEM;
@@ -134,7 +134,7 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
134 if (!irq) { 134 if (!irq) {
135 dev_err(&pdev->dev, "Failed to get IRQ\n"); 135 dev_err(&pdev->dev, "Failed to get IRQ\n");
136 err = -ENODEV; 136 err = -ENODEV;
137 goto fail; 137 goto fail_io;
138 } 138 }
139 139
140 if (pdata->phy_init) 140 if (pdata->phy_init)
@@ -146,23 +146,19 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
146 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 146 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
147 if (err) { 147 if (err) {
148 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 148 dev_err(&pdev->dev, "Failed to add USB HCD\n");
149 goto fail; 149 goto fail_io;
150 } 150 }
151 151
152 platform_set_drvdata(pdev, exynos_ohci); 152 platform_set_drvdata(pdev, exynos_ohci);
153 153
154 return 0; 154 return 0;
155 155
156fail:
157 iounmap(hcd->regs);
158fail_io: 156fail_io:
159 clk_disable(exynos_ohci->clk); 157 clk_disable(exynos_ohci->clk);
160fail_clken: 158fail_clken:
161 clk_put(exynos_ohci->clk); 159 clk_put(exynos_ohci->clk);
162fail_clk: 160fail_clk:
163 usb_put_hcd(hcd); 161 usb_put_hcd(hcd);
164fail_hcd:
165 kfree(exynos_ohci);
166 return err; 162 return err;
167} 163}
168 164
@@ -177,13 +173,10 @@ static int __devexit exynos_ohci_remove(struct platform_device *pdev)
177 if (pdata && pdata->phy_exit) 173 if (pdata && pdata->phy_exit)
178 pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 174 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
179 175
180 iounmap(hcd->regs);
181
182 clk_disable(exynos_ohci->clk); 176 clk_disable(exynos_ohci->clk);
183 clk_put(exynos_ohci->clk); 177 clk_put(exynos_ohci->clk);
184 178
185 usb_put_hcd(hcd); 179 usb_put_hcd(hcd);
186 kfree(exynos_ohci);
187 180
188 return 0; 181 return 0;
189} 182}
@@ -225,6 +218,9 @@ static int exynos_ohci_suspend(struct device *dev)
225 218
226 if (pdata && pdata->phy_exit) 219 if (pdata && pdata->phy_exit)
227 pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 220 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
221
222 clk_disable(exynos_ohci->clk);
223
228fail: 224fail:
229 spin_unlock_irqrestore(&ohci->lock, flags); 225 spin_unlock_irqrestore(&ohci->lock, flags);
230 226
@@ -238,6 +234,8 @@ static int exynos_ohci_resume(struct device *dev)
238 struct platform_device *pdev = to_platform_device(dev); 234 struct platform_device *pdev = to_platform_device(dev);
239 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data; 235 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
240 236
237 clk_enable(exynos_ohci->clk);
238
241 if (pdata && pdata->phy_init) 239 if (pdata && pdata->phy_init)
242 pdata->phy_init(pdev, S5P_USB_PHY_HOST); 240 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
243 241
diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c
index 1e364ec962fb..a446386bf779 100644
--- a/drivers/usb/host/ohci-nxp.c
+++ b/drivers/usb/host/ohci-nxp.c
@@ -43,16 +43,6 @@
43#define USB_HOST_NEED_CLK_EN (1 << 21) 43#define USB_HOST_NEED_CLK_EN (1 << 21)
44#define PAD_CONTROL_LAST_DRIVEN (1 << 19) 44#define PAD_CONTROL_LAST_DRIVEN (1 << 19)
45 45
46#define USB_OTG_CLK_CTRL IO_ADDRESS(USB_CONFIG_BASE + 0xFF4)
47#define USB_OTG_CLK_STAT IO_ADDRESS(USB_CONFIG_BASE + 0xFF8)
48
49/* USB_OTG_CLK_CTRL bit defines */
50#define AHB_M_CLOCK_ON (1 << 4)
51#define OTG_CLOCK_ON (1 << 3)
52#define I2C_CLOCK_ON (1 << 2)
53#define DEV_CLOCK_ON (1 << 1)
54#define HOST_CLOCK_ON (1 << 0)
55
56#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110) 46#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
57 47
58/* USB_OTG_STAT_CONTROL bit defines */ 48/* USB_OTG_STAT_CONTROL bit defines */
@@ -72,7 +62,9 @@ static struct i2c_client *isp1301_i2c_client;
72 62
73extern int usb_disabled(void); 63extern int usb_disabled(void);
74 64
75static struct clk *usb_clk; 65static struct clk *usb_pll_clk;
66static struct clk *usb_dev_clk;
67static struct clk *usb_otg_clk;
76 68
77static void isp1301_configure_pnx4008(void) 69static void isp1301_configure_pnx4008(void)
78{ 70{
@@ -249,8 +241,6 @@ static const struct hc_driver ohci_nxp_hc_driver = {
249 .start_port_reset = ohci_start_port_reset, 241 .start_port_reset = ohci_start_port_reset,
250}; 242};
251 243
252#define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON)
253
254static void nxp_set_usb_bits(void) 244static void nxp_set_usb_bits(void)
255{ 245{
256 if (machine_is_pnx4008()) { 246 if (machine_is_pnx4008()) {
@@ -327,41 +317,63 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
327 /* Enable AHB slave USB clock, needed for further USB clock control */ 317 /* Enable AHB slave USB clock, needed for further USB clock control */
328 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL); 318 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
329 319
330 isp1301_configure();
331
332 /* Enable USB PLL */ 320 /* Enable USB PLL */
333 usb_clk = clk_get(&pdev->dev, "ck_pll5"); 321 usb_pll_clk = clk_get(&pdev->dev, "ck_pll5");
334 if (IS_ERR(usb_clk)) { 322 if (IS_ERR(usb_pll_clk)) {
335 dev_err(&pdev->dev, "failed to acquire USB PLL\n"); 323 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
336 ret = PTR_ERR(usb_clk); 324 ret = PTR_ERR(usb_pll_clk);
337 goto out1; 325 goto out1;
338 } 326 }
339 327
340 ret = clk_enable(usb_clk); 328 ret = clk_enable(usb_pll_clk);
341 if (ret < 0) { 329 if (ret < 0) {
342 dev_err(&pdev->dev, "failed to start USB PLL\n"); 330 dev_err(&pdev->dev, "failed to start USB PLL\n");
343 goto out2; 331 goto out2;
344 } 332 }
345 333
346 ret = clk_set_rate(usb_clk, 48000); 334 ret = clk_set_rate(usb_pll_clk, 48000);
347 if (ret < 0) { 335 if (ret < 0) {
348 dev_err(&pdev->dev, "failed to set USB clock rate\n"); 336 dev_err(&pdev->dev, "failed to set USB clock rate\n");
349 goto out3; 337 goto out3;
350 } 338 }
351 339
340 /* Enable USB device clock */
341 usb_dev_clk = clk_get(&pdev->dev, "ck_usbd");
342 if (IS_ERR(usb_dev_clk)) {
343 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
344 ret = PTR_ERR(usb_dev_clk);
345 goto out4;
346 }
347
348 ret = clk_enable(usb_dev_clk);
349 if (ret < 0) {
350 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
351 goto out5;
352 }
353
354 /* Enable USB otg clocks */
355 usb_otg_clk = clk_get(&pdev->dev, "ck_usb_otg");
356 if (IS_ERR(usb_otg_clk)) {
357 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
358 ret = PTR_ERR(usb_dev_clk);
359 goto out6;
360 }
361
352 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL); 362 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
353 363
354 /* Set to enable all needed USB clocks */ 364 ret = clk_enable(usb_otg_clk);
355 __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL); 365 if (ret < 0) {
366 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
367 goto out7;
368 }
356 369
357 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) != 370 isp1301_configure();
358 USB_CLOCK_MASK) ;
359 371
360 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); 372 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
361 if (!hcd) { 373 if (!hcd) {
362 dev_err(&pdev->dev, "Failed to allocate HC buffer\n"); 374 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
363 ret = -ENOMEM; 375 ret = -ENOMEM;
364 goto out3; 376 goto out8;
365 } 377 }
366 378
367 /* Set all USB bits in the Start Enable register */ 379 /* Set all USB bits in the Start Enable register */
@@ -371,14 +383,14 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
371 if (!res) { 383 if (!res) {
372 dev_err(&pdev->dev, "Failed to get MEM resource\n"); 384 dev_err(&pdev->dev, "Failed to get MEM resource\n");
373 ret = -ENOMEM; 385 ret = -ENOMEM;
374 goto out4; 386 goto out8;
375 } 387 }
376 388
377 hcd->regs = devm_request_and_ioremap(&pdev->dev, res); 389 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
378 if (!hcd->regs) { 390 if (!hcd->regs) {
379 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n"); 391 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n");
380 ret = -ENOMEM; 392 ret = -ENOMEM;
381 goto out4; 393 goto out8;
382 } 394 }
383 hcd->rsrc_start = res->start; 395 hcd->rsrc_start = res->start;
384 hcd->rsrc_len = resource_size(res); 396 hcd->rsrc_len = resource_size(res);
@@ -386,7 +398,7 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
386 irq = platform_get_irq(pdev, 0); 398 irq = platform_get_irq(pdev, 0);
387 if (irq < 0) { 399 if (irq < 0) {
388 ret = -ENXIO; 400 ret = -ENXIO;
389 goto out4; 401 goto out8;
390 } 402 }
391 403
392 nxp_start_hc(); 404 nxp_start_hc();
@@ -400,13 +412,21 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
400 return ret; 412 return ret;
401 413
402 nxp_stop_hc(); 414 nxp_stop_hc();
403out4: 415out8:
404 nxp_unset_usb_bits(); 416 nxp_unset_usb_bits();
405 usb_put_hcd(hcd); 417 usb_put_hcd(hcd);
418out7:
419 clk_disable(usb_otg_clk);
420out6:
421 clk_put(usb_otg_clk);
422out5:
423 clk_disable(usb_dev_clk);
424out4:
425 clk_put(usb_dev_clk);
406out3: 426out3:
407 clk_disable(usb_clk); 427 clk_disable(usb_pll_clk);
408out2: 428out2:
409 clk_put(usb_clk); 429 clk_put(usb_pll_clk);
410out1: 430out1:
411 isp1301_i2c_client = NULL; 431 isp1301_i2c_client = NULL;
412out: 432out:
@@ -422,8 +442,10 @@ static int usb_hcd_nxp_remove(struct platform_device *pdev)
422 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 442 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
423 usb_put_hcd(hcd); 443 usb_put_hcd(hcd);
424 nxp_unset_usb_bits(); 444 nxp_unset_usb_bits();
425 clk_disable(usb_clk); 445 clk_disable(usb_pll_clk);
426 clk_put(usb_clk); 446 clk_put(usb_pll_clk);
447 clk_disable(usb_dev_clk);
448 clk_put(usb_dev_clk);
427 i2c_unregister_device(isp1301_i2c_client); 449 i2c_unregister_device(isp1301_i2c_client);
428 isp1301_i2c_client = NULL; 450 isp1301_i2c_client = NULL;
429 451
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 9ce35d0d9d5d..076d2018e6df 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -18,6 +18,7 @@
18#include <linux/jiffies.h> 18#include <linux/jiffies.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/clk.h> 20#include <linux/clk.h>
21#include <linux/err.h>
21#include <linux/gpio.h> 22#include <linux/gpio.h>
22 23
23#include <mach/hardware.h> 24#include <mach/hardware.h>
@@ -167,14 +168,15 @@ static int omap_1510_local_bus_init(void)
167 168
168static void start_hnp(struct ohci_hcd *ohci) 169static void start_hnp(struct ohci_hcd *ohci)
169{ 170{
170 const unsigned port = ohci_to_hcd(ohci)->self.otg_port - 1; 171 struct usb_hcd *hcd = ohci_to_hcd(ohci);
172 const unsigned port = hcd->self.otg_port - 1;
171 unsigned long flags; 173 unsigned long flags;
172 u32 l; 174 u32 l;
173 175
174 otg_start_hnp(ohci->transceiver->otg); 176 otg_start_hnp(hcd->phy->otg);
175 177
176 local_irq_save(flags); 178 local_irq_save(flags);
177 ohci->transceiver->state = OTG_STATE_A_SUSPEND; 179 hcd->phy->state = OTG_STATE_A_SUSPEND;
178 writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]); 180 writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]);
179 l = omap_readl(OTG_CTRL); 181 l = omap_readl(OTG_CTRL);
180 l &= ~OTG_A_BUSREQ; 182 l &= ~OTG_A_BUSREQ;
@@ -211,18 +213,18 @@ static int ohci_omap_init(struct usb_hcd *hcd)
211 213
212#ifdef CONFIG_USB_OTG 214#ifdef CONFIG_USB_OTG
213 if (need_transceiver) { 215 if (need_transceiver) {
214 ohci->transceiver = usb_get_transceiver(); 216 hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2);
215 if (ohci->transceiver) { 217 if (!IS_ERR_OR_NULL(hcd->phy)) {
216 int status = otg_set_host(ohci->transceiver->otg, 218 int status = otg_set_host(hcd->phy->otg,
217 &ohci_to_hcd(ohci)->self); 219 &ohci_to_hcd(ohci)->self);
218 dev_dbg(hcd->self.controller, "init %s transceiver, status %d\n", 220 dev_dbg(hcd->self.controller, "init %s phy, status %d\n",
219 ohci->transceiver->label, status); 221 hcd->phy->label, status);
220 if (status) { 222 if (status) {
221 usb_put_transceiver(ohci->transceiver); 223 usb_put_phy(hcd->phy);
222 return status; 224 return status;
223 } 225 }
224 } else { 226 } else {
225 dev_err(hcd->self.controller, "can't find transceiver\n"); 227 dev_err(hcd->self.controller, "can't find phy\n");
226 return -ENODEV; 228 return -ENODEV;
227 } 229 }
228 ohci->start_hnp = start_hnp; 230 ohci->start_hnp = start_hnp;
@@ -403,9 +405,9 @@ usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
403 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 405 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
404 406
405 usb_remove_hcd(hcd); 407 usb_remove_hcd(hcd);
406 if (ohci->transceiver) { 408 if (!IS_ERR_OR_NULL(hcd->phy)) {
407 (void) otg_set_host(ohci->transceiver->otg, 0); 409 (void) otg_set_host(hcd->phy->otg, 0);
408 usb_put_transceiver(ohci->transceiver); 410 usb_put_phy(hcd->phy);
409 } 411 }
410 if (machine_is_omap_osk()) 412 if (machine_is_omap_osk())
411 gpio_free(9); 413 gpio_free(9);
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 1b19aea25a2b..d3299143d9e2 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -372,11 +372,6 @@ struct ohci_hcd {
372 struct ed *ed_controltail; /* last in ctrl list */ 372 struct ed *ed_controltail; /* last in ctrl list */
373 struct ed *periodic [NUM_INTS]; /* shadow int_table */ 373 struct ed *periodic [NUM_INTS]; /* shadow int_table */
374 374
375 /*
376 * OTG controllers and transceivers need software interaction;
377 * other external transceivers should be software-transparent
378 */
379 struct usb_phy *transceiver;
380 void (*start_hnp)(struct ohci_hcd *ohci); 375 void (*start_hnp)(struct ohci_hcd *ohci);
381 376
382 /* 377 /*
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index a979cd0dbe0f..7648b2d4b268 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4450,6 +4450,8 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4450 4450
4451 /* Accept arbitrarily long scatter-gather lists */ 4451 /* Accept arbitrarily long scatter-gather lists */
4452 hcd->self.sg_tablesize = ~0; 4452 hcd->self.sg_tablesize = ~0;
4453 /* XHCI controllers don't stop the ep queue on short packets :| */
4454 hcd->self.no_stop_on_short = 1;
4453 4455
4454 if (usb_hcd_is_primary_hcd(hcd)) { 4456 if (usb_hcd_is_primary_hcd(hcd)) {
4455 xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL); 4457 xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL);
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 9f3eda91ea4d..7a95ab87ac00 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -29,6 +29,7 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/clk.h> 31#include <linux/clk.h>
32#include <linux/err.h>
32#include <linux/io.h> 33#include <linux/io.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
34#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
@@ -364,8 +365,8 @@ static int am35x_musb_init(struct musb *musb)
364 return -ENODEV; 365 return -ENODEV;
365 366
366 usb_nop_xceiv_register(); 367 usb_nop_xceiv_register();
367 musb->xceiv = usb_get_transceiver(); 368 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
368 if (!musb->xceiv) 369 if (IS_ERR_OR_NULL(musb->xceiv))
369 return -ENODEV; 370 return -ENODEV;
370 371
371 if (is_host_enabled(musb)) 372 if (is_host_enabled(musb))
@@ -406,7 +407,7 @@ static int am35x_musb_exit(struct musb *musb)
406 if (data->set_phy_power) 407 if (data->set_phy_power)
407 data->set_phy_power(0); 408 data->set_phy_power(0);
408 409
409 usb_put_transceiver(musb->xceiv); 410 usb_put_phy(musb->xceiv);
410 usb_nop_xceiv_unregister(); 411 usb_nop_xceiv_unregister();
411 412
412 return 0; 413 return 0;
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index a087ed6c3be9..428e6aa3e78a 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -15,6 +15,7 @@
15#include <linux/list.h> 15#include <linux/list.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/err.h>
18#include <linux/platform_device.h> 19#include <linux/platform_device.h>
19#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
20#include <linux/prefetch.h> 21#include <linux/prefetch.h>
@@ -415,8 +416,8 @@ static int bfin_musb_init(struct musb *musb)
415 gpio_direction_output(musb->config->gpio_vrsel, 0); 416 gpio_direction_output(musb->config->gpio_vrsel, 0);
416 417
417 usb_nop_xceiv_register(); 418 usb_nop_xceiv_register();
418 musb->xceiv = usb_get_transceiver(); 419 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
419 if (!musb->xceiv) { 420 if (IS_ERR_OR_NULL(musb->xceiv)) {
420 gpio_free(musb->config->gpio_vrsel); 421 gpio_free(musb->config->gpio_vrsel);
421 return -ENODEV; 422 return -ENODEV;
422 } 423 }
@@ -440,7 +441,7 @@ static int bfin_musb_exit(struct musb *musb)
440{ 441{
441 gpio_free(musb->config->gpio_vrsel); 442 gpio_free(musb->config->gpio_vrsel);
442 443
443 usb_put_transceiver(musb->xceiv); 444 usb_put_phy(musb->xceiv);
444 usb_nop_xceiv_unregister(); 445 usb_nop_xceiv_unregister();
445 return 0; 446 return 0;
446} 447}
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 8bd9566f3fbb..0f9fcec4e1d3 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -29,6 +29,7 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/clk.h> 31#include <linux/clk.h>
32#include <linux/err.h>
32#include <linux/io.h> 33#include <linux/io.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
34#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
@@ -425,8 +426,8 @@ static int da8xx_musb_init(struct musb *musb)
425 goto fail; 426 goto fail;
426 427
427 usb_nop_xceiv_register(); 428 usb_nop_xceiv_register();
428 musb->xceiv = usb_get_transceiver(); 429 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
429 if (!musb->xceiv) 430 if (IS_ERR_OR_NULL(musb->xceiv))
430 goto fail; 431 goto fail;
431 432
432 if (is_host_enabled(musb)) 433 if (is_host_enabled(musb))
@@ -458,7 +459,7 @@ static int da8xx_musb_exit(struct musb *musb)
458 459
459 phy_off(); 460 phy_off();
460 461
461 usb_put_transceiver(musb->xceiv); 462 usb_put_phy(musb->xceiv);
462 usb_nop_xceiv_unregister(); 463 usb_nop_xceiv_unregister();
463 464
464 return 0; 465 return 0;
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 9d63ba4d10d6..472c8b42d38b 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -28,6 +28,7 @@
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/clk.h> 30#include <linux/clk.h>
31#include <linux/err.h>
31#include <linux/io.h> 32#include <linux/io.h>
32#include <linux/gpio.h> 33#include <linux/gpio.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
@@ -385,8 +386,8 @@ static int davinci_musb_init(struct musb *musb)
385 u32 revision; 386 u32 revision;
386 387
387 usb_nop_xceiv_register(); 388 usb_nop_xceiv_register();
388 musb->xceiv = usb_get_transceiver(); 389 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
389 if (!musb->xceiv) 390 if (IS_ERR_OR_NULL(musb->xceiv))
390 goto unregister; 391 goto unregister;
391 392
392 musb->mregs += DAVINCI_BASE_OFFSET; 393 musb->mregs += DAVINCI_BASE_OFFSET;
@@ -444,7 +445,7 @@ static int davinci_musb_init(struct musb *musb)
444 return 0; 445 return 0;
445 446
446fail: 447fail:
447 usb_put_transceiver(musb->xceiv); 448 usb_put_phy(musb->xceiv);
448unregister: 449unregister:
449 usb_nop_xceiv_unregister(); 450 usb_nop_xceiv_unregister();
450 return -ENODEV; 451 return -ENODEV;
@@ -494,7 +495,7 @@ static int davinci_musb_exit(struct musb *musb)
494 495
495 phy_off(); 496 phy_off();
496 497
497 usb_put_transceiver(musb->xceiv); 498 usb_put_phy(musb->xceiv);
498 usb_nop_xceiv_unregister(); 499 usb_nop_xceiv_unregister();
499 500
500 return 0; 501 return 0;
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index db3dff854b71..26f1befb4896 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1909,7 +1909,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1909 /* The musb_platform_init() call: 1909 /* The musb_platform_init() call:
1910 * - adjusts musb->mregs and musb->isr if needed, 1910 * - adjusts musb->mregs and musb->isr if needed,
1911 * - may initialize an integrated tranceiver 1911 * - may initialize an integrated tranceiver
1912 * - initializes musb->xceiv, usually by otg_get_transceiver() 1912 * - initializes musb->xceiv, usually by otg_get_phy()
1913 * - stops powering VBUS 1913 * - stops powering VBUS
1914 * 1914 *
1915 * There are various transceiver configurations. Blackfin, 1915 * There are various transceiver configurations. Blackfin,
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index f4a40f001c88..dbcdeea30f09 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -327,7 +327,6 @@ struct musb {
327 327
328 irqreturn_t (*isr)(int, void *); 328 irqreturn_t (*isr)(int, void *);
329 struct work_struct irq_work; 329 struct work_struct irq_work;
330 struct work_struct otg_notifier_work;
331 u16 hwvers; 330 u16 hwvers;
332 331
333/* this hub status bit is reserved by USB 2.0 and not seen by usbcore */ 332/* this hub status bit is reserved by USB 2.0 and not seen by usbcore */
@@ -373,7 +372,6 @@ struct musb {
373 u16 int_tx; 372 u16 int_tx;
374 373
375 struct usb_phy *xceiv; 374 struct usb_phy *xceiv;
376 u8 xceiv_event;
377 375
378 int nIrq; 376 int nIrq;
379 unsigned irq_wake:1; 377 unsigned irq_wake:1;
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 23db42db761a..217808d9fbe1 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -31,6 +31,7 @@
31 31
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/err.h>
34#include <linux/platform_device.h> 35#include <linux/platform_device.h>
35#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
36#include <linux/pm_runtime.h> 37#include <linux/pm_runtime.h>
@@ -376,8 +377,8 @@ static int dsps_musb_init(struct musb *musb)
376 377
377 /* NOP driver needs change if supporting dual instance */ 378 /* NOP driver needs change if supporting dual instance */
378 usb_nop_xceiv_register(); 379 usb_nop_xceiv_register();
379 musb->xceiv = usb_get_transceiver(); 380 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
380 if (!musb->xceiv) 381 if (IS_ERR_OR_NULL(musb->xceiv))
381 return -ENODEV; 382 return -ENODEV;
382 383
383 /* Returns zero if e.g. not clocked */ 384 /* Returns zero if e.g. not clocked */
@@ -409,7 +410,7 @@ static int dsps_musb_init(struct musb *musb)
409 410
410 return 0; 411 return 0;
411err0: 412err0:
412 usb_put_transceiver(musb->xceiv); 413 usb_put_phy(musb->xceiv);
413 usb_nop_xceiv_unregister(); 414 usb_nop_xceiv_unregister();
414 return status; 415 return status;
415} 416}
@@ -430,7 +431,7 @@ static int dsps_musb_exit(struct musb *musb)
430 data->set_phy_power(0); 431 data->set_phy_power(0);
431 432
432 /* NOP driver needs change if supporting dual instance */ 433 /* NOP driver needs change if supporting dual instance */
433 usb_put_transceiver(musb->xceiv); 434 usb_put_phy(musb->xceiv);
434 usb_nop_xceiv_unregister(); 435 usb_nop_xceiv_unregister();
435 436
436 return 0; 437 return 0;
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 95918dacc99a..f7194cf65aba 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -328,6 +328,13 @@ static void txstate(struct musb *musb, struct musb_request *req)
328 328
329 musb_ep = req->ep; 329 musb_ep = req->ep;
330 330
331 /* Check if EP is disabled */
332 if (!musb_ep->desc) {
333 dev_dbg(musb->controller, "ep:%s disabled - ignore request\n",
334 musb_ep->end_point.name);
335 return;
336 }
337
331 /* we shouldn't get here while DMA is active ... but we do ... */ 338 /* we shouldn't get here while DMA is active ... but we do ... */
332 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) { 339 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) {
333 dev_dbg(musb->controller, "dma pending...\n"); 340 dev_dbg(musb->controller, "dma pending...\n");
@@ -650,6 +657,13 @@ static void rxstate(struct musb *musb, struct musb_request *req)
650 657
651 len = musb_ep->packet_sz; 658 len = musb_ep->packet_sz;
652 659
660 /* Check if EP is disabled */
661 if (!musb_ep->desc) {
662 dev_dbg(musb->controller, "ep:%s disabled - ignore request\n",
663 musb_ep->end_point.name);
664 return;
665 }
666
653 /* We shouldn't get here while DMA is active, but we do... */ 667 /* We shouldn't get here while DMA is active, but we do... */
654 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) { 668 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) {
655 dev_dbg(musb->controller, "DMA pending...\n"); 669 dev_dbg(musb->controller, "DMA pending...\n");
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index e090c799d87b..4bb717d0bd41 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -1746,7 +1746,11 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1746 c->channel_release(dma); 1746 c->channel_release(dma);
1747 hw_ep->rx_channel = NULL; 1747 hw_ep->rx_channel = NULL;
1748 dma = NULL; 1748 dma = NULL;
1749 /* REVISIT reset CSR */ 1749 val = musb_readw(epio, MUSB_RXCSR);
1750 val &= ~(MUSB_RXCSR_DMAENAB
1751 | MUSB_RXCSR_H_AUTOREQ
1752 | MUSB_RXCSR_AUTOCLEAR);
1753 musb_writew(epio, MUSB_RXCSR, val);
1750 } 1754 }
1751 } 1755 }
1752#endif /* Mentor DMA */ 1756#endif /* Mentor DMA */
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index c7785e81254c..5fdb9da8dd56 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -34,6 +34,7 @@
34#include <linux/dma-mapping.h> 34#include <linux/dma-mapping.h>
35#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
36#include <linux/err.h> 36#include <linux/err.h>
37#include <linux/usb/musb-omap.h>
37 38
38#include "musb_core.h" 39#include "musb_core.h"
39#include "omap2430.h" 40#include "omap2430.h"
@@ -41,9 +42,13 @@
41struct omap2430_glue { 42struct omap2430_glue {
42 struct device *dev; 43 struct device *dev;
43 struct platform_device *musb; 44 struct platform_device *musb;
45 enum omap_musb_vbus_id_status status;
46 struct work_struct omap_musb_mailbox_work;
44}; 47};
45#define glue_to_musb(g) platform_get_drvdata(g->musb) 48#define glue_to_musb(g) platform_get_drvdata(g->musb)
46 49
50struct omap2430_glue *_glue;
51
47static struct timer_list musb_idle_timer; 52static struct timer_list musb_idle_timer;
48 53
49static void musb_do_idle(unsigned long _musb) 54static void musb_do_idle(unsigned long _musb)
@@ -223,50 +228,63 @@ static inline void omap2430_low_level_init(struct musb *musb)
223 musb_writel(musb->mregs, OTG_FORCESTDBY, l); 228 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
224} 229}
225 230
226static int musb_otg_notifications(struct notifier_block *nb, 231void omap_musb_mailbox(enum omap_musb_vbus_id_status status)
227 unsigned long event, void *unused)
228{ 232{
229 struct musb *musb = container_of(nb, struct musb, nb); 233 struct omap2430_glue *glue = _glue;
234 struct musb *musb = glue_to_musb(glue);
230 235
231 musb->xceiv_event = event; 236 glue->status = status;
232 schedule_work(&musb->otg_notifier_work); 237 if (!musb) {
238 dev_err(glue->dev, "musb core is not yet ready\n");
239 return;
240 }
233 241
234 return NOTIFY_OK; 242 schedule_work(&glue->omap_musb_mailbox_work);
235} 243}
244EXPORT_SYMBOL_GPL(omap_musb_mailbox);
236 245
237static void musb_otg_notifier_work(struct work_struct *data_notifier_work) 246static void omap_musb_set_mailbox(struct omap2430_glue *glue)
238{ 247{
239 struct musb *musb = container_of(data_notifier_work, struct musb, otg_notifier_work); 248 struct musb *musb = glue_to_musb(glue);
240 struct device *dev = musb->controller; 249 struct device *dev = musb->controller;
241 struct musb_hdrc_platform_data *pdata = dev->platform_data; 250 struct musb_hdrc_platform_data *pdata = dev->platform_data;
242 struct omap_musb_board_data *data = pdata->board_data; 251 struct omap_musb_board_data *data = pdata->board_data;
252 struct usb_otg *otg = musb->xceiv->otg;
243 253
244 switch (musb->xceiv_event) { 254 switch (glue->status) {
245 case USB_EVENT_ID: 255 case OMAP_MUSB_ID_GROUND:
246 dev_dbg(musb->controller, "ID GND\n"); 256 dev_dbg(dev, "ID GND\n");
247 257
258 otg->default_a = true;
259 musb->xceiv->state = OTG_STATE_A_IDLE;
260 musb->xceiv->last_event = USB_EVENT_ID;
248 if (!is_otg_enabled(musb) || musb->gadget_driver) { 261 if (!is_otg_enabled(musb) || musb->gadget_driver) {
249 pm_runtime_get_sync(musb->controller); 262 pm_runtime_get_sync(dev);
250 usb_phy_init(musb->xceiv); 263 usb_phy_init(musb->xceiv);
251 omap2430_musb_set_vbus(musb, 1); 264 omap2430_musb_set_vbus(musb, 1);
252 } 265 }
253 break; 266 break;
254 267
255 case USB_EVENT_VBUS: 268 case OMAP_MUSB_VBUS_VALID:
256 dev_dbg(musb->controller, "VBUS Connect\n"); 269 dev_dbg(dev, "VBUS Connect\n");
257 270
271 otg->default_a = false;
272 musb->xceiv->state = OTG_STATE_B_IDLE;
273 musb->xceiv->last_event = USB_EVENT_VBUS;
258 if (musb->gadget_driver) 274 if (musb->gadget_driver)
259 pm_runtime_get_sync(musb->controller); 275 pm_runtime_get_sync(dev);
260 usb_phy_init(musb->xceiv); 276 usb_phy_init(musb->xceiv);
261 break; 277 break;
262 278
263 case USB_EVENT_NONE: 279 case OMAP_MUSB_ID_FLOAT:
264 dev_dbg(musb->controller, "VBUS Disconnect\n"); 280 case OMAP_MUSB_VBUS_OFF:
281 dev_dbg(dev, "VBUS Disconnect\n");
265 282
283 musb->xceiv->last_event = USB_EVENT_NONE;
266 if (is_otg_enabled(musb) || is_peripheral_enabled(musb)) 284 if (is_otg_enabled(musb) || is_peripheral_enabled(musb))
267 if (musb->gadget_driver) { 285 if (musb->gadget_driver) {
268 pm_runtime_mark_last_busy(musb->controller); 286 pm_runtime_mark_last_busy(dev);
269 pm_runtime_put_autosuspend(musb->controller); 287 pm_runtime_put_autosuspend(dev);
270 } 288 }
271 289
272 if (data->interface_type == MUSB_INTERFACE_UTMI) { 290 if (data->interface_type == MUSB_INTERFACE_UTMI) {
@@ -276,15 +294,24 @@ static void musb_otg_notifier_work(struct work_struct *data_notifier_work)
276 usb_phy_shutdown(musb->xceiv); 294 usb_phy_shutdown(musb->xceiv);
277 break; 295 break;
278 default: 296 default:
279 dev_dbg(musb->controller, "ID float\n"); 297 dev_dbg(dev, "ID float\n");
280 } 298 }
281} 299}
282 300
301
302static void omap_musb_mailbox_work(struct work_struct *mailbox_work)
303{
304 struct omap2430_glue *glue = container_of(mailbox_work,
305 struct omap2430_glue, omap_musb_mailbox_work);
306 omap_musb_set_mailbox(glue);
307}
308
283static int omap2430_musb_init(struct musb *musb) 309static int omap2430_musb_init(struct musb *musb)
284{ 310{
285 u32 l; 311 u32 l;
286 int status = 0; 312 int status = 0;
287 struct device *dev = musb->controller; 313 struct device *dev = musb->controller;
314 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
288 struct musb_hdrc_platform_data *plat = dev->platform_data; 315 struct musb_hdrc_platform_data *plat = dev->platform_data;
289 struct omap_musb_board_data *data = plat->board_data; 316 struct omap_musb_board_data *data = plat->board_data;
290 317
@@ -292,14 +319,12 @@ static int omap2430_musb_init(struct musb *musb)
292 * up through ULPI. TWL4030-family PMICs include one, 319 * up through ULPI. TWL4030-family PMICs include one,
293 * which needs a driver, drivers aren't always needed. 320 * which needs a driver, drivers aren't always needed.
294 */ 321 */
295 musb->xceiv = usb_get_transceiver(); 322 musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
296 if (!musb->xceiv) { 323 if (IS_ERR_OR_NULL(musb->xceiv)) {
297 pr_err("HS USB OTG: no transceiver configured\n"); 324 pr_err("HS USB OTG: no transceiver configured\n");
298 return -ENODEV; 325 return -ENODEV;
299 } 326 }
300 327
301 INIT_WORK(&musb->otg_notifier_work, musb_otg_notifier_work);
302
303 status = pm_runtime_get_sync(dev); 328 status = pm_runtime_get_sync(dev);
304 if (status < 0) { 329 if (status < 0) {
305 dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status); 330 dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status);
@@ -326,14 +351,11 @@ static int omap2430_musb_init(struct musb *musb)
326 musb_readl(musb->mregs, OTG_INTERFSEL), 351 musb_readl(musb->mregs, OTG_INTERFSEL),
327 musb_readl(musb->mregs, OTG_SIMENABLE)); 352 musb_readl(musb->mregs, OTG_SIMENABLE));
328 353
329 musb->nb.notifier_call = musb_otg_notifications;
330 status = usb_register_notifier(musb->xceiv, &musb->nb);
331
332 if (status)
333 dev_dbg(musb->controller, "notification register failed\n");
334
335 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 354 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
336 355
356 if (glue->status != OMAP_MUSB_UNKNOWN)
357 omap_musb_set_mailbox(glue);
358
337 pm_runtime_put_noidle(musb->controller); 359 pm_runtime_put_noidle(musb->controller);
338 return 0; 360 return 0;
339 361
@@ -346,12 +368,13 @@ static void omap2430_musb_enable(struct musb *musb)
346 u8 devctl; 368 u8 devctl;
347 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 369 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
348 struct device *dev = musb->controller; 370 struct device *dev = musb->controller;
371 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
349 struct musb_hdrc_platform_data *pdata = dev->platform_data; 372 struct musb_hdrc_platform_data *pdata = dev->platform_data;
350 struct omap_musb_board_data *data = pdata->board_data; 373 struct omap_musb_board_data *data = pdata->board_data;
351 374
352 switch (musb->xceiv->last_event) { 375 switch (glue->status) {
353 376
354 case USB_EVENT_ID: 377 case OMAP_MUSB_ID_GROUND:
355 usb_phy_init(musb->xceiv); 378 usb_phy_init(musb->xceiv);
356 if (data->interface_type != MUSB_INTERFACE_UTMI) 379 if (data->interface_type != MUSB_INTERFACE_UTMI)
357 break; 380 break;
@@ -370,7 +393,7 @@ static void omap2430_musb_enable(struct musb *musb)
370 } 393 }
371 break; 394 break;
372 395
373 case USB_EVENT_VBUS: 396 case OMAP_MUSB_VBUS_VALID:
374 usb_phy_init(musb->xceiv); 397 usb_phy_init(musb->xceiv);
375 break; 398 break;
376 399
@@ -381,17 +404,18 @@ static void omap2430_musb_enable(struct musb *musb)
381 404
382static void omap2430_musb_disable(struct musb *musb) 405static void omap2430_musb_disable(struct musb *musb)
383{ 406{
384 if (musb->xceiv->last_event) 407 struct device *dev = musb->controller;
408 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
409
410 if (glue->status != OMAP_MUSB_UNKNOWN)
385 usb_phy_shutdown(musb->xceiv); 411 usb_phy_shutdown(musb->xceiv);
386} 412}
387 413
388static int omap2430_musb_exit(struct musb *musb) 414static int omap2430_musb_exit(struct musb *musb)
389{ 415{
390 del_timer_sync(&musb_idle_timer); 416 del_timer_sync(&musb_idle_timer);
391 cancel_work_sync(&musb->otg_notifier_work);
392 417
393 omap2430_low_level_exit(musb); 418 omap2430_low_level_exit(musb);
394 usb_put_transceiver(musb->xceiv);
395 419
396 return 0; 420 return 0;
397} 421}
@@ -418,7 +442,7 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
418 struct omap2430_glue *glue; 442 struct omap2430_glue *glue;
419 int ret = -ENOMEM; 443 int ret = -ENOMEM;
420 444
421 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 445 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
422 if (!glue) { 446 if (!glue) {
423 dev_err(&pdev->dev, "failed to allocate glue context\n"); 447 dev_err(&pdev->dev, "failed to allocate glue context\n");
424 goto err0; 448 goto err0;
@@ -427,7 +451,7 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
427 musb = platform_device_alloc("musb-hdrc", -1); 451 musb = platform_device_alloc("musb-hdrc", -1);
428 if (!musb) { 452 if (!musb) {
429 dev_err(&pdev->dev, "failed to allocate musb device\n"); 453 dev_err(&pdev->dev, "failed to allocate musb device\n");
430 goto err1; 454 goto err0;
431 } 455 }
432 456
433 musb->dev.parent = &pdev->dev; 457 musb->dev.parent = &pdev->dev;
@@ -436,22 +460,31 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
436 460
437 glue->dev = &pdev->dev; 461 glue->dev = &pdev->dev;
438 glue->musb = musb; 462 glue->musb = musb;
463 glue->status = OMAP_MUSB_UNKNOWN;
439 464
440 pdata->platform_ops = &omap2430_ops; 465 pdata->platform_ops = &omap2430_ops;
441 466
442 platform_set_drvdata(pdev, glue); 467 platform_set_drvdata(pdev, glue);
443 468
469 /*
470 * REVISIT if we ever have two instances of the wrapper, we will be
471 * in big trouble
472 */
473 _glue = glue;
474
475 INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work);
476
444 ret = platform_device_add_resources(musb, pdev->resource, 477 ret = platform_device_add_resources(musb, pdev->resource,
445 pdev->num_resources); 478 pdev->num_resources);
446 if (ret) { 479 if (ret) {
447 dev_err(&pdev->dev, "failed to add resources\n"); 480 dev_err(&pdev->dev, "failed to add resources\n");
448 goto err2; 481 goto err1;
449 } 482 }
450 483
451 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 484 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
452 if (ret) { 485 if (ret) {
453 dev_err(&pdev->dev, "failed to add platform_data\n"); 486 dev_err(&pdev->dev, "failed to add platform_data\n");
454 goto err2; 487 goto err1;
455 } 488 }
456 489
457 pm_runtime_enable(&pdev->dev); 490 pm_runtime_enable(&pdev->dev);
@@ -459,16 +492,13 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
459 ret = platform_device_add(musb); 492 ret = platform_device_add(musb);
460 if (ret) { 493 if (ret) {
461 dev_err(&pdev->dev, "failed to register musb device\n"); 494 dev_err(&pdev->dev, "failed to register musb device\n");
462 goto err2; 495 goto err1;
463 } 496 }
464 497
465 return 0; 498 return 0;
466 499
467err2:
468 platform_device_put(musb);
469
470err1: 500err1:
471 kfree(glue); 501 platform_device_put(musb);
472 502
473err0: 503err0:
474 return ret; 504 return ret;
@@ -478,9 +508,9 @@ static int __devexit omap2430_remove(struct platform_device *pdev)
478{ 508{
479 struct omap2430_glue *glue = platform_get_drvdata(pdev); 509 struct omap2430_glue *glue = platform_get_drvdata(pdev);
480 510
511 cancel_work_sync(&glue->omap_musb_mailbox_work);
481 platform_device_del(glue->musb); 512 platform_device_del(glue->musb);
482 platform_device_put(glue->musb); 513 platform_device_put(glue->musb);
483 kfree(glue);
484 514
485 return 0; 515 return 0;
486} 516}
@@ -546,7 +576,7 @@ static int __init omap2430_init(void)
546{ 576{
547 return platform_driver_register(&omap2430_driver); 577 return platform_driver_register(&omap2430_driver);
548} 578}
549module_init(omap2430_init); 579subsys_initcall(omap2430_init);
550 580
551static void __exit omap2430_exit(void) 581static void __exit omap2430_exit(void)
552{ 582{
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index de1355946a83..1a1bd9cf40c5 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -17,6 +17,7 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/err.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/prefetch.h> 22#include <linux/prefetch.h>
22#include <linux/usb.h> 23#include <linux/usb.h>
@@ -1078,8 +1079,8 @@ static int tusb_musb_init(struct musb *musb)
1078 int ret; 1079 int ret;
1079 1080
1080 usb_nop_xceiv_register(); 1081 usb_nop_xceiv_register();
1081 musb->xceiv = usb_get_transceiver(); 1082 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
1082 if (!musb->xceiv) 1083 if (IS_ERR_OR_NULL(musb->xceiv))
1083 return -ENODEV; 1084 return -ENODEV;
1084 1085
1085 pdev = to_platform_device(musb->controller); 1086 pdev = to_platform_device(musb->controller);
@@ -1130,7 +1131,7 @@ done:
1130 if (sync) 1131 if (sync)
1131 iounmap(sync); 1132 iounmap(sync);
1132 1133
1133 usb_put_transceiver(musb->xceiv); 1134 usb_put_phy(musb->xceiv);
1134 usb_nop_xceiv_unregister(); 1135 usb_nop_xceiv_unregister();
1135 } 1136 }
1136 return ret; 1137 return ret;
@@ -1146,7 +1147,7 @@ static int tusb_musb_exit(struct musb *musb)
1146 1147
1147 iounmap(musb->sync_va); 1148 iounmap(musb->sync_va);
1148 1149
1149 usb_put_transceiver(musb->xceiv); 1150 usb_put_phy(musb->xceiv);
1150 usb_nop_xceiv_unregister(); 1151 usb_nop_xceiv_unregister();
1151 return 0; 1152 return 0;
1152} 1153}
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index aa09dd417b94..a8c0fadce1b0 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -23,6 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/clk.h> 25#include <linux/clk.h>
26#include <linux/err.h>
26#include <linux/io.h> 27#include <linux/io.h>
27#include <linux/platform_device.h> 28#include <linux/platform_device.h>
28 29
@@ -37,8 +38,8 @@ struct ux500_glue {
37 38
38static int ux500_musb_init(struct musb *musb) 39static int ux500_musb_init(struct musb *musb)
39{ 40{
40 musb->xceiv = usb_get_transceiver(); 41 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
41 if (!musb->xceiv) { 42 if (IS_ERR_OR_NULL(musb->xceiv)) {
42 pr_err("HS USB OTG: no transceiver configured\n"); 43 pr_err("HS USB OTG: no transceiver configured\n");
43 return -ENODEV; 44 return -ENODEV;
44 } 45 }
@@ -48,7 +49,7 @@ static int ux500_musb_init(struct musb *musb)
48 49
49static int ux500_musb_exit(struct musb *musb) 50static int ux500_musb_exit(struct musb *musb)
50{ 51{
51 usb_put_transceiver(musb->xceiv); 52 usb_put_phy(musb->xceiv);
52 53
53 return 0; 54 return 0;
54} 55}
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 5c87db06b598..13fd1ddf742f 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -116,6 +116,16 @@ config FSL_USB2_OTG
116 help 116 help
117 Enable this to support Freescale USB OTG transceiver. 117 Enable this to support Freescale USB OTG transceiver.
118 118
119config USB_MXS_PHY
120 tristate "Freescale MXS USB PHY support"
121 depends on ARCH_MXC || ARCH_MXS
122 select STMP_DEVICE
123 select USB_OTG_UTILS
124 help
125 Enable this to support the Freescale MXS USB PHY.
126
127 MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
128
119config USB_MV_OTG 129config USB_MV_OTG
120 tristate "Marvell USB OTG support" 130 tristate "Marvell USB OTG support"
121 depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND 131 depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index 41aa5098b139..a844b8d35d14 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG) += msm_otg.o
20obj-$(CONFIG_AB8500_USB) += ab8500-usb.o 20obj-$(CONFIG_AB8500_USB) += ab8500-usb.o
21fsl_usb2_otg-objs := fsl_otg.o otg_fsm.o 21fsl_usb2_otg-objs := fsl_otg.o otg_fsm.o
22obj-$(CONFIG_FSL_USB2_OTG) += fsl_usb2_otg.o 22obj-$(CONFIG_FSL_USB2_OTG) += fsl_usb2_otg.o
23obj-$(CONFIG_USB_MXS_PHY) += mxs-phy.o
23obj-$(CONFIG_USB_MV_OTG) += mv_otg.o 24obj-$(CONFIG_USB_MV_OTG) += mv_otg.o
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c
index a84af677dc59..ae8ad561f083 100644
--- a/drivers/usb/otg/ab8500-usb.c
+++ b/drivers/usb/otg/ab8500-usb.c
@@ -529,7 +529,7 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev)
529 if (err < 0) 529 if (err < 0)
530 goto fail0; 530 goto fail0;
531 531
532 err = usb_set_transceiver(&ab->phy); 532 err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
533 if (err) { 533 if (err) {
534 dev_err(&pdev->dev, "Can't register transceiver\n"); 534 dev_err(&pdev->dev, "Can't register transceiver\n");
535 goto fail1; 535 goto fail1;
@@ -556,7 +556,7 @@ static int __devexit ab8500_usb_remove(struct platform_device *pdev)
556 556
557 cancel_work_sync(&ab->phy_dis_work); 557 cancel_work_sync(&ab->phy_dis_work);
558 558
559 usb_set_transceiver(NULL); 559 usb_remove_phy(&ab->phy);
560 560
561 ab8500_usb_host_phy_dis(ab); 561 ab8500_usb_host_phy_dis(ab);
562 ab8500_usb_peri_phy_dis(ab); 562 ab8500_usb_peri_phy_dis(ab);
diff --git a/drivers/usb/otg/fsl_otg.c b/drivers/usb/otg/fsl_otg.c
index be4a63e8302f..23c798cb2d7f 100644
--- a/drivers/usb/otg/fsl_otg.c
+++ b/drivers/usb/otg/fsl_otg.c
@@ -806,7 +806,7 @@ static int fsl_otg_conf(struct platform_device *pdev)
806 fsl_otg_dev = fsl_otg_tc; 806 fsl_otg_dev = fsl_otg_tc;
807 807
808 /* Store the otg transceiver */ 808 /* Store the otg transceiver */
809 status = usb_set_transceiver(&fsl_otg_tc->phy); 809 status = usb_add_phy(&fsl_otg_tc->phy, USB_PHY_TYPE_USB2);
810 if (status) { 810 if (status) {
811 pr_warn(FSL_OTG_NAME ": unable to register OTG transceiver.\n"); 811 pr_warn(FSL_OTG_NAME ": unable to register OTG transceiver.\n");
812 goto err; 812 goto err;
@@ -824,7 +824,7 @@ err:
824int usb_otg_start(struct platform_device *pdev) 824int usb_otg_start(struct platform_device *pdev)
825{ 825{
826 struct fsl_otg *p_otg; 826 struct fsl_otg *p_otg;
827 struct usb_phy *otg_trans = usb_get_transceiver(); 827 struct usb_phy *otg_trans = usb_get_phy(USB_PHY_TYPE_USB2);
828 struct otg_fsm *fsm; 828 struct otg_fsm *fsm;
829 int status; 829 int status;
830 struct resource *res; 830 struct resource *res;
@@ -1134,7 +1134,7 @@ static int __devexit fsl_otg_remove(struct platform_device *pdev)
1134{ 1134{
1135 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 1135 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
1136 1136
1137 usb_set_transceiver(NULL); 1137 usb_remove_phy(&fsl_otg_dev->phy);
1138 free_irq(fsl_otg_dev->irq, fsl_otg_dev); 1138 free_irq(fsl_otg_dev->irq, fsl_otg_dev);
1139 1139
1140 iounmap((void *)usb_dr_regs); 1140 iounmap((void *)usb_dr_regs);
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c
index bde6298a9693..a67ffe22179a 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/otg/gpio_vbus.c
@@ -320,7 +320,7 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
320 } 320 }
321 321
322 /* only active when a gadget is registered */ 322 /* only active when a gadget is registered */
323 err = usb_set_transceiver(&gpio_vbus->phy); 323 err = usb_add_phy(&gpio_vbus->phy, USB_PHY_TYPE_USB2);
324 if (err) { 324 if (err) {
325 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 325 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
326 err); 326 err);
@@ -354,7 +354,7 @@ static int __exit gpio_vbus_remove(struct platform_device *pdev)
354 cancel_delayed_work_sync(&gpio_vbus->work); 354 cancel_delayed_work_sync(&gpio_vbus->work);
355 regulator_put(gpio_vbus->vbus_draw); 355 regulator_put(gpio_vbus->vbus_draw);
356 356
357 usb_set_transceiver(NULL); 357 usb_remove_phy(&gpio_vbus->phy);
358 358
359 free_irq(gpio_vbus->irq, pdev); 359 free_irq(gpio_vbus->irq, pdev);
360 if (gpio_is_valid(pdata->gpio_pullup)) 360 if (gpio_is_valid(pdata->gpio_pullup))
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c
index 70cf5d7bca48..75cea4ab0985 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/otg/isp1301_omap.c
@@ -1336,9 +1336,6 @@ static int
1336isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) 1336isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
1337{ 1337{
1338 struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); 1338 struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy);
1339#ifndef CONFIG_USB_OTG
1340 u32 l;
1341#endif
1342 1339
1343 if (!otg || isp != the_transceiver) 1340 if (!otg || isp != the_transceiver)
1344 return -ENODEV; 1341 return -ENODEV;
@@ -1365,10 +1362,14 @@ isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
1365 otg->gadget = gadget; 1362 otg->gadget = gadget;
1366 // FIXME update its refcount 1363 // FIXME update its refcount
1367 1364
1368 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; 1365 {
1369 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS); 1366 u32 l;
1370 l |= OTG_ID; 1367
1371 omap_writel(l, OTG_CTRL); 1368 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1369 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS);
1370 l |= OTG_ID;
1371 omap_writel(l, OTG_CTRL);
1372 }
1372 1373
1373 power_up(isp); 1374 power_up(isp);
1374 isp->phy.state = OTG_STATE_B_IDLE; 1375 isp->phy.state = OTG_STATE_B_IDLE;
@@ -1610,7 +1611,7 @@ isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
1610 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES); 1611 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1611#endif 1612#endif
1612 1613
1613 status = usb_set_transceiver(&isp->phy); 1614 status = usb_add_phy(&isp->phy, USB_PHY_TYPE_USB2);
1614 if (status < 0) 1615 if (status < 0)
1615 dev_err(&i2c->dev, "can't register transceiver, %d\n", 1616 dev_err(&i2c->dev, "can't register transceiver, %d\n",
1616 status); 1617 status);
@@ -1649,7 +1650,7 @@ subsys_initcall(isp_init);
1649static void __exit isp_exit(void) 1650static void __exit isp_exit(void)
1650{ 1651{
1651 if (the_transceiver) 1652 if (the_transceiver)
1652 usb_set_transceiver(NULL); 1653 usb_remove_phy(&the_transceiver->phy);
1653 i2c_del_driver(&isp1301_driver); 1654 i2c_del_driver(&isp1301_driver);
1654} 1655}
1655module_exit(isp_exit); 1656module_exit(isp_exit);
diff --git a/drivers/usb/otg/msm_otg.c b/drivers/usb/otg/msm_otg.c
index 1d0347c247d1..9f5fc906041a 100644
--- a/drivers/usb/otg/msm_otg.c
+++ b/drivers/usb/otg/msm_otg.c
@@ -1555,9 +1555,9 @@ static int __init msm_otg_probe(struct platform_device *pdev)
1555 phy->otg->set_host = msm_otg_set_host; 1555 phy->otg->set_host = msm_otg_set_host;
1556 phy->otg->set_peripheral = msm_otg_set_peripheral; 1556 phy->otg->set_peripheral = msm_otg_set_peripheral;
1557 1557
1558 ret = usb_set_transceiver(&motg->phy); 1558 ret = usb_add_phy(&motg->phy, USB_PHY_TYPE_USB2);
1559 if (ret) { 1559 if (ret) {
1560 dev_err(&pdev->dev, "usb_set_transceiver failed\n"); 1560 dev_err(&pdev->dev, "usb_add_phy failed\n");
1561 goto free_irq; 1561 goto free_irq;
1562 } 1562 }
1563 1563
@@ -1624,7 +1624,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev)
1624 device_init_wakeup(&pdev->dev, 0); 1624 device_init_wakeup(&pdev->dev, 0);
1625 pm_runtime_disable(&pdev->dev); 1625 pm_runtime_disable(&pdev->dev);
1626 1626
1627 usb_set_transceiver(NULL); 1627 usb_remove_phy(phy);
1628 free_irq(motg->irq, motg); 1628 free_irq(motg->irq, motg);
1629 1629
1630 /* 1630 /*
diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c
index 6cc6c3ffbb83..3f124e8f5792 100644
--- a/drivers/usb/otg/mv_otg.c
+++ b/drivers/usb/otg/mv_otg.c
@@ -690,7 +690,7 @@ int mv_otg_remove(struct platform_device *pdev)
690 for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++) 690 for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++)
691 clk_put(mvotg->clk[clk_i]); 691 clk_put(mvotg->clk[clk_i]);
692 692
693 usb_set_transceiver(NULL); 693 usb_remove_phy(&mvotg->phy);
694 platform_set_drvdata(pdev, NULL); 694 platform_set_drvdata(pdev, NULL);
695 695
696 kfree(mvotg->phy.otg); 696 kfree(mvotg->phy.otg);
@@ -853,7 +853,7 @@ static int mv_otg_probe(struct platform_device *pdev)
853 goto err_disable_clk; 853 goto err_disable_clk;
854 } 854 }
855 855
856 retval = usb_set_transceiver(&mvotg->phy); 856 retval = usb_add_phy(&mvotg->phy, USB_PHY_TYPE_USB2);
857 if (retval < 0) { 857 if (retval < 0) {
858 dev_err(&pdev->dev, "can't register transceiver, %d\n", 858 dev_err(&pdev->dev, "can't register transceiver, %d\n",
859 retval); 859 retval);
@@ -880,7 +880,7 @@ static int mv_otg_probe(struct platform_device *pdev)
880 return 0; 880 return 0;
881 881
882err_set_transceiver: 882err_set_transceiver:
883 usb_set_transceiver(NULL); 883 usb_remove_phy(&mvotg->phy);
884err_free_irq: 884err_free_irq:
885 free_irq(mvotg->irq, mvotg); 885 free_irq(mvotg->irq, mvotg);
886err_disable_clk: 886err_disable_clk:
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
new file mode 100644
index 000000000000..c1a67cb8e244
--- /dev/null
+++ b/drivers/usb/otg/mxs-phy.c
@@ -0,0 +1,186 @@
1/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Copyright (C) 2012 Marek Vasut <marex@denx.de>
4 * on behalf of DENX Software Engineering GmbH
5 *
6 * The code contained herein is licensed under the GNU General Public
7 * License. You may obtain a copy of the GNU General Public License
8 * Version 2 or later at the following locations:
9 *
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/platform_device.h>
17#include <linux/clk.h>
18#include <linux/usb/otg.h>
19#include <linux/stmp_device.h>
20#include <linux/delay.h>
21#include <linux/err.h>
22#include <linux/io.h>
23
24#define DRIVER_NAME "mxs_phy"
25
26#define HW_USBPHY_PWD 0x00
27#define HW_USBPHY_CTRL 0x30
28#define HW_USBPHY_CTRL_SET 0x34
29#define HW_USBPHY_CTRL_CLR 0x38
30
31#define BM_USBPHY_CTRL_SFTRST BIT(31)
32#define BM_USBPHY_CTRL_CLKGATE BIT(30)
33#define BM_USBPHY_CTRL_ENUTMILEVEL3 BIT(15)
34#define BM_USBPHY_CTRL_ENUTMILEVEL2 BIT(14)
35#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)
36
37struct mxs_phy {
38 struct usb_phy phy;
39 struct clk *clk;
40};
41
42#define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
43
44static void mxs_phy_hw_init(struct mxs_phy *mxs_phy)
45{
46 void __iomem *base = mxs_phy->phy.io_priv;
47
48 stmp_reset_block(base + HW_USBPHY_CTRL);
49
50 /* Power up the PHY */
51 writel_relaxed(0, base + HW_USBPHY_PWD);
52
53 /* enable FS/LS device */
54 writel_relaxed(BM_USBPHY_CTRL_ENUTMILEVEL2 |
55 BM_USBPHY_CTRL_ENUTMILEVEL3,
56 base + HW_USBPHY_CTRL_SET);
57}
58
59static int mxs_phy_init(struct usb_phy *phy)
60{
61 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
62
63 clk_prepare_enable(mxs_phy->clk);
64 mxs_phy_hw_init(mxs_phy);
65
66 return 0;
67}
68
69static void mxs_phy_shutdown(struct usb_phy *phy)
70{
71 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
72
73 writel_relaxed(BM_USBPHY_CTRL_CLKGATE,
74 phy->io_priv + HW_USBPHY_CTRL_SET);
75
76 clk_disable_unprepare(mxs_phy->clk);
77}
78
79static int mxs_phy_on_connect(struct usb_phy *phy, int port)
80{
81 dev_dbg(phy->dev, "Connect on port %d\n", port);
82
83 mxs_phy_hw_init(to_mxs_phy(phy));
84 writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
85 phy->io_priv + HW_USBPHY_CTRL_SET);
86
87 return 0;
88}
89
90static int mxs_phy_on_disconnect(struct usb_phy *phy, int port)
91{
92 dev_dbg(phy->dev, "Disconnect on port %d\n", port);
93
94 writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
95 phy->io_priv + HW_USBPHY_CTRL_CLR);
96
97 return 0;
98}
99
100static int mxs_phy_probe(struct platform_device *pdev)
101{
102 struct resource *res;
103 void __iomem *base;
104 struct clk *clk;
105 struct mxs_phy *mxs_phy;
106
107 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
108 if (!res) {
109 dev_err(&pdev->dev, "can't get device resources\n");
110 return -ENOENT;
111 }
112
113 base = devm_request_and_ioremap(&pdev->dev, res);
114 if (!base)
115 return -EBUSY;
116
117 clk = devm_clk_get(&pdev->dev, NULL);
118 if (IS_ERR(clk)) {
119 dev_err(&pdev->dev,
120 "can't get the clock, err=%ld", PTR_ERR(clk));
121 return PTR_ERR(clk);
122 }
123
124 mxs_phy = devm_kzalloc(&pdev->dev, sizeof(*mxs_phy), GFP_KERNEL);
125 if (!mxs_phy) {
126 dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n");
127 return -ENOMEM;
128 }
129
130 mxs_phy->phy.io_priv = base;
131 mxs_phy->phy.dev = &pdev->dev;
132 mxs_phy->phy.label = DRIVER_NAME;
133 mxs_phy->phy.init = mxs_phy_init;
134 mxs_phy->phy.shutdown = mxs_phy_shutdown;
135 mxs_phy->phy.notify_connect = mxs_phy_on_connect;
136 mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect;
137
138 ATOMIC_INIT_NOTIFIER_HEAD(&mxs_phy->phy.notifier);
139
140 mxs_phy->clk = clk;
141
142 platform_set_drvdata(pdev, &mxs_phy->phy);
143
144 return 0;
145}
146
147static int __devexit mxs_phy_remove(struct platform_device *pdev)
148{
149 platform_set_drvdata(pdev, NULL);
150
151 return 0;
152}
153
154static const struct of_device_id mxs_phy_dt_ids[] = {
155 { .compatible = "fsl,imx23-usbphy", },
156 { /* sentinel */ }
157};
158MODULE_DEVICE_TABLE(of, mxs_phy_dt_ids);
159
160static struct platform_driver mxs_phy_driver = {
161 .probe = mxs_phy_probe,
162 .remove = __devexit_p(mxs_phy_remove),
163 .driver = {
164 .name = DRIVER_NAME,
165 .owner = THIS_MODULE,
166 .of_match_table = mxs_phy_dt_ids,
167 },
168};
169
170static int __init mxs_phy_module_init(void)
171{
172 return platform_driver_register(&mxs_phy_driver);
173}
174postcore_initcall(mxs_phy_module_init);
175
176static void __exit mxs_phy_module_exit(void)
177{
178 platform_driver_unregister(&mxs_phy_driver);
179}
180module_exit(mxs_phy_module_exit);
181
182MODULE_ALIAS("platform:mxs-usb-phy");
183MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
184MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
185MODULE_DESCRIPTION("Freescale MXS USB PHY driver");
186MODULE_LICENSE("GPL");
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
index 58b26df6afd1..803f958f4133 100644
--- a/drivers/usb/otg/nop-usb-xceiv.c
+++ b/drivers/usb/otg/nop-usb-xceiv.c
@@ -117,7 +117,7 @@ static int __devinit nop_usb_xceiv_probe(struct platform_device *pdev)
117 nop->phy.otg->set_host = nop_set_host; 117 nop->phy.otg->set_host = nop_set_host;
118 nop->phy.otg->set_peripheral = nop_set_peripheral; 118 nop->phy.otg->set_peripheral = nop_set_peripheral;
119 119
120 err = usb_set_transceiver(&nop->phy); 120 err = usb_add_phy(&nop->phy, USB_PHY_TYPE_USB2);
121 if (err) { 121 if (err) {
122 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 122 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
123 err); 123 err);
@@ -139,7 +139,7 @@ static int __devexit nop_usb_xceiv_remove(struct platform_device *pdev)
139{ 139{
140 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev); 140 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
141 141
142 usb_set_transceiver(NULL); 142 usb_remove_phy(&nop->phy);
143 143
144 platform_set_drvdata(pdev, NULL); 144 platform_set_drvdata(pdev, NULL);
145 kfree(nop->phy.otg); 145 kfree(nop->phy.otg);
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index 801e597a1541..1bf60a22595c 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -11,60 +11,195 @@
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/export.h> 13#include <linux/export.h>
14#include <linux/err.h>
14#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/slab.h>
15 17
16#include <linux/usb/otg.h> 18#include <linux/usb/otg.h>
17 19
18static struct usb_phy *phy; 20static LIST_HEAD(phy_list);
21static DEFINE_SPINLOCK(phy_lock);
22
23static struct usb_phy *__usb_find_phy(struct list_head *list,
24 enum usb_phy_type type)
25{
26 struct usb_phy *phy = NULL;
27
28 list_for_each_entry(phy, list, head) {
29 if (phy->type != type)
30 continue;
31
32 return phy;
33 }
34
35 return ERR_PTR(-ENODEV);
36}
37
38static void devm_usb_phy_release(struct device *dev, void *res)
39{
40 struct usb_phy *phy = *(struct usb_phy **)res;
41
42 usb_put_phy(phy);
43}
44
45static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
46{
47 return res == match_data;
48}
19 49
20/** 50/**
21 * usb_get_transceiver - find the (single) USB transceiver 51 * devm_usb_get_phy - find the USB PHY
52 * @dev - device that requests this phy
53 * @type - the type of the phy the controller requires
22 * 54 *
23 * Returns the transceiver driver, after getting a refcount to it; or 55 * Gets the phy using usb_get_phy(), and associates a device with it using
24 * null if there is no such transceiver. The caller is responsible for 56 * devres. On driver detach, release function is invoked on the devres data,
25 * calling usb_put_transceiver() to release that count. 57 * then, devres data is freed.
26 * 58 *
27 * For use by USB host and peripheral drivers. 59 * For use by USB host and peripheral drivers.
28 */ 60 */
29struct usb_phy *usb_get_transceiver(void) 61struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
30{ 62{
31 if (phy) 63 struct usb_phy **ptr, *phy;
32 get_device(phy->dev); 64
65 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
66 if (!ptr)
67 return NULL;
68
69 phy = usb_get_phy(type);
70 if (!IS_ERR(phy)) {
71 *ptr = phy;
72 devres_add(dev, ptr);
73 } else
74 devres_free(ptr);
75
76 return phy;
77}
78EXPORT_SYMBOL(devm_usb_get_phy);
79
80/**
81 * usb_get_phy - find the USB PHY
82 * @type - the type of the phy the controller requires
83 *
84 * Returns the phy driver, after getting a refcount to it; or
85 * -ENODEV if there is no such phy. The caller is responsible for
86 * calling usb_put_phy() to release that count.
87 *
88 * For use by USB host and peripheral drivers.
89 */
90struct usb_phy *usb_get_phy(enum usb_phy_type type)
91{
92 struct usb_phy *phy = NULL;
93 unsigned long flags;
94
95 spin_lock_irqsave(&phy_lock, flags);
96
97 phy = __usb_find_phy(&phy_list, type);
98 if (IS_ERR(phy)) {
99 pr_err("unable to find transceiver of type %s\n",
100 usb_phy_type_string(type));
101 goto err0;
102 }
103
104 get_device(phy->dev);
105
106err0:
107 spin_unlock_irqrestore(&phy_lock, flags);
108
33 return phy; 109 return phy;
34} 110}
35EXPORT_SYMBOL(usb_get_transceiver); 111EXPORT_SYMBOL(usb_get_phy);
112
113/**
114 * devm_usb_put_phy - release the USB PHY
115 * @dev - device that wants to release this phy
116 * @phy - the phy returned by devm_usb_get_phy()
117 *
118 * destroys the devres associated with this phy and invokes usb_put_phy
119 * to release the phy.
120 *
121 * For use by USB host and peripheral drivers.
122 */
123void devm_usb_put_phy(struct device *dev, struct usb_phy *phy)
124{
125 int r;
126
127 r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy);
128 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
129}
130EXPORT_SYMBOL(devm_usb_put_phy);
36 131
37/** 132/**
38 * usb_put_transceiver - release the (single) USB transceiver 133 * usb_put_phy - release the USB PHY
39 * @x: the transceiver returned by usb_get_transceiver() 134 * @x: the phy returned by usb_get_phy()
40 * 135 *
41 * Releases a refcount the caller received from usb_get_transceiver(). 136 * Releases a refcount the caller received from usb_get_phy().
42 * 137 *
43 * For use by USB host and peripheral drivers. 138 * For use by USB host and peripheral drivers.
44 */ 139 */
45void usb_put_transceiver(struct usb_phy *x) 140void usb_put_phy(struct usb_phy *x)
46{ 141{
47 if (x) 142 if (x)
48 put_device(x->dev); 143 put_device(x->dev);
49} 144}
50EXPORT_SYMBOL(usb_put_transceiver); 145EXPORT_SYMBOL(usb_put_phy);
51 146
52/** 147/**
53 * usb_set_transceiver - declare the (single) USB transceiver 148 * usb_add_phy - declare the USB PHY
54 * @x: the USB transceiver to be used; or NULL 149 * @x: the USB phy to be used; or NULL
150 * @type - the type of this PHY
55 * 151 *
56 * This call is exclusively for use by transceiver drivers, which 152 * This call is exclusively for use by phy drivers, which
57 * coordinate the activities of drivers for host and peripheral 153 * coordinate the activities of drivers for host and peripheral
58 * controllers, and in some cases for VBUS current regulation. 154 * controllers, and in some cases for VBUS current regulation.
59 */ 155 */
60int usb_set_transceiver(struct usb_phy *x) 156int usb_add_phy(struct usb_phy *x, enum usb_phy_type type)
157{
158 int ret = 0;
159 unsigned long flags;
160 struct usb_phy *phy;
161
162 if (x && x->type != USB_PHY_TYPE_UNDEFINED) {
163 dev_err(x->dev, "not accepting initialized PHY %s\n", x->label);
164 return -EINVAL;
165 }
166
167 spin_lock_irqsave(&phy_lock, flags);
168
169 list_for_each_entry(phy, &phy_list, head) {
170 if (phy->type == type) {
171 ret = -EBUSY;
172 dev_err(x->dev, "transceiver type %s already exists\n",
173 usb_phy_type_string(type));
174 goto out;
175 }
176 }
177
178 x->type = type;
179 list_add_tail(&x->head, &phy_list);
180
181out:
182 spin_unlock_irqrestore(&phy_lock, flags);
183 return ret;
184}
185EXPORT_SYMBOL(usb_add_phy);
186
187/**
188 * usb_remove_phy - remove the OTG PHY
189 * @x: the USB OTG PHY to be removed;
190 *
191 * This reverts the effects of usb_add_phy
192 */
193void usb_remove_phy(struct usb_phy *x)
61{ 194{
62 if (phy && x) 195 unsigned long flags;
63 return -EBUSY; 196
64 phy = x; 197 spin_lock_irqsave(&phy_lock, flags);
65 return 0; 198 if (x)
199 list_del(&x->head);
200 spin_unlock_irqrestore(&phy_lock, flags);
66} 201}
67EXPORT_SYMBOL(usb_set_transceiver); 202EXPORT_SYMBOL(usb_remove_phy);
68 203
69const char *otg_state_string(enum usb_otg_state state) 204const char *otg_state_string(enum usb_otg_state state)
70{ 205{
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index c4a86da858e2..523cad5bfea9 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -33,11 +33,11 @@
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
36#include <linux/usb/musb-omap.h>
36#include <linux/usb/ulpi.h> 37#include <linux/usb/ulpi.h>
37#include <linux/i2c/twl.h> 38#include <linux/i2c/twl.h>
38#include <linux/regulator/consumer.h> 39#include <linux/regulator/consumer.h>
39#include <linux/err.h> 40#include <linux/err.h>
40#include <linux/notifier.h>
41#include <linux/slab.h> 41#include <linux/slab.h>
42 42
43/* Register defines */ 43/* Register defines */
@@ -159,7 +159,7 @@ struct twl4030_usb {
159 enum twl4030_usb_mode usb_mode; 159 enum twl4030_usb_mode usb_mode;
160 160
161 int irq; 161 int irq;
162 u8 linkstat; 162 enum omap_musb_vbus_id_status linkstat;
163 bool vbus_supplied; 163 bool vbus_supplied;
164 u8 asleep; 164 u8 asleep;
165 bool irq_enabled; 165 bool irq_enabled;
@@ -246,11 +246,11 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
246 246
247/*-------------------------------------------------------------------------*/ 247/*-------------------------------------------------------------------------*/
248 248
249static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl) 249static enum omap_musb_vbus_id_status
250 twl4030_usb_linkstat(struct twl4030_usb *twl)
250{ 251{
251 int status; 252 int status;
252 int linkstat = USB_EVENT_NONE; 253 enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN;
253 struct usb_otg *otg = twl->phy.otg;
254 254
255 twl->vbus_supplied = false; 255 twl->vbus_supplied = false;
256 256
@@ -273,30 +273,23 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl)
273 twl->vbus_supplied = true; 273 twl->vbus_supplied = true;
274 274
275 if (status & BIT(2)) 275 if (status & BIT(2))
276 linkstat = USB_EVENT_ID; 276 linkstat = OMAP_MUSB_ID_GROUND;
277 else 277 else
278 linkstat = USB_EVENT_VBUS; 278 linkstat = OMAP_MUSB_VBUS_VALID;
279 } else 279 } else {
280 linkstat = USB_EVENT_NONE; 280 if (twl->linkstat != OMAP_MUSB_UNKNOWN)
281 linkstat = OMAP_MUSB_VBUS_OFF;
282 }
281 283
282 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", 284 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
283 status, status, linkstat); 285 status, status, linkstat);
284 286
285 twl->phy.last_event = linkstat;
286
287 /* REVISIT this assumes host and peripheral controllers 287 /* REVISIT this assumes host and peripheral controllers
288 * are registered, and that both are active... 288 * are registered, and that both are active...
289 */ 289 */
290 290
291 spin_lock_irq(&twl->lock); 291 spin_lock_irq(&twl->lock);
292 twl->linkstat = linkstat; 292 twl->linkstat = linkstat;
293 if (linkstat == USB_EVENT_ID) {
294 otg->default_a = true;
295 twl->phy.state = OTG_STATE_A_IDLE;
296 } else {
297 otg->default_a = false;
298 twl->phy.state = OTG_STATE_B_IDLE;
299 }
300 spin_unlock_irq(&twl->lock); 293 spin_unlock_irq(&twl->lock);
301 294
302 return linkstat; 295 return linkstat;
@@ -501,10 +494,10 @@ static DEVICE_ATTR(vbus, 0444, twl4030_usb_vbus_show, NULL);
501static irqreturn_t twl4030_usb_irq(int irq, void *_twl) 494static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
502{ 495{
503 struct twl4030_usb *twl = _twl; 496 struct twl4030_usb *twl = _twl;
504 int status; 497 enum omap_musb_vbus_id_status status;
505 498
506 status = twl4030_usb_linkstat(twl); 499 status = twl4030_usb_linkstat(twl);
507 if (status >= 0) { 500 if (status > 0) {
508 /* FIXME add a set_power() method so that B-devices can 501 /* FIXME add a set_power() method so that B-devices can
509 * configure the charger appropriately. It's not always 502 * configure the charger appropriately. It's not always
510 * correct to consume VBUS power, and how much current to 503 * correct to consume VBUS power, and how much current to
@@ -516,13 +509,13 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
516 * USB_LINK_VBUS state. musb_hdrc won't care until it 509 * USB_LINK_VBUS state. musb_hdrc won't care until it
517 * starts to handle softconnect right. 510 * starts to handle softconnect right.
518 */ 511 */
519 if (status == USB_EVENT_NONE) 512 if (status == OMAP_MUSB_VBUS_OFF ||
513 status == OMAP_MUSB_ID_FLOAT)
520 twl4030_phy_suspend(twl, 0); 514 twl4030_phy_suspend(twl, 0);
521 else 515 else
522 twl4030_phy_resume(twl); 516 twl4030_phy_resume(twl);
523 517
524 atomic_notifier_call_chain(&twl->phy.notifier, status, 518 omap_musb_mailbox(twl->linkstat);
525 twl->phy.otg->gadget);
526 } 519 }
527 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 520 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
528 521
@@ -531,11 +524,12 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
531 524
532static void twl4030_usb_phy_init(struct twl4030_usb *twl) 525static void twl4030_usb_phy_init(struct twl4030_usb *twl)
533{ 526{
534 int status; 527 enum omap_musb_vbus_id_status status;
535 528
536 status = twl4030_usb_linkstat(twl); 529 status = twl4030_usb_linkstat(twl);
537 if (status >= 0) { 530 if (status > 0) {
538 if (status == USB_EVENT_NONE) { 531 if (status == OMAP_MUSB_VBUS_OFF ||
532 status == OMAP_MUSB_ID_FLOAT) {
539 __twl4030_phy_power(twl, 0); 533 __twl4030_phy_power(twl, 0);
540 twl->asleep = 1; 534 twl->asleep = 1;
541 } else { 535 } else {
@@ -543,8 +537,7 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl)
543 twl->asleep = 0; 537 twl->asleep = 0;
544 } 538 }
545 539
546 atomic_notifier_call_chain(&twl->phy.notifier, status, 540 omap_musb_mailbox(twl->linkstat);
547 twl->phy.otg->gadget);
548 } 541 }
549 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 542 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
550} 543}
@@ -598,21 +591,20 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
598 return -EINVAL; 591 return -EINVAL;
599 } 592 }
600 593
601 twl = kzalloc(sizeof *twl, GFP_KERNEL); 594 twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL);
602 if (!twl) 595 if (!twl)
603 return -ENOMEM; 596 return -ENOMEM;
604 597
605 otg = kzalloc(sizeof *otg, GFP_KERNEL); 598 otg = devm_kzalloc(&pdev->dev, sizeof *otg, GFP_KERNEL);
606 if (!otg) { 599 if (!otg)
607 kfree(twl);
608 return -ENOMEM; 600 return -ENOMEM;
609 }
610 601
611 twl->dev = &pdev->dev; 602 twl->dev = &pdev->dev;
612 twl->irq = platform_get_irq(pdev, 0); 603 twl->irq = platform_get_irq(pdev, 0);
613 twl->usb_mode = pdata->usb_mode; 604 twl->usb_mode = pdata->usb_mode;
614 twl->vbus_supplied = false; 605 twl->vbus_supplied = false;
615 twl->asleep = 1; 606 twl->asleep = 1;
607 twl->linkstat = OMAP_MUSB_UNKNOWN;
616 608
617 twl->phy.dev = twl->dev; 609 twl->phy.dev = twl->dev;
618 twl->phy.label = "twl4030"; 610 twl->phy.label = "twl4030";
@@ -629,18 +621,14 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
629 err = twl4030_usb_ldo_init(twl); 621 err = twl4030_usb_ldo_init(twl);
630 if (err) { 622 if (err) {
631 dev_err(&pdev->dev, "ldo init failed\n"); 623 dev_err(&pdev->dev, "ldo init failed\n");
632 kfree(otg);
633 kfree(twl);
634 return err; 624 return err;
635 } 625 }
636 usb_set_transceiver(&twl->phy); 626 usb_add_phy(&twl->phy, USB_PHY_TYPE_USB2);
637 627
638 platform_set_drvdata(pdev, twl); 628 platform_set_drvdata(pdev, twl);
639 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 629 if (device_create_file(&pdev->dev, &dev_attr_vbus))
640 dev_warn(&pdev->dev, "could not create sysfs file\n"); 630 dev_warn(&pdev->dev, "could not create sysfs file\n");
641 631
642 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier);
643
644 /* Our job is to use irqs and status from the power module 632 /* Our job is to use irqs and status from the power module
645 * to keep the transceiver disabled when nothing's connected. 633 * to keep the transceiver disabled when nothing's connected.
646 * 634 *
@@ -651,13 +639,11 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
651 */ 639 */
652 twl->irq_enabled = true; 640 twl->irq_enabled = true;
653 status = request_threaded_irq(twl->irq, NULL, twl4030_usb_irq, 641 status = request_threaded_irq(twl->irq, NULL, twl4030_usb_irq,
654 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 642 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
655 "twl4030_usb", twl); 643 IRQF_ONESHOT, "twl4030_usb", twl);
656 if (status < 0) { 644 if (status < 0) {
657 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", 645 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n",
658 twl->irq, status); 646 twl->irq, status);
659 kfree(otg);
660 kfree(twl);
661 return status; 647 return status;
662 } 648 }
663 649
@@ -701,9 +687,6 @@ static int __exit twl4030_usb_remove(struct platform_device *pdev)
701 regulator_put(twl->usb1v8); 687 regulator_put(twl->usb1v8);
702 regulator_put(twl->usb3v1); 688 regulator_put(twl->usb3v1);
703 689
704 kfree(twl->phy.otg);
705 kfree(twl);
706
707 return 0; 690 return 0;
708} 691}
709 692
diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/otg/twl6030-usb.c
index 0eabb049b6a9..6907d8df7a27 100644
--- a/drivers/usb/otg/twl6030-usb.c
+++ b/drivers/usb/otg/twl6030-usb.c
@@ -26,10 +26,10 @@
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/usb/otg.h> 28#include <linux/usb/otg.h>
29#include <linux/usb/musb-omap.h>
29#include <linux/i2c/twl.h> 30#include <linux/i2c/twl.h>
30#include <linux/regulator/consumer.h> 31#include <linux/regulator/consumer.h>
31#include <linux/err.h> 32#include <linux/err.h>
32#include <linux/notifier.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35 35
@@ -100,7 +100,7 @@ struct twl6030_usb {
100 100
101 int irq1; 101 int irq1;
102 int irq2; 102 int irq2;
103 u8 linkstat; 103 enum omap_musb_vbus_id_status linkstat;
104 u8 asleep; 104 u8 asleep;
105 bool irq_enabled; 105 bool irq_enabled;
106 bool vbus_enable; 106 bool vbus_enable;
@@ -147,7 +147,7 @@ static int twl6030_phy_init(struct usb_phy *x)
147 dev = twl->dev; 147 dev = twl->dev;
148 pdata = dev->platform_data; 148 pdata = dev->platform_data;
149 149
150 if (twl->linkstat == USB_EVENT_ID) 150 if (twl->linkstat == OMAP_MUSB_ID_GROUND)
151 pdata->phy_power(twl->dev, 1, 1); 151 pdata->phy_power(twl->dev, 1, 1);
152 else 152 else
153 pdata->phy_power(twl->dev, 0, 1); 153 pdata->phy_power(twl->dev, 0, 1);
@@ -235,13 +235,13 @@ static ssize_t twl6030_usb_vbus_show(struct device *dev,
235 spin_lock_irqsave(&twl->lock, flags); 235 spin_lock_irqsave(&twl->lock, flags);
236 236
237 switch (twl->linkstat) { 237 switch (twl->linkstat) {
238 case USB_EVENT_VBUS: 238 case OMAP_MUSB_VBUS_VALID:
239 ret = snprintf(buf, PAGE_SIZE, "vbus\n"); 239 ret = snprintf(buf, PAGE_SIZE, "vbus\n");
240 break; 240 break;
241 case USB_EVENT_ID: 241 case OMAP_MUSB_ID_GROUND:
242 ret = snprintf(buf, PAGE_SIZE, "id\n"); 242 ret = snprintf(buf, PAGE_SIZE, "id\n");
243 break; 243 break;
244 case USB_EVENT_NONE: 244 case OMAP_MUSB_VBUS_OFF:
245 ret = snprintf(buf, PAGE_SIZE, "none\n"); 245 ret = snprintf(buf, PAGE_SIZE, "none\n");
246 break; 246 break;
247 default: 247 default:
@@ -256,8 +256,7 @@ static DEVICE_ATTR(vbus, 0444, twl6030_usb_vbus_show, NULL);
256static irqreturn_t twl6030_usb_irq(int irq, void *_twl) 256static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
257{ 257{
258 struct twl6030_usb *twl = _twl; 258 struct twl6030_usb *twl = _twl;
259 struct usb_otg *otg = twl->phy.otg; 259 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
260 int status;
261 u8 vbus_state, hw_state; 260 u8 vbus_state, hw_state;
262 261
263 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); 262 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
@@ -268,22 +267,18 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
268 if (vbus_state & VBUS_DET) { 267 if (vbus_state & VBUS_DET) {
269 regulator_enable(twl->usb3v3); 268 regulator_enable(twl->usb3v3);
270 twl->asleep = 1; 269 twl->asleep = 1;
271 status = USB_EVENT_VBUS; 270 status = OMAP_MUSB_VBUS_VALID;
272 otg->default_a = false;
273 twl->phy.state = OTG_STATE_B_IDLE;
274 twl->linkstat = status; 271 twl->linkstat = status;
275 twl->phy.last_event = status; 272 omap_musb_mailbox(status);
276 atomic_notifier_call_chain(&twl->phy.notifier,
277 status, otg->gadget);
278 } else { 273 } else {
279 status = USB_EVENT_NONE; 274 if (twl->linkstat != OMAP_MUSB_UNKNOWN) {
280 twl->linkstat = status; 275 status = OMAP_MUSB_VBUS_OFF;
281 twl->phy.last_event = status; 276 twl->linkstat = status;
282 atomic_notifier_call_chain(&twl->phy.notifier, 277 omap_musb_mailbox(status);
283 status, otg->gadget); 278 if (twl->asleep) {
284 if (twl->asleep) { 279 regulator_disable(twl->usb3v3);
285 regulator_disable(twl->usb3v3); 280 twl->asleep = 0;
286 twl->asleep = 0; 281 }
287 } 282 }
288 } 283 }
289 } 284 }
@@ -295,8 +290,7 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
295static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl) 290static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
296{ 291{
297 struct twl6030_usb *twl = _twl; 292 struct twl6030_usb *twl = _twl;
298 struct usb_otg *otg = twl->phy.otg; 293 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
299 int status = USB_EVENT_NONE;
300 u8 hw_state; 294 u8 hw_state;
301 295
302 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); 296 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
@@ -307,13 +301,9 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
307 twl->asleep = 1; 301 twl->asleep = 1;
308 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR); 302 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR);
309 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET); 303 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET);
310 status = USB_EVENT_ID; 304 status = OMAP_MUSB_ID_GROUND;
311 otg->default_a = true;
312 twl->phy.state = OTG_STATE_A_IDLE;
313 twl->linkstat = status; 305 twl->linkstat = status;
314 twl->phy.last_event = status; 306 omap_musb_mailbox(status);
315 atomic_notifier_call_chain(&twl->phy.notifier, status,
316 otg->gadget);
317 } else { 307 } else {
318 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_CLR); 308 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_CLR);
319 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET); 309 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET);
@@ -402,20 +392,19 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
402 struct device *dev = &pdev->dev; 392 struct device *dev = &pdev->dev;
403 pdata = dev->platform_data; 393 pdata = dev->platform_data;
404 394
405 twl = kzalloc(sizeof *twl, GFP_KERNEL); 395 twl = devm_kzalloc(dev, sizeof *twl, GFP_KERNEL);
406 if (!twl) 396 if (!twl)
407 return -ENOMEM; 397 return -ENOMEM;
408 398
409 otg = kzalloc(sizeof *otg, GFP_KERNEL); 399 otg = devm_kzalloc(dev, sizeof *otg, GFP_KERNEL);
410 if (!otg) { 400 if (!otg)
411 kfree(twl);
412 return -ENOMEM; 401 return -ENOMEM;
413 }
414 402
415 twl->dev = &pdev->dev; 403 twl->dev = &pdev->dev;
416 twl->irq1 = platform_get_irq(pdev, 0); 404 twl->irq1 = platform_get_irq(pdev, 0);
417 twl->irq2 = platform_get_irq(pdev, 1); 405 twl->irq2 = platform_get_irq(pdev, 1);
418 twl->features = pdata->features; 406 twl->features = pdata->features;
407 twl->linkstat = OMAP_MUSB_UNKNOWN;
419 408
420 twl->phy.dev = twl->dev; 409 twl->phy.dev = twl->dev;
421 twl->phy.label = "twl6030"; 410 twl->phy.label = "twl6030";
@@ -436,18 +425,14 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
436 err = twl6030_usb_ldo_init(twl); 425 err = twl6030_usb_ldo_init(twl);
437 if (err) { 426 if (err) {
438 dev_err(&pdev->dev, "ldo init failed\n"); 427 dev_err(&pdev->dev, "ldo init failed\n");
439 kfree(otg);
440 kfree(twl);
441 return err; 428 return err;
442 } 429 }
443 usb_set_transceiver(&twl->phy); 430 usb_add_phy(&twl->phy, USB_PHY_TYPE_USB2);
444 431
445 platform_set_drvdata(pdev, twl); 432 platform_set_drvdata(pdev, twl);
446 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 433 if (device_create_file(&pdev->dev, &dev_attr_vbus))
447 dev_warn(&pdev->dev, "could not create sysfs file\n"); 434 dev_warn(&pdev->dev, "could not create sysfs file\n");
448 435
449 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier);
450
451 INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work); 436 INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
452 437
453 twl->irq_enabled = true; 438 twl->irq_enabled = true;
@@ -458,8 +443,6 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
458 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", 443 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
459 twl->irq1, status); 444 twl->irq1, status);
460 device_remove_file(twl->dev, &dev_attr_vbus); 445 device_remove_file(twl->dev, &dev_attr_vbus);
461 kfree(otg);
462 kfree(twl);
463 return status; 446 return status;
464 } 447 }
465 448
@@ -471,8 +454,6 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
471 twl->irq2, status); 454 twl->irq2, status);
472 free_irq(twl->irq1, twl); 455 free_irq(twl->irq1, twl);
473 device_remove_file(twl->dev, &dev_attr_vbus); 456 device_remove_file(twl->dev, &dev_attr_vbus);
474 kfree(otg);
475 kfree(twl);
476 return status; 457 return status;
477 } 458 }
478 459
@@ -503,8 +484,6 @@ static int __exit twl6030_usb_remove(struct platform_device *pdev)
503 pdata->phy_exit(twl->dev); 484 pdata->phy_exit(twl->dev);
504 device_remove_file(twl->dev, &dev_attr_vbus); 485 device_remove_file(twl->dev, &dev_attr_vbus);
505 cancel_work_sync(&twl->set_vbus_work); 486 cancel_work_sync(&twl->set_vbus_work);
506 kfree(twl->phy.otg);
507 kfree(twl);
508 487
509 return 0; 488 return 0;
510} 489}
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index 6ec7f838d7fa..d5272d4714ce 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -771,22 +771,15 @@ static void xfer_work(struct work_struct *work)
771 struct usbhs_pipe *pipe = pkt->pipe; 771 struct usbhs_pipe *pipe = pkt->pipe;
772 struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe); 772 struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe);
773 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); 773 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
774 struct scatterlist sg;
775 struct dma_async_tx_descriptor *desc; 774 struct dma_async_tx_descriptor *desc;
776 struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt); 775 struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt);
777 struct device *dev = usbhs_priv_to_dev(priv); 776 struct device *dev = usbhs_priv_to_dev(priv);
778 enum dma_transfer_direction dir; 777 enum dma_transfer_direction dir;
779 dma_cookie_t cookie;
780 778
781 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV; 779 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV;
782 780
783 sg_init_table(&sg, 1); 781 desc = dmaengine_prep_slave_single(chan, pkt->dma + pkt->actual,
784 sg_set_page(&sg, virt_to_page(pkt->dma), 782 pkt->trans, dir,
785 pkt->length, offset_in_page(pkt->dma));
786 sg_dma_address(&sg) = pkt->dma + pkt->actual;
787 sg_dma_len(&sg) = pkt->trans;
788
789 desc = dmaengine_prep_slave_sg(chan, &sg, 1, dir,
790 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 783 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
791 if (!desc) 784 if (!desc)
792 return; 785 return;
@@ -794,8 +787,7 @@ static void xfer_work(struct work_struct *work)
794 desc->callback = usbhsf_dma_complete; 787 desc->callback = usbhsf_dma_complete;
795 desc->callback_param = pipe; 788 desc->callback_param = pipe;
796 789
797 cookie = desc->tx_submit(desc); 790 if (dmaengine_submit(desc) < 0) {
798 if (cookie < 0) {
799 dev_err(dev, "Failed to submit dma descriptor\n"); 791 dev_err(dev, "Failed to submit dma descriptor\n");
800 return; 792 return;
801 } 793 }
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index a1b99243dac9..9a0ca8355905 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1036,15 +1036,12 @@ static int keyspan_write_room(struct tty_struct *tty)
1036static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port) 1036static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1037{ 1037{
1038 struct keyspan_port_private *p_priv; 1038 struct keyspan_port_private *p_priv;
1039 struct keyspan_serial_private *s_priv;
1040 struct usb_serial *serial = port->serial;
1041 const struct keyspan_device_details *d_details; 1039 const struct keyspan_device_details *d_details;
1042 int i, err; 1040 int i, err;
1043 int baud_rate, device_port; 1041 int baud_rate, device_port;
1044 struct urb *urb; 1042 struct urb *urb;
1045 unsigned int cflag = 0; 1043 unsigned int cflag = 0;
1046 1044
1047 s_priv = usb_get_serial_data(serial);
1048 p_priv = usb_get_serial_port_data(port); 1045 p_priv = usb_get_serial_port_data(port);
1049 d_details = p_priv->device_details; 1046 d_details = p_priv->device_details;
1050 1047
@@ -1130,10 +1127,8 @@ static void keyspan_close(struct usb_serial_port *port)
1130{ 1127{
1131 int i; 1128 int i;
1132 struct usb_serial *serial = port->serial; 1129 struct usb_serial *serial = port->serial;
1133 struct keyspan_serial_private *s_priv;
1134 struct keyspan_port_private *p_priv; 1130 struct keyspan_port_private *p_priv;
1135 1131
1136 s_priv = usb_get_serial_data(serial);
1137 p_priv = usb_get_serial_port_data(port); 1132 p_priv = usb_get_serial_port_data(port);
1138 1133
1139 p_priv->rts_state = 0; 1134 p_priv->rts_state = 0;
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 417ab1b0aa30..2b0c88da7828 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -1310,6 +1310,10 @@ static struct usb_serial_driver * const serial_drivers[] = {
1310 1310
1311static bool debug; 1311static bool debug;
1312 1312
1313struct option_private {
1314 u8 bInterfaceNumber;
1315};
1316
1313module_usb_serial_driver(serial_drivers, option_ids); 1317module_usb_serial_driver(serial_drivers, option_ids);
1314 1318
1315static bool is_blacklisted(const u8 ifnum, enum option_blacklist_reason reason, 1319static bool is_blacklisted(const u8 ifnum, enum option_blacklist_reason reason,
@@ -1340,51 +1344,78 @@ static int option_probe(struct usb_serial *serial,
1340 const struct usb_device_id *id) 1344 const struct usb_device_id *id)
1341{ 1345{
1342 struct usb_wwan_intf_private *data; 1346 struct usb_wwan_intf_private *data;
1343 1347 struct option_private *priv;
1344 /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */ 1348 struct usb_interface_descriptor *iface_desc =
1345 if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID && 1349 &serial->interface->cur_altsetting->desc;
1346 serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 && 1350 struct usb_device_descriptor *dev_desc = &serial->dev->descriptor;
1347 serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8) 1351
1352 /*
1353 * D-Link DWM 652 still exposes CD-Rom emulation interface in modem
1354 * mode.
1355 */
1356 if (dev_desc->idVendor == DLINK_VENDOR_ID &&
1357 dev_desc->idProduct == DLINK_PRODUCT_DWM_652 &&
1358 iface_desc->bInterfaceClass == 0x08)
1348 return -ENODEV; 1359 return -ENODEV;
1349 1360
1350 /* Bandrich modem and AT command interface is 0xff */ 1361 /* Bandrich modem and AT command interface is 0xff */
1351 if ((serial->dev->descriptor.idVendor == BANDRICH_VENDOR_ID || 1362 if ((dev_desc->idVendor == BANDRICH_VENDOR_ID ||
1352 serial->dev->descriptor.idVendor == PIRELLI_VENDOR_ID) && 1363 dev_desc->idVendor == PIRELLI_VENDOR_ID) &&
1353 serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff) 1364 iface_desc->bInterfaceClass != 0xff)
1354 return -ENODEV; 1365 return -ENODEV;
1355 1366 /*
1356 /* Don't bind reserved interfaces (like network ones) which often have 1367 * Don't bind reserved interfaces (like network ones) which often have
1357 * the same class/subclass/protocol as the serial interfaces. Look at 1368 * the same class/subclass/protocol as the serial interfaces. Look at
1358 * the Windows driver .INF files for reserved interface numbers. 1369 * the Windows driver .INF files for reserved interface numbers.
1359 */ 1370 */
1360 if (is_blacklisted( 1371 if (is_blacklisted(
1361 serial->interface->cur_altsetting->desc.bInterfaceNumber, 1372 iface_desc->bInterfaceNumber,
1362 OPTION_BLACKLIST_RESERVED_IF, 1373 OPTION_BLACKLIST_RESERVED_IF,
1363 (const struct option_blacklist_info *) id->driver_info)) 1374 (const struct option_blacklist_info *) id->driver_info))
1364 return -ENODEV; 1375 return -ENODEV;
1365 1376 /*
1366 /* Don't bind network interface on Samsung GT-B3730, it is handled by a separate module */ 1377 * Don't bind network interface on Samsung GT-B3730, it is handled by
1367 if (serial->dev->descriptor.idVendor == SAMSUNG_VENDOR_ID && 1378 * a separate module.
1368 serial->dev->descriptor.idProduct == SAMSUNG_PRODUCT_GT_B3730 && 1379 */
1369 serial->interface->cur_altsetting->desc.bInterfaceClass != USB_CLASS_CDC_DATA) 1380 if (dev_desc->idVendor == SAMSUNG_VENDOR_ID &&
1381 dev_desc->idProduct == SAMSUNG_PRODUCT_GT_B3730 &&
1382 iface_desc->bInterfaceClass != USB_CLASS_CDC_DATA)
1370 return -ENODEV; 1383 return -ENODEV;
1371 1384
1372 data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL); 1385 data = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL);
1373 if (!data) 1386 if (!data)
1374 return -ENOMEM; 1387 return -ENOMEM;
1375 data->send_setup = option_send_setup; 1388
1389 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1390 if (!priv) {
1391 kfree(data);
1392 return -ENOMEM;
1393 }
1394
1395 priv->bInterfaceNumber = iface_desc->bInterfaceNumber;
1396 data->private = priv;
1397
1398 if (!is_blacklisted(iface_desc->bInterfaceNumber,
1399 OPTION_BLACKLIST_SENDSETUP,
1400 (struct option_blacklist_info *)id->driver_info)) {
1401 data->send_setup = option_send_setup;
1402 }
1376 spin_lock_init(&data->susp_lock); 1403 spin_lock_init(&data->susp_lock);
1377 data->private = (void *)id->driver_info; 1404
1405 usb_set_serial_data(serial, data);
1406
1378 return 0; 1407 return 0;
1379} 1408}
1380 1409
1381static void option_release(struct usb_serial *serial) 1410static void option_release(struct usb_serial *serial)
1382{ 1411{
1383 struct usb_wwan_intf_private *priv = usb_get_serial_data(serial); 1412 struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial);
1413 struct option_private *priv = intfdata->private;
1384 1414
1385 usb_wwan_release(serial); 1415 usb_wwan_release(serial);
1386 1416
1387 kfree(priv); 1417 kfree(priv);
1418 kfree(intfdata);
1388} 1419}
1389 1420
1390static void option_instat_callback(struct urb *urb) 1421static void option_instat_callback(struct urb *urb)
@@ -1451,18 +1482,11 @@ static void option_instat_callback(struct urb *urb)
1451static int option_send_setup(struct usb_serial_port *port) 1482static int option_send_setup(struct usb_serial_port *port)
1452{ 1483{
1453 struct usb_serial *serial = port->serial; 1484 struct usb_serial *serial = port->serial;
1454 struct usb_wwan_intf_private *intfdata = 1485 struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial);
1455 (struct usb_wwan_intf_private *) serial->private; 1486 struct option_private *priv = intfdata->private;
1456 struct usb_wwan_port_private *portdata; 1487 struct usb_wwan_port_private *portdata;
1457 int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
1458 int val = 0; 1488 int val = 0;
1459 1489
1460 if (is_blacklisted(ifNum, OPTION_BLACKLIST_SENDSETUP,
1461 (struct option_blacklist_info *) intfdata->private)) {
1462 dbg("No send_setup on blacklisted interface #%d\n", ifNum);
1463 return -EIO;
1464 }
1465
1466 portdata = usb_get_serial_port_data(port); 1490 portdata = usb_get_serial_port_data(port);
1467 1491
1468 if (portdata->dtr_state) 1492 if (portdata->dtr_state)
@@ -1470,9 +1494,9 @@ static int option_send_setup(struct usb_serial_port *port)
1470 if (portdata->rts_state) 1494 if (portdata->rts_state)
1471 val |= 0x02; 1495 val |= 0x02;
1472 1496
1473 return usb_control_msg(serial->dev, 1497 return usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
1474 usb_rcvctrlpipe(serial->dev, 0), 1498 0x22, 0x21, val, priv->bInterfaceNumber, NULL,
1475 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT); 1499 0, USB_CTRL_SET_TIMEOUT);
1476} 1500}
1477 1501
1478MODULE_AUTHOR(DRIVER_AUTHOR); 1502MODULE_AUTHOR(DRIVER_AUTHOR);
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
index 8dd88ebe9863..151670b6b72a 100644
--- a/drivers/usb/serial/quatech2.c
+++ b/drivers/usb/serial/quatech2.c
@@ -345,7 +345,6 @@ static void qt2_set_termios(struct tty_struct *tty,
345static int qt2_open(struct tty_struct *tty, struct usb_serial_port *port) 345static int qt2_open(struct tty_struct *tty, struct usb_serial_port *port)
346{ 346{
347 struct usb_serial *serial; 347 struct usb_serial *serial;
348 struct qt2_serial_private *serial_priv;
349 struct qt2_port_private *port_priv; 348 struct qt2_port_private *port_priv;
350 u8 *data; 349 u8 *data;
351 u16 device_port; 350 u16 device_port;
@@ -357,7 +356,6 @@ static int qt2_open(struct tty_struct *tty, struct usb_serial_port *port)
357 serial = port->serial; 356 serial = port->serial;
358 357
359 port_priv = usb_get_serial_port_data(port); 358 port_priv = usb_get_serial_port_data(port);
360 serial_priv = usb_get_serial_data(serial);
361 359
362 /* set the port to RS232 mode */ 360 /* set the port to RS232 mode */
363 status = qt2_control_msg(serial->dev, QT2_GET_SET_QMCR, 361 status = qt2_control_msg(serial->dev, QT2_GET_SET_QMCR,
@@ -417,13 +415,11 @@ static int qt2_open(struct tty_struct *tty, struct usb_serial_port *port)
417static void qt2_close(struct usb_serial_port *port) 415static void qt2_close(struct usb_serial_port *port)
418{ 416{
419 struct usb_serial *serial; 417 struct usb_serial *serial;
420 struct qt2_serial_private *serial_priv;
421 struct qt2_port_private *port_priv; 418 struct qt2_port_private *port_priv;
422 unsigned long flags; 419 unsigned long flags;
423 int i; 420 int i;
424 421
425 serial = port->serial; 422 serial = port->serial;
426 serial_priv = usb_get_serial_data(serial);
427 port_priv = usb_get_serial_port_data(port); 423 port_priv = usb_get_serial_port_data(port);
428 424
429 port_priv->is_open = false; 425 port_priv->is_open = false;
diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c
index 82dd834709c7..5dfb4c36a1b0 100644
--- a/drivers/usb/storage/protocol.c
+++ b/drivers/usb/storage/protocol.c
@@ -66,7 +66,7 @@ void usb_stor_pad12_command(struct scsi_cmnd *srb, struct us_data *us)
66 * NOTE: This only works because a scsi_cmnd struct field contains 66 * NOTE: This only works because a scsi_cmnd struct field contains
67 * a unsigned char cmnd[16], so we know we have storage available 67 * a unsigned char cmnd[16], so we know we have storage available
68 */ 68 */
69 for (; srb->cmd_len<12; srb->cmd_len++) 69 for (; srb->cmd_len < 12; srb->cmd_len++)
70 srb->cmnd[srb->cmd_len] = 0; 70 srb->cmnd[srb->cmd_len] = 0;
71 71
72 /* send the command to the transport layer */ 72 /* send the command to the transport layer */
@@ -76,14 +76,14 @@ void usb_stor_pad12_command(struct scsi_cmnd *srb, struct us_data *us)
76void usb_stor_ufi_command(struct scsi_cmnd *srb, struct us_data *us) 76void usb_stor_ufi_command(struct scsi_cmnd *srb, struct us_data *us)
77{ 77{
78 /* fix some commands -- this is a form of mode translation 78 /* fix some commands -- this is a form of mode translation
79 * UFI devices only accept 12 byte long commands 79 * UFI devices only accept 12 byte long commands
80 * 80 *
81 * NOTE: This only works because a scsi_cmnd struct field contains 81 * NOTE: This only works because a scsi_cmnd struct field contains
82 * a unsigned char cmnd[16], so we know we have storage available 82 * a unsigned char cmnd[16], so we know we have storage available
83 */ 83 */
84 84
85 /* Pad the ATAPI command with zeros */ 85 /* Pad the ATAPI command with zeros */
86 for (; srb->cmd_len<12; srb->cmd_len++) 86 for (; srb->cmd_len < 12; srb->cmd_len++)
87 srb->cmnd[srb->cmd_len] = 0; 87 srb->cmnd[srb->cmd_len] = 0;
88 88
89 /* set command length to 12 bytes (this affects the transport layer) */ 89 /* set command length to 12 bytes (this affects the transport layer) */
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 8ec8a6e66f50..638cd64f9610 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -41,16 +41,17 @@ struct sense_iu_old {
41struct uas_dev_info { 41struct uas_dev_info {
42 struct usb_interface *intf; 42 struct usb_interface *intf;
43 struct usb_device *udev; 43 struct usb_device *udev;
44 int qdepth; 44 struct usb_anchor sense_urbs;
45 struct usb_anchor data_urbs;
46 int qdepth, resetting;
47 struct response_ui response;
45 unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe; 48 unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe;
46 unsigned use_streams:1; 49 unsigned use_streams:1;
47 unsigned uas_sense_old:1; 50 unsigned uas_sense_old:1;
48 struct scsi_cmnd *cmnd; 51 struct scsi_cmnd *cmnd;
49 struct urb *status_urb; /* used only if stream support is available */
50}; 52};
51 53
52enum { 54enum {
53 ALLOC_STATUS_URB = (1 << 0),
54 SUBMIT_STATUS_URB = (1 << 1), 55 SUBMIT_STATUS_URB = (1 << 1),
55 ALLOC_DATA_IN_URB = (1 << 2), 56 ALLOC_DATA_IN_URB = (1 << 2),
56 SUBMIT_DATA_IN_URB = (1 << 3), 57 SUBMIT_DATA_IN_URB = (1 << 3),
@@ -58,18 +59,18 @@ enum {
58 SUBMIT_DATA_OUT_URB = (1 << 5), 59 SUBMIT_DATA_OUT_URB = (1 << 5),
59 ALLOC_CMD_URB = (1 << 6), 60 ALLOC_CMD_URB = (1 << 6),
60 SUBMIT_CMD_URB = (1 << 7), 61 SUBMIT_CMD_URB = (1 << 7),
61 COMPLETED_DATA_IN = (1 << 8), 62 COMMAND_INFLIGHT = (1 << 8),
62 COMPLETED_DATA_OUT = (1 << 9), 63 DATA_IN_URB_INFLIGHT = (1 << 9),
63 DATA_COMPLETES_CMD = (1 << 10), 64 DATA_OUT_URB_INFLIGHT = (1 << 10),
65 COMMAND_COMPLETED = (1 << 11),
64}; 66};
65 67
66/* Overrides scsi_pointer */ 68/* Overrides scsi_pointer */
67struct uas_cmd_info { 69struct uas_cmd_info {
68 unsigned int state; 70 unsigned int state;
69 unsigned int stream; 71 unsigned int stream;
72 unsigned int aborted;
70 struct urb *cmd_urb; 73 struct urb *cmd_urb;
71 /* status_urb is used only if stream support isn't available */
72 struct urb *status_urb;
73 struct urb *data_in_urb; 74 struct urb *data_in_urb;
74 struct urb *data_out_urb; 75 struct urb *data_out_urb;
75 struct list_head list; 76 struct list_head list;
@@ -114,7 +115,6 @@ static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd)
114{ 115{
115 struct sense_iu *sense_iu = urb->transfer_buffer; 116 struct sense_iu *sense_iu = urb->transfer_buffer;
116 struct scsi_device *sdev = cmnd->device; 117 struct scsi_device *sdev = cmnd->device;
117 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
118 118
119 if (urb->actual_length > 16) { 119 if (urb->actual_length > 16) {
120 unsigned len = be16_to_cpup(&sense_iu->len); 120 unsigned len = be16_to_cpup(&sense_iu->len);
@@ -132,15 +132,12 @@ static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd)
132 } 132 }
133 133
134 cmnd->result = sense_iu->status; 134 cmnd->result = sense_iu->status;
135 if (!(cmdinfo->state & DATA_COMPLETES_CMD))
136 cmnd->scsi_done(cmnd);
137} 135}
138 136
139static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd) 137static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd)
140{ 138{
141 struct sense_iu_old *sense_iu = urb->transfer_buffer; 139 struct sense_iu_old *sense_iu = urb->transfer_buffer;
142 struct scsi_device *sdev = cmnd->device; 140 struct scsi_device *sdev = cmnd->device;
143 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
144 141
145 if (urb->actual_length > 8) { 142 if (urb->actual_length > 8) {
146 unsigned len = be16_to_cpup(&sense_iu->len) - 2; 143 unsigned len = be16_to_cpup(&sense_iu->len) - 2;
@@ -158,17 +155,51 @@ static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd)
158 } 155 }
159 156
160 cmnd->result = sense_iu->status; 157 cmnd->result = sense_iu->status;
161 if (!(cmdinfo->state & DATA_COMPLETES_CMD)) 158}
162 cmnd->scsi_done(cmnd); 159
160static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *caller)
161{
162 struct uas_cmd_info *ci = (void *)&cmnd->SCp;
163
164 scmd_printk(KERN_INFO, cmnd, "%s %p tag %d, inflight:"
165 "%s%s%s%s%s%s%s%s%s%s%s\n",
166 caller, cmnd, cmnd->request->tag,
167 (ci->state & SUBMIT_STATUS_URB) ? " s-st" : "",
168 (ci->state & ALLOC_DATA_IN_URB) ? " a-in" : "",
169 (ci->state & SUBMIT_DATA_IN_URB) ? " s-in" : "",
170 (ci->state & ALLOC_DATA_OUT_URB) ? " a-out" : "",
171 (ci->state & SUBMIT_DATA_OUT_URB) ? " s-out" : "",
172 (ci->state & ALLOC_CMD_URB) ? " a-cmd" : "",
173 (ci->state & SUBMIT_CMD_URB) ? " s-cmd" : "",
174 (ci->state & COMMAND_INFLIGHT) ? " CMD" : "",
175 (ci->state & DATA_IN_URB_INFLIGHT) ? " IN" : "",
176 (ci->state & DATA_OUT_URB_INFLIGHT) ? " OUT" : "",
177 (ci->state & COMMAND_COMPLETED) ? " done" : "");
178}
179
180static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller)
181{
182 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
183
184 if (cmdinfo->state & (COMMAND_INFLIGHT |
185 DATA_IN_URB_INFLIGHT |
186 DATA_OUT_URB_INFLIGHT))
187 return -EBUSY;
188 BUG_ON(cmdinfo->state & COMMAND_COMPLETED);
189 cmdinfo->state |= COMMAND_COMPLETED;
190 usb_free_urb(cmdinfo->data_in_urb);
191 usb_free_urb(cmdinfo->data_out_urb);
192 cmnd->scsi_done(cmnd);
193 return 0;
163} 194}
164 195
165static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd, 196static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd,
166 unsigned direction) 197 unsigned direction)
167{ 198{
168 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; 199 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
169 int err; 200 int err;
170 201
171 cmdinfo->state = direction; 202 cmdinfo->state |= direction | SUBMIT_STATUS_URB;
172 err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC); 203 err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC);
173 if (err) { 204 if (err) {
174 spin_lock(&uas_work_lock); 205 spin_lock(&uas_work_lock);
@@ -186,12 +217,15 @@ static void uas_stat_cmplt(struct urb *urb)
186 struct scsi_cmnd *cmnd; 217 struct scsi_cmnd *cmnd;
187 struct uas_cmd_info *cmdinfo; 218 struct uas_cmd_info *cmdinfo;
188 u16 tag; 219 u16 tag;
189 int ret;
190 220
191 if (urb->status) { 221 if (urb->status) {
192 dev_err(&urb->dev->dev, "URB BAD STATUS %d\n", urb->status); 222 dev_err(&urb->dev->dev, "URB BAD STATUS %d\n", urb->status);
193 if (devinfo->use_streams) 223 usb_free_urb(urb);
194 usb_free_urb(urb); 224 return;
225 }
226
227 if (devinfo->resetting) {
228 usb_free_urb(urb);
195 return; 229 return;
196 } 230 }
197 231
@@ -201,47 +235,34 @@ static void uas_stat_cmplt(struct urb *urb)
201 else 235 else
202 cmnd = scsi_host_find_tag(shost, tag - 1); 236 cmnd = scsi_host_find_tag(shost, tag - 1);
203 if (!cmnd) { 237 if (!cmnd) {
204 if (devinfo->use_streams) { 238 if (iu->iu_id != IU_ID_RESPONSE) {
205 usb_free_urb(urb); 239 usb_free_urb(urb);
206 return; 240 return;
207 } 241 }
208 ret = usb_submit_urb(urb, GFP_ATOMIC); 242 } else {
209 if (ret) 243 cmdinfo = (void *)&cmnd->SCp;
210 dev_err(&urb->dev->dev, "failed submit status urb\n");
211 return;
212 } 244 }
213 cmdinfo = (void *)&cmnd->SCp;
214 245
215 switch (iu->iu_id) { 246 switch (iu->iu_id) {
216 case IU_ID_STATUS: 247 case IU_ID_STATUS:
217 if (devinfo->cmnd == cmnd) 248 if (devinfo->cmnd == cmnd)
218 devinfo->cmnd = NULL; 249 devinfo->cmnd = NULL;
219 250
220 if (!(cmdinfo->state & COMPLETED_DATA_IN) &&
221 cmdinfo->data_in_urb) {
222 if (devinfo->use_streams) {
223 cmdinfo->state |= DATA_COMPLETES_CMD;
224 usb_unlink_urb(cmdinfo->data_in_urb);
225 } else {
226 usb_free_urb(cmdinfo->data_in_urb);
227 }
228 }
229 if (!(cmdinfo->state & COMPLETED_DATA_OUT) &&
230 cmdinfo->data_out_urb) {
231 if (devinfo->use_streams) {
232 cmdinfo->state |= DATA_COMPLETES_CMD;
233 usb_unlink_urb(cmdinfo->data_in_urb);
234 } else {
235 usb_free_urb(cmdinfo->data_out_urb);
236 }
237 }
238
239 if (urb->actual_length < 16) 251 if (urb->actual_length < 16)
240 devinfo->uas_sense_old = 1; 252 devinfo->uas_sense_old = 1;
241 if (devinfo->uas_sense_old) 253 if (devinfo->uas_sense_old)
242 uas_sense_old(urb, cmnd); 254 uas_sense_old(urb, cmnd);
243 else 255 else
244 uas_sense(urb, cmnd); 256 uas_sense(urb, cmnd);
257 if (cmnd->result != 0) {
258 /* cancel data transfers on error */
259 if (cmdinfo->state & DATA_IN_URB_INFLIGHT)
260 usb_unlink_urb(cmdinfo->data_in_urb);
261 if (cmdinfo->state & DATA_OUT_URB_INFLIGHT)
262 usb_unlink_urb(cmdinfo->data_out_urb);
263 }
264 cmdinfo->state &= ~COMMAND_INFLIGHT;
265 uas_try_complete(cmnd, __func__);
245 break; 266 break;
246 case IU_ID_READ_READY: 267 case IU_ID_READ_READY:
247 uas_xfer_data(urb, cmnd, SUBMIT_DATA_IN_URB); 268 uas_xfer_data(urb, cmnd, SUBMIT_DATA_IN_URB);
@@ -249,74 +270,59 @@ static void uas_stat_cmplt(struct urb *urb)
249 case IU_ID_WRITE_READY: 270 case IU_ID_WRITE_READY:
250 uas_xfer_data(urb, cmnd, SUBMIT_DATA_OUT_URB); 271 uas_xfer_data(urb, cmnd, SUBMIT_DATA_OUT_URB);
251 break; 272 break;
273 case IU_ID_RESPONSE:
274 /* store results for uas_eh_task_mgmt() */
275 memcpy(&devinfo->response, iu, sizeof(devinfo->response));
276 break;
252 default: 277 default:
253 scmd_printk(KERN_ERR, cmnd, 278 scmd_printk(KERN_ERR, cmnd,
254 "Bogus IU (%d) received on status pipe\n", iu->iu_id); 279 "Bogus IU (%d) received on status pipe\n", iu->iu_id);
255 } 280 }
256
257 if (devinfo->use_streams) {
258 usb_free_urb(urb);
259 return;
260 }
261
262 ret = usb_submit_urb(urb, GFP_ATOMIC);
263 if (ret)
264 dev_err(&urb->dev->dev, "failed submit status urb\n");
265}
266
267static void uas_data_out_cmplt(struct urb *urb)
268{
269 struct scsi_cmnd *cmnd = urb->context;
270 struct scsi_data_buffer *sdb = scsi_out(cmnd);
271 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
272
273 cmdinfo->state |= COMPLETED_DATA_OUT;
274
275 sdb->resid = sdb->length - urb->actual_length;
276 usb_free_urb(urb); 281 usb_free_urb(urb);
277
278 if (cmdinfo->state & DATA_COMPLETES_CMD)
279 cmnd->scsi_done(cmnd);
280} 282}
281 283
282static void uas_data_in_cmplt(struct urb *urb) 284static void uas_data_cmplt(struct urb *urb)
283{ 285{
284 struct scsi_cmnd *cmnd = urb->context; 286 struct scsi_cmnd *cmnd = urb->context;
285 struct scsi_data_buffer *sdb = scsi_in(cmnd);
286 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; 287 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
288 struct scsi_data_buffer *sdb = NULL;
287 289
288 cmdinfo->state |= COMPLETED_DATA_IN; 290 if (cmdinfo->data_in_urb == urb) {
289 291 sdb = scsi_in(cmnd);
290 sdb->resid = sdb->length - urb->actual_length; 292 cmdinfo->state &= ~DATA_IN_URB_INFLIGHT;
291 usb_free_urb(urb); 293 } else if (cmdinfo->data_out_urb == urb) {
292 294 sdb = scsi_out(cmnd);
293 if (cmdinfo->state & DATA_COMPLETES_CMD) 295 cmdinfo->state &= ~DATA_OUT_URB_INFLIGHT;
294 cmnd->scsi_done(cmnd); 296 }
297 BUG_ON(sdb == NULL);
298 if (urb->status) {
299 /* error: no data transfered */
300 sdb->resid = sdb->length;
301 } else {
302 sdb->resid = sdb->length - urb->actual_length;
303 }
304 if (cmdinfo->aborted) {
305 return;
306 }
307 uas_try_complete(cmnd, __func__);
295} 308}
296 309
297static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp, 310static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp,
298 unsigned int pipe, struct scsi_cmnd *cmnd, 311 unsigned int pipe, u16 stream_id,
299 enum dma_data_direction dir) 312 struct scsi_cmnd *cmnd,
313 enum dma_data_direction dir)
300{ 314{
301 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
302 struct usb_device *udev = devinfo->udev; 315 struct usb_device *udev = devinfo->udev;
303 struct urb *urb = usb_alloc_urb(0, gfp); 316 struct urb *urb = usb_alloc_urb(0, gfp);
304 struct scsi_data_buffer *sdb; 317 struct scsi_data_buffer *sdb = (dir == DMA_FROM_DEVICE)
305 usb_complete_t complete_fn; 318 ? scsi_in(cmnd) : scsi_out(cmnd);
306 u16 stream_id = cmdinfo->stream;
307 319
308 if (!urb) 320 if (!urb)
309 goto out; 321 goto out;
310 if (dir == DMA_FROM_DEVICE) {
311 sdb = scsi_in(cmnd);
312 complete_fn = uas_data_in_cmplt;
313 } else {
314 sdb = scsi_out(cmnd);
315 complete_fn = uas_data_out_cmplt;
316 }
317 usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length, 322 usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length,
318 complete_fn, cmnd); 323 uas_data_cmplt, cmnd);
319 urb->stream_id = stream_id; 324 if (devinfo->use_streams)
325 urb->stream_id = stream_id;
320 urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0; 326 urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0;
321 urb->sg = sdb->table.sgl; 327 urb->sg = sdb->table.sgl;
322 out: 328 out:
@@ -324,7 +330,7 @@ static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp,
324} 330}
325 331
326static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp, 332static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp,
327 struct Scsi_Host *shost, u16 stream_id) 333 struct Scsi_Host *shost, u16 stream_id)
328{ 334{
329 struct usb_device *udev = devinfo->udev; 335 struct usb_device *udev = devinfo->udev;
330 struct urb *urb = usb_alloc_urb(0, gfp); 336 struct urb *urb = usb_alloc_urb(0, gfp);
@@ -388,38 +394,95 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp,
388 return NULL; 394 return NULL;
389} 395}
390 396
397static int uas_submit_task_urb(struct scsi_cmnd *cmnd, gfp_t gfp,
398 u8 function, u16 stream_id)
399{
400 struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata;
401 struct usb_device *udev = devinfo->udev;
402 struct urb *urb = usb_alloc_urb(0, gfp);
403 struct task_mgmt_iu *iu;
404 int err = -ENOMEM;
405
406 if (!urb)
407 goto err;
408
409 iu = kzalloc(sizeof(*iu), gfp);
410 if (!iu)
411 goto err;
412
413 iu->iu_id = IU_ID_TASK_MGMT;
414 iu->tag = cpu_to_be16(stream_id);
415 int_to_scsilun(cmnd->device->lun, &iu->lun);
416
417 iu->function = function;
418 switch (function) {
419 case TMF_ABORT_TASK:
420 if (blk_rq_tagged(cmnd->request))
421 iu->task_tag = cpu_to_be16(cmnd->request->tag + 2);
422 else
423 iu->task_tag = cpu_to_be16(1);
424 break;
425 }
426
427 usb_fill_bulk_urb(urb, udev, devinfo->cmd_pipe, iu, sizeof(*iu),
428 usb_free_urb, NULL);
429 urb->transfer_flags |= URB_FREE_BUFFER;
430
431 err = usb_submit_urb(urb, gfp);
432 if (err)
433 goto err;
434
435 return 0;
436
437err:
438 usb_free_urb(urb);
439 return err;
440}
441
391/* 442/*
392 * Why should I request the Status IU before sending the Command IU? Spec 443 * Why should I request the Status IU before sending the Command IU? Spec
393 * says to, but also says the device may receive them in any order. Seems 444 * says to, but also says the device may receive them in any order. Seems
394 * daft to me. 445 * daft to me.
395 */ 446 */
396 447
397static int uas_submit_urbs(struct scsi_cmnd *cmnd, 448static int uas_submit_sense_urb(struct Scsi_Host *shost,
398 struct uas_dev_info *devinfo, gfp_t gfp) 449 gfp_t gfp, unsigned int stream)
399{ 450{
400 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; 451 struct uas_dev_info *devinfo = (void *)shost->hostdata[0];
452 struct urb *urb;
401 453
402 if (cmdinfo->state & ALLOC_STATUS_URB) { 454 urb = uas_alloc_sense_urb(devinfo, gfp, shost, stream);
403 cmdinfo->status_urb = uas_alloc_sense_urb(devinfo, gfp, 455 if (!urb)
404 cmnd->device->host, cmdinfo->stream); 456 return SCSI_MLQUEUE_DEVICE_BUSY;
405 if (!cmdinfo->status_urb) 457 if (usb_submit_urb(urb, gfp)) {
406 return SCSI_MLQUEUE_DEVICE_BUSY; 458 shost_printk(KERN_INFO, shost,
407 cmdinfo->state &= ~ALLOC_STATUS_URB; 459 "sense urb submission failure\n");
460 usb_free_urb(urb);
461 return SCSI_MLQUEUE_DEVICE_BUSY;
408 } 462 }
463 usb_anchor_urb(urb, &devinfo->sense_urbs);
464 return 0;
465}
466
467static int uas_submit_urbs(struct scsi_cmnd *cmnd,
468 struct uas_dev_info *devinfo, gfp_t gfp)
469{
470 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
471 int err;
409 472
410 if (cmdinfo->state & SUBMIT_STATUS_URB) { 473 if (cmdinfo->state & SUBMIT_STATUS_URB) {
411 if (usb_submit_urb(cmdinfo->status_urb, gfp)) { 474 err = uas_submit_sense_urb(cmnd->device->host, gfp,
412 scmd_printk(KERN_INFO, cmnd, 475 cmdinfo->stream);
413 "sense urb submission failure\n"); 476 if (err) {
414 return SCSI_MLQUEUE_DEVICE_BUSY; 477 return err;
415 } 478 }
416 cmdinfo->state &= ~SUBMIT_STATUS_URB; 479 cmdinfo->state &= ~SUBMIT_STATUS_URB;
417 } 480 }
418 481
419 if (cmdinfo->state & ALLOC_DATA_IN_URB) { 482 if (cmdinfo->state & ALLOC_DATA_IN_URB) {
420 cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp, 483 cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp,
421 devinfo->data_in_pipe, cmnd, 484 devinfo->data_in_pipe, cmdinfo->stream,
422 DMA_FROM_DEVICE); 485 cmnd, DMA_FROM_DEVICE);
423 if (!cmdinfo->data_in_urb) 486 if (!cmdinfo->data_in_urb)
424 return SCSI_MLQUEUE_DEVICE_BUSY; 487 return SCSI_MLQUEUE_DEVICE_BUSY;
425 cmdinfo->state &= ~ALLOC_DATA_IN_URB; 488 cmdinfo->state &= ~ALLOC_DATA_IN_URB;
@@ -432,12 +495,14 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
432 return SCSI_MLQUEUE_DEVICE_BUSY; 495 return SCSI_MLQUEUE_DEVICE_BUSY;
433 } 496 }
434 cmdinfo->state &= ~SUBMIT_DATA_IN_URB; 497 cmdinfo->state &= ~SUBMIT_DATA_IN_URB;
498 cmdinfo->state |= DATA_IN_URB_INFLIGHT;
499 usb_anchor_urb(cmdinfo->data_in_urb, &devinfo->data_urbs);
435 } 500 }
436 501
437 if (cmdinfo->state & ALLOC_DATA_OUT_URB) { 502 if (cmdinfo->state & ALLOC_DATA_OUT_URB) {
438 cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp, 503 cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp,
439 devinfo->data_out_pipe, cmnd, 504 devinfo->data_out_pipe, cmdinfo->stream,
440 DMA_TO_DEVICE); 505 cmnd, DMA_TO_DEVICE);
441 if (!cmdinfo->data_out_urb) 506 if (!cmdinfo->data_out_urb)
442 return SCSI_MLQUEUE_DEVICE_BUSY; 507 return SCSI_MLQUEUE_DEVICE_BUSY;
443 cmdinfo->state &= ~ALLOC_DATA_OUT_URB; 508 cmdinfo->state &= ~ALLOC_DATA_OUT_URB;
@@ -450,6 +515,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
450 return SCSI_MLQUEUE_DEVICE_BUSY; 515 return SCSI_MLQUEUE_DEVICE_BUSY;
451 } 516 }
452 cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; 517 cmdinfo->state &= ~SUBMIT_DATA_OUT_URB;
518 cmdinfo->state |= DATA_OUT_URB_INFLIGHT;
519 usb_anchor_urb(cmdinfo->data_out_urb, &devinfo->data_urbs);
453 } 520 }
454 521
455 if (cmdinfo->state & ALLOC_CMD_URB) { 522 if (cmdinfo->state & ALLOC_CMD_URB) {
@@ -467,6 +534,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
467 return SCSI_MLQUEUE_DEVICE_BUSY; 534 return SCSI_MLQUEUE_DEVICE_BUSY;
468 } 535 }
469 cmdinfo->state &= ~SUBMIT_CMD_URB; 536 cmdinfo->state &= ~SUBMIT_CMD_URB;
537 cmdinfo->state |= COMMAND_INFLIGHT;
470 } 538 }
471 539
472 return 0; 540 return 0;
@@ -494,8 +562,9 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
494 562
495 cmnd->scsi_done = done; 563 cmnd->scsi_done = done;
496 564
497 cmdinfo->state = ALLOC_STATUS_URB | SUBMIT_STATUS_URB | 565 cmdinfo->state = SUBMIT_STATUS_URB |
498 ALLOC_CMD_URB | SUBMIT_CMD_URB; 566 ALLOC_CMD_URB | SUBMIT_CMD_URB;
567 cmdinfo->aborted = 0;
499 568
500 switch (cmnd->sc_data_direction) { 569 switch (cmnd->sc_data_direction) {
501 case DMA_FROM_DEVICE: 570 case DMA_FROM_DEVICE:
@@ -510,8 +579,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
510 } 579 }
511 580
512 if (!devinfo->use_streams) { 581 if (!devinfo->use_streams) {
513 cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB | 582 cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB);
514 ALLOC_STATUS_URB | SUBMIT_STATUS_URB);
515 cmdinfo->stream = 0; 583 cmdinfo->stream = 0;
516 } 584 }
517 585
@@ -519,7 +587,6 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
519 if (err) { 587 if (err) {
520 /* If we did nothing, give up now */ 588 /* If we did nothing, give up now */
521 if (cmdinfo->state & SUBMIT_STATUS_URB) { 589 if (cmdinfo->state & SUBMIT_STATUS_URB) {
522 usb_free_urb(cmdinfo->status_urb);
523 return SCSI_MLQUEUE_DEVICE_BUSY; 590 return SCSI_MLQUEUE_DEVICE_BUSY;
524 } 591 }
525 spin_lock(&uas_work_lock); 592 spin_lock(&uas_work_lock);
@@ -533,36 +600,66 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
533 600
534static DEF_SCSI_QCMD(uas_queuecommand) 601static DEF_SCSI_QCMD(uas_queuecommand)
535 602
536static int uas_eh_abort_handler(struct scsi_cmnd *cmnd) 603static int uas_eh_task_mgmt(struct scsi_cmnd *cmnd,
604 const char *fname, u8 function)
537{ 605{
538 struct scsi_device *sdev = cmnd->device; 606 struct Scsi_Host *shost = cmnd->device->host;
539 sdev_printk(KERN_INFO, sdev, "%s tag %d\n", __func__, 607 struct uas_dev_info *devinfo = (void *)shost->hostdata[0];
540 cmnd->request->tag); 608 u16 tag = 9999; /* FIXME */
541 609
542/* XXX: Send ABORT TASK Task Management command */ 610 memset(&devinfo->response, 0, sizeof(devinfo->response));
543 return FAILED; 611 if (uas_submit_sense_urb(shost, GFP_NOIO, tag)) {
612 shost_printk(KERN_INFO, shost,
613 "%s: %s: submit sense urb failed\n",
614 __func__, fname);
615 return FAILED;
616 }
617 if (uas_submit_task_urb(cmnd, GFP_NOIO, function, tag)) {
618 shost_printk(KERN_INFO, shost,
619 "%s: %s: submit task mgmt urb failed\n",
620 __func__, fname);
621 return FAILED;
622 }
623 if (0 == usb_wait_anchor_empty_timeout(&devinfo->sense_urbs, 3000)) {
624 shost_printk(KERN_INFO, shost,
625 "%s: %s timed out\n", __func__, fname);
626 return FAILED;
627 }
628 if (be16_to_cpu(devinfo->response.tag) != tag) {
629 shost_printk(KERN_INFO, shost,
630 "%s: %s failed (wrong tag %d/%d)\n", __func__,
631 fname, be16_to_cpu(devinfo->response.tag), tag);
632 return FAILED;
633 }
634 if (devinfo->response.response_code != RC_TMF_COMPLETE) {
635 shost_printk(KERN_INFO, shost,
636 "%s: %s failed (rc 0x%x)\n", __func__,
637 fname, devinfo->response.response_code);
638 return FAILED;
639 }
640 return SUCCESS;
544} 641}
545 642
546static int uas_eh_device_reset_handler(struct scsi_cmnd *cmnd) 643static int uas_eh_abort_handler(struct scsi_cmnd *cmnd)
547{ 644{
548 struct scsi_device *sdev = cmnd->device; 645 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
549 sdev_printk(KERN_INFO, sdev, "%s tag %d\n", __func__, 646 int ret;
550 cmnd->request->tag);
551 647
552/* XXX: Send LOGICAL UNIT RESET Task Management command */ 648 uas_log_cmd_state(cmnd, __func__);
553 return FAILED; 649 cmdinfo->aborted = 1;
650 ret = uas_eh_task_mgmt(cmnd, "ABORT TASK", TMF_ABORT_TASK);
651 if (cmdinfo->state & DATA_IN_URB_INFLIGHT)
652 usb_kill_urb(cmdinfo->data_in_urb);
653 if (cmdinfo->state & DATA_OUT_URB_INFLIGHT)
654 usb_kill_urb(cmdinfo->data_out_urb);
655 return ret;
554} 656}
555 657
556static int uas_eh_target_reset_handler(struct scsi_cmnd *cmnd) 658static int uas_eh_device_reset_handler(struct scsi_cmnd *cmnd)
557{ 659{
558 struct scsi_device *sdev = cmnd->device; 660 sdev_printk(KERN_INFO, cmnd->device, "%s\n", __func__);
559 sdev_printk(KERN_INFO, sdev, "%s tag %d\n", __func__, 661 return uas_eh_task_mgmt(cmnd, "LOGICAL UNIT RESET",
560 cmnd->request->tag); 662 TMF_LOGICAL_UNIT_RESET);
561
562/* XXX: Can we reset just the one USB interface?
563 * Would calling usb_set_interface() have the right effect?
564 */
565 return FAILED;
566} 663}
567 664
568static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd) 665static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd)
@@ -570,14 +667,21 @@ static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd)
570 struct scsi_device *sdev = cmnd->device; 667 struct scsi_device *sdev = cmnd->device;
571 struct uas_dev_info *devinfo = sdev->hostdata; 668 struct uas_dev_info *devinfo = sdev->hostdata;
572 struct usb_device *udev = devinfo->udev; 669 struct usb_device *udev = devinfo->udev;
670 int err;
573 671
574 sdev_printk(KERN_INFO, sdev, "%s tag %d\n", __func__, 672 devinfo->resetting = 1;
575 cmnd->request->tag); 673 usb_kill_anchored_urbs(&devinfo->sense_urbs);
674 usb_kill_anchored_urbs(&devinfo->data_urbs);
675 err = usb_reset_device(udev);
676 devinfo->resetting = 0;
576 677
577 if (usb_reset_device(udev)) 678 if (err) {
578 return SUCCESS; 679 shost_printk(KERN_INFO, sdev->host, "%s FAILED\n", __func__);
680 return FAILED;
681 }
579 682
580 return FAILED; 683 shost_printk(KERN_INFO, sdev->host, "%s success\n", __func__);
684 return SUCCESS;
581} 685}
582 686
583static int uas_slave_alloc(struct scsi_device *sdev) 687static int uas_slave_alloc(struct scsi_device *sdev)
@@ -602,7 +706,6 @@ static struct scsi_host_template uas_host_template = {
602 .slave_configure = uas_slave_configure, 706 .slave_configure = uas_slave_configure,
603 .eh_abort_handler = uas_eh_abort_handler, 707 .eh_abort_handler = uas_eh_abort_handler,
604 .eh_device_reset_handler = uas_eh_device_reset_handler, 708 .eh_device_reset_handler = uas_eh_device_reset_handler,
605 .eh_target_reset_handler = uas_eh_target_reset_handler,
606 .eh_bus_reset_handler = uas_eh_bus_reset_handler, 709 .eh_bus_reset_handler = uas_eh_bus_reset_handler,
607 .can_queue = 65536, /* Is there a limit on the _host_ ? */ 710 .can_queue = 65536, /* Is there a limit on the _host_ ? */
608 .this_id = -1, 711 .this_id = -1,
@@ -722,29 +825,6 @@ static void uas_configure_endpoints(struct uas_dev_info *devinfo)
722 } 825 }
723} 826}
724 827
725static int uas_alloc_status_urb(struct uas_dev_info *devinfo,
726 struct Scsi_Host *shost)
727{
728 if (devinfo->use_streams) {
729 devinfo->status_urb = NULL;
730 return 0;
731 }
732
733 devinfo->status_urb = uas_alloc_sense_urb(devinfo, GFP_KERNEL,
734 shost, 0);
735 if (!devinfo->status_urb)
736 goto err_s_urb;
737
738 if (usb_submit_urb(devinfo->status_urb, GFP_KERNEL))
739 goto err_submit_urb;
740
741 return 0;
742err_submit_urb:
743 usb_free_urb(devinfo->status_urb);
744err_s_urb:
745 return -ENOMEM;
746}
747
748static void uas_free_streams(struct uas_dev_info *devinfo) 828static void uas_free_streams(struct uas_dev_info *devinfo)
749{ 829{
750 struct usb_device *udev = devinfo->udev; 830 struct usb_device *udev = devinfo->udev;
@@ -787,6 +867,9 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
787 867
788 devinfo->intf = intf; 868 devinfo->intf = intf;
789 devinfo->udev = udev; 869 devinfo->udev = udev;
870 devinfo->resetting = 0;
871 init_usb_anchor(&devinfo->sense_urbs);
872 init_usb_anchor(&devinfo->data_urbs);
790 uas_configure_endpoints(devinfo); 873 uas_configure_endpoints(devinfo);
791 874
792 result = scsi_init_shared_tag_map(shost, devinfo->qdepth - 2); 875 result = scsi_init_shared_tag_map(shost, devinfo->qdepth - 2);
@@ -799,17 +882,10 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
799 882
800 shost->hostdata[0] = (unsigned long)devinfo; 883 shost->hostdata[0] = (unsigned long)devinfo;
801 884
802 result = uas_alloc_status_urb(devinfo, shost);
803 if (result)
804 goto err_alloc_status;
805
806 scsi_scan_host(shost); 885 scsi_scan_host(shost);
807 usb_set_intfdata(intf, shost); 886 usb_set_intfdata(intf, shost);
808 return result; 887 return result;
809 888
810err_alloc_status:
811 scsi_remove_host(shost);
812 shost = NULL;
813deconfig_eps: 889deconfig_eps:
814 uas_free_streams(devinfo); 890 uas_free_streams(devinfo);
815 free: 891 free:
@@ -837,8 +913,8 @@ static void uas_disconnect(struct usb_interface *intf)
837 struct uas_dev_info *devinfo = (void *)shost->hostdata[0]; 913 struct uas_dev_info *devinfo = (void *)shost->hostdata[0];
838 914
839 scsi_remove_host(shost); 915 scsi_remove_host(shost);
840 usb_kill_urb(devinfo->status_urb); 916 usb_kill_anchored_urbs(&devinfo->sense_urbs);
841 usb_free_urb(devinfo->status_urb); 917 usb_kill_anchored_urbs(&devinfo->data_urbs);
842 uas_free_streams(devinfo); 918 uas_free_streams(devinfo);
843 kfree(devinfo); 919 kfree(devinfo);
844} 920}