2 * Realtek 8019AS Ethernet
3 * (C) Copyright 2002-2003
4 * Xue Ligong(lgxue@hotmail.com),Wang Kehao, ESLAB, whut.edu.cn
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 * This code works in 8bit mode.
27 * If you need to work in 16bit mode, PLS change it!
35 #ifdef CONFIG_DRIVER_RTL8019
37 #if (CONFIG_COMMANDS & CFG_CMD_NET)
40 /* packet page register access functions */
43 static unsigned char get_reg (unsigned int regno)
45 return (*(unsigned char *) regno);
49 static void put_reg (unsigned int regno, unsigned char val)
51 *(volatile unsigned char *) regno = val;
54 static void eth_reset (void)
59 ucTemp = get_reg (RTL8019_RESET);
60 put_reg (RTL8019_RESET, ucTemp);
61 put_reg (RTL8019_INTERRUPTSTATUS, 0xff);
62 udelay (2000); /* wait for 2ms */
65 void rtl8019_get_enetaddr (uchar * addr)
72 put_reg (RTL8019_COMMAND, RTL8019_REMOTEDMARD);
73 put_reg (RTL8019_DATACONFIGURATION, 0x48);
74 put_reg (RTL8019_REMOTESTARTADDRESS0, 0x00);
75 put_reg (RTL8019_REMOTESTARTADDRESS1, 0x00);
76 put_reg (RTL8019_REMOTEBYTECOUNT0, 12);
77 put_reg (RTL8019_REMOTEBYTECOUNT1, 0x00);
78 put_reg (RTL8019_COMMAND, RTL8019_REMOTEDMARD);
80 for (i = 0; i < 6; i++) {
81 temp = get_reg (RTL8019_DMA_DATA);
83 temp = get_reg (RTL8019_DMA_DATA);
87 while ((!get_reg (RTL8019_INTERRUPTSTATUS) & 0x40));
89 put_reg (RTL8019_REMOTEBYTECOUNT0, 0x00);
90 put_reg (RTL8019_REMOTEBYTECOUNT1, 0x00);
91 put_reg (RTL8019_COMMAND, RTL8019_PAGE0);
97 put_reg (RTL8019_COMMAND, 0x01);
100 int eth_init (bd_t * bd)
103 put_reg (RTL8019_COMMAND, RTL8019_PAGE0STOP);
104 put_reg (RTL8019_DATACONFIGURATION, 0x48);
105 put_reg (RTL8019_REMOTEBYTECOUNT0, 0x00);
106 put_reg (RTL8019_REMOTEBYTECOUNT1, 0x00);
107 put_reg (RTL8019_RECEIVECONFIGURATION, 0x00); /*00; */
108 put_reg (RTL8019_TRANSMITPAGE, RTL8019_TPSTART);
109 put_reg (RTL8019_TRANSMITCONFIGURATION, 0x02);
110 put_reg (RTL8019_PAGESTART, RTL8019_PSTART);
111 put_reg (RTL8019_BOUNDARY, RTL8019_PSTART);
112 put_reg (RTL8019_PAGESTOP, RTL8019_PSTOP);
113 put_reg (RTL8019_INTERRUPTSTATUS, 0xff);
114 put_reg (RTL8019_INTERRUPTMASK, 0x11); /*b; */
115 put_reg (RTL8019_COMMAND, RTL8019_PAGE1STOP);
116 put_reg (RTL8019_PHYSICALADDRESS0, bd->bi_enetaddr[0]);
117 put_reg (RTL8019_PHYSICALADDRESS1, bd->bi_enetaddr[1]);
118 put_reg (RTL8019_PHYSICALADDRESS2, bd->bi_enetaddr[2]);
119 put_reg (RTL8019_PHYSICALADDRESS3, bd->bi_enetaddr[3]);
120 put_reg (RTL8019_PHYSICALADDRESS4, bd->bi_enetaddr[4]);
121 put_reg (RTL8019_PHYSICALADDRESS5, bd->bi_enetaddr[5]);
122 put_reg (RTL8019_MULTIADDRESS0, 0x00);
123 put_reg (RTL8019_MULTIADDRESS1, 0x00);
124 put_reg (RTL8019_MULTIADDRESS2, 0x00);
125 put_reg (RTL8019_MULTIADDRESS3, 0x00);
126 put_reg (RTL8019_MULTIADDRESS4, 0x00);
127 put_reg (RTL8019_MULTIADDRESS5, 0x00);
128 put_reg (RTL8019_MULTIADDRESS6, 0x00);
129 put_reg (RTL8019_MULTIADDRESS7, 0x00);
130 put_reg (RTL8019_CURRENT, RTL8019_PSTART);
131 put_reg (RTL8019_COMMAND, RTL8019_PAGE0);
132 put_reg (RTL8019_TRANSMITCONFIGURATION, 0xe0); /*58; */
138 static unsigned char nic_to_pc (void)
140 unsigned char rec_head_status;
141 unsigned char next_packet_pointer;
142 unsigned char packet_length0;
143 unsigned char packet_length1;
144 unsigned short rxlen = 0;
146 unsigned char current_point;
150 * The RTL8019's first 4B is packet status,page of next packet
151 * and packet length(2B).So we receive the fist 4B.
153 put_reg (RTL8019_REMOTESTARTADDRESS1, get_reg (RTL8019_BOUNDARY));
154 put_reg (RTL8019_REMOTESTARTADDRESS0, 0x00);
155 put_reg (RTL8019_REMOTEBYTECOUNT1, 0x00);
156 put_reg (RTL8019_REMOTEBYTECOUNT0, 0x04);
158 put_reg (RTL8019_COMMAND, RTL8019_REMOTEDMARD);
160 rec_head_status = get_reg (RTL8019_DMA_DATA);
161 next_packet_pointer = get_reg (RTL8019_DMA_DATA);
162 packet_length0 = get_reg (RTL8019_DMA_DATA);
163 packet_length1 = get_reg (RTL8019_DMA_DATA);
165 put_reg (RTL8019_COMMAND, RTL8019_PAGE0);
166 /*Packet length is in two 8bit registers */
167 rxlen = packet_length1;
168 rxlen = (((rxlen << 8) & 0xff00) + packet_length0);
171 if (rxlen > PKTSIZE_ALIGN + PKTALIGN)
172 printf ("packet too big!\n");
174 /*Receive the packet */
175 put_reg (RTL8019_REMOTESTARTADDRESS0, 0x04);
176 put_reg (RTL8019_REMOTESTARTADDRESS1, get_reg (RTL8019_BOUNDARY));
178 put_reg (RTL8019_REMOTEBYTECOUNT0, (rxlen & 0xff));
179 put_reg (RTL8019_REMOTEBYTECOUNT1, ((rxlen >> 8) & 0xff));
182 put_reg (RTL8019_COMMAND, RTL8019_REMOTEDMARD);
184 for (addr = (unsigned char *) NetRxPackets[0], i = rxlen; i > 0; i--)
185 *addr++ = get_reg (RTL8019_DMA_DATA);
186 /* Pass the packet up to the protocol layers. */
187 NetReceive (NetRxPackets[0], rxlen);
189 while (!(get_reg (RTL8019_INTERRUPTSTATUS)) & 0x40); /* wait for the op. */
192 * To test whether the packets are all received,get the
193 * location of current point
195 put_reg (RTL8019_COMMAND, RTL8019_PAGE1);
196 current_point = get_reg (RTL8019_CURRENT);
197 put_reg (RTL8019_COMMAND, RTL8019_PAGE0);
198 put_reg (RTL8019_BOUNDARY, next_packet_pointer);
199 return current_point;
202 /* Get a data block via Ethernet */
203 extern int eth_rx (void)
205 unsigned char temp, current_point;
207 put_reg (RTL8019_COMMAND, RTL8019_PAGE0);
210 temp = get_reg (RTL8019_INTERRUPTSTATUS);
214 put_reg (RTL8019_COMMAND, RTL8019_PAGE0STOP);
216 put_reg (RTL8019_REMOTEBYTECOUNT0, 0);
217 put_reg (RTL8019_REMOTEBYTECOUNT1, 0);
218 put_reg (RTL8019_TRANSMITCONFIGURATION, 2);
220 current_point = nic_to_pc ();
221 } while (get_reg (RTL8019_BOUNDARY) != current_point);
223 put_reg (RTL8019_TRANSMITCONFIGURATION, 0xe0);
229 put_reg (RTL8019_INTERRUPTSTATUS, 0x01);
230 current_point = nic_to_pc ();
231 } while (get_reg (RTL8019_BOUNDARY) != current_point);
240 /* Send a data block via Ethernet. */
241 extern int eth_send (volatile void *packet, int length)
243 volatile unsigned char *p;
247 p = (volatile unsigned char *) packet;
249 while (get_reg (RTL8019_COMMAND) == RTL8019_TRANSMIT);
251 put_reg (RTL8019_REMOTESTARTADDRESS0, 0);
252 put_reg (RTL8019_REMOTESTARTADDRESS1, RTL8019_TPSTART);
253 put_reg (RTL8019_REMOTEBYTECOUNT0, (pn & 0xff));
254 put_reg (RTL8019_REMOTEBYTECOUNT1, ((pn >> 8) & 0xff));
256 put_reg (RTL8019_COMMAND, RTL8019_REMOTEDMAWR);
258 put_reg (RTL8019_DMA_DATA, *p++);
264 while (pn < 60) { /*Padding */
265 put_reg (RTL8019_DMA_DATA, 0);
269 while (!(get_reg (RTL8019_INTERRUPTSTATUS)) & 0x40);
271 put_reg (RTL8019_INTERRUPTSTATUS, 0x40);
272 put_reg (RTL8019_TRANSMITPAGE, RTL8019_TPSTART);
273 put_reg (RTL8019_TRANSMITBYTECOUNT0, (pn & 0xff));
274 put_reg (RTL8019_TRANSMITBYTECOUNT1, ((pn >> 8 & 0xff)));
275 put_reg (RTL8019_COMMAND, RTL8019_TRANSMIT);
280 #endif /* COMMANDS & CFG_NET */
282 #endif /* CONFIG_DRIVER_RTL8019 */