PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 6ms app.codeStats 0ms

/drivers/staging/et131x/et1310_pm.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 180 lines | 57 code | 23 blank | 100 comment | 0 complexity | 4d353c6a0054d973eec880a2612262de MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * Agere Systems Inc.
  3. * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
  4. *
  5. * Copyright © 2005 Agere Systems Inc.
  6. * All rights reserved.
  7. * http://www.agere.com
  8. *
  9. *------------------------------------------------------------------------------
  10. *
  11. * et1310_pm.c - All power management related code (not completely implemented)
  12. *
  13. *------------------------------------------------------------------------------
  14. *
  15. * SOFTWARE LICENSE
  16. *
  17. * This software is provided subject to the following terms and conditions,
  18. * which you should read carefully before using the software. Using this
  19. * software indicates your acceptance of these terms and conditions. If you do
  20. * not agree with these terms and conditions, do not use the software.
  21. *
  22. * Copyright © 2005 Agere Systems Inc.
  23. * All rights reserved.
  24. *
  25. * Redistribution and use in source or binary forms, with or without
  26. * modifications, are permitted provided that the following conditions are met:
  27. *
  28. * . Redistributions of source code must retain the above copyright notice, this
  29. * list of conditions and the following Disclaimer as comments in the code as
  30. * well as in the documentation and/or other materials provided with the
  31. * distribution.
  32. *
  33. * . Redistributions in binary form must reproduce the above copyright notice,
  34. * this list of conditions and the following Disclaimer in the documentation
  35. * and/or other materials provided with the distribution.
  36. *
  37. * . Neither the name of Agere Systems Inc. nor the names of the contributors
  38. * may be used to endorse or promote products derived from this software
  39. * without specific prior written permission.
  40. *
  41. * Disclaimer
  42. *
  43. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  44. * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
  45. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
  46. * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
  47. * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
  48. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  49. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  50. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  51. * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
  52. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  53. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54. * DAMAGE.
  55. *
  56. */
  57. #include "et131x_version.h"
  58. #include "et131x_defs.h"
  59. #include <linux/init.h>
  60. #include <linux/module.h>
  61. #include <linux/types.h>
  62. #include <linux/kernel.h>
  63. #include <linux/sched.h>
  64. #include <linux/ptrace.h>
  65. #include <linux/ctype.h>
  66. #include <linux/string.h>
  67. #include <linux/timer.h>
  68. #include <linux/interrupt.h>
  69. #include <linux/in.h>
  70. #include <linux/delay.h>
  71. #include <linux/io.h>
  72. #include <linux/bitops.h>
  73. #include <asm/system.h>
  74. #include <linux/netdevice.h>
  75. #include <linux/etherdevice.h>
  76. #include <linux/skbuff.h>
  77. #include <linux/if_arp.h>
  78. #include <linux/ioport.h>
  79. #include "et1310_phy.h"
  80. #include "et1310_rx.h"
  81. #include "et131x_adapter.h"
  82. #include "et131x.h"
  83. /**
  84. * EnablePhyComa - called when network cable is unplugged
  85. * @etdev: pointer to our adapter structure
  86. *
  87. * driver receive an phy status change interrupt while in D0 and check that
  88. * phy_status is down.
  89. *
  90. * -- gate off JAGCore;
  91. * -- set gigE PHY in Coma mode
  92. * -- wake on phy_interrupt; Perform software reset JAGCore,
  93. * re-initialize jagcore and gigE PHY
  94. *
  95. * Add D0-ASPM-PhyLinkDown Support:
  96. * -- while in D0, when there is a phy_interrupt indicating phy link
  97. * down status, call the MPSetPhyComa routine to enter this active
  98. * state power saving mode
  99. * -- while in D0-ASPM-PhyLinkDown mode, when there is a phy_interrupt
  100. * indicating linkup status, call the MPDisablePhyComa routine to
  101. * restore JAGCore and gigE PHY
  102. */
  103. void EnablePhyComa(struct et131x_adapter *etdev)
  104. {
  105. unsigned long flags;
  106. u32 pmcsr;
  107. pmcsr = readl(&etdev->regs->global.pm_csr);
  108. /* Save the GbE PHY speed and duplex modes. Need to restore this
  109. * when cable is plugged back in
  110. */
  111. etdev->pdown_speed = etdev->AiForceSpeed;
  112. etdev->pdown_duplex = etdev->AiForceDpx;
  113. /* Stop sending packets. */
  114. spin_lock_irqsave(&etdev->send_hw_lock, flags);
  115. etdev->Flags |= fMP_ADAPTER_LOWER_POWER;
  116. spin_unlock_irqrestore(&etdev->send_hw_lock, flags);
  117. /* Wait for outstanding Receive packets */
  118. /* Gate off JAGCore 3 clock domains */
  119. pmcsr &= ~ET_PMCSR_INIT;
  120. writel(pmcsr, &etdev->regs->global.pm_csr);
  121. /* Program gigE PHY in to Coma mode */
  122. pmcsr |= ET_PM_PHY_SW_COMA;
  123. writel(pmcsr, &etdev->regs->global.pm_csr);
  124. }
  125. /**
  126. * DisablePhyComa - Disable the Phy Coma Mode
  127. * @etdev: pointer to our adapter structure
  128. */
  129. void DisablePhyComa(struct et131x_adapter *etdev)
  130. {
  131. u32 pmcsr;
  132. pmcsr = readl(&etdev->regs->global.pm_csr);
  133. /* Disable phy_sw_coma register and re-enable JAGCore clocks */
  134. pmcsr |= ET_PMCSR_INIT;
  135. pmcsr &= ~ET_PM_PHY_SW_COMA;
  136. writel(pmcsr, &etdev->regs->global.pm_csr);
  137. /* Restore the GbE PHY speed and duplex modes;
  138. * Reset JAGCore; re-configure and initialize JAGCore and gigE PHY
  139. */
  140. etdev->AiForceSpeed = etdev->pdown_speed;
  141. etdev->AiForceDpx = etdev->pdown_duplex;
  142. /* Re-initialize the send structures */
  143. et131x_init_send(etdev);
  144. /* Reset the RFD list and re-start RU */
  145. et131x_reset_recv(etdev);
  146. /* Bring the device back to the state it was during init prior to
  147. * autonegotiation being complete. This way, when we get the auto-neg
  148. * complete interrupt, we can complete init by calling ConfigMacREGS2.
  149. */
  150. et131x_soft_reset(etdev);
  151. /* setup et1310 as per the documentation ?? */
  152. et131x_adapter_setup(etdev);
  153. /* Allow Tx to restart */
  154. etdev->Flags &= ~fMP_ADAPTER_LOWER_POWER;
  155. /* Need to re-enable Rx. */
  156. et131x_rx_dma_enable(etdev);
  157. }