xref: /OK3568_Linux_fs/kernel/drivers/usb/host/ehci-hub.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0+
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) 2001-2004 by David Brownell
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun /* this file is part of ehci-hcd.c */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /*
11*4882a593Smuzhiyun  * EHCI Root Hub ... the nonsharable stuff
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * Registers don't need cpu_to_le32, that happens transparently
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #define	PORT_WAKE_BITS	(PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #ifdef	CONFIG_PM
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun static void unlink_empty_async_suspended(struct ehci_hcd *ehci);
23*4882a593Smuzhiyun 
persist_enabled_on_companion(struct usb_device * udev,void * unused)24*4882a593Smuzhiyun static int persist_enabled_on_companion(struct usb_device *udev, void *unused)
25*4882a593Smuzhiyun {
26*4882a593Smuzhiyun 	return !udev->maxchild && udev->persist_enabled &&
27*4882a593Smuzhiyun 		udev->bus->root_hub->speed < USB_SPEED_HIGH;
28*4882a593Smuzhiyun }
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* After a power loss, ports that were owned by the companion must be
31*4882a593Smuzhiyun  * reset so that the companion can still own them.
32*4882a593Smuzhiyun  */
ehci_handover_companion_ports(struct ehci_hcd * ehci)33*4882a593Smuzhiyun static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun 	u32 __iomem	*reg;
36*4882a593Smuzhiyun 	u32		status;
37*4882a593Smuzhiyun 	int		port;
38*4882a593Smuzhiyun 	__le32		buf;
39*4882a593Smuzhiyun 	struct usb_hcd	*hcd = ehci_to_hcd(ehci);
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 	if (!ehci->owned_ports)
42*4882a593Smuzhiyun 		return;
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun 	/*
45*4882a593Smuzhiyun 	 * USB 1.1 devices are mostly HIDs, which don't need to persist across
46*4882a593Smuzhiyun 	 * suspends. If we ensure that none of our companion's devices have
47*4882a593Smuzhiyun 	 * persist_enabled (by looking through all USB 1.1 buses in the system),
48*4882a593Smuzhiyun 	 * we can skip this and avoid slowing resume down. Devices without
49*4882a593Smuzhiyun 	 * persist will just get reenumerated shortly after resume anyway.
50*4882a593Smuzhiyun 	 */
51*4882a593Smuzhiyun 	if (!usb_for_each_dev(NULL, persist_enabled_on_companion))
52*4882a593Smuzhiyun 		return;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	/* Make sure the ports are powered */
55*4882a593Smuzhiyun 	port = HCS_N_PORTS(ehci->hcs_params);
56*4882a593Smuzhiyun 	while (port--) {
57*4882a593Smuzhiyun 		if (test_bit(port, &ehci->owned_ports)) {
58*4882a593Smuzhiyun 			reg = &ehci->regs->port_status[port];
59*4882a593Smuzhiyun 			status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
60*4882a593Smuzhiyun 			if (!(status & PORT_POWER))
61*4882a593Smuzhiyun 				ehci_port_power(ehci, port, true);
62*4882a593Smuzhiyun 		}
63*4882a593Smuzhiyun 	}
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	/* Give the connections some time to appear */
66*4882a593Smuzhiyun 	msleep(20);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun 	spin_lock_irq(&ehci->lock);
69*4882a593Smuzhiyun 	port = HCS_N_PORTS(ehci->hcs_params);
70*4882a593Smuzhiyun 	while (port--) {
71*4882a593Smuzhiyun 		if (test_bit(port, &ehci->owned_ports)) {
72*4882a593Smuzhiyun 			reg = &ehci->regs->port_status[port];
73*4882a593Smuzhiyun 			status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 			/* Port already owned by companion? */
76*4882a593Smuzhiyun 			if (status & PORT_OWNER)
77*4882a593Smuzhiyun 				clear_bit(port, &ehci->owned_ports);
78*4882a593Smuzhiyun 			else if (test_bit(port, &ehci->companion_ports))
79*4882a593Smuzhiyun 				ehci_writel(ehci, status & ~PORT_PE, reg);
80*4882a593Smuzhiyun 			else {
81*4882a593Smuzhiyun 				spin_unlock_irq(&ehci->lock);
82*4882a593Smuzhiyun 				ehci_hub_control(hcd, SetPortFeature,
83*4882a593Smuzhiyun 						USB_PORT_FEAT_RESET, port + 1,
84*4882a593Smuzhiyun 						NULL, 0);
85*4882a593Smuzhiyun 				spin_lock_irq(&ehci->lock);
86*4882a593Smuzhiyun 			}
87*4882a593Smuzhiyun 		}
88*4882a593Smuzhiyun 	}
89*4882a593Smuzhiyun 	spin_unlock_irq(&ehci->lock);
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 	if (!ehci->owned_ports)
92*4882a593Smuzhiyun 		return;
93*4882a593Smuzhiyun 	msleep(90);		/* Wait for resets to complete */
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun 	spin_lock_irq(&ehci->lock);
96*4882a593Smuzhiyun 	port = HCS_N_PORTS(ehci->hcs_params);
97*4882a593Smuzhiyun 	while (port--) {
98*4882a593Smuzhiyun 		if (test_bit(port, &ehci->owned_ports)) {
99*4882a593Smuzhiyun 			spin_unlock_irq(&ehci->lock);
100*4882a593Smuzhiyun 			ehci_hub_control(hcd, GetPortStatus,
101*4882a593Smuzhiyun 					0, port + 1,
102*4882a593Smuzhiyun 					(char *) &buf, sizeof(buf));
103*4882a593Smuzhiyun 			spin_lock_irq(&ehci->lock);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 			/* The companion should now own the port,
106*4882a593Smuzhiyun 			 * but if something went wrong the port must not
107*4882a593Smuzhiyun 			 * remain enabled.
108*4882a593Smuzhiyun 			 */
109*4882a593Smuzhiyun 			reg = &ehci->regs->port_status[port];
110*4882a593Smuzhiyun 			status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
111*4882a593Smuzhiyun 			if (status & PORT_OWNER)
112*4882a593Smuzhiyun 				ehci_writel(ehci, status | PORT_CSC, reg);
113*4882a593Smuzhiyun 			else {
114*4882a593Smuzhiyun 				ehci_dbg(ehci, "failed handover port %d: %x\n",
115*4882a593Smuzhiyun 						port + 1, status);
116*4882a593Smuzhiyun 				ehci_writel(ehci, status & ~PORT_PE, reg);
117*4882a593Smuzhiyun 			}
118*4882a593Smuzhiyun 		}
119*4882a593Smuzhiyun 	}
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun 	ehci->owned_ports = 0;
122*4882a593Smuzhiyun 	spin_unlock_irq(&ehci->lock);
123*4882a593Smuzhiyun }
124*4882a593Smuzhiyun 
ehci_port_change(struct ehci_hcd * ehci)125*4882a593Smuzhiyun static int ehci_port_change(struct ehci_hcd *ehci)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun 	int i = HCS_N_PORTS(ehci->hcs_params);
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	/* First check if the controller indicates a change event */
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun 	if (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)
132*4882a593Smuzhiyun 		return 1;
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun 	/*
135*4882a593Smuzhiyun 	 * Not all controllers appear to update this while going from D3 to D0,
136*4882a593Smuzhiyun 	 * so check the individual port status registers as well
137*4882a593Smuzhiyun 	 */
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun 	while (i--)
140*4882a593Smuzhiyun 		if (ehci_readl(ehci, &ehci->regs->port_status[i]) & PORT_CSC)
141*4882a593Smuzhiyun 			return 1;
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	return 0;
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun 
ehci_adjust_port_wakeup_flags(struct ehci_hcd * ehci,bool suspending,bool do_wakeup)146*4882a593Smuzhiyun void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
147*4882a593Smuzhiyun 		bool suspending, bool do_wakeup)
148*4882a593Smuzhiyun {
149*4882a593Smuzhiyun 	int		port;
150*4882a593Smuzhiyun 	u32		temp;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	/* If remote wakeup is enabled for the root hub but disabled
153*4882a593Smuzhiyun 	 * for the controller, we must adjust all the port wakeup flags
154*4882a593Smuzhiyun 	 * when the controller is suspended or resumed.  In all other
155*4882a593Smuzhiyun 	 * cases they don't need to be changed.
156*4882a593Smuzhiyun 	 */
157*4882a593Smuzhiyun 	if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
158*4882a593Smuzhiyun 		return;
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 	spin_lock_irq(&ehci->lock);
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	/* clear phy low-power mode before changing wakeup flags */
163*4882a593Smuzhiyun 	if (ehci->has_tdi_phy_lpm) {
164*4882a593Smuzhiyun 		port = HCS_N_PORTS(ehci->hcs_params);
165*4882a593Smuzhiyun 		while (port--) {
166*4882a593Smuzhiyun 			u32 __iomem	*hostpc_reg = &ehci->regs->hostpc[port];
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 			temp = ehci_readl(ehci, hostpc_reg);
169*4882a593Smuzhiyun 			ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
170*4882a593Smuzhiyun 		}
171*4882a593Smuzhiyun 		spin_unlock_irq(&ehci->lock);
172*4882a593Smuzhiyun 		msleep(5);
173*4882a593Smuzhiyun 		spin_lock_irq(&ehci->lock);
174*4882a593Smuzhiyun 	}
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	port = HCS_N_PORTS(ehci->hcs_params);
177*4882a593Smuzhiyun 	while (port--) {
178*4882a593Smuzhiyun 		u32 __iomem	*reg = &ehci->regs->port_status[port];
179*4882a593Smuzhiyun 		u32		t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
180*4882a593Smuzhiyun 		u32		t2 = t1 & ~PORT_WAKE_BITS;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 		/* If we are suspending the controller, clear the flags.
183*4882a593Smuzhiyun 		 * If we are resuming the controller, set the wakeup flags.
184*4882a593Smuzhiyun 		 */
185*4882a593Smuzhiyun 		if (!suspending) {
186*4882a593Smuzhiyun 			if (t1 & PORT_CONNECT)
187*4882a593Smuzhiyun 				t2 |= PORT_WKOC_E | PORT_WKDISC_E;
188*4882a593Smuzhiyun 			else
189*4882a593Smuzhiyun 				t2 |= PORT_WKOC_E | PORT_WKCONN_E;
190*4882a593Smuzhiyun 		}
191*4882a593Smuzhiyun 		ehci_writel(ehci, t2, reg);
192*4882a593Smuzhiyun 	}
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun 	/* enter phy low-power mode again */
195*4882a593Smuzhiyun 	if (ehci->has_tdi_phy_lpm) {
196*4882a593Smuzhiyun 		port = HCS_N_PORTS(ehci->hcs_params);
197*4882a593Smuzhiyun 		while (port--) {
198*4882a593Smuzhiyun 			u32 __iomem	*hostpc_reg = &ehci->regs->hostpc[port];
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 			temp = ehci_readl(ehci, hostpc_reg);
201*4882a593Smuzhiyun 			ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
202*4882a593Smuzhiyun 		}
203*4882a593Smuzhiyun 	}
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	/* Does the root hub have a port wakeup pending? */
206*4882a593Smuzhiyun 	if (!suspending && ehci_port_change(ehci))
207*4882a593Smuzhiyun 		usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	spin_unlock_irq(&ehci->lock);
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(ehci_adjust_port_wakeup_flags);
212*4882a593Smuzhiyun 
ehci_bus_suspend(struct usb_hcd * hcd)213*4882a593Smuzhiyun static int ehci_bus_suspend (struct usb_hcd *hcd)
214*4882a593Smuzhiyun {
215*4882a593Smuzhiyun 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
216*4882a593Smuzhiyun 	int			port;
217*4882a593Smuzhiyun 	int			mask;
218*4882a593Smuzhiyun 	int			changed;
219*4882a593Smuzhiyun 	bool			fs_idle_delay;
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun 	ehci_dbg(ehci, "suspend root hub\n");
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun 	if (time_before (jiffies, ehci->next_statechange))
224*4882a593Smuzhiyun 		msleep(5);
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun 	/* stop the schedules */
227*4882a593Smuzhiyun 	ehci_quiesce(ehci);
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun 	spin_lock_irq (&ehci->lock);
230*4882a593Smuzhiyun 	if (ehci->rh_state < EHCI_RH_RUNNING)
231*4882a593Smuzhiyun 		goto done;
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun 	/* Once the controller is stopped, port resumes that are already
234*4882a593Smuzhiyun 	 * in progress won't complete.  Hence if remote wakeup is enabled
235*4882a593Smuzhiyun 	 * for the root hub and any ports are in the middle of a resume or
236*4882a593Smuzhiyun 	 * remote wakeup, we must fail the suspend.
237*4882a593Smuzhiyun 	 */
238*4882a593Smuzhiyun 	if (hcd->self.root_hub->do_remote_wakeup) {
239*4882a593Smuzhiyun 		if (ehci->resuming_ports) {
240*4882a593Smuzhiyun 			spin_unlock_irq(&ehci->lock);
241*4882a593Smuzhiyun 			ehci_dbg(ehci, "suspend failed because a port is resuming\n");
242*4882a593Smuzhiyun 			return -EBUSY;
243*4882a593Smuzhiyun 		}
244*4882a593Smuzhiyun 	}
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun 	/* Unlike other USB host controller types, EHCI doesn't have
247*4882a593Smuzhiyun 	 * any notion of "global" or bus-wide suspend.  The driver has
248*4882a593Smuzhiyun 	 * to manually suspend all the active unsuspended ports, and
249*4882a593Smuzhiyun 	 * then manually resume them in the bus_resume() routine.
250*4882a593Smuzhiyun 	 */
251*4882a593Smuzhiyun 	ehci->bus_suspended = 0;
252*4882a593Smuzhiyun 	ehci->owned_ports = 0;
253*4882a593Smuzhiyun 	changed = 0;
254*4882a593Smuzhiyun 	fs_idle_delay = false;
255*4882a593Smuzhiyun 	port = HCS_N_PORTS(ehci->hcs_params);
256*4882a593Smuzhiyun 	while (port--) {
257*4882a593Smuzhiyun 		u32 __iomem	*reg = &ehci->regs->port_status [port];
258*4882a593Smuzhiyun 		u32		t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
259*4882a593Smuzhiyun 		u32		t2 = t1 & ~PORT_WAKE_BITS;
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun 		/* keep track of which ports we suspend */
262*4882a593Smuzhiyun 		if (t1 & PORT_OWNER)
263*4882a593Smuzhiyun 			set_bit(port, &ehci->owned_ports);
264*4882a593Smuzhiyun 		else if ((t1 & PORT_PE) && !(t1 & PORT_SUSPEND)) {
265*4882a593Smuzhiyun 			t2 |= PORT_SUSPEND;
266*4882a593Smuzhiyun 			set_bit(port, &ehci->bus_suspended);
267*4882a593Smuzhiyun 		}
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun 		/* enable remote wakeup on all ports, if told to do so */
270*4882a593Smuzhiyun 		if (hcd->self.root_hub->do_remote_wakeup) {
271*4882a593Smuzhiyun 			/* only enable appropriate wake bits, otherwise the
272*4882a593Smuzhiyun 			 * hardware can not go phy low power mode. If a race
273*4882a593Smuzhiyun 			 * condition happens here(connection change during bits
274*4882a593Smuzhiyun 			 * set), the port change detection will finally fix it.
275*4882a593Smuzhiyun 			 */
276*4882a593Smuzhiyun 			if (t1 & PORT_CONNECT)
277*4882a593Smuzhiyun 				t2 |= PORT_WKOC_E | PORT_WKDISC_E;
278*4882a593Smuzhiyun 			else
279*4882a593Smuzhiyun 				t2 |= PORT_WKOC_E | PORT_WKCONN_E;
280*4882a593Smuzhiyun 		}
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun 		if (t1 != t2) {
283*4882a593Smuzhiyun 			/*
284*4882a593Smuzhiyun 			 * On some controllers, Wake-On-Disconnect will
285*4882a593Smuzhiyun 			 * generate false wakeup signals until the bus
286*4882a593Smuzhiyun 			 * switches over to full-speed idle.  For their
287*4882a593Smuzhiyun 			 * sake, add a delay if we need one.
288*4882a593Smuzhiyun 			 */
289*4882a593Smuzhiyun 			if ((t2 & PORT_WKDISC_E) &&
290*4882a593Smuzhiyun 					ehci_port_speed(ehci, t2) ==
291*4882a593Smuzhiyun 						USB_PORT_STAT_HIGH_SPEED)
292*4882a593Smuzhiyun 				fs_idle_delay = true;
293*4882a593Smuzhiyun 			ehci_writel(ehci, t2, reg);
294*4882a593Smuzhiyun 			changed = 1;
295*4882a593Smuzhiyun 		}
296*4882a593Smuzhiyun 	}
297*4882a593Smuzhiyun 	spin_unlock_irq(&ehci->lock);
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun 	if (changed && ehci_has_fsl_susp_errata(ehci))
300*4882a593Smuzhiyun 		/*
301*4882a593Smuzhiyun 		 * Wait for at least 10 millisecondes to ensure the controller
302*4882a593Smuzhiyun 		 * enter the suspend status before initiating a port resume
303*4882a593Smuzhiyun 		 * using the Force Port Resume bit (Not-EHCI compatible).
304*4882a593Smuzhiyun 		 */
305*4882a593Smuzhiyun 		usleep_range(10000, 20000);
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun 	if ((changed && ehci->has_tdi_phy_lpm) || fs_idle_delay) {
308*4882a593Smuzhiyun 		/*
309*4882a593Smuzhiyun 		 * Wait for HCD to enter low-power mode or for the bus
310*4882a593Smuzhiyun 		 * to switch to full-speed idle.
311*4882a593Smuzhiyun 		 */
312*4882a593Smuzhiyun 		usleep_range(5000, 5500);
313*4882a593Smuzhiyun 	}
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun 	if (changed && ehci->has_tdi_phy_lpm) {
316*4882a593Smuzhiyun 		spin_lock_irq(&ehci->lock);
317*4882a593Smuzhiyun 		port = HCS_N_PORTS(ehci->hcs_params);
318*4882a593Smuzhiyun 		while (port--) {
319*4882a593Smuzhiyun 			u32 __iomem	*hostpc_reg = &ehci->regs->hostpc[port];
320*4882a593Smuzhiyun 			u32		t3;
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun 			t3 = ehci_readl(ehci, hostpc_reg);
323*4882a593Smuzhiyun 			ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
324*4882a593Smuzhiyun 			t3 = ehci_readl(ehci, hostpc_reg);
325*4882a593Smuzhiyun 			ehci_dbg(ehci, "Port %d phy low-power mode %s\n",
326*4882a593Smuzhiyun 					port, (t3 & HOSTPC_PHCD) ?
327*4882a593Smuzhiyun 					"succeeded" : "failed");
328*4882a593Smuzhiyun 		}
329*4882a593Smuzhiyun 		spin_unlock_irq(&ehci->lock);
330*4882a593Smuzhiyun 	}
331*4882a593Smuzhiyun 
332*4882a593Smuzhiyun 	/* Apparently some devices need a >= 1-uframe delay here */
333*4882a593Smuzhiyun 	if (ehci->bus_suspended)
334*4882a593Smuzhiyun 		udelay(150);
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 	/* turn off now-idle HC */
337*4882a593Smuzhiyun 	ehci_halt (ehci);
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun 	spin_lock_irq(&ehci->lock);
340*4882a593Smuzhiyun 	if (ehci->enabled_hrtimer_events & BIT(EHCI_HRTIMER_POLL_DEAD))
341*4882a593Smuzhiyun 		ehci_handle_controller_death(ehci);
342*4882a593Smuzhiyun 	if (ehci->rh_state != EHCI_RH_RUNNING)
343*4882a593Smuzhiyun 		goto done;
344*4882a593Smuzhiyun 	ehci->rh_state = EHCI_RH_SUSPENDED;
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun 	unlink_empty_async_suspended(ehci);
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun 	/* Some Synopsys controllers mistakenly leave IAA turned on */
349*4882a593Smuzhiyun 	ehci_writel(ehci, STS_IAA, &ehci->regs->status);
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	/* Any IAA cycle that started before the suspend is now invalid */
352*4882a593Smuzhiyun 	end_iaa_cycle(ehci);
353*4882a593Smuzhiyun 	ehci_handle_start_intr_unlinks(ehci);
354*4882a593Smuzhiyun 	ehci_handle_intr_unlinks(ehci);
355*4882a593Smuzhiyun 	end_free_itds(ehci);
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun 	/* allow remote wakeup */
358*4882a593Smuzhiyun 	mask = INTR_MASK;
359*4882a593Smuzhiyun 	if (!hcd->self.root_hub->do_remote_wakeup)
360*4882a593Smuzhiyun 		mask &= ~STS_PCD;
361*4882a593Smuzhiyun 	ehci_writel(ehci, mask, &ehci->regs->intr_enable);
362*4882a593Smuzhiyun 	ehci_readl(ehci, &ehci->regs->intr_enable);
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun  done:
365*4882a593Smuzhiyun 	ehci->next_statechange = jiffies + msecs_to_jiffies(10);
366*4882a593Smuzhiyun 	ehci->enabled_hrtimer_events = 0;
367*4882a593Smuzhiyun 	ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
368*4882a593Smuzhiyun 	spin_unlock_irq (&ehci->lock);
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun 	hrtimer_cancel(&ehci->hrtimer);
371*4882a593Smuzhiyun 	return 0;
372*4882a593Smuzhiyun }
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun /* caller has locked the root hub, and should reset/reinit on error */
ehci_bus_resume(struct usb_hcd * hcd)376*4882a593Smuzhiyun static int ehci_bus_resume (struct usb_hcd *hcd)
377*4882a593Smuzhiyun {
378*4882a593Smuzhiyun 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
379*4882a593Smuzhiyun 	u32			temp;
380*4882a593Smuzhiyun 	u32			power_okay;
381*4882a593Smuzhiyun 	int			i;
382*4882a593Smuzhiyun 	unsigned long		resume_needed = 0;
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun 	if (time_before (jiffies, ehci->next_statechange))
385*4882a593Smuzhiyun 		msleep(5);
386*4882a593Smuzhiyun 	spin_lock_irq (&ehci->lock);
387*4882a593Smuzhiyun 	if (!HCD_HW_ACCESSIBLE(hcd) || ehci->shutdown)
388*4882a593Smuzhiyun 		goto shutdown;
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 	if (unlikely(ehci->debug)) {
391*4882a593Smuzhiyun 		if (!dbgp_reset_prep(hcd))
392*4882a593Smuzhiyun 			ehci->debug = NULL;
393*4882a593Smuzhiyun 		else
394*4882a593Smuzhiyun 			dbgp_external_startup(hcd);
395*4882a593Smuzhiyun 	}
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun 	/* Ideally and we've got a real resume here, and no port's power
398*4882a593Smuzhiyun 	 * was lost.  (For PCI, that means Vaux was maintained.)  But we
399*4882a593Smuzhiyun 	 * could instead be restoring a swsusp snapshot -- so that BIOS was
400*4882a593Smuzhiyun 	 * the last user of the controller, not reset/pm hardware keeping
401*4882a593Smuzhiyun 	 * state we gave to it.
402*4882a593Smuzhiyun 	 */
403*4882a593Smuzhiyun 	power_okay = ehci_readl(ehci, &ehci->regs->intr_enable);
404*4882a593Smuzhiyun 	ehci_dbg(ehci, "resume root hub%s\n",
405*4882a593Smuzhiyun 			power_okay ? "" : " after power loss");
406*4882a593Smuzhiyun 
407*4882a593Smuzhiyun 	/* at least some APM implementations will try to deliver
408*4882a593Smuzhiyun 	 * IRQs right away, so delay them until we're ready.
409*4882a593Smuzhiyun 	 */
410*4882a593Smuzhiyun 	ehci_writel(ehci, 0, &ehci->regs->intr_enable);
411*4882a593Smuzhiyun 
412*4882a593Smuzhiyun 	/* re-init operational registers */
413*4882a593Smuzhiyun 	ehci_writel(ehci, 0, &ehci->regs->segment);
414*4882a593Smuzhiyun 	ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
415*4882a593Smuzhiyun 	ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun 	/* restore CMD_RUN, framelist size, and irq threshold */
418*4882a593Smuzhiyun 	ehci->command |= CMD_RUN;
419*4882a593Smuzhiyun 	ehci_writel(ehci, ehci->command, &ehci->regs->command);
420*4882a593Smuzhiyun 	ehci->rh_state = EHCI_RH_RUNNING;
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun 	/*
423*4882a593Smuzhiyun 	 * According to Bugzilla #8190, the port status for some controllers
424*4882a593Smuzhiyun 	 * will be wrong without a delay. At their wrong status, the port
425*4882a593Smuzhiyun 	 * is enabled, but not suspended neither resumed.
426*4882a593Smuzhiyun 	 */
427*4882a593Smuzhiyun 	i = HCS_N_PORTS(ehci->hcs_params);
428*4882a593Smuzhiyun 	while (i--) {
429*4882a593Smuzhiyun 		temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
430*4882a593Smuzhiyun 		if ((temp & PORT_PE) &&
431*4882a593Smuzhiyun 				!(temp & (PORT_SUSPEND | PORT_RESUME))) {
432*4882a593Smuzhiyun 			ehci_dbg(ehci, "Port status(0x%x) is wrong\n", temp);
433*4882a593Smuzhiyun 			spin_unlock_irq(&ehci->lock);
434*4882a593Smuzhiyun 			msleep(8);
435*4882a593Smuzhiyun 			spin_lock_irq(&ehci->lock);
436*4882a593Smuzhiyun 			break;
437*4882a593Smuzhiyun 		}
438*4882a593Smuzhiyun 	}
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun 	if (ehci->shutdown)
441*4882a593Smuzhiyun 		goto shutdown;
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun 	/* clear phy low-power mode before resume */
444*4882a593Smuzhiyun 	if (ehci->bus_suspended && ehci->has_tdi_phy_lpm) {
445*4882a593Smuzhiyun 		i = HCS_N_PORTS(ehci->hcs_params);
446*4882a593Smuzhiyun 		while (i--) {
447*4882a593Smuzhiyun 			if (test_bit(i, &ehci->bus_suspended)) {
448*4882a593Smuzhiyun 				u32 __iomem	*hostpc_reg =
449*4882a593Smuzhiyun 							&ehci->regs->hostpc[i];
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun 				temp = ehci_readl(ehci, hostpc_reg);
452*4882a593Smuzhiyun 				ehci_writel(ehci, temp & ~HOSTPC_PHCD,
453*4882a593Smuzhiyun 						hostpc_reg);
454*4882a593Smuzhiyun 			}
455*4882a593Smuzhiyun 		}
456*4882a593Smuzhiyun 		spin_unlock_irq(&ehci->lock);
457*4882a593Smuzhiyun 		msleep(5);
458*4882a593Smuzhiyun 		spin_lock_irq(&ehci->lock);
459*4882a593Smuzhiyun 		if (ehci->shutdown)
460*4882a593Smuzhiyun 			goto shutdown;
461*4882a593Smuzhiyun 	}
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun 	/* manually resume the ports we suspended during bus_suspend() */
464*4882a593Smuzhiyun 	i = HCS_N_PORTS (ehci->hcs_params);
465*4882a593Smuzhiyun 	while (i--) {
466*4882a593Smuzhiyun 		temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
467*4882a593Smuzhiyun 		temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
468*4882a593Smuzhiyun 		if (test_bit(i, &ehci->bus_suspended) &&
469*4882a593Smuzhiyun 				(temp & PORT_SUSPEND)) {
470*4882a593Smuzhiyun 			temp |= PORT_RESUME;
471*4882a593Smuzhiyun 			set_bit(i, &resume_needed);
472*4882a593Smuzhiyun 		}
473*4882a593Smuzhiyun 		ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
474*4882a593Smuzhiyun 	}
475*4882a593Smuzhiyun 
476*4882a593Smuzhiyun 	/*
477*4882a593Smuzhiyun 	 * msleep for USB_RESUME_TIMEOUT ms only if code is trying to resume
478*4882a593Smuzhiyun 	 * port
479*4882a593Smuzhiyun 	 */
480*4882a593Smuzhiyun 	if (resume_needed) {
481*4882a593Smuzhiyun 		spin_unlock_irq(&ehci->lock);
482*4882a593Smuzhiyun 		msleep(USB_RESUME_TIMEOUT);
483*4882a593Smuzhiyun 		spin_lock_irq(&ehci->lock);
484*4882a593Smuzhiyun 		if (ehci->shutdown)
485*4882a593Smuzhiyun 			goto shutdown;
486*4882a593Smuzhiyun 	}
487*4882a593Smuzhiyun 
488*4882a593Smuzhiyun 	i = HCS_N_PORTS (ehci->hcs_params);
489*4882a593Smuzhiyun 	while (i--) {
490*4882a593Smuzhiyun 		temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
491*4882a593Smuzhiyun 		if (test_bit(i, &resume_needed)) {
492*4882a593Smuzhiyun 			temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
493*4882a593Smuzhiyun 			ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
494*4882a593Smuzhiyun 		}
495*4882a593Smuzhiyun 	}
496*4882a593Smuzhiyun 
497*4882a593Smuzhiyun 	ehci->next_statechange = jiffies + msecs_to_jiffies(5);
498*4882a593Smuzhiyun 	spin_unlock_irq(&ehci->lock);
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun 	ehci_handover_companion_ports(ehci);
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun 	/* Now we can safely re-enable irqs */
503*4882a593Smuzhiyun 	spin_lock_irq(&ehci->lock);
504*4882a593Smuzhiyun 	if (ehci->shutdown)
505*4882a593Smuzhiyun 		goto shutdown;
506*4882a593Smuzhiyun 	ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
507*4882a593Smuzhiyun 	(void) ehci_readl(ehci, &ehci->regs->intr_enable);
508*4882a593Smuzhiyun 	spin_unlock_irq(&ehci->lock);
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun 	return 0;
511*4882a593Smuzhiyun 
512*4882a593Smuzhiyun  shutdown:
513*4882a593Smuzhiyun 	spin_unlock_irq(&ehci->lock);
514*4882a593Smuzhiyun 	return -ESHUTDOWN;
515*4882a593Smuzhiyun }
516*4882a593Smuzhiyun 
ehci_get_resuming_ports(struct usb_hcd * hcd)517*4882a593Smuzhiyun static unsigned long ehci_get_resuming_ports(struct usb_hcd *hcd)
518*4882a593Smuzhiyun {
519*4882a593Smuzhiyun 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
520*4882a593Smuzhiyun 
521*4882a593Smuzhiyun 	return ehci->resuming_ports;
522*4882a593Smuzhiyun }
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun #else
525*4882a593Smuzhiyun 
526*4882a593Smuzhiyun #define ehci_bus_suspend	NULL
527*4882a593Smuzhiyun #define ehci_bus_resume		NULL
528*4882a593Smuzhiyun #define ehci_get_resuming_ports	NULL
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun #endif	/* CONFIG_PM */
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
533*4882a593Smuzhiyun 
534*4882a593Smuzhiyun /*
535*4882a593Smuzhiyun  * Sets the owner of a port
536*4882a593Smuzhiyun  */
set_owner(struct ehci_hcd * ehci,int portnum,int new_owner)537*4882a593Smuzhiyun static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
538*4882a593Smuzhiyun {
539*4882a593Smuzhiyun 	u32 __iomem		*status_reg;
540*4882a593Smuzhiyun 	u32			port_status;
541*4882a593Smuzhiyun 	int 			try;
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun 	status_reg = &ehci->regs->port_status[portnum];
544*4882a593Smuzhiyun 
545*4882a593Smuzhiyun 	/*
546*4882a593Smuzhiyun 	 * The controller won't set the OWNER bit if the port is
547*4882a593Smuzhiyun 	 * enabled, so this loop will sometimes require at least two
548*4882a593Smuzhiyun 	 * iterations: one to disable the port and one to set OWNER.
549*4882a593Smuzhiyun 	 */
550*4882a593Smuzhiyun 	for (try = 4; try > 0; --try) {
551*4882a593Smuzhiyun 		spin_lock_irq(&ehci->lock);
552*4882a593Smuzhiyun 		port_status = ehci_readl(ehci, status_reg);
553*4882a593Smuzhiyun 		if ((port_status & PORT_OWNER) == new_owner
554*4882a593Smuzhiyun 				|| (port_status & (PORT_OWNER | PORT_CONNECT))
555*4882a593Smuzhiyun 					== 0)
556*4882a593Smuzhiyun 			try = 0;
557*4882a593Smuzhiyun 		else {
558*4882a593Smuzhiyun 			port_status ^= PORT_OWNER;
559*4882a593Smuzhiyun 			port_status &= ~(PORT_PE | PORT_RWC_BITS);
560*4882a593Smuzhiyun 			ehci_writel(ehci, port_status, status_reg);
561*4882a593Smuzhiyun 		}
562*4882a593Smuzhiyun 		spin_unlock_irq(&ehci->lock);
563*4882a593Smuzhiyun 		if (try > 1)
564*4882a593Smuzhiyun 			msleep(5);
565*4882a593Smuzhiyun 	}
566*4882a593Smuzhiyun }
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
569*4882a593Smuzhiyun 
check_reset_complete(struct ehci_hcd * ehci,int index,u32 __iomem * status_reg,int port_status)570*4882a593Smuzhiyun static int check_reset_complete (
571*4882a593Smuzhiyun 	struct ehci_hcd	*ehci,
572*4882a593Smuzhiyun 	int		index,
573*4882a593Smuzhiyun 	u32 __iomem	*status_reg,
574*4882a593Smuzhiyun 	int		port_status
575*4882a593Smuzhiyun ) {
576*4882a593Smuzhiyun 	if (!(port_status & PORT_CONNECT))
577*4882a593Smuzhiyun 		return port_status;
578*4882a593Smuzhiyun 
579*4882a593Smuzhiyun 	/* if reset finished and it's still not enabled -- handoff */
580*4882a593Smuzhiyun 	if (!(port_status & PORT_PE)) {
581*4882a593Smuzhiyun 
582*4882a593Smuzhiyun 		/* with integrated TT, there's nobody to hand it to! */
583*4882a593Smuzhiyun 		if (ehci_is_TDI(ehci)) {
584*4882a593Smuzhiyun 			ehci_dbg (ehci,
585*4882a593Smuzhiyun 				"Failed to enable port %d on root hub TT\n",
586*4882a593Smuzhiyun 				index+1);
587*4882a593Smuzhiyun 			return port_status;
588*4882a593Smuzhiyun 		}
589*4882a593Smuzhiyun 
590*4882a593Smuzhiyun 		ehci_dbg (ehci, "port %d full speed --> companion\n",
591*4882a593Smuzhiyun 			index + 1);
592*4882a593Smuzhiyun 
593*4882a593Smuzhiyun 		// what happens if HCS_N_CC(params) == 0 ?
594*4882a593Smuzhiyun 		port_status |= PORT_OWNER;
595*4882a593Smuzhiyun 		port_status &= ~PORT_RWC_BITS;
596*4882a593Smuzhiyun 		ehci_writel(ehci, port_status, status_reg);
597*4882a593Smuzhiyun 
598*4882a593Smuzhiyun 		/* ensure 440EPX ohci controller state is operational */
599*4882a593Smuzhiyun 		if (ehci->has_amcc_usb23)
600*4882a593Smuzhiyun 			set_ohci_hcfs(ehci, 1);
601*4882a593Smuzhiyun 	} else {
602*4882a593Smuzhiyun 		ehci_dbg(ehci, "port %d reset complete, port enabled\n",
603*4882a593Smuzhiyun 			index + 1);
604*4882a593Smuzhiyun 		/* ensure 440EPx ohci controller state is suspended */
605*4882a593Smuzhiyun 		if (ehci->has_amcc_usb23)
606*4882a593Smuzhiyun 			set_ohci_hcfs(ehci, 0);
607*4882a593Smuzhiyun 	}
608*4882a593Smuzhiyun 
609*4882a593Smuzhiyun 	return port_status;
610*4882a593Smuzhiyun }
611*4882a593Smuzhiyun 
612*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
613*4882a593Smuzhiyun 
614*4882a593Smuzhiyun 
615*4882a593Smuzhiyun /* build "status change" packet (one or two bytes) from HC registers */
616*4882a593Smuzhiyun 
617*4882a593Smuzhiyun static int
ehci_hub_status_data(struct usb_hcd * hcd,char * buf)618*4882a593Smuzhiyun ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
619*4882a593Smuzhiyun {
620*4882a593Smuzhiyun 	struct ehci_hcd	*ehci = hcd_to_ehci (hcd);
621*4882a593Smuzhiyun 	u32		temp, status;
622*4882a593Smuzhiyun 	u32		mask;
623*4882a593Smuzhiyun 	int		ports, i, retval = 1;
624*4882a593Smuzhiyun 	unsigned long	flags;
625*4882a593Smuzhiyun 	u32		ppcd = ~0;
626*4882a593Smuzhiyun 
627*4882a593Smuzhiyun 	/* init status to no-changes */
628*4882a593Smuzhiyun 	buf [0] = 0;
629*4882a593Smuzhiyun 	ports = HCS_N_PORTS (ehci->hcs_params);
630*4882a593Smuzhiyun 	if (ports > 7) {
631*4882a593Smuzhiyun 		buf [1] = 0;
632*4882a593Smuzhiyun 		retval++;
633*4882a593Smuzhiyun 	}
634*4882a593Smuzhiyun 
635*4882a593Smuzhiyun 	/* Inform the core about resumes-in-progress by returning
636*4882a593Smuzhiyun 	 * a non-zero value even if there are no status changes.
637*4882a593Smuzhiyun 	 */
638*4882a593Smuzhiyun 	status = ehci->resuming_ports;
639*4882a593Smuzhiyun 
640*4882a593Smuzhiyun 	/* Some boards (mostly VIA?) report bogus overcurrent indications,
641*4882a593Smuzhiyun 	 * causing massive log spam unless we completely ignore them.  It
642*4882a593Smuzhiyun 	 * may be relevant that VIA VT8235 controllers, where PORT_POWER is
643*4882a593Smuzhiyun 	 * always set, seem to clear PORT_OCC and PORT_CSC when writing to
644*4882a593Smuzhiyun 	 * PORT_POWER; that's surprising, but maybe within-spec.
645*4882a593Smuzhiyun 	 */
646*4882a593Smuzhiyun 	if (!ignore_oc)
647*4882a593Smuzhiyun 		mask = PORT_CSC | PORT_PEC | PORT_OCC;
648*4882a593Smuzhiyun 	else
649*4882a593Smuzhiyun 		mask = PORT_CSC | PORT_PEC;
650*4882a593Smuzhiyun 	// PORT_RESUME from hardware ~= PORT_STAT_C_SUSPEND
651*4882a593Smuzhiyun 
652*4882a593Smuzhiyun 	/* no hub change reports (bit 0) for now (power, ...) */
653*4882a593Smuzhiyun 
654*4882a593Smuzhiyun 	/* port N changes (bit N)? */
655*4882a593Smuzhiyun 	spin_lock_irqsave (&ehci->lock, flags);
656*4882a593Smuzhiyun 
657*4882a593Smuzhiyun 	/* get per-port change detect bits */
658*4882a593Smuzhiyun 	if (ehci->has_ppcd)
659*4882a593Smuzhiyun 		ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16;
660*4882a593Smuzhiyun 
661*4882a593Smuzhiyun 	for (i = 0; i < ports; i++) {
662*4882a593Smuzhiyun 		/* leverage per-port change bits feature */
663*4882a593Smuzhiyun 		if (ppcd & (1 << i))
664*4882a593Smuzhiyun 			temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
665*4882a593Smuzhiyun 		else
666*4882a593Smuzhiyun 			temp = 0;
667*4882a593Smuzhiyun 
668*4882a593Smuzhiyun 		/*
669*4882a593Smuzhiyun 		 * Return status information even for ports with OWNER set.
670*4882a593Smuzhiyun 		 * Otherwise hub_wq wouldn't see the disconnect event when a
671*4882a593Smuzhiyun 		 * high-speed device is switched over to the companion
672*4882a593Smuzhiyun 		 * controller by the user.
673*4882a593Smuzhiyun 		 */
674*4882a593Smuzhiyun 
675*4882a593Smuzhiyun 		if ((temp & mask) != 0 || test_bit(i, &ehci->port_c_suspend)
676*4882a593Smuzhiyun 				|| (ehci->reset_done[i] && time_after_eq(
677*4882a593Smuzhiyun 					jiffies, ehci->reset_done[i]))) {
678*4882a593Smuzhiyun 			if (i < 7)
679*4882a593Smuzhiyun 			    buf [0] |= 1 << (i + 1);
680*4882a593Smuzhiyun 			else
681*4882a593Smuzhiyun 			    buf [1] |= 1 << (i - 7);
682*4882a593Smuzhiyun 			status = STS_PCD;
683*4882a593Smuzhiyun 		}
684*4882a593Smuzhiyun 	}
685*4882a593Smuzhiyun 
686*4882a593Smuzhiyun 	/* If a resume is in progress, make sure it can finish */
687*4882a593Smuzhiyun 	if (ehci->resuming_ports)
688*4882a593Smuzhiyun 		mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(25));
689*4882a593Smuzhiyun 
690*4882a593Smuzhiyun 	spin_unlock_irqrestore (&ehci->lock, flags);
691*4882a593Smuzhiyun 	return status ? retval : 0;
692*4882a593Smuzhiyun }
693*4882a593Smuzhiyun 
694*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
695*4882a593Smuzhiyun 
696*4882a593Smuzhiyun static void
ehci_hub_descriptor(struct ehci_hcd * ehci,struct usb_hub_descriptor * desc)697*4882a593Smuzhiyun ehci_hub_descriptor (
698*4882a593Smuzhiyun 	struct ehci_hcd			*ehci,
699*4882a593Smuzhiyun 	struct usb_hub_descriptor	*desc
700*4882a593Smuzhiyun ) {
701*4882a593Smuzhiyun 	int		ports = HCS_N_PORTS (ehci->hcs_params);
702*4882a593Smuzhiyun 	u16		temp;
703*4882a593Smuzhiyun 
704*4882a593Smuzhiyun 	desc->bDescriptorType = USB_DT_HUB;
705*4882a593Smuzhiyun 	desc->bPwrOn2PwrGood = 10;	/* ehci 1.0, 2.3.9 says 20ms max */
706*4882a593Smuzhiyun 	desc->bHubContrCurrent = 0;
707*4882a593Smuzhiyun 
708*4882a593Smuzhiyun 	desc->bNbrPorts = ports;
709*4882a593Smuzhiyun 	temp = 1 + (ports / 8);
710*4882a593Smuzhiyun 	desc->bDescLength = 7 + 2 * temp;
711*4882a593Smuzhiyun 
712*4882a593Smuzhiyun 	/* two bitmaps:  ports removable, and usb 1.0 legacy PortPwrCtrlMask */
713*4882a593Smuzhiyun 	memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
714*4882a593Smuzhiyun 	memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
715*4882a593Smuzhiyun 
716*4882a593Smuzhiyun 	temp = HUB_CHAR_INDV_PORT_OCPM;	/* per-port overcurrent reporting */
717*4882a593Smuzhiyun 	if (HCS_PPC (ehci->hcs_params))
718*4882a593Smuzhiyun 		temp |= HUB_CHAR_INDV_PORT_LPSM; /* per-port power control */
719*4882a593Smuzhiyun 	else
720*4882a593Smuzhiyun 		temp |= HUB_CHAR_NO_LPSM; /* no power switching */
721*4882a593Smuzhiyun #if 0
722*4882a593Smuzhiyun // re-enable when we support USB_PORT_FEAT_INDICATOR below.
723*4882a593Smuzhiyun 	if (HCS_INDICATOR (ehci->hcs_params))
724*4882a593Smuzhiyun 		temp |= HUB_CHAR_PORTIND; /* per-port indicators (LEDs) */
725*4882a593Smuzhiyun #endif
726*4882a593Smuzhiyun 	desc->wHubCharacteristics = cpu_to_le16(temp);
727*4882a593Smuzhiyun }
728*4882a593Smuzhiyun 
729*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
730*4882a593Smuzhiyun #ifdef CONFIG_USB_HCD_TEST_MODE
731*4882a593Smuzhiyun 
732*4882a593Smuzhiyun #define EHSET_TEST_SINGLE_STEP_SET_FEATURE 0x06
733*4882a593Smuzhiyun 
usb_ehset_completion(struct urb * urb)734*4882a593Smuzhiyun static void usb_ehset_completion(struct urb *urb)
735*4882a593Smuzhiyun {
736*4882a593Smuzhiyun 	struct completion  *done = urb->context;
737*4882a593Smuzhiyun 
738*4882a593Smuzhiyun 	complete(done);
739*4882a593Smuzhiyun }
740*4882a593Smuzhiyun static int submit_single_step_set_feature(
741*4882a593Smuzhiyun 	struct usb_hcd	*hcd,
742*4882a593Smuzhiyun 	struct urb	*urb,
743*4882a593Smuzhiyun 	int		is_setup
744*4882a593Smuzhiyun );
745*4882a593Smuzhiyun 
746*4882a593Smuzhiyun /*
747*4882a593Smuzhiyun  * Allocate and initialize a control URB. This request will be used by the
748*4882a593Smuzhiyun  * EHSET SINGLE_STEP_SET_FEATURE test in which the DATA and STATUS stages
749*4882a593Smuzhiyun  * of the GetDescriptor request are sent 15 seconds after the SETUP stage.
750*4882a593Smuzhiyun  * Return NULL if failed.
751*4882a593Smuzhiyun  */
request_single_step_set_feature_urb(struct usb_device * udev,void * dr,void * buf,struct completion * done)752*4882a593Smuzhiyun static struct urb *request_single_step_set_feature_urb(
753*4882a593Smuzhiyun 	struct usb_device	*udev,
754*4882a593Smuzhiyun 	void			*dr,
755*4882a593Smuzhiyun 	void			*buf,
756*4882a593Smuzhiyun 	struct completion	*done
757*4882a593Smuzhiyun ) {
758*4882a593Smuzhiyun 	struct urb *urb;
759*4882a593Smuzhiyun 	struct usb_hcd *hcd = bus_to_hcd(udev->bus);
760*4882a593Smuzhiyun 	struct usb_host_endpoint *ep;
761*4882a593Smuzhiyun 
762*4882a593Smuzhiyun 	urb = usb_alloc_urb(0, GFP_KERNEL);
763*4882a593Smuzhiyun 	if (!urb)
764*4882a593Smuzhiyun 		return NULL;
765*4882a593Smuzhiyun 
766*4882a593Smuzhiyun 	urb->pipe = usb_rcvctrlpipe(udev, 0);
767*4882a593Smuzhiyun 	ep = (usb_pipein(urb->pipe) ? udev->ep_in : udev->ep_out)
768*4882a593Smuzhiyun 				[usb_pipeendpoint(urb->pipe)];
769*4882a593Smuzhiyun 	if (!ep) {
770*4882a593Smuzhiyun 		usb_free_urb(urb);
771*4882a593Smuzhiyun 		return NULL;
772*4882a593Smuzhiyun 	}
773*4882a593Smuzhiyun 
774*4882a593Smuzhiyun 	urb->ep = ep;
775*4882a593Smuzhiyun 	urb->dev = udev;
776*4882a593Smuzhiyun 	urb->setup_packet = (void *)dr;
777*4882a593Smuzhiyun 	urb->transfer_buffer = buf;
778*4882a593Smuzhiyun 	urb->transfer_buffer_length = USB_DT_DEVICE_SIZE;
779*4882a593Smuzhiyun 	urb->complete = usb_ehset_completion;
780*4882a593Smuzhiyun 	urb->status = -EINPROGRESS;
781*4882a593Smuzhiyun 	urb->actual_length = 0;
782*4882a593Smuzhiyun 	urb->transfer_flags = URB_DIR_IN;
783*4882a593Smuzhiyun 	usb_get_urb(urb);
784*4882a593Smuzhiyun 	atomic_inc(&urb->use_count);
785*4882a593Smuzhiyun 	atomic_inc(&urb->dev->urbnum);
786*4882a593Smuzhiyun 	urb->setup_dma = dma_map_single(
787*4882a593Smuzhiyun 			hcd->self.sysdev,
788*4882a593Smuzhiyun 			urb->setup_packet,
789*4882a593Smuzhiyun 			sizeof(struct usb_ctrlrequest),
790*4882a593Smuzhiyun 			DMA_TO_DEVICE);
791*4882a593Smuzhiyun 	urb->transfer_dma = dma_map_single(
792*4882a593Smuzhiyun 			hcd->self.sysdev,
793*4882a593Smuzhiyun 			urb->transfer_buffer,
794*4882a593Smuzhiyun 			urb->transfer_buffer_length,
795*4882a593Smuzhiyun 			DMA_FROM_DEVICE);
796*4882a593Smuzhiyun 	urb->context = done;
797*4882a593Smuzhiyun 	return urb;
798*4882a593Smuzhiyun }
799*4882a593Smuzhiyun 
ehset_single_step_set_feature(struct usb_hcd * hcd,int port)800*4882a593Smuzhiyun static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
801*4882a593Smuzhiyun {
802*4882a593Smuzhiyun 	int retval = -ENOMEM;
803*4882a593Smuzhiyun 	struct usb_ctrlrequest *dr;
804*4882a593Smuzhiyun 	struct urb *urb;
805*4882a593Smuzhiyun 	struct usb_device *udev;
806*4882a593Smuzhiyun 	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
807*4882a593Smuzhiyun 	struct usb_device_descriptor *buf;
808*4882a593Smuzhiyun 	DECLARE_COMPLETION_ONSTACK(done);
809*4882a593Smuzhiyun 
810*4882a593Smuzhiyun 	/* Obtain udev of the rhub's child port */
811*4882a593Smuzhiyun 	udev = usb_hub_find_child(hcd->self.root_hub, port);
812*4882a593Smuzhiyun 	if (!udev) {
813*4882a593Smuzhiyun 		ehci_err(ehci, "No device attached to the RootHub\n");
814*4882a593Smuzhiyun 		return -ENODEV;
815*4882a593Smuzhiyun 	}
816*4882a593Smuzhiyun 	buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL);
817*4882a593Smuzhiyun 	if (!buf)
818*4882a593Smuzhiyun 		return -ENOMEM;
819*4882a593Smuzhiyun 
820*4882a593Smuzhiyun 	dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
821*4882a593Smuzhiyun 	if (!dr) {
822*4882a593Smuzhiyun 		kfree(buf);
823*4882a593Smuzhiyun 		return -ENOMEM;
824*4882a593Smuzhiyun 	}
825*4882a593Smuzhiyun 
826*4882a593Smuzhiyun 	/* Fill Setup packet for GetDescriptor */
827*4882a593Smuzhiyun 	dr->bRequestType = USB_DIR_IN;
828*4882a593Smuzhiyun 	dr->bRequest = USB_REQ_GET_DESCRIPTOR;
829*4882a593Smuzhiyun 	dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8);
830*4882a593Smuzhiyun 	dr->wIndex = 0;
831*4882a593Smuzhiyun 	dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE);
832*4882a593Smuzhiyun 	urb = request_single_step_set_feature_urb(udev, dr, buf, &done);
833*4882a593Smuzhiyun 	if (!urb)
834*4882a593Smuzhiyun 		goto cleanup;
835*4882a593Smuzhiyun 
836*4882a593Smuzhiyun 	/* Submit just the SETUP stage */
837*4882a593Smuzhiyun 	retval = submit_single_step_set_feature(hcd, urb, 1);
838*4882a593Smuzhiyun 	if (retval)
839*4882a593Smuzhiyun 		goto out1;
840*4882a593Smuzhiyun 	if (!wait_for_completion_timeout(&done, msecs_to_jiffies(2000))) {
841*4882a593Smuzhiyun 		usb_kill_urb(urb);
842*4882a593Smuzhiyun 		retval = -ETIMEDOUT;
843*4882a593Smuzhiyun 		ehci_err(ehci, "%s SETUP stage timed out on ep0\n", __func__);
844*4882a593Smuzhiyun 		goto out1;
845*4882a593Smuzhiyun 	}
846*4882a593Smuzhiyun 	msleep(15 * 1000);
847*4882a593Smuzhiyun 
848*4882a593Smuzhiyun 	/* Complete remaining DATA and STATUS stages using the same URB */
849*4882a593Smuzhiyun 	urb->status = -EINPROGRESS;
850*4882a593Smuzhiyun 	usb_get_urb(urb);
851*4882a593Smuzhiyun 	atomic_inc(&urb->use_count);
852*4882a593Smuzhiyun 	atomic_inc(&urb->dev->urbnum);
853*4882a593Smuzhiyun 	retval = submit_single_step_set_feature(hcd, urb, 0);
854*4882a593Smuzhiyun 	if (!retval && !wait_for_completion_timeout(&done,
855*4882a593Smuzhiyun 						msecs_to_jiffies(2000))) {
856*4882a593Smuzhiyun 		usb_kill_urb(urb);
857*4882a593Smuzhiyun 		retval = -ETIMEDOUT;
858*4882a593Smuzhiyun 		ehci_err(ehci, "%s IN stage timed out on ep0\n", __func__);
859*4882a593Smuzhiyun 	}
860*4882a593Smuzhiyun out1:
861*4882a593Smuzhiyun 	usb_free_urb(urb);
862*4882a593Smuzhiyun cleanup:
863*4882a593Smuzhiyun 	kfree(dr);
864*4882a593Smuzhiyun 	kfree(buf);
865*4882a593Smuzhiyun 	return retval;
866*4882a593Smuzhiyun }
867*4882a593Smuzhiyun #endif /* CONFIG_USB_HCD_TEST_MODE */
868*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
869*4882a593Smuzhiyun 
ehci_hub_control(struct usb_hcd * hcd,u16 typeReq,u16 wValue,u16 wIndex,char * buf,u16 wLength)870*4882a593Smuzhiyun int ehci_hub_control(
871*4882a593Smuzhiyun 	struct usb_hcd	*hcd,
872*4882a593Smuzhiyun 	u16		typeReq,
873*4882a593Smuzhiyun 	u16		wValue,
874*4882a593Smuzhiyun 	u16		wIndex,
875*4882a593Smuzhiyun 	char		*buf,
876*4882a593Smuzhiyun 	u16		wLength
877*4882a593Smuzhiyun ) {
878*4882a593Smuzhiyun 	struct ehci_hcd	*ehci = hcd_to_ehci (hcd);
879*4882a593Smuzhiyun 	int		ports = HCS_N_PORTS (ehci->hcs_params);
880*4882a593Smuzhiyun 	u32 __iomem	*status_reg, *hostpc_reg;
881*4882a593Smuzhiyun 	u32		temp, temp1, status;
882*4882a593Smuzhiyun 	unsigned long	flags;
883*4882a593Smuzhiyun 	int		retval = 0;
884*4882a593Smuzhiyun 	unsigned	selector;
885*4882a593Smuzhiyun 
886*4882a593Smuzhiyun 	/*
887*4882a593Smuzhiyun 	 * Avoid underflow while calculating (wIndex & 0xff) - 1.
888*4882a593Smuzhiyun 	 * The compiler might deduce that wIndex can never be 0 and then
889*4882a593Smuzhiyun 	 * optimize away the tests for !wIndex below.
890*4882a593Smuzhiyun 	 */
891*4882a593Smuzhiyun 	temp = wIndex & 0xff;
892*4882a593Smuzhiyun 	temp -= (temp > 0);
893*4882a593Smuzhiyun 	status_reg = &ehci->regs->port_status[temp];
894*4882a593Smuzhiyun 	hostpc_reg = &ehci->regs->hostpc[temp];
895*4882a593Smuzhiyun 
896*4882a593Smuzhiyun 	/*
897*4882a593Smuzhiyun 	 * FIXME:  support SetPortFeatures USB_PORT_FEAT_INDICATOR.
898*4882a593Smuzhiyun 	 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
899*4882a593Smuzhiyun 	 * (track current state ourselves) ... blink for diagnostics,
900*4882a593Smuzhiyun 	 * power, "this is the one", etc.  EHCI spec supports this.
901*4882a593Smuzhiyun 	 */
902*4882a593Smuzhiyun 
903*4882a593Smuzhiyun 	spin_lock_irqsave (&ehci->lock, flags);
904*4882a593Smuzhiyun 	switch (typeReq) {
905*4882a593Smuzhiyun 	case ClearHubFeature:
906*4882a593Smuzhiyun 		switch (wValue) {
907*4882a593Smuzhiyun 		case C_HUB_LOCAL_POWER:
908*4882a593Smuzhiyun 		case C_HUB_OVER_CURRENT:
909*4882a593Smuzhiyun 			/* no hub-wide feature/status flags */
910*4882a593Smuzhiyun 			break;
911*4882a593Smuzhiyun 		default:
912*4882a593Smuzhiyun 			goto error;
913*4882a593Smuzhiyun 		}
914*4882a593Smuzhiyun 		break;
915*4882a593Smuzhiyun 	case ClearPortFeature:
916*4882a593Smuzhiyun 		if (!wIndex || wIndex > ports)
917*4882a593Smuzhiyun 			goto error;
918*4882a593Smuzhiyun 		wIndex--;
919*4882a593Smuzhiyun 		temp = ehci_readl(ehci, status_reg);
920*4882a593Smuzhiyun 		temp &= ~PORT_RWC_BITS;
921*4882a593Smuzhiyun 
922*4882a593Smuzhiyun 		/*
923*4882a593Smuzhiyun 		 * Even if OWNER is set, so the port is owned by the
924*4882a593Smuzhiyun 		 * companion controller, hub_wq needs to be able to clear
925*4882a593Smuzhiyun 		 * the port-change status bits (especially
926*4882a593Smuzhiyun 		 * USB_PORT_STAT_C_CONNECTION).
927*4882a593Smuzhiyun 		 */
928*4882a593Smuzhiyun 
929*4882a593Smuzhiyun 		switch (wValue) {
930*4882a593Smuzhiyun 		case USB_PORT_FEAT_ENABLE:
931*4882a593Smuzhiyun 			ehci_writel(ehci, temp & ~PORT_PE, status_reg);
932*4882a593Smuzhiyun 			break;
933*4882a593Smuzhiyun 		case USB_PORT_FEAT_C_ENABLE:
934*4882a593Smuzhiyun 			ehci_writel(ehci, temp | PORT_PEC, status_reg);
935*4882a593Smuzhiyun 			break;
936*4882a593Smuzhiyun 		case USB_PORT_FEAT_SUSPEND:
937*4882a593Smuzhiyun 			if (temp & PORT_RESET)
938*4882a593Smuzhiyun 				goto error;
939*4882a593Smuzhiyun 			if (ehci->no_selective_suspend)
940*4882a593Smuzhiyun 				break;
941*4882a593Smuzhiyun #ifdef CONFIG_USB_OTG
942*4882a593Smuzhiyun 			if ((hcd->self.otg_port == (wIndex + 1))
943*4882a593Smuzhiyun 			    && hcd->self.b_hnp_enable) {
944*4882a593Smuzhiyun 				otg_start_hnp(hcd->usb_phy->otg);
945*4882a593Smuzhiyun 				break;
946*4882a593Smuzhiyun 			}
947*4882a593Smuzhiyun #endif
948*4882a593Smuzhiyun 			if (!(temp & PORT_SUSPEND))
949*4882a593Smuzhiyun 				break;
950*4882a593Smuzhiyun 			if ((temp & PORT_PE) == 0)
951*4882a593Smuzhiyun 				goto error;
952*4882a593Smuzhiyun 
953*4882a593Smuzhiyun 			/* clear phy low-power mode before resume */
954*4882a593Smuzhiyun 			if (ehci->has_tdi_phy_lpm) {
955*4882a593Smuzhiyun 				temp1 = ehci_readl(ehci, hostpc_reg);
956*4882a593Smuzhiyun 				ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
957*4882a593Smuzhiyun 						hostpc_reg);
958*4882a593Smuzhiyun 				spin_unlock_irqrestore(&ehci->lock, flags);
959*4882a593Smuzhiyun 				msleep(5);/* wait to leave low-power mode */
960*4882a593Smuzhiyun 				spin_lock_irqsave(&ehci->lock, flags);
961*4882a593Smuzhiyun 			}
962*4882a593Smuzhiyun 			/* resume signaling for 20 msec */
963*4882a593Smuzhiyun 			temp &= ~PORT_WAKE_BITS;
964*4882a593Smuzhiyun 			ehci_writel(ehci, temp | PORT_RESUME, status_reg);
965*4882a593Smuzhiyun 			ehci->reset_done[wIndex] = jiffies
966*4882a593Smuzhiyun 					+ msecs_to_jiffies(USB_RESUME_TIMEOUT);
967*4882a593Smuzhiyun 			set_bit(wIndex, &ehci->resuming_ports);
968*4882a593Smuzhiyun 			usb_hcd_start_port_resume(&hcd->self, wIndex);
969*4882a593Smuzhiyun 			break;
970*4882a593Smuzhiyun 		case USB_PORT_FEAT_C_SUSPEND:
971*4882a593Smuzhiyun 			clear_bit(wIndex, &ehci->port_c_suspend);
972*4882a593Smuzhiyun 			break;
973*4882a593Smuzhiyun 		case USB_PORT_FEAT_POWER:
974*4882a593Smuzhiyun 			if (HCS_PPC(ehci->hcs_params)) {
975*4882a593Smuzhiyun 				spin_unlock_irqrestore(&ehci->lock, flags);
976*4882a593Smuzhiyun 				ehci_port_power(ehci, wIndex, false);
977*4882a593Smuzhiyun 				spin_lock_irqsave(&ehci->lock, flags);
978*4882a593Smuzhiyun 			}
979*4882a593Smuzhiyun 			break;
980*4882a593Smuzhiyun 		case USB_PORT_FEAT_C_CONNECTION:
981*4882a593Smuzhiyun 			ehci_writel(ehci, temp | PORT_CSC, status_reg);
982*4882a593Smuzhiyun 			break;
983*4882a593Smuzhiyun 		case USB_PORT_FEAT_C_OVER_CURRENT:
984*4882a593Smuzhiyun 			ehci_writel(ehci, temp | PORT_OCC, status_reg);
985*4882a593Smuzhiyun 			break;
986*4882a593Smuzhiyun 		case USB_PORT_FEAT_C_RESET:
987*4882a593Smuzhiyun 			/* GetPortStatus clears reset */
988*4882a593Smuzhiyun 			break;
989*4882a593Smuzhiyun 		default:
990*4882a593Smuzhiyun 			goto error;
991*4882a593Smuzhiyun 		}
992*4882a593Smuzhiyun 		ehci_readl(ehci, &ehci->regs->command);	/* unblock posted write */
993*4882a593Smuzhiyun 		break;
994*4882a593Smuzhiyun 	case GetHubDescriptor:
995*4882a593Smuzhiyun 		ehci_hub_descriptor (ehci, (struct usb_hub_descriptor *)
996*4882a593Smuzhiyun 			buf);
997*4882a593Smuzhiyun 		break;
998*4882a593Smuzhiyun 	case GetHubStatus:
999*4882a593Smuzhiyun 		/* no hub-wide feature/status flags */
1000*4882a593Smuzhiyun 		memset (buf, 0, 4);
1001*4882a593Smuzhiyun 		//cpu_to_le32s ((u32 *) buf);
1002*4882a593Smuzhiyun 		break;
1003*4882a593Smuzhiyun 	case GetPortStatus:
1004*4882a593Smuzhiyun 		if (!wIndex || wIndex > ports)
1005*4882a593Smuzhiyun 			goto error;
1006*4882a593Smuzhiyun 		wIndex--;
1007*4882a593Smuzhiyun 		status = 0;
1008*4882a593Smuzhiyun 		temp = ehci_readl(ehci, status_reg);
1009*4882a593Smuzhiyun 
1010*4882a593Smuzhiyun 		// wPortChange bits
1011*4882a593Smuzhiyun 		if (temp & PORT_CSC)
1012*4882a593Smuzhiyun 			status |= USB_PORT_STAT_C_CONNECTION << 16;
1013*4882a593Smuzhiyun 		if (temp & PORT_PEC)
1014*4882a593Smuzhiyun 			status |= USB_PORT_STAT_C_ENABLE << 16;
1015*4882a593Smuzhiyun 
1016*4882a593Smuzhiyun 		if ((temp & PORT_OCC) && !ignore_oc){
1017*4882a593Smuzhiyun 			status |= USB_PORT_STAT_C_OVERCURRENT << 16;
1018*4882a593Smuzhiyun 
1019*4882a593Smuzhiyun 			/*
1020*4882a593Smuzhiyun 			 * Hubs should disable port power on over-current.
1021*4882a593Smuzhiyun 			 * However, not all EHCI implementations do this
1022*4882a593Smuzhiyun 			 * automatically, even if they _do_ support per-port
1023*4882a593Smuzhiyun 			 * power switching; they're allowed to just limit the
1024*4882a593Smuzhiyun 			 * current.  hub_wq will turn the power back on.
1025*4882a593Smuzhiyun 			 */
1026*4882a593Smuzhiyun 			if (((temp & PORT_OC) || (ehci->need_oc_pp_cycle))
1027*4882a593Smuzhiyun 					&& HCS_PPC(ehci->hcs_params)) {
1028*4882a593Smuzhiyun 				spin_unlock_irqrestore(&ehci->lock, flags);
1029*4882a593Smuzhiyun 				ehci_port_power(ehci, wIndex, false);
1030*4882a593Smuzhiyun 				spin_lock_irqsave(&ehci->lock, flags);
1031*4882a593Smuzhiyun 				temp = ehci_readl(ehci, status_reg);
1032*4882a593Smuzhiyun 			}
1033*4882a593Smuzhiyun 		}
1034*4882a593Smuzhiyun 
1035*4882a593Smuzhiyun 		/* no reset or resume pending */
1036*4882a593Smuzhiyun 		if (!ehci->reset_done[wIndex]) {
1037*4882a593Smuzhiyun 
1038*4882a593Smuzhiyun 			/* Remote Wakeup received? */
1039*4882a593Smuzhiyun 			if (temp & PORT_RESUME) {
1040*4882a593Smuzhiyun 				/* resume signaling for 20 msec */
1041*4882a593Smuzhiyun 				ehci->reset_done[wIndex] = jiffies
1042*4882a593Smuzhiyun 						+ msecs_to_jiffies(20);
1043*4882a593Smuzhiyun 				usb_hcd_start_port_resume(&hcd->self, wIndex);
1044*4882a593Smuzhiyun 				set_bit(wIndex, &ehci->resuming_ports);
1045*4882a593Smuzhiyun 				/* check the port again */
1046*4882a593Smuzhiyun 				mod_timer(&ehci_to_hcd(ehci)->rh_timer,
1047*4882a593Smuzhiyun 						ehci->reset_done[wIndex]);
1048*4882a593Smuzhiyun 			}
1049*4882a593Smuzhiyun 
1050*4882a593Smuzhiyun 		/* reset or resume not yet complete */
1051*4882a593Smuzhiyun 		} else if (!time_after_eq(jiffies, ehci->reset_done[wIndex])) {
1052*4882a593Smuzhiyun 			;	/* wait until it is complete */
1053*4882a593Smuzhiyun 
1054*4882a593Smuzhiyun 		/* resume completed */
1055*4882a593Smuzhiyun 		} else if (test_bit(wIndex, &ehci->resuming_ports)) {
1056*4882a593Smuzhiyun 			clear_bit(wIndex, &ehci->suspended_ports);
1057*4882a593Smuzhiyun 			set_bit(wIndex, &ehci->port_c_suspend);
1058*4882a593Smuzhiyun 			ehci->reset_done[wIndex] = 0;
1059*4882a593Smuzhiyun 			usb_hcd_end_port_resume(&hcd->self, wIndex);
1060*4882a593Smuzhiyun 
1061*4882a593Smuzhiyun 			/* stop resume signaling */
1062*4882a593Smuzhiyun 			temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
1063*4882a593Smuzhiyun 			ehci_writel(ehci, temp, status_reg);
1064*4882a593Smuzhiyun 			clear_bit(wIndex, &ehci->resuming_ports);
1065*4882a593Smuzhiyun 			retval = ehci_handshake(ehci, status_reg,
1066*4882a593Smuzhiyun 					PORT_RESUME, 0, 2000 /* 2msec */);
1067*4882a593Smuzhiyun 			if (retval != 0) {
1068*4882a593Smuzhiyun 				ehci_err(ehci, "port %d resume error %d\n",
1069*4882a593Smuzhiyun 						wIndex + 1, retval);
1070*4882a593Smuzhiyun 				goto error;
1071*4882a593Smuzhiyun 			}
1072*4882a593Smuzhiyun 			temp = ehci_readl(ehci, status_reg);
1073*4882a593Smuzhiyun 
1074*4882a593Smuzhiyun 		/* whoever resets must GetPortStatus to complete it!! */
1075*4882a593Smuzhiyun 		} else {
1076*4882a593Smuzhiyun 			status |= USB_PORT_STAT_C_RESET << 16;
1077*4882a593Smuzhiyun 			ehci->reset_done [wIndex] = 0;
1078*4882a593Smuzhiyun 
1079*4882a593Smuzhiyun 			/* force reset to complete */
1080*4882a593Smuzhiyun 			ehci_writel(ehci, temp & ~(PORT_RWC_BITS | PORT_RESET),
1081*4882a593Smuzhiyun 					status_reg);
1082*4882a593Smuzhiyun 			/* REVISIT:  some hardware needs 550+ usec to clear
1083*4882a593Smuzhiyun 			 * this bit; seems too long to spin routinely...
1084*4882a593Smuzhiyun 			 */
1085*4882a593Smuzhiyun 			retval = ehci_handshake(ehci, status_reg,
1086*4882a593Smuzhiyun 					PORT_RESET, 0, 1000);
1087*4882a593Smuzhiyun 			if (retval != 0) {
1088*4882a593Smuzhiyun 				ehci_err (ehci, "port %d reset error %d\n",
1089*4882a593Smuzhiyun 					wIndex + 1, retval);
1090*4882a593Smuzhiyun 				goto error;
1091*4882a593Smuzhiyun 			}
1092*4882a593Smuzhiyun 
1093*4882a593Smuzhiyun 			/* see what we found out */
1094*4882a593Smuzhiyun 			temp = check_reset_complete (ehci, wIndex, status_reg,
1095*4882a593Smuzhiyun 					ehci_readl(ehci, status_reg));
1096*4882a593Smuzhiyun 		}
1097*4882a593Smuzhiyun 
1098*4882a593Smuzhiyun 		/* transfer dedicated ports to the companion hc */
1099*4882a593Smuzhiyun 		if ((temp & PORT_CONNECT) &&
1100*4882a593Smuzhiyun 				test_bit(wIndex, &ehci->companion_ports)) {
1101*4882a593Smuzhiyun 			temp &= ~PORT_RWC_BITS;
1102*4882a593Smuzhiyun 			temp |= PORT_OWNER;
1103*4882a593Smuzhiyun 			ehci_writel(ehci, temp, status_reg);
1104*4882a593Smuzhiyun 			ehci_dbg(ehci, "port %d --> companion\n", wIndex + 1);
1105*4882a593Smuzhiyun 			temp = ehci_readl(ehci, status_reg);
1106*4882a593Smuzhiyun 		}
1107*4882a593Smuzhiyun 
1108*4882a593Smuzhiyun 		/*
1109*4882a593Smuzhiyun 		 * Even if OWNER is set, there's no harm letting hub_wq
1110*4882a593Smuzhiyun 		 * see the wPortStatus values (they should all be 0 except
1111*4882a593Smuzhiyun 		 * for PORT_POWER anyway).
1112*4882a593Smuzhiyun 		 */
1113*4882a593Smuzhiyun 
1114*4882a593Smuzhiyun 		if (temp & PORT_CONNECT) {
1115*4882a593Smuzhiyun 			status |= USB_PORT_STAT_CONNECTION;
1116*4882a593Smuzhiyun 			// status may be from integrated TT
1117*4882a593Smuzhiyun 			if (ehci->has_hostpc) {
1118*4882a593Smuzhiyun 				temp1 = ehci_readl(ehci, hostpc_reg);
1119*4882a593Smuzhiyun 				status |= ehci_port_speed(ehci, temp1);
1120*4882a593Smuzhiyun 			} else
1121*4882a593Smuzhiyun 				status |= ehci_port_speed(ehci, temp);
1122*4882a593Smuzhiyun 		}
1123*4882a593Smuzhiyun 		if (temp & PORT_PE)
1124*4882a593Smuzhiyun 			status |= USB_PORT_STAT_ENABLE;
1125*4882a593Smuzhiyun 
1126*4882a593Smuzhiyun 		/* maybe the port was unsuspended without our knowledge */
1127*4882a593Smuzhiyun 		if (temp & (PORT_SUSPEND|PORT_RESUME)) {
1128*4882a593Smuzhiyun 			status |= USB_PORT_STAT_SUSPEND;
1129*4882a593Smuzhiyun 		} else if (test_bit(wIndex, &ehci->suspended_ports)) {
1130*4882a593Smuzhiyun 			clear_bit(wIndex, &ehci->suspended_ports);
1131*4882a593Smuzhiyun 			clear_bit(wIndex, &ehci->resuming_ports);
1132*4882a593Smuzhiyun 			ehci->reset_done[wIndex] = 0;
1133*4882a593Smuzhiyun 			if (temp & PORT_PE)
1134*4882a593Smuzhiyun 				set_bit(wIndex, &ehci->port_c_suspend);
1135*4882a593Smuzhiyun 			usb_hcd_end_port_resume(&hcd->self, wIndex);
1136*4882a593Smuzhiyun 		}
1137*4882a593Smuzhiyun 
1138*4882a593Smuzhiyun 		if (temp & PORT_OC)
1139*4882a593Smuzhiyun 			status |= USB_PORT_STAT_OVERCURRENT;
1140*4882a593Smuzhiyun 		if (temp & PORT_RESET)
1141*4882a593Smuzhiyun 			status |= USB_PORT_STAT_RESET;
1142*4882a593Smuzhiyun 		if (temp & PORT_POWER)
1143*4882a593Smuzhiyun 			status |= USB_PORT_STAT_POWER;
1144*4882a593Smuzhiyun 		if (test_bit(wIndex, &ehci->port_c_suspend))
1145*4882a593Smuzhiyun 			status |= USB_PORT_STAT_C_SUSPEND << 16;
1146*4882a593Smuzhiyun 
1147*4882a593Smuzhiyun 		if (status & ~0xffff)	/* only if wPortChange is interesting */
1148*4882a593Smuzhiyun 			dbg_port(ehci, "GetStatus", wIndex + 1, temp);
1149*4882a593Smuzhiyun 		put_unaligned_le32(status, buf);
1150*4882a593Smuzhiyun 		break;
1151*4882a593Smuzhiyun 	case SetHubFeature:
1152*4882a593Smuzhiyun 		switch (wValue) {
1153*4882a593Smuzhiyun 		case C_HUB_LOCAL_POWER:
1154*4882a593Smuzhiyun 		case C_HUB_OVER_CURRENT:
1155*4882a593Smuzhiyun 			/* no hub-wide feature/status flags */
1156*4882a593Smuzhiyun 			break;
1157*4882a593Smuzhiyun 		default:
1158*4882a593Smuzhiyun 			goto error;
1159*4882a593Smuzhiyun 		}
1160*4882a593Smuzhiyun 		break;
1161*4882a593Smuzhiyun 	case SetPortFeature:
1162*4882a593Smuzhiyun 		selector = wIndex >> 8;
1163*4882a593Smuzhiyun 		wIndex &= 0xff;
1164*4882a593Smuzhiyun 		if (unlikely(ehci->debug)) {
1165*4882a593Smuzhiyun 			/* If the debug port is active any port
1166*4882a593Smuzhiyun 			 * feature requests should get denied */
1167*4882a593Smuzhiyun 			if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) &&
1168*4882a593Smuzhiyun 			    (readl(&ehci->debug->control) & DBGP_ENABLED)) {
1169*4882a593Smuzhiyun 				retval = -ENODEV;
1170*4882a593Smuzhiyun 				goto error_exit;
1171*4882a593Smuzhiyun 			}
1172*4882a593Smuzhiyun 		}
1173*4882a593Smuzhiyun 		if (!wIndex || wIndex > ports)
1174*4882a593Smuzhiyun 			goto error;
1175*4882a593Smuzhiyun 		wIndex--;
1176*4882a593Smuzhiyun 		temp = ehci_readl(ehci, status_reg);
1177*4882a593Smuzhiyun 		if (temp & PORT_OWNER)
1178*4882a593Smuzhiyun 			break;
1179*4882a593Smuzhiyun 
1180*4882a593Smuzhiyun 		temp &= ~PORT_RWC_BITS;
1181*4882a593Smuzhiyun 		switch (wValue) {
1182*4882a593Smuzhiyun 		case USB_PORT_FEAT_SUSPEND:
1183*4882a593Smuzhiyun 			if (ehci->no_selective_suspend)
1184*4882a593Smuzhiyun 				break;
1185*4882a593Smuzhiyun 			if ((temp & PORT_PE) == 0
1186*4882a593Smuzhiyun 					|| (temp & PORT_RESET) != 0)
1187*4882a593Smuzhiyun 				goto error;
1188*4882a593Smuzhiyun 
1189*4882a593Smuzhiyun 			/* After above check the port must be connected.
1190*4882a593Smuzhiyun 			 * Set appropriate bit thus could put phy into low power
1191*4882a593Smuzhiyun 			 * mode if we have tdi_phy_lpm feature
1192*4882a593Smuzhiyun 			 */
1193*4882a593Smuzhiyun 			temp &= ~PORT_WKCONN_E;
1194*4882a593Smuzhiyun 			temp |= PORT_WKDISC_E | PORT_WKOC_E;
1195*4882a593Smuzhiyun 			ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
1196*4882a593Smuzhiyun 			if (ehci->has_tdi_phy_lpm) {
1197*4882a593Smuzhiyun 				spin_unlock_irqrestore(&ehci->lock, flags);
1198*4882a593Smuzhiyun 				msleep(5);/* 5ms for HCD enter low pwr mode */
1199*4882a593Smuzhiyun 				spin_lock_irqsave(&ehci->lock, flags);
1200*4882a593Smuzhiyun 				temp1 = ehci_readl(ehci, hostpc_reg);
1201*4882a593Smuzhiyun 				ehci_writel(ehci, temp1 | HOSTPC_PHCD,
1202*4882a593Smuzhiyun 					hostpc_reg);
1203*4882a593Smuzhiyun 				temp1 = ehci_readl(ehci, hostpc_reg);
1204*4882a593Smuzhiyun 				ehci_dbg(ehci, "Port%d phy low pwr mode %s\n",
1205*4882a593Smuzhiyun 					wIndex, (temp1 & HOSTPC_PHCD) ?
1206*4882a593Smuzhiyun 					"succeeded" : "failed");
1207*4882a593Smuzhiyun 			}
1208*4882a593Smuzhiyun 			if (ehci_has_fsl_susp_errata(ehci)) {
1209*4882a593Smuzhiyun 				/* 10ms for HCD enter suspend */
1210*4882a593Smuzhiyun 				spin_unlock_irqrestore(&ehci->lock, flags);
1211*4882a593Smuzhiyun 				usleep_range(10000, 20000);
1212*4882a593Smuzhiyun 				spin_lock_irqsave(&ehci->lock, flags);
1213*4882a593Smuzhiyun 			}
1214*4882a593Smuzhiyun 			set_bit(wIndex, &ehci->suspended_ports);
1215*4882a593Smuzhiyun 			break;
1216*4882a593Smuzhiyun 		case USB_PORT_FEAT_POWER:
1217*4882a593Smuzhiyun 			if (HCS_PPC(ehci->hcs_params)) {
1218*4882a593Smuzhiyun 				spin_unlock_irqrestore(&ehci->lock, flags);
1219*4882a593Smuzhiyun 				ehci_port_power(ehci, wIndex, true);
1220*4882a593Smuzhiyun 				spin_lock_irqsave(&ehci->lock, flags);
1221*4882a593Smuzhiyun 			}
1222*4882a593Smuzhiyun 			break;
1223*4882a593Smuzhiyun 		case USB_PORT_FEAT_RESET:
1224*4882a593Smuzhiyun 			if (temp & (PORT_SUSPEND|PORT_RESUME))
1225*4882a593Smuzhiyun 				goto error;
1226*4882a593Smuzhiyun 			/* line status bits may report this as low speed,
1227*4882a593Smuzhiyun 			 * which can be fine if this root hub has a
1228*4882a593Smuzhiyun 			 * transaction translator built in.
1229*4882a593Smuzhiyun 			 */
1230*4882a593Smuzhiyun 			if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
1231*4882a593Smuzhiyun 					&& !ehci_is_TDI(ehci)
1232*4882a593Smuzhiyun 					&& PORT_USB11 (temp)) {
1233*4882a593Smuzhiyun 				ehci_dbg (ehci,
1234*4882a593Smuzhiyun 					"port %d low speed --> companion\n",
1235*4882a593Smuzhiyun 					wIndex + 1);
1236*4882a593Smuzhiyun 				temp |= PORT_OWNER;
1237*4882a593Smuzhiyun 			} else {
1238*4882a593Smuzhiyun 				temp |= PORT_RESET;
1239*4882a593Smuzhiyun 				temp &= ~PORT_PE;
1240*4882a593Smuzhiyun 
1241*4882a593Smuzhiyun 				/*
1242*4882a593Smuzhiyun 				 * caller must wait, then call GetPortStatus
1243*4882a593Smuzhiyun 				 * usb 2.0 spec says 50 ms resets on root
1244*4882a593Smuzhiyun 				 */
1245*4882a593Smuzhiyun 				ehci->reset_done [wIndex] = jiffies
1246*4882a593Smuzhiyun 						+ msecs_to_jiffies (50);
1247*4882a593Smuzhiyun 
1248*4882a593Smuzhiyun 				/*
1249*4882a593Smuzhiyun 				 * Force full-speed connect for FSL high-speed
1250*4882a593Smuzhiyun 				 * erratum; disable HS Chirp by setting PFSC bit
1251*4882a593Smuzhiyun 				 */
1252*4882a593Smuzhiyun 				if (ehci_has_fsl_hs_errata(ehci))
1253*4882a593Smuzhiyun 					temp |= (1 << PORTSC_FSL_PFSC);
1254*4882a593Smuzhiyun 			}
1255*4882a593Smuzhiyun 			ehci_writel(ehci, temp, status_reg);
1256*4882a593Smuzhiyun 			break;
1257*4882a593Smuzhiyun 
1258*4882a593Smuzhiyun 		/* For downstream facing ports (these):  one hub port is put
1259*4882a593Smuzhiyun 		 * into test mode according to USB2 11.24.2.13, then the hub
1260*4882a593Smuzhiyun 		 * must be reset (which for root hub now means rmmod+modprobe,
1261*4882a593Smuzhiyun 		 * or else system reboot).  See EHCI 2.3.9 and 4.14 for info
1262*4882a593Smuzhiyun 		 * about the EHCI-specific stuff.
1263*4882a593Smuzhiyun 		 */
1264*4882a593Smuzhiyun 		case USB_PORT_FEAT_TEST:
1265*4882a593Smuzhiyun #ifdef CONFIG_USB_HCD_TEST_MODE
1266*4882a593Smuzhiyun 			if (selector == EHSET_TEST_SINGLE_STEP_SET_FEATURE) {
1267*4882a593Smuzhiyun 				spin_unlock_irqrestore(&ehci->lock, flags);
1268*4882a593Smuzhiyun 				retval = ehset_single_step_set_feature(hcd,
1269*4882a593Smuzhiyun 								wIndex + 1);
1270*4882a593Smuzhiyun 				spin_lock_irqsave(&ehci->lock, flags);
1271*4882a593Smuzhiyun 				break;
1272*4882a593Smuzhiyun 			}
1273*4882a593Smuzhiyun #endif
1274*4882a593Smuzhiyun 			if (!selector || selector > 5)
1275*4882a593Smuzhiyun 				goto error;
1276*4882a593Smuzhiyun 			spin_unlock_irqrestore(&ehci->lock, flags);
1277*4882a593Smuzhiyun 			ehci_quiesce(ehci);
1278*4882a593Smuzhiyun 			spin_lock_irqsave(&ehci->lock, flags);
1279*4882a593Smuzhiyun 
1280*4882a593Smuzhiyun 			/* Put all enabled ports into suspend */
1281*4882a593Smuzhiyun 			while (ports--) {
1282*4882a593Smuzhiyun 				u32 __iomem *sreg =
1283*4882a593Smuzhiyun 						&ehci->regs->port_status[ports];
1284*4882a593Smuzhiyun 
1285*4882a593Smuzhiyun 				temp = ehci_readl(ehci, sreg) & ~PORT_RWC_BITS;
1286*4882a593Smuzhiyun 				if (temp & PORT_PE)
1287*4882a593Smuzhiyun 					ehci_writel(ehci, temp | PORT_SUSPEND,
1288*4882a593Smuzhiyun 							sreg);
1289*4882a593Smuzhiyun 			}
1290*4882a593Smuzhiyun 
1291*4882a593Smuzhiyun 			spin_unlock_irqrestore(&ehci->lock, flags);
1292*4882a593Smuzhiyun 			ehci_halt(ehci);
1293*4882a593Smuzhiyun 			spin_lock_irqsave(&ehci->lock, flags);
1294*4882a593Smuzhiyun 
1295*4882a593Smuzhiyun 			temp = ehci_readl(ehci, status_reg);
1296*4882a593Smuzhiyun 			temp |= selector << 16;
1297*4882a593Smuzhiyun 			ehci_writel(ehci, temp, status_reg);
1298*4882a593Smuzhiyun 			break;
1299*4882a593Smuzhiyun 
1300*4882a593Smuzhiyun 		default:
1301*4882a593Smuzhiyun 			goto error;
1302*4882a593Smuzhiyun 		}
1303*4882a593Smuzhiyun 		ehci_readl(ehci, &ehci->regs->command);	/* unblock posted writes */
1304*4882a593Smuzhiyun 		break;
1305*4882a593Smuzhiyun 
1306*4882a593Smuzhiyun 	default:
1307*4882a593Smuzhiyun error:
1308*4882a593Smuzhiyun 		/* "stall" on error */
1309*4882a593Smuzhiyun 		retval = -EPIPE;
1310*4882a593Smuzhiyun 	}
1311*4882a593Smuzhiyun error_exit:
1312*4882a593Smuzhiyun 	spin_unlock_irqrestore (&ehci->lock, flags);
1313*4882a593Smuzhiyun 	return retval;
1314*4882a593Smuzhiyun }
1315*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(ehci_hub_control);
1316*4882a593Smuzhiyun 
ehci_relinquish_port(struct usb_hcd * hcd,int portnum)1317*4882a593Smuzhiyun static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum)
1318*4882a593Smuzhiyun {
1319*4882a593Smuzhiyun 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
1320*4882a593Smuzhiyun 
1321*4882a593Smuzhiyun 	if (ehci_is_TDI(ehci))
1322*4882a593Smuzhiyun 		return;
1323*4882a593Smuzhiyun 	set_owner(ehci, --portnum, PORT_OWNER);
1324*4882a593Smuzhiyun }
1325*4882a593Smuzhiyun 
ehci_port_handed_over(struct usb_hcd * hcd,int portnum)1326*4882a593Smuzhiyun static int ehci_port_handed_over(struct usb_hcd *hcd, int portnum)
1327*4882a593Smuzhiyun {
1328*4882a593Smuzhiyun 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
1329*4882a593Smuzhiyun 	u32 __iomem		*reg;
1330*4882a593Smuzhiyun 
1331*4882a593Smuzhiyun 	if (ehci_is_TDI(ehci))
1332*4882a593Smuzhiyun 		return 0;
1333*4882a593Smuzhiyun 	reg = &ehci->regs->port_status[portnum - 1];
1334*4882a593Smuzhiyun 	return ehci_readl(ehci, reg) & PORT_OWNER;
1335*4882a593Smuzhiyun }
1336*4882a593Smuzhiyun 
ehci_port_power(struct ehci_hcd * ehci,int portnum,bool enable)1337*4882a593Smuzhiyun static int ehci_port_power(struct ehci_hcd *ehci, int portnum, bool enable)
1338*4882a593Smuzhiyun {
1339*4882a593Smuzhiyun 	struct usb_hcd *hcd = ehci_to_hcd(ehci);
1340*4882a593Smuzhiyun 	u32 __iomem *status_reg = &ehci->regs->port_status[portnum];
1341*4882a593Smuzhiyun 	u32 temp = ehci_readl(ehci, status_reg) & ~PORT_RWC_BITS;
1342*4882a593Smuzhiyun 
1343*4882a593Smuzhiyun 	if (enable)
1344*4882a593Smuzhiyun 		ehci_writel(ehci, temp | PORT_POWER, status_reg);
1345*4882a593Smuzhiyun 	else
1346*4882a593Smuzhiyun 		ehci_writel(ehci, temp & ~PORT_POWER, status_reg);
1347*4882a593Smuzhiyun 
1348*4882a593Smuzhiyun 	if (hcd->driver->port_power)
1349*4882a593Smuzhiyun 		hcd->driver->port_power(hcd, portnum, enable);
1350*4882a593Smuzhiyun 
1351*4882a593Smuzhiyun 	return 0;
1352*4882a593Smuzhiyun }
1353