ehci-lpm.c 2.6 KB

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