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 * Adatped for KwikByte KB920x board: 22APR2005
29 #include <at91rm9200_net.h>
33 #ifdef CONFIG_DRIVER_ETHER
35 #if (CONFIG_COMMANDS & CFG_CMD_NET)
39 * lxt972_IsPhyConnected
41 * Reads the 2 PHY ID registers
43 * p_mac - pointer to AT91S_EMAC struct
45 * TRUE - if id read successfully
48 static unsigned int lxt972_IsPhyConnected (AT91PS_EMAC p_mac)
50 unsigned short Id1, Id2;
52 at91rm9200_EmacEnableMDIO (p_mac);
53 at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_ID1, &Id1);
54 at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_ID2, &Id2);
55 at91rm9200_EmacDisableMDIO (p_mac);
57 if ((Id1 == (0x0013)) && ((Id2 & 0xFFF0) == 0x78E0))
67 * Link parallel detection status of MAC is checked and set in the
68 * MAC configuration registers
70 * p_mac - pointer to MAC
72 * TRUE - if link status set succesfully
73 * FALSE - if link status not set
75 static UCHAR lxt972_GetLinkSpeed (AT91PS_EMAC p_mac)
79 if (!at91rm9200_EmacReadPhy (p_mac, PHY_LXT971_STAT2, &stat1))
82 if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link status up? */
85 if (stat1 & PHY_LXT971_STAT2_100BTX) {
87 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
89 /*set Emac for 100BaseTX and Full Duplex */
90 p_mac->EMAC_CFG |= AT91C_EMAC_SPD | AT91C_EMAC_FD;
93 /*set Emac for 100BaseTX and Half Duplex */
94 p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
95 ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
103 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
105 /*set MII for 10BaseT and Full Duplex */
106 p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
107 ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
111 /*set MII for 10BaseT and Half Duplex */
112 p_mac->EMAC_CFG &= ~(AT91C_EMAC_SPD | AT91C_EMAC_FD);
126 * MAC starts checking its link by using parallel detection and
127 * Autonegotiation and the same is set in the MAC configuration registers
129 * p_mac - pointer to struct AT91S_EMAC
131 * TRUE - if link status set succesfully
132 * FALSE - if link status not set
134 static UCHAR lxt972_InitPhy (AT91PS_EMAC p_mac)
138 at91rm9200_EmacEnableMDIO (p_mac);
140 if (!lxt972_GetLinkSpeed (p_mac)) {
141 /* Try another time */
142 ret = lxt972_GetLinkSpeed (p_mac);
145 /* Disable PHY Interrupts */
146 at91rm9200_EmacWritePhy (p_mac, PHY_LXT971_INT_ENABLE, 0);
148 at91rm9200_EmacDisableMDIO (p_mac);
156 * lxt972_AutoNegotiate
158 * MAC Autonegotiates with the partner status of same is set in the
159 * MAC configuration registers
161 * dev - pointer to struct net_device
163 * TRUE - if link status set successfully
164 * FALSE - if link status not set
166 static UCHAR lxt972_AutoNegotiate (AT91PS_EMAC p_mac, int *status)
168 unsigned short value;
170 /* Set lxt972 control register */
171 if (!at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_CTRL, &value))
174 /* Restart Auto_negotiation */
175 value |= PHY_COMMON_CTRL_RES_AUTO;
176 if (!at91rm9200_EmacWritePhy (p_mac, PHY_COMMON_CTRL, &value))
179 /*check AutoNegotiate complete */
181 at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_STAT, &value);
182 if (!(value & PHY_COMMON_STAT_AN_COMP))
185 return (lxt972_GetLinkSpeed (p_mac));
191 * at91rm92000_GetPhyInterface
193 * Initialise the interface functions to the PHY
199 void at91rm92000_GetPhyInterface(AT91PS_PhyOps p_phyops)
201 p_phyops->Init = lxt972_InitPhy;
202 p_phyops->IsPhyConnected = lxt972_IsPhyConnected;
203 p_phyops->GetLinkSpeed = lxt972_GetLinkSpeed;
204 p_phyops->AutoNegotiate = lxt972_AutoNegotiate;
207 #endif /* CONFIG_COMMANDS & CFG_CMD_NET */
209 #endif /* CONFIG_DRIVER_ETHER */