aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAlek Du <alek.du@intel.com>2010-06-04 03:47:55 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-08-10 17:35:35 -0400
commit48f24970144479c29b8cee6d2e1dbedf6dcf9cfb (patch)
tree5a4944c496f4209a862188c16f29cdef55db3224 /drivers
parentaa4d8342988d0c1a79ff19b2ede1e81dfbb16ea5 (diff)
USB: EHCI: EHCI 1.1 addendum: Basic LPM feature support
With this patch, the LPM capable EHCI host controller can put device into L1 sleep state which is a mode that can enter/exit quickly, and reduce power consumption. Signed-off-by: Jacob Pan <jacob.jun.pan@intel.com> Signed-off-by: Alek Du <alek.du@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/core/hub.c4
-rw-r--r--drivers/usb/host/ehci-hcd.c17
-rw-r--r--drivers/usb/host/ehci-hub.c5
-rw-r--r--drivers/usb/host/ehci-lpm.c83
-rw-r--r--drivers/usb/host/ehci-pci.c21
-rw-r--r--drivers/usb/host/ehci.h2
6 files changed, 130 insertions, 2 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 70cccc75a362..9cd77a2af821 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2880,7 +2880,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2880 } 2880 }
2881 2881
2882 retval = 0; 2882 retval = 0;
2883 2883 /* notify HCD that we have a device connected and addressed */
2884 if (hcd->driver->update_device)
2885 hcd->driver->update_device(hcd, udev);
2884fail: 2886fail:
2885 if (retval) { 2887 if (retval) {
2886 hub_port_disable(hub, port1, 0); 2888 hub_port_disable(hub, port1, 0);
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 20ca6a9ff213..baf9b648bb1f 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -101,6 +101,11 @@ static int ignore_oc = 0;
101module_param (ignore_oc, bool, S_IRUGO); 101module_param (ignore_oc, bool, S_IRUGO);
102MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications"); 102MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
103 103
104/* for link power management(LPM) feature */
105static unsigned int hird;
106module_param(hird, int, S_IRUGO);
107MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n");
108
104#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) 109#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
105 110
106/*-------------------------------------------------------------------------*/ 111/*-------------------------------------------------------------------------*/
@@ -305,6 +310,7 @@ static void end_unlink_async(struct ehci_hcd *ehci);
305static void ehci_work(struct ehci_hcd *ehci); 310static void ehci_work(struct ehci_hcd *ehci);
306 311
307#include "ehci-hub.c" 312#include "ehci-hub.c"
313#include "ehci-lpm.c"
308#include "ehci-mem.c" 314#include "ehci-mem.c"
309#include "ehci-q.c" 315#include "ehci-q.c"
310#include "ehci-sched.c" 316#include "ehci-sched.c"
@@ -604,6 +610,17 @@ static int ehci_init(struct usb_hcd *hcd)
604 default: BUG(); 610 default: BUG();
605 } 611 }
606 } 612 }
613 if (HCC_LPM(hcc_params)) {
614 /* support link power management EHCI 1.1 addendum */
615 ehci_dbg(ehci, "support lpm\n");
616 ehci->has_lpm = 1;
617 if (hird > 0xf) {
618 ehci_dbg(ehci, "hird %d invalid, use default 0",
619 hird);
620 hird = 0;
621 }
622 temp |= hird << 24;
623 }
607 ehci->command = temp; 624 ehci->command = temp;
608 625
609 /* Accept arbitrarily long scatter-gather lists */ 626 /* Accept arbitrarily long scatter-gather lists */
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index e7d3d8def282..8a28dae8a375 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -790,6 +790,11 @@ static int ehci_hub_control (
790 status_reg); 790 status_reg);
791 break; 791 break;
792 case USB_PORT_FEAT_C_CONNECTION: 792 case USB_PORT_FEAT_C_CONNECTION:
793 if (ehci->has_lpm) {
794 /* clear PORTSC bits on disconnect */
795 temp &= ~PORT_LPM;
796 temp &= ~PORT_DEV_ADDR;
797 }
793 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC, 798 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC,
794 status_reg); 799 status_reg);
795 break; 800 break;
diff --git a/drivers/usb/host/ehci-lpm.c b/drivers/usb/host/ehci-lpm.c
new file mode 100644
index 000000000000..b4d4d63c13ed
--- /dev/null
+++ b/drivers/usb/host/ehci-lpm.c
@@ -0,0 +1,83 @@
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>
4 *
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.
8 *
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.
13 *
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.
17*/
18
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)
21{
22 u32 __iomem portsc;
23
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;
28 }
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;
34}
35
36/*
37 * this function is used to check if the device support LPM
38 * if yes, mark the PORTSC register with PORT_LPM bit
39 */
40static int ehci_lpm_check(struct ehci_hcd *ehci, int port)
41{
42 u32 __iomem *portsc ;
43 u32 val32;
44 int retval;
45
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;
51 }
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;
66 /*
67 * now device should be in L1 sleep, let's wake up the device
68 * so that we can complete enumeration.
69 */
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);
80 }
81
82 return retval;
83}
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index d43d176161aa..a307d550bdaf 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -361,6 +361,22 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
361} 361}
362#endif 362#endif
363 363
364static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
365{
366 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
367 int rc = 0;
368
369 if (!udev->parent) /* udev is root hub itself, impossible */
370 rc = -1;
371 /* we only support lpm device connected to root hub yet */
372 if (ehci->has_lpm && !udev->parent->parent) {
373 rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
374 if (!rc)
375 rc = ehci_lpm_check(ehci, udev->portnum);
376 }
377 return rc;
378}
379
364static const struct hc_driver ehci_pci_hc_driver = { 380static const struct hc_driver ehci_pci_hc_driver = {
365 .description = hcd_name, 381 .description = hcd_name,
366 .product_desc = "EHCI Host Controller", 382 .product_desc = "EHCI Host Controller",
@@ -407,6 +423,11 @@ static const struct hc_driver ehci_pci_hc_driver = {
407 .relinquish_port = ehci_relinquish_port, 423 .relinquish_port = ehci_relinquish_port,
408 .port_handed_over = ehci_port_handed_over, 424 .port_handed_over = ehci_port_handed_over,
409 425
426 /*
427 * call back when device connected and addressed
428 */
429 .update_device = ehci_update_device,
430
410 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 431 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
411}; 432};
412 433
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index bfaac1646365..21f30a0c3d2f 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -140,7 +140,7 @@ struct ehci_hcd { /* one per controller */
140 #define OHCI_HCCTRL_LEN 0x4 140 #define OHCI_HCCTRL_LEN 0x4
141 __hc32 *ohci_hcctrl_reg; 141 __hc32 *ohci_hcctrl_reg;
142 unsigned has_hostpc:1; 142 unsigned has_hostpc:1;
143 143 unsigned has_lpm:1; /* support link power management */
144 u8 sbrn; /* packed release number */ 144 u8 sbrn; /* packed release number */
145 145
146 /* irq statistics */ 146 /* irq statistics */