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>
35 #ifdef CONFIG_DRIVER_ETHER
37 #if defined(CONFIG_CMD_NET)
41 * lxt972_IsPhyConnected
43 * Reads the 2 PHY ID registers
45 * p_mac - pointer to AT91S_EMAC struct
47 * TRUE - if id read successfully
50 unsigned int lxt972_IsPhyConnected (AT91PS_EMAC p_mac)
52 unsigned short Id1, Id2;
54 at91rm9200_EmacEnableMDIO (p_mac);
55 at91rm9200_EmacReadPhy(p_mac, PHY_PHYIDR1, &Id1);
56 at91rm9200_EmacReadPhy(p_mac, PHY_PHYIDR2, &Id2);
57 at91rm9200_EmacDisableMDIO (p_mac);
59 if ((Id1 == (0x0013)) && ((Id2 & 0xFFF0) == 0x78E0))
69 * Link parallel detection status of MAC is checked and set in the
70 * MAC configuration registers
72 * p_mac - pointer to MAC
74 * TRUE - if link status set succesfully
75 * FALSE - if link status not set
77 UCHAR lxt972_GetLinkSpeed (AT91PS_EMAC p_mac)
81 if (!at91rm9200_EmacReadPhy (p_mac, PHY_LXT971_STAT2, &stat1))
84 if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link status up? */
87 if (stat1 & PHY_LXT971_STAT2_100BTX) {
89 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
91 /*set Emac for 100BaseTX and Full Duplex */
92 p_mac->EMAC_CFG |= AT91C_EMAC_SPD | AT91C_EMAC_FD;
95 /*set Emac for 100BaseTX and Half Duplex */
96 p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
97 ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
105 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
107 /*set MII for 10BaseT and Full Duplex */
108 p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
109 ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
113 /*set MII for 10BaseT and Half Duplex */
114 p_mac->EMAC_CFG &= ~(AT91C_EMAC_SPD | AT91C_EMAC_FD);
128 * MAC starts checking its link by using parallel detection and
129 * Autonegotiation and the same is set in the MAC configuration registers
131 * p_mac - pointer to struct AT91S_EMAC
133 * TRUE - if link status set succesfully
134 * FALSE - if link status not set
136 UCHAR lxt972_InitPhy (AT91PS_EMAC p_mac)
140 at91rm9200_EmacEnableMDIO (p_mac);
142 if (!lxt972_GetLinkSpeed (p_mac)) {
143 /* Try another time */
144 ret = lxt972_GetLinkSpeed (p_mac);
147 /* Disable PHY Interrupts */
148 at91rm9200_EmacWritePhy (p_mac, PHY_LXT971_INT_ENABLE, 0);
150 at91rm9200_EmacDisableMDIO (p_mac);
158 * lxt972_AutoNegotiate
160 * MAC Autonegotiates with the partner status of same is set in the
161 * MAC configuration registers
163 * dev - pointer to struct net_device
165 * TRUE - if link status set successfully
166 * FALSE - if link status not set
168 UCHAR lxt972_AutoNegotiate (AT91PS_EMAC p_mac, int *status)
170 unsigned short value;
172 /* Set lxt972 control register */
173 if (!at91rm9200_EmacReadPhy (p_mac, PHY_BMCR, &value))
176 /* Restart Auto_negotiation */
177 value |= PHY_BMCR_RST_NEG;
178 if (!at91rm9200_EmacWritePhy (p_mac, PHY_BMCR, &value))
181 /*check AutoNegotiate complete */
183 at91rm9200_EmacReadPhy(p_mac, PHY_BMSR, &value);
184 if (!(value & PHY_BMSR_AUTN_COMP))
187 return (lxt972_GetLinkSpeed (p_mac));
192 #endif /* CONFIG_DRIVER_ETHER */