blob: 2baddbdd3e25ed5316134986eacf00f7b7e56d18 [file] [log] [blame]
Wolfgang Denk9da240c2005-10-05 00:19:34 +02001/*
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/*
26 * Adatped for KwikByte KB920x board: 22APR2005
27 */
28
29#include <at91rm9200_net.h>
30#include <net.h>
31#include <lxt971a.h>
32
33#ifdef CONFIG_DRIVER_ETHER
34
35#if (CONFIG_COMMANDS & CFG_CMD_NET)
36
37/*
38 * Name:
39 * lxt972_IsPhyConnected
40 * Description:
41 * Reads the 2 PHY ID registers
42 * Arguments:
43 * p_mac - pointer to AT91S_EMAC struct
44 * Return value:
45 * TRUE - if id read successfully
46 * FALSE- if error
47 */
48static unsigned int lxt972_IsPhyConnected (AT91PS_EMAC p_mac)
49{
50 unsigned short Id1, Id2;
51
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);
56
57 if ((Id1 == (0x0013)) && ((Id2 & 0xFFF0) == 0x78E0))
58 return TRUE;
59
60 return FALSE;
61}
62
63/*
64 * Name:
65 * lxt972_GetLinkSpeed
66 * Description:
67 * Link parallel detection status of MAC is checked and set in the
68 * MAC configuration registers
69 * Arguments:
70 * p_mac - pointer to MAC
71 * Return value:
72 * TRUE - if link status set succesfully
73 * FALSE - if link status not set
74 */
75static UCHAR lxt972_GetLinkSpeed (AT91PS_EMAC p_mac)
76{
77 unsigned short stat1;
78
79 if (!at91rm9200_EmacReadPhy (p_mac, PHY_LXT971_STAT2, &stat1))
80 return FALSE;
81
82 if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link status up? */
83 return FALSE;
84
85 if (stat1 & PHY_LXT971_STAT2_100BTX) {
86
87 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
88
89 /*set Emac for 100BaseTX and Full Duplex */
90 p_mac->EMAC_CFG |= AT91C_EMAC_SPD | AT91C_EMAC_FD;
91 } else {
92
93 /*set Emac for 100BaseTX and Half Duplex */
94 p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
95 ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
96 | AT91C_EMAC_SPD;
97 }
98
99 return TRUE;
100
101 } else {
102
103 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
104
105 /*set MII for 10BaseT and Full Duplex */
106 p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
107 ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
108 | AT91C_EMAC_FD;
109 } else {
110
111 /*set MII for 10BaseT and Half Duplex */
112 p_mac->EMAC_CFG &= ~(AT91C_EMAC_SPD | AT91C_EMAC_FD);
113 }
114
115 return TRUE;
116 }
117
118 return FALSE;
119}
120
121
122/*
123 * Name:
124 * lxt972_InitPhy
125 * Description:
126 * MAC starts checking its link by using parallel detection and
127 * Autonegotiation and the same is set in the MAC configuration registers
128 * Arguments:
129 * p_mac - pointer to struct AT91S_EMAC
130 * Return value:
131 * TRUE - if link status set succesfully
132 * FALSE - if link status not set
133 */
134static UCHAR lxt972_InitPhy (AT91PS_EMAC p_mac)
135{
136 UCHAR ret = TRUE;
137
138 at91rm9200_EmacEnableMDIO (p_mac);
139
140 if (!lxt972_GetLinkSpeed (p_mac)) {
141 /* Try another time */
142 ret = lxt972_GetLinkSpeed (p_mac);
143 }
144
145 /* Disable PHY Interrupts */
146 at91rm9200_EmacWritePhy (p_mac, PHY_LXT971_INT_ENABLE, 0);
147
148 at91rm9200_EmacDisableMDIO (p_mac);
149
150 return (ret);
151}
152
153
154/*
155 * Name:
156 * lxt972_AutoNegotiate
157 * Description:
158 * MAC Autonegotiates with the partner status of same is set in the
159 * MAC configuration registers
160 * Arguments:
161 * dev - pointer to struct net_device
162 * Return value:
163 * TRUE - if link status set successfully
164 * FALSE - if link status not set
165 */
166static UCHAR lxt972_AutoNegotiate (AT91PS_EMAC p_mac, int *status)
167{
168 unsigned short value;
169
170 /* Set lxt972 control register */
171 if (!at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_CTRL, &value))
172 return FALSE;
173
174 /* Restart Auto_negotiation */
175 value |= PHY_COMMON_CTRL_RES_AUTO;
176 if (!at91rm9200_EmacWritePhy (p_mac, PHY_COMMON_CTRL, &value))
177 return FALSE;
178
179 /*check AutoNegotiate complete */
180 udelay (10000);
181 at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_STAT, &value);
182 if (!(value & PHY_COMMON_STAT_AN_COMP))
183 return FALSE;
184
185 return (lxt972_GetLinkSpeed (p_mac));
186}
187
188
189/*
190 * Name:
191 * at91rm92000_GetPhyInterface
192 * Description:
193 * Initialise the interface functions to the PHY
194 * Arguments:
195 * None
196 * Return value:
197 * None
198 */
199void at91rm92000_GetPhyInterface(AT91PS_PhyOps p_phyops)
200{
201 p_phyops->Init = lxt972_InitPhy;
202 p_phyops->IsPhyConnected = lxt972_IsPhyConnected;
203 p_phyops->GetLinkSpeed = lxt972_GetLinkSpeed;
204 p_phyops->AutoNegotiate = lxt972_AutoNegotiate;
205}
206
207#endif /* CONFIG_COMMANDS & CFG_CMD_NET */
208
209#endif /* CONFIG_DRIVER_ETHER */