RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / usb / host / ehci-lpm.c
blobb4d4d63c13ed84616d11bc6dcde488b9626b53f8
1 /* ehci-lpm.c EHCI HCD LPM support code
2 * Copyright (c) 2008 - 2010, Intel Corporation.
3 * Author: Jacob Pan <jacob.jun.pan@intel.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* this file is part of ehci-hcd.c */
20 static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num)
22 u32 __iomem portsc;
24 ehci_dbg(ehci, "set dev address %d for port %d\n", dev_addr, port_num);
25 if (port_num > HCS_N_PORTS(ehci->hcs_params)) {
26 ehci_dbg(ehci, "invalid port number %d\n", port_num);
27 return -ENODEV;
29 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_num-1]);
30 portsc &= ~PORT_DEV_ADDR;
31 portsc |= dev_addr<<25;
32 ehci_writel(ehci, portsc, &ehci->regs->port_status[port_num-1]);
33 return 0;
37 * this function is used to check if the device support LPM
38 * if yes, mark the PORTSC register with PORT_LPM bit
40 static int ehci_lpm_check(struct ehci_hcd *ehci, int port)
42 u32 __iomem *portsc ;
43 u32 val32;
44 int retval;
46 portsc = &ehci->regs->port_status[port-1];
47 val32 = ehci_readl(ehci, portsc);
48 if (!(val32 & PORT_DEV_ADDR)) {
49 ehci_dbg(ehci, "LPM: no device attached\n");
50 return -ENODEV;
52 val32 |= PORT_LPM;
53 ehci_writel(ehci, val32, portsc);
54 msleep(5);
55 val32 |= PORT_SUSPEND;
56 ehci_dbg(ehci, "Sending LPM 0x%08x to port %d\n", val32, port);
57 ehci_writel(ehci, val32, portsc);
58 /* wait for ACK */
59 msleep(10);
60 retval = handshake(ehci, &ehci->regs->port_status[port-1], PORT_SSTS,
61 PORTSC_SUSPEND_STS_ACK, 125);
62 dbg_port(ehci, "LPM", port, val32);
63 if (retval != -ETIMEDOUT) {
64 ehci_dbg(ehci, "LPM: device ACK for LPM\n");
65 val32 |= PORT_LPM;
67 * now device should be in L1 sleep, let's wake up the device
68 * so that we can complete enumeration.
70 ehci_writel(ehci, val32, portsc);
71 msleep(10);
72 val32 |= PORT_RESUME;
73 ehci_writel(ehci, val32, portsc);
74 } else {
75 ehci_dbg(ehci, "LPM: device does not ACK, disable LPM %d\n",
76 retval);
77 val32 &= ~PORT_LPM;
78 retval = -ETIMEDOUT;
79 ehci_writel(ehci, val32, portsc);
82 return retval;