Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * (C) Copyright 2003 |
| 4 | * Author : Hamid Ikdoumi (Atmel) |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | /* |
Wolfgang Denk | 080bdb7 | 2005-10-05 01:51:29 +0200 | [diff] [blame] | 26 | * Adapted for KwikByte KB920x board: 22APR2005 |
Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 27 | */ |
| 28 | |
Wolfgang Denk | 080bdb7 | 2005-10-05 01:51:29 +0200 | [diff] [blame] | 29 | #include <common.h> |
Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 30 | #include <at91rm9200_net.h> |
| 31 | #include <net.h> |
| 32 | #include <lxt971a.h> |
| 33 | |
| 34 | #ifdef CONFIG_DRIVER_ETHER |
| 35 | |
Jon Loeliger | 7371841 | 2007-06-11 19:03:15 -0500 | [diff] [blame] | 36 | #if (CONFIG_COMMANDS & CFG_CMD_NET) || defined(CONFIG_CMD_NET) |
Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Name: |
| 40 | * lxt972_IsPhyConnected |
| 41 | * Description: |
| 42 | * Reads the 2 PHY ID registers |
| 43 | * Arguments: |
| 44 | * p_mac - pointer to AT91S_EMAC struct |
| 45 | * Return value: |
| 46 | * TRUE - if id read successfully |
| 47 | * FALSE- if error |
| 48 | */ |
Wolfgang Denk | 080bdb7 | 2005-10-05 01:51:29 +0200 | [diff] [blame] | 49 | unsigned int lxt972_IsPhyConnected (AT91PS_EMAC p_mac) |
Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 50 | { |
| 51 | unsigned short Id1, Id2; |
| 52 | |
| 53 | at91rm9200_EmacEnableMDIO (p_mac); |
| 54 | at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_ID1, &Id1); |
| 55 | at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_ID2, &Id2); |
| 56 | at91rm9200_EmacDisableMDIO (p_mac); |
| 57 | |
| 58 | if ((Id1 == (0x0013)) && ((Id2 & 0xFFF0) == 0x78E0)) |
| 59 | return TRUE; |
| 60 | |
| 61 | return FALSE; |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Name: |
| 66 | * lxt972_GetLinkSpeed |
| 67 | * Description: |
| 68 | * Link parallel detection status of MAC is checked and set in the |
| 69 | * MAC configuration registers |
| 70 | * Arguments: |
| 71 | * p_mac - pointer to MAC |
| 72 | * Return value: |
| 73 | * TRUE - if link status set succesfully |
| 74 | * FALSE - if link status not set |
| 75 | */ |
Wolfgang Denk | 080bdb7 | 2005-10-05 01:51:29 +0200 | [diff] [blame] | 76 | UCHAR lxt972_GetLinkSpeed (AT91PS_EMAC p_mac) |
Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 77 | { |
| 78 | unsigned short stat1; |
| 79 | |
| 80 | if (!at91rm9200_EmacReadPhy (p_mac, PHY_LXT971_STAT2, &stat1)) |
| 81 | return FALSE; |
| 82 | |
| 83 | if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link status up? */ |
| 84 | return FALSE; |
| 85 | |
| 86 | if (stat1 & PHY_LXT971_STAT2_100BTX) { |
| 87 | |
| 88 | if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) { |
| 89 | |
| 90 | /*set Emac for 100BaseTX and Full Duplex */ |
| 91 | p_mac->EMAC_CFG |= AT91C_EMAC_SPD | AT91C_EMAC_FD; |
| 92 | } else { |
| 93 | |
| 94 | /*set Emac for 100BaseTX and Half Duplex */ |
| 95 | p_mac->EMAC_CFG = (p_mac->EMAC_CFG & |
| 96 | ~(AT91C_EMAC_SPD | AT91C_EMAC_FD)) |
| 97 | | AT91C_EMAC_SPD; |
| 98 | } |
| 99 | |
| 100 | return TRUE; |
| 101 | |
| 102 | } else { |
| 103 | |
| 104 | if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) { |
| 105 | |
| 106 | /*set MII for 10BaseT and Full Duplex */ |
| 107 | p_mac->EMAC_CFG = (p_mac->EMAC_CFG & |
| 108 | ~(AT91C_EMAC_SPD | AT91C_EMAC_FD)) |
| 109 | | AT91C_EMAC_FD; |
| 110 | } else { |
| 111 | |
| 112 | /*set MII for 10BaseT and Half Duplex */ |
| 113 | p_mac->EMAC_CFG &= ~(AT91C_EMAC_SPD | AT91C_EMAC_FD); |
| 114 | } |
| 115 | |
| 116 | return TRUE; |
| 117 | } |
| 118 | |
| 119 | return FALSE; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /* |
| 124 | * Name: |
| 125 | * lxt972_InitPhy |
| 126 | * Description: |
| 127 | * MAC starts checking its link by using parallel detection and |
| 128 | * Autonegotiation and the same is set in the MAC configuration registers |
| 129 | * Arguments: |
| 130 | * p_mac - pointer to struct AT91S_EMAC |
| 131 | * Return value: |
| 132 | * TRUE - if link status set succesfully |
| 133 | * FALSE - if link status not set |
| 134 | */ |
Wolfgang Denk | 080bdb7 | 2005-10-05 01:51:29 +0200 | [diff] [blame] | 135 | UCHAR lxt972_InitPhy (AT91PS_EMAC p_mac) |
Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 136 | { |
| 137 | UCHAR ret = TRUE; |
| 138 | |
| 139 | at91rm9200_EmacEnableMDIO (p_mac); |
| 140 | |
| 141 | if (!lxt972_GetLinkSpeed (p_mac)) { |
| 142 | /* Try another time */ |
| 143 | ret = lxt972_GetLinkSpeed (p_mac); |
| 144 | } |
| 145 | |
| 146 | /* Disable PHY Interrupts */ |
| 147 | at91rm9200_EmacWritePhy (p_mac, PHY_LXT971_INT_ENABLE, 0); |
| 148 | |
| 149 | at91rm9200_EmacDisableMDIO (p_mac); |
| 150 | |
| 151 | return (ret); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | /* |
| 156 | * Name: |
| 157 | * lxt972_AutoNegotiate |
| 158 | * Description: |
| 159 | * MAC Autonegotiates with the partner status of same is set in the |
| 160 | * MAC configuration registers |
| 161 | * Arguments: |
| 162 | * dev - pointer to struct net_device |
| 163 | * Return value: |
| 164 | * TRUE - if link status set successfully |
| 165 | * FALSE - if link status not set |
| 166 | */ |
Wolfgang Denk | 080bdb7 | 2005-10-05 01:51:29 +0200 | [diff] [blame] | 167 | UCHAR lxt972_AutoNegotiate (AT91PS_EMAC p_mac, int *status) |
Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 168 | { |
| 169 | unsigned short value; |
| 170 | |
| 171 | /* Set lxt972 control register */ |
| 172 | if (!at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_CTRL, &value)) |
| 173 | return FALSE; |
| 174 | |
| 175 | /* Restart Auto_negotiation */ |
| 176 | value |= PHY_COMMON_CTRL_RES_AUTO; |
| 177 | if (!at91rm9200_EmacWritePhy (p_mac, PHY_COMMON_CTRL, &value)) |
| 178 | return FALSE; |
| 179 | |
| 180 | /*check AutoNegotiate complete */ |
| 181 | udelay (10000); |
| 182 | at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_STAT, &value); |
| 183 | if (!(value & PHY_COMMON_STAT_AN_COMP)) |
| 184 | return FALSE; |
| 185 | |
| 186 | return (lxt972_GetLinkSpeed (p_mac)); |
| 187 | } |
| 188 | |
Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 189 | #endif /* CONFIG_COMMANDS & CFG_CMD_NET */ |
| 190 | |
| 191 | #endif /* CONFIG_DRIVER_ETHER */ |