aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Carlson <mcarlson@broadcom.com>2011-06-13 09:39:02 -0400
committerDavid S. Miller <davem@conan.davemloft.net>2011-06-15 11:11:58 -0400
commit520b2756d9414cb6b0f6fc70714e95ee9248ebf4 (patch)
tree0f204d3e50a141d4dcdb7d678553225da7ec2d7a
parent221c56373ee7088dd3015b928782d5e70dc5074e (diff)
tg3: Create funcs for power source switching
The power source switching code is about to get a little more complex. This patch seeks to simplify future power source switching patches by clarifying the existing code. Signed-off-by: Matt Carlson <mcarlson@broadcom.com> Reviewed-by: Michael Chan <mchan@broadcom.com> Reviewed-by: Benjamin Li <benli@broadcom.com> Signed-off-by: David S. Miller <davem@conan.davemloft.net>
-rw-r--r--drivers/net/tg3.c201
1 files changed, 119 insertions, 82 deletions
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index da5e9105b9f4..ca6687a94225 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -107,6 +107,8 @@ static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits)
107 NETIF_MSG_RX_ERR | \ 107 NETIF_MSG_RX_ERR | \
108 NETIF_MSG_TX_ERR) 108 NETIF_MSG_TX_ERR)
109 109
110#define TG3_GRC_LCLCTL_PWRSW_DELAY 100
111
110/* length of time before we decide the hardware is borked, 112/* length of time before we decide the hardware is borked,
111 * and dev->tx_timeout() should be called to fix the problem 113 * and dev->tx_timeout() should be called to fix the problem
112 */ 114 */
@@ -2165,6 +2167,118 @@ out:
2165 return 0; 2167 return 0;
2166} 2168}
2167 2169
2170static inline int tg3_pwrsrc_switch_to_vmain(struct tg3 *tp)
2171{
2172 if (!tg3_flag(tp, IS_NIC))
2173 return 0;
2174
2175 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl,
2176 TG3_GRC_LCLCTL_PWRSW_DELAY);
2177
2178 return 0;
2179}
2180
2181static void tg3_pwrsrc_die_with_vmain(struct tg3 *tp)
2182{
2183 u32 grc_local_ctrl;
2184
2185 if (!tg3_flag(tp, IS_NIC) ||
2186 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
2187 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)
2188 return;
2189
2190 grc_local_ctrl = tp->grc_local_ctrl | GRC_LCLCTRL_GPIO_OE1;
2191
2192 tw32_wait_f(GRC_LOCAL_CTRL,
2193 grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1,
2194 TG3_GRC_LCLCTL_PWRSW_DELAY);
2195
2196 tw32_wait_f(GRC_LOCAL_CTRL,
2197 grc_local_ctrl,
2198 TG3_GRC_LCLCTL_PWRSW_DELAY);
2199
2200 tw32_wait_f(GRC_LOCAL_CTRL,
2201 grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1,
2202 TG3_GRC_LCLCTL_PWRSW_DELAY);
2203}
2204
2205static void tg3_pwrsrc_switch_to_vaux(struct tg3 *tp)
2206{
2207 if (!tg3_flag(tp, IS_NIC))
2208 return;
2209
2210 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
2211 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) {
2212 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2213 (GRC_LCLCTRL_GPIO_OE0 |
2214 GRC_LCLCTRL_GPIO_OE1 |
2215 GRC_LCLCTRL_GPIO_OE2 |
2216 GRC_LCLCTRL_GPIO_OUTPUT0 |
2217 GRC_LCLCTRL_GPIO_OUTPUT1),
2218 TG3_GRC_LCLCTL_PWRSW_DELAY);
2219 } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 ||
2220 tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) {
2221 /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */
2222 u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 |
2223 GRC_LCLCTRL_GPIO_OE1 |
2224 GRC_LCLCTRL_GPIO_OE2 |
2225 GRC_LCLCTRL_GPIO_OUTPUT0 |
2226 GRC_LCLCTRL_GPIO_OUTPUT1 |
2227 tp->grc_local_ctrl;
2228 tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl,
2229 TG3_GRC_LCLCTL_PWRSW_DELAY);
2230
2231 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2;
2232 tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl,
2233 TG3_GRC_LCLCTL_PWRSW_DELAY);
2234
2235 grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0;
2236 tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl,
2237 TG3_GRC_LCLCTL_PWRSW_DELAY);
2238 } else {
2239 u32 no_gpio2;
2240 u32 grc_local_ctrl = 0;
2241
2242 /* Workaround to prevent overdrawing Amps. */
2243 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
2244 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
2245 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2246 grc_local_ctrl,
2247 TG3_GRC_LCLCTL_PWRSW_DELAY);
2248 }
2249
2250 /* On 5753 and variants, GPIO2 cannot be used. */
2251 no_gpio2 = tp->nic_sram_data_cfg &
2252 NIC_SRAM_DATA_CFG_NO_GPIO2;
2253
2254 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
2255 GRC_LCLCTRL_GPIO_OE1 |
2256 GRC_LCLCTRL_GPIO_OE2 |
2257 GRC_LCLCTRL_GPIO_OUTPUT1 |
2258 GRC_LCLCTRL_GPIO_OUTPUT2;
2259 if (no_gpio2) {
2260 grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
2261 GRC_LCLCTRL_GPIO_OUTPUT2);
2262 }
2263 tw32_wait_f(GRC_LOCAL_CTRL,
2264 tp->grc_local_ctrl | grc_local_ctrl,
2265 TG3_GRC_LCLCTL_PWRSW_DELAY);
2266
2267 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
2268
2269 tw32_wait_f(GRC_LOCAL_CTRL,
2270 tp->grc_local_ctrl | grc_local_ctrl,
2271 TG3_GRC_LCLCTL_PWRSW_DELAY);
2272
2273 if (!no_gpio2) {
2274 grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
2275 tw32_wait_f(GRC_LOCAL_CTRL,
2276 tp->grc_local_ctrl | grc_local_ctrl,
2277 TG3_GRC_LCLCTL_PWRSW_DELAY);
2278 }
2279 }
2280}
2281
2168static void tg3_frob_aux_power(struct tg3 *tp) 2282static void tg3_frob_aux_power(struct tg3 *tp)
2169{ 2283{
2170 bool need_vaux = false; 2284 bool need_vaux = false;
@@ -2200,86 +2314,10 @@ static void tg3_frob_aux_power(struct tg3 *tp)
2200 if (tg3_flag(tp, WOL_ENABLE) || tg3_flag(tp, ENABLE_ASF)) 2314 if (tg3_flag(tp, WOL_ENABLE) || tg3_flag(tp, ENABLE_ASF))
2201 need_vaux = true; 2315 need_vaux = true;
2202 2316
2203 if (need_vaux) { 2317 if (need_vaux)
2204 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || 2318 tg3_pwrsrc_switch_to_vaux(tp);
2205 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { 2319 else
2206 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | 2320 tg3_pwrsrc_die_with_vmain(tp);
2207 (GRC_LCLCTRL_GPIO_OE0 |
2208 GRC_LCLCTRL_GPIO_OE1 |
2209 GRC_LCLCTRL_GPIO_OE2 |
2210 GRC_LCLCTRL_GPIO_OUTPUT0 |
2211 GRC_LCLCTRL_GPIO_OUTPUT1),
2212 100);
2213 } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 ||
2214 tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) {
2215 /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */
2216 u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 |
2217 GRC_LCLCTRL_GPIO_OE1 |
2218 GRC_LCLCTRL_GPIO_OE2 |
2219 GRC_LCLCTRL_GPIO_OUTPUT0 |
2220 GRC_LCLCTRL_GPIO_OUTPUT1 |
2221 tp->grc_local_ctrl;
2222 tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100);
2223
2224 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2;
2225 tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100);
2226
2227 grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0;
2228 tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100);
2229 } else {
2230 u32 no_gpio2;
2231 u32 grc_local_ctrl = 0;
2232
2233 /* Workaround to prevent overdrawing Amps. */
2234 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
2235 ASIC_REV_5714) {
2236 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
2237 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2238 grc_local_ctrl, 100);
2239 }
2240
2241 /* On 5753 and variants, GPIO2 cannot be used. */
2242 no_gpio2 = tp->nic_sram_data_cfg &
2243 NIC_SRAM_DATA_CFG_NO_GPIO2;
2244
2245 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 |
2246 GRC_LCLCTRL_GPIO_OE1 |
2247 GRC_LCLCTRL_GPIO_OE2 |
2248 GRC_LCLCTRL_GPIO_OUTPUT1 |
2249 GRC_LCLCTRL_GPIO_OUTPUT2;
2250 if (no_gpio2) {
2251 grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 |
2252 GRC_LCLCTRL_GPIO_OUTPUT2);
2253 }
2254 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2255 grc_local_ctrl, 100);
2256
2257 grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0;
2258
2259 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2260 grc_local_ctrl, 100);
2261
2262 if (!no_gpio2) {
2263 grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2;
2264 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2265 grc_local_ctrl, 100);
2266 }
2267 }
2268 } else {
2269 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 &&
2270 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) {
2271 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2272 (GRC_LCLCTRL_GPIO_OE1 |
2273 GRC_LCLCTRL_GPIO_OUTPUT1), 100);
2274
2275 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2276 GRC_LCLCTRL_GPIO_OE1, 100);
2277
2278 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl |
2279 (GRC_LCLCTRL_GPIO_OE1 |
2280 GRC_LCLCTRL_GPIO_OUTPUT1), 100);
2281 }
2282 }
2283} 2321}
2284 2322
2285static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) 2323static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed)
@@ -2624,8 +2662,7 @@ static int tg3_power_up(struct tg3 *tp)
2624 pci_set_power_state(tp->pdev, PCI_D0); 2662 pci_set_power_state(tp->pdev, PCI_D0);
2625 2663
2626 /* Switch out of Vaux if it is a NIC */ 2664 /* Switch out of Vaux if it is a NIC */
2627 if (tg3_flag(tp, IS_NIC)) 2665 tg3_pwrsrc_switch_to_vmain(tp);
2628 tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100);
2629 2666
2630 return 0; 2667 return 0;
2631} 2668}