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