4 * Author : Hamid Ikdoumi (Atmel)
6 * See file CREDITS for list of people who contributed to this
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.
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.
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,
26 * Adapted for KwikByte KB920x board: 22APR2005
30 #include <at91rm9200_net.h>
34 #ifdef CONFIG_DRIVER_ETHER
36 #if (CONFIG_COMMANDS & CFG_CMD_NET)
40 * lxt972_IsPhyConnected
42 * Reads the 2 PHY ID registers
44 * p_mac - pointer to AT91S_EMAC struct
46 * TRUE - if id read successfully
49 unsigned int lxt972_IsPhyConnected (AT91PS_EMAC p_mac)
51 unsigned short Id1, Id2;
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);
58 if ((Id1 == (0x0013)) && ((Id2 & 0xFFF0) == 0x78E0))
68 * Link parallel detection status of MAC is checked and set in the
69 * MAC configuration registers
71 * p_mac - pointer to MAC
73 * TRUE - if link status set succesfully
74 * FALSE - if link status not set
76 UCHAR lxt972_GetLinkSpeed (AT91PS_EMAC p_mac)
80 if (!at91rm9200_EmacReadPhy (p_mac, PHY_LXT971_STAT2, &stat1))
83 if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link status up? */
86 if (stat1 & PHY_LXT971_STAT2_100BTX) {
88 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
90 /*set Emac for 100BaseTX and Full Duplex */
91 p_mac->EMAC_CFG |= AT91C_EMAC_SPD | AT91C_EMAC_FD;
94 /*set Emac for 100BaseTX and Half Duplex */
95 p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
96 ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
104 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
106 /*set MII for 10BaseT and Full Duplex */
107 p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
108 ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
112 /*set MII for 10BaseT and Half Duplex */
113 p_mac->EMAC_CFG &= ~(AT91C_EMAC_SPD | AT91C_EMAC_FD);
127 * MAC starts checking its link by using parallel detection and
128 * Autonegotiation and the same is set in the MAC configuration registers
130 * p_mac - pointer to struct AT91S_EMAC
132 * TRUE - if link status set succesfully
133 * FALSE - if link status not set
135 UCHAR lxt972_InitPhy (AT91PS_EMAC p_mac)
139 at91rm9200_EmacEnableMDIO (p_mac);
141 if (!lxt972_GetLinkSpeed (p_mac)) {
142 /* Try another time */
143 ret = lxt972_GetLinkSpeed (p_mac);
146 /* Disable PHY Interrupts */
147 at91rm9200_EmacWritePhy (p_mac, PHY_LXT971_INT_ENABLE, 0);
149 at91rm9200_EmacDisableMDIO (p_mac);
157 * lxt972_AutoNegotiate
159 * MAC Autonegotiates with the partner status of same is set in the
160 * MAC configuration registers
162 * dev - pointer to struct net_device
164 * TRUE - if link status set successfully
165 * FALSE - if link status not set
167 UCHAR lxt972_AutoNegotiate (AT91PS_EMAC p_mac, int *status)
169 unsigned short value;
171 /* Set lxt972 control register */
172 if (!at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_CTRL, &value))
175 /* Restart Auto_negotiation */
176 value |= PHY_COMMON_CTRL_RES_AUTO;
177 if (!at91rm9200_EmacWritePhy (p_mac, PHY_COMMON_CTRL, &value))
180 /*check AutoNegotiate complete */
182 at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_STAT, &value);
183 if (!(value & PHY_COMMON_STAT_AN_COMP))
186 return (lxt972_GetLinkSpeed (p_mac));
189 #endif /* CONFIG_COMMANDS & CFG_CMD_NET */
191 #endif /* CONFIG_DRIVER_ETHER */