aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-03-16 18:04:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-16 18:04:26 -0400
commit971f115a50afbe409825c9f3399d5a3b9aca4381 (patch)
treecb42dc07a032e325f22b64d961587c081225c6d6 /drivers
parent2e270d84223262a38d4755c61d55f5c73ea89e56 (diff)
parent500132a0f26ad7d9916102193cbc6c1b1becb373 (diff)
Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (172 commits) USB: Add support for SuperSpeed isoc endpoints xhci: Clean up cycle bit math used during stalls. xhci: Fix cycle bit calculation during stall handling. xhci: Update internal dequeue pointers after stalls. USB: Disable auto-suspend for USB 3.0 hubs. USB: Remove bogus USB_PORT_STAT_SUPER_SPEED symbol. xhci: Return canceled URBs immediately when host is halted. xhci: Fixes for suspend/resume of shared HCDs. xhci: Fix re-init on power loss after resume. xhci: Make roothub functions deal with device removal. xhci: Limit roothub ports to 15 USB3 & 31 USB2 ports. xhci: Return a USB 3.0 hub descriptor for USB3 roothub. xhci: Register second xHCI roothub. xhci: Change xhci_find_slot_id_by_port() API. xhci: Refactor bus suspend state into a struct. xhci: Index with a port array instead of PORTSC addresses. USB: Set usb_hcd->state and flags for shared roothubs. usb: Make core allocate resources per PCI-device. usb: Store bus type in usb_hcd, not in driver flags. usb: Change usb_hcd->bandwidth_mutex to a pointer. ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mfd/Kconfig9
-rw-r--r--drivers/mfd/Makefile1
-rw-r--r--drivers/mfd/omap-usb-host.c1061
-rw-r--r--drivers/staging/usbip/vhci_hcd.c4
-rw-r--r--drivers/usb/atm/ueagle-atm.c19
-rw-r--r--drivers/usb/core/buffer.c26
-rw-r--r--drivers/usb/core/driver.c5
-rw-r--r--drivers/usb/core/hcd-pci.c56
-rw-r--r--drivers/usb/core/hcd.c281
-rw-r--r--drivers/usb/core/hub.c199
-rw-r--r--drivers/usb/core/message.c22
-rw-r--r--drivers/usb/core/urb.c11
-rw-r--r--drivers/usb/core/usb.h13
-rw-r--r--drivers/usb/early/ehci-dbgp.c2
-rw-r--r--drivers/usb/gadget/Kconfig14
-rw-r--r--drivers/usb/gadget/Makefile1
-rw-r--r--drivers/usb/gadget/at91_udc.c4
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c344
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.h9
-rw-r--r--drivers/usb/gadget/composite.c14
-rw-r--r--drivers/usb/gadget/dummy_hcd.c4
-rw-r--r--drivers/usb/gadget/epautoconf.c7
-rw-r--r--drivers/usb/gadget/f_fs.c8
-rw-r--r--drivers/usb/gadget/fsl_mxc_udc.c21
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c2
-rw-r--r--drivers/usb/gadget/fusb300_udc.c1744
-rw-r--r--drivers/usb/gadget/fusb300_udc.h687
-rw-r--r--drivers/usb/gadget/m66592-udc.c2
-rw-r--r--drivers/usb/gadget/pch_udc.c178
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c76
-rw-r--r--drivers/usb/gadget/u_ether.c2
-rw-r--r--drivers/usb/host/Kconfig39
-rw-r--r--drivers/usb/host/ehci-atmel.c6
-rw-r--r--drivers/usb/host/ehci-dbg.c4
-rw-r--r--drivers/usb/host/ehci-hcd.c29
-rw-r--r--drivers/usb/host/ehci-hub.c32
-rw-r--r--drivers/usb/host/ehci-lpm.c5
-rw-r--r--drivers/usb/host/ehci-msm.c96
-rw-r--r--drivers/usb/host/ehci-omap.c882
-rw-r--r--drivers/usb/host/ehci-orion.c5
-rw-r--r--drivers/usb/host/ehci-pci.c45
-rw-r--r--drivers/usb/host/ehci-pmcmsp.c383
-rw-r--r--drivers/usb/host/ehci-q.c18
-rw-r--r--drivers/usb/host/ehci-sched.c76
-rw-r--r--drivers/usb/host/ehci-tegra.c715
-rw-r--r--drivers/usb/host/ehci.h2
-rw-r--r--drivers/usb/host/imx21-hcd.c9
-rw-r--r--drivers/usb/host/isp116x-hcd.c6
-rw-r--r--drivers/usb/host/isp1362-hcd.c13
-rw-r--r--drivers/usb/host/isp1760-hcd.c1395
-rw-r--r--drivers/usb/host/isp1760-hcd.h56
-rw-r--r--drivers/usb/host/ohci-hcd.c18
-rw-r--r--drivers/usb/host/ohci-hub.c13
-rw-r--r--drivers/usb/host/ohci-omap3.c584
-rw-r--r--drivers/usb/host/ohci-pci.c114
-rw-r--r--drivers/usb/host/ohci-q.c4
-rw-r--r--drivers/usb/host/ohci.h4
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c6
-rw-r--r--drivers/usb/host/pci-quirks.c258
-rw-r--r--drivers/usb/host/pci-quirks.h10
-rw-r--r--drivers/usb/host/r8a66597-hcd.c5
-rw-r--r--drivers/usb/host/sl811-hcd.c6
-rw-r--r--drivers/usb/host/u132-hcd.c11
-rw-r--r--drivers/usb/host/uhci-hcd.c2
-rw-r--r--drivers/usb/host/xhci-ext-caps.h4
-rw-r--r--drivers/usb/host/xhci-hub.c392
-rw-r--r--drivers/usb/host/xhci-mem.c93
-rw-r--r--drivers/usb/host/xhci-pci.c124
-rw-r--r--drivers/usb/host/xhci-ring.c195
-rw-r--r--drivers/usb/host/xhci.c129
-rw-r--r--drivers/usb/host/xhci.h53
-rw-r--r--drivers/usb/misc/usbtest.c236
-rw-r--r--drivers/usb/mon/mon_text.c3
-rw-r--r--drivers/usb/musb/musb_core.c65
-rw-r--r--drivers/usb/musb/musb_core.h8
-rw-r--r--drivers/usb/musb/musb_gadget.c217
-rw-r--r--drivers/usb/musb/musb_gadget.h7
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c24
-rw-r--r--drivers/usb/musb/musb_host.c4
-rw-r--r--drivers/usb/musb/musb_virthub.c4
-rw-r--r--drivers/usb/musb/omap2430.c176
-rw-r--r--drivers/usb/musb/tusb6010_omap.c4
-rw-r--r--drivers/usb/otg/Kconfig9
-rw-r--r--drivers/usb/otg/Makefile3
-rw-r--r--drivers/usb/otg/ab8500-usb.c6
-rw-r--r--drivers/usb/otg/langwell_otg.c48
-rw-r--r--drivers/usb/otg/msm_otg.c (renamed from drivers/usb/otg/msm72k_otg.c)31
-rw-r--r--drivers/usb/otg/nop-usb-xceiv.c2
-rw-r--r--drivers/usb/otg/twl4030-usb.c8
-rw-r--r--drivers/usb/otg/twl6030-usb.c56
-rw-r--r--drivers/usb/otg/ulpi_viewport.c80
-rw-r--r--drivers/usb/serial/ch341.c1
-rw-r--r--drivers/usb/serial/ftdi_sio.c4
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h1
-rw-r--r--drivers/usb/serial/io_edgeport.c3
-rw-r--r--drivers/usb/serial/keyspan.c10
-rw-r--r--drivers/usb/serial/keyspan_pda.c15
-rw-r--r--drivers/usb/serial/kobil_sct.c2
-rw-r--r--drivers/usb/serial/mct_u232.c107
-rw-r--r--drivers/usb/serial/mos7720.c3
-rw-r--r--drivers/usb/serial/opticon.c156
-rw-r--r--drivers/usb/serial/option.c3
-rw-r--r--drivers/usb/serial/sierra.c16
-rw-r--r--drivers/usb/serial/usb-serial.c5
-rw-r--r--drivers/usb/serial/usb_wwan.c43
-rw-r--r--drivers/usb/storage/Kconfig10
-rw-r--r--drivers/usb/storage/Makefile2
-rw-r--r--drivers/usb/storage/realtek_cr.c675
-rw-r--r--drivers/usb/storage/sierra_ms.c2
-rw-r--r--drivers/usb/storage/unusual_realtek.h41
-rw-r--r--drivers/usb/storage/usual-tables.c1
-rw-r--r--drivers/usb/wusbcore/rh.c6
-rw-r--r--drivers/usb/wusbcore/wusbhc.c2
-rw-r--r--drivers/usb/wusbcore/wusbhc.h2
-rw-r--r--drivers/uwb/scan.c2
115 files changed, 9178 insertions, 3592 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index fd018366d670..a6dfa37a674d 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -624,6 +624,15 @@ config MFD_WL1273_CORE
624 driver connects the radio-wl1273 V4L2 module and the wl1273 624 driver connects the radio-wl1273 V4L2 module and the wl1273
625 audio codec. 625 audio codec.
626 626
627config MFD_OMAP_USB_HOST
628 bool "Support OMAP USBHS core driver"
629 depends on USB_EHCI_HCD_OMAP || USB_OHCI_HCD_OMAP3
630 default y
631 help
632 This is the core driver for the OAMP EHCI and OHCI drivers.
633 This MFD driver does the required setup functionalities for
634 OMAP USB Host drivers.
635
627endif # MFD_SUPPORT 636endif # MFD_SUPPORT
628 637
629menu "Multimedia Capabilities Port drivers" 638menu "Multimedia Capabilities Port drivers"
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index a54e2c7c6a1c..91fe384459ab 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -83,3 +83,4 @@ obj-$(CONFIG_MFD_TPS6586X) += tps6586x.o
83obj-$(CONFIG_MFD_VX855) += vx855.o 83obj-$(CONFIG_MFD_VX855) += vx855.o
84obj-$(CONFIG_MFD_WL1273_CORE) += wl1273-core.o 84obj-$(CONFIG_MFD_WL1273_CORE) += wl1273-core.o
85obj-$(CONFIG_MFD_CS5535) += cs5535-mfd.o 85obj-$(CONFIG_MFD_CS5535) += cs5535-mfd.o
86obj-$(CONFIG_MFD_OMAP_USB_HOST) += omap-usb-host.o
diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c
new file mode 100644
index 000000000000..cb01209754e0
--- /dev/null
+++ b/drivers/mfd/omap-usb-host.c
@@ -0,0 +1,1061 @@
1/**
2 * omap-usb-host.c - The USBHS core driver for OMAP EHCI & OHCI
3 *
4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
5 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 of
9 * the License as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#include <linux/kernel.h>
20#include <linux/types.h>
21#include <linux/slab.h>
22#include <linux/delay.h>
23#include <linux/platform_device.h>
24#include <linux/clk.h>
25#include <linux/dma-mapping.h>
26#include <linux/spinlock.h>
27#include <linux/gpio.h>
28#include <linux/regulator/consumer.h>
29#include <plat/usb.h>
30
31#define USBHS_DRIVER_NAME "usbhs-omap"
32#define OMAP_EHCI_DEVICE "ehci-omap"
33#define OMAP_OHCI_DEVICE "ohci-omap3"
34
35/* OMAP USBHOST Register addresses */
36
37/* TLL Register Set */
38#define OMAP_USBTLL_REVISION (0x00)
39#define OMAP_USBTLL_SYSCONFIG (0x10)
40#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
41#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
42#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
43#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
44#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
45
46#define OMAP_USBTLL_SYSSTATUS (0x14)
47#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
48
49#define OMAP_USBTLL_IRQSTATUS (0x18)
50#define OMAP_USBTLL_IRQENABLE (0x1C)
51
52#define OMAP_TLL_SHARED_CONF (0x30)
53#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
54#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
55#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
56#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
57#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
58
59#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
60#define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
61#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
62#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
63#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
64#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
65#define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1)
66#define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
67
68#define OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0 0x0
69#define OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM 0x1
70#define OMAP_TLL_FSLSMODE_3PIN_PHY 0x2
71#define OMAP_TLL_FSLSMODE_4PIN_PHY 0x3
72#define OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0 0x4
73#define OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM 0x5
74#define OMAP_TLL_FSLSMODE_3PIN_TLL 0x6
75#define OMAP_TLL_FSLSMODE_4PIN_TLL 0x7
76#define OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0 0xA
77#define OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM 0xB
78
79#define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
80#define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
81#define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
82#define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
83#define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
84#define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
85#define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
86#define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
87#define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
88
89#define OMAP_TLL_CHANNEL_COUNT 3
90#define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0)
91#define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1)
92#define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2)
93
94/* UHH Register Set */
95#define OMAP_UHH_REVISION (0x00)
96#define OMAP_UHH_SYSCONFIG (0x10)
97#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
98#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
99#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
100#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
101#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
102#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
103
104#define OMAP_UHH_SYSSTATUS (0x14)
105#define OMAP_UHH_HOSTCONFIG (0x40)
106#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
107#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
108#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
109#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
110#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
111#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
112#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
113#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
114#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
115#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
116#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
117#define OMAP4_UHH_HOSTCONFIG_APP_START_CLK (1 << 31)
118
119/* OMAP4-specific defines */
120#define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2)
121#define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2)
122#define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4)
123#define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4)
124#define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0)
125
126#define OMAP4_P1_MODE_CLEAR (3 << 16)
127#define OMAP4_P1_MODE_TLL (1 << 16)
128#define OMAP4_P1_MODE_HSIC (3 << 16)
129#define OMAP4_P2_MODE_CLEAR (3 << 18)
130#define OMAP4_P2_MODE_TLL (1 << 18)
131#define OMAP4_P2_MODE_HSIC (3 << 18)
132
133#define OMAP_REV2_TLL_CHANNEL_COUNT 2
134
135#define OMAP_UHH_DEBUG_CSR (0x44)
136
137/* Values of UHH_REVISION - Note: these are not given in the TRM */
138#define OMAP_USBHS_REV1 0x00000010 /* OMAP3 */
139#define OMAP_USBHS_REV2 0x50700100 /* OMAP4 */
140
141#define is_omap_usbhs_rev1(x) (x->usbhs_rev == OMAP_USBHS_REV1)
142#define is_omap_usbhs_rev2(x) (x->usbhs_rev == OMAP_USBHS_REV2)
143
144#define is_ehci_phy_mode(x) (x == OMAP_EHCI_PORT_MODE_PHY)
145#define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
146#define is_ehci_hsic_mode(x) (x == OMAP_EHCI_PORT_MODE_HSIC)
147
148
149struct usbhs_hcd_omap {
150 struct clk *usbhost_ick;
151 struct clk *usbhost_hs_fck;
152 struct clk *usbhost_fs_fck;
153 struct clk *xclk60mhsp1_ck;
154 struct clk *xclk60mhsp2_ck;
155 struct clk *utmi_p1_fck;
156 struct clk *usbhost_p1_fck;
157 struct clk *usbtll_p1_fck;
158 struct clk *utmi_p2_fck;
159 struct clk *usbhost_p2_fck;
160 struct clk *usbtll_p2_fck;
161 struct clk *init_60m_fclk;
162 struct clk *usbtll_fck;
163 struct clk *usbtll_ick;
164
165 void __iomem *uhh_base;
166 void __iomem *tll_base;
167
168 struct usbhs_omap_platform_data platdata;
169
170 u32 usbhs_rev;
171 spinlock_t lock;
172 int count;
173};
174/*-------------------------------------------------------------------------*/
175
176const char usbhs_driver_name[] = USBHS_DRIVER_NAME;
177static u64 usbhs_dmamask = ~(u32)0;
178
179/*-------------------------------------------------------------------------*/
180
181static inline void usbhs_write(void __iomem *base, u32 reg, u32 val)
182{
183 __raw_writel(val, base + reg);
184}
185
186static inline u32 usbhs_read(void __iomem *base, u32 reg)
187{
188 return __raw_readl(base + reg);
189}
190
191static inline void usbhs_writeb(void __iomem *base, u8 reg, u8 val)
192{
193 __raw_writeb(val, base + reg);
194}
195
196static inline u8 usbhs_readb(void __iomem *base, u8 reg)
197{
198 return __raw_readb(base + reg);
199}
200
201/*-------------------------------------------------------------------------*/
202
203static struct platform_device *omap_usbhs_alloc_child(const char *name,
204 struct resource *res, int num_resources, void *pdata,
205 size_t pdata_size, struct device *dev)
206{
207 struct platform_device *child;
208 int ret;
209
210 child = platform_device_alloc(name, 0);
211
212 if (!child) {
213 dev_err(dev, "platform_device_alloc %s failed\n", name);
214 goto err_end;
215 }
216
217 ret = platform_device_add_resources(child, res, num_resources);
218 if (ret) {
219 dev_err(dev, "platform_device_add_resources failed\n");
220 goto err_alloc;
221 }
222
223 ret = platform_device_add_data(child, pdata, pdata_size);
224 if (ret) {
225 dev_err(dev, "platform_device_add_data failed\n");
226 goto err_alloc;
227 }
228
229 child->dev.dma_mask = &usbhs_dmamask;
230 child->dev.coherent_dma_mask = 0xffffffff;
231 child->dev.parent = dev;
232
233 ret = platform_device_add(child);
234 if (ret) {
235 dev_err(dev, "platform_device_add failed\n");
236 goto err_alloc;
237 }
238
239 return child;
240
241err_alloc:
242 platform_device_put(child);
243
244err_end:
245 return NULL;
246}
247
248static int omap_usbhs_alloc_children(struct platform_device *pdev)
249{
250 struct device *dev = &pdev->dev;
251 struct usbhs_hcd_omap *omap;
252 struct ehci_hcd_omap_platform_data *ehci_data;
253 struct ohci_hcd_omap_platform_data *ohci_data;
254 struct platform_device *ehci;
255 struct platform_device *ohci;
256 struct resource *res;
257 struct resource resources[2];
258 int ret;
259
260 omap = platform_get_drvdata(pdev);
261 ehci_data = omap->platdata.ehci_data;
262 ohci_data = omap->platdata.ohci_data;
263
264 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci");
265 if (!res) {
266 dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n");
267 ret = -ENODEV;
268 goto err_end;
269 }
270 resources[0] = *res;
271
272 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq");
273 if (!res) {
274 dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n");
275 ret = -ENODEV;
276 goto err_end;
277 }
278 resources[1] = *res;
279
280 ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, ehci_data,
281 sizeof(*ehci_data), dev);
282
283 if (!ehci) {
284 dev_err(dev, "omap_usbhs_alloc_child failed\n");
285 goto err_end;
286 }
287
288 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci");
289 if (!res) {
290 dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n");
291 ret = -ENODEV;
292 goto err_ehci;
293 }
294 resources[0] = *res;
295
296 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq");
297 if (!res) {
298 dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n");
299 ret = -ENODEV;
300 goto err_ehci;
301 }
302 resources[1] = *res;
303
304 ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, ohci_data,
305 sizeof(*ohci_data), dev);
306 if (!ohci) {
307 dev_err(dev, "omap_usbhs_alloc_child failed\n");
308 goto err_ehci;
309 }
310
311 return 0;
312
313err_ehci:
314 platform_device_put(ehci);
315
316err_end:
317 return ret;
318}
319
320/**
321 * usbhs_omap_probe - initialize TI-based HCDs
322 *
323 * Allocates basic resources for this USB host controller.
324 */
325static int __devinit usbhs_omap_probe(struct platform_device *pdev)
326{
327 struct device *dev = &pdev->dev;
328 struct usbhs_omap_platform_data *pdata = dev->platform_data;
329 struct usbhs_hcd_omap *omap;
330 struct resource *res;
331 int ret = 0;
332 int i;
333
334 if (!pdata) {
335 dev_err(dev, "Missing platfrom data\n");
336 ret = -ENOMEM;
337 goto end_probe;
338 }
339
340 omap = kzalloc(sizeof(*omap), GFP_KERNEL);
341 if (!omap) {
342 dev_err(dev, "Memory allocation failed\n");
343 ret = -ENOMEM;
344 goto end_probe;
345 }
346
347 spin_lock_init(&omap->lock);
348
349 for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
350 omap->platdata.port_mode[i] = pdata->port_mode[i];
351
352 omap->platdata.ehci_data = pdata->ehci_data;
353 omap->platdata.ohci_data = pdata->ohci_data;
354
355 omap->usbhost_ick = clk_get(dev, "usbhost_ick");
356 if (IS_ERR(omap->usbhost_ick)) {
357 ret = PTR_ERR(omap->usbhost_ick);
358 dev_err(dev, "usbhost_ick failed error:%d\n", ret);
359 goto err_end;
360 }
361
362 omap->usbhost_hs_fck = clk_get(dev, "hs_fck");
363 if (IS_ERR(omap->usbhost_hs_fck)) {
364 ret = PTR_ERR(omap->usbhost_hs_fck);
365 dev_err(dev, "usbhost_hs_fck failed error:%d\n", ret);
366 goto err_usbhost_ick;
367 }
368
369 omap->usbhost_fs_fck = clk_get(dev, "fs_fck");
370 if (IS_ERR(omap->usbhost_fs_fck)) {
371 ret = PTR_ERR(omap->usbhost_fs_fck);
372 dev_err(dev, "usbhost_fs_fck failed error:%d\n", ret);
373 goto err_usbhost_hs_fck;
374 }
375
376 omap->usbtll_fck = clk_get(dev, "usbtll_fck");
377 if (IS_ERR(omap->usbtll_fck)) {
378 ret = PTR_ERR(omap->usbtll_fck);
379 dev_err(dev, "usbtll_fck failed error:%d\n", ret);
380 goto err_usbhost_fs_fck;
381 }
382
383 omap->usbtll_ick = clk_get(dev, "usbtll_ick");
384 if (IS_ERR(omap->usbtll_ick)) {
385 ret = PTR_ERR(omap->usbtll_ick);
386 dev_err(dev, "usbtll_ick failed error:%d\n", ret);
387 goto err_usbtll_fck;
388 }
389
390 omap->utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk");
391 if (IS_ERR(omap->utmi_p1_fck)) {
392 ret = PTR_ERR(omap->utmi_p1_fck);
393 dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret);
394 goto err_usbtll_ick;
395 }
396
397 omap->xclk60mhsp1_ck = clk_get(dev, "xclk60mhsp1_ck");
398 if (IS_ERR(omap->xclk60mhsp1_ck)) {
399 ret = PTR_ERR(omap->xclk60mhsp1_ck);
400 dev_err(dev, "xclk60mhsp1_ck failed error:%d\n", ret);
401 goto err_utmi_p1_fck;
402 }
403
404 omap->utmi_p2_fck = clk_get(dev, "utmi_p2_gfclk");
405 if (IS_ERR(omap->utmi_p2_fck)) {
406 ret = PTR_ERR(omap->utmi_p2_fck);
407 dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret);
408 goto err_xclk60mhsp1_ck;
409 }
410
411 omap->xclk60mhsp2_ck = clk_get(dev, "xclk60mhsp2_ck");
412 if (IS_ERR(omap->xclk60mhsp2_ck)) {
413 ret = PTR_ERR(omap->xclk60mhsp2_ck);
414 dev_err(dev, "xclk60mhsp2_ck failed error:%d\n", ret);
415 goto err_utmi_p2_fck;
416 }
417
418 omap->usbhost_p1_fck = clk_get(dev, "usb_host_hs_utmi_p1_clk");
419 if (IS_ERR(omap->usbhost_p1_fck)) {
420 ret = PTR_ERR(omap->usbhost_p1_fck);
421 dev_err(dev, "usbhost_p1_fck failed error:%d\n", ret);
422 goto err_xclk60mhsp2_ck;
423 }
424
425 omap->usbtll_p1_fck = clk_get(dev, "usb_tll_hs_usb_ch0_clk");
426 if (IS_ERR(omap->usbtll_p1_fck)) {
427 ret = PTR_ERR(omap->usbtll_p1_fck);
428 dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret);
429 goto err_usbhost_p1_fck;
430 }
431
432 omap->usbhost_p2_fck = clk_get(dev, "usb_host_hs_utmi_p2_clk");
433 if (IS_ERR(omap->usbhost_p2_fck)) {
434 ret = PTR_ERR(omap->usbhost_p2_fck);
435 dev_err(dev, "usbhost_p2_fck failed error:%d\n", ret);
436 goto err_usbtll_p1_fck;
437 }
438
439 omap->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk");
440 if (IS_ERR(omap->usbtll_p2_fck)) {
441 ret = PTR_ERR(omap->usbtll_p2_fck);
442 dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret);
443 goto err_usbhost_p2_fck;
444 }
445
446 omap->init_60m_fclk = clk_get(dev, "init_60m_fclk");
447 if (IS_ERR(omap->init_60m_fclk)) {
448 ret = PTR_ERR(omap->init_60m_fclk);
449 dev_err(dev, "init_60m_fclk failed error:%d\n", ret);
450 goto err_usbtll_p2_fck;
451 }
452
453 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uhh");
454 if (!res) {
455 dev_err(dev, "UHH EHCI get resource failed\n");
456 ret = -ENODEV;
457 goto err_init_60m_fclk;
458 }
459
460 omap->uhh_base = ioremap(res->start, resource_size(res));
461 if (!omap->uhh_base) {
462 dev_err(dev, "UHH ioremap failed\n");
463 ret = -ENOMEM;
464 goto err_init_60m_fclk;
465 }
466
467 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tll");
468 if (!res) {
469 dev_err(dev, "UHH EHCI get resource failed\n");
470 ret = -ENODEV;
471 goto err_tll;
472 }
473
474 omap->tll_base = ioremap(res->start, resource_size(res));
475 if (!omap->tll_base) {
476 dev_err(dev, "TLL ioremap failed\n");
477 ret = -ENOMEM;
478 goto err_tll;
479 }
480
481 platform_set_drvdata(pdev, omap);
482
483 ret = omap_usbhs_alloc_children(pdev);
484 if (ret) {
485 dev_err(dev, "omap_usbhs_alloc_children failed\n");
486 goto err_alloc;
487 }
488
489 goto end_probe;
490
491err_alloc:
492 iounmap(omap->tll_base);
493
494err_tll:
495 iounmap(omap->uhh_base);
496
497err_init_60m_fclk:
498 clk_put(omap->init_60m_fclk);
499
500err_usbtll_p2_fck:
501 clk_put(omap->usbtll_p2_fck);
502
503err_usbhost_p2_fck:
504 clk_put(omap->usbhost_p2_fck);
505
506err_usbtll_p1_fck:
507 clk_put(omap->usbtll_p1_fck);
508
509err_usbhost_p1_fck:
510 clk_put(omap->usbhost_p1_fck);
511
512err_xclk60mhsp2_ck:
513 clk_put(omap->xclk60mhsp2_ck);
514
515err_utmi_p2_fck:
516 clk_put(omap->utmi_p2_fck);
517
518err_xclk60mhsp1_ck:
519 clk_put(omap->xclk60mhsp1_ck);
520
521err_utmi_p1_fck:
522 clk_put(omap->utmi_p1_fck);
523
524err_usbtll_ick:
525 clk_put(omap->usbtll_ick);
526
527err_usbtll_fck:
528 clk_put(omap->usbtll_fck);
529
530err_usbhost_fs_fck:
531 clk_put(omap->usbhost_fs_fck);
532
533err_usbhost_hs_fck:
534 clk_put(omap->usbhost_hs_fck);
535
536err_usbhost_ick:
537 clk_put(omap->usbhost_ick);
538
539err_end:
540 kfree(omap);
541
542end_probe:
543 return ret;
544}
545
546/**
547 * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs
548 * @pdev: USB Host Controller being removed
549 *
550 * Reverses the effect of usbhs_omap_probe().
551 */
552static int __devexit usbhs_omap_remove(struct platform_device *pdev)
553{
554 struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev);
555
556 if (omap->count != 0) {
557 dev_err(&pdev->dev,
558 "Either EHCI or OHCI is still using usbhs core\n");
559 return -EBUSY;
560 }
561
562 iounmap(omap->tll_base);
563 iounmap(omap->uhh_base);
564 clk_put(omap->init_60m_fclk);
565 clk_put(omap->usbtll_p2_fck);
566 clk_put(omap->usbhost_p2_fck);
567 clk_put(omap->usbtll_p1_fck);
568 clk_put(omap->usbhost_p1_fck);
569 clk_put(omap->xclk60mhsp2_ck);
570 clk_put(omap->utmi_p2_fck);
571 clk_put(omap->xclk60mhsp1_ck);
572 clk_put(omap->utmi_p1_fck);
573 clk_put(omap->usbtll_ick);
574 clk_put(omap->usbtll_fck);
575 clk_put(omap->usbhost_fs_fck);
576 clk_put(omap->usbhost_hs_fck);
577 clk_put(omap->usbhost_ick);
578 kfree(omap);
579
580 return 0;
581}
582
583static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
584{
585 switch (pmode) {
586 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
587 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
588 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
589 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
590 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
591 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
592 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
593 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
594 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
595 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
596 return true;
597
598 default:
599 return false;
600 }
601}
602
603/*
604 * convert the port-mode enum to a value we can use in the FSLSMODE
605 * field of USBTLL_CHANNEL_CONF
606 */
607static unsigned ohci_omap3_fslsmode(enum usbhs_omap_port_mode mode)
608{
609 switch (mode) {
610 case OMAP_USBHS_PORT_MODE_UNUSED:
611 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
612 return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
613
614 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
615 return OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM;
616
617 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
618 return OMAP_TLL_FSLSMODE_3PIN_PHY;
619
620 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
621 return OMAP_TLL_FSLSMODE_4PIN_PHY;
622
623 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
624 return OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0;
625
626 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
627 return OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM;
628
629 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
630 return OMAP_TLL_FSLSMODE_3PIN_TLL;
631
632 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
633 return OMAP_TLL_FSLSMODE_4PIN_TLL;
634
635 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
636 return OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0;
637
638 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
639 return OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM;
640 default:
641 pr_warning("Invalid port mode, using default\n");
642 return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
643 }
644}
645
646static void usbhs_omap_tll_init(struct device *dev, u8 tll_channel_count)
647{
648 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
649 struct usbhs_omap_platform_data *pdata = dev->platform_data;
650 unsigned reg;
651 int i;
652
653 /* Program Common TLL register */
654 reg = usbhs_read(omap->tll_base, OMAP_TLL_SHARED_CONF);
655 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
656 | OMAP_TLL_SHARED_CONF_USB_DIVRATION);
657 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
658 reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
659
660 usbhs_write(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
661
662 /* Enable channels now */
663 for (i = 0; i < tll_channel_count; i++) {
664 reg = usbhs_read(omap->tll_base,
665 OMAP_TLL_CHANNEL_CONF(i));
666
667 if (is_ohci_port(pdata->port_mode[i])) {
668 reg |= ohci_omap3_fslsmode(pdata->port_mode[i])
669 << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
670 reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
671 } else if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_TLL) {
672
673 /* Disable AutoIdle, BitStuffing and use SDR Mode */
674 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
675 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
676 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
677
678 reg |= (1 << (i + 1));
679 } else
680 continue;
681
682 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
683 usbhs_write(omap->tll_base,
684 OMAP_TLL_CHANNEL_CONF(i), reg);
685
686 usbhs_writeb(omap->tll_base,
687 OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
688 }
689}
690
691static int usbhs_enable(struct device *dev)
692{
693 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
694 struct usbhs_omap_platform_data *pdata = &omap->platdata;
695 unsigned long flags = 0;
696 int ret = 0;
697 unsigned long timeout;
698 unsigned reg;
699
700 dev_dbg(dev, "starting TI HSUSB Controller\n");
701 if (!pdata) {
702 dev_dbg(dev, "missing platform_data\n");
703 ret = -ENODEV;
704 goto end_enable;
705 }
706
707 spin_lock_irqsave(&omap->lock, flags);
708 if (omap->count > 0)
709 goto end_count;
710
711 clk_enable(omap->usbhost_ick);
712 clk_enable(omap->usbhost_hs_fck);
713 clk_enable(omap->usbhost_fs_fck);
714 clk_enable(omap->usbtll_fck);
715 clk_enable(omap->usbtll_ick);
716
717 if (pdata->ehci_data->phy_reset) {
718 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0])) {
719 gpio_request(pdata->ehci_data->reset_gpio_port[0],
720 "USB1 PHY reset");
721 gpio_direction_output
722 (pdata->ehci_data->reset_gpio_port[0], 1);
723 }
724
725 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1])) {
726 gpio_request(pdata->ehci_data->reset_gpio_port[1],
727 "USB2 PHY reset");
728 gpio_direction_output
729 (pdata->ehci_data->reset_gpio_port[1], 1);
730 }
731
732 /* Hold the PHY in RESET for enough time till DIR is high */
733 udelay(10);
734 }
735
736 omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
737 dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev);
738
739 /* perform TLL soft reset, and wait until reset is complete */
740 usbhs_write(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
741 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
742
743 /* Wait for TLL reset to complete */
744 timeout = jiffies + msecs_to_jiffies(1000);
745 while (!(usbhs_read(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
746 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
747 cpu_relax();
748
749 if (time_after(jiffies, timeout)) {
750 dev_dbg(dev, "operation timed out\n");
751 ret = -EINVAL;
752 goto err_tll;
753 }
754 }
755
756 dev_dbg(dev, "TLL RESET DONE\n");
757
758 /* (1<<3) = no idle mode only for initial debugging */
759 usbhs_write(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
760 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
761 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
762 OMAP_USBTLL_SYSCONFIG_AUTOIDLE);
763
764 /* Put UHH in NoIdle/NoStandby mode */
765 reg = usbhs_read(omap->uhh_base, OMAP_UHH_SYSCONFIG);
766 if (is_omap_usbhs_rev1(omap)) {
767 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
768 | OMAP_UHH_SYSCONFIG_SIDLEMODE
769 | OMAP_UHH_SYSCONFIG_CACTIVITY
770 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
771 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
772
773
774 } else if (is_omap_usbhs_rev2(omap)) {
775 reg &= ~OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR;
776 reg |= OMAP4_UHH_SYSCONFIG_NOIDLE;
777 reg &= ~OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR;
778 reg |= OMAP4_UHH_SYSCONFIG_NOSTDBY;
779 }
780
781 usbhs_write(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
782
783 reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
784 /* setup ULPI bypass and burst configurations */
785 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
786 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
787 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
788 reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK;
789 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
790
791 if (is_omap_usbhs_rev1(omap)) {
792 if (pdata->port_mode[0] == OMAP_USBHS_PORT_MODE_UNUSED)
793 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
794 if (pdata->port_mode[1] == OMAP_USBHS_PORT_MODE_UNUSED)
795 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
796 if (pdata->port_mode[2] == OMAP_USBHS_PORT_MODE_UNUSED)
797 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
798
799 /* Bypass the TLL module for PHY mode operation */
800 if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
801 dev_dbg(dev, "OMAP3 ES version <= ES2.1\n");
802 if (is_ehci_phy_mode(pdata->port_mode[0]) ||
803 is_ehci_phy_mode(pdata->port_mode[1]) ||
804 is_ehci_phy_mode(pdata->port_mode[2]))
805 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
806 else
807 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
808 } else {
809 dev_dbg(dev, "OMAP3 ES version > ES2.1\n");
810 if (is_ehci_phy_mode(pdata->port_mode[0]))
811 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
812 else
813 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
814 if (is_ehci_phy_mode(pdata->port_mode[1]))
815 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
816 else
817 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
818 if (is_ehci_phy_mode(pdata->port_mode[2]))
819 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
820 else
821 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
822 }
823 } else if (is_omap_usbhs_rev2(omap)) {
824 /* Clear port mode fields for PHY mode*/
825 reg &= ~OMAP4_P1_MODE_CLEAR;
826 reg &= ~OMAP4_P2_MODE_CLEAR;
827
828 if (is_ehci_phy_mode(pdata->port_mode[0])) {
829 ret = clk_set_parent(omap->utmi_p1_fck,
830 omap->xclk60mhsp1_ck);
831 if (ret != 0) {
832 dev_err(dev, "xclk60mhsp1_ck set parent"
833 "failed error:%d\n", ret);
834 goto err_tll;
835 }
836 } else if (is_ehci_tll_mode(pdata->port_mode[0])) {
837 ret = clk_set_parent(omap->utmi_p1_fck,
838 omap->init_60m_fclk);
839 if (ret != 0) {
840 dev_err(dev, "init_60m_fclk set parent"
841 "failed error:%d\n", ret);
842 goto err_tll;
843 }
844 clk_enable(omap->usbhost_p1_fck);
845 clk_enable(omap->usbtll_p1_fck);
846 }
847
848 if (is_ehci_phy_mode(pdata->port_mode[1])) {
849 ret = clk_set_parent(omap->utmi_p2_fck,
850 omap->xclk60mhsp2_ck);
851 if (ret != 0) {
852 dev_err(dev, "xclk60mhsp1_ck set parent"
853 "failed error:%d\n", ret);
854 goto err_tll;
855 }
856 } else if (is_ehci_tll_mode(pdata->port_mode[1])) {
857 ret = clk_set_parent(omap->utmi_p2_fck,
858 omap->init_60m_fclk);
859 if (ret != 0) {
860 dev_err(dev, "init_60m_fclk set parent"
861 "failed error:%d\n", ret);
862 goto err_tll;
863 }
864 clk_enable(omap->usbhost_p2_fck);
865 clk_enable(omap->usbtll_p2_fck);
866 }
867
868 clk_enable(omap->utmi_p1_fck);
869 clk_enable(omap->utmi_p2_fck);
870
871 if (is_ehci_tll_mode(pdata->port_mode[0]) ||
872 (is_ohci_port(pdata->port_mode[0])))
873 reg |= OMAP4_P1_MODE_TLL;
874 else if (is_ehci_hsic_mode(pdata->port_mode[0]))
875 reg |= OMAP4_P1_MODE_HSIC;
876
877 if (is_ehci_tll_mode(pdata->port_mode[1]) ||
878 (is_ohci_port(pdata->port_mode[1])))
879 reg |= OMAP4_P2_MODE_TLL;
880 else if (is_ehci_hsic_mode(pdata->port_mode[1]))
881 reg |= OMAP4_P2_MODE_HSIC;
882 }
883
884 usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
885 dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
886
887 if (is_ehci_tll_mode(pdata->port_mode[0]) ||
888 is_ehci_tll_mode(pdata->port_mode[1]) ||
889 is_ehci_tll_mode(pdata->port_mode[2]) ||
890 (is_ohci_port(pdata->port_mode[0])) ||
891 (is_ohci_port(pdata->port_mode[1])) ||
892 (is_ohci_port(pdata->port_mode[2]))) {
893
894 /* Enable UTMI mode for required TLL channels */
895 if (is_omap_usbhs_rev2(omap))
896 usbhs_omap_tll_init(dev, OMAP_REV2_TLL_CHANNEL_COUNT);
897 else
898 usbhs_omap_tll_init(dev, OMAP_TLL_CHANNEL_COUNT);
899 }
900
901 if (pdata->ehci_data->phy_reset) {
902 /* Hold the PHY in RESET for enough time till
903 * PHY is settled and ready
904 */
905 udelay(10);
906
907 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
908 gpio_set_value
909 (pdata->ehci_data->reset_gpio_port[0], 0);
910
911 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
912 gpio_set_value
913 (pdata->ehci_data->reset_gpio_port[1], 0);
914 }
915
916end_count:
917 omap->count++;
918 goto end_enable;
919
920err_tll:
921 if (pdata->ehci_data->phy_reset) {
922 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
923 gpio_free(pdata->ehci_data->reset_gpio_port[0]);
924
925 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
926 gpio_free(pdata->ehci_data->reset_gpio_port[1]);
927 }
928
929 clk_disable(omap->usbtll_ick);
930 clk_disable(omap->usbtll_fck);
931 clk_disable(omap->usbhost_fs_fck);
932 clk_disable(omap->usbhost_hs_fck);
933 clk_disable(omap->usbhost_ick);
934
935end_enable:
936 spin_unlock_irqrestore(&omap->lock, flags);
937 return ret;
938}
939
940static void usbhs_disable(struct device *dev)
941{
942 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
943 struct usbhs_omap_platform_data *pdata = &omap->platdata;
944 unsigned long flags = 0;
945 unsigned long timeout;
946
947 dev_dbg(dev, "stopping TI HSUSB Controller\n");
948
949 spin_lock_irqsave(&omap->lock, flags);
950
951 if (omap->count == 0)
952 goto end_disble;
953
954 omap->count--;
955
956 if (omap->count != 0)
957 goto end_disble;
958
959 /* Reset OMAP modules for insmod/rmmod to work */
960 usbhs_write(omap->uhh_base, OMAP_UHH_SYSCONFIG,
961 is_omap_usbhs_rev2(omap) ?
962 OMAP4_UHH_SYSCONFIG_SOFTRESET :
963 OMAP_UHH_SYSCONFIG_SOFTRESET);
964
965 timeout = jiffies + msecs_to_jiffies(100);
966 while (!(usbhs_read(omap->uhh_base, OMAP_UHH_SYSSTATUS)
967 & (1 << 0))) {
968 cpu_relax();
969
970 if (time_after(jiffies, timeout))
971 dev_dbg(dev, "operation timed out\n");
972 }
973
974 while (!(usbhs_read(omap->uhh_base, OMAP_UHH_SYSSTATUS)
975 & (1 << 1))) {
976 cpu_relax();
977
978 if (time_after(jiffies, timeout))
979 dev_dbg(dev, "operation timed out\n");
980 }
981
982 while (!(usbhs_read(omap->uhh_base, OMAP_UHH_SYSSTATUS)
983 & (1 << 2))) {
984 cpu_relax();
985
986 if (time_after(jiffies, timeout))
987 dev_dbg(dev, "operation timed out\n");
988 }
989
990 usbhs_write(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
991
992 while (!(usbhs_read(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
993 & (1 << 0))) {
994 cpu_relax();
995
996 if (time_after(jiffies, timeout))
997 dev_dbg(dev, "operation timed out\n");
998 }
999
1000 if (pdata->ehci_data->phy_reset) {
1001 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
1002 gpio_free(pdata->ehci_data->reset_gpio_port[0]);
1003
1004 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
1005 gpio_free(pdata->ehci_data->reset_gpio_port[1]);
1006 }
1007
1008 clk_disable(omap->utmi_p2_fck);
1009 clk_disable(omap->utmi_p1_fck);
1010 clk_disable(omap->usbtll_ick);
1011 clk_disable(omap->usbtll_fck);
1012 clk_disable(omap->usbhost_fs_fck);
1013 clk_disable(omap->usbhost_hs_fck);
1014 clk_disable(omap->usbhost_ick);
1015
1016end_disble:
1017 spin_unlock_irqrestore(&omap->lock, flags);
1018}
1019
1020int omap_usbhs_enable(struct device *dev)
1021{
1022 return usbhs_enable(dev->parent);
1023}
1024EXPORT_SYMBOL_GPL(omap_usbhs_enable);
1025
1026void omap_usbhs_disable(struct device *dev)
1027{
1028 usbhs_disable(dev->parent);
1029}
1030EXPORT_SYMBOL_GPL(omap_usbhs_disable);
1031
1032static struct platform_driver usbhs_omap_driver = {
1033 .driver = {
1034 .name = (char *)usbhs_driver_name,
1035 .owner = THIS_MODULE,
1036 },
1037 .remove = __exit_p(usbhs_omap_remove),
1038};
1039
1040MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
1041MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
1042MODULE_LICENSE("GPL v2");
1043MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI");
1044
1045static int __init omap_usbhs_drvinit(void)
1046{
1047 return platform_driver_probe(&usbhs_omap_driver, usbhs_omap_probe);
1048}
1049
1050/*
1051 * init before ehci and ohci drivers;
1052 * The usbhs core driver should be initialized much before
1053 * the omap ehci and ohci probe functions are called.
1054 */
1055fs_initcall(omap_usbhs_drvinit);
1056
1057static void __exit omap_usbhs_drvexit(void)
1058{
1059 platform_driver_unregister(&usbhs_omap_driver);
1060}
1061module_exit(omap_usbhs_drvexit);
diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index a35fe61268de..29ccc0150996 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -255,8 +255,8 @@ static inline void hub_descriptor(struct usb_hub_descriptor *desc)
255 desc->wHubCharacteristics = (__force __u16) 255 desc->wHubCharacteristics = (__force __u16)
256 (__constant_cpu_to_le16(0x0001)); 256 (__constant_cpu_to_le16(0x0001));
257 desc->bNbrPorts = VHCI_NPORTS; 257 desc->bNbrPorts = VHCI_NPORTS;
258 desc->bitmap[0] = 0xff; 258 desc->u.hs.DeviceRemovable[0] = 0xff;
259 desc->bitmap[1] = 0xff; 259 desc->u.hs.DeviceRemovable[1] = 0xff;
260} 260}
261 261
262static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 262static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index 99ac70e32556..b268e9fccb47 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -168,7 +168,6 @@ struct uea_softc {
168 union cmv_dsc cmv_dsc; 168 union cmv_dsc cmv_dsc;
169 169
170 struct work_struct task; 170 struct work_struct task;
171 struct workqueue_struct *work_q;
172 u16 pageno; 171 u16 pageno;
173 u16 ovl; 172 u16 ovl;
174 173
@@ -1879,7 +1878,7 @@ static int uea_start_reset(struct uea_softc *sc)
1879 /* start loading DSP */ 1878 /* start loading DSP */
1880 sc->pageno = 0; 1879 sc->pageno = 0;
1881 sc->ovl = 0; 1880 sc->ovl = 0;
1882 queue_work(sc->work_q, &sc->task); 1881 schedule_work(&sc->task);
1883 1882
1884 /* wait for modem ready CMV */ 1883 /* wait for modem ready CMV */
1885 ret = wait_cmv_ack(sc); 1884 ret = wait_cmv_ack(sc);
@@ -2091,14 +2090,14 @@ static void uea_schedule_load_page_e1(struct uea_softc *sc,
2091{ 2090{
2092 sc->pageno = intr->e1_bSwapPageNo; 2091 sc->pageno = intr->e1_bSwapPageNo;
2093 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4; 2092 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2094 queue_work(sc->work_q, &sc->task); 2093 schedule_work(&sc->task);
2095} 2094}
2096 2095
2097static void uea_schedule_load_page_e4(struct uea_softc *sc, 2096static void uea_schedule_load_page_e4(struct uea_softc *sc,
2098 struct intr_pkt *intr) 2097 struct intr_pkt *intr)
2099{ 2098{
2100 sc->pageno = intr->e4_bSwapPageNo; 2099 sc->pageno = intr->e4_bSwapPageNo;
2101 queue_work(sc->work_q, &sc->task); 2100 schedule_work(&sc->task);
2102} 2101}
2103 2102
2104/* 2103/*
@@ -2170,13 +2169,6 @@ static int uea_boot(struct uea_softc *sc)
2170 2169
2171 init_waitqueue_head(&sc->sync_q); 2170 init_waitqueue_head(&sc->sync_q);
2172 2171
2173 sc->work_q = create_workqueue("ueagle-dsp");
2174 if (!sc->work_q) {
2175 uea_err(INS_TO_USBDEV(sc), "cannot allocate workqueue\n");
2176 uea_leaves(INS_TO_USBDEV(sc));
2177 return -ENOMEM;
2178 }
2179
2180 if (UEA_CHIP_VERSION(sc) == ADI930) 2172 if (UEA_CHIP_VERSION(sc) == ADI930)
2181 load_XILINX_firmware(sc); 2173 load_XILINX_firmware(sc);
2182 2174
@@ -2225,7 +2217,6 @@ err1:
2225 sc->urb_int = NULL; 2217 sc->urb_int = NULL;
2226 kfree(intr); 2218 kfree(intr);
2227err0: 2219err0:
2228 destroy_workqueue(sc->work_q);
2229 uea_leaves(INS_TO_USBDEV(sc)); 2220 uea_leaves(INS_TO_USBDEV(sc));
2230 return -ENOMEM; 2221 return -ENOMEM;
2231} 2222}
@@ -2246,8 +2237,8 @@ static void uea_stop(struct uea_softc *sc)
2246 kfree(sc->urb_int->transfer_buffer); 2237 kfree(sc->urb_int->transfer_buffer);
2247 usb_free_urb(sc->urb_int); 2238 usb_free_urb(sc->urb_int);
2248 2239
2249 /* stop any pending boot process, when no one can schedule work */ 2240 /* flush the work item, when no one can schedule it */
2250 destroy_workqueue(sc->work_q); 2241 flush_work_sync(&sc->task);
2251 2242
2252 if (sc->dsp_firm) 2243 if (sc->dsp_firm)
2253 release_firmware(sc->dsp_firm); 2244 release_firmware(sc->dsp_firm);
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 2c6965484fe8..b0585e623ba9 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -10,7 +10,7 @@
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <asm/io.h> 13#include <linux/io.h>
14#include <linux/dma-mapping.h> 14#include <linux/dma-mapping.h>
15#include <linux/dmapool.h> 15#include <linux/dmapool.h>
16#include <linux/usb.h> 16#include <linux/usb.h>
@@ -22,7 +22,7 @@
22 */ 22 */
23 23
24/* FIXME tune these based on pool statistics ... */ 24/* FIXME tune these based on pool statistics ... */
25static const size_t pool_max [HCD_BUFFER_POOLS] = { 25static const size_t pool_max[HCD_BUFFER_POOLS] = {
26 /* platforms without dma-friendly caches might need to 26 /* platforms without dma-friendly caches might need to
27 * prevent cacheline sharing... 27 * prevent cacheline sharing...
28 */ 28 */
@@ -51,7 +51,7 @@ static const size_t pool_max [HCD_BUFFER_POOLS] = {
51int hcd_buffer_create(struct usb_hcd *hcd) 51int hcd_buffer_create(struct usb_hcd *hcd)
52{ 52{
53 char name[16]; 53 char name[16];
54 int i, size; 54 int i, size;
55 55
56 if (!hcd->self.controller->dma_mask && 56 if (!hcd->self.controller->dma_mask &&
57 !(hcd->driver->flags & HCD_LOCAL_MEM)) 57 !(hcd->driver->flags & HCD_LOCAL_MEM))
@@ -64,7 +64,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
64 snprintf(name, sizeof name, "buffer-%d", size); 64 snprintf(name, sizeof name, "buffer-%d", size);
65 hcd->pool[i] = dma_pool_create(name, hcd->self.controller, 65 hcd->pool[i] = dma_pool_create(name, hcd->self.controller,
66 size, size, 0); 66 size, size, 0);
67 if (!hcd->pool [i]) { 67 if (!hcd->pool[i]) {
68 hcd_buffer_destroy(hcd); 68 hcd_buffer_destroy(hcd);
69 return -ENOMEM; 69 return -ENOMEM;
70 } 70 }
@@ -99,14 +99,14 @@ void hcd_buffer_destroy(struct usb_hcd *hcd)
99 */ 99 */
100 100
101void *hcd_buffer_alloc( 101void *hcd_buffer_alloc(
102 struct usb_bus *bus, 102 struct usb_bus *bus,
103 size_t size, 103 size_t size,
104 gfp_t mem_flags, 104 gfp_t mem_flags,
105 dma_addr_t *dma 105 dma_addr_t *dma
106) 106)
107{ 107{
108 struct usb_hcd *hcd = bus_to_hcd(bus); 108 struct usb_hcd *hcd = bus_to_hcd(bus);
109 int i; 109 int i;
110 110
111 /* some USB hosts just use PIO */ 111 /* some USB hosts just use PIO */
112 if (!bus->controller->dma_mask && 112 if (!bus->controller->dma_mask &&
@@ -116,21 +116,21 @@ void *hcd_buffer_alloc(
116 } 116 }
117 117
118 for (i = 0; i < HCD_BUFFER_POOLS; i++) { 118 for (i = 0; i < HCD_BUFFER_POOLS; i++) {
119 if (size <= pool_max [i]) 119 if (size <= pool_max[i])
120 return dma_pool_alloc(hcd->pool [i], mem_flags, dma); 120 return dma_pool_alloc(hcd->pool[i], mem_flags, dma);
121 } 121 }
122 return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags); 122 return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags);
123} 123}
124 124
125void hcd_buffer_free( 125void hcd_buffer_free(
126 struct usb_bus *bus, 126 struct usb_bus *bus,
127 size_t size, 127 size_t size,
128 void *addr, 128 void *addr,
129 dma_addr_t dma 129 dma_addr_t dma
130) 130)
131{ 131{
132 struct usb_hcd *hcd = bus_to_hcd(bus); 132 struct usb_hcd *hcd = bus_to_hcd(bus);
133 int i; 133 int i;
134 134
135 if (!addr) 135 if (!addr)
136 return; 136 return;
@@ -142,8 +142,8 @@ void hcd_buffer_free(
142 } 142 }
143 143
144 for (i = 0; i < HCD_BUFFER_POOLS; i++) { 144 for (i = 0; i < HCD_BUFFER_POOLS; i++) {
145 if (size <= pool_max [i]) { 145 if (size <= pool_max[i]) {
146 dma_pool_free(hcd->pool [i], addr, dma); 146 dma_pool_free(hcd->pool[i], addr, dma);
147 return; 147 return;
148 } 148 }
149 } 149 }
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index fca61720b873..38072e4e74bd 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1659,6 +1659,11 @@ static int usb_runtime_suspend(struct device *dev)
1659 return -EAGAIN; 1659 return -EAGAIN;
1660 1660
1661 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); 1661 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND);
1662 /* The PM core reacts badly unless the return code is 0,
1663 * -EAGAIN, or -EBUSY, so always return -EBUSY on an error.
1664 */
1665 if (status != 0)
1666 return -EBUSY;
1662 return status; 1667 return status;
1663} 1668}
1664 1669
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 64a035ba2eab..ce22f4a84ed0 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -192,13 +192,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
192 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", 192 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
193 pci_name(dev)); 193 pci_name(dev));
194 retval = -ENODEV; 194 retval = -ENODEV;
195 goto err1; 195 goto disable_pci;
196 } 196 }
197 197
198 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); 198 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
199 if (!hcd) { 199 if (!hcd) {
200 retval = -ENOMEM; 200 retval = -ENOMEM;
201 goto err1; 201 goto disable_pci;
202 } 202 }
203 203
204 if (driver->flags & HCD_MEMORY) { 204 if (driver->flags & HCD_MEMORY) {
@@ -209,13 +209,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
209 driver->description)) { 209 driver->description)) {
210 dev_dbg(&dev->dev, "controller already in use\n"); 210 dev_dbg(&dev->dev, "controller already in use\n");
211 retval = -EBUSY; 211 retval = -EBUSY;
212 goto err2; 212 goto clear_companion;
213 } 213 }
214 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); 214 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
215 if (hcd->regs == NULL) { 215 if (hcd->regs == NULL) {
216 dev_dbg(&dev->dev, "error mapping memory\n"); 216 dev_dbg(&dev->dev, "error mapping memory\n");
217 retval = -EFAULT; 217 retval = -EFAULT;
218 goto err3; 218 goto release_mem_region;
219 } 219 }
220 220
221 } else { 221 } else {
@@ -236,7 +236,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
236 if (region == PCI_ROM_RESOURCE) { 236 if (region == PCI_ROM_RESOURCE) {
237 dev_dbg(&dev->dev, "no i/o regions available\n"); 237 dev_dbg(&dev->dev, "no i/o regions available\n");
238 retval = -EBUSY; 238 retval = -EBUSY;
239 goto err2; 239 goto clear_companion;
240 } 240 }
241 } 241 }
242 242
@@ -244,24 +244,24 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
244 244
245 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); 245 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
246 if (retval != 0) 246 if (retval != 0)
247 goto err4; 247 goto unmap_registers;
248 set_hs_companion(dev, hcd); 248 set_hs_companion(dev, hcd);
249 249
250 if (pci_dev_run_wake(dev)) 250 if (pci_dev_run_wake(dev))
251 pm_runtime_put_noidle(&dev->dev); 251 pm_runtime_put_noidle(&dev->dev);
252 return retval; 252 return retval;
253 253
254 err4: 254unmap_registers:
255 if (driver->flags & HCD_MEMORY) { 255 if (driver->flags & HCD_MEMORY) {
256 iounmap(hcd->regs); 256 iounmap(hcd->regs);
257 err3: 257release_mem_region:
258 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 258 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
259 } else 259 } else
260 release_region(hcd->rsrc_start, hcd->rsrc_len); 260 release_region(hcd->rsrc_start, hcd->rsrc_len);
261 err2: 261clear_companion:
262 clear_hs_companion(dev, hcd); 262 clear_hs_companion(dev, hcd);
263 usb_put_hcd(hcd); 263 usb_put_hcd(hcd);
264 err1: 264disable_pci:
265 pci_disable_device(dev); 265 pci_disable_device(dev);
266 dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); 266 dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval);
267 return retval; 267 return retval;
@@ -363,11 +363,17 @@ static int check_root_hub_suspended(struct device *dev)
363 struct pci_dev *pci_dev = to_pci_dev(dev); 363 struct pci_dev *pci_dev = to_pci_dev(dev);
364 struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 364 struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
365 365
366 if (!(hcd->state == HC_STATE_SUSPENDED || 366 if (HCD_RH_RUNNING(hcd)) {
367 hcd->state == HC_STATE_HALT)) {
368 dev_warn(dev, "Root hub is not suspended\n"); 367 dev_warn(dev, "Root hub is not suspended\n");
369 return -EBUSY; 368 return -EBUSY;
370 } 369 }
370 if (hcd->shared_hcd) {
371 hcd = hcd->shared_hcd;
372 if (HCD_RH_RUNNING(hcd)) {
373 dev_warn(dev, "Secondary root hub is not suspended\n");
374 return -EBUSY;
375 }
376 }
371 return 0; 377 return 0;
372} 378}
373 379
@@ -386,17 +392,22 @@ static int suspend_common(struct device *dev, bool do_wakeup)
386 if (retval) 392 if (retval)
387 return retval; 393 return retval;
388 394
389 if (hcd->driver->pci_suspend) { 395 if (hcd->driver->pci_suspend && !HCD_DEAD(hcd)) {
390 /* Optimization: Don't suspend if a root-hub wakeup is 396 /* Optimization: Don't suspend if a root-hub wakeup is
391 * pending and it would cause the HCD to wake up anyway. 397 * pending and it would cause the HCD to wake up anyway.
392 */ 398 */
393 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) 399 if (do_wakeup && HCD_WAKEUP_PENDING(hcd))
394 return -EBUSY; 400 return -EBUSY;
401 if (do_wakeup && hcd->shared_hcd &&
402 HCD_WAKEUP_PENDING(hcd->shared_hcd))
403 return -EBUSY;
395 retval = hcd->driver->pci_suspend(hcd, do_wakeup); 404 retval = hcd->driver->pci_suspend(hcd, do_wakeup);
396 suspend_report_result(hcd->driver->pci_suspend, retval); 405 suspend_report_result(hcd->driver->pci_suspend, retval);
397 406
398 /* Check again in case wakeup raced with pci_suspend */ 407 /* Check again in case wakeup raced with pci_suspend */
399 if (retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) { 408 if ((retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) ||
409 (retval == 0 && do_wakeup && hcd->shared_hcd &&
410 HCD_WAKEUP_PENDING(hcd->shared_hcd))) {
400 if (hcd->driver->pci_resume) 411 if (hcd->driver->pci_resume)
401 hcd->driver->pci_resume(hcd, false); 412 hcd->driver->pci_resume(hcd, false);
402 retval = -EBUSY; 413 retval = -EBUSY;
@@ -427,7 +438,9 @@ static int resume_common(struct device *dev, int event)
427 struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 438 struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
428 int retval; 439 int retval;
429 440
430 if (hcd->state != HC_STATE_SUSPENDED) { 441 if (HCD_RH_RUNNING(hcd) ||
442 (hcd->shared_hcd &&
443 HCD_RH_RUNNING(hcd->shared_hcd))) {
431 dev_dbg(dev, "can't resume, not suspended!\n"); 444 dev_dbg(dev, "can't resume, not suspended!\n");
432 return 0; 445 return 0;
433 } 446 }
@@ -441,8 +454,10 @@ static int resume_common(struct device *dev, int event)
441 pci_set_master(pci_dev); 454 pci_set_master(pci_dev);
442 455
443 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 456 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
457 if (hcd->shared_hcd)
458 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags);
444 459
445 if (hcd->driver->pci_resume) { 460 if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) {
446 if (event != PM_EVENT_AUTO_RESUME) 461 if (event != PM_EVENT_AUTO_RESUME)
447 wait_for_companions(pci_dev, hcd); 462 wait_for_companions(pci_dev, hcd);
448 463
@@ -450,6 +465,8 @@ static int resume_common(struct device *dev, int event)
450 event == PM_EVENT_RESTORE); 465 event == PM_EVENT_RESTORE);
451 if (retval) { 466 if (retval) {
452 dev_err(dev, "PCI post-resume error %d!\n", retval); 467 dev_err(dev, "PCI post-resume error %d!\n", retval);
468 if (hcd->shared_hcd)
469 usb_hc_died(hcd->shared_hcd);
453 usb_hc_died(hcd); 470 usb_hc_died(hcd);
454 } 471 }
455 } 472 }
@@ -475,10 +492,11 @@ static int hcd_pci_suspend_noirq(struct device *dev)
475 492
476 pci_save_state(pci_dev); 493 pci_save_state(pci_dev);
477 494
478 /* If the root hub is HALTed rather than SUSPENDed, 495 /* If the root hub is dead rather than suspended, disallow remote
479 * disallow remote wakeup. 496 * wakeup. usb_hc_died() should ensure that both hosts are marked as
497 * dying, so we only need to check the primary roothub.
480 */ 498 */
481 if (hcd->state == HC_STATE_HALT) 499 if (HCD_DEAD(hcd))
482 device_set_wakeup_enable(dev, 0); 500 device_set_wakeup_enable(dev, 0);
483 dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); 501 dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev));
484 502
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index e935f71d7a34..02b4dbfa488a 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -297,7 +297,7 @@ static const u8 ss_rh_config_descriptor[] = {
297 /* one configuration */ 297 /* one configuration */
298 0x09, /* __u8 bLength; */ 298 0x09, /* __u8 bLength; */
299 0x02, /* __u8 bDescriptorType; Configuration */ 299 0x02, /* __u8 bDescriptorType; Configuration */
300 0x19, 0x00, /* __le16 wTotalLength; FIXME */ 300 0x1f, 0x00, /* __le16 wTotalLength; */
301 0x01, /* __u8 bNumInterfaces; (1) */ 301 0x01, /* __u8 bNumInterfaces; (1) */
302 0x01, /* __u8 bConfigurationValue; */ 302 0x01, /* __u8 bConfigurationValue; */
303 0x00, /* __u8 iConfiguration; */ 303 0x00, /* __u8 iConfiguration; */
@@ -327,11 +327,14 @@ static const u8 ss_rh_config_descriptor[] = {
327 /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) 327 /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8)
328 * see hub.c:hub_configure() for details. */ 328 * see hub.c:hub_configure() for details. */
329 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, 329 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
330 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ 330 0x0c, /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
331 /* 331
332 * All 3.0 hubs should have an endpoint companion descriptor, 332 /* one SuperSpeed endpoint companion descriptor */
333 * but we're ignoring that for now. FIXME? 333 0x06, /* __u8 ss_bLength */
334 */ 334 0x30, /* __u8 ss_bDescriptorType; SuperSpeed EP Companion */
335 0x00, /* __u8 ss_bMaxBurst; allows 1 TX between ACKs */
336 0x00, /* __u8 ss_bmAttributes; 1 packet per service interval */
337 0x02, 0x00 /* __le16 ss_wBytesPerInterval; 15 bits for max 15 ports */
335}; 338};
336 339
337/*-------------------------------------------------------------------------*/ 340/*-------------------------------------------------------------------------*/
@@ -504,7 +507,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
504 case DeviceRequest | USB_REQ_GET_DESCRIPTOR: 507 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
505 switch (wValue & 0xff00) { 508 switch (wValue & 0xff00) {
506 case USB_DT_DEVICE << 8: 509 case USB_DT_DEVICE << 8:
507 switch (hcd->driver->flags & HCD_MASK) { 510 switch (hcd->speed) {
508 case HCD_USB3: 511 case HCD_USB3:
509 bufp = usb3_rh_dev_descriptor; 512 bufp = usb3_rh_dev_descriptor;
510 break; 513 break;
@@ -522,7 +525,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
522 patch_protocol = 1; 525 patch_protocol = 1;
523 break; 526 break;
524 case USB_DT_CONFIG << 8: 527 case USB_DT_CONFIG << 8:
525 switch (hcd->driver->flags & HCD_MASK) { 528 switch (hcd->speed) {
526 case HCD_USB3: 529 case HCD_USB3:
527 bufp = ss_rh_config_descriptor; 530 bufp = ss_rh_config_descriptor;
528 len = sizeof ss_rh_config_descriptor; 531 len = sizeof ss_rh_config_descriptor;
@@ -983,7 +986,7 @@ static int register_root_hub(struct usb_hcd *hcd)
983 spin_unlock_irq (&hcd_root_hub_lock); 986 spin_unlock_irq (&hcd_root_hub_lock);
984 987
985 /* Did the HC die before the root hub was registered? */ 988 /* Did the HC die before the root hub was registered? */
986 if (hcd->state == HC_STATE_HALT) 989 if (HCD_DEAD(hcd) || hcd->state == HC_STATE_HALT)
987 usb_hc_died (hcd); /* This time clean up */ 990 usb_hc_died (hcd); /* This time clean up */
988 } 991 }
989 992
@@ -1089,13 +1092,10 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb)
1089 * Check the host controller's state and add the URB to the 1092 * Check the host controller's state and add the URB to the
1090 * endpoint's queue. 1093 * endpoint's queue.
1091 */ 1094 */
1092 switch (hcd->state) { 1095 if (HCD_RH_RUNNING(hcd)) {
1093 case HC_STATE_RUNNING:
1094 case HC_STATE_RESUMING:
1095 urb->unlinked = 0; 1096 urb->unlinked = 0;
1096 list_add_tail(&urb->urb_list, &urb->ep->urb_list); 1097 list_add_tail(&urb->urb_list, &urb->ep->urb_list);
1097 break; 1098 } else {
1098 default:
1099 rc = -ESHUTDOWN; 1099 rc = -ESHUTDOWN;
1100 goto done; 1100 goto done;
1101 } 1101 }
@@ -1153,6 +1153,8 @@ int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
1153 dev_warn(hcd->self.controller, "Unlink after no-IRQ? " 1153 dev_warn(hcd->self.controller, "Unlink after no-IRQ? "
1154 "Controller is probably using the wrong IRQ.\n"); 1154 "Controller is probably using the wrong IRQ.\n");
1155 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 1155 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
1156 if (hcd->shared_hcd)
1157 set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags);
1156 } 1158 }
1157 1159
1158 return 0; 1160 return 0;
@@ -1262,7 +1264,7 @@ static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle,
1262 *dma_handle = 0; 1264 *dma_handle = 0;
1263} 1265}
1264 1266
1265void unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) 1267void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb)
1266{ 1268{
1267 if (urb->transfer_flags & URB_SETUP_MAP_SINGLE) 1269 if (urb->transfer_flags & URB_SETUP_MAP_SINGLE)
1268 dma_unmap_single(hcd->self.controller, 1270 dma_unmap_single(hcd->self.controller,
@@ -1279,13 +1281,21 @@ void unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb)
1279 /* Make it safe to call this routine more than once */ 1281 /* Make it safe to call this routine more than once */
1280 urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL); 1282 urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL);
1281} 1283}
1282EXPORT_SYMBOL_GPL(unmap_urb_setup_for_dma); 1284EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_setup_for_dma);
1283 1285
1284void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) 1286static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1287{
1288 if (hcd->driver->unmap_urb_for_dma)
1289 hcd->driver->unmap_urb_for_dma(hcd, urb);
1290 else
1291 usb_hcd_unmap_urb_for_dma(hcd, urb);
1292}
1293
1294void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1285{ 1295{
1286 enum dma_data_direction dir; 1296 enum dma_data_direction dir;
1287 1297
1288 unmap_urb_setup_for_dma(hcd, urb); 1298 usb_hcd_unmap_urb_setup_for_dma(hcd, urb);
1289 1299
1290 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 1300 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1291 if (urb->transfer_flags & URB_DMA_MAP_SG) 1301 if (urb->transfer_flags & URB_DMA_MAP_SG)
@@ -1314,11 +1324,20 @@ void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1314 urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | 1324 urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE |
1315 URB_DMA_MAP_SINGLE | URB_MAP_LOCAL); 1325 URB_DMA_MAP_SINGLE | URB_MAP_LOCAL);
1316} 1326}
1317EXPORT_SYMBOL_GPL(unmap_urb_for_dma); 1327EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_for_dma);
1318 1328
1319static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, 1329static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1320 gfp_t mem_flags) 1330 gfp_t mem_flags)
1321{ 1331{
1332 if (hcd->driver->map_urb_for_dma)
1333 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags);
1334 else
1335 return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
1336}
1337
1338int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1339 gfp_t mem_flags)
1340{
1322 enum dma_data_direction dir; 1341 enum dma_data_direction dir;
1323 int ret = 0; 1342 int ret = 0;
1324 1343
@@ -1410,10 +1429,11 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1410 } 1429 }
1411 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | 1430 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE |
1412 URB_SETUP_MAP_LOCAL))) 1431 URB_SETUP_MAP_LOCAL)))
1413 unmap_urb_for_dma(hcd, urb); 1432 usb_hcd_unmap_urb_for_dma(hcd, urb);
1414 } 1433 }
1415 return ret; 1434 return ret;
1416} 1435}
1436EXPORT_SYMBOL_GPL(usb_hcd_map_urb_for_dma);
1417 1437
1418/*-------------------------------------------------------------------------*/ 1438/*-------------------------------------------------------------------------*/
1419 1439
@@ -1913,7 +1933,7 @@ int usb_hcd_get_frame_number (struct usb_device *udev)
1913{ 1933{
1914 struct usb_hcd *hcd = bus_to_hcd(udev->bus); 1934 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1915 1935
1916 if (!HC_IS_RUNNING (hcd->state)) 1936 if (!HCD_RH_RUNNING(hcd))
1917 return -ESHUTDOWN; 1937 return -ESHUTDOWN;
1918 return hcd->driver->get_frame_number (hcd); 1938 return hcd->driver->get_frame_number (hcd);
1919} 1939}
@@ -1930,9 +1950,15 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
1930 1950
1931 dev_dbg(&rhdev->dev, "bus %s%s\n", 1951 dev_dbg(&rhdev->dev, "bus %s%s\n",
1932 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend"); 1952 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend");
1953 if (HCD_DEAD(hcd)) {
1954 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend");
1955 return 0;
1956 }
1957
1933 if (!hcd->driver->bus_suspend) { 1958 if (!hcd->driver->bus_suspend) {
1934 status = -ENOENT; 1959 status = -ENOENT;
1935 } else { 1960 } else {
1961 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
1936 hcd->state = HC_STATE_QUIESCING; 1962 hcd->state = HC_STATE_QUIESCING;
1937 status = hcd->driver->bus_suspend(hcd); 1963 status = hcd->driver->bus_suspend(hcd);
1938 } 1964 }
@@ -1940,7 +1966,12 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
1940 usb_set_device_state(rhdev, USB_STATE_SUSPENDED); 1966 usb_set_device_state(rhdev, USB_STATE_SUSPENDED);
1941 hcd->state = HC_STATE_SUSPENDED; 1967 hcd->state = HC_STATE_SUSPENDED;
1942 } else { 1968 } else {
1943 hcd->state = old_state; 1969 spin_lock_irq(&hcd_root_hub_lock);
1970 if (!HCD_DEAD(hcd)) {
1971 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
1972 hcd->state = old_state;
1973 }
1974 spin_unlock_irq(&hcd_root_hub_lock);
1944 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", 1975 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
1945 "suspend", status); 1976 "suspend", status);
1946 } 1977 }
@@ -1955,9 +1986,13 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
1955 1986
1956 dev_dbg(&rhdev->dev, "usb %s%s\n", 1987 dev_dbg(&rhdev->dev, "usb %s%s\n",
1957 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); 1988 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume");
1989 if (HCD_DEAD(hcd)) {
1990 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume");
1991 return 0;
1992 }
1958 if (!hcd->driver->bus_resume) 1993 if (!hcd->driver->bus_resume)
1959 return -ENOENT; 1994 return -ENOENT;
1960 if (hcd->state == HC_STATE_RUNNING) 1995 if (HCD_RH_RUNNING(hcd))
1961 return 0; 1996 return 0;
1962 1997
1963 hcd->state = HC_STATE_RESUMING; 1998 hcd->state = HC_STATE_RESUMING;
@@ -1966,10 +2001,15 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
1966 if (status == 0) { 2001 if (status == 0) {
1967 /* TRSMRCY = 10 msec */ 2002 /* TRSMRCY = 10 msec */
1968 msleep(10); 2003 msleep(10);
1969 usb_set_device_state(rhdev, rhdev->actconfig 2004 spin_lock_irq(&hcd_root_hub_lock);
1970 ? USB_STATE_CONFIGURED 2005 if (!HCD_DEAD(hcd)) {
1971 : USB_STATE_ADDRESS); 2006 usb_set_device_state(rhdev, rhdev->actconfig
1972 hcd->state = HC_STATE_RUNNING; 2007 ? USB_STATE_CONFIGURED
2008 : USB_STATE_ADDRESS);
2009 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2010 hcd->state = HC_STATE_RUNNING;
2011 }
2012 spin_unlock_irq(&hcd_root_hub_lock);
1973 } else { 2013 } else {
1974 hcd->state = old_state; 2014 hcd->state = old_state;
1975 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", 2015 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
@@ -2080,12 +2120,14 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd)
2080 */ 2120 */
2081 local_irq_save(flags); 2121 local_irq_save(flags);
2082 2122
2083 if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) { 2123 if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) {
2084 rc = IRQ_NONE; 2124 rc = IRQ_NONE;
2085 } else if (hcd->driver->irq(hcd) == IRQ_NONE) { 2125 } else if (hcd->driver->irq(hcd) == IRQ_NONE) {
2086 rc = IRQ_NONE; 2126 rc = IRQ_NONE;
2087 } else { 2127 } else {
2088 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 2128 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
2129 if (hcd->shared_hcd)
2130 set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags);
2089 2131
2090 if (unlikely(hcd->state == HC_STATE_HALT)) 2132 if (unlikely(hcd->state == HC_STATE_HALT))
2091 usb_hc_died(hcd); 2133 usb_hc_died(hcd);
@@ -2105,7 +2147,9 @@ EXPORT_SYMBOL_GPL(usb_hcd_irq);
2105 * 2147 *
2106 * This is called by bus glue to report a USB host controller that died 2148 * This is called by bus glue to report a USB host controller that died
2107 * while operations may still have been pending. It's called automatically 2149 * while operations may still have been pending. It's called automatically
2108 * by the PCI glue, so only glue for non-PCI busses should need to call it. 2150 * by the PCI glue, so only glue for non-PCI busses should need to call it.
2151 *
2152 * Only call this function with the primary HCD.
2109 */ 2153 */
2110void usb_hc_died (struct usb_hcd *hcd) 2154void usb_hc_died (struct usb_hcd *hcd)
2111{ 2155{
@@ -2114,6 +2158,8 @@ void usb_hc_died (struct usb_hcd *hcd)
2114 dev_err (hcd->self.controller, "HC died; cleaning up\n"); 2158 dev_err (hcd->self.controller, "HC died; cleaning up\n");
2115 2159
2116 spin_lock_irqsave (&hcd_root_hub_lock, flags); 2160 spin_lock_irqsave (&hcd_root_hub_lock, flags);
2161 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2162 set_bit(HCD_FLAG_DEAD, &hcd->flags);
2117 if (hcd->rh_registered) { 2163 if (hcd->rh_registered) {
2118 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2164 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2119 2165
@@ -2122,17 +2168,31 @@ void usb_hc_died (struct usb_hcd *hcd)
2122 USB_STATE_NOTATTACHED); 2168 USB_STATE_NOTATTACHED);
2123 usb_kick_khubd (hcd->self.root_hub); 2169 usb_kick_khubd (hcd->self.root_hub);
2124 } 2170 }
2171 if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) {
2172 hcd = hcd->shared_hcd;
2173 if (hcd->rh_registered) {
2174 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2175
2176 /* make khubd clean up old urbs and devices */
2177 usb_set_device_state(hcd->self.root_hub,
2178 USB_STATE_NOTATTACHED);
2179 usb_kick_khubd(hcd->self.root_hub);
2180 }
2181 }
2125 spin_unlock_irqrestore (&hcd_root_hub_lock, flags); 2182 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
2183 /* Make sure that the other roothub is also deallocated. */
2126} 2184}
2127EXPORT_SYMBOL_GPL (usb_hc_died); 2185EXPORT_SYMBOL_GPL (usb_hc_died);
2128 2186
2129/*-------------------------------------------------------------------------*/ 2187/*-------------------------------------------------------------------------*/
2130 2188
2131/** 2189/**
2132 * usb_create_hcd - create and initialize an HCD structure 2190 * usb_create_shared_hcd - create and initialize an HCD structure
2133 * @driver: HC driver that will use this hcd 2191 * @driver: HC driver that will use this hcd
2134 * @dev: device for this HC, stored in hcd->self.controller 2192 * @dev: device for this HC, stored in hcd->self.controller
2135 * @bus_name: value to store in hcd->self.bus_name 2193 * @bus_name: value to store in hcd->self.bus_name
2194 * @primary_hcd: a pointer to the usb_hcd structure that is sharing the
2195 * PCI device. Only allocate certain resources for the primary HCD
2136 * Context: !in_interrupt() 2196 * Context: !in_interrupt()
2137 * 2197 *
2138 * Allocate a struct usb_hcd, with extra space at the end for the 2198 * Allocate a struct usb_hcd, with extra space at the end for the
@@ -2141,8 +2201,9 @@ EXPORT_SYMBOL_GPL (usb_hc_died);
2141 * 2201 *
2142 * If memory is unavailable, returns NULL. 2202 * If memory is unavailable, returns NULL.
2143 */ 2203 */
2144struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, 2204struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
2145 struct device *dev, const char *bus_name) 2205 struct device *dev, const char *bus_name,
2206 struct usb_hcd *primary_hcd)
2146{ 2207{
2147 struct usb_hcd *hcd; 2208 struct usb_hcd *hcd;
2148 2209
@@ -2151,7 +2212,24 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
2151 dev_dbg (dev, "hcd alloc failed\n"); 2212 dev_dbg (dev, "hcd alloc failed\n");
2152 return NULL; 2213 return NULL;
2153 } 2214 }
2154 dev_set_drvdata(dev, hcd); 2215 if (primary_hcd == NULL) {
2216 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex),
2217 GFP_KERNEL);
2218 if (!hcd->bandwidth_mutex) {
2219 kfree(hcd);
2220 dev_dbg(dev, "hcd bandwidth mutex alloc failed\n");
2221 return NULL;
2222 }
2223 mutex_init(hcd->bandwidth_mutex);
2224 dev_set_drvdata(dev, hcd);
2225 } else {
2226 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex;
2227 hcd->primary_hcd = primary_hcd;
2228 primary_hcd->primary_hcd = primary_hcd;
2229 hcd->shared_hcd = primary_hcd;
2230 primary_hcd->shared_hcd = hcd;
2231 }
2232
2155 kref_init(&hcd->kref); 2233 kref_init(&hcd->kref);
2156 2234
2157 usb_bus_init(&hcd->self); 2235 usb_bus_init(&hcd->self);
@@ -2165,19 +2243,53 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
2165#ifdef CONFIG_USB_SUSPEND 2243#ifdef CONFIG_USB_SUSPEND
2166 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); 2244 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
2167#endif 2245#endif
2168 mutex_init(&hcd->bandwidth_mutex);
2169 2246
2170 hcd->driver = driver; 2247 hcd->driver = driver;
2248 hcd->speed = driver->flags & HCD_MASK;
2171 hcd->product_desc = (driver->product_desc) ? driver->product_desc : 2249 hcd->product_desc = (driver->product_desc) ? driver->product_desc :
2172 "USB Host Controller"; 2250 "USB Host Controller";
2173 return hcd; 2251 return hcd;
2174} 2252}
2253EXPORT_SYMBOL_GPL(usb_create_shared_hcd);
2254
2255/**
2256 * usb_create_hcd - create and initialize an HCD structure
2257 * @driver: HC driver that will use this hcd
2258 * @dev: device for this HC, stored in hcd->self.controller
2259 * @bus_name: value to store in hcd->self.bus_name
2260 * Context: !in_interrupt()
2261 *
2262 * Allocate a struct usb_hcd, with extra space at the end for the
2263 * HC driver's private data. Initialize the generic members of the
2264 * hcd structure.
2265 *
2266 * If memory is unavailable, returns NULL.
2267 */
2268struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
2269 struct device *dev, const char *bus_name)
2270{
2271 return usb_create_shared_hcd(driver, dev, bus_name, NULL);
2272}
2175EXPORT_SYMBOL_GPL(usb_create_hcd); 2273EXPORT_SYMBOL_GPL(usb_create_hcd);
2176 2274
2275/*
2276 * Roothubs that share one PCI device must also share the bandwidth mutex.
2277 * Don't deallocate the bandwidth_mutex until the last shared usb_hcd is
2278 * deallocated.
2279 *
2280 * Make sure to only deallocate the bandwidth_mutex when the primary HCD is
2281 * freed. When hcd_release() is called for the non-primary HCD, set the
2282 * primary_hcd's shared_hcd pointer to null (since the non-primary HCD will be
2283 * freed shortly).
2284 */
2177static void hcd_release (struct kref *kref) 2285static void hcd_release (struct kref *kref)
2178{ 2286{
2179 struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); 2287 struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref);
2180 2288
2289 if (usb_hcd_is_primary_hcd(hcd))
2290 kfree(hcd->bandwidth_mutex);
2291 else
2292 hcd->shared_hcd->shared_hcd = NULL;
2181 kfree(hcd); 2293 kfree(hcd);
2182} 2294}
2183 2295
@@ -2196,6 +2308,54 @@ void usb_put_hcd (struct usb_hcd *hcd)
2196} 2308}
2197EXPORT_SYMBOL_GPL(usb_put_hcd); 2309EXPORT_SYMBOL_GPL(usb_put_hcd);
2198 2310
2311int usb_hcd_is_primary_hcd(struct usb_hcd *hcd)
2312{
2313 if (!hcd->primary_hcd)
2314 return 1;
2315 return hcd == hcd->primary_hcd;
2316}
2317EXPORT_SYMBOL_GPL(usb_hcd_is_primary_hcd);
2318
2319static int usb_hcd_request_irqs(struct usb_hcd *hcd,
2320 unsigned int irqnum, unsigned long irqflags)
2321{
2322 int retval;
2323
2324 if (hcd->driver->irq) {
2325
2326 /* IRQF_DISABLED doesn't work as advertised when used together
2327 * with IRQF_SHARED. As usb_hcd_irq() will always disable
2328 * interrupts we can remove it here.
2329 */
2330 if (irqflags & IRQF_SHARED)
2331 irqflags &= ~IRQF_DISABLED;
2332
2333 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
2334 hcd->driver->description, hcd->self.busnum);
2335 retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
2336 hcd->irq_descr, hcd);
2337 if (retval != 0) {
2338 dev_err(hcd->self.controller,
2339 "request interrupt %d failed\n",
2340 irqnum);
2341 return retval;
2342 }
2343 hcd->irq = irqnum;
2344 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum,
2345 (hcd->driver->flags & HCD_MEMORY) ?
2346 "io mem" : "io base",
2347 (unsigned long long)hcd->rsrc_start);
2348 } else {
2349 hcd->irq = -1;
2350 if (hcd->rsrc_start)
2351 dev_info(hcd->self.controller, "%s 0x%08llx\n",
2352 (hcd->driver->flags & HCD_MEMORY) ?
2353 "io mem" : "io base",
2354 (unsigned long long)hcd->rsrc_start);
2355 }
2356 return 0;
2357}
2358
2199/** 2359/**
2200 * usb_add_hcd - finish generic HCD structure initialization and register 2360 * usb_add_hcd - finish generic HCD structure initialization and register
2201 * @hcd: the usb_hcd structure to initialize 2361 * @hcd: the usb_hcd structure to initialize
@@ -2236,7 +2396,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2236 } 2396 }
2237 hcd->self.root_hub = rhdev; 2397 hcd->self.root_hub = rhdev;
2238 2398
2239 switch (hcd->driver->flags & HCD_MASK) { 2399 switch (hcd->speed) {
2240 case HCD_USB11: 2400 case HCD_USB11:
2241 rhdev->speed = USB_SPEED_FULL; 2401 rhdev->speed = USB_SPEED_FULL;
2242 break; 2402 break;
@@ -2256,6 +2416,12 @@ int usb_add_hcd(struct usb_hcd *hcd,
2256 */ 2416 */
2257 device_init_wakeup(&rhdev->dev, 1); 2417 device_init_wakeup(&rhdev->dev, 1);
2258 2418
2419 /* HCD_FLAG_RH_RUNNING doesn't matter until the root hub is
2420 * registered. But since the controller can die at any time,
2421 * let's initialize the flag before touching the hardware.
2422 */
2423 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2424
2259 /* "reset" is misnamed; its role is now one-time init. the controller 2425 /* "reset" is misnamed; its role is now one-time init. the controller
2260 * should already have been reset (and boot firmware kicked off etc). 2426 * should already have been reset (and boot firmware kicked off etc).
2261 */ 2427 */
@@ -2271,38 +2437,15 @@ int usb_add_hcd(struct usb_hcd *hcd,
2271 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); 2437 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
2272 2438
2273 /* enable irqs just before we start the controller */ 2439 /* enable irqs just before we start the controller */
2274 if (hcd->driver->irq) { 2440 if (usb_hcd_is_primary_hcd(hcd)) {
2275 2441 retval = usb_hcd_request_irqs(hcd, irqnum, irqflags);
2276 /* IRQF_DISABLED doesn't work as advertised when used together 2442 if (retval)
2277 * with IRQF_SHARED. As usb_hcd_irq() will always disable
2278 * interrupts we can remove it here.
2279 */
2280 if (irqflags & IRQF_SHARED)
2281 irqflags &= ~IRQF_DISABLED;
2282
2283 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
2284 hcd->driver->description, hcd->self.busnum);
2285 if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
2286 hcd->irq_descr, hcd)) != 0) {
2287 dev_err(hcd->self.controller,
2288 "request interrupt %d failed\n", irqnum);
2289 goto err_request_irq; 2443 goto err_request_irq;
2290 }
2291 hcd->irq = irqnum;
2292 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum,
2293 (hcd->driver->flags & HCD_MEMORY) ?
2294 "io mem" : "io base",
2295 (unsigned long long)hcd->rsrc_start);
2296 } else {
2297 hcd->irq = -1;
2298 if (hcd->rsrc_start)
2299 dev_info(hcd->self.controller, "%s 0x%08llx\n",
2300 (hcd->driver->flags & HCD_MEMORY) ?
2301 "io mem" : "io base",
2302 (unsigned long long)hcd->rsrc_start);
2303 } 2444 }
2304 2445
2305 if ((retval = hcd->driver->start(hcd)) < 0) { 2446 hcd->state = HC_STATE_RUNNING;
2447 retval = hcd->driver->start(hcd);
2448 if (retval < 0) {
2306 dev_err(hcd->self.controller, "startup error %d\n", retval); 2449 dev_err(hcd->self.controller, "startup error %d\n", retval);
2307 goto err_hcd_driver_start; 2450 goto err_hcd_driver_start;
2308 } 2451 }
@@ -2323,6 +2466,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2323 return retval; 2466 return retval;
2324 2467
2325error_create_attr_group: 2468error_create_attr_group:
2469 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2326 if (HC_IS_RUNNING(hcd->state)) 2470 if (HC_IS_RUNNING(hcd->state))
2327 hcd->state = HC_STATE_QUIESCING; 2471 hcd->state = HC_STATE_QUIESCING;
2328 spin_lock_irq(&hcd_root_hub_lock); 2472 spin_lock_irq(&hcd_root_hub_lock);
@@ -2344,7 +2488,7 @@ err_register_root_hub:
2344 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2488 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2345 del_timer_sync(&hcd->rh_timer); 2489 del_timer_sync(&hcd->rh_timer);
2346err_hcd_driver_start: 2490err_hcd_driver_start:
2347 if (hcd->irq >= 0) 2491 if (usb_hcd_is_primary_hcd(hcd) && hcd->irq >= 0)
2348 free_irq(irqnum, hcd); 2492 free_irq(irqnum, hcd);
2349err_request_irq: 2493err_request_irq:
2350err_hcd_driver_setup: 2494err_hcd_driver_setup:
@@ -2375,6 +2519,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2375 usb_get_dev(rhdev); 2519 usb_get_dev(rhdev);
2376 sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group); 2520 sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group);
2377 2521
2522 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2378 if (HC_IS_RUNNING (hcd->state)) 2523 if (HC_IS_RUNNING (hcd->state))
2379 hcd->state = HC_STATE_QUIESCING; 2524 hcd->state = HC_STATE_QUIESCING;
2380 2525
@@ -2407,8 +2552,10 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2407 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2552 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2408 del_timer_sync(&hcd->rh_timer); 2553 del_timer_sync(&hcd->rh_timer);
2409 2554
2410 if (hcd->irq >= 0) 2555 if (usb_hcd_is_primary_hcd(hcd)) {
2411 free_irq(hcd->irq, hcd); 2556 if (hcd->irq >= 0)
2557 free_irq(hcd->irq, hcd);
2558 }
2412 2559
2413 usb_put_dev(hcd->self.root_hub); 2560 usb_put_dev(hcd->self.root_hub);
2414 usb_deregister_bus(&hcd->self); 2561 usb_deregister_bus(&hcd->self);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 19d3435e6140..564eaa5525d7 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -82,6 +82,10 @@ struct usb_hub {
82 void **port_owners; 82 void **port_owners;
83}; 83};
84 84
85static inline int hub_is_superspeed(struct usb_device *hdev)
86{
87 return (hdev->descriptor.bDeviceProtocol == 3);
88}
85 89
86/* Protect struct usb_device->state and ->children members 90/* Protect struct usb_device->state and ->children members
87 * Note: Both are also protected by ->dev.sem, except that ->state can 91 * Note: Both are also protected by ->dev.sem, except that ->state can
@@ -151,14 +155,14 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem);
151 155
152static int usb_reset_and_verify_device(struct usb_device *udev); 156static int usb_reset_and_verify_device(struct usb_device *udev);
153 157
154static inline char *portspeed(int portstatus) 158static inline char *portspeed(struct usb_hub *hub, int portstatus)
155{ 159{
160 if (hub_is_superspeed(hub->hdev))
161 return "5.0 Gb/s";
156 if (portstatus & USB_PORT_STAT_HIGH_SPEED) 162 if (portstatus & USB_PORT_STAT_HIGH_SPEED)
157 return "480 Mb/s"; 163 return "480 Mb/s";
158 else if (portstatus & USB_PORT_STAT_LOW_SPEED) 164 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
159 return "1.5 Mb/s"; 165 return "1.5 Mb/s";
160 else if (portstatus & USB_PORT_STAT_SUPER_SPEED)
161 return "5.0 Gb/s";
162 else 166 else
163 return "12 Mb/s"; 167 return "12 Mb/s";
164} 168}
@@ -172,14 +176,23 @@ static struct usb_hub *hdev_to_hub(struct usb_device *hdev)
172} 176}
173 177
174/* USB 2.0 spec Section 11.24.4.5 */ 178/* USB 2.0 spec Section 11.24.4.5 */
175static int get_hub_descriptor(struct usb_device *hdev, void *data, int size) 179static int get_hub_descriptor(struct usb_device *hdev, void *data)
176{ 180{
177 int i, ret; 181 int i, ret, size;
182 unsigned dtype;
183
184 if (hub_is_superspeed(hdev)) {
185 dtype = USB_DT_SS_HUB;
186 size = USB_DT_SS_HUB_SIZE;
187 } else {
188 dtype = USB_DT_HUB;
189 size = sizeof(struct usb_hub_descriptor);
190 }
178 191
179 for (i = 0; i < 3; i++) { 192 for (i = 0; i < 3; i++) {
180 ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), 193 ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0),
181 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, 194 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB,
182 USB_DT_HUB << 8, 0, data, size, 195 dtype << 8, 0, data, size,
183 USB_CTRL_GET_TIMEOUT); 196 USB_CTRL_GET_TIMEOUT);
184 if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2)) 197 if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2))
185 return ret; 198 return ret;
@@ -365,6 +378,16 @@ static int hub_port_status(struct usb_hub *hub, int port1,
365 } else { 378 } else {
366 *status = le16_to_cpu(hub->status->port.wPortStatus); 379 *status = le16_to_cpu(hub->status->port.wPortStatus);
367 *change = le16_to_cpu(hub->status->port.wPortChange); 380 *change = le16_to_cpu(hub->status->port.wPortChange);
381
382 if ((hub->hdev->parent != NULL) &&
383 hub_is_superspeed(hub->hdev)) {
384 /* Translate the USB 3 port status */
385 u16 tmp = *status & USB_SS_PORT_STAT_MASK;
386 if (*status & USB_SS_PORT_STAT_POWER)
387 tmp |= USB_PORT_STAT_POWER;
388 *status = tmp;
389 }
390
368 ret = 0; 391 ret = 0;
369 } 392 }
370 mutex_unlock(&hub->status_mutex); 393 mutex_unlock(&hub->status_mutex);
@@ -607,7 +630,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
607 if (hdev->children[port1-1] && set_state) 630 if (hdev->children[port1-1] && set_state)
608 usb_set_device_state(hdev->children[port1-1], 631 usb_set_device_state(hdev->children[port1-1],
609 USB_STATE_NOTATTACHED); 632 USB_STATE_NOTATTACHED);
610 if (!hub->error) 633 if (!hub->error && !hub_is_superspeed(hub->hdev))
611 ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); 634 ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE);
612 if (ret) 635 if (ret)
613 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", 636 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
@@ -616,7 +639,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
616} 639}
617 640
618/* 641/*
619 * Disable a port and mark a logical connnect-change event, so that some 642 * Disable a port and mark a logical connect-change event, so that some
620 * time later khubd will disconnect() any existing usb_device on the port 643 * time later khubd will disconnect() any existing usb_device on the port
621 * and will re-enumerate if there actually is a device attached. 644 * and will re-enumerate if there actually is a device attached.
622 */ 645 */
@@ -769,12 +792,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
769 * USB3 protocol ports will automatically transition 792 * USB3 protocol ports will automatically transition
770 * to Enabled state when detect an USB3.0 device attach. 793 * to Enabled state when detect an USB3.0 device attach.
771 * Do not disable USB3 protocol ports. 794 * Do not disable USB3 protocol ports.
772 * FIXME: USB3 root hub and external hubs are treated
773 * differently here.
774 */ 795 */
775 if (hdev->descriptor.bDeviceProtocol != 3 || 796 if (!hub_is_superspeed(hdev)) {
776 (!hdev->parent &&
777 !(portstatus & USB_PORT_STAT_SUPER_SPEED))) {
778 clear_port_feature(hdev, port1, 797 clear_port_feature(hdev, port1,
779 USB_PORT_FEAT_ENABLE); 798 USB_PORT_FEAT_ENABLE);
780 portstatus &= ~USB_PORT_STAT_ENABLE; 799 portstatus &= ~USB_PORT_STAT_ENABLE;
@@ -795,6 +814,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
795 clear_port_feature(hub->hdev, port1, 814 clear_port_feature(hub->hdev, port1,
796 USB_PORT_FEAT_C_ENABLE); 815 USB_PORT_FEAT_C_ENABLE);
797 } 816 }
817 if (portchange & USB_PORT_STAT_C_LINK_STATE) {
818 need_debounce_delay = true;
819 clear_port_feature(hub->hdev, port1,
820 USB_PORT_FEAT_C_PORT_LINK_STATE);
821 }
798 822
799 /* We can forget about a "removed" device when there's a 823 /* We can forget about a "removed" device when there's a
800 * physical disconnect or the connect status changes. 824 * physical disconnect or the connect status changes.
@@ -964,12 +988,23 @@ static int hub_configure(struct usb_hub *hub,
964 goto fail; 988 goto fail;
965 } 989 }
966 990
991 if (hub_is_superspeed(hdev) && (hdev->parent != NULL)) {
992 ret = usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
993 HUB_SET_DEPTH, USB_RT_HUB,
994 hdev->level - 1, 0, NULL, 0,
995 USB_CTRL_SET_TIMEOUT);
996
997 if (ret < 0) {
998 message = "can't set hub depth";
999 goto fail;
1000 }
1001 }
1002
967 /* Request the entire hub descriptor. 1003 /* Request the entire hub descriptor.
968 * hub->descriptor can handle USB_MAXCHILDREN ports, 1004 * hub->descriptor can handle USB_MAXCHILDREN ports,
969 * but the hub can/will return fewer bytes here. 1005 * but the hub can/will return fewer bytes here.
970 */ 1006 */
971 ret = get_hub_descriptor(hdev, hub->descriptor, 1007 ret = get_hub_descriptor(hdev, hub->descriptor);
972 sizeof(*hub->descriptor));
973 if (ret < 0) { 1008 if (ret < 0) {
974 message = "can't read hub descriptor"; 1009 message = "can't read hub descriptor";
975 goto fail; 1010 goto fail;
@@ -991,12 +1026,14 @@ static int hub_configure(struct usb_hub *hub,
991 1026
992 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); 1027 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
993 1028
994 if (wHubCharacteristics & HUB_CHAR_COMPOUND) { 1029 /* FIXME for USB 3.0, skip for now */
1030 if ((wHubCharacteristics & HUB_CHAR_COMPOUND) &&
1031 !(hub_is_superspeed(hdev))) {
995 int i; 1032 int i;
996 char portstr [USB_MAXCHILDREN + 1]; 1033 char portstr [USB_MAXCHILDREN + 1];
997 1034
998 for (i = 0; i < hdev->maxchild; i++) 1035 for (i = 0; i < hdev->maxchild; i++)
999 portstr[i] = hub->descriptor->DeviceRemovable 1036 portstr[i] = hub->descriptor->u.hs.DeviceRemovable
1000 [((i + 1) / 8)] & (1 << ((i + 1) % 8)) 1037 [((i + 1) / 8)] & (1 << ((i + 1) % 8))
1001 ? 'F' : 'R'; 1038 ? 'F' : 'R';
1002 portstr[hdev->maxchild] = 0; 1039 portstr[hdev->maxchild] = 0;
@@ -1253,8 +1290,14 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
1253 desc = intf->cur_altsetting; 1290 desc = intf->cur_altsetting;
1254 hdev = interface_to_usbdev(intf); 1291 hdev = interface_to_usbdev(intf);
1255 1292
1256 /* Hubs have proper suspend/resume support */ 1293 /* Hubs have proper suspend/resume support. USB 3.0 device suspend is
1257 usb_enable_autosuspend(hdev); 1294 * different from USB 2.0/1.1 device suspend, and unfortunately we
1295 * don't support it yet. So leave autosuspend disabled for USB 3.0
1296 * external hubs for now. Enable autosuspend for USB 3.0 roothubs,
1297 * since that isn't a "real" hub.
1298 */
1299 if (!hub_is_superspeed(hdev) || !hdev->parent)
1300 usb_enable_autosuspend(hdev);
1258 1301
1259 if (hdev->level == MAX_TOPO_LEVEL) { 1302 if (hdev->level == MAX_TOPO_LEVEL) {
1260 dev_err(&intf->dev, 1303 dev_err(&intf->dev,
@@ -1501,6 +1544,13 @@ void usb_set_device_state(struct usb_device *udev,
1501EXPORT_SYMBOL_GPL(usb_set_device_state); 1544EXPORT_SYMBOL_GPL(usb_set_device_state);
1502 1545
1503/* 1546/*
1547 * Choose a device number.
1548 *
1549 * Device numbers are used as filenames in usbfs. On USB-1.1 and
1550 * USB-2.0 buses they are also used as device addresses, however on
1551 * USB-3.0 buses the address is assigned by the controller hardware
1552 * and it usually is not the same as the device number.
1553 *
1504 * WUSB devices are simple: they have no hubs behind, so the mapping 1554 * WUSB devices are simple: they have no hubs behind, so the mapping
1505 * device <-> virtual port number becomes 1:1. Why? to simplify the 1555 * device <-> virtual port number becomes 1:1. Why? to simplify the
1506 * life of the device connection logic in 1556 * life of the device connection logic in
@@ -1522,7 +1572,7 @@ EXPORT_SYMBOL_GPL(usb_set_device_state);
1522 * the HCD must setup data structures before issuing a set address 1572 * the HCD must setup data structures before issuing a set address
1523 * command to the hardware. 1573 * command to the hardware.
1524 */ 1574 */
1525static void choose_address(struct usb_device *udev) 1575static void choose_devnum(struct usb_device *udev)
1526{ 1576{
1527 int devnum; 1577 int devnum;
1528 struct usb_bus *bus = udev->bus; 1578 struct usb_bus *bus = udev->bus;
@@ -1547,7 +1597,7 @@ static void choose_address(struct usb_device *udev)
1547 } 1597 }
1548} 1598}
1549 1599
1550static void release_address(struct usb_device *udev) 1600static void release_devnum(struct usb_device *udev)
1551{ 1601{
1552 if (udev->devnum > 0) { 1602 if (udev->devnum > 0) {
1553 clear_bit(udev->devnum, udev->bus->devmap.devicemap); 1603 clear_bit(udev->devnum, udev->bus->devmap.devicemap);
@@ -1555,7 +1605,7 @@ static void release_address(struct usb_device *udev)
1555 } 1605 }
1556} 1606}
1557 1607
1558static void update_address(struct usb_device *udev, int devnum) 1608static void update_devnum(struct usb_device *udev, int devnum)
1559{ 1609{
1560 /* The address for a WUSB device is managed by wusbcore. */ 1610 /* The address for a WUSB device is managed by wusbcore. */
1561 if (!udev->wusb) 1611 if (!udev->wusb)
@@ -1602,7 +1652,8 @@ void usb_disconnect(struct usb_device **pdev)
1602 * this quiesces everyting except pending urbs. 1652 * this quiesces everyting except pending urbs.
1603 */ 1653 */
1604 usb_set_device_state(udev, USB_STATE_NOTATTACHED); 1654 usb_set_device_state(udev, USB_STATE_NOTATTACHED);
1605 dev_info (&udev->dev, "USB disconnect, address %d\n", udev->devnum); 1655 dev_info(&udev->dev, "USB disconnect, device number %d\n",
1656 udev->devnum);
1606 1657
1607 usb_lock_device(udev); 1658 usb_lock_device(udev);
1608 1659
@@ -1632,7 +1683,7 @@ void usb_disconnect(struct usb_device **pdev)
1632 /* Free the device number and delete the parent's children[] 1683 /* Free the device number and delete the parent's children[]
1633 * (or root_hub) pointer. 1684 * (or root_hub) pointer.
1634 */ 1685 */
1635 release_address(udev); 1686 release_devnum(udev);
1636 1687
1637 /* Avoid races with recursively_mark_NOTATTACHED() */ 1688 /* Avoid races with recursively_mark_NOTATTACHED() */
1638 spin_lock_irq(&device_state_lock); 1689 spin_lock_irq(&device_state_lock);
@@ -2017,7 +2068,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
2017 (portstatus & USB_PORT_STAT_ENABLE)) { 2068 (portstatus & USB_PORT_STAT_ENABLE)) {
2018 if (hub_is_wusb(hub)) 2069 if (hub_is_wusb(hub))
2019 udev->speed = USB_SPEED_WIRELESS; 2070 udev->speed = USB_SPEED_WIRELESS;
2020 else if (portstatus & USB_PORT_STAT_SUPER_SPEED) 2071 else if (hub_is_superspeed(hub->hdev))
2021 udev->speed = USB_SPEED_SUPER; 2072 udev->speed = USB_SPEED_SUPER;
2022 else if (portstatus & USB_PORT_STAT_HIGH_SPEED) 2073 else if (portstatus & USB_PORT_STAT_HIGH_SPEED)
2023 udev->speed = USB_SPEED_HIGH; 2074 udev->speed = USB_SPEED_HIGH;
@@ -2073,7 +2124,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
2073 case 0: 2124 case 0:
2074 /* TRSTRCY = 10 ms; plus some extra */ 2125 /* TRSTRCY = 10 ms; plus some extra */
2075 msleep(10 + 40); 2126 msleep(10 + 40);
2076 update_address(udev, 0); 2127 update_devnum(udev, 0);
2077 if (hcd->driver->reset_device) { 2128 if (hcd->driver->reset_device) {
2078 status = hcd->driver->reset_device(hcd, udev); 2129 status = hcd->driver->reset_device(hcd, udev);
2079 if (status < 0) { 2130 if (status < 0) {
@@ -2636,7 +2687,7 @@ static int hub_set_address(struct usb_device *udev, int devnum)
2636 USB_REQ_SET_ADDRESS, 0, devnum, 0, 2687 USB_REQ_SET_ADDRESS, 0, devnum, 0,
2637 NULL, 0, USB_CTRL_SET_TIMEOUT); 2688 NULL, 0, USB_CTRL_SET_TIMEOUT);
2638 if (retval == 0) { 2689 if (retval == 0) {
2639 update_address(udev, devnum); 2690 update_devnum(udev, devnum);
2640 /* Device now using proper address. */ 2691 /* Device now using proper address. */
2641 usb_set_device_state(udev, USB_STATE_ADDRESS); 2692 usb_set_device_state(udev, USB_STATE_ADDRESS);
2642 usb_ep0_reinit(udev); 2693 usb_ep0_reinit(udev);
@@ -2741,9 +2792,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2741 } 2792 }
2742 if (udev->speed != USB_SPEED_SUPER) 2793 if (udev->speed != USB_SPEED_SUPER)
2743 dev_info(&udev->dev, 2794 dev_info(&udev->dev,
2744 "%s %s speed %sUSB device using %s and address %d\n", 2795 "%s %s speed %sUSB device number %d using %s\n",
2745 (udev->config) ? "reset" : "new", speed, type, 2796 (udev->config) ? "reset" : "new", speed, type,
2746 udev->bus->controller->driver->name, devnum); 2797 devnum, udev->bus->controller->driver->name);
2747 2798
2748 /* Set up TT records, if needed */ 2799 /* Set up TT records, if needed */
2749 if (hdev->tt) { 2800 if (hdev->tt) {
@@ -2773,10 +2824,6 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2773 * value. 2824 * value.
2774 */ 2825 */
2775 for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { 2826 for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) {
2776 /*
2777 * An xHCI controller cannot send any packets to a device until
2778 * a set address command successfully completes.
2779 */
2780 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { 2827 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) {
2781 struct usb_device_descriptor *buf; 2828 struct usb_device_descriptor *buf;
2782 int r = 0; 2829 int r = 0;
@@ -2859,9 +2906,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2859 if (udev->speed == USB_SPEED_SUPER) { 2906 if (udev->speed == USB_SPEED_SUPER) {
2860 devnum = udev->devnum; 2907 devnum = udev->devnum;
2861 dev_info(&udev->dev, 2908 dev_info(&udev->dev,
2862 "%s SuperSpeed USB device using %s and address %d\n", 2909 "%s SuperSpeed USB device number %d using %s\n",
2863 (udev->config) ? "reset" : "new", 2910 (udev->config) ? "reset" : "new",
2864 udev->bus->controller->driver->name, devnum); 2911 devnum, udev->bus->controller->driver->name);
2865 } 2912 }
2866 2913
2867 /* cope with hardware quirkiness: 2914 /* cope with hardware quirkiness:
@@ -2924,7 +2971,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2924fail: 2971fail:
2925 if (retval) { 2972 if (retval) {
2926 hub_port_disable(hub, port1, 0); 2973 hub_port_disable(hub, port1, 0);
2927 update_address(udev, devnum); /* for disconnect processing */ 2974 update_devnum(udev, devnum); /* for disconnect processing */
2928 } 2975 }
2929 mutex_unlock(&usb_address0_mutex); 2976 mutex_unlock(&usb_address0_mutex);
2930 return retval; 2977 return retval;
@@ -3015,7 +3062,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
3015 3062
3016 dev_dbg (hub_dev, 3063 dev_dbg (hub_dev,
3017 "port %d, status %04x, change %04x, %s\n", 3064 "port %d, status %04x, change %04x, %s\n",
3018 port1, portstatus, portchange, portspeed (portstatus)); 3065 port1, portstatus, portchange, portspeed(hub, portstatus));
3019 3066
3020 if (hub->has_indicators) { 3067 if (hub->has_indicators) {
3021 set_port_led(hub, port1, HUB_LED_AUTO); 3068 set_port_led(hub, port1, HUB_LED_AUTO);
@@ -3116,32 +3163,13 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
3116 udev->level = hdev->level + 1; 3163 udev->level = hdev->level + 1;
3117 udev->wusb = hub_is_wusb(hub); 3164 udev->wusb = hub_is_wusb(hub);
3118 3165
3119 /* 3166 /* Only USB 3.0 devices are connected to SuperSpeed hubs. */
3120 * USB 3.0 devices are reset automatically before the connect 3167 if (hub_is_superspeed(hub->hdev))
3121 * port status change appears, and the root hub port status
3122 * shows the correct speed. We also get port change
3123 * notifications for USB 3.0 devices from the USB 3.0 portion of
3124 * an external USB 3.0 hub, but this isn't handled correctly yet
3125 * FIXME.
3126 */
3127
3128 if (!(hcd->driver->flags & HCD_USB3))
3129 udev->speed = USB_SPEED_UNKNOWN;
3130 else if ((hdev->parent == NULL) &&
3131 (portstatus & USB_PORT_STAT_SUPER_SPEED))
3132 udev->speed = USB_SPEED_SUPER; 3168 udev->speed = USB_SPEED_SUPER;
3133 else 3169 else
3134 udev->speed = USB_SPEED_UNKNOWN; 3170 udev->speed = USB_SPEED_UNKNOWN;
3135 3171
3136 /* 3172 choose_devnum(udev);
3137 * Set the address.
3138 * Note xHCI needs to issue an address device command later
3139 * in the hub_port_init sequence for SS/HS/FS/LS devices,
3140 * and xHC will assign an address to the device. But use
3141 * kernel assigned address here, to avoid any address conflict
3142 * issue.
3143 */
3144 choose_address(udev);
3145 if (udev->devnum <= 0) { 3173 if (udev->devnum <= 0) {
3146 status = -ENOTCONN; /* Don't retry */ 3174 status = -ENOTCONN; /* Don't retry */
3147 goto loop; 3175 goto loop;
@@ -3233,7 +3261,7 @@ loop_disable:
3233 hub_port_disable(hub, port1, 1); 3261 hub_port_disable(hub, port1, 1);
3234loop: 3262loop:
3235 usb_ep0_reinit(udev); 3263 usb_ep0_reinit(udev);
3236 release_address(udev); 3264 release_devnum(udev);
3237 hub_free_dev(udev); 3265 hub_free_dev(udev);
3238 usb_put_dev(udev); 3266 usb_put_dev(udev);
3239 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) 3267 if ((status == -ENOTCONN) || (status == -ENOTSUPP))
@@ -3410,12 +3438,19 @@ static void hub_events(void)
3410 } 3438 }
3411 3439
3412 if (portchange & USB_PORT_STAT_C_OVERCURRENT) { 3440 if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
3413 dev_err (hub_dev, 3441 u16 status = 0;
3414 "over-current change on port %d\n", 3442 u16 unused;
3415 i); 3443
3444 dev_dbg(hub_dev, "over-current change on port "
3445 "%d\n", i);
3416 clear_port_feature(hdev, i, 3446 clear_port_feature(hdev, i,
3417 USB_PORT_FEAT_C_OVER_CURRENT); 3447 USB_PORT_FEAT_C_OVER_CURRENT);
3448 msleep(100); /* Cool down */
3418 hub_power_on(hub, true); 3449 hub_power_on(hub, true);
3450 hub_port_status(hub, i, &status, &unused);
3451 if (status & USB_PORT_STAT_OVERCURRENT)
3452 dev_err(hub_dev, "over-current "
3453 "condition on port %d\n", i);
3419 } 3454 }
3420 3455
3421 if (portchange & USB_PORT_STAT_C_RESET) { 3456 if (portchange & USB_PORT_STAT_C_RESET) {
@@ -3425,6 +3460,25 @@ static void hub_events(void)
3425 clear_port_feature(hdev, i, 3460 clear_port_feature(hdev, i,
3426 USB_PORT_FEAT_C_RESET); 3461 USB_PORT_FEAT_C_RESET);
3427 } 3462 }
3463 if ((portchange & USB_PORT_STAT_C_BH_RESET) &&
3464 hub_is_superspeed(hub->hdev)) {
3465 dev_dbg(hub_dev,
3466 "warm reset change on port %d\n",
3467 i);
3468 clear_port_feature(hdev, i,
3469 USB_PORT_FEAT_C_BH_PORT_RESET);
3470 }
3471 if (portchange & USB_PORT_STAT_C_LINK_STATE) {
3472 clear_port_feature(hub->hdev, i,
3473 USB_PORT_FEAT_C_PORT_LINK_STATE);
3474 }
3475 if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) {
3476 dev_warn(hub_dev,
3477 "config error on port %d\n",
3478 i);
3479 clear_port_feature(hub->hdev, i,
3480 USB_PORT_FEAT_C_PORT_CONFIG_ERROR);
3481 }
3428 3482
3429 if (connect_change) 3483 if (connect_change)
3430 hub_port_connect_change(hub, i, 3484 hub_port_connect_change(hub, i,
@@ -3447,10 +3501,17 @@ static void hub_events(void)
3447 hub->limited_power = 0; 3501 hub->limited_power = 0;
3448 } 3502 }
3449 if (hubchange & HUB_CHANGE_OVERCURRENT) { 3503 if (hubchange & HUB_CHANGE_OVERCURRENT) {
3450 dev_dbg (hub_dev, "overcurrent change\n"); 3504 u16 status = 0;
3451 msleep(500); /* Cool down */ 3505 u16 unused;
3506
3507 dev_dbg(hub_dev, "over-current change\n");
3452 clear_hub_feature(hdev, C_HUB_OVER_CURRENT); 3508 clear_hub_feature(hdev, C_HUB_OVER_CURRENT);
3509 msleep(500); /* Cool down */
3453 hub_power_on(hub, true); 3510 hub_power_on(hub, true);
3511 hub_hub_status(hub, &status, &unused);
3512 if (status & HUB_STATUS_OVERCURRENT)
3513 dev_err(hub_dev, "over-current "
3514 "condition\n");
3454 } 3515 }
3455 } 3516 }
3456 3517
@@ -3699,13 +3760,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3699 if (!udev->actconfig) 3760 if (!udev->actconfig)
3700 goto done; 3761 goto done;
3701 3762
3702 mutex_lock(&hcd->bandwidth_mutex); 3763 mutex_lock(hcd->bandwidth_mutex);
3703 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); 3764 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL);
3704 if (ret < 0) { 3765 if (ret < 0) {
3705 dev_warn(&udev->dev, 3766 dev_warn(&udev->dev,
3706 "Busted HC? Not enough HCD resources for " 3767 "Busted HC? Not enough HCD resources for "
3707 "old configuration.\n"); 3768 "old configuration.\n");
3708 mutex_unlock(&hcd->bandwidth_mutex); 3769 mutex_unlock(hcd->bandwidth_mutex);
3709 goto re_enumerate; 3770 goto re_enumerate;
3710 } 3771 }
3711 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 3772 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -3716,10 +3777,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3716 dev_err(&udev->dev, 3777 dev_err(&udev->dev,
3717 "can't restore configuration #%d (error=%d)\n", 3778 "can't restore configuration #%d (error=%d)\n",
3718 udev->actconfig->desc.bConfigurationValue, ret); 3779 udev->actconfig->desc.bConfigurationValue, ret);
3719 mutex_unlock(&hcd->bandwidth_mutex); 3780 mutex_unlock(hcd->bandwidth_mutex);
3720 goto re_enumerate; 3781 goto re_enumerate;
3721 } 3782 }
3722 mutex_unlock(&hcd->bandwidth_mutex); 3783 mutex_unlock(hcd->bandwidth_mutex);
3723 usb_set_device_state(udev, USB_STATE_CONFIGURED); 3784 usb_set_device_state(udev, USB_STATE_CONFIGURED);
3724 3785
3725 /* Put interfaces back into the same altsettings as before. 3786 /* Put interfaces back into the same altsettings as before.
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 832487423826..5701e857392b 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1284,12 +1284,12 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1284 /* Make sure we have enough bandwidth for this alternate interface. 1284 /* Make sure we have enough bandwidth for this alternate interface.
1285 * Remove the current alt setting and add the new alt setting. 1285 * Remove the current alt setting and add the new alt setting.
1286 */ 1286 */
1287 mutex_lock(&hcd->bandwidth_mutex); 1287 mutex_lock(hcd->bandwidth_mutex);
1288 ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); 1288 ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt);
1289 if (ret < 0) { 1289 if (ret < 0) {
1290 dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", 1290 dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n",
1291 alternate); 1291 alternate);
1292 mutex_unlock(&hcd->bandwidth_mutex); 1292 mutex_unlock(hcd->bandwidth_mutex);
1293 return ret; 1293 return ret;
1294 } 1294 }
1295 1295
@@ -1311,10 +1311,10 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1311 } else if (ret < 0) { 1311 } else if (ret < 0) {
1312 /* Re-instate the old alt setting */ 1312 /* Re-instate the old alt setting */
1313 usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); 1313 usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting);
1314 mutex_unlock(&hcd->bandwidth_mutex); 1314 mutex_unlock(hcd->bandwidth_mutex);
1315 return ret; 1315 return ret;
1316 } 1316 }
1317 mutex_unlock(&hcd->bandwidth_mutex); 1317 mutex_unlock(hcd->bandwidth_mutex);
1318 1318
1319 /* FIXME drivers shouldn't need to replicate/bugfix the logic here 1319 /* FIXME drivers shouldn't need to replicate/bugfix the logic here
1320 * when they implement async or easily-killable versions of this or 1320 * when they implement async or easily-killable versions of this or
@@ -1413,7 +1413,7 @@ int usb_reset_configuration(struct usb_device *dev)
1413 1413
1414 config = dev->actconfig; 1414 config = dev->actconfig;
1415 retval = 0; 1415 retval = 0;
1416 mutex_lock(&hcd->bandwidth_mutex); 1416 mutex_lock(hcd->bandwidth_mutex);
1417 /* Make sure we have enough bandwidth for each alternate setting 0 */ 1417 /* Make sure we have enough bandwidth for each alternate setting 0 */
1418 for (i = 0; i < config->desc.bNumInterfaces; i++) { 1418 for (i = 0; i < config->desc.bNumInterfaces; i++) {
1419 struct usb_interface *intf = config->interface[i]; 1419 struct usb_interface *intf = config->interface[i];
@@ -1442,7 +1442,7 @@ reset_old_alts:
1442 usb_hcd_alloc_bandwidth(dev, NULL, 1442 usb_hcd_alloc_bandwidth(dev, NULL,
1443 alt, intf->cur_altsetting); 1443 alt, intf->cur_altsetting);
1444 } 1444 }
1445 mutex_unlock(&hcd->bandwidth_mutex); 1445 mutex_unlock(hcd->bandwidth_mutex);
1446 return retval; 1446 return retval;
1447 } 1447 }
1448 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1448 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
@@ -1451,7 +1451,7 @@ reset_old_alts:
1451 NULL, 0, USB_CTRL_SET_TIMEOUT); 1451 NULL, 0, USB_CTRL_SET_TIMEOUT);
1452 if (retval < 0) 1452 if (retval < 0)
1453 goto reset_old_alts; 1453 goto reset_old_alts;
1454 mutex_unlock(&hcd->bandwidth_mutex); 1454 mutex_unlock(hcd->bandwidth_mutex);
1455 1455
1456 /* re-init hc/hcd interface/endpoint state */ 1456 /* re-init hc/hcd interface/endpoint state */
1457 for (i = 0; i < config->desc.bNumInterfaces; i++) { 1457 for (i = 0; i < config->desc.bNumInterfaces; i++) {
@@ -1739,10 +1739,10 @@ free_interfaces:
1739 * host controller will not allow submissions to dropped endpoints. If 1739 * host controller will not allow submissions to dropped endpoints. If
1740 * this call fails, the device state is unchanged. 1740 * this call fails, the device state is unchanged.
1741 */ 1741 */
1742 mutex_lock(&hcd->bandwidth_mutex); 1742 mutex_lock(hcd->bandwidth_mutex);
1743 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); 1743 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL);
1744 if (ret < 0) { 1744 if (ret < 0) {
1745 mutex_unlock(&hcd->bandwidth_mutex); 1745 mutex_unlock(hcd->bandwidth_mutex);
1746 usb_autosuspend_device(dev); 1746 usb_autosuspend_device(dev);
1747 goto free_interfaces; 1747 goto free_interfaces;
1748 } 1748 }
@@ -1761,11 +1761,11 @@ free_interfaces:
1761 if (!cp) { 1761 if (!cp) {
1762 usb_set_device_state(dev, USB_STATE_ADDRESS); 1762 usb_set_device_state(dev, USB_STATE_ADDRESS);
1763 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); 1763 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
1764 mutex_unlock(&hcd->bandwidth_mutex); 1764 mutex_unlock(hcd->bandwidth_mutex);
1765 usb_autosuspend_device(dev); 1765 usb_autosuspend_device(dev);
1766 goto free_interfaces; 1766 goto free_interfaces;
1767 } 1767 }
1768 mutex_unlock(&hcd->bandwidth_mutex); 1768 mutex_unlock(hcd->bandwidth_mutex);
1769 usb_set_device_state(dev, USB_STATE_CONFIGURED); 1769 usb_set_device_state(dev, USB_STATE_CONFIGURED);
1770 1770
1771 /* Initialize the new interface structures and the 1771 /* Initialize the new interface structures and the
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index c14fc082864f..ae334b067c13 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -366,7 +366,16 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
366 if (xfertype == USB_ENDPOINT_XFER_ISOC) { 366 if (xfertype == USB_ENDPOINT_XFER_ISOC) {
367 int n, len; 367 int n, len;
368 368
369 /* FIXME SuperSpeed isoc endpoints have up to 16 bursts */ 369 /* SuperSpeed isoc endpoints have up to 16 bursts of up to
370 * 3 packets each
371 */
372 if (dev->speed == USB_SPEED_SUPER) {
373 int burst = 1 + ep->ss_ep_comp.bMaxBurst;
374 int mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes);
375 max *= burst;
376 max *= mult;
377 }
378
370 /* "high bandwidth" mode, 1-3 packets/uframe? */ 379 /* "high bandwidth" mode, 1-3 packets/uframe? */
371 if (dev->speed == USB_SPEED_HIGH) { 380 if (dev->speed == USB_SPEED_HIGH) {
372 int mult = 1 + ((max >> 11) & 0x03); 381 int mult = 1 + ((max >> 11) & 0x03);
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index b975450f403e..a9cf484ecae4 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -122,6 +122,19 @@ static inline int is_usb_device_driver(struct device_driver *drv)
122 for_devices; 122 for_devices;
123} 123}
124 124
125/* translate USB error codes to codes user space understands */
126static inline int usb_translate_errors(int error_code)
127{
128 switch (error_code) {
129 case 0:
130 case -ENOMEM:
131 case -ENODEV:
132 return error_code;
133 default:
134 return -EIO;
135 }
136}
137
125 138
126/* for labeling diagnostics */ 139/* for labeling diagnostics */
127extern const char *usbcore_name; 140extern const char *usbcore_name;
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
index 94ecdbc758ce..0bc06e2bcfcb 100644
--- a/drivers/usb/early/ehci-dbgp.c
+++ b/drivers/usb/early/ehci-dbgp.c
@@ -601,7 +601,7 @@ try_again:
601 dbgp_printk("dbgp_bulk_write failed: %d\n", ret); 601 dbgp_printk("dbgp_bulk_write failed: %d\n", ret);
602 goto err; 602 goto err;
603 } 603 }
604 dbgp_printk("small write doned\n"); 604 dbgp_printk("small write done\n");
605 dbgp_not_safe = 0; 605 dbgp_not_safe = 0;
606 606
607 return 0; 607 return 0;
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index d50099675f28..bfde50e20b30 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -176,6 +176,18 @@ config USB_FSL_USB2
176 default USB_GADGET 176 default USB_GADGET
177 select USB_GADGET_SELECTED 177 select USB_GADGET_SELECTED
178 178
179config USB_GADGET_FUSB300
180 boolean "Faraday FUSB300 USB Peripheral Controller"
181 select USB_GADGET_DUALSPEED
182 help
183 Faraday usb device controller FUSB300 driver
184
185config USB_FUSB300
186 tristate
187 depends on USB_GADGET_FUSB300
188 default USB_GADGET
189 select USB_GADGET_SELECTED
190
179config USB_GADGET_LH7A40X 191config USB_GADGET_LH7A40X
180 boolean "LH7A40X" 192 boolean "LH7A40X"
181 depends on ARCH_LH7A40X 193 depends on ARCH_LH7A40X
@@ -540,7 +552,7 @@ config USB_GADGET_CI13XXX_MSM
540 boolean "MIPS USB CI13xxx for MSM" 552 boolean "MIPS USB CI13xxx for MSM"
541 depends on ARCH_MSM 553 depends on ARCH_MSM
542 select USB_GADGET_DUALSPEED 554 select USB_GADGET_DUALSPEED
543 select USB_MSM_OTG_72K 555 select USB_MSM_OTG
544 help 556 help
545 MSM SoC has chipidea USB controller. This driver uses 557 MSM SoC has chipidea USB controller. This driver uses
546 ci13xxx_udc core. 558 ci13xxx_udc core.
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 55f5e8ae5924..305286e181d5 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_USB_EG20T) += pch_udc.o
28obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o 28obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o
29mv_udc-y := mv_udc_core.o mv_udc_phy.o 29mv_udc-y := mv_udc_core.o mv_udc_phy.o
30obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o 30obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o
31obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
31 32
32# 33#
33# USB gadget drivers 34# USB gadget drivers
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index bdec36acd0fa..bb8ddf0469f9 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1798,8 +1798,10 @@ static int __init at91udc_probe(struct platform_device *pdev)
1798 } 1798 }
1799 1799
1800 retval = device_register(&udc->gadget.dev); 1800 retval = device_register(&udc->gadget.dev);
1801 if (retval < 0) 1801 if (retval < 0) {
1802 put_device(&udc->gadget.dev);
1802 goto fail0b; 1803 goto fail0b;
1804 }
1803 1805
1804 /* don't do anything until we have both gadget driver and VBUS */ 1806 /* don't do anything until we have both gadget driver and VBUS */
1805 clk_enable(udc->iclk); 1807 clk_enable(udc->iclk);
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index a1c67ae1572a..e09178bc1450 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -435,20 +435,6 @@ static int hw_ep_get_halt(int num, int dir)
435} 435}
436 436
437/** 437/**
438 * hw_ep_is_primed: test if endpoint is primed (execute without interruption)
439 * @num: endpoint number
440 * @dir: endpoint direction
441 *
442 * This function returns true if endpoint primed
443 */
444static int hw_ep_is_primed(int num, int dir)
445{
446 u32 reg = hw_cread(CAP_ENDPTPRIME, ~0) | hw_cread(CAP_ENDPTSTAT, ~0);
447
448 return test_bit(hw_ep_bit(num, dir), (void *)&reg);
449}
450
451/**
452 * hw_test_and_clear_setup_status: test & clear setup status (execute without 438 * hw_test_and_clear_setup_status: test & clear setup status (execute without
453 * interruption) 439 * interruption)
454 * @n: bit number (endpoint) 440 * @n: bit number (endpoint)
@@ -472,10 +458,6 @@ static int hw_ep_prime(int num, int dir, int is_ctrl)
472{ 458{
473 int n = hw_ep_bit(num, dir); 459 int n = hw_ep_bit(num, dir);
474 460
475 /* the caller should flush first */
476 if (hw_ep_is_primed(num, dir))
477 return -EBUSY;
478
479 if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) 461 if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num)))
480 return -EAGAIN; 462 return -EAGAIN;
481 463
@@ -1434,6 +1416,8 @@ static inline u8 _usb_addr(struct ci13xxx_ep *ep)
1434static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) 1416static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1435{ 1417{
1436 unsigned i; 1418 unsigned i;
1419 int ret = 0;
1420 unsigned length = mReq->req.length;
1437 1421
1438 trace("%p, %p", mEp, mReq); 1422 trace("%p, %p", mEp, mReq);
1439 1423
@@ -1441,53 +1425,91 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1441 if (mReq->req.status == -EALREADY) 1425 if (mReq->req.status == -EALREADY)
1442 return -EALREADY; 1426 return -EALREADY;
1443 1427
1444 if (hw_ep_is_primed(mEp->num, mEp->dir))
1445 return -EBUSY;
1446
1447 mReq->req.status = -EALREADY; 1428 mReq->req.status = -EALREADY;
1448 1429 if (length && !mReq->req.dma) {
1449 if (mReq->req.length && !mReq->req.dma) {
1450 mReq->req.dma = \ 1430 mReq->req.dma = \
1451 dma_map_single(mEp->device, mReq->req.buf, 1431 dma_map_single(mEp->device, mReq->req.buf,
1452 mReq->req.length, mEp->dir ? 1432 length, mEp->dir ? DMA_TO_DEVICE :
1453 DMA_TO_DEVICE : DMA_FROM_DEVICE); 1433 DMA_FROM_DEVICE);
1454 if (mReq->req.dma == 0) 1434 if (mReq->req.dma == 0)
1455 return -ENOMEM; 1435 return -ENOMEM;
1456 1436
1457 mReq->map = 1; 1437 mReq->map = 1;
1458 } 1438 }
1459 1439
1440 if (mReq->req.zero && length && (length % mEp->ep.maxpacket == 0)) {
1441 mReq->zptr = dma_pool_alloc(mEp->td_pool, GFP_ATOMIC,
1442 &mReq->zdma);
1443 if (mReq->zptr == NULL) {
1444 if (mReq->map) {
1445 dma_unmap_single(mEp->device, mReq->req.dma,
1446 length, mEp->dir ? DMA_TO_DEVICE :
1447 DMA_FROM_DEVICE);
1448 mReq->req.dma = 0;
1449 mReq->map = 0;
1450 }
1451 return -ENOMEM;
1452 }
1453 memset(mReq->zptr, 0, sizeof(*mReq->zptr));
1454 mReq->zptr->next = TD_TERMINATE;
1455 mReq->zptr->token = TD_STATUS_ACTIVE;
1456 if (!mReq->req.no_interrupt)
1457 mReq->zptr->token |= TD_IOC;
1458 }
1460 /* 1459 /*
1461 * TD configuration 1460 * TD configuration
1462 * TODO - handle requests which spawns into several TDs 1461 * TODO - handle requests which spawns into several TDs
1463 */ 1462 */
1464 memset(mReq->ptr, 0, sizeof(*mReq->ptr)); 1463 memset(mReq->ptr, 0, sizeof(*mReq->ptr));
1465 mReq->ptr->next |= TD_TERMINATE; 1464 mReq->ptr->token = length << ffs_nr(TD_TOTAL_BYTES);
1466 mReq->ptr->token = mReq->req.length << ffs_nr(TD_TOTAL_BYTES);
1467 mReq->ptr->token &= TD_TOTAL_BYTES; 1465 mReq->ptr->token &= TD_TOTAL_BYTES;
1468 mReq->ptr->token |= TD_IOC;
1469 mReq->ptr->token |= TD_STATUS_ACTIVE; 1466 mReq->ptr->token |= TD_STATUS_ACTIVE;
1467 if (mReq->zptr) {
1468 mReq->ptr->next = mReq->zdma;
1469 } else {
1470 mReq->ptr->next = TD_TERMINATE;
1471 if (!mReq->req.no_interrupt)
1472 mReq->ptr->token |= TD_IOC;
1473 }
1470 mReq->ptr->page[0] = mReq->req.dma; 1474 mReq->ptr->page[0] = mReq->req.dma;
1471 for (i = 1; i < 5; i++) 1475 for (i = 1; i < 5; i++)
1472 mReq->ptr->page[i] = 1476 mReq->ptr->page[i] =
1473 (mReq->req.dma + i * CI13XXX_PAGE_SIZE) & ~TD_RESERVED_MASK; 1477 (mReq->req.dma + i * CI13XXX_PAGE_SIZE) & ~TD_RESERVED_MASK;
1474 1478
1475 /* 1479 if (!list_empty(&mEp->qh.queue)) {
1476 * QH configuration 1480 struct ci13xxx_req *mReqPrev;
1477 * At this point it's guaranteed exclusive access to qhead 1481 int n = hw_ep_bit(mEp->num, mEp->dir);
1478 * (endpt is not primed) so it's no need to use tripwire 1482 int tmp_stat;
1479 */ 1483
1484 mReqPrev = list_entry(mEp->qh.queue.prev,
1485 struct ci13xxx_req, queue);
1486 if (mReqPrev->zptr)
1487 mReqPrev->zptr->next = mReq->dma & TD_ADDR_MASK;
1488 else
1489 mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK;
1490 wmb();
1491 if (hw_cread(CAP_ENDPTPRIME, BIT(n)))
1492 goto done;
1493 do {
1494 hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW);
1495 tmp_stat = hw_cread(CAP_ENDPTSTAT, BIT(n));
1496 } while (!hw_cread(CAP_USBCMD, USBCMD_ATDTW));
1497 hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, 0);
1498 if (tmp_stat)
1499 goto done;
1500 }
1501
1502 /* QH configuration */
1480 mEp->qh.ptr->td.next = mReq->dma; /* TERMINATE = 0 */ 1503 mEp->qh.ptr->td.next = mReq->dma; /* TERMINATE = 0 */
1481 mEp->qh.ptr->td.token &= ~TD_STATUS; /* clear status */ 1504 mEp->qh.ptr->td.token &= ~TD_STATUS; /* clear status */
1482 if (mReq->req.zero == 0) 1505 mEp->qh.ptr->cap |= QH_ZLT;
1483 mEp->qh.ptr->cap |= QH_ZLT;
1484 else
1485 mEp->qh.ptr->cap &= ~QH_ZLT;
1486 1506
1487 wmb(); /* synchronize before ep prime */ 1507 wmb(); /* synchronize before ep prime */
1488 1508
1489 return hw_ep_prime(mEp->num, mEp->dir, 1509 ret = hw_ep_prime(mEp->num, mEp->dir,
1490 mEp->type == USB_ENDPOINT_XFER_CONTROL); 1510 mEp->type == USB_ENDPOINT_XFER_CONTROL);
1511done:
1512 return ret;
1491} 1513}
1492 1514
1493/** 1515/**
@@ -1504,8 +1526,15 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1504 if (mReq->req.status != -EALREADY) 1526 if (mReq->req.status != -EALREADY)
1505 return -EINVAL; 1527 return -EINVAL;
1506 1528
1507 if (hw_ep_is_primed(mEp->num, mEp->dir)) 1529 if ((TD_STATUS_ACTIVE & mReq->ptr->token) != 0)
1508 hw_ep_flush(mEp->num, mEp->dir); 1530 return -EBUSY;
1531
1532 if (mReq->zptr) {
1533 if ((TD_STATUS_ACTIVE & mReq->zptr->token) != 0)
1534 return -EBUSY;
1535 dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma);
1536 mReq->zptr = NULL;
1537 }
1509 1538
1510 mReq->req.status = 0; 1539 mReq->req.status = 0;
1511 1540
@@ -1517,9 +1546,7 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1517 } 1546 }
1518 1547
1519 mReq->req.status = mReq->ptr->token & TD_STATUS; 1548 mReq->req.status = mReq->ptr->token & TD_STATUS;
1520 if ((TD_STATUS_ACTIVE & mReq->req.status) != 0) 1549 if ((TD_STATUS_HALTED & mReq->req.status) != 0)
1521 mReq->req.status = -ECONNRESET;
1522 else if ((TD_STATUS_HALTED & mReq->req.status) != 0)
1523 mReq->req.status = -1; 1550 mReq->req.status = -1;
1524 else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0) 1551 else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0)
1525 mReq->req.status = -1; 1552 mReq->req.status = -1;
@@ -1581,12 +1608,19 @@ static int _gadget_stop_activity(struct usb_gadget *gadget)
1581{ 1608{
1582 struct usb_ep *ep; 1609 struct usb_ep *ep;
1583 struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); 1610 struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget);
1611 unsigned long flags;
1584 1612
1585 trace("%p", gadget); 1613 trace("%p", gadget);
1586 1614
1587 if (gadget == NULL) 1615 if (gadget == NULL)
1588 return -EINVAL; 1616 return -EINVAL;
1589 1617
1618 spin_lock_irqsave(udc->lock, flags);
1619 udc->gadget.speed = USB_SPEED_UNKNOWN;
1620 udc->remote_wakeup = 0;
1621 udc->suspended = 0;
1622 spin_unlock_irqrestore(udc->lock, flags);
1623
1590 /* flush all endpoints */ 1624 /* flush all endpoints */
1591 gadget_for_each_ep(ep, gadget) { 1625 gadget_for_each_ep(ep, gadget) {
1592 usb_ep_fifo_flush(ep); 1626 usb_ep_fifo_flush(ep);
@@ -1720,7 +1754,8 @@ __acquires(mEp->lock)
1720 } 1754 }
1721 1755
1722 if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { 1756 if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) {
1723 /* TODO: D1 - Remote Wakeup; D0 - Self Powered */ 1757 /* Assume that device is bus powered for now. */
1758 *((u16 *)req->buf) = _udc->remote_wakeup << 1;
1724 retval = 0; 1759 retval = 0;
1725 } else if ((setup->bRequestType & USB_RECIP_MASK) \ 1760 } else if ((setup->bRequestType & USB_RECIP_MASK) \
1726 == USB_RECIP_ENDPOINT) { 1761 == USB_RECIP_ENDPOINT) {
@@ -1749,6 +1784,28 @@ __acquires(mEp->lock)
1749} 1784}
1750 1785
1751/** 1786/**
1787 * isr_setup_status_complete: setup_status request complete function
1788 * @ep: endpoint
1789 * @req: request handled
1790 *
1791 * Caller must release lock. Put the port in test mode if test mode
1792 * feature is selected.
1793 */
1794static void
1795isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req)
1796{
1797 struct ci13xxx *udc = req->context;
1798 unsigned long flags;
1799
1800 trace("%p, %p", ep, req);
1801
1802 spin_lock_irqsave(udc->lock, flags);
1803 if (udc->test_mode)
1804 hw_port_test_set(udc->test_mode);
1805 spin_unlock_irqrestore(udc->lock, flags);
1806}
1807
1808/**
1752 * isr_setup_status_phase: queues the status phase of a setup transation 1809 * isr_setup_status_phase: queues the status phase of a setup transation
1753 * @udc: udc struct 1810 * @udc: udc struct
1754 * 1811 *
@@ -1764,6 +1821,8 @@ __acquires(mEp->lock)
1764 trace("%p", udc); 1821 trace("%p", udc);
1765 1822
1766 mEp = (udc->ep0_dir == TX) ? &udc->ep0out : &udc->ep0in; 1823 mEp = (udc->ep0_dir == TX) ? &udc->ep0out : &udc->ep0in;
1824 udc->status->context = udc;
1825 udc->status->complete = isr_setup_status_complete;
1767 1826
1768 spin_unlock(mEp->lock); 1827 spin_unlock(mEp->lock);
1769 retval = usb_ep_queue(&mEp->ep, udc->status, GFP_ATOMIC); 1828 retval = usb_ep_queue(&mEp->ep, udc->status, GFP_ATOMIC);
@@ -1783,7 +1842,7 @@ static int isr_tr_complete_low(struct ci13xxx_ep *mEp)
1783__releases(mEp->lock) 1842__releases(mEp->lock)
1784__acquires(mEp->lock) 1843__acquires(mEp->lock)
1785{ 1844{
1786 struct ci13xxx_req *mReq; 1845 struct ci13xxx_req *mReq, *mReqTemp;
1787 int retval; 1846 int retval;
1788 1847
1789 trace("%p", mEp); 1848 trace("%p", mEp);
@@ -1791,34 +1850,25 @@ __acquires(mEp->lock)
1791 if (list_empty(&mEp->qh.queue)) 1850 if (list_empty(&mEp->qh.queue))
1792 return -EINVAL; 1851 return -EINVAL;
1793 1852
1794 /* pop oldest request */ 1853 list_for_each_entry_safe(mReq, mReqTemp, &mEp->qh.queue,
1795 mReq = list_entry(mEp->qh.queue.next, 1854 queue) {
1796 struct ci13xxx_req, queue); 1855 retval = _hardware_dequeue(mEp, mReq);
1797 list_del_init(&mReq->queue); 1856 if (retval < 0)
1798 1857 break;
1799 retval = _hardware_dequeue(mEp, mReq); 1858 list_del_init(&mReq->queue);
1800 if (retval < 0) { 1859 dbg_done(_usb_addr(mEp), mReq->ptr->token, retval);
1801 dbg_event(_usb_addr(mEp), "DONE", retval); 1860 if (mReq->req.complete != NULL) {
1802 goto done; 1861 spin_unlock(mEp->lock);
1803 } 1862 mReq->req.complete(&mEp->ep, &mReq->req);
1804 1863 spin_lock(mEp->lock);
1805 dbg_done(_usb_addr(mEp), mReq->ptr->token, retval); 1864 }
1806
1807 if (!list_empty(&mEp->qh.queue)) {
1808 struct ci13xxx_req* mReqEnq;
1809
1810 mReqEnq = list_entry(mEp->qh.queue.next,
1811 struct ci13xxx_req, queue);
1812 _hardware_enqueue(mEp, mReqEnq);
1813 } 1865 }
1814 1866
1815 if (mReq->req.complete != NULL) { 1867 if (retval == EBUSY)
1816 spin_unlock(mEp->lock); 1868 retval = 0;
1817 mReq->req.complete(&mEp->ep, &mReq->req); 1869 if (retval < 0)
1818 spin_lock(mEp->lock); 1870 dbg_event(_usb_addr(mEp), "DONE", retval);
1819 }
1820 1871
1821 done:
1822 return retval; 1872 return retval;
1823} 1873}
1824 1874
@@ -1833,6 +1883,7 @@ __releases(udc->lock)
1833__acquires(udc->lock) 1883__acquires(udc->lock)
1834{ 1884{
1835 unsigned i; 1885 unsigned i;
1886 u8 tmode = 0;
1836 1887
1837 trace("%p", udc); 1888 trace("%p", udc);
1838 1889
@@ -1895,22 +1946,32 @@ __acquires(udc->lock)
1895 1946
1896 switch (req.bRequest) { 1947 switch (req.bRequest) {
1897 case USB_REQ_CLEAR_FEATURE: 1948 case USB_REQ_CLEAR_FEATURE:
1898 if (type != (USB_DIR_OUT|USB_RECIP_ENDPOINT) && 1949 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) &&
1899 le16_to_cpu(req.wValue) != USB_ENDPOINT_HALT) 1950 le16_to_cpu(req.wValue) ==
1900 goto delegate; 1951 USB_ENDPOINT_HALT) {
1901 if (req.wLength != 0) 1952 if (req.wLength != 0)
1902 break;
1903 num = le16_to_cpu(req.wIndex);
1904 num &= USB_ENDPOINT_NUMBER_MASK;
1905 if (!udc->ci13xxx_ep[num].wedge) {
1906 spin_unlock(udc->lock);
1907 err = usb_ep_clear_halt(
1908 &udc->ci13xxx_ep[num].ep);
1909 spin_lock(udc->lock);
1910 if (err)
1911 break; 1953 break;
1954 num = le16_to_cpu(req.wIndex);
1955 num &= USB_ENDPOINT_NUMBER_MASK;
1956 if (!udc->ci13xxx_ep[num].wedge) {
1957 spin_unlock(udc->lock);
1958 err = usb_ep_clear_halt(
1959 &udc->ci13xxx_ep[num].ep);
1960 spin_lock(udc->lock);
1961 if (err)
1962 break;
1963 }
1964 err = isr_setup_status_phase(udc);
1965 } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE) &&
1966 le16_to_cpu(req.wValue) ==
1967 USB_DEVICE_REMOTE_WAKEUP) {
1968 if (req.wLength != 0)
1969 break;
1970 udc->remote_wakeup = 0;
1971 err = isr_setup_status_phase(udc);
1972 } else {
1973 goto delegate;
1912 } 1974 }
1913 err = isr_setup_status_phase(udc);
1914 break; 1975 break;
1915 case USB_REQ_GET_STATUS: 1976 case USB_REQ_GET_STATUS:
1916 if (type != (USB_DIR_IN|USB_RECIP_DEVICE) && 1977 if (type != (USB_DIR_IN|USB_RECIP_DEVICE) &&
@@ -1934,20 +1995,48 @@ __acquires(udc->lock)
1934 err = isr_setup_status_phase(udc); 1995 err = isr_setup_status_phase(udc);
1935 break; 1996 break;
1936 case USB_REQ_SET_FEATURE: 1997 case USB_REQ_SET_FEATURE:
1937 if (type != (USB_DIR_OUT|USB_RECIP_ENDPOINT) && 1998 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) &&
1938 le16_to_cpu(req.wValue) != USB_ENDPOINT_HALT) 1999 le16_to_cpu(req.wValue) ==
1939 goto delegate; 2000 USB_ENDPOINT_HALT) {
1940 if (req.wLength != 0) 2001 if (req.wLength != 0)
1941 break; 2002 break;
1942 num = le16_to_cpu(req.wIndex); 2003 num = le16_to_cpu(req.wIndex);
1943 num &= USB_ENDPOINT_NUMBER_MASK; 2004 num &= USB_ENDPOINT_NUMBER_MASK;
1944 2005
1945 spin_unlock(udc->lock); 2006 spin_unlock(udc->lock);
1946 err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep); 2007 err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep);
1947 spin_lock(udc->lock); 2008 spin_lock(udc->lock);
1948 if (err) 2009 if (!err)
1949 break; 2010 isr_setup_status_phase(udc);
1950 err = isr_setup_status_phase(udc); 2011 } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE)) {
2012 if (req.wLength != 0)
2013 break;
2014 switch (le16_to_cpu(req.wValue)) {
2015 case USB_DEVICE_REMOTE_WAKEUP:
2016 udc->remote_wakeup = 1;
2017 err = isr_setup_status_phase(udc);
2018 break;
2019 case USB_DEVICE_TEST_MODE:
2020 tmode = le16_to_cpu(req.wIndex) >> 8;
2021 switch (tmode) {
2022 case TEST_J:
2023 case TEST_K:
2024 case TEST_SE0_NAK:
2025 case TEST_PACKET:
2026 case TEST_FORCE_EN:
2027 udc->test_mode = tmode;
2028 err = isr_setup_status_phase(
2029 udc);
2030 break;
2031 default:
2032 break;
2033 }
2034 default:
2035 goto delegate;
2036 }
2037 } else {
2038 goto delegate;
2039 }
1951 break; 2040 break;
1952 default: 2041 default:
1953delegate: 2042delegate:
@@ -2178,15 +2267,15 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
2178 /* push request */ 2267 /* push request */
2179 mReq->req.status = -EINPROGRESS; 2268 mReq->req.status = -EINPROGRESS;
2180 mReq->req.actual = 0; 2269 mReq->req.actual = 0;
2181 list_add_tail(&mReq->queue, &mEp->qh.queue);
2182 2270
2183 if (list_is_singular(&mEp->qh.queue)) 2271 retval = _hardware_enqueue(mEp, mReq);
2184 retval = _hardware_enqueue(mEp, mReq);
2185 2272
2186 if (retval == -EALREADY) { 2273 if (retval == -EALREADY) {
2187 dbg_event(_usb_addr(mEp), "QUEUE", retval); 2274 dbg_event(_usb_addr(mEp), "QUEUE", retval);
2188 retval = 0; 2275 retval = 0;
2189 } 2276 }
2277 if (!retval)
2278 list_add_tail(&mReq->queue, &mEp->qh.queue);
2190 2279
2191 done: 2280 done:
2192 spin_unlock_irqrestore(mEp->lock, flags); 2281 spin_unlock_irqrestore(mEp->lock, flags);
@@ -2206,19 +2295,25 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req)
2206 2295
2207 trace("%p, %p", ep, req); 2296 trace("%p, %p", ep, req);
2208 2297
2209 if (ep == NULL || req == NULL || mEp->desc == NULL || 2298 if (ep == NULL || req == NULL || mReq->req.status != -EALREADY ||
2210 list_empty(&mReq->queue) || list_empty(&mEp->qh.queue)) 2299 mEp->desc == NULL || list_empty(&mReq->queue) ||
2300 list_empty(&mEp->qh.queue))
2211 return -EINVAL; 2301 return -EINVAL;
2212 2302
2213 spin_lock_irqsave(mEp->lock, flags); 2303 spin_lock_irqsave(mEp->lock, flags);
2214 2304
2215 dbg_event(_usb_addr(mEp), "DEQUEUE", 0); 2305 dbg_event(_usb_addr(mEp), "DEQUEUE", 0);
2216 2306
2217 if (mReq->req.status == -EALREADY) 2307 hw_ep_flush(mEp->num, mEp->dir);
2218 _hardware_dequeue(mEp, mReq);
2219 2308
2220 /* pop request */ 2309 /* pop request */
2221 list_del_init(&mReq->queue); 2310 list_del_init(&mReq->queue);
2311 if (mReq->map) {
2312 dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length,
2313 mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
2314 mReq->req.dma = 0;
2315 mReq->map = 0;
2316 }
2222 req->status = -ECONNRESET; 2317 req->status = -ECONNRESET;
2223 2318
2224 if (mReq->req.complete != NULL) { 2319 if (mReq->req.complete != NULL) {
@@ -2377,6 +2472,31 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
2377 return 0; 2472 return 0;
2378} 2473}
2379 2474
2475static int ci13xxx_wakeup(struct usb_gadget *_gadget)
2476{
2477 struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget);
2478 unsigned long flags;
2479 int ret = 0;
2480
2481 trace();
2482
2483 spin_lock_irqsave(udc->lock, flags);
2484 if (!udc->remote_wakeup) {
2485 ret = -EOPNOTSUPP;
2486 dbg_trace("remote wakeup feature is not enabled\n");
2487 goto out;
2488 }
2489 if (!hw_cread(CAP_PORTSC, PORTSC_SUSP)) {
2490 ret = -EINVAL;
2491 dbg_trace("port is not suspended\n");
2492 goto out;
2493 }
2494 hw_cwrite(CAP_PORTSC, PORTSC_FPR, PORTSC_FPR);
2495out:
2496 spin_unlock_irqrestore(udc->lock, flags);
2497 return ret;
2498}
2499
2380/** 2500/**
2381 * Device operations part of the API to the USB controller hardware, 2501 * Device operations part of the API to the USB controller hardware,
2382 * which don't involve endpoints (or i/o) 2502 * which don't involve endpoints (or i/o)
@@ -2384,6 +2504,7 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
2384 */ 2504 */
2385static const struct usb_gadget_ops usb_gadget_ops = { 2505static const struct usb_gadget_ops usb_gadget_ops = {
2386 .vbus_session = ci13xxx_vbus_session, 2506 .vbus_session = ci13xxx_vbus_session,
2507 .wakeup = ci13xxx_wakeup,
2387}; 2508};
2388 2509
2389/** 2510/**
@@ -2626,6 +2747,12 @@ static irqreturn_t udc_irq(void)
2626 isr_statistics.pci++; 2747 isr_statistics.pci++;
2627 udc->gadget.speed = hw_port_is_high_speed() ? 2748 udc->gadget.speed = hw_port_is_high_speed() ?
2628 USB_SPEED_HIGH : USB_SPEED_FULL; 2749 USB_SPEED_HIGH : USB_SPEED_FULL;
2750 if (udc->suspended) {
2751 spin_unlock(udc->lock);
2752 udc->driver->resume(&udc->gadget);
2753 spin_lock(udc->lock);
2754 udc->suspended = 0;
2755 }
2629 } 2756 }
2630 if (USBi_UEI & intr) 2757 if (USBi_UEI & intr)
2631 isr_statistics.uei++; 2758 isr_statistics.uei++;
@@ -2633,8 +2760,15 @@ static irqreturn_t udc_irq(void)
2633 isr_statistics.ui++; 2760 isr_statistics.ui++;
2634 isr_tr_complete_handler(udc); 2761 isr_tr_complete_handler(udc);
2635 } 2762 }
2636 if (USBi_SLI & intr) 2763 if (USBi_SLI & intr) {
2764 if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
2765 udc->suspended = 1;
2766 spin_unlock(udc->lock);
2767 udc->driver->suspend(&udc->gadget);
2768 spin_lock(udc->lock);
2769 }
2637 isr_statistics.sli++; 2770 isr_statistics.sli++;
2771 }
2638 retval = IRQ_HANDLED; 2772 retval = IRQ_HANDLED;
2639 } else { 2773 } else {
2640 isr_statistics.none++; 2774 isr_statistics.none++;
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h
index a2492b65f98c..23707775cb43 100644
--- a/drivers/usb/gadget/ci13xxx_udc.h
+++ b/drivers/usb/gadget/ci13xxx_udc.h
@@ -33,6 +33,7 @@ struct ci13xxx_td {
33 /* 0 */ 33 /* 0 */
34 u32 next; 34 u32 next;
35#define TD_TERMINATE BIT(0) 35#define TD_TERMINATE BIT(0)
36#define TD_ADDR_MASK (0xFFFFFFEUL << 5)
36 /* 1 */ 37 /* 1 */
37 u32 token; 38 u32 token;
38#define TD_STATUS (0x00FFUL << 0) 39#define TD_STATUS (0x00FFUL << 0)
@@ -74,6 +75,8 @@ struct ci13xxx_req {
74 struct list_head queue; 75 struct list_head queue;
75 struct ci13xxx_td *ptr; 76 struct ci13xxx_td *ptr;
76 dma_addr_t dma; 77 dma_addr_t dma;
78 struct ci13xxx_td *zptr;
79 dma_addr_t zdma;
77}; 80};
78 81
79/* Extension of usb_ep */ 82/* Extension of usb_ep */
@@ -125,6 +128,10 @@ struct ci13xxx {
125 u32 ep0_dir; /* ep0 direction */ 128 u32 ep0_dir; /* ep0 direction */
126#define ep0out ci13xxx_ep[0] 129#define ep0out ci13xxx_ep[0]
127#define ep0in ci13xxx_ep[16] 130#define ep0in ci13xxx_ep[16]
131 u8 remote_wakeup; /* Is remote wakeup feature
132 enabled by the host? */
133 u8 suspended; /* suspended by the host */
134 u8 test_mode; /* the selected test mode */
128 135
129 struct usb_gadget_driver *driver; /* 3rd party gadget driver */ 136 struct usb_gadget_driver *driver; /* 3rd party gadget driver */
130 struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ 137 struct ci13xxx_udc_driver *udc_driver; /* device controller driver */
@@ -152,6 +159,7 @@ struct ci13xxx {
152#define USBCMD_RS BIT(0) 159#define USBCMD_RS BIT(0)
153#define USBCMD_RST BIT(1) 160#define USBCMD_RST BIT(1)
154#define USBCMD_SUTW BIT(13) 161#define USBCMD_SUTW BIT(13)
162#define USBCMD_ATDTW BIT(14)
155 163
156/* USBSTS & USBINTR */ 164/* USBSTS & USBINTR */
157#define USBi_UI BIT(0) 165#define USBi_UI BIT(0)
@@ -165,6 +173,7 @@ struct ci13xxx {
165#define DEVICEADDR_USBADR (0x7FUL << 25) 173#define DEVICEADDR_USBADR (0x7FUL << 25)
166 174
167/* PORTSC */ 175/* PORTSC */
176#define PORTSC_FPR BIT(6)
168#define PORTSC_SUSP BIT(7) 177#define PORTSC_SUSP BIT(7)
169#define PORTSC_HSP BIT(9) 178#define PORTSC_HSP BIT(9)
170#define PORTSC_PTC (0x0FUL << 16) 179#define PORTSC_PTC (0x0FUL << 16)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 1ba4befe336b..c2251c40a205 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -813,7 +813,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
813 */ 813 */
814 req->zero = 0; 814 req->zero = 0;
815 req->complete = composite_setup_complete; 815 req->complete = composite_setup_complete;
816 req->length = USB_BUFSIZ; 816 req->length = 0;
817 gadget->ep0->driver_data = cdev; 817 gadget->ep0->driver_data = cdev;
818 818
819 switch (ctrl->bRequest) { 819 switch (ctrl->bRequest) {
@@ -887,7 +887,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
887 case USB_REQ_SET_INTERFACE: 887 case USB_REQ_SET_INTERFACE:
888 if (ctrl->bRequestType != USB_RECIP_INTERFACE) 888 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
889 goto unknown; 889 goto unknown;
890 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) 890 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
891 break; 891 break;
892 f = cdev->config->interface[intf]; 892 f = cdev->config->interface[intf];
893 if (!f) 893 if (!f)
@@ -899,7 +899,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
899 case USB_REQ_GET_INTERFACE: 899 case USB_REQ_GET_INTERFACE:
900 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) 900 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
901 goto unknown; 901 goto unknown;
902 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) 902 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
903 break; 903 break;
904 f = cdev->config->interface[intf]; 904 f = cdev->config->interface[intf];
905 if (!f) 905 if (!f)
@@ -928,7 +928,7 @@ unknown:
928 */ 928 */
929 switch (ctrl->bRequestType & USB_RECIP_MASK) { 929 switch (ctrl->bRequestType & USB_RECIP_MASK) {
930 case USB_RECIP_INTERFACE: 930 case USB_RECIP_INTERFACE:
931 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) 931 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
932 break; 932 break;
933 f = cdev->config->interface[intf]; 933 f = cdev->config->interface[intf];
934 break; 934 break;
@@ -1258,16 +1258,16 @@ static struct usb_gadget_driver composite_driver = {
1258 * while it was binding. That would usually be done in order to wait for 1258 * while it was binding. That would usually be done in order to wait for
1259 * some userspace participation. 1259 * some userspace participation.
1260 */ 1260 */
1261extern int usb_composite_probe(struct usb_composite_driver *driver, 1261int usb_composite_probe(struct usb_composite_driver *driver,
1262 int (*bind)(struct usb_composite_dev *cdev)) 1262 int (*bind)(struct usb_composite_dev *cdev))
1263{ 1263{
1264 if (!driver || !driver->dev || !bind || composite) 1264 if (!driver || !driver->dev || !bind || composite)
1265 return -EINVAL; 1265 return -EINVAL;
1266 1266
1267 if (!driver->iProduct)
1268 driver->iProduct = driver->name;
1269 if (!driver->name) 1267 if (!driver->name)
1270 driver->name = "composite"; 1268 driver->name = "composite";
1269 if (!driver->iProduct)
1270 driver->iProduct = driver->name;
1271 composite_driver.function = (char *) driver->name; 1271 composite_driver.function = (char *) driver->name;
1272 composite_driver.driver.name = driver->name; 1272 composite_driver.driver.name = driver->name;
1273 composite = driver; 1273 composite = driver;
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 13b9f47feecd..3214ca375d64 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -1593,8 +1593,8 @@ hub_descriptor (struct usb_hub_descriptor *desc)
1593 desc->bDescLength = 9; 1593 desc->bDescLength = 9;
1594 desc->wHubCharacteristics = cpu_to_le16(0x0001); 1594 desc->wHubCharacteristics = cpu_to_le16(0x0001);
1595 desc->bNbrPorts = 1; 1595 desc->bNbrPorts = 1;
1596 desc->bitmap [0] = 0xff; 1596 desc->u.hs.DeviceRemovable[0] = 0xff;
1597 desc->bitmap [1] = 0xff; 1597 desc->u.hs.DeviceRemovable[1] = 0xff;
1598} 1598}
1599 1599
1600static int dummy_hub_control ( 1600static int dummy_hub_control (
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 8a832488ccdd..9b7360ff5aa7 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -128,6 +128,13 @@ ep_matches (
128 } 128 }
129 } 129 }
130 130
131 /*
132 * If the protocol driver hasn't yet decided on wMaxPacketSize
133 * and wants to know the maximum possible, provide the info.
134 */
135 if (desc->wMaxPacketSize == 0)
136 desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket);
137
131 /* endpoint maxpacket size is an input parameter, except for bulk 138 /* endpoint maxpacket size is an input parameter, except for bulk
132 * where it's an output parameter representing the full speed limit. 139 * where it's an output parameter representing the full speed limit.
133 * the usb spec fixes high speed bulk maxpacket at 512 bytes. 140 * the usb spec fixes high speed bulk maxpacket at 512 bytes.
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 1499f9e4afa8..19fffccc370d 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -368,6 +368,14 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
368 req->buf = data; 368 req->buf = data;
369 req->length = len; 369 req->length = len;
370 370
371 /*
372 * UDC layer requires to provide a buffer even for ZLP, but should
373 * not use it at all. Let's provide some poisoned pointer to catch
374 * possible bug in the driver.
375 */
376 if (req->buf == NULL)
377 req->buf = (void *)0xDEADBABE;
378
371 INIT_COMPLETION(ffs->ep0req_completion); 379 INIT_COMPLETION(ffs->ep0req_completion);
372 380
373 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); 381 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC);
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c
index 77b1eb577029..43a49ecc1f36 100644
--- a/drivers/usb/gadget/fsl_mxc_udc.c
+++ b/drivers/usb/gadget/fsl_mxc_udc.c
@@ -88,15 +88,18 @@ eenahb:
88void fsl_udc_clk_finalize(struct platform_device *pdev) 88void fsl_udc_clk_finalize(struct platform_device *pdev)
89{ 89{
90 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 90 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
91#if defined(CONFIG_ARCH_MX35) 91#if defined(CONFIG_SOC_IMX35)
92 unsigned int v; 92 if (cpu_is_mx35()) {
93 93 unsigned int v;
94 /* workaround ENGcm09152 for i.MX35 */ 94
95 if (pdata->workaround & FLS_USB2_WORKAROUND_ENGCM09152) { 95 /* workaround ENGcm09152 for i.MX35 */
96 v = readl(MX35_IO_ADDRESS(MX35_USB_BASE_ADDR + 96 if (pdata->workaround & FLS_USB2_WORKAROUND_ENGCM09152) {
97 USBPHYCTRL_OTGBASE_OFFSET)); 97 v = readl(MX35_IO_ADDRESS(MX35_USB_BASE_ADDR +
98 writel(v | USBPHYCTRL_EVDO, MX35_IO_ADDRESS(MX35_USB_BASE_ADDR + 98 USBPHYCTRL_OTGBASE_OFFSET));
99 USBPHYCTRL_OTGBASE_OFFSET)); 99 writel(v | USBPHYCTRL_EVDO,
100 MX35_IO_ADDRESS(MX35_USB_BASE_ADDR +
101 USBPHYCTRL_OTGBASE_OFFSET));
102 }
100 } 103 }
101#endif 104#endif
102 105
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 4c55eda4bd20..912cb8e63fe3 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -766,7 +766,6 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
766 struct fsl_req *req = container_of(_req, struct fsl_req, req); 766 struct fsl_req *req = container_of(_req, struct fsl_req, req);
767 struct fsl_udc *udc; 767 struct fsl_udc *udc;
768 unsigned long flags; 768 unsigned long flags;
769 int is_iso = 0;
770 769
771 /* catch various bogus parameters */ 770 /* catch various bogus parameters */
772 if (!_req || !req->req.complete || !req->req.buf 771 if (!_req || !req->req.complete || !req->req.buf
@@ -781,7 +780,6 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
781 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 780 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
782 if (req->req.length > ep->ep.maxpacket) 781 if (req->req.length > ep->ep.maxpacket)
783 return -EMSGSIZE; 782 return -EMSGSIZE;
784 is_iso = 1;
785 } 783 }
786 784
787 udc = ep->udc; 785 udc = ep->udc;
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
new file mode 100644
index 000000000000..763d462454b9
--- /dev/null
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -0,0 +1,1744 @@
1/*
2 * Fusb300 UDC (USB gadget)
3 *
4 * Copyright (C) 2010 Faraday Technology Corp.
5 *
6 * Author : Yuan-hsin Chen <yhchen@faraday-tech.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22#include <linux/dma-mapping.h>
23#include <linux/err.h>
24#include <linux/interrupt.h>
25#include <linux/io.h>
26#include <linux/platform_device.h>
27#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h>
29
30#include "fusb300_udc.h"
31
32MODULE_DESCRIPTION("FUSB300 USB gadget driver");
33MODULE_LICENSE("GPL");
34MODULE_AUTHOR("Yuan Hsin Chen <yhchen@faraday-tech.com>");
35MODULE_ALIAS("platform:fusb300_udc");
36
37#define DRIVER_VERSION "20 October 2010"
38
39static const char udc_name[] = "fusb300_udc";
40static const char * const fusb300_ep_name[] = {
41 "ep0", "ep1", "ep2", "ep3", "ep4", "ep5", "ep6", "ep7", "ep8", "ep9",
42 "ep10", "ep11", "ep12", "ep13", "ep14", "ep15"
43};
44
45static void done(struct fusb300_ep *ep, struct fusb300_request *req,
46 int status);
47
48static void fusb300_enable_bit(struct fusb300 *fusb300, u32 offset,
49 u32 value)
50{
51 u32 reg = ioread32(fusb300->reg + offset);
52
53 reg |= value;
54 iowrite32(reg, fusb300->reg + offset);
55}
56
57static void fusb300_disable_bit(struct fusb300 *fusb300, u32 offset,
58 u32 value)
59{
60 u32 reg = ioread32(fusb300->reg + offset);
61
62 reg &= ~value;
63 iowrite32(reg, fusb300->reg + offset);
64}
65
66
67static void fusb300_ep_setting(struct fusb300_ep *ep,
68 struct fusb300_ep_info info)
69{
70 ep->epnum = info.epnum;
71 ep->type = info.type;
72}
73
74static int fusb300_ep_release(struct fusb300_ep *ep)
75{
76 if (!ep->epnum)
77 return 0;
78 ep->epnum = 0;
79 ep->stall = 0;
80 ep->wedged = 0;
81 return 0;
82}
83
84static void fusb300_set_fifo_entry(struct fusb300 *fusb300,
85 u32 ep)
86{
87 u32 val = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
88
89 val &= ~FUSB300_EPSET1_FIFOENTRY_MSK;
90 val |= FUSB300_EPSET1_FIFOENTRY(FUSB300_FIFO_ENTRY_NUM);
91 iowrite32(val, fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
92}
93
94static void fusb300_set_start_entry(struct fusb300 *fusb300,
95 u8 ep)
96{
97 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
98 u32 start_entry = fusb300->fifo_entry_num * FUSB300_FIFO_ENTRY_NUM;
99
100 reg &= ~FUSB300_EPSET1_START_ENTRY_MSK ;
101 reg |= FUSB300_EPSET1_START_ENTRY(start_entry);
102 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
103 if (fusb300->fifo_entry_num == FUSB300_MAX_FIFO_ENTRY) {
104 fusb300->fifo_entry_num = 0;
105 fusb300->addrofs = 0;
106 pr_err("fifo entry is over the maximum number!\n");
107 } else
108 fusb300->fifo_entry_num++;
109}
110
111/* set fusb300_set_start_entry first before fusb300_set_epaddrofs */
112static void fusb300_set_epaddrofs(struct fusb300 *fusb300,
113 struct fusb300_ep_info info)
114{
115 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
116
117 reg &= ~FUSB300_EPSET2_ADDROFS_MSK;
118 reg |= FUSB300_EPSET2_ADDROFS(fusb300->addrofs);
119 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
120 fusb300->addrofs += (info.maxpacket + 7) / 8 * FUSB300_FIFO_ENTRY_NUM;
121}
122
123static void ep_fifo_setting(struct fusb300 *fusb300,
124 struct fusb300_ep_info info)
125{
126 fusb300_set_fifo_entry(fusb300, info.epnum);
127 fusb300_set_start_entry(fusb300, info.epnum);
128 fusb300_set_epaddrofs(fusb300, info);
129}
130
131static void fusb300_set_eptype(struct fusb300 *fusb300,
132 struct fusb300_ep_info info)
133{
134 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
135
136 reg &= ~FUSB300_EPSET1_TYPE_MSK;
137 reg |= FUSB300_EPSET1_TYPE(info.type);
138 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
139}
140
141static void fusb300_set_epdir(struct fusb300 *fusb300,
142 struct fusb300_ep_info info)
143{
144 u32 reg;
145
146 if (!info.dir_in)
147 return;
148 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
149 reg &= ~FUSB300_EPSET1_DIR_MSK;
150 reg |= FUSB300_EPSET1_DIRIN;
151 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
152}
153
154static void fusb300_set_ep_active(struct fusb300 *fusb300,
155 u8 ep)
156{
157 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
158
159 reg |= FUSB300_EPSET1_ACTEN;
160 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(ep));
161}
162
163static void fusb300_set_epmps(struct fusb300 *fusb300,
164 struct fusb300_ep_info info)
165{
166 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
167
168 reg &= ~FUSB300_EPSET2_MPS_MSK;
169 reg |= FUSB300_EPSET2_MPS(info.maxpacket);
170 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum));
171}
172
173static void fusb300_set_interval(struct fusb300 *fusb300,
174 struct fusb300_ep_info info)
175{
176 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
177
178 reg &= ~FUSB300_EPSET1_INTERVAL(0x7);
179 reg |= FUSB300_EPSET1_INTERVAL(info.interval);
180 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
181}
182
183static void fusb300_set_bwnum(struct fusb300 *fusb300,
184 struct fusb300_ep_info info)
185{
186 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
187
188 reg &= ~FUSB300_EPSET1_BWNUM(0x3);
189 reg |= FUSB300_EPSET1_BWNUM(info.bw_num);
190 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum));
191}
192
193static void set_ep_reg(struct fusb300 *fusb300,
194 struct fusb300_ep_info info)
195{
196 fusb300_set_eptype(fusb300, info);
197 fusb300_set_epdir(fusb300, info);
198 fusb300_set_epmps(fusb300, info);
199
200 if (info.interval)
201 fusb300_set_interval(fusb300, info);
202
203 if (info.bw_num)
204 fusb300_set_bwnum(fusb300, info);
205
206 fusb300_set_ep_active(fusb300, info.epnum);
207}
208
209static int config_ep(struct fusb300_ep *ep,
210 const struct usb_endpoint_descriptor *desc)
211{
212 struct fusb300 *fusb300 = ep->fusb300;
213 struct fusb300_ep_info info;
214
215 ep->desc = desc;
216
217 info.interval = 0;
218 info.addrofs = 0;
219 info.bw_num = 0;
220
221 info.type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
222 info.dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0;
223 info.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
224 info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
225
226 if ((info.type == USB_ENDPOINT_XFER_INT) ||
227 (info.type == USB_ENDPOINT_XFER_ISOC)) {
228 info.interval = desc->bInterval;
229 if (info.type == USB_ENDPOINT_XFER_ISOC)
230 info.bw_num = ((desc->wMaxPacketSize & 0x1800) >> 11);
231 }
232
233 ep_fifo_setting(fusb300, info);
234
235 set_ep_reg(fusb300, info);
236
237 fusb300_ep_setting(ep, info);
238
239 fusb300->ep[info.epnum] = ep;
240
241 return 0;
242}
243
244static int fusb300_enable(struct usb_ep *_ep,
245 const struct usb_endpoint_descriptor *desc)
246{
247 struct fusb300_ep *ep;
248
249 ep = container_of(_ep, struct fusb300_ep, ep);
250
251 if (ep->fusb300->reenum) {
252 ep->fusb300->fifo_entry_num = 0;
253 ep->fusb300->addrofs = 0;
254 ep->fusb300->reenum = 0;
255 }
256
257 return config_ep(ep, desc);
258}
259
260static int fusb300_disable(struct usb_ep *_ep)
261{
262 struct fusb300_ep *ep;
263 struct fusb300_request *req;
264 unsigned long flags;
265
266 ep = container_of(_ep, struct fusb300_ep, ep);
267
268 BUG_ON(!ep);
269
270 while (!list_empty(&ep->queue)) {
271 req = list_entry(ep->queue.next, struct fusb300_request, queue);
272 spin_lock_irqsave(&ep->fusb300->lock, flags);
273 done(ep, req, -ECONNRESET);
274 spin_unlock_irqrestore(&ep->fusb300->lock, flags);
275 }
276
277 return fusb300_ep_release(ep);
278}
279
280static struct usb_request *fusb300_alloc_request(struct usb_ep *_ep,
281 gfp_t gfp_flags)
282{
283 struct fusb300_request *req;
284
285 req = kzalloc(sizeof(struct fusb300_request), gfp_flags);
286 if (!req)
287 return NULL;
288 INIT_LIST_HEAD(&req->queue);
289
290 return &req->req;
291}
292
293static void fusb300_free_request(struct usb_ep *_ep, struct usb_request *_req)
294{
295 struct fusb300_request *req;
296
297 req = container_of(_req, struct fusb300_request, req);
298 kfree(req);
299}
300
301static int enable_fifo_int(struct fusb300_ep *ep)
302{
303 struct fusb300 *fusb300 = ep->fusb300;
304
305 if (ep->epnum) {
306 fusb300_enable_bit(fusb300, FUSB300_OFFSET_IGER0,
307 FUSB300_IGER0_EEPn_FIFO_INT(ep->epnum));
308 } else {
309 pr_err("can't enable_fifo_int ep0\n");
310 return -EINVAL;
311 }
312
313 return 0;
314}
315
316static int disable_fifo_int(struct fusb300_ep *ep)
317{
318 struct fusb300 *fusb300 = ep->fusb300;
319
320 if (ep->epnum) {
321 fusb300_disable_bit(fusb300, FUSB300_OFFSET_IGER0,
322 FUSB300_IGER0_EEPn_FIFO_INT(ep->epnum));
323 } else {
324 pr_err("can't disable_fifo_int ep0\n");
325 return -EINVAL;
326 }
327
328 return 0;
329}
330
331static void fusb300_set_cxlen(struct fusb300 *fusb300, u32 length)
332{
333 u32 reg;
334
335 reg = ioread32(fusb300->reg + FUSB300_OFFSET_CSR);
336 reg &= ~FUSB300_CSR_LEN_MSK;
337 reg |= FUSB300_CSR_LEN(length);
338 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_CSR);
339}
340
341/* write data to cx fifo */
342static void fusb300_wrcxf(struct fusb300_ep *ep,
343 struct fusb300_request *req)
344{
345 int i = 0;
346 u8 *tmp;
347 u32 data;
348 struct fusb300 *fusb300 = ep->fusb300;
349 u32 length = req->req.length - req->req.actual;
350
351 tmp = req->req.buf + req->req.actual;
352
353 if (length > SS_CTL_MAX_PACKET_SIZE) {
354 fusb300_set_cxlen(fusb300, SS_CTL_MAX_PACKET_SIZE);
355 for (i = (SS_CTL_MAX_PACKET_SIZE >> 2); i > 0; i--) {
356 data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16 |
357 *(tmp + 3) << 24;
358 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
359 tmp += 4;
360 }
361 req->req.actual += SS_CTL_MAX_PACKET_SIZE;
362 } else { /* length is less than max packet size */
363 fusb300_set_cxlen(fusb300, length);
364 for (i = length >> 2; i > 0; i--) {
365 data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16 |
366 *(tmp + 3) << 24;
367 printk(KERN_DEBUG " 0x%x\n", data);
368 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
369 tmp = tmp + 4;
370 }
371 switch (length % 4) {
372 case 1:
373 data = *tmp;
374 printk(KERN_DEBUG " 0x%x\n", data);
375 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
376 break;
377 case 2:
378 data = *tmp | *(tmp + 1) << 8;
379 printk(KERN_DEBUG " 0x%x\n", data);
380 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
381 break;
382 case 3:
383 data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
384 printk(KERN_DEBUG " 0x%x\n", data);
385 iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT);
386 break;
387 default:
388 break;
389 }
390 req->req.actual += length;
391 }
392}
393
394static void fusb300_set_epnstall(struct fusb300 *fusb300, u8 ep)
395{
396 fusb300_enable_bit(fusb300, FUSB300_OFFSET_EPSET0(ep),
397 FUSB300_EPSET0_STL);
398}
399
400static void fusb300_clear_epnstall(struct fusb300 *fusb300, u8 ep)
401{
402 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
403
404 if (reg & FUSB300_EPSET0_STL) {
405 printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep);
406 reg &= ~FUSB300_EPSET0_STL;
407 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
408 }
409}
410
411static void ep0_queue(struct fusb300_ep *ep, struct fusb300_request *req)
412{
413 if (ep->fusb300->ep0_dir) { /* if IN */
414 if (req->req.length) {
415 fusb300_wrcxf(ep, req);
416 } else
417 printk(KERN_DEBUG "%s : req->req.length = 0x%x\n",
418 __func__, req->req.length);
419 if ((req->req.length == req->req.actual) ||
420 (req->req.actual < ep->ep.maxpacket))
421 done(ep, req, 0);
422 } else { /* OUT */
423 if (!req->req.length)
424 done(ep, req, 0);
425 else
426 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER1,
427 FUSB300_IGER1_CX_OUT_INT);
428 }
429}
430
431static int fusb300_queue(struct usb_ep *_ep, struct usb_request *_req,
432 gfp_t gfp_flags)
433{
434 struct fusb300_ep *ep;
435 struct fusb300_request *req;
436 unsigned long flags;
437 int request = 0;
438
439 ep = container_of(_ep, struct fusb300_ep, ep);
440 req = container_of(_req, struct fusb300_request, req);
441
442 if (ep->fusb300->gadget.speed == USB_SPEED_UNKNOWN)
443 return -ESHUTDOWN;
444
445 spin_lock_irqsave(&ep->fusb300->lock, flags);
446
447 if (list_empty(&ep->queue))
448 request = 1;
449
450 list_add_tail(&req->queue, &ep->queue);
451
452 req->req.actual = 0;
453 req->req.status = -EINPROGRESS;
454
455 if (ep->desc == NULL) /* ep0 */
456 ep0_queue(ep, req);
457 else if (request && !ep->stall)
458 enable_fifo_int(ep);
459
460 spin_unlock_irqrestore(&ep->fusb300->lock, flags);
461
462 return 0;
463}
464
465static int fusb300_dequeue(struct usb_ep *_ep, struct usb_request *_req)
466{
467 struct fusb300_ep *ep;
468 struct fusb300_request *req;
469 unsigned long flags;
470
471 ep = container_of(_ep, struct fusb300_ep, ep);
472 req = container_of(_req, struct fusb300_request, req);
473
474 spin_lock_irqsave(&ep->fusb300->lock, flags);
475 if (!list_empty(&ep->queue))
476 done(ep, req, -ECONNRESET);
477 spin_unlock_irqrestore(&ep->fusb300->lock, flags);
478
479 return 0;
480}
481
482static int fusb300_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedge)
483{
484 struct fusb300_ep *ep;
485 struct fusb300 *fusb300;
486 unsigned long flags;
487 int ret = 0;
488
489 ep = container_of(_ep, struct fusb300_ep, ep);
490
491 fusb300 = ep->fusb300;
492
493 spin_lock_irqsave(&ep->fusb300->lock, flags);
494
495 if (!list_empty(&ep->queue)) {
496 ret = -EAGAIN;
497 goto out;
498 }
499
500 if (value) {
501 fusb300_set_epnstall(fusb300, ep->epnum);
502 ep->stall = 1;
503 if (wedge)
504 ep->wedged = 1;
505 } else {
506 fusb300_clear_epnstall(fusb300, ep->epnum);
507 ep->stall = 0;
508 ep->wedged = 0;
509 }
510
511out:
512 spin_unlock_irqrestore(&ep->fusb300->lock, flags);
513 return ret;
514}
515
516static int fusb300_set_halt(struct usb_ep *_ep, int value)
517{
518 return fusb300_set_halt_and_wedge(_ep, value, 0);
519}
520
521static int fusb300_set_wedge(struct usb_ep *_ep)
522{
523 return fusb300_set_halt_and_wedge(_ep, 1, 1);
524}
525
526static void fusb300_fifo_flush(struct usb_ep *_ep)
527{
528}
529
530static struct usb_ep_ops fusb300_ep_ops = {
531 .enable = fusb300_enable,
532 .disable = fusb300_disable,
533
534 .alloc_request = fusb300_alloc_request,
535 .free_request = fusb300_free_request,
536
537 .queue = fusb300_queue,
538 .dequeue = fusb300_dequeue,
539
540 .set_halt = fusb300_set_halt,
541 .fifo_flush = fusb300_fifo_flush,
542 .set_wedge = fusb300_set_wedge,
543};
544
545/*****************************************************************************/
546static void fusb300_clear_int(struct fusb300 *fusb300, u32 offset,
547 u32 value)
548{
549 iowrite32(value, fusb300->reg + offset);
550}
551
552static void fusb300_reset(void)
553{
554}
555
556static void fusb300_set_cxstall(struct fusb300 *fusb300)
557{
558 fusb300_enable_bit(fusb300, FUSB300_OFFSET_CSR,
559 FUSB300_CSR_STL);
560}
561
562static void fusb300_set_cxdone(struct fusb300 *fusb300)
563{
564 fusb300_enable_bit(fusb300, FUSB300_OFFSET_CSR,
565 FUSB300_CSR_DONE);
566}
567
568/* read data from cx fifo */
569void fusb300_rdcxf(struct fusb300 *fusb300,
570 u8 *buffer, u32 length)
571{
572 int i = 0;
573 u8 *tmp;
574 u32 data;
575
576 tmp = buffer;
577
578 for (i = (length >> 2); i > 0; i--) {
579 data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
580 printk(KERN_DEBUG " 0x%x\n", data);
581 *tmp = data & 0xFF;
582 *(tmp + 1) = (data >> 8) & 0xFF;
583 *(tmp + 2) = (data >> 16) & 0xFF;
584 *(tmp + 3) = (data >> 24) & 0xFF;
585 tmp = tmp + 4;
586 }
587
588 switch (length % 4) {
589 case 1:
590 data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
591 printk(KERN_DEBUG " 0x%x\n", data);
592 *tmp = data & 0xFF;
593 break;
594 case 2:
595 data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
596 printk(KERN_DEBUG " 0x%x\n", data);
597 *tmp = data & 0xFF;
598 *(tmp + 1) = (data >> 8) & 0xFF;
599 break;
600 case 3:
601 data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT);
602 printk(KERN_DEBUG " 0x%x\n", data);
603 *tmp = data & 0xFF;
604 *(tmp + 1) = (data >> 8) & 0xFF;
605 *(tmp + 2) = (data >> 16) & 0xFF;
606 break;
607 default:
608 break;
609 }
610}
611
612#if 0
613static void fusb300_dbg_fifo(struct fusb300_ep *ep,
614 u8 entry, u16 length)
615{
616 u32 reg;
617 u32 i = 0;
618 u32 j = 0;
619
620 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_GTM);
621 reg &= ~(FUSB300_GTM_TST_EP_ENTRY(0xF) |
622 FUSB300_GTM_TST_EP_NUM(0xF) | FUSB300_GTM_TST_FIFO_DEG);
623 reg |= (FUSB300_GTM_TST_EP_ENTRY(entry) |
624 FUSB300_GTM_TST_EP_NUM(ep->epnum) | FUSB300_GTM_TST_FIFO_DEG);
625 iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_GTM);
626
627 for (i = 0; i < (length >> 2); i++) {
628 if (i * 4 == 1024)
629 break;
630 reg = ioread32(ep->fusb300->reg +
631 FUSB300_OFFSET_BUFDBG_START + i * 4);
632 printk(KERN_DEBUG" 0x%-8x", reg);
633 j++;
634 if ((j % 4) == 0)
635 printk(KERN_DEBUG "\n");
636 }
637
638 if (length % 4) {
639 reg = ioread32(ep->fusb300->reg +
640 FUSB300_OFFSET_BUFDBG_START + i * 4);
641 printk(KERN_DEBUG " 0x%x\n", reg);
642 }
643
644 if ((j % 4) != 0)
645 printk(KERN_DEBUG "\n");
646
647 fusb300_disable_bit(ep->fusb300, FUSB300_OFFSET_GTM,
648 FUSB300_GTM_TST_FIFO_DEG);
649}
650
651static void fusb300_cmp_dbg_fifo(struct fusb300_ep *ep,
652 u8 entry, u16 length, u8 *golden)
653{
654 u32 reg;
655 u32 i = 0;
656 u32 golden_value;
657 u8 *tmp;
658
659 tmp = golden;
660
661 printk(KERN_DEBUG "fusb300_cmp_dbg_fifo (entry %d) : start\n", entry);
662
663 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_GTM);
664 reg &= ~(FUSB300_GTM_TST_EP_ENTRY(0xF) |
665 FUSB300_GTM_TST_EP_NUM(0xF) | FUSB300_GTM_TST_FIFO_DEG);
666 reg |= (FUSB300_GTM_TST_EP_ENTRY(entry) |
667 FUSB300_GTM_TST_EP_NUM(ep->epnum) | FUSB300_GTM_TST_FIFO_DEG);
668 iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_GTM);
669
670 for (i = 0; i < (length >> 2); i++) {
671 if (i * 4 == 1024)
672 break;
673 golden_value = *tmp | *(tmp + 1) << 8 |
674 *(tmp + 2) << 16 | *(tmp + 3) << 24;
675
676 reg = ioread32(ep->fusb300->reg +
677 FUSB300_OFFSET_BUFDBG_START + i*4);
678
679 if (reg != golden_value) {
680 printk(KERN_DEBUG "0x%x : ", (u32)(ep->fusb300->reg +
681 FUSB300_OFFSET_BUFDBG_START + i*4));
682 printk(KERN_DEBUG " golden = 0x%x, reg = 0x%x\n",
683 golden_value, reg);
684 }
685 tmp += 4;
686 }
687
688 switch (length % 4) {
689 case 1:
690 golden_value = *tmp;
691 case 2:
692 golden_value = *tmp | *(tmp + 1) << 8;
693 case 3:
694 golden_value = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
695 default:
696 break;
697
698 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_BUFDBG_START + i*4);
699 if (reg != golden_value) {
700 printk(KERN_DEBUG "0x%x:", (u32)(ep->fusb300->reg +
701 FUSB300_OFFSET_BUFDBG_START + i*4));
702 printk(KERN_DEBUG " golden = 0x%x, reg = 0x%x\n",
703 golden_value, reg);
704 }
705 }
706
707 printk(KERN_DEBUG "fusb300_cmp_dbg_fifo : end\n");
708 fusb300_disable_bit(ep->fusb300, FUSB300_OFFSET_GTM,
709 FUSB300_GTM_TST_FIFO_DEG);
710}
711#endif
712
713static void fusb300_rdfifo(struct fusb300_ep *ep,
714 struct fusb300_request *req,
715 u32 length)
716{
717 int i = 0;
718 u8 *tmp;
719 u32 data, reg;
720 struct fusb300 *fusb300 = ep->fusb300;
721
722 tmp = req->req.buf + req->req.actual;
723 req->req.actual += length;
724
725 if (req->req.actual > req->req.length)
726 printk(KERN_DEBUG "req->req.actual > req->req.length\n");
727
728 for (i = (length >> 2); i > 0; i--) {
729 data = ioread32(fusb300->reg +
730 FUSB300_OFFSET_EPPORT(ep->epnum));
731 *tmp = data & 0xFF;
732 *(tmp + 1) = (data >> 8) & 0xFF;
733 *(tmp + 2) = (data >> 16) & 0xFF;
734 *(tmp + 3) = (data >> 24) & 0xFF;
735 tmp = tmp + 4;
736 }
737
738 switch (length % 4) {
739 case 1:
740 data = ioread32(fusb300->reg +
741 FUSB300_OFFSET_EPPORT(ep->epnum));
742 *tmp = data & 0xFF;
743 break;
744 case 2:
745 data = ioread32(fusb300->reg +
746 FUSB300_OFFSET_EPPORT(ep->epnum));
747 *tmp = data & 0xFF;
748 *(tmp + 1) = (data >> 8) & 0xFF;
749 break;
750 case 3:
751 data = ioread32(fusb300->reg +
752 FUSB300_OFFSET_EPPORT(ep->epnum));
753 *tmp = data & 0xFF;
754 *(tmp + 1) = (data >> 8) & 0xFF;
755 *(tmp + 2) = (data >> 16) & 0xFF;
756 break;
757 default:
758 break;
759 }
760
761 do {
762 reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
763 reg &= FUSB300_IGR1_SYNF0_EMPTY_INT;
764 if (i)
765 printk(KERN_INFO "sync fifo is not empty!\n");
766 i++;
767 } while (!reg);
768}
769
770/* write data to fifo */
771static void fusb300_wrfifo(struct fusb300_ep *ep,
772 struct fusb300_request *req)
773{
774 int i = 0;
775 u8 *tmp;
776 u32 data, reg;
777 struct fusb300 *fusb300 = ep->fusb300;
778
779 tmp = req->req.buf;
780 req->req.actual = req->req.length;
781
782 for (i = (req->req.length >> 2); i > 0; i--) {
783 data = *tmp | *(tmp + 1) << 8 |
784 *(tmp + 2) << 16 | *(tmp + 3) << 24;
785
786 iowrite32(data, fusb300->reg +
787 FUSB300_OFFSET_EPPORT(ep->epnum));
788 tmp += 4;
789 }
790
791 switch (req->req.length % 4) {
792 case 1:
793 data = *tmp;
794 iowrite32(data, fusb300->reg +
795 FUSB300_OFFSET_EPPORT(ep->epnum));
796 break;
797 case 2:
798 data = *tmp | *(tmp + 1) << 8;
799 iowrite32(data, fusb300->reg +
800 FUSB300_OFFSET_EPPORT(ep->epnum));
801 break;
802 case 3:
803 data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
804 iowrite32(data, fusb300->reg +
805 FUSB300_OFFSET_EPPORT(ep->epnum));
806 break;
807 default:
808 break;
809 }
810
811 do {
812 reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
813 reg &= FUSB300_IGR1_SYNF0_EMPTY_INT;
814 if (i)
815 printk(KERN_INFO"sync fifo is not empty!\n");
816 i++;
817 } while (!reg);
818}
819
820static u8 fusb300_get_epnstall(struct fusb300 *fusb300, u8 ep)
821{
822 u8 value;
823 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
824
825 value = reg & FUSB300_EPSET0_STL;
826
827 return value;
828}
829
830static u8 fusb300_get_cxstall(struct fusb300 *fusb300)
831{
832 u8 value;
833 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_CSR);
834
835 value = (reg & FUSB300_CSR_STL) >> 1;
836
837 return value;
838}
839
840static void request_error(struct fusb300 *fusb300)
841{
842 fusb300_set_cxstall(fusb300);
843 printk(KERN_DEBUG "request error!!\n");
844}
845
846static void get_status(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
847__releases(fusb300->lock)
848__acquires(fusb300->lock)
849{
850 u8 ep;
851 u16 status = 0;
852 u16 w_index = ctrl->wIndex;
853
854 switch (ctrl->bRequestType & USB_RECIP_MASK) {
855 case USB_RECIP_DEVICE:
856 status = 1 << USB_DEVICE_SELF_POWERED;
857 break;
858 case USB_RECIP_INTERFACE:
859 status = 0;
860 break;
861 case USB_RECIP_ENDPOINT:
862 ep = w_index & USB_ENDPOINT_NUMBER_MASK;
863 if (ep) {
864 if (fusb300_get_epnstall(fusb300, ep))
865 status = 1 << USB_ENDPOINT_HALT;
866 } else {
867 if (fusb300_get_cxstall(fusb300))
868 status = 0;
869 }
870 break;
871
872 default:
873 request_error(fusb300);
874 return; /* exit */
875 }
876
877 fusb300->ep0_data = cpu_to_le16(status);
878 fusb300->ep0_req->buf = &fusb300->ep0_data;
879 fusb300->ep0_req->length = 2;
880
881 spin_unlock(&fusb300->lock);
882 fusb300_queue(fusb300->gadget.ep0, fusb300->ep0_req, GFP_KERNEL);
883 spin_lock(&fusb300->lock);
884}
885
886static void set_feature(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
887{
888 u8 ep;
889
890 switch (ctrl->bRequestType & USB_RECIP_MASK) {
891 case USB_RECIP_DEVICE:
892 fusb300_set_cxdone(fusb300);
893 break;
894 case USB_RECIP_INTERFACE:
895 fusb300_set_cxdone(fusb300);
896 break;
897 case USB_RECIP_ENDPOINT: {
898 u16 w_index = le16_to_cpu(ctrl->wIndex);
899
900 ep = w_index & USB_ENDPOINT_NUMBER_MASK;
901 if (ep)
902 fusb300_set_epnstall(fusb300, ep);
903 else
904 fusb300_set_cxstall(fusb300);
905 fusb300_set_cxdone(fusb300);
906 }
907 break;
908 default:
909 request_error(fusb300);
910 break;
911 }
912}
913
914static void fusb300_clear_seqnum(struct fusb300 *fusb300, u8 ep)
915{
916 fusb300_enable_bit(fusb300, FUSB300_OFFSET_EPSET0(ep),
917 FUSB300_EPSET0_CLRSEQNUM);
918}
919
920static void clear_feature(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
921{
922 struct fusb300_ep *ep =
923 fusb300->ep[ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK];
924
925 switch (ctrl->bRequestType & USB_RECIP_MASK) {
926 case USB_RECIP_DEVICE:
927 fusb300_set_cxdone(fusb300);
928 break;
929 case USB_RECIP_INTERFACE:
930 fusb300_set_cxdone(fusb300);
931 break;
932 case USB_RECIP_ENDPOINT:
933 if (ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK) {
934 if (ep->wedged) {
935 fusb300_set_cxdone(fusb300);
936 break;
937 }
938 if (ep->stall) {
939 ep->stall = 0;
940 fusb300_clear_seqnum(fusb300, ep->epnum);
941 fusb300_clear_epnstall(fusb300, ep->epnum);
942 if (!list_empty(&ep->queue))
943 enable_fifo_int(ep);
944 }
945 }
946 fusb300_set_cxdone(fusb300);
947 break;
948 default:
949 request_error(fusb300);
950 break;
951 }
952}
953
954static void fusb300_set_dev_addr(struct fusb300 *fusb300, u16 addr)
955{
956 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_DAR);
957
958 reg &= ~FUSB300_DAR_DRVADDR_MSK;
959 reg |= FUSB300_DAR_DRVADDR(addr);
960
961 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_DAR);
962}
963
964static void set_address(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
965{
966 if (ctrl->wValue >= 0x0100)
967 request_error(fusb300);
968 else {
969 fusb300_set_dev_addr(fusb300, ctrl->wValue);
970 fusb300_set_cxdone(fusb300);
971 }
972}
973
974#define UVC_COPY_DESCRIPTORS(mem, src) \
975 do { \
976 const struct usb_descriptor_header * const *__src; \
977 for (__src = src; *__src; ++__src) { \
978 memcpy(mem, *__src, (*__src)->bLength); \
979 mem += (*__src)->bLength; \
980 } \
981 } while (0)
982
983static void fusb300_ep0_complete(struct usb_ep *ep,
984 struct usb_request *req)
985{
986}
987
988static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
989{
990 u8 *p = (u8 *)ctrl;
991 u8 ret = 0;
992 u8 i = 0;
993
994 fusb300_rdcxf(fusb300, p, 8);
995 fusb300->ep0_dir = ctrl->bRequestType & USB_DIR_IN;
996 fusb300->ep0_length = ctrl->wLength;
997
998 /* check request */
999 if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
1000 switch (ctrl->bRequest) {
1001 case USB_REQ_GET_STATUS:
1002 get_status(fusb300, ctrl);
1003 break;
1004 case USB_REQ_CLEAR_FEATURE:
1005 clear_feature(fusb300, ctrl);
1006 break;
1007 case USB_REQ_SET_FEATURE:
1008 set_feature(fusb300, ctrl);
1009 break;
1010 case USB_REQ_SET_ADDRESS:
1011 set_address(fusb300, ctrl);
1012 break;
1013 case USB_REQ_SET_CONFIGURATION:
1014 fusb300_enable_bit(fusb300, FUSB300_OFFSET_DAR,
1015 FUSB300_DAR_SETCONFG);
1016 /* clear sequence number */
1017 for (i = 1; i <= FUSB300_MAX_NUM_EP; i++)
1018 fusb300_clear_seqnum(fusb300, i);
1019 fusb300->reenum = 1;
1020 ret = 1;
1021 break;
1022 default:
1023 ret = 1;
1024 break;
1025 }
1026 } else
1027 ret = 1;
1028
1029 return ret;
1030}
1031
1032static void fusb300_set_ep_bycnt(struct fusb300_ep *ep, u32 bycnt)
1033{
1034 struct fusb300 *fusb300 = ep->fusb300;
1035 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
1036
1037 reg &= ~FUSB300_FFR_BYCNT;
1038 reg |= bycnt & FUSB300_FFR_BYCNT;
1039
1040 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
1041}
1042
1043static void done(struct fusb300_ep *ep, struct fusb300_request *req,
1044 int status)
1045{
1046 list_del_init(&req->queue);
1047
1048 /* don't modify queue heads during completion callback */
1049 if (ep->fusb300->gadget.speed == USB_SPEED_UNKNOWN)
1050 req->req.status = -ESHUTDOWN;
1051 else
1052 req->req.status = status;
1053
1054 spin_unlock(&ep->fusb300->lock);
1055 req->req.complete(&ep->ep, &req->req);
1056 spin_lock(&ep->fusb300->lock);
1057
1058 if (ep->epnum) {
1059 disable_fifo_int(ep);
1060 if (!list_empty(&ep->queue))
1061 enable_fifo_int(ep);
1062 } else
1063 fusb300_set_cxdone(ep->fusb300);
1064}
1065
1066void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep,
1067 struct fusb300_request *req)
1068{
1069 u32 value;
1070 u32 reg;
1071
1072 /* wait SW owner */
1073 do {
1074 reg = ioread32(ep->fusb300->reg +
1075 FUSB300_OFFSET_EPPRD_W0(ep->epnum));
1076 reg &= FUSB300_EPPRD0_H;
1077 } while (reg);
1078
1079 iowrite32((u32) req->req.buf, ep->fusb300->reg +
1080 FUSB300_OFFSET_EPPRD_W1(ep->epnum));
1081
1082 value = FUSB300_EPPRD0_BTC(req->req.length) | FUSB300_EPPRD0_H |
1083 FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I;
1084 iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum));
1085
1086 iowrite32(0x0, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W2(ep->epnum));
1087
1088 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_EPPRDRDY,
1089 FUSB300_EPPRDR_EP_PRD_RDY(ep->epnum));
1090}
1091
1092static void fusb300_wait_idma_finished(struct fusb300_ep *ep)
1093{
1094 u32 reg;
1095
1096 do {
1097 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR1);
1098 if ((reg & FUSB300_IGR1_VBUS_CHG_INT) ||
1099 (reg & FUSB300_IGR1_WARM_RST_INT) ||
1100 (reg & FUSB300_IGR1_HOT_RST_INT) ||
1101 (reg & FUSB300_IGR1_USBRST_INT)
1102 )
1103 goto IDMA_RESET;
1104 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR0);
1105 reg &= FUSB300_IGR0_EPn_PRD_INT(ep->epnum);
1106 } while (!reg);
1107
1108 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0,
1109 FUSB300_IGR0_EPn_PRD_INT(ep->epnum));
1110IDMA_RESET:
1111 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGER0,
1112 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
1113}
1114
1115static void fusb300_set_idma(struct fusb300_ep *ep,
1116 struct fusb300_request *req)
1117{
1118 dma_addr_t d;
1119 u8 *tmp = NULL;
1120
1121 d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE);
1122
1123 if (dma_mapping_error(NULL, d)) {
1124 kfree(req->req.buf);
1125 printk(KERN_DEBUG "dma_mapping_error\n");
1126 }
1127
1128 dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE);
1129
1130 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0,
1131 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
1132
1133 tmp = req->req.buf;
1134 req->req.buf = (u8 *)d;
1135
1136 fusb300_fill_idma_prdtbl(ep, req);
1137 /* check idma is done */
1138 fusb300_wait_idma_finished(ep);
1139
1140 req->req.buf = tmp;
1141
1142 if (d)
1143 dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE);
1144}
1145
1146static void in_ep_fifo_handler(struct fusb300_ep *ep)
1147{
1148 struct fusb300_request *req = list_entry(ep->queue.next,
1149 struct fusb300_request, queue);
1150
1151 if (req->req.length) {
1152#if 0
1153 fusb300_set_ep_bycnt(ep, req->req.length);
1154 fusb300_wrfifo(ep, req);
1155#else
1156 fusb300_set_idma(ep, req);
1157#endif
1158 }
1159 done(ep, req, 0);
1160}
1161
1162static void out_ep_fifo_handler(struct fusb300_ep *ep)
1163{
1164 struct fusb300 *fusb300 = ep->fusb300;
1165 struct fusb300_request *req = list_entry(ep->queue.next,
1166 struct fusb300_request, queue);
1167 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
1168 u32 length = reg & FUSB300_FFR_BYCNT;
1169
1170 fusb300_rdfifo(ep, req, length);
1171
1172 /* finish out transfer */
1173 if ((req->req.length == req->req.actual) || (length < ep->ep.maxpacket))
1174 done(ep, req, 0);
1175}
1176
1177static void check_device_mode(struct fusb300 *fusb300)
1178{
1179 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_GCR);
1180
1181 switch (reg & FUSB300_GCR_DEVEN_MSK) {
1182 case FUSB300_GCR_DEVEN_SS:
1183 fusb300->gadget.speed = USB_SPEED_SUPER;
1184 break;
1185 case FUSB300_GCR_DEVEN_HS:
1186 fusb300->gadget.speed = USB_SPEED_HIGH;
1187 break;
1188 case FUSB300_GCR_DEVEN_FS:
1189 fusb300->gadget.speed = USB_SPEED_FULL;
1190 break;
1191 default:
1192 fusb300->gadget.speed = USB_SPEED_UNKNOWN;
1193 break;
1194 }
1195 printk(KERN_INFO "dev_mode = %d\n", (reg & FUSB300_GCR_DEVEN_MSK));
1196}
1197
1198
1199static void fusb300_ep0out(struct fusb300 *fusb300)
1200{
1201 struct fusb300_ep *ep = fusb300->ep[0];
1202 u32 reg;
1203
1204 if (!list_empty(&ep->queue)) {
1205 struct fusb300_request *req;
1206
1207 req = list_first_entry(&ep->queue,
1208 struct fusb300_request, queue);
1209 if (req->req.length)
1210 fusb300_rdcxf(ep->fusb300, req->req.buf,
1211 req->req.length);
1212 done(ep, req, 0);
1213 reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1);
1214 reg &= ~FUSB300_IGER1_CX_OUT_INT;
1215 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_IGER1);
1216 } else
1217 pr_err("%s : empty queue\n", __func__);
1218}
1219
1220static void fusb300_ep0in(struct fusb300 *fusb300)
1221{
1222 struct fusb300_request *req;
1223 struct fusb300_ep *ep = fusb300->ep[0];
1224
1225 if ((!list_empty(&ep->queue)) && (fusb300->ep0_dir)) {
1226 req = list_entry(ep->queue.next,
1227 struct fusb300_request, queue);
1228 if (req->req.length)
1229 fusb300_wrcxf(ep, req);
1230 if ((req->req.length - req->req.actual) < ep->ep.maxpacket)
1231 done(ep, req, 0);
1232 } else
1233 fusb300_set_cxdone(fusb300);
1234}
1235
1236static void fusb300_grp2_handler(void)
1237{
1238}
1239
1240static void fusb300_grp3_handler(void)
1241{
1242}
1243
1244static void fusb300_grp4_handler(void)
1245{
1246}
1247
1248static void fusb300_grp5_handler(void)
1249{
1250}
1251
1252static irqreturn_t fusb300_irq(int irq, void *_fusb300)
1253{
1254 struct fusb300 *fusb300 = _fusb300;
1255 u32 int_grp1 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
1256 u32 int_grp1_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1);
1257 u32 int_grp0 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR0);
1258 u32 int_grp0_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER0);
1259 struct usb_ctrlrequest ctrl;
1260 u8 in;
1261 u32 reg;
1262 int i;
1263
1264 spin_lock(&fusb300->lock);
1265
1266 int_grp1 &= int_grp1_en;
1267 int_grp0 &= int_grp0_en;
1268
1269 if (int_grp1 & FUSB300_IGR1_WARM_RST_INT) {
1270 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1271 FUSB300_IGR1_WARM_RST_INT);
1272 printk(KERN_INFO"fusb300_warmreset\n");
1273 fusb300_reset();
1274 }
1275
1276 if (int_grp1 & FUSB300_IGR1_HOT_RST_INT) {
1277 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1278 FUSB300_IGR1_HOT_RST_INT);
1279 printk(KERN_INFO"fusb300_hotreset\n");
1280 fusb300_reset();
1281 }
1282
1283 if (int_grp1 & FUSB300_IGR1_USBRST_INT) {
1284 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1285 FUSB300_IGR1_USBRST_INT);
1286 fusb300_reset();
1287 }
1288 /* COMABT_INT has a highest priority */
1289
1290 if (int_grp1 & FUSB300_IGR1_CX_COMABT_INT) {
1291 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1292 FUSB300_IGR1_CX_COMABT_INT);
1293 printk(KERN_INFO"fusb300_ep0abt\n");
1294 }
1295
1296 if (int_grp1 & FUSB300_IGR1_VBUS_CHG_INT) {
1297 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1298 FUSB300_IGR1_VBUS_CHG_INT);
1299 printk(KERN_INFO"fusb300_vbus_change\n");
1300 }
1301
1302 if (int_grp1 & FUSB300_IGR1_U3_EXIT_FAIL_INT) {
1303 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1304 FUSB300_IGR1_U3_EXIT_FAIL_INT);
1305 }
1306
1307 if (int_grp1 & FUSB300_IGR1_U2_EXIT_FAIL_INT) {
1308 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1309 FUSB300_IGR1_U2_EXIT_FAIL_INT);
1310 }
1311
1312 if (int_grp1 & FUSB300_IGR1_U1_EXIT_FAIL_INT) {
1313 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1314 FUSB300_IGR1_U1_EXIT_FAIL_INT);
1315 }
1316
1317 if (int_grp1 & FUSB300_IGR1_U2_ENTRY_FAIL_INT) {
1318 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1319 FUSB300_IGR1_U2_ENTRY_FAIL_INT);
1320 }
1321
1322 if (int_grp1 & FUSB300_IGR1_U1_ENTRY_FAIL_INT) {
1323 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1324 FUSB300_IGR1_U1_ENTRY_FAIL_INT);
1325 }
1326
1327 if (int_grp1 & FUSB300_IGR1_U3_EXIT_INT) {
1328 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1329 FUSB300_IGR1_U3_EXIT_INT);
1330 printk(KERN_INFO "FUSB300_IGR1_U3_EXIT_INT\n");
1331 }
1332
1333 if (int_grp1 & FUSB300_IGR1_U2_EXIT_INT) {
1334 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1335 FUSB300_IGR1_U2_EXIT_INT);
1336 printk(KERN_INFO "FUSB300_IGR1_U2_EXIT_INT\n");
1337 }
1338
1339 if (int_grp1 & FUSB300_IGR1_U1_EXIT_INT) {
1340 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1341 FUSB300_IGR1_U1_EXIT_INT);
1342 printk(KERN_INFO "FUSB300_IGR1_U1_EXIT_INT\n");
1343 }
1344
1345 if (int_grp1 & FUSB300_IGR1_U3_ENTRY_INT) {
1346 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1347 FUSB300_IGR1_U3_ENTRY_INT);
1348 printk(KERN_INFO "FUSB300_IGR1_U3_ENTRY_INT\n");
1349 fusb300_enable_bit(fusb300, FUSB300_OFFSET_SSCR1,
1350 FUSB300_SSCR1_GO_U3_DONE);
1351 }
1352
1353 if (int_grp1 & FUSB300_IGR1_U2_ENTRY_INT) {
1354 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1355 FUSB300_IGR1_U2_ENTRY_INT);
1356 printk(KERN_INFO "FUSB300_IGR1_U2_ENTRY_INT\n");
1357 }
1358
1359 if (int_grp1 & FUSB300_IGR1_U1_ENTRY_INT) {
1360 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1361 FUSB300_IGR1_U1_ENTRY_INT);
1362 printk(KERN_INFO "FUSB300_IGR1_U1_ENTRY_INT\n");
1363 }
1364
1365 if (int_grp1 & FUSB300_IGR1_RESM_INT) {
1366 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1367 FUSB300_IGR1_RESM_INT);
1368 printk(KERN_INFO "fusb300_resume\n");
1369 }
1370
1371 if (int_grp1 & FUSB300_IGR1_SUSP_INT) {
1372 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1373 FUSB300_IGR1_SUSP_INT);
1374 printk(KERN_INFO "fusb300_suspend\n");
1375 }
1376
1377 if (int_grp1 & FUSB300_IGR1_HS_LPM_INT) {
1378 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1379 FUSB300_IGR1_HS_LPM_INT);
1380 printk(KERN_INFO "fusb300_HS_LPM_INT\n");
1381 }
1382
1383 if (int_grp1 & FUSB300_IGR1_DEV_MODE_CHG_INT) {
1384 fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1,
1385 FUSB300_IGR1_DEV_MODE_CHG_INT);
1386 check_device_mode(fusb300);
1387 }
1388
1389 if (int_grp1 & FUSB300_IGR1_CX_COMFAIL_INT) {
1390 fusb300_set_cxstall(fusb300);
1391 printk(KERN_INFO "fusb300_ep0fail\n");
1392 }
1393
1394 if (int_grp1 & FUSB300_IGR1_CX_SETUP_INT) {
1395 printk(KERN_INFO "fusb300_ep0setup\n");
1396 if (setup_packet(fusb300, &ctrl)) {
1397 spin_unlock(&fusb300->lock);
1398 if (fusb300->driver->setup(&fusb300->gadget, &ctrl) < 0)
1399 fusb300_set_cxstall(fusb300);
1400 spin_lock(&fusb300->lock);
1401 }
1402 }
1403
1404 if (int_grp1 & FUSB300_IGR1_CX_CMDEND_INT)
1405 printk(KERN_INFO "fusb300_cmdend\n");
1406
1407
1408 if (int_grp1 & FUSB300_IGR1_CX_OUT_INT) {
1409 printk(KERN_INFO "fusb300_cxout\n");
1410 fusb300_ep0out(fusb300);
1411 }
1412
1413 if (int_grp1 & FUSB300_IGR1_CX_IN_INT) {
1414 printk(KERN_INFO "fusb300_cxin\n");
1415 fusb300_ep0in(fusb300);
1416 }
1417
1418 if (int_grp1 & FUSB300_IGR1_INTGRP5)
1419 fusb300_grp5_handler();
1420
1421 if (int_grp1 & FUSB300_IGR1_INTGRP4)
1422 fusb300_grp4_handler();
1423
1424 if (int_grp1 & FUSB300_IGR1_INTGRP3)
1425 fusb300_grp3_handler();
1426
1427 if (int_grp1 & FUSB300_IGR1_INTGRP2)
1428 fusb300_grp2_handler();
1429
1430 if (int_grp0) {
1431 for (i = 1; i < FUSB300_MAX_NUM_EP; i++) {
1432 if (int_grp0 & FUSB300_IGR0_EPn_FIFO_INT(i)) {
1433 reg = ioread32(fusb300->reg +
1434 FUSB300_OFFSET_EPSET1(i));
1435 in = (reg & FUSB300_EPSET1_DIRIN) ? 1 : 0;
1436 if (in)
1437 in_ep_fifo_handler(fusb300->ep[i]);
1438 else
1439 out_ep_fifo_handler(fusb300->ep[i]);
1440 }
1441 }
1442 }
1443
1444 spin_unlock(&fusb300->lock);
1445
1446 return IRQ_HANDLED;
1447}
1448
1449static void fusb300_set_u2_timeout(struct fusb300 *fusb300,
1450 u32 time)
1451{
1452 u32 reg;
1453
1454 reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT);
1455 reg &= ~0xff;
1456 reg |= FUSB300_SSCR2_U2TIMEOUT(time);
1457
1458 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT);
1459}
1460
1461static void fusb300_set_u1_timeout(struct fusb300 *fusb300,
1462 u32 time)
1463{
1464 u32 reg;
1465
1466 reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT);
1467 reg &= ~(0xff << 8);
1468 reg |= FUSB300_SSCR2_U1TIMEOUT(time);
1469
1470 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT);
1471}
1472
1473static void init_controller(struct fusb300 *fusb300)
1474{
1475 u32 reg;
1476 u32 mask = 0;
1477 u32 val = 0;
1478
1479 /* split on */
1480 mask = val = FUSB300_AHBBCR_S0_SPLIT_ON | FUSB300_AHBBCR_S1_SPLIT_ON;
1481 reg = ioread32(fusb300->reg + FUSB300_OFFSET_AHBCR);
1482 reg &= ~mask;
1483 reg |= val;
1484 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_AHBCR);
1485
1486 /* enable high-speed LPM */
1487 mask = val = FUSB300_HSCR_HS_LPM_PERMIT;
1488 reg = ioread32(fusb300->reg + FUSB300_OFFSET_HSCR);
1489 reg &= ~mask;
1490 reg |= val;
1491 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_HSCR);
1492
1493 /*set u1 u2 timmer*/
1494 fusb300_set_u2_timeout(fusb300, 0xff);
1495 fusb300_set_u1_timeout(fusb300, 0xff);
1496
1497 /* enable all grp1 interrupt */
1498 iowrite32(0xcfffff9f, fusb300->reg + FUSB300_OFFSET_IGER1);
1499}
1500/*------------------------------------------------------------------------*/
1501static struct fusb300 *the_controller;
1502
1503int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1504 int (*bind)(struct usb_gadget *))
1505{
1506 struct fusb300 *fusb300 = the_controller;
1507 int retval;
1508
1509 if (!driver
1510 || driver->speed < USB_SPEED_FULL
1511 || !bind
1512 || !driver->setup)
1513 return -EINVAL;
1514
1515 if (!fusb300)
1516 return -ENODEV;
1517
1518 if (fusb300->driver)
1519 return -EBUSY;
1520
1521 /* hook up the driver */
1522 driver->driver.bus = NULL;
1523 fusb300->driver = driver;
1524 fusb300->gadget.dev.driver = &driver->driver;
1525
1526 retval = device_add(&fusb300->gadget.dev);
1527 if (retval) {
1528 pr_err("device_add error (%d)\n", retval);
1529 goto error;
1530 }
1531
1532 retval = bind(&fusb300->gadget);
1533 if (retval) {
1534 pr_err("bind to driver error (%d)\n", retval);
1535 device_del(&fusb300->gadget.dev);
1536 goto error;
1537 }
1538
1539 return 0;
1540
1541error:
1542 fusb300->driver = NULL;
1543 fusb300->gadget.dev.driver = NULL;
1544
1545 return retval;
1546}
1547EXPORT_SYMBOL(usb_gadget_probe_driver);
1548
1549int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1550{
1551 struct fusb300 *fusb300 = the_controller;
1552
1553 if (driver != fusb300->driver || !driver->unbind)
1554 return -EINVAL;
1555
1556 driver->unbind(&fusb300->gadget);
1557 fusb300->gadget.dev.driver = NULL;
1558
1559 init_controller(fusb300);
1560 device_del(&fusb300->gadget.dev);
1561 fusb300->driver = NULL;
1562
1563 return 0;
1564}
1565EXPORT_SYMBOL(usb_gadget_unregister_driver);
1566/*--------------------------------------------------------------------------*/
1567
1568static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
1569{
1570 return 0;
1571}
1572
1573static struct usb_gadget_ops fusb300_gadget_ops = {
1574 .pullup = fusb300_udc_pullup,
1575};
1576
1577static int __exit fusb300_remove(struct platform_device *pdev)
1578{
1579 struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev);
1580
1581 iounmap(fusb300->reg);
1582 free_irq(platform_get_irq(pdev, 0), fusb300);
1583
1584 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
1585 kfree(fusb300);
1586
1587 return 0;
1588}
1589
1590static int __init fusb300_probe(struct platform_device *pdev)
1591{
1592 struct resource *res, *ires, *ires1;
1593 void __iomem *reg = NULL;
1594 struct fusb300 *fusb300 = NULL;
1595 struct fusb300_ep *_ep[FUSB300_MAX_NUM_EP];
1596 int ret = 0;
1597 int i;
1598
1599 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1600 if (!res) {
1601 ret = -ENODEV;
1602 pr_err("platform_get_resource error.\n");
1603 goto clean_up;
1604 }
1605
1606 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1607 if (!ires) {
1608 ret = -ENODEV;
1609 dev_err(&pdev->dev,
1610 "platform_get_resource IORESOURCE_IRQ error.\n");
1611 goto clean_up;
1612 }
1613
1614 ires1 = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
1615 if (!ires1) {
1616 ret = -ENODEV;
1617 dev_err(&pdev->dev,
1618 "platform_get_resource IORESOURCE_IRQ 1 error.\n");
1619 goto clean_up;
1620 }
1621
1622 reg = ioremap(res->start, resource_size(res));
1623 if (reg == NULL) {
1624 ret = -ENOMEM;
1625 pr_err("ioremap error.\n");
1626 goto clean_up;
1627 }
1628
1629 /* initialize udc */
1630 fusb300 = kzalloc(sizeof(struct fusb300), GFP_KERNEL);
1631 if (fusb300 == NULL) {
1632 pr_err("kzalloc error\n");
1633 goto clean_up;
1634 }
1635
1636 for (i = 0; i < FUSB300_MAX_NUM_EP; i++) {
1637 _ep[i] = kzalloc(sizeof(struct fusb300_ep), GFP_KERNEL);
1638 if (_ep[i] == NULL) {
1639 pr_err("_ep kzalloc error\n");
1640 goto clean_up;
1641 }
1642 fusb300->ep[i] = _ep[i];
1643 }
1644
1645 spin_lock_init(&fusb300->lock);
1646
1647 dev_set_drvdata(&pdev->dev, fusb300);
1648
1649 fusb300->gadget.ops = &fusb300_gadget_ops;
1650
1651 device_initialize(&fusb300->gadget.dev);
1652
1653 dev_set_name(&fusb300->gadget.dev, "gadget");
1654
1655 fusb300->gadget.is_dualspeed = 1;
1656 fusb300->gadget.dev.parent = &pdev->dev;
1657 fusb300->gadget.dev.dma_mask = pdev->dev.dma_mask;
1658 fusb300->gadget.dev.release = pdev->dev.release;
1659 fusb300->gadget.name = udc_name;
1660 fusb300->reg = reg;
1661
1662 ret = request_irq(ires->start, fusb300_irq, IRQF_DISABLED | IRQF_SHARED,
1663 udc_name, fusb300);
1664 if (ret < 0) {
1665 pr_err("request_irq error (%d)\n", ret);
1666 goto clean_up;
1667 }
1668
1669 ret = request_irq(ires1->start, fusb300_irq,
1670 IRQF_DISABLED | IRQF_SHARED, udc_name, fusb300);
1671 if (ret < 0) {
1672 pr_err("request_irq1 error (%d)\n", ret);
1673 goto clean_up;
1674 }
1675
1676 INIT_LIST_HEAD(&fusb300->gadget.ep_list);
1677
1678 for (i = 0; i < FUSB300_MAX_NUM_EP ; i++) {
1679 struct fusb300_ep *ep = fusb300->ep[i];
1680
1681 if (i != 0) {
1682 INIT_LIST_HEAD(&fusb300->ep[i]->ep.ep_list);
1683 list_add_tail(&fusb300->ep[i]->ep.ep_list,
1684 &fusb300->gadget.ep_list);
1685 }
1686 ep->fusb300 = fusb300;
1687 INIT_LIST_HEAD(&ep->queue);
1688 ep->ep.name = fusb300_ep_name[i];
1689 ep->ep.ops = &fusb300_ep_ops;
1690 ep->ep.maxpacket = HS_BULK_MAX_PACKET_SIZE;
1691 }
1692 fusb300->ep[0]->ep.maxpacket = HS_CTL_MAX_PACKET_SIZE;
1693 fusb300->ep[0]->epnum = 0;
1694 fusb300->gadget.ep0 = &fusb300->ep[0]->ep;
1695 INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list);
1696
1697 the_controller = fusb300;
1698
1699 fusb300->ep0_req = fusb300_alloc_request(&fusb300->ep[0]->ep,
1700 GFP_KERNEL);
1701 if (fusb300->ep0_req == NULL)
1702 goto clean_up3;
1703
1704 init_controller(fusb300);
1705 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1706
1707 return 0;
1708
1709clean_up3:
1710 free_irq(ires->start, fusb300);
1711
1712clean_up:
1713 if (fusb300) {
1714 if (fusb300->ep0_req)
1715 fusb300_free_request(&fusb300->ep[0]->ep,
1716 fusb300->ep0_req);
1717 kfree(fusb300);
1718 }
1719 if (reg)
1720 iounmap(reg);
1721
1722 return ret;
1723}
1724
1725static struct platform_driver fusb300_driver = {
1726 .remove = __exit_p(fusb300_remove),
1727 .driver = {
1728 .name = (char *) udc_name,
1729 .owner = THIS_MODULE,
1730 },
1731};
1732
1733static int __init fusb300_udc_init(void)
1734{
1735 return platform_driver_probe(&fusb300_driver, fusb300_probe);
1736}
1737
1738module_init(fusb300_udc_init);
1739
1740static void __exit fusb300_udc_cleanup(void)
1741{
1742 platform_driver_unregister(&fusb300_driver);
1743}
1744module_exit(fusb300_udc_cleanup);
diff --git a/drivers/usb/gadget/fusb300_udc.h b/drivers/usb/gadget/fusb300_udc.h
new file mode 100644
index 000000000000..f51aa2ef1f90
--- /dev/null
+++ b/drivers/usb/gadget/fusb300_udc.h
@@ -0,0 +1,687 @@
1/*
2 * Fusb300 UDC (USB gadget)
3 *
4 * Copyright (C) 2010 Faraday Technology Corp.
5 *
6 * Author : Yuan-hsin Chen <yhchen@faraday-tech.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23
24#ifndef __FUSB300_UDC_H__
25#define __FUSB300_UDC_H_
26
27#include <linux/kernel.h>
28
29#define FUSB300_OFFSET_GCR 0x00
30#define FUSB300_OFFSET_GTM 0x04
31#define FUSB300_OFFSET_DAR 0x08
32#define FUSB300_OFFSET_CSR 0x0C
33#define FUSB300_OFFSET_CXPORT 0x10
34#define FUSB300_OFFSET_EPSET0(n) (0x20 + (n - 1) * 0x30)
35#define FUSB300_OFFSET_EPSET1(n) (0x24 + (n - 1) * 0x30)
36#define FUSB300_OFFSET_EPSET2(n) (0x28 + (n - 1) * 0x30)
37#define FUSB300_OFFSET_EPFFR(n) (0x2c + (n - 1) * 0x30)
38#define FUSB300_OFFSET_EPSTRID(n) (0x40 + (n - 1) * 0x30)
39#define FUSB300_OFFSET_HSPTM 0x300
40#define FUSB300_OFFSET_HSCR 0x304
41#define FUSB300_OFFSET_SSCR0 0x308
42#define FUSB300_OFFSET_SSCR1 0x30C
43#define FUSB300_OFFSET_TT 0x310
44#define FUSB300_OFFSET_DEVNOTF 0x314
45#define FUSB300_OFFSET_DNC1 0x318
46#define FUSB300_OFFSET_CS 0x31C
47#define FUSB300_OFFSET_SOF 0x324
48#define FUSB300_OFFSET_EFCS 0x328
49#define FUSB300_OFFSET_IGR0 0x400
50#define FUSB300_OFFSET_IGR1 0x404
51#define FUSB300_OFFSET_IGR2 0x408
52#define FUSB300_OFFSET_IGR3 0x40C
53#define FUSB300_OFFSET_IGR4 0x410
54#define FUSB300_OFFSET_IGR5 0x414
55#define FUSB300_OFFSET_IGER0 0x420
56#define FUSB300_OFFSET_IGER1 0x424
57#define FUSB300_OFFSET_IGER2 0x428
58#define FUSB300_OFFSET_IGER3 0x42C
59#define FUSB300_OFFSET_IGER4 0x430
60#define FUSB300_OFFSET_IGER5 0x434
61#define FUSB300_OFFSET_DMAHMER 0x500
62#define FUSB300_OFFSET_EPPRDRDY 0x504
63#define FUSB300_OFFSET_DMAEPMR 0x508
64#define FUSB300_OFFSET_DMAENR 0x50C
65#define FUSB300_OFFSET_DMAAPR 0x510
66#define FUSB300_OFFSET_AHBCR 0x514
67#define FUSB300_OFFSET_EPPRD_W0(n) (0x520 + (n - 1) * 0x10)
68#define FUSB300_OFFSET_EPPRD_W1(n) (0x524 + (n - 1) * 0x10)
69#define FUSB300_OFFSET_EPPRD_W2(n) (0x528 + (n - 1) * 0x10)
70#define FUSB300_OFFSET_EPRD_PTR(n) (0x52C + (n - 1) * 0x10)
71#define FUSB300_OFFSET_BUFDBG_START 0x800
72#define FUSB300_OFFSET_BUFDBG_END 0xBFC
73#define FUSB300_OFFSET_EPPORT(n) (0x1010 + (n - 1) * 0x10)
74
75/*
76 * * Global Control Register (offset = 000H)
77 * */
78#define FUSB300_GCR_SF_RST (1 << 8)
79#define FUSB300_GCR_VBUS_STATUS (1 << 7)
80#define FUSB300_GCR_FORCE_HS_SUSP (1 << 6)
81#define FUSB300_GCR_SYNC_FIFO1_CLR (1 << 5)
82#define FUSB300_GCR_SYNC_FIFO0_CLR (1 << 4)
83#define FUSB300_GCR_FIFOCLR (1 << 3)
84#define FUSB300_GCR_GLINTEN (1 << 2)
85#define FUSB300_GCR_DEVEN_FS 0x3
86#define FUSB300_GCR_DEVEN_HS 0x2
87#define FUSB300_GCR_DEVEN_SS 0x1
88#define FUSB300_GCR_DEVDIS 0x0
89#define FUSB300_GCR_DEVEN_MSK 0x3
90
91
92/*
93 * *Global Test Mode (offset = 004H)
94 * */
95#define FUSB300_GTM_TST_DIS_SOFGEN (1 << 16)
96#define FUSB300_GTM_TST_CUR_EP_ENTRY(n) ((n & 0xF) << 12)
97#define FUSB300_GTM_TST_EP_ENTRY(n) ((n & 0xF) << 8)
98#define FUSB300_GTM_TST_EP_NUM(n) ((n & 0xF) << 4)
99#define FUSB300_GTM_TST_FIFO_DEG (1 << 1)
100#define FUSB300_GTM_TSTMODE (1 << 0)
101
102/*
103 * * Device Address Register (offset = 008H)
104 * */
105#define FUSB300_DAR_SETCONFG (1 << 7)
106#define FUSB300_DAR_DRVADDR(x) (x & 0x7F)
107#define FUSB300_DAR_DRVADDR_MSK 0x7F
108
109/*
110 * *Control Transfer Configuration and Status Register
111 * (CX_Config_Status, offset = 00CH)
112 * */
113#define FUSB300_CSR_LEN(x) ((x & 0xFFFF) << 8)
114#define FUSB300_CSR_LEN_MSK (0xFFFF << 8)
115#define FUSB300_CSR_EMP (1 << 4)
116#define FUSB300_CSR_FUL (1 << 3)
117#define FUSB300_CSR_CLR (1 << 2)
118#define FUSB300_CSR_STL (1 << 1)
119#define FUSB300_CSR_DONE (1 << 0)
120
121/*
122 * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 )
123 * */
124#define FUSB300_EPSET0_CLRSEQNUM (1 << 2)
125#define FUSB300_EPSET0_EPn_TX0BYTE (1 << 1)
126#define FUSB300_EPSET0_STL (1 << 0)
127
128/*
129 * * EPn Setting 1 (EPn_SET1, offset = 024H+(n-1)*30H, n=1~15)
130 * */
131#define FUSB300_EPSET1_START_ENTRY(x) ((x & 0xFF) << 24)
132#define FUSB300_EPSET1_START_ENTRY_MSK (0xFF << 24)
133#define FUSB300_EPSET1_FIFOENTRY(x) ((x & 0x1F) << 12)
134#define FUSB300_EPSET1_FIFOENTRY_MSK (0x1f << 12)
135#define FUSB300_EPSET1_INTERVAL(x) ((x & 0x7) << 6)
136#define FUSB300_EPSET1_BWNUM(x) ((x & 0x3) << 4)
137#define FUSB300_EPSET1_TYPEISO (1 << 2)
138#define FUSB300_EPSET1_TYPEBLK (2 << 2)
139#define FUSB300_EPSET1_TYPEINT (3 << 2)
140#define FUSB300_EPSET1_TYPE(x) ((x & 0x3) << 2)
141#define FUSB300_EPSET1_TYPE_MSK (0x3 << 2)
142#define FUSB300_EPSET1_DIROUT (0 << 1)
143#define FUSB300_EPSET1_DIRIN (1 << 1)
144#define FUSB300_EPSET1_DIR(x) ((x & 0x1) << 1)
145#define FUSB300_EPSET1_DIRIN (1 << 1)
146#define FUSB300_EPSET1_DIR_MSK ((0x1) << 1)
147#define FUSB300_EPSET1_ACTDIS 0
148#define FUSB300_EPSET1_ACTEN 1
149
150/*
151 * *EPn Setting 2 (EPn_SET2, offset = 028H+(n-1)*30H, n=1~15)
152 * */
153#define FUSB300_EPSET2_ADDROFS(x) ((x & 0x7FFF) << 16)
154#define FUSB300_EPSET2_ADDROFS_MSK (0x7fff << 16)
155#define FUSB300_EPSET2_MPS(x) (x & 0x7FF)
156#define FUSB300_EPSET2_MPS_MSK 0x7FF
157
158/*
159 * * EPn FIFO Register (offset = 2cH+(n-1)*30H)
160 * */
161#define FUSB300_FFR_RST (1 << 31)
162#define FUSB300_FF_FUL (1 << 30)
163#define FUSB300_FF_EMPTY (1 << 29)
164#define FUSB300_FFR_BYCNT 0x1FFFF
165
166/*
167 * *EPn Stream ID (EPn_STR_ID, offset = 040H+(n-1)*30H, n=1~15)
168 * */
169#define FUSB300_STRID_STREN (1 << 16)
170#define FUSB300_STRID_STRID(x) (x & 0xFFFF)
171
172/*
173 * *HS PHY Test Mode (offset = 300H)
174 * */
175#define FUSB300_HSPTM_TSTPKDONE (1 << 4)
176#define FUSB300_HSPTM_TSTPKT (1 << 3)
177#define FUSB300_HSPTM_TSTSET0NAK (1 << 2)
178#define FUSB300_HSPTM_TSTKSTA (1 << 1)
179#define FUSB300_HSPTM_TSTJSTA (1 << 0)
180
181/*
182 * *HS Control Register (offset = 304H)
183 * */
184#define FUSB300_HSCR_HS_LPM_PERMIT (1 << 8)
185#define FUSB300_HSCR_HS_LPM_RMWKUP (1 << 7)
186#define FUSB300_HSCR_CAP_LPM_RMWKUP (1 << 6)
187#define FUSB300_HSCR_HS_GOSUSP (1 << 5)
188#define FUSB300_HSCR_HS_GORMWKU (1 << 4)
189#define FUSB300_HSCR_CAP_RMWKUP (1 << 3)
190#define FUSB300_HSCR_IDLECNT_0MS 0
191#define FUSB300_HSCR_IDLECNT_1MS 1
192#define FUSB300_HSCR_IDLECNT_2MS 2
193#define FUSB300_HSCR_IDLECNT_3MS 3
194#define FUSB300_HSCR_IDLECNT_4MS 4
195#define FUSB300_HSCR_IDLECNT_5MS 5
196#define FUSB300_HSCR_IDLECNT_6MS 6
197#define FUSB300_HSCR_IDLECNT_7MS 7
198
199/*
200 * * SS Controller Register 0 (offset = 308H)
201 * */
202#define FUSB300_SSCR0_MAX_INTERVAL(x) ((x & 0x7) << 4)
203#define FUSB300_SSCR0_U2_FUN_EN (1 << 1)
204#define FUSB300_SSCR0_U1_FUN_EN (1 << 0)
205
206/*
207 * * SS Controller Register 1 (offset = 30CH)
208 * */
209#define FUSB300_SSCR1_GO_U3_DONE (1 << 8)
210#define FUSB300_SSCR1_TXDEEMPH_LEVEL (1 << 7)
211#define FUSB300_SSCR1_DIS_SCRMB (1 << 6)
212#define FUSB300_SSCR1_FORCE_RECOVERY (1 << 5)
213#define FUSB300_SSCR1_U3_WAKEUP_EN (1 << 4)
214#define FUSB300_SSCR1_U2_EXIT_EN (1 << 3)
215#define FUSB300_SSCR1_U1_EXIT_EN (1 << 2)
216#define FUSB300_SSCR1_U2_ENTRY_EN (1 << 1)
217#define FUSB300_SSCR1_U1_ENTRY_EN (1 << 0)
218
219/*
220 * *SS Controller Register 2 (offset = 310H)
221 * */
222#define FUSB300_SSCR2_SS_TX_SWING (1 << 25)
223#define FUSB300_SSCR2_FORCE_LINKPM_ACCEPT (1 << 24)
224#define FUSB300_SSCR2_U2_INACT_TIMEOUT(x) ((x & 0xFF) << 16)
225#define FUSB300_SSCR2_U1TIMEOUT(x) ((x & 0xFF) << 8)
226#define FUSB300_SSCR2_U2TIMEOUT(x) (x & 0xFF)
227
228/*
229 * *SS Device Notification Control (DEV_NOTF, offset = 314H)
230 * */
231#define FUSB300_DEVNOTF_CONTEXT0(x) ((x & 0xFFFFFF) << 8)
232#define FUSB300_DEVNOTF_TYPE_DIS 0
233#define FUSB300_DEVNOTF_TYPE_FUNCWAKE 1
234#define FUSB300_DEVNOTF_TYPE_LTM 2
235#define FUSB300_DEVNOTF_TYPE_BUSINT_ADJMSG 3
236
237/*
238 * *BFM Arbiter Priority Register (BFM_ARB offset = 31CH)
239 * */
240#define FUSB300_BFMARB_ARB_M1 (1 << 3)
241#define FUSB300_BFMARB_ARB_M0 (1 << 2)
242#define FUSB300_BFMARB_ARB_S1 (1 << 1)
243#define FUSB300_BFMARB_ARB_S0 1
244
245/*
246 * *Vendor Specific IO Control Register (offset = 320H)
247 * */
248#define FUSB300_VSIC_VCTLOAD_N (1 << 8)
249#define FUSB300_VSIC_VCTL(x) (x & 0x3F)
250
251/*
252 * *SOF Mask Timer (offset = 324H)
253 * */
254#define FUSB300_SOF_MASK_TIMER_HS 0x044c
255#define FUSB300_SOF_MASK_TIMER_FS 0x2710
256
257/*
258 * *Error Flag and Control Status (offset = 328H)
259 * */
260#define FUSB300_EFCS_PM_STATE_U3 3
261#define FUSB300_EFCS_PM_STATE_U2 2
262#define FUSB300_EFCS_PM_STATE_U1 1
263#define FUSB300_EFCS_PM_STATE_U0 0
264
265/*
266 * *Interrupt Group 0 Register (offset = 400H)
267 * */
268#define FUSB300_IGR0_EP15_PRD_INT (1 << 31)
269#define FUSB300_IGR0_EP14_PRD_INT (1 << 30)
270#define FUSB300_IGR0_EP13_PRD_INT (1 << 29)
271#define FUSB300_IGR0_EP12_PRD_INT (1 << 28)
272#define FUSB300_IGR0_EP11_PRD_INT (1 << 27)
273#define FUSB300_IGR0_EP10_PRD_INT (1 << 26)
274#define FUSB300_IGR0_EP9_PRD_INT (1 << 25)
275#define FUSB300_IGR0_EP8_PRD_INT (1 << 24)
276#define FUSB300_IGR0_EP7_PRD_INT (1 << 23)
277#define FUSB300_IGR0_EP6_PRD_INT (1 << 22)
278#define FUSB300_IGR0_EP5_PRD_INT (1 << 21)
279#define FUSB300_IGR0_EP4_PRD_INT (1 << 20)
280#define FUSB300_IGR0_EP3_PRD_INT (1 << 19)
281#define FUSB300_IGR0_EP2_PRD_INT (1 << 18)
282#define FUSB300_IGR0_EP1_PRD_INT (1 << 17)
283#define FUSB300_IGR0_EPn_PRD_INT(n) (1 << (n + 16))
284
285#define FUSB300_IGR0_EP15_FIFO_INT (1 << 15)
286#define FUSB300_IGR0_EP14_FIFO_INT (1 << 14)
287#define FUSB300_IGR0_EP13_FIFO_INT (1 << 13)
288#define FUSB300_IGR0_EP12_FIFO_INT (1 << 12)
289#define FUSB300_IGR0_EP11_FIFO_INT (1 << 11)
290#define FUSB300_IGR0_EP10_FIFO_INT (1 << 10)
291#define FUSB300_IGR0_EP9_FIFO_INT (1 << 9)
292#define FUSB300_IGR0_EP8_FIFO_INT (1 << 8)
293#define FUSB300_IGR0_EP7_FIFO_INT (1 << 7)
294#define FUSB300_IGR0_EP6_FIFO_INT (1 << 6)
295#define FUSB300_IGR0_EP5_FIFO_INT (1 << 5)
296#define FUSB300_IGR0_EP4_FIFO_INT (1 << 4)
297#define FUSB300_IGR0_EP3_FIFO_INT (1 << 3)
298#define FUSB300_IGR0_EP2_FIFO_INT (1 << 2)
299#define FUSB300_IGR0_EP1_FIFO_INT (1 << 1)
300#define FUSB300_IGR0_EPn_FIFO_INT(n) (1 << n)
301
302/*
303 * *Interrupt Group 1 Register (offset = 404H)
304 * */
305#define FUSB300_IGR1_INTGRP5 (1 << 31)
306#define FUSB300_IGR1_VBUS_CHG_INT (1 << 30)
307#define FUSB300_IGR1_SYNF1_EMPTY_INT (1 << 29)
308#define FUSB300_IGR1_SYNF0_EMPTY_INT (1 << 28)
309#define FUSB300_IGR1_U3_EXIT_FAIL_INT (1 << 27)
310#define FUSB300_IGR1_U2_EXIT_FAIL_INT (1 << 26)
311#define FUSB300_IGR1_U1_EXIT_FAIL_INT (1 << 25)
312#define FUSB300_IGR1_U2_ENTRY_FAIL_INT (1 << 24)
313#define FUSB300_IGR1_U1_ENTRY_FAIL_INT (1 << 23)
314#define FUSB300_IGR1_U3_EXIT_INT (1 << 22)
315#define FUSB300_IGR1_U2_EXIT_INT (1 << 21)
316#define FUSB300_IGR1_U1_EXIT_INT (1 << 20)
317#define FUSB300_IGR1_U3_ENTRY_INT (1 << 19)
318#define FUSB300_IGR1_U2_ENTRY_INT (1 << 18)
319#define FUSB300_IGR1_U1_ENTRY_INT (1 << 17)
320#define FUSB300_IGR1_HOT_RST_INT (1 << 16)
321#define FUSB300_IGR1_WARM_RST_INT (1 << 15)
322#define FUSB300_IGR1_RESM_INT (1 << 14)
323#define FUSB300_IGR1_SUSP_INT (1 << 13)
324#define FUSB300_IGR1_HS_LPM_INT (1 << 12)
325#define FUSB300_IGR1_USBRST_INT (1 << 11)
326#define FUSB300_IGR1_DEV_MODE_CHG_INT (1 << 9)
327#define FUSB300_IGR1_CX_COMABT_INT (1 << 8)
328#define FUSB300_IGR1_CX_COMFAIL_INT (1 << 7)
329#define FUSB300_IGR1_CX_CMDEND_INT (1 << 6)
330#define FUSB300_IGR1_CX_OUT_INT (1 << 5)
331#define FUSB300_IGR1_CX_IN_INT (1 << 4)
332#define FUSB300_IGR1_CX_SETUP_INT (1 << 3)
333#define FUSB300_IGR1_INTGRP4 (1 << 2)
334#define FUSB300_IGR1_INTGRP3 (1 << 1)
335#define FUSB300_IGR1_INTGRP2 (1 << 0)
336
337/*
338 * *Interrupt Group 2 Register (offset = 408H)
339 * */
340#define FUSB300_IGR2_EP6_STR_ACCEPT_INT (1 << 29)
341#define FUSB300_IGR2_EP6_STR_RESUME_INT (1 << 28)
342#define FUSB300_IGR2_EP6_STR_REQ_INT (1 << 27)
343#define FUSB300_IGR2_EP6_STR_NOTRDY_INT (1 << 26)
344#define FUSB300_IGR2_EP6_STR_PRIME_INT (1 << 25)
345#define FUSB300_IGR2_EP5_STR_ACCEPT_INT (1 << 24)
346#define FUSB300_IGR2_EP5_STR_RESUME_INT (1 << 23)
347#define FUSB300_IGR2_EP5_STR_REQ_INT (1 << 22)
348#define FUSB300_IGR2_EP5_STR_NOTRDY_INT (1 << 21)
349#define FUSB300_IGR2_EP5_STR_PRIME_INT (1 << 20)
350#define FUSB300_IGR2_EP4_STR_ACCEPT_INT (1 << 19)
351#define FUSB300_IGR2_EP4_STR_RESUME_INT (1 << 18)
352#define FUSB300_IGR2_EP4_STR_REQ_INT (1 << 17)
353#define FUSB300_IGR2_EP4_STR_NOTRDY_INT (1 << 16)
354#define FUSB300_IGR2_EP4_STR_PRIME_INT (1 << 15)
355#define FUSB300_IGR2_EP3_STR_ACCEPT_INT (1 << 14)
356#define FUSB300_IGR2_EP3_STR_RESUME_INT (1 << 13)
357#define FUSB300_IGR2_EP3_STR_REQ_INT (1 << 12)
358#define FUSB300_IGR2_EP3_STR_NOTRDY_INT (1 << 11)
359#define FUSB300_IGR2_EP3_STR_PRIME_INT (1 << 10)
360#define FUSB300_IGR2_EP2_STR_ACCEPT_INT (1 << 9)
361#define FUSB300_IGR2_EP2_STR_RESUME_INT (1 << 8)
362#define FUSB300_IGR2_EP2_STR_REQ_INT (1 << 7)
363#define FUSB300_IGR2_EP2_STR_NOTRDY_INT (1 << 6)
364#define FUSB300_IGR2_EP2_STR_PRIME_INT (1 << 5)
365#define FUSB300_IGR2_EP1_STR_ACCEPT_INT (1 << 4)
366#define FUSB300_IGR2_EP1_STR_RESUME_INT (1 << 3)
367#define FUSB300_IGR2_EP1_STR_REQ_INT (1 << 2)
368#define FUSB300_IGR2_EP1_STR_NOTRDY_INT (1 << 1)
369#define FUSB300_IGR2_EP1_STR_PRIME_INT (1 << 0)
370
371#define FUSB300_IGR2_EP_STR_ACCEPT_INT(n) (1 << (5 * n - 1))
372#define FUSB300_IGR2_EP_STR_RESUME_INT(n) (1 << (5 * n - 2))
373#define FUSB300_IGR2_EP_STR_REQ_INT(n) (1 << (5 * n - 3))
374#define FUSB300_IGR2_EP_STR_NOTRDY_INT(n) (1 << (5 * n - 4))
375#define FUSB300_IGR2_EP_STR_PRIME_INT(n) (1 << (5 * n - 5))
376
377/*
378 * *Interrupt Group 3 Register (offset = 40CH)
379 * */
380#define FUSB300_IGR3_EP12_STR_ACCEPT_INT (1 << 29)
381#define FUSB300_IGR3_EP12_STR_RESUME_INT (1 << 28)
382#define FUSB300_IGR3_EP12_STR_REQ_INT (1 << 27)
383#define FUSB300_IGR3_EP12_STR_NOTRDY_INT (1 << 26)
384#define FUSB300_IGR3_EP12_STR_PRIME_INT (1 << 25)
385#define FUSB300_IGR3_EP11_STR_ACCEPT_INT (1 << 24)
386#define FUSB300_IGR3_EP11_STR_RESUME_INT (1 << 23)
387#define FUSB300_IGR3_EP11_STR_REQ_INT (1 << 22)
388#define FUSB300_IGR3_EP11_STR_NOTRDY_INT (1 << 21)
389#define FUSB300_IGR3_EP11_STR_PRIME_INT (1 << 20)
390#define FUSB300_IGR3_EP10_STR_ACCEPT_INT (1 << 19)
391#define FUSB300_IGR3_EP10_STR_RESUME_INT (1 << 18)
392#define FUSB300_IGR3_EP10_STR_REQ_INT (1 << 17)
393#define FUSB300_IGR3_EP10_STR_NOTRDY_INT (1 << 16)
394#define FUSB300_IGR3_EP10_STR_PRIME_INT (1 << 15)
395#define FUSB300_IGR3_EP9_STR_ACCEPT_INT (1 << 14)
396#define FUSB300_IGR3_EP9_STR_RESUME_INT (1 << 13)
397#define FUSB300_IGR3_EP9_STR_REQ_INT (1 << 12)
398#define FUSB300_IGR3_EP9_STR_NOTRDY_INT (1 << 11)
399#define FUSB300_IGR3_EP9_STR_PRIME_INT (1 << 10)
400#define FUSB300_IGR3_EP8_STR_ACCEPT_INT (1 << 9)
401#define FUSB300_IGR3_EP8_STR_RESUME_INT (1 << 8)
402#define FUSB300_IGR3_EP8_STR_REQ_INT (1 << 7)
403#define FUSB300_IGR3_EP8_STR_NOTRDY_INT (1 << 6)
404#define FUSB300_IGR3_EP8_STR_PRIME_INT (1 << 5)
405#define FUSB300_IGR3_EP7_STR_ACCEPT_INT (1 << 4)
406#define FUSB300_IGR3_EP7_STR_RESUME_INT (1 << 3)
407#define FUSB300_IGR3_EP7_STR_REQ_INT (1 << 2)
408#define FUSB300_IGR3_EP7_STR_NOTRDY_INT (1 << 1)
409#define FUSB300_IGR3_EP7_STR_PRIME_INT (1 << 0)
410
411#define FUSB300_IGR3_EP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1))
412#define FUSB300_IGR3_EP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2))
413#define FUSB300_IGR3_EP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3))
414#define FUSB300_IGR3_EP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4))
415#define FUSB300_IGR3_EP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5))
416
417/*
418 * *Interrupt Group 4 Register (offset = 410H)
419 * */
420#define FUSB300_IGR4_EP15_RX0_INT (1 << 31)
421#define FUSB300_IGR4_EP14_RX0_INT (1 << 30)
422#define FUSB300_IGR4_EP13_RX0_INT (1 << 29)
423#define FUSB300_IGR4_EP12_RX0_INT (1 << 28)
424#define FUSB300_IGR4_EP11_RX0_INT (1 << 27)
425#define FUSB300_IGR4_EP10_RX0_INT (1 << 26)
426#define FUSB300_IGR4_EP9_RX0_INT (1 << 25)
427#define FUSB300_IGR4_EP8_RX0_INT (1 << 24)
428#define FUSB300_IGR4_EP7_RX0_INT (1 << 23)
429#define FUSB300_IGR4_EP6_RX0_INT (1 << 22)
430#define FUSB300_IGR4_EP5_RX0_INT (1 << 21)
431#define FUSB300_IGR4_EP4_RX0_INT (1 << 20)
432#define FUSB300_IGR4_EP3_RX0_INT (1 << 19)
433#define FUSB300_IGR4_EP2_RX0_INT (1 << 18)
434#define FUSB300_IGR4_EP1_RX0_INT (1 << 17)
435#define FUSB300_IGR4_EP_RX0_INT(x) (1 << (x + 16))
436#define FUSB300_IGR4_EP15_STR_ACCEPT_INT (1 << 14)
437#define FUSB300_IGR4_EP15_STR_RESUME_INT (1 << 13)
438#define FUSB300_IGR4_EP15_STR_REQ_INT (1 << 12)
439#define FUSB300_IGR4_EP15_STR_NOTRDY_INT (1 << 11)
440#define FUSB300_IGR4_EP15_STR_PRIME_INT (1 << 10)
441#define FUSB300_IGR4_EP14_STR_ACCEPT_INT (1 << 9)
442#define FUSB300_IGR4_EP14_STR_RESUME_INT (1 << 8)
443#define FUSB300_IGR4_EP14_STR_REQ_INT (1 << 7)
444#define FUSB300_IGR4_EP14_STR_NOTRDY_INT (1 << 6)
445#define FUSB300_IGR4_EP14_STR_PRIME_INT (1 << 5)
446#define FUSB300_IGR4_EP13_STR_ACCEPT_INT (1 << 4)
447#define FUSB300_IGR4_EP13_STR_RESUME_INT (1 << 3)
448#define FUSB300_IGR4_EP13_STR_REQ_INT (1 << 2)
449#define FUSB300_IGR4_EP13_STR_NOTRDY_INT (1 << 1)
450#define FUSB300_IGR4_EP13_STR_PRIME_INT (1 << 0)
451
452#define FUSB300_IGR4_EP_STR_ACCEPT_INT(n) (1 << (5 * (n - 12) - 1))
453#define FUSB300_IGR4_EP_STR_RESUME_INT(n) (1 << (5 * (n - 12) - 2))
454#define FUSB300_IGR4_EP_STR_REQ_INT(n) (1 << (5 * (n - 12) - 3))
455#define FUSB300_IGR4_EP_STR_NOTRDY_INT(n) (1 << (5 * (n - 12) - 4))
456#define FUSB300_IGR4_EP_STR_PRIME_INT(n) (1 << (5 * (n - 12) - 5))
457
458/*
459 * *Interrupt Group 5 Register (offset = 414H)
460 * */
461#define FUSB300_IGR5_EP_STL_INT(n) (1 << n)
462
463/*
464 * *Interrupt Enable Group 0 Register (offset = 420H)
465 * */
466#define FUSB300_IGER0_EEP15_PRD_INT (1 << 31)
467#define FUSB300_IGER0_EEP14_PRD_INT (1 << 30)
468#define FUSB300_IGER0_EEP13_PRD_INT (1 << 29)
469#define FUSB300_IGER0_EEP12_PRD_INT (1 << 28)
470#define FUSB300_IGER0_EEP11_PRD_INT (1 << 27)
471#define FUSB300_IGER0_EEP10_PRD_INT (1 << 26)
472#define FUSB300_IGER0_EEP9_PRD_INT (1 << 25)
473#define FUSB300_IGER0_EP8_PRD_INT (1 << 24)
474#define FUSB300_IGER0_EEP7_PRD_INT (1 << 23)
475#define FUSB300_IGER0_EEP6_PRD_INT (1 << 22)
476#define FUSB300_IGER0_EEP5_PRD_INT (1 << 21)
477#define FUSB300_IGER0_EEP4_PRD_INT (1 << 20)
478#define FUSB300_IGER0_EEP3_PRD_INT (1 << 19)
479#define FUSB300_IGER0_EEP2_PRD_INT (1 << 18)
480#define FUSB300_IGER0_EEP1_PRD_INT (1 << 17)
481#define FUSB300_IGER0_EEPn_PRD_INT(n) (1 << (n + 16))
482
483#define FUSB300_IGER0_EEP15_FIFO_INT (1 << 15)
484#define FUSB300_IGER0_EEP14_FIFO_INT (1 << 14)
485#define FUSB300_IGER0_EEP13_FIFO_INT (1 << 13)
486#define FUSB300_IGER0_EEP12_FIFO_INT (1 << 12)
487#define FUSB300_IGER0_EEP11_FIFO_INT (1 << 11)
488#define FUSB300_IGER0_EEP10_FIFO_INT (1 << 10)
489#define FUSB300_IGER0_EEP9_FIFO_INT (1 << 9)
490#define FUSB300_IGER0_EEP8_FIFO_INT (1 << 8)
491#define FUSB300_IGER0_EEP7_FIFO_INT (1 << 7)
492#define FUSB300_IGER0_EEP6_FIFO_INT (1 << 6)
493#define FUSB300_IGER0_EEP5_FIFO_INT (1 << 5)
494#define FUSB300_IGER0_EEP4_FIFO_INT (1 << 4)
495#define FUSB300_IGER0_EEP3_FIFO_INT (1 << 3)
496#define FUSB300_IGER0_EEP2_FIFO_INT (1 << 2)
497#define FUSB300_IGER0_EEP1_FIFO_INT (1 << 1)
498#define FUSB300_IGER0_EEPn_FIFO_INT(n) (1 << n)
499
500/*
501 * *Interrupt Enable Group 1 Register (offset = 424H)
502 * */
503#define FUSB300_IGER1_EINT_GRP5 (1 << 31)
504#define FUSB300_IGER1_VBUS_CHG_INT (1 << 30)
505#define FUSB300_IGER1_SYNF1_EMPTY_INT (1 << 29)
506#define FUSB300_IGER1_SYNF0_EMPTY_INT (1 << 28)
507#define FUSB300_IGER1_U3_EXIT_FAIL_INT (1 << 27)
508#define FUSB300_IGER1_U2_EXIT_FAIL_INT (1 << 26)
509#define FUSB300_IGER1_U1_EXIT_FAIL_INT (1 << 25)
510#define FUSB300_IGER1_U2_ENTRY_FAIL_INT (1 << 24)
511#define FUSB300_IGER1_U1_ENTRY_FAIL_INT (1 << 23)
512#define FUSB300_IGER1_U3_EXIT_INT (1 << 22)
513#define FUSB300_IGER1_U2_EXIT_INT (1 << 21)
514#define FUSB300_IGER1_U1_EXIT_INT (1 << 20)
515#define FUSB300_IGER1_U3_ENTRY_INT (1 << 19)
516#define FUSB300_IGER1_U2_ENTRY_INT (1 << 18)
517#define FUSB300_IGER1_U1_ENTRY_INT (1 << 17)
518#define FUSB300_IGER1_HOT_RST_INT (1 << 16)
519#define FUSB300_IGER1_WARM_RST_INT (1 << 15)
520#define FUSB300_IGER1_RESM_INT (1 << 14)
521#define FUSB300_IGER1_SUSP_INT (1 << 13)
522#define FUSB300_IGER1_LPM_INT (1 << 12)
523#define FUSB300_IGER1_HS_RST_INT (1 << 11)
524#define FUSB300_IGER1_EDEV_MODE_CHG_INT (1 << 9)
525#define FUSB300_IGER1_CX_COMABT_INT (1 << 8)
526#define FUSB300_IGER1_CX_COMFAIL_INT (1 << 7)
527#define FUSB300_IGER1_CX_CMDEND_INT (1 << 6)
528#define FUSB300_IGER1_CX_OUT_INT (1 << 5)
529#define FUSB300_IGER1_CX_IN_INT (1 << 4)
530#define FUSB300_IGER1_CX_SETUP_INT (1 << 3)
531#define FUSB300_IGER1_INTGRP4 (1 << 2)
532#define FUSB300_IGER1_INTGRP3 (1 << 1)
533#define FUSB300_IGER1_INTGRP2 (1 << 0)
534
535/*
536 * *Interrupt Enable Group 2 Register (offset = 428H)
537 * */
538#define FUSB300_IGER2_EEP_STR_ACCEPT_INT(n) (1 << (5 * n - 1))
539#define FUSB300_IGER2_EEP_STR_RESUME_INT(n) (1 << (5 * n - 2))
540#define FUSB300_IGER2_EEP_STR_REQ_INT(n) (1 << (5 * n - 3))
541#define FUSB300_IGER2_EEP_STR_NOTRDY_INT(n) (1 << (5 * n - 4))
542#define FUSB300_IGER2_EEP_STR_PRIME_INT(n) (1 << (5 * n - 5))
543
544/*
545 * *Interrupt Enable Group 3 Register (offset = 42CH)
546 * */
547
548#define FUSB300_IGER3_EEP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1))
549#define FUSB300_IGER3_EEP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2))
550#define FUSB300_IGER3_EEP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3))
551#define FUSB300_IGER3_EEP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4))
552#define FUSB300_IGER3_EEP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5))
553
554/*
555 * *Interrupt Enable Group 4 Register (offset = 430H)
556 * */
557
558#define FUSB300_IGER4_EEP_RX0_INT(n) (1 << (n + 16))
559#define FUSB300_IGER4_EEP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1))
560#define FUSB300_IGER4_EEP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2))
561#define FUSB300_IGER4_EEP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3))
562#define FUSB300_IGER4_EEP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4))
563#define FUSB300_IGER4_EEP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5))
564
565/* EP PRD Ready (EP_PRD_RDY, offset = 504H) */
566
567#define FUSB300_EPPRDR_EP15_PRD_RDY (1 << 15)
568#define FUSB300_EPPRDR_EP14_PRD_RDY (1 << 14)
569#define FUSB300_EPPRDR_EP13_PRD_RDY (1 << 13)
570#define FUSB300_EPPRDR_EP12_PRD_RDY (1 << 12)
571#define FUSB300_EPPRDR_EP11_PRD_RDY (1 << 11)
572#define FUSB300_EPPRDR_EP10_PRD_RDY (1 << 10)
573#define FUSB300_EPPRDR_EP9_PRD_RDY (1 << 9)
574#define FUSB300_EPPRDR_EP8_PRD_RDY (1 << 8)
575#define FUSB300_EPPRDR_EP7_PRD_RDY (1 << 7)
576#define FUSB300_EPPRDR_EP6_PRD_RDY (1 << 6)
577#define FUSB300_EPPRDR_EP5_PRD_RDY (1 << 5)
578#define FUSB300_EPPRDR_EP4_PRD_RDY (1 << 4)
579#define FUSB300_EPPRDR_EP3_PRD_RDY (1 << 3)
580#define FUSB300_EPPRDR_EP2_PRD_RDY (1 << 2)
581#define FUSB300_EPPRDR_EP1_PRD_RDY (1 << 1)
582#define FUSB300_EPPRDR_EP_PRD_RDY(n) (1 << n)
583
584/* AHB Bus Control Register (offset = 514H) */
585#define FUSB300_AHBBCR_S1_SPLIT_ON (1 << 17)
586#define FUSB300_AHBBCR_S0_SPLIT_ON (1 << 16)
587#define FUSB300_AHBBCR_S1_1entry (0 << 12)
588#define FUSB300_AHBBCR_S1_4entry (3 << 12)
589#define FUSB300_AHBBCR_S1_8entry (5 << 12)
590#define FUSB300_AHBBCR_S1_16entry (7 << 12)
591#define FUSB300_AHBBCR_S0_1entry (0 << 8)
592#define FUSB300_AHBBCR_S0_4entry (3 << 8)
593#define FUSB300_AHBBCR_S0_8entry (5 << 8)
594#define FUSB300_AHBBCR_S0_16entry (7 << 8)
595#define FUSB300_AHBBCR_M1_BURST_SINGLE (0 << 4)
596#define FUSB300_AHBBCR_M1_BURST_INCR (1 << 4)
597#define FUSB300_AHBBCR_M1_BURST_INCR4 (3 << 4)
598#define FUSB300_AHBBCR_M1_BURST_INCR8 (5 << 4)
599#define FUSB300_AHBBCR_M1_BURST_INCR16 (7 << 4)
600#define FUSB300_AHBBCR_M0_BURST_SINGLE 0
601#define FUSB300_AHBBCR_M0_BURST_INCR 1
602#define FUSB300_AHBBCR_M0_BURST_INCR4 3
603#define FUSB300_AHBBCR_M0_BURST_INCR8 5
604#define FUSB300_AHBBCR_M0_BURST_INCR16 7
605#define FUSB300_IGER5_EEP_STL_INT(n) (1 << n)
606
607/* WORD 0 Data Structure of PRD Table */
608#define FUSB300_EPPRD0_M (1 << 30)
609#define FUSB300_EPPRD0_O (1 << 29)
610/* The finished prd */
611#define FUSB300_EPPRD0_F (1 << 28)
612#define FUSB300_EPPRD0_I (1 << 27)
613#define FUSB300_EPPRD0_A (1 << 26)
614/* To decide HW point to first prd at next time */
615#define FUSB300_EPPRD0_L (1 << 25)
616#define FUSB300_EPPRD0_H (1 << 24)
617#define FUSB300_EPPRD0_BTC(n) (n & 0xFFFFFF)
618
619/*----------------------------------------------------------------------*/
620#define FUSB300_MAX_NUM_EP 16
621
622#define FUSB300_FIFO_ENTRY_NUM 8
623#define FUSB300_MAX_FIFO_ENTRY 8
624
625#define SS_CTL_MAX_PACKET_SIZE 0x200
626#define SS_BULK_MAX_PACKET_SIZE 0x400
627#define SS_INT_MAX_PACKET_SIZE 0x400
628#define SS_ISO_MAX_PACKET_SIZE 0x400
629
630#define HS_BULK_MAX_PACKET_SIZE 0x200
631#define HS_CTL_MAX_PACKET_SIZE 0x40
632#define HS_INT_MAX_PACKET_SIZE 0x400
633#define HS_ISO_MAX_PACKET_SIZE 0x400
634
635struct fusb300_ep_info {
636 u8 epnum;
637 u8 type;
638 u8 interval;
639 u8 dir_in;
640 u16 maxpacket;
641 u16 addrofs;
642 u16 bw_num;
643};
644
645struct fusb300_request {
646
647 struct usb_request req;
648 struct list_head queue;
649};
650
651
652struct fusb300_ep {
653 struct usb_ep ep;
654 struct fusb300 *fusb300;
655
656 struct list_head queue;
657 unsigned stall:1;
658 unsigned wedged:1;
659 unsigned use_dma:1;
660
661 unsigned char epnum;
662 unsigned char type;
663 const struct usb_endpoint_descriptor *desc;
664};
665
666struct fusb300 {
667 spinlock_t lock;
668 void __iomem *reg;
669
670 unsigned long irq_trigger;
671
672 struct usb_gadget gadget;
673 struct usb_gadget_driver *driver;
674
675 struct fusb300_ep *ep[FUSB300_MAX_NUM_EP];
676
677 struct usb_request *ep0_req; /* for internal request */
678 __le16 ep0_data;
679 u32 ep0_length; /* for internal request */
680 u8 ep0_dir; /* 0/0x80 out/in */
681
682 u8 fifo_entry_num; /* next start fifo entry */
683 u32 addrofs; /* next fifo address offset */
684 u8 reenum; /* if re-enumeration */
685};
686
687#endif
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index 51b19f3027e7..084aa080a2d5 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -258,7 +258,7 @@ static int pipe_buffer_setting(struct m66592 *m66592,
258 break; 258 break;
259 case M66592_BULK: 259 case M66592_BULK:
260 /* isochronous pipes may be used as bulk pipes */ 260 /* isochronous pipes may be used as bulk pipes */
261 if (info->pipe > M66592_BASE_PIPENUM_BULK) 261 if (info->pipe >= M66592_BASE_PIPENUM_BULK)
262 bufnum = info->pipe - M66592_BASE_PIPENUM_BULK; 262 bufnum = info->pipe - M66592_BASE_PIPENUM_BULK;
263 else 263 else
264 bufnum = info->pipe - M66592_BASE_PIPENUM_ISOC; 264 bufnum = info->pipe - M66592_BASE_PIPENUM_ISOC;
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index b120dbb64d0f..3e4b35e50c24 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -367,7 +367,6 @@ struct pch_udc_dev {
367static const char ep0_string[] = "ep0in"; 367static const char ep0_string[] = "ep0in";
368static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */ 368static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */
369struct pch_udc_dev *pch_udc; /* pointer to device object */ 369struct pch_udc_dev *pch_udc; /* pointer to device object */
370
371static int speed_fs; 370static int speed_fs;
372module_param_named(speed_fs, speed_fs, bool, S_IRUGO); 371module_param_named(speed_fs, speed_fs, bool, S_IRUGO);
373MODULE_PARM_DESC(speed_fs, "true for Full speed operation"); 372MODULE_PARM_DESC(speed_fs, "true for Full speed operation");
@@ -383,6 +382,8 @@ MODULE_PARM_DESC(speed_fs, "true for Full speed operation");
383 * @dma_mapped: DMA memory mapped for request 382 * @dma_mapped: DMA memory mapped for request
384 * @dma_done: DMA completed for request 383 * @dma_done: DMA completed for request
385 * @chain_len: chain length 384 * @chain_len: chain length
385 * @buf: Buffer memory for align adjustment
386 * @dma: DMA memory for align adjustment
386 */ 387 */
387struct pch_udc_request { 388struct pch_udc_request {
388 struct usb_request req; 389 struct usb_request req;
@@ -394,6 +395,8 @@ struct pch_udc_request {
394 dma_mapped:1, 395 dma_mapped:1,
395 dma_done:1; 396 dma_done:1;
396 unsigned chain_len; 397 unsigned chain_len;
398 void *buf;
399 dma_addr_t dma;
397}; 400};
398 401
399static inline u32 pch_udc_readl(struct pch_udc_dev *dev, unsigned long reg) 402static inline u32 pch_udc_readl(struct pch_udc_dev *dev, unsigned long reg)
@@ -615,7 +618,7 @@ static inline void pch_udc_ep_set_trfr_type(struct pch_udc_ep *ep,
615/** 618/**
616 * pch_udc_ep_set_bufsz() - Set the maximum packet size for the endpoint 619 * pch_udc_ep_set_bufsz() - Set the maximum packet size for the endpoint
617 * @ep: Reference to structure of type pch_udc_ep_regs 620 * @ep: Reference to structure of type pch_udc_ep_regs
618 * @buf_size: The buffer size 621 * @buf_size: The buffer word size
619 */ 622 */
620static void pch_udc_ep_set_bufsz(struct pch_udc_ep *ep, 623static void pch_udc_ep_set_bufsz(struct pch_udc_ep *ep,
621 u32 buf_size, u32 ep_in) 624 u32 buf_size, u32 ep_in)
@@ -635,7 +638,7 @@ static void pch_udc_ep_set_bufsz(struct pch_udc_ep *ep,
635/** 638/**
636 * pch_udc_ep_set_maxpkt() - Set the Max packet size for the endpoint 639 * pch_udc_ep_set_maxpkt() - Set the Max packet size for the endpoint
637 * @ep: Reference to structure of type pch_udc_ep_regs 640 * @ep: Reference to structure of type pch_udc_ep_regs
638 * @pkt_size: The packet size 641 * @pkt_size: The packet byte size
639 */ 642 */
640static void pch_udc_ep_set_maxpkt(struct pch_udc_ep *ep, u32 pkt_size) 643static void pch_udc_ep_set_maxpkt(struct pch_udc_ep *ep, u32 pkt_size)
641{ 644{
@@ -920,25 +923,10 @@ static void pch_udc_ep_clear_nak(struct pch_udc_ep *ep)
920 */ 923 */
921static void pch_udc_ep_fifo_flush(struct pch_udc_ep *ep, int dir) 924static void pch_udc_ep_fifo_flush(struct pch_udc_ep *ep, int dir)
922{ 925{
923 unsigned int loopcnt = 0;
924 struct pch_udc_dev *dev = ep->dev;
925
926 if (dir) { /* IN ep */ 926 if (dir) { /* IN ep */
927 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_F); 927 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_F);
928 return; 928 return;
929 } 929 }
930
931 if (pch_udc_read_ep_status(ep) & UDC_EPSTS_MRXFIFO_EMP)
932 return;
933 pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_MRXFLUSH);
934 /* Wait for RxFIFO Empty */
935 loopcnt = 10000;
936 while (!(pch_udc_read_ep_status(ep) & UDC_EPSTS_MRXFIFO_EMP) &&
937 --loopcnt)
938 udelay(5);
939 if (!loopcnt)
940 dev_err(&dev->pdev->dev, "RxFIFO not Empty\n");
941 pch_udc_ep_bit_clr(ep, UDC_EPCTL_ADDR, UDC_EPCTL_MRXFLUSH);
942} 930}
943 931
944/** 932/**
@@ -1220,14 +1208,31 @@ static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req,
1220 1208
1221 dev = ep->dev; 1209 dev = ep->dev;
1222 if (req->dma_mapped) { 1210 if (req->dma_mapped) {
1223 if (ep->in) 1211 if (req->dma == DMA_ADDR_INVALID) {
1224 dma_unmap_single(&dev->pdev->dev, req->req.dma, 1212 if (ep->in)
1225 req->req.length, DMA_TO_DEVICE); 1213 dma_unmap_single(&dev->pdev->dev, req->req.dma,
1226 else 1214 req->req.length,
1227 dma_unmap_single(&dev->pdev->dev, req->req.dma, 1215 DMA_TO_DEVICE);
1228 req->req.length, DMA_FROM_DEVICE); 1216 else
1217 dma_unmap_single(&dev->pdev->dev, req->req.dma,
1218 req->req.length,
1219 DMA_FROM_DEVICE);
1220 req->req.dma = DMA_ADDR_INVALID;
1221 } else {
1222 if (ep->in)
1223 dma_unmap_single(&dev->pdev->dev, req->dma,
1224 req->req.length,
1225 DMA_TO_DEVICE);
1226 else {
1227 dma_unmap_single(&dev->pdev->dev, req->dma,
1228 req->req.length,
1229 DMA_FROM_DEVICE);
1230 memcpy(req->req.buf, req->buf, req->req.length);
1231 }
1232 kfree(req->buf);
1233 req->dma = DMA_ADDR_INVALID;
1234 }
1229 req->dma_mapped = 0; 1235 req->dma_mapped = 0;
1230 req->req.dma = DMA_ADDR_INVALID;
1231 } 1236 }
1232 ep->halted = 1; 1237 ep->halted = 1;
1233 spin_unlock(&dev->lock); 1238 spin_unlock(&dev->lock);
@@ -1268,12 +1273,18 @@ static void pch_udc_free_dma_chain(struct pch_udc_dev *dev,
1268 struct pch_udc_data_dma_desc *td = req->td_data; 1273 struct pch_udc_data_dma_desc *td = req->td_data;
1269 unsigned i = req->chain_len; 1274 unsigned i = req->chain_len;
1270 1275
1276 dma_addr_t addr2;
1277 dma_addr_t addr = (dma_addr_t)td->next;
1278 td->next = 0x00;
1271 for (; i > 1; --i) { 1279 for (; i > 1; --i) {
1272 dma_addr_t addr = (dma_addr_t)td->next;
1273 /* do not free first desc., will be done by free for request */ 1280 /* do not free first desc., will be done by free for request */
1274 td = phys_to_virt(addr); 1281 td = phys_to_virt(addr);
1282 addr2 = (dma_addr_t)td->next;
1275 pci_pool_free(dev->data_requests, td, addr); 1283 pci_pool_free(dev->data_requests, td, addr);
1284 td->next = 0x00;
1285 addr = addr2;
1276 } 1286 }
1287 req->chain_len = 1;
1277} 1288}
1278 1289
1279/** 1290/**
@@ -1301,23 +1312,23 @@ static int pch_udc_create_dma_chain(struct pch_udc_ep *ep,
1301 if (req->chain_len > 1) 1312 if (req->chain_len > 1)
1302 pch_udc_free_dma_chain(ep->dev, req); 1313 pch_udc_free_dma_chain(ep->dev, req);
1303 1314
1304 for (; ; bytes -= buf_len, ++len) { 1315 if (req->dma == DMA_ADDR_INVALID)
1305 if (ep->in) 1316 td->dataptr = req->req.dma;
1306 td->status = PCH_UDC_BS_HST_BSY | min(buf_len, bytes); 1317 else
1307 else 1318 td->dataptr = req->dma;
1308 td->status = PCH_UDC_BS_HST_BSY;
1309 1319
1320 td->status = PCH_UDC_BS_HST_BSY;
1321 for (; ; bytes -= buf_len, ++len) {
1322 td->status = PCH_UDC_BS_HST_BSY | min(buf_len, bytes);
1310 if (bytes <= buf_len) 1323 if (bytes <= buf_len)
1311 break; 1324 break;
1312
1313 last = td; 1325 last = td;
1314 td = pci_pool_alloc(ep->dev->data_requests, gfp_flags, 1326 td = pci_pool_alloc(ep->dev->data_requests, gfp_flags,
1315 &dma_addr); 1327 &dma_addr);
1316 if (!td) 1328 if (!td)
1317 goto nomem; 1329 goto nomem;
1318
1319 i += buf_len; 1330 i += buf_len;
1320 td->dataptr = req->req.dma + i; 1331 td->dataptr = req->td_data->dataptr + i;
1321 last->next = dma_addr; 1332 last->next = dma_addr;
1322 } 1333 }
1323 1334
@@ -1352,28 +1363,15 @@ static int prepare_dma(struct pch_udc_ep *ep, struct pch_udc_request *req,
1352{ 1363{
1353 int retval; 1364 int retval;
1354 1365
1355 req->td_data->dataptr = req->req.dma;
1356 req->td_data->status |= PCH_UDC_DMA_LAST;
1357 /* Allocate and create a DMA chain */ 1366 /* Allocate and create a DMA chain */
1358 retval = pch_udc_create_dma_chain(ep, req, ep->ep.maxpacket, gfp); 1367 retval = pch_udc_create_dma_chain(ep, req, ep->ep.maxpacket, gfp);
1359 if (retval) { 1368 if (retval) {
1360 pr_err("%s: could not create DMA chain: %d\n", 1369 pr_err("%s: could not create DMA chain:%d\n", __func__, retval);
1361 __func__, retval);
1362 return retval; 1370 return retval;
1363 } 1371 }
1364 if (!ep->in) 1372 if (ep->in)
1365 return 0;
1366 if (req->req.length <= ep->ep.maxpacket)
1367 req->td_data->status = PCH_UDC_DMA_LAST | PCH_UDC_BS_HST_BSY |
1368 req->req.length;
1369 /* if bytes < max packet then tx bytes must
1370 * be written in packet per buffer mode
1371 */
1372 if ((req->req.length < ep->ep.maxpacket) || !ep->num)
1373 req->td_data->status = (req->td_data->status & 1373 req->td_data->status = (req->td_data->status &
1374 ~PCH_UDC_RXTX_BYTES) | req->req.length; 1374 ~PCH_UDC_BUFF_STS) | PCH_UDC_BS_HST_RDY;
1375 req->td_data->status = (req->td_data->status &
1376 ~PCH_UDC_BUFF_STS) | PCH_UDC_BS_HST_BSY;
1377 return 0; 1375 return 0;
1378} 1376}
1379 1377
@@ -1529,6 +1527,7 @@ static struct usb_request *pch_udc_alloc_request(struct usb_ep *usbep,
1529 if (!req) 1527 if (!req)
1530 return NULL; 1528 return NULL;
1531 req->req.dma = DMA_ADDR_INVALID; 1529 req->req.dma = DMA_ADDR_INVALID;
1530 req->dma = DMA_ADDR_INVALID;
1532 INIT_LIST_HEAD(&req->queue); 1531 INIT_LIST_HEAD(&req->queue);
1533 if (!ep->dev->dma_addr) 1532 if (!ep->dev->dma_addr)
1534 return &req->req; 1533 return &req->req;
@@ -1613,16 +1612,33 @@ static int pch_udc_pcd_queue(struct usb_ep *usbep, struct usb_request *usbreq,
1613 /* map the buffer for dma */ 1612 /* map the buffer for dma */
1614 if (usbreq->length && 1613 if (usbreq->length &&
1615 ((usbreq->dma == DMA_ADDR_INVALID) || !usbreq->dma)) { 1614 ((usbreq->dma == DMA_ADDR_INVALID) || !usbreq->dma)) {
1616 if (ep->in) 1615 if (!((unsigned long)(usbreq->buf) & 0x03)) {
1617 usbreq->dma = dma_map_single(&dev->pdev->dev, 1616 if (ep->in)
1618 usbreq->buf, 1617 usbreq->dma = dma_map_single(&dev->pdev->dev,
1619 usbreq->length, 1618 usbreq->buf,
1620 DMA_TO_DEVICE); 1619 usbreq->length,
1621 else 1620 DMA_TO_DEVICE);
1622 usbreq->dma = dma_map_single(&dev->pdev->dev, 1621 else
1623 usbreq->buf, 1622 usbreq->dma = dma_map_single(&dev->pdev->dev,
1624 usbreq->length, 1623 usbreq->buf,
1625 DMA_FROM_DEVICE); 1624 usbreq->length,
1625 DMA_FROM_DEVICE);
1626 } else {
1627 req->buf = kzalloc(usbreq->length, GFP_ATOMIC);
1628 if (!req->buf)
1629 return -ENOMEM;
1630 if (ep->in) {
1631 memcpy(req->buf, usbreq->buf, usbreq->length);
1632 req->dma = dma_map_single(&dev->pdev->dev,
1633 req->buf,
1634 usbreq->length,
1635 DMA_TO_DEVICE);
1636 } else
1637 req->dma = dma_map_single(&dev->pdev->dev,
1638 req->buf,
1639 usbreq->length,
1640 DMA_FROM_DEVICE);
1641 }
1626 req->dma_mapped = 1; 1642 req->dma_mapped = 1;
1627 } 1643 }
1628 if (usbreq->length > 0) { 1644 if (usbreq->length > 0) {
@@ -1920,32 +1936,46 @@ static void pch_udc_complete_receiver(struct pch_udc_ep *ep)
1920 struct pch_udc_request *req; 1936 struct pch_udc_request *req;
1921 struct pch_udc_dev *dev = ep->dev; 1937 struct pch_udc_dev *dev = ep->dev;
1922 unsigned int count; 1938 unsigned int count;
1939 struct pch_udc_data_dma_desc *td;
1940 dma_addr_t addr;
1923 1941
1924 if (list_empty(&ep->queue)) 1942 if (list_empty(&ep->queue))
1925 return; 1943 return;
1926
1927 /* next request */ 1944 /* next request */
1928 req = list_entry(ep->queue.next, struct pch_udc_request, queue); 1945 req = list_entry(ep->queue.next, struct pch_udc_request, queue);
1929 if ((req->td_data_last->status & PCH_UDC_BUFF_STS) !=
1930 PCH_UDC_BS_DMA_DONE)
1931 return;
1932 pch_udc_clear_dma(ep->dev, DMA_DIR_RX); 1946 pch_udc_clear_dma(ep->dev, DMA_DIR_RX);
1933 pch_udc_ep_set_ddptr(ep, 0); 1947 pch_udc_ep_set_ddptr(ep, 0);
1934 if ((req->td_data_last->status & PCH_UDC_RXTX_STS) != 1948 if ((req->td_data_last->status & PCH_UDC_BUFF_STS) ==
1935 PCH_UDC_RTS_SUCC) { 1949 PCH_UDC_BS_DMA_DONE)
1936 dev_err(&dev->pdev->dev, "Invalid RXTX status (0x%08x) " 1950 td = req->td_data_last;
1937 "epstatus=0x%08x\n", 1951 else
1938 (req->td_data_last->status & PCH_UDC_RXTX_STS), 1952 td = req->td_data;
1939 (int)(ep->epsts));
1940 return;
1941 }
1942 count = req->td_data_last->status & PCH_UDC_RXTX_BYTES;
1943 1953
1954 while (1) {
1955 if ((td->status & PCH_UDC_RXTX_STS) != PCH_UDC_RTS_SUCC) {
1956 dev_err(&dev->pdev->dev, "Invalid RXTX status=0x%08x "
1957 "epstatus=0x%08x\n",
1958 (req->td_data->status & PCH_UDC_RXTX_STS),
1959 (int)(ep->epsts));
1960 return;
1961 }
1962 if ((td->status & PCH_UDC_BUFF_STS) == PCH_UDC_BS_DMA_DONE)
1963 if (td->status | PCH_UDC_DMA_LAST) {
1964 count = td->status & PCH_UDC_RXTX_BYTES;
1965 break;
1966 }
1967 if (td == req->td_data_last) {
1968 dev_err(&dev->pdev->dev, "Not complete RX descriptor");
1969 return;
1970 }
1971 addr = (dma_addr_t)td->next;
1972 td = phys_to_virt(addr);
1973 }
1944 /* on 64k packets the RXBYTES field is zero */ 1974 /* on 64k packets the RXBYTES field is zero */
1945 if (!count && (req->req.length == UDC_DMA_MAXPACKET)) 1975 if (!count && (req->req.length == UDC_DMA_MAXPACKET))
1946 count = UDC_DMA_MAXPACKET; 1976 count = UDC_DMA_MAXPACKET;
1947 req->td_data->status |= PCH_UDC_DMA_LAST; 1977 req->td_data->status |= PCH_UDC_DMA_LAST;
1948 req->td_data_last->status |= PCH_UDC_BS_HST_BSY; 1978 td->status |= PCH_UDC_BS_HST_BSY;
1949 1979
1950 req->dma_going = 0; 1980 req->dma_going = 0;
1951 req->req.actual = count; 1981 req->req.actual = count;
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index c2448950a8d8..6d8b04061d5d 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -902,7 +902,7 @@ static irqreturn_t s3c2410_udc_irq(int dummy, void *_dev)
902 int pwr_reg; 902 int pwr_reg;
903 int ep0csr; 903 int ep0csr;
904 int i; 904 int i;
905 u32 idx; 905 u32 idx, idx2;
906 unsigned long flags; 906 unsigned long flags;
907 907
908 spin_lock_irqsave(&dev->lock, flags); 908 spin_lock_irqsave(&dev->lock, flags);
@@ -1017,6 +1017,20 @@ static irqreturn_t s3c2410_udc_irq(int dummy, void *_dev)
1017 } 1017 }
1018 } 1018 }
1019 1019
1020 /* what else causes this interrupt? a receive! who is it? */
1021 if (!usb_status && !usbd_status && !pwr_reg && !ep0csr) {
1022 for (i = 1; i < S3C2410_ENDPOINTS; i++) {
1023 idx2 = udc_read(S3C2410_UDC_INDEX_REG);
1024 udc_write(i, S3C2410_UDC_INDEX_REG);
1025
1026 if (udc_read(S3C2410_UDC_OUT_CSR1_REG) & 0x1)
1027 s3c2410_udc_handle_ep(&dev->ep[i]);
1028
1029 /* restore index */
1030 udc_write(idx2, S3C2410_UDC_INDEX_REG);
1031 }
1032 }
1033
1020 dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", IRQ_USBD); 1034 dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", IRQ_USBD);
1021 1035
1022 /* Restore old index */ 1036 /* Restore old index */
@@ -1467,7 +1481,9 @@ static int s3c2410_udc_set_pullup(struct s3c2410_udc *udc, int is_on)
1467{ 1481{
1468 dprintk(DEBUG_NORMAL, "%s()\n", __func__); 1482 dprintk(DEBUG_NORMAL, "%s()\n", __func__);
1469 1483
1470 if (udc_info && udc_info->udc_command) { 1484 if (udc_info && (udc_info->udc_command ||
1485 gpio_is_valid(udc_info->pullup_pin))) {
1486
1471 if (is_on) 1487 if (is_on)
1472 s3c2410_udc_enable(udc); 1488 s3c2410_udc_enable(udc);
1473 else { 1489 else {
@@ -1544,6 +1560,32 @@ static const struct usb_gadget_ops s3c2410_ops = {
1544 .vbus_draw = s3c2410_vbus_draw, 1560 .vbus_draw = s3c2410_vbus_draw,
1545}; 1561};
1546 1562
1563static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd)
1564{
1565 if (!udc_info)
1566 return;
1567
1568 if (udc_info->udc_command) {
1569 udc_info->udc_command(S3C2410_UDC_P_DISABLE);
1570 } else if (gpio_is_valid(udc_info->pullup_pin)) {
1571 int value;
1572
1573 switch (cmd) {
1574 case S3C2410_UDC_P_ENABLE:
1575 value = 1;
1576 break;
1577 case S3C2410_UDC_P_DISABLE:
1578 value = 0;
1579 break;
1580 default:
1581 return;
1582 }
1583 value ^= udc_info->pullup_pin_inverted;
1584
1585 gpio_set_value(udc_info->pullup_pin, value);
1586 }
1587}
1588
1547/*------------------------- gadget driver handling---------------------------*/ 1589/*------------------------- gadget driver handling---------------------------*/
1548/* 1590/*
1549 * s3c2410_udc_disable 1591 * s3c2410_udc_disable
@@ -1565,8 +1607,7 @@ static void s3c2410_udc_disable(struct s3c2410_udc *dev)
1565 udc_write(0x1F, S3C2410_UDC_EP_INT_REG); 1607 udc_write(0x1F, S3C2410_UDC_EP_INT_REG);
1566 1608
1567 /* Good bye, cruel world */ 1609 /* Good bye, cruel world */
1568 if (udc_info && udc_info->udc_command) 1610 s3c2410_udc_command(S3C2410_UDC_P_DISABLE);
1569 udc_info->udc_command(S3C2410_UDC_P_DISABLE);
1570 1611
1571 /* Set speed to unknown */ 1612 /* Set speed to unknown */
1572 dev->gadget.speed = USB_SPEED_UNKNOWN; 1613 dev->gadget.speed = USB_SPEED_UNKNOWN;
@@ -1627,8 +1668,7 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev)
1627 udc_write(S3C2410_UDC_INT_EP0, S3C2410_UDC_EP_INT_EN_REG); 1668 udc_write(S3C2410_UDC_INT_EP0, S3C2410_UDC_EP_INT_EN_REG);
1628 1669
1629 /* time to say "hello, world" */ 1670 /* time to say "hello, world" */
1630 if (udc_info && udc_info->udc_command) 1671 s3c2410_udc_command(S3C2410_UDC_P_ENABLE);
1631 udc_info->udc_command(S3C2410_UDC_P_ENABLE);
1632} 1672}
1633 1673
1634/* 1674/*
@@ -1903,6 +1943,17 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1903 udc->vbus = 1; 1943 udc->vbus = 1;
1904 } 1944 }
1905 1945
1946 if (udc_info && !udc_info->udc_command &&
1947 gpio_is_valid(udc_info->pullup_pin)) {
1948
1949 retval = gpio_request_one(udc_info->pullup_pin,
1950 udc_info->vbus_pin_inverted ?
1951 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
1952 "udc pullup");
1953 if (retval)
1954 goto err_vbus_irq;
1955 }
1956
1906 if (s3c2410_udc_debugfs_root) { 1957 if (s3c2410_udc_debugfs_root) {
1907 udc->regs_info = debugfs_create_file("registers", S_IRUGO, 1958 udc->regs_info = debugfs_create_file("registers", S_IRUGO,
1908 s3c2410_udc_debugfs_root, 1959 s3c2410_udc_debugfs_root,
@@ -1915,6 +1966,9 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1915 1966
1916 return 0; 1967 return 0;
1917 1968
1969err_vbus_irq:
1970 if (udc_info && udc_info->vbus_pin > 0)
1971 free_irq(gpio_to_irq(udc_info->vbus_pin), udc);
1918err_gpio_claim: 1972err_gpio_claim:
1919 if (udc_info && udc_info->vbus_pin > 0) 1973 if (udc_info && udc_info->vbus_pin > 0)
1920 gpio_free(udc_info->vbus_pin); 1974 gpio_free(udc_info->vbus_pin);
@@ -1942,6 +1996,10 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
1942 1996
1943 debugfs_remove(udc->regs_info); 1997 debugfs_remove(udc->regs_info);
1944 1998
1999 if (udc_info && !udc_info->udc_command &&
2000 gpio_is_valid(udc_info->pullup_pin))
2001 gpio_free(udc_info->pullup_pin);
2002
1945 if (udc_info && udc_info->vbus_pin > 0) { 2003 if (udc_info && udc_info->vbus_pin > 0) {
1946 irq = gpio_to_irq(udc_info->vbus_pin); 2004 irq = gpio_to_irq(udc_info->vbus_pin);
1947 free_irq(irq, udc); 2005 free_irq(irq, udc);
@@ -1973,16 +2031,14 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
1973#ifdef CONFIG_PM 2031#ifdef CONFIG_PM
1974static int s3c2410_udc_suspend(struct platform_device *pdev, pm_message_t message) 2032static int s3c2410_udc_suspend(struct platform_device *pdev, pm_message_t message)
1975{ 2033{
1976 if (udc_info && udc_info->udc_command) 2034 s3c2410_udc_command(S3C2410_UDC_P_DISABLE);
1977 udc_info->udc_command(S3C2410_UDC_P_DISABLE);
1978 2035
1979 return 0; 2036 return 0;
1980} 2037}
1981 2038
1982static int s3c2410_udc_resume(struct platform_device *pdev) 2039static int s3c2410_udc_resume(struct platform_device *pdev)
1983{ 2040{
1984 if (udc_info && udc_info->udc_command) 2041 s3c2410_udc_command(S3C2410_UDC_P_ENABLE);
1985 udc_info->udc_command(S3C2410_UDC_P_ENABLE);
1986 2042
1987 return 0; 2043 return 0;
1988} 2044}
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 1eda968b5644..2ac1d2147325 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -241,7 +241,7 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
241 size -= size % out->maxpacket; 241 size -= size % out->maxpacket;
242 242
243 if (dev->port_usb->is_fixed) 243 if (dev->port_usb->is_fixed)
244 size = max(size, dev->port_usb->fixed_out_len); 244 size = max_t(size_t, size, dev->port_usb->fixed_out_len);
245 245
246 skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags); 246 skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags);
247 if (skb == NULL) { 247 if (skb == NULL) {
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 0e6afa260ed8..9483acdf2e9e 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -91,17 +91,28 @@ config USB_EHCI_TT_NEWSCHED
91 91
92 If unsure, say Y. 92 If unsure, say Y.
93 93
94config USB_EHCI_HCD_PMC_MSP
95 tristate "EHCI support for on-chip PMC MSP71xx USB controller"
96 depends on USB_EHCI_HCD && MSP_HAS_USB
97 default n
98 select USB_EHCI_BIG_ENDIAN_DESC
99 select USB_EHCI_BIG_ENDIAN_MMIO
100 ---help---
101 Enables support for the onchip USB controller on the PMC_MSP7100 Family SoC's.
102 If unsure, say N.
103
94config USB_EHCI_BIG_ENDIAN_MMIO 104config USB_EHCI_BIG_ENDIAN_MMIO
95 bool 105 bool
96 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \ 106 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \
97 ARCH_IXP4XX || XPS_USB_HCD_XILINX || \ 107 ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
98 PPC_MPC512x || CPU_CAVIUM_OCTEON) 108 PPC_MPC512x || CPU_CAVIUM_OCTEON || \
109 PMC_MSP)
99 default y 110 default y
100 111
101config USB_EHCI_BIG_ENDIAN_DESC 112config USB_EHCI_BIG_ENDIAN_DESC
102 bool 113 bool
103 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX || \ 114 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
104 PPC_MPC512x) 115 PPC_MPC512x || PMC_MSP)
105 default y 116 default y
106 117
107config XPS_USB_HCD_XILINX 118config XPS_USB_HCD_XILINX
@@ -145,7 +156,7 @@ config USB_EHCI_MSM
145 bool "Support for MSM on-chip EHCI USB controller" 156 bool "Support for MSM on-chip EHCI USB controller"
146 depends on USB_EHCI_HCD && ARCH_MSM 157 depends on USB_EHCI_HCD && ARCH_MSM
147 select USB_EHCI_ROOT_HUB_TT 158 select USB_EHCI_ROOT_HUB_TT
148 select USB_MSM_OTG_72K 159 select USB_MSM_OTG
149 ---help--- 160 ---help---
150 Enables support for the USB Host controller present on the 161 Enables support for the USB Host controller present on the
151 Qualcomm chipsets. Root Hub has inbuilt TT. 162 Qualcomm chipsets. Root Hub has inbuilt TT.
@@ -154,6 +165,14 @@ config USB_EHCI_MSM
154 This driver is not supported on boards like trout which 165 This driver is not supported on boards like trout which
155 has an external PHY. 166 has an external PHY.
156 167
168config USB_EHCI_TEGRA
169 boolean "NVIDIA Tegra HCD support"
170 depends on USB_EHCI_HCD && ARCH_TEGRA
171 select USB_EHCI_ROOT_HUB_TT
172 help
173 This driver enables support for the internal USB Host Controllers
174 found in NVIDIA Tegra SoCs. The controllers are EHCI compliant.
175
157config USB_EHCI_HCD_PPC_OF 176config USB_EHCI_HCD_PPC_OF
158 bool "EHCI support for PPC USB controller on OF platform bus" 177 bool "EHCI support for PPC USB controller on OF platform bus"
159 depends on USB_EHCI_HCD && PPC_OF 178 depends on USB_EHCI_HCD && PPC_OF
@@ -162,6 +181,13 @@ config USB_EHCI_HCD_PPC_OF
162 Enables support for the USB controller present on the PowerPC 181 Enables support for the USB controller present on the PowerPC
163 OpenFirmware platform bus. 182 OpenFirmware platform bus.
164 183
184config USB_EHCI_SH
185 bool "EHCI support for SuperH USB controller"
186 depends on USB_EHCI_HCD && SUPERH
187 ---help---
188 Enables support for the on-chip EHCI controller on the SuperH.
189 If you use the PCI EHCI controller, this option is not necessary.
190
165config USB_W90X900_EHCI 191config USB_W90X900_EHCI
166 bool "W90X900(W90P910) EHCI support" 192 bool "W90X900(W90P910) EHCI support"
167 depends on USB_EHCI_HCD && ARCH_W90X900 193 depends on USB_EHCI_HCD && ARCH_W90X900
@@ -315,6 +341,13 @@ config USB_OHCI_HCD_SSB
315 341
316 If unsure, say N. 342 If unsure, say N.
317 343
344config USB_OHCI_SH
345 bool "OHCI support for SuperH USB controller"
346 depends on USB_OHCI_HCD && SUPERH
347 ---help---
348 Enables support for the on-chip OHCI controller on the SuperH.
349 If you use the PCI OHCI controller, this option is not necessary.
350
318config USB_CNS3XXX_OHCI 351config USB_CNS3XXX_OHCI
319 bool "Cavium CNS3XXX OHCI Module" 352 bool "Cavium CNS3XXX OHCI Module"
320 depends on USB_OHCI_HCD && ARCH_CNS3XXX 353 depends on USB_OHCI_HCD && ARCH_CNS3XXX
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index d6a69d514a84..b2ed55cb811d 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -115,7 +115,7 @@ static const struct hc_driver ehci_atmel_hc_driver = {
115 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 115 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
116}; 116};
117 117
118static int __init ehci_atmel_drv_probe(struct platform_device *pdev) 118static int __devinit ehci_atmel_drv_probe(struct platform_device *pdev)
119{ 119{
120 struct usb_hcd *hcd; 120 struct usb_hcd *hcd;
121 const struct hc_driver *driver = &ehci_atmel_hc_driver; 121 const struct hc_driver *driver = &ehci_atmel_hc_driver;
@@ -207,7 +207,7 @@ fail_create_hcd:
207 return retval; 207 return retval;
208} 208}
209 209
210static int __exit ehci_atmel_drv_remove(struct platform_device *pdev) 210static int __devexit ehci_atmel_drv_remove(struct platform_device *pdev)
211{ 211{
212 struct usb_hcd *hcd = platform_get_drvdata(pdev); 212 struct usb_hcd *hcd = platform_get_drvdata(pdev);
213 213
@@ -227,7 +227,7 @@ static int __exit ehci_atmel_drv_remove(struct platform_device *pdev)
227 227
228static struct platform_driver ehci_atmel_driver = { 228static struct platform_driver ehci_atmel_driver = {
229 .probe = ehci_atmel_drv_probe, 229 .probe = ehci_atmel_drv_probe,
230 .remove = __exit_p(ehci_atmel_drv_remove), 230 .remove = __devexit_p(ehci_atmel_drv_remove),
231 .shutdown = usb_hcd_platform_shutdown, 231 .shutdown = usb_hcd_platform_shutdown,
232 .driver.name = "atmel-ehci", 232 .driver.name = "atmel-ehci",
233}; 233};
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 3be238a24cc5..693c29b30521 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -28,11 +28,9 @@
28 dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args ) 28 dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
29 29
30#ifdef VERBOSE_DEBUG 30#ifdef VERBOSE_DEBUG
31# define vdbg dbg
32# define ehci_vdbg ehci_dbg 31# define ehci_vdbg ehci_dbg
33#else 32#else
34# define vdbg(fmt,args...) do { } while (0) 33 static inline void ehci_vdbg(struct ehci_hcd *ehci, ...) {}
35# define ehci_vdbg(ehci, fmt, args...) do { } while (0)
36#endif 34#endif
37 35
38#ifdef DEBUG 36#ifdef DEBUG
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 74dcf49bd015..d30c4e08c137 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -114,13 +114,11 @@ MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n");
114 114
115#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) 115#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
116 116
117/* for ASPM quirk of ISOC on AMD SB800 */
118static struct pci_dev *amd_nb_dev;
119
120/*-------------------------------------------------------------------------*/ 117/*-------------------------------------------------------------------------*/
121 118
122#include "ehci.h" 119#include "ehci.h"
123#include "ehci-dbg.c" 120#include "ehci-dbg.c"
121#include "pci-quirks.h"
124 122
125/*-------------------------------------------------------------------------*/ 123/*-------------------------------------------------------------------------*/
126 124
@@ -532,10 +530,8 @@ static void ehci_stop (struct usb_hcd *hcd)
532 spin_unlock_irq (&ehci->lock); 530 spin_unlock_irq (&ehci->lock);
533 ehci_mem_cleanup (ehci); 531 ehci_mem_cleanup (ehci);
534 532
535 if (amd_nb_dev) { 533 if (ehci->amd_pll_fix == 1)
536 pci_dev_put(amd_nb_dev); 534 usb_amd_dev_put();
537 amd_nb_dev = NULL;
538 }
539 535
540#ifdef EHCI_STATS 536#ifdef EHCI_STATS
541 ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n", 537 ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
@@ -679,7 +675,12 @@ static int ehci_run (struct usb_hcd *hcd)
679 hcd->uses_new_polling = 1; 675 hcd->uses_new_polling = 1;
680 676
681 /* EHCI spec section 4.1 */ 677 /* EHCI spec section 4.1 */
682 if ((retval = ehci_reset(ehci)) != 0) { 678 /*
679 * TDI driver does the ehci_reset in their reset callback.
680 * Don't reset here, because configuration settings will
681 * vanish.
682 */
683 if (!ehci_is_TDI(ehci) && (retval = ehci_reset(ehci)) != 0) {
683 ehci_mem_cleanup(ehci); 684 ehci_mem_cleanup(ehci);
684 return retval; 685 return retval;
685 } 686 }
@@ -1179,7 +1180,7 @@ MODULE_LICENSE ("GPL");
1179#define PLATFORM_DRIVER ehci_mxc_driver 1180#define PLATFORM_DRIVER ehci_mxc_driver
1180#endif 1181#endif
1181 1182
1182#ifdef CONFIG_CPU_SUBTYPE_SH7786 1183#ifdef CONFIG_USB_EHCI_SH
1183#include "ehci-sh.c" 1184#include "ehci-sh.c"
1184#define PLATFORM_DRIVER ehci_hcd_sh_driver 1185#define PLATFORM_DRIVER ehci_hcd_sh_driver
1185#endif 1186#endif
@@ -1254,6 +1255,16 @@ MODULE_LICENSE ("GPL");
1254#define PLATFORM_DRIVER ehci_msm_driver 1255#define PLATFORM_DRIVER ehci_msm_driver
1255#endif 1256#endif
1256 1257
1258#ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
1259#include "ehci-pmcmsp.c"
1260#define PLATFORM_DRIVER ehci_hcd_msp_driver
1261#endif
1262
1263#ifdef CONFIG_USB_EHCI_TEGRA
1264#include "ehci-tegra.c"
1265#define PLATFORM_DRIVER tegra_ehci_driver
1266#endif
1267
1257#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ 1268#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
1258 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ 1269 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
1259 !defined(XILINX_OF_PLATFORM_DRIVER) 1270 !defined(XILINX_OF_PLATFORM_DRIVER)
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 8a515f0d5988..d05ea03cfb4d 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -106,6 +106,27 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
106 ehci->owned_ports = 0; 106 ehci->owned_ports = 0;
107} 107}
108 108
109static int ehci_port_change(struct ehci_hcd *ehci)
110{
111 int i = HCS_N_PORTS(ehci->hcs_params);
112
113 /* First check if the controller indicates a change event */
114
115 if (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)
116 return 1;
117
118 /*
119 * Not all controllers appear to update this while going from D3 to D0,
120 * so check the individual port status registers as well
121 */
122
123 while (i--)
124 if (ehci_readl(ehci, &ehci->regs->port_status[i]) & PORT_CSC)
125 return 1;
126
127 return 0;
128}
129
109static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 130static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
110 bool suspending, bool do_wakeup) 131 bool suspending, bool do_wakeup)
111{ 132{
@@ -173,7 +194,7 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
173 } 194 }
174 195
175 /* Does the root hub have a port wakeup pending? */ 196 /* Does the root hub have a port wakeup pending? */
176 if (!suspending && (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)) 197 if (!suspending && ehci_port_change(ehci))
177 usb_hcd_resume_root_hub(ehci_to_hcd(ehci)); 198 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
178 199
179 spin_unlock_irqrestore(&ehci->lock, flags); 200 spin_unlock_irqrestore(&ehci->lock, flags);
@@ -538,14 +559,15 @@ static ssize_t store_companion(struct device *dev,
538} 559}
539static DEVICE_ATTR(companion, 0644, show_companion, store_companion); 560static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
540 561
541static inline void create_companion_file(struct ehci_hcd *ehci) 562static inline int create_companion_file(struct ehci_hcd *ehci)
542{ 563{
543 int i; 564 int i = 0;
544 565
545 /* with integrated TT there is no companion! */ 566 /* with integrated TT there is no companion! */
546 if (!ehci_is_TDI(ehci)) 567 if (!ehci_is_TDI(ehci))
547 i = device_create_file(ehci_to_hcd(ehci)->self.controller, 568 i = device_create_file(ehci_to_hcd(ehci)->self.controller,
548 &dev_attr_companion); 569 &dev_attr_companion);
570 return i;
549} 571}
550 572
551static inline void remove_companion_file(struct ehci_hcd *ehci) 573static inline void remove_companion_file(struct ehci_hcd *ehci)
@@ -695,8 +717,8 @@ ehci_hub_descriptor (
695 desc->bDescLength = 7 + 2 * temp; 717 desc->bDescLength = 7 + 2 * temp;
696 718
697 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 719 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
698 memset (&desc->bitmap [0], 0, temp); 720 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
699 memset (&desc->bitmap [temp], 0xff, temp); 721 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
700 722
701 temp = 0x0008; /* per-port overcurrent reporting */ 723 temp = 0x0008; /* per-port overcurrent reporting */
702 if (HCS_PPC (ehci->hcs_params)) 724 if (HCS_PPC (ehci->hcs_params))
diff --git a/drivers/usb/host/ehci-lpm.c b/drivers/usb/host/ehci-lpm.c
index b4d4d63c13ed..2111627a19de 100644
--- a/drivers/usb/host/ehci-lpm.c
+++ b/drivers/usb/host/ehci-lpm.c
@@ -17,7 +17,8 @@
17*/ 17*/
18 18
19/* this file is part of ehci-hcd.c */ 19/* this file is part of ehci-hcd.c */
20static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num) 20static int __maybe_unused ehci_lpm_set_da(struct ehci_hcd *ehci,
21 int dev_addr, int port_num)
21{ 22{
22 u32 __iomem portsc; 23 u32 __iomem portsc;
23 24
@@ -37,7 +38,7 @@ static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num)
37 * this function is used to check if the device support LPM 38 * this function is used to check if the device support LPM
38 * if yes, mark the PORTSC register with PORT_LPM bit 39 * if yes, mark the PORTSC register with PORT_LPM bit
39 */ 40 */
40static int ehci_lpm_check(struct ehci_hcd *ehci, int port) 41static int __maybe_unused ehci_lpm_check(struct ehci_hcd *ehci, int port)
41{ 42{
42 u32 __iomem *portsc ; 43 u32 __iomem *portsc ;
43 u32 val32; 44 u32 val32;
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 413f4deca532..9ce1b0bc186d 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -1,6 +1,6 @@
1/* ehci-msm.c - HSUSB Host Controller Driver Implementation 1/* ehci-msm.c - HSUSB Host Controller Driver Implementation
2 * 2 *
3 * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved. 3 * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
4 * 4 *
5 * Partly derived from ehci-fsl.c and ehci-hcd.c 5 * Partly derived from ehci-fsl.c and ehci-hcd.c
6 * Copyright (c) 2000-2004 by David Brownell 6 * Copyright (c) 2000-2004 by David Brownell
@@ -34,92 +34,6 @@
34 34
35static struct otg_transceiver *otg; 35static struct otg_transceiver *otg;
36 36
37/*
38 * ehci_run defined in drivers/usb/host/ehci-hcd.c reset the controller and
39 * the configuration settings in ehci_msm_reset vanish after controller is
40 * reset. Resetting the controler in ehci_run seems to be un-necessary
41 * provided HCD reset the controller before calling ehci_run. Most of the HCD
42 * do but some are not. So this function is same as ehci_run but we don't
43 * reset the controller here.
44 */
45static int ehci_msm_run(struct usb_hcd *hcd)
46{
47 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
48 u32 temp;
49 u32 hcc_params;
50
51 hcd->uses_new_polling = 1;
52
53 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
54 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
55
56 /*
57 * hcc_params controls whether ehci->regs->segment must (!!!)
58 * be used; it constrains QH/ITD/SITD and QTD locations.
59 * pci_pool consistent memory always uses segment zero.
60 * streaming mappings for I/O buffers, like pci_map_single(),
61 * can return segments above 4GB, if the device allows.
62 *
63 * NOTE: the dma mask is visible through dma_supported(), so
64 * drivers can pass this info along ... like NETIF_F_HIGHDMA,
65 * Scsi_Host.highmem_io, and so forth. It's readonly to all
66 * host side drivers though.
67 */
68 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
69 if (HCC_64BIT_ADDR(hcc_params))
70 ehci_writel(ehci, 0, &ehci->regs->segment);
71
72 /*
73 * Philips, Intel, and maybe others need CMD_RUN before the
74 * root hub will detect new devices (why?); NEC doesn't
75 */
76 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
77 ehci->command |= CMD_RUN;
78 ehci_writel(ehci, ehci->command, &ehci->regs->command);
79 dbg_cmd(ehci, "init", ehci->command);
80
81 /*
82 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
83 * are explicitly handed to companion controller(s), so no TT is
84 * involved with the root hub. (Except where one is integrated,
85 * and there's no companion controller unless maybe for USB OTG.)
86 *
87 * Turning on the CF flag will transfer ownership of all ports
88 * from the companions to the EHCI controller. If any of the
89 * companions are in the middle of a port reset at the time, it
90 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
91 * guarantees that no resets are in progress. After we set CF,
92 * a short delay lets the hardware catch up; new resets shouldn't
93 * be started before the port switching actions could complete.
94 */
95 down_write(&ehci_cf_port_reset_rwsem);
96 hcd->state = HC_STATE_RUNNING;
97 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
98 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
99 usleep_range(5000, 5500);
100 up_write(&ehci_cf_port_reset_rwsem);
101 ehci->last_periodic_enable = ktime_get_real();
102
103 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
104 ehci_info(ehci,
105 "USB %x.%x started, EHCI %x.%02x%s\n",
106 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
107 temp >> 8, temp & 0xff,
108 ignore_oc ? ", overcurrent ignored" : "");
109
110 ehci_writel(ehci, INTR_MASK,
111 &ehci->regs->intr_enable); /* Turn On Interrupts */
112
113 /* GRR this is run-once init(), being done every time the HC starts.
114 * So long as they're part of class devices, we can't do it init()
115 * since the class device isn't created that early.
116 */
117 create_debug_files(ehci);
118 create_companion_file(ehci);
119
120 return 0;
121}
122
123static int ehci_msm_reset(struct usb_hcd *hcd) 37static int ehci_msm_reset(struct usb_hcd *hcd)
124{ 38{
125 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 39 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
@@ -128,6 +42,8 @@ static int ehci_msm_reset(struct usb_hcd *hcd)
128 ehci->caps = USB_CAPLENGTH; 42 ehci->caps = USB_CAPLENGTH;
129 ehci->regs = USB_CAPLENGTH + 43 ehci->regs = USB_CAPLENGTH +
130 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 44 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
45 dbg_hcs_params(ehci, "reset");
46 dbg_hcc_params(ehci, "reset");
131 47
132 /* cache the data to minimize the chip reads*/ 48 /* cache the data to minimize the chip reads*/
133 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 49 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
@@ -135,6 +51,10 @@ static int ehci_msm_reset(struct usb_hcd *hcd)
135 hcd->has_tt = 1; 51 hcd->has_tt = 1;
136 ehci->sbrn = HCD_USB2; 52 ehci->sbrn = HCD_USB2;
137 53
54 retval = ehci_halt(ehci);
55 if (retval)
56 return retval;
57
138 /* data structure init */ 58 /* data structure init */
139 retval = ehci_init(hcd); 59 retval = ehci_init(hcd);
140 if (retval) 60 if (retval)
@@ -167,7 +87,7 @@ static struct hc_driver msm_hc_driver = {
167 .flags = HCD_USB2 | HCD_MEMORY, 87 .flags = HCD_USB2 | HCD_MEMORY,
168 88
169 .reset = ehci_msm_reset, 89 .reset = ehci_msm_reset,
170 .start = ehci_msm_run, 90 .start = ehci_run,
171 91
172 .stop = ehci_stop, 92 .stop = ehci_stop,
173 .shutdown = ehci_shutdown, 93 .shutdown = ehci_shutdown,
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index f784ceb862a3..7e41a95c5ceb 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -4,9 +4,10 @@
4 * Bus Glue for the EHCI controllers in OMAP3/4 4 * Bus Glue for the EHCI controllers in OMAP3/4
5 * Tested on several OMAP3 boards, and OMAP4 Pandaboard 5 * Tested on several OMAP3 boards, and OMAP4 Pandaboard
6 * 6 *
7 * Copyright (C) 2007-2010 Texas Instruments, Inc. 7 * Copyright (C) 2007-2011 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com> 8 * Author: Vikram Pandita <vikram.pandita@ti.com>
9 * Author: Anand Gadiyar <gadiyar@ti.com> 9 * Author: Anand Gadiyar <gadiyar@ti.com>
10 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
10 * 11 *
11 * Copyright (C) 2009 Nokia Corporation 12 * Copyright (C) 2009 Nokia Corporation
12 * Contact: Felipe Balbi <felipe.balbi@nokia.com> 13 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
@@ -27,116 +28,19 @@
27 * along with this program; if not, write to the Free Software 28 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * 30 *
30 * TODO (last updated Nov 21, 2010): 31 * TODO (last updated Feb 27, 2010):
31 * - add kernel-doc 32 * - add kernel-doc
32 * - enable AUTOIDLE 33 * - enable AUTOIDLE
33 * - add suspend/resume 34 * - add suspend/resume
34 * - move workarounds to board-files
35 * - factor out code common to OHCI
36 * - add HSIC and TLL support 35 * - add HSIC and TLL support
37 * - convert to use hwmod and runtime PM 36 * - convert to use hwmod and runtime PM
38 */ 37 */
39 38
40#include <linux/platform_device.h> 39#include <linux/platform_device.h>
41#include <linux/clk.h>
42#include <linux/gpio.h>
43#include <linux/regulator/consumer.h>
44#include <linux/slab.h> 40#include <linux/slab.h>
45#include <linux/usb/ulpi.h> 41#include <linux/usb/ulpi.h>
46#include <plat/usb.h> 42#include <plat/usb.h>
47 43
48/*
49 * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
50 * Use ehci_omap_readl()/ehci_omap_writel() functions
51 */
52
53/* TLL Register Set */
54#define OMAP_USBTLL_REVISION (0x00)
55#define OMAP_USBTLL_SYSCONFIG (0x10)
56#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
57#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
58#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
59#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
60#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
61
62#define OMAP_USBTLL_SYSSTATUS (0x14)
63#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
64
65#define OMAP_USBTLL_IRQSTATUS (0x18)
66#define OMAP_USBTLL_IRQENABLE (0x1C)
67
68#define OMAP_TLL_SHARED_CONF (0x30)
69#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
70#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
71#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
72#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
73#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
74
75#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
76#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
77#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
78#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
79#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
80#define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
81
82#define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
83#define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
84#define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
85#define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
86#define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
87#define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
88#define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
89#define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
90#define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
91
92#define OMAP_TLL_CHANNEL_COUNT 3
93#define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0)
94#define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1)
95#define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2)
96
97/* UHH Register Set */
98#define OMAP_UHH_REVISION (0x00)
99#define OMAP_UHH_SYSCONFIG (0x10)
100#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
101#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
102#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
103#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
104#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
105#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
106
107#define OMAP_UHH_SYSSTATUS (0x14)
108#define OMAP_UHH_HOSTCONFIG (0x40)
109#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
110#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
111#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
112#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
113#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
114#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
115#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
116#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
117#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
118#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
119#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
120
121/* OMAP4-specific defines */
122#define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2)
123#define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2)
124
125#define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4)
126#define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4)
127#define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0)
128
129#define OMAP4_P1_MODE_CLEAR (3 << 16)
130#define OMAP4_P1_MODE_TLL (1 << 16)
131#define OMAP4_P1_MODE_HSIC (3 << 16)
132#define OMAP4_P2_MODE_CLEAR (3 << 18)
133#define OMAP4_P2_MODE_TLL (1 << 18)
134#define OMAP4_P2_MODE_HSIC (3 << 18)
135
136#define OMAP_REV2_TLL_CHANNEL_COUNT 2
137
138#define OMAP_UHH_DEBUG_CSR (0x44)
139
140/* EHCI Register Set */ 44/* EHCI Register Set */
141#define EHCI_INSNREG04 (0xA0) 45#define EHCI_INSNREG04 (0xA0)
142#define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5) 46#define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5)
@@ -148,137 +52,24 @@
148#define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8 52#define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
149#define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0 53#define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
150 54
151/* Values of UHH_REVISION - Note: these are not given in the TRM */ 55/*-------------------------------------------------------------------------*/
152#define OMAP_EHCI_REV1 0x00000010 /* OMAP3 */
153#define OMAP_EHCI_REV2 0x50700100 /* OMAP4 */
154
155#define is_omap_ehci_rev1(x) (x->omap_ehci_rev == OMAP_EHCI_REV1)
156#define is_omap_ehci_rev2(x) (x->omap_ehci_rev == OMAP_EHCI_REV2)
157 56
158#define is_ehci_phy_mode(x) (x == EHCI_HCD_OMAP_MODE_PHY) 57static const struct hc_driver ehci_omap_hc_driver;
159#define is_ehci_tll_mode(x) (x == EHCI_HCD_OMAP_MODE_TLL)
160#define is_ehci_hsic_mode(x) (x == EHCI_HCD_OMAP_MODE_HSIC)
161 58
162/*-------------------------------------------------------------------------*/
163 59
164static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val) 60static inline void ehci_write(void __iomem *base, u32 reg, u32 val)
165{ 61{
166 __raw_writel(val, base + reg); 62 __raw_writel(val, base + reg);
167} 63}
168 64
169static inline u32 ehci_omap_readl(void __iomem *base, u32 reg) 65static inline u32 ehci_read(void __iomem *base, u32 reg)
170{ 66{
171 return __raw_readl(base + reg); 67 return __raw_readl(base + reg);
172} 68}
173 69
174static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val) 70static void omap_ehci_soft_phy_reset(struct platform_device *pdev, u8 port)
175{
176 __raw_writeb(val, base + reg);
177}
178
179static inline u8 ehci_omap_readb(void __iomem *base, u8 reg)
180{
181 return __raw_readb(base + reg);
182}
183
184/*-------------------------------------------------------------------------*/
185
186struct ehci_hcd_omap {
187 struct ehci_hcd *ehci;
188 struct device *dev;
189
190 struct clk *usbhost_ick;
191 struct clk *usbhost_hs_fck;
192 struct clk *usbhost_fs_fck;
193 struct clk *usbtll_fck;
194 struct clk *usbtll_ick;
195 struct clk *xclk60mhsp1_ck;
196 struct clk *xclk60mhsp2_ck;
197 struct clk *utmi_p1_fck;
198 struct clk *utmi_p2_fck;
199
200 /* FIXME the following two workarounds are
201 * board specific not silicon-specific so these
202 * should be moved to board-file instead.
203 *
204 * Maybe someone from TI will know better which
205 * board is affected and needs the workarounds
206 * to be applied
207 */
208
209 /* gpio for resetting phy */
210 int reset_gpio_port[OMAP3_HS_USB_PORTS];
211
212 /* phy reset workaround */
213 int phy_reset;
214
215 /* IP revision */
216 u32 omap_ehci_rev;
217
218 /* desired phy_mode: TLL, PHY */
219 enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
220
221 void __iomem *uhh_base;
222 void __iomem *tll_base;
223 void __iomem *ehci_base;
224
225 /* Regulators for USB PHYs.
226 * Each PHY can have a separate regulator.
227 */
228 struct regulator *regulator[OMAP3_HS_USB_PORTS];
229};
230
231/*-------------------------------------------------------------------------*/
232
233static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask,
234 u8 tll_channel_count)
235{
236 unsigned reg;
237 int i;
238
239 /* Program the 3 TLL channels upfront */
240 for (i = 0; i < tll_channel_count; i++) {
241 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
242
243 /* Disable AutoIdle, BitStuffing and use SDR Mode */
244 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
245 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
246 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
247 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
248 }
249
250 /* Program Common TLL register */
251 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
252 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
253 | OMAP_TLL_SHARED_CONF_USB_DIVRATION
254 | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN);
255 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
256
257 ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
258
259 /* Enable channels now */
260 for (i = 0; i < tll_channel_count; i++) {
261 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
262
263 /* Enable only the reg that is needed */
264 if (!(tll_channel_mask & 1<<i))
265 continue;
266
267 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
268 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
269
270 ehci_omap_writeb(omap->tll_base,
271 OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
272 dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
273 i+1, ehci_omap_readb(omap->tll_base,
274 OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
275 }
276}
277
278/*-------------------------------------------------------------------------*/
279
280static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
281{ 71{
72 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
282 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 73 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
283 unsigned reg = 0; 74 unsigned reg = 0;
284 75
@@ -292,266 +83,87 @@ static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
292 /* start ULPI access*/ 83 /* start ULPI access*/
293 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT); 84 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
294 85
295 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg); 86 ehci_write(hcd->regs, EHCI_INSNREG05_ULPI, reg);
296 87
297 /* Wait for ULPI access completion */ 88 /* Wait for ULPI access completion */
298 while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI) 89 while ((ehci_read(hcd->regs, EHCI_INSNREG05_ULPI)
299 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) { 90 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
300 cpu_relax(); 91 cpu_relax();
301 92
302 if (time_after(jiffies, timeout)) { 93 if (time_after(jiffies, timeout)) {
303 dev_dbg(omap->dev, "phy reset operation timed out\n"); 94 dev_dbg(&pdev->dev, "phy reset operation timed out\n");
304 break; 95 break;
305 } 96 }
306 } 97 }
307} 98}
308 99
309/* omap_start_ehc
310 * - Start the TI USBHOST controller
311 */
312static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
313{
314 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
315 u8 tll_ch_mask = 0;
316 unsigned reg = 0;
317 int ret = 0;
318
319 dev_dbg(omap->dev, "starting TI EHCI USB Controller\n");
320 100
321 /* Enable Clocks for USBHOST */ 101/* configure so an HC device and id are always provided */
322 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick"); 102/* always called with process context; sleeping is OK */
323 if (IS_ERR(omap->usbhost_ick)) {
324 ret = PTR_ERR(omap->usbhost_ick);
325 goto err_host_ick;
326 }
327 clk_enable(omap->usbhost_ick);
328
329 omap->usbhost_hs_fck = clk_get(omap->dev, "hs_fck");
330 if (IS_ERR(omap->usbhost_hs_fck)) {
331 ret = PTR_ERR(omap->usbhost_hs_fck);
332 goto err_host_120m_fck;
333 }
334 clk_enable(omap->usbhost_hs_fck);
335 103
336 omap->usbhost_fs_fck = clk_get(omap->dev, "fs_fck"); 104/**
337 if (IS_ERR(omap->usbhost_fs_fck)) { 105 * ehci_hcd_omap_probe - initialize TI-based HCDs
338 ret = PTR_ERR(omap->usbhost_fs_fck); 106 *
339 goto err_host_48m_fck; 107 * Allocates basic resources for this USB host controller, and
340 } 108 * then invokes the start() method for the HCD associated with it
341 clk_enable(omap->usbhost_fs_fck); 109 * through the hotplug entry's driver_data.
342 110 */
343 if (omap->phy_reset) { 111static int ehci_hcd_omap_probe(struct platform_device *pdev)
344 /* Refer: ISSUE1 */ 112{
345 if (gpio_is_valid(omap->reset_gpio_port[0])) { 113 struct device *dev = &pdev->dev;
346 gpio_request(omap->reset_gpio_port[0], 114 struct ehci_hcd_omap_platform_data *pdata = dev->platform_data;
347 "USB1 PHY reset"); 115 struct resource *res;
348 gpio_direction_output(omap->reset_gpio_port[0], 0); 116 struct usb_hcd *hcd;
349 } 117 void __iomem *regs;
118 struct ehci_hcd *omap_ehci;
119 int ret = -ENODEV;
120 int irq;
350 121
351 if (gpio_is_valid(omap->reset_gpio_port[1])) { 122 if (usb_disabled())
352 gpio_request(omap->reset_gpio_port[1], 123 return -ENODEV;
353 "USB2 PHY reset");
354 gpio_direction_output(omap->reset_gpio_port[1], 0);
355 }
356 124
357 /* Hold the PHY in RESET for enough time till DIR is high */ 125 if (!dev->parent) {
358 udelay(10); 126 dev_err(dev, "Missing parent device\n");
127 return -ENODEV;
359 } 128 }
360 129
361 /* Configure TLL for 60Mhz clk for ULPI */ 130 irq = platform_get_irq_byname(pdev, "ehci-irq");
362 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck"); 131 if (irq < 0) {
363 if (IS_ERR(omap->usbtll_fck)) { 132 dev_err(dev, "EHCI irq failed\n");
364 ret = PTR_ERR(omap->usbtll_fck); 133 return -ENODEV;
365 goto err_tll_fck;
366 } 134 }
367 clk_enable(omap->usbtll_fck);
368 135
369 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick"); 136 res = platform_get_resource_byname(pdev,
370 if (IS_ERR(omap->usbtll_ick)) { 137 IORESOURCE_MEM, "ehci");
371 ret = PTR_ERR(omap->usbtll_ick); 138 if (!res) {
372 goto err_tll_ick; 139 dev_err(dev, "UHH EHCI get resource failed\n");
140 return -ENODEV;
373 } 141 }
374 clk_enable(omap->usbtll_ick);
375
376 omap->omap_ehci_rev = ehci_omap_readl(omap->uhh_base,
377 OMAP_UHH_REVISION);
378 dev_dbg(omap->dev, "OMAP UHH_REVISION 0x%x\n",
379 omap->omap_ehci_rev);
380 142
381 /* 143 regs = ioremap(res->start, resource_size(res));
382 * Enable per-port clocks as needed (newer controllers only). 144 if (!regs) {
383 * - External ULPI clock for PHY mode 145 dev_err(dev, "UHH EHCI ioremap failed\n");
384 * - Internal clocks for TLL and HSIC modes (TODO) 146 return -ENOMEM;
385 */
386 if (is_omap_ehci_rev2(omap)) {
387 switch (omap->port_mode[0]) {
388 case EHCI_HCD_OMAP_MODE_PHY:
389 omap->xclk60mhsp1_ck = clk_get(omap->dev,
390 "xclk60mhsp1_ck");
391 if (IS_ERR(omap->xclk60mhsp1_ck)) {
392 ret = PTR_ERR(omap->xclk60mhsp1_ck);
393 dev_err(omap->dev,
394 "Unable to get Port1 ULPI clock\n");
395 }
396
397 omap->utmi_p1_fck = clk_get(omap->dev,
398 "utmi_p1_gfclk");
399 if (IS_ERR(omap->utmi_p1_fck)) {
400 ret = PTR_ERR(omap->utmi_p1_fck);
401 dev_err(omap->dev,
402 "Unable to get utmi_p1_fck\n");
403 }
404
405 ret = clk_set_parent(omap->utmi_p1_fck,
406 omap->xclk60mhsp1_ck);
407 if (ret != 0) {
408 dev_err(omap->dev,
409 "Unable to set P1 f-clock\n");
410 }
411 break;
412 case EHCI_HCD_OMAP_MODE_TLL:
413 /* TODO */
414 default:
415 break;
416 }
417 switch (omap->port_mode[1]) {
418 case EHCI_HCD_OMAP_MODE_PHY:
419 omap->xclk60mhsp2_ck = clk_get(omap->dev,
420 "xclk60mhsp2_ck");
421 if (IS_ERR(omap->xclk60mhsp2_ck)) {
422 ret = PTR_ERR(omap->xclk60mhsp2_ck);
423 dev_err(omap->dev,
424 "Unable to get Port2 ULPI clock\n");
425 }
426
427 omap->utmi_p2_fck = clk_get(omap->dev,
428 "utmi_p2_gfclk");
429 if (IS_ERR(omap->utmi_p2_fck)) {
430 ret = PTR_ERR(omap->utmi_p2_fck);
431 dev_err(omap->dev,
432 "Unable to get utmi_p2_fck\n");
433 }
434
435 ret = clk_set_parent(omap->utmi_p2_fck,
436 omap->xclk60mhsp2_ck);
437 if (ret != 0) {
438 dev_err(omap->dev,
439 "Unable to set P2 f-clock\n");
440 }
441 break;
442 case EHCI_HCD_OMAP_MODE_TLL:
443 /* TODO */
444 default:
445 break;
446 }
447 } 147 }
448 148
449 149 hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
450 /* perform TLL soft reset, and wait until reset is complete */ 150 dev_name(dev));
451 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, 151 if (!hcd) {
452 OMAP_USBTLL_SYSCONFIG_SOFTRESET); 152 dev_err(dev, "failed to create hcd with err %d\n", ret);
453 153 ret = -ENOMEM;
454 /* Wait for TLL reset to complete */ 154 goto err_io;
455 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
456 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
457 cpu_relax();
458
459 if (time_after(jiffies, timeout)) {
460 dev_dbg(omap->dev, "operation timed out\n");
461 ret = -EINVAL;
462 goto err_sys_status;
463 }
464 } 155 }
465 156
466 dev_dbg(omap->dev, "TLL RESET DONE\n"); 157 hcd->rsrc_start = res->start;
467 158 hcd->rsrc_len = resource_size(res);
468 /* (1<<3) = no idle mode only for initial debugging */ 159 hcd->regs = regs;
469 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
470 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
471 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
472 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
473
474
475 /* Put UHH in NoIdle/NoStandby mode */
476 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
477 if (is_omap_ehci_rev1(omap)) {
478 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
479 | OMAP_UHH_SYSCONFIG_SIDLEMODE
480 | OMAP_UHH_SYSCONFIG_CACTIVITY
481 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
482 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
483
484 160
485 } else if (is_omap_ehci_rev2(omap)) { 161 ret = omap_usbhs_enable(dev);
486 reg &= ~OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR; 162 if (ret) {
487 reg |= OMAP4_UHH_SYSCONFIG_NOIDLE; 163 dev_err(dev, "failed to start usbhs with err %d\n", ret);
488 reg &= ~OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR; 164 goto err_enable;
489 reg |= OMAP4_UHH_SYSCONFIG_NOSTDBY;
490 }
491 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
492
493 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
494
495 /* setup ULPI bypass and burst configurations */
496 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
497 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
498 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
499 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
500
501 if (is_omap_ehci_rev1(omap)) {
502 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN)
503 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
504 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN)
505 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
506 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN)
507 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
508
509 /* Bypass the TLL module for PHY mode operation */
510 if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
511 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
512 if (is_ehci_phy_mode(omap->port_mode[0]) ||
513 is_ehci_phy_mode(omap->port_mode[1]) ||
514 is_ehci_phy_mode(omap->port_mode[2]))
515 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
516 else
517 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
518 } else {
519 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
520 if (is_ehci_phy_mode(omap->port_mode[0]))
521 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
522 else if (is_ehci_tll_mode(omap->port_mode[0]))
523 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
524
525 if (is_ehci_phy_mode(omap->port_mode[1]))
526 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
527 else if (is_ehci_tll_mode(omap->port_mode[1]))
528 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
529
530 if (is_ehci_phy_mode(omap->port_mode[2]))
531 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
532 else if (is_ehci_tll_mode(omap->port_mode[2]))
533 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
534 }
535 } else if (is_omap_ehci_rev2(omap)) {
536 /* Clear port mode fields for PHY mode*/
537 reg &= ~OMAP4_P1_MODE_CLEAR;
538 reg &= ~OMAP4_P2_MODE_CLEAR;
539
540 if (is_ehci_tll_mode(omap->port_mode[0]))
541 reg |= OMAP4_P1_MODE_TLL;
542 else if (is_ehci_hsic_mode(omap->port_mode[0]))
543 reg |= OMAP4_P1_MODE_HSIC;
544
545 if (is_ehci_tll_mode(omap->port_mode[1]))
546 reg |= OMAP4_P2_MODE_TLL;
547 else if (is_ehci_hsic_mode(omap->port_mode[1]))
548 reg |= OMAP4_P2_MODE_HSIC;
549 } 165 }
550 166
551 ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
552 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
553
554
555 /* 167 /*
556 * An undocumented "feature" in the OMAP3 EHCI controller, 168 * An undocumented "feature" in the OMAP3 EHCI controller,
557 * causes suspended ports to be taken out of suspend when 169 * causes suspended ports to be taken out of suspend when
@@ -561,363 +173,50 @@ static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
561 * to suspend. Writing 1 to this undocumented register bit 173 * to suspend. Writing 1 to this undocumented register bit
562 * disables this feature and restores normal behavior. 174 * disables this feature and restores normal behavior.
563 */ 175 */
564 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG04, 176 ehci_write(regs, EHCI_INSNREG04,
565 EHCI_INSNREG04_DISABLE_UNSUSPEND); 177 EHCI_INSNREG04_DISABLE_UNSUSPEND);
566 178
567 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
568 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
569 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
570
571 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
572 tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK;
573 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
574 tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK;
575 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
576 tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK;
577
578 /* Enable UTMI mode for required TLL channels */
579 omap_usb_utmi_init(omap, tll_ch_mask, OMAP_TLL_CHANNEL_COUNT);
580 }
581
582 if (omap->phy_reset) {
583 /* Refer ISSUE1:
584 * Hold the PHY in RESET for enough time till
585 * PHY is settled and ready
586 */
587 udelay(10);
588
589 if (gpio_is_valid(omap->reset_gpio_port[0]))
590 gpio_set_value(omap->reset_gpio_port[0], 1);
591
592 if (gpio_is_valid(omap->reset_gpio_port[1]))
593 gpio_set_value(omap->reset_gpio_port[1], 1);
594 }
595
596 /* Soft reset the PHY using PHY reset command over ULPI */ 179 /* Soft reset the PHY using PHY reset command over ULPI */
597 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) 180 if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY)
598 omap_ehci_soft_phy_reset(omap, 0); 181 omap_ehci_soft_phy_reset(pdev, 0);
599 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) 182 if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY)
600 omap_ehci_soft_phy_reset(omap, 1); 183 omap_ehci_soft_phy_reset(pdev, 1);
601
602 return 0;
603
604err_sys_status:
605 clk_disable(omap->utmi_p2_fck);
606 clk_put(omap->utmi_p2_fck);
607 clk_disable(omap->xclk60mhsp2_ck);
608 clk_put(omap->xclk60mhsp2_ck);
609 clk_disable(omap->utmi_p1_fck);
610 clk_put(omap->utmi_p1_fck);
611 clk_disable(omap->xclk60mhsp1_ck);
612 clk_put(omap->xclk60mhsp1_ck);
613 clk_disable(omap->usbtll_ick);
614 clk_put(omap->usbtll_ick);
615
616err_tll_ick:
617 clk_disable(omap->usbtll_fck);
618 clk_put(omap->usbtll_fck);
619
620err_tll_fck:
621 clk_disable(omap->usbhost_fs_fck);
622 clk_put(omap->usbhost_fs_fck);
623
624 if (omap->phy_reset) {
625 if (gpio_is_valid(omap->reset_gpio_port[0]))
626 gpio_free(omap->reset_gpio_port[0]);
627
628 if (gpio_is_valid(omap->reset_gpio_port[1]))
629 gpio_free(omap->reset_gpio_port[1]);
630 }
631
632err_host_48m_fck:
633 clk_disable(omap->usbhost_hs_fck);
634 clk_put(omap->usbhost_hs_fck);
635 184
636err_host_120m_fck: 185 omap_ehci = hcd_to_ehci(hcd);
637 clk_disable(omap->usbhost_ick); 186 omap_ehci->sbrn = 0x20;
638 clk_put(omap->usbhost_ick);
639
640err_host_ick:
641 return ret;
642}
643
644static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
645{
646 unsigned long timeout = jiffies + msecs_to_jiffies(100);
647
648 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
649
650 /* Reset OMAP modules for insmod/rmmod to work */
651 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
652 is_omap_ehci_rev2(omap) ?
653 OMAP4_UHH_SYSCONFIG_SOFTRESET :
654 OMAP_UHH_SYSCONFIG_SOFTRESET);
655 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
656 & (1 << 0))) {
657 cpu_relax();
658
659 if (time_after(jiffies, timeout))
660 dev_dbg(omap->dev, "operation timed out\n");
661 }
662
663 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
664 & (1 << 1))) {
665 cpu_relax();
666
667 if (time_after(jiffies, timeout))
668 dev_dbg(omap->dev, "operation timed out\n");
669 }
670
671 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
672 & (1 << 2))) {
673 cpu_relax();
674
675 if (time_after(jiffies, timeout))
676 dev_dbg(omap->dev, "operation timed out\n");
677 }
678
679 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
680
681 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
682 & (1 << 0))) {
683 cpu_relax();
684
685 if (time_after(jiffies, timeout))
686 dev_dbg(omap->dev, "operation timed out\n");
687 }
688
689 if (omap->usbtll_fck != NULL) {
690 clk_disable(omap->usbtll_fck);
691 clk_put(omap->usbtll_fck);
692 omap->usbtll_fck = NULL;
693 }
694
695 if (omap->usbhost_ick != NULL) {
696 clk_disable(omap->usbhost_ick);
697 clk_put(omap->usbhost_ick);
698 omap->usbhost_ick = NULL;
699 }
700
701 if (omap->usbhost_fs_fck != NULL) {
702 clk_disable(omap->usbhost_fs_fck);
703 clk_put(omap->usbhost_fs_fck);
704 omap->usbhost_fs_fck = NULL;
705 }
706
707 if (omap->usbhost_hs_fck != NULL) {
708 clk_disable(omap->usbhost_hs_fck);
709 clk_put(omap->usbhost_hs_fck);
710 omap->usbhost_hs_fck = NULL;
711 }
712
713 if (omap->usbtll_ick != NULL) {
714 clk_disable(omap->usbtll_ick);
715 clk_put(omap->usbtll_ick);
716 omap->usbtll_ick = NULL;
717 }
718
719 if (is_omap_ehci_rev2(omap)) {
720 if (omap->xclk60mhsp1_ck != NULL) {
721 clk_disable(omap->xclk60mhsp1_ck);
722 clk_put(omap->xclk60mhsp1_ck);
723 omap->xclk60mhsp1_ck = NULL;
724 }
725
726 if (omap->utmi_p1_fck != NULL) {
727 clk_disable(omap->utmi_p1_fck);
728 clk_put(omap->utmi_p1_fck);
729 omap->utmi_p1_fck = NULL;
730 }
731
732 if (omap->xclk60mhsp2_ck != NULL) {
733 clk_disable(omap->xclk60mhsp2_ck);
734 clk_put(omap->xclk60mhsp2_ck);
735 omap->xclk60mhsp2_ck = NULL;
736 }
737
738 if (omap->utmi_p2_fck != NULL) {
739 clk_disable(omap->utmi_p2_fck);
740 clk_put(omap->utmi_p2_fck);
741 omap->utmi_p2_fck = NULL;
742 }
743 }
744
745 if (omap->phy_reset) {
746 if (gpio_is_valid(omap->reset_gpio_port[0]))
747 gpio_free(omap->reset_gpio_port[0]);
748
749 if (gpio_is_valid(omap->reset_gpio_port[1]))
750 gpio_free(omap->reset_gpio_port[1]);
751 }
752
753 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
754}
755
756/*-------------------------------------------------------------------------*/
757
758static const struct hc_driver ehci_omap_hc_driver;
759
760/* configure so an HC device and id are always provided */
761/* always called with process context; sleeping is OK */
762
763/**
764 * ehci_hcd_omap_probe - initialize TI-based HCDs
765 *
766 * Allocates basic resources for this USB host controller, and
767 * then invokes the start() method for the HCD associated with it
768 * through the hotplug entry's driver_data.
769 */
770static int ehci_hcd_omap_probe(struct platform_device *pdev)
771{
772 struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
773 struct ehci_hcd_omap *omap;
774 struct resource *res;
775 struct usb_hcd *hcd;
776
777 int irq = platform_get_irq(pdev, 0);
778 int ret = -ENODEV;
779 int i;
780 char supply[7];
781
782 if (!pdata) {
783 dev_dbg(&pdev->dev, "missing platform_data\n");
784 goto err_pdata;
785 }
786
787 if (usb_disabled())
788 goto err_disabled;
789
790 omap = kzalloc(sizeof(*omap), GFP_KERNEL);
791 if (!omap) {
792 ret = -ENOMEM;
793 goto err_disabled;
794 }
795
796 hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev,
797 dev_name(&pdev->dev));
798 if (!hcd) {
799 dev_err(&pdev->dev, "failed to create hcd with err %d\n", ret);
800 ret = -ENOMEM;
801 goto err_create_hcd;
802 }
803
804 platform_set_drvdata(pdev, omap);
805 omap->dev = &pdev->dev;
806 omap->phy_reset = pdata->phy_reset;
807 omap->reset_gpio_port[0] = pdata->reset_gpio_port[0];
808 omap->reset_gpio_port[1] = pdata->reset_gpio_port[1];
809 omap->reset_gpio_port[2] = pdata->reset_gpio_port[2];
810 omap->port_mode[0] = pdata->port_mode[0];
811 omap->port_mode[1] = pdata->port_mode[1];
812 omap->port_mode[2] = pdata->port_mode[2];
813 omap->ehci = hcd_to_ehci(hcd);
814 omap->ehci->sbrn = 0x20;
815
816 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
817
818 hcd->rsrc_start = res->start;
819 hcd->rsrc_len = resource_size(res);
820
821 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
822 if (!hcd->regs) {
823 dev_err(&pdev->dev, "EHCI ioremap failed\n");
824 ret = -ENOMEM;
825 goto err_ioremap;
826 }
827 187
828 /* we know this is the memory we want, no need to ioremap again */ 188 /* we know this is the memory we want, no need to ioremap again */
829 omap->ehci->caps = hcd->regs; 189 omap_ehci->caps = hcd->regs;
830 omap->ehci_base = hcd->regs; 190 omap_ehci->regs = hcd->regs
831 191 + HC_LENGTH(readl(&omap_ehci->caps->hc_capbase));
832 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
833 omap->uhh_base = ioremap(res->start, resource_size(res));
834 if (!omap->uhh_base) {
835 dev_err(&pdev->dev, "UHH ioremap failed\n");
836 ret = -ENOMEM;
837 goto err_uhh_ioremap;
838 }
839
840 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
841 omap->tll_base = ioremap(res->start, resource_size(res));
842 if (!omap->tll_base) {
843 dev_err(&pdev->dev, "TLL ioremap failed\n");
844 ret = -ENOMEM;
845 goto err_tll_ioremap;
846 }
847
848 /* get ehci regulator and enable */
849 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
850 if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) {
851 omap->regulator[i] = NULL;
852 continue;
853 }
854 snprintf(supply, sizeof(supply), "hsusb%d", i);
855 omap->regulator[i] = regulator_get(omap->dev, supply);
856 if (IS_ERR(omap->regulator[i])) {
857 omap->regulator[i] = NULL;
858 dev_dbg(&pdev->dev,
859 "failed to get ehci port%d regulator\n", i);
860 } else {
861 regulator_enable(omap->regulator[i]);
862 }
863 }
864
865 ret = omap_start_ehc(omap, hcd);
866 if (ret) {
867 dev_err(&pdev->dev, "failed to start ehci with err %d\n", ret);
868 goto err_start;
869 }
870 192
871 omap->ehci->regs = hcd->regs 193 dbg_hcs_params(omap_ehci, "reset");
872 + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase)); 194 dbg_hcc_params(omap_ehci, "reset");
873
874 dbg_hcs_params(omap->ehci, "reset");
875 dbg_hcc_params(omap->ehci, "reset");
876 195
877 /* cache this readonly data; minimize chip reads */ 196 /* cache this readonly data; minimize chip reads */
878 omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params); 197 omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params);
879 198
880 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); 199 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
881 if (ret) { 200 if (ret) {
882 dev_err(&pdev->dev, "failed to add hcd with err %d\n", ret); 201 dev_err(dev, "failed to add hcd with err %d\n", ret);
883 goto err_add_hcd; 202 goto err_add_hcd;
884 } 203 }
885 204
886 /* root ports should always stay powered */ 205 /* root ports should always stay powered */
887 ehci_port_power(omap->ehci, 1); 206 ehci_port_power(omap_ehci, 1);
888 207
889 return 0; 208 return 0;
890 209
891err_add_hcd: 210err_add_hcd:
892 omap_stop_ehc(omap, hcd); 211 omap_usbhs_disable(dev);
893 212
894err_start: 213err_enable:
895 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
896 if (omap->regulator[i]) {
897 regulator_disable(omap->regulator[i]);
898 regulator_put(omap->regulator[i]);
899 }
900 }
901 iounmap(omap->tll_base);
902
903err_tll_ioremap:
904 iounmap(omap->uhh_base);
905
906err_uhh_ioremap:
907 iounmap(hcd->regs);
908
909err_ioremap:
910 usb_put_hcd(hcd); 214 usb_put_hcd(hcd);
911 215
912err_create_hcd: 216err_io:
913 kfree(omap);
914err_disabled:
915err_pdata:
916 return ret; 217 return ret;
917} 218}
918 219
919/* may be called without controller electrically present */
920/* may be called with controller, bus, and devices active */
921 220
922/** 221/**
923 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs 222 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
@@ -929,31 +228,18 @@ err_pdata:
929 */ 228 */
930static int ehci_hcd_omap_remove(struct platform_device *pdev) 229static int ehci_hcd_omap_remove(struct platform_device *pdev)
931{ 230{
932 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev); 231 struct device *dev = &pdev->dev;
933 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci); 232 struct usb_hcd *hcd = dev_get_drvdata(dev);
934 int i;
935 233
936 usb_remove_hcd(hcd); 234 usb_remove_hcd(hcd);
937 omap_stop_ehc(omap, hcd); 235 omap_usbhs_disable(dev);
938 iounmap(hcd->regs);
939 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
940 if (omap->regulator[i]) {
941 regulator_disable(omap->regulator[i]);
942 regulator_put(omap->regulator[i]);
943 }
944 }
945 iounmap(omap->tll_base);
946 iounmap(omap->uhh_base);
947 usb_put_hcd(hcd); 236 usb_put_hcd(hcd);
948 kfree(omap);
949
950 return 0; 237 return 0;
951} 238}
952 239
953static void ehci_hcd_omap_shutdown(struct platform_device *pdev) 240static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
954{ 241{
955 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev); 242 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
956 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
957 243
958 if (hcd->driver->shutdown) 244 if (hcd->driver->shutdown)
959 hcd->driver->shutdown(hcd); 245 hcd->driver->shutdown(hcd);
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 0f87dc72820a..281e094e1c18 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -105,7 +105,8 @@ static int ehci_orion_setup(struct usb_hcd *hcd)
105 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 105 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
106 int retval; 106 int retval;
107 107
108 ehci_reset(ehci); 108 hcd->has_tt = 1;
109
109 retval = ehci_halt(ehci); 110 retval = ehci_halt(ehci);
110 if (retval) 111 if (retval)
111 return retval; 112 return retval;
@@ -117,7 +118,7 @@ static int ehci_orion_setup(struct usb_hcd *hcd)
117 if (retval) 118 if (retval)
118 return retval; 119 return retval;
119 120
120 hcd->has_tt = 1; 121 ehci_reset(ehci);
121 122
122 ehci_port_power(ehci, 0); 123 ehci_port_power(ehci, 0);
123 124
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 07bb982e59f6..d5eaea7caf89 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -44,42 +44,6 @@ static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
44 return 0; 44 return 0;
45} 45}
46 46
47static int ehci_quirk_amd_hudson(struct ehci_hcd *ehci)
48{
49 struct pci_dev *amd_smbus_dev;
50 u8 rev = 0;
51
52 amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL);
53 if (amd_smbus_dev) {
54 pci_read_config_byte(amd_smbus_dev, PCI_REVISION_ID, &rev);
55 if (rev < 0x40) {
56 pci_dev_put(amd_smbus_dev);
57 amd_smbus_dev = NULL;
58 return 0;
59 }
60 } else {
61 amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x780b, NULL);
62 if (!amd_smbus_dev)
63 return 0;
64 pci_read_config_byte(amd_smbus_dev, PCI_REVISION_ID, &rev);
65 if (rev < 0x11 || rev > 0x18) {
66 pci_dev_put(amd_smbus_dev);
67 amd_smbus_dev = NULL;
68 return 0;
69 }
70 }
71
72 if (!amd_nb_dev)
73 amd_nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x1510, NULL);
74
75 ehci_info(ehci, "QUIRK: Enable exception for AMD Hudson ASPM\n");
76
77 pci_dev_put(amd_smbus_dev);
78 amd_smbus_dev = NULL;
79
80 return 1;
81}
82
83/* called during probe() after chip reset completes */ 47/* called during probe() after chip reset completes */
84static int ehci_pci_setup(struct usb_hcd *hcd) 48static int ehci_pci_setup(struct usb_hcd *hcd)
85{ 49{
@@ -138,9 +102,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
138 /* cache this readonly data; minimize chip reads */ 102 /* cache this readonly data; minimize chip reads */
139 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 103 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
140 104
141 if (ehci_quirk_amd_hudson(ehci))
142 ehci->amd_l1_fix = 1;
143
144 retval = ehci_halt(ehci); 105 retval = ehci_halt(ehci);
145 if (retval) 106 if (retval)
146 return retval; 107 return retval;
@@ -191,6 +152,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
191 } 152 }
192 break; 153 break;
193 case PCI_VENDOR_ID_AMD: 154 case PCI_VENDOR_ID_AMD:
155 /* AMD PLL quirk */
156 if (usb_amd_find_chipset_info())
157 ehci->amd_pll_fix = 1;
194 /* AMD8111 EHCI doesn't work, according to AMD errata */ 158 /* AMD8111 EHCI doesn't work, according to AMD errata */
195 if (pdev->device == 0x7463) { 159 if (pdev->device == 0x7463) {
196 ehci_info(ehci, "ignoring AMD8111 (errata)\n"); 160 ehci_info(ehci, "ignoring AMD8111 (errata)\n");
@@ -236,6 +200,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
236 } 200 }
237 break; 201 break;
238 case PCI_VENDOR_ID_ATI: 202 case PCI_VENDOR_ID_ATI:
203 /* AMD PLL quirk */
204 if (usb_amd_find_chipset_info())
205 ehci->amd_pll_fix = 1;
239 /* SB600 and old version of SB700 have a bug in EHCI controller, 206 /* SB600 and old version of SB700 have a bug in EHCI controller,
240 * which causes usb devices lose response in some cases. 207 * which causes usb devices lose response in some cases.
241 */ 208 */
diff --git a/drivers/usb/host/ehci-pmcmsp.c b/drivers/usb/host/ehci-pmcmsp.c
new file mode 100644
index 000000000000..a2168642175b
--- /dev/null
+++ b/drivers/usb/host/ehci-pmcmsp.c
@@ -0,0 +1,383 @@
1/*
2 * PMC MSP EHCI (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 2006-2010 PMC-Sierra Inc
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 *
10 */
11
12/* includes */
13#include <linux/platform_device.h>
14#include <linux/gpio.h>
15#include <linux/usb.h>
16#include <msp_usb.h>
17
18/* stream disable*/
19#define USB_CTRL_MODE_STREAM_DISABLE 0x10
20
21/* threshold */
22#define USB_CTRL_FIFO_THRESH 0x00300000
23
24/* register offset for usb_mode */
25#define USB_EHCI_REG_USB_MODE 0x68
26
27/* register offset for usb fifo */
28#define USB_EHCI_REG_USB_FIFO 0x24
29
30/* register offset for usb status */
31#define USB_EHCI_REG_USB_STATUS 0x44
32
33/* serial/parallel transceiver */
34#define USB_EHCI_REG_BIT_STAT_STS (1<<29)
35
36/* TWI USB0 host device pin */
37#define MSP_PIN_USB0_HOST_DEV 49
38
39/* TWI USB1 host device pin */
40#define MSP_PIN_USB1_HOST_DEV 50
41
42
43static void usb_hcd_tdi_set_mode(struct ehci_hcd *ehci)
44{
45 u8 *base;
46 u8 *statreg;
47 u8 *fiforeg;
48 u32 val;
49 struct ehci_regs *reg_base = ehci->regs;
50
51 /* get register base */
52 base = (u8 *)reg_base + USB_EHCI_REG_USB_MODE;
53 statreg = (u8 *)reg_base + USB_EHCI_REG_USB_STATUS;
54 fiforeg = (u8 *)reg_base + USB_EHCI_REG_USB_FIFO;
55
56 /* Disable controller mode stream */
57 val = ehci_readl(ehci, (u32 *)base);
58 ehci_writel(ehci, (val | USB_CTRL_MODE_STREAM_DISABLE),
59 (u32 *)base);
60
61 /* clear STS to select parallel transceiver interface */
62 val = ehci_readl(ehci, (u32 *)statreg);
63 val = val & ~USB_EHCI_REG_BIT_STAT_STS;
64 ehci_writel(ehci, val, (u32 *)statreg);
65
66 /* write to set the proper fifo threshold */
67 ehci_writel(ehci, USB_CTRL_FIFO_THRESH, (u32 *)fiforeg);
68
69 /* set TWI GPIO USB_HOST_DEV pin high */
70 gpio_direction_output(MSP_PIN_USB0_HOST_DEV, 1);
71#ifdef CONFIG_MSP_HAS_DUAL_USB
72 gpio_direction_output(MSP_PIN_USB1_HOST_DEV, 1);
73#endif
74}
75
76/* called during probe() after chip reset completes */
77static int ehci_msp_setup(struct usb_hcd *hcd)
78{
79 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
80 int retval;
81 ehci->big_endian_mmio = 1;
82 ehci->big_endian_desc = 1;
83
84 ehci->caps = hcd->regs;
85 ehci->regs = hcd->regs +
86 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
87 dbg_hcs_params(ehci, "reset");
88 dbg_hcc_params(ehci, "reset");
89
90 /* cache this readonly data; minimize chip reads */
91 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
92 hcd->has_tt = 1;
93
94 retval = ehci_halt(ehci);
95 if (retval)
96 return retval;
97
98 ehci_reset(ehci);
99
100 /* data structure init */
101 retval = ehci_init(hcd);
102 if (retval)
103 return retval;
104
105 usb_hcd_tdi_set_mode(ehci);
106 ehci_port_power(ehci, 0);
107
108 return retval;
109}
110
111
112/* configure so an HC device and id are always provided
113 * always called with process context; sleeping is OK
114 */
115
116static int usb_hcd_msp_map_regs(struct mspusb_device *dev)
117{
118 struct resource *res;
119 struct platform_device *pdev = &dev->dev;
120 u32 res_len;
121 int retval;
122
123 /* MAB register space */
124 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
125 if (res == NULL)
126 return -ENOMEM;
127 res_len = res->end - res->start + 1;
128 if (!request_mem_region(res->start, res_len, "mab regs"))
129 return -EBUSY;
130
131 dev->mab_regs = ioremap_nocache(res->start, res_len);
132 if (dev->mab_regs == NULL) {
133 retval = -ENOMEM;
134 goto err1;
135 }
136
137 /* MSP USB register space */
138 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
139 if (res == NULL) {
140 retval = -ENOMEM;
141 goto err2;
142 }
143 res_len = res->end - res->start + 1;
144 if (!request_mem_region(res->start, res_len, "usbid regs")) {
145 retval = -EBUSY;
146 goto err2;
147 }
148 dev->usbid_regs = ioremap_nocache(res->start, res_len);
149 if (dev->usbid_regs == NULL) {
150 retval = -ENOMEM;
151 goto err3;
152 }
153
154 return 0;
155err3:
156 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
157 res_len = res->end - res->start + 1;
158 release_mem_region(res->start, res_len);
159err2:
160 iounmap(dev->mab_regs);
161err1:
162 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
163 res_len = res->end - res->start + 1;
164 release_mem_region(res->start, res_len);
165 dev_err(&pdev->dev, "Failed to map non-EHCI regs.\n");
166 return retval;
167}
168
169/**
170 * usb_hcd_msp_probe - initialize PMC MSP-based HCDs
171 * Context: !in_interrupt()
172 *
173 * Allocates basic resources for this USB host controller, and
174 * then invokes the start() method for the HCD associated with it
175 * through the hotplug entry's driver_data.
176 *
177 */
178int usb_hcd_msp_probe(const struct hc_driver *driver,
179 struct platform_device *dev)
180{
181 int retval;
182 struct usb_hcd *hcd;
183 struct resource *res;
184 struct ehci_hcd *ehci ;
185
186 hcd = usb_create_hcd(driver, &dev->dev, "pmcmsp");
187 if (!hcd)
188 return -ENOMEM;
189
190 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
191 if (res == NULL) {
192 pr_debug("No IOMEM resource info for %s.\n", dev->name);
193 retval = -ENOMEM;
194 goto err1;
195 }
196 hcd->rsrc_start = res->start;
197 hcd->rsrc_len = res->end - res->start + 1;
198 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, dev->name)) {
199 retval = -EBUSY;
200 goto err1;
201 }
202 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
203 if (!hcd->regs) {
204 pr_debug("ioremap failed");
205 retval = -ENOMEM;
206 goto err2;
207 }
208
209 res = platform_get_resource(dev, IORESOURCE_IRQ, 0);
210 if (res == NULL) {
211 dev_err(&dev->dev, "No IRQ resource info for %s.\n", dev->name);
212 retval = -ENOMEM;
213 goto err3;
214 }
215
216 /* Map non-EHCI register spaces */
217 retval = usb_hcd_msp_map_regs(to_mspusb_device(dev));
218 if (retval != 0)
219 goto err3;
220
221 ehci = hcd_to_ehci(hcd);
222 ehci->big_endian_mmio = 1;
223 ehci->big_endian_desc = 1;
224
225
226 retval = usb_add_hcd(hcd, res->start, IRQF_SHARED);
227 if (retval == 0)
228 return 0;
229
230 usb_remove_hcd(hcd);
231err3:
232 iounmap(hcd->regs);
233err2:
234 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
235err1:
236 usb_put_hcd(hcd);
237
238 return retval;
239}
240
241
242
243/**
244 * usb_hcd_msp_remove - shutdown processing for PMC MSP-based HCDs
245 * @dev: USB Host Controller being removed
246 * Context: !in_interrupt()
247 *
248 * Reverses the effect of usb_hcd_msp_probe(), first invoking
249 * the HCD's stop() method. It is always called from a thread
250 * context, normally "rmmod", "apmd", or something similar.
251 *
252 * may be called without controller electrically present
253 * may be called with controller, bus, and devices active
254 */
255void usb_hcd_msp_remove(struct usb_hcd *hcd, struct platform_device *dev)
256{
257 usb_remove_hcd(hcd);
258 iounmap(hcd->regs);
259 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
260 usb_put_hcd(hcd);
261}
262
263#ifdef CONFIG_MSP_HAS_DUAL_USB
264/*
265 * Wrapper around the main ehci_irq. Since both USB host controllers are
266 * sharing the same IRQ, need to first determine whether we're the intended
267 * recipient of this interrupt.
268 */
269static irqreturn_t ehci_msp_irq(struct usb_hcd *hcd)
270{
271 u32 int_src;
272 struct device *dev = hcd->self.controller;
273 struct platform_device *pdev;
274 struct mspusb_device *mdev;
275 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
276 /* need to reverse-map a couple of containers to get our device */
277 pdev = to_platform_device(dev);
278 mdev = to_mspusb_device(pdev);
279
280 /* Check to see if this interrupt is for this host controller */
281 int_src = ehci_readl(ehci, &mdev->mab_regs->int_stat);
282 if (int_src & (1 << pdev->id))
283 return ehci_irq(hcd);
284
285 /* Not for this device */
286 return IRQ_NONE;
287}
288#endif /* DUAL_USB */
289
290static const struct hc_driver ehci_msp_hc_driver = {
291 .description = hcd_name,
292 .product_desc = "PMC MSP EHCI",
293 .hcd_priv_size = sizeof(struct ehci_hcd),
294
295 /*
296 * generic hardware linkage
297 */
298#ifdef CONFIG_MSP_HAS_DUAL_USB
299 .irq = ehci_msp_irq,
300#else
301 .irq = ehci_irq,
302#endif
303 .flags = HCD_MEMORY | HCD_USB2,
304
305 /*
306 * basic lifecycle operations
307 */
308 .reset = ehci_msp_setup,
309 .start = ehci_run,
310 .shutdown = ehci_shutdown,
311 .start = ehci_run,
312 .stop = ehci_stop,
313
314 /*
315 * managing i/o requests and associated device resources
316 */
317 .urb_enqueue = ehci_urb_enqueue,
318 .urb_dequeue = ehci_urb_dequeue,
319 .endpoint_disable = ehci_endpoint_disable,
320 .endpoint_reset = ehci_endpoint_reset,
321
322 /*
323 * scheduling support
324 */
325 .get_frame_number = ehci_get_frame,
326
327 /*
328 * root hub support
329 */
330 .hub_status_data = ehci_hub_status_data,
331 .hub_control = ehci_hub_control,
332 .bus_suspend = ehci_bus_suspend,
333 .bus_resume = ehci_bus_resume,
334 .relinquish_port = ehci_relinquish_port,
335 .port_handed_over = ehci_port_handed_over,
336
337 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
338};
339
340static int ehci_hcd_msp_drv_probe(struct platform_device *pdev)
341{
342 int ret;
343
344 pr_debug("In ehci_hcd_msp_drv_probe");
345
346 if (usb_disabled())
347 return -ENODEV;
348
349 gpio_request(MSP_PIN_USB0_HOST_DEV, "USB0_HOST_DEV_GPIO");
350#ifdef CONFIG_MSP_HAS_DUAL_USB
351 gpio_request(MSP_PIN_USB1_HOST_DEV, "USB1_HOST_DEV_GPIO");
352#endif
353
354 ret = usb_hcd_msp_probe(&ehci_msp_hc_driver, pdev);
355
356 return ret;
357}
358
359static int ehci_hcd_msp_drv_remove(struct platform_device *pdev)
360{
361 struct usb_hcd *hcd = platform_get_drvdata(pdev);
362
363 usb_hcd_msp_remove(hcd, pdev);
364
365 /* free TWI GPIO USB_HOST_DEV pin */
366 gpio_free(MSP_PIN_USB0_HOST_DEV);
367#ifdef CONFIG_MSP_HAS_DUAL_USB
368 gpio_free(MSP_PIN_USB1_HOST_DEV);
369#endif
370
371 return 0;
372}
373
374MODULE_ALIAS("pmcmsp-ehci");
375
376static struct platform_driver ehci_hcd_msp_driver = {
377 .probe = ehci_hcd_msp_drv_probe,
378 .remove = ehci_hcd_msp_drv_remove,
379 .driver = {
380 .name = "pmcmsp-ehci",
381 .owner = THIS_MODULE,
382 },
383};
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 233c288e3f93..fe99895fb098 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1107,22 +1107,24 @@ submit_async (
1107 struct list_head *qtd_list, 1107 struct list_head *qtd_list,
1108 gfp_t mem_flags 1108 gfp_t mem_flags
1109) { 1109) {
1110 struct ehci_qtd *qtd;
1111 int epnum; 1110 int epnum;
1112 unsigned long flags; 1111 unsigned long flags;
1113 struct ehci_qh *qh = NULL; 1112 struct ehci_qh *qh = NULL;
1114 int rc; 1113 int rc;
1115 1114
1116 qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);
1117 epnum = urb->ep->desc.bEndpointAddress; 1115 epnum = urb->ep->desc.bEndpointAddress;
1118 1116
1119#ifdef EHCI_URB_TRACE 1117#ifdef EHCI_URB_TRACE
1120 ehci_dbg (ehci, 1118 {
1121 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n", 1119 struct ehci_qtd *qtd;
1122 __func__, urb->dev->devpath, urb, 1120 qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list);
1123 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", 1121 ehci_dbg(ehci,
1124 urb->transfer_buffer_length, 1122 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
1125 qtd, urb->ep->hcpriv); 1123 __func__, urb->dev->devpath, urb,
1124 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out",
1125 urb->transfer_buffer_length,
1126 qtd, urb->ep->hcpriv);
1127 }
1126#endif 1128#endif
1127 1129
1128 spin_lock_irqsave (&ehci->lock, flags); 1130 spin_lock_irqsave (&ehci->lock, flags);
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index aa46f57f9ec8..1543c838b3d1 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1048,8 +1048,6 @@ iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream)
1048 * not like a QH -- no persistent state (toggle, halt) 1048 * not like a QH -- no persistent state (toggle, halt)
1049 */ 1049 */
1050 if (stream->refcount == 1) { 1050 if (stream->refcount == 1) {
1051 int is_in;
1052
1053 // BUG_ON (!list_empty(&stream->td_list)); 1051 // BUG_ON (!list_empty(&stream->td_list));
1054 1052
1055 while (!list_empty (&stream->free_list)) { 1053 while (!list_empty (&stream->free_list)) {
@@ -1076,7 +1074,6 @@ iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream)
1076 } 1074 }
1077 } 1075 }
1078 1076
1079 is_in = (stream->bEndpointAddress & USB_DIR_IN) ? 0x10 : 0;
1080 stream->bEndpointAddress &= 0x0f; 1077 stream->bEndpointAddress &= 0x0f;
1081 if (stream->ep) 1078 if (stream->ep)
1082 stream->ep->hcpriv = NULL; 1079 stream->ep->hcpriv = NULL;
@@ -1590,63 +1587,6 @@ itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd)
1590 *hw_p = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD); 1587 *hw_p = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD);
1591} 1588}
1592 1589
1593#define AB_REG_BAR_LOW 0xe0
1594#define AB_REG_BAR_HIGH 0xe1
1595#define AB_INDX(addr) ((addr) + 0x00)
1596#define AB_DATA(addr) ((addr) + 0x04)
1597#define NB_PCIE_INDX_ADDR 0xe0
1598#define NB_PCIE_INDX_DATA 0xe4
1599#define NB_PIF0_PWRDOWN_0 0x01100012
1600#define NB_PIF0_PWRDOWN_1 0x01100013
1601
1602static void ehci_quirk_amd_L1(struct ehci_hcd *ehci, int disable)
1603{
1604 u32 addr, addr_low, addr_high, val;
1605
1606 outb_p(AB_REG_BAR_LOW, 0xcd6);
1607 addr_low = inb_p(0xcd7);
1608 outb_p(AB_REG_BAR_HIGH, 0xcd6);
1609 addr_high = inb_p(0xcd7);
1610 addr = addr_high << 8 | addr_low;
1611 outl_p(0x30, AB_INDX(addr));
1612 outl_p(0x40, AB_DATA(addr));
1613 outl_p(0x34, AB_INDX(addr));
1614 val = inl_p(AB_DATA(addr));
1615
1616 if (disable) {
1617 val &= ~0x8;
1618 val |= (1 << 4) | (1 << 9);
1619 } else {
1620 val |= 0x8;
1621 val &= ~((1 << 4) | (1 << 9));
1622 }
1623 outl_p(val, AB_DATA(addr));
1624
1625 if (amd_nb_dev) {
1626 addr = NB_PIF0_PWRDOWN_0;
1627 pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_ADDR, addr);
1628 pci_read_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, &val);
1629 if (disable)
1630 val &= ~(0x3f << 7);
1631 else
1632 val |= 0x3f << 7;
1633
1634 pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, val);
1635
1636 addr = NB_PIF0_PWRDOWN_1;
1637 pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_ADDR, addr);
1638 pci_read_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, &val);
1639 if (disable)
1640 val &= ~(0x3f << 7);
1641 else
1642 val |= 0x3f << 7;
1643
1644 pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, val);
1645 }
1646
1647 return;
1648}
1649
1650/* fit urb's itds into the selected schedule slot; activate as needed */ 1590/* fit urb's itds into the selected schedule slot; activate as needed */
1651static int 1591static int
1652itd_link_urb ( 1592itd_link_urb (
@@ -1675,8 +1615,8 @@ itd_link_urb (
1675 } 1615 }
1676 1616
1677 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { 1617 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
1678 if (ehci->amd_l1_fix == 1) 1618 if (ehci->amd_pll_fix == 1)
1679 ehci_quirk_amd_L1(ehci, 1); 1619 usb_amd_quirk_pll_disable();
1680 } 1620 }
1681 1621
1682 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 1622 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
@@ -1804,8 +1744,8 @@ itd_complete (
1804 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; 1744 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
1805 1745
1806 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { 1746 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
1807 if (ehci->amd_l1_fix == 1) 1747 if (ehci->amd_pll_fix == 1)
1808 ehci_quirk_amd_L1(ehci, 0); 1748 usb_amd_quirk_pll_enable();
1809 } 1749 }
1810 1750
1811 if (unlikely(list_is_singular(&stream->td_list))) { 1751 if (unlikely(list_is_singular(&stream->td_list))) {
@@ -2095,8 +2035,8 @@ sitd_link_urb (
2095 } 2035 }
2096 2036
2097 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { 2037 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
2098 if (ehci->amd_l1_fix == 1) 2038 if (ehci->amd_pll_fix == 1)
2099 ehci_quirk_amd_L1(ehci, 1); 2039 usb_amd_quirk_pll_disable();
2100 } 2040 }
2101 2041
2102 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 2042 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
@@ -2200,8 +2140,8 @@ sitd_complete (
2200 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; 2140 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
2201 2141
2202 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { 2142 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
2203 if (ehci->amd_l1_fix == 1) 2143 if (ehci->amd_pll_fix == 1)
2204 ehci_quirk_amd_L1(ehci, 0); 2144 usb_amd_quirk_pll_enable();
2205 } 2145 }
2206 2146
2207 if (list_is_singular(&stream->td_list)) { 2147 if (list_is_singular(&stream->td_list)) {
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
new file mode 100644
index 000000000000..a516af28c29b
--- /dev/null
+++ b/drivers/usb/host/ehci-tegra.c
@@ -0,0 +1,715 @@
1/*
2 * EHCI-compliant USB host controller driver for NVIDIA Tegra SoCs
3 *
4 * Copyright (C) 2010 Google, Inc.
5 * Copyright (C) 2009 NVIDIA Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 */
18
19#include <linux/clk.h>
20#include <linux/platform_device.h>
21#include <linux/platform_data/tegra_usb.h>
22#include <linux/irq.h>
23#include <linux/usb/otg.h>
24#include <mach/usb_phy.h>
25
26#define TEGRA_USB_DMA_ALIGN 32
27
28struct tegra_ehci_hcd {
29 struct ehci_hcd *ehci;
30 struct tegra_usb_phy *phy;
31 struct clk *clk;
32 struct clk *emc_clk;
33 struct otg_transceiver *transceiver;
34 int host_resumed;
35 int bus_suspended;
36 int port_resuming;
37 int power_down_on_bus_suspend;
38 enum tegra_usb_phy_port_speed port_speed;
39};
40
41static void tegra_ehci_power_up(struct usb_hcd *hcd)
42{
43 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
44
45 clk_enable(tegra->emc_clk);
46 clk_enable(tegra->clk);
47 tegra_usb_phy_power_on(tegra->phy);
48 tegra->host_resumed = 1;
49}
50
51static void tegra_ehci_power_down(struct usb_hcd *hcd)
52{
53 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
54
55 tegra->host_resumed = 0;
56 tegra_usb_phy_power_off(tegra->phy);
57 clk_disable(tegra->clk);
58 clk_disable(tegra->emc_clk);
59}
60
61static int tegra_ehci_hub_control(
62 struct usb_hcd *hcd,
63 u16 typeReq,
64 u16 wValue,
65 u16 wIndex,
66 char *buf,
67 u16 wLength
68)
69{
70 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
71 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
72 u32 __iomem *status_reg;
73 u32 temp;
74 unsigned long flags;
75 int retval = 0;
76
77 status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1];
78
79 spin_lock_irqsave(&ehci->lock, flags);
80
81 /*
82 * In ehci_hub_control() for USB_PORT_FEAT_ENABLE clears the other bits
83 * that are write on clear, by writing back the register read value, so
84 * USB_PORT_FEAT_ENABLE is handled by masking the set on clear bits
85 */
86 if (typeReq == ClearPortFeature && wValue == USB_PORT_FEAT_ENABLE) {
87 temp = ehci_readl(ehci, status_reg) & ~PORT_RWC_BITS;
88 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
89 goto done;
90 }
91
92 else if (typeReq == GetPortStatus) {
93 temp = ehci_readl(ehci, status_reg);
94 if (tegra->port_resuming && !(temp & PORT_SUSPEND)) {
95 /* Resume completed, re-enable disconnect detection */
96 tegra->port_resuming = 0;
97 tegra_usb_phy_postresume(tegra->phy);
98 }
99 }
100
101 else if (typeReq == SetPortFeature && wValue == USB_PORT_FEAT_SUSPEND) {
102 temp = ehci_readl(ehci, status_reg);
103 if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) != 0) {
104 retval = -EPIPE;
105 goto done;
106 }
107
108 temp &= ~PORT_WKCONN_E;
109 temp |= PORT_WKDISC_E | PORT_WKOC_E;
110 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
111
112 /*
113 * If a transaction is in progress, there may be a delay in
114 * suspending the port. Poll until the port is suspended.
115 */
116 if (handshake(ehci, status_reg, PORT_SUSPEND,
117 PORT_SUSPEND, 5000))
118 pr_err("%s: timeout waiting for SUSPEND\n", __func__);
119
120 set_bit((wIndex & 0xff) - 1, &ehci->suspended_ports);
121 goto done;
122 }
123
124 /*
125 * Tegra host controller will time the resume operation to clear the bit
126 * when the port control state switches to HS or FS Idle. This behavior
127 * is different from EHCI where the host controller driver is required
128 * to set this bit to a zero after the resume duration is timed in the
129 * driver.
130 */
131 else if (typeReq == ClearPortFeature &&
132 wValue == USB_PORT_FEAT_SUSPEND) {
133 temp = ehci_readl(ehci, status_reg);
134 if ((temp & PORT_RESET) || !(temp & PORT_PE)) {
135 retval = -EPIPE;
136 goto done;
137 }
138
139 if (!(temp & PORT_SUSPEND))
140 goto done;
141
142 /* Disable disconnect detection during port resume */
143 tegra_usb_phy_preresume(tegra->phy);
144
145 ehci->reset_done[wIndex-1] = jiffies + msecs_to_jiffies(25);
146
147 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
148 /* start resume signalling */
149 ehci_writel(ehci, temp | PORT_RESUME, status_reg);
150
151 spin_unlock_irqrestore(&ehci->lock, flags);
152 msleep(20);
153 spin_lock_irqsave(&ehci->lock, flags);
154
155 /* Poll until the controller clears RESUME and SUSPEND */
156 if (handshake(ehci, status_reg, PORT_RESUME, 0, 2000))
157 pr_err("%s: timeout waiting for RESUME\n", __func__);
158 if (handshake(ehci, status_reg, PORT_SUSPEND, 0, 2000))
159 pr_err("%s: timeout waiting for SUSPEND\n", __func__);
160
161 ehci->reset_done[wIndex-1] = 0;
162
163 tegra->port_resuming = 1;
164 goto done;
165 }
166
167 spin_unlock_irqrestore(&ehci->lock, flags);
168
169 /* Handle the hub control events here */
170 return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
171done:
172 spin_unlock_irqrestore(&ehci->lock, flags);
173 return retval;
174}
175
176static void tegra_ehci_restart(struct usb_hcd *hcd)
177{
178 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
179
180 ehci_reset(ehci);
181
182 /* setup the frame list and Async q heads */
183 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
184 ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next);
185 /* setup the command register and set the controller in RUN mode */
186 ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
187 ehci->command |= CMD_RUN;
188 ehci_writel(ehci, ehci->command, &ehci->regs->command);
189
190 down_write(&ehci_cf_port_reset_rwsem);
191 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
192 /* flush posted writes */
193 ehci_readl(ehci, &ehci->regs->command);
194 up_write(&ehci_cf_port_reset_rwsem);
195}
196
197static int tegra_usb_suspend(struct usb_hcd *hcd)
198{
199 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
200 struct ehci_regs __iomem *hw = tegra->ehci->regs;
201 unsigned long flags;
202
203 spin_lock_irqsave(&tegra->ehci->lock, flags);
204
205 tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3;
206 ehci_halt(tegra->ehci);
207 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
208
209 spin_unlock_irqrestore(&tegra->ehci->lock, flags);
210
211 tegra_ehci_power_down(hcd);
212 return 0;
213}
214
215static int tegra_usb_resume(struct usb_hcd *hcd)
216{
217 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
218 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
219 struct ehci_regs __iomem *hw = ehci->regs;
220 unsigned long val;
221
222 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
223 tegra_ehci_power_up(hcd);
224
225 if (tegra->port_speed > TEGRA_USB_PHY_PORT_SPEED_HIGH) {
226 /* Wait for the phy to detect new devices
227 * before we restart the controller */
228 msleep(10);
229 goto restart;
230 }
231
232 /* Force the phy to keep data lines in suspend state */
233 tegra_ehci_phy_restore_start(tegra->phy, tegra->port_speed);
234
235 /* Enable host mode */
236 tdi_reset(ehci);
237
238 /* Enable Port Power */
239 val = readl(&hw->port_status[0]);
240 val |= PORT_POWER;
241 writel(val, &hw->port_status[0]);
242 udelay(10);
243
244 /* Check if the phy resume from LP0. When the phy resume from LP0
245 * USB register will be reset. */
246 if (!readl(&hw->async_next)) {
247 /* Program the field PTC based on the saved speed mode */
248 val = readl(&hw->port_status[0]);
249 val &= ~PORT_TEST(~0);
250 if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_HIGH)
251 val |= PORT_TEST_FORCE;
252 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_FULL)
253 val |= PORT_TEST(6);
254 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
255 val |= PORT_TEST(7);
256 writel(val, &hw->port_status[0]);
257 udelay(10);
258
259 /* Disable test mode by setting PTC field to NORMAL_OP */
260 val = readl(&hw->port_status[0]);
261 val &= ~PORT_TEST(~0);
262 writel(val, &hw->port_status[0]);
263 udelay(10);
264 }
265
266 /* Poll until CCS is enabled */
267 if (handshake(ehci, &hw->port_status[0], PORT_CONNECT,
268 PORT_CONNECT, 2000)) {
269 pr_err("%s: timeout waiting for PORT_CONNECT\n", __func__);
270 goto restart;
271 }
272
273 /* Poll until PE is enabled */
274 if (handshake(ehci, &hw->port_status[0], PORT_PE,
275 PORT_PE, 2000)) {
276 pr_err("%s: timeout waiting for USB_PORTSC1_PE\n", __func__);
277 goto restart;
278 }
279
280 /* Clear the PCI status, to avoid an interrupt taken upon resume */
281 val = readl(&hw->status);
282 val |= STS_PCD;
283 writel(val, &hw->status);
284
285 /* Put controller in suspend mode by writing 1 to SUSP bit of PORTSC */
286 val = readl(&hw->port_status[0]);
287 if ((val & PORT_POWER) && (val & PORT_PE)) {
288 val |= PORT_SUSPEND;
289 writel(val, &hw->port_status[0]);
290
291 /* Wait until port suspend completes */
292 if (handshake(ehci, &hw->port_status[0], PORT_SUSPEND,
293 PORT_SUSPEND, 1000)) {
294 pr_err("%s: timeout waiting for PORT_SUSPEND\n",
295 __func__);
296 goto restart;
297 }
298 }
299
300 tegra_ehci_phy_restore_end(tegra->phy);
301 return 0;
302
303restart:
304 if (tegra->port_speed <= TEGRA_USB_PHY_PORT_SPEED_HIGH)
305 tegra_ehci_phy_restore_end(tegra->phy);
306
307 tegra_ehci_restart(hcd);
308 return 0;
309}
310
311static void tegra_ehci_shutdown(struct usb_hcd *hcd)
312{
313 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
314
315 /* ehci_shutdown touches the USB controller registers, make sure
316 * controller has clocks to it */
317 if (!tegra->host_resumed)
318 tegra_ehci_power_up(hcd);
319
320 ehci_shutdown(hcd);
321}
322
323static int tegra_ehci_setup(struct usb_hcd *hcd)
324{
325 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
326 int retval;
327
328 /* EHCI registers start at offset 0x100 */
329 ehci->caps = hcd->regs + 0x100;
330 ehci->regs = hcd->regs + 0x100 +
331 HC_LENGTH(readl(&ehci->caps->hc_capbase));
332
333 dbg_hcs_params(ehci, "reset");
334 dbg_hcc_params(ehci, "reset");
335
336 /* cache this readonly data; minimize chip reads */
337 ehci->hcs_params = readl(&ehci->caps->hcs_params);
338
339 /* switch to host mode */
340 hcd->has_tt = 1;
341 ehci_reset(ehci);
342
343 retval = ehci_halt(ehci);
344 if (retval)
345 return retval;
346
347 /* data structure init */
348 retval = ehci_init(hcd);
349 if (retval)
350 return retval;
351
352 ehci->sbrn = 0x20;
353
354 ehci_port_power(ehci, 1);
355 return retval;
356}
357
358#ifdef CONFIG_PM
359static int tegra_ehci_bus_suspend(struct usb_hcd *hcd)
360{
361 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
362 int error_status = 0;
363
364 error_status = ehci_bus_suspend(hcd);
365 if (!error_status && tegra->power_down_on_bus_suspend) {
366 tegra_usb_suspend(hcd);
367 tegra->bus_suspended = 1;
368 }
369
370 return error_status;
371}
372
373static int tegra_ehci_bus_resume(struct usb_hcd *hcd)
374{
375 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
376
377 if (tegra->bus_suspended && tegra->power_down_on_bus_suspend) {
378 tegra_usb_resume(hcd);
379 tegra->bus_suspended = 0;
380 }
381
382 tegra_usb_phy_preresume(tegra->phy);
383 tegra->port_resuming = 1;
384 return ehci_bus_resume(hcd);
385}
386#endif
387
388struct temp_buffer {
389 void *kmalloc_ptr;
390 void *old_xfer_buffer;
391 u8 data[0];
392};
393
394static void free_temp_buffer(struct urb *urb)
395{
396 enum dma_data_direction dir;
397 struct temp_buffer *temp;
398
399 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
400 return;
401
402 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
403
404 temp = container_of(urb->transfer_buffer, struct temp_buffer,
405 data);
406
407 if (dir == DMA_FROM_DEVICE)
408 memcpy(temp->old_xfer_buffer, temp->data,
409 urb->transfer_buffer_length);
410 urb->transfer_buffer = temp->old_xfer_buffer;
411 kfree(temp->kmalloc_ptr);
412
413 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
414}
415
416static int alloc_temp_buffer(struct urb *urb, gfp_t mem_flags)
417{
418 enum dma_data_direction dir;
419 struct temp_buffer *temp, *kmalloc_ptr;
420 size_t kmalloc_size;
421
422 if (urb->num_sgs || urb->sg ||
423 urb->transfer_buffer_length == 0 ||
424 !((uintptr_t)urb->transfer_buffer & (TEGRA_USB_DMA_ALIGN - 1)))
425 return 0;
426
427 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
428
429 /* Allocate a buffer with enough padding for alignment */
430 kmalloc_size = urb->transfer_buffer_length +
431 sizeof(struct temp_buffer) + TEGRA_USB_DMA_ALIGN - 1;
432
433 kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
434 if (!kmalloc_ptr)
435 return -ENOMEM;
436
437 /* Position our struct temp_buffer such that data is aligned */
438 temp = PTR_ALIGN(kmalloc_ptr + 1, TEGRA_USB_DMA_ALIGN) - 1;
439
440 temp->kmalloc_ptr = kmalloc_ptr;
441 temp->old_xfer_buffer = urb->transfer_buffer;
442 if (dir == DMA_TO_DEVICE)
443 memcpy(temp->data, urb->transfer_buffer,
444 urb->transfer_buffer_length);
445 urb->transfer_buffer = temp->data;
446
447 urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER;
448
449 return 0;
450}
451
452static int tegra_ehci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
453 gfp_t mem_flags)
454{
455 int ret;
456
457 ret = alloc_temp_buffer(urb, mem_flags);
458 if (ret)
459 return ret;
460
461 ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
462 if (ret)
463 free_temp_buffer(urb);
464
465 return ret;
466}
467
468static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
469{
470 usb_hcd_unmap_urb_for_dma(hcd, urb);
471 free_temp_buffer(urb);
472}
473
474static const struct hc_driver tegra_ehci_hc_driver = {
475 .description = hcd_name,
476 .product_desc = "Tegra EHCI Host Controller",
477 .hcd_priv_size = sizeof(struct ehci_hcd),
478
479 .flags = HCD_USB2 | HCD_MEMORY,
480
481 .reset = tegra_ehci_setup,
482 .irq = ehci_irq,
483
484 .start = ehci_run,
485 .stop = ehci_stop,
486 .shutdown = tegra_ehci_shutdown,
487 .urb_enqueue = ehci_urb_enqueue,
488 .urb_dequeue = ehci_urb_dequeue,
489 .map_urb_for_dma = tegra_ehci_map_urb_for_dma,
490 .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma,
491 .endpoint_disable = ehci_endpoint_disable,
492 .endpoint_reset = ehci_endpoint_reset,
493 .get_frame_number = ehci_get_frame,
494 .hub_status_data = ehci_hub_status_data,
495 .hub_control = tegra_ehci_hub_control,
496 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
497#ifdef CONFIG_PM
498 .bus_suspend = tegra_ehci_bus_suspend,
499 .bus_resume = tegra_ehci_bus_resume,
500#endif
501 .relinquish_port = ehci_relinquish_port,
502 .port_handed_over = ehci_port_handed_over,
503};
504
505static int tegra_ehci_probe(struct platform_device *pdev)
506{
507 struct resource *res;
508 struct usb_hcd *hcd;
509 struct tegra_ehci_hcd *tegra;
510 struct tegra_ehci_platform_data *pdata;
511 int err = 0;
512 int irq;
513 int instance = pdev->id;
514
515 pdata = pdev->dev.platform_data;
516 if (!pdata) {
517 dev_err(&pdev->dev, "Platform data missing\n");
518 return -EINVAL;
519 }
520
521 tegra = kzalloc(sizeof(struct tegra_ehci_hcd), GFP_KERNEL);
522 if (!tegra)
523 return -ENOMEM;
524
525 hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev,
526 dev_name(&pdev->dev));
527 if (!hcd) {
528 dev_err(&pdev->dev, "Unable to create HCD\n");
529 err = -ENOMEM;
530 goto fail_hcd;
531 }
532
533 platform_set_drvdata(pdev, tegra);
534
535 tegra->clk = clk_get(&pdev->dev, NULL);
536 if (IS_ERR(tegra->clk)) {
537 dev_err(&pdev->dev, "Can't get ehci clock\n");
538 err = PTR_ERR(tegra->clk);
539 goto fail_clk;
540 }
541
542 err = clk_enable(tegra->clk);
543 if (err)
544 goto fail_clken;
545
546 tegra->emc_clk = clk_get(&pdev->dev, "emc");
547 if (IS_ERR(tegra->emc_clk)) {
548 dev_err(&pdev->dev, "Can't get emc clock\n");
549 err = PTR_ERR(tegra->emc_clk);
550 goto fail_emc_clk;
551 }
552
553 clk_enable(tegra->emc_clk);
554 clk_set_rate(tegra->emc_clk, 400000000);
555
556 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
557 if (!res) {
558 dev_err(&pdev->dev, "Failed to get I/O memory\n");
559 err = -ENXIO;
560 goto fail_io;
561 }
562 hcd->rsrc_start = res->start;
563 hcd->rsrc_len = resource_size(res);
564 hcd->regs = ioremap(res->start, resource_size(res));
565 if (!hcd->regs) {
566 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
567 err = -ENOMEM;
568 goto fail_io;
569 }
570
571 tegra->phy = tegra_usb_phy_open(instance, hcd->regs, pdata->phy_config,
572 TEGRA_USB_PHY_MODE_HOST);
573 if (IS_ERR(tegra->phy)) {
574 dev_err(&pdev->dev, "Failed to open USB phy\n");
575 err = -ENXIO;
576 goto fail_phy;
577 }
578
579 err = tegra_usb_phy_power_on(tegra->phy);
580 if (err) {
581 dev_err(&pdev->dev, "Failed to power on the phy\n");
582 goto fail;
583 }
584
585 tegra->host_resumed = 1;
586 tegra->power_down_on_bus_suspend = pdata->power_down_on_bus_suspend;
587 tegra->ehci = hcd_to_ehci(hcd);
588
589 irq = platform_get_irq(pdev, 0);
590 if (!irq) {
591 dev_err(&pdev->dev, "Failed to get IRQ\n");
592 err = -ENODEV;
593 goto fail;
594 }
595 set_irq_flags(irq, IRQF_VALID);
596
597#ifdef CONFIG_USB_OTG_UTILS
598 if (pdata->operating_mode == TEGRA_USB_OTG) {
599 tegra->transceiver = otg_get_transceiver();
600 if (tegra->transceiver)
601 otg_set_host(tegra->transceiver, &hcd->self);
602 }
603#endif
604
605 err = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
606 if (err) {
607 dev_err(&pdev->dev, "Failed to add USB HCD\n");
608 goto fail;
609 }
610
611 return err;
612
613fail:
614#ifdef CONFIG_USB_OTG_UTILS
615 if (tegra->transceiver) {
616 otg_set_host(tegra->transceiver, NULL);
617 otg_put_transceiver(tegra->transceiver);
618 }
619#endif
620 tegra_usb_phy_close(tegra->phy);
621fail_phy:
622 iounmap(hcd->regs);
623fail_io:
624 clk_disable(tegra->emc_clk);
625 clk_put(tegra->emc_clk);
626fail_emc_clk:
627 clk_disable(tegra->clk);
628fail_clken:
629 clk_put(tegra->clk);
630fail_clk:
631 usb_put_hcd(hcd);
632fail_hcd:
633 kfree(tegra);
634 return err;
635}
636
637#ifdef CONFIG_PM
638static int tegra_ehci_resume(struct platform_device *pdev)
639{
640 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
641 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
642
643 if (tegra->bus_suspended)
644 return 0;
645
646 return tegra_usb_resume(hcd);
647}
648
649static int tegra_ehci_suspend(struct platform_device *pdev, pm_message_t state)
650{
651 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
652 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
653
654 if (tegra->bus_suspended)
655 return 0;
656
657 if (time_before(jiffies, tegra->ehci->next_statechange))
658 msleep(10);
659
660 return tegra_usb_suspend(hcd);
661}
662#endif
663
664static int tegra_ehci_remove(struct platform_device *pdev)
665{
666 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
667 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
668
669 if (tegra == NULL || hcd == NULL)
670 return -EINVAL;
671
672#ifdef CONFIG_USB_OTG_UTILS
673 if (tegra->transceiver) {
674 otg_set_host(tegra->transceiver, NULL);
675 otg_put_transceiver(tegra->transceiver);
676 }
677#endif
678
679 usb_remove_hcd(hcd);
680 usb_put_hcd(hcd);
681
682 tegra_usb_phy_close(tegra->phy);
683 iounmap(hcd->regs);
684
685 clk_disable(tegra->clk);
686 clk_put(tegra->clk);
687
688 clk_disable(tegra->emc_clk);
689 clk_put(tegra->emc_clk);
690
691 kfree(tegra);
692 return 0;
693}
694
695static void tegra_ehci_hcd_shutdown(struct platform_device *pdev)
696{
697 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
698 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
699
700 if (hcd->driver->shutdown)
701 hcd->driver->shutdown(hcd);
702}
703
704static struct platform_driver tegra_ehci_driver = {
705 .probe = tegra_ehci_probe,
706 .remove = tegra_ehci_remove,
707#ifdef CONFIG_PM
708 .suspend = tegra_ehci_suspend,
709 .resume = tegra_ehci_resume,
710#endif
711 .shutdown = tegra_ehci_hcd_shutdown,
712 .driver = {
713 .name = "tegra-ehci",
714 }
715};
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 799ac16a54b4..f86d3fa20214 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -131,7 +131,7 @@ struct ehci_hcd { /* one per controller */
131 unsigned has_amcc_usb23:1; 131 unsigned has_amcc_usb23:1;
132 unsigned need_io_watchdog:1; 132 unsigned need_io_watchdog:1;
133 unsigned broken_periodic:1; 133 unsigned broken_periodic:1;
134 unsigned amd_l1_fix:1; 134 unsigned amd_pll_fix:1;
135 unsigned fs_i_thresh:1; /* Intel iso scheduling */ 135 unsigned fs_i_thresh:1; /* Intel iso scheduling */
136 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ 136 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/
137 137
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index f90d003f2302..2562e92e3178 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -927,7 +927,8 @@ static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb)
927 if (state == US_CTRL_SETUP) { 927 if (state == US_CTRL_SETUP) {
928 dir = TD_DIR_SETUP; 928 dir = TD_DIR_SETUP;
929 if (unsuitable_for_dma(urb->setup_dma)) 929 if (unsuitable_for_dma(urb->setup_dma))
930 unmap_urb_setup_for_dma(imx21->hcd, urb); 930 usb_hcd_unmap_urb_setup_for_dma(imx21->hcd,
931 urb);
931 etd->dma_handle = urb->setup_dma; 932 etd->dma_handle = urb->setup_dma;
932 etd->cpu_buffer = urb->setup_packet; 933 etd->cpu_buffer = urb->setup_packet;
933 bufround = 0; 934 bufround = 0;
@@ -943,7 +944,7 @@ static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb)
943 dir = usb_pipeout(pipe) ? TD_DIR_OUT : TD_DIR_IN; 944 dir = usb_pipeout(pipe) ? TD_DIR_OUT : TD_DIR_IN;
944 bufround = (dir == TD_DIR_IN) ? 1 : 0; 945 bufround = (dir == TD_DIR_IN) ? 1 : 0;
945 if (unsuitable_for_dma(urb->transfer_dma)) 946 if (unsuitable_for_dma(urb->transfer_dma))
946 unmap_urb_for_dma(imx21->hcd, urb); 947 usb_hcd_unmap_urb_for_dma(imx21->hcd, urb);
947 948
948 etd->dma_handle = urb->transfer_dma; 949 etd->dma_handle = urb->transfer_dma;
949 etd->cpu_buffer = urb->transfer_buffer; 950 etd->cpu_buffer = urb->transfer_buffer;
@@ -1471,8 +1472,8 @@ static int get_hub_descriptor(struct usb_hcd *hcd,
1471 0x0010 | /* No over current protection */ 1472 0x0010 | /* No over current protection */
1472 0); 1473 0);
1473 1474
1474 desc->bitmap[0] = 1 << 1; 1475 desc->u.hs.DeviceRemovable[0] = 1 << 1;
1475 desc->bitmap[1] = ~0; 1476 desc->u.hs.DeviceRemovable[1] = ~0;
1476 return 0; 1477 return 0;
1477} 1478}
1478 1479
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 0da7fc05f453..c0e22f26da19 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -951,9 +951,9 @@ static void isp116x_hub_descriptor(struct isp116x *isp116x,
951 /* Power switching, device type, overcurrent. */ 951 /* Power switching, device type, overcurrent. */
952 desc->wHubCharacteristics = cpu_to_le16((u16) ((reg >> 8) & 0x1f)); 952 desc->wHubCharacteristics = cpu_to_le16((u16) ((reg >> 8) & 0x1f));
953 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff); 953 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
954 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ 954 /* ports removable, and legacy PortPwrCtrlMask */
955 desc->bitmap[0] = 0; 955 desc->u.hs.DeviceRemovable[0] = 0;
956 desc->bitmap[1] = ~0; 956 desc->u.hs.DeviceRemovable[1] = ~0;
957} 957}
958 958
959/* Perform reset of a given port. 959/* Perform reset of a given port.
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index 43a39eb56cc6..662cd002adfc 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -226,7 +226,6 @@ static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
226 226
227static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1362_ep *ep) 227static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1362_ep *ep)
228{ 228{
229 int index = ep->ptd_index;
230 int last = ep->ptd_index + ep->num_ptds; 229 int last = ep->ptd_index + ep->num_ptds;
231 230
232 if (last > epq->buf_count) 231 if (last > epq->buf_count)
@@ -236,10 +235,8 @@ static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1
236 epq->buf_map, epq->skip_map); 235 epq->buf_map, epq->skip_map);
237 BUG_ON(last > epq->buf_count); 236 BUG_ON(last > epq->buf_count);
238 237
239 for (; index < last; index++) { 238 bitmap_clear(&epq->buf_map, ep->ptd_index, ep->num_ptds);
240 __clear_bit(index, &epq->buf_map); 239 bitmap_set(&epq->skip_map, ep->ptd_index, ep->num_ptds);
241 __set_bit(index, &epq->skip_map);
242 }
243 epq->buf_avail += ep->num_ptds; 240 epq->buf_avail += ep->num_ptds;
244 epq->ptd_count--; 241 epq->ptd_count--;
245 242
@@ -1555,9 +1552,9 @@ static void isp1362_hub_descriptor(struct isp1362_hcd *isp1362_hcd,
1555 desc->wHubCharacteristics = cpu_to_le16((reg >> 8) & 0x1f); 1552 desc->wHubCharacteristics = cpu_to_le16((reg >> 8) & 0x1f);
1556 DBG(0, "%s: hubcharacteristics = %02x\n", __func__, cpu_to_le16((reg >> 8) & 0x1f)); 1553 DBG(0, "%s: hubcharacteristics = %02x\n", __func__, cpu_to_le16((reg >> 8) & 0x1f));
1557 desc->bPwrOn2PwrGood = (reg >> 24) & 0xff; 1554 desc->bPwrOn2PwrGood = (reg >> 24) & 0xff;
1558 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ 1555 /* ports removable, and legacy PortPwrCtrlMask */
1559 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1; 1556 desc->u.hs.DeviceRemovable[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
1560 desc->bitmap[1] = ~0; 1557 desc->u.hs.DeviceRemovable[1] = ~0;
1561 1558
1562 DBG(3, "%s: exit\n", __func__); 1559 DBG(3, "%s: exit\n", __func__);
1563} 1560}
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index bdba8c5d844a..f50e84ac570a 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -33,6 +33,7 @@ struct isp1760_hcd {
33 struct inter_packet_info atl_ints[32]; 33 struct inter_packet_info atl_ints[32];
34 struct inter_packet_info int_ints[32]; 34 struct inter_packet_info int_ints[32];
35 struct memory_chunk memory_pool[BLOCKS]; 35 struct memory_chunk memory_pool[BLOCKS];
36 u32 atl_queued;
36 37
37 /* periodic schedule support */ 38 /* periodic schedule support */
38#define DEFAULT_I_TDPS 1024 39#define DEFAULT_I_TDPS 1024
@@ -47,10 +48,6 @@ static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd)
47{ 48{
48 return (struct isp1760_hcd *) (hcd->hcd_priv); 49 return (struct isp1760_hcd *) (hcd->hcd_priv);
49} 50}
50static inline struct usb_hcd *priv_to_hcd(struct isp1760_hcd *priv)
51{
52 return container_of((void *) priv, struct usb_hcd, hcd_priv);
53}
54 51
55/* Section 2.2 Host Controller Capability Registers */ 52/* Section 2.2 Host Controller Capability Registers */
56#define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */ 53#define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */
@@ -80,11 +77,10 @@ static inline struct usb_hcd *priv_to_hcd(struct isp1760_hcd *priv)
80#define PORT_RWC_BITS (PORT_CSC) 77#define PORT_RWC_BITS (PORT_CSC)
81 78
82struct isp1760_qtd { 79struct isp1760_qtd {
83 struct isp1760_qtd *hw_next;
84 u8 packet_type; 80 u8 packet_type;
85 u8 toggle;
86
87 void *data_buffer; 81 void *data_buffer;
82 u32 payload_addr;
83
88 /* the rest is HCD-private */ 84 /* the rest is HCD-private */
89 struct list_head qtd_list; 85 struct list_head qtd_list;
90 struct urb *urb; 86 struct urb *urb;
@@ -92,205 +88,267 @@ struct isp1760_qtd {
92 88
93 /* isp special*/ 89 /* isp special*/
94 u32 status; 90 u32 status;
95#define URB_COMPLETE_NOTIFY (1 << 0)
96#define URB_ENQUEUED (1 << 1) 91#define URB_ENQUEUED (1 << 1)
97#define URB_TYPE_ATL (1 << 2)
98#define URB_TYPE_INT (1 << 3)
99}; 92};
100 93
101struct isp1760_qh { 94struct isp1760_qh {
102 /* first part defined by EHCI spec */ 95 /* first part defined by EHCI spec */
103 struct list_head qtd_list; 96 struct list_head qtd_list;
104 struct isp1760_hcd *priv;
105
106 /* periodic schedule info */
107 unsigned short period; /* polling interval */
108 struct usb_device *dev;
109 97
110 u32 toggle; 98 u32 toggle;
111 u32 ping; 99 u32 ping;
112}; 100};
113 101
114#define ehci_port_speed(priv, portsc) USB_PORT_STAT_HIGH_SPEED 102/*
115 103 * Access functions for isp176x registers (addresses 0..0x03FF).
116static unsigned int isp1760_readl(__u32 __iomem *regs) 104 */
105static u32 reg_read32(void __iomem *base, u32 reg)
117{ 106{
118 return readl(regs); 107 return readl(base + reg);
119} 108}
120 109
121static void isp1760_writel(const unsigned int val, __u32 __iomem *regs) 110static void reg_write32(void __iomem *base, u32 reg, u32 val)
122{ 111{
123 writel(val, regs); 112 writel(val, base + reg);
124} 113}
125 114
126/* 115/*
127 * The next two copy via MMIO data to/from the device. memcpy_{to|from}io() 116 * Access functions for isp176x memory (offset >= 0x0400).
117 *
118 * bank_reads8() reads memory locations prefetched by an earlier write to
119 * HC_MEMORY_REG (see isp176x datasheet). Unless you want to do fancy multi-
120 * bank optimizations, you should use the more generic mem_reads8() below.
121 *
122 * For access to ptd memory, use the specialized ptd_read() and ptd_write()
123 * below.
124 *
125 * These functions copy via MMIO data to/from the device. memcpy_{to|from}io()
128 * doesn't quite work because some people have to enforce 32-bit access 126 * doesn't quite work because some people have to enforce 32-bit access
129 */ 127 */
130static void priv_read_copy(struct isp1760_hcd *priv, u32 *src, 128static void bank_reads8(void __iomem *src_base, u32 src_offset, u32 bank_addr,
131 __u32 __iomem *dst, u32 len) 129 __u32 *dst, u32 bytes)
132{ 130{
131 __u32 __iomem *src;
133 u32 val; 132 u32 val;
134 u8 *buff8; 133 __u8 *src_byteptr;
134 __u8 *dst_byteptr;
135 135
136 if (!src) { 136 src = src_base + (bank_addr | src_offset);
137 printk(KERN_ERR "ERROR: buffer: %p len: %d\n", src, len);
138 return;
139 }
140 137
141 while (len >= 4) { 138 if (src_offset < PAYLOAD_OFFSET) {
142 *src = __raw_readl(dst); 139 while (bytes >= 4) {
143 len -= 4; 140 *dst = le32_to_cpu(__raw_readl(src));
144 src++; 141 bytes -= 4;
145 dst++; 142 src++;
143 dst++;
144 }
145 } else {
146 while (bytes >= 4) {
147 *dst = __raw_readl(src);
148 bytes -= 4;
149 src++;
150 dst++;
151 }
146 } 152 }
147 153
148 if (!len) 154 if (!bytes)
149 return; 155 return;
150 156
151 /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully 157 /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully
152 * allocated. 158 * allocated.
153 */ 159 */
154 val = isp1760_readl(dst); 160 if (src_offset < PAYLOAD_OFFSET)
155 161 val = le32_to_cpu(__raw_readl(src));
156 buff8 = (u8 *)src; 162 else
157 while (len) { 163 val = __raw_readl(src);
158 164
159 *buff8 = val; 165 dst_byteptr = (void *) dst;
160 val >>= 8; 166 src_byteptr = (void *) &val;
161 len--; 167 while (bytes > 0) {
162 buff8++; 168 *dst_byteptr = *src_byteptr;
169 dst_byteptr++;
170 src_byteptr++;
171 bytes--;
163 } 172 }
164} 173}
165 174
166static void priv_write_copy(const struct isp1760_hcd *priv, const u32 *src, 175static void mem_reads8(void __iomem *src_base, u32 src_offset, void *dst,
167 __u32 __iomem *dst, u32 len) 176 u32 bytes)
168{ 177{
169 while (len >= 4) { 178 reg_write32(src_base, HC_MEMORY_REG, src_offset + ISP_BANK(0));
170 __raw_writel(*src, dst); 179 ndelay(90);
171 len -= 4; 180 bank_reads8(src_base, src_offset, ISP_BANK(0), dst, bytes);
172 src++; 181}
173 dst++; 182
183static void mem_writes8(void __iomem *dst_base, u32 dst_offset,
184 __u32 const *src, u32 bytes)
185{
186 __u32 __iomem *dst;
187
188 dst = dst_base + dst_offset;
189
190 if (dst_offset < PAYLOAD_OFFSET) {
191 while (bytes >= 4) {
192 __raw_writel(cpu_to_le32(*src), dst);
193 bytes -= 4;
194 src++;
195 dst++;
196 }
197 } else {
198 while (bytes >= 4) {
199 __raw_writel(*src, dst);
200 bytes -= 4;
201 src++;
202 dst++;
203 }
174 } 204 }
175 205
176 if (!len) 206 if (!bytes)
177 return; 207 return;
178 /* in case we have 3, 2 or 1 by left. The buffer is allocated and the 208 /* in case we have 3, 2 or 1 bytes left. The buffer is allocated and the
179 * extra bytes should not be read by the HW 209 * extra bytes should not be read by the HW.
180 */ 210 */
181 211
182 __raw_writel(*src, dst); 212 if (dst_offset < PAYLOAD_OFFSET)
213 __raw_writel(cpu_to_le32(*src), dst);
214 else
215 __raw_writel(*src, dst);
216}
217
218/*
219 * Read and write ptds. 'ptd_offset' should be one of ISO_PTD_OFFSET,
220 * INT_PTD_OFFSET, and ATL_PTD_OFFSET. 'slot' should be less than 32.
221 */
222static void ptd_read(void __iomem *base, u32 ptd_offset, u32 slot,
223 struct ptd *ptd)
224{
225 reg_write32(base, HC_MEMORY_REG,
226 ISP_BANK(0) + ptd_offset + slot*sizeof(*ptd));
227 ndelay(90);
228 bank_reads8(base, ptd_offset + slot*sizeof(*ptd), ISP_BANK(0),
229 (void *) ptd, sizeof(*ptd));
230}
231
232static void ptd_write(void __iomem *base, u32 ptd_offset, u32 slot,
233 struct ptd *ptd)
234{
235 mem_writes8(base, ptd_offset + slot*sizeof(*ptd) + sizeof(ptd->dw0),
236 &ptd->dw1, 7*sizeof(ptd->dw1));
237 /* Make sure dw0 gets written last (after other dw's and after payload)
238 since it contains the enable bit */
239 wmb();
240 mem_writes8(base, ptd_offset + slot*sizeof(*ptd), &ptd->dw0,
241 sizeof(ptd->dw0));
183} 242}
184 243
244
185/* memory management of the 60kb on the chip from 0x1000 to 0xffff */ 245/* memory management of the 60kb on the chip from 0x1000 to 0xffff */
186static void init_memory(struct isp1760_hcd *priv) 246static void init_memory(struct isp1760_hcd *priv)
187{ 247{
188 int i; 248 int i, curr;
189 u32 payload; 249 u32 payload_addr;
190 250
191 payload = 0x1000; 251 payload_addr = PAYLOAD_OFFSET;
192 for (i = 0; i < BLOCK_1_NUM; i++) { 252 for (i = 0; i < BLOCK_1_NUM; i++) {
193 priv->memory_pool[i].start = payload; 253 priv->memory_pool[i].start = payload_addr;
194 priv->memory_pool[i].size = BLOCK_1_SIZE; 254 priv->memory_pool[i].size = BLOCK_1_SIZE;
195 priv->memory_pool[i].free = 1; 255 priv->memory_pool[i].free = 1;
196 payload += priv->memory_pool[i].size; 256 payload_addr += priv->memory_pool[i].size;
197 } 257 }
198 258
199 259 curr = i;
200 for (i = BLOCK_1_NUM; i < BLOCK_1_NUM + BLOCK_2_NUM; i++) { 260 for (i = 0; i < BLOCK_2_NUM; i++) {
201 priv->memory_pool[i].start = payload; 261 priv->memory_pool[curr + i].start = payload_addr;
202 priv->memory_pool[i].size = BLOCK_2_SIZE; 262 priv->memory_pool[curr + i].size = BLOCK_2_SIZE;
203 priv->memory_pool[i].free = 1; 263 priv->memory_pool[curr + i].free = 1;
204 payload += priv->memory_pool[i].size; 264 payload_addr += priv->memory_pool[curr + i].size;
205 } 265 }
206 266
207 267 curr = i;
208 for (i = BLOCK_1_NUM + BLOCK_2_NUM; i < BLOCKS; i++) { 268 for (i = 0; i < BLOCK_3_NUM; i++) {
209 priv->memory_pool[i].start = payload; 269 priv->memory_pool[curr + i].start = payload_addr;
210 priv->memory_pool[i].size = BLOCK_3_SIZE; 270 priv->memory_pool[curr + i].size = BLOCK_3_SIZE;
211 priv->memory_pool[i].free = 1; 271 priv->memory_pool[curr + i].free = 1;
212 payload += priv->memory_pool[i].size; 272 payload_addr += priv->memory_pool[curr + i].size;
213 } 273 }
214 274
215 BUG_ON(payload - priv->memory_pool[i - 1].size > PAYLOAD_SIZE); 275 BUG_ON(payload_addr - priv->memory_pool[0].start > PAYLOAD_AREA_SIZE);
216} 276}
217 277
218static u32 alloc_mem(struct isp1760_hcd *priv, u32 size) 278static void alloc_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd)
219{ 279{
280 struct isp1760_hcd *priv = hcd_to_priv(hcd);
220 int i; 281 int i;
221 282
222 if (!size) 283 BUG_ON(qtd->payload_addr);
223 return ISP1760_NULL_POINTER; 284
285 if (!qtd->length)
286 return;
224 287
225 for (i = 0; i < BLOCKS; i++) { 288 for (i = 0; i < BLOCKS; i++) {
226 if (priv->memory_pool[i].size >= size && 289 if (priv->memory_pool[i].size >= qtd->length &&
227 priv->memory_pool[i].free) { 290 priv->memory_pool[i].free) {
228
229 priv->memory_pool[i].free = 0; 291 priv->memory_pool[i].free = 0;
230 return priv->memory_pool[i].start; 292 qtd->payload_addr = priv->memory_pool[i].start;
293 return;
231 } 294 }
232 } 295 }
233 296
234 printk(KERN_ERR "ISP1760 MEM: can not allocate %d bytes of memory\n", 297 dev_err(hcd->self.controller,
235 size); 298 "%s: Can not allocate %lu bytes of memory\n"
236 printk(KERN_ERR "Current memory map:\n"); 299 "Current memory map:\n",
300 __func__, qtd->length);
237 for (i = 0; i < BLOCKS; i++) { 301 for (i = 0; i < BLOCKS; i++) {
238 printk(KERN_ERR "Pool %2d size %4d status: %d\n", 302 dev_err(hcd->self.controller, "Pool %2d size %4d status: %d\n",
239 i, priv->memory_pool[i].size, 303 i, priv->memory_pool[i].size,
240 priv->memory_pool[i].free); 304 priv->memory_pool[i].free);
241 } 305 }
242 /* XXX maybe -ENOMEM could be possible */ 306 /* XXX maybe -ENOMEM could be possible */
243 BUG(); 307 BUG();
244 return 0; 308 return;
245} 309}
246 310
247static void free_mem(struct isp1760_hcd *priv, u32 mem) 311static void free_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd)
248{ 312{
313 struct isp1760_hcd *priv = hcd_to_priv(hcd);
249 int i; 314 int i;
250 315
251 if (mem == ISP1760_NULL_POINTER) 316 if (!qtd->payload_addr)
252 return; 317 return;
253 318
254 for (i = 0; i < BLOCKS; i++) { 319 for (i = 0; i < BLOCKS; i++) {
255 if (priv->memory_pool[i].start == mem) { 320 if (priv->memory_pool[i].start == qtd->payload_addr) {
256
257 BUG_ON(priv->memory_pool[i].free); 321 BUG_ON(priv->memory_pool[i].free);
258
259 priv->memory_pool[i].free = 1; 322 priv->memory_pool[i].free = 1;
260 return ; 323 qtd->payload_addr = 0;
324 return;
261 } 325 }
262 } 326 }
263 327
264 printk(KERN_ERR "Trying to free not-here-allocated memory :%08x\n", 328 dev_err(hcd->self.controller, "%s: Invalid pointer: %08x\n",
265 mem); 329 __func__, qtd->payload_addr);
266 BUG(); 330 BUG();
267} 331}
268 332
269static void isp1760_init_regs(struct usb_hcd *hcd) 333static void isp1760_init_regs(struct usb_hcd *hcd)
270{ 334{
271 isp1760_writel(0, hcd->regs + HC_BUFFER_STATUS_REG); 335 reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, 0);
272 isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs + 336 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE);
273 HC_ATL_PTD_SKIPMAP_REG); 337 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE);
274 isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs + 338 reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE);
275 HC_INT_PTD_SKIPMAP_REG); 339
276 isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs + 340 reg_write32(hcd->regs, HC_ATL_PTD_DONEMAP_REG, ~NO_TRANSFER_ACTIVE);
277 HC_ISO_PTD_SKIPMAP_REG); 341 reg_write32(hcd->regs, HC_INT_PTD_DONEMAP_REG, ~NO_TRANSFER_ACTIVE);
278 342 reg_write32(hcd->regs, HC_ISO_PTD_DONEMAP_REG, ~NO_TRANSFER_ACTIVE);
279 isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs +
280 HC_ATL_PTD_DONEMAP_REG);
281 isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs +
282 HC_INT_PTD_DONEMAP_REG);
283 isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs +
284 HC_ISO_PTD_DONEMAP_REG);
285} 343}
286 344
287static int handshake(struct isp1760_hcd *priv, void __iomem *ptr, 345static int handshake(struct usb_hcd *hcd, u32 reg,
288 u32 mask, u32 done, int usec) 346 u32 mask, u32 done, int usec)
289{ 347{
290 u32 result; 348 u32 result;
291 349
292 do { 350 do {
293 result = isp1760_readl(ptr); 351 result = reg_read32(hcd->regs, reg);
294 if (result == ~0) 352 if (result == ~0)
295 return -ENODEV; 353 return -ENODEV;
296 result &= mask; 354 result &= mask;
@@ -303,17 +361,18 @@ static int handshake(struct isp1760_hcd *priv, void __iomem *ptr,
303} 361}
304 362
305/* reset a non-running (STS_HALT == 1) controller */ 363/* reset a non-running (STS_HALT == 1) controller */
306static int ehci_reset(struct isp1760_hcd *priv) 364static int ehci_reset(struct usb_hcd *hcd)
307{ 365{
308 int retval; 366 int retval;
309 struct usb_hcd *hcd = priv_to_hcd(priv); 367 struct isp1760_hcd *priv = hcd_to_priv(hcd);
310 u32 command = isp1760_readl(hcd->regs + HC_USBCMD); 368
369 u32 command = reg_read32(hcd->regs, HC_USBCMD);
311 370
312 command |= CMD_RESET; 371 command |= CMD_RESET;
313 isp1760_writel(command, hcd->regs + HC_USBCMD); 372 reg_write32(hcd->regs, HC_USBCMD, command);
314 hcd->state = HC_STATE_HALT; 373 hcd->state = HC_STATE_HALT;
315 priv->next_statechange = jiffies; 374 priv->next_statechange = jiffies;
316 retval = handshake(priv, hcd->regs + HC_USBCMD, 375 retval = handshake(hcd, HC_USBCMD,
317 CMD_RESET, 0, 250 * 1000); 376 CMD_RESET, 0, 250 * 1000);
318 return retval; 377 return retval;
319} 378}
@@ -324,8 +383,7 @@ static void qh_destroy(struct isp1760_qh *qh)
324 kmem_cache_free(qh_cachep, qh); 383 kmem_cache_free(qh_cachep, qh);
325} 384}
326 385
327static struct isp1760_qh *isp1760_qh_alloc(struct isp1760_hcd *priv, 386static struct isp1760_qh *isp1760_qh_alloc(gfp_t flags)
328 gfp_t flags)
329{ 387{
330 struct isp1760_qh *qh; 388 struct isp1760_qh *qh;
331 389
@@ -334,7 +392,6 @@ static struct isp1760_qh *isp1760_qh_alloc(struct isp1760_hcd *priv,
334 return qh; 392 return qh;
335 393
336 INIT_LIST_HEAD(&qh->qtd_list); 394 INIT_LIST_HEAD(&qh->qtd_list);
337 qh->priv = priv;
338 return qh; 395 return qh;
339} 396}
340 397
@@ -361,7 +418,7 @@ static int priv_init(struct usb_hcd *hcd)
361 priv->periodic_size = DEFAULT_I_TDPS; 418 priv->periodic_size = DEFAULT_I_TDPS;
362 419
363 /* controllers may cache some of the periodic schedule ... */ 420 /* controllers may cache some of the periodic schedule ... */
364 hcc_params = isp1760_readl(hcd->regs + HC_HCCPARAMS); 421 hcc_params = reg_read32(hcd->regs, HC_HCCPARAMS);
365 /* full frame cache */ 422 /* full frame cache */
366 if (HCC_ISOC_CACHE(hcc_params)) 423 if (HCC_ISOC_CACHE(hcc_params))
367 priv->i_thresh = 8; 424 priv->i_thresh = 8;
@@ -398,15 +455,15 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
398 * Write it twice to ensure correct upper bits if switching 455 * Write it twice to ensure correct upper bits if switching
399 * to 16-bit mode. 456 * to 16-bit mode.
400 */ 457 */
401 isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL); 458 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
402 isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL); 459 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
403 460
404 isp1760_writel(0xdeadbabe, hcd->regs + HC_SCRATCH_REG); 461 reg_write32(hcd->regs, HC_SCRATCH_REG, 0xdeadbabe);
405 /* Change bus pattern */ 462 /* Change bus pattern */
406 scratch = isp1760_readl(hcd->regs + HC_CHIP_ID_REG); 463 scratch = reg_read32(hcd->regs, HC_CHIP_ID_REG);
407 scratch = isp1760_readl(hcd->regs + HC_SCRATCH_REG); 464 scratch = reg_read32(hcd->regs, HC_SCRATCH_REG);
408 if (scratch != 0xdeadbabe) { 465 if (scratch != 0xdeadbabe) {
409 printk(KERN_ERR "ISP1760: Scratch test failed.\n"); 466 dev_err(hcd->self.controller, "Scratch test failed.\n");
410 return -ENODEV; 467 return -ENODEV;
411 } 468 }
412 469
@@ -414,30 +471,30 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
414 isp1760_init_regs(hcd); 471 isp1760_init_regs(hcd);
415 472
416 /* reset */ 473 /* reset */
417 isp1760_writel(SW_RESET_RESET_ALL, hcd->regs + HC_RESET_REG); 474 reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_ALL);
418 mdelay(100); 475 mdelay(100);
419 476
420 isp1760_writel(SW_RESET_RESET_HC, hcd->regs + HC_RESET_REG); 477 reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_HC);
421 mdelay(100); 478 mdelay(100);
422 479
423 result = ehci_reset(priv); 480 result = ehci_reset(hcd);
424 if (result) 481 if (result)
425 return result; 482 return result;
426 483
427 /* Step 11 passed */ 484 /* Step 11 passed */
428 485
429 isp1760_info(priv, "bus width: %d, oc: %s\n", 486 dev_info(hcd->self.controller, "bus width: %d, oc: %s\n",
430 (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ? 487 (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ?
431 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ? 488 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ?
432 "analog" : "digital"); 489 "analog" : "digital");
433 490
434 /* ATL reset */ 491 /* ATL reset */
435 isp1760_writel(hwmode | ALL_ATX_RESET, hcd->regs + HC_HW_MODE_CTRL); 492 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET);
436 mdelay(10); 493 mdelay(10);
437 isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL); 494 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
438 495
439 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_REG); 496 reg_write32(hcd->regs, HC_INTERRUPT_REG, INTERRUPT_ENABLE_MASK);
440 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_ENABLE); 497 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, INTERRUPT_ENABLE_MASK);
441 498
442 /* 499 /*
443 * PORT 1 Control register of the ISP1760 is the OTG control 500 * PORT 1 Control register of the ISP1760 is the OTG control
@@ -445,11 +502,10 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
445 * support in this driver, we use port 1 as a "normal" USB host port on 502 * support in this driver, we use port 1 as a "normal" USB host port on
446 * both chips. 503 * both chips.
447 */ 504 */
448 isp1760_writel(PORT1_POWER | PORT1_INIT2, 505 reg_write32(hcd->regs, HC_PORT1_CTRL, PORT1_POWER | PORT1_INIT2);
449 hcd->regs + HC_PORT1_CTRL);
450 mdelay(10); 506 mdelay(10);
451 507
452 priv->hcs_params = isp1760_readl(hcd->regs + HC_HCSPARAMS); 508 priv->hcs_params = reg_read32(hcd->regs, HC_HCSPARAMS);
453 509
454 return priv_init(hcd); 510 return priv_init(hcd);
455} 511}
@@ -457,25 +513,24 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
457static void isp1760_init_maps(struct usb_hcd *hcd) 513static void isp1760_init_maps(struct usb_hcd *hcd)
458{ 514{
459 /*set last maps, for iso its only 1, else 32 tds bitmap*/ 515 /*set last maps, for iso its only 1, else 32 tds bitmap*/
460 isp1760_writel(0x80000000, hcd->regs + HC_ATL_PTD_LASTPTD_REG); 516 reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000);
461 isp1760_writel(0x80000000, hcd->regs + HC_INT_PTD_LASTPTD_REG); 517 reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000);
462 isp1760_writel(0x00000001, hcd->regs + HC_ISO_PTD_LASTPTD_REG); 518 reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001);
463} 519}
464 520
465static void isp1760_enable_interrupts(struct usb_hcd *hcd) 521static void isp1760_enable_interrupts(struct usb_hcd *hcd)
466{ 522{
467 isp1760_writel(0, hcd->regs + HC_ATL_IRQ_MASK_AND_REG); 523 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0);
468 isp1760_writel(0, hcd->regs + HC_ATL_IRQ_MASK_OR_REG); 524 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0);
469 isp1760_writel(0, hcd->regs + HC_INT_IRQ_MASK_AND_REG); 525 reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0);
470 isp1760_writel(0, hcd->regs + HC_INT_IRQ_MASK_OR_REG); 526 reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0);
471 isp1760_writel(0, hcd->regs + HC_ISO_IRQ_MASK_AND_REG); 527 reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0);
472 isp1760_writel(0xffffffff, hcd->regs + HC_ISO_IRQ_MASK_OR_REG); 528 reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff);
473 /* step 23 passed */ 529 /* step 23 passed */
474} 530}
475 531
476static int isp1760_run(struct usb_hcd *hcd) 532static int isp1760_run(struct usb_hcd *hcd)
477{ 533{
478 struct isp1760_hcd *priv = hcd_to_priv(hcd);
479 int retval; 534 int retval;
480 u32 temp; 535 u32 temp;
481 u32 command; 536 u32 command;
@@ -485,15 +540,15 @@ static int isp1760_run(struct usb_hcd *hcd)
485 540
486 hcd->state = HC_STATE_RUNNING; 541 hcd->state = HC_STATE_RUNNING;
487 isp1760_enable_interrupts(hcd); 542 isp1760_enable_interrupts(hcd);
488 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); 543 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
489 isp1760_writel(temp | HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL); 544 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN);
490 545
491 command = isp1760_readl(hcd->regs + HC_USBCMD); 546 command = reg_read32(hcd->regs, HC_USBCMD);
492 command &= ~(CMD_LRESET|CMD_RESET); 547 command &= ~(CMD_LRESET|CMD_RESET);
493 command |= CMD_RUN; 548 command |= CMD_RUN;
494 isp1760_writel(command, hcd->regs + HC_USBCMD); 549 reg_write32(hcd->regs, HC_USBCMD, command);
495 550
496 retval = handshake(priv, hcd->regs + HC_USBCMD, CMD_RUN, CMD_RUN, 551 retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN,
497 250 * 1000); 552 250 * 1000);
498 if (retval) 553 if (retval)
499 return retval; 554 return retval;
@@ -504,17 +559,16 @@ static int isp1760_run(struct usb_hcd *hcd)
504 * the semaphore while doing so. 559 * the semaphore while doing so.
505 */ 560 */
506 down_write(&ehci_cf_port_reset_rwsem); 561 down_write(&ehci_cf_port_reset_rwsem);
507 isp1760_writel(FLAG_CF, hcd->regs + HC_CONFIGFLAG); 562 reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF);
508 563
509 retval = handshake(priv, hcd->regs + HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 564 retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000);
510 250 * 1000);
511 up_write(&ehci_cf_port_reset_rwsem); 565 up_write(&ehci_cf_port_reset_rwsem);
512 if (retval) 566 if (retval)
513 return retval; 567 return retval;
514 568
515 chipid = isp1760_readl(hcd->regs + HC_CHIP_ID_REG); 569 chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG);
516 isp1760_info(priv, "USB ISP %04x HW rev. %d started\n", chipid & 0xffff, 570 dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n",
517 chipid >> 16); 571 chipid & 0xffff, chipid >> 16);
518 572
519 /* PTD Register Init Part 2, Step 28 */ 573 /* PTD Register Init Part 2, Step 28 */
520 /* enable INTs */ 574 /* enable INTs */
@@ -532,160 +586,156 @@ static u32 base_to_chip(u32 base)
532 return ((base - 0x400) >> 3); 586 return ((base - 0x400) >> 3);
533} 587}
534 588
535static void transform_into_atl(struct isp1760_hcd *priv, struct isp1760_qh *qh, 589static int last_qtd_of_urb(struct isp1760_qtd *qtd, struct isp1760_qh *qh)
536 struct isp1760_qtd *qtd, struct urb *urb, 590{
537 u32 payload, struct ptd *ptd) 591 struct urb *urb;
592
593 if (list_is_last(&qtd->qtd_list, &qh->qtd_list))
594 return 1;
595
596 urb = qtd->urb;
597 qtd = list_entry(qtd->qtd_list.next, typeof(*qtd), qtd_list);
598 return (qtd->urb != urb);
599}
600
601static void transform_into_atl(struct isp1760_qh *qh,
602 struct isp1760_qtd *qtd, struct ptd *ptd)
538{ 603{
539 u32 dw0;
540 u32 dw1;
541 u32 dw2;
542 u32 dw3;
543 u32 maxpacket; 604 u32 maxpacket;
544 u32 multi; 605 u32 multi;
545 u32 pid_code; 606 u32 pid_code;
546 u32 rl = RL_COUNTER; 607 u32 rl = RL_COUNTER;
547 u32 nak = NAK_COUNTER; 608 u32 nak = NAK_COUNTER;
548 609
610 memset(ptd, 0, sizeof(*ptd));
611
549 /* according to 3.6.2, max packet len can not be > 0x400 */ 612 /* according to 3.6.2, max packet len can not be > 0x400 */
550 maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); 613 maxpacket = usb_maxpacket(qtd->urb->dev, qtd->urb->pipe,
614 usb_pipeout(qtd->urb->pipe));
551 multi = 1 + ((maxpacket >> 11) & 0x3); 615 multi = 1 + ((maxpacket >> 11) & 0x3);
552 maxpacket &= 0x7ff; 616 maxpacket &= 0x7ff;
553 617
554 /* DW0 */ 618 /* DW0 */
555 dw0 = PTD_VALID; 619 ptd->dw0 = PTD_VALID;
556 dw0 |= PTD_LENGTH(qtd->length); 620 ptd->dw0 |= PTD_LENGTH(qtd->length);
557 dw0 |= PTD_MAXPACKET(maxpacket); 621 ptd->dw0 |= PTD_MAXPACKET(maxpacket);
558 dw0 |= PTD_ENDPOINT(usb_pipeendpoint(urb->pipe)); 622 ptd->dw0 |= PTD_ENDPOINT(usb_pipeendpoint(qtd->urb->pipe));
559 dw1 = usb_pipeendpoint(urb->pipe) >> 1;
560 623
561 /* DW1 */ 624 /* DW1 */
562 dw1 |= PTD_DEVICE_ADDR(usb_pipedevice(urb->pipe)); 625 ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1;
626 ptd->dw1 |= PTD_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe));
563 627
564 pid_code = qtd->packet_type; 628 pid_code = qtd->packet_type;
565 dw1 |= PTD_PID_TOKEN(pid_code); 629 ptd->dw1 |= PTD_PID_TOKEN(pid_code);
566 630
567 if (usb_pipebulk(urb->pipe)) 631 if (usb_pipebulk(qtd->urb->pipe))
568 dw1 |= PTD_TRANS_BULK; 632 ptd->dw1 |= PTD_TRANS_BULK;
569 else if (usb_pipeint(urb->pipe)) 633 else if (usb_pipeint(qtd->urb->pipe))
570 dw1 |= PTD_TRANS_INT; 634 ptd->dw1 |= PTD_TRANS_INT;
571 635
572 if (urb->dev->speed != USB_SPEED_HIGH) { 636 if (qtd->urb->dev->speed != USB_SPEED_HIGH) {
573 /* split transaction */ 637 /* split transaction */
574 638
575 dw1 |= PTD_TRANS_SPLIT; 639 ptd->dw1 |= PTD_TRANS_SPLIT;
576 if (urb->dev->speed == USB_SPEED_LOW) 640 if (qtd->urb->dev->speed == USB_SPEED_LOW)
577 dw1 |= PTD_SE_USB_LOSPEED; 641 ptd->dw1 |= PTD_SE_USB_LOSPEED;
578 642
579 dw1 |= PTD_PORT_NUM(urb->dev->ttport); 643 ptd->dw1 |= PTD_PORT_NUM(qtd->urb->dev->ttport);
580 dw1 |= PTD_HUB_NUM(urb->dev->tt->hub->devnum); 644 ptd->dw1 |= PTD_HUB_NUM(qtd->urb->dev->tt->hub->devnum);
581 645
582 /* SE bit for Split INT transfers */ 646 /* SE bit for Split INT transfers */
583 if (usb_pipeint(urb->pipe) && 647 if (usb_pipeint(qtd->urb->pipe) &&
584 (urb->dev->speed == USB_SPEED_LOW)) 648 (qtd->urb->dev->speed == USB_SPEED_LOW))
585 dw1 |= 2 << 16; 649 ptd->dw1 |= 2 << 16;
586 650
587 dw3 = 0; 651 ptd->dw3 = 0;
588 rl = 0; 652 rl = 0;
589 nak = 0; 653 nak = 0;
590 } else { 654 } else {
591 dw0 |= PTD_MULTI(multi); 655 ptd->dw0 |= PTD_MULTI(multi);
592 if (usb_pipecontrol(urb->pipe) || usb_pipebulk(urb->pipe)) 656 if (usb_pipecontrol(qtd->urb->pipe) ||
593 dw3 = qh->ping; 657 usb_pipebulk(qtd->urb->pipe))
658 ptd->dw3 = qh->ping;
594 else 659 else
595 dw3 = 0; 660 ptd->dw3 = 0;
596 } 661 }
597 /* DW2 */ 662 /* DW2 */
598 dw2 = 0; 663 ptd->dw2 = 0;
599 dw2 |= PTD_DATA_START_ADDR(base_to_chip(payload)); 664 ptd->dw2 |= PTD_DATA_START_ADDR(base_to_chip(qtd->payload_addr));
600 dw2 |= PTD_RL_CNT(rl); 665 ptd->dw2 |= PTD_RL_CNT(rl);
601 dw3 |= PTD_NAC_CNT(nak); 666 ptd->dw3 |= PTD_NAC_CNT(nak);
602 667
603 /* DW3 */ 668 /* DW3 */
604 if (usb_pipecontrol(urb->pipe)) 669 ptd->dw3 |= qh->toggle;
605 dw3 |= PTD_DATA_TOGGLE(qtd->toggle); 670 if (usb_pipecontrol(qtd->urb->pipe)) {
606 else 671 if (qtd->data_buffer == qtd->urb->setup_packet)
607 dw3 |= qh->toggle; 672 ptd->dw3 &= ~PTD_DATA_TOGGLE(1);
608 673 else if (last_qtd_of_urb(qtd, qh))
674 ptd->dw3 |= PTD_DATA_TOGGLE(1);
675 }
609 676
610 dw3 |= PTD_ACTIVE; 677 ptd->dw3 |= PTD_ACTIVE;
611 /* Cerr */ 678 /* Cerr */
612 dw3 |= PTD_CERR(ERR_COUNTER); 679 ptd->dw3 |= PTD_CERR(ERR_COUNTER);
613
614 memset(ptd, 0, sizeof(*ptd));
615
616 ptd->dw0 = cpu_to_le32(dw0);
617 ptd->dw1 = cpu_to_le32(dw1);
618 ptd->dw2 = cpu_to_le32(dw2);
619 ptd->dw3 = cpu_to_le32(dw3);
620} 680}
621 681
622static void transform_add_int(struct isp1760_hcd *priv, struct isp1760_qh *qh, 682static void transform_add_int(struct isp1760_qh *qh,
623 struct isp1760_qtd *qtd, struct urb *urb, 683 struct isp1760_qtd *qtd, struct ptd *ptd)
624 u32 payload, struct ptd *ptd)
625{ 684{
626 u32 maxpacket; 685 u32 usof;
627 u32 multi;
628 u32 numberofusofs;
629 u32 i;
630 u32 usofmask, usof;
631 u32 period; 686 u32 period;
632 687
633 maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); 688 /*
634 multi = 1 + ((maxpacket >> 11) & 0x3); 689 * Most of this is guessing. ISP1761 datasheet is quite unclear, and
635 maxpacket &= 0x7ff; 690 * the algorithm from the original Philips driver code, which was
636 /* length of the data per uframe */ 691 * pretty much used in this driver before as well, is quite horrendous
637 maxpacket = multi * maxpacket; 692 * and, i believe, incorrect. The code below follows the datasheet and
638 693 * USB2.0 spec as far as I can tell, and plug/unplug seems to be much
639 numberofusofs = urb->transfer_buffer_length / maxpacket; 694 * more reliable this way (fingers crossed...).
640 if (urb->transfer_buffer_length % maxpacket) 695 */
641 numberofusofs += 1;
642
643 usofmask = 1;
644 usof = 0;
645 for (i = 0; i < numberofusofs; i++) {
646 usof |= usofmask;
647 usofmask <<= 1;
648 }
649
650 if (urb->dev->speed != USB_SPEED_HIGH) {
651 /* split */
652 ptd->dw5 = cpu_to_le32(0x1c);
653 696
654 if (qh->period >= 32) 697 if (qtd->urb->dev->speed == USB_SPEED_HIGH) {
655 period = qh->period / 2; 698 /* urb->interval is in units of microframes (1/8 ms) */
699 period = qtd->urb->interval >> 3;
700
701 if (qtd->urb->interval > 4)
702 usof = 0x01; /* One bit set =>
703 interval 1 ms * uFrame-match */
704 else if (qtd->urb->interval > 2)
705 usof = 0x22; /* Two bits set => interval 1/2 ms */
706 else if (qtd->urb->interval > 1)
707 usof = 0x55; /* Four bits set => interval 1/4 ms */
656 else 708 else
657 period = qh->period; 709 usof = 0xff; /* All bits set => interval 1/8 ms */
658
659 } else { 710 } else {
711 /* urb->interval is in units of frames (1 ms) */
712 period = qtd->urb->interval;
713 usof = 0x0f; /* Execute Start Split on any of the
714 four first uFrames */
660 715
661 if (qh->period >= 8) 716 /*
662 period = qh->period/8; 717 * First 8 bits in dw5 is uSCS and "specifies which uSOF the
663 else 718 * complete split needs to be sent. Valid only for IN." Also,
664 period = qh->period; 719 * "All bits can be set to one for every transfer." (p 82,
665 720 * ISP1761 data sheet.) 0x1c is from Philips driver. Where did
666 if (period >= 32) 721 * that number come from? 0xff seems to work fine...
667 period = 16; 722 */
668 723 /* ptd->dw5 = 0x1c; */
669 if (qh->period >= 8) { 724 ptd->dw5 = 0xff; /* Execute Complete Split on any uFrame */
670 /* millisecond period */
671 period = (period << 3);
672 } else {
673 /* usof based tranmsfers */
674 /* minimum 4 usofs */
675 usof = 0x11;
676 }
677 } 725 }
678 726
679 ptd->dw2 |= cpu_to_le32(period); 727 period = period >> 1;/* Ensure equal or shorter period than requested */
680 ptd->dw4 = cpu_to_le32(usof); 728 period &= 0xf8; /* Mask off too large values and lowest unused 3 bits */
729
730 ptd->dw2 |= period;
731 ptd->dw4 = usof;
681} 732}
682 733
683static void transform_into_int(struct isp1760_hcd *priv, struct isp1760_qh *qh, 734static void transform_into_int(struct isp1760_qh *qh,
684 struct isp1760_qtd *qtd, struct urb *urb, 735 struct isp1760_qtd *qtd, struct ptd *ptd)
685 u32 payload, struct ptd *ptd)
686{ 736{
687 transform_into_atl(priv, qh, qtd, urb, payload, ptd); 737 transform_into_atl(qh, qtd, ptd);
688 transform_add_int(priv, qh, qtd, urb, payload, ptd); 738 transform_add_int(qh, qtd, ptd);
689} 739}
690 740
691static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len, 741static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len,
@@ -695,10 +745,9 @@ static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len,
695 745
696 qtd->data_buffer = databuffer; 746 qtd->data_buffer = databuffer;
697 qtd->packet_type = GET_QTD_TOKEN_TYPE(token); 747 qtd->packet_type = GET_QTD_TOKEN_TYPE(token);
698 qtd->toggle = GET_DATA_TOGGLE(token);
699 748
700 if (len > HC_ATL_PL_SIZE) 749 if (len > MAX_PAYLOAD_SIZE)
701 count = HC_ATL_PL_SIZE; 750 count = MAX_PAYLOAD_SIZE;
702 else 751 else
703 count = len; 752 count = len;
704 753
@@ -706,29 +755,27 @@ static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len,
706 return count; 755 return count;
707} 756}
708 757
709static int check_error(struct ptd *ptd) 758static int check_error(struct usb_hcd *hcd, struct ptd *ptd)
710{ 759{
711 int error = 0; 760 int error = 0;
712 u32 dw3;
713 761
714 dw3 = le32_to_cpu(ptd->dw3); 762 if (ptd->dw3 & DW3_HALT_BIT) {
715 if (dw3 & DW3_HALT_BIT) {
716 error = -EPIPE; 763 error = -EPIPE;
717 764
718 if (dw3 & DW3_ERROR_BIT) 765 if (ptd->dw3 & DW3_ERROR_BIT)
719 pr_err("error bit is set in DW3\n"); 766 pr_err("error bit is set in DW3\n");
720 } 767 }
721 768
722 if (dw3 & DW3_QTD_ACTIVE) { 769 if (ptd->dw3 & DW3_QTD_ACTIVE) {
723 printk(KERN_ERR "transfer active bit is set DW3\n"); 770 dev_err(hcd->self.controller, "Transfer active bit is set DW3\n"
724 printk(KERN_ERR "nak counter: %d, rl: %d\n", (dw3 >> 19) & 0xf, 771 "nak counter: %d, rl: %d\n",
725 (le32_to_cpu(ptd->dw2) >> 25) & 0xf); 772 (ptd->dw3 >> 19) & 0xf, (ptd->dw2 >> 25) & 0xf);
726 } 773 }
727 774
728 return error; 775 return error;
729} 776}
730 777
731static void check_int_err_status(u32 dw4) 778static void check_int_err_status(struct usb_hcd *hcd, u32 dw4)
732{ 779{
733 u32 i; 780 u32 i;
734 781
@@ -737,79 +784,67 @@ static void check_int_err_status(u32 dw4)
737 for (i = 0; i < 8; i++) { 784 for (i = 0; i < 8; i++) {
738 switch (dw4 & 0x7) { 785 switch (dw4 & 0x7) {
739 case INT_UNDERRUN: 786 case INT_UNDERRUN:
740 printk(KERN_ERR "ERROR: under run , %d\n", i); 787 dev_err(hcd->self.controller, "Underrun (%d)\n", i);
741 break; 788 break;
742 789
743 case INT_EXACT: 790 case INT_EXACT:
744 printk(KERN_ERR "ERROR: transaction error, %d\n", i); 791 dev_err(hcd->self.controller,
792 "Transaction error (%d)\n", i);
745 break; 793 break;
746 794
747 case INT_BABBLE: 795 case INT_BABBLE:
748 printk(KERN_ERR "ERROR: babble error, %d\n", i); 796 dev_err(hcd->self.controller, "Babble error (%d)\n", i);
749 break; 797 break;
750 } 798 }
751 dw4 >>= 3; 799 dw4 >>= 3;
752 } 800 }
753} 801}
754 802
755static void enqueue_one_qtd(struct isp1760_qtd *qtd, struct isp1760_hcd *priv, 803static void enqueue_one_qtd(struct usb_hcd *hcd, struct isp1760_qtd *qtd)
756 u32 payload)
757{ 804{
758 u32 token; 805 if (qtd->length && (qtd->length <= MAX_PAYLOAD_SIZE)) {
759 struct usb_hcd *hcd = priv_to_hcd(priv); 806 switch (qtd->packet_type) {
760
761 token = qtd->packet_type;
762
763 if (qtd->length && (qtd->length <= HC_ATL_PL_SIZE)) {
764 switch (token) {
765 case IN_PID: 807 case IN_PID:
766 break; 808 break;
767 case OUT_PID: 809 case OUT_PID:
768 case SETUP_PID: 810 case SETUP_PID:
769 priv_write_copy(priv, qtd->data_buffer, 811 mem_writes8(hcd->regs, qtd->payload_addr,
770 hcd->regs + payload, 812 qtd->data_buffer, qtd->length);
771 qtd->length);
772 } 813 }
773 } 814 }
774} 815}
775 816
776static void enqueue_one_atl_qtd(u32 atl_regs, u32 payload, 817static void enqueue_one_atl_qtd(struct usb_hcd *hcd, struct isp1760_qh *qh,
777 struct isp1760_hcd *priv, struct isp1760_qh *qh, 818 u32 slot, struct isp1760_qtd *qtd)
778 struct urb *urb, u32 slot, struct isp1760_qtd *qtd)
779{ 819{
820 struct isp1760_hcd *priv = hcd_to_priv(hcd);
780 struct ptd ptd; 821 struct ptd ptd;
781 struct usb_hcd *hcd = priv_to_hcd(priv);
782 822
783 transform_into_atl(priv, qh, qtd, urb, payload, &ptd); 823 alloc_mem(hcd, qtd);
784 priv_write_copy(priv, (u32 *)&ptd, hcd->regs + atl_regs, sizeof(ptd)); 824 transform_into_atl(qh, qtd, &ptd);
785 enqueue_one_qtd(qtd, priv, payload); 825 ptd_write(hcd->regs, ATL_PTD_OFFSET, slot, &ptd);
826 enqueue_one_qtd(hcd, qtd);
786 827
787 priv->atl_ints[slot].urb = urb;
788 priv->atl_ints[slot].qh = qh; 828 priv->atl_ints[slot].qh = qh;
789 priv->atl_ints[slot].qtd = qtd; 829 priv->atl_ints[slot].qtd = qtd;
790 priv->atl_ints[slot].data_buffer = qtd->data_buffer; 830 qtd->status |= URB_ENQUEUED;
791 priv->atl_ints[slot].payload = payload;
792 qtd->status |= URB_ENQUEUED | URB_TYPE_ATL;
793 qtd->status |= slot << 16; 831 qtd->status |= slot << 16;
794} 832}
795 833
796static void enqueue_one_int_qtd(u32 int_regs, u32 payload, 834static void enqueue_one_int_qtd(struct usb_hcd *hcd, struct isp1760_qh *qh,
797 struct isp1760_hcd *priv, struct isp1760_qh *qh, 835 u32 slot, struct isp1760_qtd *qtd)
798 struct urb *urb, u32 slot, struct isp1760_qtd *qtd)
799{ 836{
837 struct isp1760_hcd *priv = hcd_to_priv(hcd);
800 struct ptd ptd; 838 struct ptd ptd;
801 struct usb_hcd *hcd = priv_to_hcd(priv);
802 839
803 transform_into_int(priv, qh, qtd, urb, payload, &ptd); 840 alloc_mem(hcd, qtd);
804 priv_write_copy(priv, (u32 *)&ptd, hcd->regs + int_regs, sizeof(ptd)); 841 transform_into_int(qh, qtd, &ptd);
805 enqueue_one_qtd(qtd, priv, payload); 842 ptd_write(hcd->regs, INT_PTD_OFFSET, slot, &ptd);
843 enqueue_one_qtd(hcd, qtd);
806 844
807 priv->int_ints[slot].urb = urb;
808 priv->int_ints[slot].qh = qh; 845 priv->int_ints[slot].qh = qh;
809 priv->int_ints[slot].qtd = qtd; 846 priv->int_ints[slot].qtd = qtd;
810 priv->int_ints[slot].data_buffer = qtd->data_buffer; 847 qtd->status |= URB_ENQUEUED;
811 priv->int_ints[slot].payload = payload;
812 qtd->status |= URB_ENQUEUED | URB_TYPE_INT;
813 qtd->status |= slot << 16; 848 qtd->status |= slot << 16;
814} 849}
815 850
@@ -818,9 +853,7 @@ static void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
818{ 853{
819 struct isp1760_hcd *priv = hcd_to_priv(hcd); 854 struct isp1760_hcd *priv = hcd_to_priv(hcd);
820 u32 skip_map, or_map; 855 u32 skip_map, or_map;
821 u32 queue_entry;
822 u32 slot; 856 u32 slot;
823 u32 atl_regs, payload;
824 u32 buffstatus; 857 u32 buffstatus;
825 858
826 /* 859 /*
@@ -831,38 +864,35 @@ static void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
831 */ 864 */
832 mmiowb(); 865 mmiowb();
833 ndelay(195); 866 ndelay(195);
834 skip_map = isp1760_readl(hcd->regs + HC_ATL_PTD_SKIPMAP_REG); 867 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
835 868
836 BUG_ON(!skip_map); 869 BUG_ON(!skip_map);
837 slot = __ffs(skip_map); 870 slot = __ffs(skip_map);
838 queue_entry = 1 << slot;
839
840 atl_regs = ATL_REGS_OFFSET + slot * sizeof(struct ptd);
841 871
842 payload = alloc_mem(priv, qtd->length); 872 enqueue_one_atl_qtd(hcd, qh, slot, qtd);
843 873
844 enqueue_one_atl_qtd(atl_regs, payload, priv, qh, qtd->urb, slot, qtd); 874 or_map = reg_read32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG);
875 or_map |= (1 << slot);
876 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, or_map);
845 877
846 or_map = isp1760_readl(hcd->regs + HC_ATL_IRQ_MASK_OR_REG); 878 skip_map &= ~(1 << slot);
847 or_map |= queue_entry; 879 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map);
848 isp1760_writel(or_map, hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
849 880
850 skip_map &= ~queue_entry; 881 priv->atl_queued++;
851 isp1760_writel(skip_map, hcd->regs + HC_ATL_PTD_SKIPMAP_REG); 882 if (priv->atl_queued == 2)
883 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE,
884 INTERRUPT_ENABLE_SOT_MASK);
852 885
853 buffstatus = isp1760_readl(hcd->regs + HC_BUFFER_STATUS_REG); 886 buffstatus = reg_read32(hcd->regs, HC_BUFFER_STATUS_REG);
854 buffstatus |= ATL_BUFFER; 887 buffstatus |= ATL_BUFFER;
855 isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG); 888 reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, buffstatus);
856} 889}
857 890
858static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, 891static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
859 struct isp1760_qtd *qtd) 892 struct isp1760_qtd *qtd)
860{ 893{
861 struct isp1760_hcd *priv = hcd_to_priv(hcd);
862 u32 skip_map, or_map; 894 u32 skip_map, or_map;
863 u32 queue_entry;
864 u32 slot; 895 u32 slot;
865 u32 int_regs, payload;
866 u32 buffstatus; 896 u32 buffstatus;
867 897
868 /* 898 /*
@@ -873,37 +903,34 @@ static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
873 */ 903 */
874 mmiowb(); 904 mmiowb();
875 ndelay(195); 905 ndelay(195);
876 skip_map = isp1760_readl(hcd->regs + HC_INT_PTD_SKIPMAP_REG); 906 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
877 907
878 BUG_ON(!skip_map); 908 BUG_ON(!skip_map);
879 slot = __ffs(skip_map); 909 slot = __ffs(skip_map);
880 queue_entry = 1 << slot;
881
882 int_regs = INT_REGS_OFFSET + slot * sizeof(struct ptd);
883 910
884 payload = alloc_mem(priv, qtd->length); 911 enqueue_one_int_qtd(hcd, qh, slot, qtd);
885 912
886 enqueue_one_int_qtd(int_regs, payload, priv, qh, qtd->urb, slot, qtd); 913 or_map = reg_read32(hcd->regs, HC_INT_IRQ_MASK_OR_REG);
914 or_map |= (1 << slot);
915 reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, or_map);
887 916
888 or_map = isp1760_readl(hcd->regs + HC_INT_IRQ_MASK_OR_REG); 917 skip_map &= ~(1 << slot);
889 or_map |= queue_entry; 918 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map);
890 isp1760_writel(or_map, hcd->regs + HC_INT_IRQ_MASK_OR_REG);
891 919
892 skip_map &= ~queue_entry; 920 buffstatus = reg_read32(hcd->regs, HC_BUFFER_STATUS_REG);
893 isp1760_writel(skip_map, hcd->regs + HC_INT_PTD_SKIPMAP_REG);
894
895 buffstatus = isp1760_readl(hcd->regs + HC_BUFFER_STATUS_REG);
896 buffstatus |= INT_BUFFER; 921 buffstatus |= INT_BUFFER;
897 isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG); 922 reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, buffstatus);
898} 923}
899 924
900static void isp1760_urb_done(struct isp1760_hcd *priv, struct urb *urb, int status) 925static void isp1760_urb_done(struct usb_hcd *hcd, struct urb *urb)
901__releases(priv->lock) 926__releases(priv->lock)
902__acquires(priv->lock) 927__acquires(priv->lock)
903{ 928{
929 struct isp1760_hcd *priv = hcd_to_priv(hcd);
930
904 if (!urb->unlinked) { 931 if (!urb->unlinked) {
905 if (status == -EINPROGRESS) 932 if (urb->status == -EINPROGRESS)
906 status = 0; 933 urb->status = 0;
907 } 934 }
908 935
909 if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) { 936 if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) {
@@ -915,22 +942,28 @@ __acquires(priv->lock)
915 } 942 }
916 943
917 /* complete() can reenter this HCD */ 944 /* complete() can reenter this HCD */
918 usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb); 945 usb_hcd_unlink_urb_from_ep(hcd, urb);
919 spin_unlock(&priv->lock); 946 spin_unlock(&priv->lock);
920 usb_hcd_giveback_urb(priv_to_hcd(priv), urb, status); 947 usb_hcd_giveback_urb(hcd, urb, urb->status);
921 spin_lock(&priv->lock); 948 spin_lock(&priv->lock);
922} 949}
923 950
924static void isp1760_qtd_free(struct isp1760_qtd *qtd) 951static void isp1760_qtd_free(struct isp1760_qtd *qtd)
925{ 952{
953 BUG_ON(qtd->payload_addr);
926 kmem_cache_free(qtd_cachep, qtd); 954 kmem_cache_free(qtd_cachep, qtd);
927} 955}
928 956
929static struct isp1760_qtd *clean_this_qtd(struct isp1760_qtd *qtd) 957static struct isp1760_qtd *clean_this_qtd(struct isp1760_qtd *qtd,
958 struct isp1760_qh *qh)
930{ 959{
931 struct isp1760_qtd *tmp_qtd; 960 struct isp1760_qtd *tmp_qtd;
932 961
933 tmp_qtd = qtd->hw_next; 962 if (list_is_last(&qtd->qtd_list, &qh->qtd_list))
963 tmp_qtd = NULL;
964 else
965 tmp_qtd = list_entry(qtd->qtd_list.next, struct isp1760_qtd,
966 qtd_list);
934 list_del(&qtd->qtd_list); 967 list_del(&qtd->qtd_list);
935 isp1760_qtd_free(qtd); 968 isp1760_qtd_free(qtd);
936 return tmp_qtd; 969 return tmp_qtd;
@@ -941,32 +974,26 @@ static struct isp1760_qtd *clean_this_qtd(struct isp1760_qtd *qtd)
941 * isn't the last one than remove also his successor(s). 974 * isn't the last one than remove also his successor(s).
942 * Returns the QTD which is part of an new URB and should be enqueued. 975 * Returns the QTD which is part of an new URB and should be enqueued.
943 */ 976 */
944static struct isp1760_qtd *clean_up_qtdlist(struct isp1760_qtd *qtd) 977static struct isp1760_qtd *clean_up_qtdlist(struct isp1760_qtd *qtd,
978 struct isp1760_qh *qh)
945{ 979{
946 struct isp1760_qtd *tmp_qtd; 980 struct urb *urb;
947 int last_one;
948 981
982 urb = qtd->urb;
949 do { 983 do {
950 tmp_qtd = qtd->hw_next; 984 qtd = clean_this_qtd(qtd, qh);
951 last_one = qtd->status & URB_COMPLETE_NOTIFY; 985 } while (qtd && (qtd->urb == urb));
952 list_del(&qtd->qtd_list);
953 isp1760_qtd_free(qtd);
954 qtd = tmp_qtd;
955 } while (!last_one && qtd);
956 986
957 return qtd; 987 return qtd;
958} 988}
959 989
960static void do_atl_int(struct usb_hcd *usb_hcd) 990static void do_atl_int(struct usb_hcd *hcd)
961{ 991{
962 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); 992 struct isp1760_hcd *priv = hcd_to_priv(hcd);
963 u32 done_map, skip_map; 993 u32 done_map, skip_map;
964 struct ptd ptd; 994 struct ptd ptd;
965 struct urb *urb = NULL; 995 struct urb *urb;
966 u32 atl_regs_base; 996 u32 slot;
967 u32 atl_regs;
968 u32 queue_entry;
969 u32 payload;
970 u32 length; 997 u32 length;
971 u32 or_map; 998 u32 or_map;
972 u32 status = -EINVAL; 999 u32 status = -EINVAL;
@@ -976,62 +1003,36 @@ static void do_atl_int(struct usb_hcd *usb_hcd)
976 u32 rl; 1003 u32 rl;
977 u32 nakcount; 1004 u32 nakcount;
978 1005
979 done_map = isp1760_readl(usb_hcd->regs + 1006 done_map = reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG);
980 HC_ATL_PTD_DONEMAP_REG); 1007 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
981 skip_map = isp1760_readl(usb_hcd->regs +
982 HC_ATL_PTD_SKIPMAP_REG);
983 1008
984 or_map = isp1760_readl(usb_hcd->regs + HC_ATL_IRQ_MASK_OR_REG); 1009 or_map = reg_read32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG);
985 or_map &= ~done_map; 1010 or_map &= ~done_map;
986 isp1760_writel(or_map, usb_hcd->regs + HC_ATL_IRQ_MASK_OR_REG); 1011 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, or_map);
987 1012
988 atl_regs_base = ATL_REGS_OFFSET;
989 while (done_map) { 1013 while (done_map) {
990 u32 dw1;
991 u32 dw2;
992 u32 dw3;
993
994 status = 0; 1014 status = 0;
1015 priv->atl_queued--;
995 1016
996 queue_entry = __ffs(done_map); 1017 slot = __ffs(done_map);
997 done_map &= ~(1 << queue_entry); 1018 done_map &= ~(1 << slot);
998 skip_map |= 1 << queue_entry; 1019 skip_map |= (1 << slot);
999
1000 atl_regs = atl_regs_base + queue_entry * sizeof(struct ptd);
1001 1020
1002 urb = priv->atl_ints[queue_entry].urb; 1021 qtd = priv->atl_ints[slot].qtd;
1003 qtd = priv->atl_ints[queue_entry].qtd; 1022 qh = priv->atl_ints[slot].qh;
1004 qh = priv->atl_ints[queue_entry].qh;
1005 payload = priv->atl_ints[queue_entry].payload;
1006 1023
1007 if (!qh) { 1024 if (!qh) {
1008 printk(KERN_ERR "qh is 0\n"); 1025 dev_err(hcd->self.controller, "qh is 0\n");
1009 continue; 1026 continue;
1010 } 1027 }
1011 isp1760_writel(atl_regs + ISP_BANK(0), usb_hcd->regs + 1028 ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd);
1012 HC_MEMORY_REG);
1013 isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs +
1014 HC_MEMORY_REG);
1015 /*
1016 * write bank1 address twice to ensure the 90ns delay (time
1017 * between BANK0 write and the priv_read_copy() call is at
1018 * least 3*t_WHWL + 2*t_w11 = 3*25ns + 2*17ns = 109ns)
1019 */
1020 isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs +
1021 HC_MEMORY_REG);
1022 1029
1023 priv_read_copy(priv, (u32 *)&ptd, usb_hcd->regs + atl_regs + 1030 rl = (ptd.dw2 >> 25) & 0x0f;
1024 ISP_BANK(0), sizeof(ptd)); 1031 nakcount = (ptd.dw3 >> 19) & 0xf;
1025
1026 dw1 = le32_to_cpu(ptd.dw1);
1027 dw2 = le32_to_cpu(ptd.dw2);
1028 dw3 = le32_to_cpu(ptd.dw3);
1029 rl = (dw2 >> 25) & 0x0f;
1030 nakcount = (dw3 >> 19) & 0xf;
1031 1032
1032 /* Transfer Error, *but* active and no HALT -> reload */ 1033 /* Transfer Error, *but* active and no HALT -> reload */
1033 if ((dw3 & DW3_ERROR_BIT) && (dw3 & DW3_QTD_ACTIVE) && 1034 if ((ptd.dw3 & DW3_ERROR_BIT) && (ptd.dw3 & DW3_QTD_ACTIVE) &&
1034 !(dw3 & DW3_HALT_BIT)) { 1035 !(ptd.dw3 & DW3_HALT_BIT)) {
1035 1036
1036 /* according to ppriv code, we have to 1037 /* according to ppriv code, we have to
1037 * reload this one if trasfered bytes != requested bytes 1038 * reload this one if trasfered bytes != requested bytes
@@ -1040,13 +1041,14 @@ static void do_atl_int(struct usb_hcd *usb_hcd)
1040 * triggered so far. 1041 * triggered so far.
1041 */ 1042 */
1042 1043
1043 length = PTD_XFERRED_LENGTH(dw3); 1044 length = PTD_XFERRED_LENGTH(ptd.dw3);
1044 printk(KERN_ERR "Should reload now.... transfered %d " 1045 dev_err(hcd->self.controller,
1046 "Should reload now... transferred %d "
1045 "of %zu\n", length, qtd->length); 1047 "of %zu\n", length, qtd->length);
1046 BUG(); 1048 BUG();
1047 } 1049 }
1048 1050
1049 if (!nakcount && (dw3 & DW3_QTD_ACTIVE)) { 1051 if (!nakcount && (ptd.dw3 & DW3_QTD_ACTIVE)) {
1050 u32 buffstatus; 1052 u32 buffstatus;
1051 1053
1052 /* 1054 /*
@@ -1054,52 +1056,45 @@ static void do_atl_int(struct usb_hcd *usb_hcd)
1054 * device is not able to send data fast enough. 1056 * device is not able to send data fast enough.
1055 * This happens mostly on slower hardware. 1057 * This happens mostly on slower hardware.
1056 */ 1058 */
1057 printk(KERN_NOTICE "Reloading ptd %p/%p... qh %p read: "
1058 "%d of %zu done: %08x cur: %08x\n", qtd,
1059 urb, qh, PTD_XFERRED_LENGTH(dw3),
1060 qtd->length, done_map,
1061 (1 << queue_entry));
1062 1059
1063 /* RL counter = ERR counter */ 1060 /* RL counter = ERR counter */
1064 dw3 &= ~(0xf << 19); 1061 ptd.dw3 &= ~(0xf << 19);
1065 dw3 |= rl << 19; 1062 ptd.dw3 |= rl << 19;
1066 dw3 &= ~(3 << (55 - 32)); 1063 ptd.dw3 &= ~(3 << (55 - 32));
1067 dw3 |= ERR_COUNTER << (55 - 32); 1064 ptd.dw3 |= ERR_COUNTER << (55 - 32);
1068 1065
1069 /* 1066 /*
1070 * It is not needed to write skip map back because it 1067 * It is not needed to write skip map back because it
1071 * is unchanged. Just make sure that this entry is 1068 * is unchanged. Just make sure that this entry is
1072 * unskipped once it gets written to the HW. 1069 * unskipped once it gets written to the HW.
1073 */ 1070 */
1074 skip_map &= ~(1 << queue_entry); 1071 skip_map &= ~(1 << slot);
1075 or_map = isp1760_readl(usb_hcd->regs + 1072 or_map = reg_read32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG);
1076 HC_ATL_IRQ_MASK_OR_REG); 1073 or_map |= 1 << slot;
1077 or_map |= 1 << queue_entry; 1074 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, or_map);
1078 isp1760_writel(or_map, usb_hcd->regs + 1075
1079 HC_ATL_IRQ_MASK_OR_REG); 1076 ptd.dw0 |= PTD_VALID;
1080 1077 ptd_write(hcd->regs, ATL_PTD_OFFSET, slot, &ptd);
1081 ptd.dw3 = cpu_to_le32(dw3); 1078
1082 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs + 1079 priv->atl_queued++;
1083 atl_regs, sizeof(ptd)); 1080 if (priv->atl_queued == 2)
1084 1081 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE,
1085 ptd.dw0 |= cpu_to_le32(PTD_VALID); 1082 INTERRUPT_ENABLE_SOT_MASK);
1086 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs + 1083
1087 atl_regs, sizeof(ptd)); 1084 buffstatus = reg_read32(hcd->regs,
1088 1085 HC_BUFFER_STATUS_REG);
1089 buffstatus = isp1760_readl(usb_hcd->regs +
1090 HC_BUFFER_STATUS_REG);
1091 buffstatus |= ATL_BUFFER; 1086 buffstatus |= ATL_BUFFER;
1092 isp1760_writel(buffstatus, usb_hcd->regs + 1087 reg_write32(hcd->regs, HC_BUFFER_STATUS_REG,
1093 HC_BUFFER_STATUS_REG); 1088 buffstatus);
1094 continue; 1089 continue;
1095 } 1090 }
1096 1091
1097 error = check_error(&ptd); 1092 error = check_error(hcd, &ptd);
1098 if (error) { 1093 if (error) {
1099 status = error; 1094 status = error;
1100 priv->atl_ints[queue_entry].qh->toggle = 0; 1095 priv->atl_ints[slot].qh->toggle = 0;
1101 priv->atl_ints[queue_entry].qh->ping = 0; 1096 priv->atl_ints[slot].qh->ping = 0;
1102 urb->status = -EPIPE; 1097 qtd->urb->status = -EPIPE;
1103 1098
1104#if 0 1099#if 0
1105 printk(KERN_ERR "Error in %s().\n", __func__); 1100 printk(KERN_ERR "Error in %s().\n", __func__);
@@ -1110,154 +1105,123 @@ static void do_atl_int(struct usb_hcd *usb_hcd)
1110 ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7); 1105 ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7);
1111#endif 1106#endif
1112 } else { 1107 } else {
1113 if (usb_pipetype(urb->pipe) == PIPE_BULK) { 1108 priv->atl_ints[slot].qh->toggle = ptd.dw3 & (1 << 25);
1114 priv->atl_ints[queue_entry].qh->toggle = dw3 & 1109 priv->atl_ints[slot].qh->ping = ptd.dw3 & (1 << 26);
1115 (1 << 25);
1116 priv->atl_ints[queue_entry].qh->ping = dw3 &
1117 (1 << 26);
1118 }
1119 } 1110 }
1120 1111
1121 length = PTD_XFERRED_LENGTH(dw3); 1112 length = PTD_XFERRED_LENGTH(ptd.dw3);
1122 if (length) { 1113 if (length) {
1123 switch (DW1_GET_PID(dw1)) { 1114 switch (DW1_GET_PID(ptd.dw1)) {
1124 case IN_PID: 1115 case IN_PID:
1125 priv_read_copy(priv, 1116 mem_reads8(hcd->regs, qtd->payload_addr,
1126 priv->atl_ints[queue_entry].data_buffer, 1117 qtd->data_buffer, length);
1127 usb_hcd->regs + payload + ISP_BANK(1),
1128 length);
1129 1118
1130 case OUT_PID: 1119 case OUT_PID:
1131 1120
1132 urb->actual_length += length; 1121 qtd->urb->actual_length += length;
1133 1122
1134 case SETUP_PID: 1123 case SETUP_PID:
1135 break; 1124 break;
1136 } 1125 }
1137 } 1126 }
1138 1127
1139 priv->atl_ints[queue_entry].data_buffer = NULL; 1128 priv->atl_ints[slot].qtd = NULL;
1140 priv->atl_ints[queue_entry].urb = NULL; 1129 priv->atl_ints[slot].qh = NULL;
1141 priv->atl_ints[queue_entry].qtd = NULL;
1142 priv->atl_ints[queue_entry].qh = NULL;
1143 1130
1144 free_mem(priv, payload); 1131 free_mem(hcd, qtd);
1145 1132
1146 isp1760_writel(skip_map, usb_hcd->regs + 1133 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map);
1147 HC_ATL_PTD_SKIPMAP_REG);
1148 1134
1149 if (urb->status == -EPIPE) { 1135 if (qtd->urb->status == -EPIPE) {
1150 /* HALT was received */ 1136 /* HALT was received */
1151 1137
1152 qtd = clean_up_qtdlist(qtd); 1138 urb = qtd->urb;
1153 isp1760_urb_done(priv, urb, urb->status); 1139 qtd = clean_up_qtdlist(qtd, qh);
1140 isp1760_urb_done(hcd, urb);
1154 1141
1155 } else if (usb_pipebulk(urb->pipe) && (length < qtd->length)) { 1142 } else if (usb_pipebulk(qtd->urb->pipe) &&
1143 (length < qtd->length)) {
1156 /* short BULK received */ 1144 /* short BULK received */
1157 1145
1158 if (urb->transfer_flags & URB_SHORT_NOT_OK) { 1146 if (qtd->urb->transfer_flags & URB_SHORT_NOT_OK) {
1159 urb->status = -EREMOTEIO; 1147 qtd->urb->status = -EREMOTEIO;
1160 isp1760_dbg(priv, "short bulk, %d instead %zu " 1148 dev_dbg(hcd->self.controller,
1161 "with URB_SHORT_NOT_OK flag.\n", 1149 "short bulk, %d instead %zu "
1162 length, qtd->length); 1150 "with URB_SHORT_NOT_OK flag.\n",
1151 length, qtd->length);
1163 } 1152 }
1164 1153
1165 if (urb->status == -EINPROGRESS) 1154 if (qtd->urb->status == -EINPROGRESS)
1166 urb->status = 0; 1155 qtd->urb->status = 0;
1167
1168 qtd = clean_up_qtdlist(qtd);
1169 1156
1170 isp1760_urb_done(priv, urb, urb->status); 1157 urb = qtd->urb;
1158 qtd = clean_up_qtdlist(qtd, qh);
1159 isp1760_urb_done(hcd, urb);
1171 1160
1172 } else if (qtd->status & URB_COMPLETE_NOTIFY) { 1161 } else if (last_qtd_of_urb(qtd, qh)) {
1173 /* that was the last qtd of that URB */ 1162 /* that was the last qtd of that URB */
1174 1163
1175 if (urb->status == -EINPROGRESS) 1164 if (qtd->urb->status == -EINPROGRESS)
1176 urb->status = 0; 1165 qtd->urb->status = 0;
1177 1166
1178 qtd = clean_this_qtd(qtd); 1167 urb = qtd->urb;
1179 isp1760_urb_done(priv, urb, urb->status); 1168 qtd = clean_up_qtdlist(qtd, qh);
1169 isp1760_urb_done(hcd, urb);
1180 1170
1181 } else { 1171 } else {
1182 /* next QTD of this URB */ 1172 /* next QTD of this URB */
1183 1173
1184 qtd = clean_this_qtd(qtd); 1174 qtd = clean_this_qtd(qtd, qh);
1185 BUG_ON(!qtd); 1175 BUG_ON(!qtd);
1186 } 1176 }
1187 1177
1188 if (qtd) 1178 if (qtd)
1189 enqueue_an_ATL_packet(usb_hcd, qh, qtd); 1179 enqueue_an_ATL_packet(hcd, qh, qtd);
1190 1180
1191 skip_map = isp1760_readl(usb_hcd->regs + 1181 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
1192 HC_ATL_PTD_SKIPMAP_REG);
1193 } 1182 }
1183 if (priv->atl_queued <= 1)
1184 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE,
1185 INTERRUPT_ENABLE_MASK);
1194} 1186}
1195 1187
1196static void do_intl_int(struct usb_hcd *usb_hcd) 1188static void do_intl_int(struct usb_hcd *hcd)
1197{ 1189{
1198 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); 1190 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1199 u32 done_map, skip_map; 1191 u32 done_map, skip_map;
1200 struct ptd ptd; 1192 struct ptd ptd;
1201 struct urb *urb = NULL; 1193 struct urb *urb;
1202 u32 int_regs;
1203 u32 int_regs_base;
1204 u32 payload;
1205 u32 length; 1194 u32 length;
1206 u32 or_map; 1195 u32 or_map;
1207 int error; 1196 int error;
1208 u32 queue_entry; 1197 u32 slot;
1209 struct isp1760_qtd *qtd; 1198 struct isp1760_qtd *qtd;
1210 struct isp1760_qh *qh; 1199 struct isp1760_qh *qh;
1211 1200
1212 done_map = isp1760_readl(usb_hcd->regs + 1201 done_map = reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG);
1213 HC_INT_PTD_DONEMAP_REG); 1202 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
1214 skip_map = isp1760_readl(usb_hcd->regs +
1215 HC_INT_PTD_SKIPMAP_REG);
1216 1203
1217 or_map = isp1760_readl(usb_hcd->regs + HC_INT_IRQ_MASK_OR_REG); 1204 or_map = reg_read32(hcd->regs, HC_INT_IRQ_MASK_OR_REG);
1218 or_map &= ~done_map; 1205 or_map &= ~done_map;
1219 isp1760_writel(or_map, usb_hcd->regs + HC_INT_IRQ_MASK_OR_REG); 1206 reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, or_map);
1220
1221 int_regs_base = INT_REGS_OFFSET;
1222 1207
1223 while (done_map) { 1208 while (done_map) {
1224 u32 dw1; 1209 slot = __ffs(done_map);
1225 u32 dw3; 1210 done_map &= ~(1 << slot);
1211 skip_map |= (1 << slot);
1226 1212
1227 queue_entry = __ffs(done_map); 1213 qtd = priv->int_ints[slot].qtd;
1228 done_map &= ~(1 << queue_entry); 1214 qh = priv->int_ints[slot].qh;
1229 skip_map |= 1 << queue_entry;
1230
1231 int_regs = int_regs_base + queue_entry * sizeof(struct ptd);
1232 urb = priv->int_ints[queue_entry].urb;
1233 qtd = priv->int_ints[queue_entry].qtd;
1234 qh = priv->int_ints[queue_entry].qh;
1235 payload = priv->int_ints[queue_entry].payload;
1236 1215
1237 if (!qh) { 1216 if (!qh) {
1238 printk(KERN_ERR "(INT) qh is 0\n"); 1217 dev_err(hcd->self.controller, "(INT) qh is 0\n");
1239 continue; 1218 continue;
1240 } 1219 }
1241 1220
1242 isp1760_writel(int_regs + ISP_BANK(0), usb_hcd->regs + 1221 ptd_read(hcd->regs, INT_PTD_OFFSET, slot, &ptd);
1243 HC_MEMORY_REG); 1222 check_int_err_status(hcd, ptd.dw4);
1244 isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs +
1245 HC_MEMORY_REG);
1246 /*
1247 * write bank1 address twice to ensure the 90ns delay (time
1248 * between BANK0 write and the priv_read_copy() call is at
1249 * least 3*t_WHWL + 2*t_w11 = 3*25ns + 2*17ns = 92ns)
1250 */
1251 isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs +
1252 HC_MEMORY_REG);
1253 1223
1254 priv_read_copy(priv, (u32 *)&ptd, usb_hcd->regs + int_regs + 1224 error = check_error(hcd, &ptd);
1255 ISP_BANK(0), sizeof(ptd));
1256 dw1 = le32_to_cpu(ptd.dw1);
1257 dw3 = le32_to_cpu(ptd.dw3);
1258 check_int_err_status(le32_to_cpu(ptd.dw4));
1259
1260 error = check_error(&ptd);
1261 if (error) { 1225 if (error) {
1262#if 0 1226#if 0
1263 printk(KERN_ERR "Error in %s().\n", __func__); 1227 printk(KERN_ERR "Error in %s().\n", __func__);
@@ -1267,83 +1231,77 @@ static void do_intl_int(struct usb_hcd *usb_hcd)
1267 ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3, 1231 ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3,
1268 ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7); 1232 ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7);
1269#endif 1233#endif
1270 urb->status = -EPIPE; 1234 qtd->urb->status = -EPIPE;
1271 priv->int_ints[queue_entry].qh->toggle = 0; 1235 priv->int_ints[slot].qh->toggle = 0;
1272 priv->int_ints[queue_entry].qh->ping = 0; 1236 priv->int_ints[slot].qh->ping = 0;
1273 1237
1274 } else { 1238 } else {
1275 priv->int_ints[queue_entry].qh->toggle = 1239 priv->int_ints[slot].qh->toggle = ptd.dw3 & (1 << 25);
1276 dw3 & (1 << 25); 1240 priv->int_ints[slot].qh->ping = ptd.dw3 & (1 << 26);
1277 priv->int_ints[queue_entry].qh->ping = dw3 & (1 << 26);
1278 } 1241 }
1279 1242
1280 if (urb->dev->speed != USB_SPEED_HIGH) 1243 if (qtd->urb->dev->speed != USB_SPEED_HIGH)
1281 length = PTD_XFERRED_LENGTH_LO(dw3); 1244 length = PTD_XFERRED_LENGTH_LO(ptd.dw3);
1282 else 1245 else
1283 length = PTD_XFERRED_LENGTH(dw3); 1246 length = PTD_XFERRED_LENGTH(ptd.dw3);
1284 1247
1285 if (length) { 1248 if (length) {
1286 switch (DW1_GET_PID(dw1)) { 1249 switch (DW1_GET_PID(ptd.dw1)) {
1287 case IN_PID: 1250 case IN_PID:
1288 priv_read_copy(priv, 1251 mem_reads8(hcd->regs, qtd->payload_addr,
1289 priv->int_ints[queue_entry].data_buffer, 1252 qtd->data_buffer, length);
1290 usb_hcd->regs + payload + ISP_BANK(1),
1291 length);
1292 case OUT_PID: 1253 case OUT_PID:
1293 1254
1294 urb->actual_length += length; 1255 qtd->urb->actual_length += length;
1295 1256
1296 case SETUP_PID: 1257 case SETUP_PID:
1297 break; 1258 break;
1298 } 1259 }
1299 } 1260 }
1300 1261
1301 priv->int_ints[queue_entry].data_buffer = NULL; 1262 priv->int_ints[slot].qtd = NULL;
1302 priv->int_ints[queue_entry].urb = NULL; 1263 priv->int_ints[slot].qh = NULL;
1303 priv->int_ints[queue_entry].qtd = NULL;
1304 priv->int_ints[queue_entry].qh = NULL;
1305 1264
1306 isp1760_writel(skip_map, usb_hcd->regs + 1265 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map);
1307 HC_INT_PTD_SKIPMAP_REG); 1266 free_mem(hcd, qtd);
1308 free_mem(priv, payload);
1309 1267
1310 if (urb->status == -EPIPE) { 1268 if (qtd->urb->status == -EPIPE) {
1311 /* HALT received */ 1269 /* HALT received */
1312 1270
1313 qtd = clean_up_qtdlist(qtd); 1271 urb = qtd->urb;
1314 isp1760_urb_done(priv, urb, urb->status); 1272 qtd = clean_up_qtdlist(qtd, qh);
1273 isp1760_urb_done(hcd, urb);
1315 1274
1316 } else if (qtd->status & URB_COMPLETE_NOTIFY) { 1275 } else if (last_qtd_of_urb(qtd, qh)) {
1317 1276
1318 if (urb->status == -EINPROGRESS) 1277 if (qtd->urb->status == -EINPROGRESS)
1319 urb->status = 0; 1278 qtd->urb->status = 0;
1320 1279
1321 qtd = clean_this_qtd(qtd); 1280 urb = qtd->urb;
1322 isp1760_urb_done(priv, urb, urb->status); 1281 qtd = clean_up_qtdlist(qtd, qh);
1282 isp1760_urb_done(hcd, urb);
1323 1283
1324 } else { 1284 } else {
1325 /* next QTD of this URB */ 1285 /* next QTD of this URB */
1326 1286
1327 qtd = clean_this_qtd(qtd); 1287 qtd = clean_this_qtd(qtd, qh);
1328 BUG_ON(!qtd); 1288 BUG_ON(!qtd);
1329 } 1289 }
1330 1290
1331 if (qtd) 1291 if (qtd)
1332 enqueue_an_INT_packet(usb_hcd, qh, qtd); 1292 enqueue_an_INT_packet(hcd, qh, qtd);
1333 1293
1334 skip_map = isp1760_readl(usb_hcd->regs + 1294 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
1335 HC_INT_PTD_SKIPMAP_REG);
1336 } 1295 }
1337} 1296}
1338 1297
1339#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) 1298static struct isp1760_qh *qh_make(struct usb_hcd *hcd, struct urb *urb,
1340static struct isp1760_qh *qh_make(struct isp1760_hcd *priv, struct urb *urb,
1341 gfp_t flags) 1299 gfp_t flags)
1342{ 1300{
1343 struct isp1760_qh *qh; 1301 struct isp1760_qh *qh;
1344 int is_input, type; 1302 int is_input, type;
1345 1303
1346 qh = isp1760_qh_alloc(priv, flags); 1304 qh = isp1760_qh_alloc(flags);
1347 if (!qh) 1305 if (!qh)
1348 return qh; 1306 return qh;
1349 1307
@@ -1353,29 +1311,6 @@ static struct isp1760_qh *qh_make(struct isp1760_hcd *priv, struct urb *urb,
1353 is_input = usb_pipein(urb->pipe); 1311 is_input = usb_pipein(urb->pipe);
1354 type = usb_pipetype(urb->pipe); 1312 type = usb_pipetype(urb->pipe);
1355 1313
1356 if (type == PIPE_INTERRUPT) {
1357
1358 if (urb->dev->speed == USB_SPEED_HIGH) {
1359
1360 qh->period = urb->interval >> 3;
1361 if (qh->period == 0 && urb->interval != 1) {
1362 /* NOTE interval 2 or 4 uframes could work.
1363 * But interval 1 scheduling is simpler, and
1364 * includes high bandwidth.
1365 */
1366 printk(KERN_ERR "intr period %d uframes, NYET!",
1367 urb->interval);
1368 qh_destroy(qh);
1369 return NULL;
1370 }
1371 } else {
1372 qh->period = urb->interval;
1373 }
1374 }
1375
1376 /* support for tt scheduling, and access to toggles */
1377 qh->dev = urb->dev;
1378
1379 if (!usb_pipecontrol(urb->pipe)) 1314 if (!usb_pipecontrol(urb->pipe))
1380 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1315 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input,
1381 1); 1316 1);
@@ -1388,43 +1323,27 @@ static struct isp1760_qh *qh_make(struct isp1760_hcd *priv, struct urb *urb,
1388 * Returns null if it can't allocate a QH it needs to. 1323 * Returns null if it can't allocate a QH it needs to.
1389 * If the QH has TDs (urbs) already, that's great. 1324 * If the QH has TDs (urbs) already, that's great.
1390 */ 1325 */
1391static struct isp1760_qh *qh_append_tds(struct isp1760_hcd *priv, 1326static struct isp1760_qh *qh_append_tds(struct usb_hcd *hcd,
1392 struct urb *urb, struct list_head *qtd_list, int epnum, 1327 struct urb *urb, struct list_head *qtd_list, int epnum,
1393 void **ptr) 1328 void **ptr)
1394{ 1329{
1395 struct isp1760_qh *qh; 1330 struct isp1760_qh *qh;
1396 struct isp1760_qtd *qtd;
1397 struct isp1760_qtd *prev_qtd;
1398 1331
1399 qh = (struct isp1760_qh *)*ptr; 1332 qh = (struct isp1760_qh *)*ptr;
1400 if (!qh) { 1333 if (!qh) {
1401 /* can't sleep here, we have priv->lock... */ 1334 /* can't sleep here, we have priv->lock... */
1402 qh = qh_make(priv, urb, GFP_ATOMIC); 1335 qh = qh_make(hcd, urb, GFP_ATOMIC);
1403 if (!qh) 1336 if (!qh)
1404 return qh; 1337 return qh;
1405 *ptr = qh; 1338 *ptr = qh;
1406 } 1339 }
1407 1340
1408 qtd = list_entry(qtd_list->next, struct isp1760_qtd,
1409 qtd_list);
1410 if (!list_empty(&qh->qtd_list))
1411 prev_qtd = list_entry(qh->qtd_list.prev,
1412 struct isp1760_qtd, qtd_list);
1413 else
1414 prev_qtd = NULL;
1415
1416 list_splice(qtd_list, qh->qtd_list.prev); 1341 list_splice(qtd_list, qh->qtd_list.prev);
1417 if (prev_qtd) {
1418 BUG_ON(prev_qtd->hw_next);
1419 prev_qtd->hw_next = qtd;
1420 }
1421 1342
1422 urb->hcpriv = qh;
1423 return qh; 1343 return qh;
1424} 1344}
1425 1345
1426static void qtd_list_free(struct isp1760_hcd *priv, struct urb *urb, 1346static void qtd_list_free(struct urb *urb, struct list_head *qtd_list)
1427 struct list_head *qtd_list)
1428{ 1347{
1429 struct list_head *entry, *temp; 1348 struct list_head *entry, *temp;
1430 1349
@@ -1437,9 +1356,10 @@ static void qtd_list_free(struct isp1760_hcd *priv, struct urb *urb,
1437 } 1356 }
1438} 1357}
1439 1358
1440static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb, 1359static int isp1760_prepare_enqueue(struct usb_hcd *hcd, struct urb *urb,
1441 struct list_head *qtd_list, gfp_t mem_flags, packet_enqueue *p) 1360 struct list_head *qtd_list, gfp_t mem_flags, packet_enqueue *p)
1442{ 1361{
1362 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1443 struct isp1760_qtd *qtd; 1363 struct isp1760_qtd *qtd;
1444 int epnum; 1364 int epnum;
1445 unsigned long flags; 1365 unsigned long flags;
@@ -1451,11 +1371,11 @@ static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb,
1451 epnum = urb->ep->desc.bEndpointAddress; 1371 epnum = urb->ep->desc.bEndpointAddress;
1452 1372
1453 spin_lock_irqsave(&priv->lock, flags); 1373 spin_lock_irqsave(&priv->lock, flags);
1454 if (!HCD_HW_ACCESSIBLE(priv_to_hcd(priv))) { 1374 if (!HCD_HW_ACCESSIBLE(hcd)) {
1455 rc = -ESHUTDOWN; 1375 rc = -ESHUTDOWN;
1456 goto done; 1376 goto done;
1457 } 1377 }
1458 rc = usb_hcd_link_urb_to_ep(priv_to_hcd(priv), urb); 1378 rc = usb_hcd_link_urb_to_ep(hcd, urb);
1459 if (rc) 1379 if (rc)
1460 goto done; 1380 goto done;
1461 1381
@@ -1465,25 +1385,24 @@ static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb,
1465 else 1385 else
1466 qh_busy = 0; 1386 qh_busy = 0;
1467 1387
1468 qh = qh_append_tds(priv, urb, qtd_list, epnum, &urb->ep->hcpriv); 1388 qh = qh_append_tds(hcd, urb, qtd_list, epnum, &urb->ep->hcpriv);
1469 if (!qh) { 1389 if (!qh) {
1470 usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb); 1390 usb_hcd_unlink_urb_from_ep(hcd, urb);
1471 rc = -ENOMEM; 1391 rc = -ENOMEM;
1472 goto done; 1392 goto done;
1473 } 1393 }
1474 1394
1475 if (!qh_busy) 1395 if (!qh_busy)
1476 p(priv_to_hcd(priv), qh, qtd); 1396 p(hcd, qh, qtd);
1477 1397
1478done: 1398done:
1479 spin_unlock_irqrestore(&priv->lock, flags); 1399 spin_unlock_irqrestore(&priv->lock, flags);
1480 if (!qh) 1400 if (!qh)
1481 qtd_list_free(priv, urb, qtd_list); 1401 qtd_list_free(urb, qtd_list);
1482 return rc; 1402 return rc;
1483} 1403}
1484 1404
1485static struct isp1760_qtd *isp1760_qtd_alloc(struct isp1760_hcd *priv, 1405static struct isp1760_qtd *isp1760_qtd_alloc(gfp_t flags)
1486 gfp_t flags)
1487{ 1406{
1488 struct isp1760_qtd *qtd; 1407 struct isp1760_qtd *qtd;
1489 1408
@@ -1497,10 +1416,11 @@ static struct isp1760_qtd *isp1760_qtd_alloc(struct isp1760_hcd *priv,
1497/* 1416/*
1498 * create a list of filled qtds for this URB; won't link into qh. 1417 * create a list of filled qtds for this URB; won't link into qh.
1499 */ 1418 */
1500static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv, 1419#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
1420static struct list_head *qh_urb_transaction(struct usb_hcd *hcd,
1501 struct urb *urb, struct list_head *head, gfp_t flags) 1421 struct urb *urb, struct list_head *head, gfp_t flags)
1502{ 1422{
1503 struct isp1760_qtd *qtd, *qtd_prev; 1423 struct isp1760_qtd *qtd;
1504 void *buf; 1424 void *buf;
1505 int len, maxpacket; 1425 int len, maxpacket;
1506 int is_input; 1426 int is_input;
@@ -1509,7 +1429,7 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv,
1509 /* 1429 /*
1510 * URBs map to sequences of QTDs: one logical transaction 1430 * URBs map to sequences of QTDs: one logical transaction
1511 */ 1431 */
1512 qtd = isp1760_qtd_alloc(priv, flags); 1432 qtd = isp1760_qtd_alloc(flags);
1513 if (!qtd) 1433 if (!qtd)
1514 return NULL; 1434 return NULL;
1515 1435
@@ -1529,13 +1449,10 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv,
1529 token | SETUP_PID); 1449 token | SETUP_PID);
1530 1450
1531 /* ... and always at least one more pid */ 1451 /* ... and always at least one more pid */
1532 token ^= DATA_TOGGLE; 1452 qtd = isp1760_qtd_alloc(flags);
1533 qtd_prev = qtd;
1534 qtd = isp1760_qtd_alloc(priv, flags);
1535 if (!qtd) 1453 if (!qtd)
1536 goto cleanup; 1454 goto cleanup;
1537 qtd->urb = urb; 1455 qtd->urb = urb;
1538 qtd_prev->hw_next = qtd;
1539 list_add_tail(&qtd->qtd_list, head); 1456 list_add_tail(&qtd->qtd_list, head);
1540 1457
1541 /* for zero length DATA stages, STATUS is always IN */ 1458 /* for zero length DATA stages, STATUS is always IN */
@@ -1565,7 +1482,7 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv,
1565 1482
1566 if (!buf && len) { 1483 if (!buf && len) {
1567 /* XXX This looks like usb storage / SCSI bug */ 1484 /* XXX This looks like usb storage / SCSI bug */
1568 printk(KERN_ERR "buf is null, dma is %08lx len is %d\n", 1485 dev_err(hcd->self.controller, "buf is null, dma is %08lx len is %d\n",
1569 (long unsigned)urb->transfer_dma, len); 1486 (long unsigned)urb->transfer_dma, len);
1570 WARN_ON(1); 1487 WARN_ON(1);
1571 } 1488 }
@@ -1574,19 +1491,13 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv,
1574 len -= this_qtd_len; 1491 len -= this_qtd_len;
1575 buf += this_qtd_len; 1492 buf += this_qtd_len;
1576 1493
1577 /* qh makes control packets use qtd toggle; maybe switch it */
1578 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
1579 token ^= DATA_TOGGLE;
1580
1581 if (len <= 0) 1494 if (len <= 0)
1582 break; 1495 break;
1583 1496
1584 qtd_prev = qtd; 1497 qtd = isp1760_qtd_alloc(flags);
1585 qtd = isp1760_qtd_alloc(priv, flags);
1586 if (!qtd) 1498 if (!qtd)
1587 goto cleanup; 1499 goto cleanup;
1588 qtd->urb = urb; 1500 qtd->urb = urb;
1589 qtd_prev->hw_next = qtd;
1590 list_add_tail(&qtd->qtd_list, head); 1501 list_add_tail(&qtd->qtd_list, head);
1591 } 1502 }
1592 1503
@@ -1601,20 +1512,16 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv,
1601 one_more = 1; 1512 one_more = 1;
1602 /* "in" <--> "out" */ 1513 /* "in" <--> "out" */
1603 token ^= IN_PID; 1514 token ^= IN_PID;
1604 /* force DATA1 */
1605 token |= DATA_TOGGLE;
1606 } else if (usb_pipebulk(urb->pipe) 1515 } else if (usb_pipebulk(urb->pipe)
1607 && (urb->transfer_flags & URB_ZERO_PACKET) 1516 && (urb->transfer_flags & URB_ZERO_PACKET)
1608 && !(urb->transfer_buffer_length % maxpacket)) { 1517 && !(urb->transfer_buffer_length % maxpacket)) {
1609 one_more = 1; 1518 one_more = 1;
1610 } 1519 }
1611 if (one_more) { 1520 if (one_more) {
1612 qtd_prev = qtd; 1521 qtd = isp1760_qtd_alloc(flags);
1613 qtd = isp1760_qtd_alloc(priv, flags);
1614 if (!qtd) 1522 if (!qtd)
1615 goto cleanup; 1523 goto cleanup;
1616 qtd->urb = urb; 1524 qtd->urb = urb;
1617 qtd_prev->hw_next = qtd;
1618 list_add_tail(&qtd->qtd_list, head); 1525 list_add_tail(&qtd->qtd_list, head);
1619 1526
1620 /* never any data in such packets */ 1527 /* never any data in such packets */
@@ -1622,18 +1529,17 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv,
1622 } 1529 }
1623 } 1530 }
1624 1531
1625 qtd->status = URB_COMPLETE_NOTIFY; 1532 qtd->status = 0;
1626 return head; 1533 return head;
1627 1534
1628cleanup: 1535cleanup:
1629 qtd_list_free(priv, urb, head); 1536 qtd_list_free(urb, head);
1630 return NULL; 1537 return NULL;
1631} 1538}
1632 1539
1633static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, 1540static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1634 gfp_t mem_flags) 1541 gfp_t mem_flags)
1635{ 1542{
1636 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1637 struct list_head qtd_list; 1543 struct list_head qtd_list;
1638 packet_enqueue *pe; 1544 packet_enqueue *pe;
1639 1545
@@ -1642,29 +1548,27 @@ static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1642 switch (usb_pipetype(urb->pipe)) { 1548 switch (usb_pipetype(urb->pipe)) {
1643 case PIPE_CONTROL: 1549 case PIPE_CONTROL:
1644 case PIPE_BULK: 1550 case PIPE_BULK:
1645 1551 if (!qh_urb_transaction(hcd, urb, &qtd_list, mem_flags))
1646 if (!qh_urb_transaction(priv, urb, &qtd_list, mem_flags))
1647 return -ENOMEM; 1552 return -ENOMEM;
1648 pe = enqueue_an_ATL_packet; 1553 pe = enqueue_an_ATL_packet;
1649 break; 1554 break;
1650 1555
1651 case PIPE_INTERRUPT: 1556 case PIPE_INTERRUPT:
1652 if (!qh_urb_transaction(priv, urb, &qtd_list, mem_flags)) 1557 if (!qh_urb_transaction(hcd, urb, &qtd_list, mem_flags))
1653 return -ENOMEM; 1558 return -ENOMEM;
1654 pe = enqueue_an_INT_packet; 1559 pe = enqueue_an_INT_packet;
1655 break; 1560 break;
1656 1561
1657 case PIPE_ISOCHRONOUS: 1562 case PIPE_ISOCHRONOUS:
1658 printk(KERN_ERR "PIPE_ISOCHRONOUS ain't supported\n"); 1563 dev_err(hcd->self.controller, "PIPE_ISOCHRONOUS ain't supported\n");
1659 default: 1564 default:
1660 return -EPIPE; 1565 return -EPIPE;
1661 } 1566 }
1662 1567
1663 return isp1760_prepare_enqueue(priv, urb, &qtd_list, mem_flags, pe); 1568 return isp1760_prepare_enqueue(hcd, urb, &qtd_list, mem_flags, pe);
1664} 1569}
1665 1570
1666static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, 1571static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1667 int status)
1668{ 1572{
1669 struct isp1760_hcd *priv = hcd_to_priv(hcd); 1573 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1670 struct inter_packet_info *ints; 1574 struct inter_packet_info *ints;
@@ -1681,7 +1585,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1681 1585
1682 case PIPE_INTERRUPT: 1586 case PIPE_INTERRUPT:
1683 ints = priv->int_ints; 1587 ints = priv->int_ints;
1684 reg_base = INT_REGS_OFFSET; 1588 reg_base = INT_PTD_OFFSET;
1685 or_reg = HC_INT_IRQ_MASK_OR_REG; 1589 or_reg = HC_INT_IRQ_MASK_OR_REG;
1686 skip_reg = HC_INT_PTD_SKIPMAP_REG; 1590 skip_reg = HC_INT_PTD_SKIPMAP_REG;
1687 pe = enqueue_an_INT_packet; 1591 pe = enqueue_an_INT_packet;
@@ -1689,7 +1593,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1689 1593
1690 default: 1594 default:
1691 ints = priv->atl_ints; 1595 ints = priv->atl_ints;
1692 reg_base = ATL_REGS_OFFSET; 1596 reg_base = ATL_PTD_OFFSET;
1693 or_reg = HC_ATL_IRQ_MASK_OR_REG; 1597 or_reg = HC_ATL_IRQ_MASK_OR_REG;
1694 skip_reg = HC_ATL_PTD_SKIPMAP_REG; 1598 skip_reg = HC_ATL_PTD_SKIPMAP_REG;
1695 pe = enqueue_an_ATL_packet; 1599 pe = enqueue_an_ATL_packet;
@@ -1700,81 +1604,84 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1700 spin_lock_irqsave(&priv->lock, flags); 1604 spin_lock_irqsave(&priv->lock, flags);
1701 1605
1702 for (i = 0; i < 32; i++) { 1606 for (i = 0; i < 32; i++) {
1703 if (ints->urb == urb) { 1607 if (!ints[i].qh)
1608 continue;
1609 BUG_ON(!ints[i].qtd);
1610
1611 if (ints[i].qtd->urb == urb) {
1704 u32 skip_map; 1612 u32 skip_map;
1705 u32 or_map; 1613 u32 or_map;
1706 struct isp1760_qtd *qtd; 1614 struct isp1760_qtd *qtd;
1707 struct isp1760_qh *qh = ints->qh; 1615 struct isp1760_qh *qh;
1708 1616
1709 skip_map = isp1760_readl(hcd->regs + skip_reg); 1617 skip_map = reg_read32(hcd->regs, skip_reg);
1710 skip_map |= 1 << i; 1618 skip_map |= 1 << i;
1711 isp1760_writel(skip_map, hcd->regs + skip_reg); 1619 reg_write32(hcd->regs, skip_reg, skip_map);
1712 1620
1713 or_map = isp1760_readl(hcd->regs + or_reg); 1621 or_map = reg_read32(hcd->regs, or_reg);
1714 or_map &= ~(1 << i); 1622 or_map &= ~(1 << i);
1715 isp1760_writel(or_map, hcd->regs + or_reg); 1623 reg_write32(hcd->regs, or_reg, or_map);
1624
1625 ptd_write(hcd->regs, reg_base, i, &ptd);
1716 1626
1717 priv_write_copy(priv, (u32 *)&ptd, hcd->regs + reg_base 1627 qtd = ints[i].qtd;
1718 + i * sizeof(ptd), sizeof(ptd)); 1628 qh = ints[i].qh;
1719 qtd = ints->qtd;
1720 qtd = clean_up_qtdlist(qtd);
1721 1629
1722 free_mem(priv, ints->payload); 1630 free_mem(hcd, qtd);
1631 qtd = clean_up_qtdlist(qtd, qh);
1723 1632
1724 ints->urb = NULL; 1633 ints[i].qh = NULL;
1725 ints->qh = NULL; 1634 ints[i].qtd = NULL;
1726 ints->qtd = NULL;
1727 ints->data_buffer = NULL;
1728 ints->payload = 0;
1729 1635
1730 isp1760_urb_done(priv, urb, status); 1636 isp1760_urb_done(hcd, urb);
1731 if (qtd) 1637 if (qtd)
1732 pe(hcd, qh, qtd); 1638 pe(hcd, qh, qtd);
1733 break; 1639 break;
1734 1640
1735 } else if (ints->qtd) { 1641 } else {
1736 struct isp1760_qtd *qtd, *prev_qtd = ints->qtd; 1642 struct isp1760_qtd *qtd;
1737 1643
1738 for (qtd = ints->qtd->hw_next; qtd; qtd = qtd->hw_next) { 1644 list_for_each_entry(qtd, &ints[i].qtd->qtd_list,
1645 qtd_list) {
1739 if (qtd->urb == urb) { 1646 if (qtd->urb == urb) {
1740 prev_qtd->hw_next = clean_up_qtdlist(qtd); 1647 clean_up_qtdlist(qtd, ints[i].qh);
1741 isp1760_urb_done(priv, urb, status); 1648 isp1760_urb_done(hcd, urb);
1649 qtd = NULL;
1742 break; 1650 break;
1743 } 1651 }
1744 prev_qtd = qtd;
1745 } 1652 }
1746 /* we found the urb before the end of the list */ 1653
1747 if (qtd) 1654 /* We found the urb before the last slot */
1655 if (!qtd)
1748 break; 1656 break;
1749 } 1657 }
1750 ints++;
1751 } 1658 }
1752 1659
1753 spin_unlock_irqrestore(&priv->lock, flags); 1660 spin_unlock_irqrestore(&priv->lock, flags);
1754 return 0; 1661 return 0;
1755} 1662}
1756 1663
1757static irqreturn_t isp1760_irq(struct usb_hcd *usb_hcd) 1664static irqreturn_t isp1760_irq(struct usb_hcd *hcd)
1758{ 1665{
1759 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); 1666 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1760 u32 imask; 1667 u32 imask;
1761 irqreturn_t irqret = IRQ_NONE; 1668 irqreturn_t irqret = IRQ_NONE;
1762 1669
1763 spin_lock(&priv->lock); 1670 spin_lock(&priv->lock);
1764 1671
1765 if (!(usb_hcd->state & HC_STATE_RUNNING)) 1672 if (!(hcd->state & HC_STATE_RUNNING))
1766 goto leave; 1673 goto leave;
1767 1674
1768 imask = isp1760_readl(usb_hcd->regs + HC_INTERRUPT_REG); 1675 imask = reg_read32(hcd->regs, HC_INTERRUPT_REG);
1769 if (unlikely(!imask)) 1676 if (unlikely(!imask))
1770 goto leave; 1677 goto leave;
1771 1678
1772 isp1760_writel(imask, usb_hcd->regs + HC_INTERRUPT_REG); 1679 reg_write32(hcd->regs, HC_INTERRUPT_REG, imask);
1773 if (imask & HC_ATL_INT) 1680 if (imask & (HC_ATL_INT | HC_SOT_INT))
1774 do_atl_int(usb_hcd); 1681 do_atl_int(hcd);
1775 1682
1776 if (imask & HC_INTL_INT) 1683 if (imask & HC_INTL_INT)
1777 do_intl_int(usb_hcd); 1684 do_intl_int(hcd);
1778 1685
1779 irqret = IRQ_HANDLED; 1686 irqret = IRQ_HANDLED;
1780leave: 1687leave:
@@ -1799,12 +1706,12 @@ static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf)
1799 mask = PORT_CSC; 1706 mask = PORT_CSC;
1800 1707
1801 spin_lock_irqsave(&priv->lock, flags); 1708 spin_lock_irqsave(&priv->lock, flags);
1802 temp = isp1760_readl(hcd->regs + HC_PORTSC1); 1709 temp = reg_read32(hcd->regs, HC_PORTSC1);
1803 1710
1804 if (temp & PORT_OWNER) { 1711 if (temp & PORT_OWNER) {
1805 if (temp & PORT_CSC) { 1712 if (temp & PORT_CSC) {
1806 temp &= ~PORT_CSC; 1713 temp &= ~PORT_CSC;
1807 isp1760_writel(temp, hcd->regs + HC_PORTSC1); 1714 reg_write32(hcd->regs, HC_PORTSC1, temp);
1808 goto done; 1715 goto done;
1809 } 1716 }
1810 } 1717 }
@@ -1844,9 +1751,9 @@ static void isp1760_hub_descriptor(struct isp1760_hcd *priv,
1844 temp = 1 + (ports / 8); 1751 temp = 1 + (ports / 8);
1845 desc->bDescLength = 7 + 2 * temp; 1752 desc->bDescLength = 7 + 2 * temp;
1846 1753
1847 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 1754 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
1848 memset(&desc->bitmap[0], 0, temp); 1755 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
1849 memset(&desc->bitmap[temp], 0xff, temp); 1756 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
1850 1757
1851 /* per-port overcurrent reporting */ 1758 /* per-port overcurrent reporting */
1852 temp = 0x0008; 1759 temp = 0x0008;
@@ -1861,8 +1768,8 @@ static void isp1760_hub_descriptor(struct isp1760_hcd *priv,
1861 1768
1862#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) 1769#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
1863 1770
1864static int check_reset_complete(struct isp1760_hcd *priv, int index, 1771static int check_reset_complete(struct usb_hcd *hcd, int index,
1865 u32 __iomem *status_reg, int port_status) 1772 int port_status)
1866{ 1773{
1867 if (!(port_status & PORT_CONNECT)) 1774 if (!(port_status & PORT_CONNECT))
1868 return port_status; 1775 return port_status;
@@ -1870,15 +1777,17 @@ static int check_reset_complete(struct isp1760_hcd *priv, int index,
1870 /* if reset finished and it's still not enabled -- handoff */ 1777 /* if reset finished and it's still not enabled -- handoff */
1871 if (!(port_status & PORT_PE)) { 1778 if (!(port_status & PORT_PE)) {
1872 1779
1873 printk(KERN_ERR "port %d full speed --> companion\n", 1780 dev_err(hcd->self.controller,
1874 index + 1); 1781 "port %d full speed --> companion\n",
1782 index + 1);
1875 1783
1876 port_status |= PORT_OWNER; 1784 port_status |= PORT_OWNER;
1877 port_status &= ~PORT_RWC_BITS; 1785 port_status &= ~PORT_RWC_BITS;
1878 isp1760_writel(port_status, status_reg); 1786 reg_write32(hcd->regs, HC_PORTSC1, port_status);
1879 1787
1880 } else 1788 } else
1881 printk(KERN_ERR "port %d high speed\n", index + 1); 1789 dev_err(hcd->self.controller, "port %d high speed\n",
1790 index + 1);
1882 1791
1883 return port_status; 1792 return port_status;
1884} 1793}
@@ -1888,7 +1797,6 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1888{ 1797{
1889 struct isp1760_hcd *priv = hcd_to_priv(hcd); 1798 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1890 int ports = HCS_N_PORTS(priv->hcs_params); 1799 int ports = HCS_N_PORTS(priv->hcs_params);
1891 u32 __iomem *status_reg = hcd->regs + HC_PORTSC1;
1892 u32 temp, status; 1800 u32 temp, status;
1893 unsigned long flags; 1801 unsigned long flags;
1894 int retval = 0; 1802 int retval = 0;
@@ -1917,7 +1825,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1917 if (!wIndex || wIndex > ports) 1825 if (!wIndex || wIndex > ports)
1918 goto error; 1826 goto error;
1919 wIndex--; 1827 wIndex--;
1920 temp = isp1760_readl(status_reg); 1828 temp = reg_read32(hcd->regs, HC_PORTSC1);
1921 1829
1922 /* 1830 /*
1923 * Even if OWNER is set, so the port is owned by the 1831 * Even if OWNER is set, so the port is owned by the
@@ -1928,7 +1836,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1928 1836
1929 switch (wValue) { 1837 switch (wValue) {
1930 case USB_PORT_FEAT_ENABLE: 1838 case USB_PORT_FEAT_ENABLE:
1931 isp1760_writel(temp & ~PORT_PE, status_reg); 1839 reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_PE);
1932 break; 1840 break;
1933 case USB_PORT_FEAT_C_ENABLE: 1841 case USB_PORT_FEAT_C_ENABLE:
1934 /* XXX error? */ 1842 /* XXX error? */
@@ -1942,8 +1850,8 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1942 goto error; 1850 goto error;
1943 /* resume signaling for 20 msec */ 1851 /* resume signaling for 20 msec */
1944 temp &= ~(PORT_RWC_BITS); 1852 temp &= ~(PORT_RWC_BITS);
1945 isp1760_writel(temp | PORT_RESUME, 1853 reg_write32(hcd->regs, HC_PORTSC1,
1946 status_reg); 1854 temp | PORT_RESUME);
1947 priv->reset_done = jiffies + 1855 priv->reset_done = jiffies +
1948 msecs_to_jiffies(20); 1856 msecs_to_jiffies(20);
1949 } 1857 }
@@ -1953,11 +1861,11 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1953 break; 1861 break;
1954 case USB_PORT_FEAT_POWER: 1862 case USB_PORT_FEAT_POWER:
1955 if (HCS_PPC(priv->hcs_params)) 1863 if (HCS_PPC(priv->hcs_params))
1956 isp1760_writel(temp & ~PORT_POWER, status_reg); 1864 reg_write32(hcd->regs, HC_PORTSC1,
1865 temp & ~PORT_POWER);
1957 break; 1866 break;
1958 case USB_PORT_FEAT_C_CONNECTION: 1867 case USB_PORT_FEAT_C_CONNECTION:
1959 isp1760_writel(temp | PORT_CSC, 1868 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_CSC);
1960 status_reg);
1961 break; 1869 break;
1962 case USB_PORT_FEAT_C_OVER_CURRENT: 1870 case USB_PORT_FEAT_C_OVER_CURRENT:
1963 /* XXX error ?*/ 1871 /* XXX error ?*/
@@ -1968,7 +1876,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1968 default: 1876 default:
1969 goto error; 1877 goto error;
1970 } 1878 }
1971 isp1760_readl(hcd->regs + HC_USBCMD); 1879 reg_read32(hcd->regs, HC_USBCMD);
1972 break; 1880 break;
1973 case GetHubDescriptor: 1881 case GetHubDescriptor:
1974 isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *) 1882 isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *)
@@ -1983,7 +1891,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1983 goto error; 1891 goto error;
1984 wIndex--; 1892 wIndex--;
1985 status = 0; 1893 status = 0;
1986 temp = isp1760_readl(status_reg); 1894 temp = reg_read32(hcd->regs, HC_PORTSC1);
1987 1895
1988 /* wPortChange bits */ 1896 /* wPortChange bits */
1989 if (temp & PORT_CSC) 1897 if (temp & PORT_CSC)
@@ -1992,7 +1900,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1992 1900
1993 /* whoever resumes must GetPortStatus to complete it!! */ 1901 /* whoever resumes must GetPortStatus to complete it!! */
1994 if (temp & PORT_RESUME) { 1902 if (temp & PORT_RESUME) {
1995 printk(KERN_ERR "Port resume should be skipped.\n"); 1903 dev_err(hcd->self.controller, "Port resume should be skipped.\n");
1996 1904
1997 /* Remote Wakeup received? */ 1905 /* Remote Wakeup received? */
1998 if (!priv->reset_done) { 1906 if (!priv->reset_done) {
@@ -2000,8 +1908,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2000 priv->reset_done = jiffies 1908 priv->reset_done = jiffies
2001 + msecs_to_jiffies(20); 1909 + msecs_to_jiffies(20);
2002 /* check the port again */ 1910 /* check the port again */
2003 mod_timer(&priv_to_hcd(priv)->rh_timer, 1911 mod_timer(&hcd->rh_timer, priv->reset_done);
2004 priv->reset_done);
2005 } 1912 }
2006 1913
2007 /* resume completed? */ 1914 /* resume completed? */
@@ -2011,14 +1918,13 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2011 priv->reset_done = 0; 1918 priv->reset_done = 0;
2012 1919
2013 /* stop resume signaling */ 1920 /* stop resume signaling */
2014 temp = isp1760_readl(status_reg); 1921 temp = reg_read32(hcd->regs, HC_PORTSC1);
2015 isp1760_writel( 1922 reg_write32(hcd->regs, HC_PORTSC1,
2016 temp & ~(PORT_RWC_BITS | PORT_RESUME), 1923 temp & ~(PORT_RWC_BITS | PORT_RESUME));
2017 status_reg); 1924 retval = handshake(hcd, HC_PORTSC1,
2018 retval = handshake(priv, status_reg,
2019 PORT_RESUME, 0, 2000 /* 2msec */); 1925 PORT_RESUME, 0, 2000 /* 2msec */);
2020 if (retval != 0) { 1926 if (retval != 0) {
2021 isp1760_err(priv, 1927 dev_err(hcd->self.controller,
2022 "port %d resume error %d\n", 1928 "port %d resume error %d\n",
2023 wIndex + 1, retval); 1929 wIndex + 1, retval);
2024 goto error; 1930 goto error;
@@ -2035,22 +1941,21 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2035 priv->reset_done = 0; 1941 priv->reset_done = 0;
2036 1942
2037 /* force reset to complete */ 1943 /* force reset to complete */
2038 isp1760_writel(temp & ~PORT_RESET, 1944 reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_RESET);
2039 status_reg);
2040 /* REVISIT: some hardware needs 550+ usec to clear 1945 /* REVISIT: some hardware needs 550+ usec to clear
2041 * this bit; seems too long to spin routinely... 1946 * this bit; seems too long to spin routinely...
2042 */ 1947 */
2043 retval = handshake(priv, status_reg, 1948 retval = handshake(hcd, HC_PORTSC1,
2044 PORT_RESET, 0, 750); 1949 PORT_RESET, 0, 750);
2045 if (retval != 0) { 1950 if (retval != 0) {
2046 isp1760_err(priv, "port %d reset error %d\n", 1951 dev_err(hcd->self.controller, "port %d reset error %d\n",
2047 wIndex + 1, retval); 1952 wIndex + 1, retval);
2048 goto error; 1953 goto error;
2049 } 1954 }
2050 1955
2051 /* see what we found out */ 1956 /* see what we found out */
2052 temp = check_reset_complete(priv, wIndex, status_reg, 1957 temp = check_reset_complete(hcd, wIndex,
2053 isp1760_readl(status_reg)); 1958 reg_read32(hcd->regs, HC_PORTSC1));
2054 } 1959 }
2055 /* 1960 /*
2056 * Even if OWNER is set, there's no harm letting khubd 1961 * Even if OWNER is set, there's no harm letting khubd
@@ -2059,12 +1964,12 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2059 */ 1964 */
2060 1965
2061 if (temp & PORT_OWNER) 1966 if (temp & PORT_OWNER)
2062 printk(KERN_ERR "Warning: PORT_OWNER is set\n"); 1967 dev_err(hcd->self.controller, "PORT_OWNER is set\n");
2063 1968
2064 if (temp & PORT_CONNECT) { 1969 if (temp & PORT_CONNECT) {
2065 status |= USB_PORT_STAT_CONNECTION; 1970 status |= USB_PORT_STAT_CONNECTION;
2066 /* status may be from integrated TT */ 1971 /* status may be from integrated TT */
2067 status |= ehci_port_speed(priv, temp); 1972 status |= USB_PORT_STAT_HIGH_SPEED;
2068 } 1973 }
2069 if (temp & PORT_PE) 1974 if (temp & PORT_PE)
2070 status |= USB_PORT_STAT_ENABLE; 1975 status |= USB_PORT_STAT_ENABLE;
@@ -2093,14 +1998,14 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2093 if (!wIndex || wIndex > ports) 1998 if (!wIndex || wIndex > ports)
2094 goto error; 1999 goto error;
2095 wIndex--; 2000 wIndex--;
2096 temp = isp1760_readl(status_reg); 2001 temp = reg_read32(hcd->regs, HC_PORTSC1);
2097 if (temp & PORT_OWNER) 2002 if (temp & PORT_OWNER)
2098 break; 2003 break;
2099 2004
2100/* temp &= ~PORT_RWC_BITS; */ 2005/* temp &= ~PORT_RWC_BITS; */
2101 switch (wValue) { 2006 switch (wValue) {
2102 case USB_PORT_FEAT_ENABLE: 2007 case USB_PORT_FEAT_ENABLE:
2103 isp1760_writel(temp | PORT_PE, status_reg); 2008 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_PE);
2104 break; 2009 break;
2105 2010
2106 case USB_PORT_FEAT_SUSPEND: 2011 case USB_PORT_FEAT_SUSPEND:
@@ -2108,12 +2013,12 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2108 || (temp & PORT_RESET) != 0) 2013 || (temp & PORT_RESET) != 0)
2109 goto error; 2014 goto error;
2110 2015
2111 isp1760_writel(temp | PORT_SUSPEND, status_reg); 2016 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_SUSPEND);
2112 break; 2017 break;
2113 case USB_PORT_FEAT_POWER: 2018 case USB_PORT_FEAT_POWER:
2114 if (HCS_PPC(priv->hcs_params)) 2019 if (HCS_PPC(priv->hcs_params))
2115 isp1760_writel(temp | PORT_POWER, 2020 reg_write32(hcd->regs, HC_PORTSC1,
2116 status_reg); 2021 temp | PORT_POWER);
2117 break; 2022 break;
2118 case USB_PORT_FEAT_RESET: 2023 case USB_PORT_FEAT_RESET:
2119 if (temp & PORT_RESUME) 2024 if (temp & PORT_RESUME)
@@ -2136,12 +2041,12 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2136 priv->reset_done = jiffies + 2041 priv->reset_done = jiffies +
2137 msecs_to_jiffies(50); 2042 msecs_to_jiffies(50);
2138 } 2043 }
2139 isp1760_writel(temp, status_reg); 2044 reg_write32(hcd->regs, HC_PORTSC1, temp);
2140 break; 2045 break;
2141 default: 2046 default:
2142 goto error; 2047 goto error;
2143 } 2048 }
2144 isp1760_readl(hcd->regs + HC_USBCMD); 2049 reg_read32(hcd->regs, HC_USBCMD);
2145 break; 2050 break;
2146 2051
2147 default: 2052 default:
@@ -2153,10 +2058,10 @@ error:
2153 return retval; 2058 return retval;
2154} 2059}
2155 2060
2156static void isp1760_endpoint_disable(struct usb_hcd *usb_hcd, 2061static void isp1760_endpoint_disable(struct usb_hcd *hcd,
2157 struct usb_host_endpoint *ep) 2062 struct usb_host_endpoint *ep)
2158{ 2063{
2159 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); 2064 struct isp1760_hcd *priv = hcd_to_priv(hcd);
2160 struct isp1760_qh *qh; 2065 struct isp1760_qh *qh;
2161 struct isp1760_qtd *qtd; 2066 struct isp1760_qtd *qtd;
2162 unsigned long flags; 2067 unsigned long flags;
@@ -2176,16 +2081,16 @@ static void isp1760_endpoint_disable(struct usb_hcd *usb_hcd,
2176 qtd_list); 2081 qtd_list);
2177 2082
2178 if (qtd->status & URB_ENQUEUED) { 2083 if (qtd->status & URB_ENQUEUED) {
2179
2180 spin_unlock_irqrestore(&priv->lock, flags); 2084 spin_unlock_irqrestore(&priv->lock, flags);
2181 isp1760_urb_dequeue(usb_hcd, qtd->urb, -ECONNRESET); 2085 isp1760_urb_dequeue(hcd, qtd->urb, -ECONNRESET);
2182 spin_lock_irqsave(&priv->lock, flags); 2086 spin_lock_irqsave(&priv->lock, flags);
2183 } else { 2087 } else {
2184 struct urb *urb; 2088 struct urb *urb;
2185 2089
2186 urb = qtd->urb; 2090 urb = qtd->urb;
2187 clean_up_qtdlist(qtd); 2091 clean_up_qtdlist(qtd, qh);
2188 isp1760_urb_done(priv, urb, -ECONNRESET); 2092 urb->status = -ECONNRESET;
2093 isp1760_urb_done(hcd, urb);
2189 } 2094 }
2190 } while (1); 2095 } while (1);
2191 2096
@@ -2203,7 +2108,7 @@ static int isp1760_get_frame(struct usb_hcd *hcd)
2203 struct isp1760_hcd *priv = hcd_to_priv(hcd); 2108 struct isp1760_hcd *priv = hcd_to_priv(hcd);
2204 u32 fr; 2109 u32 fr;
2205 2110
2206 fr = isp1760_readl(hcd->regs + HC_FRINDEX); 2111 fr = reg_read32(hcd->regs, HC_FRINDEX);
2207 return (fr >> 3) % priv->periodic_size; 2112 return (fr >> 3) % priv->periodic_size;
2208} 2113}
2209 2114
@@ -2217,13 +2122,13 @@ static void isp1760_stop(struct usb_hcd *hcd)
2217 mdelay(20); 2122 mdelay(20);
2218 2123
2219 spin_lock_irq(&priv->lock); 2124 spin_lock_irq(&priv->lock);
2220 ehci_reset(priv); 2125 ehci_reset(hcd);
2221 /* Disable IRQ */ 2126 /* Disable IRQ */
2222 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); 2127 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
2223 isp1760_writel(temp &= ~HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL); 2128 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN);
2224 spin_unlock_irq(&priv->lock); 2129 spin_unlock_irq(&priv->lock);
2225 2130
2226 isp1760_writel(0, hcd->regs + HC_CONFIGFLAG); 2131 reg_write32(hcd->regs, HC_CONFIGFLAG, 0);
2227} 2132}
2228 2133
2229static void isp1760_shutdown(struct usb_hcd *hcd) 2134static void isp1760_shutdown(struct usb_hcd *hcd)
@@ -2231,12 +2136,12 @@ static void isp1760_shutdown(struct usb_hcd *hcd)
2231 u32 command, temp; 2136 u32 command, temp;
2232 2137
2233 isp1760_stop(hcd); 2138 isp1760_stop(hcd);
2234 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); 2139 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
2235 isp1760_writel(temp &= ~HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL); 2140 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN);
2236 2141
2237 command = isp1760_readl(hcd->regs + HC_USBCMD); 2142 command = reg_read32(hcd->regs, HC_USBCMD);
2238 command &= ~CMD_RUN; 2143 command &= ~CMD_RUN;
2239 isp1760_writel(command, hcd->regs + HC_USBCMD); 2144 reg_write32(hcd->regs, HC_USBCMD, command);
2240} 2145}
2241 2146
2242static const struct hc_driver isp1760_hc_driver = { 2147static const struct hc_driver isp1760_hc_driver = {
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h
index 6931ef5c9650..870507690607 100644
--- a/drivers/usb/host/isp1760-hcd.h
+++ b/drivers/usb/host/isp1760-hcd.h
@@ -69,6 +69,7 @@ void deinit_kmem_cache(void);
69 69
70#define HC_INTERRUPT_ENABLE 0x314 70#define HC_INTERRUPT_ENABLE 0x314
71#define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT | HC_EOT_INT) 71#define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT | HC_EOT_INT)
72#define INTERRUPT_ENABLE_SOT_MASK (HC_INTL_INT | HC_SOT_INT | HC_EOT_INT)
72 73
73#define HC_ISO_INT (1 << 9) 74#define HC_ISO_INT (1 << 9)
74#define HC_ATL_INT (1 << 8) 75#define HC_ATL_INT (1 << 8)
@@ -83,37 +84,29 @@ void deinit_kmem_cache(void);
83#define HC_INT_IRQ_MASK_AND_REG 0x328 84#define HC_INT_IRQ_MASK_AND_REG 0x328
84#define HC_ATL_IRQ_MASK_AND_REG 0x32C 85#define HC_ATL_IRQ_MASK_AND_REG 0x32C
85 86
86/* Register sets */
87#define HC_BEGIN_OF_ATL 0x0c00
88#define HC_BEGIN_OF_INT 0x0800
89#define HC_BEGIN_OF_ISO 0x0400
90#define HC_BEGIN_OF_PAYLOAD 0x1000
91
92/* urb state*/ 87/* urb state*/
93#define DELETE_URB (0x0008) 88#define DELETE_URB (0x0008)
94#define NO_TRANSFER_ACTIVE (0xffffffff) 89#define NO_TRANSFER_ACTIVE (0xffffffff)
95 90
96#define ATL_REGS_OFFSET (0xc00) 91/* Philips Proprietary Transfer Descriptor (PTD) */
97#define INT_REGS_OFFSET (0x800) 92typedef __u32 __bitwise __dw;
98
99/* Philips Transfer Descriptor (PTD) */
100struct ptd { 93struct ptd {
101 __le32 dw0; 94 __dw dw0;
102 __le32 dw1; 95 __dw dw1;
103 __le32 dw2; 96 __dw dw2;
104 __le32 dw3; 97 __dw dw3;
105 __le32 dw4; 98 __dw dw4;
106 __le32 dw5; 99 __dw dw5;
107 __le32 dw6; 100 __dw dw6;
108 __le32 dw7; 101 __dw dw7;
109}; 102};
103#define PTD_OFFSET 0x0400
104#define ISO_PTD_OFFSET 0x0400
105#define INT_PTD_OFFSET 0x0800
106#define ATL_PTD_OFFSET 0x0c00
107#define PAYLOAD_OFFSET 0x1000
110 108
111struct inter_packet_info { 109struct inter_packet_info {
112 void *data_buffer;
113 u32 payload;
114#define PTD_FIRE_NEXT (1 << 0)
115#define PTD_URB_FINISHED (1 << 1)
116 struct urb *urb;
117 struct isp1760_qh *qh; 110 struct isp1760_qh *qh;
118 struct isp1760_qtd *qtd; 111 struct isp1760_qtd *qtd;
119}; 112};
@@ -122,15 +115,6 @@ struct inter_packet_info {
122typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh, 115typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh,
123 struct isp1760_qtd *qtd); 116 struct isp1760_qtd *qtd);
124 117
125#define isp1760_dbg(priv, fmt, args...) \
126 dev_dbg(priv_to_hcd(priv)->self.controller, fmt, ##args)
127
128#define isp1760_info(priv, fmt, args...) \
129 dev_info(priv_to_hcd(priv)->self.controller, fmt, ##args)
130
131#define isp1760_err(priv, fmt, args...) \
132 dev_err(priv_to_hcd(priv)->self.controller, fmt, ##args)
133
134/* 118/*
135 * Device flags that can vary from board to board. All of these 119 * Device flags that can vary from board to board. All of these
136 * indicate the most "atypical" case, so that a devflags of 0 is 120 * indicate the most "atypical" case, so that a devflags of 0 is
@@ -167,10 +151,8 @@ struct memory_chunk {
167#define BLOCK_2_SIZE 1024 151#define BLOCK_2_SIZE 1024
168#define BLOCK_3_SIZE 8192 152#define BLOCK_3_SIZE 8192
169#define BLOCKS (BLOCK_1_NUM + BLOCK_2_NUM + BLOCK_3_NUM) 153#define BLOCKS (BLOCK_1_NUM + BLOCK_2_NUM + BLOCK_3_NUM)
170#define PAYLOAD_SIZE 0xf000 154#define MAX_PAYLOAD_SIZE BLOCK_3_SIZE
171 155#define PAYLOAD_AREA_SIZE 0xf000
172/* I saw if some reloads if the pointer was negative */
173#define ISP1760_NULL_POINTER (0x400)
174 156
175/* ATL */ 157/* ATL */
176/* DW0 */ 158/* DW0 */
@@ -224,6 +206,4 @@ struct memory_chunk {
224#define NAK_COUNTER (0) 206#define NAK_COUNTER (0)
225#define ERR_COUNTER (2) 207#define ERR_COUNTER (2)
226 208
227#define HC_ATL_PL_SIZE (8192)
228
229#endif 209#endif
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 759a12ff8048..fb035751e4b2 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -75,6 +75,7 @@ static const char hcd_name [] = "ohci_hcd";
75#define STATECHANGE_DELAY msecs_to_jiffies(300) 75#define STATECHANGE_DELAY msecs_to_jiffies(300)
76 76
77#include "ohci.h" 77#include "ohci.h"
78#include "pci-quirks.h"
78 79
79static void ohci_dump (struct ohci_hcd *ohci, int verbose); 80static void ohci_dump (struct ohci_hcd *ohci, int verbose);
80static int ohci_init (struct ohci_hcd *ohci); 81static int ohci_init (struct ohci_hcd *ohci);
@@ -85,18 +86,8 @@ static int ohci_restart (struct ohci_hcd *ohci);
85#endif 86#endif
86 87
87#ifdef CONFIG_PCI 88#ifdef CONFIG_PCI
88static void quirk_amd_pll(int state);
89static void amd_iso_dev_put(void);
90static void sb800_prefetch(struct ohci_hcd *ohci, int on); 89static void sb800_prefetch(struct ohci_hcd *ohci, int on);
91#else 90#else
92static inline void quirk_amd_pll(int state)
93{
94 return;
95}
96static inline void amd_iso_dev_put(void)
97{
98 return;
99}
100static inline void sb800_prefetch(struct ohci_hcd *ohci, int on) 91static inline void sb800_prefetch(struct ohci_hcd *ohci, int on)
101{ 92{
102 return; 93 return;
@@ -912,7 +903,7 @@ static void ohci_stop (struct usb_hcd *hcd)
912 if (quirk_zfmicro(ohci)) 903 if (quirk_zfmicro(ohci))
913 del_timer(&ohci->unlink_watchdog); 904 del_timer(&ohci->unlink_watchdog);
914 if (quirk_amdiso(ohci)) 905 if (quirk_amdiso(ohci))
915 amd_iso_dev_put(); 906 usb_amd_dev_put();
916 907
917 remove_debug_files (ohci); 908 remove_debug_files (ohci);
918 ohci_mem_cleanup (ohci); 909 ohci_mem_cleanup (ohci);
@@ -1068,10 +1059,7 @@ MODULE_LICENSE ("GPL");
1068#define PLATFORM_DRIVER ohci_hcd_da8xx_driver 1059#define PLATFORM_DRIVER ohci_hcd_da8xx_driver
1069#endif 1060#endif
1070 1061
1071#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 1062#ifdef CONFIG_USB_OHCI_SH
1072 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
1073 defined(CONFIG_CPU_SUBTYPE_SH7763) || \
1074 defined(CONFIG_CPU_SUBTYPE_SH7786)
1075#include "ohci-sh.c" 1063#include "ohci-sh.c"
1076#define PLATFORM_DRIVER ohci_hcd_sh_driver 1064#define PLATFORM_DRIVER ohci_hcd_sh_driver
1077#endif 1065#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index cddcda95b579..9154615292db 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -580,15 +580,16 @@ ohci_hub_descriptor (
580 temp |= 0x0008; 580 temp |= 0x0008;
581 desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); 581 desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp);
582 582
583 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 583 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
584 rh = roothub_b (ohci); 584 rh = roothub_b (ohci);
585 memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); 585 memset(desc->u.hs.DeviceRemovable, 0xff,
586 desc->bitmap [0] = rh & RH_B_DR; 586 sizeof(desc->u.hs.DeviceRemovable));
587 desc->u.hs.DeviceRemovable[0] = rh & RH_B_DR;
587 if (ohci->num_ports > 7) { 588 if (ohci->num_ports > 7) {
588 desc->bitmap [1] = (rh & RH_B_DR) >> 8; 589 desc->u.hs.DeviceRemovable[1] = (rh & RH_B_DR) >> 8;
589 desc->bitmap [2] = 0xff; 590 desc->u.hs.DeviceRemovable[2] = 0xff;
590 } else 591 } else
591 desc->bitmap [1] = 0xff; 592 desc->u.hs.DeviceRemovable[1] = 0xff;
592} 593}
593 594
594/*-------------------------------------------------------------------------*/ 595/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c
index a37d5993e4e3..6048f2f64f73 100644
--- a/drivers/usb/host/ohci-omap3.c
+++ b/drivers/usb/host/ohci-omap3.c
@@ -7,6 +7,7 @@
7 * Copyright (C) 2007-2010 Texas Instruments, Inc. 7 * Copyright (C) 2007-2010 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com> 8 * Author: Vikram Pandita <vikram.pandita@ti.com>
9 * Author: Anand Gadiyar <gadiyar@ti.com> 9 * Author: Anand Gadiyar <gadiyar@ti.com>
10 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
10 * 11 *
11 * Based on ehci-omap.c and some other ohci glue layers 12 * Based on ehci-omap.c and some other ohci glue layers
12 * 13 *
@@ -24,150 +25,15 @@
24 * along with this program; if not, write to the Free Software 25 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * 27 *
27 * TODO (last updated Mar 10th, 2010): 28 * TODO (last updated Feb 27, 2011):
28 * - add kernel-doc 29 * - add kernel-doc
29 * - Factor out code common to EHCI to a separate file
30 * - Make EHCI and OHCI coexist together
31 * - needs newer silicon versions to actually work
32 * - the last one to be loaded currently steps on the other's toes
33 * - Add hooks for configuring transceivers, etc. at init/exit
34 * - Add aggressive clock-management code
35 */ 30 */
36 31
37#include <linux/platform_device.h> 32#include <linux/platform_device.h>
38#include <linux/clk.h>
39
40#include <plat/usb.h> 33#include <plat/usb.h>
41 34
42/*
43 * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
44 * Use ohci_omap_readl()/ohci_omap_writel() functions
45 */
46
47/* TLL Register Set */
48#define OMAP_USBTLL_REVISION (0x00)
49#define OMAP_USBTLL_SYSCONFIG (0x10)
50#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
51#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
52#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
53#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
54#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
55
56#define OMAP_USBTLL_SYSSTATUS (0x14)
57#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
58
59#define OMAP_USBTLL_IRQSTATUS (0x18)
60#define OMAP_USBTLL_IRQENABLE (0x1C)
61
62#define OMAP_TLL_SHARED_CONF (0x30)
63#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
64#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
65#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
66#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
67#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
68
69#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
70#define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
71#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
72#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
73#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
74#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
75#define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1)
76#define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
77
78#define OMAP_TLL_CHANNEL_COUNT 3
79
80/* UHH Register Set */
81#define OMAP_UHH_REVISION (0x00)
82#define OMAP_UHH_SYSCONFIG (0x10)
83#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
84#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
85#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
86#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
87#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
88#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
89
90#define OMAP_UHH_SYSSTATUS (0x14)
91#define OMAP_UHH_SYSSTATUS_UHHRESETDONE (1 << 0)
92#define OMAP_UHH_SYSSTATUS_OHCIRESETDONE (1 << 1)
93#define OMAP_UHH_SYSSTATUS_EHCIRESETDONE (1 << 2)
94#define OMAP_UHH_HOSTCONFIG (0x40)
95#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
96#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
97#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
98#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
99#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
100#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
101#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
102#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
103#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
104#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
105#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
106
107#define OMAP_UHH_DEBUG_CSR (0x44)
108
109/*-------------------------------------------------------------------------*/ 35/*-------------------------------------------------------------------------*/
110 36
111static inline void ohci_omap_writel(void __iomem *base, u32 reg, u32 val)
112{
113 __raw_writel(val, base + reg);
114}
115
116static inline u32 ohci_omap_readl(void __iomem *base, u32 reg)
117{
118 return __raw_readl(base + reg);
119}
120
121static inline void ohci_omap_writeb(void __iomem *base, u8 reg, u8 val)
122{
123 __raw_writeb(val, base + reg);
124}
125
126static inline u8 ohci_omap_readb(void __iomem *base, u8 reg)
127{
128 return __raw_readb(base + reg);
129}
130
131/*-------------------------------------------------------------------------*/
132
133struct ohci_hcd_omap3 {
134 struct ohci_hcd *ohci;
135 struct device *dev;
136
137 struct clk *usbhost_ick;
138 struct clk *usbhost2_120m_fck;
139 struct clk *usbhost1_48m_fck;
140 struct clk *usbtll_fck;
141 struct clk *usbtll_ick;
142
143 /* port_mode: TLL/PHY, 2/3/4/6-PIN, DP-DM/DAT-SE0 */
144 enum ohci_omap3_port_mode port_mode[OMAP3_HS_USB_PORTS];
145 void __iomem *uhh_base;
146 void __iomem *tll_base;
147 void __iomem *ohci_base;
148
149 unsigned es2_compatibility:1;
150};
151
152/*-------------------------------------------------------------------------*/
153
154static void ohci_omap3_clock_power(struct ohci_hcd_omap3 *omap, int on)
155{
156 if (on) {
157 clk_enable(omap->usbtll_ick);
158 clk_enable(omap->usbtll_fck);
159 clk_enable(omap->usbhost_ick);
160 clk_enable(omap->usbhost1_48m_fck);
161 clk_enable(omap->usbhost2_120m_fck);
162 } else {
163 clk_disable(omap->usbhost2_120m_fck);
164 clk_disable(omap->usbhost1_48m_fck);
165 clk_disable(omap->usbhost_ick);
166 clk_disable(omap->usbtll_fck);
167 clk_disable(omap->usbtll_ick);
168 }
169}
170
171static int ohci_omap3_init(struct usb_hcd *hcd) 37static int ohci_omap3_init(struct usb_hcd *hcd)
172{ 38{
173 dev_dbg(hcd->self.controller, "starting OHCI controller\n"); 39 dev_dbg(hcd->self.controller, "starting OHCI controller\n");
@@ -175,7 +41,6 @@ static int ohci_omap3_init(struct usb_hcd *hcd)
175 return ohci_init(hcd_to_ohci(hcd)); 41 return ohci_init(hcd_to_ohci(hcd));
176} 42}
177 43
178
179/*-------------------------------------------------------------------------*/ 44/*-------------------------------------------------------------------------*/
180 45
181static int ohci_omap3_start(struct usb_hcd *hcd) 46static int ohci_omap3_start(struct usb_hcd *hcd)
@@ -202,325 +67,6 @@ static int ohci_omap3_start(struct usb_hcd *hcd)
202 67
203/*-------------------------------------------------------------------------*/ 68/*-------------------------------------------------------------------------*/
204 69
205/*
206 * convert the port-mode enum to a value we can use in the FSLSMODE
207 * field of USBTLL_CHANNEL_CONF
208 */
209static unsigned ohci_omap3_fslsmode(enum ohci_omap3_port_mode mode)
210{
211 switch (mode) {
212 case OMAP_OHCI_PORT_MODE_UNUSED:
213 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
214 return 0x0;
215
216 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
217 return 0x1;
218
219 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
220 return 0x2;
221
222 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
223 return 0x3;
224
225 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
226 return 0x4;
227
228 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
229 return 0x5;
230
231 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
232 return 0x6;
233
234 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
235 return 0x7;
236
237 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
238 return 0xA;
239
240 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
241 return 0xB;
242 default:
243 pr_warning("Invalid port mode, using default\n");
244 return 0x0;
245 }
246}
247
248static void ohci_omap3_tll_config(struct ohci_hcd_omap3 *omap)
249{
250 u32 reg;
251 int i;
252
253 /* Program TLL SHARED CONF */
254 reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
255 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
256 reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
257 reg |= OMAP_TLL_SHARED_CONF_USB_DIVRATION;
258 reg |= OMAP_TLL_SHARED_CONF_FCLK_IS_ON;
259 ohci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
260
261 /* Program each TLL channel */
262 /*
263 * REVISIT: Only the 3-pin and 4-pin PHY modes have
264 * actually been tested.
265 */
266 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
267
268 /* Enable only those channels that are actually used */
269 if (omap->port_mode[i] == OMAP_OHCI_PORT_MODE_UNUSED)
270 continue;
271
272 reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
273 reg |= ohci_omap3_fslsmode(omap->port_mode[i])
274 << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
275 reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
276 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
277 ohci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
278 }
279}
280
281/* omap3_start_ohci
282 * - Start the TI USBHOST controller
283 */
284static int omap3_start_ohci(struct ohci_hcd_omap3 *omap, struct usb_hcd *hcd)
285{
286 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
287 u32 reg = 0;
288 int ret = 0;
289
290 dev_dbg(omap->dev, "starting TI OHCI USB Controller\n");
291
292 /* Get all the clock handles we need */
293 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
294 if (IS_ERR(omap->usbhost_ick)) {
295 dev_err(omap->dev, "could not get usbhost_ick\n");
296 ret = PTR_ERR(omap->usbhost_ick);
297 goto err_host_ick;
298 }
299
300 omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck");
301 if (IS_ERR(omap->usbhost2_120m_fck)) {
302 dev_err(omap->dev, "could not get usbhost_120m_fck\n");
303 ret = PTR_ERR(omap->usbhost2_120m_fck);
304 goto err_host_120m_fck;
305 }
306
307 omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck");
308 if (IS_ERR(omap->usbhost1_48m_fck)) {
309 dev_err(omap->dev, "could not get usbhost_48m_fck\n");
310 ret = PTR_ERR(omap->usbhost1_48m_fck);
311 goto err_host_48m_fck;
312 }
313
314 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
315 if (IS_ERR(omap->usbtll_fck)) {
316 dev_err(omap->dev, "could not get usbtll_fck\n");
317 ret = PTR_ERR(omap->usbtll_fck);
318 goto err_tll_fck;
319 }
320
321 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
322 if (IS_ERR(omap->usbtll_ick)) {
323 dev_err(omap->dev, "could not get usbtll_ick\n");
324 ret = PTR_ERR(omap->usbtll_ick);
325 goto err_tll_ick;
326 }
327
328 /* Now enable all the clocks in the correct order */
329 ohci_omap3_clock_power(omap, 1);
330
331 /* perform TLL soft reset, and wait until reset is complete */
332 ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
333 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
334
335 /* Wait for TLL reset to complete */
336 while (!(ohci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
337 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
338 cpu_relax();
339
340 if (time_after(jiffies, timeout)) {
341 dev_dbg(omap->dev, "operation timed out\n");
342 ret = -EINVAL;
343 goto err_sys_status;
344 }
345 }
346
347 dev_dbg(omap->dev, "TLL reset done\n");
348
349 /* (1<<3) = no idle mode only for initial debugging */
350 ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
351 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
352 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
353 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
354
355
356 /* Put UHH in NoIdle/NoStandby mode */
357 reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
358 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
359 | OMAP_UHH_SYSCONFIG_SIDLEMODE
360 | OMAP_UHH_SYSCONFIG_CACTIVITY
361 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
362 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
363 reg &= ~OMAP_UHH_SYSCONFIG_SOFTRESET;
364
365 ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
366
367 reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
368
369 /* setup ULPI bypass and burst configurations */
370 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
371 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
372 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
373 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
374
375 /*
376 * REVISIT: Pi_CONNECT_STATUS controls MStandby
377 * assertion and Swakeup generation - let us not
378 * worry about this for now. OMAP HWMOD framework
379 * might take care of this later. If not, we can
380 * update these registers when adding aggressive
381 * clock management code.
382 *
383 * For now, turn off all the Pi_CONNECT_STATUS bits
384 *
385 if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED)
386 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
387 if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED)
388 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
389 if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED)
390 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
391 */
392 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
393 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
394 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
395
396 if (omap->es2_compatibility) {
397 /*
398 * All OHCI modes need to go through the TLL,
399 * unlike in the EHCI case. So use UTMI mode
400 * for all ports for OHCI, on ES2.x silicon
401 */
402 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
403 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
404 } else {
405 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
406 if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED)
407 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
408 else
409 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
410
411 if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED)
412 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
413 else
414 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
415
416 if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED)
417 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
418 else
419 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
420
421 }
422 ohci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
423 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
424
425 ohci_omap3_tll_config(omap);
426
427 return 0;
428
429err_sys_status:
430 ohci_omap3_clock_power(omap, 0);
431 clk_put(omap->usbtll_ick);
432
433err_tll_ick:
434 clk_put(omap->usbtll_fck);
435
436err_tll_fck:
437 clk_put(omap->usbhost1_48m_fck);
438
439err_host_48m_fck:
440 clk_put(omap->usbhost2_120m_fck);
441
442err_host_120m_fck:
443 clk_put(omap->usbhost_ick);
444
445err_host_ick:
446 return ret;
447}
448
449static void omap3_stop_ohci(struct ohci_hcd_omap3 *omap, struct usb_hcd *hcd)
450{
451 unsigned long timeout = jiffies + msecs_to_jiffies(100);
452
453 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
454
455 /* Reset USBHOST for insmod/rmmod to work */
456 ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
457 OMAP_UHH_SYSCONFIG_SOFTRESET);
458 while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
459 & OMAP_UHH_SYSSTATUS_UHHRESETDONE)) {
460 cpu_relax();
461
462 if (time_after(jiffies, timeout))
463 dev_dbg(omap->dev, "operation timed out\n");
464 }
465
466 while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
467 & OMAP_UHH_SYSSTATUS_OHCIRESETDONE)) {
468 cpu_relax();
469
470 if (time_after(jiffies, timeout))
471 dev_dbg(omap->dev, "operation timed out\n");
472 }
473
474 while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
475 & OMAP_UHH_SYSSTATUS_EHCIRESETDONE)) {
476 cpu_relax();
477
478 if (time_after(jiffies, timeout))
479 dev_dbg(omap->dev, "operation timed out\n");
480 }
481
482 ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
483
484 while (!(ohci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
485 & (1 << 0))) {
486 cpu_relax();
487
488 if (time_after(jiffies, timeout))
489 dev_dbg(omap->dev, "operation timed out\n");
490 }
491
492 ohci_omap3_clock_power(omap, 0);
493
494 if (omap->usbtll_fck != NULL) {
495 clk_put(omap->usbtll_fck);
496 omap->usbtll_fck = NULL;
497 }
498
499 if (omap->usbhost_ick != NULL) {
500 clk_put(omap->usbhost_ick);
501 omap->usbhost_ick = NULL;
502 }
503
504 if (omap->usbhost1_48m_fck != NULL) {
505 clk_put(omap->usbhost1_48m_fck);
506 omap->usbhost1_48m_fck = NULL;
507 }
508
509 if (omap->usbhost2_120m_fck != NULL) {
510 clk_put(omap->usbhost2_120m_fck);
511 omap->usbhost2_120m_fck = NULL;
512 }
513
514 if (omap->usbtll_ick != NULL) {
515 clk_put(omap->usbtll_ick);
516 omap->usbtll_ick = NULL;
517 }
518
519 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
520}
521
522/*-------------------------------------------------------------------------*/
523
524static const struct hc_driver ohci_omap3_hc_driver = { 70static const struct hc_driver ohci_omap3_hc_driver = {
525 .description = hcd_name, 71 .description = hcd_name,
526 .product_desc = "OMAP3 OHCI Host Controller", 72 .product_desc = "OMAP3 OHCI Host Controller",
@@ -580,107 +126,77 @@ static const struct hc_driver ohci_omap3_hc_driver = {
580 */ 126 */
581static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev) 127static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev)
582{ 128{
583 struct ohci_hcd_omap_platform_data *pdata = pdev->dev.platform_data; 129 struct device *dev = &pdev->dev;
584 struct ohci_hcd_omap3 *omap; 130 struct usb_hcd *hcd = NULL;
585 struct resource *res; 131 void __iomem *regs = NULL;
586 struct usb_hcd *hcd; 132 struct resource *res;
587 int ret = -ENODEV; 133 int ret = -ENODEV;
588 int irq; 134 int irq;
589 135
590 if (usb_disabled()) 136 if (usb_disabled())
591 goto err_disabled; 137 goto err_end;
592 138
593 if (!pdata) { 139 if (!dev->parent) {
594 dev_dbg(&pdev->dev, "missing platform_data\n"); 140 dev_err(dev, "Missing parent device\n");
595 goto err_pdata; 141 return -ENODEV;
596 } 142 }
597 143
598 irq = platform_get_irq(pdev, 0); 144 irq = platform_get_irq_byname(pdev, "ohci-irq");
145 if (irq < 0) {
146 dev_err(dev, "OHCI irq failed\n");
147 return -ENODEV;
148 }
599 149
600 omap = kzalloc(sizeof(*omap), GFP_KERNEL); 150 res = platform_get_resource_byname(pdev,
601 if (!omap) { 151 IORESOURCE_MEM, "ohci");
602 ret = -ENOMEM; 152 if (!ret) {
603 goto err_disabled; 153 dev_err(dev, "UHH OHCI get resource failed\n");
154 return -ENOMEM;
604 } 155 }
605 156
606 hcd = usb_create_hcd(&ohci_omap3_hc_driver, &pdev->dev, 157 regs = ioremap(res->start, resource_size(res));
607 dev_name(&pdev->dev)); 158 if (!regs) {
608 if (!hcd) { 159 dev_err(dev, "UHH OHCI ioremap failed\n");
609 ret = -ENOMEM; 160 return -ENOMEM;
610 goto err_create_hcd;
611 } 161 }
612 162
613 platform_set_drvdata(pdev, omap);
614 omap->dev = &pdev->dev;
615 omap->port_mode[0] = pdata->port_mode[0];
616 omap->port_mode[1] = pdata->port_mode[1];
617 omap->port_mode[2] = pdata->port_mode[2];
618 omap->es2_compatibility = pdata->es2_compatibility;
619 omap->ohci = hcd_to_ohci(hcd);
620 163
621 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 164 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
165 dev_name(dev));
166 if (!hcd) {
167 dev_err(dev, "usb_create_hcd failed\n");
168 goto err_io;
169 }
622 170
623 hcd->rsrc_start = res->start; 171 hcd->rsrc_start = res->start;
624 hcd->rsrc_len = resource_size(res); 172 hcd->rsrc_len = resource_size(res);
173 hcd->regs = regs;
625 174
626 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 175 ret = omap_usbhs_enable(dev);
627 if (!hcd->regs) {
628 dev_err(&pdev->dev, "OHCI ioremap failed\n");
629 ret = -ENOMEM;
630 goto err_ioremap;
631 }
632
633 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
634 omap->uhh_base = ioremap(res->start, resource_size(res));
635 if (!omap->uhh_base) {
636 dev_err(&pdev->dev, "UHH ioremap failed\n");
637 ret = -ENOMEM;
638 goto err_uhh_ioremap;
639 }
640
641 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
642 omap->tll_base = ioremap(res->start, resource_size(res));
643 if (!omap->tll_base) {
644 dev_err(&pdev->dev, "TLL ioremap failed\n");
645 ret = -ENOMEM;
646 goto err_tll_ioremap;
647 }
648
649 ret = omap3_start_ohci(omap, hcd);
650 if (ret) { 176 if (ret) {
651 dev_dbg(&pdev->dev, "failed to start ohci\n"); 177 dev_dbg(dev, "failed to start ohci\n");
652 goto err_start; 178 goto err_end;
653 } 179 }
654 180
655 ohci_hcd_init(omap->ohci); 181 ohci_hcd_init(hcd_to_ohci(hcd));
656 182
657 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); 183 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
658 if (ret) { 184 if (ret) {
659 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); 185 dev_dbg(dev, "failed to add hcd with err %d\n", ret);
660 goto err_add_hcd; 186 goto err_add_hcd;
661 } 187 }
662 188
663 return 0; 189 return 0;
664 190
665err_add_hcd: 191err_add_hcd:
666 omap3_stop_ohci(omap, hcd); 192 omap_usbhs_disable(dev);
667
668err_start:
669 iounmap(omap->tll_base);
670
671err_tll_ioremap:
672 iounmap(omap->uhh_base);
673
674err_uhh_ioremap:
675 iounmap(hcd->regs);
676 193
677err_ioremap: 194err_end:
678 usb_put_hcd(hcd); 195 usb_put_hcd(hcd);
679 196
680err_create_hcd: 197err_io:
681 kfree(omap); 198 iounmap(regs);
682err_pdata: 199
683err_disabled:
684 return ret; 200 return ret;
685} 201}
686 202
@@ -699,24 +215,20 @@ err_disabled:
699 */ 215 */
700static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev) 216static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev)
701{ 217{
702 struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev); 218 struct device *dev = &pdev->dev;
703 struct usb_hcd *hcd = ohci_to_hcd(omap->ohci); 219 struct usb_hcd *hcd = dev_get_drvdata(dev);
704 220
705 usb_remove_hcd(hcd);
706 omap3_stop_ohci(omap, hcd);
707 iounmap(hcd->regs); 221 iounmap(hcd->regs);
708 iounmap(omap->tll_base); 222 usb_remove_hcd(hcd);
709 iounmap(omap->uhh_base); 223 omap_usbhs_disable(dev);
710 usb_put_hcd(hcd); 224 usb_put_hcd(hcd);
711 kfree(omap);
712 225
713 return 0; 226 return 0;
714} 227}
715 228
716static void ohci_hcd_omap3_shutdown(struct platform_device *pdev) 229static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
717{ 230{
718 struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev); 231 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
719 struct usb_hcd *hcd = ohci_to_hcd(omap->ohci);
720 232
721 if (hcd->driver->shutdown) 233 if (hcd->driver->shutdown)
722 hcd->driver->shutdown(hcd); 234 hcd->driver->shutdown(hcd);
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index 36ee9a666e93..d84d6f0314f9 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -22,24 +22,6 @@
22#include <linux/io.h> 22#include <linux/io.h>
23 23
24 24
25/* constants used to work around PM-related transfer
26 * glitches in some AMD 700 series southbridges
27 */
28#define AB_REG_BAR 0xf0
29#define AB_INDX(addr) ((addr) + 0x00)
30#define AB_DATA(addr) ((addr) + 0x04)
31#define AX_INDXC 0X30
32#define AX_DATAC 0x34
33
34#define NB_PCIE_INDX_ADDR 0xe0
35#define NB_PCIE_INDX_DATA 0xe4
36#define PCIE_P_CNTL 0x10040
37#define BIF_NB 0x10002
38
39static struct pci_dev *amd_smbus_dev;
40static struct pci_dev *amd_hb_dev;
41static int amd_ohci_iso_count;
42
43/*-------------------------------------------------------------------------*/ 25/*-------------------------------------------------------------------------*/
44 26
45static int broken_suspend(struct usb_hcd *hcd) 27static int broken_suspend(struct usb_hcd *hcd)
@@ -168,15 +150,18 @@ static int ohci_quirk_nec(struct usb_hcd *hcd)
168static int ohci_quirk_amd700(struct usb_hcd *hcd) 150static int ohci_quirk_amd700(struct usb_hcd *hcd)
169{ 151{
170 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 152 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
171 u8 rev = 0; 153 struct pci_dev *amd_smbus_dev;
154 u8 rev;
172 155
173 if (!amd_smbus_dev) 156 if (usb_amd_find_chipset_info())
174 amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 157 ohci->flags |= OHCI_QUIRK_AMD_PLL;
175 PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL); 158
159 amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI,
160 PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL);
176 if (!amd_smbus_dev) 161 if (!amd_smbus_dev)
177 return 0; 162 return 0;
178 163
179 pci_read_config_byte(amd_smbus_dev, PCI_REVISION_ID, &rev); 164 rev = amd_smbus_dev->revision;
180 165
181 /* SB800 needs pre-fetch fix */ 166 /* SB800 needs pre-fetch fix */
182 if ((rev >= 0x40) && (rev <= 0x4f)) { 167 if ((rev >= 0x40) && (rev <= 0x4f)) {
@@ -184,19 +169,8 @@ static int ohci_quirk_amd700(struct usb_hcd *hcd)
184 ohci_dbg(ohci, "enabled AMD prefetch quirk\n"); 169 ohci_dbg(ohci, "enabled AMD prefetch quirk\n");
185 } 170 }
186 171
187 if ((rev > 0x3b) || (rev < 0x30)) { 172 pci_dev_put(amd_smbus_dev);
188 pci_dev_put(amd_smbus_dev); 173 amd_smbus_dev = NULL;
189 amd_smbus_dev = NULL;
190 return 0;
191 }
192
193 amd_ohci_iso_count++;
194
195 if (!amd_hb_dev)
196 amd_hb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9600, NULL);
197
198 ohci->flags |= OHCI_QUIRK_AMD_ISO;
199 ohci_dbg(ohci, "enabled AMD ISO transfers quirk\n");
200 174
201 return 0; 175 return 0;
202} 176}
@@ -215,74 +189,6 @@ static int ohci_quirk_nvidia_shutdown(struct usb_hcd *hcd)
215 return 0; 189 return 0;
216} 190}
217 191
218/*
219 * The hardware normally enables the A-link power management feature, which
220 * lets the system lower the power consumption in idle states.
221 *
222 * Assume the system is configured to have USB 1.1 ISO transfers going
223 * to or from a USB device. Without this quirk, that stream may stutter
224 * or have breaks occasionally. For transfers going to speakers, this
225 * makes a very audible mess...
226 *
227 * That audio playback corruption is due to the audio stream getting
228 * interrupted occasionally when the link goes in lower power state
229 * This USB quirk prevents the link going into that lower power state
230 * during audio playback or other ISO operations.
231 */
232static void quirk_amd_pll(int on)
233{
234 u32 addr;
235 u32 val;
236 u32 bit = (on > 0) ? 1 : 0;
237
238 pci_read_config_dword(amd_smbus_dev, AB_REG_BAR, &addr);
239
240 /* BIT names/meanings are NDA-protected, sorry ... */
241
242 outl(AX_INDXC, AB_INDX(addr));
243 outl(0x40, AB_DATA(addr));
244 outl(AX_DATAC, AB_INDX(addr));
245 val = inl(AB_DATA(addr));
246 val &= ~((1 << 3) | (1 << 4) | (1 << 9));
247 val |= (bit << 3) | ((!bit) << 4) | ((!bit) << 9);
248 outl(val, AB_DATA(addr));
249
250 if (amd_hb_dev) {
251 addr = PCIE_P_CNTL;
252 pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr);
253
254 pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val);
255 val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12));
256 val |= bit | (bit << 3) | (bit << 12);
257 val |= ((!bit) << 4) | ((!bit) << 9);
258 pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val);
259
260 addr = BIF_NB;
261 pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr);
262
263 pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val);
264 val &= ~(1 << 8);
265 val |= bit << 8;
266 pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val);
267 }
268}
269
270static void amd_iso_dev_put(void)
271{
272 amd_ohci_iso_count--;
273 if (amd_ohci_iso_count == 0) {
274 if (amd_smbus_dev) {
275 pci_dev_put(amd_smbus_dev);
276 amd_smbus_dev = NULL;
277 }
278 if (amd_hb_dev) {
279 pci_dev_put(amd_hb_dev);
280 amd_hb_dev = NULL;
281 }
282 }
283
284}
285
286static void sb800_prefetch(struct ohci_hcd *ohci, int on) 192static void sb800_prefetch(struct ohci_hcd *ohci, int on)
287{ 193{
288 struct pci_dev *pdev; 194 struct pci_dev *pdev;
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index 83094d067e0f..dd24fc115e48 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -52,7 +52,7 @@ __acquires(ohci->lock)
52 ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--; 52 ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--;
53 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { 53 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) {
54 if (quirk_amdiso(ohci)) 54 if (quirk_amdiso(ohci))
55 quirk_amd_pll(1); 55 usb_amd_quirk_pll_enable();
56 if (quirk_amdprefetch(ohci)) 56 if (quirk_amdprefetch(ohci))
57 sb800_prefetch(ohci, 0); 57 sb800_prefetch(ohci, 0);
58 } 58 }
@@ -686,7 +686,7 @@ static void td_submit_urb (
686 } 686 }
687 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { 687 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) {
688 if (quirk_amdiso(ohci)) 688 if (quirk_amdiso(ohci))
689 quirk_amd_pll(0); 689 usb_amd_quirk_pll_disable();
690 if (quirk_amdprefetch(ohci)) 690 if (quirk_amdprefetch(ohci))
691 sb800_prefetch(ohci, 1); 691 sb800_prefetch(ohci, 1);
692 } 692 }
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 51facb985c84..bad11a72c202 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -401,7 +401,7 @@ struct ohci_hcd {
401#define OHCI_QUIRK_NEC 0x40 /* lost interrupts */ 401#define OHCI_QUIRK_NEC 0x40 /* lost interrupts */
402#define OHCI_QUIRK_FRAME_NO 0x80 /* no big endian frame_no shift */ 402#define OHCI_QUIRK_FRAME_NO 0x80 /* no big endian frame_no shift */
403#define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */ 403#define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */
404#define OHCI_QUIRK_AMD_ISO 0x200 /* ISO transfers*/ 404#define OHCI_QUIRK_AMD_PLL 0x200 /* AMD PLL quirk*/
405#define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */ 405#define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */
406#define OHCI_QUIRK_SHUTDOWN 0x800 /* nVidia power bug */ 406#define OHCI_QUIRK_SHUTDOWN 0x800 /* nVidia power bug */
407 // there are also chip quirks/bugs in init logic 407 // there are also chip quirks/bugs in init logic
@@ -433,7 +433,7 @@ static inline int quirk_zfmicro(struct ohci_hcd *ohci)
433} 433}
434static inline int quirk_amdiso(struct ohci_hcd *ohci) 434static inline int quirk_amdiso(struct ohci_hcd *ohci)
435{ 435{
436 return ohci->flags & OHCI_QUIRK_AMD_ISO; 436 return ohci->flags & OHCI_QUIRK_AMD_PLL;
437} 437}
438static inline int quirk_amdprefetch(struct ohci_hcd *ohci) 438static inline int quirk_amdprefetch(struct ohci_hcd *ohci)
439{ 439{
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index e0cb12b573f9..38193f4e980e 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -451,9 +451,9 @@ static void ehci_hub_descriptor(struct oxu_hcd *oxu,
451 temp = 1 + (ports / 8); 451 temp = 1 + (ports / 8);
452 desc->bDescLength = 7 + 2 * temp; 452 desc->bDescLength = 7 + 2 * temp;
453 453
454 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 454 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
455 memset(&desc->bitmap[0], 0, temp); 455 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
456 memset(&desc->bitmap[temp], 0xff, temp); 456 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
457 457
458 temp = 0x0008; /* per-port overcurrent reporting */ 458 temp = 0x0008; /* per-port overcurrent reporting */
459 if (HCS_PPC(oxu->hcs_params)) 459 if (HCS_PPC(oxu->hcs_params))
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 4c502c890ebd..1d586d4f7b56 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -52,6 +52,264 @@
52#define EHCI_USBLEGCTLSTS 4 /* legacy control/status */ 52#define EHCI_USBLEGCTLSTS 4 /* legacy control/status */
53#define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */ 53#define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */
54 54
55/* AMD quirk use */
56#define AB_REG_BAR_LOW 0xe0
57#define AB_REG_BAR_HIGH 0xe1
58#define AB_REG_BAR_SB700 0xf0
59#define AB_INDX(addr) ((addr) + 0x00)
60#define AB_DATA(addr) ((addr) + 0x04)
61#define AX_INDXC 0x30
62#define AX_DATAC 0x34
63
64#define NB_PCIE_INDX_ADDR 0xe0
65#define NB_PCIE_INDX_DATA 0xe4
66#define PCIE_P_CNTL 0x10040
67#define BIF_NB 0x10002
68#define NB_PIF0_PWRDOWN_0 0x01100012
69#define NB_PIF0_PWRDOWN_1 0x01100013
70
71static struct amd_chipset_info {
72 struct pci_dev *nb_dev;
73 struct pci_dev *smbus_dev;
74 int nb_type;
75 int sb_type;
76 int isoc_reqs;
77 int probe_count;
78 int probe_result;
79} amd_chipset;
80
81static DEFINE_SPINLOCK(amd_lock);
82
83int usb_amd_find_chipset_info(void)
84{
85 u8 rev = 0;
86 unsigned long flags;
87
88 spin_lock_irqsave(&amd_lock, flags);
89
90 amd_chipset.probe_count++;
91 /* probe only once */
92 if (amd_chipset.probe_count > 1) {
93 spin_unlock_irqrestore(&amd_lock, flags);
94 return amd_chipset.probe_result;
95 }
96
97 amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL);
98 if (amd_chipset.smbus_dev) {
99 rev = amd_chipset.smbus_dev->revision;
100 if (rev >= 0x40)
101 amd_chipset.sb_type = 1;
102 else if (rev >= 0x30 && rev <= 0x3b)
103 amd_chipset.sb_type = 3;
104 } else {
105 amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
106 0x780b, NULL);
107 if (!amd_chipset.smbus_dev) {
108 spin_unlock_irqrestore(&amd_lock, flags);
109 return 0;
110 }
111 rev = amd_chipset.smbus_dev->revision;
112 if (rev >= 0x11 && rev <= 0x18)
113 amd_chipset.sb_type = 2;
114 }
115
116 if (amd_chipset.sb_type == 0) {
117 if (amd_chipset.smbus_dev) {
118 pci_dev_put(amd_chipset.smbus_dev);
119 amd_chipset.smbus_dev = NULL;
120 }
121 spin_unlock_irqrestore(&amd_lock, flags);
122 return 0;
123 }
124
125 amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9601, NULL);
126 if (amd_chipset.nb_dev) {
127 amd_chipset.nb_type = 1;
128 } else {
129 amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD,
130 0x1510, NULL);
131 if (amd_chipset.nb_dev) {
132 amd_chipset.nb_type = 2;
133 } else {
134 amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD,
135 0x9600, NULL);
136 if (amd_chipset.nb_dev)
137 amd_chipset.nb_type = 3;
138 }
139 }
140
141 amd_chipset.probe_result = 1;
142 printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n");
143
144 spin_unlock_irqrestore(&amd_lock, flags);
145 return amd_chipset.probe_result;
146}
147EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info);
148
149/*
150 * The hardware normally enables the A-link power management feature, which
151 * lets the system lower the power consumption in idle states.
152 *
153 * This USB quirk prevents the link going into that lower power state
154 * during isochronous transfers.
155 *
156 * Without this quirk, isochronous stream on OHCI/EHCI/xHCI controllers of
157 * some AMD platforms may stutter or have breaks occasionally.
158 */
159static void usb_amd_quirk_pll(int disable)
160{
161 u32 addr, addr_low, addr_high, val;
162 u32 bit = disable ? 0 : 1;
163 unsigned long flags;
164
165 spin_lock_irqsave(&amd_lock, flags);
166
167 if (disable) {
168 amd_chipset.isoc_reqs++;
169 if (amd_chipset.isoc_reqs > 1) {
170 spin_unlock_irqrestore(&amd_lock, flags);
171 return;
172 }
173 } else {
174 amd_chipset.isoc_reqs--;
175 if (amd_chipset.isoc_reqs > 0) {
176 spin_unlock_irqrestore(&amd_lock, flags);
177 return;
178 }
179 }
180
181 if (amd_chipset.sb_type == 1 || amd_chipset.sb_type == 2) {
182 outb_p(AB_REG_BAR_LOW, 0xcd6);
183 addr_low = inb_p(0xcd7);
184 outb_p(AB_REG_BAR_HIGH, 0xcd6);
185 addr_high = inb_p(0xcd7);
186 addr = addr_high << 8 | addr_low;
187
188 outl_p(0x30, AB_INDX(addr));
189 outl_p(0x40, AB_DATA(addr));
190 outl_p(0x34, AB_INDX(addr));
191 val = inl_p(AB_DATA(addr));
192 } else if (amd_chipset.sb_type == 3) {
193 pci_read_config_dword(amd_chipset.smbus_dev,
194 AB_REG_BAR_SB700, &addr);
195 outl(AX_INDXC, AB_INDX(addr));
196 outl(0x40, AB_DATA(addr));
197 outl(AX_DATAC, AB_INDX(addr));
198 val = inl(AB_DATA(addr));
199 } else {
200 spin_unlock_irqrestore(&amd_lock, flags);
201 return;
202 }
203
204 if (disable) {
205 val &= ~0x08;
206 val |= (1 << 4) | (1 << 9);
207 } else {
208 val |= 0x08;
209 val &= ~((1 << 4) | (1 << 9));
210 }
211 outl_p(val, AB_DATA(addr));
212
213 if (!amd_chipset.nb_dev) {
214 spin_unlock_irqrestore(&amd_lock, flags);
215 return;
216 }
217
218 if (amd_chipset.nb_type == 1 || amd_chipset.nb_type == 3) {
219 addr = PCIE_P_CNTL;
220 pci_write_config_dword(amd_chipset.nb_dev,
221 NB_PCIE_INDX_ADDR, addr);
222 pci_read_config_dword(amd_chipset.nb_dev,
223 NB_PCIE_INDX_DATA, &val);
224
225 val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12));
226 val |= bit | (bit << 3) | (bit << 12);
227 val |= ((!bit) << 4) | ((!bit) << 9);
228 pci_write_config_dword(amd_chipset.nb_dev,
229 NB_PCIE_INDX_DATA, val);
230
231 addr = BIF_NB;
232 pci_write_config_dword(amd_chipset.nb_dev,
233 NB_PCIE_INDX_ADDR, addr);
234 pci_read_config_dword(amd_chipset.nb_dev,
235 NB_PCIE_INDX_DATA, &val);
236 val &= ~(1 << 8);
237 val |= bit << 8;
238
239 pci_write_config_dword(amd_chipset.nb_dev,
240 NB_PCIE_INDX_DATA, val);
241 } else if (amd_chipset.nb_type == 2) {
242 addr = NB_PIF0_PWRDOWN_0;
243 pci_write_config_dword(amd_chipset.nb_dev,
244 NB_PCIE_INDX_ADDR, addr);
245 pci_read_config_dword(amd_chipset.nb_dev,
246 NB_PCIE_INDX_DATA, &val);
247 if (disable)
248 val &= ~(0x3f << 7);
249 else
250 val |= 0x3f << 7;
251
252 pci_write_config_dword(amd_chipset.nb_dev,
253 NB_PCIE_INDX_DATA, val);
254
255 addr = NB_PIF0_PWRDOWN_1;
256 pci_write_config_dword(amd_chipset.nb_dev,
257 NB_PCIE_INDX_ADDR, addr);
258 pci_read_config_dword(amd_chipset.nb_dev,
259 NB_PCIE_INDX_DATA, &val);
260 if (disable)
261 val &= ~(0x3f << 7);
262 else
263 val |= 0x3f << 7;
264
265 pci_write_config_dword(amd_chipset.nb_dev,
266 NB_PCIE_INDX_DATA, val);
267 }
268
269 spin_unlock_irqrestore(&amd_lock, flags);
270 return;
271}
272
273void usb_amd_quirk_pll_disable(void)
274{
275 usb_amd_quirk_pll(1);
276}
277EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_disable);
278
279void usb_amd_quirk_pll_enable(void)
280{
281 usb_amd_quirk_pll(0);
282}
283EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_enable);
284
285void usb_amd_dev_put(void)
286{
287 unsigned long flags;
288
289 spin_lock_irqsave(&amd_lock, flags);
290
291 amd_chipset.probe_count--;
292 if (amd_chipset.probe_count > 0) {
293 spin_unlock_irqrestore(&amd_lock, flags);
294 return;
295 }
296
297 if (amd_chipset.nb_dev) {
298 pci_dev_put(amd_chipset.nb_dev);
299 amd_chipset.nb_dev = NULL;
300 }
301 if (amd_chipset.smbus_dev) {
302 pci_dev_put(amd_chipset.smbus_dev);
303 amd_chipset.smbus_dev = NULL;
304 }
305 amd_chipset.nb_type = 0;
306 amd_chipset.sb_type = 0;
307 amd_chipset.isoc_reqs = 0;
308 amd_chipset.probe_result = 0;
309
310 spin_unlock_irqrestore(&amd_lock, flags);
311}
312EXPORT_SYMBOL_GPL(usb_amd_dev_put);
55 313
56/* 314/*
57 * Make sure the controller is completely inactive, unable to 315 * Make sure the controller is completely inactive, unable to
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h
index 1564edfff6fe..6ae9f78e9938 100644
--- a/drivers/usb/host/pci-quirks.h
+++ b/drivers/usb/host/pci-quirks.h
@@ -1,7 +1,17 @@
1#ifndef __LINUX_USB_PCI_QUIRKS_H 1#ifndef __LINUX_USB_PCI_QUIRKS_H
2#define __LINUX_USB_PCI_QUIRKS_H 2#define __LINUX_USB_PCI_QUIRKS_H
3 3
4#ifdef CONFIG_PCI
4void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); 5void uhci_reset_hc(struct pci_dev *pdev, unsigned long base);
5int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base); 6int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base);
7int usb_amd_find_chipset_info(void);
8void usb_amd_dev_put(void);
9void usb_amd_quirk_pll_disable(void);
10void usb_amd_quirk_pll_enable(void);
11#else
12static inline void usb_amd_quirk_pll_disable(void) {}
13static inline void usb_amd_quirk_pll_enable(void) {}
14static inline void usb_amd_dev_put(void) {}
15#endif /* CONFIG_PCI */
6 16
7#endif /* __LINUX_USB_PCI_QUIRKS_H */ 17#endif /* __LINUX_USB_PCI_QUIRKS_H */
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 3076b1cc05df..db6f8b9c19b6 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -2150,8 +2150,9 @@ static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597,
2150 desc->bDescLength = 9; 2150 desc->bDescLength = 9;
2151 desc->bPwrOn2PwrGood = 0; 2151 desc->bPwrOn2PwrGood = 0;
2152 desc->wHubCharacteristics = cpu_to_le16(0x0011); 2152 desc->wHubCharacteristics = cpu_to_le16(0x0011);
2153 desc->bitmap[0] = ((1 << r8a66597->max_root_hub) - 1) << 1; 2153 desc->u.hs.DeviceRemovable[0] =
2154 desc->bitmap[1] = ~0; 2154 ((1 << r8a66597->max_root_hub) - 1) << 1;
2155 desc->u.hs.DeviceRemovable[1] = ~0;
2155} 2156}
2156 2157
2157static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 2158static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 2e9602a10e9b..18b7099a8125 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1111,9 +1111,9 @@ sl811h_hub_descriptor (
1111 1111
1112 desc->wHubCharacteristics = cpu_to_le16(temp); 1112 desc->wHubCharacteristics = cpu_to_le16(temp);
1113 1113
1114 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ 1114 /* ports removable, and legacy PortPwrCtrlMask */
1115 desc->bitmap[0] = 0 << 1; 1115 desc->u.hs.DeviceRemovable[0] = 0 << 1;
1116 desc->bitmap[1] = ~0; 1116 desc->u.hs.DeviceRemovable[1] = ~0;
1117} 1117}
1118 1118
1119static void 1119static void
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index fab764946c74..b4785934e091 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -2604,13 +2604,14 @@ static int u132_roothub_descriptor(struct u132 *u132,
2604 retval = u132_read_pcimem(u132, roothub.b, &rh_b); 2604 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2605 if (retval) 2605 if (retval)
2606 return retval; 2606 return retval;
2607 memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); 2607 memset(desc->u.hs.DeviceRemovable, 0xff,
2608 desc->bitmap[0] = rh_b & RH_B_DR; 2608 sizeof(desc->u.hs.DeviceRemovable));
2609 desc->u.hs.DeviceRemovable[0] = rh_b & RH_B_DR;
2609 if (u132->num_ports > 7) { 2610 if (u132->num_ports > 7) {
2610 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8; 2611 desc->u.hs.DeviceRemovable[1] = (rh_b & RH_B_DR) >> 8;
2611 desc->bitmap[2] = 0xff; 2612 desc->u.hs.DeviceRemovable[2] = 0xff;
2612 } else 2613 } else
2613 desc->bitmap[1] = 0xff; 2614 desc->u.hs.DeviceRemovable[1] = 0xff;
2614 return 0; 2615 return 0;
2615} 2616}
2616 2617
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index cee867829ec9..4f65b14e5e08 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -471,7 +471,7 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd)
471 471
472/* 472/*
473 * Store the current frame number in uhci->frame_number if the controller 473 * Store the current frame number in uhci->frame_number if the controller
474 * is runnning. Expand from 11 bits (of which we use only 10) to a 474 * is running. Expand from 11 bits (of which we use only 10) to a
475 * full-sized integer. 475 * full-sized integer.
476 * 476 *
477 * Like many other parts of the driver, this code relies on being polled 477 * Like many other parts of the driver, this code relies on being polled
diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h
index 78c4edac1db1..ce5c9e51748e 100644
--- a/drivers/usb/host/xhci-ext-caps.h
+++ b/drivers/usb/host/xhci-ext-caps.h
@@ -19,8 +19,8 @@
19 * along with this program; if not, write to the Free Software Foundation, 19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22/* Up to 16 microframes to halt an HC - one microframe is 125 microsectonds */ 22/* Up to 16 ms to halt an HC */
23#define XHCI_MAX_HALT_USEC (16*125) 23#define XHCI_MAX_HALT_USEC (16*1000)
24/* HC not running - set to 1 when run/stop bit is cleared. */ 24/* HC not running - set to 1 when run/stop bit is cleared. */
25#define XHCI_STS_HALT (1<<0) 25#define XHCI_STS_HALT (1<<0)
26 26
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 5d963e350494..a78f2ebd11b7 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -28,27 +28,15 @@
28#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ 28#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
29 PORT_RC | PORT_PLC | PORT_PE) 29 PORT_RC | PORT_PLC | PORT_PE)
30 30
31static void xhci_hub_descriptor(struct xhci_hcd *xhci, 31static void xhci_common_hub_descriptor(struct xhci_hcd *xhci,
32 struct usb_hub_descriptor *desc) 32 struct usb_hub_descriptor *desc, int ports)
33{ 33{
34 int ports;
35 u16 temp; 34 u16 temp;
36 35
37 ports = HCS_MAX_PORTS(xhci->hcs_params1);
38
39 /* USB 3.0 hubs have a different descriptor, but we fake this for now */
40 desc->bDescriptorType = 0x29;
41 desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.9 says 20ms max */ 36 desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.9 says 20ms max */
42 desc->bHubContrCurrent = 0; 37 desc->bHubContrCurrent = 0;
43 38
44 desc->bNbrPorts = ports; 39 desc->bNbrPorts = ports;
45 temp = 1 + (ports / 8);
46 desc->bDescLength = 7 + 2 * temp;
47
48 /* Why does core/hcd.h define bitmap? It's just confusing. */
49 memset(&desc->DeviceRemovable[0], 0, temp);
50 memset(&desc->DeviceRemovable[temp], 0xff, temp);
51
52 /* Ugh, these should be #defines, FIXME */ 40 /* Ugh, these should be #defines, FIXME */
53 /* Using table 11-13 in USB 2.0 spec. */ 41 /* Using table 11-13 in USB 2.0 spec. */
54 temp = 0; 42 temp = 0;
@@ -65,14 +53,108 @@ static void xhci_hub_descriptor(struct xhci_hcd *xhci,
65 desc->wHubCharacteristics = (__force __u16) cpu_to_le16(temp); 53 desc->wHubCharacteristics = (__force __u16) cpu_to_le16(temp);
66} 54}
67 55
56/* Fill in the USB 2.0 roothub descriptor */
57static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
58 struct usb_hub_descriptor *desc)
59{
60 int ports;
61 u16 temp;
62 __u8 port_removable[(USB_MAXCHILDREN + 1 + 7) / 8];
63 u32 portsc;
64 unsigned int i;
65
66 ports = xhci->num_usb2_ports;
67
68 xhci_common_hub_descriptor(xhci, desc, ports);
69 desc->bDescriptorType = 0x29;
70 temp = 1 + (ports / 8);
71 desc->bDescLength = 7 + 2 * temp;
72
73 /* The Device Removable bits are reported on a byte granularity.
74 * If the port doesn't exist within that byte, the bit is set to 0.
75 */
76 memset(port_removable, 0, sizeof(port_removable));
77 for (i = 0; i < ports; i++) {
78 portsc = xhci_readl(xhci, xhci->usb3_ports[i]);
79 /* If a device is removable, PORTSC reports a 0, same as in the
80 * hub descriptor DeviceRemovable bits.
81 */
82 if (portsc & PORT_DEV_REMOVE)
83 /* This math is hairy because bit 0 of DeviceRemovable
84 * is reserved, and bit 1 is for port 1, etc.
85 */
86 port_removable[(i + 1) / 8] |= 1 << ((i + 1) % 8);
87 }
88
89 /* ch11.h defines a hub descriptor that has room for USB_MAXCHILDREN
90 * ports on it. The USB 2.0 specification says that there are two
91 * variable length fields at the end of the hub descriptor:
92 * DeviceRemovable and PortPwrCtrlMask. But since we can have less than
93 * USB_MAXCHILDREN ports, we may need to use the DeviceRemovable array
94 * to set PortPwrCtrlMask bits. PortPwrCtrlMask must always be set to
95 * 0xFF, so we initialize the both arrays (DeviceRemovable and
96 * PortPwrCtrlMask) to 0xFF. Then we set the DeviceRemovable for each
97 * set of ports that actually exist.
98 */
99 memset(desc->u.hs.DeviceRemovable, 0xff,
100 sizeof(desc->u.hs.DeviceRemovable));
101 memset(desc->u.hs.PortPwrCtrlMask, 0xff,
102 sizeof(desc->u.hs.PortPwrCtrlMask));
103
104 for (i = 0; i < (ports + 1 + 7) / 8; i++)
105 memset(&desc->u.hs.DeviceRemovable[i], port_removable[i],
106 sizeof(__u8));
107}
108
109/* Fill in the USB 3.0 roothub descriptor */
110static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
111 struct usb_hub_descriptor *desc)
112{
113 int ports;
114 u16 port_removable;
115 u32 portsc;
116 unsigned int i;
117
118 ports = xhci->num_usb3_ports;
119 xhci_common_hub_descriptor(xhci, desc, ports);
120 desc->bDescriptorType = 0x2a;
121 desc->bDescLength = 12;
122
123 /* header decode latency should be zero for roothubs,
124 * see section 4.23.5.2.
125 */
126 desc->u.ss.bHubHdrDecLat = 0;
127 desc->u.ss.wHubDelay = 0;
128
129 port_removable = 0;
130 /* bit 0 is reserved, bit 1 is for port 1, etc. */
131 for (i = 0; i < ports; i++) {
132 portsc = xhci_readl(xhci, xhci->usb3_ports[i]);
133 if (portsc & PORT_DEV_REMOVE)
134 port_removable |= 1 << (i + 1);
135 }
136 memset(&desc->u.ss.DeviceRemovable,
137 (__force __u16) cpu_to_le16(port_removable),
138 sizeof(__u16));
139}
140
141static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
142 struct usb_hub_descriptor *desc)
143{
144
145 if (hcd->speed == HCD_USB3)
146 xhci_usb3_hub_descriptor(hcd, xhci, desc);
147 else
148 xhci_usb2_hub_descriptor(hcd, xhci, desc);
149
150}
151
68static unsigned int xhci_port_speed(unsigned int port_status) 152static unsigned int xhci_port_speed(unsigned int port_status)
69{ 153{
70 if (DEV_LOWSPEED(port_status)) 154 if (DEV_LOWSPEED(port_status))
71 return USB_PORT_STAT_LOW_SPEED; 155 return USB_PORT_STAT_LOW_SPEED;
72 if (DEV_HIGHSPEED(port_status)) 156 if (DEV_HIGHSPEED(port_status))
73 return USB_PORT_STAT_HIGH_SPEED; 157 return USB_PORT_STAT_HIGH_SPEED;
74 if (DEV_SUPERSPEED(port_status))
75 return USB_PORT_STAT_SUPER_SPEED;
76 /* 158 /*
77 * FIXME: Yes, we should check for full speed, but the core uses that as 159 * FIXME: Yes, we should check for full speed, but the core uses that as
78 * a default in portspeed() in usb/core/hub.c (which is the only place 160 * a default in portspeed() in usb/core/hub.c (which is the only place
@@ -135,17 +217,22 @@ u32 xhci_port_state_to_neutral(u32 state)
135 217
136/* 218/*
137 * find slot id based on port number. 219 * find slot id based on port number.
220 * @port: The one-based port number from one of the two split roothubs.
138 */ 221 */
139int xhci_find_slot_id_by_port(struct xhci_hcd *xhci, u16 port) 222int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
223 u16 port)
140{ 224{
141 int slot_id; 225 int slot_id;
142 int i; 226 int i;
227 enum usb_device_speed speed;
143 228
144 slot_id = 0; 229 slot_id = 0;
145 for (i = 0; i < MAX_HC_SLOTS; i++) { 230 for (i = 0; i < MAX_HC_SLOTS; i++) {
146 if (!xhci->devs[i]) 231 if (!xhci->devs[i])
147 continue; 232 continue;
148 if (xhci->devs[i]->port == port) { 233 speed = xhci->devs[i]->udev->speed;
234 if (((speed == USB_SPEED_SUPER) == (hcd->speed == HCD_USB3))
235 && xhci->devs[i]->port == port) {
149 slot_id = i; 236 slot_id = i;
150 break; 237 break;
151 } 238 }
@@ -226,11 +313,11 @@ void xhci_ring_device(struct xhci_hcd *xhci, int slot_id)
226 return; 313 return;
227} 314}
228 315
229static void xhci_disable_port(struct xhci_hcd *xhci, u16 wIndex, 316static void xhci_disable_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
230 u32 __iomem *addr, u32 port_status) 317 u16 wIndex, u32 __iomem *addr, u32 port_status)
231{ 318{
232 /* Don't allow the USB core to disable SuperSpeed ports. */ 319 /* Don't allow the USB core to disable SuperSpeed ports. */
233 if (xhci->port_array[wIndex] == 0x03) { 320 if (hcd->speed == HCD_USB3) {
234 xhci_dbg(xhci, "Ignoring request to disable " 321 xhci_dbg(xhci, "Ignoring request to disable "
235 "SuperSpeed port.\n"); 322 "SuperSpeed port.\n");
236 return; 323 return;
@@ -289,10 +376,18 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
289 unsigned long flags; 376 unsigned long flags;
290 u32 temp, temp1, status; 377 u32 temp, temp1, status;
291 int retval = 0; 378 int retval = 0;
292 u32 __iomem *addr; 379 u32 __iomem **port_array;
293 int slot_id; 380 int slot_id;
294 381 struct xhci_bus_state *bus_state;
295 ports = HCS_MAX_PORTS(xhci->hcs_params1); 382
383 if (hcd->speed == HCD_USB3) {
384 ports = xhci->num_usb3_ports;
385 port_array = xhci->usb3_ports;
386 } else {
387 ports = xhci->num_usb2_ports;
388 port_array = xhci->usb2_ports;
389 }
390 bus_state = &xhci->bus_state[hcd_index(hcd)];
296 391
297 spin_lock_irqsave(&xhci->lock, flags); 392 spin_lock_irqsave(&xhci->lock, flags);
298 switch (typeReq) { 393 switch (typeReq) {
@@ -301,17 +396,35 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
301 memset(buf, 0, 4); 396 memset(buf, 0, 4);
302 break; 397 break;
303 case GetHubDescriptor: 398 case GetHubDescriptor:
304 xhci_hub_descriptor(xhci, (struct usb_hub_descriptor *) buf); 399 /* Check to make sure userspace is asking for the USB 3.0 hub
400 * descriptor for the USB 3.0 roothub. If not, we stall the
401 * endpoint, like external hubs do.
402 */
403 if (hcd->speed == HCD_USB3 &&
404 (wLength < USB_DT_SS_HUB_SIZE ||
405 wValue != (USB_DT_SS_HUB << 8))) {
406 xhci_dbg(xhci, "Wrong hub descriptor type for "
407 "USB 3.0 roothub.\n");
408 goto error;
409 }
410 xhci_hub_descriptor(hcd, xhci,
411 (struct usb_hub_descriptor *) buf);
305 break; 412 break;
306 case GetPortStatus: 413 case GetPortStatus:
307 if (!wIndex || wIndex > ports) 414 if (!wIndex || wIndex > ports)
308 goto error; 415 goto error;
309 wIndex--; 416 wIndex--;
310 status = 0; 417 status = 0;
311 addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS*(wIndex & 0xff); 418 temp = xhci_readl(xhci, port_array[wIndex]);
312 temp = xhci_readl(xhci, addr); 419 if (temp == 0xffffffff) {
420 retval = -ENODEV;
421 break;
422 }
313 xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n", wIndex, temp); 423 xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n", wIndex, temp);
314 424
425 /* FIXME - should we return a port status value like the USB
426 * 3.0 external hubs do?
427 */
315 /* wPortChange bits */ 428 /* wPortChange bits */
316 if (temp & PORT_CSC) 429 if (temp & PORT_CSC)
317 status |= USB_PORT_STAT_C_CONNECTION << 16; 430 status |= USB_PORT_STAT_C_CONNECTION << 16;
@@ -330,38 +443,33 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
330 if ((temp & PORT_RESET) || !(temp & PORT_PE)) 443 if ((temp & PORT_RESET) || !(temp & PORT_PE))
331 goto error; 444 goto error;
332 if (!DEV_SUPERSPEED(temp) && time_after_eq(jiffies, 445 if (!DEV_SUPERSPEED(temp) && time_after_eq(jiffies,
333 xhci->resume_done[wIndex])) { 446 bus_state->resume_done[wIndex])) {
334 xhci_dbg(xhci, "Resume USB2 port %d\n", 447 xhci_dbg(xhci, "Resume USB2 port %d\n",
335 wIndex + 1); 448 wIndex + 1);
336 xhci->resume_done[wIndex] = 0; 449 bus_state->resume_done[wIndex] = 0;
337 temp1 = xhci_port_state_to_neutral(temp); 450 temp1 = xhci_port_state_to_neutral(temp);
338 temp1 &= ~PORT_PLS_MASK; 451 temp1 &= ~PORT_PLS_MASK;
339 temp1 |= PORT_LINK_STROBE | XDEV_U0; 452 temp1 |= PORT_LINK_STROBE | XDEV_U0;
340 xhci_writel(xhci, temp1, addr); 453 xhci_writel(xhci, temp1, port_array[wIndex]);
341 454
342 xhci_dbg(xhci, "set port %d resume\n", 455 xhci_dbg(xhci, "set port %d resume\n",
343 wIndex + 1); 456 wIndex + 1);
344 slot_id = xhci_find_slot_id_by_port(xhci, 457 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
345 wIndex + 1); 458 wIndex + 1);
346 if (!slot_id) { 459 if (!slot_id) {
347 xhci_dbg(xhci, "slot_id is zero\n"); 460 xhci_dbg(xhci, "slot_id is zero\n");
348 goto error; 461 goto error;
349 } 462 }
350 xhci_ring_device(xhci, slot_id); 463 xhci_ring_device(xhci, slot_id);
351 xhci->port_c_suspend[wIndex >> 5] |= 464 bus_state->port_c_suspend |= 1 << wIndex;
352 1 << (wIndex & 31); 465 bus_state->suspended_ports &= ~(1 << wIndex);
353 xhci->suspended_ports[wIndex >> 5] &=
354 ~(1 << (wIndex & 31));
355 } 466 }
356 } 467 }
357 if ((temp & PORT_PLS_MASK) == XDEV_U0 468 if ((temp & PORT_PLS_MASK) == XDEV_U0
358 && (temp & PORT_POWER) 469 && (temp & PORT_POWER)
359 && (xhci->suspended_ports[wIndex >> 5] & 470 && (bus_state->suspended_ports & (1 << wIndex))) {
360 (1 << (wIndex & 31)))) { 471 bus_state->suspended_ports &= ~(1 << wIndex);
361 xhci->suspended_ports[wIndex >> 5] &= 472 bus_state->port_c_suspend |= 1 << wIndex;
362 ~(1 << (wIndex & 31));
363 xhci->port_c_suspend[wIndex >> 5] |=
364 1 << (wIndex & 31);
365 } 473 }
366 if (temp & PORT_CONNECT) { 474 if (temp & PORT_CONNECT) {
367 status |= USB_PORT_STAT_CONNECTION; 475 status |= USB_PORT_STAT_CONNECTION;
@@ -375,7 +483,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
375 status |= USB_PORT_STAT_RESET; 483 status |= USB_PORT_STAT_RESET;
376 if (temp & PORT_POWER) 484 if (temp & PORT_POWER)
377 status |= USB_PORT_STAT_POWER; 485 status |= USB_PORT_STAT_POWER;
378 if (xhci->port_c_suspend[wIndex >> 5] & (1 << (wIndex & 31))) 486 if (bus_state->port_c_suspend & (1 << wIndex))
379 status |= 1 << USB_PORT_FEAT_C_SUSPEND; 487 status |= 1 << USB_PORT_FEAT_C_SUSPEND;
380 xhci_dbg(xhci, "Get port status returned 0x%x\n", status); 488 xhci_dbg(xhci, "Get port status returned 0x%x\n", status);
381 put_unaligned(cpu_to_le32(status), (__le32 *) buf); 489 put_unaligned(cpu_to_le32(status), (__le32 *) buf);
@@ -385,12 +493,16 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
385 if (!wIndex || wIndex > ports) 493 if (!wIndex || wIndex > ports)
386 goto error; 494 goto error;
387 wIndex--; 495 wIndex--;
388 addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS*(wIndex & 0xff); 496 temp = xhci_readl(xhci, port_array[wIndex]);
389 temp = xhci_readl(xhci, addr); 497 if (temp == 0xffffffff) {
498 retval = -ENODEV;
499 break;
500 }
390 temp = xhci_port_state_to_neutral(temp); 501 temp = xhci_port_state_to_neutral(temp);
502 /* FIXME: What new port features do we need to support? */
391 switch (wValue) { 503 switch (wValue) {
392 case USB_PORT_FEAT_SUSPEND: 504 case USB_PORT_FEAT_SUSPEND:
393 temp = xhci_readl(xhci, addr); 505 temp = xhci_readl(xhci, port_array[wIndex]);
394 /* In spec software should not attempt to suspend 506 /* In spec software should not attempt to suspend
395 * a port unless the port reports that it is in the 507 * a port unless the port reports that it is in the
396 * enabled (PED = ‘1’,PLS < ‘3’) state. 508 * enabled (PED = ‘1’,PLS < ‘3’) state.
@@ -402,7 +514,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
402 goto error; 514 goto error;
403 } 515 }
404 516
405 slot_id = xhci_find_slot_id_by_port(xhci, wIndex + 1); 517 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
518 wIndex + 1);
406 if (!slot_id) { 519 if (!slot_id) {
407 xhci_warn(xhci, "slot_id is zero\n"); 520 xhci_warn(xhci, "slot_id is zero\n");
408 goto error; 521 goto error;
@@ -415,15 +528,14 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
415 temp = xhci_port_state_to_neutral(temp); 528 temp = xhci_port_state_to_neutral(temp);
416 temp &= ~PORT_PLS_MASK; 529 temp &= ~PORT_PLS_MASK;
417 temp |= PORT_LINK_STROBE | XDEV_U3; 530 temp |= PORT_LINK_STROBE | XDEV_U3;
418 xhci_writel(xhci, temp, addr); 531 xhci_writel(xhci, temp, port_array[wIndex]);
419 532
420 spin_unlock_irqrestore(&xhci->lock, flags); 533 spin_unlock_irqrestore(&xhci->lock, flags);
421 msleep(10); /* wait device to enter */ 534 msleep(10); /* wait device to enter */
422 spin_lock_irqsave(&xhci->lock, flags); 535 spin_lock_irqsave(&xhci->lock, flags);
423 536
424 temp = xhci_readl(xhci, addr); 537 temp = xhci_readl(xhci, port_array[wIndex]);
425 xhci->suspended_ports[wIndex >> 5] |= 538 bus_state->suspended_ports |= 1 << wIndex;
426 1 << (wIndex & (31));
427 break; 539 break;
428 case USB_PORT_FEAT_POWER: 540 case USB_PORT_FEAT_POWER:
429 /* 541 /*
@@ -432,34 +544,39 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
432 * However, khubd will ignore the roothub events until 544 * However, khubd will ignore the roothub events until
433 * the roothub is registered. 545 * the roothub is registered.
434 */ 546 */
435 xhci_writel(xhci, temp | PORT_POWER, addr); 547 xhci_writel(xhci, temp | PORT_POWER,
548 port_array[wIndex]);
436 549
437 temp = xhci_readl(xhci, addr); 550 temp = xhci_readl(xhci, port_array[wIndex]);
438 xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp); 551 xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp);
439 break; 552 break;
440 case USB_PORT_FEAT_RESET: 553 case USB_PORT_FEAT_RESET:
441 temp = (temp | PORT_RESET); 554 temp = (temp | PORT_RESET);
442 xhci_writel(xhci, temp, addr); 555 xhci_writel(xhci, temp, port_array[wIndex]);
443 556
444 temp = xhci_readl(xhci, addr); 557 temp = xhci_readl(xhci, port_array[wIndex]);
445 xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp); 558 xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp);
446 break; 559 break;
447 default: 560 default:
448 goto error; 561 goto error;
449 } 562 }
450 temp = xhci_readl(xhci, addr); /* unblock any posted writes */ 563 /* unblock any posted writes */
564 temp = xhci_readl(xhci, port_array[wIndex]);
451 break; 565 break;
452 case ClearPortFeature: 566 case ClearPortFeature:
453 if (!wIndex || wIndex > ports) 567 if (!wIndex || wIndex > ports)
454 goto error; 568 goto error;
455 wIndex--; 569 wIndex--;
456 addr = &xhci->op_regs->port_status_base + 570 temp = xhci_readl(xhci, port_array[wIndex]);
457 NUM_PORT_REGS*(wIndex & 0xff); 571 if (temp == 0xffffffff) {
458 temp = xhci_readl(xhci, addr); 572 retval = -ENODEV;
573 break;
574 }
575 /* FIXME: What new port features do we need to support? */
459 temp = xhci_port_state_to_neutral(temp); 576 temp = xhci_port_state_to_neutral(temp);
460 switch (wValue) { 577 switch (wValue) {
461 case USB_PORT_FEAT_SUSPEND: 578 case USB_PORT_FEAT_SUSPEND:
462 temp = xhci_readl(xhci, addr); 579 temp = xhci_readl(xhci, port_array[wIndex]);
463 xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n"); 580 xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n");
464 xhci_dbg(xhci, "PORTSC %04x\n", temp); 581 xhci_dbg(xhci, "PORTSC %04x\n", temp);
465 if (temp & PORT_RESET) 582 if (temp & PORT_RESET)
@@ -471,30 +588,34 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
471 temp = xhci_port_state_to_neutral(temp); 588 temp = xhci_port_state_to_neutral(temp);
472 temp &= ~PORT_PLS_MASK; 589 temp &= ~PORT_PLS_MASK;
473 temp |= PORT_LINK_STROBE | XDEV_U0; 590 temp |= PORT_LINK_STROBE | XDEV_U0;
474 xhci_writel(xhci, temp, addr); 591 xhci_writel(xhci, temp,
475 xhci_readl(xhci, addr); 592 port_array[wIndex]);
593 xhci_readl(xhci, port_array[wIndex]);
476 } else { 594 } else {
477 temp = xhci_port_state_to_neutral(temp); 595 temp = xhci_port_state_to_neutral(temp);
478 temp &= ~PORT_PLS_MASK; 596 temp &= ~PORT_PLS_MASK;
479 temp |= PORT_LINK_STROBE | XDEV_RESUME; 597 temp |= PORT_LINK_STROBE | XDEV_RESUME;
480 xhci_writel(xhci, temp, addr); 598 xhci_writel(xhci, temp,
599 port_array[wIndex]);
481 600
482 spin_unlock_irqrestore(&xhci->lock, 601 spin_unlock_irqrestore(&xhci->lock,
483 flags); 602 flags);
484 msleep(20); 603 msleep(20);
485 spin_lock_irqsave(&xhci->lock, flags); 604 spin_lock_irqsave(&xhci->lock, flags);
486 605
487 temp = xhci_readl(xhci, addr); 606 temp = xhci_readl(xhci,
607 port_array[wIndex]);
488 temp = xhci_port_state_to_neutral(temp); 608 temp = xhci_port_state_to_neutral(temp);
489 temp &= ~PORT_PLS_MASK; 609 temp &= ~PORT_PLS_MASK;
490 temp |= PORT_LINK_STROBE | XDEV_U0; 610 temp |= PORT_LINK_STROBE | XDEV_U0;
491 xhci_writel(xhci, temp, addr); 611 xhci_writel(xhci, temp,
612 port_array[wIndex]);
492 } 613 }
493 xhci->port_c_suspend[wIndex >> 5] |= 614 bus_state->port_c_suspend |= 1 << wIndex;
494 1 << (wIndex & 31);
495 } 615 }
496 616
497 slot_id = xhci_find_slot_id_by_port(xhci, wIndex + 1); 617 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
618 wIndex + 1);
498 if (!slot_id) { 619 if (!slot_id) {
499 xhci_dbg(xhci, "slot_id is zero\n"); 620 xhci_dbg(xhci, "slot_id is zero\n");
500 goto error; 621 goto error;
@@ -502,17 +623,17 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
502 xhci_ring_device(xhci, slot_id); 623 xhci_ring_device(xhci, slot_id);
503 break; 624 break;
504 case USB_PORT_FEAT_C_SUSPEND: 625 case USB_PORT_FEAT_C_SUSPEND:
505 xhci->port_c_suspend[wIndex >> 5] &= 626 bus_state->port_c_suspend &= ~(1 << wIndex);
506 ~(1 << (wIndex & 31));
507 case USB_PORT_FEAT_C_RESET: 627 case USB_PORT_FEAT_C_RESET:
508 case USB_PORT_FEAT_C_CONNECTION: 628 case USB_PORT_FEAT_C_CONNECTION:
509 case USB_PORT_FEAT_C_OVER_CURRENT: 629 case USB_PORT_FEAT_C_OVER_CURRENT:
510 case USB_PORT_FEAT_C_ENABLE: 630 case USB_PORT_FEAT_C_ENABLE:
511 xhci_clear_port_change_bit(xhci, wValue, wIndex, 631 xhci_clear_port_change_bit(xhci, wValue, wIndex,
512 addr, temp); 632 port_array[wIndex], temp);
513 break; 633 break;
514 case USB_PORT_FEAT_ENABLE: 634 case USB_PORT_FEAT_ENABLE:
515 xhci_disable_port(xhci, wIndex, addr, temp); 635 xhci_disable_port(hcd, xhci, wIndex,
636 port_array[wIndex], temp);
516 break; 637 break;
517 default: 638 default:
518 goto error; 639 goto error;
@@ -543,9 +664,17 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
543 int i, retval; 664 int i, retval;
544 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 665 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
545 int ports; 666 int ports;
546 u32 __iomem *addr; 667 u32 __iomem **port_array;
547 668 struct xhci_bus_state *bus_state;
548 ports = HCS_MAX_PORTS(xhci->hcs_params1); 669
670 if (hcd->speed == HCD_USB3) {
671 ports = xhci->num_usb3_ports;
672 port_array = xhci->usb3_ports;
673 } else {
674 ports = xhci->num_usb2_ports;
675 port_array = xhci->usb2_ports;
676 }
677 bus_state = &xhci->bus_state[hcd_index(hcd)];
549 678
550 /* Initial status is no changes */ 679 /* Initial status is no changes */
551 retval = (ports + 8) / 8; 680 retval = (ports + 8) / 8;
@@ -557,13 +686,15 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
557 spin_lock_irqsave(&xhci->lock, flags); 686 spin_lock_irqsave(&xhci->lock, flags);
558 /* For each port, did anything change? If so, set that bit in buf. */ 687 /* For each port, did anything change? If so, set that bit in buf. */
559 for (i = 0; i < ports; i++) { 688 for (i = 0; i < ports; i++) {
560 addr = &xhci->op_regs->port_status_base + 689 temp = xhci_readl(xhci, port_array[i]);
561 NUM_PORT_REGS*i; 690 if (temp == 0xffffffff) {
562 temp = xhci_readl(xhci, addr); 691 retval = -ENODEV;
692 break;
693 }
563 if ((temp & mask) != 0 || 694 if ((temp & mask) != 0 ||
564 (xhci->port_c_suspend[i >> 5] & 1 << (i & 31)) || 695 (bus_state->port_c_suspend & 1 << i) ||
565 (xhci->resume_done[i] && time_after_eq( 696 (bus_state->resume_done[i] && time_after_eq(
566 jiffies, xhci->resume_done[i]))) { 697 jiffies, bus_state->resume_done[i]))) {
567 buf[(i + 1) / 8] |= 1 << (i + 1) % 8; 698 buf[(i + 1) / 8] |= 1 << (i + 1) % 8;
568 status = 1; 699 status = 1;
569 } 700 }
@@ -577,42 +708,51 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
577int xhci_bus_suspend(struct usb_hcd *hcd) 708int xhci_bus_suspend(struct usb_hcd *hcd)
578{ 709{
579 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 710 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
580 int port; 711 int max_ports, port_index;
712 u32 __iomem **port_array;
713 struct xhci_bus_state *bus_state;
581 unsigned long flags; 714 unsigned long flags;
582 715
583 xhci_dbg(xhci, "suspend root hub\n"); 716 if (hcd->speed == HCD_USB3) {
717 max_ports = xhci->num_usb3_ports;
718 port_array = xhci->usb3_ports;
719 xhci_dbg(xhci, "suspend USB 3.0 root hub\n");
720 } else {
721 max_ports = xhci->num_usb2_ports;
722 port_array = xhci->usb2_ports;
723 xhci_dbg(xhci, "suspend USB 2.0 root hub\n");
724 }
725 bus_state = &xhci->bus_state[hcd_index(hcd)];
584 726
585 spin_lock_irqsave(&xhci->lock, flags); 727 spin_lock_irqsave(&xhci->lock, flags);
586 728
587 if (hcd->self.root_hub->do_remote_wakeup) { 729 if (hcd->self.root_hub->do_remote_wakeup) {
588 port = HCS_MAX_PORTS(xhci->hcs_params1); 730 port_index = max_ports;
589 while (port--) { 731 while (port_index--) {
590 if (xhci->resume_done[port] != 0) { 732 if (bus_state->resume_done[port_index] != 0) {
591 spin_unlock_irqrestore(&xhci->lock, flags); 733 spin_unlock_irqrestore(&xhci->lock, flags);
592 xhci_dbg(xhci, "suspend failed because " 734 xhci_dbg(xhci, "suspend failed because "
593 "port %d is resuming\n", 735 "port %d is resuming\n",
594 port + 1); 736 port_index + 1);
595 return -EBUSY; 737 return -EBUSY;
596 } 738 }
597 } 739 }
598 } 740 }
599 741
600 port = HCS_MAX_PORTS(xhci->hcs_params1); 742 port_index = max_ports;
601 xhci->bus_suspended = 0; 743 bus_state->bus_suspended = 0;
602 while (port--) { 744 while (port_index--) {
603 /* suspend the port if the port is not suspended */ 745 /* suspend the port if the port is not suspended */
604 u32 __iomem *addr;
605 u32 t1, t2; 746 u32 t1, t2;
606 int slot_id; 747 int slot_id;
607 748
608 addr = &xhci->op_regs->port_status_base + 749 t1 = xhci_readl(xhci, port_array[port_index]);
609 NUM_PORT_REGS * (port & 0xff);
610 t1 = xhci_readl(xhci, addr);
611 t2 = xhci_port_state_to_neutral(t1); 750 t2 = xhci_port_state_to_neutral(t1);
612 751
613 if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) { 752 if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) {
614 xhci_dbg(xhci, "port %d not suspended\n", port); 753 xhci_dbg(xhci, "port %d not suspended\n", port_index);
615 slot_id = xhci_find_slot_id_by_port(xhci, port + 1); 754 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
755 port_index + 1);
616 if (slot_id) { 756 if (slot_id) {
617 spin_unlock_irqrestore(&xhci->lock, flags); 757 spin_unlock_irqrestore(&xhci->lock, flags);
618 xhci_stop_device(xhci, slot_id, 1); 758 xhci_stop_device(xhci, slot_id, 1);
@@ -620,7 +760,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
620 } 760 }
621 t2 &= ~PORT_PLS_MASK; 761 t2 &= ~PORT_PLS_MASK;
622 t2 |= PORT_LINK_STROBE | XDEV_U3; 762 t2 |= PORT_LINK_STROBE | XDEV_U3;
623 set_bit(port, &xhci->bus_suspended); 763 set_bit(port_index, &bus_state->bus_suspended);
624 } 764 }
625 if (hcd->self.root_hub->do_remote_wakeup) { 765 if (hcd->self.root_hub->do_remote_wakeup) {
626 if (t1 & PORT_CONNECT) { 766 if (t1 & PORT_CONNECT) {
@@ -635,22 +775,24 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
635 775
636 t1 = xhci_port_state_to_neutral(t1); 776 t1 = xhci_port_state_to_neutral(t1);
637 if (t1 != t2) 777 if (t1 != t2)
638 xhci_writel(xhci, t2, addr); 778 xhci_writel(xhci, t2, port_array[port_index]);
639 779
640 if (DEV_HIGHSPEED(t1)) { 780 if (DEV_HIGHSPEED(t1)) {
641 /* enable remote wake up for USB 2.0 */ 781 /* enable remote wake up for USB 2.0 */
642 u32 __iomem *addr; 782 u32 __iomem *addr;
643 u32 tmp; 783 u32 tmp;
644 784
645 addr = &xhci->op_regs->port_power_base + 785 /* Add one to the port status register address to get
646 NUM_PORT_REGS * (port & 0xff); 786 * the port power control register address.
787 */
788 addr = port_array[port_index] + 1;
647 tmp = xhci_readl(xhci, addr); 789 tmp = xhci_readl(xhci, addr);
648 tmp |= PORT_RWE; 790 tmp |= PORT_RWE;
649 xhci_writel(xhci, tmp, addr); 791 xhci_writel(xhci, tmp, addr);
650 } 792 }
651 } 793 }
652 hcd->state = HC_STATE_SUSPENDED; 794 hcd->state = HC_STATE_SUSPENDED;
653 xhci->next_statechange = jiffies + msecs_to_jiffies(10); 795 bus_state->next_statechange = jiffies + msecs_to_jiffies(10);
654 spin_unlock_irqrestore(&xhci->lock, flags); 796 spin_unlock_irqrestore(&xhci->lock, flags);
655 return 0; 797 return 0;
656} 798}
@@ -658,13 +800,24 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
658int xhci_bus_resume(struct usb_hcd *hcd) 800int xhci_bus_resume(struct usb_hcd *hcd)
659{ 801{
660 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 802 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
661 int port; 803 int max_ports, port_index;
804 u32 __iomem **port_array;
805 struct xhci_bus_state *bus_state;
662 u32 temp; 806 u32 temp;
663 unsigned long flags; 807 unsigned long flags;
664 808
665 xhci_dbg(xhci, "resume root hub\n"); 809 if (hcd->speed == HCD_USB3) {
810 max_ports = xhci->num_usb3_ports;
811 port_array = xhci->usb3_ports;
812 xhci_dbg(xhci, "resume USB 3.0 root hub\n");
813 } else {
814 max_ports = xhci->num_usb2_ports;
815 port_array = xhci->usb2_ports;
816 xhci_dbg(xhci, "resume USB 2.0 root hub\n");
817 }
818 bus_state = &xhci->bus_state[hcd_index(hcd)];
666 819
667 if (time_before(jiffies, xhci->next_statechange)) 820 if (time_before(jiffies, bus_state->next_statechange))
668 msleep(5); 821 msleep(5);
669 822
670 spin_lock_irqsave(&xhci->lock, flags); 823 spin_lock_irqsave(&xhci->lock, flags);
@@ -678,57 +831,57 @@ int xhci_bus_resume(struct usb_hcd *hcd)
678 temp &= ~CMD_EIE; 831 temp &= ~CMD_EIE;
679 xhci_writel(xhci, temp, &xhci->op_regs->command); 832 xhci_writel(xhci, temp, &xhci->op_regs->command);
680 833
681 port = HCS_MAX_PORTS(xhci->hcs_params1); 834 port_index = max_ports;
682 while (port--) { 835 while (port_index--) {
683 /* Check whether need resume ports. If needed 836 /* Check whether need resume ports. If needed
684 resume port and disable remote wakeup */ 837 resume port and disable remote wakeup */
685 u32 __iomem *addr;
686 u32 temp; 838 u32 temp;
687 int slot_id; 839 int slot_id;
688 840
689 addr = &xhci->op_regs->port_status_base + 841 temp = xhci_readl(xhci, port_array[port_index]);
690 NUM_PORT_REGS * (port & 0xff);
691 temp = xhci_readl(xhci, addr);
692 if (DEV_SUPERSPEED(temp)) 842 if (DEV_SUPERSPEED(temp))
693 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); 843 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
694 else 844 else
695 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); 845 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
696 if (test_bit(port, &xhci->bus_suspended) && 846 if (test_bit(port_index, &bus_state->bus_suspended) &&
697 (temp & PORT_PLS_MASK)) { 847 (temp & PORT_PLS_MASK)) {
698 if (DEV_SUPERSPEED(temp)) { 848 if (DEV_SUPERSPEED(temp)) {
699 temp = xhci_port_state_to_neutral(temp); 849 temp = xhci_port_state_to_neutral(temp);
700 temp &= ~PORT_PLS_MASK; 850 temp &= ~PORT_PLS_MASK;
701 temp |= PORT_LINK_STROBE | XDEV_U0; 851 temp |= PORT_LINK_STROBE | XDEV_U0;
702 xhci_writel(xhci, temp, addr); 852 xhci_writel(xhci, temp, port_array[port_index]);
703 } else { 853 } else {
704 temp = xhci_port_state_to_neutral(temp); 854 temp = xhci_port_state_to_neutral(temp);
705 temp &= ~PORT_PLS_MASK; 855 temp &= ~PORT_PLS_MASK;
706 temp |= PORT_LINK_STROBE | XDEV_RESUME; 856 temp |= PORT_LINK_STROBE | XDEV_RESUME;
707 xhci_writel(xhci, temp, addr); 857 xhci_writel(xhci, temp, port_array[port_index]);
708 858
709 spin_unlock_irqrestore(&xhci->lock, flags); 859 spin_unlock_irqrestore(&xhci->lock, flags);
710 msleep(20); 860 msleep(20);
711 spin_lock_irqsave(&xhci->lock, flags); 861 spin_lock_irqsave(&xhci->lock, flags);
712 862
713 temp = xhci_readl(xhci, addr); 863 temp = xhci_readl(xhci, port_array[port_index]);
714 temp = xhci_port_state_to_neutral(temp); 864 temp = xhci_port_state_to_neutral(temp);
715 temp &= ~PORT_PLS_MASK; 865 temp &= ~PORT_PLS_MASK;
716 temp |= PORT_LINK_STROBE | XDEV_U0; 866 temp |= PORT_LINK_STROBE | XDEV_U0;
717 xhci_writel(xhci, temp, addr); 867 xhci_writel(xhci, temp, port_array[port_index]);
718 } 868 }
719 slot_id = xhci_find_slot_id_by_port(xhci, port + 1); 869 slot_id = xhci_find_slot_id_by_port(hcd,
870 xhci, port_index + 1);
720 if (slot_id) 871 if (slot_id)
721 xhci_ring_device(xhci, slot_id); 872 xhci_ring_device(xhci, slot_id);
722 } else 873 } else
723 xhci_writel(xhci, temp, addr); 874 xhci_writel(xhci, temp, port_array[port_index]);
724 875
725 if (DEV_HIGHSPEED(temp)) { 876 if (DEV_HIGHSPEED(temp)) {
726 /* disable remote wake up for USB 2.0 */ 877 /* disable remote wake up for USB 2.0 */
727 u32 __iomem *addr; 878 u32 __iomem *addr;
728 u32 tmp; 879 u32 tmp;
729 880
730 addr = &xhci->op_regs->port_power_base + 881 /* Add one to the port status register address to get
731 NUM_PORT_REGS * (port & 0xff); 882 * the port power control register address.
883 */
884 addr = port_array[port_index] + 1;
732 tmp = xhci_readl(xhci, addr); 885 tmp = xhci_readl(xhci, addr);
733 tmp &= ~PORT_RWE; 886 tmp &= ~PORT_RWE;
734 xhci_writel(xhci, tmp, addr); 887 xhci_writel(xhci, tmp, addr);
@@ -737,8 +890,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
737 890
738 (void) xhci_readl(xhci, &xhci->op_regs->command); 891 (void) xhci_readl(xhci, &xhci->op_regs->command);
739 892
740 xhci->next_statechange = jiffies + msecs_to_jiffies(5); 893 bus_state->next_statechange = jiffies + msecs_to_jiffies(5);
741 hcd->state = HC_STATE_RUNNING;
742 /* re-enable irqs */ 894 /* re-enable irqs */
743 temp = xhci_readl(xhci, &xhci->op_regs->command); 895 temp = xhci_readl(xhci, &xhci->op_regs->command);
744 temp |= CMD_EIE; 896 temp |= CMD_EIE;
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index a9534396e85b..a003e79aacdc 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -814,14 +814,64 @@ void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci,
814 ep0_ctx->deq |= ep_ring->cycle_state; 814 ep0_ctx->deq |= ep_ring->cycle_state;
815} 815}
816 816
817/*
818 * The xHCI roothub may have ports of differing speeds in any order in the port
819 * status registers. xhci->port_array provides an array of the port speed for
820 * each offset into the port status registers.
821 *
822 * The xHCI hardware wants to know the roothub port number that the USB device
823 * is attached to (or the roothub port its ancestor hub is attached to). All we
824 * know is the index of that port under either the USB 2.0 or the USB 3.0
825 * roothub, but that doesn't give us the real index into the HW port status
826 * registers. Scan through the xHCI roothub port array, looking for the Nth
827 * entry of the correct port speed. Return the port number of that entry.
828 */
829static u32 xhci_find_real_port_number(struct xhci_hcd *xhci,
830 struct usb_device *udev)
831{
832 struct usb_device *top_dev;
833 unsigned int num_similar_speed_ports;
834 unsigned int faked_port_num;
835 int i;
836
837 for (top_dev = udev; top_dev->parent && top_dev->parent->parent;
838 top_dev = top_dev->parent)
839 /* Found device below root hub */;
840 faked_port_num = top_dev->portnum;
841 for (i = 0, num_similar_speed_ports = 0;
842 i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
843 u8 port_speed = xhci->port_array[i];
844
845 /*
846 * Skip ports that don't have known speeds, or have duplicate
847 * Extended Capabilities port speed entries.
848 */
849 if (port_speed == 0 || port_speed == -1)
850 continue;
851
852 /*
853 * USB 3.0 ports are always under a USB 3.0 hub. USB 2.0 and
854 * 1.1 ports are under the USB 2.0 hub. If the port speed
855 * matches the device speed, it's a similar speed port.
856 */
857 if ((port_speed == 0x03) == (udev->speed == USB_SPEED_SUPER))
858 num_similar_speed_ports++;
859 if (num_similar_speed_ports == faked_port_num)
860 /* Roothub ports are numbered from 1 to N */
861 return i+1;
862 }
863 return 0;
864}
865
817/* Setup an xHCI virtual device for a Set Address command */ 866/* Setup an xHCI virtual device for a Set Address command */
818int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev) 867int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev)
819{ 868{
820 struct xhci_virt_device *dev; 869 struct xhci_virt_device *dev;
821 struct xhci_ep_ctx *ep0_ctx; 870 struct xhci_ep_ctx *ep0_ctx;
822 struct usb_device *top_dev;
823 struct xhci_slot_ctx *slot_ctx; 871 struct xhci_slot_ctx *slot_ctx;
824 struct xhci_input_control_ctx *ctrl_ctx; 872 struct xhci_input_control_ctx *ctrl_ctx;
873 u32 port_num;
874 struct usb_device *top_dev;
825 875
826 dev = xhci->devs[udev->slot_id]; 876 dev = xhci->devs[udev->slot_id];
827 /* Slot ID 0 is reserved */ 877 /* Slot ID 0 is reserved */
@@ -863,16 +913,20 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
863 BUG(); 913 BUG();
864 } 914 }
865 /* Find the root hub port this device is under */ 915 /* Find the root hub port this device is under */
916 port_num = xhci_find_real_port_number(xhci, udev);
917 if (!port_num)
918 return -EINVAL;
919 slot_ctx->dev_info2 |= (u32) ROOT_HUB_PORT(port_num);
920 /* Set the port number in the virtual_device to the faked port number */
866 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; 921 for (top_dev = udev; top_dev->parent && top_dev->parent->parent;
867 top_dev = top_dev->parent) 922 top_dev = top_dev->parent)
868 /* Found device below root hub */; 923 /* Found device below root hub */;
869 slot_ctx->dev_info2 |= (u32) ROOT_HUB_PORT(top_dev->portnum);
870 dev->port = top_dev->portnum; 924 dev->port = top_dev->portnum;
871 xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); 925 xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num);
926 xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->port);
872 927
873 /* Is this a LS/FS device under a HS hub? */ 928 /* Is this a LS/FS device under an external HS hub? */
874 if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) && 929 if (udev->tt && udev->tt->hub->parent) {
875 udev->tt) {
876 slot_ctx->tt_info = udev->tt->hub->slot_id; 930 slot_ctx->tt_info = udev->tt->hub->slot_id;
877 slot_ctx->tt_info |= udev->ttport << 8; 931 slot_ctx->tt_info |= udev->ttport << 8;
878 if (udev->tt->multi) 932 if (udev->tt->multi)
@@ -1452,7 +1506,8 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1452 1506
1453 xhci->page_size = 0; 1507 xhci->page_size = 0;
1454 xhci->page_shift = 0; 1508 xhci->page_shift = 0;
1455 xhci->bus_suspended = 0; 1509 xhci->bus_state[0].bus_suspended = 0;
1510 xhci->bus_state[1].bus_suspended = 0;
1456} 1511}
1457 1512
1458static int xhci_test_trb_in_td(struct xhci_hcd *xhci, 1513static int xhci_test_trb_in_td(struct xhci_hcd *xhci,
@@ -1748,6 +1803,20 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
1748 } 1803 }
1749 xhci_dbg(xhci, "Found %u USB 2.0 ports and %u USB 3.0 ports.\n", 1804 xhci_dbg(xhci, "Found %u USB 2.0 ports and %u USB 3.0 ports.\n",
1750 xhci->num_usb2_ports, xhci->num_usb3_ports); 1805 xhci->num_usb2_ports, xhci->num_usb3_ports);
1806
1807 /* Place limits on the number of roothub ports so that the hub
1808 * descriptors aren't longer than the USB core will allocate.
1809 */
1810 if (xhci->num_usb3_ports > 15) {
1811 xhci_dbg(xhci, "Limiting USB 3.0 roothub ports to 15.\n");
1812 xhci->num_usb3_ports = 15;
1813 }
1814 if (xhci->num_usb2_ports > USB_MAXCHILDREN) {
1815 xhci_dbg(xhci, "Limiting USB 2.0 roothub ports to %u.\n",
1816 USB_MAXCHILDREN);
1817 xhci->num_usb2_ports = USB_MAXCHILDREN;
1818 }
1819
1751 /* 1820 /*
1752 * Note we could have all USB 3.0 ports, or all USB 2.0 ports. 1821 * Note we could have all USB 3.0 ports, or all USB 2.0 ports.
1753 * Not sure how the USB core will handle a hub with no ports... 1822 * Not sure how the USB core will handle a hub with no ports...
@@ -1772,6 +1841,8 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
1772 "addr = %p\n", i, 1841 "addr = %p\n", i,
1773 xhci->usb2_ports[port_index]); 1842 xhci->usb2_ports[port_index]);
1774 port_index++; 1843 port_index++;
1844 if (port_index == xhci->num_usb2_ports)
1845 break;
1775 } 1846 }
1776 } 1847 }
1777 if (xhci->num_usb3_ports) { 1848 if (xhci->num_usb3_ports) {
@@ -1790,6 +1861,8 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
1790 "addr = %p\n", i, 1861 "addr = %p\n", i,
1791 xhci->usb3_ports[port_index]); 1862 xhci->usb3_ports[port_index]);
1792 port_index++; 1863 port_index++;
1864 if (port_index == xhci->num_usb3_ports)
1865 break;
1793 } 1866 }
1794 } 1867 }
1795 return 0; 1868 return 0;
@@ -1971,8 +2044,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1971 init_completion(&xhci->addr_dev); 2044 init_completion(&xhci->addr_dev);
1972 for (i = 0; i < MAX_HC_SLOTS; ++i) 2045 for (i = 0; i < MAX_HC_SLOTS; ++i)
1973 xhci->devs[i] = NULL; 2046 xhci->devs[i] = NULL;
1974 for (i = 0; i < MAX_HC_PORTS; ++i) 2047 for (i = 0; i < USB_MAXCHILDREN; ++i) {
1975 xhci->resume_done[i] = 0; 2048 xhci->bus_state[0].resume_done[i] = 0;
2049 xhci->bus_state[1].resume_done[i] = 0;
2050 }
1976 2051
1977 if (scratchpad_alloc(xhci, flags)) 2052 if (scratchpad_alloc(xhci, flags))
1978 goto fail; 2053 goto fail;
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index bb668a894ab9..ceea9f33491c 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -50,13 +50,45 @@ static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
50/* called during probe() after chip reset completes */ 50/* called during probe() after chip reset completes */
51static int xhci_pci_setup(struct usb_hcd *hcd) 51static int xhci_pci_setup(struct usb_hcd *hcd)
52{ 52{
53 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 53 struct xhci_hcd *xhci;
54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
55 int retval; 55 int retval;
56 u32 temp; 56 u32 temp;
57 57
58 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; 58 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2;
59 59
60 if (usb_hcd_is_primary_hcd(hcd)) {
61 xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL);
62 if (!xhci)
63 return -ENOMEM;
64 *((struct xhci_hcd **) hcd->hcd_priv) = xhci;
65 xhci->main_hcd = hcd;
66 /* Mark the first roothub as being USB 2.0.
67 * The xHCI driver will register the USB 3.0 roothub.
68 */
69 hcd->speed = HCD_USB2;
70 hcd->self.root_hub->speed = USB_SPEED_HIGH;
71 /*
72 * USB 2.0 roothub under xHCI has an integrated TT,
73 * (rate matching hub) as opposed to having an OHCI/UHCI
74 * companion controller.
75 */
76 hcd->has_tt = 1;
77 } else {
78 /* xHCI private pointer was set in xhci_pci_probe for the second
79 * registered roothub.
80 */
81 xhci = hcd_to_xhci(hcd);
82 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
83 if (HCC_64BIT_ADDR(temp)) {
84 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
85 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64));
86 } else {
87 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32));
88 }
89 return 0;
90 }
91
60 xhci->cap_regs = hcd->regs; 92 xhci->cap_regs = hcd->regs;
61 xhci->op_regs = hcd->regs + 93 xhci->op_regs = hcd->regs +
62 HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); 94 HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase));
@@ -85,13 +117,13 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
85 /* Make sure the HC is halted. */ 117 /* Make sure the HC is halted. */
86 retval = xhci_halt(xhci); 118 retval = xhci_halt(xhci);
87 if (retval) 119 if (retval)
88 return retval; 120 goto error;
89 121
90 xhci_dbg(xhci, "Resetting HCD\n"); 122 xhci_dbg(xhci, "Resetting HCD\n");
91 /* Reset the internal HC memory state and registers. */ 123 /* Reset the internal HC memory state and registers. */
92 retval = xhci_reset(xhci); 124 retval = xhci_reset(xhci);
93 if (retval) 125 if (retval)
94 return retval; 126 goto error;
95 xhci_dbg(xhci, "Reset complete\n"); 127 xhci_dbg(xhci, "Reset complete\n");
96 128
97 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); 129 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
@@ -106,14 +138,85 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
106 /* Initialize HCD and host controller data structures. */ 138 /* Initialize HCD and host controller data structures. */
107 retval = xhci_init(hcd); 139 retval = xhci_init(hcd);
108 if (retval) 140 if (retval)
109 return retval; 141 goto error;
110 xhci_dbg(xhci, "Called HCD init\n"); 142 xhci_dbg(xhci, "Called HCD init\n");
111 143
112 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); 144 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn);
113 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); 145 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn);
114 146
115 /* Find any debug ports */ 147 /* Find any debug ports */
116 return xhci_pci_reinit(xhci, pdev); 148 retval = xhci_pci_reinit(xhci, pdev);
149 if (!retval)
150 return retval;
151
152error:
153 kfree(xhci);
154 return retval;
155}
156
157/*
158 * We need to register our own PCI probe function (instead of the USB core's
159 * function) in order to create a second roothub under xHCI.
160 */
161static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
162{
163 int retval;
164 struct xhci_hcd *xhci;
165 struct hc_driver *driver;
166 struct usb_hcd *hcd;
167
168 driver = (struct hc_driver *)id->driver_data;
169 /* Register the USB 2.0 roothub.
170 * FIXME: USB core must know to register the USB 2.0 roothub first.
171 * This is sort of silly, because we could just set the HCD driver flags
172 * to say USB 2.0, but I'm not sure what the implications would be in
173 * the other parts of the HCD code.
174 */
175 retval = usb_hcd_pci_probe(dev, id);
176
177 if (retval)
178 return retval;
179
180 /* USB 2.0 roothub is stored in the PCI device now. */
181 hcd = dev_get_drvdata(&dev->dev);
182 xhci = hcd_to_xhci(hcd);
183 xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev,
184 pci_name(dev), hcd);
185 if (!xhci->shared_hcd) {
186 retval = -ENOMEM;
187 goto dealloc_usb2_hcd;
188 }
189
190 /* Set the xHCI pointer before xhci_pci_setup() (aka hcd_driver.reset)
191 * is called by usb_add_hcd().
192 */
193 *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
194
195 retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
196 IRQF_DISABLED | IRQF_SHARED);
197 if (retval)
198 goto put_usb3_hcd;
199 /* Roothub already marked as USB 3.0 speed */
200 return 0;
201
202put_usb3_hcd:
203 usb_put_hcd(xhci->shared_hcd);
204dealloc_usb2_hcd:
205 usb_hcd_pci_remove(dev);
206 return retval;
207}
208
209static void xhci_pci_remove(struct pci_dev *dev)
210{
211 struct xhci_hcd *xhci;
212
213 xhci = hcd_to_xhci(pci_get_drvdata(dev));
214 if (xhci->shared_hcd) {
215 usb_remove_hcd(xhci->shared_hcd);
216 usb_put_hcd(xhci->shared_hcd);
217 }
218 usb_hcd_pci_remove(dev);
219 kfree(xhci);
117} 220}
118 221
119#ifdef CONFIG_PM 222#ifdef CONFIG_PM
@@ -122,7 +225,8 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
122 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 225 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
123 int retval = 0; 226 int retval = 0;
124 227
125 if (hcd->state != HC_STATE_SUSPENDED) 228 if (hcd->state != HC_STATE_SUSPENDED ||
229 xhci->shared_hcd->state != HC_STATE_SUSPENDED)
126 return -EINVAL; 230 return -EINVAL;
127 231
128 retval = xhci_suspend(xhci); 232 retval = xhci_suspend(xhci);
@@ -143,13 +247,13 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
143static const struct hc_driver xhci_pci_hc_driver = { 247static const struct hc_driver xhci_pci_hc_driver = {
144 .description = hcd_name, 248 .description = hcd_name,
145 .product_desc = "xHCI Host Controller", 249 .product_desc = "xHCI Host Controller",
146 .hcd_priv_size = sizeof(struct xhci_hcd), 250 .hcd_priv_size = sizeof(struct xhci_hcd *),
147 251
148 /* 252 /*
149 * generic hardware linkage 253 * generic hardware linkage
150 */ 254 */
151 .irq = xhci_irq, 255 .irq = xhci_irq,
152 .flags = HCD_MEMORY | HCD_USB3, 256 .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
153 257
154 /* 258 /*
155 * basic lifecycle operations 259 * basic lifecycle operations
@@ -210,8 +314,8 @@ static struct pci_driver xhci_pci_driver = {
210 .name = (char *) hcd_name, 314 .name = (char *) hcd_name,
211 .id_table = pci_ids, 315 .id_table = pci_ids,
212 316
213 .probe = usb_hcd_pci_probe, 317 .probe = xhci_pci_probe,
214 .remove = usb_hcd_pci_remove, 318 .remove = xhci_pci_remove,
215 /* suspend and resume implemented later */ 319 /* suspend and resume implemented later */
216 320
217 .shutdown = usb_hcd_pci_shutdown, 321 .shutdown = usb_hcd_pci_shutdown,
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 3289bf4832c9..cfc1ad92473f 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -380,10 +380,8 @@ static struct xhci_segment *find_trb_seg(
380 while (cur_seg->trbs > trb || 380 while (cur_seg->trbs > trb ||
381 &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) { 381 &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) {
382 generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic; 382 generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic;
383 if ((generic_trb->field[3] & TRB_TYPE_BITMASK) == 383 if (generic_trb->field[3] & LINK_TOGGLE)
384 TRB_TYPE(TRB_LINK) && 384 *cycle_state ^= 0x1;
385 (generic_trb->field[3] & LINK_TOGGLE))
386 *cycle_state = ~(*cycle_state) & 0x1;
387 cur_seg = cur_seg->next; 385 cur_seg = cur_seg->next;
388 if (cur_seg == start_seg) 386 if (cur_seg == start_seg)
389 /* Looped over the entire list. Oops! */ 387 /* Looped over the entire list. Oops! */
@@ -497,18 +495,29 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
497 trb = &state->new_deq_ptr->generic; 495 trb = &state->new_deq_ptr->generic;
498 if ((trb->field[3] & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK) && 496 if ((trb->field[3] & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK) &&
499 (trb->field[3] & LINK_TOGGLE)) 497 (trb->field[3] & LINK_TOGGLE))
500 state->new_cycle_state = ~(state->new_cycle_state) & 0x1; 498 state->new_cycle_state ^= 0x1;
501 next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr); 499 next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr);
502 500
501 /*
502 * If there is only one segment in a ring, find_trb_seg()'s while loop
503 * will not run, and it will return before it has a chance to see if it
504 * needs to toggle the cycle bit. It can't tell if the stalled transfer
505 * ended just before the link TRB on a one-segment ring, or if the TD
506 * wrapped around the top of the ring, because it doesn't have the TD in
507 * question. Look for the one-segment case where stalled TRB's address
508 * is greater than the new dequeue pointer address.
509 */
510 if (ep_ring->first_seg == ep_ring->first_seg->next &&
511 state->new_deq_ptr < dev->eps[ep_index].stopped_trb)
512 state->new_cycle_state ^= 0x1;
513 xhci_dbg(xhci, "Cycle state = 0x%x\n", state->new_cycle_state);
514
503 /* Don't update the ring cycle state for the producer (us). */ 515 /* Don't update the ring cycle state for the producer (us). */
504 xhci_dbg(xhci, "New dequeue segment = %p (virtual)\n", 516 xhci_dbg(xhci, "New dequeue segment = %p (virtual)\n",
505 state->new_deq_seg); 517 state->new_deq_seg);
506 addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr); 518 addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr);
507 xhci_dbg(xhci, "New dequeue pointer = 0x%llx (DMA)\n", 519 xhci_dbg(xhci, "New dequeue pointer = 0x%llx (DMA)\n",
508 (unsigned long long) addr); 520 (unsigned long long) addr);
509 xhci_dbg(xhci, "Setting dequeue pointer in internal ring state.\n");
510 ep_ring->dequeue = state->new_deq_ptr;
511 ep_ring->deq_seg = state->new_deq_seg;
512} 521}
513 522
514static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, 523static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
@@ -599,13 +608,14 @@ static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
599static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, 608static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
600 struct xhci_td *cur_td, int status, char *adjective) 609 struct xhci_td *cur_td, int status, char *adjective)
601{ 610{
602 struct usb_hcd *hcd = xhci_to_hcd(xhci); 611 struct usb_hcd *hcd;
603 struct urb *urb; 612 struct urb *urb;
604 struct urb_priv *urb_priv; 613 struct urb_priv *urb_priv;
605 614
606 urb = cur_td->urb; 615 urb = cur_td->urb;
607 urb_priv = urb->hcpriv; 616 urb_priv = urb->hcpriv;
608 urb_priv->td_cnt++; 617 urb_priv->td_cnt++;
618 hcd = bus_to_hcd(urb->dev->bus);
609 619
610 /* Only giveback urb when this is the last td in urb */ 620 /* Only giveback urb when this is the last td in urb */
611 if (urb_priv->td_cnt == urb_priv->length) { 621 if (urb_priv->td_cnt == urb_priv->length) {
@@ -824,8 +834,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
824 if (ret < 0) { 834 if (ret < 0) {
825 /* This is bad; the host is not responding to commands and it's 835 /* This is bad; the host is not responding to commands and it's
826 * not allowing itself to be halted. At least interrupts are 836 * not allowing itself to be halted. At least interrupts are
827 * disabled, so we can set HC_STATE_HALT and notify the 837 * disabled. If we call usb_hc_died(), it will attempt to
828 * USB core. But if we call usb_hc_died(), it will attempt to
829 * disconnect all device drivers under this host. Those 838 * disconnect all device drivers under this host. Those
830 * disconnect() methods will wait for all URBs to be unlinked, 839 * disconnect() methods will wait for all URBs to be unlinked,
831 * so we must complete them. 840 * so we must complete them.
@@ -870,9 +879,8 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
870 } 879 }
871 } 880 }
872 spin_unlock(&xhci->lock); 881 spin_unlock(&xhci->lock);
873 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
874 xhci_dbg(xhci, "Calling usb_hc_died()\n"); 882 xhci_dbg(xhci, "Calling usb_hc_died()\n");
875 usb_hc_died(xhci_to_hcd(xhci)); 883 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd);
876 xhci_dbg(xhci, "xHCI host controller is dead.\n"); 884 xhci_dbg(xhci, "xHCI host controller is dead.\n");
877} 885}
878 886
@@ -951,9 +959,26 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
951 } else { 959 } else {
952 xhci_dbg(xhci, "Successful Set TR Deq Ptr cmd, deq = @%08llx\n", 960 xhci_dbg(xhci, "Successful Set TR Deq Ptr cmd, deq = @%08llx\n",
953 ep_ctx->deq); 961 ep_ctx->deq);
962 if (xhci_trb_virt_to_dma(dev->eps[ep_index].queued_deq_seg,
963 dev->eps[ep_index].queued_deq_ptr) ==
964 (ep_ctx->deq & ~(EP_CTX_CYCLE_MASK))) {
965 /* Update the ring's dequeue segment and dequeue pointer
966 * to reflect the new position.
967 */
968 ep_ring->deq_seg = dev->eps[ep_index].queued_deq_seg;
969 ep_ring->dequeue = dev->eps[ep_index].queued_deq_ptr;
970 } else {
971 xhci_warn(xhci, "Mismatch between completed Set TR Deq "
972 "Ptr command & xHCI internal state.\n");
973 xhci_warn(xhci, "ep deq seg = %p, deq ptr = %p\n",
974 dev->eps[ep_index].queued_deq_seg,
975 dev->eps[ep_index].queued_deq_ptr);
976 }
954 } 977 }
955 978
956 dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING; 979 dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING;
980 dev->eps[ep_index].queued_deq_seg = NULL;
981 dev->eps[ep_index].queued_deq_ptr = NULL;
957 /* Restart any rings with pending URBs */ 982 /* Restart any rings with pending URBs */
958 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); 983 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
959} 984}
@@ -1118,7 +1143,6 @@ bandwidth_change:
1118 handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue); 1143 handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue);
1119 break; 1144 break;
1120 case TRB_TYPE(TRB_CMD_NOOP): 1145 case TRB_TYPE(TRB_CMD_NOOP):
1121 ++xhci->noops_handled;
1122 break; 1146 break;
1123 case TRB_TYPE(TRB_RESET_EP): 1147 case TRB_TYPE(TRB_RESET_EP):
1124 handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); 1148 handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue);
@@ -1162,15 +1186,55 @@ static void handle_vendor_event(struct xhci_hcd *xhci,
1162 handle_cmd_completion(xhci, &event->event_cmd); 1186 handle_cmd_completion(xhci, &event->event_cmd);
1163} 1187}
1164 1188
1189/* @port_id: the one-based port ID from the hardware (indexed from array of all
1190 * port registers -- USB 3.0 and USB 2.0).
1191 *
1192 * Returns a zero-based port number, which is suitable for indexing into each of
1193 * the split roothubs' port arrays and bus state arrays.
1194 */
1195static unsigned int find_faked_portnum_from_hw_portnum(struct usb_hcd *hcd,
1196 struct xhci_hcd *xhci, u32 port_id)
1197{
1198 unsigned int i;
1199 unsigned int num_similar_speed_ports = 0;
1200
1201 /* port_id from the hardware is 1-based, but port_array[], usb3_ports[],
1202 * and usb2_ports are 0-based indexes. Count the number of similar
1203 * speed ports, up to 1 port before this port.
1204 */
1205 for (i = 0; i < (port_id - 1); i++) {
1206 u8 port_speed = xhci->port_array[i];
1207
1208 /*
1209 * Skip ports that don't have known speeds, or have duplicate
1210 * Extended Capabilities port speed entries.
1211 */
1212 if (port_speed == 0 || port_speed == -1)
1213 continue;
1214
1215 /*
1216 * USB 3.0 ports are always under a USB 3.0 hub. USB 2.0 and
1217 * 1.1 ports are under the USB 2.0 hub. If the port speed
1218 * matches the device speed, it's a similar speed port.
1219 */
1220 if ((port_speed == 0x03) == (hcd->speed == HCD_USB3))
1221 num_similar_speed_ports++;
1222 }
1223 return num_similar_speed_ports;
1224}
1225
1165static void handle_port_status(struct xhci_hcd *xhci, 1226static void handle_port_status(struct xhci_hcd *xhci,
1166 union xhci_trb *event) 1227 union xhci_trb *event)
1167{ 1228{
1168 struct usb_hcd *hcd = xhci_to_hcd(xhci); 1229 struct usb_hcd *hcd;
1169 u32 port_id; 1230 u32 port_id;
1170 u32 temp, temp1; 1231 u32 temp, temp1;
1171 u32 __iomem *addr; 1232 int max_ports;
1172 int ports;
1173 int slot_id; 1233 int slot_id;
1234 unsigned int faked_port_index;
1235 u8 major_revision;
1236 struct xhci_bus_state *bus_state;
1237 u32 __iomem **port_array;
1174 1238
1175 /* Port status change events always have a successful completion code */ 1239 /* Port status change events always have a successful completion code */
1176 if (GET_COMP_CODE(event->generic.field[2]) != COMP_SUCCESS) { 1240 if (GET_COMP_CODE(event->generic.field[2]) != COMP_SUCCESS) {
@@ -1180,14 +1244,50 @@ static void handle_port_status(struct xhci_hcd *xhci,
1180 port_id = GET_PORT_ID(event->generic.field[0]); 1244 port_id = GET_PORT_ID(event->generic.field[0]);
1181 xhci_dbg(xhci, "Port Status Change Event for port %d\n", port_id); 1245 xhci_dbg(xhci, "Port Status Change Event for port %d\n", port_id);
1182 1246
1183 ports = HCS_MAX_PORTS(xhci->hcs_params1); 1247 max_ports = HCS_MAX_PORTS(xhci->hcs_params1);
1184 if ((port_id <= 0) || (port_id > ports)) { 1248 if ((port_id <= 0) || (port_id > max_ports)) {
1185 xhci_warn(xhci, "Invalid port id %d\n", port_id); 1249 xhci_warn(xhci, "Invalid port id %d\n", port_id);
1186 goto cleanup; 1250 goto cleanup;
1187 } 1251 }
1188 1252
1189 addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS * (port_id - 1); 1253 /* Figure out which usb_hcd this port is attached to:
1190 temp = xhci_readl(xhci, addr); 1254 * is it a USB 3.0 port or a USB 2.0/1.1 port?
1255 */
1256 major_revision = xhci->port_array[port_id - 1];
1257 if (major_revision == 0) {
1258 xhci_warn(xhci, "Event for port %u not in "
1259 "Extended Capabilities, ignoring.\n",
1260 port_id);
1261 goto cleanup;
1262 }
1263 if (major_revision == (u8) -1) {
1264 xhci_warn(xhci, "Event for port %u duplicated in"
1265 "Extended Capabilities, ignoring.\n",
1266 port_id);
1267 goto cleanup;
1268 }
1269
1270 /*
1271 * Hardware port IDs reported by a Port Status Change Event include USB
1272 * 3.0 and USB 2.0 ports. We want to check if the port has reported a
1273 * resume event, but we first need to translate the hardware port ID
1274 * into the index into the ports on the correct split roothub, and the
1275 * correct bus_state structure.
1276 */
1277 /* Find the right roothub. */
1278 hcd = xhci_to_hcd(xhci);
1279 if ((major_revision == 0x03) != (hcd->speed == HCD_USB3))
1280 hcd = xhci->shared_hcd;
1281 bus_state = &xhci->bus_state[hcd_index(hcd)];
1282 if (hcd->speed == HCD_USB3)
1283 port_array = xhci->usb3_ports;
1284 else
1285 port_array = xhci->usb2_ports;
1286 /* Find the faked port hub number */
1287 faked_port_index = find_faked_portnum_from_hw_portnum(hcd, xhci,
1288 port_id);
1289
1290 temp = xhci_readl(xhci, port_array[faked_port_index]);
1191 if (hcd->state == HC_STATE_SUSPENDED) { 1291 if (hcd->state == HC_STATE_SUSPENDED) {
1192 xhci_dbg(xhci, "resume root hub\n"); 1292 xhci_dbg(xhci, "resume root hub\n");
1193 usb_hcd_resume_root_hub(hcd); 1293 usb_hcd_resume_root_hub(hcd);
@@ -1207,8 +1307,9 @@ static void handle_port_status(struct xhci_hcd *xhci,
1207 temp = xhci_port_state_to_neutral(temp); 1307 temp = xhci_port_state_to_neutral(temp);
1208 temp &= ~PORT_PLS_MASK; 1308 temp &= ~PORT_PLS_MASK;
1209 temp |= PORT_LINK_STROBE | XDEV_U0; 1309 temp |= PORT_LINK_STROBE | XDEV_U0;
1210 xhci_writel(xhci, temp, addr); 1310 xhci_writel(xhci, temp, port_array[faked_port_index]);
1211 slot_id = xhci_find_slot_id_by_port(xhci, port_id); 1311 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
1312 faked_port_index);
1212 if (!slot_id) { 1313 if (!slot_id) {
1213 xhci_dbg(xhci, "slot_id is zero\n"); 1314 xhci_dbg(xhci, "slot_id is zero\n");
1214 goto cleanup; 1315 goto cleanup;
@@ -1216,16 +1317,16 @@ static void handle_port_status(struct xhci_hcd *xhci,
1216 xhci_ring_device(xhci, slot_id); 1317 xhci_ring_device(xhci, slot_id);
1217 xhci_dbg(xhci, "resume SS port %d finished\n", port_id); 1318 xhci_dbg(xhci, "resume SS port %d finished\n", port_id);
1218 /* Clear PORT_PLC */ 1319 /* Clear PORT_PLC */
1219 temp = xhci_readl(xhci, addr); 1320 temp = xhci_readl(xhci, port_array[faked_port_index]);
1220 temp = xhci_port_state_to_neutral(temp); 1321 temp = xhci_port_state_to_neutral(temp);
1221 temp |= PORT_PLC; 1322 temp |= PORT_PLC;
1222 xhci_writel(xhci, temp, addr); 1323 xhci_writel(xhci, temp, port_array[faked_port_index]);
1223 } else { 1324 } else {
1224 xhci_dbg(xhci, "resume HS port %d\n", port_id); 1325 xhci_dbg(xhci, "resume HS port %d\n", port_id);
1225 xhci->resume_done[port_id - 1] = jiffies + 1326 bus_state->resume_done[faked_port_index] = jiffies +
1226 msecs_to_jiffies(20); 1327 msecs_to_jiffies(20);
1227 mod_timer(&hcd->rh_timer, 1328 mod_timer(&hcd->rh_timer,
1228 xhci->resume_done[port_id - 1]); 1329 bus_state->resume_done[faked_port_index]);
1229 /* Do the rest in GetPortStatus */ 1330 /* Do the rest in GetPortStatus */
1230 } 1331 }
1231 } 1332 }
@@ -1236,7 +1337,7 @@ cleanup:
1236 1337
1237 spin_unlock(&xhci->lock); 1338 spin_unlock(&xhci->lock);
1238 /* Pass this up to the core */ 1339 /* Pass this up to the core */
1239 usb_hcd_poll_rh_status(xhci_to_hcd(xhci)); 1340 usb_hcd_poll_rh_status(hcd);
1240 spin_lock(&xhci->lock); 1341 spin_lock(&xhci->lock);
1241} 1342}
1242 1343
@@ -1990,12 +2091,12 @@ cleanup:
1990 trb_comp_code != COMP_BABBLE)) 2091 trb_comp_code != COMP_BABBLE))
1991 xhci_urb_free_priv(xhci, urb_priv); 2092 xhci_urb_free_priv(xhci, urb_priv);
1992 2093
1993 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); 2094 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb);
1994 xhci_dbg(xhci, "Giveback URB %p, len = %d, " 2095 xhci_dbg(xhci, "Giveback URB %p, len = %d, "
1995 "status = %d\n", 2096 "status = %d\n",
1996 urb, urb->actual_length, status); 2097 urb, urb->actual_length, status);
1997 spin_unlock(&xhci->lock); 2098 spin_unlock(&xhci->lock);
1998 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); 2099 usb_hcd_giveback_urb(bus_to_hcd(urb->dev->bus), urb, status);
1999 spin_lock(&xhci->lock); 2100 spin_lock(&xhci->lock);
2000 } 2101 }
2001 2102
@@ -2119,7 +2220,6 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
2119 xhci_warn(xhci, "WARNING: Host System Error\n"); 2220 xhci_warn(xhci, "WARNING: Host System Error\n");
2120 xhci_halt(xhci); 2221 xhci_halt(xhci);
2121hw_died: 2222hw_died:
2122 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
2123 spin_unlock(&xhci->lock); 2223 spin_unlock(&xhci->lock);
2124 return -ESHUTDOWN; 2224 return -ESHUTDOWN;
2125 } 2225 }
@@ -2187,8 +2287,12 @@ hw_died:
2187irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd) 2287irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd)
2188{ 2288{
2189 irqreturn_t ret; 2289 irqreturn_t ret;
2290 struct xhci_hcd *xhci;
2190 2291
2292 xhci = hcd_to_xhci(hcd);
2191 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 2293 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
2294 if (xhci->shared_hcd)
2295 set_bit(HCD_FLAG_SAW_IRQ, &xhci->shared_hcd->flags);
2192 2296
2193 ret = xhci_irq(hcd); 2297 ret = xhci_irq(hcd);
2194 2298
@@ -2332,7 +2436,7 @@ static int prepare_transfer(struct xhci_hcd *xhci,
2332 INIT_LIST_HEAD(&td->cancelled_td_list); 2436 INIT_LIST_HEAD(&td->cancelled_td_list);
2333 2437
2334 if (td_index == 0) { 2438 if (td_index == 0) {
2335 ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb); 2439 ret = usb_hcd_link_urb_to_ep(bus_to_hcd(urb->dev->bus), urb);
2336 if (unlikely(ret)) { 2440 if (unlikely(ret)) {
2337 xhci_urb_free_priv(xhci, urb_priv); 2441 xhci_urb_free_priv(xhci, urb_priv);
2338 urb->hcpriv = NULL; 2442 urb->hcpriv = NULL;
@@ -3131,24 +3235,6 @@ static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2,
3131 return 0; 3235 return 0;
3132} 3236}
3133 3237
3134/* Queue a no-op command on the command ring */
3135static int queue_cmd_noop(struct xhci_hcd *xhci)
3136{
3137 return queue_command(xhci, 0, 0, 0, TRB_TYPE(TRB_CMD_NOOP), false);
3138}
3139
3140/*
3141 * Place a no-op command on the command ring to test the command and
3142 * event ring.
3143 */
3144void *xhci_setup_one_noop(struct xhci_hcd *xhci)
3145{
3146 if (queue_cmd_noop(xhci) < 0)
3147 return NULL;
3148 xhci->noops_submitted++;
3149 return xhci_ring_cmd_db;
3150}
3151
3152/* Queue a slot enable or disable request on the command ring */ 3238/* Queue a slot enable or disable request on the command ring */
3153int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) 3239int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id)
3154{ 3240{
@@ -3229,6 +3315,7 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
3229 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); 3315 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
3230 u32 trb_stream_id = STREAM_ID_FOR_TRB(stream_id); 3316 u32 trb_stream_id = STREAM_ID_FOR_TRB(stream_id);
3231 u32 type = TRB_TYPE(TRB_SET_DEQ); 3317 u32 type = TRB_TYPE(TRB_SET_DEQ);
3318 struct xhci_virt_ep *ep;
3232 3319
3233 addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr); 3320 addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr);
3234 if (addr == 0) { 3321 if (addr == 0) {
@@ -3237,6 +3324,14 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
3237 deq_seg, deq_ptr); 3324 deq_seg, deq_ptr);
3238 return 0; 3325 return 0;
3239 } 3326 }
3327 ep = &xhci->devs[slot_id]->eps[ep_index];
3328 if ((ep->ep_state & SET_DEQ_PENDING)) {
3329 xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n");
3330 xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n");
3331 return 0;
3332 }
3333 ep->queued_deq_seg = deq_seg;
3334 ep->queued_deq_ptr = deq_ptr;
3240 return queue_command(xhci, lower_32_bits(addr) | cycle_state, 3335 return queue_command(xhci, lower_32_bits(addr) | cycle_state,
3241 upper_32_bits(addr), trb_stream_id, 3336 upper_32_bits(addr), trb_stream_id,
3242 trb_slot_id | trb_ep_index | type, false); 3337 trb_slot_id | trb_ep_index | type, false);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 2083fc2179b2..9a3645fd759b 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -93,17 +93,20 @@ void xhci_quiesce(struct xhci_hcd *xhci)
93 * 93 *
94 * Disable any IRQs and clear the run/stop bit. 94 * Disable any IRQs and clear the run/stop bit.
95 * HC will complete any current and actively pipelined transactions, and 95 * HC will complete any current and actively pipelined transactions, and
96 * should halt within 16 microframes of the run/stop bit being cleared. 96 * should halt within 16 ms of the run/stop bit being cleared.
97 * Read HC Halted bit in the status register to see when the HC is finished. 97 * Read HC Halted bit in the status register to see when the HC is finished.
98 * XXX: shouldn't we set HC_STATE_HALT here somewhere?
99 */ 98 */
100int xhci_halt(struct xhci_hcd *xhci) 99int xhci_halt(struct xhci_hcd *xhci)
101{ 100{
101 int ret;
102 xhci_dbg(xhci, "// Halt the HC\n"); 102 xhci_dbg(xhci, "// Halt the HC\n");
103 xhci_quiesce(xhci); 103 xhci_quiesce(xhci);
104 104
105 return handshake(xhci, &xhci->op_regs->status, 105 ret = handshake(xhci, &xhci->op_regs->status,
106 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); 106 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC);
107 if (!ret)
108 xhci->xhc_state |= XHCI_STATE_HALTED;
109 return ret;
107} 110}
108 111
109/* 112/*
@@ -130,11 +133,13 @@ static int xhci_start(struct xhci_hcd *xhci)
130 xhci_err(xhci, "Host took too long to start, " 133 xhci_err(xhci, "Host took too long to start, "
131 "waited %u microseconds.\n", 134 "waited %u microseconds.\n",
132 XHCI_MAX_HALT_USEC); 135 XHCI_MAX_HALT_USEC);
136 if (!ret)
137 xhci->xhc_state &= ~XHCI_STATE_HALTED;
133 return ret; 138 return ret;
134} 139}
135 140
136/* 141/*
137 * Reset a halted HC, and set the internal HC state to HC_STATE_HALT. 142 * Reset a halted HC.
138 * 143 *
139 * This resets pipelines, timers, counters, state machines, etc. 144 * This resets pipelines, timers, counters, state machines, etc.
140 * Transactions will be terminated immediately, and operational registers 145 * Transactions will be terminated immediately, and operational registers
@@ -156,8 +161,6 @@ int xhci_reset(struct xhci_hcd *xhci)
156 command = xhci_readl(xhci, &xhci->op_regs->command); 161 command = xhci_readl(xhci, &xhci->op_regs->command);
157 command |= CMD_RESET; 162 command |= CMD_RESET;
158 xhci_writel(xhci, command, &xhci->op_regs->command); 163 xhci_writel(xhci, command, &xhci->op_regs->command);
159 /* XXX: Why does EHCI set this here? Shouldn't other code do this? */
160 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
161 164
162 ret = handshake(xhci, &xhci->op_regs->command, 165 ret = handshake(xhci, &xhci->op_regs->command,
163 CMD_RESET, 0, 250 * 1000); 166 CMD_RESET, 0, 250 * 1000);
@@ -350,7 +353,6 @@ static void xhci_event_ring_work(unsigned long arg)
350 353
351 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); 354 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
352 xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp); 355 xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp);
353 xhci_dbg(xhci, "No-op commands handled = %d\n", xhci->noops_handled);
354 xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask); 356 xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask);
355 xhci->error_bitmask = 0; 357 xhci->error_bitmask = 0;
356 xhci_dbg(xhci, "Event ring:\n"); 358 xhci_dbg(xhci, "Event ring:\n");
@@ -370,10 +372,6 @@ static void xhci_event_ring_work(unsigned long arg)
370 xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]); 372 xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]);
371 } 373 }
372 } 374 }
373
374 if (xhci->noops_submitted != NUM_TEST_NOOPS)
375 if (xhci_setup_one_noop(xhci))
376 xhci_ring_cmd_db(xhci);
377 spin_unlock_irqrestore(&xhci->lock, flags); 375 spin_unlock_irqrestore(&xhci->lock, flags);
378 376
379 if (!xhci->zombie) 377 if (!xhci->zombie)
@@ -383,6 +381,21 @@ static void xhci_event_ring_work(unsigned long arg)
383} 381}
384#endif 382#endif
385 383
384static int xhci_run_finished(struct xhci_hcd *xhci)
385{
386 if (xhci_start(xhci)) {
387 xhci_halt(xhci);
388 return -ENODEV;
389 }
390 xhci->shared_hcd->state = HC_STATE_RUNNING;
391
392 if (xhci->quirks & XHCI_NEC_HOST)
393 xhci_ring_cmd_db(xhci);
394
395 xhci_dbg(xhci, "Finished xhci_run for USB3 roothub\n");
396 return 0;
397}
398
386/* 399/*
387 * Start the HC after it was halted. 400 * Start the HC after it was halted.
388 * 401 *
@@ -402,9 +415,14 @@ int xhci_run(struct usb_hcd *hcd)
402 u32 ret; 415 u32 ret;
403 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 416 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
404 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 417 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
405 void (*doorbell)(struct xhci_hcd *) = NULL; 418
419 /* Start the xHCI host controller running only after the USB 2.0 roothub
420 * is setup.
421 */
406 422
407 hcd->uses_new_polling = 1; 423 hcd->uses_new_polling = 1;
424 if (!usb_hcd_is_primary_hcd(hcd))
425 return xhci_run_finished(xhci);
408 426
409 xhci_dbg(xhci, "xhci_run\n"); 427 xhci_dbg(xhci, "xhci_run\n");
410 /* unregister the legacy interrupt */ 428 /* unregister the legacy interrupt */
@@ -461,7 +479,6 @@ int xhci_run(struct usb_hcd *hcd)
461 xhci_writel(xhci, temp, &xhci->ir_set->irq_control); 479 xhci_writel(xhci, temp, &xhci->ir_set->irq_control);
462 480
463 /* Set the HCD state before we enable the irqs */ 481 /* Set the HCD state before we enable the irqs */
464 hcd->state = HC_STATE_RUNNING;
465 temp = xhci_readl(xhci, &xhci->op_regs->command); 482 temp = xhci_readl(xhci, &xhci->op_regs->command);
466 temp |= (CMD_EIE); 483 temp |= (CMD_EIE);
467 xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n", 484 xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n",
@@ -475,24 +492,27 @@ int xhci_run(struct usb_hcd *hcd)
475 &xhci->ir_set->irq_pending); 492 &xhci->ir_set->irq_pending);
476 xhci_print_ir_set(xhci, 0); 493 xhci_print_ir_set(xhci, 0);
477 494
478 if (NUM_TEST_NOOPS > 0)
479 doorbell = xhci_setup_one_noop(xhci);
480 if (xhci->quirks & XHCI_NEC_HOST) 495 if (xhci->quirks & XHCI_NEC_HOST)
481 xhci_queue_vendor_command(xhci, 0, 0, 0, 496 xhci_queue_vendor_command(xhci, 0, 0, 0,
482 TRB_TYPE(TRB_NEC_GET_FW)); 497 TRB_TYPE(TRB_NEC_GET_FW));
483 498
484 if (xhci_start(xhci)) { 499 xhci_dbg(xhci, "Finished xhci_run for USB2 roothub\n");
485 xhci_halt(xhci); 500 return 0;
486 return -ENODEV; 501}
487 }
488 502
489 if (doorbell) 503static void xhci_only_stop_hcd(struct usb_hcd *hcd)
490 (*doorbell)(xhci); 504{
491 if (xhci->quirks & XHCI_NEC_HOST) 505 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
492 xhci_ring_cmd_db(xhci);
493 506
494 xhci_dbg(xhci, "Finished xhci_run\n"); 507 spin_lock_irq(&xhci->lock);
495 return 0; 508 xhci_halt(xhci);
509
510 /* The shared_hcd is going to be deallocated shortly (the USB core only
511 * calls this function when allocation fails in usb_add_hcd(), or
512 * usb_remove_hcd() is called). So we need to unset xHCI's pointer.
513 */
514 xhci->shared_hcd = NULL;
515 spin_unlock_irq(&xhci->lock);
496} 516}
497 517
498/* 518/*
@@ -509,7 +529,15 @@ void xhci_stop(struct usb_hcd *hcd)
509 u32 temp; 529 u32 temp;
510 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 530 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
511 531
532 if (!usb_hcd_is_primary_hcd(hcd)) {
533 xhci_only_stop_hcd(xhci->shared_hcd);
534 return;
535 }
536
512 spin_lock_irq(&xhci->lock); 537 spin_lock_irq(&xhci->lock);
538 /* Make sure the xHC is halted for a USB3 roothub
539 * (xhci_stop() could be called as part of failed init).
540 */
513 xhci_halt(xhci); 541 xhci_halt(xhci);
514 xhci_reset(xhci); 542 xhci_reset(xhci);
515 spin_unlock_irq(&xhci->lock); 543 spin_unlock_irq(&xhci->lock);
@@ -542,6 +570,8 @@ void xhci_stop(struct usb_hcd *hcd)
542 * This is called when the machine is rebooting or halting. We assume that the 570 * This is called when the machine is rebooting or halting. We assume that the
543 * machine will be powered off, and the HC's internal state will be reset. 571 * machine will be powered off, and the HC's internal state will be reset.
544 * Don't bother to free memory. 572 * Don't bother to free memory.
573 *
574 * This will only ever be called with the main usb_hcd (the USB3 roothub).
545 */ 575 */
546void xhci_shutdown(struct usb_hcd *hcd) 576void xhci_shutdown(struct usb_hcd *hcd)
547{ 577{
@@ -657,6 +687,7 @@ int xhci_suspend(struct xhci_hcd *xhci)
657 687
658 spin_lock_irq(&xhci->lock); 688 spin_lock_irq(&xhci->lock);
659 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 689 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
690 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
660 /* step 1: stop endpoint */ 691 /* step 1: stop endpoint */
661 /* skipped assuming that port suspend has done */ 692 /* skipped assuming that port suspend has done */
662 693
@@ -706,10 +737,15 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
706{ 737{
707 u32 command, temp = 0; 738 u32 command, temp = 0;
708 struct usb_hcd *hcd = xhci_to_hcd(xhci); 739 struct usb_hcd *hcd = xhci_to_hcd(xhci);
709 int old_state, retval; 740 struct usb_hcd *secondary_hcd;
741 int retval;
710 742
711 old_state = hcd->state; 743 /* Wait a bit if either of the roothubs need to settle from the
712 if (time_before(jiffies, xhci->next_statechange)) 744 * transistion into bus suspend.
745 */
746 if (time_before(jiffies, xhci->bus_state[0].next_statechange) ||
747 time_before(jiffies,
748 xhci->bus_state[1].next_statechange))
713 msleep(100); 749 msleep(100);
714 750
715 spin_lock_irq(&xhci->lock); 751 spin_lock_irq(&xhci->lock);
@@ -762,16 +798,34 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
762 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", 798 xhci_dbg(xhci, "xhci_stop completed - status = %x\n",
763 xhci_readl(xhci, &xhci->op_regs->status)); 799 xhci_readl(xhci, &xhci->op_regs->status));
764 800
765 xhci_dbg(xhci, "Initialize the HCD\n"); 801 /* USB core calls the PCI reinit and start functions twice:
766 retval = xhci_init(hcd); 802 * first with the primary HCD, and then with the secondary HCD.
803 * If we don't do the same, the host will never be started.
804 */
805 if (!usb_hcd_is_primary_hcd(hcd))
806 secondary_hcd = hcd;
807 else
808 secondary_hcd = xhci->shared_hcd;
809
810 xhci_dbg(xhci, "Initialize the xhci_hcd\n");
811 retval = xhci_init(hcd->primary_hcd);
767 if (retval) 812 if (retval)
768 return retval; 813 return retval;
814 xhci_dbg(xhci, "Start the primary HCD\n");
815 retval = xhci_run(hcd->primary_hcd);
816 if (retval)
817 goto failed_restart;
769 818
770 xhci_dbg(xhci, "Start the HCD\n"); 819 xhci_dbg(xhci, "Start the secondary HCD\n");
771 retval = xhci_run(hcd); 820 retval = xhci_run(secondary_hcd);
772 if (!retval) 821 if (!retval) {
773 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 822 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
823 set_bit(HCD_FLAG_HW_ACCESSIBLE,
824 &xhci->shared_hcd->flags);
825 }
826failed_restart:
774 hcd->state = HC_STATE_SUSPENDED; 827 hcd->state = HC_STATE_SUSPENDED;
828 xhci->shared_hcd->state = HC_STATE_SUSPENDED;
775 return retval; 829 return retval;
776 } 830 }
777 831
@@ -792,10 +846,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
792 */ 846 */
793 847
794 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 848 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
795 if (!hibernated) 849 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
796 hcd->state = old_state;
797 else
798 hcd->state = HC_STATE_SUSPENDED;
799 850
800 spin_unlock_irq(&xhci->lock); 851 spin_unlock_irq(&xhci->lock);
801 return 0; 852 return 0;
@@ -1167,13 +1218,13 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1167 if (ret || !urb->hcpriv) 1218 if (ret || !urb->hcpriv)
1168 goto done; 1219 goto done;
1169 temp = xhci_readl(xhci, &xhci->op_regs->status); 1220 temp = xhci_readl(xhci, &xhci->op_regs->status);
1170 if (temp == 0xffffffff) { 1221 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) {
1171 xhci_dbg(xhci, "HW died, freeing TD.\n"); 1222 xhci_dbg(xhci, "HW died, freeing TD.\n");
1172 urb_priv = urb->hcpriv; 1223 urb_priv = urb->hcpriv;
1173 1224
1174 usb_hcd_unlink_urb_from_ep(hcd, urb); 1225 usb_hcd_unlink_urb_from_ep(hcd, urb);
1175 spin_unlock_irqrestore(&xhci->lock, flags); 1226 spin_unlock_irqrestore(&xhci->lock, flags);
1176 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, -ESHUTDOWN); 1227 usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN);
1177 xhci_urb_free_priv(xhci, urb_priv); 1228 xhci_urb_free_priv(xhci, urb_priv);
1178 return ret; 1229 return ret;
1179 } 1230 }
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 7f127df6dd55..711de253bc0f 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -644,6 +644,9 @@ struct xhci_ep_ctx {
644#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff) 644#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff)
645#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16) 645#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16)
646 646
647/* deq bitmasks */
648#define EP_CTX_CYCLE_MASK (1 << 0)
649
647 650
648/** 651/**
649 * struct xhci_input_control_context 652 * struct xhci_input_control_context
@@ -746,6 +749,12 @@ struct xhci_virt_ep {
746 struct timer_list stop_cmd_timer; 749 struct timer_list stop_cmd_timer;
747 int stop_cmds_pending; 750 int stop_cmds_pending;
748 struct xhci_hcd *xhci; 751 struct xhci_hcd *xhci;
752 /* Dequeue pointer and dequeue segment for a submitted Set TR Dequeue
753 * command. We'll need to update the ring's dequeue segment and dequeue
754 * pointer after the command completes.
755 */
756 struct xhci_segment *queued_deq_seg;
757 union xhci_trb *queued_deq_ptr;
749 /* 758 /*
750 * Sometimes the xHC can not process isochronous endpoint ring quickly 759 * Sometimes the xHC can not process isochronous endpoint ring quickly
751 * enough, and it will miss some isoc tds on the ring and generate 760 * enough, and it will miss some isoc tds on the ring and generate
@@ -1161,8 +1170,29 @@ struct s3_save {
1161 u64 erst_dequeue; 1170 u64 erst_dequeue;
1162}; 1171};
1163 1172
1173struct xhci_bus_state {
1174 unsigned long bus_suspended;
1175 unsigned long next_statechange;
1176
1177 /* Port suspend arrays are indexed by the portnum of the fake roothub */
1178 /* ports suspend status arrays - max 31 ports for USB2, 15 for USB3 */
1179 u32 port_c_suspend;
1180 u32 suspended_ports;
1181 unsigned long resume_done[USB_MAXCHILDREN];
1182};
1183
1184static inline unsigned int hcd_index(struct usb_hcd *hcd)
1185{
1186 if (hcd->speed == HCD_USB3)
1187 return 0;
1188 else
1189 return 1;
1190}
1191
1164/* There is one ehci_hci structure per controller */ 1192/* There is one ehci_hci structure per controller */
1165struct xhci_hcd { 1193struct xhci_hcd {
1194 struct usb_hcd *main_hcd;
1195 struct usb_hcd *shared_hcd;
1166 /* glue to PCI and HCD framework */ 1196 /* glue to PCI and HCD framework */
1167 struct xhci_cap_regs __iomem *cap_regs; 1197 struct xhci_cap_regs __iomem *cap_regs;
1168 struct xhci_op_regs __iomem *op_regs; 1198 struct xhci_op_regs __iomem *op_regs;
@@ -1224,9 +1254,6 @@ struct xhci_hcd {
1224 /* Host controller watchdog timer structures */ 1254 /* Host controller watchdog timer structures */
1225 unsigned int xhc_state; 1255 unsigned int xhc_state;
1226 1256
1227 unsigned long bus_suspended;
1228 unsigned long next_statechange;
1229
1230 u32 command; 1257 u32 command;
1231 struct s3_save s3; 1258 struct s3_save s3;
1232/* Host controller is dying - not responding to commands. "I'm not dead yet!" 1259/* Host controller is dying - not responding to commands. "I'm not dead yet!"
@@ -1242,18 +1269,15 @@ struct xhci_hcd {
1242 * There are no reports of xHCI host controllers that display this issue. 1269 * There are no reports of xHCI host controllers that display this issue.
1243 */ 1270 */
1244#define XHCI_STATE_DYING (1 << 0) 1271#define XHCI_STATE_DYING (1 << 0)
1272#define XHCI_STATE_HALTED (1 << 1)
1245 /* Statistics */ 1273 /* Statistics */
1246 int noops_submitted;
1247 int noops_handled;
1248 int error_bitmask; 1274 int error_bitmask;
1249 unsigned int quirks; 1275 unsigned int quirks;
1250#define XHCI_LINK_TRB_QUIRK (1 << 0) 1276#define XHCI_LINK_TRB_QUIRK (1 << 0)
1251#define XHCI_RESET_EP_QUIRK (1 << 1) 1277#define XHCI_RESET_EP_QUIRK (1 << 1)
1252#define XHCI_NEC_HOST (1 << 2) 1278#define XHCI_NEC_HOST (1 << 2)
1253 u32 port_c_suspend[8]; /* port suspend change*/ 1279 /* There are two roothubs to keep track of bus suspend info for */
1254 u32 suspended_ports[8]; /* which ports are 1280 struct xhci_bus_state bus_state[2];
1255 suspended */
1256 unsigned long resume_done[MAX_HC_PORTS];
1257 /* Is each xHCI roothub port a USB 3.0, USB 2.0, or USB 1.1 port? */ 1281 /* Is each xHCI roothub port a USB 3.0, USB 2.0, or USB 1.1 port? */
1258 u8 *port_array; 1282 u8 *port_array;
1259 /* Array of pointers to USB 3.0 PORTSC registers */ 1283 /* Array of pointers to USB 3.0 PORTSC registers */
@@ -1264,18 +1288,15 @@ struct xhci_hcd {
1264 unsigned int num_usb2_ports; 1288 unsigned int num_usb2_ports;
1265}; 1289};
1266 1290
1267/* For testing purposes */
1268#define NUM_TEST_NOOPS 0
1269
1270/* convert between an HCD pointer and the corresponding EHCI_HCD */ 1291/* convert between an HCD pointer and the corresponding EHCI_HCD */
1271static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd) 1292static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd)
1272{ 1293{
1273 return (struct xhci_hcd *) (hcd->hcd_priv); 1294 return *((struct xhci_hcd **) (hcd->hcd_priv));
1274} 1295}
1275 1296
1276static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci) 1297static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1277{ 1298{
1278 return container_of((void *) xhci, struct usb_hcd, hcd_priv); 1299 return xhci->main_hcd;
1279} 1300}
1280 1301
1281#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 1302#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
@@ -1471,7 +1492,6 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
1471 dma_addr_t suspect_dma); 1492 dma_addr_t suspect_dma);
1472int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); 1493int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
1473void xhci_ring_cmd_db(struct xhci_hcd *xhci); 1494void xhci_ring_cmd_db(struct xhci_hcd *xhci);
1474void *xhci_setup_one_noop(struct xhci_hcd *xhci);
1475int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); 1495int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
1476int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1496int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1477 u32 slot_id); 1497 u32 slot_id);
@@ -1525,7 +1545,8 @@ int xhci_bus_resume(struct usb_hcd *hcd);
1525#endif /* CONFIG_PM */ 1545#endif /* CONFIG_PM */
1526 1546
1527u32 xhci_port_state_to_neutral(u32 state); 1547u32 xhci_port_state_to_neutral(u32 state);
1528int xhci_find_slot_id_by_port(struct xhci_hcd *xhci, u16 port); 1548int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
1549 u16 port);
1529void xhci_ring_device(struct xhci_hcd *xhci, int slot_id); 1550void xhci_ring_device(struct xhci_hcd *xhci, int slot_id);
1530 1551
1531/* xHCI contexts */ 1552/* xHCI contexts */
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index a35b427c0bac..388cc128072a 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -83,6 +83,8 @@ static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
83#define WARNING(tdev, fmt, args...) \ 83#define WARNING(tdev, fmt, args...) \
84 dev_warn(&(tdev)->intf->dev , fmt , ## args) 84 dev_warn(&(tdev)->intf->dev , fmt , ## args)
85 85
86#define GUARD_BYTE 0xA5
87
86/*-------------------------------------------------------------------------*/ 88/*-------------------------------------------------------------------------*/
87 89
88static int 90static int
@@ -186,11 +188,12 @@ static void simple_callback(struct urb *urb)
186 complete(urb->context); 188 complete(urb->context);
187} 189}
188 190
189static struct urb *simple_alloc_urb( 191static struct urb *usbtest_alloc_urb(
190 struct usb_device *udev, 192 struct usb_device *udev,
191 int pipe, 193 int pipe,
192 unsigned long bytes 194 unsigned long bytes,
193) 195 unsigned transfer_flags,
196 unsigned offset)
194{ 197{
195 struct urb *urb; 198 struct urb *urb;
196 199
@@ -201,19 +204,46 @@ static struct urb *simple_alloc_urb(
201 urb->interval = (udev->speed == USB_SPEED_HIGH) 204 urb->interval = (udev->speed == USB_SPEED_HIGH)
202 ? (INTERRUPT_RATE << 3) 205 ? (INTERRUPT_RATE << 3)
203 : INTERRUPT_RATE; 206 : INTERRUPT_RATE;
204 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 207 urb->transfer_flags = transfer_flags;
205 if (usb_pipein(pipe)) 208 if (usb_pipein(pipe))
206 urb->transfer_flags |= URB_SHORT_NOT_OK; 209 urb->transfer_flags |= URB_SHORT_NOT_OK;
207 urb->transfer_buffer = usb_alloc_coherent(udev, bytes, GFP_KERNEL, 210
208 &urb->transfer_dma); 211 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
212 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
213 GFP_KERNEL, &urb->transfer_dma);
214 else
215 urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL);
216
209 if (!urb->transfer_buffer) { 217 if (!urb->transfer_buffer) {
210 usb_free_urb(urb); 218 usb_free_urb(urb);
211 urb = NULL; 219 return NULL;
212 } else 220 }
213 memset(urb->transfer_buffer, 0, bytes); 221
222 /* To test unaligned transfers add an offset and fill the
223 unused memory with a guard value */
224 if (offset) {
225 memset(urb->transfer_buffer, GUARD_BYTE, offset);
226 urb->transfer_buffer += offset;
227 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
228 urb->transfer_dma += offset;
229 }
230
231 /* For inbound transfers use guard byte so that test fails if
232 data not correctly copied */
233 memset(urb->transfer_buffer,
234 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
235 bytes);
214 return urb; 236 return urb;
215} 237}
216 238
239static struct urb *simple_alloc_urb(
240 struct usb_device *udev,
241 int pipe,
242 unsigned long bytes)
243{
244 return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0);
245}
246
217static unsigned pattern; 247static unsigned pattern;
218static unsigned mod_pattern; 248static unsigned mod_pattern;
219module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR); 249module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR);
@@ -238,13 +268,38 @@ static inline void simple_fill_buf(struct urb *urb)
238 } 268 }
239} 269}
240 270
241static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb) 271static inline unsigned buffer_offset(void *buf)
272{
273 return (unsigned)buf & (ARCH_KMALLOC_MINALIGN - 1);
274}
275
276static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb)
277{
278 u8 *buf = urb->transfer_buffer;
279 u8 *guard = buf - buffer_offset(buf);
280 unsigned i;
281
282 for (i = 0; guard < buf; i++, guard++) {
283 if (*guard != GUARD_BYTE) {
284 ERROR(tdev, "guard byte[%d] %d (not %d)\n",
285 i, *guard, GUARD_BYTE);
286 return -EINVAL;
287 }
288 }
289 return 0;
290}
291
292static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
242{ 293{
243 unsigned i; 294 unsigned i;
244 u8 expected; 295 u8 expected;
245 u8 *buf = urb->transfer_buffer; 296 u8 *buf = urb->transfer_buffer;
246 unsigned len = urb->actual_length; 297 unsigned len = urb->actual_length;
247 298
299 int ret = check_guard_bytes(tdev, urb);
300 if (ret)
301 return ret;
302
248 for (i = 0; i < len; i++, buf++) { 303 for (i = 0; i < len; i++, buf++) {
249 switch (pattern) { 304 switch (pattern) {
250 /* all-zeroes has no synchronization issues */ 305 /* all-zeroes has no synchronization issues */
@@ -274,8 +329,16 @@ static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
274 329
275static void simple_free_urb(struct urb *urb) 330static void simple_free_urb(struct urb *urb)
276{ 331{
277 usb_free_coherent(urb->dev, urb->transfer_buffer_length, 332 unsigned offset = buffer_offset(urb->transfer_buffer);
278 urb->transfer_buffer, urb->transfer_dma); 333
334 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
335 usb_free_coherent(
336 urb->dev,
337 urb->transfer_buffer_length + offset,
338 urb->transfer_buffer - offset,
339 urb->transfer_dma - offset);
340 else
341 kfree(urb->transfer_buffer - offset);
279 usb_free_urb(urb); 342 usb_free_urb(urb);
280} 343}
281 344
@@ -1256,7 +1319,7 @@ done:
1256 * try whatever we're told to try. 1319 * try whatever we're told to try.
1257 */ 1320 */
1258static int ctrl_out(struct usbtest_dev *dev, 1321static int ctrl_out(struct usbtest_dev *dev,
1259 unsigned count, unsigned length, unsigned vary) 1322 unsigned count, unsigned length, unsigned vary, unsigned offset)
1260{ 1323{
1261 unsigned i, j, len; 1324 unsigned i, j, len;
1262 int retval; 1325 int retval;
@@ -1267,10 +1330,11 @@ static int ctrl_out(struct usbtest_dev *dev,
1267 if (length < 1 || length > 0xffff || vary >= length) 1330 if (length < 1 || length > 0xffff || vary >= length)
1268 return -EINVAL; 1331 return -EINVAL;
1269 1332
1270 buf = kmalloc(length, GFP_KERNEL); 1333 buf = kmalloc(length + offset, GFP_KERNEL);
1271 if (!buf) 1334 if (!buf)
1272 return -ENOMEM; 1335 return -ENOMEM;
1273 1336
1337 buf += offset;
1274 udev = testdev_to_usbdev(dev); 1338 udev = testdev_to_usbdev(dev);
1275 len = length; 1339 len = length;
1276 retval = 0; 1340 retval = 0;
@@ -1337,7 +1401,7 @@ static int ctrl_out(struct usbtest_dev *dev,
1337 ERROR(dev, "ctrl_out %s failed, code %d, count %d\n", 1401 ERROR(dev, "ctrl_out %s failed, code %d, count %d\n",
1338 what, retval, i); 1402 what, retval, i);
1339 1403
1340 kfree(buf); 1404 kfree(buf - offset);
1341 return retval; 1405 return retval;
1342} 1406}
1343 1407
@@ -1373,6 +1437,8 @@ static void iso_callback(struct urb *urb)
1373 ctx->errors += urb->number_of_packets; 1437 ctx->errors += urb->number_of_packets;
1374 else if (urb->actual_length != urb->transfer_buffer_length) 1438 else if (urb->actual_length != urb->transfer_buffer_length)
1375 ctx->errors++; 1439 ctx->errors++;
1440 else if (check_guard_bytes(ctx->dev, urb) != 0)
1441 ctx->errors++;
1376 1442
1377 if (urb->status == 0 && ctx->count > (ctx->pending - 1) 1443 if (urb->status == 0 && ctx->count > (ctx->pending - 1)
1378 && !ctx->submit_error) { 1444 && !ctx->submit_error) {
@@ -1408,7 +1474,8 @@ static struct urb *iso_alloc_urb(
1408 struct usb_device *udev, 1474 struct usb_device *udev,
1409 int pipe, 1475 int pipe,
1410 struct usb_endpoint_descriptor *desc, 1476 struct usb_endpoint_descriptor *desc,
1411 long bytes 1477 long bytes,
1478 unsigned offset
1412) 1479)
1413{ 1480{
1414 struct urb *urb; 1481 struct urb *urb;
@@ -1428,13 +1495,24 @@ static struct urb *iso_alloc_urb(
1428 1495
1429 urb->number_of_packets = packets; 1496 urb->number_of_packets = packets;
1430 urb->transfer_buffer_length = bytes; 1497 urb->transfer_buffer_length = bytes;
1431 urb->transfer_buffer = usb_alloc_coherent(udev, bytes, GFP_KERNEL, 1498 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
1432 &urb->transfer_dma); 1499 GFP_KERNEL,
1500 &urb->transfer_dma);
1433 if (!urb->transfer_buffer) { 1501 if (!urb->transfer_buffer) {
1434 usb_free_urb(urb); 1502 usb_free_urb(urb);
1435 return NULL; 1503 return NULL;
1436 } 1504 }
1437 memset(urb->transfer_buffer, 0, bytes); 1505 if (offset) {
1506 memset(urb->transfer_buffer, GUARD_BYTE, offset);
1507 urb->transfer_buffer += offset;
1508 urb->transfer_dma += offset;
1509 }
1510 /* For inbound transfers use guard byte so that test fails if
1511 data not correctly copied */
1512 memset(urb->transfer_buffer,
1513 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
1514 bytes);
1515
1438 for (i = 0; i < packets; i++) { 1516 for (i = 0; i < packets; i++) {
1439 /* here, only the last packet will be short */ 1517 /* here, only the last packet will be short */
1440 urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp); 1518 urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp);
@@ -1452,7 +1530,7 @@ static struct urb *iso_alloc_urb(
1452 1530
1453static int 1531static int
1454test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param, 1532test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
1455 int pipe, struct usb_endpoint_descriptor *desc) 1533 int pipe, struct usb_endpoint_descriptor *desc, unsigned offset)
1456{ 1534{
1457 struct iso_context context; 1535 struct iso_context context;
1458 struct usb_device *udev; 1536 struct usb_device *udev;
@@ -1480,7 +1558,7 @@ test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
1480 1558
1481 for (i = 0; i < param->sglen; i++) { 1559 for (i = 0; i < param->sglen; i++) {
1482 urbs[i] = iso_alloc_urb(udev, pipe, desc, 1560 urbs[i] = iso_alloc_urb(udev, pipe, desc,
1483 param->length); 1561 param->length, offset);
1484 if (!urbs[i]) { 1562 if (!urbs[i]) {
1485 status = -ENOMEM; 1563 status = -ENOMEM;
1486 goto fail; 1564 goto fail;
@@ -1542,6 +1620,26 @@ fail:
1542 return status; 1620 return status;
1543} 1621}
1544 1622
1623static int test_unaligned_bulk(
1624 struct usbtest_dev *tdev,
1625 int pipe,
1626 unsigned length,
1627 int iterations,
1628 unsigned transfer_flags,
1629 const char *label)
1630{
1631 int retval;
1632 struct urb *urb = usbtest_alloc_urb(
1633 testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1);
1634
1635 if (!urb)
1636 return -ENOMEM;
1637
1638 retval = simple_io(tdev, urb, iterations, 0, 0, label);
1639 simple_free_urb(urb);
1640 return retval;
1641}
1642
1545/*-------------------------------------------------------------------------*/ 1643/*-------------------------------------------------------------------------*/
1546 1644
1547/* We only have this one interface to user space, through usbfs. 1645/* We only have this one interface to user space, through usbfs.
@@ -1843,7 +1941,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
1843 realworld ? 1 : 0, param->length, 1941 realworld ? 1 : 0, param->length,
1844 param->vary); 1942 param->vary);
1845 retval = ctrl_out(dev, param->iterations, 1943 retval = ctrl_out(dev, param->iterations,
1846 param->length, param->vary); 1944 param->length, param->vary, 0);
1847 break; 1945 break;
1848 1946
1849 /* iso write tests */ 1947 /* iso write tests */
@@ -1856,7 +1954,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
1856 param->sglen, param->length); 1954 param->sglen, param->length);
1857 /* FIRMWARE: iso sink */ 1955 /* FIRMWARE: iso sink */
1858 retval = test_iso_queue(dev, param, 1956 retval = test_iso_queue(dev, param,
1859 dev->out_iso_pipe, dev->iso_out); 1957 dev->out_iso_pipe, dev->iso_out, 0);
1860 break; 1958 break;
1861 1959
1862 /* iso read tests */ 1960 /* iso read tests */
@@ -1869,13 +1967,103 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
1869 param->sglen, param->length); 1967 param->sglen, param->length);
1870 /* FIRMWARE: iso source */ 1968 /* FIRMWARE: iso source */
1871 retval = test_iso_queue(dev, param, 1969 retval = test_iso_queue(dev, param,
1872 dev->in_iso_pipe, dev->iso_in); 1970 dev->in_iso_pipe, dev->iso_in, 0);
1873 break; 1971 break;
1874 1972
1875 /* FIXME unlink from queue (ring with N urbs) */ 1973 /* FIXME unlink from queue (ring with N urbs) */
1876 1974
1877 /* FIXME scatterlist cancel (needs helper thread) */ 1975 /* FIXME scatterlist cancel (needs helper thread) */
1878 1976
1977 /* Tests for bulk I/O using DMA mapping by core and odd address */
1978 case 17:
1979 if (dev->out_pipe == 0)
1980 break;
1981 dev_info(&intf->dev,
1982 "TEST 17: write odd addr %d bytes %u times core map\n",
1983 param->length, param->iterations);
1984
1985 retval = test_unaligned_bulk(
1986 dev, dev->out_pipe,
1987 param->length, param->iterations,
1988 0, "test17");
1989 break;
1990
1991 case 18:
1992 if (dev->in_pipe == 0)
1993 break;
1994 dev_info(&intf->dev,
1995 "TEST 18: read odd addr %d bytes %u times core map\n",
1996 param->length, param->iterations);
1997
1998 retval = test_unaligned_bulk(
1999 dev, dev->in_pipe,
2000 param->length, param->iterations,
2001 0, "test18");
2002 break;
2003
2004 /* Tests for bulk I/O using premapped coherent buffer and odd address */
2005 case 19:
2006 if (dev->out_pipe == 0)
2007 break;
2008 dev_info(&intf->dev,
2009 "TEST 19: write odd addr %d bytes %u times premapped\n",
2010 param->length, param->iterations);
2011
2012 retval = test_unaligned_bulk(
2013 dev, dev->out_pipe,
2014 param->length, param->iterations,
2015 URB_NO_TRANSFER_DMA_MAP, "test19");
2016 break;
2017
2018 case 20:
2019 if (dev->in_pipe == 0)
2020 break;
2021 dev_info(&intf->dev,
2022 "TEST 20: read odd addr %d bytes %u times premapped\n",
2023 param->length, param->iterations);
2024
2025 retval = test_unaligned_bulk(
2026 dev, dev->in_pipe,
2027 param->length, param->iterations,
2028 URB_NO_TRANSFER_DMA_MAP, "test20");
2029 break;
2030
2031 /* control write tests with unaligned buffer */
2032 case 21:
2033 if (!dev->info->ctrl_out)
2034 break;
2035 dev_info(&intf->dev,
2036 "TEST 21: %d ep0out odd addr, %d..%d vary %d\n",
2037 param->iterations,
2038 realworld ? 1 : 0, param->length,
2039 param->vary);
2040 retval = ctrl_out(dev, param->iterations,
2041 param->length, param->vary, 1);
2042 break;
2043
2044 /* unaligned iso tests */
2045 case 22:
2046 if (dev->out_iso_pipe == 0 || param->sglen == 0)
2047 break;
2048 dev_info(&intf->dev,
2049 "TEST 22: write %d iso odd, %d entries of %d bytes\n",
2050 param->iterations,
2051 param->sglen, param->length);
2052 retval = test_iso_queue(dev, param,
2053 dev->out_iso_pipe, dev->iso_out, 1);
2054 break;
2055
2056 case 23:
2057 if (dev->in_iso_pipe == 0 || param->sglen == 0)
2058 break;
2059 dev_info(&intf->dev,
2060 "TEST 23: read %d iso odd, %d entries of %d bytes\n",
2061 param->iterations,
2062 param->sglen, param->length);
2063 retval = test_iso_queue(dev, param,
2064 dev->in_iso_pipe, dev->iso_in, 1);
2065 break;
2066
1879 } 2067 }
1880 do_gettimeofday(&param->duration); 2068 do_gettimeofday(&param->duration);
1881 param->duration.tv_sec -= start.tv_sec; 2069 param->duration.tv_sec -= start.tv_sec;
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index a545d65f6e57..c302e1983c70 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -236,6 +236,9 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb,
236 fp++; 236 fp++;
237 dp++; 237 dp++;
238 } 238 }
239 /* Wasteful, but simple to understand: ISO 'C' is sparse. */
240 if (ev_type == 'C')
241 ep->length = urb->transfer_buffer_length;
239 } 242 }
240 243
241 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus); 244 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus);
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index c292d5c499e7..a914010d9d12 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1950,31 +1950,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1950 goto fail0; 1950 goto fail0;
1951 } 1951 }
1952 1952
1953 switch (plat->mode) {
1954 case MUSB_HOST:
1955#ifdef CONFIG_USB_MUSB_HDRC_HCD
1956 break;
1957#else
1958 goto bad_config;
1959#endif
1960 case MUSB_PERIPHERAL:
1961#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1962 break;
1963#else
1964 goto bad_config;
1965#endif
1966 case MUSB_OTG:
1967#ifdef CONFIG_USB_MUSB_OTG
1968 break;
1969#else
1970bad_config:
1971#endif
1972 default:
1973 dev_err(dev, "incompatible Kconfig role setting\n");
1974 status = -EINVAL;
1975 goto fail0;
1976 }
1977
1978 /* allocate */ 1953 /* allocate */
1979 musb = allocate_instance(dev, plat->config, ctrl); 1954 musb = allocate_instance(dev, plat->config, ctrl);
1980 if (!musb) { 1955 if (!musb) {
@@ -1982,6 +1957,10 @@ bad_config:
1982 goto fail0; 1957 goto fail0;
1983 } 1958 }
1984 1959
1960 pm_runtime_use_autosuspend(musb->controller);
1961 pm_runtime_set_autosuspend_delay(musb->controller, 200);
1962 pm_runtime_enable(musb->controller);
1963
1985 spin_lock_init(&musb->lock); 1964 spin_lock_init(&musb->lock);
1986 musb->board_mode = plat->mode; 1965 musb->board_mode = plat->mode;
1987 musb->board_set_power = plat->set_power; 1966 musb->board_set_power = plat->set_power;
@@ -2117,6 +2096,8 @@ bad_config:
2117 if (status < 0) 2096 if (status < 0)
2118 goto fail3; 2097 goto fail3;
2119 2098
2099 pm_runtime_put(musb->controller);
2100
2120 status = musb_init_debugfs(musb); 2101 status = musb_init_debugfs(musb);
2121 if (status < 0) 2102 if (status < 0)
2122 goto fail4; 2103 goto fail4;
@@ -2216,9 +2197,11 @@ static int __exit musb_remove(struct platform_device *pdev)
2216 * - Peripheral mode: peripheral is deactivated (or never-activated) 2197 * - Peripheral mode: peripheral is deactivated (or never-activated)
2217 * - OTG mode: both roles are deactivated (or never-activated) 2198 * - OTG mode: both roles are deactivated (or never-activated)
2218 */ 2199 */
2200 pm_runtime_get_sync(musb->controller);
2219 musb_exit_debugfs(musb); 2201 musb_exit_debugfs(musb);
2220 musb_shutdown(pdev); 2202 musb_shutdown(pdev);
2221 2203
2204 pm_runtime_put(musb->controller);
2222 musb_free(musb); 2205 musb_free(musb);
2223 iounmap(ctrl_base); 2206 iounmap(ctrl_base);
2224 device_init_wakeup(&pdev->dev, 0); 2207 device_init_wakeup(&pdev->dev, 0);
@@ -2404,9 +2387,41 @@ static int musb_resume_noirq(struct device *dev)
2404 return 0; 2387 return 0;
2405} 2388}
2406 2389
2390static int musb_runtime_suspend(struct device *dev)
2391{
2392 struct musb *musb = dev_to_musb(dev);
2393
2394 musb_save_context(musb);
2395
2396 return 0;
2397}
2398
2399static int musb_runtime_resume(struct device *dev)
2400{
2401 struct musb *musb = dev_to_musb(dev);
2402 static int first = 1;
2403
2404 /*
2405 * When pm_runtime_get_sync called for the first time in driver
2406 * init, some of the structure is still not initialized which is
2407 * used in restore function. But clock needs to be
2408 * enabled before any register access, so
2409 * pm_runtime_get_sync has to be called.
2410 * Also context restore without save does not make
2411 * any sense
2412 */
2413 if (!first)
2414 musb_restore_context(musb);
2415 first = 0;
2416
2417 return 0;
2418}
2419
2407static const struct dev_pm_ops musb_dev_pm_ops = { 2420static const struct dev_pm_ops musb_dev_pm_ops = {
2408 .suspend = musb_suspend, 2421 .suspend = musb_suspend,
2409 .resume_noirq = musb_resume_noirq, 2422 .resume_noirq = musb_resume_noirq,
2423 .runtime_suspend = musb_runtime_suspend,
2424 .runtime_resume = musb_runtime_resume,
2410}; 2425};
2411 2426
2412#define MUSB_DEV_PM_OPS (&musb_dev_pm_ops) 2427#define MUSB_DEV_PM_OPS (&musb_dev_pm_ops)
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index e6400be8a0f8..4f0dd2ed3964 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -328,7 +328,7 @@ struct musb_hw_ep {
328#endif 328#endif
329}; 329};
330 330
331static inline struct usb_request *next_in_request(struct musb_hw_ep *hw_ep) 331static inline struct musb_request *next_in_request(struct musb_hw_ep *hw_ep)
332{ 332{
333#ifdef CONFIG_USB_GADGET_MUSB_HDRC 333#ifdef CONFIG_USB_GADGET_MUSB_HDRC
334 return next_request(&hw_ep->ep_in); 334 return next_request(&hw_ep->ep_in);
@@ -337,7 +337,7 @@ static inline struct usb_request *next_in_request(struct musb_hw_ep *hw_ep)
337#endif 337#endif
338} 338}
339 339
340static inline struct usb_request *next_out_request(struct musb_hw_ep *hw_ep) 340static inline struct musb_request *next_out_request(struct musb_hw_ep *hw_ep)
341{ 341{
342#ifdef CONFIG_USB_GADGET_MUSB_HDRC 342#ifdef CONFIG_USB_GADGET_MUSB_HDRC
343 return next_request(&hw_ep->ep_out); 343 return next_request(&hw_ep->ep_out);
@@ -358,10 +358,6 @@ struct musb_csr_regs {
358 358
359struct musb_context_registers { 359struct musb_context_registers {
360 360
361#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \
362 defined(CONFIG_ARCH_OMAP4)
363 u32 otg_sysconfig, otg_forcestandby;
364#endif
365 u8 power; 361 u8 power;
366 u16 intrtxe, intrrxe; 362 u16 intrtxe, intrrxe;
367 u8 intrusbe; 363 u8 intrusbe;
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 2fe304611dcf..5c7b321d3959 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -189,7 +189,7 @@ __acquires(ep->musb->lock)
189 189
190 req = to_musb_request(request); 190 req = to_musb_request(request);
191 191
192 list_del(&request->list); 192 list_del(&req->list);
193 if (req->request.status == -EINPROGRESS) 193 if (req->request.status == -EINPROGRESS)
194 req->request.status = status; 194 req->request.status = status;
195 musb = req->musb; 195 musb = req->musb;
@@ -251,9 +251,8 @@ static void nuke(struct musb_ep *ep, const int status)
251 ep->dma = NULL; 251 ep->dma = NULL;
252 } 252 }
253 253
254 while (!list_empty(&(ep->req_list))) { 254 while (!list_empty(&ep->req_list)) {
255 req = container_of(ep->req_list.next, struct musb_request, 255 req = list_first_entry(&ep->req_list, struct musb_request, list);
256 request.list);
257 musb_g_giveback(ep, &req->request, status); 256 musb_g_giveback(ep, &req->request, status);
258 } 257 }
259} 258}
@@ -485,6 +484,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
485void musb_g_tx(struct musb *musb, u8 epnum) 484void musb_g_tx(struct musb *musb, u8 epnum)
486{ 485{
487 u16 csr; 486 u16 csr;
487 struct musb_request *req;
488 struct usb_request *request; 488 struct usb_request *request;
489 u8 __iomem *mbase = musb->mregs; 489 u8 __iomem *mbase = musb->mregs;
490 struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_in; 490 struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_in;
@@ -492,7 +492,8 @@ void musb_g_tx(struct musb *musb, u8 epnum)
492 struct dma_channel *dma; 492 struct dma_channel *dma;
493 493
494 musb_ep_select(mbase, epnum); 494 musb_ep_select(mbase, epnum);
495 request = next_request(musb_ep); 495 req = next_request(musb_ep);
496 request = &req->request;
496 497
497 csr = musb_readw(epio, MUSB_TXCSR); 498 csr = musb_readw(epio, MUSB_TXCSR);
498 DBG(4, "<== %s, txcsr %04x\n", musb_ep->end_point.name, csr); 499 DBG(4, "<== %s, txcsr %04x\n", musb_ep->end_point.name, csr);
@@ -571,15 +572,15 @@ void musb_g_tx(struct musb *musb, u8 epnum)
571 572
572 if (request->actual == request->length) { 573 if (request->actual == request->length) {
573 musb_g_giveback(musb_ep, request, 0); 574 musb_g_giveback(musb_ep, request, 0);
574 request = musb_ep->desc ? next_request(musb_ep) : NULL; 575 req = musb_ep->desc ? next_request(musb_ep) : NULL;
575 if (!request) { 576 if (!req) {
576 DBG(4, "%s idle now\n", 577 DBG(4, "%s idle now\n",
577 musb_ep->end_point.name); 578 musb_ep->end_point.name);
578 return; 579 return;
579 } 580 }
580 } 581 }
581 582
582 txstate(musb, to_musb_request(request)); 583 txstate(musb, req);
583 } 584 }
584} 585}
585 586
@@ -821,6 +822,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
821void musb_g_rx(struct musb *musb, u8 epnum) 822void musb_g_rx(struct musb *musb, u8 epnum)
822{ 823{
823 u16 csr; 824 u16 csr;
825 struct musb_request *req;
824 struct usb_request *request; 826 struct usb_request *request;
825 void __iomem *mbase = musb->mregs; 827 void __iomem *mbase = musb->mregs;
826 struct musb_ep *musb_ep; 828 struct musb_ep *musb_ep;
@@ -835,10 +837,12 @@ void musb_g_rx(struct musb *musb, u8 epnum)
835 837
836 musb_ep_select(mbase, epnum); 838 musb_ep_select(mbase, epnum);
837 839
838 request = next_request(musb_ep); 840 req = next_request(musb_ep);
839 if (!request) 841 if (!req)
840 return; 842 return;
841 843
844 request = &req->request;
845
842 csr = musb_readw(epio, MUSB_RXCSR); 846 csr = musb_readw(epio, MUSB_RXCSR);
843 dma = is_dma_capable() ? musb_ep->dma : NULL; 847 dma = is_dma_capable() ? musb_ep->dma : NULL;
844 848
@@ -914,15 +918,15 @@ void musb_g_rx(struct musb *musb, u8 epnum)
914#endif 918#endif
915 musb_g_giveback(musb_ep, request, 0); 919 musb_g_giveback(musb_ep, request, 0);
916 920
917 request = next_request(musb_ep); 921 req = next_request(musb_ep);
918 if (!request) 922 if (!req)
919 return; 923 return;
920 } 924 }
921#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA) 925#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA)
922exit: 926exit:
923#endif 927#endif
924 /* Analyze request */ 928 /* Analyze request */
925 rxstate(musb, to_musb_request(request)); 929 rxstate(musb, req);
926} 930}
927 931
928/* ------------------------------------------------------------ */ 932/* ------------------------------------------------------------ */
@@ -974,7 +978,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
974 ok = musb->hb_iso_rx; 978 ok = musb->hb_iso_rx;
975 979
976 if (!ok) { 980 if (!ok) {
977 DBG(4, "%s: not support ISO high bandwidth\n", __func__); 981 DBG(4, "no support for high bandwidth ISO\n");
978 goto fail; 982 goto fail;
979 } 983 }
980 musb_ep->hb_mult = (tmp >> 11) & 3; 984 musb_ep->hb_mult = (tmp >> 11) & 3;
@@ -998,7 +1002,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
998 goto fail; 1002 goto fail;
999 1003
1000 if (tmp > hw_ep->max_packet_sz_tx) { 1004 if (tmp > hw_ep->max_packet_sz_tx) {
1001 DBG(4, "%s: packet size beyond hw fifo size\n", __func__); 1005 DBG(4, "packet size beyond hardware FIFO size\n");
1002 goto fail; 1006 goto fail;
1003 } 1007 }
1004 1008
@@ -1038,7 +1042,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
1038 goto fail; 1042 goto fail;
1039 1043
1040 if (tmp > hw_ep->max_packet_sz_rx) { 1044 if (tmp > hw_ep->max_packet_sz_rx) {
1041 DBG(4, "%s: packet size beyond hw fifo size\n", __func__); 1045 DBG(4, "packet size beyond hardware FIFO size\n");
1042 goto fail; 1046 goto fail;
1043 } 1047 }
1044 1048
@@ -1171,7 +1175,6 @@ struct usb_request *musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
1171 return NULL; 1175 return NULL;
1172 } 1176 }
1173 1177
1174 INIT_LIST_HEAD(&request->request.list);
1175 request->request.dma = DMA_ADDR_INVALID; 1178 request->request.dma = DMA_ADDR_INVALID;
1176 request->epnum = musb_ep->current_epnum; 1179 request->epnum = musb_ep->current_epnum;
1177 request->ep = musb_ep; 1180 request->ep = musb_ep;
@@ -1257,10 +1260,10 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1257 } 1260 }
1258 1261
1259 /* add request to the list */ 1262 /* add request to the list */
1260 list_add_tail(&(request->request.list), &(musb_ep->req_list)); 1263 list_add_tail(&request->list, &musb_ep->req_list);
1261 1264
1262 /* it this is the head of the queue, start i/o ... */ 1265 /* it this is the head of the queue, start i/o ... */
1263 if (!musb_ep->busy && &request->request.list == musb_ep->req_list.next) 1266 if (!musb_ep->busy && &request->list == musb_ep->req_list.next)
1264 musb_ep_restart(musb, request); 1267 musb_ep_restart(musb, request);
1265 1268
1266cleanup: 1269cleanup:
@@ -1271,7 +1274,8 @@ cleanup:
1271static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request) 1274static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request)
1272{ 1275{
1273 struct musb_ep *musb_ep = to_musb_ep(ep); 1276 struct musb_ep *musb_ep = to_musb_ep(ep);
1274 struct usb_request *r; 1277 struct musb_request *req = to_musb_request(request);
1278 struct musb_request *r;
1275 unsigned long flags; 1279 unsigned long flags;
1276 int status = 0; 1280 int status = 0;
1277 struct musb *musb = musb_ep->musb; 1281 struct musb *musb = musb_ep->musb;
@@ -1282,10 +1286,10 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request)
1282 spin_lock_irqsave(&musb->lock, flags); 1286 spin_lock_irqsave(&musb->lock, flags);
1283 1287
1284 list_for_each_entry(r, &musb_ep->req_list, list) { 1288 list_for_each_entry(r, &musb_ep->req_list, list) {
1285 if (r == request) 1289 if (r == req)
1286 break; 1290 break;
1287 } 1291 }
1288 if (r != request) { 1292 if (r != req) {
1289 DBG(3, "request %p not queued to %s\n", request, ep->name); 1293 DBG(3, "request %p not queued to %s\n", request, ep->name);
1290 status = -EINVAL; 1294 status = -EINVAL;
1291 goto done; 1295 goto done;
@@ -1349,7 +1353,7 @@ static int musb_gadget_set_halt(struct usb_ep *ep, int value)
1349 1353
1350 musb_ep_select(mbase, epnum); 1354 musb_ep_select(mbase, epnum);
1351 1355
1352 request = to_musb_request(next_request(musb_ep)); 1356 request = next_request(musb_ep);
1353 if (value) { 1357 if (value) {
1354 if (request) { 1358 if (request) {
1355 DBG(3, "request in progress, cannot halt %s\n", 1359 DBG(3, "request in progress, cannot halt %s\n",
@@ -1801,90 +1805,105 @@ void musb_gadget_cleanup(struct musb *musb)
1801int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1805int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1802 int (*bind)(struct usb_gadget *)) 1806 int (*bind)(struct usb_gadget *))
1803{ 1807{
1804 int retval; 1808 struct musb *musb = the_gadget;
1805 unsigned long flags; 1809 unsigned long flags;
1806 struct musb *musb = the_gadget; 1810 int retval = -EINVAL;
1807 1811
1808 if (!driver 1812 if (!driver
1809 || driver->speed != USB_SPEED_HIGH 1813 || driver->speed != USB_SPEED_HIGH
1810 || !bind || !driver->setup) 1814 || !bind || !driver->setup)
1811 return -EINVAL; 1815 goto err0;
1812 1816
1813 /* driver must be initialized to support peripheral mode */ 1817 /* driver must be initialized to support peripheral mode */
1814 if (!musb) { 1818 if (!musb) {
1815 DBG(1, "%s, no dev??\n", __func__); 1819 DBG(1, "no dev??\n");
1816 return -ENODEV; 1820 retval = -ENODEV;
1821 goto err0;
1817 } 1822 }
1818 1823
1824 pm_runtime_get_sync(musb->controller);
1825
1819 DBG(3, "registering driver %s\n", driver->function); 1826 DBG(3, "registering driver %s\n", driver->function);
1820 spin_lock_irqsave(&musb->lock, flags);
1821 1827
1822 if (musb->gadget_driver) { 1828 if (musb->gadget_driver) {
1823 DBG(1, "%s is already bound to %s\n", 1829 DBG(1, "%s is already bound to %s\n",
1824 musb_driver_name, 1830 musb_driver_name,
1825 musb->gadget_driver->driver.name); 1831 musb->gadget_driver->driver.name);
1826 retval = -EBUSY; 1832 retval = -EBUSY;
1827 } else { 1833 goto err0;
1828 musb->gadget_driver = driver;
1829 musb->g.dev.driver = &driver->driver;
1830 driver->driver.bus = NULL;
1831 musb->softconnect = 1;
1832 retval = 0;
1833 } 1834 }
1834 1835
1836 spin_lock_irqsave(&musb->lock, flags);
1837 musb->gadget_driver = driver;
1838 musb->g.dev.driver = &driver->driver;
1839 driver->driver.bus = NULL;
1840 musb->softconnect = 1;
1835 spin_unlock_irqrestore(&musb->lock, flags); 1841 spin_unlock_irqrestore(&musb->lock, flags);
1836 1842
1837 if (retval == 0) { 1843 retval = bind(&musb->g);
1838 retval = bind(&musb->g); 1844 if (retval) {
1839 if (retval != 0) { 1845 DBG(3, "bind to driver %s failed --> %d\n",
1840 DBG(3, "bind to driver %s failed --> %d\n", 1846 driver->driver.name, retval);
1841 driver->driver.name, retval); 1847 goto err1;
1842 musb->gadget_driver = NULL; 1848 }
1843 musb->g.dev.driver = NULL;
1844 }
1845 1849
1846 spin_lock_irqsave(&musb->lock, flags); 1850 spin_lock_irqsave(&musb->lock, flags);
1847 1851
1848 otg_set_peripheral(musb->xceiv, &musb->g); 1852 otg_set_peripheral(musb->xceiv, &musb->g);
1849 musb->xceiv->state = OTG_STATE_B_IDLE; 1853 musb->xceiv->state = OTG_STATE_B_IDLE;
1850 musb->is_active = 1; 1854 musb->is_active = 1;
1851 1855
1852 /* FIXME this ignores the softconnect flag. Drivers are 1856 /*
1853 * allowed hold the peripheral inactive until for example 1857 * FIXME this ignores the softconnect flag. Drivers are
1854 * userspace hooks up printer hardware or DSP codecs, so 1858 * allowed hold the peripheral inactive until for example
1855 * hosts only see fully functional devices. 1859 * userspace hooks up printer hardware or DSP codecs, so
1856 */ 1860 * hosts only see fully functional devices.
1861 */
1857 1862
1858 if (!is_otg_enabled(musb)) 1863 if (!is_otg_enabled(musb))
1859 musb_start(musb); 1864 musb_start(musb);
1860 1865
1861 otg_set_peripheral(musb->xceiv, &musb->g); 1866 otg_set_peripheral(musb->xceiv, &musb->g);
1862 1867
1863 spin_unlock_irqrestore(&musb->lock, flags); 1868 spin_unlock_irqrestore(&musb->lock, flags);
1864 1869
1865 if (is_otg_enabled(musb)) { 1870 if (is_otg_enabled(musb)) {
1866 struct usb_hcd *hcd = musb_to_hcd(musb); 1871 struct usb_hcd *hcd = musb_to_hcd(musb);
1867 1872
1868 DBG(3, "OTG startup...\n"); 1873 DBG(3, "OTG startup...\n");
1869 1874
1870 /* REVISIT: funcall to other code, which also 1875 /* REVISIT: funcall to other code, which also
1871 * handles power budgeting ... this way also 1876 * handles power budgeting ... this way also
1872 * ensures HdrcStart is indirectly called. 1877 * ensures HdrcStart is indirectly called.
1873 */ 1878 */
1874 retval = usb_add_hcd(musb_to_hcd(musb), -1, 0); 1879 retval = usb_add_hcd(musb_to_hcd(musb), -1, 0);
1875 if (retval < 0) { 1880 if (retval < 0) {
1876 DBG(1, "add_hcd failed, %d\n", retval); 1881 DBG(1, "add_hcd failed, %d\n", retval);
1877 spin_lock_irqsave(&musb->lock, flags); 1882 goto err2;
1878 otg_set_peripheral(musb->xceiv, NULL); 1883
1879 musb->gadget_driver = NULL; 1884 if ((musb->xceiv->last_event == USB_EVENT_ID)
1880 musb->g.dev.driver = NULL; 1885 && musb->xceiv->set_vbus)
1881 spin_unlock_irqrestore(&musb->lock, flags); 1886 otg_set_vbus(musb->xceiv, 1);
1882 } else {
1883 hcd->self.uses_pio_for_control = 1;
1884 }
1885 } 1887 }
1888
1889 hcd->self.uses_pio_for_control = 1;
1890
1891 if (musb->xceiv->last_event == USB_EVENT_NONE)
1892 pm_runtime_put(musb->controller);
1893
1886 } 1894 }
1887 1895
1896 return 0;
1897
1898err2:
1899 if (!is_otg_enabled(musb))
1900 musb_stop(musb);
1901
1902err1:
1903 musb->gadget_driver = NULL;
1904 musb->g.dev.driver = NULL;
1905
1906err0:
1888 return retval; 1907 return retval;
1889} 1908}
1890EXPORT_SYMBOL(usb_gadget_probe_driver); 1909EXPORT_SYMBOL(usb_gadget_probe_driver);
@@ -1939,14 +1958,20 @@ static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver)
1939 */ 1958 */
1940int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1959int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1941{ 1960{
1942 unsigned long flags;
1943 int retval = 0;
1944 struct musb *musb = the_gadget; 1961 struct musb *musb = the_gadget;
1962 unsigned long flags;
1945 1963
1946 if (!driver || !driver->unbind || !musb) 1964 if (!driver || !driver->unbind || !musb)
1947 return -EINVAL; 1965 return -EINVAL;
1948 1966
1949 /* REVISIT always use otg_set_peripheral() here too; 1967 if (!musb->gadget_driver)
1968 return -EINVAL;
1969
1970 if (musb->xceiv->last_event == USB_EVENT_NONE)
1971 pm_runtime_get_sync(musb->controller);
1972
1973 /*
1974 * REVISIT always use otg_set_peripheral() here too;
1950 * this needs to shut down the OTG engine. 1975 * this needs to shut down the OTG engine.
1951 */ 1976 */
1952 1977
@@ -1956,29 +1981,26 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1956 musb_hnp_stop(musb); 1981 musb_hnp_stop(musb);
1957#endif 1982#endif
1958 1983
1959 if (musb->gadget_driver == driver) { 1984 (void) musb_gadget_vbus_draw(&musb->g, 0);
1960 1985
1961 (void) musb_gadget_vbus_draw(&musb->g, 0); 1986 musb->xceiv->state = OTG_STATE_UNDEFINED;
1987 stop_activity(musb, driver);
1988 otg_set_peripheral(musb->xceiv, NULL);
1962 1989
1963 musb->xceiv->state = OTG_STATE_UNDEFINED; 1990 DBG(3, "unregistering driver %s\n", driver->function);
1964 stop_activity(musb, driver);
1965 otg_set_peripheral(musb->xceiv, NULL);
1966 1991
1967 DBG(3, "unregistering driver %s\n", driver->function); 1992 spin_unlock_irqrestore(&musb->lock, flags);
1968 spin_unlock_irqrestore(&musb->lock, flags); 1993 driver->unbind(&musb->g);
1969 driver->unbind(&musb->g); 1994 spin_lock_irqsave(&musb->lock, flags);
1970 spin_lock_irqsave(&musb->lock, flags);
1971 1995
1972 musb->gadget_driver = NULL; 1996 musb->gadget_driver = NULL;
1973 musb->g.dev.driver = NULL; 1997 musb->g.dev.driver = NULL;
1974 1998
1975 musb->is_active = 0; 1999 musb->is_active = 0;
1976 musb_platform_try_idle(musb, 0); 2000 musb_platform_try_idle(musb, 0);
1977 } else
1978 retval = -EINVAL;
1979 spin_unlock_irqrestore(&musb->lock, flags); 2001 spin_unlock_irqrestore(&musb->lock, flags);
1980 2002
1981 if (is_otg_enabled(musb) && retval == 0) { 2003 if (is_otg_enabled(musb)) {
1982 usb_remove_hcd(musb_to_hcd(musb)); 2004 usb_remove_hcd(musb_to_hcd(musb));
1983 /* FIXME we need to be able to register another 2005 /* FIXME we need to be able to register another
1984 * gadget driver here and have everything work; 2006 * gadget driver here and have everything work;
@@ -1986,7 +2008,12 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1986 */ 2008 */
1987 } 2009 }
1988 2010
1989 return retval; 2011 if (!is_otg_enabled(musb))
2012 musb_stop(musb);
2013
2014 pm_runtime_put(musb->controller);
2015
2016 return 0;
1990} 2017}
1991EXPORT_SYMBOL(usb_gadget_unregister_driver); 2018EXPORT_SYMBOL(usb_gadget_unregister_driver);
1992 2019
diff --git a/drivers/usb/musb/musb_gadget.h b/drivers/usb/musb/musb_gadget.h
index a55354fbccf5..66b7c5e0fb44 100644
--- a/drivers/usb/musb/musb_gadget.h
+++ b/drivers/usb/musb/musb_gadget.h
@@ -35,6 +35,8 @@
35#ifndef __MUSB_GADGET_H 35#ifndef __MUSB_GADGET_H
36#define __MUSB_GADGET_H 36#define __MUSB_GADGET_H
37 37
38#include <linux/list.h>
39
38enum buffer_map_state { 40enum buffer_map_state {
39 UN_MAPPED = 0, 41 UN_MAPPED = 0,
40 PRE_MAPPED, 42 PRE_MAPPED,
@@ -43,6 +45,7 @@ enum buffer_map_state {
43 45
44struct musb_request { 46struct musb_request {
45 struct usb_request request; 47 struct usb_request request;
48 struct list_head list;
46 struct musb_ep *ep; 49 struct musb_ep *ep;
47 struct musb *musb; 50 struct musb *musb;
48 u8 tx; /* endpoint direction */ 51 u8 tx; /* endpoint direction */
@@ -94,13 +97,13 @@ static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
94 return ep ? container_of(ep, struct musb_ep, end_point) : NULL; 97 return ep ? container_of(ep, struct musb_ep, end_point) : NULL;
95} 98}
96 99
97static inline struct usb_request *next_request(struct musb_ep *ep) 100static inline struct musb_request *next_request(struct musb_ep *ep)
98{ 101{
99 struct list_head *queue = &ep->req_list; 102 struct list_head *queue = &ep->req_list;
100 103
101 if (list_empty(queue)) 104 if (list_empty(queue))
102 return NULL; 105 return NULL;
103 return container_of(queue->next, struct usb_request, list); 106 return container_of(queue->next, struct musb_request, list);
104} 107}
105 108
106extern void musb_g_tx(struct musb *musb, u8 epnum); 109extern void musb_g_tx(struct musb *musb, u8 epnum);
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 6dd03f4c5f49..75a542e42fdf 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -304,8 +304,7 @@ __acquires(musb->lock)
304 } 304 }
305 305
306 /* Maybe start the first request in the queue */ 306 /* Maybe start the first request in the queue */
307 request = to_musb_request( 307 request = next_request(musb_ep);
308 next_request(musb_ep));
309 if (!musb_ep->busy && request) { 308 if (!musb_ep->busy && request) {
310 DBG(3, "restarting the request\n"); 309 DBG(3, "restarting the request\n");
311 musb_ep_restart(musb, request); 310 musb_ep_restart(musb, request);
@@ -491,10 +490,12 @@ stall:
491static void ep0_rxstate(struct musb *musb) 490static void ep0_rxstate(struct musb *musb)
492{ 491{
493 void __iomem *regs = musb->control_ep->regs; 492 void __iomem *regs = musb->control_ep->regs;
493 struct musb_request *request;
494 struct usb_request *req; 494 struct usb_request *req;
495 u16 count, csr; 495 u16 count, csr;
496 496
497 req = next_ep0_request(musb); 497 request = next_ep0_request(musb);
498 req = &request->request;
498 499
499 /* read packet and ack; or stall because of gadget driver bug: 500 /* read packet and ack; or stall because of gadget driver bug:
500 * should have provided the rx buffer before setup() returned. 501 * should have provided the rx buffer before setup() returned.
@@ -544,17 +545,20 @@ static void ep0_rxstate(struct musb *musb)
544static void ep0_txstate(struct musb *musb) 545static void ep0_txstate(struct musb *musb)
545{ 546{
546 void __iomem *regs = musb->control_ep->regs; 547 void __iomem *regs = musb->control_ep->regs;
547 struct usb_request *request = next_ep0_request(musb); 548 struct musb_request *req = next_ep0_request(musb);
549 struct usb_request *request;
548 u16 csr = MUSB_CSR0_TXPKTRDY; 550 u16 csr = MUSB_CSR0_TXPKTRDY;
549 u8 *fifo_src; 551 u8 *fifo_src;
550 u8 fifo_count; 552 u8 fifo_count;
551 553
552 if (!request) { 554 if (!req) {
553 /* WARN_ON(1); */ 555 /* WARN_ON(1); */
554 DBG(2, "odd; csr0 %04x\n", musb_readw(regs, MUSB_CSR0)); 556 DBG(2, "odd; csr0 %04x\n", musb_readw(regs, MUSB_CSR0));
555 return; 557 return;
556 } 558 }
557 559
560 request = &req->request;
561
558 /* load the data */ 562 /* load the data */
559 fifo_src = (u8 *) request->buf + request->actual; 563 fifo_src = (u8 *) request->buf + request->actual;
560 fifo_count = min((unsigned) MUSB_EP0_FIFOSIZE, 564 fifo_count = min((unsigned) MUSB_EP0_FIFOSIZE,
@@ -598,7 +602,7 @@ static void ep0_txstate(struct musb *musb)
598static void 602static void
599musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req) 603musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req)
600{ 604{
601 struct usb_request *r; 605 struct musb_request *r;
602 void __iomem *regs = musb->control_ep->regs; 606 void __iomem *regs = musb->control_ep->regs;
603 607
604 musb_read_fifo(&musb->endpoints[0], sizeof *req, (u8 *)req); 608 musb_read_fifo(&musb->endpoints[0], sizeof *req, (u8 *)req);
@@ -616,7 +620,7 @@ musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req)
616 /* clean up any leftover transfers */ 620 /* clean up any leftover transfers */
617 r = next_ep0_request(musb); 621 r = next_ep0_request(musb);
618 if (r) 622 if (r)
619 musb_g_ep0_giveback(musb, r); 623 musb_g_ep0_giveback(musb, &r->request);
620 624
621 /* For zero-data requests we want to delay the STATUS stage to 625 /* For zero-data requests we want to delay the STATUS stage to
622 * avoid SETUPEND errors. If we read data (OUT), delay accepting 626 * avoid SETUPEND errors. If we read data (OUT), delay accepting
@@ -758,11 +762,11 @@ irqreturn_t musb_g_ep0_irq(struct musb *musb)
758 case MUSB_EP0_STAGE_STATUSOUT: 762 case MUSB_EP0_STAGE_STATUSOUT:
759 /* end of sequence #1: write to host (TX state) */ 763 /* end of sequence #1: write to host (TX state) */
760 { 764 {
761 struct usb_request *req; 765 struct musb_request *req;
762 766
763 req = next_ep0_request(musb); 767 req = next_ep0_request(musb);
764 if (req) 768 if (req)
765 musb_g_ep0_giveback(musb, req); 769 musb_g_ep0_giveback(musb, &req->request);
766 } 770 }
767 771
768 /* 772 /*
@@ -961,7 +965,7 @@ musb_g_ep0_queue(struct usb_ep *e, struct usb_request *r, gfp_t gfp_flags)
961 } 965 }
962 966
963 /* add request to the list */ 967 /* add request to the list */
964 list_add_tail(&(req->request.list), &(ep->req_list)); 968 list_add_tail(&req->list, &ep->req_list);
965 969
966 DBG(3, "queue to %s (%s), length=%d\n", 970 DBG(3, "queue to %s (%s), length=%d\n",
967 ep->name, ep->is_in ? "IN/TX" : "OUT/RX", 971 ep->name, ep->is_in ? "IN/TX" : "OUT/RX",
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 0f523d7db57b..5eef4a8847db 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -1335,7 +1335,7 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1335 if (length > qh->maxpacket) 1335 if (length > qh->maxpacket)
1336 length = qh->maxpacket; 1336 length = qh->maxpacket;
1337 /* Unmap the buffer so that CPU can use it */ 1337 /* Unmap the buffer so that CPU can use it */
1338 unmap_urb_for_dma(musb_to_hcd(musb), urb); 1338 usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb);
1339 musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset); 1339 musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset);
1340 qh->segsize = length; 1340 qh->segsize = length;
1341 1341
@@ -1757,7 +1757,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1757 1757
1758 if (!dma) { 1758 if (!dma) {
1759 /* Unmap the buffer so that CPU can use it */ 1759 /* Unmap the buffer so that CPU can use it */
1760 unmap_urb_for_dma(musb_to_hcd(musb), urb); 1760 usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb);
1761 done = musb_host_packet_rx(musb, urb, 1761 done = musb_host_packet_rx(musb, urb,
1762 epnum, iso_err); 1762 epnum, iso_err);
1763 DBG(6, "read %spacket\n", done ? "last " : ""); 1763 DBG(6, "read %spacket\n", done ? "last " : "");
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index b46d1877e28e..489104a5ae14 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -305,8 +305,8 @@ int musb_hub_control(
305 desc->bHubContrCurrent = 0; 305 desc->bHubContrCurrent = 0;
306 306
307 /* workaround bogus struct definition */ 307 /* workaround bogus struct definition */
308 desc->DeviceRemovable[0] = 0x02; /* port 1 */ 308 desc->u.hs.DeviceRemovable[0] = 0x02; /* port 1 */
309 desc->DeviceRemovable[1] = 0xff; 309 desc->u.hs.DeviceRemovable[1] = 0xff;
310 } 310 }
311 break; 311 break;
312 case GetHubStatus: 312 case GetHubStatus:
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index bc8badd16897..25cb8b0003b1 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -33,6 +33,8 @@
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
36#include <linux/pm_runtime.h>
37#include <linux/err.h>
36 38
37#include "musb_core.h" 39#include "musb_core.h"
38#include "omap2430.h" 40#include "omap2430.h"
@@ -40,7 +42,6 @@
40struct omap2430_glue { 42struct omap2430_glue {
41 struct device *dev; 43 struct device *dev;
42 struct platform_device *musb; 44 struct platform_device *musb;
43 struct clk *clk;
44}; 45};
45#define glue_to_musb(g) platform_get_drvdata(g->musb) 46#define glue_to_musb(g) platform_get_drvdata(g->musb)
46 47
@@ -216,20 +217,12 @@ static inline void omap2430_low_level_exit(struct musb *musb)
216 l = musb_readl(musb->mregs, OTG_FORCESTDBY); 217 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
217 l |= ENABLEFORCE; /* enable MSTANDBY */ 218 l |= ENABLEFORCE; /* enable MSTANDBY */
218 musb_writel(musb->mregs, OTG_FORCESTDBY, l); 219 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
219
220 l = musb_readl(musb->mregs, OTG_SYSCONFIG);
221 l |= ENABLEWAKEUP; /* enable wakeup */
222 musb_writel(musb->mregs, OTG_SYSCONFIG, l);
223} 220}
224 221
225static inline void omap2430_low_level_init(struct musb *musb) 222static inline void omap2430_low_level_init(struct musb *musb)
226{ 223{
227 u32 l; 224 u32 l;
228 225
229 l = musb_readl(musb->mregs, OTG_SYSCONFIG);
230 l &= ~ENABLEWAKEUP; /* disable wakeup */
231 musb_writel(musb->mregs, OTG_SYSCONFIG, l);
232
233 l = musb_readl(musb->mregs, OTG_FORCESTDBY); 226 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
234 l &= ~ENABLEFORCE; /* disable MSTANDBY */ 227 l &= ~ENABLEFORCE; /* disable MSTANDBY */
235 musb_writel(musb->mregs, OTG_FORCESTDBY, l); 228 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
@@ -251,31 +244,39 @@ static int musb_otg_notifications(struct notifier_block *nb,
251 if (is_otg_enabled(musb)) { 244 if (is_otg_enabled(musb)) {
252#ifdef CONFIG_USB_GADGET_MUSB_HDRC 245#ifdef CONFIG_USB_GADGET_MUSB_HDRC
253 if (musb->gadget_driver) { 246 if (musb->gadget_driver) {
247 pm_runtime_get_sync(musb->controller);
254 otg_init(musb->xceiv); 248 otg_init(musb->xceiv);
255 249 omap2430_musb_set_vbus(musb, 1);
256 if (data->interface_type ==
257 MUSB_INTERFACE_UTMI)
258 omap2430_musb_set_vbus(musb, 1);
259
260 } 250 }
261#endif 251#endif
262 } else { 252 } else {
253 pm_runtime_get_sync(musb->controller);
263 otg_init(musb->xceiv); 254 otg_init(musb->xceiv);
264 if (data->interface_type == 255 omap2430_musb_set_vbus(musb, 1);
265 MUSB_INTERFACE_UTMI)
266 omap2430_musb_set_vbus(musb, 1);
267 } 256 }
268 break; 257 break;
269 258
270 case USB_EVENT_VBUS: 259 case USB_EVENT_VBUS:
271 DBG(4, "VBUS Connect\n"); 260 DBG(4, "VBUS Connect\n");
272 261
262 if (musb->gadget_driver)
263 pm_runtime_get_sync(musb->controller);
264
273 otg_init(musb->xceiv); 265 otg_init(musb->xceiv);
274 break; 266 break;
275 267
276 case USB_EVENT_NONE: 268 case USB_EVENT_NONE:
277 DBG(4, "VBUS Disconnect\n"); 269 DBG(4, "VBUS Disconnect\n");
278 270
271#ifdef CONFIG_USB_GADGET_MUSB_HDRC
272 if (is_otg_enabled(musb))
273 if (musb->gadget_driver)
274#endif
275 {
276 pm_runtime_mark_last_busy(musb->controller);
277 pm_runtime_put_autosuspend(musb->controller);
278 }
279
279 if (data->interface_type == MUSB_INTERFACE_UTMI) { 280 if (data->interface_type == MUSB_INTERFACE_UTMI) {
280 if (musb->xceiv->set_vbus) 281 if (musb->xceiv->set_vbus)
281 otg_set_vbus(musb->xceiv, 0); 282 otg_set_vbus(musb->xceiv, 0);
@@ -307,22 +308,11 @@ static int omap2430_musb_init(struct musb *musb)
307 return -ENODEV; 308 return -ENODEV;
308 } 309 }
309 310
310 omap2430_low_level_init(musb); 311 status = pm_runtime_get_sync(dev);
311 312 if (status < 0) {
312 l = musb_readl(musb->mregs, OTG_SYSCONFIG); 313 dev_err(dev, "pm_runtime_get_sync FAILED");
313 l &= ~ENABLEWAKEUP; /* disable wakeup */ 314 goto err1;
314 l &= ~NOSTDBY; /* remove possible nostdby */ 315 }
315 l |= SMARTSTDBY; /* enable smart standby */
316 l &= ~AUTOIDLE; /* disable auto idle */
317 l &= ~NOIDLE; /* remove possible noidle */
318 l |= SMARTIDLE; /* enable smart idle */
319 /*
320 * MUSB AUTOIDLE don't work in 3430.
321 * Workaround by Richard Woodruff/TI
322 */
323 if (!cpu_is_omap3430())
324 l |= AUTOIDLE; /* enable auto idle */
325 musb_writel(musb->mregs, OTG_SYSCONFIG, l);
326 316
327 l = musb_readl(musb->mregs, OTG_INTERFSEL); 317 l = musb_readl(musb->mregs, OTG_INTERFSEL);
328 318
@@ -350,14 +340,58 @@ static int omap2430_musb_init(struct musb *musb)
350 if (status) 340 if (status)
351 DBG(1, "notification register failed\n"); 341 DBG(1, "notification register failed\n");
352 342
353 /* check whether cable is already connected */
354 if (musb->xceiv->state ==OTG_STATE_B_IDLE)
355 musb_otg_notifications(&musb->nb, 1,
356 musb->xceiv->gadget);
357
358 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 343 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
359 344
360 return 0; 345 return 0;
346
347err1:
348 pm_runtime_disable(dev);
349 return status;
350}
351
352static void omap2430_musb_enable(struct musb *musb)
353{
354 u8 devctl;
355 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
356 struct device *dev = musb->controller;
357 struct musb_hdrc_platform_data *pdata = dev->platform_data;
358 struct omap_musb_board_data *data = pdata->board_data;
359
360 switch (musb->xceiv->last_event) {
361
362 case USB_EVENT_ID:
363 otg_init(musb->xceiv);
364 if (data->interface_type == MUSB_INTERFACE_UTMI) {
365 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
366 /* start the session */
367 devctl |= MUSB_DEVCTL_SESSION;
368 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
369 while (musb_readb(musb->mregs, MUSB_DEVCTL) &
370 MUSB_DEVCTL_BDEVICE) {
371 cpu_relax();
372
373 if (time_after(jiffies, timeout)) {
374 dev_err(musb->controller,
375 "configured as A device timeout");
376 break;
377 }
378 }
379 }
380 break;
381
382 case USB_EVENT_VBUS:
383 otg_init(musb->xceiv);
384 break;
385
386 default:
387 break;
388 }
389}
390
391static void omap2430_musb_disable(struct musb *musb)
392{
393 if (musb->xceiv->last_event)
394 otg_shutdown(musb->xceiv);
361} 395}
362 396
363static int omap2430_musb_exit(struct musb *musb) 397static int omap2430_musb_exit(struct musb *musb)
@@ -378,6 +412,9 @@ static const struct musb_platform_ops omap2430_ops = {
378 .try_idle = omap2430_musb_try_idle, 412 .try_idle = omap2430_musb_try_idle,
379 413
380 .set_vbus = omap2430_musb_set_vbus, 414 .set_vbus = omap2430_musb_set_vbus,
415
416 .enable = omap2430_musb_enable,
417 .disable = omap2430_musb_disable,
381}; 418};
382 419
383static u64 omap2430_dmamask = DMA_BIT_MASK(32); 420static u64 omap2430_dmamask = DMA_BIT_MASK(32);
@@ -387,8 +424,6 @@ static int __init omap2430_probe(struct platform_device *pdev)
387 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 424 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
388 struct platform_device *musb; 425 struct platform_device *musb;
389 struct omap2430_glue *glue; 426 struct omap2430_glue *glue;
390 struct clk *clk;
391
392 int ret = -ENOMEM; 427 int ret = -ENOMEM;
393 428
394 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 429 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
@@ -403,26 +438,12 @@ static int __init omap2430_probe(struct platform_device *pdev)
403 goto err1; 438 goto err1;
404 } 439 }
405 440
406 clk = clk_get(&pdev->dev, "ick");
407 if (IS_ERR(clk)) {
408 dev_err(&pdev->dev, "failed to get clock\n");
409 ret = PTR_ERR(clk);
410 goto err2;
411 }
412
413 ret = clk_enable(clk);
414 if (ret) {
415 dev_err(&pdev->dev, "failed to enable clock\n");
416 goto err3;
417 }
418
419 musb->dev.parent = &pdev->dev; 441 musb->dev.parent = &pdev->dev;
420 musb->dev.dma_mask = &omap2430_dmamask; 442 musb->dev.dma_mask = &omap2430_dmamask;
421 musb->dev.coherent_dma_mask = omap2430_dmamask; 443 musb->dev.coherent_dma_mask = omap2430_dmamask;
422 444
423 glue->dev = &pdev->dev; 445 glue->dev = &pdev->dev;
424 glue->musb = musb; 446 glue->musb = musb;
425 glue->clk = clk;
426 447
427 pdata->platform_ops = &omap2430_ops; 448 pdata->platform_ops = &omap2430_ops;
428 449
@@ -432,28 +453,24 @@ static int __init omap2430_probe(struct platform_device *pdev)
432 pdev->num_resources); 453 pdev->num_resources);
433 if (ret) { 454 if (ret) {
434 dev_err(&pdev->dev, "failed to add resources\n"); 455 dev_err(&pdev->dev, "failed to add resources\n");
435 goto err4; 456 goto err2;
436 } 457 }
437 458
438 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 459 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
439 if (ret) { 460 if (ret) {
440 dev_err(&pdev->dev, "failed to add platform_data\n"); 461 dev_err(&pdev->dev, "failed to add platform_data\n");
441 goto err4; 462 goto err2;
442 } 463 }
443 464
444 ret = platform_device_add(musb); 465 ret = platform_device_add(musb);
445 if (ret) { 466 if (ret) {
446 dev_err(&pdev->dev, "failed to register musb device\n"); 467 dev_err(&pdev->dev, "failed to register musb device\n");
447 goto err4; 468 goto err2;
448 } 469 }
449 470
450 return 0; 471 pm_runtime_enable(&pdev->dev);
451
452err4:
453 clk_disable(clk);
454 472
455err3: 473 return 0;
456 clk_put(clk);
457 474
458err2: 475err2:
459 platform_device_put(musb); 476 platform_device_put(musb);
@@ -471,61 +488,40 @@ static int __exit omap2430_remove(struct platform_device *pdev)
471 488
472 platform_device_del(glue->musb); 489 platform_device_del(glue->musb);
473 platform_device_put(glue->musb); 490 platform_device_put(glue->musb);
474 clk_disable(glue->clk); 491 pm_runtime_put(&pdev->dev);
475 clk_put(glue->clk); 492 pm_runtime_disable(&pdev->dev);
476 kfree(glue); 493 kfree(glue);
477 494
478 return 0; 495 return 0;
479} 496}
480 497
481#ifdef CONFIG_PM 498#ifdef CONFIG_PM
482static void omap2430_save_context(struct musb *musb)
483{
484 musb->context.otg_sysconfig = musb_readl(musb->mregs, OTG_SYSCONFIG);
485 musb->context.otg_forcestandby = musb_readl(musb->mregs, OTG_FORCESTDBY);
486}
487 499
488static void omap2430_restore_context(struct musb *musb) 500static int omap2430_runtime_suspend(struct device *dev)
489{
490 musb_writel(musb->mregs, OTG_SYSCONFIG, musb->context.otg_sysconfig);
491 musb_writel(musb->mregs, OTG_FORCESTDBY, musb->context.otg_forcestandby);
492}
493
494static int omap2430_suspend(struct device *dev)
495{ 501{
496 struct omap2430_glue *glue = dev_get_drvdata(dev); 502 struct omap2430_glue *glue = dev_get_drvdata(dev);
497 struct musb *musb = glue_to_musb(glue); 503 struct musb *musb = glue_to_musb(glue);
498 504
499 omap2430_low_level_exit(musb); 505 omap2430_low_level_exit(musb);
500 otg_set_suspend(musb->xceiv, 1); 506 otg_set_suspend(musb->xceiv, 1);
501 omap2430_save_context(musb);
502 clk_disable(glue->clk);
503 507
504 return 0; 508 return 0;
505} 509}
506 510
507static int omap2430_resume(struct device *dev) 511static int omap2430_runtime_resume(struct device *dev)
508{ 512{
509 struct omap2430_glue *glue = dev_get_drvdata(dev); 513 struct omap2430_glue *glue = dev_get_drvdata(dev);
510 struct musb *musb = glue_to_musb(glue); 514 struct musb *musb = glue_to_musb(glue);
511 int ret;
512
513 ret = clk_enable(glue->clk);
514 if (ret) {
515 dev_err(dev, "faled to enable clock\n");
516 return ret;
517 }
518 515
519 omap2430_low_level_init(musb); 516 omap2430_low_level_init(musb);
520 omap2430_restore_context(musb);
521 otg_set_suspend(musb->xceiv, 0); 517 otg_set_suspend(musb->xceiv, 0);
522 518
523 return 0; 519 return 0;
524} 520}
525 521
526static struct dev_pm_ops omap2430_pm_ops = { 522static struct dev_pm_ops omap2430_pm_ops = {
527 .suspend = omap2430_suspend, 523 .runtime_suspend = omap2430_runtime_suspend,
528 .resume = omap2430_resume, 524 .runtime_resume = omap2430_runtime_resume,
529}; 525};
530 526
531#define DEV_PM_OPS (&omap2430_pm_ops) 527#define DEV_PM_OPS (&omap2430_pm_ops)
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c
index c061a88f2b0f..99cb541e4ef0 100644
--- a/drivers/usb/musb/tusb6010_omap.c
+++ b/drivers/usb/musb/tusb6010_omap.c
@@ -680,7 +680,7 @@ dma_controller_create(struct musb *musb, void __iomem *base)
680 680
681 tusb_dma = kzalloc(sizeof(struct tusb_omap_dma), GFP_KERNEL); 681 tusb_dma = kzalloc(sizeof(struct tusb_omap_dma), GFP_KERNEL);
682 if (!tusb_dma) 682 if (!tusb_dma)
683 goto cleanup; 683 goto out;
684 684
685 tusb_dma->musb = musb; 685 tusb_dma->musb = musb;
686 tusb_dma->tbase = musb->ctrl_base; 686 tusb_dma->tbase = musb->ctrl_base;
@@ -721,6 +721,6 @@ dma_controller_create(struct musb *musb, void __iomem *base)
721 721
722cleanup: 722cleanup:
723 dma_controller_destroy(&tusb_dma->controller); 723 dma_controller_destroy(&tusb_dma->controller);
724 724out:
725 return NULL; 725 return NULL;
726} 726}
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 9ffc8237fb4b..daf3e5f1a0e7 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -49,6 +49,13 @@ config USB_ULPI
49 Enable this to support ULPI connected USB OTG transceivers which 49 Enable this to support ULPI connected USB OTG transceivers which
50 are likely found on embedded boards. 50 are likely found on embedded boards.
51 51
52config USB_ULPI_VIEWPORT
53 bool
54 depends on USB_ULPI
55 help
56 Provides read/write operations to the ULPI phy register set for
57 controllers with a viewport register (e.g. Chipidea/ARC controllers).
58
52config TWL4030_USB 59config TWL4030_USB
53 tristate "TWL4030 USB Transceiver Driver" 60 tristate "TWL4030 USB Transceiver Driver"
54 depends on TWL4030_CORE && REGULATOR_TWL4030 61 depends on TWL4030_CORE && REGULATOR_TWL4030
@@ -93,7 +100,7 @@ config USB_LANGWELL_OTG
93 To compile this driver as a module, choose M here: the 100 To compile this driver as a module, choose M here: the
94 module will be called langwell_otg. 101 module will be called langwell_otg.
95 102
96config USB_MSM_OTG_72K 103config USB_MSM_OTG
97 tristate "OTG support for Qualcomm on-chip USB controller" 104 tristate "OTG support for Qualcomm on-chip USB controller"
98 depends on (USB || USB_GADGET) && ARCH_MSM 105 depends on (USB || USB_GADGET) && ARCH_MSM
99 select USB_OTG_UTILS 106 select USB_OTG_UTILS
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index a520e715cfd6..e22d917de017 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -16,5 +16,6 @@ obj-$(CONFIG_TWL6030_USB) += twl6030-usb.o
16obj-$(CONFIG_USB_LANGWELL_OTG) += langwell_otg.o 16obj-$(CONFIG_USB_LANGWELL_OTG) += langwell_otg.o
17obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o 17obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o
18obj-$(CONFIG_USB_ULPI) += ulpi.o 18obj-$(CONFIG_USB_ULPI) += ulpi.o
19obj-$(CONFIG_USB_MSM_OTG_72K) += msm72k_otg.o 19obj-$(CONFIG_USB_ULPI_VIEWPORT) += ulpi_viewport.o
20obj-$(CONFIG_USB_MSM_OTG) += msm_otg.o
20obj-$(CONFIG_AB8500_USB) += ab8500-usb.o 21obj-$(CONFIG_AB8500_USB) += ab8500-usb.o
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c
index d14736b3107b..07ccea9ada40 100644
--- a/drivers/usb/otg/ab8500-usb.c
+++ b/drivers/usb/otg/ab8500-usb.c
@@ -212,7 +212,7 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab)
212 break; 212 break;
213 } 213 }
214 214
215 blocking_notifier_call_chain(&ab->otg.notifier, event, v); 215 atomic_notifier_call_chain(&ab->otg.notifier, event, v);
216 216
217 return 0; 217 return 0;
218} 218}
@@ -281,7 +281,7 @@ static int ab8500_usb_set_power(struct otg_transceiver *otg, unsigned mA)
281 ab->vbus_draw = mA; 281 ab->vbus_draw = mA;
282 282
283 if (mA) 283 if (mA)
284 blocking_notifier_call_chain(&ab->otg.notifier, 284 atomic_notifier_call_chain(&ab->otg.notifier,
285 USB_EVENT_ENUMERATED, ab->otg.gadget); 285 USB_EVENT_ENUMERATED, ab->otg.gadget);
286 return 0; 286 return 0;
287} 287}
@@ -500,7 +500,7 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev)
500 500
501 platform_set_drvdata(pdev, ab); 501 platform_set_drvdata(pdev, ab);
502 502
503 BLOCKING_INIT_NOTIFIER_HEAD(&ab->otg.notifier); 503 ATOMIC_INIT_NOTIFIER_HEAD(&ab->otg.notifier);
504 504
505 /* v1: Wait for link status to become stable. 505 /* v1: Wait for link status to become stable.
506 * all: Updates form set_host and set_peripheral as they are atomic. 506 * all: Updates form set_host and set_peripheral as they are atomic.
diff --git a/drivers/usb/otg/langwell_otg.c b/drivers/usb/otg/langwell_otg.c
index 9fea48264fa2..7f9b8cd4514b 100644
--- a/drivers/usb/otg/langwell_otg.c
+++ b/drivers/usb/otg/langwell_otg.c
@@ -174,50 +174,24 @@ static int langwell_otg_set_power(struct otg_transceiver *otg,
174 return 0; 174 return 0;
175} 175}
176 176
177/* A-device drives vbus, controlled through PMIC CHRGCNTL register*/ 177/* A-device drives vbus, controlled through IPC commands */
178static int langwell_otg_set_vbus(struct otg_transceiver *otg, bool enabled) 178static int langwell_otg_set_vbus(struct otg_transceiver *otg, bool enabled)
179{ 179{
180 struct langwell_otg *lnw = the_transceiver; 180 struct langwell_otg *lnw = the_transceiver;
181 u8 r; 181 u8 sub_id;
182 182
183 dev_dbg(lnw->dev, "%s <--- %s\n", __func__, enabled ? "on" : "off"); 183 dev_dbg(lnw->dev, "%s <--- %s\n", __func__, enabled ? "on" : "off");
184 184
185 /* FIXME: surely we should cache this on the first read. If not use 185 if (enabled)
186 readv to avoid two transactions */ 186 sub_id = 0x8; /* Turn on the VBus */
187 if (intel_scu_ipc_ioread8(0x00, &r) < 0) { 187 else
188 dev_dbg(lnw->dev, "Failed to read PMIC register 0xD2"); 188 sub_id = 0x9; /* Turn off the VBus */
189 return -EBUSY;
190 }
191 if ((r & 0x03) != 0x02) {
192 dev_dbg(lnw->dev, "not NEC PMIC attached\n");
193 return -EBUSY;
194 }
195
196 if (intel_scu_ipc_ioread8(0x20, &r) < 0) {
197 dev_dbg(lnw->dev, "Failed to read PMIC register 0xD2");
198 return -EBUSY;
199 }
200
201 if ((r & 0x20) == 0) {
202 dev_dbg(lnw->dev, "no battery attached\n");
203 return -EBUSY;
204 }
205 189
206 /* Workaround for battery attachment issue */ 190 if (intel_scu_ipc_simple_command(0xef, sub_id)) {
207 if (r == 0x34) { 191 dev_dbg(lnw->dev, "Failed to set Vbus via IPC commands\n");
208 dev_dbg(lnw->dev, "no battery attached on SH\n");
209 return -EBUSY; 192 return -EBUSY;
210 } 193 }
211 194
212 dev_dbg(lnw->dev, "battery attached. 2 reg = %x\n", r);
213
214 /* workaround: FW detect writing 0x20/0xc0 to d4 event.
215 * this is only for NEC PMIC.
216 */
217
218 if (intel_scu_ipc_iowrite8(0xD4, enabled ? 0x20 : 0xC0))
219 dev_dbg(lnw->dev, "Failed to write PMIC.\n");
220
221 dev_dbg(lnw->dev, "%s --->\n", __func__); 195 dev_dbg(lnw->dev, "%s --->\n", __func__);
222 196
223 return 0; 197 return 0;
@@ -394,14 +368,14 @@ static void langwell_otg_phy_low_power(int on)
394 dev_dbg(lnw->dev, "%s <--- done\n", __func__); 368 dev_dbg(lnw->dev, "%s <--- done\n", __func__);
395} 369}
396 370
397/* After drv vbus, add 2 ms delay to set PHCD */ 371/* After drv vbus, add 5 ms delay to set PHCD */
398static void langwell_otg_phy_low_power_wait(int on) 372static void langwell_otg_phy_low_power_wait(int on)
399{ 373{
400 struct langwell_otg *lnw = the_transceiver; 374 struct langwell_otg *lnw = the_transceiver;
401 375
402 dev_dbg(lnw->dev, "add 2ms delay before programing PHCD\n"); 376 dev_dbg(lnw->dev, "add 5ms delay before programing PHCD\n");
403 377
404 mdelay(2); 378 mdelay(5);
405 langwell_otg_phy_low_power(on); 379 langwell_otg_phy_low_power(on);
406} 380}
407 381
diff --git a/drivers/usb/otg/msm72k_otg.c b/drivers/usb/otg/msm_otg.c
index 1cd52edcd0c2..296598628b85 100644
--- a/drivers/usb/otg/msm72k_otg.c
+++ b/drivers/usb/otg/msm_otg.c
@@ -253,6 +253,9 @@ static int msm_otg_reset(struct otg_transceiver *otg)
253} 253}
254 254
255#define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) 255#define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000)
256#define PHY_RESUME_TIMEOUT_USEC (100 * 1000)
257
258#ifdef CONFIG_PM_SLEEP
256static int msm_otg_suspend(struct msm_otg *motg) 259static int msm_otg_suspend(struct msm_otg *motg)
257{ 260{
258 struct otg_transceiver *otg = &motg->otg; 261 struct otg_transceiver *otg = &motg->otg;
@@ -334,7 +337,6 @@ static int msm_otg_suspend(struct msm_otg *motg)
334 return 0; 337 return 0;
335} 338}
336 339
337#define PHY_RESUME_TIMEOUT_USEC (100 * 1000)
338static int msm_otg_resume(struct msm_otg *motg) 340static int msm_otg_resume(struct msm_otg *motg)
339{ 341{
340 struct otg_transceiver *otg = &motg->otg; 342 struct otg_transceiver *otg = &motg->otg;
@@ -399,6 +401,7 @@ skip_phy_resume:
399 401
400 return 0; 402 return 0;
401} 403}
404#endif
402 405
403static void msm_otg_start_host(struct otg_transceiver *otg, int on) 406static void msm_otg_start_host(struct otg_transceiver *otg, int on)
404{ 407{
@@ -720,7 +723,8 @@ static int msm_otg_mode_open(struct inode *inode, struct file *file)
720static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, 723static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf,
721 size_t count, loff_t *ppos) 724 size_t count, loff_t *ppos)
722{ 725{
723 struct msm_otg *motg = file->private_data; 726 struct seq_file *s = file->private_data;
727 struct msm_otg *motg = s->private;
724 char buf[16]; 728 char buf[16];
725 struct otg_transceiver *otg = &motg->otg; 729 struct otg_transceiver *otg = &motg->otg;
726 int status = count; 730 int status = count;
@@ -972,7 +976,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev)
972 msm_otg_debugfs_cleanup(); 976 msm_otg_debugfs_cleanup();
973 cancel_work_sync(&motg->sm_work); 977 cancel_work_sync(&motg->sm_work);
974 978
975 msm_otg_resume(motg); 979 pm_runtime_resume(&pdev->dev);
976 980
977 device_init_wakeup(&pdev->dev, 0); 981 device_init_wakeup(&pdev->dev, 0);
978 pm_runtime_disable(&pdev->dev); 982 pm_runtime_disable(&pdev->dev);
@@ -1050,13 +1054,9 @@ static int msm_otg_runtime_resume(struct device *dev)
1050 dev_dbg(dev, "OTG runtime resume\n"); 1054 dev_dbg(dev, "OTG runtime resume\n");
1051 return msm_otg_resume(motg); 1055 return msm_otg_resume(motg);
1052} 1056}
1053#else
1054#define msm_otg_runtime_idle NULL
1055#define msm_otg_runtime_suspend NULL
1056#define msm_otg_runtime_resume NULL
1057#endif 1057#endif
1058 1058
1059#ifdef CONFIG_PM 1059#ifdef CONFIG_PM_SLEEP
1060static int msm_otg_pm_suspend(struct device *dev) 1060static int msm_otg_pm_suspend(struct device *dev)
1061{ 1061{
1062 struct msm_otg *motg = dev_get_drvdata(dev); 1062 struct msm_otg *motg = dev_get_drvdata(dev);
@@ -1086,25 +1086,24 @@ static int msm_otg_pm_resume(struct device *dev)
1086 1086
1087 return 0; 1087 return 0;
1088} 1088}
1089#else
1090#define msm_otg_pm_suspend NULL
1091#define msm_otg_pm_resume NULL
1092#endif 1089#endif
1093 1090
1091#ifdef CONFIG_PM
1094static const struct dev_pm_ops msm_otg_dev_pm_ops = { 1092static const struct dev_pm_ops msm_otg_dev_pm_ops = {
1095 .runtime_suspend = msm_otg_runtime_suspend, 1093 SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume)
1096 .runtime_resume = msm_otg_runtime_resume, 1094 SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume,
1097 .runtime_idle = msm_otg_runtime_idle, 1095 msm_otg_runtime_idle)
1098 .suspend = msm_otg_pm_suspend,
1099 .resume = msm_otg_pm_resume,
1100}; 1096};
1097#endif
1101 1098
1102static struct platform_driver msm_otg_driver = { 1099static struct platform_driver msm_otg_driver = {
1103 .remove = __devexit_p(msm_otg_remove), 1100 .remove = __devexit_p(msm_otg_remove),
1104 .driver = { 1101 .driver = {
1105 .name = DRIVER_NAME, 1102 .name = DRIVER_NAME,
1106 .owner = THIS_MODULE, 1103 .owner = THIS_MODULE,
1104#ifdef CONFIG_PM
1107 .pm = &msm_otg_dev_pm_ops, 1105 .pm = &msm_otg_dev_pm_ops,
1106#endif
1108 }, 1107 },
1109}; 1108};
1110 1109
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
index 8acf165fe13b..c1e360046435 100644
--- a/drivers/usb/otg/nop-usb-xceiv.c
+++ b/drivers/usb/otg/nop-usb-xceiv.c
@@ -132,7 +132,7 @@ static int __devinit nop_usb_xceiv_probe(struct platform_device *pdev)
132 132
133 platform_set_drvdata(pdev, nop); 133 platform_set_drvdata(pdev, nop);
134 134
135 BLOCKING_INIT_NOTIFIER_HEAD(&nop->otg.notifier); 135 ATOMIC_INIT_NOTIFIER_HEAD(&nop->otg.notifier);
136 136
137 return 0; 137 return 0;
138exit: 138exit:
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index 6ca505f333e4..e01b073cc489 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -275,6 +275,8 @@ static enum usb_xceiv_events twl4030_usb_linkstat(struct twl4030_usb *twl)
275 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", 275 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
276 status, status, linkstat); 276 status, status, linkstat);
277 277
278 twl->otg.last_event = linkstat;
279
278 /* REVISIT this assumes host and peripheral controllers 280 /* REVISIT this assumes host and peripheral controllers
279 * are registered, and that both are active... 281 * are registered, and that both are active...
280 */ 282 */
@@ -512,7 +514,7 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
512 else 514 else
513 twl4030_phy_resume(twl); 515 twl4030_phy_resume(twl);
514 516
515 blocking_notifier_call_chain(&twl->otg.notifier, status, 517 atomic_notifier_call_chain(&twl->otg.notifier, status,
516 twl->otg.gadget); 518 twl->otg.gadget);
517 } 519 }
518 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 520 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
@@ -534,7 +536,7 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl)
534 twl->asleep = 0; 536 twl->asleep = 0;
535 } 537 }
536 538
537 blocking_notifier_call_chain(&twl->otg.notifier, status, 539 atomic_notifier_call_chain(&twl->otg.notifier, status,
538 twl->otg.gadget); 540 twl->otg.gadget);
539 } 541 }
540 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 542 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
@@ -623,7 +625,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
623 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 625 if (device_create_file(&pdev->dev, &dev_attr_vbus))
624 dev_warn(&pdev->dev, "could not create sysfs file\n"); 626 dev_warn(&pdev->dev, "could not create sysfs file\n");
625 627
626 BLOCKING_INIT_NOTIFIER_HEAD(&twl->otg.notifier); 628 ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier);
627 629
628 /* Our job is to use irqs and status from the power module 630 /* Our job is to use irqs and status from the power module
629 * to keep the transceiver disabled when nothing's connected. 631 * to keep the transceiver disabled when nothing's connected.
diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/otg/twl6030-usb.c
index 28f770103640..8a91b4b832a1 100644
--- a/drivers/usb/otg/twl6030-usb.c
+++ b/drivers/usb/otg/twl6030-usb.c
@@ -149,7 +149,6 @@ static int twl6030_set_phy_clk(struct otg_transceiver *x, int on)
149 149
150static int twl6030_phy_init(struct otg_transceiver *x) 150static int twl6030_phy_init(struct otg_transceiver *x)
151{ 151{
152 u8 hw_state;
153 struct twl6030_usb *twl; 152 struct twl6030_usb *twl;
154 struct device *dev; 153 struct device *dev;
155 struct twl4030_usb_data *pdata; 154 struct twl4030_usb_data *pdata;
@@ -158,11 +157,7 @@ static int twl6030_phy_init(struct otg_transceiver *x)
158 dev = twl->dev; 157 dev = twl->dev;
159 pdata = dev->platform_data; 158 pdata = dev->platform_data;
160 159
161 regulator_enable(twl->usb3v3); 160 if (twl->linkstat == USB_EVENT_ID)
162
163 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
164
165 if (hw_state & STS_USB_ID)
166 pdata->phy_power(twl->dev, 1, 1); 161 pdata->phy_power(twl->dev, 1, 1);
167 else 162 else
168 pdata->phy_power(twl->dev, 0, 1); 163 pdata->phy_power(twl->dev, 0, 1);
@@ -180,7 +175,17 @@ static void twl6030_phy_shutdown(struct otg_transceiver *x)
180 dev = twl->dev; 175 dev = twl->dev;
181 pdata = dev->platform_data; 176 pdata = dev->platform_data;
182 pdata->phy_power(twl->dev, 0, 0); 177 pdata->phy_power(twl->dev, 0, 0);
183 regulator_disable(twl->usb3v3); 178}
179
180static int twl6030_phy_suspend(struct otg_transceiver *x, int suspend)
181{
182 struct twl6030_usb *twl = xceiv_to_twl(x);
183 struct device *dev = twl->dev;
184 struct twl4030_usb_data *pdata = dev->platform_data;
185
186 pdata->phy_suspend(dev, suspend);
187
188 return 0;
184} 189}
185 190
186static int twl6030_usb_ldo_init(struct twl6030_usb *twl) 191static int twl6030_usb_ldo_init(struct twl6030_usb *twl)
@@ -199,16 +204,6 @@ static int twl6030_usb_ldo_init(struct twl6030_usb *twl)
199 if (IS_ERR(twl->usb3v3)) 204 if (IS_ERR(twl->usb3v3))
200 return -ENODEV; 205 return -ENODEV;
201 206
202 regulator_enable(twl->usb3v3);
203
204 /* Program the VUSB_CFG_TRANS for ACTIVE state. */
205 twl6030_writeb(twl, TWL_MODULE_PM_RECEIVER, 0x3F,
206 VUSB_CFG_TRANS);
207
208 /* Program the VUSB_CFG_STATE register to ON on all groups. */
209 twl6030_writeb(twl, TWL_MODULE_PM_RECEIVER, 0xE1,
210 VUSB_CFG_STATE);
211
212 /* Program the USB_VBUS_CTRL_SET and set VBUS_ACT_COMP bit */ 207 /* Program the USB_VBUS_CTRL_SET and set VBUS_ACT_COMP bit */
213 twl6030_writeb(twl, TWL_MODULE_USB, 0x4, USB_VBUS_CTRL_SET); 208 twl6030_writeb(twl, TWL_MODULE_USB, 0x4, USB_VBUS_CTRL_SET);
214 209
@@ -261,16 +256,25 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
261 CONTROLLER_STAT1); 256 CONTROLLER_STAT1);
262 if (!(hw_state & STS_USB_ID)) { 257 if (!(hw_state & STS_USB_ID)) {
263 if (vbus_state & VBUS_DET) { 258 if (vbus_state & VBUS_DET) {
259 regulator_enable(twl->usb3v3);
260 twl->asleep = 1;
264 status = USB_EVENT_VBUS; 261 status = USB_EVENT_VBUS;
265 twl->otg.default_a = false; 262 twl->otg.default_a = false;
266 twl->otg.state = OTG_STATE_B_IDLE; 263 twl->otg.state = OTG_STATE_B_IDLE;
264 twl->linkstat = status;
265 twl->otg.last_event = status;
266 atomic_notifier_call_chain(&twl->otg.notifier,
267 status, twl->otg.gadget);
267 } else { 268 } else {
268 status = USB_EVENT_NONE; 269 status = USB_EVENT_NONE;
269 }
270 if (status >= 0) {
271 twl->linkstat = status; 270 twl->linkstat = status;
272 blocking_notifier_call_chain(&twl->otg.notifier, 271 twl->otg.last_event = status;
272 atomic_notifier_call_chain(&twl->otg.notifier,
273 status, twl->otg.gadget); 273 status, twl->otg.gadget);
274 if (twl->asleep) {
275 regulator_disable(twl->usb3v3);
276 twl->asleep = 0;
277 }
274 } 278 }
275 } 279 }
276 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 280 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
@@ -288,13 +292,17 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
288 292
289 if (hw_state & STS_USB_ID) { 293 if (hw_state & STS_USB_ID) {
290 294
295 regulator_enable(twl->usb3v3);
296 twl->asleep = 1;
291 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR, 0x1); 297 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR, 0x1);
292 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET, 298 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET,
293 0x10); 299 0x10);
294 status = USB_EVENT_ID; 300 status = USB_EVENT_ID;
295 twl->otg.default_a = true; 301 twl->otg.default_a = true;
296 twl->otg.state = OTG_STATE_A_IDLE; 302 twl->otg.state = OTG_STATE_A_IDLE;
297 blocking_notifier_call_chain(&twl->otg.notifier, status, 303 twl->linkstat = status;
304 twl->otg.last_event = status;
305 atomic_notifier_call_chain(&twl->otg.notifier, status,
298 twl->otg.gadget); 306 twl->otg.gadget);
299 } else { 307 } else {
300 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR, 308 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR,
@@ -303,7 +311,6 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
303 0x1); 311 0x1);
304 } 312 }
305 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_LATCH_CLR, status); 313 twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_LATCH_CLR, status);
306 twl->linkstat = status;
307 314
308 return IRQ_HANDLED; 315 return IRQ_HANDLED;
309} 316}
@@ -395,6 +402,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
395 twl->otg.set_vbus = twl6030_set_vbus; 402 twl->otg.set_vbus = twl6030_set_vbus;
396 twl->otg.init = twl6030_phy_init; 403 twl->otg.init = twl6030_phy_init;
397 twl->otg.shutdown = twl6030_phy_shutdown; 404 twl->otg.shutdown = twl6030_phy_shutdown;
405 twl->otg.set_suspend = twl6030_phy_suspend;
398 406
399 /* init spinlock for workqueue */ 407 /* init spinlock for workqueue */
400 spin_lock_init(&twl->lock); 408 spin_lock_init(&twl->lock);
@@ -411,7 +419,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
411 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 419 if (device_create_file(&pdev->dev, &dev_attr_vbus))
412 dev_warn(&pdev->dev, "could not create sysfs file\n"); 420 dev_warn(&pdev->dev, "could not create sysfs file\n");
413 421
414 BLOCKING_INIT_NOTIFIER_HEAD(&twl->otg.notifier); 422 ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier);
415 423
416 twl->irq_enabled = true; 424 twl->irq_enabled = true;
417 status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq, 425 status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq,
@@ -437,7 +445,9 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
437 return status; 445 return status;
438 } 446 }
439 447
448 twl->asleep = 0;
440 pdata->phy_init(dev); 449 pdata->phy_init(dev);
450 twl6030_phy_suspend(&twl->otg, 0);
441 twl6030_enable_irq(&twl->otg); 451 twl6030_enable_irq(&twl->otg);
442 dev_info(&pdev->dev, "Initialized TWL6030 USB module\n"); 452 dev_info(&pdev->dev, "Initialized TWL6030 USB module\n");
443 453
diff --git a/drivers/usb/otg/ulpi_viewport.c b/drivers/usb/otg/ulpi_viewport.c
new file mode 100644
index 000000000000..e9a37f90994f
--- /dev/null
+++ b/drivers/usb/otg/ulpi_viewport.c
@@ -0,0 +1,80 @@
1/*
2 * Copyright (C) 2011 Google, Inc.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#include <linux/kernel.h>
16#include <linux/usb.h>
17#include <linux/io.h>
18#include <linux/usb/otg.h>
19#include <linux/usb/ulpi.h>
20
21#define ULPI_VIEW_WAKEUP (1 << 31)
22#define ULPI_VIEW_RUN (1 << 30)
23#define ULPI_VIEW_WRITE (1 << 29)
24#define ULPI_VIEW_READ (0 << 29)
25#define ULPI_VIEW_ADDR(x) (((x) & 0xff) << 16)
26#define ULPI_VIEW_DATA_READ(x) (((x) >> 8) & 0xff)
27#define ULPI_VIEW_DATA_WRITE(x) ((x) & 0xff)
28
29static int ulpi_viewport_wait(void __iomem *view, u32 mask)
30{
31 unsigned long usec = 2000;
32
33 while (usec--) {
34 if (!(readl(view) & mask))
35 return 0;
36
37 udelay(1);
38 };
39
40 return -ETIMEDOUT;
41}
42
43static int ulpi_viewport_read(struct otg_transceiver *otg, u32 reg)
44{
45 int ret;
46 void __iomem *view = otg->io_priv;
47
48 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
49 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
50 if (ret)
51 return ret;
52
53 writel(ULPI_VIEW_RUN | ULPI_VIEW_READ | ULPI_VIEW_ADDR(reg), view);
54 ret = ulpi_viewport_wait(view, ULPI_VIEW_RUN);
55 if (ret)
56 return ret;
57
58 return ULPI_VIEW_DATA_READ(readl(view));
59}
60
61static int ulpi_viewport_write(struct otg_transceiver *otg, u32 val, u32 reg)
62{
63 int ret;
64 void __iomem *view = otg->io_priv;
65
66 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
67 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
68 if (ret)
69 return ret;
70
71 writel(ULPI_VIEW_RUN | ULPI_VIEW_WRITE | ULPI_VIEW_DATA_WRITE(val) |
72 ULPI_VIEW_ADDR(reg), view);
73
74 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
75}
76
77struct otg_io_access_ops ulpi_viewport_access_ops = {
78 .read = ulpi_viewport_read,
79 .write = ulpi_viewport_write,
80};
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 7b8815ddf368..14ac87ee9251 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -75,6 +75,7 @@ static int debug;
75static const struct usb_device_id id_table[] = { 75static const struct usb_device_id id_table[] = {
76 { USB_DEVICE(0x4348, 0x5523) }, 76 { USB_DEVICE(0x4348, 0x5523) },
77 { USB_DEVICE(0x1a86, 0x7523) }, 77 { USB_DEVICE(0x1a86, 0x7523) },
78 { USB_DEVICE(0x1a86, 0x5523) },
78 { }, 79 { },
79}; 80};
80MODULE_DEVICE_TABLE(usb, id_table); 81MODULE_DEVICE_TABLE(usb, id_table);
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index f349a3629d00..a75f9298d88f 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -722,6 +722,8 @@ static struct usb_device_id id_table_combined [] = {
722 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) }, 722 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) },
723 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID), 723 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID),
724 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 724 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
725 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_H_PID),
726 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
725 { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID), 727 { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID),
726 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 728 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
727 { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID), 729 { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID),
@@ -973,7 +975,7 @@ static __u32 ftdi_2232h_baud_base_to_divisor(int baud, int base)
973 int divisor3; 975 int divisor3;
974 976
975 /* hi-speed baud rate is 10-bit sampling instead of 16-bit */ 977 /* hi-speed baud rate is 10-bit sampling instead of 16-bit */
976 divisor3 = (base / 10 / baud) * 8; 978 divisor3 = base * 8 / (baud * 10);
977 979
978 divisor = divisor3 >> 3; 980 divisor = divisor3 >> 3;
979 divisor |= (__u32)divfrac[divisor3 & 0x7] << 14; 981 divisor |= (__u32)divfrac[divisor3 & 0x7] << 14;
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 117e8e6f93c6..c543e55bafba 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -730,6 +730,7 @@
730/* Olimex */ 730/* Olimex */
731#define OLIMEX_VID 0x15BA 731#define OLIMEX_VID 0x15BA
732#define OLIMEX_ARM_USB_OCD_PID 0x0003 732#define OLIMEX_ARM_USB_OCD_PID 0x0003
733#define OLIMEX_ARM_USB_OCD_H_PID 0x002b
733 734
734/* 735/*
735 * Telldus Technologies 736 * Telldus Technologies
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 3b246d93cf22..76e3e502c23d 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -2343,7 +2343,6 @@ static int write_cmd_usb(struct edgeport_port *edge_port,
2343 usb_get_serial_data(edge_port->port->serial); 2343 usb_get_serial_data(edge_port->port->serial);
2344 int status = 0; 2344 int status = 0;
2345 struct urb *urb; 2345 struct urb *urb;
2346 int timeout;
2347 2346
2348 usb_serial_debug_data(debug, &edge_port->port->dev, 2347 usb_serial_debug_data(debug, &edge_port->port->dev,
2349 __func__, length, buffer); 2348 __func__, length, buffer);
@@ -2376,8 +2375,6 @@ static int write_cmd_usb(struct edgeport_port *edge_port,
2376 return status; 2375 return status;
2377 } 2376 }
2378 2377
2379 /* wait for command to finish */
2380 timeout = COMMAND_TIMEOUT;
2381#if 0 2378#if 0
2382 wait_event(&edge_port->wait_command, !edge_port->commandPending); 2379 wait_event(&edge_port->wait_command, !edge_port->commandPending);
2383 2380
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 0791778a66f3..67f41b526570 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -2121,16 +2121,16 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2121 /* Work out which port within the device is being setup */ 2121 /* Work out which port within the device is being setup */
2122 device_port = port->number - port->serial->minor; 2122 device_port = port->number - port->serial->minor;
2123 2123
2124 dbg("%s - endpoint %d port %d (%d)", 2124 /* Make sure we have an urb then send the message */
2125 __func__, usb_pipeendpoint(this_urb->pipe),
2126 port->number, device_port);
2127
2128 /* Make sure we have an urb then send the message */
2129 if (this_urb == NULL) { 2125 if (this_urb == NULL) {
2130 dbg("%s - oops no urb for port %d.", __func__, port->number); 2126 dbg("%s - oops no urb for port %d.", __func__, port->number);
2131 return -1; 2127 return -1;
2132 } 2128 }
2133 2129
2130 dbg("%s - endpoint %d port %d (%d)",
2131 __func__, usb_pipeendpoint(this_urb->pipe),
2132 port->number, device_port);
2133
2134 /* Save reset port val for resend. 2134 /* Save reset port val for resend.
2135 Don't overwrite resend for open/close condition. */ 2135 Don't overwrite resend for open/close condition. */
2136 if ((reset_port + 1) > p_priv->resend_cont) 2136 if ((reset_port + 1) > p_priv->resend_cont)
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 554a8693a463..7b690f3282a2 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -173,7 +173,8 @@ static void keyspan_pda_wakeup_write(struct work_struct *work)
173 container_of(work, struct keyspan_pda_private, wakeup_work); 173 container_of(work, struct keyspan_pda_private, wakeup_work);
174 struct usb_serial_port *port = priv->port; 174 struct usb_serial_port *port = priv->port;
175 struct tty_struct *tty = tty_port_tty_get(&port->port); 175 struct tty_struct *tty = tty_port_tty_get(&port->port);
176 tty_wakeup(tty); 176 if (tty)
177 tty_wakeup(tty);
177 tty_kref_put(tty); 178 tty_kref_put(tty);
178} 179}
179 180
@@ -206,7 +207,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
206static void keyspan_pda_rx_interrupt(struct urb *urb) 207static void keyspan_pda_rx_interrupt(struct urb *urb)
207{ 208{
208 struct usb_serial_port *port = urb->context; 209 struct usb_serial_port *port = urb->context;
209 struct tty_struct *tty = tty_port_tty_get(&port->port); 210 struct tty_struct *tty;
210 unsigned char *data = urb->transfer_buffer; 211 unsigned char *data = urb->transfer_buffer;
211 int retval; 212 int retval;
212 int status = urb->status; 213 int status = urb->status;
@@ -223,7 +224,7 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
223 /* this urb is terminated, clean up */ 224 /* this urb is terminated, clean up */
224 dbg("%s - urb shutting down with status: %d", 225 dbg("%s - urb shutting down with status: %d",
225 __func__, status); 226 __func__, status);
226 goto out; 227 return;
227 default: 228 default:
228 dbg("%s - nonzero urb status received: %d", 229 dbg("%s - nonzero urb status received: %d",
229 __func__, status); 230 __func__, status);
@@ -233,12 +234,14 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
233 /* see if the message is data or a status interrupt */ 234 /* see if the message is data or a status interrupt */
234 switch (data[0]) { 235 switch (data[0]) {
235 case 0: 236 case 0:
236 /* rest of message is rx data */ 237 tty = tty_port_tty_get(&port->port);
237 if (urb->actual_length) { 238 /* rest of message is rx data */
239 if (tty && urb->actual_length) {
238 tty_insert_flip_string(tty, data + 1, 240 tty_insert_flip_string(tty, data + 1,
239 urb->actual_length - 1); 241 urb->actual_length - 1);
240 tty_flip_buffer_push(tty); 242 tty_flip_buffer_push(tty);
241 } 243 }
244 tty_kref_put(tty);
242 break; 245 break;
243 case 1: 246 case 1:
244 /* status interrupt */ 247 /* status interrupt */
@@ -265,8 +268,6 @@ exit:
265 dev_err(&port->dev, 268 dev_err(&port->dev,
266 "%s - usb_submit_urb failed with result %d", 269 "%s - usb_submit_urb failed with result %d",
267 __func__, retval); 270 __func__, retval);
268out:
269 tty_kref_put(tty);
270} 271}
271 272
272 273
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index bd5bd8589e04..b382d9a0274d 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -372,7 +372,7 @@ static void kobil_read_int_callback(struct urb *urb)
372 } 372 }
373 373
374 tty = tty_port_tty_get(&port->port); 374 tty = tty_port_tty_get(&port->port);
375 if (urb->actual_length) { 375 if (tty && urb->actual_length) {
376 376
377 /* BEGIN DEBUG */ 377 /* BEGIN DEBUG */
378 /* 378 /*
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 2849f8c32015..1e225aacf46e 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -78,6 +78,8 @@
78#include <asm/unaligned.h> 78#include <asm/unaligned.h>
79#include <linux/usb.h> 79#include <linux/usb.h>
80#include <linux/usb/serial.h> 80#include <linux/usb/serial.h>
81#include <linux/serial.h>
82#include <linux/ioctl.h>
81#include "mct_u232.h" 83#include "mct_u232.h"
82 84
83/* 85/*
@@ -104,6 +106,10 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state);
104static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file); 106static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file);
105static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file, 107static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
106 unsigned int set, unsigned int clear); 108 unsigned int set, unsigned int clear);
109static int mct_u232_ioctl(struct tty_struct *tty, struct file *file,
110 unsigned int cmd, unsigned long arg);
111static int mct_u232_get_icount(struct tty_struct *tty,
112 struct serial_icounter_struct *icount);
107static void mct_u232_throttle(struct tty_struct *tty); 113static void mct_u232_throttle(struct tty_struct *tty);
108static void mct_u232_unthrottle(struct tty_struct *tty); 114static void mct_u232_unthrottle(struct tty_struct *tty);
109 115
@@ -150,9 +156,10 @@ static struct usb_serial_driver mct_u232_device = {
150 .tiocmset = mct_u232_tiocmset, 156 .tiocmset = mct_u232_tiocmset,
151 .attach = mct_u232_startup, 157 .attach = mct_u232_startup,
152 .release = mct_u232_release, 158 .release = mct_u232_release,
159 .ioctl = mct_u232_ioctl,
160 .get_icount = mct_u232_get_icount,
153}; 161};
154 162
155
156struct mct_u232_private { 163struct mct_u232_private {
157 spinlock_t lock; 164 spinlock_t lock;
158 unsigned int control_state; /* Modem Line Setting (TIOCM) */ 165 unsigned int control_state; /* Modem Line Setting (TIOCM) */
@@ -160,6 +167,9 @@ struct mct_u232_private {
160 unsigned char last_lsr; /* Line Status Register */ 167 unsigned char last_lsr; /* Line Status Register */
161 unsigned char last_msr; /* Modem Status Register */ 168 unsigned char last_msr; /* Modem Status Register */
162 unsigned int rx_flags; /* Throttling flags */ 169 unsigned int rx_flags; /* Throttling flags */
170 struct async_icount icount;
171 wait_queue_head_t msr_wait; /* for handling sleeping while waiting
172 for msr change to happen */
163}; 173};
164 174
165#define THROTTLED 0x01 175#define THROTTLED 0x01
@@ -386,6 +396,20 @@ static int mct_u232_get_modem_stat(struct usb_serial *serial,
386 return rc; 396 return rc;
387} /* mct_u232_get_modem_stat */ 397} /* mct_u232_get_modem_stat */
388 398
399static void mct_u232_msr_to_icount(struct async_icount *icount,
400 unsigned char msr)
401{
402 /* Translate Control Line states */
403 if (msr & MCT_U232_MSR_DDSR)
404 icount->dsr++;
405 if (msr & MCT_U232_MSR_DCTS)
406 icount->cts++;
407 if (msr & MCT_U232_MSR_DRI)
408 icount->rng++;
409 if (msr & MCT_U232_MSR_DCD)
410 icount->dcd++;
411} /* mct_u232_msr_to_icount */
412
389static void mct_u232_msr_to_state(unsigned int *control_state, 413static void mct_u232_msr_to_state(unsigned int *control_state,
390 unsigned char msr) 414 unsigned char msr)
391{ 415{
@@ -422,6 +446,7 @@ static int mct_u232_startup(struct usb_serial *serial)
422 if (!priv) 446 if (!priv)
423 return -ENOMEM; 447 return -ENOMEM;
424 spin_lock_init(&priv->lock); 448 spin_lock_init(&priv->lock);
449 init_waitqueue_head(&priv->msr_wait);
425 usb_set_serial_port_data(serial->port[0], priv); 450 usb_set_serial_port_data(serial->port[0], priv);
426 451
427 init_waitqueue_head(&serial->port[0]->write_wait); 452 init_waitqueue_head(&serial->port[0]->write_wait);
@@ -621,6 +646,8 @@ static void mct_u232_read_int_callback(struct urb *urb)
621 /* Record Control Line states */ 646 /* Record Control Line states */
622 mct_u232_msr_to_state(&priv->control_state, priv->last_msr); 647 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
623 648
649 mct_u232_msr_to_icount(&priv->icount, priv->last_msr);
650
624#if 0 651#if 0
625 /* Not yet handled. See belkin_sa.c for further information */ 652 /* Not yet handled. See belkin_sa.c for further information */
626 /* Now to report any errors */ 653 /* Now to report any errors */
@@ -647,6 +674,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
647 tty_kref_put(tty); 674 tty_kref_put(tty);
648 } 675 }
649#endif 676#endif
677 wake_up_interruptible(&priv->msr_wait);
650 spin_unlock_irqrestore(&priv->lock, flags); 678 spin_unlock_irqrestore(&priv->lock, flags);
651exit: 679exit:
652 retval = usb_submit_urb(urb, GFP_ATOMIC); 680 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -826,7 +854,6 @@ static void mct_u232_throttle(struct tty_struct *tty)
826 } 854 }
827} 855}
828 856
829
830static void mct_u232_unthrottle(struct tty_struct *tty) 857static void mct_u232_unthrottle(struct tty_struct *tty)
831{ 858{
832 struct usb_serial_port *port = tty->driver_data; 859 struct usb_serial_port *port = tty->driver_data;
@@ -847,6 +874,82 @@ static void mct_u232_unthrottle(struct tty_struct *tty)
847 } 874 }
848} 875}
849 876
877static int mct_u232_ioctl(struct tty_struct *tty, struct file *file,
878 unsigned int cmd, unsigned long arg)
879{
880 DEFINE_WAIT(wait);
881 struct usb_serial_port *port = tty->driver_data;
882 struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port);
883 struct async_icount cnow, cprev;
884 unsigned long flags;
885
886 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
887
888 switch (cmd) {
889
890 case TIOCMIWAIT:
891
892 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
893
894 spin_lock_irqsave(&mct_u232_port->lock, flags);
895 cprev = mct_u232_port->icount;
896 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
897 for ( ; ; ) {
898 prepare_to_wait(&mct_u232_port->msr_wait,
899 &wait, TASK_INTERRUPTIBLE);
900 schedule();
901 finish_wait(&mct_u232_port->msr_wait, &wait);
902 /* see if a signal did it */
903 if (signal_pending(current))
904 return -ERESTARTSYS;
905 spin_lock_irqsave(&mct_u232_port->lock, flags);
906 cnow = mct_u232_port->icount;
907 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
908 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
909 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
910 return -EIO; /* no change => error */
911 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
912 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
913 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
914 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
915 return 0;
916 }
917 cprev = cnow;
918 }
919
920 }
921 return -ENOIOCTLCMD;
922}
923
924static int mct_u232_get_icount(struct tty_struct *tty,
925 struct serial_icounter_struct *icount)
926{
927 struct usb_serial_port *port = tty->driver_data;
928 struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port);
929 struct async_icount *ic = &mct_u232_port->icount;
930 unsigned long flags;
931
932 spin_lock_irqsave(&mct_u232_port->lock, flags);
933
934 icount->cts = ic->cts;
935 icount->dsr = ic->dsr;
936 icount->rng = ic->rng;
937 icount->dcd = ic->dcd;
938 icount->rx = ic->rx;
939 icount->tx = ic->tx;
940 icount->frame = ic->frame;
941 icount->overrun = ic->overrun;
942 icount->parity = ic->parity;
943 icount->brk = ic->brk;
944 icount->buf_overrun = ic->buf_overrun;
945
946 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
947
948 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d",
949 __func__, port->number, icount->rx, icount->tx);
950 return 0;
951}
952
850static int __init mct_u232_init(void) 953static int __init mct_u232_init(void)
851{ 954{
852 int retval; 955 int retval;
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 7d3bc9a3e2b6..ae506f4ee29d 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -2052,7 +2052,7 @@ static int mos7720_startup(struct usb_serial *serial)
2052 struct usb_device *dev; 2052 struct usb_device *dev;
2053 int i; 2053 int i;
2054 char data; 2054 char data;
2055 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); 2055 u16 product;
2056 int ret_val; 2056 int ret_val;
2057 2057
2058 dbg("%s: Entering ..........", __func__); 2058 dbg("%s: Entering ..........", __func__);
@@ -2062,6 +2062,7 @@ static int mos7720_startup(struct usb_serial *serial)
2062 return -ENODEV; 2062 return -ENODEV;
2063 } 2063 }
2064 2064
2065 product = le16_to_cpu(serial->dev->descriptor.idProduct);
2065 dev = serial->dev; 2066 dev = serial->dev;
2066 2067
2067 /* 2068 /*
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index eda1f9266c4e..ce82396fc4e8 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Opticon USB barcode to serial driver 2 * Opticon USB barcode to serial driver
3 * 3 *
4 * Copyright (C) 2011 Martin Jansen <martin.jansen@opticon.com>
4 * Copyright (C) 2008 - 2009 Greg Kroah-Hartman <gregkh@suse.de> 5 * Copyright (C) 2008 - 2009 Greg Kroah-Hartman <gregkh@suse.de>
5 * Copyright (C) 2008 - 2009 Novell Inc. 6 * Copyright (C) 2008 - 2009 Novell Inc.
6 * 7 *
@@ -21,6 +22,16 @@
21#include <linux/usb/serial.h> 22#include <linux/usb/serial.h>
22#include <linux/uaccess.h> 23#include <linux/uaccess.h>
23 24
25#define CONTROL_RTS 0x02
26#define RESEND_CTS_STATE 0x03
27
28/* max number of write urbs in flight */
29#define URB_UPPER_LIMIT 8
30
31/* This driver works for the Opticon 1D barcode reader
32 * an examples of 1D barcode types are EAN, UPC, Code39, IATA etc.. */
33#define DRIVER_DESC "Opticon USB barcode to serial driver (1D)"
34
24static int debug; 35static int debug;
25 36
26static const struct usb_device_id id_table[] = { 37static const struct usb_device_id id_table[] = {
@@ -42,13 +53,13 @@ struct opticon_private {
42 bool throttled; 53 bool throttled;
43 bool actually_throttled; 54 bool actually_throttled;
44 bool rts; 55 bool rts;
56 bool cts;
45 int outstanding_urbs; 57 int outstanding_urbs;
46}; 58};
47 59
48/* max number of write urbs in flight */
49#define URB_UPPER_LIMIT 4
50 60
51static void opticon_bulk_callback(struct urb *urb) 61
62static void opticon_read_bulk_callback(struct urb *urb)
52{ 63{
53 struct opticon_private *priv = urb->context; 64 struct opticon_private *priv = urb->context;
54 unsigned char *data = urb->transfer_buffer; 65 unsigned char *data = urb->transfer_buffer;
@@ -57,6 +68,7 @@ static void opticon_bulk_callback(struct urb *urb)
57 struct tty_struct *tty; 68 struct tty_struct *tty;
58 int result; 69 int result;
59 int data_length; 70 int data_length;
71 unsigned long flags;
60 72
61 dbg("%s - port %d", __func__, port->number); 73 dbg("%s - port %d", __func__, port->number);
62 74
@@ -87,10 +99,10 @@ static void opticon_bulk_callback(struct urb *urb)
87 * Data from the device comes with a 2 byte header: 99 * Data from the device comes with a 2 byte header:
88 * 100 *
89 * <0x00><0x00>data... 101 * <0x00><0x00>data...
90 * This is real data to be sent to the tty layer 102 * This is real data to be sent to the tty layer
91 * <0x00><0x01)level 103 * <0x00><0x01)level
92 * This is a RTS level change, the third byte is the RTS 104 * This is a CTS level change, the third byte is the CTS
93 * value (0 for low, 1 for high). 105 * value (0 for low, 1 for high).
94 */ 106 */
95 if ((data[0] == 0x00) && (data[1] == 0x00)) { 107 if ((data[0] == 0x00) && (data[1] == 0x00)) {
96 /* real data, send it to the tty layer */ 108 /* real data, send it to the tty layer */
@@ -103,10 +115,13 @@ static void opticon_bulk_callback(struct urb *urb)
103 } 115 }
104 } else { 116 } else {
105 if ((data[0] == 0x00) && (data[1] == 0x01)) { 117 if ((data[0] == 0x00) && (data[1] == 0x01)) {
118 spin_lock_irqsave(&priv->lock, flags);
119 /* CTS status infomation package */
106 if (data[2] == 0x00) 120 if (data[2] == 0x00)
107 priv->rts = false; 121 priv->cts = false;
108 else 122 else
109 priv->rts = true; 123 priv->cts = true;
124 spin_unlock_irqrestore(&priv->lock, flags);
110 } else { 125 } else {
111 dev_dbg(&priv->udev->dev, 126 dev_dbg(&priv->udev->dev,
112 "Unknown data packet received from the device:" 127 "Unknown data packet received from the device:"
@@ -129,7 +144,7 @@ exit:
129 usb_rcvbulkpipe(priv->udev, 144 usb_rcvbulkpipe(priv->udev,
130 priv->bulk_address), 145 priv->bulk_address),
131 priv->bulk_in_buffer, priv->buffer_size, 146 priv->bulk_in_buffer, priv->buffer_size,
132 opticon_bulk_callback, priv); 147 opticon_read_bulk_callback, priv);
133 result = usb_submit_urb(priv->bulk_read_urb, GFP_ATOMIC); 148 result = usb_submit_urb(priv->bulk_read_urb, GFP_ATOMIC);
134 if (result) 149 if (result)
135 dev_err(&port->dev, 150 dev_err(&port->dev,
@@ -140,6 +155,24 @@ exit:
140 spin_unlock(&priv->lock); 155 spin_unlock(&priv->lock);
141} 156}
142 157
158static int send_control_msg(struct usb_serial_port *port, u8 requesttype,
159 u8 val)
160{
161 struct usb_serial *serial = port->serial;
162 int retval;
163 u8 buffer[2];
164
165 buffer[0] = val;
166 /* Send the message to the vendor control endpoint
167 * of the connected device */
168 retval = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
169 requesttype,
170 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
171 0, 0, buffer, 1, 0);
172
173 return retval;
174}
175
143static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) 176static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
144{ 177{
145 struct opticon_private *priv = usb_get_serial_data(port->serial); 178 struct opticon_private *priv = usb_get_serial_data(port->serial);
@@ -152,19 +185,30 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
152 priv->throttled = false; 185 priv->throttled = false;
153 priv->actually_throttled = false; 186 priv->actually_throttled = false;
154 priv->port = port; 187 priv->port = port;
188 priv->rts = false;
155 spin_unlock_irqrestore(&priv->lock, flags); 189 spin_unlock_irqrestore(&priv->lock, flags);
156 190
157 /* Start reading from the device */ 191 /* Clear RTS line */
192 send_control_msg(port, CONTROL_RTS, 0);
193
194 /* Setup the read URB and start reading from the device */
158 usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev, 195 usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev,
159 usb_rcvbulkpipe(priv->udev, 196 usb_rcvbulkpipe(priv->udev,
160 priv->bulk_address), 197 priv->bulk_address),
161 priv->bulk_in_buffer, priv->buffer_size, 198 priv->bulk_in_buffer, priv->buffer_size,
162 opticon_bulk_callback, priv); 199 opticon_read_bulk_callback, priv);
200
201 /* clear the halt status of the enpoint */
202 usb_clear_halt(priv->udev, priv->bulk_read_urb->pipe);
203
163 result = usb_submit_urb(priv->bulk_read_urb, GFP_KERNEL); 204 result = usb_submit_urb(priv->bulk_read_urb, GFP_KERNEL);
164 if (result) 205 if (result)
165 dev_err(&port->dev, 206 dev_err(&port->dev,
166 "%s - failed resubmitting read urb, error %d\n", 207 "%s - failed resubmitting read urb, error %d\n",
167 __func__, result); 208 __func__, result);
209 /* Request CTS line state, sometimes during opening the current
210 * CTS state can be missed. */
211 send_control_msg(port, RESEND_CTS_STATE, 1);
168 return result; 212 return result;
169} 213}
170 214
@@ -178,7 +222,7 @@ static void opticon_close(struct usb_serial_port *port)
178 usb_kill_urb(priv->bulk_read_urb); 222 usb_kill_urb(priv->bulk_read_urb);
179} 223}
180 224
181static void opticon_write_bulk_callback(struct urb *urb) 225static void opticon_write_control_callback(struct urb *urb)
182{ 226{
183 struct opticon_private *priv = urb->context; 227 struct opticon_private *priv = urb->context;
184 int status = urb->status; 228 int status = urb->status;
@@ -210,6 +254,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
210 unsigned char *buffer; 254 unsigned char *buffer;
211 unsigned long flags; 255 unsigned long flags;
212 int status; 256 int status;
257 struct usb_ctrlrequest *dr;
213 258
214 dbg("%s - port %d", __func__, port->number); 259 dbg("%s - port %d", __func__, port->number);
215 260
@@ -226,6 +271,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
226 if (!buffer) { 271 if (!buffer) {
227 dev_err(&port->dev, "out of memory\n"); 272 dev_err(&port->dev, "out of memory\n");
228 count = -ENOMEM; 273 count = -ENOMEM;
274
229 goto error_no_buffer; 275 goto error_no_buffer;
230 } 276 }
231 277
@@ -240,35 +286,28 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
240 286
241 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); 287 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
242 288
243 if (port->bulk_out_endpointAddress) { 289 /* The conncected devices do not have a bulk write endpoint,
244 usb_fill_bulk_urb(urb, serial->dev, 290 * to transmit data to de barcode device the control endpoint is used */
245 usb_sndbulkpipe(serial->dev, 291 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
246 port->bulk_out_endpointAddress), 292 if (!dr)
247 buffer, count, opticon_write_bulk_callback, priv); 293 return -ENOMEM;
248 } else { 294
249 struct usb_ctrlrequest *dr; 295 dr->bRequestType = USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT;
250 296 dr->bRequest = 0x01;
251 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); 297 dr->wValue = 0;
252 if (!dr) 298 dr->wIndex = 0;
253 return -ENOMEM; 299 dr->wLength = cpu_to_le16(count);
254 300
255 dr->bRequestType = USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT; 301 usb_fill_control_urb(urb, serial->dev,
256 dr->bRequest = 0x01; 302 usb_sndctrlpipe(serial->dev, 0),
257 dr->wValue = 0; 303 (unsigned char *)dr, buffer, count,
258 dr->wIndex = 0; 304 opticon_write_control_callback, priv);
259 dr->wLength = cpu_to_le16(count);
260
261 usb_fill_control_urb(urb, serial->dev,
262 usb_sndctrlpipe(serial->dev, 0),
263 (unsigned char *)dr, buffer, count,
264 opticon_write_bulk_callback, priv);
265 }
266 305
267 /* send it down the pipe */ 306 /* send it down the pipe */
268 status = usb_submit_urb(urb, GFP_ATOMIC); 307 status = usb_submit_urb(urb, GFP_ATOMIC);
269 if (status) { 308 if (status) {
270 dev_err(&port->dev, 309 dev_err(&port->dev,
271 "%s - usb_submit_urb(write bulk) failed with status = %d\n", 310 "%s - usb_submit_urb(write endpoint) failed status = %d\n",
272 __func__, status); 311 __func__, status);
273 count = status; 312 count = status;
274 goto error; 313 goto error;
@@ -360,16 +399,49 @@ static int opticon_tiocmget(struct tty_struct *tty, struct file *file)
360 int result = 0; 399 int result = 0;
361 400
362 dbg("%s - port %d", __func__, port->number); 401 dbg("%s - port %d", __func__, port->number);
402 if (!usb_get_intfdata(port->serial->interface))
403 return -ENODEV;
363 404
364 spin_lock_irqsave(&priv->lock, flags); 405 spin_lock_irqsave(&priv->lock, flags);
365 if (priv->rts) 406 if (priv->rts)
366 result = TIOCM_RTS; 407 result |= TIOCM_RTS;
408 if (priv->cts)
409 result |= TIOCM_CTS;
367 spin_unlock_irqrestore(&priv->lock, flags); 410 spin_unlock_irqrestore(&priv->lock, flags);
368 411
369 dbg("%s - %x", __func__, result); 412 dbg("%s - %x", __func__, result);
370 return result; 413 return result;
371} 414}
372 415
416static int opticon_tiocmset(struct tty_struct *tty, struct file *file,
417 unsigned int set, unsigned int clear)
418{
419 struct usb_serial_port *port = tty->driver_data;
420 struct opticon_private *priv = usb_get_serial_data(port->serial);
421 unsigned long flags;
422 bool rts;
423 bool changed = false;
424
425 if (!usb_get_intfdata(port->serial->interface))
426 return -ENODEV;
427 /* We only support RTS so we only handle that */
428 spin_lock_irqsave(&priv->lock, flags);
429
430 rts = priv->rts;
431 if (set & TIOCM_RTS)
432 priv->rts = true;
433 if (clear & TIOCM_RTS)
434 priv->rts = false;
435 changed = rts ^ priv->rts;
436 spin_unlock_irqrestore(&priv->lock, flags);
437
438 if (!changed)
439 return 0;
440
441 /* Send the new RTS state to the connected device */
442 return send_control_msg(port, CONTROL_RTS, !rts);
443}
444
373static int get_serial_info(struct opticon_private *priv, 445static int get_serial_info(struct opticon_private *priv,
374 struct serial_struct __user *serial) 446 struct serial_struct __user *serial)
375{ 447{
@@ -431,6 +503,7 @@ static int opticon_startup(struct usb_serial *serial)
431 priv->serial = serial; 503 priv->serial = serial;
432 priv->port = serial->port[0]; 504 priv->port = serial->port[0];
433 priv->udev = serial->dev; 505 priv->udev = serial->dev;
506 priv->outstanding_urbs = 0; /* Init the outstanding urbs */
434 507
435 /* find our bulk endpoint */ 508 /* find our bulk endpoint */
436 intf = serial->interface->altsetting; 509 intf = serial->interface->altsetting;
@@ -456,13 +529,6 @@ static int opticon_startup(struct usb_serial *serial)
456 529
457 priv->bulk_address = endpoint->bEndpointAddress; 530 priv->bulk_address = endpoint->bEndpointAddress;
458 531
459 /* set up our bulk urb */
460 usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev,
461 usb_rcvbulkpipe(priv->udev,
462 endpoint->bEndpointAddress),
463 priv->bulk_in_buffer, priv->buffer_size,
464 opticon_bulk_callback, priv);
465
466 bulk_in_found = true; 532 bulk_in_found = true;
467 break; 533 break;
468 } 534 }
@@ -558,6 +624,7 @@ static struct usb_serial_driver opticon_device = {
558 .unthrottle = opticon_unthrottle, 624 .unthrottle = opticon_unthrottle,
559 .ioctl = opticon_ioctl, 625 .ioctl = opticon_ioctl,
560 .tiocmget = opticon_tiocmget, 626 .tiocmget = opticon_tiocmget,
627 .tiocmset = opticon_tiocmset,
561}; 628};
562 629
563static int __init opticon_init(void) 630static int __init opticon_init(void)
@@ -581,6 +648,7 @@ static void __exit opticon_exit(void)
581 648
582module_init(opticon_init); 649module_init(opticon_init);
583module_exit(opticon_exit); 650module_exit(opticon_exit);
651MODULE_DESCRIPTION(DRIVER_DESC);
584MODULE_LICENSE("GPL"); 652MODULE_LICENSE("GPL");
585 653
586module_param(debug, bool, S_IRUGO | S_IWUSR); 654module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 5f46838dfee5..75c7f456eed5 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -652,7 +652,8 @@ static const struct usb_device_id option_ids[] = {
652 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0028, 0xff, 0xff, 0xff) }, 652 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0028, 0xff, 0xff, 0xff) },
653 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0029, 0xff, 0xff, 0xff) }, 653 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0029, 0xff, 0xff, 0xff) },
654 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0030, 0xff, 0xff, 0xff) }, 654 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0030, 0xff, 0xff, 0xff) },
655 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF626, 0xff, 0xff, 0xff) }, 655 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF626, 0xff,
656 0xff, 0xff), .driver_info = (kernel_ulong_t)&four_g_w14_blacklist },
656 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0032, 0xff, 0xff, 0xff) }, 657 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0032, 0xff, 0xff, 0xff) },
657 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0033, 0xff, 0xff, 0xff) }, 658 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0033, 0xff, 0xff, 0xff) },
658 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0034, 0xff, 0xff, 0xff) }, 659 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0034, 0xff, 0xff, 0xff) },
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 0457813eebee..5b88b6836a81 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -376,7 +376,10 @@ static int sierra_send_setup(struct usb_serial_port *port)
376 if (!do_send) 376 if (!do_send)
377 return 0; 377 return 0;
378 378
379 usb_autopm_get_interface(serial->interface); 379 retval = usb_autopm_get_interface(serial->interface);
380 if (retval < 0)
381 return retval;
382
380 retval = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 383 retval = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
381 0x22, 0x21, val, interface, NULL, 0, USB_CTRL_SET_TIMEOUT); 384 0x22, 0x21, val, interface, NULL, 0, USB_CTRL_SET_TIMEOUT);
382 usb_autopm_put_interface(serial->interface); 385 usb_autopm_put_interface(serial->interface);
@@ -811,8 +814,12 @@ static void sierra_close(struct usb_serial_port *port)
811 mutex_lock(&serial->disc_mutex); 814 mutex_lock(&serial->disc_mutex);
812 if (!serial->disconnected) { 815 if (!serial->disconnected) {
813 serial->interface->needs_remote_wakeup = 0; 816 serial->interface->needs_remote_wakeup = 0;
814 usb_autopm_get_interface(serial->interface); 817 /* odd error handling due to pm counters */
815 sierra_send_setup(port); 818 if (!usb_autopm_get_interface(serial->interface))
819 sierra_send_setup(port);
820 else
821 usb_autopm_get_interface_no_resume(serial->interface);
822
816 } 823 }
817 mutex_unlock(&serial->disc_mutex); 824 mutex_unlock(&serial->disc_mutex);
818 spin_lock_irq(&intfdata->susp_lock); 825 spin_lock_irq(&intfdata->susp_lock);
@@ -865,7 +872,8 @@ static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port)
865 /* get rid of everything as in close */ 872 /* get rid of everything as in close */
866 sierra_close(port); 873 sierra_close(port);
867 /* restore balance for autopm */ 874 /* restore balance for autopm */
868 usb_autopm_put_interface(serial->interface); 875 if (!serial->disconnected)
876 usb_autopm_put_interface(serial->interface);
869 return err; 877 return err;
870 } 878 }
871 sierra_send_setup(port); 879 sierra_send_setup(port);
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 546a52179bec..2ff90a9c8f47 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -911,9 +911,8 @@ int usb_serial_probe(struct usb_interface *interface,
911 dev_err(&interface->dev, "No free urbs available\n"); 911 dev_err(&interface->dev, "No free urbs available\n");
912 goto probe_error; 912 goto probe_error;
913 } 913 }
914 buffer_size = serial->type->bulk_in_size; 914 buffer_size = max_t(int, serial->type->bulk_in_size,
915 if (!buffer_size) 915 le16_to_cpu(endpoint->wMaxPacketSize));
916 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
917 port->bulk_in_size = buffer_size; 916 port->bulk_in_size = buffer_size;
918 port->bulk_in_endpointAddress = endpoint->bEndpointAddress; 917 port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
919 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 918 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
index 9c014e2ecd68..eb95aecc0015 100644
--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -261,7 +261,8 @@ int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
261 intfdata->in_flight--; 261 intfdata->in_flight--;
262 spin_unlock_irqrestore(&intfdata->susp_lock, 262 spin_unlock_irqrestore(&intfdata->susp_lock,
263 flags); 263 flags);
264 continue; 264 usb_autopm_put_interface_async(port->serial->interface);
265 break;
265 } 266 }
266 } 267 }
267 268
@@ -308,11 +309,16 @@ static void usb_wwan_indat_callback(struct urb *urb)
308 /* Resubmit urb so we continue receiving */ 309 /* Resubmit urb so we continue receiving */
309 if (status != -ESHUTDOWN) { 310 if (status != -ESHUTDOWN) {
310 err = usb_submit_urb(urb, GFP_ATOMIC); 311 err = usb_submit_urb(urb, GFP_ATOMIC);
311 if (err && err != -EPERM) 312 if (err) {
312 printk(KERN_ERR "%s: resubmit read urb failed. " 313 if (err != -EPERM) {
313 "(%d)", __func__, err); 314 printk(KERN_ERR "%s: resubmit read urb failed. "
314 else 315 "(%d)", __func__, err);
316 /* busy also in error unless we are killed */
317 usb_mark_last_busy(port->serial->dev);
318 }
319 } else {
315 usb_mark_last_busy(port->serial->dev); 320 usb_mark_last_busy(port->serial->dev);
321 }
316 } 322 }
317 323
318 } 324 }
@@ -421,6 +427,7 @@ int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port)
421 spin_lock_irq(&intfdata->susp_lock); 427 spin_lock_irq(&intfdata->susp_lock);
422 portdata->opened = 1; 428 portdata->opened = 1;
423 spin_unlock_irq(&intfdata->susp_lock); 429 spin_unlock_irq(&intfdata->susp_lock);
430 /* this balances a get in the generic USB serial code */
424 usb_autopm_put_interface(serial->interface); 431 usb_autopm_put_interface(serial->interface);
425 432
426 return 0; 433 return 0;
@@ -447,7 +454,8 @@ void usb_wwan_close(struct usb_serial_port *port)
447 usb_kill_urb(portdata->in_urbs[i]); 454 usb_kill_urb(portdata->in_urbs[i]);
448 for (i = 0; i < N_OUT_URB; i++) 455 for (i = 0; i < N_OUT_URB; i++)
449 usb_kill_urb(portdata->out_urbs[i]); 456 usb_kill_urb(portdata->out_urbs[i]);
450 usb_autopm_get_interface(serial->interface); 457 /* balancing - important as an error cannot be handled*/
458 usb_autopm_get_interface_no_resume(serial->interface);
451 serial->interface->needs_remote_wakeup = 0; 459 serial->interface->needs_remote_wakeup = 0;
452 } 460 }
453} 461}
@@ -661,6 +669,18 @@ int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message)
661} 669}
662EXPORT_SYMBOL(usb_wwan_suspend); 670EXPORT_SYMBOL(usb_wwan_suspend);
663 671
672static void unbusy_queued_urb(struct urb *urb, struct usb_wwan_port_private *portdata)
673{
674 int i;
675
676 for (i = 0; i < N_OUT_URB; i++) {
677 if (urb == portdata->out_urbs[i]) {
678 clear_bit(i, &portdata->out_busy);
679 break;
680 }
681 }
682}
683
664static void play_delayed(struct usb_serial_port *port) 684static void play_delayed(struct usb_serial_port *port)
665{ 685{
666 struct usb_wwan_intf_private *data; 686 struct usb_wwan_intf_private *data;
@@ -672,8 +692,17 @@ static void play_delayed(struct usb_serial_port *port)
672 data = port->serial->private; 692 data = port->serial->private;
673 while ((urb = usb_get_from_anchor(&portdata->delayed))) { 693 while ((urb = usb_get_from_anchor(&portdata->delayed))) {
674 err = usb_submit_urb(urb, GFP_ATOMIC); 694 err = usb_submit_urb(urb, GFP_ATOMIC);
675 if (!err) 695 if (!err) {
676 data->in_flight++; 696 data->in_flight++;
697 } else {
698 /* we have to throw away the rest */
699 do {
700 unbusy_queued_urb(urb, portdata);
701 //extremely dirty
702 atomic_dec(&port->serial->interface->dev.power.usage_count);
703 } while ((urb = usb_get_from_anchor(&portdata->delayed)));
704 break;
705 }
677 } 706 }
678} 707}
679 708
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index 49a489e03716..353aeb44da6a 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -31,6 +31,16 @@ config USB_STORAGE_DEBUG
31 Say Y here in order to have the USB Mass Storage code generate 31 Say Y here in order to have the USB Mass Storage code generate
32 verbose debugging messages. 32 verbose debugging messages.
33 33
34config USB_STORAGE_REALTEK
35 tristate "Realtek Card Reader support"
36 depends on USB_STORAGE
37 help
38 Say Y here to include additional code to support the power-saving function
39 for Realtek RTS51xx USB card readers.
40
41 If this driver is compiled as a module, it will be named ums-realtek.
42
43
34config USB_STORAGE_DATAFAB 44config USB_STORAGE_DATAFAB
35 tristate "Datafab Compact Flash Reader support" 45 tristate "Datafab Compact Flash Reader support"
36 depends on USB_STORAGE 46 depends on USB_STORAGE
diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile
index fcf14cdc4a04..0d2de971bd91 100644
--- a/drivers/usb/storage/Makefile
+++ b/drivers/usb/storage/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_USB_STORAGE_ISD200) += ums-isd200.o
30obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += ums-jumpshot.o 30obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += ums-jumpshot.o
31obj-$(CONFIG_USB_STORAGE_KARMA) += ums-karma.o 31obj-$(CONFIG_USB_STORAGE_KARMA) += ums-karma.o
32obj-$(CONFIG_USB_STORAGE_ONETOUCH) += ums-onetouch.o 32obj-$(CONFIG_USB_STORAGE_ONETOUCH) += ums-onetouch.o
33obj-$(CONFIG_USB_STORAGE_REALTEK) += ums-realtek.o
33obj-$(CONFIG_USB_STORAGE_SDDR09) += ums-sddr09.o 34obj-$(CONFIG_USB_STORAGE_SDDR09) += ums-sddr09.o
34obj-$(CONFIG_USB_STORAGE_SDDR55) += ums-sddr55.o 35obj-$(CONFIG_USB_STORAGE_SDDR55) += ums-sddr55.o
35obj-$(CONFIG_USB_STORAGE_USBAT) += ums-usbat.o 36obj-$(CONFIG_USB_STORAGE_USBAT) += ums-usbat.o
@@ -42,6 +43,7 @@ ums-isd200-y := isd200.o
42ums-jumpshot-y := jumpshot.o 43ums-jumpshot-y := jumpshot.o
43ums-karma-y := karma.o 44ums-karma-y := karma.o
44ums-onetouch-y := onetouch.o 45ums-onetouch-y := onetouch.o
46ums-realtek-y := realtek_cr.o
45ums-sddr09-y := sddr09.o 47ums-sddr09-y := sddr09.o
46ums-sddr55-y := sddr55.o 48ums-sddr55-y := sddr55.o
47ums-usbat-y := shuttle_usbat.o 49ums-usbat-y := shuttle_usbat.o
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
new file mode 100644
index 000000000000..d509a4a7d74f
--- /dev/null
+++ b/drivers/usb/storage/realtek_cr.c
@@ -0,0 +1,675 @@
1/* Driver for Realtek RTS51xx USB card reader
2 *
3 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
8 * later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 * wwang (wei_wang@realsil.com.cn)
20 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
21 */
22
23#include <linux/module.h>
24#include <linux/blkdev.h>
25#include <linux/kthread.h>
26#include <linux/sched.h>
27#include <linux/workqueue.h>
28#include <linux/kernel.h>
29#include <linux/version.h>
30
31#include <scsi/scsi.h>
32#include <scsi/scsi_cmnd.h>
33#include <scsi/scsi_device.h>
34#include <linux/cdrom.h>
35
36#include <linux/usb.h>
37#include <linux/slab.h>
38#include <linux/usb_usual.h>
39
40#include "usb.h"
41#include "transport.h"
42#include "protocol.h"
43#include "debug.h"
44
45MODULE_DESCRIPTION("Driver for Realtek USB Card Reader");
46MODULE_AUTHOR("wwang <wei_wang@realsil.com.cn>");
47MODULE_LICENSE("GPL");
48MODULE_VERSION("1.03");
49
50static int auto_delink_en = 1;
51module_param(auto_delink_en, int, S_IRUGO | S_IWUSR);
52MODULE_PARM_DESC(auto_delink_en, "enable auto delink");
53
54struct rts51x_status {
55 u16 vid;
56 u16 pid;
57 u8 cur_lun;
58 u8 card_type;
59 u8 total_lun;
60 u16 fw_ver;
61 u8 phy_exist;
62 u8 multi_flag;
63 u8 multi_card;
64 u8 log_exist;
65 union {
66 u8 detailed_type1;
67 u8 detailed_type2;
68 } detailed_type;
69 u8 function[2];
70};
71
72struct rts51x_chip {
73 u16 vendor_id;
74 u16 product_id;
75 char max_lun;
76
77 struct rts51x_status *status;
78 int status_len;
79
80 u32 flag;
81};
82
83/* flag definition */
84#define FLIDX_AUTO_DELINK 0x01
85
86#define SCSI_LUN(srb) ((srb)->device->lun)
87
88/* Bit Operation */
89#define SET_BIT(data, idx) ((data) |= 1 << (idx))
90#define CLR_BIT(data, idx) ((data) &= ~(1 << (idx)))
91#define CHK_BIT(data, idx) ((data) & (1 << (idx)))
92
93#define SET_AUTO_DELINK(chip) ((chip)->flag |= FLIDX_AUTO_DELINK)
94#define CLR_AUTO_DELINK(chip) ((chip)->flag &= ~FLIDX_AUTO_DELINK)
95#define CHK_AUTO_DELINK(chip) ((chip)->flag & FLIDX_AUTO_DELINK)
96
97#define RTS51X_GET_VID(chip) ((chip)->vendor_id)
98#define RTS51X_GET_PID(chip) ((chip)->product_id)
99
100#define FW_VERSION(chip) ((chip)->status[0].fw_ver)
101#define STATUS_LEN(chip) ((chip)->status_len)
102
103/* Check card reader function */
104#define SUPPORT_DETAILED_TYPE1(chip) \
105 CHK_BIT((chip)->status[0].function[0], 1)
106#define SUPPORT_OT(chip) \
107 CHK_BIT((chip)->status[0].function[0], 2)
108#define SUPPORT_OC(chip) \
109 CHK_BIT((chip)->status[0].function[0], 3)
110#define SUPPORT_AUTO_DELINK(chip) \
111 CHK_BIT((chip)->status[0].function[0], 4)
112#define SUPPORT_SDIO(chip) \
113 CHK_BIT((chip)->status[0].function[1], 0)
114#define SUPPORT_DETAILED_TYPE2(chip) \
115 CHK_BIT((chip)->status[0].function[1], 1)
116
117#define CHECK_PID(chip, pid) (RTS51X_GET_PID(chip) == (pid))
118#define CHECK_FW_VER(chip, fw_ver) (FW_VERSION(chip) == (fw_ver))
119#define CHECK_ID(chip, pid, fw_ver) \
120 (CHECK_PID((chip), (pid)) && CHECK_FW_VER((chip), (fw_ver)))
121
122#define wait_timeout_x(task_state, msecs) \
123do { \
124 set_current_state((task_state)); \
125 schedule_timeout((msecs) * HZ / 1000); \
126} while (0)
127
128#define wait_timeout(msecs) \
129 wait_timeout_x(TASK_INTERRUPTIBLE, (msecs))
130
131static int init_realtek_cr(struct us_data *us);
132
133/*
134 * The table of devices
135 */
136#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
137 vendorName, productName, useProtocol, useTransport, \
138 initFunction, flags) \
139{\
140 USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
141 .driver_info = (flags)|(USB_US_TYPE_STOR<<24)\
142}
143
144static const struct usb_device_id realtek_cr_ids[] = {
145# include "unusual_realtek.h"
146 { } /* Terminating entry */
147};
148MODULE_DEVICE_TABLE(usb, realtek_cr_ids);
149
150#undef UNUSUAL_DEV
151
152/*
153 * The flags table
154 */
155#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
156 vendor_name, product_name, use_protocol, use_transport, \
157 init_function, Flags) \
158{ \
159 .vendorName = vendor_name, \
160 .productName = product_name, \
161 .useProtocol = use_protocol, \
162 .useTransport = use_transport, \
163 .initFunction = init_function, \
164}
165
166static struct us_unusual_dev realtek_cr_unusual_dev_list[] = {
167# include "unusual_realtek.h"
168 { } /* Terminating entry */
169};
170
171#undef UNUSUAL_DEV
172
173static int rts51x_bulk_transport(struct us_data *us, u8 lun,
174 u8 *cmd, int cmd_len, u8 *buf, int buf_len,
175 enum dma_data_direction dir, int *act_len)
176{
177 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
178 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
179 int result;
180 unsigned int residue;
181 unsigned int cswlen;
182 unsigned int cbwlen = US_BULK_CB_WRAP_LEN;
183
184 /* set up the command wrapper */
185 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
186 bcb->DataTransferLength = cpu_to_le32(buf_len);
187 bcb->Flags = (dir == DMA_FROM_DEVICE) ? 1 << 7 : 0;
188 bcb->Tag = ++us->tag;
189 bcb->Lun = lun;
190 bcb->Length = cmd_len;
191
192 /* copy the command payload */
193 memset(bcb->CDB, 0, sizeof(bcb->CDB));
194 memcpy(bcb->CDB, cmd, bcb->Length);
195
196 /* send it to out endpoint */
197 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
198 bcb, cbwlen, NULL);
199 if (result != USB_STOR_XFER_GOOD)
200 return USB_STOR_TRANSPORT_ERROR;
201
202 /* DATA STAGE */
203 /* send/receive data payload, if there is any */
204
205 if (buf && buf_len) {
206 unsigned int pipe = (dir == DMA_FROM_DEVICE) ?
207 us->recv_bulk_pipe : us->send_bulk_pipe;
208 result = usb_stor_bulk_transfer_buf(us, pipe,
209 buf, buf_len, NULL);
210 if (result == USB_STOR_XFER_ERROR)
211 return USB_STOR_TRANSPORT_ERROR;
212 }
213
214 /* get CSW for device status */
215 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
216 bcs, US_BULK_CS_WRAP_LEN, &cswlen);
217 if (result != USB_STOR_XFER_GOOD)
218 return USB_STOR_TRANSPORT_ERROR;
219
220 /* check bulk status */
221 if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN)) {
222 US_DEBUGP("Signature mismatch: got %08X, expecting %08X\n",
223 le32_to_cpu(bcs->Signature),
224 US_BULK_CS_SIGN);
225 return USB_STOR_TRANSPORT_ERROR;
226 }
227
228 residue = bcs->Residue;
229 if (bcs->Tag != us->tag)
230 return USB_STOR_TRANSPORT_ERROR;
231
232 /* try to compute the actual residue, based on how much data
233 * was really transferred and what the device tells us */
234 if (residue)
235 residue = residue < buf_len ? residue : buf_len;
236
237 if (act_len)
238 *act_len = buf_len - residue;
239
240 /* based on the status code, we report good or bad */
241 switch (bcs->Status) {
242 case US_BULK_STAT_OK:
243 /* command good -- note that data could be short */
244 return USB_STOR_TRANSPORT_GOOD;
245
246 case US_BULK_STAT_FAIL:
247 /* command failed */
248 return USB_STOR_TRANSPORT_FAILED;
249
250 case US_BULK_STAT_PHASE:
251 /* phase error -- note that a transport reset will be
252 * invoked by the invoke_transport() function
253 */
254 return USB_STOR_TRANSPORT_ERROR;
255 }
256
257 /* we should never get here, but if we do, we're in trouble */
258 return USB_STOR_TRANSPORT_ERROR;
259}
260
261/* Determine what the maximum LUN supported is */
262static int rts51x_get_max_lun(struct us_data *us)
263{
264 int result;
265
266 /* issue the command */
267 us->iobuf[0] = 0;
268 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
269 US_BULK_GET_MAX_LUN,
270 USB_DIR_IN | USB_TYPE_CLASS |
271 USB_RECIP_INTERFACE,
272 0, us->ifnum, us->iobuf, 1, 10*HZ);
273
274 US_DEBUGP("GetMaxLUN command result is %d, data is %d\n",
275 result, us->iobuf[0]);
276
277 /* if we have a successful request, return the result */
278 if (result > 0)
279 return us->iobuf[0];
280
281 return 0;
282}
283
284static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
285{
286 int retval;
287 u8 cmnd[12] = {0};
288
289 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
290
291 cmnd[0] = 0xF0;
292 cmnd[1] = 0x0D;
293 cmnd[2] = (u8)(addr >> 8);
294 cmnd[3] = (u8)addr;
295 cmnd[4] = (u8)(len >> 8);
296 cmnd[5] = (u8)len;
297
298 retval = rts51x_bulk_transport(us, 0, cmnd, 12,
299 data, len, DMA_FROM_DEVICE, NULL);
300 if (retval != USB_STOR_TRANSPORT_GOOD)
301 return -EIO;
302
303 return 0;
304}
305
306static int rts51x_write_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
307{
308 int retval;
309 u8 cmnd[12] = {0};
310
311 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
312
313 cmnd[0] = 0xF0;
314 cmnd[1] = 0x0E;
315 cmnd[2] = (u8)(addr >> 8);
316 cmnd[3] = (u8)addr;
317 cmnd[4] = (u8)(len >> 8);
318 cmnd[5] = (u8)len;
319
320 retval = rts51x_bulk_transport(us, 0, cmnd, 12,
321 data, len, DMA_TO_DEVICE, NULL);
322 if (retval != USB_STOR_TRANSPORT_GOOD)
323 return -EIO;
324
325 return 0;
326}
327
328static int rts51x_read_status(struct us_data *us,
329 u8 lun, u8 *status, int len, int *actlen)
330{
331 int retval;
332 u8 cmnd[12] = {0};
333
334 US_DEBUGP("%s, lun = %d\n", __func__, lun);
335
336 cmnd[0] = 0xF0;
337 cmnd[1] = 0x09;
338
339 retval = rts51x_bulk_transport(us, lun, cmnd, 12,
340 status, len, DMA_FROM_DEVICE, actlen);
341 if (retval != USB_STOR_TRANSPORT_GOOD)
342 return -EIO;
343
344 return 0;
345}
346
347static int rts51x_check_status(struct us_data *us, u8 lun)
348{
349 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
350 int retval;
351 u8 buf[16];
352
353 retval = rts51x_read_status(us, lun, buf, 16, &(chip->status_len));
354 if (retval < 0)
355 return -EIO;
356
357 US_DEBUGP("chip->status_len = %d\n", chip->status_len);
358
359 chip->status[lun].vid = ((u16)buf[0] << 8) | buf[1];
360 chip->status[lun].pid = ((u16)buf[2] << 8) | buf[3];
361 chip->status[lun].cur_lun = buf[4];
362 chip->status[lun].card_type = buf[5];
363 chip->status[lun].total_lun = buf[6];
364 chip->status[lun].fw_ver = ((u16)buf[7] << 8) | buf[8];
365 chip->status[lun].phy_exist = buf[9];
366 chip->status[lun].multi_flag = buf[10];
367 chip->status[lun].multi_card = buf[11];
368 chip->status[lun].log_exist = buf[12];
369 if (chip->status_len == 16) {
370 chip->status[lun].detailed_type.detailed_type1 = buf[13];
371 chip->status[lun].function[0] = buf[14];
372 chip->status[lun].function[1] = buf[15];
373 }
374
375 return 0;
376}
377
378static int enable_oscillator(struct us_data *us)
379{
380 int retval;
381 u8 value;
382
383 retval = rts51x_read_mem(us, 0xFE77, &value, 1);
384 if (retval < 0)
385 return -EIO;
386
387 value |= 0x04;
388 retval = rts51x_write_mem(us, 0xFE77, &value, 1);
389 if (retval < 0)
390 return -EIO;
391
392 retval = rts51x_read_mem(us, 0xFE77, &value, 1);
393 if (retval < 0)
394 return -EIO;
395
396 if (!(value & 0x04))
397 return -EIO;
398
399 return 0;
400}
401
402static int do_config_autodelink(struct us_data *us, int enable, int force)
403{
404 int retval;
405 u8 value;
406
407 retval = rts51x_read_mem(us, 0xFE47, &value, 1);
408 if (retval < 0)
409 return -EIO;
410
411 if (enable) {
412 if (force)
413 value |= 0x03;
414 else
415 value |= 0x01;
416 } else {
417 value &= ~0x03;
418 }
419
420 US_DEBUGP("In %s,set 0xfe47 to 0x%x\n", __func__, value);
421
422 retval = rts51x_write_mem(us, 0xFE47, &value, 1);
423 if (retval < 0)
424 return -EIO;
425
426 return 0;
427}
428
429static int config_autodelink_after_power_on(struct us_data *us)
430{
431 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
432 int retval;
433 u8 value;
434
435 if (!CHK_AUTO_DELINK(chip))
436 return 0;
437
438 retval = rts51x_read_mem(us, 0xFE47, &value, 1);
439 if (retval < 0)
440 return -EIO;
441
442 if (auto_delink_en) {
443 CLR_BIT(value, 0);
444 CLR_BIT(value, 1);
445 SET_BIT(value, 2);
446
447 if (CHECK_ID(chip, 0x0138, 0x3882))
448 CLR_BIT(value, 2);
449
450 SET_BIT(value, 7);
451
452 retval = rts51x_write_mem(us, 0xFE47, &value, 1);
453 if (retval < 0)
454 return -EIO;
455
456 retval = enable_oscillator(us);
457 if (retval == 0)
458 (void)do_config_autodelink(us, 1, 0);
459 } else {
460 /* Autodelink controlled by firmware */
461
462 SET_BIT(value, 2);
463
464 if (CHECK_ID(chip, 0x0138, 0x3882))
465 CLR_BIT(value, 2);
466
467 if (CHECK_ID(chip, 0x0159, 0x5889) ||
468 CHECK_ID(chip, 0x0138, 0x3880)) {
469 CLR_BIT(value, 0);
470 CLR_BIT(value, 7);
471 }
472
473 retval = rts51x_write_mem(us, 0xFE47, &value, 1);
474 if (retval < 0)
475 return -EIO;
476
477 if (CHECK_ID(chip, 0x0159, 0x5888)) {
478 value = 0xFF;
479 retval = rts51x_write_mem(us, 0xFE79, &value, 1);
480 if (retval < 0)
481 return -EIO;
482
483 value = 0x01;
484 retval = rts51x_write_mem(us, 0x48, &value, 1);
485 if (retval < 0)
486 return -EIO;
487 }
488 }
489
490 return 0;
491}
492
493static int config_autodelink_before_power_down(struct us_data *us)
494{
495 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
496 int retval;
497 u8 value;
498
499 if (!CHK_AUTO_DELINK(chip))
500 return 0;
501
502 if (auto_delink_en) {
503 retval = rts51x_read_mem(us, 0xFE77, &value, 1);
504 if (retval < 0)
505 return -EIO;
506
507 SET_BIT(value, 2);
508 retval = rts51x_write_mem(us, 0xFE77, &value, 1);
509 if (retval < 0)
510 return -EIO;
511
512 if (CHECK_ID(chip, 0x0159, 0x5888)) {
513 value = 0x01;
514 retval = rts51x_write_mem(us, 0x48, &value, 1);
515 if (retval < 0)
516 return -EIO;
517 }
518
519 retval = rts51x_read_mem(us, 0xFE47, &value, 1);
520 if (retval < 0)
521 return -EIO;
522
523 SET_BIT(value, 0);
524 if (CHECK_ID(chip, 0x0138, 0x3882))
525 SET_BIT(value, 2);
526 retval = rts51x_write_mem(us, 0xFE77, &value, 1);
527 if (retval < 0)
528 return -EIO;
529 } else {
530 if (CHECK_ID(chip, 0x0159, 0x5889) ||
531 CHECK_ID(chip, 0x0138, 0x3880) ||
532 CHECK_ID(chip, 0x0138, 0x3882)) {
533 retval = rts51x_read_mem(us, 0xFE47, &value, 1);
534 if (retval < 0)
535 return -EIO;
536
537 if (CHECK_ID(chip, 0x0159, 0x5889) ||
538 CHECK_ID(chip, 0x0138, 0x3880)) {
539 SET_BIT(value, 0);
540 SET_BIT(value, 7);
541 }
542
543 if (CHECK_ID(chip, 0x0138, 0x3882))
544 SET_BIT(value, 2);
545
546 retval = rts51x_write_mem(us, 0xFE47, &value, 1);
547 if (retval < 0)
548 return -EIO;
549 }
550
551 if (CHECK_ID(chip, 0x0159, 0x5888)) {
552 value = 0x01;
553 retval = rts51x_write_mem(us, 0x48, &value, 1);
554 if (retval < 0)
555 return -EIO;
556 }
557 }
558
559 return 0;
560}
561
562static void realtek_cr_destructor(void *extra)
563{
564 struct rts51x_chip *chip = (struct rts51x_chip *)extra;
565
566 if (!chip)
567 return;
568
569 kfree(chip->status);
570}
571
572#ifdef CONFIG_PM
573static void realtek_pm_hook(struct us_data *us, int pm_state)
574{
575 if (pm_state == US_SUSPEND)
576 (void)config_autodelink_before_power_down(us);
577}
578#endif
579
580static int init_realtek_cr(struct us_data *us)
581{
582 struct rts51x_chip *chip;
583 int size, i, retval;
584
585 chip = kzalloc(sizeof(struct rts51x_chip), GFP_KERNEL);
586 if (!chip)
587 return -ENOMEM;
588
589 us->extra = chip;
590 us->extra_destructor = realtek_cr_destructor;
591#ifdef CONFIG_PM
592 us->suspend_resume_hook = realtek_pm_hook;
593#endif
594
595 us->max_lun = chip->max_lun = rts51x_get_max_lun(us);
596
597 US_DEBUGP("chip->max_lun = %d\n", chip->max_lun);
598
599 size = (chip->max_lun + 1) * sizeof(struct rts51x_status);
600 chip->status = kzalloc(size, GFP_KERNEL);
601 if (!chip->status)
602 goto INIT_FAIL;
603
604 for (i = 0; i <= (int)(chip->max_lun); i++) {
605 retval = rts51x_check_status(us, (u8)i);
606 if (retval < 0)
607 goto INIT_FAIL;
608 }
609
610 if (CHECK_FW_VER(chip, 0x5888) || CHECK_FW_VER(chip, 0x5889) ||
611 CHECK_FW_VER(chip, 0x5901))
612 SET_AUTO_DELINK(chip);
613 if (STATUS_LEN(chip) == 16) {
614 if (SUPPORT_AUTO_DELINK(chip))
615 SET_AUTO_DELINK(chip);
616 }
617
618 US_DEBUGP("chip->flag = 0x%x\n", chip->flag);
619
620 (void)config_autodelink_after_power_on(us);
621
622 return 0;
623
624INIT_FAIL:
625 if (us->extra) {
626 kfree(chip->status);
627 kfree(us->extra);
628 us->extra = NULL;
629 }
630
631 return -EIO;
632}
633
634static int realtek_cr_probe(struct usb_interface *intf,
635 const struct usb_device_id *id)
636{
637 struct us_data *us;
638 int result;
639
640 US_DEBUGP("Probe Realtek Card Reader!\n");
641
642 result = usb_stor_probe1(&us, intf, id,
643 (id - realtek_cr_ids) + realtek_cr_unusual_dev_list);
644 if (result)
645 return result;
646
647 result = usb_stor_probe2(us);
648 return result;
649}
650
651static struct usb_driver realtek_cr_driver = {
652 .name = "ums-realtek",
653 .probe = realtek_cr_probe,
654 .disconnect = usb_stor_disconnect,
655 .suspend = usb_stor_suspend,
656 .resume = usb_stor_resume,
657 .reset_resume = usb_stor_reset_resume,
658 .pre_reset = usb_stor_pre_reset,
659 .post_reset = usb_stor_post_reset,
660 .id_table = realtek_cr_ids,
661 .soft_unbind = 1,
662};
663
664static int __init realtek_cr_init(void)
665{
666 return usb_register(&realtek_cr_driver);
667}
668
669static void __exit realtek_cr_exit(void)
670{
671 usb_deregister(&realtek_cr_driver);
672}
673
674module_init(realtek_cr_init);
675module_exit(realtek_cr_exit);
diff --git a/drivers/usb/storage/sierra_ms.c b/drivers/usb/storage/sierra_ms.c
index ceba512f84d0..1deca07c8265 100644
--- a/drivers/usb/storage/sierra_ms.c
+++ b/drivers/usb/storage/sierra_ms.c
@@ -126,13 +126,11 @@ static DEVICE_ATTR(truinst, S_IRUGO, show_truinst, NULL);
126int sierra_ms_init(struct us_data *us) 126int sierra_ms_init(struct us_data *us)
127{ 127{
128 int result, retries; 128 int result, retries;
129 signed long delay_t;
130 struct swoc_info *swocInfo; 129 struct swoc_info *swocInfo;
131 struct usb_device *udev; 130 struct usb_device *udev;
132 struct Scsi_Host *sh; 131 struct Scsi_Host *sh;
133 struct scsi_device *sd; 132 struct scsi_device *sd;
134 133
135 delay_t = 2;
136 retries = 3; 134 retries = 3;
137 result = 0; 135 result = 0;
138 udev = us->pusb_dev; 136 udev = us->pusb_dev;
diff --git a/drivers/usb/storage/unusual_realtek.h b/drivers/usb/storage/unusual_realtek.h
new file mode 100644
index 000000000000..3236e0328516
--- /dev/null
+++ b/drivers/usb/storage/unusual_realtek.h
@@ -0,0 +1,41 @@
1/* Driver for Realtek RTS51xx USB card reader
2 *
3 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
8 * later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 * wwang (wei_wang@realsil.com.cn)
20 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
21 */
22
23#if defined(CONFIG_USB_STORAGE_REALTEK) || \
24 defined(CONFIG_USB_STORAGE_REALTEK_MODULE)
25
26UNUSUAL_DEV(0x0bda, 0x0159, 0x0000, 0x9999,
27 "Realtek",
28 "USB Card Reader",
29 USB_SC_SCSI, USB_PR_BULK, init_realtek_cr, 0),
30
31UNUSUAL_DEV(0x0bda, 0x0158, 0x0000, 0x9999,
32 "Realtek",
33 "USB Card Reader",
34 USB_SC_SCSI, USB_PR_BULK, init_realtek_cr, 0),
35
36UNUSUAL_DEV(0x0bda, 0x0138, 0x0000, 0x9999,
37 "Realtek",
38 "USB Card Reader",
39 USB_SC_SCSI, USB_PR_BULK, init_realtek_cr, 0),
40
41#endif /* defined(CONFIG_USB_STORAGE_REALTEK) || ... */
diff --git a/drivers/usb/storage/usual-tables.c b/drivers/usb/storage/usual-tables.c
index 468bde7d1971..4293077c01aa 100644
--- a/drivers/usb/storage/usual-tables.c
+++ b/drivers/usb/storage/usual-tables.c
@@ -85,6 +85,7 @@ static struct ignore_entry ignore_ids[] = {
85# include "unusual_jumpshot.h" 85# include "unusual_jumpshot.h"
86# include "unusual_karma.h" 86# include "unusual_karma.h"
87# include "unusual_onetouch.h" 87# include "unusual_onetouch.h"
88# include "unusual_realtek.h"
88# include "unusual_sddr09.h" 89# include "unusual_sddr09.h"
89# include "unusual_sddr55.h" 90# include "unusual_sddr55.h"
90# include "unusual_usbat.h" 91# include "unusual_usbat.h"
diff --git a/drivers/usb/wusbcore/rh.c b/drivers/usb/wusbcore/rh.c
index a68ad7aa0b59..c175b7300c73 100644
--- a/drivers/usb/wusbcore/rh.c
+++ b/drivers/usb/wusbcore/rh.c
@@ -156,7 +156,7 @@ int wusbhc_rh_status_data(struct usb_hcd *usb_hcd, char *_buf)
156EXPORT_SYMBOL_GPL(wusbhc_rh_status_data); 156EXPORT_SYMBOL_GPL(wusbhc_rh_status_data);
157 157
158/* 158/*
159 * Return the hub's desciptor 159 * Return the hub's descriptor
160 * 160 *
161 * NOTE: almost cut and paste from ehci-hub.c 161 * NOTE: almost cut and paste from ehci-hub.c
162 * 162 *
@@ -184,8 +184,8 @@ static int wusbhc_rh_get_hub_descr(struct wusbhc *wusbhc, u16 wValue,
184 descr->bPwrOn2PwrGood = 0; 184 descr->bPwrOn2PwrGood = 0;
185 descr->bHubContrCurrent = 0; 185 descr->bHubContrCurrent = 0;
186 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 186 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
187 memset(&descr->bitmap[0], 0, temp); 187 memset(&descr->u.hs.DeviceRemovable[0], 0, temp);
188 memset(&descr->bitmap[temp], 0xff, temp); 188 memset(&descr->u.hs.DeviceRemovable[temp], 0xff, temp);
189 return 0; 189 return 0;
190} 190}
191 191
diff --git a/drivers/usb/wusbcore/wusbhc.c b/drivers/usb/wusbcore/wusbhc.c
index 2054d4ee9774..0faca16df765 100644
--- a/drivers/usb/wusbcore/wusbhc.c
+++ b/drivers/usb/wusbcore/wusbhc.c
@@ -320,7 +320,7 @@ u8 wusb_cluster_id_get(void)
320 u8 id; 320 u8 id;
321 spin_lock(&wusb_cluster_ids_lock); 321 spin_lock(&wusb_cluster_ids_lock);
322 id = find_first_zero_bit(wusb_cluster_id_table, CLUSTER_IDS); 322 id = find_first_zero_bit(wusb_cluster_id_table, CLUSTER_IDS);
323 if (id > CLUSTER_IDS) { 323 if (id >= CLUSTER_IDS) {
324 id = 0; 324 id = 0;
325 goto out; 325 goto out;
326 } 326 }
diff --git a/drivers/usb/wusbcore/wusbhc.h b/drivers/usb/wusbcore/wusbhc.h
index 3d94c4247f46..6bd426b7ec07 100644
--- a/drivers/usb/wusbcore/wusbhc.h
+++ b/drivers/usb/wusbcore/wusbhc.h
@@ -132,7 +132,7 @@ static inline void wusb_dev_put(struct wusb_dev *wusb_dev)
132} 132}
133 133
134/** 134/**
135 * Wireless USB Host Controlller root hub "fake" ports 135 * Wireless USB Host Controller root hub "fake" ports
136 * (state and device information) 136 * (state and device information)
137 * 137 *
138 * Wireless USB is wireless, so there are no ports; but we 138 * Wireless USB is wireless, so there are no ports; but we
diff --git a/drivers/uwb/scan.c b/drivers/uwb/scan.c
index 76a1a1ed7d3e..367aa12786b9 100644
--- a/drivers/uwb/scan.c
+++ b/drivers/uwb/scan.c
@@ -42,7 +42,7 @@
42/** 42/**
43 * Start/stop scanning in a radio controller 43 * Start/stop scanning in a radio controller
44 * 44 *
45 * @rc: UWB Radio Controlller 45 * @rc: UWB Radio Controller
46 * @channel: Channel to scan; encodings in WUSB1.0[Table 5.12] 46 * @channel: Channel to scan; encodings in WUSB1.0[Table 5.12]
47 * @type: Type of scanning to do. 47 * @type: Type of scanning to do.
48 * @bpst_offset: value at which to start scanning (if type == 48 * @bpst_offset: value at which to start scanning (if type ==