blob: d890d6045378371eb7fc4d5ecda2f7d4f49bf507 [file] [log] [blame]
Michal Simek14b4c702009-09-07 09:08:02 +02001/*
2 * (C) Copyright 2007-2009 Michal Simek
3 * (C) Copyright 2003 Xilinx Inc.
Michal Simek4514b372008-03-28 12:41:56 +01004 *
Michal Simek4514b372008-03-28 12:41:56 +01005 * Michal SIMEK <monstr@monstr.eu>
6 *
Michal Simek14b4c702009-09-07 09:08:02 +02007 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
Michal Simek4514b372008-03-28 12:41:56 +010019 *
Michal Simek14b4c702009-09-07 09:08:02 +020020 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
Michal Simek4514b372008-03-28 12:41:56 +010025
26#include <common.h>
27#include <net.h>
28#include <config.h>
Michal Simekb4a1d082010-10-11 11:41:47 +100029#include <malloc.h>
Michal Simek4514b372008-03-28 12:41:56 +010030#include <asm/io.h>
Michal Simekbb8b27b2012-06-28 21:37:57 +000031#include <fdtdec.h>
32
33DECLARE_GLOBAL_DATA_PTR;
Michal Simek4514b372008-03-28 12:41:56 +010034
35#undef DEBUG
36
Michal Simek4514b372008-03-28 12:41:56 +010037#define ENET_ADDR_LENGTH 6
38
39/* EmacLite constants */
40#define XEL_BUFFER_OFFSET 0x0800 /* Next buffer's offset */
41#define XEL_TPLR_OFFSET 0x07F4 /* Tx packet length */
42#define XEL_TSR_OFFSET 0x07FC /* Tx status */
43#define XEL_RSR_OFFSET 0x17FC /* Rx status */
44#define XEL_RXBUFF_OFFSET 0x1000 /* Receive Buffer */
45
46/* Xmit complete */
47#define XEL_TSR_XMIT_BUSY_MASK 0x00000001UL
48/* Xmit interrupt enable bit */
49#define XEL_TSR_XMIT_IE_MASK 0x00000008UL
50/* Buffer is active, SW bit only */
51#define XEL_TSR_XMIT_ACTIVE_MASK 0x80000000UL
52/* Program the MAC address */
53#define XEL_TSR_PROGRAM_MASK 0x00000002UL
54/* define for programming the MAC address into the EMAC Lite */
55#define XEL_TSR_PROG_MAC_ADDR (XEL_TSR_XMIT_BUSY_MASK | XEL_TSR_PROGRAM_MASK)
56
57/* Transmit packet length upper byte */
58#define XEL_TPLR_LENGTH_MASK_HI 0x0000FF00UL
59/* Transmit packet length lower byte */
60#define XEL_TPLR_LENGTH_MASK_LO 0x000000FFUL
61
62/* Recv complete */
63#define XEL_RSR_RECV_DONE_MASK 0x00000001UL
64/* Recv interrupt enable bit */
65#define XEL_RSR_RECV_IE_MASK 0x00000008UL
66
Michal Simekf35b7cd2011-08-25 12:47:56 +020067struct xemaclite {
Michal Simekb4a1d082010-10-11 11:41:47 +100068 u32 nexttxbuffertouse; /* Next TX buffer to write to */
69 u32 nextrxbuffertouse; /* Next RX buffer to read from */
Michal Simekdf40ead2011-09-12 21:10:01 +000070 u32 txpp; /* TX ping pong buffer */
71 u32 rxpp; /* RX ping pong buffer */
Michal Simekf35b7cd2011-08-25 12:47:56 +020072};
Michal Simek4514b372008-03-28 12:41:56 +010073
Clive Stubbings0d501912008-10-27 15:05:00 +000074static u32 etherrxbuff[PKTSIZE_ALIGN/4]; /* Receive buffer */
Michal Simek4514b372008-03-28 12:41:56 +010075
Michal Simek5d1cf6c2011-09-12 21:10:05 +000076static void xemaclite_alignedread(u32 *srcptr, void *destptr, u32 bytecount)
Michal Simek4514b372008-03-28 12:41:56 +010077{
Michal Simekb4a1d082010-10-11 11:41:47 +100078 u32 i;
Michal Simek4514b372008-03-28 12:41:56 +010079 u32 alignbuffer;
80 u32 *to32ptr;
81 u32 *from32ptr;
82 u8 *to8ptr;
83 u8 *from8ptr;
84
85 from32ptr = (u32 *) srcptr;
86
87 /* Word aligned buffer, no correction needed. */
88 to32ptr = (u32 *) destptr;
89 while (bytecount > 3) {
90 *to32ptr++ = *from32ptr++;
91 bytecount -= 4;
92 }
93 to8ptr = (u8 *) to32ptr;
94
95 alignbuffer = *from32ptr++;
Michal Simek5d1cf6c2011-09-12 21:10:05 +000096 from8ptr = (u8 *) &alignbuffer;
Michal Simek4514b372008-03-28 12:41:56 +010097
Michal Simek5d1cf6c2011-09-12 21:10:05 +000098 for (i = 0; i < bytecount; i++)
Michal Simek4514b372008-03-28 12:41:56 +010099 *to8ptr++ = *from8ptr++;
Michal Simek4514b372008-03-28 12:41:56 +0100100}
101
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000102static void xemaclite_alignedwrite(void *srcptr, u32 destptr, u32 bytecount)
Michal Simek4514b372008-03-28 12:41:56 +0100103{
Michal Simekb4a1d082010-10-11 11:41:47 +1000104 u32 i;
Michal Simek4514b372008-03-28 12:41:56 +0100105 u32 alignbuffer;
106 u32 *to32ptr = (u32 *) destptr;
107 u32 *from32ptr;
108 u8 *to8ptr;
109 u8 *from8ptr;
110
111 from32ptr = (u32 *) srcptr;
112 while (bytecount > 3) {
113
114 *to32ptr++ = *from32ptr++;
115 bytecount -= 4;
116 }
117
118 alignbuffer = 0;
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000119 to8ptr = (u8 *) &alignbuffer;
Michal Simek4514b372008-03-28 12:41:56 +0100120 from8ptr = (u8 *) from32ptr;
121
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000122 for (i = 0; i < bytecount; i++)
Michal Simek4514b372008-03-28 12:41:56 +0100123 *to8ptr++ = *from8ptr++;
Michal Simek4514b372008-03-28 12:41:56 +0100124
125 *to32ptr++ = alignbuffer;
126}
127
Michal Simekb4a1d082010-10-11 11:41:47 +1000128static void emaclite_halt(struct eth_device *dev)
Michal Simek4514b372008-03-28 12:41:56 +0100129{
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000130 debug("eth_halt\n");
Michal Simek4514b372008-03-28 12:41:56 +0100131}
132
Michal Simekb4a1d082010-10-11 11:41:47 +1000133static int emaclite_init(struct eth_device *dev, bd_t *bis)
Michal Simek4514b372008-03-28 12:41:56 +0100134{
Michal Simekdf40ead2011-09-12 21:10:01 +0000135 struct xemaclite *emaclite = dev->priv;
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000136 debug("EmacLite Initialization Started\n");
Michal Simek4514b372008-03-28 12:41:56 +0100137
138/*
139 * TX - TX_PING & TX_PONG initialization
140 */
141 /* Restart PING TX */
Michal Simekac357ac2011-08-25 12:36:39 +0200142 out_be32 (dev->iobase + XEL_TSR_OFFSET, 0);
Michal Simek4514b372008-03-28 12:41:56 +0100143 /* Copy MAC address */
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000144 xemaclite_alignedwrite(dev->enetaddr, dev->iobase, ENET_ADDR_LENGTH);
Michal Simek4514b372008-03-28 12:41:56 +0100145 /* Set the length */
Michal Simekac357ac2011-08-25 12:36:39 +0200146 out_be32 (dev->iobase + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH);
Michal Simek4514b372008-03-28 12:41:56 +0100147 /* Update the MAC address in the EMAC Lite */
Michal Simekac357ac2011-08-25 12:36:39 +0200148 out_be32 (dev->iobase + XEL_TSR_OFFSET, XEL_TSR_PROG_MAC_ADDR);
Michal Simek4514b372008-03-28 12:41:56 +0100149 /* Wait for EMAC Lite to finish with the MAC address update */
Michal Simekac357ac2011-08-25 12:36:39 +0200150 while ((in_be32 (dev->iobase + XEL_TSR_OFFSET) &
151 XEL_TSR_PROG_MAC_ADDR) != 0)
152 ;
Michal Simek4514b372008-03-28 12:41:56 +0100153
Michal Simekdf40ead2011-09-12 21:10:01 +0000154 if (emaclite->txpp) {
155 /* The same operation with PONG TX */
156 out_be32 (dev->iobase + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET, 0);
157 xemaclite_alignedwrite(dev->enetaddr, dev->iobase +
158 XEL_BUFFER_OFFSET, ENET_ADDR_LENGTH);
159 out_be32 (dev->iobase + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH);
160 out_be32 (dev->iobase + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET,
161 XEL_TSR_PROG_MAC_ADDR);
162 while ((in_be32 (dev->iobase + XEL_TSR_OFFSET +
163 XEL_BUFFER_OFFSET) & XEL_TSR_PROG_MAC_ADDR) != 0)
164 ;
165 }
Michal Simek4514b372008-03-28 12:41:56 +0100166
167/*
168 * RX - RX_PING & RX_PONG initialization
169 */
170 /* Write out the value to flush the RX buffer */
Michal Simekac357ac2011-08-25 12:36:39 +0200171 out_be32 (dev->iobase + XEL_RSR_OFFSET, XEL_RSR_RECV_IE_MASK);
Michal Simekdf40ead2011-09-12 21:10:01 +0000172
173 if (emaclite->rxpp)
174 out_be32 (dev->iobase + XEL_RSR_OFFSET + XEL_BUFFER_OFFSET,
175 XEL_RSR_RECV_IE_MASK);
Michal Simek4514b372008-03-28 12:41:56 +0100176
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000177 debug("EmacLite Initialization complete\n");
Michal Simek4514b372008-03-28 12:41:56 +0100178 return 0;
179}
180
Michal Simekf35b7cd2011-08-25 12:47:56 +0200181static int xemaclite_txbufferavailable(struct eth_device *dev)
Michal Simek4514b372008-03-28 12:41:56 +0100182{
183 u32 reg;
184 u32 txpingbusy;
185 u32 txpongbusy;
Michal Simekf35b7cd2011-08-25 12:47:56 +0200186 struct xemaclite *emaclite = dev->priv;
187
Michal Simek4514b372008-03-28 12:41:56 +0100188 /*
189 * Read the other buffer register
190 * and determine if the other buffer is available
191 */
Michal Simekf35b7cd2011-08-25 12:47:56 +0200192 reg = in_be32 (dev->iobase +
193 emaclite->nexttxbuffertouse + 0);
Michal Simek4514b372008-03-28 12:41:56 +0100194 txpingbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) ==
195 XEL_TSR_XMIT_BUSY_MASK);
196
Michal Simekf35b7cd2011-08-25 12:47:56 +0200197 reg = in_be32 (dev->iobase +
198 (emaclite->nexttxbuffertouse ^ XEL_TSR_OFFSET) + 0);
Michal Simek4514b372008-03-28 12:41:56 +0100199 txpongbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) ==
200 XEL_TSR_XMIT_BUSY_MASK);
201
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000202 return !(txpingbusy && txpongbusy);
Michal Simek4514b372008-03-28 12:41:56 +0100203}
204
Stephan Linz76aeeb92012-05-22 12:18:10 +0000205static int emaclite_send(struct eth_device *dev, void *ptr, int len)
Michal Simekb4a1d082010-10-11 11:41:47 +1000206{
207 u32 reg;
208 u32 baseaddress;
Michal Simekf35b7cd2011-08-25 12:47:56 +0200209 struct xemaclite *emaclite = dev->priv;
Michal Simek4514b372008-03-28 12:41:56 +0100210
Michal Simekb4a1d082010-10-11 11:41:47 +1000211 u32 maxtry = 1000;
Michal Simek4514b372008-03-28 12:41:56 +0100212
Michal Simek3aa96f82011-09-12 21:10:04 +0000213 if (len > PKTSIZE)
214 len = PKTSIZE;
Michal Simek4514b372008-03-28 12:41:56 +0100215
Michal Simekf35b7cd2011-08-25 12:47:56 +0200216 while (!xemaclite_txbufferavailable(dev) && maxtry) {
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000217 udelay(10);
Michal Simek4514b372008-03-28 12:41:56 +0100218 maxtry--;
219 }
220
221 if (!maxtry) {
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000222 printf("Error: Timeout waiting for ethernet TX buffer\n");
Michal Simek4514b372008-03-28 12:41:56 +0100223 /* Restart PING TX */
Michal Simekac357ac2011-08-25 12:36:39 +0200224 out_be32 (dev->iobase + XEL_TSR_OFFSET, 0);
Michal Simekdf40ead2011-09-12 21:10:01 +0000225 if (emaclite->txpp) {
226 out_be32 (dev->iobase + XEL_TSR_OFFSET +
227 XEL_BUFFER_OFFSET, 0);
228 }
Michal Simek29869212011-03-08 04:25:53 +0000229 return -1;
Michal Simek4514b372008-03-28 12:41:56 +0100230 }
231
232 /* Determine the expected TX buffer address */
Michal Simekf35b7cd2011-08-25 12:47:56 +0200233 baseaddress = (dev->iobase + emaclite->nexttxbuffertouse);
Michal Simek4514b372008-03-28 12:41:56 +0100234
235 /* Determine if the expected buffer address is empty */
236 reg = in_be32 (baseaddress + XEL_TSR_OFFSET);
237 if (((reg & XEL_TSR_XMIT_BUSY_MASK) == 0)
238 && ((in_be32 ((baseaddress) + XEL_TSR_OFFSET)
239 & XEL_TSR_XMIT_ACTIVE_MASK) == 0)) {
240
Michal Simekdf40ead2011-09-12 21:10:01 +0000241 if (emaclite->txpp)
242 emaclite->nexttxbuffertouse ^= XEL_BUFFER_OFFSET;
243
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000244 debug("Send packet from 0x%x\n", baseaddress);
Michal Simek4514b372008-03-28 12:41:56 +0100245 /* Write the frame to the buffer */
Stephan Linz76aeeb92012-05-22 12:18:10 +0000246 xemaclite_alignedwrite(ptr, baseaddress, len);
Michal Simek4514b372008-03-28 12:41:56 +0100247 out_be32 (baseaddress + XEL_TPLR_OFFSET,(len &
248 (XEL_TPLR_LENGTH_MASK_HI | XEL_TPLR_LENGTH_MASK_LO)));
249 reg = in_be32 (baseaddress + XEL_TSR_OFFSET);
250 reg |= XEL_TSR_XMIT_BUSY_MASK;
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000251 if ((reg & XEL_TSR_XMIT_IE_MASK) != 0)
Michal Simek4514b372008-03-28 12:41:56 +0100252 reg |= XEL_TSR_XMIT_ACTIVE_MASK;
Michal Simek4514b372008-03-28 12:41:56 +0100253 out_be32 (baseaddress + XEL_TSR_OFFSET, reg);
Michal Simek29869212011-03-08 04:25:53 +0000254 return 0;
Michal Simek4514b372008-03-28 12:41:56 +0100255 }
Michal Simekdf40ead2011-09-12 21:10:01 +0000256
257 if (emaclite->txpp) {
258 /* Switch to second buffer */
259 baseaddress ^= XEL_BUFFER_OFFSET;
260 /* Determine if the expected buffer address is empty */
Michal Simek4514b372008-03-28 12:41:56 +0100261 reg = in_be32 (baseaddress + XEL_TSR_OFFSET);
Michal Simekdf40ead2011-09-12 21:10:01 +0000262 if (((reg & XEL_TSR_XMIT_BUSY_MASK) == 0)
263 && ((in_be32 ((baseaddress) + XEL_TSR_OFFSET)
264 & XEL_TSR_XMIT_ACTIVE_MASK) == 0)) {
265 debug("Send packet from 0x%x\n", baseaddress);
266 /* Write the frame to the buffer */
Stephan Linz76aeeb92012-05-22 12:18:10 +0000267 xemaclite_alignedwrite(ptr, baseaddress, len);
Michal Simekdf40ead2011-09-12 21:10:01 +0000268 out_be32 (baseaddress + XEL_TPLR_OFFSET, (len &
269 (XEL_TPLR_LENGTH_MASK_HI |
270 XEL_TPLR_LENGTH_MASK_LO)));
271 reg = in_be32 (baseaddress + XEL_TSR_OFFSET);
272 reg |= XEL_TSR_XMIT_BUSY_MASK;
273 if ((reg & XEL_TSR_XMIT_IE_MASK) != 0)
274 reg |= XEL_TSR_XMIT_ACTIVE_MASK;
275 out_be32 (baseaddress + XEL_TSR_OFFSET, reg);
276 return 0;
Michal Simek4514b372008-03-28 12:41:56 +0100277 }
Michal Simek4514b372008-03-28 12:41:56 +0100278 }
Michal Simekdf40ead2011-09-12 21:10:01 +0000279
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000280 puts("Error while sending frame\n");
Michal Simek29869212011-03-08 04:25:53 +0000281 return -1;
Michal Simek4514b372008-03-28 12:41:56 +0100282}
283
Michal Simekb4a1d082010-10-11 11:41:47 +1000284static int emaclite_recv(struct eth_device *dev)
Michal Simek4514b372008-03-28 12:41:56 +0100285{
Michal Simekb4a1d082010-10-11 11:41:47 +1000286 u32 length;
287 u32 reg;
288 u32 baseaddress;
Michal Simekf35b7cd2011-08-25 12:47:56 +0200289 struct xemaclite *emaclite = dev->priv;
Michal Simek4514b372008-03-28 12:41:56 +0100290
Michal Simekf35b7cd2011-08-25 12:47:56 +0200291 baseaddress = dev->iobase + emaclite->nextrxbuffertouse;
Michal Simek4514b372008-03-28 12:41:56 +0100292 reg = in_be32 (baseaddress + XEL_RSR_OFFSET);
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000293 debug("Testing data at address 0x%x\n", baseaddress);
Michal Simek4514b372008-03-28 12:41:56 +0100294 if ((reg & XEL_RSR_RECV_DONE_MASK) == XEL_RSR_RECV_DONE_MASK) {
Michal Simekdf40ead2011-09-12 21:10:01 +0000295 if (emaclite->rxpp)
296 emaclite->nextrxbuffertouse ^= XEL_BUFFER_OFFSET;
Michal Simek4514b372008-03-28 12:41:56 +0100297 } else {
Michal Simekdf40ead2011-09-12 21:10:01 +0000298
299 if (!emaclite->rxpp) {
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000300 debug("No data was available - address 0x%x\n",
Michal Simekdf40ead2011-09-12 21:10:01 +0000301 baseaddress);
Michal Simek4514b372008-03-28 12:41:56 +0100302 return 0;
Michal Simekdf40ead2011-09-12 21:10:01 +0000303 } else {
304 baseaddress ^= XEL_BUFFER_OFFSET;
305 reg = in_be32 (baseaddress + XEL_RSR_OFFSET);
306 if ((reg & XEL_RSR_RECV_DONE_MASK) !=
307 XEL_RSR_RECV_DONE_MASK) {
308 debug("No data was available - address 0x%x\n",
309 baseaddress);
310 return 0;
311 }
Michal Simek4514b372008-03-28 12:41:56 +0100312 }
Michal Simek4514b372008-03-28 12:41:56 +0100313 }
314 /* Get the length of the frame that arrived */
Michal Simek1b9ecc92010-10-11 11:41:46 +1000315 switch(((ntohl(in_be32 (baseaddress + XEL_RXBUFF_OFFSET + 0xC))) &
Michal Simek4514b372008-03-28 12:41:56 +0100316 0xFFFF0000 ) >> 16) {
317 case 0x806:
318 length = 42 + 20; /* FIXME size of ARP */
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000319 debug("ARP Packet\n");
Michal Simek4514b372008-03-28 12:41:56 +0100320 break;
321 case 0x800:
322 length = 14 + 14 +
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000323 (((ntohl(in_be32 (baseaddress + XEL_RXBUFF_OFFSET +
324 0x10))) & 0xFFFF0000) >> 16);
325 /* FIXME size of IP packet */
Michal Simek4514b372008-03-28 12:41:56 +0100326 debug ("IP Packet\n");
327 break;
328 default:
Michal Simek3aa96f82011-09-12 21:10:04 +0000329 debug("Other Packet\n");
330 length = PKTSIZE;
Michal Simek4514b372008-03-28 12:41:56 +0100331 break;
332 }
333
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000334 xemaclite_alignedread((u32 *) (baseaddress + XEL_RXBUFF_OFFSET),
Michal Simek4514b372008-03-28 12:41:56 +0100335 etherrxbuff, length);
336
337 /* Acknowledge the frame */
338 reg = in_be32 (baseaddress + XEL_RSR_OFFSET);
339 reg &= ~XEL_RSR_RECV_DONE_MASK;
340 out_be32 (baseaddress + XEL_RSR_OFFSET, reg);
341
Michal Simek5d1cf6c2011-09-12 21:10:05 +0000342 debug("Packet receive from 0x%x, length %dB\n", baseaddress, length);
343 NetReceive((uchar *) etherrxbuff, length);
Michal Simek29869212011-03-08 04:25:53 +0000344 return length;
Michal Simek4514b372008-03-28 12:41:56 +0100345
346}
Michal Simekb4a1d082010-10-11 11:41:47 +1000347
Michal Simeka6745b82011-10-12 23:23:22 +0000348int xilinx_emaclite_initialize(bd_t *bis, unsigned long base_addr,
349 int txpp, int rxpp)
Michal Simekb4a1d082010-10-11 11:41:47 +1000350{
351 struct eth_device *dev;
Michal Simekf35b7cd2011-08-25 12:47:56 +0200352 struct xemaclite *emaclite;
Michal Simekb4a1d082010-10-11 11:41:47 +1000353
Michal Simek8f2bf362011-08-25 12:28:47 +0200354 dev = calloc(1, sizeof(*dev));
Michal Simekb4a1d082010-10-11 11:41:47 +1000355 if (dev == NULL)
Michal Simek29869212011-03-08 04:25:53 +0000356 return -1;
Michal Simekf35b7cd2011-08-25 12:47:56 +0200357
358 emaclite = calloc(1, sizeof(struct xemaclite));
359 if (emaclite == NULL) {
360 free(dev);
361 return -1;
362 }
363
364 dev->priv = emaclite;
Michal Simekb4a1d082010-10-11 11:41:47 +1000365
Michal Simeka6745b82011-10-12 23:23:22 +0000366 emaclite->txpp = txpp;
367 emaclite->rxpp = rxpp;
Michal Simekdf40ead2011-09-12 21:10:01 +0000368
Michal Simekc4336552011-10-12 23:23:21 +0000369 sprintf(dev->name, "Xelite.%lx", base_addr);
Michal Simekb4a1d082010-10-11 11:41:47 +1000370
371 dev->iobase = base_addr;
Michal Simekb4a1d082010-10-11 11:41:47 +1000372 dev->init = emaclite_init;
373 dev->halt = emaclite_halt;
374 dev->send = emaclite_send;
375 dev->recv = emaclite_recv;
376
377 eth_register(dev);
378
Michal Simek29869212011-03-08 04:25:53 +0000379 return 1;
Michal Simekb4a1d082010-10-11 11:41:47 +1000380}
Michal Simekbb8b27b2012-06-28 21:37:57 +0000381
382#ifdef CONFIG_OF_CONTROL
383int xilinx_emaclite_init(bd_t *bis)
384{
385 int offset = 0;
386 u32 ret = 0;
387 u32 reg;
388
389 do {
390 offset = fdt_node_offset_by_compatible(gd->fdt_blob, offset,
391 "xlnx,xps-ethernetlite-1.00.a");
392 if (offset != -1) {
393 reg = fdtdec_get_addr(gd->fdt_blob, offset, "reg");
394 if (reg != FDT_ADDR_T_NONE) {
395 u32 rxpp = fdtdec_get_int(gd->fdt_blob, offset,
396 "xlnx,rx-ping-pong", 0);
397 u32 txpp = fdtdec_get_int(gd->fdt_blob, offset,
398 "xlnx,tx-ping-pong", 0);
399 ret |= xilinx_emaclite_initialize(bis, reg,
400 txpp, rxpp);
401 }
402 }
403 } while (offset != -1);
404
405 return ret;
406}
407#endif