ehci-lpm.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /* this file is part of ehci-hcd.c */
  19. static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num)
  20. {
  21. u32 __iomem portsc;
  22. ehci_dbg(ehci, "set dev address %d for port %d\n", dev_addr, port_num);
  23. if (port_num > HCS_N_PORTS(ehci->hcs_params)) {
  24. ehci_dbg(ehci, "invalid port number %d\n", port_num);
  25. return -ENODEV;
  26. }
  27. portsc = ehci_readl(ehci, &ehci->regs->port_status[port_num-1]);
  28. portsc &= ~PORT_DEV_ADDR;
  29. portsc |= dev_addr<<25;
  30. ehci_writel(ehci, portsc, &ehci->regs->port_status[port_num-1]);
  31. return 0;
  32. }
  33. /*
  34. * this function is used to check if the device support LPM
  35. * if yes, mark the PORTSC register with PORT_LPM bit
  36. */
  37. static int ehci_lpm_check(struct ehci_hcd *ehci, int port)
  38. {
  39. u32 __iomem *portsc ;
  40. u32 val32;
  41. int retval;
  42. portsc = &ehci->regs->port_status[port-1];
  43. val32 = ehci_readl(ehci, portsc);
  44. if (!(val32 & PORT_DEV_ADDR)) {
  45. ehci_dbg(ehci, "LPM: no device attached\n");
  46. return -ENODEV;
  47. }
  48. val32 |= PORT_LPM;
  49. ehci_writel(ehci, val32, portsc);
  50. msleep(5);
  51. val32 |= PORT_SUSPEND;
  52. ehci_dbg(ehci, "Sending LPM 0x%08x to port %d\n", val32, port);
  53. ehci_writel(ehci, val32, portsc);
  54. /* wait for ACK */
  55. msleep(10);
  56. retval = handshake(ehci, &ehci->regs->port_status[port-1], PORT_SSTS,
  57. PORTSC_SUSPEND_STS_ACK, 125);
  58. dbg_port(ehci, "LPM", port, val32);
  59. if (retval != -ETIMEDOUT) {
  60. ehci_dbg(ehci, "LPM: device ACK for LPM\n");
  61. val32 |= PORT_LPM;
  62. /*
  63. * now device should be in L1 sleep, let's wake up the device
  64. * so that we can complete enumeration.
  65. */
  66. ehci_writel(ehci, val32, portsc);
  67. msleep(10);
  68. val32 |= PORT_RESUME;
  69. ehci_writel(ehci, val32, portsc);
  70. } else {
  71. ehci_dbg(ehci, "LPM: device does not ACK, disable LPM %d\n",
  72. retval);
  73. val32 &= ~PORT_LPM;
  74. retval = -ETIMEDOUT;
  75. ehci_writel(ehci, val32, portsc);
  76. }
  77. return retval;
  78. }